heads/Makefile.nerf
2017-09-22 16:20:58 -04:00

162 lines
4.2 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
GenSec-name = $(EDK2_DIR)/GenSec \
-S EFI_SECTION_USER_INTERFACE \
-o "$1" \
-n $2 \
GenSec-version = $(EDK2_DIR)/GenSec \
-S EFI_SECTION_VERSION \
-o "$1" \
-n $2 \
GenSec-pe = $(EDK2_DIR)/GenSec \
-S EFI_SECTION_PE32 \
-o "$1" \
"$2" \
$(build)/$(linux_dir)/arch/x86/boot/bzImage: linux.intermediate
linux-pe.sec: $(build)/$(linux_dir)/arch/x86/boot/bzImage
$(call GenSec-pe,$@,$<)
linux-name.sec:
$(call GenSec-name,$@,"HeadsNERF")
linux-version.sec:
$(call GenSec-version,$@,"0.1")
# Linux depends on the RuntimeArchProtocolGuid to have been installed,
# so we hand code a PUSH GUID, END dependecy file.
linux-dep.sec:
perl -e 'print chr(hex($$_)) for @ARGV' > $@.tmp \
02 \
e1 b4 df b7 \
2f 05 \
9f 44 \
87 be \
98 18 fc 91 b7 33 \
08 \
$(EDK2_DIR)/GenSec \
-S EFI_SECTION_DXE_DEPEX \
-o $@ \
$@.tmp
-$(RM) $@.tmp
# The RuntimeDxe has no dependencies, so we create an empty
# DEPEX file for it (TRUE, END). GenDepex could be used, but its
# commandline parser makes no sense.
nop-dep.sec:
perl -e 'print chr(hex($$_)) for qw/06 08/' > $@.tmp
$(EDK2_DIR)/GenSec \
-S EFI_SECTION_DXE_DEPEX \
-o $@ \
$@.tmp
-$(RM) $@.tmp
linux.ffs: linux-pe.sec linux-name.sec linux-version.sec nop-dep.sec
$(EDK2_DIR)/GenFfs \
-t EFI_FV_FILETYPE_DRIVER \
-g DECAFBAD-6548-6461-732d-2f2d4e455246 \
--align 64K \
$(addprefix -i ,$^) \
-o $@ \
$(build)/$(edk2_dir)/DxeCore.efi: edk2.intermediate
DxeCore-pe.sec: $(build)/$(edk2_dir)/DxeCore.efi
$(call GenSec-pe,$@,$<)
DxeCore-name.sec:
$(call GenSec-name,$@,"DxeCore")
DxeCore-version.sec:
$(call GenSec-version,$@,"1.0")
DxeCore.ffs: DxeCore-pe.sec DxeCore-name.sec DxeCore-version.sec
$(EDK2_DIR)/GenFfs \
-t EFI_FV_FILETYPE_DXE_CORE \
-g D6A2CB7F-6A18-4E2F-B43B-9920A733700A \
--align 1K \
$(addprefix -i ,$^) \
-o $@ \
$(build)/$(edk2_dir)/RuntimeDxe.efi: edk2.intermediate
RuntimeDxe-pe.sec: $(build)/$(edk2_dir)/RuntimeDxe.efi
$(call GenSec-pe,$@,$<)
RuntimeDxe-name.sec:
$(call GenSec-name,$@,"RuntimeDxe")
RuntimeDxe-version.sec:
$(call GenSec-version,$@,"1.0")
RuntimeDxe.ffs: RuntimeDxe-pe.sec RuntimeDxe-name.sec RuntimeDxe-version.sec nop-dep.sec
$(EDK2_DIR)/GenFfs \
-t EFI_FV_FILETYPE_DRIVER \
-g B601F8C4-43B7-4784-95B1-F4226CB40CEE \
--align 64K \
$(addprefix -i ,$^) \
-o $@ \
# Generate a firmware file with a well known guid
# "initrd.cpio/bios" that contains the real initrd file
initrd.ffs: initrd.cpio.xz
$(call GenSec-name,initrd-name.sec,"initrd")
$(call GenSec-version,initrd-version.sec,"0.0")
$(EDK2_DIR)/GenSec \
-S EFI_SECTION_RAW \
-o "initrd-data.sec" \
$<
$(EDK2_DIR)/GenFfs \
-t EFI_FV_FILETYPE_FREEFORM \
-g 74696e69-6472-632e-7069-6f2f62696f73 \
--align 64K \
-o $@ \
-i initrd-name.sec \
-i initrd-version.sec \
-i initrd-data.sec \
# 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.
nerf.vol: DxeCore.ffs RuntimeDxe.ffs linux.ffs initrd.ffs
$(EDK2_DIR)/GenFv \
--numberblock 0xB3 \
--blocksize 0x10000 \
--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/r630/me.bin: r630.rom
dd < $< bs=$$[0x10000] skip=$$[0x02] count=$$[0x2F] > $@
blobs/r630/pei.bin: r630.rom
dd < $< bs=$$[0x10000] skip=$$[0xE4] count=$$[0x1C] > $@
nerf-r630.rom: \
blobs/r630/ifd.bin \
blobs/r630/me.bin \
nerf.vol \
blobs/r630/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
nerf.intermediate: nerf-r630.rom