Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
719 lines (494 sloc) 23.7 KB
Debian rootfs
Step 0 - QEMU image for creating rootfs
* I used to create images straight on the device, but i dont do it anymore.
* Easiest way to create tarbal and NAND images is in qemu. You can download my
preinstalled qemu image from:
* Unpack the tarball, install qemu and run ./
* After the system is started you can use redirected port to ssh there:
ssh -p 22222 root@localhost
please note that the root password is empty.
* The system is very minimal, download more packages:
apt-get update
apt-get install cdebootstrap mtd-utils
Step 1
* We will be installing new image to /media/card:
cdebootstrap --flavour=minimal --include=ifupdown,net-tools,procps,netbase,nano,module-init-tools,wget,openssh-server,screen,mc,libts-0.0-0,libasound2,alsa-utils,udhcpc,wpasupplicant,wireless-tools,iputils-ping,iproute,bluez,bluez-alsa,dosfstools,fbset,rsyslog,psmisc,iptables,dash,ttf-dejavu,libpng12-0,libjpeg8,libxtst6,sqlite3,ntpdate,gstreamer0.10-ffmpeg,gstreamer0.10-plugins-good,gstreamer0.10-fluendo-mp3,liblcms1,libmng1,libtiff4,libvorbisfile3,libicu48,gpsd,gpsd-clients,rfkill,libspeex1,libspeexdsp1,lsof,gstreamer0.10-pulseaudio,pulseaudio,pulseaudio-utils,libasound2-plugins,libpulse-mainloop-glib0 wheezy /media/card/
Step 2
* Complete installation. Copy paste below in shell:
mkdir /media/card/mnt/nfs
mkdir /media/card/mnt/p1
mkdir /media/card/mnt/p2
mkdir /media/card/mnt/p3
mkdir /media/card/mnt/p5
mkdir /media/card/mnt/p6
mkdir /media/card/mnt/p7
mkdir /media/card/media/card
mkdir /media/card/media/p1
echo "neo" > /media/card/etc/hostname
echo " neo" >> /media/card/etc/hosts
cat > /media/card/etc/network/interfaces <<__END__
auto lo
iface lo inet loopback
auto usb0
iface usb0 inet static
up rm /etc/resolv.conf
up echo nameserver >/etc/resolv.conf
cat > /media/card/etc/fstab << __END__
rootfs / auto defaults,errors=remount-ro,noatime 0 1
/dev/mmcblk0p1 /media/p1 auto defaults 0 0
/dev/mmcblk0p5 /media/card auto defaults 0 0
proc /proc proc defaults 0 0
#tmpfs /var/cache/apt tmpfs defaults,noatime 0 0 /mnt/nfs nfs noauto,nolock,soft,rsize=32768,wsize=32768 0 0
cat > /media/card/etc/apt/apt.conf.d/99no-install-recommends << __END__
APT::Install-Recommends "0";
sed -i 's/\(PermitEmptyPasswords\) no/\1 yes/' /media/card/etc/ssh/sshd_config
chroot /media/card /bin/sh -e <<__END_CHROOT__
echo root: root | chpasswd
sed -i 's/root:.*/root:C0XOiCyzQDtsA:14973:0:99999:7:::/' /etc/shadow
apt-get --yes --purge remove cdebootstrap-helper-rc.d
Step 3 - add more package repositories
echo "deb wheezy contrib" >> /media/card/etc/apt/sources.list
echo "deb wheezy non-free" >> /media/card/etc/apt/sources.list
echo "deb wheezy/updates main contrib non-free" >> /media/card/etc/apt/sources.list
echo "deb /" >> /media/card/etc/apt/sources.list
echo "deb /" >> /media/card/etc/apt/sources.list
echo "deb /" >> /media/card/etc/apt/sources.list
Step 4
* Device drivers modules. Most of device drivers are built in kernel, but
following drivers are exception: g_ether is module so that we can switch
between mass storage, ppp_generic is not needed for people not using GPRS,
joydev is used in qtmaze for accelerometers, hso is for UMTS.
echo g_ether > /media/card/etc/modules
echo joydev >> /media/card/etc/modules
echo hso >> /media/card/etc/modules
echo ledtrig-timer >> /media/card/etc/modules
echo bmp085 >> /media/card/etc/modules
* Make the MAC address of g_ether fixed instead of random, so that network
manager can be configured:
echo "options g_ether host_addr=46:0d:9e:67:69:eb dev_addr=b6:c8:ab:ac:44:7f" >> /media/card/etc/modprobe.d/options
* Configure bluez4 for handsfreee calls, otherwise there is no sounds:
nano /media/card/etc/bluetooth/audio.conf
and uncomment SCORouting=PCM setting in [General]:
* Remove alsa-utils init scripts - we dont need them, we set correct alsa
state ourselves when qtmoko starts up:
chroot /media/card
update-rc.d -f alsa-utils remove
Step 4.1 - stable device nodes for UMTS
* Modem device is by default on /dev/ttyHS3, but it can rename after modem
disconnect. For details see:
We will use udev to create stable symlinks for us:
cd /media/card/etc/udev/rules.d
Step 4.2 - charging udev rules
* For more info see:
cat > /media/card/etc/udev/rules.d/gta04-charging.rules <<__END__
SUBSYSTEM=="power_supply", ACTION=="change", DEVPATH=="*power_supply/twl4030_usb" ATTRS{1-0048/twl4030_usb/id}=="floating", ATTR{../../max_current}="500000"
SUBSYSTEM=="power_supply", ACTION=="change", DEVPATH=="*power_supply/twl4030_usb" ATTRS{1-0048/twl4030_usb/id}=="102k", ATTR{../../max_current}="851000"
Step 4.5 - make it generate SSH keys on start
* SSH server keys are automatically generated during debootstrap. This can be
security problem if user does not regenerate them. So we delete old keys and
generate new ones during first boot.
rm /media/card/etc/ssh/ssh_host_*
cat > /media/card/etc/init.d/sshkeysfirstboot << __END__
# Provides: sshkeysfirstboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Generate SSH host keys on first boot
dpkg-reconfigure openssh-server
update-rc.d -f sshkeysfirstboot remove
rm -f /etc/init.d/sshkeysfirstboot
chmod +x /media/card/etc/init.d/sshkeysfirstboot
chroot /media/card
update-rc.d sshkeysfirstboot defaults
Step 4.6 - get rid of getty in inittab
* TTY's are for logging to console which is useful only if you have USB
keyboard. So tty respawning is in done in script and we can
comment it out from /etc/inittab:
nano /media/card/etc/inittab
and comment all lines with "respawn:/sbin/getty 38400 ttyX"
Step 4.7 - disable logging by defaults
* We will have syslogd and klogd disabled by default. If phone works it's not
needed and it saves flash memory from wearing off. It can be always enabled
in settings->logging or via devtools menu or with script.
chroot /media/card
update-rc.d -f rsyslog remove
Step 5
* Set locale to get rid of apt-get warnings
echo "LANG=C" > /media/card/etc/default/locale
echo "LC_ALL=C" >> /media/card/etc/default/locale
* Fix incompatible libts version
cd /media/card/usr/lib
ln -s
* Remove .udev dir, that confuses udev. This dir is here after instalation and
causes some error/warnings during init. Not sure what's the exact problem.
cd /media/card/dev
rm -rf .udev
* Remove /etc/network/run and do make dir /etc/network/run
Otherwise fstab mounting will fail for this directory
rm /media/card/etc/network/run
mkdir /media/card/etc/network/run
Step 6.5 - configure gpsd
* We use gpsd and it has to be configured for Freerunner:
nano /media/card/etc/default/gpsd
* Make sure you have these values:
Step 7.5 - dash
* For faster boot (~15s) and more memory (+1MB) we use dash instead of bash.
cd /media/card/bin/
rm sh
ln -s dash sh
Step 7.6 - libertas firmware
* Wifi needs sd8686.bin and sd8686_helper.bin in /lib/firmware:
chroot /media/card
dpkg -i libertas-firmware_9.70.7.p0.0-1_all.deb
rm libertas-firmware_9.70.7.p0.0-1_all.deb
cd /lib/firmware
mv sd8686.bin 1
mv sd8686_helper.bin 2
rm -f *.bin
mv 1 sd8686.bin
mv 2 sd8686_helper.bin
Step 8 - install QtMoko
* I use qemu armhf host for building qtmoko package. It should be as simple as
git checkout v55
* Note that you may need to install some dependencies before building:
apt-get install libX11-dev libXext-dev libXtst-dev libasound2-dev libdbus-1-dev libts-dev libbluetooth-dev
...and checkout git submodules as it's necessary to place qt sources into qtmoko/qtopiacore/qt/:
git submodule update --init
* Please note that releases are made from translations branch so that we have
all languages.
* Now upload the package to sourceforge. In filezilla connect to sourceforge
sftp and upload it to /home/project-web/qtmoko/htdocs/debian/gta04
* Install it
chroot /media/card/
dpkg -i qtmoko-gta04_55-1_armhf.deb
update-rc.d qtmoko-gta04 defaults
rm qtmoko-gta04_55-1_armhf.deb
killall # recent versions start qtmoko after install, so kill it
killall # kill pulseaudio - in qemu it just eats cpu
rm -rf /media/card/home/root/* # remove all stuff created by qpe
Step 8.1 - install mokofaen theme
* Mokofaen is now default theme for qtmoko - but it's not part of qtmoko deb
package, so that user can uninstall it to save space. So install mokofaen:
chroot /media/card/
dpkg -i qtmoko-theme-mokofaen_3-2_all.deb
rm qtmoko-theme-mokofaen_3-2_all.deb
Step 8.2 - some more alarm and ringtones
mkdir -p /media/card/home/root/Documents
cd /media/card/home/root/Documents
Step 9 - Linux kernel
* Sources for qtmoko are on github:
* Checkout branch for your qtmoko version:
git checkout v3.7-gta04-qtmoko-v55
* Create package in buildhost:
cd linux-2.6
* You should remove .git while building the package so that the tar with
sources is not that big. Upload the package to sourceforge.
* Install kernel image:
chroot /media/card
dpkg -i linux-image-3.7-qtmoko-gta04_55-1_armhf.deb
rm linux-image-3.7-qtmoko-gta04_55-1_armhf.deb
* Install bootargs.scr so for correct kernel cmdline arguments:
cd /media/card/boot
Step 9.1 - Linux kernel cross compiling - not using anymore for releases
* If you want to cross compile kernel and make uboot image on PC:
make CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- ARCH=arm gta04_qtmoko_defconfig
make -j8 CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- ARCH=arm uImage
make -j8 CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- ARCH=arm modules
make CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- ARCH=arm modules_install INSTALL_MOD_PATH=GTA04
find GTA04/lib/modules -name *.ko -exec /usr/bin/arm-linux-gnueabihf-strip -R .not -R .comment --strip-unneeded {} \;
Step 9.2 - Setup bluetooth uarts
* Bluetooth is on /dev/ttyO0 serial port and we need to run hciattach to have
bluetooth working. For more info see
echo "-s 3000000 /dev/ttyO0 any 3000000" > /media/card/etc/bluetooth/uart
Step 9.4 - Set pulseaudio as default source/sink for gstreamer
chroot /media/card
. /opt/qtmoko/qpe.env
gconftool-2 -t string --set /system/gstreamer/0.10/default/audiosink pulsesink
gconftool-2 -t string --set /system/gstreamer/0.10/default/audiosrc pulsesrc
Step 9.4.1 - config pulseaudio
* Use speex-fixed-3 for resampling (
* Disable udev autodetection, because it's for some reason broken on GTA04:
cd /media/card/etc/pulse
wget -O daemon.conf
wget -O
Step 9.5 - import QtMoko debian repository public keys
* We use secure apt and we need keys for QtMoko repositories:
cd /media/card
chroot /media/card
apt-key add /qtmoko-pubring.gpg
rm qtmoko-pubring.gpg
Step 9.5.1 - remove bash history
* Remove .bash_history created during install
rm -f /media/card/root/.bash_history
Step 9.6 - setup default DNS
* So that internet works on neo, DNS used during installation is not working
e.g. when installing from qemu:
cat > /media/card/etc/resolv.conf <<__END__
Step 9.7 - boot logo
* gta04-init displays this logo on boot:
cd /media/card/boot
wget -O logo.bmp
Step 9.8 - directory for multiboot
* QtMoko can use gta04-init to boot other distibutions in /distros
subdirectory. Create this dir and write instructions how to use it:
mkdir /media/card/distros
cat > /media/card/distros/README <<__END__
This directory can contain other distributions and you can boot to them. Simply
create subdirectory here and unpack distribution tarball here. E.g:
mkdir SHR
cd SHR
tar xzvpf /path/to/shr-rootfs.tar.gz
You need first SD partition to be FAT and enable initramfs multiboot system:
mkdir /media/p1/gta04-init
Now press POWER, select the distribution from combo box and press "Restart Device"
Step 9.9 - enable ssh access just on usb
* SSH root access can be dangerous on wifi or on GPRS, so enable it only on usb0
echo "# Enable ssh access just on usb" >> /media/card/etc/rc.local
echo "ip6tables -A INPUT ! -i usb0 -p tcp --dport 22 -j REJECT --reject-with tcp-reset; iptables -A INPUT ! -i usb0 -p tcp --dport 22 -j REJECT --reject-with tcp-reset" >> /media/card/etc/rc.local
* Manually edit /media/card/etc/rc.local and move "exit" 0 to the end of file:
nano /media/card/etc/rc.local
Step 10 - release tarball
cd /media/card
tar -czvf ../qtmoko-debian-gta04-v55-armhf.tar.gz .
Step 11 - make ubifs image
* Download logo for NAND boot:
cd /media/card/boot/
rm -f logo.bmp
wget -O logo.bmp
* Remove doc and stuff that is not needed and makes NAND image slower:
find /media/card/usr/share/locale/ -type f -exec rm -f '{}' \;
find /media/card/usr/share/doc/ -type f -exec rm -f '{}' \;
find /media/card/usr/share/doc-base/ -type f -exec rm -f '{}' \;
find /media/card/usr/share/info/ -type f -exec rm -f '{}' \;
find /media/card/usr/share/man/ -type f -exec rm -f '{}' \;
rm -rf /media/card/usr/share/sounds/alsa/*
rm -rf /media/card/usr/share/ssh/blacklist*
* We need just 3 fonts
cd /media/card/usr/share/fonts/truetype/ttf-dejavu/
mv DejaVuSansCondensed-Bold.ttf 1
mv DejaVuSansCondensed.ttf 2
mv DejaVuSansMono.ttf 3
rm *.ttf
mv 1 DejaVuSansCondensed-Bold.ttf
mv 2 DejaVuSansCondensed.ttf
mv 3 DejaVuSansMono.ttf
* Edit the mount for root in /media/card/etc/fstab so that it reads:
rootfs / auto defaults,no_chk_data_crc,bulk_read 0 1
* Create config for ubinize and create the resulting image:
cd /media
cat > ubinize.cfg <<__END__
mkfs.ubifs -r /media/card -m 2048 -e 129024 -c 4007 -o ubifs.img
ubinize -o qtmoko-debian-gta04-v55.ubi -m 2048 -p 128KiB -s 512 ubinize.cfg
rm ubifs.img
* To install it on the device you need to boot from SD and:
ubiformat /dev/mtd4 -f /qtmoko-debian-gta04-v55.ubi
* To check that it's mountable:
ubiattach /dev/ubi_ctrl -m 4
mount -t ubifs ubi0:rootfs /mnt/ubifs/
Step 12 - jffs2 - not using anymore
* Same first 2 steps as with ubi (copy&delete /boot)
* Create jffs2 image:
cd /media
mkfs.jffs2 -o qtmoko-debian-gta04-nosum-v55.jffs2 -e 0x20000 -n -d/media/card
sumtool -n -e 0x20000 -p -i qtmoko-debian-gta04-nosum-v55.jffs2 -o qtmoko-debian-gta04-v55.jffs2
* Create tarbal for NAND:
tar -czvf ../qtmoko-debian-nand.tar.gz .
* You will need bootloader script with bootmenu, you can find it under
devices/gta04/boot. The script is generated with:
mkimage -A arm -O linux -a 0 -e 0 -T script -C none -n "GTA04 Boot Script" -d boot.scr
* You will need uImage with cmdline compiled with root on NAND, so replace the
part with root on /dev/mmcblk02 with root=/dev/mtdblock4 rootfstype=jffs2 rw
in kernel config and make new kernel package. You also have to enable JFFS2
* Boot GTA04 from SD card
* Write kernel to NAND (based on instructions from
flash_eraseall /dev/mtd3
nandwrite -p /dev/mtd3 uImage # uImage is the one with root=/dev/mtdblock4
* Write rootfs to NAND:
flash_eraseall -j /dev/mtd4
mount -t jffs2 /dev/mtdblock4 /mnt
cd /mnt
tar xzvpf qtmoko-debian-nand.tar.gz
* Uncomment the /var/cache/apt mount in /mnt/etc/fstab
* Edit the mount for root in /mnt/etc/fstab so that it reads:
/dev/mtdblock4 / jffs2 rw,noatime 1 1
* Unmount NAND:
cd /
umount /mnt
* Write boot.scr with bootmenu to root of FAT boot partition
* Reboot and select NAND from the bootmenu
Step 13 - generate Packages.gz for debian repository
* We have debian repository at After you
upload packages there (using filezilla, host is user is
radekp,qtmoko and directory is /home/project-web/qtmoko/htdocs/debian) you
have to generate Packages.gz:
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
* For secure apt you need to generate and sign Release file:
apt-ftparchive release . > Release
gpg -abs -o Release.gpg Release
Boot speedup
- replacing /bin/sh with dash, speedup 15s
Ideas & TODO
- support for dumb batteries as described in mail
"Document with answers to most popular battery-related questions is ready"
from Paul Ferster
Creating debian cross compiling toolchain
* Install packages needed for toolchain. Use your phone and existing
qtmoko-debian rootfs (ideally from chroot over NFS in /root/toolchain on
your PC). (Havent found xcalibrate pkg, where is it? Is it needed?)
apt-get install libasound2-dev libbluetooth-dev libdbus-1-dev libglib2.0-dev \
libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libavcodec-dev \
libswscale-dev libxsettings-client-dev libssl-dev libts-dev \
libxcomposite-dev libxcursor-dev libxdamage-dev libxfont-dev \
libxfontcache-dev libxft-dev libxinerama-dev libxi-dev \
libxmu-dev libxmuu-dev libxp-dev libxrandr-dev libxts-dev libxtst-dev \
libxxf86dga-dev libxxf86misc-dev libxxf86vm-dev zlib1g-dev \
build-essential libc6-dev libjpeg-dev libfreetype6-dev libdjvulibre-dev
* Make directory for your toolchain and copy files from toolchain rootfs:
mkdir -p /opt/toolchains/arm920t-eabi/arm-linux-gnueabi/lib
mkdir -p /opt/toolchains/arm920t-eabi/arm-linux-gnueabi/include
cp -r /root/toolchain/lib /opt/toolchains/arm920t-eabi/arm-linux-gnueabi
cp -r /root/toolchain/usr/lib /opt/toolchains/arm920t-eabi/arm-linux-gnueabi
cp -r /root/toolchain/usr/include /opt/toolchains/arm920t-eabi/arm-linux-gnueabi
* We will use cross compiler from emdebian project. On PC add emdebian
repository to your /etc/apt/sources.list
deb lenny main
* Download needed packages
apt-get update
apt-get -d install libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi gcc-4.3-arm-linux-gnueabi g++-4.3-arm-linux-gnueabi
* Unpack toolchain packages
ln -s /opt/toolchains/arm920t-eabi /opt/toolchains/arm920t-eabi/usr
rm -rf /opt/toolchains/arm920t-eabi/arm-linux-gnueabi/include/c++/4.3*
dpkg -x /var/cache/apt/archives/binutils-arm-linux-gnueabi_2.18.1~cvs20080103-7_i386.deb /opt/toolchains/arm920t-eabi/
dpkg -x /var/cache/apt/archives/cpp-4.3-arm-linux-gnueabi_4.3.2-1.1_i386.deb /opt/toolchains/arm920t-eabi/
dpkg -x /var/cache/apt/archives/gcc-4.3-arm-linux-gnueabi-base_4.3.2-1.1_i386.deb /opt/toolchains/arm920t-eabi/
dpkg -x /var/cache/apt/archives/gcc-4.3-arm-linux-gnueabi_4.3.2-1.1_i386.deb /opt/toolchains/arm920t-eabi/
dpkg -x /var/cache/apt/archives/g++-4.3-arm-linux-gnueabi_4.3.2-1.1_i386.deb /opt/toolchains/arm920t-eabi/
dpkg -x /var/cache/apt/archives/libc6-armel-cross_2.7-18_all.deb /opt/toolchains/arm920t-eabi/
dpkg -x /var/cache/apt/archives/libc6-dev-armel-cross_2.7-18_all.deb /opt/toolchains/arm920t-eabi/
dpkg -x /var/cache/apt/archives/libgcc1-armel-cross_1%3a4.3.2-1.1_all.deb /opt/toolchains/arm920t-eabi/
dpkg -x /var/cache/apt/archives/libstdc++6-armel-cross_4.3.2-1.1_all.deb /opt/toolchains/arm920t-eabi/
dpkg -x /var/cache/apt/archives/libstdc++6-4.3-dev-armel-cross_4.3.2-1.1_all.deb /opt/toolchains/arm920t-eabi/
* Symlinks
cd /opt/toolchains/arm920t-eabi/lib/gcc/arm-linux-gnueabi/4.3.2
ln -s ../../../../arm-linux-gnueabi/lib/
* Fix problems with #include_next in stddef and others
cd /opt/toolchains/arm920t-eabi/arm-linux-gnueabi/include/c++/4.3.2
find . -type f -print0 | xargs -0 sed -i 's/#include_next/#include/g'
* Fix path to toolchain in package config files:
cd /opt/toolchains/arm920t-eabi/arm-linux-gnueabi/lib/pkgconfig
sed -i 's/\/usr/\/opt\/toolchains\/arm920t-eabi\/arm-linux-gnueabi/g' *.pc
* Make paths relative in and others:
cd /opt/toolchains/arm920t-eabi/arm-linux-gnueabi/lib
sed -i 's/\/usr\/arm-linux-gnueabi\/lib\///g' *.so
* Make the toolchain compatible with our old toolchain
cd /opt/toolchains/arm920t-eabi/
ln -s arm-linux-gnueabi arm-angstrom-linux-gnueabi
cd /opt/toolchains/arm920t-eabi/bin/
ln -s arm-linux-gnueabi-gcc-4.3 arm-linux-gcc
ln -s arm-linux-gnueabi-g++-4.3 arm-linux-g++
ln -s arm-linux-gnueabi-ar arm-linux-ar
ln -s arm-linux-gnueabi-strip arm-linux-strip
ln -s arm-linux-gnueabi-ld arm-linux-ld
ln -s arm-linux-gnueabi-nm arm-linux-nm
ln -s arm-linux-gnueabi-objcopy arm-linux-objcopy
ln -s arm-linux-gnueabi-objdump arm-linux-objdump
Something went wrong with that request. Please try again.