[PATCH] spl: allow boot from first bootable partition

This was implemented in order to get dual-slot bootloader partitions on the BeagleBone Black, whose MLO boots from the first bootable partition: MLO chainloads u-boot in the same way.
Signed-off-by: Jérôme Carretero cJ-uboot@zougloub.eu --- common/spl/Kconfig | 3 ++- common/spl/spl_mmc.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 9418d37b2e..ea20d514d3 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -668,7 +668,8 @@ config SYS_MMCSD_FS_BOOT_PARTITION default 1 help Partition on the MMC to load U-Boot from when the MMC is being - used in fs mode + used in fs mode. + Use -1 as a special value to use the first bootable partition.
config SPL_MMC_TINY bool "Tiny MMC framework in SPL" diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 1c41d24ff4..93daeea7c9 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -280,16 +280,41 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, { int err = -ENOSYS;
+ + int partition = CONFIG_SYS_MMCSD_FS_BOOT_PARTITION; + +#if CONFIG_SYS_MMCSD_FS_BOOT_PARTITION == -1 + { + struct disk_partition info; + debug("Checking for the first MBR bootable partition\n"); + for (int type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) { + err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info); + if (err) + continue; + debug("Partition %d is of type %d and bootable=%d\n", type_part, info.sys_ind, info.bootable); + if (info.bootable != 0) { + debug("Partition %d is bootable, using it\n", type_part); + partition = type_part; + break; + } + } + printf("Using first bootable partition: %d\n", partition); + if (partition == CONFIG_SYS_MMCSD_FS_BOOT_PARTITION) { + return -ENOSYS; + } + } +#endif + #ifdef CONFIG_SPL_FS_FAT if (!spl_start_uboot()) { err = spl_load_image_fat_os(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); + partition); if (!err) return err; } #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME err = spl_load_image_fat(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, + partition, filename); if (!err) return err; @@ -298,13 +323,13 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, #ifdef CONFIG_SPL_FS_EXT4 if (!spl_start_uboot()) { err = spl_load_image_ext_os(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); + partition); if (!err) return err; } #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME err = spl_load_image_ext(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, + partition, filename); if (!err) return err;

Hi,
On Thu, 10 Mar 2022 11:44:04 -0500 Jérôme Carretero cJ-uboot@zougloub.eu wrote:
This was implemented in order to get dual-slot bootloader partitions on the BeagleBone Black, whose MLO boots from the first bootable partition: MLO chainloads u-boot in the same way.
I realize some tests (eg. sifive_unleashed_sdcard) are failing to pass due to -Werror=unused-variable.
Will update in consequence.
Regards,

This was implemented in order to get dual-slot bootloader partitions on the BeagleBone Black, whose MLO boots from the first bootable partition: MLO chainloads u-boot in the same way.
Signed-off-by: Jérôme Carretero cJ-uboot@zougloub.eu --- common/spl/Kconfig | 3 ++- common/spl/spl_mmc.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 9418d37b2e..ea20d514d3 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -668,7 +668,8 @@ config SYS_MMCSD_FS_BOOT_PARTITION default 1 help Partition on the MMC to load U-Boot from when the MMC is being - used in fs mode + used in fs mode. + Use -1 as a special value to use the first bootable partition.
config SPL_MMC_TINY bool "Tiny MMC framework in SPL" diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 1c41d24ff4..3408444c2a 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -280,16 +280,41 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, { int err = -ENOSYS;
+ __attribute__ ((unused)) + int partition = CONFIG_SYS_MMCSD_FS_BOOT_PARTITION; + +#if CONFIG_SYS_MMCSD_FS_BOOT_PARTITION == -1 + { + struct disk_partition info; + debug("Checking for the first MBR bootable partition\n"); + for (int type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) { + err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info); + if (err) + continue; + debug("Partition %d is of type %d and bootable=%d\n", type_part, info.sys_ind, info.bootable); + if (info.bootable != 0) { + debug("Partition %d is bootable, using it\n", type_part); + partition = type_part; + break; + } + } + printf("Using first bootable partition: %d\n", partition); + if (partition == CONFIG_SYS_MMCSD_FS_BOOT_PARTITION) { + return -ENOSYS; + } + } +#endif + #ifdef CONFIG_SPL_FS_FAT if (!spl_start_uboot()) { err = spl_load_image_fat_os(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); + partition); if (!err) return err; } #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME err = spl_load_image_fat(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, + partition, filename); if (!err) return err; @@ -298,13 +323,13 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, #ifdef CONFIG_SPL_FS_EXT4 if (!spl_start_uboot()) { err = spl_load_image_ext_os(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); + partition); if (!err) return err; } #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME err = spl_load_image_ext(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, + partition, filename); if (!err) return err;

On Thu, Mar 10, 2022 at 01:38:37PM -0500, Jérôme Carretero wrote:
This was implemented in order to get dual-slot bootloader partitions on the BeagleBone Black, whose MLO boots from the first bootable partition: MLO chainloads u-boot in the same way.
Signed-off-by: Jérôme Carretero cJ-uboot@zougloub.eu
common/spl/Kconfig | 3 ++- common/spl/spl_mmc.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 9418d37b2e..ea20d514d3 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -668,7 +668,8 @@ config SYS_MMCSD_FS_BOOT_PARTITION default 1 help Partition on the MMC to load U-Boot from when the MMC is being
used in fs mode
used in fs mode.
Use -1 as a special value to use the first bootable partition.
config SPL_MMC_TINY bool "Tiny MMC framework in SPL" diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 1c41d24ff4..3408444c2a 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -280,16 +280,41 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, { int err = -ENOSYS;
- __attribute__ ((unused))
- int partition = CONFIG_SYS_MMCSD_FS_BOOT_PARTITION;
We have __maybe_unused in <linux/compiler.h> that should be used instead here.

This was implemented in order to get dual-slot bootloader partitions on the BeagleBone Black, whose MLO boots from the first bootable partition: MLO chainloads u-boot in the same way.
Signed-off-by: Jérôme Carretero cJ-uboot@zougloub.eu --- common/spl/Kconfig | 3 ++- common/spl/spl_mmc.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 9418d37b2e..ea20d514d3 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -668,7 +668,8 @@ config SYS_MMCSD_FS_BOOT_PARTITION default 1 help Partition on the MMC to load U-Boot from when the MMC is being - used in fs mode + used in fs mode. + Use -1 as a special value to use the first bootable partition.
config SPL_MMC_TINY bool "Tiny MMC framework in SPL" diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 1c41d24ff4..728fb64094 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -280,16 +280,40 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, { int err = -ENOSYS;
+ __maybe_unused int partition = CONFIG_SYS_MMCSD_FS_BOOT_PARTITION; + +#if CONFIG_SYS_MMCSD_FS_BOOT_PARTITION == -1 + { + struct disk_partition info; + debug("Checking for the first MBR bootable partition\n"); + for (int type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) { + err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info); + if (err) + continue; + debug("Partition %d is of type %d and bootable=%d\n", type_part, info.sys_ind, info.bootable); + if (info.bootable != 0) { + debug("Partition %d is bootable, using it\n", type_part); + partition = type_part; + break; + } + } + printf("Using first bootable partition: %d\n", partition); + if (partition == CONFIG_SYS_MMCSD_FS_BOOT_PARTITION) { + return -ENOSYS; + } + } +#endif + #ifdef CONFIG_SPL_FS_FAT if (!spl_start_uboot()) { err = spl_load_image_fat_os(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); + partition); if (!err) return err; } #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME err = spl_load_image_fat(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, + partition, filename); if (!err) return err; @@ -298,13 +322,13 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, #ifdef CONFIG_SPL_FS_EXT4 if (!spl_start_uboot()) { err = spl_load_image_ext_os(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); + partition); if (!err) return err; } #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME err = spl_load_image_ext(spl_image, bootdev, mmc_get_blk_desc(mmc), - CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, + partition, filename); if (!err) return err;

On Tue, Mar 15, 2022 at 04:34:51PM -0400, Jérôme Carretero wrote:
This was implemented in order to get dual-slot bootloader partitions on the BeagleBone Black, whose MLO boots from the first bootable partition: MLO chainloads u-boot in the same way.
Signed-off-by: Jérôme Carretero cJ-uboot@zougloub.eu
Reviewed-by: Tom Rini trini@konsulko.com

On Tue, Mar 15, 2022 at 04:34:51PM -0400, Jérôme Carretero wrote:
This was implemented in order to get dual-slot bootloader partitions on the BeagleBone Black, whose MLO boots from the first bootable partition: MLO chainloads u-boot in the same way.
Signed-off-by: Jérôme Carretero cJ-uboot@zougloub.eu Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!
participants (2)
-
Jérôme Carretero
-
Tom Rini