move assembler bootloader code to end of flash

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

Hi!

I'm trying to modify and port Kasper Pedersens assembler bootloader tinyloader to gnu avr-gcc.

I'm stuck with moving the code to the end of flash. I read about .section statements and --section-start linker arguments (in the makefile), but I just can't figure it out. Either the section it's not moved up, or it's missing in the .hex file while it shows up correctly in the .lst file.

Using '.org 0x3000' got the code up to 0x3080 which looks good (I can subtract 0x80), but there was some exit code after the boot loader. Also the hex file contained lots of 0 bytes in between which would make uploading it to the uC longer and strain the flash more than necessary.

Can someone please show me with the attached dummy code how to do it?

Other example code would be good, too, but please only for gnu avr-gcc.

Thanks, Bernhard

-----------------------------------------

Attached are the dummy source file and the Makefile.

Here's the assembler dummy code with some statements commented as I was trying to see what works and what not.

#include 

;       .section .text
        
;dummy main program
main1:
        ldi     r16,0xff
        OUT     _SFR_IO_ADDR(DDRD),r16
loop:
        adiw    r24,1
        out     _SFR_IO_ADDR(PORTD),r25
        jmp     loop

;       .end



;       .section .bootloader,"ax",@progbits
        .global main
;put this dummy bootloader code to 0x3000
.org 0x3000
main:
        lds     r24,0x5555
        nop
        jmp     main1

        .end

-------------------------------------

An excerpt from the Makefile.

PRG            = test
OBJ            = $(PRG).o
MCU_TARGET     = atmega168
OPTIMIZE       = -O0

DEFS           = -Wl,--section-start=.bootloader=0x3000
LIBS           =

# You should not have to change anything below here.

CC             = avr-gcc

# Override is only needed by avr-lib build system.

override CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
override CPPFLAGS      = -mmcu=$(MCU_TARGET)
override LDFLAGS       = -Wl,-Map,$(PRG).map

OBJCOPY        = avr-objcopy
OBJDUMP        = avr-objdump

all: $(PRG).elf lst text eeprom

$(PRG).elf: $(OBJ)
        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

Attachment(s): 

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

I am not expert in this but maybe the folowing code will do what you want.
I have added "-nostartfiles" to linker options so as to eliminate the .org offset.
I have used Avrstudio-gcc without external makefile.

#include 

.section .text
.org 0       
;dummy main program
main1:
        ldi     r16,0xff
        OUT     _SFR_IO_ADDR(DDRD),r16
loop:
        adiw    r24,1
        out     _SFR_IO_ADDR(PORTD),r25
        jmp     loop  ; (adr 0x0b here)

;       fill adr 0x0c - 0x2fff with value 0xff
.fill  0x3000-0x0c, 1 , 0xff

;       put this dummy bootloader code to 0x3000
.global main
main:
.org 0x3000

        nop
        jmp     main1

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

Ok, I found it in the archives of the avr-gcc mailing list: I have to add the .bootloader section to objcopy:

%.hex: %.elf
        $(OBJCOPY) -j .text -j .data -j .bootloader -O ihex $< $@

Filling the gap with 0xff saves the flash a write cycle, but still takes time as avrdude doesn't yet skip the gap between sections.

Complete exmple code attached.

Attachment(s):