Skip to content

jetson-orin: use XML-aware splicing for flash partition layout#1849

Open
Mic92 wants to merge 1 commit intomainfrom
splice-flash-xml
Open

jetson-orin: use XML-aware splicing for flash partition layout#1849
Mic92 wants to merge 1 commit intomainfrom
splice-flash-xml

Conversation

@Mic92
Copy link
Contributor

@Mic92 Mic92 commented Mar 23, 2026

Add splice-flash-xml.py, a Python script that replaces the partitions in NVIDIA's flash XML with a custom layout defined in JSON. This replaces fragile line-count based head/tail splicing that breaks when the upstream BSP XML changes.

Convert partition-template.nix to use the new script. The partition layout is now defined as structured Nix data serialized to JSON. Partition sizes are injected at build time from sdImage metadata via --set instead of flash-time sed substitution.

This has been split from #1847

Description of Changes

Type of Change

  • New Feature
  • Bug Fix
  • Improvement / Refactor

Related Issues / Tickets

Checklist

  • Clear summary in PR description
  • Detailed and meaningful commit message(s)
  • Commits are logically organized and squashed if appropriate
  • Contribution guidelines followed
  • Ghaf documentation updated with the commit - https://tiiuae.github.io/ghaf/
  • Author has run make-checks and it passes
  • All automatic GitHub Action checks pass - see actions
  • Author has added reviewers and removed PR draft status

Testing Instructions

Applicable Targets

  • Orin AGX aarch64
  • Orin NX aarch64
  • Lenovo X1 x86_64
  • Dell Latitude x86_64
  • System 76 x86_64

Installation Method

  • Requires full re-installation
  • Can be updated with nixos-rebuild ... switch
  • Other:

Test Steps To Verify:

  1. ...

in
pkgs.runCommand "flash.xml" { } (
''
head -n ${toString partitionTemplateReplaceRange.firstLineCount} ${xmlFile} >"$out"
Copy link
Contributor Author

@Mic92 Mic92 Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that seemed a bit fragile, hence the PR

@Mic92
Copy link
Contributor Author

Mic92 commented Mar 23, 2026

still waiting for the image to build....

@Mic92 Mic92 marked this pull request as ready for review March 23, 2026 20:20
@Mic92 Mic92 requested a review from vunnyso March 23, 2026 20:20
@Mic92
Copy link
Contributor Author

Mic92 commented Mar 23, 2026

Image build & flashing works.

Copy link
Contributor

@TanelDettenborn TanelDettenborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR breaks NX QSPI flash. I have done a quick skim but have not been able to pinpoint the root cause. Dropping this comment now to ensure this is not merged to mainline.

@vunnyso vunnyso self-requested a review March 24, 2026 09:05
@Mic92 Mic92 marked this pull request as draft March 24, 2026 13:52
@Mic92
Copy link
Contributor Author

Mic92 commented Mar 24, 2026

This PR breaks NX QSPI flash. I have done a quick skim but have not been able to pinpoint the root cause. Dropping this comment now to ensure this is not merged to mainline.

@TanelDettenborn do you have a chance to dump out the xml it produced vs. the original one?

@Mic92
Copy link
Contributor Author

Mic92 commented Mar 24, 2026

@TanelDettenborn I wasn't able to test onlyQSPI properly, because I don't own the hardware. I could try generate the xml and see if there is something outstanding.

@TanelDettenborn
Copy link
Contributor

I should have been more precise with my words. Technically, the QSPI flash on the NX is failing, but it doesn't even reach the actual flashing phase.

To reproduce the issue, execute: nix build .#nvidia-jetson-orin-nx-debug-from-x86_64-flash-qspi

I've compared the XML files, and the only difference appears to be the XML declaration. The new version explicitly defines encoding='utf-8', whereas the old version did not define an encoding at all.

Add splice-flash-xml.py, a Python script that replaces the
<device type="sdmmc_user"> partitions in NVIDIA's flash XML with a
custom layout defined in JSON. This replaces fragile line-count based
head/tail splicing that breaks when the upstream BSP XML changes.

Convert partition-template.nix to use the new script. The partition
layout is now defined as structured Nix data serialized to JSON.
Partition sizes are injected at build time from sdImage metadata
via --set instead of flash-time sed substitution.

Features:
  --set PARTITION.FIELD=VALUE  override partition child element values
  --remove-device              remove sdmmc_user device (QSPI-only)
Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
@Mic92
Copy link
Contributor Author

Mic92 commented Mar 24, 2026

Root cause: tree.write(output, xml_declaration=True, encoding="unicode") emits <?xml version='1.0' encoding='utf-8'?> but NVIDIA's original XML has <?xml version="1.0"?> (no encoding attribute).

Fixed in #1811 by writing the declaration manually:

with open(output, "w") as f:
    f.write('<?xml version="1.0"?>\n')
    tree.write(f, xml_declaration=False, encoding="unicode")
    f.write("\n")

@Mic92 Mic92 force-pushed the splice-flash-xml branch from 3239717 to 7d431a6 Compare March 24, 2026 22:35
@Mic92 Mic92 marked this pull request as ready for review March 24, 2026 22:38
@Mic92 Mic92 added the Needs Testing CI Team to pre-verify label Mar 25, 2026
Copy link
Contributor

@TanelDettenborn TanelDettenborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smoke tested NX and flash is working.

If testing does not turn up anything, LGTM.

@leivos-unikie
Copy link
Contributor

Tested on Orin AGX

nix build .#packages.x86_64-linux.nvidia-jetson-orin-agx-debug-from-x86_64-flash-script
sudo ./result/bin/flash-orin-agx-devkit

  • firewall.service fails in net-vm and admin-vm
  • USB-eth / WiFi passthrough to net-vm is broken
  • Eth connection to ghaf-host via RJ45 connector works

@leivos-unikie leivos-unikie added bug on Orin AGX Cross Issues found on NVIDIA Jetson AGX Orin cross-compiled while checking this PR and removed Needs Testing CI Team to pre-verify labels Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug on Orin AGX Cross Issues found on NVIDIA Jetson AGX Orin cross-compiled while checking this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants