Skip to content

Commit 9bcd9be

Browse files
committed
jetson-orin: add generic LUKS flash flow for upstream 6.6 targets
Add opt-in Orin disk encryption targets that reencrypt APP with a shared passphrase during legacy flashing, wire initrd LUKS root mapping, and enable required dm-crypt/device-mapper kernel config for upstream-6-6. Update build docs and target matrix to use the correct flash entrypoint for LUKS targets. Signed-off-by: vadik likholetov <vadikas@gmail.com>
1 parent dd80ded commit 9bcd9be

File tree

5 files changed

+180
-4
lines changed

5 files changed

+180
-4
lines changed

docs/src/content/docs/ghaf/dev/ref/build_and_run.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ This is the primary reference device for Ghaf on AArch64 architecture, built usi
9090
# For 32GB AGX version (cross-compiled):
9191
nix build .#nvidia-jetson-orin-agx-debug-from-x86_64-flash-script
9292

93+
# For 32GB AGX with generic LUKS passphrase rootfs encryption:
94+
nix build .#nvidia-jetson-orin-agx-debug-luks-from-x86_64-flash-script
95+
9396
# For 64GB AGX version (cross-compiled):
9497
nix build .#nvidia-jetson-orin-agx64-debug-from-x86_64-flash-script
9598
```
@@ -107,6 +110,16 @@ This is the primary reference device for Ghaf on AArch64 architecture, built usi
107110
sudo ./flash.sh
108111
```
109112

113+
For `*-luks-*` targets, use the legacy flashing entrypoint so rootfs can be
114+
encrypted before APP is written:
115+
116+
```sh
117+
sudo ./result/bin/flash-ghaf-host
118+
```
119+
120+
This prompts for a shared LUKS passphrase, encrypts the extracted root image,
121+
and then flashes it. On boot, initrd prompts for the same passphrase.
122+
110123
## Alternative Build Targets
111124

112125
## Virtual Machine (For Testing)

docs/src/content/docs/ghaf/dev/ref/cross_compilation.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The NVIDIA Jetson family represents Ghaf's primary AArch64 platform with full cr
2424
```sh
2525
# Debug variants
2626
nix build .#nvidia-jetson-orin-agx-debug-from-x86_64
27+
nix build .#nvidia-jetson-orin-agx-debug-luks-from-x86_64
2728
nix build .#nvidia-jetson-orin-agx-debug-nodemoapps-from-x86_64
2829

2930
# Release variants
@@ -32,6 +33,7 @@ nix build .#nvidia-jetson-orin-agx-release-nodemoapps-from-x86_64
3233

3334
# Flash script generation
3435
nix build .#nvidia-jetson-orin-agx-debug-from-x86_64-flash-script
36+
nix build .#nvidia-jetson-orin-agx-debug-luks-from-x86_64-flash-script
3537
```
3638

3739
#### Jetson AGX Orin (64GB)

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ in
4848
type = types.str;
4949
default = "bsp-default";
5050
};
51+
52+
diskEncryption = {
53+
enable = mkEnableOption "generic LUKS root filesystem encryption for eMMC APP partition";
54+
55+
mode = mkOption {
56+
description = "Disk encryption mode for Jetson root filesystem";
57+
type = types.enum [ "generic-luks-passphrase" ];
58+
default = "generic-luks-passphrase";
59+
};
60+
61+
mapperName = mkOption {
62+
description = "Mapped device name used by initrd after LUKS unlock";
63+
type = types.str;
64+
default = "cryptroot";
65+
};
66+
};
5167
};
5268

