public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Paul Parsons <lost.distance@yahoo.com>
To: Artem Bityutskiy <dedekind1@gmail.com>,
	Ricard Wanderlof <ricard.wanderlof@axis.com>
Cc: "Ricard Wanderlöf" <ricardw@axis.com>,
	"Linux mtd" <linux-mtd@lists.infradead.org>
Subject: Re: UBI/ubifs problem
Date: Wed, 7 Mar 2012 16:51:25 +0000 (GMT)	[thread overview]
Message-ID: <1331139085.50366.YahooMailClassic@web29001.mail.ird.yahoo.com> (raw)
In-Reply-To: <Pine.LNX.4.64.1203071723410.21132@lnxricardw.se.axis.com>

--- On Wed, 7/3/12, Ricard Wanderlof <ricard.wanderlof@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.

      parent reply	other threads:[~2012-03-07 16:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-16 15:17 UBI/ubifs problem Ricard Wanderlof
2012-02-17 10:13 ` Ricard Wanderlof
2012-03-07 14:40   ` Artem Bityutskiy
2012-03-07 16:26     ` Ricard Wanderlof
2012-03-07 16:37       ` Artem Bityutskiy
2012-03-08  5:09         ` Ricard Wanderlof
2012-03-09 13:39           ` Artem Bityutskiy
2012-03-09 13:45             ` Ricard Wanderlof
2012-03-09 13:51               ` Artem Bityutskiy
2012-03-07 16:51       ` Paul Parsons [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1331139085.50366.YahooMailClassic@web29001.mail.ird.yahoo.com \
    --to=lost.distance@yahoo.com \
    --cc=dedekind1@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=ricard.wanderlof@axis.com \
    --cc=ricardw@axis.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox