Update flash contents in ELF with objcopy

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I am working on a new Microchip Studio project for ARM AtmelSAML22 device. We use srec_cat to fill (patch any holes in) the intel hex image and append information (mainly a couple of CRC values but also project info) to the end of the image. This process works OK in that I can do all this and generate an output hex file using a post build batch file in windows.

 

I want to make sure that the IDE still works (programming and debugging) with this modified image and it appears that I need to update the ELF output with this modified intel hex file (as Atmel Studio appears to use the ELF for this).

 

I am not sure how to do this.

 

From reading some other posts it seems that it should be achievable with the arm-none-eabi-objcopy.exe (objcopy) tool but I'm just not sure how. I assume I should use the --update-section with the hex file but I assume that the hex file includes .text and .data sections?

 

Any help would be most appreciated.

This topic has a solution.
Last Edited: Thu. Apr 1, 2021 - 10:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

mike.pcl wrote:
it appears that I need to update the ELF output

I think that shouldn't be necessary?

 

Just make sure that MCS doesn't program the chip (from the ELF)  when you start the  debug session - use Debug > Attach to target:

 

 

EDIT

 

https://microchipsupport.force.com/s/article/Atmel-Studio-SAM-Smart-ARM-MCU-Live-Attach-feature

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Mar 30, 2021 - 10:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But will the IDE not program the target from the ELF when I hit the play button?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes - so don't do that!

 

Do 'Attach to target' instead.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How will this program the target with the modified hex file?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


You'd have to do that manually - go to 'Device Programming' 

 

 

and tell it to program your modified Hex file.

 

As you're already doing .bat files, you could probably put that into a .bat file - using the atprogram command-line tool ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, I get it, but this feels like a bit of a hack.

 

I want to try to maintain the ELF file such that this can be used for easier production programming (my understanding is that this contains any eeprom, fuse settings, lock bits etc.).

 

One solution I read was to allocate a section in the linker script and then use the --update-section option in objcopy but I just thought it should be easy to replace the ELF contents with the hex file?

 

Cheers 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mike.pcl wrote:
my understanding is that this contains any eeprom, fuse settings, lock bits etc.

Does a SAML22 have such things?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fuses - yes, lock (security) - yes, signature - I think so, eeprom - no (but may be using a different part soon).

 

As much as anything else I just don't want to 'break' the IDE  

 

Cheers

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually, maybe you are right.

 

I cannot see sections in the ELF for .eeprom, .fuse, .lock or .signature as inferred by the Makefile.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I've moved this thread from AVR to ARM as SAM was mentioned in #1.

 

To me that then raises the question "are things like .fuse, .lock even used for SAM or are they an AVR only concept?" I don't know enough about Atmel ARMs to answer that.

 

Anyway in the above:

awneil wrote:
Do 'Attach to target' instead.
mike.pcl wrote:
OK, I get it, but this feels like a bit of a hack.

personally I don't see why. My day job is basically working on the development of Windows DLLs that are loaded by an EXE that does not change. So to debug we run the EXE then "attach to target" to debug the code in the DLLs. I don't see that it's particularly unusual to use "attach to target" - indeed the option would not exist in Visual Studio if it were not a common requirement.

 

I don't see anything particularly wrong in doing the same with AVR/SAM if you are using binaries that are different to what the build system creates in the ELF (which is where the debugger loads its symbolic info from - the equivalent of PDB in the EXE/DLL world).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, thanks.

 

I am struggling to find a better method anyway.

 

Cheers

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Thanks again for the help. Just to keep this thread updated I found the solution I was looking for in this thread

 

https://www.avrfreaks.net/forum/usage-srecord-batch-file-hex-file-modification

 

This is very similar to our existing process but adds the CRC information to a specific memory location at the end of flash. Porting the example given is fairly straightforward, just update the linker with the crc section and update the addresses in the post-build script.

 

This keeps all the build outputs updated with the CRC information.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the feedback. Please mark the solution - see Tip #5 in my signature, below:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Done, thanks