ModifyingRootImage

Modifying Root Image of Nokia 770

This HOWTO describes one method for extending and modifying an existing JFFS2 root image of 770.

Background

Mounting JFFS2 image is little bit tricky and not as straight forward as some examples related to "mounting images with loopback devices" in man page of mount let assume.

Mounting JFFS2 Image

First we initiate mount which will eventually fail. This will still create the /dev/loop1 device that we use for the actual mount.

$ mount -t jffs2 myRootImage.jffs2 /media/jffs2

The following script should be placed in a file, for example mount_jffs2.sh.

#!/bin/sh

if [ ! -b /dev/mtdblock0 ] ; then
        mknod /dev/mtdblock0 b 31 0 || exit 1
fi

JFFSIMG=$1 # jffs image
LOOP="/dev/loop1" # loop device
MP="/media/jffs2" # mount po

losetup $LOOP $JFFSIMG || exit 1
sleep 1
modprobe blkmtd device=$LOOP || exit 1
sleep 1
mount -t jffs2 /dev/mtdblock0 $MP || exit 1

Usage: $ ./mount_jffs2.sh myRootImage.jffs2

Archiving and Extracting the Copy of Root Image

Next step is to copy the whole image to another directory which will be used for modifying the image. Extending the currently mounted JFFS2 image is somewhat impossible. Using cp for copying the image to a working directory won't work due to special files in /media/jffs/dev, for example. This is the reason we use tar.

$ cd $HOME
$ tar cvzf myRootImage.tar.gz /media/jffs2
$ tar xvzf myRootImage.tar.gz

Modifying the Copy of Image

Now the image is successfully archived and copied. The working directory $HOME/media/jffs2 can now be used for adding packages etc, for example.

$ cd $HOME/media/jffs2
$ dpkg -x $HOME/arm_debs/mypackage_arm.deb .

Now we create a new tarball from the working directory of the image.

$ cd $HOME/media/jffs2
$ tar cvzf $HOME/myNewRootImage.tar.gz .

Installing into Nokia 770

When the new tarball is created, refer to HOWTO: Using flasher and the reference root filesystem for creating JFFS2 image from the myNewRootImage.tar.gz. Use flasher to install the image to Nokia 770, as described.

Alternative way to get the image

Comment: The way described above didn't work out on my Debian box. So, here is what worked for me. (by Michael Mlivoncic)

First of all, we need to get the rootfs.jffs2 from the official Nokia binary:

#!plain
$ mkdir SE2005_image
$ cd SE2005_image
$ sudo ./flasher --unpack  -F /path_to_file/Nokia_770_SE2005_3_2005_51_13.bin

Found image 2nd (length 8576)
Found image secondary (length 79360)
Found image xloader (length 13824)
Found image initfs (length 1581824)
Found image kernel (length 1481856)
Found image rootfs (length 58851328)
Unpacking 2nd image to file '2nd.bin'...
Unpacking X-Loader image to file 'xloader.bin'...
Unpacking secondary image to file 'secondary.bin'...
Unpacking kernel image to file 'zImage'...
Unpacking initfs image to file 'initfs.jffs2'...
Unpacking rootfs image to file 'rootfs.jffs2'...

Now, we have to modprobe a few kernel modules, make space for the image, etc.

#!plain
$ sudo modprobe mtdblock
$ sudo modprobe mtdram total_size=65536 erase_size=256
$ sudo modprobe jffs2
$ sudo modprobe loop
$ sudo losetup /dev/loop0 /pathtoimage/rootfs.jffs2
$ sudo dd if=/pathtoimage/rootfs.jffs2 of=/dev/mtdblock0
$ mkdir /mnt/jffs2
$ sudo mount -t jffs2 /dev/mtdblock0 /mnt/jffs2

Probably, you can also ommit the losetup step, but I have to check that. The image is now browseable unter /mnt/jffs2; proceed as above, i.e.:

$ cd /mnt/jffs2
$ sudo tar cvzf /my_path/myRootImage.tar.gz .
[...]

To clean up (other than reboot), run something like

#!plain
$ sudo umount /mnt/jffs2
$ sudo losetup -d /dev/loop0
$ sudo rmmod jffs2
$ sudo rmmod loop
$ sudo rmmod mtdram
$ sudo rmmod mtdblock

After creating your own image, installing tools as describeds above and

./tar2jffs2.sh yyyymmdd-hhmmss-rootfs.tgz

, you can flash the root_fs to the device with something like this:

#!plain
$ sudo ./flasher --flash-only rootfs -F image.bin -f 

$ sudo ./flasher <del>rootfs  SE2005/rootfs.jffs2 </del>flash-only rootfs --flash

$ sudo /scratchbox/flasher <del>enable-rd-mode </del>reboot

The flash-only parameter is used just to make sure ;-)

    • Final remarks --

Tonight, I had to re-flash the first time, as I screwed up a script in /etc/init.d/. For the future, I will try to make a full backup of my productive rootfs, to avoid starting all over again

Maybe one could write a script removing unwanted stuff from that image (sample video, song), changing sudoers, gainroot script, adding sshd, ...

'_Hey, maybe you'll find this link useful: http://maemo.org/maemowiki/HowTo_EASILY_Boot_From_MMC_card _'