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;
+}
return 0;
}
+static int do_cedit_read_env(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ bool verbose;
+ int ret;
+
+ if (check_cur_expo())
+ return CMD_RET_FAILURE;
+
+ verbose = argc > 1 && !strcmp(argv[1], "-v");
+
+ ret = cedit_read_settings_env(cur_exp, verbose);
+ if (ret) {
+ printf("Failed to read settings from environment: %dE\n", ret);
+ return CMD_RET_FAILURE;
+ }
+
+ return 0;
+}
+
static int do_cedit_run(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
"load <interface> <dev[:part]> <filename> - load config editor\n"
"cedit read_fdt <i/f> <dev[:part]> <filename> - read settings\n"
"cedit write_fdt <i/f> <dev[:part]> <filename> - write settings\n"
+ "cedit read_env [-v] - read settings from env vars\n"
"cedit write_env [-v] - write settings to env vars\n"
"cedit run - run config editor";
#endif /* CONFIG_SYS_LONGHELP */
U_BOOT_SUBCMD_MKENT(load, 5, 1, do_cedit_load),
U_BOOT_SUBCMD_MKENT(read_fdt, 5, 1, do_cedit_read_fdt),
U_BOOT_SUBCMD_MKENT(write_fdt, 5, 1, do_cedit_write_fdt),
+ U_BOOT_SUBCMD_MKENT(read_env, 2, 1, do_cedit_read_env),
U_BOOT_SUBCMD_MKENT(write_env, 2, 1, do_cedit_write_env),
U_BOOT_SUBCMD_MKENT(run, 1, 1, do_cedit_run),
);
cedit write_fdt <dev[:part]> <filename>
cedit read_fdt <dev[:part]> <filename>
cedit write_env [-v]
+ cedit read_env [-v]
Description
-----------
Reads the user settings from a devicetree file and updates the cedit with those
settings.
+cedit read_env
+~~~~~~~~~~~~~~
+
+Reads the settings from the environment variables. For each menu item `<name>`,
+cedit looks for a variable called `c.<name>` with the ID of the selected menu
+item.
+
+The `-v` flag enables verbose mode, where each variable is printed after it is
+read.
+
cedit write_env
~~~~~~~~~~~~~~~
This shows settings being stored in the environment::
=> cedit write_env -v
+ c.cpu-speed=7
+ c.cpu-speed-str=2.5 GHz
+ c.power-loss=12
+ c.power-loss-str=Memory
=> print
...
c.cpu-speed=6
c.power-loss=10
c.power-loss-str=Always Off
...
+
+ => cedit read_env -v
+ c.cpu-speed=7
+ c.power-loss=12
*/
int cedit_write_settings_env(struct expo *exp, bool verbose);
+/*
+ * cedit_read_settings_env() - Read settings from the environment
+ *
+ * @exp: Expo to read settings into
+ * @verbose: true to print each var before it is read
+ */
+int cedit_read_settings_env(struct expo *exp, bool verbose);
+
#endif /* __CEDIT_H */
}
BOOTSTD_TEST(cedit_fdt, 0);
-/* Check the cedit write_env command */
+/* Check the cedit write_env and read_env commands */
static int cedit_env(struct unit_test_state *uts)
{
struct video_priv *vid_priv;
ut_asserteq(7, env_get_ulong("c.cpu-speed", 10, 0));
ut_asserteq_str("2.5 GHz", env_get("c.cpu-speed-str"));
+ /* reset the expo */
+ menu->cur_item_id = ID_CPU_SPEED_1;
+
+ ut_assertok(run_command("cedit read_env -v", 0));
+ ut_assert_nextlinen("c.cpu-speed=7");
+ ut_assert_nextlinen("c.power-loss=10");
+ ut_assert_console_end();
+
+ ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id);
+
return 0;
}
BOOTSTD_TEST(cedit_env, 0);