[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 |
---|
| 44 | |
---|
| 45 | OBJS := $(subst .s,.o,$(S_SRCS)) |
---|
| 46 | OBJS += $(subst .c,.o,$(C_SRCS)) |
---|
| 47 | OBJS := $(addprefix $(OBJS_DIR)/, $(OBJS)) |
---|
| 48 | |
---|
| 49 | TARGET := bin.soft |
---|
| 50 | |
---|
| 51 | ifdef SOCLIB |
---|
| 52 | DEFS+= -DSOCLIB_IOC |
---|
| 53 | DTS=platform_soclib.dts |
---|
| 54 | $(info Making for $(PLATFORM_DIR), SocLib variant) |
---|
| 55 | else |
---|
| 56 | DTS=platform_fpga.dts |
---|
| 57 | $(info Making for $(PLATFORM_DIR), FPGA variant) |
---|
| 58 | endif |
---|
| 59 | |
---|
| 60 | CFLAGS := -Wall -mno-gpopt -ffreestanding -fomit-frame-pointer -mips32 \ |
---|
| 61 | -ggdb -mlong-calls |
---|
| 62 | # ============================================================================= |
---|
| 63 | # ALL target. If the MIF variable is defined, the $(MIF) file is generated |
---|
| 64 | # using the $(basename $(MIF))_tab.txt file |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | all: $(TARGET) |
---|
| 68 | if [ ! -z $(MIF) ]; then\ |
---|
| 69 | if [ ! -e $(MIF_DIR) ]; then\ |
---|
| 70 | $(MKDIR) $(MIF_DIR);\ |
---|
| 71 | fi;\ |
---|
| 72 | $(ECHO) "[ MIF ] $(MIF)";\ |
---|
| 73 | $(ELF2MIF) \ |
---|
| 74 | -ELF_FILE $(TARGET) \ |
---|
| 75 | -SEG_FILE $(basename $(MIF))_tab.txt \ |
---|
| 76 | -MIF_FILE $(MIF_DIR)/$(MIF);\ |
---|
| 77 | fi; |
---|
| 78 | |
---|
| 79 | $(TARGET): $(OBJS_DIR) $(OBJS) ldscript $(OBJS_DIR)/platform.ld |
---|
| 80 | @\ |
---|
| 81 | $(ECHO) "[ LD ] $@" |
---|
| 82 | $(LD) -o $@ -T ldscript $(OBJS) |
---|
| 83 | $(DU) -D $@ > $@.txt |
---|
| 84 | |
---|
| 85 | $(OBJS_DIR)/platform.ld: $(OBJS_DIR)/platform.dtb |
---|
| 86 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
| 87 | |
---|
| 88 | $(OBJS_DIR)/platform.dtb: $(DTS) |
---|
| 89 | ${DTC} -O dtb -o $@ $< |
---|
| 90 | |
---|
| 91 | $(OBJS_DIR): |
---|
| 92 | $(MKDIR) $@ |
---|
| 93 | |
---|
| 94 | clean: |
---|
| 95 | $(RM) $(TARGET).txt $(TARGET) *~ $(OBJS_DIR) |
---|
| 96 | |
---|
| 97 | distclean: clean |
---|
| 98 | $(RM) $(MIF_DIR) |
---|
| 99 | # ============================================================================= |
---|
| 100 | # Implicit makefile rules |
---|
| 101 | |
---|
| 102 | $(OBJS_DIR)/%.o: %.c |
---|
| 103 | @\ |
---|
| 104 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
| 105 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
| 106 | $(DU) -D $@ > $@.txt |
---|
| 107 | |
---|
| 108 | $(OBJS_DIR)/%.o: %.S |
---|
| 109 | @\ |
---|
| 110 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
| 111 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
| 112 | $(DU) -D $@ > $@.txt |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | .SILENT: |
---|
| 116 | endif |
---|