Active Topics

 


Reply
Thread Tools
joerg_rw's Avatar
Posts: 2,222 | Thanked: 12,651 times | Joined on Mar 2010 @ SOL 3
#11
writing to mtd with dd is prone to fail, as dd doesn't know about bad block management in mtd, and mtd is a *raw* device where you eventually will run into an occasional bad block.

There are tools that are specifically built to deal with bad blocks on mtd, e.g mtd_debug is one of them I'd assume, available in fremantle.

/j
__________________
Maemo Community Council member [2012-10, 2013-05, 2013-11, 2014-06 terms]
Hildon Foundation Council inaugural member.
MCe.V. foundation member

EX Hildon Foundation approved
Maemo Administration Coordinator (stepped down due to bullying 2014-04-05)
aka "techstaff" - the guys who keep your infra running - Devotion to Duty http://xkcd.com/705/

IRC(freenode): DocScrutinizer*
First USB hostmode fanatic, father of H-E-N
 

The Following User Says Thank You to joerg_rw For This Useful Post:
Posts: 2,154 | Thanked: 8,464 times | Joined on May 2010
#12
Correct way how to erase/flash rootfs partition (on which is ubi) is to use ubiformat utility.

Before using ubiformat utility, first any mounted ubifs volume must be umounted and ubi device deattached from mtd partition.

Code:
$ umount ubi:rootfs
$ ubidetach /dev/ubi_ctrl -d 0
Erasing mtd partition on with is ubi:

Code:
$ ubiformat /dev/<mtd_rootfs>
Erasing & Flashing new ubi image (with volumes) on mtd partition:

Code:
$ ubiformat /dev/<mtd_rootfs> -s 512 -O 512 -f <image.ubi>
After flashing new ubi image to mtd, ubi can be attached to mtd device again:

Code:
$ ubiattach /dev/ubi_ctrl -p /dev/<mtd_rootfs>
And then available ubifs volume in ubi can be mounted
Code:
$ mount ubi:rootfs </mountpoint> -t ubifs
 

