Skip to content

feat(libgpod): write the iPod nano 6G/7G firmware categories and schema level - #78

Open
Pred8or wants to merge 8 commits into
jvgomg:mainfrom
Pred8or:pr/3-nano7-accept
Open

Pred8or wants to merge 8 commits into
jvgomg:mainfrom
Pred8or:pr/3-nano7-accept

Conversation

@Pred8or

@Pred8or Pred8or commented Oct 28, 2026 •

Copy link
Copy Markdown

Part 3 of 8 for iPod nano 7th generation support (overview: #75). Stacked on #77: until that merges, this PR also shows its commits; only the commits named below are new here.

Branch pr/3-nano7-accept (2 commits: caf1d7c, bb0f779). Review after PR 2.

By swapping database files on my nano 7G I found what its firmware needs to show a library: six hidden "category" playlists (Music, Videos, Movies, TV Shows, Audiobooks, Rentals) and the SQLite schema level iTunes uses. Either one alone is not enough.

For HashAB devices that are not iOS devices, the libgpod patch now:

  • adds the columns iTunes' Library.itdb has beyond libgpod's schema, and names the columns in its inserts;
  • writes version_info 1.117, Genius user_version 2, and runs the device's post-process commands (set 25 → user_version 26);
  • keeps two dataset-5 header fields as read (libgpod used to turn the Videos category into a normal playlist);
  • writes one hidden smart playlist per category and adds missing ones with iTunes' rules;
  • makes itdb_write() fail before replacing any file if a post-process command is missing or fails, or an insert or commit fails. Other devices behave as before.

Both models stay read-only in this PR.

Testing: tools/nano7 round trip: schema level; each failure leaves the library unchanged (including a full disk); categories and rules over repeated saves; missing categories added with stable ids; header fields; nano 5G unchanged. On the device: the six categories and the schema level stayed correct in every write of the hardware run in PR 4.

…an invalid signature

On macOS 27 (arm64, Bun 1.3.13) the compiled binary keeps the linker's
ad-hoc signature after Bun appends the payload. codesign --verify reports
"code or signature have been modified" and the kernel kills the binary on
launch with status 137. compile.sh now verifies the signature on darwin and
re-signs ad hoc only when verification fails.
A Nano 7 synced by macOS carries iTunes Library.itlp and iTunesCDB but no
iTunesDB; libgpod parses the CDB, yet IpodDatabase.hasDatabase only probed
iTunesDB. device scan reported "iTunesDB not found" and sync refused with
IPOD_NEEDS_INIT, pointing at device init for a device with 21 tracks.
hasDatabase now accepts either file.
…line

runRepair ran its own refusal check with the injected assessIpodIdentity
but called runRepairPipeline without deps, so the pipeline's second
check assessed the real device path. The supported-device test therefore
failed on any host without an iPod at /Volumes/iPod. The assessor is
now forwarded through the pipeline's existing deps; both checks stay,
and the test counts that both used the injected assessor.
…abases

The nano 6th and 7th generation sign iTunesCDB and Locations.itdb.cbk
with HashAB. libgpod 0.8.3 only computes it through an external blob
loaded from LIBGPOD_BLOB_DIR, which podkit does not ship. dstaley/hashab
is an Unlicense C implementation of the same calcHashAB function.

The C sources, headers, licence and the 100 upstream reference vectors
are copied byte for byte from the pinned commit; UPSTREAM.md records the
source. Nothing builds them yet.
…B signer

libgpod 0.8.3 loads calcHashAB from an external hashab module in
LIBGPOD_BLOB_DIR and fails nano 6G/7G writes without it. A small patch
replaces that loader with a direct call into the vendored sources, which
prepare-libgpod-nano.sh copies into the libgpod tree before autoreconf.
They are built as an internal convenience library with -fwrapv, and
their global symbols are renamed and hidden, so that they neither clash
with other code linked with libgpod nor become part of its interface.
The macOS developer build and the static prebuild dependencies both
apply the patch. The signer only accepts an eight-byte FireWire GUID, so
the patch checks for 16 hex digits first and fails the write otherwise.

The static dependency cache now records a fingerprint of the patch and
the vendored sources, and the CI cache keys hash all of tools/prebuild,
so either change rebuilds libgpod. macOS static links name the system
sqlite3 and libxml2 that libgpod already uses, and Linux static links
group the archives, so standalone executables link too.

tools/nano7 holds the checks: a read-only probe that verifies the
signatures of a copied Locations.itdb/.cbk pair and iTunesCDB, including
the hashing scheme libgpod writes, tests against the upstream vectors
and a reference checksum book, and a libgpod roundtrip for nano 6G/7G
that the prebuild workflow runs. ADR-030 records the decision. Both
generations stay read-only.
The support notes, unsupported-device reasons and docs still said
libgpod cannot produce the nano 6G database format or needs an external
hashab blob. With the signer linked in, the remaining blocker is
different: on a nano 7G the firmware shows no music for a library libgpod
writes, even though its signatures verify. The nano 6G write path is
covered only by synthetic tests.

Both generations stay read-only. The notes and reasons now say that
syncing is not supported yet and, for the nano 7G, what the firmware
shows; the generated support matrix, the supported-devices page and the
device notes follow, the generation notes in docs/formats/generations.md
and docs/test-devices.md point to ADR-030, and the classify/identify
tests track the new reason. The generation comments drop the test
devices' serial numbers.
…evel

A nano 7G (firmware 1.0.4) shows no music for a library libgpod writes,
although its signatures verify. Replacing the databases on the device
showed that the firmware needs the hidden category containers together
with iTunes' schema level; the containers alone are not enough.

For devices that sign with HashAB and are not iOS devices, the patch now
- adds the columns iTunes' Library.itdb has beyond libgpod's schema,
  appended after the tables are created; the inserts that relied on
  column positions name their columns,
- writes version_info 1.117 as iTunes does and sets the Genius.itdb
  user_version to 2,
- runs the device's post-process command set 25, which fits that schema,
  adds is_home_video and sets user_version 26, instead of the newest set.
  Two commands of the set add a column that is already there:
  item_stats.rental_expired, which libgpod's schema has, is skipped once
  the column is confirmed, and the repeated AddGenreMapCompilationCount
  only after its first run succeeded.

On these devices a missing command set, a missing, malformed or failing
command, an insert that fails while the databases are generated or a
failed commit now fails itdb_write() before any library file is
replaced; failed post-process commands are rolled back. Other devices
keep logging such failures. Attached database paths are quoted.

The tools/nano7 roundtrip checks the schema level for nano 6G/7G, that
each kind of command failure, a rejected insert and a commit that fails
as on a full disk leave the library unchanged, that the first of the
repeated genre commands runs, and that a nano 5G keeps libgpod's layout.
Both generations stay read-only.
The nano 6G/7G firmware browses six hidden smart containers: Music,
Videos, Movies, TV Shows, Audiobooks and Rentals. iTunes keeps them as
dataset 5 playlists in the iTunesCDB and as container rows in
Library.itdb. libgpod parsed and rewrote the dataset 5 playlists but
wrote no SQLite rows for them.

On devices that sign with HashAB and are not iOS devices:
- Dataset 5 headers keep +0x52, the category kind that SQLite stores as
  distinguished_kind, and +0x54 as read. libgpod copied +0x50 into
  +0x52, which turns the Videos category (+0x50 0, +0x52 1) into an
  ordinary playlist for iTunes.
- Library.itdb gets one hidden, live smart container per category, with
  iTunes' smart settings and the rules as smart_criteria, serialised by
  the existing mhod 51 writer. The firmware evaluates the rules itself,
  so no members are written; Music gets the master playlist's media
  kinds, as in iTunes. Dynamic.itdb gets their container_ui rows.
- A library that lacks a category, such as a new one, gets it with
  iTunes' rules.
- The Rentals rule has an action libgpod cannot classify; it is written
  as read instead of passing through itdb_splr_validate(), which only
  warned about it.

The roundtrip checks the rows and rules in both files, that they stay
the same over resaves, that missing categories are added while the
others keep their ids, Music's media kinds with audio and a movie, that
the three header fields round-trip independently, and that a nano 5G
still writes dataset 5 as before.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant