Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset OTA fixes #2711

Merged
merged 6 commits into from Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/gcc-tools.mk
Expand Up @@ -14,7 +14,7 @@ endif

# C compiler flags
CFLAGS += -g3 -m64 -O$(GCC_OPTIMIZE) -gdwarf-2
CFLAGS += -Wno-unused-local-typedefs -Wno-pragmas
CFLAGS += -Wno-unused-local-typedefs -Wno-pragmas -Wno-overloaded-virtual
ASFLAGS += -g3


Expand Down
35 changes: 22 additions & 13 deletions proto_defs/src/cloud/describe.pb.h
Expand Up @@ -45,11 +45,6 @@ typedef enum _particle_cloud_FirmwareModuleValidityFlag {
} particle_cloud_FirmwareModuleValidityFlag;

/* Struct definitions */
typedef struct _particle_cloud_FirmwareModuleAsset {
pb_callback_t hash; /* /< SHA-256 hash */
pb_callback_t name; /* /< Asset name */
} particle_cloud_FirmwareModuleAsset;

/* *
System describe. */
typedef struct _particle_cloud_SystemDescribe {
Expand All @@ -73,8 +68,16 @@ typedef struct _particle_cloud_FirmwareModule {
pb_callback_t hash; /* /< SHA-256 hash */
pb_callback_t dependencies; /* /< Module dependencies */
pb_callback_t asset_dependencies; /* /< Asset dependencies */
uint32_t size; /* /< Actual module size */
} particle_cloud_FirmwareModule;

typedef struct _particle_cloud_FirmwareModuleAsset {
pb_callback_t hash; /* /< SHA-256 hash */
pb_callback_t name; /* /< Asset name */
uint32_t size; /* /< Asset size */
uint32_t storage_size; /* /< Asset storage size (taking into account compression and metadata) */
} particle_cloud_FirmwareModuleAsset;

/* *
Firmware module dependency. */
typedef struct _particle_cloud_FirmwareModuleDependency {
Expand Down Expand Up @@ -104,17 +107,15 @@ extern "C" {

/* Initializer values for message structs */
#define particle_cloud_FirmwareModuleDependency_init_default {_particle_cloud_FirmwareModuleType_MIN, 0, 0}
#define particle_cloud_FirmwareModuleAsset_init_default {{{NULL}, NULL}, {{NULL}, NULL}}
#define particle_cloud_FirmwareModule_init_default {_particle_cloud_FirmwareModuleType_MIN, 0, 0, _particle_cloud_FirmwareModuleStore_MIN, 0, 0, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}}
#define particle_cloud_FirmwareModuleAsset_init_default {{{NULL}, NULL}, {{NULL}, NULL}, 0, 0}
#define particle_cloud_FirmwareModule_init_default {_particle_cloud_FirmwareModuleType_MIN, 0, 0, _particle_cloud_FirmwareModuleStore_MIN, 0, 0, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, 0}
#define particle_cloud_SystemDescribe_init_default {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}}
#define particle_cloud_FirmwareModuleDependency_init_zero {_particle_cloud_FirmwareModuleType_MIN, 0, 0}
#define particle_cloud_FirmwareModuleAsset_init_zero {{{NULL}, NULL}, {{NULL}, NULL}}
#define particle_cloud_FirmwareModule_init_zero {_particle_cloud_FirmwareModuleType_MIN, 0, 0, _particle_cloud_FirmwareModuleStore_MIN, 0, 0, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}}
#define particle_cloud_FirmwareModuleAsset_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, 0, 0}
#define particle_cloud_FirmwareModule_init_zero {_particle_cloud_FirmwareModuleType_MIN, 0, 0, _particle_cloud_FirmwareModuleStore_MIN, 0, 0, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, 0}
#define particle_cloud_SystemDescribe_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}}

/* Field tags (for use in manual encoding/decoding) */
#define particle_cloud_FirmwareModuleAsset_hash_tag 1
#define particle_cloud_FirmwareModuleAsset_name_tag 2
#define particle_cloud_SystemDescribe_firmware_modules_tag 1
#define particle_cloud_SystemDescribe_imei_tag 2
#define particle_cloud_SystemDescribe_iccid_tag 3
Expand All @@ -130,6 +131,11 @@ extern "C" {
#define particle_cloud_FirmwareModule_hash_tag 8
#define particle_cloud_FirmwareModule_dependencies_tag 9
#define particle_cloud_FirmwareModule_asset_dependencies_tag 10
#define particle_cloud_FirmwareModule_size_tag 11
#define particle_cloud_FirmwareModuleAsset_hash_tag 1
#define particle_cloud_FirmwareModuleAsset_name_tag 2
#define particle_cloud_FirmwareModuleAsset_size_tag 3
#define particle_cloud_FirmwareModuleAsset_storage_size_tag 4
#define particle_cloud_FirmwareModuleDependency_type_tag 1
#define particle_cloud_FirmwareModuleDependency_index_tag 2
#define particle_cloud_FirmwareModuleDependency_version_tag 3
Expand All @@ -144,7 +150,9 @@ X(a, STATIC, SINGULAR, UINT32, version, 3)

#define particle_cloud_FirmwareModuleAsset_FIELDLIST(X, a) \
X(a, CALLBACK, SINGULAR, BYTES, hash, 1) \
X(a, CALLBACK, SINGULAR, STRING, name, 2)
X(a, CALLBACK, SINGULAR, STRING, name, 2) \
X(a, STATIC, SINGULAR, UINT32, size, 3) \
X(a, STATIC, SINGULAR, UINT32, storage_size, 4)
#define particle_cloud_FirmwareModuleAsset_CALLBACK pb_default_field_callback
#define particle_cloud_FirmwareModuleAsset_DEFAULT NULL

Expand All @@ -158,7 +166,8 @@ X(a, STATIC, SINGULAR, FIXED32, checked_flags, 6) \
X(a, STATIC, SINGULAR, FIXED32, passed_flags, 7) \
X(a, CALLBACK, OPTIONAL, BYTES, hash, 8) \
X(a, CALLBACK, REPEATED, MESSAGE, dependencies, 9) \
X(a, CALLBACK, REPEATED, MESSAGE, asset_dependencies, 10)
X(a, CALLBACK, REPEATED, MESSAGE, asset_dependencies, 10) \
X(a, STATIC, SINGULAR, UINT32, size, 11)
#define particle_cloud_FirmwareModule_CALLBACK pb_default_field_callback
#define particle_cloud_FirmwareModule_DEFAULT NULL
#define particle_cloud_FirmwareModule_dependencies_MSGTYPE particle_cloud_FirmwareModuleDependency
Expand Down
6 changes: 6 additions & 0 deletions proto_defs/src/control/storage.pb.c
Expand Up @@ -81,6 +81,12 @@ PB_BIND(particle_ctrl_GetModuleInfoReply_Dependency, particle_ctrl_GetModuleInfo
PB_BIND(particle_ctrl_GetModuleInfoReply_Module, particle_ctrl_GetModuleInfoReply_Module, AUTO)


PB_BIND(particle_ctrl_GetAssetInfoRequest, particle_ctrl_GetAssetInfoRequest, AUTO)


PB_BIND(particle_ctrl_GetAssetInfoReply, particle_ctrl_GetAssetInfoReply, AUTO)





Expand Down
54 changes: 48 additions & 6 deletions proto_defs/src/control/storage.pb.h
Expand Up @@ -5,6 +5,7 @@
#define PB_PARTICLE_CTRL_CONTROL_STORAGE_PB_H_INCLUDED
#include <pb.h>
#include "control/extensions.pb.h"
#include "cloud/describe.pb.h"

#if PB_PROTO_HEADER_VERSION != 40
#error Regenerate this file with the current version of nanopb generator.
Expand Down Expand Up @@ -93,7 +94,17 @@ typedef struct _particle_ctrl_FirmwareUpdateDataRequest {
pb_callback_t data;
} particle_ctrl_FirmwareUpdateDataRequest;

typedef struct _particle_ctrl_GetAssetInfoReply {
pb_callback_t available;
pb_callback_t required;
} particle_ctrl_GetAssetInfoReply;

typedef struct _particle_ctrl_GetAssetInfoRequest {
char dummy_field;
} particle_ctrl_GetAssetInfoRequest;

typedef struct _particle_ctrl_GetModuleInfoReply {
pb_callback_t modules_deprecated;
pb_callback_t modules;
} particle_ctrl_GetModuleInfoReply;

Expand Down Expand Up @@ -145,13 +156,16 @@ typedef struct _particle_ctrl_GetModuleInfoReply_Module {
pb_callback_t dependencies;
} particle_ctrl_GetModuleInfoReply_Module;

/* *
Get asset info. */
typedef struct _particle_ctrl_GetSectionDataSizeReply {
uint32_t size;
} particle_ctrl_GetSectionDataSizeReply;

typedef struct _particle_ctrl_GetSectionDataSizeRequest {
uint32_t storage; /* Firmware modules */
uint32_t section;
/* TODO: move these messages to common place */
uint32_t section; /* /< Firmware modules */
} particle_ctrl_GetSectionDataSizeRequest;

typedef struct _particle_ctrl_ReadSectionDataRequest {
Expand Down Expand Up @@ -239,9 +253,11 @@ extern "C" {
#define particle_ctrl_GetSectionDataSizeRequest_init_default {0, 0}
#define particle_ctrl_GetSectionDataSizeReply_init_default {0}
#define particle_ctrl_GetModuleInfoRequest_init_default {0}
#define particle_ctrl_GetModuleInfoReply_init_default {{{NULL}, NULL}}
#define particle_ctrl_GetModuleInfoReply_init_default {{{NULL}, NULL}, {{NULL}, NULL}}
#define particle_ctrl_GetModuleInfoReply_Dependency_init_default {_particle_ctrl_FirmwareModuleType_MIN, 0, 0}
#define particle_ctrl_GetModuleInfoReply_Module_init_default {_particle_ctrl_FirmwareModuleType_MIN, 0, 0, 0, 0, {{NULL}, NULL}}
#define particle_ctrl_GetAssetInfoRequest_init_default {0}
#define particle_ctrl_GetAssetInfoReply_init_default {{{NULL}, NULL}, {{NULL}, NULL}}
#define particle_ctrl_StartFirmwareUpdateRequest_init_zero {0, _particle_ctrl_FileFormat_MIN}
#define particle_ctrl_StartFirmwareUpdateReply_init_zero {0}
#define particle_ctrl_FinishFirmwareUpdateRequest_init_zero {0}
Expand All @@ -264,14 +280,19 @@ extern "C" {
#define particle_ctrl_GetSectionDataSizeRequest_init_zero {0, 0}
#define particle_ctrl_GetSectionDataSizeReply_init_zero {0}
#define particle_ctrl_GetModuleInfoRequest_init_zero {0}
#define particle_ctrl_GetModuleInfoReply_init_zero {{{NULL}, NULL}}
#define particle_ctrl_GetModuleInfoReply_init_zero {{{NULL}, NULL}, {{NULL}, NULL}}
#define particle_ctrl_GetModuleInfoReply_Dependency_init_zero {_particle_ctrl_FirmwareModuleType_MIN, 0, 0}
#define particle_ctrl_GetModuleInfoReply_Module_init_zero {_particle_ctrl_FirmwareModuleType_MIN, 0, 0, 0, 0, {{NULL}, NULL}}
#define particle_ctrl_GetAssetInfoRequest_init_zero {0}
#define particle_ctrl_GetAssetInfoReply_init_zero {{{NULL}, NULL}, {{NULL}, NULL}}

/* Field tags (for use in manual encoding/decoding) */
#define particle_ctrl_DescribeStorageReply_storage_tag 1
#define particle_ctrl_FirmwareUpdateDataRequest_data_tag 1
#define particle_ctrl_GetModuleInfoReply_modules_tag 1
#define particle_ctrl_GetAssetInfoReply_available_tag 1
#define particle_ctrl_GetAssetInfoReply_required_tag 2
#define particle_ctrl_GetModuleInfoReply_modules_deprecated_tag 1
#define particle_ctrl_GetModuleInfoReply_modules_tag 2
#define particle_ctrl_ReadSectionDataReply_data_tag 1
#define particle_ctrl_ClearSectionDataRequest_storage_tag 1
#define particle_ctrl_ClearSectionDataRequest_section_tag 2
Expand Down Expand Up @@ -439,10 +460,12 @@ X(a, STATIC, SINGULAR, UINT32, size, 1)
#define particle_ctrl_GetModuleInfoRequest_DEFAULT NULL

#define particle_ctrl_GetModuleInfoReply_FIELDLIST(X, a) \
X(a, CALLBACK, REPEATED, MESSAGE, modules, 1)
X(a, CALLBACK, REPEATED, MESSAGE, modules_deprecated, 1) \
X(a, CALLBACK, REPEATED, MESSAGE, modules, 2)
#define particle_ctrl_GetModuleInfoReply_CALLBACK pb_default_field_callback
#define particle_ctrl_GetModuleInfoReply_DEFAULT NULL
#define particle_ctrl_GetModuleInfoReply_modules_MSGTYPE particle_ctrl_GetModuleInfoReply_Module
#define particle_ctrl_GetModuleInfoReply_modules_deprecated_MSGTYPE particle_ctrl_GetModuleInfoReply_Module
#define particle_ctrl_GetModuleInfoReply_modules_MSGTYPE particle_cloud_FirmwareModule

#define particle_ctrl_GetModuleInfoReply_Dependency_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UENUM, type, 1) \
Expand All @@ -462,6 +485,19 @@ X(a, CALLBACK, REPEATED, MESSAGE, dependencies, 6)
#define particle_ctrl_GetModuleInfoReply_Module_DEFAULT NULL
#define particle_ctrl_GetModuleInfoReply_Module_dependencies_MSGTYPE particle_ctrl_GetModuleInfoReply_Dependency

#define particle_ctrl_GetAssetInfoRequest_FIELDLIST(X, a) \

#define particle_ctrl_GetAssetInfoRequest_CALLBACK NULL
#define particle_ctrl_GetAssetInfoRequest_DEFAULT NULL

#define particle_ctrl_GetAssetInfoReply_FIELDLIST(X, a) \
X(a, CALLBACK, REPEATED, MESSAGE, available, 1) \
X(a, CALLBACK, REPEATED, MESSAGE, required, 2)
#define particle_ctrl_GetAssetInfoReply_CALLBACK pb_default_field_callback
#define particle_ctrl_GetAssetInfoReply_DEFAULT NULL
#define particle_ctrl_GetAssetInfoReply_available_MSGTYPE particle_cloud_FirmwareModuleAsset
#define particle_ctrl_GetAssetInfoReply_required_MSGTYPE particle_cloud_FirmwareModuleAsset

extern const pb_msgdesc_t particle_ctrl_StartFirmwareUpdateRequest_msg;
extern const pb_msgdesc_t particle_ctrl_StartFirmwareUpdateReply_msg;
extern const pb_msgdesc_t particle_ctrl_FinishFirmwareUpdateRequest_msg;
Expand All @@ -487,6 +523,8 @@ extern const pb_msgdesc_t particle_ctrl_GetModuleInfoRequest_msg;
extern const pb_msgdesc_t particle_ctrl_GetModuleInfoReply_msg;
extern const pb_msgdesc_t particle_ctrl_GetModuleInfoReply_Dependency_msg;
extern const pb_msgdesc_t particle_ctrl_GetModuleInfoReply_Module_msg;
extern const pb_msgdesc_t particle_ctrl_GetAssetInfoRequest_msg;
extern const pb_msgdesc_t particle_ctrl_GetAssetInfoReply_msg;

/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
#define particle_ctrl_StartFirmwareUpdateRequest_fields &particle_ctrl_StartFirmwareUpdateRequest_msg
Expand Down Expand Up @@ -514,6 +552,8 @@ extern const pb_msgdesc_t particle_ctrl_GetModuleInfoReply_Module_msg;
#define particle_ctrl_GetModuleInfoReply_fields &particle_ctrl_GetModuleInfoReply_msg
#define particle_ctrl_GetModuleInfoReply_Dependency_fields &particle_ctrl_GetModuleInfoReply_Dependency_msg
#define particle_ctrl_GetModuleInfoReply_Module_fields &particle_ctrl_GetModuleInfoReply_Module_msg
#define particle_ctrl_GetAssetInfoRequest_fields &particle_ctrl_GetAssetInfoRequest_msg
#define particle_ctrl_GetAssetInfoReply_fields &particle_ctrl_GetAssetInfoReply_msg

/* Maximum encoded size of messages (where known) */
/* particle_ctrl_FirmwareUpdateDataRequest_size depends on runtime parameters */
Expand All @@ -523,6 +563,7 @@ extern const pb_msgdesc_t particle_ctrl_GetModuleInfoReply_Module_msg;
/* particle_ctrl_WriteSectionDataRequest_size depends on runtime parameters */
/* particle_ctrl_GetModuleInfoReply_size depends on runtime parameters */
/* particle_ctrl_GetModuleInfoReply_Module_size depends on runtime parameters */
/* particle_ctrl_GetAssetInfoReply_size depends on runtime parameters */
#define particle_ctrl_CancelFirmwareUpdateReply_size 0
#define particle_ctrl_CancelFirmwareUpdateRequest_size 0
#define particle_ctrl_ClearSectionDataReply_size 0
Expand All @@ -533,6 +574,7 @@ extern const pb_msgdesc_t particle_ctrl_GetModuleInfoReply_Module_msg;
#define particle_ctrl_FinishFirmwareUpdateReply_size 0
#define particle_ctrl_FinishFirmwareUpdateRequest_size 2
#define particle_ctrl_FirmwareUpdateDataReply_size 0
#define particle_ctrl_GetAssetInfoRequest_size 0
#define particle_ctrl_GetModuleInfoReply_Dependency_size 14
#define particle_ctrl_GetModuleInfoRequest_size 0
#define particle_ctrl_GetSectionDataSizeReply_size 6
Expand Down
17 changes: 15 additions & 2 deletions services/inc/storage_streams.h
Expand Up @@ -162,6 +162,7 @@ class FileInputStream : public InputStream {
}

int peek(char* data, size_t size) override {
size_t originalSize = size;
if (!remaining_) {
return SYSTEM_ERROR_END_OF_STREAM;
}
Expand All @@ -170,6 +171,9 @@ class FileInputStream : public InputStream {
fs::FsLock lock(fs_);
CHECK_FS(lfs_file_seek(&fs_->instance, &file_, offset_, LFS_SEEK_SET));
size = CHECK_FS(lfs_file_read(&fs_->instance, &file_, data, size));
if (size == 0 && originalSize > 0) {
return SYSTEM_ERROR_NOT_ENOUGH_DATA;
}
return size;
}

Expand Down Expand Up @@ -277,11 +281,16 @@ class InflatorStream: public InputStream {
}

int seek(size_t offset) override {
CHECK_TRUE(offset == 0 || (offset >= offset_ && offset <= inflatedSize_), SYSTEM_ERROR_NOT_ALLOWED);
CHECK_TRUE(offset == 0 || (offset >= offset_ && offset <= inflatedSize_) || (offset < offset_ && (offset_ - offset) <= posInChunk_), SYSTEM_ERROR_NOT_ALLOWED);
if (offset == 0) {
return rewind();
} else {
} else if (offset >= offset_) {
return skip(offset - offset_);
} else {
auto diff = offset_ - offset;
offset_ -= diff;
posInChunk_ -= diff;
return offset_;
}
}

Expand Down Expand Up @@ -339,6 +348,9 @@ class InflatorStream: public InputStream {
CHECK(r);
compressedPos += n;
compressedStream_->skip(n);
if (n == 0 && availForRead() <= 0) {
break;
}
} while (compressedPos < compressedChunk && r != INFLATE_HAS_MORE_OUTPUT);
if (r == INFLATE_HAS_MORE_OUTPUT && availForRead() > 0) {
break;
Expand Down Expand Up @@ -427,6 +439,7 @@ class ProxyInputStream : public InputStream {
// offset, storageId_, address_, remaining_, offset_);
CHECK_TRUE(offset <= size_, SYSTEM_ERROR_NOT_ENOUGH_DATA);
offset_ = CHECK(stream_->seek(baseOffset_ + offset));
offset_ -= baseOffset_;
return offset_;
}

Expand Down
1 change: 1 addition & 0 deletions system/inc/asset_manager.h
Expand Up @@ -128,6 +128,7 @@ class AssetManager {

const Vector<Asset>& requiredAssets() const;
const Vector<Asset>& availableAssets() const;
Vector<Asset> availableAndRequiredAssets() const;
Vector<Asset> missingAssets() const;
Vector<Asset> unusedAssets() const;

Expand Down
1 change: 1 addition & 0 deletions system/inc/system_control.h
Expand Up @@ -61,6 +61,7 @@ typedef enum ctrl_request_type {
CTRL_REQUEST_SET_STARTUP_MODE = 75,
CTRL_REQUEST_LOG_CONFIG = 80,
CTRL_REQUEST_GET_MODULE_INFO = 90,
CTRL_REQUEST_GET_ASSET_INFO = 91,
CTRL_REQUEST_DIAGNOSTIC_INFO = 100,
// CTRL_REQUEST_WIFI_SET_ANTENNA = 110,
// CTRL_REQUEST_WIFI_GET_ANTENNA = 111,
Expand Down