Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch: Add aarch64 support #205

Merged
merged 15 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,35 @@ jobs:
if: github.event_name == 'pull_request'
name: Build
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-none.json
tests: true
- target: aarch64-unknown-none.json
tests: false
steps:
- name: Code checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install rust-src
run: rustup component add rust-src
- name: Install clippy
run: rustup component add clippy
- name: Install rustfmt
run: rustup component add rustfmt
- name: Install Rust components
run: rustup component add rust-src clippy rustfmt
- name: Build (debug)
run: cargo build --target x86_64-unknown-none.json -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
run: cargo build --target ${{ matrix.target }} -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
- name: Build (release)
run: cargo build --release --target x86_64-unknown-none.json -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
run: cargo build --release --target ${{ matrix.target }} -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
- name: Clippy (default)
run: cargo clippy --target x86_64-unknown-none.json -Zbuild-std=core,alloc
run: cargo clippy --target ${{ matrix.target }} -Zbuild-std=core,alloc
- name: Clippy (all targets, all features)
run: cargo clippy --all-targets --all-features
- name: Formatting
run: cargo fmt --all -- --check
- name: Unit tests
- if: ${{ matrix.tests }}
name: Unit tests
run: |
sudo apt-get install -y mtools
bash scripts/run_unit_tests.sh
14 changes: 11 additions & 3 deletions .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,32 @@ jobs:
- name: Code checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Get active Rust toolchain
id: get-toolchain
run: echo "toolchain=`rustup show active-toolchain | cut -d ' ' -f1`" >> $GITHUB_ENV

- name: Login to DockerHub
if: ${{ github.repository == 'cloud-hypervisor/rust-hypervisor-firmware' && github.event_name == 'push' }}
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
file: ./resources/Dockerfile
build-args: |
RUST_TOOLCHAIN=${{ env.toolchain }}
platforms: linux/amd64
platforms: |
linux/arm64
linux/amd64
push: ${{ github.repository == 'cloud-hypervisor/rust-hypervisor-firmware' && github.event_name == 'push' }}
tags: rusthypervisorfirmware/dev:latest

Expand Down
54 changes: 54 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ atomic_refcell = "0.1.9"
r-efi = { version = "4.1.0", features = ["efiapi"] }
linked_list_allocator = "0.10.4"

[target.'cfg(target_arch = "aarch64")'.dependencies]
tock-registers = "0.8.1"
cortex-a = "8.0.0"
fdt = "0.1.4"
retrage marked this conversation as resolved.
Show resolved Hide resolved
chrono = { version = "0.4", default-features = false }

[target.'cfg(target_arch = "x86_64")'.dependencies]
uart_16550 = "0.2.18"
x86_64 = "0.14.10"
Expand Down
15 changes: 15 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ pipeline {
}
}
}
stage ('AArch64 Unit Tests') {
agent { node { label 'focal-arm64' } }
stages {
stage ('Checkout') {
steps {
checkout scm
}
}
stage('Run unit tests') {
steps {
sh "scripts/dev_cli.sh --local tests --unit"
}
}
}
}
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions aarch64-unknown-none.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"llvm-target": "aarch64-unknown-none",
"abi": "softfloat",
"arch": "aarch64",
"data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128",
"disable-redzone": true,
"features": "+strict-align,-neon,-fp-armv8",
"linker": "rust-lld",
"linker-flavor": "ld.lld",
"os": "none",
"executables": true,
"max-atomic-width": 128,
"panic-strategy": "abort",
"code-model": "small",
"relocation-model": "pic",
"target-pointer-width": "64",
"pre-link-args": {
"ld.lld": ["--script=aarch64-unknown-none.ld", "--oformat=binary"]
}
}
44 changes: 44 additions & 0 deletions aarch64-unknown-none.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ENTRY(ram64_start)

/* Cloud Hypervisor Memory layout:
DRAM: [0x4000_0000-0xfc00_0000]
FDT: [0x4000_0000-0x401f_ffff)
ACPI: [0x4020_0000-0x403f_ffff)
kernel: [0x4048_0000-]
The stack start is at the end of the DRAM region. */
ram_min = 0x40480000;

