maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Editing n900's rootfs.jffs2 (https://talk.maemo.org/showthread.php?t=35554)

x86 2009-12-01 12:52

Editing n900 rootfs image
 
How to mount or edit rootfs.jffs2 file?
Already tried via nandsim and mtdram - no luck. I can't mount ubifs filesystem. Wiki entry have only information about jffs2 and not ubifs.

fanoush 2009-12-01 13:15

Re: Editing n900's rootfs.jffs2
 
Well in theory you need recent kernel that supports ubifs and recent mtd-utils and follow stuff here
http://www.linux-mtd.infradead.org/d...tml#L_usptools
http://www.linux-mtd.infradead.org/doc/ubifs.html

I was trying to mount it too but didn't manage yet. Was also thinking that easier might be to simply flash it to NAND in my beagleboard and mount it there. But there shouldn't be problem with mtdram, just create mtdram device, use ubi tools to create/attach ubi volume and 'flash' image to it.

x86 2009-12-01 16:14

Re: Editing n900's rootfs.jffs2
 
Here one solution to mount it:
Code:

# modprobe mtdblock

# modprobe ubi

# modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa third_id_byte=0x00 fourth_id_byte=0x15

# cat /proc/mtd
dev:    size  erasesize  name
mtd0: 10000000 00020000 "NAND simulator partition 0"

# ls -la /dev/mtd*
brw-r--r-- 1 root root 31, 0 2009-12-01 18:50 /dev/mtd0
brw-rw---- 1 root disk 31, 0 2009-12-01 19:06 /dev/mtdblock0

# dd if=rootfs.jffs2 of=/dev/mtdblock0 bs=2048
74688+0 records in
74688+0 records out
152961024 bytes (153 MB) copied, 5.87334 s, 26.0 MB/s

# ubiattach /dev/ubi_ctrl -m 0
UBI device number 0, total 2048 LEBs (264241152 bytes, 252.0 MiB), available 0 LEBs (0 bytes), LEB size 129024 bytes (126.0 KiB)

# ls -la /dev/ubi*
crw-rw---- 1 root root 252,  0 2009-12-01 19:06 /dev/ubi0
crw-rw---- 1 root root 252,  1 2009-12-01 19:06 /dev/ubi0_0
crw-rw---- 1 root root  10, 58 2009-12-01 19:05 /dev/ubi_ctrl
# mount -t ubifs ubi0_0 /mnt/n900/

# ls -la /mnt/n900 | head
total 4
drwxr-xr-x 22 root root 1504 2009-10-30 14:36 .
drwxr-xr-x  9 root root 4096 2009-10-25 20:02 ..
drwxr-xr-x  2 root root 3920 2009-10-30 14:31 bin
drwxr-xr-x  2 root root  232 2009-10-30 14:48 boot
drwxr-xr-x  2 root root  160 2009-10-30 14:28 cdrom
drwxr-xr-x  3 root root 3808 2009-10-30 14:37 dev
drwxr-xr-x  2 root root  160 2009-10-30 14:28 .dev
drwxr-xr-x 72 root root 7488 2009-10-30 14:48 etc
drwxr-xr-x  2 root root  160 2009-10-30 14:28 floppy

#

To pack back into ubifs do following:
Code:

# mkfs.ubifs -m 2048 -e 129024 -c 2047 -r /mnt/n900/ rootfs_ubifs.jffs2

# cat > cfg.ini
[rootfs]
mode=ubi
image=rootfs_ubifs.jffs2
vol_id=0
vol_size=160MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
vol_alignment=1

# ubinize -o rootfs_new.jffs2 -p 128KiB -m 2048 -s 512 cfg.ini

# ./flasher-3.5 -f -R -r rootfs_new.jffs2

Doing this please be careful, it was working for me, but you must check all parameters according with dmesg after mounting volume. Untested with image bigger than original.
Somebody please test this and add to wiki.

techdork 2009-12-27 16:41

Re: Editing n900's rootfs.jffs2
 
Quote:

Doing this please be careful, it was working for me, but you must check all parameters according with dmesg after mounting volume. Untested with image bigger than original.
Somebody please test this and add to wiki.
This doesn't work for me, using the SDK VM.

Can anyone confirm the true filesystem type of the rootfs.jffs2 file, and possibly a working How To for mounting the image?

mad_soft 2010-10-09 15:55

Re: Editing n900's rootfs.jffs2
 
Quote:

Originally Posted by x86 (Post 403015)
Here one solution to mount it:

I have suse 11.3 with kernel 2.6.34.7-0.3-desktop
i can't mount rootfs.jffs2
all commands works perfectly excepts when i run
Code:

modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa third_id_byte=0x00 fourth_id_byte=0x15
the output is
[code]
crw------- 1 root root 90, 0 Oct 9 17:34 /dev/mtd0
crw------- 1 root root 90, 1 Oct 9 17:34 /dev/mtd0ro
brw-rw---- 1 root disk 31, 0 Oct 9 17:34 /dev/mtdblock0
[code]
Then i run
Code:

ubiattach /dev/ubi_ctrl -m 0
I get an error
Code:

ubiattach: error!: cannot attach mtd0
          error 30 (Read-only file system)

And of course, can't mount it

kaos_king 2010-11-03 12:10

Re: Editing n900's rootfs.jffs2
 
What is your result to:

Code:

cat /proc/mtd
?

I suspect your mtd0 is taken

mad_soft 2011-01-25 15:30

Re: Editing n900's rootfs.jffs2
 
cat /proc/mtd
Code:

dev:    size  erasesize  name
mtd0: 10000000 00020000 "NAND simulator partition 0"


stevomanu 2011-02-04 21:18

Re: Editing n900's rootfs.jffs2
 
when using this command
Code:

dd if=rootfs.jffs2 of=/dev/mtdblock0 bs=2048
this is what i get in reply

Code:

dd if=rootfs.jffs2 of=/dev/mtdblock0 bs=2048
dd: opening `rootfs.jffs2': No such file or directory


many thanks ]

mad_soft 2011-02-15 17:49

Re: Editing n900's rootfs.jffs2
 
put the full path to rootfs.jffs2

The above instructions only work for me on ubuntu 10.04 32bit.
In openSUSE don't work

MohammadAG 2011-02-15 17:52

Re: Editing n900's rootfs.jffs2
 
Technically, they should work on all OSs assuming there's MTD block support in the kernel (afaik ubuntu got that in 10.04)

joerg_rw 2011-07-30 01:51

Re: Editing n900's rootfs.jffs2
 
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

pali 2013-02-25 13:39

Re: Editing n900's rootfs.jffs2
 
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

pali 2013-02-25 13:40

Re: Editing n900's rootfs.jffs2
 
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


pali 2022-06-12 16:38

Re: Editing n900's rootfs.jffs2
 
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


biketool 2022-06-12 17:48

Re: Editing n900's rootfs.jffs2
 
Oh $#!T it's Pali!!! OY! it has been a long time!
(edit)since 2019!!

peterleinchen 2022-06-12 21:33

Re: Editing n900's rootfs.jffs2
 
Oh yeah! :)

pali 2022-07-03 01:09

Re: Editing n900's rootfs.jffs2
 
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).

Maemish 2022-07-03 14:12

Re: Editing n900's rootfs.jffs2
 
Just awesome you are here and share this info!


All times are GMT. The time now is 01:12.

vBulletin® Version 3.8.8