Subject: [PATCH] main/u-boot: add ODROID-C2 signed bootloader

From: Daniel Santana <[email-masked]>
Date: Fri, 28 Feb 2020 16:39:14 -0300

---
 main/u-boot/APKBUILD      | 29 +++++++++++++++++++++++++----
 main/u-boot/update-u-boot | 38 +++++++++++++++++++++++---------------
 2 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/main/u-boot/APKBUILD b/main/u-boot/APKBUILD
index 4aa36df3d1..0048c82168 100644
--- a/main/u-boot/APKBUILD
+++ b/main/u-boot/APKBUILD
@@ -3,17 +3,19 @@
 # Maintainer: Leonardo Arena <[email-masked]>
 pkgname=u-boot
 pkgver=2020.01
-pkgrel=0
+pkgrel=1
 pkgdesc="u-boot bootloader common files"
 url="http://www.denx.de/wiki/U-Boot/"
 arch="armhf armv7 aarch64"
 license="GPL-2.0-or-later OFL-1.1 BSD-2-Clause BSD-3-Clause eCos-2.0 IBM-pibs
 	ISC LGPL-2.0-only LGPL-2.1-only X11"
-makedepends="$depends_dev bc dtc python3-dev swig bison flex openssl-dev"
+makedepends="$depends_dev bc dtc python2-dev swig bison flex openssl-dev bsd-compat-headers meson-tools"
 if [ "$CARCH" = "aarch64" ]; then
 	makedepends="$makedepends arm-trusted-firmware-sun50i"
 fi
+_odroidc2_commit=205c7b3259559283161703a1a200b787c2c445a5
 source="ftp://ftp.denx.de/pub/u-boot/u-boot-${pkgver//_/-}.tar.bz2
+	u-boot-odroidc2.tar.gz::https://github.com/hardkernel/u-boot/archive/${_odroidc2_commit}.tar.gz
 	README.txt
 	update-u-boot
 	"
@@ -68,6 +70,23 @@ build() {
 			mkdir -p "$BUILD_DIR"
 			make O="$BUILD_DIR" ${board}_config || return 1
 			make O="$BUILD_DIR" all || return 1
+
+			if [ "$board" = "odroid-c2" ]; then
+				# ODROID-C2 requires a signed bootloader
+				local odroid_dir="$srcdir"/u-boot-$_odroidc2_commit
+				sed -i 's/-Werror//' "$odroid_dir"/tools/fip_create/Makefile
+				make -C "$odroid_dir"/tools/fip_create
+				"$odroid_dir"/tools/fip_create/fip_create \
+					--bl30  "$odroid_dir"/fip/gxb/bl30.bin \
+					--bl301 "$odroid_dir"/fip/gxb/bl301.bin \
+					--bl31  "$odroid_dir"/fip/gxb/bl31.bin \
+					--bl33  "$BUILD_DIR"/u-boot.bin \
+					"$BUILD_DIR"/fip.bin
+				cat "$odroid_dir"/fip/gxb/bl2.package "$BUILD_DIR"/fip.bin > "$BUILD_DIR"/boot_new.bin
+				amlbootsig "$BUILD_DIR"/boot_new.bin "$BUILD_DIR"/u-boot.img
+				dd if="$BUILD_DIR"/u-boot.img of="$BUILD_DIR"/u-boot.gxbb bs=512 skip=96
+				cp "$odroid_dir"/sd_fuse/bl1.bin.hardkernel "$BUILD_DIR"
+			fi
 		done
 	done
 }
@@ -97,7 +116,8 @@ _split_boards() {
 		mkdir -p "$subpkgdir"/usr/share/$pkgname/$board
 		export BUILD_DIR="$builddir"/build/$board
 		local ok=no
-		for image in u-boot-sunxi-with-spl.bin -- MLO SPL u-boot.img -- u-boot.bin; do
+		for image in u-boot-sunxi-with-spl.bin -- bl1.bin.hardkernel u-boot.gxbb -- \
+			MLO SPL u-boot.img -- u-boot.bin; do
 			if [ "$image" = "--" ]; then
 				[ "$ok" = yes ] && break
 				continue
@@ -119,5 +139,6 @@ for board_config in $board_configs; do
 done
 
 sha512sums="073d4e0234095c1bda1ffa7a648972aa4530d106ee1a73035e0501b1aba2951653582c8b7bcf338d4e95012fa67e75f97b7e1fbac5cc764d609b671ef29617f7  u-boot-2020.01.tar.bz2
+7929bd3ae90dea5966678dc4673627b58c9d270ef898bb42e3ba80f8626d4a821c0093c9d71d8eca08451906c7cba1eb6951cd0ec3a88c056c74eb9e1b5af6c4  u-boot-odroidc2.tar.gz
 f8c9bb6e84d6f0620c976ac7ad5dd7ec7ff9dfdd4b1d03d2bf6653e7beccf80bdf2debfc92fb1f696dba92fb40287d3c45897e0078951451d0835cb61a5f16d1  README.txt
-b3b4fb70c4eea2034bae45c513bca7b738be7507b46d3f2d62b31c794cd238d492acf960c95078cb1c945520debd5d2762103df7cef0fc36acfe9ff9a94549fc  update-u-boot"
+fe086b84d867bbdc78568559a3e822a22b348c81bed0326bdc94f15f6a633d40d5a5f0326139d1d39314dab7dccfe6434ceba06643e11edd914aa73b8c80cbfc  update-u-boot"
diff --git a/main/u-boot/update-u-boot b/main/u-boot/update-u-boot
index b012b5fedf..f7ab8f9781 100755
--- a/main/u-boot/update-u-boot
+++ b/main/u-boot/update-u-boot
@@ -10,6 +10,7 @@ get_defaults() {
 	if [ -z "$board" -a -e /sys/firmware/devicetree/base/compatible ]; then
 		case "$(cat /sys/firmware/devicetree/base/compatible 2>/dev/null)" in
 		wand,*) board=wand ;;
+		hardkernel,odroid-c2amlogic,*) board=odroid-c2 ;;
 		esac
 	fi
 
