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