From 9c6d050966be910586aba358a8c63364afe37e03 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 19 Jan 2021 19:30:04 +0100 Subject: [PATCH 01/12] doc: document sbi command Add a man-page for the sbi command. Signed-off-by: Heinrich Schuchardt --- MAINTAINERS | 1 + doc/usage/index.rst | 1 + doc/usage/sbi.rst | 49 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 doc/usage/sbi.rst diff --git a/MAINTAINERS b/MAINTAINERS index a7a62dff81..e7a6dd9ce2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -951,6 +951,7 @@ S: Maintained T: git https://gitlab.denx.de/u-boot/custodians/u-boot-riscv.git F: arch/riscv/ F: cmd/riscv/ +F: doc/usage/sbi.rst F: drivers/timer/andes_plmt_timer.c F: drivers/timer/sifive_clint_timer.c F: tools/prelink-riscv.c diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 6def250766..eedcdb110b 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -19,3 +19,4 @@ Shell commands button mbr pstore + sbi diff --git a/doc/usage/sbi.rst b/doc/usage/sbi.rst new file mode 100644 index 0000000000..96d8861057 --- /dev/null +++ b/doc/usage/sbi.rst @@ -0,0 +1,49 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +sbi command +=========== + +Synopsis +-------- + +:: + + sbi + +Description +----------- + +The sbi command is used to display information about the SBI (Supervisor Binary +Interface) implementation on RISC-V systems. + +The output may look like: + +:: + + => sbi + SBI 0.2 + OpenSBI + Extensions: + sbi_set_timer + sbi_console_putchar + sbi_console_getchar + sbi_clear_ipi + sbi_send_ipi + sbi_remote_fence_i + sbi_remote_sfence_vma + sbi_remote_sfence_vma_asid + sbi_shutdown + SBI Base Functionality + Timer Extension + IPI Extension + RFENCE Extension + Hart State Management Extension + +The first line indicates the version of the RISC-V SBI specification. +The second line indicates the implementation. +The further lines enumerate the implemented extensions. + +Configuration +------------- + +To use the sbi command you must specify CONFIG_CMD_SBI=y. From 627b57bde05063b2f512d8e3ec6f8060aea25b91 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 20 Jan 2021 12:14:01 +0100 Subject: [PATCH 02/12] doc: describe exit command Man-page for exit shell command. Signed-off-by: Heinrich Schuchardt --- doc/usage/exit.rst | 40 ++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 41 insertions(+) create mode 100644 doc/usage/exit.rst diff --git a/doc/usage/exit.rst b/doc/usage/exit.rst new file mode 100644 index 0000000000..769223c477 --- /dev/null +++ b/doc/usage/exit.rst @@ -0,0 +1,40 @@ +exit command +============ + +Synopsis +-------- + +:: + + exit + +Description +----------- + +The exit command terminates a script started via the run or source command. +If scripts are nested, only the innermost script is left. + +:: + + => setenv inner 'echo entry inner; exit; echo inner done' + => setenv outer 'echo entry outer; run inner; echo outer done' + => run outer + entry outer + entry inner + outer done + => + +When executed outside a script a warning is written. Following commands are not +executed. + +:: + + => echo first; exit; echo last + first + exit not allowed from main input shell. + => + +Return value +------------ + +$? is always set to 0 (true). diff --git a/doc/usage/index.rst b/doc/usage/index.rst index eedcdb110b..b8f216b713 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -17,6 +17,7 @@ Shell commands bootefi bootmenu button + exit mbr pstore sbi From de702493c449200a0e84c8e6dcc58deb49837691 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 20 Jan 2021 18:09:30 +0100 Subject: [PATCH 03/12] doc: document for statement Create a man-page for the for statement. Signed-off-by: Heinrich Schuchardt --- doc/usage/for.rst | 65 +++++++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 66 insertions(+) create mode 100644 doc/usage/for.rst diff --git a/doc/usage/for.rst b/doc/usage/for.rst new file mode 100644 index 0000000000..f9e504979c --- /dev/null +++ b/doc/usage/for.rst @@ -0,0 +1,65 @@ +for command +=========== + +Synopis +------- + +:: + + for in ; do ; done + +Description +----------- + +The for command is used to loop over a list of values and execute a series of +commands for each of these. + +The counter variable of the loop is a shell variable. Please, keep in mind that +an environment variable takes precedence over a shell variable of the same name. + +variable + name of the counter variable + +items + space separated item list + +commands + commands to execute + +Example +------- + +:: + + => setenv c + => for c in 1 2 3; do echo item ${c}; done + item 1 + item 2 + item 3 + => echo ${c} + 3 + => setenv c x + => for c in 1 2 3; do echo item ${c}; done + item x + item x + item x + => + +The first line ensures that there is no environment variable *c*. Hence in the +first loop the shell variable *c* is printed. + +After defining an environment variable of name *c* it takes precedence over the +shell variable and the environment variable is printed. + +Return value +------------ + +The return value $? after the done statement is the return value of the last +statement executed in the loop. + +:: + + => for i in true false; do ${i}; done; echo $? + 1 + => for i in false true; do ${i}; done; echo $? + 0 diff --git a/doc/usage/index.rst b/doc/usage/index.rst index b8f216b713..6f49652758 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -18,6 +18,7 @@ Shell commands bootmenu button exit + for mbr pstore sbi From d018734c0cc2c21c69926a5c85293c1dd6fb3b2b Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 20 Jan 2021 12:13:30 +0100 Subject: [PATCH 04/12] cmd: change suppress newline in echo command By default the echo command emits its arguments followed by a line feed. If any of the arguments contains the sub-string "\c", the line feed is suppressed. This does not match shells used in Linux and BSD where the first argument has to be -n to suppress the line feed. The hush shell interferes with the parsing of backslashes. E.g. in the following command line quadruple backslashes are required for suppressing the line feed: for i in 1 2 3; do for j in 4 5; do echo \\\\c ${i}${j}; done; echo; done; To avoid unexpected behavior the patch changes echo to use -n as first argument to suppress the line feed. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- cmd/echo.c | 51 +++++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/cmd/echo.c b/cmd/echo.c index d02a4cfd58..fda844ee9d 100644 --- a/cmd/echo.c +++ b/cmd/echo.c @@ -10,47 +10,34 @@ static int do_echo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - int i; - int putnl = 1; + int i = 1; + bool space = false; + bool newline = true; - for (i = 1; i < argc; i++) { - char *p = argv[i]; - char *nls; /* new-line suppression */ - - if (i > 1) - putc(' '); - - nls = strstr(p, "\\c"); - if (nls) { - char *prenls = p; - - putnl = 0; - /* - * be paranoid and guess that someone might - * say \c more than once - */ - while (nls) { - *nls = '\0'; - puts(prenls); - *nls = '\\'; - prenls = nls + 2; - nls = strstr(prenls, "\\c"); - } - puts(prenls); - } else { - puts(p); + if (argc > 1) { + if (!strcmp(argv[1], "-n")) { + newline = false; + ++i; } } - if (putnl) + for (; i < argc; ++i) { + if (space) { + putc(' '); + } + puts(argv[i]); + space = true; + } + + if (newline) putc('\n'); return 0; } U_BOOT_CMD( - echo, CONFIG_SYS_MAXARGS, 1, do_echo, + echo, CONFIG_SYS_MAXARGS, 1, do_echo, "echo args to console", - "[args..]\n" - " - echo args to console; \\c suppresses newline" + "[-n] [args..]\n" + " - echo args to console; -n suppresses newline" ); From c0445c18d3cd97b6ebc81355d239efefe771f0aa Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 21 Jan 2021 18:41:28 +0100 Subject: [PATCH 05/12] test: unit test for echo command Provide a unit test for the unit command Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- test/cmd/Makefile | 3 +++ test/cmd/test_echo.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 test/cmd/test_echo.c diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 758bc14273..5451e9ea90 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -2,6 +2,9 @@ # # Copyright (c) 2013 Google, Inc +ifdef CONFIG_HUSH_PARSER +obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o +endif obj-y += mem.o obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o obj-$(CONFIG_CMD_PWM) += pwm.o diff --git a/test/cmd/test_echo.c b/test/cmd/test_echo.c new file mode 100644 index 0000000000..4183cf75bb --- /dev/null +++ b/test/cmd/test_echo.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for echo command + * + * Copyright 2020, Heinrich Schuchadt + */ + +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +struct test_data { + char *cmd; + char *expected; +}; + +static struct test_data echo_data[] = { + {"echo 1 2 3", + "1 2 3"}, + /* Test new line handling */ + {"echo -n 1 2 3; echo a b c", + "1 2 3a b c"}, + /* + * Test handling of environment variables. + * + * j, q, x are among the least frequent letters in English. + * Hence no collision for the variable name jQx is expected. + */ + {"setenv jQx X; echo \"a)\" ${jQx} 'b)' '${jQx}' c) ${jQx}; setenv jQx", + "a) X b) ${jQx} c) X"}, + /* Test handling of shell variables. */ + {"setenv jQx; for jQx in 1 2 3; do echo -n \"${jQx}, \"; done; echo;", + "1, 2, 3, "}, +}; + +static int lib_test_hush_echo(struct unit_test_state *uts) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(echo_data); ++i) { + console_record_reset_enable(); + ut_assertok(run_command(echo_data[i].cmd, 0)); + gd->flags &= ~GD_FLG_RECORD; + console_record_readline(uts->actual_str, + sizeof(uts->actual_str)); + ut_asserteq_str(echo_data[i].expected, uts->actual_str); + ut_assertok(ut_check_console_end(uts)); + } + return 0; +} + +LIB_TEST(lib_test_hush_echo, 0); From 750ff62da7e76e2c71a782853c52c0a863b40d5d Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 21 Jan 2021 17:33:44 +0100 Subject: [PATCH 06/12] doc: document echo command Provide a man-page for the echo command. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- doc/usage/echo.rst | 65 +++++++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 66 insertions(+) create mode 100644 doc/usage/echo.rst diff --git a/doc/usage/echo.rst b/doc/usage/echo.rst new file mode 100644 index 0000000000..861abdfd1e --- /dev/null +++ b/doc/usage/echo.rst @@ -0,0 +1,65 @@ +echo command +============ + +Synopsis +-------- + +:: + + echo [-n] [args ...] + +Description +----------- + +The echo command prints its arguments to the console separated by spaces. + +-n + Do not print a line feed after the last argument. + +args + Arguments to be printed. The arguments are evaluated before being passed to + the command. + +Examples +-------- + +Strings are parsed before the arguments are passed to the echo command: + +:: + + => echo "a" 'b' c + a b c + => + +Observe how variables included in strings are handled: + +:: + + => setenv var X; echo "a)" ${var} 'b)' '${var}' c) ${var} + a) X b) ${var} c) X + => + + +-n suppresses the line feed: + +:: + + => echo -n 1 2 3; echo a b c + 1 2 3a b c + => echo -n 1 2 3 + 1 2 3=> + +A more complex example: + +:: + + => for i in a b c; do for j in 1 2 3; do echo -n "${i}${j}, "; done; echo; done; + a1, a2, a3, + b1, b2, b3, + c1, c2, c3, + => + +Return value +------------ + +The return value $? is always set to 0 (true). diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 6f49652758..317db3b449 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -17,6 +17,7 @@ Shell commands bootefi bootmenu button + echo exit for mbr From b911208f41854e791503ef7f32113d2f31fc1542 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 22 Jan 2021 13:16:04 +0100 Subject: [PATCH 07/12] cmd: correct long text loadb, loadx, loady The first argument is the load address and not an offset. The second argument cannot be entered without the first one. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- cmd/load.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/load.c b/cmd/load.c index c6a7cc4651..f252c74894 100644 --- a/cmd/load.c +++ b/cmd/load.c @@ -1065,25 +1065,25 @@ U_BOOT_CMD( U_BOOT_CMD( loadb, 3, 0, do_load_serial_bin, "load binary file over serial line (kermit mode)", - "[ off ] [ baud ]\n" + "[ addr [ baud ] ]\n" " - load binary file over serial line" - " with offset 'off' and baudrate 'baud'" + " at address 'addr' with baudrate 'baud'" ); U_BOOT_CMD( loadx, 3, 0, do_load_serial_bin, "load binary file over serial line (xmodem mode)", - "[ off ] [ baud ]\n" + "[ addr [ baud ] ]\n" " - load binary file over serial line" - " with offset 'off' and baudrate 'baud'" + " at address 'addr' with baudrate 'baud'" ); U_BOOT_CMD( loady, 3, 0, do_load_serial_bin, "load binary file over serial line (ymodem mode)", - "[ off ] [ baud ]\n" + "[ addr [ baud ] ]\n" " - load binary file over serial line" - " with offset 'off' and baudrate 'baud'" + " at address 'addr' with baudrate 'baud'" ); #endif /* CONFIG_CMD_LOADB */ From a3ad3079c007adb08d24a30855b188f5cdd4ec97 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 22 Jan 2021 19:18:01 +0100 Subject: [PATCH 08/12] doc: describe loady command Create a man-page for the loady command. Signed-off-by: Heinrich Schuchardt --- doc/usage/index.rst | 1 + doc/usage/loady.rst | 67 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 doc/usage/loady.rst diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 317db3b449..1304b59aad 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -20,6 +20,7 @@ Shell commands echo exit for + loady mbr pstore sbi diff --git a/doc/usage/loady.rst b/doc/usage/loady.rst new file mode 100644 index 0000000000..2819cc72ae --- /dev/null +++ b/doc/usage/loady.rst @@ -0,0 +1,67 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +loady command +============= + +Synopsis +-------- + +:: + + loady [addr [baud]] + +Description +----------- + +The loady command is used to transfer a file to the device via the serial line +using the YMODEM protocol. + +The number of transferred bytes is saved in environment variable filesize. + +addr + load address, defaults to environment variable loadaddr or if loadaddr is + not set to configuration variable CONFIG_SYS_LOAD_ADDR + +baud + baud rate for the ymodem transmission. After the transmission the baud + rate is reset to the original value. + +Example +------- + +In the example below the terminal emulation program picocom was used to +transfer a file to the device. + +After entering the loady command the key sequence is used to +let picocom prompt for the file name. Picocom invokes the program sz for the +file transfer. + +:: + + => loady 80064000 115200 + ## Ready for binary (ymodem) download to 0x80064000 at 115200 bps... + C + *** file: BOOTRISCV64.EFI + $ sz -b -vv BOOTRISCV64.EFI + Sending: BOOTRISCV64.EFI + Bytes Sent: 398976 BPS:7883 + Sending: + Ymodem sectors/kbytes sent: 0/ 0k + Transfer complete + + *** exit status: 0 *** + /1(CAN) packets, 4 retries + ## Total Size = 0x0006165f = 398943 Bytes + => echo ${filesize} + 6165f + => + +Configuration +------------- + +The command is only available if CONFIG_CMD_LOADB=y. + +Return value +------------ + +The return value $? is always 0 (true). From 9d4445bc6dd314cc34aaeeac1c03d5bdb6761cca Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 22 Jan 2021 19:25:53 +0100 Subject: [PATCH 09/12] doc: document true command Create a man-page for the true command. Signed-off-by: Heinrich Schuchardt --- doc/usage/index.rst | 1 + doc/usage/true.rst | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 doc/usage/true.rst diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 1304b59aad..d3abf2d88a 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -24,3 +24,4 @@ Shell commands mbr pstore sbi + true diff --git a/doc/usage/true.rst b/doc/usage/true.rst new file mode 100644 index 0000000000..f9ef71b2d1 --- /dev/null +++ b/doc/usage/true.rst @@ -0,0 +1,28 @@ +true command +============ + +Synopsis +-------- + +:: + + true + +Description +----------- + +The true command sets the return value $? to 0 (true). + +Example +------- + +:: + + => true; echo $? + 0 + => + +Configuration +------------- + +The true command is only available if CONFIG_HUSH_PARSER=y. From a03185a3ecbc5a51fbae9c1790b6148f8c68b1be Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 24 Jan 2021 21:48:00 +0100 Subject: [PATCH 10/12] dm: core: describe uclass_root_s 'make htmldocs' creates a warning: ./include/asm-generic/global_data.h:443: warning: Function parameter or member 'uclass_root_s' not described in 'global_data' Correct the member descriptions. Cc: Simon Glass Signed-off-by: Heinrich Schuchardt --- include/asm-generic/global_data.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 19f70393b4..b6f707e97e 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -198,13 +198,21 @@ struct global_data { */ struct udevice *dm_root_f; /** - * @uclass_root: head of core tree + * @uclass_root_s: + * head of core tree when uclasses are not in read-only memory. + * + * When uclasses are in read-only memory, @uclass_root_s is not used and + * @uclass_root points to the root node generated by dtoc. */ struct list_head uclass_root_s; /** - * @uclass_root: pointer to head of core tree, if uclasses are in - * read-only memory and cannot be adjusted to use @uclass_root as a - * list head. + * @uclass_root: + * pointer to head of core tree, if uclasses are in read-only memory and + * cannot be adjusted to use @uclass_root as a list head. + * + * When not in read-only memory, @uclass_root_s is used to hold the + * uclass root, and @uclass_root points to the address of + * @uclass_root_s. */ struct list_head *uclass_root; # if CONFIG_IS_ENABLED(OF_PLATDATA) From bce86e075fbe8b54262b73380846f10a9e9a0c0d Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 24 Jan 2021 22:11:55 +0100 Subject: [PATCH 11/12] doc: describe the false command Provide a man-page for the false command. Signed-off-by: Heinrich Schuchardt --- doc/usage/false.rst | 28 ++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 29 insertions(+) create mode 100644 doc/usage/false.rst diff --git a/doc/usage/false.rst b/doc/usage/false.rst new file mode 100644 index 0000000000..a17fe86021 --- /dev/null +++ b/doc/usage/false.rst @@ -0,0 +1,28 @@ +false command +============= + +Synopsis +-------- + +:: + + false + +Description +----------- + +The false command sets the return value $? to 1 (false). + +Example +------- + +:: + + => false; echo $? + 1 + => + +Configuration +------------- + +The false command is only available if CONFIG_HUSH_PARSER=y. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index d3abf2d88a..0309abf2ff 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -19,6 +19,7 @@ Shell commands button echo exit + false for loady mbr From 5b6dac01e636aa8b799a68c115d9fd86e4bbbf09 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 25 Jan 2021 01:11:47 +0100 Subject: [PATCH 12/12] doc: describe command conitrace Provide a man-page for the conitrace command. Signed-off-by: Heinrich Schuchardt --- doc/usage/conitrace.rst | 54 +++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 55 insertions(+) create mode 100644 doc/usage/conitrace.rst diff --git a/doc/usage/conitrace.rst b/doc/usage/conitrace.rst new file mode 100644 index 0000000000..d9916c865e --- /dev/null +++ b/doc/usage/conitrace.rst @@ -0,0 +1,54 @@ +conitrace command +================= + +Synopsis +-------- + +:: + + conitrace + +Description +----------- + +The conitrace command is used to test the correct function of the console input +driver. It is especially valuable for checking the support for special keys like + or . + +To display escape sequences on a single line the output only advances to the +next line after detecting a pause of a few milliseconds. + +The output is hexadecimal. + +Examples +-------- + +Entering keys + +:: + + => conitrace + Waiting for your input + To terminate type 'x' + 62 + 42 + 02 + => + +Entering keys + +:: + + => conitrace + Waiting for your input + To terminate type 'x' + 1b 4f 50 + 1b 5b 48 + 1b 5b 33 7e + 7f + => + +Configuration +------------- + +The conitrace command is only available if CONFIG_CMD_CONITRACE=y. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 0309abf2ff..f75bd08237 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -17,6 +17,7 @@ Shell commands bootefi bootmenu button + conitrace echo exit false