Cástor Muñoz | 346423c | 2016-02-04 23:05:17 +0100 | [diff] [blame] | 1 | # __________ __ ___. |
| 2 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 3 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 4 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 5 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 6 | # \/ \/ \/ \/ \/ |
| 7 | # $Id$ |
| 8 | # |
| 9 | ifndef V |
| 10 | SILENT = @ |
| 11 | endif |
| 12 | |
| 13 | CC = gcc |
| 14 | LD = ld |
| 15 | OC = objcopy |
| 16 | CROSS ?= arm-elf-eabi- |
| 17 | |
| 18 | ROOTDIR = ../../.. |
| 19 | FIRMDIR = $(ROOTDIR)/firmware |
| 20 | FWARM = $(FIRMDIR)/target/arm |
| 21 | FW8702 = $(FWARM)/s5l8702 |
| 22 | BUILDDIR = build/ |
| 23 | LINKFILE = dualboot.lds |
| 24 | |
| 25 | # Edit the following variables when adding a new target. |
| 26 | # mks5lboot.c also needs to be edited to refer to these |
| 27 | # To add a new target x you need to: |
| 28 | # 1) add x to the list in TARGETS |
| 29 | # 2) create a variable named OPT_x of the form: |
| 30 | # OPT_x=target specific defines |
| 31 | TARGETS = ipod6g |
| 32 | OPT_ipod6g = -DIPOD_6G -DMEMORYSIZE=64 |
| 33 | |
| 34 | LOADERS = install uninstall |
| 35 | OPT_install = |
| 36 | OPT_uninstall = -DDUALBOOT_UNINSTALL |
| 37 | |
| 38 | # target/loader specific options |
| 39 | $(foreach l, $(LOADERS),$(foreach t, $(TARGETS),\ |
| 40 | $(eval OPT_$(l)_$(t) = $(OPT_$(l)) $(OPT_$(t))))) |
| 41 | |
| 42 | DEFINES = -DBOOTLOADER |
| 43 | |
| 44 | SOURCES = init.S dualboot.c |
| 45 | SOURCES += $(ROOTDIR)/lib/arm_support/support-arm.S |
| 46 | SOURCES += $(wildcard $(FIRMDIR)/asm/mem*.c $(FIRMDIR)/libc/mem*.c) |
| 47 | SOURCES += $(addprefix $(FWARM)/, mmu-arm.S) |
| 48 | SOURCES += $(addprefix $(FW8702)/, clocking-s5l8702.c spi-s5l8702.c nor-s5l8702.c crypto-s5l8702.c) |
| 49 | # target/loader specific sources |
| 50 | SRCTARGET = piezo-.c |
| 51 | $(foreach l, $(LOADERS), $(foreach t, $(TARGETS),\ |
| 52 | $(eval SRC_$(l)_$(t) = $(addprefix $(FW8702)/$(t)/, $(subst -.,-$(subst ipod,,$(t)).,$(SRCTARGET)))))) |
| 53 | |
| 54 | INCLUDES += -I. -I.. -I$(FIRMDIR) -I$(FWARM) -I$(FW8702) |
| 55 | INCLUDES += $(addprefix -I$(FIRMDIR)/, export include libc/include kernel/include) |
| 56 | # target/loader specific includes |
| 57 | $(foreach l,$(LOADERS),$(foreach t,$(TARGETS),$(eval INC_$(l)_$(t) = -I$(FW8702)/$(t)))) |
| 58 | |
| 59 | CFLAGS = $(INCLUDES) -mcpu=arm926ej-s -std=gnu99 -nostdlib -ffreestanding -Os -W -Wall\ |
| 60 | -Wundef -Wstrict-prototypes -ffunction-sections -fdata-sections -Wl,--gc-sections $(DEFINES) |
| 61 | |
| 62 | # Build filenames prefix |
| 63 | PFX = dualboot_ |
| 64 | |
| 65 | BOOTBINS = $(foreach l, $(LOADERS),$(foreach t, $(TARGETS),$(PFX)$(l)_$(t).arm-bin)) |
| 66 | |
| 67 | OUTPUTDUALBOOT = ../dualboot.h ../dualboot.c |
| 68 | OUTPUTDEBUG = $(BOOTBINS:%.arm-bin=$(BUILDDIR)%.arm-elf) $(BOOTBINS:%.arm-bin=$(BUILDDIR)%.lds) |
| 69 | |
| 70 | |
| 71 | all: $(BUILDDIR) $(OUTPUTDUALBOOT) |
| 72 | |
| 73 | $(BUILDDIR)$(PFX)%.lds: $(LINKFILE) |
| 74 | @echo Creating $@ |
| 75 | $(SILENT)$(CROSS)$(CC) $(INC_$*) $(CFLAGS) $(OPT_$*) -E -x c - < $< | sed '/#/d' > $@ |
| 76 | |
| 77 | $(BUILDDIR)$(PFX)%.arm-elf: $(BUILDDIR)$(PFX)%.lds $(SOURCES) |
| 78 | @echo CC -T $(notdir $^ $(SRC_$*)) |
| 79 | $(SILENT)$(CROSS)$(CC) $(INC_$*) $(CFLAGS) $(OPT_$*) -o $@ -T$^ $(SRC_$*) |
| 80 | |
| 81 | $(PFX)%.arm-bin: $(BUILDDIR)$(PFX)%.arm-elf |
| 82 | @echo OC $< |
| 83 | $(SILENT)$(CROSS)$(OC) -O binary $< $@ |
| 84 | |
| 85 | bin2c: bin2c.c |
| 86 | $(CC) -o $@ $< |
| 87 | |
| 88 | $(OUTPUTDUALBOOT): bin2c $(BOOTBINS) |
| 89 | ./bin2c ../dualboot $(BOOTBINS) |
| 90 | |
| 91 | $(BUILDDIR): |
| 92 | mkdir -p $@ |
| 93 | |
| 94 | clean: |
| 95 | rm -rf bin2c $(BOOTBINS) $(BUILDDIR) |
| 96 | |
| 97 | .PRECIOUS: $(OUTPUTDEBUG) |