summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-12-02 17:21:09 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-12-02 17:21:09 -0600
commit754aaeac9368329698087cee63919ccac0abced9 (patch)
tree6561bb475372ce92cb982892bb6bf7a084e71b4b /nuttx
parent832e51d36f305b7fee48deba6311cf70841a8e35 (diff)
downloadpx4-nuttx-754aaeac9368329698087cee63919ccac0abced9.tar.gz
px4-nuttx-754aaeac9368329698087cee63919ccac0abced9.tar.bz2
px4-nuttx-754aaeac9368329698087cee63919ccac0abced9.zip
MTD NAND: Fix an error in the calculation of the page number
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/drivers/mtd/hamming.c20
-rwxr-xr-xnuttx/drivers/mtd/mtd_nand.c6
2 files changed, 15 insertions, 11 deletions
diff --git a/nuttx/drivers/mtd/hamming.c b/nuttx/drivers/mtd/hamming.c
index 82622ab3e..bc51f0bff 100644
--- a/nuttx/drivers/mtd/hamming.c
+++ b/nuttx/drivers/mtd/hamming.c
@@ -259,8 +259,6 @@ static void hamming_compute256(FAR const uint8_t *data, FAR uint8_t *code)
code[0] = (~(uint32_t)code[0]);
code[1] = (~(uint32_t)code[1]);
code[2] = (~(uint32_t)code[2]);
-
- fvdbg("Computed: %02x %02x %02x\n", code[0], code[1], code[2]);
}
/****************************************************************************
@@ -294,9 +292,6 @@ static int hamming_verify256(FAR uint8_t *data, FAR const uint8_t *original)
correction[1] = computed[1] ^ original[1];
correction[2] = computed[2] ^ original[2];
- fvdbg("Correction: %02x %02x %02x\n",
- correction[0], correction[1], correction[2]);
-
/* If all bytes are 0, there is no error */
if ((correction[0] == 0) && (correction[1] == 0) && (correction[2] == 0))
@@ -304,6 +299,15 @@ static int hamming_verify256(FAR uint8_t *data, FAR const uint8_t *original)
return 0;
}
+ /* There are bit errors */
+
+ fvdbg("Read: %02x %02x %02x\n",
+ original[0], original[1], original[2]);
+ fvdbg("Computed: %02x %02x %02x\n",
+ computed[0], computed[1], computed[2]);
+ fvdbg("Correction: %02x %02x %02x\n",
+ correction[0], correction[1], correction[2]);
+
/* If there is a single bit error, there are 11 bits set to 1 */
if (hamming_bitsincode256(correction) == 11)
@@ -339,13 +343,15 @@ static int hamming_verify256(FAR uint8_t *data, FAR const uint8_t *original)
if (hamming_bitsincode256(correction) == 1)
{
+ fdbg("ERROR: ECC has been correupted\n");
return HAMMING_ERROR_ECC;
}
- /* Otherwise, this is a multi-bit error */
+ /* Otherwise, there are multiple bit errors */
else
{
+ fdbg("ERROR: Multiple bit errors\n");
return HAMMING_ERROR_MULTIPLEBITS;
}
}
@@ -421,8 +427,6 @@ int hamming_verify256x(FAR uint8_t *data, size_t size, FAR const uint8_t *code)
while (remaining > 0)
{
- fvdbg("Code: %02x %02x %02x\n", code[0], code[1], code[2]);
-
result = hamming_verify256(data, code);
if (result != HAMMING_SUCCESS)
{
diff --git a/nuttx/drivers/mtd/mtd_nand.c b/nuttx/drivers/mtd/mtd_nand.c
index 9122554a8..50e59c105 100755
--- a/nuttx/drivers/mtd/mtd_nand.c
+++ b/nuttx/drivers/mtd/mtd_nand.c
@@ -609,7 +609,7 @@ static ssize_t nand_bread(struct mtd_dev_s *dev, off_t startpage,
off_t block;
int ret;
- fvdbg("startpage: %08lx npages: %d\n", (long)startpage, (int)npages);
+ fvdbg("startpage: %ld npages: %d\n", (long)startpage, (int)npages);
DEBUGASSERT(nand && nand->raw);
/* Retrieve the model */
@@ -628,7 +628,7 @@ static ssize_t nand_bread(struct mtd_dev_s *dev, off_t startpage,
/* Get the block and page offset associated with the startpage */
block = startpage / pagesperblock;
- page = pagesperblock % pagesperblock;
+ page = startpage % pagesperblock;
/* Lock access to the NAND until we complete the read */
@@ -719,7 +719,7 @@ static ssize_t nand_bwrite(struct mtd_dev_s *dev, off_t startpage,
/* Get the block and page offset associated with the startpage */
block = startpage / pagesperblock;
- page = pagesperblock % pagesperblock;
+ page = startpage % pagesperblock;
/* Lock access to the NAND until we complete the write */