Commit graph

381 commits

Author SHA1 Message Date
Peter Mitsis
a30cf39975 kernel: update k_thread_state_str() API
When threads are in more than one state at a time, k_thread_state_str()
returns a string that lists each of its states delimited by a '+'.
This in turn necessitates a change to the API that includes both a
pointer to the buffer to use for the string and the size of the buffer.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-04-20 20:20:13 -04:00
Nicolas Pitre
1a21ac8122 shell: fix history optimization
Commit f7c4fe6778 ("shell: optimize history storage a bit") forgot
to distinguish between the newly allocated history item and the previous
one, causing havoc on ring buffer wraparounds with excess padding.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-04-20 09:50:03 +02:00
Bartosz Bilas
1ace84a896 shell: remove superfluous default n for boolean
bool symbols implicitly default to n so
there is no need to redundant those values.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2022-04-19 11:49:27 +02:00
Anders Storrø
7963c819f2 Shell: String to numeric conversion utils
Adds string to numeric conversion utility for shell.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-04-05 09:21:52 +02:00
Nazar Kazakov
f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Yong Cong Sin
74a0ae01bc shell: Add MQTT backend
Add MQTT backed for shell module.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-03-15 10:01:12 +01:00
Nicolas Pitre
f7c4fe6778 shell: optimize history storage a bit
When padding is added to "fill" the gap in order to wrap to the
beginning of the ring buffer, such padding is attributed to the
current item being added. Let's attribute it to the previous entry
instead so it'll be freed along with that entry and make the space
available one entry sooner, increasing the chances for keeping the
current entry around longer.

If ring buffer is empty then always reset it up front to get best
alignment right away i.e. beginning of buffer.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-03-14 11:33:17 +01:00
Emil Gydesen
555f15deaa Shell: shell.c Use IN_RANGE macro from util.h
Change an occurence of `in_range` to use the IN_RANGE macro.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-03-11 07:20:16 -06:00
Robert Lubos
bb5909f7d1 net: tcp: Update receive window in other direct net_context users
As the receive window is now decreased at the TCP module level, other
direct net_context users are also responsible for acknowledging the
received data with net_context_update_recv_wnd() - otherwise, the
communication will stall.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-03-11 09:21:51 +01:00
Gerard Marull-Paretas
95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Nicolas Pitre
eee5b8e563 ring_buffer: make finish methods final
Make it possible to "finish" with fewer bytes than what was "claimed".

This was possible before on the get side, but the put side was
cummulative wrt finish. The revamp made it cummulative on both sides.
Turns out that existing users rely on the opposite behavior which is
more logical and useful. So make both sides that way.

Adjust documentation, test case and users accordingly.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-02-28 10:52:41 +01:00
Nicolas Pitre
24f5c65b5a shell: fix history memory reclaim
No ring_buf_get_finish() should be performed on ring_buf memory that
wasn't claimed beforehand. Using ring_buf_get() with a NULL destination
does both the claim and the finish part without retrieving anything.

This is especially important with the ring_buffer revanp where the above
is enforced for proper operation.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-02-24 14:49:00 -08:00
Michał Barnaś
08c41e7e4f shell: don't print colon if there's no item help
If the item has name but no help, there's no need to fill
shell with tabulators and colon at the end of the line.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2022-02-24 08:29:52 -06:00
Krzysztof Chruscinski
caa3ee686a shell: kernel_service: Use z_stack_space_get for isr stack stats
Use dedicated function for calculating stack usage of the
interrupt stack(s).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-21 20:57:17 -05:00
Krzysztof Chruscinski
262cc55609 logging: Deprecate v1, default to v2
Reduced logging mode selection to deferred, immediate, minimal and
frontend. Decoupled logging version from mode and created CONFIG_LOG1
which can be used to explicitly select deprecated version.

From now on, chosing CONFIG_LOG_MODE_{IMMEDIATE,DEFERRED} will result
in version2.

Deprecated CONFIG_LOG2_MODE_{IMMEDIATE,DEFERRED} with cmake warning.

