This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Does bootloader need put data on MBR section of coed?

Hi,

I am developing a product based on nrf52840 soc, I need to write a softdevice, program hex file, bootloader on the chip. when I want to select them all in the nrf connect to program the chip, nrf connect says that bootloader and softdevice have some overlapping data. as I can see this overlapping occurs in the MBR section.

is this normal? does bootloader need to put data on the MBR section of code?

I've attached the bootloader and softdevice.

thanks

bootloader.hexsoftdevice.hex

Parents
  • Hi Alireza, 

    Which SDK version are you using? It could sound like you are using SDK v15.3.0, where we introduced support for the v6.1.1 SoftDevices. The v6.1.1 SoftDevices allows the bootloader to write the bootloader start address and the MBR parameter page address to flash locations inside the MBR. The MBR will then use these addresses instead of fecthing the bootloader start and the MBR parameter page addresses from the UICR registers. If the bootloader start and the MBR parameter page address is not written to the MBR region, then the MBR will try to fetch the addresses from UICR like before. 

    In SDK v15.3.0 we modified the bootloader project so that it would place the bootloader start and the MBR parameter page addresses in the MBR region, i.e. it would place the bootloader start and MBR parameter page addresses at 0xFF8 and 0xFFC respectivly. So the compiled bootloader binary will contain code in the MRB region, so this is why nRF Connect Programmer states that the bootloader and SoftDevice( specifically the MBR) overlaps. 

    This can be solved by modifying the bootloader to place the bootlaoder start address and MBR parameter page to UICR and then write to 0xFF8 and 0xFFC at run-time, rather than placing the addresses in the MBR region in the compiled binary. The bootloader will only perform the write to the MBR region on the first start up and on all subsequent startups the values inside the MBR will be used and not the ones stored in the UICR registers. 

    The modification needed is adding the snippet below to main() before nrf_bootloader_flash_protect().

    // Add this function to main() before the nrf_bootloader_flash_protect call
    
    ret_code_t nrf_bootloader_write_bl_addr_to_mbr(void){
    
        if( (*(volatile uint32_t *)MBR_BOOTLOADER_ADDR != BOOTLOADER_START_ADDR) && 
         (*(volatile uint32_t *)MBR_PARAM_PAGE_ADDR = NRF_MBR_PARAMS_PAGE_ADDRESS))
         {
              // Enable Write with the NVMC
              NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
              while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
    
              // Write Bootloader start address to MBR 
              *(volatile uint32_t *)MBR_BOOTLOADER_ADDR = BOOTLOADER_START_ADDR;
              // Write MBR parameter page address to MBR
              *(volatile uint32_t *)MBR_PARAM_PAGE_ADDR = NRF_MBR_PARAMS_PAGE_ADDRESS;
              // Revert NVMC to read-only
              NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
              while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
          }
    
        return NRF_SUCCESS;
    }

    Then you need to  modify the flash_placement.xml to place the addresses in UICR instead of flash. 

      <MemorySegment name="uicr_bootloader_start_address" start="0x10001014" size="0x4">
        <ProgramSection alignment="4" keep="Yes" load="Yes" name=".uicr_bootloader_start_address" address_symbol="__start_uicr_bootloader_start_address" end_symbol="__stop_uicr_bootloader_start_address" start = "0x10001014" size="0x4" />
      </MemorySegment>
      <MemorySegment name="uicr_mbr_params_page" start="0x10001018" size="0x4">
        <ProgramSection alignment="4" keep="Yes" load="Yes" name=".uicr_mbr_params_page" address_symbol="__start_uicr_mbr_params_page" end_symbol="__stop_uicr_mbr_params_page" start = "0x10001018" size="0x4" />
      </MemorySegment>
    </Root>

    Best regards

    Bjørn

Reply
  • Hi Alireza, 

    Which SDK version are you using? It could sound like you are using SDK v15.3.0, where we introduced support for the v6.1.1 SoftDevices. The v6.1.1 SoftDevices allows the bootloader to write the bootloader start address and the MBR parameter page address to flash locations inside the MBR. The MBR will then use these addresses instead of fecthing the bootloader start and the MBR parameter page addresses from the UICR registers. If the bootloader start and the MBR parameter page address is not written to the MBR region, then the MBR will try to fetch the addresses from UICR like before. 

    In SDK v15.3.0 we modified the bootloader project so that it would place the bootloader start and the MBR parameter page addresses in the MBR region, i.e. it would place the bootloader start and MBR parameter page addresses at 0xFF8 and 0xFFC respectivly. So the compiled bootloader binary will contain code in the MRB region, so this is why nRF Connect Programmer states that the bootloader and SoftDevice( specifically the MBR) overlaps. 

    This can be solved by modifying the bootloader to place the bootlaoder start address and MBR parameter page to UICR and then write to 0xFF8 and 0xFFC at run-time, rather than placing the addresses in the MBR region in the compiled binary. The bootloader will only perform the write to the MBR region on the first start up and on all subsequent startups the values inside the MBR will be used and not the ones stored in the UICR registers. 

    The modification needed is adding the snippet below to main() before nrf_bootloader_flash_protect().

    // Add this function to main() before the nrf_bootloader_flash_protect call
    
    ret_code_t nrf_bootloader_write_bl_addr_to_mbr(void){
    
        if( (*(volatile uint32_t *)MBR_BOOTLOADER_ADDR != BOOTLOADER_START_ADDR) && 
         (*(volatile uint32_t *)MBR_PARAM_PAGE_ADDR = NRF_MBR_PARAMS_PAGE_ADDRESS))
         {
              // Enable Write with the NVMC
              NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
              while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
    
              // Write Bootloader start address to MBR 
              *(volatile uint32_t *)MBR_BOOTLOADER_ADDR = BOOTLOADER_START_ADDR;
              // Write MBR parameter page address to MBR
              *(volatile uint32_t *)MBR_PARAM_PAGE_ADDR = NRF_MBR_PARAMS_PAGE_ADDRESS;
              // Revert NVMC to read-only
              NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
              while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
          }
    
        return NRF_SUCCESS;
    }

    Then you need to  modify the flash_placement.xml to place the addresses in UICR instead of flash. 

      <MemorySegment name="uicr_bootloader_start_address" start="0x10001014" size="0x4">
        <ProgramSection alignment="4" keep="Yes" load="Yes" name=".uicr_bootloader_start_address" address_symbol="__start_uicr_bootloader_start_address" end_symbol="__stop_uicr_bootloader_start_address" start = "0x10001014" size="0x4" />
      </MemorySegment>
      <MemorySegment name="uicr_mbr_params_page" start="0x10001018" size="0x4">
        <ProgramSection alignment="4" keep="Yes" load="Yes" name=".uicr_mbr_params_page" address_symbol="__start_uicr_mbr_params_page" end_symbol="__stop_uicr_mbr_params_page" start = "0x10001018" size="0x4" />
      </MemorySegment>
    </Root>

    Best regards

    Bjørn

Children
Related