Skip to content

Commit 402382d

Browse files
nvidia: move to a 2 stage install
Builds standalone ESP and root partition images for initrd-based flashing. These replace the legacy sdImage approach: instead of a single disk image, we build ESP (FAT32) and root (ext4) as independent compressed images that are written to eMMC partitions created on-device by sgdisk. Signed-off-by: Brian McGillion <bmg.avoin@gmail.com>
1 parent 35cb7d2 commit 402382d

File tree

7 files changed

+692
-294
lines changed

7 files changed

+692
-294
lines changed

modules/reference/hardware/jetpack/nvidia-jetson-orin/default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# Top-level module entry point for the Orin family of chips
55
{
66
imports = [
7-
./partition-template.nix
7+
./flash-images.nix
8+
./initrd-flash.nix
89
./jetson-orin.nix
910
./pci-passthrough-common.nix
1011
./virtualization
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# SPDX-FileCopyrightText: 2022-2026 TII (SSRC) and the Ghaf contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Builds standalone ESP and root partition images for initrd-based flashing.
5+
# These replace the legacy sdImage approach: instead of a single disk image,
6+
# we build ESP (FAT32) and root (ext4) as independent compressed images that
7+
# are written to eMMC partitions created on-device by sgdisk.
8+
#
9+
{
10+
config,
11+
pkgs,
12+
modulesPath,
13+
lib,
14+
...
15+
}:
16+
let
17+
cfg = config.ghaf.hardware.nvidia.orin;
18+
19+
mkESPContentSource = pkgs.replaceVars ./mk-esp-contents.py {
20+
inherit (pkgs.buildPackages) python3;
21+
};
22+
mkESPContent =
23+
pkgs.runCommand "mk-esp-contents"
24+
{
25+
nativeBuildInputs = with pkgs; [
26+
mypy
27+
python3
28+
];
29+
}
30+
''
31+
install -m755 ${mkESPContentSource} $out
32+
mypy \
33+
--no-implicit-optional \
34+
--disallow-untyped-calls \
35+
--disallow-untyped-defs \
36+
$out
37+
'';
38+
39+
fdtPath = "${config.hardware.deviceTree.package}/${config.hardware.deviceTree.name}";
40+
41+
# ESP image: FAT32 with systemd-boot, kernel, initrd, device tree
42+
espSizeMiB = 256;
43+
espSizeBytes = espSizeMiB * 1024 * 1024;
44+
45+
espImage =
46+
pkgs.runCommand "esp.img"
47+
{
48+
nativeBuildInputs = with pkgs; [
49+
dosfstools
50+
mtools
51+
];
52+
}
53+
''
54+
espDir=$(mktemp -d)
55+
${mkESPContent} \
56+
--toplevel ${config.system.build.toplevel} \
57+
--output "$espDir" \
58+
--device-tree ${fdtPath}
59+
60+
truncate -s ${toString espSizeBytes} $out
61+
mkfs.vfat -F 32 -n FIRMWARE $out
62+
cd "$espDir"
63+
for d in $(find . -type d | sort); do
64+
mmd -i $out "::$d" 2>/dev/null || true
65+
done
66+
for f in $(find . -type f); do
67+
mcopy -i $out "$f" "::$f"
68+
done
69+
'';
70+
71+
# Root image: ext4 containing the NixOS closure, auto-sized to contents
72+
rootImage = pkgs.callPackage (modulesPath + "/../lib/make-ext4-fs.nix") {
73+
storePaths = [ config.system.build.toplevel ];
74+
volumeLabel = "NIXOS_ROOT";
75+
populateImageCommands = ''
76+
mkdir -p ./files/etc
77+
echo "${config.system.build.toplevel}" > ./files/etc/.nixos-toplevel
78+
cp ${config.system.build.toplevel}/etc/os-release ./files/etc/os-release
79+
'';
80+
};
81+
in
82+
{
83+
config = lib.mkIf cfg.enable {
84+
boot.loader.grub.enable = false;
85+
86+
fileSystems."/" = {
87+
device = "/dev/disk/by-label/NIXOS_ROOT";
88+
fsType = "ext4";
89+
autoResize = true;
90+
};
91+
92+
fileSystems."/boot" = {
93+
device = "/dev/disk/by-label/FIRMWARE";
94+
fsType = "vfat";
95+
};
96+
97+
system.build.ghafFlashImages =
98+
pkgs.runCommand "ghaf-flash-images"
99+
{
100+
nativeBuildInputs = [ pkgs.zstd ];
101+
}
102+
''
103+
mkdir -p $out
104+
zstd -19 -T$NIX_BUILD_CORES ${espImage} -o $out/esp.img.zst
105+
zstd -19 -T$NIX_BUILD_CORES ${rootImage} -o $out/root.img.zst
106+
'';
107+
};
108+
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# SPDX-FileCopyrightText: 2022-2026 TII (SSRC) and the Ghaf contributors
22
# SPDX-License-Identifier: Apache-2.0
33
#
4-
# Format module for Orin targets — wires ghafImage to sdImage.
4+
# Format module for Orin targets — wires ghafImage to ghafFlashImages.
55
#
66
{ config, ... }:
77
{
8-
imports = [ ./sdimage.nix ];
9-
system.build.ghafImage = config.system.build.sdImage;
8+
system.build.ghafImage = config.system.build.ghafFlashImages;
109
}

0 commit comments

Comments
 (0)