Subject: Add installer support for u-boot imx6 boards.

From: Vagrant Cascadian <[email-masked]>
Date: Thu, 10 May 2018 10:47:54 -0700

Add support to install u-boot for wandboard and mx6cuboxi, and add
u-boot target and installer support for novena.

Tested using GuixSD on wandboard solo and novena. The mx6cuboxi target
uses the same device offsets, and worked with manual installation.

It should be noted that the offsets for installing u-boot.img on imx6
targets conflict with a typical GPT partition table header; works fine
with dos partition table headers. I'm not sure what safeguards could be
added to detect that. This also may not be unique to imx6 targets
(e.g. pine64 u-boot/atf also has a similar issue).

Also, the novena patch has a known flaw, in that it requires copying the
u-boot.img file to the first partition rather than writing it to a raw
offset on the mmc device.

Not sure how to handle that exactly, as partitioning is typically a
manual process in guixsd?

If nothing else, merging only the wandboard and mx6cuboxi patches and
only including the u-boot target for novena might make sense. Another
option would be to patch novena to load u-boot.img from an offset rather
than a filesystem, though I doubt that will be accepted in u-boot
upstream.

live well,
  vagrant

Vagrant Cascadian (3):
  system: Add mx6cuboxi installer.
  system: Add wandboard installer.
  gnu: Add u-boot-novena installer.

 gnu/bootloader/u-boot.scm    | 34 +++++++++++++++++++++++++++++++++-
 gnu/packages/bootloaders.scm |  3 +++
 gnu/system/install.scm       | 20 +++++++++++++++++++-
 3 files changed, 55 insertions(+), 2 deletions(-)

-- 
2.17.0

From 39b8f64e964c2a88d6f0bcbb5dcfa2ccb194793f Mon Sep 17 00:00:00 2001
From: Vagrant Cascadian <[email-masked]>
Date: Mon, 7 May 2018 14:32:02 +0000
Subject: [PATCH 1/3] system: Add mx6cuboxi installer.

* gnu/bootloader/u-boot.scm (u-boot-mx6cuboxi-bootloader):
  New exported variable.
* gnu/system/install.scm (mx6cuboxi-installation-os):
  New exported variable.
---
 gnu/bootloader/u-boot.scm | 20 ++++++++++++++++++++
 gnu/system/install.scm    |  6 ++++++
 2 files changed, 26 insertions(+)

diff --git a/gnu/bootloader/u-boot.scm b/gnu/bootloader/u-boot.scm
index 21d0aecce..58ee528a2 100644
--- a/gnu/bootloader/u-boot.scm
+++ b/gnu/bootloader/u-boot.scm
@@ -33,6 +33,7 @@
             u-boot-a20-olinuxino-micro-bootloader
             u-boot-banana-pi-m2-ultra-bootloader
             u-boot-beaglebone-black-bootloader
+            u-boot-mx6cuboxi-bootloader
             u-boot-nintendo-nes-classic-edition-bootloader))
 
 (define install-u-boot
@@ -62,6 +63,15 @@
         (write-file-on-device u-boot (stat:size (stat u-boot))
                               device (* 8 1024)))))
 
+(define install-imx-u-boot
+  #~(lambda (bootloader device mount-point)
+      (let ((spl (string-append bootloader "/libexec/SPL"))
+            (u-boot (string-append bootloader "/libexec/u-boot.img")))
+        (write-file-on-device spl (stat:size (stat spl))
+                              device (* 1 1024))
+        (write-file-on-device u-boot (stat:size (stat u-boot))
+                              device (* 69 1024)))))
+
 
 
 ;;;
@@ -86,6 +96,11 @@
    (inherit u-boot-bootloader)
    (installer install-allwinner-u-boot)))
 
+(define u-boot-imx-bootloader
+  (bootloader
+   (inherit u-boot-bootloader)
+   (installer install-imx-u-boot)))
+
 (define u-boot-nintendo-nes-classic-edition-bootloader
   (bootloader
     (inherit u-boot-allwinner-bootloader)
@@ -110,3 +125,8 @@
   (bootloader
    (inherit u-boot-allwinner-bootloader)
    (package u-boot-banana-pi-m2-ultra)))
+
+(define u-boot-mx6cuboxi-bootloader
+  (bootloader
+   (inherit u-boot-imx-bootloader)
+   (package u-boot-mx6cuboxi)))
diff --git a/gnu/system/install.scm b/gnu/system/install.scm
index 920d21527..7580d981b 100644
--- a/gnu/system/install.scm
+++ b/gnu/system/install.scm
@@ -49,6 +49,7 @@
             a20-olinuxino-micro-installation-os
             banana-pi-m2-ultra-installation-os
             beaglebone-black-installation-os
+            mx6cuboxi-installation-os
             nintendo-nes-classic-edition-installation-os))
 
 ;;; Commentary:
@@ -429,6 +430,11 @@ The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
                             "/dev/mmcblk1" ; eMMC storage
                             "ttyS0"))
 
