diff options
| author | Tom Rini <[email protected]> | 2023-12-28 12:03:25 -0500 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2023-12-28 14:38:25 -0500 |
| commit | 2b28c3b871cd5d55b19f0a86cef970139f8ab952 (patch) | |
| tree | e65243d1c47743f2823ef7943e51efdf7caf1733 /include | |
| parent | 64e47952f594e28b24a57d98c482a6e0be0268c6 (diff) | |
| parent | 2a58783f9495ae3512937a8a035c9d6452401e46 (diff) | |
Merge patch series "Modernize U-Boot shell"
Francis Laniel <[email protected]> says:
During 2021 summer, Sean Anderson wrote a contribution to add a new shell, based
on LIL, to U-Boot [1, 2].
While one of the goals of this contribution was to address the fact actual
U-Boot shell, which is based on Busybox hush, is old there was a discussion
about adding a new shell versus updating the actual one [3, 4].
So, in this series, with Harald Seiler, we updated the actual U-Boot shell to
reflect what is currently in Busybox source code.
Basically, this contribution is about taking a snapshot of Busybox shell/hush.c
file (as it exists in commit 37460f5da) and adapt it to suit U-Boot needs.
This contribution was written to be as backward-compatible as possible to avoid
breaking the existing.
So, the modern hush flavor offers the same as the actual, that is to say:
1. Variable expansion.
2. Instruction lists (;, && and ||).
3. If, then and else.
4. Loops (for, while and until).
No new features offered by Busybox hush were implemented (e.g. functions).
It is possible to change the parser at runtime using the "cli" command:
=> cli print
old
=> cli set modern
=> cli print
modern
=> cli set old
The default parser is the old one.
Note that to use both parser, you would need to set both
CONFIG_HUSH_MODERN_PARSER and CONFIG_HUSH_OLD_PARSER.
In terms of testing, new unit tests were added to ut to ensure the new behavior
is the same as the old one and it does not add regression.
Nonetheless, if old behavior was buggy and fixed upstream, the fix is then added
to U-Boot [5].
In sandbox, all of these tests pass smoothly:
=> printenv board
board=sandbox
=> ut hush
Running 20 hush tests
...
Failures: 0
=> cli set modern
=> ut hush
Running 20 hush tests
...
Failures: 0
Thanks to the effort of Harald Seiler, I was successful booting a board:
=> printenv fdtfile
fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb
=> cli get
old
=> boot
...
root@lepotato:~#
root@lepotato:~# reboot
...
=> cli set modern
=> cli get
modern
=> printenv fdtfile
fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb
=> boot
...
root@lepotato:~#
This contribution indeed adds a lot of code and there were concern about its
size [6, 7].
With regard to the amount of code added, the cli_hush_upstream.c is 13030 lines
long but it seems a smaller subset is really used:
gcc -D__U_BOOT__ -E common/cli_hush_upstream.c | wc -l
2870
Despite this, it is better to still have the whole upstream code for the sake of
easing maintenance.
With regard to memory size, I conducted some experiments for version 8 of this
series and for a subset of arm64 boards and found the worst case to be 4K [8].
Tom Rini conducted more research on this and also found the increase to be
acceptable [9].
If you want to review it - your review will really be appreciated - here are
some information regarding the commits:
* commits marked as "test:" deal with unit tests.
* commit "cli: Add Busybox upstream hush.c file." copies Busybox shell/hush.c
into U-Boot tree, this explain why this commit contains around 12000 additions.
* commit "cli: Port Busybox 2021 hush to U-Boot." modifies previously added file
to permit us to use this as new shell.
The really good idea of #include'ing Busybox code into a wrapper file to define
some particular functions while minimizing modifications to upstream code comes
from Harald Seiler.
* commit "cmd: Add new parser command" adds a new command which permits
selecting parser at runtime.
I am not really satisfied with the fact it calls cli_init() and cli_loop() each
time the parser is set, so your reviews would be welcomed.
* Other commits focus on enabling features we need (e.g. if).
Diffstat (limited to 'include')
| -rw-r--r-- | include/asm-generic/global_data.h | 8 | ||||
| -rw-r--r-- | include/cli_hush.h | 51 | ||||
| -rw-r--r-- | include/test/hush.h | 15 | ||||
| -rw-r--r-- | include/test/suites.h | 1 |
4 files changed, 73 insertions, 2 deletions
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index e8c6412e3f8..99bde9ec7e4 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -697,6 +697,14 @@ enum gd_flags { * @GD_FLG_BLOBLIST_READY: bloblist is ready for use */ GD_FLG_BLOBLIST_READY = 0x800000, + /** + * @GD_FLG_HUSH_OLD_PARSER: Use hush old parser. + */ + GD_FLG_HUSH_OLD_PARSER = 0x1000000, + /** + * @GD_FLG_HUSH_MODERN_PARSER: Use hush 2021 parser. + */ + GD_FLG_HUSH_MODERN_PARSER = 0x2000000, }; #endif /* __ASSEMBLY__ */ diff --git a/include/cli_hush.h b/include/cli_hush.h index 2bd35670c73..007b8d6372f 100644 --- a/include/cli_hush.h +++ b/include/cli_hush.h @@ -12,11 +12,58 @@ #define FLAG_REPARSING (1 << 2) /* >=2nd pass */ #define FLAG_CONT_ON_NEWLINE (1 << 3) /* continue when we see \n */ +#if CONFIG_IS_ENABLED(HUSH_OLD_PARSER) extern int u_boot_hush_start(void); -extern int parse_string_outer(const char *, int); +extern int parse_string_outer(const char *str, int flag); extern int parse_file_outer(void); - int set_local_var(const char *s, int flg_export); +#else +static inline int u_boot_hush_start(void) +{ + return 0; +} + +static inline int parse_string_outer(const char *str, int flag) +{ + return 1; +} + +static inline int parse_file_outer(void) +{ + return 0; +} + +static inline int set_local_var(const char *s, int flg_export) +{ + return 0; +} +#endif +#if CONFIG_IS_ENABLED(HUSH_MODERN_PARSER) +extern int u_boot_hush_start_modern(void); +extern int parse_string_outer_modern(const char *str, int flag); +extern void parse_and_run_file(void); +int set_local_var_modern(char *s, int flg_export); +#else +static inline int u_boot_hush_start_modern(void) +{ + return 0; +} + +static inline int parse_string_outer_modern(const char *str, int flag) +{ + return 1; +} + +static inline void parse_and_run_file(void) +{ +} + +static inline int set_local_var_modern(char *s, int flg_export) +{ + return 0; +} +#endif + void unset_local_var(const char *name); char *get_local_var(const char *s); diff --git a/include/test/hush.h b/include/test/hush.h new file mode 100644 index 00000000000..cca66544a06 --- /dev/null +++ b/include/test/hush.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * (C) Copyright 2021 + * Francis Laniel, Amarula Solutions, [email protected] + */ + +#ifndef __TEST_HUSH_H__ +#define __TEST_HUSH_H__ + +#include <test/test.h> + +/* Declare a new environment test */ +#define HUSH_TEST(_name, _flags) UNIT_TEST(_name, _flags, hush_test) + +#endif /* __TEST_HUSH_H__ */ diff --git a/include/test/suites.h b/include/test/suites.h index 49224d8ea2e..365d5f20dfe 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -43,6 +43,7 @@ int do_ut_env(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_exit(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_ut_hush(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]); |
