[OpenPower-Firmware] Building OpenPOWER firmware on NixOS
Hugo Landau
hlandau at devever.net
Sat Nov 11 11:34:49 AEDT 2017
The following documents what it took to build OpenPOWER firmware on
NixOS, mainly for posterity.
**Building natively in nix-shell:** Initially I tried to build the
firmware natively on NixOS. This had a lot of problems because of fixed
paths and shebang lines like #!/usr/bin/perl, since on NixOS the only
binaries with conventional paths are /bin/sh and /usr/bin/env. These
need to be patched to appropriate values before building. There were a
number of other miscellaneous small patches which needed to be made, as
well. Eventually I abandoned this route after some peculiar interactions
with include paths and an #include_next statement in gcc's system header
files when trying to build gcc-ppe42.
**Building using FHS emulation:** This worked, and took much less
effort. Save the following file as e.g. fhs.nix:
{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
name = "fhs-env";
targetPkgs = pkgs: (with pkgs; [
# Build tools.
gcc
binutils
gnumake
flex
bison
git
file
cscope
ctags
python
unzip
wget
bc
texinfo
which
ccache
perl
rsync
cpio
patch
m4
getopt
# Libraries.
zlib
expat
libxslt
openssl.dev
perlPackages.XMLLibXMLSimple
perlPackages.XMLSimple
perlPackages.XMLSAX
libxml2.dev
# Needed for make menuconfig.
ncurses.dev
pkgconfig
]);
profile = ''
# There are some warnings during the build which get turned into
# errors if this isn't set.
export hardeningDisable=all
# This is fixed by nixpkgs 2a036ca1a5e but it isn't in stable yet.
export NIX_CC_WRAPPER_x86_64_unknown_linux_gnu_TARGET_HOST=1
# Perl include path doesn't seem to get set properly.
export PERL5LIB="/usr/lib/perl5/site_perl"
'';
}).env
After cloning op-build and updating the submodules, enter the shell
using `nix-shell fhs.nix`. In the shell, source op-build-env; op-build a
configuration (I used zaius_defconfig); optionally op-build menuconfig
to make adjustments (the only change I made was to enable ccache). Run
op-build -j... to run parallel make.
The following subsidiary repositories need some small patches. These
repositories only get downloaded when you run op-build. It's rather
manual, but I just ran op-build first, patched them manually and ran
op-build again.
- buildroot (checked out at buildroot)
Symptom: Perl can't find XML/Simple.pm.
Cause: PERL5LIB environment variable gets replaced outright by build
system, which causes problems if it's actually necessary to find
Perl packages expected to be present on the system.
Workaround:
In buildroot, apply the following patch:
diff --git a/package/Makefile.in b/package/Makefile.in
index a1a531605..59173db33 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -252,7 +252,7 @@ export PERL=$(shell which perl)
# host-intltool needs libxml-parser-perl, which Buildroot installs in
# $(HOST_DIR)/lib/perl, so we must make sure that the system perl
# finds this perl module by exporting the proper value for PERL5LIB.
-export PERL5LIB=$(HOST_DIR)/lib/perl
+export PERL5LIB:=$(HOST_DIR)/lib/perl:$(PERL5LIB)
TARGET_MAKE_ENV = PATH=$(BR_PATH)
- openpower-ffs (checked out at output/build/host-openpower-ffs-{hash})
Symptom: Error in glibc's <bits/fcntl2.h>
about "invalid use of __builtin_arg_va_pack"
Cause: Conflicting definition of __inline macro in openpower-ffs.
Workaround:
Comment out #define __inline in clib/attribute.h.
(You may need to delete some .o files if you've already partially
built openpower-ffs and you get some linker errors about multiple
definitions of the same function.)
- fakeroot (checked out at output/build/host-fakeroot-{version})
Symptom: "chown: invalid argument" errors.
Cause: See link below.
Workaround:
Apply the patch at
<https://github.com/NixOS/nixpkgs/issues/10496#issuecomment-149893498>
Run "op-build rebuild-host-fakeroot" to rebuild afterwards; the need
to rebuild will not be detected automatically.
More information about the OpenPower-Firmware
mailing list