Location of initialized & PROGMEM variables (in flash) in Bootloader programs.

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

I am writing a custom bootloader program for Atmega2560 micro controller. I understand that the global/static initialized variables in SRAM gets initialized from the flash memory by the crt code (from __data_start to __data_end). Now, what I see is that even for the bootloader code, the global initialized variables and the variables with PROGMEM attribute in boot section are getting stored in the beginning of the Flash ( __data_start to __data_end are in the beginning of the flash). I want the global initialized variables and the variables with PROGMEM attribute in boot section to be initialized from the BLS section of the flash itself (i.e. __data_start to __data_end in BLS section). How can I change them to BLS area.

Vinu Raja Kumar C

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

You move the whole app to the bootloader section by changing the .text address. Everything gets moved up, and the data loading is taken care of (and it knows to use elpm to load data from flash).

 

#include <avr/io.h>
//set .text section to word address of bootloader start address
//-Wl,-section-start=.text=0x1F000
int mydata = 0x1234;
int main(void) {
    for(;;){};
}

 

Disassembly of section .text:

0003e000 <__vectors>:
   3e000:    0d 94 72 f0 

...

0003e0f4 <__do_copy_data>:

...
   3e0fe:    03 e0           ldi    r16, 0x03    ; 3
   3e100:    0b bf           out    0x3b, r16    ; 59
   3e102:    02 c0           rjmp    .+4          ; 0x3e108 <__do_copy_data+0x14>
   3e104:    07 90           elpm    r0, Z+

...

 

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

VinuRajaKumar wrote:
I want the global initialized variables and the variables with PROGMEM
You sure you want to use globals in a bootloader? Normally, because bootloaders don't use interrupts you don't want to waste bootloader space so you build with -nostartfiles but that also means you won't get a _do_copy_data loop so you are better off avoiding globals (.data) variables all together.
curtvm wrote:
//-Wl,-section-start=.text=0x1F000
Just to point out that this is such a common requirement that the linker offers:

 

//-Wl,-Ttext=0x1F000

 

as a shortcut ;-)