From a6aa6c63851334c76d36daa12e979bacc34c6441 Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Wed, 25 Oct 2023 16:22:07 -0500 Subject: bsps/zynqmp/jffs2: Use BBT information directly 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; } -- cgit v1.2.3