Downloading an Arduino sketch from Internet to SD card for flashing via the SD card bootloader

With the SD card bootloader ready, I thought I need a mechanism to be able to download firmware from the Internet and save it to the SD card, so that upon the next reset, the Arduino is re-flashed with the newly downloaded sketch. So, I created a basic sketch that does that, it looks up a file called “app.bin” from my site (DNS resolved) and downloads it to the SD card. It is a compiled Arduino sketch that is converted to .bin format with a command like that:

avr-objcopy -I elf32-avr -O binary ledfade9.cpp.elf app.bin

As a to-do remains that I figure a neat way to reset the Arduino after the sketch is downloaded so that the flashing takes place immediately. I lean toward using the hardware watchdog reset, but I need to check the implications on the bootloader as well. Until then, a “dirty” hack maybe used to jump directly to the bootloader address, but this is not elegant solution:

	cli();
	asm volatile("jmp 0x7000");

Note that it is a 4KB bootloader, so hence the 0x7000 address

So the possible use of this sketch is to include it in the “setup” section of the code, so that it check for new firmware over the Internet and re-flashes itself. Combined with the SD bootloader’s capability to use file name of your choice via EEPROM string, it makes a nice add-on.

My code is available on github

Page views: 3922

3 thoughts on “Downloading an Arduino sketch from Internet to SD card for flashing via the SD card bootloader

  1. Hi,
    I am very interested in using this bootloader for a project of my own, did you manage to come up with an elegant solution to the rebooting when the firmware has been downloaded?

  2. Hi,
    that can be done by the following code

    wdt_enable(WDTO_1S); // Set WDT to 1S
    delay(2000); // Wait long enough for the WDT to kick in and reset

    Just make sure the SD card bootloader resets it, this should be in the first few lines of code:

    MCUSR = 0;
    wdt_disable();

  3. Pingback: 2boots bootloader on the uIoT: Serial + MMC bootloader in 2Kb | Martin's corner on the web

Comments are closed.