From 236a1f38d7f1cd416275e89885737aeed010e0c5 Mon Sep 17 00:00:00 2001
From: Martyn Welch <martyn.welch@collabora.com>
Date: Thu, 28 Feb 2019 16:53:14 +0000
Subject: [PATCH] Add image for installing U-Boot on SABRE Lite

We are moving to installing U-Boot in the SPI NOR on the SABRE Lite board.
Provide an image to make it trivial to get U-Boot installed without
needing to follow a list of error prone instructions.

Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
---
 mx6qsabrelite-uboot-installer.yaml        | 87 +++++++++++++++++++++++
 overlays/installer-mx6qsabrelite/boot.cmd | 15 ++++
 2 files changed, 102 insertions(+)
 create mode 100644 mx6qsabrelite-uboot-installer.yaml
 create mode 100644 overlays/installer-mx6qsabrelite/boot.cmd

diff --git a/mx6qsabrelite-uboot-installer.yaml b/mx6qsabrelite-uboot-installer.yaml
new file mode 100644
index 00000000..6efece5a
--- /dev/null
+++ b/mx6qsabrelite-uboot-installer.yaml
@@ -0,0 +1,87 @@
+{{ $architecture := or .architecture "armhf" }}
+{{ $target := or .target "mx6qsabrelite" }}
+{{ $mirror := or .mirror "https://repositories.apertis.org/apertis/" }}
+{{ $suite := or .suite "v2019dev0" }}
+{{ $image := or .image (printf "uboot-%s-installer-%s" $suite $target) }}
+
+architecture: {{ $architecture }}
+
+actions:
+  - action: image-partition
+    imagename: {{ $image }}.img
+    imagesize: 300M
+    partitiontype: msdos
+
+    mountpoints:
+      - mountpoint: /
+        partition: data
+        options: [ ro ]
+
+    partitions:
+      - name: data
+        fs: ext2
+        start: 6176s
+        end: 100%
+        flags: [ boot ]
+
+  - action: overlay
+    source: overlays/installer-{{ $target }}
+
+  - action: filesystem-deploy
+    description: Deploying filesystem onto image
+
+  - action: run
+    description: Create chdist directory
+    chroot: false
+    command: mkdir "./chdist"
+
+  - action: run
+    description: Setup chdist
+    chroot: false
+    command: chdist -d "./chdist" create apertis-{{ $suite }} {{ $mirror }} {{ $suite }} target
+
+  - action: run
+    description: Add Apertis gpg key to chdist
+    chroot: false
+    command: cp "${RECIPEDIR}/keyring/apertis-archive-keyring.gpg" "./chdist/apertis-{{ $suite }}/etc/apt/trusted.gpg.d"
+
+  - action: run
+    description: Update repo (chdist)
+    chroot: false
+    command: chdist -d "./chdist" -a {{ $architecture }} apt apertis-{{ $suite }} update
+
+  - action: run
+    description: Download U-Boot (chdist)
+    chroot: false
+    command: chdist -d "./chdist" -a {{ $architecture }} apt apertis-{{ $suite }} download u-boot-imx
+
+  - action: run
+    description: Unpack U-Boot
+    chroot: false
+    command: dpkg -x u-boot-imx_*.deb "${ROOTDIR}/deb-binaries"
+
+  - action: run
+    description: Wrapper installation script
+    chroot: false
+    command: mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "U-Boot SPI Installation Script" -d "${ROOTDIR}/boot.cmd" "${ROOTDIR}/boot.scr"
+
+  - action: raw
+    description: Install U-Boot
+    origin: filesystem
+    source: /deb-binaries/usr/lib/u-boot/{{ $target }}/u-boot.imx
+    offset: {{ sector 2 }}
+
+  - action: run
+    description: Create block map for {{ $image }}.img
+    postprocess: true
+    command: bmaptool create {{ $image }}.img > {{ $image }}.img.bmap
+
+  - action: run
+    description: Compress {{ $image }}.img
+    postprocess: true
+    command: gzip -f {{ $image }}.img
+
+  - action: run
+    description: Checksum for {{ $image }}.img.gz
+    postprocess: true
+    command: sha256sum {{ $image }}.img.gz > {{ $image }}.img.gz.sha256
diff --git a/overlays/installer-mx6qsabrelite/boot.cmd b/overlays/installer-mx6qsabrelite/boot.cmd
new file mode 100644
index 00000000..2a6301e0
--- /dev/null
+++ b/overlays/installer-mx6qsabrelite/boot.cmd
@@ -0,0 +1,15 @@
+echo "Copying U-Boot to RAM"
+load mmc 0:1 0x12000000 /deb-binaries/usr/lib/u-boot/mx6qsabrelite/u-boot.imx
+echo "Probing SPI-NOR"
+sf probe 0
+echo "Erasing SPI_NOR"
+sf erase 0x0 0xc0000
+echo "Writing U-Boot to SPI-NOR"
+sf write 0x12000000 0x400 0xc0000
+echo ""
+echo '+-----------------------------------------------------------------+'
+echo '|                  U-Boot installation complete                   |'
+echo '|                                                                 |'
+echo '| Please remove the SD Card and power cycle the board to continue |'
+echo '+-----------------------------------------------------------------+'
+loop 0 0
-- 
GitLab