Hi Gordon
Thanks for taking the time to look over the documentation!
yes, I did think about reusing the existing /dev/sda1 as the Gentoo root (for those users who want to put Gentoo on their internal drive, rather than simply run it from the 'live USB'). However, 10G is quite tight for a Gentoo machine. As you note, /usr/portage can get quite large - the ebuild tree (uncompressed) takes about 1G, but by default Gentoo also keeps tarballs for every source package ever emerged (in /usr/portage/distfiles), so unless you run eclean regularly it can easily top 10G!
Otherwise, the setup is standard Gentoo handbook stuff - just trying to keep things simple ^-^ As such I've assumed the user is overwriting the disk with a DOS partition table (o in fdisk). However, the version of fdisk on the image can create GPT partition tables too, and there's nothing to prevent a user doing that if they like. Or creating LVM over LUKS etc!
Of course I guess most people will simply run it from the USB key to have a play with Gentoo, without altering their existing Excito system.
Version 1.1.0 of gentoo-on-b3 (GitHub)
This is now locked off - thanks to everyone who sent comments or tried out the 1.0.0 image. I'll release it within the next couple of days on GitHub, and post a message here when I do.
How to Cross-Compile a B3 Kernel on a Gentoo PC
Lastly, for anyone with Gentoo on their home machine, spinning a custom kernel for the B3 is easy, via Gentoo's crossdev (and a lot faster than doing it on the B3 itself! 5 minutes vs 4 hours, in my case). Should you want to build a kernel on your Gentoo PC (for your B3 that is), here's what you do.
First, since crossdev uses the first overlay it finds as home, if you use layman, then you should do the following:
Code: Select all
gentoo_pc ~ # mdkir /usr/local/portage
gentoo_pc ~ # echo 'PORTDIR_OVERLAY="/usr/local/portage $PORTDIR_OVERLAY"' >> \
/etc/portage/make.conf
Next, if you haven't already done so, convert the relevant /etc/portage files (package.accept_keywords etc.) to directories. You can run the following script to do this automatically (credit: MobileAPES):
Code: Select all
#!/bin/bash
PROFILE_DIR="/etc/portage"
if [ ! -e ${PROFILE_DIR} ]; then
mkdir ${PROFILE_DIR};
fi;
MYCHOST=$(gcc-config -c | sed -e 's/\-[0-9]*\.[0-9\.]*.*$//g')
for PACK_DIR in package.keywords package.use package.unmask package.mask \
package.license package.accept_keywords; do
CUR_DIR="${PROFILE_DIR}/${PACK_DIR}"
if [ ! -e ${CUR_DIR} ]; then
mkdir ${CUR_DIR}
fi
if [ -e ${CUR_DIR} -a ! -d ${CUR_DIR} ]; then
mv ${CUR_DIR} ${CUR_DIR}.moving
mkdir ${CUR_DIR}
mv ${CUR_DIR}.moving ${CUR_DIR}/${MYCHOST}
fi
done
echo "Completed!"
Install crossdev and the uboot tools (for mkimage) if you don't already have them:
Code: Select all
gentoo_pc ~ # emerge -av sys-devel/crossdev dev-embedded/u-boot-tools sys-fs/dosfstools
Next, let crossdev build a cross-toolchain for our target architecture, using 'stable branch' tools (gcc etc.)
Code: Select all
gentoo_pc ~ # crossdev --stable --target armv5tel-softfloat-linux-gnueabi
(It may complain about '/usr/local/portage/metadata/layout.conf' not existing, but crossdev will create and populate the file for you.)
Now grab some kernel sources. Let's say you wanted 3.16.1. As of the time of writing, this is not stabilized for the arm architecture on Gentoo, so we'd need to issue:
Code: Select all
gentoo_pc ~ # echo "sys-kernel/gentoo-sources ~arm" >> \
/etc/portage/package.accept_keywords/cross-armv5tel-softfloat-linux-gnueabi
And you need the 'freedist' license:
Code: Select all
gentoo_pc ~ # echo "sys-kernel/gentoo-sources freedist" >> \
/etc/portage/package.license/cross-armv5tel-softfloat-linux-gnueabi
Grab the sources (note we use --nodeps here; we don't actually want to cross-emerge the perl etc. tools that'll be used by Gentoo to patch the sources, you already have them in your native arch)
Code: Select all
gentoo_pc ~ # ARCH="arm" armv5tel-softfloat-linux-gnueabi-emerge \
-av --nodeps =sys-kernel/gentoo-sources-3.16.1
That's all the one-off steps out of the way. Now, go into the source directory (crossdev automatically keeps things separate from your normal sysroot, to avoid pollution):
Code: Select all
gentoo_pc ~ # cd /usr/armv5tel-softfloat-linux-gnueabi/usr/src/linux-3.16.1-gentoo
Grab a suitable starter config from somewhere, such as off of my GitHub project, save it to .config, and sanitize it:
Code: Select all
gentoo_pc linux-3.16.1-gentoo # cp <your config file> .config
gentoo_pc linux-3.16.1-gentoo # make ARCH="arm" \
CROSS_COMPILE="armv5tel-softfloat-linux-gnueabi-" olddefconfig
(Don't forget the hyphen at the end of armv5tel-softfloat-linux-gnueabi-!) Now set any configuration options you like in there (such as built-in command line etc):
Code: Select all
gentoo_pc linux-3.16.1-gentoo # make ARCH="arm" \
CROSS_COMPILE="armv5tel-softfloat-linux-gnueabi-" menuconfig
To build it, copy the following script into /root/build_image.sh and make it executable:
Code: Select all
#!/bin/bash
# Prepare B3 image, switching off cache, and appending DTB; also
# builds the modules. Results go to deploy_root directory.
# Execute in top-level kernel directory.
# Copyright (c) 2014 sakaki
# License: GPL 3.0+
# NO WARRANTY
set -e
set -u
DR="deploy_root"
die() { cat <<< "$@" 1>&2; exit 1; }
if [ ! -d "${DR}" ]; then
echo "Creating directory: ${DR}"
mkdir "${DR}"
fi
echo "Cleaning prior ${DR}..."
if [ -d "${DR}/boot" ]; then
rm -rf "${DR}/boot"
fi
if [ -d "${DR}/lib" ]; then
rm -rf "${DR}/lib"
fi
if [ -s "${DR}.tar" ]; then
rm -f "${DR}.tar"
fi
NUMTHREADS=$(( $(grep -E 'processor\s+:' /proc/cpuinfo | wc -l) + 1 ))
KNAME="$(basename "${PWD}")"
KNAME="${KNAME/linux-/Linux }"
echo "Compiling kernel (${KNAME})..."
make -j${NUMTHREADS} ARCH=arm CROSS_COMPILE=armv5tel-softfloat-linux-gnueabi- \
zImage
echo "Compiling DTB..."
make ARCH=arm CROSS_COMPILE=armv5tel-softfloat-linux-gnueabi- kirkwood-b3.dtb
echo "Compiling modules..."
make -j${NUMTHREADS} ARCH=arm CROSS_COMPILE=armv5tel-softfloat-linux-gnueabi- \
modules
echo "Installing modules to ${DR}..."
make ARCH=arm CROSS_COMPILE=armv5tel-softfloat-linux-gnueabi- \
INSTALL_MOD_PATH="${DR}" modules_install
echo "Creating patched image for B3 (caches off, DTB appended)..."
pushd arch/arm/boot
# per Debian workaround #658904 (credit: Ian Campbell)
echo -n -e \\x11\\x3f\\x3f\\xee > cache_head_patch
echo -n -e \\x01\\x35\\xc3\\xe3 >> cache_head_patch
echo -n -e \\x11\\x3f\\x2f\\xee >> cache_head_patch
echo -n -e \\x00\\x30\\xa0\\xe3 >> cache_head_patch
echo -n -e \\x17\\x3f\\x07\\xee >> cache_head_patch
cat cache_head_patch zImage dts/kirkwood-b3.dtb > zImage-dts-appended
rm cache_head_patch
mkimage -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 \
-n "Gentoo ARM: ${KNAME}" -d zImage-dts-appended ../../../uImage
popd
echo "Final uImage has been created, copying to ${DR}..."
mkdir -p "${DR}/boot"
cp -v uImage "${DR}/boot/uImage"
cp -v System.map "${DR}/boot/System.map"
cp -v .config "${DR}/boot/config"
find "${DR}/lib/modules" -type l -name 'build' -delete
find "${DR}/lib/modules" -type l -name 'source' -delete
echo "Creating tarball..."
tar cf "${DR}.tar" "${DR}"
echo "Syncing filesystems, please wait..."
sync
echo "All done!"
This script deals with all the unpleasant L2-caches-off code, device tree blob etc. Now run it! This does a parallel compile so on a modern PC, it shoudn't take long (5-10 mins):
Code: Select all
gentoo_pc linux-3.16.1-gentoo # /root/build_image.sh
When done, you'll have a new directory deploy_root, which will contain a directory boot (with the uImage, System.map and config in it), and lib (with the modules and firmware).
Deploy these to your (Gentoo) B3 and off you go! (You can repeat the menuconfig / build_image.sh steps as often as you need, to refine the kernel).
Obviously,
proceed at your own risk: only do this if you have a reasonable idea of what you are doing! And make sure you have a rescue system on hand. Don't delete your old /boot/uImage (just rename it); and leave your old /lib/modules/<...> in place), in case you need to fall back.
Note also that this will
only work with version >=3.15 of the kernel, as that is when the B3's device tree data was integrated into the mainline (thereby obviating the need for an Excito-patched kernel).
3.16.1 on a Debian Squeeze B3
BTW, and I mention this more as a curiosity than anything else, I've managed to boot the standard Debian 'squeeze' B3 (no Gentoo) from a 'stock' 3.16.1 kernel using this method (the only difference being, that I downloaded the sources using sys-kernel/vanilla-sources, so no Gentoo patch set was applied). Most things seem to work (e.g., the Excito interface web GUI comes up), but I'm not a Debian hacker. Of course, some things are broken. For example, the LEDs are now accessed via the /sys paths defined in the device tree (rather than via Excito's patches, which obviously aren't applied), so as things stand, the front light doesn't go blue when you boot, etc.)
If anyone is interested, I can post that kernel and module set on GitHub too, just let me know.
best
sakaki