|
| 1 | +{ callPackage, pkgsBuildHost, runCommand, writeText, writeShellApplication |
| 2 | +, stdenv, dtc, mtdutils, coreutils }: |
| 3 | +let |
| 4 | + uboot = callPackage ./uboot.nix { }; |
| 5 | + opensbi = callPackage ./opensbi.nix { |
| 6 | + withPayload = "${uboot}/u-boot.bin"; |
| 7 | + withFDT = "${uboot}/pine64_star64.dtb"; |
| 8 | + }; |
| 9 | + spl-tool = pkgsBuildHost.callPackage ./spl-tool.nix { }; |
| 10 | + its-file = writeText "star64-uboot-fit-image.its" '' |
| 11 | + /dts-v1/; |
| 12 | +
|
| 13 | + / { |
| 14 | + description = "U-boot-spl FIT image for JH7110 Star64"; |
| 15 | + #address-cells = <2>; |
| 16 | +
|
| 17 | + images { |
| 18 | + firmware { |
| 19 | + description = "u-boot"; |
| 20 | + data = /incbin/("${opensbi}/share/opensbi/lp64/generic/firmware/fw_payload.bin"); |
| 21 | + type = "firmware"; |
| 22 | + arch = "riscv"; |
| 23 | + os = "u-boot"; |
| 24 | + load = <0x0 0x40000000>; |
| 25 | + entry = <0x0 0x40000000>; |
| 26 | + compression = "none"; |
| 27 | + }; |
| 28 | + }; |
| 29 | +
|
| 30 | + configurations { |
| 31 | + default = "config-1"; |
| 32 | +
|
| 33 | + config-1 { |
| 34 | + description = "U-boot-spl FIT config for JH7110 Star64"; |
| 35 | + firmware = "firmware"; |
| 36 | + }; |
| 37 | + }; |
| 38 | + }; |
| 39 | + ''; |
| 40 | +in rec { |
| 41 | + inherit opensbi uboot; |
| 42 | + spl = stdenv.mkDerivation { |
| 43 | + name = "pine64-star64-spl"; |
| 44 | + depsBuildBuild = [ spl-tool ]; |
| 45 | + phases = [ "installPhase" ]; |
| 46 | + installPhase = '' |
| 47 | + mkdir -p $out/share/pine64-star64/ |
| 48 | + ln -s ${uboot}/u-boot-spl.bin . |
| 49 | + spl_tool -c -f ./u-boot-spl.bin |
| 50 | + cp u-boot-spl.bin.normal.out $out/share/pine64-star64/spl.bin |
| 51 | + ''; |
| 52 | + }; |
| 53 | + uboot-fit-image = stdenv.mkDerivation { |
| 54 | + name = "pine64-star64-uboot-fit-image"; |
| 55 | + nativeBuildInputs = [ dtc ]; |
| 56 | + phases = [ "installPhase" ]; |
| 57 | + installPhase = '' |
| 58 | + mkdir -p $out/share/pine64-star64/ |
| 59 | + ${uboot}/mkimage -f ${its-file} -A riscv -O u-boot -T firmware $out/share/pine64-star64/star64_fw_payload.img |
| 60 | + ''; |
| 61 | + }; |
| 62 | + updater-flash = writeShellApplication { |
| 63 | + name = "star64-firmware-update-flash"; |
| 64 | + runtimeInputs = [ mtdutils ]; |
| 65 | + text = '' |
| 66 | + flashcp -v ${spl}/share/pine64-star64/spl.bin /dev/mtd0 |
| 67 | + flashcp -v ${uboot-fit-image}/share/pine64-star64/star64_fw_payload.img /dev/mtd1 |
| 68 | + ''; |
| 69 | + }; |
| 70 | + updater-sd = writeShellApplication { |
| 71 | + name = "star64-firmware-update-sd"; |
| 72 | + runtimeInputs = [ ]; |
| 73 | + text = '' |
| 74 | + dd if=${spl}/share/pine64-star64/spl.bin of=/dev/mmcblk0p1 conv=fsync |
| 75 | + dd if=${uboot-fit-image}/share/pine64-star64/star64_fw_payload.img of=/dev/mmcblk0p2 conv=fsync |
| 76 | + ''; |
| 77 | + }; |
| 78 | +} |
0 commit comments