You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+55-27Lines changed: 55 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,11 +14,19 @@ You need a nightly [Rust](https://www.rust-lang.org) compiler with the `llvm-too
14
14
15
15
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.
16
16
17
+
### Migrating from older bootloader version
18
+
17
19
If you're already using an older version of the `bootloader` crate, follow our [migration guides](docs/migration).
18
20
19
-
### Kernel
21
+
### Starting from scratch
22
+
23
+
Our [basic example](examples/basic/basic-os.md) showcases an OS that boots a minimal kernel using `bootloader`.
24
+
25
+
### Using an existing kernel
20
26
21
-
To make your kernel compatible with `bootloader`:
27
+
To combine your kernel with `bootloader` and create a bootable disk image, follow these steps:
28
+
29
+
#### Make your kernel compatible with `bootloader`
22
30
23
31
- Add a dependency on the `bootloader_api` crate in your kernel's `Cargo.toml`.
24
32
- Your kernel binary should be `#![no_std]` and `#![no_main]`.
@@ -35,37 +43,57 @@ To make your kernel compatible with `bootloader`:
-Setupan [artifactdependency](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#artifact-dependencies) to add your `kernel` crate as a `build-dependency`:
Alternatively, you can use [`std::process::Command`](https://doc.rust-lang.org/stable/std/process/struct.Command.html) to invoke the build command of your kernel in the `build.rs` script.
64
-
- Obtain the path to the kernel executable. When using an artifact dependency, you can retrieve this path using `std::env::var_os("CARGO_BIN_FILE_MY_KERNEL_my-kernel")`
65
-
- Use `bootloader::UefiBoot` and/or `bootloader::BiosBoot` to create a bootable disk image with your kernel.
61
+
```sh
62
+
$cargonewos--bin
63
+
```
64
+
-Addyourkernelasaworkspacemember
65
+
```toml
66
+
# inCargo.toml
67
+
[workspace]
68
+
resolver="3"
69
+
members= ["kernel"]
70
+
```
71
+
-Enabletheworkspacetobuildyourkernel:
72
+
-Setupan [artifactdependency](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#artifact-dependencies) to add your `kernel` crate as a `build-dependency`:
-Alternatively, youcanuse [`std::process::Command`](https://doc.rust-lang.org/stable/std/process/struct.Command.html) to invoke the build command of your kernel in the `build.rs` script.
92
+
-Create a [`build.rs`](https://doc.rust-lang.org/cargo/reference/build-scripts.html) build script in the `os` crate. See our [disk image creation template](docs/create-disk-image.md) for a more detailed example.
93
+
-Obtain the path to the kernel executable.When using an artifact dependency, you can retrieve this path using `std::env::var_os("CARGO_BIN_FILE_MY_KERNEL_my-kernel")`
94
+
-Use `bootloader::UefiBoot` and/or `bootloader::BiosBoot` to create a bootable disk image with your kernel.
66
95
-Do something with the bootable disk images in your `main.rs` function.For example, run them with QEMU.
67
-
68
-
See our [disk image creation template](docs/create-disk-image.md) for a more detailed example.
Copy file name to clipboardExpand all lines: docs/create-disk-image.md
+15-80Lines changed: 15 additions & 80 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,83 +5,18 @@ The [`bootloader`](https://docs.rs/bootloader/0.11) crate provides simple functi
5
5
A good way to implement this is to move your kernel into a `kernel` subdirectory. Then you can create
6
6
a new `os` crate at the top level that defines a [workspace](https://doc.rust-lang.org/cargo/reference/workspaces.html). The root package has build-dependencies on the `kernel`[artifact](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#artifact-dependencies) and on the bootloader crate. This allows you to create the bootable disk image in a [cargo build script](https://doc.rust-lang.org/cargo/reference/build-scripts.html) and launch the created image in QEMU in the `main` function.
7
7
8
-
The files could look like this:
9
-
10
-
```toml
11
-
# .cargo/config.toml
12
-
13
-
[unstable]
14
-
# enable the unstable artifact-dependencies feature, see
Now you should be able to use `cargo build` to create a bootable disk image and `cargo run` to run in QEMU. Your kernel is automatically recompiled when it changes. For more advanced usage, you can add command-line arguments to your `main.rs` to e.g. pass additional arguments to QEMU or to copy the disk images to some path to make it easier to find them (e.g. for copying them to an thumb drive).
8
+
Our [basic example](examples/basic/basic-os.md) showcases this setup:
9
+
-[Cargo.toml](/examples/basic/Cargo.toml)
10
+
- create a workspace & add kernel as member
11
+
- add kernel as build-dependency
12
+
- add ovmf-prebuilt for UEFI booting in QEMU
13
+
-[.cargo/config.toml](/examples/basic/Cargo.toml)
14
+
- enable the unstable artifact-dependencies feature
Now you should be able to use `cargo build` to create a bootable disk image and `cargo run bios` and `cargo run uefi` to run it in QEMU. Your kernel is automatically recompiled when it changes. For more advanced usage, you can add command-line arguments to your `main.rs` to e.g. pass additional arguments to QEMU or to copy the disk images to some path to make it easier to find them (e.g. for copying them to an thumb drive).
0 commit comments