Bootloader Confusion - ATmega128

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

The Atmel datasheet says the bootloader section starts at 0xF000 on pg. 286
AVR Studio has a fuse bit to start the boot loader at 0xF000
I've seen several posts here on the site that says 0x1E000

In bootloader.h I have the following line of code:
void bootloader(void) __attribute__ ((section (".bootloader")));

In bootloader.c I have the following function:
void bootloader( void )
{
DDRF = 0xFF;
PORTF = 0x00;

while(1);
}

I'm using JTAG ICE to program and debug so I expect to see bits 0-3 on the STK500 light up and don't care about bits 4-7.

With BOOTSZ = 00 and BOOTRST = 0 (both of the boxes checked) and using the makefile line:
LDFLAGS = -Wl,--section-start=.bootloader=0x1E000 -Wl,-Map=$(TARGET).map,--cref

It works even though the fuse setting says 0xF000 and this places the code at 0x1E000. (can't simulate though, just program with JTAG and unplug it) Does it just "fall through" the unprogrammed space until it gets to valid code?

If I change the makefile line to what I would expect it should be from looking at the datasheet and fuse settings to:
LDFLAGS = -Wl,--section-start=.bootloader=0xF000 -Wl,-Map=$(TARGET).map,--cref

It doesn't work.

I've read that the JTAG ICE can't simulate the bootloader section and that I should place the code in something lower, perhaps 0xC000 and just call the bootloader function (bootrst fuse unchecked) to see if the lights turn on and debug from there. Get the actual function working (have to follow a specific protocol thats already been implemented on the host so a generic bootloader would have to be modified... might as well make my own and learn something instead right?) and then move it back to the proper location.

I would expect the bootloader area of the mega128 to be around 1E000 as thats near the end of the 128k of flash, and the mega64 bootloader to be at F000, as thats near the end of the 64k flash. But why does the datasheet and the AVR Studio seem to say that its at 0xF000 instead?

Compiling with GCC 3.3.1 from AVR Studio 3.56
Programming with JTAG ICE in AVR Studio 4.08 or 3.56
Simulating with JTAG ICE in AVR Studio 4.08
WinAVR 20030913

Can someone explain away my confusion?

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

I just placed my code in the makefile to 0xC000. When I program the target the LEDs turn on as expected. If I run it on the JTAG ICE it shows 0xC000 as unprogrammed space. I knew from reading other posts that you can't simulate in the bootloader section, but I thought that meant in the actual boot loader area of code... not what I DEFINED in the makefile as the bootloader area...

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

Question answered, the fuse is showing word address while the makefile uses byte address.

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

That is correct. The datasheet specifies word addresses. The GNU toolset does everything in byte addresses.

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

I'm having a difficult time with the boot loader, I can't seem to get the interrupts to work. For a while, I thought they were but I think that was because I didn't perform a "clean" after I edited the makefil to move everything to 0x1E000.

LDFLAGS = -Wl,--section-start=.text=0x1E000 -Wl,-Map=$(TARGET).map,--cref
#LDFLAGS = -Wl, -Map=$(TARGET).map,--cref

The first line uncommented does not work. LED0 on the STK500 turns on, but nothing happens. If I use the second line (that is shown as commented) then the light scrolls by in half a second. I need to stay in the bootloader for half a second and then exit if I receive nothing on the UART. I'd also like to use an interrupt driven UART but I've also been unsuccessful in using global variables in the bootloader.

#include 
#include 
#include "main.h"


int main( void )
{	
	DDRA = 0xFF;
	PORTA = ~0x01;
	start_timer0();
	
	sei();
	
	while (1);
	
	return(0);
}

void start_timer0()
{
	TCNT0 = 0x1F;
	TCCR0 = (1<<CS02) | (1<<CS01) | (1<<CS00);
	TIMSK = (1<<TOIE0);	
}

SIGNAL(SIG_OVERFLOW0) 
{
	PORTA = ~((~PINA)<<1);
}

Am I SOL? If worst comes to worst, I'll loop some set amount of times, I'm using a 3.6869 crystal.

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

Boot reset vector is enabled