關於閃存布局可參考官網文檔 Flash Layout
關於OpenWrt的文件系統內容可以參考 Filesystems
本篇文章均參考以上兩篇文章。
進入設備后可以通過/proc/mtd
root@fogcell:~# cat /proc/mtd dev: size erasesize name mtd0: 00040000 00010000 "u-boot" mtd1: 00010000 00010000 "u-boot-env" mtd2: 00e30000 00010000 "rootfs" mtd3: 00620000 00010000 "rootfs_data" mtd4: 00170000 00010000 "kernel" mtd5: 00010000 00010000 "art" mtd6: 00fa0000 00010000 "firmware"
與/proc/partitions ,查看到系統的分區信息。erasesize 為單位擦除的最小單位, 其為64KB
root@fogcell:~# cat /proc/partitions major minor #blocks name 31 0 256 mtdblock0 31 1 64 mtdblock1 31 2 14528 mtdblock2 31 3 6272 mtdblock3 31 4 1472 mtdblock4 31 5 64 mtdblock5 31 6 16000 mtdblock6
以上的這些信息可以在設備啟動的串口打印數據中找到如下:
[ 0.710000] bootconsole [early0] disabled [ 0.710000] bootconsole [early0] disabled [ 0.720000] m25p80 spi0.0: found w25q128, expected m25p80 [ 0.730000] m25p80 spi0.0: w25q128 (16384 Kbytes) [ 0.730000] 6 cmdlinepart partitions found on MTD device spi0.0 [ 0.740000] Creating 6 MTD partitions on "spi0.0": [ 0.740000] 0x000000000000-0x000000040000 : "u-boot" [ 0.750000] 0x000000040000-0x000000050000 : "u-boot-env" [ 0.750000] 0x000000050000-0x000000e80000 : "rootfs" [ 0.760000] mtd: device 2 (rootfs) set to be root filesystem [ 0.770000] 1 squashfs-split partitions found on MTD device rootfs [ 0.770000] 0x000000860000-0x000000e80000 : "rootfs_data" [ 0.780000] 0x000000e80000-0x000000ff0000 : "kernel" [ 0.780000] 0x000000ff0000-0x000001000000 : "art" [ 0.790000] 0x000000050000-0x000000ff0000 : "firmware"
這次使用的是16MB的FLASH存儲芯片,不同機型不同。針對以上信息,有如下的解釋。英文版的內容更豐富The OpenWrt Flash Layout
通用的Flash layout 如下
The generic Flash layout is:
對本設備來說,總共 16384 KB = 256 KiB + 64 KiB + 16000 KiB + 64 KiB = 16 MiB
bootloader partition(s) : "u-boot" 256 KiB
optional SoC specific partition(s): "u-boot-env" 64 KiB
OpenWrt firmware partition: "kernel" + "rootfs" ="firmware" 16000 KiB 其中 "rootfs" = "rootfs_data" (6272 KiB)+ 8256 KiB
optional SoC specific partition(s
這是官網針對此型號的例子。
這種存儲芯片可被認為是塊(block)設備,與之相似的是內存。如果操作系統(Linux)可以直接讀取叫做“raw flash”,如果閃存芯片不能夠直接被操作系統讀取(還需要在閃存中間添加額外的控制芯片來連接的)叫做“FTL (Flash Translation Layer)flash” 。嵌入式系統中常用的就是“raw flash”,USB存儲設備使用的是 FTL flash。 詳細信息可查看鏈接 Raw flash vs. FTL devices
官網對以上圖片的解釋如下:
Since the partitions are nested we look at this whole thing in layers:
-
Layer0: So we have the Flashchip, 8 MiB in size, which is soldered to the PCB and connected to the SoC over SPI (Serial Peripheral Interface Bus).
-
Layer1: We "partition" the space into mtd0 for the bootloader, mtd5 for OpenWrt and, in this case, mtd4 for the ART (Atheros Radio Test) - it contains calibration data for the wifi (EEPROM). If it is missing or corrupt,
ath9k
(wireless driver) won't come up anymore. The bootloader (128 KiB) contains of the u-boot 64KiB block AND a data section which contains the MAC, WPS-PIN and type description. If no MAC is configured ath9k will not work correctly due to a faulty MAC. -
Layer2: we subdivide mtd5 (firmware) into mtd1 (kernel) and mtd2 (rootfs); In the generation process of the firmware (see obtain.firmware.generate) the Kernel binary file is first packed with LZMA, then the obtained file is packed with gzip and then this file will be written onto the raw flash (mtd1) without being part of any filesystem! During boot, u-boot copies this entire section into RAM and executes it. From there on, the Linux kernel bootstraps itself…
-
Layer3: we subdivide rootfs even further into mtd3 for rootfs_data and the rest for an unnamed partition which will accommodate the SquashFS-partition.
待更新。。