aboutsummaryrefslogtreecommitdiff
path: root/common/cli_hush.c
AgeCommit message (Collapse)AuthorFilesLines
2021-05-17cli: slighly more clear error messagespeng.wang@smartm.com1-2/+2
This patch tries to distinguish two error messages. Signed-off-by: peng.wang@smartm.com <peng.wang@smartm.com>
2021-04-12hush: Fix assignments being misinterpreted as commandsSean Anderson1-1/+1
If there were no variable substitutions in a command, then initial assignments would be misinterpreted as commands, instead of being skipped over. This is demonstrated by the following example: => foo=bar echo baz Unknown command 'foo=bar' - try 'help' Signed-off-by: Sean Anderson <seanga2@gmail.com>
2021-02-02common: Drop asm/global_data.h from common headerSimon Glass1-0/+1
Move this out of the common header and include it only where needed. In a number of cases this requires adding "struct udevice;" to avoid adding another large header or in other cases replacing / adding missing header files that had been pulled in, very indirectly. Finally, we have a few cases where we did not need to include <asm/global_data.h> at all, so remove that include. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Rini <trini@konsulko.com>
2020-12-01cmd: Kconfig: migrate CONFIG_SYS_PROMPT_HUSH_PS2Patrick Delaunay1-3/+0
Move CONFIG_SYS_PROMPT_HUSH_PS2 in Kconfig, depending on CONFIG_HUSH_PARSER, and remove the default value defined in cli_hush.c under __U_BOOT__. Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-10-22cli_hush.c: remove broken sanity checkRasmus Villemoes1-8/+0
This code is intended do prevent one from setting a shell variable abc by doing abc=123 if an environment variable named abc already exists. However, the check is broken, since the env_get is done before the split on =, so we look up whether an environment variable "abc=123" exists, which is obviously never the case. One could move the code to below the split on =, but instead, just remove it, saving a little .text: The check has never worked as intended (it goes all the way back to the initial git commit), and it would anyway not guard against one first setting the shell variable, then doing 'env set abc xyz'. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2020-05-18command: Remove the cmd_tbl_t typedefSimon Glass1-2/+2
We should not use typedefs in U-Boot. They cannot be used as forward declarations which means that header files must include the full header to access them. Drop the typedef and rename the struct to remove the _s suffix which is now not useful. This requires quite a few header-file additions. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-01hush: avoid NULL check before free()Heinrich Schuchardt1-2/+1
free() checks if its argument is NULL. Don't duplicate this in the calling code. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2019-11-07hush: re-sequence includesHeinrich Schuchardt1-1/+1
'make tests' on a 32bit ARM system leads to In file included from ../common/cli_hush.c:79: ../include/malloc.h:364:7: error: conflicting types for ‘memset’ void* memset(void*, int, size_t); ^~~~~~ In file included from ../include/compiler.h:126, from ../include/env.h:12, from ../common/cli_hush.c:78: ../include/linux/string.h:103:15: note: previous declaration of ‘memset’ was here extern void * memset(void *,int,__kernel_size_t); ^~~~~~ In file included from ../common/cli_hush.c:79: ../include/malloc.h:365:7: error: conflicting types for ‘memcpy’ void* memcpy(void*, const void*, size_t); ^~~~~~ In file included from ../include/compiler.h:126, from ../include/env.h:12, from ../common/cli_hush.c:78: ../include/linux/string.h:106:15: note: previous declaration of ‘memcpy’ was here extern void * memcpy(void *,const void *,__kernel_size_t); ^~~~~~ According to the U-Boot coding style guide common.h should be the first include. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-08-11env: Move env_set() to env.hSimon Glass1-0/+1
Move env_set() over to the new header file. Acked-by: Joe Hershberger <joe.hershberger@ni.com> Signed-off-by: Simon Glass <sjg@chromium.org>
2018-05-07SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini1-2/+1
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
2017-08-16env: Rename getenv/_f() to env_get()Simon Glass1-7/+7
We are now using an env_ prefix for environment functions. Rename these two functions for consistency. Also add function comments in common.h. Quite a few places use getenv() in a condition context, provoking a warning from checkpatch. These are fixed up in this patch also. Suggested-by: Wolfgang Denk <wd@denx.de> Signed-off-by: Simon Glass <sjg@chromium.org>
2017-08-16env: Rename setenv() to env_set()Simon Glass1-1/+1
We are now using an env_ prefix for environment functions. Rename setenv() for consistency. Also add function comments in common.h. Suggested-by: Wolfgang Denk <wd@denx.de> Signed-off-by: Simon Glass <sjg@chromium.org>
2016-02-08hush: Add rudimentary support for PS1 and PS2Marek Vasut1-0/+10
Add trivial support for changing the U-Boot command prompt string by setting PS1 and PS2 environment variables. Only static variables are supported. Signed-off-by: Marek Vasut <marex@denx.de> Reviewed-by: Heiko Schocher <hs@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2016-02-08hush: Pull out U-Boot prompt display and read functionalityMarek Vasut1-5/+16
Pull the code which displays U-Boot prompt and reads the command line into a separate function. No functional change. Signed-off-by: Marek Vasut <marex@denx.de> Reviewed-by: Heiko Schocher <hs@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2015-12-12common: cli_hush: Fix up simple typoNishanth Menon1-2/+2
Correct the spelling for character.. Signed-off-by: Nishanth Menon <nm@ti.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2015-12-05common: cli_hush: avoid memory leakPeng Fan1-2/+7
Need to free memory avoid memory leak, when error. Signed-off-by: Peng Fan <Peng.Fan@freescale.com> Reviewed-by: Simon Glass <sjg@chromium.org> Cc: Simon Glass <sjg@chromium.org> Cc: Tom Rini <trini@konsulko.com>
2015-12-05common: cli_hush: avoid dead codePeng Fan1-1/+1
Condition "(value == NULL && ++value == NULL)" actully will always return false. Instead, use condition "(value == NULL || *(value + 1) == 0)" to detect such expression "c=". To "c=", *(value + 1) is 0, so directly return -1, but not continue. Signed-off-by: Peng Fan <Peng.Fan@freescale.com> Cc: Rabin Vincent <rabin@rab.in> Cc: Simon Glass <sjg@chromium.org> Cc: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2015-11-19Move console definitions into a new console.h fileSimon Glass1-0/+1
The console includes a global variable and several functions that are only used by a small subset of U-Boot files. Before adding more functions, move the definitions into their own header file. Signed-off-by: Simon Glass <sjg@chromium.org>
2014-11-24Revert "hush: fix segfault on syntax error"Rabin Vincent1-1/+1
128059b92 ("hush: fix segfault on syntax error") attempted to fix a segfault on syntax errors, but it broke Ctrl-C handling, and the assumption that it made, that rcode could not be -1, is incorrect. Revert this change. Reported-by: Stephen Warren <swarren@wwwdotorg.org> Reported-by: Przemyslaw Marczak <p.marczak@samsung.com> Signed-off-by: Rabin Vincent <rabin@rab.in>
2014-11-07hush: make run_command() return an error on parsing failureRabin Vincent1-1/+1
run_command() returns success even if the command had a syntax error; correct this behaviour. Signed-off-by: Rabin Vincent <rabin@rab.in> Acked-by: Simon Glass <sjg@chromium.org)
2014-11-07hush: fix segfault on syntax errorRabin Vincent1-1/+1
Hush segfaults if it sees a syntax error while attempting to parse a command: $ ./u-boot -c "'" ... syntax error Segmentation fault (core dumped) This is due to a NULL pointer dereference of in_str->p in static_peek(). The problem is that the exit condition for the loop in parse_stream_outer() checks for rcode not being -1, but rcode is only ever 0 or 1. Signed-off-by: Rabin Vincent <rabin@rab.in> Acked-by: Simon Glass <sjg@chromium.org) Tested-by: Simon Glass <sjg@chromium.org)
2014-11-07hush: return consistent codes from run_command()Rabin Vincent1-1/+3
Attempting to run: - an empty string - a string with just spaces returns different error codes, 1 for the empty string and 0 for the string with just spaces. Make both of them return 0 for consistency. Signed-off-by: Rabin Vincent <rabin@rab.in> Acked-by: Simon Glass <sjg@chromium.org)
2014-10-27cli: hush: Adjust 'run' command to run each line of the env varSimon Glass1-1/+2
The run command treats each argument an an environment variable. It gets the value of each variable and executes it as a command. If an environment variable contains a newline and the hush cli is used, it is supposed to execute each line one after the other. Normally a newline signals to hush to exit - this is used in normal command line entry - after a command is entered we want to return to allow the user to enter the next one. But environment variables obviously need to execute to completion. Add a special case for the execution of environment variables which continues when a newline is seen, and add a few tests to check this behaviour. Note: it's not impossible that this may cause regressions in other areas. I can't think of a case but with any change of behaviour with limited test coverage there is always a risk. From what I can tell this behaviour has been around since at least U-Boot 2011.03, although this pre-dates sandbox and I have not tested it on real hardware. Reported-by: Wolfgang Denk <wd@denx.de> Signed-off-by: Simon Glass <sjg@chromium.org>
2014-06-11common/cli_hush.c: remove unnecessary double bracesJeroen Hofstee1-2/+2
Clang interpretes an if condition like "if ((a = b) == NULL) as it tries to assign a value in a statement. Hence if you do "if ((something)) it warns you that you might be confused. Hence drop the double braces for plane if statements. Simon Glass <sjg@chromium.org> Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
2014-06-05Fix hush to give the correct return code for a simple commandSimon Glass1-1/+3
When a simple command like 'false' is provided, hush should return the result of that command. However, hush only does this if the FLAG_EXIT_FROM_LOOP flag is provided. Without this flag, hush will happily execute the empty string command immediate after 'false' and then return a success code. This behaviour does not seem very useful, and requiring the flag also seems wrong, since it means that hush will execute only the first command in a sequence. Add a check for empty string and fall out of the loop in that case. That at least fixes the simple command case. This is a change in behaviour but it is unlikely that the old behaviour would be considered correct in any case. Reported-by: Stefan Herbrechtsmeier <stefan@herbrechtsmeier.net> Signed-off-by: Simon Glass <sjg@chromium.org>
2014-05-29Rename bootretry functions and remove #ifdefsSimon Glass1-6/+1
Add a bootretry_ prefix to these two functions, and remove the need for the #ifdef around everything (it moves to the Makefile). Signed-off-by: Simon Glass <sjg@chromium.org>
2014-05-29Move bootretry code into bootretry.c and clean upSimon Glass1-0/+1
This code is only used by one board, so it seems a shame to clutter up the readline code with it. Move it into its own file. Signed-off-by: Simon Glass <sjg@chromium.org>
2014-05-29Add cli_ prefix to readline functionsSimon Glass1-2/+2
This makes it clear where the code resides. Signed-off-by: Simon Glass <sjg@chromium.org>
2014-05-29move CLI prototypes to cli.h and add commentsSimon Glass1-0/+1
Move the CLI prototypes from common.h to cli.h as part of an effort to reduce the size of common.h. Signed-off-by: Simon Glass <sjg@chromium.org>
2014-05-29Rename hush to cli_hushSimon Glass1-0/+3687
Hush is a command-line interpreter, so rename it to make that clearer. Signed-off-by: Simon Glass <sjg@chromium.org>