linux内核创建ubi,ubifs文件系统构建

=====================阶段一:创建根文件系统所需文件======================

一、构建busybox并make install

然后修改_install/bin/busybox权限:

chmod 4755 _install/bin/busybox

(给予busybox任何人可读可执行,所有者可读可写可执行,4读,2写,1执行,7=4+2+1,5=4+1,三者分别是所有者,所有者组,其他组。最前面的4表示其他用户执行该文件时,权限同所有者)

进入到_install目录创建linux需要的一些目录:

mkdir -p dev etc home lib mnt proc root sys tmp usr var/lib/misc var/lock var/log var/run var/tmp

并修改权限:

chmod 1777 tmp

chmod 1777 var/tmp

(最前面1防止被其他用户删除)

在dev下创建console和null设备:

mknod -m 660 console c 5 1

mknod -m 660 null c 1 3

mknod -m 660 ttySAC0 c 204 64

mknod -m 660 ttySAC1 c 204 65

mknod -m 660 ttySAC2 c 204 66

(这两个设备用来供init启动时调用)

看busybox依赖那些so库

/develop/crosstools/arm-dhole-linux-gnueabi/bin/arm-linux-readelf -a busybox  | grep Shared

显示结果

0x00000001 (NEEDED)                     Shared library: [libm.so.6]

0x00000001 (NEEDED)                     Shared library: [libc.so.6]

说明依赖libm.so.6和libc.so.6

把交叉编译器里的library拷贝到_install/lib目录下,

我做的交叉编译器lib库是在

/develop/crosstools/arm-dhole-linux-gnueabi/arm-dhole-linux-gnueabi/sysroot/lib/

目录下,鉴于以后的应用程序可能会用到除libm.so.6和libc.so.6外的这些库,因此全部拷过去,

在_install下执行如下命令:

