From eded6bca81be4e410987cbb355c916e8c2b0840c Mon Sep 17 00:00:00 2001 From: zhanghua000 Date: Sun, 13 Nov 2022 21:32:58 +0800 Subject: [PATCH] Add alarm/uefi-raspberrypi4 This is the UEFI firmware for Raspberry Pi 4 implemented by tianocore. This allows raspbberrypi runs almost any OS with proper drivers, even Windows. However, it has some limitations, devices such as V3D Core and GPIO are not available currently, you can see its upstream for more info. We have disabled the 3GB limit by default because our kernel linux-aarch64 is new enough(>=5.8). This will allow OS uses full RAM on the models have RAM larger than 3GB. Signed-off-by: zhanghua000 --- alarm/uefi-raspberrypi4/.gitignore | 2 + .../70-post-install-uefi.hook | 12 ++++ .../uefi-raspberrypi4/80-pre-remove-uefi.hook | 9 +++ alarm/uefi-raspberrypi4/PKGBUILD | 71 +++++++++++++++++++ alarm/uefi-raspberrypi4/build.sh | 10 +++ alarm/uefi-raspberrypi4/post-install-uefi | 8 +++ alarm/uefi-raspberrypi4/pre-remove-uefi | 8 +++ 7 files changed, 120 insertions(+) create mode 100644 alarm/uefi-raspberrypi4/.gitignore create mode 100644 alarm/uefi-raspberrypi4/70-post-install-uefi.hook create mode 100644 alarm/uefi-raspberrypi4/80-pre-remove-uefi.hook create mode 100644 alarm/uefi-raspberrypi4/PKGBUILD create mode 100644 alarm/uefi-raspberrypi4/build.sh create mode 100644 alarm/uefi-raspberrypi4/post-install-uefi create mode 100644 alarm/uefi-raspberrypi4/pre-remove-uefi diff --git a/alarm/uefi-raspberrypi4/.gitignore b/alarm/uefi-raspberrypi4/.gitignore new file mode 100644 index 0000000000..2ba1b93288 --- /dev/null +++ b/alarm/uefi-raspberrypi4/.gitignore @@ -0,0 +1,2 @@ +*.cer +*.bin diff --git a/alarm/uefi-raspberrypi4/70-post-install-uefi.hook b/alarm/uefi-raspberrypi4/70-post-install-uefi.hook new file mode 100644 index 0000000000..a478eb9ce6 --- /dev/null +++ b/alarm/uefi-raspberrypi4/70-post-install-uefi.hook @@ -0,0 +1,12 @@ +[Trigger] +Type = File +Operation = Install +Operation = Upgrade +Target = boot/Image +Target = boot/Image.gz +Target = boot/RPI_EFI.fd + +[Action] +Description = Copying kernel binaries... +When = PostTransaction +Exec = /usr/share/libalpm/scripts/post-install-uefi diff --git a/alarm/uefi-raspberrypi4/80-pre-remove-uefi.hook b/alarm/uefi-raspberrypi4/80-pre-remove-uefi.hook new file mode 100644 index 0000000000..6edd79144d --- /dev/null +++ b/alarm/uefi-raspberrypi4/80-pre-remove-uefi.hook @@ -0,0 +1,9 @@ +[Trigger] +Type = File +Operation = Remove +Target = boot/RPI_EFI.fd + +[Action] +Description = Removing copied files for UEFI... +When = PreTransaction +Exec = /usr/share/libalpm/scripts/pre-remove-uefi diff --git a/alarm/uefi-raspberrypi4/PKGBUILD b/alarm/uefi-raspberrypi4/PKGBUILD new file mode 100644 index 0000000000..97ae099929 --- /dev/null +++ b/alarm/uefi-raspberrypi4/PKGBUILD @@ -0,0 +1,71 @@ + +buildarch=8 # aarch64 + +pkgname="uefi-raspberrypi4" +pkgver=1.33.r1.g02bc9ce +pkgrel=1 +backup=("boot/config.txt") +pkgdesc="UEFI firmware for RaspberryPi 4B" +url="https://github.com/pftf/RPi4" +arch=("aarch64") +license=("custom:BSD-2-Clause-Patent") +makedepends=("git" "acpica" "openssl" "util-linux" "python" "clang" "llvm" "lld") +source=( + "git+https://github.com/pftf/RPi4" + "ms_kek.cer::https://go.microsoft.com/fwlink/?LinkId=321185" + "ms_db1.cer::https://go.microsoft.com/fwlink/?linkid=321192" + "ms_db2.cer::https://go.microsoft.com/fwlink/?linkid=321194" + "arm64_dbx.bin::https://uefi.org/sites/default/files/resources/dbxupdate_arm64.bin" + "build.sh" + "70-post-install-uefi.hook" + "80-pre-remove-uefi.hook" + "post-install-uefi" + "pre-remove-uefi" +) +sha256sums=('SKIP' + 'a1117f516a32cefcba3f2d1ace10a87972fd6bbe8fe0d0b996e09e65d802a503' + 'e8e95f0733a55e8bad7be0a1413ee23c51fcea64b3c8fa6a786935fddcc71961' + '48e99b991f57fc52f76149599bff0a58c47154229b9f8d603ac40d3500248507' + 'f42c187f8b01b497f81fb0459164b27d16ca2af0b95c7331a82c1a27a731a885' + 'b36edc417b1061ba926934f9e16bd2d35723e3db69b7879e854f4a8339cf45bf' + '8e55eb4afdd6b572d2413e87b64219d2f9d3bd033de2dfd37e176e92d25d5821' + 'caa86b22a1452d8974e7bbecbb6d9fb591a58da928a06d5e13cee9592e785b12' + '02a799c12e818c6a177df4a5c52454d177f3c8cea11584fcc19e392f08c7418c' + '4052d07f78e0230406c311aab5dcd153c111fb72024d4afa33f2ea019eeb3a6a') + +pkgver(){ + cd "${srcdir}/RPi4" + git describe --tags | sed "s/v//;s/-/.r/;s/-/./g" +} +prepare(){ + cd "${srcdir}/RPi4" + git submodule update --init --recursive + mkdir -p keys + cp "${srcdir}"/{ms_kek.cer,ms_db1.cer,ms_db2.cer,arm64_dbx.bin} keys/ + openssl req -new -x509 -newkey rsa:2048 -subj "/CN=Raspberry Pi Platform Key/" -keyout /dev/null -outform DER -out keys/pk.cer -days 7300 -nodes -sha256 + cp "${srcdir}/build.sh" build.sh + patch --binary -d edk2 -p1 -i ../0001-MdeModulePkg-UefiBootManagerLib-Signal-ReadyToBoot-o.patch + patch --binary -d edk2-platforms -p1 -i ../0002-Check-for-Boot-Discovery-Policy-change.patch +} +build(){ + cd "${srcdir}/RPi4" + sed -i "s/%FIRMVER%/${pkgver}-${pkgrel}/g" build.sh + MAKEFLAGS= make -C edk2/BaseTools CXX=llvm + bash build.sh +} +package(){ + conflicts=("uboot-raspberrypi") + depends=("raspberrypi-overlays" "linux-aarch64>=5.8" "raspberrypi-bootloader") + optdepends=( + "firmware-raspberrypi: firmware for RaspberryPi 4B" + "linux-firmware: firmware for RaspberryPi 4B") + + install -Dm644 "${srcdir}/RPi4/Build/RPi4/RELEASE_CLANG38/FV/RPI_EFI.fd" "${pkgdir}/boot/RPI_EFI.fd" + install -Dm644 "${srcdir}/RPi4/config.txt" "${pkgdir}/boot/config.txt" + install -Dm644 "${srcdir}/RPi4/License.txt" "${pkgdir}/usr/share/licenses/${pkgname}/License.txt" + install -Dm644 "${srcdir}/70-post-install-uefi.hook" "${pkgdir}/usr/share/libalpm/hooks/70-post-install-uefi.hook" + install -Dm644 "${srcdir}/80-pre-remove-uefi.hook" "${pkgdir}/usr/share/libalpm/hooks/80-pre-remove-uefi.hook" + install -Dm755 "${srcdir}/post-install-uefi" "${pkgdir}/usr/share/libalpm/scripts/post-install-uefi" + install -Dm755 "${srcdir}/pre-remove-uefi" "${pkgdir}/usr/share/libalpm/scripts/pre-remove-uefi" +} + diff --git a/alarm/uefi-raspberrypi4/build.sh b/alarm/uefi-raspberrypi4/build.sh new file mode 100644 index 0000000000..ee60c194ca --- /dev/null +++ b/alarm/uefi-raspberrypi4/build.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +export WORKSPACE=$PWD +export PACKAGES_PATH=$WORKSPACE/edk2:$WORKSPACE/edk2-platforms:$WORKSPACE/edk2-non-osi +export CLANG38_AARCH64_PREFIX=llvm- +export BUILD_FLAGS="-D SECURE_BOOT_ENABLE=TRUE -D INCLUDE_TFTP_COMMAND=TRUE -D NETWORK_ISCSI_ENABLE=TRUE -D SMC_PCI_SUPPORT=1" +export DEFAULT_KEYS="-D DEFAULT_KEYS=TRUE -D PK_DEFAULT_FILE=$WORKSPACE/keys/pk.cer -D KEK_DEFAULT_FILE1=$WORKSPACE/keys/ms_kek.cer -D DB_DEFAULT_FILE1=$WORKSPACE/keys/ms_db1.cer -D DB_DEFAULT_FILE2=$WORKSPACE/keys/ms_db2.cer -D DBX_DEFAULT_FILE1=$WORKSPACE/keys/arm64_dbx.bin" +source edk2/edksetup.sh +# EDK2's 'build' command doesn't play nice with spaces in environmnent variables, so we can't move the PCDs there... +build -a AARCH64 -t CLANG38 -p edk2-platforms/Platform/RaspberryPi/RPi4/RPi4.dsc -b RELEASE -n $(nproc) --pcd gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor=L"https://github.com/pftf/RPi4" --pcd gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString=L"UEFI Firmware %FIRMVER%" --pcd gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB=0 ${BUILD_FLAGS} ${DEFAULT_KEYS} diff --git a/alarm/uefi-raspberrypi4/post-install-uefi b/alarm/uefi-raspberrypi4/post-install-uefi new file mode 100644 index 0000000000..c2dadead30 --- /dev/null +++ b/alarm/uefi-raspberrypi4/post-install-uefi @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +echo "Copying /boot/Image to /boot/vmlinux-linux..." +cp /boot/Image /boot/vmlinux-linux +echo "Copying /boot/Image.gz to /boot/vmlinuz-linux..." +cp /boot/Image.gz /boot/vmlinuz-linux +echo "Copying device tree from kernel..." +cp /boot/dtbs/broadcom/bcm2711-rpi-4-b.dtb /boot/bcm2711-rpi-4-b.dtb diff --git a/alarm/uefi-raspberrypi4/pre-remove-uefi b/alarm/uefi-raspberrypi4/pre-remove-uefi new file mode 100644 index 0000000000..03ddb7b57f --- /dev/null +++ b/alarm/uefi-raspberrypi4/pre-remove-uefi @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +echo "Removing /boot/vmlinux-linux..." +rm -f /boot/vmlinux-linux +echo "Removing /boot/vmlinuz-linux..." +rm -f /boot/vmlinuz-linux +echo "Removing /boot/bcm2711-rpi-4-b" +rm -f /boot/bcm2711-rpi-4-b.dtb