Saturday, March 20, 2010

Dumping out the content of the Arduino

I'm very impressed by how easy it is to make a small program on the arduino, the community did a great job. Also, I think it's a very easy introduction to embedded systems, because you don't have to worry about the low-level aspect of embedded systems in general.
Recently, I had to analyze a "black-box". By black-box I mean a box that you don't know anything about. In my case, it was a 3k$ video component, with a FPGA (Cyclone II) and an atmel (Atmega168). I got it for a little moment, I also had an AVR programmer but I did not know how I could dump out the content of the atmega chip.

It turns out that in Windows, you can just install AVR Studio and from there you will have a nice GUI with all the options to maybe retrieve the content from the memory. This programs does a great job, but what about Linux ?

Well, avrdude is your friend in the Linux world. I wanted to dump the content of the memory, so an idea might be to use it this way:

~/arduino-0017/hardware/tools/avrdude \
-C~/arduino-0017/hardware/tools/avrdude.conf -v -v -v -v \
-pm328p -cstk500v2 -P/dev/ttyUSB1 -D -Uflash:r:/tmp/kikou.hex:i

And ohh... magic, all the content is dumped on the file /tmp/kikou.hex.

Well, this is an intel hex dump, so not really readable:


I tried to dump it as "raw output", but you will get an hexdump. "Ce n'est pas folichon" I'd like to say. From the hexdump, one cool thing would be a disassembler, but apparently, nobody has done one on Linux. If you know a way to read hexfiles (avr-objdump won't work here), drop me a message!
Another solution is to use the AVR Studio program in Windows, apparently it does the job, but I haven't tried yet.

We'll probably come back on that very soon 8).

1 comment:

  1. avr-objdump will work!

    First, create an .elf:

    avr-objcopy -I ihex -O elf32-avr test.hex test.elf

    Check out the section names:

    avr-objdump -h test.elf

    For each section, set the code-flag (and a couple of others)

    avr-objcopy --set-section-flags .sec1=contents,alloc,load,readonly,code test.elf
    avr-objcopy --set-section-flags .sec2=contents,alloc,load,readonly,code test.elf
    avr-objcopy --set-section-flags .sec3=contents,alloc,load,readonly,code test.elf

    Finally, dump the whole thing:

    avr-objdump -h -S test.elf >test.lss

    As simple as that :-)