Commit graph

616 commits

Author SHA1 Message Date
Benjamin Cabé
0132ea07fb doc: fix spelling errors tree-wide
fix some spelling errors in code comments and Kconfig helps

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-09-03 17:04:13 +02:00
Jaakko Korhonen
7390004b06 shell: modules: devmem: fix devmem load occasionally losing bytes
Changed devmem load to process all characters from the *recv buffer.

Signed-off-by: Jaakko Korhonen <jaakko.korhonen@nordicsemi.no>
2025-08-29 09:01:20 +02:00
Jeppe Odgaard
cbc2b3b540 shell: mqtt: remove username and password preprocessor checks
`#ifdef` will always evaluate to true when used on string Kconfig options.
Therefore username and password is set to "" if unset in Kconfig which is
not an issue.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2025-08-27 09:47:04 +02:00
Jeppe Odgaard
a8c8f7f2b8 shell: mqtt: select NET_CONNECTION_MANAGER
Replace `select NET_MGMT` and `select NET_MGMT_EVENT` with
`select NET_CONNECTION_MANAGER` to get L4 events.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2025-08-26 13:25:47 +02:00
Jeppe Odgaard
ddc4479243 shell: mqtt: use topic levels
Change topic from <device_id>_rx (and tx) to <device_id>/sh/rx.

This allows use of wildcards. E.g. subscribe to all devices "+/sh/tx".

Level "sh" is added to the topic to make it less generic and prevent
potential clashes with other topics.

The topic part after <device_id> is configurable via Kconfig.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2025-08-26 13:25:47 +02:00
Tim Pambor
e3a99bd625 shell: backend: Default to poll mode for uart_native_pty
The interrupt-driven UART API is emulated via polling on native_sim,
which introduces additional overhead. Defaulting to poll mode improves
performance by avoiding this emulation cost.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-08-19 19:14:21 +02:00
Tomasz Bursztyka
60e5a5622b shell: Improve device list command with an optional filter
It might come in handy to filter the output of a device list
command, by adding a filter (auto-completion enabled as well).

Such as:
$ device list uart
devices:
- uart@2f8 (READY)
  DT node labels: uart1
- uart@3f8 (READY)
  DT node labels: uart0

Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
Co-authored-by: Dimitris Karnikis <dika@bang-olufsen.dk>
Co-authored-by: Hans Binderup <habi@bang-olufsen.dk>
2025-08-13 11:08:07 +01:00
Tomasz Bursztyka
1cb1a2777e shell: Add an init command to device module
Optional, this command can be helpful to debug device initialization
process.

Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
2025-08-13 11:08:07 +01:00
Tomasz Bursztyka
c30cbe39b4 shell: utils: Add non-ready device handling functions
It might come in handy to access non-initialized devices throuhg the
shell. I.e. devices which 'zephyr,deferred-init' DTS attribute was set.

Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
2025-08-13 11:08:07 +01:00
Tomasz Bursztyka
eb85374e2a shell: Fix device name lookup buffer size
It is actually easy to have device name going beyond 20 characters.
There is a maximum defined internally, better using it.

Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
2025-08-13 11:08:07 +01:00
Jeppe Odgaard
7c796c417e shell: mqtt: add configurable delays
Allow changing delays via Kconfig values.

Use identical delay (`SHELL_MQTT_WORK_DELAY_MS`) for connect, subscribe and
process work instead of varying 1 or 2 second delay.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2025-08-12 21:31:35 +02:00
Alex Fabre
bfd2ac78ad shell: add app version command
This commit brings a shell command to retreive the following application
version information:

- APP_VERSION_STRING
- APP_VERSION_EXTENDED_STRING
- APP_BUILD_VERSION

Signed-off-by: Alex Fabre <alex.fabre@rtone.fr>
2025-08-09 20:27:30 -04:00
Flavio Ceolin
1ccf9391bc shell: Use proper flexible array
0 length array is a GNU extension. Use proper C99 flexible
array.

Signed-off-by: Flavio Ceolin <flavio.ceolin@gmail.com>
2025-07-31 10:52:49 +01:00
Jeremy Bettis
aab1dc6858 shell: Restore uninit_cb that was lost in #93154
The sh->ctx->uninit_cb needs to be set before posting the
SHELL_SIGNAL_KILL to the event, like the k_poll based code did prior to

