From 603a814a3358eccdb8955bc228f9180173575083 Mon Sep 17 00:00:00 2001 From: Francis Laniel Date: Fri, 22 Dec 2023 22:02:30 +0100 Subject: global_data.h: add GD_FLG_HUSH_OLD_PARSER flag This flag is used to indicate we are using the hush parser. Reviewed-by: Simon Glass Signed-off-by: Francis Laniel --- common/cli.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'common/cli.c') diff --git a/common/cli.c b/common/cli.c index 3916a7b10a7..e5fe1060d0b 100644 --- a/common/cli.c +++ b/common/cli.c @@ -268,6 +268,8 @@ void cli_loop(void) void cli_init(void) { #ifdef CONFIG_HUSH_PARSER + if (!(gd->flags & GD_FLG_HUSH_OLD_PARSER)) + gd->flags |= GD_FLG_HUSH_OLD_PARSER; u_boot_hush_start(); #endif -- cgit v1.2.3 From 6bb39f5d16e8531eeca8237454cc528aa54c9e81 Mon Sep 17 00:00:00 2001 From: Francis Laniel Date: Fri, 22 Dec 2023 22:02:31 +0100 Subject: cmd: Add new cli command This command can be used to print the current parser with 'cli get'. It can also be used to set the current parser with 'cli set'. For the moment, only one value is valid for set: old. Signed-off-by: Francis Laniel --- common/cli.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'common/cli.c') diff --git a/common/cli.c b/common/cli.c index e5fe1060d0b..d419671e8c8 100644 --- a/common/cli.c +++ b/common/cli.c @@ -268,7 +268,8 @@ void cli_loop(void) void cli_init(void) { #ifdef CONFIG_HUSH_PARSER - if (!(gd->flags & GD_FLG_HUSH_OLD_PARSER)) + 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(); #endif -- cgit v1.2.3 From 9a068377313c1feabb55072d2d1157999cf9d15e Mon Sep 17 00:00:00 2001 From: Francis Laniel Date: Fri, 22 Dec 2023 22:02:32 +0100 Subject: 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 Signed-off-by: Francis Laniel --- common/cli.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'common/cli.c') diff --git a/common/cli.c b/common/cli.c index d419671e8c8..b3eb512b623 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) -- cgit v1.2.3 From 3ea3c57ef5c5853f54714a3df8b0d406e8d4dd1c Mon Sep 17 00:00:00 2001 From: Francis Laniel Date: Fri, 22 Dec 2023 22:02:35 +0100 Subject: cli: add modern hush as parser for run_command*() Enables using, in code, modern hush as parser for run_command function family. It also enables the command run to be used by CLI user of modern hush. Reviewed-by: Simon Glass Signed-off-by: Francis Laniel --- common/cli.c | 67 +++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 17 deletions(-) (limited to 'common/cli.c') diff --git a/common/cli.c b/common/cli.c index b3eb512b623..a34938294ec 100644 --- a/common/cli.c +++ b/common/cli.c @@ -25,6 +25,14 @@ #include #ifdef CONFIG_CMDLINE + +static inline bool use_hush_old(void) +{ + return IS_ENABLED(CONFIG_HUSH_SELECTABLE) ? + gd->flags & GD_FLG_HUSH_OLD_PARSER : + IS_ENABLED(CONFIG_HUSH_OLD_PARSER); +} + /* * Run a command using the selected parser. * @@ -43,15 +51,30 @@ int run_command(const char *cmd, int flag) return 1; return 0; -#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; +#else + if (use_hush_old()) { + 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); + } + /* + * Possible values for flags are the following: + * FLAG_EXIT_FROM_LOOP: This flags ensures we exit from loop in + * parse_and_run_stream() after first iteration while normal + * behavior, * i.e. when called from cli_loop(), is to loop + * infinitely. + * FLAG_PARSE_SEMICOLON: modern Hush parses ';' and does not stop + * first time it sees one. So, I think we do not need this flag. + * FLAG_REPARSING: For the moment, I do not understand the goal + * of this flag. + * FLAG_CONT_ON_NEWLINE: This flag seems to be used to continue + * parsing even when reading '\n' when coming from + * run_command(). In this case, modern Hush reads until it finds + * '\0'. So, I think we do not need this flag. + */ + return parse_string_outer_modern(cmd, FLAG_EXIT_FROM_LOOP); #endif } @@ -67,12 +90,23 @@ int run_command_repeatable(const char *cmd, int flag) #ifndef CONFIG_HUSH_PARSER return cli_simple_run_command(cmd, flag); #else + int ret; + + if (use_hush_old()) { + ret = parse_string_outer(cmd, + FLAG_PARSE_SEMICOLON + | FLAG_EXIT_FROM_LOOP); + } else { + ret = parse_string_outer_modern(cmd, + FLAG_PARSE_SEMICOLON + | FLAG_EXIT_FROM_LOOP); + } + /* * parse_string_outer() returns 1 for failure, so clean up * its result. */ - if (parse_string_outer(cmd, - FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP)) + if (ret) return -1; return 0; @@ -111,12 +145,11 @@ 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 + if (use_hush_old()) { + rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON); + } else { + rcode = parse_string_outer_modern(buff, FLAG_PARSE_SEMICOLON); + } #else /* * This function will overwrite any \n it sees with a \0, which -- cgit v1.2.3