summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKinsey Moore <kinsey.moore@oarcorp.com>2023-10-04 10:58:23 -0500
committerJoel Sherrill <joel@rtems.org>2023-10-12 18:56:43 -0500
commitc5476e2b8c14b62a95a9fa35c1e4db0c4ae7bb7c (patch)
tree1b223c97b9867cc6308689dd4f9730346b8c46e9
parentb9f7eb2a92ad8850b20ad178d0e9e116b9e4df94 (diff)
bsps/xilinx-zynqmp: Unify JFFS2 OOB write locking
Ensure that a single locking session is carried over OOB writes including the OOB read that is sometimes required. This removes the possibility of another write occurring between the read and write that would make the write incorrect.
-rw-r--r--bsps/aarch64/xilinx-zynqmp/jffs2_xnandpsu.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/bsps/aarch64/xilinx-zynqmp/jffs2_xnandpsu.c b/bsps/aarch64/xilinx-zynqmp/jffs2_xnandpsu.c
index 5fb00d5eeb..ab0eb1ccd5 100644
--- a/bsps/aarch64/xilinx-zynqmp/jffs2_xnandpsu.c
+++ b/bsps/aarch64/xilinx-zynqmp/jffs2_xnandpsu.c
@@ -175,7 +175,7 @@ static int flash_block_mark_bad(
return RTEMS_SUCCESSFUL;
}
-static int flash_read_oob(
+static int flash_read_oob_locked(
rtems_jffs2_flash_control *super,
uint32_t offset,
uint8_t *oobbuf,
@@ -203,7 +203,6 @@ static int flash_read_oob(
return -ENOMEM;
}
- rtems_mutex_lock(&(get_flash_control(super)->access_lock));
while (ooblen) {
int rv = XNandPsu_ReadSpareBytes(nandpsu, PageIndex, spare_bytes);
/* no guarantee oobbuf can hold all of spare bytes, so read and then copy */
@@ -213,7 +212,6 @@ static int flash_read_oob(
}
if (rv) {
- rtems_mutex_unlock(&(get_flash_control(super)->access_lock));
free(spare_bytes);
return -EIO;
}
@@ -224,11 +222,23 @@ static int flash_read_oob(
ooblen -= readlen;
oobbuf += readlen;
}
- rtems_mutex_unlock(&(get_flash_control(super)->access_lock));
free(spare_bytes);
return RTEMS_SUCCESSFUL;
}
+static int flash_read_oob(
+ rtems_jffs2_flash_control *super,
+ uint32_t offset,
+ uint8_t *oobbuf,
+ uint32_t ooblen
+)
+{
+ rtems_mutex_lock(&(get_flash_control(super)->access_lock));
+ int ret = flash_read_oob_locked(super, offset, oobbuf, ooblen);
+ rtems_mutex_unlock(&(get_flash_control(super)->access_lock));
+ return ret;
+}
+
static int flash_write_oob(
rtems_jffs2_flash_control *super,
uint32_t offset,
@@ -257,10 +267,12 @@ static int flash_write_oob(
}
/* Writing a page spare area to small will result in invalid accesses */
+ rtems_mutex_lock(&(get_flash_control(super)->access_lock));
if (ooblen < SpareBytesPerPage) {
- int rv = flash_read_oob(super, offset, spare_bytes, SpareBytesPerPage);
+ int rv = flash_read_oob_locked(super, offset, spare_bytes, SpareBytesPerPage);
if (rv) {
free(spare_bytes);
+ rtems_mutex_unlock(&(get_flash_control(super)->access_lock));
return rv;
}
buffer = spare_bytes;
@@ -270,7 +282,6 @@ static int flash_write_oob(
/* Get page index */
uint32_t PageIndex = offset / nandpsu->Geometry.BytesPerPage;
- rtems_mutex_lock(&(get_flash_control(super)->access_lock));
sc = XNandPsu_WriteSpareBytes(nandpsu, PageIndex, buffer);
rtems_mutex_unlock(&(get_flash_control(super)->access_lock));
free(spare_bytes);