hrvach / deskhop

Fast Desktop Switching Device
GNU General Public License v3.0
5.96k stars 166 forks source link

DFU support (Phase 1) #78

Closed kpfleming closed 1 week ago

kpfleming commented 3 months ago

Implementation of #77.

Since this is 'phase 1', it only supports DFU operations against the board it is attached to (A or B), it does not support operations against the 'other' board over a single connection. This means that upgrading firmware must be done twice, connecting to each board.

hrvach commented 3 months ago

I'll test it a bit and play around with it, on first look it seems very well done. Thank you for contributing!

kpfleming commented 3 months ago

Thanks! I'm going to keep this in draft mode until it actually has some functionality that is useful :-)

(Edit: thoughts about cross-board communication removed)

kpfleming commented 3 months ago

More progress: it is now possible to use DFU to extract the firmware and config from a running board :-)

Example commands (while connected to board A; change 'a' to 'b' if connected to board B):

dfu-util -a board_a_fw -d 2e8a:107c -D firmware.bin
dfu-util -a config -d 2e8a:107c -D config.bin

In each case dfu-util will trigger the board to reboot into DFU mode and perform the transfer. The board will reset itself to normal mode 500ms after the transfer has been completed.

kpfleming commented 3 months ago

I have now successfully used this to upgrade firmware a half-dozen times. I'll write some docs for it tomorrow and then it will be ready for review/testing.

kpfleming commented 3 months ago

Also, apologies for the inconsistent code formatting... I've tried to follow the style in various source files but they aren't consistent with each other so it was challenging!

kpfleming commented 3 months ago

Documentation has been added and I've re-ordered the commits so that the first three are simpler to review (they don't include the DFU code).

kpfleming commented 3 months ago

Going back to draft mode; I need to do some more work on handling configuration data.

kpfleming commented 2 months ago

I spent some time trying to determine whether it made sense to build a simple 'transfer configuration over the UART link' mechanism, but decided that it does not make sense at this time as we'll eventually want to be able to transfer entire firmware binaries over that link too and the design will need to be done with both usages in mind.

Given that, I'm putting this back in 'ready to review' mode after updating DFU.md to demonstrate how to upload configuration data into both boards.

kpfleming commented 2 months ago

Before this can be merged, a second request will need to be made to the RPi team for a PID for the DeskHop to use while in 'DFU transfer' mode. This is primarily needed for Windows, since Windows assigns combinations of drivers to VID/PID combinations, and when the board goes into that mode it should not have any HID drivers attached to it, which would happen if the PID did not change.

hrvach commented 2 months ago

Haven't forgotten about this, don't worry - just been super busy. Thanks again for working on this, I'll take a look as soon as I can scrape some free time.

kpfleming commented 1 week ago

Closing this as the entire firmware upgrade/configuration process has been redesigned.