Signed-off-by: Jeremy Bettis <jbettis@google.com>
2025-07-25 17:02:31 +01:00
Bjarki Arge Andreasen
825dea6832 shell: exchange k_mutex for k_sem
The mutex is being used as a simple binary semaphore. It is not
recursed so we don't need to track thread ownership nor lock count.

Exchange the mutex for a binary semaphore to save resources and
speed up shell.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2025-07-24 17:00:07 +01:00
Bjarki Arge Andreasen
a39285b720 shell: exchange k_poll for k_event
The shell subsystem currently uses k_poll for signalling. However,
k_poll is only used for simple event signals, results are not used.

Replacing the k_poll with k_event greatly simplifies the code, and
saves 4 struct k_poll_signal and 4 struct k_poll_event (one of which
was entirely unused) while costing a single struct k_event, for
every shell instance. It also allows us to not select POLL,
as we are using the simpler EVENTS instead.

A quick test build of the shell test suite on an nrf54l15 produces
the following build info:

using EVENTS:

           FLASH:       71592 B      1428 KB      4.90%
             RAM:        9872 B       188 KB      5.13%
        IDT_LIST:          0 GB        32 KB      0.00%

using POLL

           FLASH:       75524 B      1428 KB      5.16%
             RAM:       11224 B       188 KB      5.83%
        IDT_LIST:          0 GB        32 KB      0.00%

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2025-07-22 19:34:02 -04:00
Fin Maaß
7e05345562 shell: move date_service to sys_clock api
move date_service from posix api
to sys_clock api.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-07-19 15:30:29 -04:00
Jukka Rissanen
5a9a39caf3 net: mgmt: Convert the mgmt API to use 64-bit masks
Instead of using 32 bit enum values for event numbers, convert
the code to use 64 bit long bit fields. This means that the
user API is changed to use 64 bit event values instead of 32
bit event values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-06-18 10:54:44 +02:00
Tommi Kangas
941dcd31e7 shell: Make TX mutex timeout configurable
The 50 ms TX mutex timeouts introduced in commit b0a0feb cause
dropped messages when used with the shell log backend. This
commit makes time timeout configurable using the
CONFIG_SHELL_TX_TIMEOUT_MS Kconfig option and makes the
default timeout longer when shell log backend is enabled.

Link: #90215

Signed-off-by: Tommi Kangas <tommi.kangas@nordicsemi.no>
2025-06-17 16:05:20 +02:00
Benjamin Cabé
9ab0ea73a8 shell: Introduce structured help message
In order to enable better and more consistent help messages for shell
commands, this commit introduces a new SHELL_HELP macro that allows to
document a command's description and usage in a more structured way.

This will allow to get rid of inconsistent (and duplicated!) variations
of "Syntax: ...", "Syntax:\n ...", "Usage: ...", in the commands, and
formatting of the description+usage will be taken care of by the shell
when it detects the help message is using the "structured" format.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-11 09:55:21 +02:00
Benjamin Cabé
7bdeffb5a6 shell: fix margin handling after newlines in formatted help text
Lines following newlines in shell help text were not properly indented.
For example, in "abc def\ndef ghi\njkl mno", the lines "def ghi" and
"jkl mno" would appear without the expected left margin.

The issue was that after processing a newline and setting proper cursor
position, the function would fall through to z_shell_raw_fprintf() which

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-11 09:55:21 +02:00
Pisit Sawangvonganan
7abda99fe3 shell: mqtt: use ring_buf_reset to flush rx_rb
The `sh_mqtt_rx_rb_flush` function was intended to flush `rx_rb` when
get an error return from `mqtt_read_publish_payload_blocking`.
Instead of retrieving values from `rx_rb` one by one, calling
`ring_buf_reset` achieves the same result more efficiently.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-04-09 22:06:05 +02:00
Pisit Sawangvonganan
24dabdd5fb shell: mqtt: optimize module-scoped sh_mqtt variable access
Introduce a local pointer, `struct shell_mqtt *sh`, to minimize access
to the module-scoped `sh_mqtt` variable.
This allows `sh` to be stored in a CPU register, resulting in more
compact code and improved execution efficiency.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-04-09 22:06:05 +02:00
Tomasz Bursztyka
b4f9242a6a shell: kernel: Add a panic command
For testing purposes only. Testing the fatal error handler or
a coredump backend. Or just out of curiosity.

Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
2025-03-29 07:44:11 -04:00
Robert Lubos
55e1c10894 net: mqtt: Add MQTT 5.0 support for DISCONNECT
Add support for DICONNECT message specified in MQTT 5.0.
As with MQTT 5.0, the disconnect can now also be initiated by the
broker, it was needed to add decoder support for the message.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Triveni Danda
e7a65ac9b4 shell: Set default max argc count when WiFi shell is enabled
Set the default maximum argument count for the shell to 30
when the Wi-Fi shell is enabled, to ensure all Wi-Fi
commands work without failure.

