Ramdisk的制作,以及genext2fs和mkiamge的工具使用

来源:互联网 发布:mysql官网无法访问 编辑:程序博客网 时间:2024/05/16 13:42

    在嵌入式系统中,有时出于主板硬件成本的考虑,可能会没有NANDFLASH设备,并且SPI-FLASH也只有512K可以放下一个bootloader,这个时候可以采取让bootloader从网络或者硬盘读取kernelramdisk并在bootm之后挂载ramdisk来解决FLASH存储空间不能放下文件系统的问题。

    而ramdisk是通过genext2fs工具和ubootmkimage工具制作而成的,下面我们就来看看这两个工具的使用说明和制作ramdisk的方法。


一、genext2fs的使用

genext2fs下载地址是:http://sourceforge.net/projects/genext2fs/files/

genext2fs工具的作用在于将一个文件夹制作成一个ext2文件系统镜像

使用: ./genext2fs [options] image

参数说明:

  -x, --starting-image <image>

  -d, --root <directory>

  -D, --devtable <file>

  -b, --size-in-blocks <blocks>

  -i, --bytes-per-inode <bytes per inode>

  -N, --number-of-inodes <number of inodes>

  -m, --reserved-percentage <percentage of blocks to reserve>

  -g, --block-map <path>     Generate a block map file for this path.

  -e, --fill-value <value>   Fill unallocated blocks with value.

  -z, --allow-holes          Allow files with holes.

  -f, --faketime             Set filesystem timestamps to 0 (for testing).

  -q, --squash               Same as "-U -P".

  -U, --squash-uids          Squash owners making all files be owned by root.

  -P, --squash-perms         Squash permissions on all files.

  -h, --help

  -V, --version

  -v, --verbose


二、mkimage的使用

这个工具来自于uboottools中,作用是将genext2fs生成的ext2文件系统镜像压缩并生成为ramdisk镜像

使用1: ./mkimage -l image

          -l ==> list image header information

使用2:./mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image

          -A ==> set architecture to 'arch'

          -O ==> set operating system to 'os'

          -T ==> set image type to 'type'

          -C ==> set compression type 'comp'

          -a ==> set load address to 'addr' (hex)

          -e ==> set entry point to 'ep' (hex)

          -n ==> set image name to 'name'

          -d ==> use image data from 'datafile'

          -x ==> set XIP (execute in place)

使用3:./mkimage [-D dtc_options] -f fit-image.its fit-image


三、ramdisk的制作

现假设约定如下:

./rootboxbusybox生成的文件系统文件夹

1,生成ext2文件系统镜像

计算文件夹的大小:

size=`du -s --apparent-size ./rootfs | cut --fields=1`

size=`expr '(' '(' $size / 1024 ')' + 2 ')' '*' 1024 `

计算节点数:

inode_counti=`expr '(' $size / 4 ')'`

rootbox文件夹生成名为roottbox.ext2ext2文件系统镜像

genext2fs -b $size -N $inode_counti -d ./rootbox rootbox.ext2

2.生成ramdisk镜像

内存中load地址为0x2500000

ramdisk名称为 ARM Linux RAMDisk

生成的镜像名为ramdisk.img

./mkimage -A arm -O linux -T ramdisk -C gzip -a 0x2500000 -e 0x2500000 -n "ARM Linux RAMDisk" -d rootbox.ext2.gz  ramdisk.img