First off, it is absolutely true that you CAN do firmware changes through a command-line interface. I was dismayed at the Arduino IDE and the apparent modus operandi that everything must be done through this GUI. I have an intense distate for GUIs, generally. This one is no exception.
Now, you will need the source code for the firmware. There are several pointers on the forum threads to various versions of the firmware. I have a 2012-vintage M2, with the split 12V/19V power supplies, so I got my version of the firmware from Ketil. Instructions are here, where I asked Ketil to be specific because I didn't know how to pull a specific branch off of a repository on github:
viewtopic.php?f=3&t=106&start=10#p2304
Once checked out, this distribution has a subdirectory Marlin/. cd to that subdirectory. There you will find a Makefile. The Makefile is full of apparently untouched default values, which indicates that the GUI method just bypasses it altogether. But assuming you want to build from the command line, this is what you want.
I modified the following lines like so:
Code: Select all
HARDWARE_MOTHERBOARD ?= 301
ARDUINO_INSTALL_DIR ?= /home/tim/projects/arduino/arduino-1.0.5
AVR_TOOLS_PATH ?= /home/tim/projects/arduino/arduino-1.0.5/hardware/tools/avr/bin/
AVRDUDE_PROGRAMMER ?= stk500v2
UPLOAD_PORT ?= /dev/ttyACM0
BUILD_DIR ?= build
I added BUILD_DIR = "build" just because that's far more typical than their default value of "applet". Regardless, you will need to create this directory ("mkdir build") because the Makefile doesn't try to detect its existance, and will not create it if it doesn't exist.
Now you should be able to just do "make", and it will all compile (fingers crossed). If that works, you get an executable
Code: Select all
build/Marlin.elf
Code: Select all
build/Marlin.hex
By dissecting the Makefile, I can pull out the command-line invocation for "avrdude", and replace the flash write command with a flash read command. The result is the following command to download the existing firmware as a hex format file (using "ARDUINO_INSTALL_DIR" from the Makefile):
Code: Select all
${ARDUINO_INSTALL_DIR}/hardware/tools/avrdude -D -C ${ARDUINO_INSTALL_DIR}/hardware/tools/avrdude.conf -p atmega2560 -P /dev/ttyACM0 -c stk500v2 -b 115200 -U flash:r:build/Marlin_orig.hex:i
But. . . I can't help but notice that "build/Marlin_orig.hex" is nearly three times the size of the newly-compiled "build/Marlin.hex" (623kB vs. 215kB). So maybe I'm paranoid with good reason. I will investigate this disparity before continuing. (to be continued)