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