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#pragma once
7
8#include <stdint.h>
10#include <golioth/client.h>
11#include <golioth/config.h>
12
18
20#define GOLIOTH_OTA_BLOCKSIZE 1024
22#define GOLIOTH_OTA_COMPONENT_HASH_LEN 64
24#define GOLIOTH_OTA_MAX_COMPONENT_BOOTLOADER_NAME_LEN 7
26#define GOLIOTH_OTA_MAX_COMPONENT_URI_LEN \
27 (CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN + CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN + 7)
28
41
66
85
96
106 size_t payload_size,
107 struct golioth_ota_manifest *manifest);
108
110size_t golioth_ota_size_to_nblocks(size_t component_size);
111
120 const struct golioth_ota_manifest *manifest,
121 const char *package);
122
128enum golioth_status golioth_ota_observe_manifest_async(struct golioth_client *client,
129 golioth_get_cb_fn callback,
130 void *arg);
131
160enum golioth_status golioth_ota_get_block_sync(struct golioth_client *client,
161 const char *package,
162 const char *version,
163 size_t block_index,
164 uint8_t *buf,
165 size_t *block_nbytes,
166 bool *is_last,
167 int32_t timeout_s);
168
184enum golioth_status golioth_ota_report_state_sync(struct golioth_client *client,
185 enum golioth_ota_state state,
186 enum golioth_ota_reason reason,
187 const char *package,
188 const char *current_version,
189 const char *target_version,
190 int32_t timeout_s);
191
196
#define CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN
Definition config.h:69
#define CONFIG_GOLIOTH_OTA_MAX_NUM_COMPONENTS
Definition config.h:73
#define CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN
Definition config.h:65
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:146
#define GOLIOTH_OTA_MAX_COMPONENT_BOOTLOADER_NAME_LEN
Maximum size of Binary Detected Type in bytes.
Definition ota.h:24
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)
Convert a size in bytes to the number of blocks required (of size up to GOLIOTH_OTA_BLOCKSIZE)
#define GOLIOTH_OTA_MAX_COMPONENT_URI_LEN
Maximum size of Relative URI to download binary (+ 7 bytes for Path)
Definition ota.h:26
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:31
#define GOLIOTH_OTA_COMPONENT_HASH_LEN
Size of a SHA256 of Artifact Binary in bytes.
Definition ota.h:22
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:44
@ GOLIOTH_OTA_STATE_DOWNLOADED
OTA has been downloaded and written to flash.
Definition ota.h:37
@ GOLIOTH_OTA_STATE_IDLE
No OTA update in progress.
Definition ota.h:33
@ GOLIOTH_OTA_STATE_UPDATING
OTA is being applied to the system, but is not yet complete.
Definition ota.h:39
@ GOLIOTH_OTA_STATE_DOWNLOADING
OTA is being downloaded and written to flash.
Definition ota.h:35
@ GOLIOTH_OTA_REASON_FIRMWARE_UPDATE_FAILED
Firmware update was not successful.
Definition ota.h:62
@ GOLIOTH_OTA_REASON_OUT_OF_RAM
Insufficient RAM on device.
Definition ota.h:52
@ GOLIOTH_OTA_REASON_INVALID_URI
URI not valid.
Definition ota.h:60
@ GOLIOTH_OTA_REASON_CONNECTION_LOST
Lost connection to server during OTA update.
Definition ota.h:54
@ GOLIOTH_OTA_REASON_UNSUPPORTED_PROTOCOL
Protocol not supported.
Definition ota.h:64
@ GOLIOTH_OTA_REASON_NOT_ENOUGH_FLASH_MEMORY
Insufficient flash memory on device.
Definition ota.h:50
@ GOLIOTH_OTA_REASON_READY
OTA update is ready to go. Also used for "no reason".
Definition ota.h:46
@ GOLIOTH_OTA_REASON_FIRMWARE_UPDATED_SUCCESSFULLY
Firmware update was successful.
Definition ota.h:48
@ GOLIOTH_OTA_REASON_INTEGRITY_CHECK_FAILURE
Data integrity check of downloaded artifact failed.
Definition ota.h:56
@ GOLIOTH_OTA_REASON_UNSUPPORTED_PACKAGE_TYPE
Package type not supported.
Definition ota.h:58
A component/artifact within an OTA manifest.
Definition ota.h:69
char bootloader[GOLIOTH_OTA_MAX_COMPONENT_BOOTLOADER_NAME_LEN+1]
Artifact bootloader ("mcuboot" or "default"")
Definition ota.h:83
char uri[GOLIOTH_OTA_MAX_COMPONENT_URI_LEN+1]
Artifact uri (e.g. "/.u/c/[email protected]")
Definition ota.h:81
bool is_compressed
True, if the component is compressed and requires decompression.
Definition ota.h:77
char version[CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN+1]
Artifact version (e.g. "1.0.0")
Definition ota.h:73
int32_t size
Size of the artifact, in bytes.
Definition ota.h:75
char package[CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN+1]
Artifact package name (e.g. "main")
Definition ota.h:71
char hash[GOLIOTH_OTA_COMPONENT_HASH_LEN+1]
Artifact Hash.
Definition ota.h:79
An OTA manifest, composed of multiple components/artifacts.
Definition ota.h:88
struct golioth_ota_component components[CONFIG_GOLIOTH_OTA_MAX_NUM_COMPONENTS]
An array of artifacts.
Definition ota.h:92
int32_t seqnum
OTA release sequence number.
Definition ota.h:90
size_t num_components
Number of artifacts.
Definition ota.h:94