Commit graph

521 commits

Author SHA1 Message Date
Pisit Sawangvonganan 557ad8e45c shell: devmem: address cmd_dump multiple call problem
Call `getopt_init()` to reset `state->optind` instead of directly setting
`optind = 1`. The `getopt()` function uses `getopt_state` from
`getopt_state_get` for state handling, so `getopt_init()` should be called
to correctly run the command again.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-05-15 10:13:23 +02:00
Pisit Sawangvonganan 93ee60fe87 shell: devmem: correct number of mand and opt of cmd_dump
According to the `SHELL_CMD_ARG` macro, the `mand` argument of `cmd_dump`
should be 5, including the command name itself, `dump`.
Meanwhile, the `opt` should be 2, as this value describes the optional
field, which is [-w <width>].

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-05-15 10:13:23 +02:00
Keith Short bfe8020c4c Revert "shell: backends: uart: avoid unnecessary TX IRQs"
This reverts commit d2e5eeb51d.

PR zephyrproject-rtos/zephyr#71172 is causing the bug reported on
issue zephyrproject-rtos/zephyr#72598.

Signed-off-by: Keith Short <keithshort@google.com>
2024-05-10 18:23:50 -04:00
Robert Hancock d2e5eeb51d shell: backends: uart: avoid unnecessary TX IRQs
The shell UART TX code would only disable the TX IRQ when no data was
available in the TX ring buffer. However, it should also disable the IRQ
when all data retrieved from the buffer has been written. Otherwise it
will just result in another immediate TX IRQ which results in the IRQ
finally being disabled.

For this to work, since ring_buf_get_claim may not always return all
available data in the ring buffer on a single call, we need to loop
until either no data is left in the ring buffer or the UART was unable
to consume any of the data.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
2024-05-09 15:46:25 +02:00
Fabio Baltieri 4257fb6a3d shell: device_service: show the usage conter when pm runtime is enabled
Add an extra "usage=%d" to the device status to show the current usage
counter when PM runtime is enabled.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-05-01 10:31:03 +02:00
Fabio Baltieri 48e2f67869 shell: add a callback-filter variant of shell_device_lookup
Add a shell_device_filter variant of the shell device lookup helper that
takes a callback as an argument. This allows more complex filtering on
the device than the existing name prefix.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-04-30 19:30:15 -05:00
Al Semjonovs 0bca04635d shell: Allow extension of shell APIs
Similar to logging module, allow application specific extension of
shell fprintf APIs at a macro level.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2024-04-24 16:04:03 -04:00
Joakim Andersson 24264ad4af shell: Improve the default serial backend init level
Improve the default serial backend init level.
The documentation says to be bigger than the init level of the serial
device used. Since serial devices default to the kernel device init
level (50) then put this to default of application level drivers (90).

Signed-off-by: Joakim Andersson <joerchan@gmail.com>
2024-04-24 19:42:23 +00:00
Jakub Rzeszutko f8263e8293 shell: Add synchronization for prompt-string access in shell
Resolved a data race in shell.c by copying the user-provided
prompt-string into a private buffer within the shell, ensuring
proper synchronization with the shell-thread.

Fixes: #64972

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2024-04-04 15:18:36 -05:00
Krzysztof Chruściński 04a74ce107 shell: rtt: Add detection of host presence
If host is not reading RTT data (because there is no PC connection
or RTT reading application is not running on the host), thread will
stuck continuously trying to write to RTT. All threads with equal or
lower priority are blocked then. Adding detection of that case and
if host is not reading data for configurable period then data is
dropped until host accepts new data.

Similar solution is using in RTT logging backend.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-03-28 14:47:03 +00:00
Daniel Leung b69d2486fe kernel: rename Z_KERNEL_STACK_BUFFER to K_KERNEL_STACK_BUFFER
Simple rename to align the kernel naming scheme. This is being
used throughout the tree, especially in the architecture code.
As this is not a private API internal to kernel, prefix it
appropriately with K_.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-03-27 19:27:10 -04:00
Jukka Rissanen e158c1729a shell: mqtt: Avoid using POSIX function names
This commit fixes this error seen in CI so that things
work even if CONFIG_POSIX_API is enabled.

