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

modified from 10bytes to 9 bytes in oob ecc offset

parent e9fa1d5c
No related branches found
No related tags found
No related merge requests found
...@@ -122,11 +122,13 @@ int main(int argc, char **argv) ...@@ -122,11 +122,13 @@ int main(int argc, char **argv)
int pages_in_block, i = 0; int pages_in_block, i = 0;
const char *input_file = NULL; const char *input_file = NULL;
const char *output_file = NULL; const char *output_file = NULL;
FILE *in_file = NULL, *out_file = NULL; char *tes_file = "test.out";
FILE *in_file = NULL, *out_file = NULL, *test_file = NULL;
struct stat st; struct stat st;
uint8_t *buffer; uint8_t *buffer;
uint8_t cmp_buffer[SECTOR_SZ * SECTORS_PER_PAGE]; uint8_t cmp_buffer[SECTOR_SZ * SECTORS_PER_PAGE];
uint8_t ecc[OOB_ECC_LEN]; uint8_t ecc[OOB_ECC_LEN];
int erased_block = 1;
/* Initialize BCH lib data and parameters */ /* Initialize BCH lib data and parameters */
...@@ -224,6 +226,13 @@ int main(int argc, char **argv) ...@@ -224,6 +226,13 @@ int main(int argc, char **argv)
goto exit; goto exit;
} }
test_file = fopen(tes_file, "wb");
if (out_file == NULL)
{
printf("Out file open error\n");
goto exit;
}
fseek(in_file, 0, SEEK_SET); fseek(in_file, 0, SEEK_SET);
fseek(out_file, 0, SEEK_SET); fseek(out_file, 0, SEEK_SET);
...@@ -234,7 +243,7 @@ int main(int argc, char **argv) ...@@ -234,7 +243,7 @@ int main(int argc, char **argv)
goto exit; 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"); printf("File size not multiple of block size\n");
goto exit; goto exit;
...@@ -297,14 +306,13 @@ int main(int argc, char **argv) ...@@ -297,14 +306,13 @@ int main(int argc, char **argv)
printf("OOB_ECC_LEN %d\n", oob_ecc_len); printf("OOB_ECC_LEN %d\n", oob_ecc_len);
printf("OOB_ECC_OFS %d\n", oob_ecc_ofs); printf("OOB_ECC_OFS %d\n", oob_ecc_ofs);
while (!feof(in_file))
while (!feof(in_file))
{ {
clear_pagebuffer(); clear_pagebuffer();
numBytesRead = fread(page_buffer, (size_t)1, (sector_sz ) * SECTORS_PER_PAGE, in_file); numBytesRead = fread(page_buffer, (size_t)1, (sector_sz)*SECTORS_PER_PAGE, in_file);
totalBytesRead += numBytesRead; totalBytesRead += numBytesRead;
/* printf("\r\nRead %d bytes [%d%%] from file...\r\n", /* printf("\r\nRead %d bytes [%d%%] from file...\r\n",
...@@ -317,7 +325,8 @@ int main(int argc, char **argv) ...@@ -317,7 +325,8 @@ int main(int argc, char **argv)
goto exit; goto exit;
} }
if (numBytesRead != (sector_sz ) * SECTORS_PER_PAGE) break; // skip if byte is less than bytes read from fread api. 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); memset(cmp_buffer, 0, sector_sz * SECTORS_PER_PAGE);
...@@ -327,24 +336,62 @@ int main(int argc, char **argv) ...@@ -327,24 +336,62 @@ int main(int argc, char **argv)
for(i=0; i < 2048; i++) for(i=0; i < 2048; i++)
printf("0x%X\t", cmp_buffer[i]); */ printf("0x%X\t", cmp_buffer[i]); */
for (i = 0; i != SECTORS_PER_PAGE; ++i) //for (i = 0; i != SECTOR_SZ * SECTORS_PER_PAGE; ++i)
{ // if (page_buffer[i] == 0xff)
// {
const uint8_t *sector_data = page_buffer + sector_sz * i; // ++erased_block;
uint8_t *sector_oob = page_buffer + sector_sz * SECTORS_PER_PAGE + oob_sz * i; // //break;
// }
memset(sector_oob + oob_ecc_ofs, 0xff, oob_ecc_len);
memset(buffer, 0, sector_sz + oob_ecc_ofs + 1);
shift_half_byte(sector_data, buffer, sector_sz);
shift_half_byte(sector_oob, buffer + sector_sz, oob_ecc_ofs);
// compute ECC
memset(ecc, 0, oob_ecc_len); for (i = 0; i < SECTOR_SZ * SECTORS_PER_PAGE; i += 4)
encode_bch(bch, buffer, sector_sz + oob_ecc_ofs + 1, ecc); {
// copy the result in its OOB block, shifting right by 4 bits if (*(uint32_t *)(page_buffer + i) != 0xffffffff)
shift_half_byte(ecc, sector_oob + oob_ecc_ofs, oob_ecc_len - 1); {
sector_oob[oob_ecc_ofs + oob_ecc_len - 1] |= ecc[oob_ecc_len - 1] >> 4; for (i = 0; i != SECTORS_PER_PAGE; ++i)
{
const uint8_t *sector_data = page_buffer + sector_sz * i;
uint8_t *sector_oob = page_buffer + sector_sz * SECTORS_PER_PAGE + oob_sz * i;
//if (erased_block)
//{
// erased page ECC consumes full 7 bytes, including high 4 bits set to 0xf
memset(sector_oob + oob_ecc_ofs, 0xff, oob_ecc_len);
//}
// memset(sector_oob + oob_ecc_ofs, 0xff, oob_ecc_len);
memset(buffer, 0, sector_sz + oob_ecc_ofs);
shift_half_byte(sector_data, buffer, sector_sz);
//if(i == 1)
//fwrite(buffer, sector_sz , 1, out_file);
shift_half_byte(sector_oob, buffer + sector_sz, oob_ecc_ofs);
// if(i == 1) {
//fwrite(buffer, sector_sz + oob_ecc_ofs , 1, test_file);
//goto exit;
//}
// compute ECC
// if(i == 2)
// fwrite(buffer, sector_sz , 1, out_file);
memset(ecc, 0, oob_ecc_len);
encode_bch(bch, buffer, sector_sz, ecc);
// copy the result in its OOB block, shifting right by 4 bits
shift_half_byte(ecc, sector_oob + oob_ecc_ofs - 1, oob_ecc_len);
sector_oob[oob_ecc_ofs + oob_ecc_len - 1] |= ecc[oob_ecc_len - 1] >> 4;
//fwrite(sector_oob , oob_ecc_ofs + oob_ecc_len , 1, test_file);
//if(i == 2) {
//fwrite(page_buffer, (sector_sz + oob_sz) * SECTORS_PER_PAGE, 1, test_file);
// goto exit;
// }
}
}
break;
} }
fwrite(page_buffer, (sector_sz + oob_sz) * SECTORS_PER_PAGE, 1, out_file); fwrite(page_buffer, (sector_sz + oob_sz) * SECTORS_PER_PAGE, 1, out_file);
...@@ -362,10 +409,9 @@ int main(int argc, char **argv) ...@@ -362,10 +409,9 @@ int main(int argc, char **argv)
if (!(count & countMask)) if (!(count & countMask))
{ {
/* printf("block No %d\r\n", blocks_num); */ /* printf("block No %d\r\n", blocks_num); */
blocks_num++; blocks_num++;
} }
} }
exit: exit:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment