Skip to content

Commit 83ccb95

Browse files
committed
[nrf noup] samples: smp_svr: Demonstration of bootloader info on nrf54h20
Example usage of bootloader info for reporting mcuboot version from application. Signed-off-by: Adam Szczygieł <[email protected]>
1 parent 893c333 commit 83ccb95

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/ {
2+
sram@22007FC0 {
3+
compatible = "zephyr,memory-region", "mmio-sram";
4+
reg = <0x22007FC0 0x40>;
5+
zephyr,memory-region = "RetainedMem";
6+
status = "okay";
7+
8+
retainedmem {
9+
compatible = "zephyr,retained-ram";
10+
status = "okay";
11+
#address-cells = <1>;
12+
#size-cells = <1>;
13+
14+
boot_info0: boot_info@0 {
15+
compatible = "zephyr,retention";
16+
status = "okay";
17+
reg = <0x0 0x40>;
18+
};
19+
};
20+
};
21+
22+
chosen {
23+
zephyr,bootloader-info = &boot_info0;
24+
};
25+
};
26+
27+
&cpuapp_ram0 {
28+
reg = <0x22000000 0x7FC0>;
29+
};

samples/subsys/mgmt/mcumgr/smp_svr/prj.conf

+5
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,8 @@ CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y
3939

4040
# Disable debug logging
4141
CONFIG_LOG_MAX_LEVEL=3
42+
43+
CONFIG_RETAINED_MEM=y
44+
CONFIG_RETENTION=y
45+
CONFIG_RETENTION_BOOTLOADER_INFO=y
46+
CONFIG_RETENTION_BOOTLOADER_INFO_TYPE_MCUBOOT=y

samples/subsys/mgmt/mcumgr/smp_svr/src/main.c

+23
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ LOG_MODULE_REGISTER(smp_sample);
2424

2525
#include "common.h"
2626

27+
#include <zephyr/retention/blinfo.h>
28+
#include <bootutil/image.h>
29+
2730
#define STORAGE_PARTITION_LABEL storage_partition
2831
#define STORAGE_PARTITION_ID FIXED_PARTITION_ID(STORAGE_PARTITION_LABEL)
2932

@@ -50,6 +53,24 @@ static struct fs_mount_t littlefs_mnt = {
5053
};
5154
#endif
5255

56+
static void blinfo_bootloader_version(void)
57+
{
58+
struct image_version version = {0x00};
59+
60+
int ret = blinfo_lookup(BLINFO_BOOTLOADER_VERSION,
61+
(char *)&version,
62+
sizeof(struct image_version));
63+
64+
if (ret < 0) {
65+
printf("blinfo_lookup error: %d\n", ret);
66+
} else {
67+
printf("bl iv_major: %d\n", version.iv_major);
68+
printf("bl iv_minor: %d\n", version.iv_minor);
69+
printf("bl iv_revision: %d\n", version.iv_revision);
70+
printf("bl iv_build_num: %d\n", version.iv_build_num);
71+
}
72+
}
73+
5374
int main(void)
5475
{
5576
int rc = STATS_INIT_AND_REG(smp_svr_stats, STATS_SIZE_32,
@@ -85,6 +106,8 @@ int main(void)
85106
*/
86107
LOG_INF("build time: " __DATE__ " " __TIME__);
87108

109+
blinfo_bootloader_version();
110+
88111
/* The system work queue handles all incoming mcumgr requests. Let the
89112
* main thread idle while the mcumgr server runs.
90113
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CONFIG_LOG=y
2+
CONFIG_MCUBOOT_LOG_LEVEL_INF=y
3+
4+
CONFIG_RETAINED_MEM=y
5+
CONFIG_RETENTION=y
6+
CONFIG_BOOT_SHARE_DATA=y
7+
CONFIG_BOOT_SHARE_DATA_BOOTINFO=y
8+
CONFIG_BOOT_SHARE_BACKEND_RETENTION=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/ {
2+
sram@22007FC0 {
3+
compatible = "zephyr,memory-region", "mmio-sram";
4+
reg = <0x22007FC0 0x40>;
5+
zephyr,memory-region = "RetainedMem";
6+
status = "okay";
7+
8+
retainedmem {
9+
compatible = "zephyr,retained-ram";
10+
status = "okay";
11+
#address-cells = <1>;
12+
#size-cells = <1>;
13+
14+
boot_info0: boot_info@0 {
15+
compatible = "zephyr,retention";
16+
status = "okay";
17+
reg = <0x0 0x40>;
18+
};
19+
};
20+
};
21+
22+
chosen {
23+
zephyr,bootloader-info = &boot_info0;
24+
zephyr,code-partition = &boot_partition;
25+
};
26+
};
27+
28+
&cpuapp_ram0 {
29+
reg = <0x22000000 0x7FC0>;
30+
};

0 commit comments

Comments
 (0)