summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Kconfig9
-rw-r--r--cmd/Makefile1
-rw-r--r--cmd/cat.c47
-rw-r--r--cmd/cedit.c93
4 files changed, 120 insertions, 30 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index c1941849f98..f6b10e01f84 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -428,6 +428,15 @@ config CMD_ABOOTIMG
See doc/android/boot-image.rst for details.
+config CMD_CEDIT
+ bool "cedit - Configuration editor"
+ depends on CEDIT
+ default y
+ help
+ Provides a command to allow editing of board configuration and
+ providing a UI for the user to adjust settings. Subcommands allow
+ loading and saving of configuration as well as showing an editor.
+
config CMD_ELF
bool "bootelf, bootvx"
default y
diff --git a/cmd/Makefile b/cmd/Makefile
index 6c37521b4e2..9f8c0b058be 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_CMD_BUTTON) += button.o
obj-$(CONFIG_CMD_CAT) += cat.o
obj-$(CONFIG_CMD_CACHE) += cache.o
obj-$(CONFIG_CMD_CBFS) += cbfs.o
+obj-$(CONFIG_CMD_CEDIT) += cedit.o
obj-$(CONFIG_CMD_CLK) += clk.o
obj-$(CONFIG_CMD_CLS) += cls.o
obj-$(CONFIG_CMD_CONFIG) += config.o
diff --git a/cmd/cat.c b/cmd/cat.c
index 1273a26b145..b059080193d 100644
--- a/cmd/cat.c
+++ b/cmd/cat.c
@@ -17,8 +17,8 @@ static int do_cat(struct cmd_tbl *cmdtp, int flag, int argc,
char *dev;
char *file;
char *buffer;
- phys_addr_t addr;
- loff_t file_size;
+ ulong file_size;
+ int ret;
if (argc < 4)
return CMD_RET_USAGE;
@@ -27,40 +27,27 @@ static int do_cat(struct cmd_tbl *cmdtp, int flag, int argc,
dev = argv[2];
file = argv[3];
+ ret = fs_load_alloc(ifname, dev, file, 0, 0, (void **)&buffer,
+ &file_size);
+
// check file exists
- if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
+ switch (ret) {
+ case 0:
+ break;
+ case -ENOMEDIUM:
return CMD_RET_FAILURE;
-
- if (!fs_exists(file)) {
+ case -ENOENT:
log_err("File does not exist: ifname=%s dev=%s file=%s\n", ifname, dev, file);
return CMD_RET_FAILURE;
- }
-
- // get file size
- if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
+ case -E2BIG:
+ log_err("File is too large: ifname=%s dev=%s file=%s\n", ifname, dev, file);
return CMD_RET_FAILURE;
-
- if (fs_size(file, &file_size)) {
- log_err("Cannot read file size: ifname=%s dev=%s file=%s\n", ifname, dev, file);
+ case -ENOMEM:
+ log_err("Not enough memory: ifname=%s dev=%s file=%s\n", ifname, dev, file);
return CMD_RET_FAILURE;
- }
-
- // allocate memory for file content
- buffer = calloc(sizeof(char), file_size + 1);
- if (!buffer) {
- log_err("Out of memory\n");
- return CMD_RET_FAILURE;
- }
-
- // map pointer to system memory
- addr = map_to_sysmem(buffer);
-
- // read file to memory
- if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
- return CMD_RET_FAILURE;
-
- if (fs_read(file, addr, 0, 0, &file_size)) {
- log_err("Cannot read file: ifname=%s dev=%s file=%s\n", ifname, dev, file);
+ default:
+ case -EIO:
+ log_err("File-read failed: ifname=%s dev=%s file=%s\n", ifname, dev, file);
return CMD_RET_FAILURE;
}
diff --git a/cmd/cedit.c b/cmd/cedit.c
new file mode 100644
index 00000000000..0cae304c4ad
--- /dev/null
+++ b/cmd/cedit.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * 'cedit' command
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <expo.h>
+#include <fs.h>
+#include <dm/ofnode.h>
+#include <linux/sizes.h>
+
+struct expo *cur_exp;
+
+static int do_cedit_load(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ const char *fname;
+ struct expo *exp;
+ oftree tree;
+ ulong size;
+ void *buf;
+ int ret;
+
+ if (argc < 4)
+ return CMD_RET_USAGE;
+ fname = argv[3];
+
+ ret = fs_load_alloc(argv[1], argv[2], argv[3], SZ_1M, 0, &buf, &size);
+ if (ret) {
+ printf("File not found\n");
+ return CMD_RET_FAILURE;
+ }
+
+ tree = oftree_from_fdt(buf);
+ if (!oftree_valid(tree)) {
+ printf("Cannot create oftree\n");
+ return CMD_RET_FAILURE;
+ }
+
+ ret = expo_build(oftree_root(tree), &exp);
+ oftree_dispose(tree);
+ if (ret) {
+ printf("Failed to build expo: %dE\n", ret);
+ return CMD_RET_FAILURE;
+ }
+
+ cur_exp = exp;
+
+ return 0;
+}
+
+static int do_cedit_run(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ ofnode node;
+ int ret;
+
+ if (!cur_exp) {
+ printf("No expo loaded\n");
+ return CMD_RET_FAILURE;
+ }
+
+ node = ofnode_path("/cedit-theme");
+ if (ofnode_valid(node)) {
+ ret = expo_apply_theme(cur_exp, node);
+ if (ret)
+ return CMD_RET_FAILURE;
+ } else {
+ log_warning("No theme found\n");
+ }
+ ret = cedit_run(cur_exp);
+ if (ret) {
+ log_err("Failed (err=%dE)\n", ret);
+ return CMD_RET_FAILURE;
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char cedit_help_text[] =
+ "load <interface> <dev[:part]> <filename> - load config editor\n"
+ "cedit run - run config editor";
+#endif /* CONFIG_SYS_LONGHELP */
+
+U_BOOT_CMD_WITH_SUBCMDS(cedit, "Configuration editor", cedit_help_text,
+ U_BOOT_SUBCMD_MKENT(load, 5, 1, do_cedit_load),
+ U_BOOT_SUBCMD_MKENT(run, 1, 1, do_cedit_run),
+);