cp /develop/crosstools/arm-dhole-linux-gnueabi/arm-dhole-linux-gnueabi/sysroot/lib/*.so* lib -a

然后在_install/etc下创建一些配置文件:

文件fstab:

内容如下:

----------------------------------------------------------------->

# /etc/fstab: static file system information.

#

#

#

# file system   mount       type    options           dump    pass

#for mdev

proc            /proc       proc    defaults          0       0

sysfs           /sys        sysfs   defaults          0       0

#make sure /dev /tmp /var are tmpfs(tmpfs use ram as media) thus can be r/w

tmpfs           /tmp        tmpfs   defaults          0       0

tmpfs           /dev        tmpfs   defaults          0       0

tmpfs           /var        tmpfs   defaults          0       0

#usbfs        /proc/bus/usb  usbfs   defaults          0       0

-----------------------------------------------------------------<

说明: fstab中的文件系统会被mount -a挂载。

文件inittab:

内容如下:

----------------------------------------------------------------->

# see busybox/examples/inittab

# Boot-time system configuration/initialization script.

# This is run first except when booting in single-user mode.

::sysinit:/etc/init.d/rcS

#Start an "askfirst" shell on the console (whatever that may be)

#use respawn instead askfirst to make sure console always active

::respawn:-bin/sh

# Stuff to do when restarting the init process

::restart:/sbin/init

# Stuff to do before rebooting

::ctrlaltdel:/sbin/reboot

::shutdown:/bin/umount -a -r

::shutdown:/sbin/swapoff -a

-----------------------------------------------------------------<

说明: inittab会被init执行

文件init.d/rcS:(mkdir init.d;cd init.d)

内容如下:

----------------------------------------------------------------->

#!/bin/sh

#add setting here for auto start program

PATH=/sbin:/bin:/usr/sbin:/usr/bin

runlevel=S

prevlevel=N

umask 022

export PATH runlevel prevlevel

#See docs/mdev.txt

#mount all fs in fstab,proc and sysfs are must for mdev

mount -a

#create device nodes

echo /sbin/mdev > /proc/sys/kernel/hotplug

#seed  all device nodes

mdev -s

#create pts directory for remote login such as SSH and telnet

mkdir -p /dev/pts

mount -t devpts devpts /dev/pts

if [ -f /etc/hostname ]; then

/bin/hostname -F /etc/hostname

fi

if [ -e /sys/class/net/eth0 ]; then

ifconfig eth0 192.168.1.15

fi

echo "etc init.d rcS done"

-----------------------------------------------------------------<

说明: init.d/rcS会在开机时自动执行。

更改rcS和inittab的权限为777:

chmod 777 init.d/rcS

chmod 777 inittab

=============阶段二:制作ubifs文件系统=======================================

1、制作mkfs.ubifs

yum install zlib-devel.i686

yum install lzo-devel.i686        compr_lzo.c:29:23: error: lzo/lzo1x.h: No such file or directory

yum install uuid-devel.i686

yum install uuid-dce-devel.i686

yum install libacl-devel.i686    sys/acl.h: No such file or directory

yum install libuuid-devel.i686    uuid/uuid.h: No such file or directory

make #编译pc上用的工具,我只要mkfs.ubifs

2、把_install做成ubifs文件系统:

根据下面的log

----------------------------------------------------------------->

mtd: Giving out device 2 to dhole rootfs

UBI: attaching mtd2 to ubi0

UBI: physical eraseblock size:   131072 bytes (128 KiB)

UBI: logical eraseblock size:    129024 bytes

UBI: smallest flash I/O unit:    2048

UBI: sub-page size:              512

UBI: VID header offset:          512 (aligned 512)

UBI: data offset:                2048

UBI error: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 0:0, read 64 bytes

-----------------------------------------------------------------<

得出如下命令:

./mkfs.ubifs -r /develop/project/busybox-1.19.3/_install/ -m 2048 -e 129024 -c 2008 -o ubifs.img    #2008块*128KiB*2KiB

./ubinize -o ubi.img -m 2048 -p 128KiB -s 512 ubinize.cfg

ubinize.cfg配置文件内容如下:

----------------------------------------------------------------->

[ubifs]

mode=ubi

image=ubifs.img

vol_id=0

vol_size=200MiB

vol_type=dynamic

vol_name=rootfs

vol_flags=autoresize

-----------------------------------------------------------------<

其中-m表示页面大小,-e表示逻辑擦除块大小,-c表示最大的逻辑擦除块数量,具体的可以通过barebox执行ubiattach的时候看到。

3、内核支持

(1)、配置内核支持UBIFS

Device Drivers   --->Memory Technology Device (MTD) support  --->UBI - Unsorted block  images  --->Enable UBI

(2)、配置mtd支持UBI接口

File  systems  --->Miscellaneous filesystems  --->UBIFS file system  support配置内核支持UBIFS文件系统

有关ubifs的详细介绍,请参考:

=================阶段三=========================================================

///u-boot 烧写ubifs.img/

1、使用默认的分区对nand进行分区

mtdpart default

2、查看分区表

mtdpart

结果如下:

----------------------------------------------------------------->

device nand0 , # parts = 3

#: name                size            offset          mask_flags

0: uboot               0x00100000      0x00000000      0

1: kernel              0x00400000      0x00100000      0

2: root                0x0fb00000      0x00500000      0

active partition: nand0,0 - (uboot) 0x00100000 @ 0x00000000

defaults:

mtdids  : nand0=nandflash0

mtdparts: mtdparts=nandflash0:1m(uboot),4m(kernel),-(root)

-----------------------------------------------------------------<

4、擦除uboot的root分区

nand erase.part root

结果如下:

----------------------------------------------------------------->

NAND erase.part: device 0 offset 0x500000, size 0xfb00000

Skipping bad block at  0x01a80000

Skipping bad block at  0x03f40000

Erasing at 0xffe0000 -- 100% complete.

OK

-----------------------------------------------------------------<

5、用ubi格式格式化root分区

ubi part root    设置root(u-boot)分区为当前分区,后面所有的命令ubi都基于root分区操作

结果如下:

----------------------------------------------------------------->

Creating 1 MTD partitions on "nand0":

0x000000500000-0x000010000000 : "mtd=2"

UBI: attaching mtd1 to ubi0

UBI: physical eraseblock size:   131072 bytes (128 KiB)

UBI: logical eraseblock size:    129024 bytes

UBI: smallest flash I/O unit:    2048

UBI: sub-page size:              512

UBI: VID header offset:          512 (aligned 512)

UBI: data offset:                2048

UBI: empty MTD device detected

UBI: create volume table (copy #1)

UBI: create volume table (copy #2)

UBI: attached mtd1 to ubi0

UBI: MTD device name:            "mtd=2"

UBI: MTD device size:            251 MiB

UBI: number of good PEBs:        2006

UBI: number of bad PEBs:         2

UBI: max. allowed volumes:       128

UBI: wear-leveling threshold:    4096

UBI: number of internal volumes: 1

UBI: number of user volumes:     0

UBI: available PEBs:             1982

UBI: total number of reserved PEBs: 24

UBI: number of PEBs reserved for bad PEB handling: 20

UBI: max/mean erase counter: 1/0

-----------------------------------------------------------------<

6、创建linux用的rootfs分区,"rootfs"这个名字必须和内核中的名字一样

ubi create rootfs

结果如下:

----------------------------------------------------------------->

No size specified -> Using max size (255725568)

Creating dynamic volume root of size 255725568

-----------------------------------------------------------------<

7、把ubifs.img烧写到flash中

tftp 0x31000000 ubifs.img

ubi write 0x31000000 rootfs 0x607800    #注意命令执行顺序,否则没用rootfs为linux中用的的分区名字

11、修复错误"ubi_io_write: error -5 while writing 512 bytes to PEB 5:512"

make menuconfig

#去除选项,此处有问题的描述

Device Drivers  ---> Memory Technology Device (MTD) support  ---> NAND Device Support  ---> Verify NAND page writes

由于我移植的u-boot还没有实现硬件校验,而软件校验和硬件校验的结果不同,造成linux驱动读写ubifs文件系统失败,所以暂时先屏蔽nand 硬件校验

Device Drivers  ---> Memory Technology Device (MTD) support  ---> NAND Device Support  ---> Samsung S3C NAND Hardware ECC

这样内核就可以顺利的启动到下面的log处,但还是没有成功引导进入shell

----------------------------------------------------------------->

......

UBIFS: mounted UBI device 0, volume 0, name "rootfs"

UBIFS: file system size:   254306304 bytes (248346 KiB, 242 MiB, 1971 LEBs)

UBIFS: journal size:       9033728 bytes (8822 KiB, 8 MiB, 71 LEBs)

UBIFS: media format:       w4/r0 (latest is w4/r0)

UBIFS: default compressor: lzo

UBIFS: reserved for root:  0 bytes (0 KiB)

VFS: Mounted root (ubifs filesystem) on device 0:13.

Freeing init memory: 136K

Kernel panic - not syncing: Attempted to kill init!

[] (unwind_backtrace+0x0/0xf0) from [] (panic+0x58/0x188)

[] (panic+0x58/0x188) from [] (do_exit+0x5dc/0x6c4)

[] (do_exit+0x5dc/0x6c4) from [] (do_group_exit+0x3c/0xbc)

[] (do_group_exit+0x3c/0xbc) from [] (get_signal_to_deliver+0x1bc/0x490)

[] (get_signal_to_deliver+0x1bc/0x490) from [] (do_signal+0x90/0x4e8)

[] (do_signal+0x90/0x4e8) from [] (do_notify_resume+0x60/0x6c)

[] (do_notify_resume+0x60/0x6c) from [] (work_pending+0x24/0x28)

在此处死了

-----------------------------------------------------------------<

而上面的错误是由于交叉编译器的错误,导致编译出来的busybox执行失败,一般是交叉编译器生出了cpu不支持的指令。

解决方案重做交叉编译器

阅读(5758) | 评论(0) | 转发(1) |

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值