Skip to content
Snippets Groups Projects
Commit e9fa1d5c authored by Pitchaiah Murugan's avatar Pitchaiah Murugan
Browse files

Reading only page size of nand in fread

parent d8cbf529
Branches
No related tags found
No related merge requests found
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment