Skip to content

Commit 317609c

Browse files
committed
init
0 parents  commit 317609c

20 files changed

+149
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
esp/NvVars
3+
esp/zircon.bin
4+
bootfs

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Runji Wang
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
OVMF := prebuilt/OVMF.fd
2+
ZBI := tools/${shell uname}/zbi
3+
ESP := esp
4+
QEMU_ARGS := -m 1G -net none -smp cores=4 -nographic
5+
PROJ ?= hello
6+
7+
.PHONY: build zbi run
8+
9+
# build rust program
10+
build:
11+
cd ${PROJ} && cargo build --target x86_64-fuchsia
12+
mkdir -p bootfs/bin
13+
mv ${PROJ}/target/x86_64-fuchsia/debug/${PROJ} bootfs/bin
14+
15+
# zip BootFS and generate zircon.bin
16+
zbi:
17+
${ZBI} --compressed=lz4f prebuilt/legacy-image-x64.zbi --replace bootfs -o esp/zircon.bin
18+
19+
# run Zircon on QEMU
20+
run: zbi
21+
qemu-system-x86_64 \
22+
-bios ${OVMF} \
23+
-drive format=raw,file=fat:rw:${ESP} \
24+
-serial mon:stdio \
25+
$(QEMU_ARGS)

README.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Fuchsia Rust SDK
2+
3+
A minimal out-of-the-box Fuchsia SDK for Rust (without complex GN!).
4+
5+
Build and test your Rust programs on Fuchsia OS (Zircon Kernel) right now!!
6+
7+
## Quick start
8+
9+
Dependencies:
10+
11+
* Linux or macOS
12+
* QEMU
13+
* Rust toolchain
14+
15+
Before you start:
16+
17+
```sh
18+
rustup target add x86_64-fuchsia
19+
```
20+
21+
Build and run:
22+
23+
```sh
24+
make build # build Rust project
25+
make run # run Zircon on QEMU
26+
```
27+
28+
Test your programs:
29+
30+
```sh
31+
...
32+
[00005.462] 01919:01974> vc: Successfully attached to display 1
33+
[00005.474] 01919:01974> vc: new input device /dev/class/input/002
34+
# you need to press Enter here
35+
$ hello
36+
Hello, Zircon!!!
37+
$
38+
```
39+
40+
## What's inside the box
41+
42+
We use prebuilt objects from [Fuchsia-VM-20190715](https://fuchsia-china.com/fuchsia-virtual-machine-download/).
43+
44+
### UEFI Bootloader
45+
46+
| Description | Path | Source Path |
47+
| ---------------------- | ---------------------------------------------------- | -------------------------------------------- |
48+
| UEFI firmware for QEMU | [prebuilt/OVMF.fd](prebuilt/OVMF.fd) | https://www.kraxel.org/repos/jenkins/edk2/ |
49+
| Zircon UEFI Bootloader | [esp/efi/boot/bootx64.efi](esp/efi/boot/bootx64.efi) | out/default.zircon/efi-x64-clang/bootx64.efi |
50+
51+
The bootloader will look for a ZBI-format image (`esp/zircon.bin`) containing kernel and bootfs.
52+
53+
### BootFS and ZBI image
54+
55+
| Description | Path | Source Path |
56+
| ----------------------- | ------------------------------------------------------------ | --------------------------------------- |
57+
| Zircon and BootFS image | [prebuilt/legacy-image-x64.zbi](prebuilt/legacy-image-x64.zbi) | out/default.zircon/legacy-image-x64.zbi |
58+
| ZBI CLI tool | [tools/Linux/zbi](tools/Linux/zbi) | out/default.zircon/tools/zbi |
59+
60+
We use `zbi` CLI tool to append all files in `bootfs` dir, to the BOOTFS section of the prebuilt image `legacy-image-x64.zbi`, then put the result to `esp/zircon.bin`.
61+
62+
### User libs
63+
64+
Rust programs for Fuchsia need to link the following libraries:
65+
66+
| Path | Source Path |
67+
| ------------------------------------------------------------ | ------------------------------------------------------------ |
68+
| [prebuilt/ulib](prebuilt/ulib)/{Scrt1.o, libc.so, libzircon.so} | out/default/sdk/exported/zircon_sysroot/arch/x64/sysroot/lib/* |
69+
| [prebuilt/ulib/libfdio.so](prebuilt/ulib/libfdio.so) | out/default.zircon/user-x64-clang.shlib/obj/system/ulib/fdio/libfdio.so |
70+
| [prebuilt/ulib/libunwind.so](prebuilt/ulib/libunwind.so) | prebuilt/third_party/clang/linux-x64/lib/x86_64-unknown-fuchsia/c++/libunwind.so |
71+
72+
## Acknowledgement
73+
74+
Thanks to [@PanQL](https://github.com/PanQL) for the help and deep analysis of Fuchsia project.

esp/cmdline

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
kernel.halt-on-panic=true
2+
kernel.serial=legacy

esp/efi/boot/bootx64.efi

79.5 KB
Binary file not shown.

hello/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
**/*.rs.bk

hello/Cargo.lock

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hello/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "hello"
3+
version = "0.1.0"
4+
authors = ["Runji Wang <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

hello/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("cargo:rustc-link-search=native={}", "../prebuilt/ulib");
3+
}

hello/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, Zircon!!!");
3+
}

prebuilt/OVMF.fd

2 MB
Binary file not shown.

prebuilt/legacy-image-x64.zbi

12 MB
Binary file not shown.

prebuilt/ulib/Scrt1.o

3.28 KB
Binary file not shown.

prebuilt/ulib/libc.so

2.48 MB
Binary file not shown.

prebuilt/ulib/libfdio.so

253 KB
Binary file not shown.

prebuilt/ulib/libunwind.so

61.6 KB
Binary file not shown.

prebuilt/ulib/libzircon.so

119 KB
Binary file not shown.

tools/Darwin/zbi

1.12 MB
Binary file not shown.

tools/Linux/zbi

911 KB
Binary file not shown.

0 commit comments

Comments
 (0)