OpenWrt 的 Flash Layout 与文件系统

关于闪存布局可参考官网文档 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:

  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.

 

 待更新。。

posted @ 2017-11-03 15:56  Prefog  阅读(2085)  评论(0编辑  收藏  举报