UBI/ubifs problem

Paul Parsons lost.distance at yahoo.com
Wed Mar 7 11:51:25 EST 2012


--- On Wed, 7/3/12, Ricard Wanderlof <ricard.wanderlof at axis.com> wrote:
> Is it possible to get mkfs.ubifs to create an image without
> specifying the max-leb-count ? I.e. just to create an image
> that is as big as it has to be. Admittedly, one would have
> to figure out the size of the resulting volume afterwards,
> to provide an allocation size for ubimkvol or ubinize, so
> perhaps it would help much.

When I first started to try out UBI/UBIFS I had problems understanding the
arithmetic, and it took several attempts to get it working.

In the end I created a simple shell script to do all the hard work for me.

Given the UBI MTD partition size, PEB size, and desired volume sizes, the
script would do the rest:

#!/bin/bash

#
#	Create UBI for 125MiB MTD on NOR flash, consisting of:
#
#		UBI overhead.
#		Volume 0: rootfs, 75MiB less UBI overhead.
#		Volume 1: homefs, 50MiB.
#

declare -r rootimg="rootfs.img"
declare -r homeimg="homefs.img"
declare -r ipaqcfg="ipaq.cfg"

declare -ir KiB=1024
declare -ir MiB=$((1024*1024))

declare -i UBI=$((125*MiB))			# UBI size
declare -i Sp=$((256*KiB))			# PEB size
declare -i P=$((UBI/Sp))			# Total number of PEBs
declare -i O=128				# EC header + VID header overhead
declare -i Sl=$((Sp-O))				# LEB size
declare -i B=0					# NOR does not have bad PEBs
declare -i U=$((((B+4)*Sp)+(O*(P-B-4))))	# UBI overhead
declare -i Ur=$(((U+Sp-1)&(~(Sp-1))))		# UBI overhead rounded up to next PEB size

declare -i ROOTFS=$(((75*MiB)-Ur))		# rootfs size
declare -i HOMEFS=$((50*MiB))			# homefs size

cmd="mkfs.ubifs --root=rootfs --output=${rootimg} -m 1 -e ${Sl} -c $((ROOTFS/Sp)) -x none"
echo ${cmd}
${cmd} || exit 1

cmd="mkfs.ubifs --root=homefs --output=${homeimg} -m 1 -e ${Sl} -c $((HOMEFS/Sp)) -x none"
echo ${cmd}
${cmd} || exit 1

rm -f ${ipaqcfg}
echo "[rootfs]" >> ${ipaqcfg}
echo "mode=ubi" >> ${ipaqcfg}
echo "image=${rootimg}" >> ${ipaqcfg}
echo "vol_id=0" >> ${ipaqcfg}
echo "vol_size=$((((ROOTFS)/Sp)*Sl))" >> ${ipaqcfg}
echo "vol_type=dynamic" >> ${ipaqcfg}
echo "vol_name=rootfs" >> ${ipaqcfg}
echo "[homefs]" >> ${ipaqcfg}
echo "mode=ubi" >> ${ipaqcfg}
echo "image=${homeimg}" >> ${ipaqcfg}
echo "vol_id=1" >> ${ipaqcfg}
echo "vol_size=$((((HOMEFS)/Sp)*Sl))" >> ${ipaqcfg}
echo "vol_type=dynamic" >> ${ipaqcfg}
echo "vol_name=homefs" >> ${ipaqcfg}

cmd="ubinize -o ipaq.ubi -p ${Sp} -m 1 -v ${ipaqcfg}"
echo ${cmd}
${cmd} || exit 1

It works for me. Hopefully it might be useful to others.



More information about the linux-mtd mailing list