From 3363fabb9d1f03b0ce8219058b8013e92598a696 Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Thu, 19 Oct 2023 13:26:29 -0500 Subject: bsps/xnandpsu: Avoid loop counter reset On configurations where multiple NAND chips are in use, the erasure loop in XNandPsu_Erase() can reset the loop counter variable once it gets to blocks in the second chip causing an infinite loop overwriting parts of the first chip. This change ensures that the loop counter is not accidentally reset. --- bsps/shared/dev/nand/xnandpsu.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'bsps/shared') diff --git a/bsps/shared/dev/nand/xnandpsu.c b/bsps/shared/dev/nand/xnandpsu.c index e140364ce8..5aeee90084 100644 --- a/bsps/shared/dev/nand/xnandpsu.c +++ b/bsps/shared/dev/nand/xnandpsu.c @@ -1714,13 +1714,21 @@ s32 XNandPsu_Erase(XNandPsu *InstancePtr, u64 Offset, u64 Length) for (Block = StartBlock; Block < (StartBlock + NumBlocks); Block++) { Target = Block/InstancePtr->Geometry.NumTargetBlocks; +#ifdef __rtems__ + u32 ModBlock = Block % InstancePtr->Geometry.NumTargetBlocks; +#else Block %= InstancePtr->Geometry.NumTargetBlocks; +#endif /* Don't erase bad block */ if (XNandPsu_IsBlockBad(InstancePtr, Block) == XST_SUCCESS) continue; /* Block Erase */ +#ifdef __rtems__ + Status = XNandPsu_EraseBlock(InstancePtr, Target, ModBlock); +#else Status = XNandPsu_EraseBlock(InstancePtr, Target, Block); +#endif if (Status != XST_SUCCESS) goto Out; -- cgit v1.2.3