subsys/shell/backends/shell_mqtt.c:727:12: error:
  conflicting types for 'write'; have
 'int(const struct shell_transport *, const void *, size_t,  size_t *)'
  727 | static int write(const struct shell_transport *transport,
                         const void *data, size_t length)

include/zephyr/posix/unistd.h:230:9: note: previous declaration
 of 'write' with type
 'ssize_t(int,  const void *, size_t)'
  230 | ssize_t write(int file, const void *buffer, size_t count);

subsys/shell/backends/shell_mqtt.c:787:12: error:
 conflicting types for 'read'; have
 'int(const struct shell_transport *, void *, size_t,  size_t *)'
  787 | static int read(const struct shell_transport *transport,
                        void *data, size_t length, size_t *cnt)

include/zephyr/posix/unistd.h:231:9: note: previous declaration
 of 'read' with type
 'ssize_t(int,  void *, size_t)'
  231 | ssize_t read(int file, void *buffer, size_t count);

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-27 13:40:13 -05:00
Krzysztof Chruściński d2bd82eb5f drivers: serial: uart_async_rx: Add return value to consume function
Return availability of free buffers after data is consumed. This
information may be important for the module using uart_async_rx to
schedule next reception if there is a new buffer available.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-03-26 10:46:02 -04:00
Daniel Leung 3664ed64c3 arch: move arch_interface.h under zephyr/arch
arch_interface.h is for architecture and should not be
under sys/. So move it under include/zephyr/arch/.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-03-25 09:58:35 +00:00
Robert Lubos 4300f042bb net: telnet: Fix spelling in command defines
Rename command defines to make checkpatch happy.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-11 15:09:32 -05:00
Robert Lubos 5bb97a112d net: telnet: Improve command processing
Current TELNET implementation wrongly assumed that if the command is
present, it will always be included at the beginning of the packet/data
buffer. Such assumptions however are not valid for STREAM sockets,
where the actual stream data could be fragmented in any way.

Therefore, the command parsing needed rework, so that we analyze each
byte received for the command escape code, and once received we enter
"command parsing" mode. Once no more commands are identified in a data
streak, the command bytes are removed from the data buffer before the
buffer is provided to the shell subsystem for processing.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-11 15:09:32 -05:00
Robert Lubos 9e2e234003 net: telnet: Switch TELNET shell backend to use sockets
Rework TELNET shell backend to use socket API for communication and
socket service library for socket monitoring.

Additionally, rework the TX part so that non-blocking TX is used when
sending from the system work queue. In case transfer is not possible at
the moment, the TX work is rescheduled instead of blocking the system
work queue.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-11 15:09:32 -05:00
Maciej Baczmanski 9be8310ac9 kconfig: shell: fix incorrect shell stack size for Thread
Shell stack size is too low for OpenThread without joiner
functionality, causing overflow.

In this commit, the value of stack size is not changed.
Incorrect assigning of value for opentrhead with
no joiner functionality has been removed.

Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
2024-03-08 10:21:20 +00:00
Jakub Rzeszutko 1261745b2c shell: fix shell_stop command
Added missing condition to check if log backend is configured before
calling the function: z_shell_log_backend_disable. Without this, in some
configurations, a compilation error appeared due to calling a
non-existent function.

Fixes: #69555

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2024-03-04 14:08:04 +01:00
Pieter De Gendt df7750f63a shell: backends: Add RPMsg shell backend
Introduce a backend for the Shell subsystem using a RPMsg endpoint.

This is useful for tooling & testing a remote processor from linux.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-03-01 14:10:24 +01:00
Brian Moran b411094b85 shell: Add a configuration for not printing shell messages
The shell currently prints out `: command not found` and
`Please specify a subcommand.` when invalid commands are
sent.

This can cause issues in certain situations, such as if a U-Boot
console in interactive mode is on the other end of the shell's
UART, where the U-Boot console will stop booting the device
if it receives any characters, and it will print out strings that
the shell then sees as commands. This causes the shell to send
out the messages above, preventing the device running
U-Boot on the other end from booting up.

