diff mbox

[v6] gnu: Add u-boot, device-tree-compiler.

Message ID 20160802071139.6664-1-dannym@scratchpost.org
State New
Headers show

Commit Message

Danny Milosavljevic Aug. 2, 2016, 7:11 a.m. UTC
gnu: Add u-boot, device-tree-compiler.

* gnu/packages/u-boot.scm (device-tree-compiler, u-boot): New variables.
---
 gnu/local.mk                                       |   4 +
 .../u-boot-device-tree-compiler-01_build_doc.patch |  21 ++++
 ...t-Add-missing-functions-to-shared-library.patch |  30 +++++
 ...t-Add-some-missing-symbols-to-version.lds.patch |  33 ++++++
 gnu/packages/u-boot.scm                            | 131 +++++++++++++++++++++
 5 files changed, 219 insertions(+)
 create mode 100644 gnu/packages/patches/u-boot-device-tree-compiler-01_build_doc.patch
 create mode 100644 gnu/packages/patches/u-boot-device-tree-compiler-23-libfdt-Add-missing-functions-to-shared-library.patch
 create mode 100644 gnu/packages/patches/u-boot-device-tree-compiler-24_libfdt-Add-some-missing-symbols-to-version.lds.patch
 create mode 100644 gnu/packages/u-boot.scm

Comments

Danny Milosavljevic Aug. 21, 2016, 8:23 a.m. UTC | #1
Any news on this? This is the version Debian uses and that I'm using myself and it's probably not going to change substantially. It would be great if someone could get this into the Guix git repo if there are no objections.
David Craven Aug. 21, 2016, 9:47 a.m. UTC | #2
Is this necessary?

+       #:make-flags '("HOSTCC=gcc")

this line also seems weird to me, why does the device-tree-compiler
respect HOME instead of PREFIX?

+     `(#:make-flags `("CC=gcc" ,(string-append "HOME=" (assoc-ref
%outputs "out"))) ; Note: or patch out PREFIX

I thought we were phasing #:select for licenses out?

+  #:use-module ((guix licenses) #:select (gpl2))

I think that we should add shortcuts for uboot loaders that would work
with our supported platforms in qemu. For arm-system-qemu that would
be the versatile-express board that works out of the box, I don't know
what the equivalent is for x86_64 and mips. (The rationale being that
the goal is to get guix system vm --system=armhf-linux working)

+;(define-public u-boot-a20-olinuxino-lime2
+;  (make-u-boot-package "A20-OLinuXino-Lime2"))
+
+;(define-public u-boot-efi-x86
+;  (make-u-boot-package "efi-x86"))
Danny Milosavljevic Aug. 22, 2016, 7:40 p.m. UTC | #3
On Sun, 21 Aug 2016 11:47:10 +0200
David Craven <david@craven.ch> wrote:

> Is this necessary?
> 
> +       #:make-flags '("HOSTCC=gcc")

Yes. When you remove it you get:

starting phase `configure'
configs/efi-x86_defconfig
  HOSTCC  scripts/basic/fixdep
/gnu/store/03zjklzb1jr6v9p4zpy5c0p9k6h1c54y-bash-4.3.42/bin/bash: cc: command not found
scripts/Makefile.host:94: recipe for target 'scripts/basic/fixdep' failed

That's because it needs to compile some native helpers even when (potentially) cross compiling. If there are better ways to find out what the appropriate compiler is, I'm all for it.

> this line also seems weird to me, why does the device-tree-compiler
> respect HOME instead of PREFIX?
> 
> +     `(#:make-flags `("CC=gcc" ,(string-append "HOME=" (assoc-ref
> %outputs "out"))) ; Note: or patch out PREFIX

I don't know. You have to ask them...

The culprit is:

Makefile:

PREFIX = $(HOME) <---- here
BINDIR = $(PREFIX)/bin
LIBDIR = $(PREFIX)/lib
INCLUDEDIR = $(PREFIX)/include

I know I could patch this out but I don't feel like having fragile patches (what if the context changes) or substitutions (what if it is changed to use some other way to cause PREFIX to be set to HOME) when I can just set HOME up and that's it.

> I thought we were phasing #:select for licenses out?
> 
> +  #:use-module ((guix licenses) #:select (gpl2))

Yes, indeed. When someone applies this patch please take this into account.

> I think that we should add shortcuts for uboot loaders that would work
> with our supported platforms in qemu. For arm-system-qemu that would
> be the versatile-express board that works out of the box,

