problem using bootloader section

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

Below I've posted some example C code I'm using to test using the booloader section of an ATmega128. When I compile and link the code without the "section" attribute it works just fine. However, when I compile and link using the "section" attribute to mark regions of the code to be placed in bootloader area of the flash it doesn't do anything at all. I've tried several version of the test code that don't use the USART(eg, flashing LEDs) and they behave similarly. I can't simulate bootloader code using AVRStudio.

Can anyone please offer me advice on what I'm doing wrong? I believe my fuses are programmed correctly: BOOTSZ = '00' and BOOTRST = '0'. I am also using version 3.3.2 of avr-gcc.

Source code:

#include 
#include 
#include 
#include 
 
void boot_test(void) __attribute__ ((section (".bootloader")));

static inline void uart_init() 
{
	/* 9600 baud @ 3.69 MHz*/
	UBRR0H = 0;
	UBRR0L = 23;
	UCSR0C = 0x06; /* 8 Bit */
	UCSR0B = _BV(RXEN) | _BV(TXEN);
}

static inline int putchar(unsigned char ch)
{ 	
	while ( !(UCSR0A & (1<<UDRE)) );
	UDR0 = ch; 		
	return 0;
}

static inline unsigned char getchar(void)
{
	while ( !(UCSR0A & (1<<RXC)) );
	return UDR0;
}

/**
 * boot_test -- dummy bootloader test function
 */
void boot_test(void)
{
	putchar('a');
}


/**
 * main -- 
 */
int main (void)
{
    uart_init();
    boot_test();
	
    while (1);

    return 1;
}

Linker flags:

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

Cheers.

--
sheldona

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

AVR Studio will not simulate code that is not in the .text section so debugging bootloaders can be problematic. I have debugged bootloader code on a M128 successfully using the second UART to output debug info.

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

Here is another trick.

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

take out __attribute__ ((section (".bootloader"))); This way everything is in the .text section which starts at 1E000

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

eejay,

thanks a bunch! I tried that and it works just great. Even though I had all my code flagged for the bootloader section of the flash there must've been some library code being thrown into other parts of the flash. Using the ".text" section tag instead of ".bootloader" worked much better.

Cheers.

--
sheldona