|
1 |
| -# rustboot |
| 1 | +# bootloader |
2 | 2 |
|
3 |
| -[](https://gitter.im/rust-osdev/bootloader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
| 3 | +[](https://travis-ci.org/rust-osdev/bootloader) [](https://gitter.im/rust-osdev/bootloader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
4 | 4 |
|
5 |
| -An experimental pure-Rust x86 bootloader for the [planned second edition](https://github.com/phil-opp/blog_os/issues/360) of the [Writing an OS in Rust](https://os.phil-opp.com) series. |
| 5 | +An experimental x86 bootloader written in Rust and inline assembly. |
6 | 6 |
|
7 |
| -**This is still work in progress**. |
| 7 | +Written for the [second edition](https://github.com/phil-opp/blog_os/issues/360) of the [Writing an OS in Rust](https://os.phil-opp.com) series. |
8 | 8 |
|
9 |
| -The idea is to build the kernel as a `no_std` longmode executable and then build the bootloader with the kernel [ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) file in `kernel.bin`. The output is a flat binary disk image (including a basic [MBR](https://en.wikipedia.org/wiki/Master_boot_record)) that can be run in [QEMU](https://www.qemu.org/) or burned to an USB flash drive (CDs require a different kind of bootloader, which is not supported at the moment). The plan is to create a custom tool (or cargo subcommand) that performs these steps automatically. |
| 9 | +## Design |
| 10 | + |
| 11 | +TODO |
10 | 12 |
|
11 | 13 | ## Build and Run
|
12 |
| -You need a nightly [Rust](https://www.rust-lang.org) compiler, [xargo](https://github.com/japaric/xargo), [objcopy](https://sourceware.org/binutils/docs/binutils/objcopy.html) (or a similar tool), and [QEMU](https://www.qemu.org/) (for running it). |
| 14 | +You need a nightly [Rust](https://www.rust-lang.org) compiler and [cargo xbuild](https://github.com/rust-osdev/cargo-xbuild). |
| 15 | + |
| 16 | +Then you can run the `builder` executable with your kernel as argument: |
| 17 | + |
| 18 | +``` |
| 19 | +cd builder |
| 20 | +cargo run -- --kernel path/to/your/kernel/elf/file |
| 21 | +``` |
13 | 22 |
|
14 |
| -### Mac OS |
| 23 | +This will output a file named `bootimage.bin` in the `../target/x86_64-bootloader/release` folder. |
15 | 24 |
|
16 |
| -If you are building on Mac OS and get a error saying `ld.bfd not found` you first need to [cross compile binutils](https://os.phil-opp.com/cross-compile-binutils) and then adjust |
17 |
| -the linker name in the `x86_64-bootloader.json` file. The reason for this is the default rust LLVM linker doesn't support some features this project needs. |
| 25 | +You can run this file using [QEMU](https://www.qemu.org/): |
18 | 26 |
|
19 |
| -After doing that continue with the instructions for Linux. |
| 27 | +``` |
| 28 | +qemu-system-x86_64 -drive format=raw,file=target/x86_64-bootloader/release/bootimage.bin |
| 29 | +``` |
20 | 30 |
|
21 |
| -### Linux |
| 31 | +Or burn it to an USB drive: |
22 | 32 |
|
23 | 33 | ```
|
24 |
| -> RUST_TARGET_PATH=$(pwd) xargo build --target x86_64-bootloader --release |
25 |
| -> objcopy -O binary -S target/x86_64-bootloader/release/bootloader bootimage.bin |
26 |
| -> qemu-system-x86_64 -hda bootimage.bin -d int -s |
| 34 | +dd if=target/x86_64-blog_os/debug/bootimage-blog_os.bin of=/dev/sdX && sync |
27 | 35 | ```
|
| 36 | + |
| 37 | +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