DistroKit Mailinglist
 help / color / mirror / Atom feed
From: Roland Hieber <rhi@pengutronix.de>
To: distrokit@pengutronix.de
Cc: Roland Hieber <rhi@pengutronix.de>
Subject: [DistroKit] [PATCH v2 6/6] images: convert to GPT format
Date: Wed, 11 Oct 2023 12:50:38 +0200	[thread overview]
Message-ID: <20231011105038.1380620-6-rhi@pengutronix.de> (raw)
In-Reply-To: <20231011105038.1380620-1-rhi@pengutronix.de>

The GUID Partition Table format has several advantages over the legacy
MBR format. Especially when we want to make use of systemd-repart
functionality later, the GPT format is a necessity. Therefore, migrate
all images to the GPT format.

For some platforms (Raspberry Pi, AM355x, AT91), we still need a legacy
MBR partition table so that the ROM code can find a bootable partition
(which contains our barebox image). For those cases, transform the image
into a hybrid format containing an MBR at offset 0, which contains the
VFAT boot partition for the ROM loader, and a protective GPT partition
of partition type 0xEE after it to claim the remaining space on the
storage medium for GPT purposes. Then a GPT header is added at the
default GPT offset of 0x200, which defines the boot partition as well as
the root partition, and which is read by Barebox and Linux to boot the
system.

For images that contain a raw barebox image at a fixed offset outside of
a GPT partition, make sure that the GPT does not conflict with the
barebox image, and write only the primary GPT header into the hole
specified by the barebox image (offset 440 to 1K), but move the GPT
partition array to an offset behind the barebox image. (genimage will
then also offset the following partitions accordingly.)

Remove any 'disk-signature' options, which are not compatible with GPT;
genimage will generate a random Disk UUID instead. Also remove any
'partition-type' options, and set the respective partition type GUIDs
specified by the Discoverable Partitions Specification [1], or let
genimage default to the 'linux-generic' partition type.

For the rpi1 image-hdimg, overwrite the upstream hd.config with a
hardcoded genimage config file since it is not possible to build a
hybrid MBR/GPT image with the image recipe from upstream PTXdist.

For the v7a image-hdimg, enable GPT support in the platformconfig menu,
and re-add the respective config lines from the upstream version of the
config file in order to make GPT work.

The images with fixed partition sizes for qemu need to stay below the
size specified in the 'size' option, so decrease the size of the last
partition further to make space for the secondary GPT header, which will
reside in the last block of the image.

Link: [1] https://uapi-group.org/specifications/specs/discoverable_partitions_specification/
Signed-off-by: Roland Hieber <rhi@pengutronix.de>
---
PATCH v2:
 * fix typo in log message
 * use partition-type-uuids from Discoverable Partitions Specification

PATCH v1: https://lore.distrokit.org/distrokit/20231010191631.31141-6-rhi@pengutronix.de
---
 .../platform-mips/config/images/ar9331.config    |  5 ++---
 configs/platform-mips/config/images/malta.config |  5 ++---
 .../platform-mipsel/config/images/malta.config   |  5 ++---
 configs/platform-rpi1/config/images/hd.config    | 16 ++++++++++++++++
 configs/platform-rpi1/platformconfig             |  4 ----
 configs/platform-rpi1/platforms/image-hdimg.in   | 11 +++++++++++
 .../platform-v7a/config/images/at91-sd.config    |  6 +++---
 .../platform-v7a/config/images/beaglebone.config |  8 ++++----
 configs/platform-v7a/config/images/gf.config     |  6 +++---
 configs/platform-v7a/config/images/hd.config     |  4 ++--
 .../platform-v7a/config/images/riotboard.config  |  8 ++++----
 configs/platform-v7a/config/images/rpi2.config   |  8 ++++----
 .../platform-v7a/config/images/sabrelite.config  |  6 +++---
 .../platform-v7a/config/images/udoo-neo.config   |  6 +++---
 .../platform-v7a/config/images/vexpress.config   |  7 +++----
 configs/platform-v7a/platformconfig              |  2 +-
 .../config/images/at91-sd.config                 |  6 +++---
 .../config/images/vexpress.config                |  5 ++---
 .../config/images/espressobin.config             |  4 ++--
 configs/platform-v8a/config/images/rock3a.config |  5 ++---
 20 files changed, 72 insertions(+), 55 deletions(-)
 create mode 100644 configs/platform-rpi1/config/images/hd.config
 create mode 100644 configs/platform-rpi1/platforms/image-hdimg.in

