Gentoo on OpenMoko FreeRunner
2014-02-25
1. Install crossdev with
emerge crossdev
2. Build the Toolchain
crossdev -v --portage -b --binutils 2.23.1 --gcc 4.7.2 --libc 2.16.0 --kernel 2.6.39 --ov-output /usr/local/portage/ -t armv4tl-softfloat-linux-gnueabi
Get linux-headers linux-headers-2.6.39.ebuild and gentoo-headers-base-2.6.39.tar.xz from files/
Run this to get wrapper script armv4tl-softfloat-linux-gnueabi-emerge
emerge-wrapper --init
3. Kernel
Follow this guide to get the latest working kernel (2.6.39+)
http://wiki.openmoko.org/wiki/Kernel#Building_the_2.6.39_branch
Summary of commands
git clone git://git.openmoko.org/git/kernel.git linux-2.6
cd linux-2.6
git checkout --track -b om-gta02-2.6.39 origin/om-gta02-2.6.39
#Config, thanks to the OpenEmbedded guys
http://cgit.openembedded.org/cgit.cgi/openembedded/plain/recipes/linux/linux-2.6.39/om-gta02/defconfig?h=org.openembedded.dev
export ARCH="arm"
export CROSS_COMPILE="armv4tl-softfloat-linux-gnueabi-"
#Save the config
make menuconfig
make -j10
make uImage (emerge u-boot-tools first to get the mkimage binary)
mkdir GTA02
make modules_install INSTALL_MOD_PATH=GTA02
#We'll copy the contents of this to our runtime root in the end
Flash the kernel
dfu-util -a kernel -R -D arch/arm/boot/uImage
4. Emerge packages in SYSROOT
a. Use this profile
cd /usr/armv4tl-softfloat-linux-gnueabi/etc/portage/
ln -s /usr/portage/profiles/default/linux/arm/13.0/armv4t/ make.profile
b. Edit make.conf to
add 'distcc' to FEATURES
add " -nls -iconv -ipv6 -acl" to USE
c. Add this to package.use >=sys-libs/pam-1.1.5 -berkdb
d. The first goal is to get a working prompt on the phone and be able to login using ssh. cross merge these packages. To setup busybox and dropbear follow these steps
armv4tl-softfloat-linux-gnueabi-emerge -b flex
armv4tl-softfloat-linux-gnueabi-emerge -b openrc bash
armv4tl-softfloat-linux-gnueabi-emerge -b coreutils util-linux
armv4tl-softfloat-linux-gnueabi-emerge -b udex net-tools openssh
armv4tl-softfloat-linux-gnueabi-emerge -b sys-apps/findutils app-arch/gzip sys-apps/sed sys-process/procps sys-apps/kbd sys-apps/grep
5. Runtime Root
a. Create a new directory for our runtime root. Do all this as root. In my case it's
mkdir /disks/storage/openmoko/myroot
cd /disks/storage/openmoko/myroot
mkdir root proc sys dev
chmod -R 555 proc sys
chmod -R 700 root
chmod -R 755 dev
armv4tl-softfloat-linux-gnueabi-emerge --root /disks/storage/openmoko/myroot -K glibc openrc udev bash openssh net-tools sys-apps/findutils app-arch/gzip sys-apps/sed sys-process/procps sys-apps/kbd sys-apps/grep
b. Copy libgcc_s.so.1 from sysroot to runtime root
cp /usr/lib/gcc/armv4tl-softfloat-linux-gnueabi/4.7.1/libgcc_s.so.1 /disks/storage/openmoko/myroot/lib/
c. Copy firmware and modules to runtime rootfs
cp -rp linux-2.6/GTA02/lib/* myroot/lib/
d. Configuration
Following configuration was required
i. Add user 'sshd' to /etc/passwd and group 'sshd' to /etc/group
Add this line to myroot/etc/passwd sshd:x:22:22:added by portage for openssh:/var/empty:/sbin/nologin
Add this to myroot/etc/group
sshd:x:22:
If you emerge dbus, you'll have to do similar thing for the user and group 'messagebus'
'messagebus:x:101:249:added by portage for dbus:/dev/null:/sbin/nologin' in /etc/passwd
'messagebus:x:249:' in /etc/group
ii. Edit myroot/etc/shadow and set the root line to this. You have to remove the asterisk to set an empty password
root::10770:0:::::
iii. Load g_ether kernel module automatically so that we can ssh into the phone over USB. Add this line to myroot/etc/conf.d/modules
modules_2_6="g_ether"
iv. Put config for usb0 interface in myroot/etc/conf.d/net
config_usb0="192.168.0.202 netmask 255.255.255.0 brd 192.168.0.255"
v. Edit myroot/etc/ssh/sshd_config and set PermitEmptyPasswords yes
vi. Add net.usb0 and sshd to runlevel default
cd myroot/etc/init.d
ln -s net.lo net.usb0
cd myroot/etc/runlevels/default/
ln -s /etc/init.d/net.usb0 net.usb0
ln -s /etc/init.d/sshd sshd
vii. Add the --noclear option to agetty for tty1 in myroot/etc/inittab
c1:12345:respawn:/sbin/agetty --noclear 38400 tty1 linux
You can comment out all other terminals
viii. Set the hostname in nano myroot/etc/conf.d/hostname
6. Flash Rootfs To use NFS Root, follow these steps
cd /disks/storage/openmoko
mkfs.jffs2 -r myroot/ -o openrc.jffs2 (emerge mtd-utils to get mkfs.jffs2)
dfu-util -a rootfs -R -D openrc.jffs2
7. Other Packages
To begin with, emerge nano, Minicom to test the modem. To switch on the modem (/dev/ttySAC0) [1152000 8N1], do
echo 1 > /sys/bus/platform/devices/gta02-pm-gsm.0/power_on
Then you can look at emerging a GSM stack like ofono
armv4tl-softfloat-linux-gnueabi-emerge xf86-video-fbdev
for xorg works
Note 1: The above steps should work for any toolchain built using crossdev
Note 2: For using DISTCC while cross compiling, refer to https://wiki.gentoo.org/wiki/Distcc/Cross-Compiling. To install the toolchain on helper boxes, you don't need to build it again. Just copy over /usr/portage/packages/cross-armv4tl-softfloat-linux-gnueabi/ and run
crossdev -v --portage -K --binutils 2.23.1 --gcc 4.7.2 --libc 2.16.0 --kernel 2.6.39 --ov-output /usr/local/portage/ -t armv4tl-softfloat-linux-gnueabi
Apart from the steps mentioned in the cross compile guide, I had to create the following symlinks on all the boxes including the host
cd /usr/lib/distcc/bin/
ln -s /usr/bin/distcc armv4tl-softfloat-linux-gnueabi-gcc
ln -s /usr/bin/distcc armv4tl-softfloat-linux-gnueabi-g++
ln -s /usr/bin/distcc armv4tl-softfloat-linux-gnueabi-c++
References
https://www.gentoo.org/proj/en/base/embedded/handbook/
http://www.gentoo.org/proj/en/base/embedded/
https://www.gentoo.org/proj/en/base/embedded/cross-development.xml
http://tinderbox.dev.gentoo.org/cross-x86/
https://wiki.gentoo.org/wiki/Distcc/Cross-Compiling
http://wiki.openmoko.org/wiki/Kernel#Building_the_2.6.39_branch
http://wiki.openmoko.org/wiki/Flashing_the_Neo_FreeRunner#Using_dfu-util
You can reach me on