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 | HARD_CONFIG:= $(HARD_CONFIG_PATH)/hard_config.h |
---|
37 | |
---|
38 | # ============================================================================= |
---|
39 | # Include files paths |
---|
40 | # ============================================================================= |
---|
41 | |
---|
42 | INCLUDE += -I. -Iinclude -Idrivers -I$(HARD_CONFIG_PATH) |
---|
43 | |
---|
44 | # ============================================================================= |
---|
45 | # Object files |
---|
46 | # ============================================================================= |
---|
47 | |
---|
48 | VPATH += src |
---|
49 | |
---|
50 | CFLAGS := -Wall \ |
---|
51 | -mno-gpopt \ |
---|
52 | -ffreestanding \ |
---|
53 | -fomit-frame-pointer \ |
---|
54 | -march=mips32 \ |
---|
55 | -O2 \ |
---|
56 | -Werror |
---|
57 | |
---|
58 | C_SRCS := reset_elf_loader.c \ |
---|
59 | reset_utils.c \ |
---|
60 | reset_exception.c \ |
---|
61 | reset_ioc.c \ |
---|
62 | version.c |
---|
63 | |
---|
64 | S_SRCS := reset.S |
---|
65 | |
---|
66 | OBJS := $(addprefix $(BUILD_DIR)/,\ |
---|
67 | $(subst .c,.o, $(notdir $(C_SRCS))) \ |
---|
68 | $(subst .S,.o, $(notdir $(S_SRCS)))) |
---|
69 | |
---|
70 | TARGET := preloader.elf |
---|
71 | |
---|
72 | # ============================================================================= |
---|
73 | # Drivers library |
---|
74 | # ============================================================================= |
---|
75 | |
---|
76 | VPATH += drivers |
---|
77 | |
---|
78 | DRV_SRCS := reset_tty.c \ |
---|
79 | reset_inval.c \ |
---|
80 | reset_sdc.c \ |
---|
81 | reset_bdv.c \ |
---|
82 | reset_rdk.c \ |
---|
83 | sdcard.c \ |
---|
84 | spi.c |
---|
85 | |
---|
86 | DRV_OBJS := $(addprefix $(BUILD_DIR)/,\ |
---|
87 | $(subst .c,.o, $(notdir $(DRV_SRCS)))) |
---|
88 | |
---|
89 | DRV_LIB := libdrivers.a |
---|
90 | |
---|
91 | # ============================================================================= |
---|
92 | # Makefile rules |
---|
93 | # ============================================================================= |
---|
94 | |
---|
95 | VPATH += $(BUILD_DIR) |
---|
96 | |
---|
97 | all: $(TARGET) |
---|
98 | |
---|
99 | $(DRV_OBJS): $(HARD_CONFIG) |
---|
100 | $(OBJS): $(HARD_CONFIG) |
---|
101 | |
---|
102 | $(BUILD_DIR)/$(DRV_LIB): $(BUILD_DIR) $(DRV_OBJS) |
---|
103 | $(ECHO) "[ AR ] $(notdir $@)" |
---|
104 | $(AR) rcs $@ $(DRV_OBJS) |
---|
105 | |
---|
106 | $(BUILD_DIR)/version.o: $(BUILD_DIR)/version.c |
---|
107 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
108 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
109 | $(DU) -D $@ > $@.txt |
---|
110 | |
---|
111 | $(BUILD_DIR)/version.c: $(BUILD_DIR) version.sh VERSION |
---|
112 | $(ECHO) "[version.sh]" |
---|
113 | ./version.sh > $@ |
---|
114 | |
---|
115 | $(BUILD_DIR)/preloader.ld: preloader.ld.in |
---|
116 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
117 | $(CC) -x c $(INCLUDE) -E $< | $(SED) -e '/#/d' -e '/^[\s\t]*$$/d' > $@ |
---|
118 | |
---|
119 | $(TARGET): $(BUILD_DIR) $(OBJS) $(BUILD_DIR)/preloader.ld $(BUILD_DIR)/platform.ld $(BUILD_DIR)/$(DRV_LIB) |
---|
120 | $(ECHO) "[ LD ] $@" |
---|
121 | $(LD) -o $@ -T $(BUILD_DIR)/preloader.ld $(OBJS) -L$(BUILD_DIR) -ldrivers |
---|
122 | $(DU) -D $@ > $@.txt |
---|
123 | |
---|
124 | ifeq ($(USE_DT), 1) |
---|
125 | $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb |
---|
126 | $(ECHO) "[ HEXDUMP ] $(notdir $<)" |
---|
127 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
128 | else |
---|
129 | $(BUILD_DIR)/platform.ld: |
---|
130 | $(ECHO) "[ TOUCH ] $(notdir $@)" |
---|
131 | touch $@ |
---|
132 | endif |
---|
133 | |
---|
134 | $(BUILD_DIR)/platform.dtb: $(HARD_CONFIG_PATH)/$(DTS) |
---|
135 | $(ECHO) "[ DTC ] $(notdir $<)" |
---|
136 | ${DTC} -O dtb -o $@ $< &> /dev/null |
---|
137 | |
---|
138 | $(BUILD_DIR): |
---|
139 | $(MKDIR) $@ |
---|
140 | |
---|
141 | doc: Doxyfile |
---|
142 | $(DOXYGEN) Doxyfile |
---|
143 | |
---|
144 | clean: |
---|
145 | $(RM) $(TARGET).txt $(TARGET) *~ $(BUILD_DIR) |
---|
146 | |
---|
147 | clean-doc: |
---|
148 | $(RM) doc |
---|
149 | |
---|
150 | distclean: clean clean-doc |
---|
151 | |
---|
152 | # ============================================================================= |
---|
153 | # Implicit makefile rules |
---|
154 | |
---|
155 | $(BUILD_DIR)/%.o: %.c |
---|
156 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
157 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
158 | $(DU) -D $@ > $@.txt |
---|
159 | |
---|
160 | $(BUILD_DIR)/%.o: %.S |
---|
161 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
162 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
163 | $(DU) -D $@ > $@.txt |
---|
164 | |
---|