Bootloader section - Kontrollerlab, GCC

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

Hi guys,

I am putting together a bootloader and am having trouble offsetting the address of my .hex file to start at the bootloader section. I have seen a lot of related posts but am still having trouble. I am using Kontrollerlab.

I am aware of the definition...

#define BOOTLOADER_SECTION __attribute__ ((section (".bootloader"))) 

Do I then put the line BOOTLOADER_SECTION at the start of all function declerations? Or just main?

Anyway, for this to work, I understand that the ".bootloader" section needs to be defined.

I have been enjoying the use of Kontrollerlab with Ubuntu, but I cannot find the make file and how configure it.

There is a range of linker options that allows one to set the start of the text, bss, data and heap sections, but I have no idea how to define a new bootloader section.

Does anyone have any ideas how I can configure Kontrollerlab?
or
Is there a method of moving the bootloader to the bootloader section without touching the make file?
or
Can AVRDUDE be used to add an address offset to the input address data?

Any help is much appreciated,

Nick

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

noddy2 wrote:
I am aware of the definition...

#define BOOTLOADER_SECTION __attribute__ ((section (".bootloader"))) 

Do I then put the line BOOTLOADER_SECTION at the start of all function declerations? Or just main?

You put it at the end of every function prototype. Yeah, if you declare the functions in the proper order you don't need prototypes, but just go ahead and do it.

For example, in my bootloader code I have the following prototypes at the beginning of the .c file:

void Monitor(void) __attribute__ ((naked)) BOOTLOADER_SECTION;

void AppDownloadFirmware( void ) BOOTLOADER_SECTION;

void DownloadFirmware( void ) BOOTLOADER_SECTION;

void StartApp( void ) BOOTLOADER_SECTION;

Followed by their actual declarations later:

void Monitor(void)
{
    unsigned char val;
    uint8_t sreg;
    uint8_t badCRC = 0;
    uint8_t wdr = MCUSR & (1<<WDRF);

 . . . and blah, blah, blah . . .

As for KontrollerLab and Ubuntu, I have no experience at all. However, I would look for a file named "Makefile" or "makefile" (or, perhaps, "Makefile.mak"). Also, check KontrollerLab for an "Export Makefile" option, menu pick or button somewhere. Most of these auto-magic environments have it somewhere.

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

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

Just forget about the .bootloader section unless you are using the bootloader section for the purpose of using SPM from an application.

You simply want the .text section moved up to the start of the bootloader address you want. Looking at the screenshots, it appears you simply need to check 'Specify start of text section' and select the needed start address.
http://www.cadmaniac.org/project...

You should end up with the linker option similar to this-
-Wl,-section-start=.text=0x3e00
(where the address is a byte address of the bootloader section start address)

One linker option takes care of everything, and you simply have a 'normal' application that just happens to start at the bootloader section start address. About the only thing that keeps it from being 'totally normal', is if you use the vector table you need to deal with ivsel.

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

Stu and Curt, thanks heaps for your answers.

When I try setting the "Specify start of text section" to anything (even 0x0!) I get a compile error:

/usr/libc/gcc/avr/4.2.2/../.../../../../avr/bin/ld: address 0x8004fa of SMBoot.out section.text is not within text region

Not quite sure what that means. I did find a project.map file with

Memory Configuration

Name             Origin             Length             Attributes
text             0x00000000         0x00020000         xr
data             0x00800060         0x0000ffa0         rw !x
eeprom           0x00810000         0x00010000         rw !x
fuse             0x00820000         0x00000400         rw !x
lock             0x00830000         0x00000400         rw !x
signature        0x00840000         0x00000400         rw !x
*default*        0x00000000         0xffffffff

and some linker information, but this file is generated during build so it can't be used to control anything. Still working on it.

If I do tell the text section to start in a particular place, do the other sections need to start there as well. i.e. I assume the .data section of the bootloader would also have to be in the bootloader section and therefore either automatically come after the .text section or be told explicitly.

Any further ideas, kontrollerlab specific or not, would be much appreciated.

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

Quote:
If I do tell the text section to start in a particular place, do the other sections need to start there as well. i.e. I assume the .data section of the bootloader would also have to be in the bootloader section and therefore either automatically come after the .text section or be told explicitly.
Your ram is always in the same location, whether you are using it from an application or a bootloader. The only data that is related to flash is the initial data values which are loaded from flash at start up. That's taken care of by the linker with the LMA- load memory address for the .data section. There is nothing more to do, other than tell the linker that you want .text starting at your specified address. Everything else just falls into place like it should.

You need to see what options are being passed to the linker (and find out what it takes to control it). What is 'SMBoot'? Looks like you are trying to assign code into the .data section. Or something.

I use avr studio. Its as easy as can be. Configuration options, memory settings, click add, select flash, type .text, type in address, done.

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

So, I was nearly there with my spreadsheet, which basically divided the hex data into the various sections, added the address offset and stuck it all back together. I was just stuffing around trying to get the checksum right.

For about the tenth time I thought "it just can't be this @^%& difficult to offset the $%^&! flash start address by a constant number" and had another fiddle.

Whenever I offset the text in the box where it says "specify start of text section" in the linker options I get an error (Curt, SMBoot is just the name of the project), even when I entered 0 of 0x0.

So I thought WTF and just cut and pasted Curt's -Wl,-section-start=.text=0xf000 into the 'linker command' text field, next to 'avr-gcc' and it just worked.

So thanks Curt, for suggesting that linker option. Knowing what to do with it was the only bit that was missing.

I'm still having a great time using Kontrollerlab and really appreciate the work the authors have put in. With some documentation (a handbook would be fantastic) it could only get better.

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

Just for future reference:

-Wl,-Ttext=0xf000

is simply a shorter way to type:

-Wl,-section-start=.text=0xf000

(basically because the need to rebase .text occurs so often - there's also: -TData to rebase the .data)