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

changes in Bootloader- saving image in external flash and transferring in internal via Bootloader

Hi , I am using ZEPHYR rtos , and using the internal bootloader and its working fine and there are two images but now my code size has increased and i can not store 2 images in internal flash  so have to do implementation of saving the image to external flash and after validation move to internal flash ,what changes i require to make in zephyr bootloader to add external flash code(SPI) and  using only 1 image in bootloader 

  • Hi Anil, 
    Please provide what exact error do you receive ? Do you have any debug log ? 

    Note that it's not possible (as far as I know) to boot from the external flash. What you can do is to receive the image in the secondary slot and then swap the image to the primary slot (the internal flash) 

    Please let us know what's your modification, which flash library,  how you configure the device tree and the partition manager (partitions.yml file). 
    Do you have the Dev Kit ? You can test my example on the devkit and then change the QSPI interface to SPI interface. It's easier if we have the same hardware and can test here.

  • Hi Hung ,

    what can cause this issue also attaching my project files

    00> *** Booting Zephyr Otonga_nrf52833.dtsS build v2.4.99-ncs1 ***usb_cdc_acm_log_recovery.conf

    00> I: Starting bootloader 00> W: Failed reading sectors; BOOT_MAX_IMG_SECTORS=512 - too small?

    00>E: Image in the primary slot is not valid!

    00> E: Unable to find bootable image

    this is the error i am getting ,this is exactly what i wanted to do save the file in external flash and then move it to internal flash,

    this is my partotion file below 

    #include <autoconf.h>

    app:
      address: 0x12200
      end_address: 0x7A000
      region: flash_primary
      size: 0x69e00
    external_flash:
      address: 0x0
      end_address: 0x800000
      region: external_flash
      size: 0x800000
    littlefs_storage:
      address: 0x7a000
      end_address: 0x80000
      placement:
        before:
        - end
      region: flash_primary
      size: 0x6000
    mcuboot:
      address: 0x0
      end_address: 0x12000
      placement:
        before:
        - mcuboot_primary
      region: flash_primary
      size: 0x12000
    mcuboot_pad:
      address: 0x12000
      end_address: 0x12200
      placement:
        align:
          start: 0x1000
        before:
        - mcuboot_primary_app
      region: flash_primary
      size: 0x200
    mcuboot_primary:
      address: 0x12000
      end_address: 0x7A000
      orig_span: &id001
      - mcuboot_pad
      - app
      region: flash_primary
      sharers: 0x1
      size: 0x69000
      span: *id001
    mcuboot_primary_app:
      address: 0x12200
      end_address: 0x7A000
      orig_span: &id002
      - app
      region: flash_primary
      size: 0x69e00
      span: *id002
    mcuboot_secondary:
      address: 0x00000
      device: mx25r6435f
      end_address: 0x69000
      placement:
        align:
          start: 0x000
      region: external_flash
      size: 0x6A000
    sram_primary:
      address: 0x20000000
      end_address: 0x20020000
      region: sram_primary
      size: 0x20000
  • Hi anil, 
    I don't see

    chosen {
    nordic,pm-ext-flash = &mx25r64; 

    }; 

    in your dts, are you sure you followed that in the overlay file in my example ? 
    Do you have a DK that can run my example ?

  • Hi Hung,

    Already have done that also added that in dts file but result is still the same having the same problem

    /*
    * Copyright (c) 2019 Nordic Semiconductor ASA
    *
    * SPDX-License-Identifier: Apache-2.0
    */

    /dts-v1/;
    #include <nordic/nrf52833_qiaa.dtsi>

    / {
    model = "MPC Tonga NRF52833";
    compatible = "nordic,tonga-nrf52833";

    chosen {
    zephyr,console = &uart0;
    zephyr,shell-uart = &uart0;
    zephyr,uart-mcumgr = &uart0;
    zephyr,bt-mon-uart = &uart0;
    zephyr,bt-c2h-uart = &uart0;
    zephyr,sram = &sram0;
    zephyr,flash = &flash0;
    zephyr,code-partition = &slot0_partition;
    zephyr,pm-ext-flash = &mx25r64;
    };

    leds {
    compatible = "gpio-leds";
    led0: led_0 {
    gpios = <&gpio0 19 GPIO_ACTIVE_HIGH>;
    label = "Green LED";
    };
    led1: led_1 {
    gpios = <&gpio0 20 GPIO_ACTIVE_HIGH>;
    label = "Red LED";
    };
    led2: led_2 {
    gpios = <&gpio0 21 GPIO_ACTIVE_HIGH>;
    label = "Blue LED";
    };
    };

    pwmleds {
    compatible = "pwm-leds";
    pwm_led0: pwm_led_0 {
    pwms = <&pwm0 13>;
    };
    };

    buttons {
    compatible = "gpio-keys";
    button0: button_0 {
    gpios = <&gpio0 22 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
    label = "Push button switch 0";
    };
    };

    interrupt {
    compatible = "gpio-keys";
    interrupt1: interrupt_1 {
    gpios = <&gpio1 7 (GPIO_ACTIVE_LOW)>;
    label = "Accel interrupt 1";
    };
    interrupt2: interrupt_2 {
    gpios = <&gpio1 6 (GPIO_ACTIVE_LOW)>;
    label = "Accel interrupt 2";
    };
    };

    arduino_header: connector {
    compatible = "arduino-header-r3";
    #gpio-cells = <2>;
    gpio-map-mask = <0xffffffff 0xffffffc0>;
    gpio-map-pass-thru = <0 0x3f>;
    gpio-map = <0 0 &gpio0 3 0>, /* A0 */
    <1 0 &gpio0 4 0>, /* A1 */
    <2 0 &gpio0 28 0>, /* A2 */
    <3 0 &gpio0 29 0>, /* A3 */
    <4 0 &gpio0 30 0>, /* A4 */
    <5 0 &gpio0 31 0>, /* A5 */
    <6 0 &gpio1 1 0>, /* D0 */
    <7 0 &gpio1 2 0>, /* D1 */
    <8 0 &gpio1 3 0>, /* D2 */
    <9 0 &gpio1 4 0>, /* D3 */
    <10 0 &gpio1 5 0>, /* D4 */
    <11 0 &gpio1 6 0>, /* D5 */
    <12 0 &gpio1 7 0>, /* D6 */
    <13 0 &gpio1 8 0>, /* D7 */
    <14 0 &gpio0 17 0>, /* D8 */
    <15 0 &gpio0 19 0>, /* D9 */
    <16 0 &gpio0 20 0>, /* D10 */
    <17 0 &gpio0 21 0>, /* D11 */
    <18 0 &gpio0 22 0>, /* D12 */
    <19 0 &gpio0 23 0>, /* D13 */
    <20 0 &gpio0 26 0>, /* D14 */
    <21 0 &gpio0 27 0>; /* D15 */
    };

    /* These aliases are provided for compatibility with samples */
    aliases {
    led0 = &led0;
    led1 = &led1;
    led2 = &led2;
    pwm-led0 = &pwm_led0;
    sw0 = &button0;
    interrupt1 = &interrupt1;
    interrupt2 = &interrupt2;
    };
    };

    &adc {
    status = "okay";
    };

    &gpiote {
    status = "okay";
    };

    &gpio0 {
    status = "okay";
    };

    &gpio1 {
    status = "okay";
    };

    &uart0 {
    compatible = "nordic,nrf-uarte";
    status = "okay";
    current-speed = <115200>;
    tx-pin = <2>;
    rx-pin = <3>;
    rts-pin = <4>;
    cts-pin = <5>;
    };

    arduino_serial: &uart1 {
    /* status = "okay"; */
    current-speed = <115200>;
    rx-pin = <33>;
    tx-pin = <34>;
    };

    arduino_i2c: &i2c0 {
    compatible = "nordic,nrf-twi";
    /* status = "okay"; */
    sda-pin = <9>;
    scl-pin = <10>;
    };

    &i2c1 {
    compatible = "nordic,nrf-twi";
    /* Cannot be used together with spi1. */
    status = "okay";
    sda-pin = <9>;
    scl-pin = <10>;
    };

    &pwm0 {
    status = "okay";
    ch0-pin = <13>;
    ch0-inverted;
    };

    &spi0 {
    compatible = "nordic,nrf-spi";
    /* Cannot be used together with i2c0. */
    status = "okay";
    sck-pin = <26>;
    mosi-pin = <24>;
    miso-pin = <25>;
    };

    &spi1 {
    compatible = "nordic,nrf-spi";
    /* status = "okay"; */
    sck-pin = <31>;
    mosi-pin = <30>;
    miso-pin = <40>;
    };

    &spi3 {
    status = "okay";
    sck-pin = <13>;
    mosi-pin = <14>;
    miso-pin = <15>;
    cs-gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;
    mx25r64: mx25r6435f@0 {
    status = "okay";
    compatible = "jedec,spi-nor";
    reg = <0>;
    spi-max-frequency = <8000000>;
    label = "MX25R64";
    jedec-id = [c2 28 17];
    size = <67108864>;
    wp-gpios = <&gpio0 16 GPIO_ACTIVE_LOW>;
    reset-gpios = <&gpio0 17 GPIO_ACTIVE_LOW>;
    partitions {
    compatible = "fixed-partitions";
    #address-cells = <1>;
    #size-cells = <1>;

    storage_partition: partition@0 {
    label = "external-flash";
    reg = <0x00000000 0x00800000>;
    };
    };
    };
    };

    &flash0 {

    partitions {
    compatible = "fixed-partitions";
    #address-cells = <1>;
    #size-cells = <1>;

    boot_partition: partition@0 {
    label = "mcuboot";
    reg = <0x000000000 0x12000>;
    };
    slot0_partition: partition@12000 {
    label = "image-0";
    reg = <0x00012000 0x69000>;
    };
    scratch_partition: partition@7B000 {
    label = "image-scratch";
    reg = <0x0007B000 0x9000>;
    };
    };
    };

    &mx25r64 {
    partitions {
    compatible = "fixed-partitions";
    #address-cells = <1>;
    #size-cells = <1>;

    slot1_partition: partition@0 {
    label = "image-1";
    reg = <0x000000000 0x000069000>;
    };
    };
    };

    &usbd {
    compatible = "nordic,nrf-usbd";
    status = "okay";
    };

  • Hi Anil, 

    - Please let us know if you have tested the example I provided ? 
    - Do you have Devkit (nRF52840/nRF52833) to test ? 
    - I'm not 100% sure but why you use "zephyr,pm-ext-flash = &mx25r64;" instead of "nordic,pm-ext-flash = &mx25r64; " ? 
    - Please send us your test project including the build folder. 

Related