summaryrefslogtreecommitdiffstats
path: root/temporary-bootstrap-builder-setup.txt
blob: 50a715dac6f4fdf7971a53126f04c950f0b67323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
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.


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 '<BASE_DIR>' 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 <<EOF
  > exec env -i HOME="${HOME}" TERM="${TERM}" /bin/bash
  > EOF
  $ cat > ~/.bashrc <<EOF
  > set +h
  > umask 022
  > BBL=<BASE_DIR>/sys/fsmnt
  > LC_ALL=C
  > PATH=<BASE_DIR>/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 <<EOF
  > root::0:0:root:/root:/bin/bash
  > EOF
  $ cat > ${BBL}/etc/group <<EOF
  > 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.
  $ 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