Skip to contentSkip to conversation

SPL EBBR - EFI System Partition support

PATCH Superseded Mayuresh Chitale 4 participants 10 messages Sep 14, 2023 – Sep 21, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover SPL EBBR - EFI System Partition support

This series adds support to locate an EFI System Partition on a disk and boot the next stage from such a parition if found. The next stage image is expected to be under the FIRMWARE directory as described in the EBBR specification [1]. Also update the spl_blk_fs and spl_fat drivers to prefer booting from ESP and fall back to the configured parition in case of a failure.

These patches are built on top of the following series from Sean Anderson:
https://lists.denx.de/pipermail/u-boot/2023-August/525665.html

[1] : https://github.com/ARM-software/ebbr/blob/854ba0e68590102667b84a5ba4e0b076a3f5f2cb/source/chapter4-firmware-media.rst

The patches are also present in the branch below:
https://github.com/mdchitale/u-boot/tree/mchitale_spl_ebbr_v1

Mayuresh Chitale (2):
part: Add a function to find ESP partition
spl: Add support for booting from ESP

 common/spl/Kconfig      |  7 +++++
 common/spl/spl_blk_fs.c | 61 +++++++++++++++++++++++++++++------------
 common/spl/spl_fat.c    | 34 ++++++++++++++++++++---
 disk/part.c             | 16 +++++++++++
 include/part.h          | 10 +++++++
 5 files changed, 107 insertions(+), 21 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 part: Add a function to find ESP partition

If a disk has an EFI system partition (ESP) then it can be used to locate the boot files. Add a function to find the ESP.

---
 disk/part.c    | 16 ++++++++++++++++
 include/part.h | 10 ++++++++++
 2 files changed, 26 insertions(+)
disk/part.c +16 -0
index 72241b7b23..2be0866671 100644
@@ -841,3 +841,19 @@ int part_get_bootable(struct blk_desc *desc)
 
 	return 0;
 }
+
+int part_get_esp(struct blk_desc *desc)
+{
+	struct disk_partition info;
+	int p;
+
+	for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+		int ret;
+
+		ret = part_get_info(desc, p, &info);
+		if (!ret && (info.bootable & PART_EFI_SYSTEM_PARTITION))
+			return p;
+	}
+
+	return 0;
+}
include/part.h +10 -0
index db34bc6bb7..036f9fd762 100644
@@ -689,6 +689,13 @@ int part_get_type_by_name(const char *name);
  * @return first bootable partition, or 0 if there is none
  */
 int part_get_bootable(struct blk_desc *desc);
+/**
+ * part_get_esp() - Find the EFI system partition
+ *
+ * @desc: Block-device descriptor
+ * @Return the EFI system partition, or 0 if there is none
+ */
+int part_get_esp(struct blk_desc *desc);
 
 #else
 static inline int part_driver_get_count(void)
@@ -700,6 +707,9 @@ static inline struct part_driver *part_driver_get_first(void)
 static inline bool part_get_bootable(struct blk_desc *desc)
 { return false; }
 
+static int part_get_esp(struct blk_desc *desc)
+{ return 0; }
+
 #endif /* CONFIG_PARTITIONS */
 
 #endif /* _PART_H */
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v1 1/2] part: Add a function to find ESP partition

Quoted 39 lines · Mayuresh Chitale

If a disk has an EFI system partition (ESP) then it can be used to locate the boot files. Add a function to find the ESP.

---
 disk/part.c    | 16 ++++++++++++++++
 include/part.h | 10 ++++++++++
 2 files changed, 26 insertions(+)
disk/part.c +16 -0
index 72241b7b23..2be0866671 100644
@@ -841,3 +841,19 @@ int part_get_bootable(struct blk_desc *desc)
 
 	return 0;
 }
+
+int part_get_esp(struct blk_desc *desc)
+{
+	struct disk_partition info;
+	int p;
+
+	for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+		int ret;
+
+		ret = part_get_info(desc, p, &info);
+		if (!ret && (info.bootable & PART_EFI_SYSTEM_PARTITION))
+			return p;
+	}
+
+	return 0;
+}
include/part.h +0 -0
index db34bc6bb7..036f9fd762 100644

include/part.h int part_get_type_by_name(const char *name); · line 692

Quoted 4 lines
include/part.h +1 -0
@@ -689,6 +689,13 @@ int part_get_type_by_name(const char *name);
  * @return first bootable partition, or 0 if there is none
  */
 int part_get_bootable(struct blk_desc *desc);