I added the configurations
`CONFIG_SHELL_MSG_SPECIFY_SUBCOMMAND` and
`CONFIG_SHELL_MSG_CMD_NOT_FOUND` to allow disabling
these messages.

Signed-off-by: Brian Moran <brian.moran@sabantoag.com>
2024-02-26 11:53:58 +00:00
Abderrahmane Jarmouni 92a24ba4b4 shell: backends: fix for async shell selection
This patch modifies the way SHELL_BACKEND_SERIAL_API_ASYNC is selected.
The current logic causes conflicts (no console output) when the user tries
to use one of the UARTs in async mode, by setting CONFIG_SHELL_ASYNC_API,
while using Shell with a different UART (typically the Console's one).

Signed-off-by: Abderrahmane Jarmouni <abderrahmane.jarmouni-ext@st.com>
2024-02-06 19:34:15 +01:00
Henrik Brix Andersen 14fa9f3e21 shell: modules: kernel: include EXTRAVERSION when printing version
Include the full version in the output of the "kernel version" shell
subcommand. Previously, EXTRAVERSION was not included, causing
e.g. "3.6.0-rc1" to be printed as "3.6.0".

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-02-05 23:06:19 +01:00
Alberto Escolar Piedras 06f15fcc36 subsys shell devmem_service: Fix includes
* The include for the host libC should be guarded with
  using the host libC instead of the POSIX arch, as this
  supports other C libraries.
* This code uses getopt, which is an extension to the
  C library. Let's explicity select one of the extensions
  which includes it instead of relaying on somebody having
  set it for this file somewhere else.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-01-26 07:48:55 -05:00
Jakub Rzeszutko 04de43b1a1 shell: Fix shell init procedure when configured as inactive on startup
The previous behavior of the CONFIG_SHELL_AUTOSTART option, where setting
it to 'n' disabled shell interaction at startup but kept the logger
active as a shell backend, was inconsistent.
Now, when CONFIG_SHELL_AUTOSTART is set to 'n', both the shell and the
logger are inactive at startup. Calling the shell_start function will
activate them and print any pending logs. This change ensures a more
consistent and logical behavior regarding shell and logger activity at
startup.

Additionally, now when the shell_stop function is called, both the shell
and the logger are halted. This enhancement ensures that stopping
the shell also effectively stops the associated logger.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2024-01-21 16:01:36 +01:00
Miika Karanki 7c0047263a shell: telnet: Don't close the connection on ENOBUFS error
If there's not enough networking buffers at certain moment,
they might become available later. So instead of closing connection
(and failing assertation) sleep and retry. This avoid the following
assertion failure when there's much of data to send:

    net_pkt: Data buffer (1500) allocation failed.
    net_tcp: conn: 0x20076024 packet allocation failed, len=1460
    shell_telnet: Failed to send -105, shutting down
    ASSERTION FAIL [err == 0] @ .../subsys/shell/shell_ops.c:416
    os: r0/a1:  0x00000004  r1/a2:  0x000001a0  r2/a3:  0x00000004
    os: r3/a4:  0x20044380 r12/ip:  0x00001958 r14/lr:  0x080c9027
    os:  xpsr:  0x41000000
    os: Faulting instruction address (r15/pc): 0x0811ed26
    os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
    os: Current thread: 0x20045100 (shell_telnet)
    os: Halting system

Signed-off-by: Miika Karanki <miika.karanki@vaisala.com>
2024-01-17 09:54:15 +01:00
Jonathan Hamberg 9c1a45cc00 posix: Fix name collision with __bswap
__bswap_ in zephyr/sys/byteorder.h conflicts with __bswap_ in host's
byteswap.h. byteswap.h from host compiler used in posix_native_64 boards
causes a compilation issue.

This commit renames __bswap_ to BSWAP_ to prevent collision.

Before this commit a compilation error can be created by adding #include
<byteswap.h> to samples/net/sockets/echo/src/socket_echo.c

This does not change external API to byteorder.h, but does change
internal implementation which some other source files depend on.

Replaced manual byteswap operations in devmem_service.c with APIs from
byteorder.h which automatically converts to CPU endianess when necessary.

Fixes #44324

Signed-off-by: Jonathan Hamberg <jonathanhamberg@gmail.com>
2024-01-10 18:13:44 +00:00
Chaitanya Tata 66f63455ea shell: Add a space after colon
Just a cosmetic change, but IMHO the help looks much better now :).

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-05 14:43:21 -05:00
Benedikt Schmidt 4c731f27c6 shell: modules: do not use k_thread_foreach with shell callbacks
Always use k_thread_foreach_unlocked with callbacks which print
something out to the shell, as they might call arch_irq_unlock.
Fixes #66660.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2023-12-21 10:01:08 +00:00
Johan Hedberg 3fbf12487c kernel: Introduce a way to specify minimum system heap size
There are several subsystems and boards which require a relatively large
system heap (used by k_malloc()) to function properly. This became even
more notable with the recent introduction of the ACPICA library, which
causes ACPI-using boards to require a system heap of up to several
megabytes in size.

