From: Carlos Santos Date: Sat, 29 Sep 2018 03:16:09 +0000 (-0300) Subject: configs/pc_x86_64_efi: use a GPT partition table X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fee29b05bb7db25e37c8a5175ce00dc712554edf;p=buildroot.git configs/pc_x86_64_efi: use a GPT partition table Since all EFI-based systems support GPT, this commit changes pc_x86_64_efi to use a GPT partition table. It shows an example of how to craft a disk image with GPT partitioning instead of MBR. This is achieved by means of a post-image script which uses mkdosfs+mcopy+sfdisk, since genimage is unable to deal with GPT. Long term, it would be ideal if genimage had GPT support, but until then, this script shows how to achieve creating a GPT-based disk image. The script was kept as simple as possible to make it easy to understand and adapt for other purposes. The root filesystem location is passed to the kernel by a partition UUID, so it is possible to boot on QEMU, directly from the disk image, or dump the image to a physical device. Signed-off-by: Carlos Santos Acked-by: Thomas Petazzoni Signed-off-by: Thomas Petazzoni --- diff --git a/board/pc/genimage-efi.cfg b/board/pc/genimage-efi.cfg deleted file mode 100644 index ec96d73dd1..0000000000 --- a/board/pc/genimage-efi.cfg +++ /dev/null @@ -1,31 +0,0 @@ -image efi-part.vfat { - vfat { - file startup.nsh { - image = "efi-part/startup.nsh" - } - file EFI { - image = "efi-part/EFI" - } - file bzImage { - image = "bzImage" - } - } - size = 16M -} - -image disk.img { - - hdimage { - } - - partition boot { - partition-type = 0xEF - image = "efi-part.vfat" - } - - partition root { - partition-type = 0x83 - image = "rootfs.ext2" - } - -} diff --git a/board/pc/post-build.sh b/board/pc/post-build.sh index 552d488160..346f29ab6a 100755 --- a/board/pc/post-build.sh +++ b/board/pc/post-build.sh @@ -4,12 +4,7 @@ set -e BOARD_DIR=$(dirname "$0") -# Detect boot strategy, EFI or BIOS -if [ -f "$BINARIES_DIR/efi-part/startup.nsh" ]; then - cp -f "$BOARD_DIR/grub-efi.cfg" "$BINARIES_DIR/efi-part/EFI/BOOT/grub.cfg" -else - cp -f "$BOARD_DIR/grub-bios.cfg" "$TARGET_DIR/boot/grub/grub.cfg" - - # Copy grub 1st stage to binaries, required for genimage - cp -f "$HOST_DIR/lib/grub/i387-pc/boot.img" "$BINARIES_DIR" -fi +cp -f "$BOARD_DIR/grub-bios.cfg" "$TARGET_DIR/boot/grub/grub.cfg" + +# Copy grub 1st stage to binaries, required for genimage +cp -f "$HOST_DIR/lib/grub/i387-pc/boot.img" "$BINARIES_DIR" diff --git a/board/pc/post-image-efi-gpt.sh b/board/pc/post-image-efi-gpt.sh new file mode 100755 index 0000000000..d2acd8f852 --- /dev/null +++ b/board/pc/post-image-efi-gpt.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +set -e + +cd ${BINARIES_DIR} + +# GPT partition type UUIDs +esp_type=c12a7328-f81f-11d2-ba4b-00a0c93ec93b +linux_type=44479540-f297-41b2-9af7-d131d5f0458a + +# Partition UUIDs +efi_part_uuid=$(uuidgen) +root_part_uuid=$(uuidgen) + +# Boot partition offset and size, in 512-byte sectors +efi_part_start=64 +efi_part_size=32768 + +# Rootfs partition offset and size, in 512-byte sectors +root_part_start=$(( efi_part_start + efi_part_size )) +root_part_size=$(( $(stat -c %s rootfs.ext2) / 512 )) + +first_lba=34 +last_lba=$(( root_part_start + root_part_size )) + +# Disk image size in 512-byte sectors +image_size=$(( last_lba + first_lba )) + +cat > efi-part/EFI/BOOT/grub.cfg <