Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zcbor 0.8.1 #13768

Merged
merged 15 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/nrf/links.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@

.. _`commit #d55314`: https://github.com/nrfconnect/sdk-nrf/commit/d553142f4f37bc324da9869e4837cdd9105e25ab

.. _`zcbor 0.8.0 release notes`: https://github.com/zephyrproject-rtos/zcbor/blob/0.8.0/RELEASE_NOTES.md
.. _`zcbor 0.8.1 release notes`: https://github.com/zephyrproject-rtos/zcbor/blob/0.8.1/RELEASE_NOTES.md

.. ### Source: github.io

.. _`TinyCBOR`: https://intel.github.io/tinycbor/current/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ The following list summarizes the most important changes inherited from the upst
* Renamed the ``CONFIG_CHIP_SED_ACTIVE_INTERVAL`` Kconfig option to :kconfig:option:`CONFIG_CHIP_ICD_FAST_POLLING_INTERVAL`.
* Renamed the ``CONFIG_CHIP_SED_ACTIVE_THRESHOLD`` Kconfig option to :kconfig:option:`CONFIG_CHIP_ICD_ACTIVE_MODE_THRESHOLD`.

* zcbor 0.7.0 to 0.8.1.

Thread
------

Expand Down Expand Up @@ -358,6 +360,10 @@ Bluetooth samples

* Corrected the behavior when building with the :ref:`ble_rpc` library.

* :ref:`bluetooth_central_dfu_smp` sample:

* Updated to adapt to API changes in zcbor 0.8.x.

Bluetooth Mesh samples
----------------------

Expand Down Expand Up @@ -758,6 +764,13 @@ DFU libraries

* The :kconfig:option:`CONFIG_DFU_TARGET_FULL_MODEM_USE_EXT_PARTITION` Kconfig option to be automatically enabled when ``nordic,pm-ext-flash`` is chosen in the devicetree.
See :ref:`partition_manager` for details.
* Adapted to API changes in zcbor 0.8.x.

* :ref:`lib_fmfu_fdev` library:

* Updated:

* Regenerated cbor code with zcbor 0.8.1 and adapted to API changes in zcbor 0.8.x.

Modem libraries
---------------
Expand Down Expand Up @@ -846,6 +859,10 @@ Modem libraries

* Fixed a potential race condition, where two threads might corrupt a shared response buffer.

* :ref:`lib_modem_attest_token` library:

* Updated to adapt to API changes in zcbor 0.8.x.

Libraries for networking
------------------------

Expand Down Expand Up @@ -898,6 +915,8 @@ Libraries for networking

This parameter determines whether CoAP CON or NON messages are used.

* Regenerated cbor code with zcbor 0.8.1 and adapted to API changes in zcbor 0.8.x.

* :ref:`lib_nrf_cloud_log` library:

* Added:
Expand Down Expand Up @@ -932,9 +951,13 @@ Libraries for networking
* :ref:`lib_nrf_provisioning` library:

* Renamed nRF Device provisioning to :ref:`lib_nrf_provisioning`.
* Updated the device mode callback to send an event when the provisioning state changes.
* Fixed file descriptor handling by setting the :c:struct:`coap_client` structure's ``fd`` field to ``-1`` when closing the socket.
* Added the :kconfig:option:`CONFIG_NRF_PROVISIONING_PRINT_ATTESTATION_TOKEN` option to enable printing the attestation token when the device is not yet claimed.
* Updated:

* The device mode callback sends an event when the provisioning state changes.
* Regenerated cbor code with zcbor 0.8.1 and adapted to API changes in zcbor 0.8.x.

* Fixed file descriptor handling by setting the :c:struct:`coap_client` structure's ``fd`` field to ``-1`` when closing the socket.

* :ref:`lib_nrf_cloud_fota` library:

Expand Down Expand Up @@ -1091,7 +1114,15 @@ Additions specific to |NCS|
zcbor
=====

|no_changes_yet_note|
zcbor has been updated from 0.7.0 to 0.8.1.
For more information see the `zcbor 0.8.0 release notes`_ and the `zcbor 0.8.1 release notes`_.

* Added:

* Support for unordered maps.
* Performance improvements.
* Naming improvements for generated code.
* Bugfixes.

