Firmware upgrades
Posted: Mon Jun 09, 2014 8:02 pm
I'm not sure how many people out there are Linux users and tend to want to do everything from a terminal command line. But I am, and since there seems to be extraordinarily little documentation to be found on it, I thought I'd make a quick how-to on this.
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:
Note that while you may not use the Arduino IDE GUI, you still need the Arduino IDE (latest stable revision, 1.0.5) because it contains the gcc cross-compiler for the AVR processor. So just point the paths ARDUINO_INSTALL_DIR and AVR_TOOLS_PATH to the installed Arduino IDE. The upload port of /dev/ttyACM0 is typical for Linux systems connecting to the Rambo.
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
and a hex file:
Theoretically, you now connect the printer and do "make upload" and it works, using the command-line tool "avrdude". At this point, though, being the paranoid person I am, I want to see if I can pull the existing firmware off of the M2 and into a hex file where I can save it locally, as a backup, to be restored should anything go wrong. I have no wish to overwrite a perfectly good existing firmware with one that claims to be the same, having no proof of that assertion.
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):
Run this and you should get a file "build/Marlin_orig.hex" which is the existing firmware. Now I have greater faith that I can restore my M2 to its original condition at any time by uploading it with the same command as above, but with "r" replaced by "w" in the "-U" argument.
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)
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)