[759] | 1 | # let the user have a default configuration (ie for HARD_CONFIG_PATH) |
---|
[411] | 2 | -include ./build.mk |
---|
| 3 | |
---|
[992] | 4 | USE_DT ?= 0 |
---|
| 5 | DTS ?= platform.dts |
---|
| 6 | HARD_CONFIG_PATH ?= ../../../giet_vm |
---|
| 7 | MAKECMDGOALS ?= none |
---|
[1024] | 8 | BS_PROC ?= 0 |
---|
[758] | 9 | |
---|
[1024] | 10 | MAKECMDGOALS ?= none |
---|
| 11 | BUILD_DIR ?= build |
---|
| 12 | |
---|
[388] | 13 | ifneq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),clean distclean clean-doc doc)) |
---|
[759] | 14 | ifndef HARD_CONFIG_PATH |
---|
| 15 | $(error please define HARD_CONFIG_PATH 'make HARD_CONFIG_PATH=foo') |
---|
[388] | 16 | else |
---|
[759] | 17 | $(info Make for $(HARD_CONFIG_PATH)) |
---|
[388] | 18 | endif |
---|
| 19 | endif |
---|
| 20 | |
---|
[758] | 21 | # Platform clock frequency (in KHz) |
---|
| 22 | ifdef SYSTEM_CLK |
---|
| 23 | DEFS := "-DRESET_SYSTEM_CLK=$(SYSTEM_CLK)" |
---|
| 24 | endif |
---|
[1024] | 25 | DEFS := -DBS_PROC=$(BS_PROC) |
---|
[758] | 26 | |
---|
[653] | 27 | LD := mipsel-unknown-elf-ld |
---|
| 28 | CC := mipsel-unknown-elf-gcc |
---|
| 29 | AS := mipsel-unknown-elf-as |
---|
| 30 | DU := mipsel-unknown-elf-objdump |
---|
[758] | 31 | AR := mipsel-unknown-elf-ar |
---|
[653] | 32 | RM := rm -rf |
---|
[759] | 33 | SED := sed |
---|
[653] | 34 | ECHO := @echo |
---|
| 35 | MKDIR := mkdir |
---|
| 36 | DTC := dtc |
---|
| 37 | HEXDUMP := hexdump |
---|
[388] | 38 | DOXYGEN := doxygen |
---|
[293] | 39 | |
---|
[761] | 40 | HARD_CONFIG:= $(HARD_CONFIG_PATH)/hard_config.h |
---|
[293] | 41 | |
---|
| 42 | # ============================================================================= |
---|
| 43 | # Include files paths |
---|
| 44 | # ============================================================================= |
---|
| 45 | |
---|
[759] | 46 | INCLUDE += -I. -Iinclude -Idrivers -I$(HARD_CONFIG_PATH) |
---|
[293] | 47 | |
---|
| 48 | # ============================================================================= |
---|
[758] | 49 | # Object files |
---|
[293] | 50 | # ============================================================================= |
---|
| 51 | |
---|
[758] | 52 | VPATH += src |
---|
[293] | 53 | |
---|
[586] | 54 | CFLAGS := -Wall \ |
---|
| 55 | -mno-gpopt \ |
---|
| 56 | -ffreestanding \ |
---|
| 57 | -fomit-frame-pointer \ |
---|
[758] | 58 | -march=mips32 \ |
---|
[701] | 59 | -O2 \ |
---|
[586] | 60 | -Werror |
---|
[293] | 61 | |
---|
[653] | 62 | C_SRCS := reset_elf_loader.c \ |
---|
[758] | 63 | reset_utils.c \ |
---|
| 64 | reset_exception.c \ |
---|
[586] | 65 | reset_ioc.c \ |
---|
[758] | 66 | version.c |
---|
[406] | 67 | |
---|
[653] | 68 | S_SRCS := reset.S |
---|
[293] | 69 | |
---|
[758] | 70 | OBJS := $(addprefix $(BUILD_DIR)/,\ |
---|
| 71 | $(subst .c,.o, $(notdir $(C_SRCS))) \ |
---|
| 72 | $(subst .S,.o, $(notdir $(S_SRCS)))) |
---|
[1024] | 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 |
---|
[293] | 76 | |
---|
[758] | 77 | # ============================================================================= |
---|
| 78 | # Drivers library |
---|
| 79 | # ============================================================================= |
---|
[293] | 80 | |
---|
[758] | 81 | VPATH += drivers |
---|
| 82 | |
---|
| 83 | DRV_SRCS := reset_tty.c \ |
---|
| 84 | reset_inval.c \ |
---|
[992] | 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 \ |
---|
[758] | 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 | |
---|
[293] | 103 | all: $(TARGET) |
---|
| 104 | |
---|
[761] | 105 | $(DRV_OBJS): $(HARD_CONFIG) |
---|
| 106 | $(OBJS): $(HARD_CONFIG) |
---|
| 107 | |
---|
[758] | 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 $@ $< |
---|
[587] | 115 | $(DU) -D $@ > $@.txt |
---|
[502] | 116 | |
---|
[758] | 117 | $(BUILD_DIR)/version.c: $(BUILD_DIR) version.sh VERSION |
---|
| 118 | $(ECHO) "[version.sh]" |
---|
| 119 | ./version.sh > $@ |
---|
| 120 | |
---|
[1024] | 121 | $(BUILD_DIR)/preloader.ld: preloader.ld.in $(HARD_CONFIG) |
---|
[759] | 122 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
[801] | 123 | $(CC) -x c -P -E -DUSE_DT=$(USE_DT) $(INCLUDE) $< -o $@ |
---|
[759] | 124 | |
---|
[791] | 125 | $(TARGET): $(BUILD_DIR) $(OBJS) $(BUILD_DIR)/preloader.ld $(BUILD_DIR)/$(DRV_LIB) |
---|
[388] | 126 | $(ECHO) "[ LD ] $@" |
---|
[759] | 127 | $(LD) -o $@ -T $(BUILD_DIR)/preloader.ld $(OBJS) -L$(BUILD_DIR) -ldrivers |
---|
[293] | 128 | $(DU) -D $@ > $@.txt |
---|
| 129 | |
---|
[425] | 130 | ifeq ($(USE_DT), 1) |
---|
[791] | 131 | $(TARGET): $(BUILD_DIR)/platform.ld |
---|
| 132 | |
---|
| 133 | $(BUILD_DIR)/platform.dtb: $(HARD_CONFIG_PATH)/$(DTS) |
---|
| 134 | $(ECHO) "[ DTC ] $(notdir $<)" |
---|
[866] | 135 | $(DTC) -O dtb -o $@ $< > /dev/null 2>&1 |
---|
[791] | 136 | |
---|
[293] | 137 | $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb |
---|
[388] | 138 | $(ECHO) "[ HEXDUMP ] $(notdir $<)" |
---|
[293] | 139 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
[425] | 140 | endif |
---|
[293] | 141 | |
---|
| 142 | $(BUILD_DIR): |
---|
| 143 | $(MKDIR) $@ |
---|
| 144 | |
---|
[388] | 145 | doc: Doxyfile |
---|
| 146 | $(DOXYGEN) Doxyfile |
---|
| 147 | |
---|
[293] | 148 | clean: |
---|
| 149 | $(RM) $(TARGET).txt $(TARGET) *~ $(BUILD_DIR) |
---|
| 150 | |
---|
[388] | 151 | clean-doc: |
---|
| 152 | $(RM) doc |
---|
[293] | 153 | |
---|
[388] | 154 | distclean: clean clean-doc |
---|
| 155 | |
---|
[293] | 156 | # ============================================================================= |
---|
| 157 | # Implicit makefile rules |
---|
| 158 | |
---|
| 159 | $(BUILD_DIR)/%.o: %.c |
---|
[388] | 160 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
[293] | 161 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
| 162 | $(DU) -D $@ > $@.txt |
---|
| 163 | |
---|
| 164 | $(BUILD_DIR)/%.o: %.S |
---|
[388] | 165 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
[293] | 166 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
| 167 | $(DU) -D $@ > $@.txt |
---|
| 168 | |
---|