Skip to content

Commit 4c5b4ef

Browse files
committed
Don't require using systemd-boot to get automated firmware updates
Using systemd-boot is not a requirement for applying capsule updates. We can make the firmware update a systemd service, which gives us the behavior of running on every `switch-to-configuration` when the capsule update file changes.
1 parent 0739781 commit 4c5b4ef

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Weston and sway have been tested working on Orin devices, but do not work on Xav
129129
### Updating firmware from device
130130
Recent versions of Jetpack (>=5.1) support updating the device firmware from the device using the UEFI Capsule update mechanism.
131131
This can be done as a more convenient alternative to physically attaching to the device and re-running the flash script.
132-
These updates can be performed automatically after a `nixos-rebuild boot` if the `hardware.nvidia-jetpack.bootloader.autoUpdate` setting is set to true and systemd-boot is used.
132+
These updates can be performed automatically after a `nixos-rebuild boot` if the `hardware.nvidia-jetpack.bootloader.autoUpdate` setting is set to true.
133133
Otherwise, the instructions to apply the update manually are below.
134134

135135
To determine if the currently running firmware matches the software, run, `ota-check-firmware`:

modules/flash-script.nix

+25-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ config, pkgs, lib, ... }:
1+
{ config, pkgs, lib, utils, ... }:
22

33
# Convenience package that allows you to set options for the flash script using the NixOS module system.
44
# You could do the overrides yourself if you'd prefer.
@@ -403,23 +403,28 @@ in
403403
}.${cfg.som}
404404
)) else lib.mkOptionDefault [ ];
405405

406-
systemd.services = lib.mkIf (cfg.flashScriptOverrides.targetBoard != null) {
407-
setup-jetson-efi-variables = {
408-
enable = true;
409-
description = "Setup Jetson OTA UEFI variables";
410-
wantedBy = [ "multi-user.target" ];
411-
after = [ "opt-nvidia-esp.mount" ];
412-
serviceConfig.Type = "oneshot";
413-
serviceConfig.ExecStart = "${pkgs.nvidia-jetpack.otaUtils}/bin/ota-setup-efivars ${cfg.flashScriptOverrides.targetBoard}";
414-
};
406+
systemd.services.setup-jetson-efi-variables = lib.mkIf (cfg.flashScriptOverrides.targetBoard != null) {
407+
description = "Setup Jetson OTA UEFI variables";
408+
wantedBy = [ "multi-user.target" ];
409+
after = [ "opt-nvidia-esp.mount" ];
410+
serviceConfig.Type = "oneshot";
411+
serviceConfig.ExecStart = "${pkgs.nvidia-jetpack.otaUtils}/bin/ota-setup-efivars ${cfg.flashScriptOverrides.targetBoard}";
415412
};
416413

417-
boot.loader.systemd-boot.extraInstallCommands = lib.mkIf (cfg.firmware.autoUpdate && cfg.som != null && cfg.flashScriptOverrides.targetBoard != null) ''
418-
# Jetpack 5.0 didn't expose this DMI variable,
419-
if [[ ! -f /sys/devices/virtual/dmi/id/bios_version ]]; then
420-
echo "Unable to determine current Jetson firmware version."
421-
echo "You should reflash the firmware with the new version to ensure compatibility"
422-
else
414+
systemd.services.firmware-update = lib.mkIf (cfg.firmware.autoUpdate && cfg.som != null && cfg.flashScriptOverrides.targetBoard != null) {
415+
wantedBy = [ "multi-user.target" ];
416+
path = [ pkgs.nvidia-jetpack.otaUtils ];
417+
after = [
418+
"${utils.escapeSystemdPath config.boot.loader.efi.efiSysMountPoint}.mount"
419+
"opt-nvidia-esp.mount"
420+
];
421+
unitConfig = {
422+
ConditionPathExists = "/sys/devices/virtual/dmi/id/bios_version";
423+
# This directory is populated by ota-apply-capsule-update, don't run
424+
# if we already have a capsule update present on the ESP.
425+
ConditionDirectoryNotEmpty = "!${config.boot.loader.efi.efiSysMountPoint}/EFI/UpdateCapsule";
426+
};
427+
script = ''
423428
CUR_VER=$(cat /sys/devices/virtual/dmi/id/bios_version)
424429
NEW_VER=${pkgs.nvidia-jetpack.l4tVersion}
425430
@@ -433,12 +438,12 @@ in
433438
# systemd service. Plus, this ota-setup-efivars will be from the
434439
# generation we're switching to, which can contain additional
435440
# fixes/improvements.
436-
${pkgs.nvidia-jetpack.otaUtils}/bin/ota-setup-efivars ${cfg.flashScriptOverrides.targetBoard}
441+
ota-setup-efivars ${cfg.flashScriptOverrides.targetBoard}
437442
438-
${pkgs.nvidia-jetpack.otaUtils}/bin/ota-apply-capsule-update ${config.system.build.jetsonDevicePkgs.uefiCapsuleUpdate}
443+
ota-apply-capsule-update ${config.system.build.jetsonDevicePkgs.uefiCapsuleUpdate}
439444
fi
440-
fi
441-
'';
445+
'';
446+
};
442447

443448
environment.systemPackages = lib.mkIf (cfg.firmware.autoUpdate && cfg.som != null && cfg.flashScriptOverrides.targetBoard != null) [
444449
(pkgs.writeShellScriptBin "ota-apply-capsule-update-included" ''

0 commit comments

Comments
 (0)