Extend storage partition info for FWU
The block_store interface provides a method for retrieving
information about storage partitions. This commit extends
the information retrieved to include the partition GUID
and the disk GUID of a containing parent, if it exists.
This extra information is needed to allow the FWU fw_directory
to be populated with information about where update images
need to be installed.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I57934a32feda540b2da5429d5333a4a597e3f308
diff --git a/components/service/block_storage/block_store/block_store.h b/components/service/block_storage/block_store/block_store.h
index 341e365..e2575d7 100644
--- a/components/service/block_storage/block_store/block_store.h
+++ b/components/service/block_storage/block_store/block_store.h
@@ -33,8 +33,20 @@
*/
struct storage_partition_info
{
- size_t num_blocks; /* Number of contiguous blocks from LBA zero */
- size_t block_size; /* Block size in bytes */
+ /* Number of contiguous blocks from LBA zero */
+ size_t num_blocks;
+
+ /* Block size in bytes */
+ size_t block_size;
+
+ /* The unique partition GUID */
+ struct uuid_octets partition_guid;
+
+ /* GUID of the parent partition/device e.g. the disk GUID of the disk that
+ * contains the subject storage partition. A nil UUID should be returned if
+ * there is no parent.
+ */
+ struct uuid_octets parent_guid;
};
/**
diff --git a/components/service/block_storage/block_store/client/block_storage_client.c b/components/service/block_storage/block_store/client/block_storage_client.c
index 04b345e..5a7b491 100644
--- a/components/service/block_storage/block_store/client/block_storage_client.c
+++ b/components/service/block_storage/block_store/client/block_storage_client.c
@@ -57,7 +57,16 @@
info->block_size = resp_msg.block_size;
info->num_blocks = resp_msg.num_blocks;
- } else {
+
+ memcpy(info->partition_guid.octets,
+ resp_msg.partition_guid,
+ TS_BLOCK_STORAGE_GUID_OCTET_LEN);
+
+ memcpy(info->parent_guid.octets,
+ resp_msg.parent_guid,
+ TS_BLOCK_STORAGE_GUID_OCTET_LEN);
+ }
+ else {
/* Failed to decode response message */
psa_status = PSA_ERROR_GENERIC_ERROR;
}
diff --git a/components/service/block_storage/block_store/device/block_device.c b/components/service/block_storage/block_store/device/block_device.c
index dd3abd0..c355e82 100644
--- a/components/service/block_storage/block_store/device/block_device.c
+++ b/components/service/block_storage/block_store/device/block_device.c
@@ -5,6 +5,7 @@
*
*/
+#include <string.h>
#include "block_device.h"
#define BLOCK_DEVICE_PARTITION_HANDLE (0)
@@ -34,6 +35,11 @@
info->block_size = block_device->storage_partition.block_size;
info->num_blocks = block_device->storage_partition.num_blocks;
+ info->partition_guid = block_device->storage_partition.partition_guid;
+
+ /* A block_device has no parent so return a nil UUID */
+ memset(info->parent_guid.octets, 0, sizeof(info->parent_guid.octets));
+
status = PSA_SUCCESS;
}
diff --git a/components/service/block_storage/block_store/device/ram/test/ram_block_store_tests.cpp b/components/service/block_storage/block_store/device/ram/test/ram_block_store_tests.cpp
index f7ba5b0..5e9537f 100644
--- a/components/service/block_storage/block_store/device/ram/test/ram_block_store_tests.cpp
+++ b/components/service/block_storage/block_store/device/ram/test/ram_block_store_tests.cpp
@@ -47,6 +47,8 @@
LONGS_EQUAL(PSA_SUCCESS, status);
LONGS_EQUAL(NUM_BLOCKS, info.num_blocks);
LONGS_EQUAL(BLOCK_SIZE, info.block_size);
+ MEMCMP_EQUAL(m_partition_guid.octets,
+ info.partition_guid.octets, sizeof(info.partition_guid.octets));
}
TEST(RamBlockStoreTests, openClose)
diff --git a/components/service/block_storage/block_store/partitioned/partitioned_block_store.c b/components/service/block_storage/block_store/partitioned/partitioned_block_store.c
index a2ac1bd..735dead 100644
--- a/components/service/block_storage/block_store/partitioned/partitioned_block_store.c
+++ b/components/service/block_storage/block_store/partitioned/partitioned_block_store.c
@@ -89,6 +89,8 @@
info->block_size = partition->block_size;
info->num_blocks = partition->num_blocks;
+ info->partition_guid = partition->partition_guid;
+ info->parent_guid = partitioned_block_store->back_store_info.partition_guid;
}
return status;
diff --git a/components/service/block_storage/block_store/partitioned/test/partitioned_block_store_tests.cpp b/components/service/block_storage/block_store/partitioned/test/partitioned_block_store_tests.cpp
index a499b95..12541bf 100644
--- a/components/service/block_storage/block_store/partitioned/test/partitioned_block_store_tests.cpp
+++ b/components/service/block_storage/block_store/partitioned/test/partitioned_block_store_tests.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2022-2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -15,12 +15,12 @@
void setup()
{
/* Initialize a ram_block_store to use as the back store */
- struct uuid_octets back_store_guid;
- memset(&back_store_guid, 0, sizeof(back_store_guid));
+ uuid_guid_octets_from_canonical(&m_back_store_guid,
+ "6ec10ff6-4252-4ef7-aeca-5036db6697df");
struct block_store *back_store = ram_block_store_init(
&m_ram_store,
- &back_store_guid,
+ &m_back_store_guid,
BACK_STORE_NUM_BLOCKS,
BACK_STORE_BLOCK_SIZE);
@@ -30,7 +30,7 @@
m_block_store = partitioned_block_store_init(
&m_partitioned_store,
LOCAL_CLIENT_ID,
- &back_store_guid,
+ &m_back_store_guid,
back_store,
NULL);
@@ -84,6 +84,7 @@
struct partitioned_block_store m_partitioned_store;
struct uuid_octets m_partition_1_guid;
struct uuid_octets m_partition_2_guid;
+ struct uuid_octets m_back_store_guid;
};
TEST(PartitionedBlockStoreTests, getPartitionInfo)
@@ -97,6 +98,10 @@
LONGS_EQUAL(PSA_SUCCESS, status);
LONGS_EQUAL(PARTITION_1_ENDING_LBA - PARTITION_1_STARTING_LBA + 1, info.num_blocks);
LONGS_EQUAL(BACK_STORE_BLOCK_SIZE, info.block_size);
+ MEMCMP_EQUAL(m_partition_1_guid.octets,
+ info.partition_guid.octets, sizeof(info.partition_guid.octets));
+ MEMCMP_EQUAL(m_back_store_guid.octets,
+ info.parent_guid.octets, sizeof(info.parent_guid.octets));
/* Check partition info for partition 2 */
status = block_store_get_partition_info(
@@ -105,6 +110,10 @@
LONGS_EQUAL(PSA_SUCCESS, status);
LONGS_EQUAL(PARTITION_2_ENDING_LBA - PARTITION_2_STARTING_LBA + 1, info.num_blocks);
LONGS_EQUAL(BACK_STORE_BLOCK_SIZE, info.block_size);
+ MEMCMP_EQUAL(m_partition_2_guid.octets,
+ info.partition_guid.octets, sizeof(info.partition_guid.octets));
+ MEMCMP_EQUAL(m_back_store_guid.octets,
+ info.parent_guid.octets, sizeof(info.parent_guid.octets));
}
TEST(PartitionedBlockStoreTests, openClose)
diff --git a/components/service/block_storage/provider/serializer/packed-c/packedc_block_storage_serializer.c b/components/service/block_storage/provider/serializer/packed-c/packedc_block_storage_serializer.c
index cb5fd7a..7946a47 100644
--- a/components/service/block_storage/provider/serializer/packed-c/packedc_block_storage_serializer.c
+++ b/components/service/block_storage/provider/serializer/packed-c/packedc_block_storage_serializer.c
@@ -39,6 +39,12 @@
resp_msg.num_blocks = info->num_blocks;
resp_msg.block_size = info->block_size;
+ memcpy(resp_msg.partition_guid,
+ info->partition_guid.octets, TS_BLOCK_STORAGE_GUID_OCTET_LEN);
+
+ memcpy(resp_msg.parent_guid,
+ info->parent_guid.octets, TS_BLOCK_STORAGE_GUID_OCTET_LEN);
+
if (fixed_len <= resp_buf->size) {
memcpy(resp_buf->data, &resp_msg, fixed_len);
diff --git a/components/service/block_storage/test/service/block_storage_service_tests.cpp b/components/service/block_storage/test/service/block_storage_service_tests.cpp
index 3c376d9..3899a04 100644
--- a/components/service/block_storage/test/service/block_storage_service_tests.cpp
+++ b/components/service/block_storage/test/service/block_storage_service_tests.cpp
@@ -61,40 +61,40 @@
m_block_store, &m_partition_1_guid, &info);
LONGS_EQUAL(PSA_SUCCESS, status);
- UNSIGNED_LONGS_EQUAL(
- REF_PARTITION_1_ENDING_LBA - REF_PARTITION_1_STARTING_LBA + 1,
- info.num_blocks);
- UNSIGNED_LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
+ LONGS_EQUAL(REF_PARTITION_1_ENDING_LBA - REF_PARTITION_1_STARTING_LBA + 1, info.num_blocks);
+ LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
+ MEMCMP_EQUAL(m_partition_1_guid.octets,
+ info.partition_guid.octets, sizeof(info.partition_guid.octets));
/* Check partition info for partition 2 */
status = block_store_get_partition_info(
m_block_store, &m_partition_2_guid, &info);
LONGS_EQUAL(PSA_SUCCESS, status);
- UNSIGNED_LONGS_EQUAL(
- REF_PARTITION_2_ENDING_LBA - REF_PARTITION_2_STARTING_LBA + 1,
- info.num_blocks);
- UNSIGNED_LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
+ LONGS_EQUAL(REF_PARTITION_2_ENDING_LBA - REF_PARTITION_2_STARTING_LBA + 1, info.num_blocks);
+ LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
+ MEMCMP_EQUAL(m_partition_2_guid.octets,
+ info.partition_guid.octets, sizeof(info.partition_guid.octets));
/* Check partition info for partition 3 */
status = block_store_get_partition_info(
m_block_store, &m_partition_3_guid, &info);
LONGS_EQUAL(PSA_SUCCESS, status);
- UNSIGNED_LONGS_EQUAL(
- REF_PARTITION_3_ENDING_LBA - REF_PARTITION_3_STARTING_LBA + 1,
- info.num_blocks);
- UNSIGNED_LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
+ LONGS_EQUAL(REF_PARTITION_3_ENDING_LBA - REF_PARTITION_3_STARTING_LBA + 1, info.num_blocks);
+ LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
+ MEMCMP_EQUAL(m_partition_3_guid.octets,
+ info.partition_guid.octets, sizeof(info.partition_guid.octets));
/* Check partition info for partition 4 */
status = block_store_get_partition_info(
m_block_store, &m_partition_4_guid, &info);
LONGS_EQUAL(PSA_SUCCESS, status);
- UNSIGNED_LONGS_EQUAL(
- REF_PARTITION_4_ENDING_LBA - REF_PARTITION_4_STARTING_LBA + 1,
- info.num_blocks);
- UNSIGNED_LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
+ LONGS_EQUAL(REF_PARTITION_4_ENDING_LBA - REF_PARTITION_4_STARTING_LBA + 1, info.num_blocks);
+ LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
+ MEMCMP_EQUAL(m_partition_4_guid.octets,
+ info.partition_guid.octets, sizeof(info.partition_guid.octets));
}
TEST(BlockStorageServiceTests, openClose)
diff --git a/protocols/service/block_storage/packed-c/messages.h b/protocols/service/block_storage/packed-c/messages.h
index 7769912..fc17d79 100644
--- a/protocols/service/block_storage/packed-c/messages.h
+++ b/protocols/service/block_storage/packed-c/messages.h
@@ -28,14 +28,16 @@
/* Mandatory fixed sized input parameters */
struct __attribute__ ((__packed__)) ts_block_storage_get_partition_info_in
{
- uint8_t partition_guid[TS_BLOCK_STORAGE_GUID_OCTET_LEN];
+ uint8_t partition_guid[TS_BLOCK_STORAGE_GUID_OCTET_LEN];
};
/* Mandatory fixed sized output parameters */
struct __attribute__ ((__packed__)) ts_block_storage_get_partition_info_out
{
- uint32_t num_blocks;
- uint32_t block_size;
+ uint32_t num_blocks;
+ uint32_t block_size;
+ uint8_t partition_guid[TS_BLOCK_STORAGE_GUID_OCTET_LEN];
+ uint8_t parent_guid[TS_BLOCK_STORAGE_GUID_OCTET_LEN];
};
/****************************************
@@ -49,13 +51,13 @@
/* Mandatory fixed sized input parameters */
struct __attribute__ ((__packed__)) ts_block_storage_open_in
{
- uint8_t partition_guid[TS_BLOCK_STORAGE_GUID_OCTET_LEN];
+ uint8_t partition_guid[TS_BLOCK_STORAGE_GUID_OCTET_LEN];
};
/* Mandatory fixed sized output parameters */
struct __attribute__ ((__packed__)) ts_block_storage_open_out
{
- uint64_t handle;
+ uint64_t handle;
};
/****************************************
@@ -68,7 +70,7 @@
/* Mandatory fixed sized input parameters */
struct __attribute__ ((__packed__)) ts_block_storage_close_in
{
- uint64_t handle;
+ uint64_t handle;
};
/****************************************
@@ -80,10 +82,10 @@
/* Mandatory fixed sized input parameters */
struct __attribute__ ((__packed__)) ts_block_storage_read_in
{
- uint64_t handle;
- uint32_t lba;
- uint32_t offset;
- uint32_t len;
+ uint64_t handle;
+ uint32_t lba;
+ uint32_t offset;
+ uint32_t len;
};
/* Read data returned in response */
@@ -97,9 +99,9 @@
/* Mandatory fixed sized input parameters */
struct __attribute__ ((__packed__)) ts_block_storage_write_in
{
- uint64_t handle;
- uint32_t lba;
- uint32_t offset;
+ uint64_t handle;
+ uint32_t lba;
+ uint32_t offset;
};
/* Write data follows fixed size input message */
@@ -107,7 +109,7 @@
/* Mandatory fixed sized output parameters */
struct __attribute__ ((__packed__)) ts_block_storage_write_out
{
- uint64_t num_written;
+ uint64_t num_written;
};
/****************************************
@@ -119,9 +121,9 @@
/* Mandatory fixed sized input parameters */
struct __attribute__ ((__packed__)) ts_block_storage_erase_in
{
- uint64_t handle;
- uint32_t begin_lba;
- uint32_t num_blocks;
+ uint64_t handle;
+ uint32_t begin_lba;
+ uint32_t num_blocks;
};
#endif /* TS_BLOCK_STORAGE_PACKEDC_MESSAGES_H */