Flash layout of the new openwrt framework

Source: Internet
Author: User

Well, the new framework also supports a read-only File System (squashfs) and a readable and writable file system (jffs2 ). Therefore, we need to know how to deal with these problems.

 

About flash

In most embedded systems, Flash is the main program and data storage space. Due to the speed of flash, these programs and data will be moved to ram during system operation. During the operation, the CPU actually extracts the program and data from Ram. The famous uboot is responsible for moving the operating system to ram. The operating system is responsible for loading data and other programs stored in the file system.

Depending on its internal structure, there are two types of FLASH: nandflash and norflash. In the past, we were more inclined to use norflash because it had no bad blocks, so it was relatively easy to use. openwrt's support for norflash was already perfect. However, because the price of large-capacity nandflash is very advantageous, now many devices that require large-capacity Flash (> 32 M bytes) choose nandflash; the disadvantage is that it will have bad blocks. Unfortunately, openwrt does not support nandflash. If you need to use it, you can use ubifs to support nandflash.

Then, we use different driver types based on the way they connect to the CPU, including raw flash and FTL flash. Raw Flash is a mount method that connects directly to the SOC (CPU) and can read data directly through address line addressing. FTL flash is connected to the system flash through an additional controller, such as USB, SSD, MMC, emmc, SD, compactflash, etc. At this time, we need an FTL (Flash Translation Layer) to obtain data in flash.

 

Partitioning of the file system in Flash

In the previous section, we mentioned uboot, kernel, and filesystem. Here we will mainly talk about how these are organized in Flash devices in openwrt. We can use a picture to understand this problem as a whole. In general, the specific configurations of openwrt devices are similar and can be referenced by each other:

As shown in the figure above, we can see. Flash is divided into five blocks, which store different information: U-boot, kernel, squashfs, jffs2, and art.

When we can clearly distinguish from the figure, these parts are placed under different MTD blocks. So what is MTD? MTD is short for media technology device. In terms of operating system, MTD is an abstract ing provided for raw flash devices, allowing the kernel to perform unified operations on these devices. Currently, MTD is part of the standard kernel. H ", you can see that both character (/dev/mtdxx) and block (/dev/mtdblockxx) device drivers are provided. In addition, there is also a shell tool MTD for the user space (for example, burn to write FLASH: MTD-r write Linux. TRX Linux ).

Therefore, to make the structure clearer, we can consider the entire storage ing in layers:

1. layer0: that is, our entire flash. Here is an 8 Mb m25q64, which is connected to our SOC through the SPI interface.

2. layer1: We divide the entire flash into three regions. The first is mtd0 for uboot and the second is mtd5 for firmware, the third is the mtd4 used to store the test data of the atheros radio. Among them, mtd0 in addition to storage uboot, there is a data space, storage of Wi-Fi Mac and WPS-PIN information, if not set Mac here, wi-Fi will not work normally. If the art test data is incomplete, the device will not work normally. However, it seems to be unrelated to the specific device, as long as it is a type of device, this data is common.

3. Layer2: We divide the entire mtd5 into mtd1 (kernel) and mtd2 (rootfs ). After the kernel is compiled, the reality is compressed by lazma, and the obtained file is compressed by gzip. Then, mtd1 is placed into the final file.

4. layer3: Although mtd2 is regarded as a system rootfs, it is actually mounted into two different parts. Well, we can see that there is actually a side ball. First, squashfs is placed at the beginning of mtd2. Therefore, when the system is started, squashfs is regarded as a rootfs mount. Do not forget that squashfs is a read-only file system, so its size is fixed, so there is actually a fixed size space on the mtd2 used to place squashfs. Then, the fixed-size space is named mtd3. mtd3 is mounted with a file package in jffs2 format, that is, rootfs_data mentioned above.

 

Hands-on system

OK. Now we know the distribution above. Let's take a look at how the system is partitioned. First, view/proc/MTD:

# cat /proc/mtd dev:    size   erasesize  namemtd0: 00020000 00010000 "u-boot"mtd1: 000fc144 00010000 "kernel"mtd2: 006d3ebc 00010000 "rootfs"mtd3: 00140000 00010000 "rootfs_data"mtd4: 00010000 00010000 "art"mtd5: 007d0000 00010000 "firmware"

In addition, you can find the following information in the startup information (you can use dmesg to "play back "):

[    0.490000] 5 tp-link partitions found on MTD device spi0.0[    0.490000] Creating 5 MTD partitions on "spi0.0":[    0.500000] 0x000000000000-0x000000020000 : "u-boot"[    0.500000] 0x000000020000-0x00000011c144 : "kernel"[    0.510000] mtd: partition "kernel" must either start or end on erase block boundary or by[    0.520000] 0x00000011c144-0x0000007f0000 : "rootfs"[    0.530000] mtd: partition "rootfs" must either start or end on erase block boundary or by[    0.540000] mtd: device 2 (rootfs) set to be root filesystem[    0.540000] 1 squashfs-split partitions found on MTD device rootfs[    0.550000] 0x0000006b0000-0x0000007f0000 : "rootfs_data"[    0.560000] 0x0000007f0000-0x000000800000 : "art"[    0.560000] 0x000000020000-0x0000007f0000 : "firmware"

Then, let's look at which files are put in squashfs and which are put under jffs2:

# cd /[email protected]-link:/# ls rombin      etc      mnt      proc     root     sys      usr      wwwdev      lib      overlay  rom      sbin     tmp      var[email protected]-link:/# ls overlay/etc   mnt   root[email protected]-link:/# cd overlay/etc/[email protected]-link:/overlay/etc# lsconfig        ethers        rc.d          uci-defaultsdropbear      init.d        samba

So here, we can edit and modify only a few specific directories under etc (mainly for system configuration), MNT, and root. Other files are all compiled into squashfs. After squashfs is completed, we cannot modify it.

 

Refer:

1. http://wiki.openwrt.org/doc/techref/flash.layout

2. http://www.linux-mtd.infradead.org/doc/general.html

3. http://www.osslab.com.tw/Hardware/Open_Embedded_System/MIPS/Atheros/WR-703N

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.