The boot-cloner is a program compiled and burnt with the Arduino IDE, that copies part of it's flash memory onto another microcontroller. The bootloader can be written to a new microcontroller by the Arduino, instead of burning the bootloader onto new ATmega8's with a separate device.
If you're like me, then you need more than one microcontroller, so you can put the IC into a circuit and leave it there permanently. Unfortunately, burning multiple bootloaders can be a very involved, time consuming process. The cloner will help you get dozens of new ATmega8's ready to use, in seconds. The program gives you access to an implementation of the ISP protocol and declaring and using tables stored in program flash, which don't occupy ram.
Notes:
In-System Programming (ISP) is a protocol developed by Atmel to be used as the primary means of programming their microcontrollers. The three wire serial protocol can be used to write the fuse bits, program memory and eeprom. It's a bit of a language by itself, and varys slightly from one microcontroller to another - mostly by chip architecture differences. (i.e. flash/eeprom size and fuse bit features) While holding the RESET pin of the microcontroller at a low level, the first command issued through ISP is called program enable. After those special 32 bits are sent, the microcontroller begins communicating. There's several commands that can be issued after program enable, which are sent serially at any rate: reading the flash memory, writing the flash memory page-by-page, erasing the flash memory, reading/writing the fuse bits or eeprom, reading device codes and more.
In the Boot-Cloner sketch is an implementation of the ISP protocol for an ATmega8, complete with functions that encapsulate the protocol's commands - making them easier to use. These functions are compatible with many of the other atmel microcontrollers as-is, but haven't been tested yet.
The bootloader written to the new ATmega8 is stored in a large array - because default fuse bits of your Arduino prevent reading the boot section. This was a problem I ran into, but the table that had to be added also provides new possibilities.
To sum it all up, this means the Boot-Cloner could write any program to any atmel microcontroller. But, because the target's program must be stored in the source's memory (which limits the maximum size of the program) it's only possible to write small programs like bootloaders.
The ISP protocol is detailed in the Atmel ATmega8 datasheet, towards the end. Additional comments in the sketch's source code describe command parameters and the flash write process.
1) Download and expand the zip archive containing the source code and schematic
2) In the Arduino IDE, open the Boot-Cloner sketch
3) Verify the sketch compiles without error
4) The +5V and GND of your Arduino should be used to power the target ATmega8
5) Upon wiring the circuit, according to the schematic, your Arduino should be connected by 10 wires to a breadboard
5V, GND, RESET, SCK, MISO, MOSI, LED1, LED2, LED3, START BTN
6) Ensure you have the chip oriented correctly, and oscillator and power connected to the pins as shown in the schematic
7) Burn the BootCloner sketch to the Arduino and wait for the program to start - you'll see an LED light up according to the program's state
8) At this point, you can push the start button.
The LEDs will change from Idle/Green to Run/Yellow for a moment (less than 4 seconds) and then switch back to Idle/Green.
9) Remove the target ATmega8, insert the next.
10) Test the first one you burn, the first time you do this, by putting it in an Arduino and writing the Blinking LED program.
11) If step 10 worked you can repeat steps 8 and 9 until all your ICs are prepared.
The bootloader table in the BootCloner sketch holds the raw data which is written to the boot section of the microcontroller. However, a hex file contains memory address and checksums in addition to the raw data. To save space the extra information was discarded and the string hexadecimal numbers were converted to decimal or hexadecimal constants recognizable by the Arduino IDE. (0-255 or 0x00-0xFF)
At the beginning of the BootCloner source code is a reference to a website described as "iHex flash file format information". If you want to understand the format better, that's a great place to start.
The program below, "Hex Data Extractor" can be built into an application that'll extract it for you.
There are also some things in the sketch that need to be changed. How many defined constants need to be modified depends on how different your target microcontroller is than an ATmega8. Ideally you should only have to change the constants, and not the program itself.
Alternate bootloader for an ATmega8:
Alternate bootloader for an ATmega168:
Diecimila bootloader for ATmega168 (arduino-010 version)
Alternate bootloaders for other atmel microcontrollers:
Notes:
/* Data Extractor for Intel Hex Formatted Files * ------------------ * Created 2007 by jims * <mailto:jim@federated.com> * * Compile this with your preferred C environment, as a standard console app. * From the console (Command Prompt), launch the app with the hex file pathname. * The console output will be the extracted hex data. * * 05/25/2008: Bug fix by froyer * . The last important byte of each line was getting truncated. * . replaced buf[len-4] = 0; with buf[len-3] = 0; and zeroed out 2 more bytes to the end of the line * . removed space between bytes in output */ #include <stdio.h> #include <string.h> void main() { char buf[4096]; int ByteCount = 0; while(fgets(buf, sizeof(buf)-1, stdin)) { int len = strlen(buf); char *b; if (len<9) { continue; } buf[len-3] = 0; buf[len-2] = 0; buf[len-1] = 0; for (b = buf+9; *b; b += 2) { printf("0x%c%c,", b[0], b[1]); ByteCount++; } printf("\n"); } printf("/*%d Bytes*/", ByteCount); }
I couldn't get the above code to work on Windows. This modified code does:
#include "stdafx.h" #include "stdio.h" #include "string.h" int main(int argc, char* argv[]) { FILE * pFile; pFile = fopen (argv[1], "r"); if (pFile == NULL) { perror ("Error opening file"); return 1; } else { char buf[4096]; int ByteCount = 0; while(fgets(buf, sizeof(buf)-1, pFile)) { int len = strlen(buf); char *b; if (len<9) { continue; } buf[len-3] = 0; //write null 2nd char //last char - strips out the //last two chars ie checksum for (b = buf+9; *b; b += 2) //strip out //first 9 chars - ie non-data chars { printf("0x%c%c,", *b, *(b + 1)); // changed b[1]; - array format to *(b + 1); -pointer //format for consistency ByteCount++; } printf("\n"); } printf("/*%d Bytes*/", ByteCount); fclose (pFile); return 0; } }
(It's probably not terribly useful at the moment since there don't appear to be any alternative bootloaders for the Atmega8 but it does work.)
NOTE by Fabien Royer, May 26 2008 I had not luck with this Boot Cloner. However, I was able to use [https://playground.arduino.cc/Code/Programmer2] successfully.
Note by Ae7flux, 02/06/08 Doesn't work with the Atmega168 but it's fine for the Atmega8 (programs in about two seconds).
Note by Celso Fraga, July 18 2008
Worked like a charm! Even bringing back to life some Mega8's that was lying around... I've built an shield for the Boot-Clonner, I can upload some pics if somebody told me how to...