Skip to content

Add support for Implied ApobNvCopy BHD directory entry #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions etc/turin-cosmo-1.0.0.5.efs.json5
Original file line number Diff line number Diff line change
@@ -2487,15 +2487,15 @@
ConsoleOutControl: {
abl_console_out_control: {
enable_console_logging: true,
enable_mem_flow_logging: true,
enable_mem_setreg_logging: true,
enable_mem_flow_logging: false,
enable_mem_setreg_logging: false,
enable_mem_getreg_logging: false,
enable_mem_status_logging: true,
enable_mem_status_logging: false,
enable_mem_pmu_logging: true,
enable_mem_pmu_sram_read_logging: false,
enable_mem_pmu_sram_write_logging: false,
enable_mem_test_verbose_logging: false,
enable_mem_basic_output_logging: true,
enable_mem_basic_output_logging: false,
abl_console_port: 128
},
abl_breakpoint_control: {
@@ -11064,7 +11064,7 @@
},
{
Byte: {
FchConsoleOutMode: "Disabled"
FchConsoleOutMode: "Enabled"
}
},
{
@@ -11568,6 +11568,21 @@
type: "ApcbBackup"
}
},
{
source: "Implied",
target: {
type: "Apob",
ram_destination_address: 0x4000000
}
},
{
source: "Implied",
target: {
type: "ApobNvCopy",
flash_location: 0x7000000,
size: 0xd0000
}
},
{
source: {
BlobFile: "Type0x64_AppbDdr5RdimmImem3_BRH.ecsbin"
13,876 changes: 13,836 additions & 40 deletions etc/turin-rubyred-1.0.0.2-p1.efs.json5

Large diffs are not rendered by default.

84 changes: 64 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -413,10 +413,10 @@
) -> std::io::Result<(PspDirectory, ErasableRange, Option<ErasableLocation>)> {
let filename = output_filename;
let efs_to_io_error = |e| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("EFS error: {e:?} in file {filename:?}"),
)

Check warning on line 419 in src/main.rs

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

warning: this can be `std::io::Error::other(_)` --> src/main.rs:416:9 | 416 | / std::io::Error::new( 417 | | std::io::ErrorKind::Other, 418 | | format!("EFS error: {e:?} in file {filename:?}"), 419 | | ) | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error help: use `std::io::Error::other` | 416 ~ std::io::Error::other( 417 ~ format!("EFS error: {e:?} in file {filename:?}"), |
};

let mut first_payload_range_beginning: Option<ErasableLocation> = None;
@@ -523,10 +523,10 @@
) -> std::io::Result<(BhdDirectory, ErasableRange, Option<ErasableLocation>)> {
let filename = output_filename;
let efs_to_io_error = |e| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("EFS error: {e:?} in file {filename:?}"),
)

Check warning on line 529 in src/main.rs

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

warning: this can be `std::io::Error::other(_)` --> src/main.rs:526:9 | 526 | / std::io::Error::new( 527 | | std::io::ErrorKind::Other, 528 | | format!("EFS error: {e:?} in file {filename:?}"), 529 | | ) | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error help: use `std::io::Error::other` | 526 ~ std::io::Error::other( 527 ~ format!("EFS error: {e:?} in file {filename:?}"), |
};

let mut first_payload_range_beginning: Option<ErasableLocation> = None;
@@ -1258,13 +1258,13 @@
) -> BhdDirectoryContents<'a> {
let mut custom_bios_reset_entry: bool = false;
let apcb_to_io_error = |e| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"APCB error: {e:?} in file {:?}",
efs_configuration_filename
),
)

Check warning on line 1267 in src/main.rs

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

warning: this can be `std::io::Error::other(_)` --> src/main.rs:1261:9 | 1261 | / std::io::Error::new( 1262 | | std::io::ErrorKind::Other, 1263 | | format!( 1264 | | "APCB error: {e:?} in file {:?}", 1265 | | efs_configuration_filename 1266 | | ), 1267 | | ) | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error help: use `std::io::Error::other` | 1261 ~ std::io::Error::other( 1262 ~ format!( |
};
let bhd_directory_address_mode = AddressMode::EfsRelativeOffset;
let mut custom_apob = Option::<u64>::None;
@@ -1289,43 +1289,87 @@
}
let source = entry.source;
let blob_slot_settings = entry.target.blob;
let flash_location =
blob_slot_settings.as_ref().and_then(|x| x.flash_location)
let flash_location = blob_slot_settings
.as_ref()
.and_then(|x| x.flash_location)
// AMD sometimes uses target.flash_location=Some(0) together
// with Implied to mean "No flash location".
// Ignore that (definitely do not allocate that on the flash).
.filter(|&loc| !(matches!(source, SerdeBhdSource::Implied) && loc == 0));
.filter(|&loc| {
!(matches!(source, SerdeBhdSource::Implied) && loc == 0)
});

