From e9fa1d5c5298459f5383906260aa18f50bd1e314 Mon Sep 17 00:00:00 2001
From: pitchaiah prakash <pitchaiah.murugan@iopsys.eu>
Date: Fri, 27 Mar 2020 11:56:50 +0100
Subject: [PATCH] Reading only page size of nand in fread
---
nand-image-builder.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/nand-image-builder.c b/nand-image-builder.c
index b3def12..8b37d00 100644
--- a/nand-image-builder.c
+++ b/nand-image-builder.c
@@ -16,6 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
+ *
+ * This code is referenced from https://github.com/ak-hard/brcm-nand-bch/.
+ *
*/
// BCH 4 algorithm is used for ECC level. In schematic bootstrap sets to 4 bit ECC level for NAND.
@@ -87,7 +90,7 @@ static void clear_pagebuffer()
/* Clears the buffers before programming the Page. */
for (index = 0; index < ((SECTOR_SZ + OOB_SZ) * SECTORS_PER_PAGE); index++)
{
- page_buffer[index] = 0x0;
+ page_buffer[index] = 0xFF;
}
}
@@ -231,11 +234,11 @@ int main(int argc, char **argv)
goto exit;
}
- if ((st.st_size % block_size) != 0)
+ /* if ((st.st_size % block_size) != 0)
{
printf("File size not multiple of block size\n");
goto exit;
- }
+ } */
blocks_app = st.st_size / block_size; //calculate total blocks needed for application.
pages_in_block = block_size / page_size;
@@ -294,12 +297,14 @@ int main(int argc, char **argv)
printf("OOB_ECC_LEN %d\n", oob_ecc_len);
printf("OOB_ECC_OFS %d\n", oob_ecc_ofs);
- while (!feof(in_file))
+
+ while (!feof(in_file))
+
{
clear_pagebuffer();
- numBytesRead = fread(page_buffer, (size_t)1, (sector_sz + oob_sz) * SECTORS_PER_PAGE, in_file);
+ numBytesRead = fread(page_buffer, (size_t)1, (sector_sz ) * SECTORS_PER_PAGE, in_file);
totalBytesRead += numBytesRead;
/* printf("\r\nRead %d bytes [%d%%] from file...\r\n",
@@ -312,6 +317,8 @@ int main(int argc, char **argv)
goto exit;
}
+ if (numBytesRead != (sector_sz ) * SECTORS_PER_PAGE) break; // skip if byte is less than bytes read from fread api.
+
memset(cmp_buffer, 0, sector_sz * SECTORS_PER_PAGE);
memcpy(cmp_buffer, page_buffer, (sector_sz)*SECTORS_PER_PAGE);
--
GitLab