Join GitHub today
Important: In order the bootloader to function, the BOOTRST Fuse-Bit has to be set.
Both, the USB-Stick and the Socket are shipped with a preinstalled bootloader which is used to update the firmware. The update is done on a PC with the "BootloaderFlasher" program which transfers a Intel-Hex file to the appropriate bootloader.
###Starting the bootloader:
- If Contiki is running, by pressing the button approximately 8 sec long
- By holding the button pressed, while plugging the socket
In both cases an EEPROM-Flag will be set. While in the bootloeder, the LED on the Hexabus Plug will blink quickly (it will first blink slowly when it goes into pairing mode. Keep holding the button until it blinks more quickly). After the successful flashing (or a 30 second timeout), it will again be disabled.
Note: Not all Hexabus Plugs have the bootloader installed. If your Plug just reboots when you press the button for 8 seconds, there is no bootloader.
###Integrity check of the Flash-memory:
When starting the bootloader, a CRC-value over the total memory (except for the boot sector) will be computed and compared with a CRC-value that is already in the EEPROM. The later one is computed and written in the EEPROM after a successful flashing. In case the CRC-values don’t match, the program stays in the bootloader.
###Displaying the bootloader mode:
A blinking red LED will show that the bootloader is running.
###Leaving the bootloader:
If in 30 sec. there is no command to flash the bootloader, it will exit. Thereby, the program will jump to position 0x0000 in the flash memory.
The flashing can be made through the Linux console application „BootloaderFlasher“ in the folder
firmware/bootloader/BootloaderFlasher/. An explanation of the various parameters can be shown by using the parameter “-h”.
MacOSX: for MacOSX the
/dev/cu.* device has to be used, since /dev/cu.* is the callout device contrary to /dev/tty.* which is for incoming traffic only.
###Flashing the USB stick:
The USB stick that has to be flashed, has to be in a bootloader mode. The application “BootloaderFlasher”, with the hex file used for flashing as an input parameter, has to be started on the device, to which the USB stick is connected. The flashing should now run automatically.
./BootloaderFlasher -p /dev/USBstickDEVICE ../../Hexabus-USB/Hexabus-USB.hex
The Application is continously outputting the line of the hex file which it is currently transfering to the USB-Stick. After a successful flashing the BootloaderFlasher will stop with the output "Programming completed successfully".
###Flashing the socket:
The socket that has to be flashed has to be in a bootloader mode. The application “BootloaderFlasher”, has to be started with the parameter “-f”, as well as with the hex file used for flashing. The application should run on the device, to which the USB stick is connected. The flashing should then follow automatically.
./BootloaderFlasher -p /dev/USBstickDEVICE -f ../../Hexabus-Socket/Hexabus-Socket.hex
The Application is continously outputting the line of the hex file which it is currently transfering to the Socket. After a successful flashing the BootloaderFlasher will stop with the output "Programming completed successfully".
##Setting up the bootloader firmware:
In case the bootloader is not functioning, it has to be rewritten via JTAG. In case of using an AVR JTAGMKII this is done by invoking:
sudo make program
in the respective folder
firmware/bootloader/Socket/ for the socket and
firmware/bootloader/USB/ for the USB stick.
If due to writing the bootloader, the EEPROM is accidentally deleted, it can be rewritten by using the command:
sudo avrdude -p atmega1284p -P usb -c jtagmkII -U eeprom:w:Bootloader.eep -F
or respectively, for the USB stick:
sudo avrdude -p at90usb1287 -P usb -c jtagmkII -U eeprom:w:Bootloader.eep -F
Thereby, it is important, to put the original MAC address of the device in the EEPROM area of the Bootloader.c.
In case avrdude reports a device signature error, the workaround is, to invoke avrdude with an additional
-F. This ignores the device signature and flashing will work.
###Communication protocol USB-bootloader:
A serial communication with the USB-bootloader will be setup through a virtual serial port. After the startup, the bootloader waits for a command on the serial port: The commands “e” (end bootloader) and ”p” (program bootloader) will be accepted.
If the command “e” is used, the bootloader acknowledges it with the hex value 0x06. Afterwards the bootloader will be exited. If the command “p” is used, the bootloader acknowledges this with a hex value 0x01. Now, the bootloader waits line after line, for the data of an Intel hex file. Every line has to begin with the value ‘:’. If the line does not begin with this value, the program mode will be exited and the hex value 0x00 will be returned. At the end of the transfer, a check sum is computed for every line, which is checked from the bootloader. If this sum is correct, the line data will be written in the flash memory and the hex value 0x05 will be returned. After that, the next line can be further transferred. If the check sum is incorrect, the hex value 0x06 is returned. In that case, the line has to be transferred again. The last line of each Intel hex file contains the „End of Record“. As soon as this line will be transferred, the programming mode will be left and assumed, that a valid image was written.
###Communication protocol Socket-bootloader:
If the socket is flashed, the communication over the serial connection with the USB stick runs the same way, as if the USB stick would have been in a bootloader mode. However, the flashing won’t be initiated with the command “-p”. Instead, the USB stick will be set in the flash mode in the running Contiki by using the command “-f’. The USB stick will further remain in Contiki, but, during the flashing, it ignores the packets from the transceiver that don’t originate from the socket which has to be flashed. Moreover, there will be no status announcements from Contiki through the serial connection. The USB stick sends the lines from the hex files through the transceiver to the socket. The socket, in return, sends an acknowledgment packet to confirm the correctly received line or to ask for resending. The packet contains the hex value 0x06 if the line should be retransmitted or 0x05 if the next line should be sent. At the beginning, the socket generates in the bootloader a 2-Byte random value, which, while flashing, will be send along in every packet to the USB stick. After the USB stick has received the value for the first time, it also sends this value in every packet. This way, it is assured, that no other flashing process, that runs simultaneously, will disturb the existing one.