Adding bootloader code to Xmega32a4u in AVR Studio 7

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

Hi, we are trying to add the code below to the project and locate it at 0x8000-0x8fff which is where the Bootloader resides. Thius works fine in Imagecraft but we cannot find any AVR Studio help file.

 

The line below does not locate the table below to the bootloader sectiobn which is defined in the Linker as .BOOT. Any help would be much appreciated. Thanks

__attribute__ ((section (".BOOT")))

 

const BYTE bldx[4096] = {

 

0x00,0xC0,0x00,0x91,0x78,0x00,0x05,0xFD,0x6A,0xC0,0xF0,0x92,0x80,0x06,0x08,0xE1, //0x800f

0x00,0x93,0x90,0x06,0x0F,0xEF,0x0A,0x95,0x00,0x23,0xE9,0xF7,0x00,0x91,0x88,0x06,

0x00,0xFF,0xEC,0xC0,0xE0,0xE0,0xF0,0xE0,0x07,0x91,0x16,0x91,0x0F,0x3F,0x19,0xF4,

Electronic System Design
http://www.esdn.com.au

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

What you have done there is just half the solution so far.

 

At present it puts "bldx" in a section called ".BOOT" but now you need something to then tell the linker where ".BOOT" should reside in flash.

 

You can modify the linker script but a simpler "over-ride" is simply to add the link option:

-Wl,-section-start=.BOOT=0x8000

That should do it.

 

HOWEVER you may face issues with -fdata-sections and -gc-sections. The latter is going to "notice" that nothing else in the code makes reference to ".BOOT" so in the .map file you may find that .BOOT is listed in the "discarded sections". If that happens try changing:

__attribute__ ((section (".BOOT")))

to be:

__attribute__ ((section (".BOOT"), used))

And if that doesn't work either you may need to use a linker option (think it is '-u') to tell it that it should consider the symbol "bldx" to be used.

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

Thanks Clawson. I will try this.

 

With the linker options, this was already defined by default.

-Wl,-section-start=.BOOT=0x8000

The map file shows this:

 .rodata.bldx   0x00000000     0x1000 src/epm_bootload.o

 

The used did not seem to make any difference.

 

The -u option changed the linker options to 

-Wl,--relax -Wl,--section-start=.BOOT=0x8000 -u

but this now gives an error of 

 

Error missing argument to '-u' EPM avr-gcc.exe 0

 

Electronic System Design
http://www.esdn.com.au

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

You aren't using -u right. See the linker manual:

 

https://gcc.gnu.org/onlinedocs/g...

 

So "-Wl,-u bldx"

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

Thanks Clawson, tried that but there is still some issue:

 

Severity Code Description Project File Line

Error bldx: No such file or directory EPM avr-gcc.exe 0

 

Here are the linker options, thanks

-Wl,--relax -Wl,--section-start=.BOOT=0x8000, -Wl,-u bldx

Electronic System Design
http://www.esdn.com.au

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

OK so I took this:

#include <stdint.h>

typedef uint8_t BYTE;

__attribute__ ((section (".BOOT")))
const BYTE bldx[4096] = {
0x00,0xC0,0x00,0x91,0x78,0x00,0x05,0xFD,0x6A,0xC0,0xF0,0x92,0x80,0x06,0x08,0xE1, //0x800f
0x00,0x93,0x90,0x06,0x0F,0xEF,0x0A,0x95,0x00,0x23,0xE9,0xF7,0x00,0x91,0x88,0x06,
0x00,0xFF,0xEC,0xC0,0xE0,0xE0,0xF0,0xE0,0x07,0x91,0x16,0x91,0x0F,0x3F,0x19,0xF4 
};

int main(void) {
}

built it like this:

C:\SysGCC\avr\bin>avr-gcc -mmcu=atmega64 -fdata-sections -Wl,-gc-sections -Wl,--relax -Wl,--section-start=.BOOT=0x8000, -Wl,-u,bldx -Wl,-Map,avr.map avr.c -o avr.elf

C:\SysGCC\avr\bin>

and ended up with this in the .map file:

.BOOT           0x00008000     0x1000
 .BOOT          0x00008000     0x1000 C:\Users\xyz\AppData\Local\Temp\ccAF7cml.o
                0x00008000                bldx

and if I run objcopy to get a .hex file I find:

C:\SysGCC\avr\bin>avr-objcopy -O ihex -j .text -j .BOOT avr.elf avr.hex

C:\SysGCC\avr\bin>type avr.hex
:1000000045C000004BC0000049C0000047C00000D0
:1000100045C0000043C0000041C000003FC00000D8
:100020003DC000003BC0000039C0000037C00000E8
:1000300035C0000033C0000031C000002FC00000F8
:100040002DC000002BC0000029C0000027C0000008
:1000500025C0000023C0000021C000001FC0000018
:100060001DC000001BC0000019C0000017C0000028
:1000700015C0000013C0000011C000000FC0000038
:100080000DC000000BC0000009C0000011241FBEFD
:10009000CFEFD0E1DEBFCDBF02D00AC0B1CFCF934A
:1000A000DF93CDB7DEB780E090E0DF91CF91089588
:0400B000F894FFCFF2
:1080000000C00091780005FD6AC0F092800608E18A
:10801000009390060FEF0A950023E9F70091880678
:1080200000FFECC0E0E0F0E0079116910F3F19F47B
:108030000000000000000000000000000000000040
:108040000000000000000000000000000000000030
:108050000000000000000000000000000000000020

That certainly seems to have put the "program" at 0x0000 and the desired data from 0x8000 onwards.

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

Thanks clawson. This looks good if only I could make it work.  I tried this and got some bizarre errors which mean nothing to me.

 

Anyway, I played around a bit more and added the code below to the main() routine and this now seems to compile the extra code in. Note that it is not enough just to add a local variable i and declare i=bldx[0] since this then gets optimized out. I will try this next week when back in the office. Thanks again for your help.

 

usb_rx = bldx[0]; // note usb-rx is a variable used elsewhere 

Electronic System Design
http://www.esdn.com.au

Last Edited: Sat. Feb 3, 2018 - 11:03 AM