Skip to content

Support firmware transfer (IEC 62386-105) - #176

Open
huetti79 wants to merge 5 commits into
sde1000:masterfrom
tridonic-com:pr-firmware
Open

huetti79 wants to merge 5 commits into
sde1000:masterfrom
tridonic-com:pr-firmware

Conversation

@huetti79

@huetti79 huetti79 commented Nov 25, 2026 •

Copy link
Copy Markdown

PR 3 — python-dali: firmware transfer (IEC 62386-105)

Open at: https://github.com/tridonic-com/python-dali/pull/new/pr-firmware
Base: sde1000/python-dali:master ← tridonic-com:pr-firmware
Scope: 7 files · independent of the other two python-dali PRs


Split out of #171 as requested — "a major new feature and needs considering on
its own". It is now genuinely standalone: rebased straight onto master, with
no dependency on the EnableDeviceType(0) PR.

Status

The first version of this PR was written without a copy of the standard, and
said so: it listed the properties of the commands that had been inferred rather
than read. I have since read IEC 62386-105 Ed.2 (FDIS) and reconciled the
code with it. What was wrong has been fixed, and what was right is now cited
against the clause that says so rather than hedged.

It still has not been run against hardware that accepts a firmware image —
the commands and their framing are exercised by unit tests only.

What the standard changed

Addressing — this was wrong, and is the substantive fix. Table 1 encodes the
address byte as 0AAAAAAx / 1111110x / 1111111x, and footnote a says that
bit 24 selects the address space: 0 is control gear, 1 is control devices.
Section 9.2 requires a bus unit to discard a short, broadcast or
broadcast-unaddressed command whose bit 24 does not match its own type.

The first version hard-coded bit 24 to zero everywhere, on the theory that a
32-bit frame addresses a "bus unit" without distinguishing gear from devices. It
does distinguish them, so that version could only ever reach control gear, and
FindFirmwareUpdateTargets could not have found a control device despite saying
it did. The address family now mirrors the existing gear/device split:

control gear control devices
short FirmwareGearShort FirmwareDeviceShort
broadcast FirmwareGearBroadcast FirmwareDeviceBroadcast
broadcast unaddressed FirmwareGearBroadcastUnaddressed FirmwareDeviceBroadcastUnaddressed

A bare int is no longer accepted as a destination: a short address on its own
does not say which address space is meant. There is no group addressing — part
105 Table 1 does not define one.

Two further points worth knowing, both now in the module docstrings:

  • A firmware transfer short address is not a separate address space. Nothing
    in part 105 assigns, programs or queries one, so a unit has one only because
    it already has a part 102 or part 103 short address. FirmwareGearShort(3) is
    the unit GearShort(3) addresses.
  • Section 4.2: one bus unit may hold several logical units, starting an
    update affects all of them, and the part 105 variables are shared. So a
    product presenting both control gear and a control device answers in both
    address spaces but is updated once, not twice. The scan reports such a pair
    and the example warns about it.

Confirmed, previously only inferred:

  • the opcodes and the 0xfb marker byte match Table 6, and 0xcb / 0xbd
    match Table 7;
  • no command in either table is marked "send twice", so sendtwice = False
    throughout was right;
  • the sequence order was right. Annex C recommends QUERY BLOCK INCOMPLETE OR FAULT after each complete data block for blocks 1 and up; 11.4.3 describes
    polling QUERY FW UPDATE RECEIVER READY while the unit writes flash; Annex C
    notes that some units restart by themselves after FINISH FW UPDATE while
    others need RESTART FW.

Naming: every class is named after the command it sends, with the standard's
abbreviations spelled out — QUERY FW TRANSFER VERSION is
QueryFirmwareTransferVersion, QUERY BLOCK INCOMPLETE OR FAULT is
QueryBlockIncompleteOrFault. Each docstring names the command and the clause
of part 105 that defines it.

The change

  • dali.address — the six Firmware* classes above, under FirmwareAddress
  • dali.firmware — the commands, registered through __init_subclass__ (the
    removed Command._register_subclass() is not used)
  • dali.firmware_sequences — sequences that drive an image onto a unit and that
    find the units supporting transfer at all

devicetype is irrelevant to a 32-bit frame, and the tests assert that decoding
one does not depend on whatever device type was last enabled — so this PR reads
the same before and after the EnableDeviceType(0) change.

Not included

FirmwareUpdate() transfers an image that is already in the part 105 Annex A
update file format, block 0 included; it does not build that file or compute the
Annex B CRC16.

The worked example lives in the companion dali-drivers PR, since examples
moved to that project in ce885e7. The drivers that actually carry 32-bit frames
are in that PR too; this is the library half.

Testing

  • pytest dali/ — 174 passed
  • mypy --strict dali/ — clean, 49 files
  • flake8 dali — 0

New tests cover the Table 1 encoding in both address spaces, that the gear and
device forms of an address differ only in bit 24, that both spaces are scanned
by default, and that an int destination is refused.

🤖 Generated with Claude Code

@sde1000

sde1000 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

This is definitely going to require some better documentation!