Signed-off-by: Triveni Danda <triveni.danda@nordicsemi.no>
2025-03-14 14:40:57 +01:00
Michal Piekos
81bf6e746e shell: fixes shell dead code issue
Move z_transport_buffer_flush(sh) to the scope of the while loop.

Coverity-CID: 399568

Signed-off-by: Michal Piekos <michal.piekos@wp.pl>
2025-03-07 20:00:27 +01:00
Christopher Clingerman
db9dccdc8a shell: rtt: increase bypass buffer size
If the RTT shell backend is selected and the "down" buffer size
has been selected, the shell bypass functionality should instead
use the buffer size specified by the configuration.

Signed-off-by: Christopher Clingerman <christopher.clingerman@sensorfy.ai>
2025-02-14 17:07:52 +01:00
Jeremy Bettis
e1cfd098a2 shell: Fix Kconfig dependencies
PR #84651 introduced new shell commands that don't compile if
CONFIG_THREAD_MONITOR=n

Add THREAD_MONITOR to new shell commands.

Signed-off-by: Jeremy Bettis <jbettis@google.com>
2025-02-06 21:14:01 +01:00
S Swetha
8f647ef46b [shell]: Add thread control features through shell
This commit extends the shell command functionality by
adding three new operations for thread management.
kernel thread suspend <thread_id>:
Suspends any thread based on its identifier.
kernel thread resume <thread_id>:
Resumes the thread that was previously suspended.
kernel thread kill <thread_id>:
Terminates any thread based on its identifier
These extended commands are useful for controlling
any threads through Zephyr Shell.

Signed-off-by: S Swetha <s.swetha@intel.com>
2025-02-04 11:56:22 +01:00
Daniel DeGrasse
598f343385 shell: handle reprint correctly when output crosses line boundary
When reprinting the shell command buffer with long user inputs, the
reprinted buffer may cross a line boundary, and require a newline to be
printed. For these cases, print the command buffer character by
character, inserting newlines as appropriate.

Fixes #82155

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2025-01-30 16:21:53 +01:00
Jakub Rzeszutko
b0a0febe58 shell: fix unsafe API calls and add configurable autoflush behavior
Fixes an issue where the shell API could block indefinitely when called
from threads other than the shell's processing thread, especially when
the transport (e.g. USB CDC ACM) was unavailable or inactive.

Replaced `k_mutex_lock` calls with an indefinite timeout (`K_FOREVER`)
by using a fixed timeout (`K_MSEC(SHELL_TX_MTX_TIMEOUT_MS)`) in shell
API functions to prevent indefinite blocking.

Link: https://github.com/zephyrproject-rtos/zephyr/issues/84274

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2025-01-23 13:45:20 +01:00
Jakub Rzeszutko
8991b954bc shell: add Kconfig option for configurable autoflush behavior
Introduced a new Kconfig option `SHELL_PRINTF_AUTOFLUSH` to allow
configuring the autoflush behavior of shell printing functions.

