Chinaunix首页 | 论坛 | 博客
  • 博客访问: 143439
  • 博文数量: 29
  • 博客积分: 717
  • 博客等级: 上士
  • 技术积分: 352
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-16 16:17
文章分类

全部博文(29)

文章存档

2013年(4)

2012年(4)

2011年(21)

我的朋友

分类: LINUX

2013-02-21 17:13:30

This file store on my homepage: 


HOW-TO build embedded file system

 

WARNING: PLEASE READ IN WEB LAYOUT VIEW

In general, the image have two format : BIG-ENDBIAN OR LITTLE-ENDBIAN

由于内核是以root身份来运行用户空间的第一个进程,所以创建根文件系统时需要注意文件系统里文件的权限!

 

YAFFS

mkyaffs2image

unyaffs image_file_name

reference:

 

JFFS2

reference:

http://blog.2of1.org/2010/07/11/mounting-jffs2-on-ubuntu/

https://wiki.maemo.org/Modifying_the_root_image

 

LZMA

Gzip

 

Initramdisk/Initramfs

内核是通过gen_initramfs_list.sh脚本来生成initramdisk和initramfs,这两种的文件格式都是cpio,创建的方法有三种:

1.      直接传递一个目标目录的path,并且设置CONFIG_INITRAMFS_ROOT_UID和CONFIG_INITRAMFS_ROOT_GID为目标目录里文件的uid和gid(进制是十进制)。

2.      直接传递个cpio数据包

3.      传递cpio数据包中的文件描述符的配置文件

方法1,中间都会产生3,即描述符的配置文件。

 

KERNELDIR/scripts/gen_initramfs_list.sh的usage:

gen_initramfs_list.sh [-o ] [-u ] [-g ] {-d | } …

       -o       Create compressed initramfs file named using gen_init_cpio and compressor depending on the extension

       -u        User ID to map to user ID 0 (root).  is only meaningful if is a directory. "squash" forces all files to uid 0.

       -g        Group ID to map to group ID 0 (root). is only meaningful if is a directory. "squash" forces all files to gid 0.

         File list or directory for cpio archive. If is a .cpio file it will be used as direct input to initramfs.

       -d             Output the default cpio list.

 

?   方式1

在KERNELDIR/scripts/gen_initramfs_list.sh 116 : prase()函数的代码片段

parse() {

       local uid="$3"

       local gid="$4"

      

       # remap uid/gid to 0 if necessary

       [ "$root_uid" = "squash" ] && uid=0 || [ "$uid" -eq "$root_uid" ] && uid=0

       [ "$root_gid" = "squash" ] && gid=0 || [ "$gid" -eq "$root_gid" ] && gid=0

上面两句脚本的含义是如果变量root_uid等于squash或者变量uid那么将uid赋值为0,即initramfs里的文件的owner就是root,gid亦是如此。变量root_uid和root_gid是通过CONFIG_INITRAMFS_ROOT_UID和CONFIG_INITRAMFS_ROOT_GID传递,变量uid和gid是脚本内部通过$3,$4传递的,这两个变量是目标目录里文件的uid和gid。另外测试时发现设置CONFIG_INITRAMFS_ROOT_UID和CONFIG_INITRAMFS_ROOT_GID为squash时会出错???

 

内核生成intramfs的Makefile:

在KERNELDIR/usr/Makfile 58: 该目标会生成cpio格式的文件initramfs_data.cpio。其中$(Q)=@, 即执行该命令时不会向终端打印该命令本身内容

                     $(obj)/initramfs_data.cpio$(suffix_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdir

                     $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.d

                     $(call if_changed,initfs)

在KERNELDIR/usr/Makfile 46 : 定义了initfs所执行的内容

                     quiet_cmd_initfs = GEN     $@

                            cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)

在KERNELDIR/usr/Makfile 30 : 定义了initramfs、ramfsflag、ramfs-input变量

                     initramfs   := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh

                            ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \

                     $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d)

                            ramfs-args  := \

                            $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \

                            $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))    

目标最后执行$(call if_changed,initfs),会调用cmd_initfs, 等价于执行

gen_initramfs_list.sh -o $(obj)/initramfs_data.cpio$(suffix_y) -u $(CONFIG_INITRAMFS_ROOT_UID) -g $(CONFIG_INITRAMFS_ROOT_GID) $(ramfs-input)

 

?   方式2

Help info

Command: cpio –help

Reference:

执行cpio –help,部分信息打印如下

Operation modifiers valid in copy-in and copy-out modes:

      --absolute-filenames   Do not strip file system prefix components from the file names

      --no-absolute-filenames   Create all files relative to the current directory

因此在使用cpio进行解压缩文件时,可以先使用archive manager打开该文件,查看是否有”.”目录,如果没有解压时需要加--no-absolute-filenames,否则会解压到当前系统的”/”目录。可以简单使用下面的命令来完成cpio文件的压缩和解压缩

压缩: find . -depth -print | cpio -H newc -o >../data.cpio. cpio命令的 -H 选项指定打包文件的具体格式,要生成initramfs,只能用newc 格式,内核会打出这样的出错信息:Unpacking initramfs...<0> kernel panic - not syncing: no cpio magic

解压: cpio -id < ../data.cpio或者cpio -i -F data.cpio –no-absolute-filenames

阅读(2324) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~