@@ -15,10 +15,6 @@ type ExitCode = i32;
15
15
#[ derive( FromArgs ) ]
16
16
/// Build the bootloader
17
17
struct BuildArguments {
18
- /// path to the `Cargo.toml` of the kernel
19
- #[ argh( option) ]
20
- kernel_manifest : PathBuf ,
21
-
22
18
/// path to the kernel ELF binary
23
19
#[ argh( option) ]
24
20
kernel_binary : PathBuf ,
@@ -107,8 +103,6 @@ fn main() -> anyhow::Result<()> {
107
103
if args. quiet {
108
104
cmd. arg ( "--quiet" ) ;
109
105
}
110
- cmd. env ( "KERNEL" , & args. kernel_binary ) ;
111
- cmd. env ( "KERNEL_MANIFEST" , & args. kernel_manifest ) ;
112
106
assert ! ( cmd. status( ) ?. success( ) ) ;
113
107
114
108
// Retrieve binary paths
@@ -155,7 +149,7 @@ fn main() -> anyhow::Result<()> {
155
149
156
150
if let Some ( out_dir) = & args. out_dir {
157
151
let efi_file = out_dir. join ( format ! ( "boot-{}-{}.efi" , executable_name, kernel_name) ) ;
158
- create_uefi_disk_image ( & executable_path, & efi_file)
152
+ create_uefi_disk_image ( & executable_path, & efi_file, & args . kernel_binary )
159
153
. context ( "failed to create UEFI disk image" ) ?;
160
154
}
161
155
}
@@ -176,8 +170,6 @@ fn main() -> anyhow::Result<()> {
176
170
if args. quiet {
177
171
cmd. arg ( "--quiet" ) ;
178
172
}
179
- cmd. env ( "KERNEL" , & args. kernel_binary ) ;
180
- cmd. env ( "KERNEL_MANIFEST" , & args. kernel_manifest ) ;
181
173
cmd. env ( "RUSTFLAGS" , "-C opt-level=s" ) ;
182
174
assert ! ( cmd. status( ) ?. success( ) ) ;
183
175
@@ -233,13 +225,21 @@ fn main() -> anyhow::Result<()> {
233
225
Ok ( ( ) )
234
226
}
235
227
236
- fn create_uefi_disk_image ( executable_path : & Path , efi_file : & Path ) -> anyhow:: Result < ( ) > {
228
+ fn create_uefi_disk_image (
229
+ executable_path : & Path ,
230
+ efi_file : & Path ,
231
+ kernel_binary : & Path ,
232
+ ) -> anyhow:: Result < ( ) > {
237
233
fs:: copy ( & executable_path, & efi_file) . context ( "failed to copy efi file to out dir" ) ?;
238
234
239
235
let efi_size = fs:: metadata ( & efi_file)
240
236
. context ( "failed to read metadata of efi file" ) ?
241
237
. len ( ) ;
242
238
239
+ let kernel_size = fs:: metadata ( & kernel_binary)
240
+ . context ( "failed to read metadata of kernel binary" ) ?
241
+ . len ( ) ;
242
+
243
243
// create fat partition
244
244
let fat_file_path = {
245
245
const MB : u64 = 1024 * 1024 ;
@@ -252,9 +252,10 @@ fn create_uefi_disk_image(executable_path: &Path, efi_file: &Path) -> anyhow::Re
252
252
. truncate ( true )
253
253
. open ( & fat_path)
254
254
. context ( "Failed to create UEFI FAT file" ) ?;
255
- let efi_size_padded_and_rounded = ( ( efi_size + 1024 * 64 - 1 ) / MB + 1 ) * MB ;
255
+ let fat_size = efi_size + kernel_size;
256
+ let fat_size_padded_and_rounded = ( ( fat_size + 1024 * 64 - 1 ) / MB + 1 ) * MB ;
256
257
fat_file
257
- . set_len ( efi_size_padded_and_rounded )
258
+ . set_len ( fat_size_padded_and_rounded )
258
259
. context ( "failed to set UEFI FAT file length" ) ?;
259
260
260
261
// create new FAT partition
@@ -272,6 +273,11 @@ fn create_uefi_disk_image(executable_path: &Path, efi_file: &Path) -> anyhow::Re
272
273
bootx64. truncate ( ) ?;
273
274
io:: copy ( & mut fs:: File :: open ( & executable_path) ?, & mut bootx64) ?;
274
275
276
+ // copy kernel to FAT filesystem
277
+ let mut kernel_file = root_dir. create_file ( "kernel-x86_64" ) ?;
278
+ kernel_file. truncate ( ) ?;
279
+ io:: copy ( & mut fs:: File :: open ( & kernel_binary) ?, & mut kernel_file) ?;
280
+
275
281
fat_path
276
282
} ;
277
283
@@ -315,7 +321,7 @@ fn create_uefi_disk_image(executable_path: &Path, efi_file: &Path) -> anyhow::Re
315
321
316
322
// add add EFI system partition
317
323
let partition_id = disk
318
- . add_partition ( "boot" , partition_size, gpt:: partition_types:: EFI , 0 )
324
+ . add_partition ( "boot" , partition_size, gpt:: partition_types:: EFI , 0 , None )
319
325
. context ( "failed to add boot partition" ) ?;
320
326
321
327
let partition = disk
0 commit comments