This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF9160 DK full_modem_update FOTA failing with E: Unable to decode wrapper and Error: fmfu_fdev_load failed: -22

Hello,

I am trying to perform full modem FOTA update on my nRF9160 DK board using sample code without using buttons press functionality as we want to integrate the same code to our own software.

I have performed below configurations before flashing the nRF9160. 

1. Set SW10 to nRF52

2. Created device tree overlay file in zephyr\samples\hello_world\set_9160_ext_flash.overlay with the following contents:


&external_flash_pins_routing {
status = "okay";
};


3. Ran below commands on bash terminal

    west build -b [email protected] -- -DDTC_OVERLAY_FILE=set_9160_ext_flash.overlay

    west flash

4. Set SW10 to nRF91

5. Flashed below code to nRF9160 DK : 

/*
 * Copyright (c) 2021 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#include <zephyr.h>
#include <modem/at_cmd.h>
#include <modem/nrf_modem_lib.h>
#include <dfu/dfu_target_full_modem.h>
#include <net/fota_download.h>
#include <nrf_modem_full_dfu.h>
#include <modem/modem_info.h>
#include <dfu/fmfu_fdev.h>
#include <drivers/gpio.h>
#include <modem/lte_lc.h>
#include <stdio.h>
#include <string.h>
#include <update.h>

/* We assume that modem version strings (not UUID) will not be more than this */
#define MAX_MODEM_VERSION_LEN 256
#define EXT_FLASH_DEVICE DT_LABEL(DT_INST(0, jedec_spi_nor))
//#define SW1_PIN (DT_GPIO_PIN(DT_ALIAS(sw1), gpios))
//#define SW1_FLAGS (DT_GPIO_FLAGS(DT_ALIAS(sw1), gpios))

static struct k_work fmfu_work;
//static const struct device *gpiob;
//static struct gpio_callback gpio_cb;
static const struct device *flash_dev;
static char modem_version[MAX_MODEM_VERSION_LEN];

/* Buffer used as temporary storage when downloading the modem firmware, and
 * when loading the modem firmware from external flash to the modem.
 */
#define FMFU_BUF_SIZE (0x1000)
static uint8_t fmfu_buf[FMFU_BUF_SIZE];

/*static void fmfu_button_irq_disable(void)
{
	gpio_pin_interrupt_configure(gpiob, SW1_PIN, GPIO_INT_DISABLE);
}

static void fmfu_button_irq_enable(void)
{
	gpio_pin_interrupt_configure(gpiob, SW1_PIN, GPIO_INT_EDGE_TO_ACTIVE);
}

void fmfu_button_pressed(const struct device *gpiob, struct gpio_callback *cb,
			 uint32_t pins)
{
	k_work_submit(&fmfu_work);
	fmfu_button_irq_disable();
}*/

static void apply_fmfu_from_ext_flash(bool valid_init)
{
	int err;

	printk("Applying full modem firmware update from external flash\n");

	if (valid_init) {
		err = nrf_modem_lib_shutdown();
		if (err != 0) {
			printk("nrf_modem_lib_shutdown() failed: %d\n", err);
			return;
		}
	}

	err = nrf_modem_lib_init(FULL_DFU_MODE);
	if (err != 0) {
		printk("nrf_modem_lib_init(FULL_DFU_MODE) failed: %d\n", err);
		return;
	}

	err = fmfu_fdev_load(fmfu_buf, sizeof(fmfu_buf), flash_dev, 0);
	if (err != 0) {
		printk("fmfu_fdev_load failed: %d\n", err);
		return;
	}

	err = nrf_modem_lib_shutdown();
	if (err != 0) {
		printk("nrf_modem_lib_shutdown() failed: %d\n", err);
		return;
	}

	err = nrf_modem_lib_init(NORMAL_MODE);
	if (err != 0) {
		printk("nrf_modem_lib_init() failed: %d\n", err);
		return;
	}

	printk("Modem firmware update completed\n");
}

static void fmfu_work_cb(struct k_work *work)
{
	ARG_UNUSED(work);

	apply_fmfu_from_ext_flash(true);

	modem_info_string_get(MODEM_INFO_FW_VERSION, modem_version,
			      MODEM_INFO_MAX_RESPONSE_SIZE);
	printk("Current modem firmware version: %s\n", modem_version);
}

/*static int button_init(void)
{
	int err;

	gpiob = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(sw1), gpios));
	if (gpiob == 0) {
		printk("Nordic nRF GPIO driver was not found!\n");
		return 1;
	}
	err = gpio_pin_configure(gpiob, SW1_PIN, GPIO_INPUT | SW1_FLAGS);
	if (err == 0) {
		gpio_init_callback(&gpio_cb, fmfu_button_pressed, BIT(SW1_PIN));
		err = gpio_add_callback(gpiob, &gpio_cb);
	}
	if (err == 0) {
		fmfu_button_irq_enable();
	}
	if (err != 0) {
		printk("Unable to configure SW1 GPIO pin!\n");
		return 1;
	}
	return 0;
}*/

static bool current_version_is_0(void)
{
	return strncmp(modem_version, CONFIG_DOWNLOAD_MODEM_0_VERSION,
		       strlen(CONFIG_DOWNLOAD_MODEM_0_VERSION)) == 0;
}

static const char *get_file(void)
{
	const char *file = CONFIG_DOWNLOAD_MODEM_0_FILE;

	if (current_version_is_0()) {
		file = CONFIG_DOWNLOAD_MODEM_1_FILE;
	}

	return file;
}

void fota_dl_handler(const struct fota_download_evt *evt)
{
	switch (evt->id) {
	case FOTA_DOWNLOAD_EVT_ERROR:
		printk("Received error from fota_download\n");
		/* Fallthrough */
	case FOTA_DOWNLOAD_EVT_FINISHED:
        printk("Modem fota_download complete...\n");
        k_work_submit(&fmfu_work);
		//apply_fmfu_from_ext_flash(true);
		break;

	default:
		break;
	}
}

void update_start(void)
{
	int err;

	/* Functions for getting the host and file */
	err = fota_download_start(CONFIG_DOWNLOAD_HOST, get_file(), SEC_TAG,
				  NULL, 0);
	if (err != 0) {
		//update_sample_done();
		printk("fota_download_start() failed, err %d\n", err);
	}
}

/*static int num_leds(void)
{
	return current_version_is_0() ? 1 : 2;
}*/

void main(void)
{
	int err;

	printk("HTTP full modem update sample started\n");

	flash_dev = device_get_binding(EXT_FLASH_DEVICE);
	if (flash_dev == NULL) {
		printk("Failed to get flash device: %s\n", EXT_FLASH_DEVICE);
		return;
	}

	err = nrf_modem_lib_init(NORMAL_MODE);
	if (err) {
		printk("Failed to initialize modem lib, err: %d\n", err);
		printk("This could indicate that an earlier update failed\n");
		printk("Trying to apply modem update from ext flash\n");
		apply_fmfu_from_ext_flash(false);
	}

	k_work_init(&fmfu_work, fmfu_work_cb);

	/*err = button_init();
	if (err != 0) {
		printk("button_init() failed: %d\n", err);
		return;
	}*/

	err = fota_download_init(fota_dl_handler);
	if (err != 0) {
		printk("fota_download_init() failed, err %d\n", err);
		return;
	}

	const struct dfu_target_full_modem_params params = {
		.buf = fmfu_buf,
		.len = sizeof(fmfu_buf),
		.dev = &(struct dfu_target_fmfu_fdev){ .dev = flash_dev,
						       .offset = 0,
						       .size = 0 }
	};

	err = dfu_target_full_modem_cfg(&params);
	if (err != 0) {
		printk("dfu_target_full_modem_cfg failed: %d\n", err);
		return;
	}

	err = at_cmd_init();
	if (err != 0) {
		printk("at_cmd_init failed: %d\n", err);
		return;
	}

	err = modem_info_init();
	if (err != 0) {
		printk("modem_info_init failed: %d\n", err);
		return;
	}

	modem_info_string_get(MODEM_INFO_FW_VERSION, modem_version,
			      MODEM_INFO_MAX_RESPONSE_SIZE);
	printk("Current modem firmware version: %s\n", modem_version);

	/*err = update_sample_init(&(struct update_sample_init_params){
					.update_start = update_start,
					.num_leds = num_leds()
				});
	if (err != 0) {
		printk("update_sample_init() failed, err %d\n", err);
		return;
	}*/
    
    modem_configure();
    k_sleep(K_MSEC(5000));
    
    update_start();
    
	//printk("Press Button 1 to download and apply full modem firmware update\n");
	//printk("Press Button 2 to apply modem firmware update (no download)\n");
}