+/**

Missing blank line?

Signature · 1 line
Tom
#3 lore raw

Re: [PATCH v1 1/2] part: Add a function to find ESP partition

Quoted 40 lines · Tom Rini
Quoted 39 lines · Mayuresh Chitale

If a disk has an EFI system partition (ESP) then it can be used to locate the boot files. Add a function to find the ESP.

Quoted 1 line
---
 disk/part.c    | 16 ++++++++++++++++
 include/part.h | 10 ++++++++++
 2 files changed, 26 insertions(+)
disk/part.c +11 -0
index 72241b7b23..2be0866671 100644
@@ -841,3 +841,19 @@ int part_get_bootable(struct blk_desc *desc)
 
 	return 0;
 }
+
+int part_get_esp(struct blk_desc *desc)
+{
+	struct disk_partition info;
+	int p;
+
+	for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+		int ret;
+
+		ret = part_get_info(desc, p, &info);
+		if (!ret && (info.bootable &

PART_EFI_SYSTEM_PARTITION))

disk/part.c +5 -0
+			return p;
+	}
+
+	return 0;
+}
include/part.h +0 -1
index db34bc6bb7..036f9fd762 100644
--- a/include/part.h
Quoted 9 lines

include/part.h int part_get_type_by_name(const char *name); · line 692

Quoted 6 lines

+++ b/include/part.h

include/part.h +1 -0
@@ -689,6 +689,13 @@ int part_get_type_by_name(const char *name);
  * @return first bootable partition, or 0 if there is none
  */
 int part_get_bootable(struct blk_desc *desc);
+/**

Missing blank line?

Ok, I will add it.

#4 lore raw

PATCH 2/2 spl: Add support for booting from ESP

In reply to Mayuresh Chitale

Some platforms as described by EBBR specification may store images in the FIRMWARE directory of the UEFI system partition(ESP). Add support to boot from the EFI system partition if it is enabled for a platform.

---
 common/spl/Kconfig      |  7 +++++
 common/spl/spl_blk_fs.c | 61 +++++++++++++++++++++++++++++------------
 common/spl/spl_fat.c    | 34 ++++++++++++++++++++---
 3 files changed, 81 insertions(+), 21 deletions(-)
common/spl/Kconfig +7 -0
index 76bde18515..92984b19da 100644
@@ -1241,6 +1241,13 @@ config SPL_SATA_RAW_U_BOOT_SECTOR
 	  Sector on the SATA disk to load U-Boot from, when the SATA disk is being
 	  used in raw mode. Units: SATA disk sectors (1 sector = 512 bytes).
 
+config SPL_ESP_BOOT
+	bool "Load next stage boot image from the UEFI system partition"
+	select SPL_PARTITION_TYPE_GUID
+	help
+	  When enabled, first try to boot from the UEFI system partition as
+	  described in the Ch.4 of the EBBR specification.
+
 config SPL_NVME
 	bool "NVM Express device support"
 	depends on BLK
common/spl/spl_blk_fs.c +44 -17

93 lines not on this page · raw message

common/spl/spl_fat.c +30 -4
index 6530bcd5a7..63091f2bd6 100644
@@ -54,10 +54,10 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
 	return actread;
 }
 
-int spl_load_image_fat(struct spl_image_info *spl_image,
-		       struct spl_boot_device *bootdev,
-		       struct blk_desc *block_dev, int partition,
-		       const char *filename)
+int spl_load_image_fat_one(struct spl_image_info *spl_image,
+			   struct spl_boot_device *bootdev,
+			   struct blk_desc *block_dev, int partition,
+			   const char *filename)
 {
 	int err;
 	loff_t size;
@@ -96,6 +96,32 @@ end:
 	return err;
 }
 
+int spl_load_image_fat(struct spl_image_info *spl_image,
+		       struct spl_boot_device *bootdev,
+		       struct blk_desc *block_dev, int partition,
+		       const char *filename)
+{
+	int err, part;
+
+	/*
+	 * First try to boot from EFI System partition. In case of failure,
+	 * fall back to the configured partition.
+	 */
+	if (IS_ENABLED(CONFIG_SPL_ESP_BOOT)) {
+		part = part_get_esp(block_dev);
+		if (part) {
+			err = spl_load_image_fat_one(spl_image, bootdev,
+						     block_dev, part,
+						     filename);
+			if (!err)
+				return err;
+		}
+	}
+
+	return spl_load_image_fat_one(spl_image, bootdev, block_dev,
+				      partition, filename);
+}
+
 #if CONFIG_IS_ENABLED(OS_BOOT)
 int spl_load_image_fat_os(struct spl_image_info *spl_image,
 			  struct spl_boot_device *bootdev,
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v1 2/2] spl: Add support for booting from ESP

