Golioth Firmware SDK
Loading...
Searching...
No Matches
ota.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Golioth, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifdef __cplusplus
8extern "C"
9{
10#endif
11
12#pragma once
13
14#include <stdint.h>
16#include <golioth/client.h>
17#include <golioth/config.h>
18
24
26#define GOLIOTH_OTA_BLOCKSIZE 1024
28#define GOLIOTH_OTA_COMPONENT_HASH_LEN 64
30#define GOLIOTH_OTA_MAX_COMPONENT_BOOTLOADER_NAME_LEN 7
32#define GOLIOTH_OTA_MAX_COMPONENT_URI_LEN \
33 (CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN + CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN + 7)
34
47
72
91
102
112 size_t payload_size,
113 struct golioth_ota_manifest *manifest);
114
116size_t golioth_ota_size_to_nblocks(size_t component_size);
117
126 const struct golioth_ota_manifest *manifest,
127 const char *package);
128
134enum golioth_status golioth_ota_observe_manifest_async(struct golioth_client *client,
135 golioth_get_cb_fn callback,
136 void *arg);
137
139 const struct golioth_ota_component *component,
140 uint32_t block_idx,
141 uint8_t *block_buffer,
142 size_t block_size,
143 bool is_last,
144 void *arg);
145
146enum golioth_status golioth_ota_download_component(struct golioth_client *client,
147 const struct golioth_ota_component *component,
149 void *arg);
150
179enum golioth_status golioth_ota_get_block_sync(struct golioth_client *client,
180 const char *package,
181 const char *version,
182 size_t block_index,
183 uint8_t *buf,
184 size_t *block_nbytes,
185 bool *is_last,
186 int32_t timeout_s);
187
203enum golioth_status golioth_ota_report_state_sync(struct golioth_client *client,
204 enum golioth_ota_state state,
205 enum golioth_ota_reason reason,
206 const char *package,
207 const char *current_version,
208 const char *target_version,
209 int32_t timeout_s);
210
215
217
218#ifdef __cplusplus
219}
220#endif
#define CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN
Definition config.h:75
#define CONFIG_GOLIOTH_OTA_MAX_NUM_COMPONENTS
Definition config.h:79
#define CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN
Definition config.h:71
golioth_status
void(* golioth_get_cb_fn)(struct golioth_client *client, const struct golioth_response *response, const char *path, const uint8_t *payload, size_t payload_size, void *arg)
Definition client.h:153
#define GOLIOTH_OTA_MAX_COMPONENT_BOOTLOADER_NAME_LEN
Maximum size of Binary Detected Type in bytes.
Definition ota.h:30
enum golioth_status golioth_ota_report_state_sync(struct golioth_client *client, enum golioth_ota_state state, enum golioth_ota_reason reason, const char *package, const char *current_version, const char *target_version, int32_t timeout_s)
enum golioth_ota_state golioth_ota_get_state(void)
enum golioth_status golioth_ota_observe_manifest_async(struct golioth_client *client, golioth_get_cb_fn callback, void *arg)
enum golioth_status golioth_ota_download_component(struct golioth_client *client, const struct golioth_ota_component *component, ota_component_block_write_cb cb, void *arg)
size_t golioth_ota_size_to_nblocks(size_t component_size)
Convert a size in bytes to the number of blocks required (of size up to GOLIOTH_OTA_BLOCKSIZE)
enum golioth_status(* ota_component_block_write_cb)(const struct golioth_ota_component *component, uint32_t block_idx, uint8_t *block_buffer, size_t block_size, bool is_last, void *arg)
Definition ota.h:138
#define GOLIOTH_OTA_MAX_COMPONENT_URI_LEN
Maximum size of Relative URI to download binary (+ 7 bytes for Path)
Definition ota.h:32
const struct golioth_ota_component * golioth_ota_find_component(const struct golioth_ota_manifest *manifest, const char *package)
golioth_ota_state
State of OTA update, reported to Golioth server.
Definition ota.h:37
#define GOLIOTH_OTA_COMPONENT_HASH_LEN
Size of a SHA256 of Artifact Binary in bytes.
Definition ota.h:28
enum golioth_status golioth_ota_payload_as_manifest(const uint8_t *payload, size_t payload_size, struct golioth_ota_manifest *manifest)
enum golioth_status golioth_ota_get_block_sync(struct golioth_client *client, const char *package, const char *version, size_t block_index, uint8_t *buf, size_t *block_nbytes, bool *is_last, int32_t timeout_s)
golioth_ota_reason
A reason associated with state changes.
Definition ota.h:50
@ GOLIOTH_OTA_STATE_DOWNLOADED
OTA has been downloaded and written to flash.
Definition ota.h:43
@ GOLIOTH_OTA_STATE_IDLE
No OTA update in progress.
Definition ota.h:39
@ GOLIOTH_OTA_STATE_UPDATING
OTA is being applied to the system, but is not yet complete.
Definition ota.h:45
@ GOLIOTH_OTA_STATE_DOWNLOADING
OTA is being downloaded and written to flash.
Definition ota.h:41
@ GOLIOTH_OTA_REASON_FIRMWARE_UPDATE_FAILED
Firmware update was not successful.
Definition ota.h:68
@ GOLIOTH_OTA_REASON_OUT_OF_RAM
Insufficient RAM on device.
Definition ota.h:58
@ GOLIOTH_OTA_REASON_INVALID_URI
URI not valid.
Definition ota.h:66
@ GOLIOTH_OTA_REASON_CONNECTION_LOST
Lost connection to server during OTA update.
Definition ota.h:60
@ GOLIOTH_OTA_REASON_UNSUPPORTED_PROTOCOL
Protocol not supported.
Definition ota.h:70
@ GOLIOTH_OTA_REASON_NOT_ENOUGH_FLASH_MEMORY
Insufficient flash memory on device.
Definition ota.h:56
@ GOLIOTH_OTA_REASON_READY
OTA update is ready to go. Also used for "no reason".
Definition ota.h:52
@ GOLIOTH_OTA_REASON_FIRMWARE_UPDATED_SUCCESSFULLY
Firmware update was successful.
Definition ota.h:54
@ GOLIOTH_OTA_REASON_INTEGRITY_CHECK_FAILURE
Data integrity check of downloaded artifact failed.
Definition ota.h:62
@ GOLIOTH_OTA_REASON_UNSUPPORTED_PACKAGE_TYPE
Package type not supported.
Definition ota.h:64
A component/artifact within an OTA manifest.
Definition ota.h:75
char bootloader[GOLIOTH_OTA_MAX_COMPONENT_BOOTLOADER_NAME_LEN+1]
Artifact bootloader ("mcuboot" or "default"")
Definition ota.h:89
char uri[GOLIOTH_OTA_MAX_COMPONENT_URI_LEN+1]
Artifact uri (e.g. "/.u/c/[email protected]")
Definition ota.h:87
bool is_compressed
True, if the component is compressed and requires decompression.
Definition ota.h:83
char version[CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN+1]
Artifact version (e.g. "1.0.0")
Definition ota.h:79
int32_t size
Size of the artifact, in bytes.
Definition ota.h:81
char package[CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN+1]
Artifact package name (e.g. "main")
Definition ota.h:77
char hash[GOLIOTH_OTA_COMPONENT_HASH_LEN+1]
Artifact Hash.
Definition ota.h:85
An OTA manifest, composed of multiple components/artifacts.
Definition ota.h:94
struct golioth_ota_component components[CONFIG_GOLIOTH_OTA_MAX_NUM_COMPONENTS]
An array of artifacts.
Definition ota.h:98
int32_t seqnum
OTA release sequence number.
Definition ota.h:96
size_t num_components
Number of artifacts.
Definition ota.h:100