Loading...
Pages: [1]   Go Down
Author Topic: read the program already uploaded on arduino  (Read 350 times)
0 Members and 1 Guest are viewing this topic.
italy
Offline Offline
Full Member
***
Karma: 2
Posts: 207
Muuuuu
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you know if it is possible to read a program already uploaded on arduino? I suppose that the code will not be c++ but something near assembly but it doesn't matter.
Thanks
« Last Edit: April 18, 2012, 09:42:23 am by cantore » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 270
Posts: 17040
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You may be able to retrieve the databytes that are there in hex format, if the Lock bits weren't set to preclude that.
Then you would need to "dissamble" the data and try to make sense of it as program.
Not an easy task.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Netherlands
Offline Offline
Tesla Member
***
Karma: 101
Posts: 9551
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

retrieving the binary can be done with avrdude.exe
The documentation is in the Arduino distribution, but be aware that you will get a dump of the Flash (32 K) which is only partial the program (most of the times)
The rest is residu from larger programs and maybe just plain zero's

As said not trivial.

If you hold the shift key while uploading you will see the AVRDUDE command to upload, the download has 90% the same parameters.

 
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 226
Posts: 14101
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Depending on the exact device and programmer you have, something like:

Code:
avrdude -c usbtiny -p m328p -U flash:r:myfile.hex:i    # <---- read from device into myfile.hex
avr-objdump -j .sec1 -d -m avr3 myfile.hex       # <-- disassemble myfile.hex

You probably need to replace "usbtiny" with your own programmer and add the comm port number. What robtillaart said, basically.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For download of an stk500 compile on a Arduino Mini Pro (atmega328p) I used the latest install of AVRDude 1.0:
avrdude -C "G:\Devices\CT6A RC kit\arduino-1.0\hardware\tools\avr\etc\avrdude.conf" -v -v -v -v -p atmega328p -c stk500 -U flash:r:"c:/arduino.bin":r -P\\.\COM4 -b57600

This should have produced an arduino.bin file but all I got was a repeat output of
avrdude: Recv: & [26]

and finally:
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_command(): failed miserably to execute command 0x11
avrdude: stk500v2_disable(): failed to leave programming mode

Not sure what it means but there's no dump

Have heard it might be due to the 1.0 version AVRdude and should try .22. Haven't had a chance yet but will try it out asap if I can find that version to download from somewhere.

One thing that bothers me tho is that using the serial monitor I only get a line of jibberish instead of something readable. What's supposed to be shown?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Update:
Downloaded Arduino software v0022 and repeated avrdude instruction: works, resulted in an arduino.bin to be used as a backup in case I screw the sketch up! Thanks to all (but especially Rob of course!)
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 270
Posts: 17040
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"in case I screw the sketch up!"
So you want a method to back up your sketches? You could always save the .hex file that is created by the IDE directly. It ends up in a directory.
If you select File:Preferences and turn on Verbose Output (in 1.0 anyway) you can scroll thru and find the directory & filename that is created.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 226
Posts: 14101
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Downloaded Arduino software v0022 and repeated avrdude instruction: works, resulted in an arduino.bin to be used as a backup in case I screw the sketch up!

Wouldn't it be better to save the sketch source?
Logged


italy
Offline Offline
Full Member
***
Karma: 2
Posts: 207
Muuuuu
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for your suggestion
Logged

Pages: [1]   Go Up
Print
 
Jump to: