]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
bootstd: Use the bootargs env var for changing the cmdline
authorSimon Glass <sjg@chromium.org>
Wed, 12 Jul 2023 15:04:35 +0000 (09:04 -0600)
committerBin Meng <bmeng@tinylab.org>
Sun, 16 Jul 2023 15:13:17 +0000 (23:13 +0800)
The "bootargs" environment variable is used to set the command-line
arguments to pass to the OS. Use this same mechanism with bootstd as well.
When the variable is updated, it is written to the current bootflow. When
the current bootflow is updated, the environment variable is updated too.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
boot/bootflow.c
cmd/bootflow.c
include/env_callback.h

index 487552fa28c0721866a6ed62ca39fa1e7ee68032..b820678d41ab498781de81458c6fa6c1b1788eae 100644 (file)
@@ -12,6 +12,7 @@
 #include <bootmeth.h>
 #include <bootstd.h>
 #include <dm.h>
+#include <env_internal.h>
 #include <malloc.h>
 #include <dm/device-internal.h>
 #include <dm/uclass-internal.h>
@@ -552,3 +553,60 @@ int bootflow_iter_check_system(const struct bootflow_iter *iter)
 
        return -ENOTSUPP;
 }
+
+/**
+ * bootflow_cmdline_set() - Set the command line for a bootflow
+ *
+ * @value: New command-line string
+ * Returns 0 if OK, -ENOENT if no current bootflow, -ENOMEM if out of memory
+ */
+int bootflow_cmdline_set(struct bootflow *bflow, const char *value)
+{
+       char *cmdline = NULL;
+
+       if (value) {
+               cmdline = strdup(value);
+               if (!cmdline)
+                       return -ENOMEM;
+       }
+
+       free(bflow->cmdline);
+       bflow->cmdline = cmdline;
+
+       return 0;
+}
+
+#ifdef CONFIG_BOOTSTD_FULL
+/**
+ * on_bootargs() - Update the cmdline of a bootflow
+ */
+static int on_bootargs(const char *name, const char *value, enum env_op op,
+                      int flags)
+{
+       struct bootstd_priv *std;
+       struct bootflow *bflow;
+       int ret;
+
+       ret = bootstd_get_priv(&std);
+       if (ret)
+               return 0;
+       bflow = std->cur_bootflow;
+       if (!bflow)
+               return 0;
+
+       switch (op) {
+       case env_op_create:
+       case env_op_overwrite:
+               ret = bootflow_cmdline_set(bflow, value);
+               if (ret && ret != ENOENT)
+                       return 1;
+               return 0;
+       case env_op_delete:
+               bootflow_cmdline_set(bflow, NULL);
+               fallthrough;
+       default:
+               return 0;
+       }
+}
+U_BOOT_ENV_CALLBACK(bootargs, on_bootargs);
+#endif
index ddb168c70390ddfe92ab029df2e7d961d4d11f30..f33db7be5f2e32a51d4306541868c46ff9701f21 100644 (file)
@@ -288,6 +288,12 @@ static int do_bootflow_select(struct cmd_tbl *cmdtp, int flag, int argc,
                return CMD_RET_FAILURE;
        }
        std->cur_bootflow = found;
+       if (IS_ENABLED(CONFIG_BOOTSTD_FULL)) {
+               if (env_set("bootargs", found->cmdline)) {
+                       printf("Cannot set bootargs\n");
+                       return CMD_RET_FAILURE;
+               }
+       }
 
        return 0;
 }
index a9a14f2a84a5b7d7c063a769e46f14d6411b1a6a..23bc650c162de4bd22813406ec1321dff3c204e7 100644 (file)
 #define NET6_CALLBACKS
 #endif
 
-#ifdef CONFIG_BOOTSTD
-#define BOOTSTD_CALLBACK       "bootmeths:bootmeths,"
+#ifdef CONFIG_BOOTSTD_FULL
+#define BOOTSTD_CALLBACK \
+       "bootmeths:bootmeths," \
+       "bootargs:bootargs,"
 #else
 #define BOOTSTD_CALLBACK
 #endif