[Concept,v2,08/22] boot: Pass flags to the bootm_final event

Message ID 20250819185900.835939-9-sjg@u-boot.org
State New
Headers
Series efi: Improvements for the EFI app on ARM |

Commit Message

Simon Glass Aug. 19, 2025, 6:58 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

For a fake go, we should tell the event not to actually do anything
irreversable, so pass the flag along.

Move the enum into a separate event_decl.h header file since otherwise
we must include bootm.h which causes a breakage with qemu-ppce500

We also don't want to pull event.h into the tools build, since it uses
types like u8 which are not available outside U-Boot

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 boot/bootm_final.c   | 13 ++++++++-----
 include/bootm.h      | 13 +------------
 include/event.h      | 10 ++++++++++
 include/event_decl.h | 27 +++++++++++++++++++++++++++
 4 files changed, 46 insertions(+), 17 deletions(-)
 create mode 100644 include/event_decl.h
  

Patch

diff --git a/boot/bootm_final.c b/boot/bootm_final.c
index 7594880399e..881d737ce67 100644
--- a/boot/bootm_final.c
+++ b/boot/bootm_final.c
@@ -17,6 +17,7 @@  __weak void board_quiesce_devices(void)
 
 void bootm_final(enum bootm_final_t flags)
 {
+	struct event_bootm_final final;
 	int ret;
 
 	printf("\nStarting kernel ...%s\n\n", flags & BOOTM_FINAL_FAKE ?
@@ -43,15 +44,17 @@  void bootm_final(enum bootm_final_t flags)
 	 */
 	dm_remove_devices_active();
 
-	ret = event_notify_null(EVT_BOOTM_FINAL);
+	final.flags = flags;
+	ret = event_notify(EVT_BOOTM_FINAL, &final, sizeof(final));
 	if (ret) {
 		printf("Event handler failed to finalise (err %dE\n",
 		       ret);
 		return;
 	}
+	if (!(flags & BOOTM_FINAL_FAKE)) {
+		bootm_disable_interrupts();
 
-	bootm_disable_interrupts();
-
-	if (!(flags & BOOTM_FINAL_NO_CLEANUP))
-		cleanup_before_linux();
+		if (!(flags & BOOTM_FINAL_NO_CLEANUP))
+			cleanup_before_linux();
+	}
 }
diff --git a/include/bootm.h b/include/bootm.h
index b026e1dd80d..392825841e9 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -7,6 +7,7 @@ 
 #ifndef _BOOTM_H
 #define _BOOTM_H
 
+#include <event_decl.h>
 #include <image.h>
 
 struct boot_params;
@@ -16,18 +17,6 @@  struct cmd_tbl;
 #define BOOTM_ERR_OVERLAP		(-2)
 #define BOOTM_ERR_UNIMPLEMENTED	(-3)
 
-/**
- * enum bootm_final_t - flags to control bootm_final()
- *
- * @BOOTM_FINAL_FAKE: true to do everything except actually boot; it then
- *	returns to the caller
- * @BOOTM_FINAL_NO_CLEANUP: true to skip calling cleanup_before_linux()
- */
-enum bootm_final_t {
-	BOOTM_FINAL_FAKE	= BIT(0),
-	BOOTM_FINAL_NO_CLEANUP	= BIT(1),
-};
-
 /**
  * struct bootm_info() - information used when processing images to boot
  *
diff --git a/include/event.h b/include/event.h
index a68be9fc1e8..5fecaa66e80 100644
--- a/include/event.h
+++ b/include/event.h
@@ -12,6 +12,7 @@ 
 
 #include <dm/ofnode_decl.h>
 #include <linux/types.h>
+#include <event_decl.h>
 
 /**
  * enum event_t - Types of events supported by U-Boot
@@ -260,6 +261,15 @@  union event_data {
 	struct event_ft_fixup_f {
 		oftree tree;
 	} ft_fixup_f;
+
+	/**
+	 * struct event_bootm_final - State information
+	 *
+	 * @flags: Flags passed to bootm_final()
+	 */
+	struct event_bootm_final {
+		enum bootm_final_t flags;
+	} bootm_final;
 };
 
 /**
diff --git a/include/event_decl.h b/include/event_decl.h
new file mode 100644
index 00000000000..483ae687e5a
--- /dev/null
+++ b/include/event_decl.h
@@ -0,0 +1,27 @@ 
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Declarations needed by events
+ *
+ * Copyright 2025 Simon Glass <sjg@chromium.org>
+ */
+
+#ifndef __event_decl_h
+#define __event_decl_h
+
+#include <linux/bitops.h>
+
+/**
+ * enum bootm_final_t - flags to control bootm_final()
+ *
+ * Note that this is defined in event.h since it is used by events
+ *
+ * @BOOTM_FINAL_FAKE: true to do everything except actually boot; it then
+ *	returns to the caller
+ * @BOOTM_FINAL_NO_CLEANUP: true to skip calling cleanup_before_linux()
+ */
+enum bootm_final_t {
+	BOOTM_FINAL_FAKE	= BIT(0),
+	BOOTM_FINAL_NO_CLEANUP	= BIT(1),
+};
+
+#endif