INFINITEHEARTRESOURCES.INFO

Updating fota keisha want

Firmware Over the Air update (FOTA)¶

This module enables access to VM functionalities for updating firmware and/or VM at runtime. It can be safely imported in every program, however its functions will raise UnsupportedError if the target VM is not enabled for FOTA features (available for Pro users only).

In Zerynth FOTA can be performed for bytecode only or for bytecode and VM if the target device supports a multiple VM layout. In order to support FOTA updates, the flash memory of the target device is divided in segments that can hold either a VM or bytecode. Moreover a small segment of persistent memory (not necessary flash) must be allocated to store the current and desired state of the firmware (FOTA record).

The following layouts show different flash organization for FOTA support:

FOTA process for bytecode only¶

The FOTA process consists of the following steps:

  • check the FOTA record structure to ensure that the current VM+Bytecode slot configuration is functioning correctly ()
  • identify the available slot for the new bytecode ()
  • erase the bytecode slot to make room for new bytecode ()
  • write the binary representation of the new bytecode to the slot ()
  • optionally check that the new bytecode has been written correctly ()
  • modify the FOTA record with the new desired configuration ()
  • restart the VM in the new configuration ()
  • the new bytecode should check that everything is ok and confirm the configuration (). In case the new bytecode is faulty, a simple restart will bring the system back in the previously working configuration.

FOTA process for bytecode and VM¶

For some target devices it is possible to change both the bytecode and the VM in a single FOTA process.

The FOTA process in this case consists of the following steps:

  • check the FOTA record structure to ensure that the current VM+Bytecode slot configuration is functioning correctly ()
  • identify the available slot for the new bytecode () and for the new VM ()
  • erase the bytecode slot and vm slot to make room for new firmware ()
  • write the binary representation of the new bytecode and vm to the slots ()
  • optionally check that the new bytecode and vm have been written correctly ()
  • modify the FOTA record with the new desired configuration ()
  • restart the VM in the new configuration ()
  • the previous VM will start and behave as a bootloader passing control to the new VM
  • the new bytecode should check that everything is ok and confirm the configuration (). In case the new bytecode is faulty, a simple restart will bring the system back in the previously working configuration.

Important

for the new firmware to work after the FOTA process, it must be compiled and linked for the correct slots using the dedicated ZTC command (link)

Important

manually performing the FOTA process can be difficult. FOTA features can be easily tested by using the Zerynth ADM Library.

Important

The FOTA process can be performed WITHOUT stopping the current firmware execution until the very end of the process

FOTA functions¶

()¶

Return the FOTA record (fota) as a tuple of integers following this scheme:

  • fota[0] is 0 if the FOTA record is not valid
  • fota[2] is the slot of the current VM (as an index starting from 0)
  • fota[3] is the slot of the last working VM (as an index starting from 0)
  • fota[4] is the slot of the current bytecode (as an index starting from 0)
  • fota[5] is the slot of the last working bytecode (as an index starting from 0)
  • fota[6] is the flash address of the current bytecode
  • fota[7] is the flash address of the current VM
  • fota[8] is the OTA chunk
(newfota

Set the FOTA record (fota) to the values in newfota according to this scheme:

  • fota[2] = newfota[0], sets the current VM for next restart
  • fota[3] = newfota[1], sets the last working VM
  • fota[4] = newfota[2], set the current bytecode for the next restart
  • fota[5] = newfota[3], set the last working bytecode

All other fota elements are managed by the VM and cannot be changed

()¶

Return the address of next available bytecode slot.

()¶

Return the address of the next available vm slot. If the result of the function is equal to fota[7], the current VM does not support VM updates.

(addr, size

Erase the slot (either bytecode or VM) starting at for at least bytes. Since flash memories are often organized in sectors, the erased size can be larger than the requested size.

(addr, block

Write (bytes, bytearray or string) at where is an address contained in a bytecode or VM slot. This function does not keep count of the written blocks, it is up to the programmer to update the address correctly.

(addr, size

Return the MD5 checksum (as a bytes object) of the slot starting at and extending for bytes.

()¶

Reset the microcontroller and restart the system

()¶

Modify the FOTA record to make the current configuration the last working configuration. Must be called by the new bytecode in order to end the FOTA process correctly.

(bcslot, vmslot

Modify the FOTA record to make and (expressed as indexes starting from 0), the test configuration to be tried on restart.

SupportforFOTAupdateofbytecodeonly|------------------------------------------------------------------------------|||||||VM|BytecodeSlot0|BytecodeSlot1||<--FOTARecord||||||------------------------------------------------------------------------------|SupportforFOTAupdateofbytecodeandVM|------------------------------------------------------------------------------||||||||VM0|BytecodeSlot0|VM1|BytecodeSlot1||<--FOTARecord|||||||------------------------------------------------------------------------------|
https://docs.zerynth.com/latest/official/core.zerynth.stdlib/docs/official_core.zerynth.stdlib_fota.html