Commit graph

524 commits

Author SHA1 Message Date
Rick Talbott 829b91ab2f shell: Fix scrolling long commands in history
This fixes scrolling long commands in command history in the shell

Signed-off-by: Rick Talbott <richard.talbott1@t-mobile.com>
2023-09-13 16:26:02 +02:00
Rick Talbott 774da57db9 shell: Add shell command command rem
Added the shell comment command.

Signed-off-by: Rick Talbott <richard.talbott1@t-mobile.com>
2023-09-06 14:02:38 +02:00
Jakub Rzeszutko 14b1d0283c shell: make ascii filtering optional
Added configuration parameter to toggle shell ascii filtering
feature.

Fixes #59048

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2023-08-29 19:22:16 +03:00
Georges Oates_Larsen b25ea4742e net: conn_mgr: Rename connectivity monitor
The connectivity monitoring subfeature of conn_mgr is currently also
named conn_mgr, which is confusing.

This commit renames it to conn_mgr_monitor, or conn_mgr_mon for short,
for clarity.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-08-29 16:13:37 +02:00
Christopher Friedt e6c6d82a00 shell: date_service: conditionally include posix/time.h
When compiling for ARCH_POSIX, include `time.h` rather than
`posix/time.h`.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-23 10:06:00 +02:00
Andrei Emeltchenko 2bf4ab625a shell: Set right SERIAL_INIT_PRIORITY if ACPI enabled
Set correct SHELL_BACKEND_SERIAL_INIT_PRIORITY if ACPI is enabled.
Otherwise when enabling SHELL using menuconfig, etc serial backend is
not working.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-08-21 10:55:52 +02:00
Grant Ramsay 07b2731de5 shell: Increase the default shell stack size for 64bit
The default stack size is too small on 64bit.
Some standard shell commands cause stack overflow

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-08-18 10:13:12 +02:00
Daniel Leung 565c5d476e shell: rename shadow variables
This renames shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-10 08:14:12 +00:00
Jakub Rzeszutko bdeb62d116 shell: fix possible negative indexing
Fixes #60808

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2023-07-27 10:20:04 +02:00
Yong Cong Sin 7fba7d3957 shell: mqtt: fix uint32_t compared against 0
Fix unsigned compared against 0 reported by coverity check.
CID: 321096

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2023-07-11 18:21:46 +00:00
Florian Grandel c88a9ef272 segger: rtt: disable unsupported shell/log features
The RTT backend of the shell does not support several of the more
advanced terminal features. This commit proposes to inactivate these
features by default when RTT is selected as shell backend.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 14:42:41 +02:00
Gerard Marull-Paretas 48b201cc53 device: make device dependencies optional
Device dependencies are not always required, so make them optional via
CONFIG_DEVICE_DEPS. When enabled, the gen_device_deps script will run so
that dependencies are collected and part of the final image. Related
APIs will be also made available. Since device dependencies are used in
just a few places (power domains), disable the feature by default. When
not enabled, a second linking pass will not be required.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-06-21 09:32:05 +02:00
Maxim Adelman ecf2cb5932 kernel shell, stacks shell commands: iterate unlocked on SMP
call k_thread_foreach_unlocked to avoid assertions caused
by calling shell_print while holding a global lock

Signed-off-by: Maxim Adelman <imax@meta.com>
2023-06-15 05:55:56 -04:00
Emil Gydesen 7bce75bd0d Shell: Add missing long long type in shell_strtoull
shell_strtoull used a unsigned long instead of a unsigned
long long to store the result in stroull, so the return
value may have been truncated.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-13 07:08:04 -04:00
Lars Knudsen fb408077df shell: Fix shell_vfprintf when vt100 is disabled
Without this fix, for every call to shell_vfprintf,
a prompt string and vt100 codes are printed too,
resulting in mangled log output.

Signed-off-by: Lars Knudsen <lakd@demant.com>
2023-06-09 11:44:49 -04:00
Emil Gydesen de3e709b50 Shell: Add shell_strtoull
Add a shell_strtoull function that works similar to
shell_strtoul except that it calls strtoull instead
of strtoul.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 07:05:20 -04:00
Wojciech Slenska db7803b60e shell: shell_cmds: added prompt commands
Added command for enabling/disabling shell prompt.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2023-05-22 12:03:03 +02:00
Gerard Marull-Paretas dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Gerard Marull-Paretas 13f87494bb shell: device_service: remove levels command
While it may be useful in some contexts, this information can be
obtained at compile time. Removing this command allows to migrate the
device infrastructure code to standard iterable sections, done later.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-12 12:01:10 +02:00
Georges Oates_Larsen 716c19f7ef net: conn_mgr: Reorganize files
Since conn_mgr is a subsystem rather than a library, relocate it
directly into subsys/net rather than subsys/net/lib/

