FOTA to external flash

Hi there

I'm using Asset tracker v2 as a base for my application with AWS, however I wanted the FOTA to download to external flash, as the Asset tracker application is large, and leaves little room for any other application code.

I'm able to FOTA, to external SPI flash using MCUBoot, however once the download is complete I get an error

<err> dfu_target_mcuboot: boot_request_upgrade for image-0 error -14

Any help appreciated. 

Here is the debug 

[00:07:17.860,687] <inf> download_client: Downloaded 323584/328496 bytes (98%)
[00:07:18.965,179] <inf> download_client: Downloaded 324608/328496 bytes (98%)
[00:07:20.061,065] <inf> download_client: Downloaded 325632/328496 bytes (99%)
[00:07:21.231,323] <inf> download_client: Downloaded 326656/328496 bytes (99%)
[00:07:22.301,300] <inf> download_client: Downloaded 327680/328496 bytes (99%)
[00:07:23.365,417] <inf> download_client: Downloaded 328496/328496 bytes (100%)
[00:07:23.365,509] <dbg> STREAM_FLASH: stream_flash_erase_page: Erasing page at offset 0x00050000
[00:07:23.494,506] <inf> download_client: Download complete
[00:07:23.497,711] <dbg> STREAM_FLASH: stream_flash_erase_page: Erasing page at offset 0x000e0000
[00:07:23.618,499] <err> dfu_target_mcuboot: boot_request_upgrade for image-0 error -14
[00:07:23.618,530] <err> fota_download: dfu_target_done error: -14
[00:07:23.618,530] <err> aws_fota: FOTA_DOWNLOAD_EVT_ERROR
[00:07:23.618,560] <dbg> aws_fota: update_job_execution: update_job_execution, status: 3, version_number: 1236
[00:07:23.620,544] <err> aws_iot: AWS_FOTA_EVT_ERROR
[00:07:23.620,544] <dbg> aws_iot_integration: aws_iot_event_handler: AWS_IOT_EVT_FOTA_ERROR
[00:07:23.620,574] <dbg> cloud_module: cloud_wrap_event_handler: CLOUD_WRAP_EVT_FOTA_ERROR

The only files I had to add to the asset_tracker application were. 

\child_image\mcuboot\boards\thingy91_nrf9160.overlay

/ {
	chosen {
		nordic,pm-ext-flash = &is25lp032d;
	};

};


&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";

    pinctrl-0 = <&spi3_default>;
	pinctrl-1 = <&spi3_sleep>;
	pinctrl-names = "default", "sleep";

	cs-gpios = < &gpio0 7 GPIO_ACTIVE_LOW >,< &gpio0 7 GPIO_ACTIVE_LOW >;
	is25lp032d: is25lp032d@0 {
		compatible = "jedec,spi-nor";
		label = "IS25LP032D";
		reg = < 0 >;
		spi-max-frequency = < 40000000 >;
		wp-gpios = < &gpio0 8 GPIO_ACTIVE_LOW >;
		hold-gpios = < &gpio0 10 GPIO_ACTIVE_LOW >;
		size = < 0x2000000 >;
		has-dpd;
		t-enter-dpd = < 3000 >;
		t-exit-dpd = < 30000 >;
		jedec-id = [ 9d 60 16  ];

	};
};

&uart0 {
	compatible = "nordic,nrf-uarte";
	status = "okay";
	/delete-property/ cts-pull-up;
	//hw-flow-control;
    pinctrl-0 = <&uart0_default_alt>;
	pinctrl-1 = <&uart0_sleep_alt>;
	pinctrl-names = "default", "sleep";
	

};


&pinctrl {
	uart0_default_alt: uart_default_alt {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 6)>,
				<NRF_PSEL(UART_RX, 0, 5)>,
				<NRF_PSEL(UART_RTS, 0, 16)>,
				<NRF_PSEL(UART_CTS, 0, 15)>;
		};
	};

	uart0_sleep_alt: uart0_sleep_alt {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 6)>,
				<NRF_PSEL(UART_RX, 0, 5)>,
				<NRF_PSEL(UART_RTS, 0, 16)>,
				<NRF_PSEL(UART_CTS, 0, 15)>;
			low-power-enable;
		};
	};



    spi3_default: spi3_default {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 11)>,
                <NRF_PSEL(SPIM_MOSI, 0, 9)>,
                <NRF_PSEL(SPIM_MISO, 0, 28)>;
        };
    };

    spi3_sleep: spi3_sleep {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 11)>,
                <NRF_PSEL(SPIM_MOSI, 0, 9)>,
                <NRF_PSEL(SPIM_MISO, 0, 28)>;
            low-power-enable;
        };
    };
};

