Commit graph

688 commits

Author SHA1 Message Date
Dawid Niedzwiecki d64ce2531d mgmt: ec_host_cmd: add PM for SPI STM32 backend
The SPI STM32 Host Command backend doesn't use general SPI driver, so it
has to implement Power Management on its own.

The suspend procedure includes: setting pins to the sleep state,
disabling device clock and disabling CS pin interrupt.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-12-27 15:59:32 +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
Pieter De Gendt 276ae6c573 mcumgr: transport: smp_udp: Start socket on interface UP
The implementation waited for a NET_EVENT_L4_CONNECTED event to be
emitted. However we can start the receiving thread in case the interface
is up.

This allows for IPv6 Link Local addresses to be used with mcumgr.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-12-19 08:51:34 +01:00
Ruben Völl 2b83e91a43 mgmt: fs_mgmt: clear lock before return
Not clearing that lock lead to the fs_mgmt commands being useless, after
the mgmt callback returned `MGMT_CB_ERROR_RC` once, since the lock is now
occupied and never cleared.

Fixes #66581

Signed-off-by: Ruben Völl <ruben.voell@grandcentrix.net>
2023-12-18 11:17:00 +00:00
Jamie McCrae a48a594f13 mgmt: mcumgr: callback: Add op to receive callback
Adds the operation supplied by the client to the MCUmgr command
received callback

Signed-off-by: Jamie McCrae <spam@helper3000.net>
2023-12-15 11:48:59 +00:00
Kuno Heltborg 220a57b0b1 mgmt: mcumgr: improve custom payload types
Use a flag in `c:struct:mgmt_handler` to skip the cbor start and end byte,
and instead use pure custom user defined payload.

Signed-off-by: Kuno Heltborg <kunoh@live.dk>
2023-12-11 18:31:23 +01:00
Arkadiusz Wadowski 3fc40c9779 mgmt/osdp: Remove unused variable from osdp_phy_packet_finalize()
The variable was removed to avoid generating compilation warrning.


Signed-off-by: Arkadiusz Wadowski <wadowski.arkadiusz@gmail.com>
2023-12-08 20:20:56 +00:00
Arkadiusz Wadowski a9b0230360 mgmt/osdp: Fix compilation when CONFIG_OSDP_SC_ENABLED enabled
The 2 issues were found after CONFIG_OSDP_SC_ENABLED was enabled:
- missing curly brace after if
- typo in type name


Signed-off-by: Arkadiusz Wadowski <wadowski.arkadiusz@gmail.com>
2023-12-08 20:20:56 +00:00
Lingao Meng 786b9a0ad4 Bluetooth: Host: Add const prefix for UUID
Add const prefix for service uuid and char uuid.

Since Service UUID and Char UUID should not change in the service
definition, they are most reasonably defined as rodata, also for
save some ram footprint.

The field `attr->user_data` type is `void *`, as this PR change
all Service UUID to rodata, so there must add (void *) to avoid warning.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2023-12-07 16:16:43 +00:00
Arkadiusz Wadowski 90978b9f40 mgmt/osdp: Make OSDP slab init safer
slab_buff size is calculated based on size of osdp_ephemeral_data union
so it is safer to use same structure for slab init.
Changes in osdp_event or osd_cmd structures can cause crashes without this.

Signed-off-by: Arkadiusz Wadowski <wadowski.arkadiusz@gmail.com>
2023-11-30 10:02:20 +01:00
Jun Lin 3f9d24e4c0 mgmt: ec_host_cmd: shi_npcx: support the enhanced mode
The original SHI module only has one output FIFO buffer. It costs a lot
when the driver has to send/change the protocol control code because it
must fill out all 128 bytes of output FIFO. In npcx4, we introduce
another output buffer in 1-byte depth. These two buffers can switch back
and forth during the transaction. We can use the single-byte buffer
to send the control code and the 128-byte FIFO to send the data payload.
It helps improve the SHI driver's efficiency.

Signed-off-by: Jun Lin <CHLin56@nuvoton.com>
2023-11-24 11:45:13 +01:00
Jun Lin 717a7835bb mgmt: ec_host_cmd: shi_npcx: add pm_policy lock
Implement the pm_policy lock to prevent the chip enters the deep slepp
mode while shi transaction is ongoing.

