Skip to content

Commit

Permalink
Merge remote-tracking branch 'public/master' into jp514
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfullmer committed Nov 18, 2024
2 parents e8b8412 + 7d5ff42 commit 2e266b5
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 293 deletions.
116 changes: 10 additions & 106 deletions device-pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
{ lib
, dtc
, gcc
, makeInitrd
, nvidia-jetpack
, openssl
, python3
, runCommand
, writeScript
, writeShellApplication
, buildPackages
}:
Expand All @@ -26,57 +21,24 @@ let
inherit (pkgs.nvidia-jetpack)
chipId
flashInitrd
l4tVersion
mkFlashScript
;

inherit (cfg.flashScriptOverrides) flashArgs fuseArgs partitionTemplate;

# This produces a script where we have already called the ./flash.sh script
# with `--no-flash` and produced a file under bootloader/flashcmd.txt.
# This requires setting various BOARD* environment variables to the exact
# board being flashed. These are set by the firmware.variants option.
#
# The output of this should be something we can take anywhere and doesn't
# require any additional signing or other dynamic behavior
mkFlashCmdScript = args:
let
variant =
if builtins.length cfg.firmware.variants != 1
then throw "mkFlashCmdScript requires exactly one Jetson variant set in hardware.nvidia-jetson.firmware.variants"
else builtins.elemAt cfg.firmware.variants 0;

# Use the flash-tools produced by mkFlashScript, we need whatever changes
# the script made, as well as the flashcmd.txt from it
flash-tools-flashcmd = runCommand "flash-tools-flashcmd"
{
# Needed for signing
inherit (cfg.firmware.secureBoot) requiredSystemFeatures;
} ''
export BOARDID=${variant.boardid}
export BOARDSKU=${variant.boardsku}
export FAB=${variant.fab}
export BOARDREV=${variant.boardrev}
${lib.optionalString (variant.chipsku != null) ''
export CHIP_SKU=${variant.chipsku}
''}
export CHIPREV=${variant.chiprev}
${lib.optionalString (variant.ramcode != null) ''
export RAMCODE=${variant.ramcode}
''}
${cfg.firmware.secureBoot.preSignCommands buildPackages}
${mkFlashScript nvidia-jetpack.flash-tools (args // { flashArgs = [ "--no-root-check" "--no-flash" ] ++ (args.flashArgs or flashArgs); }) }
cp -r ./ $out
'';
in
import ./flashcmd-script.nix {
inherit lib;
inherit gcc dtc;
flash-tools = flash-tools-flashcmd;
mkFlashCmdScript = args: import ./flashcmd-script.nix {
inherit lib;
inherit gcc dtc;
flash-tools = nvidia-jetpack.flash-tools-flashcmd.override {
inherit mkFlashScript;
mkFlashScriptArgs = args;
};
};

# With either produce a standard flash script, which does variant detection,
# or if there is only a single variant, will produce a script specialized to
Expand Down Expand Up @@ -123,19 +85,7 @@ let
text = ''
${mkRcmBootScript {
kernelPath = "${config.system.build.kernel}/${config.system.boot.loader.kernelFile}";
initrdPath =
let
signedFirmwareInitrd = makeInitrd {
contents = [{ object = signedFirmware; symlink = "/signed-firmware"; }];
};
in
# The linux kernel supports concatenated initrds where each initrd
# can be optionally compressed with any compression algorithm
# supported by the kernel (initrds don't need to match in
# compression algorithm).
runCommand "combined-initrd" { } ''
cat ${flashInitrd}/initrd ${signedFirmwareInitrd}/initrd > $out
'';
initrdPath = "${flashInitrd}/initrd";
kernelCmdline = "initrd=initrd console=ttyTCU0,115200";
}}
echo
Expand All @@ -145,48 +95,13 @@ let
meta.platforms = [ "x86_64-linux" ];
};

signedFirmware = runCommand "signed-${hostName}-${l4tVersion}"
{
inherit (cfg.firmware.secureBoot) requiredSystemFeatures;
}
(mkFlashScript nvidia-jetpack.flash-tools {
flashCommands = ''
${cfg.firmware.secureBoot.preSignCommands buildPackages}
'' + lib.concatMapStringsSep "\n"
(v: with v; ''
BOARDID=${boardid} BOARDSKU=${boardsku} FAB=${fab} BOARDREV=${boardrev} FUSELEVEL=${fuselevel} CHIPREV=${chiprev} ${lib.optionalString (chipsku != null) "CHIP_SKU=${chipsku}"} ${lib.optionalString (ramcode != null) "RAMCODE=${ramcode}"} ./flash.sh ${lib.optionalString (partitionTemplate != null) "-c flash.xml"} --no-root-check --no-flash --sign ${builtins.toString flashArgs}
outdir=$out/${boardid}-${fab}-${boardsku}-${boardrev}-${if fuselevel == "fuselevel_production" then "1" else "0"}-${chiprev}--
mkdir -p $outdir
cp -v bootloader/signed/flash.idx $outdir/
# Copy files referenced by flash.idx
while IFS=", " read -r partnumber partloc start_location partsize partfile partattrs partsha; do
if [[ "$partfile" != "" ]]; then
if [[ -f "bootloader/signed/$partfile" ]]; then
cp -v "bootloader/signed/$partfile" $outdir/
elif [[ -f "bootloader/$partfile" ]]; then
cp -v "bootloader/$partfile" $outdir/
else
echo "Unable to find $partfile"
exit 1
fi
fi
done < bootloader/signed/flash.idx
rm -rf bootloader/signed
'')
cfg.firmware.variants;
});

fuseScript = writeShellApplication {
name = "fuse-${hostName}";
text = import ./flash-script.nix {
inherit lib;
inherit (nvidia-jetpack) flash-tools;
flashCommands = ''
./odmfuse.sh -i ${chipId} "$@" ${builtins.toString fuseArgs}
./odmfuse.sh -i ${chipId} "$@" ${builtins.toString cfg.flashScriptOverrides.fuseArgs}
'';

# Fuse script needs device tree files, which aren't already present for
Expand All @@ -196,15 +111,4 @@ let
meta.platforms = [ "x86_64-linux" ];
};
in
{
inherit
flashScript
fuseScript
initrdFlashScript
mkFlashCmdScript
mkFlashScriptAuto
mkRcmBootScript
rcmBoot
signedFirmware
;
}
{ inherit flashScript initrdFlashScript fuseScript rcmBoot; }
38 changes: 38 additions & 0 deletions device-pkgs/flash-tools-flashcmd.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{ lib
, pkgs
, runCommand
, cfg
, flash-tools
, mkFlashScript
, mkFlashScriptArgs ? { }
}:

let
variant =
if builtins.length cfg.firmware.variants != 1
then throw "mkFlashCmdScript requires exactly one Jetson variant set in hardware.nvidia-jetson.firmware.variants"
else builtins.elemAt cfg.firmware.variants 0;
in
runCommand "flash-tools-flashcmd"
{
# Needed for signing
inherit (cfg.firmware.secureBoot) requiredSystemFeatures;
} ''
export BOARDID=${variant.boardid}
export BOARDSKU=${variant.boardsku}
export FAB=${variant.fab}
export BOARDREV=${variant.boardrev}
${lib.optionalString (variant.chipsku != null) ''
export CHIP_SKU=${variant.chipsku}
''}
export CHIPREV=${variant.chiprev}
${lib.optionalString (variant.ramcode != null) ''
export RAMCODE=${variant.ramcode}
''}
${cfg.firmware.secureBoot.preSignCommands pkgs}
${mkFlashScript flash-tools (mkFlashScriptArgs // { flashArgs = [ "--no-root-check" "--no-flash" ] ++ (mkFlashScriptArgs.flashArgs or cfg.flashScriptOverrides.flashArgs); }) }
cp -r ./ $out
''
Loading

0 comments on commit 2e266b5

Please sign in to comment.