From 097422d5d76327e7d1d37c8a5b5eb7fc24588f15 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Thu, 19 Jan 2017 00:53:37 +0100 Subject: [PATCH] run: support for creating uefi boot image Issue #2242 --- tool/run/boot_dir/hw | 47 +++++++++++++++++++++++++----------------- tool/run/boot_dir/nova | 42 +++++++++++++++++++++++-------------- tool/run/image/uefi | 43 ++++++++++++++++++++++++++++++++++++++ tool/run/power_on/qemu | 23 +++++++++++---------- 4 files changed, 109 insertions(+), 46 deletions(-) create mode 100644 tool/run/image/uefi diff --git a/tool/run/boot_dir/hw b/tool/run/boot_dir/hw index fc58a256a78..7e1d3254b85 100644 --- a/tool/run/boot_dir/hw +++ b/tool/run/boot_dir/hw @@ -40,28 +40,37 @@ proc run_boot_dir {binaries} { build_core_image $binaries - if {[have_include "image/iso"] || [have_include "image/disk"]} { - # - # Install isolinux/GRUB files and bender - # - install_iso_bootloader_to_run_dir + if {[have_include "image/iso"] || [have_include "image/disk"] || [have_include image/uefi]} { + if {[have_include "image/iso"] || [have_include "image/disk"]} { + # + # Install isolinux/GRUB files and bender + # + install_iso_bootloader_to_run_dir - # - # Generate GRUB config file - # - set fh [open "[run_dir]/boot/grub/menu.lst" "WRONLY CREAT TRUNC"] - puts $fh "timeout 0" - puts $fh "default 0" + # + # Generate GRUB config file + # + set fh [open "[run_dir]/boot/grub/menu.lst" "WRONLY CREAT TRUNC"] + puts $fh "timeout 0" + puts $fh "default 0" + + if {[have_spec "muen"]} { + puts $fh "\ntitle Genode on base-hw/Muen SK" + puts $fh " kernel /image.bin" + } else { + puts $fh "\ntitle Genode on base-hw" + puts $fh " kernel /boot/bender" + puts $fh " module /image.elf" + } + close $fh + } - if {[have_spec "muen"]} { - puts $fh "\ntitle Genode on base-hw/Muen SK" - puts $fh " kernel /image.bin" - } else { - puts $fh "\ntitle Genode on base-hw" - puts $fh " kernel /boot/bender" - puts $fh " module /image.elf" + if {[have_include image/uefi]} { + exec mkdir -p [run_dir]/efi/boot + exec cp [genode_dir]/tool/boot/grub2_32.efi [run_dir]/efi/boot/bootia32.efi + exec cp [genode_dir]/tool/boot/grub2_64.efi [run_dir]/efi/boot/bootx64.efi + exec mkdir -p [run_dir]/boot/grub } - close $fh # # Generate GRUB2 config file diff --git a/tool/run/boot_dir/nova b/tool/run/boot_dir/nova index ba39607f505..3764618962b 100644 --- a/tool/run/boot_dir/nova +++ b/tool/run/boot_dir/nova @@ -63,23 +63,32 @@ proc run_boot_dir {binaries} { exec [cross_dev_prefix]objcopy -O elf32-i386 [nova_kernel] [run_dir]/hypervisor exec [cross_dev_prefix]strip [run_dir]/hypervisor - if {[have_include "image/iso"] || [have_include "image/disk"]} { - # - # Install isolinux/GRUB files and bender - # - install_iso_bootloader_to_run_dir + if {[have_include "image/iso"] || [have_include "image/disk"] || [have_include image/uefi]} { + if {[have_include "image/iso"] || [have_include "image/disk"]} { + # + # Install isolinux/GRUB files and bender + # + install_iso_bootloader_to_run_dir + + # + # Generate GRUB config file + # + set fh [open "[run_dir]/boot/grub/menu.lst" "WRONLY CREAT TRUNC"] + puts $fh "timeout 0" + puts $fh "default 0" + puts $fh "\ntitle Genode on NOVA" + puts $fh " kernel /boot/bender" + puts $fh " module /hypervisor iommu serial novpid novga" + puts $fh " module /image.elf" + close $fh + } - # - # Generate GRUB config file - # - set fh [open "[run_dir]/boot/grub/menu.lst" "WRONLY CREAT TRUNC"] - puts $fh "timeout 0" - puts $fh "default 0" - puts $fh "\ntitle Genode on NOVA" - puts $fh " kernel /boot/bender" - puts $fh " module /hypervisor iommu serial novpid novga" - puts $fh " module /image.elf" - close $fh + if {[have_include image/uefi]} { + exec mkdir -p [run_dir]/efi/boot + exec cp [genode_dir]/tool/boot/grub2_32.efi [run_dir]/efi/boot/bootia32.efi + exec cp [genode_dir]/tool/boot/grub2_64.efi [run_dir]/efi/boot/bootx64.efi + exec mkdir -p [run_dir]/boot/grub + } # # Generate GRUB2 config file @@ -91,6 +100,7 @@ proc run_boot_dir {binaries} { puts $fh " module2 /image.elf" puts $fh "}" close $fh + } # diff --git a/tool/run/image/uefi b/tool/run/image/uefi new file mode 100644 index 00000000000..bd8e783eb7b --- /dev/null +++ b/tool/run/image/uefi @@ -0,0 +1,43 @@ +## +# Create GPT disk image with UEFI boot loaders and content of the run directory +# +# \param --image-uefi-size disk size in MiB +# + +proc image_uefi_size { } { return [get_cmd_arg --image-uefi_size 0] } + + +## +# Create uefi image +# +proc run_image { {unused ""} } { + + requires_installation_of parted + requires_installation_of mkfs.vfat + requires_installation_of mcopy + + set run_size [expr [regsub {\s.*} [exec du -sm [run_dir]] {}]] + + if {[image_uefi_size] > 0} { + set disk_size [image_uefi_size] + } else { + set disk_size [expr $run_size + 1] + } + + # generate head space designated for the partition table + exec dd if=/dev/zero of=[run_dir].header count=34 bs=512 2>/dev/null + + exec dd if=/dev/zero of=[run_dir].partition bs=1M count=$disk_size 2>/dev/null + exec mkfs.vfat -n GENODE [run_dir].partition + + # copy content to disk image + foreach file [exec ls [run_dir]] { + exec mcopy -i [run_dir].partition -s [run_dir]/$file :: + } + + exec cat [run_dir].header [run_dir].partition > [run_dir].img + + exec parted -a none -s [run_dir].img -- mklabel gpt mkpart ESP fat32 34s [expr $disk_size * 1024 * 1024 / 512]s set 1 boot on + + exec rm -f [run_dir].header [run_dir].partition +} diff --git a/tool/run/power_on/qemu b/tool/run/power_on/qemu index 8cbac78f32b..c04c76a04fc 100644 --- a/tool/run/power_on/qemu +++ b/tool/run/power_on/qemu @@ -60,17 +60,18 @@ proc run_power_on { } { if {[have_include "load/tftp"]} { append qemu_args " -boot n -tftp [run_dir] -bootp boot/pulsar -no-reboot -no-shutdown " } else { - if {[have_include "image/iso"]} { - append qemu_args " -cdrom [run_dir].iso " - } else { - if {[have_include "image/disk"]} { - append qemu_args " -hda [run_dir].img " - } else { - puts "Aborting, cannot execute Qemu without a ISO or disk image" - exit -4 - } - } - } + if {[have_include "image/iso"]} { + append qemu_args " -cdrom [run_dir].iso " + } else { + if {[have_include "image/disk"]} { + append qemu_args " -hda [run_dir].img " + } else { + if {[have_include "image/uefi"]} { + append qemu_args " --bios [genode_dir]/tool/boot/tianocore.bin -net none -drive format=raw,file=[run_dir].img " + } else { + puts "Aborting, cannot execute Qemu without a ISO or disk image" + exit -4 + } } } } } # on ARM, we supply the boot image as kernel