blob: 5f0e84403f5be83a2a0550edc6eff7237b798bf3 [file] [log] [blame]
Simon Glassc8925112023-06-01 10:23:02 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * 'cedit' command
4 *
5 * Copyright 2023 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#include <common.h>
Simon Glass8df4a4e2023-08-14 16:40:25 -060010#include <cedit.h>
Simon Glassc8925112023-06-01 10:23:02 -060011#include <command.h>
12#include <expo.h>
13#include <fs.h>
14#include <dm/ofnode.h>
15#include <linux/sizes.h>
16
17struct expo *cur_exp;
18
19static int do_cedit_load(struct cmd_tbl *cmdtp, int flag, int argc,
20 char *const argv[])
21{
22 const char *fname;
23 struct expo *exp;
24 oftree tree;
25 ulong size;
26 void *buf;
27 int ret;
28
29 if (argc < 4)
30 return CMD_RET_USAGE;
31 fname = argv[3];
32
33 ret = fs_load_alloc(argv[1], argv[2], argv[3], SZ_1M, 0, &buf, &size);
34 if (ret) {
35 printf("File not found\n");
36 return CMD_RET_FAILURE;
37 }
38
39 tree = oftree_from_fdt(buf);
40 if (!oftree_valid(tree)) {
41 printf("Cannot create oftree\n");
42 return CMD_RET_FAILURE;
43 }
44
45 ret = expo_build(oftree_root(tree), &exp);
46 oftree_dispose(tree);
47 if (ret) {
48 printf("Failed to build expo: %dE\n", ret);
49 return CMD_RET_FAILURE;
50 }
51
52 cur_exp = exp;
53
54 return 0;
55}
56
57static int do_cedit_run(struct cmd_tbl *cmdtp, int flag, int argc,
58 char *const argv[])
59{
60 ofnode node;
61 int ret;
62
63 if (!cur_exp) {
64 printf("No expo loaded\n");
65 return CMD_RET_FAILURE;
66 }
67
68 node = ofnode_path("/cedit-theme");
69 if (ofnode_valid(node)) {
70 ret = expo_apply_theme(cur_exp, node);
71 if (ret)
72 return CMD_RET_FAILURE;
73 } else {
74 log_warning("No theme found\n");
75 }
76 ret = cedit_run(cur_exp);
77 if (ret) {
78 log_err("Failed (err=%dE)\n", ret);
79 return CMD_RET_FAILURE;
80 }
81
82 return 0;
83}
84
85#ifdef CONFIG_SYS_LONGHELP
86static char cedit_help_text[] =
87 "load <interface> <dev[:part]> <filename> - load config editor\n"
88 "cedit run - run config editor";
89#endif /* CONFIG_SYS_LONGHELP */
90
91U_BOOT_CMD_WITH_SUBCMDS(cedit, "Configuration editor", cedit_help_text,
92 U_BOOT_SUBCMD_MKENT(load, 5, 1, do_cedit_load),
93 U_BOOT_SUBCMD_MKENT(run, 1, 1, do_cedit_run),
94);