Skip to content

Commit 12082b2

Browse files
authored
Merge pull request rust-osdev#34 from rust-osdev/builder
Create new `builder` sub-crate
2 parents 4c393ac + 30758ea commit 12082b2

File tree

11 files changed

+469
-19
lines changed

11 files changed

+469
-19
lines changed

.travis.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,32 @@ language: rust
33
rust:
44
- nightly
55

6-
os: linux
6+
os:
7+
- linux
8+
- osx
9+
- windows
710

811
cache:
912
directories:
1013
- $HOME/.cargo
11-
- $HOME/.xargo
14+
- $HOME/Library/Caches/Homebrew
1215
- $TRAVIS_BUILD_DIR/target
16+
- $TRAVIS_BUILD_DIR/example-kernel/target
17+
18+
addons:
19+
apt:
20+
packages:
21+
- qemu-system-x86
22+
homebrew:
23+
packages:
24+
- qemu
25+
26+
install:
27+
- if [ $TRAVIS_OS_NAME = windows ]; then choco install qemu; export PATH="/c/Program Files/qemu:$PATH"; fi
1328

1429
before_script:
1530
- rustup component add rust-src
16-
- "(test -x $HOME/.cargo/bin/xargo || cargo install xargo)"
31+
- "(test -x $HOME/.cargo/bin/cargo-xbuild || cargo install cargo-xbuild)"
1732

1833
sudo: false
1934

@@ -23,5 +38,6 @@ notifications:
2338
on_failure: change
2439

2540
script:
26-
- RUST_TARGET_PATH=`pwd` xargo build --target x86_64-bootloader --release
27-
- objcopy -O binary -S target/x86_64-bootloader/release/bootloader bootimage.bin
41+
- cd example-kernel; cargo xbuild --target x86_64-example-kernel.json; cd ..
42+
- cd builder; cargo run -- --kernel ../example-kernel/target/x86_64-example-kernel/debug/example-kernel; cd ..
43+
- qemu-system-x86_64 -drive format=raw,file=target/x86_64-bootloader/release/bootimage.bin -device isa-debug-exit,iobase=0xf4,iosize=0x04 -display none; if [ $? -eq 123 ]; then (exit 0); else (exit 1); fi

README.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1-
# rustboot
1+
# bootloader
22

3-
[![Join the chat at https://gitter.im/rust-osdev/bootloader](https://badges.gitter.im/rust-osdev/bootloader.svg)](https://gitter.im/rust-osdev/bootloader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
3+
[![Build Status](https://travis-ci.org/rust-osdev/bootloader.svg?branch=master)](https://travis-ci.org/rust-osdev/bootloader) [![Join the chat at https://gitter.im/rust-osdev/bootloader](https://badges.gitter.im/rust-osdev/bootloader.svg)](https://gitter.im/rust-osdev/bootloader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
44

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.
66

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.
88

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
1012

1113
## 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+
```
1322

14-
### Mac OS
23+
This will output a file named `bootimage.bin` in the `../target/x86_64-bootloader/release` folder.
1524

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/):
1826

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+
```
2030

21-
### Linux
31+
Or burn it to an USB drive:
2232

2333
```
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
2735
```
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.

builder/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target/
2+
**/*.rs.bk

builder/Cargo.lock

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "builder"
3+
version = "0.1.0"
4+
authors = ["Philipp Oppermann <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
xmas-elf = "0.6.2"
9+
byteorder = "1.2.7"
10+
args = "2.2.0"
11+
getopts = "0.2.18"

0 commit comments

Comments
 (0)