5369
config = mkIf cfg.enable {
@@ -85,7 +101,73 @@ in
85101
VIRTIO_VSOCKETS_COMMON = yes;
86102
};
87103
}
104+
]
105+
++ lib.optionals (cfg.diskEncryption.enable && cfg.kernelVersion == "upstream-6-6") [
106+
{
107+
name = "dm-crypt-config";
108+
patch = null;
109+
structuredExtraConfig = with lib.kernel; {
110+
BLK_DEV_DM = yes;
111+
DM_BUFIO = yes;
112+
DM_BIO_PRISON = yes;
113+
DM_CRYPT = yes;
114+
CRYPTO_USER_API = yes;
115+
CRYPTO_USER_API_HASH = yes;
116+
CRYPTO_USER_API_SKCIPHER = yes;
117+
CRYPTO_XTS = yes;
118+
};
119+
}
88120
];
121+
122+
};
123+
124+
boot.initrd = mkIf cfg.diskEncryption.enable {
125+
# Keep module selection aligned with the Orin JetPack baseline and avoid
126+
# requesting dm-crypt as a loadable module for upstream-6-6.
127+
availableKernelModules = lib.mkForce [
128+
"xhci-tegra"
129+
"ucsi_ccg"
130+
"typec_ucsi"
131+
"typec"
132+
"nvme"
133+
"tegra_mce"
134+
"phy-tegra-xusb"
135+
"i2c-tegra"
136+
"fusb301"
137+
"phy_tegra194_p2u"
138+
"pcie_tegra194"
139+
"nvpps"
140+
"nvethernet"
141+
];
142+
kernelModules = lib.mkForce [ ];
143+
# algif_skcipher is not available with the upstream-6-6 kernel variant
144+
# used by current Orin reference targets.
145+
luks.cryptoModules = lib.mkForce [
146+
"aes"
147+
"aes_generic"
148+
"cbc"
149+
"xts"
150+
"sha1"
151+
"sha256"
152+
"sha512"
153+
"af_alg"
154+
];
155+
luks.devices.${cfg.diskEncryption.mapperName} = {
156+
device = "/dev/mmcblk0p1";
157+
allowDiscards = true;
158+
};
159+
160+
systemd.services."systemd-cryptsetup@${cfg.diskEncryption.mapperName}".after = [
161+
"initrd-root-device.target"
162+
"cryptsetup.target"
163+
];
164+
};
165+
166+
fileSystems = mkIf cfg.diskEncryption.enable {
167+
"/" = lib.mkForce {
168+
device = "/dev/mapper/${cfg.diskEncryption.mapperName}";
169+
fsType = "ext4";
170+
};
89171
};
90172

