Commit graph

599 commits

Author SHA1 Message Date
Nicolas Pitre
fb73ac392c lib/os/cbprintf_nano.c: several improvements
This makes cbprintf_nano.c much closer to the standard printf and
therefore more useful. The following are now implemented:

- right justification for everything (only for numbers previously)
- precision value for numbers, chars and strings
- width/precision passed as arguments with *
- "unlimited" padding length
- lower/uppercase hex output
- the #, + and ' ' flags are supported

And the code was heavily reworked to reduce its size as much as
possible to mitigate the size growth. Still, the binary resulting
from cbprintf_nano.c is now between 10% and 20% bigger depending on
the architecture. This is still far smaller than cbprintf_complete.c
which remains about twice as big on average even without FP support.

Many unit tests that were skipped with CONFIG_CBPRINTF_NANO are now
enabled, and a few more were added for good measure.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2021-02-23 19:39:59 +01:00
Dan Kalowsky
305ba26c6e subsys/shell: check for shell context before accessing it
The ASSERT order is backwards, where the shell->ctx is being accessed
before it is being checked as valid.  Moving the check for the
shell->ctx to before the using it.

Signed-off-by: Dan Kalowsky <dkalowsky@amperecomputing.com>
2021-02-22 15:20:37 +01:00
Peter Bigot
1fa3447b4e shell: device_service: refine level output
Fix the order so that it reflects the actual initialization order,
rather than putting PRE_KERNEL initializations after APPLICATION.

Add SMP in the proper location.

Use the helper function to provide unique identifiers for "devices"
that don't have a device pointer (so don't have a name).

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-19 15:46:16 -05:00
Peter Bigot
f0df72c269 shell: device_service: add dependency information
Refactor the output of device list to use standard API to retrieve the
list of devices, and to always display a status rather than hiding
disabled/failed devices.

Add API to associate a distinct identifier with any "device" that does
not have a name.

Where a device has requires dependencies display the devices on which
it depends.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-19 15:46:16 -05:00
Peter Bigot
6a6cf2183e Revert "shell: device_service: add dependency information"
This reverts commit a3af137c26.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-01-23 18:01:03 -05:00
Peter Bigot
a3af137c26 shell: device_service: add dependency information
Refactor the output of device list to use standard API to retrieve the
list of devices, and to always display a status rather than hiding
disabled/failed devices.

Add API to associate a distinct identifier with any "device" that does
not have a name.

Where a device has requires dependencies display the devices on which
it depends.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-01-21 14:49:04 -06:00
Jakub Rzeszutko
889e37b8d9 shell: shell_utils internal api update
Add prefix z_ to internal functions provided by the shell_utils
module.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-01-14 12:07:25 +01:00
Jakub Rzeszutko
31bc7d2d1e shell: make shell_root_cmd_find function static
Function shell_root_cmd_find was only used in shell_utils.c file.
Hence it is changed to static and renamed to root_cmd_find.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-01-14 12:07:25 +01:00
Jakub Rzeszutko
0738e1f04d shell: remove unused function shell_command_add
This function is not used at all.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-01-14 12:07:25 +01:00
Jakub Rzeszutko
0eea85bf08 shell: shell_ops internal api update
Add prefix z_ to internal functions provided by the shell_ops module.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-01-14 12:07:25 +01:00
Jakub Rzeszutko
52c999210f shell: internal api update in shell.h
Add Z_ prefix for internal macros.
Remove obsolete defines.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-01-14 12:07:25 +01:00
Jakub Rzeszutko
37e8d825bf shell: internal api update: log backend
Add prefix z_ to internal functions and macros handling log backend.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-01-14 12:07:25 +01:00
Jakub Rzeszutko
91b01ce703 shell: internal api update: history module
Add prefix z_ to internal functions handling history feature.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-01-14 12:07:25 +01:00
Jakub Rzeszutko
58c7114c17 shell: internal api update: wildcards
Mark global wildcard functions with z_ prefix.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-01-14 12:07:25 +01:00
Jakub Rzeszutko
fb6155a242 shell: internal api update: help module
Add prefix z_ to internal functions printing help.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-01-14 12:07:25 +01:00
Jakub Rzeszutko
460995c810 shell: internal api update: fprintf
Add z_ prefix to internal fprintf functions and macros.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2021-01-14 12:07:25 +01:00
Anas Nashif
dd931f93a2 power: standarize PM Kconfigs and cleanup
- Remove SYS_ prefix
- shorten POWER_MANAGEMENT to just PM
- DEVICE_POWER_MANAGEMENT -> PM_DEVICE

