Skip to content

Commit 55a0fb5

Browse files
committed
[nrf noup] uuid: Add DTS-based configuration
Rework the UUID configuration from Kconfig to DTS-based solution. Ref: NCSDK-36636 Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
1 parent e6b471a commit 55a0fb5

15 files changed

Lines changed: 611 additions & 237 deletions

File tree

boot/bootutil/include/bootutil/mcuboot_uuid.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <stdint.h>
2020
#include "bootutil/fault_injection_hardening.h"
21+
#include <flash_map_backend/flash_map_backend.h>
2122

2223
#ifdef __cplusplus
2324
extern "C" {
@@ -39,22 +40,22 @@ fih_ret boot_uuid_init(void);
3940
/**
4041
* @brief Check if the specified vendor UUID is allowed for a given image.
4142
*
42-
* @param[in] image_id Index of the image (from 0).
43+
* @param[in] fap Pointer to the flash area structure.
4344
* @param[in] uuid_vid The reference to the image's vendor ID value.
4445
*
4546
* @return FIH_SUCCESS on success.
4647
*/
47-
fih_ret boot_uuid_vid_match(uint32_t image_id, const struct image_uuid *uuid_vid);
48+
fih_ret boot_uuid_vid_match(const struct flash_area *fap, const struct image_uuid *uuid_vid);
4849

4950
/**
5051
* @brief Check if the specified image class UUID is allowed for a given image.
5152
*
52-
* @param[in] image_id Index of the image (from 0).
53+
* @param[in] fap Pointer to the flash area structure.
5354
* @param[in] uuid_cid The reference to the image's class ID value.
5455
*
5556
* @return FIH_SUCCESS on success
5657
*/
57-
fih_ret boot_uuid_cid_match(uint32_t image_id, const struct image_uuid *uuid_cid);
58+
fih_ret boot_uuid_cid_match(const struct flash_area *fap, const struct image_uuid *uuid_cid);
5859

5960
#ifdef __cplusplus
6061
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef __MCUBOOT_UUID_GENERATED_H__
8+
#define __MCUBOOT_UUID_GENERATED_H__
9+
10+
/**
11+
* @file mcuboot_uuid_generated.h
12+
*
13+
* @note APIs declared in this file are generated by the gen_mcuboot_config.py script and should
14+
* be aligned with templates.
15+
*/
16+
17+
#include <bootutil/mcuboot_uuid.h>
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
/** The automatically generated UUID map entry structure. */
24+
struct uuid_map_entry {
25+
const struct device *dev;
26+
size_t off;
27+
size_t size;
28+
size_t image_index;
29+
size_t partition_index;
30+
struct image_uuid uuid;
31+
};
32+
33+
/**
34+
* @brief Get the map of vendor UUIDs.
35+
*
36+
* @return The number of entries in the vendor UUID map, or 0 if the map is not available.
37+
*/
38+
size_t boot_uuid_vid_map_get(const struct uuid_map_entry **map);
39+
40+
/**
41+
* @brief Get the map of class UUIDs.
42+
*
43+
* @return The number of entries in the class UUID map, or 0 if the map is not available.
44+
*/
45+
size_t boot_uuid_cid_map_get(const struct uuid_map_entry **map);
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
51+
#endif /* __MCUBOOT_UUID_GENERATED_H__ */

boot/bootutil/src/image_validate.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ bootutil_img_validate(struct boot_loader_state *state,
221221
#if (defined(EXPECTED_KEY_TLV) && defined(MCUBOOT_HW_KEY)) || \
222222
(defined(EXPECTED_SIG_TLV) && defined(MCUBOOT_BUILTIN_KEY)) || \
223223
defined(MCUBOOT_HW_ROLLBACK_PROT) || defined(MCUBOOT_MANIFEST_UPDATES) || \
224-
defined(MCUBOOT_UUID_VID) || defined(MCUBOOT_UUID_CID) || defined(MCUBOOT_DECOMPRESS_IMAGES) ||\
225-
defined(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
224+
defined(MCUBOOT_DECOMPRESS_IMAGES) || defined(CONFIG_NCS_MCUBOOT_LOAD_PERIPHCONF)
226225
int image_index = (state == NULL ? 0 : BOOT_CURR_IMG(state));
227226
#endif
228227
uint32_t off;
@@ -703,9 +702,10 @@ bootutil_img_validate(struct boot_loader_state *state,
703702
goto out;
704703
}
705704

706-
FIH_CALL(boot_uuid_vid_match, fih_rc, image_index, &img_uuid_vid);
705+
FIH_CALL(boot_uuid_vid_match, fih_rc, fap, &img_uuid_vid);
707706
if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) {
708707
FIH_SET(uuid_vid_valid, FIH_FAILURE);
708+
BOOT_LOG_ERR("bootutil_img_validate: image rejected, vendor UUID does not match");
709709
goto out;
710710
}
711711

@@ -732,9 +732,10 @@ bootutil_img_validate(struct boot_loader_state *state,
732732
goto out;
733733
}
734734

735-
FIH_CALL(boot_uuid_cid_match, fih_rc, image_index, &img_uuid_cid);
735+
FIH_CALL(boot_uuid_cid_match, fih_rc, fap, &img_uuid_cid);
736736
if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) {
737737
FIH_SET(uuid_cid_valid, FIH_FAILURE);
738+
BOOT_LOG_ERR("bootutil_img_validate: image rejected, class UUID does not match");
738739
goto out;
739740
}
740741

boot/zephyr/Kconfig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ comment "MCUboot-specific configuration options"
1111

1212
source "$(ZEPHYR_NRF_MODULE_DIR)/modules/mcuboot/boot/zephyr/Kconfig"
1313

14+
DT_COMPAT_NORDIC_MCUBOOT := nordic,mcuboot
15+
1416
# Hidden option to mark a project as MCUboot
1517
config MCUBOOT
1618
default y
@@ -1215,18 +1217,18 @@ endif # MCUBOOT_MANIFEST_UPDATES
12151217

12161218
config MCUBOOT_UUID_VID
12171219
bool "Expect vendor unique identifier in image's TLV"
1220+
default y if $(dt_compat_any_has_prop,$(DT_COMPAT_NORDIC_MCUBOOT),uuid-vid-required)
12181221
help
12191222
Provide a vendor identification scheme to prevent processing images
12201223
generated by a different vendor.
12211224

12221225
config MCUBOOT_UUID_CID
12231226
bool "Expect image class unique identifier in image's TLV"
1227+
default y if $(dt_compat_any_has_prop,$(DT_COMPAT_NORDIC_MCUBOOT),uuid-cid-required)
12241228
help
12251229
Provide an image class identification scheme to prevent processing
12261230
images for a different CPU or device produced by the same vendor.
12271231

1228-
rsource "uuid/Kconfig"
1229-
12301232
config BOOT_WATCHDOG_FEED
12311233
bool "Feed the watchdog while doing swap"
12321234
default y if WATCHDOG

boot/zephyr/uuid/CMakeLists.txt

Lines changed: 26 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,34 @@
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
66

7-
if(CONFIG_NCS_MCUBOOT_UUID_SINGLE_VID)
8-
if(CONFIG_MCUBOOT_UUID_VID OR CONFIG_MCUBOOT_UUID_CID)
9-
zephyr_library_sources(
10-
uuid.c
11-
)
12-
endif()
7+
set(edt_pickle ${CMAKE_BINARY_DIR}/zephyr/edt.pickle)
8+
set(gen_mcuboot_config_path
9+
"${ZEPHYR_MCUBOOT_MODULE_DIR}/scripts/gen_mcuboot_config.py"
10+
)
11+
set(gen_mcuboot_config_args
12+
--edt-pickle "${edt_pickle}"
13+
--output-dir "${CMAKE_CURRENT_BINARY_DIR}"
14+
)
1315

14-
# Generate VID value and raw value definition
15-
if(CONFIG_MCUBOOT_UUID_VID OR CONFIG_MCUBOOT_UUID_CID)
16-
if("${CONFIG_NCS_MCUBOOT_UUID_VID_VALUE}" STREQUAL "" AND CONFIG_MCUBOOT_UUID_VID)
17-
message(WARNING "VID value not set")
18-
return()
19-
endif()
20-
21-
string(REGEX MATCHALL "^([0-9A-F][0-9A-F]|\-)+$" match_parts "${CONFIG_NCS_MCUBOOT_UUID_VID_VALUE}")
22-
if("${match_parts}" STREQUAL "${CONFIG_NCS_MCUBOOT_UUID_VID_VALUE}")
23-
set(UUID_VID ${match_parts})
24-
else()
25-
set(UUID_DNS_NAMESPACE 6ba7b810-9dad-11d1-80b4-00c04fd430c8)
26-
string(
27-
UUID UUID_VID
28-
NAMESPACE ${UUID_DNS_NAMESPACE}
29-
NAME ${CONFIG_NCS_MCUBOOT_UUID_VID_VALUE}
30-
TYPE SHA1 UPPER
31-
)
32-
endif()
33-
34-
if(CONFIG_MCUBOOT_UUID_VID)
35-
# Convert UUID into C array.
36-
string(REGEX REPLACE "([0-9A-F][0-9A-F])\-?" "0x\\1, " UUID_VID_RAW "${UUID_VID}")
37-
zephyr_compile_definitions(NCS_MCUBOOT_UUID_VID_VALUE=${UUID_VID_RAW})
38-
endif()
39-
endif()
16+
if(CONFIG_MCUBOOT_UUID_VID)
17+
list(APPEND gen_mcuboot_config_args --uuid-vid-map)
18+
endif()
4019

41-
# Generate VID value(s) and raw value definition(s)
42-
if(CONFIG_MCUBOOT_UUID_CID)
43-
set(MCUBOOT_IMAGES_COUNT ${CONFIG_UPDATEABLE_IMAGE_NUMBER})
44-
foreach(image_id RANGE ${MCUBOOT_IMAGES_COUNT})
45-
if(CONFIG_NCS_MCUBOOT_UUID_CID_IMAGE_${image_id})
46-
if("${CONFIG_NCS_MCUBOOT_UUID_CID_IMAGE_${image_id}_VALUE}" STREQUAL "")
47-
message(WARNING "CID value not set for image ${image_id}")
48-
return()
49-
endif()
20+
if(CONFIG_MCUBOOT_UUID_CID)
21+
list(APPEND gen_mcuboot_config_args --uuid-cid-map)
22+
endif()
5023

51-
# Check if RAW UUID format is used
52-
string(REGEX MATCHALL "^([0-9A-F][0-9A-F]|\-)+$" match_parts "${CONFIG_NCS_MCUBOOT_UUID_CID_IMAGE_${image_id}_VALUE}")
53-
if("${match_parts}" STREQUAL "${CONFIG_NCS_MCUBOOT_UUID_CID_IMAGE_${image_id}_VALUE}")
54-
set(UUID_CID_IMAGE_${image_id} ${match_parts})
55-
elseif(NOT "${UUID_VID}" STREQUAL "")
56-
# If not - generate UUID based on VID and CID values
57-
string(
58-
UUID UUID_CID_IMAGE_${image_id}
59-
NAMESPACE ${UUID_VID}
60-
NAME ${CONFIG_NCS_MCUBOOT_UUID_CID_IMAGE_${image_id}_VALUE}
61-
TYPE SHA1 UPPER
62-
)
63-
else()
64-
message(WARNING "VID value not set, cannot generate CID for image ${image_id}")
65-
return()
66-
endif()
24+
if(CONFIG_MCUBOOT_UUID_VID OR CONFIG_MCUBOOT_UUID_CID)
25+
execute_process(
26+
COMMAND ${PYTHON_EXECUTABLE} ${gen_mcuboot_config_path} ${gen_mcuboot_config_args}
27+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
28+
COMMAND_ERROR_IS_FATAL ANY
29+
)
30+
include(${CMAKE_CURRENT_BINARY_DIR}/uuid.cmake)
31+
target_link_libraries(uuid PUBLIC zephyr_interface)
6732

68-
# Convert UUID into C array.
69-
string(REGEX REPLACE "([0-9A-F][0-9A-F])\-?" "0x\\1, " UUID_CID_IMAGE_${image_id}_RAW "${UUID_CID_IMAGE_${image_id}}")
70-
zephyr_compile_definitions(NCS_MCUBOOT_UUID_CID_IMAGE_${image_id}_VALUE=${UUID_CID_IMAGE_${image_id}_RAW})
71-
endif()
72-
endforeach()
73-
endif()
33+
zephyr_library_sources(
34+
uuid.c
35+
)
36+
zephyr_library_link_libraries(uuid)
7437
endif()

boot/zephyr/uuid/Kconfig

Lines changed: 0 additions & 55 deletions
This file was deleted.

boot/zephyr/uuid/Kconfig.uuid.template

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)