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 MIME-Version: 1.0 To: Brian Norris , Matt Kline CC: , Richard Weinberger Subject: Re: [PATCH] Update UBIFS mounting instructions References: <1427921758-10295-1-git-send-email-matthew.kline@flukenetworks.com> <20151219011822.GZ10460@google.com> In-Reply-To: <20151219011822.GZ10460@google.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On 12/19/2015 09:18 AM, Brian Norris wrote: > Garbage collecting old patches... > > On Wed, Apr 01, 2015 at 01:55:58PM -0700, Matt Kline wrote: >> I recently spent several days attempting to mount a UBIFS image. >> Efforts were hampered by seemingly outdated documentation, >> the fact that much of the documentation was for UBI images, >> not UBIFS ones, and the fact that the image was for NOR memory and >> all documentation I found only referenced nandsim. >> >> After some very kind help on IRC and from Artem Bityutskiy on the >> mailing list, I was able to figure things out. I think it is only >> fair that I contribute back and bring the web site up to date so >> others don't face the same stumbling blocks. >> >> This patch includes the following changes: >> >> - Acknowledge that udev _does_ now create a block device >> automatically for MTD. >> >> - Provide instructions for mounting standalone UBIFS images as well >> as UBI images. >> >> - Mention mtdram and its usefulness in mounting UBIFS images made >> for NOR memory. >> >> Signed-off-by: Matt Kline > > This looks pretty good to me (as in, it's a net positive). I know > Dongsheng Yang (and Richard?) has been working on some kind of user > space unpacker tools, so this might be out of date "soon". But when > isn't documentation out of date? :) Yes, agreed. BTW, Brian and Richard, I would like to pick patches from Richard in my local tree, fixing some conflict maybe. And then send a patchset out about unpacker and ubifs_dump tools. Is that okey? Yang > > Anyway, pushed to mtd-www.git. Improvements are welcome from anyone > doing updates to this though! > > Thanks, > Brian > >> --- >> faq/ubifs.xml | 81 +++++++++++++++++++++++++++++++++++++++-------------------- >> 1 file changed, 54 insertions(+), 27 deletions(-) >> >> diff --git a/faq/ubifs.xml b/faq/ubifs.xml >> index 8b61fc7..2b724f3 100644 >> --- a/faq/ubifs.xml >> +++ b/faq/ubifs.xml >> @@ -894,10 +894,9 @@ embedded systems.

>> 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 >> >> # Load UBI module and attach mtd0 >> modprobe ubi mtd=0 >> @@ -917,44 +916,65 @@ mount -t ubifs /dev/ubi0_0 /mnt/ubifs >>

How do I extract files from an UBI/UBIFS image?

>> >>

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: >> +

    >> +
  1. 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.
  2. >> + >> +
  3. 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. >> +
  4. >> +
>> +These modules should be provided on most distributions released in the past >> +few years.

>> >> -

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. >> >> >>

I need more space - should I make UBIFS journal smaller?

>> -- >> 2.3.4 >> >> ______________________________________________________ >> Linux MTD discussion mailing list >> http://lists.infradead.org/mailman/listinfo/linux-mtd/ > > > . >