[PATCH 1/9] bsps/zynqmp/jffs2: Use BBT information directly

Kinsey Moore kinsey.moore at oarcorp.com
Sat Dec 9 02:31:18 UTC 2023


The XNandPsu_IsBlockBad() function is insufficient for JFFS2 to
determine whether a block is usable since the function does not report
reserved blocks. JFFS2 is also unable to use the last 4 blocks of each
target attached to the NAND controller since they are reserved for the
Bad Block Table (BBT), but not necessarily marked as such.
---
 bsps/aarch64/xilinx-zynqmp/jffs2_xnandpsu.c | 24 ++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/bsps/aarch64/xilinx-zynqmp/jffs2_xnandpsu.c b/bsps/aarch64/xilinx-zynqmp/jffs2_xnandpsu.c
index cf2a7d8192..3fa70cc0c3 100644
--- a/bsps/aarch64/xilinx-zynqmp/jffs2_xnandpsu.c
+++ b/bsps/aarch64/xilinx-zynqmp/jffs2_xnandpsu.c
@@ -130,6 +130,10 @@ static int flash_block_is_bad(
 {
   XNandPsu *nandpsu = get_flash_control(super)->nandpsu;
   uint32_t BlockIndex;
+  uint8_t BlockData;
+  uint8_t BlockShift;
+  uint8_t BlockType;
+  uint32_t BlockOffset;
 
   assert(bad);
 
@@ -137,10 +141,28 @@ static int flash_block_is_bad(
     return -EIO;
   }
 
+  *bad = true;
+
   BlockIndex = offset / nandpsu->Geometry.BlockSize;
 
   rtems_mutex_lock(&(get_flash_control(super)->access_lock));
-  *bad = (XNandPsu_IsBlockBad(nandpsu, BlockIndex) == XST_SUCCESS);
+
+  /* XNandPsu_IsBlockBad() is insufficient for this use case */
+  BlockOffset = BlockIndex >> XNANDPSU_BBT_BLOCK_SHIFT;
+  BlockShift = XNandPsu_BbtBlockShift(BlockIndex);
+  BlockData = nandpsu->Bbt[BlockOffset];
+  BlockType = (BlockData >> BlockShift) & XNANDPSU_BLOCK_TYPE_MASK;
+
+  if (BlockType == XNANDPSU_BLOCK_GOOD) {
+    *bad = false;
+  }
+
+  int TargetBlockIndex = BlockIndex % nandpsu->Geometry.NumTargetBlocks;
+  /* The last 4 blocks of every device target are reserved for the BBT */
+  if (nandpsu->Geometry.NumTargetBlocks - TargetBlockIndex <= 4) {
+    *bad = true;
+  }
+
   rtems_mutex_unlock(&(get_flash_control(super)->access_lock));
   return 0;
 }
-- 
2.39.2



More information about the devel mailing list