0

I am working on an embedded Linux system (5.10.24), where there is a NAND FLASH as storage. The NAND FLASH supports internal ECC and has 128Bytes OOB.
Its DS says if the ECC is enabled the last 64Bytes are used as ECC, and the whole 128Bytes OOB could be read.

So I wrote a C program in Linux to read the OOB as follows,

    fd = open(argv[1], O_RDWR | O_SYNC);
    if (fd < 0) {
        perror("Failed to open MTD device");
        return -1;
    }

    if (ioctl(fd, MEMGETINFO, &mtd_info) < 0) {
        perror("Failed to get MTD device info");
        close(fd);
        return -1;
    }

    printf("OOBSIZE: %d\n", mtd_info.oobsize);

    oob_buf.start = atoi(argv[2]);
    oob_buf.length = 128;                 // Hard code to 128B
    oob_buf.ptr = malloc(oob_buf.length);

    rc = ioctl(fd, MEMREADOOB, &oob_buf);
    if (rc < 0) {
        perror("Failed to read OOB data");
        close(fd);
        return -1;
    }

    for (int i = 0; i < oob_buf.length; i++) {
        printf("%02X ", oob_buf.ptr[i]);
        if ((i%0x10) == 0xf)
           printf("\n");
    }
    printf("\n");

Then, I ran the code as follows,

# /tmp/nandoob /dev/mtd1 2048
OOBSIZE: 64
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
91 FF 19 A7 2E E2 62 C0 0D 36 24 42 78 86 FF FF
20 FF 53 0A 08 23 3B 06 CF BD 31 E7 B0 75 FF FF
BB FF 35 83 F3 AD 39 08 7A 9A 05 9B 98 8E FF FF
E1 FF F7 C1 23 58 A7 DD 8F 26 DC 3A 69 72 FF FF

I am not sure if the data read is correct or NOT.
I tried the nand dump.oob 0x2048 in u-boot, but I got 64 Bytes of 0xFF, no ECC data read.

So is my code to dump/read the whole 128Byte OOB correct? If not, how to read the whole NAND OOB in Linux?

1 Answer 1

0

I think I figured it out to some extents.

Firstly, I found a bug in my private u-boot in setting of OOB size to 64B not 128B. By setting it to 128B, I can get the OOB data, as follows,

# nand dump.oob 100000
Page 00100000 dump:
OOB:
        ff ff ff ff ff ff ff ff
        ff ff ff ff ff ff ff ff
        ff ff ff ff ff ff ff ff
        ff ff ff ff ff ff ff ff
        ff ff ff ff ff ff ff ff
        ff ff ff ff ff ff ff ff
        ff ff ff ff ff ff ff ff
        ff ff ff ff ff ff ff ff
        f2 ff 58 81 ff cd d8 b8
        ff ff ff ff ff ff ff ff
        fa ff c1 ad 20 5f cb a8
        ff ff ff ff ff ff ff ff
        f8 ff 65 8d 79 61 35 1a
        ff ff ff ff ff ff ff ff
        ff ff 01 12 35 1d 0a 8f
        ff ff ff ff ff ff ff ff

Then I called my C program to read the same page, and I got the same data.

So, I think the C code is correct in reading/dumping the NAND's OOB. (please correct me if I am wrong).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .