Bootloader

From OpenMotics
Jump to navigation Jump to search

This Section describes the Bootloader of the Slave Modules. For more information about the Bootloader in the master controller, please see Master Bootloader. For more information about the Bootloader in the Micro CAN, please see Micro CAN Bootloader.

The Slave Modules are equipped with a Bootloader to update the Firmware. The new firmware is split into blocks of 64 bytes and sent over from the Gateway Controller over the Master Controller to the Slave Modules.

Following Steps needs to be performed to update 1 Slave Module with new firmware:

  1. Use instruction FR to put the slave module in Bootloader Mode. In Bootloader mode, normal functionality is not possible and only functionality to load new firmware is available.
  2. Use instruction FV to check if the switch to Bootloader Mode is successful and to check which version of the Firmware is installed on this slave module.
  3. Use instruction FH to check the version of the Bootloader.
  4. Use instruction FC to set the CRC of the new firmware code to be loaded. (1)
  5. Use instruction FN to set the new version of the Firmware to be loaded
  6. Use instruction cm to change the communication protocol to 77 bytes format
  7. Use instruction FD multiple times until the new firmware version is fully transmitted
  8. Use instruction cm to change the communication protocol to 18 bytes format
  9. Use instruction FE to End the Firmware upload and to check integrity of the new firmware loaded (Full CRC check)
  10. Use instruction FG to leave Bootloader mode and to enter App mode (integrity check of the new firmware code against the Full CRC check is preformed, fail = stay in bootloader)
  11. Use instruction FV to check if App mode is active again

(1) After the instruction (FC) is send, the application firmware will be seen as corrupt because the new loaded crc will not match the old firmware code. This will be the case till the new firmware code is fully loaded (after the last FD instruction).

Slave Flash table

Bootloader.png


If the booloader starts up, it will first check if the code needs to stay in booloader or jump to application directly.

The checks are:

  • Button is pressed: stay in boot for 30s
  • Challenge is not reset by the user program: stay in boot for 10s
  • "stay in boot time" is set higher than 0 -> stay in boot for x seconds

If timeout is longer than 0 seconds, the bootloader will wait for a command from the master.

After a timeout or command "goto app":

  • the challenge is written to eeprom.
  • the bootloader will check if the code is valid (code and crc match)
    • if match -> jump to app.
  • otherwise reset the processor

If the code was not ok, the bootloader will restart and see that the challenge was not cleared in code -> stay in boot for 10s is guaranteed

Slave Eeprom table for all slave modules except the CAN modules

Every Slave Module is equipped with a Microchip 18F45K80 with a built-in eeprom of 1k. A few eeprom byte are used for bootloader purposes. Below you can find the eeprom table with some explanantion:

Eeprom address Description
1
ID0 of the slave module address
2
ID1 of the slave module address
3
ID2 of the slave module address
4
ID3 of the slave module address
64
Hardware version
65
F1 (Firmware Major Release)
66
F2 (Firmware Minor Release)
67
F3 (Firmware Built)
68
CRC check of the full firmware - Byte 0 (LSB)
69
CRC check of the full firmware - Byte 1
70
CRC check of the full firmware - Byte 2
71
CRC check of the full firmware - Byte 3 (MSB)
74
Flashmode, see below for more explanation (2)
75
Time in seconds that the bootloader must stay in bootmode when CRC and Flashmode are OK (3)

(2) In App mode, Flashmode will be put on 0. In bootloader, Flashmode will be checked to see if the app mode was running normally (Flashmode=0), if the application didn't put Flashmode on 0, the bootloader will remain longer in bootloader mode. The Bootloader will put Flashmode on 4.

(3) When the CRC is wrong, the slave will stay in Bootloader until the CRC error is resolved (by writing the correct CRC in address 68-71 or by loading the correct firmware). When the Flashmode is not correctly written during normal operations (thus something is wrong in the app), the slave will remain in bootloader for 10 seconds before trying app mode again.

Slave Eeprom table for the CAN Control

The CAN Control Module is equipped with a Microchip 18F46K80 with a built-in eeprom of 1k. A few eeprom byte are used for bootloader purposes. Below you can find the eeprom table with some explanantion:

Eeprom address Description
309
ID0 of the slave module address
310
ID1 of the slave module address
311
ID2 of the slave module address
312
ID3 of the slave module address
320
Hardware version
321
F1 (Firmware Major Release)
322
F2 (Firmware Minor Release)
323
F3 (Firmware Built)
324
CRC check of the full firmware - Byte 0 (LSB)
325
CRC check of the full firmware - Byte 1
326
CRC check of the full firmware - Byte 2
327
CRC check of the full firmware - Byte 3 (MSB)
329
Flashmode, see below for more explanation (4)
330
Time in seconds that the bootloader must stay in bootmode when CRC and Flashmode are OK (5)
331
Status bootloader
332
When=255 then Bootloader UART debug information is disabled (See also Memory Model page0/Byte94)

(4) In App mode, Flashmode will be put on 0. In bootloader, Flashmode will be checked to see if the app mode was running normally (Flashmode=0), if the application didn't put Flashmode on 0, the bootloader will remain longer in bootloader mode. The Bootloader will put Flashmode on 4.

(5) When the CRC is wrong, the slave will stay in Bootloader until the CRC error is resolved (by writing the correct CRC in address 324-327 or by loading the correct firmware). When the Flashmode is not correctly written during normal operations (thus something is wrong in the app), the slave will remain in bootloader for 10 seconds before trying app mode again.

Changes made in slave Firmware

  • Following has been added in the 18F45K80.inc file: CONFIG PLLCFG = ON
  • The OSCON and OSCTUNE are not used anymore in the firmware itself
  • The eeprom variables have been adapted to keep firmware version in eeprom
  • The Bootloader instructions have been added (FV and FR)