Skip to content

Commit d13b41b

Browse files
committed
Add --dump-gpu-descriptor-file
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent e8acfa7 commit d13b41b

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

EXAMPLES_ADVANCED.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ It's intended for advanced users who build their own expansion bay module.
8787
The I2C address of the EEPROM is hardcoded to 0x50.
8888

8989
```
90+
# Dump current descriptor (e.g. for backup)
91+
> framework_tool --dump-gpu-descriptor-file foo.bin
92+
Dumping to foo.bin
93+
Wrote 153 bytes to foo.bin
94+
9095
# Update just the serial number
9196
> framework_tool --flash_gpu_descriptor GPU FRAKMQCP41500ASSY1
9297
> framework_tool --flash_gpu_descriptor 13 FRAKMQCP41500ASSY1

framework_lib/src/chromium_ec/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,16 @@ impl CrosEc {
12541254
Ok(())
12551255
}
12561256

1257+
pub fn read_gpu_descriptor(&self) -> EcResult<Vec<u8>> {
1258+
let header = self.read_gpu_desc_header()?;
1259+
if header.magic != [0x32, 0xAC, 0x00, 0x00] {
1260+
return Err(EcError::DeviceError(
1261+
"Invalid descriptor hdr magic".to_string(),
1262+
));
1263+
}
1264+
self.read_ec_gpu_chunk(0x00, header.descriptor_length as u16)
1265+
}
1266+
12571267
pub fn read_gpu_desc_header(&self) -> EcResult<GpuCfgDescriptor> {
12581268
let bytes =
12591269
self.read_ec_gpu_chunk(0x00, core::mem::size_of::<GpuCfgDescriptor>() as u16)?;

framework_lib/src/commandline/clap_std.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ struct ClapCli {
274274
/// File to write to the gpu EEPROM
275275
#[arg(long)]
276276
flash_gpu_descriptor_file: Option<std::path::PathBuf>,
277+
278+
/// File to dump the gpu EEPROM to
279+
#[arg(long)]
280+
dump_gpu_descriptor_file: Option<std::path::PathBuf>,
277281
}
278282

279283
/// Parse a list of commandline arguments and return the struct
@@ -464,6 +468,9 @@ pub fn parse(args: &[String]) -> Cli {
464468
flash_gpu_descriptor_file: args
465469
.flash_gpu_descriptor_file
466470
.map(|x| x.into_os_string().into_string().unwrap()),
471+
dump_gpu_descriptor_file: args
472+
.dump_gpu_descriptor_file
473+
.map(|x| x.into_os_string().into_string().unwrap()),
467474
raw_command: vec![],
468475
}
469476
}

framework_lib/src/commandline/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ pub struct Cli {
202202
pub info: bool,
203203
pub flash_gpu_descriptor: Option<(u8, String)>,
204204
pub flash_gpu_descriptor_file: Option<String>,
205+
pub dump_gpu_descriptor_file: Option<String>,
205206
// UEFI only
206207
pub allupdate: bool,
207208
pub paginate: bool,
@@ -680,6 +681,24 @@ fn dump_ec_flash(ec: &CrosEc, dump_path: &str) {
680681
}
681682
}
682683

684+
fn dump_dgpu_eeprom(ec: &CrosEc, dump_path: &str) {
685+
let flash_bin = ec.read_gpu_descriptor().unwrap();
686+
687+
#[cfg(not(feature = "uefi"))]
688+
{
689+
let mut file = fs::File::create(dump_path).unwrap();
690+
file.write_all(&flash_bin).unwrap();
691+
}
692+
#[cfg(feature = "uefi")]
693+
{
694+
let ret = crate::uefi::fs::shell_write_file(dump_path, &flash_bin);
695+
if ret.is_err() {
696+
println!("Failed to dump EC FW image.");
697+
}
698+
}
699+
println!("Wrote {} bytes to {}", flash_bin.len(), dump_path);
700+
}
701+
683702
fn compare_version(device: Option<HardwareDeviceType>, version: String, ec: &CrosEc) -> i32 {
684703
println!("Target Version {:?}", version);
685704

@@ -1270,6 +1289,9 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
12701289
} else {
12711290
println!("Unsupported on this platform");
12721291
}
1292+
} else if let Some(dump_path) = &args.dump_gpu_descriptor_file {
1293+
println!("Dumping to {}", dump_path);
1294+
dump_dgpu_eeprom(&ec, dump_path);
12731295
}
12741296

12751297
0

framework_lib/src/commandline/uefi.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub fn parse(args: &[String]) -> Cli {
117117
help: false,
118118
flash_gpu_descriptor: None,
119119
flash_gpu_descriptor_file: None,
120+
dump_gpu_descriptor_file: None,
120121
allupdate: false,
121122
info: false,
122123
raw_command: vec![],
@@ -773,6 +774,14 @@ pub fn parse(args: &[String]) -> Cli {
773774
None
774775
};
775776
found_an_option = true;
777+
} else if arg == "--dump-gpu-descriptor-file" {
778+
cli.dump_gpu_descriptor_file = if args.len() > i + 1 {
779+
Some(args[i + 1].clone())
780+
} else {
781+
println!("Need to provide a value for --dump_gpu_descriptor_file. PATH");
782+
None
783+
};
784+
found_an_option = true;
776785
}
777786
}
778787

0 commit comments

Comments
 (0)