Remove the `kernel log_level <module> <severity>` shell subcommand. It
has warned at runtime on every invocation since commit 8207a05304
("shell: modules: kernel_service: deprecate log_level"), first released
in Zephyr 4.1, so it is well past the two-release deprecation window.
The `log enable <severity> <module>` command from the logging command
set provides the same functionality.
The command was fully self-contained in log-level.c and registered
through KERNEL_CMD_ARG_ADD, so removing the file and its CMakeLists.txt
entry drops it entirely; no other code referenced it.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
This commit updates the usage of ring_buf to utilize the new
put_ptr/commit/get_ptr/consume pattern instead of the traditional
claim/finish approach. This change is part of a larger refactor aimed at
streamlining the ring_buf API and improving its efficiency.
Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
Fix regression introduced by 069d3a7652. async_read() function
was allocating new buffer even when UART was not expecting it.
Buffer pool was quickly drained and shell was unresponsive.
Added additional check to attempt to allocate new a new buffer
only if UART is waiting for new buffer (UART is disabled or there
is unhandled RX buffer request).
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
The whitespace-skipping loop in formatted_text_print() advances past
every character for which isspace() returns non-zero. Because isspace()
matches both newlines and ordinary spaces, any leading spaces that
follow
a '\n' in a help string were being discarded, stripping intentional
indentation from continuation lines.
Fix this by breaking out of the loop immediately after consuming the
'\n'. The newline itself must still be skipped to prevent an empty line
from being printed, but the spaces that follow it on the next line are
part of the author's intended layout and must be preserved.
Before this fix, a help string such as:
"[-v] [-n <count>]\n"
" Options:\n"
" -v verbose output\n"
" -n <count> number of iterations (default: 1)"
was rendered as:
test - [-v] [-n <count>]
Options:
-v verbose output
-n <count> number of iterations (default: 1)
After this fix:
test - [-v] [-n <count>]
Options:
-v verbose output
-n <count> number of iterations (default: 1)
Signed-off-by: Aziz Sellami <aziz.sellami@nxp.com>
This replaces the older k_sleep(K_MSEC(time)) pattern with the modern,
more efficient k_msleep(time) API. This prevents double-macro expansion
overhead and adheres to Zephyr's preferred timeout style.
Signed-off-by: Saksham Gupta <saksham77779@gmail.com>
shell_stop() read/wrote sh->ctx->state without taking the shell lock.
If a command was still running on the shell thread, state_collect()
would finish with an unconditional state_set(ACTIVE), clobbering the
SHELL_STATE_INITIALIZED shell_stop() had just set. The log backend
was left disabled and shell_start() would then fail with -ENOTSUP.
Fix by having shell_stop() take the same lock shell_thread() already
holds during shell_process()/state_collect(), like shell_start()
already does. Returns -EBUSY if the lock is busy.
Fixes#115019
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
The telnet backend exposes the full Zephyr shell over an unauthenticated,
unencrypted TCP port, which is equivalent to granting full device control
to anyone who can reach the port. There is no in-tree authentication to
switch on, so add the security warning to the Kconfig help, mirroring the
guidance already given for MCUMGR_GRP_SHELL.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Use #include <> instead of #include "" to include a header file which path
is not relative to the directory path of the file emitting the #include
directive.
This change was made running scripts/check_quoted_includes.py script
proposed in https://github.com/zephyrproject-rtos/zephyr/pull/112135
with the Linux shell command below and manually selecting the applicable
changes:
$ find subsys/shell/ -type f -exec \
./scripts/check_quoted_includes.py -w {} \;
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
If RX buffers are not provided on time it may be possible that device
enters disabling phase. Code was attempting to re-enable the UART
immediately when that is detected but it fails if UART is not yet
disabled. If providing next buffer fails then just release that
buffer and wait for UART_RX_DISABLED event. Re-enable UART from
that event.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
atomic_set is used to access tx_busy in the irq_write function (in order to
get atomic exchange behavior) so we should also access it atomically here
(even though we don't need atomic exchange behavior here).
Signed-off-by: Phil Hindman <phindman@xes-inc.com>
node is NULL if shell history is empty.
Applying a zero offset to NULL is undefined behavior.
Signed-off-by: Sandro Scherer <sandro.scherer@siemens.com>
In most usage scenarios, the thread id parameter is useful for unwind
subcommand. For example, use the 'kernel thread list' command to
locate the <thread id> of the target thread, then check the call trace
with 'kernel thread unwind <thread id>'.
At least, users should be reminded that this command accepts the
<thread id> parameter to check the call trace of any thread.
Signed-off-by: Chingbin Li <liqb365@163.com>
The "send" command of the CAN shell allows to send also CAN FD frames,
which can contain up to 64 bytes of data.
Increase the shell argc count to be able to send a fully complete CAN FD
frame with all the payload.
The exact count of argc is determined by the following command, which
uses extended ID, enables CAN FD and bit rate switch, and specify the
maximum payload size :
can send can0 -e -f -b 12345678 00 01 02 03 04 05 06 07 08 09 10 11 12 13
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
Signed-off-by: Adrien Ricciardi <aricciardi@baylibre.com>
Without optimizations the compiler does not follow how addr may be used,
only that it passed to zsoc_accept. And warns that it may be used
unitialized. Let's initialize it to zero to silence this warning.
If optimizations are used, the compiler should anyhow drop the
initialization.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Add a binary min-heap as a selectable timeout backend alongside the
sorted delta list, plugging into the backend abstraction rather than
forking timeout.c. Pending timeouts are kept in a min-heap keyed on
absolute expiry tick; insertion and arbitrary removal are O(log n),
which scales better than the delta list's O(n) insertion when many
timeouts are pending.
The backend is a new kernel/timeout_minheap.h: the heap instance (a
min_heap_ref from the previous commit), its comparator and the
z_timeout_q_*() operations, included only by timeout.c (after curr_tick)
so the whole backend stays private to that translation unit. struct
_timeout gains the abs_ticks + heap_handle representation, selected by
Kconfig (the delta list's node + dticks is the #else), with the common
fn pointer kept as a shared trailing member; the per-node helpers in
timeout_q.h grow a matching min-heap variant. The kernel shell thread
dump prints the backend's raw scheduling field (dticks or abs_ticks)
under #ifdef.
Because the shared z_add_timeout() already applies the post-#107452
conditional tick round-up, the heap inherits it: the backend's insert
simply stores abs_ticks = curr_tick + dticks. Likewise in-flight
handler synchronization (PR #109977) lives in timeout.c, so the heap
node carries no ANNOUNCING/ABORTED sentinels -- "not queued" is just
heap_handle.idx == 0.
The backend is EXPERIMENTAL, depends on TIMEOUT_64BIT (absolute ticks
need 64-bit precision), and uses a fixed-capacity heap
(CONFIG_TIMEOUT_HEAP_MAX_ENTRIES) whose overflow is a fatal error.
The min-heap algorithm, struct fields, Kconfig and capacity model are
derived from Sayooj K Karun's min-heap timeout subsystem (#106013),
reworked here to fit the pluggable backend and the current in-tree
in-flight-handler synchronization.
Co-authored-by: Sayooj K Karun <sayooj@aerlync.com>
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
A peer replying to the ESC[6n cursor-position query with ESC[0;0R
causes terminal_size_get() to store terminal_wid = 0. Any later
shell-core helper that divides or moduloes by terminal_wid then
faults with a divide-by-zero.
Validate the parsed coordinates and treat zero as a parsing failure.
cmd_resize() already restores CONFIG_SHELL_DEFAULT_TERMINAL_WIDTH/
HEIGHT on error, so a forged reply now behaves the same as a
terminal-response timeout.
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
Read-only strings can only be skipped if shell main core has
access to the read only memory of the remote core. By default
assume that it has not access.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Use <> operator to include a Zephyr header file instead of "" that
is intended to local header files, not header files relative to
specifically defined search paths.
This change was made running the sed shell command below:
$ sed -i -E 's/#include "zephyr\/([^"]+)\.h"/#include <zephyr\/\1.h>/g' \
`grep -rsl "#include \"zephyr/" subsys/shell/`
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
The `thread` field is not initialized, if it's being animated via
k_work_queue_run instead of k_work_queue_start.
Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
async_uninit() was a no-op, so when the shell UART transport was
uninitialized, UART RX stayed enabled and the device remained active.
Call uart_rx_disable() in async_uninit to match async_init's rx_enable(),
so the UART is fully disabled on uninit.
Signed-off-by: Jakub Topic <jakub.topic@anitra.cz>
Omitting the parameter name in a function definition is a C23 extension.
Fix this by naming second and third parameter in shell_thread function
definition to address compilation warning promoted to error in CI with
LLVM.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Up to now, some initialization has been deferred from the shell_init
function (which starts the shell_thread) to the shell_thread function. When
using SHELL_AUTOSTART this is fine, but when autostart is disabled this
causes a race between the shell_thread and whatever thread eventually calls
shell_start, because shell_start needs initialization to have completed
before it runs. So, move the remaining initialization code from the
beginning of the shell_thread to shell_init (before starting the
shell_thread).
Signed-off-by: Phil Hindman <phindman@xes-inc.com>
Display which CPU each thread and interrupt stack is running on when
SMP is enabled. Shows CPU ID as the last column for clarity and proper
alignment. On non-SMP systems, output remains unchanged.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Log messages arriving during shell_readline corrupt the input line
because the log backend does not account for the different line
layout in readline mode (no shell prompt, optional readline prompt).
Fix by checking readline_state in process_log_msg (immediate mode)
and shell_log_process (deferred mode) to properly erase and restore
the readline input line. Process deferred logs inside the readline
loop so they appear in real-time.
Introduce shell_readline_prompt_set() so command handlers can
register a prompt string that is printed at readline start and
restored after log output.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
Fix four bugs in shell UART async backend when using
SMP (mcumgr) transport:
1. Use CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_TIMEOUT
Kconfig value instead of hardcoded 10000 in
rx_enable().
2. Consume all claimed bytes (blen) in
uart_async_rx_data_consume(), not just shell
bytes (sh_cnt). SMP-consumed bytes also need to
be released from the async RX buffer.
3-4. Loop in async_read() to keep claiming data when
SMP consumes all bytes, preventing data from
getting stuck in the buffer until the next
UART_RX_RDY event.
Fixes#98597
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
Instead of relaying on the dynamic_get() callback initializing the whole
struct shell_static_entry *entry,
pre-initialize it to 0, so previous garbage in the stack does not cause
random behaviour.
The issue can be seen when running with valgrind, for example:
```
twister -p native_sim -T tests/drivers/comparator/shell/ --enable-valgrind
cmake -GNinja -DBOARD=native_sim ../tests/drivers/comparator/shell/
ninja
valgrind zephyr/zephyr.exe
```
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Since commit 37717b229f ("sys: util: rename Z_MIN Z_MAX Z_CLAMP to min
max and clamp"), <zephyr/sys/util.h> unconditionally defines function-
like macros named `min`, `max`, and `clamp` in the global namespace (in
C mode). util.h gets pulled in transitively by very broad headers,
including the POSIX layer's <pthread.h>, so any third-party C code that
uses these names as ordinary identifiers (e.g. XNNPACK's static `clamp`
helper and its public `clamp` struct field) fails to build as soon as
<pthread.h> is included.
Following the approach used by Linux, move the lowercase `min`, `max`,
`min3`, `max3`, and `clamp` macros (and their helpers) into a new
<zephyr/sys/minmax.h> header that has to be included explicitly by
source files that want them. util.h keeps the uppercase MIN/MAX/CLAMP,
so most code is unaffected; only the (much smaller) set of files that
actually use the lowercase variants needs to pick up the new include.
Fixes#107853.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>