Skip to content

Commit 0aad9cf

Browse files
nvlsianpumbolivar-nordic
authored andcommitted
[nrf fromtree] zephyr/boot_serial_extension: added hooks to custom image list MGMT
Introduced boot_img_install_stat_hook() hook fuinction for fetch the image's slot installation status. The image's slot installation status is custom property. It's detailed definition depends on user implementation. It is only defined that the status will be set to 0 if this hook not provides another value. Inserted available hook for read image header as well. Signed-off-by: Andrzej Puzdrowski <[email protected]> (cherry picked from commit c1ba5fe)
1 parent ff4148f commit 0aad9cf

File tree

2 files changed

+53
-20
lines changed

2 files changed

+53
-20
lines changed

boot/bootutil/include/bootutil/boot_hooks.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,24 @@ int boot_copy_region_post_hook(int img_index, const struct flash_area *area,
137137
int boot_serial_uploaded_hook(int img_index, const struct flash_area *area,
138138
size_t size);
139139

140+
/** Hook for implement the image's slot installation status fetch operation for
141+
* the MGMT custom command.
142+
*
143+
* The image's slot installation status is custom property. It's detailed
144+
* definition depends on user implementation. It is only defined that the status
145+
* will be set to 0 if this hook not provides another value.
146+
*
147+
* @param img_index the index of the image pair
148+
* @param slot slot number
149+
* @param img_install_stat the image installation status to be populated
150+
*
151+
* @retval 0: the installaton status was fetched successfully,
152+
* BOOT_HOOK_REGULAR: follow the normal execution path, status will be
153+
* set to 0
154+
* otherwise an error-code value. Error-code is ignored, but it is up to
155+
* the implementation to reflect this error in img_install_stat.
156+
*/
157+
int boot_img_install_stat_hook(int image_index, int slot,
158+
int *img_install_stat);
159+
140160
#endif /*H_BOOTUTIL_HOOKS*/

boot/zephyr/boot_serial_extensions.c

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "../boot_serial/src/cbor_encode.h"
1717

1818
#include "bootutil/image.h"
19+
#include "bootutil/bootutil_public.h"
20+
#include "bootutil/boot_hooks.h"
1921

2022
MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
2123

@@ -60,33 +62,44 @@ static int custom_img_status(int image_index, uint32_t slot,char *buffer,
6062
struct flash_area const *fap;
6163
struct image_header hdr;
6264
int rc;
63-
int img_install_stat = 0;
65+
int img_install_stat;
6466

65-
area_id = flash_area_id_from_multi_image_slot(image_index, slot);
66-
67-
rc = flash_area_open(area_id, &fap);
68-
if (rc) {
69-
return rc;
67+
rc = BOOT_HOOK_CALL(boot_img_install_stat_hook, BOOT_HOOK_REGULAR,
68+
image_index, slot, &img_install_stat);
69+
if (rc == BOOT_HOOK_REGULAR)
70+
{
71+
img_install_stat = 0;
7072
}
7173

72-
rc = flash_area_read(fap, 0, &hdr, sizeof(hdr));
73-
if (rc) {
74-
goto func_end;
74+
rc = BOOT_HOOK_CALL(boot_read_image_header_hook, BOOT_HOOK_REGULAR,
75+
image_index, slot, &hdr);
76+
if (rc == BOOT_HOOK_REGULAR)
77+
{
78+
area_id = flash_area_id_from_multi_image_slot(image_index, slot);
79+
80+
rc = flash_area_open(area_id, &fap);
81+
if (rc) {
82+
return rc;
83+
}
84+
85+
rc = flash_area_read(fap, 0, &hdr, sizeof(hdr));
86+
87+
flash_area_close(fap);
7588
}
7689

77-
if (hdr.ih_magic == IMAGE_MAGIC) {
78-
snprintf(buffer, len, "ver=%d.%d.%d.%d,install_stat=%d",
79-
hdr.ih_ver.iv_major,
80-
hdr.ih_ver.iv_minor,
81-
hdr.ih_ver.iv_revision,
82-
hdr.ih_ver.iv_build_num,
83-
img_install_stat);
84-
} else {
85-
rc = 1;
90+
if (rc == 0) {
91+
if (hdr.ih_magic == IMAGE_MAGIC) {
92+
snprintf(buffer, len, "ver=%d.%d.%d.%d,install_stat=%d",
93+
hdr.ih_ver.iv_major,
94+
hdr.ih_ver.iv_minor,
95+
hdr.ih_ver.iv_revision,
96+
hdr.ih_ver.iv_build_num,
97+
img_install_stat);
98+
} else {
99+
rc = 1;
100+
}
86101
}
87102

88-
func_end:
89-
flash_area_close(fap);
90103
return rc;
91104
}
92105

0 commit comments

Comments
 (0)