\child_image\mcuboot.conf

CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

CONFIG_MULTITHREADING=y

# MCUboot requires a large stack size, otherwise an MPU fault will occur
CONFIG_MAIN_STACK_SIZE=10240


# Enable flash operations
CONFIG_FLASH=y

# This must be increased to accommodate the bigger images.
CONFIG_BOOT_MAX_IMG_SECTORS=256

#MKB Added 
#https://devzone.nordicsemi.com/f/nordic-q-a/87502/mcubootloader-won-t-build-for-custom-board---zephyr-zephyr_pre0-elf-section-text-will-not-fit-in-region-flash
#CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10000
#compiled size is 49584bytes. = 0xC1B0 so C200 is enough. 
CONFIG_PM_PARTITION_SIZE_MCUBOOT=0xc200 

# Size of mcuboot partition
CONFIG_SIZE_OPTIMIZATIONS=y


###############  ALSO #######
#comment out or rename the file 

#C:\ncs\v2.1.0\nrf\boards\arm\thingy91_nrf9160\thingy91_pm_static.yml

#commenting it out will allow the partition manager to use the CONFIG_PM_PARTION_SIZE_MCUBOOT 
#above.

  • Hi

    This issue looks very much like the issue described in this case, and seems to be related to the device JEDEC ID that you have set for your external flash. As my colleague Håkon explains, this can be read out of the datasheet of your used external flash. For the external flash mounted on the nRF91 DK, this is C2 28 17. If you read all zeroes here, your device has issues connecting to your flash. 

    For the nRF9160-DK, you must switch in the pins for communicating with the flash, as explained in this post:

     RE: Full modem update configuration 

    Note that this is for the board controller, i.e. nrf9160dk_nrf52840, so it is important that you set the switch into "NRF52" position before programming the above snippet.

    Best regards,

    Simon

  • Thanks for the reply Simon, 

    I am using a CircuitDojo Feather board, this has different flash on it, and the pins for driving it are different. 

    64/128 Mbit Single Operation Voltage (mouser.com)

    The Flash is working, with the current overlay I'm using above. 

    But there are some good clues in your response that'll I'll follow. 

    How do I turn on the logging in the bootloader in Asset Tracker V2? It would be useful while I'm trying to sort out whats going on. 

    Regards

    Marshall

  • Hi Simon 

    I just read out the JEDEC ID from the Flash, it matches the overlay. 

    [00:00:00.501,708] <inf> opito: JEDEC SPI-NOR SPI flash testing
    [00:00:00.501,708] <inf> opito: ==========================
    [00:00:00.503,021] <inf> opito: Flash read ID succeeded! 9d 60 16
    [00:00:00.503,051] <inf> opito: Test 1: Flash erase
    [00:00:00.553,863] <inf> opito: Flash erase succeeded!
    [00:00:00.553,863] <inf> opito: Test 2: Flash write
    [00:00:00.553,894] <inf> opito: Attempting to write 4 bytes
    [00:00:00.558,868] <inf> opito: Data read matches data written. Good!!

    Regards

    Marshall

  • Hi Marshall

    If you want to enable logging in the MCUBoot you need to add CONFIG_LOG=y and the backend you want to use CONFIG_LOG_BACKEND_UART=y for example. In projects where MCUBoot is the child image you should do it in the mcuboot.conf file located under child images I believe. Like this for example:

    Best regards,

    Simon

  • Thanks, that didn't work though. 

    Is there somewhere that you set the serial port config for MCUBoot as well? 

    This is in mcuboot.conf

    CONFIG_SERIAL=y
    CONFIG_LOG=y
    CONFIG_LOG_BACKEND_UART=y 
    CONFIG_MCUBOOT_LOG_LEVEL_DBG=y
    #CONFIG_LOG_MODE_MINIMAL=y # former CONFIG_MODE_MINIMAL
    ### Ensure Zephyr logging changes don't use more resources
    #was 0
    CONFIG_LOG_DEFAULT_LEVEL=4 
    ### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
    CONFIG_CBPRINTF_NANO=y
    CONFIG_RESET_ON_FATAL_ERROR=n
    CONFIG_THREAD_NAME=y
    #CONFIG_DEBUG_OPTIMIZATIONS=y

    The overlay above is also in the child image folder, and the pins are correct for the UART. 

    Thanks 

    Marshall

Related