ubifs文件系统的制作

1. ubifs文件系统简介

摘自官网上的简介:One thing people have to understand when dealing with UBIFS is that UBIFS is very different to any traditional file system - it does not work on top of block devices (like hard drives, MMC/SD cards, USB flash drives, SSDs, etc). UBIFS was designed to work on top of raw flash, which has nothing to do with block devices. This is why UBIFS does not work on MMC cards and the like - they look like block devices to the outside world because they implement FTL (Flash Translation Layer) support in hardware, which simply speaking emulates a block device on top of the built-in raw flash. Please, make sure you understand the differences between raw flash and, say, MMC flash before dealing with UBIFS. This section should help.
… … …
简而言之,ubifs建立在ubi卷层之上,ubi卷层工作在mtd设备层之上,ubifs涉及三个子系统,区别jffs2,yaffs2直接工作在mtd设备层上面;不能工作在SD卡,U盘这些常用的设备上面,是直接工作在Raw Flash设备上(如Nandflash)。详细内容可以去官网查看。这个是官网上的链接。

2.根文件镜像制作

2.1 mkfs.jffs2使用说明

[klaus@localhost ~]$ cd fl2240maker/jffs+ker_fl2440/linux/
[klaus@localhost linux]$ mkfs.ubifs -h
[klaus@localhost linux]$ ubinize -h

2.2 参数选定

[klaus@localhost linux]$ ls
kernel  linux-3.0  linux-3.0.tar.bz2  rootfs
[klaus@localhost linux]$ mkfs.ubifs -x lzo -m 2048 -e 129024 -c 300 -r ./rootfs -o rootfs-ubifs.img
Error: cannot create output file 'rootfs-ubifs.img'
       Permission denied (error 13)
[klaus@localhost linux]$ sudo mkfs.ubifs -x lzo -m 2048 -e 129024 -c 300 -r ./rootfs -o rootfs-ubifs.img
[sudo] password for klaus: 
[klaus@localhost linux]$ sudo vim ubinize.ini
[klaus@localhost linux]$ sudo ubinize -o rootfs-ubifs.bin -m 2048 -p 131072 -s 512 -O 512 ubinize.ini
[klaus@localhost linux]$ ls
kernel  linux-3.0  linux-3.0.tar.bz2  rootfs  rootfs-ubifs.bin  rootfs-ubifs.img  ubinize.ini
[klaus@localhost linux]$ du -h rootfs-ubifs.bin
8.3M    rootfs-ubifs.bin

2.3 参数解读

mkfs.ubifs

  • -x lzo 指定使用lzo压缩方法
  • -m 2048 Nand Flash的最小读写单元
  • -e 129024 指定LEB(Logical Erase Block,逻辑擦除块)大小
  • -r ./rootfs 指定根文件系统目录树的路径
  • -o rootfs-ubifs.img 指定制作出的根文件系统镜像文件名
  • -c 300 指定该分区最大逻辑擦除块数量(预设坏块容忍量为16)

ubinize.ini

[klaus@localhost linux]$ cat ubinize.ini 
[ubifs-volume]
mode=ubi
image=rootfs-ubifs.img //指定根文件系统镜像文件路径
vol_id=0 //指定根文件系统树的卷标为0
vol_size=38707200//指定该UBI逻辑卷的大小=逻辑擦除块大小*逻辑擦除块个数
vol_type=dynamic
vol_name=rootfs//指定UBI卷的名称
vol_flags=autoresize//UBI Subsystem在系统启动时自动调整逻辑擦除块的个数
vol_alignment=1
[klaus@localhost linux]$ 

ubinize

  • -o rootfs-ubifs.bin 指定生成文件名
  • -m 2048 nandflash的页大小
  • -p 131072 指定物理擦除块大小
  • -s 512 指定sub-page-size大小

3. 内核配置和编译

3.1 General setup

同样,取消对inittramfs文件系统的支持。
ubifs文件系统的制作_第1张图片

3.2 Device Drivers

使能ubi,因为ubifs文件系统建立在ubi一层上。

<*> Memory Technology Device (MTD) support
    < > RedBoot partition table parsing
    < > FTL (Flash Translation Layer) support
    < > NFTL (NAND Flash Translation Layer) support
       Enable UBI - Unsorted block images  --->
          --- Enable UBI - Unsorted block images
              (4096) UBI wear-leveling threshold (NEW)
              (1)   Percentage of reserved eraseblocks for bad eraseblocks handling (NEW)
              MTD devices emulation driver (gluebi) (NEW)
              [ ]   UBI debugging (NEW) 

3.3 File systems

选择支持ubifs文件系统

