1 | ifndef PLATFORM_DIR |
---|
2 | $(error please define PLATFORM_DIR 'make PLATFORM_DIR=foo') |
---|
3 | else |
---|
4 | TOOLS := tools |
---|
5 | |
---|
6 | ELF2MIF := $(TOOLS)/elf_read/elf_utils.x |
---|
7 | LD := mipsel-unknown-elf-ld |
---|
8 | CC := mipsel-unknown-elf-gcc |
---|
9 | AS := mipsel-unknown-elf-as |
---|
10 | DU := mipsel-unknown-elf-objdump |
---|
11 | RM := rm -rf |
---|
12 | ECHO := echo |
---|
13 | MKDIR := mkdir |
---|
14 | DTC := dtc |
---|
15 | HEXDUMP := hexdump |
---|
16 | |
---|
17 | OBJS_DIR := objs |
---|
18 | MIF_DIR := mifs |
---|
19 | |
---|
20 | # ============================================================================= |
---|
21 | # Include files paths |
---|
22 | # ============================================================================= |
---|
23 | |
---|
24 | INCLUDE += -I. -Iio_drivers -I$(PLATFORM_DIR) |
---|
25 | |
---|
26 | # ============================================================================= |
---|
27 | # Paths of sources in another directories |
---|
28 | # ============================================================================= |
---|
29 | |
---|
30 | VPATH += io_drivers |
---|
31 | VPATH += $(PLATFORM_DIR) |
---|
32 | |
---|
33 | # ============================================================================= |
---|
34 | # Object files |
---|
35 | # ============================================================================= |
---|
36 | |
---|
37 | S_SRCS += reset.s |
---|
38 | |
---|
39 | C_SRCS += spi.c |
---|
40 | C_SRCS += sdcard.c |
---|
41 | C_SRCS += ioc.c |
---|
42 | C_SRCS += boot_tty.c |
---|
43 | C_SRCS += boot_loader_entry.c |
---|
44 | C_SRCS += exceptions.c |
---|
45 | |
---|
46 | OBJS := $(subst .s,.o,$(S_SRCS)) |
---|
47 | OBJS += $(subst .c,.o,$(C_SRCS)) |
---|
48 | OBJS := $(addprefix $(OBJS_DIR)/, $(OBJS)) |
---|
49 | |
---|
50 | TARGET := bin.soft |
---|
51 | |
---|
52 | ifdef SOCLIB |
---|
53 | DEFS+= -DSOCLIB_IOC |
---|
54 | DTS=platform_soclib.dts |
---|
55 | $(info Making for $(PLATFORM_DIR), SocLib variant) |
---|
56 | else |
---|
57 | DTS=platform_fpga.dts |
---|
58 | $(info Making for $(PLATFORM_DIR), FPGA variant) |
---|
59 | endif |
---|
60 | |
---|
61 | CFLAGS := -Wall -mno-gpopt -ffreestanding -fomit-frame-pointer -mips32 \ |
---|
62 | -ggdb -mlong-calls |
---|
63 | # ============================================================================= |
---|
64 | # ALL target. If the MIF variable is defined, the $(MIF) file is generated |
---|
65 | # using the $(basename $(MIF))_tab.txt file |
---|
66 | |
---|
67 | |
---|
68 | all: $(TARGET) |
---|
69 | if [ ! -z $(MIF) ]; then\ |
---|
70 | if [ ! -e $(MIF_DIR) ]; then\ |
---|
71 | $(MKDIR) $(MIF_DIR);\ |
---|
72 | fi;\ |
---|
73 | $(ECHO) "[ MIF ] $(MIF)";\ |
---|
74 | $(ELF2MIF) \ |
---|
75 | -ELF_FILE $(TARGET) \ |
---|
76 | -SEG_FILE $(basename $(MIF))_tab.txt \ |
---|
77 | -MIF_FILE $(MIF_DIR)/$(MIF);\ |
---|
78 | fi; |
---|
79 | |
---|
80 | $(TARGET): $(OBJS_DIR) $(OBJS) ldscript $(OBJS_DIR)/platform.ld |
---|
81 | @\ |
---|
82 | $(ECHO) "[ LD ] $@" |
---|
83 | $(LD) -o $@ -T ldscript $(OBJS) |
---|
84 | $(DU) -D $@ > $@.txt |
---|
85 | |
---|
86 | $(OBJS_DIR)/platform.ld: $(OBJS_DIR)/platform.dtb |
---|
87 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
88 | |
---|
89 | $(OBJS_DIR)/platform.dtb: $(DTS) |
---|
90 | ${DTC} -O dtb -o $@ $< |
---|
91 | |
---|
92 | $(OBJS_DIR): |
---|
93 | $(MKDIR) $@ |
---|
94 | |
---|
95 | clean: |
---|
96 | $(RM) $(TARGET).txt $(TARGET) *~ $(OBJS_DIR) |
---|
97 | |
---|
98 | distclean: clean |
---|
99 | $(RM) $(MIF_DIR) |
---|
100 | # ============================================================================= |
---|
101 | # Implicit makefile rules |
---|
102 | |
---|
103 | $(OBJS_DIR)/%.o: %.c |
---|
104 | @\ |
---|
105 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
106 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
107 | $(DU) -D $@ > $@.txt |
---|
108 | |
---|
109 | $(OBJS_DIR)/%.o: %.S |
---|
110 | @\ |
---|
111 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
112 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
113 | $(DU) -D $@ > $@.txt |
---|
114 | |
---|
115 | |
---|
116 | .SILENT: |
---|
117 | endif |
---|