Commit graph

671 commits

Author SHA1 Message Date
Jukka Rissanen
d3dfbfb3d3 shell: aliases: Do not enable by default
As the aliases support will increase stack usage, turn the
feature off by default in order to avoid surprises with
tests and samples.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-05-12 08:57:40 +02:00
Jukka Rissanen
dd3fcffa1c shell: Add support for tab completion for aliased subcommands
Make sure user is able to tab complete aliased subcommands.

Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-05-11 15:30:56 +01:00
Jukka Rissanen
363c8a1581 shell: Add aliases support
Allow user to specify a file containing command name aliases.
The format of the file is:

    # This is an example aliases file. The file can have
    # comments on it.
    stacks="kernel thread stacks"
    foo=bar

There is "aliases" shell command that can show the current
list of aliases specified in the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-05-11 15:30:56 +01:00
Jukka Rissanen
e22c29c8d4 net: ssh: server: Add multi instance support
Allow multiple incoming SSH connections if we are the server.
This is controlled by CONFIG_SSH_SERVER_SHELL_COUNT option, the
default value is 1 so only one simultaneous ssh connections by
default.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-05-11 13:40:07 +02:00
Jukka Rissanen
2736baba9c shell: Add ssh backend
Add ssh backend for client and server.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-05-11 13:40:07 +02:00
Jukka Rissanen
57ce922032 shell: Check return code from api read()
Make sure to check the return code from sh->iface->api->read()
and bail out if there is an error. The issue was noticed in ssh
client testing where the ssh shell was terminated which then caused
a forever loop.

Signed-off-by: Grant Ramsay <grant.ramsay@hotmail.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-05-04 15:00:15 +02:00
Krzysztof Chruściński
70389cf7ec shell: Extend shell with remote client support
Add option for remote shell client. Remote shell client is an
implementation of shell on the client core which supports
IPC communication with host shell implementation. It allows
to use host shell backends to execute commands on the remote
client. The remote client implementation takes much less
memory than the normal shell implementation.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2026-04-29 09:56:21 +02:00
Krzysztof Chruściński
aaf5bba2a0 shell: Move hexdump printing to shell_utils
In preparation for remote shell support, move hexdump printing to
the shell_utils.c file. Main shell.c file is not compiled for remote
shell client.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2026-04-29 09:56:21 +02:00
Krzysztof Chruściński
b5c9f03553 shell: Add compile time guards
Do not compile shell_help() implementation if CONFIG_SHELL_HELP=n.
In that case, empty inline function is implemented in the shell
header and it may fail to compile.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2026-04-29 09:56:21 +02:00
Krzysztof Chruściński
c61dfc6856 shell: backends: dummy: Add RX notification
When input buffer is written, notify the shell. It will wake the
shell thread which will process the input buffer.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2026-04-29 09:56:21 +02:00
Jakub Rzeszutko
79cf685dfe shell: prevent deadlock from non-yieldable context
shell_vfprintf can block on k_event_wait when the TX ring buffer is full.
Calling it from a non-yieldable context (ISR, spinlock, pre-kernel)
causes a deadlock.

Add a k_can_yield() check in shell_vfprintf as both an assert for debug
builds and a runtime guard that silently drops the output when called
from a context that cannot yield, preventing the deadlock regardless
of whether asserts are enabled.

Fixes: #103954

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2026-04-17 16:42:54 +01:00
Muhammad Waleed Badar
ab32cd6fb8 net: shell: add HTTP client shell commands
Add HTTP client shell commands under the 'net http' subcommand group.
Supports GET, POST, PUT, and DELETE methods.