and resulted in below console Output Logs after flashing the application. 

*** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
Flash regions           Domain          Permissions
00 01 0x00000 0x10000   Secure          rwxl
02 31 0x10000 0x100000  Non-Secure      rwxl

Non-secure callable region 0 placed in flash region 1 with size 32.

SRAM region             Domain          Permissions
00 07 0x00000 0x10000   Secure          rwxl
08 31 0x10000 0x40000   Non-Secure      rwxl

Peripheral              Domain          Status
00 NRF_P0               Non-Secure      OK
01 NRF_CLOCK            Non-Secure      OK
02 NRF_RTC0             Non-Secure      OK
03 NRF_RTC1             Non-Secure      OK
04 NRF_NVMC             Non-Secure      OK
05 NRF_UARTE1           Non-Secure      OK
06 NRF_UARTE2           Secure          SKIP
07 NRF_TWIM2            Non-Secure      OK
08 NRF_SPIM3            Non-Secure      OK
09 NRF_TIMER0           Non-Secure      OK
10 NRF_TIMER1           Non-Secure      OK
11 NRF_TIMER2           Non-Secure      OK
12 NRF_SAADC            Non-Secure      OK
13 NRF_PWM0             Non-Secure      OK
14 NRF_PWM1             Non-Secure      OK
15 NRF_PWM2             Non-Secure      OK
16 NRF_PWM3             Non-Secure      OK
17 NRF_WDT              Non-Secure      OK
18 NRF_IPC              Non-Secure      OK
19 NRF_VMC              Non-Secure      OK
20 NRF_FPU              Non-Secure      OK
21 NRF_EGU1             Non-Secure      OK
22 NRF_EGU2             Non-Secure      OK
23 NRF_DPPIC            Non-Secure      OK
24 NRF_REGULATORS       Non-Secure      OK
25 NRF_PDM              Non-Secure      OK
26 NRF_I2S              Non-Secure      OK
27 NRF_GPIOTE1          Non-Secure      OK

