1. 程式人生 > >【Linux】【檔案系統】squashfs檔案系統掛載失敗問題

【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驅動,升級檔案的製作流程等,後續補充。