Commit graph

653 commits

Author SHA1 Message Date
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
Pieter De Gendt
4fa4329a16 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-10-10 12:53:55 -04:00
Jeppe Odgaard
d58e6efc76 shell: mqtt: cancel disconnect work on connect event
If the disconnect work has not yet run when a connect event is received the
connect event is dropped.

Prevent this behaviour by reorganizing `network_evt_handler()`.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2025-10-09 12:46:33 -04:00
Fabio Baltieri
37717b229f sys: util: rename Z_MIN Z_MAX Z_CLAMP to min max and clamp
Rename these three macros to an unprefixed lower-case variant. This is
normally not done for Zephyr macros (see container_of) but in this case
it seems like a good idea to adopt the lowercase names to:

1. have the same convention as the equivalent Linux macros, helping devs
   working cross project recognizing (mis)use patterns.
2. make it somewhat intuitive that the lowercase ones are meant to be
   used in functions while the uppercase ones are to be used for static
   evaluation.

Add few c++ guards to avoid colliding with std::min and std::max.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2025-10-03 21:14:11 -04:00
Benjamin Cabé
febf4e8e53 shell: fix app version sub commands
commands should not have spaces around hyphens:
version - extended --> version-extended
build - version --> build-version

Fixes: zephyrproject-rtos/zephyr#96591

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-10-02 22:00:11 +02:00
Heghedus Razvan
5430400579 shell: add option to toggle logs output
When logging through shell is enabled, it is inconvenient to use
the shell when there are logs coming in. Having a mechanism for
easy disabling/re-enabling the shell logs is a nice quality of life
feature.

To toggle the logs, `CTRL+T` combination can be used. This is
available only when meta key feature is enabled.

Signed-off-by: Heghedus Razvan <heghedus.razvan@protonmail.com>
2025-09-26 09:10:50 +02:00
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