Commands:
  net http get <url>
  net http post <url> <body>
  net http put <url> <body>
  net http delete <url>

Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
2026-04-14 22:22:41 -04:00
Nicolas Pitre
1c9955a060 pm: shell: hold sys_clock_lock() around timer driver calls
sys_clock_set_timeout() and sys_clock_elapsed() are now documented
as requiring the system clock lock to be held by the caller. Wrap
the calls in subsys/pm/pm.c, soc/nxp/rw/power.c and the kernel
shell thread list command with sys_clock_lock()/sys_clock_unlock().

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-04-07 11:40:49 -05:00
Pieter De Gendt
7b0e88ac61 shell: backends: telnet: Use struct net_sockaddr_storage
A struct net_sockaddr should be considered an incomplete type, replace by
using net_sockaddr_storage.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-03-24 07:07:17 -04:00
Fabio Baltieri
d0067a18c9 shell: add missing dependency for KERNEL_THREAD_SHELL_UNWIND
The option needs a dependency to THREAD_MONITOR, fix a build breakage
with, for example:

west build -p -b nrf52dk/nrf52832 samples/subsys/shell/shell_module -- \
-DCONFIG_EXTRA_EXCEPTION_INFO=y -DCONFIG_THREAD_MONITOR=n

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2026-03-23 12:32:52 -05:00
Arthur Gay
099d0e0590 shell: websocket: Fix client disconnection handling
Don't rely solely on disconnect events to determine writability, since
the socket can drop at any time. A send() to a closed socket fails and
the resulting error reaches the shell thread, where a failing __ASSERT
causes a crash.

Signed-off-by: Arthur Gay <arthur.gay@marshmallow.kids>
2026-03-19 17:02:00 +01:00
Arthur Gay
164cf2c8e8 shell: websocket: Fix race condition
Guard the websocket shell backend's internal state with a mutex.
The disconnect callback executes on a different thread than the shell
and can interleave with sends, leading to writes on an invalid fd or
a disconnected socket.

Signed-off-by: Arthur Gay <arthur.gay@marshmallow.kids>
2026-03-19 17:02:00 +01:00
Alberto Escolar Piedras
f9002f02fc shell: backends: shell_telnet: Remove uses of net logging helper macros
These macros are private to the net subsystem, let's not use them in
other subsystems.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-03-17 18:21:28 -04:00
Pieter De Gendt
20d62fe4e0 shell: Add shell_readline helper
Introduce a helper function to wait for user input with a timeout.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-02-11 17:47:50 -06:00
Pieter De Gendt
186597eb99 shell: dummy: Add input buffer
Allow reading from the dummy shell backend, useful for testing purposes.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-02-11 17:47:50 -06:00
Pieter De Gendt
15b86499ce shell: devmem_service: Unmap virtual memory
WHen running the shell devmem dump command and CONFIG_MMU is enabled, the
virtual memory wasn't unmapped.

Call the device_unmap function to cleanup virtual memory resources.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-02-10 10:53:32 +01:00
Andreas Klinger
22ba487f3d shell: add new command zyclictest
- Name derived from Zephyr cyclictest
- Inspired by Linux realtime test program cyclictest
- Measure latency of interrupt service routine as well as thread with the
  help of the timer interrupt, of which the programmed point of time is
  known.
- Zyclictest thread is running in background while individual application
  under test can be running in foreground.

- The interval can be set up with optional argument -i. It should be at
  least double of expected worst case thread latency to get valid output.
  If this is not met the measurement needs to be repeated.
- The priority can also be set up. It should be the priority of the
  application which should run on the final product.
- The maximum size of the histogram is hard coded to 200 so far.

- After stopping measurement the maximum latency, number of errors /
  overflows and the histogram itself is printed.
- Histogram is printed in a form which is easy to be used by plotting
  programs like GNUplot or Python matplotlib.

- Example: One wants to know what is the expected maximum latency of a
  cooperative task with priority of -10.

  $ zyclictest start -i 400 -p -10

  $ # start your application test cases

  $ zyclictest stop

Count: 547329
                   IRQ  Thread
