Go Down

Topic: read the program already uploaded on arduino (Read 863 times) previous topic - next topic

cantore

Apr 18, 2012, 11:56 am Last Edit: Apr 18, 2012, 04:42 pm by cantore Reason: 1
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

CrossRoads

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.
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.

robtillaart

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.


Rob Tillaart

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

Nick Gammon

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

Code: [Select]
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.
http://www.gammon.com.au/electronics

tizzy

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?

tizzy

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!)

CrossRoads

"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.
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.

Nick Gammon


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?
http://www.gammon.com.au/electronics

cantore


Xylitol

#9
Jan 26, 2014, 01:24 pm Last Edit: Jan 26, 2014, 04:15 pm by Xylitol Reason: 1
Sorry for the 2012 bump but i've a problem with my arduino mega 2560, i'm doing the following command:
Code: [Select]
avrdude.exe -c arduino -p m2560 -P \\.\COM8 -U flash:r:dump.hex:i
And avr dude answer me after sending the command:
Code: [Select]
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.

robtillaart

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

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

Xylitol

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.

Go Up