Building the Toolchain

The first step in the bootstrapping process is to compile the essential tools and libraries needed to build the rest of the system. Currently, Shedbuilt's toolchain, which is derived from Linux from Scratch, contains a meager thirty packages. This is far fewer than the ninety or so needed in later phases of the bootstrap, but will nonetheless require a considerable amount of time. At this point, you have two choices. You can either use the script below to automate the build - hereafter referred to as the 'easy' way - or you can do it the 'hard' way by typing in the individual commands yourself. Each approach has its advantages and disadvantages so I recommend you read on before deciding what to do.

The Easy Way

If you don't intend to configure the toolchain differently than is done in the shedbuilt-toolchain repository then you might as well use the handy script below and spare a bit of patience for forthcoming steps. You won't have opportunities to test the individual components during the build, but, assuming that we, the Shedbuilt developers, are on top of things, everything should work out fine.

Requirements

To build the Shedbuilt toolchain you'll need to run the commands below as root from the command-line of an existing GNU/Linux system, running on Shedbuilt-supported hardware. An obvious choice for this is, of course, Shedbuilt, but nearly anything will work. As the Shedbuilt System 1 'Amano' toolchain is derived from Linux from Scratch 8.1-systemd, please refer to their Host Requirements doc to ensure the existing operating system meets their base requirements. Additionally, our toolchain scripts require our packaging tool, shedmake, which itself requires git and wget to function properly in this phase. Please refer to the documentation for those tools and get them up and running before moving on.

Creating a Separate Partition

To build the toolchain and complete the bootstrap you'll need to create a sparkly, fresh paritition on your SD card or eMMC device on which the new system will be installed. This may require resizing the existing system's root partition from another machine to make room. You'll need at least 4GB of space for the standard Shedbuilt System 1 'Amano' bootstrap. Once you've created your new partition, modify your /etc/fstab to mount it by default to a folder on the root filesystem such as /mnt/shedstrap.

Running the Script

Pasting the following into your terminal will create a script to automate the toolchain build:

cat > install_toolchain.sh << "EOF"
#!/bin/bash

# install_toolchain
# Description: Pulls packaging for the bootstrap toolchain from
# the repository, then compiles and installs the toolchain.
# NOTE: This script assumes the presence of an ordered list of
# the packages to be installed in 'toolchain.txt' in the working
# directory.
# Example: sudo ./install_toolchain.sh https://github.com/shedbuilt/shedbuilt-toolchain.git amano orangepi-one /mnt/shedstrap

# Sanity Checks
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root. Please use 'sudo' if not logged in as root."
   exit 1
fi

if [ $# -lt 4 ]; then
   echo "Too few arguments to install_shedbuilt_toolchain"
   echo "Usage: install_shedbuilt_toolchain <repo-url> <release-branch> <device> <install-root>"
   echo "Example: sudo ./install_toolchain.sh https://github.com/shedbuilt/shedbuilt-toolchain.git amano orangepi-one /mnt/shedstrap"
   exit 1
fi

# Configuration
TOOLCHAINREPO="$1"
RELEASEBRANCH="$2"
TOOLCHAINDEV="$3"
INSTALLROOT="${4%/}"

# Create Shedmake toolchain repo at destination
PKGDIR="shedbuilt-toolchain"
cd "$INSTALLROOT"
if [ ! -d $PKGDIR ]; then
    git clone "$TOOLCHAINREPO" $PKGDIR
    cd $PKGDIR
    git checkout "$RELEASEBRANCH"
    git submodule init
else
    cd $PKGDIR
    git pull
fi
git submodule update

# Create symlink
if [ ! -L /tools ]; then
    mkdir -v "${INSTALLROOT}/tools"
    ln -sv "${INSTALLROOT}/tools" /
fi

# Set environment variables
set +h
umask 022
LC_ALL=POSIX
if [[ ":${PATH}:" != *":/tools/bin:"* ]]; then
    PATH="/tools/bin:${PATH}"
fi
export LC_ALL PATH

# Install toolchain packages
shedmake install-list toolchain.sml --device "$TOOLCHAINDEV" \
                                    --install-root "$INSTALLROOT" \
                                    --verbose || exit 1

# Strip binaries and remove docs
strip --strip-debug /tools/lib/*
/usr/bin/strip --strip-unneeded /tools/{,s}bin/*
rm -rf /tools/{,share}/{info,man,doc}
EOF
chmod +x install_toolchain.sh

Hit 'enter', and you will be ready to begin compilation. At this point, it's good to double-check that the new partition is mounted and the device has Internet connectivity. If you're building over ssh, consider running the script from screen so your build doesn't come to a screetching halt if the connection drops. When you're ready, kick off the script as the root user, substituting your new partition's mount point for /mnt/shedstrap:

$ sudo ./install_toolchain.sh https://github.com/shedbuilt/shedbuilt-toolchain.git amano orangepi-one /mnt/shedstrap

Passing the Time

Quad-core ARMv7 devices such as the Orange Pi One can take as 8 hours or more to build a complete toolchain. If watching the seemingly endless stream of compiler commands fly by doesn't strike you as top-notch entertainment then I suggest you step back from your computer and take a nice long walk. Let the sun burn away the vampiric palor of too many mispent days bathed in the cool glow of your LCD monitor. That's assuming you have fair weather. If it's raining, why not read about packaging software for Shedbuilt or skip ahead to the System Bootstrap page and get amped up for the 18+ hour compile-o-thon that's in store for you there.

The Hard Way

Welcome, young jedi, to the dark side. If you want to learn as much as you can about the foundation of the system, or simply cannot resist the temptation to begin tweaking compiler flags as soon as you can, this bit is for you. This approach will also provide ample opportunity to verify that essential tools are functional before proceeding before heading into the big nasty bootstrap on the next page.

Requirements

The requirements for a manual or semi-automated build are no different from those for the 'The Easy Way' so you'll want to read through the section above first. Keep in mind that you'll need to perform all of the setup steps in the install_toolchain.sh script manually before beginning compilation and ensure that the environment remains in that state throughout the process.

Installing Packages One-by-One

Rather than subject ourselves to the dismal exercise of manually configuring each lump of source code, we'll use Shedbuilt's packaging tool, shedmake, and our ready-made build recipes, located in the shedbuilt-toolchain repository to do it for us. Check out the branch corresponding to our current release and make any desired modifications locally, optionally committing your changes back to your own fork for safe keeping. If none of that made any sense, then I strongly suggest you read our documentation about Shedbuilt's packaging and how it interfaces with Git SCM.

To proceed, you essentially need to split the batch install performed using shedmake in the script into individual commands. To do this, bring up the bootstrap.sml file located in the root of the shedbuilt-toolchain repository. Each line of this file contains the arguments to shedmake that install, sometimes in multiple iterations, an individual toolchain package. To create the individual commands you need, simply sandwich each line between an invocation of shedmake's install action and an --install-root <your mountpoint> option. For instance, the first line of bootstrap.sml is used to build the first toolchain package, binutils:

binutils --mode toolchain --target toolchain --strip no

To perform the first-pass install of binutils to your fresly-prepared partition at /mnt/shedstrap, you'd type:

$ cd /mnt/shedstrap/shedbuilt-toolchain
$ sudo shedmake install binutils --mode toolchain --target toolchain --strip no --install-root /mnt/shedstrap

To complete installation of the toolchain, proceed through the packages on subsequent lines of bootstrap.sml in order, one-by-one. When at last you are returned to the command prompt after installing the final package you'll have both a lovely, custom toolchain and long, flowing locks of silvery hair. But there is so much more to do!