diff --git a/gnu/packages/u-boot.scm b/gnu/packages/u-boot.scm index 5f3fd49..4a10782 100644 --- a/gnu/packages/u-boot.scm +++ b/gnu/packages/u-boot.scm @@ -23,8 +23,11 @@ #:use-module (guix packages) #:use-module ((guix licenses) #:prefix license:) #:use-module (gnu packages) + #:use-module ((gnu packages algebra) #:select (bc)) #:use-module (gnu packages bison) - #:use-module (gnu packages flex)) + #:use-module (gnu packages cross-base) + #:use-module (gnu packages flex) + #:use-module (gnu packages python)) (define-public dtc (package @@ -38,9 +41,9 @@ (sha256 (base32 "155v52palf5fwfcnq696s41whjk0a5dqx98b7maqzdn7xbc2m6bp")) - (patches (search-patches "u-boot-dtc-01_build_doc.patch" - "u-boot-dtc-23-libfdt-Add-missing-functions-to-shared-library.patch" - "u-boot-dtc-24_libfdt-Add-some-missing-symbols-to-version.lds.patch")))) + (patches (search-patches "dtc-01_build_doc.patch" + "dtc-23-libfdt-Add-missing-functions-to-shared-library.patch" + "dtc-24_libfdt-Add-some-missing-symbols-to-version.lds.patch")))) (build-system gnu-build-system) (native-inputs `(("bison" ,bison) @@ -63,3 +66,82 @@ device tree binary (.dtb) files. These are hardware (board) description files (used by Linux and BSD).") (license license:gpl2+))) + +(define u-boot + (package + (name "u-boot") + (version "2016.07") + (source (origin + (method url-fetch) + (uri (string-append + "ftp://ftp.denx.de/pub/u-boot/" + "u-boot-" version ".tar.bz2")) + (sha256 + (base32 + "0lqj4ckmfqiap8mc6z2d5albs3g2h5mzccbn60hsgxhabhibfkwp")))) + (native-inputs + `(("bc" ,bc) + ("dtc" ,dtc) + ("python-2" ,python-2))) + (build-system gnu-build-system) + (home-page "http://www.denx.de/wiki/U-Boot/") + (synopsis "ARM Bootloader") + (description "U-Boot is a bootloader mostly used for ARM boards. +It also initializes the boards (RAM etc).") + (license license:gpl2+))) + +(define (make-u-boot-package board triplet) + (let ((xgcc (cross-gcc triplet))) + (package + (inherit u-boot) + (name (string-append "u-boot-" (string-downcase board))) + (native-inputs + `(("cross-gcc" ,xgcc) + ("cross-binutils" ,(cross-binutils triplet)) + ,@(package-native-inputs u-boot))) + (arguments + `(#:test-target "test" + #:make-flags + (list "HOSTCC=gcc" (string-append "CROSS_COMPILE=" ,triplet "-")) + #:phases + (modify-phases %standard-phases + (replace + 'configure + (lambda* (#:key outputs make-flags #:allow-other-keys) + (let ((config-name (string-append ,board "_defconfig"))) + (if (zero? (system* "ls" (string-append "configs/" config-name))) + (zero? (apply system* "make" `(,@make-flags ,config-name))) + (begin + (use-modules (ice-9 match) (ice-9 format)) + (display "Invalid board name. Valid board names would have been:") + (newline) + (let ((dir (opendir "configs"))) + (do ((file-name (readdir dir) (readdir dir))) + ((eof-object? file-name)) + (if (string-suffix? "_defconfig" file-name) + (format #t + "- ~A\n" + (string-drop-right file-name + (string-length "_defconfig"))))) + (closedir dir)) + #f))))) + (replace 'install + (lambda* (#:key outputs make-flags #:allow-other-keys) + (let ((out (string-append (assoc-ref outputs "out") "/libexec"))) + (mkdir-p out) + (for-each (lambda (name) + (let ((outname (string-append out "/" name))) + (mkdir-p (dirname outname)) + (copy-file name outname))) + (find-files "." ".*\\.(bin|efi|spl)$"))))))))))) + +(define-public armhf-linux-uboot + (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf")) + +(define-public mips64el-linux-uboot + (make-u-boot-package "malta" "mips64el-linux-gnuabi64")) + +;;; Something should: +;;; - create extlinux.conf and put it on the first bootable partition +;;; (the one with the Active flag) +;;; - install the u-boot bootloader