From mboxrd@z Thu Jan 1 00:00:00 1970
Received: from [59.151.112.132] (helo=heian.cn.fujitsu.com)
by casper.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux))
id 1aAUGO-00047u-4R
for linux-mtd@lists.infradead.org; Sun, 20 Dec 2015 03:02:28 +0000
Message-ID: <56761811.7060604@cn.fujitsu.com>
Date: Sun, 20 Dec 2015 10:53:05 +0800
From: Dongsheng Yang
Unfortunately, at the moment there are no user-space tools which can >> -unwrap UBI and UBIFS images. UBIFS cannot be loop-back mounted as well, >> +unwrap UBI and UBIFS images. UBIFS cannot be loop-back mounted either, >> because it does not work with block devices.
>> >> -However, there is a hacky way to unwrap UBI/UBIFS images. But you have >> -to make sure you have UBIFS support in your host machine. UBIFS is a relatively >> -new file system and is not supported by all Linux distributions. But at least >> -Fedora 11 does include it.
>> +However, kernel modules exist that allow you to create a virtual MTD >> +onto which UBIFS can be mounted. You have two options: >> +
nandsim
, which can simulate various NAND devices.
>> + You can find an incomplete list of those devices
>> + here.
>> + To emulate a given device, pass its ID bytes via the module parameters
>> + first_id_byte
, second_id_byte
,
>> + third_id_byte
, and fourth_id_byte
.mtdram
, which simulates a generic MTD.
>> + Use the module parameter total_size
to specify the device size
>> + in KiB and erase_size
to specify the erase block size in KiB.
>> + This module is useful for mounting UBIFS images made for NOR memory,
>> + which usually have a minimum I/O unit of 1 byte, as opposed to NAND
>> + devices which have a minimum unit of at least 512 bytes.
>> + See more information here.
>> + Let's consider a simple example. Suppose you have an ubi.img
>> -file. This is an UBI image, which contains a single UBI volume, which in turn
>> -contains UBIFS file-system. In other words, this is an image which was
>> -created using the mkfs.ubifs
and ubinize
tools,
>> -just like it is described in this
>> -section (the image is created for a 256MiB NAND flash with 2KiB NAND page
>> -size and which supports sub-pages). Here is what you can do:
Consider a simple example. Suppose you have some ubifs.img
>> +file which contains a single UBIFS filesystem.
>> +In other words, this is an image which was created using mkfs.ubifs
,
>> +as described in this section. To mount it:
>> -# Create an 256MiB emulated NAND flash with 2KiB NAND page size >> -# (you should see the new MTD device in /proc/mtd) >> +# Create a virtual MTD by bringing up one of the kernel modules mentioned above. >> modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa \ >> third_id_byte=0x00 fourth_id_byte=0x15 >> >> -# MTD is not LDM-enabled and udev does not create device >> -# MTD device nodes automatically, so create /dev/mtd0 >> -# (we assume that you do not have other MTD devices) >> -mknod /dev/mtd0 c 90 0 >> +# udev should create MTD device nodes automatically. >> +# If it does not, we can create /dev/mtd0 manually with >> +# mknod /dev/mtd0 c 90 0 >> >> -# Copy the contents of your image to the emulated MTD device >> -dd if=ubi.img of=/dev/mtd0 bs=2048 >> +# Format the device. IOSIZE should be the minimum I/O unit size passed >> +# via -s to mkfs.ubifs when the image was created. >> +ubiformat /dev/mtd0 -s $IOSIZE >> >> # Load UBI module and attach mtd0 >> modprobe ubi mtd=0 >> >> -# Mount UBIFS >> -mount -t ubifs /dev/ubi0_0 /mnt/ubifs >> +# Create a volume. >> +# -N names the volume and -s sets its size, in bytes, kilobytes (KiB), >> +# or megabytes (MiB). Make sure it is at least as large as the image. >> +ubimkvol /dev/ubi0 -N "My UBIFS volume name" -s $VOLSIZE >> + >> +# Apply our image to that volume >> +ubiupdatevol /dev/ubi0_0 ubifs.img >> + >> +# Mount it to any desired mount point >> +mount /dev/ubi0_0 /mnt/ubifs >>>> >> -
Now you have the file-system in /mnt/ubifs
. Use
>> +
Now you have the filesystem in /mnt/ubifs
. Use
>> the following to get rid of it:
>> @@ -962,6 +982,13 @@ umount /mnt/ubifs >> rmmod ubifs ubi nandsim >>>> >> +If you have an entire UBI image made with
ubinize
,
>> +the process is simpler.
>> +Write the image to the MTD via ubiformat -f ubi.img
>> +(assuming that is the name of your image file).
>> +You should be able to skip the instructions above after
>> +modprobe ubi mtd=0
, since
>> +the UBI image should take care of the volume(s) itself.
>>
>>
>>