SPL EBBR - EFI System Partition support
v2 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.
Changes in v2:
- Rebase on latest next branch
- Enable SPL_ESP_BOOT by default
- For NVMe boot, remove fallback in case of ESP boot failure
Mayuresh Chitale (2):
part: Add a function to find ESP partition
spl: Add support for booting from ESP
common/spl/Kconfig | 8 +++++++ common/spl/spl_blk_fs.c | 51 ++++++++++++++++++++++++++++++----------- common/spl/spl_fat.c | 34 +++++++++++++++++++++++---- disk/part.c | 16 +++++++++++++ include/part.h | 11 +++++++++ 5 files changed, 102 insertions(+), 18 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 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 | 11 +++++++++++ 2 files changed, 27 insertions(+)
disk/part.c +16 -0
@@ -848,3 +848,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 +11 -0
@@ -690,6 +690,14 @@ int part_get_type_by_name(const char *name);*/ 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 ) {return 0 ; }
@@ -700,6 +708,9 @@ static inline struct part_driver *part_driver_get_first(void)static inline bool part_get_bootable (struct blk_desc *desc) {return false; } +static inline bool part_get_esp (struct blk_desc *desc) +{return false; } +#endif /* CONFIG_PARTITIONS */ #endif /* _PART_H */
Signature · 1 line
2.34.1
Re: [PATCH v2 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.
Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Heinrich Schuchardt <[email protected]>--- disk/part.c | 16 ++++++++++++++++ include/part.h | 11 +++++++++++ 2 files changed, 27 insertions(+)disk/part.c +16
-0@@ -848,3 +848,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
include/part.h int part_get_type_by_name(const char *name); · line 697
Quoted 8 lines
include/part.h +5
-0@@ -690,6 +690,14 @@ int part_get_type_by_name(const char *name);*/ 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
We want to be able to add the include to our API documentation. This requires adhering to the Sphinx documentation style.
%s/@Return the/Return:/
Cf. https://www.kernel.org/doc/html/v6.7/doc-guide/kernel-doc.html#function-documentation
Best regards
Heinrich
Quoted 16 lines
include/part.h +6
-0+*/ +int part_get_esp (struct blk_desc *desc); +#else static inline int part_driver_get_count (void ) {return 0 ; }@@ -700,6 +708,9 @@ static inline struct part_driver *part_driver_get_first(void)static inline bool part_get_bootable (struct blk_desc *desc) {return false; } +static inline bool part_get_esp (struct blk_desc *desc) +{return false; } +#endif /* CONFIG_PARTITIONS */ #endif /* _PART_H */
Re: [PATCH v2 1/2] part: Add a function to find ESP partition
Quoted 6 lines · Heinrich Schuchardt
Quoted 5 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.
Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Heinrich Schuchardt <[email protected]>
I ran your patches through Gitlab CI and some issues came up:
https://source.denx.de/u-boot/custodians/u-boot-efi/-/jobs/771497
https://source.denx.de/u-boot/custodians/u-boot-efi/-/jobs/771498
Could you, please, have a look at it.
Best regards
Heinrich
Quoted 67 lines
Quoted 33 lines
---
disk/part.c | 16 ++++++++++++++++
include/part.h| 11 +++++++++++2 files changed, 27 insertions(+)disk/part.c +16
-0@@ -848,3 +848,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
-0include/part.h int part_get_type_by_name(const char *name); · line 696
Quoted 7 lines
include/part.h +5
-0@@ -690,6 +690,14 @@ int part_get_type_by_name(const char *name);*/ 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 We want to be able to add the include to our API documentation. This requires adhering to the Sphinx documentation style.
%s/@Return the/Return:/
Cf. https://www.kernel.org/doc/html/v6.7/doc-guide/kernel-doc.html#function-documentation
Best regards
Heinrich
Quoted 15 lines
include/part.h +6
-0+*/ +int part_get_esp (struct blk_desc *desc); + #else static inline int part_driver_get_count(void) { return 0; }@@ -700,6 +708,9 @@ static inline struct part_driver *part_driver_get_first(void) static inline bool part_get_bootable(struct blk_desc *desc) { return false; } +static inline bool part_get_esp (struct blk_desc *desc) +{return false; } + #endif /* CONFIG_PARTITIONS */ #endif /* _PART_H */
Re: [PATCH v2 1/2] part: Add a function to find ESP partition
Hi Heinrich,
Quoted 10 lines · Heinrich Schuchardt
Quoted 8 lines · Heinrich Schuchardt
Quoted 7 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.Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Heinrich Schuchardt <
Quoted 6 lines
I ran your patches through Gitlab CI and some issues came up:
https://source.denx.de/u-boot/custodians/u-boot-efi/-/jobs/771497
https://source.denx.de/u-boot/custodians/u-boot-efi/-/jobs/771498Could you, please, have a look at it.
I looked into the log files below:
https://u-boot.source-pages.denx.de/-/custodians/u-boot-efi/-/jobs/771497/artifacts/test-log.html
https://u-boot.source-pages.denx.de/-/custodians/u-boot-efi/-/jobs/771498/artifacts/test-log.html
If those logs are correct, I think the failure is probably because I removed fallback to the user provided partition in case the ESP probe failed for some reason. I think that fallback is required here.
Quoted 74 lines
Best regards
Heinrich
Quoted 69 lines
Quoted 33 lines
--- disk/part.c | 16 ++++++++++++++++ include/part.h | 11 +++++++++++ 2 files changed, 27 insertions(+)disk/part.c +16
-0@@ -848,3 +848,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
-0include/part.h int part_get_type_by_name(const char *name); · line 696
Quoted 7 lines
include/part.h +5
-0@@ -690,6 +690,14 @@ int part_get_type_by_name(const char *name);*/ 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 We want to be able to add the include to our API documentation. This
requires adhering to the Sphinx documentation style.%s/@Return the/Return:/
Cf.
https://www.kernel.org/doc/html/v6.7/doc-guide/kernel-doc.html#function-documentationBest regards
Heinrich
Quoted 15 lines
include/part.h +6
-0+*/ +int part_get_esp (struct blk_desc *desc); +#else static inline int part_driver_get_count (void ) {return 0 ; }@@ -700,6 +708,9 @@ static inline struct part_driver *part_driver_get_first(void)static inline bool part_get_bootable (struct blk_desc *desc) {return false; } +static inline bool part_get_esp (struct blk_desc *desc) +{return false; } +#endif /* CONFIG_PARTITIONS */ #endif /* _PART_H */
Re: [PATCH v2 1/2] part: Add a function to find ESP partition
In reply to Heinrich SchuchardtQuoted 83 lines · Heinrich Schuchardt
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.
Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Heinrich Schuchardt <[email protected]>--- disk/part.c | 16 ++++++++++++++++ include/part.h | 11 +++++++++++ 2 files changed, 27 insertions(+)disk/part.c +16
-0@@ -848,3 +848,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
-0include/part.h int part_get_type_by_name(const char *name); · line 697
Quoted 8 lines
include/part.h +5
-0@@ -690,6 +690,14 @@ int part_get_type_by_name(const char *name);*/ 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 We want to be able to add the include to our API documentation. This requires adhering to the Sphinx documentation style.
%s/@Return the/Return:/
Ok.
Cf.
https://www.kernel.org/doc/html/v6.7/doc-guide/kernel-doc.html#function-documentation
Best regards
Heinrich
include/part.h static inline struct part_driver
Quoted 7 lines
include/part.h +3
-0+*/ +int part_get_esp (struct blk_desc *desc); +#else static inline int part_driver_get_count (void ) {return 0 ; }@@ -700,6 +708,9 @@ static inline struct part_driver
*part_driver_get_first(void)Quoted 9 lines
include/part.h +3
-0static inline bool part_get_bootable (struct blk_desc *desc) {return false; } +static inline bool part_get_esp (struct blk_desc *desc) +{return false; } +#endif /* CONFIG_PARTITIONS */ #endif /* _PART_H */
Re: [PATCH v2 1/2] part: Add a function to find ESP partition
In reply to Mayuresh ChitaleQuoted 54 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.
Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Heinrich Schuchardt <[email protected]>--- disk/part.c | 16 ++++++++++++++++ include/part.h | 11 +++++++++++ 2 files changed, 27 insertions(+)disk/part.c +16
-0@@ -848,3 +848,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 +8
-0@@ -690,6 +690,14 @@ int part_get_type_by_name(const char *name);*/ 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 ) {return 0 ; }
include/part.h static inline struct part_driver *part_driver_get_first(void) · line 711
Quoted 4 lines
include/part.h +1
-0@@ -700,6 +708,9 @@ static inline struct part_driver *part_driver_get_first(void)static inline bool part_get_bootable (struct blk_desc *desc) {return false; } +static inline bool part_get_esp (struct blk_desc *desc)
Please use the same signature as above.
include/part.h static inline struct part_driver *part_driver_get_first(void) · line 712
Quoted 1 line
include/part.h +1
-0+{return false; }
The statement here should be on its own line.
--Sean
Quoted 4 lines
include/part.h +1
-0+#endif /* CONFIG_PARTITIONS */ #endif /* _PART_H */
Re: [PATCH v2 1/2] part: Add a function to find ESP partition
Quoted 56 lines · Sean Anderson
include/part.h static inline struct part_driver
Quoted 54 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.
Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Heinrich Schuchardt <[email protected]>--- disk/part.c | 16 ++++++++++++++++ include/part.h | 11 +++++++++++ 2 files changed, 27 insertions(+)disk/part.c +16
-0@@ -848,3 +848,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 +8
-0@@ -690,6 +690,14 @@ int part_get_type_by_name(const char *name);*/ 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 ) {return 0 ; }@@ -700,6 +708,9 @@ static inline struct part_driver
*part_driver_get_first(void)
Quoted 7 lines
include/part.h static inline struct part_driver *part_driver_get_first(void) · line 711
Quoted 4 lines
include/part.h +1
-0static inline bool part_get_bootable (struct blk_desc *desc) {return false; } +static inline bool part_get_esp (struct blk_desc *desc)Please use the same signature as above.
Yes.
Quoted 14 lines
include/part.h static inline struct part_driver *part_driver_get_first(void) · line 712
Quoted 1 line
include/part.h +1
-0+{return false; }The statement here should be on its own line.
Ok.
--Sean
Quoted 4 lines
include/part.h +1
-0+#endif /* CONFIG_PARTITIONS */ #endif /* _PART_H */
PATCH v2 2/2 spl: Add support for booting from ESP
In reply to Mayuresh ChitaleSome 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 | 8 +++++++ common/spl/spl_blk_fs.c | 51 ++++++++++++++++++++++++++++++----------- common/spl/spl_fat.c | 34 +++++++++++++++++++++++---- 3 files changed, 75 insertions(+), 18 deletions(-)
common/spl/Kconfig +8 -0
@@ -1292,6 +1292,14 @@ 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" + default y if BOOT_DEFAULTS + 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 +37 -14
83 lines not on this page · raw message
common/spl/spl_fat.c +30 -4
@@ -60,10 +60,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;
@@ -103,6 +103,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
Re: [PATCH v2 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.
Signed-off-by Mayuresh Chitale <[email protected]>
Thank you for respinning this series.
For future submissions it would be preferable to have the changes between the versions also in the individual patches.
Quoted 46 lines
--- common/spl/Kconfig | 8 +++++++ common/spl/spl_blk_fs.c | 51 ++++++++++++++++++++++++++++++----------- common/spl/spl_fat.c | 34 +++++++++++++++++++++++---- 3 files changed, 75 insertions(+), 18 deletions(-)common/spl/Kconfig +8
-0@@ -1292,6 +1292,14 @@ 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" + default y if BOOT_DEFAULTS + 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 BLKcommon/spl/spl_blk_fs.c +3
-0@@ -10,12 +10,15 @@#include <spl_load.h> #include <image.h> #include <fs.h> +#include <part.h> #include <asm/cache.h> #include <asm/io.h> struct blk_dev {const char *ifname;const char *filename; +int devnum; +int partnum;char dev_part_str[8 ]; };
common/spl/spl_blk_fs.c static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, · line 56
Quoted 10 lines
common/spl/spl_blk_fs.c +7
-0@@ -44,6 +47,29 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,return actlen; } +static int spl_blk_file_size (struct blk_dev *dev,const char *filename, +loff_t *filesize) +{ +int ret; + +snprintf (dev->dev_part_str,sizeof (dev->dev_part_str) -1 ,"%x:%x" , + dev->devnum, dev->partnum);
Using log functions allows to provide more information if CONFIG_SPL_LOG=y otherwise they fall back to printf() and debug().
common/spl/spl_blk_fs.c static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, · line 58
Quoted 2 lines
common/spl/spl_blk_fs.c +2
-0+debug ("Loading file %s from %s %s\n" , filename, dev->ifname, + dev->dev_part_str);
log_debug(
common/spl/spl_blk_fs.c static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, · line 61
Quoted 3 lines
common/spl/spl_blk_fs.c +3
-0+ ret =fs_set_blk_dev (dev->ifname, dev->dev_part_str,FS_TYPE_ANY ); +if (ret) { + printf("spl: unable to set blk_dev %s %s. Err - %d\n",
SPL binary size is limited on many systems. There is already a message telling that we are in SPL. I would suggest to abbreviate the message.
log_err("Can't access %s %s\n", dev->ifname, dev->dev_part_str);
common/spl/spl_blk_fs.c static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, · line 69
Quoted 8 lines
common/spl/spl_blk_fs.c +8
-0+ dev->ifname, dev->dev_part_str, ret); +return ret; + } + + ret =fs_size (filename, filesize); +if (ret) +printf ("spl: unable to get size, file: %s. Err - %d\n" , + filename, ret);
log_err("File not found %s\n", filename);
Moving to log functions and adjusting the messages can be done in a follow up patch. I don't want to stop this series.
Quoted 99 lines
common/spl/spl_blk_fs.c +14
-14+return ret; +} +int spl_blk_load_image (struct spl_image_info *spl_image,struct spl_boot_device *bootdev,enum uclass_id uclass_id,int devnum,int partnum)@@ -53,7 +79,7 @@ int spl_blk_load_image(struct spl_image_info *spl_image,loff_t filesize;struct blk_dev dev;struct spl_load_info load; -int ret; +int ret, part; blk_desc =blk_get_devnum_by_uclass_id (uclass_id, devnum);if (!blk_desc) {@@ -65,21 +91,18 @@ int spl_blk_load_image(struct spl_image_info *spl_image, dev.filename = filename; dev.ifname =blk_get_uclass_name (uclass_id); -snprintf (dev.dev_part_str,sizeof (dev.dev_part_str) -1 ,"%x:%x" , - devnum, partnum); - ret =fs_set_blk_dev (dev.ifname, dev.dev_part_str,FS_TYPE_ANY ); -if (ret) { -printf ("spl: unable to set blk_dev %s %s. Err - %d\n" , - dev.ifname, dev.dev_part_str, ret); -return ret; + dev.devnum = devnum; + dev.partnum = partnum; +if (IS_ENABLED (CONFIG_SPL_ESP_BOOT )) { + part =part_get_esp (blk_desc); +if (part) + dev.partnum = part; +else +return -ENODEV ; } - - ret =fs_size (filename, &filesize); -if (ret) { -printf ("spl: unable to get file size: %s. Err - %d\n" , - filename, ret); + ret =spl_blk_file_size (&dev, filename, &filesize); +if (ret)return ret; - } load.read = spl_fit_read;if (IS_ENABLED (CONFIG_SPL_FS_FAT_DMA_ALIGN ))common/spl/spl_fat.c +30
-4@@ -60,10 +60,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;@@ -103,6 +103,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,
Re: [PATCH v2 2/2] spl: Add support for booting from ESP
Quoted 5 lines · Heinrich Schuchardt
Quoted 4 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.
Quoted 7 lines
Quoted 1 line
Signed-off-by Mayuresh Chitale <[email protected]>Thank you for respinning this series.
For future submissions it would be preferable to have the changes between the versions also in the individual patches.
Ok.
Quoted 201 lines
common/spl/Kconfig config SPL_SATA_RAW_U_BOOT_SECTOR · line 1292
Quoted 13 lines
--- common/spl/Kconfig | 8 +++++++ common/spl/spl_blk_fs.c | 51 ++++++++++++++++++++++++++++++----------- common/spl/spl_fat.c | 34 +++++++++++++++++++++++---- 3 files changed, 75 insertions(+), 18 deletions(-)common/spl/Kconfig +0
-0@@ -1292,6 +1292,14 @@ config SPL_SATA_RAW_U_BOOT_SECTOR Sector on the SATA disk to load U-Boot from, when the SATA diskis being
common/spl/Kconfig config SPL_SATA_RAW_U_BOOT_SECTOR · line 1293
Quoted 1 line
common/spl/Kconfig +0
-0used in raw mode. Units: SATA disk sectors (1 sector = 512bytes).
common/spl/spl_blk_fs.c static ulong spl_fit_read(struct spl_load_info *load,
Quoted 33 lines
common/spl/Kconfig +8
-0+config SPL_ESP_BOOT + bool "Load next stage boot image from the UEFI system partition" + default y if BOOT_DEFAULTS + 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 BLKcommon/spl/spl_blk_fs.c +3
-0@@ -10,12 +10,15 @@#include <spl_load.h> #include <image.h> #include <fs.h> +#include <part.h> #include <asm/cache.h> #include <asm/io.h> struct blk_dev {const char *ifname;const char *filename; +int devnum; +int partnum;char dev_part_str[8 ]; };@@ -44,6 +47,29 @@ static ulong spl_fit_read(struct spl_load_info *load,ulong
file_offset,common/spl/spl_blk_fs.c static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, · line 56
Quoted 10 lines
common/spl/spl_blk_fs.c +7
-0return actlen; } +static int spl_blk_file_size (struct blk_dev *dev,const char *filename, +loff_t *filesize) +{ +int ret; + +snprintf (dev->dev_part_str,sizeof (dev->dev_part_str) -1 ,"%x:%x" , + dev->devnum, dev->partnum);Using log functions allows to provide more information if
CONFIG_SPL_LOG=yotherwise they fall back toprintf()anddebug().common/spl/spl_blk_fs.c static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, · line 58
Quoted 2 lines
common/spl/spl_blk_fs.c +2
-0+debug ("Loading file %s from %s %s\n" , filename, dev->ifname, + dev->dev_part_str);log_debug(
common/spl/spl_blk_fs.c static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, · line 61
Quoted 3 lines
common/spl/spl_blk_fs.c +3
-0+ ret =fs_set_blk_dev (dev->ifname, dev->dev_part_str,FS_TYPE_ANY ); +if (ret) { + printf("spl: unable to set blk_dev %s %s. Err - %d\n",SPL binary size is limited on many systems. There is already a message telling that we are in SPL. I would suggest to abbreviate the message.
log_err("Can't access %s %s\n", dev->ifname, dev->dev_part_str);common/spl/spl_blk_fs.c static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, · line 69
Quoted 8 lines
common/spl/spl_blk_fs.c +8
-0+ dev->ifname, dev->dev_part_str, ret); +return ret; + } + + ret =fs_size (filename, filesize); +if (ret) +printf ("spl: unable to get size, file: %s. Err - %d\n" , + filename, ret);
log_err("File not found %s\n", filename);Moving to log functions and adjusting the messages can be done in a follow up patch. I don't want to stop this series.
Ok.
Reviewed-by Heinrich Schuchardt <[email protected]>common/spl/spl_blk_fs.c int spl_blk_load_image(struct spl_image_info
Quoted 7 lines
common/spl/spl_blk_fs.c +3
-0+return ret; +} +int spl_blk_load_image (struct spl_image_info *spl_image,struct spl_boot_device *bootdev,enum uclass_id uclass_id,int devnum,int partnum)@@ -53,7 +79,7 @@ int spl_blk_load_image(struct spl_image_info
*spl_image,common/spl/spl_blk_fs.c int spl_blk_load_image(struct spl_image_info
Quoted 9 lines
common/spl/spl_blk_fs.c +1
-1loff_t filesize;struct blk_dev dev;struct spl_load_info load; -int ret; +int ret, part; blk_desc =blk_get_devnum_by_uclass_id (uclass_id, devnum);if (!blk_desc) {@@ -65,21 +91,18 @@ int spl_blk_load_image(struct spl_image_info
*spl_image,common/spl/spl_fat.c static ulong spl_fit_read(struct spl_load_info
Quoted 36 lines
common/spl/spl_blk_fs.c +10
-13dev.filename = filename; dev.ifname =blk_get_uclass_name (uclass_id); -snprintf (dev.dev_part_str,sizeof (dev.dev_part_str) -1 ,"%x:%x" , - devnum, partnum); - ret =fs_set_blk_dev (dev.ifname, dev.dev_part_str,FS_TYPE_ANY ); -if (ret) { -printf ("spl: unable to set blk_dev %s %s. Err - %d\n" , - dev.ifname, dev.dev_part_str, ret); -return ret; + dev.devnum = devnum; + dev.partnum = partnum; +if (IS_ENABLED (CONFIG_SPL_ESP_BOOT )) { + part =part_get_esp (blk_desc); +if (part) + dev.partnum = part; +else +return -ENODEV ; } - - ret =fs_size (filename, &filesize); -if (ret) { -printf ("spl: unable to get file size: %s. Err - %d\n" , - filename, ret); + ret =spl_blk_file_size (&dev, filename, &filesize); +if (ret)return ret; - } load.read = spl_fit_read;if (IS_ENABLED (CONFIG_SPL_FS_FAT_DMA_ALIGN ))common/spl/spl_fat.c +0
-0@@ -60,10 +60,10 @@ static ulong spl_fit_read(struct spl_load_info*load, ulong
file_offset,Quoted 47 lines
common/spl/spl_fat.c +30
-4return 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;@@ -103,6 +103,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,