Skip to content

Commit

Permalink
Orin AGX/NX: Add QSPI only variant of flash script
Browse files Browse the repository at this point in the history
Add variant of flash script, which only flashes QSPI partitions, and not
eMMC at all. Also does not build boot & root images so it is faster and
lighter to build.

Signed-off-by: Mika Tammi <[email protected]>
  • Loading branch information
Mika Tammi authored and brianmcgillion committed Oct 11, 2023
1 parent aac908b commit 2044163
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 37 deletions.
4 changes: 4 additions & 0 deletions modules/hardware/nvidia-jetson-orin/jetson-orin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ in
# Enable the Orin boards
enable = mkEnableOption "Orin hardware";

flashScriptOverrides.onlyQSPI =
mkEnableOption
"to only flash QSPI partitions, i.e. disable flashing of boot and root partitions to eMMC";

flashScriptOverrides.preFlashCommands = mkOption {
description = "Commands to run before the actual flashing";
type = types.str;
Expand Down
92 changes: 57 additions & 35 deletions modules/hardware/nvidia-jetson-orin/partition-template.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,47 +76,69 @@
# of the <device type="sdmmc_user" ...> </device> XML-tag), from the
# NVIDIA-supplied flash_t234_qspi_sdmmc.xml, with the partitions specified in
# the above partitionsEmmc variable.
partitionTemplateReplaceRange = {
firstLineCount = 588;
lastLineCount = 2;
};
partitionTemplate = pkgs.runCommand "flash.xml" {} ''
head -n ${builtins.toString partitionTemplateReplaceRange.firstLineCount} ${pkgs.nvidia-jetpack.bspSrc}/bootloader/t186ref/cfg/flash_t234_qspi_sdmmc.xml >$out
partitionTemplateReplaceRange =
if !cfg.flashScriptOverrides.onlyQSPI
then {
firstLineCount = 588;
lastLineCount = 2;
}
else {
# If we don't flash anything to eMMC, then we don't need to have the
# <device type="sdmmc_user" ...> </device> XML-tag at all.
firstLineCount = 587;
lastLineCount = 1;
};
partitionTemplate = pkgs.runCommand "flash.xml" {} (''
head -n ${builtins.toString partitionTemplateReplaceRange.firstLineCount} ${pkgs.nvidia-jetpack.bspSrc}/bootloader/t186ref/cfg/flash_t234_qspi_sdmmc.xml >"$out"
# Replace the section for sdmmc-device with our own section
cat ${partitionsEmmc} >>$out
''
+ lib.optionalString (!cfg.flashScriptOverrides.onlyQSPI) ''
tail -n ${builtins.toString partitionTemplateReplaceRange.lastLineCount} ${pkgs.nvidia-jetpack.bspSrc}/bootloader/t186ref/cfg/flash_t234_qspi_sdmmc.xml >>$out
'';
# Replace the section for sdmmc-device with our own section
cat ${partitionsEmmc} >>"$out"
''
+ ''
tail -n ${builtins.toString partitionTemplateReplaceRange.lastLineCount} ${pkgs.nvidia-jetpack.bspSrc}/bootloader/t186ref/cfg/flash_t234_qspi_sdmmc.xml >>"$out"
'');
in
with lib; {
config = mkIf cfg.enable {
hardware.nvidia-jetpack.flashScriptOverrides.partitionTemplate = partitionTemplate;

ghaf.hardware.nvidia.orin.flashScriptOverrides.preFlashCommands = ''
echo "============================================================"
echo "ghaf flashing script"
echo "============================================================"
echo "ghaf version: ${lib.ghaf.version}"
echo "cross-compiled build: @isCross@"
echo "l4tVersion: @l4tVersion@"
echo "som: ${config.hardware.nvidia-jetpack.som}"
echo "carrierBoard: ${config.hardware.nvidia-jetpack.carrierBoard}"
echo "============================================================"
echo ""
echo "Working dir: $WORKDIR"
echo "Removing bootlodaer/esp.img if it exists ..."
rm -fv "$WORKDIR/bootloader/esp.img"
mkdir -pv "$WORKDIR/bootloader"
echo "Decompressing ${images}/esp.img.zst into $WORKDIR/bootloader/esp.img ..."
@pzstd@ -d "${images}/esp.img.zst" -o "$WORKDIR/bootloader/esp.img"
echo "Decompressing ${images}/root.img.zst into $WORKDIR/root.img ..."
@pzstd@ -d "${images}/root.img.zst" -o "$WORKDIR/root.img"
echo "Patching flash.xml with absolute paths to esp.img and root.img ..."
@sed@ -i -e "s#bootloader/esp.img#$WORKDIR/bootloader/esp.img#" -e "s#root.img#$WORKDIR/root.img#" flash.xml
echo "Ready to flash!"
echo "============================================================"
echo ""
'';
ghaf.hardware.nvidia.orin.flashScriptOverrides.preFlashCommands =
''
echo "============================================================"
echo "ghaf flashing script"
echo "============================================================"
echo "ghaf version: ${lib.ghaf.version}"
echo "cross-compiled build: @isCross@"
echo "l4tVersion: @l4tVersion@"
echo "som: ${config.hardware.nvidia-jetpack.som}"
echo "carrierBoard: ${config.hardware.nvidia-jetpack.carrierBoard}"
echo "============================================================"
echo ""
echo "Working dir: $WORKDIR"
echo "Removing bootlodaer/esp.img if it exists ..."
rm -fv "$WORKDIR/bootloader/esp.img"
mkdir -pv "$WORKDIR/bootloader"
''
+ lib.optionalString (!cfg.flashScriptOverrides.onlyQSPI) ''
echo "Decompressing ${images}/esp.img.zst into $WORKDIR/bootloader/esp.img ..."
@pzstd@ -d "${images}/esp.img.zst" -o "$WORKDIR/bootloader/esp.img"
echo "Decompressing ${images}/root.img.zst into $WORKDIR/root.img ..."
@pzstd@ -d "${images}/root.img.zst" -o "$WORKDIR/root.img"
echo "Patching flash.xml with absolute paths to esp.img and root.img ..."
@sed@ -i -e "s#bootloader/esp.img#$WORKDIR/bootloader/esp.img#" -e "s#root.img#$WORKDIR/root.img#" flash.xml
''
+ lib.optionalString cfg.flashScriptOverrides.onlyQSPI ''
echo "Flashing QSPI only, boot and root images not included."
''
+ ''
echo "Ready to flash!"
echo "============================================================"
echo ""
'';
};
}
22 changes: 20 additions & 2 deletions targets/nvidia-jetson-orin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,29 @@
targets = baseTargets ++ (map generate-nodemoapps baseTargets);
crossTargets = map generate-cross-from-x86_64 targets;
mkFlashScript = import ../../lib/mk-flash-script;
# Generate flash script variant which flashes both QSPI and eMMC
generate-flash-script = tgt: flash-tools-system:
mkFlashScript {
inherit nixpkgs;
inherit (tgt) hostConfiguration;
inherit jetpack-nixos;
inherit flash-tools-system;
};
# Generate flash script variant which flashes QSPI only. Useful for Orin NX
# and non-eMMC based development.
generate-flash-qspi = tgt: flash-tools-system:
mkFlashScript {
inherit nixpkgs;
hostConfiguration = tgt.hostConfiguration.extendModules {
modules = [
{
ghaf.hardware.nvidia.orin.flashScriptOverrides.onlyQSPI = true;
}
];
};
inherit jetpack-nixos;
inherit flash-tools-system;
};
in {
nixosConfigurations =
builtins.listToAttrs (map (t: lib.nameValuePair t.name t.hostConfiguration) (targets ++ crossTargets));
Expand All @@ -144,9 +160,11 @@ in {
builtins.listToAttrs (map (t: lib.nameValuePair t.name t.package) targets)
# EXPERIMENTAL: The aarch64-linux hosted flashing support is experimental
# and it simply might not work. Providing the script anyway
// builtins.listToAttrs (map (t: lib.nameValuePair "${t.name}-flash-script" (generate-flash-script t "aarch64-linux")) targets);
// builtins.listToAttrs (map (t: lib.nameValuePair "${t.name}-flash-script" (generate-flash-script t "aarch64-linux")) targets)
// builtins.listToAttrs (map (t: lib.nameValuePair "${t.name}-flash-qspi" (generate-flash-qspi t "aarch64-linux")) targets);
x86_64-linux =
builtins.listToAttrs (map (t: lib.nameValuePair t.name t.package) crossTargets)
// builtins.listToAttrs (map (t: lib.nameValuePair "${t.name}-flash-script" (generate-flash-script t "x86_64-linux")) (targets ++ crossTargets));
// builtins.listToAttrs (map (t: lib.nameValuePair "${t.name}-flash-script" (generate-flash-script t "x86_64-linux")) (targets ++ crossTargets))
// builtins.listToAttrs (map (t: lib.nameValuePair "${t.name}-flash-qspi" (generate-flash-qspi t "x86_64-linux")) (targets ++ crossTargets));
};
}

0 comments on commit 2044163

Please sign in to comment.