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 = { busybox = import <nix/fetchurl.nix> {
# Built from make-bootstrap-tools-crosspi.nix url = https://dl.dropboxusercontent.com/s/4705ffxjrxxqnh2/busybox?dl=0;
# nixpkgs rev eb0422e4c1263a65a9b2b954fe10a1e03d67db3e sha256 = "032maafy4akcdgccpxdxrza29pkcpm81g8kh1hv8bj2rvssly3z2";
url = http://viric.name/tmp/nix/pi/bootstrap-tools.cpio.bz2; executable = true;
sha256 = "1zb27x5h54k51yrvn3sy4wb1qprx8iv2kfbgklxwc0mcxp9b7ccd"; };
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 == "x86_64-linux" then import ./bootstrap/x86_64.nix
else if system == "armv5tel-linux" then import ./bootstrap/armv5tel.nix else if system == "armv5tel-linux" then import ./bootstrap/armv5tel.nix
else if system == "armv6l-linux" then import ./bootstrap/armv6l.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 if system == "mips64el-linux" then import ./bootstrap/loongson2f.nix
else abort "unsupported platform for the pure Linux stdenv"; else abort "unsupported platform for the pure Linux stdenv";
@ -42,10 +42,9 @@ rec {
builder = bootstrapFiles.busybox; builder = bootstrapFiles.busybox;
args = args = if system == "armv5tel-linux" || system == "armv6l-linux"
if system == "armv5tel-linux" || system == "armv6l-linux"
|| system == "armv7l-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 ]; else [ "ash" "-e" ./scripts/unpack-bootstrap-tools.sh ];
tarball = bootstrapFiles.bootstrapTools; tarball = bootstrapFiles.bootstrapTools;

View File

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

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. # Unpack the bootstrap tools tarball.
echo Unpacking the bootstrap tools... echo Unpacking the bootstrap tools...
$mkdir $out $builder mkdir $out
$bzip2 -d < $tarball | (cd $out && $cpio -V -i) < $tarball $builder unxz | $builder tar x -C $out
# Set the ELF interpreter / RPATH in the bootstrap binaries. # Set the ELF interpreter / RPATH in the bootstrap binaries.
echo Patching the bootstrap tools... 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 # On x86_64, ld-linux-x86-64.so.2 barfs on patchelf'ed programs. So
# use a copy of patchelf. # 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 for i in $out/bin/* $out/libexec/gcc/*/*/*; do
if test ${i%.la} != $i; then continue; fi if [ -L "$i" ]; then continue; fi
if test ${i%*.so*} != $i; then continue; fi if [ -z "${i##*/liblto*}" ]; then continue; fi
if ! test -f $i; then continue; fi echo patching "$i"
if test -L $i; then continue; fi LD_LIBRARY_PATH=$out/lib $LD_BINARY \
echo patching $i $out/bin/patchelf --set-interpreter $LD_BINARY --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
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
done done
for i in $out/lib/librt* $out/lib/libcloog* $out/lib/libppl* $out/lib/libgmp*; do
if ! test -f $i; then continue; fi for i in $out/lib/librt-*.so $out/lib/libpcre*; do
if test -L $i; then continue; fi if [ -L "$i" ]; then continue; fi
echo patching $i echo patching "$i"
LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \ $out/bin/patchelf --set-rpath $out/lib --force-rpath "$i"
$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
done done
# Fix the libc linker script. # 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 bash $out/bin/sh
ln -s bzip2 $out/bin/bunzip2 ln -s bzip2 $out/bin/bunzip2
# Mimic the gunzip script as in gzip installations # Provide a gunzip script.
cat > $out/bin/gunzip <<EOF cat > $out/bin/gunzip <<EOF
#!$out/bin/sh #!$out/bin/sh
exec $out/bin/gzip -d "\$@" exec $out/bin/gzip -d "\$@"
EOF EOF
chmod +x $out/bin/gunzip chmod +x $out/bin/gunzip
# fetchurl needs curl. # Provide fgrep/egrep.
bzip2 -d < $curl > $out/bin/curl echo "#! $out/bin/sh" > $out/bin/egrep
chmod +x $out/bin/curl 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