ReferencePlatforms/Test/N900-PR1.2

From MozillaWiki
Jump to: navigation, search

Creating an N900 Image

This document assumes that a computer has been set up as specified in this document.

There are three phases in generating an N900 firmware image,

  • extract official image
  • modify files
  • generate new image

We use the linux kernel's nandsim kernel module in concert with its ubi and ubifs support to mount the official nokia firmware that is extracted with the flasher-3.5 utility.

Extract Official Image

Using tool

You can use the extract_rootfs.py tool in the tools repo

sudo ./extract_rootfs.py -F RX-51_2009SE_10.2010.19-1.002_PR_COMBINED_002_ARM.bin -o moz-n900-v1

If you see ERROR: Could not mount filesystem, chances are that rebooting the machine will remedy the situation

Manually

To extract the official image, we need to unpack the FIASCO file into the composite parts.

mkdir parts
cd parts
../flasher-3.5 -F ../RX-51_2009SE_10.2010.19-1.002_PR_COMBINED_002_ARM.bin --unpack
mv rootfs.jffs2 ../rootfs.ubi #it is really a ubi image not a jffs2 fs
cd ..
rm -rf parts

We then mount the rootfs image.

su -
modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa \
                 third_id_byte=0x00 fourth_id_byte=0x15
#/dev/mtd0 should be present, if not run "mknod /dev/mtd0 c 90 0"
dd if=rootfs.ubi of=/dev/mtd0 bs=2048
modprobe ubi mtd=0
mkdir mount
mount -t ubifs /dev/ubi0_0 mount

To make any changes, or to create an image, we need to copy the data from the nandsim device.

mkdir moz-n900-v1
rsync -a mount/. moz-n900-v1/.

Modify Files

First, make a copy of the official firmware image for your work

su -
mkdir n900-v1
rsync -a n900-pr1.2-main/. moz-n900-v1/.

Pineapple

On a computer with FREMANTLE_ARMEL scratchbox THAT IS NOT USING OUR DEPLOYED VERSION OF SCRATCHBOX THAT HAS CHINOOK AND HOST PYTHON run:

/scratchbox/login
sb-conf select FREMANTLE_ARMEL

wget http://ftp.gnu.org/gnu/tar/tar-1.22.tar.gz
wget http://mercurial.selenic.com/release/mercurial-1.4.2.tar.gz
wget http://tmrc.mit.edu/mirror/twisted/Twisted/9.0/Twisted-9.0.0.tar.bz2
wget http://www.zope.org/Products/ZopeInterface/3.3.0/zope.interface-3.3.0.tar.gz
wget http://nginx.org/download/nginx-0.7.65.tar.gz
wget http://projects.o-hand.com/sources/xrestop/xrestop-0.4.tar.gz
wget http://ftp.gnu.org/non-gnu/cvs/source/stable/1.11.23/cvs-1.11.23.tar.bz2 
wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2.6p1.tar.gz
wget http://downloads.sourceforge.net/project/buildbot/buildbot/0.8.1p1/buildbot-slave-0.8.1p1.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fbuildbot%2Ffiles%2F&ts=1286470918&use_mirror=cdnetworks-us-2
#wget http://cdnetworks-us-2.dl.sourceforge.net/project/buildbot/buildbot/0.8.1p1/buildbot-slave-0.8.1p1.tar.gz
wget http://pyyaml.org/download/pyyaml/PyYAML-3.09.tar.gz
wget http://samba.anu.edu.au/ftp/rsync/src/rsync-3.0.7.tar.gz
wget http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
wget http://ftp.gnu.org/gnu/wget/wget-1.12.tar.bz2
wget http://downloads.sourceforge.net/project/infozip/Zip%203.x%20%28latest%29/3.0/zip30.tar.gz
wget http://downloads.sourceforge.net/project/infozip/UnZip%206.x%20%28latest%29/UnZip%206.0/unzip60.tar.gz
wget http://matt.ucc.asn.au/dropbear/releases/dropbear-0.52.tar.gz
wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-5.5p1.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.02.tar.gz
wget http://www.python.org/ftp/python/2.6.5/Python-2.6.5.tar.bz2
wget http://downloads.sourceforge.net/project/pcre/pcre/8.02/pcre-8.02.tar.gz

find -name "*.tar.gz" -exec tar zxf '{}' \;
find -name "*.tar.bz2" -exec tar jxf '{}' \;

mkdir build
cd build
export ROOTDIR=$(pwd)/buildroot
export PREFIX=/usr

#tar
cd tar-1.22
./configure --prefix=$PREFIX
make -j4
make install DESTDIR=$ROOTDIR
cd ..

#bzip2
cd bzip2-1.0.5
make
make install PREFIX="$ROOTDIR$PREFIX"
cd ..

#Nginx
cd nginx-0.7.65
./configure --without-http-cache --prefix=$PREFIX/nginx --with-pcre=../pcre-8.02
make -j4
make install DESTDIR=$ROOTDIR
cd ..

#xrestop
cd xrestop-0.4
./configure --prefix=$PREFIX
make -j4
make install DESTDIR=$ROOTDIR
cp /usr/lib/libXRes.so* $ROOTDIR/usr/lib #libXRes not in apt for device
cd ..

#cvs
cd cvs-1.11.23
./configure --prefix=$PREFIX
make -j4
make install DESTDIR=$ROOTDIR
cd ..

#ntp
cd ntp-4.2.6p1
./configure --prefix=$PREFIX
cd ntpdate
make -j4
make install DESTDIR=$ROOTDIR
cd ..

#dropbear
cd dropbear-0.5.2
./configure --prefix=$PREFIX
make -j4
fakeroot make install DESTDIR=$ROOTDIR
cd ..

