PC의 측면에서 littlefs 파일 시스템을 디버깅 사용 littlefs 퓨즈

배경

임베디드 장치 littlefs 아암 안티 파워 다운, 동적 마모 평준화, 이하 RAM / ROM 요구 특성을 보이는 특정 정보와 보안 시스템 다운 작은 파일의 시작이다 https://github.com/ARMmbed/littlefs

일이 잘못되면 임베디드 디바이스에서 사용하기위한 파일 시스템으로, 일반적으로 분석을위한 데이터를 덤프해야합니다. 그런 다음 PC 쪽 디버깅 도구가 필요합니다.

littlefs 퓨즈 소개

이 프로젝트는 즉, 직접 거울 littlefs PC에 마운트 할이 프로젝트를 사용할 수있는 littlefs의 FUSE 패키지를 제공하고, 일반 파일 시스템의 일부를 운영하고 있습니다.

소스는 위치 : https://github.com/ARMmbed/littlefs-fuse

구조

우리는 직접 다운로드

 $ git clone https://github.com/ARMmbed/littlefs-fuse.git
 $ cd littlefs-fuse

건설 봐

$ tree -L 2

.
├── lfs_fuse_bd.c
├── lfs_fuse_bd.h
├── lfs_fuse.c
├── LICENSE.md
├── littlefs
│   ├── DESIGN.md
│   ├── emubd
│   ├── lfs.c
│   ├── lfs.h
│   ├── lfs_util.c
│   ├── lfs_util.h
│   ├── LICENSE.md
│   ├── Makefile
│   ├── README.md
│   ├── scripts
│   ├── SPEC.md
│   └── tests
├── Makefile
└── README.md

그것은 바로 littlefs 폴더가있는 외부 포장입니다. 우리 littlefs의 특정 버전을 필요로하는 경우와 littlefs 장치의 동일한 버전을 사용하는 경우, 예를 들어, 매우 편리 내층에 littlefs를 교체 할 필요가있다.

컴파일

README에 따르면,이 프로젝트는 FUSE 버전 2.6 이상 버전 종속성, 당신은 버전을 보려면 다음 명령을 사용할 수 있습니다

fusermount -V

또한 필요 libfuse-DEV를 설치합니다 :

sudo apt-get install libfuse-dev

의존성이 만족되면, LFS를 생성하는 직접 응용 프로그램을

make

생성 장치와 마운트를 사용하여

장비를 구축하기 위해 우선 필요

sudo chmod a+rw /dev/loop0                  # make loop device user accessible
dd if=/dev/zero of=image bs=512 count=2048  # create a 1MB image
losetup /dev/loop0 image                    # attach the loop device

당신이 형식이 필요하므로 이전 DD 우리는 빈 이미지를 생성하는

./lfs --format /dev/loop0

그런 다음 마운트

mkdir -p mount
./lfs /dev/loop0 mount

성공적으로 마운트 한 후, 실행이이 케이스를 장착 볼 수 있습니다 마운트

$ mount | grep lfs
/home/zhuangqiubin/debug_littlefs/littlefs-fuse/lfs on /home/zhuangqiubin/debug_littlefs/littlefs-fuse/mount type fuse.lfs (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)

이제 작동 무료, 아래에 디렉토리를 마운트 할 수 있으며, 삭제 작업이 읽기, 쓰기를 만드는 데, 그것은 결국 이미지에 적용 littlefs로 변환됩니다

프로세스, 당신은, 당신은 예를 들어, 작업을 참조하고, 궁극적으로 어떤 종류의 littlefs의 형식을 저장된 데이터의 수, 언제든지 데이터를 덤프 할 수

$ echo "www.cnblogs.com/zqb-all/" >> mount/test_littlefs.txt

$ hexdump -C image
00000000  03 00 00 00 f0 0f ff f7  6c 69 74 74 6c 65 66 73  |........littlefs|
00000010  2f e0 00 10 00 00 02 00  00 02 00 00 00 08 00 00  |/...............|
00000020  ff 00 00 00 ff ff ff 7f  fe 03 00 00 20 00 04 09  |............ ...|
00000030  74 65 73 74 5f 6c 69 74  74 6c 65 66 73 2e 74 78  |test_littlefs.tx|
00000040  74 20 00 00 11 70 0f f9  b7 ee c0 48 bb ff ff ff  |t ...p.....H....|
00000050  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000200  04 00 00 00 f0 0f ff f7  6c 69 74 74 6c 65 66 73  |........littlefs|
00000210  2f e0 00 10 00 00 02 00  00 02 00 00 00 08 00 00  |/...............|
00000220  ff 00 00 00 ff ff ff 7f  fe 03 00 00 20 00 04 09  |............ ...|
00000230  74 65 73 74 5f 6c 69 74  74 6c 65 66 73 2e 74 78  |test_littlefs.tx|
00000240  74 20 00 00 08 77 77 77  2e 63 6e 62 6c 6f 67 73  |t ...www.cnblogs|
00000250  2e 63 6f 6d 2f 7a 71 62  2d 61 6c 6c 2f 0a 70 0f  |.com/zqb-all/.p.|
00000260  f9 87 46 fe c1 ad ff ff  ff ff ff ff ff ff ff ff  |..F.............|
00000270  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000400  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00100000

사용 후 제거하려면 다음 명령을 사용

umount mount
sudo losetup -d /dev/loop0

지정된 미러 마운트

이들은 빈 이미지가 생성 포맷 및 마운트되어 있습니다. 당신은 준비가 만든 이미지를 마운트하려면 단계는 유사하지만, 변화를 반영. 는 기존의 미러링이라고 littlefs.img 가정

