gnu: Add enet.
[jackhill/guix/guix.git] / gnu / packages / u-boot.scm
CommitLineData
d62ed732
DM
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2016 Danny Milosavljevic <dannym@scratchpost.org>
3;;; Copyright © 2016 David Craven <david@craven.ch>
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (gnu packages u-boot)
21 #:use-module (guix build-system gnu)
22 #:use-module (guix download)
23 #:use-module (guix packages)
24 #:use-module ((guix licenses) #:prefix license:)
71d46760
DM
25 #:use-module (gnu packages)
26 #:use-module ((gnu packages algebra) #:select (bc))
d62ed732 27 #:use-module (gnu packages bison)
71d46760
DM
28 #:use-module (gnu packages cross-base)
29 #:use-module (gnu packages flex)
30 #:use-module (gnu packages python))
d62ed732
DM
31
32(define-public dtc
33 (package
34 (name "dtc")
8cfdd64c 35 (version "1.4.2")
d62ed732
DM
36 (source (origin
37 (method url-fetch)
38 (uri (string-append
39 "https://www.kernel.org/pub/software/utils/dtc/"
40 "dtc-" version ".tar.xz"))
41 (sha256
42 (base32
8cfdd64c 43 "1b7si8niyca4wxbfah3qw4p4wli81mc1qwfhaswvrfqahklnwi8k"))))
d62ed732
DM
44 (build-system gnu-build-system)
45 (native-inputs
46 `(("bison" ,bison)
47 ("flex" ,flex)))
48 (arguments
49 `(#:make-flags
e42a0771
DM
50 (list "CC=gcc"
51 (string-append "PREFIX=" (assoc-ref %outputs "out"))
52 "INSTALL=install")
d62ed732
DM
53 #:phases
54 (modify-phases %standard-phases
d62ed732
DM
55 (delete 'configure))))
56 (home-page "https://www.devicetree.org")
57 (synopsis "Compiles device tree source files")
58 (description "@command{dtc} compiles device tree source files to device
59tree binary files. These are board description files used by Linux and BSD.")
60 (license license:gpl2+)))
71d46760
DM
61
62(define u-boot
63 (package
64 (name "u-boot")
65 (version "2016.07")
66 (source (origin
67 (method url-fetch)
68 (uri (string-append
69 "ftp://ftp.denx.de/pub/u-boot/"
70 "u-boot-" version ".tar.bz2"))
71 (sha256
72 (base32
73 "0lqj4ckmfqiap8mc6z2d5albs3g2h5mzccbn60hsgxhabhibfkwp"))))
74 (native-inputs
75 `(("bc" ,bc)
76 ("dtc" ,dtc)
77 ("python-2" ,python-2)))
78 (build-system gnu-build-system)
79 (home-page "http://www.denx.de/wiki/U-Boot/")
80 (synopsis "ARM bootloader")
81 (description "U-Boot is a bootloader used mostly for ARM boards. It
82also initializes the boards (RAM etc).")
83 (license license:gpl2+)))
84
85(define (make-u-boot-package board triplet)
86 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
87 (package
88 (inherit u-boot)
89 (name (string-append "u-boot-" (string-downcase board)))
90 (native-inputs
91 `(("cross-gcc" ,(cross-gcc triplet))
92 ("cross-binutils" ,(cross-binutils triplet))
93 ,@(package-native-inputs u-boot)))
94 (arguments
95 `(#:test-target "test"
96 #:make-flags
97 (list "HOSTCC=gcc" (string-append "CROSS_COMPILE=" ,triplet "-"))
98 #:phases
99 (modify-phases %standard-phases
100 (replace 'configure
101 (lambda* (#:key outputs make-flags #:allow-other-keys)
102 (let ((config-name (string-append ,board "_defconfig")))
103 (if (file-exists? (string-append "configs/" config-name))
104 (zero? (apply system* "make" `(,@make-flags ,config-name)))
105 (begin
106 (display "Invalid board name. Valid board names are:")
107 (let ((dir (opendir "configs"))
108 (suffix-length (string-length "_defconfig")))
109 (do ((file-name (readdir dir) (readdir dir)))
110 ((eof-object? file-name))
111 (when (string-suffix? "_defconfig" file-name)
112 (format #t "- ~A\n"
113 (string-drop-right file-name suffix-length))))
114 (closedir dir))
115 #f)))))
116 (replace 'install
117 (lambda* (#:key outputs make-flags #:allow-other-keys)
118 (let* ((out (assoc-ref outputs "out"))
119 (libexec (string-append out "/libexec"))
120 (uboot-files (find-files "." ".*\\.(bin|efi|spl)$")))
121 (mkdir-p libexec)
122 (for-each
123 (lambda (file)
124 (let ((target-file (string-append libexec "/" file)))
125 (mkdir-p (dirname target-file))
126 (copy-file file target-file)))
127 uboot-files)))))))))
128
8feb56b0 129(define-public u-boot-vexpress
71d46760
DM
130 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
131
132(define-public u-boot-malta
133 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
20f9c676
DC
134
135(define-public u-boot-beagle-bone-black
136 (make-u-boot-package "am335x_boneblack" "arm-linux-gnueabihf"))