Skip to content

Commit

Permalink
dummy tmp patch
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGillion <[email protected]>
  • Loading branch information
brianmcgillion committed Dec 19, 2024
1 parent dac1787 commit 464b151
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 115 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
92 changes: 92 additions & 0 deletions lib/mk-flash-script/backup.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
#
# 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;

inherit (hostConfiguration) pkgs;
inherit (pkgs.nvidia-jetpack) mkFlashScript;

# 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;
inherit (pkgs.nvidia-jetpack) mkFlashScript;

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;

flashScript = (
mkFlashScript {
inherit flash-tools;
args = [ ];
# = 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 mkFlashScript flash-tools {inherit preFlashCommands;};

}
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
19 changes: 2 additions & 17 deletions targets/nvidia-jetson-orin/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,16 @@ let
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
{
Expand All @@ -188,17 +182,8 @@ in

packages = {
aarch64-linux =
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-qspi" (generate-flash-qspi t "aarch64-linux")) targets
);
# should only build images as the flashers are not supported on aarch64-linux
builtins.listToAttrs (map (t: lib.nameValuePair t.name t.package) targets);
x86_64-linux =
builtins.listToAttrs (map (t: lib.nameValuePair t.name t.package) crossTargets)
// builtins.listToAttrs (
Expand Down

0 comments on commit 464b151

Please sign in to comment.