I may be able to take a day to visit the British Library in London to consult IEC 62386-105 and improve the documentation in this pull request. (I'm not going to buy the standard, the relevant part of it is only 20 pages long and it would cost me £302!)

Do you know how addressing is supposed to work — how do the short firmware addresses relate to short gear and device addresses, if at all? If not, how do bus units get short firmware addresses?

Add dali.firmware with the commands of IEC 62386-105 Ed.2, and
dali.firmware_sequences with the sequences that drive an image onto a
bus unit and that find the units supporting transfer at all.

Firmware transfer uses 32-bit forward frames which carry their
destination in the most significant byte. Table 1 encodes that byte as
0AAAAAAx for short addressing, 1111110x for broadcast unaddressed and
1111111x for broadcast, where bit 24 selects the address space: 0 is
control gear and 1 is control devices. Section 9.2 requires a bus unit
to discard a short, broadcast or broadcast-unaddressed command whose
bit 24 does not match its own type, so the addresses split into
FirmwareGear* and FirmwareDevice* classes mirroring GearAddress and
DeviceAddress. There is no group addressing, and an int is not
accepted as a destination because a short address alone does not say
which address space is meant.

A firmware transfer short address is not a separate address space:
nothing in part 105 assigns, programs or queries one, so a unit has
one only because it already has a part 102 or part 103 short address.
One bus unit may hold several logical units, and per section 4.2
starting an update affects all of them, so a product presenting both
control gear and a control device answers in both address spaces but
is updated once.

The commands have not been run against hardware that accepts a
firmware image; they are exercised by unit tests only.

The drivers that carry 32-bit frames live in dali-drivers; this is the
library half.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@huetti79

Copy link
Copy Markdown
Author

Updated according reviewers comment.

Comment thread dali/address.py Resolved
Comment thread dali/firmware.py Resolved
Review feedback from sde1000 on the firmware transfer PR.

There is no separate address space for firmware transfer: part 105
assigns, programs and queries no short address of its own, so
GearShort(3) in a 32-bit frame is the same unit as GearShort(3) in a
16-bit one. The separate FirmwareGear* and FirmwareDevice* classes
therefore said nothing that GearShort and DeviceShort did not already
say, so they are gone. GearShort, GearBroadcast,
GearBroadcastUnaddressed, DeviceShort, DeviceBroadcast and
DeviceBroadcastUnaddressed now encode into and decode from 32-bit
frames too, writing bit 24 to select the address space.

Part 105 Table 1 defines no group address. With groups now reachable
through the same base classes, check_destination() rejects GearGroup
and DeviceGroup explicitly rather than relying on the type system to
make them unrepresentable.

Address.required_frame_size is removed. It had no readers anywhere,
and the merge makes it untrue in any case: an address may now be
valid in more than one frame size. FirmwareAddress.is_control_device
goes with it; firmware_sequences tests isinstance against
DeviceAddress instead.

Also drop the address_obj indirection in check_destination(). It
reached dali.device.Device.address_obj, which was last renamed in 0.5
and no longer exists.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comment thread dali/firmware.py Resolved
# Conflicts:
#	CHANGES.rst
#	dali/address.py
#	dali/tests/test_command.py
Comment thread dali/firmware_sequences.py Resolved
Comment thread dali/firmware_sequences.py Resolved
Comment thread dali/firmware.py Resolved
Drop the FirmwareDestination alias: check_destination() checks the
destination at runtime anyway, so address.Address says everything the
annotation needs to.

Store only the address in FirmwareUpdateTarget. Its class already says
which address space the unit was found in, and the short address is
reachable through it, so the separate address and control_device
members were restating what destination held.

Correct the note about transactions in FirmwareUpdate: a driver does
run the sequence as a transaction, but each sleep() in it breaks that
transaction and lets other bus masters transmit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@sde1000

sde1000 commented Nov 30, 2026

Copy link
Copy Markdown
Owner

General comment: it's great that the docstrings of the commands refer to the section of Part 105 that they implement, but it would be good if they could also paraphrase the appropriate section so that someone without a copy of the standard has some hope of understanding what the commands do.

Part 105 Table 2 defines two bits in the firmware update feature set:
bit 0 reports whether CANCEL FW UPDATE is supported, and bit 1 an
integrated bus power supply that is disabled for the duration of the
update, so that the updating tool has to supply bus power itself.
Bits 2 to 7 are reserved.

Name them in a BitmapResponse subclass rather than handing back a
bare integer, so callers can ask for the bit they mean.
FirmwareUpdateTarget.features carries the response, and the progress
messages list the features that are set instead of printing a hex
byte.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comment thread dali/firmware.py
Comment on lines +307 to +311
Bit 1 means an integrated bus power supply is present and is
disabled for the duration of the update, so the updating tool has
to supply bus power itself; 0 means either that there is none, or
that its state is left alone throughout. Bits 2 to 7 are
reserved, and are not listed here.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This comment is confusing and seems to be conflating bits 0 and 1?

Comment thread dali/firmware.py
Comment on lines +321 to +322
Part 105 sections 9.6 and 11.4.1. Discarded while the firmware
update process is enabled.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

What is discarded while the firmware update process is enabled?

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.

2 participants