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

Problems with bytes added at end of image

Hi everybody,

I'm writing a bootloader for a Cortex-M4 microcontroller. This bootloader is placed into the first 16 kByte-Flash-Segment of the chip (Address-region 0x08000000 - 0x08004000). The bootloader is a seperate Keil-Project and after execution jumps to the application-start-address at 0x08004000.
The application has its own Keil-Project where I configured the target options for a start-address of 0x08004000 and a size of 32 kBytes. Furthermore I added some arrays at the end of the 32 kByte application-region where the bootloader can retrieve some data. I've accomplished it like this:

const uint8_t u8_ProgramVersion[4] __attribute__((at(0x0800BFF4))) = {1, 2, 3, 4};

All in all there are three arrays with a 4-Byte size like the one above placed flush at start address 0x0800BFF4 in a specific c-file.
Now the following Scenario: omitting the c-file with the above-mentioned arrays gives me a code-size of around 15 kBytes (Code + RO-data + RW-data), which fits well into the overall 32 kByte area.
If I put in the c-file with the arrays again, I get an linker-error:

"Error: L6220E: Load region LR_IROM1 size (32948 bytes) exceeds limit (32768 bytes). Region contains 17441 bytes of padding and 0 bytes of veneers (total 17441 bytes of linker generated content)"

If I increase the allowed memory-size for the application to 48 kBytes (the arrays are still placed at the above-mentioned addresses at the end of 32 kBytes) I get a code size of 32,59 kBytes when I expected exactly 32 kBytes. Looking into the bin-file I see some bytes after my arrays. I can't find what those bytes are when I look into the map-file.
During debugging I accidentally found out, that when some of those bytes at the end are not flashed into the controller I get an Hard fault in the __main of the startup-code and it doesn't jump into normal main(). So I guess those bytes are from the startup-code.

Now, the question is: how do I tell uVision, that my arrays are supposed to be the last bytes in the Image?
If possible I want to avoid giving the c-file containing the Arrays its own region at the end of the 32 kBytes because that results in two bin-files. Is there a way to do that and get only one bin-file?

Best regards, Niclas

  • For sparse data use a .HEX file

    To control placement in the linker, use a scatter file with the appropriate regions/sections described in that. Keep your arrays OUTSIDE the primary flash load region (LR).

  • Hi Westonsupermare,

    thanks for your answer. I was hoping that there is a solution that results in one single bin-file. When I place the arrays in their own section I get a "TargetName.bin"-folder with two bin-files in it. With a single bin-file I would be able to use a tool we're already using for another much older microcontroller that sends me the bin-file-content as a stream of can-messages. Handling a hex-file would require us to make a new tool for the purpose of sending the data via can. But if there's no other solution I guess we have to swallow the bitter pill...

    Regards, Niclas

  • Ok, problem solved. I place the arrays in their own section and then use a hex2bin-tool I found on the internet to make my bin-file from the hex-file. Works like a charm.