boot: Support priority for global bootmeths
v2 cover boot: Support priority for global bootmeths
At present global bootmeths always run first, before all other bootmeths. Optimisations in the code take advantage of this, putting them at the end, so they can be used once and then forgotten.
In some cases it is useful to run global bootmeths later in the boot. For example, the EFI-bootmgr bootmeth may itself scan devices and the network, so running it first can hold up the boot significantly for boards not actually relying on EFI-bootmgr to boot.
This series introduces a new field in global bootmeths which indicates the priority, using the same scheme as is used with bootdev hunters. Thus it is possible to insert the EFI-bootmgr bootmeth just before the hunter for network bootdevs is invoked.
Despite the simplicity of the concept and the relatively small series, this is a fairly significant enhancement. It is also quite tricky to implement, largely due to the way the original code was written, with global bootmeths being a small, size-optimised add-on to the original bootstd implementation.
For now we only allow each global bootmeth to run at most once, but this implementation is written in a way that we could relax that if needed. Then the bootmeth itself could decide whether to run at any particular point in the bootflow iteration.
Size growth is about 390 bytes on Thumb2 (e.g. firefly-rk3288) if CONFIG_BOOTMETH_GLOBAL is enabled, which it normally is. With that disabled (which saves about 4K on the same platform), there is no growth.
Changes in v2:
- Add a log_err() for an invalid state
- Update commit message to indicate the bootmeth will always run
- Document how the priority was chosen
- Add a bit more detail suggested by Heinrich
Simon Glass (17):
boot: Improve comments related to global bootmeths
boot: Try all bootmeths on the final partition
boot: Move obtaining the label into a common file
boot: Add more debugging to iter_incr()
boot: Move showing of bootflows out of the command
boot: Add a new test for global bootmeths
boot: Update first_glob_method when dropping a bootmeth
boot: Add a flag for whether there are global bootmeths
boot: Keep track of which bootmeths have been used
boot: Move preparing bootdev into a function
boot: Support rescanning the global bootmeths
boot: Only run global bootmeths once each
boot: Implement a priority for global bootmeths
boot: Don't change the method count after global bootmeths
boot: Run global bootmeths after all bootdevs are exhausted
boot: Run the EFI bootmgr just before network devices
boot: doc: Update for new global-bootmeth features
boot/bootflow.c | 318 ++++++++++++++++++++++++++++--- boot/bootmeth-uclass.c | 15 +- boot/bootmeth_efi_mgr.c | 9 + cmd/bootflow.c | 66 +------ doc/develop/bootstd/overview.rst | 40 +++- include/bootflow.h | 39 +++- include/bootmeth.h | 4 + test/boot/bootflow.c | 75 +++++++- 8 files changed, 457 insertions(+), 109 deletions(-)
Signature · 4 lines
2.43.0 base-commit: aff68c8514858ddd8d2e508d47bede566511521b branch: glob-us2
PATCH v2 1/17 boot: Improve comments related to global bootmeths
Add a few comments about global bootmeths and first_glob_method
Fix a broken line in bootmeth_setup_iter_order() while we are here.
---
(no changes since v1)
boot/bootflow.c | 3 ++- boot/bootmeth-uclass.c | 4 ++-- include/bootflow.h | 3 ++- test/boot/bootflow.c | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-)
boot/bootflow.c +2 -1
@@ -147,7 +147,7 @@ static void bootflow_iter_set_dev(struct bootflow_iter *iter,if (dev)printf ("Scanning bootdev '%s':\n" , dev->name);else if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && - ucp->flags &BOOTMETHF_GLOBAL ) + ucp->flags &BOOTMETHF_GLOBAL )printf ("Scanning global bootmeth '%s':\n" , iter->method->name);else
@@ -344,6 +344,7 @@ static int bootflow_check(struct bootflow_iter *iter, struct bootflow *bflow)struct udevice *dev;int ret; +/* handle global bootmeths if needed */ if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && iter->doing_global) {bootflow_iter_set_dev (iter,NULL ,0 ); ret =bootmeth_get_bootflow (iter->method, bflow);
boot/bootmeth-uclass.c +2 -2
@@ -156,8 +156,7 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) } ucp =dev_get_uclass_plat (dev); - is_global = ucp->flags & -BOOTMETHF_GLOBAL ; + is_global = ucp->flags &BOOTMETHF_GLOBAL ;if (is_global) { iter->first_glob_method = i;break ;
@@ -204,6 +203,7 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) goto err_order; } +/* start with the global bootmeths */ if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && include_global && iter->first_glob_method !=-1 && iter->first_glob_method != count) { iter->cur_method = iter->first_glob_method;
include/bootflow.h +2 -1
@@ -250,7 +250,8 @@ enum bootflow_meth_flags_t {* @cur_label: Current label being processed * @num_methods: Number of bootmeth devices in @method_order * @cur_method: Current method number, an index into @method_order -* @first_glob_method: First global method, if any, else -1 +* @first_glob_method: Index of first global method within @method_order[], if +* any, else -1 * @cur_prio: Current priority being scanned * @method_order: List of bootmeth devices to use, in order. The normal methods * appear first, then the global ones, if any
test/boot/bootflow.c +1 -1
@@ -401,7 +401,7 @@ static int bootflow_system(struct unit_test_state *uts)ut_assertok (device_probe (dev));sandbox_set_fake_efi_mgr_dev (dev, true); -/* We should get a single 'bootmgr' method right at the end */ +/* We should get a single 'bootmgr' method at the start */ bootstd_clear_glob ();ut_assertok (run_command ("bootflow scan -lH" ,0 )); ut_assert_skip_to_line(
Signature · 1 line
2.43.0
Re: [PATCH v2 01/17] boot: Improve comments related to global bootmeths
Quoted 5 lines · Simon Glass
Add a few comments about global bootmeths and
first_glob_methodFix a broken line in
bootmeth_setup_iter_order()while we are here.Signed-off-by Simon Glass <[email protected]>
Quoted 80 lines
---
(no changes since v1)
boot/bootflow.c | 3 ++- boot/bootmeth-uclass.c | 4 ++-- include/bootflow.h | 3 ++- test/boot/bootflow.c | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-)boot/bootflow.c +2
-1@@ -147,7 +147,7 @@ static void bootflow_iter_set_dev(struct bootflow_iter *iter,if (dev)printf ("Scanning bootdev '%s':\n" , dev->name);else if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && - ucp->flags &BOOTMETHF_GLOBAL ) + ucp->flags &BOOTMETHF_GLOBAL )printf ("Scanning global bootmeth '%s':\n" , iter->method->name);else @@ -344,6 +344,7 @@ static int bootflow_check(struct bootflow_iter *iter, struct bootflow *bflow)struct udevice *dev;int ret; +/* handle global bootmeths if needed */ if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && iter->doing_global) {bootflow_iter_set_dev (iter,NULL ,0 ); ret =bootmeth_get_bootflow (iter->method, bflow);boot/bootmeth-uclass.c +2
-2@@ -156,8 +156,7 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) } ucp =dev_get_uclass_plat (dev); - is_global = ucp->flags & -BOOTMETHF_GLOBAL ; + is_global = ucp->flags &BOOTMETHF_GLOBAL ;if (is_global) { iter->first_glob_method = i;break ;@@ -204,6 +203,7 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) goto err_order; } +/* start with the global bootmeths */ if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && include_global && iter->first_glob_method !=-1 && iter->first_glob_method != count) { iter->cur_method = iter->first_glob_method;include/bootflow.h +2
-1@@ -250,7 +250,8 @@ enum bootflow_meth_flags_t {* @cur_label: Current label being processed * @num_methods: Number of bootmeth devices in @method_order * @cur_method: Current method number, an index into @method_order -* @first_glob_method: First global method, if any, else -1 +* @first_glob_method: Index of first global method within @method_order[], if +* any, else -1 * @cur_prio: Current priority being scanned * @method_order: List of bootmeth devices to use, in order. The normal methods * appear first, then the global ones, if any test/boot/bootflow.c +1
-1@@ -401,7 +401,7 @@ static int bootflow_system(struct unit_test_state *uts)ut_assertok (device_probe (dev));sandbox_set_fake_efi_mgr_dev (dev, true); -/* We should get a single 'bootmgr' method right at the end */ +/* We should get a single 'bootmgr' method at the start */ bootstd_clear_glob ();ut_assertok (run_command ("bootflow scan -lH" ,0 )); ut_assert_skip_to_line(
Re: [PATCH v2 01/17] boot: Improve comments related to global bootmeths
In reply to Simon GlassQuoted 5 lines · Simon Glass
Add a few comments about global bootmeths and
first_glob_methodFix a broken line in
bootmeth_setup_iter_order()while we are here.Signed-off-by Simon Glass <[email protected]>
I'm not a fan of fixing up little spacing issues. Even more so when we aren't changing anything within the function, it just makes the git history slightly harder to read. That's not a NAK either, to be clear.
Signature · 1 line
Tom
PATCH v2 2/17 boot: Try all bootmeths on the final partition
In reply to Simon GlassAt present when one bootmeth fails on the final partition, the next bootmeth is not tried. Adjust the logic to go to the next bootmeth, which is the more natural behaviour.
---
(no changes since v1)
boot/bootflow.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-)
boot/bootflow.c +16 -18
@@ -195,27 +195,25 @@ static int iter_incr(struct bootflow_iter *iter)if (iter->err ==BF_NO_MORE_DEVICES )return BF_NO_MORE_DEVICES ; -if (iter->err !=BF_NO_MORE_PARTS ) { -/* Get the next boothmethod */ -if (++iter->cur_method < iter->num_methods) { - iter->method = iter->method_order[iter->cur_method]; -return 0 ; - } +/* Get the next boothmethod */ +if (++iter->cur_method < iter->num_methods) { + iter->method = iter->method_order[iter->cur_method]; +return 0 ; + } + +/* +* If we have finished scanning the global bootmeths, start the +* normal bootdev scan +*/ +if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && global) { + iter->num_methods = iter->first_glob_method; + iter->doing_global = false;/* -* If we have finished scanning the global bootmeths, start the -* normal bootdev scan +* Don't move to the next dev as we haven't tried this +* one yet! */ -if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && global) { - iter->num_methods = iter->first_glob_method; - iter->doing_global = false; - -/* -* Don't move to the next dev as we haven't tried this -* one yet! -*/ - inc_dev = false; - } + inc_dev = false; }if (iter->flags &BOOTFLOWIF_SINGLE_PARTITION )
Signature · 1 line
2.43.0
Re: [PATCH v2 02/17] boot: Try all bootmeths on the final partition
Quoted 5 lines · Simon Glass
At present when one bootmeth fails on the final partition, the next bootmeth is not tried. Adjust the logic to go to the next bootmeth, which is the more natural behaviour.
Signed-off-by Simon Glass <[email protected]>
My feedback on v1:
https://lore.kernel.org/u-boot/20250331174144.GI93000@bill-the-cat/
was that we need to do a documentation change when doing a behavior change. And I cannot recall if this change here is because of reports of problems or not.
Signature · 1 line
Tom
Re: [PATCH v2 02/17] boot: Try all bootmeths on the final partition
Hi Tom,
Quoted 7 lines · Tom Rini
Quoted 4 lines · Simon Glass
At present when one bootmeth fails on the final partition, the next bootmeth is not tried. Adjust the logic to go to the next bootmeth, which is the more natural behaviour.
Quoted 7 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>My feedback on v1:
https://lore.kernel.org/u-boot/20250331174144.GI93000@bill-the-cat/
was that we need to do a documentation change when doing a behavior change. And I cannot recall if this change here is because of reports of problems or not.
This is a long time ago, but I think it might have been an inconsistency that I found myself. Otherwise I would probably have mentioned the person who reported it.
The documentation already implies the logic in this patch, as I see it. But please suggest any changes.
Regards,
Simon
Re: [PATCH v2 02/17] boot: Try all bootmeths on the final partition
Quoted 18 lines · Simon Glass
Hi Tom,
Quoted 7 lines · Tom Rini
Quoted 4 lines · Simon Glass
At present when one bootmeth fails on the final partition, the next bootmeth is not tried. Adjust the logic to go to the next bootmeth, which is the more natural behaviour.
Quoted 7 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>My feedback on v1:
https://lore.kernel.org/u-boot/20250331174144.GI93000@bill-the-cat/
was that we need to do a documentation change when doing a behavior change. And I cannot recall if this change here is because of reports of problems or not.
Quoted 6 lines
This is a long time ago, but I think it might have been an inconsistency that I found myself. Otherwise I would probably have mentioned the person who reported it.
The documentation already implies the logic in this patch, as I see it. But please suggest any changes.
OK, I guess it's because the commit message doesn't explain the bug clearly enough. Is this a correct description of the patch:
At present, normally when one bootmeth fails on a partition, we move on and try the next bootmeth. However, this was not the case for the final partition due to a bug. Rework the logic so that all partitions are treated the same.
Signature · 1 line
Tom
Re: [PATCH v2 02/17] boot: Try all bootmeths on the final partition
Hi Tom,
Quoted 27 lines · Tom Rini
Quoted 18 lines · Simon Glass
Hi Tom,
Quoted 7 lines · Tom Rini
Quoted 4 lines · Simon Glass
At present when one bootmeth fails on the final partition, the next bootmeth is not tried. Adjust the logic to go to the next bootmeth, which is the more natural behaviour.
Quoted 7 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>My feedback on v1:
https://lore.kernel.org/u-boot/20250331174144.GI93000@bill-the-cat/
was that we need to do a documentation change when doing a behavior change. And I cannot recall if this change here is because of reports of problems or not.Quoted 6 lines
This is a long time ago, but I think it might have been an inconsistency that I found myself. Otherwise I would probably have mentioned the person who reported it.
The documentation already implies the logic in this patch, as I see it. But please suggest any changes.
Quoted 7 lines
OK, I guess it's because the commit message doesn't explain the bug clearly enough. Is this a correct description of the patch:
At present, normally when one bootmeth fails on a partition, we move on and try the next bootmeth. However, this was not the case for the final partition due to a bug. Rework the logic so that all partitions are treated the same.
We can certainly say that if you like. It is fair to say that the algorithm is still being evolved as new things come up. Most of the behaviour has been driven by new tests that I've written. The global bootmeth is the biggest change since hunters were introduced, but I suspect there will be more in future.
I'm heading out later today but can probably send v3 series (with the tweaks you've given) tomorrow. After that I'm not sure as I'm on holiday for two weeks.
Regards,
Simon
Re: [PATCH v2 02/17] boot: Try all bootmeths on the final partition
Quoted 44 lines · Simon Glass
Hi Tom,
Quoted 27 lines · Tom Rini
Quoted 18 lines · Simon Glass
Hi Tom,
Quoted 7 lines · Tom Rini
Quoted 4 lines · Simon Glass
At present when one bootmeth fails on the final partition, the next bootmeth is not tried. Adjust the logic to go to the next bootmeth, which is the more natural behaviour.
Quoted 7 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>My feedback on v1:
https://lore.kernel.org/u-boot/20250331174144.GI93000@bill-the-cat/
was that we need to do a documentation change when doing a behavior change. And I cannot recall if this change here is because of reports of problems or not.Quoted 6 lines
This is a long time ago, but I think it might have been an inconsistency that I found myself. Otherwise I would probably have mentioned the person who reported it.
The documentation already implies the logic in this patch, as I see it. But please suggest any changes.
Quoted 7 lines
OK, I guess it's because the commit message doesn't explain the bug clearly enough. Is this a correct description of the patch:
At present, normally when one bootmeth fails on a partition, we move on and try the next bootmeth. However, this was not the case for the final partition due to a bug. Rework the logic so that all partitions are treated the same.
We can certainly say that if you like. It is fair to say that the algorithm is still being evolved as new things come up. Most of the behaviour has been driven by new tests that I've written. The global bootmeth is the biggest change since hunters were introduced, but I suspect there will be more in future.
Quoted 3 lines
I'm heading out later today but can probably send v3 series (with the tweaks you've given) tomorrow. After that I'm not sure as I'm on holiday for two weeks.
Peter's feedback should be addressed too for a v3 (and not just set aside).
Signature · 1 line
Tom
Re: [PATCH v2 02/17] boot: Try all bootmeths on the final partition
Hi Tom,
Quoted 46 lines · Tom Rini
Quoted 44 lines · Simon Glass
Hi Tom,
Quoted 27 lines · Tom Rini
Quoted 18 lines · Simon Glass
Hi Tom,
Quoted 7 lines · Tom Rini
Quoted 4 lines · Simon Glass
At present when one bootmeth fails on the final partition, the next bootmeth is not tried. Adjust the logic to go to the next bootmeth, which is the more natural behaviour.
Quoted 7 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>My feedback on v1:
https://lore.kernel.org/u-boot/20250331174144.GI93000@bill-the-cat/
was that we need to do a documentation change when doing a behavior change. And I cannot recall if this change here is because of reports of problems or not.Quoted 6 lines
This is a long time ago, but I think it might have been an inconsistency that I found myself. Otherwise I would probably have mentioned the person who reported it.
The documentation already implies the logic in this patch, as I see it. But please suggest any changes.
Quoted 7 lines
OK, I guess it's because the commit message doesn't explain the bug clearly enough. Is this a correct description of the patch:
At present, normally when one bootmeth fails on a partition, we move on and try the next bootmeth. However, this was not the case for the final partition due to a bug. Rework the logic so that all partitions are treated the same.
We can certainly say that if you like. It is fair to say that the algorithm is still being evolved as new things come up. Most of the behaviour has been driven by new tests that I've written. The global bootmeth is the biggest change since hunters were introduced, but I suspect there will be more in future.
Quoted 6 lines
Quoted 3 lines
I'm heading out later today but can probably send v3 series (with the tweaks you've given) tomorrow. After that I'm not sure as I'm on holiday for two weeks.
Peter's feedback should be addressed too for a v3 (and not just set aside).
Is that the email just received, or something from a different series that I maybe missed from a while back?
Regards,
Simon
Re: [PATCH v2 02/17] boot: Try all bootmeths on the final partition
Quoted 53 lines · Simon Glass
Hi Tom,
Quoted 50 lines · Tom Rini
Quoted 47 lines · Simon Glass
Hi Tom,
Quoted 27 lines · Tom Rini
Quoted 18 lines · Simon Glass
Hi Tom,
Quoted 7 lines · Tom Rini
Quoted 4 lines · Simon Glass
At present when one bootmeth fails on the final partition, the next bootmeth is not tried. Adjust the logic to go to the next bootmeth, which is the more natural behaviour.
Quoted 7 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>My feedback on v1:
https://lore.kernel.org/u-boot/20250331174144.GI93000@bill-the-cat/
was that we need to do a documentation change when doing a behavior change. And I cannot recall if this change here is because of reports of problems or not.Quoted 6 lines
This is a long time ago, but I think it might have been an inconsistency that I found myself. Otherwise I would probably have mentioned the person who reported it.
The documentation already implies the logic in this patch, as I see it. But please suggest any changes.
Quoted 7 lines
OK, I guess it's because the commit message doesn't explain the bug clearly enough. Is this a correct description of the patch:
At present, normally when one bootmeth fails on a partition, we move on and try the next bootmeth. However, this was not the case for the final partition due to a bug. Rework the logic so that all partitions are treated the same.
We can certainly say that if you like. It is fair to say that the algorithm is still being evolved as new things come up. Most of the behaviour has been driven by new tests that I've written. The global bootmeth is the biggest change since hunters were introduced, but I suspect there will be more in future.
I'm heading out later today but can probably send v3 series (with the tweaks you've given) tomorrow. After that I'm not sure as I'm on holiday for two weeks.
Quoted 5 lines
Quoted 2 lines
Peter's feedback should be addressed too for a v3 (and not just set aside).
Is that the email just received, or something from a different series that I maybe missed from a while back?
It was yesterday:
https://lore.kernel.org/u-boot/CALeDE9Ovemog2AGN_Li8Ju12QKHOC0D30V2=KG00f0KsQ5aPkg@mail.gmail.com/T/#m34f6e2c51fdfb275ba9930bfdc2ff349ee542b51
Signature · 1 line
Tom
Re: [PATCH v2 02/17] boot: Try all bootmeths on the final partition
Hi Tom,
Quoted 55 lines · Tom Rini
Quoted 53 lines · Simon Glass
Hi Tom,
Quoted 50 lines · Tom Rini
Quoted 47 lines · Simon Glass
Hi Tom,
Quoted 27 lines · Tom Rini
Quoted 18 lines · Simon Glass
Hi Tom,
Quoted 7 lines · Tom Rini
Quoted 4 lines · Simon Glass
At present when one bootmeth fails on the final partition, the next bootmeth is not tried. Adjust the logic to go to the next bootmeth, which is the more natural behaviour.
Quoted 7 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>My feedback on v1:
https://lore.kernel.org/u-boot/20250331174144.GI93000@bill-the-cat/
was that we need to do a documentation change when doing a behavior change. And I cannot recall if this change here is because of reports of problems or not.Quoted 6 lines
This is a long time ago, but I think it might have been an inconsistency that I found myself. Otherwise I would probably have mentioned the person who reported it.
The documentation already implies the logic in this patch, as I see it. But please suggest any changes.
Quoted 7 lines
OK, I guess it's because the commit message doesn't explain the bug clearly enough. Is this a correct description of the patch:
At present, normally when one bootmeth fails on a partition, we move on and try the next bootmeth. However, this was not the case for the final partition due to a bug. Rework the logic so that all partitions are treated the same.
We can certainly say that if you like. It is fair to say that the algorithm is still being evolved as new things come up. Most of the behaviour has been driven by new tests that I've written. The global bootmeth is the biggest change since hunters were introduced, but I suspect there will be more in future.
I'm heading out later today but can probably send v3 series (with the tweaks you've given) tomorrow. After that I'm not sure as I'm on holiday for two weeks.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Peter's feedback should be addressed too for a v3 (and not just set aside).
Is that the email just received, or something from a different series that I maybe missed from a while back?
It was yesterday:
https://lore.kernel.org/u-boot/CALeDE9Ovemog2AGN_Li8Ju12QKHOC0D30V2=KG00f0KsQ5aPkg@mail.gmail.com/T/#m34f6e2c51fdfb275ba9930bfdc2ff349ee542b51
OK, I replied. Would you like me to send the 5 separate patches he mentions as a separate series?
Regards,
Simon
Re: [PATCH v2 02/17] boot: Try all bootmeths on the final partition
Quoted 61 lines · Simon Glass
Hi Tom,
Quoted 58 lines · Tom Rini
Quoted 56 lines · Simon Glass
Hi Tom,
Quoted 52 lines · Tom Rini
Quoted 44 lines · Simon Glass
Hi Tom,
Quoted 27 lines · Tom Rini
Quoted 18 lines · Simon Glass
Hi Tom,
Quoted 7 lines · Tom Rini
Quoted 4 lines · Simon Glass
At present when one bootmeth fails on the final partition, the next bootmeth is not tried. Adjust the logic to go to the next bootmeth, which is the more natural behaviour.
Quoted 7 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>My feedback on v1:
https://lore.kernel.org/u-boot/20250331174144.GI93000@bill-the-cat/
was that we need to do a documentation change when doing a behavior change. And I cannot recall if this change here is because of reports of problems or not.Quoted 6 lines
This is a long time ago, but I think it might have been an inconsistency that I found myself. Otherwise I would probably have mentioned the person who reported it.
The documentation already implies the logic in this patch, as I see it. But please suggest any changes.
Quoted 7 lines
OK, I guess it's because the commit message doesn't explain the bug clearly enough. Is this a correct description of the patch:
At present, normally when one bootmeth fails on a partition, we move on and try the next bootmeth. However, this was not the case for the final partition due to a bug. Rework the logic so that all partitions are treated the same.
We can certainly say that if you like. It is fair to say that the algorithm is still being evolved as new things come up. Most of the behaviour has been driven by new tests that I've written. The global bootmeth is the biggest change since hunters were introduced, but I suspect there will be more in future.
Quoted 3 lines
I'm heading out later today but can probably send v3 series (with the tweaks you've given) tomorrow. After that I'm not sure as I'm on holiday for two weeks.
Peter's feedback should be addressed too for a v3 (and not just set aside).
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Is that the email just received, or something from a different series that I maybe missed from a while back?
It was yesterday:
https://lore.kernel.org/u-boot/CALeDE9Ovemog2AGN_Li8Ju12QKHOC0D30V2=KG00f0KsQ5aPkg@mail.gmail.com/T/#m34f6e2c51fdfb275ba9930bfdc2ff349ee542b51OK, I replied. Would you like me to send the 5 separate patches he mentions as a separate series?
I think given what Andre said on the call (and that he'll test v2 to see if it addresses things) and what you said to Peter now, there's some misunderstandings of what the issues are still. So yes, splitting just those patches out to start with (and not reposting the rest) would be a good next step.
Signature · 1 line
Tom
PATCH v2 3/17 boot: Move obtaining the label into a common file
In reply to Simon GlassThe 'bootflow list' command supports looking at the EFI device-path when available. Move this piece into a common function so it can be used elsewhere.
Use 'usb' instead of 'usb_mass_storage' for usb so that it fits in the column space.
This updates the output from 'bootflow list'.
---
(no changes since v1)
boot/bootflow.c | 19 +++++++++++++++++++ cmd/bootflow.c | 8 +++++--- include/bootflow.h | 8 ++++++++ test/boot/bootflow.c | 2 +- 4 files changed, 33 insertions(+), 4 deletions(-)
boot/bootflow.c +19 -0
@@ -11,6 +11,7 @@#include <bootmeth.h> #include <bootstd.h> #include <dm.h> +#include <efi_device_path.h> #include <env_internal.h> #include <malloc.h> #include <serial.h>
@@ -1008,3 +1009,21 @@ int bootflow_get_seq(const struct bootflow *bflow)return alist_calc_index (&std->bootflows, bflow); } + +const char *bootflow_guess_label (const struct bootflow *bflow) +{ +const char *name =NULL ; + +if (bflow->dev) { +struct udevice *media =dev_get_parent (bflow->dev); + +if (device_get_uclass_id (media) ==UCLASS_MASS_STORAGE ) + name ="usb" ; +else + name =dev_get_uclass_name (media); + } +if (!name) + name ="(none)" ; + +return name; +}
cmd/bootflow.c +5 -3
@@ -70,10 +70,12 @@ static void report_bootflow_err(struct bootflow *bflow, int err)*/ static void show_bootflow (int index,struct bootflow *bflow,bool errors) { +const char *name =bootflow_guess_label (bflow); +printf ("%3x %-11s %-6s %-9.9s %4x %-25.25s %s\n" , index, - bflow->method->name,bootflow_state_get_name (bflow->state), - bflow->dev ?dev_get_uclass_name (dev_get_parent (bflow->dev)) : -"(none)" , bflow->part, bflow->name, bflow->fname ?:"" ); + bflow->method ? bflow->method->name :"(none)" , +bootflow_state_get_name (bflow->state), name, bflow->part, + bflow->name, bflow->fname ?:"" );if (errors)report_bootflow_err (bflow, bflow->err); }
include/bootflow.h +8 -0
@@ -692,4 +692,12 @@ int bootflow_menu_start(struct bootstd_priv *std, bool text_mode,*/ int bootflow_menu_poll (struct expo *exp,int *seqp); +/** +* bootflow_guess_label() - Produce a plausible label for a bootflow +* +* This uses the uclass name or EFI device-path to come up with a useful label +* for display to the user. Ideally it will say "mmc", "usb", nvme", etc. +*/ +const char *bootflow_guess_label (const struct bootflow *bflow); +#endif
test/boot/bootflow.c +1 -1
@@ -1301,7 +1301,7 @@ static int bootflow_efi(struct unit_test_state *uts)ut_assert_nextlinen ("---" );ut_assert_nextlinen (" 0 extlinux" );ut_assert_nextlinen ( -" 1 efi ready usb_mass_ 1 usb_mass_storage.lun0.boo /EFI/BOOT/BOOTSBOX.EFI" ); +" 1 efi ready usb 1 usb_mass_storage.lun0.boo /EFI/BOOT/BOOTSBOX.EFI" );ut_assert_nextlinen ("---" );ut_assert_skip_to_line ("(2 bootflows, 2 valid)" );ut_assert_console_end ();
Signature · 1 line
2.43.0
PATCH v2 4/17 boot: Add more debugging to iter_incr()
In reply to Simon GlassThis function is the core of the bootstd iteration. Add some debugging for the decisions it makes along the way, to make it easier to track what is going on.
---
(no changes since v1)
boot/bootflow.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
boot/bootflow.c +20 -4
@@ -193,14 +193,19 @@ static int iter_incr(struct bootflow_iter *iter)log_debug ("entry: err=%d\n" , iter->err); global = iter->doing_global; -if (iter->err ==BF_NO_MORE_DEVICES ) +if (iter->err ==BF_NO_MORE_DEVICES ) { +log_debug ("-> err: no more devices1\n" );return BF_NO_MORE_DEVICES ; + }/* Get the next boothmethod */ if (++iter->cur_method < iter->num_methods) { iter->method = iter->method_order[iter->cur_method]; +log_debug ("-> next method '%s'\n" , iter->method->name);return 0 ; } +log_debug ("! no more methods: cur_method %d num_methods %d\n" , + iter->cur_method, iter->num_methods);/* * If we have finished scanning the global bootmeths, start the
@@ -217,8 +222,10 @@ static int iter_incr(struct bootflow_iter *iter) inc_dev = false; } -if (iter->flags &BOOTFLOWIF_SINGLE_PARTITION ) +if (iter->flags &BOOTFLOWIF_SINGLE_PARTITION ) { +log_debug ("-> single partition: no more devices\n" );return BF_NO_MORE_DEVICES ; + }/* No more bootmeths; start at the first one, and... */ iter->cur_method =0 ;
@@ -226,11 +233,15 @@ static int iter_incr(struct bootflow_iter *iter)if (iter->err !=BF_NO_MORE_PARTS ) {/* ...select next partition */ -if (++iter->part <= iter->max_part) +if (++iter->part <= iter->max_part) { +log_debug ("-> next partition %d max %d\n" , iter->part, + iter->max_part);return 0 ; + } }/* No more partitions; start at the first one and... */ +log_debug ("! no more partitions\n" ); iter->part =0 ;/*
@@ -324,8 +335,13 @@ static int iter_incr(struct bootflow_iter *iter) }/* if there are no more bootdevs, give up */ -if (ret) +if (ret) { +log_debug ("-> no more bootdevs\n" );return log_msg_ret ("incr" ,BF_NO_MORE_DEVICES ); + } + +log_debug ("-> bootdev '%s' method '%s'\n" , dev->name, + iter->method->name);return 0 ; }
Signature · 1 line
2.43.0
PATCH v2 5/17 boot: Move showing of bootflows out of the command
In reply to Simon GlassIt is helpful in tests to be able to show the bootflow that is being examined. Move show_bootflow() into boot/ and rename it.
---
Changes in v2:
- Add a log_err() for an invalid state
boot/bootflow.c | 57 ++++++++++++++++++++++++++++++++++++++ cmd/bootflow.c | 68 ++-------------------------------------------- include/bootflow.h | 9 ++++++ 3 files changed, 69 insertions(+), 65 deletions(-)
boot/bootflow.c +57 -0
@@ -54,6 +54,63 @@ const char *bootflow_state_get_name(enum bootflow_state_t state)return bootflow_state[state]; } +/** +* report_bootflow_err() - Report where a bootflow failed +* +* When a bootflow does not make it to the 'loaded' state, something went wrong. +* Print a helpful message if there is an error +* +* @bflow: Bootflow to process +* @err: Error code (0 if none) +*/ +static void report_bootflow_err (struct bootflow *bflow,int err) +{ +if (!err) +return ; + +/* Indent out to 'Method' */ +printf (" ** " ); + +switch (bflow->state) { +case BOOTFLOWST_BASE : +printf ("No media/partition found" ); +break ; +case BOOTFLOWST_MEDIA : +printf ("No partition found" ); +break ; +case BOOTFLOWST_PART : +printf ("No filesystem found" ); +break ; +case BOOTFLOWST_FS : +printf ("File not found" ); +break ; +case BOOTFLOWST_FILE : +printf ("File cannot be loaded" ); +break ; +case BOOTFLOWST_READY : +printf ("Ready" ); +break ; +case BOOTFLOWST_COUNT : +log_err ("Unexpected boot value of bootflow error %d" , + bflow->state); +break ; + } + +printf (", err=%dE\n" , err); +} + +void bootflow_show (int index,struct bootflow *bflow,bool errors) +{ +const char *name =bootflow_guess_label (bflow); + +printf ("%3x %-11s %-6s %-9.9s %4x %-25.25s %s\n" , index, + bflow->method ? bflow->method->name :"(none)" , +bootflow_state_get_name (bflow->state), name, bflow->part, + bflow->name, bflow->fname ?:"" ); +if (errors) +report_bootflow_err (bflow, bflow->err); +} +int bootflow_first_glob (struct bootflow **bflowp) {struct bootstd_priv *std;
cmd/bootflow.c +3 -65
92 lines not on this page · raw message
include/bootflow.h +9 -0
@@ -700,4 +700,13 @@ int bootflow_menu_poll(struct expo *exp, int *seqp);*/ const char *bootflow_guess_label (const struct bootflow *bflow); +/** +* bootflow_show() - Show the status of a bootflow +* +* @seq: Bootflow index +* @bflow: Bootflow to show +* @errors: True to show the error received, if any +*/ +void bootflow_show (int index,struct bootflow *bflow,bool errors); +#endif
Signature · 1 line
2.43.0
Re: [PATCH v2 05/17] boot: Move showing of bootflows out of the command
Quoted 13 lines · Simon Glass
It is helpful in tests to be able to show the bootflow that is being examined. Move
show_bootflow()into boot/ and rename it.Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add alog_err()for an invalid stateboot/bootflow.c | 57 ++++++++++++++++++++++++++++++++++++++ cmd/bootflow.c | 68 ++-------------------------------------------- include/bootflow.h | 9 ++++++ 3 files changed, 69 insertions(+), 65 deletions(-)
[snip]
boot/bootflow.c const char *bootflow_state_get_name(enum bootflow_state_t state) · line 95
Quoted 3 lines
boot/bootflow.c +3
-0+case BOOTFLOWST_COUNT : +log_err ("Unexpected boot value of bootflow error %d" , + bflow->state);
A small thing, checkpatch.pl catches that this isn't aligned with the '(' here as it should be.
A larger thing, and please correct me if I'm wrong, but on reading the whole set of changes, this move + rename just means we're putting more info in the test output, and nothing else?
Signature · 1 line
Tom
Re: [PATCH v2 05/17] boot: Move showing of bootflows out of the command
Hi Tom,
Quoted 16 lines · Tom Rini
Quoted 6 lines · Simon Glass
It is helpful in tests to be able to show the bootflow that is being examined. Move
show_bootflow()into boot/ and rename it.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v2:
- Add alog_err()for an invalid stateboot/bootflow.c | 57 ++++++++++++++++++++++++++++++++++++++ cmd/bootflow.c | 68 ++-------------------------------------------- include/bootflow.h | 9 ++++++ 3 files changed, 69 insertions(+), 65 deletions(-)
Quoted 7 lines
[snip]
boot/bootflow.c const char *bootflow_state_get_name(enum bootflow_state_t state) · line 95
Quoted 3 lines
boot/bootflow.c +3
-0+case BOOTFLOWST_COUNT : +log_err ("Unexpected boot value of bootflow error %d" , + bflow->state);A small thing, checkpatch.pl catches that this isn't aligned with the '(' here as it should be.
OK. I'm unsure whether I really want this line anyway, since it increases code size.
Quoted 4 lines
A larger thing, and please correct me if I'm wrong, but on reading the whole set of changes, this move + rename just means we're putting more info in the test output, and nothing else?
It will also appear if you have CONFIG BOOTSTD_FULL and use 'bootflow list' or 'bootflow scan -l'.
Regards.
Simon
Re: [PATCH v2 05/17] boot: Move showing of bootflows out of the command
Quoted 31 lines · Simon Glass
Hi Tom,
Quoted 16 lines · Tom Rini
Quoted 6 lines · Simon Glass
It is helpful in tests to be able to show the bootflow that is being examined. Move
show_bootflow()into boot/ and rename it.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v2:
- Add alog_err()for an invalid stateboot/bootflow.c | 57 ++++++++++++++++++++++++++++++++++++++ cmd/bootflow.c | 68 ++-------------------------------------------- include/bootflow.h | 9 ++++++ 3 files changed, 69 insertions(+), 65 deletions(-)Quoted 7 lines
[snip]
boot/bootflow.c const char *bootflow_state_get_name(enum bootflow_state_t state) · line 95
Quoted 3 lines
boot/bootflow.c +3
-0+case BOOTFLOWST_COUNT : +log_err ("Unexpected boot value of bootflow error %d" , + bflow->state);A small thing, checkpatch.pl catches that this isn't aligned with the '(' here as it should be.
OK. I'm unsure whether I really want this line anyway, since it increases code size.
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
A larger thing, and please correct me if I'm wrong, but on reading the whole set of changes, this move + rename just means we're putting more info in the test output, and nothing else?
It will also appear if you have CONFIG
BOOTSTD_FULLand use 'bootflow list' or 'bootflow scan -l'.
But that should be the case before this patch as well, yes?
Signature · 1 line
Tom
Re: [PATCH v2 05/17] boot: Move showing of bootflows out of the command
Hi Tom,
Quoted 33 lines · Tom Rini
Quoted 31 lines · Simon Glass
Hi Tom,
Quoted 16 lines · Tom Rini
Quoted 6 lines · Simon Glass
It is helpful in tests to be able to show the bootflow that is being examined. Move
show_bootflow()into boot/ and rename it.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v2:
- Add alog_err()for an invalid stateboot/bootflow.c | 57 ++++++++++++++++++++++++++++++++++++++ cmd/bootflow.c | 68 ++-------------------------------------------- include/bootflow.h | 9 ++++++ 3 files changed, 69 insertions(+), 65 deletions(-)Quoted 7 lines
[snip]
boot/bootflow.c const char *bootflow_state_get_name(enum bootflow_state_t state) · line 95
Quoted 3 lines
boot/bootflow.c +3
-0+case BOOTFLOWST_COUNT : +log_err ("Unexpected boot value of bootflow error %d" , + bflow->state);A small thing, checkpatch.pl catches that this isn't aligned with the '(' here as it should be.
OK. I'm unsure whether I really want this line anyway, since it increases code size.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
A larger thing, and please correct me if I'm wrong, but on reading the whole set of changes, this move + rename just means we're putting more info in the test output, and nothing else?
It will also appear if you have CONFIG
BOOTSTD_FULLand use 'bootflow list' or 'bootflow scan -l'.But that should be the case before this patch as well, yes?
Yes, that's right. This is just moving the code into a place where it can be used from tests.
Regards,
Simon
Re: [PATCH v2 05/17] boot: Move showing of bootflows out of the command
Quoted 40 lines · Simon Glass
Hi Tom,
Quoted 37 lines · Tom Rini
Quoted 35 lines · Simon Glass
Hi Tom,
Quoted 16 lines · Tom Rini
Quoted 6 lines · Simon Glass
It is helpful in tests to be able to show the bootflow that is being examined. Move
show_bootflow()into boot/ and rename it.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v2:
- Add alog_err()for an invalid stateboot/bootflow.c | 57 ++++++++++++++++++++++++++++++++++++++ cmd/bootflow.c | 68 ++-------------------------------------------- include/bootflow.h | 9 ++++++ 3 files changed, 69 insertions(+), 65 deletions(-)Quoted 7 lines
[snip]
boot/bootflow.c const char *bootflow_state_get_name(enum bootflow_state_t state) · line 95
Quoted 3 lines
boot/bootflow.c +3
-0+case BOOTFLOWST_COUNT : +log_err ("Unexpected boot value of bootflow error %d" , + bflow->state);A small thing, checkpatch.pl catches that this isn't aligned with the '(' here as it should be.
OK. I'm unsure whether I really want this line anyway, since it increases code size.
Quoted 4 lines
A larger thing, and please correct me if I'm wrong, but on reading the whole set of changes, this move + rename just means we're putting more info in the test output, and nothing else?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
It will also appear if you have CONFIG
BOOTSTD_FULLand use 'bootflow list' or 'bootflow scan -l'.But that should be the case before this patch as well, yes?
Yes, that's right. This is just moving the code into a place where it can be used from tests.
But it's not being used from tests, with this series.
Signature · 1 line
Tom
Re: [PATCH v2 05/17] boot: Move showing of bootflows out of the command
Hi Tom,
Quoted 45 lines · Tom Rini
Quoted 43 lines · Simon Glass
Hi Tom,
Quoted 40 lines · Tom Rini
Quoted 37 lines · Simon Glass
Hi Tom,
Quoted 16 lines · Tom Rini
Quoted 6 lines · Simon Glass
It is helpful in tests to be able to show the bootflow that is being examined. Move
show_bootflow()into boot/ and rename it.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v2:
- Add alog_err()for an invalid stateboot/bootflow.c | 57 ++++++++++++++++++++++++++++++++++++++ cmd/bootflow.c | 68 ++-------------------------------------------- include/bootflow.h | 9 ++++++ 3 files changed, 69 insertions(+), 65 deletions(-)Quoted 7 lines
[snip]
boot/bootflow.c const char *bootflow_state_get_name(enum bootflow_state_t state) · line 95
Quoted 3 lines
boot/bootflow.c +3
-0+case BOOTFLOWST_COUNT : +log_err ("Unexpected boot value of bootflow error %d" , + bflow->state);A small thing, checkpatch.pl catches that this isn't aligned with the '(' here as it should be.
OK. I'm unsure whether I really want this line anyway, since it increases code size.
Quoted 4 lines
A larger thing, and please correct me if I'm wrong, but on reading the whole set of changes, this move + rename just means we're putting more info in the test output, and nothing else?
It will also appear if you have CONFIG
BOOTSTD_FULLand use 'bootflow list' or 'bootflow scan -l'.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
But that should be the case before this patch as well, yes?
Yes, that's right. This is just moving the code into a place where it can be used from tests.
But it's not being used from tests, with this series.
Please see this one: 'boot: Add a new test for global bootmeths'
Regards,
Simon
Re: [PATCH v2 05/17] boot: Move showing of bootflows out of the command
Quoted 48 lines · Simon Glass
Hi Tom,
Quoted 45 lines · Tom Rini
Quoted 43 lines · Simon Glass
Hi Tom,
Quoted 40 lines · Tom Rini
Quoted 37 lines · Simon Glass
Hi Tom,
Quoted 16 lines · Tom Rini
Quoted 6 lines · Simon Glass
It is helpful in tests to be able to show the bootflow that is being examined. Move
show_bootflow()into boot/ and rename it.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v2:
- Add alog_err()for an invalid stateboot/bootflow.c | 57 ++++++++++++++++++++++++++++++++++++++ cmd/bootflow.c | 68 ++-------------------------------------------- include/bootflow.h | 9 ++++++ 3 files changed, 69 insertions(+), 65 deletions(-)Quoted 7 lines
[snip]
Review
Quoted 3 lines
(quoted diff) +3
-0+ case BOOTFLOWST_COUNT: + log_err("Unexpected boot value of bootflow error %d", + bflow->state);A small thing, checkpatch.pl catches that this isn't aligned with the '(' here as it should be.
OK. I'm unsure whether I really want this line anyway, since it increases code size.
Quoted 4 lines
A larger thing, and please correct me if I'm wrong, but on reading the whole set of changes, this move + rename just means we're putting more info in the test output, and nothing else?
It will also appear if you have CONFIG
BOOTSTD_FULLand use 'bootflow list' or 'bootflow scan -l'.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
But that should be the case before this patch as well, yes?
Yes, that's right. This is just moving the code into a place where it can be used from tests.
But it's not being used from tests, with this series.
Please see this one: 'boot: Add a new test for global bootmeths'
Yes, it calls the function, but doesn't seem to do anything with that, especially considering what the test does before these patches.
Signature · 1 line
Tom
Re: [PATCH v2 05/17] boot: Move showing of bootflows out of the command
Hi Tom,
Quoted 55 lines · Tom Rini
Quoted 53 lines · Simon Glass
Hi Tom,
Quoted 50 lines · Tom Rini
Quoted 47 lines · Simon Glass
Hi Tom,
Quoted 33 lines · Tom Rini
Quoted 31 lines · Simon Glass
Hi Tom,
Quoted 16 lines · Tom Rini
Quoted 6 lines · Simon Glass
It is helpful in tests to be able to show the bootflow that is being examined. Move
show_bootflow()into boot/ and rename it.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v2:
- Add alog_err()for an invalid stateboot/bootflow.c | 57 ++++++++++++++++++++++++++++++++++++++ cmd/bootflow.c | 68 ++-------------------------------------------- include/bootflow.h | 9 ++++++ 3 files changed, 69 insertions(+), 65 deletions(-)Quoted 7 lines
[snip]
Review
Quoted 3 lines
(quoted diff) +3
-0+ case BOOTFLOWST_COUNT: + log_err("Unexpected boot value of bootflow error %d", + bflow->state);A small thing, checkpatch.pl catches that this isn't aligned with the '(' here as it should be.
OK. I'm unsure whether I really want this line anyway, since it increases code size.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
A larger thing, and please correct me if I'm wrong, but on reading the whole set of changes, this move + rename just means we're putting more info in the test output, and nothing else?
It will also appear if you have CONFIG
BOOTSTD_FULLand use 'bootflow list' or 'bootflow scan -l'.But that should be the case before this patch as well, yes?
Yes, that's right. This is just moving the code into a place where it can be used from tests.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
But it's not being used from tests, with this series.
Please see this one: 'boot: Add a new test for global bootmeths'
Yes, it calls the function, but doesn't seem to do anything with that, especially considering what the test does before these patches.
Well, it prints out the information so you can see it when running the test. Other tests show what is going on so it seemed sensible to do the same here.
I'm happy to remove this patch if you like.
Regards,
Simon
Re: [PATCH v2 05/17] boot: Move showing of bootflows out of the command
Quoted 60 lines · Simon Glass
Hi Tom,
Quoted 57 lines · Tom Rini
Quoted 55 lines · Simon Glass
Hi Tom,
Quoted 51 lines · Tom Rini
Quoted 40 lines · Simon Glass
Hi Tom,
Quoted 37 lines · Tom Rini
Quoted 35 lines · Simon Glass
Hi Tom,
Quoted 16 lines · Tom Rini
Quoted 6 lines · Simon Glass
It is helpful in tests to be able to show the bootflow that is being examined. Move
show_bootflow()into boot/ and rename it.Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v2:
- Add alog_err()for an invalid stateboot/bootflow.c | 57 ++++++++++++++++++++++++++++++++++++++ cmd/bootflow.c | 68 ++-------------------------------------------- include/bootflow.h | 9 ++++++ 3 files changed, 69 insertions(+), 65 deletions(-)Quoted 7 lines
[snip]
Review
Quoted 3 lines
(quoted diff) +3
-0+ case BOOTFLOWST_COUNT: + log_err("Unexpected boot value of bootflow error %d", + bflow->state);A small thing, checkpatch.pl catches that this isn't aligned with the '(' here as it should be.
OK. I'm unsure whether I really want this line anyway, since it increases code size.
Quoted 4 lines
A larger thing, and please correct me if I'm wrong, but on reading the whole set of changes, this move + rename just means we're putting more info in the test output, and nothing else?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
It will also appear if you have CONFIG
BOOTSTD_FULLand use 'bootflow list' or 'bootflow scan -l'.But that should be the case before this patch as well, yes?
Yes, that's right. This is just moving the code into a place where it can be used from tests.
But it's not being used from tests, with this series.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Please see this one: 'boot: Add a new test for global bootmeths'
Yes, it calls the function, but doesn't seem to do anything with that, especially considering what the test does before these patches.
Well, it prints out the information so you can see it when running the test. Other tests show what is going on so it seemed sensible to do the same here.
The flipside is that since all of the test is working testing the values of the struct it's easy to debug any failure as we'll be told field X expected value X but found Y.
Quoted 1 line
I'm happy to remove this patch if you like.
Yes, please drop this patch, thanks.
Signature · 1 line
Tom
PATCH v2 6/17 boot: Add a new test for global bootmeths
In reply to Simon GlassThese have different behaviour from normal bootmeths and we are about to enhance it. So add a test and also an extra check in bootflow_iter()
---
(no changes since v1)
test/boot/bootflow.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
test/boot/bootflow.c +45 -0
@@ -307,6 +307,8 @@ static int bootflow_iter(struct unit_test_state *uts)ut_asserteq (0 , iter.max_part);ut_asserteq_str ("extlinux" , iter.method->name);ut_asserteq (0 , bflow.err); +ut_assert (!iter.doing_global); +ut_asserteq (-1 , iter.first_glob_method);/* * This shows MEDIA even though there is none, since in
@@ -388,6 +390,49 @@ static int bootflow_iter(struct unit_test_state *uts)BOOTSTD_TEST (bootflow_iter,UTF_DM |UTF_SCAN_FDT |UTF_CONSOLE );#if defined(CONFIG_SANDBOX ) && defined(CONFIG_BOOTMETH_GLOBAL ) + +/* Check iterating through available bootflows to test global bootmeths */ +static int bootflow_iter_glob (struct unit_test_state *uts) +{ +struct bootflow_iter iter; +struct bootflow bflow; + +bootstd_clear_glob (); + +/* we should get the global bootmeth initially */ +ut_asserteq (-EINVAL , +bootflow_scan_first (NULL ,NULL , &iter,BOOTFLOWIF_ALL | +BOOTFLOWIF_SHOW , &bflow)); +bootflow_show (0 , &bflow, true); +ut_asserteq (3 , iter.num_methods); +ut_assert (iter.doing_global); +ut_asserteq (2 , iter.first_glob_method); + +ut_asserteq (2 , iter.cur_method); +ut_asserteq (0 , iter.part); +ut_asserteq (0 , iter.max_part); +ut_asserteq_str ("firmware0" , iter.method->name); +ut_asserteq (0 , bflow.err); +bootflow_free (&bflow); + +/* next we should get the first non-global bootmeth */ +ut_asserteq (-EPROTONOSUPPORT ,bootflow_scan_next (&iter, &bflow)); + +/* at this point the global bootmeths are stranded above num_methods */ +ut_asserteq (2 , iter.num_methods); +ut_asserteq (2 , iter.first_glob_method); +ut_assert (!iter.doing_global); + +ut_asserteq (0 , iter.cur_method); +ut_asserteq (0 , iter.part); +ut_asserteq (0 , iter.max_part); +ut_asserteq_str ("extlinux" , iter.method->name); +ut_asserteq (0 , bflow.err); + +return 0 ; +} +BOOTSTD_TEST (bootflow_iter_glob,UTF_DM |UTF_SCAN_FDT ); +/* Check using the system bootdev */ static int bootflow_system (struct unit_test_state *uts) {
Signature · 1 line
2.43.0
Re: [PATCH v2 06/17] boot: Add a new test for global bootmeths
Quoted 4 lines · Simon Glass
These have different behaviour from normal bootmeths and we are about to enhance it. So add a test and also an extra check in
bootflow_iter()Signed-off-by Simon Glass <[email protected]>
[snip]
Quoted 8 lines
test/boot/bootflow.c +4
-0@@ -388,6 +390,49 @@ static int bootflow_iter(struct unit_test_state *uts)BOOTSTD_TEST (bootflow_iter,UTF_DM |UTF_SCAN_FDT |UTF_CONSOLE );#if defined(CONFIG_SANDBOX ) && defined(CONFIG_BOOTMETH_GLOBAL ) + +/* Check iterating through available bootflows to test global bootmeths */ +static int bootflow_iter_glob (struct unit_test_state *uts) +{
test/boot/bootflow.c static int bootflow_iter(struct unit_test_state *uts) · line 406
Quoted 10 lines
test/boot/bootflow.c +10
-0+struct bootflow_iter iter; +struct bootflow bflow; + +bootstd_clear_glob (); + +/* we should get the global bootmeth initially */ +ut_asserteq (-EINVAL , +bootflow_scan_first (NULL ,NULL , &iter,BOOTFLOWIF_ALL | +BOOTFLOWIF_SHOW , &bflow)); +bootflow_show (0 , &bflow, true);
Here is the one call of bootflow_show outside of where show_bootflow is called today, and bootflow_show is called by the end of this series.
Quoted 14 lines
test/boot/bootflow.c +14
-0+ut_asserteq (3 , iter.num_methods); +ut_assert (iter.doing_global); +ut_asserteq (2 , iter.first_glob_method); + +ut_asserteq (2 , iter.cur_method); +ut_asserteq (0 , iter.part); +ut_asserteq (0 , iter.max_part); +ut_asserteq_str ("firmware0" , iter.method->name); +ut_asserteq (0 , bflow.err); +bootflow_free (&bflow); + +/* next we should get the first non-global bootmeth */ +ut_asserteq (-EPROTONOSUPPORT ,bootflow_scan_next (&iter, &bflow)); +
test/boot/bootflow.c static int bootflow_iter(struct unit_test_state *uts) · line 430
Quoted 10 lines
test/boot/bootflow.c +10
-0+/* at this point the global bootmeths are stranded above num_methods */ +ut_asserteq (2 , iter.num_methods); +ut_asserteq (2 , iter.first_glob_method); +ut_assert (!iter.doing_global); + +ut_asserteq (0 , iter.cur_method); +ut_asserteq (0 , iter.part); +ut_asserteq (0 , iter.max_part); +ut_asserteq_str ("extlinux" , iter.method->name); +ut_asserteq (0 , bflow.err);
Nothing in the rest of this test is checking the output of strings, and nor should it since the test is checking the struct itself to be as expected. Am I missing something? If not, I don't think we should bother with the previous patch.
Signature · 1 line
Tom
Re: [PATCH v2 06/17] boot: Add a new test for global bootmeths
Hi Tom,
Quoted 51 lines · Tom Rini
Quoted 4 lines · Simon Glass
These have different behaviour from normal bootmeths and we are about to enhance it. So add a test and also an extra check in
bootflow_iter()Signed-off-by Simon Glass <[email protected]>[snip]
Quoted 8 lines
test/boot/bootflow.c +4
-0@@ -388,6 +390,49 @@ static int bootflow_iter(struct unit_test_state *uts)BOOTSTD_TEST (bootflow_iter,UTF_DM |UTF_SCAN_FDT |UTF_CONSOLE );#if defined(CONFIG_SANDBOX ) && defined(CONFIG_BOOTMETH_GLOBAL ) + +/* Check iterating through available bootflows to test global bootmeths */ +static int bootflow_iter_glob (struct unit_test_state *uts) +{test/boot/bootflow.c static int bootflow_iter(struct unit_test_state *uts) · line 406
Quoted 10 lines
test/boot/bootflow.c +10
-0+struct bootflow_iter iter; +struct bootflow bflow; + +bootstd_clear_glob (); + +/* we should get the global bootmeth initially */ +ut_asserteq (-EINVAL , +bootflow_scan_first (NULL ,NULL , &iter,BOOTFLOWIF_ALL | +BOOTFLOWIF_SHOW , &bflow)); +bootflow_show (0 , &bflow, true);Here is the one call of
bootflow_showoutside of whereshow_bootflowis called today, andbootflow_showis called by the end of this series.Quoted 21 lines
test/boot/bootflow.c +21
-0+ut_asserteq (3 , iter.num_methods); +ut_assert (iter.doing_global); +ut_asserteq (2 , iter.first_glob_method); + +ut_asserteq (2 , iter.cur_method); +ut_asserteq (0 , iter.part); +ut_asserteq (0 , iter.max_part); +ut_asserteq_str ("firmware0" , iter.method->name); +ut_asserteq (0 , bflow.err); +bootflow_free (&bflow); + +/* next we should get the first non-global bootmeth */ +ut_asserteq (-EPROTONOSUPPORT ,bootflow_scan_next (&iter, &bflow)); + +/* at this point the global bootmeths are stranded above num_methods */ +ut_asserteq (2 , iter.num_methods); +ut_asserteq (2 , iter.first_glob_method); +ut_assert (!iter.doing_global); + +ut_asserteq (0 , iter.cur_method); +ut_asserteq (0 , iter.part);
Quoted 8 lines
test/boot/bootflow.c static int bootflow_iter(struct unit_test_state *uts) · line 430
Quoted 3 lines
test/boot/bootflow.c +3
-0+ut_asserteq (0 , iter.max_part); +ut_asserteq_str ("extlinux" , iter.method->name); +ut_asserteq (0 , bflow.err);Nothing in the rest of this test is checking the output of strings, and nor should it since the test is checking the struct itself to be as expected. Am I missing something? If not, I don't think we should bother with the previous patch.
You're missing that when the test fails you need to try to figure out why...it is much easier to do that if it prints out info on the bootflow. In my case it was printing a completely different one.
I'm happy to remove that line (and the patch) if you like.
Regards,
Simon
Re: [PATCH v2 06/17] boot: Add a new test for global bootmeths
Quoted 63 lines · Simon Glass
Hi Tom,
Quoted 51 lines · Tom Rini
Quoted 4 lines · Simon Glass
These have different behaviour from normal bootmeths and we are about to enhance it. So add a test and also an extra check in
bootflow_iter()Signed-off-by Simon Glass <[email protected]>[snip]
Quoted 8 lines
test/boot/bootflow.c +4
-0@@ -388,6 +390,49 @@ static int bootflow_iter(struct unit_test_state *uts)BOOTSTD_TEST (bootflow_iter,UTF_DM |UTF_SCAN_FDT |UTF_CONSOLE );#if defined(CONFIG_SANDBOX ) && defined(CONFIG_BOOTMETH_GLOBAL ) + +/* Check iterating through available bootflows to test global bootmeths */ +static int bootflow_iter_glob (struct unit_test_state *uts) +{test/boot/bootflow.c static int bootflow_iter(struct unit_test_state *uts) · line 406
Quoted 10 lines
test/boot/bootflow.c +10
-0+struct bootflow_iter iter; +struct bootflow bflow; + +bootstd_clear_glob (); + +/* we should get the global bootmeth initially */ +ut_asserteq (-EINVAL , +bootflow_scan_first (NULL ,NULL , &iter,BOOTFLOWIF_ALL | +BOOTFLOWIF_SHOW , &bflow)); +bootflow_show (0 , &bflow, true);Here is the one call of
bootflow_showoutside of whereshow_bootflowis called today, andbootflow_showis called by the end of this series.Quoted 21 lines
test/boot/bootflow.c +21
-0+ut_asserteq (3 , iter.num_methods); +ut_assert (iter.doing_global); +ut_asserteq (2 , iter.first_glob_method); + +ut_asserteq (2 , iter.cur_method); +ut_asserteq (0 , iter.part); +ut_asserteq (0 , iter.max_part); +ut_asserteq_str ("firmware0" , iter.method->name); +ut_asserteq (0 , bflow.err); +bootflow_free (&bflow); + +/* next we should get the first non-global bootmeth */ +ut_asserteq (-EPROTONOSUPPORT ,bootflow_scan_next (&iter, &bflow)); + +/* at this point the global bootmeths are stranded above num_methods */ +ut_asserteq (2 , iter.num_methods); +ut_asserteq (2 , iter.first_glob_method); +ut_assert (!iter.doing_global); + +ut_asserteq (0 , iter.cur_method); +ut_asserteq (0 , iter.part);Quoted 8 lines
test/boot/bootflow.c static int bootflow_iter(struct unit_test_state *uts) · line 430
Quoted 3 lines
test/boot/bootflow.c +3
-0+ut_asserteq (0 , iter.max_part); +ut_asserteq_str ("extlinux" , iter.method->name); +ut_asserteq (0 , bflow.err);Nothing in the rest of this test is checking the output of strings, and nor should it since the test is checking the struct itself to be as expected. Am I missing something? If not, I don't think we should bother with the previous patch.
Quoted 3 lines
You're missing that when the test fails you need to try to figure out why...it is much easier to do that if it prints out info on the bootflow. In my case it was printing a completely different one.
I want to come back to this for a moment, because (along with a few other parts of this series) it shows the hard question of:
- After debugging a problem, how much logging / debug statements should remain?
More comments are always good. There's no size cost, there's no run time cost and it helps everyone who comes along later understand the code better.
Given that CONFIG_LOG isn't usually enabled, on the one hand log_debug should be fine as that should be compile-time optimized out. On the other hand, is that information that we should have available already? Do we need a debug statement about returning -EFOO vs the caller(s) printing "got %d as ret" ?
And then it's also a question of "will anyone use this again? Is the churn to git blame for adding '{' here worth it?"
I often lean towards the last question being answered with "No" and so just making sure comments are correct. That also means not keeping in things like show_bootflow being a public function now even if I had exposed it as a quick "what does this number mean again?".
Signature · 1 line
Tom
Re: [PATCH v2 06/17] boot: Add a new test for global bootmeths
Hi Tom,
Quoted 85 lines · Tom Rini
Quoted 63 lines · Simon Glass
Hi Tom,
Quoted 51 lines · Tom Rini
Quoted 4 lines · Simon Glass
These have different behaviour from normal bootmeths and we are about to enhance it. So add a test and also an extra check in
bootflow_iter()Signed-off-by Simon Glass <[email protected]>[snip]
Quoted 8 lines
test/boot/bootflow.c +4
-0@@ -388,6 +390,49 @@ static int bootflow_iter(struct unit_test_state *uts)BOOTSTD_TEST (bootflow_iter,UTF_DM |UTF_SCAN_FDT |UTF_CONSOLE );#if defined(CONFIG_SANDBOX ) && defined(CONFIG_BOOTMETH_GLOBAL ) + +/* Check iterating through available bootflows to test global bootmeths */ +static int bootflow_iter_glob (struct unit_test_state *uts) +{test/boot/bootflow.c static int bootflow_iter(struct unit_test_state *uts) · line 406
Quoted 10 lines
test/boot/bootflow.c +10
-0+struct bootflow_iter iter; +struct bootflow bflow; + +bootstd_clear_glob (); + +/* we should get the global bootmeth initially */ +ut_asserteq (-EINVAL , +bootflow_scan_first (NULL ,NULL , &iter,BOOTFLOWIF_ALL | +BOOTFLOWIF_SHOW , &bflow)); +bootflow_show (0 , &bflow, true);Here is the one call of
bootflow_showoutside of whereshow_bootflowis called today, andbootflow_showis called by the end of this series.Quoted 21 lines
test/boot/bootflow.c +21
-0+ut_asserteq (3 , iter.num_methods); +ut_assert (iter.doing_global); +ut_asserteq (2 , iter.first_glob_method); + +ut_asserteq (2 , iter.cur_method); +ut_asserteq (0 , iter.part); +ut_asserteq (0 , iter.max_part); +ut_asserteq_str ("firmware0" , iter.method->name); +ut_asserteq (0 , bflow.err); +bootflow_free (&bflow); + +/* next we should get the first non-global bootmeth */ +ut_asserteq (-EPROTONOSUPPORT ,bootflow_scan_next (&iter, &bflow)); + +/* at this point the global bootmeths are stranded above num_methods */ +ut_asserteq (2 , iter.num_methods); +ut_asserteq (2 , iter.first_glob_method); +ut_assert (!iter.doing_global); + +ut_asserteq (0 , iter.cur_method); +ut_asserteq (0 , iter.part);Quoted 8 lines
test/boot/bootflow.c static int bootflow_iter(struct unit_test_state *uts) · line 430
Quoted 3 lines
test/boot/bootflow.c +3
-0+ut_asserteq (0 , iter.max_part); +ut_asserteq_str ("extlinux" , iter.method->name); +ut_asserteq (0 , bflow.err);Nothing in the rest of this test is checking the output of strings, and nor should it since the test is checking the struct itself to be as expected. Am I missing something? If not, I don't think we should bother with the previous patch.
Quoted 3 lines
You're missing that when the test fails you need to try to figure out why...it is much easier to do that if it prints out info on the bootflow. In my case it was printing a completely different one.
I want to come back to this for a moment, because (along with a few other parts of this series) it shows the hard question of:
- After debugging a problem, how much logging / debug statements should remain?
More comments are always good. There's no size cost, there's no run time cost and it helps everyone who comes along later understand the code better.
Given that
CONFIG_LOGisn't usually enabled, on the one handlog_debugshould be fine as that should be compile-time optimized out. On the other hand, is that information that we should have available already? Do we need a debug statement about returning-EFOOvs the caller(s) printing "got %d as ret" ?
Quoted 7 lines
And then it's also a question of "will anyone use this again? Is the churn to git blame for adding '{' here worth it?"
I often lean towards the last question being answered with "No" and so just making sure comments are correct. That also means not keeping in things like
show_bootflowbeing a public function now even if I had exposed it as a quick "what does this number mean again?".
The best initial debugging aid I have with bootstd etc. is to enable CONFIG_LOG_ERROR_RETURN since it shows a trace of where things happened. It doesn't have a code cost unless it is enabled.
For myself, I do like adding things like show_bootflow() in tests. It is so much easier to understand what is going wrong when you can pass -v and see the test output.
Regards,
Simon
PATCH v2 7/17 boot: Update first_glob_method when dropping a bootmeth
In reply to Simon GlassFor now we only support dropping non-global bootmeths from the iteration. Update first_glob_method in that case and add a few checks that things are correct.
---
(no changes since v1)
boot/bootflow.c | 6 ++++++ test/boot/bootflow.c | 8 ++++++++ 2 files changed, 14 insertions(+)
boot/bootflow.c +6 -0
@@ -167,11 +167,17 @@ int bootflow_iter_drop_bootmeth(struct bootflow_iter *iter, iter->method_order[iter->cur_method] != bmeth) return -EINVAL; +log_debug ("Dropping bootmeth '%s'\n" , bmeth->name); +memmove (&iter->method_order[iter->cur_method], &iter->method_order[iter->cur_method +1 ], (iter->num_methods - iter->cur_method -1 ) *sizeof (void *)); iter->num_methods--; +if (iter->first_glob_method >0 ) { + iter->first_glob_method--; +log_debug ("first_glob_method %d\n" , iter->first_glob_method); + }return 0 ; }
test/boot/bootflow.c +8 -0
@@ -483,7 +483,11 @@ static int bootflow_iter_disable(struct unit_test_state *uts)/* Try to boot the bootmgr flow, which will fail */ console_record_reset_enable ();ut_assertok (bootflow_scan_first (NULL ,NULL , &iter,0 , &bflow)); + +/* at this point the global bootmeths are stranded above num_methods */ ut_asserteq (3 , iter.num_methods); +ut_assert (!iter.doing_global); +ut_asserteq (3 , iter.first_glob_method);ut_asserteq_str ("sandbox" , iter.method->name);ut_assertok (inject_response (uts));ut_asserteq (-ENOTSUPP ,bootflow_run_boot (&iter, &bflow));
@@ -493,9 +497,13 @@ static int bootflow_iter_disable(struct unit_test_state *uts)/* Check that the sandbox bootmeth has been removed */ ut_asserteq (2 , iter.num_methods); +for (i =0 ; i < iter.num_methods; i++)ut_assert (strcmp ("sandbox" , iter.method_order[i]->name)); +/* the first global bootmeth is now down one place in the list */ +ut_asserteq (2 , iter.first_glob_method); +return 0 ; }BOOTSTD_TEST (bootflow_iter_disable,UTF_DM |UTF_SCAN_FDT |UTF_CONSOLE );
Signature · 1 line
2.43.0
PATCH v2 8/17 boot: Add a flag for whether there are global bootmeths
In reply to Simon GlassThe current 'doing_global' refers to being in the state of processing global bootmeths. Since global bootmeths are currently used once at the start, it becomes false once the last global bootmeth has been used.
In preparation for allowing bootmeths to run at other points in the bootstd interation, add a new 'have_global' flag which tracks whether there are any global bootmeths in the method_order[] list. It is set up when iteration starts. Unlike doing_global which resets back to false after the global bootmeths have been handled, once have_global is set to true, it remains true for the entire iteration process. This provides a quick check as to whether global-bootmeth processing is needed.
---
(no changes since v1)
boot/bootmeth-uclass.c | 1 + include/bootflow.h | 2 ++ test/boot/bootflow.c | 4 ++++ 3 files changed, 7 insertions(+)
boot/bootmeth-uclass.c +1 -0
@@ -208,6 +208,7 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) iter->first_glob_method != -1 && iter->first_glob_method != count) { iter->cur_method = iter->first_glob_method; iter->doing_global = true; + iter->have_global = true; } iter->method_order = order; iter->num_methods = count;
include/bootflow.h +2 -0
@@ -255,6 +255,7 @@ enum bootflow_meth_flags_t {* @cur_prio: Current priority being scanned * @method_order: List of bootmeth devices to use, in order. The normal methods * appear first, then the global ones, if any +* @have_global: true if we have global bootmeths in @method_order[] * @doing_global: true if we are iterating through the global bootmeths (which * happens before the normal ones) * @method_flags: flags controlling which methods should be used for this @dev
@@ -278,6 +279,7 @@ struct bootflow_iter {int first_glob_method;enum bootdev_prio_t cur_prio;struct udevice **method_order; +bool have_global;bool doing_global;int method_flags; };
test/boot/bootflow.c +4 -0
@@ -308,6 +308,7 @@ static int bootflow_iter(struct unit_test_state *uts)ut_asserteq_str ("extlinux" , iter.method->name);ut_asserteq (0 , bflow.err);ut_assert (!iter.doing_global); +ut_assert (!iter.have_global);ut_asserteq (-1 , iter.first_glob_method);/*
@@ -406,6 +407,7 @@ static int bootflow_iter_glob(struct unit_test_state *uts)bootflow_show (0 , &bflow, true);ut_asserteq (3 , iter.num_methods);ut_assert (iter.doing_global); +ut_assert (iter.have_global);ut_asserteq (2 , iter.first_glob_method);ut_asserteq (2 , iter.cur_method);
@@ -422,6 +424,7 @@ static int bootflow_iter_glob(struct unit_test_state *uts)ut_asserteq (2 , iter.num_methods);ut_asserteq (2 , iter.first_glob_method);ut_assert (!iter.doing_global); +ut_assert (iter.have_global);ut_asserteq (0 , iter.cur_method);ut_asserteq (0 , iter.part);
@@ -487,6 +490,7 @@ static int bootflow_iter_disable(struct unit_test_state *uts)/* at this point the global bootmeths are stranded above num_methods */ ut_asserteq (3 , iter.num_methods);ut_assert (!iter.doing_global); +ut_assert (iter.have_global);ut_asserteq (3 , iter.first_glob_method);ut_asserteq_str ("sandbox" , iter.method->name);ut_assertok (inject_response (uts));
Signature · 1 line
2.43.0
PATCH v2 9/17 boot: Keep track of which bootmeths have been used
In reply to Simon GlassAdd a bitfield which tracks when bootmeths have been used. This will be needed when global bootmeths can be used later in the iteration.
Fix a missing bootflow_free() while here.
---
(no changes since v1)
boot/bootflow.c | 13 +++++++++++++ boot/bootmeth-uclass.c | 10 ++++++++++ include/bootflow.h | 10 +++++++++- test/boot/bootflow.c | 8 +++++++- 4 files changed, 39 insertions(+), 2 deletions(-)
boot/bootflow.c +13 -0
@@ -18,6 +18,10 @@#include <dm/device-internal.h> #include <dm/uclass-internal.h> +/* ensure BOOTMETH_MAX_COUNT fits in method_flags field */ +static_assert (BOOTMETH_MAX_COUNT <= + (sizeof (((struct bootflow_iter *)NULL )->method_flags) *8 )); +/* error codes used to signal running out of things */ enum {BF_NO_MORE_PARTS = -ESHUTDOWN ,
@@ -489,6 +493,10 @@ int bootflow_scan_first(struct udevice *dev, const char *label,bootflow_iter_set_dev (iter, dev, method_flags); } +if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL )) { + iter->methods_done |=BIT (iter->cur_method); +log_debug ("methods_done now %x\n" , iter->cur_method); + } ret =bootflow_check (iter, bflow);if (ret) {log_debug ("check - ret=%d\n" , ret);
@@ -516,6 +524,11 @@ int bootflow_scan_next(struct bootflow_iter *iter, struct bootflow *bflow)return log_msg_ret ("done" , ret);if (!ret) { +if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL )) { + iter->methods_done |=BIT (iter->cur_method); +log_debug ("methods_done now %x\n" , + iter->cur_method); + } ret =bootflow_check (iter, bflow);log_debug ("check - ret=%d\n" , ret);if (!ret)
boot/bootmeth-uclass.c +10 -0
@@ -210,6 +210,16 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) iter->doing_global = true; iter->have_global = true; } + +/* +* check we don't exceed the maximum bits in methods_done when tracking +* which global bootmeths have run +*/ +if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && count >BOOTMETH_MAX_COUNT ) { +free (order); +return log_msg_ret ("tmb" , -ENOSPC ); + } + iter->method_order = order; iter->num_methods = count;
include/bootflow.h +9 -1
@@ -11,7 +11,8 @@#include <bootdev.h> #include <image.h> #include <dm/ofnode_decl.h> -#include <linux/types.h> +#include <linux/list.h> +#include <linux/build_bug.h> struct bootstd_priv ;struct expo ;
@@ -213,6 +214,10 @@ enum bootflow_meth_flags_t { BOOTFLOW_METHF_SINGLE_UCLASS = 1 << 3, }; +enum { +BOOTMETH_MAX_COUNT =32 , +}; +/** * struct bootflow_iter - state for iterating through bootflows *
@@ -260,6 +265,8 @@ enum bootflow_meth_flags_t {* happens before the normal ones) * @method_flags: flags controlling which methods should be used for this @dev * (enum bootflow_meth_flags_t) +* @methods_done: indicates which methods have been processed, one bit for +* each method in @method_order[] */ struct bootflow_iter {int flags;
@@ -282,6 +289,7 @@ struct bootflow_iter {bool have_global;bool doing_global;int method_flags; +uint methods_done; };/**
test/boot/bootflow.c +7 -1
@@ -310,6 +310,7 @@ static int bootflow_iter(struct unit_test_state *uts)ut_assert (!iter.doing_global);ut_assert (!iter.have_global);ut_asserteq (-1 , iter.first_glob_method); +ut_asserteq (BIT (0 ), iter.methods_done);/* * This shows MEDIA even though there is none, since in
@@ -318,6 +319,7 @@ static int bootflow_iter(struct unit_test_state *uts)* know. */ ut_asserteq (BOOTFLOWST_MEDIA , bflow.state); +bootflow_free (&bflow);ut_asserteq (-EPROTONOSUPPORT ,bootflow_scan_next (&iter, &bflow));ut_asserteq (2 , iter.num_methods);
@@ -327,6 +329,7 @@ static int bootflow_iter(struct unit_test_state *uts)ut_asserteq_str ("efi" , iter.method->name);ut_asserteq (0 , bflow.err);ut_asserteq (BOOTFLOWST_MEDIA , bflow.state); +ut_asserteq (BIT (0 ) |BIT (1 ), iter.methods_done);bootflow_free (&bflow);/* The next device is mmc1.bootdev - at first we use the whole device */
@@ -338,6 +341,7 @@ static int bootflow_iter(struct unit_test_state *uts)ut_asserteq_str ("extlinux" , iter.method->name);ut_asserteq (0 , bflow.err);ut_asserteq (BOOTFLOWST_MEDIA , bflow.state); +ut_asserteq (BIT (0 ) |BIT (1 ), iter.methods_done);bootflow_free (&bflow);ut_asserteq (-ENOENT ,bootflow_scan_next (&iter, &bflow));
@@ -348,9 +352,10 @@ static int bootflow_iter(struct unit_test_state *uts)ut_asserteq_str ("efi" , iter.method->name);ut_asserteq (0 , bflow.err);ut_asserteq (BOOTFLOWST_MEDIA , bflow.state); +ut_asserteq (BIT (0 ) |BIT (1 ), iter.methods_done);bootflow_free (&bflow); -/* Then more to partition 1 where we find something */ +/* Then move to partition 1 where we find something */ ut_assertok (bootflow_scan_next (&iter, &bflow));ut_asserteq (2 , iter.num_methods);ut_asserteq (0 , iter.cur_method);
@@ -380,6 +385,7 @@ static int bootflow_iter(struct unit_test_state *uts)ut_asserteq_str ("extlinux" , iter.method->name);ut_asserteq (0 , bflow.err);ut_asserteq (BOOTFLOWST_MEDIA , bflow.state); +ut_asserteq (BIT (0 ) |BIT (1 ), iter.methods_done);bootflow_free (&bflow);bootflow_iter_uninit (&iter);
Signature · 1 line
2.43.0
PATCH v2 10/17 boot: Move preparing bootdev into a function
In reply to Simon GlassThe code at the end of iter_inc() is already somewhat tortuous. Before making it worse, move it into a function.
---
(no changes since v1)
boot/bootflow.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-)
boot/bootflow.c +29 -11
@@ -245,6 +245,32 @@ static void scan_next_in_uclass(struct udevice **devp) *devp = dev; } +/** +* prepare_bootdev() - Get ready to use a bootdev +* +* @iter: Bootflow iterator being used +* @dev: UCLASS_BOOTDEV device to use +* @method_flags: Method flag for the bootdev +* Return 0 if OK, -ve if the bootdev failed to probe +*/ +static int prepare_bootdev (struct bootflow_iter *iter,struct udevice *dev, +int method_flags) +{ +int ret; + +/* +* Probe the bootdev. This does not probe any attached block device, +* since they are siblings +*/ + ret =device_probe (dev); +log_debug ("probe %s %d\n" , dev->name, ret); +if (ret) +return log_msg_ret ("probe" , ret); +bootflow_iter_set_dev (iter, dev, method_flags); + +return 0 ; +} +/** * iter_incr() - Move to the next item (method, part, bootdev) *
@@ -387,18 +413,10 @@ static int iter_incr(struct bootflow_iter *iter) }log_debug ("ret=%d, dev=%p %s\n" , ret, dev, dev ? dev->name :"none" ); -if (ret) { +if (ret)bootflow_iter_set_dev (iter,NULL ,0 ); - }else { -/* -* Probe the bootdev. This does not probe any attached -* block device, since they are siblings -*/ - ret =device_probe (dev); -log_debug ("probe %s %d\n" , dev->name, ret); -if (!log_msg_ret ("probe" , ret)) -bootflow_iter_set_dev (iter, dev, method_flags); - } +else + ret =prepare_bootdev (iter, dev, method_flags); }/* if there are no more bootdevs, give up */
Signature · 1 line
2.43.0
PATCH v2 11/17 boot: Support rescanning the global bootmeths
In reply to Simon GlassAdd the logic to scan through the global bootmeths for every new bootdev, in preparation for allowing global bootmeths to select where in the hunter ordering they go.
Use a new bootmeth_glob_allowed() function to check if a bootmeth is allowed, ensuring that each can run at most once.
For now this has no actual effect, since the global bootmeths are unconditionally processed at the start, with iter->methods_done being updated to include all of them. Therefore when scanning again, no unprocessed global bootmeths will be found.
---
(no changes since v1)
boot/bootflow.c | 90 ++++++++++++++++++++++++++++++++++++++++++++-- include/bootflow.h | 5 +++ 2 files changed, 93 insertions(+), 2 deletions(-)
boot/bootflow.c +88 -2
@@ -245,19 +245,81 @@ static void scan_next_in_uclass(struct udevice **devp) *devp = dev; } +/** +* bootmeth_glob_allowed() - Check if a global bootmeth is usable at this point +* +* @iter: Bootflow iterator being used +* Return: true if the global bootmeth has not already been used +*/ +static bool bootmeth_glob_allowed (struct bootflow_iter *iter,int meth_seq) +{ +struct udevice *meth = iter->method_order[meth_seq]; +bool done = iter->methods_done &BIT (meth_seq); + +log_debug ("considering glob '%s': done %d\n" , meth->name, done); + +/* if this one has already been used, try the next */ +if (done) +return false; + +return true; +} + +/** +* next_glob_bootmeth() - Find the next global bootmeth to use +* +* Scans the global bootmeths to find the first unused one whose priority has +* been reached. If found, iter->cur_method and iter->method are set up and +* doing_global is set to true +* +* @iter: Bootflow iterator being used +* Return 0 if found, -ENOENT if no more global bootmeths are available +*/ +static int next_glob_bootmeth (struct bootflow_iter *iter) +{ +log_debug ("rescan global bootmeths have_global %d\n" , + iter->have_global); +if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && iter->have_global) { +int i; + +/* rescan the global bootmeths */ +log_debug ("first_glob_method %d num_methods %d methods_done %x\n" , + iter->first_glob_method, iter->num_methods, + iter->methods_done); +for (i = iter->first_glob_method; i < iter->num_methods; i++) { +if (bootmeth_glob_allowed (iter, i)) { + iter->cur_method = i; + iter->method = iter->method_order[i]; + iter->doing_global = true; + iter->dev =NULL ; +return 0 ; + } + } + } + +return -ENOENT ; +} +/** * prepare_bootdev() - Get ready to use a bootdev * * @iter: Bootflow iterator being used * @dev: UCLASS_BOOTDEV device to use * @method_flags: Method flag for the bootdev +* @check_global: true to check global bootmeths before processing @dev * Return 0 if OK, -ve if the bootdev failed to probe */ static int prepare_bootdev (struct bootflow_iter *iter,struct udevice *dev, -int method_flags) +int method_flags,bool check_global) {int ret; +if (check_global && !next_glob_bootmeth (iter)) { + iter->pending_bootdev = dev; + iter->pending_method_flags = method_flags; +return 0 ; + } +/* * Probe the bootdev. This does not probe any attached block device, * since they are siblings
@@ -308,6 +370,30 @@ static int iter_incr(struct bootflow_iter *iter) iter->num_methods = iter->first_glob_method; iter->doing_global = false; +/* +* we've come to the end, so see if we should use a pending +* bootdev from when we decided to rescan the global bootmeths +*/ +if (iter->pending_bootdev) { +int meth_flags = iter->pending_method_flags; + + dev = iter->pending_bootdev; + iter->pending_bootdev =NULL ; + iter->pending_method_flags =0 ; + + ret =prepare_bootdev (iter, dev, meth_flags, false); +if (ret) +return log_msg_ret ("ipb" , ret); + + iter->cur_method =0 ; + iter->method = iter->method_order[iter->cur_method]; + +log_debug ("-> using pending bootdev '%s' method '%s'\n" , + dev->name, iter->method->name); + +return 0 ; + } +/* * Don't move to the next dev as we haven't tried this * one yet!
@@ -416,7 +502,7 @@ static int iter_incr(struct bootflow_iter *iter)if (ret)bootflow_iter_set_dev (iter,NULL ,0 );else - ret =prepare_bootdev (iter, dev, method_flags); + ret =prepare_bootdev (iter, dev, method_flags, true); }/* if there are no more bootdevs, give up */
include/bootflow.h +5 -0
@@ -267,6 +267,9 @@ enum {* (enum bootflow_meth_flags_t) * @methods_done: indicates which methods have been processed, one bit for * each method in @method_order[] +* @pending_bootdev: if non-NULL, bootdev which will be used when the global +* bootmeths are done +* @pending_method_flags: method flags which will be used with @pending_bootdev */ struct bootflow_iter {int flags;
@@ -290,6 +293,8 @@ struct bootflow_iter {bool doing_global;int method_flags;uint methods_done; +struct udevice *pending_bootdev; +int pending_method_flags; };/**
Signature · 1 line
2.43.0
PATCH v2 12/17 boot: Only run global bootmeths once each
In reply to Simon GlassUse the methods_done flags to make sure that each global bootmeth is only used once. For now this has no effect, since they are all processed at the start.
---
(no changes since v1)
boot/bootflow.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
boot/bootflow.c +7 -1
@@ -354,7 +354,13 @@ static int iter_incr(struct bootflow_iter *iter) }/* Get the next boothmethod */ -if (++iter->cur_method < iter->num_methods) { +for (iter->cur_method++; iter->cur_method < iter->num_methods; + iter->cur_method++) { +/* loop until we find a global bootmeth we haven't used */ +if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && iter->doing_global && + !bootmeth_glob_allowed (iter, iter->cur_method)) +continue ; + iter->method = iter->method_order[iter->cur_method];log_debug ("-> next method '%s'\n" , iter->method->name);return 0 ;
Signature · 1 line
2.43.0
PATCH v2 13/17 boot: Implement a priority for global bootmeths
In reply to Simon GlassAllow bootmeths to select when they want to run, using the bootdev priority. Provide a new bootmeth_glob_allowed() function which checks if a bootmeth is ready to use.
Fix a comment in bootflow_system() which is a test for global bootmeths.
---
(no changes since v1)
boot/bootflow.c | 15 +++++++++++---- include/bootflow.h | 2 +- include/bootmeth.h | 4 ++++ 3 files changed, 16 insertions(+), 5 deletions(-)
boot/bootflow.c +11 -4
@@ -249,17 +249,24 @@ static void scan_next_in_uclass(struct udevice **devp)* bootmeth_glob_allowed() - Check if a global bootmeth is usable at this point * * @iter: Bootflow iterator being used -* Return: true if the global bootmeth has not already been used +* Return: true if the global bootmeth has a suitable priority and has not +* already been used */ static bool bootmeth_glob_allowed (struct bootflow_iter *iter,int meth_seq) {struct udevice *meth = iter->method_order[meth_seq];bool done = iter->methods_done &BIT (meth_seq); +struct bootmeth_uc_plat *ucp; -log_debug ("considering glob '%s': done %d\n" , meth->name, done); + ucp =dev_get_uclass_plat (meth); +log_debug ("considering glob '%s': done %d glob_prio %d\n" , meth->name, + done, ucp->glob_prio); -/* if this one has already been used, try the next */ -if (done) +/* +* if this one has already been used, or its priority is too low, try +* the next +*/ +if (done || ucp->glob_prio > iter->cur_prio)return false;return true;
include/bootflow.h +1 -1
@@ -262,7 +262,7 @@ enum {* appear first, then the global ones, if any * @have_global: true if we have global bootmeths in @method_order[] * @doing_global: true if we are iterating through the global bootmeths (which -* happens before the normal ones) +* generally happens before the normal ones) * @method_flags: flags controlling which methods should be used for this @dev * (enum bootflow_meth_flags_t) * @methods_done: indicates which methods have been processed, one bit for
include/bootmeth.h +4 -0
@@ -30,10 +30,14 @@ enum bootmeth_flags {* * @desc: A long description of the bootmeth * @flags: Flags for this bootmeth (enum bootmeth_flags) +* @glob_prio: Priority for this bootmeth. If unset (0) the bootmeth is started +* before all other bootmeths. Otherwise it is started before the iteration +* reaches the given priority. */ struct bootmeth_uc_plat {const char *desc;int flags; +enum bootdev_prio_t glob_prio; };/** struct bootmeth_ops - Operations for boot methods */
Signature · 1 line
2.43.0
PATCH v2 14/17 boot: Don't change the method count after global bootmeths
In reply to Simon GlassAt present before scanning global bootmeths, the iterator sets the method count to the index of the first global bootmeth. Now that we support scanning the global bootmeths multiple times, we must leave this count alone.
Check against have_global and first_glob_method instead.
---
(no changes since v1)
boot/bootflow.c | 18 ++++++++++++++---- test/boot/bootflow.c | 6 +++--- 2 files changed, 17 insertions(+), 7 deletions(-)
boot/bootflow.c +14 -4
@@ -364,9 +364,20 @@ static int iter_incr(struct bootflow_iter *iter)for (iter->cur_method++; iter->cur_method < iter->num_methods; iter->cur_method++) {/* loop until we find a global bootmeth we haven't used */ -if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && iter->doing_global && - !bootmeth_glob_allowed (iter, iter->cur_method)) -continue ; +if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && iter->doing_global) { +if (!bootmeth_glob_allowed (iter, iter->cur_method)) +continue ; + + iter->method = iter->method_order[iter->cur_method]; +log_debug ("-> next global method '%s'\n" , + iter->method->name); +return 0 ; + } + +/* at this point we are only considering non-global bootmeths */ +if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && iter->have_global && + iter->cur_method >= iter->first_glob_method) +break ; iter->method = iter->method_order[iter->cur_method];log_debug ("-> next method '%s'\n" , iter->method->name);
@@ -380,7 +391,6 @@ static int iter_incr(struct bootflow_iter *iter)* normal bootdev scan */ if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && global) { - iter->num_methods = iter->first_glob_method; iter->doing_global = false;/*
test/boot/bootflow.c +3 -3
@@ -427,7 +427,7 @@ static int bootflow_iter_glob(struct unit_test_state *uts)ut_asserteq (-EPROTONOSUPPORT ,bootflow_scan_next (&iter, &bflow));/* at this point the global bootmeths are stranded above num_methods */ -ut_asserteq (2 , iter.num_methods); +ut_asserteq (3 , iter.num_methods);ut_asserteq (2 , iter.first_glob_method);ut_assert (!iter.doing_global);ut_assert (iter.have_global);
@@ -494,7 +494,7 @@ static int bootflow_iter_disable(struct unit_test_state *uts)ut_assertok (bootflow_scan_first (NULL ,NULL , &iter,0 , &bflow));/* at this point the global bootmeths are stranded above num_methods */ -ut_asserteq (3 , iter.num_methods); +ut_asserteq (4 , iter.num_methods);ut_assert (!iter.doing_global);ut_assert (iter.have_global);ut_asserteq (3 , iter.first_glob_method);
@@ -506,7 +506,7 @@ static int bootflow_iter_disable(struct unit_test_state *uts)ut_assert_console_end ();/* Check that the sandbox bootmeth has been removed */ -ut_asserteq (2 , iter.num_methods); +ut_asserteq (3 , iter.num_methods);for (i =0 ; i < iter.num_methods; i++)ut_assert (strcmp ("sandbox" , iter.method_order[i]->name));
Signature · 1 line
2.43.0
PATCH v2 15/17 boot: Run global bootmeths after all bootdevs are exhausted
In reply to Simon GlassWhen there are no more bootdevs we should still go through the global bootmeths, since some may not have yet been used, if their priority has not yet come up.
Add a final check for this at the end of the iterator.
---
(no changes since v1)
boot/bootflow.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
boot/bootflow.c +23 -0
@@ -417,6 +417,18 @@ static int iter_incr(struct bootflow_iter *iter)return 0 ; } +/* if this was the final global bootmeth check, we are done */ +if (iter->cur_prio ==BOOTDEVP_COUNT ) { +log_debug ("-> done global bootmeths\n" ); + +/* print the same message as bootflow_iter_set_dev() */ +if ((iter->flags & (BOOTFLOWIF_SHOW | +BOOTFLOWIF_SINGLE_DEV )) == +BOOTFLOWIF_SHOW ) +printf ("No more bootdevs\n" ); +return BF_NO_MORE_DEVICES ; + } +/* * Don't move to the next dev as we haven't tried this * one yet!
@@ -528,6 +540,17 @@ static int iter_incr(struct bootflow_iter *iter) ret =prepare_bootdev (iter, dev, method_flags, true); } +if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) && ret) { +log_debug ("no more bootdevs, trying global\n" ); + +/* allow global bootmeths with any priority */ + iter->cur_prio =BOOTDEVP_COUNT ; +if (!next_glob_bootmeth (iter)) { +log_debug ("-> next method '%s'\n" , iter->method->name); +return 0 ; + } + } +/* if there are no more bootdevs, give up */ if (ret) {log_debug ("-> no more bootdevs\n" );
Signature · 1 line
2.43.0
PATCH v2 16/17 boot: Run the EFI bootmgr just before network devices
In reply to Simon GlassAt present the EFI bootmgr scans all devices in the system before deciding which one to boot. Ideally it would use the bootstd iterator for this, but in the meantime, give it a lower priority, so it runs just before the network devices.
Note that if there are no hunted network devices hunted, then it will run at the end, after all bootdevs are exhausted. In other words, it will always run.
---
Changes in v2:
- Update commit message to indicate the bootmeth will always run
- Document how the priority was chosen
boot/bootmeth_efi_mgr.c | 9 +++++++++ test/boot/bootflow.c | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-)
boot/bootmeth_efi_mgr.c +9 -0
@@ -99,6 +99,15 @@ static int bootmeth_efi_mgr_bind(struct udevice *dev) plat->desc ="EFI bootmgr flow" ; plat->flags =BOOTMETHF_GLOBAL ; +/* +* bootmgr scans all available devices which can take a while, +* especially for network devices. So choose the priority so that it +* comes just before the 'very slow' devices. This allows systems which +* don't rely on bootmgr to boot quickly, while allowing bootmgr to run +* on systems which need it. +*/ + plat->glob_prio =BOOTDEVP_6_NET_BASE ; +return 0 ; }
test/boot/bootflow.c +2 -2
@@ -455,11 +455,11 @@ static int bootflow_system(struct unit_test_state *uts)ut_assertok (device_probe (dev));sandbox_set_fake_efi_mgr_dev (dev, true); -/* We should get a single 'bootmgr' method at the start */ +/* We should get a single 'bootmgr' method at the end */ bootstd_clear_glob ();ut_assertok (run_command ("bootflow scan -lH" ,0 ));ut_assert_skip_to_line ( -" 0 efi_mgr ready (none) 0 <NULL> " ); +" 1 efi_mgr ready (none) 0 <NULL> " );ut_assert_skip_to_line ("No more bootdevs" );ut_assert_skip_to_line ("(2 bootflows, 2 valid)" );ut_assert_console_end ();
Signature · 1 line
2.43.0
Re: [PATCH v2 16/17] boot: Run the EFI bootmgr just before network devices
Quoted 10 lines · Simon Glass
At present the EFI bootmgr scans all devices in the system before deciding which one to boot. Ideally it would use the bootstd iterator for this, but in the meantime, give it a lower priority, so it runs just before the network devices.
Note that if there are no hunted network devices hunted, then it will run at the end, after all bootdevs are exhausted. In other words, it will always run.
Signed-off-by Simon Glass <[email protected]>
This does not apply cleanly to master nor next as the test portion fails to apply.
Signature · 1 line
Tom
Re: [PATCH v2 16/17] boot: Run the EFI bootmgr just before network devices
Hi Tom,
Quoted 8 lines · Tom Rini
Quoted 5 lines · Simon Glass
At present the EFI bootmgr scans all devices in the system before deciding which one to boot. Ideally it would use the bootstd iterator for this, but in the meantime, give it a lower priority, so it runs just before the network devices.
Quoted 8 lines
Quoted 5 lines
Note that if there are no hunted network devices hunted, then it will run at the end, after all bootdevs are exhausted. In other words, it will always run.
Signed-off-by Simon Glass <[email protected]>This does not apply cleanly to master nor next as the test portion fails to apply.
OK. I'm not sure what happened there but it could perhaps have been a timing problem. I'll try again when I send the next version.
Regards,
SImon
Re: [PATCH v2 16/17] boot: Run the EFI bootmgr just before network devices
Quoted 15 lines · Simon Glass
Hi Tom,
Quoted 12 lines · Tom Rini
Quoted 9 lines · Simon Glass
At present the EFI bootmgr scans all devices in the system before deciding which one to boot. Ideally it would use the bootstd iterator for this, but in the meantime, give it a lower priority, so it runs just before the network devices.
Note that if there are no hunted network devices hunted, then it will run at the end, after all bootdevs are exhausted. In other words, it will always run.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Simon Glass <[email protected]>This does not apply cleanly to master nor next as the test portion fails to apply.
OK. I'm not sure what happened there but it could perhaps have been a timing problem. I'll try again when I send the next version.
I don't know what you mean by a timing problem but yes, please make sure to have something that's on top of master and documents any dependencies, thanks.
Signature · 1 line
Tom
PATCH v2 17/17 boot: doc: Update for new global-bootmeth features
In reply to Simon GlassProvide some developer documentation on the priority feature for global bootmeths.
---
Changes in v2:
- Add a bit more detail suggested by Heinrich
doc/develop/bootstd/overview.rst | 40 +++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-)
doc/develop/bootstd/overview.rst +34 -6
@@ -133,7 +133,8 @@ which scans for available bootflows, optionally listing each find it finds (-l) and trying to boot it (-b). When global bootmeths are available, these are typically checked before the -above bootdev scanning. +above bootdev scanning, but it is possible provide a priority to make them +run later, by setting the glob_prio field in the driver's bind() method. Controlling ordering
@@ -612,9 +613,9 @@ simply copied into the iterator. Either way, the `method_order` array it set up, along with `num_methods`. Note that global bootmeths are always put at the end of the ordering. If any are -present, `cur_method` is set to the first one, so that global bootmeths are done -first. Once all have been used, these bootmeths are dropped from the iteration. -When there are no global bootmeths, `cur_method` is set to 0. +present, `cur_method` is set to the first one, so that global bootmeths are +processed first, so long as their priority allows it. Bootstd keeps track of +which global bootmeths have been used, to make sure they are only used once. At this point the iterator is ready to use, with the first bootmeth selected. Most of the other fields are 0. This means that the current partition
@@ -714,8 +715,35 @@ to the next partition, or bootdev, for example. The special values `BF_NO_MORE_PARTS` and `BF_NO_MORE_DEVICES` handle this. When `iter_incr` sees `BF_NO_MORE_PARTS` it knows that it should immediately move to the next bootdev. When it sees `BF_NO_MORE_DEVICES` it knows that there is nothing more it can do -so it should immediately return. The caller of `iter_incr()` is responsible for -updating the `err` field, based on the return value it sees. +so it should immediately run any unused global bootmeths and then return. The +caller of `iter_incr()` is responsible for updating the `err` field, based on +the return value it sees. + +Global bootmeths can have a non-zero priority, which indicates where in the +iteration sequence they should run. Each time a new bootdev is produced by a +hunter, all of the global bootmeths are first checked to see if they should run +before this new bootdev. For example, if the bootdev was produced by a hunter +with priority BOOTDEVP_6_NET_BASE, then a quick check is made for global +bootmeths with that priority or less. If there are any, they run before the new +bootdev is processed. + +Assuming they are enabled and the iteration sequence runs right to the end, all +global bootmeths will be used. This is handled by a special case at the end of +iter_incr(), where it processes amy so-far-unused global bootmeths. + +It is important to note the special nature of global bootmeths, with respect to +priority. If there are two normal bootmeths and a global one, the normal ones +are run for each bootdev, but the global one is independent of bootdevs. The +order might be: + + bootdev priority 3: normal-1, normal-3 + global-2, prio 4 + bootdev priority 5: normal-1, normal-3 + +Of course if a specific bootmeth ordering is provided, then this overrides the +default ordering. Global bootmeths must be listed at the end, reflecting their +hybrid nature (they are bootmeths but operate on the system as a whole, not on +a particular bootdev). The above describes the iteration process at a high level. It is basically a very simple increment function with a checker called `bootflow_check()` that
Signature · 1 line
2.43.0
Re: [PATCH v2 17/17] boot: doc: Update for new global-bootmeth features
Quoted 4 lines · Simon Glass
Provide some developer documentation on the priority feature for global bootmeths.
Signed-off-by Simon Glass <[email protected]>
We should be doing documentation in the patch making the change, not standalone as this isn't "document old things which weren't documented before".
Signature · 1 line
Tom
Hi Simon,
Welcome back!
This is quite a large series making it quite hard to review.
Quoted 3 lines
At present global bootmeths always run first, before all other bootmeths. Optimisations in the code take advantage of this, putting them at the end, so they can be used once and then forgotten.
How often would you expect a device to actually want to enable and run all boot methods? EG I would expect an organisation who's making a general purpose devic to maybe want UEFI and extlinux, but likely not android, rauc and some of the other ones. I would think it's would be quite unusual for a device to enable everything and for a usecase specific device they'd probably want just one.
Quoted 4 lines
In some cases it is useful to run global bootmeths later in the boot. For example, the EFI-bootmgr bootmeth may itself scan devices and the network, so running it first can hold up the boot significantly for boards not actually relying on EFI-bootmgr to boot.
Exactly, would boards not relying on UEFI actually enable it at all, similarly if a device is not ever expecting to boot off a network they would disable it.
Quoted 10 lines
This series introduces a new field in global bootmeths which indicates the priority, using the same scheme as is used with bootdev hunters. Thus it is possible to insert the EFI-bootmgr bootmeth just before the hunter for network bootdevs is invoked.
Despite the simplicity of the concept and the relatively small series, this is a fairly significant enhancement. It is also quite tricky to implement, largely due to the way the original code was written, with global bootmeths being a small, size-optimised add-on to the original bootstd implementation.
So we know it's complex but I'm still unsure what value it provides.
Quoted 4 lines
For now we only allow each global bootmeth to run at most once, but this implementation is written in a way that we could relax that if needed. Then the bootmeth itself could decide whether to run at any particular point in the bootflow iteration.
Why would we want to run them more than once?
Quoted 4 lines
Size growth is about 390 bytes on Thumb2 (e.g. firefly-rk3288) if
CONFIG_BOOTMETH_GLOBALis enabled, which it normally is. With that disabled (which saves about 4K on the same platform), there is no growth.
So what value does adding 4K by default to the firmware provide? All what makes something a global boot method vs a non global (local?) boot method?
Quoted 5 lines
Changes in v2:
- Add alog_err()for an invalid state
- Update commit message to indicate the bootmeth will always run
- Document how the priority was chosen
- Add a bit more detail suggested by Heinrich
I think this series needs to be broken down into a couple of series.
These looks like fixes mostly unrelated to and independent of the new feature:
Quoted 5 lines
boot: Improve comments related to global bootmeths
boot: Move obtaining the label into a common file
boot: Add more debugging toiter_incr()
boot: Move showing of bootflows out of the command
boot: Move preparing bootdev into a function
I think these are the bits that do the global stuff.
Quoted 10 lines
boot: Add a new test for global bootmeths
boot: Updatefirst_glob_methodwhen dropping a bootmeth
boot: Add a flag for whether there are global bootmeths
boot: Support rescanning the global bootmeths
boot: Only run global bootmeths once each
boot: Implement a priority for global bootmeths
boot: Don't change the method count after global bootmeths
boot: Run global bootmeths after all bootdevs are exhausted
boot: Run the EFI bootmgr just before network devices
boot: doc: Update for new global-bootmeth features
Why do we want this? What does all bootmeths mean in this context?
Quoted 1 line
boot: Try all bootmeths on the final partition
As I, and at least Tom, but I think others, have asked in the past please do smaller patchsets on single topics. If you need to do cleanups post them as a different dependent patch set.
You have complained in the past that people don't review your series fast enough, but doing large sets like this with an inter mix of fixes and enhancements make it hard for people to review, eg I put this in my back log because of that exactly.
Regards,
Peter
Quoted 15 lines
boot/bootflow.c | 318 ++++++++++++++++++++++++++++--- boot/bootmeth-uclass.c | 15 +- boot/bootmeth_efi_mgr.c | 9 + cmd/bootflow.c | 66 +------ doc/develop/bootstd/overview.rst | 40 +++- include/bootflow.h | 39 +++- include/bootmeth.h | 4 + test/boot/bootflow.c | 75 +++++++- 8 files changed, 457 insertions(+), 109 deletions(-)--
2.43.0base-commit:
aff68c8514858ddd8d2e508d47bede566511521b
branch: glob-us2
Hi Peter,
Quoted 11 lines · Peter Robinson
Hi Simon,
Welcome back!
This is quite a large series making it quite hard to review.
Quoted 3 lines
At present global bootmeths always run first, before all other bootmeths. Optimisations in the code take advantage of this, putting them at the end, so they can be used once and then forgotten.
Quoted 6 lines
How often would you expect a device to actually want to enable and run all boot methods? EG I would expect an organisation who's making a general purpose devic to maybe want UEFI and extlinux, but likely not android, rauc and some of the other ones. I would think it's would be quite unusual for a device to enable everything and for a usecase specific device they'd probably want just one.
I suppose it depends on what is being booted. If it is a more closed and embedded system, then perhaps only one bootmeth is enabled. For many of the boards that U-Boot supports, different people likely run a lot of different things.
Quoted 9 lines
Quoted 5 lines
In some cases it is useful to run global bootmeths later in the boot. For example, the EFI-bootmgr bootmeth may itself scan devices and the network, so running it first can hold up the boot significantly for boards not actually relying on EFI-bootmgr to boot.
Exactly, would boards not relying on UEFI actually enable it at all, similarly if a device is not ever expecting to boot off a network they would disable it.
Possibly.
Quoted 12 lines
Quoted 11 lines
This series introduces a new field in global bootmeths which indicates the priority, using the same scheme as is used with bootdev hunters. Thus it is possible to insert the EFI-bootmgr bootmeth just before the hunter for network bootdevs is invoked.
Despite the simplicity of the concept and the relatively small series, this is a fairly significant enhancement. It is also quite tricky to implement, largely due to the way the original code was written, with global bootmeths being a small, size-optimised add-on to the original bootstd implementation.
Quoted 8 lines
So we know it's complex but I'm still unsure what value it provides.
Quoted 4 lines
For now we only allow each global bootmeth to run at most once, but this implementation is written in a way that we could relax that if needed. Then the bootmeth itself could decide whether to run at any particular point in the bootflow iteration.
Why would we want to run them more than once?
It may come to pass that we want a bootmeth to try to boot based on the bootdevs already seen (e.g. pre-network) and then try again later (e.g. once the network is available).
Quoted 9 lines
Quoted 5 lines
Size growth is about 390 bytes on Thumb2 (e.g. firefly-rk3288) if
CONFIG_BOOTMETH_GLOBALis enabled, which it normally is. With that disabled (which saves about 4K on the same platform), there is no growth.So what value does adding 4K by default to the firmware provide? All what makes something a global boot method vs a non global (local?) boot method?
This is described at [1]. Global bootmeths are not specific to a bootdev. They can operate independently of particular devices. For example, sunxi FEL operates on something that isn't a bootdev. Bootmgr operates on all devices it can find in the system. So global bootmeths are an important part of the bootstd model.
Quoted 7 lines
Quoted 6 lines
Changes in v2:
- Add alog_err()for an invalid state
- Update commit message to indicate the bootmeth will always run
- Document how the priority was chosen
- Add a bit more detail suggested by Heinrich
Quoted 8 lines
I think this series needs to be broken down into a couple of series.
These looks like fixes mostly unrelated to and independent of the new feature:
Quoted 5 lines
boot: Improve comments related to global bootmeths
boot: Move obtaining the label into a common file
boot: Add more debugging toiter_incr()
boot: Move showing of bootflows out of the command
boot: Move preparing bootdev into a function
OK.
Quoted 13 lines
I think these are the bits that do the global stuff.
Quoted 10 lines
boot: Add a new test for global bootmeths
boot: Updatefirst_glob_methodwhen dropping a bootmeth
boot: Add a flag for whether there are global bootmeths
boot: Support rescanning the global bootmeths
boot: Only run global bootmeths once each
boot: Implement a priority for global bootmeths
boot: Don't change the method count after global bootmeths
boot: Run global bootmeths after all bootdevs are exhausted
boot: Run the EFI bootmgr just before network devices
boot: doc: Update for new global-bootmeth features
Quoted 1 line
Why do we want this? What does all bootmeths mean in this context?
Are you asking why we want this feature at all? The original genesis was a discussion on the U-Boot call a few weeks back, where we were trying to work out how to enable the 'script' bootmeth to run before bootmgr, since the latter starts up the network, thus slowing boot significantly. This idea what we came up with.
Quoted 10 lines
Quoted 1 line
boot: Try all bootmeths on the final partition
As I, and at least Tom, but I think others, have asked in the past please do smaller patchsets on single topics. If you need to do cleanups post them as a different dependent patch set.
You have complained in the past that people don't review your series fast enough, but doing large sets like this with an inter mix of fixes and enhancements make it hard for people to review, eg I put this in my back log because of that exactly.
I'm not sure what you are referring to here. Can you provide a link?
I will check with Tom about posting just the 5 patches above.
Quoted 19 lines
Regards,
PeterQuoted 15 lines
boot/bootflow.c | 318 ++++++++++++++++++++++++++++--- boot/bootmeth-uclass.c | 15 +- boot/bootmeth_efi_mgr.c | 9 + cmd/bootflow.c | 66 +------ doc/develop/bootstd/overview.rst | 40 +++- include/bootflow.h | 39 +++- include/bootmeth.h | 4 + test/boot/bootflow.c | 75 +++++++- 8 files changed, 457 insertions(+), 109 deletions(-)--
2.43.0base-commit:
aff68c8514858ddd8d2e508d47bede566511521b
branch: glob-us2
[1] https://docs.u-boot.org/en/latest/develop/bootstd/overview.html#bootmeth