This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA2PXEVM: MTD(Memory Technology Device) Subsystem Write

Part Number: TDA2PXEVM


Hello All,

We are using MTD(Memory Technology Device) Subsystem provided abstraction layer from HLOS usecase to save some data in flash device and retrieve from the same.

We are using mtd4 which has 64k space to read and write.

Our data is around 800 bytes which we are saving on this sector. But in order to do so we need to write two times consecutively.

But we have checked for small bytes of data like 64 bytes in there we are able to read all the data correctly with single write only.

We are not getting exactly why we need to write two times for 800 bytes in order to read all the data correctly.

Inputs, Suggestions will be of great help.

Regards

Shantanu Joshi

  • Hi Shantanu,

    Can you please share the exact commands that you are using in Linux to reproduce the issue
    at our end.

    Best Regards,
    Keerthy

  • Hi Keerthy

    Sharing you the small code for reading and writing small chunk of data with single write,

    static int qspiInit = 1 ;
    static unsigned char buf[64];
    static int fd = 0;
    mtd_info_t mtd_info;

    fd = open("/dev/mtd4", O_RDWR);
    ioctl(fd, MEMGETINFO, &mtd_info);

    if(qspiInit)

    {
            qspiInit = 0;
            erase_info_t ei;
            ei.length = mtd_info.erasesize;
            for(ei.start = 0; ei.start < mtd_info.size; ei.start += mtd_info.erasesize)
            {
                ioctl(fd, MEMUNLOCK, &ei);
                ioctl(fd, MEMERASE, &ei);
            }
            for(int i = 0; i< 64; i++)
            {
                 buf[i] = 5;
            }
            lseek(fd, -mtd_info.erasesize, SEEK_END);
            write(fd, buf, sizeof(buf));

    }

    lseek(fd, -mtd_info.erasesize, SEEK_END);

    read(fd, buf, sizeof(buf));

    for(int j = 0; j< 64; j++)

    {

          Vps_printf("buf[%d]\n", j, buf[j]);

    }

    close(fd);

    Regards

    Shantanu

  • Hi Shantanu,

    If i understand the above is the working case. Can you share the non working test case with 800 Bytes written.

    Also share the u-boot & kernel logs so we know the version.

    Best Regards,
    Keerthy

  • Hi Shantanu,

    I do not have TDA2P at my end but i tried something very close to what you are trying on my am574x-idk which
    is similar to TDA2P:

    Step 1: Created a file of 800 bytes: dd if=/dev/urandom of=test bs=800 count=1

    Step 2: ls -al test                                                                                                                                                                              
    -rw-r--r--    1 root     root           800 Sep 12 17:24 test

    Ensured that test is created

    Step 3: flash_erase /dev/mtd4 0 0

    Step 4: mtd_debug write /dev/mtd4 0 800 test /* Write 800 bytes from test file to offset 0 of mtd4 flash */

    Step 5:  mtd_debug read /dev/mtd4 0 800 test1 /* Read 800 bytes from offset 0 of mtd4 flash to  test1 file to */

    Step 6:  md5sum test
    af13366b0cf79c93609607194f904ac2  test
    root@am57xx-evm:~# md5sum test1
    af13366b0cf79c93609607194f904ac2  test1

    As you can see 800 bytes went through just fine.

    Can you try the above?

    Best Regards,
    Keerthy

  • Hello Keerthy,

    From above I can see if i am not wrong you have tested with linux commands. Can you try the same with a C function similar as me.

    Please do note that in 800 bytes I am writing consists of a structure which has different structure elements as well as elements of different data types such as char,short,float,int.

    one of the structure element has size of 544 bytes out of 800 bytes I am writing.

    Regards

    Shantanu

  • Shantanu,

    Can you try writing your contents to a file once you boot to prompt & try the commands i have shown
    to be sure that linux mtd commands are working fine before we get to you code?

    Best Regards,
    Keerthy

  • Keerthy,

    Ok I will do that.

    Regards

    Shantanu