From 3468ef16fa55610bae3bacefaf816231a20cfab0 Mon Sep 17 00:00:00 2001 From: Alexandre PAYEN Date: Wed, 7 Aug 2019 15:54:57 +0200 Subject: [PATCH] configs/pc_x86_64_efi: use genimage GPT partition table support Thanks to the introduction of GPT partition table support in genimage, this commit improves the pc_x86_64_efi_defconfig to remove the use of the custom script creating the image. Tested in QEMU, not on a physical device. So: - revert commit fee29b05bb7db25e37c8a5175ce00dc712554edf[1] - add GPT support - tweak shell script to add the correct UUID in genimage config. [1]: https://git.buildroot.net/buildroot/commit/?id=fee29b05bb7db25e37c8a5175ce00dc712554edf [2]: https://git.buildroot.net/buildroot/commit/?id=79b8540d624ac4846ba341b1b9691eccacf0bc05 Signed-off-by: Alexandre PAYEN Cc: Carlos Santos Cc: Thomas Petazzoni [Thomas: - drop commented code in post-build.sh - take into account comments made by Carlos Santos in http://patchwork.ozlabs.org/patch/1143502/] Signed-off-by: Thomas Petazzoni --- board/pc/genimage-efi.cfg | 35 +++++++++++++++++++ board/pc/grub-efi.cfg | 6 ++++ board/pc/post-build.sh | 11 ++++-- board/pc/post-image-efi-gpt.sh | 62 --------------------------------- board/pc/post-image-efi.sh | 6 ++++ configs/pc_x86_64_efi_defconfig | 4 ++- 6 files changed, 58 insertions(+), 66 deletions(-) create mode 100644 board/pc/genimage-efi.cfg create mode 100644 board/pc/grub-efi.cfg delete mode 100755 board/pc/post-image-efi-gpt.sh create mode 100755 board/pc/post-image-efi.sh diff --git a/board/pc/genimage-efi.cfg b/board/pc/genimage-efi.cfg new file mode 100644 index 0000000000..ea15ae5cfb --- /dev/null +++ b/board/pc/genimage-efi.cfg @@ -0,0 +1,35 @@ +image efi-part.vfat { + vfat { + file startup.nsh { + image = "efi-part/startup.nsh" + } + file EFI { + image = "efi-part/EFI" + } + file bzImage { + image = "bzImage" + } + } + size = 16777216 +} + +image disk.img { + hdimage { + gpt = true + } + + partition boot { + image = "efi-part.vfat" + partition-type-uuid = c12a7328-f81f-11d2-ba4b-00a0c93ec93b + offset = 32768 + size = 16777216 + bootable = true + } + + partition root { + partition-type-uuid = 44479540-f297-41b2-9af7-d131d5f0458a + partition-uuid = UUID_TMP + image = "rootfs.ext2" + offset = 16809984 + } +} diff --git a/board/pc/grub-efi.cfg b/board/pc/grub-efi.cfg new file mode 100644 index 0000000000..bd44666404 --- /dev/null +++ b/board/pc/grub-efi.cfg @@ -0,0 +1,6 @@ +set default="0" +set timeout="5" + +menuentry "Buildroot" { + linux /bzImage root=PARTUUID=UUID_TMP rootwait console=tty1 +} diff --git a/board/pc/post-build.sh b/board/pc/post-build.sh index b245cc00c6..552d488160 100755 --- a/board/pc/post-build.sh +++ b/board/pc/post-build.sh @@ -4,7 +4,12 @@ set -e BOARD_DIR=$(dirname "$0") -cp -f "$BOARD_DIR/grub-bios.cfg" "$TARGET_DIR/boot/grub/grub.cfg" +# 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/i386-pc/boot.img" "$BINARIES_DIR" + # Copy grub 1st stage to binaries, required for genimage + cp -f "$HOST_DIR/lib/grub/i387-pc/boot.img" "$BINARIES_DIR" +fi diff --git a/board/pc/post-image-efi-gpt.sh b/board/pc/post-image-efi-gpt.sh deleted file mode 100755 index d2acd8f852..0000000000 --- a/board/pc/post-image-efi-gpt.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/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 </dev/null | sed -n 's/^Filesystem UUID: *\(.*\)/\1/p') +sed -i "s/UUID_TMP/$UUID/g" "$BINARIES_DIR/efi-part/EFI/BOOT/grub.cfg" +sed "s/UUID_TMP/$UUID/g" board/pc/genimage-efi.cfg > "$BINARIES_DIR/genimage-efi.cfg" +support/scripts/genimage.sh -c "$BINARIES_DIR/genimage-efi.cfg" diff --git a/configs/pc_x86_64_efi_defconfig b/configs/pc_x86_64_efi_defconfig index 324de35dff..984fc8f92f 100644 --- a/configs/pc_x86_64_efi_defconfig +++ b/configs/pc_x86_64_efi_defconfig @@ -10,6 +10,7 @@ BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y # Required tools to create bootable media BR2_PACKAGE_HOST_DOSFSTOOLS=y +BR2_PACKAGE_HOST_GENIMAGE=y BR2_PACKAGE_HOST_MTOOLS=y # Bootloader @@ -21,7 +22,8 @@ BR2_TARGET_ROOTFS_EXT2=y BR2_TARGET_ROOTFS_EXT2_4=y BR2_TARGET_ROOTFS_EXT2_SIZE="120M" # BR2_TARGET_ROOTFS_TAR is not set -BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image-efi-gpt.sh" +BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh" +BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image-efi.sh" # Linux headers same as kernel, a 4.18 series BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_18=y