Signed-off-by: Jun Lin <CHLin56@nuvoton.com>
2023-11-24 11:45:13 +01:00
Siddharth Chandrasekaran 5b24a8ad72 mgmt/osdp: Fix off-by-one in buf len checks
Initially, the command/reply ID byte was not part of the data length
macros. But later, when it was changed to include it, the buffer length
checks was not adjusted. Due to this, we were not using the last byte in
the buffer. Fix this issue by correcting the condition.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-11-23 09:59:52 +01:00
Siddharth Chandrasekaran 061a87aff8 mgmt/osdp: Replace __ASSERT() with an explicit if
Commit c7fec71193 ("mgmt/osdp: Add length checks for commands and
replies") attempted to remove code duplication by adding a macro to perform
a length check. At the time, a CI linter did not like macros with control
flow so the code was switched to a method which called __ASSERT() on this
condition.

The __ASSERT() macro is a nop if CONFIG_ASSERT=n (which is the default) and
causes the buffer access to be unguarded which may lead to OOB accesses.
This patch fixes the issue by reintroducing the if check.

Fixes: c7fec71193.
Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-11-23 09:59:52 +01:00
Jukka Rissanen bc8b5b3813 mgmt: updatehub: Fix CMakeLists.txt file
Fix the CMakeLists of the updatehub to link with mbedtls.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-11-21 08:48:04 +00: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 d31424e040 mgmt: osdp: Add dependency to UART runtime configuration
Force enabling of the UART runtime configuration for OSDP.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-11-15 10:02:18 +01:00
Krzysztof Chruściński 6d2e3b59a5 mgmt: mcumgr: smp_shell: Change the way shell uart device is fetched
SMP shell was looking into internal shell uart structures to get
uart device. This structures are now internal to the shell and
cannot be used. Using device tree chosen instead.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-11-14 16:09:08 +02:00
Jamie McCrae 6c4b89cb00 mgmt: mcumgr: grp: os_mgmt: Add datetime get/set functions
Adds datetime set and get functions which allow for setting and
getting the current time to/from the rtc alias device

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-11-13 09:48:13 +01:00
Anas Nashif 4e396174ce kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Ben Marsh 18a0952407 subsys/mgmt/mcumgr: Name struct to avoid violation
The mcumgr SMP UDP configs struct was causing a unique tag name
violation (rule 5.7).

The struct name has been changed from configs to smp_udp_configs.

Signed-off-by: Ben Marsh <ben.marsh@helvar.com>
2023-11-01 12:01:58 +00:00
Ben Marsh f9809a0a72 subsys/mgmt/mcumgr: Reduce unnecessary ROM usage
mcumgr's SMP UDP transport was unnecessarily using a potentially large
amount of ROM space due to static initialising fields in a
config struct that also contains buffers/stacks.

This has been changed to instead initialise fields in the start
function, reducing ROM usage by ~5K in the default configuration
with IPv4 and IPv6 enabled.

Signed-off-by: Ben Marsh <ben.marsh@helvar.com>
2023-11-01 12:01:58 +00:00
Jamie McCrae e3c06c5d8f mgmt: mcumgr: transport: Fix UDP user data buffer overflow
Fixes a buffer overflow issue if UDP is enabled for IPv4 only
but IPv6 networking is enabled

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-10-30 14:58:49 -05:00
Dawid Niedzwiecki 0aed42f2ee mgmt: ec_host_cmd: improve handling buffer sizes
Add the len_max rx structure member to indicate maximum number of bytes
possible to receive. It is needed to send information about our protocol
parameters to host.

Also, limit the maximum size of request/responses for backends that uses
buffers provided by the handler.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-10-27 13:26:00 -05:00
Jamie McCrae b032d0bc00 mgmt: mcumgr: grp: fs_mgmt: Select CRC if hash/checksum is enabled
Since CRC32 hash/checksum support is enabled by default, make it
select the CRC Kconfig symbol

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-10-23 12:15:41 +02:00
Jamie McCrae 8f5925c6de mgmt: mcumgr: Do not imply CRC
Only SMP over console transports need CRC support, therefore do
not imply CRC support for MCUmgr entirely because only 2 optional
transports require it

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-10-23 12:15:41 +02:00
Jamie McCrae 0c1d968581 mgmt: mcumgr: transport: shell/uart: Require CRC to use
SMP over console uses a checksum, therefore it is required in order
to enable these transports

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-10-23 12:15:41 +02:00
Jamie McCrae e8bbb033ef mgmt: mcumgr: grp: img_mgmt: Fix erase returning unknown error
Fixes an issue whereby the erase function would return an unknown
error, which would happen when the slot was already erased.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-10-23 10:03:02 +01:00
Dawid Niedzwiecki eac3ba2b3d mgmt: ec_host_cmd: remove timeout for UART callback
Do not use timeout for UART callback. The UART IRQ bases on the IDLE
line, so waiting for additional bytes is not necessary and it introduce
additional latency.

Another issue with the timeout is that the UART drivers use sysworkq for
implementing timeout. The sysworkq thread may have lower prio than the
host command thread, which may cause a delay in calling the UART
callback, which gives the semaphore to the HC handler.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-10-20 15:17:47 +02:00
Dawid Niedzwiecki f02c612c99 mgmt: ec_host_cmd: align buffers
Align the rx and tx buffers to prevent unaligned access.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-10-13 11:59:33 +03:00
Alexander Stark d385d10130 mgmt: mcumgr: update bt smp initialization
Oneline fix to smp_bt.c smp transport register.
smp_client_transport_register() is a void function and
has no return value, so it should be ignored.

Signed-off-by: Alexander Stark <alexander.t.stark@gmail.com>
2023-10-13 09:40:21 +01:00
Jamie McCrae c67560cbbd mcumgr: grp: settings_mgmt: Handle settings return values
Handles return values from settings handlers which were missing
and would return "Unknown error" to clients instead of the read
error

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-10-12 11:54:30 +01:00
Jamie McCrae 828940b420 mcumgr: grp: fs_mgmt: Fix error on hash/checksum of empty file
Fixes the error code being returned when trying to perform a
hash/checksum on an empty file to show it is because the file is
empty, not because a paramter (which was not provided) was too
large.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-10-12 11:54:01 +01:00
Flavio Ceolin e7bd10ae71 random: Rename random header
rand32.h does not make much sense, since the random subsystem
provides more APIs than just getting a random 32 bits value.

Rename it to random.h and get consistently with other
subsystems.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-10 14:23:50 +03:00
Stasys Aužbikas deac568b18 mgmt: mcumgr: transport: dummy: Fix truncating uint16_t
`smp_send_pos` is 16 bits wide but it was being
passed as uint8_t, thus truncating.
This made it impossible to receive packets
larger than 256 bytes.

Signed-off-by: Stasys Aužbikas <stasysau@gmail.com>
2023-10-05 11:22:32 +02:00
Martin Åberg 8130435c2a mgmt: mcumgr: grp: os_mgmt: Add SPARC
Define the preprocessor symbol PROCESSOR_NAME for SPARC to avoid a
preprocessor warning.

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2023-10-03 15:14:30 +01:00
Chandler Keep 27b4b9f4c8 mgmt/MCUmgr/mgmt: Support for finding registered command groups
This commit adds support for finding registered mcumgr command groups.

By default, supported command groups are local to the namespace where
they're registered. This api addition allows applications to get
reference to these supported command groups to deregister & re-register
them.

This adds scope for applications to support multiple implementations
of a command group alongside the default.

Signed-off-by: Chandler Keep <chandlersamkeep@gmail.com>
2023-09-30 18:48:06 +02:00
Dominik Ermel e48354455a mgmt/MCUmgr/grp/os: Add booloader info support
Adds command allowing to query information on bootloader.
In this case support is provided to query MCUboot information.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-09-28 16:27:45 +02:00
Flavio Ceolin 646a06c9fe random: Fix kconfig symbol name
s/CSPRING_ENABLED/CSPRNG_ENABLED/g

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-09-27 11:55:10 -05:00
Dominik Ermel f3067f2364 mgmt/MCUmgr/grp/img: Add support for DirectXIP with revert
The commit adds support for uploading image to board with MCUboot
configured with DirectXIP with revert.
It allows to set uploaded image either for test or as permanent
boot application, until newer image gets confirmed.
Note that in DirectXIP with revert MCUboot will remove image
that has not been set for test nor confirmed and MCUmgr does not
set either mode unless image has the mode set within uploaded
binary.
The commit adds Kconfig option
CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT
that enabled the new mode of operation within MCUmgr.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-09-26 13:40:11 +02:00
Dominik Ermel ea6129cd7c mgmt/MCUmgr/grp/img: Add support for three image configuration
The commit adds support for uploading images to secondary slots
of three images.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-09-22 15:13:31 +02:00
Jamie McCrae 0d5c508fc7 mgmt: mcumgr: grp: fs_mgmt: Update file upload errors
Updates possible return errors for fs mgmt file upload, to clarify
when a provided path is on a read-only filesystem or if the mount
point does not exist.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-09-21 11:54:26 +02:00
Dawid Niedzwiecki 340ffe1c48 mgmt: ec_host_cmd: fix struct init order
Order structure members according to the structure definition.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-09-21 09:28:59 +02:00
Dawid Niedzwiecki fa4086875d mgmt: ec_host_cmd: fix checking number of backends
If autoinit is not enebled, it is allowed to build a few backends and
initialize a proper one in runtime.

Check number of backends only if autoinit is enabled.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-09-21 09:28:59 +02:00
Juha Heiskanen 0c6a3faeb4 mgmt: mcumgr: Image management client fix
Fix broken MCUmgr image group client.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-09-19 15:21:08 +01:00
Kuno Heltborg 2d02cae964 MGMT: Add user data to mgmt_handler
RFC: #60616

Signed-off-by: Kuno Heltborg <kunoh@live.dk>
2023-09-19 15:20:58 +01:00
Carles Cufi 8c748fd005 kernel: Modify the signature of k_mem_slab_free()
Modify the signature of the k_mem_slab_free() function with a new one,
replacing the old void **mem with void *mem as a parameter.

The following function:
void k_mem_slab_free(struct k_mem_slab *slab, void **mem);

has the wrong signature. mem is only used as a regular pointer, so there
is no need to use a double-pointer. The correct signature should be:
void k_mem_slab_free(struct k_mem_slab *slab, void *mem);

The issue with the current signature, although functional, is that it is
extremely confusing. I myself, a veteran Zephyr developer, was confused
by this parameter when looking at it recently.

All in-tree uses of the function have been adapted.

Fixes #61888.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2023-09-03 18:20:59 -04:00
Dominik Ermel 1c7b069853 mgmt/MCUmgr/grp/img: Reduce logic in img_mgmt_slot_to_image
Makes img_mgmt_slot_to_image image number independent and moves
it to header file as static inline.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-08-31 10:19:15 +02:00
Dominik Ermel fe08ed65c0 mgmt/MCUmgr/grp/img: Simplify img_mgmt_get_unused_slot_area_id
Simplified and made CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER
independent.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-08-31 10:19:15 +02:00
Dominik Ermel 58b22bc4a9 mgmt/MCUmgr/grp/img: Improvement in image erase logic
The erase logic has been switched to using img_mgmt_get_opposite_slot
and the img_mgmt_get_other_slot has been removed.
The commit adds CONFIG_MCUMGR_GRP_IMG_ALLOW_ERASE_PENDING Kconfig
options, default set to n, that allows to make pending slot
erasable. The option only allows erase on pending slot that
is not revert slot.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-08-31 10:19:15 +02:00
Dominik Ermel 21c3263b95 mgmt/MCUmgr/grp/img: Reduce logic in img_mgmt_active_slot
Make img_mgmt_active_slot independent from
CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER for MCUboot swap type
algorithms.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-08-31 10:19:15 +02:00
Dominik Ermel 5739f2c6da mgmt/MCUmgr/grp/img: Switch to using img_mgmt_get_next_boot_slot
The commit modifies image list command operations to use
img_mgmt_get_next_boot_slot instead of directly relying of
MCUboot flags.
The function is now used, also, by img_mgmt_slot_in_use to
figure out whether queried slot is in use.
The commit introduces two new Kconfig options
 MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_IMAGE_SECONDARY
 MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_IMAGE_ANY
that allow users to enable confirming non-active images slots.
The MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_IMAGE_SECONDARY is y
by default to keep original behavior of logic that accidentally
allowed confirming secondary slot.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-08-31 10:19:15 +02:00
Dominik Ermel 81e98d2487 mgmt/MCUmgr/grp/img: Add img_mgmt_get_next_boot_slot
The commit adds functions:
 img_mgmt_get_next_boot_slot
 img_mgmt_get_opposite_slot

to simplify obtaining information on next boot slot.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-08-31 10:19:15 +02:00
Fabio Baltieri d1504ff66f mcumgr: fix few mismatched CONTAINER_OF
Fix a missing first element reference in a CONTAINER_OF.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-30 10:22:00 +02:00
Georges Oates_Larsen b25ea4742e net: conn_mgr: Rename connectivity monitor
The connectivity monitoring subfeature of conn_mgr is currently also
named conn_mgr, which is confusing.

This commit renames it to conn_mgr_monitor, or conn_mgr_mon for short,
for clarity.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-08-29 16:13:37 +02:00
Gerard Marull-Paretas aa4ebc1f63 mgmt: ec_host_cmd: simulator: s/device.h/init.h
File is not using any device.h API, but init.h (SYS_INIT).

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-08-29 11:54:19 +01:00
Fabio Baltieri 7b59e34a22 mgmt: mcumgr: drop few redeclared/shadowed variables
Drop few redeclared variables, fixes some:

settings_mgmt.c:454:30: error: declaration of ok shadows a previous
local [-Werror=shadow]
  454 |                         bool ok;
      |                              ^~
settings_mgmt.c:436:14: note: shadowed declaration is here
  436 |         bool ok = true;
      |              ^~

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-28 17:17:24 +02:00
Fabio Baltieri ec71be5d9d drivers,subsys: fix few missing k_work_delayable_from_work
Fix few instances of delayable work handlers using the k_work pointer
directly in a CONTAINER_OF pointing to a k_work_delayable.

This is harmless since the k_work is the first element in
k_work_delayable, but using k_work_delayable_from_work is the right way
of handling it.

Change a couple of explicit CONTAINER_OF doing the same work as the
macro in the process.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-28 10:12:21 +02:00
Jamie McCrae 55527d8733 mgmt: mcumgr: Add settings management
Adds a settings management group to MCUmgr which allows for
manipulation of the zephyr settings from a remote device.
Includes callback hooks to secure access from an application.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-25 10:54:06 +01:00
Dominik Ermel 535278a3ba mgmt/MCUmgr/grp: Add missing const in mgmt_handler definitions
Make mgmt_handler definitions static const for shell and stat
groups.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-08-24 15:52:49 +02:00
Juha Heiskanen ea84ef55da mcumgr: img_mgmt_client: Fix Image upload max data length
MCUmgr client upload max data payload length was missing
Transport layer CRC + 16bit lenght. Full net buf packet was
possible to send but receiver side it was blocked because there
was not space for calculate CRC and length.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-08-24 12:57:10 +02:00
Dawid Niedzwiecki 63af3c00e9 mgmt: ec_host_cmd: add SPI SMT32 backend
Add support for SPI host command backend for STM32 chips family.

Unfortunately, the current SPI API can't be used to handle the host
commands communication. The main issues are unknown command size sent
by the host(the SPI transaction sends/receives specific number of bytes)
and need to constant sending status byte(the SPI module is enabled and
disabled per transaction). Thus the SPI backend includes basic SPI STM32
driver adjusted to host command specification.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-08-21 15:11:21 +02:00
Jamie McCrae 5c88d45544 treewide: mgmt: mcumgr: Change "ret" to "err" for SMP version 2
This is a stable API treewide change changing the newly introduced
"ret" response to "err" as it was overlooked that the shell_mgmt
group already used "ret" to return the exit code of the command
and this created a collision. Since SMP version 2 was only recently
introduced, there should not be any public implementations of it
as of yet, but the original function has been kept and marked as
deprecated.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-21 10:18:50 +02:00
Jamie McCrae 0001d01bfe mgmt: mcumgr: Allow additional cbor states for encoding
Allows selecting more than the default number of encoding states.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-21 10:12:06 +02:00
Jamie McCrae 8de70bc294 mgmt: mcumgr: transport: udp: Fix non-automatic start
Fixes a stray ifdef which causes a build failure if the automatic
UDP start Kconfig is not enabled.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-21 10:11:50 +02:00
Anas Nashif ccba6d4143 mcumgr: do noy rely on CRC being enable, imply CRC in Kconfig
CRC is now disabled by default, so use imply to enable it.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-08-18 08:52:16 +03:00
Jamie McCrae 4b9dddcd3a mgmt: mcumgr: grp: os_mgmt: Add force parameter to reset command
Adds the force parameter to the reset command which is now
provided to the callback hook (if enabled).

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-04 12:17:07 +02:00
Jamie McCrae 9023a8e14f mgmt: mcumgr: grp: stat_mgmt: Use zcbor decode bulk function
Uses the zcbor decode bulk function instead of manually parsing the
array in the function to reduce duplicated code.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-04 10:44:29 +02:00
Jamie McCrae 8616e6ac01 mgmt: mcumgr: grp: os_mgmt: Use zcbor decode bulk function for echo
Uses the zcbor decode bulk function instead of manually parsing the
array in the function to reduce duplicated code.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-04 10:44:29 +02:00
Jamie McCrae a0a9539d02 mgmt: mcumgr: grp: Fix error translation function indent
Fixes lines not being indented and looking like a single blob

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-31 12:49:36 +02:00
Jamie McCrae 588f6acbd5 mgmt: mcumgr: grp: img_mgmt: Fix not checking write bounds
Fixes an issue whereby the data packets were not checked to ensure
that the client has not attempted to write more data than the size
that was provided in the original upload packet.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-31 10:43:54 +02:00
Jamie McCrae 9422fc6e20 mgmt: mcumgr: grp: img_mgmt: Fix not checking image upload size
Fixes an issue whereby upload image size would not be checked in
the first packet of an upload, which would allow an image to be
uploaded until it reached the point of it being too large to
fit anymore.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-31 10:43:54 +02:00
Jamie McCrae 097c568c81 mgmt: mcumgr: grp: fs_mgmt: Fix wrong error checking
Fixes an issue with not properly checking error responses.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-31 10:43:28 +02:00
Juha Heiskanen d77a657526 mgmt: smp: MCUmgr Client support
MCUmgr client basic implementation for support Image and OS grpup
commands.

Image Group:
* Image state read/write
* Image Upload secondary slot
* Image Erase secondary slot

OS group:
* Reset
* Echo service, disabled by default

Opeartion's are blocked call and cant't call inside worker queue.
IMG and OS need to be SMP client object for transport.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-07-27 14:35:43 +02:00
Juha Heiskanen 5797e4241e mgmt: smp: SMP Client enabler
SMP client support for generate request and handling
response message.

Updated SMP transport for send request.

Added API for register SMP transport.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-07-27 14:35:43 +02:00
Jamie McCrae 8ecedf2dfb mgmt: mcumgr: grp: img_mgmt: Fix renamed define
Fixes an issue whereby a define was renamed in one place but not
another.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-27 11:16:04 +02:00
Jamie McCrae 7ca7f5a39c mgmt: mcumgr: Use MCUboot bootutil file instead of outdated copy
Uses the MCUboot bootutil image.h file directly instead of an
outdated copy which resides in the zephyr tree.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-26 14:32:20 +02:00
Girisha Dengi 75547dd522 soc: arm64: Add agilex5 soc folder and its configurations
Add Agilex5 soc folder, MMU table and its configurations for
Intel SoC FPGA Agilex5 platform for initial bring up.
Add ARM Cortex-a76 and Cortex-a55 HMP cluster type.

Signed-off-by: Teik Heng Chong <teik.heng.chong@intel.com>
Signed-off-by: Girisha Dengi <girisha.dengi@intel.com>
2023-07-25 16:58:01 +00:00
Jamie McCrae ee5c9b2629 mgmt: mcumgr: grp: img_mgmt: Add image data written callback
Adds an optional callback upon image data being written, can be
used for syncing or timeout purposes.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-20 14:55:46 +00:00
Jamie McCrae 6c541e1af0 mgmt: mcumgr: Add event ID index callback function
Adds a function which gets the callback ID index of a given
event ID.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-20 14:55:46 +00:00
Jamie McCrae ecfbabd213 mgmt: mcumgr: Make SMP version 2 to legacy error lookup extensible
Replaces the manual lookup function with a lookup function which
is provided when registering MCUmgr handlers which can be used to
find the function to translate error codes, allowing out of tree
MCUmgr handlers to provide error translation handlers.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-20 10:35:14 +00:00
Dominik Ermel ebaa145818 mgmt/MCUmgr/img: Fix build issue with slot0_ns_partition
The commit fixes build issue when building for two application
images in board that does not have slot0_ns_partition.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-07-14 17:49:02 +02:00
Dominik Ermel cb4aa46faf mgmt/MCUmgr/img: Fix img_mgmt_get_other_slot
Fix conditional compilation within img_mgmt_get_other_slot,
where CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER has been
incorrectly checked and #endif incorrectly placed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-07-14 17:48:40 +02:00
Dawid Niedzwiecki c590c5c1ee mgmt: ec_host_cmd: add suppressing commands
Add a feature to suppress commands. The suppressed commands are not
logged on the command reception.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-14 09:38:20 +02:00
Dawid Niedzwiecki cf3b0381ae mgmt: ec_host_cmd: fix init of npxc shi backend
Make sure not to access not assigned pointer at the begining of the
initialization.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-13 09:21:08 +02:00
Dawid Niedzwiecki b04692b747 mgmt: ec_host_cmd: add user callback for a new command
Add a user possibility to set a callback for receiving a new function.
It allows instant performing some actions, that need to be done before
context switch.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-12 09:26:42 +02:00
Dawid Niedzwiecki b6a3254d8b mgmt: ec_host_cmd: verify a command before passing it to handler
Verify validity of a received command before passing it to the general
handler.

It allows performing some actions, right after receiving the command.
The context switch is not needed. Such feature may be needed for
overloaded system, where instant reboot is required.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-12 09:26:42 +02:00
Dawid Niedzwiecki 1b6d6fb135 mgmt: ec_host_cmd: add function to signal a new command
Add a function to signal a new host command by a backend.

Use a function instead of giving semaphore, because it allows more
actions on rx event, common for all backends.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-12 09:26:42 +02:00
Dawid Niedzwiecki 7a479eec0d mgmt: ec_host_cmd: save result of IN_PROGRESS command
Add a config to save the final result of a last host command that has
sent EC_HOST_CMD_IN_PROGRESS response. To get the final result use the
ec_host_cmd_send_in_progress_status function.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-12 09:26:42 +02:00
Mykola Kvach d0472aae7a soc: arm64: add Renesas Rcar Gen3 SoC support
Add files for supporting arm64 Renesas r8a77951 SoC.
Add config option CPU_CORTEX_A57.

Enable build of clock_control_r8a7795_cpg_mssr.c for
a new ARM64 SoC R8A77951.

Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
2023-07-11 11:17:41 +02:00
Jamie McCrae c9a4764c10 mgmt: mcumgt: smp: Fix not checking returned status
Fixes not checking if a zcbor operation was successful.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-10 12:04:40 +02:00
Jamie McCrae fbacedaef8 mgmt: mcumgr: grp: shell_mgmt: Fix issue with unset variable
Fixes an issue where a variable was used without being correctly
set by other parts of the code.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-10 09:26:19 +02:00
Dawid Niedzwiecki 40924edec2 mgmt: ec_host_cmd: fix checking command version
The sizeof is used in a wrong way which causes incorrect checking a
version of a command. Use NUM_BITS instead.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-07 09:22:13 +02:00
Dawid Niedzwiecki 521f0ba4f8 mgmt: ec_host_cmd: clear response buffer every command
The response buffer has to be cleared every command not to pass
unintended content e.g. response from a previous command, or stack
content.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-07 09:22:13 +02:00
Dawid Niedzwiecki f2d6e0f660 mgmt: ec_host_cmd: set max response every command
Update the response buffer size, passed to a command handler, every
command, since a backend could change it in runtime.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-07 09:22:13 +02:00
Matthias Breithaupt 04ce5b9e58 mgmt: hawkbit: remove NET_SOCKETS_POSIX_NAMES dependency
Currently, it is not possible to use hawkbit with code that requires
POSIX_API to be set due to the dependency on NET_SOCKETS_POSIX_NAMES.
Since a lot of other code has already been moved to `zsock_`, this
commit does the same for hawkbit.

Co-authored-by: rojedag <r.ojeda@vogl-electronic.com>
Signed-off-by: Matthias Breithaupt <m.breithaupt@vogl-electronic.com>
2023-06-28 06:32:45 +00:00
Dawid Niedzwiecki c8c149dce8 mgmt: ec_host_cmd: add logging system
Add a native way to log Host Command communication.

Use Zephyr logging system to do it. Use debug and normal levels.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-06-26 16:13:42 +02:00
Dawid Niedzwiecki 159f56d57e mgmt: ec_host_cmd: use one command to send response
Use one common function to send Host Command response. It allows
handling all response types within one function.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-06-26 16:13:42 +02:00
Marek Pieta 6bbd6d3794 mcumgr: img_mgmt: Fix unused "status" variable warning
Changes aligns ifdefs to fix compilation warnings related to unused
"status" variable.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2023-06-26 12:31:05 +00:00
Jamie McCrae 6877ad413f mgmt: mcumgr: smp: Allow preventing command execution via hook
Adds status checking to the command status hook which allows an
application to inspect a request and, optionally, reject it.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-06-21 13:24:12 +02:00