Crates.io | bootloader |
lib.rs | bootloader |
version | |
source | src |
created_at | 2018-01-28 15:39:52.582736 |
updated_at | 2024-11-02 07:03:17.211073 |
description | An experimental x86_64 bootloader that works on both BIOS and UEFI systems. |
homepage | |
repository | https://github.com/rust-osdev/bootloader |
max_upload_size | |
id | 48654 |
Cargo.toml error: | TOML parse error at line 20, column 1 | 20 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
An experimental x86_64 bootloader that works on both BIOS and UEFI systems. Written in Rust and some inline assembly, buildable on all platforms without additional build-time dependencies (just some rustup
components).
You need a nightly Rust compiler with the llvm-tools-preview
component, which can be installed through rustup component add llvm-tools-preview
.
To use this crate, you need to adjust your kernel to be bootable first. Then you can create a bootable disk image from your compiled kernel. These steps are explained in detail below.
If you're already using an older version of the bootloader
crate, follow our migration guides.
To make your kernel compatible with bootloader
:
bootloader_api
crate in your kernel's Cargo.toml
.#![no_std]
and #![no_main]
.fn kernel_main(boot_info: &'static mut bootloader_api::BootInfo) -> !
. The function name can be arbitrary.
boot_info
argument provides information about available memory, the framebuffer, and more. See the API docs for bootloader_api
crate for details.entry_point
macro to register the entry point function: bootloader_api::entry_point!(kernel_main);
_start
entry point symbol for it. (If you use a linker script, make sure that you don't change the entry point name to something else.)&'static bootloader_api::BootloaderConfig
to the entry_point
macro. For example, you can require a specific stack size for your kernel:
const CONFIG: bootloader_api::BootloaderConfig = {
let mut config = bootloader_api::BootloaderConfig::new_default();
config.kernel_stack_size = 100 * 1024; // 100 KiB
config
};
bootloader_api::entry_point!(kernel_main, config = &CONFIG);
cargo build --target x86_64-unknown-none
. You might need to run rustup target add x86_64-unknown-none
before to download precompiled versions of the core
and alloc
crates.entry_point
macro, the compiled executable contains a special section with metadata and the serialized config, which will enable the bootloader
crate to load it.To combine your kernel with a bootloader and create a bootable disk image, follow these steps:
kernel
subdirectory.os
crate at the top level that defines a workspace.build-dependencies
on the bootloader
crate.build.rs
build script.kernel
crate as a build-dependency
:
# in Cargo.toml
[build-dependencies]
kernel = { path = "kernel", artifact = "bin", target = "x86_64-unknown-none" }
# .cargo/config.toml
[unstable]
# enable the unstable artifact-dependencies feature, see
# https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#artifact-dependencies
bindeps = true
Alternatively, you can use std::process::Command
to invoke the build command of your kernel in the build.rs
script.std::env::var_os("CARGO_BIN_FILE_MY_KERNEL_my-kernel")
bootloader::UefiBoot
and/or bootloader::BiosBoot
to create a bootable disk image with your kernel.main.rs
function. For example, run them with QEMU.See our disk image creation template for a more detailed example.
This project is split into three separate entities:
bootloader_api
library with the entry point, configuration, and boot info definitions.
entry_point
macro will encode the configuration settings into a separate ELF section of the compiled kernel executable.entry_point
macro of the bootloader_api
library.bootloader
library to create bootable disk images that run a given kernel. This library is the top-level crate in this project.
build.rs
.Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.