and use PM_ as the prefix for all PM related Kconfigs

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-09 15:18:29 -05:00
Peter Bigot
63638ceed6 shell: use public API to check device readiness
Avoid the private API now that there's a public equivalent.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-12-01 15:19:22 -05:00
Jakub Rzeszutko
3e65944cfe shell: documentation update
Updated the documantation with newly added configuration features.
Added information where to find minimal shell config file.
Added information how to activate particular features.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2020-11-30 16:03:01 -06:00
Jakub Rzeszutko
86df66290f shell: help feature improvement
Shell help printing function can now fully support
CONFIG_CBPRINTF_NANO.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2020-11-30 16:03:01 -06:00
Jakub Rzeszutko
6e18a63f9b shell: move help command to shell.c
The help command is needed to list all available commands
when it is not possible to use the tab key.
Previously when build-in commands were deactivated command
help was not compiled as well.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2020-11-30 16:03:01 -06:00
Jakub Rzeszutko
de7e208d8d shell: tab feature optimization
Add options to Kconfig that deactivate the Tab button and
autocompletion feature.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2020-11-30 16:03:01 -06:00
Jakub Rzeszutko
572d2b02a2 shell: select command feature optimalization
Added IS_ENABLED(CONFIG_SHELL_CMDS_SELECT) to remove a dead code.
Added static inline function that returns pointer to the selected
command.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2020-11-30 16:03:01 -06:00
Jakub Rzeszutko
0e91aada4a shell: history feature optimization
When history feature is not compiled in it makes no sense to
trim the command. In addition when history feature is not active the
shell will not call function history_put.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2020-11-30 16:03:01 -06:00
Daniel Leung
c7a0cdd1a5 shell: kernel: fix interrupt stack size calculation on SMP
When calculating the size of unused interrupt stacks on SMP,
the "unused" variable is not cleared between CPUs. So this
value keeps incrementing and does not reflect actual unused
size for CPUs other than the first one. So clear the "unused"
variable for each CPU.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-11-13 07:13:07 -05:00
Peter Bigot
125c5752a6 shell: switch to cbprintf as basis for printf functionality
Replace use of z_prf with cbprintf.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-13 06:38:01 -05:00
Peter Bigot
abb3a28c94 Revert "shell: support floating point output with newlib"
This reverts commit e812ee6c21.

This is the initial step towards replacing the core Zephyr formatting
infrastructure with a common functionally-complete solution.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-13 06:38:01 -05:00
Daniel Leung
939d48cb02 shell: show thread execution cycles
This adds the bits to show the thread execution cycles
when doing "kernel threads" in shell.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-11-11 23:55:49 -05:00
Peter Bigot
96bd6f79b9 shell: fix declarations for external device arrays
The objects should be const-qualified for consistency with other uses,
including declarations in headers.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-04 12:14:45 +01:00
Eduardo Montoya
846c01434c shell: increase stack size for OpenThread
Default shell stack size is not always enough when used with
OpenThread. Increasing it to the found adequate value.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2020-10-09 11:51:41 +02:00
Jakub Rzeszutko
19ef740950 shell: fix compilation error
Fix a compilation error when shell help feature was not selected and
but shell help command was compiled.

Fixes: #29042

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2020-10-09 11:48:44 +02:00
Marcin Niestroj
7451a32e98 mgmt: smp: shell: allow to configure multiple RX buffers via Kconfig
With only single RX buffer there is a high chance that such buffer will
not be processed before new bytes come in over UART. This is why it is
good to have at least two buffers, one which can be processed by SMP
layer, while another is being filled with new incoming bytes.

Add Kconfig option which allows to configure multiple buffers filled
with received UART SMP fragments. Use default value of 2, so we can
safely process already received frame in thread, while new fragment
comes in concurrently.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-10-07 14:51:06 +02:00
Marcin Niestroj
79fa92229a mgmt: smp: shell: use net_buf API for storing UART SMP fragments
So far there was a simple char array used as buffer, with additional
variable representing number of bytes already written into it. After
full frame was written, a boolean flag was simply set to notify thread
about being ready to be processed. There was however no mechanism
implemented to prevent new incoming bytes from overwriting such buffer
before (or during) being processed.

Use net_buf to store temporary frame. Define dedicated net_buf_pool,
from which such buffer will be allocated and freed after being
processed. This will prevent from reusing the same buffer before having
it fully processed (and returning once again to available buffer pool)
in shell thread.

Define also fifo that will store buffers that are ready to be
processed. This will be the mechanism for notifying thread about new
UART SMP fragments.

net_buf pool and k_fifo are used on purpose, keeping in mind their
additional overhead (mostly in RAM/ROM usage). This makes the code ready
for increasing number of buffers if needed. In this commit however we
stick with only 1 buffer, to keep minimal changes in processing flow.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-10-07 14:51:06 +02:00
Jakub Rzeszutko
f43985e334 shell: enhance help command
To get a list of all supported shell commands user must hit the TAB
button. It may be awkward on some terminal emulators. This change
enhances the help command in a way it will in addition print all
supported commands.

