Flash string at specific location

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

I am working with a bootloader that requires "RCM" to be in the code space byte address 0x26.

In C, I can do:
const char bootstring[] PROGMEM = "RCM";
But how do I specify the absolute location?

With IAR, I used assembler:
ASEG CODE
ORG 0x0026
DB "RCM"

For the GCC assembler, tried
.org 0x0026
.db "RCM"

But it doesn't like ".db".

Please help.

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

Which AVR is this? Surely 0x0026 is somewhere in the middle of the vector table?

But generally to place data you used "named sections" (see the manual) and then the --section-start positions it to an absolute address but aiming for 0x0026 you are going to get a clash with the linker - usually you can only place things absolutely in the free space beyond the app.

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

clawson wrote:
Which AVR is this? Surely 0x0026 is somewhere in the middle of the vector table?
I would assume that it is right after the vector table (e.g. true for Mega8).
Otherwise his C-version wouldn't work. ;-)

Stefan Ernst

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

You are right, it is a Mega 8. I have done this with IAR and I assumed or hoped it was possible with GCC.

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

In that case if you simply put it into PROGMEM the linker should locate it directly after the vectors.

#include 
#include 


char Temp [] PROGMEM = "RMC";

int main(void) { 
	while(1);
}

built for mega8 yields:

  20:	0c c0       	rjmp	.+24     	; 0x3a <__bad_interrupt>
  22:	0b c0       	rjmp	.+22     	; 0x3a <__bad_interrupt>
  24:	0a c0       	rjmp	.+20     	; 0x3a <__bad_interrupt>

00000026 :
  26:	52 4d 43 00                                         RMC.

0000002a <__ctors_end>:
  2a:	11 24       	eor	r1, r1
  2c:	1f be       	out	0x3f, r1	; 63

with the text positioned after the vectors but before the code start.

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

clawson wrote:
In that case if you simply put it into PROGMEM the linker should locate it directly after the vectors.
...
with the text positioned after the vectors but before the code start.

You'll need to ensure that it is the first PROGMEM object that the linker sees, in order to guarantee the location.

I'm guessing it could be done, using named sections, and a custom linker script.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

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

glitch wrote:
I'm guessing it could be done, using named sections, and a custom linker script.
It might be a good idea to leave the default linker script alone and only "amend" it by a short piece of script. The newest ld offers an undocumented AFTER keyword in the command-line "attachment" linker "stub" to control positioning of user-defined sections - example of usage here.

JW

PS. Oh yes, the default library startup code including the vectors could be overridden with a custom-written one, too.