gnu: libmad: Add comment justifying the 'install-pkg-config phase.
[jackhill/guix/guix.git] / gnu / packages / bootloaders.scm
index 9e9d4c3..88abe29 100644 (file)
@@ -2,16 +2,19 @@
 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2015, 2018 Mark H Weaver <mhw@netris.org>
 ;;; Copyright © 2015 Leo Famulari <leo@famulari.name>
-;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2016, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
 ;;; Copyright © 2016, 2017, 2018 Marius Bakke <mbakke@fastmail.com>
 ;;; Copyright © 2016, 2017 Danny Milosavljevic <dannym@scratchpost.org>
 ;;; Copyright © 2016, 2017 David Craven <david@craven.ch>
-;;; Copyright © 2017, 2018 Efraim Flashner <efraim@flashner.co.il>
-;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
+;;; Copyright © 2017, 2018, 2020 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2018, 2019, 2020, 2021 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2019 nee <nee@cock.li>
 ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2020 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
-;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2018, 2019, 2020 Vagrant Cascadian <vagrant@debian.org>
+;;; Copyright © 2020 Pierre Langlois <pierre.langlois@gmx.com>
+;;; Copyright © 2021 Vincent Legoll <vincent.legoll@gmail.com>
+;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -94,7 +97,9 @@
                "0zgp5m3hmc9jh8wpjx6czzkh5id2y8n1k823x2mjvm2sk6b28ag5"))
              (patches (search-patches
                        "grub-efi-fat-serial-number.patch"
-                       "grub-verifiers-Blocklist-fallout-cleanup.patch"))))
+                       "grub-setup-root.patch"
+                       "grub-verifiers-Blocklist-fallout-cleanup.patch"
+                       "grub-cross-system-i686.patch"))))
     (build-system gnu-build-system)
     (arguments
      `(#:configure-flags
                      ;; determine the root file system when it's a RAID
                      ;; device.  Failing to do that, 'grub-probe' silently
                      ;; fails if 'mdadm' is not in $PATH.
-                     (substitute* "grub-core/osdep/linux/getroot.c"
-                       (("argv\\[0\\] = \"mdadm\"")
-                        (string-append "argv[0] = \""
-                                       (assoc-ref inputs "mdadm")
-                                       "/sbin/mdadm\"")))
+                     (when (assoc-ref inputs "mdadm")
+                       (substitute* "grub-core/osdep/linux/getroot.c"
+                         (("argv\\[0\\] = \"mdadm\"")
+                          (string-append "argv[0] = \""
+                                         (assoc-ref inputs "mdadm")
+                                         "/sbin/mdadm\""))))
 
                      ;; Make the font visible.
                      (copy-file (assoc-ref (or native-inputs inputs)
                         (string-append (assoc-ref inputs "console-setup")
                                        "/bin/ckbcomp ")))
                      #t))
+                  (add-after 'unpack 'set-freetype-variables
+                    ;; These variables need to be set to the native versions
+                    ;; of the dependencies because they are used to build
+                    ;; programs which are executed during build time.
+                    (lambda* (#:key native-inputs #:allow-other-keys)
+                      (when (assoc-ref native-inputs "freetype")
+                        (let ((freetype (assoc-ref native-inputs "freetype")))
+                          (setenv "BUILD_FREETYPE_LIBS"
+                                  (string-append "-L" freetype
+                                                 "/lib -lfreetype"))
+                          (setenv "BUILD_FREETYPE_CFLAGS"
+                                  (string-append "-I" freetype
+                                                 "/include/freetype2"))))
+                     #t))
                   (add-before 'check 'disable-flaky-test
                     (lambda _
                       ;; This test is unreliable. For more information, see:
                         (("test_unset grub_func_test")
                           "test_unset"))
                       #t)))
-       ;; Disable tests on ARM and AARCH64 platforms.
-       #:tests? ,(not (any (cute string-prefix? <> (or (%current-target-system)
-                                                       (%current-system)))
-                           '("arm" "aarch64")))))
+       ;; Disable tests on ARM and AARCH64 platforms or when cross-compiling.
+       #:tests? ,(not (or (any (cute string-prefix? <> (or (%current-target-system)
+                                                           (%current-system)))
+                               '("arm" "aarch64"))
+                          (%current-target-system)))))
     (inputs
      `(("gettext" ,gettext-minimal)
 
        ("flex" ,flex)
        ("texinfo" ,texinfo)
        ("help2man" ,help2man)
+       ("freetype" ,freetype)   ; native version needed for build-grub-mkfont
 
        ;; XXX: When building GRUB 2.02 on 32-bit x86, we need a binutils
        ;; capable of assembling 64-bit instructions.  However, our default
@@ -238,21 +260,25 @@ menu to select one of the installed operating systems.")
      (fold alist-delete (package-native-inputs grub)
            '("help2man" "texinfo" "parted" "qemu" "xorriso")))
     (arguments
-     `(#:configure-flags (list "PYTHON=true")
-       #:phases (modify-phases %standard-phases
-                  (add-after 'unpack 'patch-stuff
-                   (lambda* (#:key native-inputs inputs #:allow-other-keys)
-                     (substitute* "grub-core/Makefile.in"
-                       (("/bin/sh") (which "sh")))
+     (substitute-keyword-arguments (package-arguments grub)
+       ((#:configure-flags _ ''())
+        '(list "PYTHON=true"))
+       ((#:tests? _ #t)
+        #f)
+       ((#:phases phases '%standard-phases)
+        `(modify-phases ,phases
+           (replace 'patch-stuff
+             (lambda* (#:key native-inputs inputs #:allow-other-keys)
+               (substitute* "grub-core/Makefile.in"
+                 (("/bin/sh") (which "sh")))
 
-                     ;; Make the font visible.
-                     (copy-file (assoc-ref (or native-inputs inputs)
-                                           "unifont")
-                                "unifont.bdf.gz")
-                     (system* "gunzip" "unifont.bdf.gz")
+               ;; Make the font visible.
+               (copy-file (assoc-ref (or native-inputs inputs)
+                                     "unifont")
+                          "unifont.bdf.gz")
+               (system* "gunzip" "unifont.bdf.gz")
 
-                     #t)))
-       #:tests? #f))))
+               #t))))))))
 
 (define-public grub-efi
   (package
@@ -400,7 +426,7 @@ menu to select one of the installed operating systems.")
 (define-public dtc
   (package
     (name "dtc")
-    (version "1.5.1")
+    (version "1.6.0")
     (source (origin
               (method url-fetch)
               (uri (string-append
@@ -408,7 +434,7 @@ menu to select one of the installed operating systems.")
                     "dtc-" version ".tar.xz"))
               (sha256
                (base32
-                "07q3mdsvl4smbiakriq3hnsyyd0q344lsm306q0kgz4hjq1p82v6"))))
+                "0bf8801z6fpd1gz9mxd5pqqj8nq101x393cyw8rpkc712w13nl0h"))))
     (build-system gnu-build-system)
     (native-inputs
      `(("bison" ,bison)
@@ -421,7 +447,7 @@ menu to select one of the installed operating systems.")
      `(("python" ,python)))
     (arguments
      `(#:make-flags
-       (list "CC=gcc"
+       (list (string-append "CC=" ,(cc-for-target))
 
              ;; /bin/fdt{get,overlay,put} need help finding libfdt.so.1.
              (string-append "LDFLAGS=-Wl,-rpath="
@@ -432,6 +458,15 @@ menu to select one of the installed operating systems.")
              "INSTALL=install")
        #:phases
        (modify-phases %standard-phases
+         (add-after 'unpack 'patch-pkg-config
+           (lambda _
+             (substitute* '("Makefile"
+                            "tests/run_tests.sh")
+               (("pkg-config")
+                (or (which "pkg-config")
+                    (string-append ,(%current-target-system)
+                                   "-pkg-config"))))
+             #t))
          (delete 'configure))))         ; no configure script
     (home-page "https://www.devicetree.org")
     (synopsis "Compiles device tree source files")
@@ -443,7 +478,7 @@ tree binary files.  These are board description files used by Linux and BSD.")
 (define u-boot
   (package
     (name "u-boot")
-    (version "2020.04")
+    (version "2020.10")
     (source (origin
               (method url-fetch)
               (uri (string-append
@@ -451,7 +486,7 @@ tree binary files.  These are board description files used by Linux and BSD.")
                     "u-boot-" version ".tar.bz2"))
               (sha256
                (base32
-                "0wjkasnz87q86hx93inspdjfjsinmxi87bcvj30c773x0fpjlwzy"))))
+                "08m6f1bh4pdcqbxf983qdb66ccd5vak5cbzc114yf3jwq2yinj0d"))))
     (native-inputs
      `(("bc" ,bc)
        ("bison" ,bison)
@@ -462,7 +497,6 @@ tree binary files.  These are board description files used by Linux and BSD.")
        ("python" ,python)
        ("python-coverage" ,python-coverage)
        ("python-pytest" ,python-pytest)
-       ("sdl" ,sdl)
        ("swig" ,swig)))
     (build-system  gnu-build-system)
     (home-page "https://www.denx.de/wiki/U-Boot/")
@@ -475,9 +509,12 @@ also initializes the boards (RAM etc).")
   (package
     (inherit u-boot)
     (name "u-boot-tools")
+    (native-inputs
+     `(("sdl2" ,sdl2)
+       ,@(package-native-inputs u-boot)))
     (arguments
      `(#:make-flags '("HOSTCC=gcc")
-       #:test-target "tests"
+       #:test-target "tcheck"
        #:phases
        (modify-phases %standard-phases
          (add-after 'unpack 'patch
@@ -488,11 +525,8 @@ also initializes the boards (RAM etc).")
              (substitute* "tools/dtoc/fdt_util.py"
               (("'cc'") "'gcc'"))
              (substitute* "tools/patman/test_util.py"
-              ;; python*-coverage is simply called coverage in guix.
-              (("%s-coverage") "coverage")
-              ;; XXX Allow for only 99% test coverage.
-              ;; TODO: Find out why that is needed.
-              (("if coverage != '100%':") "if not int(coverage.rstrip('%')) >= 99:"))
+              ;; python3-coverage is simply called coverage in guix.
+              (("python3-coverage") "coverage"))
              (substitute* "test/run"
               ;; Make it easier to find test failures.
               (("#!/bin/bash") "#!/bin/bash -x")
@@ -502,8 +536,6 @@ also initializes the boards (RAM etc).")
               (("run_test \"binman\"") ": run_test \"binman\"")
               ;; FIXME: code coverage not working
               (("run_test \"binman code coverage\"") ": run_test \"binman code coverage\"")
-              (("run_test \"dtoc code coverage\"") ": run_test \"dtoc code coverage\"")
-              (("run_test \"fdt code coverage\"") ": run_test \"fdt code coverage\"")
               ;; This test would require internet access.
               (("\\./tools/buildman/buildman") (which "true")))
              (substitute* "test/py/tests/test_sandbox_exit.py"
@@ -516,10 +548,12 @@ def test_ctrl_c"))
                (("BASEDIR=sandbox") "BASEDIR=."))
              (for-each (lambda (file)
                               (substitute* file
-                                  ;; Disable signatures, due to GPL/Openssl
-                                  ;; license incompatibilities.  See
-                                  ;; https://bugs.gnu.org/34717 for details.
-                                  (("CONFIG_FIT_SIGNATURE=y") "CONFIG_FIT_SIGNATURE=n")
+                                  ;; Disable features that require OpenSSL due
+                                  ;; to GPL/Openssl license incompatibilities.
+                                  ;; See https://bugs.gnu.org/34717 for
+                                  ;; details.
+                                  (("CONFIG_FIT_SIGNATURE=y")
+                                   "CONFIG_FIT_SIGNATURE=n\nCONFIG_UT_LIB_ASN1=n")
                                   ;; This test requires a sound system, which is un-used
                                   ;; in u-boot-tools.
                                   (("CONFIG_SOUND=y") "CONFIG_SOUND=n")))
@@ -862,6 +896,33 @@ to Novena upstream, does not load u-boot.img from the first partition.")
   (let ((base (make-u-boot-package "rockpro64-rk3399" "aarch64-linux-gnu")))
     (package
       (inherit base)
+      (arguments
+        (substitute-keyword-arguments (package-arguments base)
+          ((#:phases phases)
+           `(modify-phases ,phases
+              (add-after 'unpack 'patch-rockpro64-config
+                ;; Fix regression in 2020.10 causing freezes on boot with USB boot enabled.
+                ;; See https://gitlab.manjaro.org/manjaro-arm/packages/core/uboot-rockpro64/-/issues/4
+                (lambda _
+                  (substitute* "configs/rockpro64-rk3399_defconfig"
+                    (("CONFIG_USE_PREBOOT=y") "CONFIG_USE_PREBOOT=n"))
+                  #t))
+              (add-after 'patch-rockpro64-config 'set-environment
+                (lambda* (#:key inputs #:allow-other-keys)
+                  (setenv "BL31" (string-append (assoc-ref inputs "firmware")
+                                                "/bl31.elf"))
+                  #t))
+              ;; Phases do not succeed on the bl31 ELF.
+              (delete 'strip)
+              (delete 'validate-runpath)))))
+      (native-inputs
+       `(("firmware" ,arm-trusted-firmware-rk3399)
+         ,@(package-native-inputs base))))))
+
+(define-public u-boot-pinebook-pro-rk3399
+  (let ((base (make-u-boot-package "pinebook-pro-rk3399" "aarch64-linux-gnu")))
+    (package
+     (inherit base)
       (arguments
         (substitute-keyword-arguments (package-arguments base)
           ((#:phases phases)
@@ -985,7 +1046,8 @@ tools, and more.")
                   (guix build utils)
                   (ice-9 regex)         ; for string-match
                   (srfi srfi-26))       ; for cut
-       #:make-flags (list "CC=gcc")
+       #:make-flags
+       (list ,(string-append "CC=" (cc-for-target)))
        #:tests? #f                      ; no tests
        #:phases
        (modify-phases %standard-phases
@@ -1035,3 +1097,124 @@ systems so that they can be added to the bootloader.  It also works out how to
 boot existing GNU/Linux systems and detects what distribution is installed in
 order to add a suitable bootloader menu entry.")
     (license license:gpl2+)))
+
+(define-public ipxe
+  ;; XXX: 'BUILD_TIMESTAMP' is used to automatically select the newest version
+  ;; of iPXE if multiple iPXE drivers are loaded concurrently in a UEFI system.
+  ;;
+  ;; TODO: Bump this timestamp at each modifications of the package (not only
+  ;; for updates) by running: date +%s.
+  (let ((timestamp "1591706427"))
+    (package
+      (name "ipxe")
+      (version "1.21.1")
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/ipxe/ipxe")
+                      (commit (string-append "v" version))))
+                (file-name (git-file-name name version))
+                (patches (search-patches "ipxe-reproducible-geniso.patch"))
+                (sha256
+                 (base32
+                  "1pkf1n1c0rdlzfls8fvjvi1sd9xjd9ijqlyz3wigr70ijcv6x8i9"))))
+      (build-system gnu-build-system)
+      (arguments
+       `(#:modules ((guix build utils)
+                    (guix build gnu-build-system)
+                    (guix base32)
+                    (ice-9 string-fun)
+                    (ice-9 regex)
+                    (rnrs bytevectors))
+         #:imported-modules ((guix base32)
+                             ,@%gnu-build-system-modules)
+         #:make-flags
+         ;; XXX: 'BUILD_ID' is used to determine when another ROM in the
+         ;; system contains identical code in order to save space within the
+         ;; legacy BIOS option ROM area, which is extremely limited in size.
+         ;; It is supposed to be collision-free across all ROMs, to do so we
+         ;; use the truncated output hash of the package.
+         (let ((build-id
+                (lambda (out)
+                  (let* ((nix-store (string-append
+                                     (or (getenv "NIX_STORE") "/gnu/store")
+                                     "/"))
+                         (filename
+                          (string-replace-substring out nix-store ""))
+                         (hash (match:substring (string-match "[0-9a-z]{32}"
+                                                              filename)))
+                         (bv (nix-base32-string->bytevector hash)))
+                    (format #f "0x~x"
+                            (bytevector-u32-ref bv 0 (endianness big))))))
+               (out (assoc-ref %outputs "out"))
+               (syslinux (assoc-ref %build-inputs "syslinux")))
+           (list "ECHO_E_BIN_ECHO=echo"
+                 "ECHO_E_BIN_ECHO_E=echo -e"
+
+                 ;; cdrtools' mkisofs will silently ignore a missing isolinux.bin!
+                 ;; Luckily xorriso is more strict.
+                 (string-append "ISOLINUX_BIN=" syslinux
+                                "/share/syslinux/isolinux.bin")
+                 (string-append "SYSLINUX_MBR_DISK_PATH=" syslinux
+                                "/share/syslinux/isohdpfx.bin")
+
+                 ;; Build reproducibly.
+                 (string-append "BUILD_ID_CMD=echo -n " (build-id out))
+                 (string-append "BUILD_TIMESTAMP=" ,timestamp)
+                 "everything"))
+         #:phases
+         (modify-phases %standard-phases
+           (add-after 'unpack 'enter-source-directory
+             (lambda _ (chdir "src") #t))
+           (add-after 'enter-source-directory 'set-options
+             (lambda _
+               (substitute* "config/general.h"
+                 (("^//(#define PING_CMD.*)" _ uncommented) uncommented)
+                 (("^//(#define IMAGE_TRUST_CMD.*)" _ uncommented)
+                  uncommented)
+                 (("^#undef.*(DOWNLOAD_PROTO_HTTPS.*)" _ option)
+                  (string-append "#define " option))
+                 (("^#undef.*(DOWNLOAD_PROTO_NFS.*)" _ option)
+                  (string-append "#define " option)))
+               #t))
+           (delete 'configure)          ; no configure script
+           (replace 'install
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let* ((out (assoc-ref outputs "out"))
+                      (ipxe (string-append out "/lib/ipxe"))
+                      (exts-re
+                       "\\.(efi|efirom|iso|kkpxe|kpxe|lkrn|mrom|pxe|rom|usb)$")
+                      (dirs '("bin" "bin-i386-linux" "bin-x86_64-pcbios"
+                              "bin-x86_64-efi" "bin-x86_64-linux" "bin-i386-efi"))
+                      (files (apply append
+                                    (map (lambda (dir)
+                                           (find-files dir exts-re)) dirs))))
+                 (for-each (lambda (file)
+                             (let* ((subdir (dirname file))
+                                    (fn (basename file))
+                                    (tgtsubdir (cond
+                                                ((string=? "bin" subdir) "")
+                                                ((string-prefix? "bin-" subdir)
+                                                 (string-drop subdir 4)))))
+                               (install-file file
+                                             (string-append ipxe "/" tgtsubdir))))
+                           files))
+               #t))
+           (add-after 'install 'leave-source-directory
+             (lambda _ (chdir "..") #t)))
+         #:tests? #f))                  ; no test suite
+      (native-inputs
+       `(("perl" ,perl)
+         ("syslinux" ,syslinux)
+         ("xorriso" ,xorriso)))
+      (home-page "https://ipxe.org")
+      (synopsis "PXE-compliant network boot firmware")
+      (description "iPXE is a network boot firmware.  It provides a full PXE
+implementation enhanced with additional features such as booting from: a web
+server via HTTP, an iSCSI SAN, a Fibre Channel SAN via FCoE, an AoE SAN, a
+wireless network, a wide-area network, an Infiniband network.  It allows to
+control the boot process with a script.  You can use iPXE to replace the
+existing PXE ROM on your network card, or you can chainload into iPXE to obtain
+the features of iPXE without the hassle of reflashing.")
+      (license license:gpl2+))))
+