Max-Latency:        21      27
Errors:              0       0
Overflow:            0       0
Histogram:
...
 23                  0  547306
 24                  0       2
 25                  0       5
 26                  0       5
 27                  0       2

Signed-off-by: Andreas Klinger <ak@it-klinger.de>
2026-02-05 10:27:48 +00:00
Ryan Smith
b54d787d3e shell: allow empty prompt
Setting the prompt to the empty string allows it to be hidden. This is the
intent of the shell command 'shell prompt off'. However, in the most recent
change to the prompt handling, this functionality was lost. Presumably,
the check for 'prompt_length == 0' was to avoid a NULL prompt. However,
NULL is already checked for. Remove the zero-length check and restore the
ability to set the prompt to the empty string.

Signed-off-by: Ryan Smith <elryno@elryno.com>
2026-01-31 17:29:18 +01:00
Karel Blavka
699e7c2ebc shell: add configurable bypass buffer size
The bypass mode in shell.c transfers data in a loop and doesn't need
a large buffer. The previous code conditionally used
CONFIG_SEGGER_RTT_BUFFER_SIZE_DOWN which unnecessarily tied the bypass
buffer size to RTT configuration and could increase stack usage when
RTT buffer is configured larger.

This adds CONFIG_SHELL_BYPASS_READ_BUF_SIZE with a default of 16 bytes,
which is sufficient for the iterative read loop. A build-time assert
ensures the buffer doesn't exceed SHELL_STACK_SIZE.

Fixes: db9dccdc8a

Signed-off-by: Karel Blavka <karel.blavka@hardwario.com>
2026-01-30 18:03:52 +01:00
Jakub Rzeszutko
a04d8957c2 shell: fix race condition between prompt print and RX buffer flush
Move z_shell_backend_rx_buffer_flush() before state_set() in
shell_start() to prevent a race condition where incoming shell
commands could be lost.

Previously, the sequence was:
1. state_set() - prints the prompt
2. z_shell_backend_rx_buffer_flush() - flushes RX buffer

If the shell thread was preempted after printing the prompt,
the host could see the prompt and send commands. When the
thread resumed, z_shell_backend_rx_buffer_flush() would discard
those commands.

By flushing the RX buffer before printing the prompt, any
commands received after the prompt is visible will not be
affected by the flush operation.

Fixes #99674

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2026-01-23 09:21:43 -06:00
Alberto Escolar Piedras
3b4cde8132 shell: backends: websocket: Fix net API use
In d45cd6716b the mayority of the
Zephyr codebased was changed to use the Zephyr native net_ prefixed
types, but some were forgotten.
Without this fix/change the code still builds as we are by now setting
CONFIG_NET_NAMESPACE_COMPAT_MODE. But when this is not set, things
fail to build.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-12-18 18:51:59 +00:00
Peter Ujfalusi
ebb5625bee intel_adsp: Add debug slot manager
Currently all drivers which uses a slot from the debug window have fragile
hardwired slot 'mapping', they are locked to use specific slots even if
there are free slots available for them to take.

The new API hides the management of the slots and descriptors and users
can ask, release or even seize slots that they want to use.

Add a new debug slot manager API and a new default no config option to
allow selection between the hardwired or dynamic debug slot management.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
2025-12-12 04:54:53 -05:00
Pisit Sawangvonganan
c5365797ac shell: modules: devmem: utilize sys_put_le(16|32|64) in memory_dump
Replaces direct byte shifting and assignment with `sys_put_le16`,
`sys_put_le32`, and `sys_put_le64` to simplify the `memory_dump` function.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-12-11 09:19:51 +02:00
Pisit Sawangvonganan
ed75a0a293 shell: modules: devmem: use shell_print where applicable
To improve code clarity, use `shell_print` in place of `shell_fprintf`
with `SHELL_NORMAL` where appropriate.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-12-11 09:19:51 +02:00
Stuart Longland
b87498212d shell_uart: Drop superfluous if statement
We're now checking if there is space prior to executing the loop body,
therefore guaranteeing this condition is never going to fire in a
single-threaded context.

