[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] move assembler bootloader code to end of flash
From: |
Bernhard Kuemel |
Subject: |
[avr-gcc-list] move assembler bootloader code to end of flash |
Date: |
Thu, 08 Sep 2011 23:26:07 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20110818 Icedove/3.0.11 |
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 is not
moved up, or it's missing in the .hex file while it shows up fine in the
.lst file.
Using '.org 0x3000,0xff' moves 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 gets quite big with the many 0xff bytes which makes
uploading it to the uC longer.
Can someone please show me with the attached dummy code how to do it?
Working example code would be good, too.
Thanks, Bernhard
unmangled files are in the attached test.tar.bz2
=============== test.S ===========================
#include <avr/io.h>
;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
.fill 10,1,0x55
.section .bootloader,"ax",@progbits
.global main
;put this dummy bootloader code to 0x3000
main:
nop
jmp main1
.fill 10,1,0xAA ;this is a marker to see if the bootloader is there
================== 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
#override LDFLAGS = -Wl,-Map,$(PRG).map -Wl,--undefined=_bootloader
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
all: $(PRG).elf lst text eeprom
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
# dependency:
#demo.o: demo.c iocompat.h
clean:
rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak
rm -rf *.lst *.map $(EXTRA_CLEAN_FILES)
lst: $(PRG).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
# Rules for building the .text rom images
text: hex bin srec
hex: $(PRG).hex
bin: $(PRG).bin
srec: $(PRG).srec
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
# Rules for building the .eeprom rom images
eeprom: ehex ebin esrec
ehex: $(PRG)_eeprom.hex
ebin: $(PRG)_eeprom.bin
esrec: $(PRG)_eeprom.srec
%_eeprom.hex: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ \
|| { echo empty $@ not generated; exit 0; }
%_eeprom.srec: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@ \
|| { echo empty $@ not generated; exit 0; }
%_eeprom.bin: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary
$< $@ \
|| { echo empty $@ not generated; exit 0; }
# Every thing below here is used by avr-libc's build system and can be
ignored
# by the casual user.
FIG2DEV = fig2dev
EXTRA_CLEAN_FILES = *.hex *.bin *.srec
dox: eps png pdf
eps: $(PRG).eps
png: $(PRG).png
pdf: $(PRG).pdf
%.eps: %.fig
$(FIG2DEV) -L eps $< $@
%.pdf: %.fig
$(FIG2DEV) -L pdf $< $@
%.png: %.fig
$(FIG2DEV) -L png $< $@
test.tar.bz2
Description: application/bzip
- [avr-gcc-list] move assembler bootloader code to end of flash,
Bernhard Kuemel <=