175. How the bytes of a write reach storage, and what still stands between that and a first write¶
The gate on phase 8 opened on 25 August 2026, and the first thing behind it was not a bench session
but a hole in this file. WRITE_FLASH had been read as far as its announce packet: five bytes,
identical to READ_FLASH, parsed into the same variables and validated by the same routine, section
88. What happened to the data was one sentence, that it "arrives as 0x40 packets handled in the USB
callback", and nothing had followed those packets. packages/usb's writeFlash says so out loud and
throws rather than sending anything, which is why the gate could open onto a derivation instead of a
write.
It is read now, on both remotes on the bench and on the arch 14 reference image, and the protocol half is complete. What is not complete is the part that decides whether a first write succeeds, and that distinction is the point of this section.
A correction inside the section's own first day. The paragraphs below were written naming the
Harmony 700 and the Harmony One as "both bench architectures", and the commit that landed them said
it too. There is no Harmony 700 here and never has been: the bench holds two Harmony Ones, a Harmony
600 and a Harmony 525, and the 700 is an arch 14 reference image, which is exactly what
CLAUDE.md has always called it. Reading the 700 first was the right call, since it is the better
mapped arch 14 image, and calling it hardware was not, because it silently promoted a reference to a
thing that could be written to. The Harmony 600 is read below alongside it now, and it is the image
that would matter if a write ever reached arch 14, which today's rails refuse for want of a second
arch 14 unit. Danny caught it; nothing in the tests could have, since an image name says nothing
about what is on the desk.
Two commands exist inside a write and neither can be sent outside one. Section 19 said this
already, and said why it matters, that the firmware accepts flash data only after it has agreed to a
write; what is added here is where that chain is in each image and what its two arms do. The main
dispatch is gated on the command state variable, and state 2 is what WRITE_FLASH sets. State 2 reaches a chain of its
own, 0x26752 on the Harmony One, 0x0C4C0 on the Harmony 600 and 0x0C55C on the 700 image, and
that chain has exactly two cases: 0x40, the data packet, and 0xF0, the end of the transfer. So a remote that has not agreed
to a write cannot be handed data at all, which is the firmware's own reason for 0x40 being absent
from the command table rather than an omission in the table.
The address this file gave for that chain was wrong, and it is worth saying which kind of wrong.
docs/usb-protocol.md named 0x0BD5C, which is the SUBWF that compares the command against 0xE0
in the escape handler, four instructions before the state gate. The description beside it, a two entry
chain handling 0x40 and 0xF0, was right. So the reading was right and the citation was off by one
routine, which nothing could catch, because no test read the address.
A data packet lands in a buffer that holds one packet. 0x01A5 on the Harmony One, 0x068C on
the Harmony 600 and 0x068F on the 700 image, stated as two literals and reloaded at the top of every
packet rather than advanced across them. The two arch 14 builds putting it three bytes apart is what
says the address is a build's own choice and not a constant of the architecture. The handler copies
the payload there a byte at a time, then sets a flag and stores the packet's length: 0x28D and
0x28E on the One, 0x723 and 0x724 on the 600, 0x37E and 0x37F on the 700. The length it
stores is the callback's own decoded length nibble, not a share of the announced count, so the
firmware writes what the packet says it carries.
The main loop drains that buffer, and it forks on the byte the validator wrote. The executor is
0x267FE on the One, 0x0C578 on the 600 and 0x0C614 on the 700 image. It subtracts the packet's
length from the announced remaining count, and then reads the destination selector, 0x28B on the
One, 0x1CD on the 600 and 0xED5 on the 700. 0x00 is external
storage and 0xFE is internal program flash. That selector is not new here: section 94 read 0x28B
as the byte the read body branches on. What is new is that the write executor branches on the same
byte with the same two values, so the validator classifies an address once and both directions obey
it, and neither command carries a region rule of its own. That is the mechanism behind a sentence
docs/usb-protocol.md already carried, that the validator is called by both.
An internal write is the part's own self programming sequence, not anything of Logitech's. A byte
goes to TABLAT and into the holding registers with TBLWT, and only when the low six bits of the
address are all set does the executor call a commit that sets EECON1 to 0x04 and runs the unlock.
So internal program flash is programmed in 64 byte blocks, and a transfer that stops in the middle of
one leaves those bytes in the holding registers and never programmed. A writer that ends on an
unaligned boundary loses its tail with no error.
The transfer is acknowledged once, at the end, and not per packet. 0xF0 moves the remote to
state 3 on all three images, and state 3's executor answers 0xF0 0x30: the acknowledgement shape
section 19 established, naming the command being finished. Confirmed on the Harmony One at 0x26A9C
as well as on the 700 image, since a reply the write target does not send would be the one that
mattered. So a host sends an announce, a run of data
packets that are each answered by nothing at all, and one done packet that is answered once. The only
thing standing between the host and a lost packet is the pending flag above, and the buffer it guards
holds 63 bytes.
Ending the session disarms the destination, and so does any command the firmware does not
recognise. 0xE0 0x01, the escape section 97 reads as clearing the command gate so a remote can
leave USB mode when its cable goes, sets the selector to 0xFF. So does the dispatcher's own fall
through: the shared exit at 0x267E4 tests whether the command was handled and, if it was not, clears
the state and sets the selector, which is the more general rule and turned up while the pacing
question was being answered. And so does the ordinary end of a transfer, which review added and
which is the tidiest of the three: the 0xF0 handler itself sets the selector on its way out, at
0x267BE on the Harmony One, 0x0C52C on the Harmony 600 and 0x0C5C8 on the 700. So a completed
write disarms itself, and a second transfer needs a second announce packet rather than inheriting the
first one's destination. A stray byte during a transfer does not corrupt it, it ends it. Both arms of the fork refuse
that value, so after an end of session a remote cannot write again until an address has been
validated. Three values, and the third one is the safe one.
The Harmony One will not write below 0x020000 unless a low erase has just cleared an interlock,
and this paragraph got that wrong twice before arriving at it. Both wrong versions are kept, because
the pair of them is a better lesson than the answer.
Version one read the bit as a permit. It said a write below 0x020000 happens only once a write at
or above it has set the bit, so the safe mode region was unreachable until something else was written
first. That inverts the firmware, and the error is the one CLAUDE.md already warns about after three
previous instances: a bit test's polarity. 0x268BC is BTFSS 0x1A4, 5, skip if set, and the
instruction it skips is the branch that jumps over the CLRF at 0x268C2. That CLRF zeroes the
go ahead flag, so it is the set case that abandons the write. Bit 5 is a block, not a permit.
Version two fixed the polarity and then got the consequence wrong anyway, which is the more
interesting failure. Having established that a high write sets the bit and a low write needs it clear,
it concluded that the low region is writable at the start of a session, before anything has set
the bit, and locked afterwards. That followed only because the write path was the only place anybody
had looked. Enumerating every instruction in the image that touches the bit gives four, not three,
and the fourth is decisive: 0x2B824 BSF 0x1A4, 5, in a routine reached from 0x28A0E, which is
CALLed by the first instruction of the entry point at 0x2EA38 and again at 0x2EA4C, whose
next instruction is BRA 0x2EA4C. That two instruction loop is the main loop. So the bit is set before
anything else runs and re-set on every pass of the main loop, and the ordinary state of a running
Harmony One is bit 5 set.
Three things hold that up and each is checked by something other than this section's own reading. Worth saying because the reading it replaced was also coherent, and coherence is what got the first two versions written.
The enumeration is confirmed by a method that cannot mis-step. Walking an image instruction by
instruction is how the list was built, and a single wrong width silently skips whatever follows it, so
the same four were found again by scanning every even offset for the raw encodings 0x8BA4, 0x9BA4,
0xABA4 and 0xBBA4, which are BSF, BCF, BTFSS and BTFSC on this file register and bit. Same
four addresses. An alignment error cannot survive that, and the count is the crux of the section.
The polarity rests on BTFSS meaning skip if set, and that is pinned in tests/test_isa.py
without appeal to a datasheet: the Harmony 700's firmware waits for a timer overflow with a bit test
branching to itself, which is a correct wait under one reading and a loop that spins forever once the
flag sets under the other. Only one is coherent. That check matters here more than anywhere else in
this section, because the whole conclusion inverts with it, and CLAUDE.md records these two
mnemonics having once been swapped in this repository.
The entry point is derived rather than taken from a summary, which is a correction to the first
version of this paragraph: it cited 0x2EA38 on the strength of CLAUDE.md's key facts table.
tests/test_isa.py's citation table holds 0x2000A: 0xEF1C and 0x2000C: 0xF175 against
one34_code, and that pair decodes as GOTO 0x2EA38, in the Harmony One's own vector area, asserted
against the real image. And the claim survives even without it, which is the better reason to
believe it: the main loop CALL at 0x2EA4C is read straight from the bytes, so "re-set on every
pass" stands alone, and the entry point only adds "and before anything else runs".
So the reading that survives: writing below 0x020000 is refused in the ordinary running state, and
the only instruction anywhere that clears the bit is 0x26612 BCF 0x1A4, 5, reached when ERASE_FLASH
is given an address below 0x020000, the boundary checked by the three byte subtract at 0x26604.
That makes it an interlock rather than a latch: the low region opens only just after a low erase,
and an installer satisfies it naturally while a stray write never does. What is not established is
whether a low write can actually win that race, since the erase executor, the write drain and the
routine that re-sets the bit all run within one main loop pass and their order within it has not been
read. It does not need to be, because nothing here is going to write there.
Both wrong versions pointed at the same practical answer for opposite reasons, and that is why
neither was caught by anything but review. Version one said the low region is protected by a gate;
version two said it is exposed and the rails are all that stand in the way; the truth is that it is
protected by an interlock. packages/usb refuses the whole region under all three, which is why two
rounds of correction changed no code. What it changed is what a future reader would believe about how
much slack there is, and version two was the dangerous one to leave standing, because "the safe mode
image is writable right now" invites a rail to be argued about rather than obeyed.
The transferable lesson is about the population and not about the polarity. A claim of the form
"this bit means X" needs every site that touches the bit, not the site the current derivation walked
through. One BSF in the write path made a story that was coherent, testable and wrong, and the test
written for it passed. Arch 14 is clean here for a reason that costs nothing to state: across both of
its write executors there is no BTFSS and no BTFSC at all, so there is no bit whose population
could be got wrong.
What the validator says on its own remains the point worth carrying: section 88 measured the arch 12
window as every top byte below 0x40, which is that model's whole 4 MiB part and is not the figure
for the others, the table there giving 0x20 on arch 14 and 0x80 to 0x88 on arch 9. So a reader
who stopped at the validator would conclude the safe mode image is freely writable. It is not, and the
interlock above is why, but that is invisible to the validator: one refuses by address class and the
other by a bit, and neither knows about the other. So the validator's window remains the wrong place
to read a region's safety off, which is the point that survived all three readings of the bit.
The internal offset bound is per architecture and the two disagree. 0xFFC0 on arch 14, one full
report below the top of the page, and 0xFFF8 on arch 12. packages/usb applies 0xFFC0 to both,
which is stricter than the firmware on the Harmony One and therefore safe, and its comment called the
number "the firmware's own bound" without saying whose firmware. Corrected there in the same commit.
The test asserts both literals, and its control is that asserting 0xFFC0 for arch 12 fails.
What is still not read, and what it costs¶
Four things, and the first two are what a rehearsal would run into rather than curiosities.
- ~~Whether the firmware erases before it programs.~~ Answered on arch 14 and still open on
arch 12, section 186, by the blind reading of 27 August 2026 and verified here. The Harmony 600's
program path sends serial flash opcode
0x02and never0xD8, and the eraser is a separate routine reached only from the erase command, so that architecture does not erase before it programs. The Harmony One's store ends in a resident call gate below its image base, so it cannot be read from anything held here, which is a reason rather than a gap. This entry said "no architecture's external path was followed far enough to say", which was true when written and is now true of one of the two. It matters because flash only clears bits: programming over unerased content silently produces the AND of the two.ERASE_FLASHexists, Logitech's client picks a block table, andpackages/usbalready requires a block aligned erase of a whole 64 KiB block, so the rails assume the caller erases. That assumption being unverified costs nothing while the caller erases anyway, which is what makes this the weaker of the two open questions rather than a blocker: erasing an already erased block changes nothing, so erasing first is right under both answers. - ~~Whether a host has to pace its data packets.~~ Answered for the firmware, by reading, and the entry is kept because it was got wrong twice, in opposite directions, and the second time was worse than the first.
It first said the question could not be settled from the firmware, on the strength of one cross
reference coming back empty. One empty cross reference is not a search: the answer was a few
instructions from code already read in this section. The address that reference named, 0x0C5FA,
was also simply the wrong instruction, which is why it came back empty. It is a SETF on the
destination selector, not a predicate, and quoting it as one survived into three documents.
The mechanism, with the addresses checked: the command dispatcher's shared exit returns whether
work is pending as its value, and the caller drains it immediately. On the Harmony One the exit at
0x267E4 to 0x267FC reaches MOVF 0x28D,W and RETURN; its caller at 0x202E8 tail calls the
drain executor at 0x267FE when that is nonzero. The 700 image does the same at 0x0C600, where
the returned value is 0x37E or 0x37D, and the Harmony 600 at 0x0C566, where it is 0x723
or 0x722. The drain then gates on the write flag alone, MOVF 0x37E; BZ at 0x0C614 on the 700
and MOVF 0x723; BZ at 0x0C578 on the 600, clears it, consumes the packet length beside it and
subtracts that length from the transfer's remaining count. So the second variable in the returned
value is a different pending thing, not the packet length, which the first write up of this had
conflated: the returned value asks "is there anything to do", and only the flag asks "is there a
write packet".
So a data packet is staged and then programmed inside the same service call that received it,
before the dispatcher can be entered again. Two things follow that this section had listed as risks.
The done cannot overtake the last data packet, so state 3's acknowledgement is emitted after the
final bytes are programmed rather than racing them. And the firmware imposes no pacing
requirement, so writeFlash's delay between packets defaults to zero on a derivation rather than
on a hope. The Harmony 600 is checked now and was listed here as the gap, which mattered because
it is the arch 14 remote rather than the reference image.
What this does not establish, and the earlier wording claimed, is that a host cannot lose a
packet. It said the buffer is free again before the next report is looked at, and therefore that
streaming is safe. The first half is what was read; the second does not follow from it. Whether the
USB hardware can accept a second report before the firmware has serviced the first is a question
about the endpoint's buffer descriptor and its ownership bit, which is not read here. The
ordinary PIC18 arrangement makes the endpoint refuse rather than overwrite, which is why streaming
is expected to work, but that is a reasonable expectation about the silicon and not a finding about
this firmware. Stated separately because the two claims have different evidence and the rehearsal
will exercise both at once.
* The arch 12 external mechanism. The Harmony One's path pokes a value derived from the address
top byte through TBLWT at program 0x020025 and then rewrites the top byte with 0x13, which
reads as a bank register and a window rather than a direct write, and is not established.
* Why arch 14's external path issues a read first. Both images call the SPI read setup, opcode
0x03 plus the address, before the routine that enables writing and programs the buffer: the 700 at
0x18D98 and the Harmony 600 at 0x17434, called from the same position in each external arm and
agreeing instruction for instruction in the four literals that identify them. So the whether is
settled and only the why is open, which is the better state to leave it in: the remote, rather
than the reference image, is the one that would be written to. A plausible reading is a read modify
write of the part's page, since the count the drain decrements is a byte count and not a page count,
and it is not established.
A read modify write would explain it and has not been demonstrated.
So writeFlash sends, and what stops a write is the rails rather than a gap in the reading. This
paragraph twice said the method still refuses, which was true for the hours between the derivation and
the instrument and is not true now: packages/usb/src/writes.ts builds the packets, writeFlash sends
them and waits for the one acknowledgement, and rails.ts decides whether any of it may happen. The
build flag is off, the door HARMONY_FIRST_WRITE is shut, the architecture list holds one entry and
the target must be the spare.
Of the two questions this section opened about the medium, neither can now cost a run. Pacing is
answered above. The erase question is moot for any caller that erases, which the rehearsal does,
because erasing an erased block changes nothing. writeFlash keeps a delay between data packets, and
its default of zero is now a derived default rather than a guess about which case to try first.
The cheapest first write is one block of the unit's own dump. The rehearsal in
docs/adding-a-device.md asks for the spare Harmony One's own config to be written back and read
identical, on the argument that a write that changes nothing is the only one whose correct outcome is
known in advance. A Harmony One config is about 1.6 MB and spans 26 erase blocks, and that count is
per config rather than a property of the model: the spare's own two here span 26 and 21. One erase
block of it, erased and
rewritten from the verified dump with the same bytes it already holds, exercises the erase, the
announce, the packets, the done and the read back compare, ends with the config byte identical either
way, and is repeatable if it fails halfway.
And a correction to this paragraph, made before anything ran. It said the block also answers the erase question by measurement, by being written once without a preceding erase, on the grounds that the outcome is either the bytes back or their AND and both are informative. That is wrong, and the arithmetic is the refutation: the bytes being written are the bytes already there, so their AND is the bytes back. The experiment cannot distinguish the two cases at all, and a run that "passed" would have said nothing.
What follows is better than the experiment: the rehearsal erases explicitly, so the question is moot for it. Erasing first is correct whether or not the firmware also erases, since erasing an erased block changes nothing. The question only bites for a caller who wants to skip the erase, and nothing here does. Answering it properly needs a write whose new bytes set a bit the old bytes clear, which is a real modification and belongs after a first write has worked, not before it.
Section 174 | the archive | section 176. Section 175 of the findings archive, which is frozen; the reference holds the current answer. The archive on GitHub.