Openwrt的FlashLayout
T、he OpenWrt Flash Layouthttp://wiki.openwrt.org/doc/techref/flash.layout?s[]=trx There are hard discs,which are considered block devices,and there is flash memory. There types of flash,like NOR flash,SLC NAND flash and MLC NAND flash. Partitioning of SquashFS-ImagesThe flash chip on embedded systems is not accompanied by a controller chip,and thus are not "FTL"-devices but "raw flash"-devices. Storage space is treated and addressed as an MTD (Memory Technology Device) and special Filesystems are used. The available storage is not partitioned in the traditional way,where you store the data about the partitions in the MBR and PBRs,but it is done in the Linux Kernel (and sometimes independently in the bootloader as well!). You simply define,that "partition kernel starts at offset x and ends at offset y". The advantage is,that later we can address these partitions by name,rather then specifying the precise start point of the data.
PartitionsSince the partitions are nested we look at this whole thing in layers:
Filesystems→ filesystems Mount Points
Rather than deleting the files,insert a whiteout,a special high-priority entry that marks the file as deleted. File system code that sees a whiteout entry for file F behaves as if F does not exist. #!/bin/bash # shows all overlay-whiteout symlinks ? find /overlay -type l | while read FILE do [ -z "$FILE" ] && break if ls -la "$FILE" 2>&- | grep -q '(overlay-whiteout)'; then echo "$FILE" fi done Directories→ user.beginner.fhs
Partitioning of JFFS2-ImagesTODO Discovery (How to find out)cat /proc/mtd dev: size erasesize name mtd0: 00020000 00010000 "u-boot" mtd1: 00140000 00010000 "kernel" mtd2: 00690000 00010000 "rootfs" mtd3: 00530000 00010000 "rootfs_data" mtd4: 00010000 00010000 "art" mtd5: 007d0000 00010000 "firmware" The erasesize is the block size of the flash,in this case 64KiB. The size is little or big endian hex value in Bytes. In case of little endian,you switch to hex-mode and enter 02 0000 into the calculator for example and convert to decimal (by switching back to decimal mode again). Then guess how they are nested into each other. Or execute Creating 5 MTD partitions on "spi0.0": 0x000000000000-0x000000020000 : "u-boot" 0x000000020000-0x000000160000 : "kernel" 0x000000160000-0x0000007f0000 : "rootfs" mtd: partition "rootfs" set to be root filesystem mtd: partition "rootfs_data" created automatically,ofs=2C0000,len=530000 0x0000002c0000-0x0000007f0000 : "rootfs_data" 0x0000007f0000-0x000000800000 : "art" 0x000000020000-0x0000007f0000 : "firmware"These are the start and end offsets of the partitions as hex values in Bytes. Now you don't have to guess which is nested in which. E.g. 02 0000 = 131.072 Bytes = 128KiB. DetailsgenericThe flash chip can be represented as a large block of continuous space:
There is no ROM to boot from; at power up the CPU begins executing the code at the very start of the flash. Luckily this isn't the firmware or we'd be in real danger every time we reflashed. Boot is actually handled by a section of code we tend to refer to as the bootloader (the BIOS of your PC is a bootloader).
The partition or partitions containing so called Special Configuration Data differ very much from each other. Example: The broadcom with CFEIf you dig into the "firmware" section you'll find a trx. A trx is just an encapsulation,which looks something like this:
"HDR0" is a magic value to indicate a trx header,rest is 4 byte unsigned values followed by the actual contents. In short,it's a block of data with a length and a checksum. So,our flash usage actually looks something like this:
Except that the firmware is generally pretty small and doesn't use the entire space between CFE and NVRAM:
( So what exactly is the firmware? The boot loader really has no concept of filesystems,it pretty much assumes that the start of the trx data section is executable code. So,at the very start of our firmware is the kernel. But just putting a kernel directly onto flash is quite boring and consumes a lot of space,so we compress the kernel with a heavy compression known as LZMA. Now the start of firmware is code for an LZMA decompress:
Now,the boot loader boots into an LZMA program which decompresses the kernel into memory and executes it. It adds one second to the bootup time,but it saves a large chunk of flash space. (And if that wasn't amusing enough,it turns out the boot loader does know gzip compression,so we gzip compressed the LZMA decompression program) Immediately following the kernel is the filesystem. We use SquashFS for this because it's a highly compressed readonly filesystem – remember that altering the contents of the trx in any way would invalidate the crc,so we put our writable data in a JFFS2 partition,which is outside the trx. This means that our firmware looks like this:
And the entire flash usage looks like this -
That's about as tight as we can possibly pack things into flash. ExplanationsWhat is an Image File?An image file is byte by byte copy of data contained in a file system. If you installed a Debian or a Windows in the usual way onto one or two harddisc partitions and would afterwards copy the whole content byte by byte from the hard disc into one file: dd if=/dev/sda of=/media/sdb3/backup.dd the obtained backup file The difference is,that OpenWrt-Image-File are not created that way
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |