vboot: Fix vb2ex_printf host output vb2ex_printf is a variadic function used by the vboot_reference C code to log. We provide an implementation on the Rust side using the unstable `c_variadic` feature. This worked correctly when run in the uefi environment, but would print incorrect values when run on the host target (i.e. when running the vboot unit tests). I'm not clear on exactly why the previous code didn't work; something about how the variadic args got passed to `printf_wrapper` was incorrect. This might be a Rust bug, or a bug in my code. At any rate, using a single function does work correctly. Unfortunately the printf test had to be removed since there's no easy way to programatically read the output now, but manual testing shows it is functioning correctly. BUG=None TEST=cargo xtask check TEST=Temporarily add `panic!()` at the bottom of `test_load_kernel` to make it fail. TEST=Run `cargo xtask check` again, observe logs contain sensible numbers. Change-Id: I8220ffbc0c15fce929f8784f5d633282c8f75761 Reviewed-on: https://chromium-review.googlesource.com/c/crdyboot/+/3629371 Tested-by: Nicholas Bishop <[email protected]> Commit-Queue: Jeffery Miller <[email protected]> Tested-by: Jeffery Miller <[email protected]> Auto-Submit: Nicholas Bishop <[email protected]> Reviewed-by: Jeffery Miller <[email protected]>
Pronounced CUR-dee-boot.
This is a UEFI bootloader for CloudReady. Crdyboot handles loading, verifying, and running the Linux kernel.
Goals:
The vboot subdirectory is a no_std library that handles loading and verifying the kernel. Internally it uses the LoadKernel function from third_party/vboot_reference. This crate can be built for the host target so that tests can run.
The crdyboot subdirectory contains the actual bootloader. It can only be built for the x86_64-unknown-uefi and i686-unknown-uefi targets.
The xtask subdirectory contains a single binary that is used by the various xtask commands shown below.
The enroller subdirectory contains a small UEFI application that enrolls a test key in the PK, KEK, and db variables. This only works if the machine is in secure boot custom mode.
Install nightly Rust:
cargo xtask install-toolchain
Provides headers needed for compiling C code compatible with the Rust UEFI targets.
sudo apt install mingw-w64-i686-dev mingw-w64-x86-64-dev
Other tools used for image signing and running in a VM:
sudo apt install efitools gdisk ovmf ovmf-ia32 qemu-system-x86 sbsigntool
After installing qemu, add your user to the kvm group. You will need to log out and back in for this to take effect:
sudo adduser ${USER} kvm
To check formatting, lint, test, and build both vboot and crdyboot:
cargo xtask check
To build crdyboot for both 64-bit and 32-bit UEFI targets:
cargo xtask build
One-time step to enroll custom secure-boot keys:
cargo xtask secure-boot-setup
One-time step to copy in an existing cloudready image:
cp /path/to/cloudready.bin workspace/disk.bin
One-time step to prepare the image:
cargo xtask prep-disk
To copy the latest crdyboot build to the image:
cargo xtask update-disk
Then run it in QEMU:
cargo xtask qemu [--ia32] [--secure-boot]
Some additional build options can be set in crdyboot.toml (in the root of the repo). This file will be created automatically if it doesn't already exist by copying xtask/default.toml. The defaults are appropriate for development. In a release build, verbose logging and the test key should be turned off.
To test secure boot with real hardware you will need to enroll custom keys. First build the enroller image (workspace/enroller.bin):
cargo xtask build-enroller
Write workspace/enroller.bin to a USB, and write workspace/disk.bin to a second USB, e.g. using writedisk.
Boot the DUT and enter the boot setup. Find the secure boot settings and change it to setup mode. (The details will vary from one vendor to another.)
Plug in the enroller USB and reboot. Use the boot menu to select the USB and wait for it to complete.
Unplug the enroller USB and plug in the cloudready USB, then reboot. Use the boot menu to select the USB.
An older pure-Rust version can be found in the pure-rust-20210729 branch. Since then we have switched to building the C vboot library and loading/verifying the kernel through that library.