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 -P -E -DUSE_DT=$(USE_DT) $(INCLUDE) $< -o $@ |
---|
118 | |
---|
119 | $(TARGET): $(BUILD_DIR) $(OBJS) $(BUILD_DIR)/preloader.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 | $(TARGET): $(BUILD_DIR)/platform.ld |
---|
126 | |
---|
127 | $(BUILD_DIR)/platform.dtb: $(HARD_CONFIG_PATH)/$(DTS) |
---|
128 | $(ECHO) "[ DTC ] $(notdir $<)" |
---|
129 | $(DTC) -O dtb -o $@ $< > /dev/null 2>&1 |
---|
130 | |
---|
131 | $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb |
---|
132 | $(ECHO) "[ HEXDUMP ] $(notdir $<)" |
---|
133 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
134 | endif |
---|
135 | |
---|
136 | $(BUILD_DIR): |
---|
137 | $(MKDIR) $@ |
---|
138 | |
---|
139 | doc: Doxyfile |
---|
140 | $(DOXYGEN) Doxyfile |
---|
141 | |
---|
142 | clean: |
---|
143 | $(RM) $(TARGET).txt $(TARGET) *~ $(BUILD_DIR) |
---|
144 | |
---|
145 | clean-doc: |
---|
146 | $(RM) doc |
---|
147 | |
---|
148 | distclean: clean clean-doc |
---|
149 | |
---|
150 | # ============================================================================= |
---|
151 | # Implicit makefile rules |
---|
152 | |
---|
153 | $(BUILD_DIR)/%.o: %.c |
---|
154 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
155 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
156 | $(DU) -D $@ > $@.txt |
---|
157 | |
---|
158 | $(BUILD_DIR)/%.o: %.S |
---|
159 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
160 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
161 | $(DU) -D $@ > $@.txt |
---|
162 | |
---|