mirror of
https://github.com/edera-dev/sprout.git
synced 2025-12-19 08:30:16 +00:00
fix chainloading to linux properly
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
version = 1
|
||||
|
||||
[values]
|
||||
default-options = "initrd=\\initramfs init=/bin/sh console=hvc0"
|
||||
default-options = "initrd=\\initramfs console=hvc0"
|
||||
|
||||
[actions.welcome]
|
||||
print.text = "Welcome to Sprout!"
|
||||
|
||||
@@ -47,33 +47,33 @@ pub fn chainload(context: Rc<SproutContext>, configuration: &ChainloadConfigurat
|
||||
.map(|item| context.stamp(item))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ");
|
||||
|
||||
let mut options_holder: Option<Box<CString16>> = None;
|
||||
if !options.is_empty() {
|
||||
let options = Box::new(
|
||||
CString16::try_from(&options[..])
|
||||
.context("unable to convert chainloader options to CString16")?,
|
||||
);
|
||||
info!("options: {}", options);
|
||||
|
||||
// TODO(azenla): Free this memory, if possible.
|
||||
// The lifetime of the pointer needs ot outlive start_image.
|
||||
// Maybe consider moving this up.
|
||||
let options = Box::leak(options);
|
||||
info!("options: {}", options);
|
||||
|
||||
if options.num_bytes() > u32::MAX as usize {
|
||||
bail!("chainloader options too large");
|
||||
}
|
||||
|
||||
// SAFETY: options size is checked to validate it is safe to pass.
|
||||
// Additionally, the pointer is allocated and retained on the heap which makes
|
||||
// passing the options pointer safe to the next image.
|
||||
// SAFETY: option size is checked to validate it is safe to pass.
|
||||
// Additionally, the pointer is allocated and retained on heap, which makes
|
||||
// passing the `options` pointer safe to the next image.
|
||||
unsafe {
|
||||
loaded_image_protocol
|
||||
.set_load_options(options.as_ptr() as *const u8, options.num_bytes() as u32);
|
||||
}
|
||||
options_holder = Some(options);
|
||||
}
|
||||
|
||||
let (base, size) = loaded_image_protocol.info();
|
||||
info!("loaded image: base={:#x} size={:#x}", base.addr(), size);
|
||||
uefi::boot::start_image(image).context("failed to start image")?;
|
||||
drop(options_holder);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ FROM alpine:3.22@sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8c4
|
||||
RUN apk --no-cache add busybox-static
|
||||
RUN mkdir -p /tmp/initramfs/bin && cp /bin/busybox.static /tmp/initramfs/bin/busybox && \
|
||||
chroot /tmp/initramfs /bin/busybox --install -s /bin && \
|
||||
chroot /tmp/initramfs ln -s /bin/sh /init && \
|
||||
chroot /tmp/initramfs ln -s /bin/init /init && \
|
||||
cd /tmp/initramfs && \
|
||||
find . | cpio -R 0:0 --ignore-devno --renumber-inodes -o -H newc --quiet > /initramfs && \
|
||||
rm -rf /tmp/initramfs
|
||||
|
||||
Reference in New Issue
Block a user