Genode Packages collection
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.6 KiB

# Builds a compressed EFI System Partition image
{ config, pkgs }:
grub' = pkgs.buildPackages.grub2_efi;
# Name used by UEFI for architectures.
targetArch = if pkgs.stdenv.isi686 || config.boot.loader.grub.forcei686 then
else if pkgs.stdenv.isx86_64 then
else if pkgs.stdenv.isAarch64 then
throw "Unsupported architecture";
in pkgs.stdenv.mkDerivation {
name = "esp.img.zst";
nativeBuildInputs = with pkgs.buildPackages; [ grub' dosfstools mtools zstd ];
buildCommand = ''
mkdir -p $bootdir
cat <<EOF > embedded.cfg
insmod configfile
insmod efi_gop
insmod efi_uga
insmod ext2
insmod normal
insmod part_gpt
insmod search_fs_uuid
search.fs_uuid ${config.genode.boot.storeFsUuid} root
set prefix=($root)/boot/grub
configfile /boot/grub/grub.cfg
grub-script-check embedded.cfg
${grub'}/bin/grub-mkimage \
--config=embedded.cfg \
--output=$bootdir/boot${targetArch}.efi \
--prefix=/boot/grub \
--format=${grub'.grubTarget} \
# Make the ESP image twice as large as necessary
imageBytes=$(du --summarize --block-size=4096 --total $bootdir | tail -1 | awk '{ print int($1 * 8192) }')
truncate --size=$imageBytes $img
mkfs.vfat -n EFIBOOT --invariant $img
mcopy -sv -i $img EFI ::
fsck.vfat -nv $img
zstd --verbose --no-progress ./$img -o $out