diff --git a/configs/platform-mips/config/images/ar9331.config b/configs/platform-mips/config/images/ar9331.config
index 16122eb26a22..f26627f84cc0 100644
--- a/configs/platform-mips/config/images/ar9331.config
+++ b/configs/platform-mips/config/images/ar9331.config
@@ -3,16 +3,15 @@ image @IMAGE@ {
 	size = 1G
 	hdimage {
 		align = 1M
-		disk-signature = 0x74823abf
 		fill = true
+		partition-table-type = gpt
 	}
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = e9434544-6e2c-47cc-bae2-12d6deafb44c # root-mips
 		size = 512M
 	}
 	partition data {
-		partition-type = 0x83
 		autoresize = true
 	}
 }
diff --git a/configs/platform-mips/config/images/malta.config b/configs/platform-mips/config/images/malta.config
index 16122eb26a22..f26627f84cc0 100644
--- a/configs/platform-mips/config/images/malta.config
+++ b/configs/platform-mips/config/images/malta.config
@@ -3,16 +3,15 @@ image @IMAGE@ {
 	size = 1G
 	hdimage {
 		align = 1M
-		disk-signature = 0x74823abf
 		fill = true
+		partition-table-type = gpt
 	}
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = e9434544-6e2c-47cc-bae2-12d6deafb44c # root-mips
 		size = 512M
 	}
 	partition data {
-		partition-type = 0x83
 		autoresize = true
 	}
 }
diff --git a/configs/platform-mipsel/config/images/malta.config b/configs/platform-mipsel/config/images/malta.config
index 16122eb26a22..c873c7e8b724 100644
--- a/configs/platform-mipsel/config/images/malta.config
+++ b/configs/platform-mipsel/config/images/malta.config
@@ -3,16 +3,15 @@ image @IMAGE@ {
 	size = 1G
 	hdimage {
 		align = 1M
-		disk-signature = 0x74823abf
 		fill = true
+		partition-table-type = gpt
 	}
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 37c58c8a-d913-4156-a25f-48b1b64e07f0 # root-mips-le
 		size = 512M
 	}
 	partition data {
-		partition-type = 0x83
 		autoresize = true
 	}
 }
diff --git a/configs/platform-rpi1/config/images/hd.config b/configs/platform-rpi1/config/images/hd.config
new file mode 100644
index 000000000000..7b659a3130ad
--- /dev/null
+++ b/configs/platform-rpi1/config/images/hd.config
@@ -0,0 +1,16 @@
+image @IMAGE@ {
+	hdimage {
+		align = 1M
+		partition-table-type = hybrid
+	}
+	partition boot-vfat {
+		image = boot.vfat
+		partition-type-uuid = F
+		partition-type = 0xc
+		bootable = true
+	}
+	partition root {
+		image = root.ext2
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
+	}
+}
diff --git a/configs/platform-rpi1/platformconfig b/configs/platform-rpi1/platformconfig
index 67e5f161cd78..8fd1b1983015 100644
--- a/configs/platform-rpi1/platformconfig
+++ b/configs/platform-rpi1/platformconfig
@@ -230,10 +230,6 @@ PTXCONF_IMAGE_BOOT_VFAT=y
 PTXCONF_IMAGE_BOOT_VFAT_GPU_MEM=16
 # PTXCONF_IMAGE_HD_VDI is not set
 PTXCONF_IMAGE_HDIMG=y
-# PTXCONF_IMAGE_HDIMG_GPT is not set
-# PTXCONF_IMAGE_HDIMG_NONE is not set
-# PTXCONF_IMAGE_HDIMG_BAREBOX is not set
-PTXCONF_IMAGE_HDIMG_VFAT=y
 PTXCONF_IMAGE_KERNEL=y
 
 #