#openssh
cd openssh-5.5p1
./configure --prefix=$PREFIX
make ssh
make ssh-keygen
make scp
cp ssh scp ssh-keygen $ROOTDIR$PREFIX/bin

#rsync
cd rsync-3.0.7
./configure --prefix=$PREFIX
make -j4
make install DESTDIR=$ROOTDIR
cd ..

#wget
cd wget-1.12
./configure --prefix=$PREFIX
make -j4
make install DESTDIR=$ROOTDIR
cd ..

#zip
cd zip30
make -f unix/Makefile generic IZ_BZIP2=no_such_directory
cp zip $ROOTDIR$PREFIX/bin/
cd ..

#unzip
cd unzip60
make -f unix/Makefile generic
cp unzip $ROOTDIR$PREFIX/bin
cd ..

#python
cd Python-2.6.5
sed -i -e 's|--root=/|--root=|' Makefile.pre.in
./configure --prefix=$PREFIX
make -j4
make install DESTDIR=$ROOTDIR

#SET UP PYTHON
export PY=$ROOTDIR/$PREFIX/bin/python2.6

#hg
cd mercurial-1.4.2
$PY setup.py install --root=$ROOTDIR --prefix=$PREFIX
cd ..

#Twisted
cd Twisted-9.0.0
$PY setup.py install --root=$ROOTDIR --prefix=$PREFIX
cd ..

#Zope Interfaces
cd zope.interface-3.3.0
$PY setup.py install --root=$ROOTDIR --prefix=$PREFIX
cd ..

#buildbot
cd buildbot-slave-0.8.1p1
$PY setup.py install --root=$ROOTDIR --prefix=$PREFIX
cd $ROOTDIR/$PREFIX/bin
cp buildslave buildbot
cd ..

#PyYAML
cd PyYAML-3.09
$PY setup.py --without-libyaml install --root=$ROOTDIR --prefix=$PREFIX
cd ..

#I made a backup before i started to shrink things
cd $ROOTDIR
cp -r usr usr-backup

#Cleanup some things we do not need
cd $ROOTDIR$PREFIX
find lib/python2.6 -type d -name "test*" -exec rm -rf \;
rm share/info/*
rm share/man/*
rm share/cvs/*
rm -r share/locale/*

find -type f -exec strip --strip-unneeded --strip-debug {} \;

#for me, this reduced the usr directory from 132mb to 70mb.  It is critical for the software to fit on the device that the size is significantly reduced.

#Next, fix the #! line for python scripts
cd $ROOTDIR$PREFIX/bin
find -exec grep -l "$ROOTDIR" {} \; | xargs sed -i -e "s|$ROOTDIR||"

cd $ROOTDIR
mkdir -p etc/dropbear
./usr/bin/dropbearkey -t rsa -f etc/dropbear/dropbear_rsa_host_key
./usr/bin/dropbearkey -t dss -f etc/dropbear/dropbear_dss_host_key

Install applications

get the build files onto the same computer as the image preparation is to occur and run

rsync -a buildroot/. moz-n900-v1/.

Modify system files

make user and root able to do sudo

sudo gainroot
EDITOR=vi visudo

The top of the file should look like:

### Automatically added by update-sudoers start ###
Defaults env_check+="HOME DISPLAY"
Defaults env_keep+="HOME DISPLAY"
Defaults env_reset
user ALL = NOPASSWD: ALL               
root ALL = NOPASSWD: ALL
user ALL = NOPASSWD: /usr/sbin/gainroot
user ALL = NOPASSWD: /usr/sbin/mmc-mount /dev/mmcblk0 /media/mmc1
user ALL = NOPASSWD: /usr/sbin/mmc-mount /dev/mmcblk0p1 /media/mmc1
...

Modify the power config

cat > /etc/pmconfig <<EOF
enable_off_mode 0
sleep_while_idle 0
sr_vdd1_autocomp 0
sr_vdd2_autocomp 0
clocks_off_while_idle 0
voltage_off_while_idle 0
scaling_governor ondemand
scaling_max_freq 550000
scaling_min_freq 550000
sleep_ind 1
EOF

Generate a public/private key for the device

cd moz-n900-v1/root/
sudo mkdir .ssh
cd .ssh
sudo dropbearkey -t dss -f n900 -y | grep "^ssh" | sudo tee n900.pub authorized_keys
sudo chown root:root *
#if dropbearkey isn't on the host system, aptitude install dropbear
dropbearkey

Generate New Image

Using tool

sudo ./generate_image.py -r moz-n900-v1 -o moz-n900-v1

Manually

To be able to flash this filesystem onto a device you will need to generate an image. The images for the N900s are in the UBI format. In order to generate a UBI image, you must first generate a UBIFS image.

First, generate the UBIFS file system

su -
./mkfs.ubifs -m 2048 -e 129024 -c 2047 -r moz-n900-v1 moz-n900-v1.ubifs

Then 'ubinize' this ubifs file

cat > ubi.cfg <<EOF
[rootfs]
mode=ubi
image=moz-n900-v1.ubifs
vol_id=0
vol_size=200MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
vol_alignment=1
EOF
./ubinize -o moz-n900-v1.ubi -p 128KiB -m 2048 -s 512 ubi.cfg

Flashing image

The recommended process for flashing your custom firmware image is

su -
./flasher-3.5 -F RX-51_2009SE_10.2010.19-1.002_PR_COMBINED_002_ARM.bin -f
./flasher-3.5 --rootfs moz-n900-v1.ubi -f
./flasher-3.5 -F RX-51_2009SE_10.2010.13-2.VANILLA_PR_EMMC_MR0_ARM.bin -f

References