Pages: [1]   Go Down
Author Topic: read the program already uploaded on arduino  (Read 795 times)
0 Members and 2 Guests are viewing this topic.
italy
Offline Offline
Full Member
***
Karma: 3
Posts: 223
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: 538
Posts: 27088
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
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.
Arduino for Teens available at Amazon.com.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13705
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 -
(Please do not PM for private consultancy)

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
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: 538
Posts: 27088
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
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.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
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: 3
Posts: 223
Muuuuu
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for your suggestion
Logged

Seireitei, Soul Society
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for the 2012 bump but i've a problem with my arduino mega 2560, i'm doing the following command:
Code:
avrdude.exe -c arduino -p m2560 -P \\.\COM8 -U flash:r:dump.hex:i
And avr dude answer me after sending the command:
Code:
avrdude.exe: stk500_getsync(): not in sync: resp=0x00
But my arduino seem to get the signal because the L/RX leds blink before i got the getsync() message.
Any idea on what's wrong with my command, i'm using avrdude v5.10.
« Last Edit: January 26, 2014, 10:15:27 am by Xylitol » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you set verbose output in the IDE (file-> config)  you can see what avrDude.exe expects for commands when uploading.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Seireitei, Soul Society
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oh okay, i fixed the problem it was a conflict on my avrdude.conf
i was using avrdude of the arduino package but he was using the config file of my other avrdude installation of WinAVR.
Logged

Pages: [1]   Go Up
Jump to: