MCPcopy Index your code
hub / github.com/FrameworkComputer/framework-system / flash_firmware

Function flash_firmware

framework_lib/src/ccgx/hid.rs:289–384  ·  view source on GitHub ↗
(fw_binary: &[u8])

Source from the content-addressed store, hash-verified

287}
288
289pub fn flash_firmware(fw_binary: &[u8]) {
290 let versions = if let Some(versions) = ccgx::binary::read_versions(fw_binary, SiliconId::Ccg3) {
291 versions
292 } else {
293 println!("Incompatible firmware. Need CCG3 firmware.");
294 return;
295 };
296
297 // Not sure if there's a better way to check whether the firmware is for DP or HDMI card
298 let dp_string = b"F\0r\0a\0m\0e\0w\0o\0r\0k\x006\x03D\0i\0s\0p\0l\0a\0y\0P\0o\0r\0t\0 \0E\0x\0p\0a\0n\0s\0i\0o\0n\0 \0C\0a\0r\0d\0";
299 let hdmi_string = b"F\0r\0a\0m\0e\0w\0o\0r\0k\0(\x03H\0D\0M\0I\0 \0E\0x\0p\0a\0n\0s\0i\0o\0n\0 \0C\0a\0r\0d\0";
300 let filter_devs = if util::find_sequence(fw_binary, hdmi_string).is_some() {
301 [HDMI_CARD_PID]
302 } else if util::find_sequence(fw_binary, dp_string).is_some() {
303 [DP_CARD_PID]
304 } else {
305 println!("Incompatible firmware. Need DP/HDMI Expansion Card Firmware.");
306 return;
307 };
308
309 let fw1_rows = versions.backup_fw.size / versions.backup_fw.row_size;
310 let fw2_rows = versions.main_fw.size / versions.main_fw.row_size;
311
312 println!("File Firmware:");
313 println!(" {}", device_name(FRAMEWORK_VID, filter_devs[0]).unwrap());
314 println!(" {}", versions.main_fw.base_version);
315
316 // First update the one that's not currently running.
317 // After updating the first image, the device restarts and boots into the other one.
318 // Then we need to re-enumerate the USB devices because it'll change device id
319 let mut api = HidApi::new().unwrap();
320 let devices = find_devices(&api, &filter_devs, None);
321 if devices.is_empty() {
322 println!("No compatible Expansion Card connected");
323 return;
324 };
325 for dev_info in devices {
326 // Unfortunately the HID API doesn't allow us to introspect the USB
327 // topology because it abstracts USB, Bluetooth and other HID devices.
328 // The libusb API does allow that but it's lower level and requires
329 // root privileges on Linux.
330 // So we can't figure out which port the card is connected to.
331 // Would be nice to show that instead of the serial number.
332 // We want to show that so the user knows that multiple *different*
333 // cards are being updated.
334 let sn = dev_info
335 .serial_number()
336 .expect("Device has no serial number");
337 let dev_name = device_name(dev_info.vendor_id(), dev_info.product_id()).unwrap();
338 println!();
339 println!("Updating {} with SN: {:?}", dev_name, sn);
340
341 let device = dev_info.open_device(&api).unwrap();
342 magic_unlock(&device);
343 let info = get_fw_info(&device);
344 println!("Before Updating");
345 print_fw_info(&info, true);
346

Callers 1

flash_dp_hdmi_cardFunction · 0.85

Calls 10

read_versionsFunction · 0.85
find_sequenceFunction · 0.85
find_devicesFunction · 0.85
device_nameFunction · 0.85
magic_unlockFunction · 0.85
get_fw_infoFunction · 0.85
print_fw_infoFunction · 0.85
flash_firmware_imageFunction · 0.85
wait_to_reappearFunction · 0.85
open_deviceMethod · 0.45

Tested by

no test coverage detected