Skip to content

Commit

Permalink
activate dead code removal, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
zevero committed Aug 8, 2015
1 parent 1fe57f1 commit 81d42f4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@
MCU_TARGET = atmega1284p # Target device to be used (32K or lager)
BOOT_ADR = 0x1F000 # Boot loader start address [byte] NOT [word] as in http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega1284p
F_CPU = 16000000 # CPU clock frequency [Hz]
USE_LED = 0 # Define two leds in asmfunc.S (mainly for debug!!!)
USE_UART = 16 # Debug on Serial. 0 ... deactivate or divider of http://wormfood.net/avrbaudcalc.php for baud rate!
# !!!Enable uart/uart.c or uncomment to save 382 bytes !!!
USE_LED = 0 # Debug with two (defined in asmfunc.S)
USE_UART = 1 # Debug on Serial. 0 ... deactivate or divider of http://wormfood.net/avrbaudcalc.php for baud rate!
#------------------------------------------------------------------
CSRC = main.c pff/src/pff.c diskio.c uart/uart.c #Please help to make this conditional on USE_UART
CSRC = main.c pff/src/pff.c diskio.c uart/uart.c #uart/uart.c is taken out by --gc,sections is USE_UART = 0

TARGET = avr_boot
ASRC = asmfunc.S
OPTIMIZE = -Os -mcall-prologues
OPTIMIZE = -Os -mcall-prologues -ffunction-sections -fdata-sections
DEFS = -DBOOT_ADR=$(BOOT_ADR) -DF_CPU=$(F_CPU) -DUSE_LED=$(USE_LED) -DUSE_UART=$(USE_UART)
LIBS =
DEBUG = dwarf-2

ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs $(DEFS)
ALL_ASFLAGS = -mmcu=$(MCU_TARGET) -I. -x assembler-with-cpp $(ASFLAGS)
CFLAGS = -g$(DEBUG) -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -std=c99 $(DEFS)
LDFLAGS = -Wl,-Map,$(TARGET).map -Wl,--section-start,.text=$(BOOT_ADR)
LDFLAGS = -Wl,-Map,$(TARGET).map -Wl,--gc-sections -Wl,--section-start,.text=$(BOOT_ADR)
OBJ = $(CSRC:.c=.o) $(ASRC:.S=.o)

CC = avr-gcc
Expand All @@ -31,7 +30,7 @@ OBJDUMP = avr-objdump
SIZE = avr-size


all: $(TARGET).elf lst text bin size
all: clean $(TARGET).elf lst text bin size

$(TARGET).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
Expand Down
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,47 @@ SD card Bootloader for atmega processors

As easy as it can get! I spent days with this. Hopefully you wont!

- for any ATMega with SD Card
- Petit FatFs R0.03 for FAT16 && FAT32
- 4096kB Bootloader required
- CRC Check or EEprom can be easily added - look into main.c

...*BUT* I prefere to keep things simple. Instead of an elaborate versioning systems avr_boot checks on one filename and will reflash as long as it finds this filename. This is not a problem since, it happens nearly instantly and only differing bytes are flashed.
You may put the logic as well into the application (which you want to distribute) and delete or rename the firmware file.

- for any ATMega with 4096kb Bootloader
- uses Petit FatFs R0.03 for FAT16 && FAT32
- looks for FIRMWARE.BIN and flashes it nearly instantly
- without any interference to your application
- simple check before starting your application or retry every 5 seconds
- no CRC Check and no version bytes in EEPROM (see More...)

# Usage

This is with avr-gcc and avrdude under linux with an Atmega1284p! Adaption to your case (WinAvr) will not be too complicated...

- adapt Makefile
- MCU_TARGET: Your AtmegaXXX (maybe not relevant?)
- BOOT_ADR: in bytes not words.
- BOOT_ADR: in bytes not words!
- F_CPU: CPU Frequency
- USE_LED: For debugging 0...deactivate or 1...active
- USE_UART: For debugging 0...deactivate or divider for baudate see http://wormfood.net/avrbaudcalc.php
- USE_UART: For debugging 0...deactivate or divider for baudate see http://wormfood.net/avrbaudcalc.php
- adapt pins in asmfunc.S
- adapt pff/src/pffconfh.h
- adapt filename of firmware (now FIRMWARE.BIN) in main.c
- make clean
- make
- set fuses: avrdude -c avrispmkII -p m1284p -U hfuse:w:0xda:m
- find high fuse in http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega1284p
- find high fuse in http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega1284p
- flash: avrdude -c avrispmkII -p m1284p -Uflash:w:./avr_boot.hex:i -Ulock:w:0x3F:m
- get your app.cpp.hex (out of /tmp/buildxxx in case of Arduino IDE)
- make bin file: avr-objcopy -I ihex -O binary app.cpp.hex FIRMWARE.BIN
- copy the file into the root of an SD (FAT12/FAT16/FAT32)
- it might already have happen!. Flashing is nearly instantly (unless USE_LED=1)
- put it into the SD slot of your Atmega
- reset it
- it might already have happend!

# Bootloader size
- 3540 bytes
- 3852 bytes debugging with USE_LED
- 3934 bytes debugging with USE_UART
- 4240 bytes debugging with USE_LED and USE_UART (does not fit in 4096)

# More ...
... if you wish you *can* add CRC Check or versioning with EEPROM *but* I prefere to keep things simple. avr_boot will reflash your FIRMWARE.BIN as long as it is present.
Is this a problem? No! It happens nearly instantly and only differing bytes are flashed really.
You may consider putting your logic into your application and perform a CRC Check after the fact to inform the user and deleting or renaming FIRMWARE.BIN

# Thanks to
- http://elm-chan.org/fsw/ff/00index_p.html
Expand Down

0 comments on commit 81d42f4

Please sign in to comment.