|
1 |
| -//! This library part of the bootloader allows kernels to retrieve information from the bootloader. |
2 |
| -//! |
3 |
| -//! To combine your kernel with the bootloader crate you need a tool such |
4 |
| -//! as [`bootimage`](https://github.com/rust-osdev/bootimage). See the |
5 |
| -//! [_Writing an OS in Rust_](https://os.phil-opp.com/minimal-rust-kernel/#creating-a-bootimage) |
6 |
| -//! blog for an explanation. |
| 1 | +/*! |
| 2 | +An experimental x86_64 bootloader that works on both BIOS and UEFI systems. |
| 3 | +
|
| 4 | +To use this crate, specify it as a dependency in the `Cargo.toml` of your operating system |
| 5 | +kernel. Then you can use the [`entry_point`] macro to mark your entry point function. This |
| 6 | +gives you access to the [`BootInfo`] struct, which is passed by the bootloader. |
| 7 | +
|
| 8 | +## Disk Image Creation |
| 9 | +
|
| 10 | +Including the `bootloader` crate as a dependency makes the kernel binary suitable for booting, |
| 11 | +but does not create any bootable disk images. To create them, two additional steps are needed: |
| 12 | +
|
| 13 | +1. **Locate the source code of the `bootloader` dependency** on your local system. By using the |
| 14 | + dependency source code directly, we ensure that the kernel and bootloader use the same version |
| 15 | + of the [`BootInfo`] struct. |
| 16 | + - When creating a builder binary written in Rust, the |
| 17 | + [`bootloader_locator`](https://docs.rs/bootloader-locator/0.0.4/bootloader_locator/) crate can |
| 18 | + be used to automate this step. |
| 19 | + - Otherwise, the |
| 20 | + [`cargo metadata`](https://doc.rust-lang.org/cargo/commands/cargo-metadata.html) subcommand |
| 21 | + can be used to locate the dependency. The command outputs a JSON object with various metadata |
| 22 | + for the current package. To find the `bootloader` source path in it, first look for the |
| 23 | + "bootloader" dependency under `resolve.nodes.deps` to find out its ID (in the `pkg` field). |
| 24 | + Then use that ID to find the bootloader in `packages`. Its `manifest_path` field contains the |
| 25 | + local path to the `Cargo.toml` of the bootloader. |
| 26 | +2. **Run the following command** in the source code directory of the `bootloader` dependency to create |
| 27 | + the bootable disk images: |
| 28 | +
|
| 29 | + ```notrust |
| 30 | + cargo builder --kernel-manifest path/to/kernel/Cargo.toml --kernel-binary path/to/kernel_bin |
| 31 | + ``` |
| 32 | +
|
| 33 | + The `--kernel-manifest` argument should point to the `Cargo.toml` of your kernel. It is used |
| 34 | + for applying configuration settings. The `--kernel-binary` argument should point to the kernel |
| 35 | + executable that should be used for the bootable disk images. |
| 36 | +
|
| 37 | + In addition to the `--kernel-manifest` and `--kernel-binary` arguments, it is recommended to also |
| 38 | + set the `--target-dir` and `--out-dir` arguments. The former specifies the directory that should |
| 39 | + used for cargo build artifacts and the latter specfies the directory where the resulting disk |
| 40 | + images should be placed. It is recommended to set `--target-dir` to the `target` folder of your |
| 41 | + kernel and `--out-dir` to the the parent folder of `--kernel-binary`. |
| 42 | +
|
| 43 | +## Configuration |
| 44 | +
|
| 45 | +The bootloader can be configured through a `[package.metadata.bootloader]` table in the |
| 46 | +`Cargo.toml` of the kernel (the one passed as `--kernel-manifest`). See the [`Config`] struct |
| 47 | +for all possible configuration options. |
| 48 | +*/ |
7 | 49 |
|
8 | 50 | #![cfg_attr(not(feature = "builder"), no_std)]
|
9 | 51 | #![feature(asm)]
|
|
0 commit comments