[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 |
---|
| 36 | |
---|
| 37 | # ============================================================================= |
---|
| 38 | # Include files paths |
---|
| 39 | # ============================================================================= |
---|
| 40 | |
---|
[759] | 41 | INCLUDE += -I. -Iinclude -Idrivers -I$(HARD_CONFIG_PATH) |
---|
[293] | 42 | |
---|
| 43 | # ============================================================================= |
---|
[758] | 44 | # Object files |
---|
[293] | 45 | # ============================================================================= |
---|
| 46 | |
---|
[758] | 47 | VPATH += src |
---|
[293] | 48 | |
---|
[586] | 49 | CFLAGS := -Wall \ |
---|
| 50 | -mno-gpopt \ |
---|
| 51 | -ffreestanding \ |
---|
| 52 | -fomit-frame-pointer \ |
---|
[758] | 53 | -march=mips32 \ |
---|
[701] | 54 | -O2 \ |
---|
[586] | 55 | -Werror |
---|
[293] | 56 | |
---|
[653] | 57 | C_SRCS := reset_elf_loader.c \ |
---|
[758] | 58 | reset_utils.c \ |
---|
| 59 | reset_exception.c \ |
---|
[586] | 60 | reset_ioc.c \ |
---|
[758] | 61 | version.c |
---|
[406] | 62 | |
---|
[653] | 63 | S_SRCS := reset.S |
---|
[293] | 64 | |
---|
[758] | 65 | OBJS := $(addprefix $(BUILD_DIR)/,\ |
---|
| 66 | $(subst .c,.o, $(notdir $(C_SRCS))) \ |
---|
| 67 | $(subst .S,.o, $(notdir $(S_SRCS)))) |
---|
[293] | 68 | |
---|
[586] | 69 | TARGET := preloader.elf |
---|
[293] | 70 | |
---|
[758] | 71 | # ============================================================================= |
---|
| 72 | # Drivers library |
---|
| 73 | # ============================================================================= |
---|
[293] | 74 | |
---|
[758] | 75 | VPATH += drivers |
---|
| 76 | |
---|
| 77 | DRV_SRCS := reset_tty.c \ |
---|
| 78 | reset_inval.c \ |
---|
| 79 | reset_sdc.c \ |
---|
| 80 | reset_bdv.c \ |
---|
| 81 | reset_rdk.c \ |
---|
| 82 | sdcard.c \ |
---|
| 83 | spi.c |
---|
| 84 | |
---|
| 85 | DRV_OBJS := $(addprefix $(BUILD_DIR)/,\ |
---|
| 86 | $(subst .c,.o, $(notdir $(DRV_SRCS)))) |
---|
| 87 | |
---|
| 88 | DRV_LIB := libdrivers.a |
---|
| 89 | |
---|
| 90 | # ============================================================================= |
---|
| 91 | # Makefile rules |
---|
| 92 | # ============================================================================= |
---|
| 93 | |
---|
| 94 | VPATH += $(BUILD_DIR) |
---|
| 95 | |
---|
[293] | 96 | all: $(TARGET) |
---|
| 97 | |
---|
[758] | 98 | $(BUILD_DIR)/$(DRV_LIB): $(BUILD_DIR) $(DRV_OBJS) |
---|
| 99 | $(ECHO) "[ AR ] $(notdir $@)" |
---|
| 100 | $(AR) rcs $@ $(DRV_OBJS) |
---|
| 101 | |
---|
| 102 | $(BUILD_DIR)/version.o: $(BUILD_DIR)/version.c |
---|
| 103 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
| 104 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
[587] | 105 | $(DU) -D $@ > $@.txt |
---|
[502] | 106 | |
---|
[758] | 107 | $(BUILD_DIR)/version.c: $(BUILD_DIR) version.sh VERSION |
---|
| 108 | $(ECHO) "[version.sh]" |
---|
| 109 | ./version.sh > $@ |
---|
| 110 | |
---|
[759] | 111 | $(BUILD_DIR)/preloader.ld: preloader.ld.in |
---|
| 112 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
| 113 | $(CC) -x c $(INCLUDE) -E $< | $(SED) -e '/#/d' -e '/^[\s\t]*$$/d' > $@ |
---|
| 114 | |
---|
| 115 | $(TARGET): $(BUILD_DIR) $(OBJS) $(BUILD_DIR)/preloader.ld $(BUILD_DIR)/platform.ld $(BUILD_DIR)/$(DRV_LIB) |
---|
[388] | 116 | $(ECHO) "[ LD ] $@" |
---|
[759] | 117 | $(LD) -o $@ -T $(BUILD_DIR)/preloader.ld $(OBJS) -L$(BUILD_DIR) -ldrivers |
---|
[293] | 118 | $(DU) -D $@ > $@.txt |
---|
| 119 | |
---|
[425] | 120 | ifeq ($(USE_DT), 1) |
---|
[293] | 121 | $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb |
---|
[388] | 122 | $(ECHO) "[ HEXDUMP ] $(notdir $<)" |
---|
[293] | 123 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
[425] | 124 | else |
---|
| 125 | $(BUILD_DIR)/platform.ld: |
---|
| 126 | $(ECHO) "[ TOUCH ] $(notdir $@)" |
---|
| 127 | touch $@ |
---|
| 128 | endif |
---|
[293] | 129 | |
---|
[759] | 130 | $(BUILD_DIR)/platform.dtb: $(HARD_CONFIG_PATH)/$(DTS) |
---|
[388] | 131 | $(ECHO) "[ DTC ] $(notdir $<)" |
---|
[390] | 132 | ${DTC} -O dtb -o $@ $< &> /dev/null |
---|
[293] | 133 | |
---|
| 134 | $(BUILD_DIR): |
---|
| 135 | $(MKDIR) $@ |
---|
| 136 | |
---|
[388] | 137 | doc: Doxyfile |
---|
| 138 | $(DOXYGEN) Doxyfile |
---|
| 139 | |
---|
[293] | 140 | clean: |
---|
| 141 | $(RM) $(TARGET).txt $(TARGET) *~ $(BUILD_DIR) |
---|
| 142 | |
---|
[388] | 143 | clean-doc: |
---|
| 144 | $(RM) doc |
---|
[293] | 145 | |
---|
[388] | 146 | distclean: clean clean-doc |
---|
| 147 | |
---|
[293] | 148 | # ============================================================================= |
---|
| 149 | # Implicit makefile rules |
---|
| 150 | |
---|
| 151 | $(BUILD_DIR)/%.o: %.c |
---|
[388] | 152 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
[293] | 153 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
| 154 | $(DU) -D $@ > $@.txt |
---|
| 155 | |
---|
| 156 | $(BUILD_DIR)/%.o: %.S |
---|
[388] | 157 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
[293] | 158 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
| 159 | $(DU) -D $@ > $@.txt |
---|
| 160 | |
---|