How do I move the initialization data in Flash?

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

I'm compiling some code for an ATmega32 with avr-gcc 3.4.5 and I'd like to partition the Flash as follows:

vectors, .text, & variable initialization: 0000-35FF
update1_app: 3600-39FF
update2_app: 3A00-3DFF
update1_nrww: 3E00-3EFF
update2_nrww: 3F00-3FFF

To get the four custom sections in Flash, I added the following parameter to my link command:

-Wl,--section-start,.update1_app=6C00,--section-start,.update2_app=7400,--section-start,.update1_nrww=7C00,--section-start,.update2_nrww=7E00

This is almost perfect. The code for these sections show up exactly where they should. The main code and vector table are in the right place. My variables in .data and .bss end up in the right part of RAM too.

The initialized variables in .data are initialized by copying the data from Flash to RAM with the LPM command. Those constants are located in SOME SECTION. I'm assuming this region has a name, but I don't know what it is. My web searches have been fruitless. Anyhow, gcc has placed these constants at the end of my last section (update2_nrww) and this is NOT where I want them.

What is the simplest way to move this data to the end of my .text and to make sure it gets located within 0000-35FF?

Thanks in advance. I've had a million questions so far (this is my first AVR project) and thanks to these forums, this is the first one I haven't been able to answer myself by reading your posts!

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

Are you sure that GCC has placed them there or is this where you are seeing them after Studio has parsed and loaded the .ELF file? There are limitations with Studio's .ELF support and when I added just a single additional section (.bootloader) to my code I found that the C pre-amble was not initialising values in .data but they WERE in the right place in the .HEX file - it was just when Studio loaded the .ELF file and it had more than just the "standard" .text, .data and .bss it seemed that Studio misplaced the initialisers (but I'm not sure what that section is actually called though!)

So have a look at the generated .HEX (even program it into the AVR) then have a look and see if the .data initialisers are placed correctly in that case - I think you'll find they will be.

Cliff

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

Well I'll be Bill Gates' little girl! GCC was doing everything correctly after all and it was just Studio screwing up. I guess in retrospect, this doesn't really surprise me, but I wouldn't have guessed this is what is going on. Thanks for pointing me in the right direction!

So is there a workaround to this problem or should I search the Studio forum for help on that?

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

Gre7g

Well the workaround is to NOT have Studio download the contents of the .ELF to the device when you start JTAG debugging. Instead, what you do, is use Studio/ICE to just program the raw .HEX file that is output from the build into the device (this has everything located in the right places) then to debug you load the .ELF but, because it is not programmed into the device, Studio effectively only uses it for symbolic debugging to get the location of symbols. So the .data initialisers will be copied from the right location.

Cliff

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

Brilliant! Such a cool idea, that I feel like a total heel for asking this next one. However, I'm sure you saw it coming... :?

clawson wrote:
Well the workaround is to NOT have Studio download the contents of the .ELF to the device when you start JTAG debugging.

drum roll... How?

I can't find any Studio option to tell it not to download the .ELF when I begin debugging. Programming the .hex file is no problem, but how do I keep Studio from covering this up when I try to debug?

I tried doing a "avr-objcopy --only-keep-debug" on the .ELF, but once you do that, Studio won't even touch the file, much less enter debug mode.

Just another couple of hints, and I swear I'll be off and running. Thanks!

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

I know what you mean - it took me a while to find the option. See my last post (the second last post) in this thread:

https://www.avrfreaks.net/index.p...

Cliff

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

THAT'S WHAT THAT CHECKBOX IS FOR?!?!?!?

Grrr. Thanks for pointing it out!

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

I did some work on the elf/dwarf parser to fix problems like these, and the changes are included in the latest AVR Studio service pack. Can any of you confirm that the parser puts the sections in their right places now?

Torleif

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

Torleif,

Yes, the latest service pack fixed the elf file data parsing problem

Cliff

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

Great!
Thanks for the reply.

Torleif