Skip to content

Commit f595eda

Browse files
committed
Add commands to flash PD controllers
Signed-off-by: Daniel Schaefer <dhs@frame.work> WIP: Debug PD Flash Signed-off-by: Daniel Schaefer <dhs@frame.work> WIP PDFLASH Signed-off-by: Daniel Schaefer <dhs@frame.work> replace disable_ports with enable_ports Signed-off-by: Daniel Schaefer <dhs@frame.work> WIP: Implement --validate-pd01 and --validate-pd23 NO testing done yet! Signed-off-by: Daniel Schaefer <dhs@frame.work> Add PD flash validation, firmware dump, and jump commands Improvements to PD controller flashing: - Add EC flash notification (0x3E01) before flash operations Required by EC to properly communicate with PD controllers - Add --pd-validate to validate FW1/FW2 firmware images - Add --pd-dump-fw to dump firmware to file for debugging - Add --pd-jump-boot/backup/main for testing jump commands - Improve enter_flashing_mode to poll for Success response - Add PD port disable before jump commands (per reference impl) - Add polling loop to wait for device after reset/jump - Properly handle interrupt and response registers Flash mode entry now works reliably: - Notifies EC with FLASH_FLAG_PD (0x11) before starting - Waits for and validates Success (0x02) response - Notifies EC with FLASH_FINISHED (0x02) when done Jump to bootloader confirmed working. Jump to alternate firmware gets correct ResetComplete response but device boots back to MainFw when both images are identical (expected behavior per CCG8 priority handling). Signed-off-by: Daniel Schaefer <dhs@frame.work> WIP: PD Flash Signed-off-by: Daniel Schaefer <dhs@frame.work> work on pd flashing `--pd-jump-backup 0` now works. `--info` confirms it `--pd-reset 0` now works, goes back into main `--validate-pd01 framework_lib/test_bins/sakura-pd-1.0.0A.bin` is successful. Shows failure with different firmware. Signed-off-by: Daniel Schaefer <dhs@frame.work> Allow flashing only a single pd firmware Signed-off-by: Daniel Schaefer <dhs@frame.work> --pd-info: Skip non-existent PD Signed-off-by: Daniel Schaefer <dhs@frame.work> Add pd commands to examples Signed-off-by: Daniel Schaefer <dhs@frame.work> --pd-info: Add more Signed-off-by: Daniel Schaefer <dhs@frame.work> check pd compatibility the id that the chip reports is not exactly the same one as in the firmware Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent ecebf5f commit f595eda

14 files changed

Lines changed: 1894 additions & 220 deletions

File tree

‎EXAMPLES_ADVANCED.md‎

Lines changed: 163 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,45 @@ Summary:
7676

7777
### Check PD state
7878

79-
Example on Framework Laptop 13 AMD Ryzen AI 300
79+
Example on Framework Laptop 13 (CCG8 CFP). The right controller is currently
80+
running the backup firmware, which supports fewer HPI features than the main
81+
firmware.
8082

8183
```
82-
> sudo framework_tool.exe --pd-info
84+
> sudo framework_tool --pd-info
8385
Right / Ports 01
84-
Silicon ID: 0x3580
85-
Mode: MainFw
86+
Silicon ID: 0x3E81
87+
Mode: BackupFw
8688
Flash Row Size: 256 B
8789
Ports Enabled: 0, 1
88-
Bootloader Version: Base: 3.6.0.009, App: 0.0.01
89-
FW1 (Backup) Version: Base: 3.7.0.197, App: 0.0.0B
90-
FW2 (Main) Version: Base: 3.7.0.197, App: 0.0.0B
90+
HPI Version: 2.4 (0x04006124) cyacd2
91+
Boot Reason: 0x00 (Both firmwares valid)
92+
WDT Resets: 0
93+
Config Table: v2.0
94+
Flash Layout: Bootloader rows 0-1, FW1 from row 2, FW2 from row 103
95+
Bootloader Version: Base: 3.6.0.044, App: 0.0.01
96+
FW1 (Backup) Version: Base: 3.8.50.00A, App: 1.0.09
97+
FW2 (Main) Version: Base: 3.8.50.00A, App: 1.0.0A
9198
Left / Ports 23
92-
Silicon ID: 0x3580
99+
Silicon ID: 0x3E81
93100
Mode: MainFw
94101
Flash Row Size: 256 B
95102
Ports Enabled: 0, 1
96-
Bootloader Version: Base: 3.6.0.009, App: 0.0.01
97-
FW1 (Backup) Version: Base: 3.7.0.197, App: 0.0.0B
98-
FW2 (Main) Version: Base: 3.7.0.197, App: 0.0.0B
103+
HPI Version: 2.4 (0x04237724) PD Commands, UCSI, EPR, cyacd2
104+
Boot Reason: 0x00 (Both firmwares valid)
105+
WDT Resets: 0
106+
Config Table: v2.0
107+
Flash Layout: Bootloader rows 0-1, FW1 from row 2, FW2 from row 103
108+
Bootloader Version: Base: 3.6.0.044, App: 0.0.01
109+
FW1 (Backup) Version: Base: 3.8.50.00A, App: 1.0.0A
110+
FW2 (Main) Version: Base: 3.8.50.00A, App: 1.0.0A
99111
```
100112

