cross bootstrap

slonopotamus edited this page Jan 6, 2011 · 1 revision

Initial cross-bootstrap

This page is only left as a historical note

First I tried using existing arm OABI stages. Two problems. You'll immediately hit #462677. That can possibly be fixed by using kernel >=2.6.25. However one of my goals is minimal intervention in device preinstalled software (initfs, kernel, maemo image). Second: although Gentoo has some documented way of changing CHOST, I don't believe it is possible to perform OABI->EABI migration. Correct me if I'm wrong. Third, there isn't any working >2.6.21 kernel for n8x0

Another interesting approach is to convert maemo image into Gentoo using bootstrap-portage script.

Alternatively, Gentoo could be built from scratch using LFS approach. However this may be hard because of busybox. Actually I managed to build full GNU stack (coreutils, diffutils, etc) to /usr/local on vanilla maemo.

Anyway, I chose cross-compilation.


  • existing gentoo installation
  • n8x0 tablet
  • 4gb sd card
  • luck
  • free time

Step 1, cross-build minimal working system

Install cross-development tools:

emerge crossdev crossdev-wrappers

Build cross-toolchain:

crossdev -S armv6j-unknown-linux-gnueabi

Create convenient cross-portage infrastructure:

emerge-wrapper --init

Change profile from busybox to fully-powered GNU utils:

rm /usr/armv6j-unknown-linux-gnueabi/etc/make.profile
ln -s /usr/portage/profiles/default/linux/arm/10.0/ /usr/armv6j-unknown-linux-gnueabi/etc/make.profile

Tweak make.conf:

nano /usr/armv6j-unknown-linux-gnueabi/etc/make.conf

My tweaks:

  • Remove ~arm from ACCEPT_KEYWORDS (I prefer running stable branch and add ~arch keywords on a per-package basis)
  • USE='-* zlib minimal unicode ncurses'
  • Set CFLAGS (see CFLAGS page)

Try to cross-build mininal system (I hope it will pass successfully one day):

emerge-armv6j-unknown-linux-gnueabi -vND system

Los of stuff builds, but libperl fails. It won't build. At all. Even don't try. Emerge all remaining packages that don't depend on libperl with --oneshot.

So. We have minimal gentoo system (without perl).

Step 2, chroot into Gentoo on device, perform full native rebuild

From your tablet:

Transfer gentoo from build machine:

cd /path/to/gentoo/chroot && \
  ssh root@<gentoo_host_address> 'cd /usr/armv6j-unknown-linux-gnueabi && tar -czp * -O -' | tar -xvzp

Mount misc system stuff into chroot:

cd /path/to/gentoo/chroot && \
  mount -t proc proc proc && \
  mount -o bind /dev dev && \
  cp -L /etc/resolv.conf etc/resolv.conf

Enter chroot:

chroot /path/to/gentoo/chroot /bin/bash

Wooo-haaa! You're inside your n8x0 gentoo installation!

Remove cross-build related stuff from make.conf:

cat > /etc/make.conf << 'EOF'
CFLAGS='-Os -pipe -march=armv6j -mtune=arm1136jf-s -mfpu=vfp'
USE='-* zlib minimal unicode ncurses'

Sync portage tree:

emerge --sync

Build missing stuff from 'system':

emerge -v1 automake

Check that all 'system' built:

emerge -vuND system

Rebuild bash (I got strange failures without this):

emerge -v1 bash

Tweak USE flags in make.conf. I set USE='-ipv6 -fortran'

Reemerge natively gcc/glibc (~15 hours using 'performance' cpu governor). Do not forget to plug in battery charger.

Rebuild natively whole world.

emerge -ve system

Profit! You have fully-functional native arm gentoo chroot.