Trusted Firmware-M
==================
Expand Down
3 changes: 2 additions & 1 deletion lib/modem_attest_token/modem_attest_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ int modem_attest_token_parse(struct nrf_attestation_token const *const token_in,
goto cleanup;
}

zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), bin_buf, bin_buf_sz, 1);
zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), bin_buf, bin_buf_sz, 1,
NULL, 0);

/* Get attestation token data */
err = get_attest_data(states, data_out);
Expand Down
9 changes: 5 additions & 4 deletions samples/bluetooth/central_smp_client/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ static void smp_echo_rsp_proc(struct bt_dfu_smp *dfu_smp)
char map_value[SMP_ECHO_MAP_VALUE_MAX_LEN];
bool ok;

zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), smp_rsp_buff.payload, payload_len, 1);
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), smp_rsp_buff.payload, payload_len, 1,
NULL, 0);

/* Stop decoding on the error. */
zsd->constant_state->stop_on_error = true;
Expand Down Expand Up @@ -360,7 +361,7 @@ static void smp_echo_rsp_proc(struct bt_dfu_smp *dfu_smp)
}

static int send_smp_echo(struct bt_dfu_smp *dfu_smp,
const char *string)
const char *string, size_t string_max_len)
{
static struct smp_buffer smp_cmd;
zcbor_state_t zse[CBOR_ENCODER_STATE_NUM];
Expand All @@ -374,7 +375,7 @@ static int send_smp_echo(struct bt_dfu_smp *dfu_smp,

zcbor_map_start_encode(zse, CBOR_MAP_MAX_ELEMENT_CNT);
zcbor_tstr_put_lit(zse, "d");
zcbor_tstr_put_term(zse, string);
zcbor_tstr_put_term(zse, string, string_max_len);
zcbor_map_end_encode(zse, CBOR_MAP_MAX_ELEMENT_CNT);

if (!zcbor_check_error(zse)) {
Expand Down Expand Up @@ -409,7 +410,7 @@ static void button_echo(bool state)
++echo_cnt;
printk("Echo test: %d\n", echo_cnt);
snprintk(buffer, sizeof(buffer), "Echo message: %u", echo_cnt);
ret = send_smp_echo(&dfu_smp, buffer);
ret = send_smp_echo(&dfu_smp, buffer, sizeof(buffer));
if (ret) {
printk("Echo command send error (err: %d)\n", ret);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/requirements-build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cryptography>=42.0.0
imagesize>=1.2.0
intelhex
pylint
zcbor
zcbor~=0.8.0
2 changes: 1 addition & 1 deletion scripts/requirements-extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Pillow>=10.2.0
editdistance>=0.5.0
PyGithub
jinja2>=3.1.3
zcbor==0.7.0
zcbor>=0.8.0
nrfcredstore>=1.0.0,<2
6 changes: 3 additions & 3 deletions scripts/requirements-fixed.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ future==0.18.3 # via junitparser
gcovr==6.0 # via -r zephyr/scripts/requirements-build-test.txt
gitdb==4.0.10 # via gitpython
gitlint==0.18.0 # via -r nrf/scripts/requirements-ci.txt, -r zephyr/scripts/requirements-extras.txt
gitlint-core==0.18.0 # via gitlint, gitlint-core
gitlint-core==0.18.0 # via gitlint
gitpython==3.1.41 # via -r nrf/scripts/requirements-ci.txt
graphviz==0.20.1 # via -r zephyr/scripts/requirements-extras.txt
grpcio==1.58.0 # via grpcio-tools
Expand Down Expand Up @@ -84,7 +84,7 @@ pyelftools==0.30 # via -r zephyr/scripts/requirements-base.txt, pyocd
pygit2==1.10.0 # via -r nrf/scripts/requirements-extra.txt
pygithub==1.59.1 # via -r nrf/scripts/requirements-extra.txt, -r zephyr/scripts/requirements-extras.txt
pygments==2.16.1 # via gcovr
pyjwt==2.8.0 # via pygithub, pyjwt
pyjwt==2.8.0 # via pygithub
pykwalify==1.8.0 # via -r zephyr/scripts/requirements-base.txt, west
pylink-square==1.2.0 # via -r zephyr/scripts/requirements-base.txt, pyocd
pylint==2.17.5 # via -r nrf/scripts/requirements-build.txt, -r zephyr/scripts/requirements-compliance.txt
Expand Down Expand Up @@ -125,7 +125,7 @@ west==1.2.0 # via -r nrf/scripts/requirements-base.txt, -r zephyr/
wget==3.2 # via -r nrf/scripts/requirements-ci.txt
wrapt==1.15.0 # via astroid, deprecated, python-can
yamllint==1.32.0 # via -r zephyr/scripts/requirements-compliance.txt
zcbor==0.7.0 # via -r nrf/scripts/requirements-build.txt, -r nrf/scripts/requirements-extra.txt, -r zephyr/scripts/requirements-extras.txt
zcbor==0.8.1 # via -r nrf/scripts/requirements-build.txt, -r nrf/scripts/requirements-extra.txt, -r zephyr/scripts/requirements-extras.txt
zipp==3.17.0 # via importlib-metadata, importlib-resources

# The following packages are considered to be unsafe in a requirements file:
Expand Down
2 changes: 1 addition & 1 deletion subsys/dfu/dfu_multi_image/src/dfu_multi_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static int parse_cbor_header(void)
uint_fast32_t image_count;

ZCBOR_STATE_D(states, CBOR_HEADER_NESTING_LEVEL, ctx.buffer + FIXED_HEADER_SIZE,
ctx.cur_item_size - FIXED_HEADER_SIZE, 1);
ctx.cur_item_size - FIXED_HEADER_SIZE, 1, 0);

res = zcbor_map_start_decode(states);
res = res && zcbor_tstr_expect_lit(states, "img");
Expand Down
2 changes: 1 addition & 1 deletion subsys/dfu/dfu_target/src/dfu_target_smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static int dfu_target_smp_recovery_enable(void)
{
int rc;

rc = os_mgmt_client_echo(&os_gr_client, dfu_smp_echo_str);
rc = os_mgmt_client_echo(&os_gr_client, dfu_smp_echo_str, sizeof(dfu_smp_echo_str));
LOG_DBG("Recovery activate status %d", rc);

return rc;
Expand Down
2 changes: 0 additions & 2 deletions subsys/dfu/fmfu_fdev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ zephyr_library()

zephyr_library_sources(src/fmfu_fdev.c)

zephyr_compile_definitions(fmfu_fdev CDDL_CBOR_CANONICAL)

if (CONFIG_FMFU_CDDL_DECODER_GENERATE)
add_subdirectory(cddl)
else()
Expand Down
2 changes: 1 addition & 1 deletion subsys/dfu/fmfu_fdev/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ menuconfig FMFU_FDEV
if (FMFU_FDEV)

config FMFU_CDDL_DECODER_GENERATE
bool
bool "Regenerate FMFU CBOR code from cddl using zcbor, for internal use."
help
Nordic internal, see cddl/CMakeLists.txt

Expand Down
9 changes: 4 additions & 5 deletions subsys/dfu/fmfu_fdev/cddl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,23 @@ find_program(
if(NOT CLANG_FORMAT)
message(WARNING
"'clang-format' not found, generated code will not be formatted")
else()
set(CLANG_FORMAT_COMMAND
COMMAND ${CLANG_FORMAT} -i "${decode_c};${decode_h};${types_h}")
endif()

add_custom_command(
OUTPUT ${decode_c} ${decode_h} ${types_h}
COMMAND
${PYTHON_EXECUTABLE}
${ZEPHYR_ZCBOR_MODULE_DIR}/zcbor/zcbor.py
code
-c ${cddl_file}
--default-max-qty 128 # TNSW-33521
code
--oc ${decode_c}
--oh ${decode_h}
--oht ${types_h}
-t ${entry_types}
-d # Decode
COMMAND
${CMAKE_COMMAND} -DFILES="${decode_c}\;${decode_h}\;${types_h}" -P ${license}
${CLANG_FORMAT_COMMAND}
COMMENT
"Generating files based on ${cddl_file}"
DEPENDS ${license} ${cddl_file}
Expand All @@ -86,11 +82,14 @@ zephyr_include_directories(${include_out})

# Create install target which allows the user to 'install' the generated
# parser files into the working tree.
# Run clang format here in case the build folder is outside the nrf tree,
# in which case clang-format doesn't find the config file.
add_custom_target(
fmfu_cddl_modem_update_install
COMMAND ${CMAKE_COMMAND} -E copy ${decode_c} ${src_install_dir}/${decode_c_name}
COMMAND ${CMAKE_COMMAND} -E copy ${decode_h} ${include_install_dir}/${decode_h_name}
COMMAND ${CMAKE_COMMAND} -E copy ${types_h} ${include_install_dir}/${types_h_name}
COMMAND ${CLANG_FORMAT} -i ${src_install_dir}/${decode_c_name} ${include_install_dir}/${decode_h_name} ${include_install_dir}/${types_h_name}
DEPENDS
${decode_c} ${decode_h} ${types_h}
COMMENT
Expand Down
4 changes: 3 additions & 1 deletion subsys/dfu/fmfu_fdev/cddl/license.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

string(TIMESTAMP NOW_YEAR "%Y")

set(LICENSE "\
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* Copyright (c) ${NOW_YEAR} Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
Expand Down
13 changes: 10 additions & 3 deletions subsys/dfu/fmfu_fdev/include/modem_update_decode.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/*
* Generated using zcbor version 0.5.1
* Generated using zcbor version 0.8.1
* https://github.com/NordicSemiconductor/zcbor
* Generated with a --default-max-qty of 128
*/
Expand All @@ -17,9 +17,12 @@
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "zcbor_decode.h"
#include "modem_update_types.h"

#ifdef __cplusplus
extern "C" {
#endif

#if DEFAULT_MAX_QTY != 128
#error "The type file was generated with a different default_max_qty than this file"
#endif
Expand All @@ -33,4 +36,8 @@ int cbor_decode_Sig_structure1(const uint8_t *payload, size_t payload_len,
int cbor_decode_Segments(const uint8_t *payload, size_t payload_len, struct Segments *result,
size_t *payload_len_out);

#ifdef __cplusplus
}
#endif

#endif /* MODEM_UPDATE_DECODE_H__ */
41 changes: 25 additions & 16 deletions subsys/dfu/fmfu_fdev/include/modem_update_types.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/*
* Generated using zcbor version 0.5.1
* Generated using zcbor version 0.8.1
* https://github.com/NordicSemiconductor/zcbor
* Generated with a --default-max-qty of 128
*/
Expand All @@ -16,8 +16,11 @@
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "zcbor_decode.h"
#include <zcbor_common.h>

#ifdef __cplusplus
extern "C" {
#endif

/** Which value for --default-max-qty this file was created with.
*
Expand All @@ -29,30 +32,36 @@
#define DEFAULT_MAX_QTY 128

struct Segment {
uint32_t _Segment_target_addr;
uint32_t _Segment_len;
uint32_t Segment_target_addr;
uint32_t Segment_len;
};

struct Segments {
struct Segment _Segments__Segment[128];
uint_fast32_t _Segments__Segment_count;
struct Segment Segments_Segment_m[128];
size_t Segments_Segment_m_count;
};

struct Sig_structure1 {
struct zcbor_string _Sig_structure1_payload;
struct zcbor_string Sig_structure1_body_protected;
struct zcbor_string Sig_structure1_payload;
};

struct Manifest {
uint32_t _Manifest_version;
uint32_t _Manifest_compat;
struct zcbor_string _Manifest_blob_hash;
struct zcbor_string _Manifest_segments;
uint32_t Manifest_version;
uint32_t Manifest_compat;
struct zcbor_string Manifest_blob_hash;
struct zcbor_string Manifest_segments;
};

struct COSE_Sign1_Manifest {
struct zcbor_string _COSE_Sign1_Manifest_payload;
struct Manifest _COSE_Sign1_Manifest_payload_cbor;
struct zcbor_string _COSE_Sign1_Manifest_signature;
struct zcbor_string COSE_Sign1_Manifest_protected;
struct zcbor_string COSE_Sign1_Manifest_payload;
struct Manifest COSE_Sign1_Manifest_payload_cbor;
struct zcbor_string COSE_Sign1_Manifest_signature;
};

#ifdef __cplusplus
}
#endif

#endif /* MODEM_UPDATE_TYPES_H__ */
Loading
Loading