@@ -24,6 +24,10 @@ pub struct Qemu {
2424 #[ arg( long) ]
2525 microvm : bool ,
2626
27+ /// Run with U-Boot.
28+ #[ arg( long) ]
29+ u_boot : bool ,
30+
2731 #[ command( flatten) ]
2832 build : Build ,
2933
@@ -51,17 +55,9 @@ impl Qemu {
5155 eprintln ! ( "::endgroup::" )
5256 }
5357
54- let sh = crate :: sh ( ) ?;
55-
56- if self . build . target ( ) == Target :: X86_64Uefi {
57- sh. create_dir ( "target/esp/efi/boot" ) ?;
58- sh. copy_file ( self . build . dist_object ( ) , "target/esp/efi/boot/bootx64.efi" ) ?;
59- sh. copy_file (
60- self . build . ci_image ( self . image . as_deref ( ) . unwrap ( ) ) ,
61- "target/esp/efi/boot/hermit-app" ,
62- ) ?;
63- }
58+ self . prepare_image ( ) ?;
6459
60+ let sh = crate :: sh ( ) ?;
6561 let target = self . build . target ( ) ;
6662 let qemu = target. qemu ( ) ;
6763 let qemu = env:: var ( "QEMU" ) . unwrap_or_else ( |_| format ! ( "qemu-system-{qemu}" ) ) ;
@@ -82,6 +78,43 @@ impl Qemu {
8278 Ok ( ( ) )
8379 }
8480
81+ fn prepare_image ( & self ) -> Result < ( ) > {
82+ let sh = crate :: sh ( ) ?;
83+
84+ match self . build . target ( ) {
85+ Target :: X86_64Uefi => {
86+ sh. create_dir ( "target/esp/efi/boot" ) ?;
87+ sh. copy_file ( self . build . dist_object ( ) , "target/esp/efi/boot/bootx64.efi" ) ?;
88+ sh. copy_file (
89+ self . build . ci_image ( self . image . as_deref ( ) . unwrap ( ) ) ,
90+ "target/esp/efi/boot/hermit-app" ,
91+ ) ?;
92+ }
93+ Target :: Aarch64Elf | Target :: Aarch64BeElf if self . u_boot => {
94+ sh. create_dir ( "target/boot" ) ?;
95+ sh. copy_file ( self . build . dist_object ( ) , "target/boot/hermit-loader" ) ?;
96+ sh. copy_file (
97+ self . build . ci_image ( self . image . as_deref ( ) . unwrap ( ) ) ,
98+ "target/boot/hermit-app" ,
99+ ) ?;
100+
101+ cmd ! (
102+ sh,
103+ "mkimage -f xtask/src/ci/u-boot/boot.its target/boot/boot.scr"
104+ )
105+ . run ( ) ?;
106+ cmd ! (
107+ sh,
108+ "mkimage -E -f xtask/src/ci/u-boot/hermit.its target/boot/hermit.fit"
109+ )
110+ . run ( ) ?;
111+ }
112+ _ => ( ) ,
113+ }
114+
115+ Ok ( ( ) )
116+ }
117+
85118 fn machine_args ( & self ) -> Vec < String > {
86119 if self . microvm {
87120 let frequency = get_frequency ( ) ;
@@ -193,13 +226,20 @@ impl Qemu {
193226 ]
194227 } ;
195228 cpu_args. push ( "-semihosting" . to_string ( ) ) ;
196- cpu_args. push ( "-device" . to_string ( ) ) ;
197- cpu_args. push ( format ! (
198- "guest-loader,addr=0x48000000,initrd={}" ,
199- self . build
200- . ci_image( self . image. as_deref( ) . unwrap( ) )
201- . display( )
202- ) ) ;
229+ if self . u_boot {
230+ cpu_args. push ( "-bios" . to_string ( ) ) ;
231+ cpu_args. push ( "/usr/lib/u-boot/qemu_arm64/u-boot.bin" . to_string ( ) ) ;
232+ cpu_args. push ( "-drive" . to_string ( ) ) ;
233+ cpu_args. push ( "format=raw,file=fat:rw:target/boot" . to_string ( ) ) ;
234+ } else {
235+ cpu_args. push ( "-device" . to_string ( ) ) ;
236+ cpu_args. push ( format ! (
237+ "guest-loader,addr=0x48000000,initrd={}" ,
238+ self . build
239+ . ci_image( self . image. as_deref( ) . unwrap( ) )
240+ . display( )
241+ ) ) ;
242+ }
203243 cpu_args
204244 }
205245 Target :: Riscv64Sbi => {
0 commit comments