The Following 4 Users Say Thank You to pali For This Useful Post:
Posts: 2,154 | Thanked: 8,464 times | Joined on May 2010
#13
So correct way how to mount N900 rootfs on computer using nandsim is:
(this will use ubiformat instead mtdblock and dd as in #3rd post)

1. Load nandsim module (which emulate nand mtd device) with same layout as has N900:
Code:
$ modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa third_id_byte=0x00 fourth_id_byte=0x15 parts=1,3,2,16,16,2010
2. Load ubi and ubifs modules:
Code:
$ modprobe ubi
$ modprobe ubifs
3. Flash rootfs ubi image to emulated nand mtd device:
Code:
$ ubiformat /dev/mtd5 -s 512 -O 512 -f <rootfs_image>
4. Attach mtd device to ubi:
Code:
$ ubiattach /dev/ubi_ctrl -p /dev/mtd5
5. Mount rootfs volume (ubifs image) from ubi to /mnt/n900:
Code:
$ mkdir -p /mnt/n900
$ mount ubi:rootfs /mnt/n900 -t ubifs
And then rootfs image should be mounted to /mnt/n900

Umounting & cleaning:
Code:
$ umount /mnt/n900
$ ubidetach /dev/ubi_ctrl -d 0
$ rmmod ubifs
$ rmmod ubi
$ rmmod nandsim
 

The Following 6 Users Say Thank You to pali For This Useful Post:
Posts: 2,154 | Thanked: 8,464 times | Joined on May 2010
#14
Original Maemo 5 rootfs UBI image was generated with 1870 UBI LEBs for rootfs UBIFS volume, which correspond to 230MiB (=1870*126KiB). Therefore correction for #3rd post of cfg.ini:

Code:
[rootfs]
mode=ubi
image=rootfs_ubifs.jffs2
vol_id=0
vol_size=230MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
vol_alignment=1

Last edited by pali; 2022-06-26 at 21:48. Reason: vol_size is in UBI LEBs (not PEBs)
 

The Following 5 Users Say Thank You to pali For This Useful Post:
Posts: 1,424 | Thanked: 2,623 times | Joined on Jan 2011 @ Touring
#15
Oh $#!T it's Pali!!! OY! it has been a long time!
(edit)since 2019!!
 

The Following 4 Users Say Thank You to biketool For This Useful Post:
peterleinchen's Avatar
Posts: 4,118 | Thanked: 8,901 times | Joined on Aug 2010 @ Ruhrgebiet, Germany
#16
Oh yeah!
__________________
SIM-Switcher, automated SIM switching with a Double (Dual) SIM adapter
--
Thank you all for voting me into the Community Council 2014-2016!

Please consider your membership / supporting Maemo e.V. and help to spread this by following/copying this link to your TMO signature:
[MC eV] Maemo Community eV membership application, http://talk.maemo.org/showthread.php?t=94257

editsignature, http://talk.maemo.org/profile.php?do=editsignature
 

The Following 2 Users Say Thank You to peterleinchen For This Useful Post:
Posts: 2,154 | Thanked: 8,464 times | Joined on May 2010
#17
I think it can be useful also for others with other devices, so here is guide how to properly generate UBI image with UBIFS volume for any MTD device. Both mkfs.ubifs and ubinize tools needs to know geometry of target MTD device (e.g. NAND) during creating of images. The best way how to detect all required parameters is to install mtdinfo utility on target system and run it with -u option for target MTD device. Also optimal value of $MAX_LEB_CNT depends on kernel config option CONFIG_MTD_UBI_BEB_LIMIT.

Here are all commands how to determinate and calculate all required parameters for target MTD device /dev/mtd0:

PEB_SIZE <-- mtdinfo /dev/mtd0 -u | sed -n 's/^Eraseblock size: *\([^ ]*\).*/\1/p'
LEB_SIZE <-- mtdinfo /dev/mtd0 -u | sed -n 's/^Default UBI LEB size: *\([^ ]*\).*/\1/p'
MIN_IO_SIZE <-- mtdinfo /dev/mtd0 -u | sed -n 's/^Minimum input\/output unit size: *\([^ ]*\).*/\1/p'
SUB_PAGE_SIZE <-- mtdinfo /dev/mtd0 -u | sed -n 's/^Sub-page size: *\([^ ]*\).*/\1/p'
EB_CNT <-- mtdinfo /dev/mtd0 -u | sed -n 's/^Amount of eraseblocks: *\([^ ]*\).*/\1/p'
BEB_LIMIT <-- gunzip -c /proc/config.gz | sed -n 's/^CONFIG_MTD_UBI_BEB_LIMIT=//p'
BEB_CNT <-- $BEB_LIMIT * $EB_CNT / 1000
MAX_LEB_CNT <-- (($EB_CNT * $PEB_SIZE) - (($BEB_CNT + 4) * $PEB_SIZE + ($PEB_SIZE - $LEB_SIZE) * ($EB_CNT - $BEB_CNT - 4))) / $LEB_SIZE
VOL_SIZE <-- Size of the generated UBIFS image file ubifs.img (minimal value)
VOL_NAME <-- Name of UBI volume for UBIFS image (e.g. "rootfs")


Calculation of $MAX_LEB_CNT is done according to official information in UBI documentation at:
http://www.linux-mtd.infradead.org/d...tml#L_overhead
Maximal number (but not larger than $MAX_LEB_CNT) for currenly attached UBI volume can be read from file:
/sys/class/ubi/ubi0_0/reserved_ebs. So it can be used for verification that $MAX_LEB_CNT was calculated optimally. Note that bad blocks on device cause lower value.

UBI image ubi.img with UBIFS volume with content of $ROOT_DIR can be generated via following commands:

Code:
/usr/sbin/mkfs.ubifs -m $MIN_IO_SIZE -e $LEB_SIZE -c $MAX_LEB_CNT -r $ROOT_DIR ubifs.img

cat > cfg.ini << EOF
[$VOL_NAME]
mode=ubi
image=ubifs.img
vol_id=0
vol_size=$VOL_SIZE
vol_type=dynamic
vol_name=$VOL_NAME
vol_flags=autoresize
vol_alignment=1
EOF

/usr/sbin/ubinize -o ubi.img -p $PEB_SIZE -m $MIN_IO_SIZE -s $SUB_PAGE_SIZE cfg.ini
Line vol_size= in cfg.ini can be omitted and ubinize will then calculate size from ubifs.img file.

For /dev/mtd5 partition in Nokia N900 with Maemo 2.6.28 kernel are following optimal/correct values:

PEB_SIZE=131072
LEB_SIZE=129024
MIN_IO_SIZE=2048
SUB_PAGE_SIZE=512
MAX_LEB_CNT=1986


As can be seen in examples, mkfs.ubifs was called by Nokia with -c option MAX_LEB_CNT=2047, but maximal value is just 1986. On my N900, kernel reports in /sys/class/ubi/ubi0_0/reserved_ebs value 1985 which proves that calculation is correct (value is smaller probably due to already bad blocks).
 

The Following 7 Users Say Thank You to pali For This Useful Post:
Maemish's Avatar
Posts: 1,720 | Thanked: 4,765 times | Joined on Apr 2018 @ Helsinki, Finland.
#18
Just awesome you are here and share this info!
__________________
"I don't know how but I can try!" (active)

Master of not knowing (active)

For me it is possible to get lost in any case (active)

Learning to fall from high (DONE)

Learning to code with BASIC (WIP)
 

The Following User Says Thank You to Maemish For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 17:40.