Codebase adapted to those changes.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-17 15:49:10 -05:00
Peter Mitsis
68c9845b41 shell: report thread runtime stats
Updates the kernel service to display the extended thread
runtime stats when the following shell command is issued.

 kernel threads

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-01-10 10:38:06 -05:00
Jakub Rzeszutko
d4559f53fa lib: getopt: rework and extend getopt library
Getopt has been rework in this way that calling it does not require
extra state parameter and its execution is thread safe.
Global parameters describing the state of the getopt function have been
made available to ensure full API compatibility in using this library.
However, referencing these global variables directly is not thread
safe. In order to get the state of the getopt function for the thread
that is currently using it, call: getopt_state_get();

Extended the library with getopt_long and getopt_long_only functions.

Moved getopt libary from utils to posix.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2022-01-06 21:26:59 +01:00
Krzysztof Chruscinski
4100c57faa shell: Fix immediate logging case
When logging is using immediate mode then logging messages
can be processed from any context, including interrupt context.
z_shell_fprintf was asserting in that case since it allowed to
be called from interrupt context only when logging was in panic
mode. However, shell works in the same way when logging is in
immediate mode as in panic mode.

Renamed internal shell flag from panic_mode to sync_mode. Flag
is also set when shell log backend is started in synchronous
mode (immediate logging) which prevents assertion.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-05 14:58:46 -05:00
Gerard Marull-Paretas
89a4f36fc8 device: remove inclusion of pm/device.h
The device PM subsystem _depends_ on device, not vice-versa. Devices
only hold a reference to struct pm_device now, and initialize this
reference with the value provided in Z_DEVICE_DEFINE. This requirement
can be solved with a forward struct declaration, meaning there is no
need to include device PM headers.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-29 11:08:38 +01:00
Krzysztof Chruscinski
c0808e3f59 logging: Minimal mode configuration cleanup
Remove LOG_MINIMAL kconfig option which was confusing
since LOG_MODE_MINIMAL existed. LOG_MINIMAL was used to
force minimal mode but because of invalid dependencies
it was leading to issues.

Refactored code to use LOG_MODE_MINIMAL everywhere and
renamed LOG_MINIMAL to LOG_DEFAULT_MINIMAL which has impact
on defualt logging mode (which still can be later changed
in conf file or in menuconfig).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-11-20 11:58:40 -05:00
Johann Fischer
fdcc104455 usb: remove Kconfig option USB_UART_CONSOLE
Since there are no more users and dependencies of
Kconfig option USB_UART_CONSOLE in the tree,
remove the remains and the option USB_UART_CONSOLE.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-18 14:29:18 +01:00
Christopher Friedt
3e86c627f7 kernel: atomics: update print specifiers for atomic_t
The print specifier for `atomic_t` should be updated
to `%ld`, `%lu`, or `%lx` to account for the type
change of `atomic_t` to `long`.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-11-15 09:59:01 -05:00
Robert Lubos
51dc4c3b1e shell: telnet: Disable echo
When telnet client queries about remote echo support, we reply that we
won't do it (which reduces the traffic), however the echo was not
actually disabled on the shell. In result characters were double-echoed
in the character mode (by both local echo from the client and remote
echo from the server).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-11 19:23:20 -05:00
Robert Lubos
c932354694 shell: telnet: Fix handling of multiple commands in a single packet
In case multiple commands were sent in a single packet, only the first
one was processed. Fix this by processing them in a loop.

As the subnegotiation command have variable length, and we currently
don't have any support for subnegotiation, stop processing packet when
such a command occurs.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-11 19:23:20 -05:00
Jakub Rzeszutko
f29d46ac4a shell: add a directory for backends
This change organizes the file structure for the shell.
Files implementing backends are moved to a separate folder.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-11-08 11:07:49 -05:00
Jakub Rzeszutko
b9d4471dbd shell: fix compilation error
Fixed compilatione error when shell sample has been build with flag
CONFIG_SHELL_VT100_COMMANDS set to n.