113+
The HPI Version, Boot Reason, WDT Resets, Config Table and Flash Layout lines
114+
are only shown if the PD firmware implements those registers. Boot Reason is
115+
only updated when the controller boots, it does not reflect firmware updates
116+
done since.
117+
101118
### Disable/enable/reset PD
102119

103120
```
@@ -281,6 +298,141 @@ This command has not been thoroughly tested on all Framework Computer systems
281298
> framework_tool --reboot-ec jump-rw
282299
```
283300

301+
## Flashing PD firmware
302+
303+
**IMPORTANT** Flashing PD firmware yourself is not recommended. Please update
304+
your firmware using the official BIOS update methods (Windows .exe,
305+
LVFS/FWUPD, EFI updater)!
306+
307+
The PD controllers hold two copies of the firmware, FW1 (backup) and FW2
308+
(main). Each firmware can only update the other one, so to update both the
309+
tool writes the inactive image, switches the controller to it, writes the other
310+
image and finally resets the controller. Normally the main firmware is running
311+
and gets booted after the reset.
312+
313+
While the PD controller is being updated, the EC does not talk to it and the
314+
ports get disabled. Make sure the battery is present and charged.
315+
316+
Tested on Framework Laptop 13 (CCG8 CFP).
317+
318+
### Check the firmware on the controller against a file
319+
320+
Runs the same checks as flashing without writing anything, asks the controller
321+
to validate both images and compares the inactive image with the file.
322+
323+
```
324+
> sudo framework_tool --validate-pd01 framework_lib/test_bins/sakura-pd-1.0.0A.bin
325+
Device
326+
Silicon ID: 0x3E81
327+
Mode: MainFw
328+
Flash Row Size: 256 B
329+
Backup FW: 1.0.0A
330+
Main FW: 1.0.0A
331+
File
332+
Silicon ID: 0x3E81 (Ccg8Cfp)
333+
Backup FW: 1.0.0A (rows 2-101)
334+
Main FW: 1.0.0A (rows 103-416)
335+
Validating firmware on the controller
336+
Firmware file layout matches the controller
337+
Main FW (FW2) Valid: true
338+
Backup FW (FW1) Valid: true
339+
Comparing Backup FW (FW1) on the controller with the file
340+
Row 1/100
341+
Row 33/100
342+
Row 65/100
343+
Row 97/100
344+
Row 100/100
345+
Backup FW (FW1) on the controller is identical to the file
346+
```
347+
348+
If the file is not what is on the controller, the command fails:
349+
350+
```
351+
> sudo framework_tool --validate-pd01 Compal_Sakura_8229_PD1_0x5253_v0.0.02.bin
352+
[...]
353+
Backup FW (FW1) on the controller differs from the file in 84 of 99 rows
354+
Failed to validate PD 01: DeviceError("Firmware on the controller does not match the file")
355+
Error: "Fail"
356+
```
357+
358+
### Flash
359+
360+
By default both images are updated. With `--pd-image main` or
361+
`--pd-image backup` only one of them is written. If the selected image is the
362+
one currently running, the controller is switched to the other one first.
363+
364+
```
365+
# Only update the backup firmware on PD 0 (right side)
366+
> sudo framework_tool --flash-pd01 pd-1.0.09.bin --pd-image backup
367+
Device
368+
Silicon ID: 0x3E81
369+
Mode: MainFw
370+
Flash Row Size: 256 B
371+
Backup FW: 1.0.0A
372+
Main FW: 1.0.0A
373+
File
374+
Silicon ID: 0x3E81 (Ccg8Cfp)
375+
Backup FW: 1.0.09 (rows 2-101)
376+
Main FW: 1.0.09 (rows 103-416)
377+
378+
Flashing BackupFw (1.0.09) from MainFw
379+
Writing rows 2 to 101 (100 rows)
380+
Row 1/100
381+
Row 33/100
382+
Row 65/100
383+
Row 97/100
384+
Row 100/100
385+
Controller validated BackupFw: true
386+
387+
Restarting controller
388+
Resetting PD controller Right01
389+
Controller is running MainFw
390+
Bootloader Version: Base: 3.6.0.044, App: 0.0.01
391+
FW1 (Backup) Version: Base: 3.8.50.00A, App: 1.0.09
392+
FW2 (Main) Version: Base: 3.8.50.00A, App: 1.0.0A
393+
394+
# Update both images on PD 1 (left side)
395+
> sudo framework_tool --flash-pd23 pd-1.0.09.bin
396+
```
397+
398+
### Switch between the firmwares
399+
400+
For debugging it is possible to boot the other firmware copy. The switch lasts
401+
until the next reset of the PD controller, then the main firmware is booted
402+
again (if it is valid).
403+
404+
```
405+
> sudo framework_tool --pd-jump-backup 0
406+
Jumping PD 0 to backup firmware...
407+
Current mode: MainFw, jumping to BackupFw
408+
Disabling PD ports
409+
Jumping from MainFw to BackupFw
410+
Now running BackupFw
411+
412+
> sudo framework_tool --pd-jump-main 0
413+
Jumping PD 0 to main firmware...
414+
Current mode: BackupFw, jumping to MainFw
415+
Disabling PD ports
416+
Jumping from BackupFw to MainFw
417+
Now running MainFw
418+
419+
# A reset also boots the main firmware again
420+
> sudo framework_tool --pd-reset 0
421+
Resetting PD 0...
422+
Disabling PD ports
423+
Resetting PD controller Right01
424+
Controller is running MainFw
425+
```
426+
427+
### Dump the flash
428+
429+
The controller only allows reading the inactive firmware image. The rows of
430+
the bootloader and the running firmware are filled with zeros.
431+
432+
```
433+
> sudo framework_tool --pd-dump-fw 0:pd0-dump.bin
434+
```
435+
284436
## Flashing Expansion Bay EEPROM (Framework Laptop 16)
285437

