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