91173
services.nvpmodel = {

modules/reference/hardware/jetpack/nvidia-jetson-orin/partition-template.nix

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ let
133133
runtimeInputs = [
134134
pkgs.pkgsBuildBuild.zstd
135135
pkgs.pkgsBuildBuild.gnused
136+
pkgs.pkgsBuildBuild.cryptsetup
136137
];
137138
text = ''
138139
echo "============================================================"
@@ -166,15 +167,69 @@ let
166167
bs=512 iseek="$ESP_OFFSET" count="$ESP_SIZE" status=progress
167168
168169
echo "Extracting root partition..."
170+
ROOT_IMAGE_PATH="$WORKDIR/bootloader/root.img"
171+
${lib.optionalString cfg.diskEncryption.enable ''
172+
ROOT_IMAGE_PATH="$WORKDIR/bootloader/root.enc.img"
173+
''}
169174
dd if=<(pzstd -d "$img" -c) \
170-
of="$WORKDIR/bootloader/root.img" \
175+
of="$ROOT_IMAGE_PATH" \
171176
bs=512 iseek="$ROOT_OFFSET" count="$ROOT_SIZE" status=progress
172177
178+
${lib.optionalString cfg.diskEncryption.enable ''
179+
echo ""
180+
echo "Generic LUKS rootfs encryption is enabled."
181+
GHAF_SKIP_LUKS_ENCRYPTION=0
182+
183+
if [ -n "''${GHAF_LUKS_PASSPHRASE-}" ]; then
184+
GHAF_LUKS_PASSPHRASE_CONFIRM="$GHAF_LUKS_PASSPHRASE"
185+
elif [ -t 0 ] && [ -t 1 ]; then
186+
while true; do
187+
read -r -s -p "Enter shared LUKS passphrase: " GHAF_LUKS_PASSPHRASE
188+
echo ""
189+
read -r -s -p "Confirm shared LUKS passphrase: " GHAF_LUKS_PASSPHRASE_CONFIRM
190+
echo ""
191+
192+
if [ -z "$GHAF_LUKS_PASSPHRASE" ]; then
193+
echo "Passphrase cannot be empty."
194+
continue
195+
fi
196+
197+
if [ "$GHAF_LUKS_PASSPHRASE" != "$GHAF_LUKS_PASSPHRASE_CONFIRM" ]; then
198+
echo "Passphrases do not match. Try again."
199+
continue
200+
fi
201+
202+
break
203+
done
204+
else
205+
GHAF_SKIP_LUKS_ENCRYPTION=1
206+
echo "Non-interactive environment without GHAF_LUKS_PASSPHRASE; skipping root image encryption."
207+
fi
208+
209+
if [ "$GHAF_SKIP_LUKS_ENCRYPTION" -eq 0 ]; then
210+
GHAF_LUKS_PASSPHRASE_FILE=$(mktemp "$WORKDIR/.luks-passphrase.XXXXXX")
211+
chmod 600 "$GHAF_LUKS_PASSPHRASE_FILE"
212+
printf '%s' "$GHAF_LUKS_PASSPHRASE" > "$GHAF_LUKS_PASSPHRASE_FILE"
213+
unset GHAF_LUKS_PASSPHRASE GHAF_LUKS_PASSPHRASE_CONFIRM
214+
215+
echo "Encrypting extracted root image with LUKS2 ..."
216+
cryptsetup reencrypt \
217+
--encrypt \
218+
--type luks2 \
219+
--batch-mode \
220+
--reduce-device-size $((16 * 1024 * 1024)) \
221+
--key-file "$GHAF_LUKS_PASSPHRASE_FILE" \
222+
"$ROOT_IMAGE_PATH"
223+
224+
rm -f "$GHAF_LUKS_PASSPHRASE_FILE"
225+
fi
226+
''}
227+
173228
echo ""
174229
echo "Patching flash.xml with image paths and sizes..."
175230
sed -i \
176231
-e "s#bootloader/esp.img#$WORKDIR/bootloader/esp.img#" \
177-
-e "s#root.img#$WORKDIR/bootloader/root.img#" \
232+
-e "s#root.img#$ROOT_IMAGE_PATH#" \
178233
-e "s#ESP_SIZE#$((ESP_SIZE * 512))#" \
179234
-e "s#ROOT_SIZE#$((ROOT_SIZE * 512))#" \
180235
flash.xml

targets/nvidia-jetson-orin/flake-module.nix

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,27 @@ let
174174
package = hostConfiguration.config.system.build.ghafImage;
175175
};
176176

177+
generate-luks =
178+
tgt:
179+
tgt
180+
// rec {
181+
name = tgt.name + "-luks";
182+
hostConfiguration = tgt.hostConfiguration.extendModules {
183+
modules = [
184+
{
185+
ghaf.hardware.nvidia.orin.diskEncryption.enable = true;
186+
}
187+
];
188+
};
189+
package = hostConfiguration.config.system.build.ghafImage;
190+
};
191+
177192
# Add nodemoapps targets
178-
targets = target-configs ++ (map generate-nodemoapps target-configs);
193+
targets =
194+
target-configs
195+
++ (map generate-nodemoapps target-configs)
196+
++ (map generate-luks target-configs)
197+
++ (map (t: generate-luks (generate-nodemoapps t)) target-configs);
179198
crossTargets = map generate-cross-from-x86_64 targets;
180199
in
181200
{
@@ -191,7 +210,12 @@ in
191210
// builtins.listToAttrs (
192211
map (
193212
t:
194-
lib.nameValuePair "${t.name}-flash-script" t.hostConfiguration.pkgs.nvidia-jetpack.legacyFlashScript
213+
lib.nameValuePair "${t.name}-flash-script" (
214+
if t.hostConfiguration.config.ghaf.hardware.nvidia.orin.diskEncryption.enable then
215+
t.hostConfiguration.pkgs.nvidia-jetpack.legacyFlashScript
216+
else
217+
t.hostConfiguration.pkgs.nvidia-jetpack.flashScript
218+
)
195219
) crossTargets
196220
)
197221
// builtins.listToAttrs (

0 commit comments

Comments
 (0)