Fix static analysis errors
Fix checkpatch and cppcheck findings in newly added FWU files.
Change-Id: Ie6a877e65b758399647ceda345ae22081d911f8e
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/components/media/disk/gpt_iterator/gpt_iterator.c b/components/media/disk/gpt_iterator/gpt_iterator.c
index 94a91af..1c5ba0f 100644
--- a/components/media/disk/gpt_iterator/gpt_iterator.c
+++ b/components/media/disk/gpt_iterator/gpt_iterator.c
@@ -5,17 +5,16 @@
*
*/
-#include <assert.h>
-#include <errno.h>
-#include <string.h>
-#include <stddef.h>
-#include <media/volume/volume.h>
#include "gpt_iterator.h"
+#include <assert.h>
+#include <errno.h>
+#include <stddef.h>
+#include <string.h>
-int gpt_iterator_init(
- struct gpt_iterator *iter,
- struct volume *volume)
+#include "media/volume/volume.h"
+
+int gpt_iterator_init(struct gpt_iterator *iter, struct volume *volume)
{
assert(iter);
assert(volume);
@@ -62,13 +61,11 @@
*/
size_t min_required_entry_size =
offsetof(gpt_entry_t, name) + EFI_NAMELEN * sizeof(unsigned short);
- size_t max_expected_entry_size =
- sizeof(gpt_entry_t) * 2;
+ size_t max_expected_entry_size = sizeof(gpt_entry_t) * 2;
if ((memcmp(GPT_SIGNATURE, gpt_header.signature, sizeof(gpt_header.signature)) != 0) ||
- (gpt_header.part_size < min_required_entry_size) ||
- (gpt_header.part_size > max_expected_entry_size) ||
- (iter->num_entries > 128))
+ gpt_header.part_size < min_required_entry_size ||
+ gpt_header.part_size > max_expected_entry_size || iter->num_entries > 128)
return -EIO;
iter->num_entries = gpt_header.list_num;
@@ -77,8 +74,7 @@
return 0;
}
-void gpt_iterator_deinit(
- struct gpt_iterator *iter)
+void gpt_iterator_deinit(struct gpt_iterator *iter)
{
assert(iter);
@@ -86,33 +82,28 @@
volume_close(iter->volume);
}
-void gpt_iterator_first(
- struct gpt_iterator *iter)
+void gpt_iterator_first(struct gpt_iterator *iter)
{
assert(iter);
iter->cur_index = 0;
}
-void gpt_iterator_next(
- struct gpt_iterator *iter)
+void gpt_iterator_next(struct gpt_iterator *iter)
{
assert(iter);
++iter->cur_index;
}
-bool gpt_iterator_is_done(
- const struct gpt_iterator *iter)
+bool gpt_iterator_is_done(const struct gpt_iterator *iter)
{
assert(iter);
return (iter->cur_index >= iter->num_entries);
}
-int gpt_iterator_current(
- struct gpt_iterator *iter,
- gpt_entry_t *entry)
+int gpt_iterator_current(struct gpt_iterator *iter, gpt_entry_t *entry)
{
assert(iter);
assert(iter->volume);
diff --git a/components/media/disk/gpt_iterator/gpt_iterator.h b/components/media/disk/gpt_iterator/gpt_iterator.h
index bb0ebc8..e288aaa 100644
--- a/components/media/disk/gpt_iterator/gpt_iterator.h
+++ b/components/media/disk/gpt_iterator/gpt_iterator.h
@@ -30,7 +30,6 @@
* Holds state while iterating over partition table entries
*/
struct gpt_iterator {
-
unsigned int num_entries;
unsigned int entry_size;
unsigned int cur_index;
@@ -52,41 +51,35 @@
*
* \return IO Status code (0 for success)
*/
-int gpt_iterator_init(
- struct gpt_iterator *iter,
- struct volume *volume);
+int gpt_iterator_init(struct gpt_iterator *iter, struct volume *volume);
/**
* \brief De-initialize the iterator
*
* \param[in] iter The subject gpt_iterator
*/
-void gpt_iterator_deinit(
- struct gpt_iterator *iter);
+void gpt_iterator_deinit(struct gpt_iterator *iter);
/**
* \brief Set iterator position to first partition entry
*
* \param[in] iter The subject gpt_iterator
*/
-void gpt_iterator_first(
- struct gpt_iterator *iter);
+void gpt_iterator_first(struct gpt_iterator *iter);
/**
* \brief Iterate to the next entry
*
* \param[in] iter The subject gpt_iterator
*/
-void gpt_iterator_next(
- struct gpt_iterator *iter);
+void gpt_iterator_next(struct gpt_iterator *iter);
/**
* \brief Returns true if iterated beyond final entry
*
* \param[in] iter The subject gpt_iterator
*/
-bool gpt_iterator_is_done(
- const struct gpt_iterator *iter);
+bool gpt_iterator_is_done(const struct gpt_iterator *iter);
/**
* \brief Returns the partition entry at the current iterator position
@@ -96,10 +89,7 @@
*
* \return IO Status code (0 for success)
*/
-int gpt_iterator_current(
- struct gpt_iterator *iter,
- gpt_entry_t *entry);
-
+int gpt_iterator_current(struct gpt_iterator *iter, gpt_entry_t *entry);
#ifdef __cplusplus
}
diff --git a/components/media/disk/test/gpt_iterator_tests.cpp b/components/media/disk/test/gpt_iterator_tests.cpp
index 3e16dff..b7d4d26 100644
--- a/components/media/disk/test/gpt_iterator_tests.cpp
+++ b/components/media/disk/test/gpt_iterator_tests.cpp
@@ -4,16 +4,17 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string>
-#include <cstring>
-#include <common/uuid/uuid.h>
-#include <service/block_storage/factory/ref_ram_gpt/block_store_factory.h>
-#include <service/block_storage/config/ref/ref_partition_configurator.h>
-#include <media/volume/index/volume_index.h>
-#include <media/volume/block_volume/block_volume.h>
-#include <media/disk/gpt_iterator/gpt_iterator.h>
-#include <media/disk/guid.h>
#include <CppUTest/TestHarness.h>
+#include <cstring>
+#include <string>
+
+#include "common/uuid/uuid.h"
+#include "media/disk/gpt_iterator/gpt_iterator.h"
+#include "media/disk/guid.h"
+#include "media/volume/block_volume/block_volume.h"
+#include "media/volume/index/volume_index.h"
+#include "service/block_storage/config/ref/ref_partition_configurator.h"
+#include "service/block_storage/factory/ref_ram_gpt/block_store_factory.h"
TEST_GROUP(GptIteratorTests)
{
@@ -27,13 +28,12 @@
/* Use partition exposed for accessing the disk header */
uuid_guid_octets_from_canonical(&m_partition_guid,
- DISK_GUID_UNIQUE_PARTITION_DISK_HEADER);
+ DISK_GUID_UNIQUE_PARTITION_DISK_HEADER);
m_volume = NULL;
- int status = block_volume_init(&m_block_volume,
- m_block_store, &m_partition_guid,
- &m_volume);
+ int status = block_volume_init(&m_block_volume, m_block_store, &m_partition_guid,
+ &m_volume);
LONGS_EQUAL(0, status);
CHECK_TRUE(m_volume);
@@ -131,7 +131,6 @@
gpt_iterator_next(&m_iter);
while (!gpt_iterator_is_done(&m_iter)) {
-
status = gpt_iterator_current(&m_iter, &gpt_entry);
LONGS_EQUAL(0, status);
CHECK_FALSE(check_in_use(&gpt_entry));
diff --git a/components/media/volume/block_volume/test/block_volume_tests.cpp b/components/media/volume/block_volume/test/block_volume_tests.cpp
index 89d1726..eda442c 100644
--- a/components/media/volume/block_volume/test/block_volume_tests.cpp
+++ b/components/media/volume/block_volume/test/block_volume_tests.cpp
@@ -4,32 +4,31 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-
-#include <string>
-#include <cstring>
-#include <common/uuid/uuid.h>
-#include <service/block_storage/block_store/device/ram/ram_block_store.h>
-#include <media/volume/block_volume/block_volume.h>
-#include <media/volume/index/volume_index.h>
#include <CppUTest/TestHarness.h>
+#include <cstring>
+#include <string>
+
+#include "common/uuid/uuid.h"
+#include "media/volume/block_volume/block_volume.h"
+#include "media/volume/index/volume_index.h"
+#include "service/block_storage/block_store/device/ram/ram_block_store.h"
TEST_GROUP(BlockVolumeTests)
{
void setup()
{
uuid_guid_octets_from_canonical(&m_partition_guid,
- "6152f22b-8128-4c1f-981f-3bd279519907");
+ "6152f22b-8128-4c1f-981f-3bd279519907");
- m_block_store = ram_block_store_init(&m_ram_block_store,
- &m_partition_guid, NUM_BLOCKS, BLOCK_SIZE);
+ m_block_store = ram_block_store_init(&m_ram_block_store, &m_partition_guid,
+ NUM_BLOCKS, BLOCK_SIZE);
CHECK_TRUE(m_block_store);
m_volume = NULL;
- int result = block_volume_init(&m_block_volume,
- m_block_store, &m_partition_guid,
- &m_volume);
+ int result = block_volume_init(&m_block_volume, m_block_store, &m_partition_guid,
+ &m_volume);
LONGS_EQUAL(0, result);
CHECK_TRUE(m_volume);
@@ -56,7 +55,6 @@
struct volume *m_volume;
};
-
TEST(BlockVolumeTests, openClose)
{
/* Check the open flow used by tf-a components */
@@ -88,12 +86,10 @@
/* Write message a few times. Expect file pointer to advance on each write */
for (size_t i = 0; i < num_iterations; ++i) {
-
size_t len_written = 0;
- result = volume_write(m_volume,
- (const uintptr_t)message.c_str(), message.size(),
- &len_written);
+ result = volume_write(m_volume, (const uintptr_t)message.c_str(), message.size(),
+ &len_written);
LONGS_EQUAL(0, result);
UNSIGNED_LONGS_EQUAL(message.size(), len_written);
@@ -106,14 +102,12 @@
uint8_t read_buf[message.size()];
for (size_t i = 0; i < num_iterations; ++i) {
-
size_t len_read = 0;
memset(read_buf, 0, sizeof(read_buf));
- result = volume_read(m_volume,
- (const uintptr_t)read_buf, sizeof(read_buf),
- &len_read);
+ result = volume_read(m_volume, (const uintptr_t)read_buf, sizeof(read_buf),
+ &len_read);
LONGS_EQUAL(0, result);
UNSIGNED_LONGS_EQUAL(message.size(), len_read);
@@ -206,7 +200,6 @@
CHECK_TRUE(volume);
for (size_t i = 0; i < 3; ++i) {
-
size_t len = 0;
/* Each iteration represents an update installation where arbitrary sized
@@ -231,7 +224,7 @@
LONGS_EQUAL(0, result);
UNSIGNED_LONGS_EQUAL(chunk2.size(), len);
- std::string chunk3("The third chunck is soooooooooooooooooooooooooooo much longer");
+ std::string chunk3("The third chunk is soooooooooooooooooooooooooooo much longer");
result = volume_write(volume, (const uintptr_t)chunk3.c_str(), chunk3.size(), &len);
LONGS_EQUAL(0, result);
UNSIGNED_LONGS_EQUAL(chunk3.size(), len);
@@ -273,12 +266,10 @@
CHECK_TRUE(space_remaining > 0);
for (size_t i = 0; i < num_whole_messages; ++i) {
-
size_t len_written = 0;
- result = volume_write(m_volume,
- (const uintptr_t)message.c_str(), message.size(),
- &len_written);
+ result = volume_write(m_volume, (const uintptr_t)message.c_str(), message.size(),
+ &len_written);
LONGS_EQUAL(0, result);
UNSIGNED_LONGS_EQUAL(message.size(), len_written);
@@ -287,9 +278,8 @@
/* Writing the message one more time should exceed the volume size */
size_t len_written = 0;
- result = volume_write(m_volume,
- (const uintptr_t)message.c_str(), message.size(),
- &len_written);
+ result = volume_write(m_volume, (const uintptr_t)message.c_str(), message.size(),
+ &len_written);
LONGS_EQUAL(0, result);
@@ -303,14 +293,12 @@
uint8_t read_buf[message.size()];
for (size_t i = 0; i < num_whole_messages; ++i) {
-
size_t len_read = 0;
memset(read_buf, 0, sizeof(read_buf));
- result = volume_read(m_volume,
- (const uintptr_t)read_buf, sizeof(read_buf),
- &len_read);
+ result = volume_read(m_volume, (const uintptr_t)read_buf, sizeof(read_buf),
+ &len_read);
LONGS_EQUAL(0, result);
UNSIGNED_LONGS_EQUAL(message.size(), len_read);
@@ -322,9 +310,7 @@
memset(read_buf, 0, sizeof(read_buf));
- result = volume_read(m_volume,
- (const uintptr_t)read_buf, sizeof(read_buf),
- &len_read);
+ result = volume_read(m_volume, (const uintptr_t)read_buf, sizeof(read_buf), &len_read);
LONGS_EQUAL(0, result);
UNSIGNED_LONGS_EQUAL(space_remaining, len_read);
diff --git a/components/media/volume/factory/single_flash/volume_factory.c b/components/media/volume/factory/single_flash/volume_factory.c
index 0f302cc..ab7bfef 100644
--- a/components/media/volume/factory/single_flash/volume_factory.c
+++ b/components/media/volume/factory/single_flash/volume_factory.c
@@ -4,16 +4,18 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include "media/volume/factory/volume_factory.h"
+
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#include <trace.h>
-#include <service/block_storage/factory/block_store_factory.h>
-#include <service/block_storage/block_store/block_store.h>
-#include <media/volume/factory/volume_factory.h>
-#include <media/volume/block_volume/block_volume.h>
-#include <media/disk/guid.h>
+
+#include "media/disk/guid.h"
+#include "media/volume/block_volume/block_volume.h"
+#include "service/block_storage/block_store/block_store.h"
+#include "service/block_storage/factory/block_store_factory.h"
+#include "trace.h"
/**
* A volume factory for single flash deployments where underlying block-level
@@ -23,10 +25,8 @@
*/
static struct block_store *single_block_store;
-int volume_factory_init(
- struct uuid_octets *device_uuids,
- size_t device_uuids_size,
- size_t *num_device_uuids)
+int volume_factory_init(struct uuid_octets *device_uuids, size_t device_uuids_size,
+ size_t *num_device_uuids)
{
assert(device_uuids || !device_uuids_size);
assert(num_device_uuids);
@@ -35,22 +35,19 @@
single_block_store = block_store_factory_create();
if (!single_block_store) {
-
EMSG("Failed to construct block_store");
return -EIO;
}
if (device_uuids_size > 0) {
-
struct storage_partition_info device_info;
struct uuid_octets uuid;
/* Query for GPT partition to get info about the parent device */
- uuid_guid_octets_from_canonical(&uuid,
- DISK_GUID_UNIQUE_PARTITION_DISK_HEADER);
+ uuid_guid_octets_from_canonical(&uuid, DISK_GUID_UNIQUE_PARTITION_DISK_HEADER);
- psa_status_t psa_status = block_store_get_partition_info(single_block_store,
- &uuid, &device_info);
+ psa_status_t psa_status =
+ block_store_get_partition_info(single_block_store, &uuid, &device_info);
if (psa_status == PSA_SUCCESS)
device_uuids[0] = device_info.parent_guid;
@@ -69,9 +66,8 @@
single_block_store = NULL;
}
-struct volume *volume_factory_create_volume(
- const struct uuid_octets *partition_uuid,
- const struct uuid_octets *device_uuid)
+struct volume *volume_factory_create_volume(const struct uuid_octets *partition_uuid,
+ const struct uuid_octets *device_uuid)
{
struct volume *product = NULL;
@@ -84,27 +80,22 @@
(struct block_volume *)malloc(sizeof(struct block_volume));
if (block_volume) {
-
- int status = block_volume_init(block_volume,
- single_block_store, partition_uuid,
- &product);
+ int status = block_volume_init(block_volume, single_block_store, partition_uuid,
+ &product);
if (status) {
-
EMSG("Failed to init block volume: %d", status);
product = NULL;
free(block_volume);
}
} else {
-
EMSG("Failed to alloc block volume");
}
return product;
}
-void volume_factory_destroy_volume(
- struct volume *volume)
+void volume_factory_destroy_volume(struct volume *volume)
{
if (volume && volume->io_spec)
free((void *)volume->io_spec);
diff --git a/components/media/volume/factory/volume_factory.h b/components/media/volume/factory/volume_factory.h
index f7e9115..04d70ab 100644
--- a/components/media/volume/factory/volume_factory.h
+++ b/components/media/volume/factory/volume_factory.h
@@ -8,8 +8,9 @@
#define MEDIA_VOLUME_FACTORY_H
#include <stddef.h>
-#include <common/uuid/uuid.h>
-#include <media/volume/volume.h>
+
+#include "common/uuid/uuid.h"
+#include "media/volume/volume.h"
#ifdef __cplusplus
extern "C" {
@@ -30,10 +31,8 @@
*
* \return Status (0 on success)
*/
-int volume_factory_init(
- struct uuid_octets *device_uuids,
- size_t device_uuids_size,
- size_t *num_device_uuids);
+int volume_factory_init(struct uuid_octets *device_uuids, size_t device_uuids_size,
+ size_t *num_device_uuids);
/**
* \brief De-initialises the volume_factory
@@ -52,17 +51,15 @@
*
* \return Pointer to volume or NULL
*/
-struct volume *volume_factory_create_volume(
- const struct uuid_octets *partition_uuid,
- const struct uuid_octets *device_uuid);
+struct volume *volume_factory_create_volume(const struct uuid_octets *partition_uuid,
+ const struct uuid_octets *device_uuid);
/**
* \brief Destroys a volume object
*
* \param[in] volume Volume to destroy
*/
-void volume_factory_destroy_volume(
- struct volume *volume);
+void volume_factory_destroy_volume(struct volume *volume);
#ifdef __cplusplus
}
diff --git a/components/media/volume/volume.c b/components/media/volume/volume.c
index b043376..aa17c26 100644
--- a/components/media/volume/volume.c
+++ b/components/media/volume/volume.c
@@ -4,14 +4,13 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <errno.h>
-#include <stddef.h>
#include "volume.h"
-void volume_init(
- struct volume *this_volume,
- const io_dev_funcs_t *io_dev_funcs,
- uintptr_t concrete_volume)
+#include <errno.h>
+#include <stddef.h>
+
+void volume_init(struct volume *this_volume, const io_dev_funcs_t *io_dev_funcs,
+ uintptr_t concrete_volume)
{
this_volume->dev_info.funcs = io_dev_funcs;
this_volume->dev_info.info = concrete_volume;
@@ -26,70 +25,48 @@
this_volume->get_storage_ids = NULL;
}
-int volume_open(
- struct volume *this_volume)
+int volume_open(struct volume *this_volume)
{
- return io_open(
- this_volume->dev_handle,
- this_volume->io_spec,
- &this_volume->io_handle);
+ return io_open(this_volume->dev_handle, this_volume->io_spec, &this_volume->io_handle);
}
-int volume_close(
- struct volume *this_volume)
+int volume_close(struct volume *this_volume)
{
return io_close(this_volume->io_handle);
}
-int volume_seek(
- struct volume *this_volume,
- io_seek_mode_t mode,
- signed long long offset)
+int volume_seek(struct volume *this_volume, io_seek_mode_t mode, signed long long offset)
{
return io_seek(this_volume->io_handle, mode, offset);
}
-int volume_size(
- struct volume *this_volume,
- size_t *size)
+int volume_size(struct volume *this_volume, size_t *size)
{
return io_size(this_volume->io_handle, size);
}
-int volume_read(
- struct volume *this_volume,
- uintptr_t buffer,
- size_t length,
- size_t *length_read)
+int volume_read(struct volume *this_volume, uintptr_t buffer, size_t length, size_t *length_read)
{
return io_read(this_volume->io_handle, buffer, length, length_read);
}
-int volume_write(
- struct volume *this_volume,
- const uintptr_t buffer,
- size_t length,
- size_t *length_written)
+int volume_write(struct volume *this_volume, const uintptr_t buffer, size_t length,
+ size_t *length_written)
{
return io_write(this_volume->io_handle, buffer, length, length_written);
}
-int volume_erase(
- struct volume *this_volume)
+int volume_erase(struct volume *this_volume)
{
- return (this_volume->erase) ?
- this_volume->erase(this_volume->dev_info.info) : 0;
+ return (this_volume->erase) ? this_volume->erase(this_volume->dev_info.info) : 0;
}
-int volume_get_storage_ids(
- struct volume *this_volume,
- struct uuid_octets *partition_guid,
- struct uuid_octets *parent_guid)
+int volume_get_storage_ids(struct volume *this_volume, struct uuid_octets *partition_guid,
+ struct uuid_octets *parent_guid)
{
if (this_volume->get_storage_ids)
- return this_volume->get_storage_ids(
- this_volume->dev_info.info,
- partition_guid, parent_guid);
+ return this_volume->get_storage_ids(this_volume->dev_info.info, partition_guid,
+ parent_guid);
return -EIO;
}
diff --git a/components/media/volume/volume.h b/components/media/volume/volume.h
index 3395e5b..1e335eb 100644
--- a/components/media/volume/volume.h
+++ b/components/media/volume/volume.h
@@ -8,7 +8,8 @@
#define MEDIA_VOLUME_H
#include <stddef.h>
-#include <common/uuid/uuid.h>
+
+#include "common/uuid/uuid.h"
#ifdef __cplusplus
extern "C" {
@@ -31,7 +32,6 @@
* erase function pointer may be set to NULL;
*/
struct volume {
-
/* IO device handle for volume access */
uintptr_t dev_handle;
@@ -48,9 +48,8 @@
int (*erase)(uintptr_t context);
/* Optional function to get storage IDs for the volume */
- int (*get_storage_ids)(uintptr_t context,
- struct uuid_octets *partition_guid,
- struct uuid_octets *parent_guid);
+ int (*get_storage_ids)(uintptr_t context, struct uuid_octets *partition_guid,
+ struct uuid_octets *parent_guid);
};
/**
@@ -62,10 +61,8 @@
* @param[in] io_dev_funcs io_dev function struct for concrete handlers
* @param[in] concrete_volume Pointer to the concrete volume instance
*/
-void volume_init(
- struct volume *this_volume,
- const io_dev_funcs_t *io_dev_funcs,
- uintptr_t concrete_volume);
+void volume_init(struct volume *this_volume, const io_dev_funcs_t *io_dev_funcs,
+ uintptr_t concrete_volume);
/**
* @brief Open the volume for IO operations
@@ -74,8 +71,7 @@
*
* @return 0 on success
*/
-int volume_open(
- struct volume *this_volume);
+int volume_open(struct volume *this_volume);
/**
* @brief Close the volume when done with IO operations
@@ -84,8 +80,7 @@
*
* @return 0 on success
*/
-int volume_close(
- struct volume *this_volume);
+int volume_close(struct volume *this_volume);
/**
* @brief Seek to the specified position
@@ -96,10 +91,7 @@
*
* @return 0 on success
*/
-int volume_seek(
- struct volume *this_volume,
- io_seek_mode_t mode,
- signed long long offset);
+int volume_seek(struct volume *this_volume, io_seek_mode_t mode, signed long long offset);
/**
* @brief Get the size of the volume
@@ -109,9 +101,7 @@
*
* @return 0 on success
*/
-int volume_size(
- struct volume *this_volume,
- size_t *size);
+int volume_size(struct volume *this_volume, size_t *size);
/**
* @brief Read from the volume
@@ -125,11 +115,7 @@
*
* @return 0 on success
*/
-int volume_read(
- struct volume *this_volume,
- uintptr_t buffer,
- size_t length,
- size_t *length_read);
+int volume_read(struct volume *this_volume, uintptr_t buffer, size_t length, size_t *length_read);
/**
* @brief Write the volume
@@ -143,11 +129,8 @@
*
* @return 0 on success
*/
-int volume_write(
- struct volume *this_volume,
- const uintptr_t buffer,
- size_t length,
- size_t *length_written);
+int volume_write(struct volume *this_volume, const uintptr_t buffer, size_t length,
+ size_t *length_written);
/**
* @brief Erase the entire volume
@@ -156,8 +139,7 @@
*
* @return 0 on success
*/
-int volume_erase(
- struct volume *this_volume);
+int volume_erase(struct volume *this_volume);
/**
* @brief Get GUIDs to identify the storage associated with the volume
@@ -170,10 +152,8 @@
*
* @return 0 on success, ENOSYS if not supported
*/
-int volume_get_storage_ids(
- struct volume *this_volume,
- struct uuid_octets *partition_guid,
- struct uuid_octets *parent_guid);
+int volume_get_storage_ids(struct volume *this_volume, struct uuid_octets *partition_guid,
+ struct uuid_octets *parent_guid);
#ifdef __cplusplus
}
diff --git a/components/rpc/http/caller/http_caller.c b/components/rpc/http/caller/http_caller.c
index af541e8..120eef8 100644
--- a/components/rpc/http/caller/http_caller.c
+++ b/components/rpc/http/caller/http_caller.c
@@ -4,19 +4,21 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <assert.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <trace.h>
-#include <curl/curl.h>
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/rpc/common/packed-c/header.h>
#include "http_caller.h"
-#define USER_AGENT "libcurl-agent/1.0"
+#include <assert.h>
+#include <curl/curl.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "protocols/rpc/common/packed-c/header.h"
+#include "protocols/rpc/common/packed-c/status.h"
+#include "trace.h"
+
+#define USER_AGENT "libcurl-agent/1.0"
struct payload_buffer {
uint8_t *data;
@@ -24,10 +26,9 @@
size_t pos;
};
-
static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len);
static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
- rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len);
+ rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len);
static void call_end(void *context, rpc_call_handle handle);
static size_t request_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
@@ -36,8 +37,8 @@
struct payload_buffer *buf = (struct payload_buffer *)userdata;
size_t bytes_remaining = buf->size - buf->pos;
- size_t bytes_to_send = (bytes_remaining < bytes_requested) ?
- bytes_remaining : bytes_requested;
+ size_t bytes_to_send = (bytes_remaining < bytes_requested) ? bytes_remaining :
+ bytes_requested;
memcpy(ptr, &buf->data[buf->pos], bytes_to_send);
@@ -64,9 +65,7 @@
return bytes_received;
}
-static bool send_head_request(const char *url,
- struct payload_buffer *response_buf,
- long *http_code)
+static bool send_head_request(const char *url, struct payload_buffer *response_buf, long *http_code)
{
assert(url);
assert(response_buf);
@@ -77,7 +76,6 @@
*http_code = 0;
if (curl_session) {
-
curl_easy_setopt(curl_session, CURLOPT_URL, url);
curl_easy_setopt(curl_session, CURLOPT_NOBODY, 1L);
curl_easy_setopt(curl_session, CURLOPT_WRITEFUNCTION, response_callback);
@@ -87,9 +85,9 @@
CURLcode status = curl_easy_perform(curl_session);
if (status == CURLE_OK) {
-
status = curl_easy_getinfo(curl_session, CURLINFO_RESPONSE_CODE, http_code);
- is_success = (status == CURLE_OK) && (*http_code >= 200) && (*http_code < 300);
+ is_success = (status == CURLE_OK) && (*http_code >= 200) &&
+ (*http_code < 300);
}
curl_easy_cleanup(curl_session);
@@ -100,9 +98,8 @@
return is_success;
}
-static bool send_put_request(const char *url,
- struct payload_buffer *request_buf,
- struct payload_buffer *response_buf)
+static bool send_put_request(const char *url, struct payload_buffer *request_buf,
+ struct payload_buffer *response_buf)
{
bool is_success = false;
@@ -113,12 +110,12 @@
CURL *curl_session = curl_easy_init();
if (curl_session) {
-
curl_easy_setopt(curl_session, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl_session, CURLOPT_URL, url);
curl_easy_setopt(curl_session, CURLOPT_READFUNCTION, request_callback);
curl_easy_setopt(curl_session, CURLOPT_READDATA, (void *)request_buf);
- curl_easy_setopt(curl_session, CURLOPT_INFILESIZE_LARGE, (curl_off_t)request_buf->size);
+ curl_easy_setopt(curl_session, CURLOPT_INFILESIZE_LARGE,
+ (curl_off_t)request_buf->size);
curl_easy_setopt(curl_session, CURLOPT_WRITEFUNCTION, response_callback);
curl_easy_setopt(curl_session, CURLOPT_WRITEDATA, (void *)response_buf);
curl_easy_setopt(curl_session, CURLOPT_USERAGENT, USER_AGENT);
@@ -126,11 +123,12 @@
CURLcode status = curl_easy_perform(curl_session);
if (status == CURLE_OK) {
-
long http_code = 0;
- status = curl_easy_getinfo(curl_session, CURLINFO_RESPONSE_CODE, &http_code);
- is_success = (status == CURLE_OK) && (http_code >= 200) && (http_code < 300);
+ status =
+ curl_easy_getinfo(curl_session, CURLINFO_RESPONSE_CODE, &http_code);
+ is_success = (status == CURLE_OK) && (http_code >= 200) &&
+ (http_code < 300);
}
curl_easy_cleanup(curl_session);
@@ -141,10 +139,8 @@
return is_success;
}
-static void prepare_call_url(const struct http_caller *s,
- unsigned int opcode,
- char *url_buf,
- size_t url_buf_size)
+static void prepare_call_url(const struct http_caller *s, unsigned int opcode, char *url_buf,
+ size_t url_buf_size)
{
size_t base_url_len = strnlen(s->rpc_call_url, HTTP_CALLER_MAX_URL_LEN);
@@ -156,14 +152,12 @@
/* Ensure '/' is present before adding opcode */
if (url_buf[base_url_len - 1] != '/') {
-
url_buf[base_url_len] = '/';
base_url_len += 1;
}
size_t remaining_space = url_buf_size - base_url_len;
- size_t opcode_len = snprintf(&url_buf[base_url_len],
- remaining_space, "%u", opcode);
+ size_t opcode_len = snprintf(&url_buf[base_url_len], remaining_space, "%u", opcode);
assert(opcode_len < remaining_space);
}
@@ -234,9 +228,7 @@
return 0;
}
-static rpc_call_handle call_begin(void *context,
- uint8_t **req_buf,
- size_t req_len)
+static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len)
{
assert(context);
assert(req_buf || !req_len);
@@ -245,13 +237,11 @@
struct http_caller *s = (struct http_caller *)context;
if (!s->req_body_buf) {
-
size_t req_body_size = sizeof(struct ts_rpc_req_hdr) + req_len;
s->req_body_buf = malloc(req_body_size);
if (s->req_body_buf) {
-
memset(s->req_body_buf, 0, req_body_size);
handle = s;
@@ -271,12 +261,8 @@
return handle;
}
-static rpc_status_t call_invoke(void *context,
- rpc_call_handle handle,
- uint32_t opcode,
- rpc_opstatus_t *opstatus,
- uint8_t **resp_buf,
- size_t *resp_len)
+static rpc_status_t call_invoke(void *context, const rpc_call_handle handle, uint32_t opcode,
+ rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len)
{
rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
struct http_caller *s = (struct http_caller *)context;
@@ -284,10 +270,9 @@
*resp_len = 0;
if ((handle == s) && s->req_body_buf) {
-
struct ts_rpc_req_hdr *rpc_hdr = (struct ts_rpc_req_hdr *)s->req_body_buf;
- struct payload_buffer request_buf = {0};
- struct payload_buffer response_buf = {0};
+ struct payload_buffer request_buf = { 0 };
+ struct payload_buffer response_buf = { 0 };
rpc_status = TS_RPC_ERROR_EP_DOES_NOT_EXIT;
@@ -300,27 +285,25 @@
prepare_call_url(s, opcode, call_url, sizeof(call_url));
- if (send_put_request(call_url, &request_buf, &response_buf) &&
- response_buf.data &&
- response_buf.size >= sizeof(struct ts_rpc_resp_hdr)) {
-
- struct ts_rpc_resp_hdr *resp_hdr = (struct ts_rpc_resp_hdr *)response_buf.data;
- size_t response_param_len = response_buf.size - sizeof(struct ts_rpc_resp_hdr);
+ if (send_put_request(call_url, &request_buf, &response_buf) && response_buf.data &&
+ response_buf.size >= sizeof(struct ts_rpc_resp_hdr)) {
+ struct ts_rpc_resp_hdr *resp_hdr =
+ (struct ts_rpc_resp_hdr *)response_buf.data;
+ size_t response_param_len =
+ response_buf.size - sizeof(struct ts_rpc_resp_hdr);
if (resp_hdr->param_len == response_param_len) {
-
rpc_status = resp_hdr->rpc_status;
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- *resp_buf = &response_buf.data[sizeof(struct ts_rpc_resp_hdr)];
+ *resp_buf =
+ &response_buf.data[sizeof(struct ts_rpc_resp_hdr)];
*resp_len = response_param_len;
*opstatus = resp_hdr->op_status;
}
} else {
-
rpc_status = TS_RPC_ERROR_INVALID_RESP_BODY;
}
}
@@ -329,12 +312,11 @@
return rpc_status;
}
-static void call_end(void *context, rpc_call_handle handle)
+static void call_end(void *context, const rpc_call_handle handle)
{
struct http_caller *s = (struct http_caller *)context;
if ((handle == s) && s->req_body_buf) {
-
free(s->req_body_buf);
s->req_body_buf = NULL;
diff --git a/components/rpc/http/caller/http_caller.h b/components/rpc/http/caller/http_caller.h
index d1c7e9d..ac3a336 100644
--- a/components/rpc/http/caller/http_caller.h
+++ b/components/rpc/http/caller/http_caller.h
@@ -9,13 +9,14 @@
#include <stdbool.h>
#include <stdint.h>
-#include <rpc_caller.h>
+
+#include "rpc_caller.h"
#ifdef __cplusplus
extern "C" {
#endif
-#define HTTP_CALLER_MAX_URL_LEN (2048)
+#define HTTP_CALLER_MAX_URL_LEN (2048)
/*
* An RPC caller that makes call requests via a REST API 'call' endpoint
diff --git a/components/rpc/http/caller/test/http_caller_tests.cpp b/components/rpc/http/caller/test/http_caller_tests.cpp
index d3e7115..cfbc52a 100644
--- a/components/rpc/http/caller/test/http_caller_tests.cpp
+++ b/components/rpc/http/caller/test/http_caller_tests.cpp
@@ -5,11 +5,12 @@
*/
#include <CppUTest/TestHarness.h>
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/discovery/packed-c/opcodes.h>
-#include <service/locator/remote/restapi/restapi_location.h>
-#include <rpc/http/caller/http_caller.h>
-#include <psa/error.h>
+
+#include "protocols/rpc/common/packed-c/status.h"
+#include "protocols/service/discovery/packed-c/opcodes.h"
+#include "psa/error.h"
+#include "rpc/http/caller/http_caller.h"
+#include "service/locator/remote/restapi/restapi_location.h"
/*
* http_caller tests rely on a fw test api server running on the local host
@@ -51,8 +52,7 @@
{
int status;
- status = http_caller_open(&http_caller_under_test,
- RESTAPI_LOCATOR_API_URL "foo/call/");
+ status = http_caller_open(&http_caller_under_test, RESTAPI_LOCATOR_API_URL "foo/call/");
LONGS_EQUAL(0, status);
rpc_call_handle call_handle;
@@ -67,9 +67,8 @@
uint8_t *resp_buf = NULL;
size_t resp_len = 0;
- rpc_status = rpc_caller_invoke(rpc_caller, call_handle,
- 251, &op_status,
- &resp_buf, &resp_len);
+ rpc_status =
+ rpc_caller_invoke(rpc_caller, call_handle, 251, &op_status, &resp_buf, &resp_len);
LONGS_EQUAL(TS_RPC_ERROR_EP_DOES_NOT_EXIT, rpc_status);
rpc_caller_end(rpc_caller, call_handle);
@@ -79,8 +78,7 @@
{
int status;
- status = http_caller_open(&http_caller_under_test,
- RESTAPI_LOCATOR_API_URL "fwu/call/");
+ status = http_caller_open(&http_caller_under_test, RESTAPI_LOCATOR_API_URL "fwu/call/");
LONGS_EQUAL(0, status);
rpc_call_handle call_handle;
@@ -96,8 +94,8 @@
size_t resp_len = 0;
rpc_status = rpc_caller_invoke(rpc_caller, call_handle,
- TS_DISCOVERY_OPCODE_GET_SERVICE_INFO, &op_status,
- &resp_buf, &resp_len);
+ TS_DISCOVERY_OPCODE_GET_SERVICE_INFO, &op_status, &resp_buf,
+ &resp_len);
LONGS_EQUAL(TS_RPC_CALL_ACCEPTED, rpc_status);
LONGS_EQUAL(PSA_SUCCESS, op_status);
CHECK_TRUE(resp_len > 0);
diff --git a/components/service/block_storage/block_store/device/file/file_block_store.c b/components/service/block_storage/block_store/device/file/file_block_store.c
index 1d8d542..7d11304 100644
--- a/components/service/block_storage/block_store/device/file/file_block_store.c
+++ b/components/service/block_storage/block_store/device/file/file_block_store.c
@@ -5,13 +5,14 @@
*
*/
-#include <assert.h>
-#include <errno.h>
-#include <string.h>
-#include <stddef.h>
#include "file_block_store.h"
-#define ERASED_DATA_VAL (0xff)
+#include <assert.h>
+#include <errno.h>
+#include <stddef.h>
+#include <string.h>
+
+#define ERASED_DATA_VAL (0xff)
ssize_t file_length(FILE *fp)
{
@@ -31,11 +32,9 @@
return PSA_SUCCESS;
}
-static psa_status_t prepare_for_read(
- const struct file_block_store *this_instance,
- uint32_t lba, size_t offset,
- size_t requested_read_len,
- size_t *adjusted_read_len)
+static psa_status_t prepare_for_read(const struct file_block_store *this_instance, uint32_t lba,
+ size_t offset, size_t requested_read_len,
+ size_t *adjusted_read_len)
{
assert(this_instance);
@@ -48,24 +47,20 @@
ssize_t file_len = file_length(this_instance->file_handle);
if (file_len >= 0) {
-
/* File exists so attempt to seek the read position to the requested LBA + offset */
if (read_pos <= file_len) {
-
size_t bytes_until_end_of_file = (size_t)(file_len - read_pos);
size_t bytes_until_end_of_block = storage_partition->block_size - offset;
size_t read_limit = (bytes_until_end_of_file < bytes_until_end_of_block) ?
- bytes_until_end_of_file :
- bytes_until_end_of_block;
+ bytes_until_end_of_file :
+ bytes_until_end_of_block;
- *adjusted_read_len = (requested_read_len < read_limit) ?
- requested_read_len :
- read_limit;
+ *adjusted_read_len =
+ (requested_read_len < read_limit) ? requested_read_len : read_limit;
status = seek(this_instance->file_handle, read_pos);
} else {
-
/* Requested block is beyond the end of the file */
status = PSA_ERROR_INVALID_ARGUMENT;
}
@@ -74,10 +69,8 @@
return status;
}
-static psa_status_t write_erased(
- const struct file_block_store *this_instance,
- size_t pos,
- size_t len)
+static psa_status_t write_erased(const struct file_block_store *this_instance, size_t pos,
+ size_t len)
{
psa_status_t status = PSA_ERROR_BAD_STATE;
size_t remaining_len = len;
@@ -87,13 +80,12 @@
status = seek(this_instance->file_handle, pos);
while ((status == PSA_SUCCESS) && (remaining_len > 0)) {
-
size_t erase_len = (remaining_len < sizeof(this_instance->erase_buf)) ?
- remaining_len :
- sizeof(this_instance->erase_buf);
+ remaining_len :
+ sizeof(this_instance->erase_buf);
- size_t write_len = fwrite(this_instance->erase_buf, 1,
- erase_len, this_instance->file_handle);
+ size_t write_len =
+ fwrite(this_instance->erase_buf, 1, erase_len, this_instance->file_handle);
if (write_len != erase_len)
status = PSA_ERROR_BAD_STATE;
@@ -104,11 +96,9 @@
return status;
}
-static psa_status_t prepare_for_write(
- const struct file_block_store *this_instance,
- uint32_t lba, size_t offset,
- size_t requested_write_len,
- size_t *adjusted_write_len)
+static psa_status_t prepare_for_write(const struct file_block_store *this_instance, uint32_t lba,
+ size_t offset, size_t requested_write_len,
+ size_t *adjusted_write_len)
{
assert(this_instance);
@@ -119,20 +109,17 @@
size_t bytes_until_end_of_block = storage_partition->block_size - offset;
*adjusted_write_len = (requested_write_len < bytes_until_end_of_block) ?
- requested_write_len :
- bytes_until_end_of_block;
+ requested_write_len :
+ bytes_until_end_of_block;
ssize_t write_pos = lba * storage_partition->block_size + offset;
ssize_t file_len = file_length(this_instance->file_handle);
if (file_len >= 0) {
-
if (write_pos > file_len) {
-
/* Writing beyond the current end-of-file so extend the file */
status = write_erased(this_instance, file_len, write_pos - file_len);
} else {
-
/* Writing over existing data */
status = seek(this_instance->file_handle, write_pos);
}
@@ -142,80 +129,63 @@
}
static psa_status_t file_block_store_get_partition_info(void *context,
- const struct uuid_octets *partition_guid,
- struct storage_partition_info *info)
+ const struct uuid_octets *partition_guid,
+ struct storage_partition_info *info)
{
struct file_block_store *this_instance = (struct file_block_store *)context;
- return block_device_get_partition_info(
- &this_instance->base_block_device, partition_guid, info);
+ return block_device_get_partition_info(&this_instance->base_block_device, partition_guid,
+ info);
}
-static psa_status_t file_block_store_open(void *context,
- uint32_t client_id,
- const struct uuid_octets *partition_guid,
- storage_partition_handle_t *handle)
+static psa_status_t file_block_store_open(void *context, uint32_t client_id,
+ const struct uuid_octets *partition_guid,
+ storage_partition_handle_t *handle)
{
struct file_block_store *this_instance = (struct file_block_store *)context;
psa_status_t status = PSA_ERROR_BAD_STATE;
if (this_instance->file_handle > 0) {
-
- status = block_device_open(
- &this_instance->base_block_device,
- client_id, partition_guid, handle);
+ status = block_device_open(&this_instance->base_block_device, client_id,
+ partition_guid, handle);
}
return status;
}
-static psa_status_t file_block_store_close(void *context,
- uint32_t client_id,
- storage_partition_handle_t handle)
+static psa_status_t file_block_store_close(void *context, uint32_t client_id,
+ storage_partition_handle_t handle)
{
struct file_block_store *this_instance = (struct file_block_store *)context;
- return block_device_close(
- &this_instance->base_block_device, client_id, handle);
+ return block_device_close(&this_instance->base_block_device, client_id, handle);
}
-static psa_status_t file_block_store_read(void *context,
- uint32_t client_id,
- storage_partition_handle_t handle,
- uint32_t lba,
- size_t offset,
- size_t buffer_size,
- uint8_t *buffer,
- size_t *data_len)
+static psa_status_t file_block_store_read(void *context, uint32_t client_id,
+ storage_partition_handle_t handle, uint32_t lba,
+ size_t offset, size_t buffer_size, uint8_t *buffer,
+ size_t *data_len)
{
- const struct file_block_store *this_instance =
- (struct file_block_store *)context;
+ const struct file_block_store *this_instance = (struct file_block_store *)context;
- psa_status_t status = block_device_check_access_permitted(
- &this_instance->base_block_device, client_id, handle);
+ psa_status_t status = block_device_check_access_permitted(&this_instance->base_block_device,
+ client_id, handle);
*data_len = 0;
if (status == PSA_SUCCESS) {
-
const struct storage_partition *storage_partition =
&this_instance->base_block_device.storage_partition;
if (storage_partition_is_lba_legal(storage_partition, lba) &&
- (offset < storage_partition->block_size)) {
-
+ (offset < storage_partition->block_size)) {
size_t read_len = 0;
- status = prepare_for_read(
- this_instance,
- lba, offset,
- buffer_size,
- &read_len);
+ status = prepare_for_read(this_instance, lba, offset, buffer_size,
+ &read_len);
if (status == PSA_SUCCESS) {
-
- *data_len = fread(buffer, 1,
- read_len, this_instance->file_handle);
+ *data_len = fread(buffer, 1, read_len, this_instance->file_handle);
if (*data_len != read_len)
status = PSA_ERROR_BAD_STATE;
@@ -228,42 +198,32 @@
return status;
}
-static psa_status_t file_block_store_write(void *context,
- uint32_t client_id,
- storage_partition_handle_t handle,
- uint32_t lba,
- size_t offset,
- const uint8_t *data,
- size_t data_len,
- size_t *num_written)
+static psa_status_t file_block_store_write(void *context, uint32_t client_id,
+ storage_partition_handle_t handle, uint32_t lba,
+ size_t offset, const uint8_t *data, size_t data_len,
+ size_t *num_written)
{
struct file_block_store *this_instance = (struct file_block_store *)context;
- psa_status_t status = block_device_check_access_permitted(
- &this_instance->base_block_device, client_id, handle);
+ psa_status_t status = block_device_check_access_permitted(&this_instance->base_block_device,
+ client_id, handle);
*num_written = 0;
if (status == PSA_SUCCESS) {
-
const struct storage_partition *storage_partition =
&this_instance->base_block_device.storage_partition;
if (storage_partition_is_lba_legal(storage_partition, lba) &&
- (offset < storage_partition->block_size)) {
-
+ (offset < storage_partition->block_size)) {
size_t adjusted_len = 0;
- status = prepare_for_write(
- this_instance,
- lba, offset,
- data_len,
- &adjusted_len);
+ status = prepare_for_write(this_instance, lba, offset, data_len,
+ &adjusted_len);
if (status == PSA_SUCCESS) {
-
- *num_written = fwrite(data, 1,
- adjusted_len, this_instance->file_handle);
+ *num_written =
+ fwrite(data, 1, adjusted_len, this_instance->file_handle);
if (*num_written != adjusted_len)
status = PSA_ERROR_BAD_STATE;
@@ -276,34 +236,30 @@
return status;
}
-static psa_status_t file_block_store_erase(void *context,
- uint32_t client_id,
- storage_partition_handle_t handle,
- uint32_t begin_lba,
- size_t num_blocks)
+static psa_status_t file_block_store_erase(void *context, uint32_t client_id,
+ storage_partition_handle_t handle, uint32_t begin_lba,
+ size_t num_blocks)
{
struct file_block_store *this_instance = (struct file_block_store *)context;
const struct storage_partition *storage_partition =
&this_instance->base_block_device.storage_partition;
- psa_status_t status = block_device_check_access_permitted(
- &this_instance->base_block_device, client_id, handle);
+ psa_status_t status = block_device_check_access_permitted(&this_instance->base_block_device,
+ client_id, handle);
/* Sanitize the range of LBAs to erase */
if ((status == PSA_SUCCESS) &&
- !storage_partition_is_lba_legal(storage_partition, begin_lba))
+ !storage_partition_is_lba_legal(storage_partition, begin_lba))
status = PSA_ERROR_INVALID_ARGUMENT;
if (status == PSA_SUCCESS) {
-
size_t blocks_remaining = storage_partition->num_blocks - begin_lba;
- size_t blocks_to_erase = (num_blocks < blocks_remaining) ?
- num_blocks : blocks_remaining;
+ size_t blocks_to_erase = (num_blocks < blocks_remaining) ? num_blocks :
+ blocks_remaining;
ssize_t file_len = file_length(this_instance->file_handle);
if (file_len >= 0) {
-
/* File exists. If erased block falls within the limits of the file,
* explicitly set blocks to the erased state. If erased block is
* beyond EOF, there's nothing to do.
@@ -311,9 +267,9 @@
ssize_t block_pos = begin_lba * storage_partition->block_size;
if (block_pos < file_len)
- status = write_erased(this_instance,
- block_pos,
- blocks_to_erase * storage_partition->block_size);
+ status = write_erased(this_instance, block_pos,
+ blocks_to_erase *
+ storage_partition->block_size);
} else {
status = PSA_ERROR_BAD_STATE;
@@ -323,10 +279,8 @@
return status;
}
-struct block_store *file_block_store_init(
- struct file_block_store *this_instance,
- const char *filename,
- size_t block_size)
+struct block_store *file_block_store_init(struct file_block_store *this_instance,
+ const char *filename, size_t block_size)
{
struct block_store *block_store = NULL;
size_t num_blocks = 0;
@@ -334,14 +288,12 @@
assert(this_instance);
/* Define concrete block store interface */
- static const struct block_store_interface interface = {
- file_block_store_get_partition_info,
- file_block_store_open,
- file_block_store_close,
- file_block_store_read,
- file_block_store_write,
- file_block_store_erase
- };
+ static const struct block_store_interface interface = { file_block_store_get_partition_info,
+ file_block_store_open,
+ file_block_store_close,
+ file_block_store_read,
+ file_block_store_write,
+ file_block_store_erase };
/* Initialize base block_store */
this_instance->base_block_device.base_block_store.context = this_instance;
@@ -354,7 +306,6 @@
this_instance->file_handle = fopen(filename, "r+b");
if (this_instance->file_handle) {
-
/* File already exists so initialise the view of the number of blocks */
ssize_t file_len = file_length(this_instance->file_handle);
@@ -362,25 +313,22 @@
num_blocks = (size_t)file_len / block_size;
} else {
-
/* File doesn't exist so create an empty one */
this_instance->file_handle = fopen(filename, "w+b");
}
if (this_instance->file_handle)
- block_store = block_device_init(
- &this_instance->base_block_device, NULL, num_blocks, block_size);
+ block_store = block_device_init(&this_instance->base_block_device, NULL, num_blocks,
+ block_size);
return block_store;
}
-void file_block_store_deinit(
- struct file_block_store *this_instance)
+void file_block_store_deinit(struct file_block_store *this_instance)
{
assert(this_instance);
if (this_instance->file_handle) {
-
fclose(this_instance->file_handle);
this_instance->file_handle = NULL;
}
@@ -388,16 +336,14 @@
block_device_deinit(&this_instance->base_block_device);
}
-psa_status_t file_block_store_configure(
- struct file_block_store *this_instance,
- const struct uuid_octets *disk_guid,
- size_t num_blocks,
- size_t block_size)
+psa_status_t file_block_store_configure(struct file_block_store *this_instance,
+ const struct uuid_octets *disk_guid, size_t num_blocks,
+ size_t block_size)
{
assert(this_instance);
- block_device_configure(&this_instance->base_block_device,
- disk_guid, num_blocks, block_size);
+ block_device_configure(&this_instance->base_block_device, disk_guid, num_blocks,
+ block_size);
return PSA_SUCCESS;
}
diff --git a/components/service/block_storage/block_store/device/file/file_block_store.h b/components/service/block_storage/block_store/device/file/file_block_store.h
index cb66b9b..889b8e3 100644
--- a/components/service/block_storage/block_store/device/file/file_block_store.h
+++ b/components/service/block_storage/block_store/device/file/file_block_store.h
@@ -10,6 +10,7 @@
#include <stdint.h>
#include <stdio.h>
+
#include "service/block_storage/block_store/device/block_device.h"
#ifdef __cplusplus
@@ -24,8 +25,7 @@
* consecutive blocks. The file_block_store can be used for accessing disk
* image files in a Posix environment.
*/
-struct file_block_store
-{
+struct file_block_store {
struct block_device base_block_device;
FILE *file_handle;
uint8_t erase_buf[256];
@@ -40,18 +40,15 @@
*
* \return Pointer to block_store or NULL on failure
*/
-struct block_store *file_block_store_init(
- struct file_block_store *file_block_store,
- const char *filename,
- size_t block_size);
+struct block_store *file_block_store_init(struct file_block_store *file_block_store,
+ const char *filename, size_t block_size);
/**
* \brief De-initialize a file_block_store
*
* \param[in] file_block_store The subject file_block_store
*/
-void file_block_store_deinit(
- struct file_block_store *file_block_store);
+void file_block_store_deinit(struct file_block_store *file_block_store);
/**
* \brief Configure the file_block_store
@@ -63,11 +60,9 @@
*
* \return PSA_SUCCESS if successful
*/
-psa_status_t file_block_store_configure(
- struct file_block_store *file_block_store,
- const struct uuid_octets *disk_guid,
- size_t num_blocks,
- size_t block_size);
+psa_status_t file_block_store_configure(struct file_block_store *file_block_store,
+ const struct uuid_octets *disk_guid, size_t num_blocks,
+ size_t block_size);
#ifdef __cplusplus
}
diff --git a/components/service/block_storage/block_store/device/file/test/file_block_store_tests.cpp b/components/service/block_storage/block_store/device/file/test/file_block_store_tests.cpp
index 34ea57c..ca87772 100644
--- a/components/service/block_storage/block_store/device/file/test/file_block_store_tests.cpp
+++ b/components/service/block_storage/block_store/device/file/test/file_block_store_tests.cpp
@@ -4,13 +4,14 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <cstring>
+#include <CppUTest/TestHarness.h>
#include <cstdio>
-#include <string>
+#include <cstring>
#include <stdint.h>
+#include <string>
+
#include "common/uuid/uuid.h"
#include "service/block_storage/block_store/device/file/file_block_store.h"
-#include "CppUTest/TestHarness.h"
TEST_GROUP(FileBlockStoreTests)
{
@@ -19,44 +20,32 @@
m_filename = std::string("file_block_store.tmp");
memset(m_disk_guid.octets, 0, sizeof(m_disk_guid.octets));
- struct block_store *block_store = file_block_store_init(
- &m_file_block_store,
- m_filename.c_str(),
- BLOCK_SIZE);
+ struct block_store *block_store =
+ file_block_store_init(&m_file_block_store, m_filename.c_str(), BLOCK_SIZE);
CHECK_TRUE(block_store);
- psa_status_t status = file_block_store_configure(
- &m_file_block_store,
- &m_disk_guid,
- NUM_BLOCKS, BLOCK_SIZE);
+ psa_status_t status = file_block_store_configure(&m_file_block_store, &m_disk_guid,
+ NUM_BLOCKS, BLOCK_SIZE);
LONGS_EQUAL(PSA_SUCCESS, status);
- status = block_store_open(
- &m_file_block_store.base_block_device.base_block_store,
- CLIENT_ID,
- &m_disk_guid,
- &m_partition_handle);
+ status = block_store_open(&m_file_block_store.base_block_device.base_block_store,
+ CLIENT_ID, &m_disk_guid, &m_partition_handle);
LONGS_EQUAL(PSA_SUCCESS, status);
}
void teardown()
{
- block_store_close(
- &m_file_block_store.base_block_device.base_block_store,
- CLIENT_ID,
- m_partition_handle);
+ block_store_close(&m_file_block_store.base_block_device.base_block_store, CLIENT_ID,
+ m_partition_handle);
file_block_store_deinit(&m_file_block_store);
remove(m_filename.c_str());
}
- void set_block(
- size_t lba, size_t offset,
- size_t len, uint8_t val,
- size_t *num_written)
+ void set_block(size_t lba, size_t offset, size_t len, uint8_t val, size_t * num_written)
{
struct block_store *bs = &m_file_block_store.base_block_device.base_block_store;
uint8_t write_buf[len];
@@ -64,27 +53,20 @@
memset(write_buf, val, len);
*num_written = 0;
- psa_status_t status = block_store_write(
- bs, CLIENT_ID, m_partition_handle,
- lba, offset,
- write_buf, len, num_written);
+ psa_status_t status = block_store_write(bs, CLIENT_ID, m_partition_handle, lba,
+ offset, write_buf, len, num_written);
LONGS_EQUAL(PSA_SUCCESS, status);
}
- void check_block(
- size_t lba, size_t offset,
- size_t len, uint8_t expected_val)
+ void check_block(size_t lba, size_t offset, size_t len, uint8_t expected_val)
{
struct block_store *bs = &m_file_block_store.base_block_device.base_block_store;
uint8_t read_buf[len];
size_t num_read = 0;
- psa_status_t status = block_store_read(
- bs, CLIENT_ID, m_partition_handle,
- lba, offset,
- len, read_buf,
- &num_read);
+ psa_status_t status = block_store_read(bs, CLIENT_ID, m_partition_handle, lba,
+ offset, len, read_buf, &num_read);
LONGS_EQUAL(PSA_SUCCESS, status);
UNSIGNED_LONGS_EQUAL(len, num_read);
@@ -93,15 +75,12 @@
BYTES_EQUAL(expected_val, read_buf[i]);
}
- void erase_blocks(
- uint32_t begin_lba,
- size_t num_blocks)
+ void erase_blocks(uint32_t begin_lba, size_t num_blocks)
{
struct block_store *bs = &m_file_block_store.base_block_device.base_block_store;
- psa_status_t status = block_store_erase(
- bs, CLIENT_ID, m_partition_handle,
- begin_lba, num_blocks);
+ psa_status_t status =
+ block_store_erase(bs, CLIENT_ID, m_partition_handle, begin_lba, num_blocks);
LONGS_EQUAL(PSA_SUCCESS, status);
}
@@ -160,26 +139,19 @@
UNSIGNED_LONGS_EQUAL(BLOCK_SIZE, num_written);
/* Close the block_store opened during setup. This will have created a disk image file */
- block_store_close(
- &m_file_block_store.base_block_device.base_block_store,
- CLIENT_ID,
- m_partition_handle);
+ block_store_close(&m_file_block_store.base_block_device.base_block_store, CLIENT_ID,
+ m_partition_handle);
file_block_store_deinit(&m_file_block_store);
/* Re-initialise and open */
- struct block_store *block_store = file_block_store_init(
- &m_file_block_store,
- m_filename.c_str(),
- BLOCK_SIZE);
+ struct block_store *block_store =
+ file_block_store_init(&m_file_block_store, m_filename.c_str(), BLOCK_SIZE);
CHECK_TRUE(block_store);
- psa_status_t status = block_store_open(
- block_store,
- CLIENT_ID,
- &m_disk_guid,
- &m_partition_handle);
+ psa_status_t status =
+ block_store_open(block_store, CLIENT_ID, &m_disk_guid, &m_partition_handle);
LONGS_EQUAL(PSA_SUCCESS, status);
diff --git a/components/service/block_storage/factory/file/block_store_factory.c b/components/service/block_storage/factory/file/block_store_factory.c
index d879332..c691510 100644
--- a/components/service/block_storage/factory/file/block_store_factory.c
+++ b/components/service/block_storage/factory/file/block_store_factory.c
@@ -5,28 +5,29 @@
*
*/
+#include "block_store_factory.h"
+
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
-#include <trace.h>
-#include "block_store_factory.h"
+
+#include "media/volume/block_volume/block_volume.h"
+#include "media/volume/index/volume_index.h"
#include "service/block_storage/block_store/device/file/file_block_store.h"
#include "service/block_storage/block_store/partitioned/partitioned_block_store.h"
#include "service/block_storage/config/gpt/gpt_partition_configurator.h"
-#include "media/volume/index/volume_index.h"
-#include "media/volume/block_volume/block_volume.h"
+#include "trace.h"
#ifndef FILE_BLOCK_SIZE
/* Default to most common block size for UEFI volumes */
-#define FILE_BLOCK_SIZE (512)
+#define FILE_BLOCK_SIZE (512)
#endif
static char disk_img_filename[256];
-struct block_store_assembly
-{
+struct block_store_assembly {
struct file_block_store file_block_store;
struct partitioned_block_store partitioned_block_store;
struct block_volume volume;
@@ -49,10 +50,9 @@
{
struct block_store *product = NULL;
struct block_store_assembly *assembly =
- (struct block_store_assembly*)malloc(sizeof(struct block_store_assembly));
+ (struct block_store_assembly *)malloc(sizeof(struct block_store_assembly));
if (assembly) {
-
struct uuid_octets disk_guid;
memset(&disk_guid, 0, sizeof(disk_guid));
@@ -64,36 +64,27 @@
/* Initialise a file_block_store to provide underlying storage */
struct block_store *secure_flash = file_block_store_init(
- &assembly->file_block_store,
- disk_img_filename,
- FILE_BLOCK_SIZE);
+ &assembly->file_block_store, disk_img_filename, FILE_BLOCK_SIZE);
if (secure_flash) {
-
/* Secure flash successfully initialized so create a block_volume
* associated with secure flash block store to enable it to be
* accessed as a storage volume.
*/
struct volume *volume = NULL;
- int result = block_volume_init(&assembly->volume,
- secure_flash, &disk_guid,
- &volume);
+ int result = block_volume_init(&assembly->volume, secure_flash, &disk_guid,
+ &volume);
if (result == 0) {
-
volume_index_add(VOLUME_ID_SECURE_FLASH, volume);
/* Stack a partitioned_block_store over the back store */
product = partitioned_block_store_init(
- &assembly->partitioned_block_store,
- 0,
- &disk_guid,
- secure_flash,
- NULL);
+ &assembly->partitioned_block_store, 0, &disk_guid,
+ secure_flash, NULL);
if (product) {
-
/* Successfully created the block store stack so configure the
* partitions if there are any described in the GPT. No GPT
* is a valid configuration option so it's deliberately not
@@ -115,7 +106,6 @@
EMSG("Failed to init file_block_store: %s", disk_img_filename);
if (!product) {
-
/* Something went wrong! */
tear_down_assembly(assembly);
}
@@ -128,13 +118,13 @@
void file_block_store_factory_destroy(struct block_store *block_store)
{
if (block_store) {
-
size_t offset_into_assembly =
offsetof(struct block_store_assembly, partitioned_block_store) +
offsetof(struct partitioned_block_store, base_block_store);
- struct block_store_assembly *assembly = (struct block_store_assembly*)
- ((uint8_t*)block_store - offset_into_assembly);
+ struct block_store_assembly *assembly =
+ (struct block_store_assembly *)((uint8_t *)block_store -
+ offset_into_assembly);
tear_down_assembly(assembly);
}
diff --git a/components/service/block_storage/factory/file/block_store_factory.h b/components/service/block_storage/factory/file/block_store_factory.h
index 647a4df..c37513f 100644
--- a/components/service/block_storage/factory/file/block_store_factory.h
+++ b/components/service/block_storage/factory/file/block_store_factory.h
@@ -45,7 +45,6 @@
*/
void file_block_store_factory_set_filename(const char *filename);
-
#ifdef __cplusplus
}
#endif
diff --git a/components/service/fwu/agent/fw_directory.c b/components/service/fwu/agent/fw_directory.c
index c794832..ec7486b 100644
--- a/components/service/fwu/agent/fw_directory.c
+++ b/components/service/fwu/agent/fw_directory.c
@@ -5,14 +5,15 @@
*
*/
+#include "fw_directory.h"
+
#include <assert.h>
#include <stddef.h>
#include <string.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include "fw_directory.h"
-void fw_directory_init(
- struct fw_directory *fw_directory)
+#include "protocols/service/fwu/packed-c/status.h"
+
+void fw_directory_init(struct fw_directory *fw_directory)
{
assert(fw_directory);
@@ -22,23 +23,20 @@
memset(fw_directory, 0, sizeof(struct fw_directory));
}
-void fw_directory_deinit(
- struct fw_directory *fw_directory)
+void fw_directory_deinit(struct fw_directory *fw_directory)
{
(void)fw_directory;
}
-void fw_directory_set_boot_info(
- struct fw_directory *fw_directory,
- const struct boot_info *boot_info)
+void fw_directory_set_boot_info(struct fw_directory *fw_directory,
+ const struct boot_info *boot_info)
{
assert(fw_directory);
fw_directory->boot_info = *boot_info;
}
-int fw_directory_add_image_info(
- struct fw_directory *fw_directory,
- const struct image_info *image_info)
+int fw_directory_add_image_info(struct fw_directory *fw_directory,
+ const struct image_info *image_info)
{
assert(fw_directory);
assert(image_info);
@@ -46,7 +44,6 @@
int status = FWU_STATUS_UNKNOWN;
if (fw_directory->num_images < FWU_MAX_FW_DIRECTORY_ENTRIES) {
-
uint32_t image_index = fw_directory->num_images;
fw_directory->entries[image_index] = *image_info;
@@ -60,9 +57,8 @@
return status;
}
-const struct image_info *fw_directory_find_image_info(
- const struct fw_directory *fw_directory,
- const struct uuid_octets *img_type_uuid)
+const struct image_info *fw_directory_find_image_info(const struct fw_directory *fw_directory,
+ const struct uuid_octets *img_type_uuid)
{
assert(fw_directory);
assert(img_type_uuid);
@@ -70,10 +66,8 @@
const struct image_info *info = NULL;
for (size_t i = 0; i < fw_directory->num_images; i++) {
-
if (uuid_is_equal(img_type_uuid->octets,
- fw_directory->entries[i].img_type_uuid.octets)) {
-
+ fw_directory->entries[i].img_type_uuid.octets)) {
info = &fw_directory->entries[i];
break;
}
@@ -82,16 +76,14 @@
return info;
}
-const struct boot_info *fw_directory_get_boot_info(
- const struct fw_directory *fw_directory)
+const struct boot_info *fw_directory_get_boot_info(const struct fw_directory *fw_directory)
{
assert(fw_directory);
return &fw_directory->boot_info;
}
-const struct image_info *fw_directory_get_image_info(
- const struct fw_directory *fw_directory,
- size_t index)
+const struct image_info *fw_directory_get_image_info(const struct fw_directory *fw_directory,
+ size_t index)
{
assert(fw_directory);
@@ -103,8 +95,7 @@
return info;
}
-size_t fw_directory_num_images(
- const struct fw_directory *fw_directory)
+size_t fw_directory_num_images(const struct fw_directory *fw_directory)
{
assert(fw_directory);
return fw_directory->num_images;
diff --git a/components/service/fwu/agent/fw_directory.h b/components/service/fwu/agent/fw_directory.h
index 119f5bc..6c59554 100644
--- a/components/service/fwu/agent/fw_directory.h
+++ b/components/service/fwu/agent/fw_directory.h
@@ -11,7 +11,8 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-#include <common/uuid/uuid.h>
+
+#include "common/uuid/uuid.h"
#include "install_type.h"
#ifdef __cplusplus
@@ -23,7 +24,7 @@
* Can be overridden by an external definition.
*/
#ifndef FWU_MAX_FW_DIRECTORY_ENTRIES
-#define FWU_MAX_FW_DIRECTORY_ENTRIES (20)
+#define FWU_MAX_FW_DIRECTORY_ENTRIES (20)
#endif
/**
@@ -71,7 +72,7 @@
/* The version of the currently active version of this image. */
uint32_t active_version;
- /* Bitmap of access permissions for this iamge. */
+ /* Bitmap of access permissions for this image. */
uint32_t permissions;
/* The index [0..n] of the image in the fw directory. */
@@ -108,16 +109,14 @@
*
* \param[in] fw_directory The subject fw_directory
*/
-void fw_directory_init(
- struct fw_directory *fw_directory);
+void fw_directory_init(struct fw_directory *fw_directory);
/**
* \brief De-initialise a fw_directory
*
* \param[in] fw_directory The subject fw_directory
*/
-void fw_directory_deinit(
- struct fw_directory *fw_directory);
+void fw_directory_deinit(struct fw_directory *fw_directory);
/**
* \brief Sets the boot_info held by the fw_directory
@@ -127,9 +126,8 @@
* \param[in] fw_directory The subject fw_directory
* \param[in] boot_info boot_info for most recent system boot
*/
-void fw_directory_set_boot_info(
- struct fw_directory *fw_directory,
- const struct boot_info *boot_info);
+void fw_directory_set_boot_info(struct fw_directory *fw_directory,
+ const struct boot_info *boot_info);
/**
* \brief Adds an image_info to the directory
@@ -141,9 +139,8 @@
*
* \return FWU status
*/
-int fw_directory_add_image_info(
- struct fw_directory *fw_directory,
- const struct image_info *image_info);
+int fw_directory_add_image_info(struct fw_directory *fw_directory,
+ const struct image_info *image_info);
/**
* \brief Find an image_info entry
@@ -155,9 +152,8 @@
*
* \return Pointer to image_info or NULL
*/
-const struct image_info *fw_directory_find_image_info(
- const struct fw_directory *fw_directory,
- const struct uuid_octets *img_type_uuid);
+const struct image_info *fw_directory_find_image_info(const struct fw_directory *fw_directory,
+ const struct uuid_octets *img_type_uuid);
/**
* \brief Get the boot_info
@@ -166,8 +162,7 @@
*
* \return Pointer to the boot_info
*/
-const struct boot_info *fw_directory_get_boot_info(
- const struct fw_directory *fw_directory);
+const struct boot_info *fw_directory_get_boot_info(const struct fw_directory *fw_directory);
/**
* \brief Get an image_info by index
@@ -179,9 +174,8 @@
*
* \return Pointer to the image_info or NULL if index invalid
*/
-const struct image_info *fw_directory_get_image_info(
- const struct fw_directory *fw_directory,
- size_t index);
+const struct image_info *fw_directory_get_image_info(const struct fw_directory *fw_directory,
+ size_t index);
/**
* \brief Get the number of image_info entries held
@@ -190,8 +184,7 @@
*
* \return Number of entries
*/
-size_t fw_directory_num_images(
- const struct fw_directory *fw_directory);
+size_t fw_directory_num_images(const struct fw_directory *fw_directory);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/agent/img_dir_serializer.c b/components/service/fwu/agent/img_dir_serializer.c
index db210bc..d1f44af 100644
--- a/components/service/fwu/agent/img_dir_serializer.c
+++ b/components/service/fwu/agent/img_dir_serializer.c
@@ -5,19 +5,17 @@
*
*/
-#include <assert.h>
-#include <string.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
-#include <service/fwu/fw_store/fw_store.h>
-#include "fw_directory.h"
#include "img_dir_serializer.h"
-int img_dir_serializer_serialize(
- const struct fw_directory *fw_dir,
- const struct fw_store *fw_store,
- uint8_t *buf,
- size_t buf_size,
- size_t *data_len)
+#include <assert.h>
+#include <string.h>
+
+#include "fw_directory.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+#include "service/fwu/fw_store/fw_store.h"
+
+int img_dir_serializer_serialize(const struct fw_directory *fw_dir, const struct fw_store *fw_store,
+ uint8_t *buf, size_t buf_size, size_t *data_len)
{
size_t serialized_len = img_dir_serializer_get_len(fw_dir);
@@ -45,24 +43,19 @@
/* Serialize image info for each image */
for (size_t image_index = 0; image_index < output->num_images; image_index++) {
-
const struct image_info *image_info =
fw_directory_get_image_info(fw_dir, image_index);
assert(image_info);
memcpy(output->img_info_entry[image_index].img_type_uuid,
- image_info->img_type_uuid.octets,
- OSF_UUID_OCTET_LEN);
+ image_info->img_type_uuid.octets, OSF_UUID_OCTET_LEN);
- output->img_info_entry[image_index].client_permissions =
- image_info->permissions;
- output->img_info_entry[image_index].img_max_size =
- image_info->max_size;
+ output->img_info_entry[image_index].client_permissions = image_info->permissions;
+ output->img_info_entry[image_index].img_max_size = image_info->max_size;
output->img_info_entry[image_index].lowest_accepted_version =
image_info->lowest_accepted_version;
- output->img_info_entry[image_index].img_version =
- image_info->active_version;
+ output->img_info_entry[image_index].img_version = image_info->active_version;
output->img_info_entry[image_index].accepted =
(uint32_t)fw_store_is_accepted(fw_store, image_info);
}
@@ -72,10 +65,8 @@
return FWU_STATUS_SUCCESS;
}
-size_t img_dir_serializer_get_len(
- const struct fw_directory *fw_dir)
+size_t img_dir_serializer_get_len(const struct fw_directory *fw_dir)
{
- return
- offsetof(struct ts_fwu_image_directory, img_info_entry) +
- sizeof(struct ts_fwu_image_info_entry) * fw_directory_num_images(fw_dir);
+ return offsetof(struct ts_fwu_image_directory, img_info_entry) +
+ sizeof(struct ts_fwu_image_info_entry) * fw_directory_num_images(fw_dir);
}
diff --git a/components/service/fwu/agent/img_dir_serializer.h b/components/service/fwu/agent/img_dir_serializer.h
index 28274f2..fe8c7ec 100644
--- a/components/service/fwu/agent/img_dir_serializer.h
+++ b/components/service/fwu/agent/img_dir_serializer.h
@@ -36,12 +36,8 @@
*
* \return Status
*/
-int img_dir_serializer_serialize(
- const struct fw_directory *fw_dir,
- const struct fw_store *fw_store,
- uint8_t *buf,
- size_t buf_size,
- size_t *data_len);
+int img_dir_serializer_serialize(const struct fw_directory *fw_dir, const struct fw_store *fw_store,
+ uint8_t *buf, size_t buf_size, size_t *data_len);
/**
* \brief Return the length in bytes of the serialized image directory
@@ -50,8 +46,7 @@
*
* \return Size in bytes
*/
-size_t img_dir_serializer_get_len(
- const struct fw_directory *fw_dir);
+size_t img_dir_serializer_get_len(const struct fw_directory *fw_dir);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/agent/stream_manager.c b/components/service/fwu/agent/stream_manager.c
index 5284f71..c93bdf1 100644
--- a/components/service/fwu/agent/stream_manager.c
+++ b/components/service/fwu/agent/stream_manager.c
@@ -4,15 +4,16 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <stddef.h>
-#include <string.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include <service/fwu/fw_store/fw_store.h>
#include "stream_manager.h"
-static uint32_t generate_handle(
- struct stream_manager *subject,
- struct stream_context *context)
+#include <stddef.h>
+#include <string.h>
+
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/fw_store/fw_store.h"
+
+static uint32_t generate_handle(struct stream_manager *subject,
+ const struct stream_context *const context)
{
/* Handle includes rolling count value to protect against use of a stale handle */
uint32_t new_handle = context - subject->contexts;
@@ -27,9 +28,7 @@
return handle & 0xffff;
}
-static void add_to_free_list(
- struct stream_manager *subject,
- struct stream_context *context)
+static void add_to_free_list(struct stream_manager *subject, struct stream_context *context)
{
context->type = FWU_STREAM_TYPE_NONE;
context->handle = 0;
@@ -38,25 +37,18 @@
subject->free = context;
}
-static struct stream_context *alloc_stream_context(
- struct stream_manager *subject,
- enum fwu_stream_type type,
- uint32_t *handle)
+static struct stream_context *alloc_stream_context(struct stream_manager *subject,
+ enum fwu_stream_type type, uint32_t *handle)
{
struct stream_context *context = NULL;
/* Re-cycle least-recently used context if there are no free contexts */
if (!subject->free && subject->active_tail) {
-
- stream_manager_close(
- subject,
- subject->active_tail->handle,
- false);
+ stream_manager_close(subject, subject->active_tail->handle, false);
}
/* Active contexts are held in a linked list in most recently allocated order */
if (subject->free) {
-
context = subject->free;
subject->free = context->next;
@@ -79,9 +71,7 @@
return context;
}
-static void free_stream_context(
- struct stream_manager *subject,
- struct stream_context *context)
+static void free_stream_context(struct stream_manager *subject, struct stream_context *context)
{
/* Remove from active list */
if (context->prev)
@@ -98,17 +88,14 @@
add_to_free_list(subject, context);
}
-static struct stream_context *get_active_context(
- struct stream_manager *subject,
- uint32_t handle)
+static struct stream_context *get_active_context(struct stream_manager *subject, uint32_t handle)
{
struct stream_context *context = NULL;
uint32_t index = index_from_handle(handle);
if ((index < FWU_STREAM_MANAGER_POOL_SIZE) &&
- (subject->contexts[index].type != FWU_STREAM_TYPE_NONE) &&
- (subject->contexts[index].handle == handle)) {
-
+ (subject->contexts[index].type != FWU_STREAM_TYPE_NONE) &&
+ (subject->contexts[index].handle == handle)) {
/* Handle qualifies an active stream context */
context = &subject->contexts[index];
}
@@ -116,8 +103,7 @@
return context;
}
-void stream_manager_init(
- struct stream_manager *subject)
+void stream_manager_init(struct stream_manager *subject)
{
subject->free = NULL;
subject->active_head = NULL;
@@ -128,17 +114,13 @@
add_to_free_list(subject, &subject->contexts[i]);
}
-void stream_manager_deinit(
- struct stream_manager *subject)
+void stream_manager_deinit(struct stream_manager *subject)
{
(void)subject;
}
-int stream_manager_open_buffer_stream(
- struct stream_manager *subject,
- const uint8_t *data,
- size_t data_len,
- uint32_t *handle)
+int stream_manager_open_buffer_stream(struct stream_manager *subject, const uint8_t *data,
+ size_t data_len, uint32_t *handle)
{
struct stream_context *context;
int status = FWU_STATUS_UNKNOWN;
@@ -149,22 +131,17 @@
* being updated while a read stream is open.
*/
for (size_t i = 0; i < FWU_STREAM_MANAGER_POOL_SIZE; i++) {
-
context = &subject->contexts[i];
if ((context->type == FWU_STREAM_TYPE_BUFFER) &&
- (context->variant.buffer.data == data))
+ (context->variant.buffer.data == data))
free_stream_context(subject, context);
}
/* Allocate and initialize a new stream */
- context = alloc_stream_context(
- subject,
- FWU_STREAM_TYPE_BUFFER,
- handle);
+ context = alloc_stream_context(subject, FWU_STREAM_TYPE_BUFFER, handle);
if (context) {
-
context->variant.buffer.data = data;
context->variant.buffer.data_len = data_len;
context->variant.buffer.pos = 0;
@@ -175,12 +152,9 @@
return status;
}
-int stream_manager_open_install_stream(
- struct stream_manager *subject,
- struct fw_store *fw_store,
- struct installer *installer,
- const struct image_info *image_info,
- uint32_t *stream_handle)
+int stream_manager_open_install_stream(struct stream_manager *subject, struct fw_store *fw_store,
+ struct installer *installer,
+ const struct image_info *image_info, uint32_t *stream_handle)
{
struct stream_context *context;
int status = FWU_STATUS_UNKNOWN;
@@ -191,23 +165,18 @@
* same installer, resulting in image corruption.
*/
for (size_t i = 0; i < FWU_STREAM_MANAGER_POOL_SIZE; i++) {
-
context = &subject->contexts[i];
if ((context->type == FWU_STREAM_TYPE_INSTALL) &&
- (context->variant.install.fw_store == fw_store) &&
- (context->variant.install.installer == installer))
+ (context->variant.install.fw_store == fw_store) &&
+ (context->variant.install.installer == installer))
free_stream_context(subject, context);
}
/* Allocate and initialize a new stream */
- context = alloc_stream_context(
- subject,
- FWU_STREAM_TYPE_INSTALL,
- stream_handle);
+ context = alloc_stream_context(subject, FWU_STREAM_TYPE_INSTALL, stream_handle);
if (context) {
-
context->variant.install.fw_store = fw_store;
context->variant.install.installer = installer;
context->variant.install.image_info = image_info;
@@ -218,25 +187,19 @@
return status;
}
-int stream_manager_close(
- struct stream_manager *subject,
- uint32_t handle,
- bool accepted)
+int stream_manager_close(struct stream_manager *subject, uint32_t handle, bool accepted)
{
int status = FWU_STATUS_UNKNOWN;
struct stream_context *context = get_active_context(subject, handle);
if (context) {
-
status = FWU_STATUS_SUCCESS;
if (context->type == FWU_STREAM_TYPE_INSTALL) {
-
- status = fw_store_commit_image(
- context->variant.install.fw_store,
- context->variant.install.installer,
- context->variant.install.image_info,
- accepted);
+ status = fw_store_commit_image(context->variant.install.fw_store,
+ context->variant.install.installer,
+ context->variant.install.image_info,
+ accepted);
}
free_stream_context(subject, context);
@@ -245,12 +208,9 @@
return status;
}
-void stream_manager_cancel_streams(
- struct stream_manager *subject,
- enum fwu_stream_type type)
+void stream_manager_cancel_streams(struct stream_manager *subject, enum fwu_stream_type type)
{
for (size_t i = 0; i < FWU_STREAM_MANAGER_POOL_SIZE; i++) {
-
struct stream_context *context = &subject->contexts[i];
if (context->type == type)
@@ -258,18 +218,14 @@
}
}
-bool stream_manager_is_open_streams(
- const struct stream_manager *subject,
- enum fwu_stream_type type)
+bool stream_manager_is_open_streams(const struct stream_manager *subject, enum fwu_stream_type type)
{
bool any_open = false;
for (size_t i = 0; i < FWU_STREAM_MANAGER_POOL_SIZE; i++) {
-
const struct stream_context *context = &subject->contexts[i];
if (context->type == type) {
-
any_open = true;
break;
}
@@ -278,45 +234,31 @@
return any_open;
}
-int stream_manager_write(
- struct stream_manager *subject,
- uint32_t handle,
- const uint8_t *data,
- size_t data_len)
+int stream_manager_write(struct stream_manager *subject, uint32_t handle, const uint8_t *data,
+ size_t data_len)
{
int status = FWU_STATUS_UNKNOWN;
struct stream_context *context = get_active_context(subject, handle);
if (context && context->type == FWU_STREAM_TYPE_INSTALL) {
-
- status = fw_store_write_image(
- context->variant.install.fw_store,
- context->variant.install.installer,
- data, data_len);
+ status = fw_store_write_image(context->variant.install.fw_store,
+ context->variant.install.installer, data, data_len);
}
return status;
}
-int stream_manager_read(
- struct stream_manager *subject,
- uint32_t handle,
- uint8_t *buf,
- size_t buf_size,
- size_t *read_len,
- size_t *total_len)
+int stream_manager_read(struct stream_manager *subject, uint32_t handle, uint8_t *buf,
+ size_t buf_size, size_t *read_len, size_t *total_len)
{
int status = FWU_STATUS_UNKNOWN;
struct stream_context *context = get_active_context(subject, handle);
if (context) {
-
if (context->type == FWU_STREAM_TYPE_BUFFER) {
-
size_t pos = context->variant.buffer.pos;
size_t remaining_len = context->variant.buffer.data_len - pos;
- size_t len_to_read =
- (remaining_len <= buf_size) ? remaining_len : buf_size;
+ size_t len_to_read = (remaining_len <= buf_size) ? remaining_len : buf_size;
memcpy(buf, &context->variant.buffer.data[pos], len_to_read);
@@ -326,7 +268,6 @@
status = FWU_STATUS_SUCCESS;
} else {
-
/* Reading from other types of stream is forbidden */
status = FWU_STATUS_DENIED;
}
diff --git a/components/service/fwu/agent/stream_manager.h b/components/service/fwu/agent/stream_manager.h
index 422080d..0ce534d 100644
--- a/components/service/fwu/agent/stream_manager.h
+++ b/components/service/fwu/agent/stream_manager.h
@@ -8,8 +8,8 @@
#define FWU_STREAM_MANAGER_H
#include <stdbool.h>
-#include <stdint.h>
#include <stddef.h>
+#include <stdint.h>
/**
* Manages the set of streams used by the update_agent for image installation
@@ -35,17 +35,13 @@
* The default stream subject size
*/
#ifndef FWU_STREAM_MANAGER_POOL_SIZE
-#define FWU_STREAM_MANAGER_POOL_SIZE (4)
+#define FWU_STREAM_MANAGER_POOL_SIZE (4)
#endif
/**
* Identifier for the type of stream
*/
-enum fwu_stream_type {
- FWU_STREAM_TYPE_NONE,
- FWU_STREAM_TYPE_BUFFER,
- FWU_STREAM_TYPE_INSTALL
-};
+enum fwu_stream_type { FWU_STREAM_TYPE_NONE, FWU_STREAM_TYPE_BUFFER, FWU_STREAM_TYPE_INSTALL };
/**
* A stream context
@@ -57,7 +53,6 @@
struct stream_context *prev;
union stream_variant {
-
/* Buffer stream variant */
struct buffer_variant {
size_t pos;
@@ -115,11 +110,8 @@
*
* \return FWU status
*/
-int stream_manager_open_buffer_stream(
- struct stream_manager *subject,
- const uint8_t *data,
- size_t data_len,
- uint32_t *stream_handle);
+int stream_manager_open_buffer_stream(struct stream_manager *subject, const uint8_t *data,
+ size_t data_len, uint32_t *stream_handle);
/**
* \brief Open an install stream
@@ -135,12 +127,10 @@
*
* \return FWU status
*/
-int stream_manager_open_install_stream(
- struct stream_manager *subject,
- struct fw_store *fw_store,
- struct installer *installer,
- const struct image_info *image_info,
- uint32_t *stream_handle);
+int stream_manager_open_install_stream(struct stream_manager *subject, struct fw_store *fw_store,
+ struct installer *installer,
+ const struct image_info *image_info,
+ uint32_t *stream_handle);
/**
* \brief Close a previously opened stream
@@ -151,10 +141,7 @@
*
* \return FWU status
*/
-int stream_manager_close(
- struct stream_manager *subject,
- uint32_t stream_handle,
- bool accepted);
+int stream_manager_close(struct stream_manager *subject, uint32_t stream_handle, bool accepted);
/**
* \brief Cancel all streams of the specified type
@@ -162,9 +149,7 @@
* \param[in] subject The subject stream_manager
* \param[in] type Type of stream to cancel
*/
-void stream_manager_cancel_streams(
- struct stream_manager *subject,
- enum fwu_stream_type type);
+void stream_manager_cancel_streams(struct stream_manager *subject, enum fwu_stream_type type);
/**
* \brief Check for any open streams of the specified type
@@ -174,9 +159,8 @@
*
* \return True is any are open
*/
-bool stream_manager_is_open_streams(
- const struct stream_manager *subject,
- enum fwu_stream_type type);
+bool stream_manager_is_open_streams(const struct stream_manager *subject,
+ enum fwu_stream_type type);
/**
* \brief Write to a previously opened stream
@@ -188,11 +172,8 @@
*
* \return Status (0 on success)
*/
-int stream_manager_write(
- struct stream_manager *subject,
- uint32_t stream_handle,
- const uint8_t *data,
- size_t data_len);
+int stream_manager_write(struct stream_manager *subject, uint32_t stream_handle,
+ const uint8_t *data, size_t data_len);
/**
* \brief Read from a previously opened stream
@@ -206,14 +187,8 @@
*
* \return Status (0 on success)
*/
-int stream_manager_read(
- struct stream_manager *subject,
- uint32_t handle,
- uint8_t *buf,
- size_t buf_size,
- size_t *read_len,
- size_t *total_len);
-
+int stream_manager_read(struct stream_manager *subject, uint32_t handle, uint8_t *buf,
+ size_t buf_size, size_t *read_len, size_t *total_len);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/components/service/fwu/agent/update_agent.c b/components/service/fwu/agent/update_agent.c
index c54e9e5..2a4d19d 100644
--- a/components/service/fwu/agent/update_agent.c
+++ b/components/service/fwu/agent/update_agent.c
@@ -5,42 +5,30 @@
*
*/
+#include "update_agent.h"
+
#include <assert.h>
#include <stdlib.h>
#include <string.h>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
-#include <service/fwu/fw_store/fw_store.h>
-#include <service/fwu/inspector/fw_inspector.h>
+
+#include "common/uuid/uuid.h"
#include "img_dir_serializer.h"
-#include "update_agent.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/fw_store/fw_store.h"
+#include "service/fwu/inspector/fw_inspector.h"
+static bool open_image_directory(struct update_agent *update_agent, const struct uuid_octets *uuid,
+ uint32_t *handle, int *status);
-static bool open_image_directory(
- struct update_agent *update_agent,
- const struct uuid_octets *uuid,
- uint32_t *handle,
- int *status);
+static bool open_fw_store_object(struct update_agent *update_agent, const struct uuid_octets *uuid,
+ uint32_t *handle, int *status);
-static bool open_fw_store_object(
- struct update_agent *update_agent,
- const struct uuid_octets *uuid,
- uint32_t *handle,
- int *status);
+static bool open_fw_image(struct update_agent *update_agent, const struct uuid_octets *uuid,
+ uint32_t *handle, int *status);
-static bool open_fw_image(
- struct update_agent *update_agent,
- const struct uuid_octets *uuid,
- uint32_t *handle,
- int *status);
-
-
-int update_agent_init(
- struct update_agent *update_agent,
- unsigned int boot_index,
- fw_inspector_inspect fw_inspect_method,
- struct fw_store *fw_store)
+int update_agent_init(struct update_agent *update_agent, unsigned int boot_index,
+ fw_inspector_inspect fw_inspect_method, struct fw_store *fw_store)
{
assert(update_agent);
assert(fw_inspect_method);
@@ -63,19 +51,15 @@
*/
fw_directory_init(&update_agent->fw_directory);
- status = update_agent->fw_inspect_method(
- &update_agent->fw_directory,
- boot_index);
+ status = update_agent->fw_inspect_method(&update_agent->fw_directory, boot_index);
if (status != FWU_STATUS_SUCCESS)
return status;
/* Allow the associated fw_store to synchronize its state to the
* state of the booted firmware reflected by the fw_directory.
*/
- status = fw_store_synchronize(
- update_agent->fw_store,
- &update_agent->fw_directory,
- boot_index);
+ status = fw_store_synchronize(update_agent->fw_store, &update_agent->fw_directory,
+ boot_index);
if (status != FWU_STATUS_SUCCESS)
return status;
@@ -86,15 +70,13 @@
return FWU_STATUS_UNKNOWN;
/* Transition to initial state */
- update_agent->state =
- fw_store_is_trial(update_agent->fw_store) ?
- FWU_STATE_TRIAL : FWU_STATE_REGULAR;
+ update_agent->state = fw_store_is_trial(update_agent->fw_store) ? FWU_STATE_TRIAL :
+ FWU_STATE_REGULAR;
return FWU_STATUS_SUCCESS;
}
-void update_agent_deinit(
- struct update_agent *update_agent)
+void update_agent_deinit(struct update_agent *update_agent)
{
update_agent->state = FWU_STATE_DEINITIALZED;
@@ -103,8 +85,7 @@
stream_manager_deinit(&update_agent->stream_manager);
}
-int update_agent_begin_staging(
- struct update_agent *update_agent)
+int update_agent_begin_staging(struct update_agent *update_agent)
{
int status = FWU_STATUS_DENIED;
@@ -112,7 +93,6 @@
update_agent_cancel_staging(update_agent);
if (update_agent->state == FWU_STATE_REGULAR) {
-
status = fw_store_begin_install(update_agent->fw_store);
/* Check if ready to install images */
@@ -123,21 +103,18 @@
return status;
}
-int update_agent_end_staging(
- struct update_agent *update_agent)
+int update_agent_end_staging(struct update_agent *update_agent)
{
int status = FWU_STATUS_DENIED;
if (update_agent->state == FWU_STATE_STAGING) {
-
/* The client is responsible for committing each installed image. If any
* install streams have been left open, not all images were committed.
*/
- bool any_uncommitted = stream_manager_is_open_streams(
- &update_agent->stream_manager, FWU_STREAM_TYPE_INSTALL);
+ bool any_uncommitted = stream_manager_is_open_streams(&update_agent->stream_manager,
+ FWU_STREAM_TYPE_INSTALL);
if (!any_uncommitted) {
-
/* All installed images have been committed so we're
* ready for a trial.
*/
@@ -150,7 +127,6 @@
update_agent->state = FWU_STATE_TRIAL_PENDING;
} else {
-
/* Client failed to commit all images installed */
status = FWU_STATUS_BUSY;
}
@@ -159,15 +135,13 @@
return status;
}
-int update_agent_cancel_staging(
- struct update_agent *update_agent)
+int update_agent_cancel_staging(struct update_agent *update_agent)
{
int status = FWU_STATUS_DENIED;
if (update_agent->state == FWU_STATE_STAGING) {
-
- stream_manager_cancel_streams(
- &update_agent->stream_manager, FWU_STREAM_TYPE_INSTALL);
+ stream_manager_cancel_streams(&update_agent->stream_manager,
+ FWU_STREAM_TYPE_INSTALL);
fw_store_cancel_install(update_agent->fw_store);
@@ -179,23 +153,17 @@
return status;
}
-int update_agent_accept(
- struct update_agent *update_agent,
- const struct uuid_octets *image_type_uuid)
+int update_agent_accept(struct update_agent *update_agent,
+ const struct uuid_octets *image_type_uuid)
{
int status = FWU_STATUS_DENIED;
if (update_agent->state == FWU_STATE_TRIAL) {
-
- const struct image_info *image_info = fw_directory_find_image_info(
- &update_agent->fw_directory,
- image_type_uuid);
+ const struct image_info *image_info =
+ fw_directory_find_image_info(&update_agent->fw_directory, image_type_uuid);
if (image_info) {
-
- if (fw_store_notify_accepted(
- update_agent->fw_store, image_info)) {
-
+ if (fw_store_notify_accepted(update_agent->fw_store, image_info)) {
/* From the fw_store perspective, the update has
* been fully accepted.
*/
@@ -213,14 +181,12 @@
return status;
}
-int update_agent_select_previous(
- struct update_agent *update_agent)
+int update_agent_select_previous(struct update_agent *update_agent)
{
int status = FWU_STATUS_DENIED;
if ((update_agent->state == FWU_STATE_TRIAL) ||
- (update_agent->state == FWU_STATE_TRIAL_PENDING)) {
-
+ (update_agent->state == FWU_STATE_TRIAL_PENDING)) {
status = fw_store_revert_to_previous(update_agent->fw_store);
update_agent->state = FWU_STATE_REGULAR;
}
@@ -228,18 +194,15 @@
return status;
}
-int update_agent_open(
- struct update_agent *update_agent,
- const struct uuid_octets *uuid,
- uint32_t *handle)
+int update_agent_open(struct update_agent *update_agent, const struct uuid_octets *uuid,
+ uint32_t *handle)
{
int status;
/* Pass UUID along a chain-of-responsibility until it's handled */
if (!open_image_directory(update_agent, uuid, handle, &status) &&
- !open_fw_store_object(update_agent, uuid, handle, &status) &&
- !open_fw_image(update_agent, uuid, handle, &status)) {
-
+ !open_fw_store_object(update_agent, uuid, handle, &status) &&
+ !open_fw_image(update_agent, uuid, handle, &status)) {
/* UUID not recognised */
status = FWU_STATUS_UNKNOWN;
}
@@ -247,73 +210,45 @@
return status;
}
-int update_agent_commit(
- struct update_agent *update_agent,
- uint32_t handle,
- bool accepted)
+int update_agent_commit(struct update_agent *update_agent, uint32_t handle, bool accepted)
{
- return stream_manager_close(
- &update_agent->stream_manager,
- handle,
- accepted);
+ return stream_manager_close(&update_agent->stream_manager, handle, accepted);
}
-int update_agent_write_stream(
- struct update_agent *update_agent,
- uint32_t handle,
- const uint8_t *data,
- size_t data_len)
+int update_agent_write_stream(struct update_agent *update_agent, uint32_t handle,
+ const uint8_t *data, size_t data_len)
{
- return stream_manager_write(
- &update_agent->stream_manager,
- handle,
- data, data_len);
+ return stream_manager_write(&update_agent->stream_manager, handle, data, data_len);
}
-int update_agent_read_stream(
- struct update_agent *update_agent,
- uint32_t handle,
- uint8_t *buf,
- size_t buf_size,
- size_t *read_len,
- size_t *total_len)
+int update_agent_read_stream(struct update_agent *update_agent, uint32_t handle, uint8_t *buf,
+ size_t buf_size, size_t *read_len, size_t *total_len)
{
- return stream_manager_read(
- &update_agent->stream_manager,
- handle,
- buf, buf_size,
- read_len, total_len);
+ return stream_manager_read(&update_agent->stream_manager, handle, buf, buf_size, read_len,
+ total_len);
}
-static bool open_image_directory(
- struct update_agent *update_agent,
- const struct uuid_octets *uuid,
- uint32_t *handle,
- int *status)
+static bool open_image_directory(struct update_agent *update_agent, const struct uuid_octets *uuid,
+ uint32_t *handle, int *status)
{
struct uuid_octets target_uuid;
uuid_guid_octets_from_canonical(&target_uuid, FWU_DIRECTORY_CANONICAL_UUID);
if (uuid_is_equal(uuid->octets, target_uuid.octets)) {
-
/* Serialize a fresh view of the image directory */
size_t serialized_len = 0;
- *status = img_dir_serializer_serialize(
- &update_agent->fw_directory,
- update_agent->fw_store,
- update_agent->image_dir_buf,
- update_agent->image_dir_buf_size,
- &serialized_len);
+ *status = img_dir_serializer_serialize(&update_agent->fw_directory,
+ update_agent->fw_store,
+ update_agent->image_dir_buf,
+ update_agent->image_dir_buf_size,
+ &serialized_len);
if (*status == FWU_STATUS_SUCCESS) {
-
- *status = stream_manager_open_buffer_stream(
- &update_agent->stream_manager,
- update_agent->image_dir_buf,
- serialized_len,
- handle);
+ *status = stream_manager_open_buffer_stream(&update_agent->stream_manager,
+ update_agent->image_dir_buf,
+ serialized_len, handle);
}
return true;
@@ -322,28 +257,18 @@
return false;
}
-static bool open_fw_store_object(
- struct update_agent *update_agent,
- const struct uuid_octets *uuid,
- uint32_t *handle,
- int *status)
+static bool open_fw_store_object(struct update_agent *update_agent, const struct uuid_octets *uuid,
+ uint32_t *handle, int *status)
{
const uint8_t *exported_data;
size_t exported_data_len;
- if (fw_store_export(
- update_agent->fw_store,
- uuid,
- &exported_data, &exported_data_len,
- status)) {
-
+ if (fw_store_export(update_agent->fw_store, uuid, &exported_data, &exported_data_len,
+ status)) {
if (*status == FWU_STATUS_SUCCESS) {
-
- *status = stream_manager_open_buffer_stream(
- &update_agent->stream_manager,
- exported_data,
- exported_data_len,
- handle);
+ *status = stream_manager_open_buffer_stream(&update_agent->stream_manager,
+ exported_data,
+ exported_data_len, handle);
}
return true;
@@ -352,38 +277,25 @@
return false;
}
-static bool open_fw_image(
- struct update_agent *update_agent,
- const struct uuid_octets *uuid,
- uint32_t *handle,
- int *status)
+static bool open_fw_image(struct update_agent *update_agent, const struct uuid_octets *uuid,
+ uint32_t *handle, int *status)
{
- const struct image_info *image_info = fw_directory_find_image_info(
- &update_agent->fw_directory,
- uuid);
+ const struct image_info *image_info =
+ fw_directory_find_image_info(&update_agent->fw_directory, uuid);
if (image_info) {
-
if (update_agent->state == FWU_STATE_STAGING) {
-
struct installer *installer;
- *status = fw_store_select_installer(
- update_agent->fw_store,
- image_info,
- &installer);
+ *status = fw_store_select_installer(update_agent->fw_store, image_info,
+ &installer);
if (*status == FWU_STATUS_SUCCESS) {
-
*status = stream_manager_open_install_stream(
- &update_agent->stream_manager,
- update_agent->fw_store,
- installer,
- image_info,
- handle);
+ &update_agent->stream_manager, update_agent->fw_store,
+ installer, image_info, handle);
}
} else {
-
/* Attempting to open a fw image when not staging */
*status = FWU_STATUS_DENIED;
}
diff --git a/components/service/fwu/agent/update_agent.h b/components/service/fwu/agent/update_agent.h
index 274e71a..ea214ee 100644
--- a/components/service/fwu/agent/update_agent.h
+++ b/components/service/fwu/agent/update_agent.h
@@ -10,9 +10,10 @@
#include <stdbool.h>
#include <stdint.h>
-#include <common/uuid/uuid.h>
-#include <service/fwu/inspector/fw_inspector.h>
+
+#include "common/uuid/uuid.h"
#include "fw_directory.h"
+#include "service/fwu/inspector/fw_inspector.h"
#include "stream_manager.h"
#ifdef __cplusplus
@@ -67,19 +68,15 @@
*
* \return Status (0 for success). Uses fwu protocol status codes.
*/
-int update_agent_init(
- struct update_agent *update_agent,
- unsigned int boot_index,
- fw_inspector_inspect fw_inspect_method,
- struct fw_store *fw_store);
+int update_agent_init(struct update_agent *update_agent, unsigned int boot_index,
+ fw_inspector_inspect fw_inspect_method, struct fw_store *fw_store);
/**
* \brief De-initialise the update_agent
*
* \param[in] update_agent The subject update_agent
*/
-void update_agent_deinit(
- struct update_agent *update_agent);
+void update_agent_deinit(struct update_agent *update_agent);
/**
* \brief Begin staging
@@ -88,8 +85,7 @@
*
* \return 0 on successfully transitioning to the STAGING state
*/
-int update_agent_begin_staging(
- struct update_agent *update_agent);
+int update_agent_begin_staging(struct update_agent *update_agent);
/**
* \brief End staging
@@ -98,8 +94,7 @@
*
* \return 0 on successfully transitioning to the TRIAL state
*/
-int update_agent_end_staging(
- struct update_agent *update_agent);
+int update_agent_end_staging(struct update_agent *update_agent);
/**
* \brief Cancel staging
@@ -108,8 +103,7 @@
*
* \return 0 on successfully transitioning to the REGULAR state
*/
-int update_agent_cancel_staging(
- struct update_agent *update_agent);
+int update_agent_cancel_staging(struct update_agent *update_agent);
/**
* \brief Accept an updated image
@@ -119,9 +113,8 @@
*
* \return Status (0 on success)
*/
-int update_agent_accept(
- struct update_agent *update_agent,
- const struct uuid_octets *image_type_uuid);
+int update_agent_accept(struct update_agent *update_agent,
+ const struct uuid_octets *image_type_uuid);
/**
* \brief Select previous version
@@ -132,8 +125,7 @@
*
* \return Status (0 on success)
*/
-int update_agent_select_previous(
- struct update_agent *update_agent);
+int update_agent_select_previous(struct update_agent *update_agent);
/**
* \brief Open a stream for accessing an fwu stream
@@ -147,10 +139,8 @@
*
* \return Status (0 on success)
*/
-int update_agent_open(
- struct update_agent *update_agent,
- const struct uuid_octets *uuid,
- uint32_t *handle);
+int update_agent_open(struct update_agent *update_agent, const struct uuid_octets *uuid,
+ uint32_t *handle);
/**
* \brief Close a stream and commit any writes to the stream
@@ -161,10 +151,7 @@
*
* \return Status (0 on success)
*/
-int update_agent_commit(
- struct update_agent *update_agent,
- uint32_t handle,
- bool accepted);
+int update_agent_commit(struct update_agent *update_agent, uint32_t handle, bool accepted);
/**
* \brief Write to a previously opened stream
@@ -176,11 +163,8 @@
*
* \return Status (0 on success)
*/
-int update_agent_write_stream(
- struct update_agent *update_agent,
- uint32_t handle,
- const uint8_t *data,
- size_t data_len);
+int update_agent_write_stream(struct update_agent *update_agent, uint32_t handle,
+ const uint8_t *data, size_t data_len);
/**
* \brief Read from a previously opened stream
@@ -194,14 +178,8 @@
*
* \return Status (0 on success)
*/
-int update_agent_read_stream(
- struct update_agent *update_agent,
- uint32_t handle,
- uint8_t *buf,
- size_t buf_size,
- size_t *read_len,
- size_t *total_len);
-
+int update_agent_read_stream(struct update_agent *update_agent, uint32_t handle, uint8_t *buf,
+ size_t buf_size, size_t *read_len, size_t *total_len);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/app/fwu_app.cpp b/components/service/fwu/app/fwu_app.cpp
index 70059d0..173afce 100644
--- a/components/service/fwu/app/fwu_app.cpp
+++ b/components/service/fwu/app/fwu_app.cpp
@@ -4,30 +4,32 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include "fwu_app.h"
+
#include <cassert>
#include <cstddef>
#include <cstring>
#include <errno.h>
-#include <media/volume/factory/volume_factory.h>
-#include <service/block_storage/factory/file/block_store_factory.h>
-#include <service/fwu/installer/factory/installer_factory.h>
-#include <service/fwu/fw_store/banked/bank_scheme.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.h>
-#include <service/fwu/inspector/direct/direct_fw_inspector.h>
-#include <service/fwu/agent/update_agent.h>
-#include <service/fwu/fw_store/banked/banked_fw_store.h>
-#include <service/fwu/config/fwu_configure.h>
+
+#include "media/volume/factory/volume_factory.h"
#include "metadata_reader.h"
-#include "fwu_app.h"
+#include "service/block_storage/factory/file/block_store_factory.h"
+#include "service/fwu/agent/update_agent.h"
+#include "service/fwu/config/fwu_configure.h"
+#include "service/fwu/fw_store/banked/bank_scheme.h"
+#include "service/fwu/fw_store/banked/banked_fw_store.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.h"
+#include "service/fwu/inspector/direct/direct_fw_inspector.h"
+#include "service/fwu/installer/factory/installer_factory.h"
extern "C" {
-#include <trace.h>
+#include "trace.h"
}
-fwu_app::fwu_app() :
- m_update_agent(),
- m_fw_store()
+fwu_app::fwu_app()
+ : m_update_agent()
+ , m_fw_store()
{
memset(&m_update_agent, 0, sizeof(m_update_agent));
memset(&m_fw_store, 0, sizeof(m_fw_store));
@@ -42,8 +44,7 @@
volume_factory_deinit();
}
-int fwu_app::configure(
- const char *disk_img_filename)
+int fwu_app::configure(const char *disk_img_filename)
{
if (disk_img_filename)
file_block_store_factory_set_filename(disk_img_filename);
@@ -51,11 +52,9 @@
struct uuid_octets device_uuids[MAX_STORAGE_DEVICES];
size_t num_storage_devices = 0;
- int status = volume_factory_init(device_uuids,
- MAX_STORAGE_DEVICES, &num_storage_devices);
+ int status = volume_factory_init(device_uuids, MAX_STORAGE_DEVICES, &num_storage_devices);
if (status) {
-
EMSG("Failed to init volume factory: %d", status);
return -EIO;
}
@@ -63,7 +62,6 @@
status = fwu_configure(device_uuids, num_storage_devices);
if (status) {
-
EMSG("Failed to setup FWU configuration: %d", status);
return -EIO;
}
@@ -71,28 +69,21 @@
return 0;
}
-int fwu_app::get_boot_info(
- unsigned int &active_index,
- unsigned int &metadata_version)
+int fwu_app::get_boot_info(unsigned int &active_index, unsigned int &metadata_version)
{
return metadata_reader::instance()->get_boot_info(active_index, metadata_version);
}
-int fwu_app::init_update_agent(
- unsigned int boot_index,
- unsigned int metadata_version)
+int fwu_app::init_update_agent(unsigned int boot_index, unsigned int metadata_version)
{
if (boot_index >= BANK_SCHEME_NUM_BANKS) {
-
IMSG("Invalid boot index");
return -1;
}
- const struct metadata_serializer *serializer =
- select_metadata_serializer(metadata_version);
+ const struct metadata_serializer *serializer = select_metadata_serializer(metadata_version);
if (!serializer) {
-
IMSG("Unsupported FWU metadata version");
return -1;
}
@@ -101,16 +92,14 @@
int status = banked_fw_store_init(&m_fw_store, serializer);
if (status) {
-
IMSG("fw store initialisation error %d", status);
return -1;
}
- status = update_agent_init(&m_update_agent, boot_index,
- direct_fw_inspector_inspect, &m_fw_store);
+ status = update_agent_init(&m_update_agent, boot_index, direct_fw_inspector_inspect,
+ &m_fw_store);
if (status) {
-
IMSG("update agent initialisation error %d", status);
return -1;
}
@@ -119,10 +108,8 @@
return 0;
}
-int fwu_app::update_image(
- const struct uuid_octets &img_type_uuid,
- const uint8_t *img_data,
- size_t img_size)
+int fwu_app::update_image(const struct uuid_octets &img_type_uuid, const uint8_t *img_data,
+ size_t img_size)
{
int status = update_agent_begin_staging(&m_update_agent);
@@ -131,17 +118,14 @@
uint32_t stream_handle = 0;
- status = update_agent_open(&m_update_agent,
- &img_type_uuid, &stream_handle);
+ status = update_agent_open(&m_update_agent, &img_type_uuid, &stream_handle);
if (!status) {
-
- status = update_agent_write_stream(&m_update_agent,
- stream_handle, img_data, img_size);
+ status = update_agent_write_stream(&m_update_agent, stream_handle, img_data,
+ img_size);
if (!status)
- status = update_agent_commit(&m_update_agent,
- stream_handle, false);
+ status = update_agent_commit(&m_update_agent, stream_handle, false);
}
if (!status)
@@ -152,9 +136,7 @@
return status;
}
-int fwu_app::read_object(
- const struct uuid_octets &object_uuid,
- std::vector<uint8_t> &data)
+int fwu_app::read_object(const struct uuid_octets &object_uuid, std::vector<uint8_t> &data)
{
uint32_t stream_handle = 0;
int status = update_agent_open(&m_update_agent, &object_uuid, &stream_handle);
@@ -172,23 +154,17 @@
data.resize(vector_capacity);
do {
-
size_t data_len_read = 0;
size_t requested_read_len = vector_capacity - read_so_far;
- status = update_agent_read_stream(
- &m_update_agent,
- stream_handle,
- &data[read_so_far],
- requested_read_len,
- &data_len_read,
- &reported_total_len);
+ status = update_agent_read_stream(&m_update_agent, stream_handle,
+ &data[read_so_far], requested_read_len,
+ &data_len_read, &reported_total_len);
read_so_far += data_len_read;
data.resize(read_so_far);
if (reported_total_len > vector_capacity) {
-
vector_capacity = reported_total_len;
data.resize(vector_capacity);
}
@@ -196,7 +172,6 @@
assert(read_so_far <= reported_total_len);
if (read_so_far == reported_total_len) {
-
/* Read all the data */
if (vector_capacity > reported_total_len)
data.resize(reported_total_len);
@@ -216,8 +191,7 @@
return &m_update_agent;
}
-const struct metadata_serializer *fwu_app::select_metadata_serializer(
- unsigned int version)
+const struct metadata_serializer *fwu_app::select_metadata_serializer(unsigned int version)
{
if (version == 1)
return metadata_serializer_v1();
diff --git a/components/service/fwu/app/fwu_app.h b/components/service/fwu/app/fwu_app.h
index 8e7f74c..8bbaa9d 100644
--- a/components/service/fwu/app/fwu_app.h
+++ b/components/service/fwu/app/fwu_app.h
@@ -9,9 +9,10 @@
#include <stdint.h>
#include <vector>
-#include <common/uuid/uuid.h>
-#include <service/fwu/agent/update_agent.h>
-#include <service/fwu/fw_store/banked/banked_fw_store.h>
+
+#include "common/uuid/uuid.h"
+#include "service/fwu/agent/update_agent.h"
+#include "service/fwu/fw_store/banked/banked_fw_store.h"
/*
* The fwu_app class is intended to provide the core for an application
@@ -23,7 +24,6 @@
* different application areas without overloading the base app.
*/
class fwu_app {
-
public:
fwu_app();
virtual ~fwu_app();
@@ -38,8 +38,7 @@
*
* \return Status (0 on success)
*/
- int configure(
- const char *disk_img_filename);
+ int configure(const char *disk_img_filename);
/**
* \brief Get boot info from the FWU metadata
@@ -49,9 +48,7 @@
*
* \return Status (0 on success)
*/
- int get_boot_info(
- unsigned int &active_index,
- unsigned int &metadata_version);
+ int get_boot_info(unsigned int &active_index, unsigned int &metadata_version);
/**
* \brief Initialise the update agent
@@ -61,9 +58,7 @@
*
* \return Status (0 on success)
*/
- int init_update_agent(
- unsigned int boot_index,
- unsigned int metadata_version);
+ int init_update_agent(unsigned int boot_index, unsigned int metadata_version);
/**
* \brief Update a single image
@@ -77,10 +72,8 @@
*
* \return Status (0 on success)
*/
- int update_image(
- const struct uuid_octets &img_type_uuid,
- const uint8_t *img_data,
- size_t img_size);
+ int update_image(const struct uuid_octets &img_type_uuid, const uint8_t *img_data,
+ size_t img_size);
/**
* \brief Read an object from the update agent
@@ -90,12 +83,9 @@
*
* \return Status (0 on success)
*/
- int read_object(
- const struct uuid_octets &object_uuid,
- std::vector<uint8_t> &data);
+ int read_object(const struct uuid_octets &object_uuid, std::vector<uint8_t> &data);
protected:
-
/**
* \brief Return pointer to update_agent struct
*
@@ -104,11 +94,9 @@
struct update_agent *update_agent();
private:
-
static const size_t MAX_STORAGE_DEVICES = 4;
- static const struct metadata_serializer *select_metadata_serializer(
- unsigned int version);
+ static const struct metadata_serializer *select_metadata_serializer(unsigned int version);
struct update_agent m_update_agent;
struct fw_store m_fw_store;
diff --git a/components/service/fwu/app/metadata_reader.cpp b/components/service/fwu/app/metadata_reader.cpp
index d1507f5..2d38a2f 100644
--- a/components/service/fwu/app/metadata_reader.cpp
+++ b/components/service/fwu/app/metadata_reader.cpp
@@ -4,24 +4,23 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <media/volume/volume.h>
-#include <media/volume/index/volume_index.h>
-#include <service/fwu/fw_store/banked/volume_id.h>
#include "metadata_reader.h"
+#include "media/volume/index/volume_index.h"
+#include "media/volume/volume.h"
+#include "service/fwu/fw_store/banked/volume_id.h"
+
extern "C" {
-#include <trace.h>
+#include "trace.h"
}
-metadata_reader::metadata_reader() :
- registered_readers()
+metadata_reader::metadata_reader()
+ : registered_readers()
{
-
}
metadata_reader::~metadata_reader()
{
-
}
metadata_reader *metadata_reader::instance()
@@ -35,16 +34,13 @@
registered_readers.push_back(reader);
}
-int metadata_reader::get_boot_info(
- unsigned int &active_index,
- unsigned int &metadata_version) const
+int metadata_reader::get_boot_info(unsigned int &active_index, unsigned int &metadata_version) const
{
struct volume *volume;
int status = volume_index_find(BANKED_VOLUME_ID_PRIMARY_METADATA, &volume);
if (status) {
-
IMSG("Failed to find metadata volume");
return status;
}
@@ -52,7 +48,6 @@
status = volume_open(volume);
if (!status) {
-
/* Assume whatever metadata version is in-use, it will fit in the buffer */
size_t len_read = 0;
uint8_t buf[1000];
@@ -60,15 +55,12 @@
status = volume_read(volume, (uintptr_t)buf, sizeof(buf), &len_read);
if (!status) {
-
bool is_handled = false;
for (unsigned int i = 0; i < registered_readers.size(); i++) {
-
metadata_version_specific_reader *reader = registered_readers[i];
if (reader->is_supported(buf, len_read)) {
-
reader->get_version(buf, len_read, metadata_version);
reader->get_active_index(buf, len_read, active_index);
@@ -78,7 +70,6 @@
}
if (!is_handled) {
-
/* This is normal on first-boot */
status = -1;
}
@@ -93,4 +84,3 @@
return status;
}
-
diff --git a/components/service/fwu/app/metadata_reader.h b/components/service/fwu/app/metadata_reader.h
index d84017c..19c3cf4 100644
--- a/components/service/fwu/app/metadata_reader.h
+++ b/components/service/fwu/app/metadata_reader.h
@@ -16,24 +16,18 @@
* input metadata version is supported.
*/
class metadata_version_specific_reader {
-
public:
+ virtual ~metadata_version_specific_reader()
+ {
+ }
- virtual ~metadata_version_specific_reader() {}
+ virtual bool is_supported(const uint8_t *buf, size_t data_len) const = 0;
- virtual bool is_supported(
- const uint8_t *buf,
- size_t data_len) const = 0;
+ virtual void get_version(const uint8_t *buf, size_t data_len,
+ unsigned int &version) const = 0;
- virtual void get_version(
- const uint8_t *buf,
- size_t data_len,
- unsigned int &version) const = 0;
-
- virtual void get_active_index(
- const uint8_t *buf,
- size_t data_len,
- unsigned int &active_index) const = 0;
+ virtual void get_active_index(const uint8_t *buf, size_t data_len,
+ unsigned int &active_index) const = 0;
};
/*
@@ -41,17 +35,13 @@
* The caller doesn't need to worry about the version of metadata being used.
*/
class metadata_reader {
-
public:
-
static metadata_reader *instance();
~metadata_reader();
void register_reader(metadata_version_specific_reader *reader);
- int get_boot_info(
- unsigned int &active_index,
- unsigned int &metadata_version) const;
+ int get_boot_info(unsigned int &active_index, unsigned int &metadata_version) const;
private:
metadata_reader();
diff --git a/components/service/fwu/app/metadata_v1_reader.cpp b/components/service/fwu/app/metadata_v1_reader.cpp
index 58faa23..195fa6e 100644
--- a/components/service/fwu/app/metadata_v1_reader.cpp
+++ b/components/service/fwu/app/metadata_v1_reader.cpp
@@ -5,63 +5,47 @@
*/
#include <assert.h>
-#include <protocols/service/fwu/packed-c/metadata_v1.h>
+
#include "metadata_reader.h"
+#include "protocols/service/fwu/packed-c/metadata_v1.h"
class metadata_v1_reader : public metadata_version_specific_reader {
-
public:
-
metadata_v1_reader();
~metadata_v1_reader();
- bool is_supported(
- const uint8_t *buf,
- size_t data_len) const;
+ bool is_supported(const uint8_t *buf, size_t data_len) const override;
- void get_version(
- const uint8_t *buf,
- size_t data_len,
- unsigned int &version) const;
+ void get_version(const uint8_t *buf, size_t data_len, unsigned int &version) const override;
- void get_active_index(
- const uint8_t *buf,
- size_t data_len,
- unsigned int &active_index) const;
+ void get_active_index(const uint8_t *buf, size_t data_len,
+ unsigned int &active_index) const override;
};
/* Registers on static construction */
static metadata_v1_reader the_v1_reader;
-
-metadata_v1_reader::metadata_v1_reader() :
- metadata_version_specific_reader()
+metadata_v1_reader::metadata_v1_reader()
+ : metadata_version_specific_reader()
{
metadata_reader::instance()->register_reader(this);
}
metadata_v1_reader::~metadata_v1_reader()
{
-
}
-bool metadata_v1_reader::is_supported(
- const uint8_t *buf,
- size_t data_len) const
+bool metadata_v1_reader::is_supported(const uint8_t *buf, size_t data_len) const
{
assert(buf);
const struct fwu_metadata *metadata = (const struct fwu_metadata *)buf;
- return
- (data_len >= sizeof(struct fwu_metadata)) &&
- (metadata->version == 1);
+ return (data_len >= sizeof(struct fwu_metadata)) && (metadata->version == 1);
}
-void metadata_v1_reader::get_version(
- const uint8_t *buf,
- size_t data_len,
- unsigned int &version) const
+void metadata_v1_reader::get_version(const uint8_t *buf, size_t data_len,
+ unsigned int &version) const
{
assert(buf);
assert(data_len >= sizeof(struct fwu_metadata));
@@ -71,10 +55,8 @@
version = metadata->version;
}
-void metadata_v1_reader::get_active_index(
- const uint8_t *buf,
- size_t data_len,
- unsigned int &active_index) const
+void metadata_v1_reader::get_active_index(const uint8_t *buf, size_t data_len,
+ unsigned int &active_index) const
{
assert(buf);
assert(data_len >= sizeof(struct fwu_metadata));
diff --git a/components/service/fwu/app/metadata_v2_reader.cpp b/components/service/fwu/app/metadata_v2_reader.cpp
index 0bf7a6b..61faa61 100644
--- a/components/service/fwu/app/metadata_v2_reader.cpp
+++ b/components/service/fwu/app/metadata_v2_reader.cpp
@@ -5,63 +5,47 @@
*/
#include <assert.h>
-#include <protocols/service/fwu/packed-c/metadata_v2.h>
+
#include "metadata_reader.h"
+#include "protocols/service/fwu/packed-c/metadata_v2.h"
class metadata_v2_reader : public metadata_version_specific_reader {
-
public:
-
metadata_v2_reader();
~metadata_v2_reader();
- bool is_supported(
- const uint8_t *buf,
- size_t data_len) const;
+ bool is_supported(const uint8_t *buf, size_t data_len) const override;
- void get_version(
- const uint8_t *buf,
- size_t data_len,
- unsigned int &version) const;
+ void get_version(const uint8_t *buf, size_t data_len, unsigned int &version) const override;
- void get_active_index(
- const uint8_t *buf,
- size_t data_len,
- unsigned int &active_index) const;
+ void get_active_index(const uint8_t *buf, size_t data_len,
+ unsigned int &active_index) const override;
};
/* Registers on static construction */
static metadata_v2_reader the_v2_reader;
-
-metadata_v2_reader::metadata_v2_reader() :
- metadata_version_specific_reader()
+metadata_v2_reader::metadata_v2_reader()
+ : metadata_version_specific_reader()
{
metadata_reader::instance()->register_reader(this);
}
metadata_v2_reader::~metadata_v2_reader()
{
-
}
-bool metadata_v2_reader::is_supported(
- const uint8_t *buf,
- size_t data_len) const
+bool metadata_v2_reader::is_supported(const uint8_t *buf, size_t data_len) const
{
assert(buf);
const struct fwu_metadata *metadata = (const struct fwu_metadata *)buf;
- return
- (data_len >= sizeof(struct fwu_metadata)) &&
- (metadata->version == 2);
+ return (data_len >= sizeof(struct fwu_metadata)) && (metadata->version == 2);
}
-void metadata_v2_reader::get_version(
- const uint8_t *buf,
- size_t data_len,
- unsigned int &version) const
+void metadata_v2_reader::get_version(const uint8_t *buf, size_t data_len,
+ unsigned int &version) const
{
assert(buf);
assert(data_len >= sizeof(struct fwu_metadata));
@@ -71,10 +55,8 @@
version = metadata->version;
}
-void metadata_v2_reader::get_active_index(
- const uint8_t *buf,
- size_t data_len,
- unsigned int &active_index) const
+void metadata_v2_reader::get_active_index(const uint8_t *buf, size_t data_len,
+ unsigned int &active_index) const
{
assert(buf);
assert(data_len >= sizeof(struct fwu_metadata));
diff --git a/components/service/fwu/config/fwu_configure.c b/components/service/fwu/config/fwu_configure.c
index 0a30518..998673f 100644
--- a/components/service/fwu/config/fwu_configure.c
+++ b/components/service/fwu/config/fwu_configure.c
@@ -5,13 +5,15 @@
*
*/
-#include <media/volume/index/volume_index.h>
-#include <media/volume/factory/volume_factory.h>
-#include <service/fwu/installer/installer_index.h>
-#include <service/fwu/installer/factory/installer_factory.h>
-#include <service/fwu/config/gpt/gpt_fwu_configure.h>
#include "fwu_configure.h"
+#include <service/fwu/config/gpt/gpt_fwu_configure.h>
+
+#include "media/volume/factory/volume_factory.h"
+#include "media/volume/index/volume_index.h"
+#include "service/fwu/installer/factory/installer_factory.h"
+#include "service/fwu/installer/installer_index.h"
+
int fwu_configure(const struct uuid_octets *device_uuids, size_t num_device_uuids)
{
unsigned int location_id = 0;
@@ -20,11 +22,9 @@
installer_index_init();
for (size_t i = 0; i < num_device_uuids; i++) {
-
unsigned int new_location_count = 0;
- int status = gpt_fwu_configure(&device_uuids[i],
- location_id, &new_location_count);
+ int status = gpt_fwu_configure(&device_uuids[i], location_id, &new_location_count);
if (status)
return status;
diff --git a/components/service/fwu/config/fwu_configure.h b/components/service/fwu/config/fwu_configure.h
index 8aa98fe..7137c01 100644
--- a/components/service/fwu/config/fwu_configure.h
+++ b/components/service/fwu/config/fwu_configure.h
@@ -8,7 +8,7 @@
#ifndef FWU_CONFIGURE_H
#define FWU_CONFIGURE_H
-#include <common/uuid/uuid.h>
+#include "common/uuid/uuid.h"
#ifdef __cplusplus
extern "C" {
diff --git a/components/service/fwu/config/gpt/gpt_fwu_configure.c b/components/service/fwu/config/gpt/gpt_fwu_configure.c
index 6f065ef..e5cfed3 100644
--- a/components/service/fwu/config/gpt/gpt_fwu_configure.c
+++ b/components/service/fwu/config/gpt/gpt_fwu_configure.c
@@ -5,32 +5,30 @@
*
*/
-#include <errno.h>
-#include <trace.h>
-#include <stdint.h>
-#include <media/disk/guid.h>
-#include <media/disk/gpt_iterator/gpt_iterator.h>
-#include <media/volume/factory/volume_factory.h>
-#include <media/volume/index/volume_index.h>
-#include <service/fwu/fw_store/banked/volume_id.h>
-#include <service/fwu/installer/factory/installer_factory.h>
-#include <service/fwu/installer/installer_index.h>
-#include <service/fwu/installer/installer.h>
#include "gpt_fwu_configure.h"
-static struct installer *create_and_register_installers(
- const struct uuid_octets *partition_type_uuid,
- unsigned int location_id);
+#include <errno.h>
+#include <stdint.h>
-static int create_and_register_metadata_volume(
- const struct uuid_octets *device_uuid,
- gpt_entry_t *entry,
- unsigned *metadata_count);
+#include "media/disk/gpt_iterator/gpt_iterator.h"
+#include "media/disk/guid.h"
+#include "media/volume/factory/volume_factory.h"
+#include "media/volume/index/volume_index.h"
+#include "service/fwu/fw_store/banked/volume_id.h"
+#include "service/fwu/installer/factory/installer_factory.h"
+#include "service/fwu/installer/installer.h"
+#include "service/fwu/installer/installer_index.h"
+#include "trace.h"
+static struct installer *
+create_and_register_installers(const struct uuid_octets *partition_type_uuid,
+ unsigned int location_id);
-int gpt_fwu_configure(const struct uuid_octets *device_uuid,
- unsigned int initial_location_id,
- unsigned int *location_count)
+static int create_and_register_metadata_volume(const struct uuid_octets *device_uuid,
+ gpt_entry_t *entry, unsigned int *metadata_count);
+
+int gpt_fwu_configure(const struct uuid_octets *device_uuid, unsigned int initial_location_id,
+ unsigned int *location_count)
{
struct uuid_octets gpt_guid;
unsigned int next_location_id = initial_location_id;
@@ -39,7 +37,7 @@
*location_count = 0;
uuid_guid_octets_from_canonical(&gpt_guid, DISK_GUID_UNIQUE_PARTITION_DISK_HEADER);
- struct volume *gpt_volume = volume_factory_create_volume( &gpt_guid, device_uuid);
+ struct volume *gpt_volume = volume_factory_create_volume(&gpt_guid, device_uuid);
if (!gpt_volume) {
/* The case where there is no GPT volume is not necessarily an error.
@@ -67,7 +65,6 @@
gpt_iterator_first(&gpt_iter);
while (!gpt_iterator_is_done(&gpt_iter)) {
-
gpt_entry_t entry;
status = gpt_iterator_current(&gpt_iter, &entry);
@@ -82,7 +79,6 @@
/* Skip unused entry */
if (uuid_is_nil(partition_type_guid->octets)) {
-
gpt_iterator_next(&gpt_iter);
continue;
}
@@ -97,22 +93,19 @@
installer_index_find_by_location_uuid(partition_type_guid);
if (!installer) {
-
/* No installer for the partition type has yet been registered. This
* is either because this is the first partition of this type to be
* encountered or because the partition is not updatable. Find out by
* attempting to construct one or more installers.
*/
- installer =
- create_and_register_installers(partition_type_guid, next_location_id);
+ installer = create_and_register_installers(partition_type_guid,
+ next_location_id);
if (installer)
++next_location_id;
-
}
if (installer) {
-
/* This configurator relies on the partition name to identify the bank
* index that the partition corresponds to. This convention also needs
* to be used by the bootloader to ensure that there is a consistent
@@ -126,7 +119,6 @@
else if (entry.name[0] == '1')
bank_index = 1;
else {
-
EMSG("Invalid bank index in partition name");
goto abnormal_exit;
}
@@ -138,30 +130,26 @@
(const struct uuid_octets *)&entry.unique_uuid, device_uuid);
if (!volume) {
-
EMSG("Failed to create volume");
goto abnormal_exit;
}
- status = volume_index_add(
- banked_volume_id(installer->location_id,
- banked_usage_id(bank_index)), volume);
+ status = volume_index_add(banked_volume_id(installer->location_id,
+ banked_usage_id(bank_index)),
+ volume);
if (status) {
-
volume_factory_destroy_volume(volume);
EMSG("Failed to register volume");
goto abnormal_exit;
}
} else {
-
/* Not an updatable partition but it might be for FWU metadata */
- status = create_and_register_metadata_volume(device_uuid,
- &entry, &metadata_partition_count);
+ status = create_and_register_metadata_volume(device_uuid, &entry,
+ &metadata_partition_count);
if (status) {
-
EMSG("Failed to create metadata volume");
goto abnormal_exit;
}
@@ -180,9 +168,9 @@
return status;
}
-static struct installer *create_and_register_installers(
- const struct uuid_octets *partition_type_uuid,
- unsigned int location_id)
+static struct installer *
+create_and_register_installers(const struct uuid_octets *partition_type_uuid,
+ unsigned int location_id)
{
/* Attempt to create a complete set of installers for updating images
* contained within a partition of the specified type. The installer_factory
@@ -193,29 +181,26 @@
struct installer *last_constructed = NULL;
struct installer *installer = NULL;
- installer = installer_factory_create_installer(
- INSTALL_TYPE_WHOLE_VOLUME, location_id, partition_type_uuid);
+ installer = installer_factory_create_installer(INSTALL_TYPE_WHOLE_VOLUME, location_id,
+ partition_type_uuid);
if (installer) {
-
installer_index_register(installer);
last_constructed = installer;
}
- installer = installer_factory_create_installer(
- INSTALL_TYPE_SUB_VOLUME, location_id, partition_type_uuid);
+ installer = installer_factory_create_installer(INSTALL_TYPE_SUB_VOLUME, location_id,
+ partition_type_uuid);
if (installer) {
-
installer_index_register(installer);
last_constructed = installer;
}
- installer = installer_factory_create_installer(
- INSTALL_TYPE_WHOLE_VOLUME_COPY, location_id, partition_type_uuid);
+ installer = installer_factory_create_installer(INSTALL_TYPE_WHOLE_VOLUME_COPY, location_id,
+ partition_type_uuid);
if (installer) {
-
installer_index_register(installer);
last_constructed = installer;
}
@@ -223,10 +208,8 @@
return last_constructed;
}
-static int create_and_register_metadata_volume(
- const struct uuid_octets *device_uuid,
- gpt_entry_t *entry,
- unsigned *metadata_count)
+static int create_and_register_metadata_volume(const struct uuid_octets *device_uuid,
+ gpt_entry_t *entry, unsigned int *metadata_count)
{
struct uuid_octets guid;
@@ -252,7 +235,6 @@
return -EIO;
if (volume_index_add(volume_id, volume)) {
-
volume_factory_destroy_volume(volume);
return -EIO;
}
diff --git a/components/service/fwu/config/gpt/gpt_fwu_configure.h b/components/service/fwu/config/gpt/gpt_fwu_configure.h
index a9d591b..d6856da 100644
--- a/components/service/fwu/config/gpt/gpt_fwu_configure.h
+++ b/components/service/fwu/config/gpt/gpt_fwu_configure.h
@@ -8,7 +8,7 @@
#ifndef GPT_FWU_CONFIGURE_H
#define GPT_FWU_CONFIGURE_H
-#include <common/uuid/uuid.h>
+#include "common/uuid/uuid.h"
#ifdef __cplusplus
extern "C" {
@@ -32,9 +32,8 @@
*
* \return Status code (0 for success)
*/
-int gpt_fwu_configure(const struct uuid_octets *device_uuid,
- unsigned int initial_location_id,
- unsigned int *location_count);
+int gpt_fwu_configure(const struct uuid_octets *device_uuid, unsigned int initial_location_id,
+ unsigned int *location_count);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/fw_store/banked/bank_scheme.h b/components/service/fwu/fw_store/banked/bank_scheme.h
index 83a9f0d..5696f39 100644
--- a/components/service/fwu/fw_store/banked/bank_scheme.h
+++ b/components/service/fwu/fw_store/banked/bank_scheme.h
@@ -17,7 +17,7 @@
/**
* Definitions for an A/B banked scheme.
*/
-#define BANK_SCHEME_NUM_BANKS (2)
+#define BANK_SCHEME_NUM_BANKS (2)
/**
* \brief Returns the index of the next bank to use
diff --git a/components/service/fwu/fw_store/banked/bank_tracker.c b/components/service/fwu/fw_store/banked/bank_tracker.c
index 239be37..5f80d01 100644
--- a/components/service/fwu/fw_store/banked/bank_tracker.c
+++ b/components/service/fwu/fw_store/banked/bank_tracker.c
@@ -5,41 +5,33 @@
*
*/
+#include "bank_tracker.h"
+
#include <assert.h>
#include <stddef.h>
#include <string.h>
-#include "bank_tracker.h"
-
-void bank_tracker_init(
- struct bank_tracker *subject)
+void bank_tracker_init(struct bank_tracker *subject)
{
memset(subject, 0, sizeof(struct bank_tracker));
}
-void bank_tracker_deinit(
- struct bank_tracker *subject)
+void bank_tracker_deinit(struct bank_tracker *subject)
{
(void)subject;
}
-void bank_tracker_accept(
- struct bank_tracker *subject,
- unsigned int bank_index,
- unsigned int image_index)
+void bank_tracker_accept(struct bank_tracker *subject, unsigned int bank_index,
+ unsigned int image_index)
{
assert(bank_index < BANK_SCHEME_NUM_BANKS);
assert(image_index < FWU_MAX_FW_DIRECTORY_ENTRIES);
subject->bank_state[bank_index].is_accepted[image_index] = true;
-
}
-void bank_tracker_copy_accept(
- struct bank_tracker *subject,
- unsigned int from_bank_index,
- unsigned int to_bank_index,
- unsigned int image_index)
+void bank_tracker_copy_accept(struct bank_tracker *subject, unsigned int from_bank_index,
+ unsigned int to_bank_index, unsigned int image_index)
{
assert(from_bank_index < BANK_SCHEME_NUM_BANKS);
assert(to_bank_index < BANK_SCHEME_NUM_BANKS);
@@ -49,9 +41,7 @@
subject->bank_state[from_bank_index].is_accepted[image_index];
}
-void bank_tracker_set_no_content(
- struct bank_tracker *subject,
- unsigned int bank_index)
+void bank_tracker_set_no_content(struct bank_tracker *subject, unsigned int bank_index)
{
assert(bank_index < BANK_SCHEME_NUM_BANKS);
@@ -61,18 +51,14 @@
subject->bank_state[bank_index].is_accepted[i] = false;
}
-void bank_tracker_set_holds_content(
- struct bank_tracker *subject,
- unsigned int bank_index)
+void bank_tracker_set_holds_content(struct bank_tracker *subject, unsigned int bank_index)
{
assert(bank_index < BANK_SCHEME_NUM_BANKS);
subject->bank_state[bank_index].is_content = true;
}
-void bank_tracker_set_holds_accepted_content(
- struct bank_tracker *subject,
- unsigned int bank_index)
+void bank_tracker_set_holds_accepted_content(struct bank_tracker *subject, unsigned int bank_index)
{
assert(bank_index < BANK_SCHEME_NUM_BANKS);
@@ -82,19 +68,15 @@
subject->bank_state[bank_index].is_accepted[i] = true;
}
-bool bank_tracker_is_content(
- const struct bank_tracker *subject,
- unsigned int bank_index)
+bool bank_tracker_is_content(const struct bank_tracker *subject, unsigned int bank_index)
{
assert(bank_index < BANK_SCHEME_NUM_BANKS);
return subject->bank_state[bank_index].is_content;
}
-bool bank_tracker_is_accepted(
- const struct bank_tracker *subject,
- unsigned int bank_index,
- unsigned int image_index)
+bool bank_tracker_is_accepted(const struct bank_tracker *subject, unsigned int bank_index,
+ unsigned int image_index)
{
assert(bank_index < BANK_SCHEME_NUM_BANKS);
assert(image_index < FWU_MAX_FW_DIRECTORY_ENTRIES);
@@ -102,16 +84,13 @@
return subject->bank_state[bank_index].is_accepted[image_index];
}
-bool bank_tracker_is_all_accepted(
- const struct bank_tracker *subject,
- unsigned int bank_index,
- unsigned int num_images)
+bool bank_tracker_is_all_accepted(const struct bank_tracker *subject, unsigned int bank_index,
+ unsigned int num_images)
{
assert(bank_index < BANK_SCHEME_NUM_BANKS);
assert(num_images <= FWU_MAX_FW_DIRECTORY_ENTRIES);
for (unsigned int image_index = 0; image_index < num_images; image_index++) {
-
if (!subject->bank_state[bank_index].is_accepted[image_index])
return false;
}
diff --git a/components/service/fwu/fw_store/banked/bank_tracker.h b/components/service/fwu/fw_store/banked/bank_tracker.h
index cf3279d..b2f9b46 100644
--- a/components/service/fwu/fw_store/banked/bank_tracker.h
+++ b/components/service/fwu/fw_store/banked/bank_tracker.h
@@ -9,8 +9,9 @@
#define BANK_TRACKER_H
#include <stdbool.h>
-#include <service/fwu/agent/fw_directory.h>
+
#include "bank_scheme.h"
+#include "service/fwu/agent/fw_directory.h"
#ifdef __cplusplus
extern "C" {
@@ -22,9 +23,7 @@
* Tracks the state of fw_store banks.
*/
struct bank_tracker {
-
struct {
-
/* True if bank holds content */
bool is_content;
@@ -32,7 +31,6 @@
bool is_accepted[FWU_MAX_FW_DIRECTORY_ENTRIES];
} bank_state[BANK_SCHEME_NUM_BANKS];
-
};
/**
@@ -40,16 +38,14 @@
*
* \param[in] subject This instance
*/
-void bank_tracker_init(
- struct bank_tracker *subject);
+void bank_tracker_init(struct bank_tracker *subject);
/**
* \brief De-initialize the bank_tracker
*
* \param[in] subject This instance
*/
-void bank_tracker_deinit(
- struct bank_tracker *subject);
+void bank_tracker_deinit(struct bank_tracker *subject);
/**
* \brief Mark image as accepted
@@ -58,10 +54,8 @@
* \param[in] bank_index The firmware bank
* \param[in] image_index The image index (from fw_directory)
*/
-void bank_tracker_accept(
- struct bank_tracker *subject,
- unsigned int bank_index,
- unsigned int image_index);
+void bank_tracker_accept(struct bank_tracker *subject, unsigned int bank_index,
+ unsigned int image_index);
/**
* \brief Copy image accept state
@@ -71,11 +65,8 @@
* \param[in] to_bank_index Copy accepted state to bank index
* \param[in] image_index The image index (from fw_directory)
*/
-void bank_tracker_copy_accept(
- struct bank_tracker *subject,
- unsigned int from_bank_index,
- unsigned int to_bank_index,
- unsigned int image_index);
+void bank_tracker_copy_accept(struct bank_tracker *subject, unsigned int from_bank_index,
+ unsigned int to_bank_index, unsigned int image_index);
/**
* \brief Sets bank as holding no content
@@ -83,9 +74,7 @@
* \param[in] subject This instance
* \param[in] bank_index The firmware bank
*/
-void bank_tracker_set_no_content(
- struct bank_tracker *subject,
- unsigned int bank_index);
+void bank_tracker_set_no_content(struct bank_tracker *subject, unsigned int bank_index);
/**
* \brief Set bank as holding content
@@ -93,9 +82,7 @@
* \param[in] subject This instance
* \param[in] bank_index The firmware bank
*/
-void bank_tracker_set_holds_content(
- struct bank_tracker *subject,
- unsigned int bank_index);
+void bank_tracker_set_holds_content(struct bank_tracker *subject, unsigned int bank_index);
/**
* \brief Set bank as holding fully accepted content
@@ -103,9 +90,7 @@
* \param[in] subject This instance
* \param[in] bank_index The firmware bank
*/
-void bank_tracker_set_holds_accepted_content(
- struct bank_tracker *subject,
- unsigned int bank_index);
+void bank_tracker_set_holds_accepted_content(struct bank_tracker *subject, unsigned int bank_index);
/**
* \brief Check if bank holds contents
@@ -115,9 +100,7 @@
*
* \return True if bank holds content
*/
-bool bank_tracker_is_content(
- const struct bank_tracker *subject,
- unsigned int bank_index);
+bool bank_tracker_is_content(const struct bank_tracker *subject, unsigned int bank_index);
/**
* \brief Check if image is accepted
@@ -128,10 +111,8 @@
*
* \return True if an image has been accepted
*/
-bool bank_tracker_is_accepted(
- const struct bank_tracker *subject,
- unsigned int bank_index,
- unsigned int image_index);
+bool bank_tracker_is_accepted(const struct bank_tracker *subject, unsigned int bank_index,
+ unsigned int image_index);
/**
* \brief Check if all images are accepted
@@ -142,10 +123,8 @@
*
* \return True if all images have been accepted
*/
-bool bank_tracker_is_all_accepted(
- const struct bank_tracker *subject,
- unsigned int bank_index,
- unsigned int num_images);
+bool bank_tracker_is_all_accepted(const struct bank_tracker *subject, unsigned int bank_index,
+ unsigned int num_images);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/fw_store/banked/banked_fw_store.c b/components/service/fwu/fw_store/banked/banked_fw_store.c
index dec576a..b987b48 100644
--- a/components/service/fwu/fw_store/banked/banked_fw_store.c
+++ b/components/service/fwu/fw_store/banked/banked_fw_store.c
@@ -5,22 +5,22 @@
*
*/
+#include "banked_fw_store.h"
+
#include <assert.h>
#include <stddef.h>
#include <string.h>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include <service/fwu/installer/installer.h>
-#include <service/fwu/installer/installer_index.h>
-#include "banked_fw_store.h"
+
#include "bank_scheme.h"
+#include "common/uuid/uuid.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/installer/installer.h"
+#include "service/fwu/installer/installer_index.h"
#include "volume_id.h"
-static int activate_installer(
- struct fw_store *fw_store,
- struct installer *installer,
- uint32_t location_id)
+static int activate_installer(struct fw_store *fw_store, struct installer *installer,
+ uint32_t location_id)
{
int status = FWU_STATUS_UNKNOWN;
@@ -30,16 +30,15 @@
* state. Active installers are held in a linked list during
* the installation phase of an update transaction.
*/
- unsigned int update_volume_id = banked_volume_id(
- location_id, banked_usage_id(fw_store->update_index));
+ unsigned int update_volume_id =
+ banked_volume_id(location_id, banked_usage_id(fw_store->update_index));
- unsigned int current_volume_id = banked_volume_id(
- location_id, banked_usage_id(fw_store->boot_index));
+ unsigned int current_volume_id =
+ banked_volume_id(location_id, banked_usage_id(fw_store->boot_index));
status = installer_begin(installer, current_volume_id, update_volume_id);
if (status == FWU_STATUS_SUCCESS) {
-
/* Add to list of active installers */
installer->next = fw_store->active_installers;
fw_store->active_installers = installer;
@@ -48,25 +47,20 @@
return status;
}
-static void copy_accepted_state_for_location(
- struct fw_store *fw_store,
- uint32_t location_id)
+static void copy_accepted_state_for_location(struct fw_store *fw_store, uint32_t location_id)
{
size_t index = 0;
while (1) {
-
- const struct image_info *image_info = fw_directory_get_image_info(
- fw_store->fw_directory, index);
+ const struct image_info *image_info =
+ fw_directory_get_image_info(fw_store->fw_directory, index);
if (image_info) {
-
if (image_info->location_id == location_id)
- bank_tracker_copy_accept(
- &fw_store->bank_tracker,
- fw_store->boot_index,
- fw_store->update_index,
- image_info->image_index);
+ bank_tracker_copy_accept(&fw_store->bank_tracker,
+ fw_store->boot_index,
+ fw_store->update_index,
+ image_info->image_index);
} else
break;
@@ -74,8 +68,7 @@
}
}
-static int install_unchanged_images(
- struct fw_store *fw_store)
+static int install_unchanged_images(struct fw_store *fw_store)
{
int status = FWU_STATUS_SUCCESS;
size_t num_locations = 0;
@@ -86,16 +79,13 @@
* currently active bank.
*/
for (size_t i = 0; !status && i < num_locations; i++) {
-
bool is_installer_found = false;
uint32_t location_id = location_ids[i];
struct installer *installer = fw_store->active_installers;
while (installer) {
-
if ((installer->location_id == location_id) &&
- !installer_status(installer)) {
-
+ !installer_status(installer)) {
/* There was an installer for this location and the installation
* went without errors.
*/
@@ -107,18 +97,16 @@
}
if (!is_installer_found) {
-
/* There is no installer for the location so assume the active bank
* should be copied. This relies on the platform integrator providing
* a suitable installer to do the copying. It's a legitimate platform
* configuration to not provide one and only allow updates that consist
* of images for all locations.
*/
- struct installer *copy_installer = installer_index_find(
- INSTALL_TYPE_WHOLE_VOLUME_COPY, location_id);
+ struct installer *copy_installer =
+ installer_index_find(INSTALL_TYPE_WHOLE_VOLUME_COPY, location_id);
if (copy_installer) {
-
/* A copy installer doesn't accept any external data. Instead, it
* copies from the current volume to the update volume during the
* finalize operation.
@@ -129,11 +117,10 @@
unsigned int current_volume_id = banked_volume_id(
location_id, banked_usage_id(fw_store->boot_index));
- status = installer_begin(copy_installer,
- current_volume_id, update_volume_id);
+ status = installer_begin(copy_installer, current_volume_id,
+ update_volume_id);
if (status == FWU_STATUS_SUCCESS) {
-
status = installer_finalize(copy_installer);
/* If a whole volume image was successfully copied from
@@ -143,11 +130,11 @@
* that have already been accepted during a previous update.
*/
if (status == FWU_STATUS_SUCCESS)
- copy_accepted_state_for_location(fw_store, location_id);
+ copy_accepted_state_for_location(fw_store,
+ location_id);
}
} else {
-
/* Platform configuration doesn't include a suitable copy installer
* so treat this update attempt as not viable.
*/
@@ -159,9 +146,7 @@
return status;
}
-int banked_fw_store_init(
- struct fw_store *fw_store,
- const struct metadata_serializer *serializer)
+int banked_fw_store_init(struct fw_store *fw_store, const struct metadata_serializer *serializer)
{
fw_store->fw_directory = NULL;
fw_store->active_installers = NULL;
@@ -174,17 +159,14 @@
return metadata_manager_init(&fw_store->metadata_manager, serializer);
}
-void banked_fw_store_deinit(
- struct fw_store *fw_store)
+void banked_fw_store_deinit(struct fw_store *fw_store)
{
bank_tracker_deinit(&fw_store->bank_tracker);
metadata_manager_deinit(&fw_store->metadata_manager);
}
-int fw_store_synchronize(
- struct fw_store *fw_store,
- struct fw_directory *fw_dir,
- unsigned int boot_index)
+int fw_store_synchronize(struct fw_store *fw_store, struct fw_directory *fw_dir,
+ unsigned int boot_index)
{
int status = FWU_STATUS_UNKNOWN;
@@ -198,7 +180,7 @@
fw_store->update_index = bank_scheme_next_index(boot_index);
/* Start building a view of the boot_info that will be advertised by the fw_directory */
- struct boot_info boot_info = {0};
+ struct boot_info boot_info = { 0 };
boot_info.boot_index = boot_index;
@@ -206,11 +188,9 @@
* due to power failures. The following steps will repair a corrupted
* metadata copy or generate fresh metadata if necessary.
*/
- status = metadata_manager_check_and_repair(
- &fw_store->metadata_manager, fw_dir);
+ status = metadata_manager_check_and_repair(&fw_store->metadata_manager, fw_dir);
if (status != FWU_STATUS_SUCCESS) {
-
/* No viable metadata exists so a fresh version needs to be created. We
* can only assume that the boot_index is good. Also assume that it is
* fully accepted as there is no knowledge that a rollback to a previous
@@ -219,31 +199,25 @@
boot_info.active_index = boot_index;
boot_info.previous_active_index = boot_index;
- bank_tracker_set_holds_accepted_content(
- &fw_store->bank_tracker,
- fw_store->boot_index);
+ bank_tracker_set_holds_accepted_content(&fw_store->bank_tracker,
+ fw_store->boot_index);
- status = metadata_manager_update(
- &fw_store->metadata_manager,
- boot_info.active_index,
- boot_info.previous_active_index,
- fw_dir,
- &fw_store->bank_tracker);
+ status = metadata_manager_update(&fw_store->metadata_manager,
+ boot_info.active_index,
+ boot_info.previous_active_index, fw_dir,
+ &fw_store->bank_tracker);
} else {
-
/* Metadata was successfully loaded from storage so synchronize local
* state to the NV state reflected by the metadata.
*/
- status = metadata_manager_get_active_indices(
- &fw_store->metadata_manager,
- &boot_info.active_index,
- &boot_info.previous_active_index);
+ status = metadata_manager_get_active_indices(&fw_store->metadata_manager,
+ &boot_info.active_index,
+ &boot_info.previous_active_index);
/* Synchronize image approval state with NV information contained in the metadata */
- metadata_manager_preload_bank_tracker(
- &fw_store->metadata_manager,
- &fw_store->bank_tracker);
+ metadata_manager_preload_bank_tracker(&fw_store->metadata_manager,
+ &fw_store->bank_tracker);
/* Check for the case where the bootloader has not booted from the active bank.
* This will occur when boot loader conditions for a successful boot are not
@@ -251,18 +225,14 @@
* repeated failed boots, the metadata is updated in-line with the
* bootloader's decision.
*/
- if ((status == FWU_STATUS_SUCCESS) &&
- (boot_index != boot_info.active_index)) {
-
+ if ((status == FWU_STATUS_SUCCESS) && (boot_index != boot_info.active_index)) {
boot_info.active_index = boot_index;
boot_info.previous_active_index = boot_index;
- status = metadata_manager_update(
- &fw_store->metadata_manager,
- boot_info.active_index,
- boot_info.previous_active_index,
- fw_dir,
- &fw_store->bank_tracker);
+ status = metadata_manager_update(&fw_store->metadata_manager,
+ boot_info.active_index,
+ boot_info.previous_active_index, fw_dir,
+ &fw_store->bank_tracker);
}
}
@@ -272,8 +242,7 @@
return status;
}
-int fw_store_begin_install(
- struct fw_store *fw_store)
+int fw_store_begin_install(struct fw_store *fw_store)
{
assert(!fw_store->active_installers);
@@ -282,9 +251,7 @@
* images may be committed as accepted after installation or accepted
* during the trial state.
*/
- bank_tracker_set_no_content(
- &fw_store->bank_tracker,
- fw_store->update_index);
+ bank_tracker_set_no_content(&fw_store->bank_tracker, fw_store->update_index);
/* Protect the update bank from use while the installation is in
* progress by setting the active and previous active indices to be equal.
@@ -292,24 +259,19 @@
* possibility of the boot loader attempting to boot from a bank in a partially
* installed state.
*/
- int status = metadata_manager_update(
- &fw_store->metadata_manager,
- fw_store->boot_index,
- fw_store->boot_index,
- fw_store->fw_directory,
- &fw_store->bank_tracker);
+ int status = metadata_manager_update(&fw_store->metadata_manager, fw_store->boot_index,
+ fw_store->boot_index, fw_store->fw_directory,
+ &fw_store->bank_tracker);
return status;
}
-void fw_store_cancel_install(
- struct fw_store *fw_store)
+void fw_store_cancel_install(struct fw_store *fw_store)
{
/* Abort all active installers - each installer will do its best to
* clean-up to a state where a follow-in installation is possible.
*/
while (fw_store->active_installers) {
-
struct installer *installer = fw_store->active_installers;
fw_store->active_installers = installer->next;
@@ -318,8 +280,7 @@
}
}
-int fw_store_finalize_install(
- struct fw_store *fw_store)
+int fw_store_finalize_install(struct fw_store *fw_store)
{
int status = FWU_STATUS_NOT_AVAILABLE;
@@ -335,7 +296,6 @@
* only contains images for some locations.
*/
if (!is_error) {
-
status = install_unchanged_images(fw_store);
is_error = (status != FWU_STATUS_SUCCESS);
}
@@ -347,13 +307,11 @@
* from the currently active storage volume.
*/
while (fw_store->active_installers) {
-
struct installer *installer = fw_store->active_installers;
fw_store->active_installers = installer->next;
if (!is_error) {
-
status = installer_finalize(installer);
is_error = (status != FWU_STATUS_SUCCESS);
@@ -362,33 +320,24 @@
}
if (is_error) {
-
- return (status != FWU_STATUS_SUCCESS) ?
- status : FWU_STATUS_NOT_AVAILABLE;
+ return (status != FWU_STATUS_SUCCESS) ? status : FWU_STATUS_NOT_AVAILABLE;
}
/* All installers finalized successfully so mark update bank as holding
* content and signal to boot loader that the update is ready for a trial
* by promoting the update bank to being the active bank.
*/
- bank_tracker_set_holds_content(
- &fw_store->bank_tracker,
- fw_store->update_index);
+ bank_tracker_set_holds_content(&fw_store->bank_tracker, fw_store->update_index);
- status = metadata_manager_update(
- &fw_store->metadata_manager,
- fw_store->update_index,
- fw_store->boot_index,
- fw_store->fw_directory,
- &fw_store->bank_tracker);
+ status = metadata_manager_update(&fw_store->metadata_manager, fw_store->update_index,
+ fw_store->boot_index, fw_store->fw_directory,
+ &fw_store->bank_tracker);
return status;
}
-int fw_store_select_installer(
- struct fw_store *fw_store,
- const struct image_info *image_info,
- struct installer **installer)
+int fw_store_select_installer(struct fw_store *fw_store, const struct image_info *image_info,
+ struct installer **installer)
{
int status = FWU_STATUS_UNKNOWN;
@@ -398,16 +347,14 @@
installer_index_find(image_info->install_type, image_info->location_id);
if (selected_installer) {
-
/* An installer is available to handle the incoming image. An installer
* will potentially handle multiple images as part of an update transaction.
* If this is the first, the installer needs to be activated.
*/
if (installer_is_active(selected_installer) ||
- (status = activate_installer(fw_store,
- selected_installer, image_info->location_id),
- status == FWU_STATUS_SUCCESS)) {
-
+ (status = activate_installer(fw_store, selected_installer,
+ image_info->location_id),
+ status == FWU_STATUS_SUCCESS)) {
status = installer_open(selected_installer, image_info);
if (status == FWU_STATUS_SUCCESS)
@@ -418,11 +365,8 @@
return status;
}
-int fw_store_write_image(
- struct fw_store *fw_store,
- struct installer *installer,
- const uint8_t *data,
- size_t data_len)
+int fw_store_write_image(struct fw_store *fw_store, struct installer *installer,
+ const uint8_t *data, size_t data_len)
{
if (!installer_is_active(installer))
/* Attempting to write to an inactive installer */
@@ -433,11 +377,8 @@
return status;
}
-int fw_store_commit_image(
- struct fw_store *fw_store,
- struct installer *installer,
- const struct image_info *image_info,
- bool accepted)
+int fw_store_commit_image(struct fw_store *fw_store, struct installer *installer,
+ const struct image_info *image_info, bool accepted)
{
if (!installer_is_active(installer))
/* Attempting to commit an inactive installer */
@@ -446,65 +387,44 @@
int status = installer_commit(installer);
if ((status == FWU_STATUS_SUCCESS) && accepted)
- bank_tracker_accept(
- &fw_store->bank_tracker,
- fw_store->update_index,
- image_info->image_index);
+ bank_tracker_accept(&fw_store->bank_tracker, fw_store->update_index,
+ image_info->image_index);
return status;
}
-bool fw_store_notify_accepted(
- struct fw_store *fw_store,
- const struct image_info *image_info)
+bool fw_store_notify_accepted(struct fw_store *fw_store, const struct image_info *image_info)
{
unsigned int num_images = fw_directory_num_images(fw_store->fw_directory);
- bank_tracker_accept(
- &fw_store->bank_tracker,
- fw_store->boot_index,
- image_info->image_index);
+ bank_tracker_accept(&fw_store->bank_tracker, fw_store->boot_index, image_info->image_index);
- int status = metadata_manager_update(
- &fw_store->metadata_manager,
- fw_store->boot_index,
- fw_store->update_index,
- fw_store->fw_directory,
- &fw_store->bank_tracker);
+ int status = metadata_manager_update(&fw_store->metadata_manager, fw_store->boot_index,
+ fw_store->update_index, fw_store->fw_directory,
+ &fw_store->bank_tracker);
return (status == FWU_STATUS_SUCCESS) &&
- bank_tracker_is_all_accepted(
- &fw_store->bank_tracker,
- fw_store->boot_index,
- num_images);
+ bank_tracker_is_all_accepted(&fw_store->bank_tracker, fw_store->boot_index,
+ num_images);
}
-bool fw_store_is_accepted(
- const struct fw_store *fw_store,
- const struct image_info *image_info)
+bool fw_store_is_accepted(const struct fw_store *fw_store, const struct image_info *image_info)
{
- return bank_tracker_is_accepted(
- &fw_store->bank_tracker,
- fw_store->boot_index,
- image_info->image_index);
+ return bank_tracker_is_accepted(&fw_store->bank_tracker, fw_store->boot_index,
+ image_info->image_index);
}
-bool fw_store_is_trial(
- const struct fw_store *fw_store)
+bool fw_store_is_trial(const struct fw_store *fw_store)
{
const struct boot_info *boot_info = fw_directory_get_boot_info(fw_store->fw_directory);
unsigned int num_images = fw_directory_num_images(fw_store->fw_directory);
- return
- (boot_info->boot_index == boot_info->active_index) &&
- !bank_tracker_is_all_accepted(
- &fw_store->bank_tracker,
- fw_store->boot_index,
- num_images);
+ return (boot_info->boot_index == boot_info->active_index) &&
+ !bank_tracker_is_all_accepted(&fw_store->bank_tracker, fw_store->boot_index,
+ num_images);
}
-int fw_store_commit_to_update(
- struct fw_store *fw_store)
+int fw_store_commit_to_update(struct fw_store *fw_store)
{
(void)fw_store;
@@ -516,29 +436,24 @@
return FWU_STATUS_SUCCESS;
}
-int fw_store_revert_to_previous(
- struct fw_store *fw_store)
+int fw_store_revert_to_previous(struct fw_store *fw_store)
{
uint32_t active_index;
uint32_t previous_active_index;
- int status = metadata_manager_get_active_indices(
- &fw_store->metadata_manager,
- &active_index,
- &previous_active_index);
+ int status = metadata_manager_get_active_indices(&fw_store->metadata_manager, &active_index,
+ &previous_active_index);
if (status)
return status;
if (active_index == fw_store->boot_index) {
-
/* Update has been activated via a reboot */
active_index = previous_active_index;
previous_active_index = fw_store->boot_index;
fw_store->update_index = bank_scheme_next_index(active_index);
} else {
-
/* Update has not yet been activated */
previous_active_index = active_index;
active_index = fw_store->boot_index;
@@ -546,27 +461,18 @@
}
/* Ensure all images for the new active bank are marked as accepted */
- bank_tracker_set_holds_accepted_content(
- &fw_store->bank_tracker,
- active_index);
+ bank_tracker_set_holds_accepted_content(&fw_store->bank_tracker, active_index);
/* Update the FWU metadata to the pre-update state */
- status = metadata_manager_update(
- &fw_store->metadata_manager,
- active_index,
- previous_active_index,
- fw_store->fw_directory,
- &fw_store->bank_tracker);
+ status = metadata_manager_update(&fw_store->metadata_manager, active_index,
+ previous_active_index, fw_store->fw_directory,
+ &fw_store->bank_tracker);
return status;
}
-bool fw_store_export(
- struct fw_store *fw_store,
- const struct uuid_octets *uuid,
- const uint8_t **data,
- size_t *data_len,
- int *status)
+bool fw_store_export(struct fw_store *fw_store, const struct uuid_octets *uuid,
+ const uint8_t **data, size_t *data_len, int *status)
{
struct uuid_octets target_uuid;
@@ -574,13 +480,10 @@
uuid_guid_octets_from_canonical(&target_uuid, FWU_METADATA_CANONICAL_UUID);
if (uuid_is_equal(uuid->octets, target_uuid.octets)) {
-
bool is_dirty;
- *status = metadata_manager_fetch(
- &fw_store->metadata_manager,
- data, data_len,
- &is_dirty);
+ *status = metadata_manager_fetch(&fw_store->metadata_manager, data, data_len,
+ &is_dirty);
/* is_dirty value is not yet returned when exporting the FWU Metadata but this
* may be added to allow for deployments where metadata is written by the client
@@ -592,4 +495,3 @@
return false;
}
-
diff --git a/components/service/fwu/fw_store/banked/banked_fw_store.h b/components/service/fwu/fw_store/banked/banked_fw_store.h
index 43849ec..5e35e77 100644
--- a/components/service/fwu/fw_store/banked/banked_fw_store.h
+++ b/components/service/fwu/fw_store/banked/banked_fw_store.h
@@ -9,9 +9,10 @@
#define BANKED_FW_STORE_H
#include <stdint.h>
-#include <service/fwu/fw_store/fw_store.h>
-#include "metadata_manager.h"
+
#include "bank_tracker.h"
+#include "metadata_manager.h"
+#include "service/fwu/fw_store/fw_store.h"
#ifdef __cplusplus
extern "C" {
@@ -51,18 +52,14 @@
*
* \return FWU status code
*/
-int banked_fw_store_init(
- struct fw_store *fw_store,
- const struct metadata_serializer *serializer);
+int banked_fw_store_init(struct fw_store *fw_store, const struct metadata_serializer *serializer);
/**
* \brief De-initialize a banked_fw_store
*
* \param[in] fw_store The subject fw_store
*/
-void banked_fw_store_deinit(
- struct fw_store *fw_store);
-
+void banked_fw_store_deinit(struct fw_store *fw_store);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/fw_store/banked/metadata_manager.c b/components/service/fwu/fw_store/banked/metadata_manager.c
index f2d49f8..954dcc9 100644
--- a/components/service/fwu/fw_store/banked/metadata_manager.c
+++ b/components/service/fwu/fw_store/banked/metadata_manager.c
@@ -5,44 +5,40 @@
*
*/
+#include "metadata_manager.h"
+
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
-#include <trace.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include <media/volume/index/volume_index.h>
-#include <media/volume/volume.h>
-#include <common/crc32/crc32.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h>
-#include "metadata_manager.h"
+
+#include "common/crc32/crc32.h"
+#include "media/volume/index/volume_index.h"
+#include "media/volume/volume.h"
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h"
+#include "trace.h"
#include "volume_id.h"
-static int load_and_check_metadata(
- struct volume *volume,
- uint8_t *buf,
- size_t expected_len)
+static int load_and_check_metadata(struct volume *volume, uint8_t *buf, size_t expected_len)
{
int status = FWU_STATUS_UNKNOWN;
status = volume_open(volume);
if (status == 0) {
-
size_t len = 0;
status = volume_read(volume, (uintptr_t)buf, expected_len, &len);
if (status == 0) {
-
- uint32_t calc_crc = crc32(0U,
- buf + sizeof(uint32_t),
- expected_len - sizeof(uint32_t));
+ uint32_t calc_crc =
+ crc32(0U, buf + sizeof(uint32_t), expected_len - sizeof(uint32_t));
uint32_t expected_crc = *((uint32_t *)buf);
- status = (calc_crc == expected_crc) ?
- FWU_STATUS_SUCCESS : FWU_STATUS_UNKNOWN;
+ status = (calc_crc == expected_crc) ? FWU_STATUS_SUCCESS :
+ FWU_STATUS_UNKNOWN;
}
volume_close(volume);
@@ -51,24 +47,18 @@
return status;
}
-static int store_metadata(
- struct volume *volume,
- const uint8_t *data,
- size_t data_len)
+static int store_metadata(struct volume *volume, const uint8_t *data, size_t data_len)
{
int status = volume_open(volume);
if (status == 0) {
-
status = volume_erase(volume);
if (status == 0) {
-
size_t written_len = 0;
- status = volume_write(
- volume, (const uintptr_t)data,
- data_len, &written_len);
+ status =
+ volume_write(volume, (const uintptr_t)data, data_len, &written_len);
}
volume_close(volume);
@@ -77,9 +67,8 @@
return status;
}
-int metadata_manager_init(
- struct metadata_manager *subject,
- const struct metadata_serializer *serializer)
+int metadata_manager_init(struct metadata_manager *subject,
+ const struct metadata_serializer *serializer)
{
assert(subject);
assert(serializer);
@@ -94,10 +83,8 @@
subject->primary_metadata_volume = NULL;
subject->backup_metadata_volume = NULL;
- volume_index_find(BANKED_VOLUME_ID_PRIMARY_METADATA,
- &subject->primary_metadata_volume);
- volume_index_find(BANKED_VOLUME_ID_BACKUP_METADATA,
- &subject->backup_metadata_volume);
+ volume_index_find(BANKED_VOLUME_ID_PRIMARY_METADATA, &subject->primary_metadata_volume);
+ volume_index_find(BANKED_VOLUME_ID_BACKUP_METADATA, &subject->backup_metadata_volume);
/* A cached copy of the metadata is held in memory. It will not initially
* hold a valid copy until one has been loaded from storage or a fresh
@@ -110,19 +97,16 @@
subject->metadata_max_len = subject->serializer->max_size();
subject->metadata_cache = malloc(subject->metadata_max_len);
- return (subject->metadata_cache) ?
- FWU_STATUS_SUCCESS : FWU_STATUS_UNKNOWN;
+ return (subject->metadata_cache) ? FWU_STATUS_SUCCESS : FWU_STATUS_UNKNOWN;
}
-void metadata_manager_deinit(
- struct metadata_manager *subject)
+void metadata_manager_deinit(struct metadata_manager *subject)
{
free(subject->metadata_cache);
}
-int metadata_manager_check_and_repair(
- struct metadata_manager *subject,
- const struct fw_directory *fw_dir)
+int metadata_manager_check_and_repair(struct metadata_manager *subject,
+ const struct fw_directory *fw_dir)
{
int primary_status = FWU_STATUS_UNKNOWN;
int backup_status = FWU_STATUS_UNKNOWN;
@@ -135,7 +119,6 @@
* the operation can never succeed.
*/
if (!subject->primary_metadata_volume && !subject->backup_metadata_volume) {
-
IMSG("FWU volume not accessible");
return FWU_STATUS_UNKNOWN;
}
@@ -146,18 +129,15 @@
subject->metadata_len = subject->serializer->size(fw_dir);
if (subject->primary_metadata_volume) {
-
primary_status = load_and_check_metadata(subject->primary_metadata_volume,
- subject->metadata_cache,
- subject->metadata_len);
+ subject->metadata_cache,
+ subject->metadata_len);
subject->is_valid = (primary_status == FWU_STATUS_SUCCESS);
}
if (subject->backup_metadata_volume) {
-
if (subject->is_valid) {
-
/* Already successfully loaded the primary copy. Just need to check
* the backup and repair it if necessary. During an update operation,
* the primary metadata is always written first. A hazard exists where
@@ -168,16 +148,13 @@
uint8_t *backup_buf = malloc(subject->metadata_len);
if (backup_buf) {
-
- backup_status = load_and_check_metadata(
- subject->backup_metadata_volume,
- backup_buf,
- subject->metadata_len);
+ backup_status =
+ load_and_check_metadata(subject->backup_metadata_volume,
+ backup_buf, subject->metadata_len);
if ((backup_status == FWU_STATUS_SUCCESS) &&
- (*(uint32_t *)backup_buf !=
- *(uint32_t *)subject->metadata_cache)) {
-
+ (*(uint32_t *)backup_buf !=
+ *(uint32_t *)subject->metadata_cache)) {
/* Both copies have valid CRC but CRSs are different. Force
* the backup to be repaired.
*/
@@ -187,11 +164,10 @@
free(backup_buf);
}
} else {
-
/* Primary must have failed so use the backup copy. */
backup_status = load_and_check_metadata(subject->backup_metadata_volume,
- subject->metadata_cache,
- subject->metadata_len);
+ subject->metadata_cache,
+ subject->metadata_len);
subject->is_valid = (backup_status == FWU_STATUS_SUCCESS);
}
@@ -199,25 +175,20 @@
/* Attempt a repair if necessary (and possible) */
if (subject->is_valid) {
-
if ((primary_status != FWU_STATUS_SUCCESS) && subject->primary_metadata_volume) {
-
IMSG("Repairing primary FWU metadata");
- primary_status = store_metadata(
- subject->primary_metadata_volume,
- subject->metadata_cache,
- subject->metadata_len);
+ primary_status = store_metadata(subject->primary_metadata_volume,
+ subject->metadata_cache,
+ subject->metadata_len);
}
if ((backup_status != FWU_STATUS_SUCCESS) && subject->backup_metadata_volume) {
-
IMSG("Repairing backup FWU metadata");
- backup_status = store_metadata(
- subject->backup_metadata_volume,
- subject->metadata_cache,
- subject->metadata_len);
+ backup_status = store_metadata(subject->backup_metadata_volume,
+ subject->metadata_cache,
+ subject->metadata_len);
}
}
@@ -228,12 +199,9 @@
return (subject->is_valid) ? FWU_STATUS_SUCCESS : FWU_STATUS_UNKNOWN;
}
-int metadata_manager_update(
- struct metadata_manager *subject,
- uint32_t active_index,
- uint32_t previous_active_index,
- const struct fw_directory *fw_dir,
- const struct bank_tracker *bank_tracker)
+int metadata_manager_update(struct metadata_manager *subject, uint32_t active_index,
+ uint32_t previous_active_index, const struct fw_directory *fw_dir,
+ const struct bank_tracker *bank_tracker)
{
int primary_status = FWU_STATUS_SUCCESS;
int backup_status = FWU_STATUS_SUCCESS;
@@ -241,17 +209,13 @@
subject->metadata_len = subject->serializer->size(fw_dir);
/* Serialize metadata into metadata cache */
- subject->serializer->serialize(
- active_index, previous_active_index,
- fw_dir, bank_tracker,
- subject->metadata_cache,
- subject->metadata_max_len,
- &subject->metadata_len);
+ subject->serializer->serialize(active_index, previous_active_index, fw_dir, bank_tracker,
+ subject->metadata_cache, subject->metadata_max_len,
+ &subject->metadata_len);
/* Update cache copy with valid crc */
- uint32_t calc_crc = crc32(0U,
- subject->metadata_cache + sizeof(uint32_t),
- subject->metadata_len - sizeof(uint32_t));
+ uint32_t calc_crc = crc32(0U, subject->metadata_cache + sizeof(uint32_t),
+ subject->metadata_len - sizeof(uint32_t));
*(uint32_t *)subject->metadata_cache = calc_crc;
bool was_valid = subject->is_valid;
@@ -270,41 +234,30 @@
* defend against a power failure after updating the primary but before the backup.
*/
if (subject->primary_metadata_volume) {
-
- primary_status = store_metadata(
- subject->primary_metadata_volume,
- subject->metadata_cache,
- subject->metadata_len);
+ primary_status = store_metadata(subject->primary_metadata_volume,
+ subject->metadata_cache, subject->metadata_len);
}
if (subject->backup_metadata_volume) {
-
- backup_status = store_metadata(
- subject->backup_metadata_volume,
- subject->metadata_cache,
- subject->metadata_len);
+ backup_status = store_metadata(subject->backup_metadata_volume,
+ subject->metadata_cache, subject->metadata_len);
}
/* Updated the view of the stored data if successfully stored */
if ((primary_status == FWU_STATUS_SUCCESS) && (backup_status == FWU_STATUS_SUCCESS))
subject->stored_crc = *(uint32_t *)subject->metadata_cache;
- return
- (primary_status != FWU_STATUS_SUCCESS) ? primary_status :
- (backup_status != FWU_STATUS_SUCCESS) ? backup_status :
- FWU_STATUS_SUCCESS;
+ return (primary_status != FWU_STATUS_SUCCESS) ? primary_status :
+ (backup_status != FWU_STATUS_SUCCESS) ? backup_status :
+ FWU_STATUS_SUCCESS;
}
-int metadata_manager_fetch(
- struct metadata_manager *subject,
- const uint8_t **data,
- size_t *data_len,
- bool *is_dirty)
+int metadata_manager_fetch(struct metadata_manager *subject, const uint8_t **data, size_t *data_len,
+ bool *is_dirty)
{
int status = FWU_STATUS_UNKNOWN;
if (subject->is_valid) {
-
*data = subject->metadata_cache;
*data_len = subject->metadata_len;
*is_dirty = subject->is_dirty;
@@ -317,18 +270,15 @@
return status;
}
-int metadata_manager_get_active_indices(
- const struct metadata_manager *subject,
- uint32_t *active_index,
- uint32_t *previous_active_index)
+int metadata_manager_get_active_indices(const struct metadata_manager *subject,
+ uint32_t *active_index, uint32_t *previous_active_index)
{
int status = FWU_STATUS_UNKNOWN;
if (subject->is_valid) {
-
- subject->serializer->deserialize_active_indices(
- active_index, previous_active_index,
- subject->metadata_cache, subject->metadata_len);
+ subject->serializer->deserialize_active_indices(active_index, previous_active_index,
+ subject->metadata_cache,
+ subject->metadata_len);
status = FWU_STATUS_SUCCESS;
}
@@ -336,17 +286,14 @@
return status;
}
-void metadata_manager_cache_invalidate(
- struct metadata_manager *subject)
+void metadata_manager_cache_invalidate(struct metadata_manager *subject)
{
subject->is_valid = false;
}
-void metadata_manager_preload_bank_tracker(
- const struct metadata_manager *subject,
- struct bank_tracker *bank_tracker)
+void metadata_manager_preload_bank_tracker(const struct metadata_manager *subject,
+ struct bank_tracker *bank_tracker)
{
- subject->serializer->deserialize_bank_info(
- bank_tracker,
- subject->metadata_cache, subject->metadata_len);
+ subject->serializer->deserialize_bank_info(bank_tracker, subject->metadata_cache,
+ subject->metadata_len);
}
diff --git a/components/service/fwu/fw_store/banked/metadata_manager.h b/components/service/fwu/fw_store/banked/metadata_manager.h
index 67ad602..6841057 100644
--- a/components/service/fwu/fw_store/banked/metadata_manager.h
+++ b/components/service/fwu/fw_store/banked/metadata_manager.h
@@ -8,8 +8,8 @@
#ifndef METADATA_MANAGER_H
#define METADATA_MANAGER_H
-#include <stddef.h>
#include <stdbool.h>
+#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
@@ -30,7 +30,6 @@
* Manages the FWU metadata seen by the boot loader.
*/
struct metadata_manager {
-
/* Volume objects for IO operations to NV storage */
struct volume *primary_metadata_volume;
struct volume *backup_metadata_volume;
@@ -55,17 +54,15 @@
*
* \return Status 0 on success
*/
-int metadata_manager_init(
- struct metadata_manager *subject,
- const struct metadata_serializer *serializer);
+int metadata_manager_init(struct metadata_manager *subject,
+ const struct metadata_serializer *serializer);
/**
* \brief De-initialize the metadata_manager
*
* \param[in] subject This instance
*/
-void metadata_manager_deinit(
- struct metadata_manager *subject);
+void metadata_manager_deinit(struct metadata_manager *subject);
/**
* \brief Check integrity of FWU metadata and repair if necessary
@@ -81,9 +78,8 @@
*
* \return Status 0 if intact or if repair was successful
*/
-int metadata_manager_check_and_repair(
- struct metadata_manager *subject,
- const struct fw_directory *fw_dir);
+int metadata_manager_check_and_repair(struct metadata_manager *subject,
+ const struct fw_directory *fw_dir);
/**
* \brief Update the FWU metadata seen by the boot loader
@@ -96,12 +92,9 @@
*
* \return Status 0 if successful
*/
-int metadata_manager_update(
- struct metadata_manager *subject,
- uint32_t active_index,
- uint32_t previous_active_index,
- const struct fw_directory *fw_dir,
- const struct bank_tracker *bank_tracker);
+int metadata_manager_update(struct metadata_manager *subject, uint32_t active_index,
+ uint32_t previous_active_index, const struct fw_directory *fw_dir,
+ const struct bank_tracker *bank_tracker);
/**
* \brief Get the active index values from the metadata
@@ -112,10 +105,8 @@
*
* \return Status 0 if successful
*/
-int metadata_manager_get_active_indices(
- const struct metadata_manager *subject,
- uint32_t *active_index,
- uint32_t *previous_active_index);
+int metadata_manager_get_active_indices(const struct metadata_manager *subject,
+ uint32_t *active_index, uint32_t *previous_active_index);
/**
* \brief Fetch the FWU metadata that should be seen by the boot loader
@@ -132,19 +123,15 @@
*
* \return Status 0 if successful
*/
-int metadata_manager_fetch(
- struct metadata_manager *subject,
- const uint8_t **data,
- size_t *data_len,
- bool *is_dirty);
+int metadata_manager_fetch(struct metadata_manager *subject, const uint8_t **data, size_t *data_len,
+ bool *is_dirty);
/**
* \brief Invalidate the metadata cache
*
* \param[in] subject This instance
*/
-void metadata_manager_cache_invalidate(
- struct metadata_manager *subject);
+void metadata_manager_cache_invalidate(struct metadata_manager *subject);
/**
* \brief Preload the bank_tracker with NV state from metadata
@@ -154,9 +141,8 @@
*
* \return Status 0 if successful
*/
-void metadata_manager_preload_bank_tracker(
- const struct metadata_manager *subject,
- struct bank_tracker *bank_tracker);
+void metadata_manager_preload_bank_tracker(const struct metadata_manager *subject,
+ struct bank_tracker *bank_tracker);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h b/components/service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h
index 2e411e5..3d28181 100644
--- a/components/service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h
+++ b/components/service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h
@@ -36,7 +36,6 @@
* support for runtime selection of the metadata serializer is possible.
*/
struct metadata_serializer {
-
/**
* \brief Serialize FWU metadata
*
@@ -52,14 +51,9 @@
*
* \return Status
*/
- int (*serialize)(
- uint32_t active_index,
- uint32_t previous_active_index,
- const struct fw_directory *fw_dir,
- const struct bank_tracker *bank_tracker,
- uint8_t *buf,
- size_t buf_size,
- size_t *metadata_len);
+ int (*serialize)(uint32_t active_index, uint32_t previous_active_index,
+ const struct fw_directory *fw_dir, const struct bank_tracker *bank_tracker,
+ uint8_t *buf, size_t buf_size, size_t *metadata_len);
/**
* \brief Return serialized FWU metadata size
@@ -68,8 +62,7 @@
*
* \return Size in bytes
*/
- size_t (*size)(
- const struct fw_directory *fw_dir);
+ size_t (*size)(const struct fw_directory *fw_dir);
/**
* \brief Return the maximum serialized FWU metadata size
@@ -85,10 +78,8 @@
* \param[in] serialized_metadata Serialized metadata
* \param[in] metadata_len Length of serialized metadata
*/
- void (*deserialize_bank_info)(
- struct bank_tracker *bank_tracker,
- const uint8_t *serialized_metadata,
- size_t metadata_len);
+ void (*deserialize_bank_info)(struct bank_tracker *bank_tracker,
+ const uint8_t *serialized_metadata, size_t metadata_len);
/**
* \brief De-serialize active indices
@@ -98,11 +89,8 @@
* \param[in] serialized_metadata Serialized metadata
* \param[in] metadata_len Length of serialized metadata
*/
- void (*deserialize_active_indices)(
- uint32_t *active_index,
- uint32_t *previous_active_index,
- const uint8_t *serialized_metadata,
- size_t metadata_len);
+ void (*deserialize_active_indices)(uint32_t *active_index, uint32_t *previous_active_index,
+ const uint8_t *serialized_metadata, size_t metadata_len);
};
#ifdef __cplusplus
diff --git a/components/service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.c b/components/service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.c
index 39e0fea..5458b4c 100644
--- a/components/service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.c
+++ b/components/service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.c
@@ -5,25 +5,24 @@
*
*/
+#include "metadata_serializer_v1.h"
+
#include <assert.h>
#include <stddef.h>
#include <string.h>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/metadata_v1.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include <media/volume/volume.h>
-#include <media/volume/index/volume_index.h>
-#include <service/fwu/agent/fw_directory.h>
-#include <service/fwu/fw_store/banked/bank_tracker.h>
-#include <service/fwu/fw_store/banked/volume_id.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h>
-#include "metadata_serializer_v1.h"
+#include "common/uuid/uuid.h"
+#include "media/volume/index/volume_index.h"
+#include "media/volume/volume.h"
+#include "protocols/service/fwu/packed-c/metadata_v1.h"
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/agent/fw_directory.h"
+#include "service/fwu/fw_store/banked/bank_tracker.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h"
+#include "service/fwu/fw_store/banked/volume_id.h"
-static int serialize_image_entries(
- struct fwu_metadata *metadata,
- const struct fw_directory *fw_dir,
- const struct bank_tracker *bank_tracker)
+static int serialize_image_entries(struct fwu_metadata *metadata, const struct fw_directory *fw_dir,
+ const struct bank_tracker *bank_tracker)
{
size_t image_index = 0;
@@ -42,21 +41,18 @@
* are assumed to have the same parent location, identified by the location
* uuid.
*/
- struct uuid_octets location_uuid = {0};
+ struct uuid_octets location_uuid = { 0 };
struct fwu_image_entry *entry = &metadata->img_entry[image_index];
/* Serialize bank storage info */
- for (size_t bank_index = 0;
- bank_index < BANK_SCHEME_NUM_BANKS; bank_index++) {
-
- struct uuid_octets img_uuid = {0};
+ for (size_t bank_index = 0; bank_index < BANK_SCHEME_NUM_BANKS; bank_index++) {
+ struct uuid_octets img_uuid = { 0 };
struct volume *volume = NULL;
- int status = volume_index_find(
- banked_volume_id(
- image_info->location_id,
- banked_usage_id(bank_index)),
- &volume);
+ int status =
+ volume_index_find(banked_volume_id(image_info->location_id,
+ banked_usage_id(bank_index)),
+ &volume);
if (!status && volume)
volume_get_storage_ids(volume, &img_uuid, &location_uuid);
@@ -65,15 +61,15 @@
memcpy(properties->img_uuid, img_uuid.octets, OSF_UUID_OCTET_LEN);
properties->reserved = 0;
- properties->accepted = bank_tracker_is_accepted(
- bank_tracker, bank_index, image_index) ? 1 : 0;
+ properties->accepted =
+ bank_tracker_is_accepted(bank_tracker, bank_index, image_index) ?
+ 1 :
+ 0;
}
/* Serialize per-image UUIDs */
- memcpy(entry->img_type_uuid,
- image_info->img_type_uuid.octets, OSF_UUID_OCTET_LEN);
- memcpy(entry->location_uuid,
- location_uuid.octets, OSF_UUID_OCTET_LEN);
+ memcpy(entry->img_type_uuid, image_info->img_type_uuid.octets, OSF_UUID_OCTET_LEN);
+ memcpy(entry->location_uuid, location_uuid.octets, OSF_UUID_OCTET_LEN);
++image_index;
@@ -82,29 +78,22 @@
return FWU_STATUS_SUCCESS;
}
-static size_t metadata_serializer_size(
- const struct fw_directory *fw_dir)
+static size_t metadata_serializer_size(const struct fw_directory *fw_dir)
{
- return
- offsetof(struct fwu_metadata, img_entry) +
- fw_directory_num_images(fw_dir) * sizeof(struct fwu_image_entry);
+ return offsetof(struct fwu_metadata, img_entry) +
+ fw_directory_num_images(fw_dir) * sizeof(struct fwu_image_entry);
}
static size_t metadata_serializer_max_size(void)
{
- return
- offsetof(struct fwu_metadata, img_entry) +
- FWU_MAX_FW_DIRECTORY_ENTRIES * sizeof(struct fwu_image_entry);
+ return offsetof(struct fwu_metadata, img_entry) +
+ FWU_MAX_FW_DIRECTORY_ENTRIES * sizeof(struct fwu_image_entry);
}
-static int metadata_serializer_serialize(
- uint32_t active_index,
- uint32_t previous_active_index,
- const struct fw_directory *fw_dir,
- const struct bank_tracker *bank_tracker,
- uint8_t *buf,
- size_t buf_size,
- size_t *metadata_len)
+static int metadata_serializer_serialize(uint32_t active_index, uint32_t previous_active_index,
+ const struct fw_directory *fw_dir,
+ const struct bank_tracker *bank_tracker, uint8_t *buf,
+ size_t buf_size, size_t *metadata_len)
{
int status = FWU_STATUS_UNKNOWN;
size_t serialized_size = metadata_serializer_size(fw_dir);
@@ -112,7 +101,6 @@
*metadata_len = 0;
if (serialized_size <= buf_size) {
-
struct fwu_metadata *metadata = (struct fwu_metadata *)buf;
/* Serialize metadata header */
@@ -131,10 +119,9 @@
return status;
}
-static void metadata_serializer_deserialize_bank_info(
- struct bank_tracker *bank_tracker,
- const uint8_t *serialized_metadata,
- size_t metadata_len)
+static void metadata_serializer_deserialize_bank_info(struct bank_tracker *bank_tracker,
+ const uint8_t *serialized_metadata,
+ size_t metadata_len)
{
const struct fwu_metadata *metadata = (const struct fwu_metadata *)serialized_metadata;
@@ -147,19 +134,15 @@
/* Deserialize image accept state */
if (metadata_len >= offsetof(struct fwu_metadata, img_entry)) {
-
- size_t num_images =
- (metadata_len - offsetof(struct fwu_metadata, img_entry)) /
- sizeof(struct fwu_image_entry);
+ size_t num_images = (metadata_len - offsetof(struct fwu_metadata, img_entry)) /
+ sizeof(struct fwu_image_entry);
for (size_t image_index = 0; image_index < num_images; image_index++) {
-
const struct fwu_image_entry *image_entry =
&metadata->img_entry[image_index];
- for (size_t bank_index = 0;
- bank_index < BANK_SCHEME_NUM_BANKS; bank_index++) {
-
+ for (size_t bank_index = 0; bank_index < BANK_SCHEME_NUM_BANKS;
+ bank_index++) {
if (image_entry->img_props[bank_index].accepted)
bank_tracker_accept(bank_tracker, bank_index, image_index);
}
@@ -167,11 +150,10 @@
}
}
-static void metadata_serializer_deserialize_active_indices(
- uint32_t *active_index,
- uint32_t *previous_active_index,
- const uint8_t *serialized_metadata,
- size_t metadata_len)
+static void metadata_serializer_deserialize_active_indices(uint32_t *active_index,
+ uint32_t *previous_active_index,
+ const uint8_t *serialized_metadata,
+ size_t metadata_len)
{
const struct fwu_metadata *metadata = (const struct fwu_metadata *)serialized_metadata;
@@ -184,10 +166,8 @@
const struct metadata_serializer *metadata_serializer_v1(void)
{
static const struct metadata_serializer serializer = {
- metadata_serializer_serialize,
- metadata_serializer_size,
- metadata_serializer_max_size,
- metadata_serializer_deserialize_bank_info,
+ metadata_serializer_serialize, metadata_serializer_size,
+ metadata_serializer_max_size, metadata_serializer_deserialize_bank_info,
metadata_serializer_deserialize_active_indices
};
diff --git a/components/service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.c b/components/service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.c
index c5a6688..1ef61e4 100644
--- a/components/service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.c
+++ b/components/service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.c
@@ -5,45 +5,39 @@
*
*/
+#include "metadata_serializer_v2.h"
+
#include <assert.h>
#include <stddef.h>
#include <string.h>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/metadata_v2.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include <media/volume/volume.h>
-#include <media/volume/index/volume_index.h>
-#include <service/fwu/agent/fw_directory.h>
-#include <service/fwu/fw_store/banked/bank_tracker.h>
-#include <service/fwu/fw_store/banked/volume_id.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h>
-#include "metadata_serializer_v2.h"
+#include "common/uuid/uuid.h"
+#include "media/volume/index/volume_index.h"
+#include "media/volume/volume.h"
+#include "protocols/service/fwu/packed-c/metadata_v2.h"
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/agent/fw_directory.h"
+#include "service/fwu/fw_store/banked/bank_tracker.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h"
+#include "service/fwu/fw_store/banked/volume_id.h"
-static size_t metadata_serializer_size(
- const struct fw_directory *fw_dir)
+static size_t metadata_serializer_size(const struct fw_directory *fw_dir)
{
- return
- sizeof(struct fwu_metadata) +
- offsetof(struct fwu_fw_store_desc, img_entry) +
- sizeof(struct fwu_image_entry) * fw_directory_num_images(fw_dir);
+ return sizeof(struct fwu_metadata) + offsetof(struct fwu_fw_store_desc, img_entry) +
+ sizeof(struct fwu_image_entry) * fw_directory_num_images(fw_dir);
}
static size_t metadata_serializer_max_size(void)
{
- return
- sizeof(struct fwu_metadata) +
- offsetof(struct fwu_fw_store_desc, img_entry) +
- sizeof(struct fwu_image_entry) * FWU_MAX_FW_DIRECTORY_ENTRIES;
+ return sizeof(struct fwu_metadata) + offsetof(struct fwu_fw_store_desc, img_entry) +
+ sizeof(struct fwu_image_entry) * FWU_MAX_FW_DIRECTORY_ENTRIES;
}
-static int serialize_image_entries(
- struct fwu_fw_store_desc *fw_store_desc,
- const struct fw_directory *fw_dir,
- const struct bank_tracker *bank_tracker)
+static int serialize_image_entries(struct fwu_fw_store_desc *fw_store_desc,
+ const struct fw_directory *fw_dir,
+ const struct bank_tracker *bank_tracker)
{
for (size_t image_index = 0; image_index < fw_store_desc->num_images; image_index++) {
-
/* Image entry indices in the fw_store_desc correspond to the image index
* of the associate entry in the fw_directory.
*/
@@ -57,21 +51,18 @@
* are assumed to have the same parent location, identified by the location
* uuid.
*/
- struct uuid_octets location_uuid = {0};
+ struct uuid_octets location_uuid = { 0 };
struct fwu_image_entry *entry = &fw_store_desc->img_entry[image_index];
/* Serialize bank storage info */
- for (size_t bank_index = 0;
- bank_index < BANK_SCHEME_NUM_BANKS; bank_index++) {
-
- struct uuid_octets img_uuid = {0};
+ for (size_t bank_index = 0; bank_index < BANK_SCHEME_NUM_BANKS; bank_index++) {
+ struct uuid_octets img_uuid = { 0 };
struct volume *volume = NULL;
- int status = volume_index_find(
- banked_volume_id(
- image_info->location_id,
- banked_usage_id(bank_index)),
- &volume);
+ int status =
+ volume_index_find(banked_volume_id(image_info->location_id,
+ banked_usage_id(bank_index)),
+ &volume);
if (!status && volume) {
/* A concrete volume may not support retrieving storage IDs. If
@@ -81,8 +72,8 @@
* location uuid returned by the volume holding the first bank is
* used as the parent.
*/
- struct uuid_octets *parent_uuid = (bank_index == 0) ?
- &location_uuid : NULL;
+ struct uuid_octets *parent_uuid =
+ (bank_index == 0) ? &location_uuid : NULL;
volume_get_storage_ids(volume, &img_uuid, parent_uuid);
}
@@ -91,24 +82,22 @@
memcpy(bank_info->img_uuid, img_uuid.octets, OSF_UUID_OCTET_LEN);
bank_info->reserved = 0;
- bank_info->accepted = bank_tracker_is_accepted(
- bank_tracker, bank_index, image_index) ? 1 : 0;
+ bank_info->accepted =
+ bank_tracker_is_accepted(bank_tracker, bank_index, image_index) ?
+ 1 :
+ 0;
}
/* Serialize per-image UUIDs */
- memcpy(entry->img_type_uuid,
- image_info->img_type_uuid.octets, OSF_UUID_OCTET_LEN);
- memcpy(entry->location_uuid,
- location_uuid.octets, OSF_UUID_OCTET_LEN);
+ memcpy(entry->img_type_uuid, image_info->img_type_uuid.octets, OSF_UUID_OCTET_LEN);
+ memcpy(entry->location_uuid, location_uuid.octets, OSF_UUID_OCTET_LEN);
}
return FWU_STATUS_SUCCESS;
}
-static int serialize_fw_store_desc(
- const struct fw_directory *fw_dir,
- const struct bank_tracker *bank_tracker,
- uint8_t *buf)
+static int serialize_fw_store_desc(const struct fw_directory *fw_dir,
+ const struct bank_tracker *bank_tracker, uint8_t *buf)
{
struct fwu_fw_store_desc *fw_store_desc = (struct fwu_fw_store_desc *)buf;
@@ -120,14 +109,10 @@
return serialize_image_entries(fw_store_desc, fw_dir, bank_tracker);
}
-static int metadata_serializer_serialize(
- uint32_t active_index,
- uint32_t previous_active_index,
- const struct fw_directory *fw_dir,
- const struct bank_tracker *bank_tracker,
- uint8_t *buf,
- size_t buf_size,
- size_t *metadata_len)
+static int metadata_serializer_serialize(uint32_t active_index, uint32_t previous_active_index,
+ const struct fw_directory *fw_dir,
+ const struct bank_tracker *bank_tracker, uint8_t *buf,
+ size_t buf_size, size_t *metadata_len)
{
int status = FWU_STATUS_UNKNOWN;
size_t serialized_size = metadata_serializer_size(fw_dir);
@@ -135,7 +120,6 @@
*metadata_len = 0;
if (serialized_size <= buf_size) {
-
struct fwu_metadata *metadata = (struct fwu_metadata *)buf;
/* Serialize metadata header */
@@ -146,20 +130,14 @@
metadata->active_index = active_index;
metadata->previous_active_index = previous_active_index;
- for (unsigned int bank_index = 0;
- bank_index < FWU_METADATA_V2_NUM_BANK_STATES; bank_index++) {
-
+ for (unsigned int bank_index = 0; bank_index < FWU_METADATA_V2_NUM_BANK_STATES;
+ bank_index++) {
if (bank_index < BANK_SCHEME_NUM_BANKS) {
-
- if (bank_tracker_is_all_accepted(
- bank_tracker,
- bank_index,
- fw_directory_num_images(fw_dir)))
+ if (bank_tracker_is_all_accepted(bank_tracker, bank_index,
+ fw_directory_num_images(fw_dir)))
metadata->bank_state[bank_index] =
FWU_METADATA_V2_BANK_STATE_ACCEPTED;
- else if (bank_tracker_is_content(
- bank_tracker,
- bank_index))
+ else if (bank_tracker_is_content(bank_tracker, bank_index))
metadata->bank_state[bank_index] =
FWU_METADATA_V2_BANK_STATE_VALID;
else
@@ -173,10 +151,8 @@
/* Serialize optional fw store descriptor if required */
if (serialized_size > metadata->header_size)
- status = serialize_fw_store_desc(
- fw_dir,
- bank_tracker,
- &buf[metadata->header_size]);
+ status = serialize_fw_store_desc(fw_dir, bank_tracker,
+ &buf[metadata->header_size]);
else
status = FWU_STATUS_SUCCESS;
@@ -187,21 +163,18 @@
return status;
}
-static void metadata_serializer_deserialize_bank_info(
- struct bank_tracker *bank_tracker,
- const uint8_t *serialized_metadata,
- size_t metadata_len)
+static void metadata_serializer_deserialize_bank_info(struct bank_tracker *bank_tracker,
+ const uint8_t *serialized_metadata,
+ size_t metadata_len)
{
const struct fwu_metadata *metadata = (const struct fwu_metadata *)serialized_metadata;
/* Sanity check size values in header */
- if ((metadata->header_size > metadata_len) ||
- (metadata->metadata_size > metadata_len))
+ if ((metadata->header_size > metadata_len) || (metadata->metadata_size > metadata_len))
return;
/* Deserialize bank state in header and update bank_tracker to reflect the same state */
for (unsigned int bank_index = 0; bank_index < BANK_SCHEME_NUM_BANKS; bank_index++) {
-
if (metadata->bank_state[bank_index] == FWU_METADATA_V2_BANK_STATE_ACCEPTED)
bank_tracker_set_holds_accepted_content(bank_tracker, bank_index);
else if (metadata->bank_state[bank_index] == FWU_METADATA_V2_BANK_STATE_VALID)
@@ -210,48 +183,43 @@
/* If present, deserialize the fw_store_desc */
if (metadata->metadata_size >=
- metadata->header_size + offsetof(struct fwu_fw_store_desc, img_entry)) {
-
+ metadata->header_size + offsetof(struct fwu_fw_store_desc, img_entry)) {
const struct fwu_fw_store_desc *fw_store_desc =
- (const struct fwu_fw_store_desc *)(serialized_metadata + metadata->header_size);
+ (const struct fwu_fw_store_desc *)(serialized_metadata +
+ metadata->header_size);
- size_t fw_store_desc_size =
- metadata->metadata_size - metadata->header_size;
+ size_t fw_store_desc_size = metadata->metadata_size - metadata->header_size;
size_t total_img_entries_size =
fw_store_desc_size - offsetof(struct fwu_fw_store_desc, img_entry);
size_t per_img_entry_bank_info_size =
fw_store_desc->num_banks * fw_store_desc->bank_entry_size;
/* Sanity check fw_store_desc values */
- if ((fw_store_desc->img_entry_size <
- sizeof(struct fwu_image_entry)) ||
- (fw_store_desc->bank_entry_size <
- sizeof(struct fwu_img_bank_info)) ||
- (fw_store_desc->num_banks >
- BANK_SCHEME_NUM_BANKS) ||
- (fw_store_desc->img_entry_size <
- offsetof(struct fwu_image_entry, img_bank_info) +
- per_img_entry_bank_info_size) ||
- (fw_store_desc->num_images >
- FWU_MAX_FW_DIRECTORY_ENTRIES) ||
- (total_img_entries_size <
- fw_store_desc->num_images * fw_store_desc->img_entry_size))
+ if ((fw_store_desc->img_entry_size < sizeof(struct fwu_image_entry)) ||
+ (fw_store_desc->bank_entry_size < sizeof(struct fwu_img_bank_info)) ||
+ (fw_store_desc->num_banks > BANK_SCHEME_NUM_BANKS) ||
+ (fw_store_desc->img_entry_size <
+ offsetof(struct fwu_image_entry, img_bank_info) +
+ per_img_entry_bank_info_size) ||
+ (fw_store_desc->num_images > FWU_MAX_FW_DIRECTORY_ENTRIES) ||
+ (total_img_entries_size <
+ fw_store_desc->num_images * fw_store_desc->img_entry_size))
return;
/* Deserialize per-image info */
- for (size_t image_index = 0;
- image_index < fw_store_desc->num_images; image_index++) {
+ for (size_t image_index = 0; image_index < fw_store_desc->num_images;
+ image_index++) {
+ const struct fwu_image_entry *image_entry =
+ (const struct fwu_image_entry
+ *)((const uint8_t *)fw_store_desc->img_entry +
+ image_index * fw_store_desc->img_entry_size);
- const struct fwu_image_entry *image_entry = (const struct fwu_image_entry *)
- ((const uint8_t *)fw_store_desc->img_entry +
- image_index * fw_store_desc->img_entry_size);
-
- for (size_t bank_index = 0;
- bank_index < fw_store_desc->num_banks; bank_index++) {
-
- const struct fwu_img_bank_info *bank_info =(const struct fwu_img_bank_info *)
- ((const uint8_t *)image_entry->img_bank_info +
- bank_index * fw_store_desc->bank_entry_size);
+ for (size_t bank_index = 0; bank_index < fw_store_desc->num_banks;
+ bank_index++) {
+ const struct fwu_img_bank_info *bank_info =
+ (const struct fwu_img_bank_info
+ *)((const uint8_t *)image_entry->img_bank_info +
+ bank_index * fw_store_desc->bank_entry_size);
if (bank_info->accepted)
bank_tracker_accept(bank_tracker, bank_index, image_index);
@@ -260,11 +228,10 @@
}
}
-static void metadata_serializer_deserialize_active_indices(
- uint32_t *active_index,
- uint32_t *previous_active_index,
- const uint8_t *serialized_metadata,
- size_t metadata_len)
+static void metadata_serializer_deserialize_active_indices(uint32_t *active_index,
+ uint32_t *previous_active_index,
+ const uint8_t *serialized_metadata,
+ size_t metadata_len)
{
const struct fwu_metadata *metadata = (const struct fwu_metadata *)serialized_metadata;
@@ -277,10 +244,8 @@
const struct metadata_serializer *metadata_serializer_v2(void)
{
static const struct metadata_serializer serializer = {
- metadata_serializer_serialize,
- metadata_serializer_size,
- metadata_serializer_max_size,
- metadata_serializer_deserialize_bank_info,
+ metadata_serializer_serialize, metadata_serializer_size,
+ metadata_serializer_max_size, metadata_serializer_deserialize_bank_info,
metadata_serializer_deserialize_active_indices
};
diff --git a/components/service/fwu/fw_store/banked/test/metadata_manager_tests.cpp b/components/service/fwu/fw_store/banked/test/metadata_manager_tests.cpp
index 0bc4310..5295be3 100644
--- a/components/service/fwu/fw_store/banked/test/metadata_manager_tests.cpp
+++ b/components/service/fwu/fw_store/banked/test/metadata_manager_tests.cpp
@@ -4,21 +4,22 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <stdlib.h>
-#include <common/uuid/uuid.h>
-#include <media/disk/guid.h>
-#include <media/volume/block_volume/block_volume.h>
-#include <media/volume/index/volume_index.h>
-#include <media/volume/volume.h>
-#include <service/block_storage/factory/ref_ram_gpt/block_store_factory.h>
-#include <service/fwu/fw_store/banked/metadata_manager.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.h>
-#include <service/fwu/fw_store/banked/bank_tracker.h>
-#include <service/fwu/fw_store/banked/volume_id.h>
-#include <service/fwu/agent/fw_directory.h>
-#include <service/fwu/inspector/mock/mock_fw_inspector.h>
#include <CppUTest/TestHarness.h>
+#include <stdlib.h>
+
+#include "common/uuid/uuid.h"
+#include "media/disk/guid.h"
+#include "media/volume/block_volume/block_volume.h"
+#include "media/volume/index/volume_index.h"
+#include "media/volume/volume.h"
+#include "service/block_storage/factory/ref_ram_gpt/block_store_factory.h"
+#include "service/fwu/agent/fw_directory.h"
+#include "service/fwu/fw_store/banked/bank_tracker.h"
+#include "service/fwu/fw_store/banked/metadata_manager.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.h"
+#include "service/fwu/fw_store/banked/volume_id.h"
+#include "service/fwu/inspector/mock/mock_fw_inspector.h"
TEST_GROUP(FwuMetadataManagerTests)
{
@@ -36,22 +37,20 @@
/* Construct primary metadata volume */
uuid_guid_octets_from_canonical(&partition_guid,
- DISK_GUID_UNIQUE_PARTITION_PRIMARY_FWU_METADATA);
+ DISK_GUID_UNIQUE_PARTITION_PRIMARY_FWU_METADATA);
- result = block_volume_init(&m_primary_block_volume,
- m_block_store, &partition_guid,
- &m_primary_volume);
+ result = block_volume_init(&m_primary_block_volume, m_block_store, &partition_guid,
+ &m_primary_volume);
LONGS_EQUAL(0, result);
CHECK_TRUE(m_primary_volume);
/* Construct backup metadata volume */
uuid_guid_octets_from_canonical(&partition_guid,
- DISK_GUID_UNIQUE_PARTITION_BACKUP_FWU_METADATA);
+ DISK_GUID_UNIQUE_PARTITION_BACKUP_FWU_METADATA);
- result = block_volume_init(&m_backup_block_volume,
- m_block_store, &partition_guid,
- &m_backup_volume);
+ result = block_volume_init(&m_backup_block_volume, m_block_store, &partition_guid,
+ &m_backup_volume);
LONGS_EQUAL(0, result);
CHECK_TRUE(m_backup_volume);
@@ -75,7 +74,7 @@
ref_ram_gpt_block_store_factory_destroy(m_block_store);
}
- void corrupt_metadata(struct volume *volume)
+ void corrupt_metadata(struct volume * volume)
{
int status;
size_t metadata_size = m_serializer->size(&m_fw_directory);
@@ -85,8 +84,7 @@
status = volume_open(volume);
LONGS_EQUAL(0, status);
- status = volume_read(volume,
- (uintptr_t)metadata_buf, metadata_size, &actual_len);
+ status = volume_read(volume, (uintptr_t)metadata_buf, metadata_size, &actual_len);
LONGS_EQUAL(0, status);
UNSIGNED_LONGS_EQUAL(metadata_size, actual_len);
@@ -100,8 +98,8 @@
status = volume_seek(volume, IO_SEEK_SET, 0);
LONGS_EQUAL(0, status);
- status = volume_write(volume,
- (const uintptr_t)metadata_buf, metadata_size, &actual_len);
+ status = volume_write(volume, (const uintptr_t)metadata_buf, metadata_size,
+ &actual_len);
LONGS_EQUAL(0, status);
UNSIGNED_LONGS_EQUAL(metadata_size, actual_len);
@@ -141,8 +139,8 @@
/* An update to the metadata should result in both primary and backup copies
* being initialized. */
- result = metadata_manager_update(&m_metadata_manager, 0, 1,
- &m_fw_directory, &m_bank_tracker);
+ result = metadata_manager_update(&m_metadata_manager, 0, 1, &m_fw_directory,
+ &m_bank_tracker);
LONGS_EQUAL(0, result);
/* If the update was successful, check_and_repair shouldn't have anything to do. */
@@ -157,10 +155,7 @@
/* Corrupt either copy randomly a few times and expect to always repair */
for (size_t i = 0; i < 100; ++i) {
-
- struct volume *volume = (rand() & 1) ?
- m_primary_volume :
- m_backup_volume;
+ struct volume *volume = (rand() & 1) ? m_primary_volume : m_backup_volume;
corrupt_metadata(volume);
metadata_manager_cache_invalidate(&m_metadata_manager);
diff --git a/components/service/fwu/fw_store/banked/test/metadata_v2_tests.cpp b/components/service/fwu/fw_store/banked/test/metadata_v2_tests.cpp
index f3482a1..7e59c6f 100644
--- a/components/service/fwu/fw_store/banked/test/metadata_v2_tests.cpp
+++ b/components/service/fwu/fw_store/banked/test/metadata_v2_tests.cpp
@@ -4,15 +4,15 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <cstddef>
-#include <protocols/service/fwu/packed-c/metadata_v2.h>
#include <CppUTest/TestHarness.h>
+#include <cstddef>
+
+#include "protocols/service/fwu/packed-c/metadata_v2.h"
/* Tests check FWU metadata protocol definitions are aligned to the FWU-A
* specification.
*/
-TEST_GROUP(FwuMetadataV2Tests)
-{
+TEST_GROUP(FwuMetadataV2Tests){
};
@@ -23,12 +23,14 @@
UNSIGNED_LONGS_EQUAL(0x04, offsetof(fwu_metadata, version));
UNSIGNED_LONGS_EQUAL(0x08, offsetof(fwu_metadata, metadata_size));
UNSIGNED_LONGS_EQUAL(0x0c, offsetof(fwu_metadata, header_size));
- UNSIGNED_LONGS_EQUAL(0x0e, offsetof(fwu_metadata, active_index)); /* Note spec incorrectly says 0x0d - fed back */
+ /* Note: spec incorrectly says 0x0d - fed back */
+ UNSIGNED_LONGS_EQUAL(0x0e, offsetof(fwu_metadata, active_index));
UNSIGNED_LONGS_EQUAL(0x0f, offsetof(fwu_metadata, previous_active_index));
UNSIGNED_LONGS_EQUAL(0x10, offsetof(fwu_metadata, bank_state));
/* Check header size aligns with expected offset of optional fw_store_desc */
- UNSIGNED_LONGS_EQUAL(0x14, sizeof(struct fwu_metadata)); /* Note spec incorrectly says 0x11 - fed back */
+ /* Note: spec incorrectly says 0x11 - fed back */
+ UNSIGNED_LONGS_EQUAL(0x14, sizeof(struct fwu_metadata));
}
TEST(FwuMetadataV2Tests, checkFwStoreDescStructure)
diff --git a/components/service/fwu/fw_store/banked/volume_id.h b/components/service/fwu/fw_store/banked/volume_id.h
index d29bccf..5776edc 100644
--- a/components/service/fwu/fw_store/banked/volume_id.h
+++ b/components/service/fwu/fw_store/banked/volume_id.h
@@ -28,12 +28,12 @@
*/
/* FWU metadata volume IDs. A single location is assumed. */
-#define BANKED_VOLUME_ID_PRIMARY_METADATA (0xffff0000)
-#define BANKED_VOLUME_ID_BACKUP_METADATA (0xffff0001)
+#define BANKED_VOLUME_ID_PRIMARY_METADATA (0xffff0000)
+#define BANKED_VOLUME_ID_BACKUP_METADATA (0xffff0001)
/* Per-location usage IDs for the banked_fw store */
-#define BANKED_USAGE_ID_FW_BANK_A (0)
-#define BANKED_USAGE_ID_FW_BANK_B (1)
+#define BANKED_USAGE_ID_FW_BANK_A (0)
+#define BANKED_USAGE_ID_FW_BANK_B (1)
/**
* \brief Return a volume id constructed from a usage and location id
@@ -50,9 +50,7 @@
*
* \return volume id
*/
-static inline unsigned int banked_volume_id(
- unsigned int location_id,
- unsigned int usage_id)
+static inline unsigned int banked_volume_id(unsigned int location_id, unsigned int usage_id)
{
return (location_id << 16) | (usage_id & 0xffff);
}
@@ -66,8 +64,7 @@
*/
static inline unsigned int banked_usage_id(unsigned int bank_index)
{
- return (bank_index == 0) ?
- BANKED_USAGE_ID_FW_BANK_A : BANKED_USAGE_ID_FW_BANK_B;
+ return (bank_index == 0) ? BANKED_USAGE_ID_FW_BANK_A : BANKED_USAGE_ID_FW_BANK_B;
}
#ifdef __cplusplus
diff --git a/components/service/fwu/fw_store/fw_store.h b/components/service/fwu/fw_store/fw_store.h
index b4eeade..1fde41a 100644
--- a/components/service/fwu/fw_store/fw_store.h
+++ b/components/service/fwu/fw_store/fw_store.h
@@ -39,10 +39,8 @@
*
* \return FWU status code
*/
-int fw_store_synchronize(
- struct fw_store *fw_store,
- struct fw_directory *fw_dir,
- unsigned int boot_index);
+int fw_store_synchronize(struct fw_store *fw_store, struct fw_directory *fw_dir,
+ unsigned int boot_index);
/**
* \brief Begin to install one or more images
@@ -54,16 +52,14 @@
*
* \return FWU status code
*/
-int fw_store_begin_install(
- struct fw_store *fw_store);
+int fw_store_begin_install(struct fw_store *fw_store);
/**
* \brief Cancel any install operation in progress
*
* \param[in] fw_store The subject fw_store
*/
-void fw_store_cancel_install(
- struct fw_store *fw_store);
+void fw_store_cancel_install(struct fw_store *fw_store);
/**
* \brief Finalize the installation of a set of images
@@ -75,8 +71,7 @@
*
* \return FWU status code
*/
-int fw_store_finalize_install(
- struct fw_store *fw_store);
+int fw_store_finalize_install(struct fw_store *fw_store);
/**
* \brief Select an installer
@@ -90,10 +85,8 @@
*
* \return FWU status code
*/
-int fw_store_select_installer(
- struct fw_store *fw_store,
- const struct image_info *image_info,
- struct installer **installer);
+int fw_store_select_installer(struct fw_store *fw_store, const struct image_info *image_info,
+ struct installer **installer);
/**
* \brief Write image data during image installation
@@ -105,11 +98,8 @@
*
* \return FWU status code
*/
-int fw_store_write_image(
- struct fw_store *fw_store,
- struct installer *installer,
- const uint8_t *data,
- size_t data_len);
+int fw_store_write_image(struct fw_store *fw_store, struct installer *installer,
+ const uint8_t *data, size_t data_len);
/**
* \brief Commit image data
@@ -123,11 +113,8 @@
*
* \return FWU status code
*/
-int fw_store_commit_image(
- struct fw_store *fw_store,
- struct installer *installer,
- const struct image_info *image_info,
- bool accepted);
+int fw_store_commit_image(struct fw_store *fw_store, struct installer *installer,
+ const struct image_info *image_info, bool accepted);
/**
* \brief Notify that an updated image has been accepted
@@ -137,9 +124,7 @@
*
* \return True if all necessary images have been accepted
*/
-bool fw_store_notify_accepted(
- struct fw_store *fw_store,
- const struct image_info *image_info);
+bool fw_store_notify_accepted(struct fw_store *fw_store, const struct image_info *image_info);
/**
* \brief Check if image is accepted
@@ -149,9 +134,7 @@
*
* \return True if image has been accepted
*/
-bool fw_store_is_accepted(
- const struct fw_store *fw_store,
- const struct image_info *image_info);
+bool fw_store_is_accepted(const struct fw_store *fw_store, const struct image_info *image_info);
/**
* \brief Check if the booted firmware is being trialed
@@ -160,8 +143,7 @@
*
* \return True if trialed
*/
-bool fw_store_is_trial(
- const struct fw_store *fw_store);
+bool fw_store_is_trial(const struct fw_store *fw_store);
/**
* \brief Commit to the complete update
@@ -170,8 +152,7 @@
*
* \return FWU status code
*/
-int fw_store_commit_to_update(
- struct fw_store *fw_store);
+int fw_store_commit_to_update(struct fw_store *fw_store);
/**
* \brief Revert back to the previous good version (if possible)
@@ -180,8 +161,7 @@
*
* \return FWU status code
*/
-int fw_store_revert_to_previous(
- struct fw_store *fw_store);
+int fw_store_revert_to_previous(struct fw_store *fw_store);
/**
* \brief Export fw_store specific objects
@@ -198,12 +178,8 @@
*
* \return True if UUID identifies an object held by the fw_store
*/
-bool fw_store_export(
- struct fw_store *fw_store,
- const struct uuid_octets *uuid,
- const uint8_t **data,
- size_t *data_len,
- int *status);
+bool fw_store_export(struct fw_store *fw_store, const struct uuid_octets *uuid,
+ const uint8_t **data, size_t *data_len, int *status);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/inspector/direct/direct_fw_inspector.c b/components/service/fwu/inspector/direct/direct_fw_inspector.c
index 61ce670..503cf45 100644
--- a/components/service/fwu/inspector/direct/direct_fw_inspector.c
+++ b/components/service/fwu/inspector/direct/direct_fw_inspector.c
@@ -5,18 +5,17 @@
*
*/
-#include <trace.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include <media/volume/index/volume_index.h>
-#include <service/fwu/installer/installer.h>
-#include <service/fwu/installer/installer_index.h>
-#include <service/fwu/agent/fw_directory.h>
-#include <service/fwu/fw_store/banked/volume_id.h>
#include "direct_fw_inspector.h"
-int direct_fw_inspector_inspect(
- struct fw_directory *fw_dir,
- unsigned int boot_index)
+#include "media/volume/index/volume_index.h"
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/agent/fw_directory.h"
+#include "service/fwu/fw_store/banked/volume_id.h"
+#include "service/fwu/installer/installer.h"
+#include "service/fwu/installer/installer_index.h"
+#include "trace.h"
+
+int direct_fw_inspector_inspect(struct fw_directory *fw_dir, unsigned int boot_index)
{
int status = FWU_STATUS_SUCCESS;
@@ -35,7 +34,6 @@
unsigned int index = 0;
do {
-
struct installer *installer = installer_index_get(index);
if (!installer)
@@ -45,9 +43,8 @@
* was booted from, determined the correct volume_id based on the
* most recent boot_index.
*/
- unsigned int volume_id = banked_volume_id(
- installer->location_id,
- banked_usage_id(boot_index));
+ unsigned int volume_id =
+ banked_volume_id(installer->location_id, banked_usage_id(boot_index));
/* Delegate volume inspection to the installer that will have
* the necessary package format knowledge to extract information
@@ -57,7 +54,6 @@
status = installer_enumerate(installer, volume_id, fw_dir);
if (status != FWU_STATUS_SUCCESS) {
-
EMSG("Failed to enumerate contents of volume %d", volume_id);
break;
}
diff --git a/components/service/fwu/inspector/direct/direct_fw_inspector.h b/components/service/fwu/inspector/direct/direct_fw_inspector.h
index e34d29f..0fa515f 100644
--- a/components/service/fwu/inspector/direct/direct_fw_inspector.h
+++ b/components/service/fwu/inspector/direct/direct_fw_inspector.h
@@ -8,13 +8,12 @@
#ifndef DIRECT_FW_INSPECTOR_H
#define DIRECT_FW_INSPECTOR_H
-#include <service/fwu/inspector/fw_inspector.h>
+#include "service/fwu/inspector/fw_inspector.h"
#ifdef __cplusplus
extern "C" {
#endif
-
/**
* \brief direct_fw_inspector inspect method
*
@@ -29,9 +28,7 @@
*
* \return FWU status
*/
-int direct_fw_inspector_inspect(
- struct fw_directory *fw_dir,
- unsigned int boot_index);
+int direct_fw_inspector_inspect(struct fw_directory *fw_dir, unsigned int boot_index);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/inspector/fw_inspector.h b/components/service/fwu/inspector/fw_inspector.h
index 037a20f..8048130 100644
--- a/components/service/fwu/inspector/fw_inspector.h
+++ b/components/service/fwu/inspector/fw_inspector.h
@@ -35,9 +35,7 @@
*
* \return FWU status
*/
-typedef int (*fw_inspector_inspect)(
- struct fw_directory *fw_dir,
- unsigned int boot_index);
+typedef int (*fw_inspector_inspect)(struct fw_directory *fw_dir, unsigned int boot_index);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/inspector/mock/mock_fw_inspector.c b/components/service/fwu/inspector/mock/mock_fw_inspector.c
index da8945d..0ec12db 100644
--- a/components/service/fwu/inspector/mock/mock_fw_inspector.c
+++ b/components/service/fwu/inspector/mock/mock_fw_inspector.c
@@ -5,13 +5,12 @@
*
*/
-#include <common/uuid/uuid.h>
-#include <service/fwu/agent/fw_directory.h>
#include "mock_fw_inspector.h"
-int mock_fw_inspector_inspect(
- struct fw_directory *fw_dir,
- unsigned int boot_index)
+#include "common/uuid/uuid.h"
+#include "service/fwu/agent/fw_directory.h"
+
+int mock_fw_inspector_inspect(struct fw_directory *fw_dir, unsigned int boot_index)
{
(void)boot_index;
@@ -20,7 +19,7 @@
*/
/* Add some mock image entries to represent updatable units. */
- struct image_info image_info = {0};
+ struct image_info image_info = { 0 };
/* Image 1 */
uuid_guid_octets_from_canonical(&image_info.img_type_uuid, MOCK_IMG_TYPE_UUID_1);
@@ -64,5 +63,3 @@
return 0;
}
-
-
diff --git a/components/service/fwu/inspector/mock/mock_fw_inspector.h b/components/service/fwu/inspector/mock/mock_fw_inspector.h
index 0eb91dd..b31ef42 100644
--- a/components/service/fwu/inspector/mock/mock_fw_inspector.h
+++ b/components/service/fwu/inspector/mock/mock_fw_inspector.h
@@ -8,7 +8,7 @@
#ifndef MOCK_FW_INSPECTOR_H
#define MOCK_FW_INSPECTOR_H
-#include <service/fwu/inspector/fw_inspector.h>
+#include "service/fwu/inspector/fw_inspector.h"
#ifdef __cplusplus
extern "C" {
@@ -17,10 +17,10 @@
/**
* Mock image type UUIDs
*/
-#define MOCK_IMG_TYPE_UUID_1 "7744b3ab-2672-4a36-b619-b9a3608c9973"
-#define MOCK_IMG_TYPE_UUID_2 "52b3b093-08c4-427e-8cfe-a4c3b804ed88"
-#define MOCK_IMG_TYPE_UUID_3 "14345e20-a0b6-46dd-8699-e89512596205"
-#define MOCK_IMG_TYPE_UUID_4 "420f26dc-0a91-436f-8420-f4372b88ae16"
+#define MOCK_IMG_TYPE_UUID_1 "7744b3ab-2672-4a36-b619-b9a3608c9973"
+#define MOCK_IMG_TYPE_UUID_2 "52b3b093-08c4-427e-8cfe-a4c3b804ed88"
+#define MOCK_IMG_TYPE_UUID_3 "14345e20-a0b6-46dd-8699-e89512596205"
+#define MOCK_IMG_TYPE_UUID_4 "420f26dc-0a91-436f-8420-f4372b88ae16"
/**
* \brief mock_fw_inspector inspect method
@@ -34,9 +34,7 @@
*
* \return FWU status
*/
-int mock_fw_inspector_inspect(
- struct fw_directory *fw_dir,
- unsigned int boot_index);
+int mock_fw_inspector_inspect(struct fw_directory *fw_dir, unsigned int boot_index);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/installer/copy/copy_installer.c b/components/service/fwu/installer/copy/copy_installer.c
index 3ef19f3..84543a3 100644
--- a/components/service/fwu/installer/copy/copy_installer.c
+++ b/components/service/fwu/installer/copy/copy_installer.c
@@ -5,19 +5,19 @@
*
*/
+#include "copy_installer.h"
+
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
-#include <util.h>
-#include <media/volume/index/volume_index.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include "copy_installer.h"
-#define COPY_CHUNK_SIZE (4096)
+#include "media/volume/index/volume_index.h"
+#include "protocols/service/fwu/packed-c/status.h"
+#include "util.h"
+#define COPY_CHUNK_SIZE (4096)
-static int close_volumes_on_error(
- struct copy_installer *subject)
+static int close_volumes_on_error(struct copy_installer *subject)
{
volume_close(subject->source_volume);
volume_close(subject->destination_volume);
@@ -25,9 +25,7 @@
return FWU_STATUS_UNKNOWN;
}
-static int copy_volume_contents(
- struct copy_installer *subject,
- size_t target_copy_len)
+static int copy_volume_contents(struct copy_installer *subject, size_t target_copy_len)
{
int status = FWU_STATUS_SUCCESS;
size_t copy_len = 0;
@@ -37,27 +35,20 @@
return FWU_STATUS_UNKNOWN;
while (copy_len < target_copy_len) {
-
size_t actual_read_len = 0;
size_t actual_write_len = 0;
size_t remaining_len = target_copy_len - copy_len;
- size_t requested_read_len = (remaining_len < COPY_CHUNK_SIZE) ?
- remaining_len : COPY_CHUNK_SIZE;
+ size_t requested_read_len = (remaining_len < COPY_CHUNK_SIZE) ? remaining_len :
+ COPY_CHUNK_SIZE;
- status = volume_read(
- subject->source_volume,
- (uintptr_t)copy_buf,
- requested_read_len,
- &actual_read_len);
+ status = volume_read(subject->source_volume, (uintptr_t)copy_buf,
+ requested_read_len, &actual_read_len);
if (status)
break;
- status = volume_write(
- subject->destination_volume,
- (const uintptr_t)copy_buf,
- actual_read_len,
- &actual_write_len);
+ status = volume_write(subject->destination_volume, (const uintptr_t)copy_buf,
+ actual_read_len, &actual_write_len);
if (status)
break;
@@ -75,25 +66,18 @@
return status;
}
-static int copy_installer_begin(void *context,
- unsigned int current_volume_id,
- unsigned int update_volume_id)
+static int copy_installer_begin(void *context, unsigned int current_volume_id,
+ unsigned int update_volume_id)
{
struct copy_installer *subject = (struct copy_installer *)context;
- int status = volume_index_find(
- update_volume_id,
- &subject->destination_volume);
+ int status = volume_index_find(update_volume_id, &subject->destination_volume);
if (status == 0) {
-
- status = volume_index_find(
- current_volume_id,
- &subject->source_volume);
+ status = volume_index_find(current_volume_id, &subject->source_volume);
}
if (status != 0) {
-
subject->destination_volume = NULL;
subject->source_volume = NULL;
}
@@ -117,7 +101,6 @@
int destination_status = volume_open(subject->destination_volume);
if (destination_status) {
-
volume_close(subject->source_volume);
return destination_status;
}
@@ -149,11 +132,10 @@
source_status = volume_close(subject->source_volume);
destination_status = volume_close(subject->destination_volume);
- return
- (copy_status) ? copy_status :
- (destination_status) ? destination_status :
- (source_status) ? source_status :
- FWU_STATUS_SUCCESS;
+ return (copy_status) ? copy_status :
+ (destination_status) ? destination_status :
+ (source_status) ? source_status :
+ FWU_STATUS_SUCCESS;
}
static void copy_installer_abort(void *context)
@@ -164,8 +146,7 @@
subject->destination_volume = NULL;
}
-static int copy_installer_open(void *context,
- const struct image_info *image_info)
+static int copy_installer_open(void *context, const struct image_info *image_info)
{
(void)context;
(void)image_info;
@@ -180,9 +161,7 @@
return FWU_STATUS_DENIED;
}
-static int copy_installer_write(void *context,
- const uint8_t *data,
- size_t data_len)
+static int copy_installer_write(void *context, const uint8_t *data, size_t data_len)
{
(void)context;
(void)data;
@@ -191,9 +170,8 @@
return FWU_STATUS_DENIED;
}
-static int copy_installer_enumerate(void *context,
- uint32_t volume_id,
- struct fw_directory *fw_directory)
+static int copy_installer_enumerate(void *context, uint32_t volume_id,
+ struct fw_directory *fw_directory)
{
(void)volume_id;
(void)fw_directory;
@@ -204,18 +182,13 @@
return FWU_STATUS_SUCCESS;
}
-void copy_installer_init(struct copy_installer *subject,
- const struct uuid_octets *location_uuid,
- uint32_t location_id)
+void copy_installer_init(struct copy_installer *subject, const struct uuid_octets *location_uuid,
+ uint32_t location_id)
{
/* Define concrete installer interface */
static const struct installer_interface interface = {
- copy_installer_begin,
- copy_installer_finalize,
- copy_installer_abort,
- copy_installer_open,
- copy_installer_commit,
- copy_installer_write,
+ copy_installer_begin, copy_installer_finalize, copy_installer_abort,
+ copy_installer_open, copy_installer_commit, copy_installer_write,
copy_installer_enumerate
};
@@ -223,11 +196,8 @@
* installer that always updates a whole volume by copying
* from another.
*/
- installer_init(&subject->base_installer,
- INSTALL_TYPE_WHOLE_VOLUME_COPY,
- location_id,
- location_uuid,
- subject, &interface);
+ installer_init(&subject->base_installer, INSTALL_TYPE_WHOLE_VOLUME_COPY, location_id,
+ location_uuid, subject, &interface);
/* Initialize copy_installer specifics */
subject->source_volume = NULL;
diff --git a/components/service/fwu/installer/copy/copy_installer.h b/components/service/fwu/installer/copy/copy_installer.h
index c59745b..3aaf6a3 100644
--- a/components/service/fwu/installer/copy/copy_installer.h
+++ b/components/service/fwu/installer/copy/copy_installer.h
@@ -9,8 +9,9 @@
#define FWU_COPY_INSTALLER_H
#include <stdint.h>
-#include <service/fwu/installer/installer.h>
-#include <media/volume/volume.h>
+
+#include "media/volume/volume.h"
+#include "service/fwu/installer/installer.h"
#ifdef __cplusplus
extern "C" {
@@ -42,9 +43,8 @@
* \param[in] location_uuid The associated location UUID
* \param[in] location_id Identifies where to install qualifying images
*/
-void copy_installer_init(struct copy_installer *subject,
- const struct uuid_octets *location_uuid,
- uint32_t location_id);
+void copy_installer_init(struct copy_installer *subject, const struct uuid_octets *location_uuid,
+ uint32_t location_id);
/**
* \brief De-initialize a copy_installer
diff --git a/components/service/fwu/installer/copy/test/copy_installer_tests.cpp b/components/service/fwu/installer/copy/test/copy_installer_tests.cpp
index 3a51033..ac72092 100644
--- a/components/service/fwu/installer/copy/test/copy_installer_tests.cpp
+++ b/components/service/fwu/installer/copy/test/copy_installer_tests.cpp
@@ -4,21 +4,22 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include <CppUTest/TestHarness.h>
#include <cstdlib>
#include <cstring>
-#include <common/uuid/uuid.h>
-#include <media/disk/guid.h>
-#include <media/volume/block_volume/block_volume.h>
-#include <media/volume/index/volume_index.h>
-#include <media/volume/volume.h>
-#include <service/block_storage/factory/ref_ram_gpt/block_store_factory.h>
-#include <service/block_storage/config/ref/ref_partition_configurator.h>
-#include <service/fwu/agent/fw_directory.h>
-#include <service/fwu/installer/copy/copy_installer.h>
-#include <service/fwu/installer/raw/raw_installer.h>
-#include <service/fwu/installer/installer_index.h>
-#include <service/fwu/fw_store/banked/volume_id.h>
-#include <CppUTest/TestHarness.h>
+
+#include "common/uuid/uuid.h"
+#include "media/disk/guid.h"
+#include "media/volume/block_volume/block_volume.h"
+#include "media/volume/index/volume_index.h"
+#include "media/volume/volume.h"
+#include "service/block_storage/config/ref/ref_partition_configurator.h"
+#include "service/block_storage/factory/ref_ram_gpt/block_store_factory.h"
+#include "service/fwu/agent/fw_directory.h"
+#include "service/fwu/fw_store/banked/volume_id.h"
+#include "service/fwu/installer/copy/copy_installer.h"
+#include "service/fwu/installer/installer_index.h"
+#include "service/fwu/installer/raw/raw_installer.h"
TEST_GROUP(FwuCopyInstallerTests)
{
@@ -40,9 +41,8 @@
/* Construct fw volume A */
uuid_guid_octets_from_canonical(&partition_guid, REF_PARTITION_1_GUID);
- result = block_volume_init(&m_block_volume_a,
- m_block_store, &partition_guid,
- &m_fw_volume_a);
+ result = block_volume_init(&m_block_volume_a, m_block_store, &partition_guid,
+ &m_fw_volume_a);
LONGS_EQUAL(0, result);
CHECK_TRUE(m_fw_volume_a);
@@ -50,9 +50,8 @@
/* Construct fw volume B */
uuid_guid_octets_from_canonical(&partition_guid, REF_PARTITION_2_GUID);
- result = block_volume_init(&m_block_volume_b,
- m_block_store, &partition_guid,
- &m_fw_volume_b);
+ result = block_volume_init(&m_block_volume_b, m_block_store, &partition_guid,
+ &m_fw_volume_b);
LONGS_EQUAL(0, result);
CHECK_TRUE(m_fw_volume_b);
@@ -61,7 +60,7 @@
* install into one of volumes.
*/
uuid_guid_octets_from_canonical(&m_image_info.img_type_uuid,
- "1c22ca2c-9732-49e6-ba3b-eed40e27fda3");
+ "1c22ca2c-9732-49e6-ba3b-eed40e27fda3");
m_image_info.max_size =
(REF_PARTITION_1_ENDING_LBA - REF_PARTITION_1_STARTING_LBA + 1) *
@@ -77,24 +76,22 @@
* location and usage IDs. These usage IDs correspond to an A/B banked
* firmware store.
*/
- volume_index_add(
- banked_volume_id(FW_STORE_LOCATION_ID, BANKED_USAGE_ID_FW_BANK_A),
- m_fw_volume_a);
- volume_index_add(
- banked_volume_id(FW_STORE_LOCATION_ID, BANKED_USAGE_ID_FW_BANK_B),
- m_fw_volume_b);
+ volume_index_add(banked_volume_id(FW_STORE_LOCATION_ID, BANKED_USAGE_ID_FW_BANK_A),
+ m_fw_volume_a);
+ volume_index_add(banked_volume_id(FW_STORE_LOCATION_ID, BANKED_USAGE_ID_FW_BANK_B),
+ m_fw_volume_b);
/* A platform configuration will also determine which installers are
* assigned to which locations. For these tests, there is a raw_installer
* to install the initial image and a copy_installer to install a copy
* into the other bank.
*/
- raw_installer_init(&m_raw_installer,
- &m_image_info.img_type_uuid, FW_STORE_LOCATION_ID);
+ raw_installer_init(&m_raw_installer, &m_image_info.img_type_uuid,
+ FW_STORE_LOCATION_ID);
installer_index_register(&m_raw_installer.base_installer);
- copy_installer_init(&m_copy_installer,
- &m_image_info.img_type_uuid, FW_STORE_LOCATION_ID);
+ copy_installer_init(&m_copy_installer, &m_image_info.img_type_uuid,
+ FW_STORE_LOCATION_ID);
installer_index_register(&m_copy_installer.base_installer);
}
@@ -127,17 +124,18 @@
create_image(len);
/* Expect to find a suitable installer for the given image_info */
- struct installer *installer = installer_index_find(
- m_image_info.install_type, m_image_info.location_id);
+ struct installer *installer =
+ installer_index_find(m_image_info.install_type, m_image_info.location_id);
CHECK_TRUE(installer);
UNSIGNED_LONGS_EQUAL(FW_STORE_LOCATION_ID, installer->location_id);
/* Begin installation transaction - installing into volume A */
- int status = installer_begin(installer,
+ int status = installer_begin(
+ installer,
banked_volume_id(FW_STORE_LOCATION_ID,
- BANKED_USAGE_ID_FW_BANK_B), /* Current volume */
+ BANKED_USAGE_ID_FW_BANK_B), /* Current volume */
banked_volume_id(FW_STORE_LOCATION_ID,
- BANKED_USAGE_ID_FW_BANK_A)); /* Update volume */
+ BANKED_USAGE_ID_FW_BANK_A)); /* Update volume */
LONGS_EQUAL(0, status);
status = installer_open(installer, &m_image_info);
@@ -155,7 +153,7 @@
check_update_installed(m_fw_volume_a);
}
- void check_update_installed(struct volume *volume)
+ void check_update_installed(struct volume * volume)
{
int status = 0;
size_t total_read = 0;
@@ -164,18 +162,15 @@
LONGS_EQUAL(0, status);
while (total_read < m_image_len) {
-
uint8_t read_buf[1000];
size_t len_read = 0;
size_t bytes_remaining = m_image_len - total_read;
- size_t req_len = (bytes_remaining > sizeof(read_buf)) ?
- sizeof(read_buf) : bytes_remaining;
+ size_t req_len = (bytes_remaining > sizeof(read_buf)) ? sizeof(read_buf) :
+ bytes_remaining;
memset(read_buf, 0, sizeof(read_buf));
- status = volume_read(volume,
- (uintptr_t)read_buf, req_len,
- &len_read);
+ status = volume_read(volume, (uintptr_t)read_buf, req_len, &len_read);
LONGS_EQUAL(0, status);
UNSIGNED_LONGS_EQUAL(req_len, len_read);
@@ -188,7 +183,6 @@
LONGS_EQUAL(0, status);
}
-
static const unsigned int FW_STORE_LOCATION_ID = 0x100;
struct block_store *m_block_store;
@@ -209,17 +203,18 @@
install_initial_image(13011);
/* Expect to find a suitable copy installer */
- struct installer *installer = installer_index_find(
- INSTALL_TYPE_WHOLE_VOLUME_COPY, FW_STORE_LOCATION_ID);
+ struct installer *installer =
+ installer_index_find(INSTALL_TYPE_WHOLE_VOLUME_COPY, FW_STORE_LOCATION_ID);
CHECK_TRUE(installer);
UNSIGNED_LONGS_EQUAL(FW_STORE_LOCATION_ID, installer->location_id);
/* Begin installation transaction - installing into volume B */
- int status = installer_begin(installer,
- banked_volume_id(FW_STORE_LOCATION_ID,
- BANKED_USAGE_ID_FW_BANK_A), /* Current volume */
- banked_volume_id(FW_STORE_LOCATION_ID,
- BANKED_USAGE_ID_FW_BANK_B)); /* Update volume */
+ int status =
+ installer_begin(installer,
+ banked_volume_id(FW_STORE_LOCATION_ID,
+ BANKED_USAGE_ID_FW_BANK_A), /* Current volume */
+ banked_volume_id(FW_STORE_LOCATION_ID,
+ BANKED_USAGE_ID_FW_BANK_B)); /* Update volume */
LONGS_EQUAL(0, status);
/* Finalize the installation - the copy should happen here */
diff --git a/components/service/fwu/installer/factory/default/installer_factory.c b/components/service/fwu/installer/factory/default/installer_factory.c
index 96eec26..611ce93 100644
--- a/components/service/fwu/installer/factory/default/installer_factory.c
+++ b/components/service/fwu/installer/factory/default/installer_factory.c
@@ -4,16 +4,18 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include "service/fwu/installer/factory/installer_factory.h"
+
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include <common/uuid/uuid.h>
-#include <service/fwu/installer/installer.h>
-#include <service/fwu/installer/factory/locations.h>
-#include <service/fwu/installer/factory/installer_factory.h>
-#include <service/fwu/installer/copy/copy_installer.h>
-#include <service/fwu/installer/raw/raw_installer.h>
+
+#include "common/uuid/uuid.h"
+#include "service/fwu/installer/copy/copy_installer.h"
+#include "service/fwu/installer/factory/locations.h"
+#include "service/fwu/installer/installer.h"
+#include "service/fwu/installer/raw/raw_installer.h"
/**
* An installer factory for constructing installers for a platform
@@ -27,21 +29,18 @@
* a separate storage volume.
*/
-static bool check_supported_locations(
- const char *supported_uuids[],
- const struct uuid_octets *location_uuid)
+static bool check_supported_locations(const char *supported_uuids[],
+ const struct uuid_octets *location_uuid)
{
bool is_supported = false;
unsigned int i = 0;
while (supported_uuids[i]) {
-
struct uuid_octets comparison_uuid;
uuid_guid_octets_from_canonical(&comparison_uuid, supported_uuids[i]);
if (uuid_is_equal(comparison_uuid.octets, location_uuid->octets)) {
-
is_supported = true;
break;
}
@@ -52,32 +51,25 @@
return is_supported;
}
-struct installer *installer_factory_create_installer(
- enum install_type installation_type,
- unsigned int location_id,
- const struct uuid_octets *location_uuid)
+struct installer *installer_factory_create_installer(enum install_type installation_type,
+ unsigned int location_id,
+ const struct uuid_octets *location_uuid)
{
assert(location_uuid);
struct installer *product = NULL;
if (installation_type == INSTALL_TYPE_WHOLE_VOLUME) {
-
#ifdef RAW_INSTALLER_AVAILABLE
- static const char *raw_installer_compatibility[] = {
- LOCATION_UUID_AP_FW,
- LOCATION_UUID_SCP_FW,
- LOCATION_UUID_RSS_FW,
- NULL
+ static const char *const raw_installer_compatibility[] = {
+ LOCATION_UUID_AP_FW, LOCATION_UUID_SCP_FW, LOCATION_UUID_RSS_FW, NULL
};
if (check_supported_locations(raw_installer_compatibility, location_uuid)) {
-
struct raw_installer *raw_installer =
(struct raw_installer *)malloc(sizeof(struct raw_installer));
if (raw_installer) {
-
raw_installer_init(raw_installer, location_uuid, location_id);
product = &raw_installer->base_installer;
}
@@ -85,22 +77,16 @@
#endif
} else if (installation_type == INSTALL_TYPE_WHOLE_VOLUME_COPY) {
-
#ifdef COPY_INSTALLER_AVAILABLE
- static const char *copy_installer_compatibility[] = {
- LOCATION_UUID_AP_FW,
- LOCATION_UUID_SCP_FW,
- LOCATION_UUID_RSS_FW,
- NULL
+ static const char *const copy_installer_compatibility[] = {
+ LOCATION_UUID_AP_FW, LOCATION_UUID_SCP_FW, LOCATION_UUID_RSS_FW, NULL
};
if (check_supported_locations(copy_installer_compatibility, location_uuid)) {
-
struct copy_installer *copy_installer =
(struct copy_installer *)malloc(sizeof(struct copy_installer));
if (copy_installer) {
-
copy_installer_init(copy_installer, location_uuid, location_id);
product = ©_installer->base_installer;
}
@@ -111,8 +97,7 @@
return product;
}
-void installer_factory_destroy_installer(
- struct installer *installer)
+void installer_factory_destroy_installer(struct installer *installer)
{
if (installer)
free(installer->context);
diff --git a/components/service/fwu/installer/factory/default/test/default_installer_factory_tests.cpp b/components/service/fwu/installer/factory/default/test/default_installer_factory_tests.cpp
index 9a71426..213a265 100644
--- a/components/service/fwu/installer/factory/default/test/default_installer_factory_tests.cpp
+++ b/components/service/fwu/installer/factory/default/test/default_installer_factory_tests.cpp
@@ -4,39 +4,36 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <common/uuid/uuid.h>
-#include <media/disk/guid.h>
-#include <service/fwu/installer/factory/locations.h>
-#include <service/fwu/installer/factory/installer_factory.h>
-#include <service/fwu/installer/installer_index.h>
#include <CppUTest/TestHarness.h>
-TEST_GROUP(FwuDefaultInstallerFactoryTests)
+#include "common/uuid/uuid.h"
+#include "media/disk/guid.h"
+#include "service/fwu/installer/factory/installer_factory.h"
+#include "service/fwu/installer/factory/locations.h"
+#include "service/fwu/installer/installer_index.h"
+
+TEST_GROUP(FwuDefaultInstallerFactoryTests){ void setup(){ installer_index_init();
+}
+
+void teardown()
{
- void setup()
- {
- installer_index_init();
- }
+ unsigned int i = 0;
- void teardown()
- {
- unsigned int i = 0;
+ do {
+ struct installer *installer = installer_index_get(i);
- do {
+ if (!installer)
+ break;
- struct installer *installer = installer_index_get(i);
+ installer_factory_destroy_installer(installer);
+ ++i;
- if (!installer)
- break;
+ } while (1);
- installer_factory_destroy_installer(installer);
- ++i;
-
- } while (1);
-
- installer_index_clear();
- }
-};
+ installer_index_clear();
+}
+}
+;
TEST(FwuDefaultInstallerFactoryTests, configureInstallersFlow)
{
@@ -52,63 +49,61 @@
*/
/* Configure installers for updating AP firmware */
- uuid_guid_octets_from_canonical(&ap_fw_uuid,LOCATION_UUID_AP_FW);
+ uuid_guid_octets_from_canonical(&ap_fw_uuid, LOCATION_UUID_AP_FW);
/* Expect no installer to initially be registered */
CHECK_FALSE(installer_index_find_by_location_uuid(&ap_fw_uuid));
/* Configure for whole volume and copy installation */
- struct installer *installer = installer_factory_create_installer(
- INSTALL_TYPE_WHOLE_VOLUME, 0, &ap_fw_uuid);
+ struct installer *installer =
+ installer_factory_create_installer(INSTALL_TYPE_WHOLE_VOLUME, 0, &ap_fw_uuid);
CHECK_TRUE(installer);
installer_index_register(installer);
CHECK_TRUE(installer_index_find_by_location_uuid(&ap_fw_uuid));
- installer = installer_factory_create_installer(
- INSTALL_TYPE_WHOLE_VOLUME_COPY, 0, &ap_fw_uuid);
+ installer =
+ installer_factory_create_installer(INSTALL_TYPE_WHOLE_VOLUME_COPY, 0, &ap_fw_uuid);
CHECK_TRUE(installer);
installer_index_register(installer);
CHECK_TRUE(installer_index_find_by_location_uuid(&ap_fw_uuid));
/* Configure installers for updating SCP firmware */
- uuid_guid_octets_from_canonical(&scp_fw_uuid,LOCATION_UUID_SCP_FW);
+ uuid_guid_octets_from_canonical(&scp_fw_uuid, LOCATION_UUID_SCP_FW);
/* Expect no installer to initially be registered */
CHECK_FALSE(installer_index_find_by_location_uuid(&scp_fw_uuid));
/* Configure for whole volume and copy installation */
- installer = installer_factory_create_installer(
- INSTALL_TYPE_WHOLE_VOLUME, 0, &scp_fw_uuid);
+ installer = installer_factory_create_installer(INSTALL_TYPE_WHOLE_VOLUME, 0, &scp_fw_uuid);
CHECK_TRUE(installer);
installer_index_register(installer);
CHECK_TRUE(installer_index_find_by_location_uuid(&scp_fw_uuid));
- installer = installer_factory_create_installer(
- INSTALL_TYPE_WHOLE_VOLUME_COPY, 0, &scp_fw_uuid);
+ installer =
+ installer_factory_create_installer(INSTALL_TYPE_WHOLE_VOLUME_COPY, 0, &scp_fw_uuid);
CHECK_TRUE(installer);
installer_index_register(installer);
CHECK_TRUE(installer_index_find_by_location_uuid(&scp_fw_uuid));
/* Configure installers for updating RSS firmware */
- uuid_guid_octets_from_canonical(&rss_fw_uuid,LOCATION_UUID_RSS_FW);
+ uuid_guid_octets_from_canonical(&rss_fw_uuid, LOCATION_UUID_RSS_FW);
/* Expect no installer to initially be registered */
CHECK_FALSE(installer_index_find_by_location_uuid(&rss_fw_uuid));
/* Configure for whole volume and copy installation */
- installer = installer_factory_create_installer(
- INSTALL_TYPE_WHOLE_VOLUME, 0, &rss_fw_uuid);
+ installer = installer_factory_create_installer(INSTALL_TYPE_WHOLE_VOLUME, 0, &rss_fw_uuid);
CHECK_TRUE(installer);
installer_index_register(installer);
CHECK_TRUE(installer_index_find_by_location_uuid(&rss_fw_uuid));
- installer = installer_factory_create_installer(
- INSTALL_TYPE_WHOLE_VOLUME_COPY, 0, &rss_fw_uuid);
+ installer =
+ installer_factory_create_installer(INSTALL_TYPE_WHOLE_VOLUME_COPY, 0, &rss_fw_uuid);
CHECK_TRUE(installer);
installer_index_register(installer);
@@ -118,10 +113,10 @@
struct uuid_octets unsupported_location_uuid;
uuid_guid_octets_from_canonical(&unsupported_location_uuid,
- DISK_GUID_PARTITION_TYPE_FWU_METADATA);
+ DISK_GUID_PARTITION_TYPE_FWU_METADATA);
- installer = installer_factory_create_installer(INSTALL_TYPE_WHOLE_VOLUME,
- 0, &unsupported_location_uuid);
+ installer = installer_factory_create_installer(INSTALL_TYPE_WHOLE_VOLUME, 0,
+ &unsupported_location_uuid);
CHECK_FALSE(installer);
CHECK_FALSE(installer_index_find_by_location_uuid(&unsupported_location_uuid));
diff --git a/components/service/fwu/installer/factory/installer_factory.h b/components/service/fwu/installer/factory/installer_factory.h
index 7bf80c1..b903be9 100644
--- a/components/service/fwu/installer/factory/installer_factory.h
+++ b/components/service/fwu/installer/factory/installer_factory.h
@@ -7,8 +7,8 @@
#ifndef INSTALLER_FACTORY_H
#define INSTALLER_FACTORY_H
-#include <common/uuid/uuid.h>
-#include <service/fwu/agent/install_type.h>
+#include "common/uuid/uuid.h"
+#include "service/fwu/agent/install_type.h"
#ifdef __cplusplus
extern "C" {
@@ -37,19 +37,16 @@
*
* \return The constructed installer or NULL if no suitable installer can be constructed.
*/
-struct installer *installer_factory_create_installer(
- enum install_type installation_type,
- unsigned int location_id,
- const struct uuid_octets *location_uuid);
+struct installer *installer_factory_create_installer(enum install_type installation_type,
+ unsigned int location_id,
+ const struct uuid_octets *location_uuid);
/**
* \brief Destroy an installer
*
* \param[in] installer Installer to destroy
*/
-void installer_factory_destroy_installer(
- struct installer *installer);
-
+void installer_factory_destroy_installer(struct installer *installer);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/installer/factory/locations.h b/components/service/fwu/installer/factory/locations.h
index a20a7bc..4df7843 100644
--- a/components/service/fwu/installer/factory/locations.h
+++ b/components/service/fwu/installer/factory/locations.h
@@ -21,15 +21,12 @@
*/
/* Location UUID for application processor firmware */
-#define LOCATION_UUID_AP_FW \
- "2451cd6e-90fe-4b15-bf10-a69bce2d4486"
+#define LOCATION_UUID_AP_FW "2451cd6e-90fe-4b15-bf10-a69bce2d4486"
/* Location UUID for SCP firmware */
-#define LOCATION_UUID_SCP_FW \
- "691d5ea3-27fe-4104-badd-7539c00a9095"
+#define LOCATION_UUID_SCP_FW "691d5ea3-27fe-4104-badd-7539c00a9095"
/* Location UUID for RSS firmware */
-#define LOCATION_UUID_RSS_FW \
- "c948a156-58cb-4c38-b406-e60bff2223d5"
+#define LOCATION_UUID_RSS_FW "c948a156-58cb-4c38-b406-e60bff2223d5"
#endif /* INSTALLER_FACTORY_LOCATIONS_H */
diff --git a/components/service/fwu/installer/installer.c b/components/service/fwu/installer/installer.c
index 3c78a65..b69a71c 100644
--- a/components/service/fwu/installer/installer.c
+++ b/components/service/fwu/installer/installer.c
@@ -5,19 +5,17 @@
*
*/
+#include "installer.h"
+
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include "installer.h"
-void installer_init(
- struct installer *installer,
- enum install_type install_type,
- uint32_t location_id,
- const struct uuid_octets *location_uuid,
- void *context,
- const struct installer_interface *interface)
+#include "protocols/service/fwu/packed-c/status.h"
+
+void installer_init(struct installer *installer, enum install_type install_type,
+ uint32_t location_id, const struct uuid_octets *location_uuid, void *context,
+ const struct installer_interface *interface)
{
assert(installer);
assert(location_uuid);
@@ -35,10 +33,8 @@
installer->next = NULL;
}
-int installer_begin(
- struct installer *installer,
- uint32_t current_volume_id,
- uint32_t update_volume_id)
+int installer_begin(struct installer *installer, uint32_t current_volume_id,
+ uint32_t update_volume_id)
{
assert(installer);
assert(installer->interface);
@@ -47,14 +43,10 @@
installer->install_status = FWU_STATUS_SUCCESS;
installer->is_active = true;
- return installer->interface->begin(
- installer->context,
- current_volume_id,
- update_volume_id);
+ return installer->interface->begin(installer->context, current_volume_id, update_volume_id);
}
-int installer_finalize(
- struct installer *installer)
+int installer_finalize(struct installer *installer)
{
assert(installer);
assert(installer->interface);
@@ -62,12 +54,10 @@
installer->is_active = false;
- return installer->interface->finalize(
- installer->context);
+ return installer->interface->finalize(installer->context);
}
-void installer_abort(
- struct installer *installer)
+void installer_abort(struct installer *installer)
{
assert(installer);
assert(installer->interface);
@@ -75,21 +65,16 @@
installer->is_active = false;
- installer->interface->abort(
- installer->context);
+ installer->interface->abort(installer->context);
}
-int installer_open(
- struct installer *installer,
- const struct image_info *image_info)
+int installer_open(struct installer *installer, const struct image_info *image_info)
{
assert(installer);
assert(installer->interface);
assert(installer->interface->open);
- int status = installer->interface->open(
- installer->context,
- image_info);
+ int status = installer->interface->open(installer->context, image_info);
if (status && !installer->install_status)
installer->install_status = status;
@@ -97,15 +82,13 @@
return status;
}
-int installer_commit(
- struct installer *installer)
+int installer_commit(struct installer *installer)
{
assert(installer);
assert(installer->interface);
assert(installer->interface->commit);
- int status = installer->interface->commit(
- installer->context);
+ int status = installer->interface->commit(installer->context);
if (status && !installer->install_status)
installer->install_status = status;
@@ -113,18 +96,13 @@
return status;
}
-int installer_write(
- struct installer *installer,
- const uint8_t *data,
- size_t data_len)
+int installer_write(struct installer *installer, const uint8_t *data, size_t data_len)
{
assert(installer);
assert(installer->interface);
assert(installer->interface->write);
- int status = installer->interface->write(
- installer->context,
- data, data_len);
+ int status = installer->interface->write(installer->context, data, data_len);
if (status && !installer->install_status)
installer->install_status = status;
@@ -132,17 +110,12 @@
return status;
}
-int installer_enumerate(
- struct installer *installer,
- uint32_t volume_id,
- struct fw_directory *fw_directory)
+int installer_enumerate(struct installer *installer, uint32_t volume_id,
+ struct fw_directory *fw_directory)
{
assert(installer);
assert(installer->interface);
assert(installer->interface->enumerate);
- return installer->interface->enumerate(
- installer->context,
- volume_id,
- fw_directory);
+ return installer->interface->enumerate(installer->context, volume_id, fw_directory);
}
diff --git a/components/service/fwu/installer/installer.h b/components/service/fwu/installer/installer.h
index 49c822c..e8bddb0 100644
--- a/components/service/fwu/installer/installer.h
+++ b/components/service/fwu/installer/installer.h
@@ -11,8 +11,9 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-#include <common/uuid/uuid.h>
-#include <service/fwu/agent/install_type.h>
+
+#include "common/uuid/uuid.h"
+#include "service/fwu/agent/install_type.h"
#ifdef __cplusplus
extern "C" {
@@ -42,9 +43,7 @@
*
* \return FWU status
*/
- int (*begin)(void *context,
- uint32_t current_volume_id,
- uint32_t update_volume_id);
+ int (*begin)(void *context, uint32_t current_volume_id, uint32_t update_volume_id);
/**
* \brief Finalize a transaction of one or more image install operations
@@ -70,8 +69,7 @@
*
* \return FWU status
*/
- int (*open)(void *context,
- const struct image_info *image_info);
+ int (*open)(void *context, const struct image_info *image_info);
/**
* \brief Commit installed data (called once per open)
@@ -91,9 +89,7 @@
*
* \return FWU status
*/
- int (*write)(void *context,
- const uint8_t *data,
- size_t data_len);
+ int (*write)(void *context, const uint8_t *data, size_t data_len);
/**
* \brief Enumerate the collection of images that can be handled by the installer
@@ -108,9 +104,7 @@
*
* \return FWU status
*/
- int (*enumerate)(void *context,
- uint32_t volume_id,
- struct fw_directory *fw_directory);
+ int (*enumerate)(void *context, uint32_t volume_id, struct fw_directory *fw_directory);
};
/**
@@ -118,7 +112,6 @@
*
*/
struct installer {
-
/* The installation type handled by the installer */
enum install_type install_type;
@@ -172,41 +165,25 @@
return installer->install_status;
}
-void installer_init(
- struct installer *installer,
- enum install_type install_type,
- uint32_t location_id,
- const struct uuid_octets *location_uuid,
- void *context,
- const struct installer_interface *interface);
+void installer_init(struct installer *installer, enum install_type install_type,
+ uint32_t location_id, const struct uuid_octets *location_uuid, void *context,
+ const struct installer_interface *interface);
-int installer_begin(
- struct installer *installer,
- uint32_t current_volume_id,
- uint32_t update_volume_id);
+int installer_begin(struct installer *installer, uint32_t current_volume_id,
+ uint32_t update_volume_id);
-int installer_finalize(
- struct installer *installer);
+int installer_finalize(struct installer *installer);
-void installer_abort(
- struct installer *installer);
+void installer_abort(struct installer *installer);
-int installer_open(
- struct installer *installer,
- const struct image_info *image_info);
+int installer_open(struct installer *installer, const struct image_info *image_info);
-int installer_commit(
- struct installer *installer);
+int installer_commit(struct installer *installer);
-int installer_write(
- struct installer *installer,
- const uint8_t *data,
- size_t data_len);
+int installer_write(struct installer *installer, const uint8_t *data, size_t data_len);
-int installer_enumerate(
- struct installer *installer,
- uint32_t volume_id,
- struct fw_directory *fw_directory);
+int installer_enumerate(struct installer *installer, uint32_t volume_id,
+ struct fw_directory *fw_directory);
#ifdef __cplusplus
}
diff --git a/components/service/fwu/installer/installer_index.c b/components/service/fwu/installer/installer_index.c
index b2b24ef..a5a6290 100644
--- a/components/service/fwu/installer/installer_index.c
+++ b/components/service/fwu/installer/installer_index.c
@@ -4,26 +4,27 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <assert.h>
-#include <string.h>
-#include <stdint.h>
-#include <trace.h>
-#include "installer.h"
#include "installer_index.h"
+#include <assert.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "installer.h"
+#include "trace.h"
+
#ifndef INSTALLER_INDEX_LIMIT
-#define INSTALLER_INDEX_LIMIT (8)
+#define INSTALLER_INDEX_LIMIT (8)
#endif
#ifndef INSTALLER_INDEX_LOCATION_ID_LIMIT
-#define INSTALLER_INDEX_LOCATION_ID_LIMIT (8)
+#define INSTALLER_INDEX_LOCATION_ID_LIMIT (8)
#endif
/**
* Singleton index of installers to use for different classes of image.
*/
static struct {
-
/* An index for registered installers to handle update installation
* for the platform. The set of registered installers will have been
* selected for compatibility with the class of update image handled
@@ -49,14 +50,12 @@
* location_ids that have already been added.
*/
for (size_t i = 0; i < installer_index.num_location_ids; i++) {
-
if (location_id == installer_index.location_ids[i])
return;
}
/* It's a new location_id so add it */
if (installer_index.num_location_ids < INSTALLER_INDEX_LOCATION_ID_LIMIT) {
-
installer_index.location_ids[installer_index.num_location_ids] = location_id;
++installer_index.num_location_ids;
} else {
@@ -74,36 +73,29 @@
memset(&installer_index, 0, sizeof(installer_index));
}
-void installer_index_register(
- struct installer *installer)
+void installer_index_register(struct installer *installer)
{
assert(installer);
if (installer_index.num_registered < INSTALLER_INDEX_LIMIT) {
-
installer_index.installers[installer_index.num_registered] = installer;
++installer_index.num_registered;
-
add_location_id(installer->location_id);
} else {
EMSG("FWU configuration exceeds installer limit");
}
}
-struct installer *installer_index_find(
- enum install_type install_type,
- uint32_t location_id)
+struct installer *installer_index_find(enum install_type install_type, uint32_t location_id)
{
struct installer *result = NULL;
for (size_t i = 0; i < installer_index.num_registered; i++) {
-
struct installer *installer = installer_index.installers[i];
if ((installer->install_type == install_type) &&
- (installer->location_id == location_id)) {
-
+ (installer->location_id == location_id)) {
result = installer;
break;
}
@@ -112,18 +104,14 @@
return result;
}
-struct installer *installer_index_find_by_location_uuid(
- const struct uuid_octets *location_uuid)
+struct installer *installer_index_find_by_location_uuid(const struct uuid_octets *location_uuid)
{
struct installer *result = NULL;
for (size_t i = 0; i < installer_index.num_registered; i++) {
-
struct installer *installer = installer_index.installers[i];
- if (uuid_is_equal(location_uuid->octets,
- installer->location_uuid.octets)) {
-
+ if (uuid_is_equal(location_uuid->octets, installer->location_uuid.octets)) {
result = installer;
break;
}
@@ -132,8 +120,7 @@
return result;
}
-struct installer *installer_index_get(
- unsigned int index)
+struct installer *installer_index_get(unsigned int index)
{
struct installer *result = NULL;
diff --git a/components/service/fwu/installer/installer_index.h b/components/service/fwu/installer/installer_index.h
index 1626257..8e0baf5 100644
--- a/components/service/fwu/installer/installer_index.h
+++ b/components/service/fwu/installer/installer_index.h
@@ -9,7 +9,8 @@
#include <stddef.h>
#include <stdint.h>
-#include <service/fwu/agent/install_type.h>
+
+#include "service/fwu/agent/install_type.h"
#ifdef __cplusplus
extern "C" {
@@ -44,8 +45,7 @@
*
* @param[in] installer The installer to use
*/
-void installer_index_register(
- struct installer *installer);
+void installer_index_register(struct installer *installer);
/**
* @brief Find an installer for the specified type and location
@@ -55,9 +55,7 @@
*
* @return Pointer to a concrete installer or NULL if none found
*/
-struct installer *installer_index_find(
- enum install_type install_type,
- uint32_t location_id);
+struct installer *installer_index_find(enum install_type install_type, uint32_t location_id);
/**
* @brief Find a registered installer associated with the specified location UUID
@@ -66,8 +64,7 @@
*
* @return Pointer to a concrete installer or NULL if none found
*/
-struct installer *installer_index_find_by_location_uuid(
- const struct uuid_octets *location_uuid);
+struct installer *installer_index_find_by_location_uuid(const struct uuid_octets *location_uuid);
/**
* @brief Iterator function
diff --git a/components/service/fwu/installer/raw/raw_installer.c b/components/service/fwu/installer/raw/raw_installer.c
index 55cdcff..0002779 100644
--- a/components/service/fwu/installer/raw/raw_installer.c
+++ b/components/service/fwu/installer/raw/raw_installer.c
@@ -5,29 +5,26 @@
*
*/
+#include "raw_installer.h"
+
#include <assert.h>
#include <stddef.h>
#include <string.h>
-#include <media/volume/index/volume_index.h>
-#include <service/fwu/agent/fw_directory.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include "raw_installer.h"
+#include "media/volume/index/volume_index.h"
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/agent/fw_directory.h"
-static int raw_installer_begin(void *context,
- unsigned int current_volume_id,
- unsigned int update_volume_id)
+static int raw_installer_begin(void *context, unsigned int current_volume_id,
+ unsigned int update_volume_id)
{
struct raw_installer *subject = (struct raw_installer *)context;
(void)current_volume_id;
- int status = volume_index_find(
- update_volume_id,
- &subject->target_volume);
+ int status = volume_index_find(update_volume_id, &subject->target_volume);
if (status == 0) {
-
assert(subject->target_volume);
subject->commit_count = 0;
@@ -43,7 +40,6 @@
/* Close volume if left open */
if (subject->is_open) {
-
assert(subject->target_volume);
volume_close(subject->target_volume);
@@ -58,8 +54,7 @@
raw_installer_finalize(context);
}
-static int raw_installer_open(void *context,
- const struct image_info *image_info)
+static int raw_installer_open(void *context, const struct image_info *image_info)
{
struct raw_installer *subject = (struct raw_installer *)context;
int status = FWU_STATUS_DENIED;
@@ -71,20 +66,17 @@
* install into a particular location.
*/
if (!subject->is_open && subject->commit_count < 1) {
-
assert(subject->target_volume);
status = volume_open(subject->target_volume);
if (!status) {
-
/* Prior to writing to the volume to install the image, ensure
* that the volume is erased.
*/
status = volume_erase(subject->target_volume);
if (!status) {
-
subject->is_open = true;
subject->bytes_written = 0;
} else {
@@ -103,7 +95,6 @@
int status = FWU_STATUS_DENIED;
if (subject->is_open) {
-
assert(subject->target_volume);
status = volume_close(subject->target_volume);
@@ -112,7 +103,6 @@
subject->is_open = false;
if (!status && !subject->bytes_written) {
-
/* Installing a zero length image can imply an image delete
* operation. For certain types of installer, this is a legitimate
* operation. For a raw_installer, there really is no way to
@@ -125,22 +115,18 @@
return status;
}
-static int raw_installer_write(void *context,
- const uint8_t *data,
- size_t data_len)
+static int raw_installer_write(void *context, const uint8_t *data, size_t data_len)
{
struct raw_installer *subject = (struct raw_installer *)context;
int status = FWU_STATUS_DENIED;
if (subject->is_open) {
-
assert(subject->target_volume);
size_t len_written = 0;
- status = volume_write(subject->target_volume,
- (const uintptr_t)data, data_len,
- &len_written);
+ status = volume_write(subject->target_volume, (const uintptr_t)data, data_len,
+ &len_written);
subject->bytes_written += len_written;
@@ -154,9 +140,8 @@
return status;
}
-static int raw_installer_enumerate(void *context,
- uint32_t volume_id,
- struct fw_directory *fw_directory)
+static int raw_installer_enumerate(void *context, uint32_t volume_id,
+ struct fw_directory *fw_directory)
{
struct raw_installer *subject = (struct raw_installer *)context;
struct volume *volume = NULL;
@@ -172,7 +157,7 @@
* prepare an entry in the fw_directory to represent the whole volume
* as an advertised updatable image.
*/
- struct image_info image_info = {0};
+ struct image_info image_info = { 0 };
/* Limit the advertised max size to the volume size. The volume needs
* to be open to query its size.
@@ -205,29 +190,21 @@
return status;
}
-void raw_installer_init(struct raw_installer *subject,
- const struct uuid_octets *location_uuid,
- uint32_t location_id)
+void raw_installer_init(struct raw_installer *subject, const struct uuid_octets *location_uuid,
+ uint32_t location_id)
{
/* Define concrete installer interface */
static const struct installer_interface interface = {
- raw_installer_begin,
- raw_installer_finalize,
- raw_installer_abort,
- raw_installer_open,
- raw_installer_commit,
- raw_installer_write,
+ raw_installer_begin, raw_installer_finalize, raw_installer_abort,
+ raw_installer_open, raw_installer_commit, raw_installer_write,
raw_installer_enumerate
};
/* Initialize base installer - a raw_installer is a type of
* installer that always updates a whole volume.
*/
- installer_init(&subject->base_installer,
- INSTALL_TYPE_WHOLE_VOLUME,
- location_id,
- location_uuid,
- subject, &interface);
+ installer_init(&subject->base_installer, INSTALL_TYPE_WHOLE_VOLUME, location_id,
+ location_uuid, subject, &interface);
/* Initialize raw_installer specifics */
subject->target_volume = NULL;
diff --git a/components/service/fwu/installer/raw/raw_installer.h b/components/service/fwu/installer/raw/raw_installer.h
index d82cbc2..51b7354 100644
--- a/components/service/fwu/installer/raw/raw_installer.h
+++ b/components/service/fwu/installer/raw/raw_installer.h
@@ -11,9 +11,10 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-#include <common/uuid/uuid.h>
-#include <service/fwu/installer/installer.h>
-#include <media/volume/volume.h>
+
+#include "common/uuid/uuid.h"
+#include "media/volume/volume.h"
+#include "service/fwu/installer/installer.h"
#ifdef __cplusplus
extern "C" {
@@ -47,9 +48,8 @@
* \param[in] location_uuid The associated location UUID
* \param[in] location_id Identifies where to install qualifying images
*/
-void raw_installer_init(struct raw_installer *subject,
- const struct uuid_octets *location_uuid,
- uint32_t location_id);
+void raw_installer_init(struct raw_installer *subject, const struct uuid_octets *location_uuid,
+ uint32_t location_id);
/**
* \brief De-initialize a raw_installer
diff --git a/components/service/fwu/installer/raw/test/raw_installer_tests.cpp b/components/service/fwu/installer/raw/test/raw_installer_tests.cpp
index e0c1c6a..18c2654 100644
--- a/components/service/fwu/installer/raw/test/raw_installer_tests.cpp
+++ b/components/service/fwu/installer/raw/test/raw_installer_tests.cpp
@@ -4,20 +4,21 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include <CppUTest/TestHarness.h>
#include <cstdlib>
#include <cstring>
-#include <common/uuid/uuid.h>
-#include <media/disk/guid.h>
-#include <media/volume/block_volume/block_volume.h>
-#include <media/volume/index/volume_index.h>
-#include <media/volume/volume.h>
-#include <service/block_storage/factory/ref_ram_gpt/block_store_factory.h>
-#include <service/block_storage/config/ref/ref_partition_configurator.h>
-#include <service/fwu/installer/raw/raw_installer.h>
-#include <service/fwu/installer/installer_index.h>
-#include <service/fwu/fw_store/banked/volume_id.h>
-#include <service/fwu/agent/fw_directory.h>
-#include <CppUTest/TestHarness.h>
+
+#include "common/uuid/uuid.h"
+#include "media/disk/guid.h"
+#include "media/volume/block_volume/block_volume.h"
+#include "media/volume/index/volume_index.h"
+#include "media/volume/volume.h"
+#include "service/block_storage/config/ref/ref_partition_configurator.h"
+#include "service/block_storage/factory/ref_ram_gpt/block_store_factory.h"
+#include "service/fwu/agent/fw_directory.h"
+#include "service/fwu/fw_store/banked/volume_id.h"
+#include "service/fwu/installer/installer_index.h"
+#include "service/fwu/installer/raw/raw_installer.h"
TEST_GROUP(FwuRawInstallerTests)
{
@@ -39,9 +40,8 @@
/* Construct fw volume A */
uuid_guid_octets_from_canonical(&partition_guid, REF_PARTITION_1_GUID);
- result = block_volume_init(&m_block_volume_a,
- m_block_store, &partition_guid,
- &m_fw_volume_a);
+ result = block_volume_init(&m_block_volume_a, m_block_store, &partition_guid,
+ &m_fw_volume_a);
LONGS_EQUAL(0, result);
CHECK_TRUE(m_fw_volume_a);
@@ -49,9 +49,8 @@
/* Construct fw volume B */
uuid_guid_octets_from_canonical(&partition_guid, REF_PARTITION_2_GUID);
- result = block_volume_init(&m_block_volume_b,
- m_block_store, &partition_guid,
- &m_fw_volume_b);
+ result = block_volume_init(&m_block_volume_b, m_block_store, &partition_guid,
+ &m_fw_volume_b);
LONGS_EQUAL(0, result);
CHECK_TRUE(m_fw_volume_b);
@@ -61,7 +60,7 @@
* fw_directory.
*/
uuid_guid_octets_from_canonical(&m_image_info.img_type_uuid,
- "1c22ca2c-9732-49e6-ba3b-eed40e27fda3");
+ "1c22ca2c-9732-49e6-ba3b-eed40e27fda3");
m_image_info.max_size =
(REF_PARTITION_1_ENDING_LBA - REF_PARTITION_1_STARTING_LBA + 1) *
@@ -80,20 +79,17 @@
* banked_fw_store to be completely decoupled from the details
* of which fw volumes need updating on a platform.
*/
- volume_index_add(
- banked_volume_id(FW_STORE_LOCATION_ID, BANKED_USAGE_ID_FW_BANK_A),
- m_fw_volume_a);
- volume_index_add(
- banked_volume_id(FW_STORE_LOCATION_ID, BANKED_USAGE_ID_FW_BANK_B),
- m_fw_volume_b);
+ volume_index_add(banked_volume_id(FW_STORE_LOCATION_ID, BANKED_USAGE_ID_FW_BANK_A),
+ m_fw_volume_a);
+ volume_index_add(banked_volume_id(FW_STORE_LOCATION_ID, BANKED_USAGE_ID_FW_BANK_B),
+ m_fw_volume_b);
/* A platform configuration will also determine which installers are
* assigned to which locations. This provides flexibility to configure
* appropriate installers to handle alternative fw packages and installation
* strategies.
*/
- raw_installer_init(&m_installer,
- &m_image_info.img_type_uuid, FW_STORE_LOCATION_ID);
+ raw_installer_init(&m_installer, &m_image_info.img_type_uuid, FW_STORE_LOCATION_ID);
installer_index_register(&m_installer.base_installer);
}
@@ -121,13 +117,12 @@
m_image[i] = (uint8_t)rand();
}
- int write_image_in_random_len_chunks(struct installer *installer)
+ int write_image_in_random_len_chunks(struct installer * installer)
{
int status = 0;
size_t bytes_written = 0;
while ((bytes_written < m_image_len) && !status) {
-
size_t write_len = rand() % 100 + 1;
if ((bytes_written + write_len) > m_image_len)
@@ -140,7 +135,7 @@
return status;
}
- void check_update_installed(struct volume *volume)
+ void check_update_installed(struct volume * volume)
{
int status = 0;
size_t total_read = 0;
@@ -150,18 +145,15 @@
LONGS_EQUAL(0, status);
while (total_read < m_image_len) {
-
uint8_t read_buf[1000];
size_t len_read = 0;
size_t bytes_remaining = m_image_len - total_read;
- size_t req_len = (bytes_remaining > sizeof(read_buf)) ?
- sizeof(read_buf) : bytes_remaining;
+ size_t req_len = (bytes_remaining > sizeof(read_buf)) ? sizeof(read_buf) :
+ bytes_remaining;
memset(read_buf, 0, sizeof(read_buf));
- status = io_read(file_handle,
- (uintptr_t)read_buf, req_len,
- &len_read);
+ status = io_read(file_handle, (uintptr_t)read_buf, req_len, &len_read);
LONGS_EQUAL(0, status);
UNSIGNED_LONGS_EQUAL(req_len, len_read);
@@ -194,17 +186,17 @@
create_image(REF_PARTITION_BLOCK_SIZE * 2 + 111);
/* Expect to find a suitable installer for the given image_info */
- struct installer *installer = installer_index_find(
- m_image_info.install_type, m_image_info.location_id);
+ struct installer *installer =
+ installer_index_find(m_image_info.install_type, m_image_info.location_id);
CHECK_TRUE(installer);
UNSIGNED_LONGS_EQUAL(FW_STORE_LOCATION_ID, installer->location_id);
/* Begin installation transaction - installing into volume A */
status = installer_begin(installer,
- banked_volume_id(FW_STORE_LOCATION_ID,
- BANKED_USAGE_ID_FW_BANK_B), /* Current volume */
- banked_volume_id(FW_STORE_LOCATION_ID,
- BANKED_USAGE_ID_FW_BANK_A)); /* Update volume */
+ banked_volume_id(FW_STORE_LOCATION_ID,
+ BANKED_USAGE_ID_FW_BANK_B), /* Current volume */
+ banked_volume_id(FW_STORE_LOCATION_ID,
+ BANKED_USAGE_ID_FW_BANK_A)); /* Update volume */
LONGS_EQUAL(0, status);
/* Open install stream */
diff --git a/components/service/fwu/provider/fwu_provider.c b/components/service/fwu/provider/fwu_provider.c
index fe750f5..275d399 100644
--- a/components/service/fwu/provider/fwu_provider.c
+++ b/components/service/fwu/provider/fwu_provider.c
@@ -4,14 +4,16 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <stddef.h>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/opcodes.h>
-#include <protocols/rpc/common/packed-c/status.h>
-#include <service/fwu/agent/update_agent.h>
-#include <service/fwu/provider/serializer/fwu_provider_serializer.h>
#include "fwu_provider.h"
+#include <stddef.h>
+
+#include "common/uuid/uuid.h"
+#include "protocols/rpc/common/packed-c/status.h"
+#include "protocols/service/fwu/packed-c/opcodes.h"
+#include "service/fwu/agent/update_agent.h"
+#include "service/fwu/provider/serializer/fwu_provider_serializer.h"
+
/* Service request handlers */
static rpc_status_t begin_staging_handler(void *context, struct call_req *req);
static rpc_status_t end_staging_handler(void *context, struct call_req *req);
@@ -25,20 +27,19 @@
/* Handler mapping table for service */
static const struct service_handler handler_table[] = {
- {TS_FWU_OPCODE_BEGIN_STAGING, begin_staging_handler},
- {TS_FWU_OPCODE_END_STAGING, end_staging_handler},
- {TS_FWU_OPCODE_CANCEL_STAGING, cancel_staging_handler},
- {TS_FWU_OPCODE_OPEN, open_handler},
- {TS_FWU_OPCODE_WRITE_STREAM, write_stream_handler},
- {TS_FWU_OPCODE_READ_STREAM, read_stream_handler},
- {TS_FWU_OPCODE_COMMIT, commit_handler},
- {TS_FWU_OPCODE_ACCEPT_IMAGE, accept_image_handler},
- {TS_FWU_OPCODE_SELECT_PREVIOUS, select_previous_handler}
+ { TS_FWU_OPCODE_BEGIN_STAGING, begin_staging_handler },
+ { TS_FWU_OPCODE_END_STAGING, end_staging_handler },
+ { TS_FWU_OPCODE_CANCEL_STAGING, cancel_staging_handler },
+ { TS_FWU_OPCODE_OPEN, open_handler },
+ { TS_FWU_OPCODE_WRITE_STREAM, write_stream_handler },
+ { TS_FWU_OPCODE_READ_STREAM, read_stream_handler },
+ { TS_FWU_OPCODE_COMMIT, commit_handler },
+ { TS_FWU_OPCODE_ACCEPT_IMAGE, accept_image_handler },
+ { TS_FWU_OPCODE_SELECT_PREVIOUS, select_previous_handler }
};
-struct rpc_interface *fwu_provider_init(
- struct fwu_provider *context,
- struct update_agent *update_agent)
+struct rpc_interface *fwu_provider_init(struct fwu_provider *context,
+ struct update_agent *update_agent)
{
/* Initialise the fwu_provider */
context->update_agent = update_agent;
@@ -46,42 +47,36 @@
for (size_t encoding = 0; encoding < TS_RPC_ENCODING_LIMIT; ++encoding)
context->serializers[encoding] = NULL;
- service_provider_init(&context->base_provider, context,
- handler_table, sizeof(handler_table)/sizeof(struct service_handler));
+ service_provider_init(&context->base_provider, context, handler_table,
+ sizeof(handler_table) / sizeof(struct service_handler));
/* Initialise the associated discovery_provider and attach it */
discovery_provider_init(&context->discovery_provider);
- service_provider_extend(
- &context->base_provider,
- &context->discovery_provider.base_provider);
+ service_provider_extend(&context->base_provider,
+ &context->discovery_provider.base_provider);
return service_provider_get_rpc_interface(&context->base_provider);
}
-void fwu_provider_deinit(
- struct fwu_provider *context)
+void fwu_provider_deinit(struct fwu_provider *context)
{
discovery_provider_deinit(&context->discovery_provider);
}
-void fwu_provider_register_serializer(
- struct fwu_provider *context,
- unsigned int encoding,
- const struct fwu_provider_serializer *serializer)
+void fwu_provider_register_serializer(struct fwu_provider *context, unsigned int encoding,
+ const struct fwu_provider_serializer *serializer)
{
if (encoding < TS_RPC_ENCODING_LIMIT) {
-
context->serializers[encoding] = serializer;
- discovery_provider_register_supported_encoding(
- &context->discovery_provider, encoding);
+ discovery_provider_register_supported_encoding(&context->discovery_provider,
+ encoding);
}
}
-static const struct fwu_provider_serializer* get_fwu_serializer(
- struct fwu_provider *this_instance,
- const struct call_req *req)
+static const struct fwu_provider_serializer *get_fwu_serializer(struct fwu_provider *this_instance,
+ const struct call_req *req)
{
- const struct fwu_provider_serializer* serializer = NULL;
+ const struct fwu_provider_serializer *serializer = NULL;
unsigned int encoding = call_req_get_encoding(req);
if (encoding < TS_RPC_ENCODING_LIMIT)
@@ -135,13 +130,11 @@
rpc_status = serializer->deserialize_open_req(req_buf, &image_type_uuid);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
uint32_t handle = 0;
- int op_status = update_agent_open(this_instance->update_agent,
- &image_type_uuid, &handle);
+ int op_status =
+ update_agent_open(this_instance->update_agent, &image_type_uuid, &handle);
if (!op_status) {
-
struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
rpc_status = serializer->serialize_open_resp(resp_buf, handle);
}
@@ -163,13 +156,12 @@
const uint8_t *data = NULL;
if (serializer)
- rpc_status = serializer->deserialize_write_stream_req(
- req_buf, &handle, &data_len, &data);
+ rpc_status = serializer->deserialize_write_stream_req(req_buf, &handle, &data_len,
+ &data);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- int op_status = update_agent_write_stream(this_instance->update_agent,
- handle, data, data_len);
+ int op_status = update_agent_write_stream(this_instance->update_agent, handle, data,
+ data_len);
call_req_set_opstatus(req, op_status);
}
@@ -189,7 +181,6 @@
rpc_status = serializer->deserialize_read_stream_req(req_buf, &handle);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
uint8_t *payload_buf;
size_t max_payload;
@@ -198,13 +189,13 @@
serializer->read_stream_resp_payload(resp_buf, &payload_buf, &max_payload);
- int op_status = update_agent_read_stream(this_instance->update_agent,
- handle, payload_buf, max_payload,
- &read_len, &total_len);
+ int op_status = update_agent_read_stream(this_instance->update_agent, handle,
+ payload_buf, max_payload, &read_len,
+ &total_len);
if (!op_status)
- rpc_status = serializer->serialize_read_stream_resp(resp_buf,
- read_len, total_len);
+ rpc_status = serializer->serialize_read_stream_resp(resp_buf, read_len,
+ total_len);
call_req_set_opstatus(req, op_status);
}
@@ -223,16 +214,13 @@
size_t max_atomic_len = 0;
if (serializer)
- rpc_status = serializer->deserialize_commit_req(req_buf,
- &handle, &accepted, &max_atomic_len);
+ rpc_status = serializer->deserialize_commit_req(req_buf, &handle, &accepted,
+ &max_atomic_len);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- int op_status = update_agent_commit(
- this_instance->update_agent, handle, accepted);
+ int op_status = update_agent_commit(this_instance->update_agent, handle, accepted);
if (!op_status) {
-
struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
rpc_status = serializer->serialize_commit_resp(resp_buf, 0, 0);
}
@@ -255,7 +243,6 @@
rpc_status = serializer->deserialize_accept_req(req_buf, &image_type_uuid);
if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
int op_status = update_agent_accept(this_instance->update_agent, &image_type_uuid);
call_req_set_opstatus(req, op_status);
diff --git a/components/service/fwu/provider/fwu_provider.h b/components/service/fwu/provider/fwu_provider.h
index 3141f54..94c6ce5 100644
--- a/components/service/fwu/provider/fwu_provider.h
+++ b/components/service/fwu/provider/fwu_provider.h
@@ -7,10 +7,10 @@
#ifndef FWU_PROVIDER_H
#define FWU_PROVIDER_H
-#include <rpc/common/endpoint/rpc_interface.h>
-#include <service/common/provider/service_provider.h>
-#include <service/discovery/provider/discovery_provider.h>
-#include <protocols/rpc/common/packed-c/encoding.h>
+#include "protocols/rpc/common/packed-c/encoding.h"
+#include "rpc/common/endpoint/rpc_interface.h"
+#include "service/common/provider/service_provider.h"
+#include "service/discovery/provider/discovery_provider.h"
#ifdef __cplusplus
extern "C" {
@@ -31,8 +31,7 @@
* serialization/deserialization and parameter sanitation. Request are delegated
* to the associated update_agent.
*/
-struct fwu_provider
-{
+struct fwu_provider {
struct service_provider base_provider;
const struct fwu_provider_serializer *serializers[TS_RPC_ENCODING_LIMIT];
struct discovery_provider discovery_provider;
@@ -47,17 +46,15 @@
*
* \return A pointer to the exposed rpc_interface or NULL on failure
*/
-struct rpc_interface *fwu_provider_init(
- struct fwu_provider *context,
- struct update_agent *update_agent);
+struct rpc_interface *fwu_provider_init(struct fwu_provider *context,
+ struct update_agent *update_agent);
/**
* \brief De-initialise a fwu_provider
*
* \param[in] context The subject fwu_provider context
*/
-void fwu_provider_deinit(
- struct fwu_provider *context);
+void fwu_provider_deinit(struct fwu_provider *context);
/**
* \brief Register a serializer
@@ -66,10 +63,8 @@
* \param[in] encoding The encoding scheme
* \param[in] serializer The serializer
*/
-void fwu_provider_register_serializer(
- struct fwu_provider *context,
- unsigned int encoding,
- const struct fwu_provider_serializer *serializer);
+void fwu_provider_register_serializer(struct fwu_provider *context, unsigned int encoding,
+ const struct fwu_provider_serializer *serializer);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/components/service/fwu/provider/serializer/fwu_provider_serializer.h b/components/service/fwu/provider/serializer/fwu_provider_serializer.h
index 3c61bfd..0529068 100644
--- a/components/service/fwu/provider/serializer/fwu_provider_serializer.h
+++ b/components/service/fwu/provider/serializer/fwu_provider_serializer.h
@@ -7,11 +7,12 @@
#ifndef FWU_PROVIDER_SERIALIZER_H
#define FWU_PROVIDER_SERIALIZER_H
-#include <stddef.h>
#include <stdbool.h>
+#include <stddef.h>
#include <stdint.h>
-#include <common/uuid/uuid.h>
-#include <rpc/common/endpoint/rpc_interface.h>
+
+#include "common/uuid/uuid.h"
+#include "rpc/common/endpoint/rpc_interface.h"
/* Provides a common interface for parameter serialization operations
* for the fwu service provider. Allows alternative serialization
@@ -20,54 +21,38 @@
* implement this interface.
*/
struct fwu_provider_serializer {
-
/* Operation: open */
- rpc_status_t (*deserialize_open_req)(
- const struct call_param_buf *req_buf,
- struct uuid_octets *image_type_uuid);
+ rpc_status_t (*deserialize_open_req)(const struct call_param_buf *req_buf,
+ struct uuid_octets *image_type_uuid);
- rpc_status_t (*serialize_open_resp)(
- struct call_param_buf *resp_buf,
- uint32_t handle);
+ rpc_status_t (*serialize_open_resp)(struct call_param_buf *resp_buf, uint32_t handle);
/* Operation: write_stream */
- rpc_status_t (*deserialize_write_stream_req)(
- const struct call_param_buf *req_buf,
- uint32_t *handle,
- size_t *data_len,
- const uint8_t **data);
+ rpc_status_t (*deserialize_write_stream_req)(const struct call_param_buf *req_buf,
+ uint32_t *handle, size_t *data_len,
+ const uint8_t **data);
/* Operation: read_stream */
- rpc_status_t (*deserialize_read_stream_req)(
- const struct call_param_buf *req_buf,
- uint32_t *handle);
+ rpc_status_t (*deserialize_read_stream_req)(const struct call_param_buf *req_buf,
+ uint32_t *handle);
- void (*read_stream_resp_payload)(
- const struct call_param_buf *resp_buf,
- uint8_t **payload_buf,
- size_t *max_payload);
+ void (*read_stream_resp_payload)(const struct call_param_buf *resp_buf,
+ uint8_t **payload_buf, size_t *max_payload);
- rpc_status_t (*serialize_read_stream_resp)(
- struct call_param_buf *resp_buf,
- size_t read_bytes,
- size_t total_bytes);
+ rpc_status_t (*serialize_read_stream_resp)(struct call_param_buf *resp_buf,
+ size_t read_bytes, size_t total_bytes);
/* Operation: commit */
- rpc_status_t (*deserialize_commit_req)(
- const struct call_param_buf *req_buf,
- uint32_t *handle,
- bool *accepted,
- size_t *max_atomic_len);
+ rpc_status_t (*deserialize_commit_req)(const struct call_param_buf *req_buf,
+ uint32_t *handle, bool *accepted,
+ size_t *max_atomic_len);
- rpc_status_t (*serialize_commit_resp)(
- struct call_param_buf *resp_buf,
- size_t progress,
- size_t total_work);
+ rpc_status_t (*serialize_commit_resp)(struct call_param_buf *resp_buf, size_t progress,
+ size_t total_work);
/* Operation: accept_image */
- rpc_status_t (*deserialize_accept_req)(
- const struct call_param_buf *req_buf,
- struct uuid_octets *image_type_uuid);
+ rpc_status_t (*deserialize_accept_req)(const struct call_param_buf *req_buf,
+ struct uuid_octets *image_type_uuid);
};
#endif /* FWU_PROVIDER_SERIALIZER_H */
diff --git a/components/service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.c b/components/service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.c
index 9413417..9bafb42 100644
--- a/components/service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.c
+++ b/components/service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.c
@@ -3,26 +3,24 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
#include "packedc_fwu_provider_serializer.h"
+#include <string.h>
-static rpc_status_t deserialize_open_req(
- const struct call_param_buf *req_buf,
- struct uuid_octets *image_type_uuid)
+#include "protocols/rpc/common/packed-c/status.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+
+static rpc_status_t deserialize_open_req(const struct call_param_buf *req_buf,
+ struct uuid_octets *image_type_uuid)
{
rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
size_t expected_fixed_len = sizeof(struct ts_fwu_open_in);
if (expected_fixed_len <= req_buf->data_len) {
-
const struct ts_fwu_open_in *recv_msg =
(const struct ts_fwu_open_in *)req_buf->data;
- memcpy(image_type_uuid->octets,
- recv_msg->image_type_uuid, UUID_OCTETS_LEN);
+ memcpy(image_type_uuid->octets, recv_msg->image_type_uuid, UUID_OCTETS_LEN);
rpc_status = TS_RPC_CALL_ACCEPTED;
}
@@ -30,17 +28,13 @@
return rpc_status;
}
-static rpc_status_t serialize_open_resp(
- struct call_param_buf *resp_buf,
- uint32_t handle)
+static rpc_status_t serialize_open_resp(struct call_param_buf *resp_buf, uint32_t handle)
{
rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
size_t fixed_len = sizeof(struct ts_fwu_open_out);
if (fixed_len <= resp_buf->size) {
-
- struct ts_fwu_open_out *resp_msg =
- (struct ts_fwu_open_out *)resp_buf->data;
+ struct ts_fwu_open_out *resp_msg = (struct ts_fwu_open_out *)resp_buf->data;
resp_msg->handle = handle;
@@ -52,17 +46,14 @@
}
/* Operation: write_stream */
-static rpc_status_t deserialize_write_stream_req(
- const struct call_param_buf *req_buf,
- uint32_t *handle,
- size_t *data_len,
- const uint8_t **data)
+static rpc_status_t deserialize_write_stream_req(const struct call_param_buf *req_buf,
+ uint32_t *handle, size_t *data_len,
+ const uint8_t **data)
{
rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
size_t expected_fixed_len = sizeof(struct ts_fwu_write_stream_in);
if (expected_fixed_len <= req_buf->data_len) {
-
const struct ts_fwu_write_stream_in *recv_msg =
(const struct ts_fwu_write_stream_in *)req_buf->data;
@@ -76,15 +67,13 @@
}
/* Operation: read_stream */
-static rpc_status_t deserialize_read_stream_req(
- const struct call_param_buf *req_buf,
- uint32_t *handle)
+static rpc_status_t deserialize_read_stream_req(const struct call_param_buf *req_buf,
+ uint32_t *handle)
{
rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
size_t expected_fixed_len = sizeof(struct ts_fwu_read_stream_in);
if (expected_fixed_len <= req_buf->data_len) {
-
const struct ts_fwu_read_stream_in *recv_msg =
(const struct ts_fwu_read_stream_in *)req_buf->data;
@@ -95,10 +84,8 @@
return rpc_status;
}
-static void read_stream_resp_payload(
- const struct call_param_buf *resp_buf,
- uint8_t **payload_buf,
- size_t *max_payload)
+static void read_stream_resp_payload(const struct call_param_buf *resp_buf, uint8_t **payload_buf,
+ size_t *max_payload)
{
struct ts_fwu_read_stream_out *resp_msg = (struct ts_fwu_read_stream_out *)resp_buf->data;
size_t fixed_len = offsetof(struct ts_fwu_read_stream_out, payload);
@@ -110,10 +97,8 @@
*max_payload = resp_buf->size - fixed_len;
}
-static rpc_status_t serialize_read_stream_resp(
- struct call_param_buf *resp_buf,
- size_t read_bytes,
- size_t total_bytes)
+static rpc_status_t serialize_read_stream_resp(struct call_param_buf *resp_buf, size_t read_bytes,
+ size_t total_bytes)
{
rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
struct ts_fwu_read_stream_out *resp_msg = (struct ts_fwu_read_stream_out *)resp_buf->data;
@@ -125,7 +110,6 @@
size_t required_len = proto_overhead + read_bytes;
if (required_len <= resp_buf->size) {
-
resp_msg->read_bytes = read_bytes;
resp_msg->total_bytes = total_bytes;
@@ -137,17 +121,13 @@
}
/* Operation: commit */
-static rpc_status_t deserialize_commit_req(
- const struct call_param_buf *req_buf,
- uint32_t *handle,
- bool *accepted,
- size_t *max_atomic_len)
+static rpc_status_t deserialize_commit_req(const struct call_param_buf *req_buf, uint32_t *handle,
+ bool *accepted, size_t *max_atomic_len)
{
rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
size_t expected_fixed_len = sizeof(struct ts_fwu_commit_in);
if (expected_fixed_len <= req_buf->data_len) {
-
const struct ts_fwu_commit_in *recv_msg =
(const struct ts_fwu_commit_in *)req_buf->data;
@@ -160,10 +140,8 @@
return rpc_status;
}
-static rpc_status_t serialize_commit_resp(
- struct call_param_buf *resp_buf,
- size_t progress,
- size_t total_work)
+static rpc_status_t serialize_commit_resp(struct call_param_buf *resp_buf, size_t progress,
+ size_t total_work)
{
rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
struct ts_fwu_commit_out *resp_msg = (struct ts_fwu_commit_out *)resp_buf->data;
@@ -171,7 +149,6 @@
size_t required_len = sizeof(struct ts_fwu_commit_out);
if (required_len <= resp_buf->size) {
-
resp_msg->progress = progress;
resp_msg->total_work = total_work;
@@ -183,15 +160,13 @@
}
/* Operation: accept_image */
-static rpc_status_t deserialize_accept_req(
- const struct call_param_buf *req_buf,
- struct uuid_octets *image_type_uuid)
+static rpc_status_t deserialize_accept_req(const struct call_param_buf *req_buf,
+ struct uuid_octets *image_type_uuid)
{
rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
size_t expected_fixed_len = sizeof(struct ts_fwu_accept_image_in);
if (expected_fixed_len <= req_buf->data_len) {
-
const struct ts_fwu_accept_image_in *recv_msg =
(const struct ts_fwu_accept_image_in *)req_buf->data;
@@ -206,15 +181,9 @@
const struct fwu_provider_serializer *packedc_fwu_provider_serializer_instance(void)
{
static const struct fwu_provider_serializer instance = {
- deserialize_open_req,
- serialize_open_resp,
- deserialize_write_stream_req,
- deserialize_read_stream_req,
- read_stream_resp_payload,
- serialize_read_stream_resp,
- deserialize_commit_req,
- serialize_commit_resp,
- deserialize_accept_req
+ deserialize_open_req, serialize_open_resp, deserialize_write_stream_req,
+ deserialize_read_stream_req, read_stream_resp_payload, serialize_read_stream_resp,
+ deserialize_commit_req, serialize_commit_resp, deserialize_accept_req
};
return &instance;
diff --git a/components/service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.h b/components/service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.h
index b9ced37..e1baeed 100644
--- a/components/service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.h
+++ b/components/service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.h
@@ -7,7 +7,7 @@
#ifndef PACKEDC_FWU_PROVIDER_SERIALIZER_H
#define PACKEDC_FWU_PROVIDER_SERIALIZER_H
-#include <service/fwu/provider/serializer/fwu_provider_serializer.h>
+#include "service/fwu/provider/serializer/fwu_provider_serializer.h"
#ifdef __cplusplus
extern "C" {
diff --git a/components/service/fwu/test/fwu_client/direct/direct_fwu_client.cpp b/components/service/fwu/test/fwu_client/direct/direct_fwu_client.cpp
index 933258e..6afd0f2 100644
--- a/components/service/fwu/test/fwu_client/direct/direct_fwu_client.cpp
+++ b/components/service/fwu/test/fwu_client/direct/direct_fwu_client.cpp
@@ -4,15 +4,16 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <cstring>
-#include <service/fwu/agent/update_agent.h>
#include "direct_fwu_client.h"
+#include <cstring>
-direct_fwu_client::direct_fwu_client(struct update_agent *update_agent) :
- fwu_client(),
- m_update_agent(update_agent),
- m_read_buf()
+#include "service/fwu/agent/update_agent.h"
+
+direct_fwu_client::direct_fwu_client(struct update_agent *update_agent)
+ : fwu_client()
+ , m_update_agent(update_agent)
+ , m_read_buf()
{
/* The read buffer represents a communication buffer that will
* constrain the amount of data that may be read in a single read.
@@ -22,7 +23,6 @@
direct_fwu_client::~direct_fwu_client()
{
-
}
int direct_fwu_client::begin_staging(void)
@@ -40,8 +40,7 @@
return update_agent_cancel_staging(m_update_agent);
}
-int direct_fwu_client::accept(
- const struct uuid_octets *image_type_uuid)
+int direct_fwu_client::accept(const struct uuid_octets *image_type_uuid)
{
return update_agent_accept(m_update_agent, image_type_uuid);
}
@@ -51,47 +50,32 @@
return update_agent_select_previous(m_update_agent);
}
-int direct_fwu_client::open(
- const struct uuid_octets *uuid,
- uint32_t *handle)
+int direct_fwu_client::open(const struct uuid_octets *uuid, uint32_t *handle)
{
return update_agent_open(m_update_agent, uuid, handle);
}
-int direct_fwu_client::commit(
- uint32_t handle,
- bool accepted)
+int direct_fwu_client::commit(uint32_t handle, bool accepted)
{
return update_agent_commit(m_update_agent, handle, accepted);
}
-int direct_fwu_client::write_stream(
- uint32_t handle,
- const uint8_t *data,
- size_t data_len)
+int direct_fwu_client::write_stream(uint32_t handle, const uint8_t *data, size_t data_len)
{
return update_agent_write_stream(m_update_agent, handle, data, data_len);
}
-int direct_fwu_client::read_stream(
- uint32_t handle,
- uint8_t *buf,
- size_t buf_size,
- size_t *read_len,
- size_t *total_len)
+int direct_fwu_client::read_stream(uint32_t handle, uint8_t *buf, size_t buf_size, size_t *read_len,
+ size_t *total_len)
{
- int status = update_agent_read_stream(m_update_agent, handle,
- m_read_buf, READ_BUF_SIZE,
- read_len, total_len);
+ int status = update_agent_read_stream(m_update_agent, handle, m_read_buf, READ_BUF_SIZE,
+ read_len, total_len);
if (!status && buf && buf_size) {
-
- size_t copy_len = (*read_len <= buf_size) ?
- *read_len : buf_size;
+ size_t copy_len = (*read_len <= buf_size) ? *read_len : buf_size;
memcpy(buf, m_read_buf, copy_len);
}
return status;
}
-
diff --git a/components/service/fwu/test/fwu_client/direct/direct_fwu_client.h b/components/service/fwu/test/fwu_client/direct/direct_fwu_client.h
index c28ecf3..bfa925b 100644
--- a/components/service/fwu/test/fwu_client/direct/direct_fwu_client.h
+++ b/components/service/fwu/test/fwu_client/direct/direct_fwu_client.h
@@ -7,7 +7,7 @@
#ifndef DIRECT_FWU_CLIENT_H
#define DIRECT_FWU_CLIENT_H
-#include <service/fwu/test/fwu_client/fwu_client.h>
+#include "service/fwu/test/fwu_client/fwu_client.h"
/* Public interface dependencies */
struct update_agent;
@@ -17,11 +17,9 @@
* used for component level testing where tests and update_agent are
* combined in the same build.
*/
-class direct_fwu_client : public fwu_client
-{
+class direct_fwu_client : public fwu_client {
public:
-
- direct_fwu_client(struct update_agent *update_agent);
+ explicit direct_fwu_client(struct update_agent *update_agent);
~direct_fwu_client();
int begin_staging(void);
@@ -30,33 +28,20 @@
int cancel_staging(void);
- int accept(
- const struct uuid_octets *image_type_uuid);
+ int accept(const struct uuid_octets *image_type_uuid);
int select_previous(void);
- int open(
- const struct uuid_octets *uuid,
- uint32_t *handle);
+ int open(const struct uuid_octets *uuid, uint32_t *handle);
- int commit(
- uint32_t handle,
- bool accepted);
+ int commit(uint32_t handle, bool accepted);
- int write_stream(
- uint32_t handle,
- const uint8_t *data,
- size_t data_len);
+ int write_stream(uint32_t handle, const uint8_t *data, size_t data_len);
- int read_stream(
- uint32_t handle,
- uint8_t *buf,
- size_t buf_size,
- size_t *read_len,
- size_t *total_len);
+ int read_stream(uint32_t handle, uint8_t *buf, size_t buf_size, size_t *read_len,
+ size_t *total_len);
private:
-
static const size_t READ_BUF_SIZE = 512;
struct update_agent *m_update_agent;
diff --git a/components/service/fwu/test/fwu_client/fwu_client.h b/components/service/fwu/test/fwu_client/fwu_client.h
index d9773e9..55f4c87 100644
--- a/components/service/fwu/test/fwu_client/fwu_client.h
+++ b/components/service/fwu/test/fwu_client/fwu_client.h
@@ -9,25 +9,22 @@
#include <stddef.h>
#include <stdint.h>
-#include <common/uuid/uuid.h>
+
+#include "common/uuid/uuid.h"
/*
* Presents a client interface for interacting with a fwu service provider.
* Test cases that use this interface can potentially be reused with alternative
* service provider deployments.
*/
-class fwu_client
-{
+class fwu_client {
public:
-
fwu_client()
{
-
}
virtual ~fwu_client()
{
-
}
virtual int begin_staging(void) = 0;
@@ -36,30 +33,18 @@
virtual int cancel_staging(void) = 0;
- virtual int accept(
- const struct uuid_octets *image_type_uuid) = 0;
+ virtual int accept(const struct uuid_octets *image_type_uuid) = 0;
virtual int select_previous(void) = 0;
- virtual int open(
- const struct uuid_octets *uuid,
- uint32_t *handle) = 0;
+ virtual int open(const struct uuid_octets *uuid, uint32_t *handle) = 0;
- virtual int commit(
- uint32_t handle,
- bool accepted) = 0;
+ virtual int commit(uint32_t handle, bool accepted) = 0;
- virtual int write_stream(
- uint32_t handle,
- const uint8_t *data,
- size_t data_len) = 0;
+ virtual int write_stream(uint32_t handle, const uint8_t *data, size_t data_len) = 0;
- virtual int read_stream(
- uint32_t handle,
- uint8_t *buf,
- size_t buf_size,
- size_t *read_len,
- size_t *total_len) = 0;
+ virtual int read_stream(uint32_t handle, uint8_t *buf, size_t buf_size, size_t *read_len,
+ size_t *total_len) = 0;
};
#endif /* FWU_CLIENT_H */
diff --git a/components/service/fwu/test/fwu_client/remote/remote_fwu_client.cpp b/components/service/fwu/test/fwu_client/remote/remote_fwu_client.cpp
index 13058f5..d4503a5 100644
--- a/components/service/fwu/test/fwu_client/remote/remote_fwu_client.cpp
+++ b/components/service/fwu/test/fwu_client/remote/remote_fwu_client.cpp
@@ -4,22 +4,24 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include "remote_fwu_client.h"
+
#include <cassert>
#include <climits>
#include <cstring>
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/fwu/packed-c/opcodes.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
-#include <protocols/service/fwu/packed-c/status.h>
-#include <protocols/rpc/common/packed-c/encoding.h>
-#include <service/discovery/client/discovery_client.h>
-#include "remote_fwu_client.h"
-remote_fwu_client::remote_fwu_client() :
- fwu_client(),
- m_client(),
- m_rpc_session_handle(NULL),
- m_service_context(NULL)
+#include "protocols/rpc/common/packed-c/encoding.h"
+#include "protocols/rpc/common/packed-c/status.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+#include "protocols/service/fwu/packed-c/opcodes.h"
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/discovery/client/discovery_client.h"
+
+remote_fwu_client::remote_fwu_client()
+ : fwu_client()
+ , m_client()
+ , m_rpc_session_handle(NULL)
+ , m_service_context(NULL)
{
open_session();
}
@@ -42,19 +44,16 @@
m_service_context = service_locator_query("sn:trustedfirmware.org:fwu:0", &status);
if (m_service_context) {
-
- m_rpc_session_handle = service_context_open(
- m_service_context, TS_RPC_ENCODING_PACKED_C, &caller);
+ m_rpc_session_handle =
+ service_context_open(m_service_context, TS_RPC_ENCODING_PACKED_C, &caller);
if (m_rpc_session_handle) {
-
assert(caller);
service_client_init(&m_client, caller);
discovery_client_get_service_info(&m_client);
} else {
-
service_context_relinquish(m_service_context);
m_service_context = NULL;
}
@@ -64,11 +63,9 @@
void remote_fwu_client::close_session(void)
{
if (m_service_context) {
-
service_client_deinit(&m_client);
if (m_rpc_session_handle) {
-
service_context_close(m_service_context, m_rpc_session_handle);
m_rpc_session_handle = NULL;
}
@@ -91,14 +88,12 @@
call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
rpc_opstatus_t opstatus;
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- opcode, &opstatus,
- &resp_buf, &resp_len);
+ m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle, opcode,
+ &opstatus, &resp_buf, &resp_len);
if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED)
fwu_status = opstatus;
@@ -109,7 +104,6 @@
return fwu_status;
}
-
int remote_fwu_client::begin_staging(void)
{
return invoke_no_param(TS_FWU_OPCODE_BEGIN_STAGING);
@@ -125,11 +119,10 @@
return invoke_no_param(TS_FWU_OPCODE_CANCEL_STAGING);
}
-int remote_fwu_client::accept(
- const struct uuid_octets *image_type_uuid)
+int remote_fwu_client::accept(const struct uuid_octets *image_type_uuid)
{
int fwu_status = FWU_STATUS_NOT_AVAILABLE;
- struct ts_fwu_accept_image_in req_msg = {0};
+ struct ts_fwu_accept_image_in req_msg = { 0 };
size_t req_len = sizeof(struct ts_fwu_accept_image_in);
if (!m_service_context)
@@ -143,7 +136,6 @@
call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
rpc_opstatus_t opstatus;
@@ -151,8 +143,8 @@
memcpy(req_buf, &req_msg, req_len);
m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_FWU_OPCODE_ACCEPT_IMAGE, &opstatus,
- &resp_buf, &resp_len);
+ TS_FWU_OPCODE_ACCEPT_IMAGE, &opstatus,
+ &resp_buf, &resp_len);
if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED)
fwu_status = opstatus;
@@ -168,12 +160,10 @@
return invoke_no_param(TS_FWU_OPCODE_SELECT_PREVIOUS);
}
-int remote_fwu_client::open(
- const struct uuid_octets *uuid,
- uint32_t *handle)
+int remote_fwu_client::open(const struct uuid_octets *uuid, uint32_t *handle)
{
int fwu_status = FWU_STATUS_NOT_AVAILABLE;
- struct ts_fwu_open_in req_msg = {0};
+ struct ts_fwu_open_in req_msg = { 0 };
size_t req_len = sizeof(struct ts_fwu_open_in);
if (!m_service_context)
@@ -187,7 +177,6 @@
call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
rpc_opstatus_t opstatus;
@@ -195,16 +184,14 @@
memcpy(req_buf, &req_msg, req_len);
m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_FWU_OPCODE_OPEN, &opstatus,
- &resp_buf, &resp_len);
+ TS_FWU_OPCODE_OPEN, &opstatus, &resp_buf,
+ &resp_len);
if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
fwu_status = opstatus;
if ((fwu_status == FWU_STATUS_SUCCESS) &&
- (resp_len >= sizeof(struct ts_fwu_open_out))) {
-
+ (resp_len >= sizeof(struct ts_fwu_open_out))) {
struct ts_fwu_open_out resp_msg;
memcpy(&resp_msg, resp_buf, sizeof(struct ts_fwu_open_out));
@@ -218,12 +205,10 @@
return fwu_status;
}
-int remote_fwu_client::commit(
- uint32_t handle,
- bool accepted)
+int remote_fwu_client::commit(uint32_t handle, bool accepted)
{
int fwu_status = FWU_STATUS_NOT_AVAILABLE;
- struct ts_fwu_commit_in req_msg = {0};
+ struct ts_fwu_commit_in req_msg = { 0 };
size_t req_len = sizeof(struct ts_fwu_commit_in);
if (!m_service_context)
@@ -238,7 +223,6 @@
call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
rpc_opstatus_t opstatus;
@@ -246,8 +230,8 @@
memcpy(req_buf, &req_msg, req_len);
m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_FWU_OPCODE_COMMIT, &opstatus,
- &resp_buf, &resp_len);
+ TS_FWU_OPCODE_COMMIT, &opstatus, &resp_buf,
+ &resp_len);
if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED)
fwu_status = opstatus;
@@ -258,14 +242,12 @@
return fwu_status;
}
-int remote_fwu_client::write_stream(
- uint32_t handle,
- const uint8_t *data,
- size_t data_len)
+int remote_fwu_client::write_stream(uint32_t handle, const uint8_t *data, size_t data_len)
{
size_t proto_overhead = offsetof(ts_fwu_write_stream_in, payload);
size_t max_payload = (m_client.service_info.max_payload > proto_overhead) ?
- m_client.service_info.max_payload - proto_overhead : 0;
+ m_client.service_info.max_payload - proto_overhead :
+ 0;
if (!data || (data_len > (SIZE_MAX - proto_overhead)))
return FWU_STATUS_OUT_OF_BOUNDS;
@@ -282,10 +264,8 @@
req_msg.handle = handle;
while (total_written < data_len) {
-
size_t bytes_remaining = data_len - total_written;
- size_t write_len = (bytes_remaining < max_payload) ?
- bytes_remaining : max_payload;
+ size_t write_len = (bytes_remaining < max_payload) ? bytes_remaining : max_payload;
size_t req_len = proto_overhead + write_len;
req_msg.data_len = write_len;
@@ -296,7 +276,6 @@
call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
rpc_opstatus_t opstatus;
@@ -307,8 +286,8 @@
total_written += write_len;
m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_FWU_OPCODE_WRITE_STREAM, &opstatus,
- &resp_buf, &resp_len);
+ TS_FWU_OPCODE_WRITE_STREAM,
+ &opstatus, &resp_buf, &resp_len);
rpc_caller_end(m_client.caller, call_handle);
@@ -325,12 +304,8 @@
return FWU_STATUS_SUCCESS;
}
-int remote_fwu_client::read_stream(
- uint32_t handle,
- uint8_t *buf,
- size_t buf_size,
- size_t *read_len,
- size_t *total_len)
+int remote_fwu_client::read_stream(uint32_t handle, uint8_t *buf, size_t buf_size, size_t *read_len,
+ size_t *total_len)
{
int fwu_status = FWU_STATUS_NOT_AVAILABLE;
struct ts_fwu_read_stream_in req_msg;
@@ -350,7 +325,6 @@
call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
if (call_handle) {
-
uint8_t *resp_buf;
size_t resp_len;
rpc_opstatus_t opstatus;
@@ -358,18 +332,15 @@
memcpy(req_buf, &req_msg, req_len);
m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_FWU_OPCODE_READ_STREAM, &opstatus,
- &resp_buf, &resp_len);
+ TS_FWU_OPCODE_READ_STREAM, &opstatus,
+ &resp_buf, &resp_len);
size_t proto_overhead = offsetof(ts_fwu_read_stream_out, payload);
if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
fwu_status = opstatus;
- if ((fwu_status == FWU_STATUS_SUCCESS) &&
- (resp_len >= proto_overhead)) {
-
+ if ((fwu_status == FWU_STATUS_SUCCESS) && (resp_len >= proto_overhead)) {
const struct ts_fwu_read_stream_out *resp_msg =
(const struct ts_fwu_read_stream_out *)resp_buf;
@@ -377,9 +348,9 @@
*total_len = resp_msg->total_bytes;
if (buf && buf_size) {
-
size_t copy_len = (resp_msg->read_bytes <= buf_size) ?
- resp_msg->read_bytes : buf_size;
+ resp_msg->read_bytes :
+ buf_size;
memcpy(buf, resp_msg->payload, copy_len);
}
diff --git a/components/service/fwu/test/fwu_client/remote/remote_fwu_client.h b/components/service/fwu/test/fwu_client/remote/remote_fwu_client.h
index 01e763e..c9a440e 100644
--- a/components/service/fwu/test/fwu_client/remote/remote_fwu_client.h
+++ b/components/service/fwu/test/fwu_client/remote/remote_fwu_client.h
@@ -7,19 +7,17 @@
#ifndef REMOTE_FWU_CLIENT_H
#define REMOTE_FWU_CLIENT_H
-#include <service/common/client/service_client.h>
-#include <service/fwu/test/fwu_client/fwu_client.h>
-#include <service_locator.h>
+#include "service/common/client/service_client.h"
+#include "service/fwu/test/fwu_client/fwu_client.h"
+#include "service_locator.h"
/*
* An fwu_client that calls a remote fwu service provider via a
* deployment specific RPC caller. Assumes that call request and
* response parameters are serialized in-line with the FWU-A specification.
*/
-class remote_fwu_client : public fwu_client
-{
+class remote_fwu_client : public fwu_client {
public:
-
remote_fwu_client();
~remote_fwu_client();
@@ -29,33 +27,20 @@
int cancel_staging(void);
- int accept(
- const struct uuid_octets *image_type_uuid);
+ int accept(const struct uuid_octets *image_type_uuid);
int select_previous(void);
- int open(
- const struct uuid_octets *uuid,
- uint32_t *handle);
+ int open(const struct uuid_octets *uuid, uint32_t *handle);
- int commit(
- uint32_t handle,
- bool accepted);
+ int commit(uint32_t handle, bool accepted);
- int write_stream(
- uint32_t handle,
- const uint8_t *data,
- size_t data_len);
+ int write_stream(uint32_t handle, const uint8_t *data, size_t data_len);
- int read_stream(
- uint32_t handle,
- uint8_t *buf,
- size_t buf_size,
- size_t *read_len,
- size_t *total_len);
+ int read_stream(uint32_t handle, uint8_t *buf, size_t buf_size, size_t *read_len,
+ size_t *total_len);
private:
-
int invoke_no_param(unsigned int opcode);
void open_session(void);
void close_session(void);
diff --git a/components/service/fwu/test/fwu_dut/fwu_dut.cpp b/components/service/fwu/test/fwu_dut/fwu_dut.cpp
index f661dd2..0e6f15f 100644
--- a/components/service/fwu/test/fwu_dut/fwu_dut.cpp
+++ b/components/service/fwu/test/fwu_dut/fwu_dut.cpp
@@ -4,39 +4,36 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include "fwu_dut.h"
+
+#include <CppUTest/TestHarness.h>
#include <cassert>
#include <cstring>
#include <string>
-#include <common/endian/le.h>
-#include <service/fwu/test/metadata_checker/metadata_checker_v1.h>
-#include <service/fwu/test/metadata_checker/metadata_checker_v2.h>
-#include <CppUTest/TestHarness.h>
-#include "fwu_dut.h"
+
+#include "common/endian/le.h"
+#include "service/fwu/test/metadata_checker/metadata_checker_v1.h"
+#include "service/fwu/test/metadata_checker/metadata_checker_v2.h"
const char *fwu_dut::VALID_IMAGE_HEADER = "Valid-fw-image-";
-fwu_dut::fwu_dut() :
- m_generated_image_count(0),
- m_metadata_version(1)
+fwu_dut::fwu_dut()
+ : m_generated_image_count(0)
+ , m_metadata_version(1)
{
-
}
-fwu_dut::fwu_dut(unsigned int metadata_version) :
- m_generated_image_count(0),
- m_metadata_version(metadata_version)
+fwu_dut::fwu_dut(unsigned int metadata_version)
+ : m_generated_image_count(0)
+ , m_metadata_version(metadata_version)
{
-
}
fwu_dut::~fwu_dut()
{
-
}
-void fwu_dut::generate_image_data(
- std::vector<uint8_t> *image_data,
- size_t image_size)
+void fwu_dut::generate_image_data(std::vector<uint8_t> *image_data, size_t image_size)
{
std::string fixed_header(VALID_IMAGE_HEADER);
@@ -45,35 +42,29 @@
* - Image size (32-bit)
* - Sequence count (32-bit)
*/
- size_t header_len =
- fixed_header.size() +
- sizeof(uint32_t) +
- sizeof(uint32_t);
+ size_t header_len = fixed_header.size() + sizeof(uint32_t) + sizeof(uint32_t);
/* Reserve space */
image_data->resize(image_size);
if (image_size >= header_len) {
-
/* Prepare image header */
memcpy(image_data->data(), fixed_header.data(), fixed_header.size());
store_u32_le(image_data->data(), fixed_header.size(),
- static_cast<uint32_t>(image_size));
+ static_cast<uint32_t>(image_size));
store_u32_le(image_data->data(), fixed_header.size() + sizeof(uint32_t),
- static_cast<uint32_t>(m_generated_image_count));
+ static_cast<uint32_t>(m_generated_image_count));
/* Fill any remaining space */
if (image_size > header_len) {
-
uint8_t fill_val = static_cast<uint8_t>(m_generated_image_count);
size_t fill_len = image_size - header_len;
memset(image_data->data() + header_len, fill_val, fill_len);
}
} else if (image_size > 0) {
-
/* No room for header so just initialise to fixed value. This will
* fail any image verification check.
*/
@@ -83,25 +74,21 @@
++m_generated_image_count;
}
-void fwu_dut::whole_volume_image_type_uuid(
- unsigned int location_index,
- struct uuid_octets *uuid) const
+void fwu_dut::whole_volume_image_type_uuid(unsigned int location_index,
+ struct uuid_octets *uuid) const
{
- static const char *img_type_guid[] = {
- "cb0faf2f-f498-49fb-9810-cb09dac1184f",
- "e9755079-db61-4d90-8a8a-45727eaa1c6e",
- "d439bc29-83e6-40c7-babe-eb59e415c05e",
- "433a6c93-8bb0-4966-b49c-dc0c56080d19"
- };
+ static const char *img_type_guid[] = { "cb0faf2f-f498-49fb-9810-cb09dac1184f",
+ "e9755079-db61-4d90-8a8a-45727eaa1c6e",
+ "d439bc29-83e6-40c7-babe-eb59e415c05e",
+ "433a6c93-8bb0-4966-b49c-dc0c56080d19" };
- CHECK_TRUE(location_index < sizeof(img_type_guid)/sizeof(char *));
+ CHECK_TRUE(location_index < sizeof(img_type_guid) / sizeof(char *));
uuid_guid_octets_from_canonical(uuid, img_type_guid[location_index]);
}
-metadata_checker *fwu_dut::create_metadata_checker(
- metadata_fetcher *metadata_fetcher,
- unsigned int num_images) const
+metadata_checker *fwu_dut::create_metadata_checker(metadata_fetcher *metadata_fetcher,
+ unsigned int num_images) const
{
if (m_metadata_version == 1)
return new metadata_checker_v1(metadata_fetcher, num_images);
diff --git a/components/service/fwu/test/fwu_dut/fwu_dut.h b/components/service/fwu/test/fwu_dut/fwu_dut.h
index 51f917e..27b27d7 100644
--- a/components/service/fwu/test/fwu_dut/fwu_dut.h
+++ b/components/service/fwu/test/fwu_dut/fwu_dut.h
@@ -8,20 +8,19 @@
#define FWU_DUT_H
#include <vector>
-#include <common/uuid/uuid.h>
-#include <service/fwu/agent/fw_directory.h>
-#include <service/fwu/test/metadata_checker/metadata_checker.h>
-#include <service/fwu/test/fwu_client/fwu_client.h>
+
+#include "common/uuid/uuid.h"
+#include "service/fwu/agent/fw_directory.h"
+#include "service/fwu/test/fwu_client/fwu_client.h"
+#include "service/fwu/test/metadata_checker/metadata_checker.h"
/*
* An fwu_dut represents a device-under-test for the purpose of testing
* firmware update functionality. The fwu_dut presents a common interface
* that decouples test cases from details of the concrete device under test.
*/
-class fwu_dut
-{
+class fwu_dut {
public:
-
fwu_dut();
fwu_dut(unsigned int metadata_version);
virtual ~fwu_dut();
@@ -66,8 +65,7 @@
*
* \return The constructed metadata_checker
*/
- virtual metadata_checker *create_metadata_checker(
- bool is_primary = true) const = 0;
+ virtual metadata_checker *create_metadata_checker(bool is_primary = true) const = 0;
/**
* \brief Factory method to construct a fwu_client
@@ -89,9 +87,7 @@
* \param[in] image_data Image data written to the provided vector
* \param[in] image_size The required image size
*/
- void generate_image_data(
- std::vector<uint8_t> *image_data,
- size_t image_size = 4096);
+ void generate_image_data(std::vector<uint8_t> *image_data, size_t image_size = 4096);
/**
* \brief Returns image type UUIDs
@@ -102,12 +98,10 @@
* \param[in] location_index 0..num_locations-1
* \param[out] uuid Outputs the GUID octets
*/
- virtual void whole_volume_image_type_uuid(
- unsigned int location_index,
- struct uuid_octets *uuid) const;
+ virtual void whole_volume_image_type_uuid(unsigned int location_index,
+ struct uuid_octets *uuid) const;
protected:
-
/**
* \brief Create a metadata_checker for the configured metadata version
*
@@ -118,9 +112,8 @@
* \param[in] metadata_fetcher To fetch the metadata
* \param[in] num_images The expected number of images
*/
- metadata_checker *create_metadata_checker(
- metadata_fetcher *metadata_fetcher,
- unsigned int num_images) const;
+ metadata_checker *create_metadata_checker(metadata_fetcher *metadata_fetcher,
+ unsigned int num_images) const;
/**
* \brief Returns the configured FWU metadata version
@@ -135,7 +128,6 @@
static const char *VALID_IMAGE_HEADER;
private:
-
unsigned int m_generated_image_count;
unsigned int m_metadata_version;
};
diff --git a/components/service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.cpp b/components/service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.cpp
index 15a2eb9..a736bf7 100644
--- a/components/service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.cpp
+++ b/components/service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.cpp
@@ -4,20 +4,19 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <cassert>
-#include <service/fwu/test/fwu_client/remote/remote_fwu_client.h>
-#include <service/fwu/test/metadata_fetcher/client/client_metadata_fetcher.h>
#include "proxy_fwu_dut.h"
-proxy_fwu_dut::proxy_fwu_dut(
- unsigned int num_locations,
- unsigned int metadata_version,
- fwu_dut *remote_dut) :
- fwu_dut(metadata_version),
- m_num_locations(num_locations),
- m_remote_dut(remote_dut)
-{
+#include <cassert>
+#include "service/fwu/test/fwu_client/remote/remote_fwu_client.h"
+#include "service/fwu/test/metadata_fetcher/client/client_metadata_fetcher.h"
+
+proxy_fwu_dut::proxy_fwu_dut(unsigned int num_locations, unsigned int metadata_version,
+ fwu_dut *remote_dut)
+ : fwu_dut(metadata_version)
+ , m_num_locations(num_locations)
+ , m_remote_dut(remote_dut)
+{
}
proxy_fwu_dut::~proxy_fwu_dut()
diff --git a/components/service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.h b/components/service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.h
index 7fe0a81..d334fe9 100644
--- a/components/service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.h
+++ b/components/service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.h
@@ -7,7 +7,7 @@
#ifndef PROXY_FWU_DUT_H
#define PROXY_FWU_DUT_H
-#include <service/fwu/test/fwu_dut/fwu_dut.h>
+#include "service/fwu/test/fwu_dut/fwu_dut.h"
/*
* A proxy_fwu_dut is an fwu_dut that acts as a proxy for a full fwu_dut
@@ -15,10 +15,8 @@
* integrations where the fwu service is being accessed via RPC e.g. from
* Nwd.
*/
-class proxy_fwu_dut : public fwu_dut
-{
+class proxy_fwu_dut : public fwu_dut {
public:
-
/**
* \brief proxy_fwu_dut constructor
*
@@ -26,10 +24,8 @@
* \param[in] metadata_version FWU metadata version supported by bootloader
* \param[in] remote_dut The associated remote fwu dut
*/
- proxy_fwu_dut(
- unsigned int num_locations,
- unsigned int metadata_version,
- fwu_dut *remote_dut);
+ proxy_fwu_dut(unsigned int num_locations, unsigned int metadata_version,
+ fwu_dut *remote_dut);
~proxy_fwu_dut();
@@ -42,7 +38,6 @@
fwu_client *create_fwu_client(void);
private:
-
unsigned int m_num_locations;
fwu_dut *m_remote_dut;
};
diff --git a/components/service/fwu/test/fwu_dut/sim/sim_fwu_dut.cpp b/components/service/fwu/test/fwu_dut/sim/sim_fwu_dut.cpp
index 6f2a21b..260cb65 100644
--- a/components/service/fwu/test/fwu_dut/sim/sim_fwu_dut.cpp
+++ b/components/service/fwu/test/fwu_dut/sim/sim_fwu_dut.cpp
@@ -4,51 +4,49 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include "sim_fwu_dut.h"
+
+#include <CppUTest/TestHarness.h>
#include <cassert>
#include <cstring>
#include <sstream>
-#include <CppUTest/TestHarness.h>
-#include <common/endian/le.h>
-#include <media/volume/index/volume_index.h>
-#include <media/disk/guid.h>
-#include <service/discovery/provider/discovery_provider.h>
-#include <service/discovery/provider/serializer/packed-c/packedc_discovery_provider_serializer.h>
-#include <service/fwu/installer/installer_index.h>
-#include <service/fwu/fw_store/banked/volume_id.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.h>
-#include <service/fwu/inspector/direct/direct_fw_inspector.h>
-#include <service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.h>
-#include <service/fwu/test/fwu_client/direct/direct_fwu_client.h>
-#include <service/fwu/test/metadata_fetcher/volume/volume_metadata_fetcher.h>
-#include "sim_fwu_dut.h"
-sim_fwu_dut::sim_fwu_dut(
- unsigned int num_locations,
- unsigned int metadata_version,
- bool allow_partial_updates) :
- fwu_dut(metadata_version),
- m_is_booted(false),
- m_is_first_boot(true),
- m_boot_info(),
- m_metadata_checker(NULL),
- m_num_locations(num_locations),
- m_service_iface(NULL),
- m_fw_flash(),
- m_partitioned_block_store(),
- m_block_store(NULL),
- m_fw_volume_used_count(0),
- m_fw_volume_pool(),
- m_raw_installer_used_count(0),
- m_raw_installer_pool(),
- m_copy_installer_used_count(0),
- m_copy_installer_pool(),
- m_update_agent(),
- m_fw_store(),
- m_fwu_provider()
+#include "common/endian/le.h"
+#include "media/disk/guid.h"
+#include "media/volume/index/volume_index.h"
+#include "service/discovery/provider/discovery_provider.h"
+#include "service/discovery/provider/serializer/packed-c/packedc_discovery_provider_serializer.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.h"
+#include "service/fwu/fw_store/banked/volume_id.h"
+#include "service/fwu/inspector/direct/direct_fw_inspector.h"
+#include "service/fwu/installer/installer_index.h"
+#include "service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.h"
+#include "service/fwu/test/fwu_client/direct/direct_fwu_client.h"
+#include "service/fwu/test/metadata_fetcher/volume/volume_metadata_fetcher.h"
+
+sim_fwu_dut::sim_fwu_dut(unsigned int num_locations, unsigned int metadata_version,
+ bool allow_partial_updates)
+ : fwu_dut(metadata_version)
+ , m_is_booted(false)
+ , m_is_first_boot(true)
+ , m_boot_info()
+ , m_metadata_checker(NULL)
+ , m_num_locations(num_locations)
+ , m_service_iface(NULL)
+ , m_fw_flash()
+ , m_partitioned_block_store()
+ , m_block_store(NULL)
+ , m_fw_volume_used_count(0)
+ , m_fw_volume_pool()
+ , m_raw_installer_used_count(0)
+ , m_raw_installer_pool()
+ , m_copy_installer_used_count(0)
+ , m_copy_installer_pool()
+ , m_update_agent()
+ , m_fw_store()
+ , m_fwu_provider()
{
- m_boot_info = {0};
-
volume_index_init();
installer_index_init();
@@ -67,19 +65,14 @@
memset(&m_update_agent, 0, sizeof(m_update_agent));
m_update_agent.state = FWU_STATE_DEINITIALZED;
- m_service_iface = fwu_provider_init(
- &m_fwu_provider,
- &m_update_agent);
+ m_service_iface = fwu_provider_init(&m_fwu_provider, &m_update_agent);
- fwu_provider_register_serializer(
- &m_fwu_provider,
- TS_RPC_ENCODING_PACKED_C,
- packedc_fwu_provider_serializer_instance());
+ fwu_provider_register_serializer(&m_fwu_provider, TS_RPC_ENCODING_PACKED_C,
+ packedc_fwu_provider_serializer_instance());
- discovery_provider_register_serializer(
- &m_fwu_provider.discovery_provider,
- TS_RPC_ENCODING_PACKED_C,
- packedc_discovery_provider_serializer_instance());
+ discovery_provider_register_serializer(&m_fwu_provider.discovery_provider,
+ TS_RPC_ENCODING_PACKED_C,
+ packedc_discovery_provider_serializer_instance());
m_metadata_checker = create_metadata_checker();
}
@@ -107,25 +100,20 @@
return;
if (m_is_first_boot) {
-
/* First boot where valid FWU metadata does not yet exist. */
- m_boot_info.boot_index =
- m_boot_info.active_index =
- m_boot_info.previous_active_index = FIRST_BOOT_BANK_INDEX;
+ m_boot_info.boot_index = m_boot_info.active_index =
+ m_boot_info.previous_active_index = FIRST_BOOT_BANK_INDEX;
m_is_first_boot = false;
} else {
-
/* On subsequent boots, mimic the boot loader and derive boot
* info from the FWU metadata.
*/
- m_metadata_checker->get_active_indices(
- &m_boot_info.active_index,
- &m_boot_info.previous_active_index);
+ m_metadata_checker->get_active_indices(&m_boot_info.active_index,
+ &m_boot_info.previous_active_index);
- m_boot_info.boot_index = (from_active_bank) ?
- m_boot_info.active_index :
- m_boot_info.previous_active_index;
+ m_boot_info.boot_index = (from_active_bank) ? m_boot_info.active_index :
+ m_boot_info.previous_active_index;
}
/* Now mimic boot loader image verification */
@@ -137,11 +125,8 @@
int status = banked_fw_store_init(&m_fw_store, select_metadata_serializer());
LONGS_EQUAL(0, status);
- status = update_agent_init(
- &m_update_agent,
- m_boot_info.boot_index,
- direct_fw_inspector_inspect,
- &m_fw_store);
+ status = update_agent_init(&m_update_agent, m_boot_info.boot_index,
+ direct_fw_inspector_inspect, &m_fw_store);
LONGS_EQUAL(0, status);
m_is_booted = true;
@@ -188,46 +173,35 @@
return new direct_fwu_client(&m_update_agent);
}
-void sim_fwu_dut::fw_partition_guid(
- unsigned int location_index,
- unsigned int bank_index,
- struct uuid_octets *uuid) const
+void sim_fwu_dut::fw_partition_guid(unsigned int location_index, unsigned int bank_index,
+ struct uuid_octets *uuid) const
{
static const char *partition_guid[MAX_LOCATIONS][BANK_SCHEME_NUM_BANKS] = {
- {"318757ec-82a0-48ce-a0d9-dfdeee6847a9",
- "3455a361-4074-42a3-ac0f-0e217c58494a"},
- {"5feb0dff-3d4b-42ab-9635-c112cf641f2b",
- "d75c1efc-6c8c-458a-aa72-41810d1d8a99"},
- {"0558ce63-db89-40ad-8039-1fafeb057fc8",
- "f07f1be5-077d-487f-9bd9-1ae33ed580e9"},
- {"3b00979c-e776-4e79-b675-f78681b4cce3",
- "3de167ca-5e8c-4f05-9f87-e0c6a57538a5"}
+ { "318757ec-82a0-48ce-a0d9-dfdeee6847a9", "3455a361-4074-42a3-ac0f-0e217c58494a" },
+ { "5feb0dff-3d4b-42ab-9635-c112cf641f2b", "d75c1efc-6c8c-458a-aa72-41810d1d8a99" },
+ { "0558ce63-db89-40ad-8039-1fafeb057fc8", "f07f1be5-077d-487f-9bd9-1ae33ed580e9" },
+ { "3b00979c-e776-4e79-b675-f78681b4cce3", "3de167ca-5e8c-4f05-9f87-e0c6a57538a5" }
};
CHECK_TRUE(location_index < MAX_LOCATIONS);
CHECK_TRUE(bank_index < BANK_SCHEME_NUM_BANKS);
- uuid_guid_octets_from_canonical(uuid,
- partition_guid[location_index][bank_index]);
+ uuid_guid_octets_from_canonical(uuid, partition_guid[location_index][bank_index]);
}
-void sim_fwu_dut::fwu_metadata_partition_guid(
- bool is_primary,
- struct uuid_octets *uuid) const
+void sim_fwu_dut::fwu_metadata_partition_guid(bool is_primary, struct uuid_octets *uuid) const
{
if (is_primary)
uuid_guid_octets_from_canonical(uuid,
- DISK_GUID_UNIQUE_PARTITION_PRIMARY_FWU_METADATA);
+ DISK_GUID_UNIQUE_PARTITION_PRIMARY_FWU_METADATA);
else
uuid_guid_octets_from_canonical(uuid,
- DISK_GUID_UNIQUE_PARTITION_BACKUP_FWU_METADATA);
+ DISK_GUID_UNIQUE_PARTITION_BACKUP_FWU_METADATA);
}
-void sim_fwu_dut::disk_guid(
- struct uuid_octets *uuid) const
+void sim_fwu_dut::disk_guid(struct uuid_octets *uuid) const
{
- uuid_guid_octets_from_canonical(uuid,
- "da92a93d-91d3-4b74-9102-7b45c21fe7db");
+ uuid_guid_octets_from_canonical(uuid, "da92a93d-91d3-4b74-9102-7b45c21fe7db");
}
void sim_fwu_dut::construct_storage(unsigned int num_locations)
@@ -242,18 +216,11 @@
/* Construct the 'flash' */
struct block_store *flash_store = ram_block_store_init(
- &m_fw_flash,
- &flash_store_guid,
- required_storage_blocks,
- FLASH_BLOCK_SIZE);
+ &m_fw_flash, &flash_store_guid, required_storage_blocks, FLASH_BLOCK_SIZE);
/* Stack a partitioned_block_store over the flash */
- m_block_store = partitioned_block_store_init(
- &m_partitioned_block_store,
- 0,
- &flash_store_guid,
- flash_store,
- NULL);
+ m_block_store = partitioned_block_store_init(&m_partitioned_block_store, 0,
+ &flash_store_guid, flash_store, NULL);
/* Add all disk partitions */
unsigned int lba = 0;
@@ -261,26 +228,21 @@
/* First the primary fwu metadata partition */
fwu_metadata_partition_guid(true, &partition_guid);
- bool is_added = partitioned_block_store_add_partition(
- &m_partitioned_block_store,
- &partition_guid,
- lba, lba + METADATA_VOLUME_NUM_BLOCKS - 1,
- 0, NULL);
+ bool is_added = partitioned_block_store_add_partition(&m_partitioned_block_store,
+ &partition_guid, lba,
+ lba + METADATA_VOLUME_NUM_BLOCKS - 1,
+ 0, NULL);
CHECK_TRUE(is_added);
lba += METADATA_VOLUME_NUM_BLOCKS;
/* Add partitions for each fw location */
for (unsigned int location = 0; location < num_locations; location++) {
-
for (unsigned int bank = 0; bank < BANK_SCHEME_NUM_BANKS; bank++) {
-
fw_partition_guid(location, bank, &partition_guid);
is_added = partitioned_block_store_add_partition(
- &m_partitioned_block_store,
- &partition_guid,
- lba, lba + FW_VOLUME_NUM_BLOCKS - 1,
- 0, NULL);
+ &m_partitioned_block_store, &partition_guid, lba,
+ lba + FW_VOLUME_NUM_BLOCKS - 1, 0, NULL);
CHECK_TRUE(is_added);
lba += FW_VOLUME_NUM_BLOCKS;
@@ -289,11 +251,10 @@
/* Finally, add the backup fwu metadata partition */
fwu_metadata_partition_guid(false, &partition_guid);
- is_added = partitioned_block_store_add_partition(
- &m_partitioned_block_store,
- &partition_guid,
- lba, lba + METADATA_VOLUME_NUM_BLOCKS - 1,
- 0, NULL);
+ is_added = partitioned_block_store_add_partition(&m_partitioned_block_store,
+ &partition_guid, lba,
+ lba + METADATA_VOLUME_NUM_BLOCKS - 1, 0,
+ NULL);
CHECK_TRUE(is_added);
}
@@ -313,8 +274,8 @@
/* Construct volume for primary fwu metadata access */
fwu_metadata_partition_guid(true, &partition_guid);
- status = block_volume_init(&m_fw_volume_pool[m_fw_volume_used_count],
- m_block_store, &partition_guid, &volume);
+ status = block_volume_init(&m_fw_volume_pool[m_fw_volume_used_count], m_block_store,
+ &partition_guid, &volume);
LONGS_EQUAL(0, status);
CHECK_TRUE(volume);
@@ -325,8 +286,8 @@
/* Construct volume for backup fwu metadata access */
fwu_metadata_partition_guid(false, &partition_guid);
- status = block_volume_init(&m_fw_volume_pool[m_fw_volume_used_count],
- m_block_store, &partition_guid, &volume);
+ status = block_volume_init(&m_fw_volume_pool[m_fw_volume_used_count], m_block_store,
+ &partition_guid, &volume);
LONGS_EQUAL(0, status);
CHECK_TRUE(volume);
@@ -336,19 +297,16 @@
/* Construct volumes for each fw storage partition */
for (unsigned int location = 0; location < num_locations; location++) {
-
for (unsigned int bank = 0; bank < BANK_SCHEME_NUM_BANKS; bank++) {
-
fw_partition_guid(location, bank, &partition_guid);
status = block_volume_init(&m_fw_volume_pool[m_fw_volume_used_count],
- m_block_store, &partition_guid, &volume);
+ m_block_store, &partition_guid, &volume);
LONGS_EQUAL(0, status);
CHECK_TRUE(volume);
- status = volume_index_add(
- banked_volume_id(location, banked_usage_id(bank)),
- volume);
+ status = volume_index_add(banked_volume_id(location, banked_usage_id(bank)),
+ volume);
LONGS_EQUAL(0, status);
++m_fw_volume_used_count;
}
@@ -363,12 +321,9 @@
m_fw_volume_used_count = 0;
}
-void sim_fwu_dut::construct_installers(
- unsigned int num_locations,
- bool allow_partial_updates)
+void sim_fwu_dut::construct_installers(unsigned int num_locations, bool allow_partial_updates)
{
for (unsigned int location = 0; location < num_locations; location++) {
-
/* Provides a raw and optional copy installer per location. The raw_installer
* is used for installing whole volume images using an externally streamed
* image while the copy installer is used to copy the previously good whole
@@ -390,7 +345,6 @@
++m_raw_installer_used_count;
if (allow_partial_updates) {
-
struct copy_installer *copy_installer =
&m_copy_installer_pool[m_copy_installer_used_count];
@@ -420,7 +374,6 @@
* a device with factory programmed flash.
*/
for (unsigned int location = 0; location < num_locations; location++) {
-
struct volume *volume = NULL;
size_t len_written = 0;
@@ -437,9 +390,8 @@
status = volume_open(volume);
LONGS_EQUAL(0, status);
- status = volume_write(volume,
- (uintptr_t)image_data.data(), image_data.size(),
- &len_written);
+ status = volume_write(volume, (uintptr_t)image_data.data(), image_data.size(),
+ &len_written);
LONGS_EQUAL(0, status);
UNSIGNED_LONGS_EQUAL(image_data.size(), len_written);
@@ -451,12 +403,10 @@
void sim_fwu_dut::verify_boot_images(unsigned int boot_index)
{
for (unsigned int location = 0; location < m_num_locations; location++) {
-
struct volume *volume = NULL;
int status = volume_index_find(
- banked_volume_id(location, banked_usage_id(boot_index)),
- &volume);
+ banked_volume_id(location, banked_usage_id(boot_index)), &volume);
LONGS_EQUAL(0, status);
CHECK_TRUE(volume);
@@ -486,8 +436,7 @@
return NULL;
}
-void sim_fwu_dut::verify_image(
- struct volume *volume)
+void sim_fwu_dut::verify_image(struct volume *volume)
{
std::string fixed_header(VALID_IMAGE_HEADER);
size_t header_len = fixed_header.size() + sizeof(uint32_t) + sizeof(uint32_t);
@@ -496,7 +445,7 @@
uint8_t header_buf[header_len];
size_t total_bytes_read = 0;
- int status = volume_read(volume, (uintptr_t)header_buf, header_len, &total_bytes_read);
+ int status = volume_read(volume, (uintptr_t)header_buf, header_len, &total_bytes_read);
LONGS_EQUAL(0, status);
CHECK_TRUE(total_bytes_read == header_len);
@@ -512,14 +461,13 @@
uint8_t expected_fill_val = static_cast<uint8_t>(seq_num);
while (total_bytes_read < image_size) {
-
uint8_t read_buf[1024];
size_t bytes_read = 0;
size_t bytes_remaining = image_size - total_bytes_read;
- size_t bytes_to_read = (bytes_remaining > sizeof(read_buf)) ?
- sizeof(read_buf) : bytes_remaining;
+ size_t bytes_to_read = (bytes_remaining > sizeof(read_buf)) ? sizeof(read_buf) :
+ bytes_remaining;
- status = volume_read(volume, (uintptr_t)read_buf, bytes_to_read, &bytes_read);
+ status = volume_read(volume, (uintptr_t)read_buf, bytes_to_read, &bytes_read);
LONGS_EQUAL(0, status);
UNSIGNED_LONGS_EQUAL(bytes_to_read, bytes_read);
diff --git a/components/service/fwu/test/fwu_dut/sim/sim_fwu_dut.h b/components/service/fwu/test/fwu_dut/sim/sim_fwu_dut.h
index b3b3f05..aa6e75b 100644
--- a/components/service/fwu/test/fwu_dut/sim/sim_fwu_dut.h
+++ b/components/service/fwu/test/fwu_dut/sim/sim_fwu_dut.h
@@ -7,22 +7,23 @@
#ifndef SIM_FWU_DUT_H
#define SIM_FWU_DUT_H
-#include <string>
#include <cstddef>
-#include <common/uuid/uuid.h>
-#include <media/volume/block_volume/block_volume.h>
-#include <service/block_storage/block_store/device/ram/ram_block_store.h>
-#include <service/block_storage/block_store/partitioned/partitioned_block_store.h>
-#include <service/fwu/agent/update_agent.h>
-#include <service/fwu/agent/fw_directory.h>
-#include <service/fwu/fw_store/banked/banked_fw_store.h>
-#include <service/fwu/fw_store/banked/bank_scheme.h>
-#include <service/fwu/installer/raw/raw_installer.h>
-#include <service/fwu/installer/copy/copy_installer.h>
-#include <service/fwu/provider/fwu_provider.h>
-#include <service/fwu/test/metadata_checker/metadata_checker.h>
-#include <service/fwu/test/fwu_client/fwu_client.h>
-#include <service/fwu/test/fwu_dut/fwu_dut.h>
+#include <string>
+
+#include "common/uuid/uuid.h"
+#include "media/volume/block_volume/block_volume.h"
+#include "service/block_storage/block_store/device/ram/ram_block_store.h"
+#include "service/block_storage/block_store/partitioned/partitioned_block_store.h"
+#include "service/fwu/agent/fw_directory.h"
+#include "service/fwu/agent/update_agent.h"
+#include "service/fwu/fw_store/banked/bank_scheme.h"
+#include "service/fwu/fw_store/banked/banked_fw_store.h"
+#include "service/fwu/installer/copy/copy_installer.h"
+#include "service/fwu/installer/raw/raw_installer.h"
+#include "service/fwu/provider/fwu_provider.h"
+#include "service/fwu/test/fwu_client/fwu_client.h"
+#include "service/fwu/test/fwu_dut/fwu_dut.h"
+#include "service/fwu/test/metadata_checker/metadata_checker.h"
/*
* An sim_fwu_dut is an aggregate of components that simulates
@@ -32,10 +33,8 @@
* realizations. As much as possible, the set of components that forms
* the DUT is the same as what is used in real deployments.
*/
-class sim_fwu_dut : public fwu_dut
-{
+class sim_fwu_dut : public fwu_dut {
public:
-
/**
* \brief sim_fwu_dut constructor
*
@@ -43,10 +42,8 @@
* \param[in] metadata_version FWU metadata version supported by bootloader
* \param[in] allow_partial_updates True if updating a subset of locations is permitted
*/
- sim_fwu_dut(
- unsigned int num_locations,
- unsigned int metadata_version,
- bool allow_partial_updates = false);
+ sim_fwu_dut(unsigned int num_locations, unsigned int metadata_version,
+ bool allow_partial_updates = false);
~sim_fwu_dut();
@@ -61,7 +58,6 @@
struct rpc_interface *get_service_interface(void);
private:
-
/* Maximum locations supported */
static const unsigned int MAX_LOCATIONS = 4;
@@ -76,17 +72,12 @@
static const size_t FW_VOLUME_NUM_BLOCKS = 20;
static const size_t METADATA_VOLUME_NUM_BLOCKS = 4;
- void fw_partition_guid(
- unsigned int location_index,
- unsigned int bank_index,
- struct uuid_octets *uuid) const;
+ void fw_partition_guid(unsigned int location_index, unsigned int bank_index,
+ struct uuid_octets *uuid) const;
- void fwu_metadata_partition_guid(
- bool is_primary,
- struct uuid_octets *uuid) const;
+ void fwu_metadata_partition_guid(bool is_primary, struct uuid_octets *uuid) const;
- void disk_guid(
- struct uuid_octets *uuid) const;
+ void disk_guid(struct uuid_octets *uuid) const;
void construct_storage(unsigned int num_locations);
void destroy_storage(void);
@@ -118,8 +109,8 @@
/* Pools of volume objects */
size_t m_fw_volume_used_count;
- struct block_volume m_fw_volume_pool[
- MAX_LOCATIONS * BANK_SCHEME_NUM_BANKS + FWU_METADATA_VOLUMES];
+ struct block_volume
+ m_fw_volume_pool[MAX_LOCATIONS * BANK_SCHEME_NUM_BANKS + FWU_METADATA_VOLUMES];
/* Pools of different types of installer */
size_t m_raw_installer_used_count;
diff --git a/components/service/fwu/test/fwu_dut_factory/fwu_dut_factory.h b/components/service/fwu/test/fwu_dut_factory/fwu_dut_factory.h
index aac99a7..3876267 100644
--- a/components/service/fwu/test/fwu_dut_factory/fwu_dut_factory.h
+++ b/components/service/fwu/test/fwu_dut_factory/fwu_dut_factory.h
@@ -7,7 +7,7 @@
#ifndef FWU_DUT_FACTORY_H
#define FWU_DUT_FACTORY_H
-#include <service/fwu/test/fwu_dut/fwu_dut.h>
+#include "service/fwu/test/fwu_dut/fwu_dut.h"
/*
* A factory for constructing fwu_dut objects. To allow for different test
@@ -15,10 +15,8 @@
* possible. The fwu_dut_factory provides a common interface to allow test
* cases that depend on a fwu_dut to be reused in different deployments.
*/
-class fwu_dut_factory
-{
+class fwu_dut_factory {
public:
-
/**
* \brief Factory method to construct concrete fwu_dut objects
*
@@ -27,12 +25,9 @@
*
* \return The constructed fwu_dut
*/
- static fwu_dut *create(
- unsigned int num_locations,
- bool allow_partial_updates = false);
+ static fwu_dut *create(unsigned int num_locations, bool allow_partial_updates = false);
private:
-
static const unsigned int FWU_METADATA_VERSION = 2;
};
diff --git a/components/service/fwu/test/fwu_dut_factory/remote/fwu_dut_factory.cpp b/components/service/fwu/test/fwu_dut_factory/remote/fwu_dut_factory.cpp
index 6246879..16a3ea0 100644
--- a/components/service/fwu/test/fwu_dut_factory/remote/fwu_dut_factory.cpp
+++ b/components/service/fwu/test/fwu_dut_factory/remote/fwu_dut_factory.cpp
@@ -4,8 +4,9 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.h>
-#include <service/fwu/test/fwu_dut_factory/fwu_dut_factory.h>
+#include "service/fwu/test/fwu_dut_factory/fwu_dut_factory.h"
+
+#include "service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.h"
/*
* A factory for constructing fwu_dut objects for remote access to
@@ -13,15 +14,12 @@
* been configured using its own mechanism, configuration parameters
* passed on 'create' are ignored.
*/
-fwu_dut *fwu_dut_factory::create(
- unsigned int num_locations,
- bool allow_partial_updates)
+fwu_dut *fwu_dut_factory::create(unsigned int num_locations, bool allow_partial_updates)
{
/* Determined by FWU service provider configuration */
(void)num_locations;
(void)allow_partial_updates;
/* Construct a proxy_fwu_dut with no explicit link to a backend fwu_dut */
- return new proxy_fwu_dut(num_locations,
- FWU_METADATA_VERSION, NULL);
+ return new proxy_fwu_dut(num_locations, FWU_METADATA_VERSION, NULL);
}
\ No newline at end of file
diff --git a/components/service/fwu/test/fwu_dut_factory/remote_sim/fwu_dut_factory.cpp b/components/service/fwu/test/fwu_dut_factory/remote_sim/fwu_dut_factory.cpp
index bbd2f45..63e6dd8 100644
--- a/components/service/fwu/test/fwu_dut_factory/remote_sim/fwu_dut_factory.cpp
+++ b/components/service/fwu/test/fwu_dut_factory/remote_sim/fwu_dut_factory.cpp
@@ -4,10 +4,11 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <service/fwu/test/fwu_dut/sim/sim_fwu_dut.h>
-#include <service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.h>
-#include <service/fwu/test/fwu_dut_factory/fwu_dut_factory.h>
-#include <service/locator/standalone/services/fwu/fwu_service_context.h>
+#include "service/fwu/test/fwu_dut_factory/fwu_dut_factory.h"
+
+#include "service/fwu/test/fwu_dut/proxy/proxy_fwu_dut.h"
+#include "service/fwu/test/fwu_dut/sim/sim_fwu_dut.h"
+#include "service/locator/standalone/services/fwu/fwu_service_context.h"
/*
* A factory for constructing fwu_dut objects for remote access to
@@ -18,21 +19,18 @@
* cases. The sim_fwu_dut forms the backend for the standalone
* fwu service.
*/
-fwu_dut *fwu_dut_factory::create(
- unsigned int num_locations,
- bool allow_partial_updates)
+fwu_dut *fwu_dut_factory::create(unsigned int num_locations, bool allow_partial_updates)
{
/* Construct and set the simulated dut that provides the configured
* device and fwu service provider.
*/
- sim_fwu_dut *sim_dut = new sim_fwu_dut(num_locations,
- FWU_METADATA_VERSION, allow_partial_updates);
+ sim_fwu_dut *sim_dut =
+ new sim_fwu_dut(num_locations, FWU_METADATA_VERSION, allow_partial_updates);
fwu_service_context_set_provider(sim_dut->get_service_interface());
/* Construct a proxy_fwu_dut chained to the sim_fwu_dut. On deletion,
* the proxy_fwu_dut deletes the associated sim_fwu_dut.
*/
- return new proxy_fwu_dut(num_locations,
- FWU_METADATA_VERSION, sim_dut);
+ return new proxy_fwu_dut(num_locations, FWU_METADATA_VERSION, sim_dut);
}
\ No newline at end of file
diff --git a/components/service/fwu/test/fwu_dut_factory/sim/fwu_dut_factory.cpp b/components/service/fwu/test/fwu_dut_factory/sim/fwu_dut_factory.cpp
index a4e3799..b2ee1d4 100644
--- a/components/service/fwu/test/fwu_dut_factory/sim/fwu_dut_factory.cpp
+++ b/components/service/fwu/test/fwu_dut_factory/sim/fwu_dut_factory.cpp
@@ -4,8 +4,9 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <service/fwu/test/fwu_dut/sim/sim_fwu_dut.h>
-#include <service/fwu/test/fwu_dut_factory/fwu_dut_factory.h>
+#include "service/fwu/test/fwu_dut_factory/fwu_dut_factory.h"
+
+#include "service/fwu/test/fwu_dut/sim/sim_fwu_dut.h"
/*
* A factory for constructing sim_fwu_dut objects. A sim_fwu_dut is an
@@ -13,10 +14,7 @@
* component level testing. The sim_fwu_dut simulates the role of the
* bootloader and device shutdown and boot-up.
*/
-fwu_dut *fwu_dut_factory::create(
- unsigned int num_locations,
- bool allow_partial_updates)
+fwu_dut *fwu_dut_factory::create(unsigned int num_locations, bool allow_partial_updates)
{
- return new sim_fwu_dut(num_locations,
- FWU_METADATA_VERSION, allow_partial_updates);
+ return new sim_fwu_dut(num_locations, FWU_METADATA_VERSION, allow_partial_updates);
}
\ No newline at end of file
diff --git a/components/service/fwu/test/image_directory_checker/image_directory_checker.cpp b/components/service/fwu/test/image_directory_checker/image_directory_checker.cpp
index 6d4680d..49610c1 100644
--- a/components/service/fwu/test/image_directory_checker/image_directory_checker.cpp
+++ b/components/service/fwu/test/image_directory_checker/image_directory_checker.cpp
@@ -4,16 +4,18 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include "image_directory_checker.h"
+
#include <cassert>
#include <cstdlib>
#include <cstring>
-#include <common/uuid/uuid.h>
-#include "image_directory_checker.h"
-image_directory_checker::image_directory_checker() :
- m_buf(NULL),
- m_buf_size(0),
- m_total_read_len(0)
+#include "common/uuid/uuid.h"
+
+image_directory_checker::image_directory_checker()
+ : m_buf(NULL)
+ , m_buf_size(0)
+ , m_total_read_len(0)
{
alloc_buffer();
}
@@ -23,8 +25,7 @@
delete[] m_buf;
}
-int image_directory_checker::fetch_image_directory(
- fwu_client *fwu_client)
+int image_directory_checker::fetch_image_directory(fwu_client *fwu_client)
{
int status = 0;
uint32_t stream_handle = 0;
@@ -41,23 +42,18 @@
m_total_read_len = 0;
do {
-
size_t data_len_read = 0;
size_t requested_read_len = m_buf_size - m_total_read_len;
- status = fwu_client->read_stream(
- stream_handle,
- &m_buf[m_total_read_len],
- requested_read_len,
- &data_len_read,
- &reported_total_len);
+ status = fwu_client->read_stream(stream_handle, &m_buf[m_total_read_len],
+ requested_read_len, &data_len_read,
+ &reported_total_len);
m_total_read_len += data_len_read;
assert(m_total_read_len <= reported_total_len);
if (m_total_read_len == reported_total_len) {
-
/* Read all the data */
break;
}
@@ -74,7 +70,6 @@
size_t num_images = 0;
if (m_total_read_len >= offsetof(struct ts_fwu_image_directory, img_info_entry)) {
-
const struct ts_fwu_image_directory *header =
(const struct ts_fwu_image_directory *)m_buf;
@@ -84,14 +79,11 @@
return num_images;
}
-bool image_directory_checker::is_contents_equal(
- const image_directory_checker &rhs) const
+bool image_directory_checker::is_contents_equal(const image_directory_checker &rhs) const
{
- return
- (this->m_total_read_len > 0) &&
- (this->m_total_read_len == rhs.m_total_read_len) &&
- (this->m_buf && rhs.m_buf) &&
- (memcmp(this->m_buf, rhs.m_buf, this->m_total_read_len) == 0);
+ return (this->m_total_read_len > 0) && (this->m_total_read_len == rhs.m_total_read_len) &&
+ (this->m_buf && rhs.m_buf) &&
+ (memcmp(this->m_buf, rhs.m_buf, this->m_total_read_len) == 0);
}
const struct ts_fwu_image_directory *image_directory_checker::get_header(void) const
@@ -104,23 +96,20 @@
return header;
}
-const struct ts_fwu_image_info_entry *image_directory_checker::find_entry(
- const struct uuid_octets *img_type_uuid) const
+const struct ts_fwu_image_info_entry *
+image_directory_checker::find_entry(const struct uuid_octets *img_type_uuid) const
{
const struct ts_fwu_image_info_entry *found_entry = NULL;
const struct ts_fwu_image_directory *header = get_header();
if (header) {
-
unsigned int index = 0;
while ((const uint8_t *)&header->img_info_entry[index + 1] <=
- &m_buf[m_total_read_len]) {
-
+ &m_buf[m_total_read_len]) {
if (uuid_is_equal(img_type_uuid->octets,
- header->img_info_entry[index].img_type_uuid)) {
-
+ header->img_info_entry[index].img_type_uuid)) {
found_entry = &header->img_info_entry[index];
break;
}
@@ -134,9 +123,8 @@
void image_directory_checker::alloc_buffer(void)
{
- m_buf_size =
- offsetof(struct ts_fwu_image_directory, img_info_entry) +
- MAX_IMAGES * sizeof(ts_fwu_image_info_entry);
+ m_buf_size = offsetof(struct ts_fwu_image_directory, img_info_entry) +
+ MAX_IMAGES * sizeof(ts_fwu_image_info_entry);
m_buf = new uint8_t[m_buf_size];
assert(m_buf);
diff --git a/components/service/fwu/test/image_directory_checker/image_directory_checker.h b/components/service/fwu/test/image_directory_checker/image_directory_checker.h
index 39dfd25..a8594a3 100644
--- a/components/service/fwu/test/image_directory_checker/image_directory_checker.h
+++ b/components/service/fwu/test/image_directory_checker/image_directory_checker.h
@@ -9,18 +9,17 @@
#include <cstddef>
#include <cstdint>
-#include <common/uuid/uuid.h>
-#include <service/fwu/test/fwu_client/fwu_client.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
+
+#include "common/uuid/uuid.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+#include "service/fwu/test/fwu_client/fwu_client.h"
/*
* Provides check methods for checking the contents of the image
* directory fetched from the update agent.
*/
-class image_directory_checker
-{
+class image_directory_checker {
public:
-
image_directory_checker();
~image_directory_checker();
@@ -31,11 +30,10 @@
bool is_contents_equal(const image_directory_checker &rhs) const;
const struct ts_fwu_image_directory *get_header(void) const;
- const struct ts_fwu_image_info_entry *find_entry(
- const struct uuid_octets *img_type_uuid) const;
+ const struct ts_fwu_image_info_entry *
+ find_entry(const struct uuid_octets *img_type_uuid) const;
private:
-
static const size_t MAX_IMAGES = 50;
void alloc_buffer(void);
diff --git a/components/service/fwu/test/metadata_checker/metadata_checker.cpp b/components/service/fwu/test/metadata_checker/metadata_checker.cpp
index 618f97e..0f0186f 100644
--- a/components/service/fwu/test/metadata_checker/metadata_checker.cpp
+++ b/components/service/fwu/test/metadata_checker/metadata_checker.cpp
@@ -4,15 +4,14 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <CppUTest/TestHarness.h>
#include "metadata_checker.h"
-metadata_checker::metadata_checker(
- size_t max_metadata_size,
- metadata_fetcher *metadata_fetcher) :
- m_metadata_fetcher(metadata_fetcher),
- m_meta_buf(NULL),
- m_meta_buf_size(max_metadata_size)
+#include <CppUTest/TestHarness.h>
+
+metadata_checker::metadata_checker(size_t max_metadata_size, metadata_fetcher *metadata_fetcher)
+ : m_metadata_fetcher(metadata_fetcher)
+ , m_meta_buf(NULL)
+ , m_meta_buf_size(max_metadata_size)
{
m_metadata_fetcher->open();
@@ -24,7 +23,7 @@
{
m_metadata_fetcher->close();
- delete [] m_meta_buf;
+ delete[] m_meta_buf;
m_meta_buf = NULL;
delete m_metadata_fetcher;
diff --git a/components/service/fwu/test/metadata_checker/metadata_checker.h b/components/service/fwu/test/metadata_checker/metadata_checker.h
index 765897a..5c0c7bd 100644
--- a/components/service/fwu/test/metadata_checker/metadata_checker.h
+++ b/components/service/fwu/test/metadata_checker/metadata_checker.h
@@ -8,7 +8,8 @@
#define METADATA_CHECKER_H
#include <cstdint>
-#include <service/fwu/test/metadata_fetcher/metadata_fetcher.h>
+
+#include "service/fwu/test/metadata_fetcher/metadata_fetcher.h"
/*
* Provides check methods for verifying that the state of fwu metadata is
@@ -16,19 +17,14 @@
* methods are virtual and will be provided by a version specific concrete
* metadata_checker.
*/
-class metadata_checker
-{
+class metadata_checker {
public:
-
- metadata_checker(
- size_t max_metadata_size,
- metadata_fetcher *metadata_fetcher);
+ metadata_checker(size_t max_metadata_size, metadata_fetcher *metadata_fetcher);
virtual ~metadata_checker();
- virtual void get_active_indices(
- uint32_t *active_index,
- uint32_t *previous_active_index) = 0;
+ virtual void get_active_indices(uint32_t *active_index,
+ uint32_t *previous_active_index) = 0;
virtual void check_regular(unsigned int boot_index) = 0;
virtual void check_ready_for_staging(unsigned int boot_index) = 0;
@@ -37,12 +33,15 @@
virtual void check_fallback_to_previous(unsigned int boot_index) = 0;
protected:
-
void load_metadata(void);
metadata_fetcher *m_metadata_fetcher;
uint8_t *m_meta_buf;
size_t m_meta_buf_size;
+
+private:
+ metadata_checker(const metadata_checker &);
+ operator=(const metadata_checker &);
};
#endif /* METADATA_CHECKER_H */
diff --git a/components/service/fwu/test/metadata_checker/metadata_checker_v1.cpp b/components/service/fwu/test/metadata_checker/metadata_checker_v1.cpp
index 042226f..f64037c 100644
--- a/components/service/fwu/test/metadata_checker/metadata_checker_v1.cpp
+++ b/components/service/fwu/test/metadata_checker/metadata_checker_v1.cpp
@@ -4,33 +4,30 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <service/fwu/agent/fw_directory.h>
-#include <protocols/service/fwu/packed-c/metadata_v1.h>
-#include <CppUTest/TestHarness.h>
#include "metadata_checker_v1.h"
+#include <CppUTest/TestHarness.h>
+
+#include "protocols/service/fwu/packed-c/metadata_v1.h"
+#include "service/fwu/agent/fw_directory.h"
+
const size_t metadata_checker_v1::MAX_FWU_METADATA_SIZE =
offsetof(struct fwu_metadata, img_entry) +
FWU_MAX_FW_DIRECTORY_ENTRIES * sizeof(struct fwu_image_entry);
-
-metadata_checker_v1::metadata_checker_v1(
- metadata_fetcher *metadata_fetcher,
- unsigned int num_images) :
- metadata_checker(MAX_FWU_METADATA_SIZE, metadata_fetcher),
- m_num_images(num_images)
+metadata_checker_v1::metadata_checker_v1(metadata_fetcher *metadata_fetcher,
+ unsigned int num_images)
+ : metadata_checker(MAX_FWU_METADATA_SIZE, metadata_fetcher)
+ , m_num_images(num_images)
{
-
}
metadata_checker_v1::~metadata_checker_v1()
{
-
}
-void metadata_checker_v1::get_active_indices(
- uint32_t *active_index,
- uint32_t *previous_active_index)
+void metadata_checker_v1::get_active_indices(uint32_t *active_index,
+ uint32_t *previous_active_index)
{
load_metadata();
@@ -97,9 +94,7 @@
struct fwu_metadata *metadata = reinterpret_cast<struct fwu_metadata *>(m_meta_buf);
for (unsigned int i = 0; i < m_num_images; i++) {
-
if (!metadata->img_entry[i].img_props[boot_index].accepted) {
-
result = false;
break;
}
diff --git a/components/service/fwu/test/metadata_checker/metadata_checker_v1.h b/components/service/fwu/test/metadata_checker/metadata_checker_v1.h
index 81be66a..36bbbe9 100644
--- a/components/service/fwu/test/metadata_checker/metadata_checker_v1.h
+++ b/components/service/fwu/test/metadata_checker/metadata_checker_v1.h
@@ -12,28 +12,21 @@
/*
* A metadata_checker for FWU-A V1 metadata
*/
-class metadata_checker_v1 : public metadata_checker
-{
+class metadata_checker_v1 : public metadata_checker {
public:
-
- metadata_checker_v1(
- metadata_fetcher *metadata_fetcher,
- unsigned int num_images);
+ metadata_checker_v1(metadata_fetcher *metadata_fetcher, unsigned int num_images);
virtual ~metadata_checker_v1();
- void get_active_indices(
- uint32_t *active_index,
- uint32_t *previous_active_index);
+ void get_active_indices(uint32_t *active_index, uint32_t *previous_active_index) override;
- void check_regular(unsigned int boot_index);
- void check_ready_for_staging(unsigned int boot_index);
- void check_ready_to_activate(unsigned int boot_index);
- void check_trial(unsigned int boot_index);
- void check_fallback_to_previous(unsigned int boot_index);
+ void check_regular(unsigned int boot_index) override;
+ void check_ready_for_staging(unsigned int boot_index) override;
+ void check_ready_to_activate(unsigned int boot_index) override;
+ void check_trial(unsigned int boot_index) override;
+ void check_fallback_to_previous(unsigned int boot_index) override;
private:
-
static const size_t MAX_FWU_METADATA_SIZE;
bool is_all_accepted(unsigned int boot_index) const;
diff --git a/components/service/fwu/test/metadata_checker/metadata_checker_v2.cpp b/components/service/fwu/test/metadata_checker/metadata_checker_v2.cpp
index dadcba4..e51ed32 100644
--- a/components/service/fwu/test/metadata_checker/metadata_checker_v2.cpp
+++ b/components/service/fwu/test/metadata_checker/metadata_checker_v2.cpp
@@ -4,33 +4,29 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <service/fwu/agent/fw_directory.h>
-#include <protocols/service/fwu/packed-c/metadata_v2.h>
-#include <CppUTest/TestHarness.h>
#include "metadata_checker_v2.h"
+#include <CppUTest/TestHarness.h>
+
+#include "protocols/service/fwu/packed-c/metadata_v2.h"
+#include "service/fwu/agent/fw_directory.h"
+
const size_t metadata_checker_v2::MAX_FWU_METADATA_SIZE =
- sizeof(struct fwu_metadata) +
- offsetof(struct fwu_fw_store_desc, img_entry) +
+ sizeof(struct fwu_metadata) + offsetof(struct fwu_fw_store_desc, img_entry) +
sizeof(struct fwu_image_entry) * FWU_MAX_FW_DIRECTORY_ENTRIES;
-
-metadata_checker_v2::metadata_checker_v2(
- metadata_fetcher *metadata_fetcher,
- unsigned int num_images) :
- metadata_checker(MAX_FWU_METADATA_SIZE, metadata_fetcher)
+metadata_checker_v2::metadata_checker_v2(metadata_fetcher *metadata_fetcher,
+ unsigned int num_images)
+ : metadata_checker(MAX_FWU_METADATA_SIZE, metadata_fetcher)
{
-
}
metadata_checker_v2::~metadata_checker_v2()
{
-
}
-void metadata_checker_v2::get_active_indices(
- uint32_t *active_index,
- uint32_t *previous_active_index)
+void metadata_checker_v2::get_active_indices(uint32_t *active_index,
+ uint32_t *previous_active_index)
{
load_metadata();
@@ -48,8 +44,7 @@
UNSIGNED_LONGS_EQUAL(boot_index, metadata->active_index);
- BYTES_EQUAL(FWU_METADATA_V2_BANK_STATE_ACCEPTED,
- metadata->bank_state[boot_index]);
+ BYTES_EQUAL(FWU_METADATA_V2_BANK_STATE_ACCEPTED, metadata->bank_state[boot_index]);
}
void metadata_checker_v2::check_ready_for_staging(unsigned int boot_index)
@@ -60,10 +55,9 @@
UNSIGNED_LONGS_EQUAL(boot_index, metadata->active_index);
- BYTES_EQUAL(FWU_METADATA_V2_BANK_STATE_ACCEPTED,
- metadata->bank_state[boot_index]);
+ BYTES_EQUAL(FWU_METADATA_V2_BANK_STATE_ACCEPTED, metadata->bank_state[boot_index]);
BYTES_EQUAL(FWU_METADATA_V2_BANK_STATE_INVALID,
- metadata->bank_state[alternate_bank_index(boot_index)]);
+ metadata->bank_state[alternate_bank_index(boot_index)]);
}
void metadata_checker_v2::check_ready_to_activate(unsigned int boot_index)
@@ -75,8 +69,7 @@
UNSIGNED_LONGS_EQUAL(boot_index, metadata->previous_active_index);
CHECK_TRUE(metadata->active_index != boot_index);
- BYTES_EQUAL(FWU_METADATA_V2_BANK_STATE_VALID,
- metadata->bank_state[metadata->active_index]);
+ BYTES_EQUAL(FWU_METADATA_V2_BANK_STATE_VALID, metadata->bank_state[metadata->active_index]);
}
void metadata_checker_v2::check_trial(unsigned int boot_index)
@@ -88,8 +81,7 @@
UNSIGNED_LONGS_EQUAL(boot_index, metadata->active_index);
CHECK_TRUE(metadata->previous_active_index != boot_index);
- BYTES_EQUAL(FWU_METADATA_V2_BANK_STATE_VALID,
- metadata->bank_state[boot_index]);
+ BYTES_EQUAL(FWU_METADATA_V2_BANK_STATE_VALID, metadata->bank_state[boot_index]);
}
void metadata_checker_v2::check_fallback_to_previous(unsigned int boot_index)
@@ -101,8 +93,7 @@
UNSIGNED_LONGS_EQUAL(boot_index, metadata->previous_active_index);
CHECK_TRUE(metadata->active_index != boot_index);
- BYTES_EQUAL(FWU_METADATA_V2_BANK_STATE_ACCEPTED,
- metadata->bank_state[boot_index]);
+ BYTES_EQUAL(FWU_METADATA_V2_BANK_STATE_ACCEPTED, metadata->bank_state[boot_index]);
}
unsigned int metadata_checker_v2::alternate_bank_index(unsigned int bank_index)
diff --git a/components/service/fwu/test/metadata_checker/metadata_checker_v2.h b/components/service/fwu/test/metadata_checker/metadata_checker_v2.h
index 76e001d..8a13da2 100644
--- a/components/service/fwu/test/metadata_checker/metadata_checker_v2.h
+++ b/components/service/fwu/test/metadata_checker/metadata_checker_v2.h
@@ -12,28 +12,21 @@
/*
* A metadata_checker for FWU-A V2 metadata
*/
-class metadata_checker_v2 : public metadata_checker
-{
+class metadata_checker_v2 : public metadata_checker {
public:
-
- metadata_checker_v2(
- metadata_fetcher *metadata_fetcher,
- unsigned int num_images);
+ metadata_checker_v2(metadata_fetcher *metadata_fetcher, unsigned int num_images);
virtual ~metadata_checker_v2();
- void get_active_indices(
- uint32_t *active_index,
- uint32_t *previous_active_index);
+ void get_active_indices(uint32_t *active_index, uint32_t *previous_active_index) override;
- void check_regular(unsigned int boot_index);
- void check_ready_for_staging(unsigned int boot_index);
- void check_ready_to_activate(unsigned int boot_index);
- void check_trial(unsigned int boot_index);
- void check_fallback_to_previous(unsigned int boot_index);
+ void check_regular(unsigned int boot_index) override;
+ void check_ready_for_staging(unsigned int boot_index) override;
+ void check_ready_to_activate(unsigned int boot_index) override;
+ void check_trial(unsigned int boot_index) override;
+ void check_fallback_to_previous(unsigned int boot_index) override;
private:
-
static unsigned int alternate_bank_index(unsigned int bank_index);
static const size_t MAX_FWU_METADATA_SIZE;
diff --git a/components/service/fwu/test/metadata_fetcher/client/client_metadata_fetcher.cpp b/components/service/fwu/test/metadata_fetcher/client/client_metadata_fetcher.cpp
index 8076e94..77d211c 100644
--- a/components/service/fwu/test/metadata_fetcher/client/client_metadata_fetcher.cpp
+++ b/components/service/fwu/test/metadata_fetcher/client/client_metadata_fetcher.cpp
@@ -4,18 +4,18 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <cstring>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
-#include <CppUTest/TestHarness.h>
#include "client_metadata_fetcher.h"
-client_metadata_fetcher::client_metadata_fetcher(
- fwu_client *fwu_client) :
- metadata_fetcher(),
- m_fwu_client(fwu_client)
-{
+#include <CppUTest/TestHarness.h>
+#include <cstring>
+#include "common/uuid/uuid.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+
+client_metadata_fetcher::client_metadata_fetcher(fwu_client *fwu_client)
+ : metadata_fetcher()
+ , m_fwu_client(fwu_client)
+{
}
client_metadata_fetcher::~client_metadata_fetcher()
@@ -26,12 +26,10 @@
void client_metadata_fetcher::open()
{
-
}
void client_metadata_fetcher::close(void)
{
-
}
void client_metadata_fetcher::fetch(uint8_t *buf, size_t buf_size)
@@ -48,10 +46,7 @@
size_t read_len = 0;
size_t total_len = 0;
- status = m_fwu_client->read_stream(
- stream_handle,
- buf, buf_size,
- &read_len, &total_len);
+ status = m_fwu_client->read_stream(stream_handle, buf, buf_size, &read_len, &total_len);
LONGS_EQUAL(0, status);
m_fwu_client->commit(stream_handle, false);
diff --git a/components/service/fwu/test/metadata_fetcher/client/client_metadata_fetcher.h b/components/service/fwu/test/metadata_fetcher/client/client_metadata_fetcher.h
index 3bee9be..0ced2b6 100644
--- a/components/service/fwu/test/metadata_fetcher/client/client_metadata_fetcher.h
+++ b/components/service/fwu/test/metadata_fetcher/client/client_metadata_fetcher.h
@@ -7,8 +7,8 @@
#ifndef CLIENT_METADATA_FETCHER_H
#define CLIENT_METADATA_FETCHER_H
-#include <service/fwu/test/metadata_fetcher/metadata_fetcher.h>
-#include <service/fwu/test/fwu_client/fwu_client.h>
+#include "service/fwu/test/fwu_client/fwu_client.h"
+#include "service/fwu/test/metadata_fetcher/metadata_fetcher.h"
/*
* A metadata_fetcher that fetches fwu metadata using the FWU
@@ -20,12 +20,9 @@
* client_metadata_fetcher is responsible for deleting the
* fwu_client when it no longer needs it.
*/
-class client_metadata_fetcher : public metadata_fetcher
-{
+class client_metadata_fetcher : public metadata_fetcher {
public:
-
- client_metadata_fetcher(
- fwu_client *fwu_client);
+ explicit client_metadata_fetcher(fwu_client *fwu_client);
~client_metadata_fetcher();
@@ -34,7 +31,6 @@
void fetch(uint8_t *buf, size_t buf_size);
private:
-
fwu_client *m_fwu_client;
};
diff --git a/components/service/fwu/test/metadata_fetcher/metadata_fetcher.h b/components/service/fwu/test/metadata_fetcher/metadata_fetcher.h
index bbdc47c..97f18db 100644
--- a/components/service/fwu/test/metadata_fetcher/metadata_fetcher.h
+++ b/components/service/fwu/test/metadata_fetcher/metadata_fetcher.h
@@ -15,18 +15,14 @@
* fwu metadata and writing it to a presented buffer. Different concrete
* fetching methods can be used for alternative test configurations.
*/
-class metadata_fetcher
-{
+class metadata_fetcher {
public:
-
metadata_fetcher()
{
-
}
virtual ~metadata_fetcher()
{
-
}
virtual void open(void) = 0;
diff --git a/components/service/fwu/test/metadata_fetcher/volume/volume_metadata_fetcher.cpp b/components/service/fwu/test/metadata_fetcher/volume/volume_metadata_fetcher.cpp
index 4acd766..b766e85 100644
--- a/components/service/fwu/test/metadata_fetcher/volume/volume_metadata_fetcher.cpp
+++ b/components/service/fwu/test/metadata_fetcher/volume/volume_metadata_fetcher.cpp
@@ -4,20 +4,21 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <cstring>
-#include <media/volume/volume.h>
-#include <CppUTest/TestHarness.h>
#include "volume_metadata_fetcher.h"
-volume_metadata_fetcher::volume_metadata_fetcher(
- const struct uuid_octets *partition_guid,
- struct block_store *block_store) :
- metadata_fetcher(),
- m_meta_block_volume(),
- m_meta_volume(NULL)
+#include <CppUTest/TestHarness.h>
+#include <cstring>
+
+#include "media/volume/volume.h"
+
+volume_metadata_fetcher::volume_metadata_fetcher(const struct uuid_octets *partition_guid,
+ struct block_store *block_store)
+ : metadata_fetcher()
+ , m_meta_block_volume()
+ , m_meta_volume(NULL)
{
- int status = block_volume_init(&m_meta_block_volume,
- block_store, partition_guid, &m_meta_volume);
+ int status = block_volume_init(&m_meta_block_volume, block_store, partition_guid,
+ &m_meta_volume);
LONGS_EQUAL(0, status);
CHECK_TRUE(m_meta_volume);
}
@@ -48,9 +49,7 @@
size_t length_read = 0;
- status = volume_read(m_meta_volume,
- (uintptr_t)buf, buf_size,
- &length_read);
+ status = volume_read(m_meta_volume, (uintptr_t)buf, buf_size, &length_read);
LONGS_EQUAL(0, status);
UNSIGNED_LONGS_EQUAL(buf_size, length_read);
diff --git a/components/service/fwu/test/metadata_fetcher/volume/volume_metadata_fetcher.h b/components/service/fwu/test/metadata_fetcher/volume/volume_metadata_fetcher.h
index 6656fb7..200a8cf 100644
--- a/components/service/fwu/test/metadata_fetcher/volume/volume_metadata_fetcher.h
+++ b/components/service/fwu/test/metadata_fetcher/volume/volume_metadata_fetcher.h
@@ -7,20 +7,17 @@
#ifndef VOLUME_METADATA_FETCHER_H
#define VOLUME_METADATA_FETCHER_H
-#include <service/fwu/test/metadata_fetcher/metadata_fetcher.h>
-#include <media/volume/block_volume/block_volume.h>
+#include "media/volume/block_volume/block_volume.h"
+#include "service/fwu/test/metadata_fetcher/metadata_fetcher.h"
/*
* A metadata_fetcher that fetches fwu metadata from a storage volume
* that provides access to the disk partition used for fwu metadata.
*/
-class volume_metadata_fetcher : public metadata_fetcher
-{
+class volume_metadata_fetcher : public metadata_fetcher {
public:
-
- volume_metadata_fetcher(
- const struct uuid_octets *partition_guid,
- struct block_store *block_store);
+ volume_metadata_fetcher(const struct uuid_octets *partition_guid,
+ struct block_store *block_store);
~volume_metadata_fetcher();
diff --git a/components/service/fwu/test/ref_scenarios/image_directory_tests.cpp b/components/service/fwu/test/ref_scenarios/image_directory_tests.cpp
index 229a0df..453525b 100644
--- a/components/service/fwu/test/ref_scenarios/image_directory_tests.cpp
+++ b/components/service/fwu/test/ref_scenarios/image_directory_tests.cpp
@@ -4,12 +4,13 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include <CppUTest/TestHarness.h>
#include <cstdint>
#include <vector>
-#include <CppUTest/TestHarness.h>
-#include <service/fwu/test/image_directory_checker/image_directory_checker.h>
-#include <service/fwu/test/fwu_dut_factory/fwu_dut_factory.h>
-#include <service/fwu/test/fwu_dut/fwu_dut.h>
+
+#include "service/fwu/test/fwu_dut/fwu_dut.h"
+#include "service/fwu/test/fwu_dut_factory/fwu_dut_factory.h"
+#include "service/fwu/test/image_directory_checker/image_directory_checker.h"
/*
* Tests that focus on retrieving and checking the contents of the image
@@ -60,7 +61,6 @@
image_directory_checker checker_b;
for (unsigned int i = 0; i < 100; ++i) {
-
/* Try lots of reads */
status = checker_b.fetch_image_directory(m_fwu_client);
LONGS_EQUAL(0, status);
@@ -88,7 +88,6 @@
* attack where streams are opened but never closed.
*/
for (unsigned int i = 0; i < 200; ++i) {
-
int status = 0;
uint32_t stream_handle = 0;
@@ -109,22 +108,17 @@
CHECK_TRUE(stream_index > 0);
do {
-
int status = 0;
--stream_index;
- status = m_fwu_client->commit(
- stream_handles[stream_index],
- false);
+ status = m_fwu_client->commit(stream_handles[stream_index], false);
if (!status) {
-
/* Operation successful so expect this to be a recently opened stream */
LONGS_EQUAL(0, cancelled_count);
++successfully_closed_count;
} else {
-
/* Operation failed so expect this to be an older stream */
CHECK_TRUE(successfully_closed_count > 0);
++cancelled_count;
@@ -152,15 +146,13 @@
status = checker.fetch_image_directory(m_fwu_client);
LONGS_EQUAL(0, status);
- const struct ts_fwu_image_directory *dir_header =
- checker.get_header();
+ const struct ts_fwu_image_directory *dir_header = checker.get_header();
/* Expect directory header to reflect correct values */
CHECK_TRUE(dir_header);
UNSIGNED_LONGS_EQUAL(offsetof(struct ts_fwu_image_directory, img_info_entry),
- dir_header->img_info_offset);
- UNSIGNED_LONGS_EQUAL(sizeof(struct ts_fwu_image_info_entry),
- dir_header->img_info_size);
+ dir_header->img_info_offset);
+ UNSIGNED_LONGS_EQUAL(sizeof(struct ts_fwu_image_info_entry), dir_header->img_info_size);
UNSIGNED_LONGS_EQUAL(2, dir_header->directory_version);
UNSIGNED_LONGS_EQUAL(1, dir_header->correct_boot);
UNSIGNED_LONGS_EQUAL(0, dir_header->reserved);
@@ -195,8 +187,7 @@
status = checker.fetch_image_directory(m_fwu_client);
LONGS_EQUAL(0, status);
- const struct ts_fwu_image_directory *dir_header =
- checker.get_header();
+ const struct ts_fwu_image_directory *dir_header = checker.get_header();
/* Expect directory header to reflect correct values */
CHECK_TRUE(dir_header);
@@ -205,7 +196,6 @@
CHECK_TRUE(dir_header->num_images >= num_locations);
for (unsigned int location_id = 0; location_id < num_locations; location_id++) {
-
/* Expect an image entry for whole volume updates for each location */
struct uuid_octets expected_img_type_uuid;
@@ -236,8 +226,7 @@
status = checker.fetch_image_directory(m_fwu_client);
LONGS_EQUAL(0, status);
- const struct ts_fwu_image_directory *dir_header =
- checker.get_header();
+ const struct ts_fwu_image_directory *dir_header = checker.get_header();
/* Expect directory header to reflect correct values */
CHECK_TRUE(dir_header);
diff --git a/components/service/fwu/test/ref_scenarios/invalid_behaviour_tests.cpp b/components/service/fwu/test/ref_scenarios/invalid_behaviour_tests.cpp
index a77c984..100940a 100644
--- a/components/service/fwu/test/ref_scenarios/invalid_behaviour_tests.cpp
+++ b/components/service/fwu/test/ref_scenarios/invalid_behaviour_tests.cpp
@@ -4,12 +4,13 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
-#include <protocols/service/fwu/packed-c/status.h>
#include <CppUTest/TestHarness.h>
-#include <service/fwu/test/image_directory_checker/image_directory_checker.h>
-#include <service/fwu/test/fwu_dut_factory/fwu_dut_factory.h>
-#include <service/fwu/test/fwu_dut/fwu_dut.h>
+#include <vector>
+
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/test/fwu_dut/fwu_dut.h"
+#include "service/fwu/test/fwu_dut_factory/fwu_dut_factory.h"
+#include "service/fwu/test/image_directory_checker/image_directory_checker.h"
/*
* Tests that check defenses against invalid behaviour from a client.
@@ -74,16 +75,14 @@
std::string image_data("some image data...");
stream_handle = 67;
- status = m_fwu_client->write_stream(
- stream_handle,
- reinterpret_cast<const uint8_t*>(image_data.data()),
- image_data.size());
+ status = m_fwu_client->write_stream(stream_handle,
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_UNKNOWN, status);
/* An attempt to commit with an invalid handle should fail in a similar way */
stream_handle = 771;
- status = m_fwu_client->commit(
- stream_handle, false);
+ status = m_fwu_client->commit(stream_handle, false);
LONGS_EQUAL(FWU_STATUS_UNKNOWN, status);
}
@@ -199,7 +198,8 @@
m_dut->generate_image_data(&image_data);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->commit(stream_handle, false);
@@ -261,5 +261,3 @@
m_dut->shutdown();
}
-
-
diff --git a/components/service/fwu/test/ref_scenarios/oversize_image_tests.cpp b/components/service/fwu/test/ref_scenarios/oversize_image_tests.cpp
index 8fe51c2..c8d91a1 100644
--- a/components/service/fwu/test/ref_scenarios/oversize_image_tests.cpp
+++ b/components/service/fwu/test/ref_scenarios/oversize_image_tests.cpp
@@ -4,12 +4,13 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
-#include <protocols/service/fwu/packed-c/status.h>
#include <CppUTest/TestHarness.h>
-#include <service/fwu/test/image_directory_checker/image_directory_checker.h>
-#include <service/fwu/test/fwu_dut_factory/fwu_dut_factory.h>
-#include <service/fwu/test/fwu_dut/fwu_dut.h>
+#include <vector>
+
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/test/fwu_dut/fwu_dut.h"
+#include "service/fwu/test/fwu_dut_factory/fwu_dut_factory.h"
+#include "service/fwu/test/image_directory_checker/image_directory_checker.h"
/*
* Tests that check behaviour when oversize images are installed.
@@ -38,8 +39,7 @@
int status = dir_checker.fetch_image_directory(m_fwu_client);
LONGS_EQUAL(0, status);
- const struct ts_fwu_image_info_entry *img_entry =
- dir_checker.find_entry(uuid);
+ const struct ts_fwu_image_info_entry *img_entry = dir_checker.find_entry(uuid);
CHECK_TRUE(img_entry);
return static_cast<size_t>(img_entry->img_max_size);
@@ -77,7 +77,8 @@
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->commit(stream_handle, false);
@@ -120,7 +121,8 @@
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_OUT_OF_BOUNDS, status);
/* Client response to the error by cancelling staging */
@@ -161,7 +163,8 @@
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_OUT_OF_BOUNDS, status);
status = m_fwu_client->commit(stream_handle, false);
@@ -211,7 +214,8 @@
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->commit(stream_handle, false);
@@ -226,7 +230,8 @@
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_OUT_OF_BOUNDS, status);
status = m_fwu_client->commit(stream_handle, false);
@@ -241,7 +246,8 @@
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->commit(stream_handle, false);
diff --git a/components/service/fwu/test/ref_scenarios/power_failure_tests.cpp b/components/service/fwu/test/ref_scenarios/power_failure_tests.cpp
index 892951c..a009e8c 100644
--- a/components/service/fwu/test/ref_scenarios/power_failure_tests.cpp
+++ b/components/service/fwu/test/ref_scenarios/power_failure_tests.cpp
@@ -4,11 +4,12 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
-#include <protocols/service/fwu/packed-c/status.h>
#include <CppUTest/TestHarness.h>
-#include <service/fwu/test/fwu_dut_factory/fwu_dut_factory.h>
-#include <service/fwu/test/fwu_dut/fwu_dut.h>
+#include <vector>
+
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/test/fwu_dut/fwu_dut.h"
+#include "service/fwu/test/fwu_dut_factory/fwu_dut_factory.h"
/*
* Tests to check that FWU metadata is never left in an invalid state
* during the update process when unexpected power failures occur. Power
@@ -86,7 +87,8 @@
m_dut->generate_image_data(&image_data);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
/* Power cycle */
@@ -110,7 +112,8 @@
m_dut->generate_image_data(&image_data);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->commit(stream_handle, false);
@@ -156,7 +159,8 @@
m_dut->generate_image_data(&image_data);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->commit(stream_handle, false);
diff --git a/components/service/fwu/test/ref_scenarios/rollback_tests.cpp b/components/service/fwu/test/ref_scenarios/rollback_tests.cpp
index b04fe33..db77a3f 100644
--- a/components/service/fwu/test/ref_scenarios/rollback_tests.cpp
+++ b/components/service/fwu/test/ref_scenarios/rollback_tests.cpp
@@ -4,11 +4,12 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
-#include <protocols/service/fwu/packed-c/status.h>
#include <CppUTest/TestHarness.h>
-#include <service/fwu/test/fwu_dut_factory/fwu_dut_factory.h>
-#include <service/fwu/test/fwu_dut/fwu_dut.h>
+#include <vector>
+
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/test/fwu_dut/fwu_dut.h"
+#include "service/fwu/test/fwu_dut_factory/fwu_dut_factory.h"
/*
* Tests that check update rollback during the trial state where an
@@ -78,7 +79,8 @@
m_dut->generate_image_data(&image_data);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->commit(stream_handle, false);
@@ -142,7 +144,8 @@
m_dut->generate_image_data(&image_data);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->commit(stream_handle, false);
@@ -213,7 +216,8 @@
m_dut->generate_image_data(&image_data);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->commit(stream_handle, false);
diff --git a/components/service/fwu/test/ref_scenarios/update_fmp_tests.cpp b/components/service/fwu/test/ref_scenarios/update_fmp_tests.cpp
index 2b04016..aaa8fd3 100644
--- a/components/service/fwu/test/ref_scenarios/update_fmp_tests.cpp
+++ b/components/service/fwu/test/ref_scenarios/update_fmp_tests.cpp
@@ -4,59 +4,58 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <cstring>
-#include <cassert>
-#include <vector>
-#include <protocols/service/fwu/packed-c/status.h>
#include <CppUTest/TestHarness.h>
-#include <service/fwu/test/fwu_dut_factory/fwu_dut_factory.h>
-#include <service/fwu/test/fwu_dut/fwu_dut.h>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
+#include <cassert>
+#include <cstring>
+#include <vector>
+
+#include "common/uuid/uuid.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/test/fwu_dut/fwu_dut.h"
+#include "service/fwu/test/fwu_dut_factory/fwu_dut_factory.h"
#define EFI_BUFFER_TOO_SMALL ((int32_t)5)
-#define EFI_SUCCESS ((int32_t)0)
+#define EFI_SUCCESS ((int32_t)0)
//*************************************************************
// EFI_FIRMWARE_IMAGE_DESCRIPTOR
//*************************************************************
typedef struct {
- uint8_t ImageIndex;
- struct uuid_octets ImageTypeId;
- uint64_t ImageId;
- char16_t *ImageIdName;
- uint32_t Version;
- char16_t *VersionName;
- uint64_t Size;
- uint64_t AttributesSupported;
- uint64_t AttributesSetting;
- uint64_t Compatibilities;
-//Introduced with DescriptorVersion 2+
- uint32_t LowestSupportedImageVersion;
-//Introduced with DescriptorVersion 3+
- uint32_t LastAttemptVersion;
- uint32_t LastAttemptStatus;
- uint64_t HardwareInstance;
+ uint8_t ImageIndex;
+ struct uuid_octets ImageTypeId;
+ uint64_t ImageId;
+ char16_t *ImageIdName;
+ uint32_t Version;
+ char16_t *VersionName;
+ uint64_t Size;
+ uint64_t AttributesSupported;
+ uint64_t AttributesSetting;
+ uint64_t Compatibilities;
+ //Introduced with DescriptorVersion 2+
+ uint32_t LowestSupportedImageVersion;
+ //Introduced with DescriptorVersion 3+
+ uint32_t LastAttemptVersion;
+ uint32_t LastAttemptStatus;
+ uint64_t HardwareInstance;
} EFI_FIRMWARE_IMAGE_DESCRIPTOR;
-struct fmp{
-
- fmp(fwu_client *m_fwu_client):
- client(m_fwu_client), is_staging(false), img_info(NULL),
- num_images(0) {
-
+struct fmp {
+ explicit fmp(fwu_client *m_fwu_client)
+ : client(m_fwu_client)
+ , is_staging(false)
+ , img_info(NULL)
+ , num_images(0)
+ , payload_max_size(0)
+ {
parse_img_directory();
}
- int get_image_info (
- uint64_t *ImageInfoSize,
- EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,
- uint32_t *DescriptorVersion,
- uint8_t *DescriptorCount,
- uint64_t *DescriptorSize,
- uint32_t *PackageVersion,
- char16_t **PackageVersionName
- ) {
+ int get_image_info(uint64_t *ImageInfoSize, EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,
+ uint32_t *DescriptorVersion, uint8_t *DescriptorCount,
+ uint64_t *DescriptorSize, uint32_t *PackageVersion,
+ char16_t **PackageVersionName)
+ {
const uint64_t img_info_size = num_images * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR);
if (img_info_size > *ImageInfoSize) {
*ImageInfoSize = img_info_size;
@@ -64,33 +63,28 @@
return -EFI_BUFFER_TOO_SMALL;
}
- memcpy (ImageInfo, img_info, *ImageInfoSize);
+ memcpy(ImageInfo, img_info, *ImageInfoSize);
*DescriptorVersion = 3;
*DescriptorCount = num_images;
*DescriptorSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR);
- // PackageVersion 0xFFFFFFFF means that package version
+ // PackageVersion 0xFFFFFFFF means that package version
// is not supported. See UEFI specification.
*PackageVersion = 0xFFFFFFFF;
return EFI_SUCCESS;
};
- int set_image (
- uint8_t ImageIndex,
- const void *Image,
- uint64_t ImageSize,
- const void *VendorCode,
- void *Progress,
- char16_t **AbortReason
- ) {
+ int set_image(uint8_t ImageIndex, const void *Image, uint64_t ImageSize,
+ const void *VendorCode, void *Progress, char16_t **AbortReason)
+ {
int status = 0;
uint32_t stream_handle = 0;
struct uuid_octets *uuid = &(img_info[ImageIndex].ImageTypeId);
- if(!is_staging) {
+ if (!is_staging) {
status = client->begin_staging();
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
is_staging = true;
@@ -99,7 +93,8 @@
status = client->open(uuid, &stream_handle);
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
- status = client->write_stream(stream_handle, static_cast<const uint8_t*>(Image), ImageSize);
+ status = client->write_stream(stream_handle, static_cast<const uint8_t *>(Image),
+ ImageSize);
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = client->commit(stream_handle, false);
@@ -108,8 +103,7 @@
return 0;
};
- private:
-
+private:
int parse_img_directory()
{
int status = 0;
@@ -130,13 +124,8 @@
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
// Determine the size of the FW directory without reading any info.
- status = client->read_stream(
- stream_handle,
- NULL,
- 0,
- &data_len_read,
- &reported_total_len
- );
+ status = client->read_stream(stream_handle, NULL, 0, &data_len_read,
+ &reported_total_len);
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
// Close and reopen the firmware directory stream
@@ -146,16 +135,12 @@
status = client->open(&uuid, &stream_handle);
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
- img_dir = (ts_fwu_image_directory *) new uint8_t[reported_total_len];
+ img_dir = (ts_fwu_image_directory *)new uint8_t[reported_total_len];
// Read the firmware directory info into img_dir.
- status = client->read_stream(
- stream_handle,
- reinterpret_cast<uint8_t *>(img_dir),
- reported_total_len,
- &data_len_read,
- &reported_total_len
- );
+ status = client->read_stream(stream_handle, reinterpret_cast<uint8_t *>(img_dir),
+ reported_total_len, &data_len_read,
+ &reported_total_len);
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
LONGS_EQUAL(data_len_read, reported_total_len);
@@ -164,13 +149,15 @@
num_img = img_dir->num_images;
- // Translate the data from each entry in the img diretory into the img
+ // Translate the data from each entry in the img directory into the img
// info array.
- img_info = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)new uint8_t[num_img * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR)];
+ img_info = (EFI_FIRMWARE_IMAGE_DESCRIPTOR
+ *)new uint8_t[num_img * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR)];
- for (int idx=0; idx<num_img; idx++) {
+ for (int idx = 0; idx < num_img; idx++) {
img_info[idx].ImageIndex = idx;
- memcpy(img_info[idx].ImageTypeId.octets, img_dir->img_info_entry[idx].img_type_uuid, UUID_OCTETS_LEN);
+ memcpy(img_info[idx].ImageTypeId.octets,
+ img_dir->img_info_entry[idx].img_type_uuid, UUID_OCTETS_LEN);
img_info[idx].ImageId = idx;
img_info[idx].ImageIdName = NULL;
img_info[idx].Version = img_dir->img_info_entry[idx].img_version;
@@ -187,7 +174,7 @@
num_images = num_img;
- delete [] img_dir;
+ delete[] img_dir;
return status;
}
@@ -234,7 +221,7 @@
uint64_t ImageInfoSize;
uint32_t DescriptorVersion;
- uint8_t DescriptorCount;
+ uint8_t DescriptorCount;
uint64_t DescriptorSize;
uint32_t PackageVersion;
int status;
@@ -262,43 +249,22 @@
ImageInfoSize = 0;
// First call to fmp.get_image_info obtains the required size.
- m_fmp_protocol->get_image_info(
- &ImageInfoSize,
- img_info,
- &DescriptorVersion,
- &DescriptorCount,
- &DescriptorSize,
- &PackageVersion,
- NULL
- );
+ m_fmp_protocol->get_image_info(&ImageInfoSize, img_info, &DescriptorVersion,
+ &DescriptorCount, &DescriptorSize, &PackageVersion, NULL);
- img_info = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *) new uint8_t[ImageInfoSize];
+ img_info = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)new uint8_t[ImageInfoSize];
- m_fmp_protocol->get_image_info(
- &ImageInfoSize,
- img_info,
- &DescriptorVersion,
- &DescriptorCount,
- &DescriptorSize,
- &PackageVersion,
- NULL
- );
+ m_fmp_protocol->get_image_info(&ImageInfoSize, img_info, &DescriptorVersion,
+ &DescriptorCount, &DescriptorSize, &PackageVersion, NULL);
// Iterate over all the image descriptors returned by get_img_info
// to obtain the ImageId.
for (int idx = 0; idx < DescriptorCount; idx++) {
- if(uuid_is_equal(img_info[idx].ImageTypeId.octets, uuid.octets)) {
-
+ if (uuid_is_equal(img_info[idx].ImageTypeId.octets, uuid.octets)) {
uint8_t img_idx = img_info[idx].ImageIndex;
- m_fmp_protocol->set_image(
- img_idx,
- image_data.data(),
- image_data.size(),
- NULL,
- NULL,
- NULL
- );
+ m_fmp_protocol->set_image(img_idx, image_data.data(), image_data.size(),
+ NULL, NULL, NULL);
break;
}
}
@@ -306,5 +272,5 @@
status = m_fwu_client->end_staging();
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
- delete [] img_info;
+ delete[] img_info;
}
diff --git a/components/service/fwu/test/ref_scenarios/update_scenario_tests.cpp b/components/service/fwu/test/ref_scenarios/update_scenario_tests.cpp
index 7d5ee00..b5c8341 100644
--- a/components/service/fwu/test/ref_scenarios/update_scenario_tests.cpp
+++ b/components/service/fwu/test/ref_scenarios/update_scenario_tests.cpp
@@ -4,11 +4,12 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
-#include <protocols/service/fwu/packed-c/status.h>
#include <CppUTest/TestHarness.h>
-#include <service/fwu/test/fwu_dut_factory/fwu_dut_factory.h>
-#include <service/fwu/test/fwu_dut/fwu_dut.h>
+#include <vector>
+
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/test/fwu_dut/fwu_dut.h"
+#include "service/fwu/test/fwu_dut_factory/fwu_dut_factory.h"
/*
* Tests that perform a range of normal update scenarios
@@ -78,7 +79,8 @@
m_dut->generate_image_data(&image_data);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->commit(stream_handle, false);
@@ -162,7 +164,8 @@
m_dut->generate_image_data(&image_data);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
/* Accept on commit. No need to accept during trial */
@@ -177,7 +180,8 @@
m_dut->generate_image_data(&image_data);
status = m_fwu_client->write_stream(stream_handle,
- reinterpret_cast<const uint8_t *>(image_data.data()), image_data.size());
+ reinterpret_cast<const uint8_t *>(image_data.data()),
+ image_data.size());
LONGS_EQUAL(FWU_STATUS_SUCCESS, status);
status = m_fwu_client->commit(stream_handle, false);
diff --git a/components/service/fwu/test/service/fwu_service_tests.cpp b/components/service/fwu/test/service/fwu_service_tests.cpp
index 051b245..0476d92 100644
--- a/components/service/fwu/test/service/fwu_service_tests.cpp
+++ b/components/service/fwu/test/service/fwu_service_tests.cpp
@@ -4,12 +4,13 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
-#include <protocols/service/fwu/packed-c/status.h>
#include <CppUTest/TestHarness.h>
-#include <service/fwu/test/image_directory_checker/image_directory_checker.h>
-#include <service/fwu/test/fwu_dut_factory/fwu_dut_factory.h>
-#include <service/fwu/test/fwu_dut/fwu_dut.h>
+#include <vector>
+
+#include "protocols/service/fwu/packed-c/status.h"
+#include "service/fwu/test/fwu_dut/fwu_dut.h"
+#include "service/fwu/test/fwu_dut_factory/fwu_dut_factory.h"
+#include "service/fwu/test/image_directory_checker/image_directory_checker.h"
/*
* FWU service level tests that can be run with other service level tests.
diff --git a/components/service/locator/remote/restapi/restapi_env.c b/components/service/locator/remote/restapi/restapi_env.c
index d219595..8e6561f 100644
--- a/components/service/locator/remote/restapi/restapi_env.c
+++ b/components/service/locator/remote/restapi/restapi_env.c
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <service_locator.h>
#include "restapi_location_strategy.h"
+#include "service_locator.h"
void service_locator_envinit(void)
{
diff --git a/components/service/locator/remote/restapi/restapi_location.h b/components/service/locator/remote/restapi/restapi_location.h
index 8bab310..bd4986f 100644
--- a/components/service/locator/remote/restapi/restapi_location.h
+++ b/components/service/locator/remote/restapi/restapi_location.h
@@ -11,7 +11,7 @@
* is required.
*/
#ifndef RESTAPI_LOCATOR_API_URL
-#define RESTAPI_LOCATOR_API_URL "http://127.0.0.1/api/v1/services/"
+#define RESTAPI_LOCATOR_API_URL "http://127.0.0.1/api/v1/services/"
#endif
#endif /* RESTAPI_LOCATION_STRATEGY_H */
diff --git a/components/service/locator/remote/restapi/restapi_location_strategy.c b/components/service/locator/remote/restapi/restapi_location_strategy.c
index 0352940..93dcb3f 100644
--- a/components/service/locator/remote/restapi/restapi_location_strategy.c
+++ b/components/service/locator/remote/restapi/restapi_location_strategy.c
@@ -4,31 +4,30 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <assert.h>
-#include <unistd.h>
-#include <string.h>
-#include <trace.h>
-#include <service/locator/service_name.h>
-#include <rpc/http/caller/http_caller.h>
#include "restapi_location_strategy.h"
-#include "restapi_service_context.h"
-#include "restapi_location.h"
+#include <assert.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "restapi_location.h"
+#include "restapi_service_context.h"
+#include "rpc/http/caller/http_caller.h"
+#include "service/locator/service_name.h"
+#include "trace.h"
/* Maximum wait for an unresponsive API server. During testing, this period
* may need to accommodate the boot time for a device under test.
*/
#ifndef RESTAPI_LOCATOR_MAX_API_WAIT
-#define RESTAPI_LOCATOR_MAX_API_WAIT (120)
+#define RESTAPI_LOCATOR_MAX_API_WAIT (120)
#endif
-
static bool probe_api_server(void)
{
unsigned int seconds_waited = 0;
do {
-
long http_code = 0;
if (http_caller_probe(RESTAPI_LOCATOR_API_URL, &http_code))
@@ -36,7 +35,6 @@
/* Failed to reach API or received an error response */
if (http_code == 0) {
-
/* It's possible that the device hosting the API server is in the
* process of booting up so it's worth waiting and trying again.
*/
@@ -44,7 +42,6 @@
++seconds_waited;
} else {
-
/* The server was reached but it returned an error */
EMSG("API server HTTP error: %ld", http_code);
return false;
@@ -89,7 +86,6 @@
prepare_service_url(sn, service_url, sizeof(service_url));
if (!http_caller_probe(service_url, &http_code)) {
-
if (http_code != 404)
EMSG("Unexpected HTTP error: %ld", http_code);
diff --git a/components/service/locator/remote/restapi/restapi_location_strategy.h b/components/service/locator/remote/restapi/restapi_location_strategy.h
index 3212cc4..3a352ae 100644
--- a/components/service/locator/remote/restapi/restapi_location_strategy.h
+++ b/components/service/locator/remote/restapi/restapi_location_strategy.h
@@ -7,7 +7,7 @@
#ifndef RESTAPI_LOCATION_STRATEGY_H
#define RESTAPI_LOCATION_STRATEGY_H
-#include <service_locator.h>
+#include "service_locator.h"
#ifdef __cplusplus
extern "C" {
diff --git a/components/service/locator/remote/restapi/restapi_service_context.c b/components/service/locator/remote/restapi/restapi_service_context.c
index 120f117..92d3f2a 100644
--- a/components/service/locator/remote/restapi/restapi_service_context.c
+++ b/components/service/locator/remote/restapi/restapi_service_context.c
@@ -4,18 +4,19 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include "restapi_service_context.h"
+
#include <stdlib.h>
#include <string.h>
-#include <trace.h>
-#include <rpc/http/caller/http_caller.h>
-#include "restapi_service_context.h"
+
+#include "rpc/http/caller/http_caller.h"
+#include "trace.h"
/**
* A service_context that represents a service instance reached via
* a remote REST API
*/
-struct restapi_service_context
-{
+struct restapi_service_context {
struct service_context service_context;
char rpc_call_url[HTTP_CALLER_MAX_URL_LEN];
};
@@ -25,7 +26,6 @@
static void restapi_service_context_close(void *context, rpc_session_handle session_handle);
static void restapi_service_context_relinquish(void *context);
-
struct service_context *restapi_service_context_create(const char *service_url)
{
struct restapi_service_context *new_context =
@@ -52,10 +52,10 @@
struct restapi_service_context *this_context = (struct restapi_service_context *)context;
rpc_session_handle session_handle = NULL;
- struct http_caller *http_caller = (struct http_caller *)calloc(1, sizeof(struct http_caller));
+ struct http_caller *http_caller =
+ (struct http_caller *)calloc(1, sizeof(struct http_caller));
if (http_caller) {
-
*caller = http_caller_init(http_caller);
int status = http_caller_open(http_caller, this_context->rpc_call_url);
@@ -63,8 +63,7 @@
if (status == 0) {
/* Successfully opened session */
session_handle = http_caller;
- }
- else {
+ } else {
/* Failed to open session */
http_caller_close(http_caller);
http_caller_deinit(http_caller);
@@ -82,7 +81,6 @@
(void)context;
if (http_caller) {
-
http_caller_close(http_caller);
http_caller_deinit(http_caller);
free(http_caller);
diff --git a/components/service/locator/remote/restapi/restapi_service_context.h b/components/service/locator/remote/restapi/restapi_service_context.h
index 6c04344..8f6cd29 100644
--- a/components/service/locator/remote/restapi/restapi_service_context.h
+++ b/components/service/locator/remote/restapi/restapi_service_context.h
@@ -7,7 +7,7 @@
#ifndef RESTAPI_SERVICE_CONTEXT_H
#define RESTAPI_SERVICE_CONTEXT_H
-#include <service_locator.h>
+#include "service_locator.h"
#ifdef __cplusplus
extern "C" {
diff --git a/components/service/locator/standalone/services/fwu/fwu_service_context.cpp b/components/service/locator/standalone/services/fwu/fwu_service_context.cpp
index bab0768..2691ba8 100644
--- a/components/service/locator/standalone/services/fwu/fwu_service_context.cpp
+++ b/components/service/locator/standalone/services/fwu/fwu_service_context.cpp
@@ -6,23 +6,19 @@
#include "fwu_service_context.h"
-
struct rpc_interface *fwu_service_context::m_provider_iface = NULL;
-fwu_service_context::fwu_service_context(const char *sn) :
- standalone_service_context(sn),
- m_rpc_demux()
+fwu_service_context::fwu_service_context(const char *sn)
+ : standalone_service_context(sn)
+ , m_rpc_demux()
{
-
}
fwu_service_context::~fwu_service_context()
{
-
}
-void fwu_service_context::set_provider(
- struct rpc_interface *iface)
+void fwu_service_context::set_provider(struct rpc_interface *iface)
{
m_provider_iface = iface;
}
@@ -36,7 +32,6 @@
struct rpc_interface *rpc_iface = rpc_demux_init(&m_rpc_demux);
if (m_provider_iface) {
-
/* A service provider is available. This facility allows a test
* case to apply an fwu_provider with a particular configuration
* to suite test goals.
@@ -53,8 +48,7 @@
set_provider(NULL);
}
-void fwu_service_context_set_provider(
- struct rpc_interface *iface)
+void fwu_service_context_set_provider(struct rpc_interface *iface)
{
fwu_service_context::set_provider(iface);
}
\ No newline at end of file
diff --git a/components/service/locator/standalone/services/fwu/fwu_service_context.h b/components/service/locator/standalone/services/fwu/fwu_service_context.h
index 41084ce..4cb23d2 100644
--- a/components/service/locator/standalone/services/fwu/fwu_service_context.h
+++ b/components/service/locator/standalone/services/fwu/fwu_service_context.h
@@ -7,20 +7,17 @@
#ifndef STANDALONE_FWU_SERVICE_CONTEXT_H
#define STANDALONE_FWU_SERVICE_CONTEXT_H
-#include <service/locator/standalone/standalone_service_context.h>
-#include <rpc/common/demux/rpc_demux.h>
+#include "rpc/common/demux/rpc_demux.h"
+#include "service/locator/standalone/standalone_service_context.h"
-class fwu_service_context : public standalone_service_context
-{
+class fwu_service_context : public standalone_service_context {
public:
- fwu_service_context(const char *sn);
+ explicit fwu_service_context(const char *sn);
virtual ~fwu_service_context();
- static void set_provider(
- struct rpc_interface *iface);
+ static void set_provider(struct rpc_interface *iface);
private:
-
void do_init();
void do_deinit();
@@ -38,7 +35,6 @@
#define FWU_SERVICE_CONTEXT_EXPORTED
#endif
-FWU_SERVICE_CONTEXT_EXPORTED void fwu_service_context_set_provider(
- struct rpc_interface *iface);
+FWU_SERVICE_CONTEXT_EXPORTED void fwu_service_context_set_provider(struct rpc_interface *iface);
#endif /* STANDALONE_FWU_SERVICE_CONTEXT_H */
diff --git a/deployments/fwu/config/default-opteesp/optee_sp_user_defines.h b/deployments/fwu/config/default-opteesp/optee_sp_user_defines.h
index 66cd9f2..e5fb8c1 100644
--- a/deployments/fwu/config/default-opteesp/optee_sp_user_defines.h
+++ b/deployments/fwu/config/default-opteesp/optee_sp_user_defines.h
@@ -6,9 +6,9 @@
#ifndef OPTEE_SP_USER_DEFINES_H
#define OPTEE_SP_USER_DEFINES_H
-#define OPTEE_SP_FLAGS 0
+#define OPTEE_SP_FLAGS 0
/* Provisioned stack size */
-#define OPTEE_SP_STACK_SIZE (64 * 1024)
+#define OPTEE_SP_STACK_SIZE (64 * 1024)
#endif /* SP_HEADER_DEFINES_H */
diff --git a/deployments/fwu/env/commonsp/fwu_sp.c b/deployments/fwu/env/commonsp/fwu_sp.c
index 016ec50..bf7cbe8 100644
--- a/deployments/fwu/env/commonsp/fwu_sp.c
+++ b/deployments/fwu/env/commonsp/fwu_sp.c
@@ -4,38 +4,37 @@
*/
#include <stddef.h>
-#include <sp_api.h>
-#include <sp_discovery.h>
-#include <sp_messaging.h>
-#include <sp_rxtx.h>
-#include <trace.h>
-#include <rpc/ffarpc/endpoint/ffarpc_call_ep.h>
-#include <protocols/rpc/common/packed-c/status.h>
-#include <config/ramstore/config_ramstore.h>
-#include <config/loader/sp/sp_config_loader.h>
-#include <media/volume/factory/volume_factory.h>
-#include <service/fwu/config/fwu_configure.h>
-#include <service/discovery/provider/discovery_provider.h>
-#include <service/discovery/provider/serializer/packed-c/packedc_discovery_provider_serializer.h>
-#include <service/fwu/provider/fwu_provider.h>
-#include <service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.h>
-#include <service/fwu/fw_store/banked/bank_scheme.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.h>
-#include <service/fwu/inspector/direct/direct_fw_inspector.h>
-#include <service/fwu/agent/update_agent.h>
-#include <service/fwu/fw_store/banked/banked_fw_store.h>
+#include "config/loader/sp/sp_config_loader.h"
+#include "config/ramstore/config_ramstore.h"
+#include "media/volume/factory/volume_factory.h"
+#include "protocols/rpc/common/packed-c/status.h"
+#include "rpc/ffarpc/endpoint/ffarpc_call_ep.h"
+#include "service/discovery/provider/discovery_provider.h"
+#include "service/discovery/provider/serializer/packed-c/packedc_discovery_provider_serializer.h"
+#include "service/fwu/agent/update_agent.h"
+#include "service/fwu/config/fwu_configure.h"
+#include "service/fwu/fw_store/banked/bank_scheme.h"
+#include "service/fwu/fw_store/banked/banked_fw_store.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.h"
+#include "service/fwu/inspector/direct/direct_fw_inspector.h"
+#include "service/fwu/provider/fwu_provider.h"
+#include "service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.h"
+#include "sp_api.h"
+#include "sp_discovery.h"
+#include "sp_messaging.h"
+#include "sp_rxtx.h"
+#include "trace.h"
/* Set default limit on the number of storage devices to update */
#ifndef FWU_SP_MAX_STORAGE_DEVICES
-#define FWU_SP_MAX_STORAGE_DEVICES (1)
+#define FWU_SP_MAX_STORAGE_DEVICES (1)
#endif
/* Parameters that should be passed forward by the bootloader */
-#define HARD_CODED_BOOT_INDEX (0)
-#define HARD_CODED_METADATA_VER (2)
-
+#define HARD_CODED_BOOT_INDEX (0)
+#define HARD_CODED_METADATA_VER (2)
static bool sp_init(uint16_t *own_sp_id);
static bool configure_for_platform(void);
@@ -87,31 +86,26 @@
goto fatal_error;
}
- if (update_agent_init(&update_agent, HARD_CODED_BOOT_INDEX,
- direct_fw_inspector_inspect, &fw_store)) {
+ if (update_agent_init(&update_agent, HARD_CODED_BOOT_INDEX, direct_fw_inspector_inspect,
+ &fw_store)) {
EMSG("Failed to init update agent");
goto fatal_error;
}
/* Initialise the FWU service provider */
- service_iface = fwu_provider_init(
- &service_provider,
- &update_agent);
+ service_iface = fwu_provider_init(&service_provider, &update_agent);
if (!service_iface) {
EMSG("Failed to init service provider");
goto fatal_error;
}
- fwu_provider_register_serializer(
- &service_provider,
- TS_RPC_ENCODING_PACKED_C,
- packedc_fwu_provider_serializer_instance());
+ fwu_provider_register_serializer(&service_provider, TS_RPC_ENCODING_PACKED_C,
+ packedc_fwu_provider_serializer_instance());
- discovery_provider_register_serializer(
- &service_provider.discovery_provider,
- TS_RPC_ENCODING_PACKED_C,
- packedc_discovery_provider_serializer_instance());
+ discovery_provider_register_serializer(&service_provider.discovery_provider,
+ TS_RPC_ENCODING_PACKED_C,
+ packedc_discovery_provider_serializer_instance());
/* Associate service interface with FFA call endpoint */
ffa_call_ep_init(&ffarpc_call_ep, service_iface, own_id);
@@ -140,7 +134,8 @@
fatal_error:
/* SP is not viable */
EMSG("FWU SP error");
- while (1) {}
+ while (1) {
+ }
}
void sp_interrupt_handler(uint32_t interrupt_id)
@@ -150,11 +145,10 @@
static bool sp_init(uint16_t *own_id)
{
- sp_result sp_res = SP_RESULT_INTERNAL_ERROR;
static uint8_t tx_buffer[4096] __aligned(4096);
static uint8_t rx_buffer[4096] __aligned(4096);
- sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
+ sp_result sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
if (sp_res != SP_RESULT_OK) {
EMSG("Failed to map RXTX buffers: %d", sp_res);
return false;
@@ -174,11 +168,10 @@
struct uuid_octets device_uuids[FWU_SP_MAX_STORAGE_DEVICES];
size_t num_storage_devices = 0;
- int status = volume_factory_init(device_uuids,
- FWU_SP_MAX_STORAGE_DEVICES, &num_storage_devices);
+ int status =
+ volume_factory_init(device_uuids, FWU_SP_MAX_STORAGE_DEVICES, &num_storage_devices);
if (status) {
-
EMSG("Failed to init volume factory: %d", status);
return false;
}
@@ -186,7 +179,6 @@
status = fwu_configure(device_uuids, num_storage_devices);
if (status) {
-
EMSG("Failed to setup FWU configuration: %d", status);
return false;
}
diff --git a/deployments/fwu/env/posix/cmd_print_image_dir.cpp b/deployments/fwu/env/posix/cmd_print_image_dir.cpp
index 0060ebd..1e07027 100644
--- a/deployments/fwu/env/posix/cmd_print_image_dir.cpp
+++ b/deployments/fwu/env/posix/cmd_print_image_dir.cpp
@@ -4,17 +4,18 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
+#include "cmd_print_image_dir.h"
+
#include <cstdint>
#include <cstdio>
#include <cstdlib>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
-#include "cmd_print_image_dir.h"
-#include "print_uuid.h"
+#include <vector>
-void cmd_print_image_dir(
- fwu_app &app)
+#include "common/uuid/uuid.h"
+#include "print_uuid.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+
+void cmd_print_image_dir(fwu_app &app)
{
std::vector<uint8_t> fetched_object;
struct uuid_octets object_uuid;
@@ -24,13 +25,11 @@
int status = app.read_object(object_uuid, fetched_object);
if (status) {
-
printf("Error: failed to read image directory\n");
return;
}
if (fetched_object.size() < offsetof(ts_fwu_image_directory, img_info_entry)) {
-
printf("Error: invalid image directory size\n");
return;
}
@@ -38,25 +37,21 @@
const struct ts_fwu_image_directory *img_dir =
(const struct ts_fwu_image_directory *)fetched_object.data();
- printf("\nimage_directory (size %ld bytes) :\n", fetched_object.size());
+ printf("\nimage_directory (size %zu bytes) :\n", fetched_object.size());
printf("\tdirectory_version : %d\n", img_dir->directory_version);
printf("\tnum_images : %d\n", img_dir->num_images);
printf("\tcorrect_boot : %d\n", img_dir->correct_boot);
for (unsigned int i = 0; i < img_dir->num_images; i++) {
-
- printf("\timg_info_entry[%d]:\n", i);
+ printf("\timg_info_entry[%u]:\n", i);
printf("\t\timg_type_uuid : %s\n",
- print_uuid(img_dir->img_info_entry[i].img_type_uuid).c_str());
+ print_uuid(img_dir->img_info_entry[i].img_type_uuid).c_str());
printf("\t\tclient_permissions : 0x%x\n",
- img_dir->img_info_entry[i].client_permissions);
- printf("\t\timg_max_size : %d\n",
- img_dir->img_info_entry[i].img_max_size);
+ img_dir->img_info_entry[i].client_permissions);
+ printf("\t\timg_max_size : %d\n", img_dir->img_info_entry[i].img_max_size);
printf("\t\tlowest_accepted_version : %d\n",
- img_dir->img_info_entry[i].lowest_accepted_version);
- printf("\t\timg_version : %d\n",
- img_dir->img_info_entry[i].img_version);
- printf("\t\taccepted : %d\n",
- img_dir->img_info_entry[i].accepted);
+ img_dir->img_info_entry[i].lowest_accepted_version);
+ printf("\t\timg_version : %d\n", img_dir->img_info_entry[i].img_version);
+ printf("\t\taccepted : %d\n", img_dir->img_info_entry[i].accepted);
}
}
diff --git a/deployments/fwu/env/posix/cmd_print_image_dir.h b/deployments/fwu/env/posix/cmd_print_image_dir.h
index 1630734..7ae2e01 100644
--- a/deployments/fwu/env/posix/cmd_print_image_dir.h
+++ b/deployments/fwu/env/posix/cmd_print_image_dir.h
@@ -8,7 +8,7 @@
#ifndef CMD_PRINT_IMAGE_DIR_H
#define CMD_PRINT_IMAGE_DIR_H
-#include <service/fwu/app/fwu_app.h>
+#include "service/fwu/app/fwu_app.h"
void cmd_print_image_dir(fwu_app &app);
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v1.cpp b/deployments/fwu/env/posix/cmd_print_metadata_v1.cpp
index 3762745..6539e57 100644
--- a/deployments/fwu/env/posix/cmd_print_metadata_v1.cpp
+++ b/deployments/fwu/env/posix/cmd_print_metadata_v1.cpp
@@ -4,19 +4,19 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
+#include "cmd_print_metadata_v1.h"
+
#include <cstdint>
#include <cstdio>
#include <cstdlib>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
-#include <protocols/service/fwu/packed-c/metadata_v1.h>
-#include "cmd_print_metadata_v1.h"
+#include <vector>
+
+#include "common/uuid/uuid.h"
#include "print_uuid.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+#include "protocols/service/fwu/packed-c/metadata_v1.h"
-
-void cmd_print_metadata_v1(
- fwu_app &app)
+void cmd_print_metadata_v1(fwu_app &app)
{
std::vector<uint8_t> fetched_object;
struct uuid_octets object_uuid;
@@ -26,41 +26,38 @@
int status = app.read_object(object_uuid, fetched_object);
if (status) {
-
printf("Error: failed to read metadata\n");
return;
}
if (fetched_object.size() < sizeof(struct fwu_metadata)) {
-
printf("Error: invalid metadata size\n");
return;
}
- const struct fwu_metadata *metadata =
- (const struct fwu_metadata *)fetched_object.data();
+ const struct fwu_metadata *metadata = (const struct fwu_metadata *)fetched_object.data();
- printf("\nfwu_metadata (size %ld bytes) :\n", fetched_object.size());
+ printf("\nfwu_metadata (size %zu bytes) :\n", fetched_object.size());
printf("\tcrc_32 : 0x%x\n", metadata->crc_32);
printf("\tversion : %d\n", metadata->version);
printf("\tactive_index : %d\n", metadata->active_index);
printf("\tprevious_active_index : %d\n", metadata->previous_active_index);
for (unsigned int i = 0; i < FWU_METADATA_NUM_IMAGE_ENTRIES; i++) {
-
- printf("\timg_entry[%d]:\n", i);
+ printf("\timg_entry[%u]:\n", i);
printf("\t\timg_type_uuid : %s\n",
- print_uuid(metadata->img_entry[i].img_type_uuid).c_str());
+ print_uuid(metadata->img_entry[i].img_type_uuid).c_str());
printf("\t\tlocation_uuid : %s\n",
- print_uuid(metadata->img_entry[i].location_uuid).c_str());
+ print_uuid(metadata->img_entry[i].location_uuid).c_str());
- for (unsigned int bank_index = 0; bank_index < FWU_METADATA_NUM_BANKS; bank_index++) {
-
- printf("\t\timg_props[%d]:\n", bank_index);
+ for (unsigned int bank_index = 0; bank_index < FWU_METADATA_NUM_BANKS;
+ bank_index++) {
+ printf("\t\timg_props[%u]:\n", bank_index);
printf("\t\t\timg_uuid : %s\n",
- print_uuid(metadata->img_entry[i].img_props[bank_index].img_uuid).c_str());
+ print_uuid(metadata->img_entry[i].img_props[bank_index].img_uuid)
+ .c_str());
printf("\t\t\taccepted : %d\n",
- metadata->img_entry[i].img_props[bank_index].accepted);
+ metadata->img_entry[i].img_props[bank_index].accepted);
}
}
}
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v1.h b/deployments/fwu/env/posix/cmd_print_metadata_v1.h
index 0dc5eac..c31ec68 100644
--- a/deployments/fwu/env/posix/cmd_print_metadata_v1.h
+++ b/deployments/fwu/env/posix/cmd_print_metadata_v1.h
@@ -8,7 +8,7 @@
#ifndef CMD_PRINT_METADATA_V1_H
#define CMD_PRINT_METADATA_V1_H
-#include <service/fwu/app/fwu_app.h>
+#include "service/fwu/app/fwu_app.h"
void cmd_print_metadata_v1(fwu_app &app);
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v2.cpp b/deployments/fwu/env/posix/cmd_print_metadata_v2.cpp
index 5fee2d9..69e09d7 100644
--- a/deployments/fwu/env/posix/cmd_print_metadata_v2.cpp
+++ b/deployments/fwu/env/posix/cmd_print_metadata_v2.cpp
@@ -4,18 +4,19 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
+#include "cmd_print_metadata_v2.h"
+
#include <cstdint>
#include <cstdio>
#include <cstdlib>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
-#include <protocols/service/fwu/packed-c/metadata_v2.h>
-#include "cmd_print_metadata_v2.h"
-#include "print_uuid.h"
+#include <vector>
-void cmd_print_metadata_v2(
- fwu_app &app)
+#include "common/uuid/uuid.h"
+#include "print_uuid.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+#include "protocols/service/fwu/packed-c/metadata_v2.h"
+
+void cmd_print_metadata_v2(fwu_app &app)
{
std::vector<uint8_t> fetched_object;
struct uuid_octets object_uuid;
@@ -25,30 +26,26 @@
int status = app.read_object(object_uuid, fetched_object);
if (status) {
-
printf("Error: failed to read metadata\n");
return;
}
if (fetched_object.size() < sizeof(struct fwu_metadata)) {
-
printf("Error: invalid metadata size\n");
return;
}
/* Print mandatory metadata header */
- const struct fwu_metadata *metadata =
- (const struct fwu_metadata *)fetched_object.data();
+ const struct fwu_metadata *metadata = (const struct fwu_metadata *)fetched_object.data();
- printf("\nfwu_metadata (size %ld bytes) :\n", fetched_object.size());
+ printf("\nfwu_metadata (size %zu bytes) :\n", fetched_object.size());
printf("\tcrc_32 : 0x%x\n", metadata->crc_32);
printf("\tversion : %d\n", metadata->version);
printf("\tmetadata_size : %d\n", metadata->metadata_size);
printf("\theader_size : %d\n", metadata->header_size);
printf("\tactive_index : %d\n", metadata->active_index);
printf("\tprevious_active_index : %d\n", metadata->previous_active_index);
- printf("\tbank_state : 0x%x 0x%x\n",
- metadata->bank_state[0], metadata->bank_state[1]);
+ printf("\tbank_state : 0x%x 0x%x\n", metadata->bank_state[0], metadata->bank_state[1]);
if (metadata->metadata_size <= metadata->header_size)
return;
@@ -56,7 +53,6 @@
size_t fw_store_desc_size = metadata->metadata_size - metadata->header_size;
if (fw_store_desc_size < sizeof(fwu_fw_store_desc)) {
-
printf("\tInsufficient space for fw store descriptor\n");
return;
}
@@ -72,18 +68,16 @@
printf("\t\tbank_entry_size : %d\n", fw_store_desc->bank_entry_size);
for (unsigned int i = 0; i < fw_store_desc->num_images; i++) {
-
struct fwu_image_entry *img_entry = &fw_store_desc->img_entry[i];
- printf("\t\timg_entry[%d] :\n", i);
+ printf("\t\timg_entry[%u] :\n", i);
printf("\t\t\timg_type_uuid : %s\n", print_uuid(img_entry->img_type_uuid).c_str());
printf("\t\t\tlocation_uuid : %s\n", print_uuid(img_entry->location_uuid).c_str());
- for (unsigned int i = 0; i < fw_store_desc->num_banks; i++) {
+ for (unsigned int j = 0; j < fw_store_desc->num_banks; j++) {
+ struct fwu_img_bank_info *bank_info = &img_entry->img_bank_info[j];
- struct fwu_img_bank_info *bank_info = &img_entry->img_bank_info[i];
-
- printf("\t\t\timg_bank_info[%d] :\n", i);
+ printf("\t\t\timg_bank_info[%u] :\n", j);
printf("\t\t\t\timg_uuid : %s\n", print_uuid(bank_info->img_uuid).c_str());
printf("\t\t\t\taccepted : %d\n", bank_info->accepted);
}
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v2.h b/deployments/fwu/env/posix/cmd_print_metadata_v2.h
index 2943f93..5377212 100644
--- a/deployments/fwu/env/posix/cmd_print_metadata_v2.h
+++ b/deployments/fwu/env/posix/cmd_print_metadata_v2.h
@@ -8,7 +8,7 @@
#ifndef CMD_PRINT_METADATA_V2_H
#define CMD_PRINT_METADATA_V2_H
-#include <service/fwu/app/fwu_app.h>
+#include "service/fwu/app/fwu_app.h"
void cmd_print_metadata_v2(fwu_app &app);
diff --git a/deployments/fwu/env/posix/cmd_update_image.cpp b/deployments/fwu/env/posix/cmd_update_image.cpp
index 8e1014f..06c13a6 100644
--- a/deployments/fwu/env/posix/cmd_update_image.cpp
+++ b/deployments/fwu/env/posix/cmd_update_image.cpp
@@ -4,22 +4,20 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include "cmd_update_image.h"
+
#include <cstdio>
#include <cstdlib>
#include <cstring>
-#include <common/uuid/uuid.h>
-#include "cmd_update_image.h"
+#include "common/uuid/uuid.h"
-int cmd_update_image(
- fwu_app &app,
- const std::string &img_type_uuid,
- const std::string &img_filename)
+int cmd_update_image(fwu_app &app, const std::string &img_type_uuid,
+ const std::string &img_filename)
{
FILE *fp = fopen(img_filename.c_str(), "rb");
if (!fp) {
-
printf("Error: failed to open image file: %s\n", img_filename.c_str());
return -1;
}
@@ -33,7 +31,6 @@
uint8_t *img_buf = (uint8_t *)malloc(img_size);
if (!img_buf) {
-
fclose(fp);
printf("Error: failed to allocate image buffer\n");
return -1;
@@ -41,8 +38,8 @@
/* Read file contents into buffer */
if (fread(img_buf, 1, img_size, fp)) {
-
fclose(fp);
+ free(img_buf);
printf("Error: failed to read image file\n");
return -1;
}
diff --git a/deployments/fwu/env/posix/cmd_update_image.h b/deployments/fwu/env/posix/cmd_update_image.h
index b0fe6ae..7091bd2 100644
--- a/deployments/fwu/env/posix/cmd_update_image.h
+++ b/deployments/fwu/env/posix/cmd_update_image.h
@@ -9,11 +9,10 @@
#define CMD_UPDATE_IMAGE_H
#include <string>
-#include <service/fwu/app/fwu_app.h>
-int cmd_update_image(
- fwu_app &app,
- const std::string &img_type_uuid,
- const std::string &img_filename);
+#include "service/fwu/app/fwu_app.h"
+
+int cmd_update_image(fwu_app &app, const std::string &img_type_uuid,
+ const std::string &img_filename);
#endif /* CMD_UPDATE_IMAGE_H */
diff --git a/deployments/fwu/env/posix/fwu_main.cpp b/deployments/fwu/env/posix/fwu_main.cpp
index e01640a..88bac76 100644
--- a/deployments/fwu/env/posix/fwu_main.cpp
+++ b/deployments/fwu/env/posix/fwu_main.cpp
@@ -7,37 +7,29 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
-#include <string>
#include <sstream>
+#include <string>
#include <sys/stat.h>
-#include <common/uuid/uuid.h>
-#include <service/fwu/app/fwu_app.h>
-#include "cmd_update_image.h"
+
#include "cmd_print_image_dir.h"
#include "cmd_print_metadata_v1.h"
#include "cmd_print_metadata_v2.h"
+#include "cmd_update_image.h"
+#include "common/uuid/uuid.h"
+#include "service/fwu/app/fwu_app.h"
-static bool option_selected(
- const char *option_switch,
- int argc, char *argv[]);
+static bool option_selected(const char *option_switch, int argc, char *argv[]);
-static std::string parse_string_option(
- const char *option_switch,
- int argc, char *argv[],
- const char *default_val);
+static std::string parse_string_option(const char *option_switch, int argc, char *argv[],
+ const char *default_val);
-static int parse_numeric_option(
- const char *option_switch,
- int argc, char *argv[],
- int default_val);
+static int parse_numeric_option(const char *option_switch, int argc, char *argv[], int default_val);
-static bool file_exists(
- const std::string &filename);
+static bool file_exists(const std::string &filename);
static void print_usage(void);
static void print_help(void);
-
int main(int argc, char *argv[])
{
fwu_app app;
@@ -46,10 +38,8 @@
std::string img_type_uuid;
/* Check for help */
- if (option_selected("-h", argc, argv) ||
- option_selected("-help", argc, argv) ||
- option_selected("--help", argc, argv)) {
-
+ if (option_selected("-h", argc, argv) || option_selected("-help", argc, argv) ||
+ option_selected("--help", argc, argv)) {
print_help();
return 0;
}
@@ -58,7 +48,6 @@
if (argc > 1)
disk_img_filename = std::string(argv[1]);
else {
-
printf("Error: missing disk-filename argument\n");
print_usage();
return -1;
@@ -66,7 +55,6 @@
/* Check if disk image file exists */
if (!file_exists(disk_img_filename)) {
-
printf("Error: %s does not exist\n", disk_img_filename.c_str());
return -1;
}
@@ -75,7 +63,6 @@
int status = app.configure(disk_img_filename.c_str());
if (status) {
-
printf("Error: failed to configure with status: %d\n", status);
return -1;
}
@@ -89,7 +76,6 @@
status = app.get_boot_info(boot_index, metadata_version);
if (status) {
-
printf("No recognised metadata, assume default boot index and version\n");
boot_index = 0;
@@ -110,14 +96,12 @@
/* Check if image file exists (if one was specified) */
if (!update_img_filename.empty() && !file_exists(update_img_filename)) {
-
printf("Error: %s does not exist\n", update_img_filename.c_str());
return -1;
}
/* Check if img type canonical uuid is well formed */
if (!img_type_uuid.empty() && !uuid_is_valid(img_type_uuid.c_str())) {
-
printf("Error: image type uuid invalid\n");
return -1;
}
@@ -127,30 +111,25 @@
status = app.init_update_agent(boot_index, metadata_version);
if (!status) {
-
- printf("Update agent started: boot index: %d metadata ver: %d\n",
- boot_index, metadata_version);
+ printf("Update agent started: boot index: %u metadata ver: %u\n", boot_index,
+ metadata_version);
if (is_print_img_dir)
cmd_print_image_dir(app);
if (is_print_metadata) {
-
if (metadata_version == 1)
cmd_print_metadata_v1(app);
else if (metadata_version == 2)
cmd_print_metadata_v2(app);
else
printf("Unsupported metadata version\n");
-
}
if (!update_img_filename.empty() && !img_type_uuid.empty()) {
-
status = cmd_update_image(app, img_type_uuid, update_img_filename);
} else if (!update_img_filename.empty() || !img_type_uuid.empty()) {
-
printf("Error: both image filename and uuid arguments are needed\n");
return -1;
}
@@ -164,31 +143,24 @@
return status;
}
-static bool option_selected(
- const char *option_switch,
- int argc, char *argv[])
+static bool option_selected(const char *option_switch, int argc, char *argv[])
{
bool is_selected = false;
for (int i = 1; (i < argc) && !is_selected; ++i) {
-
is_selected = (strcmp(argv[i], option_switch) == 0);
}
return is_selected;
}
-static std::string parse_string_option(
- const char *option_switch,
- int argc, char *argv[],
- const char *default_val)
+static std::string parse_string_option(const char *option_switch, int argc, char *argv[],
+ const char *default_val)
{
std::string option = std::string(default_val);
for (int i = 1; i + 1 < argc; ++i) {
-
if (strcmp(argv[i], option_switch) == 0) {
-
option = std::string(argv[i + 1]);
break;
}
@@ -197,17 +169,12 @@
return option;
}
-static int parse_numeric_option(
- const char *option_switch,
- int argc, char *argv[],
- int default_val)
+static int parse_numeric_option(const char *option_switch, int argc, char *argv[], int default_val)
{
int option = default_val;
for (int i = 1; i + 1 < argc; ++i) {
-
if (strcmp(argv[i], option_switch) == 0) {
-
std::istringstream iss(argv[i + 1]);
int val;
@@ -233,7 +200,7 @@
static void print_usage(void)
{
printf("Usage: fwu disk-filename [-dir -meta] [-boot-index number -meta-ver number] "
- "[-img filename -img-type uuid]\n");
+ "[-img filename -img-type uuid]\n");
}
static void print_help(void)
@@ -249,4 +216,3 @@
printf("\t-img\t\tFile containing image update\n");
printf("\t-img-type\tCanonical UUID of image to update\n");
}
-
diff --git a/deployments/fwu/env/posix/print_uuid.cpp b/deployments/fwu/env/posix/print_uuid.cpp
index 6cfbdcd..a65bac1 100644
--- a/deployments/fwu/env/posix/print_uuid.cpp
+++ b/deployments/fwu/env/posix/print_uuid.cpp
@@ -4,9 +4,10 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <common/uuid/uuid.h>
#include "print_uuid.h"
+#include "common/uuid/uuid.h"
+
std::string print_uuid(const uint8_t *uuid_octets)
{
struct uuid_canonical canonical_uuid;
diff --git a/environments/posix/posix_trace.c b/environments/posix/posix_trace.c
index a0df51b..2e6b8cb 100644
--- a/environments/posix/posix_trace.c
+++ b/environments/posix/posix_trace.c
@@ -4,7 +4,8 @@
*/
#include <stdio.h>
-#include <trace.h>
+
+#include "trace.h"
#if TRACE_LEVEL >= TRACE_LEVEL_ERROR
@@ -13,4 +14,4 @@
puts(str);
}
-#endif /* TRACE_LEVEL >= TRACE_LEVEL_ERROR */
+#endif /* TRACE_LEVEL >= TRACE_LEVEL_ERROR */
diff --git a/protocols/common/osf/uuid.h b/protocols/common/osf/uuid.h
index d5cbd9c..be0e9ea 100644
--- a/protocols/common/osf/uuid.h
+++ b/protocols/common/osf/uuid.h
@@ -12,12 +12,12 @@
/**
* Octet length for standard binary encoded UUID in Big Endian byte order (see RFC4122)
*/
-#define OSF_UUID_OCTET_LEN (16)
+#define OSF_UUID_OCTET_LEN (16)
/**
* Character length of a canonical form UUID string
* e.g. 123e4567-e89b-12d3-a456-426614174000
*/
-#define OSF_UUID_CANONICAL_FORM_LEN (36)
+#define OSF_UUID_CANONICAL_FORM_LEN (36)
#endif /* COMMON_OSF_UUID_H */
diff --git a/protocols/service/fwu/packed-c/fwu_proto.h b/protocols/service/fwu/packed-c/fwu_proto.h
index a1bb644..6cd691a 100644
--- a/protocols/service/fwu/packed-c/fwu_proto.h
+++ b/protocols/service/fwu/packed-c/fwu_proto.h
@@ -8,8 +8,9 @@
#define FWU_PROTO_H
#include <stdint.h>
-#include <protocols/common/osf/uuid.h>
+
#include "opcodes.h"
+#include "protocols/common/osf/uuid.h"
#include "status.h"
/**
@@ -27,19 +28,18 @@
/**
* Protocol GUIDs defined in FWU-A specification
*/
-#define FWU_UPDATE_AGENT_CANONICAL_UUID "6823a838-1b06-470e-9774-0cce8bfb53fd"
-#define FWU_DIRECTORY_CANONICAL_UUID "deee58d9-5147-4ad3-a290-77666e2341a5"
-#define FWU_METADATA_CANONICAL_UUID "8a7a84a0-8387-40f6-ab41-a8b9a5a60d23"
+#define FWU_UPDATE_AGENT_CANONICAL_UUID "6823a838-1b06-470e-9774-0cce8bfb53fd"
+#define FWU_DIRECTORY_CANONICAL_UUID "deee58d9-5147-4ad3-a290-77666e2341a5"
+#define FWU_METADATA_CANONICAL_UUID "8a7a84a0-8387-40f6-ab41-a8b9a5a60d23"
/**
* Image directory
*/
-#define FWU_READ_PERM (1u << 1)
-#define FWU_WRITE_PERM (1u << 0)
+#define FWU_READ_PERM (1u << 1)
+#define FWU_WRITE_PERM (1u << 0)
-struct __attribute__ ((__packed__)) ts_fwu_image_info_entry
-{
- uint8_t img_type_uuid[OSF_UUID_OCTET_LEN];
+struct __attribute__((__packed__)) ts_fwu_image_info_entry {
+ uint8_t img_type_uuid[OSF_UUID_OCTET_LEN];
uint32_t client_permissions;
uint32_t img_max_size;
uint32_t lowest_accepted_version;
@@ -48,8 +48,7 @@
uint32_t reserved;
};
-struct __attribute__ ((__packed__)) ts_fwu_image_directory
-{
+struct __attribute__((__packed__)) ts_fwu_image_directory {
uint32_t directory_version;
uint32_t img_info_offset;
uint32_t num_images;
@@ -63,60 +62,51 @@
* Message parameters
*/
-struct __attribute__ ((__packed__)) ts_fwu_discover_out
-{
- uint8_t version_major;
- uint8_t version_minor;
+struct __attribute__((__packed__)) ts_fwu_discover_out {
+ uint8_t version_major;
+ uint8_t version_minor;
uint16_t num_func;
- uint8_t function_presence[];
+ uint8_t function_presence[];
};
-struct __attribute__ ((__packed__)) ts_fwu_open_in
-{
- uint8_t image_type_uuid[OSF_UUID_OCTET_LEN];
+struct __attribute__((__packed__)) ts_fwu_open_in {
+ uint8_t image_type_uuid[OSF_UUID_OCTET_LEN];
};
-struct __attribute__ ((__packed__)) ts_fwu_open_out
-{
+struct __attribute__((__packed__)) ts_fwu_open_out {
uint32_t handle;
};
-struct __attribute__ ((__packed__)) ts_fwu_write_stream_in
-{
+struct __attribute__((__packed__)) ts_fwu_write_stream_in {
uint32_t handle;
uint32_t data_len;
- uint8_t payload[];
+ uint8_t payload[];
};
-struct __attribute__ ((__packed__)) ts_fwu_read_stream_in
-{
+struct __attribute__((__packed__)) ts_fwu_read_stream_in {
uint32_t handle;
};
-struct __attribute__ ((__packed__)) ts_fwu_read_stream_out
-{
+struct __attribute__((__packed__)) ts_fwu_read_stream_out {
uint32_t read_bytes;
uint32_t total_bytes;
- uint8_t payload[];
+ uint8_t payload[];
};
-struct __attribute__ ((__packed__)) ts_fwu_commit_in
-{
+struct __attribute__((__packed__)) ts_fwu_commit_in {
uint32_t handle;
uint32_t acceptance_req;
uint32_t max_atomic_len;
};
-struct __attribute__ ((__packed__)) ts_fwu_commit_out
-{
+struct __attribute__((__packed__)) ts_fwu_commit_out {
uint32_t progress;
uint32_t total_work;
};
-struct __attribute__ ((__packed__)) ts_fwu_accept_image_in
-{
+struct __attribute__((__packed__)) ts_fwu_accept_image_in {
uint32_t reserved;
- uint8_t image_type_uuid[OSF_UUID_OCTET_LEN];
+ uint8_t image_type_uuid[OSF_UUID_OCTET_LEN];
};
#endif /* FWU_PROTO_H */
diff --git a/protocols/service/fwu/packed-c/metadata.h b/protocols/service/fwu/packed-c/metadata.h
index b89cc9e..7a3c4fb 100644
--- a/protocols/service/fwu/packed-c/metadata.h
+++ b/protocols/service/fwu/packed-c/metadata.h
@@ -16,7 +16,7 @@
* With the default configuration, a dual bank A/B scheme is used.
*/
#ifndef FWU_METADATA_NUM_BANKS
-#define FWU_METADATA_NUM_BANKS (2)
+#define FWU_METADATA_NUM_BANKS (2)
#endif
#endif /* FWU_PROTO_METADATA_H */
diff --git a/protocols/service/fwu/packed-c/metadata_v1.h b/protocols/service/fwu/packed-c/metadata_v1.h
index 2271c9b..cb264da 100644
--- a/protocols/service/fwu/packed-c/metadata_v1.h
+++ b/protocols/service/fwu/packed-c/metadata_v1.h
@@ -12,24 +12,24 @@
#define FWU_PROTO_METADATA_V1_H
#include <stdint.h>
-#include <protocols/common/osf/uuid.h>
+
#include "metadata.h"
+#include "protocols/common/osf/uuid.h"
/**
* FWU metadata version corresponding to these structure definitions.
*/
-#define FWU_METADATA_VERSION (1)
+#define FWU_METADATA_VERSION (1)
/**
* The number of image entries in the metadata structure.
*/
#ifndef FWU_METADATA_NUM_IMAGE_ENTRIES
-#define FWU_METADATA_NUM_IMAGE_ENTRIES (1)
+#define FWU_METADATA_NUM_IMAGE_ENTRIES (1)
#endif
/* Properties of image in a bank */
-struct __attribute__ ((__packed__)) fwu_image_properties {
-
+struct __attribute__((__packed__)) fwu_image_properties {
/* UUID of the image in this bank */
uint8_t img_uuid[OSF_UUID_OCTET_LEN];
@@ -41,12 +41,10 @@
/* reserved (MBZ) */
uint32_t reserved;
-
};
/* Image entry information */
-struct __attribute__ ((__packed__)) fwu_image_entry {
-
+struct __attribute__((__packed__)) fwu_image_entry {
/* UUID identifying the image type */
uint8_t img_type_uuid[OSF_UUID_OCTET_LEN];
@@ -55,7 +53,6 @@
/* Properties of images with img_type_uuid in the different FW banks */
struct fwu_image_properties img_props[FWU_METADATA_NUM_BANKS];
-
};
/*
@@ -65,8 +62,7 @@
* 2. Rollback to previous working FW bank.
* 3. Get properties of all images present in all banks.
*/
-struct __attribute__ ((__packed__)) fwu_metadata {
-
+struct __attribute__((__packed__)) fwu_metadata {
/* Metadata CRC value */
uint32_t crc_32;
@@ -81,7 +77,6 @@
/* Image entry information */
struct fwu_image_entry img_entry[FWU_METADATA_NUM_IMAGE_ENTRIES];
-
};
#endif /* FWU_PROTO_METADATA_V1_H */
diff --git a/protocols/service/fwu/packed-c/metadata_v2.h b/protocols/service/fwu/packed-c/metadata_v2.h
index 5cac380..33efb33 100644
--- a/protocols/service/fwu/packed-c/metadata_v2.h
+++ b/protocols/service/fwu/packed-c/metadata_v2.h
@@ -12,14 +12,15 @@
#define FWU_PROTO_METADATA_V2_H
#include <stdint.h>
-#include <protocols/common/osf/uuid.h>
+
#include "metadata.h"
+#include "protocols/common/osf/uuid.h"
/* Bank state definitions */
-#define FWU_METADATA_V2_NUM_BANK_STATES (4)
-#define FWU_METADATA_V2_BANK_STATE_INVALID (0xff)
-#define FWU_METADATA_V2_BANK_STATE_VALID (0xfe)
-#define FWU_METADATA_V2_BANK_STATE_ACCEPTED (0xfc)
+#define FWU_METADATA_V2_NUM_BANK_STATES (4)
+#define FWU_METADATA_V2_BANK_STATE_INVALID (0xff)
+#define FWU_METADATA_V2_BANK_STATE_VALID (0xfe)
+#define FWU_METADATA_V2_BANK_STATE_ACCEPTED (0xfc)
/*
* Version 2 FWU metadata data structure (mandatory)
@@ -27,8 +28,7 @@
* The metadata structure is variable length. The actual length is determined
* from the metadata_size member.
*/
-struct __attribute__ ((__packed__)) fwu_metadata {
-
+struct __attribute__((__packed__)) fwu_metadata {
/* Metadata CRC value */
uint32_t crc_32;
@@ -49,12 +49,10 @@
/* Bank state bitmaps */
uint8_t bank_state[FWU_METADATA_V2_NUM_BANK_STATES];
-
};
/* Properties of image in a bank */
-struct __attribute__ ((__packed__)) fwu_img_bank_info {
-
+struct __attribute__((__packed__)) fwu_img_bank_info {
/* UUID of the image in this bank */
uint8_t img_uuid[OSF_UUID_OCTET_LEN];
@@ -66,12 +64,10 @@
/* reserved (MBZ) */
uint32_t reserved;
-
};
/* Image entry information */
-struct __attribute__ ((__packed__)) fwu_image_entry {
-
+struct __attribute__((__packed__)) fwu_image_entry {
/* UUID identifying the image type */
uint8_t img_type_uuid[OSF_UUID_OCTET_LEN];
@@ -80,7 +76,6 @@
/* Per-bank info related to the image */
struct fwu_img_bank_info img_bank_info[FWU_METADATA_NUM_BANKS];
-
};
/*
@@ -92,8 +87,7 @@
* not required. The fw_store_desc is assumed to be present if metadata_size
* > header_size.
*/
-struct __attribute__ ((__packed__)) fwu_fw_store_desc {
-
+struct __attribute__((__packed__)) fwu_fw_store_desc {
/* Number of banks */
uint8_t num_banks;
diff --git a/protocols/service/fwu/packed-c/opcodes.h b/protocols/service/fwu/packed-c/opcodes.h
index b900677..1905a65 100644
--- a/protocols/service/fwu/packed-c/opcodes.h
+++ b/protocols/service/fwu/packed-c/opcodes.h
@@ -10,15 +10,15 @@
/**
* Service-level opcodes
*/
-#define TS_FWU_OPCODE_BASE (0x10)
-#define TS_FWU_OPCODE_BEGIN_STAGING (TS_FWU_OPCODE_BASE + 0)
-#define TS_FWU_OPCODE_END_STAGING (TS_FWU_OPCODE_BASE + 1)
-#define TS_FWU_OPCODE_CANCEL_STAGING (TS_FWU_OPCODE_BASE + 2)
-#define TS_FWU_OPCODE_OPEN (TS_FWU_OPCODE_BASE + 3)
-#define TS_FWU_OPCODE_WRITE_STREAM (TS_FWU_OPCODE_BASE + 4)
-#define TS_FWU_OPCODE_READ_STREAM (TS_FWU_OPCODE_BASE + 5)
-#define TS_FWU_OPCODE_COMMIT (TS_FWU_OPCODE_BASE + 6)
-#define TS_FWU_OPCODE_ACCEPT_IMAGE (TS_FWU_OPCODE_BASE + 7)
-#define TS_FWU_OPCODE_SELECT_PREVIOUS (TS_FWU_OPCODE_BASE + 8)
+#define TS_FWU_OPCODE_BASE (0x10)
+#define TS_FWU_OPCODE_BEGIN_STAGING (TS_FWU_OPCODE_BASE + 0)
+#define TS_FWU_OPCODE_END_STAGING (TS_FWU_OPCODE_BASE + 1)
+#define TS_FWU_OPCODE_CANCEL_STAGING (TS_FWU_OPCODE_BASE + 2)
+#define TS_FWU_OPCODE_OPEN (TS_FWU_OPCODE_BASE + 3)
+#define TS_FWU_OPCODE_WRITE_STREAM (TS_FWU_OPCODE_BASE + 4)
+#define TS_FWU_OPCODE_READ_STREAM (TS_FWU_OPCODE_BASE + 5)
+#define TS_FWU_OPCODE_COMMIT (TS_FWU_OPCODE_BASE + 6)
+#define TS_FWU_OPCODE_ACCEPT_IMAGE (TS_FWU_OPCODE_BASE + 7)
+#define TS_FWU_OPCODE_SELECT_PREVIOUS (TS_FWU_OPCODE_BASE + 8)
#endif /* FWU_PROTO_OPCODES_H */
diff --git a/protocols/service/fwu/packed-c/status.h b/protocols/service/fwu/packed-c/status.h
index b53e8b8..6d3e90b 100644
--- a/protocols/service/fwu/packed-c/status.h
+++ b/protocols/service/fwu/packed-c/status.h
@@ -10,14 +10,14 @@
/**
* Service-level status codes
*/
-#define FWU_STATUS_SUCCESS ((int32_t)0)
-#define FWU_STATUS_UNKNOWN ((int32_t)-1)
-#define FWU_STATUS_BUSY ((int32_t)-2)
+#define FWU_STATUS_SUCCESS ((int32_t)0)
+#define FWU_STATUS_UNKNOWN ((int32_t)-1)
+#define FWU_STATUS_BUSY ((int32_t)-2)
#define FWU_STATUS_OUT_OF_BOUNDS ((int32_t)-3)
-#define FWU_STATUS_AUTH_FAIL ((int32_t)-4)
+#define FWU_STATUS_AUTH_FAIL ((int32_t)-4)
#define FWU_STATUS_NO_PERMISSION ((int32_t)-5)
-#define FWU_STATUS_DENIED ((int32_t)-6)
-#define FWU_STATUS_RESUME ((int32_t)-7)
+#define FWU_STATUS_DENIED ((int32_t)-6)
+#define FWU_STATUS_RESUME ((int32_t)-7)
#define FWU_STATUS_NOT_AVAILABLE ((int32_t)-8)
#endif /* FWU_PROTO_STATUS_H */