aboutsummaryrefslogtreecommitdiff
path: root/common/cli.c
diff options
context:
space:
mode:
authorFrancis Laniel <francis.laniel@amarulasolutions.com>2023-12-22 22:02:32 +0100
committerTom Rini <trini@konsulko.com>2023-12-28 12:02:56 -0500
commit9a068377313c1feabb55072d2d1157999cf9d15e (patch)
tree19502dfd7079f0c040ec2cb0a9efeedd3ee60cec /common/cli.c
parent6bb39f5d16e8531eeca8237454cc528aa54c9e81 (diff)
cli: Enables using modern hush parser as command line parser
If one defines HUSH_MODERN_PARSER, it is then possible to use modern parser with: => cli get old => cli set modern => cli get modern Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>
Diffstat (limited to 'common/cli.c')
-rw-r--r--common/cli.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/common/cli.c b/common/cli.c
index d419671e8c..b3eb512b62 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -43,12 +43,15 @@ int run_command(const char *cmd, int flag)
return 1;
return 0;
-#else
+#elif CONFIG_IS_ENABLED(HUSH_OLD_PARSER)
int hush_flags = FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP;
if (flag & CMD_FLAG_ENV)
hush_flags |= FLAG_CONT_ON_NEWLINE;
return parse_string_outer(cmd, hush_flags);
+#else /* HUSH_MODERN_PARSER */
+ /* Not yet implemented. */
+ return 1;
#endif
}
@@ -108,7 +111,12 @@ int run_command_list(const char *cmd, int len, int flag)
buff[len] = '\0';
}
#ifdef CONFIG_HUSH_PARSER
+#if CONFIG_IS_ENABLED(HUSH_OLD_PARSER)
rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON);
+#else /* HUSH_MODERN_PARSER */
+ /* Not yet implemented. */
+ rcode = 1;
+#endif
#else
/*
* This function will overwrite any \n it sees with a \0, which
@@ -254,8 +262,13 @@ err:
void cli_loop(void)
{
bootstage_mark(BOOTSTAGE_ID_ENTER_CLI_LOOP);
-#ifdef CONFIG_HUSH_PARSER
- parse_file_outer();
+#if CONFIG_IS_ENABLED(HUSH_PARSER)
+ if (gd->flags & GD_FLG_HUSH_MODERN_PARSER)
+ parse_and_run_file();
+ else if (gd->flags & GD_FLG_HUSH_OLD_PARSER)
+ parse_file_outer();
+
+ printf("Problem\n");
/* This point is never reached */
for (;;);
#elif defined(CONFIG_CMDLINE)
@@ -268,10 +281,23 @@ void cli_loop(void)
void cli_init(void)
{
#ifdef CONFIG_HUSH_PARSER
+ /* This if block is used to initialize hush parser gd flag. */
if (!(gd->flags & GD_FLG_HUSH_OLD_PARSER)
- && CONFIG_IS_ENABLED(HUSH_OLD_PARSER))
- gd->flags |= GD_FLG_HUSH_OLD_PARSER;
- u_boot_hush_start();
+ && !(gd->flags & GD_FLG_HUSH_MODERN_PARSER)) {
+ if (CONFIG_IS_ENABLED(HUSH_OLD_PARSER))
+ gd->flags |= GD_FLG_HUSH_OLD_PARSER;
+ else if (CONFIG_IS_ENABLED(HUSH_MODERN_PARSER))
+ gd->flags |= GD_FLG_HUSH_MODERN_PARSER;
+ }
+
+ if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+ u_boot_hush_start();
+ } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+ u_boot_hush_start_modern();
+ } else {
+ printf("No valid hush parser to use, cli will not initialized!\n");
+ return;
+ }
#endif
#if defined(CONFIG_HUSH_INIT_VAR)