Skip to content

Commit 8cbf6b3

Browse files
Apply review comments
Co-authored-by: Philipp Oppermann <[email protected]>
1 parent 68ce2ee commit 8cbf6b3

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

common/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,16 @@ where
275275
let ramdisk_address_start = mapping_addr(
276276
config.mappings.ramdisk_memory,
277277
system_info.ramdisk_len,
278-
8,
278+
Size4KiB::SIZE,
279279
&mut used_entries,
280280
);
281281
let physical_address = PhysAddr::new(ramdisk_address);
282282
let ramdisk_physical_start_page: PhysFrame<Size4KiB> =
283283
PhysFrame::containing_address(physical_address);
284-
let ramdisk_page_count = (system_info.ramdisk_len - 1 / Size4KiB::SIZE) + 1;
284+
let ramdisk_page_count = ((system_info.ramdisk_len - 1) / Size4KiB::SIZE) + 1;
285285
let ramdisk_physical_end_page = ramdisk_physical_start_page + ramdisk_page_count;
286-
let start_page = Page::containing_address(ramdisk_address_start);
286+
let start_page = Page::from_start_address(ramdisk_address_start)
287+
.expect("the ramdisk start address must be page aligned");
287288

288289
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
289290
for (i, frame) in

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ impl UefiBoot {
131131
/// bootloader won't be found.
132132
pub fn create_pxe_tftp_folder(&self, out_path: &Path) -> anyhow::Result<()> {
133133
let bootloader_path = Path::new(env!("UEFI_BOOTLOADER_PATH"));
134-
let ramdisk_path = match self.ramdisk.as_ref() {
135-
Some(rd) => Some(rd.as_path()),
136-
None => None,
137-
};
134+
let ramdisk_path = self.ramdisk.as_deref();
138135
pxe::create_uefi_tftp_folder(
139136
bootloader_path,
140137
self.kernel.as_path(),

uefi/src/main.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,28 @@ fn main_inner(image: Handle, mut st: SystemTable<Boot>) -> Status {
119119
let mmap_storage = {
120120
let mut memory_map_size = st.boot_services().memory_map_size();
121121
let mut target_size = memory_map_size.map_size + (8 * memory_map_size.entry_size);
122-
let mut storage: &mut [u8];
123122
loop {
124123
let ptr = st
125124
.boot_services()
126125
.allocate_pool(MemoryType::LOADER_DATA, target_size)
127126
.expect("Failed to allocate memory for mmap storage");
128-
storage = unsafe { slice::from_raw_parts_mut(ptr, target_size) };
129-
if let Err(_) = st.boot_services().memory_map(storage) {
130-
memory_map_size = st.boot_services().memory_map_size();
131-
// By measuring the size here, we can find out exactly how much we need.
132-
// We may hit this code twice, if the map allocation ends up spanning more pages.
133-
let next_target_size = memory_map_size.map_size + (8 * memory_map_size.entry_size);
134-
target_size = next_target_size;
135-
st.boot_services()
136-
.free_pool(ptr)
137-
.expect("Failed to free temporary memory for memory map!");
138-
continue;
127+
let storage = unsafe { slice::from_raw_parts_mut(ptr, target_size) };
128+
if st.boot_services().memory_map(storage).is_ok() {
129+
break storage;
139130
}
140-
break;
131+
// allocated memory region was not big enough -> free it again
132+
st.boot_services()
133+
.free_pool(ptr)
134+
.expect("Failed to free temporary memory for memory map!");
135+
136+
// By measuring the size here, we can find out exactly how much we need.
137+
// We may hit this code twice, if the map allocation ends up spanning more pages.
138+
memory_map_size = st.boot_services().memory_map_size();
139+
140+
let next_target_size = memory_map_size.map_size + (8 * memory_map_size.entry_size);
141+
target_size = next_target_size;
142+
141143
}
142-
storage
143144
};
144145

145146
log::trace!("exiting boot services");
@@ -309,11 +310,10 @@ fn load_file_from_disk(
309310

310311
let file_handle_result = root.open(filename, FileMode::Read, FileAttribute::empty());
311312

312-
if file_handle_result.is_err() {
313-
return None;
314-
}
315-
316-
let file_handle = file_handle_result.unwrap();
313+
let file_handle = match file_handle_result {
314+
Err(_) => return None,
315+
Ok(handle) => handle,
316+
};
317317

318318
let mut file = match file_handle.into_type().unwrap() {
319319
uefi::proto::media::file::FileType::Regular(f) => f,
@@ -353,7 +353,6 @@ fn load_file_from_tftp_boot_server(
353353
assert!(mode.dhcp_ack_received);
354354
let dhcpv4: &DhcpV4Packet = mode.dhcp_ack.as_ref();
355355
let server_ip = IpAddress::new_v4(dhcpv4.bootp_si_addr);
356-
let mut buf = [0u8; 256];
357356
assert!(name.len() < 256);
358357

359358
let filename = CStr8::from_bytes_with_nul(name.as_bytes()).unwrap();

0 commit comments

Comments
 (0)