Skip to contentSkip to conversation

fwu: Call EFI stack initialization after preboot

PATCH Superseded Michal Simek 3 participants 9 messages Apr 1

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover fwu: Call EFI stack initialization after preboot

Hi,

the whole series is trying to address issues we have on platforms where usb and ufs init are not done before efi initialization. This is happening on platforms where A/B update is enabled. FWU code is called early and do EFI initialization before usb and ufs started that's why they are not visible.

We are workarounding it by starting usb/ufs from board file but this should be more generic approach.

Thanks,
Michal

Changes in v3:
- add missing type_name extension

Changes in v2:
- new patch in series
- check return value

Michal Simek (3):
event: Check return value from event_notify_null()
event: Introduce EVT_POST_PREBOOT event
fwu: Move boottime checks to EVT_POST_PREBOOT

 common/board_r.c      | 6 +++++-
 common/event.c        | 3 +++
 common/main.c         | 4 ++++
 include/event.h       | 9 +++++++++
 lib/fwu_updates/fwu.c | 2 +-
 test/dm/fwu_mdata.c   | 4 ++--
 6 files changed, 24 insertions(+), 4 deletions(-)
Signature · 4 lines
2.43.0

base-commit: 0da1866a8fdd4d4bc4837ef2af281dbe010ae16b
branch: debian-sent3
#1 lore raw

PATCH v3 1/3 event: Check return value from event_notify_null()

event_notify_null() returns int but its return value is not checked in run_main_loop() and in fwu_mdata tests. Add proper error checking to all unchecked call sites.

---

(no changes since v2)

Changes in v2:
- new patch in series

 common/board_r.c    | 6 +++++-
 test/dm/fwu_mdata.c | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)
