Firmware update

What is the problem?
I want to make a copy of firmware before I flash a new firmware.
What did you already try to solve it?
Avrdude installed but it cannot read flash. This via PuTTY / RPi
Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log, serial.log or output on terminal tab, ...)

What is the correct command for this as this one will not work
sudo avrdude -p atmega1284p -c arduino -P /dev/ttyUSB0 -b 57600 -F -U flash:r:flash_backup_file.hex

This is the error message I get. Wanhao i3 = Meltzi

pi@octopi:~ $ sudo avrdude -p atmega1284p -c arduino -P /dev/ttyUSB0 -b 57600 -F -U flash:r:flash_backup_file.hex
[sudo] password for pi:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9705 (probably m1284p)
avrdude: reading flash memory:

Reading | | 0% 0.00s
avrdude: stk500_paged_load(): (a) protocol error, expect=0x10, resp=0xef
avrdude: stk500_cmd(): programmer is out of sync
avr_read(): error reading address 0x0000
read operation not supported for memory "flash"
avrdude: failed to read all of flash memory, rc=-2

avrdude: stk500_cmd(): programmer is out of sync
avrdude: stk500_cmd(): programmer is out of sync
avrdude: stk500_cmd(): programmer is out of sync
avrdude: stk500_cmd(): programmer is out of sync
avrdude: safemode: Sorry, reading back fuses was unreliable. I have given up and exited programming mode
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x4a

avrdude done. Thank you.

As I know, you can't read the firmware form the board.

1 Like

OK, is it that bad. So there is overhanging risk that trying to flash new firmware can go south.

So what does this say ??

pi@octopi:~ $ sudo avrdude -P /dev/ttyUSB0 -b 57600 -c arduino -p m1284p -v

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/root/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
         AVR Part                      : ATmega1284P
         Chip Erase delay              : 55000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    10   128    0 no       4096    8      0  9000  9000 0xff 0xff
           flash         65    10   256    0 yes    131072  256    512  4500  4500 0xff 0xff
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.16
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9705 (probably m1284p)
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done.  Thank you.

Something fishy going on here, now suddenly my previous syntax works.

pi@octopi:~ $ sudo avrdude -p  atmega1284p -c arduino -P /dev/ttyUSB0 -b 57600 -F -U flash:r:flash_backup_file.hex
[sudo] password for pi:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9705 (probably m1284p)
avrdude: reading flash memory:

Reading | ################################################## | 100% 38.99s

avrdude: writing output file "flash_backup_file.hex"

avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done.  Thank you.

pi@octopi:~ $ sudo find / -name *.hex
/home/pi/flash_backup_file.hex

In many cases, you're supposed to be able to read most of the different parts of memory from the Arduino chip. (In a few cases, the lock bit has been set so that you can't.)

Sometimes, it's necessary to unplug/re-plug the USB cable once for this to work. I think it's effectively similar to pressing the RESET button in that the board is freshly powered and is more willing to give up the information. They're finicky like that. I'm guessing that once the serial connection has been opened and a START command sent from the host it now doesn't want to allow you to back anything up. So maybe the trick is to boot it up and then go for it.

  • flash: sudo avrdude -c arduino -P /dev/ttyUSB0 -p m1284p -b 57600 -F -U flash:r:flash_backup_file.hex:r

  • eeprom: sudo avrdude -c arduino -P /dev/ttyUSB0 -p m1284p -b 57600 -F -U eeprom:r:eeprom_backup_file.hex:r

  • hfuse: sudo avrdude -c arduino -P /dev/ttyUSB0 -p m1284p -b 57600 -F -U hfuse:r:hfuse_backup_file.hex:r

  • lfuse: sudo avrdude -c arduino -P /dev/ttyUSB0 -p m1284p -b 57600 -F -U lfuse:r:lfuse_backup_file.hex:r

  • efuse: sudo avrdude -c arduino -P /dev/ttyUSB0 -p m1284p -b 57600 -F -U efuse:r:efuse_backup_file.hex:r

It wouldn't surprise me if it could talk faster (-b 115200) than what you're trying.

I normally bring up the Arduino IDE software from Arduino.cc, configure the board type, etc and then verify the Board Info as returned from the chip. You can use this information to slightly change the avrdude configuration if necessary.

I just pulled my flash with the following (noting that I've got a Robo 3D ROBOmainboard that's based on an Arduino Mega 2560 via a straight serial cable connection without an FTDI chip'd cable/dongle/programmer/whatever):

avrdude -c avrispmkII -P /dev/cu.usbmodem14201 -b 115200 -p ATmega2560 -U flash:r:backup_flash.bin:r

2 Likes