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_COMPONENT_HEX_HASH_LEN 64
28#define GOLIOTH_OTA_COMPONENT_BIN_HASH_LEN 32
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
76
93
104
114 size_t payload_size,
115 struct golioth_ota_manifest *manifest);
116
119size_t golioth_ota_size_to_nblocks(size_t component_size);
120
129 const struct golioth_ota_manifest *manifest,
130 const char *package);
131
141enum golioth_status golioth_ota_observe_manifest_async(struct golioth_client *client,
142 golioth_get_cb_fn callback,
143 void *arg);
144
153enum golioth_status golioth_ota_get_manifest_async(struct golioth_client *client,
154 golioth_get_cb_fn callback,
155 void *arg);
156
169 const struct golioth_ota_component *component,
170 uint32_t block_idx,
171 const uint8_t *block_buffer,
172 size_t block_buffer_len,
173 bool is_last,
174 size_t negotiated_block_size,
175 void *arg);
176
189 const struct golioth_coap_rsp_code *rsp_code,
190 const struct golioth_ota_component *component,
191 uint32_t block_idx,
192 void *arg);
193
219enum golioth_status golioth_ota_download_component(struct golioth_client *client,
220 const struct golioth_ota_component *component,
221 uint32_t block_idx,
224 void *arg);
225
254enum golioth_status golioth_ota_get_block_sync(struct golioth_client *client,
255 const char *package,
256 const char *version,
257 size_t block_index,
258 uint8_t *buf,
259 size_t *block_nbytes,
260 bool *is_last,
261 int32_t timeout_s);
262
278enum golioth_status golioth_ota_report_state_sync(struct golioth_client *client,
279 enum golioth_ota_state state,
280 enum golioth_ota_reason reason,
281 const char *package,
282 const char *current_version,
283 const char *target_version,
284 int32_t timeout_s);
285
290
292
293#ifdef __cplusplus
294}
295#endif
#define CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN
Definition config.h:77
#define CONFIG_GOLIOTH_OTA_MAX_NUM_COMPONENTS
Definition config.h:81
#define CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN
Definition config.h:73
golioth_status
void(* golioth_get_cb_fn)(struct golioth_client *client, enum golioth_status status, const struct golioth_coap_rsp_code *coap_rsp_code, const char *path, const uint8_t *payload, size_t payload_size, void *arg)
Definition client.h:158
#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)
size_t golioth_ota_size_to_nblocks(size_t component_size)
void(* ota_component_download_end_cb)(enum golioth_status status, const struct golioth_coap_rsp_code *rsp_code, const struct golioth_ota_component *component, uint32_t block_idx, void *arg)
Definition ota.h:188
enum golioth_status(* ota_component_block_write_cb)(const struct golioth_ota_component *component, uint32_t block_idx, const uint8_t *block_buffer, size_t block_buffer_len, bool is_last, size_t negotiated_block_size, void *arg)
Definition ota.h:168
#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_BIN_HASH_LEN
Size of a SHA256 of Artifact bin array 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)
enum golioth_status golioth_ota_get_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, uint32_t block_idx, ota_component_block_write_cb block_cb, ota_component_download_end_cb end_cb, void *arg)
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_IO
IO error while trying to store component.
Definition ota.h:72
@ 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
@ GOLIOTH_OTA_REASON_AWAIT_RETRY
Awaiting retry.
Definition ota.h:74
CoAP response code returned by server.
Definition client.h:53
A component/artifact within an OTA manifest.
Definition ota.h:79
char bootloader[GOLIOTH_OTA_MAX_COMPONENT_BOOTLOADER_NAME_LEN+1]
Artifact bootloader ("mcuboot" or "default"")
Definition ota.h:91
uint8_t hash[GOLIOTH_OTA_COMPONENT_BIN_HASH_LEN]
Artifact Hash.
Definition ota.h:87
char uri[GOLIOTH_OTA_MAX_COMPONENT_URI_LEN+1]
Artifact uri (e.g. "/.u/c/main@1.2.3")
Definition ota.h:89
char version[CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN+1]
Artifact version (e.g. "1.0.0")
Definition ota.h:83
int32_t size
Size of the artifact, in bytes.
Definition ota.h:85
char package[CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN+1]
Artifact package name (e.g. "main")
Definition ota.h:81
An OTA manifest, composed of multiple components/artifacts.
Definition ota.h:96
struct golioth_ota_component components[CONFIG_GOLIOTH_OTA_MAX_NUM_COMPONENTS]
An array of artifacts.
Definition ota.h:100
int32_t seqnum
OTA release sequence number.
Definition ota.h:98
size_t num_components
Number of artifacts.
Definition ota.h:102