Pages: [1]   Go Down
Author Topic: Fetching the code from the Atmega chip  (Read 499 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

My question is a bit deliciously weird. Some weeks ago I uploaded a sketch(code) into the Arduino's micro-controller. Now I need the code but i cannot remember and find the file in my PC.

I know that was the last code I uploaded and it is in there.

Is there a way to take it out?

Thanks,
« Last Edit: April 26, 2012, 12:56:28 am by cmd1024 » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a good question. I would be interested in knowing the answer to this as well.
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can take it out but it's post compiled, ie unintelligible.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19036
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The closest you can get is the disassembled machine code, which looks like this:

Code:
   f2d4: 85 e1       ldi r24, 0x15 ; 21
    f2d6: 92 ee       ldi r25, 0xE2 ; 226
    f2d8: 60 e0       ldi r22, 0x00 ; 0
    f2da: 0f 94 c2 f1 call 0x3e384 ;  0x3e384
    f2de: c8 01       movw r24, r16
    f2e0: aa 27       eor r26, r26
    f2e2: bb 27       eor r27, r27
    f2e4: 0f 94 11 f2 call 0x3e422 ;  0x3e422
    f2e8: bb 27       eor r27, r27
    f2ea: a1 2f       mov r26, r17
    f2ec: 90 2f       mov r25, r16
    f2ee: 8f 2d       mov r24, r15
    f2f0: 0f 94 11 f2 call 0x3e422 ;  0x3e422
    f2f4: 8e 2d       mov r24, r14

Not particularly useful unless you are an assembler guru.

I would be doing a "find files" for files ending in .pde or .ino and see if you can find that file.
Logged


Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi nick,

what kind of method is used to reach the machine code? i mean basically.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19036
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Assuming you are using the USBtinyISP programmer (if not, modify to suit):

Code:
avrdude -c usbtiny -p m328p -U flash:r:myfile.hex:i
avr-objdump -j .sec1 -d -m avr3 myfile.hex > myfile.asm

That reads in the flash memory to myfile.hex, and the second line disassembles it into myfile.asm.
Logged


Pages: [1]   Go Up
Jump to: