Remove erasing from ram store
The RAM block store is a RAM-based device, so it should not assume
that storage must be erased before writing, unlike flash memory.
This change removes the unnecessary check, improving efficiency
and extending the expected lifetime of the storage device.
Additionally, the relevant tests have been updated accordingly.
Change-Id: I3156002cac7654e8b301aea3fdd56d0d533357ba
Signed-off-by: Gabor Toth <gabor.toth2@arm.com>
diff --git a/components/service/block_storage/block_store/device/ram/ram_block_store.c b/components/service/block_storage/block_store/device/ram/ram_block_store.c
index 7c234ff..42a39b6 100644
--- a/components/service/block_storage/block_store/device/ram/ram_block_store.c
+++ b/components/service/block_storage/block_store/device/ram/ram_block_store.c
@@ -14,36 +14,6 @@
#define RAM_BLOCK_STORE_ERASED_VALUE (0xff)
-static bool is_block_erased(const struct ram_block_store *ram_block_store,
- uint64_t lba,
- size_t offset,
- size_t len)
-{
- bool is_erased = true;
- size_t block_start_index =
- ram_block_store->base_block_device.storage_partition.block_size * lba;
- size_t block_end_index =
- block_start_index + ram_block_store->base_block_device.storage_partition.block_size;
-
- size_t index = block_start_index + offset;
- size_t end_index = (index + len < block_end_index) ?
- index + len :
- block_end_index;
-
- while (index < end_index) {
-
- if (ram_block_store->ram_back_store[index] != RAM_BLOCK_STORE_ERASED_VALUE) {
-
- is_erased = false;
- break;
- }
-
- ++index;
- }
-
- return is_erased;
-}
-
static psa_status_t ram_block_store_get_partition_info(void *context,
const struct uuid_octets *partition_guid,
struct storage_partition_info *info)
@@ -134,9 +104,6 @@
if (storage_partition_is_lba_legal(storage_partition, lba) &&
(offset < storage_partition->block_size)) {
- if (!is_block_erased(ram_block_store, lba, offset, data_len))
- return PSA_ERROR_STORAGE_FAILURE;
-
size_t bytes_remaining = storage_partition->block_size - offset;
uint8_t *block_start =
&ram_block_store->ram_back_store[lba * storage_partition->block_size];
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 fa75ad0..11a73b1 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
@@ -92,11 +92,11 @@
UNSIGNED_LONGS_EQUAL(BLOCK_SIZE, data_len);
MEMCMP_EQUAL(write_buffer, read_buffer, BLOCK_SIZE);
- /* Attempt to write the same block again without an erase. Expect this to fail. */
+ /* Write to the previously written block in partition 2 should be successful */
memset(write_buffer, 0xbb, BLOCK_SIZE);
status = block_store_write(m_block_store, CLIENT_ID, handle, lba,
0, write_buffer, BLOCK_SIZE, &num_written);
- LONGS_EQUAL(PSA_ERROR_STORAGE_FAILURE, status);
+ LONGS_EQUAL(PSA_SUCCESS, status);
/* Erase the block */
status = block_store_erase(m_block_store, CLIENT_ID, handle, lba, 1);
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 560db29..63a0895 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
@@ -201,17 +201,17 @@
LONGS_EQUAL(PSA_SUCCESS, status);
UNSIGNED_LONGS_EQUAL(sizeof(write_buffer), num_written);
- /* Write to the previously written block in partition 2 should fail as it hasn't been erased */
+ /* Write to the previously written block in partition 2 should be successful */
status = block_store_write(
m_block_store, LOCAL_CLIENT_ID, handle_2, lba_2,
0, write_buffer, sizeof(write_buffer), &num_written);
- LONGS_EQUAL(PSA_ERROR_STORAGE_FAILURE, status);
+ LONGS_EQUAL(PSA_SUCCESS, status);
/* Erase the block in the partition 2 */
status = block_store_erase(m_block_store, LOCAL_CLIENT_ID, handle_2, lba_2, 1);
LONGS_EQUAL(PSA_SUCCESS, status);
- /* Now the write to partition 2 should work */
+ /* Now the write to partition 2 should work again */
status = block_store_write(
m_block_store, LOCAL_CLIENT_ID, handle_2, lba_2,
0, write_buffer, sizeof(write_buffer), &num_written);