about summary refs log tree commit diff
path: root/pkgs/misc
diff options
context:
space:
mode:
authorBen Wolsieffer <benwolsieffer@gmail.com>2019-12-05 16:19:26 -0500
committerBen Wolsieffer <benwolsieffer@gmail.com>2019-12-05 22:00:40 -0500
commit884580982851dee0529f018a0bb351f192e6f1d7 (patch)
tree98f857be243a0cfc227760f5843ef86996554b56 /pkgs/misc
parentd00a38aa7008ce89d51d5f7c41d59a575de98e0f (diff)
downloadnixlib-884580982851dee0529f018a0bb351f192e6f1d7.tar
nixlib-884580982851dee0529f018a0bb351f192e6f1d7.tar.gz
nixlib-884580982851dee0529f018a0bb351f192e6f1d7.tar.bz2
nixlib-884580982851dee0529f018a0bb351f192e6f1d7.tar.lz
nixlib-884580982851dee0529f018a0bb351f192e6f1d7.tar.xz
nixlib-884580982851dee0529f018a0bb351f192e6f1d7.tar.zst
nixlib-884580982851dee0529f018a0bb351f192e6f1d7.zip
ubootOdroidC2: init
Diffstat (limited to 'pkgs/misc')
-rw-r--r--pkgs/misc/uboot/default.nix51
1 files changed, 49 insertions, 2 deletions
diff --git a/pkgs/misc/uboot/default.nix b/pkgs/misc/uboot/default.nix
index 8a07461bb2f1..af129ff0f9a4 100644
--- a/pkgs/misc/uboot/default.nix
+++ b/pkgs/misc/uboot/default.nix
@@ -1,6 +1,7 @@
 { stdenv, lib, fetchurl, fetchpatch, fetchFromGitHub, bc, bison, dtc, flex
-, openssl, swig, armTrustedFirmwareAllwinner, armTrustedFirmwareRK3328
-, armTrustedFirmwareRK3399
+, openssl, swig, meson-tools, armTrustedFirmwareAllwinner
+, armTrustedFirmwareRK3328, armTrustedFirmwareRK3399
+, armTrustedFirmwareS905
 , buildPackages
 }:
 
@@ -172,6 +173,52 @@ in {
     filesToInstall = ["u-boot.bin" "SPL"];
   };
 
+  # Flashing instructions:
+  # dd if=bl1.bin.hardkernel of=<device> conv=fsync bs=1 count=442
+  # dd if=bl1.bin.hardkernel of=<device> conv=fsync bs=512 skip=1 seek=1
+  # dd if=u-boot.gxbb of=<device> conv=fsync bs=512 seek=97
+  ubootOdroidC2 = let
+    firmwareBlobs = fetchFromGitHub {
+      owner = "armbian";
+      repo = "odroidc2-blobs";
+      rev = "47c5aac4bcac6f067cebe76e41fb9924d45b429c";
+      sha256 = "1ns0a130yxnxysia8c3q2fgyjp9k0nkr689dxk88qh2vnibgchnp";
+      meta.license = lib.licenses.unfreeRedistributableFirmware;
+    };
+  in buildUBoot {
+    defconfig = "odroid-c2_defconfig";
+    extraMeta.platforms = ["aarch64-linux"];
+    filesToInstall = ["u-boot.bin" "u-boot.gxbb" "${firmwareBlobs}/bl1.bin.hardkernel"];
+    postBuild = ''
+      # BL301 image needs at least 64 bytes of padding after it to place
+      # signing headers (with amlbootsig)
+      truncate -s 64 bl301.padding.bin
+      cat '${firmwareBlobs}/gxb/bl301.bin' bl301.padding.bin > bl301.padded.bin
+      # The downstream fip_create tool adds a custom TOC entry with UUID
+      # AABBCCDD-ABCD-EFEF-ABCD-12345678ABCD for the BL301 image. It turns out
+      # that the firmware blob does not actually care about UUIDs, only the
+      # order the images appear in the file. Because fiptool does not know
+      # about the BL301 UUID, we would have to use the --blob option, which adds
+      # the image to the end of the file, causing the boot to fail. Instead, we
+      # take advantage of the fact that UUIDs are ignored and just put the
+      # images in the right order with the wrong UUIDs. In the command below,
+      # --tb-fw is really --scp-fw and --scp-fw is the BL301 image.
+      #
+      # See https://github.com/afaerber/meson-tools/issues/3 for more
+      # information.
+      '${buildPackages.armTrustedFirmwareTools}/bin/fiptool' create \
+        --align 0x4000 \
+        --tb-fw '${firmwareBlobs}/gxb/bl30.bin' \
+        --scp-fw bl301.padded.bin \
+        --soc-fw '${armTrustedFirmwareS905}/bl31.bin' \
+        --nt-fw u-boot.bin \
+        fip.bin
+      cat '${firmwareBlobs}/gxb/bl2.package' fip.bin > boot_new.bin
+      '${buildPackages.meson-tools}/bin/amlbootsig' boot_new.bin u-boot.img
+      dd if=u-boot.img of=u-boot.gxbb bs=512 skip=96
+    '';
+  };
+
   ubootOdroidXU3 = buildUBoot {
     defconfig = "odroid-xu3_defconfig";
     extraMeta.platforms = ["armv7l-linux"];