heads/Makefile.nerf
Trammell hudson 2438a0ea24
Build multiple boards with the NERF firmware (issue #268)
This modifies the `Makefile.nerf` to create files based on the
$(BOARD) variable, which is necessary as we start to support
multiple mainboards.

The config files must define five variables, all in bytes:

* `NERF_SIZE` - for the EFI firmware volume that contains Linux
* `PEI_SIZE` - size of the PEI image in the vendor ROM
* `PEI_OFFSET` - offset of the PEI image in the vendor ROM
* `ME_SIZE` - size of the ME image in the vendor ROM, or 0 if
there is no ME image to be extracted.
* `ME_OFFSET` - offset of the ME image in the vendor ROM

The `ifd.bin` must be created and can be checked in.
The default ROM input file is `blobs/$(BOARD)/$(BOARD).rom`,
and it *must not* be checked in.
2017-10-05 15:10:34 -04:00

201 lines
5.5 KiB
Makefile

# Targets specific for the NERF firmware
#
# this assumes that we've already made the edk2 things, via
# edk2.intermediate or something like that.
EDK2_DIR := $(build)/$(edk2_dir)/BaseTools/BinWrappers/PosixLike
# build/edk2-UDK2017/Build/MdeModule/DEBUG_GCC5/X64/MdeModulePkg/Core/Dxe/DxeMain/OUTPUT
# wtf edk2 doesn't hve a way to turn the inf file into an executable?
# this build system sucks
RuntimeArchProtocolGuid := { 0xb7dfb4e1, 0x052f, 0x449f, { 0x87, 0xbe, 0x98, 0x18, 0xfc, 0x91, 0xb7, 0x33 }}
AcpiTableProtocolGuid := { 0xFFE06BDD, 0x6107, 0x46A6, { 0x7B, 0xB2, 0x5A, 0x9C, 0x7E, 0xC5, 0x27, 0x5C }}
dxe-y += DxeCore
DxeCore-filetype := EFI_FV_FILETYPE_DXE_CORE
DxeCore-guid := D6A2CB7F-6A18-4E2F-B43B-9920A733700A
DxeCore-align := 1K
dxe-y += RuntimeDxe
RuntimeDxe-depex := TRUE
RuntimeDxe-guid := B601F8C4-43B7-4784-95B1-F4226CB40CEE
dxe-y += AcpiTableDxe
AcpiTableDxe-guid := 9622E42C-8E38-4a08-9E8F-54F784652F6B
AcpiTableDxe-depex := $(RuntimeArchProtocolGuid)
dxe-y += AcpiPlatform
AcpiPlatform-guid := cb933912-df8f-4305-b1f9-7b44fa11395c
AcpiPlatform-depex := $(RuntimeArchProtocolGuid) AND $(AcpiTableProtocolGuid)
#dxe-y += Acpi-data
Acpi-data-file := /dev/null
Acpi-data-guid := 7E374E25-8E01-4FEE-87F2-390C23C606CD
Acpi-data-filetype := EFI_FV_FILETYPE_FREEFORM
Acpi-data-sectiontype := EFI_SECTION_RAW
Acpi-data.ffs: $(sort blobs/$(BOARD)/acpi/*)
for file in $^; do \
$(EDK2_DIR)/GenSec \
-s EFI_SECTION_RAW \
-o `basename $$file`.sec $$file; \
done
$(EDK2_DIR)/GenFfs \
-t EFI_FV_FILETYPE_FREEFORM \
-g $(Acpi-data-guid) \
-o $@ \
$(foreach f,$^,-i $(notdir $f).sec)
dxe-y += Linux
Linux-file := $(build)/$(linux_dir)/arch/x86/boot/bzImage
Linux-version := $(linux-version)
Linux-guid := DECAFBAD-6548-6461-732d-2f2d4e455246
Linux-depex := $(RuntimeArchProtocolGuid) AND $(AcpiTableProtocolGuid)
dxe-y += Initrd
Initrd-file := initrd.cpio.xz
Initrd-filetype := EFI_FV_FILETYPE_FREEFORM
Initrd-guid := 74696e69-6472-632e-7069-6f2f62696f73
Initrd-sectiontype := EFI_SECTION_RAW
#$(build)/$(linux_dir)/arch/x86/boot/bzImage: linux.intermediate
%.dep:
$(EDK2_DIR)/GenDepex \
-t DXE_DRIVER \
-o $@ \
-e '$($*-depex)'
%.dep.sec: %.dep
$(EDK2_DIR)/GenSec \
-S EFI_SECTION_DXE_DEPEX \
-o $@ \
$<
%.name.sec:
$(EDK2_DIR)/GenSec \
-S EFI_SECTION_USER_INTERFACE \
-o "$@" \
-n "$*"
%.ver.sec:
$(EDK2_DIR)/GenSec \
-S EFI_SECTION_VERSION \
-o "$@" \
-n "$(or $($*-version),1.0)"
define build-ffs =
$1.ffs: $1.file.sec $1.ver.sec $1.name.sec \
$(if $($1-depex),$1.dep.sec) \
$(EDK2_DIR)/GenFfs \
-t $(or $($1-filetype),EFI_FV_FILETYPE_DRIVER) \
-g $($1-guid) \
--align $(or $($1-align),4K) \
-o $$@ \
$$(addprefix -i ,$$^)
$1.file.sec: \
$(or $($1-file),$(build)/$(edk2_dir)/Build/MdeModule/DEBUG_GCC5/X64/$1.efi)
$(EDK2_DIR)/GenSec \
-S $(or $($1-sectiontype),EFI_SECTION_PE32) \
-o $$@ \
$$^
# add a dependency on the edk2 module if we are picking up an
# edk2 build DXEexecutable.
ifndef $($1-file)
$(build)/$(edk2_dir)/Build/MdeModule/DEBUG_GCC5/X64/$1.efi: edk2.intermediate
endif
endef
# For everything that we will include in our DXE filesystem, we
# have to instatiate targets for the ffs and file sections.
# If there is no DEPEX defined, do not create a depex file dependency
$(call map,build-ffs,$(dxe-y))
$(build)/$(linux_dir)/arch/x86/boot/bzImage: linux.intermediate
# Generate a firmware file with a well known guid
# If you have to fit within the normal UEFI image, the volume is
# limited to 0x47 blocks.
#
# But you can also replace the entire region from 0x310000
# up to PEI at 0xE40000, which leaves us almost 11 MB of space.
#
# x3550m5 -- pei starts at 0xb00000, bios is from 0x1000 == 0xaff
nerf.vol: $(addsuffix .ffs,$(dxe-y)) Acpi-data.ffs # blobs/r630/acpi-data.ffs.uncompressed
$(EDK2_DIR)/GenFv \
--numberblock $$[$(NERF_SIZE)/0x1000] \
--blocksize 0x1000 \
--FvNameGuid 4652454e-482f-6165-6473-2f4c696e7578 \
-o $@ \
$(addprefix -f ,$^)
@head -2 $@.txt
-$(RM) $@.txt $@.map
# You must provide your own r630.rom as input for the ME and PEI sections.
# the ifd is only the first 64k, but we take all the way to the ME region
# and unlock the IFD (from coreboot) to allow flashrom to write to the ROM.
# ifdtool -u blobs/r630/ifd.bin && mv blobs/r630/ifd.bin.new blobs/r630/ifd.bin
blobs/$(BOARD)/me.bin: blobs/$(BOARD)/$(BOARD).rom
dd < $< bs=$$[0x10000] skip=$$[$(ME_OFFSET)/0x10000] count=$$[$(ME_SIZE)/0x10000] > $@
blobs/$(BOARD)/pei.bin: blobs/$(BOARD)/$(BOARD).rom
dd < $< bs=$$[0x10000] skip=$$[$(PEI_OFFSET)/0x10000] count=$$[$(PEI_SIZE)/0x10000] > $@
nerf-$(BOARD).rom: \
blobs/$(BOARD)/ifd.bin \
blobs/$(BOARD)/me.bin \
nerf.vol \
blobs/$(BOARD)/pei.bin \
cat $^ > $@
@if [ `stat -c'%s' $@` -ne 16777216 ]; then \
echo -n >&2 "$@ SHOULD BE 16MB. size "; \
stat -c'%s' $@ >&2 ; \
mv $@ $@.bad; \
exit 1; \
fi
#
# Generate a compressed section
# LZMA guid is EE4E5898-3914-4259-9D6E-DC7BD79403CF
# Embedded filesystem is 8C8CE578-8A3D-4F1C-9935-896185C32DD3
#
acpi-lz.ffs: blobs/$(BOARD)/acpi-data.ffs
$(EDK2_DIR)/GenFfs \
-t EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE \
-g 8C8CE578-8A3D-4F1C-9935-896185C32DD3 \
-o $<.ffs.fv \
-a 16 \
-i $<
$(EDK2_DIR)/LzmaCompress \
-e \
-q \
-o $<.fv.lz \
$<.fv
$(EDK2_DIR)/GenSec \
-s EFI_SECTION_GUID_DEFINED \
-g EE4E5898-3914-4259-9D6E-DC7BD79403CF \
-r PROCESSING_REQUIRED \
-o $<.fv.lz.sec \
$<.fv.lz
$(EDK2_DIR)/GenFfs \
-t EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE \
-g 8C8CE578-8A3D-4F1C-9935-896185C32DD3 \
-i $<.fv.lz.sec \
-o $@
nerf.intermediate: nerf-$(BOARD).rom