IAR compiled hex file not page aligned to uint32. CRC grabs bogus 0xFF as last byte

I build the application code for bank-1 using IAR.  The hex output occupies (0x0008500~0x000AAEB6).  Note that this is 155319 bytes (not page aligned to uint32--- one byte missing!). 

This is confirmed with hex edit.  One byte is missing.

When I generate bootloader settings using nrfutil.exe, it reports a size of 155320 bytes, even though the actual hex file is 155319 bytes.

I use the nRF Programmer tool to merge the hex files (MBR/SD, App, Bootloader, Bootloader Settings) and download using nrfjprog.exe.

When the debugger tries to copy firmware from bank1 to bank0, it checks the CRC using crc32_compute().  It uses the size field from the bootloader settings.  This overruns the bank-1 firmware code, and grabs a bogus 0xFF as the last byte.

Debugger paused at the end of crc32_compute().  Last byte that is included in the calculation is 0xFF at 0x0004BEB7.

Programmer

Question

Is there a setting that will tell the IAR compiler to spit out a page aligned hex file?  Is there also a bug in the nrfutil?

SDK15.0.0; SD140; nRF52840

IAR 8.50.9

  • Hi,

    What mergehex version are you using?

    There was a bug fix in mergehex v10.12.2, so make sure that you have 10.12.2 or newer.

  • Hi,

    How does your .icf file looke like?

    Something like this?

    /*###ICF### Section handled by ICF editor, don't touch! ****/
    /*-Editor annotation file-*/
    /* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
    /*-Specials-*/
    define symbol __ICFEDIT_intvec_start__ = 0x26000;
    /*-Memory Regions-*/
    define symbol __ICFEDIT_region_ROM_start__   = 0x26000;
    define symbol __ICFEDIT_region_ROM_end__     = 0xfffff;
    define symbol __ICFEDIT_region_RAM_start__   = 0x20002b88;
    define symbol __ICFEDIT_region_RAM_end__     = 0x2003ffff;
    export symbol __ICFEDIT_region_RAM_start__;
    export symbol __ICFEDIT_region_RAM_end__;
    /*-Sizes-*/
    define symbol __ICFEDIT_size_cstack__   = 8192;
    define symbol __ICFEDIT_size_heap__     = 8192;
    /**** End of ICF editor section. ###ICF###*/
    
    define memory mem with size = 4G;
    define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to __ICFEDIT_region_ROM_end__];
    define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];
    
    
    define block CSTACK    with alignment = 8, size = __ICFEDIT_size_cstack__   { };
    define block HEAP      with alignment = 8, size = __ICFEDIT_size_heap__     { };
    define block RO_END    with alignment = 8, size = 0     { };
    
    initialize by copy { readwrite };
    do not initialize  { section .noinit };
    
    keep { section .intvec };
    place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
    place in ROM_region   { readonly,
                            block RO_END };
    place in RAM_region   { readwrite,
                            block CSTACK,
                            block HEAP };
    
    

Related