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