@@ -109,14 +109,47 @@ fn prepare_rootfs(target: &str, rootfs: &Path, server: &Path, rootfs_img: &Path)
109
109
t ! ( fs:: copy( server, rootfs. join( "testd" ) ) ) ;
110
110
111
111
match target {
112
- "arm-unknown-linux-gnueabihf" | "aarch64-unknown-linux-gnu" | "x86_64-unknown-uefi" => {
112
+ "arm-unknown-linux-gnueabihf" | "aarch64-unknown-linux-gnu" => {
113
113
prepare_rootfs_cpio ( rootfs, rootfs_img)
114
114
}
115
+ "x86_64-unknown-uefi" | "i686-unknown-uefi" => prepare_rootfs_fat ( rootfs, rootfs_img) ,
115
116
"riscv64gc-unknown-linux-gnu" => prepare_rootfs_ext4 ( rootfs, rootfs_img) ,
116
117
_ => panic ! ( "{} is not supported" , target) ,
117
118
}
118
119
}
119
120
121
+ fn prepare_rootfs_fat ( rootfs : & Path , rootfs_img : & Path ) {
122
+ // println!("Rootfs: {}", rootfs.to_string_lossy());
123
+ // println!("Rootfs Img: {}", rootfs_img.to_string_lossy());
124
+ let mut dd = Command :: new ( "dd" ) ;
125
+ dd. arg ( "if=/dev/zero" )
126
+ . arg ( & format ! ( "of={}" , rootfs_img. to_string_lossy( ) ) )
127
+ . arg ( "bs=1M" )
128
+ . arg ( "count=1024" ) ;
129
+ let mut dd_child = t ! ( dd. spawn( ) ) ;
130
+ assert ! ( t!( dd_child. wait( ) ) . success( ) ) ;
131
+
132
+ let mut mformat = Command :: new ( "mformat" ) ;
133
+ mformat. arg ( "-i" ) . arg ( rootfs_img) . arg ( "::" ) ;
134
+ let mut mformat_child = t ! ( mformat. spawn( ) ) ;
135
+ assert ! ( t!( mformat_child. wait( ) ) . success( ) ) ;
136
+
137
+ let mut mcopy = Command :: new ( "mcopy" ) ;
138
+ mcopy. arg ( "-i" ) . arg ( rootfs_img) ;
139
+ add_files ( & mut mcopy, rootfs) ;
140
+ mcopy. arg ( "::" ) ;
141
+ let mut mcopy_child = t ! ( mcopy. spawn( ) ) ;
142
+ assert ! ( t!( mcopy_child. wait( ) ) . success( ) ) ;
143
+
144
+ fn add_files ( cmd : & mut Command , cur : & Path ) {
145
+ for entry in t ! ( cur. read_dir( ) ) {
146
+ let entry = t ! ( entry) ;
147
+ let path = entry. path ( ) ;
148
+ cmd. arg ( path) ;
149
+ }
150
+ }
151
+ }
152
+
120
153
fn prepare_rootfs_cpio ( rootfs : & Path , rootfs_img : & Path ) {
121
154
// Generate a new rootfs image now that we've updated the test server
122
155
// executable. This is the equivalent of:
@@ -239,25 +272,51 @@ fn start_qemu_emulator(target: &str, rootfs: &Path, server: &Path, tmpdir: &Path
239
272
let mut cmd = Command :: new ( "qemu-system-x86_64" ) ;
240
273
cmd. arg ( "-nographic" )
241
274
. arg ( "-machine" )
242
- . arg ( "virt " )
275
+ . arg ( "q35 " )
243
276
. arg ( "-m" )
244
277
. arg ( "1024" )
245
278
. arg ( "-drive" )
246
- . arg ( "if=pflash,format=raw,unit=0, file=/tmp/OVMF/OVMF_CODE.fd" )
279
+ . arg ( "if=pflash,format=raw,file=/tmp/OVMF/OVMF_CODE.fd,index=0 " )
247
280
. arg ( "-drive" )
248
- . arg ( "if=pflash,format=raw,unit=1, file=/tmp/OVMF/OVMF_VARS.fd" )
281
+ . arg ( "if=pflash,format=raw,file=/tmp/OVMF/OVMF_VARS.fd,index=1 " )
249
282
. arg ( "-drive" )
250
- . arg ( "format=raw,file=/tmp/OVMF/UefiShell.iso" )
251
- . arg ( "-append" )
252
- . arg ( "quiet console=ttyS0" )
283
+ . arg ( "format=raw,file=/tmp/OVMF/UefiShell.iso,index=2" )
253
284
. arg ( "-netdev" )
254
285
. arg ( "user,id=net0,hostfwd=tcp::12345-:12345" )
255
286
. arg ( "-device" )
256
- . arg ( "virtio-net-device ,netdev=net0,mac=00:00:00:00:00:00" )
287
+ . arg ( "virtio-net-pci ,netdev=net0,mac=00:00:00:00:00:00" )
257
288
. arg ( "-drive" )
258
- . arg ( & format ! ( "file={},format=raw,media=disk" , & rootfs_img. to_string_lossy( ) ) ) ;
289
+ . arg ( & format ! (
290
+ "file={},format=raw,media=disk,index=3" ,
291
+ & rootfs_img. to_string_lossy( )
292
+ ) ) ;
259
293
t ! ( cmd. spawn( ) ) ;
260
294
}
295
+ "i686-unknown-uefi" => {
296
+ let mut cmd = Command :: new ( "qemu-system-i386" ) ;
297
+ cmd. arg ( "-nographic" )
298
+ . arg ( "-machine" )
299
+ . arg ( "q35" )
300
+ . arg ( "-m" )
301
+ . arg ( "1024" )
302
+ . arg ( "-drive" )
303
+ . arg ( "if=pflash,format=raw,file=/tmp/OVMF/OVMF_CODE.fd,index=0" )
304
+ . arg ( "-drive" )
305
+ . arg ( "if=pflash,format=raw,file=/tmp/OVMF/OVMF_VARS.fd,index=1" )
306
+ . arg ( "-drive" )
307
+ . arg ( "format=raw,file=/tmp/OVMF/UefiShell.iso,index=2" )
308
+ . arg ( "-netdev" )
309
+ . arg ( "user,id=net0,hostfwd=tcp::12345-:12345" )
310
+ . arg ( "-device" )
311
+ . arg ( "virtio-net-pci,netdev=net0,mac=00:00:00:00:00:00" )
312
+ . arg ( "-drive" )
313
+ . arg ( & format ! (
314
+ "file={},format=raw,media=disk,index=3" ,
315
+ & rootfs_img. to_string_lossy( )
316
+ ) ) ;
317
+ t ! ( cmd. spawn( ) ) ;
318
+ }
319
+
261
320
_ => panic ! ( "cannot start emulator for: {}" , target) ,
262
321
}
263
322
}
0 commit comments