SPM: NS image at 0x10000
SPM: NS MSP at 0x2001c098
SPM: NS reset vector at 0x13b95
SPM: prepare to jump to Non-Secure image.
*** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
HTTP full modem update sample started
Current modem firmware version: mfw_nrf9160_1.2.3
LTE Link Connecting ...
LTE Link Connected!
I: Configuring socket timeout (30 s)
I: Connecting to hermes-device-firmware.s3.amazonaws.com
I: Downloading: fmfu_1.2.7.bin [0]
I: Downloaded 2048/197982 bytes (1%)
I: Modem DFU Socket created
I: Modem firmware version: 0191538f-d3a5-4fe9-8f54-ba7cad9460c0
I: Deleting firmware image, this can take several minutes
I: Modem FW delete complete
I: Downloaded 4096/197982 bytes (2%)
I: Downloaded 6144/197982 bytes (3%)
I: Downloaded 8192/197982 bytes (4%)
I: Downloaded 10240/197982 bytes (5%)
I: Downloaded 12288/197982 bytes (6%)
I: Downloaded 14336/197982 bytes (7%)
I: Downloaded 16384/197982 bytes (8%)
I: Downloaded 18432/197982 bytes (9%)
I: Downloaded 20480/197982 bytes (10%)
I: Downloaded 22528/197982 bytes (11%)
I: Downloaded 24576/197982 bytes (12%)
I: Downloaded 26624/197982 bytes (13%)
I: Downloaded 28672/197982 bytes (14%)
I: Downloaded 30720/197982 bytes (15%)
I: Downloaded 32768/197982 bytes (16%)
I: Downloaded 34816/197982 bytes (17%)
I: Downloaded 36864/197982 bytes (18%)
I: Downloaded 38912/197982 bytes (19%)
I: Downloaded 40960/197982 bytes (20%)
I: Downloaded 43008/197982 bytes (21%)
I: Downloaded 45056/197982 bytes (22%)
I: Downloaded 47104/197982 bytes (23%)
I: Downloaded 49152/197982 bytes (24%)
I: Downloaded 51200/197982 bytes (25%)
I: Downloaded 53248/197982 bytes (26%)
I: Downloaded 55296/197982 bytes (27%)
I: Downloaded 57344/197982 bytes (28%)
I: Downloaded 59392/197982 bytes (29%)
I: Downloaded 61440/197982 bytes (31%)
I: Downloaded 63488/197982 bytes (32%)
I: Downloaded 65536/197982 bytes (33%)
I: Downloaded 67584/197982 bytes (34%)
I: Downloaded 69632/197982 bytes (35%)
I: Downloaded 71680/197982 bytes (36%)
I: Downloaded 73728/197982 bytes (37%)
I: Downloaded 75776/197982 bytes (38%)
I: Downloaded 77824/197982 bytes (39%)
I: Downloaded 79872/197982 bytes (40%)
I: Downloaded 81920/197982 bytes (41%)
I: Downloaded 83968/197982 bytes (42%)
I: Downloaded 86016/197982 bytes (43%)
I: Downloaded 88064/197982 bytes (44%)
I: Downloaded 90112/197982 bytes (45%)
I: Downloaded 92160/197982 bytes (46%)
I: Downloaded 94208/197982 bytes (47%)
I: Downloaded 96256/197982 bytes (48%)
I: Downloaded 98304/197982 bytes (49%)
I: Downloaded 100352/197982 bytes (50%)
I: Downloaded 102400/197982 bytes (51%)
I: Downloaded 104448/197982 bytes (52%)
I: Downloaded 106496/197982 bytes (53%)
I: Downloaded 108544/197982 bytes (54%)
I: Downloaded 110592/197982 bytes (55%)
I: Downloaded 112640/197982 bytes (56%)
I: Downloaded 114688/197982 bytes (57%)
I: Downloaded 116736/197982 bytes (58%)
I: Downloaded 118784/197982 bytes (59%)
I: Downloaded 120832/197982 bytes (61%)
I: Downloaded 122880/197982 bytes (62%)
I: Downloaded 124928/197982 bytes (63%)
I: Downloaded 126976/197982 bytes (64%)
I: Downloaded 129024/197982 bytes (65%)
I: Downloaded 131072/197982 bytes (66%)
I: Downloaded 133120/197982 bytes (67%)
I: Downloaded 135168/197982 bytes (68%)
I: Downloaded 137216/197982 bytes (69%)
I: Downloaded 139264/197982 bytes (70%)
I: Downloaded 141312/197982 bytes (71%)
I: Downloaded 143360/197982 bytes (72%)
I: Downloaded 145408/197982 bytes (73%)
I: Downloaded 147456/197982 bytes (74%)
I: Downloaded 149504/197982 bytes (75%)
I: Downloaded 151552/197982 bytes (76%)
I: Downloaded 153600/197982 bytes (77%)
I: Downloaded 155648/197982 bytes (78%)
I: Downloaded 157696/197982 bytes (79%)
I: Downloaded 159744/197982 bytes (80%)
I: Downloaded 161792/197982 bytes (81%)
I: Downloaded 163840/197982 bytes (82%)
I: Downloaded 165888/197982 bytes (83%)
I: Downloaded 167936/197982 bytes (84%)
I: Downloaded 169984/197982 bytes (85%)
I: Downloaded 172032/197982 bytes (86%)
I: Downloaded 174080/197982 bytes (87%)
I: Downloaded 176128/197982 bytes (88%)
I: Downloaded 178176/197982 bytes (89%)
I: Downloaded 180224/197982 bytes (91%)
I: Downloaded 182272/197982 bytes (92%)
I: Downloaded 184320/197982 bytes (93%)
I: Downloaded 186368/197982 bytes (94%)
I: Downloaded 188416/197982 bytes (95%)
I: Downloaded 190464/197982 bytes (96%)
I: Downloaded 192512/197982 bytes (97%)
I: Downloaded 194560/197982 bytes (98%)
I: Downloaded 196608/197982 bytes (99%)
I: Downloaded 197982/197982 bytes (100%)
I: Download complete
I: Scheduling modem firmware upgrade at next boot
Modem fota_download complete...
Applying full modem firmware update from external flash
E: Unable to decode wrapper
fmfu_fdev_load failed: -22
Current modem firmware version: mfw_nrf9160_1.2.3