Fixes: #28785

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
2020-10-02 12:05:49 -04:00
Jakub Rzeszutko
137b7ec5bd shell: help functions update
Functions shell_help_subcmd_print and shell_help_cmd_print
are more generic. Now they can operate on command passed as an
argument not hard coded active_cmd.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
2020-10-02 12:05:49 -04:00
Jakub Rzeszutko
0cf6670b70 shell: improve function shell_cmd_get
The function can return existing root command even if dloc argument
is a NULL pointer.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
2020-10-02 12:05:49 -04:00
Jakub Rzeszutko
04903452f9 shell: add argc range in Kconfig
This commits adds a range to maximum number of arguments that can
build a command.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
2020-09-18 15:18:07 +02:00
Jakub Rzeszutko
bf5cf84191 shell: fix Tab crashing issue
Commit 770f232a67 removes an array
termination from the shell_make_argv function. This function was
called from two functions: execute and tab_handle. In the mentioned
commit termination was added only in the execute function.
As a result calling tab_handle function was causing a segmentation
fault. This fix adds array termination to the tab_handle function.

Fixes #28434

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
2020-09-18 15:18:07 +02:00
Ievgenii Meshcheriakov
aac3174677 shell: Fix typo in a comment
Typo: s/badckends/backends/.

Signed-off-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@nordicsemi.no>
2020-09-15 09:44:42 -05:00
Ievgenii Meshcheriakov
b00170436b shell: Make shell UART backend initialization priority configurable
Closes: #28331

Configurable initialization priority is useful when using CDC ACM
serial device, for example.

Signed-off-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@nordicsemi.no>
2020-09-15 09:44:42 -05:00
Krzysztof Chruscinski
770f232a67 shell: Fix case when too many arguments are provided
Shell was accepting CONFIG_SHELL_ARGC_MAX+1 arguments which lead to
memory corruption and fault. Added error message reported when number
of provided arguments exceeds CONFIG_SHELL_ARGC_MAX.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-09-14 16:05:11 +02:00
Jakub Rzeszutko
5554bdcab3 shell: fix printing from other threads
This fix prevents a scenario when command callback calls shell_fprintf
after the shell cleared the command context flag and before setting
the prompt correctly.

Fixes #27522

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
2020-09-03 21:54:47 +02:00
Peter Bigot
e812ee6c21 shell: support floating point output with newlib
shell_fprintf requires that formatted output be emitted with a
putchar()-like output function.  Newlib does not provide such a
capability.  Zephyr provides two solutions: z_prf() which is part of
minimal libc and handles floating point formatting, and z_vprintk()
which is core and does not support floating point.

Move z_prf() out of minimal libc into the core lib area, and use it
unconditionally in the shell.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-09-03 21:53:09 +02:00
Dominik Ermel
1b617a368f mgmt: smp: Change smp_shell_rx_byte to process data in bulk
The smp_shell_rx_byte has been renamed to smp_shell_rx_bytes and now
accepts data buffer pointer and its size as parameters. Return value
has been changed to size_t and represents number of bytes processed from
the given buffer.

The change has been done to more efficiently serve most common scenario
when the function is called in loop to process buffer, byte by byte.
Previously such operation required passing each byte separately,
with the change the function will work directly on source buffer
reducing number of calls and byte copy operations.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-09-03 21:53:00 +02:00
Tomasz Bursztyka
e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Flavio Ceolin
0aaae4a039 guideline: Make explicit fallthrough cases
-Wimplicit-fallthrough=2 requires a fallthrough comment or a compiler
to tells gcc that this happens intentionally.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-08-24 20:28:47 -04:00
Dominik Ermel
a3d47d9d7d shell: Fix signal shell_thread only when data received
In case when SMP has been enabled, the shell_thread would be signaled
even if no data has been read from fifo.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-08-24 11:48:19 +02:00
Dominik Ermel
d8c7fc8be6 shell: Fix uart_rx_handle byte processing when ring buffer full
In case when shell ring buffer gets full the data may still be taken
from the UART fifo, byte by byte, and accepted by the SMP back-end,
if the back-end has been enabled.

Unfortunately the uart_rx_handle failed to check if it has been
successfull in reading a byte from the fifo, before passing it to
the SMP for processing, which could lead to processing random stack data
as a part of an SMP frame.

Additinally, when the SMP would have accepted the byte,
the uart_rx_handle would fail to signal shell_thread, that the SMP has
internally buffered data that could be processed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-08-24 11:48:19 +02:00
Marcin Niestroj
f74feca027 mgmt: smp: shell: initialize SMP before feeding with received bytes
So far SMP shell transport was initialized in APPLICATION run level, but
shell over UART was initialized in POST_KERNEL. This could end up in
situation when received frames were scheduled for further processing in
SMP layer, when it was not initialized yet.

Export smp_shell_init() function declaration and call it before shell is
initialized with all its receive data handlers. This prevents situation
when data is scheduled for processing in SMP layer, when that one is not
ready yet.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-08-19 09:51:45 -04:00
Jakub Rzeszutko
a78ee2194a shell_ops: simplify flag_xxx_get functions
Removed obsolete assignments to bool values.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
2020-08-18 10:44:35 -04:00