User:Thessem/embetoo

Outline
This is a work in progress guide for creating a small embedded Gentoo distribution, which is called Embetoo.

Goal
This article will hopefully describe how to make a small, efficient embedded Gentoo system, that will run on a Cyrix MediaGX processor, build on a Core2 Duo Host computer

Installing a chrootable gentoo base system
First make the directory where we'll be playing around.
 * 1) sudo mkdir /opt/embetoo-build
 * 2) sudo chown james:users /opt/embetoo-build
 * 3) cd /opt/embetoo-build

Downloading appropriate installation files
 * 1) wget http://ftp.swin.edu.au/gentoo/releases/amd64/current-stage3/stage3-amd64-20100408.tar.bz2
 * 2) wget http://ftp.swin.edu.au/gentoo/snapshots/portage-20100414.tar.bz2
 * 3) tar xjpf stage3-amd64-20100408.tar.bz2 -C ./
 * 4) tar xjf portage-20100414.tar.bz2 -C ./usr

Prepare environment with a few things to make life nicer

Adding a nice PS1 prompt and setting a better hostname, add the following to bashrc

Now we finally chroot into it
 * 1) cp -L /etc/resolv.conf etc/resolv.conf
 * 2) sudo mount --rbind /dev dev/ #rbind instead of bind stops the openpty failed: 'out of pty devices' warning
 * 3) sudo mount -t proc proc proc/
 * 4) sudo chroot ./ /bin/bash
 * 5) env-update && source /etc/profile

Setting up build environment
Having the correct time is pretty cool, so
 * 1) ln -sf /usr/share/zoneinfo/Australia/Sydney /etc/localtime

Set up the make.conf with setting to optimising compiling to your own architecture (I'm using a core2duo)

We also need to make that overlay directory mentioned for later
 * 1) mkdir -p /usr/local/portage

Updating the installed system
 * 1) emerge --sync
 * 2) emerge -av gentoolkit	portage-utils
 * 3) emerge -uavtDN --with-bdeps=y world #Crossdev doesn't seem to work without the bdeps bit
 * 4) emerge --depclean --ask
 * 5) revdep-rebuild

Setting up the cross compiler
We have to install the package which kindly builds the cross compiler for us
 * 1) echo "sys-devel/crossdev ~amd64" >> /etc/portage/package.keywords
 * 2) emerge -uav crossdev
 * 3) crossdev -P -v -t i586-pc-linux-uclibc

This will install the cross compiler into /usr/i586-pc-linux-uclibc (or /opt/embetoo-build/usr/i586-pc-linux-uclibc outside the chrooted environment) which we will call the SYSROOT from now on (And we also call i586-pc-linux-uclibc our CTARGET)

Setup portage in the sysroot to compile packages which will work on the target system


 * 1) mkdir /usr/i586-pc-linux-uclibc/etc/
 * 2) cp /etc/make.globals /usr/i586-pc-linux-uclibc/etc/
 * 3) ln -sn /usr/portage/profiles/uclibc/x86 /usr/i586-pc-linux-uclibc/etc/make.profile

You know have a sysroot directory that is platform agnostic, and to use it properly, a /usr/embetoo-build directory that is platform specific,

Building packages in sysroot, with cross compiler
Then, make it so portage accepts the more up to date (And more suitable to embedded systems) baselayout-2 package
 * 1) mkdir -p /usr/i586-pc-linux-uclibc/etc/portage
 * 2) echo "sys-apps/baselayout ~x86" >> /usr/i586-pc-linux-uclibc/etc/portage/package.keywords
 * 3) echo "sys-apps/openrc ~x86" >> /usr/i586-pc-linux-uclibc/etc/portage/package.keywords
 * 4) echo "sys-fs/udev ~x86" >> /usr/i586-pc-linux-uclibc/etc/portage/package.keywords

Ncurses doesn't seem to build unless we remove its -cxx use flag
 * 1) echo "sys-libs/ncurses -cxx" >>  /usr/i586-pc-linux-uclibc/etc/portage/package.use

Make busybox make symlinks, this seems like a good idea
 * 1) echo "sys-apps/busybox make-symlinks" >> /usr/i586-pc-linux-uclibc/etc/portage/package.use

This is to compile the needed packages, zip the archives up, and put them in /deploy, you may need to stop every now and then to actually install some packages (zlib and ncurses from memory) in sysroot itself
 * 1) mkdir /deploy
 * 2) ROOT=/usr/i586-pc-linux-uclibc/ PKGDIR=/deploy emerge-i586-pc-linux-uclibc --buildpkgonly -uave dropbear uclibc busybox baselayout
 * 3) ROOT=/embetoo FEATURES="buildpkg -sandbox noman noinfo nodoc" INSTALL_MASK="*.a *.h *.ac *.pc *.la *.mo *.m4 Makefile*" PKGDIR=/deploy emerge-i586-pc-linux-uclibc -uaveK dropbear uclibc busybox baselayout

I had to use unstable uclibc for this to work

UCLIBC_CPU needs to be set