sudo chmod a+rw /dev/loop0                  # make loop device user accessible
losetup /dev/loop0 littlefs.img                    # attach the loop device
mkdir -p mount
./lfs /dev/loop0 mount

차이 명령을하지 제거

umount mount
sudo losetup -d /dev/loop0

그러나, 장치 littlefs 거울에 덤프, 그 구성은 반드시 littlefs 퓨즈의 기본 구성과 일치하지 않습니다.

이 때, 제대로 장착하기 위해 및 장치에서 실행 정확하게 시뮬레이션 littlefs에, 우리는 같은의 구성을 변경해야합니다.

해결책은, 직접, 예를 들어, 소스 코드를 수정

diff --git a/lfs_fuse.c b/lfs_fuse.c
index 3c87dad..d1a99a2 100644
--- a/lfs_fuse.c
+++ b/lfs_fuse.c
@@ -26,7 +26,16 @@
 
 
 // config and other state
-static struct lfs_config config = {0};
+/* static struct lfs_config config = {0}; */
+static struct lfs_config config = {
+    .read_size = 256,
+    .prog_size = 256,
+    .block_size = 4096,
+    .block_count = 1224,
+    .block_cycles = 512,
+    .cache_size = 256,
+    .lookahead_size = 32
+};

메이크업 생성에 다시 수정 후

솔루션 둘째, 예를 들어, 지정하려면 명령 줄 매개 변수에서 호출 할 때,

./lfs --block_size=512 --format /dev/loop0
./lfs --block_size=512 /dev/loop0 mount

지원되는 옵션은 도움말에서 찾을 수 있습니다

$lfs -h
usage: ./lfs [options] device mountpoint

general options:
    -o opt,[opt...]        FUSE options
    -h   --help            print help
    -V   --version         print version

littlefs options:
    --format               format instead of mounting
    --migrate              migrate previous version  instead of mounting
    -b   --block_size      logical block size, overrides the block device
    --block_count          block count, overrides the block device
    --block_cycles         number of erase cycles before eviction (512)
    --read_size            readable unit (block_size)
    --prog_size            programmable unit (block_size)
    --cache_size           size of caches (block_size)
    --lookahead_size       size of lookahead buffer (8192)
    --name_max             max size of file names (255)
    --file_max             max size of file contents (2147483647)
    --attr_max             max size of custom attributes (1022)

FUSE options:
    -d   -o debug          enable debug output (implies -f)
    -f                     foreground operation
    -s                     disable multi-threaded operation

    -o allow_other         allow access to other users
    -o allow_root          allow access to root
    -o auto_unmount        auto unmount on process termination
    -o nonempty            allow mounts over non-empty file/dir
    -o default_permissions enable permission checking by kernel
    -o fsname=NAME         set filesystem name
    -o subtype=NAME        set filesystem type
    -o large_read          issue large read requests (2.4 only)
    -o max_read=N          set maximum size of read requests

    -o hard_remove         immediate removal (don't hide files)
    -o use_ino             let filesystem set inode numbers
    -o readdir_ino         try to fill in d_ino in readdir
    -o direct_io           use direct I/O
    -o kernel_cache        cache files in kernel
    -o [no]auto_cache      enable caching based on modification times (off)
    -o umask=M             set file permissions (octal)
    -o uid=N               set file owner
    -o gid=N               set file group
    -o entry_timeout=T     cache timeout for names (1.0s)
    -o negative_timeout=T  cache timeout for deleted names (0.0s)
    -o attr_timeout=T      cache timeout for attributes (1.0s)
    -o ac_attr_timeout=T   auto cache timeout for attributes (attr_timeout)
    -o noforget            never forget cached inodes
    -o remember=T          remember cached inodes for T seconds (0s)
    -o nopath              don't supply path if not necessary
    -o intr                allow requests to be interrupted
    -o intr_signal=NUM     signal to send on interrupt (10)
    -o modules=M1[:M2...]  names of modules to push onto filesystem stack

    -o max_write=N         set maximum size of write requests
    -o max_readahead=N     set maximum readahead
    -o max_background=N    set number of maximum background requests
    -o congestion_threshold=N  set kernel's congestion threshold
    -o async_read          perform reads asynchronously (default)
    -o sync_read           perform reads synchronously
    -o atomic_o_trunc      enable atomic open+truncate support
    -o big_writes          enable larger than 4kB writes
    -o no_remote_lock      disable remote file locking
    -o no_remote_flock     disable remote file locking (BSD)
    -o no_remote_posix_lock disable remove file locking (POSIX)
    -o [no_]splice_write   use splice to write to the fuse device
    -o [no_]splice_move    move data while splicing to the fuse device
    -o [no_]splice_read    use splice to read from the fuse device

Module options:

[iconv]
    -o from_code=CHARSET   original encoding of file names (default: UTF-8)
    -o to_code=CHARSET      new encoding of the file names (default: UTF-8)

[subdir]
    -o subdir=DIR       prepend this directory to all paths (mandatory)
    -o [no]rellinks     transform absolute symlinks to relative

디버깅

그것은 무엇보다도 가장 직관적, 당신은 거울에서 다시 마운트 한 후 덤프 코드를 디버깅하고에 주문형 소스 littlefs 추가 할 수 있다는 것입니다, 마운트 PC에서 읽을 시뮬레이션 할 수 있기 때문에, 인쇄하여 문제를 분석합니다.

둘째, 필요한 경우, 우리는 더 많은 GDB 이상의 수

make DEBUG=1 clean all                # build with debug info
gdb --args ./lfs -d /dev/loop0 mount  # run with gdb

이 문서 주소 : HTTPS : //www.cnblogs.com/zqb-all/p/12078659.html

추천

출처www.cnblogs.com/zqb-all/p/12078659.html