Linking to a specific address using AS6

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

Hi All

If one is using AS6 without an external make file, what is the method to link a project to an address other than the standard start address?
Eg. link to 0x80000800 rather than 0x80000000, so that the code can be used together with a boot loader.

Regards

Mark

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

I am using a bootloader with 0x8000 length, and I modified the .lds file:

Inside "MEMORY"

 FLASH (rxai!w) : ORIGIN = 0x80008000, LENGTH = 0x00078000

and inside "SECTIONS"

__bootloader_size__ = 0x8000;
...
  PROVIDE (__executable_start = 0x80000000+__bootloader_size__); . = 0x80000000+__bootloader_size__;

But you can modify the numbers directly without using the "__bootloader_size__" variable. And think of removing the trampoline files.

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

Quote:

so that the code can be used together with a boot loader.

You are not writing the app and bootloader as a single entity? Anyway to place an entire program at a different base address use the linker option -Ttext=0x123456 or whatever. If you really intend to have a composite program that is half app and half bootloader then for the bootloader stuff mark the functions as something like:

__attribute__((section(".bootsec"))) void boot_function(void) {
 ...
}

then in the linker options add -Wl,--section-start=.bootsec=0x123456 or whatever.

But it is a very bad idea to mix app and boot. Far better to develop them separately then simply join the resultant .hex files if you want one composite entity to program the chip with. While it is for AVR8 you might want to take a look at the Bootloader FAQ in the AVR8 Tutorial Forum for more on this.

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

Quote:
Anyway to place an entire program at a different base address use the linker option -Ttext=0x123456 or whatever.

I did not know that this is working for AVR32 devices.

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

clawson wrote:
...then in the linker options add -Wl,--section-start=.bootsec=0x123456 or whatever.

But it is a very bad idea to mix app and boot. Far better to develop them separately then simply join the resultant .hex files if you want one composite entity to program the chip with.

Cliff, you may have covered this before, but why is it such a bad idea?

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

Quote:

Cliff, you may have covered this before, but why is it such a bad idea?

If you have any questions after reading the FAQ I co-wrote in Tutorial get back to me.

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

Quote:
I did not know that this is working for AVR32 devices.

I should have put more irony in my statement. Seems Clawson is running in autopilot here.

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

Quote:

Seems Clawson is running in autopilot here.

-Ttext is a generic avr-ld/avr32-ld/arm-ld command. It is simply a shortened form of --section-start=.text=0xnnnn. I take it you are able to read a user manual?

http://sourceware.org/binutils/d...

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

And note it's a GNU ld option, common to all architectures it's ported to.

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

Quote:
-Ttext is a generic avr-ld/avr32-ld/arm-ld command. It is simply a shortened form of --section-start=.text=0xnnnn. I take it you are able to read a user manual?

Ok, you may do it with the linker option, there you are right, and I apologize for not being specific where my concerns really are: I find it dangerous when working with linker files and then using linker options that collides with the linker file settings. And any AVR32 project created with AS6 is using .lds files. In my opinions when dealing with AS6 AVR32 projects, these settings should be made inside the linker file only.

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

Quote:

And any AVR32 project created with AS6 is using .lds files. In my opinions when dealing with AS6 AVR32 projects, these settings should be made inside the linker file only.

avr-gcc (or rather avr-ld) uses .x files for linker scripts but that does not preclude the use of linker options too. Is AVR32 really different in this sense? Sure the linker map may be more complex for AVR32 but if you just want to say "I want the whole thing based at this address" then surely moving the base of .text will work won't it? (in the AVR case this also moves all related sections such as reset jump, interrupt vector table, C run time, the .data initialisers and so on - maybe this is not so simple for AVR32?)

EDIT: well it has an "interesting" effect it runs out. I built an "empty" AVR32 with just main() with nothing in it and got:

Disassembly of section .reset:

80000000 <_start>:
80000000:	48 1f       	lddpc	pc,80000004 <_start+0x4>
80000002:	00 00       	add	r0,r0
80000004:	80 00       	ld.sh	r0,r0[0x0]
80000006:	00 24       	rsub	r4,r0

Disassembly of section .init:

80000008 <_init>:
80000008:	eb cd 40 40 	pushm	r6,lr
8000000c:	48 26       	lddpc	r6,80000014 <_init+0xc>
8000000e:	1e 26       	rsub	r6,pc
80000010:	c0 48       	rjmp	80000018 <_init+0x10>
80000012:	00 00       	add	r0,r0
80000014:	7f ff       	ld.w	pc,pc[0x7c]
80000016:	ff f6 f0 16 	ld.wal	r6,pc[0x58]
8000001a:	00 01       	add	r1,r0
8000001c:	f0 16 00 00 	mcall	r6[0]
80000020:	e3 cd 80 40 	ldm	sp++,r6,pc

Disassembly of section .text:

80000024 <_stext>:
80000024:	30 07       	mov	r7,0
80000026:	49 5a       	lddpc	r10,80000078 <_stext+0x54>
80000028:	5b fa       	cp.w	r10,-1
8000002a:	f4 0d 17 10 	movne	sp,r10



8000010c 
: #include int main(void) { 8000010c: c0 08 rjmp 8000010c
8000010e: d7 03 nop

Using -Ttext=0x80008000 I got:

Disassembly of section .text:

80008000 <_stext>:
80008000:	30 07       	mov	r7,0
80008002:	49 5a       	lddpc	r10,80008054 <_stext+0x54>
80008004:	5b fa       	cp.w	r10,-1
80008006:	f4 0d 17 10 	movne	sp,r10



800080e8 
: #include int main(void) { 800080e8: c0 08 rjmp 800080e8
800080ea: d7 03 nop

So it seems one loses .start and .init by doing this.

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

Quote:
So it seems one loses .start and .init by doing this.

That are the side effects that I was afraid of. Cool, that you found them directly. 8)