// done by try_from: raw_entry.set_destination_location(ram_destination_address);
// done by try_from: raw_entry.set_size(size);
match source {
SerdeBhdSource::Implied => {
assert_eq!(entry.target.attrs.type_, BhdDirectoryEntryType::Apob,
"Implied supports is only supported for Apob, not {typ}. Are you sure you want to do that?",
typ = entry.target.attrs.type_);
assert!(flash_location.is_none(),
"You specified a fixed flash location for {typ} but it has an Implied source. What does that mean?",
typ = entry.target.attrs.type_);
custom_apob = Some(raw_entry.destination_location().expect("destination address"));
raw_entry.set_size(Some(0));
vec![(raw_entry, None, None)]
}
SerdeBhdSource::Implied => match entry.target.attrs.type_ {
BhdDirectoryEntryType::Apob => {
assert!(
flash_location.is_none(),
"You specified a
fixed flash location for {typ} but it has
an Implied source. What does that mean?",
typ = entry.target.attrs.type_
);
custom_apob = Some(
raw_entry
.destination_location()
.expect("destination address"),
);
raw_entry.set_size(Some(0));
vec![(raw_entry, None, None)]
}
BhdDirectoryEntryType::ApobNvCopy => {
assert!(
raw_entry.destination_location().is_none(),
"You specified a fixed RAM location for
{typ}. What does that mean?",
typ = entry.target.attrs.type_
);
assert!(
flash_location.is_some(),
"You did not
specify a flash location for {typ}.",
typ = entry.target.attrs.type_
);
assert_ne!(
raw_entry.size(),
Some(0),
"You did not
specify a size for {typ}.",
typ = entry.target.attrs.type_
);
vec![(raw_entry, None, None)]
}
_ => {
panic!(
"Implied source is only supported for Apob
and ApobNvCopy, not {typ}. Are you sure you
want to do that?",
typ = entry.target.attrs.type_
);
}
},
SerdeBhdSource::BlobFile(blob_filename) => {
assert_ne!(entry.target.attrs.type_, BhdDirectoryEntryType::Apob,
"You specified a Blob for Apob? What does that mean?");
assert_ne!(
entry.target.attrs.type_,
BhdDirectoryEntryType::Apob,
"You specified a Blob for Apob? What does that mean?"
);
let blob_filename = resolve_blob(blob_filename).unwrap();
let body = std::fs::read(blob_filename).unwrap();
raw_entry.set_size(Some(body.len().try_into().unwrap()));
vec![(raw_entry, flash_location, Some(body))]
}
SerdeBhdSource::ApcbJson(apcb) => {
assert!(generate_is_context_valid(processor_generation, &apcb));
assert!(generate_is_context_valid(
processor_generation,
&apcb
));
// Note: We need to do this
// manually because validation
// needs ABL_VERSION.
apcb.validate(None)
.map_err(apcb_to_io_error)
.unwrap();
apcb.validate(None).map_err(apcb_to_io_error).unwrap();
let buf =
apcb.save_no_inc().map_err(apcb_to_io_error).unwrap();
let bufref = buf.as_ref();
@@ -1369,42 +1413,42 @@
) -> std::io::Result<()> {
let filename = output_filename;
let flash_to_io_error = |e: amd_efs::flash::Error| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("Flash error: {e:?} in file {filename:?}"),
)

Check warning on line 1419 in src/main.rs

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

warning: this can be `std::io::Error::other(_)` --> src/main.rs:1416:9 | 1416 | / std::io::Error::new( 1417 | | std::io::ErrorKind::Other, 1418 | | format!("Flash error: {e:?} in file {filename:?}"), 1419 | | ) | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error help: use `std::io::Error::other` | 1416 ~ std::io::Error::other( 1417 ~ format!("Flash error: {e:?} in file {filename:?}"), |
};
let efs_to_io_error = |e: amd_efs::Error| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"Config error: {e:?} in file {:?}",
efs_configuration_filename
),
)

Check warning on line 1428 in src/main.rs

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