Which u-boot defconfig should we use?

List of defconfigs with "vexpress" in the name:

vexpress_aemv8a_dram_defconfig
vexpress_aemv8a_juno_defconfig
vexpress_aemv8a_semi_defconfig
vexpress_ca15_tc2_defconfig
vexpress_ca5x2_defconfig
vexpress_ca9x4_defconfig

> I don't know
> what the equivalent is for x86_64 and mips. (The rationale being that
> the goal is to get guix system vm --system=armhf-linux working)

I don't know either...

For simple compilation tests (i.e. whether I broke the package specification) I use u-boot-efi-x86 on x86_64 without cross compiling.

Not sure what the status of qemu is in that regard. Can it do UEFI?
David Craven Aug. 22, 2016, 9:18 p.m. UTC | #4
> Which u-boot defconfig should we use?
>
> List of defconfigs with "vexpress" in the name:
>
> vexpress_aemv8a_dram_defconfig
> vexpress_aemv8a_juno_defconfig
> vexpress_aemv8a_semi_defconfig
> vexpress_ca15_tc2_defconfig
> vexpress_ca5x2_defconfig
> vexpress_ca9x4_defconfig

Ups I just realized that there is no default machine for arm. But
I think that vexpress-a9 is often used as the default machine for
qemu. That would be vexpress_ca9x4_defconfig. It's also what
nixos uses. [0]

>> I don't know
>> what the equivalent is for x86_64 and mips. (The rationale being that
>> the goal is to get guix system vm --system=armhf-linux working)
>
> I don't know either...
>
> For simple compilation tests (i.e. whether I broke the package specification) I use u-boot-efi-x86 on x86_64 without cross compiling.

The default machine for qemu-system-mips is:
malta      MIPS Malta Core LV (default)

I don't know if uboot can boot this? Maybe someone interested
in guix system vm --system=mipsel-linux can comment?

> Not sure what the status of qemu is in that regard. Can it do UEFI?

With tianocore it can, but don't think I remember ever getting it to
work (on fedora a long time ago), so we can ignore my comment
in regard to x86_64/i686 architectures, since grub already works
well anyway.

[0] https://nixos.org/wiki/NixOS_on_ARM
David Craven Aug. 23, 2016, 1:03 a.m. UTC | #5
> The default machine for qemu-system-mips is:
> malta      MIPS Malta Core LV (default)
>
> I don't know if uboot can boot this? Maybe someone interested
> in guix system vm --system=mipsel-linux can comment?

malta_defconfig should work according to [0]

[0] http://u-boot.denx.narkive.com/9y8MnoQp/using-u-boot-with-qemu-system-mips-qemu-2-1-2-caused-infinite-loop
Danny Milosavljevic Aug. 24, 2016, 12:15 a.m. UTC | #6
I see.

The additions would be then:

(define-public u-boot-vexpress_ca9x4
  (make-u-boot-package "vexpress_ca9x4"))

(define-public u-boot-malta
  (make-u-boot-package "malta"))
diff mbox

Patch

diff --git a/gnu/local.mk b/gnu/local.mk
index dcdea86..f7e3c0f 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -343,6 +343,7 @@  GNU_SYSTEM_MODULES =				\
   %D%/packages/unrtf.scm			\
   %D%/packages/upnp.scm				\
   %D%/packages/uucp.scm				\
+  %D%/packages/u-boot.scm			\
   %D%/packages/valgrind.scm			\
   %D%/packages/version-control.scm		\
   %D%/packages/video.scm			\
@@ -813,6 +814,9 @@  dist_patch_DATA =						\
   %D%/packages/patches/unzip-initialize-symlink-flag.patch	\
   %D%/packages/patches/unzip-overflow-long-fsize.patch		\
   %D%/packages/patches/unzip-remove-build-date.patch		\
+  %D%/packages/patches/u-boot-device-tree-compiler-01_build_doc.patch \
+  %D%/packages/patches/u-boot-device-tree-compiler-23-libfdt-Add-missing-functions-to-shared-library.patch \
+  %D%/packages/patches/u-boot-device-tree-compiler-24_libfdt-Add-some-missing-symbols-to-version.lds.patch \
   %D%/packages/patches/util-linux-tests.patch			\
   %D%/packages/patches/upower-builddir.patch			\
   %D%/packages/patches/valgrind-enable-arm.patch		\
