@@ -135,13 +135,22 @@ fn update_prebuilt() -> Result<PathBuf> {
135
135
enum OvmfFileType {
136
136
Code ,
137
137
Vars ,
138
+ Shell ,
138
139
}
139
140
140
141
impl OvmfFileType {
141
142
fn as_str ( & self ) -> & ' static str {
142
143
match self {
143
144
Self :: Code => "code" ,
144
145
Self :: Vars => "vars" ,
146
+ Self :: Shell => "shell" ,
147
+ }
148
+ }
149
+
150
+ fn extension ( & self ) -> & ' static str {
151
+ match self {
152
+ Self :: Code | Self :: Vars => "fd" ,
153
+ Self :: Shell => "efi" ,
145
154
}
146
155
}
147
156
@@ -161,6 +170,10 @@ impl OvmfFileType {
161
170
opt_path = & opt. ovmf_vars ;
162
171
var_name = "OVMF_VARS" ;
163
172
}
173
+ Self :: Shell => {
174
+ opt_path = & None ;
175
+ var_name = "OVMF_SHELL" ;
176
+ }
164
177
}
165
178
if let Some ( path) = opt_path {
166
179
Some ( path. clone ( ) )
@@ -173,6 +186,7 @@ impl OvmfFileType {
173
186
struct OvmfPaths {
174
187
code : PathBuf ,
175
188
vars : PathBuf ,
189
+ shell : PathBuf ,
176
190
}
177
191
178
192
impl OvmfPaths {
@@ -199,7 +213,11 @@ impl OvmfPaths {
199
213
} else {
200
214
let prebuilt_dir = update_prebuilt ( ) ?;
201
215
202
- Ok ( prebuilt_dir. join ( format ! ( "{arch}/{}.fd" , file_type. as_str( ) ) ) )
216
+ Ok ( prebuilt_dir. join ( format ! (
217
+ "{arch}/{}.{}" ,
218
+ file_type. as_str( ) ,
219
+ file_type. extension( )
220
+ ) ) )
203
221
}
204
222
}
205
223
@@ -208,8 +226,9 @@ impl OvmfPaths {
208
226
fn find ( opt : & QemuOpt , arch : UefiArch ) -> Result < Self > {
209
227
let code = Self :: find_ovmf_file ( OvmfFileType :: Code , opt, arch) ?;
210
228
let vars = Self :: find_ovmf_file ( OvmfFileType :: Vars , opt, arch) ?;
229
+ let shell = Self :: find_ovmf_file ( OvmfFileType :: Shell , opt, arch) ?;
211
230
212
- Ok ( Self { code, vars } )
231
+ Ok ( Self { code, vars, shell } )
213
232
}
214
233
}
215
234
@@ -352,7 +371,7 @@ fn process_qemu_io(mut monitor_io: Io, mut serial_io: Io, tmp_dir: &Path) -> Res
352
371
}
353
372
354
373
/// Create an EFI boot directory to pass into QEMU.
355
- fn build_esp_dir ( opt : & QemuOpt ) -> Result < PathBuf > {
374
+ fn build_esp_dir ( opt : & QemuOpt , ovmf_paths : & OvmfPaths ) -> Result < PathBuf > {
356
375
let build_mode = if opt. build_mode . release {
357
376
"release"
358
377
} else {
@@ -362,21 +381,31 @@ fn build_esp_dir(opt: &QemuOpt) -> Result<PathBuf> {
362
381
. join ( opt. target . as_triple ( ) )
363
382
. join ( build_mode) ;
364
383
let esp_dir = build_dir. join ( "esp" ) ;
384
+
385
+ // Create boot dir.
365
386
let boot_dir = esp_dir. join ( "EFI" ) . join ( "Boot" ) ;
366
- let built_file = if let Some ( example) = & opt. example {
367
- build_dir. join ( "examples" ) . join ( format ! ( "{example}.efi" ) )
368
- } else {
369
- build_dir. join ( "uefi-test-runner.efi" )
370
- } ;
371
- let output_file = match * opt. target {
387
+ if !boot_dir. exists ( ) {
388
+ fs_err:: create_dir_all ( & boot_dir) ?;
389
+ }
390
+
391
+ let boot_file_name = match * opt. target {
372
392
UefiArch :: AArch64 => "BootAA64.efi" ,
373
393
UefiArch :: IA32 => "BootIA32.efi" ,
374
394
UefiArch :: X86_64 => "BootX64.efi" ,
375
395
} ;
376
- if !boot_dir. exists ( ) {
377
- fs_err:: create_dir_all ( & boot_dir) ?;
378
- }
379
- fs_err:: copy ( built_file, boot_dir. join ( output_file) ) ?;
396
+
397
+ if let Some ( example) = & opt. example {
398
+ let src_path = build_dir. join ( "examples" ) . join ( format ! ( "{example}.efi" ) ) ;
399
+ fs_err:: copy ( src_path, boot_dir. join ( boot_file_name) ) ?;
400
+ } else {
401
+ let shell_launcher = build_dir. join ( "shell_launcher.efi" ) ;
402
+ fs_err:: copy ( shell_launcher, boot_dir. join ( boot_file_name) ) ?;
403
+
404
+ let test_runner = build_dir. join ( "uefi-test-runner.efi" ) ;
405
+ fs_err:: copy ( test_runner, boot_dir. join ( "test_runner.efi" ) ) ?;
406
+
407
+ fs_err:: copy ( & ovmf_paths. shell , boot_dir. join ( "shell.efi" ) ) ?;
408
+ } ;
380
409
381
410
Ok ( esp_dir)
382
411
}
@@ -403,8 +432,6 @@ impl Drop for ChildWrapper {
403
432
}
404
433
405
434
pub fn run_qemu ( arch : UefiArch , opt : & QemuOpt ) -> Result < ( ) > {
406
- let esp_dir = build_esp_dir ( opt) ?;
407
-
408
435
let qemu_exe = match arch {
409
436
UefiArch :: AArch64 => "qemu-system-aarch64" ,
410
437
UefiArch :: IA32 | UefiArch :: X86_64 => "qemu-system-x86_64" ,
@@ -506,6 +533,7 @@ pub fn run_qemu(arch: UefiArch, opt: &QemuOpt) -> Result<()> {
506
533
// Mount a local directory as a FAT partition.
507
534
cmd. arg ( "-drive" ) ;
508
535
let mut drive_arg = OsString :: from ( "format=raw,file=fat:rw:" ) ;
536
+ let esp_dir = build_esp_dir ( opt, & ovmf_paths) ?;
509
537
drive_arg. push ( esp_dir) ;
510
538
cmd. arg ( drive_arg) ;
511
539
0 commit comments