[*] Miscellaneous filesystems --->
    <M>   UBIFS file system support
    [*] Extended attributes support
    [*] Advanced compression options
    [*] LZO compression support (NEW)
    [*] ZLIB compression support (NEW)
    [ ] Enable debugging support (NEW)

3.4 重新编译生成uimage镜像文件

[klaus@localhost linux-3.0]$ make
[klaus@localhost linux-3.0]$ sudo mkimage -A arm -O linux -T kernel -C none -a 30008000 -e 30008040 -n "Linux Kernel" -d arch/arm/boot/zImage linuxrom-s3c2440.bin 
[sudo] password for klaus: 
Image Name:   Linux Kernel
Created:      Sat Apr  7 00:10:16 2018
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    2291796 Bytes = 2238.08 kB = 2.19 MB
Load Address: 30008000
Entry Point:  30008040
[klaus@localhost linux-3.0]$ du -h linuxrom-s3c2440.bin 
2.2M    linuxrom-s3c2440.bin

4. u-boot环境变量及烧录

这一步可以借鉴jiffs2文件系统的烧录方式和说明

4.1 内核烧录

[fl2440@lingyun]# set bootcmd 'nand read 30008000 100000 400000; bootm 30008000'
[fl2440@lingyun]# tftp 30008000 linuxrom-s3c2440.bin
dm9000 i/o: 0x20000300, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:11:22:33:44:55
could not establish link
Using dm9000 device
TFTP from server 192.168.100.8; our IP address is 192.168.100.18
Filename 'linuxrom-s3c2440.bin'.
Load address: 0x30008000
Loading: #################################################################
         #################################################################
         ###########################
done
Bytes transferred = 2291860 (22f894 hex)
[fl2440@lingyun]# nand erase 100000 F00000

NAND erase: device 0 offset 0x100000, size 0xf00000
Skipping bad block at  0x004c0000                                          
Erasing at 0xfe0000 -- 100% complete.
OK
[fl2440@lingyun]# nand write 30008000 100000 400000

NAND write: device 0 offset 0x100000, size 0x400000
Skip bad block 0x004c0000
 4194304 bytes written: OK

4.2 文件系统烧录

[fl2440@lingyun]# tftp 30008000 rootfs-ubifs.bin
dm9000 i/o: 0x20000300, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:11:22:33:44:55
could not establish link
Using dm9000 device
TFTP from server 192.168.100.8; our IP address is 192.168.100.18
Filename 'rootfs-ubifs.bin'.
Load address: 0x30008000
Loading: T #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #####
done
Bytes transferred = 8650752 (840000 hex)
[fl2440@lingyun]# nand erase 1000000 2800000

NAND erase: device 0 offset 0x1000000, size 0x2800000
Erasing at 0x37e0000 -- 100% complete.
OK
[fl2440@lingyun]# nand write 30008000 1000000 $filesize

NAND write: device 0 offset 0x1000000, size 0x840000
 8650752 bytes written: OK

5.重新启动

烧录完成后,我们可以直接重启开发板或者使用boot命令

~ >: mount
rootfs on / type rootfs (rw)
ubi0:rootfs on / type ubifs (rw,relatime) 
proc on /proc type proc (rw,relatime)
usbfs on /proc/bus/usb type usbfs (rw,relatime)
tmpfs on /dev type tmpfs (rw,relatime)
ramfs on /tmp type ramfs (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600)

可以看到是直接挂载到了根上,ubifs格式。

6.问题出现

重启过程中,发现内核没有运行起来

... ... ...
s3c-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
s3c-rtc s3c2410-rtc: setting system clock to 2017-11-04 03:01:42 UTC (1509764502)
VFS: Cannot open root device "ubi0:rootfs" or unknown-block(0,0)
Please append a correct "root=" boot option; here are the available partitions:
1f00            1024 mtdblock0  (driver?)
1f01           15360 mtdblock1  (driver?)
1f02           40960 mtdblock2  (driver?)
1f03           81920 mtdblock3  (driver?)
1f04           81920 mtdblock4  (driver?)
1f05           40960 mtdblock5  (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[] (unwind_backtrace+0x0/0xf4) from [] (panic+0x58/0x188)
[] (panic+0x58/0x188) from [] (mount_block_root+0x16c/0x220)
[] (mount_block_root+0x16c/0x220) from [] (prepare_namespace+0x8c/0x1b0)
[] (prepare_namespace+0x8c/0x1b0) from [] (kernel_init+0xdc/0x110)
[] (kernel_init+0xdc/0x110) from [] (kernel_thread_exit+0x0/0x8)

这个是参考解释链接。

你可能感兴趣的:(liunx开发学习笔记)