3131#include <zephyr/storage/flash_map.h>
3232#include <zephyr/sys/reboot.h>
3333
34+ #include <bootutil/bootutil_public.h>
35+
3436#include "hawkbit_device.h"
3537#include "hawkbit_firmware.h"
3638#include "hawkbit_priv.h"
@@ -1439,6 +1441,7 @@ static void s_download(void *o)
14391441 int ret = 0 ;
14401442 struct s_object * s = (struct s_object * )o ;
14411443 struct flash_img_check fic = {0 };
1444+ const struct flash_area * flash_area_ptr ;
14421445 char * url_buffer ;
14431446
14441447 ret = hawkbit_parse_deployment (& s -> hb_context , & s -> hb_context .results .dep , & url_buffer );
@@ -1451,6 +1454,11 @@ static void s_download(void *o)
14511454
14521455 flash_img_init (& s -> hb_context .flash_ctx );
14531456
1457+ /* The flash_area pointer has to be copied before the download starts
1458+ * because the flash_area will be set to NULL after the download has finished.
1459+ */
1460+ flash_area_ptr = s -> hb_context .flash_ctx .flash_area ;
1461+
14541462 if (!send_request (& s -> hb_context , HAWKBIT_DOWNLOAD , url_buffer , NULL )) {
14551463 LOG_ERR ("Send request failed (%s)" , "HAWKBIT_DOWNLOAD" );
14561464 smf_set_state (SMF_CTX (s ), & hawkbit_states [S_HAWKBIT_TERMINATE ]);
@@ -1468,15 +1476,15 @@ static void s_download(void *o)
14681476 /* Verify the hash of the stored firmware */
14691477 fic .match = s -> hb_context .dl .file_hash ;
14701478 fic .clen = s -> hb_context .dl .downloaded_size ;
1471- if (flash_img_check (& s -> hb_context .flash_ctx , & fic , FIXED_PARTITION_ID ( SLOT1_LABEL ) )) {
1479+ if (flash_img_check (& s -> hb_context .flash_ctx , & fic , flash_area_ptr -> fa_id )) {
14721480 LOG_ERR ("Failed to validate stored firmware" );
14731481 s -> hb_context .code_status = HAWKBIT_DOWNLOAD_ERROR ;
14741482 smf_set_state (SMF_CTX (s ), & hawkbit_states [S_HAWKBIT_TERMINATE ]);
14751483 return ;
14761484 }
14771485
14781486 /* Request mcuboot to upgrade */
1479- if (boot_request_upgrade ( BOOT_UPGRADE_TEST )) {
1487+ if (boot_set_next ( flash_area_ptr , false, false )) {
14801488 LOG_ERR ("Failed to mark the image in slot 1 as pending" );
14811489 s -> hb_context .code_status = HAWKBIT_DOWNLOAD_ERROR ;
14821490 smf_set_state (SMF_CTX (s ), & hawkbit_states [S_HAWKBIT_TERMINATE ]);
0 commit comments