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

Method set_gpu_descriptor

framework_lib/src/chromium_ec/mod.rs:1439–1527  ·  view source on GitHub ↗

Writes EC GPU descriptor to the GPU EEPROM.

(&self, data: &[u8], dry_run: bool)

Source from the content-addressed store, hash-verified

1437
1438 /// Writes EC GPU descriptor to the GPU EEPROM.
1439 pub fn set_gpu_descriptor(&self, data: &[u8], dry_run: bool) -> EcResult<()> {
1440 println!(
1441 "Writing GPU EEPROM {}",
1442 if dry_run { " (DRY RUN)" } else { "" }
1443 );
1444 let mut force_power = false;
1445
1446 let info = EcRequestExpansionBayStatus {}.send_command(self)?;
1447 println!(" Enabled: {}", info.module_enabled());
1448 println!(" No fault: {}", !info.module_fault());
1449 println!(" Door closed: {}", info.hatch_switch_closed());
1450
1451 match info.expansion_bay_board() {
1452 Ok(board) => println!(" Board: {:?}", board),
1453 Err(err) => println!(" Board: {:?}", err),
1454 }
1455
1456 if let Ok(ExpansionBayBoard::DualInterposer) = info.expansion_bay_board() {
1457 // If bay power is on already, we don't need to enable/disable it
1458 if !self.get_gpio("gpu_3v_5v_en")? {
1459 println!("Expansion Bay Power is Off");
1460 if dry_run {
1461 println!("Forcing Power to Expansion Bay (skip - dry-run)");
1462 } else {
1463 // Force power to the GPU if we are writing the EEPROM
1464 let res = self.set_gpio("gpu_3v_5v_en", true);
1465 if let Err(err) = res {
1466 error!("Failed to set ALW power to GPU on {:?}", err);
1467 return Err(err);
1468 }
1469 println!("Forcing Power to Expansion Bay");
1470 os_specific::sleep(100_000);
1471 force_power = true;
1472 }
1473 }
1474 }
1475
1476 // Need to program the EEPROM 32 bytes at a time.
1477 let chunk_size = 32;
1478
1479 let chunks = data.len().div_ceil(chunk_size);
1480 let mut return_val: EcResult<()> = Ok(());
1481 for chunk_no in 0..chunks {
1482 let offset = chunk_no * chunk_size;
1483 // Current chunk might be smaller if it's the last
1484 let cur_chunk_size = std::cmp::min(chunk_size, data.len() - chunk_no * chunk_size);
1485
1486 if chunk_no % 100 == 0 {
1487 println!();
1488 print!(
1489 "Writing chunk {:>4}/{:>4} ({:>6}/{:>6}): X",
1490 chunk_no,
1491 chunks,
1492 offset,
1493 cur_chunk_size * chunks
1494 );
1495 } else {
1496 print!("X");

Callers 1

run_with_argsFunction · 0.80

Calls 6

sleepFunction · 0.85
expansion_bay_boardMethod · 0.80
get_gpioMethod · 0.80
set_gpioMethod · 0.80
write_ec_gpu_chunkMethod · 0.80
send_commandMethod · 0.45

Tested by

no test coverage detected