common/board_r.c +5 -1
index 8cf0e14679c0..5d37345ca09d 100644
@@ -569,11 +569,15 @@ static int dm_announce(void)
 
 static int run_main_loop(void)
 {
+	int ret;
+
 #ifdef CONFIG_SANDBOX
 	sandbox_main_loop_init();
 #endif
 
-	event_notify_null(EVT_MAIN_LOOP);
+	ret = event_notify_null(EVT_MAIN_LOOP);
+	if (ret)
+		return ret;
 
 	/* main_loop() can return to retry autoboot, if so just run it again */
 	for (;;)
test/dm/fwu_mdata.c +2 -2
index b7680632f95f..643b647af0a9 100644
@@ -100,7 +100,7 @@ static int dm_test_fwu_mdata_read(struct unit_test_state *uts)
 	 * Trigger lib/fwu_updates/fwu.c fwu_boottime_checks()
 	 * to populate g_dev global pointer in that library.
 	 */
-	event_notify_null(EVT_MAIN_LOOP);
+	ut_assertok(event_notify_null(EVT_MAIN_LOOP));
 
 	ut_assertok(uclass_first_device_err(UCLASS_FWU_MDATA, &dev));
 	ut_assertok(fwu_init());
@@ -127,7 +127,7 @@ static int dm_test_fwu_mdata_write(struct unit_test_state *uts)
 	 * Trigger lib/fwu_updates/fwu.c fwu_boottime_checks()
 	 * to populate g_dev global pointer in that library.
 	 */
-	event_notify_null(EVT_MAIN_LOOP);
+	ut_assertok(event_notify_null(EVT_MAIN_LOOP));
 
 	ut_assertok(uclass_first_device_err(UCLASS_FWU_MDATA, &dev));
 
Signature · 1 line
2.43.0
#4 lore raw

PATCH v3 2/3 event: Introduce EVT_POST_PREBOOT event

In reply to Michal Simek

Add a new EVT_POST_PREBOOT event type which is fired in main_loop() after the preboot command has been executed.

---

Changes in v3:
- add missing type_name extension

Changes in v2:
- check return value

 common/event.c  | 3 +++
 common/main.c   | 4 ++++
 include/event.h | 9 +++++++++
 3 files changed, 16 insertions(+)
common/event.c +3 -0
index 8d7513eb10b6..398e713d2f82 100644
@@ -49,6 +49,9 @@ const char *const type_name[] = {
 	/* main loop events */
 	"main_loop",
 
+	/* post preboot events */
+	"post_preboot",
+
 	/* livetree has been built */
 	"of_live_init",
 };
common/main.c +4 -0
index b0b6e74f5d3d..4b4504557f6e 100644
@@ -19,6 +19,7 @@
 #include <net.h>
 #include <version_string.h>
 #include <efi_loader.h>
+#include <event.h>
 
 static void run_preboot_environment_command(void)
 {
@@ -53,6 +54,9 @@ void main_loop(void)
 	if (IS_ENABLED(CONFIG_USE_PREBOOT))
 		run_preboot_environment_command();
 
+	if (event_notify_null(EVT_POST_PREBOOT))
+		return;
+
 	if (IS_ENABLED(CONFIG_UPDATE_TFTP))
 		update_tftp(0UL, NULL, NULL);
 
include/event.h +9 -0
index 1d267f1d1054..3ce5f992b04e 100644
@@ -153,6 +153,15 @@ enum event_t {
 	 */
 	EVT_MAIN_LOOP,
 
+	/**
+	 * @EVT_POST_PREBOOT:
+	 * This event is triggered in main_loop() after the preboot command
+	 * has run, so that devices initialised by preboot (e.g. USB, UFS)
+	 * are available to event handlers. Its parameter is NULL.
+	 * A non-zero return value causes the boot to fail.
+	 */
+	EVT_POST_PREBOOT,
+
 	/**
 	 * @EVT_OF_LIVE_BUILT:
 	 * This event is triggered immediately after the live device tree has been
Signature · 1 line
2.43.0
#7 lore raw

PATCH v3 3/3 fwu: Move boottime checks to EVT_POST_PREBOOT

In reply to Michal Simek

Switch fwu_boottime_checks() from EVT_MAIN_LOOP to EVT_POST_PREBOOT because there is no reason to call FWU so early. FWU triggers EFI stack initialization before all devices are visible which prevents the EFI stack from scanning these devices and adding them to EFI variables.

---

(no changes since v1)

 lib/fwu_updates/fwu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fwu_updates/fwu.c +1 -1
index 37c613014d18..e82600a29a40 100644
@@ -796,4 +796,4 @@ static int fwu_boottime_checks(void)
 
 	return 0;
 }
-EVENT_SPY_SIMPLE(EVT_MAIN_LOOP, fwu_boottime_checks);
+EVENT_SPY_SIMPLE(EVT_POST_PREBOOT, fwu_boottime_checks);
Signature · 1 line
2.43.0
Acked-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] event: Check return value from event_notify_null()

In reply to Michal Simek
Quoted 9 lines · Michal Simek

event_notify_null() returns int but its return value is not checked in run_main_loop() and in fwu_mdata tests. Add proper error checking to all unchecked call sites.

---

Quoted 55 lines

(no changes since v2)

Changes in v2:
- new patch in series

 common/board_r.c    | 6 +++++-
 test/dm/fwu_mdata.c | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)
common/board_r.c +5 -1
index 8cf0e14679c0..5d37345ca09d 100644
@@ -569,11 +569,15 @@ static int dm_announce(void)
 
 static int run_main_loop(void)
 {
+       int ret;
+
 #ifdef CONFIG_SANDBOX
        sandbox_main_loop_init();
 #endif
 
-       event_notify_null(EVT_MAIN_LOOP);
+       ret = event_notify_null(EVT_MAIN_LOOP);
+       if (ret)
+               return ret;
 
        /* main_loop() can return to retry autoboot, if so just run it again */
        for (;;)
test/dm/fwu_mdata.c +2 -3
index b7680632f95f..643b647af0a9 100644
@@ -100,7 +100,7 @@ static int dm_test_fwu_mdata_read(struct unit_test_state *uts)
         * Trigger lib/fwu_updates/fwu.c fwu_boottime_checks()
         * to populate g_dev global pointer in that library.
         */
-       event_notify_null(EVT_MAIN_LOOP);
+       ut_assertok(event_notify_null(EVT_MAIN_LOOP));
 
        ut_assertok(uclass_first_device_err(UCLASS_FWU_MDATA, &dev));
        ut_assertok(fwu_init());
@@ -127,7 +127,7 @@ static int dm_test_fwu_mdata_write(struct unit_test_state *uts)
         * Trigger lib/fwu_updates/fwu.c fwu_boottime_checks()
         * to populate g_dev global pointer in that library.
         */
-       event_notify_null(EVT_MAIN_LOOP);
+       ut_assertok(event_notify_null(EVT_MAIN_LOOP));
 
        ut_assertok(uclass_first_device_err(UCLASS_FWU_MDATA, &dev));
 
--

2.43.0

Acked-by on v3 2/3
#5 lore raw

Re: [PATCH v3 2/3] event: Introduce EVT_POST_PREBOOT event

In reply to Michal Simek
Quoted 7 lines · Michal Simek

Add a new EVT_POST_PREBOOT event type which is fired in main_loop() after the preboot command has been executed.

---

Quoted 71 lines

Changes in v3:
- add missing type_name extension

Changes in v2:
- check return value

 common/event.c  | 3 +++
 common/main.c   | 4 ++++
 include/event.h | 9 +++++++++
 3 files changed, 16 insertions(+)
common/event.c +3 -0
index 8d7513eb10b6..398e713d2f82 100644
@@ -49,6 +49,9 @@ const char *const type_name[] = {
        /* main loop events */
        "main_loop",
 
+       /* post preboot events */
+       "post_preboot",
+
        /* livetree has been built */
        "of_live_init",
 };
common/main.c +4 -0
index b0b6e74f5d3d..4b4504557f6e 100644
@@ -19,6 +19,7 @@
 #include <net.h>
 #include <version_string.h>
 #include <efi_loader.h>
+#include <event.h>
 
 static void run_preboot_environment_command(void)
 {
@@ -53,6 +54,9 @@ void main_loop(void)
        if (IS_ENABLED(CONFIG_USE_PREBOOT))
                run_preboot_environment_command();
 
+       if (event_notify_null(EVT_POST_PREBOOT))
+               return;
+
        if (IS_ENABLED(CONFIG_UPDATE_TFTP))
                update_tftp(0UL, NULL, NULL);
 
include/event.h +9 -1
index 1d267f1d1054..3ce5f992b04e 100644
@@ -153,6 +153,15 @@ enum event_t {
         */
        EVT_MAIN_LOOP,
 
+       /**
+        * @EVT_POST_PREBOOT:
+        * This event is triggered in main_loop() after the preboot command
+        * has run, so that devices initialised by preboot (e.g. USB, UFS)
+        * are available to event handlers. Its parameter is NULL.
+        * A non-zero return value causes the boot to fail.
+        */
+       EVT_POST_PREBOOT,
+
        /**
         * @EVT_OF_LIVE_BUILT:
         * This event is triggered immediately after the live device tree has been
--

2.43.0

Reviewed-by on v3 1/3
#3 lore raw

Re: [v3,1/3] event: Check return value from event_notify_null()

In reply to Michal Simek
Quoted 6 lines · Michal Simek

event: Check return value from event_notify_null()

event_notify_null() returns int but its return value is not checked in run_main_loop() and in fwu_mdata tests. Add proper error checking to all unchecked call sites.

Quoted 7 lines

common/board_r.c | 6 +++++-

 test/dm/fwu_mdata.c | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)
Reviewed-by on v3 2/3
#6 lore raw

Re: [v3,2/3] event: Introduce EVT_POST_PREBOOT event

In reply to Michal Simek
Quoted 5 lines · Michal Simek

event: Introduce EVT_POST_PREBOOT event

Add a new EVT_POST_PREBOOT event type which is fired in main_loop() after the preboot command has been executed.

Quoted 8 lines

common/event.c | 3 +++

 common/main.c   | 4 ++++
 include/event.h | 9 +++++++++
 3 files changed, 16 insertions(+)
#8 lore raw

Re: [v3,3/3] fwu: Move boottime checks to EVT_POST_PREBOOT

In reply to Michal Simek

Hi Michal,

lib/fwu_updates/fwu.c static int fwu_boottime_checks(void) · line 790

Quoted 4 lines · Michal Simek
lib/fwu_updates/fwu.c +1 -1
@@ -790,4 +790,4 @@ static int fwu_boottime_checks(void)
-EVENT_SPY_SIMPLE(EVT_MAIN_LOOP, fwu_boottime_checks);
+EVENT_SPY_SIMPLE(EVT_POST_PREBOOT, fwu_boottime_checks);

The tests in test/dm/fwu_mdata.c still call event_notify_null(EVT_MAIN_LOOP) to trigger fwu_boottime_checks(). Since this patch moves the spy to EVT_POST_PREBOOT, those tests will no longer work - the g_dev global pointer won't be populated. Please can you update the tests to use EVT_POST_PREBOOT?

Regards,
Simon