Rename header files to better match their function.

Remove net_ prefix from conn_mgr types, API, and files, since it is
unnecessary.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Hunter Searle 898a59eb80 Shell: Edit shell to store/retrieve return values
This change to the shell API enables the user to retrieve the
return code of the most recently run shell command. This is
useful both for users wanting specific information beyond the print
statements in a command, but especially for automated users
that prefer a simple return code to parsing human readable text.
This was tested using all default shell commands, as well as
eeprom, flash, and i2c, where specific errors could be forced.
In all cases, the correct return value was returned by the new
retval command.

Signed-off-by: Hunter Searle <hsearle@xes-inc.com>
2023-05-02 16:52:21 +02:00
Kumar Gala 6b5139c4bb shell: Convert to using iterable sections
Convert handling of shell_root_cmds, shell_subcmds, and
shell_dynamic_subcmds to use iterable section macros.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-18 12:48:16 +02:00
Gerard Marull-Paretas a86ad87d84 shell: add missing blank line after declaration
Fix checkpatch compliance issue by adding a blank line after
declaration.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Gerard Marull-Paretas 404b2ba474 shell: signal is a reserved identifier use sig instead.
Rule 21.2 "A reserved identifier or macro name shall not be declared"

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Gerard Marull-Paretas b2d442ee87 shell: fix MISRA 5.7 violations on struct tm
s/struct tm *tm/struct tm *t/ to fix MISRA 5.7 rule violation
(uniqueness of tag identifiers).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Gerard Marull-Paretas 667eeb11fb shell: fix MISRA 5.7 violations on struct shell
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Maurits Fassaert 6bfb663167 shell: backends: add SHELL_BACKEND_RTT_BUFFER option
This new configuration option, SHELL_BACKEND_RTT_BUFFER, allows selecting
an alternative buffer for the Shell's RTT backend. By default buffer 0 is
used, which conflicts with the default logging subsystem RTT backend
buffer.
This option is the counterpart to the logger's LOG_BACKEND_RTT_BUFFER.

Signed-off-by: Maurits Fassaert <maurits.fassaert@sensorfy.ai>
2023-04-13 11:43:28 +02:00
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Gerard Marull-Paretas 0ebe14beb4 sys: util: migrate all files to DIV_ROUND_UP
ceiling_fraction is deprecated, use DIV_ROUND_UP.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-11 12:00:37 +02:00
Wojciech Slenska df98af0c23 shell: backends: telnet: init structure before first function call
Struct sh_telnet should be initialised before first function call.

Right now there is a possibility that telnet_accept function will
be called before memset.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2023-04-07 13:24:32 +02:00
Tomasz Moń 59f33a6019 shell: uart: Fix wait for DTR before TX
Fail compilation when incorrect configuration is detected, i.e. when
SHELL_BACKEND_SERIAL_CHECK_DTR is set but UART_LINE_CTRL is not set.

Use periodic timer to wait for DTR instead of waiting in uart callback
to prevent blocking caller workqueue and/or sleeping in ISR.

DTR check was only ever supported with interrupt driven backend so add
appropriate depends on to Kconfig.

