-
Notifications
You must be signed in to change notification settings - Fork 2
Add builder.rs #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add builder.rs #21
Changes from all commits
5d11f71
f15a9b2
02dff2d
2a595f2
1490cfe
5c12569
e567d54
d1d37a8
9586fd8
0edd932
2935975
5256b63
637194b
ff20924
100193a
09f15f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,20 +15,34 @@ pub fn create_fat_image( | |
| kernel_path: &Path, | ||
| ) -> io::Result<u32> { | ||
| println!("create_fat_image: Starting creation of FAT image."); | ||
| println!("create_fat_image: fat_img_path: {:?}", fat_img_path); | ||
| println!("create_fat_image: loader_path: {:?}", loader_path); | ||
| println!("create_fat_image: kernel_path: {:?}", kernel_path); | ||
|
Comment on lines
+18
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment on lines
+18
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These
Comment on lines
+18
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These |
||
|
|
||
| // Ensure both files exist | ||
| if !loader_path.exists() { | ||
| println!( | ||
| "create_fat_image: Loader file NOT found at {:?}", | ||
| loader_path | ||
| ); | ||
| return Err(io::Error::new( | ||
| io::ErrorKind::NotFound, | ||
| format!("Loader file not found at {:?}", loader_path), | ||
| )); | ||
| } | ||
| println!("create_fat_image: Loader file found at {:?}", loader_path); | ||
|
|
||
| if !kernel_path.exists() { | ||
| println!( | ||
| "create_fat_image: Kernel file NOT found at {:?}", | ||
| kernel_path | ||
| ); | ||
| return Err(io::Error::new( | ||
| io::ErrorKind::NotFound, | ||
| format!("Kernel file not found at {:?}", kernel_path), | ||
| )); | ||
| } | ||
| println!("create_fat_image: Kernel file found at {:?}", kernel_path); | ||
|
|
||
| // Calculate the minimum image size based on both files | ||
| let loader_size = loader_path.metadata()?.len(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,20 +14,24 @@ pub const BOOT_CATALOG_EFI_PLATFORM_ID: u8 = 0xEF; | |
| pub const ID_FIELD_OFFSET: usize = 4; | ||
| pub const BOOT_CATALOG_CHECKSUM_OFFSET: usize = 28; | ||
|
|
||
| /// Writes an El Torito boot catalog for UEFI. | ||
| pub fn write_boot_catalog( | ||
| iso: &mut File, | ||
| boot_img_lba: u32, | ||
| boot_img_sectors: u16, | ||
| ) -> io::Result<()> { | ||
| pub struct BootCatalogEntry { | ||
| pub platform_id: u8, | ||
| pub boot_image_lba: u32, | ||
| pub boot_image_sectors: u16, | ||
| pub bootable: bool, | ||
| } | ||
|
|
||
| /// Writes an El Torito boot catalog. | ||
| pub fn write_boot_catalog(iso: &mut File, entries: Vec<BootCatalogEntry>) -> io::Result<()> { | ||
| pad_to_lba(iso, LBA_BOOT_CATALOG)?; | ||
|
|
||
| let mut catalog = [0u8; ISO_SECTOR_SIZE]; | ||
| let mut offset = 0; | ||
|
|
||
| // Validation Entry (32 bytes) | ||
| let mut val = [0u8; 32]; | ||
| val[0] = BOOT_CATALOG_VALIDATION_ENTRY_HEADER_ID; | ||
| val[1] = BOOT_CATALOG_EFI_PLATFORM_ID; | ||
| val[1] = BOOT_CATALOG_EFI_PLATFORM_ID; // This is for the primary boot entry, usually UEFI | ||
|
|
||
| // ID string "UEFI" + zero padding (24 bytes total) | ||
| val[ID_FIELD_OFFSET..ID_FIELD_OFFSET + 24] | ||
|
|
@@ -46,18 +50,26 @@ pub fn write_boot_catalog( | |
| let checksum = 0u16.wrapping_sub(sum); | ||
| val[BOOT_CATALOG_CHECKSUM_OFFSET..BOOT_CATALOG_CHECKSUM_OFFSET + 2] | ||
| .copy_from_slice(&checksum.to_le_bytes()); | ||
| catalog[0..32].copy_from_slice(&val); | ||
|
|
||
| // Default Boot Entry (32 bytes) | ||
| let mut entry = [0u8; 32]; | ||
| entry[0] = BOOT_CATALOG_BOOT_ENTRY_HEADER_ID; // Bootable | ||
| entry[1] = 0x00; // No Emulation | ||
| entry[2..4].copy_from_slice(&0u16.to_le_bytes()); // Load Segment | ||
| entry[4] = BOOT_CATALOG_EFI_PLATFORM_ID; // System Type | ||
| entry[5] = 0x00; // Unused | ||
| entry[6..8].copy_from_slice(&boot_img_sectors.to_le_bytes()); // Sector count (u16, in 512-byte sectors) | ||
| entry[8..12].copy_from_slice(&boot_img_lba.to_le_bytes()); | ||
| catalog[32..64].copy_from_slice(&entry); | ||
| catalog[offset..offset + 32].copy_from_slice(&val); | ||
| offset += 32; | ||
|
|
||
| // Boot Entries | ||
| for entry_data in entries { | ||
| let mut entry = [0u8; 32]; | ||
| entry[0] = if entry_data.bootable { | ||
| BOOT_CATALOG_BOOT_ENTRY_HEADER_ID | ||
| } else { | ||
| 0x00 | ||
| }; // Bootable or not | ||
| entry[1] = 0x00; // No Emulation | ||
| entry[2..4].copy_from_slice(&0u16.to_le_bytes()); // Load Segment | ||
| entry[4] = entry_data.platform_id; // System Type | ||
| entry[5] = 0x00; // Unused | ||
| entry[6..8].copy_from_slice(&entry_data.boot_image_sectors.to_le_bytes()); // Sector count (u16, in 512-byte sectors) | ||
| entry[8..12].copy_from_slice(&entry_data.boot_image_lba.to_le_bytes()); | ||
| catalog[offset..offset + 32].copy_from_slice(&entry); | ||
| offset += 32; | ||
| } | ||
|
Comment on lines
+57
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic to create boot entries is well-structured. However, if the number of entries becomes large, this loop could potentially write beyond the bounds of the |
||
|
|
||
| iso.write_all(&catalog) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file includes several
println!statements that appear to be for debugging. For better maintainability, it's recommended to use a logging facade likelogortracing. This provides more flexible control over log verbosity and output at runtime compared to hardcoded print statements. These debug prints should be removed before merging.