Skip to content

Commit 536e0f6

Browse files
committed
Add docs for crate and Config struct
1 parent fb4813d commit 536e0f6

File tree

3 files changed

+79
-8
lines changed

3 files changed

+79
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "bootloader"
33
version = "0.10.0-alpha-03"
44
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
55
license = "MIT/Apache-2.0"
6-
description = "An experimental pure-Rust x86 bootloader."
6+
description = "An experimental x86_64 bootloader that works on both BIOS and UEFI systems."
77
repository = "https://github.com/rust-osdev/bootloader"
88
edition = "2018"
99
build = "build.rs"

src/config.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
11
/// Allows configuring the bootloader behavior.
22
///
33
/// To control these, use a `[package.metadata.bootloader]` table in the `Cargo.toml` of
4-
/// your kernel.
4+
/// your kernel. The naming convention for all config fields is `kebab-case`, otherwise the
5+
/// config keys correspond to the field names of this struct (i.e. just replace `_` with `-`).
6+
/// Unknown config keys lead to an error.
7+
///
8+
/// ## Example
9+
///
10+
/// To map the complete physical memory starting at virtual address `0x0000_4000_0000_0000`, add
11+
/// the following to your kernel's `Cargo.toml`:
12+
///
13+
/// ```toml
14+
/// [package.metadata.bootloader]
15+
/// map-physical-memory = true
16+
/// physical-memory-offset = 0x0000_4000_0000_0000
17+
/// ```
18+
///
19+
/// ## Memory Addresses
20+
///
21+
/// Memory addresses must be positive and page aligned. Since TOML does not support unsigned 64-bit
22+
/// integers, we also support string input to specify addresses larger than `i64::MAX`. For example:
23+
///
24+
/// ```toml
25+
/// physical-memory-offset = "0xf000_0000_0000_0000"
26+
/// ```
27+
///
28+
/// The above example would fail if the address was specified as integer instead (i.e. without
29+
/// the quotes).
30+
///
31+
/// All memory addresses are optional, even if their corresponding switch is enabled. If no
32+
/// address is specified, the bootloader will choose an unused entry of the level 4 page table
33+
/// at runtime.
534
#[derive(Debug)]
635
pub struct Config {
736
/// Whether to create a virtual mapping of the complete physical memory.

src/lib.rs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,51 @@
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+
*/
749

850
#![cfg_attr(not(feature = "builder"), no_std)]
951
#![feature(asm)]

0 commit comments

Comments
 (0)