diff --git a/nand-image-builder.c b/nand-image-builder.c index d0e05b278e84d1982c9bde2ec623977288082a58..3ecebcad051500683442c3e434466530aec892a9 100644 --- a/nand-image-builder.c +++ b/nand-image-builder.c @@ -54,12 +54,20 @@ int page_size = 2048; /** * * This program reads raw NAND image from standard input and updates ECC bytes in the OOB block for each sector. - * Data layout is as following: + * Data layout is as following (listing only tested geometrys): * * 2 KB page, consisting of 4 x 512 B sectors * 64 bytes OOB, consisting of 4 x 16 B OOB regions, one for each sector * - * In each OOB region, the first 9 1/2 bytes are user defined and the remaining 6 1/2 bytes are ECC. + * ./nand-image-builder -i infile -o outfile -b 131072 -p 2048 -s 64 -e 4 -m 14 + * + * or + * + * 2 KB page, consisting of 4 x 512 B sectors + * 128 bytes OOB, consisting of 4 x 32 B OOB regions, one for each sector + * in this case only 4 x 27 bytes are used as spare area + * + * ./nand-image-builder -i infile -o outfile -b 131072 -p 2048 -s 128 -e 8 -m 14 * */ @@ -76,6 +84,8 @@ void print_usage(void) printf("\t -m field order\n"); printf("Default command is:\n"); printf("./nand-image-builder -i infile -o outfile -b 131072 -p 2048 -s 64 -e 4 -m 14\n"); + printf("Example command is:\n"); + printf("./nand-image-builder -i infile -o outfile -b 131072 -p 2048 -s 128 -e 8 -m 14\n"); return; } @@ -225,6 +235,7 @@ int main(int argc, char **argv) /* Number of ecc_code bytes, v = ceil(p/8) = ceil(m*t/8) = p_partial_page_size+s-u */ oob_ecc_len = (sector_sz + oob_sz) - data_bytes; + /* Number of ecc bytes per sector (sub page) depending on the ecc level */ if (ecc_level == 4) { oob_ecc_sz = 16; } else if (ecc_level == 8) { @@ -294,10 +305,10 @@ int main(int argc, char **argv) numBytesRead = fread(page_buffer, (size_t)1, (sector_sz)*SECTORS_PER_PAGE, in_file); totalBytesRead += numBytesRead; - printf("Fread %d\n", totalBytesRead); + if (numBytesRead == 0) { - printf("Fread failed or file size is zero\r\n"); + printf("Fread failed or file size is zero or out of data\r\n"); goto exit; } @@ -321,7 +332,6 @@ int main(int argc, char **argv) { const uint8_t *sector_data = page_buffer + sector_sz * i; uint8_t *sector_oob = page_buffer + sector_sz * SECTORS_PER_PAGE + oob_ecc_sz * i; - printf("offset %d\n", sector_sz * SECTORS_PER_PAGE + oob_ecc_sz * i); if (erase_block) {