| [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        \ | 
|---|
|  | 83 | sdcard.c           \ | 
|---|
|  | 84 | spi.c | 
|---|
|  | 85 |  | 
|---|
|  | 86 | DRV_OBJS   := $(addprefix $(BUILD_DIR)/,\ | 
|---|
|  | 87 | $(subst .c,.o, $(notdir $(DRV_SRCS)))) | 
|---|
|  | 88 |  | 
|---|
|  | 89 | DRV_LIB    := libdrivers.a | 
|---|
|  | 90 |  | 
|---|
|  | 91 | # ============================================================================= | 
|---|
|  | 92 | # Makefile rules | 
|---|
|  | 93 | # ============================================================================= | 
|---|
|  | 94 |  | 
|---|
|  | 95 | VPATH      += $(BUILD_DIR) | 
|---|
|  | 96 |  | 
|---|
| [293] | 97 | all: $(TARGET) | 
|---|
|  | 98 |  | 
|---|
| [761] | 99 | $(DRV_OBJS): $(HARD_CONFIG) | 
|---|
|  | 100 | $(OBJS): $(HARD_CONFIG) | 
|---|
|  | 101 |  | 
|---|
| [758] | 102 | $(BUILD_DIR)/$(DRV_LIB): $(BUILD_DIR) $(DRV_OBJS) | 
|---|
|  | 103 | $(ECHO) "[   AR    ]     $(notdir $@)" | 
|---|
|  | 104 | $(AR) rcs $@ $(DRV_OBJS) | 
|---|
|  | 105 |  | 
|---|
|  | 106 | $(BUILD_DIR)/version.o: $(BUILD_DIR)/version.c | 
|---|
|  | 107 | $(ECHO) "[   CC    ]     $(notdir $<)" | 
|---|
|  | 108 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< | 
|---|
| [587] | 109 | $(DU) -D $@ > $@.txt | 
|---|
| [502] | 110 |  | 
|---|
| [758] | 111 | $(BUILD_DIR)/version.c: $(BUILD_DIR) version.sh VERSION | 
|---|
|  | 112 | $(ECHO) "[version.sh]" | 
|---|
|  | 113 | ./version.sh > $@ | 
|---|
|  | 114 |  | 
|---|
| [759] | 115 | $(BUILD_DIR)/preloader.ld: preloader.ld.in | 
|---|
|  | 116 | $(ECHO) "[   CC    ]     $(notdir $<)" | 
|---|
| [801] | 117 | $(CC) -x c -P -E -DUSE_DT=$(USE_DT) $(INCLUDE) $< -o $@ | 
|---|
| [759] | 118 |  | 
|---|
| [791] | 119 | $(TARGET): $(BUILD_DIR) $(OBJS) $(BUILD_DIR)/preloader.ld $(BUILD_DIR)/$(DRV_LIB) | 
|---|
| [388] | 120 | $(ECHO) "[   LD    ]     $@" | 
|---|
| [759] | 121 | $(LD) -o $@ -T $(BUILD_DIR)/preloader.ld $(OBJS) -L$(BUILD_DIR) -ldrivers | 
|---|
| [293] | 122 | $(DU) -D $@ > $@.txt | 
|---|
|  | 123 |  | 
|---|
| [425] | 124 | ifeq ($(USE_DT), 1) | 
|---|
| [791] | 125 | $(TARGET): $(BUILD_DIR)/platform.ld | 
|---|
|  | 126 |  | 
|---|
|  | 127 | $(BUILD_DIR)/platform.dtb: $(HARD_CONFIG_PATH)/$(DTS) | 
|---|
|  | 128 | $(ECHO) "[   DTC   ]     $(notdir $<)" | 
|---|
| [866] | 129 | $(DTC) -O dtb -o $@ $< > /dev/null 2>&1 | 
|---|
| [791] | 130 |  | 
|---|
| [293] | 131 | $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb | 
|---|
| [388] | 132 | $(ECHO) "[ HEXDUMP ]     $(notdir $<)" | 
|---|
| [293] | 133 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ | 
|---|
| [425] | 134 | endif | 
|---|
| [293] | 135 |  | 
|---|
|  | 136 | $(BUILD_DIR): | 
|---|
|  | 137 | $(MKDIR) $@ | 
|---|
|  | 138 |  | 
|---|
| [388] | 139 | doc: Doxyfile | 
|---|
|  | 140 | $(DOXYGEN) Doxyfile | 
|---|
|  | 141 |  | 
|---|
| [293] | 142 | clean: | 
|---|
|  | 143 | $(RM) $(TARGET).txt $(TARGET) *~ $(BUILD_DIR) | 
|---|
|  | 144 |  | 
|---|
| [388] | 145 | clean-doc: | 
|---|
|  | 146 | $(RM) doc | 
|---|
| [293] | 147 |  | 
|---|
| [388] | 148 | distclean: clean clean-doc | 
|---|
|  | 149 |  | 
|---|
| [293] | 150 | # ============================================================================= | 
|---|
|  | 151 | # Implicit makefile rules | 
|---|
|  | 152 |  | 
|---|
|  | 153 | $(BUILD_DIR)/%.o: %.c | 
|---|
| [388] | 154 | $(ECHO) "[   CC    ]     $(notdir $<)" | 
|---|
| [293] | 155 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< | 
|---|
|  | 156 | $(DU) -D $@ > $@.txt | 
|---|
|  | 157 |  | 
|---|
|  | 158 | $(BUILD_DIR)/%.o: %.S | 
|---|
| [388] | 159 | $(ECHO) "[   AS    ]     $(notdir $<)" | 
|---|
| [293] | 160 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< | 
|---|
|  | 161 | $(DU) -D $@ > $@.txt | 
|---|
|  | 162 |  | 
|---|