OpenWrt 的 Flash Layout 與文件系統

關於閃存佈局可參考官網文檔 Flash Layouthtml

關於OpenWrt的文件系統內容能夠參考 Filesystemslinux

本篇文章均參考以上兩篇文章。bootstrap

進入設備後能夠經過/proc/mtdless

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 爲單位擦除的最小單位, 其爲64KBide

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 Layoutthis

通用的Flash layout 以下spa

The generic Flash layout is:操作系統

對本設備來講,總共 16384 KB = 256 KiB + 64 KiB + 16000 KiB + 64 KiB = 16 MiBrest

               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:

  1. 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).
  2. 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.
  3. 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…
  4. Layer3: we subdivide rootfs even further into mtd3 for rootfs_data and the rest for an unnamed partition which will accommodate the SquashFS-partition.

 

 待更新。。

相關文章
相關標籤/搜索