configs/pc_x86_64_efi: add GPT partition table support.
PATCH 1/1 configs/pc_x86_64_efi: add GPT partition table support.
From: Alexandre PAYEN <[email protected]>
Based on commit fee29b05bb7db25e37c8a5175ce00dc712554edf[1]. It add the use of GPT partition table on pc_x86_64_efi. This commit removed the use of genimage and replace it with a shell script.
Since version 11, genimage support GPT partition table.
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
---
I hope it's the proper way to do it.
Actually, just adding gpt = true in the genimage-efi.cfg work also. But, doing so, the UUID will not be the same in grub bootloader and disk image ...
--- board/pc/genimage-efi.cfg | 39 +++++++++++++++++++++ board/pc/grub-efi.cfg | 6 ++++ board/pc/post-build.sh | 14 ++++++-- board/pc/post-image-efi-gpt.sh | 62 --------------------------------- board/pc/post-image-efi.sh | 6 ++++ configs/pc_x86_64_efi_defconfig | 5 ++- 6 files changed, 67 insertions(+), 65 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
board/pc/genimage-efi.cfg new file +39 -0
@@ -0,0 +1,39 @@ +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 + } + + +}
board/pc/grub-efi.cfg new file +6 -0
@@ -0,0 +1,6 @@ +set default="0" +set timeout="5" + +menuentry "Buildroot" { + linux /bzImage root=PARTUUID=UUID_TMP rootwait console=tty1 +}
board/pc/post-build.sh +12 -2
@@ -4,7 +4,17 @@ 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/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/i386-pc/boot.img" "$BINARIES_DIR" +#cp -f "$HOST_DIR/lib/grub/i386-pc/boot.img" "$BINARIES_DIR"
board/pc/post-image-efi-gpt.sh deleted +0 -62
62 lines not on this page · raw message
board/pc/post-image-efi.sh new file +6 -0
@@ -0,0 +1,6 @@ +#!/bin/sh + +UUID=`dumpe2fs test/images/rootfs.ext2 | grep UUID | cut -f 2 -d ':' | sed 's/ //g'` +sed -i "s/UUID_TMP/$UUID/g" $BINARIES_DIR/efi-part/EFI/BOOT/grub.cfg +sed "s/UUID_TMP/$UUID/g" $3 > $BINARIES_DIR/genimage-efi.cfg +sh support/scripts/genimage.sh $2 $BINARIES_DIR/genimage-efi.cfg
configs/pc_x86_64_efi_defconfig +4 -1
@@ -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,9 @@ 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" +BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/pc/genimage-efi.cfg" # Linux headers same as kernel, a 4.18 series BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_18=y
Signature · 1 line
2.21.0
PATCH 1/1 configs/pc_x86_64_efi: add GPT partition table support.
Quoted 9 lines · Aalx
From: Alexandre PAYEN <[email protected]>
Based on commit fee29b05bb7db25e37c8a5175ce00dc712554edf[1]. It add the use of GPT partition table on
pc_x86_64_efi. This commit removed the use of genimage and replace it with a shell script.Since version 11, genimage support GPT partition table.
This is great. That script was not something I was exactly proud of. :-)
Quoted 187 lines
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=79b8540d624ac4846ba341b1b9691eccacf0bc05Signed-off-by Alexandre PAYEN <[email protected]>Cc Carlos Santos <[email protected]>Cc Thomas Petazzoni <[email protected]>---
I hope it's the proper way to do it.
Actually, just addinggpt = truein the genimage-efi.cfg work also. But, doing so, the UUID will not be the same in grub bootloader and disk image ...--- board/pc/genimage-efi.cfg | 39 +++++++++++++++++++++ board/pc/grub-efi.cfg | 6 ++++ board/pc/post-build.sh | 14 ++++++-- board/pc/post-image-efi-gpt.sh | 62 --------------------------------- board/pc/post-image-efi.sh | 6 ++++ configs/pc_x86_64_efi_defconfig | 5 ++- 6 files changed, 67 insertions(+), 65 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.shboard/pc/genimage-efi.cfg new file +39
-0@@ -0,0 +1,39 @@ +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 + } + + +}board/pc/grub-efi.cfg new file +6
-0@@ -0,0 +1,6 @@ +set default="0" +set timeout="5" + +menuentry "Buildroot" { + linux /bzImage root=PARTUUID=UUID_TMP rootwait console=tty1 +}board/pc/post-build.sh +12
-2@@ -4,7 +4,17 @@ 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/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/i386-pc/boot.img" "$BINARIES_DIR" +#cp -f "$HOST_DIR/lib/grub/i386-pc/boot.img" "$BINARIES_DIR"board/pc/post-image-efi-gpt.sh deleted +0
-62@@ -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 <<EOF -set default="0" -set timeout="5" - -menuentry "Buildroot" { - linux /bzImage root=PARTUUID=$root_part_uuid rootwait console=tty1 -} -EOF - -# Create EFI system partition -rm -f efi-part.vfat -dd if=/dev/zero of=efi-part.vfat bs=512 count=0 seek=$efi_part_size -mkdosfs efi-part.vfat -mcopy -bsp -i efi-part.vfat efi-part/startup.nsh ::startup.nsh -mcopy -bsp -i efi-part.vfat efi-part/EFI ::EFI -mcopy -bsp -i efi-part.vfat bzImage ::bzImage - -rm -f disk.img -dd if=/dev/zero of=disk.img bs=512 count=0 seek=$image_size - -sfdisk disk.img <<EOF -label: gpt -label-id: $(uuidgen) -device: /dev/foobar0 -unit: sectors -first-lba: $first_lba -last-lba: $last_lba - -/dev/foobar0p1 : start=$efi_part_start, size=$efi_part_size, type=$esp_type, uuid=$efi_part_uuid, name="efi-part.vfat" -/dev/foobar0p2 : start=$root_part_start, size=$root_part_size, type=$linux_type, uuid=$root_part_uuid, name="rootfs.ext2" -EOF - -dd if=efi-part.vfat of=disk.img bs=512 count=$efi_part_size seek=$efi_part_start conv=notrunc -dd if=rootfs.ext2 of=disk.img bs=512 count=$root_part_size seek=$root_part_start conv=notruncboard/pc/post-image-efi.sh new file +0
-0
board/pc/post-image-efi.sh line 3
Quoted 3 lines
board/pc/post-image-efi.sh new file +3
-0@@ -0,0 +1,6 @@ +#!/bin/sh + +UUID=`dumpe2fs test/images/rootfs.ext2 | grep UUID | cut -f 2 -d ':' | sed 's/ //g'`
No need to use grep, cut and sed, see below.
board/pc/post-image-efi.sh line 5
Quoted 2 lines
board/pc/post-image-efi.sh new file +2
-0+sed -i "s/UUID_TMP/$UUID/g" $BINARIES_DIR/efi-part/EFI/BOOT/grub.cfg +sed "s/UUID_TMP/$UUID/g" $3 > $BINARIES_DIR/genimage-efi.cfg
No need to pass board/pc/genimage-efi.cfg as an argument to the script.
board/pc/post-image-efi.sh line 6
Quoted 1 line
board/pc/post-image-efi.sh new file +1
-0+sh support/scripts/genimage.sh $2 $BINARIES_DIR/genimage-efi.cfg
genimage.sh is already an executable bash script. Using sh may cause problems in the future.
After some polishing and passing trough shellcheck, it becomes:
---8<---
#!/bin/sh
# exit on any failure set -e
UUID=$(dumpe2fs "$BINARIES_DIR/rootfs.ext2" 2>/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"
---8<---
Quoted 13 lines
configs/pc_x86_64_efi_defconfig +1
-0@@ -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
configs/pc_x86_64_efi_defconfig BR2_TARGET_ROOTFS_EXT2=y · line 27
Quoted 7 lines
configs/pc_x86_64_efi_defconfig +3
-1@@ -21,7 +22,9 @@ 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" +BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/pc/genimage-efi.cfg"
BR2_ROOTFS_POST_SCRIPT_ARGS is not necessary (see above)
Quoted 9 lines
configs/pc_x86_64_efi_defconfig +0
-1# Linux headers same as kernel, a 4.18 series BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_18=y --2.21.0
_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Sorry for the terribly late review.
Signature · 1 line
Carlos Santos <[email protected]>
PATCH 1/1 configs/pc_x86_64_efi: add GPT partition table support.
In reply to AalxQuoted 16 lines · On Wed, 7 Aug 2019 15:54:57 +0200 Aalx <[email protected]> wrote:
From: Alexandre PAYEN <[email protected]>
Based on commit fee29b05bb7db25e37c8a5175ce00dc712554edf[1]. It add the use of GPT partition table on
pc_x86_64_efi. This commit removed the use of genimage and replace it with a shell script.Since version 11, genimage support GPT partition table.
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.
Quoted 6 lines
[1]: https://git.buildroot.net/buildroot/commit/?id=fee29b05bb7db25e37c8a5175ce00dc712554edf
[2]: https://git.buildroot.net/buildroot/commit/?id=79b8540d624ac4846ba341b1b9691eccacf0bc05Signed-off-by Alexandre PAYEN <[email protected]>Cc Carlos Santos <[email protected]>Cc Thomas Petazzoni <[email protected]>
So, I kind of screwed up: I applied this version of the patch, taking into account the comments from Carlos, and then only realized that Carlos has sent a v2.
From a quick look, Carlos v2 seems identical to the changes I've done to this v1.
Carlos, could you double check that what I have applied is OK ? I did a test build, and booted under Qemu and it worked fine here.
Thanks!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 1/1 configs/pc_x86_64_efi: add GPT partition table support.
In reply to AalxHello,
(Resending with Carlos new e-mail address)
Quoted 16 lines · On Wed, 7 Aug 2019 15:54:57 +0200 Aalx <[email protected]> wrote:
From: Alexandre PAYEN <[email protected]>
Based on commit fee29b05bb7db25e37c8a5175ce00dc712554edf[1]. It add the use of GPT partition table on
pc_x86_64_efi. This commit removed the use of genimage and replace it with a shell script.Since version 11, genimage support GPT partition table.
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.
Quoted 6 lines
[1]: https://git.buildroot.net/buildroot/commit/?id=fee29b05bb7db25e37c8a5175ce00dc712554edf
[2]: https://git.buildroot.net/buildroot/commit/?id=79b8540d624ac4846ba341b1b9691eccacf0bc05Signed-off-by Alexandre PAYEN <[email protected]>Cc Carlos Santos <[email protected]>Cc Thomas Petazzoni <[email protected]>
So, I kind of screwed up: I applied this version of the patch, taking into account the comments from Carlos, and then only realized that Carlos has sent a v2.
From a quick look, Carlos v2 seems identical to the changes I've done to this v1.
Carlos, could you double check that what I have applied is OK ? I did a test build, and booted under Qemu and it worked fine here.
Thanks!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 1/1 configs/pc_x86_64_efi: add GPT partition table support.
Quoted 41 lines · Thomas Petazzoni
Hello,
(Resending with Carlos new e-mail address)
Quoted 16 lines · On Wed, 7 Aug 2019 15:54:57 +0200 Aalx <[email protected]> wrote:
From: Alexandre PAYEN <[email protected]>
Based on commit fee29b05bb7db25e37c8a5175ce00dc712554edf[1]. It add the use of GPT partition table on
pc_x86_64_efi. This commit removed the use of genimage and replace it with a shell script.Since version 11, genimage support GPT partition table.
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.Quoted 6 lines
[1]: https://git.buildroot.net/buildroot/commit/?id=fee29b05bb7db25e37c8a5175ce00dc712554edf
[2]: https://git.buildroot.net/buildroot/commit/?id=79b8540d624ac4846ba341b1b9691eccacf0bc05Signed-off-by Alexandre PAYEN <[email protected]>Cc Carlos Santos <[email protected]>Cc Thomas Petazzoni <[email protected]>So, I kind of screwed up: I applied this version of the patch, taking into account the comments from Carlos, and then only realized that Carlos has sent a v2.
From a quick look, Carlos v2 seems identical to the changes I've done to this v1.
Carlos, could you double check that what I have applied is OK ? I did a test build, and booted under Qemu and it worked fine here.
Quoted 7 lines
Thanks!
Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
It's OK. The "set -e" at the beginning of board/pc/post-image-efi.sh is nice to have but not essential.
Signature · 1 line
Carlos Santos <[email protected]>