天天看點

【Linux】【檔案系統】squashfs檔案系統挂載失敗問題

最近負責将A公司一個比較穩定的代碼分支移植到新平台上,新平台中包含了M公司和B公司的代碼,這樣的一個代碼架構友善以後不同公司晶片方案的添加和開發。

在移植的過程中,編譯成功後DUT上電,但是出現解壓檔案系統失敗,序列槽資訊:

0.760000] unlzma 632 [    0.760000] unlzma 634 [    0.764000] unlzma 632 [    0.768000] CPU 0 Unable to handle kernel paging request at virtual address c0101f38, epc == 800f02c8, ra == 800f0264 [    0.776000] Oops[#1]: [    0.776000] Cpu 0 [    0.776000] $ 0   : 00000000 00000000 ffffff38 01000000 [    0.776000] $ 4   : ff0000e0 000000e0 ff000000 000019e3 [    0.776000] $ 8   : 802c0000 00000001 00000001 0000000a

跟進到出錯的地方,是kernel中的lib\decompress_unlzma.c中函數unlzma出錯,這個函數應該是解壓squashfs中的檔案。進一步分析原因,發現是制作檔案系統使用的壓縮方式不一樣,在制作檔案系統的指令中:

Creating 4.0 filesystem on ../board/model_qca_qca95xx/images/wpa8730v1/ap143-squashfs, block size 1048576.

[===========================================================================================================================================================================================================\] 581/581 100%

Exportable Squashfs 4.0 filesystem, data block size 1048576

        compressed data, compressed metadata, compressed fragments

        duplicates are removed

Filesystem size 3374.85 Kbytes (3.30 Mbytes)

        26.07% of uncompressed filesystem size (12947.50 Kbytes)

Inode table size 5519 bytes (5.39 Kbytes)

        20.41% of uncompressed inode table size (27037 bytes)

Directory table size 8304 bytes (8.11 Kbytes)

        46.53% of uncompressed directory table size (17845 bytes)

Number of duplicate files found 84

Number of inodes 823

Number of files 649

Number of fragments 12

Number of symbolic links  99

Number of device nodes 0

Number of fifo nodes 0

Number of socket nodes 0

Number of directories 75

Number of ids (unique uids + gids) 1

Number of uids 1

        root (0)

Number of gids 1

        root (0)

從日志中看到,這裡使用了squashfs預設的壓縮方式gzib,而squashfs使用lzma壓縮的話,資訊:

/home/project/plc_platform/board/model_qca_qca95xx/build/../../../util/fakeroot /home/project/plc_platform/board/model_qca_qca95xx/build/../../../util/buildFS_LZ

Parallel mksquashfs: Using 2 processors

Creating 4.0 filesystem on /home/project/plc_platform/board/model_qca_qca95xx/build/../images/wpa8730v1/ap135-squashfs, block size 1048576.

[===========================================================================================================================================================================================================-] 581/581 100%

Exportable Squashfs 4.0 filesystem, lzma compressed, data block size 1048576

        compressed data, compressed metadata, compressed fragments

        duplicates are removed

Filesystem size 3374.96 Kbytes (3.30 Mbytes)

        26.07% of uncompressed filesystem size (12946.99 Kbytes)

Inode table size 5633 bytes (5.50 Kbytes)

        21.26% of uncompressed inode table size (26493 bytes)

Directory table size 8344 bytes (8.15 Kbytes)

        46.70% of uncompressed directory table size (17869 bytes)

Number of duplicate files found 16

Number of inodes 823

Number of files 581

Number of fragments 12

Number of symbolic links  99

Number of device nodes 68

Number of fifo nodes 0

Number of socket nodes 0

Number of directories 75

Number of ids (unique uids + gids) 1

有明顯的 lzma compressed辨別。

而在kernel的配置中,指定了rootfs的檔案系統類型:

CONFIG_CMDLINE="console=ttyS0,115200 root=01:00 rd_start=0x802d0000 rd_size=0x800000 init=/sbin/init mem=64m mtdparts=ath-nor0:256k(u-boot),64k(u-boot-env),6336k(rootfs),1408k(uImage),64k(config),64k(radiodata)"

是以導緻kernel在解壓檔案系時使用了lzma的解壓方式去解壓一個gzib壓縮的檔案系統,出錯。

另外一個挂載失敗的現象:

[    0.704000] drivers/rtc/hctosys.c: unable to open rtc device (rtc0)

[    0.712000] List of all partitions:

[    0.716000] 1f00             128 mtdblock0 (driver?)

[    0.720000] 1f01            1024 mtdblock1 (driver?)

[    0.724000] 1f02            6976 mtdblock2 (driver?)

[    0.728000] 1f03              64 mtdblock3 (driver?)

[    0.736000] No filesystem could mount root, tried:  squashfs

[    0.740000] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,3)

原因是mtd分區參數中,檔案系統是第2個分區(分區從0開始計算),如下:

brw-r--r--    1   31,   0 Mar 28  2016 mtdblock0

brw-r--r--    1   31,   1 Mar 28  2016 mtdblock1

brw-r--r--    1   31,   2 Mar 28  2016 mtdblock2

但是挂載的裝置名号 是31:3,錯誤,應該是31:2.

解決方法:使用squashfs.lzma工具制作檔案系統就可以了。

調試過程還有很多值得記錄的地方,比如kernel的makefile檔案,mtd驅動,更新檔案的制作流程等,後續補充。

繼續閱讀