Virgil IoT KIT
firmware.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2020 Virgil Security, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // (1) Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // (2) Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in
14 // the documentation and/or other materials provided with the
15 // distribution.
16 //
17 // (3) Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
22 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 // DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
34 
209 #ifndef VS_FIRMWARE_H
210 #define VS_FIRMWARE_H
211 
217 
218 #ifdef __cplusplus
219 namespace VirgilIoTKit {
220 extern "C" {
221 #endif
222 
224 typedef struct __attribute__((__packed__)) {
226  uint8_t padding;
227  uint16_t chunk_size;
228  uint32_t firmware_length;
229  uint32_t app_size;
231 
233 typedef struct __attribute__((__packed__)) {
236  uint8_t signatures[];
238 
240 typedef struct __attribute__((__packed__)) {
241  uint32_t code_offset;
242  uint32_t code_length;
243  uint32_t footer_offset;
244  uint32_t footer_length;
248 
263  vs_secmodule_impl_t *secmodule,
264  vs_device_manufacture_id_t manufacture,
265  vs_device_type_t device_type,
266  vs_file_version_t *ver);
267 
274 vs_firmware_deinit(void);
275 
291  const uint8_t *chunk,
292  size_t chunk_sz,
293  size_t offset);
294 
307 vs_firmware_save_firmware_footer(const vs_firmware_descriptor_t *descriptor, const uint8_t *footer);
308 
325  uint32_t offset,
326  uint8_t *data,
327  size_t buf_sz,
328  size_t *data_sz);
329 
345  uint8_t *data,
346  size_t buff_sz,
347  size_t *data_sz);
348 
361 
370 
381 
394  const uint8_t device_type[VS_DEVICE_TYPE_SIZE],
395  vs_firmware_descriptor_t *descriptor);
396 
409 
422 
435 
442 int
444 
454 
462 const vs_update_file_type_t *
464 
473 void
475 
484 void
486 
495 void
497 
506 void
508 
509 #ifdef __cplusplus
510 } // extern "C"
511 } // namespace VirgilIoTKit
512 #endif
513 
514 #endif // VS_FIRMWARE_H
vs_device_manufacture_id_t
uint8_t vs_device_manufacture_id_t[VS_DEVICE_MANUFACTURE_ID_SIZE]
Manufacture ID type.
Definition: provision-structs.h:120
vs_firmware_update_file_type
const vs_update_file_type_t * vs_firmware_update_file_type(void)
Return firmware file type for Update library.
vs_firmware_header_t
Firmware header.
Definition: firmware.h:240
vs_firmware_descriptor_t
Firmware descriptor.
Definition: firmware.h:224
vs_update_file_type_t
File type information.
Definition: update.h:70
vs_firmware_load_firmware_descriptor
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.
vs_firmware_descriptor_t::chunk_size
uint16_t chunk_size
Chunk size.
Definition: firmware.h:227
vs_firmware_verify_firmware
vs_status_e vs_firmware_verify_firmware(const vs_firmware_descriptor_t *descriptor)
Verify firmware.
vs_secmodule_impl_t
Security Module implementation.
Definition: secmodule.h:458
vs_firmware_get_expected_footer_len
int vs_firmware_get_expected_footer_len(void)
Get expected firmware footer length.
vs_firmware_header_t::descriptor
vs_firmware_descriptor_t descriptor
Firnware descriptor.
Definition: firmware.h:246
vs_firmware_hton_descriptor
void vs_firmware_hton_descriptor(vs_firmware_descriptor_t *desc)
hton conversion for descriptor
vs_file_info_t
File information.
Definition: provision-structs.h:225
vs_status_e
vs_status_e
Status code.
Definition: status_code.h:77
vs_firmware_hton_header
void vs_firmware_hton_header(vs_firmware_header_t *header)
hton conversion for header
vs_firmware_descriptor_t::info
vs_file_info_t info
File information.
Definition: firmware.h:225
VS_DEVICE_MANUFACTURE_ID_SIZE
#define VS_DEVICE_MANUFACTURE_ID_SIZE
Manufacture ID size.
Definition: provision-structs.h:111
VS_DEVICE_TYPE_SIZE
#define VS_DEVICE_TYPE_SIZE
Device type size.
Definition: provision-structs.h:114
vs_firmware_save_firmware_chunk
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.
update.h
Update interface for files downloading.
vs_file_version_t
File version information.
Definition: provision-structs.h:216
vs_device_type_t
uint8_t vs_device_type_t[VS_DEVICE_TYPE_SIZE]
Device type.
Definition: provision-structs.h:127
provision.h
Provision interface.
vs_firmware_header_t::code_offset
uint32_t code_offset
Code offset = sizeof(vs_firmware_header_t)
Definition: firmware.h:241
vs_firmware_get_own_firmware_descriptor
vs_status_e vs_firmware_get_own_firmware_descriptor(vs_firmware_descriptor_t *descriptor)
Get own firmware descriptor.
vs_firmware_header_t::footer_length
uint32_t footer_length
Footer length.
Definition: firmware.h:244
vs_firmware_update_ctx
vs_update_interface_t * vs_firmware_update_ctx(void)
Return firmware Update interface.
status_code.h
Status codes and macroses.
vs_firmware_load_firmware_chunk
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.
vs_firmware_descriptor_t::padding
uint8_t padding
Padding.
Definition: firmware.h:226
vs_firmware_descriptor_t::firmware_length
uint32_t firmware_length
Firmware length.
Definition: firmware.h:228
vs_firmware_delete_firmware
vs_status_e vs_firmware_delete_firmware(const vs_firmware_descriptor_t *descriptor)
Delete firmware.
vs_firmware_ntoh_header
void vs_firmware_ntoh_header(vs_firmware_header_t *header)
ntoh conversion for header
vs_firmware_save_firmware_descriptor
vs_status_e vs_firmware_save_firmware_descriptor(const vs_firmware_descriptor_t *descriptor)
Save firmware descriptor.
vs_storage_op_ctx_t
Storage element context.
Definition: storage_hal.h:221
vs_firmware_init
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.
vs_firmware_header_t::code_length
uint32_t code_length
Code length = vs_firmware_descriptor_t .
Definition: firmware.h:242
vs_firmware_header_t::signatures_count
uint8_t signatures_count
Signatures amount.
Definition: firmware.h:245
vs_firmware_deinit
vs_status_e vs_firmware_deinit(void)
Destroy firmware module.
vs_firmware_compare_own_version
vs_status_e vs_firmware_compare_own_version(const vs_firmware_descriptor_t *new_descriptor)
Compare own firmware version with the given one.
storage_hal.h
Storage HAL interface.
vs_firmware_load_firmware_footer
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.
vs_update_interface_t
Update interface context.
Definition: update.h:284
vs_firmware_header_t::footer_offset
uint32_t footer_offset
Footer offset = code_offset + code_length.
Definition: firmware.h:243
vs_firmware_save_firmware_footer
vs_status_e vs_firmware_save_firmware_footer(const vs_firmware_descriptor_t *descriptor, const uint8_t *footer)
Save firmware footer.
vs_firmware_install_firmware
vs_status_e vs_firmware_install_firmware(const vs_firmware_descriptor_t *descriptor)
Install firmware.
secmodule.h
Security Module implementations signatures.
vs_firmware_ntoh_descriptor
void vs_firmware_ntoh_descriptor(vs_firmware_descriptor_t *desc)
ntoh conversion for descriptor
vs_firmware_descriptor_t::app_size
uint32_t app_size
Application size = firmware_length + fill_size + footer.
Definition: firmware.h:229