How to convert bootloader.hex to bootloader.bin without big size

Hi,

       My SDK is 17.0.2

       I add Bootloader function to my project. It works very well. Now, I want to convert bootloader.hex to bootloader.bin but the converted bin file is very large(260MB)

As I know. This is because the hex file contains UICR infomation. I also check below link to solved.

 NOLOAD directive for .uicr_bootloader_start_address and .uicr_mbr_params_page 

But I have two problems

1. I use IAR as build tool for my project, so I don't have .elf file I try to use .out to replaced .elf file as below command. But bootloader.bin size still have 260MB.

arm-none-eabi-objcopy -O binary --remove-section .uicr_bootloader_start_address --remove-section .uicr_mbr_params_page secure_bootloader_ble_s140_pca10056_debug.out bootloader.bin

2. I want to remove SECTION from source code by myself.But I can't find it in which file?

How can I convert hex into bin for my project?

Thank you.

John

  • Hi John,

    May I ask what your end goal is? Why are you doing this?

    1. I use IAR as build tool for my project, so I don't have .elf file I try to use .out to replaced .elf file as below command. But bootloader.bin size still have 260MB.

    bin files contain no address information, so it will have to contain FF's to fill up the empty spaces where there are no data. On the nRF52 series, regular flash start at address 0, and the UICR starts at address 0x10001000. And all the space between there needs to be part of the bin file if it contains data both in regular flash and UICR. So most of the data here is just FFs which are not even in the memory map, and this does not make sense. This is why bin files are not a good option in such cases. Intel hex files on the other hand has address information for every line, so it elegantly handles data scattered around.

    If you need the bootloader bin file, the simplest would probably be to remove the UICR part from the intel hex file with a text editor, and then convert the edited hex filet to bin (SRecord is a good tool for that).

    2. I want to remove SECTION from source code by myself.But I can't find it in which file?

    First of all, note that if you remove this form the bootloader file you need some other way of writing this to the production bootloader, as the MBR checks a specific UICR register to know the bootloader start address. This is why the bootloader project has data in the UICR. That said, his is use din components/libraries/bootloader/nrf_bootloader_info.c. So to remove it, remove it there, and remove it from the ICR project (icf file).

    Einar

  • Hi Einar,

           Actually, we want to do our own Bootloader update. So I need bin file.

    I found the zip file made by nrfutil.exe tool. After opening, there is a bin file inside and I can use.

    At present, I have made it possible to write the bootloader bin file to internal flash by our application and after rewrite NRF_UICR->NRFFW[0]. It can update and work normally.

    Is there anything I need to be aware of?

    Thank you.

    John.

         

  • Hi John,

    Yes, that was a smart trick. nrfutil does basically what I wrote in my previous post, removing the UICR part when making a bootloader DFU zip file.

    Regarding things to be aware of, the only think I notice about what you write is that you "rewrite NRF_UICR->NRFFW[0]". Note that the UICR is special, and can only be erased (flipping all bits to '1') by a full chip erase. So, other than that, the only re-writing you can do of any UICR register run-time is flipping bits from '1' to '0'. So in practice, the UICR registers (including the bootloader start address) should normally never change in the field. This also means that if you think you may need to increase the bootloader size at a later point via DFU, it is better to set aside that space right away, setting a lower bootloader start address from the get-go.

    Einar

  • Hi Einar,

               I allocate my bootloader start addr is 0xE5000 and end addr is 0xFDFFF. This should not change, enough for my future expansion. My steps are as follows

    1. Erase 0xE5000 - 0xFDFFF by nrf_fstorage_erase

    2. Copy My new bootloader bin file to 0xE5000 addr by nrf_fstorage_write

    3. After writing all the bin files, I will call this Function to change the UICR.

    uint32_t data = 0xE5000;
    
    static void write_uicr_customer_register(uint32_t * data, uint32_t offset)
    {
        uint32_t* cust_data = (uint32_t*)(NRF_UICR_BASE + offset);
    
        NRF_NVMC->CONFIG = 1; //write enabled
        while(NRF_NVMC->READY == NVMC_READY_READY_Busy);//busy
        *cust_data = *data;
        while(NRF_NVMC->READY == NVMC_READY_READY_Busy);//busy
        NRF_NVMC->CONFIG = 0; //read only
        while(NRF_NVMC->READY == NVMC_READY_READY_Busy);//busy
    }

    It should be fine with this, right?

    Thank you.

    John.

  • Yes, as long as you only do this once (never try to write another value tot he same UICR register), there is no problem.

Related