Fixes: #40124

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-11-06 21:38:02 -04:00
Torsten Rasmussen
0a29a5a26b kconfig: shell: experimental settings now uses select EXPERIMENTAL
With the introduction of `EXPERIMENTAL` and `WARN_EXPERIMENTAL` in
Zephyr all subsys/shell settings having `[EXPERIMENTAL]` in their
prompt has has been updated to include `select EXPERIMENTAL` so that
developers can enable warnings when experimental features are enabled.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-10-25 10:46:48 +02:00
Kumar Gala
fb4d68973f shell: Fix various build issues with string formattors
We get a few different CI failures associated with data type
differences on various platforms.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-10-20 10:54:38 -05:00
Krzysztof Chruscinski
eb3375f47c shell: Add __printf_like to shell_fprintf
Add __printf_like modifier to validate strings used by shell.
Fixing warnings triggered by this change.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-10-14 16:32:19 -04:00
Jakub Rzeszutko
8b8a3bbf71 shell: fix assert in panic mode
In panic mode, the function: z_shell_fprintf is expected to be
called from an interrupt context. Therefore, the dedicated assert
cannot be checked in this case.

Fixes #38612

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-10-01 14:42:25 -04:00
Jakub Rzeszutko
3ebe9c9ea1 shell: log backend minor improvements
Replace direct setting of the internal shell flag with a
dedicated function for this.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-09-28 20:02:01 -04:00
Jakub Rzeszutko
2b5723d455 shell: add init backend configuration
Each backend can configure separately features like colors on/off, VT100
handling and so on. This can be very handy for planned MQTT backend.
Shell will not send VT100 commands when VT100 is not enabled globally or
for particular backend.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-09-28 20:02:01 -04:00
Jakub Rzeszutko
0a50ebed01 shell: rework vt100 commands storage
VT100 commands are now stored as strings rather than character arrays.
This change will make it easier to create a unified macro for sending
all VT100 commands.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-09-28 20:02:01 -04:00
Michał Barnaś
01a01de594 shell: fix polling TXDONE signal by multiple threads
This patch fixes the issue that can cause a deadlock in shell.
When two threads simultaneously poll the TXDONE signal, only one
of them will receive it, leaving second one stalled.
The problem was that shell's context contains k_poll_event objects that
were polled by multiple threads. Polling it overwrites the poller field
that was set by previous thread.
Instead, the k_poll_event object must be created on the stack by every
thread that wants to poll the TXDONE signal.
This makes sure that no thread will be left waiting for this signal
forever.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2021-09-23 04:18:22 -04:00
Kamil Kasperczyk
e9f238889b shell: uart: Add waiting on DTR signal before sending data
Problem:
In some cases, as described in: https://github.com/zephyrproject-rtos/zephyr/issues/36948
shell backend sends characters to output before serial device
is ready for it. It results in observing additional characters
inserted on the shell input after device boot.

Solution:
Added waiting on DTR signal before sending anything to the output.

Fixes: #36948

Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
2021-09-02 19:39:16 -04:00
Yong Cong Sin
c1a45596c6 subsys/shell: Use use_colors flag for shell instance
Patches the instance_init to use the use_colors flag

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2021-09-02 10:47:57 +02:00
Kumar Gala
6c98d41ba6 shell: Fix builds for platforms without uart
We get build issues due to the removal of the Kconfig symbol
CONFIG_UART_SHELL_ON_DEV_NAME on platforms that didn't have a uart
set as we'd get a default value for those platforms.  Update the
Kconfig logic to only enable SHELL_BACKEND_SERIAL if we have
zephyr,shell-uart specified in the devicetree to address the issue.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-08-31 16:31:57 -05:00
Johann Fischer
741ae93ce2 shell: remove Kconfig option CONFIG_UART_SHELL_ON_DEV_NAME
Follow up on commit bfd45e5b8c
("drivers: remove Kconfig option CONFIG_UART_CONSOLE_ON_DEV_NAME")
Now we can also remove Kconfig option CONFIG_UART_CONSOLE_ON_DEV_NAME
since all UART drivers are converted to devicetree and we can just use
DEVICE_DT_GET(DT_CHOSEN(zephyr_shell_uart)).

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-24 17:15:58 -04:00
Mateusz Sierszulski
9d62f8d8ac shell: add devmem load command
This commit adds a devmem load command for shell that allows
users to easily load arbitrary data into the device memory.

Signed-off-by: Mateusz Sierszulski <msierszulski@internships.antmicro.com>
Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2021-08-13 10:13:36 -04:00
Fabio Baltieri
f88a420d69 toolchain: migrate iterable sections calls to the external API
This migrates all the current iterable section usages to the external
API, dropping the "Z_" prefix:

Z_ITERABLE_SECTION_ROM
Z_ITERABLE_SECTION_ROM_GC_ALLOWED
Z_ITERABLE_SECTION_RAM
Z_ITERABLE_SECTION_RAM_GC_ALLOWED
Z_STRUCT_SECTION_ITERABLE
Z_STRUCT_SECTION_ITERABLE_ALTERNATE
Z_STRUCT_SECTION_FOREACH

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2021-08-12 17:47:04 -04:00
Jakub Rzeszutko
1d00a75d21 shell: improve shell_execute_cmd function
The function to execute shell commands: shell_execute_cmd will now
behave similarly to invoking command line commands.
I.e. after the command is executed the command buffer is cleared,
while the cursor is set to the initial position.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-08-10 07:38:02 -04:00
Uday Ammu
17d2e9d084 shell: optionally configure priority of the shell thread
Currently, in Zephyr the shell thread is the lowest priority i.e.
K_LOWEST_APPLICATION_THREAD_PRIO. Due to this all the other threads can
preempt the shell thread. Proposed solution is to add Kconfig which
gives the flexibility to change the priority of the shell thread.

This is now implemented using a new Kconfig variable
SHELL_THREAD_PRIORITY_OVERRIDE. By setting this option
SHELL_THREAD_PRIORITY can be set.

Signed-off-by: Uday Ammu <udaykiran@google.com>
2021-07-27 19:11:47 -04:00
Marcin Niestroj
611a1ae51a shell: modules: devmem: use strtoul instead of strtol
All variables for address, width and value are unsigned, so use strtoul
instead of strtol. This fixes an issue when 0xffffffff is about to be
assigned to specific address, which was truncated to 0x7fffffff so far.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-07-07 21:01:07 -04:00
Gerard Marull-Paretas
cc2f0e9c08 pm: use enum for device PM states
Move all PM_DEVICE_STATE_* definitions to an enum. The
PM_DEVICE_STATE_SET and PM_DEVICE_STATE_GET definitions have been kept
out of the enum since they do not represent any state. However, their
name has not been changed since they will be removed soon.

All drivers and tests have been adjusted accordingly.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-07 14:13:12 -04:00
Krzysztof Chruscinski
e05aa6dc3e shell: Add option to bypass shell
Added api call that can set a callback that is called whenever
data is received on shell. When callback is set, shell processing
is bypassed and data is passed to that callback.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-07-02 13:35:18 -04:00
Henrik Brix Andersen
fe2075d140 shell: modules: promote edac mem shell subcommand to root shell command
Promote the "edac mem" shell subcommand to a generic "devmem" root shell
command. This command is useful for poking around registers and memory
outside of the EDAC drivers.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2021-07-02 13:21:25 -04:00
Hans Wilmers
414603fc9c shell: optionally set shell root command using Kconfig
If the shell root command shall be set in the application, e.g. for
implementing a login scheme, it is an advantage to set this already
during shell init.

This is now implemented using a new Kconfig variable SHELL_CMD_ROOT.

Signed-off-by: Hans Wilmers <hans@wilmers.no>
2021-06-16 10:41:17 +02:00
Bartosz Bilas
75a2ef8fc0 shell: allow disabling VT100 commands
Allow the user to disable VT100 commands to have a plain shell
without terminal emulation in order to avoid a lot of garbage
ASCII characters in shell output.

Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
2021-06-11 09:22:31 +02:00
Jakub Rzeszutko
4a85ecacda shell: fix tab for dynamic commands
The tabulator handler creates a single structure if it is handling
dynamic commands. If the currently processed dynamic command has a
dynamic subcommand they both share the same structure.
As a result tabulation operation may result in undefined behaviour.

As a solution, a new structure was introduced to keep subcommand
information.

Fixes #35926.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-06-04 12:23:15 -05:00
Krzysztof Chruscinski
f8e7ecfb56 shell: Add missing dependency to shell log backend
Shell log backend depends on logging being enabled. Lack of this
dependency leads to compilation failure when logging is disabled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-06-04 08:20:21 -05:00