I'm using an STM32 target, and I need to embed a length and CRC word into the generated code in order for my bootloader (which always runs at reset) to run a consistency check on the application before branching to it. The CRC is appended to the end of the generated image to simplify checking i.e. I get a checksum of zero if code is ok.
I found a very useful thread on the forum (http://www.keil.com/forum/10582/) that discusses the use of linker symbols to obtain the image size; I've used this successfully to embed the length at a fixed address near the start of the image (after the vector table).
Generating the CRC is simple by parsing the hex file with a simple utility which is called from the Keil project manager. Unfortunately this means the target can only be programmed using the hex file; the system will fail if the target is programmed from the IDE using the AXF file which is an inconvenience. Is there any way of inserting the required data into the AXF file so a valid image will be loaded when I start debugging? Currently I have set up a separate project to program the target with the hex file and then disabled programming operations in the debugger options in my main project, but this is rather error prone!
Hi Mike,
You are truly missed on that other forum.
AXF is an ELF, right? If so, for toolchains lacking binutils, I have found that writing custom ELF utilities to do things much like what you've described is not too difficult. Nowadays, while using toolchains <u>with</u> binutils, I have not had an occasion to need to do something that modifies the normal ELF output. I haven't dug into it, but am wondering if you can extract the sections you want to CRC (presumably .text [plus .data?]), append a CRC, and create a new ELF with just what's required for programming -- not well thought out yet, but you get the gist of it. If that didn't bear fruit quickly, I'll restate that ELF utilities are fairly easy to write.
Best regards,
-Dan Henry
If I am not mistaken, with a debugger initialization script you can do the following: - Upload a HEX file with a checksum to the target (LOAD *.hex) - Load debugging information into the debugger (LOAD *.axf NOCODE) - And proceed to debugging as usual
Hi Dan,
Yes I feel guilty about the other forum, I will make an effort to contribute ASAP. Unfortunately work and personal commitments have taken precedence for a long while...
The debugger script sounds like a nice simple workaround, but I'll look into ELF file creation as even if I don't go that route is something that could be very useful for some other firmware in development.
Thanks both!