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