Skip to content

Commit

Permalink
Version 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Manami Mori authored and fukai-t committed Feb 7, 2022
1 parent 23bbe2d commit 3713d7c
Show file tree
Hide file tree
Showing 50 changed files with 3,539 additions and 637 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Rust

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install tools
run: |
sudo apt-get update
sudo apt-get install -y build-essential make
rustup default nightly
rustup component add rust-src
rustup update
cargo install cargo-xbuild
mkdir bin
- name: Build bootloader
run: |
cd src
make bootloader
mv hypervisor_bootloader/target/aarch64-uefi/release/hypervisor_bootloader ../bin/BOOTAA64.EFI
- name: Build kernel
run: |
cd src
make kernel
mv hypervisor_kernel/target/aarch64-none/release/hypervisor_kernel ../bin/hypervisor_kernel
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: Thin Hypervisor
path: bin/


15 changes: 15 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2022 RIKEN
# All rights reserved.
#
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php

FROM rust:latest

RUN rustup default nightly \
&& rustup component add rust-src
RUN rustup update
RUN apt-get update && apt-get install -y \
build-essential make \
&& rm -rf /var/lib/apt/lists/*
RUN cargo install cargo-xbuild
25 changes: 16 additions & 9 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Copyright (c) 2022 RIKEN
# All rights reserved.
#
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php

MAKE = make -C
COMMON_MODULE = common
UEFI_MODULE = uefi
Expand All @@ -11,15 +17,19 @@ QEMU = qemu-system-aarch64
RM = rm -rf
MOUNT = mount
UMOUNT = umount
UEFI_FD ?= QEMU_EFI.fd
QEMU_EFI ?= QEMU_EFI.fd

all: .FORCE
$(MAKE) $(BOOTLOADER)
$(MAKE) $(KERNEL)
all: bootloader kernel
$(MKDIR) bin/EFI/BOOT/
$(CP) $(BOOTLOADER)/target/$(BOOTLOADER_ARCH)/release/$(BOOTLOADER) bin/EFI/BOOT/BOOTAA64.EFI
$(CP) $(KERNEL)/target/$(KERNEL_ARCH)/release/$(KERNEL) bin/EFI/BOOT/$(KERNEL)

bootloader: .FORCE
$(MAKE) $(BOOTLOADER)

kernel: .FORCE
$(MAKE) $(KERNEL)

clean:
$(RM) bin
$(MAKE) $(COMMON_MODULE) clean
Expand All @@ -34,18 +44,15 @@ fmt:
$(MAKE) $(KERNEL) fmt

run: all
$(QEMU) -m 1G -cpu cortex-a53 -machine virt-2.12,virtualization=on -smp 4 -nographic -bios $(UEFI_FD) -drive file=fat:rw:bin/,format=raw,media=disk
$(QEMU) -m 1G -cpu cortex-a53 -machine virt-2.12,virtualization=on -smp 4 -nographic -bios $(QEMU_EFI) -drive file=fat:rw:bin/,format=raw,media=disk

debug: all
$(QEMU) -m 1G -cpu cortex-a53 -machine virt-2.12,virtualization=on -smp 4 -monitor stdio -bios $(UEFI_FD) -drive file=fat:rw:bin/,format=raw,media=disk
$(QEMU) -m 1G -cpu cortex-a53 -machine virt-2.12,virtualization=on -smp 4 -monitor stdio -bios $(QEMU_EFI) -drive file=fat:rw:bin/,format=raw,media=disk

write:
$(MOUNT) $(DEVICE) /mnt
$(CP) bin/EFI/BOOT/BOOTAA64.EFI /mnt/EFI/BOOT/BOOTAA64.EFI
$(CP) bin/EFI/BOOT/$(KERNEL) /mnt/EFI/BOOT/$(KERNEL)
$(UMOUNT) /mnt

default:
$(MAKE) all

.FORCE:
43 changes: 43 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# How to build the hypervisor

## By Rust toolchain
(TBD)


## By docker
### Requirements
- Docker (Tested by `Docker version 20.10.8, build 3967b7d28e`)
- I tested by non-root users (See [this](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user) to run docker command by non-root user)

### Steps (commands list)

```bash
cd path/to/repo-root/src
./build_docker_image.sh #Build docker image to build
./build_hypervisor_by_docker.sh #Build the hypervisor by the docker image
```
More detail, please see the scripts.

# How to run the hypervisor
## On QEMU
First, please install QEMU that support to emulate `QEMU 2.12 ARM Virtual Machine`, `cortex-a53` CPU.
Then, run the following command to run the built hypervisor.

```bash
cd path/to/repo-root/src
make QEMU_EFI=/usr/share/qemu-efi/QEMU_EFI.fd run #Please set the path of your QEMU_EFI.fd to QEMU_EFI
```

## On a physical machine from an USB memory stick
### Requirement
- Prepare a USB memory which has an EFI (FAT) partition that has `/EFI/BOOT/` directory. Please confirm that there is no important file in the partition.
- Prepare a physical machine that has ARMv8-A or later, and UEFI firmware.

### Steps
1. Attach your USB memory stick to the development machine which built the hypervisor binary.
2. Identify the EFI partition (in the following description, `/dev/sdX1` is the EFI partition).
3. Run `sudo make DEVICE=/dev/sdX1 write` to copy the binary.
!! Please be carefully not to specifying a wrong partition as `DEVICE` because the script mount/unmount the partition and copy the binary file with root privilege.!!
4. Detach the USB memory from the development machine, and attach it to the physical machine to run the hypervisor.
5. Boot the physical machine with UEFI, and specify `BOOTAA64.EFI` in the EFI partition as the EFI application to boot.

13 changes: 13 additions & 0 deletions src/build_docker_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Copyright (c) 2022 RIKEN
# All rights reserved.
#
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php

IMG_NAME="rust-build-thin-hypervisor"
timestamp=$(date +%Y%m%d_%H%M%S)

docker build -f Dockerfile -t "${IMG_NAME}:${timestamp}" . \
&& docker tag "${IMG_NAME}:${timestamp}" "${IMG_NAME}:latest"
38 changes: 38 additions & 0 deletions src/build_hypervisor_by_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Copyright (c) 2022 RIKEN
# All rights reserved.
#
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php

cd $(dirname $0)
PWD="$(pwd)"
CONTAINER_NAME="rust-build-thin-hypervisor"
IMG_NAME="rust-build-thin-hypervisor"

do_clean=false

while (( $# > 0 ))
do
case $1 in
--clean)
do_clean=true
;;
*)
echo "Unknow argument"
exit 1
;;
esac
shift 1
done

build_cmdline='cd /workspace && make'
if $do_clean; then
build_cmdline="${build_cmdline} clean"
fi

docker run -it --rm --name ${CONTAINER_NAME} \
-v ${PWD}:/workspace \
${IMG_NAME}:latest \
bash -c "${build_cmdline}"
2 changes: 1 addition & 1 deletion src/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "common"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

[dependencies]
6 changes: 6 additions & 0 deletions src/common/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Copyright (c) 2022 RIKEN
# All rights reserved.
#
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php

CARGO = cargo

clean:
Expand Down
6 changes: 6 additions & 0 deletions src/common/src/acpi.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Copyright (c) 2022 RIKEN
// All rights reserved.
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php

//!
//! Advanced Configuration and Power Interface
//!
Expand Down
6 changes: 6 additions & 0 deletions src/common/src/acpi/madt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Copyright (c) 2022 RIKEN
// All rights reserved.
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php

//!
//! Multiple APIC Description Table
//!
Expand Down
Loading

0 comments on commit 3713d7c

Please sign in to comment.