Until now, subsystems and boards have tried to solve this by having
Kconfig overlays which modify the default value of HEAP_MEM_POOL_SIZE.
This works ok, except when applications start explicitly setting values
in their prj.conf files:

$ git grep CONFIG_HEAP_MEM_POOL_SIZE= tests samples|wc -l
     157

The vast majority of values set by current sample or test applications
is much too small for subsystems like ACPI, which results in the
application not being able to run on such boards.

To solve this situation, we introduce support for subsystems to specify
their own custom system heap size requirement. Subsystems do
this by defining Kconfig options with the prefix HEAP_MEM_POOL_ADD_SIZE_.
The final value of the system heap is the sum of the custom
minimum requirements, or the value existing HEAP_MEM_POOL_SIZE option,
whichever is greater.

We also introduce a new HEAP_MEM_POOL_IGNORE_MIN Kconfig option which
applications can use to force a lower value than what subsystems have
specficied, however this behavior is disabled by default.

Whenever the minimum is greater than the requested value a CMake warning
will be issued in the build output.

This patch ends up modifying several places outside of kernel code,
since the presence of the system heap is no longer detected using a
non-zero CONFIG_HEAP_MEM_POOL_SIZE value, rather it's now detected using
a new K_HEAP_MEM_POOL_SIZE value that's evaluated at build.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2023-12-20 11:01:42 +01:00
Pisit Sawangvonganan f6f8c3f9b7 shell: correct z_shell_spaces_trim when len equal to zero
Addresses a potential issue when the string contains only '\0',
which results in z_shell_strlen(str) returning len as 0.
Since the for-loop expects len >= 1, the function now immediately
returns when len == 0.
As the null check for 'str' is already handled inside
z_shell_strlen(), an additional check for 'str' is not needed.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2023-12-12 15:02:58 +01:00
Andriy Gelman 8232dddf1c shell: telnet: Don't close the connection on EAGAIN error
EAGAIN error is returned if the tcp window size is full. Retry
sending the packet instead of closing the connection if this
error occurs.

