Copy 'n Paste Arduino Firmware

I try and put my Arduino specific stuff on the forum somewhere to aid in others finding it with Search. But sometimes I forget to cross-post articles.

Back in June, I wrote an Instructables article
http://www.instructables.com/id/Copy-n-Paste-Arduino-Firmware/# and then in July I answered a forum member's question
Any command line tool to upload my own hex compiled elsewhere to my uno? - #3 by mrburnette - Microcontrollers - Arduino Forum
but I never got around to creating a new thread with the subject to assist in forum searches. Until today.

If you have an AVR-ISP device, you essentially have a chip copy machine. While we think about using the ISP for downloading (burning/flashing) the uC, the hardware interface is also capable of reading the information. Nick Gammon makes good use of this capability in his Board Detector Sketch:

But, you can essentially create uC firmware backups files and duplicate ATmel chips without using the GUI environment. Below is my Windows Vista scripts which duplicates an Atmega328.

Note: The AVRDUDE specific information derived from various sources; that is, many people helped in this development and therefore it should be considered a shared effort by many. My part is just in putting it all in one place/file.

REM
prompt $G
ECHO OFF
CLS
ECHO.
ECHO BATCH COPY ATMEGA328P-PU VIA ARDUINO-ISP ON COM9
CD C:\Program Files\Arduino_105\hardware\tools\avr\bin
ECHO ENSURE MASTER CHIP IS IN THE READER
ECHO CTRL+C to abort OR PRESS Any key to begin copy...
ECHO.
pause >nul
ECHO Creating hexadecimal binary files of ATmel328P contents...
>stdout.log 2>&1 (
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U flash:r:%temp%\backup_flash.hex:i
ECHO flash has been sAVED to backup_flash.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U eeprom:r:%temp%\backup_eeprom.hex:i
ECHO eeprom has been SAVED to backup_eerpom.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U hfuse:r:%temp%\backup_hfuse.hex:i
ECHO hfuse has been SAVED to backup_hfuse.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U lfuse:r:%temp%\backup_lfuse.hex:i
ECHO lfuse has been SAVED to backup_lfuse.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U efuse:r:%temp%\backup_efuse.hex:i
ECHO efuse has been SAVED to backup_efuse.hex
)
ECHO Hexadecimal files created.
ECHO.
CD C:\Program Files\Arduino_105\hardware\tools\avr\bin
ECHO INSERT THE NEW CHIP now!
ECHO PRESS Any key to write new chip...
pause >nul
REM Note that the path cannot contain the drive letter "C:" so you cannot use %temp% as previously
REM Reference:http://savannah.nongnu.org/bugs/index.php Bug report #39230
REM.
>>stdout.log 2>&1 (
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U flash:w:\Users\owner\AppData\Local\Temp\backup_flash.hex
ECHO backup_flash.hex WRITTEN
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U eeprom:w:\Users\owner\AppData\Local\Temp\backup_eeprom.hex
ECHO backup_eeprom.hex WRITTEN
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U hfuse:w:\Users\owner\AppData\Local\Temp\backup_hfuse.hex
ECHO hfuse WRITTEN
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U lfuse:w:\Users\owner\AppData\Local\Temp\backup_lfuse.hex
ECHO lfuse WRITTEN
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U efuse:w:\Users\owner\AppData\Local\Temp\backup_efuse.hex
ECHO efuse WRITTEN ... this may change from 05 to 07 with BOD being disabled by AVRDUDE
)
ECHO.
ECHO Chip duplication and verification is complete.
ECHO Starting Notepad editor to display log file.
start notepad C:\Program Files\Arduino_105\hardware\tools\avr\bin\stdout.log
ECHO.
ECHO Press Any key to close this window...
pause >nul

This script allows unlimited copies from the 'left over" files from the above script:

REM Execute this for 2nd throgh n copies IMMEDIATELY after 1st copy
PROMPT $G
ECHO OFF
CLS
CD C:\Program Files\Arduino_105\hardware\tools\avr\bin
ECHO INSERT THE NEW CHIP INTO ARDUINO ISP PROGRAMMER
ECHO PRESS Any key to write new chip (CTRL+C to abort)
ECHO ...
PAUSE >nul
REM Paste 328: Note that the path cannot contain the drive letter "C:" so you cannot use %temp% as previously
REM Reference:http://savannah.nongnu.org/bugs/index.php Bug report #39230
REM.
>stdout.log 2>&1 (
DIR %temp%\*.hex
ECHO ATmel328P-PU duplication is beginning now...
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U flash:w:\Users\owner\AppData\Local\Temp\backup_flash.hex
ECHO flash WRITTEN
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U eeprom:w:\Users\owner\AppData\Local\Temp\backup_eeprom.hex
ECHO eeprom WRITTEN
REM high_fuses=0xDA
REM REM avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U hfuse:w:0xDA:m
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U hfuse:w:\Users\owner\AppData\Local\Temp\backup_hfuse.hex
ECHO hfuse WRITTEN
REM low_fuses=0xE2
REM avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U lfuse:w:0xE2:m
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U lfuse:w:\Users\owner\AppData\Local\Temp\backup_lfuse.hex
ECHO lfuse WRITTEN
REM extended_fuses=0x05
REM avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U efuse:w:0x05:m
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U efuse:w:\Users\owner\AppData\Local\Temp\backup_efuse.hex
ECHO efuse WRITTEN
)
REM.
REM Chip duplication is complete... starting display of log file.
start notepad C:\Program Files\Arduino_105\hardware\tools\avr\bin\stdout.log
ECHO.
ECHO Press Any key to close this window...
PAUSE >nul

REMEMBER: When working with Windows, different versions: XP, Vista, Win7, Win8 mucks around with the directory locations. You will likely need to edit the scripts to match your specific environment and OS version.

Ray

1 Like

So that script does the same as

Tools:Burn Bootloader

and then
File:Upload Using Programmer

if one had the sketch open already?

So that script does the same as
Tools:Burn Bootloader and then
File:Upload Using Programmer
... if one had the sketch open already?

The script was not patterned after the Arduino functionality, per se, but I suspect that the "write" functionality is equivalent although I seem to remember that the Arduino passes more arguments on the command line.

When building the script, I took care to break out the logic into individual command lines rather than aggregating runline options into one command. For example, the fuses can all be burned at one time rather than using the three separate commands which I did purposefully since it is self-documenting.

The read-to-file portion is never utilized by Arduino, to my knowledge. That part of the script was concocted from info found on the avrfreaks.com site, if I remember. It was a Frankenstein effort, pulling bits of knowledge, documentation, and examples from various web and program documentation. The creation of the logfile by IO redirection was all my own doings... if it does not work beyond Vista, I take full responsibility for issues :fearful:

Ray

The creation of the logfile by IO redirection was all my own doings... if it does not work beyond Vista, I take full responsibility for issues

I can confirm that it works on Windows 7.

It's i nice feature, thanks for sharing.

I was thinking about making your script more easyer to change by alowing the user to use different com ports and processors, either by passing them as arguments or by using variables, like this:

ECHO OFF
CLS
SET comport=COM3
SET processor=t13
ECHO Using %comport% and processor %processor%

>>stdout2.log 2>&1 (
avrdude -P %comport% -b 19200 -p %processor% -c avrisp -v
)

start notepad stdout2.log

@Erni:

Go for it, thus is why the knowledge and experience is openly shared. I only use my dedicated Arduino + Adafruit Zif shield, therefore that is always the same comport for my workstation.... Hence the hard coding.

Ray

I only borrowed an ISP to get a dump of an Arduino. How do I upload it using the regular bootloader? Just chop off the first 2KB?