Signed-off-by: Stuart Longland <stuartl@vrt.com.au>
2025-12-11 09:19:40 +02:00
Stuart Longland
301c0130b2 shell_uart: Stop polling if buffer is full
Before calling `uart_poll_in`, check we have space to store the character
in the ring buffer beforehand.  If we do, *then* poll for the character.

That way we don't miss out on serial traffic when our ring buffer is full
unless we fill our hardware ring buffer too.

Signed-off-by: Stuart Longland <stuartl@vrt.com.au>
2025-12-11 09:19:40 +02:00
Peter Mitsis
d59b2a29b4 sys: sys_heap: Fix _system_heap type
Changes the type used in _system_heap extern declarations to use
k_heap instead of sys_heap.

Fixes #100530

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-12-09 17:09:25 -05:00
Pieter De Gendt
3695b2c0ca shell: Add user data argument to shell_set_bypass
Allow passing some context to the shell bypass callback function by
providing a void pointer user data argument.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-12-08 09:39:05 -05:00
Thomas Decker
06ba1ed88e shell: modules: app_version_service: fix include app_version.h
Fix include of app_version.h (see PR #63973).

Signed-off-by: Thomas Decker <decker@jb-lighting.de>
2025-12-08 06:13:34 -05:00
Joel Schaller
8f6b216ec0 shell: backend: telnet: No Error ENETDOWN
Set Log Level to Info when the Telnet socket reports ENETDOWN,
instead of logging an error each time the network is down.

Signed-off-by: Joel Schaller <joel.schaller16@gmail.com>
2025-11-26 11:04:13 +00:00
Alberto Escolar Piedras
bc77cfafe6 shell: Fix check for host libc
Let's use CONFIG_NATIVE_LIBC to detect builds with the host C library
instead of pressuming that any build targetting the POSIX architecture
uses it. This has not been the case for several years now, as we can
select different C libraries when targetting the POSIX architecture.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-11-21 10:09:08 +02:00
Jukka Rissanen
22f9ef0a33 sys: getopt: Rename getopt to sys_getopt to avoid conflicts with Posix
Summary:

As Zephyr getopt is not really compatible with Posix getopt, rename
Zephyr getopt to sys_getopt.

Background:

Zephyr getopt module was introduced in #31356 to be used by the shell.
Zephyr's getopt is not the standard one. It has multiple APIs which make
it more suited for a system like Zephyr where different components may
want to use it for different purposes. Including APIs to init it,
get and set its internal state etc.
Several Zephyr modules (shell, net, wifi, ztest) use this getopt with
these special APIs. The getopt module is bundled in the POSIX
compatibility API subsystem (CONFIG_POSIX_C_LIB_EXT).

Problem description:

As it is not the standard getopt(), no C library can possibly provide
a Zephyr compatible version (even if such C library were to provide a
standard getopt()). As it is bundled in Zephyr's POSIX API in
CONFIG_POSIX_C_LIB_EXT), multiple components that depend on it are
selecting CONFIG_POSIX_C_LIB_EXT. Zephyr core components should not
depend on the POSIX API in this way.

Changes done in this commit:

Rename the getopt*() APIs to sys_getopt*() and move them into a module
under lib/utils with its own Kconfig option to enable it.
Zephyr's users are changed to use this new component.
The POSIX subsystem can continue providing getopt() by calling the new
sys_getopt() and in that way retain backwards compatibility for external
users.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-18 10:46:29 -05:00
Nicholas Lowell
e6d1941c30 shell / logging: shell log backend output Kconfig
Gives access to all log output format flag configurations
for shell backend.

shell log backend doesn't use log_backend_std_get_flags()
and it's debateable if it should, so give it its own fullly
configurable format set for maximum backend bandwidth control

