The root file system production (b)

In the documents already required for the root file system, directory, all produced Well, then we discuss how to port it to embedded systems development board.
All directories and files take root file system ported to arm development board, need a software tool called mtd.utils, it can go directly to the official website (ftp://ftp.infradead.org/pub/mtd-utils/ ) up to download the source code, but also need zlib library support (http://zlib.net/) and lzo library (http://www.oberhumer.com/opensource/lzo/), plus utils-linux tool ( https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/) also need to download. About mtd.utils tools specific production method is somewhat complex, please refer to other tutorials on their own, there is no longer discussed.
Still below the number of large companies S3C2416 core board as an example to be discussed, to be transplanted to the root file system by using the tool making good mtd.utils.
Referring first to the previous method, using the SD card development board to start up, start the execution after the completion of "cd / opt / mtd-utils " enter the directory, you can see the directory will have to make good mtd.utils tool. Use the root file system starts up after the SD card is based on a ramdisk, it does not use NandFlash, so can use mtd.utils tools to create the root file system UBIFS format directly on NandFlash, following on to talk about production methods.
For ease of operation, you can make a good front first root file system packaged together into a root directory in the virtual machine, and then perform "tar -zcvf rootfs.tar.gz / rootfs", which is rootfs.tar.gz to generate a package file, "/ rootfs" is the directory where the root file system. After completion of the root directory will be generated in rootfs.tar.gz file, copy the file to the SD card to start development board, it can be transplanted. Then use this SD card to boot Linux development board comes in, then go to the next / opt / mtd-utils directory, follow these steps.
First, the implementation of "./flash_eraseall / dev / mtd2", the contents of the root file system partition all erased. Which, flash_eraseall is an executable program under mtd-utils directory, "/ dev / mtd2" refers to the partition where the root file system (mtd0 is UBoot partition, mtd1 for the Kernel partition). Then execute "./ubiattach / dev / ubi_ctrl -m 2 ", the same ubiattach is an executable program, which is used to link the device MTD (MTD Flash device description Original Equipment) to create and UBI (UBI reverse procedure respective devices are ubidetach). Where "/ dev / ubi_ctrl" file is a device node, if no executable "mknod / dev / ubi_ctrl c 10 63" to create it, "- m 2" refers mtd2 attach the partition. ubiattach after the implementation of the results as shown in FIG.

Then after the completion of "100MiB ./ubimkvol / dev / ubi0 -N rootfs -s" to perform the same ubimkvol is an executable program that is used to create a volume (the reverse procedure is ubirmvol), volume is the ultimate user to mount the file the system places where "/ dev / ubi0" is a device node, which was created out of the time step ubiattach in the implementation, "- N" is now behind the name of this volume - behind the "s" with the It is the size. ubimkvol after the implementation of the results as shown below.

完成后就可以执行挂载命令了。先执行“mkdir -p /tmp/nand”创建一个挂载点,然后执行“mount -t ubifs /dev/ubi0_0 /tmp/nand”进行挂载,其中“/dev/ubi0_0”是一个设备节点,它是在执行上一步ubimkvol时被创建出来的,“-t ubifs”是指挂载的文件系统为UBIFS形式,挂载完后的效果如下图所示。

至此,操作/tmp/nand目录就是操作根文件系统分区mtd2了,这就方便多了,下一步只需要把前面制作好的根文件系统拷贝过来即可。
执行“cd /mnt/sd”进入到SD卡的目录,确认一下rootfs.tar.gz文件存在(若没有内容可能需要重新挂载下SD卡),然后执行“tar -zxvf rootfs.tar.gz -C /tmp/nand”,“-C”是指把根文件系统解压到后面的“/tmp/nand”目录下。完毕后就可进入到“/tmp/nand”目录下查看一下,可见多了一个rootfs的目录,这就是解压后的目录,进入该目录就可以看到前面制作的根文件系统的目录和文件了。当然,制作好的根文件系统rootfs目录也可以通过NFS方式进行拷贝,这样就省去了打包和解压的过程,只不过在拷贝时要加上参数“-d”,以避免在拷贝过程中busybox的链接文件被破坏。
完成后还需要把根文件系统移动一下,因为前面在挂载ubi0_0(UBIFS卷)时是挂载到“/tmp/nand”目录下的,而目前在nand目录下还多出了一个rootfs的目录,所以需要执行一下命令“mv /tmp/nand/rootfs/* ../”,把rootfs下的所有文件和目录都移动到nand目录下(即rootfs分区下),然后再执行“rm -fr /tmp/nand/rootfs”把rootfs目录删除。最后执行“sync”命令同步一下NandFlash即可。
上述全部完成后,可执行“umount /tmp/nand”命令进行反挂载,然后执行“poweroff”关机命令,完成后给开发板断电,去除SD卡并跳线到NandFlash启动,随后给开发板上电。可看到启动完成后,开发板就进入到了console界面,且从中可以看到,基于UBIFS的根文件系统已经挂载成功了。插入一张SD卡,然后再拔出,再插入一个U盘,然后再拔出,从显示中可以看出,都实现了外存储器的自动挂载和反挂载,执行ls命令,可看到整个完整的根文件目录,如下图所示。

至此,整个基于UBIFS的根文件系统移植完毕。
当然,除了直接在NandFlash上制作根文件系统之外,也可能通过映像烧写的方式来制作UBIFS格式的根文件系统,这同样需要借助mtd-utils工具来实现。下面就来讨论一下这种方法。
要制作根文件系统映像,需要mkfs.ubifs和ubinize两个工具,其中mkfs.ubifs是用来将某个文件夹制作为UBIFS映像文件的,制作出的映像可在U-Boot下使用“ubi write”命令烧写到NandFlash上。但是,一般的U-Boot都不具备这个命令,因此还需要使用ubinize这个工具来把刚才生成的UBIFS映像文件转换成为通用的、可直接烧写在NandFlash上的格式(带有UBI文件系统镜像卷标)。下面就具体来看。
首先使用mkfs.ubifs工具将根文件系统目录rootfs制作成UBIFS映像,执行以下命令:
mkfs.ubifs -r /rootfs -m 2048 -e 126976 -c 992 -o ubifs.img
以上命令将/rootfs目录内容制作成UBIFS形式的映像文件,文件名为ubifs.img。其中,参数“-r”指定了根文件系统所在的目录,参数“-m”指定了最小I/O操作的大小,也就是NandFlash中一个页(page)的大小,参数“-e”指定了逻辑擦除快的大小,参数“-c”指定了最大的逻辑块号,参数“-o”指定输出文件的名称。
接下来使用ubinize工具把刚才生成的ubifs.img映像文件转换成为通用的Flash烧写格式,执行以下命令:
ubinize -o ubi.img -m 2048 -p 128KiB -s 512 -O 2048 ubinize.cfg
上述命令中的ubinize.cfg是一个配置文件,其内容如下:
[ubifs]
mode=ubi
image=ubifs.img
vol_id=0
vol_size=100MiB
vol_type=dynamic
vol_alignment=1
vol_name=rootfs
vol_flags=autoresize
该文件指明了要转换文件的名称及其他一些配置参数。其生成的UBIFS形式的根文件系统映像ubi.img就可在U-Boot下使用通用的“nand write”命令来进行烧写了。
在以上操作中要说明两点:一是两个工具命令mkfs.ubifs和ubinize都是mtd-utils下的可执行程序,但由于此时是在虚拟机下使用,所以在制作该命令时不要进行交叉编译,否则mkfs.ubifs和ubinize只能运行在ARM开发板系统下;二是命令使用中涉及到的参数要根据开发板所使用的NandFlash来具体确定。如果弄不清楚,还是推荐使用前面直接在NandFlash上建立根文件系统的形式进行移植。

Guess you like

Origin www.cnblogs.com/fxzq/p/12293583.html