Fix building and unpacking of the ARM boostrap tools.

NOTE: This is incomplete - the tools need to be built, uploaded and the references fixed.
This commit is contained in:
Ambroz Bizjak 2015-01-29 02:36:16 +01:00
parent cf317b85ad
commit 8fb7d8bede
5 changed files with 139 additions and 146 deletions

View File

@ -1,11 +1,12 @@
# Use the static tools for armv5tel-linux.
(import ./armv5tel.nix) //
{
bootstrapTools = {
# Built from make-bootstrap-tools-crosspi.nix
# nixpkgs rev eb0422e4c1263a65a9b2b954fe10a1e03d67db3e
url = http://viric.name/tmp/nix/pi/bootstrap-tools.cpio.bz2;
sha256 = "1zb27x5h54k51yrvn3sy4wb1qprx8iv2kfbgklxwc0mcxp9b7ccd";
busybox = import <nix/fetchurl.nix> {
url = https://dl.dropboxusercontent.com/s/4705ffxjrxxqnh2/busybox?dl=0;
sha256 = "032maafy4akcdgccpxdxrza29pkcpm81g8kh1hv8bj2rvssly3z2";
executable = true;
};
bootstrapTools = import <nix/fetchurl.nix> {
url = https://dl.dropboxusercontent.com/s/pen8ieymeqqdvqn/bootstrap-tools.tar.xz?dl=0;
sha256 = "0kjpjwi6qw82ca02ppsih3bnhc3y150q23k9d56xzscs0xf5d0dv";
};
}

View File

@ -0,0 +1,12 @@
{
busybox = import <nix/fetchurl.nix> {
url = https://dl.dropboxusercontent.com/s/rowzme529tc5svq/busybox?dl=0;
sha256 = "18793riwv9r1bgz6zv03c84cd0v26gxsm8wd2c7gjrwwyfg46ls4";
executable = true;
};
bootstrapTools = import <nix/fetchurl.nix> {
url = https://dl.dropboxusercontent.com/s/3jr4s5449t7zjlj/bootstrap-tools.tar.xz?dl=0;
sha256 = "1qyp871dajz5mi3yaw9sndwh4yrh1jj184wjjwaf6dpr3jir4kyd";
};
}

View File

@ -16,7 +16,7 @@ rec {
else if system == "x86_64-linux" then import ./bootstrap/x86_64.nix
else if system == "armv5tel-linux" then import ./bootstrap/armv5tel.nix
else if system == "armv6l-linux" then import ./bootstrap/armv6l.nix
else if system == "armv7l-linux" then import ./bootstrap/armv6l.nix
else if system == "armv7l-linux" then import ./bootstrap/armv7l.nix
else if system == "mips64el-linux" then import ./bootstrap/loongson2f.nix
else abort "unsupported platform for the pure Linux stdenv";
@ -42,10 +42,9 @@ rec {
builder = bootstrapFiles.busybox;
args =
if system == "armv5tel-linux" || system == "armv6l-linux"
args = if system == "armv5tel-linux" || system == "armv6l-linux"
|| system == "armv7l-linux"
then [ ./scripts/unpack-bootstrap-tools-arm.sh ]
then [ "ash" "-e" ./scripts/unpack-bootstrap-tools-arm.sh ]
else [ "ash" "-e" ./scripts/unpack-bootstrap-tools.sh ];
tarball = bootstrapFiles.bootstrapTools;

View File

@ -1,10 +1,13 @@
{system ? builtins.currentSystem}:
let buildFor = toolsArch: (
let
pkgsFun = import ../../top-level/all-packages.nix;
pkgsNoParams = pkgsFun {};
raspberrypiCrossSystem = {
crossSystem = {
crossSystem = rec {
config = "armv6l-unknown-linux-gnueabi";
bigEndian = false;
arch = "arm";
@ -14,51 +17,33 @@ let
libc = "glibc";
platform = pkgsNoParams.platforms.raspberrypi;
openssl.system = "linux-generic32";
gcc = {
arch = "armv6";
fpu = "vfp";
float = "hard";
};
inherit (platform) gcc;
};
};
raspberrypiCrossSystemUclibc = {
crossSystem = {
config = "armv6l-unknown-linux-gnueabi";
beagleboneCrossSystem = {
crossSystem = rec {
config = "armv7l-unknown-linux-gnueabi";
bigEndian = false;
arch = "arm";
float = "hard";
fpu = "vfp";
fpu = "vfpv3-d16";
withTLS = true;
libc = "uclibc";
platform = pkgsNoParams.platforms.raspberrypi;
libc = "glibc";
platform = pkgsNoParams.platforms.beaglebone;
openssl.system = "linux-generic32";
gcc = {
arch = "armv6";
fpu = "vfp";
float = "hard";
};
uclibc.extraConfig = ''
ARCH_WANTS_BIG_ENDIAN n
ARCH_BIG_ENDIAN n
ARCH_WANTS_LITTLE_ENDIAN y
ARCH_LITTLE_ENDIAN y
'';
inherit (platform) gcc;
};
};
selectedCrossSystem =
if toolsArch == "armv6l" then raspberrypiCrossSystem else
if toolsArch == "armv7l" then beagleboneCrossSystem else null;
pkgsuclibc = pkgsFun ({inherit system;} // raspberrypiCrossSystemUclibc);
pkgs = pkgsFun ({inherit system;} // raspberrypiCrossSystem);
pkgs = pkgsFun ({inherit system;} // selectedCrossSystem);
inherit (pkgs) stdenv nukeReferences cpio binutilsCross;
# We want coreutils without ACL support.
coreutils_base = pkgs.coreutils.override (args: {
aclSupport = false;
});
coreutils_ = coreutils_base.crossDrv;
glibc = pkgs.libcCross;
bash = pkgs.bash.crossDrv;
findutils = pkgs.findutils.crossDrv;
@ -72,9 +57,8 @@ let
gnumake = pkgs.gnumake.crossDrv;
patch = pkgs.patch.crossDrv;
patchelf = pkgs.patchelf.crossDrv;
replace = pkgs.replace.crossDrv;
gcc = pkgs.gcc;
gmp = pkgs.gmp.crossDrv;
gcc = pkgs.gcc.cc.crossDrv;
gmpxx = pkgs.gmpxx.crossDrv;
mpfr = pkgs.mpfr.crossDrv;
ppl = pkgs.ppl.crossDrv;
cloogppl = pkgs.cloogppl.crossDrv;
@ -83,26 +67,39 @@ let
isl = pkgs.isl.crossDrv;
libmpc = pkgs.libmpc.crossDrv;
binutils = pkgs.binutils.crossDrv;
klibc = pkgs.linuxPackages.klibc.crossDrv;
libelf = pkgs.libelf.crossDrv;
in
rec {
curlStatic = import <nixpkgs/pkgs/tools/networking/curl> {
stdenv = pkgsuclibc.stdenv;
inherit (pkgsuclibc) fetchurl;
# We want coreutils without ACL support.
coreutilsMinimal = (pkgs.coreutils.override (args: {
aclSupport = false;
})).crossDrv;
curlMinimal = (pkgs.curl.override {
zlibSupport = false;
sslSupport = false;
linkStatic = true;
};
bzip2Static = import <nixpkgs/pkgs/tools/compression/bzip2> {
stdenv = pkgsuclibc.stdenv;
inherit (pkgsuclibc) fetchurl;
linkStatic = true;
};
scpSupport = false;
}).crossDrv;
busyboxMinimal = (pkgs.busybox.override {
# TBD: uClibc is broken.
# useUclibc = true;
enableStatic = true;
enableMinimal = true;
extraConfig = ''
CONFIG_ASH y
CONFIG_ASH_BUILTIN_ECHO y
CONFIG_ASH_BUILTIN_TEST y
CONFIG_ASH_OPTIMIZE_FOR_SIZE y
CONFIG_MKDIR y
CONFIG_TAR y
CONFIG_UNXZ y
'';
}).crossDrv;
inherit pkgs;
build =
@ -128,6 +125,8 @@ rec {
cp -d ${glibc}/lib/libpthread*.so* $out/lib
cp -d ${glibc}/lib/libnsl*.so* $out/lib
cp -d ${glibc}/lib/libutil*.so* $out/lib
cp -d ${glibc}/lib/libnss*.so* $out/lib
cp -d ${glibc}/lib/libresolv*.so* $out/lib
cp -d ${glibc}/lib/crt?.o $out/lib
cp -rL ${glibc}/include $out
@ -140,7 +139,7 @@ rec {
mv $out/include $out/include-glibc
# Copy coreutils, bash, etc.
cp ${coreutils_}/bin/* $out/bin
cp ${coreutilsMinimal}/bin/* $out/bin
(cd $out/bin && rm vdir dir sha*sum pinky factor pathchk runcon shuf who whoami shred users)
cp ${bash}/bin/bash $out/bin
@ -148,7 +147,7 @@ rec {
cp ${findutils}/bin/xargs $out/bin
cp -d ${diffutils}/bin/* $out/bin
cp -d ${gnused}/bin/* $out/bin
cp -d ${gnugrep}/bin/* $out/bin
cp -d ${gnugrep}/bin/grep $out/bin
cp ${gawk}/bin/gawk $out/bin
cp -d ${gawk}/bin/awk $out/bin
cp ${gnutar}/bin/tar $out/bin
@ -157,17 +156,18 @@ rec {
cp -d ${gnumake}/bin/* $out/bin
cp -d ${patch}/bin/* $out/bin
cp ${patchelf}/bin/* $out/bin
cp ${replace}/bin/* $out/bin
cp ${curlMinimal}/bin/curl $out/bin
cp -d ${curlMinimal}/lib/libcurl* $out/lib
cp -d ${gnugrep.pcre.crossDrv}/lib/libpcre*.so* $out/lib # needed by grep
# Copy what we need of GCC.
cp -d ${gcc.cc.crossDrv}/bin/gcc $out/bin
cp -d ${gcc.cc.crossDrv}/bin/cpp $out/bin
cp -d ${gcc.cc.crossDrv}/bin/g++ $out/bin
cp -d ${gcc.cc.crossDrv}/lib*/libgcc_s.so* $out/lib
cp -d ${gcc.cc.crossDrv}/lib*/libstdc++.so* $out/lib
cp -rd ${gcc.cc.crossDrv}/lib/gcc $out/lib
cp -d ${gcc}/bin/gcc $out/bin
cp -d ${gcc}/bin/cpp $out/bin
cp -d ${gcc}/bin/g++ $out/bin
cp -d ${gcc}/lib*/libgcc_s.so* $out/lib
cp -d ${gcc}/lib*/libstdc++.so* $out/lib
cp -rd ${gcc}/lib/gcc $out/lib
chmod -R u+w $out/lib
rm -f $out/lib/gcc/*/*/include*/linux
rm -f $out/lib/gcc/*/*/include*/sound
@ -175,26 +175,31 @@ rec {
rm -f $out/lib/gcc/*/*/include-fixed/asm
rm -rf $out/lib/gcc/*/*/plugin
#rm -f $out/lib/gcc/*/*/*.a
cp -rd ${gcc.cc.crossDrv}/libexec/* $out/libexec
cp -rd ${gcc}/libexec/* $out/libexec
chmod -R u+w $out/libexec
rm -rf $out/libexec/gcc/*/*/plugin
mkdir $out/include
cp -rd ${gcc.cc.crossDrv}/include/c++ $out/include
cp -rd ${gcc}/include/c++ $out/include
chmod -R u+w $out/include
rm -rf $out/include/c++/*/ext/pb_ds
rm -rf $out/include/c++/*/ext/parallel
cp -d ${gmp}/lib/libgmp*.so* $out/lib
cp -d ${gmpxx}/lib/libgmp*.so* $out/lib
cp -d ${mpfr}/lib/libmpfr*.so* $out/lib
cp -d ${cloogppl}/lib/libcloog*.so* $out/lib
cp -d ${cloog}/lib/libcloog*.so* $out/lib
cp -d ${ppl}/lib/libppl*.so* $out/lib
cp -d ${isl}/lib/libisl*.so* $out/lib
cp -d ${libmpc}/lib/libmpc*.so* $out/lib
cp -d ${zlib}/lib/libz.so* $out/lib
cp -d ${libelf}/lib/libelf.so* $out/lib
# TBD: Why are these needed for cross but not native tools?
cp -d ${cloogppl}/lib/libcloog*.so* $out/lib
cp -d ${cloog}/lib/libcloog*.so* $out/lib
cp -d ${isl}/lib/libisl*.so* $out/lib
# Copy binutils.
for i in as ld ar ranlib nm strip readelf objdump; do
cp ${binutils}/bin/$i $out/bin
done
cp -d ${binutils}/lib/lib*.so* $out/lib
chmod -R u+w $out
@ -209,26 +214,16 @@ rec {
nuke-refs $out/bin/*
nuke-refs $out/lib/*
nuke-refs $out/libexec/gcc/*/*/*
nuke-refs $out/libexec/gcc/*/*/*/*
mkdir $out/.pack
mv $out/* $out/.pack
mv $out/.pack $out/pack
mkdir $out/on-server
(cd $out/pack && (find | cpio -o -H newc)) | bzip2 > $out/on-server/bootstrap-tools.cpio.bz2
mkdir $out/in-nixpkgs
cp ${klibc}/lib/klibc/bin.static/sh $out/in-nixpkgs
cp ${klibc}/lib/klibc/bin.static/cpio $out/in-nixpkgs
cp ${klibc}/lib/klibc/bin.static/mkdir $out/in-nixpkgs
cp ${klibc}/lib/klibc/bin.static/ln $out/in-nixpkgs
cp ${curlStatic.crossDrv}/bin/curl $out/in-nixpkgs
cp ${bzip2Static.crossDrv}/bin/bzip2 $out/in-nixpkgs
chmod u+w $out/in-nixpkgs/*
$crossConfig-strip $out/in-nixpkgs/*
nuke-refs $out/in-nixpkgs/*
bzip2 $out/in-nixpkgs/curl
tar cvfJ $out/on-server/bootstrap-tools.tar.xz -C $out/pack .
cp ${busyboxMinimal}/bin/busybox $out/on-server
chmod u+w $out/on-server/busybox
nuke-refs $out/on-server/busybox
''; # */
# The result should not contain any references (store paths) so
@ -237,33 +232,9 @@ rec {
allowedReferences = [];
};
unpack =
stdenv.mkDerivation {
name = "unpack";
buildCommand = ''
${build}/in-nixpkgs/mkdir $out
${build}/in-nixpkgs/bzip2 -d < ${build}/on-server/bootstrap-tools.cpio.bz2 | (cd $out && ${build}/in-nixpkgs/cpio -V -i)
for i in $out/bin/* $out/libexec/gcc/*/*/*; do
echo patching $i
if ! test -L $i; then
LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.2 \
$out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.2 --set-rpath $out/lib --force-rpath $i
fi
done
# Fix the libc linker script.
for i in $out/lib/libc.so; do
cat $i | sed "s|/nix/store/e*-[^/]*/|$out/|g" > $i.tmp
mv $i.tmp $i
done
''; # " */
allowedReferences = ["out"];
};
}
); in {
armv6l = buildFor "armv6l";
armv7l = buildFor "armv7l";
}

View File

@ -1,36 +1,38 @@
set -e
# TBD: It should be OK to mv this file to unpack-bootstrap-tools.sh,
# except for a mass rebuild.
# Unpack the bootstrap tools tarball.
echo Unpacking the bootstrap tools...
$mkdir $out
$bzip2 -d < $tarball | (cd $out && $cpio -V -i)
$builder mkdir $out
< $tarball $builder unxz | $builder tar x -C $out
# Set the ELF interpreter / RPATH in the bootstrap binaries.
echo Patching the bootstrap tools...
if test -f $out/lib/ld.so.?; then
# MIPS case
LD_BINARY=$out/lib/ld.so.?
else
# i686, x86_64 and armv5tel
LD_BINARY=$out/lib/ld-*so.?
fi
# On x86_64, ld-linux-x86-64.so.2 barfs on patchelf'ed programs. So
# use a copy of patchelf.
LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? $out/bin/cp $out/bin/patchelf .
LD_LIBRARY_PATH=$out/lib $LD_BINARY $out/bin/cp $out/bin/patchelf .
for i in $out/bin/* $out/libexec/gcc/*/*/* $out/lib/librt*; do
if test ${i%.la} != $i; then continue; fi
if test ${i%*.so*} != $i; then continue; fi
if ! test -f $i; then continue; fi
if test -L $i; then continue; fi
echo patching $i
LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
$out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
$out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
for i in $out/bin/* $out/libexec/gcc/*/*/*; do
if [ -L "$i" ]; then continue; fi
if [ -z "${i##*/liblto*}" ]; then continue; fi
echo patching "$i"
LD_LIBRARY_PATH=$out/lib $LD_BINARY \
$out/bin/patchelf --set-interpreter $LD_BINARY --set-rpath $out/lib --force-rpath "$i"
done
for i in $out/lib/librt* $out/lib/libcloog* $out/lib/libppl* $out/lib/libgmp*; do
if ! test -f $i; then continue; fi
if test -L $i; then continue; fi
echo patching $i
LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
$out/bin/patchelf --set-rpath $out/lib --force-rpath $i
LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
$out/bin/patchelf --set-rpath $out/lib --force-rpath $i
for i in $out/lib/librt-*.so $out/lib/libpcre*; do
if [ -L "$i" ]; then continue; fi
echo patching "$i"
$out/bin/patchelf --set-rpath $out/lib --force-rpath "$i"
done
# Fix the libc linker script.
@ -44,13 +46,21 @@ mv $out/lib/libpthread.so.tmp $out/lib/libpthread.so
ln -s bash $out/bin/sh
ln -s bzip2 $out/bin/bunzip2
# Mimic the gunzip script as in gzip installations
# Provide a gunzip script.
cat > $out/bin/gunzip <<EOF
#!$out/bin/sh
exec $out/bin/gzip -d "\$@"
EOF
chmod +x $out/bin/gunzip
# fetchurl needs curl.
bzip2 -d < $curl > $out/bin/curl
chmod +x $out/bin/curl
# Provide fgrep/egrep.
echo "#! $out/bin/sh" > $out/bin/egrep
echo "exec $out/bin/grep -E \"\$@\"" >> $out/bin/egrep
echo "#! $out/bin/sh" > $out/bin/fgrep
echo "exec $out/bin/grep -F \"\$@\"" >> $out/bin/fgrep
# Provide xz (actually only xz -d will work).
echo "#! $out/bin/sh" > $out/bin/xz
echo "exec $builder unxz \"\$@\"" >> $out/bin/xz
chmod +x $out/bin/egrep $out/bin/fgrep $out/bin/xz