diff --git a/configs/platform-rpi1/platforms/image-hdimg.in b/configs/platform-rpi1/platforms/image-hdimg.in
new file mode 100644
index 000000000000..052e7e71df38
--- /dev/null
+++ b/configs/platform-rpi1/platforms/image-hdimg.in
@@ -0,0 +1,11 @@
+## SECTION=image
+
+config IMAGE_HDIMG
+	bool
+	select HOST_GENIMAGE
+	select IMAGE_BOOT_VFAT
+	select IMAGE_ROOT_EXT
+	prompt "Generate images/hd.img"
+        help
+	  Build a harddisk root image. The image will contain one partition
+	  containing the root.ext2 and a corresponding partition table.
diff --git a/configs/platform-v7a/config/images/at91-sd.config b/configs/platform-v7a/config/images/at91-sd.config
index 641db071224f..a892868cd7b7 100644
--- a/configs/platform-v7a/config/images/at91-sd.config
+++ b/configs/platform-v7a/config/images/at91-sd.config
@@ -9,19 +9,19 @@ image @IMAGE@-boot.vfat {
 image @IMAGE@ {
 	hdimage {
 		align = 1M
-		disk-signature = 0x67823abf
+		partition-table-type = hybrid
 	}
 	partition boot {
 		image = @IMAGE@-boot.vfat
 		partition-type = 0xc
+		partition-type-uuid = F
 		bootable = true
 	}
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 	partition data {
-		partition-type = 0x83
 		size = 512M
 	}
 }
diff --git a/configs/platform-v7a/config/images/beaglebone.config b/configs/platform-v7a/config/images/beaglebone.config
index 07d251bfbe69..7509f501ec86 100644
--- a/configs/platform-v7a/config/images/beaglebone.config
+++ b/configs/platform-v7a/config/images/beaglebone.config
@@ -9,23 +9,23 @@ image beaglebone-boot.vfat {
 image @IMAGE@ {
 	hdimage {
 		align = 1M
-		disk-signature = 0xabe26147
+		partition-table-type = hybrid
 	}
 	partition boot {
 		image = beaglebone-boot.vfat
 		partition-type = 0xc
+		partition-type-uuid = F
 		bootable = true
 	}
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 	partition root-B {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 	partition data {
-		partition-type = 0x83
 		size = 512M
 	}
 }
diff --git a/configs/platform-v7a/config/images/gf.config b/configs/platform-v7a/config/images/gf.config
index fbaddf15f527..6ec1d90db659 100644
--- a/configs/platform-v7a/config/images/gf.config
+++ b/configs/platform-v7a/config/images/gf.config
@@ -9,19 +9,19 @@ image gf-boot.vfat {
 image @IMAGE@ {
 	hdimage {
 		align = 1M
-		disk-signature = 0x74823abf
+		partition-table-type = hybrid
 	}
 	partition boot {
 		image = gf-boot.vfat
 		partition-type = 0xc
+		partition-type-uuid = F
 		bootable = true
 	}
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 	partition data {
-		partition-type = 0x83
 		size = 512M
 	}
 }
diff --git a/configs/platform-v7a/config/images/hd.config b/configs/platform-v7a/config/images/hd.config
index 03cf37a0dbcf..dba48ca106ae 100644
--- a/configs/platform-v7a/config/images/hd.config
+++ b/configs/platform-v7a/config/images/hd.config
@@ -4,11 +4,11 @@
 image @IMAGE@ {
 	hdimage {
 		align = 1M
-		disk-signature = 0xdfb978e3
+		partition-table-type = "@PARTITION_TABLE_TYPE@"
 	}
 	@BOOTLOADER_PARTITIONS@
 	partition root {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 }
diff --git a/configs/platform-v7a/config/images/riotboard.config b/configs/platform-v7a/config/images/riotboard.config
index f311fd5e41b0..8ce12a07c71c 100644
--- a/configs/platform-v7a/config/images/riotboard.config
+++ b/configs/platform-v7a/config/images/riotboard.config
@@ -1,7 +1,8 @@
 image @IMAGE@ {
 	hdimage {
 		align = 1M
-		disk-signature = 0x67bac764
+		partition-table-type = gpt
+		gpt-location = 2M
 	}
 
 	partition barebox {
@@ -13,16 +14,15 @@ image @IMAGE@ {
 
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 
 	partition root-B {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 
 	partition data {
-		partition-type = 0x83
 		size = 512M
 	}
 }
diff --git a/configs/platform-v7a/config/images/rpi2.config b/configs/platform-v7a/config/images/rpi2.config
index eebf7052713f..71baae3bb8be 100644
--- a/configs/platform-v7a/config/images/rpi2.config
+++ b/configs/platform-v7a/config/images/rpi2.config
@@ -10,24 +10,24 @@ image rpi2-boot.vfat {
 image @IMAGE@ {
 	hdimage {
 		align = 1M
-		disk-signature = 0xbedf7893
+		partition-table-type = hybrid
 	}
 	partition boot {
 		offset = 4M
 		image = rpi2-boot.vfat
 		partition-type = 0xc
+		partition-type-uuid = F
 		bootable = true
 	}
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 	partition root-B {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 	partition data {
-		partition-type = 0x83
 		size = 512M
 	}
 }
diff --git a/configs/platform-v7a/config/images/sabrelite.config b/configs/platform-v7a/config/images/sabrelite.config
index 29e6b5f5a44a..2c7109c5c310 100644
--- a/configs/platform-v7a/config/images/sabrelite.config
+++ b/configs/platform-v7a/config/images/sabrelite.config
@@ -1,7 +1,8 @@
 image @IMAGE@ {
 	hdimage {
 		align = 1M
-		disk-signature = 0x67bac764
+		partition-table-type = gpt
+		gpt-location = 2M
 	}
 
 	partition barebox {
@@ -13,10 +14,9 @@ image @IMAGE@ {
 
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 	partition data {
-		partition-type = 0x83
 		size = 512M
 	}
 }
diff --git a/configs/platform-v7a/config/images/udoo-neo.config b/configs/platform-v7a/config/images/udoo-neo.config
index da677757804d..f801b5524baf 100644
--- a/configs/platform-v7a/config/images/udoo-neo.config
+++ b/configs/platform-v7a/config/images/udoo-neo.config
@@ -1,7 +1,8 @@
 image @IMAGE@ {
 	hdimage {
 		align = 1M
-		disk-signature = 0x374ac764
+		partition-table-type = gpt
+		gpt-location = 2M
 	}
 
 	partition barebox {
@@ -13,10 +14,9 @@ image @IMAGE@ {
 
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 	partition data {
-		partition-type = 0x83
 		size = 512M
 	}
 }
diff --git a/configs/platform-v7a/config/images/vexpress.config b/configs/platform-v7a/config/images/vexpress.config
index 5c523ae1707d..87eaedfe8b82 100644
--- a/configs/platform-v7a/config/images/vexpress.config
+++ b/configs/platform-v7a/config/images/vexpress.config
@@ -3,21 +3,20 @@ image @IMAGE@ {
 	size = 256M
 	hdimage {
 		align = 1M
-		disk-signature = 0x74823abf
 		fill = true
+		partition-table-type = gpt
 	}
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 		size = 96M
 	}
 	partition root-B {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 		size = 96M
 	}
 	partition data {
-		partition-type = 0x83
 		autoresize = true
 	}
 }
diff --git a/configs/platform-v7a/platformconfig b/configs/platform-v7a/platformconfig
index 1e83fb3620cd..63e98e7ff4af 100644
--- a/configs/platform-v7a/platformconfig
+++ b/configs/platform-v7a/platformconfig
@@ -242,7 +242,7 @@ PTXCONF_IMAGE_BEAGLEBONE=y
 PTXCONF_IMAGE_GF=y
 # PTXCONF_IMAGE_HD_VDI is not set
 PTXCONF_IMAGE_HDIMG=y
-# PTXCONF_IMAGE_HDIMG_GPT is not set
+PTXCONF_IMAGE_HDIMG_GPT=y
 PTXCONF_IMAGE_HDIMG_NONE=y
 # PTXCONF_IMAGE_HDIMG_BAREBOX is not set
 # PTXCONF_IMAGE_HDIMG_VFAT is not set
diff --git a/configs/platform-v7a_noneon/config/images/at91-sd.config b/configs/platform-v7a_noneon/config/images/at91-sd.config
index caecd247065a..9bf369ec9c2b 100644
--- a/configs/platform-v7a_noneon/config/images/at91-sd.config
+++ b/configs/platform-v7a_noneon/config/images/at91-sd.config
@@ -9,19 +9,19 @@ image @IMAGE@-boot.vfat {
 image @IMAGE@ {
 	hdimage {
 		align = 1M
-		disk-signature = 0x67823abf
+		partition-table-type = hybrid
 	}
 	partition boot {
 		image = @IMAGE@-boot.vfat
 		partition-type = 0xc
+		partition-type-uuid = F
 		bootable = true
 	}
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 	}
 	partition data {
-		partition-type = 0x83
 		size = 512M
 	}
 }
diff --git a/configs/platform-v7a_noneon/config/images/vexpress.config b/configs/platform-v7a_noneon/config/images/vexpress.config
index 54c47a42c8bf..0712ad82ce96 100644
--- a/configs/platform-v7a_noneon/config/images/vexpress.config
+++ b/configs/platform-v7a_noneon/config/images/vexpress.config
@@ -3,16 +3,15 @@ image @IMAGE@ {
 	size = 256M
 	hdimage {
 		align = 1M
-		disk-signature = 0x74823abf
 		fill = true
+		partition-table-type = gpt
 	}
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 		size = 192M
 	}
 	partition data {
-		partition-type = 0x83
 		autoresize = true
 	}
 }
diff --git a/configs/platform-v8a/config/images/espressobin.config b/configs/platform-v8a/config/images/espressobin.config
index c4ab201691a9..188bb9ae4d9e 100644
--- a/configs/platform-v8a/config/images/espressobin.config
+++ b/configs/platform-v8a/config/images/espressobin.config
@@ -1,14 +1,14 @@
 image @IMAGE@ {
 	hdimage {
 		align = 1M
+		partition-table-type = gpt
 	}
 	partition root-A {
 		image = root.ext2
-		partition-type = 0x83
+		partition-type-uuid = 69dad710-2ce4-4e3c-b16c-21a1d49abed3 # root-arm
 		size = 512M
 	}
 	partition data {
-		partition-type = 0x83
 		size = 512M
 	}
 }
diff --git a/configs/platform-v8a/config/images/rock3a.config b/configs/platform-v8a/config/images/rock3a.config
index 522d82cdc9c9..d6d5ada84426 100644
--- a/configs/platform-v8a/config/images/rock3a.config
+++ b/configs/platform-v8a/config/images/rock3a.config
@@ -1,7 +1,7 @@
 image @IMAGE@ {
 	hdimage {
 		align = 1M
-		disk-signature = 0xf5feaddc
+		partition-table-type = gpt
 	}
 	partition boot1 {
 		offset = 32k
@@ -24,10 +24,9 @@ image @IMAGE@ {
 	partition root-A {
 		offset = 5M
 		image = "root.ext2"
-		partition-type = 0x83
+		partition-type-uuid = b921b045-1df0-41c3-af44-4c6f280d3fae # root-arm64
 	}
 	partition data {
-		partition-type = 0x83
 		size = 512M
 	}
 }
-- 
2.39.2




  parent reply	other threads:[~2023-10-11 10:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-11 10:50 [DistroKit] [PATCH v2 1/6] v7a: image-stm32mp: use 'partition-table-type' option instead of 'gpt' Roland Hieber
2023-10-11 10:50 ` [DistroKit] [PATCH v2 2/6] images: use 'partition-table-type' option instead of 'partition-table' Roland Hieber
2023-10-11 10:50 ` [DistroKit] [PATCH v2 3/6] v7a: barebox: pass root=mmcblkXpN instead of root=PARTUUID=… to kernel Roland Hieber
2023-10-11 10:50 ` [DistroKit] [PATCH v2 4/6] v7a: barebox: enable GUID Partition Table support Roland Hieber
2023-10-11 10:50 ` [DistroKit] [PATCH v2 5/6] images: remove qemu size hack Roland Hieber
2023-10-11 10:50 ` Roland Hieber [this message]
2023-10-18  9:17 ` [DistroKit] [PATCH v2 1/6] v7a: image-stm32mp: use 'partition-table-type' option instead of 'gpt' Robert Schwebel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231011105038.1380620-6-rhi@pengutronix.de \
    --to=rhi@pengutronix.de \
    --cc=distrokit@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox