include ../common.mk

# SPIM0
ROMADDR = 0x02000000
ROMSIZE = 16384

all: hello-mini.elf
all: hello-mini.elf.img
all: hello-mini.elf.img.rom-with-bch
all: hello-board.elf
all: hello-board.elf.img
all: hello-board.elf.img.rom-with-bch
all: hello-none.elf

PROGSRC          =
PROGSRC         += hello.c
PROGSRC         += init60.c
.phony: size
size: hello.elf
	$(SIZE) $<

hello-none.elf: $(PROGSRC) $(_COMMON_C)
	$(CC) -DCFG_BOARD_NONE $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LDLIBS) -Wl,-Map=$@.map

hello-mini.elf: $(PROGSRC) $(_COMMON_C)
	$(CC) -DCFG_BOARD_MINI $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LDLIBS) -Wl,-Map=$@.map

hello-board.elf: $(PROGSRC) $(_COMMON_C)
	$(CC) -DCFG_BOARD_BOARD $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LDLIBS) -Wl,-Map=$@.map

# NOTE: Important to keep the ASW boot @ 0x3101ff00
fixup.elf: fixup.S
	$(CC) $< -nostdlib -Wl,-Ttext=0x3101ff00 -o $@

%.dis: %.elf
	$(OBJDUMP) -d -r $< > $@

# NOTE: fixup.elf is needed only on early GR716 packages with unreliable
# bootstrap sampling
%.elf.img: %.elf | fixup.elf
	$(IMG) fixup.elf $< -a $(ROMADDR) -o $@

%.rom-with-bch: %
	$(BCHFILE) -elf -a $(ROMADDR) $< $@ $(ROMSIZE)

clean:
	@$(RM) *.map
	@$(RM) *.dis
	@$(RM) *.o
	@$(RM) *.elf*
	@$(RM) *.img

