Skip to content

Commit b6d4788

Browse files
theotherjimmymbolivar-nordic
authored andcommitted
samples: psa-firmware: Display active Secure firmware version
This displays the secure firmware version before the nonsecure firmware version at the beginning of boot. Signed-off-by: Jimmy Brisson <[email protected]>
1 parent 57cefda commit b6d4788

File tree

1 file changed

+33
-19
lines changed
  • samples/tfm_integration/psa_firmware/src

1 file changed

+33
-19
lines changed

samples/tfm_integration/psa_firmware/src/main.c

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,25 @@ const size_t min_block_size = 512;
3131
/** Declare a reference to the application logging interface. */
3232
LOG_MODULE_DECLARE(app, CONFIG_LOG_DEFAULT_LEVEL);
3333

34-
bool fwu_query_ver_active(psa_image_info_t *info)
34+
bool fwu_query_ver_active(psa_image_id_t image_id, psa_image_info_t *info)
3535
{
3636
psa_status_t status;
3737

38+
/* Query the active image. */
39+
status = psa_fwu_query(image_id, info);
40+
41+
/* Get the active image version. State can be one of: */
42+
/* PSA_IMAGE_UNDEFINED */
43+
/* PSA_IMAGE_CANDIDATE */
44+
/* PSA_IMAGE_INSTALLED */
45+
/* PSA_IMAGE_REJECTED */
46+
/* PSA_IMAGE_PENDING_INSTALL */
47+
/* PSA_IMAGE_REBOOT_NEEDED */
48+
return info->state == PSA_IMAGE_INSTALLED && status == PSA_SUCCESS;
49+
}
50+
51+
void fwu_disp_ver_active(void)
52+
{
3853
/* Image type can be one of: */
3954
/* FWU_IMAGE_TYPE_NONSECURE */
4055
/* FWU_IMAGE_TYPE_SECURE */
@@ -54,26 +69,25 @@ bool fwu_query_ver_active(psa_image_info_t *info)
5469
/* If this mode is not enabled, then the application should use the */
5570
/* “FWU_IMAGE_TYPE_NONSECURE” or “FWU_IMAGE_TYPE_SECURE” type. */
5671
psa_image_id_t image_id = FWU_CALCULATE_IMAGE_ID(FWU_IMAGE_ID_SLOT_ACTIVE,
57-
FWU_IMAGE_TYPE_NONSECURE,
72+
FWU_IMAGE_TYPE_SECURE,
5873
0);
74+
psa_image_info_t info = { 0 };
75+
bool status = fwu_query_ver_active(image_id, &info);
5976

60-
/* Query the active image. */
61-
status = psa_fwu_query(image_id, info);
62-
63-
/* Get the active image version. State can be one of: */
64-
/* PSA_IMAGE_UNDEFINED */
65-
/* PSA_IMAGE_CANDIDATE */
66-
/* PSA_IMAGE_INSTALLED */
67-
/* PSA_IMAGE_REJECTED */
68-
/* PSA_IMAGE_PENDING_INSTALL */
69-
/* PSA_IMAGE_REBOOT_NEEDED */
70-
return info->state == PSA_IMAGE_INSTALLED && status == PSA_SUCCESS;
71-
}
77+
if (status) {
78+
printk("Active S image version: %d.%d.%d-%d\n",
79+
info.version.iv_major,
80+
info.version.iv_minor,
81+
info.version.iv_revision,
82+
info.version.iv_build_num);
83+
} else {
84+
printk("\nUnable to query active secure image version!\n");
85+
}
7286

73-
void fwu_disp_ver_active(void)
74-
{
75-
psa_image_info_t info = { 0 };
76-
bool status = fwu_query_ver_active(&info);
87+
image_id = FWU_CALCULATE_IMAGE_ID(FWU_IMAGE_ID_SLOT_ACTIVE,
88+
FWU_IMAGE_TYPE_NONSECURE,
89+
0);
90+
status = fwu_query_ver_active(image_id, &info);
7791

7892
if (status) {
7993
printk("Active NS image version: %d.%d.%d-%d\n",
@@ -82,7 +96,7 @@ void fwu_disp_ver_active(void)
8296
info.version.iv_revision,
8397
info.version.iv_build_num);
8498
} else {
85-
printk("\nUnable to query active image version!\n");
99+
printk("\nUnable to query active nonsecure image version!\n");
86100
}
87101
}
88102

0 commit comments

Comments
 (0)