aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/hal/lib/complex/mfs/hal_mfs.c19
-rw-r--r--os/hal/lib/complex/mfs/hal_mfs.h38
-rw-r--r--test/mfs/configuration.xml50
-rw-r--r--test/mfs/source/test/mfs_test_sequence_001.c50
-rw-r--r--testhal/STM32/multi/WSPI-MFS/make/stm32l476_discovery.make4
-rw-r--r--testhal/STM32/multi/WSPI-MFS/make/stm32l4r9_discovery.make2
6 files changed, 145 insertions, 18 deletions
diff --git a/os/hal/lib/complex/mfs/hal_mfs.c b/os/hal/lib/complex/mfs/hal_mfs.c
index d37326134..eadd3c9b4 100644
--- a/os/hal/lib/complex/mfs/hal_mfs.c
+++ b/os/hal/lib/complex/mfs/hal_mfs.c
@@ -276,11 +276,12 @@ static mfs_error_t mfs_record_check(MFSDriver *mfsp,
#if MFS_CFG_STRONG_CHECKING == TRUE
{
/* TODO: Checking the CRC while reading the record data.*/
- (void)mfsp;
+/* *sts = MFS_RECORD_CRC;
+ return MFS_NO_ERROR;*/
}
-#else
- (void)mfsp;
#endif
+ *sts = MFS_RECORD_OK;
+ return MFS_NO_ERROR;
}
}
@@ -439,6 +440,8 @@ static mfs_error_t mfs_bank_scan_records(MFSDriver *mfsp,
/* Scanning records.*/
hdr_offset = start_offset + (flash_offset_t)sizeof(mfs_bank_header_t);
while (hdr_offset < end_offset) {
+ uint32_t size;
+
/* Reading the current record header.*/
RET_ON_ERROR(mfs_flash_read(mfsp, hdr_offset,
sizeof (mfs_data_header_t),
@@ -453,7 +456,7 @@ static mfs_error_t mfs_bank_scan_records(MFSDriver *mfsp,
}
else if (sts == MFS_RECORD_OK) {
/* Record OK.*/
- uint32_t size = mfsp->buffer.dhdr.fields.size;
+ size = mfsp->buffer.dhdr.fields.size;
/* Zero-sized records are erase markers.*/
if (size == 0U) {
@@ -468,6 +471,7 @@ static mfs_error_t mfs_bank_scan_records(MFSDriver *mfsp,
else if (sts == MFS_RECORD_CRC) {
/* Record payload corrupted, scan can continue because the header
is OK.*/
+ size = mfsp->buffer.dhdr.fields.size;
warning = true;
}
else {
@@ -475,6 +479,9 @@ static mfs_error_t mfs_bank_scan_records(MFSDriver *mfsp,
warning = true;
break;
}
+ hdr_offset = hdr_offset +
+ (flash_offset_t)sizeof(mfs_data_header_t) +
+ (flash_offset_t)size;
}
if (hdr_offset > end_offset) {
@@ -926,7 +933,7 @@ mfs_error_t mfsReadRecord(MFSDriver *mfsp, mfs_id_t id,
uint16_t crc;
osalDbgCheck((mfsp != NULL) &&
- (id >= 1) && (id <= (mfs_id_t)MFS_CFG_MAX_RECORDS) &&
+ (id >= 1U) && (id <= (mfs_id_t)MFS_CFG_MAX_RECORDS) &&
(np != NULL) && (buffer != NULL));
if (mfsp->state != MFS_READY) {
@@ -992,7 +999,7 @@ mfs_error_t mfsWriteRecord(MFSDriver *mfsp, mfs_id_t id,
bool warning = false;
osalDbgCheck((mfsp != NULL) &&
- (id >= 1) && (id <= (mfs_id_t)MFS_CFG_MAX_RECORDS) &&
+ (id >= 1U) && (id <= (mfs_id_t)MFS_CFG_MAX_RECORDS) &&
(n > 0U) && (buffer != NULL));
if (mfsp->state != MFS_READY) {
diff --git a/os/hal/lib/complex/mfs/hal_mfs.h b/os/hal/lib/complex/mfs/hal_mfs.h
index 19c9b195f..56ff0b966 100644
--- a/os/hal/lib/complex/mfs/hal_mfs.h
+++ b/os/hal/lib/complex/mfs/hal_mfs.h
@@ -88,6 +88,23 @@
#if !defined(MFS_CFG_BUFFER_SIZE) || defined(__DOXYGEN__)
#define MFS_CFG_BUFFER_SIZE 32
#endif
+
+/**
+ * @brief Enforced memory alignment.
+ * @details This value must be a power of two, it enforces a memory alignment
+ * for records in the flash array. This is required when alignment
+ * constraints exist, for example when using a DTR mode on OSPI
+ * devices.
+ * @note When enforcing an alignment you need to use buffers with size
+ * aligned to the specified value. For example, if you need to
+ * write a 5 bytes object with alignment of 4 then you need to
+ * use a 8 bytes data buffer, the last 3 bytes are used as filler
+ * so ==initialize== those to zero (buffer->DDDDD000) or garbage
+ * will be written after data.
+ */
+#if !defined(MFS_CFG_MEMORY_ALIGNMENT) || defined(__DOXYGEN__)
+#define MFS_CFG_MEMORY_ALIGNMENT 1
+#endif
/** @} */
/*===========================================================================*/
@@ -102,7 +119,7 @@
#error "invalid MFS_MAX_REPAIR_ATTEMPTS value"
#endif
-#if MFS_CFG_BUFFER_SIZE <= 16
+#if MFS_CFG_BUFFER_SIZE < 16
#error "invalid MFS_CFG_BUFFER_SIZE value"
#endif
@@ -110,6 +127,14 @@
#error "MFS_CFG_BUFFER_SIZE is not a power of two"
#endif
+#if MFS_CFG_MEMORY_ALIGNMENT < 1
+#error "invalid MFS_CFG_MEMORY_ALIGNMENT value"
+#endif
+
+#if (MFS_CFG_MEMORY_ALIGNMENT & (MFS_CFG_MEMORY_ALIGNMENT - 1)) != 0
+#error "MFS_CFG_MEMORY_ALIGNMENT is not a power of two"
+#endif
+
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
@@ -228,6 +253,7 @@ typedef union {
uint16_t crc;
/**
* @brief Data size.
+ * @note The next record is located at @p MFS_ALIGN_NEXT(size).
*/
uint32_t size;
} fields;
@@ -343,6 +369,16 @@ typedef struct {
#define MFS_IS_WARNING(err) ((err) > MFS_NO_ERROR)
/** @} */
+/**
+ * @name Alignment macros
+ * @{
+ */
+#define MFS_ALIGN_MASK ((uint32_t)MFS_CFG_MEMORY_ALIGNMENT - 1U)
+#define MFS_IS_ALIGNED(v) (((uint32_t)(v) & MFS_ALIGN_MASK) == 0U)
+#define MFS_ALIGN_PREV(v) ((uint32_t)(v) & ~MFS_ALIGN_MASK)
+#define MFS_ALIGN_NEXT(v) MFS_ALIGN_PREV((size_t)(v) + MFS_ALIGN_MASK)
+/** @} */
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
diff --git a/test/mfs/configuration.xml b/test/mfs/configuration.xml
index a222033f8..efc7b5b04 100644
--- a/test/mfs/configuration.xml
+++ b/test/mfs/configuration.xml
@@ -385,10 +385,10 @@ test_assert(err == MFS_ERR_NOT_FOUND, "record not erased");]]></value>
</case>
<case>
<brief>
- <value>Erasing the whole storage.</value>
+ <value>Erasing the whole storage and re-initialization.</value>
</brief>
<description>
- <value>The managed storage is erased and re-initialized.</value>
+ <value>The managed storage is erased, initialized and re-mounted.</value>
</description>
<condition>
<value />
@@ -427,6 +427,52 @@ test_assert(err == MFS_NO_ERROR, "error creating record 3");]]></value>
</step>
<step>
<description>
+ <value>Records must exist.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[mfs_error_t err;
+size_t size;
+
+size = sizeof mfs_buffer;
+err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
+test_assert(err == MFS_NO_ERROR, "record 0 not present");
+size = sizeof mfs_buffer;
+err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer);
+test_assert(err == MFS_NO_ERROR, "record 1 not present");
+size = sizeof mfs_buffer;
+err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer);
+test_assert(err == MFS_NO_ERROR, "record 2 not present");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Re-mounting, records must still exist.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[mfs_error_t err;
+size_t size;
+
+err = mfsStart(&mfs1, &mfscfg1);
+test_assert(err == MFS_NO_ERROR, "re-mount failed");
+size = sizeof mfs_buffer;
+err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
+test_assert(err == MFS_NO_ERROR, "record 0 not present");
+size = sizeof mfs_buffer;
+err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer);
+test_assert(err == MFS_NO_ERROR, "record 1 not present");
+size = sizeof mfs_buffer;
+err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer);
+test_assert(err == MFS_NO_ERROR, "record 2 not present");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
<value>Erasing storage and verify that the records have been removed, MFS_NO_ERROR is expected on erase, MFS_ERR_NOT_FOUND is expected on retrieve.</value>
</description>
<tags>
diff --git a/test/mfs/source/test/mfs_test_sequence_001.c b/test/mfs/source/test/mfs_test_sequence_001.c
index 272924bd4..20b4d8d89 100644
--- a/test/mfs/source/test/mfs_test_sequence_001.c
+++ b/test/mfs/source/test/mfs_test_sequence_001.c
@@ -309,14 +309,16 @@ static const testcase_t mfs_test_001_003 = {
};
/**
- * @page mfs_test_001_004 [1.4] Erasing the whole storage
+ * @page mfs_test_001_004 [1.4] Erasing the whole storage and re-initialization
*
* <h2>Description</h2>
- * The managed storage is erased and re-initialized.
+ * The managed storage is erased, initialized and re-mounted.
*
* <h2>Test Steps</h2>
* - [1.4.1] Creating records 1, 2 and 3, MFS_NO_ERROR is expected.
- * - [1.4.2] Erasing storage and verify that the records have been
+ * - [1.4.2] Records must exist.
+ * - [1.4.3] Re-mounting, records must still exist.
+ * - [1.4.4] Erasing storage and verify that the records have been
* removed, MFS_NO_ERROR is expected on erase, MFS_ERR_NOT_FOUND is
* expected on retrieve.
* .
@@ -347,10 +349,46 @@ static void mfs_test_001_004_execute(void) {
test_assert(err == MFS_NO_ERROR, "error creating record 3");
}
- /* [1.4.2] Erasing storage and verify that the records have been
+ /* [1.4.2] Records must exist.*/
+ test_set_step(2);
+ {
+ mfs_error_t err;
+ size_t size;
+
+ size = sizeof mfs_buffer;
+ err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
+ test_assert(err == MFS_NO_ERROR, "record 0 not present");
+ size = sizeof mfs_buffer;
+ err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer);
+ test_assert(err == MFS_NO_ERROR, "record 1 not present");
+ size = sizeof mfs_buffer;
+ err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer);
+ test_assert(err == MFS_NO_ERROR, "record 2 not present");
+ }
+
+ /* [1.4.3] Re-mounting, records must still exist.*/
+ test_set_step(3);
+ {
+ mfs_error_t err;
+ size_t size;
+
+ err = mfsStart(&mfs1, &mfscfg1);
+ test_assert(err == MFS_NO_ERROR, "re-mount failed");
+ size = sizeof mfs_buffer;
+ err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
+ test_assert(err == MFS_NO_ERROR, "record 0 not present");
+ size = sizeof mfs_buffer;
+ err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer);
+ test_assert(err == MFS_NO_ERROR, "record 1 not present");
+ size = sizeof mfs_buffer;
+ err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer);
+ test_assert(err == MFS_NO_ERROR, "record 2 not present");
+ }
+
+ /* [1.4.4] Erasing storage and verify that the records have been
removed, MFS_NO_ERROR is expected on erase, MFS_ERR_NOT_FOUND is
expected on retrieve.*/
- test_set_step(2);
+ test_set_step(4);
{
mfs_error_t err;
size_t size;
@@ -370,7 +408,7 @@ static void mfs_test_001_004_execute(void) {
}
static const testcase_t mfs_test_001_004 = {
- "Erasing the whole storage",
+ "Erasing the whole storage and re-initialization",
mfs_test_001_004_setup,
mfs_test_001_004_teardown,
mfs_test_001_004_execute
diff --git a/testhal/STM32/multi/WSPI-MFS/make/stm32l476_discovery.make b/testhal/STM32/multi/WSPI-MFS/make/stm32l476_discovery.make
index e4860c5a3..964d88d20 100644
--- a/testhal/STM32/multi/WSPI-MFS/make/stm32l476_discovery.make
+++ b/testhal/STM32/multi/WSPI-MFS/make/stm32l476_discovery.make
@@ -5,7 +5,7 @@
# Compiler options here.
ifeq ($(USE_OPT),)
- USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
+ USE_OPT = -O2 -gdwarf-3 -fomit-frame-pointer -falign-functions=16
endif
# C specific options here (added to USE_OPT).
@@ -76,7 +76,7 @@ endif
# FPU-related options.
ifeq ($(USE_FPU_OPT),)
- USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16 -fsingle-precision-constant
+ USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16
endif
#
diff --git a/testhal/STM32/multi/WSPI-MFS/make/stm32l4r9_discovery.make b/testhal/STM32/multi/WSPI-MFS/make/stm32l4r9_discovery.make
index bb649be47..47345c16f 100644
--- a/testhal/STM32/multi/WSPI-MFS/make/stm32l4r9_discovery.make
+++ b/testhal/STM32/multi/WSPI-MFS/make/stm32l4r9_discovery.make
@@ -76,7 +76,7 @@ endif
# FPU-related options.
ifeq ($(USE_FPU_OPT),)
- USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16 -fsingle-precision-constant
+ USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16
endif
#