spl: spl_nor: add alternative SPL_LOAD_IMAGE_METHOD
Subsystems (6)
v2 cover spl: spl_nor: add alternative SPL_LOAD_IMAGE_METHOD
Add a second SPL_LOAD_IMAGE_METHOD BOOT_DEVICE_NOR2 to enable booting from an alternative NOR address in case loading from the first address fails - e.g., if no valid header is found.
Changes since v1:
- addressed right email recipients
Mario Kicherer (2):
spl: spl_nor: add BOOT_DEVICE_NOR2 as alternative
SPL_LOAD_IMAGE_METHOD
spl: spl_nor: add spl_boot_device parameter to
spl_nor_get_uboot_base()
arch/arm/include/asm/spl.h | 1 + arch/arm/mach-imx/image-container.c | 2 +- arch/mips/include/asm/spl.h | 1 + arch/mips/mach-mtmips/mt7621/spl/spl.c | 2 +- arch/mips/mach-mtmips/spl.c | 2 +- arch/riscv/include/asm/spl.h | 1 + common/spl/spl_nor.c | 11 ++++++----- 7 files changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/2 spl: spl_nor: add BOOT_DEVICE_NOR2 as alternative SPL_LOAD_IMAGE_METHOD
Add BOOT_DEVICE_NOR2 as a second SPL_LOAD_IMAGE_METHOD to enable a board-specific spl_nor_get_uboot_base() function to return an alternative address in the NOR flash in case booting from BOOT_DEVICE_NOR fails.
--- arch/arm/include/asm/spl.h | 1 + arch/mips/include/asm/spl.h | 1 + arch/riscv/include/asm/spl.h | 1 + common/spl/spl_nor.c | 1 + 4 files changed, 4 insertions(+)
arch/arm/include/asm/spl.h +1 -0
@@ -20,6 +20,7 @@ enum {BOOT_DEVICE_NAND ,BOOT_DEVICE_ONENAND ,BOOT_DEVICE_NOR , +BOOT_DEVICE_NOR2 ,BOOT_DEVICE_UART ,BOOT_DEVICE_SPI , BOOT_DEVICE_USB,
arch/mips/include/asm/spl.h +1 -0
@@ -14,6 +14,7 @@ enum {BOOT_DEVICE_NAND ,BOOT_DEVICE_ONENAND ,BOOT_DEVICE_NOR , +BOOT_DEVICE_NOR2 ,BOOT_DEVICE_UART ,BOOT_DEVICE_SPI , BOOT_DEVICE_USB,
arch/riscv/include/asm/spl.h +1 -0
@@ -16,6 +16,7 @@ enum {BOOT_DEVICE_NAND ,BOOT_DEVICE_ONENAND ,BOOT_DEVICE_NOR , +BOOT_DEVICE_NOR2 ,BOOT_DEVICE_UART ,BOOT_DEVICE_SPI , BOOT_DEVICE_USB,
common/spl/spl_nor.c +1 -0
@@ -123,3 +123,4 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,return 0 ; }SPL_LOAD_IMAGE_METHOD ("NOR" ,0 ,BOOT_DEVICE_NOR , spl_nor_load_image); +SPL_LOAD_IMAGE_METHOD ("NOR2" ,0 ,BOOT_DEVICE_NOR2 , spl_nor_load_image);
Signature · 1 line
2.34.1
Re: [PATCH v2 1/2] spl: spl_nor: add BOOT_DEVICE_NOR2 as alternative SPL_LOAD_IMAGE_METHOD
Quoted 11 lines · Mario Kicherer
Add
BOOT_DEVICE_NOR2as a secondSPL_LOAD_IMAGE_METHODto enable a board-specificspl_nor_get_uboot_base()function to return an alternative address in the NOR flash in case booting fromBOOT_DEVICE_NORfails.Signed-off-by Mario Kicherer <[email protected]>--- arch/arm/include/asm/spl.h | 1 + arch/mips/include/asm/spl.h | 1 + arch/riscv/include/asm/spl.h | 1 + common/spl/spl_nor.c | 1 + 4 files changed, 4 insertions(+)
This breaks a lot of platforms, as it only covers a few of the cases where BOOT_DEVICE_NOR is listed. I would also really like to see how this ends up being used in the board specific case as I do wonder if we can't solve this some other way that won't have impact so many other platforms. Thanks!
Signature · 1 line
Tom
Re: [PATCH v2 1/2] spl: spl_nor: add BOOT_DEVICE_NOR2 as alternative SPL_LOAD_IMAGE_METHOD
Hello Tom,
Quoted 5 lines · Tom Rini
This breaks a lot of platforms, as it only covers a few of the cases where
BOOT_DEVICE_NORis listed. I would also really like to see how this ends up being used in the board specific case as I do wonder if we can't solve this some other way that won't have impact so many other platforms. Thanks!
Hm, I did a grep through the source code and that were the only places where the new value is used as part of an enum. BOOT_DEVICE_NOR is used in more places but they also #define this themselves - if I did not miss something.
Furthermore, BOOT_DEVICE_NOR2 will not be used by default. A board has to define its own board_boot_order() function like this to use the new BOOT_DEVICE_NOR2 value:
void board_boot_order(u32 *spl_boot_list)
{
spl_boot_list[0] = BOOT_DEVICE_NOR;
spl_boot_list[1] = BOOT_DEVICE_NOR2;
}If they do not explicitly add BOOT_DEVICE_NOR2, they should not be affected by this patch, as far as I understood the code. I tried to model this similar to the BOOT_DEVICE_MMC1 and _MMC2 values.
Then, they can also define an own spl_nor_get_uboot_base() like the following that should return an address where U-Boot tries to load a valid image:
unsigned long spl_nor_get_uboot_base(struct spl_boot_device *bootdev)
{
if (bootdev->boot_device == BOOT_DEVICE_NOR) {
/* first address that is tried */
return UBOOT_PARTITION_1_IN_NOR;
else if (bootdev->boot_device == BOOT_DEVICE_NOR2) {
/*
* if loading of the first image failed for whatever
* reason, try this address as well:
*/
return UBOOT_PARTITION_2_IN_NOR;
}
}With this patch, it is possible to provide a fallback U-Boot image like above or to use an A/B slot scheme in case a bootloader update could be necessary in the field in the future.
Best regards,
Mario
Re: [PATCH v2 1/2] spl: spl_nor: add BOOT_DEVICE_NOR2 as alternative SPL_LOAD_IMAGE_METHOD
Quoted 9 lines · Mario Kicherer
Hello Tom,
Quoted 5 lines · Tom Rini
This breaks a lot of platforms, as it only covers a few of the cases where
BOOT_DEVICE_NORis listed. I would also really like to see how this ends up being used in the board specific case as I do wonder if we can't solve this some other way that won't have impact so many other platforms. Thanks!
Quoted 4 lines
Hm, I did a grep through the source code and that were the only places where the new value is used as part of an enum.
BOOT_DEVICE_NORis used in more places but they also #define this themselves - if I did not miss something.
Yes, all of the platforms that define the value (since it roughly means "ROM set this value in something we can check") instead of enum'ing it still compile that file and now fail to build.
Quoted 32 lines
Furthermore,
BOOT_DEVICE_NOR2will not be used by default. A board has to define its ownboard_boot_order()function like this to use the newBOOT_DEVICE_NOR2value:void
board_boot_order(u32 *spl_boot_list){ spl_boot_list[0] = BOOT_DEVICE_NOR; spl_boot_list[1] = BOOT_DEVICE_NOR2; }If they do not explicitly add
BOOT_DEVICE_NOR2, they should not be affected by this patch, as far as I understood the code. I tried to model this similar to theBOOT_DEVICE_MMC1and_MMC2values.Then, they can also define an own
spl_nor_get_uboot_base()like the following that should return an address where U-Boot tries to load a valid image:unsigned long
spl_nor_get_uboot_base(struct spl_boot_device *bootdev){ if (bootdev->boot_device == BOOT_DEVICE_NOR) { /* first address that is tried */ return UBOOT_PARTITION_1_IN_NOR; else if (bootdev->boot_device == BOOT_DEVICE_NOR2) { /* * if loading of the first image failed for whatever * reason, try this address as well: */ return UBOOT_PARTITION_2_IN_NOR; } }
Quoted 3 lines
With this patch, it is possible to provide a fallback U-Boot image like above or to use an A/B slot scheme in case a bootloader update could be necessary in the field in the future.
Ah, OK. Keep in mind that MMC1/MMC2 are for different physical MMC devices on a given platform. I think this is more like the case where you should be able to override spl_nor_get_uboot_base at the board level to say if you're loading A or B?
Signature · 1 line
Tom
Re: [PATCH v2 1/2] spl: spl_nor: add BOOT_DEVICE_NOR2 as alternative SPL_LOAD_IMAGE_METHOD
Quoted 3 lines · Tom Rini
Yes, all of the platforms that define the value (since it roughly means "ROM set this value in something we can check") instead of enum'ing it still compile that file and now fail to build.
Okay, I think I understand your point now. I am not sure what's the best way to proceed here. Should I try to build all targets that contain BOOT_DEVICE_NOR and add a #define for BOOT_DEVICE_NOR2 if my patch really breaks the build? Or should I just add a #define BOOT_DEVICE_NOR2 to every #define BOOT_DEVICE_NOR?
It looks like a change would be necessary in these files then:
arch/arm/include/asm/arch-am33xx/spl.harch/arm/include/asm/arch-orion5x/spl.harch/arm/mach-k3/include/mach/j721e_spl.harch/arm/mach-k3/include/mach/j721s2_spl.harch/microblaze/include/asm/spl.harch/powerpc/include/asm/spl.h
Quoted 4 lines
Ah, OK. Keep in mind that MMC1/MMC2 are for different physical MMC devices on a given platform. I think this is more like the case where you should be able to override
spl_nor_get_uboot_baseat the board level to say if you're loading A or B?
Ah yes, it's been a while since I wrote this patch originally. spl_nor_get_uboot_base() chooses between A and B and BOOT_DEVICE_NOR2 signals that I should choose the other one now.
Thank you!
Mario
Re: [PATCH v2 1/2] spl: spl_nor: add BOOT_DEVICE_NOR2 as alternative SPL_LOAD_IMAGE_METHOD
Quoted 20 lines · Mario Kicherer
Quoted 3 lines · Tom Rini
Yes, all of the platforms that define the value (since it roughly means "ROM set this value in something we can check") instead of enum'ing it still compile that file and now fail to build.
Okay, I think I understand your point now. I am not sure what's the best way to proceed here. Should I try to build all targets that contain
BOOT_DEVICE_NORand add a #define forBOOT_DEVICE_NOR2if my patch really breaks the build? Or should I just add a #defineBOOT_DEVICE_NOR2to every #defineBOOT_DEVICE_NOR?It looks like a change would be necessary in these files then:
arch/arm/include/asm/arch-am33xx/spl.harch/arm/include/asm/arch-orion5x/spl.harch/arm/mach-k3/include/mach/j721e_spl.harch/arm/mach-k3/include/mach/j721s2_spl.harch/microblaze/include/asm/spl.harch/powerpc/include/asm/spl.h
Quoted 8 lines
Quoted 4 lines
Ah, OK. Keep in mind that MMC1/MMC2 are for different physical MMC devices on a given platform. I think this is more like the case where you should be able to override
spl_nor_get_uboot_baseat the board level to say if you're loading A or B?Ah yes, it's been a while since I wrote this patch originally.
spl_nor_get_uboot_base()chooses between A and B andBOOT_DEVICE_NOR2signals that I should choose the other one now.
I think you should be able to solve this problem without making further changes upstream, yes.
Signature · 1 line
Tom
Re: [PATCH v2 1/2] spl: spl_nor: add BOOT_DEVICE_NOR2 as alternative SPL_LOAD_IMAGE_METHOD
Quoted 20 lines · Tom Rini
Quoted 20 lines
Okay, I think I understand your point now. I am not sure what's the best way to proceed here. Should I try to build all targets that contain
BOOT_DEVICE_NORand add a #define forBOOT_DEVICE_NOR2if my patch really breaks the build? Or should I just add a #defineBOOT_DEVICE_NOR2to every #defineBOOT_DEVICE_NOR?It looks like a change would be necessary in these files then:
arch/arm/include/asm/arch-am33xx/spl.harch/arm/include/asm/arch-orion5x/spl.harch/arm/mach-k3/include/mach/j721e_spl.harch/arm/mach-k3/include/mach/j721s2_spl.harch/microblaze/include/asm/spl.harch/powerpc/include/asm/spl.hQuoted 4 lines
Ah, OK. Keep in mind that MMC1/MMC2 are for different physical MMC devices on a given platform. I think this is more like the case where you should be able to override
spl_nor_get_uboot_baseat the board level to say if you're loading A or B?
Quoted 6 lines
Quoted 3 lines
Ah yes, it's been a while since I wrote this patch originally.
spl_nor_get_uboot_base()chooses between A and B andBOOT_DEVICE_NOR2signals that I should choose the other one now.I think you should be able to solve this problem without making further changes upstream, yes.
I am not sure I understand your answer. Both ways I mentioned would probably require further changes. Or do you mean I should find a way to implement this only with board-specific code?
I sent two additional patches to the mailing list:
[PATCH] spl: spl_nor: use panic instead of hang if booting fails [PATCH] spl: spl-nor: return error if no valid image was loaded
which would make this possible.
However, I would prefer this patch series as it enables loading U-Boot from an alternate location without additional resets and relying on a boot counter.
Best regards,
Mario
PATCH v2 2/2 spl: spl_nor: add spl_boot_device parameter to spl_nor_get_uboot_base()
In reply to Mario KichererWith this additional parameter, a board-specific implementation of this function can return an alternative address in case booting from the first address in the NOR flash fails.
--- arch/arm/mach-imx/image-container.c | 2 +- arch/mips/mach-mtmips/mt7621/spl/spl.c | 2 +- arch/mips/mach-mtmips/spl.c | 2 +- common/spl/spl_nor.c | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-)
arch/arm/mach-imx/image-container.c +1 -1
@@ -243,7 +243,7 @@ uint32_t spl_nand_get_uboot_raw_page(void)#endif #ifdef CONFIG_SPL_NOR_SUPPORT -unsigned long spl_nor_get_uboot_base (void ) +unsigned long spl_nor_get_uboot_base (struct spl_boot_device *bootdev) {int end;
arch/mips/mach-mtmips/mt7621/spl/spl.c +1 -1
@@ -61,7 +61,7 @@ void board_boot_order(u32 *spl_boot_list)#endif } -unsigned long spl_nor_get_uboot_base (void ) +unsigned long spl_nor_get_uboot_base (struct spl_boot_device *bootdev) {const struct tpl_info *tpli;const struct legacy_img_hdr *hdr;
arch/mips/mach-mtmips/spl.c +1 -1
@@ -34,7 +34,7 @@ void board_boot_order(u32 *spl_boot_list) spl_boot_list[0 ] =BOOT_DEVICE_NOR ; } -unsigned long spl_nor_get_uboot_base (void ) +unsigned long spl_nor_get_uboot_base (struct spl_boot_device *bootdev) {void *uboot_base = __image_copy_end;
common/spl/spl_nor.c +5 -5
@@ -17,7 +17,7 @@ static ulong spl_nor_load_read(struct spl_load_info *load, ulong sector,return count; } -unsigned long __weak spl_nor_get_uboot_base (void ) +unsigned long __weak spl_nor_get_uboot_base (struct spl_boot_device *bootdev) {return CONFIG_SYS_UBOOT_BASE ; }
@@ -91,13 +91,13 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,* defined location in SDRAM */ #ifdef CONFIG_SPL_LOAD_FIT - header = (const struct legacy_img_hdr *)spl_nor_get_uboot_base (); + header = (const struct legacy_img_hdr *)spl_nor_get_uboot_base (bootdev);if (image_get_magic (header) ==FDT_MAGIC ) {debug ("Found FIT format U-Boot\n" ); load.bl_len =1 ; load.read = spl_nor_load_read;return spl_load_simple_fit (spl_image, &load, -spl_nor_get_uboot_base (), +spl_nor_get_uboot_base (bootdev), (void *)header); }#endif
@@ -105,7 +105,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image, load.bl_len =1 ; load.read = spl_nor_load_read;return spl_load_imx_container (spl_image, &load, -spl_nor_get_uboot_base ()); +spl_nor_get_uboot_base (bootdev)); }/* Legacy image handling */
@@ -116,7 +116,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image, load.read = spl_nor_load_read;spl_nor_load_read (&load,spl_nor_get_uboot_base (bootdev),sizeof (hdr), &hdr);return spl_load_legacy_img (spl_image, bootdev, &load, -spl_nor_get_uboot_base (), +spl_nor_get_uboot_base (bootdev), &hdr); }
Signature · 1 line
2.34.1