title: Storing CRC into an AXF/ELF file
body: <p>I'm currently working on a C program in the <a href="http://www.lpcware.com/lpcxpresso">LPCXpresso (eclipse-based)</a> tool-chain on Windows 7, an IDE with gcc targeting the an NXP Cortex M3 microprocessor.  It provides a simple way to compile-link-program the microprocessor over JTAG.  The result of a build is an AXF file (ELF format) that is loaded by a debug configuration.</p>
  
  <p>The loaded program resides in Flash memory from 0x00000 to 0x3FFFB.  I'd like to include a 4-byte CRC-32 at 0x3FFFC to validate the program at start-up.  I added another section and use the gcc <code>__attribute__</code> directive to access that memory location.</p>
  
  <pre><code>uint32_t crc32_build __attribute__ ((section(".text_MFlashCRC")));
  </code></pre>
  
  <p>To compute and store the CRC-32 value, my plan was to use <a href="http://srecord.sourceforge.net/">SRecord</a> with the following post-build steps:</p>
  
  <pre><code>arm-none-eabi-size "${BuildArtifactFileName}"
  arm-none-eabi-objcopy -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin"
  checksum -p ${TargetChip} -d "${BuildArtifactFileBaseName}.bin"
  ../util/srec_cat "${BuildArtifactFileBaseName}.bin" -binary -crop 0 0x3FFFC -fill 0xFF 0x00000 0x3FFFC -crc32-b-e 0x3FFFC -o "${BuildArtifactFileBaseName}.crc.bin" -binary
  echo ""
  echo "CRC32:"
  ../util/srec_cat "${BuildArtifactFileBaseName}.crc.bin" -binary -crop 0x3FFFC 0x40000 -o - -hex-dump
  </code></pre>
  
  <p>This creates a binary with a checksum (necessary for bootloader) and then computes the CRC over the used Flash memory, storing the CRC value at 0x3FFFC.</p>
  
  <p>However, I don't think I can load the binary file using the debugger.  There is a built in programming utility with LPCXpresso that can load the modified binary file, however, that doesn't let me debug.  I believe I can then try to start a debugging session with the original AXF file using "attach-only" mode, however, this becomes cumbersome.</p>
  
  <p>I've been able to use readelf to inspect the <code>crc32_build</code> variable in the AXF file.  Is there a way to edit the variable in the AXF file?  Is there an industry-standard approach to inserting a CRC as a post-build step?</p>