Flashing a sketch from SD card using 2boot bootloader

Sure i try TO upload a bin file, not an hex .

I thought that this bootloader does not read filename from eprom but it is already made fixed to app.bin.
I need to see deep the code...

Little update:

i've let it working flashing directly this hex file for bootloader : http://baldwisdom.com/data/ArduinoEthernetSDBoot.hex

In wich is different from the code on github?

Thanks again osbock.

Hi, I am very interested in this project and I would like to get involved. In addition make it compatible with the 2560. Can someone tell me where it currently stands what the latest builds are etc?

I am using a 2560v running at 8Mhz so the whole board is running at 3.3v so I have no level shifter. The SD card is connected directly to the SPI lines.

My board is one of these with an W5200 Ethernet module attached. (Same way as the W5100)

Over a year ago there was interest in a very small SD read program as the base for a boot loader. I wrote the attached program which may be useful.

It is FAT16 only for standard (2GB or less) SD cards.

I estimate the size is about 1200 bytes.

It has two functions

bool fileOpen(uint8_t* dirName);
int fileRead();

dirName is the filename in directory format, 11 bytes with blank fill like this.

  // open TEST.BIN
  if (!fileOpen((uint8_t*)"TEST    BIN")) {
    // open failed
  }

fileRead() reads a single byte or returns -1 for error or EOF.

The programs are packaged as a library. Try the examples.

You must be logged in to download the attached zip file.

SdBoot20130403.zip (8.46 KB)

My goal is to place a sketch on the SD Card and run program that sketch to the chip itself or run the sketch off the chip. travelvietnam I am using pin 53 as chip select for the SD

hello everyone,
i'm trying to do something similar to this by uploading a sketch from an external memory.
my goal is to rewrite the bootloader that started in this post, with osbock, and make it first compile under atmel studio (i hade to change some global variables to constants...).