diff --git a/gnu/packages/patches/u-boot-device-tree-compiler-01_build_doc.patch b/gnu/packages/patches/u-boot-device-tree-compiler-01_build_doc.patch
new file mode 100644
index 0000000..06c3e40
--- /dev/null
+++ b/gnu/packages/patches/u-boot-device-tree-compiler-01_build_doc.patch
@@ -0,0 +1,21 @@ 
+Index: device-tree-compiler-1.0.0/Documentation/Makefile
+===================================================================
+--- /dev/null	1970-01-01 00:00:00.000000000 +0000
++++ device-tree-compiler-1.0.0/Documentation/Makefile	2007-08-23 18:26:22.000000000 +0200
+@@ -0,0 +1,16 @@
++all: dtc-paper.ps dtc-paper.pdf dtc-manual.txt
++
++dtc-manual.txt: manual.txt
++	cp -f $< $@
++
++dtc-paper.dvi: dtc-paper.tex
++	latex $<
++
++dtc-paper.ps: dtc-paper.dvi
++	dvips $<
++
++dtc-paper.pdf: dtc-paper.tex
++	pdflatex $<
++
++clean:
++	rm -f *.aux *.log *.dvi *.ps *.pdf dtc-manual.txt
diff --git a/gnu/packages/patches/u-boot-device-tree-compiler-23-libfdt-Add-missing-functions-to-shared-library.patch b/gnu/packages/patches/u-boot-device-tree-compiler-23-libfdt-Add-missing-functions-to-shared-library.patch
new file mode 100644
index 0000000..3bfde67
--- /dev/null
+++ b/gnu/packages/patches/u-boot-device-tree-compiler-23-libfdt-Add-missing-functions-to-shared-library.patch
@@ -0,0 +1,30 @@ 
+From a4b093f7366fdb429ca1781144d3985fa50d0fbb Mon Sep 17 00:00:00 2001
+From: Julien Grall <julien.grall@linaro.org>
+Date: Tue, 17 Mar 2015 16:00:34 +0000
+Subject: [PATCH] libfdt: Add missing functions to shared library
+
+The commit 4e76ec7 "libfdt: Add fdt_next_subnode() to permit easy
+subnode iteration" adds new functions (fdt_{first,next}_subnode) but
+forgot to mark them as 'global' in the shared library.
+
+Signed-off-by: Julien Grall <julien.grall@linaro.org>
+---
+ libfdt/version.lds | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/libfdt/version.lds b/libfdt/version.lds
+index 80b322b..941208e 100644
+--- a/libfdt/version.lds
++++ b/libfdt/version.lds
+@@ -54,6 +54,8 @@ LIBFDT_1.2 {
+ 		fdt_get_property_by_offset;
+ 		fdt_getprop_by_offset;
+ 		fdt_next_property_offset;
++		fdt_first_subnode;
++		fdt_next_subnode;
+ 
+ 	local:
+ 		*;
+-- 
+2.8.1
+
diff --git a/gnu/packages/patches/u-boot-device-tree-compiler-24_libfdt-Add-some-missing-symbols-to-version.lds.patch b/gnu/packages/patches/u-boot-device-tree-compiler-24_libfdt-Add-some-missing-symbols-to-version.lds.patch
new file mode 100644
index 0000000..4f825c4
--- /dev/null
+++ b/gnu/packages/patches/u-boot-device-tree-compiler-24_libfdt-Add-some-missing-symbols-to-version.lds.patch
@@ -0,0 +1,33 @@ 
+From f58799be130e27cc729cb2d45566daa0bb3b8605 Mon Sep 17 00:00:00 2001
+From: David Gibson <david@gibson.dropbear.id.au>
+Date: Tue, 1 Dec 2015 12:55:21 +1100
+Subject: [PATCH] libfdt: Add some missing symbols to version.lds
+
+Several functions in the header file were missing from the version.lds
+script, meaning that they couldn't be used from a libfdt shared library.
+
+Reported by Ken Aaker, via github issue tracker.
+
+Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
+---
+ libfdt/version.lds | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/libfdt/version.lds b/libfdt/version.lds
+index f19f157..1f4e1ea 100644
+--- a/libfdt/version.lds
++++ b/libfdt/version.lds
+@@ -57,6 +57,10 @@ LIBFDT_1.2 {
+ 		fdt_next_property_offset;
+ 		fdt_first_subnode;
+ 		fdt_next_subnode;
++		fdt_address_cells;
++		fdt_size_cells;
++		fdt_stringlist_contains;
++		fdt_resize;
+ 
+ 	local:
+ 		*;
+-- 
+2.8.1
+
diff --git a/gnu/packages/u-boot.scm b/gnu/packages/u-boot.scm
new file mode 100644
index 0000000..173d621
--- /dev/null
+++ b/gnu/packages/u-boot.scm
@@ -0,0 +1,131 @@ 
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2016 Danny Milosavljevic <dannym+a@scratchpost.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages u-boot)
+  #:use-module (guix download)
+  #:use-module (guix packages)
+  #:use-module ((guix licenses) #:select (gpl2))
+  #:use-module (guix build-system gnu)
+  #:use-module (guix build-system trivial)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages bison)
+  #:use-module (gnu packages flex)
+  #:use-module (gnu packages algebra) ; bc
+  #:use-module (srfi srfi-1)
+  #:use-module ((srfi srfi-1) #:select (last)))
+
+(define-public device-tree-compiler
+  (package
+    (name "device-tree-compiler")
+    (version "1.4.0")
+    (source (origin
+             (method url-fetch)
+             ;; or <https://git.kernel.org/cgit/utils/dtc/dtc.git>
+             (uri (string-append "https://launchpad.net/ubuntu/+archive/primary/+files/"
+                                 "device-tree-compiler_" version "+dfsg.orig.tar.gz"))
+             (sha256
+              (base32
+               "0hzsqkpbgl73fblpnaiczirgwn0hapa7z478xjy6vvkqljpa3ygm"))
+             (patches (search-patches "u-boot-device-tree-compiler-01_build_doc.patch"
+                                      "u-boot-device-tree-compiler-23-libfdt-Add-missing-functions-to-shared-library.patch"
+                                      "u-boot-device-tree-compiler-24_libfdt-Add-some-missing-symbols-to-version.lds.patch"))
+             (modules '((guix build utils)))
+             (snippet
+               '(substitute* "Makefile"
+                  (("/usr/bin/install")
+                   "install")))))
+    (home-page "https://git.kernel.org/cgit/utils/dtc/dtc.git")
+    (synopsis "Compiles Device Tree Source Files (.dts)")
+    (description "dtc compiles Device Tree Source Files to Device Tree Binary Files. 
+These are hardware (board) description files (used by Linux and BSD).")
+    (license gpl2)
+    (build-system gnu-build-system)
+    (native-inputs
+     `(("bison" ,bison)
+       ("flex" ,flex)))
+    (arguments
+     `(#:make-flags `("CC=gcc" ,(string-append "HOME=" (assoc-ref %outputs "out"))) ; Note: or patch out PREFIX
+       #:phases (modify-phases %standard-phases
+          (delete 'configure))))))
+
+(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"))))
+    (home-page "http://www.denx.de/wiki/U-Boot/")
+    (synopsis "ARM Universal Bootloader")
+    (description "U-Boot is an universal bootloader mostly used for ARM boards. 
+It also initializes the boards (RAM etc).")
+    (license gpl2)
+    (native-inputs
+      `(("python-2" ,python-2)
+        ("device-tree-compiler" ,device-tree-compiler)
+        ("bc" ,bc)))
+    (build-system  gnu-build-system)))
+
+(define (make-u-boot-package board)
+  (package
+    (inherit u-boot)
+    (name (string-append "u-boot-" (string-downcase board)))
+    (arguments
+     `(#:test-target "test"
+       ,@(if (string-prefix? "x86_64"
+                             (or (%current-target-system)
+                                 (%current-system)))
+           '(#:system "i686-linux")
+           '())
+       #:make-flags '("HOSTCC=gcc")
+       #:phases
+        (modify-phases %standard-phases
+         (replace
+          'configure
+           (lambda* (#:key outputs make-flags #:allow-other-keys)
+             (let ((configname (string-append ,board "_defconfig")))
+               (if (zero? (system* "ls" (string-append "configs/" configname)))
+                  (zero? (apply system* "make" `(,@make-flags ,configname)))
+                  (begin
+                    (display "Invalid boardname. Valid boardnames would have been:")
+                    (newline)
+                    (system* "ls" "-1" "configs")
+                    #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)$"))))))))))
+
+;(define-public u-boot-a20-olinuxino-lime2
+;  (make-u-boot-package "A20-OLinuXino-Lime2"))
+
+;(define-public u-boot-efi-x86
+;  (make-u-boot-package "efi-x86"))
+
+; Something should:
+; - create extlinux.conf and put it on the first bootable partition (the one with the Active flag)
+; - install the u-boot bootloader