Skip to content

Commit f427ce5

Browse files
committed
Update build instructions in the Readme
1 parent e2a00a4 commit f427ce5

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

README.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,50 @@ Written for the [second edition](https://github.com/phil-opp/blog_os/issues/360)
1010

1111
TODO
1212

13-
## Build and Run
14-
You need a nightly [Rust](https://www.rust-lang.org) compiler and [cargo xbuild](https://github.com/rust-osdev/cargo-xbuild).
13+
## Requirements
1514

16-
Then you can run the `builder` executable with your kernel as argument:
15+
You need a nightly [Rust](https://www.rust-lang.org) compiler and [cargo xbuild](https://github.com/rust-osdev/cargo-xbuild). You also need the `llvm-tools-preview` component, which can be installed through `rustup component add llvm-tools-preview`.
16+
17+
## Build
18+
19+
The simplest way to use the bootloader is in combination with the [bootimage](https://github.com/rust-osdev/bootimage) tool. With the tool installed, you can add a normal cargo dependency on the `bootloader` crate to your kernel and then run `bootimage build` to create a bootable disk image. You can also execute `bootimage run` to run your kernel in [QEMU](https://www.qemu.org/) (needs to be installed).
20+
21+
To compile the bootloader manually, you need to invoke `cargo xbuild` with a `KERNEL` environment variable that points to your kernel executable (in the ELF format):
22+
23+
```
24+
KERNEL=/path/to/your/kernel/target/debug/your_kernel cargo xbuild
25+
```
26+
27+
As an example, you can build the bootloader with example kernel from the `example-kernel` directory with the following commands:
1728

1829
```
19-
cd builder
20-
cargo run -- --kernel path/to/your/kernel/elf/file
30+
cd example-kernel
31+
cargo xbuild
32+
cd ..
33+
KERNEL=example-kernel/target/x86_64-example-kernel/debug/example-kernel cargo xbuild --release
2134
```
2235

23-
This will output a file named `bootimage.bin` in the `../target/x86_64-bootloader/release` folder.
36+
This results in a bootloader executable at `target/x86_64-bootloader.json/release/bootloader`. This executable is still an ELF file, which can't be run directly.
37+
38+
## Run
39+
40+
To run the compiled bootloader executable, you need to convert it to a binary file. You can use the `llvm-objcopy` tools that ships with the `llvm-tools-preview` rustup component. The easiest way to use this tool is using [`cargo-binutils`](https://github.com/rust-embedded/cargo-binutils), which can be installed through `cargo install cargo-binutils`. Then you can perform the conversion with the following command:
41+
42+
```
43+
cargo objcopy -- -I elf64-x86-64 -O binary --binary-architecture=i386:x86-64 \
44+
target/x86_64-bootloader/release/bootloader target/x86_64-bootloader/release/bootloader.bin
45+
```
2446

25-
You can run this file using [QEMU](https://www.qemu.org/):
47+
You can run the `bootloader.bin` file using [QEMU](https://www.qemu.org/):
2648

2749
```
28-
qemu-system-x86_64 -drive format=raw,file=target/x86_64-bootloader/release/bootimage.bin
50+
qemu-system-x86_64 -drive format=raw,file=target/x86_64-bootloader/release/bootloader.bin
2951
```
3052

31-
Or burn it to an USB drive:
53+
Or burn it to an USB drive to boot it on real hardware:
3254

3355
```
34-
dd if=target/x86_64-blog_os/debug/bootimage-blog_os.bin of=/dev/sdX && sync
56+
dd if=target/x86_64-bootloader/release/bootloader.bin of=/dev/sdX && sync
3557
```
3658

3759
Where sdX is the device name of your USB stick. **Be careful** to choose the correct device name, because everything on that device is overwritten.

0 commit comments

Comments
 (0)