ecfw: move flashing scripts to separate derivation

master
Adam Joseph 2 years ago
parent e5824b756d
commit 6cf5223d41

@ -99,9 +99,10 @@ in {
# built fromm source
arm-none-eabi-gcc = final.nixpkgsOnBuildForBuild.pkgsCross.arm-embedded.buildPackages.gcc6;
};
inherit (final) ectool;
ecfw-scripts = final.nixpkgsOnBuildForHost.callPackage (import ./ecfw/scripts.nix) {
inherit (final) ectool ecfw;
flashrom-chromebook = final.nixpkgsOnBuildForHost.callPackage ../../util/flashrom { forChromebook = true; };
};

@ -11,8 +11,6 @@
, ncurses
, fetchgit
, buildPackages
, ectool
, flashrom-chromebook
}:
let makeTarget = "build/${boardName}/ec.bin";
@ -75,72 +73,11 @@ in stdenv.mkDerivation (finalAttrs: {
makeTarget
];
flashEcRw = ''
#!/usr/bin/env bash
set -euo pipefail
echo
echo "rebooting EC into the RO image..."
${ectool}/bin/ectool reboot_ec RO
${ectool}/bin/ectool version | grep 'Firmware copy: RO'
echo
echo "enabling RO image write protect..."
${ectool}/bin/ectool flashprotect enable | head -n1 | grep ro_now
${flashrom-chromebook}/bin/flashrom-chromebook -p ec --wp-status | grep "write protect is enabled"
echo
echo "writing the RW image..."
${flashrom-chromebook}/bin/flashrom-chromebook -p ec -i EC_RW -w ${placeholder "out"}/ecfw.bin
${ectool}/bin/ectool version
echo
echo "rebooting into the new RW image..."
${ectool}/bin/ectool reboot_ec RW
sleep 2
${ectool}/bin/ectool version
${ectool}/bin/ectool version | grep 'Firmware copy: RW'
'';
flashEcRo = ''
#!/usr/bin/env bash
set -euo pipefail
echo
echo "making sure you are in the RW image before flashing the RO..."
${ectool}/bin/ectool version | grep 'Firmware copy: RW'
echo
echo "disabling RO image write protect..."
${ectool}/bin/ectool flashprotect disable
${flashrom-chromebook}/bin/flashrom-chromebook -p ec --wp-status | grep "write protect is disabled"
echo
echo "writing the RO image..."
${flashrom-chromebook}/bin/flashrom-chromebook -p ec -i EC_RO -w ${placeholder "out"}/ecfw.bin
${ectool}/bin/ectool version
echo
echo "rebooting into the new RO image..."
${ectool}/bin/ectool reboot_ec RO
sleep 2
${ectool}/bin/ectool version
${ectool}/bin/ectool version | grep 'Firmware copy: RO'
echo
echo "re-enabling RO image write protect..."
${ectool}/bin/ectool flashprotect enable
${flashrom-chromebook}/bin/flashrom-chromebook -p ec --wp-status | grep "write protect is enabled"
'';
passAsFile = [ "getVersion" "flashEcRo" "flashEcRw" ];
passAsFile = [ "getVersion" ];
installPhase = ''
mkdir -p $out/bin
mv ${makeTarget} $out/ecfw.bin
cp $flashEcRoPath $out/bin/flash-ec-ro.sh
cp $flashEcRwPath $out/bin/flash-ec-rw.sh
chmod +x $out/bin/flash-ec-ro.sh $out/bin/flash-ec-rw.sh
'';
meta = with lib; {

@ -0,0 +1,81 @@
{ stdenv
, lib
, runtimeShell
, ecfw
, ectool
, flashrom-chromebook
}:
stdenv.mkDerivation {
pname = "ecfw-scripts";
inherit (ecfw) version;
flashEcRw = ''
#!${runtimeShell}
set -euo pipefail
echo
echo "rebooting EC into the RO image..."
${ectool}/bin/ectool reboot_ec RO
sleep 2
${ectool}/bin/ectool version | grep 'Firmware copy: RO'
echo
echo "enabling RO image write protect..."
${ectool}/bin/ectool flashprotect enable | head -n1 | grep ro_now
${flashrom-chromebook}/bin/flashrom-chromebook -p ec --wp-status | grep "write protect is enabled"
echo
echo "writing the RW image..."
${flashrom-chromebook}/bin/flashrom-chromebook -p ec -i EC_RW -w ${ecfw}/ecfw.bin
${ectool}/bin/ectool version
echo
echo "rebooting into the new RW image..."
${ectool}/bin/ectool reboot_ec RW
sleep 2
${ectool}/bin/ectool version
${ectool}/bin/ectool version | grep 'Firmware copy: RW'
'';
flashEcRo = ''
#!${runtimeShell}
set -euo pipefail
echo
echo "making sure you are in the RW image before flashing the RO..."
${ectool}/bin/ectool version | grep 'Firmware copy: RW'
echo
echo "disabling RO image write protect..."
${ectool}/bin/ectool flashprotect disable
${flashrom-chromebook}/bin/flashrom-chromebook -p ec --wp-status | grep "write protect is disabled"
echo
echo "writing the RO image..."
${flashrom-chromebook}/bin/flashrom-chromebook -p ec -i EC_RO -w ${ecfw}/ecfw.bin
${ectool}/bin/ectool version
echo
echo "rebooting into the new RO image..."
${ectool}/bin/ectool reboot_ec RO
sleep 2
${ectool}/bin/ectool version
${ectool}/bin/ectool version | grep 'Firmware copy: RO'
echo
echo "re-enabling RO image write protect..."
${ectool}/bin/ectool flashprotect enable
${flashrom-chromebook}/bin/flashrom-chromebook -p ec --wp-status | grep "write protect is enabled"
'';
dontUnpack = true;
dontBuild = true;
passAsFile = [ "flashEcRo" "flashEcRw" ];
installPhase = ''
mkdir -p $out/bin
cp $flashEcRoPath $out/bin/flash-ec-ro.sh
cp $flashEcRwPath $out/bin/flash-ec-rw.sh
chmod +x $out/bin/flash-ec-ro.sh $out/bin/flash-ec-rw.sh
'';
}
Loading…
Cancel
Save