mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Merge pull request #460 from phil-opp/bootimage-0.5.0
Update to bootimage 0.5.0
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -21,6 +21,7 @@ name = "blog_os"
|
|||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"array-init 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"array-init 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"bootloader_precompiled 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -28,6 +29,14 @@ dependencies = [
|
|||||||
"x86_64 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"x86_64 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bootloader_precompiled"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@@ -91,6 +100,7 @@ dependencies = [
|
|||||||
"checksum array-init 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c3cc8456d0ae81a8c76f59e384683a601548c38949a4bfcb65dd31ded5c75ff3"
|
"checksum array-init 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c3cc8456d0ae81a8c76f59e384683a601548c38949a4bfcb65dd31ded5c75ff3"
|
||||||
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"
|
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"
|
||||||
"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
|
"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
|
||||||
|
"checksum bootloader_precompiled 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "245362094f3e7e5c801e71646a672c1fa895c033ca47473278e3d99af6300be6"
|
||||||
"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739"
|
"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739"
|
||||||
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
|
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
|
||||||
"checksum os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "66481dbeb5e773e7bd85b63cd6042c30786f834338288c5ec4f3742673db360a"
|
"checksum os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "66481dbeb5e773e7bd85b63cd6042c30786f834338288c5ec4f3742673db360a"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ name = "blog_os"
|
|||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bootloader_precompiled = "0.2.0"
|
||||||
spin = "0.4.6"
|
spin = "0.4.6"
|
||||||
volatile = "0.2.3"
|
volatile = "0.2.3"
|
||||||
uart_16550 = "0.1.0"
|
uart_16550 = "0.1.0"
|
||||||
|
|||||||
@@ -319,13 +319,42 @@ Now that we have an executable that does something perceptible, it is time to tu
|
|||||||
|
|
||||||
[section about booting]: #the-boot-process
|
[section about booting]: #the-boot-process
|
||||||
|
|
||||||
To make things easy, we created a tool named `bootimage` that automatically downloads a bootloader and combines it with the kernel executable to create a bootable disk image. To install it, execute the following command in your terminal:
|
To add a bootloader to our kernel we add a dependency on the [`bootloader_precompiled`] crate:
|
||||||
|
|
||||||
```
|
[`bootloader_precompiled`]: https://crates.io/crates/bootloader_precompiled
|
||||||
cargo install bootimage --version 0.4.0
|
|
||||||
|
```toml
|
||||||
|
# in Cargo.toml
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bootloader_precompiled = "0.2.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
After installing, creating a bootimage is as easy as executing:
|
```rust
|
||||||
|
// in main.rs
|
||||||
|
|
||||||
|
extern crate bootloader_precompiled;
|
||||||
|
```
|
||||||
|
|
||||||
|
This crate is a precompiled version of the [`bootloader`] crate, an experimental bootloader written in Rust and assembly. We use the precompiled version because the bootloader has some linking issues on platforms other than Linux. We try our best to solve these issues and will update the post as soon as it works on all platforms.
|
||||||
|
|
||||||
|
[`bootloader`]: https://crates.io/crates/bootloader
|
||||||
|
|
||||||
|
Regardless of whether precompiled or not, adding the bootloader as dependency is not enough to actually create a bootable disk image. The problem is that we need to combine the bootloader with the kernel after it has been compiled, but cargo has no support for additional build steps after successful compilation (see [this issue][post-build script] for more information).
|
||||||
|
|
||||||
|
[post-build script]: https://github.com/rust-lang/cargo/issues/545
|
||||||
|
|
||||||
|
To solve this problem, we created a tool named `bootimage` that first compiles the kernel and bootloader, and then combines them to create a bootable disk image. To install the tool, execute the following command in your terminal:
|
||||||
|
|
||||||
|
```
|
||||||
|
cargo install bootimage --version "^0.5.0"
|
||||||
|
```
|
||||||
|
|
||||||
|
The `^0.5.0` is a so-called [_caret requirement_], which means "version `0.5.0` or a later compatible version". So if we find a bug and publish version `0.5.1` or `0.5.2`, cargo would automatically use the latest version, as long as it is still a version `0.5.x`. However, it wouldn't choose version `0.6.0`, because it is not considered as compatible. Note that dependencies in your `Cargo.toml` are caret requirements by default, so the same rules are applied to our bootloader dependency.
|
||||||
|
|
||||||
|
[_caret requirement_]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#caret-requirements
|
||||||
|
|
||||||
|
After installing the `bootimage` tool, creating a bootable disk image is as easy as executing:
|
||||||
|
|
||||||
```
|
```
|
||||||
> bootimage build --target x86_64-blog_os.json
|
> bootimage build --target x86_64-blog_os.json
|
||||||
@@ -339,8 +368,8 @@ After executing the command, you should see a file named `bootimage.bin` in your
|
|||||||
The `bootimage` tool performs the following steps behind the scenes:
|
The `bootimage` tool performs the following steps behind the scenes:
|
||||||
|
|
||||||
- It compiles our kernel to an [ELF] file.
|
- It compiles our kernel to an [ELF] file.
|
||||||
- It downloads a pre-compiled bootloader release from [rust-osdev/bootloader]. The file is already a bootable image that only requires that a kernel is appended.
|
- It compiles the bootloader dependency as a standalone executable.
|
||||||
- It appends the bytes of the kernel ELF file to the bootloader (without any modifications).
|
- It appends the bytes of the kernel ELF file to the bootloader.
|
||||||
|
|
||||||
[ELF]: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
|
[ELF]: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
|
||||||
[rust-osdev/bootloader]: https://github.com/rust-osdev/bootloader
|
[rust-osdev/bootloader]: https://github.com/rust-osdev/bootloader
|
||||||
|
|||||||
@@ -374,6 +374,7 @@ Cargo supports hybrid projects that are both a library and a binary. We only nee
|
|||||||
|
|
||||||
#![no_std] // don't link the Rust standard library
|
#![no_std] // don't link the Rust standard library
|
||||||
|
|
||||||
|
extern crate bootloader_precompiled;
|
||||||
extern crate spin;
|
extern crate spin;
|
||||||
extern crate volatile;
|
extern crate volatile;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@@ -585,17 +586,14 @@ The `test-basic-boot` and `test-panic` tests we created above begin with `test-`
|
|||||||
> bootimage test
|
> bootimage test
|
||||||
test-panic
|
test-panic
|
||||||
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
|
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
|
||||||
Updating registry `https://github.com/rust-lang/crates.io-index`
|
|
||||||
Ok
|
Ok
|
||||||
|
|
||||||
test-basic-boot
|
test-basic-boot
|
||||||
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
|
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
|
||||||
Updating registry `https://github.com/rust-lang/crates.io-index`
|
|
||||||
Ok
|
Ok
|
||||||
|
|
||||||
test-something
|
test-something
|
||||||
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
|
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
|
||||||
Updating registry `https://github.com/rust-lang/crates.io-index`
|
|
||||||
Timed Out
|
Timed Out
|
||||||
|
|
||||||
The following tests failed:
|
The following tests failed:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#![no_std] // don't link the Rust standard library
|
#![no_std] // don't link the Rust standard library
|
||||||
|
|
||||||
|
extern crate bootloader_precompiled;
|
||||||
extern crate spin;
|
extern crate spin;
|
||||||
extern crate volatile;
|
extern crate volatile;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
Reference in New Issue
Block a user