Bootloader address flash write

1. Hi i am utilizing nrf52840 sdk with ver 17.1.10 s140 and i have the central UART as main app from there we are calling bootloader

2. Before calling bootloader ble dfu we are writing the data in the Flash address 0x3e000 4 bytes

3. After entering into bootloader ble dfu mode the flash address 0x3e000  data is FF 

4.  which flash address i can write so that the value remains  even it enters into ble bootloader dfu 

5. for flash writing i am using fstorage funcions   in the main central uart app

ret_code_t ret = nrf_fstorage_erase(&fstorage, 0x3e000, 1, NULL);

wait_for_flash_ready(&fstorage);

ret_code_t ret1 = nrf_fstorage_write(&fstorage, 0x3e000, &data_wrt, sizeof(data_wrt), NULL);

wait_for_flash_ready(&fstorage);

Parents
  • Hi,

    You should use the area below the bootloader shown as "Application data" here:

    https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/lib_bootloader.html 

    The size and location of this area is dependent on the start address of the bootloader and the NRF_DFU_APP_DATA_AREA_SIZE value configured in the bootloader project.

    Bes regards,

    Vidar

  • Hi thanks for your reply i need to write only 1 byte data and currently i am using fstorage libraries can we achieve using this or is there any other method for writing small data into flash or any registers that can be used ?

  • 1. So i need  to retain the data at least 4 byte even if it enters into bootloader_ble dfu after triggering form the main central UART

    2.  I have explained requirements in the above post so need to know that for writing at least 4 bytes is possible using fstorage because we need to erase before writing 

    3. Is it required to erase 4096 bytes before writing the data ?

    3. Is there any other method like registers, so that i can write 4 bytes data in the flash and that should be accessible even if it enters in the bootloader_ble dfu mode also 

    Note : I need only 1 byte if it is not happening 4 bytes is also ok but i need a simple way to write small data in flash or registers so that i can access in bootloader_ble dfu also    

  • I'm trying to understand your goal is. If just want the app to be able to pass a flag/value to the bootloader, you could just use the one of the General purpose retention registers (GPREGRET). These are retained through a Soft reset.

    Note that there are two of these registers available, and one is used by the bootloader when NRF_BL_APP_CRC_CHECK_SKIPPED_ON_GPREGRET2 is enabled, and the other when NRF_BL_DFU_ENTER_METHOD_GPREGRET is enabled.

  • 1. Hi  after setting the GPREGRET2 register value  in which address should i verify that the value is written properly 

    i have the following code snippet in central uart app before calling ble bootloader is this a correct method ?


    // Clear GPREGRET register
    err_code = sd_power_gpregret_clr(0, 0xFF);
    APP_ERROR_CHECK(err_code);

    // Set GPREGRET register to trigger DFU
    err_code = sd_power_gpregret_set(0, BOOTLOADER_DFU_START);
    APP_ERROR_CHECK(err_code);

    // Clear GPREGRET2 register
    err_code = sd_power_gpregret_clr(1, 0xFF);
    APP_ERROR_CHECK(err_code);

    // Set GPREGRET2 register
    err_code = sd_power_gpregret_set(1, 0x56);
    APP_ERROR_CHECK(err_code);

    // Reset the system
    NVIC_SystemReset();
    }

    2. I Tried to write the register in the Bootloader_ble_debug app to verify whether we can able to write and read the data  but error code 01 is returned form the func what are the required things to be done before writing into it 

    code snippet 

    uint32_t err_code;

    err_code = sd_power_gpregret_clr(1, 0xFF);
    NRF_LOG_DEBUG("ret 1 = %d\n", err_code);
    APP_ERROR_CHECK(err_code);

    // Set GPREGRET2 register
    err_code = sd_power_gpregret_set(1, 0x56);
    NRF_LOG_DEBUG("ret 2 = %d\n", err_code);
    APP_ERROR_CHECK(err_code);

    uint32_t custom_data = NRF_POWER->GPREGRET2;

    NRF_LOG_DEBUG("custom data 0x%04X", custom_data);

    logs:

    <info> app: Inside main
    <debug> app: ret 1 = 1

    <error> app: Received an error: 0x00000001!

    Note : i have tried to achieve that read and write in both the app for verification of this GPREGRET2 register

  • The GPREGRET registers are included in the POWER peripheral, which the Softdevice reserves access to. Therefore, you need to use the sd_power_gpregret_* APIs to access these registers in the application while the Softdevice is enabled. However, these functions cannot be when the Softdevice is disabled, hence the NRF_ERROR_SVC_HANDLER_MISSING ('1')  error. 

    You can see how the nrf_power_gpregret* functions are used in the bootloader.

  • Hi vidar Berg thanks for your reply

    1.I have tried with nrf_power_gpregret api by writing and reading in the register it is working fine in bootloader_ble_debug app

    2.but when we tried to read only using nrf_power_gpregret2_get() after power reset the data is 0 is that the register value becoming 0 after power reset or any where it is clearing in the code after reset in booloader_ble_debug sdk

    3. Can i verify through any particular flash address or the register address so that the data is written

    4. Is there any other registers which will retain its value even after power reset


    // nrf_power_gpregret2_set(0x56);
    // APP_ERROR_CHECK(err_code);

    // Set GPREGRET register to trigger DFU
    uint8_t ret = nrf_power_gpregret2_get();
    APP_ERROR_CHECK(err_code);

    logs:

    ret = 0x0
    <info> app: Inside main
    <debug> app: In nrf_bootloader_init
    <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
    <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
    <debug> nrf_dfu_settings: Using settings page.
    <debug> nrf_dfu_settings: Copying forbidden parts from backup page.
    <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    <info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
    <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    <debug> app: Enter nrf_bootloader_fw_activate
    <info> app: No firmware to activate.
    <info> app: Boot validation failed. No valid app to boot.
    <debug> app: DFU mode because app is not valid.
    <info> nrf_bootloader_wdt: WDT is not enabled
    <debug> app: in weak nrf_dfu_init_user
    <debug> app: timer_stop (0x2000599C)
    <debug> app: timer_activate (0x2000599C)
    <info> app: Entering DFU mode.
    <debug> app: Initializing transports (found: 1)
    <debug> nrf_dfu_ble: Initializing BLE DFU transport
    <debug> nrf_dfu_ble: Setting up vector table: 0x000F1000
    <debug> nrf_dfu_ble: Enabling SoftDevice.
    <debug> nrf_dfu_ble: Configuring BLE stack.
    <debug> nrf_dfu_ble: Enabling the BLE stack.
    <debug> nrf_dfu_ble: No advertising name found
    <debug> nrf_dfu_ble: Using default advertising name
    <debug> nrf_dfu_ble: Advertising...
    <debug> nrf_dfu_ble: BLE DFU transport initialized.
    <debug> nrf_dfu_flash: Initializing nrf_fstorage_sd backend.
    <debug> app: Enter main loop