Updated `Z_SHELL_FPRINTF_DEFINE` to use the
`CONFIG_SHELL_PRINTF_AUTOFLUSH` setting instead of hardcoding
the autoflush behavior to `true`.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2025-01-23 13:45:20 +01:00
Krzysztof Chruściński
8207a05304 shell: modules: kernel_service: deprecate log_level
Log_level command is a duplicate of 'log enable' command from
the logging command set (enabled by CONFIG_LOG_CMDS=y). Adding
warning about deprecation as 'log enable' is recommended since
it has more features (e.g. autocompletion).

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-01-17 09:08:26 +01:00
Pieter De Gendt
e7e6cb9def shell: shell_log_backend: Allow printing the thread ID or name
Add the LOG_OUTPUT_FLAG_THREAD to the default flags for the shell log
backend.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-01-16 22:36:50 +01:00
Jilay Pandya
f5a126e7ac shell: backends: shell_websocket remove deadcode
fix coverity issue about deadcode, there is no code path which would
lead to the code that is being deleted with this commit

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2025-01-16 14:51:10 +01:00
Krzysztof Chruściński
f0cdaace22 shell: modules: kernel_service: Fix log_level command
Add missing return when input logging source argument is not valid.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-01-16 14:46:33 +01:00
Robert Lubos
60f5337a7a shell: websocket: Fix build with websocket logger disabled
In case websocket logger is disabled, the websocket shell backend should
still build, fix that.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-13 20:23:07 +01:00
Robert Lubos
814aa381c4 shell: websocket: Fix duplicate logs over websocket shell backend
In case websocket logging is enabled, the websocket shell should not be
configured as a logger backend, otherwise logs are duplicated.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-13 20:23:07 +01:00
Robert Lubos
4e38abad67 shell: websocket: Fix registered log level
Wrong symbol was used for log level when registering logger instance for
websocket shell, causing misconfiguration and in result unexpected
crashes.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-13 20:23:07 +01:00
Nicolas Pitre
46aa6717ff Revert "arch: deprecate _current"
Mostly a revert of commit b1def7145f ("arch: deprecate `_current`").

This commit was part of PR #80716 whose initial purpose was about providing
an architecture specific optimization for _current. The actual deprecation
was sneaked in later on without proper discussion.

The Zephyr core always used _current before and that was fine. It is quite
prevalent as well and the alternative is proving rather verbose.
Furthermore, as a concept, the "current thread" is not something that is
necessarily architecture specific. Therefore the primary abstraction
should not carry the arch_ prefix.

Hence this revert.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-01-10 07:49:08 +01:00
Matt Rodgers
549e5de277 net: websocket: pass HTTP upgrade request context to user callback
Passing HTTP upgrade request context to the user callback allows the
user to decide whether to accept or reject the websocket connection
based on the HTTP headers in the request. The primary reason for this is
to enable authentication of the websocket connection (e.g. via cookies
or Authorization header).

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2025-01-08 21:02:02 +01:00
Pisit Sawangvonganan
b44250ae46 shell: modules: kernel: streamline code
This commit includes cleanups to `kernel_service`:
- `shell_tdata_dump()`:
  Adjust formatting to align with `.clang-format`.
- `shell_stack_dump()`:
  Update to pass `sh` directly instead of `user_data` since
  it is already assigned.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-13 11:35:28 +01:00
Pisit Sawangvonganan
8fedee30ee shell: modules: devmem: use shell_strtoul in cmd_dump
Switch from using direct `strtoul` calls to `shell_strtoul`.
This change leverages the extensive error handling provided
by `shell_strtoul`.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-13 11:35:28 +01:00
Pisit Sawangvonganan
27cbe0553c shell: modules: date: omit NULL initialization of endptr
As `strtol` guarantee to set `endptr`, the initial `NULL` can be omitted.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-13 11:35:28 +01:00
Pisit Sawangvonganan
09f13a31e9 shell: utils: omit NULL initialization of endptr
As `strtoul`, `strtoll`, and `strtol` guarantee to set `endptr`,
the initial `NULL` can be omitted.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-13 11:35:28 +01:00
Krzysztof Chruściński
c7f400c9aa shell: backends: Do not use RTT backend with immediate logging
RTT backend can only be called from thread context and immediate
logging might lead to interrupt context use. Previously this limitation
was implied in different way and commit (c88a9ef27) got reverted.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-12-11 21:30:19 +01:00
Krzysztof Chruściński
ca4f2d94f8 Revert "segger: rtt: disable unsupported shell/log features"
This reverts commit c88a9ef272.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-12-11 21:30:19 +01:00
Yishai Jaffe
59c7d5715b shell: add function to get device by name or label
Added shell_device_get_binding() that wraps device_get_binding() plus
device_get_by_dt_nodelabel() so that a shell can easily get a device by
its full name or label.

Signed-off-by: Yishai Jaffe <yishai1999@gmail.com>
2024-12-11 07:58:50 +01:00
Yong Cong Sin
b1def7145f arch: deprecate _current
`_current` is now functionally equals to `arch_curr_thread()`, remove
its usage in-tree and deprecate it instead of removing it outright,
as it has been with us since forever.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-11-23 20:12:24 -05:00