Please help me to figure it out asap. Its blocking our development activity. 

Note: 

NCS version : 1.6.0

Modem Firmware version: 1.2.3

Device Revision : NRF9160_xxAA_REV2

Board Version : PCA10090

Thank You !

Parents
  • Hello, 

    fmfu_fdev_load failed: -22

    #define EINVAL 22       /**< Invalid argument */
    This is returned by the function fmfu_fdev_load()

    What file format does the modem file have that you are trying to download? 

    Unable to decode wrapper

    This is found in the above function which is due to the following error:

    if (!cbor_decode_Wrapper(meta_buf, MAX_META_LEN, &wrapper,
    				 &wrapper_len)) {
    		LOG_ERR("Unable to decode wrapper");
    		return -EINVAL;
    	}

    Make sure to use the file firmware.update.image.cbor from the modem fw package.

    Let me know how that works for you:

    Kind regards,
    Øyvind

  • Hello Øyvind,

    Thanks for the quick response, but there is no .cbor file present in mfw_nrf9160_1.2.7 zip file. Please let me know how to get the .cbor file for mfw_nrf9160_1.2.7.

    File used for modem update: mfw_nrf9160_update_from_1.2.3_to_1.2.7.bin

    Because first I want to upgrade from modem Firmware version v1.2.3 to v1.2.7 for test purpose. 

    Thank You !

    Regards,

    Chetan

  • Hi Chetan, thanks for the update. As you are doing an update from 1.2.3 to 1.2.7 you need to use nrf\samples\nrf9160\http_update\modem_delta_update

    Chetan Kale said:
    File used for modem update: mfw_nrf9160_update_from_1.2.3_to_1.2.7.bin

    Full modem updates are done when going from 1.2.x to 1.3.0..

    Let me know how that works for you.

    Kind regards,
    Øyvind

Reply
  • Hi Chetan, thanks for the update. As you are doing an update from 1.2.3 to 1.2.7 you need to use nrf\samples\nrf9160\http_update\modem_delta_update

    Chetan Kale said:
    File used for modem update: mfw_nrf9160_update_from_1.2.3_to_1.2.7.bin

    Full modem updates are done when going from 1.2.x to 1.3.0..

    Let me know how that works for you.

    Kind regards,
    Øyvind

Children
Related