Testing an ubi+ubifs on qemu-system-mipsel

Lluís Batlle i Rossell viriketo at gmail.com
Sun Nov 21 06:02:39 EST 2010


Hello,

yesterday I managed to boot an ubi+ubifs image in qemu. I'll summarize what made
that thing work.
Note that this does not require having a root account in the host.

You need:
- qemu (specifically, qemu-system-mipsel) (I used 12.3, 13.0 will do I imagine)
- linux source, I used 2.6.36 (and the tools needed to build the kernel)
- an ubifs image (you may need to learn mtd-utils to prepare it)

1. Build a linux kernel for the malta board (use the malta_defconfig). That
board, the default in qemu-system-mips, has a PCI bus, where the qemu IDE
controllers will work.
Enable over the defconfig (I hope these are enough):
- UBIFS options
- UBI options
- BLOCK2MTD (this emulates a NOR flash from a block device)

2. Prepare the ubifs image.
The block2mtd can use any size for the PEBs (part of its command line), but its
sub-page fetches allows for 1-byte fetches. This means that on mkfs.ubifs and
ubinize you should use "-m 1". In a case close to the Nanonote, I used a
Physical PEB size of 512KiB (-p 512KiB in ubinize), that ends up in a Logical
PEB size of 524160 (-e 523160 in mkfs.ubifs).
You should set up a volume size in ubinize, and consider that you will need to
create a file slightly bigger than that in the next step.
Compile the kernel with "make vmlinux.bin", for example, and get the 'vmlinux'
ELF file resulting (not vmlinux.bin). This is what qemu knows how to boot.

3. Prepare the block device. The 'ubinize' command prepares a minimal file that
has to be written into a mtdblock device. But block2mtd needs a file that spans
along all the memory. Specifically, ubi expects the memory to be slightly
bigger; it needs some extra PEBs for it to work, regardles of it's said in the
ubinize config to be static or dynamic. For the example in step 4, I labelled
the volume "rootfs".

To achieve this, let's say that I set the volume size to be 50MiB... then I
will make a file of 60MiB. The ubi web site tells about the exact amount of PEBs
needed over the volume size, but I simply noticed that 2MiB were too few, and
10MiB worked fine.

Then we need to pad the ubi image we created with ubinize with 0xFF until it
makes the size of 60MiB. I did something like this:
SIZE=`wc -c rootfs.img | cut -f 1 -d \ `
MISS=`expr \( 60 \* 1024 \* 1024 - $SIZE \) / 1024`
cat /dev/zero | tr '\0' '\377' | dd bs=1024 count=$MISS >> rootfs.img

4. Boot qemu. I used this command line to set up the ubi. I used "-nographic"
and "-snapshot", but I leave that up to the qemu caller.

qemu-system-mipsel -hda rootfs.img -kernel vmlinux -append \
"root=ubi0:rootfs rootfstype=ubifs block2mtd.block2mtd=/dev/hda,524288 ubi.mtd=0"

That should work. I think that an ubifs image build for mips32 should work in
the malta platform, so most of the nanonote (terminal-only, maybe) software will
work there. I don't know if the malta board gives some framebuffer when not
using "-nographic".

Booting, you should see things like these:

block2mtd: mtd0: [/dev/hda] erase_size = 512KiB [524288]
UBI: attaching mtd0 to ubi0
UBI: physical eraseblock size:   524288 bytes (512 KiB)
UBI: logical eraseblock size:    524160 bytes
UBI: smallest flash I/O unit:    1
UBI: VID header offset:          64 (aligned 64)
UBI: data offset:                128
UBI: max. sequence number:       0
UBI: volume 0 ("rootfs") re-sized from 118 to 133 LEBs
UBI: attached mtd0 to ubi0
UBI: MTD device name:            "block2mtd: /dev/hda"
UBI: MTD device size:            68 MiB
UBI: number of good PEBs:        137
UBI: number of bad PEBs:         0
UBI: max. allowed volumes:       128
UBI: wear-leveling threshold:    4096
UBI: number of internal volumes: 1
UBI: number of user volumes:     1
UBI: available PEBs:             0
UBI: total number of reserved PEBs: 137
UBI: number of PEBs reserved for bad PEB handling: 0
UBI: max/mean erase counter: 1/0
UBI: image sequence number:  836554110
UBIFS: mounted UBI device 0, volume 0, name "rootfs"
UBIFS: mounted read-only
UBIFS: file system size:   64471680 bytes (62960 KiB, 61 MiB, 123 LEBs)
UBIFS: journal size:       10485248 bytes (10239 KiB, 9 MiB, 21 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) readonly on device 0:12.

Best regards,
Lluís.




More information about the discussion mailing list


interactive