Reply
  • Hi vidar Berg thanks for your reply

    1.I have tried with nrf_power_gpregret api by writing and reading in the register it is working fine in bootloader_ble_debug app

    2.but when we tried to read only using nrf_power_gpregret2_get() after power reset the data is 0 is that the register value becoming 0 after power reset or any where it is clearing in the code after reset in booloader_ble_debug sdk

    3. Can i verify through any particular flash address or the register address so that the data is written

    4. Is there any other registers which will retain its value even after power reset


    // nrf_power_gpregret2_set(0x56);
    // APP_ERROR_CHECK(err_code);

    // Set GPREGRET register to trigger DFU
    uint8_t ret = nrf_power_gpregret2_get();
    APP_ERROR_CHECK(err_code);

    logs:

    ret = 0x0
    <info> app: Inside main
    <debug> app: In nrf_bootloader_init
    <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
    <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
    <debug> nrf_dfu_settings: Using settings page.
    <debug> nrf_dfu_settings: Copying forbidden parts from backup page.
    <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    <info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
    <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    <debug> app: Enter nrf_bootloader_fw_activate
    <info> app: No firmware to activate.
    <info> app: Boot validation failed. No valid app to boot.
    <debug> app: DFU mode because app is not valid.
    <info> nrf_bootloader_wdt: WDT is not enabled
    <debug> app: in weak nrf_dfu_init_user
    <debug> app: timer_stop (0x2000599C)
    <debug> app: timer_activate (0x2000599C)
    <info> app: Entering DFU mode.
    <debug> app: Initializing transports (found: 1)
    <debug> nrf_dfu_ble: Initializing BLE DFU transport
    <debug> nrf_dfu_ble: Setting up vector table: 0x000F1000
    <debug> nrf_dfu_ble: Enabling SoftDevice.
    <debug> nrf_dfu_ble: Configuring BLE stack.
    <debug> nrf_dfu_ble: Enabling the BLE stack.
    <debug> nrf_dfu_ble: No advertising name found
    <debug> nrf_dfu_ble: Using default advertising name
    <debug> nrf_dfu_ble: Advertising...
    <debug> nrf_dfu_ble: BLE DFU transport initialized.
    <debug> nrf_dfu_flash: Initializing nrf_fstorage_sd backend.
    <debug> app: Enter main loop

Children
No Data
Related