286438
This will render your dGPU unsuable if you flash the wrong file!

‎README.md‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,70 @@ On UEFI and FreeBSD raw port I/O is used - on Linux this can also be used as a f
149149
- [x] Retimer
150150
- [x] Touchpad (Linux, Windows, FreeBSD, not UEFI)
151151
- [x] Touchscreen (Linux, Windows, FreeBSD, not UEFI)
152-
- [x] Get Expansion Card Firmware (Not on UEFI so far)
152+
- [x] Get Expansion Card Firmware Version (Not on UEFI so far)
153153
- [x] HDMI Expansion Card (`--dp-hdmi-info`)
154154
- [x] DisplayPort Expansion Card (`--dp-hdmi-info`)
155155
- [x] Audio Expansion Card (`--audio-card-info`)
156+
157+
###### Firmware Update
158+
159+
Note: Use fwupd.
160+
161+
- [ ] Flash firmware
162+
- [ ] BIOS Capsule
163+
- [x] EC
164+
- [x] TGL/ADL/RPL (Tested on TGL, ADL)
165+
- [x] Nuvoton NPCX993 (AMD) (Tested on Azalea)
166+
- [x] Nuvoton NPCX993 (MTL)
167+
- [ ] PD
168+
- [ ] CCG5 (TGL) CYPD5225
169+
- [ ] CCG6 (ADL/RPL) CYPD6227
170+
- [ ] CCG6DF (MTL) CYPD6228
171+
- [ ] CCG8DF (AMD) CYPD8225
156172
- [x] Update Expansion Card Firmware (Not on UEFI so far)
157173
- [x] HDMI Expansion Card (`--dp-hdmi-update`)
158174
- [x] DisplayPort Expansion Card (`--dp-hdmi-update`)
159175
- [ ] Audio Expansion Card
160176

177+
# TODO:
178+
179+
- [x] Compare if we're sending the same HCs as compal
180+
- Yes, but they (at least the old tool) don't send flash notify command
181+
- [x] If updating currently running firmware, need to force EC reset
182+
- Yes. Jump to itself is a noop
183+
- [x] Investigate flash notify command
184+
- On MCHP we need to do extra tasks to enable SPI access
185+
- On NPCX we don't need to do that, but it's still good to disable some interrupts
186+
- [ ] Investigate how we can check if flash FW is valid
187+
- [ ] Check if the flash ranges are correct
188+
- [x] Test other platforms
189+
- [ ] Decode flash flags from binary
190+
- [ ] Decode flash flags from system
191+
- [ ] RO/RW Support
192+
- [ ] Investigate locking command
193+
- [ ] Think about RW/RO like chromium
194+
195+
```
196+
# Flash RO (default on reboot is RO currently)
197+
> fwk.efi --flash-ro-ec ec.bin
198+
> fwk.efi --reboot-ec reboot
199+
200+
# Flash RW
201+
> fwk.efi --flash-rw-ec ec.bin
202+
# Doesn't work if you're already in RW. Need to reboot and then jump again
203+
> fwk.efi --reboot-ec reboot
204+
# From RO, just jump to RW
205+
> fwk.efi --reboot-ec jump-rw
206+
207+
> fwk.efi --test
208+
> fwk.efi --versions
209+
EC Firmware
210+
Build version: "marigold-1.0.1-0ceccfb 2024-03-26 08:14:47 marigold1@ip-172-26-3-226"
211+
RO Version: "marigold-0.0.0-c6c7ac3"
212+
RW Version: "marigold-1.0.1-0ceccfb"
213+
Current image: RW
214+
```
215+
161216
###### System Status
162217

163218
All of these need EC communication support in order to work.

0 commit comments

Comments
 (0)