1 // SPDX-License-Identifier: GPL-2.0+
6 #include <asm/global_data.h>
8 DECLARE_GLOBAL_DATA_PTR
;
10 static const char *gd_flags_to_parser_name(void)
12 if (gd
->flags
& GD_FLG_HUSH_OLD_PARSER
)
14 if (gd
->flags
& GD_FLG_HUSH_MODERN_PARSER
)
19 static int do_cli_get(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
22 const char *current
= gd_flags_to_parser_name();
25 printf("current cli value is not valid, this should not happen!\n");
26 return CMD_RET_FAILURE
;
29 printf("%s\n", current
);
31 return CMD_RET_SUCCESS
;
34 static int parser_string_to_gd_flags(const char *parser
)
36 if (!strcmp(parser
, "old"))
37 return GD_FLG_HUSH_OLD_PARSER
;
38 if (!strcmp(parser
, "modern"))
39 return GD_FLG_HUSH_MODERN_PARSER
;
43 static int gd_flags_to_parser_config(int flag
)
45 if (gd
->flags
& GD_FLG_HUSH_OLD_PARSER
)
46 return CONFIG_VAL(HUSH_OLD_PARSER
);
47 if (gd
->flags
& GD_FLG_HUSH_MODERN_PARSER
)
48 return CONFIG_VAL(HUSH_MODERN_PARSER
);
52 static void reset_parser_gd_flags(void)
54 gd
->flags
&= ~GD_FLG_HUSH_OLD_PARSER
;
55 gd
->flags
&= ~GD_FLG_HUSH_MODERN_PARSER
;
58 static int do_cli_set(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
68 parser_name
= argv
[1];
70 parser_flag
= parser_string_to_gd_flags(parser_name
);
71 if (parser_flag
== -1) {
72 printf("Bad value for parser name: %s\n", parser_name
);
76 parser_config
= gd_flags_to_parser_config(parser_flag
);
77 switch (parser_config
) {
79 printf("Bad value for parser flags: %d\n", parser_flag
);
80 return CMD_RET_FAILURE
;
82 printf("Want to set current parser to %s, but its code was not compiled!\n",
84 return CMD_RET_FAILURE
;
87 reset_parser_gd_flags();
88 gd
->flags
|= parser_flag
;
93 /* cli_loop() should never return. */
94 return CMD_RET_FAILURE
;
97 static struct cmd_tbl parser_sub
[] = {
98 U_BOOT_CMD_MKENT(get
, 1, 1, do_cli_get
, "", ""),
99 U_BOOT_CMD_MKENT(set
, 2, 1, do_cli_set
, "", ""),
102 static int do_cli(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
108 return CMD_RET_USAGE
;
110 /* drop initial "parser" arg */
114 cp
= find_cmd_tbl(argv
[0], parser_sub
, ARRAY_SIZE(parser_sub
));
116 return cp
->cmd(cmdtp
, flag
, argc
, argv
);
118 return CMD_RET_USAGE
;
122 "get - print current cli\n"
123 "set - set the current cli, possible value are: old, modern\n");
125 U_BOOT_CMD(cli
, 3, 1, do_cli
,