@@ -17,6 +18,7 @@ get_defaults() {
 		case "$board" in
 		wand|cubie|cubie2) device=/dev/mmcblk0p0 ;;
 		mx6cuboxi) device=/dev/mmcblk0 ;;
+		odroid-c2) device=/dev/mmcblk0 ;;
 		esac
 	fi
 
@@ -39,7 +41,7 @@ usage: $0 [-b|--board <board-type>] [-d|--device <device>]
 
 options:
 
- -b,--board <board>       Specify the board type: wand, cubie, cubie2, cuboxi
+ -b,--board <board>       Specify the board type: wand, cubie, cubie2, cuboxi, odroid-c2
                           (current default: ${board:-none})
 
  -d,--device <device>     Specify the device where to install u-boot
@@ -62,6 +64,7 @@ while [ $# -gt 0 ]; do
 		wand|wandboard) board="wand" ;;
 		cubie|cubieboard) board="cubie" ;;
 		cuboxi|mx6cuboxi) board="mx6cuboxi" ;;
+		odroid-c2) board="odroid-c2" ;;
 		*) usage; exit 1;;
 		esac
 		shift
@@ -77,18 +80,18 @@ while [ $# -gt 0 ]; do
 	-n|--dry-run)
 		dryrun="echo"
 		;;
-        --)
-                break
-                ;;
-        -*)
-                usage
-                exit 1
-                ;;
-        esac
+	--)
+		break
+		;;
+	-*)
+		usage
+		exit 1
+		;;
+	esac
 done
 
 get_defaults
-if [ -z "$board" -o -z "$device" -o -z "$imagedir" -o  ! -e "$imagedir" ]; then
+if [ -z "$board" -o -z "$device" -o -z "$imagedir" -o ! -e "$imagedir" ]; then
 	usage
 	exit 1
 fi
@@ -103,18 +106,23 @@ set -e
 case "$board" in
 wand)
 	[ -e "$imagedir/wandboard" ] || die "wandboard images not installed, apk add u-boot-wandboard"
-	$dryrun dd if=$imagedir/wandboard/SPL of=$device bs=1k seek=1 status=none
-	$dryrun dd if=$imagedir/wandboard/u-boot.img of=$device bs=1k seek=69 status=none
+	$dryrun dd if="$imagedir"/wandboard/SPL of="$device" bs=1k seek=1 conv=notrunc status=none
+	$dryrun dd if="$imagedir"/wandboard/u-boot.img of="$device" bs=1k seek=69 conv=notrunc status=none
 	;;
 cubie|cubie2)
 	[ -e "$imagedir/Cubieboard${board#cubie}" ] || die "Cubieboard images not installed, apk add u-boot-cubieboard"
-	$dryrun dd if=$imagedir/Cubieboard${board#cubie}/u-boot-sunxi-with-spl.bin of=$device bs=1024 seek=8 status=none
+	$dryrun dd if="$imagedir"/Cubieboard"${board#cubie}"/u-boot-sunxi-with-spl.bin of="$device" bs=1024 seek=8 conv=notrunc status=none
 	;;
 mx6cuboxi)
 	[ -e "$imagedir/mx6cuboxi" ] || die "iMX6 Cubox-i images not installed, apk add u-boot-cuboxi"
-	$dryrun dd if=$imagedir/mx6cuboxi/SPL of=$device bs=1k seek=1 status=none
-	$dryrun dd if=$imagedir/mx6cuboxi/u-boot.img of=$device bs=1k seek=69 status=none
+	$dryrun dd if="$imagedir"/mx6cuboxi/SPL of="$device" bs=1k seek=1 conv=notrunc status=none
+	$dryrun dd if="$imagedir"/mx6cuboxi/u-boot.img of="$device" bs=1k seek=69 conv=notrunc status=none
 	;;
+odroid-c2)
+	[ -e "$imagedir/odroid-c2" ] || die "ODROID-C2 images not installed, apk add u-boot-odroid"
+	$dryrun dd if="$imagedir"/odroid-c2/bl1.bin.hardkernel of="$device" bs=1 count=442 conv=notrunc status=none
+	$dryrun dd if="$imagedir"/odroid-c2/bl1.bin.hardkernel of="$device" bs=512 skip=1 seek=1 conv=notrunc status=none
+	$dryrun dd if="$imagedir"/odroid-c2/u-boot.gxbb of="$device" bs=512 seek=97 conv=notrunc status=none
 esac
 $dryrun sync
 ) || die "U-Boot installation in $device failed"
-- 
2.25.1

---

From: Milan P. Stanić <[email-masked]>
Date: Fri, 28 Feb 2020 21:03:41 +0100

Hi Daniel,

Wouldn't it be better to create separate APKBUILD for this specific
board? Imagine how would look u-boot APKBUILD if it is used to build all
specific u-boots.