+(define mx6cuboxi-installation-os
+  (embedded-installation-os u-boot-mx6cuboxi-bootloader
+                            "/dev/mmcblk0" ; SD card storage
+                            "ttymxc0"))
+
 (define nintendo-nes-classic-edition-installation-os
   (embedded-installation-os u-boot-nintendo-nes-classic-edition-bootloader
                             "/dev/mmcblk0" ; SD card (solder it yourself)
-- 
2.17.0

From 4b552cb1c4cd1df18278a2b5b63aac4ca7337140 Mon Sep 17 00:00:00 2001
From: Vagrant Cascadian <[email-masked]>
Date: Mon, 7 May 2018 14:34:43 +0000
Subject: [PATCH 2/3] system: Add wandboard installer.

* gnu/bootloader/u-boot.scm (u-boot-wandboard-bootloader):
  New exported variable.
* gnu/system/install.scm (wandboard-installation-os):
  New exported variable.
---
 gnu/bootloader/u-boot.scm | 8 +++++++-
 gnu/system/install.scm    | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gnu/bootloader/u-boot.scm b/gnu/bootloader/u-boot.scm
index 58ee528a2..9a62a166f 100644
--- a/gnu/bootloader/u-boot.scm
+++ b/gnu/bootloader/u-boot.scm
@@ -34,7 +34,8 @@
             u-boot-banana-pi-m2-ultra-bootloader
             u-boot-beaglebone-black-bootloader
             u-boot-mx6cuboxi-bootloader
-            u-boot-nintendo-nes-classic-edition-bootloader))
+            u-boot-nintendo-nes-classic-edition-bootloader
+            u-boot-wandboard-bootloader))
 
 (define install-u-boot
   #~(lambda (bootloader device mount-point)
@@ -130,3 +131,8 @@
   (bootloader
    (inherit u-boot-imx-bootloader)
    (package u-boot-mx6cuboxi)))
+
+(define u-boot-wandboard-bootloader
+  (bootloader
+   (inherit u-boot-imx-bootloader)
+   (package u-boot-wandboard)))
diff --git a/gnu/system/install.scm b/gnu/system/install.scm
index 7580d981b..9bb1d8145 100644
--- a/gnu/system/install.scm
+++ b/gnu/system/install.scm
@@ -50,7 +50,8 @@
             banana-pi-m2-ultra-installation-os
             beaglebone-black-installation-os
             mx6cuboxi-installation-os
-            nintendo-nes-classic-edition-installation-os))
+            nintendo-nes-classic-edition-installation-os
+            wandboard-installation-os))
 
 ;;; Commentary:
 ;;;
@@ -440,6 +441,11 @@ The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
                             "/dev/mmcblk0" ; SD card (solder it yourself)
                             "ttyS0"))
 
+(define wandboard-installation-os
+  (embedded-installation-os u-boot-wandboard-bootloader
+                            "/dev/mmcblk0" ; SD card storage
+                            "ttymxc0"))
+
 ;; Return the default os here so 'guix system' can consume it directly.
 installation-os
 
-- 
2.17.0

From 71cb0f715cf48bf703a8607f72088783b685d418 Mon Sep 17 00:00:00 2001
From: Vagrant Cascadian <[email-masked]>
Date: Wed, 9 May 2018 06:59:10 +0000
Subject: [PATCH 3/3] gnu: Add u-boot-novena installer.

* gnu/packages/bootloaders.scm (u-boot-novena):
  New variable.
* gnu/bootloader/u-boot.scm (u-boot-novena-bootloader):
  New exported variable.
* gnu/system/install.scm (novena-installation-os):
  New exported variable.
---
 gnu/bootloader/u-boot.scm    | 6 ++++++
 gnu/packages/bootloaders.scm | 3 +++
 gnu/system/install.scm       | 6 ++++++
 3 files changed, 15 insertions(+)

diff --git a/gnu/bootloader/u-boot.scm b/gnu/bootloader/u-boot.scm
index 9a62a166f..bc8f98f32 100644
--- a/gnu/bootloader/u-boot.scm
+++ b/gnu/bootloader/u-boot.scm
@@ -35,6 +35,7 @@
             u-boot-beaglebone-black-bootloader
             u-boot-mx6cuboxi-bootloader
             u-boot-nintendo-nes-classic-edition-bootloader
+            u-boot-novena-bootloader
             u-boot-wandboard-bootloader))
 
 (define install-u-boot
@@ -136,3 +137,8 @@
   (bootloader
    (inherit u-boot-imx-bootloader)
    (package u-boot-wandboard)))
+
+(define u-boot-novena-bootloader
+  (bootloader
+   (inherit u-boot-imx-bootloader)
+   (package u-boot-novena)))
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 0db6ad3f6..c0a0101c5 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -469,6 +469,9 @@ also initializes the boards (RAM etc).")
 (define-public u-boot-mx6cuboxi
   (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
 
+(define-public u-boot-novena
+  (make-u-boot-package "novena" "arm-linux-gnueabihf"))
+
 (define-public vboot-utils
   (package
     (name "vboot-utils")
diff --git a/gnu/system/install.scm b/gnu/system/install.scm
index 9bb1d8145..a2917e485 100644
--- a/gnu/system/install.scm
+++ b/gnu/system/install.scm
@@ -51,6 +51,7 @@
             beaglebone-black-installation-os
             mx6cuboxi-installation-os
             nintendo-nes-classic-edition-installation-os
+            novena-installation-os
             wandboard-installation-os))
 
 ;;; Commentary:
@@ -436,6 +437,11 @@ The bootloader BOOTLOADER is installed to BOOTLOADER-TARGET."
                             "/dev/mmcblk0" ; SD card storage
                             "ttymxc0"))
 
+(define novena-installation-os
+  (embedded-installation-os u-boot-novena-bootloader
+                            "/dev/mmcblk1" ; SD card storage
+                            "ttymxc1"))
+
 (define nintendo-nes-classic-edition-installation-os
   (embedded-installation-os u-boot-nintendo-nes-classic-edition-bootloader
                             "/dev/mmcblk0" ; SD card (solder it yourself)
-- 
2.17.0