9160's littlefs cannot correctly read files generated by littlefs Python

After enabling Littlefs, I wanted to use a serial port to write files to it. I first tried using mcumgr, but currently encountered some problems. So, I tried to directly read the data from the LFS partition, modify it, and write it again.

After reading the data from the LFS partition of 9160, I used the littlefs Python library to parse the data and correctly identify the files and directories in the data package. Then, I used this library to create a file in the data package, and finally wrote the newly created file into the LFS partition of 9160 again. After restarting, most of the time, it would prompt an LFS mount failure with an error code of -84. Sometimes it is possible to successfully mount, but LFS cannot recognize the files or directories inside.  There are still a few successful mounts that can recognize the files inside. (I did not use the Python library to add files to the read data during the successful mount and correct recognition. Instead, I wrote an independent LFS packet directly into the LFS partition, and LFS could recognize both the existing files and the files in the independent packet at the same time)

I have analyzed the data packet and feel that it is possible that the littlefs Python library has damaged the part of the LFS operation log that records the operation logs. I can't find the pattern, and I don't know why there were those successful situations

This is the independent LFS data packet I am using
6471.lfs2.bin

Link to the littlefs library: https://github.com/jrast/littlefs-python

Can you help me analyze this problem? Thanks

  • Hello, 

    We have close to no knowledge of the littlefs-python, and thus, we are not able to provide any support for this. 

    Where do you get error code -84? Do you have any logs from the nRF9160? What version of the nRF Connect SDK are you working with?

    Thanks.

    Kind regards,
    Øyvind

  • Hello

    This is the log that started normally. You can see that the starting address of my LFS partition is 0x70000, with a length of 0x8e000, and there are three files inside for testing. I use the command line of jlink to read the data in this area from flash and obtain a 568kb bin. Then, I erase the LFS partition through code. After the erase is completed, I use the command line to rewrite the newly obtained 568kb bin into the LFS partition. There are three possible scenarios

    [09:35:32.696]收←◆*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    Sample program to r/w files on littlefs
    Area 4 at 0x70000    on flash-controller@39000                     for 581632    bytes
    I: LittleFS version 2.5, disk version 2.0
    I: FS at flash-controller@39000:0x70000 is 142 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 142 ; bfree = 140
    
    Listing dir /lfs ...
    [FILE] 111.bin (size = 20)
    [FILE] 222.hex (size = 20)
    [FILE] 333.jpg (size = 20)
    I: /lfs unmounted
    /lfs unmount: 0

    The first scenario is a mount failure, this is the startup log when an error occurs, there is an error code inside -84,. Then, based on the code, it will format and remount it

    [09:28:54.643]收←◆*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    Sample program to r/w files on littlefs
    Area 4 at 0x70000    on flash-controller@39000                     for 581632    bytes
    I: LittleFS version 2.5, disk version 2.0
    I: FS at flash-controller@39000:0x70000 is 142 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    E: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1234: Corrupted dir pair at {0x1, 0x0}
    W: can't mount (LFS -84); formatting
    
    [09:28:54.864]收←◆I: /lfs mounted
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 142 ; bfree = 140
    
    Listing dir /lfs ...
    I: /lfs unmounted
    /lfs unmount: 0

    The second scenario is that the mount is successful, but no files are recognized

    [09:27:35.028]收←◆*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    Sample program to r/w files on littlefs
    Area 4 at 0x70000    on flash-controller@39000                     for 581632    bytes
    I: LittleFS version 2.5, disk version 2.0
    I: FS at flash-controller@39000:0x70000 is 142 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 142 ; bfree = 140
    
    Listing dir /lfs ...
    I: /lfs unmounted
    /lfs unmount: 0

    The third scenario is that the mount is successful and can correctly identify the files inside, and the log is no different from the first log. In this case, even if I write a bin that is not read from this 9160, it can still correctly recognize the file, such as update.exf below

    Sample program to r/w files on littlefs
    Area 4 at 0x70000    on flash-controller@39000                     for 581632    bytes
    I: LittleFS version 2.5, disk version 2.0
    I: FS at flash-controller@39000:0x70000 is 142 0x1000-byte blocks with 512 cycle
    I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 142 ; bfree = 121
    
    Listing dir /lfs ...
    [FILE] boot_count (size = 1)
    [FILE] list.txt (size = 393)
    [FILE] update.exf (size = 63058)
    [FILE] update.ing (size = 4)
    [DIR ] z
    /lfs/boot_count read count:2 (bytes: 1)
    /lfs/boot_count write new boot count 3: [wr:1]
    I: /lfs unmounted
    /lfs unmount: 0

    I am using version 2.6.1 of NCS,

    Do I need to add any more information?

Related