13
\$\begingroup\$

Is there a way to export code for an arduino even as a hex file?

\$\endgroup\$
  • 2
    \$\begingroup\$ Yes, using avrdude from the command line, unless the security fuse has been set. It might even be possible then, but intentionally much harder, and not clear if anyone has yet defeated that security mechanism. \$\endgroup\$ – Chris Stratton Mar 15 '13 at 21:56
  • \$\begingroup\$ @ChrisStratton I was listening to a defcon talk where they talked about how it had been defeated. I can't remember which one it was, but google might remember. \$\endgroup\$ – Hair_of_the_Dog Mar 15 '13 at 21:58
  • \$\begingroup\$ It has been defeated for some microcontrollers, and not (at least to public knowledge, short of physical dissection) yet for others. \$\endgroup\$ – Chris Stratton Mar 15 '13 at 22:00
  • \$\begingroup\$ Yeah, I'm pretty sure it was dissected. \$\endgroup\$ – Hair_of_the_Dog Mar 16 '13 at 2:24
7
\$\begingroup\$

Perusing the source code of the Arduino bootloaders at https://github.com/arduino/Arduino/tree/master/hardware/arduino/bootloaders it appears that they do in fact support the stk500 readback functionality for flash memory, such that you can accomplish your goal with a client program such as avrdude.

So the answer to the question is that if you can access the bootloader, then yes you can read out the contents of the flash memory in a binary or hex format, without resorting to an external programmer.

If you cannot access the bootloader (reset troubles, or no intact bootloader present) then you may be able to do so with an external programmer, provided security fuse settings do not prevent this.

\$\endgroup\$
  • 1
    \$\begingroup\$ It turns out that not only is readback supported, the default avrdude verify behavior relies on it as it works by reading back a buffer and performing comparison on the PC. So essentially, anyone who has ever uploaded code to an ATmega based Arduino by letting the IDE invoke avrdude with the default configuration, has also implicitly read one out. \$\endgroup\$ – Chris Stratton Feb 4 '18 at 21:53
5
\$\begingroup\$

Yes, I have successfully pulled the boot kernel from one Arduino Board via ISCP and pushed it into another. The security fuses were not set. where avrdude will work. Back then I used AVR Studio with a STK500 as it had a GUI and I did not need to learn all the avrdude switches. Either will work.

Setting the fuse defeats open source. That said the boot kernel is provided in the IDE. ..\Arduino\hardware\arduino\bootloaders\atmega8\ATmegaBOOT.hex along with others variant chips.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.