Skip to content

Commit

Permalink
mgmt: hawkbit: use area id from flash_ctx
Browse files Browse the repository at this point in the history
don't assume, that the slot to upload is the second.

Signed-off-by: Fin Maaß <[email protected]>
  • Loading branch information
maass-hamburg committed Nov 27, 2024
1 parent b77a8a3 commit 86e05e1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions subsys/mgmt/hawkbit/hawkbit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ enum hawkbit_response hawkbit_probe(void)
{
int ret;
int32_t file_size = 0;
uint8_t area_id;
struct flash_img_check fic;
char device_id[DEVICE_ID_HEX_MAX_SIZE] = { 0 },
cancel_base[CANCEL_BASE_SIZE] = { 0 },
Expand Down Expand Up @@ -1428,6 +1429,11 @@ enum hawkbit_response hawkbit_probe(void)

flash_img_init(&hb_context.flash_ctx);

/* The area_id has to be copyed before the download starts
* because the flash_area will be set to NULL after the download has finished.
*/
area_id = hb_context.flash_ctx.flash_area->fa_id;

if (!send_request(HTTP_GET, HAWKBIT_DOWNLOAD, HAWKBIT_STATUS_FINISHED_NONE,
HAWKBIT_STATUS_EXEC_NONE)) {
LOG_ERR("Send request failed (%s)", "HAWKBIT_DOWNLOAD");
Expand All @@ -1449,14 +1455,14 @@ enum hawkbit_response hawkbit_probe(void)
/* Verify the hash of the stored firmware */
fic.match = hb_context.dl.file_hash;
fic.clen = hb_context.dl.downloaded_size;
if (flash_img_check(&hb_context.flash_ctx, &fic, FIXED_PARTITION_ID(SLOT1_LABEL))) {
if (flash_img_check(&hb_context.flash_ctx, &fic, area_id)) {
LOG_ERR("Failed to validate stored firmware");
hb_context.code_status = HAWKBIT_DOWNLOAD_ERROR;
goto cleanup;
}

/* Request mcuboot to upgrade */
if (boot_request_upgrade(BOOT_UPGRADE_TEST)) {
if (boot_request_upgrade_by_id(area_id, BOOT_UPGRADE_TEST)) {
LOG_ERR("Failed to mark the image in slot 1 as pending");
hb_context.code_status = HAWKBIT_DOWNLOAD_ERROR;
goto cleanup;
Expand Down

0 comments on commit 86e05e1

Please sign in to comment.