Also the full payload may not be sent in a single call to
net_context_send(). Keep track of the number of bytes remaining
and try to send the full payload.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2023-12-12 10:57:49 +01:00
Yong Cong Sin f61ce34998 shell: shell_uart: reinstate multi-instance macro
Reinstate the `SHELL_UART_DEFINE` macro and moved the struct
declarations to header file, making it possible to create
another UART shell backend instance by doing
`SHELL_UART_DEFINE()` + `SHELL_DEFINE()` + `shell_init()`.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-12-06 11:27:20 -08:00
Yong Cong Sin d65cb1fe12 shell: fix shell instance name typo
Fixing typo from the original implementation in
44705b698c725166834f19d6fd5db2804f9a0d60, which resulted in
the name of current shell instance getting print over and over
again.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-12-05 10:44:56 -05:00
Yong Cong Sin 72fea5df56 shell: backends: uart: add public function to access smp shell data
`smp_shell_input_timeout_handler`. Create a public function in
the `shell_uart.c` for it to get the pointer to the
`smp_shell_data` and fix the compilation error.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-11-15 16:38:16 +01:00
Krzysztof Chruściński e6e6515972 shell: uart: Rework Kconfig dependencies
When UART asynchronous API support was added to shell it was set up
to be the default one and was turning on asynchronous API if it was
supported. However, it may lead to complation failures if device
requires additional setup for asynchronous UART (e.g DMA in device
tree). Becuase of that, it is reverted back to use interrupt driven
API and use asynchronous API if it is already enabled in the
application.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-11-14 16:09:08 +02:00
Krzysztof Chruściński d6a3fd7cf0 shell: uart: Add missing casting of the data pointer
Fixing compilation failure due to treating void pointer as uint8_t
array. Added missing casting.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-11-14 16:09:08 +02:00
Krzysztof Chruściński 5e4e944cc0 shell: backends: uart: Rework and add support for async API
Rework UART backend to clearly use single instance approach as
before it was a bit messy with some parts of implementation indicating
multi-instance approach and some single instance. Backend has been
around for years and multi-instance requirement never came.

Added support for UART asynchronous API which is more efficient
in terms of power consumption and performance. Asynchronous API
support is using uart_async_rx helper module for handling data
received asynchronously.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-11-14 09:21:46 +01:00
Ederson de Souza 049b67aca9 subsys/shell/backends: Fix shell_telnet.c build with clang
It declares a variable inside a switch statement without brackets to
properly delimit the scope, making clang barf. This patch adds them.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2023-11-03 20:04:08 -04:00
David Corbeil 724c162821 shell: backends: telnet: Added support for echo option
Adding support for echo option if telnet commands are supported. This is
useful when the telnet client is in character mode. It allows to use the
arrow keys, ctrl-c and more. Something to keep in mind is that when
character mode is turned on by the client, network traffic is
considerably increased as each typed character is sent over the wire.

Note: echo mode is only supported if SHELL_TELNET_SUPPORT_COMMAND is
enabled.

Signed-off-by: David Corbeil <david.corbeil@dynon.com>
2023-11-03 11:46:08 +01:00
Yong Cong Sin 0e2f5c2dbb shell: print name and prompt when listing backends
The shell name defined with `SHELL_DEFINE` is implicitly
guaranteed to be unique while it is possible that more than one
shell backends can have the same prompt.

Print the name of the shell backend alongside with its prompt
to differentiate between the backends.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-10-25 09:57:29 +02:00
Yong Cong Sin a068288091 shell: add new APIs to get the backend instances
Added some new APIs to get the backend instances more easily,
so that dev does not need to rely on `shell_backend_*_get_ptr`,
which looks more like a hack to access a local variable.

These APIs are basically copied from the log backend
implementation.

Added testcase for the APIs.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-10-25 09:57:29 +02:00
Yong Cong Sin dd154406ba shell: make the backend thread name variable generic
Rename the shell backend `thread_name` variable to just `name`,
to be used for other things not specific to thread later.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-10-25 09:57:29 +02:00
Flavio Ceolin 564adad952 treewide: Add CODE_UNREACHABLE after k_thread_abort(current)
Compiler can't tell that k_thread_abort() won't return and issues a
warning unless we tell it that control never gets this far.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-24 09:04:42 +02:00
Gerard Marull-Paretas 915cb05bb6 dts: drop HAS_DTS
HAS_DTS has become a redundant option. All Zephyr architectures now
select this option, meaning devicetree has become a de-facto
requirement.  In fact, if any board does not provide a devicetree
source, the build system uses an empty stub, meaning the devicetree
machinery always runs.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-10-20 12:18:17 -07:00
Jakub Rzeszutko 69d50db53a shell: fix a memory corruption coverity issue
Added a condition to check if the size of the copied
memory is a positive number.

Fixes #58700
Fixes #58703

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2023-10-13 13:11:28 +03:00
Jakub Rzeszutko c631bc7757 shell: modules: kernel: add human readable uptime
Added options: -p and --pretty to the kernel updtime command.

Fixes: #62543

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2023-09-28 09:34:00 +02:00
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