################################################################################
#
#   Copyright (c) 2015 Minoca Corp. All Rights Reserved
#
#   Module Name:
#
#       Raspberry Pi 2 UEFI Firmware
#
#   Abstract:
#
#       This module implements UEFI firmware for the Raspberry Pi 2.
#
#   Author:
#
#       Chris Stevens 19-Mar-2015
#
#   Environment:
#
#       Firmware
#
################################################################################

include $(SRCDIR)/../common

BINARY := rpi2fw.elf

BINARYTYPE = staticapp

BINPLACE = bin

VPATH += $(BINROOT):

LDFLAGS += -Wl,--no-wchar-size-warning -nodefaultlibs -nostartfiles -nostdlib

RAMDISK = emptyrd
RAMDISK_O = ramdisk.o

OBJS += debug.o              \
        fwvol.o              \
        intr.o               \
        main.o               \
        memmap.o             \
        rpi2fwv.o            \
        ramdenum.o           \
        $(RAMDISK_O)         \
        smbios.o             \
        smp.o                \
        timer.o              \

ARMV7_OBJS = armv7/entry.o  \
             armv7/smpa.o   \
             armv7/timera.o \

TEXT_ADDRESS = 0x00008000

TARGETLIBS += $(OBJROOT)/os/uefi/dev/pl11/pl11.a       \
              $(OBJROOT)/os/uefi/dev/sd/core/sd.a      \
              $(OBJROOT)/os/uefi/dev/bcm2709/bcm2709.a \

EXTRA_SRC_DIRS = armv7

##
## Only build the directories if the binary hasn't been forced on the command
## line.
##

ifeq ($(BINARY), rpi2fw.elf)

RAMDISK_O = emptyrd.o

DIRS = acpi     \
       blobs    \
       runtime

endif

include $(SRCROOT)/os/minoca.mk

CFLAGS += -fshort-wchar

##
## Define the target that creates the firmware volume object file.
##

FWVOL_IMAGES = $(RTBASE) runtime/rpi2rt.ffs acpi/acpi.ffs

rpi2fwv.o: rpi2fwv
	@echo Objectifying - $(notdir $<)
	@$(OBJCOPY) -B $(BFD_ARCH) -I binary -O $(OBJ_FORMAT) $< $@

rpi2fwv: $(FWVOL_IMAGES)
	@echo Generating - $@
	@genfv -o $@ $^

$(RAMDISK_O): $(RAMDISK)
	@echo Objectifying - $(notdir $<)
	@cp $^ ramdisk
	@$(OBJCOPY) -I binary -O $(OBJ_FORMAT) -B $(BFD_ARCH) ramdisk $@

emptyrd:
	@echo Minoca > $@

runtime/rpi2rt.ffs: runtime
acpi/acpi.ffs: acpi

postbuild: rpi2fw

rpi2fw: $(BINARY)
	@echo Flattening - $(notdir $<)
	@$(OBJCOPY) -O binary $^ $@
	@cp -p $@ $(BINROOT)/
