[276] | 1 | ifndef PLATFORM_DIR |
---|
| 2 | $(error please define PLATFORM_DIR 'make PLATFORM_DIR=foo') |
---|
| 3 | else |
---|
| 4 | TOOLS := tools |
---|
| 5 | |
---|
| 6 | ELF2MIF := $(TOOLS)/elf_read/elf_utils.x |
---|
| 7 | LD := mipsel-unknown-elf-ld |
---|
| 8 | CC := mipsel-unknown-elf-gcc |
---|
| 9 | AS := mipsel-unknown-elf-as |
---|
| 10 | DU := mipsel-unknown-elf-objdump |
---|
| 11 | RM := rm -rf |
---|
| 12 | ECHO := echo |
---|
| 13 | MKDIR := mkdir |
---|
| 14 | DTC := dtc |
---|
| 15 | HEXDUMP := hexdump |
---|
| 16 | |
---|
| 17 | OBJS_DIR := objs |
---|
| 18 | MIF_DIR := mifs |
---|
| 19 | |
---|
| 20 | # ============================================================================= |
---|
| 21 | # Include files paths |
---|
| 22 | # ============================================================================= |
---|
| 23 | |
---|
| 24 | INCLUDE += -I. -Iio_drivers -I$(PLATFORM_DIR) |
---|
| 25 | |
---|
| 26 | # ============================================================================= |
---|
| 27 | # Paths of sources in another directories |
---|
| 28 | # ============================================================================= |
---|
| 29 | |
---|
| 30 | VPATH += io_drivers |
---|
| 31 | VPATH += $(PLATFORM_DIR) |
---|
| 32 | |
---|
| 33 | # ============================================================================= |
---|
| 34 | # Object files |
---|
| 35 | # ============================================================================= |
---|
| 36 | |
---|
| 37 | S_SRCS += reset.s |
---|
| 38 | |
---|
| 39 | C_SRCS += spi.c |
---|
| 40 | C_SRCS += sdcard.c |
---|
| 41 | C_SRCS += ioc.c |
---|
| 42 | C_SRCS += boot_tty.c |
---|
| 43 | C_SRCS += boot_loader_entry.c |
---|
[281] | 44 | C_SRCS += exceptions.c |
---|
[276] | 45 | |
---|
| 46 | OBJS := $(subst .s,.o,$(S_SRCS)) |
---|
| 47 | OBJS += $(subst .c,.o,$(C_SRCS)) |
---|
| 48 | OBJS := $(addprefix $(OBJS_DIR)/, $(OBJS)) |
---|
| 49 | |
---|
| 50 | TARGET := bin.soft |
---|
| 51 | |
---|
| 52 | ifdef SOCLIB |
---|
| 53 | DEFS+= -DSOCLIB_IOC |
---|
| 54 | DTS=platform_soclib.dts |
---|
| 55 | $(info Making for $(PLATFORM_DIR), SocLib variant) |
---|
| 56 | else |
---|
[286] | 57 | ifdef SYSCLK_FREQ |
---|
| 58 | DEFS+= -DSYSCLK_FREQ |
---|
| 59 | endif |
---|
[276] | 60 | DTS=platform_fpga.dts |
---|
| 61 | $(info Making for $(PLATFORM_DIR), FPGA variant) |
---|
| 62 | endif |
---|
| 63 | |
---|
| 64 | CFLAGS := -Wall -mno-gpopt -ffreestanding -fomit-frame-pointer -mips32 \ |
---|
| 65 | -ggdb -mlong-calls |
---|
| 66 | # ============================================================================= |
---|
| 67 | # ALL target. If the MIF variable is defined, the $(MIF) file is generated |
---|
| 68 | # using the $(basename $(MIF))_tab.txt file |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | all: $(TARGET) |
---|
| 72 | if [ ! -z $(MIF) ]; then\ |
---|
| 73 | if [ ! -e $(MIF_DIR) ]; then\ |
---|
| 74 | $(MKDIR) $(MIF_DIR);\ |
---|
| 75 | fi;\ |
---|
| 76 | $(ECHO) "[ MIF ] $(MIF)";\ |
---|
| 77 | $(ELF2MIF) \ |
---|
| 78 | -ELF_FILE $(TARGET) \ |
---|
| 79 | -SEG_FILE $(basename $(MIF))_tab.txt \ |
---|
| 80 | -MIF_FILE $(MIF_DIR)/$(MIF);\ |
---|
| 81 | fi; |
---|
| 82 | |
---|
| 83 | $(TARGET): $(OBJS_DIR) $(OBJS) ldscript $(OBJS_DIR)/platform.ld |
---|
| 84 | @\ |
---|
| 85 | $(ECHO) "[ LD ] $@" |
---|
| 86 | $(LD) -o $@ -T ldscript $(OBJS) |
---|
| 87 | $(DU) -D $@ > $@.txt |
---|
| 88 | |
---|
| 89 | $(OBJS_DIR)/platform.ld: $(OBJS_DIR)/platform.dtb |
---|
| 90 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
| 91 | |
---|
| 92 | $(OBJS_DIR)/platform.dtb: $(DTS) |
---|
| 93 | ${DTC} -O dtb -o $@ $< |
---|
| 94 | |
---|
| 95 | $(OBJS_DIR): |
---|
| 96 | $(MKDIR) $@ |
---|
| 97 | |
---|
| 98 | clean: |
---|
| 99 | $(RM) $(TARGET).txt $(TARGET) *~ $(OBJS_DIR) |
---|
| 100 | |
---|
| 101 | distclean: clean |
---|
| 102 | $(RM) $(MIF_DIR) |
---|
| 103 | # ============================================================================= |
---|
| 104 | # Implicit makefile rules |
---|
| 105 | |
---|
| 106 | $(OBJS_DIR)/%.o: %.c |
---|
| 107 | @\ |
---|
| 108 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
| 109 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
| 110 | $(DU) -D $@ > $@.txt |
---|
| 111 | |
---|
| 112 | $(OBJS_DIR)/%.o: %.S |
---|
| 113 | @\ |
---|
| 114 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
| 115 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
| 116 | $(DU) -D $@ > $@.txt |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | .SILENT: |
---|
| 120 | endif |
---|