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_HASH_LEN 64
28#define GOLIOTH_OTA_MAX_COMPONENT_BOOTLOADER_NAME_LEN 7
30#define GOLIOTH_OTA_MAX_COMPONENT_URI_LEN \
31 (CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN + CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN + 7)
32
45
70
87
98
108 size_t payload_size,
109 struct golioth_ota_manifest *manifest);
110
113size_t golioth_ota_size_to_nblocks(size_t component_size);
114
123 const struct golioth_ota_manifest *manifest,
124 const char *package);
125
135enum golioth_status golioth_ota_observe_manifest_async(struct golioth_client *client,
136 golioth_get_cb_fn callback,
137 void *arg);
138
151 const struct golioth_ota_component *component,
152 uint32_t block_idx,
153 uint8_t *block_buffer,
154 size_t block_buffer_len,
155 bool is_last,
156 size_t negotiated_block_size,
157 void *arg);
158
185enum golioth_status golioth_ota_download_component(struct golioth_client *client,
186 const struct golioth_ota_component *component,
187 uint32_t *block_idx,
189 void *arg);
190
219enum golioth_status golioth_ota_get_block_sync(struct golioth_client *client,
220 const char *package,
221 const char *version,
222 size_t block_index,
223 uint8_t *buf,
224 size_t *block_nbytes,
225 bool *is_last,
226 int32_t timeout_s);
227
243enum golioth_status golioth_ota_report_state_sync(struct golioth_client *client,
244 enum golioth_ota_state state,
245 enum golioth_ota_reason reason,
246 const char *package,
247 const char *current_version,
248 const char *target_version,
249 int32_t timeout_s);
250
255
257
258#ifdef __cplusplus
259}
260#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, const struct golioth_response *response, const char *path, const uint8_t *payload, size_t payload_size, void *arg)
Definition client.h:155
#define GOLIOTH_OTA_MAX_COMPONENT_BOOTLOADER_NAME_LEN
Maximum size of Binary Detected Type in bytes.
Definition ota.h:28
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_status golioth_ota_download_component(struct golioth_client *client, const struct golioth_ota_component *component, uint32_t *block_idx, ota_component_block_write_cb cb, void *arg)
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)
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_buffer_len, bool is_last, size_t negotiated_block_size, void *arg)
Definition ota.h:150
#define GOLIOTH_OTA_MAX_COMPONENT_URI_LEN
Maximum size of Relative URI to download binary (+ 7 bytes for Path)
Definition ota.h:30
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:35
#define GOLIOTH_OTA_COMPONENT_HASH_LEN
Size of a SHA256 of Artifact Binary in bytes.
Definition ota.h:26
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:48
@ GOLIOTH_OTA_STATE_DOWNLOADED
OTA has been downloaded and written to flash.
Definition ota.h:41
@ GOLIOTH_OTA_STATE_IDLE
No OTA update in progress.
Definition ota.h:37
@ GOLIOTH_OTA_STATE_UPDATING
OTA is being applied to the system, but is not yet complete.
Definition ota.h:43
@ GOLIOTH_OTA_STATE_DOWNLOADING
OTA is being downloaded and written to flash.
Definition ota.h:39
@ GOLIOTH_OTA_REASON_FIRMWARE_UPDATE_FAILED
Firmware update was not successful.
Definition ota.h:66
@ GOLIOTH_OTA_REASON_OUT_OF_RAM
Insufficient RAM on device.
Definition ota.h:56
@ GOLIOTH_OTA_REASON_INVALID_URI
URI not valid.
Definition ota.h:64
@ GOLIOTH_OTA_REASON_CONNECTION_LOST
Lost connection to server during OTA update.
Definition ota.h:58
@ GOLIOTH_OTA_REASON_UNSUPPORTED_PROTOCOL
Protocol not supported.
Definition ota.h:68
@ GOLIOTH_OTA_REASON_NOT_ENOUGH_FLASH_MEMORY
Insufficient flash memory on device.
Definition ota.h:54
@ GOLIOTH_OTA_REASON_READY
OTA update is ready to go. Also used for "no reason".
Definition ota.h:50
@ GOLIOTH_OTA_REASON_FIRMWARE_UPDATED_SUCCESSFULLY
Firmware update was successful.
Definition ota.h:52
@ GOLIOTH_OTA_REASON_INTEGRITY_CHECK_FAILURE
Data integrity check of downloaded artifact failed.
Definition ota.h:60
@ GOLIOTH_OTA_REASON_UNSUPPORTED_PACKAGE_TYPE
Package type not supported.
Definition ota.h:62
A component/artifact within an OTA manifest.
Definition ota.h:73
char bootloader[GOLIOTH_OTA_MAX_COMPONENT_BOOTLOADER_NAME_LEN+1]
Artifact bootloader ("mcuboot" or "default"")
Definition ota.h:85
char uri[GOLIOTH_OTA_MAX_COMPONENT_URI_LEN+1]
Artifact uri (e.g. "/.u/c/[email protected]")
Definition ota.h:83
char version[CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN+1]
Artifact version (e.g. "1.0.0")
Definition ota.h:77
int32_t size
Size of the artifact, in bytes.
Definition ota.h:79
char package[CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN+1]
Artifact package name (e.g. "main")
Definition ota.h:75
char hash[GOLIOTH_OTA_COMPONENT_HASH_LEN+1]
Artifact Hash.
Definition ota.h:81
An OTA manifest, composed of multiple components/artifacts.
Definition ota.h:90
struct golioth_ota_component components[CONFIG_GOLIOTH_OTA_MAX_NUM_COMPONENTS]
An array of artifacts.
Definition ota.h:94
int32_t seqnum
OTA release sequence number.
Definition ota.h:92
size_t num_components
Number of artifacts.
Definition ota.h:96