SECTIONS
{
/* Mapping the program headers and note into RAM makes the file smaller. */
. = ram_min;

/* These sections are mapped into RAM from the file. Omitting :ram from
later sections avoids emitting empty sections in the final binary. */
code_start = .;
.text.boot : { *(.text.boot) }
.text : { *(.text .text.*) }
. = ALIGN(4K);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
. = ALIGN(4K);
. = ALIGN(64K);

Paging and TTable code assumes 64KiB pages, but you are aligning to 4KiB here (rest of file as well)

code_end = .;

data_start = .;
.data : { *(.data .data.*) }
.rodata : { *(.rodata .rodata.*) }

/* The BSS section isn't mapped from file data. It is just zeroed in RAM. */
.bss : {
*(.bss .bss.*)
}
. = ALIGN(4K);
data_end = .;

stack_start = .;
.stack (NOLOAD) : ALIGN(4K) { . += 128K; }
stack_end = .;

/* Strip symbols from the output binary (comment out to get symbols) */
/DISCARD/ : {
*(.symtab)
*(.strtab)
}
}
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fn main() {
println!("cargo:rerun-if-changed=aarch64-unknown-none.json");
println!("cargo:rerun-if-changed=aarch64-unknown-none.ld");
println!("cargo:rerun-if-changed=x86_64-unknown-none.json");
println!("cargo:rerun-if-changed=x86_64-unknown-none.ld");
}
59 changes: 43 additions & 16 deletions resources/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ ENV PATH="$PATH:$CARGO_HOME/bin"
ENV COREBOOT_DIR=/opt/coreboot/src

# Install all CI dependencies
RUN apt-get update \
RUN if [ "$TARGETARCH" = "amd64" ]; then \
apt-get update \
&& apt-get -yq upgrade \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq \
build-essential \
Expand Down Expand Up @@ -49,7 +50,29 @@ RUN apt-get update \
zlib1g-dev \
gnat-9 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* \
; fi

RUN if [ "$TARGETARCH" = "arm64" ]; then \
apt-get update \
&& apt-get -yq upgrade \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq \
build-essential \
docker.io \
curl \
wget \
sudo \
mtools \
libssl-dev \
pkg-config \
qemu-utils \
libseccomp-dev \
libcap-ng-dev \
libcap2-bin \
dosfstools \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
; fi

# Fix the libssl-dev install
RUN export ARCH="$(uname -m)" \
Expand All @@ -62,22 +85,26 @@ ENV OPENSSL_INCLUDE_DIR=/usr/include/

# Install the rust toolchain
RUN export ARCH="$(uname -m)" \
&& nohup curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN" \
&& rustup component add rustfmt \
&& rustup component add clippy \
&& rustup component add rust-src \
&& rm -rf "$CARGO_HOME/registry" \
&& ln -s "$CARGO_REGISTRY_DIR" "$CARGO_HOME/registry" \
&& rm -rf "$CARGO_HOME/git" \
&& ln -s "$CARGO_GIT_REGISTRY_DIR" "$CARGO_HOME/git"
&& nohup curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN" \
&& rustup component add rustfmt \
&& rustup component add clippy \
&& rustup component add rust-src \
&& rustup target add aarch64-unknown-linux-gnu \
&& rustup target add x86_64-unknown-linux-gnu \
&& rm -rf "$CARGO_HOME/registry" \
&& ln -s "$CARGO_REGISTRY_DIR" "$CARGO_HOME/registry" \
&& rm -rf "$CARGO_HOME/git" \
&& ln -s "$CARGO_GIT_REGISTRY_DIR" "$CARGO_HOME/git"

# Set the rust environment
RUN echo 'source $CARGO_HOME/env' >> $HOME/.bashrc \
&& mkdir $HOME/.cargo \
&& ln -s $CARGO_HOME/env $HOME/.cargo/env
&& mkdir $HOME/.cargo \
&& ln -s $CARGO_HOME/env $HOME/.cargo/env

# Checkout coreboot repository and setup cross toolchains
RUN git clone --quiet --branch "$COREBOOT_VERSION" --depth 1 https://github.com/coreboot/coreboot.git "$COREBOOT_DIR" \
&& cd "$COREBOOT_DIR" \
&& git submodule update --init --checkout \
&& make crossgcc-i386 CPUS=`nproc`
RUN if [ "$TARGETARCH" = "amd64" ]; then \
git clone --quiet --branch "$COREBOOT_VERSION" --depth 1 https://github.com/coreboot/coreboot.git "$COREBOOT_DIR" \
&& cd "$COREBOOT_DIR" \
&& git submodule update --init --checkout \
&& make crossgcc-i386 CPUS=`nproc`; \
fi
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "nightly-2022-11-12"
components = ["rust-src", "clippy", "rustfmt"]
targets = ["x86_64-unknown-linux-gnu"]
targets = ["aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu"]
profile = "default"
Loading