summaryrefslogtreecommitdiff
path: root/boot/cedit.c
diff options
context:
space:
mode:
authorSimon Glass <[email protected]>2023-08-14 16:40:36 -0600
committerTom Rini <[email protected]>2023-08-25 13:54:33 -0400
commitbcf2b7202e960e7fb3df8d5e8ed0d6fa00a5a9fa (patch)
tree75f46b69fa13368405aafeb36e2b1adcfcdf6a35 /boot/cedit.c
parentfc9c0e0771cad76b24f73bb64c105b6ea39721ca (diff)
expo: cedit: Support reading settings from environment vars
Add a command to read cedit settings from environment variables so that they can be restored as part of the environment. Signed-off-by: Simon Glass <[email protected]>
Diffstat (limited to 'boot/cedit.c')
-rw-r--r--boot/cedit.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/boot/cedit.c b/boot/cedit.c
index 9399c01cda9..e3f6dc00399 100644
--- a/boot/cedit.c
+++ b/boot/cedit.c
@@ -439,3 +439,48 @@ int cedit_write_settings_env(struct expo *exp, bool verbose)
return 0;
}
+
+static int h_read_settings_env(struct scene_obj *obj, void *vpriv)
+{
+ struct cedit_iter_priv *priv = vpriv;
+ struct scene_obj_menu *menu;
+ char var[60];
+ int val, ret;
+
+ if (obj->type != SCENEOBJT_MENU)
+ return 0;
+
+ menu = (struct scene_obj_menu *)obj;
+ val = menu->cur_item_id;
+ snprintf(var, sizeof(var), "c.%s", obj->name);
+
+ val = env_get_ulong(var, 10, 0);
+ if (priv->verbose)
+ printf("%s=%d\n", var, val);
+ if (!val)
+ return log_msg_ret("get", -ENOENT);
+
+ /*
+ * note that no validation is done here, to make sure the ID is valid
+ * and actually points to a menu item
+ */
+ menu->cur_item_id = val;
+
+ return 0;
+}
+
+int cedit_read_settings_env(struct expo *exp, bool verbose)
+{
+ struct cedit_iter_priv priv;
+ int ret;
+
+ /* write out the items */
+ priv.verbose = verbose;
+ ret = expo_iter_scene_objs(exp, h_read_settings_env, &priv);
+ if (ret) {
+ log_debug("Failed to read settings from env (err=%d)\n", ret);
+ return log_msg_ret("set", ret);
+ }
+
+ return 0;
+}