finally i've succeeded compiling that bootloader under atmel studio and now i have a few quwstions please:

  1. this bootloader can't upload .hex file at all and specifically from the arduino ide, correct? if so why not?

  2. if i want that bootloader to upload only sketches with the correct name (app.bin or lets say app.hex) will it check for changes? on restart and program the sketch only if it's new? if not why?

  3. if i won't to do the same thing but from external flash chip, on a breadboard and make the bootloader check whether there is a "new" file on the uSD or ext. Flash, what changes are needed? any reference?

  4. what are the correct numbers for this bootloader on arduino mega 2560 with sparkfun micro-sd shield (not eth') (speed, legs CS etc, memory addresses... etc)

thank you,
snir.

hello, where is the current stand of this project?

I think the project has somewhat stalled. I have tried to message the original contributors with no results. :frowning:

What a pity this has stalled. Just what I was looking for :frowning:

GregM:
What a pity this has stalled. Just what I was looking for :frowning:

I think, it was stalled, but then i found this.
The thread owner has found a way to make it work.

His changes are on his own github repository...

Hi, I am serching for some info about this quite a long time. And still I am not sure which project is actualy working or how to use it. Could somebody help me, give me some clues and summarize the situation. thx

Hi,

because of the problems (only FAT16 and endless loop with FAT32 sd card in on boot) with the 2boots bootloader, i switched to the avr_boot. (GitHub - osbock/avr_boot: SD card Bootloader for atmega processors)
I have made some changes for my project.
The main differences between 2boot and avr_boot:

  • booting only from sd card. No serial option
  • booting from SDHC possible, FAT32 and FAT16
  • much bigger, about 4kb...
  • no support for hex file, you need to convert the hex file into a binary file

my changes: (you can find it in OpenSeaMapLogger/bootloader/avr_boot-master at master · willie68/OpenSeaMapLogger · GitHub)

  • desired platform ATMega328P with attached SD Card standard connection (MOSI, MISO...)
  • names of firmware files will be OSMFWxxx.BIN, will be programmed, if xxx > EEPROM-Version number. If no EEPROM Version number is present 12 is the magic number. if not, file will be ignored. The next version must be within 10 version numbers. (Files will be testet from EEPROM Version + 10 down to EEPROM Version + 1) if nothing is found at last a file name OSMFIRMW.BIN will be testet and programmed, if present.
  • In the firmware setup routine the actual version is written into the EEPROM.
  • a small java program helps to convert the hex file to a bin file.

Hello forum,

I finally managed to write the bootloader to my atmega 328p (with some help of a friend to compile it) and ran into the next problem. what format the file on the sd card must have? what must i do with the .ino file to make the thing work.

Thanks in advance for your answers, Michael

Which bootloader?
Some prefer hex files (which the arduino IDE already generate, look into the build folder in the temp folder.), my avr_boot needs a binary file, so i must convert the hex file into a binary version...

Hi all,

just a short message to thanks everybody that contribute to release avr_boot.

After a long time and many tries, I find the right flow to be able to burn the new boot loader on an atmega328p dip28 and load the blink example project into the avr from a 512Mo SD card:

  • get the github from
    OpenSeaMapLogger/bootloader/avr_boot-master at master · willie68/OpenSeaMapLogger · GitHub

  • check your hardware SD <-> Arduino with avr_boot-master/asmfunc.S

  • make

  • burn fuse
    avrdude -p atmega328p -c usbasp -P usb -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xd8:m -Ulfuse:w:0xff:m

  • burn boot loader
    avrdude -p atmega328p -c usbasp -P usb -U flash:w:avr_boot-master/avr_boot.hex:i -Ulock:w:0x0F:m

  • compile blink project

  • find the compiled file
    find $TMPDIR -name Blink.cpp.elf

  • convert hex to binary
    avr-objcopy -O binary Blink.cpp.elf OSMFIRMW.BIN

  • plug the SD card and wait the reboot (it may take long time)

garfield38:
...

After a long time and many tries, I find the right flow to be able to burn the new boot loader on an atmega328p dip28 and load the blink example project into the avr from a 512Mo SD card:

  • get the github from
    OpenSeaMapLogger/bootloader/avr_boot-master at master · willie68/OpenSeaMapLogger · GitHub

  • check your hardware SD <-> Arduino with avr_boot-master/asmfunc.S

  • make

  • burn fuse
    avrdude -p atmega328p -c usbasp -P usb -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xd8:m -Ulfuse:w:0xff:m

  • burn boot loader
    avrdude -p atmega328p -c usbasp -P usb -U flash:w:avr_boot-master/avr_boot.hex:i -Ulock:w:0x0F:m

  • compile blink project

  • find the compiled file
    find $TMPDIR -name Blink.cpp.elf

  • convert hex to binary
    avr-objcopy -O binary Blink.cpp.elf OSMFIRMW.BIN

  • plug the SD card and wait the reboot (it may take long time)

Hello,

I would like to be able to load the blink example from microSD card.

I have an Arduino Uno. I downloaded avr_boot.hex from repository and added a configuration in the board.txt file with a program called "board.txt Editor".

My configuration is:
uno___2.name=Arduino SD
uno___2.build.mcu=atmega328p
uno___2.build.f_cpu=16000000L
uno___2.build.core=arduino
uno___2.build.variant=standard
uno___2.upload.protocol=arduino
uno___2.upload.maximum_size=32256
uno___2.upload.speed=115200
uno___2.bootloader.low_fuses=0xff
uno___2.bootloader.high_fuses=0xd8
uno___2.bootloader.extended_fuses=0x05
uno___2.bootloader.path=bootsd
uno___2.bootloader.file=avr_boot.hex
uno___2.bootloader.unlock_bits=0x3F
uno___2.bootloader.lock_bits=0x0F

I have a 2 GB microSD with FAT16 and Ethernet-SD board. I generated blink.cpp.elf in Windows, generated the OSMFIRMW.BIN with avr-objcopy command and added the OSMFIRMW.BIN file in root folder.

I couldn't load the blink example from microSD. Do I need to buy a SD card? What thing did I do wrong?

Thank you

Howdy,

First off, thank you for the effort you've put into this. I'm following your instructions, and I want to check my work before I get too far along.

When I get to step 3, make, I get this error:

$ make 
avr-gcc -gdwarf-2 -Wall -Os -mcall-prologues -mmcu=atmega328p -DBOOT_ADR=0x7000 -DF_CPU=16000000   -c -o main.o main.c
main.c:58:19: warning: ‘mem_cmpP’ declared ‘static’ but never defined [-Wunused-function]
 static inline int mem_cmpP(const void* dst, const void* src, int cnt);
                   ^
main.c:65:16: warning: ‘pagecmp’ defined but not used [-Wunused-function]
 static uint8_t pagecmp(uint16_t addr, uint8_t *data)
                ^
avr-gcc -gdwarf-2 -Wall -Os -mcall-prologues -mmcu=atmega328p -DBOOT_ADR=0x7000 -DF_CPU=16000000   -c -o pff.o pff.c
pff.c: In function ‘get_fat’:
pff.c:384:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   return LD_WORD(buf);
   ^
pff.c:388:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   return LD_DWORD(buf) & 0x0FFFFFFF;
   ^
pff.c: In function ‘pf_mount’:
pff.c:757:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     bsect = LD_DWORD(&buf[8]); /* Partition offset in LBA */
     ^
avr-gcc -gdwarf-2 -Wall -Os -mcall-prologues -mmcu=atmega328p -DBOOT_ADR=0x7000 -DF_CPU=16000000   -c -o mmc.o mmc.c
avr-gcc -c -mmcu=atmega328p -I. -x assembler-with-cpp -Wa,-adhlns=asmfunc.lst,-gstabs -DBOOT_ADR=0x7000 -DF_CPU=16000000 asmfunc.S -o asmfunc.o
avr-gcc -gdwarf-2 -Wall -Os -mcall-prologues -mmcu=atmega328p -DBOOT_ADR=0x7000 -DF_CPU=16000000 -Wl,-Map,avr_boot.map -Wl,--section-start,.text=0x7000 -o avr_boot.elf main.o pff.o mmc.o asmfunc.o 
avr-objdump -h -S avr_boot.elf > avr_boot.lst
avr-objcopy -j .text -j .data -j .fuse -O ihex avr_boot.elf avr_boot.hex
avr-size -C --mcu=atmega328p avr_boot.elf
avr-size: invalid option -- C
Usage: avr-size [option(s)] [file(s)]
 Displays the sizes of sections inside binary files
 If no input file(s) are specified, a.out is assumed
 The options are:
  -A|-B     --format={sysv|berkeley}  Select output style (default is berkeley)
  -o|-d|-x  --radix={8|10|16}         Display numbers in octal, decimal or hex
  -t        --totals                  Display the total sizes (Berkeley only)
            --common                  Display total size for *COM* syms
            --target=<bfdname>        Set the binary file format
            @<file>                   Read options from <file>
  -h        --help                    Display this information
  -v        --version                 Display the program's version

avr-size: supported targets: elf32-avr elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex
make: *** [size] Error 1

Seems to compile, but I don't know how critical the avr-size output is, and if this error keeps any further steps from occurring. Running it by hand looks like this:

$ avr-size avr_boot.elf
   text   data    bss    dec    hex filename
   3932     26    173   4131   1023 avr_boot.elf

There is a avr_boot.hex, but at 11,174 bytes, it seems too big to me.

Am I on track here, or did I hose something?

-Chris

garfield38:
Hi all,

just a short message to thanks everybody that contribute to release avr_boot.

After a long time and many tries, I find the right flow to be able to burn the new boot loader on an atmega328p dip28 and load the blink example project into the avr from a 512Mo SD card:

  • get the github from
    OpenSeaMapLogger/bootloader/avr_boot-master at master · willie68/OpenSeaMapLogger · GitHub

  • check your hardware SD <-> Arduino with avr_boot-master/asmfunc.S

  • make

  • burn fuse
    avrdude -p atmega328p -c usbasp -P usb -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xd8:m -Ulfuse:w:0xff:m

  • burn boot loader
    avrdude -p atmega328p -c usbasp -P usb -U flash:w:avr_boot-master/avr_boot.hex:i -Ulock:w:0x0F:m

  • compile blink project

  • find the compiled file
    find $TMPDIR -name Blink.cpp.elf

  • convert hex to binary
    avr-objcopy -O binary Blink.cpp.elf OSMFIRMW.BIN

  • plug the SD card and wait the reboot (it may take long time)

willie1968:
I think, it was stalled, but then i found this.
The thread owner has found a way to make it work.
http://harizanov.com/2013/01/2boots-bootloader-on-the-uiot-serial-mmc-bootloader-in-2kb/
His changes are on his own github repository...

that is exactly what myself and many others here would find useful but unfortunately his only compiled version was for a rather queer 6mhz clock (what goes through these guys heads?). most need something for 16mhz uno/promini. i tried:

maybe that is one of the earlier non-functional versions. using 1gb fat16 sd with "BLINK3.HEX" file and running NameBoardSketch.pde altered for "BLINK3" but the sketch dont load. has anybody ever got this to run on a regular m328 ardunio?

it is surprising such a highly prized capability as loading from sd is not part of mainstream arduino.