Skip to content

Commit ce0c781

Browse files
committed
Support dumping Turin data structures and Milan data structures at the same time.
Fixes <#191>.
1 parent b6c0a6e commit ce0c781

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
amd-apcb = { git = "https://github.com/oxidecomputer/amd-apcb.git", tag = "v0.3.3", features = ["std", "serde", "schemars"] }
10+
amd-apcb = { git = "https://github.com/oxidecomputer/amd-apcb.git", branch = "issue-135", features = ["std", "serde", "schemars"] }
1111
amd-efs = { git = "ssh://git@github.com/oxidecomputer/amd-efs.git", tag = "v0.4.0", features = ["std", "serde", "schemars"] }
1212
goblin = { version = "0.4", features = ["elf64", "endian_fd"] }
1313
serde = { version = "1.0", default-features = false, features = ["derive"] }

amd-host-image-builder-config/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd-host-image-builder-config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2018"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
amd-apcb = { git = "https://github.com/oxidecomputer/amd-apcb.git", tag = "v0.3.3", features = ["std", "serde", "schemars"] }
9+
amd-apcb = { git = "https://github.com/oxidecomputer/amd-apcb.git", branch = "issue-135", features = ["std", "serde", "schemars"] }
1010
amd-efs = { git = "ssh://git@github.com/oxidecomputer/amd-efs.git", tag = "v0.4.0", features = ["std", "serde", "schemars"] }
1111
schemars = "0.8.8"
1212
serde = { version = "1.0", default-features = false, features = ["derive"] }

src/main.rs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use amd_apcb::{Apcb, ApcbIoOptions};
1+
use amd_apcb::{Apcb, ApcbIoOptions, Context};
22

33
use amd_efs::{
44
AddressMode, BhdDirectory, BhdDirectoryEntry, BhdDirectoryEntryType,
@@ -772,6 +772,7 @@ fn dump_bhd_directory<'a, T: FlashRead + FlashWrite>(
772772
bhd_directory: &BhdDirectory,
773773
apcb_buffer_option: &mut Option<&'a mut [u8]>,
774774
blob_dump_dirname: &Option<PathBuf>,
775+
context: Context,
775776
) -> SerdeBhdDirectoryVariant<'a> {
776777
if let Some(blob_dump_dirname) = &blob_dump_dirname {
777778
let mut path = PathBuf::new();
@@ -808,7 +809,7 @@ fn dump_bhd_directory<'a, T: FlashRead + FlashWrite>(
808809
std::borrow::Cow::Borrowed(
809810
apcb_buffer,
810811
),
811-
&ApcbIoOptions::default(),
812+
&ApcbIoOptions::default().with_context(context).build(),
812813
)
813814
.unwrap();
814815
apcb.validate(None).unwrap(); // TODO: abl0 version ?
@@ -836,7 +837,7 @@ fn dump_bhd_directory<'a, T: FlashRead + FlashWrite>(
836837
t.push("bhd-second-level");
837838
t
838839
});
839-
let variant = dump_bhd_directory(storage, &sub_bhd_directory, apcb_buffer_option, &subdir); //SerdeBhdDirectoryVariant
840+
let variant = dump_bhd_directory(storage, &sub_bhd_directory, apcb_buffer_option, &subdir, context); //SerdeBhdDirectoryVariant
840841
Some(SerdeBhdEntry {
841842
source: SerdeBhdSource::SecondLevelDirectory(match variant {
842843
SerdeBhdDirectoryVariant::BhdDirectory(d) => d,
@@ -922,6 +923,13 @@ fn dump(
922923
Some(efs.psp_directory().unwrap().beginning());
923924
let bhd_main_directory_flash_location =
924925
Some(efs.bhd_directory(None).unwrap().beginning());
926+
927+
let psp = dump_psp_directory(
928+
&storage,
929+
&efs.psp_directory().unwrap(),
930+
&blob_dump_dirname,
931+
);
932+
925933
let config = SerdeConfig {
926934
processor_generation: *gen,
927935
spi_mode_bulldozer: efs.spi_mode_bulldozer().unwrap(),
@@ -932,17 +940,30 @@ fn dump(
932940
psp_main_directory_flash_location,
933941
bhd_main_directory_flash_location,
934942
// TODO: psp_directory or psp_combo_directory
935-
psp: dump_psp_directory(
936-
&storage,
937-
&efs.psp_directory().unwrap(),
938-
&blob_dump_dirname,
939-
),
943+
psp,
940944
// TODO: bhd_directory or bhd_combo_directory
941945
bhd: dump_bhd_directory(
942946
&storage,
943947
&efs.bhd_directory(None).unwrap(),
944948
&mut apcb_buffer_option,
945949
&blob_dump_dirname,
950+
match *gen {
951+
ProcessorGeneration::Naples => {
952+
Context::builder().with_generation(1).build() // FIXME abl0 version (from "psp" variable)
953+
} // FIXME
954+
ProcessorGeneration::Rome => {
955+
Context::builder().with_generation(2).build()
956+
}
957+
ProcessorGeneration::Milan => {
958+
Context::builder().with_generation(3).build()
959+
}
960+
ProcessorGeneration::Genoa => {
961+
Context::builder().with_generation(4).build()
962+
}
963+
ProcessorGeneration::Turin => {
964+
Context::builder().with_generation(5).build()
965+
}
966+
},
946967
),
947968
};
948969
if let Some(blob_dump_dirname) = &blob_dump_dirname {
@@ -1183,6 +1204,8 @@ fn prepare_bhd_directory_contents<'a>(
11831204
// Note: We need to do this
11841205
// manually because validation
11851206
// needs ABL_VERSION.
1207+
// FIXME make sure to compare apcb.context() with our processor generation here.
1208+
// Since the context is actually serialized to the JSON5 it could be messed with by the user and then deserialized again.
11861209
apcb.validate(None)
11871210
.map_err(apcb_to_io_error)
11881211
.unwrap();
@@ -1227,7 +1250,7 @@ fn generate(
12271250
blobdirs: Vec<PathBuf>,
12281251
verbose: bool,
12291252
) -> std::io::Result<()> {
1230-
let filename = &output_filename;
1253+
let filename = output_filename;
12311254
let flash_to_io_error = |e: amd_efs::flash::Error| {
12321255
std::io::Error::new(
12331256
std::io::ErrorKind::Other,

0 commit comments

Comments
 (0)