1 | # let the user have a default configuration (ie for HARD_CONFIG_PATH) |
---|
2 | -include ./build.mk |
---|
3 | |
---|
4 | USE_DT ?= 1 |
---|
5 | DTS ?= platform.dts |
---|
6 | |
---|
7 | MAKECMDGOALS ?= none |
---|
8 | |
---|
9 | ifneq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),clean distclean clean-doc doc)) |
---|
10 | ifndef HARD_CONFIG_PATH |
---|
11 | $(error please define HARD_CONFIG_PATH 'make HARD_CONFIG_PATH=foo') |
---|
12 | else |
---|
13 | $(info Make for $(HARD_CONFIG_PATH)) |
---|
14 | endif |
---|
15 | endif |
---|
16 | |
---|
17 | # Platform clock frequency (in KHz) |
---|
18 | ifdef SYSTEM_CLK |
---|
19 | DEFS := "-DRESET_SYSTEM_CLK=$(SYSTEM_CLK)" |
---|
20 | endif |
---|
21 | |
---|
22 | LD := mipsel-unknown-elf-ld |
---|
23 | CC := mipsel-unknown-elf-gcc |
---|
24 | AS := mipsel-unknown-elf-as |
---|
25 | DU := mipsel-unknown-elf-objdump |
---|
26 | AR := mipsel-unknown-elf-ar |
---|
27 | RM := rm -rf |
---|
28 | SED := sed |
---|
29 | ECHO := @echo |
---|
30 | MKDIR := mkdir |
---|
31 | DTC := dtc |
---|
32 | HEXDUMP := hexdump |
---|
33 | DOXYGEN := doxygen |
---|
34 | |
---|
35 | BUILD_DIR := build |
---|
36 | |
---|
37 | # ============================================================================= |
---|
38 | # Include files paths |
---|
39 | # ============================================================================= |
---|
40 | |
---|
41 | INCLUDE += -I. -Iinclude -Idrivers -I$(HARD_CONFIG_PATH) |
---|
42 | |
---|
43 | # ============================================================================= |
---|
44 | # Object files |
---|
45 | # ============================================================================= |
---|
46 | |
---|
47 | VPATH += src |
---|
48 | |
---|
49 | CFLAGS := -Wall \ |
---|
50 | -mno-gpopt \ |
---|
51 | -ffreestanding \ |
---|
52 | -fomit-frame-pointer \ |
---|
53 | -march=mips32 \ |
---|
54 | -O2 \ |
---|
55 | -Werror |
---|
56 | |
---|
57 | C_SRCS := reset_elf_loader.c \ |
---|
58 | reset_utils.c \ |
---|
59 | reset_exception.c \ |
---|
60 | reset_ioc.c \ |
---|
61 | version.c |
---|
62 | |
---|
63 | S_SRCS := reset.S |
---|
64 | |
---|
65 | OBJS := $(addprefix $(BUILD_DIR)/,\ |
---|
66 | $(subst .c,.o, $(notdir $(C_SRCS))) \ |
---|
67 | $(subst .S,.o, $(notdir $(S_SRCS)))) |
---|
68 | |
---|
69 | TARGET := preloader.elf |
---|
70 | |
---|
71 | # ============================================================================= |
---|
72 | # Drivers library |
---|
73 | # ============================================================================= |
---|
74 | |
---|
75 | VPATH += drivers |
---|
76 | |
---|
77 | DRV_SRCS := reset_tty.c \ |
---|
78 | reset_inval.c \ |
---|
79 | reset_sdc.c \ |
---|
80 | reset_bdv.c \ |
---|
81 | reset_rdk.c \ |
---|
82 | sdcard.c \ |
---|
83 | spi.c |
---|
84 | |
---|
85 | DRV_OBJS := $(addprefix $(BUILD_DIR)/,\ |
---|
86 | $(subst .c,.o, $(notdir $(DRV_SRCS)))) |
---|
87 | |
---|
88 | DRV_LIB := libdrivers.a |
---|
89 | |
---|
90 | # ============================================================================= |
---|
91 | # Makefile rules |
---|
92 | # ============================================================================= |
---|
93 | |
---|
94 | VPATH += $(BUILD_DIR) |
---|
95 | |
---|
96 | all: $(TARGET) |
---|
97 | |
---|
98 | $(BUILD_DIR)/$(DRV_LIB): $(BUILD_DIR) $(DRV_OBJS) |
---|
99 | $(ECHO) "[ AR ] $(notdir $@)" |
---|
100 | $(AR) rcs $@ $(DRV_OBJS) |
---|
101 | |
---|
102 | $(BUILD_DIR)/version.o: $(BUILD_DIR)/version.c |
---|
103 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
104 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
105 | $(DU) -D $@ > $@.txt |
---|
106 | |
---|
107 | $(BUILD_DIR)/version.c: $(BUILD_DIR) version.sh VERSION |
---|
108 | $(ECHO) "[version.sh]" |
---|
109 | ./version.sh > $@ |
---|
110 | |
---|
111 | $(BUILD_DIR)/preloader.ld: preloader.ld.in |
---|
112 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
113 | $(CC) -x c $(INCLUDE) -E $< | $(SED) -e '/#/d' -e '/^[\s\t]*$$/d' > $@ |
---|
114 | |
---|
115 | $(TARGET): $(BUILD_DIR) $(OBJS) $(BUILD_DIR)/preloader.ld $(BUILD_DIR)/platform.ld $(BUILD_DIR)/$(DRV_LIB) |
---|
116 | $(ECHO) "[ LD ] $@" |
---|
117 | $(LD) -o $@ -T $(BUILD_DIR)/preloader.ld $(OBJS) -L$(BUILD_DIR) -ldrivers |
---|
118 | $(DU) -D $@ > $@.txt |
---|
119 | |
---|
120 | ifeq ($(USE_DT), 1) |
---|
121 | $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb |
---|
122 | $(ECHO) "[ HEXDUMP ] $(notdir $<)" |
---|
123 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
124 | else |
---|
125 | $(BUILD_DIR)/platform.ld: |
---|
126 | $(ECHO) "[ TOUCH ] $(notdir $@)" |
---|
127 | touch $@ |
---|
128 | endif |
---|
129 | |
---|
130 | $(BUILD_DIR)/platform.dtb: $(HARD_CONFIG_PATH)/$(DTS) |
---|
131 | $(ECHO) "[ DTC ] $(notdir $<)" |
---|
132 | ${DTC} -O dtb -o $@ $< &> /dev/null |
---|
133 | |
---|
134 | $(BUILD_DIR): |
---|
135 | $(MKDIR) $@ |
---|
136 | |
---|
137 | doc: Doxyfile |
---|
138 | $(DOXYGEN) Doxyfile |
---|
139 | |
---|
140 | clean: |
---|
141 | $(RM) $(TARGET).txt $(TARGET) *~ $(BUILD_DIR) |
---|
142 | |
---|
143 | clean-doc: |
---|
144 | $(RM) doc |
---|
145 | |
---|
146 | distclean: clean clean-doc |
---|
147 | |
---|
148 | # ============================================================================= |
---|
149 | # Implicit makefile rules |
---|
150 | |
---|
151 | $(BUILD_DIR)/%.o: %.c |
---|
152 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
153 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
154 | $(DU) -D $@ > $@.txt |
---|
155 | |
---|
156 | $(BUILD_DIR)/%.o: %.S |
---|
157 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
158 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
159 | $(DU) -D $@ > $@.txt |
---|
160 | |
---|