ABOUT THIS GUIDE ================ This is a guide to building a custom BusyBox/Linux-libre system with the GNU toolchain. It mostly follows Cross Linux From Scratch Sysroot version SVN-0.0.1-20090726-x86, except that it uses more recent versions of software packages and uses a BusyBox-based userspace rather than a GNU-based one. This guide assumes the use of a GNU/Linux host system with all the necessary development software (GCC, GNU Binutils, Subversion, etc.) already installed. It is recommended that you read Cross Linux From Scratch Sysroot version SVN-0.0.1-20090726-x86 to understand the full build process and the rationale behind various elements of the setup. LEGAL NOTICE ============ THIS GUIDE: Copyright (C) 2012 Patrick (P. J.) McDermott This guide may be reproduced, distributed, modified, and otherwise dealt in under the terms of the Expat/MIT License: http://www.jclark.com/xml/copying.txt CERTAIN COMMAND LINES AND FILE CONTENTS: Cross-Compiled Linux From Scratch - Sysroot Version SVN-0.0.1-20090726-x86 Copyright © 2005-2009, Jim Gifford, & Ryan Oliver This material may be distributed only subject to the terms and conditions set forth in the Open Publication License v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The latest version of the original book may be downloaded from: http://trac.cross-lfs.org/wiki/download#CLFSSysroot1.xUnderDevelopment It may also be read online at: http://cross-lfs.org/view/clfs-sysroot/x86/ TRADEMARKS: Linux is a Registered Trademark of Linus Torvalds. PROCEDURE ========= Make a directory in which all work will be done. Under this directory, make directories 'src' and sys': $ mkdir src sys Download all of the necessary source archives and branches. $ cd src $ wget http://www.busybox.net/downloads/busybox-1.19.3.tar.bz2 $ wget http://www.fsfla.org/svnwiki/selibre/linux-libre/download/releases/\ > LATEST-3.1.N/linux-3.1.6-libre.tar.bz2 $ svn co svn://svn.eglibc.org/branches/eglibc-2_14 eglibc-2.14 $ wget http://ftp.gnu.org/gnu/gcc/gcc-4.6.2/gcc-4.6.2.tar.bz2 $ wget http://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.bz2 $ wget http://ftp.gnu.org/gnu/make/make-3.82.tar.bz2 $ wget http://ftp.gnu.org/gnu/automake/automake-1.11.2.tar.bz2 $ wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.bz2 $ wget http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.bz2 $ wget ftp://ftp.gmplib.org/pub/gmp-5.0.2/gmp-5.0.2.tar.bz2 $ wget http://www.mpfr.org/mpfr-current/mpfr-3.1.0.tar.bz2 $ wget http://www.multiprecision.org/mpc/download/mpc-0.9.tar.gz $ for file in *.tar.bz2; do tar -xjf ${file}; done $ for file in *.tar.gz; do tar -xzf ${file}; done $ cd .. Make and mount the filesystem. mkfs and mount must be run as the superuser, but dd shouldn't need to be. $ cd sys $ dd if=/dev/zero of=fs bs=1024 count=$((3*1024*1024)) # mkfs -t ext4 fs $ mkdir fsmnt # mount -o loop fs fsmnt Set up a new user. # groupadd bbl # useradd -s /bin/bash -g bbl -d /home/bbl bbl # mkdir -pv /home/bbl # chown -v bbl:bbl /home/bbl # passwd bbl # chown -Rv bbl fsmnt Set up the toolchain work environment. Be sure to change '' to the absolute path to the base work directory you made earlier, and adjust the configuration name in BBL_TARGET if you're building for a different architecture. We're using GNU Bash as the new user's default shell for convenience; this has no effect on the target system. $ su - bbl $ cat > ~/.bash_profile < exec env -i HOME="${HOME}" TERM="${TERM}" /bin/bash > EOF $ cat > ~/.bashrc < set +h > umask 022 > BBL=/sys/fsmnt > LC_ALL=C > PATH=/sys/fsmnt/cross-tools/bin:/bin:/usr/bin > export BBL LC_ALL PATH > PS1='$ ' > unset CFLAGS > unset CXXFLAGS > export BBL_HOST=$(echo ${MACHTYPE} | \ > sed "s/$(echo ${MACHTYPE} | cut -d - -f 2)/cross/") > export BBL_TARGET=x86_64-pc-linux-gnu > EOF $ source ~/.bash_profile Make system directories. These commands should give you a system that is compliant with Filesystem Hierarchy Standard version 2.3. Note that the range syntax in many of these command lines is a non-standard feature of GNU Bash; this may not work on other shells. $ mkdir -pv ${BBL}/{bin,boot,dev,etc/opt,home,lib,media,mnt,opt,proc} $ install -dv -m 0750 ${BBL}/root $ mkdir -pv ${BBL}/{sbin,srv,sys} $ install -dv -m 1777 ${BBL}{,/var}/tmp $ mkdir -pv ${BBL}/usr/{,local/}{bin,include,lib,sbin,share/{man,misc},src} $ mkdir -pv ${BBL}/usr/local/{etc,games} $ mkdir -pv ${BBL}/usr/{,local/}share/{doc,info,locale,terminfo,zoneinfo} $ mkdir -pv ${BBL}/usr/{,local/}share/man/man{1,2,3,4,5,6,7,8} $ ln -sv share/man ${BBL}/usr/local/man $ mkdir -pv ${BBL}/var/{cache,lib/misc,local,lock,log,mail,opt,run,spool} Write the passwd and group files. $ cat > ${BBL}/etc/passwd < root::0:0:root:/root:/bin/bash > EOF $ cat > ${BBL}/etc/group < root:x:0: > bin:x:1: > sys:x:2: > kmem:x:3: > tty:x:4: > tape:x:5: > daemon:x:6: > floppy:x:7: > disk:x:8: > lp:x:9: > dialout:x:10: > audio:x:11: > video:x:12: > utmp:x:13: > usb:x:14: > cdrom:x:15: > EOF If CONFIG_FEATURE_UTMP and/or CONFIG_FEATURE_WTMP are enabled in BusyBox, certain BusyBox applets (getty, login, init, etc.) will log user logins to /var/run/utmp and/or /var/run/wtmp. However, BusyBox's supporting library won't create /var/run/wtmp if it doesn't exist. So create these files now and set proper modes for them. $ touch ${BBL}/var/run/{u,w}tmp $ chmod -v 664 ${BBL}/var/run/{u,w}tmp /var/run/utmp is used to track logged-in users. /var/run/wtmp is used to record when users log into and out of the system. NB: This is an odd location for wtmp, but that's where an unpatched BusyBox will expect it. Make and change to a directory for package source code. $ mkdir -v ${BBL}/src $ cd ${BBL}/src Install Linux's headers for use by EGLIBC. $ cp -pR ${BBL}/../../src/linux-3.1.6 . $ cd linux-3.1.6 $ make mrproper $ make headers_check $ make INSTALL_HDR_PATH=${BBL}/usr headers_install $ find ${BBL}/usr/include/ -name .install -o -name ..install.cmd | \ > xargs rm -fv $ cd .. $ rm -Rf linux-3.1.6 Install GMP for use by the cross-compiling GCC build. $ cp -pR ${BBL}/../../src/gmp-5.0.2 . $ cd gmp-5.0.2 $ CPPFLAGS=-fexceptions ./configure --prefix=${BBL}/cross-tools --enable-cxx $ make $ make install $ make check $ cd .. $ rm -Rf gmp-5.0.2 Install MPFR for use by the cross-compiling GCC build. $ cp -pR ${BBL}/../../src/mpfr-3.1.0 . $ cd mpfr-3.1.0 $ LDFLAGS="-Wl,-rpath,${BBL}/cross-tools/lib" ./configure \ > --prefix=${BBL}/cross-tools --enable-shared --with-gmp=${BBL}/cross-tools $ make $ make install $ cd .. $ rm -Rf mpfr-3.1.0 Install MPC for use by the cross-compiling GCC build. $ cp -pR ${BBL}/../../src/mpc-0.9 . $ cd mpc-0.9 $ LDFLAGS="-Wl,-rpath,${BBL}/cross-tools/lib" ./configure \ > --prefix=${BBL}/cross-tools --with-mpfr=${BBL}/cross-tools \ > --with-gmp=${BBL}/cross-tools $ make $ make install $ cd .. $ rm -Rf mpc-0.9 Configure and build a cross-compiling GNU Binutils. $ cp -pR ${BBL}/../../src/binutils-2.22 . $ mkdir -v binutils-build $ cd binutils-build $ AR=ar AS=as ../binutils-2.22/configure --prefix=${BBL}/cross-tools \ > --host=${BBL_HOST} --target=${BBL_TARGET} --with-sysroot=${BBL} \ > --disable-nls --enable-shared --disable-multilib $ make configure-host $ make $ make install $ cp -v ../binutils-2.22/include/libiberty.h ${BBL}/usr/include $ cd .. $ rm -Rf binutils-2.22 binutils-build Configure and build a cross-compiling GCC with a static libgcc and no threads. $ cp -pR ${BBL}/../../src/gcc-4.6.2 . $ mkdir -v gcc-build $ cd gcc-build $ AR=ar LDFLAGS="-Wl,-rpath,${BBL}/cross-tools/lib" ../gcc-4.6.2/configure \ > --prefix=${BBL}/cross-tools --build=${BBL_HOST} --host=${BBL_HOST} \ > --target=${BBL_TARGET} --disable-multilib --with-sysroot=${BBL} \ > --disable-nls --without-headers --with-newlib --disable-decimal-float \ > --disable-libgomp --disable-libmudflap --disable-libssp \ > --with-mpfr=${BBL}/cross-tools --with-gmp=${BBL}/cross-tools \ > --with-mpc=${BBL}/cross-tools --without-ppl --without-cloog \ > --disable-shared --disable-threads --enable-languages=c $ make all-gcc all-target-libgcc $ make install-gcc install-target-libgcc $ cd .. $ rm -Rf gcc-4.6.2 Configure and build a cross-compiling EGLIBC. Change '' to the lower of either version 3.1.6 or the version of Linux running on your host system. $ cp -pR ${BBL}/../../src/eglibc-2.14 . $ cd eglibc-2.14/libc $ cp -v Makeconfig{,.orig} $ sed -e 's/-lgcc_eh//g' Makeconfig.orig > Makeconfig $ cd ../.. $ mkdir -v eglibc-build $ cd eglibc-build $ cat > config.cache < libc_cv_forced_unwind=yes > libc_cv_c_cleanup=yes > libc_cv_gnu89_inline=yes > libc_cv_ssp=no > EOF $ cat > configparams < install_root=${BBL} > EOF $ BUILD_CC=gcc CC=${BBL_TARGET}-gcc AR=${BBL_TARGET}-ar \ > RANLIB=${BBL_TARGET}-ranlib \ > CFLAGS="-march=$(cut -d - -f 1 <<< ${BBL_TARGET} | sed 's/x86_64/x86-64/') \ > -mtune=generic -g -O2" ../eglibc-2.14/libc/configure --prefix=/usr \ > --libexecdir=/usr/lib/eglibc --host=${BBL_TARGET} --build=${BBL_HOST} \ > --disable-profile --enable-add-ons --with-tls --enable-kernel= \ > --with-__thread --with-binutils=${BBL}/cross-tools/bin \ > --with-headers=${BBL}/usr/include --cache-file=config.cache $ make $ make install_root=${BBL} install $ rm -Rf * Build EGLIBC's localedef and install locales. $ CPPFLAGS=-DNOT_IN_libc ../eglibc-2.14/localedef/configure > --prefix=${BBL}/usr --with-glibc=../eglibc-2.14/libc $ make $ make SUPPORTED-LOCALES='\ > de_DE.UTF-8/UTF-8 de_DE/ISO-8859-1 de_DE@euro/ISO-8859-15 \ > en_HK.UTF-8/UTF-8 en_HK/ISO-8859-1 \ > en_PH.UTF-8/UTF-8 en_PH/ISO-8859-1 \ > en_US.UTF-8/UTF-8 en_US/ISO-8859-1 \ > es_MX.UTF-8/UTF-8 es_MX/ISO-8859-1 \ > fa_IR/UTF-8 \ > fr_FR.UTF-8/UTF-8 fr_FR/ISO-8859-1 fr_FR@euro/ISO-8859-15 \ > it_IT.UTF-8/UTF-8 it_IT/ISO-8859-1 \ > ja_JP.EUC-JP/EUC-JP ja_JP.UTF-8/UTF-8' install-locales $ cd .. $ rm -Rf eglibc-2.14 eglibc-build Write the Name Service Switch configuration file. $ cat > ${BBL}/etc/nsswitch.conf < # /etc/nsswitch.conf > > passwd: files > group: files > shadow: files > > hosts: files dns > networks: files > > protocols: files > services: files > ethers: files > rpc: files > EOF Set the system's timezone. $ TZDIR=${BBL}/usr/share/zoneinfo ${BBL}/usr/bin/tzselect Answer the prompts and the tzselect script will output the name of a time zone. Substitute '' below with this name. $ ln -sfv ../usr/share/zoneinfo/ ${BBL}/etc/localtime Configure the dynamic loader to search for libraries in /usr/local/lib and /opt/lib in addition to its default locations /lib and /usr/lib. $ cat > ${BBL}/etc/ld.so.conf < # /etc/ld.so.conf > > /usr/local/lib > /opt/lib > EOF Configure and build a final cross-compiling GCC. $ cp -pR ${BBL}/../../src/gcc-4.6.2 . $ mkdir -v gcc-build $ cd gcc-build $ AR=ar LDFLAGS="-Wl,-rpath,${BBL}/cross-tools/lib" ../gcc-4.6.2/configure \ > --prefix=${BBL}/cross-tools --build=${BBL_HOST} --host=${BBL_HOST} \ > --target=${BBL_TARGET} --disable-multilib --with-sysroot=${BBL} \ > --disable-nls --enable-shared --enable-languages=c,c++ \ > --enable-__cxa_atexit --with-mpfr=${BBL}/cross-tools \ > --with-gmp=${BBL}/cross-tools --with-mpc=${BBL}/cross-tools --without-ppl \ > --without-cloog --enable-c99 --enable-long-long --enable-threads=posix $ make AS_FOR_TARGET="${BBL_TARGET}-as" LD_FOR_TARGET="${BBL_TARGET}-ld" $ make install