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