Virgil IoT KIT
|
Firmware uploading/downloading and installation implementation. More...
#include <virgil/iot/storage_hal/storage_hal.h>
#include <virgil/iot/status_code/status_code.h>
#include <virgil/iot/provision/provision.h>
#include <virgil/iot/update/update.h>
#include <virgil/iot/secmodule/secmodule.h>
Go to the source code of this file.
Data Structures | |
struct | vs_firmware_descriptor_t |
Firmware descriptor. More... | |
struct | vs_firmware_footer_t |
Firmware footer. More... | |
struct | vs_firmware_header_t |
Firmware header. More... | |
Firmware uploading/downloading and installation implementation.
Devices use Firmware library to delete, verify and install firmware obtained from Gateway (Thing devices) or cloud (Gateway devices).
Gateway uses Firmware library for different purposes :
First of all it is necessary to initialize Firmware library :
Firmware storage implementation fw_storage_impl initialization is described in Storage HAL Usage section.
You can use software security module vs_soft_secmodule_impl() as it is done in this example.
manufacture_id, device_type are device unique characteristics and can be initialized by compile time constants. See Provision structures usage for details
For FLDT Server service (see FLDT Server Usage for details) it is necessary to implement vs_fldt_server_add_filetype_cb. Also it is necessary to add Firmware file type to the supported file types list by calling vs_fldt_server_add_file_type() :
In this example _add_filetype processes 2 standard file types. One of them is Firmware file type.
Gateway receives firmwares for different targets from Cloud. It necessary to verify them and to broadcast information about the new firmware by using FLDT Server service :
In this example Gateway receives firmware header by using Cloud module (see Cloud Usage for details ). It verifies the received firmware. In case of error it deletes the firmware. In another case it analyzes this firmware type (_is_self_firmware_image call). If this firmware is intended for this gateway, the gateway installs it (_process_own_firmware call). Otherwise it sends firmware to devices by using FLDT Server service (vs_fldt_server_add_file_type() call) :
All Firmware functionality for Thing is implemented by Virgil IoT KIT. User only needs to initialize Firmware library and destroy it at the end. See code example below :
Firmware storage implementation fw_storage_impl initialization is described in Storage HAL Usage section.
Security module implementation secmodule_impl initialization is described in Storage HAL Usage section. You can use software security module vs_soft_secmodule_impl() as shown in the example above.
manufacture_id, device_type are device unique characteristics and can be initialized by compile time constants. See Provision structures usage for details
vs_status_e vs_firmware_compare_own_version | ( | const vs_firmware_descriptor_t * | new_descriptor | ) |
Compare own firmware version with the given one.
Thing automatically compares its own version with the new_descriptor one.
See Firmware Usage by Gateway for data flow details.
[in] | descriptor | vs_firmware_descriptor_t firmware descriptor. Must not be NULL. |
vs_status_e vs_firmware_deinit | ( | void | ) |
Destroy firmware module.
It has to be executed before application finish.
vs_status_e vs_firmware_delete_firmware | ( | const vs_firmware_descriptor_t * | descriptor | ) |
Delete firmware.
Thing automatically deletes firmware in case of invalid data.
See Firmware Usage by Gateway for data flow details.
[in] | descriptor | vs_firmware_descriptor_t firmware descriptor. Must not be NULL. |
int vs_firmware_get_expected_footer_len | ( | void | ) |
Get expected firmware footer length.
This call returns firmware footer length.
vs_status_e vs_firmware_get_own_firmware_descriptor | ( | vs_firmware_descriptor_t * | descriptor | ) |
Get own firmware descriptor.
Gets own firmware description by both Gateway and Thing.
[out] | descriptor | vs_firmware_descriptor_t Output own firmware descriptor. Must not be NULL. |
void vs_firmware_hton_descriptor | ( | vs_firmware_descriptor_t * | desc | ) |
hton conversion for descriptor
This call makes host-to-network firmware descriptor conversion.
[in,out] | desc | firmware descriptor. Must not be NULL. |
void vs_firmware_hton_header | ( | vs_firmware_header_t * | header | ) |
hton conversion for header
This call makes host-to-network firmware header conversion.
[in,out] | desc | firmware descriptor. Must not be NULL. |
vs_status_e vs_firmware_init | ( | vs_storage_op_ctx_t * | ctx, |
vs_secmodule_impl_t * | secmodule, | ||
vs_device_manufacture_id_t | manufacture, | ||
vs_device_type_t | device_type, | ||
vs_file_version_t * | ver | ||
) |
Initialize firmware.
Firmware initialization has to be done before first Firmware calls.
[in] | ctx | vs_storage_op_ctx_t storage context. Must not be NULL. |
[in] | secmodule | vs_secmodule_impl_t Security Module implementation. Must not be NULL. |
[in] | manufacture | Manufacture ID |
[in] | device_type | Device type |
[out] | ver | Pointer to vs_file_version_t. Will be filled by a current version of firmware. |
vs_status_e vs_firmware_install_firmware | ( | const vs_firmware_descriptor_t * | descriptor | ) |
Install firmware.
Thing automatically installs firmware in case of successful verification.
See Firmware Usage by Gateway for data flow details.
[in] | descriptor | vs_firmware_descriptor_t firmware descriptor. Must not be NULL. |
vs_status_e vs_firmware_load_firmware_chunk | ( | const vs_firmware_descriptor_t * | descriptor, |
uint32_t | offset, | ||
uint8_t * | data, | ||
size_t | buf_sz, | ||
size_t * | data_sz | ||
) |
Load firmware data.
Gateway loads a chunk of data to send it to Thing.
See Firmware Usage by Gateway for data flow details.
[in] | descriptor | vs_firmware_descriptor_t firmware descriptor. Must not be NULL. |
[in] | offset | Data offset. |
[out] | data | Data to save data. Must not be NULL. |
[in] | buf_sz | Buffer size. |
[out] | data_sz | Stored data size. Must not be NULL. |
vs_status_e vs_firmware_load_firmware_descriptor | ( | const uint8_t | manufacture_id[VS_DEVICE_MANUFACTURE_ID_SIZE], |
const uint8_t | device_type[VS_DEVICE_TYPE_SIZE], | ||
vs_firmware_descriptor_t * | descriptor | ||
) |
Load firmware descriptor.
Gets firmware descriptor for specified manufacture and device type.
[in] | manufacture_id | Manufacture ID. |
[in] | device_type | Device type. |
[out] | descriptor | vs_firmware_descriptor_t Output firmware descriptor. Must not be NULL. |
vs_status_e vs_firmware_load_firmware_footer | ( | const vs_firmware_descriptor_t * | descriptor, |
uint8_t * | data, | ||
size_t | buff_sz, | ||
size_t * | data_sz | ||
) |
Load firmware footer.
Gateway loads firmware footer to send it to Thing.
See Firmware Usage by Gateway for data flow details.
[in] | descriptor | vs_firmware_descriptor_t firmware descriptor. Must not be NULL. |
[out] | data | Buffer to store firmware in. Must not be NULL. |
[in] | buff_sz | Buffer size. Must not be zero. |
[out] | data_sz | Saved footer size. Must not be NULL. |
void vs_firmware_ntoh_descriptor | ( | vs_firmware_descriptor_t * | desc | ) |
ntoh conversion for descriptor
This call makes network-to-host firmware descriptor conversion.
[in,out] | desc | firmware descriptor. Must not be NULL. |
void vs_firmware_ntoh_header | ( | vs_firmware_header_t * | header | ) |
ntoh conversion for header
This call makes network-to-host firmware header conversion.
[in,out] | desc | firmware descriptor. Must not be NULL. |
vs_status_e vs_firmware_save_firmware_chunk | ( | const vs_firmware_descriptor_t * | descriptor, |
const uint8_t * | chunk, | ||
size_t | chunk_sz, | ||
size_t | offset | ||
) |
Save firmware data.
Gateway saves a chunk of data received from Cloud. Thing automatically saves the chunk of data received from Gateway.
See Firmware Usage by Gateway for data flow details.
[in] | descriptor | vs_firmware_descriptor_t firmware descriptor. Must not be NULL. |
[in] | chunk | Data buffer. Must not be NULL. |
[in] | chunk_sz | Data size. Must not be zero. |
[in] | offset | Data offset. |
vs_status_e vs_firmware_save_firmware_descriptor | ( | const vs_firmware_descriptor_t * | descriptor | ) |
Save firmware descriptor.
[in] | descriptor | vs_firmware_descriptor_t firmware descriptor. Must not be NULL. |
vs_status_e vs_firmware_save_firmware_footer | ( | const vs_firmware_descriptor_t * | descriptor, |
const uint8_t * | footer | ||
) |
Save firmware footer.
Gateway saves firmware footer received from Cloud. Thing automatically saves footer firmware received from Gateway.
See Firmware Usage by Gateway for data flow details.
[in] | descriptor | vs_firmware_descriptor_t firmware descriptor. Must not be NULL. |
[in] | footer | Firmware footer. Must not be NULL. |
vs_update_interface_t* vs_firmware_update_ctx | ( | void | ) |
Return firmware Update interface.
This call returns Update implementation. It is used for Update calls.
const vs_update_file_type_t* vs_firmware_update_file_type | ( | void | ) |
Return firmware file type for Update library.
This call returns file type information for Update library. It is used for Update calls.
vs_status_e vs_firmware_verify_firmware | ( | const vs_firmware_descriptor_t * | descriptor | ) |
Verify firmware.
Gateway verifies firmware received from Cloud. Thing verifies firmware before its installation.
See Firmware Usage by Gateway for data flow details.
[in] | descriptor | vs_firmware_descriptor_t firmware descriptor. Must not be NULL. |