Quoted 5 lines · Mayuresh Chitale

Some platforms as described by EBBR specification may store images in the FIRMWARE directory of the UEFI system partition(ESP). Add support to boot from the EFI system partition if it is enabled for a platform.

[snip]

common/spl/Kconfig config SPL_SATA_RAW_U_BOOT_SECTOR · line 1249

Quoted 6 lines
common/spl/Kconfig +6 -0
+config SPL_ESP_BOOT
+	bool "Load next stage boot image from the UEFI system partition"
+	select SPL_PARTITION_TYPE_GUID
+	help
+	  When enabled, first try to boot from the UEFI system partition as
+	  described in the Ch.4 of the EBBR specification.

We need to select this by perhaps BOOT_DEFAULTS or BOOTMETH_DISTRO, whatever is supposed to signify that yes, this is going to be a SystemReady IR (or higher) compliant build.

[snip]

Quoted 6 lines

int spl_blk_load_image(struct spl_image_info *spl_image,

common/spl/spl_blk_fs.c +0 -1
 		       struct spl_boot_device *bootdev,
 		       enum uclass_id uclass_id, int devnum, int partnum)
 {
 	const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
-	struct legacy_img_hdr *header;

[snip]

common/spl/spl_blk_fs.c int spl_blk_load_image(struct spl_image_info *spl_image, · line 67

Quoted 6 lines
common/spl/spl_blk_fs.c +0 -2
@@ -63,24 +88,26 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
 	}
 
 	blk_show_device(uclass_id, devnum);
-	header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
-

[snip]

Is this an artifact of Sean's patch series where "header" is no longer actually used? As-is this won't compile on top of next (which is where given Sean's feedback, the series needs to be rebased upon anyhow).

common/spl/spl_blk_fs.c int spl_blk_load_image(struct spl_image_info *spl_image, · line 96

Quoted 4 lines
common/spl/spl_blk_fs.c +4 -0
+	/*
+	 * First try to boot from EFI System partition. In case of failure,
+	 * fall back to the configured partition.
+	 */

I don't know that this is the right behavior. If we're configured to boot from partition X, we boot from partition X. If we're configured to find the ESP and use that, we find and use that.

Signature · 1 line
Tom
#6 lore raw

Re: [PATCH v1 2/2] spl: Add support for booting from ESP

Quoted 11 lines · Tom Rini
Quoted 8 lines · Mayuresh Chitale

Some platforms as described by EBBR specification may store images in
the FIRMWARE directory of the UEFI system partition(ESP). Add support
to boot from the EFI system partition if it is enabled for a platform.

[snip]

Quoted 12 lines

common/spl/Kconfig config SPL_SATA_RAW_U_BOOT_SECTOR · line 1249

Quoted 8 lines
(quoted diff) +2 -0
+config SPL_ESP_BOOT
+	bool "Load next stage boot image from the UEFI system

partition"

common/spl/Kconfig +3 -0
+	select SPL_PARTITION_TYPE_GUID
+	help
+	  When enabled, first try to boot from the UEFI system

partition as

common/spl/Kconfig +1 -0
+	  described in the Ch.4 of the EBBR specification.

We need to select this by perhaps BOOT_DEFAULTS or BOOTMETH_DISTRO, whatever is supposed to signify that yes, this is going to be a SystemReady IR (or higher) compliant build.

I am not sure about the SystemReady compliance but I think the config option can be enabled for those platforms which require it.

Quoted 19 lines

[snip]

Quoted 7 lines

int spl_blk_load_image(struct spl_image_info *spl_image,

(quoted diff) +0 -0
 		       struct spl_boot_device *bootdev,
 		       enum uclass_id uclass_id, int devnum, int

partnum)
{

common/spl/spl_blk_fs.c +0 -1
 	const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
-	struct legacy_img_hdr *header;

[snip]

Quoted 8 lines
common/spl/spl_blk_fs.c +0 -2
@@ -63,24 +88,26 @@ int spl_blk_load_image(struct spl_image_info
 *spl_image,
 	}
 
 	blk_show_device(uclass_id, devnum);
-	header = spl_get_load_buffer(-sizeof(*header),
 sizeof(*header));
-

[snip]

Quoted 5 lines

Is this an artifact of Sean's patch series where "header" is no longer
actually used? As-is this won't compile on top of next (which is where
given Sean's feedback, the series needs to be rebased upon anyhow).

Yes, I will rebase on the latest next without Sean's series and resend the patch.

Quoted 10 lines

Review

Quoted 5 lines
(quoted diff) +2 -0
+	/*
+	 * First try to boot from EFI System partition. In case of

failure,

(quoted diff) +2 -0
+	 * fall back to the configured partition.
+	 */

I don't know that this is the right behavior. If we're configured to boot from partition X, we boot from partition X. If we're configured to
find the ESP and use that, we find and use that.

This is to maintain compatibility and make more attempts to boot. So the same SPL binary can load images from devices with or without the ESP.

#7 lore raw

Re: [PATCH v1 2/2] spl: Add support for booting from ESP

Quoted 24 lines · On Thu, Sep 21, 2023 at 05:03:37PM +0530, [email protected] wrote:
Quoted 11 lines · Tom Rini
Quoted 8 lines · Mayuresh Chitale

Some platforms as described by EBBR specification may store images in
the FIRMWARE directory of the UEFI system partition(ESP). Add support
to boot from the EFI system partition if it is enabled for a platform.

[snip]

Quoted 12 lines

common/spl/Kconfig config SPL_SATA_RAW_U_BOOT_SECTOR · line 1249

Quoted 8 lines
(quoted diff) +2 -0
+config SPL_ESP_BOOT
+	bool "Load next stage boot image from the UEFI system

partition"

common/spl/Kconfig +3 -0
+	select SPL_PARTITION_TYPE_GUID
+	help
+	  When enabled, first try to boot from the UEFI system

partition as

common/spl/Kconfig +1 -0
+	  described in the Ch.4 of the EBBR specification.

We need to select this by perhaps BOOT_DEFAULTS or BOOTMETH_DISTRO, whatever is supposed to signify that yes, this is going to be a SystemReady IR (or higher) compliant build.

Quoted 2 lines

I am not sure about the SystemReady compliance but I think the config option can be enabled for those platforms which require it.

It's "nearly everyone" that needs the option, which is why I'm saying it needs to be part of the high level options that a board selects to say they want to be compliant.

Quoted 19 lines
Quoted 19 lines

[snip]

Quoted 7 lines

int spl_blk_load_image(struct spl_image_info *spl_image,

(quoted diff) +0 -0
 		       struct spl_boot_device *bootdev,
 		       enum uclass_id uclass_id, int devnum, int

partnum)
{

common/spl/spl_blk_fs.c +0 -1
 	const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
-	struct legacy_img_hdr *header;

[snip]

Quoted 8 lines
common/spl/spl_blk_fs.c +0 -2
@@ -63,24 +88,26 @@ int spl_blk_load_image(struct spl_image_info
 *spl_image,
 	}
 
 	blk_show_device(uclass_id, devnum);
-	header = spl_get_load_buffer(-sizeof(*header),
 sizeof(*header));
-

[snip]

Quoted 7 lines
Quoted 5 lines

Is this an artifact of Sean's patch series where "header" is no longer
actually used? As-is this won't compile on top of next (which is where
given Sean's feedback, the series needs to be rebased upon anyhow).

Yes, I will rebase on the latest next without Sean's series and resend the patch.

OK.

Quoted 11 lines
Quoted 10 lines

Review

Quoted 5 lines
(quoted diff) +2 -0
+	/*
+	 * First try to boot from EFI System partition. In case of

failure,

(quoted diff) +2 -0
+	 * fall back to the configured partition.
+	 */

I don't know that this is the right behavior. If we're configured to boot from partition X, we boot from partition X. If we're configured to
find the ESP and use that, we find and use that.

Quoted 3 lines

This is to maintain compatibility and make more attempts to boot. So the same SPL binary can load images from devices with or without the ESP.

Yes, I don't think that's what we want. It should be an either/or not a a then b.

Signature · 1 line
Tom
#8 lore raw
In reply to Mayuresh Chitale
Quoted 11 lines · Mayuresh Chitale

This series adds support to locate an EFI System Partition on a disk and boot the next stage from such a parition if found. The next stage image is expected to be under the FIRMWARE directory as described in the EBBR specification [1]. Also update the spl_blk_fs and spl_fat drivers to prefer booting from ESP and fall back to the configured parition in case of a failure.

These patches are built on top of the following series from Sean Anderson:
https://lists.denx.de/pipermail/u-boot/2023-August/525665.html

[1] : https://github.com/ARM-software/ebbr/blob/854ba0e68590102667b84a5ba4e0b076a3f5f2cb/source/chapter4-firmware-media.rst

Hello Sean,

your series [1] is in status "changes requested". Will a new version come up soon, or can this change go first?

Best regards

Heinrich

Quoted 15 lines

The patches are also present in the branch below:
https://github.com/mdchitale/u-boot/tree/mchitale_spl_ebbr_v1

Mayuresh Chitale (2):
part: Add a function to find ESP partition
spl: Add support for booting from ESP

  common/spl/Kconfig      |  7 +++++
  common/spl/spl_blk_fs.c | 61 +++++++++++++++++++++++++++++------------
  common/spl/spl_fat.c    | 34 ++++++++++++++++++++---
  disk/part.c             | 16 +++++++++++
  include/part.h          | 10 +++++++
  5 files changed, 107 insertions(+), 21 deletions(-)
#9 lore raw

Hi Heinrich,

Quoted 11 lines · Heinrich Schuchardt
Quoted 10 lines · Mayuresh Chitale

This series adds support to locate an EFI System Partition on a disk and boot the next stage from such a parition if found. The next stage image is expected to be under the FIRMWARE directory as described in the EBBR specification [1]. Also update the spl_blk_fs and spl_fat drivers to prefer booting from ESP and fall back to the configured parition in case of a failure.

These patches are built on top of the following series from Sean Anderson:
https://cas5-0-urlprotect.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2flists.denx.de%2fpipermail%2fu%2dboot%2f2023%2dAugust%2f525665.html&umid=9846b220-30e5-47d9-980b-6b2a067d6959&auth=d807158c60b7d2502abde8a2fc01f40662980862-8c7a372e72c3ce6a78488f17bac32c55586848b7

Quoted 6 lines
Quoted 1 line

[1] : https://cas5-0-urlprotect.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2fgithub.com%2fARM%2dsoftware%2febbr%2fblob%2f854ba0e68590102667b84a5ba4e0b076a3f5f2cb%2fsource%2fchapter4%2dfirmware%2dmedia.rst&umid=9846b220-30e5-47d9-980b-6b2a067d6959&auth=d807158c60b7d2502abde8a2fc01f40662980862-c4109227e8dc78dcfe731b6e4cfe9dfef856e354

Hello Sean,

your series [1] is in status "changes requested". Will a new version come up soon, or can this change go first?

I had been working to incorporate your suggestion regarding bl_len. However, I have not had the time recently to finish that. I also need to have another look at the size changes once that is implemented. I had been hoping to use [1] to get some general size reductions on most platforms, but I am going to have to revisit that as well. I would like to work on this, but at the moment it's not high priority for me. Changes like this should likely go in first, since I suspect it will take another revision or two to finish up that series.

--Sean

[1] https://lore.kernel.org/u-boot/20230810221138.GY3630934@bill-the-cat/

Quoted 18 lines
Quoted 17 lines

The patches are also present in the branch below:
https://cas5-0-urlprotect.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2fgithub.com%2fmdchitale%2fu%2dboot%2ftree%2fmchitale%5fspl%5febbr%5fv1&umid=9846b220-30e5-47d9-980b-6b2a067d6959&auth=d807158c60b7d2502abde8a2fc01f40662980862-6f91c84d8d5661347bae86e4cb72a96341f7048d

Mayuresh Chitale (2):
part: Add a function to find ESP partition
spl: Add support for booting from ESP

  common/spl/Kconfig      |  7 +++++
  common/spl/spl_blk_fs.c | 61 +++++++++++++++++++++++++++++------------
  common/spl/spl_fat.c    | 34 ++++++++++++++++++++---
  disk/part.c             | 16 +++++++++++
  include/part.h          | 10 +++++++
  5 files changed, 107 insertions(+), 21 deletions(-)