Clean up bloblist initialization
cover Clean up bloblist initialization
Hey all,
I've been sitting on this series for a bit (as the patch dates imply), and I'm ready to move forward now with it.
This series does a few small but important cleanups to how we check for, and initialize a bloblist. The first thing is that the way things are done today, our HANDOFF code can only work with a fixed bloblist location, so express that requirement in Kconfig. Next, we demote the scary message about "Bloblist at ... not found" to a debug because we most often see that because the bloblist doesn't (and can't) exist yet. Finally, we remove bloblist_maybe_init and split this in to an exists and a real init. This results in practically no growth (between 8 bytes growth to 12 bytes saved, with some outliers saving much more thanks to knowing it's impossible to have been passed a bloblist yet). This also cleans up some of the code around checking for / knowing about a bloblist existing.
Signature · 1 line
Tom
PATCH 1/3 bloblist / handoff: Make this depend on BLOBLIST_FIXED
Currently, the only way we support passing a bloblist from one stage to the next is via the BLOBLIST_FIXED mechanism. Update the Kconfig logic to express this constraint.
--- common/spl/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/Kconfig +1 -1
@@ -220,7 +220,7 @@ source "common/spl/Kconfig.nxp" config HANDOFF bool "Pass hand-off information from SPL to U-Boot proper" - depends on BLOBLIST + depends on BLOBLIST_FIXED help It is useful to be able to pass information from SPL to U-Boot proper to preserve state that is known in SPL and is needed in U-Boot.
Signature · 1 line
2.43.0
Re: [PATCH 1/3] bloblist / handoff: Make this depend on BLOBLIST_FIXED
Hi Tom,
Quoted 15 lines · Tom Rini
Currently, the only way we support passing a bloblist from one stage to the next is via the
BLOBLIST_FIXEDmechanism. Update theKconfiglogic to express this constraint.Signed-off-by Tom Rini <[email protected]>--- common/spl/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)common/spl/Kconfig +0
-0
common/spl/Kconfig source "common/spl/Kconfig.nxp" · line 223
Quoted 5 lines
common/spl/Kconfig +1
-1@@ -220,7 +220,7 @@ source "common/spl/Kconfig.nxp" config HANDOFF bool "Pass hand-off information from SPL to U-Boot proper" - depends on BLOBLIST + depends on BLOBLIST_FIXED
I am wondering if SPL can use the same way as we did for Arm Firmware Handoff - the address is not defined by Kconfig but via register conventions?
Regards,
Raymond
Quoted 6 lines
common/spl/Kconfig +0
-1help It is useful to be able to pass information from SPL to U-Boot proper to preserve state that is known in SPL and is needed in U-Boot. --2.43.0
Re: [PATCH 1/3] bloblist / handoff: Make this depend on BLOBLIST_FIXED
Quoted 19 lines · Raymond Mao
Hi Tom,
Quoted 16 lines · Tom Rini
Currently, the only way we support passing a bloblist from one stage to the next is via the
BLOBLIST_FIXEDmechanism. Update theKconfiglogic to express this constraint.Signed-off-by Tom Rini <[email protected]>--- common/spl/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)common/spl/Kconfig +0
-0@@ -220,7 +220,7 @@ source "common/spl/Kconfig.nxp"
Quoted 8 lines
common/spl/Kconfig source "common/spl/Kconfig.nxp" · line 223
Quoted 4 lines
common/spl/Kconfig +1
-1config HANDOFF bool "Pass hand-off information from SPL to U-Boot proper" - depends on BLOBLIST + depends on BLOBLIST_FIXEDI am wondering if SPL can use the same way as we did for Arm Firmware Handoff - the address is not defined by
Kconfigbut via register conventions?
As part of future work, yes, it would be good to move in that direction.
Signature · 1 line
Tom
Raymond Mao
Reviewed-byRe: [PATCH 1/3] bloblist / handoff: Make this depend on BLOBLIST_FIXED
Hi Tom,
Quoted 30 lines · Tom Rini
Quoted 19 lines · Raymond Mao
Hi Tom,
Quoted 16 lines · Tom Rini
Currently, the only way we support passing a bloblist from one stage to the next is via the
BLOBLIST_FIXEDmechanism. Update theKconfiglogic to express this constraint.Signed-off-by Tom Rini <[email protected]>--- common/spl/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)common/spl/Kconfig +0
-0@@ -220,7 +220,7 @@ source "common/spl/Kconfig.nxp"Quoted 8 lines
common/spl/Kconfig source "common/spl/Kconfig.nxp" · line 223
Quoted 4 lines
common/spl/Kconfig +1
-1config HANDOFF bool "Pass hand-off information from SPL to U-Boot proper" - depends on BLOBLIST + depends on BLOBLIST_FIXEDI am wondering if SPL can use the same way as we did for Arm Firmware Handoff - the address is not defined by
Kconfigbut via register conventions?
Quoted 2 lines
As part of future work, yes, it would be good to move in that direction.
Thanks. That is reasonable. At the moment this patch is fine to me.
Raymond
Quoted 2 lines
--
Tom
PATCH 2/3 bloblist: Demote not finding a bloblist to a debug
In reply to Tom RiniThe message about not finding a bloblist will quite often be seen at least once, and is non-fatal. Demote this to a log_debug message from a log_warning message.
--- common/bloblist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common/bloblist.c +2 -2
@@ -613,8 +613,8 @@ int bloblist_init(void) ret =bloblist_check (addr, size);if (ret) -log_warning ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); +log_debug ("Bloblist at %lx not found (err=%d)\n" , + addr, ret);else /* Get the real size */ size = gd->bloblist->total_size;
Signature · 1 line
2.43.0
Re: [PATCH 2/3] bloblist: Demote not finding a bloblist to a debug
Hi Tom,
Quoted 10 lines · Tom Rini
The message about not finding a bloblist will quite often be seen at least once, and is non-fatal. Demote this to a
log_debugmessage from alog_warningmessage.Signed-off-by Tom Rini <[email protected]>--- common/bloblist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Looks fine to me.
Raymond
Quoted 18 lines
common/bloblist.c +2
-3@@ -613,8 +613,8 @@ int bloblist_init(void) ret =bloblist_check (addr, size);if (ret) -log_warning ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); +log_debug ("Bloblist at %lx not found (err=%d)\n" , + addr, ret);else /* Get the real size */ size = gd->bloblist->total_size; --2.43.0
PATCH 3/3 bloblist: Rework bloblist_init and bloblist_maybe_init
In reply to Tom RiniWith bloblist, we need to both see if one already exists as well as create one if it does not. However, the current implementation leads to odd cases where we attempt to create a bloblist before this is possible and have things be overly complicated when we are given one to work with.
This reworks things to instead have a bloblist_exists function, which as the name implies checks for an existing bloblist. This is used in the case of booting, to see if we have one and in turn if we have a device tree there as well as in the bloblist_init function to see if we need to do anything.
In practical details, we move the logic from bloblist_init that was checking for a bloblist to the new bloblist_exists function and then can clarify the logic as it is much easier to state when we know we do not have one rather than all the ways we might have one. Then we have the locations that set gd->bloblist now also set the GD_FLG_BLOBLIST_READY flag.
--- common/bloblist.c | 144 +++++++++++++++++++++++---------------------- common/board_f.c | 4 +- include/bloblist.h | 32 +++++----- lib/fdtdec.c | 15 ++--- 4 files changed, 96 insertions(+), 99 deletions(-)
common/bloblist.c +73 -71
@@ -448,6 +448,7 @@ int bloblist_new(ulong addr, uint size, uint flags, uint align_log2) hdr->align_log2 = align_log2 ? align_log2 :BLOBLIST_BLOB_ALIGN_LOG2 ; hdr->chksum =0 ; gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }
@@ -475,6 +476,7 @@ int bloblist_check(ulong addr, uint size)return log_msg_ret ("Bad checksum" , -EIO ); } gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }
@@ -576,90 +578,88 @@ int __weak xferlist_from_boot_arg(ulong __always_unused *addr)return -ENOENT ; } -int bloblist_init (void ) +bool bloblist_exists (void ) { -bool fixed =IS_ENABLED (CONFIG_BLOBLIST_FIXED ); -int ret =0 ; -ulong addr =0 , size; +int ret; +ulong addr =0 ;/* Check if a valid transfer list passed in */ -if (!xferlist_from_boot_arg (&addr)) { - size =bloblist_get_total_size (); - }else { -/* -* If U-Boot is not in the first phase, an existing bloblist must -* be at a fixed address. -*/ -bool from_addr = fixed && !xpl_is_first_phase (); - -/* -* If Firmware Handoff is mandatory but no transfer list is -* observed, report it as an error. -*/ -if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) -return -ENOENT ; - - ret = -ENOENT ; - -if (xpl_prev_phase () ==PHASE_TPL && - !IS_ENABLED (CONFIG_TPL_BLOBLIST )) - from_addr = false; -if (fixed) - addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , -CONFIG_BLOBLIST_ADDR ); - size =CONFIG_BLOBLIST_SIZE ; - -if (from_addr) - ret =bloblist_check (addr, size); +if (!xferlist_from_boot_arg (&addr)) + goto found; -if (ret) -log_debug ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); -else -/* Get the real size */ - size = gd->bloblist->total_size; - } +/* +* If Firmware Handoff is mandatory but no transfer list is +* observed, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return false; -if (ret) { -/* -* If we don't have a bloblist from a fixed address, or the one -* in the fixed address is not valid. we must allocate the -* memory for it now. -*/ -if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { -void *ptr =memalign (BLOBLIST_ALIGN , size); - -if (!ptr) -return log_msg_ret ("alloc" , -ENOMEM ); - addr =map_to_sysmem (ptr); - }else if (!fixed) { -return log_msg_ret ("BLOBLIST_FIXED is not enabled" , - ret); - } -log_debug ("Creating new bloblist size %lx at %lx\n" , size, - addr); - ret =bloblist_new (addr, size,0 ,0 ); - }else { -log_debug ("Found existing bloblist size %lx at %lx\n" , size, - addr); - } +/* +* We have checked for a valid transfer list being passed. At this +* point, if we do not have a fixed address for the bloblist, we cannot +* be provided with one. +*/ +if (xpl_is_first_phase () || !IS_ENABLED (CONFIG_BLOBLIST_FIXED )) +return false; -if (ret) -return log_msg_ret ("ini" , ret); - gd->flags |=GD_FLG_BLOBLIST_READY ; +/* +* Check for a valid list as the configured address. +*/ + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + ret =bloblist_check (addr,CONFIG_BLOBLIST_SIZE ); +if (!ret) + goto found; + +log_debug ("Bloblist at %lx not found (err=%d)\n" , addr, ret); +return false; +found: #ifdef DEBUGbloblist_show_stats ();bloblist_show_list ();#endif - -return 0 ; +return true; } -int bloblist_maybe_init (void ) +int bloblist_init (void ) { -if (CONFIG_IS_ENABLED (BLOBLIST ) && !(gd->flags &GD_FLG_BLOBLIST_READY )) -return bloblist_init (); +int ret; +ulong addr =0 , size =CONFIG_BLOBLIST_SIZE ; + +if (gd->flags &GD_FLG_BLOBLIST_READY ) { +log_debug ("Found existing bloblist size %x at %p\n" , + gd->bloblist->total_size, gd->bloblist); +return 0 ; + } + +/* +* If Firmware Handoff is mandatory but no transfer list has been +* observed by fdtdec_setup, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return -ENOENT ; + +/* +* If we don't have an existing bloblist, we either need +* to allocate one now, or initialize the fixed address +* space as a bloblist. +*/ +if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { +void *ptr =memalign (BLOBLIST_ALIGN , size); + +if (!ptr) +return log_msg_ret ("alloc" , -ENOMEM ); + addr =map_to_sysmem (ptr); + }else + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + +log_debug ("Creating new bloblist size %lx at %lx\n" , size, + addr); + ret =bloblist_new (addr, size,0 ,0 ); +if (ret) +return log_msg_ret ("ini" , ret);return 0 ; }
@@ -687,7 +687,9 @@ int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig, ulong xlist)return ret;if (rfdt != (ulong )bloblist_find (BLOBLISTT_CONTROL_FDT ,0 )) { - gd->bloblist =NULL ;/* Reset the gd bloblist pointer */ +/* Remove this bloblist from gd */ + gd->bloblist =NULL ; + gd->flags &= ~GD_FLG_BLOBLIST_READY ;return -EIO ; }
common/board_f.c +3 -1
@@ -894,7 +894,9 @@ static void initcall_run_f(void)INITCALL (log_init);INITCALL (initf_bootstage);/* uses its own timer, so does not need DM */ INITCALL (event_init); -INITCALL (bloblist_maybe_init); +#if CONFIG_IS_ENABLED (BLOBLIST ) +INITCALL (bloblist_init); +#endif INITCALL (setup_spl_handoff);#if CONFIG_IS_ENABLED (CONSOLE_RECORD_INIT_F )INITCALL (console_record_init);
include/bloblist.h +15 -17
@@ -488,10 +488,24 @@ const char *bloblist_tag_name(enum bloblist_tag_t tag);*/ int bloblist_reloc (void *to,uint to_size); +/** +* bloblist_exists() - Check for the prior existence of a bloblist +* +* This will check for a transfer list having been passed via standard +* convention. If CONFIG_BLOBLIST_PASSAGE_MANDATORY is selected and one is not +* found, we return false. +* +* If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and +* CONFIG_BLOBLIST_SIZE to check for a bloblist. +* +* Return: true if found, false if not +*/ +bool bloblist_exists (void ); +/** * bloblist_init() - Init the bloblist system with a single bloblist * -* This locates and sets up the blocklist for use. +* This creates a bloblist for use, if not already found. * * If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and * CONFIG_BLOBLIST_SIZE to set up a bloblist for use by U-Boot.
@@ -508,22 +522,6 @@ int bloblist_reloc(void *to, uint to_size);*/ int bloblist_init (void ); -#if CONFIG_IS_ENABLED (BLOBLIST ) -/** -* bloblist_maybe_init() - Init the bloblist system if not already done -* -* Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not set -* -* Return: 0 if OK, -ve on error -*/ -int bloblist_maybe_init (void ); -#else -static inline int bloblist_maybe_init (void ) -{ -return 0 ; -} -#endif /* BLOBLIST */ -/** * bloblist_check_reg_conv() - Check whether the bloblist is compliant to * the register conventions according to the
lib/fdtdec.c +5 -10
@@ -1822,17 +1822,12 @@ int fdtdec_setup(void)int ret = -ENOENT ;/* -* If allowing a bloblist, check that first. There was discussion about -* adding an OF_BLOBLIST Kconfig, but this was rejected. -* -* The necessary test is whether the previous phase passed a bloblist, -* not whether this phase creates one. +* If allowing a bloblist, check that first. The necessary test is +* whether the previous phase passed a bloblist, not whether this phase +* creates one. */ -if (CONFIG_IS_ENABLED (BLOBLIST ) && - (xpl_prev_phase () !=PHASE_TPL || -IS_ENABLED (CONFIG_TPL_BLOBLIST ))) { - ret =bloblist_maybe_init (); -if (!ret) { +if (CONFIG_IS_ENABLED (BLOBLIST ) && (xpl_prev_phase () !=PHASE_TPL )) { +if (bloblist_exists ()) { gd->fdt_blob =bloblist_find (BLOBLISTT_CONTROL_FDT ,0 );if (gd->fdt_blob) { gd->fdt_src =FDTSRC_BLOBLIST ;
Signature · 1 line
2.43.0
Re: [PATCH 3/3] bloblist: Rework bloblist_init and bloblist_maybe_init
Hi Tom,
Quoted 299 lines · Tom Rini
With bloblist, we need to both see if one already exists as well as create one if it does not. However, the current implementation leads to odd cases where we attempt to create a bloblist before this is possible and have things be overly complicated when we are given one to work with.
This reworks things to instead have a
bloblist_existsfunction, which as the name implies checks for an existing bloblist. This is used in the case of booting, to see if we have one and in turn if we have a device tree there as well as in thebloblist_initfunction to see if we need to do anything.In practical details, we move the logic from
bloblist_initthat was checking for a bloblist to the newbloblist_existsfunction and then can clarify the logic as it is much easier to state when we know we do not have one rather than all the ways we might have one. Then we have the locations that setgd->bloblistnow also set theGD_FLG_BLOBLIST_READYflag.Signed-off-by Tom Rini <[email protected]>--- common/bloblist.c | 144 +++++++++++++++++++++++---------------------- common/board_f.c | 4 +- include/bloblist.h | 32 +++++----- lib/fdtdec.c | 15 ++--- 4 files changed, 96 insertions(+), 99 deletions(-)common/bloblist.c +73
-71@@ -448,6 +448,7 @@ int bloblist_new(ulong addr, uint size, uint flags, uint align_log2) hdr->align_log2 = align_log2 ? align_log2 :BLOBLIST_BLOB_ALIGN_LOG2 ; hdr->chksum =0 ; gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -475,6 +476,7 @@ int bloblist_check(ulong addr, uint size)return log_msg_ret ("Bad checksum" , -EIO ); } gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -576,90 +578,88 @@ int __weak xferlist_from_boot_arg(ulong __always_unused *addr)return -ENOENT ; } -int bloblist_init (void ) +bool bloblist_exists (void ) { -bool fixed =IS_ENABLED (CONFIG_BLOBLIST_FIXED ); -int ret =0 ; -ulong addr =0 , size; +int ret; +ulong addr =0 ;/* Check if a valid transfer list passed in */ -if (!xferlist_from_boot_arg (&addr)) { - size =bloblist_get_total_size (); - }else { -/* -* If U-Boot is not in the first phase, an existing bloblist must -* be at a fixed address. -*/ -bool from_addr = fixed && !xpl_is_first_phase (); - -/* -* If Firmware Handoff is mandatory but no transfer list is -* observed, report it as an error. -*/ -if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) -return -ENOENT ; - - ret = -ENOENT ; - -if (xpl_prev_phase () ==PHASE_TPL && - !IS_ENABLED (CONFIG_TPL_BLOBLIST )) - from_addr = false; -if (fixed) - addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , -CONFIG_BLOBLIST_ADDR ); - size =CONFIG_BLOBLIST_SIZE ; - -if (from_addr) - ret =bloblist_check (addr, size); +if (!xferlist_from_boot_arg (&addr)) + goto found; -if (ret) -log_debug ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); -else -/* Get the real size */ - size = gd->bloblist->total_size; - } +/* +* If Firmware Handoff is mandatory but no transfer list is +* observed, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return false; -if (ret) { -/* -* If we don't have a bloblist from a fixed address, or the one -* in the fixed address is not valid. we must allocate the -* memory for it now. -*/ -if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { -void *ptr =memalign (BLOBLIST_ALIGN , size); - -if (!ptr) -return log_msg_ret ("alloc" , -ENOMEM ); - addr =map_to_sysmem (ptr); - }else if (!fixed) { -return log_msg_ret ("BLOBLIST_FIXED is not enabled" , - ret); - } -log_debug ("Creating new bloblist size %lx at %lx\n" , size, - addr); - ret =bloblist_new (addr, size,0 ,0 ); - }else { -log_debug ("Found existing bloblist size %lx at %lx\n" , size, - addr); - } +/* +* We have checked for a valid transfer list being passed. At this +* point, if we do not have a fixed address for the bloblist, we cannot +* be provided with one. +*/ +if (xpl_is_first_phase () || !IS_ENABLED (CONFIG_BLOBLIST_FIXED )) +return false; -if (ret) -return log_msg_ret ("ini" , ret); - gd->flags |=GD_FLG_BLOBLIST_READY ; +/* +* Check for a valid list as the configured address. +*/ + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + ret =bloblist_check (addr,CONFIG_BLOBLIST_SIZE ); +if (!ret) + goto found; + +log_debug ("Bloblist at %lx not found (err=%d)\n" , addr, ret); +return false; +found: #ifdef DEBUGbloblist_show_stats ();bloblist_show_list ();#endif - -return 0 ; +return true; } -int bloblist_maybe_init (void ) +int bloblist_init (void ) { -if (CONFIG_IS_ENABLED (BLOBLIST ) && !(gd->flags &GD_FLG_BLOBLIST_READY )) -return bloblist_init (); +int ret; +ulong addr =0 , size =CONFIG_BLOBLIST_SIZE ; + +if (gd->flags &GD_FLG_BLOBLIST_READY ) { +log_debug ("Found existing bloblist size %x at %p\n" , + gd->bloblist->total_size, gd->bloblist); +return 0 ; + } + +/* +* If Firmware Handoff is mandatory but no transfer list has been +* observed by fdtdec_setup, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return -ENOENT ; + +/* +* If we don't have an existing bloblist, we either need +* to allocate one now, or initialize the fixed address +* space as a bloblist. +*/ +if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { +void *ptr =memalign (BLOBLIST_ALIGN , size); + +if (!ptr) +return log_msg_ret ("alloc" , -ENOMEM ); + addr =map_to_sysmem (ptr); + }else + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + +log_debug ("Creating new bloblist size %lx at %lx\n" , size, + addr); + ret =bloblist_new (addr, size,0 ,0 ); +if (ret) +return log_msg_ret ("ini" , ret);return 0 ; }@@ -687,7 +687,9 @@ int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig, ulong xlist)return ret;if (rfdt != (ulong )bloblist_find (BLOBLISTT_CONTROL_FDT ,0 )) { - gd->bloblist =NULL ;/* Reset the gd bloblist pointer */ +/* Remove this bloblist from gd */ + gd->bloblist =NULL ; + gd->flags &= ~GD_FLG_BLOBLIST_READY ;return -EIO ; }common/board_f.c +3
-1@@ -894,7 +894,9 @@ static void initcall_run_f(void)INITCALL (log_init);INITCALL (initf_bootstage);/* uses its own timer, so does not need DM */ INITCALL (event_init); -INITCALL (bloblist_maybe_init); +#if CONFIG_IS_ENABLED (BLOBLIST ) +INITCALL (bloblist_init); +#endif INITCALL (setup_spl_handoff);#if CONFIG_IS_ENABLED (CONSOLE_RECORD_INIT_F )INITCALL (console_record_init);include/bloblist.h +15
-17@@ -488,10 +488,24 @@ const char *bloblist_tag_name(enum bloblist_tag_t tag);*/ int bloblist_reloc (void *to,uint to_size); +/** +* bloblist_exists() - Check for the prior existence of a bloblist +* +* This will check for a transfer list having been passed via standard +* convention. If CONFIG_BLOBLIST_PASSAGE_MANDATORY is selected and one is not +* found, we return false. +* +* If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and +* CONFIG_BLOBLIST_SIZE to check for a bloblist. +* +* Return: true if found, false if not +*/ +bool bloblist_exists (void ); +/** * bloblist_init() - Init the bloblist system with a single bloblist * -* This locates and sets up the blocklist for use. +* This creates a bloblist for use, if not already found. * * If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and * CONFIG_BLOBLIST_SIZE to set up a bloblist for use by U-Boot. @@ -508,22 +522,6 @@ int bloblist_reloc(void *to, uint to_size);*/ int bloblist_init (void ); -#if CONFIG_IS_ENABLED (BLOBLIST ) -/** -* bloblist_maybe_init() - Init the bloblist system if not already done -* -* Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not set -* -* Return: 0 if OK, -ve on error -*/ -int bloblist_maybe_init (void ); -#else -static inline int bloblist_maybe_init (void ) -{ -return 0 ; -} -#endif /* BLOBLIST */ -/** * bloblist_check_reg_conv() - Check whether the bloblist is compliant to * the register conventions according to the lib/fdtdec.c +0
-5@@ -1822,17 +1822,12 @@ int fdtdec_setup(void)int ret = -ENOENT ;/* -* If allowing a bloblist, check that first. There was discussion about -* adding an OF_BLOBLIST Kconfig, but this was rejected. -* -* The necessary test is whether the previous phase passed a bloblist, -* not whether this phase creates one.
lib/fdtdec.c int fdtdec_setup(void) · line 1829
Quoted 10 lines
lib/fdtdec.c +4
-5+* If allowing a bloblist, check that first. The necessary test is +* whether the previous phase passed a bloblist, not whether this phase +* creates one. */ -if (CONFIG_IS_ENABLED (BLOBLIST ) && - (xpl_prev_phase () !=PHASE_TPL || -IS_ENABLED (CONFIG_TPL_BLOBLIST ))) { - ret =bloblist_maybe_init (); -if (!ret) { +if (CONFIG_IS_ENABLED (BLOBLIST ) && (xpl_prev_phase () !=PHASE_TPL )) {
I think this change drops the TPL-provided blobs on TPL->SPL boots. When TPL_BLOBLIST is selected, the next phase starts with xpl_prev_phase() == PHASE_TPL.
This new guard now skips bloblist_exists(), so gd->flags never gets GD_FLG_BLOBLIST_READY; the later bloblist_init() in common/spl/spl.c then creates a fresh bloblist and overwrites the fixed-address list from TPL.
Regards,
Raymond
Quoted 7 lines
lib/fdtdec.c +1
-1+if (bloblist_exists ()) { gd->fdt_blob =bloblist_find (BLOBLISTT_CONTROL_FDT ,0 );if (gd->fdt_blob) { gd->fdt_src =FDTSRC_BLOBLIST ; --2.43.0
Re: [PATCH 3/3] bloblist: Rework bloblist_init and bloblist_maybe_init
Quoted 313 lines · Raymond Mao
Hi Tom,
Quoted 299 lines · Tom Rini
With bloblist, we need to both see if one already exists as well as create one if it does not. However, the current implementation leads to odd cases where we attempt to create a bloblist before this is possible and have things be overly complicated when we are given one to work with.
This reworks things to instead have a
bloblist_existsfunction, which as the name implies checks for an existing bloblist. This is used in the case of booting, to see if we have one and in turn if we have a device tree there as well as in thebloblist_initfunction to see if we need to do anything.In practical details, we move the logic from
bloblist_initthat was checking for a bloblist to the newbloblist_existsfunction and then can clarify the logic as it is much easier to state when we know we do not have one rather than all the ways we might have one. Then we have the locations that setgd->bloblistnow also set theGD_FLG_BLOBLIST_READYflag.Signed-off-by Tom Rini <[email protected]>--- common/bloblist.c | 144 +++++++++++++++++++++++---------------------- common/board_f.c | 4 +- include/bloblist.h | 32 +++++----- lib/fdtdec.c | 15 ++--- 4 files changed, 96 insertions(+), 99 deletions(-)common/bloblist.c +73
-71@@ -448,6 +448,7 @@ int bloblist_new(ulong addr, uint size, uint flags, uint align_log2) hdr->align_log2 = align_log2 ? align_log2 :BLOBLIST_BLOB_ALIGN_LOG2 ; hdr->chksum =0 ; gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -475,6 +476,7 @@ int bloblist_check(ulong addr, uint size)return log_msg_ret ("Bad checksum" , -EIO ); } gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -576,90 +578,88 @@ int __weak xferlist_from_boot_arg(ulong __always_unused *addr)return -ENOENT ; } -int bloblist_init (void ) +bool bloblist_exists (void ) { -bool fixed =IS_ENABLED (CONFIG_BLOBLIST_FIXED ); -int ret =0 ; -ulong addr =0 , size; +int ret; +ulong addr =0 ;/* Check if a valid transfer list passed in */ -if (!xferlist_from_boot_arg (&addr)) { - size =bloblist_get_total_size (); - }else { -/* -* If U-Boot is not in the first phase, an existing bloblist must -* be at a fixed address. -*/ -bool from_addr = fixed && !xpl_is_first_phase (); - -/* -* If Firmware Handoff is mandatory but no transfer list is -* observed, report it as an error. -*/ -if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) -return -ENOENT ; - - ret = -ENOENT ; - -if (xpl_prev_phase () ==PHASE_TPL && - !IS_ENABLED (CONFIG_TPL_BLOBLIST )) - from_addr = false; -if (fixed) - addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , -CONFIG_BLOBLIST_ADDR ); - size =CONFIG_BLOBLIST_SIZE ; - -if (from_addr) - ret =bloblist_check (addr, size); +if (!xferlist_from_boot_arg (&addr)) + goto found; -if (ret) -log_debug ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); -else -/* Get the real size */ - size = gd->bloblist->total_size; - } +/* +* If Firmware Handoff is mandatory but no transfer list is +* observed, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return false; -if (ret) { -/* -* If we don't have a bloblist from a fixed address, or the one -* in the fixed address is not valid. we must allocate the -* memory for it now. -*/ -if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { -void *ptr =memalign (BLOBLIST_ALIGN , size); - -if (!ptr) -return log_msg_ret ("alloc" , -ENOMEM ); - addr =map_to_sysmem (ptr); - }else if (!fixed) { -return log_msg_ret ("BLOBLIST_FIXED is not enabled" , - ret); - } -log_debug ("Creating new bloblist size %lx at %lx\n" , size, - addr); - ret =bloblist_new (addr, size,0 ,0 ); - }else { -log_debug ("Found existing bloblist size %lx at %lx\n" , size, - addr); - } +/* +* We have checked for a valid transfer list being passed. At this +* point, if we do not have a fixed address for the bloblist, we cannot +* be provided with one. +*/ +if (xpl_is_first_phase () || !IS_ENABLED (CONFIG_BLOBLIST_FIXED )) +return false; -if (ret) -return log_msg_ret ("ini" , ret); - gd->flags |=GD_FLG_BLOBLIST_READY ; +/* +* Check for a valid list as the configured address. +*/ + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + ret =bloblist_check (addr,CONFIG_BLOBLIST_SIZE ); +if (!ret) + goto found; + +log_debug ("Bloblist at %lx not found (err=%d)\n" , addr, ret); +return false; +found: #ifdef DEBUGbloblist_show_stats ();bloblist_show_list ();#endif - -return 0 ; +return true; } -int bloblist_maybe_init (void ) +int bloblist_init (void ) { -if (CONFIG_IS_ENABLED (BLOBLIST ) && !(gd->flags &GD_FLG_BLOBLIST_READY )) -return bloblist_init (); +int ret; +ulong addr =0 , size =CONFIG_BLOBLIST_SIZE ; + +if (gd->flags &GD_FLG_BLOBLIST_READY ) { +log_debug ("Found existing bloblist size %x at %p\n" , + gd->bloblist->total_size, gd->bloblist); +return 0 ; + } + +/* +* If Firmware Handoff is mandatory but no transfer list has been +* observed by fdtdec_setup, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return -ENOENT ; + +/* +* If we don't have an existing bloblist, we either need +* to allocate one now, or initialize the fixed address +* space as a bloblist. +*/ +if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { +void *ptr =memalign (BLOBLIST_ALIGN , size); + +if (!ptr) +return log_msg_ret ("alloc" , -ENOMEM ); + addr =map_to_sysmem (ptr); + }else + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + +log_debug ("Creating new bloblist size %lx at %lx\n" , size, + addr); + ret =bloblist_new (addr, size,0 ,0 ); +if (ret) +return log_msg_ret ("ini" , ret);return 0 ; }@@ -687,7 +687,9 @@ int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig, ulong xlist)return ret;if (rfdt != (ulong )bloblist_find (BLOBLISTT_CONTROL_FDT ,0 )) { - gd->bloblist =NULL ;/* Reset the gd bloblist pointer */ +/* Remove this bloblist from gd */ + gd->bloblist =NULL ; + gd->flags &= ~GD_FLG_BLOBLIST_READY ;return -EIO ; }common/board_f.c +3
-1@@ -894,7 +894,9 @@ static void initcall_run_f(void)INITCALL (log_init);INITCALL (initf_bootstage);/* uses its own timer, so does not need DM */ INITCALL (event_init); -INITCALL (bloblist_maybe_init); +#if CONFIG_IS_ENABLED (BLOBLIST ) +INITCALL (bloblist_init); +#endif INITCALL (setup_spl_handoff);#if CONFIG_IS_ENABLED (CONSOLE_RECORD_INIT_F )INITCALL (console_record_init);include/bloblist.h +15
-17@@ -488,10 +488,24 @@ const char *bloblist_tag_name(enum bloblist_tag_t tag);*/ int bloblist_reloc (void *to,uint to_size); +/** +* bloblist_exists() - Check for the prior existence of a bloblist +* +* This will check for a transfer list having been passed via standard +* convention. If CONFIG_BLOBLIST_PASSAGE_MANDATORY is selected and one is not +* found, we return false. +* +* If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and +* CONFIG_BLOBLIST_SIZE to check for a bloblist. +* +* Return: true if found, false if not +*/ +bool bloblist_exists (void ); +/** * bloblist_init() - Init the bloblist system with a single bloblist * -* This locates and sets up the blocklist for use. +* This creates a bloblist for use, if not already found. * * If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and * CONFIG_BLOBLIST_SIZE to set up a bloblist for use by U-Boot. @@ -508,22 +522,6 @@ int bloblist_reloc(void *to, uint to_size);*/ int bloblist_init (void ); -#if CONFIG_IS_ENABLED (BLOBLIST ) -/** -* bloblist_maybe_init() - Init the bloblist system if not already done -* -* Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not set -* -* Return: 0 if OK, -ve on error -*/ -int bloblist_maybe_init (void ); -#else -static inline int bloblist_maybe_init (void ) -{ -return 0 ; -} -#endif /* BLOBLIST */ -/** * bloblist_check_reg_conv() - Check whether the bloblist is compliant to * the register conventions according to the lib/fdtdec.c +0
-5@@ -1822,17 +1822,12 @@ int fdtdec_setup(void)int ret = -ENOENT ;/* -* If allowing a bloblist, check that first. There was discussion about -* adding an OF_BLOBLIST Kconfig, but this was rejected. -* -* The necessary test is whether the previous phase passed a bloblist, -* not whether this phase creates one. lib/fdtdec.c int fdtdec_setup(void) · line 1829
Quoted 10 lines
lib/fdtdec.c +4
-5+* If allowing a bloblist, check that first. The necessary test is +* whether the previous phase passed a bloblist, not whether this phase +* creates one. */ -if (CONFIG_IS_ENABLED (BLOBLIST ) && - (xpl_prev_phase () !=PHASE_TPL || -IS_ENABLED (CONFIG_TPL_BLOBLIST ))) { - ret =bloblist_maybe_init (); -if (!ret) { +if (CONFIG_IS_ENABLED (BLOBLIST ) && (xpl_prev_phase () !=PHASE_TPL )) {
Quoted 7 lines
I think this change drops the TPL-provided blobs on
TPL->SPLboots. WhenTPL_BLOBLISTis selected, the next phase starts withxpl_prev_phase()==PHASE_TPL.
This new guard now skipsbloblist_exists(), sogd->flagsnever getsGD_FLG_BLOBLIST_READY; the laterbloblist_init()incommon/spl/spl.cthen creates a fresh bloblist and overwrites the fixed-address list from TPL.
Ah right, oops. I guess the only question is if we should continue to optimize the TPL case (it can't exist) or just always check (maybe there's some 4 stage boot..).
Signature · 1 line
Tom
Re: [PATCH 3/3] bloblist: Rework bloblist_init and bloblist_maybe_init
Hi Tom,
Quoted 323 lines · Tom Rini
Quoted 313 lines · Raymond Mao
Hi Tom,
Quoted 299 lines · Tom Rini
With bloblist, we need to both see if one already exists as well as create one if it does not. However, the current implementation leads to odd cases where we attempt to create a bloblist before this is possible and have things be overly complicated when we are given one to work with.
This reworks things to instead have a
bloblist_existsfunction, which as the name implies checks for an existing bloblist. This is used in the case of booting, to see if we have one and in turn if we have a device tree there as well as in thebloblist_initfunction to see if we need to do anything.In practical details, we move the logic from
bloblist_initthat was checking for a bloblist to the newbloblist_existsfunction and then can clarify the logic as it is much easier to state when we know we do not have one rather than all the ways we might have one. Then we have the locations that setgd->bloblistnow also set theGD_FLG_BLOBLIST_READYflag.Signed-off-by Tom Rini <[email protected]>--- common/bloblist.c | 144 +++++++++++++++++++++++---------------------- common/board_f.c | 4 +- include/bloblist.h | 32 +++++----- lib/fdtdec.c | 15 ++--- 4 files changed, 96 insertions(+), 99 deletions(-)common/bloblist.c +73
-71@@ -448,6 +448,7 @@ int bloblist_new(ulong addr, uint size, uint flags, uint align_log2) hdr->align_log2 = align_log2 ? align_log2 :BLOBLIST_BLOB_ALIGN_LOG2 ; hdr->chksum =0 ; gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -475,6 +476,7 @@ int bloblist_check(ulong addr, uint size)return log_msg_ret ("Bad checksum" , -EIO ); } gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -576,90 +578,88 @@ int __weak xferlist_from_boot_arg(ulong __always_unused *addr)return -ENOENT ; } -int bloblist_init (void ) +bool bloblist_exists (void ) { -bool fixed =IS_ENABLED (CONFIG_BLOBLIST_FIXED ); -int ret =0 ; -ulong addr =0 , size; +int ret; +ulong addr =0 ;/* Check if a valid transfer list passed in */ -if (!xferlist_from_boot_arg (&addr)) { - size =bloblist_get_total_size (); - }else { -/* -* If U-Boot is not in the first phase, an existing bloblist must -* be at a fixed address. -*/ -bool from_addr = fixed && !xpl_is_first_phase (); - -/* -* If Firmware Handoff is mandatory but no transfer list is -* observed, report it as an error. -*/ -if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) -return -ENOENT ; - - ret = -ENOENT ; - -if (xpl_prev_phase () ==PHASE_TPL && - !IS_ENABLED (CONFIG_TPL_BLOBLIST )) - from_addr = false; -if (fixed) - addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , -CONFIG_BLOBLIST_ADDR ); - size =CONFIG_BLOBLIST_SIZE ; - -if (from_addr) - ret =bloblist_check (addr, size); +if (!xferlist_from_boot_arg (&addr)) + goto found; -if (ret) -log_debug ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); -else -/* Get the real size */ - size = gd->bloblist->total_size; - } +/* +* If Firmware Handoff is mandatory but no transfer list is +* observed, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return false; -if (ret) { -/* -* If we don't have a bloblist from a fixed address, or the one -* in the fixed address is not valid. we must allocate the -* memory for it now. -*/ -if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { -void *ptr =memalign (BLOBLIST_ALIGN , size); - -if (!ptr) -return log_msg_ret ("alloc" , -ENOMEM ); - addr =map_to_sysmem (ptr); - }else if (!fixed) { -return log_msg_ret ("BLOBLIST_FIXED is not enabled" , - ret); - } -log_debug ("Creating new bloblist size %lx at %lx\n" , size, - addr); - ret =bloblist_new (addr, size,0 ,0 ); - }else { -log_debug ("Found existing bloblist size %lx at %lx\n" , size, - addr); - } +/* +* We have checked for a valid transfer list being passed. At this +* point, if we do not have a fixed address for the bloblist, we cannot +* be provided with one. +*/ +if (xpl_is_first_phase () || !IS_ENABLED (CONFIG_BLOBLIST_FIXED )) +return false; -if (ret) -return log_msg_ret ("ini" , ret); - gd->flags |=GD_FLG_BLOBLIST_READY ; +/* +* Check for a valid list as the configured address. +*/ + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + ret =bloblist_check (addr,CONFIG_BLOBLIST_SIZE ); +if (!ret) + goto found; + +log_debug ("Bloblist at %lx not found (err=%d)\n" , addr, ret); +return false; +found: #ifdef DEBUGbloblist_show_stats ();bloblist_show_list ();#endif - -return 0 ; +return true; } -int bloblist_maybe_init (void ) +int bloblist_init (void ) { -if (CONFIG_IS_ENABLED (BLOBLIST ) && !(gd->flags &GD_FLG_BLOBLIST_READY )) -return bloblist_init (); +int ret; +ulong addr =0 , size =CONFIG_BLOBLIST_SIZE ; + +if (gd->flags &GD_FLG_BLOBLIST_READY ) { +log_debug ("Found existing bloblist size %x at %p\n" , + gd->bloblist->total_size, gd->bloblist); +return 0 ; + } + +/* +* If Firmware Handoff is mandatory but no transfer list has been +* observed by fdtdec_setup, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return -ENOENT ; + +/* +* If we don't have an existing bloblist, we either need +* to allocate one now, or initialize the fixed address +* space as a bloblist. +*/ +if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { +void *ptr =memalign (BLOBLIST_ALIGN , size); + +if (!ptr) +return log_msg_ret ("alloc" , -ENOMEM ); + addr =map_to_sysmem (ptr); + }else + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + +log_debug ("Creating new bloblist size %lx at %lx\n" , size, + addr); + ret =bloblist_new (addr, size,0 ,0 ); +if (ret) +return log_msg_ret ("ini" , ret);return 0 ; }@@ -687,7 +687,9 @@ int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig, ulong xlist)return ret;if (rfdt != (ulong )bloblist_find (BLOBLISTT_CONTROL_FDT ,0 )) { - gd->bloblist =NULL ;/* Reset the gd bloblist pointer */ +/* Remove this bloblist from gd */ + gd->bloblist =NULL ; + gd->flags &= ~GD_FLG_BLOBLIST_READY ;return -EIO ; }common/board_f.c +3
-1@@ -894,7 +894,9 @@ static void initcall_run_f(void)INITCALL (log_init);INITCALL (initf_bootstage);/* uses its own timer, so does not need DM */ INITCALL (event_init); -INITCALL (bloblist_maybe_init); +#if CONFIG_IS_ENABLED (BLOBLIST ) +INITCALL (bloblist_init); +#endif INITCALL (setup_spl_handoff);#if CONFIG_IS_ENABLED (CONSOLE_RECORD_INIT_F )INITCALL (console_record_init);include/bloblist.h +15
-17@@ -488,10 +488,24 @@ const char *bloblist_tag_name(enum bloblist_tag_t tag);*/ int bloblist_reloc (void *to,uint to_size); +/** +* bloblist_exists() - Check for the prior existence of a bloblist +* +* This will check for a transfer list having been passed via standard +* convention. If CONFIG_BLOBLIST_PASSAGE_MANDATORY is selected and one is not +* found, we return false. +* +* If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and +* CONFIG_BLOBLIST_SIZE to check for a bloblist. +* +* Return: true if found, false if not +*/ +bool bloblist_exists (void ); +/** * bloblist_init() - Init the bloblist system with a single bloblist * -* This locates and sets up the blocklist for use. +* This creates a bloblist for use, if not already found. * * If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and * CONFIG_BLOBLIST_SIZE to set up a bloblist for use by U-Boot. @@ -508,22 +522,6 @@ int bloblist_reloc(void *to, uint to_size);*/ int bloblist_init (void ); -#if CONFIG_IS_ENABLED (BLOBLIST ) -/** -* bloblist_maybe_init() - Init the bloblist system if not already done -* -* Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not set -* -* Return: 0 if OK, -ve on error -*/ -int bloblist_maybe_init (void ); -#else -static inline int bloblist_maybe_init (void ) -{ -return 0 ; -} -#endif /* BLOBLIST */ -/** * bloblist_check_reg_conv() - Check whether the bloblist is compliant to * the register conventions according to the lib/fdtdec.c +0
-5@@ -1822,17 +1822,12 @@ int fdtdec_setup(void)int ret = -ENOENT ;/* -* If allowing a bloblist, check that first. There was discussion about -* adding an OF_BLOBLIST Kconfig, but this was rejected. -* -* The necessary test is whether the previous phase passed a bloblist, -* not whether this phase creates one. lib/fdtdec.c int fdtdec_setup(void) · line 1829
Quoted 10 lines
lib/fdtdec.c +4
-5+* If allowing a bloblist, check that first. The necessary test is +* whether the previous phase passed a bloblist, not whether this phase +* creates one. */ -if (CONFIG_IS_ENABLED (BLOBLIST ) && - (xpl_prev_phase () !=PHASE_TPL || -IS_ENABLED (CONFIG_TPL_BLOBLIST ))) { - ret =bloblist_maybe_init (); -if (!ret) { +if (CONFIG_IS_ENABLED (BLOBLIST ) && (xpl_prev_phase () !=PHASE_TPL )) {Quoted 7 lines
I think this change drops the TPL-provided blobs on
TPL->SPLboots. WhenTPL_BLOBLISTis selected, the next phase starts withxpl_prev_phase()==PHASE_TPL.
This new guard now skipsbloblist_exists(), sogd->flagsnever getsGD_FLG_BLOBLIST_READY; the laterbloblist_init()incommon/spl/spl.cthen creates a fresh bloblist and overwrites the fixed-address list from TPL.
Quoted 4 lines
Ah right, oops. I guess the only question is if we should continue to optimize the TPL case (it can't exist) or just always check (maybe there's some 4 stage boot..).
That really depends on whether we shall consider the scenario of TPL. For the case of the Arm Firmware Handoff, stages before BL2 are not considered to hand information over to the next stage via Transfer List (aka. bloblist in U-Boot).
Regards,
Raymond
Quoted 2 lines
--
Tom
Re: [PATCH 3/3] bloblist: Rework bloblist_init and bloblist_maybe_init
Quoted 331 lines · Raymond Mao
Hi Tom,
Quoted 323 lines · Tom Rini
Quoted 313 lines · Raymond Mao
Hi Tom,
Quoted 299 lines · Tom Rini
With bloblist, we need to both see if one already exists as well as create one if it does not. However, the current implementation leads to odd cases where we attempt to create a bloblist before this is possible and have things be overly complicated when we are given one to work with.
This reworks things to instead have a
bloblist_existsfunction, which as the name implies checks for an existing bloblist. This is used in the case of booting, to see if we have one and in turn if we have a device tree there as well as in thebloblist_initfunction to see if we need to do anything.In practical details, we move the logic from
bloblist_initthat was checking for a bloblist to the newbloblist_existsfunction and then can clarify the logic as it is much easier to state when we know we do not have one rather than all the ways we might have one. Then we have the locations that setgd->bloblistnow also set theGD_FLG_BLOBLIST_READYflag.Signed-off-by Tom Rini <[email protected]>--- common/bloblist.c | 144 +++++++++++++++++++++++---------------------- common/board_f.c | 4 +- include/bloblist.h | 32 +++++----- lib/fdtdec.c | 15 ++--- 4 files changed, 96 insertions(+), 99 deletions(-)common/bloblist.c +73
-71@@ -448,6 +448,7 @@ int bloblist_new(ulong addr, uint size, uint flags, uint align_log2) hdr->align_log2 = align_log2 ? align_log2 :BLOBLIST_BLOB_ALIGN_LOG2 ; hdr->chksum =0 ; gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -475,6 +476,7 @@ int bloblist_check(ulong addr, uint size)return log_msg_ret ("Bad checksum" , -EIO ); } gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -576,90 +578,88 @@ int __weak xferlist_from_boot_arg(ulong __always_unused *addr)return -ENOENT ; } -int bloblist_init (void ) +bool bloblist_exists (void ) { -bool fixed =IS_ENABLED (CONFIG_BLOBLIST_FIXED ); -int ret =0 ; -ulong addr =0 , size; +int ret; +ulong addr =0 ;/* Check if a valid transfer list passed in */ -if (!xferlist_from_boot_arg (&addr)) { - size =bloblist_get_total_size (); - }else { -/* -* If U-Boot is not in the first phase, an existing bloblist must -* be at a fixed address. -*/ -bool from_addr = fixed && !xpl_is_first_phase (); - -/* -* If Firmware Handoff is mandatory but no transfer list is -* observed, report it as an error. -*/ -if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) -return -ENOENT ; - - ret = -ENOENT ; - -if (xpl_prev_phase () ==PHASE_TPL && - !IS_ENABLED (CONFIG_TPL_BLOBLIST )) - from_addr = false; -if (fixed) - addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , -CONFIG_BLOBLIST_ADDR ); - size =CONFIG_BLOBLIST_SIZE ; - -if (from_addr) - ret =bloblist_check (addr, size); +if (!xferlist_from_boot_arg (&addr)) + goto found; -if (ret) -log_debug ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); -else -/* Get the real size */ - size = gd->bloblist->total_size; - } +/* +* If Firmware Handoff is mandatory but no transfer list is +* observed, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return false; -if (ret) { -/* -* If we don't have a bloblist from a fixed address, or the one -* in the fixed address is not valid. we must allocate the -* memory for it now. -*/ -if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { -void *ptr =memalign (BLOBLIST_ALIGN , size); - -if (!ptr) -return log_msg_ret ("alloc" , -ENOMEM ); - addr =map_to_sysmem (ptr); - }else if (!fixed) { -return log_msg_ret ("BLOBLIST_FIXED is not enabled" , - ret); - } -log_debug ("Creating new bloblist size %lx at %lx\n" , size, - addr); - ret =bloblist_new (addr, size,0 ,0 ); - }else { -log_debug ("Found existing bloblist size %lx at %lx\n" , size, - addr); - } +/* +* We have checked for a valid transfer list being passed. At this +* point, if we do not have a fixed address for the bloblist, we cannot +* be provided with one. +*/ +if (xpl_is_first_phase () || !IS_ENABLED (CONFIG_BLOBLIST_FIXED )) +return false; -if (ret) -return log_msg_ret ("ini" , ret); - gd->flags |=GD_FLG_BLOBLIST_READY ; +/* +* Check for a valid list as the configured address. +*/ + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + ret =bloblist_check (addr,CONFIG_BLOBLIST_SIZE ); +if (!ret) + goto found; + +log_debug ("Bloblist at %lx not found (err=%d)\n" , addr, ret); +return false; +found: #ifdef DEBUGbloblist_show_stats ();bloblist_show_list ();#endif - -return 0 ; +return true; } -int bloblist_maybe_init (void ) +int bloblist_init (void ) { -if (CONFIG_IS_ENABLED (BLOBLIST ) && !(gd->flags &GD_FLG_BLOBLIST_READY )) -return bloblist_init (); +int ret; +ulong addr =0 , size =CONFIG_BLOBLIST_SIZE ; + +if (gd->flags &GD_FLG_BLOBLIST_READY ) { +log_debug ("Found existing bloblist size %x at %p\n" , + gd->bloblist->total_size, gd->bloblist); +return 0 ; + } + +/* +* If Firmware Handoff is mandatory but no transfer list has been +* observed by fdtdec_setup, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return -ENOENT ; + +/* +* If we don't have an existing bloblist, we either need +* to allocate one now, or initialize the fixed address +* space as a bloblist. +*/ +if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { +void *ptr =memalign (BLOBLIST_ALIGN , size); + +if (!ptr) +return log_msg_ret ("alloc" , -ENOMEM ); + addr =map_to_sysmem (ptr); + }else + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + +log_debug ("Creating new bloblist size %lx at %lx\n" , size, + addr); + ret =bloblist_new (addr, size,0 ,0 ); +if (ret) +return log_msg_ret ("ini" , ret);return 0 ; }@@ -687,7 +687,9 @@ int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig, ulong xlist)return ret;if (rfdt != (ulong )bloblist_find (BLOBLISTT_CONTROL_FDT ,0 )) { - gd->bloblist =NULL ;/* Reset the gd bloblist pointer */ +/* Remove this bloblist from gd */ + gd->bloblist =NULL ; + gd->flags &= ~GD_FLG_BLOBLIST_READY ;return -EIO ; }common/board_f.c +3
-1@@ -894,7 +894,9 @@ static void initcall_run_f(void)INITCALL (log_init);INITCALL (initf_bootstage);/* uses its own timer, so does not need DM */ INITCALL (event_init); -INITCALL (bloblist_maybe_init); +#if CONFIG_IS_ENABLED (BLOBLIST ) +INITCALL (bloblist_init); +#endif INITCALL (setup_spl_handoff);#if CONFIG_IS_ENABLED (CONSOLE_RECORD_INIT_F )INITCALL (console_record_init);include/bloblist.h +15
-17@@ -488,10 +488,24 @@ const char *bloblist_tag_name(enum bloblist_tag_t tag);*/ int bloblist_reloc (void *to,uint to_size); +/** +* bloblist_exists() - Check for the prior existence of a bloblist +* +* This will check for a transfer list having been passed via standard +* convention. If CONFIG_BLOBLIST_PASSAGE_MANDATORY is selected and one is not +* found, we return false. +* +* If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and +* CONFIG_BLOBLIST_SIZE to check for a bloblist. +* +* Return: true if found, false if not +*/ +bool bloblist_exists (void ); +/** * bloblist_init() - Init the bloblist system with a single bloblist * -* This locates and sets up the blocklist for use. +* This creates a bloblist for use, if not already found. * * If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and * CONFIG_BLOBLIST_SIZE to set up a bloblist for use by U-Boot. @@ -508,22 +522,6 @@ int bloblist_reloc(void *to, uint to_size);*/ int bloblist_init (void ); -#if CONFIG_IS_ENABLED (BLOBLIST ) -/** -* bloblist_maybe_init() - Init the bloblist system if not already done -* -* Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not set -* -* Return: 0 if OK, -ve on error -*/ -int bloblist_maybe_init (void ); -#else -static inline int bloblist_maybe_init (void ) -{ -return 0 ; -} -#endif /* BLOBLIST */ -/** * bloblist_check_reg_conv() - Check whether the bloblist is compliant to * the register conventions according to the lib/fdtdec.c +0
-5@@ -1822,17 +1822,12 @@ int fdtdec_setup(void)int ret = -ENOENT ;/* -* If allowing a bloblist, check that first. There was discussion about -* adding an OF_BLOBLIST Kconfig, but this was rejected. -* -* The necessary test is whether the previous phase passed a bloblist, -* not whether this phase creates one. lib/fdtdec.c int fdtdec_setup(void) · line 1829
Quoted 10 lines
lib/fdtdec.c +4
-5+* If allowing a bloblist, check that first. The necessary test is +* whether the previous phase passed a bloblist, not whether this phase +* creates one. */ -if (CONFIG_IS_ENABLED (BLOBLIST ) && - (xpl_prev_phase () !=PHASE_TPL || -IS_ENABLED (CONFIG_TPL_BLOBLIST ))) { - ret =bloblist_maybe_init (); -if (!ret) { +if (CONFIG_IS_ENABLED (BLOBLIST ) && (xpl_prev_phase () !=PHASE_TPL )) {Quoted 7 lines
I think this change drops the TPL-provided blobs on
TPL->SPLboots. WhenTPL_BLOBLISTis selected, the next phase starts withxpl_prev_phase()==PHASE_TPL.
This new guard now skipsbloblist_exists(), sogd->flagsnever getsGD_FLG_BLOBLIST_READY; the laterbloblist_init()incommon/spl/spl.cthen creates a fresh bloblist and overwrites the fixed-address list from TPL.Quoted 4 lines
Ah right, oops. I guess the only question is if we should continue to optimize the TPL case (it can't exist) or just always check (maybe there's some 4 stage boot..).
Quoted 4 lines
That really depends on whether we shall consider the scenario of TPL. For the case of the Arm Firmware Handoff, stages before BL2 are not considered to hand information over to the next stage via Transfer List (aka. bloblist in U-Boot).
OK, I think we can just go with SPL or higher looks for a bloblist, TPL can create one but not be passed one. It's simple enough to change if there's somehow a 4 stage boot we need to worry about later.
Signature · 1 line
Tom
v2 cover Clean up bloblist initialization
In reply to Tom RinihEY ALL,
I've been sitting on this series for a bit (as the patch dates imply), and I'm ready to move forward now with it.
This series does a few small but important cleanups to how we check for, and initialize a bloblist. The first thing is that the way things are done today, our HANDOFF code can only work with a fixed bloblist location, so express that requirement in Kconfig. Next, we demote the scary message about "Bloblist at ... not found" to a debug because we most often see that because the bloblist doesn't (and can't) exist yet. Finally, we remove bloblist_maybe_init and split this in to an exists and a real init. This results in practically no growth (between 8 bytes growth to 12 bytes saved, with some outliers saving much more thanks to knowing it's impossible to have been passed a bloblist yet). This also cleans up some of the code around checking for / knowing about a bloblist existing.
Changes in v2:
- Pick up Raymond's tags on patches 1 and 2
- Correct the logic in the final patch to not break TPL passes SPL a bloblist (at a fixed location), as noticed by Raymond
Signature · 1 line
Tom
PATCH v2 1/3 bloblist / handoff: Make this depend on BLOBLIST_FIXED
Currently, the only way we support passing a bloblist from one stage to the next is via the BLOBLIST_FIXED mechanism. Update the Kconfig logic to express this constraint.
--- common/spl/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/Kconfig +1 -1
@@ -220,7 +220,7 @@ source "common/spl/Kconfig.nxp" config HANDOFF bool "Pass hand-off information from SPL to U-Boot proper" - depends on BLOBLIST + depends on BLOBLIST_FIXED help It is useful to be able to pass information from SPL to U-Boot proper to preserve state that is known in SPL and is needed in U-Boot.
Signature · 1 line
2.43.0
PATCH v2 2/3 bloblist: Demote not finding a bloblist to a debug
In reply to Tom RiniThe message about not finding a bloblist will quite often be seen at least once, and is non-fatal. Demote this to a log_debug message from a log_warning message.
--- common/bloblist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common/bloblist.c +2 -2
@@ -613,8 +613,8 @@ int bloblist_init(void) ret =bloblist_check (addr, size);if (ret) -log_warning ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); +log_debug ("Bloblist at %lx not found (err=%d)\n" , + addr, ret);else /* Get the real size */ size = gd->bloblist->total_size;
Signature · 1 line
2.43.0
PATCH v2 3/3 bloblist: Rework bloblist_init and bloblist_maybe_init
In reply to Tom RiniWith bloblist, we need to both see if one already exists as well as create one if it does not. However, the current implementation leads to odd cases where we attempt to create a bloblist before this is possible and have things be overly complicated when we are given one to work with.
This reworks things to instead have a bloblist_exists function, which as the name implies checks for an existing bloblist. This is used in the case of booting, to see if we have one and in turn if we have a device tree there as well as in the bloblist_init function to see if we need to do anything.
In practical details, we move the logic from bloblist_init that was checking for a bloblist to the new bloblist_exists function and then can clarify the logic as it is much easier to state when we know we do not have one rather than all the ways we might have one. Then we have the locations that set gd->bloblist now also set the GD_FLG_BLOBLIST_READY flag.
---
Changes in v2:
- As noted by Raymond, we need to still check if SPL is being passed a bloblist by TPL.
--- common/bloblist.c | 144 +++++++++++++++++++++++---------------------- common/board_f.c | 4 +- include/bloblist.h | 32 +++++----- lib/fdtdec.c | 15 ++--- 4 files changed, 96 insertions(+), 99 deletions(-)
common/bloblist.c +73 -71
@@ -448,6 +448,7 @@ int bloblist_new(ulong addr, uint size, uint flags, uint align_log2) hdr->align_log2 = align_log2 ? align_log2 :BLOBLIST_BLOB_ALIGN_LOG2 ; hdr->chksum =0 ; gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }
@@ -475,6 +476,7 @@ int bloblist_check(ulong addr, uint size)return log_msg_ret ("Bad checksum" , -EIO ); } gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }
@@ -576,90 +578,88 @@ int __weak xferlist_from_boot_arg(ulong __always_unused *addr)return -ENOENT ; } -int bloblist_init (void ) +bool bloblist_exists (void ) { -bool fixed =IS_ENABLED (CONFIG_BLOBLIST_FIXED ); -int ret =0 ; -ulong addr =0 , size; +int ret; +ulong addr =0 ;/* Check if a valid transfer list passed in */ -if (!xferlist_from_boot_arg (&addr)) { - size =bloblist_get_total_size (); - }else { -/* -* If U-Boot is not in the first phase, an existing bloblist must -* be at a fixed address. -*/ -bool from_addr = fixed && !xpl_is_first_phase (); - -/* -* If Firmware Handoff is mandatory but no transfer list is -* observed, report it as an error. -*/ -if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) -return -ENOENT ; - - ret = -ENOENT ; - -if (xpl_prev_phase () ==PHASE_TPL && - !IS_ENABLED (CONFIG_TPL_BLOBLIST )) - from_addr = false; -if (fixed) - addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , -CONFIG_BLOBLIST_ADDR ); - size =CONFIG_BLOBLIST_SIZE ; - -if (from_addr) - ret =bloblist_check (addr, size); +if (!xferlist_from_boot_arg (&addr)) + goto found; -if (ret) -log_debug ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); -else -/* Get the real size */ - size = gd->bloblist->total_size; - } +/* +* If Firmware Handoff is mandatory but no transfer list is +* observed, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return false; -if (ret) { -/* -* If we don't have a bloblist from a fixed address, or the one -* in the fixed address is not valid. we must allocate the -* memory for it now. -*/ -if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { -void *ptr =memalign (BLOBLIST_ALIGN , size); - -if (!ptr) -return log_msg_ret ("alloc" , -ENOMEM ); - addr =map_to_sysmem (ptr); - }else if (!fixed) { -return log_msg_ret ("BLOBLIST_FIXED is not enabled" , - ret); - } -log_debug ("Creating new bloblist size %lx at %lx\n" , size, - addr); - ret =bloblist_new (addr, size,0 ,0 ); - }else { -log_debug ("Found existing bloblist size %lx at %lx\n" , size, - addr); - } +/* +* We have checked for a valid transfer list being passed. At this +* point, if we do not have a fixed address for the bloblist, we cannot +* be provided with one. +*/ +if (xpl_is_first_phase () || !IS_ENABLED (CONFIG_BLOBLIST_FIXED )) +return false; -if (ret) -return log_msg_ret ("ini" , ret); - gd->flags |=GD_FLG_BLOBLIST_READY ; +/* +* Check for a valid list as the configured address. +*/ + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + ret =bloblist_check (addr,CONFIG_BLOBLIST_SIZE ); +if (!ret) + goto found; + +log_debug ("Bloblist at %lx not found (err=%d)\n" , addr, ret); +return false; +found: #ifdef DEBUGbloblist_show_stats ();bloblist_show_list ();#endif - -return 0 ; +return true; } -int bloblist_maybe_init (void ) +int bloblist_init (void ) { -if (CONFIG_IS_ENABLED (BLOBLIST ) && !(gd->flags &GD_FLG_BLOBLIST_READY )) -return bloblist_init (); +int ret; +ulong addr =0 , size =CONFIG_BLOBLIST_SIZE ; + +if (gd->flags &GD_FLG_BLOBLIST_READY ) { +log_debug ("Found existing bloblist size %x at %p\n" , + gd->bloblist->total_size, gd->bloblist); +return 0 ; + } + +/* +* If Firmware Handoff is mandatory but no transfer list has been +* observed by fdtdec_setup, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return -ENOENT ; + +/* +* If we don't have an existing bloblist, we either need +* to allocate one now, or initialize the fixed address +* space as a bloblist. +*/ +if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { +void *ptr =memalign (BLOBLIST_ALIGN , size); + +if (!ptr) +return log_msg_ret ("alloc" , -ENOMEM ); + addr =map_to_sysmem (ptr); + }else + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + +log_debug ("Creating new bloblist size %lx at %lx\n" , size, + addr); + ret =bloblist_new (addr, size,0 ,0 ); +if (ret) +return log_msg_ret ("ini" , ret);return 0 ; }
@@ -687,7 +687,9 @@ int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig, ulong xlist)return ret;if (rfdt != (ulong )bloblist_find (BLOBLISTT_CONTROL_FDT ,0 )) { - gd->bloblist =NULL ;/* Reset the gd bloblist pointer */ +/* Remove this bloblist from gd */ + gd->bloblist =NULL ; + gd->flags &= ~GD_FLG_BLOBLIST_READY ;return -EIO ; }
common/board_f.c +3 -1
@@ -894,7 +894,9 @@ static void initcall_run_f(void)INITCALL (log_init);INITCALL (initf_bootstage);/* uses its own timer, so does not need DM */ INITCALL (event_init); -INITCALL (bloblist_maybe_init); +#if CONFIG_IS_ENABLED (BLOBLIST ) +INITCALL (bloblist_init); +#endif INITCALL (setup_spl_handoff);#if CONFIG_IS_ENABLED (CONSOLE_RECORD_INIT_F )INITCALL (console_record_init);
include/bloblist.h +15 -17
@@ -488,10 +488,24 @@ const char *bloblist_tag_name(enum bloblist_tag_t tag);*/ int bloblist_reloc (void *to,uint to_size); +/** +* bloblist_exists() - Check for the prior existence of a bloblist +* +* This will check for a transfer list having been passed via standard +* convention. If CONFIG_BLOBLIST_PASSAGE_MANDATORY is selected and one is not +* found, we return false. +* +* If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and +* CONFIG_BLOBLIST_SIZE to check for a bloblist. +* +* Return: true if found, false if not +*/ +bool bloblist_exists (void ); +/** * bloblist_init() - Init the bloblist system with a single bloblist * -* This locates and sets up the blocklist for use. +* This creates a bloblist for use, if not already found. * * If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and * CONFIG_BLOBLIST_SIZE to set up a bloblist for use by U-Boot.
@@ -508,22 +522,6 @@ int bloblist_reloc(void *to, uint to_size);*/ int bloblist_init (void ); -#if CONFIG_IS_ENABLED (BLOBLIST ) -/** -* bloblist_maybe_init() - Init the bloblist system if not already done -* -* Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not set -* -* Return: 0 if OK, -ve on error -*/ -int bloblist_maybe_init (void ); -#else -static inline int bloblist_maybe_init (void ) -{ -return 0 ; -} -#endif /* BLOBLIST */ -/** * bloblist_check_reg_conv() - Check whether the bloblist is compliant to * the register conventions according to the
lib/fdtdec.c +5 -10
@@ -1822,17 +1822,12 @@ int fdtdec_setup(void)int ret = -ENOENT ;/* -* If allowing a bloblist, check that first. There was discussion about -* adding an OF_BLOBLIST Kconfig, but this was rejected. -* -* The necessary test is whether the previous phase passed a bloblist, -* not whether this phase creates one. +* If allowing a bloblist, check that first. The necessary test is +* whether the previous phase passed a bloblist, not whether this phase +* creates one. */ -if (CONFIG_IS_ENABLED (BLOBLIST ) && - (xpl_prev_phase () !=PHASE_TPL || -IS_ENABLED (CONFIG_TPL_BLOBLIST ))) { - ret =bloblist_maybe_init (); -if (!ret) { +if (CONFIG_IS_ENABLED (BLOBLIST ) && (xpl_phase () >PHASE_TPL )) { +if (bloblist_exists ()) { gd->fdt_blob =bloblist_find (BLOBLISTT_CONTROL_FDT ,0 );if (gd->fdt_blob) { gd->fdt_src =FDTSRC_BLOBLIST ;
Signature · 1 line
2.43.0
Re: [PATCH v2 3/3] bloblist: Rework bloblist_init and bloblist_maybe_init
Hi Tom,
Quoted 171 lines · Tom Rini
With bloblist, we need to both see if one already exists as well as create one if it does not. However, the current implementation leads to odd cases where we attempt to create a bloblist before this is possible and have things be overly complicated when we are given one to work with.
This reworks things to instead have a
bloblist_existsfunction, which as the name implies checks for an existing bloblist. This is used in the case of booting, to see if we have one and in turn if we have a device tree there as well as in thebloblist_initfunction to see if we need to do anything.In practical details, we move the logic from
bloblist_initthat was checking for a bloblist to the newbloblist_existsfunction and then can clarify the logic as it is much easier to state when we know we do not have one rather than all the ways we might have one. Then we have the locations that setgd->bloblistnow also set theGD_FLG_BLOBLIST_READYflag.Signed-off-by Tom Rini <[email protected]>---
Changes in v2:
- As noted by Raymond, we need to still check if SPL is being passed a bloblist by TPL.--- common/bloblist.c | 144 +++++++++++++++++++++++---------------------- common/board_f.c | 4 +- include/bloblist.h | 32 +++++----- lib/fdtdec.c | 15 ++--- 4 files changed, 96 insertions(+), 99 deletions(-)common/bloblist.c +34
-69@@ -448,6 +448,7 @@ int bloblist_new(ulong addr, uint size, uint flags, uint align_log2) hdr->align_log2 = align_log2 ? align_log2 :BLOBLIST_BLOB_ALIGN_LOG2 ; hdr->chksum =0 ; gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -475,6 +476,7 @@ int bloblist_check(ulong addr, uint size)return log_msg_ret ("Bad checksum" , -EIO ); } gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -576,90 +578,88 @@ int __weak xferlist_from_boot_arg(ulong __always_unused *addr)return -ENOENT ; } -int bloblist_init (void ) +bool bloblist_exists (void ) { -bool fixed =IS_ENABLED (CONFIG_BLOBLIST_FIXED ); -int ret =0 ; -ulong addr =0 , size; +int ret; +ulong addr =0 ;/* Check if a valid transfer list passed in */ -if (!xferlist_from_boot_arg (&addr)) { - size =bloblist_get_total_size (); - }else { -/* -* If U-Boot is not in the first phase, an existing bloblist must -* be at a fixed address. -*/ -bool from_addr = fixed && !xpl_is_first_phase (); - -/* -* If Firmware Handoff is mandatory but no transfer list is -* observed, report it as an error. -*/ -if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) -return -ENOENT ; - - ret = -ENOENT ; - -if (xpl_prev_phase () ==PHASE_TPL && - !IS_ENABLED (CONFIG_TPL_BLOBLIST )) - from_addr = false; -if (fixed) - addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , -CONFIG_BLOBLIST_ADDR ); - size =CONFIG_BLOBLIST_SIZE ; - -if (from_addr) - ret =bloblist_check (addr, size); +if (!xferlist_from_boot_arg (&addr)) + goto found; -if (ret) -log_debug ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); -else -/* Get the real size */ - size = gd->bloblist->total_size; - } +/* +* If Firmware Handoff is mandatory but no transfer list is +* observed, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return false; -if (ret) { -/* -* If we don't have a bloblist from a fixed address, or the one -* in the fixed address is not valid. we must allocate the -* memory for it now. -*/ -if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { -void *ptr =memalign (BLOBLIST_ALIGN , size); - -if (!ptr) -return log_msg_ret ("alloc" , -ENOMEM ); - addr =map_to_sysmem (ptr); - }else if (!fixed) { -return log_msg_ret ("BLOBLIST_FIXED is not enabled" , - ret); - } -log_debug ("Creating new bloblist size %lx at %lx\n" , size, - addr); - ret =bloblist_new (addr, size,0 ,0 ); - }else { -log_debug ("Found existing bloblist size %lx at %lx\n" , size, - addr); - } +/* +* We have checked for a valid transfer list being passed. At this +* point, if we do not have a fixed address for the bloblist, we cannot +* be provided with one. +*/ +if (xpl_is_first_phase () || !IS_ENABLED (CONFIG_BLOBLIST_FIXED )) +return false; -if (ret) -return log_msg_ret ("ini" , ret); - gd->flags |=GD_FLG_BLOBLIST_READY ; +/* +* Check for a valid list as the configured address. +*/ + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + ret =bloblist_check (addr,CONFIG_BLOBLIST_SIZE ); +if (!ret) + goto found; + +log_debug ("Bloblist at %lx not found (err=%d)\n" , addr, ret); +return false; +found: #ifdef DEBUGbloblist_show_stats ();bloblist_show_list ();#endif - -return 0 ; +return true; } -int bloblist_maybe_init (void ) +int bloblist_init (void ) { -if (CONFIG_IS_ENABLED (BLOBLIST ) && !(gd->flags &GD_FLG_BLOBLIST_READY ))
common/bloblist.c int __weak xferlist_from_boot_arg(ulong __always_unused *addr) · line 635
Quoted 10 lines
common/bloblist.c +9
-1-return bloblist_init (); +int ret; +ulong addr =0 , size =CONFIG_BLOBLIST_SIZE ; + +if (gd->flags &GD_FLG_BLOBLIST_READY ) { +log_debug ("Found existing bloblist size %x at %p\n" , + gd->bloblist->total_size, gd->bloblist); +return 0 ; + } +
This part is a bit difficult to read.
The patch seems to try to assume that '!(gd->flags & GD_FLG_BLOBLIST_READY)' means 'no handoff from the previous stage', but I doubt this is a part of GD_FLG_BLOBLIST_READY's semantics. Under the 'handoff from the previous stage' scenario, if GD_FLG_BLOBLIST_READY is not set in time, the logic here breaks.
Regards,
Raymond
Quoted 139 lines
common/bloblist.c +30
-1+/* +* If Firmware Handoff is mandatory but no transfer list has been +* observed by fdtdec_setup, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return -ENOENT ; + +/* +* If we don't have an existing bloblist, we either need +* to allocate one now, or initialize the fixed address +* space as a bloblist. +*/ +if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { +void *ptr =memalign (BLOBLIST_ALIGN , size); + +if (!ptr) +return log_msg_ret ("alloc" , -ENOMEM ); + addr =map_to_sysmem (ptr); + }else + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + +log_debug ("Creating new bloblist size %lx at %lx\n" , size, + addr); + ret =bloblist_new (addr, size,0 ,0 ); +if (ret) +return log_msg_ret ("ini" , ret);return 0 ; }@@ -687,7 +687,9 @@ int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig, ulong xlist)return ret;if (rfdt != (ulong )bloblist_find (BLOBLISTT_CONTROL_FDT ,0 )) { - gd->bloblist =NULL ;/* Reset the gd bloblist pointer */ +/* Remove this bloblist from gd */ + gd->bloblist =NULL ; + gd->flags &= ~GD_FLG_BLOBLIST_READY ;return -EIO ; }common/board_f.c +3
-1@@ -894,7 +894,9 @@ static void initcall_run_f(void)INITCALL (log_init);INITCALL (initf_bootstage);/* uses its own timer, so does not need DM */ INITCALL (event_init); -INITCALL (bloblist_maybe_init); +#if CONFIG_IS_ENABLED (BLOBLIST ) +INITCALL (bloblist_init); +#endif INITCALL (setup_spl_handoff);#if CONFIG_IS_ENABLED (CONSOLE_RECORD_INIT_F )INITCALL (console_record_init);include/bloblist.h +15
-17@@ -488,10 +488,24 @@ const char *bloblist_tag_name(enum bloblist_tag_t tag);*/ int bloblist_reloc (void *to,uint to_size); +/** +* bloblist_exists() - Check for the prior existence of a bloblist +* +* This will check for a transfer list having been passed via standard +* convention. If CONFIG_BLOBLIST_PASSAGE_MANDATORY is selected and one is not +* found, we return false. +* +* If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and +* CONFIG_BLOBLIST_SIZE to check for a bloblist. +* +* Return: true if found, false if not +*/ +bool bloblist_exists (void ); +/** * bloblist_init() - Init the bloblist system with a single bloblist * -* This locates and sets up the blocklist for use. +* This creates a bloblist for use, if not already found. * * If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and * CONFIG_BLOBLIST_SIZE to set up a bloblist for use by U-Boot. @@ -508,22 +522,6 @@ int bloblist_reloc(void *to, uint to_size);*/ int bloblist_init (void ); -#if CONFIG_IS_ENABLED (BLOBLIST ) -/** -* bloblist_maybe_init() - Init the bloblist system if not already done -* -* Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not set -* -* Return: 0 if OK, -ve on error -*/ -int bloblist_maybe_init (void ); -#else -static inline int bloblist_maybe_init (void ) -{ -return 0 ; -} -#endif /* BLOBLIST */ -/** * bloblist_check_reg_conv() - Check whether the bloblist is compliant to * the register conventions according to the lib/fdtdec.c +5
-11@@ -1822,17 +1822,12 @@ int fdtdec_setup(void)int ret = -ENOENT ;/* -* If allowing a bloblist, check that first. There was discussion about -* adding an OF_BLOBLIST Kconfig, but this was rejected. -* -* The necessary test is whether the previous phase passed a bloblist, -* not whether this phase creates one. +* If allowing a bloblist, check that first. The necessary test is +* whether the previous phase passed a bloblist, not whether this phase +* creates one. */ -if (CONFIG_IS_ENABLED (BLOBLIST ) && - (xpl_prev_phase () !=PHASE_TPL || -IS_ENABLED (CONFIG_TPL_BLOBLIST ))) { - ret =bloblist_maybe_init (); -if (!ret) { +if (CONFIG_IS_ENABLED (BLOBLIST ) && (xpl_phase () >PHASE_TPL )) { +if (bloblist_exists ()) { gd->fdt_blob =bloblist_find (BLOBLISTT_CONTROL_FDT ,0 );if (gd->fdt_blob) { gd->fdt_src =FDTSRC_BLOBLIST ; --2.43.0
Re: [PATCH v2 3/3] bloblist: Rework bloblist_init and bloblist_maybe_init
Quoted 180 lines · Raymond Mao
Hi Tom,
Quoted 177 lines · Tom Rini
With bloblist, we need to both see if one already exists as well as create one if it does not. However, the current implementation leads to odd cases where we attempt to create a bloblist before this is possible and have things be overly complicated when we are given one to work with.
This reworks things to instead have a
bloblist_existsfunction, which as the name implies checks for an existing bloblist. This is used in the case of booting, to see if we have one and in turn if we have a device tree there as well as in thebloblist_initfunction to see if we need to do anything.In practical details, we move the logic from
bloblist_initthat was checking for a bloblist to the newbloblist_existsfunction and then can clarify the logic as it is much easier to state when we know we do not have one rather than all the ways we might have one. Then we have the locations that setgd->bloblistnow also set theGD_FLG_BLOBLIST_READYflag.Signed-off-by Tom Rini <[email protected]>---
Changes in v2:
- As noted by Raymond, we need to still check if SPL is being passed a bloblist by TPL.--- common/bloblist.c | 144 +++++++++++++++++++++++---------------------- common/board_f.c | 4 +- include/bloblist.h | 32 +++++----- lib/fdtdec.c | 15 ++--- 4 files changed, 96 insertions(+), 99 deletions(-)common/bloblist.c +39
-70@@ -448,6 +448,7 @@ int bloblist_new(ulong addr, uint size, uint flags, uint align_log2) hdr->align_log2 = align_log2 ? align_log2 :BLOBLIST_BLOB_ALIGN_LOG2 ; hdr->chksum =0 ; gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -475,6 +476,7 @@ int bloblist_check(ulong addr, uint size)return log_msg_ret ("Bad checksum" , -EIO ); } gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -576,90 +578,88 @@ int __weak xferlist_from_boot_arg(ulong __always_unused *addr)return -ENOENT ; } -int bloblist_init (void ) +bool bloblist_exists (void ) { -bool fixed =IS_ENABLED (CONFIG_BLOBLIST_FIXED ); -int ret =0 ; -ulong addr =0 , size; +int ret; +ulong addr =0 ;/* Check if a valid transfer list passed in */ -if (!xferlist_from_boot_arg (&addr)) { - size =bloblist_get_total_size (); - }else { -/* -* If U-Boot is not in the first phase, an existing bloblist must -* be at a fixed address. -*/ -bool from_addr = fixed && !xpl_is_first_phase (); - -/* -* If Firmware Handoff is mandatory but no transfer list is -* observed, report it as an error. -*/ -if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) -return -ENOENT ; - - ret = -ENOENT ; - -if (xpl_prev_phase () ==PHASE_TPL && - !IS_ENABLED (CONFIG_TPL_BLOBLIST )) - from_addr = false; -if (fixed) - addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , -CONFIG_BLOBLIST_ADDR ); - size =CONFIG_BLOBLIST_SIZE ; - -if (from_addr) - ret =bloblist_check (addr, size); +if (!xferlist_from_boot_arg (&addr)) + goto found; -if (ret) -log_debug ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); -else -/* Get the real size */ - size = gd->bloblist->total_size; - } +/* +* If Firmware Handoff is mandatory but no transfer list is +* observed, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return false; -if (ret) { -/* -* If we don't have a bloblist from a fixed address, or the one -* in the fixed address is not valid. we must allocate the -* memory for it now. -*/ -if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { -void *ptr =memalign (BLOBLIST_ALIGN , size); - -if (!ptr) -return log_msg_ret ("alloc" , -ENOMEM ); - addr =map_to_sysmem (ptr); - }else if (!fixed) { -return log_msg_ret ("BLOBLIST_FIXED is not enabled" , - ret); - } -log_debug ("Creating new bloblist size %lx at %lx\n" , size, - addr); - ret =bloblist_new (addr, size,0 ,0 ); - }else { -log_debug ("Found existing bloblist size %lx at %lx\n" , size, - addr); - } +/* +* We have checked for a valid transfer list being passed. At this +* point, if we do not have a fixed address for the bloblist, we cannot +* be provided with one. +*/ +if (xpl_is_first_phase () || !IS_ENABLED (CONFIG_BLOBLIST_FIXED )) +return false; -if (ret) -return log_msg_ret ("ini" , ret); - gd->flags |=GD_FLG_BLOBLIST_READY ; +/* +* Check for a valid list as the configured address. +*/ + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + ret =bloblist_check (addr,CONFIG_BLOBLIST_SIZE ); +if (!ret) + goto found; + +log_debug ("Bloblist at %lx not found (err=%d)\n" , addr, ret); +return false; +found: #ifdef DEBUGbloblist_show_stats ();bloblist_show_list ();#endif - -return 0 ; +return true; } -int bloblist_maybe_init (void ) +int bloblist_init (void ) { -if (CONFIG_IS_ENABLED (BLOBLIST ) && !(gd->flags &GD_FLG_BLOBLIST_READY )) -return bloblist_init (); +int ret; +ulong addr =0 , size =CONFIG_BLOBLIST_SIZE ; + +if (gd->flags &GD_FLG_BLOBLIST_READY ) { + log_debug("Found existing bloblist size %x at %p\n",
Quoted 8 lines
common/bloblist.c int __weak xferlist_from_boot_arg(ulong __always_unused *addr) · line 635
Quoted 4 lines
common/bloblist.c +4
-0+ gd->bloblist->total_size, gd->bloblist); +return 0 ; + } +This part is a bit difficult to read.
The patch seems to try to assume that '!(gd->flags &GD_FLG_BLOBLIST_READY)' means 'no handoff from the previous stage',
Correct.
Quoted 1 line
but I doubt this is a part of GD_FLG_BLOBLIST_READY's semantics.
It is part of the semantics now, however with this patch. That said, I don't love the name GD_FLG_BLOBLIST_READY but that name was a side effect of the old behavior too and needing to bail out from "maybe_init".
Quoted 2 lines
Under the 'handoff from the previous stage' scenario, if
GD_FLG_BLOBLIST_READYis not set in time, the logic here breaks.
Now that "exists" is not part of "init", we should have already called bloblist_check and set the flag before we can get here.
Signature · 1 line
Tom
Raymond Mao
Reviewed-byRe: [PATCH v2 3/3] bloblist: Rework bloblist_init and bloblist_maybe_init
Hi Tom,
Quoted 200 lines · Tom Rini
Quoted 180 lines · Raymond Mao
Hi Tom,
Quoted 177 lines · Tom Rini
With bloblist, we need to both see if one already exists as well as create one if it does not. However, the current implementation leads to odd cases where we attempt to create a bloblist before this is possible and have things be overly complicated when we are given one to work with.
This reworks things to instead have a
bloblist_existsfunction, which as the name implies checks for an existing bloblist. This is used in the case of booting, to see if we have one and in turn if we have a device tree there as well as in thebloblist_initfunction to see if we need to do anything.In practical details, we move the logic from
bloblist_initthat was checking for a bloblist to the newbloblist_existsfunction and then can clarify the logic as it is much easier to state when we know we do not have one rather than all the ways we might have one. Then we have the locations that setgd->bloblistnow also set theGD_FLG_BLOBLIST_READYflag.Signed-off-by Tom Rini <[email protected]>---
Changes in v2:
- As noted by Raymond, we need to still check if SPL is being passed a bloblist by TPL.--- common/bloblist.c | 144 +++++++++++++++++++++++---------------------- common/board_f.c | 4 +- include/bloblist.h | 32 +++++----- lib/fdtdec.c | 15 ++--- 4 files changed, 96 insertions(+), 99 deletions(-)common/bloblist.c +39
-70@@ -448,6 +448,7 @@ int bloblist_new(ulong addr, uint size, uint flags, uint align_log2) hdr->align_log2 = align_log2 ? align_log2 :BLOBLIST_BLOB_ALIGN_LOG2 ; hdr->chksum =0 ; gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -475,6 +476,7 @@ int bloblist_check(ulong addr, uint size)return log_msg_ret ("Bad checksum" , -EIO ); } gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -576,90 +578,88 @@ int __weak xferlist_from_boot_arg(ulong __always_unused *addr)return -ENOENT ; } -int bloblist_init (void ) +bool bloblist_exists (void ) { -bool fixed =IS_ENABLED (CONFIG_BLOBLIST_FIXED ); -int ret =0 ; -ulong addr =0 , size; +int ret; +ulong addr =0 ;/* Check if a valid transfer list passed in */ -if (!xferlist_from_boot_arg (&addr)) { - size =bloblist_get_total_size (); - }else { -/* -* If U-Boot is not in the first phase, an existing bloblist must -* be at a fixed address. -*/ -bool from_addr = fixed && !xpl_is_first_phase (); - -/* -* If Firmware Handoff is mandatory but no transfer list is -* observed, report it as an error. -*/ -if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) -return -ENOENT ; - - ret = -ENOENT ; - -if (xpl_prev_phase () ==PHASE_TPL && - !IS_ENABLED (CONFIG_TPL_BLOBLIST )) - from_addr = false; -if (fixed) - addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , -CONFIG_BLOBLIST_ADDR ); - size =CONFIG_BLOBLIST_SIZE ; - -if (from_addr) - ret =bloblist_check (addr, size); +if (!xferlist_from_boot_arg (&addr)) + goto found; -if (ret) -log_debug ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); -else -/* Get the real size */ - size = gd->bloblist->total_size; - } +/* +* If Firmware Handoff is mandatory but no transfer list is +* observed, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return false; -if (ret) { -/* -* If we don't have a bloblist from a fixed address, or the one -* in the fixed address is not valid. we must allocate the -* memory for it now. -*/ -if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { -void *ptr =memalign (BLOBLIST_ALIGN , size); - -if (!ptr) -return log_msg_ret ("alloc" , -ENOMEM ); - addr =map_to_sysmem (ptr); - }else if (!fixed) { -return log_msg_ret ("BLOBLIST_FIXED is not enabled" , - ret); - } -log_debug ("Creating new bloblist size %lx at %lx\n" , size, - addr); - ret =bloblist_new (addr, size,0 ,0 ); - }else { -log_debug ("Found existing bloblist size %lx at %lx\n" , size, - addr); - } +/* +* We have checked for a valid transfer list being passed. At this +* point, if we do not have a fixed address for the bloblist, we cannot +* be provided with one. +*/ +if (xpl_is_first_phase () || !IS_ENABLED (CONFIG_BLOBLIST_FIXED )) +return false; -if (ret) -return log_msg_ret ("ini" , ret); - gd->flags |=GD_FLG_BLOBLIST_READY ; +/* +* Check for a valid list as the configured address. +*/ + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + ret =bloblist_check (addr,CONFIG_BLOBLIST_SIZE ); +if (!ret) + goto found; + +log_debug ("Bloblist at %lx not found (err=%d)\n" , addr, ret); +return false; +found: #ifdef DEBUGbloblist_show_stats ();bloblist_show_list ();#endif - -return 0 ; +return true; } -int bloblist_maybe_init (void ) +int bloblist_init (void ) { -if (CONFIG_IS_ENABLED (BLOBLIST ) && !(gd->flags &GD_FLG_BLOBLIST_READY )) -return bloblist_init (); +int ret; +ulong addr =0 , size =CONFIG_BLOBLIST_SIZE ; + +if (gd->flags &GD_FLG_BLOBLIST_READY ) { + log_debug("Found existing bloblist size %x at %p\n",Quoted 8 lines
common/bloblist.c int __weak xferlist_from_boot_arg(ulong __always_unused *addr) · line 635
Quoted 4 lines
common/bloblist.c +4
-0+ gd->bloblist->total_size, gd->bloblist); +return 0 ; + } +This part is a bit difficult to read.
The patch seems to try to assume that '!(gd->flags &GD_FLG_BLOBLIST_READY)' means 'no handoff from the previous stage',Correct.
Quoted 1 line
but I doubt this is a part of GD_FLG_BLOBLIST_READY's semantics.
It is part of the semantics now, however with this patch. That said, I don't love the name
GD_FLG_BLOBLIST_READYbut that name was a side effect of the old behavior too and needing to bail out from "maybe_init".
Quoted 6 lines
Quoted 2 lines
Under the 'handoff from the previous stage' scenario, if
GD_FLG_BLOBLIST_READYis not set in time, the logic here breaks.Now that "exists" is not part of "init", we should have already called
bloblist_checkand set the flag before we can get here.
Just one minor suggestion, can we introduce a GD_FLG_BLOBLIST_HANDOFF? Since the _READY has an ambiguity that "it is ready from alloc"... But with or without above suggested change, overall the patch cleans up the logics, thus it is fine to me:
Regards,
Raymond
Quoted 2 lines
--
Tom
Re: [PATCH v2 3/3] bloblist: Rework bloblist_init and bloblist_maybe_init
Quoted 206 lines · Raymond Mao
Hi Tom,
Quoted 203 lines · Tom Rini
Quoted 180 lines · Raymond Mao
Hi Tom,
Quoted 177 lines · Tom Rini
With bloblist, we need to both see if one already exists as well as create one if it does not. However, the current implementation leads to odd cases where we attempt to create a bloblist before this is possible and have things be overly complicated when we are given one to work with.
This reworks things to instead have a
bloblist_existsfunction, which as the name implies checks for an existing bloblist. This is used in the case of booting, to see if we have one and in turn if we have a device tree there as well as in thebloblist_initfunction to see if we need to do anything.In practical details, we move the logic from
bloblist_initthat was checking for a bloblist to the newbloblist_existsfunction and then can clarify the logic as it is much easier to state when we know we do not have one rather than all the ways we might have one. Then we have the locations that setgd->bloblistnow also set theGD_FLG_BLOBLIST_READYflag.Signed-off-by Tom Rini <[email protected]>---
Changes in v2:
- As noted by Raymond, we need to still check if SPL is being passed a bloblist by TPL.--- common/bloblist.c | 144 +++++++++++++++++++++++---------------------- common/board_f.c | 4 +- include/bloblist.h | 32 +++++----- lib/fdtdec.c | 15 ++--- 4 files changed, 96 insertions(+), 99 deletions(-)common/bloblist.c +39
-70@@ -448,6 +448,7 @@ int bloblist_new(ulong addr, uint size, uint flags, uint align_log2) hdr->align_log2 = align_log2 ? align_log2 :BLOBLIST_BLOB_ALIGN_LOG2 ; hdr->chksum =0 ; gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -475,6 +476,7 @@ int bloblist_check(ulong addr, uint size)return log_msg_ret ("Bad checksum" , -EIO ); } gd->bloblist = hdr; + gd->flags |=GD_FLG_BLOBLIST_READY ;return 0 ; }@@ -576,90 +578,88 @@ int __weak xferlist_from_boot_arg(ulong __always_unused *addr)return -ENOENT ; } -int bloblist_init (void ) +bool bloblist_exists (void ) { -bool fixed =IS_ENABLED (CONFIG_BLOBLIST_FIXED ); -int ret =0 ; -ulong addr =0 , size; +int ret; +ulong addr =0 ;/* Check if a valid transfer list passed in */ -if (!xferlist_from_boot_arg (&addr)) { - size =bloblist_get_total_size (); - }else { -/* -* If U-Boot is not in the first phase, an existing bloblist must -* be at a fixed address. -*/ -bool from_addr = fixed && !xpl_is_first_phase (); - -/* -* If Firmware Handoff is mandatory but no transfer list is -* observed, report it as an error. -*/ -if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) -return -ENOENT ; - - ret = -ENOENT ; - -if (xpl_prev_phase () ==PHASE_TPL && - !IS_ENABLED (CONFIG_TPL_BLOBLIST )) - from_addr = false; -if (fixed) - addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , -CONFIG_BLOBLIST_ADDR ); - size =CONFIG_BLOBLIST_SIZE ; - -if (from_addr) - ret =bloblist_check (addr, size); +if (!xferlist_from_boot_arg (&addr)) + goto found; -if (ret) -log_debug ("Bloblist at %lx not found (err=%d)\n" , - addr, ret); -else -/* Get the real size */ - size = gd->bloblist->total_size; - } +/* +* If Firmware Handoff is mandatory but no transfer list is +* observed, report it as an error. +*/ +if (IS_ENABLED (CONFIG_BLOBLIST_PASSAGE_MANDATORY )) +return false; -if (ret) { -/* -* If we don't have a bloblist from a fixed address, or the one -* in the fixed address is not valid. we must allocate the -* memory for it now. -*/ -if (CONFIG_IS_ENABLED (BLOBLIST_ALLOC )) { -void *ptr =memalign (BLOBLIST_ALIGN , size); - -if (!ptr) -return log_msg_ret ("alloc" , -ENOMEM ); - addr =map_to_sysmem (ptr); - }else if (!fixed) { -return log_msg_ret ("BLOBLIST_FIXED is not enabled" , - ret); - } -log_debug ("Creating new bloblist size %lx at %lx\n" , size, - addr); - ret =bloblist_new (addr, size,0 ,0 ); - }else { -log_debug ("Found existing bloblist size %lx at %lx\n" , size, - addr); - } +/* +* We have checked for a valid transfer list being passed. At this +* point, if we do not have a fixed address for the bloblist, we cannot +* be provided with one. +*/ +if (xpl_is_first_phase () || !IS_ENABLED (CONFIG_BLOBLIST_FIXED )) +return false; -if (ret) -return log_msg_ret ("ini" , ret); - gd->flags |=GD_FLG_BLOBLIST_READY ; +/* +* Check for a valid list as the configured address. +*/ + addr =IF_ENABLED_INT (CONFIG_BLOBLIST_FIXED , +CONFIG_BLOBLIST_ADDR ); + ret =bloblist_check (addr,CONFIG_BLOBLIST_SIZE ); +if (!ret) + goto found; + +log_debug ("Bloblist at %lx not found (err=%d)\n" , addr, ret); +return false; +found: #ifdef DEBUGbloblist_show_stats ();bloblist_show_list ();#endif - -return 0 ; +return true; } -int bloblist_maybe_init (void ) +int bloblist_init (void ) { -if (CONFIG_IS_ENABLED (BLOBLIST ) && !(gd->flags &GD_FLG_BLOBLIST_READY )) -return bloblist_init (); +int ret; +ulong addr =0 , size =CONFIG_BLOBLIST_SIZE ; + +if (gd->flags &GD_FLG_BLOBLIST_READY ) { + log_debug("Found existing bloblist size %x at %p\n",Quoted 8 lines
common/bloblist.c int __weak xferlist_from_boot_arg(ulong __always_unused *addr) · line 635
Quoted 4 lines
common/bloblist.c +4
-0+ gd->bloblist->total_size, gd->bloblist); +return 0 ; + } +This part is a bit difficult to read.
The patch seems to try to assume that '!(gd->flags &GD_FLG_BLOBLIST_READY)' means 'no handoff from the previous stage',Correct.
Quoted 1 line
but I doubt this is a part of GD_FLG_BLOBLIST_READY's semantics.
It is part of the semantics now, however with this patch. That said, I don't love the name
GD_FLG_BLOBLIST_READYbut that name was a side effect of the old behavior too and needing to bail out from "maybe_init".Quoted 2 lines
Under the 'handoff from the previous stage' scenario, if
GD_FLG_BLOBLIST_READYis not set in time, the logic here breaks.
Quoted 8 lines
Quoted 3 lines
Now that "exists" is not part of "init", we should have already called
bloblist_checkand set the flag before we can get here.Just one minor suggestion, can we introduce a
GD_FLG_BLOBLIST_HANDOFF? Since the_READYhas an ambiguity that "it is ready from alloc"... But with or without above suggested change, overall the patch cleans up the logics, thus it is fine to me:
That would be good to see in a follow-up, as I do worry about putting too much in a patch.
Quoted 1 line
Reviewed-by Raymond Mao <[email protected]>
Thanks!
Signature · 1 line
Tom
Am Dienstag, 19. Mai 2026, 18:20:53 CEST schrieb Tom Rini:
Quoted 18 lines
hEY ALL,
I've been sitting on this series for a bit (as the patch dates imply), and I'm ready to move forward now with it.
This series does a few small but important cleanups to how we check for, and initialize a bloblist. The first thing is that the way things are done today, our HANDOFF code can only work with a fixed bloblist location, so express that requirement in
Kconfig. Next, we demote the scary message about "Bloblist at ... not found" to a debug because we most often see that because the bloblist doesn't (and can't) exist yet. Finally, we removebloblist_maybe_initand split this in to an exists and a real init. This results in practically no growth (between 8 bytes growth to 12 bytes saved, with some outliers saving much more thanks to knowing it's impossible to have been passed a bloblist yet). This also cleans up some of the code around checking for / knowing about a bloblist existing.
Quoted 5 lines
Changes in v2:
- Pick up Raymond's tags on patches 1 and 2
- Correct the logic in the final patch to not break TPL passes SPL a bloblist (at a fixed location), as noticed by Raymond
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany Amtsgericht München, HRB 105018 Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider http://www.tq-group.com/
Quoted 18 lines · Tom Rini
hEY ALL,
I've been sitting on this series for a bit (as the patch dates imply), and I'm ready to move forward now with it.
This series does a few small but important cleanups to how we check for, and initialize a bloblist. The first thing is that the way things are done today, our HANDOFF code can only work with a fixed bloblist location, so express that requirement in
Kconfig. Next, we demote the scary message about "Bloblist at ... not found" to a debug because we most often see that because the bloblist doesn't (and can't) exist yet. Finally, we removebloblist_maybe_initand split this in to an exists and a real init. This results in practically no growth (between 8 bytes growth to 12 bytes saved, with some outliers saving much more thanks to knowing it's impossible to have been passed a bloblist yet). This also cleans up some of the code around checking for / knowing about a bloblist existing.
Quoted 1 line
[...]
Applied to u-boot/next, thanks!
[1/3] bloblist / handoff: Make this depend on BLOBLIST_FIXED
commit: 679eb25fb8fd75bc6877e8c03f264bf80f71a4b9
[2/3] bloblist: Demote not finding a bloblist to a debug
commit: b4858d2afcf7fc819ed33643370a2b3ccf7055ac
[3/3] bloblist: Rework bloblist_init and bloblist_maybe_init
commit: 5ab1600213608129ea63fc3046f46349515821d6Signature · 1 line
Tom