summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorKory Maincent (TI.com) <[email protected]>2025-10-30 17:45:10 +0100
committerTom Rini <[email protected]>2025-11-03 10:02:39 -0600
commitf9b139342c4f6cc067df06692e6dcaa4ba2edafc (patch)
treecb3ad06fd19af41a906f89777af90570b5f62be8 /cmd
parent2d12958ee71b5f400ff2045aebc9730e8e219340 (diff)
boot: extension: Move overlay apply custom logic to command level
The extension_overlay_cmd environment variable approach is specific to the U-Boot extension_board command, while other boot flows (pxe_utils, bootstd) handle overlay loading differently. Move the extension_overlay_cmd execution out of the core extension framework to the command level. This decouples the framework from command-specific behavior and prepares for future extension support in other boot flows. Signed-off-by: Kory Maincent (TI.com) <[email protected]> Reviewed-by: Simon Glass <[email protected]>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/extension_board.c92
1 files changed, 90 insertions, 2 deletions
diff --git a/cmd/extension_board.c b/cmd/extension_board.c
index c373397e0fb..86e4795ba8a 100644
--- a/cmd/extension_board.c
+++ b/cmd/extension_board.c
@@ -7,8 +7,90 @@
#include <alist.h>
#include <exports.h>
#include <command.h>
+#include <env.h>
#include <extension_board.h>
+static int
+cmd_extension_load_overlay_from_env(const struct extension *extension,
+ ulong *filesize)
+{
+ ulong size, overlay_addr;
+ char *overlay_cmd;
+ int ret;
+
+ overlay_cmd = env_get("extension_overlay_cmd");
+ if (!overlay_cmd) {
+ printf("Environment extension_overlay_cmd is missing\n");
+ return -EINVAL;
+ }
+
+ overlay_addr = env_get_hex("extension_overlay_addr", 0);
+ if (!overlay_addr) {
+ printf("Environment extension_overlay_addr is missing\n");
+ return -EINVAL;
+ }
+
+ env_set("extension_overlay_name", extension->overlay);
+ ret = run_command(overlay_cmd, 0);
+ if (ret)
+ return ret;
+
+ size = env_get_hex("filesize", 0);
+ if (!size)
+ return -EINVAL;
+
+ *filesize = size;
+ return 0;
+}
+
+static int cmd_extension_apply(int extension_num)
+{
+ struct alist *extension_list = extension_get_list();
+ const struct extension *extension;
+ ulong size;
+ int ret;
+
+ if (!extension_list)
+ return -ENODEV;
+
+ extension = alist_get(extension_list, extension_num,
+ struct extension);
+ if (!extension) {
+ printf("Wrong extension number\n");
+ return -ENODEV;
+ }
+
+ ret = cmd_extension_load_overlay_from_env(extension, &size);
+ if (ret)
+ return ret;
+
+ return extension_apply(working_fdt, size);
+}
+
+static int cmd_extension_apply_all(void)
+{
+ struct alist *extension_list = extension_get_list();
+ const struct extension *extension;
+ int ret;
+
+ if (!extension_list)
+ return -ENODEV;
+
+ alist_for_each(extension, extension_list) {
+ ulong size;
+
+ ret = cmd_extension_load_overlay_from_env(extension, &size);
+ if (ret)
+ return ret;
+
+ ret = extension_apply(working_fdt, size);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
static int do_extension_list(struct cmd_tbl *cmdtp, int flag,
int argc, char *const argv[])
{
@@ -55,12 +137,18 @@ static int do_extension_apply(struct cmd_tbl *cmdtp, int flag,
if (argc < 2)
return CMD_RET_USAGE;
+ if (!working_fdt) {
+ printf("No FDT memory address configured. Please configure\n"
+ "the FDT address via \"fdt addr <address>\" command.\n");
+ return -EINVAL;
+ }
+
if (strcmp(argv[1], "all") == 0) {
- if (extension_apply_all())
+ if (cmd_extension_apply_all())
return CMD_RET_FAILURE;
} else {
extension_id = simple_strtol(argv[1], NULL, 10);
- if (extension_apply(extension_id))
+ if (cmd_extension_apply(extension_id))
return CMD_RET_FAILURE;
}