aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilan Pässler <milan@petabyte.dev>2020-10-10 14:47:56 +0200
committerMilan Pässler <milan@petabyte.dev>2020-10-10 14:47:56 +0200
commit38ab1843819e461543749c8a849a2d876ed6002e (patch)
treeb8bbeab75d019e63b224b766a2bd1ef2bf453b7c
initial commit
-rw-r--r--config.nix7
-rw-r--r--devices/t440p.nix8
-rw-r--r--devices/t60.nix6
-rw-r--r--devices/x1c.nix6
-rw-r--r--devices/x220.nix6
-rw-r--r--devices/x230-fhd.nix9
-rw-r--r--devices/x230.nix6
-rw-r--r--devices/x230t.nix4
-rw-r--r--flake.nix13
-rw-r--r--grub.cfg164
-rw-r--r--pkgs/coreboot-base/default.nix73
-rw-r--r--pkgs/coreboot-base/files.nix66
-rw-r--r--pkgs/coreboot-payload-grub2/default.nix11
-rw-r--r--pkgs/coreboot-payload-tianocore/default.nix78
-rw-r--r--pkgs/coreboot/default.nix3
-rw-r--r--pkgs/overlay.nix7
16 files changed, 467 insertions, 0 deletions
diff --git a/config.nix b/config.nix
new file mode 100644
index 000000000000..738f7b2ba426
--- /dev/null
+++ b/config.nix
@@ -0,0 +1,7 @@
+{
+ CONFIG_PAYLOAD_NONE = "y"; # payload is added later
+ CONFIG_CBFS_SIZE = lib.mkDefault "0x300000";
+ CONFIG_USE_OPTION_TABLE = lib.mkDefault "y";
+ CONFIG_PCIEXP_CLK_PM = lib.mkDefault "y";
+ CONFIG_GENERIC_LINEAR_FRAMEBUFFER = lib.mkDefault "y";
+}
diff --git a/devices/t440p.nix b/devices/t440p.nix
new file mode 100644
index 000000000000..5d3f29e7e68f
--- /dev/null
+++ b/devices/t440p.nix
@@ -0,0 +1,8 @@
+{ ... }:
+
+{
+ CONFIG_VENDOR_LENOVO = "y";
+ CONFIG_BOARD_LENOVO_THINKPAD_T440P = "y";
+
+ # TODO: fetch mrc.bin
+}
diff --git a/devices/t60.nix b/devices/t60.nix
new file mode 100644
index 000000000000..9af80af158ff
--- /dev/null
+++ b/devices/t60.nix
@@ -0,0 +1,6 @@
+{ ... }:
+
+{
+ CONFIG_VENDOR_LENOVO = "y";
+ CONFIG_BOARD_LENOVO_T60 = "y";
+}
diff --git a/devices/x1c.nix b/devices/x1c.nix
new file mode 100644
index 000000000000..c2a3774dadc2
--- /dev/null
+++ b/devices/x1c.nix
@@ -0,0 +1,6 @@
+{ ... }:
+
+{
+ CONFIG_VENDOR_LENOVO = "y";
+ CONFIG_BOARD_LENOVO_X1_CARBON_GEN1 = "y";
+}
diff --git a/devices/x220.nix b/devices/x220.nix
new file mode 100644
index 000000000000..4db72bcbb94d
--- /dev/null
+++ b/devices/x220.nix
@@ -0,0 +1,6 @@
+{ ... }:
+
+{
+ CONFIG_VENDOR_LENOVO = "y";
+ CONFIG_BOARD_LENOVO_X220 = "y";
+}
diff --git a/devices/x230-fhd.nix b/devices/x230-fhd.nix
new file mode 100644
index 000000000000..bb198aba4826
--- /dev/null
+++ b/devices/x230-fhd.nix
@@ -0,0 +1,9 @@
+{ ... }:
+
+{
+ imports = [
+ ./x230.nix
+ ];
+
+ # TODO: modify vbt to hide LVDS
+}
diff --git a/devices/x230.nix b/devices/x230.nix
new file mode 100644
index 000000000000..5563f11fdbad
--- /dev/null
+++ b/devices/x230.nix
@@ -0,0 +1,6 @@
+{ ... }:
+
+{
+ CONFIG_VENDOR_LENOVO = "y";
+ CONFIG_BOARD_LENOVO_X230 = "y";
+}
diff --git a/devices/x230t.nix b/devices/x230t.nix
new file mode 100644
index 000000000000..884b314b96b3
--- /dev/null
+++ b/devices/x230t.nix
@@ -0,0 +1,4 @@
+{
+ CONFIG_VENDOR_LENOVO = "y";
+ CONFIG_BOARD_LENOVO_X230T = "y";
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 000000000000..c1e63c7018fd
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,13 @@
+{
+ inputs.nixpkgs = {
+ type = "github";
+ owner = "nixos";
+ repo = "nixpkgs";
+ ref = "master";
+ };
+
+ description = "A collections of derivations for coreboot and payloads";
+ outputs = { self, nixpkgs }: {
+ packages = (import ./pkgs/overlay.nix) nixpkgs;
+ };
+}
diff --git a/grub.cfg b/grub.cfg
new file mode 100644
index 000000000000..b0abc4da8319
--- /dev/null
+++ b/grub.cfg
@@ -0,0 +1,164 @@
+function try_user_config {
+ set root="${1}"
+ for dir in boot grub grub2 boot/grub boot/grub2; do
+ for name in libreboot_ autoboot_ librecore_ coreboot_ ''; do
+ if [ -f /"${dir}"/"${name}"grub.cfg ]; then
+ unset superusers
+ configfile /"${dir}"/"${name}"grub.cfg
+ fi
+ done
+ done
+}
+
+function search_grub {
+ for i in 0 1; do
+ # raw devices
+ try_user_config "(${1}${i})"
+ for part in 1 2 3 4 5; do
+ # MBR/GPT partitions
+ try_user_config "(${1}${i},${part})"
+ done
+ done
+}
+
+function try_isolinux_config {
+ set root="${1}"
+ for dir in '' /boot; do
+ if [ -f "${dir}"/isolinux/isolinux.cfg ]; then
+ syslinux_configfile -i "${dir}"/isolinux/isolinux.cfg
+ elif [ -f "${dir}"/syslinux/syslinux.cfg ]; then
+ syslinux_configfile -s "${dir}"/syslinux/syslinux.cfg
+ fi
+ done
+}
+
+function search_isolinux {
+ for i in 0 1; do
+ # raw devices
+ try_isolinux_config "(${1}${i})"
+ for part in 1 2 3 4 5; do
+ # MBR/GPT partitions
+ try_isolinux_config "(${1}${i},${part})"
+ done
+ done
+}
+
+function load_video {
+ if [ x$feature_all_video_module = xy ]; then
+ insmod all_video
+ else
+ insmod efi_gop
+ insmod efi_uga
+ insmod ieee1275_fb
+ insmod vbe
+ insmod vga
+ insmod video_bochs
+ insmod video_cirrus
+ fi
+}
+
+
+if loadfont (cbfsdisk)/font.pf2 ; then
+ set gfxmode=auto
+ load_video
+ insmod gfxterm
+ set locale_dir=$prefix/locale
+ set lang=en_US
+ insmod gettext
+fi
+
+terminal_input console
+terminal_output gfxterm
+gfxpayload=keep
+
+if [ x$feature_timeout_style = xy ] ; then
+ set timeout_style=menu
+ set timeout=1
+# Fallback normal timeout code in case the timeout_style feature is
+# unavailable.
+else
+ set timeout=5
+fi
+
+insmod png
+if background_image (cbfsdisk)/background.png; then
+ true
+fi
+
+#Scan for OS on internal HDD
+insmod regexp
+insmod ahci
+insmod part_msdos
+for x in (ahci*,*) ; do
+ if [ -f "$x/grub/grub.cfg" ] ; then
+ menuentry "Load Config from $x" $x {
+ root=$2
+ configfile /grub/grub.cfg
+ }
+ fi
+ if [ -f "$x/boot/grub/grub.cfg" ] ; then
+ menuentry "Load Config from $x" $x {
+ root=$2
+ configfile /boot/grub/grub.cfg
+ }
+ fi
+done
+
+for x in (usb*,*) ; do
+ if [ -f "$x/grub/grub.cfg" ] ; then
+ menuentry "Load Config from $x" $x {
+ root=$2
+ configfile /grub/grub.cfg
+ }
+ fi
+ if [ -f "$x/boot/grub/grub.cfg" ] ; then
+ menuentry "Load Config from $x" $x {
+ root=$2
+ configfile /boot/grub/grub.cfg
+ }
+ fi
+done
+
+
+menuentry 'Search ISOLINUX menu (AHCI) [a]' --hotkey='a' {
+ search_isolinux ahci
+}
+
+menuentry 'Search ISOLINUX menu (USB) [u]' --hotkey='u' {
+ search_isolinux usb
+}
+
+menuentry 'Search ISOLINUX menu (CD/DVD) [d]' --hotkey='d' {
+ insmod ata
+ for dev in ata0 ata1 ata2 ata3 ahci1; do
+ try_isolinux_config "(${dev})"
+ done
+}
+
+menuentry 'Search for GRUB2 configuration on external media [s]' --hotkey='s' {
+ search_grub usb
+}
+
+menuentry 'nvramcui' {
+ chainloader (cbfsdisk)/img/nvramcui
+}
+
+menuentry 'coreinfo' {
+ chainloader (cbfsdisk)/img/coreinfo
+}
+
+menuentry 'Memtest86+' {
+ chainloader (cbfsdisk)/img/memtest
+}
+
+menuentry 'tint' {
+ chainloader (cbfsdisk)/img/tint
+}
+
+menuentry 'Poweroff [p]' --hotkey='p' {
+ halt
+}
+
+menuentry 'Reboot [r]' --hotkey='r' {
+ reboot
+}
diff --git a/pkgs/coreboot-base/default.nix b/pkgs/coreboot-base/default.nix
new file mode 100644
index 000000000000..3b8fe28f29be
--- /dev/null
+++ b/pkgs/coreboot-base/default.nix
@@ -0,0 +1,73 @@
+{ fetchgit
+, fetchurl
+, stdenv
+, m4
+, flex
+, bison
+, zlib
+, gnat
+, curl
+, grub-coreboot
+, tianocore-coreboot
+, perl
+, writeText
+, config ? {}
+}:
+
+let
+ version = "4.12";
+ src = fetchgit {
+ url = "https://review.coreboot.org/coreboot.git";
+ rev = "${version}";
+ fetchSubmodules = true;
+ sha256 = "1l140zbvn6pkbrr55lymhi4lycimhpy8xgm45shl4zv6a9vjd66z";
+ };
+
+ toolchain = stdenv.mkDerivation rec {
+ pname = "coreboot-toolchain";
+ inherit version src;
+ nativeBuildInputs = [
+ curl
+ stdenv
+ m4
+ flex
+ bison
+ zlib
+ gnat
+ ];
+ buildPhase = ''
+ mkdir -p util/crossgcc/tarballs
+ ${}
+ NIX_HARDENING_ENABLE="$\{NIX_HARDENING_ENABLE/ format/\}" make crossgcc-i386 CPUS=$NIX_BUILD_CORES
+ '';
+ installPhase = ''
+ cp -r util/crossgcc $out
+ '';
+ };
+
+in stdenv.mkDerivation rec {
+ pname = "coreboot";
+ inherit version src;
+ configurePhase = let
+ filteredConfig = lib.filterAttrs (n: v: v != null) config;
+ lines = lib.mapAttrsToList (name: value: "${name}=${value}") filteredConfig;
+ configFile = writeText "config" (concatStringsSept "\n" lines);
+ in ''
+ cp ${configFile} .config
+ make olddefconfig
+ '';
+ buildPhase = ''
+ rm -rf util/crossgcc
+ cp -r ${toolchain} util/crossgcc
+ chmod u+rwX -R util/crossgcc
+ patchShebangs util/xcompile/xcompile
+ make
+ '';
+ installPhase = ''
+ mkdir -p $out
+ cp build/coreboot.rom $out
+ '';
+ passthru = {
+ inherit toolchain configfile;
+ };
+}
diff --git a/pkgs/coreboot-base/files.nix b/pkgs/coreboot-base/files.nix
new file mode 100644
index 000000000000..3e3e3a7f92b6
--- /dev/null
+++ b/pkgs/coreboot-base/files.nix
@@ -0,0 +1,66 @@
+{ fetchurl }:
+
+# from util/crossgcc/buildgcc
+[
+ (rec {
+ version = "6.1.2";
+ archive = fetchurl {
+ sha256 = "04hrwahdxyqdik559604r7wrj9ffklwvipgfxgj4ys4skbl6bdc7";
+ url = "mirror://gnu/gmp/gmp-${version}.tar.xz";
+ };
+ })
+
+ (rec {
+ version = "4.0.2";
+ name = "mpfr-${version}.tar.xz";
+ archive = fetchurl {
+ sha256 = "12m3amcavhpqygc499s3fzqlb8f2j2rr7fkqsm10xbjfc04fffqx";
+ url = "mirror://gnu/mpfr/${name}";
+ };
+ })
+
+ (rec {
+ version = "1.1.0";
+ name = "mpc-${version}.tar.gz";
+ archive = fetchurl {
+ sha256 = "0biwnhjm3rx3hc0rfpvyniky4lpzsvdcwhmcn7f0h4iw2hwcb1b9";
+ url = "mirror://gnu/mpc/${name}";
+ };
+ })
+
+ (rec {
+ version = "8.3.0";
+ name = "gcc-${version}.tar.xz";
+ archive = fetchurl {
+ sha256 = "0b3xv411xhlnjmin2979nxcbnidgvzqdf4nbhix99x60dkzavfk4";
+ url = "mirror://gnu/gcc/${name}";
+ };
+ })
+
+ (rec {
+ version = "2.33.1";
+ name = "binutils-${version}.tar.xz";
+ archive = fetchurl {
+ sha256 = "1grcf8jaw3i0bk6f9xfzxw3qfgmn6fgkr108isdkbh1y3hnzqrmb";
+ url = "mirror://gnu/binutils/${name}";
+ };
+ })
+
+ (rec {
+ version = "20200110";
+ name = "apica-unix2-${version}.tar.gz";
+ archive = fetchurl {
+ sha256 = "1hb4g6r7w8s4bhlkk36fmb4qxghnrwvad7f18cpn6zz0b4sjs7za";
+ url = "https://acpica.org/sites/acpica/files/${name}";
+ };
+ })
+
+ (rec {
+ version = "2.14.02";
+ name = "nasm-${version}.tar.bz2";
+ archive = fetchurl {
+ sha256 = "1g409sr1kj7v1089s9kv0i4azvddkcwcypnbakfryyi71b3jdz9l";
+ url = "https://www.nasm.us/pub/nasm/releasebuilds/${version}.tar.bz2";
+ };
+ })
+]
diff --git a/pkgs/coreboot-payload-grub2/default.nix b/pkgs/coreboot-payload-grub2/default.nix
new file mode 100644
index 000000000000..0d90ef805fd5
--- /dev/null
+++ b/pkgs/coreboot-payload-grub2/default.nix
@@ -0,0 +1,11 @@
+{ grub2
+, lib
+, extraPayloadModules ? [ "png" "gfxmenu" "gfxterm_background" "ls" "cat" "echo" "linux" "xfs" "bsd" ]
+}:
+
+grub2.overrideAttrs (oA: {
+ name = "coreboot-payload-${oA.name}";
+ configureFlags = oA.configureFlags ++ [ "--with-platform=coreboot" "--enable-boot-time" ];
+ postBuild = "make -j $NIX_BUILD_CORES default_payload.elf EXTRA_PAYLOAD_MODULES=\"${lib.concatStringsSep " " extraPayloadModules}\"";
+ installPhase = "install -D default_payload.elf -t $out";
+})
diff --git a/pkgs/coreboot-payload-tianocore/default.nix b/pkgs/coreboot-payload-tianocore/default.nix
new file mode 100644
index 000000000000..8d9c29dc5329
--- /dev/null
+++ b/pkgs/coreboot-payload-tianocore/default.nix
@@ -0,0 +1,78 @@
+{ fetchFromGitHub, python2, stdenv, libuuid, bc, utillinux, nasm, iasl, seabios }:
+
+# we can not override the source in edk2, so we had to copy the entire thing
+
+let
+ src = fetchFromGitHub {
+ owner = "MrChromebox";
+ repo = "edk2";
+ rev = "860a8d95c2ee89c9916d6e11230f246afa1cd629";
+ sha256 = "1bykw3lzfjl6idca37i736mwpqv60haczp7davhgqlmlb3nw6y3s";
+ fetchSubmodules = true;
+ };
+
+ version = "unstable";
+
+ pythonEnv = python2.withPackages (ps: [ps.tkinter]);
+
+ toolchain = stdenv.mkDerivation {
+ pname = "edk2-coreboot";
+
+ inherit version src;
+
+ buildInputs = [ libuuid pythonEnv ];
+
+ makeFlags = [ "-C BaseTools" ];
+
+ NIX_CFLAGS_COMPILE = "-Wno-return-type -Wno-error=stringop-truncation";
+
+ hardeningDisable = [ "format" "fortify" ];
+
+ installPhase = ''
+ mkdir -vp $out
+ mv -v BaseTools $out
+ mv -v edksetup.sh $out
+ '';
+
+ enableParallelBuilding = true;
+ };
+
+in
+ stdenv.mkDerivation {
+ pname = "coreboot-payload-tianocore";
+ inherit version src;
+
+ buildInputs = [ bc pythonEnv utillinux nasm iasl ];
+
+ prePatch = ''
+ rm -rf BaseTools
+ ln -sv ${toolchain}/BaseTools BaseTools
+ '';
+
+ configurePhase = ''
+ runHook preConfigure
+ export WORKSPACE="$PWD"
+ . ${toolchain}/edksetup.sh BaseTools
+ runHook postConfigure
+ '';
+
+ buildPhase = ''
+ runHook preBuild
+ build -a X64 -a IA32 -b RELEASE -t GCC5 -p CorebootPayloadPkg/CorebootPayloadPkgIa32X64.dsc -n $NIX_BUILD_CORES -D CSM_ENABLE
+ runHook postBuild
+ '';
+
+ installPhase = ''
+ runHook preInstall
+ mv -v Build/*/* $out
+ runHook postInstall
+ '';
+
+ hardeningDisable = [ "format" "stackprotector" "pic" "fortify" ];
+
+ postPatch = ''
+ cp ${seabios}/Csm16.bin OvmfPkg/Csm/Csm16/Csm16.bin
+ '';
+
+ dontPatchELF = true;
+ }
diff --git a/pkgs/coreboot/default.nix b/pkgs/coreboot/default.nix
new file mode 100644
index 000000000000..abe6548fd299
--- /dev/null
+++ b/pkgs/coreboot/default.nix
@@ -0,0 +1,3 @@
+
+ # ${tianocore-coreboot}/FV/UEFIPAYLOAD.fd
+ # ${grub-coreboot}/default_payload.elf
diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix
new file mode 100644
index 000000000000..7fcbfb43ac6c
--- /dev/null
+++ b/pkgs/overlay.nix
@@ -0,0 +1,7 @@
+final: prev:
+let inherit (final) callPackage;
+in {
+ coreboot-base = callPackage ./coreboot-base {};
+ coreboot-payload-grub2 = callPackage ./coreboot-payload-grub2 {};
+ coreboot-payload-tianocore = callPackage ./coreboot-payload-tianocore {};
+}