1 | # let the user have a default configuration (ie for HARD_CONFIG_PATH) |
---|
2 | -include ./build.mk |
---|
3 | |
---|
4 | USE_DT ?= 0 |
---|
5 | DTS ?= platform.dts |
---|
6 | HARD_CONFIG_PATH ?= ../../../giet_vm |
---|
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_ioc_spi.c \ |
---|
81 | reset_ioc_bdv.c \ |
---|
82 | reset_ioc_rdk.c \ |
---|
83 | reset_ioc_hba.c \ |
---|
84 | reset_ioc_sdc.c \ |
---|
85 | spi.c |
---|
86 | |
---|
87 | DRV_OBJS := $(addprefix $(BUILD_DIR)/,\ |
---|
88 | $(subst .c,.o, $(notdir $(DRV_SRCS)))) |
---|
89 | |
---|
90 | DRV_LIB := libdrivers.a |
---|
91 | |
---|
92 | # ============================================================================= |
---|
93 | # Makefile rules |
---|
94 | # ============================================================================= |
---|
95 | |
---|
96 | VPATH += $(BUILD_DIR) |
---|
97 | |
---|
98 | all: $(TARGET) |
---|
99 | |
---|
100 | $(DRV_OBJS): $(HARD_CONFIG) |
---|
101 | $(OBJS): $(HARD_CONFIG) |
---|
102 | |
---|
103 | $(BUILD_DIR)/$(DRV_LIB): $(BUILD_DIR) $(DRV_OBJS) |
---|
104 | $(ECHO) "[ AR ] $(notdir $@)" |
---|
105 | $(AR) rcs $@ $(DRV_OBJS) |
---|
106 | |
---|
107 | $(BUILD_DIR)/version.o: $(BUILD_DIR)/version.c |
---|
108 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
109 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
110 | $(DU) -D $@ > $@.txt |
---|
111 | |
---|
112 | $(BUILD_DIR)/version.c: $(BUILD_DIR) version.sh VERSION |
---|
113 | $(ECHO) "[version.sh]" |
---|
114 | ./version.sh > $@ |
---|
115 | |
---|
116 | $(BUILD_DIR)/preloader.ld: preloader.ld.in |
---|
117 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
118 | $(CC) -x c -P -E -DUSE_DT=$(USE_DT) $(INCLUDE) $< -o $@ |
---|
119 | |
---|
120 | $(TARGET): $(BUILD_DIR) $(OBJS) $(BUILD_DIR)/preloader.ld $(BUILD_DIR)/$(DRV_LIB) |
---|
121 | $(ECHO) "[ LD ] $@" |
---|
122 | $(LD) -o $@ -T $(BUILD_DIR)/preloader.ld $(OBJS) -L$(BUILD_DIR) -ldrivers |
---|
123 | $(DU) -D $@ > $@.txt |
---|
124 | |
---|
125 | ifeq ($(USE_DT), 1) |
---|
126 | $(TARGET): $(BUILD_DIR)/platform.ld |
---|
127 | |
---|
128 | $(BUILD_DIR)/platform.dtb: $(HARD_CONFIG_PATH)/$(DTS) |
---|
129 | $(ECHO) "[ DTC ] $(notdir $<)" |
---|
130 | $(DTC) -O dtb -o $@ $< > /dev/null 2>&1 |
---|
131 | |
---|
132 | $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb |
---|
133 | $(ECHO) "[ HEXDUMP ] $(notdir $<)" |
---|
134 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
135 | endif |
---|
136 | |
---|
137 | $(BUILD_DIR): |
---|
138 | $(MKDIR) $@ |
---|
139 | |
---|
140 | doc: Doxyfile |
---|
141 | $(DOXYGEN) Doxyfile |
---|
142 | |
---|
143 | clean: |
---|
144 | $(RM) $(TARGET).txt $(TARGET) *~ $(BUILD_DIR) |
---|
145 | |
---|
146 | clean-doc: |
---|
147 | $(RM) doc |
---|
148 | |
---|
149 | distclean: clean clean-doc |
---|
150 | |
---|
151 | # ============================================================================= |
---|
152 | # Implicit makefile rules |
---|
153 | |
---|
154 | $(BUILD_DIR)/%.o: %.c |
---|
155 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
156 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
157 | $(DU) -D $@ > $@.txt |
---|
158 | |
---|
159 | $(BUILD_DIR)/%.o: %.S |
---|
160 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
161 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
162 | $(DU) -D $@ > $@.txt |
---|
163 | |
---|