warning: this can be `std::io::Error::other(_)` --> src/main.rs:1422:9 | 1422 | / std::io::Error::new( 1423 | | std::io::ErrorKind::Other, 1424 | | format!( 1425 | | "Config error: {e:?} in file {:?}", 1426 | | efs_configuration_filename 1427 | | ), 1428 | | ) | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error help: use `std::io::Error::other` | 1422 ~ std::io::Error::other( 1423 ~ format!( |
};
let json5_to_io_error = |e: json5::Error| match e {
json5::Error::Message { ref msg, ref location } => std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"JSON5 error: {msg} in file {:?} at {}",
efs_configuration_filename,
match location {
None => "unknown location".to_owned(),
Some(x) => format!("{x:?}"),
}
),
),

Check warning on line 1441 in src/main.rs

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

warning: this can be `std::io::Error::other(_)` --> src/main.rs:1431:60 | 1431 | json5::Error::Message { ref msg, ref location } => std::io::Error::new( | ____________________________________________________________^ 1432 | | std::io::ErrorKind::Other, 1433 | | format!( 1434 | | "JSON5 error: {msg} in file {:?} at {}", ... | 1440 | | ), 1441 | | ), | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error help: use `std::io::Error::other` | 1431 ~ json5::Error::Message { ref msg, ref location } => std::io::Error::other( 1432 ~ format!( |
};
let amd_host_image_builder_config_error_to_io_error =
|e: amd_host_image_builder_config::Error| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"Config error: {e:?} in file {:?}",
reset_image_filename
),
)

Check warning on line 1451 in src/main.rs

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

warning: this can be `std::io::Error::other(_)` --> src/main.rs:1445:13 | 1445 | / std::io::Error::new( 1446 | | std::io::ErrorKind::Other, 1447 | | format!( 1448 | | "Config error: {e:?} in file {:?}", 1449 | | reset_image_filename 1450 | | ), 1451 | | ) | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error help: use `std::io::Error::other` | 1445 ~ std::io::Error::other( 1446 ~ format!( |
};
let blobdirs = &blobdirs;
let resolve_blob = |blob_filename: PathBuf| -> std::io::Result<PathBuf> {
@@ -1412,12 +1456,12 @@
if blob_filename.exists() {
Ok(blob_filename)
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"Blob read error: Could not find file {blob_filename:?}",
),
))

Check warning on line 1464 in src/main.rs

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

warning: this can be `std::io::Error::other(_)` --> src/main.rs:1459:21 | 1459 | Err(std::io::Error::new( | _____________________^ 1460 | | std::io::ErrorKind::Other, 1461 | | format!( 1462 | | "Blob read error: Could not find file {blob_filename:?}", 1463 | | ), 1464 | | )) | |_________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error help: use `std::io::Error::other` | 1459 ~ Err(std::io::Error::other( 1460 ~ format!( |
}
} else {
for blobdir in blobdirs {
@@ -1429,13 +1473,13 @@
return Ok(fullname);
}
}
Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"Blob read error: Could not find file {blob_filename:?} \
(neither directly nor in any of the directories {blobdirs:?})",
),
))

Check warning on line 1482 in src/main.rs

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

warning: this can be `std::io::Error::other(_)` --> src/main.rs:1476:17 | 1476 | Err(std::io::Error::new( | _________________^ 1477 | | std::io::ErrorKind::Other, 1478 | | format!( 1479 | | "Blob read error: Could not find file {blob_filename:?} \ 1480 | | (neither directly nor in any of the directories {blobdirs:?})", 1481 | | ), 1482 | | )) | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error help: use `std::io::Error::other` | 1476 ~ Err(std::io::Error::other( 1477 ~ format!( |
}
};


Unchanged files with check annotations Beta

let filename = &self.filename;
let file_size = u32::try_from(self.file_size()?).unwrap();
let flash_to_io_error = |e: amd_efs::flash::Error| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("Flash error: {e:?} in file {filename:?}"),
)

Check warning on line 150 in src/images.rs

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

warning: this can be `std::io::Error::other(_)` --> src/images.rs:147:13 | 147 | / std::io::Error::new( 148 | | std::io::ErrorKind::Other, 149 | | format!("Flash error: {e:?} in file {filename:?}"), 150 | | ) | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error = note: `#[warn(clippy::io_other_error)]` on by default help: use `std::io::Error::other` | 147 ~ std::io::Error::other( 148 ~ format!("Flash error: {e:?} in file {filename:?}"), |
};
let erasable_block_size = self.erasable_block_size;
let mut position =