@@ -19,6 +19,7 @@ use std::cmp::min;
19
19
use std:: collections:: HashSet ;
20
20
use std:: fs;
21
21
use std:: fs:: File ;
22
+ use std:: io:: stdout;
22
23
use std:: io:: BufReader ;
23
24
use std:: io:: Read ;
24
25
use std:: io:: Seek ;
@@ -653,6 +654,11 @@ fn dump_bhd_directory<'a, T: FlashRead + FlashWrite>(
653
654
. map_while ( |entry| {
654
655
let entry = entry. clone ( ) ;
655
656
if let Ok ( typ) = entry. typ_or_err ( ) {
657
+ if typ == BhdDirectoryEntryType :: Apob {
658
+ // Since this is a runtime value we cannot read it
659
+ // from the image.
660
+ return None ;
661
+ }
656
662
let payload_beginning =
657
663
bhd_directory. payload_beginning ( & entry) . unwrap ( ) ;
658
664
let size = entry. size ( ) . unwrap ( ) as usize ;
@@ -727,6 +733,7 @@ fn dump_bhd_directory<'a, T: FlashRead + FlashWrite>(
727
733
fn dump (
728
734
image_filename : & Path ,
729
735
blob_dump_dirname : Option < PathBuf > ,
736
+ output_config_file : & mut impl std:: io:: Write ,
730
737
) -> std:: io:: Result < ( ) > {
731
738
let filename = image_filename;
732
739
let storage = FlashImage :: load ( filename) ?;
@@ -735,25 +742,40 @@ fn dump(
735
742
if filesize <= 0x100_0000 { Some ( filesize as u32 ) } else { None } ;
736
743
let efs = Efs :: load ( & storage, None , amd_physical_mode_mmio_size) . unwrap ( ) ;
737
744
if !efs. compatible_with_processor_generation ( ProcessorGeneration :: Milan ) {
738
- panic ! ( "only Milan is supported for dumping right now" ) ;
745
+ if !efs. compatible_with_processor_generation ( ProcessorGeneration :: Rome )
746
+ {
747
+ panic ! ( "only Milan or Rome is supported for dumping right now" ) ;
748
+ }
739
749
}
740
750
let mut apcb_buffer = [ 0xFFu8 ; Apcb :: MAX_SIZE ] ;
741
751
let mut apcb_buffer_option = Some ( & mut apcb_buffer[ ..] ) ;
752
+ let processor_generation = if efs
753
+ . compatible_with_processor_generation ( ProcessorGeneration :: Milan )
754
+ {
755
+ ProcessorGeneration :: Milan
756
+ } else {
757
+ ProcessorGeneration :: Rome
758
+ } ;
742
759
let config = SerdeConfig {
743
- processor_generation : ProcessorGeneration :: Milan , // FIXME could be ambiguous
744
- spi_mode_bulldozer : efs. spi_mode_bulldozer ( ) . unwrap ( ) ,
745
- spi_mode_zen_naples : efs. spi_mode_zen_naples ( ) . unwrap ( ) ,
746
- spi_mode_zen_rome : efs. spi_mode_zen_rome ( ) . unwrap ( ) ,
760
+ processor_generation,
761
+ spi_mode_bulldozer : efs
762
+ . spi_mode_bulldozer ( )
763
+ . expect ( "Bulldozer SPI Mode" ) ,
764
+ spi_mode_zen_naples : efs
765
+ . spi_mode_zen_naples ( )
766
+ . expect ( "Naples SPI Mode" ) ,
767
+ spi_mode_zen_rome : efs. spi_mode_zen_rome ( ) . expect ( "Rome SPI Mode" ) ,
747
768
// TODO: psp_directory or psp_combo_directory
748
769
psp : dump_psp_directory (
749
770
& storage,
750
- & efs. psp_directory ( ) . unwrap ( ) ,
771
+ & efs. psp_directory ( ) . expect ( "PSP directory" ) ,
751
772
& blob_dump_dirname,
752
773
) ,
753
774
// TODO: bhd_directory or bhd_combo_directory
754
775
bhd : dump_bhd_directory (
755
776
& storage,
756
- & efs. bhd_directory ( None ) . unwrap ( ) ,
777
+ & efs. bhd_directory ( Some ( processor_generation) )
778
+ . expect ( "BHD directory" ) ,
757
779
& mut apcb_buffer_option,
758
780
& blob_dump_dirname,
759
781
) ,
@@ -766,7 +788,11 @@ fn dump(
766
788
let mut file = File :: create ( & path) . expect ( "creation failed" ) ;
767
789
writeln ! ( file, "{}" , json5:: to_string( & config) . unwrap( ) ) ?;
768
790
} else {
769
- println ! ( "{}" , serde_json:: to_string_pretty( & config) ?) ;
791
+ writeln ! (
792
+ output_config_file,
793
+ "{}" ,
794
+ serde_json:: to_string_pretty( & config) ?
795
+ ) ?;
770
796
}
771
797
Ok ( ( ) )
772
798
}
@@ -1155,21 +1181,42 @@ fn run() -> std::io::Result<()> {
1155
1181
} ;
1156
1182
match opts {
1157
1183
Opts :: Dump { input_filename, blob_dump_dirname } => {
1158
- dump ( & input_filename, blob_dump_dirname)
1184
+ dump ( & input_filename, blob_dump_dirname, & mut stdout ( ) . lock ( ) )
1159
1185
}
1160
1186
Opts :: Generate {
1161
1187
output_filename,
1162
1188
efs_configuration_filename,
1163
1189
reset_image_filename,
1164
1190
blobdirs,
1165
1191
verbose,
1166
- } => generate (
1167
- & output_filename,
1168
- & efs_configuration_filename,
1169
- & reset_image_filename,
1170
- blobdirs,
1171
- verbose,
1172
- ) ,
1192
+ } => {
1193
+ let x = generate (
1194
+ & output_filename,
1195
+ & efs_configuration_filename,
1196
+ & reset_image_filename,
1197
+ blobdirs,
1198
+ verbose,
1199
+ ) ;
1200
+
1201
+ // In order to make sure that we can dump it back out, try it.
1202
+ struct DummyOutput { }
1203
+ impl std:: io:: Write for DummyOutput {
1204
+ fn write (
1205
+ & mut self ,
1206
+ buf : & [ u8 ] ,
1207
+ ) -> std:: result:: Result < usize , std:: io:: Error >
1208
+ {
1209
+ Ok ( buf. len ( ) )
1210
+ }
1211
+ fn flush ( & mut self ) -> std:: result:: Result < ( ) , std:: io:: Error > {
1212
+ Ok ( ( ) )
1213
+ }
1214
+ }
1215
+ let mut dummy_output = DummyOutput { } ;
1216
+ dump ( & output_filename, None , & mut dummy_output)
1217
+ . expect ( "read it back out from the image" ) ;
1218
+ x
1219
+ }
1173
1220
}
1174
1221
}
1175
1222
0 commit comments