SST: Add ability to disable partial asset rw
- This patch adds compile time ability to disable partial asset RW
manipulation.
- Partial asset manipulation is allowed by default.
Change-Id: I9ddb527ee050cfe8fde2fccc9801025d6e5dfc71
Signed-off-by: Ben Davis <ben.davis@arm.com>
diff --git a/CommonConfig.cmake b/CommonConfig.cmake
index 6f7dab1..c0ac875 100755
--- a/CommonConfig.cmake
+++ b/CommonConfig.cmake
@@ -180,6 +180,10 @@
if (NOT DEFINED SST_VALIDATE_METADATA_FROM_FLASH)
set (SST_VALIDATE_METADATA_FROM_FLASH ON)
endif()
+
+ if (NOT DEFINED SST_ENABLE_PARTIAL_ASSET_RW)
+ set (SST_ENABLE_PARTIAL_ASSET_RW ON)
+ endif()
endif()
if (NOT DEFINED MBEDTLS_DEBUG)
diff --git a/secure_fw/services/secure_storage/CMakeLists.inc b/secure_fw/services/secure_storage/CMakeLists.inc
index 09082cf..f691085 100644
--- a/secure_fw/services/secure_storage/CMakeLists.inc
+++ b/secure_fw/services/secure_storage/CMakeLists.inc
@@ -68,6 +68,10 @@
set_property(SOURCE ${SECURE_STORAGE_C_SRC} APPEND PROPERTY COMPILE_DEFINITIONS SST_RAM_FS)
endif()
+ if (SST_ENABLE_PARTIAL_ASSET_RW)
+ set_property(SOURCE ${SECURE_STORAGE_C_SRC} APPEND PROPERTY COMPILE_DEFINITIONS SST_ENABLE_PARTIAL_ASSET_RW)
+ endif()
+
#Append all our source files to global lists.
list(APPEND ALL_SRC_C ${SECURE_STORAGE_C_SRC})
unset(SECURE_STORAGE_C_SRC)
diff --git a/secure_fw/services/secure_storage/sst_asset_management.c b/secure_fw/services/secure_storage/sst_asset_management.c
index 66b42a4..df63b07 100644
--- a/secure_fw/services/secure_storage/sst_asset_management.c
+++ b/secure_fw/services/secure_storage/sst_asset_management.c
@@ -403,8 +403,15 @@
return TFM_SST_ERR_ASSET_NOT_FOUND;
}
+#ifndef SST_ENABLE_PARTIAL_ASSET_RW
+ if (data->offset != 0) {
+ return TFM_SST_ERR_PARAM_ERROR;
+ }
+#endif
+
err = sst_object_read(asset_handle, local_data.data,
local_data.offset, local_data.size);
+
return err;
}
@@ -432,10 +439,19 @@
err = sst_utils_check_contained_in(0, db_entry->max_size,
local_data.offset, local_data.size);
- if (err == TFM_SST_ERR_SUCCESS) {
- err = sst_object_write(asset_handle, local_data.data,
- local_data.offset, local_data.size);
+ if (err != TFM_SST_ERR_SUCCESS) {
+ return err;
}
+
+#ifndef SST_ENABLE_PARTIAL_ASSET_RW
+ if (data->offset != 0) {
+ return TFM_SST_ERR_PARAM_ERROR;
+ }
+#endif
+
+ err = sst_object_write(asset_handle, local_data.data,
+ local_data.offset, local_data.size);
+
return err;
}
diff --git a/secure_fw/services/secure_storage/sst_asset_management.h b/secure_fw/services/secure_storage/sst_asset_management.h
index b0f30b4..cbf7a6c 100644
--- a/secure_fw/services/secure_storage/sst_asset_management.h
+++ b/secure_fw/services/secure_storage/sst_asset_management.h
@@ -26,7 +26,6 @@
* violation detected
*/
-
struct sst_asset_perm_t {
uint32_t app; /*!< Application ID */
uint8_t perm; /*!< Permissions bitfield */
diff --git a/secure_fw/services/secure_storage/sst_core.c b/secure_fw/services/secure_storage/sst_core.c
index 99f5e2d..bce2e03 100644
--- a/secure_fw/services/secure_storage/sst_core.c
+++ b/secure_fw/services/secure_storage/sst_core.c
@@ -1367,6 +1367,9 @@
struct sst_assetmeta object_meta;
struct sst_block_metadata block_meta;
uint32_t align_flash_nbr_bytes;
+#ifndef SST_ENABLE_PARTIAL_ASSET_RW
+ (void)offset;
+#endif
/* Get the meta data index */
object_index = sst_utils_extract_index_from_handle(asset_handle);
@@ -1383,12 +1386,14 @@
return TFM_SST_ERR_SYSTEM_ERROR;
}
+#ifdef SST_ENABLE_PARTIAL_ASSET_RW
/* offset can not be bigger than the current asset's size to disallows gaps
* without content inside the asset.
*/
if (offset > object_meta.cur_size) {
return TFM_SST_ERR_PARAM_ERROR;
}
+#endif
/* Clean previous data in sst_buf_plain_text */
sst_utils_memset(sst_buf_plain_text, SST_DEFAULT_EMPTY_BUFF_VAL,
@@ -1416,6 +1421,7 @@
* the asset's maximum size. So, it is not needed to check it at this
* point.
*/
+#ifdef SST_ENABLE_PARTIAL_ASSET_RW
if ((offset + size) > object_meta.cur_size) {
/* Update the object metadata */
object_meta.cur_size = offset + size;
@@ -1423,6 +1429,15 @@
/* Copy new data in the sst_buf_plain_text */
sst_utils_memcpy(sst_buf_plain_text + offset, data, size);
+#else
+ if (size > object_meta.cur_size) {
+ /* Update the object metadata */
+ object_meta.cur_size = size;
+ }
+
+ /* Copy new data in the sst_buf_plain_text */
+ sst_utils_memcpy(sst_buf_plain_text, data, size);
+#endif
#ifdef SST_ENCRYPTION
/* Encrypt data in sst_buf_plain_text */
diff --git a/secure_fw/services/secure_storage/sst_core_interface.h b/secure_fw/services/secure_storage/sst_core_interface.h
index 8eb3324..fbad367 100644
--- a/secure_fw/services/secure_storage/sst_core_interface.h
+++ b/secure_fw/services/secure_storage/sst_core_interface.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -46,6 +46,7 @@
* \return Returns error code specified in \ref tfm_sst_err_t
*/
enum tfm_sst_err_t sst_object_create(uint16_t asset_uuid, uint32_t size);
+
/**
* \brief Gets asset's data referenced by asset handle, and stores it
* in the data buffer.
@@ -59,6 +60,7 @@
*/
enum tfm_sst_err_t sst_object_read(uint32_t asset_handle, uint8_t *data,
uint32_t offset, uint32_t size);
+
/**
* \brief Writes data into the asset referenced by asset uuid.
*
@@ -71,6 +73,7 @@
*/
enum tfm_sst_err_t sst_object_write(uint32_t asset_handle, const uint8_t *data,
uint32_t offset, uint32_t size);
+
/**
* \brief Deletes the asset referenced by asset handler.
*