aboutsummaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-08-14 16:40:35 -0600
committerTom Rini <trini@konsulko.com>2023-08-25 13:54:33 -0400
commitfc9c0e0771cad76b24f73bb64c105b6ea39721ca (patch)
tree354bcb5d5fae27ae957696bab20ce2574372fbe0 /boot
parent472317cb12e534f56b631365987934960dfb0a3f (diff)
downloadu-boot-fc9c0e0771cad76b24f73bb64c105b6ea39721ca.zip
u-boot-fc9c0e0771cad76b24f73bb64c105b6ea39721ca.tar.gz
u-boot-fc9c0e0771cad76b24f73bb64c105b6ea39721ca.tar.bz2
expo: cedit: Support writing settings to environment vars
Add a command to write cedit settings to environment variables so that they can be stored with 'saveenv'. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'boot')
-rw-r--r--boot/cedit.c97
1 files changed, 83 insertions, 14 deletions
diff --git a/boot/cedit.c b/boot/cedit.c
index 6a74a38..9399c01 100644
--- a/boot/cedit.c
+++ b/boot/cedit.c
@@ -13,6 +13,7 @@
#include <cedit.h>
#include <cli.h>
#include <dm.h>
+#include <env.h>
#include <expo.h>
#include <menu.h>
#include <video.h>
@@ -24,10 +25,12 @@
*
* @buf: Buffer to use when writing settings to the devicetree
* @node: Node to read from when reading settings from devicetree
+ * @verbose: true to show writing to environment variables
*/
struct cedit_iter_priv {
struct abuf *buf;
ofnode node;
+ bool verbose;
};
int cedit_arange(struct expo *exp, struct video_priv *vpriv, uint scene_id)
@@ -209,6 +212,30 @@ static int check_space(int ret, struct abuf *buf)
return 0;
}
+static int get_cur_menuitem_text(const struct scene_obj_menu *menu,
+ const char **strp)
+{
+ struct scene *scn = menu->obj.scene;
+ const struct scene_menitem *mi;
+ const struct scene_obj_txt *txt;
+ const char *str;
+
+ mi = scene_menuitem_find(menu, menu->cur_item_id);
+ if (!mi)
+ return log_msg_ret("mi", -ENOENT);
+
+ txt = scene_obj_find(scn, mi->label_id, SCENEOBJT_TEXT);
+ if (!txt)
+ return log_msg_ret("txt", -ENOENT);
+
+ str = expo_get_str(scn->expo, txt->str_id);
+ if (!str)
+ return log_msg_ret("str", -ENOENT);
+ *strp = str;
+
+ return 0;
+}
+
static int h_write_settings(struct scene_obj *obj, void *vpriv)
{
struct cedit_iter_priv *priv = vpriv;
@@ -221,9 +248,6 @@ static int h_write_settings(struct scene_obj *obj, void *vpriv)
break;
case SCENEOBJT_MENU: {
const struct scene_obj_menu *menu;
- const struct scene_obj_txt *txt;
- struct scene *scn = obj->scene;
- const struct scene_menitem *mi;
const char *str;
char name[80];
int ret, i;
@@ -243,17 +267,9 @@ static int h_write_settings(struct scene_obj *obj, void *vpriv)
if (ret)
return log_msg_ret("wrt", -EFAULT);
- mi = scene_menuitem_find(menu, menu->cur_item_id);
- if (!mi)
- return log_msg_ret("mi", -ENOENT);
-
- txt = scene_obj_find(scn, mi->label_id, SCENEOBJT_TEXT);
- if (!txt)
- return log_msg_ret("txt", -ENOENT);
-
- str = expo_get_str(scn->expo, txt->str_id);
- if (!str)
- return log_msg_ret("str", -ENOENT);
+ ret = get_cur_menuitem_text(menu, &str);
+ if (ret)
+ return log_msg_ret("mis", ret);
snprintf(name, sizeof(name), "%s-str", obj->name);
ret = -EAGAIN;
@@ -370,3 +386,56 @@ int cedit_read_settings(struct expo *exp, oftree tree)
return 0;
}
+
+static int h_write_settings_env(struct scene_obj *obj, void *vpriv)
+{
+ const struct scene_obj_menu *menu;
+ struct cedit_iter_priv *priv = vpriv;
+ char name[80], var[60];
+ const char *str;
+ 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);
+
+ if (priv->verbose)
+ printf("%s=%d\n", var, val);
+
+ ret = env_set_ulong(var, val);
+ if (ret)
+ return log_msg_ret("set", ret);
+
+ ret = get_cur_menuitem_text(menu, &str);
+ if (ret)
+ return log_msg_ret("mis", ret);
+
+ snprintf(name, sizeof(name), "c.%s-str", obj->name);
+ if (priv->verbose)
+ printf("%s=%s\n", name, str);
+
+ ret = env_set(name, str);
+ if (ret)
+ return log_msg_ret("st2", ret);
+
+ return 0;
+}
+
+int cedit_write_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_write_settings_env, &priv);
+ if (ret) {
+ log_debug("Failed to write settings to env (err=%d)\n", ret);
+ return log_msg_ret("set", ret);
+ }
+
+ return 0;
+}