Signed-off-by: Nicholas Lowell <Nicholas.Lowell@lexmark.com>
2025-11-18 08:12:38 -05:00
Henrik Brix Andersen
a4a173b43d shell: mark custom header inclusion as experimental
Mark the custom shell header support as experimental.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2025-11-18 08:10:51 -05:00
Fabian Blatz
99a8cf59b8 shell: Fix method name typo
Fix issue where method names contained bacskpace instead of backspace.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
2025-11-18 08:08:40 -05:00
Jukka Rissanen
d45cd6716b net: Convert network codebase to use renamed network APIs
Rename network symbols in network stack to use the renamed network APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-17 14:01:32 -05:00
Yong Cong Sin
6847421188 shell: backends: select RING_BUFFER_LARGE when necessary
Depending on the ring buffer configuration, users may encounter
the "size too big" assertion in runtime. Let's enable the
RING_BUFFER_LARGE when we know that it is required.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2025-11-13 23:10:37 +02:00
Bjarki Arge Andreasen
2f99ebe9b0 shell: backends: uart: implement pm_device_runtime
The UART device used by the backend needs to be gotten before use,
and put after. In limited cases, device drivers call
pm_device_runtime_get() as part of the call to uart_rx_enable(),
this is not the case for polling, nor interrupt driven API calls
for most if not all drivers, nor is that expected.

Implement pm_device_runtime calls in shell uart backend similar to
the logging uart backend to support all uart drivers in all
configurations.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2025-11-13 23:10:27 +02:00
Jakub Rzeszutko
3ae4dfe490 shell: fix deadlock in the bypass function
Previously, the bypass() function was called while the shell mutex
was still held, preventing the use of shell APIs (e.g. shell_print())
inside the bypass context.

This change unlocks the shell mutex before invoking bypass() and
locks it again afterwards, restoring proper shell context handling
and preventing potential deadlocks.

Issue fixed by: roni1234321

Fixes #97722

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2025-10-28 11:51:18 +02:00
Yong Cong Sin
e8a4b9e303 shell: modules: devmem: support 64-bit read & write
Add support for 64-bit devmem operations for 64-bit devices.

Signed-off-by: Sergii Vystoropskyi <vistorop@meta.com>
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2025-10-25 10:46:27 +03:00
Benjamin Cabé
9d061156f2 Revert "shell: modules: devmem: support 64-bit read & write"
This reverts commit 5149463f79
which causes issue for ARC64 architectures in main

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-10-22 18:31:56 +03:00
Yong Cong Sin
5149463f79 shell: modules: devmem: support 64-bit read & write
Add support for 64-bit devmem operations for 64-bit devices.

Signed-off-by: Sergii Vystoropskyi <vistorop@meta.com>
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2025-10-22 09:03:55 +02:00
Måns Ansgariusson
6528605a87 shell: Remove shell history initialization function
The shell history initialization function doesn't work in if the shell
instance hasn't been created through the shell macro. This removes the
function to avoid confusion.

Signed-off-by: Måns Ansgariusson <Mansgariusson@gmail.com>
2025-10-14 12:52:27 +03:00
Måns Ansgariusson
683819f862 shell: history rewrite to use k_heap instead of ring_buffer
The ring_buffer API was not ideal for this use case, as it is designed for
concurrent access, which is not needed here. The new implementation using
k_heap is more readable and easier to maintain.

There is a slight penalty in memory usage & effectiveness due to the
overhead of k_heap, but since this isn't a production-critical path, the
trade-off is acceptable.

Signed-off-by: Måns Ansgariusson <Mansgariusson@gmail.com>
2025-10-14 12:52:27 +03:00
Pieter De Gendt
6728e78576 Revert "shell: Add user data argument to shell_set_bypass"
Revert a change that broke the stable API function shell_set_bypass.
This reverts commit 6b876dba1ba61b659b1b2d4c3ccd0ac41bd56027.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-10-13 18:12:42 -04:00