Update: The method below uses the Atmel SAM-BA tool for flashing. It is much easier (though less educational =) to use the libNXT utilities to flash your NXT brick from linux. This uses libusb and automagically finds your NXT when you connect it to your computer.
The following was done using debian linux (unstable @ 21 Nov 2008)
Disclaimer: You can easily screw up your NXT brick doing this! You will also lose any saved data on your NXT brick. You use this howto entirely at your own risk.
Note that linux command-line instructions below are shown in italics, with the root-prompt shown as '#' and a user-prompt shown as '$'
- You first need a firmware image for the NXT brick. See references for examples of this.
- Download the Atmel SAM-BA flashing tool for linux
- I unzipped this to /opt/atmel/sam-ba_cdc_2.8.linux_01 and add it to my path by placing a soft link in /usr/local/bin (# cd /usr/local/bin; ln -s /opt/atmel/sam-ba_cdc_2.8.linux_01/sam-ba_cdc_2.8.linux_01 sam-ba)
- Make sure that the sam-ba software has its executable flag set (# chmod +x /opt/atmel/sam-ba_cdc_2.8.linux_01/sam-ba_cdc_2.8.linux_01)
- Follow the instructions in the README.linux file: install the tcl / tk dependencies (I was installed the packages tk, tcl and tclx8.4 with aptitude)
- Boot the NXT brick in SAM-BA download mode first by switching on the NXT brick and then by holding the reset button on the back of the brick for over 4 seconds, as described on p74 of the Lego Mindstorms User Guide supplied with the NXT box set. You will hear the brick repeatedly making a clicking noise when successful. This may take a few attempts, depending on what firmware is residing in your NXT brick.
- Connect the NXT brick to your computer via USB and check that it has been correctly recognized using the 'lsusb' command. You can tell if this is successful, as you will see a device with the description 'Atmel Corp. at91sam SAMBA bootloader', not 'Lego Group'. If you see 'Lego Group', you did not successfully boot into SAM-BA download mode. Go back to step 6 if this is the case.
- Remove and reinsert the usbserial module with the relevant parameters, as in the readme (# modprobe -r usbserial; modprobe usbserial vendor=0x03eb product=0x6124)
- Check that the kernel has seen your NXT device by issuing the command 'dmesg'. You should see a line containing the text "generic converter now attached to ttyUSB0"
- Start the sam-ba utility (should be started with just $ sam-ba if you followed the earlier installation steps)
- Select the "AT91SAM7S256-EK" board from the dropdown list. The tty will probably be autodetected, but make sure it is the same as the one from the earlier dmesg command.
- In the "flash" tab, make sure that the address is 0x100000 (1 + 6 zeros). This is the location of the 256kbyte flash memory in the AT91SAM7S256 uController.
- Select the firmware file that you want to put into flash in the "Send file name" text box. In my case this was "/var/tmp/nxt-lua-beta-16a/nxt-lua-Beta-16a.rfw" Hit the "Send File" button. If the NXT has stopped clicking, it has turned itself off, and you will have to press the reset button and start over from step 6.
- When prompted about unlocking / locking flash sectors, reply "yes" both times. This is just a warning to check you are OK about reflashing the device.
- It would be nice to then check the data flashed with the "Compare sent file with memory" button. I was unable to get this to work properly however.
- When you are finished, unplug the NXT brick from USB and press the reset button on the back on the NXT for a short duration (less than 4 seconds). Your custom firmware should now be flashed. You know when you have reset the brick correctly, because it stops clicking. Congratulations!
Further info:
- The sam-ba download mode of the AT91SAM7S series of microcontrollers is detailed in the AT91SAM7S datasheet (p133 onwards)
- The latest official Lego firmware (1.05 as of time of writing) can be found here
- Examples of custom firmware for the NXT are: pbLua (tried), Enhanced NBC/NXC Firmware (not tried), lejos (not tried),