Skip to content

Commit

Permalink
Fix the flashing scripts to use the new api
Browse files Browse the repository at this point in the history
The api for the flashing scripts has changed so this is an intermediate
solution to fix that api. Overall the mechanism should be rewritten to
make it a cleaner and more streamlined mechanism.

Signed-off-by: Brian McGillion <[email protected]>
  • Loading branch information
brianmcgillion committed Dec 19, 2024
1 parent dac1787 commit a2c979c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 106 deletions.
39 changes: 20 additions & 19 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
#TODO: carrying the extra patch(es) until merged to unstable
#nixpkgs.url = "github:tiiuae/nixpkgs/nixos-unstable-gbenchmark";
#nixpkgs.url = "flake:mylocalnixpkgs";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
#TODO pinned to the a version to get working
nixpkgs.url = "github:NixOS/nixpkgs/3566ab7246670a43abd2ffa913cc62dad9cdf7d5";

ghafpkgs = {
url = "github:tiiuae/ghafpkgs";
Expand Down Expand Up @@ -114,11 +115,9 @@

nixos-hardware.url = "github:NixOS/nixos-hardware";

jetpack-nixos = {
#url = "github:anduril/jetpack-nixos
url = "github:anduril/jetpack-nixos";
#inputs.nixpkgs.follows = "nixpkgs";
};
#jetpack-nixos.url = "flake:mylocaljetpack";
#pinned to the pr https://github.com/anduril/jetpack-nixos/pull/257 until merged
jetpack-nixos.url = "github:anduril/jetpack-nixos/4dc254268aea59921268206628b9d911b6703e9e";

disko = {
url = "github:nix-community/disko";
Expand Down
66 changes: 1 addition & 65 deletions lib/mk-flash-script/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,6 @@
#
# Function to generate NVIDIA Jetson Orin flash script
{
nixpkgs,
hostConfiguration,
jetpack-nixos,
flash-tools-system,
}:
let
cfg = hostConfiguration.config.hardware.nvidia-jetpack;
inherit (jetpack-nixos.legacyPackages.${flash-tools-system}) flash-tools;

# jetpack-nixos has the cross-compilation set up in a slightly strange way,
# the packages under x86_64-linux are actually cross-compiled packages for
# aarch64-linux. So we will get devicePkgs from x86_64-linux if we are cross
# compiling, otherwise we end up building UEFI firmware etc. binaries used by
# flash-script natively.
isCross =
hostConfiguration.config.nixpkgs.buildPlatform.system
!= hostConfiguration.config.nixpkgs.hostPlatform.system;
devicePkgsSystem = if isCross then "x86_64-linux" else "aarch64-linux";
devicePkgs =
jetpack-nixos.legacyPackages.${devicePkgsSystem}.devicePkgsFromNixosConfig
hostConfiguration.config;

inherit (jetpack-nixos.legacyPackages.${devicePkgsSystem}) l4tVersion;

flashScript = devicePkgs.mkFlashScript {
flash-tools = flash-tools.overrideAttrs (
{
postPatch ? "",
...
}:
{
postPatch = postPatch + cfg.flashScriptOverrides.postPatch;
}
);
preFlashCommands =
nixpkgs.lib.optionalString (flash-tools-system == "aarch64-linux") ''
echo "WARNING! WARNING! WARNING!"
echo "You are trying to run aarch64-linux hosted version of the flash-script."
echo "It runs flashing tools with QEMU using user-mode emulation of x86 cpu."
echo "There are no known reports from anyone who would have gotten this working ever."
echo "If this fails, YOU HAVE BEEN WARNED, and don't open a bug report!"
echo ""
''
+ hostConfiguration.config.ghaf.hardware.nvidia.orin.flashScriptOverrides.preFlashCommands;
};

patchFlashScript =
builtins.replaceStrings
[
"@pzstd@"
"@sed@"
"@patch@"
"@l4tVersion@"
"@isCross@"
]
[
"${nixpkgs.legacyPackages.${flash-tools-system}.zstd}/bin/pzstd"
"${nixpkgs.legacyPackages.${flash-tools-system}.gnused}/bin/sed"
"${nixpkgs.legacyPackages.${flash-tools-system}.patch}/bin/patch"
"${l4tVersion}"
"${if isCross then "true" else "false"}"
];
in
nixpkgs.legacyPackages.${flash-tools-system}.writeShellApplication {
name = "flash-ghaf";
text = patchFlashScript flashScript;
}
hostConfiguration.pkgs.nvidia-jetpack.flashScript
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,12 @@ in
{
config = lib.mkIf cfg.enable {
hardware.nvidia-jetpack.flashScriptOverrides.partitionTemplate = partitionTemplate;

ghaf.hardware.nvidia.orin.flashScriptOverrides.preFlashCommands =
hardware.nvidia-jetpack.flashScriptOverrides.preFlashCommands =
''
echo "============================================================"
echo "ghaf flashing script"
echo "============================================================"
echo "ghaf version: ${config.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 "============================================================"
Expand All @@ -131,7 +128,7 @@ in
#
# In Section: Adaptation to the Carrier Board with HDMI for the Orin
# NX/Nano Modules
@patch@ -p0 < ${./tegra2-mb2-bct-scr.patch}
"${pkgs.pkgsBuildBuild.patch}/bin/patch" -p0 < ${./tegra2-mb2-bct-scr.patch}
''
+ lib.optionalString (!cfg.flashScriptOverrides.onlyQSPI) ''
ESP_OFFSET=$(cat "${images}/esp.offset")
Expand All @@ -141,12 +138,12 @@ in
img="${images}/sd-image/${config.sdImage.imageName}.zst"
echo "Extracting ESP partition to $WORKDIR/bootloader/esp.img ..."
dd if=<(@pzstd@ -d "$img" -c) of="$WORKDIR/bootloader/esp.img" bs=512 iseek="$ESP_OFFSET" count="$ESP_SIZE"
dd if=<("${pkgs.pkgsBuildBuild.zstd}/bin/pzstd" -d "$img" -c) of="$WORKDIR/bootloader/esp.img" bs=512 iseek="$ESP_OFFSET" count="$ESP_SIZE"
echo "Extracting root partition to $WORKDIR/root.img ..."
dd if=<(@pzstd@ -d "$img" -c) of="$WORKDIR/bootloader/root.img" bs=512 iseek="$ROOT_OFFSET" count="$ROOT_SIZE"
dd if=<("${pkgs.pkgsBuildBuild.zstd}/bin/pzstd" -d "$img" -c) of="$WORKDIR/bootloader/root.img" bs=512 iseek="$ROOT_OFFSET" count="$ROOT_SIZE"
echo "Patching flash.xml with absolute paths to esp.img and root.img ..."
@sed@ -i \
"${pkgs.pkgsBuildBuild.gnused}/bin/sed" -i \
-e "s#bootloader/esp.img#$WORKDIR/bootloader/esp.img#" \
-e "s#root.img#$WORKDIR/root.img#" \
-e "s#ESP_SIZE#$((ESP_SIZE * 512))#" \
Expand Down
10 changes: 2 additions & 8 deletions targets/nvidia-jetson-orin/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,18 @@ let
mkFlashScript = import ../../lib/mk-flash-script;
# Generate flash script variant which flashes both QSPI and eMMC
generate-flash-script =
tgt: flash-tools-system:
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:
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
{
Expand Down

0 comments on commit a2c979c

Please sign in to comment.