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