[rtems commit] bsps/xnandpsu: Avoid loop counter reset

Joel Sherrill joel at rtems.org
Fri Oct 27 16:07:23 UTC 2023


Module:    rtems
Branch:    master
Commit:    3363fabb9d1f03b0ce8219058b8013e92598a696
Changeset: http://git.rtems.org/rtems/commit/?id=3363fabb9d1f03b0ce8219058b8013e92598a696

Author:    Kinsey Moore <kinsey.moore at oarcorp.com>
Date:      Thu Oct 19 13:26:29 2023 -0500

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(+)

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;
 



More information about the vc mailing list