Skip to content

Commit 023b398

Browse files
SyverHaraldsengithub-actions[bot]
authored andcommitted
app: Fix full modem update completion flow
Move full modem FOTA setup into a shared helper used by both start and finish paths. Reconfigure full modem update storage and load firmware using the resolved flash device and offset in the completion path. Also set pm-ext-flash in board overlay for external partition support. Signed-off-by: Syver Haraldsen <syver.haraldsen@nordicsemi.no> (cherry picked from commit 448cf99)
1 parent 25866d4 commit 023b398

2 files changed

Lines changed: 53 additions & 26 deletions

File tree

app/boards/nrf9151dk_nrf9151_ns.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/ {
88
chosen {
99
ncs,sm-uart = &dtr_uart0;
10+
nordic,pm-ext-flash = &gd25wb256;
1011
};
1112
};
1213

app/src/sm_at_fota.c

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,53 @@ static char hostname[URI_HOST_MAX];
6464
static uint8_t fmfu_buf[FMFU_BUF_SIZE];
6565

6666
/* External flash device for full modem firmware storage */
67+
#if !defined(CONFIG_DFU_TARGET_FULL_MODEM_USE_EXT_PARTITION)
6768
#define FLASH_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(jedec_spi_nor)
6869
static const struct device *flash_dev = DEVICE_DT_GET(FLASH_NODE);
70+
#endif
6971

7072
/* dfu_target specific configurations */
7173
static struct dfu_target_fmfu_fdev fdev;
7274
static struct dfu_target_full_modem_params full_modem_fota_params;
75+
76+
/* Setup full modem FOTA configuration */
77+
static int setup_full_modem_fota_config(void)
78+
{
79+
int err;
80+
81+
full_modem_fota_params.buf = fmfu_buf;
82+
full_modem_fota_params.len = sizeof(fmfu_buf);
83+
full_modem_fota_params.dev = &fdev;
84+
85+
#if defined(CONFIG_DFU_TARGET_FULL_MODEM_USE_EXT_PARTITION)
86+
fdev.dev = NULL;
87+
fdev.offset = 0;
88+
fdev.size = 0;
89+
#else
90+
fdev.dev = flash_dev;
91+
fdev.offset = 0;
92+
fdev.size = DT_PROP(FLASH_NODE, size) / 8;
93+
94+
if (!device_is_ready(flash_dev)) {
95+
LOG_ERR("Flash device %s not ready", flash_dev->name);
96+
return -ENXIO;
97+
}
98+
#endif
99+
100+
err = dfu_target_full_modem_cfg(&full_modem_fota_params);
101+
if (err != 0 && err != -EALREADY) {
102+
LOG_ERR("dfu_target_full_modem_cfg failed: %d", err);
103+
return err;
104+
}
105+
106+
err = dfu_target_full_modem_fdev_get(&fdev);
107+
if (err != 0) {
108+
LOG_ERR("dfu_target_full_modem_fdev_get failed: %d", err);
109+
return err;
110+
}
111+
112+
return 0;
113+
}
73114
#endif
74115

75116
static int do_fota_mfw_read(void)
@@ -334,24 +375,11 @@ static int handle_at_fota(enum at_parser_cmd_type cmd_type, struct at_parser *pa
334375
type = DFU_TARGET_IMAGE_TYPE_MCUBOOT;
335376
}
336377
#if defined(CONFIG_SM_FULL_FOTA)
337-
else if (op == SM_FOTA_START_FULL_FOTA) {
338-
fdev.dev = flash_dev;
339-
fdev.size = DT_PROP(FLASH_NODE, size) / 8;
340-
full_modem_fota_params.buf = fmfu_buf;
341-
full_modem_fota_params.len = sizeof(fmfu_buf);
342-
full_modem_fota_params.dev = &fdev;
343-
344-
if (!device_is_ready(flash_dev)) {
345-
LOG_ERR("Flash device %s not ready", flash_dev->name);
346-
return -ENXIO;
347-
}
348-
349-
err = dfu_target_full_modem_cfg(&full_modem_fota_params);
350-
if (err != 0 && err != -EALREADY) {
351-
LOG_ERR("dfu_target_full_modem_cfg failed: %d", err);
378+
else if (op == SM_FOTA_START_FULL_FOTA) {
379+
err = setup_full_modem_fota_config();
380+
if (err != 0) {
352381
return err;
353382
}
354-
355383
type = DFU_TARGET_IMAGE_TYPE_FULL_MODEM;
356384
}
357385
#endif
@@ -516,8 +544,13 @@ void sm_finish_modem_full_fota(void)
516544
handle_full_fota_activation_fail(err);
517545
}
518546

519-
/* Loading data from external flash to modem's flash. */
520-
err = fmfu_fdev_load(fmfu_buf, sizeof(fmfu_buf), flash_dev, 0);
547+
/* Re-establish dfu_target configuration after reboot */
548+
err = setup_full_modem_fota_config();
549+
if (err != 0) {
550+
handle_full_fota_activation_fail(err);
551+
}
552+
553+
err = fmfu_fdev_load(fmfu_buf, sizeof(fmfu_buf), fdev.dev, fdev.offset);
521554
if (err != 0) {
522555
LOG_ERR("fmfu_fdev_load failed: %d", err);
523556
handle_full_fota_activation_fail(err);
@@ -529,16 +562,9 @@ void sm_finish_modem_full_fota(void)
529562
handle_full_fota_activation_fail(err);
530563
}
531564

532-
/* Reset dfu_target to a pristine state, otherwise it has been observed to
533-
* fail when attempting a second full MFW update without application reset.
534-
*/
535-
err = fota_download_util_image_reset(DFU_TARGET_IMAGE_TYPE_FULL_MODEM);
536-
if (err) {
537-
LOG_ERR("fota_download_util_image_reset() failed: %d\n", err);
538-
}
539-
540565
sm_fota_status = FOTA_STATUS_OK;
541566
sm_fota_info = 0;
567+
542568
LOG_INF("Full modem firmware update complete.");
543569
}
544570

0 commit comments

Comments
 (0)