Skip to content

Commit 9943fc1

Browse files
committed
ab_split: Log bootloader version and counter value
Extend the app with a logic that reads the current security counter and bootloader version values from the bootloader info. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 91dfbb1 commit 9943fc1

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

samples/dfu/ab_split/prj.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,7 @@ CONFIG_CLOCK_CONTROL_NRF_SHELL=n
100100
CONFIG_DEVICE_SHELL=n
101101
CONFIG_DEVMEM_SHELL=n
102102
CONFIG_FLASH_SHELL=n
103+
104+
# Read bootloader version and security counters values from the retained RAM
105+
CONFIG_RETENTION_BOOTLOADER_INFO=y
106+
CONFIG_RETENTION_BOOTLOADER_INFO_TYPE_MCUBOOT=y

samples/dfu/ab_split/src/main.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,57 @@
1010
#include <common.h>
1111
#include "ab_utils.h"
1212

13+
#ifdef CONFIG_RETENTION_BOOTLOADER_INFO
14+
#include <zephyr/retention/blinfo.h>
15+
#include <bootutil/image.h>
16+
#endif
17+
1318
#define LOG_LEVEL LOG_LEVEL_DBG
1419
#include <zephyr/logging/log.h>
1520
LOG_MODULE_REGISTER(ab_sample);
1621

22+
#ifdef CONFIG_RETENTION_BOOTLOADER_INFO
23+
static void blinfo_bootloader_version(void)
24+
{
25+
struct image_version version = {0x00};
26+
27+
int ret = blinfo_lookup(BLINFO_BOOTLOADER_VERSION, (char *)&version,
28+
sizeof(struct image_version));
29+
30+
if (ret < 0) {
31+
LOG_INF("blinfo_lookup error: %d", ret);
32+
} else {
33+
LOG_INF("Bootloader version: %d.%d.%d+%d", version.iv_major,
34+
version.iv_minor, version.iv_revision, version.iv_build_num);
35+
}
36+
}
37+
38+
#ifdef CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION
39+
static void blinfo_security_counter(void)
40+
{
41+
uint32_t counter = 0;
42+
43+
int ret = blinfo_lookup(BLINFO_SECURITY_COUNTER_IMAGE_0, (char *)&counter,
44+
sizeof(counter));
45+
46+
if (ret < 0) {
47+
LOG_INF("blinfo_lookup error: %d", ret);
48+
} else {
49+
LOG_INF("Security counter: %d", counter);
50+
}
51+
}
52+
#endif /* CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION */
53+
#endif /* CONFIG_RETENTION_BOOTLOADER_INFO */
54+
1755
int main(void)
1856
{
57+
#ifdef CONFIG_RETENTION_BOOTLOADER_INFO
58+
blinfo_bootloader_version();
59+
#ifdef CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION
60+
blinfo_security_counter();
61+
#endif /* CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION */
62+
#endif
63+
1964
#ifdef CONFIG_MCUMGR_TRANSPORT_BT
2065
start_smp_bluetooth_adverts();
2166
#endif

samples/dfu/ab_split/sysbuild/mcuboot/prj.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ CONFIG_PICOLIBC=y
3030
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=0
3131

3232
CONFIG_NCS_APPLICATION_BOOT_BANNER_STRING="MCUboot"
33+
34+
# Expose bootloader version and security counter through retention
35+
CONFIG_BOOT_SHARE_DATA=y
36+
CONFIG_BOOT_SHARE_DATA_BOOTINFO=y
37+
CONFIG_BOOT_SHARE_BACKEND_RETENTION=y

samples/dfu/ab_split/sysbuild/nrf54h20dk_nrf54h20_memory_map.dtsi

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/ {
88
chosen {
99
nrf,bootloader-request = &boot_request;
10+
zephyr,bootloader-info = &boot_info0;
1011
};
1112
};
1213

@@ -15,7 +16,7 @@
1516
cpuapp_retained_mem: memory@e1ad000 {
1617
compatible = "zephyr,memory-region";
1718
reg = <0xe1ad000 DT_SIZE_K(4)>;
18-
zephyr,memory-region = "RetainedMem";
19+
zephyr,memory-region = "RetainedNvm";
1920
status = "okay";
2021

2122
retainedmem {
@@ -34,4 +35,28 @@
3435
};
3536
};
3637
};
38+
39+
sram@22007FC0 {
40+
compatible = "zephyr,memory-region", "mmio-sram";
41+
reg = <0x22007FC0 0x40>;
42+
zephyr,memory-region = "RetainedMem";
43+
status = "okay";
44+
45+
retainedmem {
46+
compatible = "zephyr,retained-ram";
47+
status = "okay";
48+
#address-cells = <1>;
49+
#size-cells = <1>;
50+
51+
boot_info0: boot_info@0 {
52+
compatible = "zephyr,retention";
53+
status = "okay";
54+
reg = <0x0 0x40>;
55+
};
56+
};
57+
};
58+
};
59+
60+
&cpuapp_ram0 {
61+
reg = <0x22000000 0x7FC0>;
3762
};

0 commit comments

Comments
 (0)