Bootloader ATtiny2313 in C

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

I made a bootloader for the ATtiny2313. It is written in C. There is only one thing I can't manage to do. I want that the first instruction (so on address 0x00), is jump to bootloader. I wasn't able to do this, so far. My knowledge of Makefiles, linkerscripts etc. is very limited. And as far as I know now, I have to change some things overthere.

What I want:
0x00 rjump to bootloader
0x02 interrupt vector
...... interrupt vector
0x24 interrupt vector
0x26 start of normal program

What I managed to do:
My first thougt was doing this:

void __rjmpBoot (void) __attribute__ ((naked)) __attribute__ ((section (".init0")));

void __rjmpBoot( void )
{
	asm volatile ( "rjmp bootloader");   // jump to bootloader()
}

In the Makefile I set the bootloader address. But what happens, after compiling is on address 0x00 the compiler jumps to the first address after the interrupt vector table (0x26, byte address). On that address, the jump to the bootloader is done. So:

0x00 rjump to 0x26
0x02 interrupt vector
...... interrupt vector
0x24 interrupt vector
0x26 rjump to bootloader
0x28 start of normal program

At the end of the bootloader, the program jumps back to the start of the normal program. This works fine.

To test if the first jump is always the same, I declarde a string wich was store in flash (with PROGMEM). It is stored directly behind the interrupt vector. The first instruction jumped a little further now. So it is depending on something. But I don't know how I can change this.

The example bootloaders of the ATtiny2313 I could find, where in assambly. But writing the complete bootloader in assambly isn't an option.

So my question is, how is it possible to make the first instruction, jumping to the bootloader. Or is there an example how to manage this in C?

I'm using WinAVR 20060125. With avr-gcc version 3.4.5

Hope some could help me, thanks in advance

Thijs

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

The reset vector jumps to the symbol __init which is bound as a weak
symbol to the startup code (in gcrt1.S) to perform all startup-time
initializations.

You can override __init from the linker command-line using the
--defsym option. If you call the linker from the compiler frontend,
prefix it with -Wl:

-Wl,--defsym,__init=

However, keep in mind that the code at then has to perform
all startup-time initialization that would normally be done in .init0.
This most likely requires a piece of assembly code to be located
there. It's best if you have a look at the implementation of gcrt1.S.

Btw.:

void __rjmpBoot( void )

Please don't define symbols starting with two underscores yourself.
They are reserved for the implementation, so there's always a risk
they collide with the library and/or compiler.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

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

Thanks for your quick reply Jörg

It works fine now. I allready realized that there was no initialization done, so I implemented that allready. Thanks for you help and tips.

Thijs