diff mbox series

[v2] configs/pc: add a configuration to build a UEFI+GPT image

Message ID 20180929031609.8939-1-casantos@datacom.com.br
State Accepted
Headers show
Series [v2] configs/pc: add a configuration to build a UEFI+GPT image | expand

Commit Message

Carlos Santos Sept. 29, 2018, 3:16 a.m. UTC
This is 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.

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 <casantos@datacom.com.br>
Acked-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
Changes v1->v2:
Fix commit message ("ane", spurious "the").
---
 board/pc/post-image-efi-gpt.sh      | 62 ++++++++++++++++++++++++++++
 board/pc/readme.txt                 |  6 ++-
 configs/pc_x86_64_efi_gpt_defconfig | 64 +++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+), 1 deletion(-)
 create mode 100755 board/pc/post-image-efi-gpt.sh
 create mode 100644 configs/pc_x86_64_efi_gpt_defconfig

Comments

Thomas Petazzoni Feb. 6, 2019, 4:43 p.m. UTC | #1
Hello,

On Sat, 29 Sep 2018 00:16:09 -0300
Carlos Santos <casantos@datacom.com.br> wrote:

> This is 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.
> 
> 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 <casantos@datacom.com.br>
> Acked-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> ---
> Changes v1->v2:
> Fix commit message ("ane", spurious "the").
> ---
>  board/pc/post-image-efi-gpt.sh      | 62 ++++++++++++++++++++++++++++
>  board/pc/readme.txt                 |  6 ++-
>  configs/pc_x86_64_efi_gpt_defconfig | 64 +++++++++++++++++++++++++++++
>  3 files changed, 131 insertions(+), 1 deletion(-)
>  create mode 100755 board/pc/post-image-efi-gpt.sh
>  create mode 100644 configs/pc_x86_64_efi_gpt_defconfig

After discussing with Arnout, we decided that there was not much point
in having an EFI configuration on one side and an EFI+GPT configuration
on the other side. Indeed, all EFI systems support GPT partition
tables. So I just took your configuration, and used it to replace the
existing pc_x86_64_efi_defconfig. I did the related adjustements as
well (hopefully correctly), such as dropping from
board/pc/post-build.sh the bits that are no longer needed.

Feel free to give it a test!

Long term of course, having support for GPT in genimage would be nice.

Thanks!

Thomas
diff mbox series

Patch

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 <<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=notrunc
diff --git a/board/pc/readme.txt b/board/pc/readme.txt
index ca3b5123c1..73d8c24838 100644
--- a/board/pc/readme.txt
+++ b/board/pc/readme.txt
@@ -9,10 +9,14 @@  Bare PC sample config
 
   $ make pc_x86_64_bios_defconfig
 
-  Or for EFI:
+  For EFI-based boot strategy on a MBR-partitioned disk:
 
   $ make pc_x86_64_efi_defconfig
 
+  Or for EFI-based boot strategy on a GPT-partitioned disk:
+
+  $ make pc_x86_64_efi_gpt_defconfig
+
   Add any additional packages required and build:
 
   $ make
diff --git a/configs/pc_x86_64_efi_gpt_defconfig b/configs/pc_x86_64_efi_gpt_defconfig
new file mode 100644
index 0000000000..8be19a75c9
--- /dev/null
+++ b/configs/pc_x86_64_efi_gpt_defconfig
@@ -0,0 +1,64 @@ 
+# Architecture
+BR2_x86_64=y
+
+# Toolchain, required for eudev (to autoload drivers)
+BR2_TOOLCHAIN_BUILDROOT_WCHAR=y
+
+# System
+BR2_TARGET_GENERIC_GETTY_PORT="tty1"
+BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y
+
+# Required tools to create bootable media
+BR2_PACKAGE_HOST_DOSFSTOOLS=y
+BR2_PACKAGE_HOST_MTOOLS=y
+
+# Bootloader
+BR2_TARGET_GRUB2=y
+BR2_TARGET_GRUB2_X86_64_EFI=y
+
+# Filesystem / image
+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"
+
+# Linux headers same as kernel, a 4.13 series
+BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_13=y
+
+# Kernel
+BR2_LINUX_KERNEL=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.13.8"
+BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/pc/linux.config"
+BR2_LINUX_KERNEL_INSTALL_TARGET=y
+
+# Firmware
+BR2_PACKAGE_LINUX_FIRMWARE=y
+BR2_PACKAGE_LINUX_FIRMWARE_ATHEROS_9170=y
+BR2_PACKAGE_LINUX_FIRMWARE_ATHEROS_9271=y
+BR2_PACKAGE_LINUX_FIRMWARE_IWLWIFI_3160=y
+BR2_PACKAGE_LINUX_FIRMWARE_IWLWIFI_3168=y
+BR2_PACKAGE_LINUX_FIRMWARE_IWLWIFI_5000=y
+BR2_PACKAGE_LINUX_FIRMWARE_IWLWIFI_6000G2A=y
+BR2_PACKAGE_LINUX_FIRMWARE_IWLWIFI_6000G2B=y
+BR2_PACKAGE_LINUX_FIRMWARE_IWLWIFI_7260=y
+BR2_PACKAGE_LINUX_FIRMWARE_IWLWIFI_7265D=y
+BR2_PACKAGE_LINUX_FIRMWARE_IWLWIFI_8000C=y
+BR2_PACKAGE_LINUX_FIRMWARE_IWLWIFI_8265=y
+BR2_PACKAGE_LINUX_FIRMWARE_RALINK_RT73=y
+BR2_PACKAGE_LINUX_FIRMWARE_RALINK_RT2XX=y
+BR2_PACKAGE_LINUX_FIRMWARE_RTL_8169=y
+BR2_PACKAGE_LINUX_FIRMWARE_RTL_81XX=y
+BR2_PACKAGE_LINUX_FIRMWARE_RTL_87XX=y
+BR2_PACKAGE_LINUX_FIRMWARE_RTL_88XX=y
+
+# Packages
+#
+# Use connman so that networking setup is simpler, via connmanctl tool
+# acpid is for seamless power button support
+BR2_PACKAGE_ACPID=y
+BR2_PACKAGE_CONNMAN=y
+BR2_PACKAGE_CONNMAN_CLIENT=y
+BR2_PACKAGE_CONNMAN_WIFI=y