Fixes: e9f238889b ("shell: uart: Add waiting on DTR signal before
sending data")
Fixes: #47120
Fixes: #54705

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2023-04-06 14:21:57 +02:00
Jakub Rzeszutko 336c0ed98f shell: fix assert when bypass mode is set
For the duration of the bypass function shell sets the command context.

Fixes: #51637

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2023-04-05 10:03:11 +02:00
Kumar Gala 762b109179 shell: fix armclang compiler warnings with is*() functions
We get compile warnings of the form:

error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
 [-Werror,-Wint-in-bool-context]
                if (!isprint(byte)) {
                     ^

Since isprint (and the other is* functions) return an int, change check
to an explicit test against the return value.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-04 13:47:14 +02:00
Tom Burdick f09685e1ac shell: Provide runtime power management toggling
Adds a device pm_toggle shell command which calls pm_runtime_device
functions put and get to toggle the runtime power state.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-03-30 17:33:22 -04:00
Kumar Gala 831bd2f841 armclang: fix compiler warnings with isprint()
We get compile warnings of the form:

drivers/console/uart_console.c:508:8: error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
 [-Werror,-Wint-in-bool-context]
                if (!isprint(byte)) {
                     ^

Since isprint returns an int, change check to an explicit test against
the return value.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-03-17 09:30:01 +01:00
Wojciech Slenska 6272ba2d5c shell: added function shell_use_vt100_set
Added function to enable/disable vt100 commands.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2023-03-04 18:36:39 +01:00
Wojciech Slenska bbd428fd63 shell: shell_cmds: added vt100 commands
Added command for enablig/disablig vt100 shell commands.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2023-03-04 18:36:39 +01:00
Chris Friedt f923441146 lib: posix: move fnmatch from lib/util to lib/posix
The `fnmatch()` function is specified by POSIX and should be
a part of `lib/posix`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-03-03 17:40:14 +09:00
Nick Ward ca3a4f5f5b shell: backends: dummy: default to log level INF
This change fixes code to match the description in
https://github.com/zephyrproject-rtos/zephyr/pull/55061
(see commit 9ecef4b).

This preserves the previous default behaviour of the
shell dummy backend.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2023-02-23 09:55:11 +01:00
Marco Argiolas 9ecef4b415 shell: backends: add init log level for dummy shell
Dummy shell was always started with log backend enabled with filter
 statically set to INFO level.
AFAIK no use of such log backend can be made, thus causing waste of
 resources.
The new changes keep INFO as the default filter level. In order to
 disable log backend to be attached to the Dummy shell,
 CONFIG_SHELL_DUMMY_INIT_LOG_LEVEL_NONE has to be set.

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2023-02-22 12:15:24 +01:00
Tommi Kangas a25bcfdc59 shell: modules: kernel: add shell command for system heap stats
Added a shell command to print kernel system heap usage statistics.

Signed-off-by: Tommi Kangas <tommi.kangas@nordicsemi.no>
2023-02-19 20:40:48 -05:00
Jamie McCrae fce2cadcde shell: backend: Set RX size default to 256 if shell MCUmgr is enabled
This fixes an issue whereby when USB CDC is used for receiving MCUmgr
commands, the commands are corrupted, invalid or messed up by
increasing the receive buffer size so that it can handle at least 1
full MCUmgr fragment.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-02-10 22:25:21 +09:00
Dominik Ermel db34adf9c3 mgmt/mcumgr: Standardise MCUmgr Kconfig names
Standardise Kconfig options for MCUmgr.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-22 12:36:34 +01:00
Robert Lubos 55af3dd075 shell: Clear command buffer when leaving bypass mode
If bypass mode is left outside of the registered bypass handler, the
command buffer was not cleared, basically containig leftovers from the
processing of the previous command. This resulted in undefined behaviour
on consecutive shell operations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-19 09:46:53 +00:00
Wojciech Slenska 4b2fffc7f9 shell: added SHELL_AUTOSTART configuration option
In some applications, there is a need to don't start the shell by
default, but run it later on some special condition.
When SHELL_AUTOSTART is set to n, the shell is not started after
boot but can be enabled later from the application code.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2022-12-14 15:17:02 +01:00
Wojciech Slenska 29400b18a6 shell: shell_log_backend: added check for msg allocation
When the message buffer cannot be allocated, dropped package
counter should be incremented.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2022-12-05 15:35:03 +01:00
Krzysztof Chruscinski 1f63a07c5f shell: Fix log message queue size for all backends
188d2dfcca introduced a change where log message queue again
become configurable through Kconfig instead of being fixed in
the code. However, it updated only the configuration of an UART
backend. This commit updates other backends as well. Including
dummy backend which has fixed in the code value.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-12-05 15:20:01 +01:00
Chris Friedt 510dca57da shell: devmem: add devmem dump subcommand
This allows the caller to dump a region of memory rather than
dumping one byte (word, etc) at a time. Additionally, it
respects alignment requirements so it works for e.g. 32-bit
register accesses.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-12-05 11:28:22 +01:00
Chris Friedt cdc0f30dbb Revert "shell: devmem: add devmem dump subcommand"
This seems to have caused build failures in spite
of CI passing in PR 52653.

This reverts commit 0a02a4a2af.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-12-02 14:09:37 +09:00
Chris Friedt 0a02a4a2af shell: devmem: add devmem dump subcommand
This allows the caller to dump a region of memory
rather than dumping one byte at a time.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-12-01 15:52:47 -05:00
Jamie McCrae b635b55ef0 logging: Increase dummy shell buffer size to 400 bytes for LOG_PRINTK
If LOG_PRINTK is used then the buffer size needs to be larger to
account for the additional header/footer output from the shell.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-29 10:46:26 +01:00
Armin Brauns 1f41c01553 shell: kernel: right-align stack usage percentages
This improves readability by aliging digits with the same significance
vertically.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2022-11-23 11:33:47 +01:00
Wojciech Slenska 188d2dfcca shell: shell_log_backend: take buffer size from config
Use LOG_MESSAGE_QUEUE_SIZE config instead of hardcoded value.
LOG_MESSAGE_QUEUE_SIZE default value has been changed to 512, so
it is now matching to the hardcoded value.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2022-11-22 13:05:29 +09:00
Kumar Gala a1195ae39b smp: Move for loops to use arch_num_cpus instead of CONFIG_MP_NUM_CPUS
Change for loops of the form:

for (i = 0; i < CONFIG_MP_NUM_CPUS; i++)
   ...

to

unsigned int num_cpus = arch_num_cpus();
for (i = 0; i < num_cpus; i++)
   ...

We do the call outside of the for loop so that it only happens once,
rather than on every iteration.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2022-10-21 13:14:58 +02:00
Kumar Gala c778eb2a56 smp: Move arrays to use CONFIG_MP_MAX_NUM_CPUS
Move to use CONFIG_MP_MAX_NUM_CPUS for array size declarations instead
of CONFIG_MP_NUM_CPUS.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2022-10-17 14:40:12 +09:00
Gerard Marull-Paretas eda9689789 shell: device_service: add missing EARLY init level
The device_service shell was missing the capability to list devices
registered in the EARLY init level.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-14 09:55:48 +02:00
Andrei Emeltchenko ab2594e313 shell: devmem: Update help string for devmem
Update help string to make it more clear.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-10-13 08:00:52 -04:00
Andrei Emeltchenko 1ff34e234c shell: devmem: Fix help for devmem module
Fixes devmem help string shown below:

uart:~$ devmem -h
devmem - Read/write physical memory"devmem address [width [value]]

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-10-13 08:00:52 -04:00
Gerard Marull-Paretas e5eade32e2 shell: device_service: fix MISRA 5.7 violation
Changes in device_service have triggered MISRA 5.7 violation CI error
(Tag name should be unique). Renamed shell to sh, same as some other
modules.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-12 18:49:12 +09:00
Gerard Marull-Paretas 495245a971 init: remove _SYS_INIT_LEVEL* definitions
The _SYS_INIT_LEVEL* definitions were used to indicate the index entry
into the levels array defined in init.c (z_sys_init_run_level). init.c
uses this information internally, so there is no point in exposing this
in a public header. It has been replaced with an enum inside init.c. The
device shell was re-using the same defines to index its own array. This
is a fragile design, the shell needs to be responsible of its own data
indexing. A similar situation happened with some unit tests.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-12 18:49:12 +09:00
Andrew Hedin 4507608d71 shell: Improve kernel stacks alignment
Use Kconfig value to determine name field width.
Pad stack size to 4 characters.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2022-09-20 09:05:00 +00:00
Yong Cong Sin 148317f075 shell/mqtt: Handle negative return value of wait
`wait()` returns the retval of `zsock_poll()` which can be
negative but is currently unhandled.

This patch make sure that the error will be handled.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-09-07 10:30:16 +02:00
Yong Cong Sin 834fb411e3 shell/mqtt: minor MISRA-related fixes
Minor MISRA-related fixes so that the conditionals are boolean
and precedence of statements are explicit.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-09-07 10:30:16 +02:00
Jakub Rzeszutko 66d4471d48 shell: add function checking shell readiness.
Tests with shell commands will fail if they are started
before the shell backend is initialized or started.
Adding API function: shell_ready indicating shell readiness.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2022-09-06 12:36:01 +02:00
Jakub Rzeszutko 2b05f467f0 shell: add missing asserts to api functions
Add missing macro: __ASSERT_NO_MSG to API functions.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2022-09-06 12:36:01 +02:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Krzysztof Chruscinski 64ab22bf43 shell: Add option to format logging timestamp
Add option to control formatting of the logging timestamp. By default
formatting is enabled which maintains backward compatibility.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-09-05 14:27:00 +02:00
Krzysztof Chruscinski 6890a9a434 shell: Fix dependency to log_output
When shell was used as a log backend it did not enabled log_output
module used for string formatting. Adding missing dependency.

Original commit (b0072e1cea) was
reverted, reappling.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-09-01 20:54:13 +02:00
Carles Cufi 7dde7f626f Revert "shell: Fix dependency to log_output"
This reverts commit b0072e1cea.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-08-30 17:28:05 -04:00
Anders Storrø 32ebeb0a5c Shell: Increase ARGC_MAX default val
Increase deafult value of SHELL_ARGC_MAX configuration.
This allows users to utilize deeper nested shell menus without
risking maxing out the number of allowed arguments.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-08-29 10:31:38 +02:00
Krzysztof Chruscinski b0072e1cea shell: Fix dependency to log_output
When shell was used as a log backend it did not enabled log_output
module used for string formatting. Adding missing dependency.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-08-25 12:18:26 +02:00
Jakub Rzeszutko 5e33b2daea shell: add backends command
Add command that lists all active shell backends.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2022-08-25 12:13:37 +02:00
Eric Johnson 7f74797b8f shell: Fix handling mandatory args with optional raw arg
Previous code provided incorrect argc value to handlers when a command
used SHELL_OPT_ARG_RAW option.

Fixes #48380

Signed-off-by: Eric Johnson <eric.johnson2@walgreens.com>
2022-08-22 16:29:59 +00:00
Gerard Marull-Paretas a202341958 devices: constify device pointers initialized at compile time
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).

Automated using:

```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-22 17:08:26 +02:00
Gerard Marull-Paretas e0125d04af devices: constify statically initialized device pointers
It is frequent to find variable definitions like this:

```c
static const struct device *dev = DEVICE_DT_GET(...)
```

That is, module level variables that are statically initialized with a
device reference. Such value is, in most cases, never changed meaning
the variable can also be declared as const (immutable). This patch
constifies all such cases.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-19 11:51:26 +02:00
Jonathan Rico 1d0692b2f7 shell: kernel: fix sleep command
Was trying to parse the second argument instead of the first one.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-08-03 18:47:03 +02:00
Jonathan Rico 76f74344a8 Shell: kernel: Add runtime log filtering command
Use `kernel log-level modulename severity`
Also enable it for the Bluetooth Shell.

Then one can compile-in a lot of BT modules like so:

CONFIG_BT_DEBUG_HCI_CORE=y
CONFIG_BT_DEBUG_L2CAP=y
CONFIG_BT_DEBUG_ATT=y
CONFIG_BT_DEBUG_GATT=y

And at runtime select only, e.g. GATT

kernel log-level bt_hci_core 0
kernel log-level bt_l2cap 0
kernel log-level bt_att 0

And then re-enable L2CAP if needed later

kernel log-level bt_l2cap 4

And so on..

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-12 12:24:43 +02:00
Jonathan Rico ad4cf99eb3 Shell: add kernel sleep command
Basic sleep command for scripting purposes.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-12 12:24:43 +02:00
Yudong Zhang 47ea15edcd shell: mqtt: fix call to bin2hex
Fixes: f2affbd973 ("os: lib: bin2hex: fix memory overwrite")
Signed-off-by: Yudong Zhang <mtwget@gmail.com>
2022-07-11 10:30:05 +02:00
Damian Krolik fc9f59ce0f shell: fix synchronization in log immediate mode
When LOG_MODE_IMMEDIATE is used, logs processed by the shell
log backend may be intertwined with messages printed by
shell commands running on the shell thread.

It is because the shell uses a mutex while the shell log
backend uses the IRQ lock for synchronization. Switch the
latter to use the mutex as well whenever it's possible.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2022-07-06 17:59:32 +00:00
Andrei Emeltchenko 6bc6b5c405 shell: mqtt: Remove unneeded variable
Remove unneeded variable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-23 15:43:59 -05:00
Krzysztof Chruscinski 9833ca61c9 logging: Removing v2 suffix from logging names
Renaming objects which had 2 in the name to indicate that
it is v2 specific. Once logging v1 has been removed such
suffixes are redundant.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 15:46:37 -04:00
Krzysztof Chruscinski 041f0e5379 all: logging: Remove log_strdup function
Logging v1 has been removed and log_strdup wrapper function is no
longer needed. Removing the function and its use in the tree.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 13:42:23 +02:00
Stephanos Ioannidis 33f87408c4 global: Correct extern K_KERNEL_STACK_ARRAY_DEFINE usage
This commit corrects all `extern K_KERNEL_STACK_ARRAY_DEFINE` macro
usages to use the `K_KERNEL_STACK_ARRAY_DECLARE` macro instead.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-06-20 10:25:52 +02:00
Krzysztof Chruscinski c5f2cdef09 logging: Remove logging v1 from the logging
Remove v1 implementation from log_core and all references in the tree.
Remove modules used by v1: log_list and log_msg.
Remove Kconfig v1 specific options.
Remove Kconfig flags used for distinction between v1 and v2.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-16 10:51:15 -04:00
Krzysztof Chruscinski 747d6ffdb0 shell: Remove support for logging v1
Remove support for logging v1 from shell log backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-15 10:55:26 -04:00
Andrei Emeltchenko a9b3c936e2 shell: uart: Fix compilation warning
Use ARG_UNUSED() to fix compilation warning unused-but-set-variable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-06 22:47:11 +02:00
Gerhard Jörges d99827f0a5 shell: suppress newlines on boot when promt is an empty string
If the user sets the default_prompt to an empty string no newlines will
be printed during boot.

Signed-off-by: Gerhard Jörges <joerges@metratec.com>
2022-06-05 14:42:26 +02:00
Alexej Rempel 476d199752 logging: shell: fix shell stats null pointer dereference
If CONFIG_SHELL_STATS is disabled, shell->stats is NULL and
must not be dereferenced. Guard against it.

Fixes #44089

Signed-off-by: Alexej Rempel <Alexej.Rempel@de.eckerle-gruppe.com>
2022-05-15 21:32:10 +02:00
Gerhard Jörges 6be558af5b shell: check echo flag in z_shell_cursor_in_empty_line()
If the echo flag is disabled the cmd_buff isn't printed and the
characters in it must not be counted in this function.

Signed-off-by: Gerhard Jörges <joerges@metratec.com>
2022-05-13 10:22:17 -05:00
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Yuriy Vynnychek e71448a00d shell: fix missing "update" for the last RXRDY signal
Fixed the issue when sometimes "update" is not called for the
last RXRDY signal. First, need to reset the signal and only
after that need to call the "update" function.

Signed-off-by: Yuriy Vynnychek <yura.vynnychek@telink-semi.com>
2022-04-29 16:11:43 +02:00
Krzysztof Chruscinski 3ee5c57934 shell: Add new way of adding subcommands
Added macro SHELL_SUBCMD_SET_CREATE which creates a set of subcommands.
SHELL_SUBCMD_ADD and SHELL_SUBCMD_COND_ADD can be used from any file to
add command to the set. This approach allows to have subcommands added
from multiple files.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-04-29 14:54:08 +02:00
Peter Mitsis a30cf39975 kernel: update k_thread_state_str() API
When threads are in more than one state at a time, k_thread_state_str()
returns a string that lists each of its states delimited by a '+'.
This in turn necessitates a change to the API that includes both a
pointer to the buffer to use for the string and the size of the buffer.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-04-20 20:20:13 -04:00
Nicolas Pitre 1a21ac8122 shell: fix history optimization
Commit f7c4fe6778 ("shell: optimize history storage a bit") forgot
to distinguish between the newly allocated history item and the previous
one, causing havoc on ring buffer wraparounds with excess padding.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-04-20 09:50:03 +02:00
Bartosz Bilas 1ace84a896 shell: remove superfluous default n for boolean
bool symbols implicitly default to n so
there is no need to redundant those values.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2022-04-19 11:49:27 +02:00
Anders Storrø 7963c819f2 Shell: String to numeric conversion utils
Adds string to numeric conversion utility for shell.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-04-05 09:21:52 +02:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Yong Cong Sin 74a0ae01bc shell: Add MQTT backend
Add MQTT backed for shell module.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-03-15 10:01:12 +01:00
Nicolas Pitre f7c4fe6778 shell: optimize history storage a bit
When padding is added to "fill" the gap in order to wrap to the
beginning of the ring buffer, such padding is attributed to the
current item being added. Let's attribute it to the previous entry
instead so it'll be freed along with that entry and make the space
available one entry sooner, increasing the chances for keeping the
current entry around longer.

If ring buffer is empty then always reset it up front to get best
alignment right away i.e. beginning of buffer.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-03-14 11:33:17 +01:00