Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration of mainline kernel to jetpack-nixos #224

Open
wants to merge 74 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
1997a7b
feat: upgrade Jetpack 5.1.2 -> 5.2.3 and l4t 35.4.1 -> 35.5.0
Princemachiavelli Mar 8, 2024
7c2bde8
fix(kernel): re-enable DMI
Princemachiavelli Mar 27, 2024
fea6e5a
chore(ota_helpers): update to follow nv-l4t-bootloader-config
Princemachiavelli Mar 27, 2024
e7e0fed
uefi-firmware: update edk2-uefi-dtb patch
Princemachiavelli Apr 8, 2024
8252591
optee-gen-ekb: add package
Princemachiavelli Apr 17, 2024
bb554dc
optee: add options for FV values and test keys.
Princemachiavelli May 2, 2024
c3091dd
kernel: remove crng_ready patch included in upstream
Princemachiavelli May 6, 2024
265baac
change version of l4t
vadika May 9, 2024
f18c415
Initial port to 36.3
vadika May 10, 2024
7f30968
fix for flash-tool
vadika May 10, 2024
596c0b2
updated CUDA version
vadika May 10, 2024
cbe7387
Fixes for new structure of UEFI sources -- stage one
vadika May 14, 2024
c3ba5c8
Stubbed out UEFI build with out of tree building of the firmware
vadika May 21, 2024
29bdfdd
...
vadika May 21, 2024
b8d301d
small cleanups
vadika May 21, 2024
0d990d2
Added nvidia-oot module to the build tree
vadika May 22, 2024
03fe125
Changed kernel input to kernel.org ref 6.8.y
juliuskoskela May 22, 2024
dd36ac2
Merge pull request #1 from tiiuae/change-kernel-input-to-6.8.1
vadika May 23, 2024
57df521
Kernel modules, cleanups and version fixes
vadika May 23, 2024
de2902d
libvpi2 -> libvpi3
vadika May 24, 2024
6773fdd
Fixes for nix build .#genL4tJson
vadika May 24, 2024
18d662a
l4t-tools build fixes
vadika May 24, 2024
3653318
updated path for device flashing scheme
vadika May 27, 2024
34e21a3
1) change https:// --> git:// in git repos prefetch script, updated r…
vadika May 28, 2024
5504387
kernel version bump to 6.8.11
vadika May 28, 2024
c67d5d9
Aligned paths for flash script
vadika May 28, 2024
402f4bf
changed UEFI build to debug
vadika May 29, 2024
5830b3b
Merge branch 'master' into main
vadika May 30, 2024
c3f1a47
Merge pull request #1 from tiiuae/main
vadika May 30, 2024
5cbc074
Another try with UEFI build
vadika May 30, 2024
73e9b3e
fix dtbo path
vadika May 30, 2024
51c850f
bumped up OP/TEE verbosity for debug purposes
vadika May 30, 2024
7f55aa4
Update optee builder to increase verbosity (take two)
vadika May 30, 2024
734efc3
Adding ATF compile flags: BRANCH_PROTECTION and ARM_ARCH_MINOR
Jun 17, 2024
0cdc717
trying to find the way to flash proper kernel
vadika Jun 24, 2024
a6be18c
Now correct (builded one) kernel is flashed.
vadika Jun 25, 2024
6d64940
Fixes to build the iso_minimal target
vadika Jul 8, 2024
0ee412d
Retain linux-firmware basename
vadika Jul 11, 2024
06ffac2
Bump nixpkgs to nixos-24.05
vadika Jul 11, 2024
4fd2472
Remove mnistCUDNN from cudnn-samples to avoid dependency on vulnerabl…
vadika Jul 11, 2024
7e6382f
Move devicePkgs to the pkgs.nvidia-jetpack package-set and clear up
vadika Jul 12, 2024
fd37aea
Add chipsku to firmware variants type
vadika Jul 12, 2024
e0f505a
Add chipsku to firmware variants type
vadika Jul 12, 2024
d682459
Set RAMCODE for Orin AGX Industrial variant
vadika Jul 12, 2024
4e73f70
Update Orin AGX industrial FAB to 500 to fix initrd flash script
vadika Jul 12, 2024
cc79855
Add Xavier AGX Industrial
vadika Jul 12, 2024
1306023
Fixed fuse script build error (#225)
vadika Jul 12, 2024
ca9ad33
Remove uses of lib.mdDoc (#227)
vadika Jul 12, 2024
2382421
Updated the checksum
vadika Jul 12, 2024
72512a6
Temporary fix for fvForEKB/fvForSSK settings
vadika Jul 17, 2024
6fa42ae
Toggle fvForEKB and fvForSSK in minimal_config
juliuskoskela Jul 24, 2024
8a0e88d
l4t-multimedia: Fix a data race in shutting down dequeue thread
vadika Aug 5, 2024
82c1e48
l4t-multimedia: Fix a data race in shutting down dequeue thread
vadika Aug 5, 2024
466dc79
clean the tree
vadika Aug 5, 2024
2b8178f
Replace pre-built devicetree utilities
vadika Aug 5, 2024
61926f4
cudaPackages.autoAddOpenGLRunpathHook -> autoAddDriverRunpath
vadika Aug 5, 2024
6ba6d27
Merge branch 'anduril:master' into master
vadika Aug 22, 2024
00282b0
Merge branch 'anduril:master' into master
vadika Sep 3, 2024
1e5611d
Update UEFI l4t version to 36.3
Sep 25, 2024
322b9b4
Fixiso_minimal evaluation: OP-TEE option path wrong
Oct 8, 2024
0d4ae99
Update README.md to at least partly describe changes we made
vadika Oct 8, 2024
37519c3
Merge remote-tracking branch 'upstream/master'
vadika Oct 9, 2024
8c44914
HACK: Commenting away NVIDIA OOT related components
Oct 9, 2024
d6e9671
Revert unfinished changes in python-jetson
juliuskoskela Oct 21, 2024
7e31abe
Bump nsight_compute_version in cuda-packages as suggested in error me…
juliuskoskela Oct 21, 2024
8f7ba4f
Remove ill-formatted trace
juliuskoskela Oct 21, 2024
fa88bb1
Refactor uefi-firmware and edk2 related code
juliuskoskela Oct 21, 2024
0e8bda5
Remove erroneous kernel attribute that prevents flash-orin-devkit fro…
juliuskoskela Oct 24, 2024
951d3c1
Correct partitionTemplate paths
Oct 30, 2024
59080ec
Reduce OPTEE log level (TODO: remove patch??)
Oct 30, 2024
0207766
Remove edk2-uefi-dtb.patch from edk2 derivation
Oct 30, 2024
3602353
NVIDIA OOT modules
Oct 30, 2024
c144bad
UnitTestFrameworkPkg: Use TianoCore mirror of subhook submodule
jpruiz84 Nov 8, 2024
04da50a
Merge pull request #3 from jpruiz84/fix_subhook
TanelDettenborn Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This repository packages components from NVIDIA's [Jetpack SDK](https://developer.nvidia.com/embedded/jetpack) for use with NixOS, including:
* Platform firmware flashing scripts
* A 5.10 Linux kernel from NVIDIA, which includes some open-source drivers like nvgpu
* A MAINLINE Linux kernel with out-of-tree drivers from NVIDIA
* An [EDK2-based UEFI firmware](https://github.com/NVIDIA/edk2-nvidia)
* ARM Trusted Firmware / OP-TEE
* Additional packages for:
Expand All @@ -11,7 +11,7 @@ This repository packages components from NVIDIA's [Jetpack SDK](https://develope
- Graphics: Wayland, GBM, EGL, Vulkan
- Power/fan control: nvpmodel, nvfancontrol

This package is based on the Jetpack 5 release, and will only work with devices supported by Jetpack 5.1:
This package is based on the Jetpack 6 release, and will only work with devices supported by Jetpack 6.3:
* Jetson Orin AGX
* Jetson Orin NX
* Jetson Xavier AGX
Expand Down Expand Up @@ -135,8 +135,8 @@ Otherwise, the instructions to apply the update manually are below.
To determine if the currently running firmware matches the software, run, `ota-check-firmware`:
```
$ ota-check-firmware
Current firmware version is: 35.2.1
Current software version is: 35.2.1
Current firmware version is: 35.5.0
Current software version is: 35.5.0
```

If these versions do not match, you can update your firmware using the UEFI Capsule update mechanism. The procedure to do so is below:
Expand Down
5 changes: 3 additions & 2 deletions UPGRADE_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
- [ ] `overlay.nix`
- [ ] `kernel/default.nix`
- [ ] `uefi-firmware.nix`
- [ ] Grep for "sha256 = ", see if there is anything else not covered
- [ ] Grep for "sha256 = " and "hash = ", see if there is anything else not covered
- [ ] Update gitrepos.json using sourceinfo/gitrepos-update.py and result/source_sync.sh from bspSrc.
- [ ] Update the kernel version in `kernel/default.nix` if it chaged.
- [ ] Grep for the previous version strings e.g. "35.4.1"
- [ ] Grep for the previous version strings e.g. "35.5.0"
- [ ] Compare files from `unpackedDebs` before and after
- [ ] Grep for NvOsLibraryLoad in libraries from debs to see if any new packages not already handled in l4t use the function
- [ ] Ensure the soc variants in `modules/flash-script.nix` match those in `jetson_board_spec.cfg` from BSP
Expand Down
260 changes: 122 additions & 138 deletions device-pkgs/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# These come from the device's nixos module arguments, so `pkgs` is actually an
# aarch64 hostPlatform packaget-set.
{ config, pkgs, ... }:
{ config, pkgs, kernel, ... }:

# These must be filled in by a `callPackage` from an x86_64 hostPlatform
# package-set to satisfy being able to run nvidia's prebuilt binaries on an
# x86-compatible platform.
{ lib
, dtc
, gcc
Expand All @@ -16,185 +11,175 @@
, writeScript
, writeShellApplication
, buildPackages
, makeModulesClosure
}:

let
cfg = config.hardware.nvidia-jetpack;
inherit (config.networking) hostName;
hostName = config.networking.hostName;

# We need to grab some packages from the device's aarch64 package set.
# Packages from the device's aarch64 package set
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) ''
mkFlashScript;

inherit (cfg.flashScriptOverrides)
flashArgs
fuseArgs
partitionTemplate;

# Function to create flash command script for a single variant
mkFlashCmdScript = args: let
variant = if builtins.length cfg.firmware.variants != 1
then throw "mkFlashCmdScript requires exactly one Jetson variant set in hardware.nvidia-jetpack.firmware.variants"
else builtins.elemAt cfg.firmware.variants 0;

flash-tools-flashcmd = runCommand "flash-tools-flashcmd" {
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 CHIPREV=${variant.chiprev}
${lib.optionalString (variant.ramcode != null) ''
export RAMCODE=${variant.ramcode}
''}
''}

${cfg.firmware.secureBoot.preSignCommands buildPackages}
${cfg.firmware.secureBoot.preSignCommands buildPackages}

${mkFlashScript nvidia-jetpack.flash-tools (args // { flashArgs = [ "--no-root-check" "--no-flash" ] ++ (args.flashArgs or flashArgs); }) }
${mkFlashScript nvidia-jetpack.flash-tools (args // {
# kernel = kernel;
flashArgs = [ "--no-root-check" "--no-flash" ] ++ (args.flashArgs or flashArgs);
})}

cp -r ./ $out
'';
in
import ./flashcmd-script.nix {
inherit lib;
inherit gcc dtc;
cp -r ./ $out
'';
in
(import ./flashcmd-script.nix) {
inherit lib gcc dtc;
flash-tools = flash-tools-flashcmd;
};

# 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
# that particular variant.
mkFlashScriptAuto = if builtins.length cfg.firmware.variants == 1 then mkFlashCmdScript else (mkFlashScript nvidia-jetpack.flash-tools);
# Function to automatically choose the appropriate flash script
mkFlashScriptAuto = args:
if builtins.length cfg.firmware.variants == 1
then mkFlashCmdScript args
else mkFlashScript nvidia-jetpack.flash-tools args;

# Generate a flash script using the built configuration options set in a NixOS configuration
flashScript = writeShellApplication {
name = "flash-${hostName}";
text = (mkFlashScriptAuto { });
meta.platforms = [ "x86_64-linux" ];
};

# Produces a script that boots a given kernel, initrd, and cmdline using the RCM boot method
# Function to create RCM boot script
mkRcmBootScript = { kernelPath, initrdPath, kernelCmdline }: mkFlashScriptAuto {
# kernel = kernel;
preFlashCommands = ''
cp ${kernelPath} kernel/Image
cp ${initrdPath} bootloader/l4t_initrd.img
cp ${kernel}/Image kernel/Image
cp ${initrdPath}/initrd bootloader/l4t_initrd.img

echo "Kernel: ${kernel}"
echo "Initrd Path: ${initrdPath}"

export CMDLINE="${builtins.toString kernelCmdline}"
export INITRD_IN_BOOTIMG="yes"
'';
flashArgs = [ "--rcm-boot" ] ++ cfg.flashScriptOverrides.flashArgs;
};

# Produces a script which boots into this NixOS system via RCM mode
# TODO: This doesn't work currently because `rcmBoot` would need to be built
# on x86_64, and the machine in `config` should be aarch64-linux
# Generate the main flash script
flashScript = writeShellApplication {
name = "flash-${hostName}";
text = mkFlashScriptAuto { };
meta.platforms = [ "x86_64-linux" ];
};

# Generate RCM boot script
rcmBoot = writeShellApplication {
name = "rcmboot-nixos";
text = mkRcmBootScript {
# See nixpkgs nixos/modules/system/activatation/top-level.nix for standard usage of these paths
kernelPath = "${config.system.build.kernel}/${config.system.boot.loader.kernelFile}";
initrdPath = "${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}";
kernelCmdline = "init=${config.system.build.toplevel}/init initrd=initrd ${toString config.boot.kernelParams}";
};
meta.platforms = [ "x86_64-linux" ];
};

# TODO: The flash script should not have the kernel output in its runtime closure
initrdFlashScript =
writeShellApplication {
name = "initrd-flash-${hostName}";
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
'';
kernelCmdline = "initrd=initrd console=ttyTCU0,115200";
}}
echo
echo "Jetson device should now be flashing and will reboot when complete."
echo "You may watch the progress of this on the device's serial port"
'';
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;
});
# Generate signed firmware
signedFirmware = runCommand "signed-${hostName}-${l4tVersion}" {
inherit (cfg.firmware.secureBoot) requiredSystemFeatures;
} (mkFlashScript nvidia-jetpack.flash-tools {
# kernel = kernel;
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 _ _ _ _ partfile _ _; 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;
});

# Generate initrd flash script
initrdFlashScript = writeShellApplication {
name = "initrd-flash-${hostName}";
text = ''
${mkRcmBootScript {
# kernel = kernel;
kernelPath = "${config.system.build.kernel}/${config.system.boot.loader.kernelFile}";
initrdPath = let
signedFirmwareInitrd = makeInitrd {
contents = [{ object = signedFirmware; symlink = "/signed-firmware"; }];
};
in
runCommand "combined-initrd" { } ''
cat ${flashInitrd}/initrd ${signedFirmwareInitrd}/initrd > $out
'';
kernelCmdline = "initrd=initrd console=ttyTCU0,115200";
}}
echo
echo "Jetson device should now be flashing and will reboot when complete."
echo "You may watch the progress of this on the device's serial port"
echo "#######################################################################"
echo "Kernel: ${config.boot.kernelPackages.kernel}"
echo "#######################################################################"
'';
meta.platforms = [ "x86_64-linux" ];
};

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

# Fuse script needs device tree files, which aren't already present for
# non-devkit boards, so we need to get our built version of them
dtbsDir = config.hardware.deviceTree.package;
};
meta.platforms = [ "x86_64-linux" ];
};

in
{
inherit
Expand All @@ -205,6 +190,5 @@ in
mkFlashScriptAuto
mkRcmBootScript
rcmBoot
signedFirmware
;
signedFirmware;
}
11 changes: 10 additions & 1 deletion device-pkgs/flash-script.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
eksFile ? null
, # Additional DTB overlays to use during device flashing
additionalDtbOverlays ? [ ]
, kernel
, flash-tools
}:
}@ args:

# builtins.trace "flash-script args: ${builtins.toJSON (builtins.removeAttrs args ["lib" "flash-tools"])}" null
(''
set -euo pipefail

Expand Down Expand Up @@ -61,9 +64,15 @@
cp ${eksFile} bootloader/eks_${socType}.img
''}

echo THE KERNEL IS ${kernel}
cp ${kernel}/Image bootloader/Image
cp ${kernel}/Image kernel/Image

${preFlashCommands}

chmod -R u+w .
chmod a-w bootloader/Image
chmod a-w kernel/Image

'' + (if (flashCommands != "") then ''
${flashCommands}
Expand Down
Loading