Skip to content
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
16 changes: 11 additions & 5 deletions .github/workflows/sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
jobs:
build_linux_x64:
name: Build SDK (Linux x86-64)
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout Microkit repository
uses: actions/checkout@v4
Expand All @@ -35,12 +35,13 @@ jobs:
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install \
gcc-riscv64-unknown-elf \
cmake pandoc device-tree-compiler ninja-build \
texlive-latex-base texlive-latex-recommended \
texlive-fonts-recommended texlive-fonts-extra \
libxml2-utils \
python3.9 python3-pip python3.9-venv \
qemu-system-arm \
qemu-system-arm qemu-system-misc \
- name: Install AArch64 GCC toolchain
run: |
wget -O aarch64-toolchain.tar.gz https://sel4-toolchains.s3.us-east-2.amazonaws.com/arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-elf.tar.xz%3Frev%3D28d5199f6db34e5980aae1062e5a6703%26hash%3DF6F5604BC1A2BBAAEAC4F6E98D8DC35B
Expand All @@ -54,7 +55,7 @@ jobs:
./pyenv/bin/python build_sdk.py --sel4=seL4
build_macos_x64:
name: Build SDK (macOS x86-64)
runs-on: macos-12
runs-on: macos-14
steps:
- name: Checkout Microkit repository
uses: actions/checkout@v4
Expand All @@ -65,7 +66,10 @@ jobs:
ref: microkit
path: seL4
- name: Install SDK dependencies
run: brew install pandoc cmake dtc ninja qemu libxml2 python@3.9 coreutils texlive qemu
run: |
brew tap riscv-software-src/riscv
brew install riscv-tools
brew install pandoc cmake dtc ninja qemu libxml2 python@3.9 coreutils texlive qemu
- name: Install AArch64 GCC toolchain
run: |
wget -O aarch64-toolchain.tar.gz https://sel4-toolchains.s3.us-east-2.amazonaws.com/arm-gnu-toolchain-12.2.rel1-darwin-x86_64-aarch64-none-elf.tar.xz%3Frev%3D09b11f159fc24fdda01e05bb32695dd5%26hash%3D6AAF4239F28AE17389AB3E611DFFE0A6
Expand All @@ -79,7 +83,7 @@ jobs:
./pyenv/bin/python build_sdk.py --sel4=seL4
build_macos_arm64:
name: Build SDK (macOS ARM64)
runs-on: macos-12
runs-on: macos-14
steps:
- name: Checkout Microkit repository
uses: actions/checkout@v4
Expand All @@ -92,6 +96,8 @@ jobs:
- name: Install SDK dependencies
run: |
rustup target add aarch64-apple-darwin
brew tap riscv-software-src/riscv
brew install riscv-tools
brew install pandoc cmake dtc ninja qemu libxml2 python@3.9 coreutils texlive
- name: Install AArch64 GCC toolchain
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pyenv/
release/
tmp_build/
target/
*.orig
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Please file an issue if additional packages are required.
* cmake
* ninja-build
* ARM GCC compiler for none-elf; version 12.2.1 20221205
* RISC-V GCC compiler for unknown-elf; version 13.2.0
* device tree compiler
* xmllint
* qemu-system-aarch64
Expand All @@ -64,7 +65,8 @@ On a Debian-like system you can do:
pandoc texlive-latex-base texlive-latex-recommended \
texlive-fonts-recommended texlive-fonts-extra \
python3.9 python3.9-venv \
qemu-system-arm
qemu-system-arm qemu-system-misc \
gcc-riscv64-unknown-elf

If you do not have Python 3.9 available, you can get it via the
*deadsnakes* PPA: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
Expand All @@ -77,6 +79,8 @@ To use this:
On macOS, with the [Homebrew](https://brew.sh) package manager you can do:

$ curl https://sh.rustup.rs -sSf | sh
$ brew tap riscv-software-src/riscv
$ brew install riscv-tools
$ brew install pandoc cmake dtc ninja qemu libxml2 python@3.9 coreutils texlive qemu

Additonally, a number of Python libraries are needed.
Expand Down Expand Up @@ -118,7 +122,7 @@ Please clone seL4 from:

The correct branch to use is `microkit`.

Testing has been performed using commit `0cdbffec9cf6b4c7c9c57971cbee5a24a70c8fd0`.
Testing has been performed using commit `4cae30a6ef166a378d4d23697b00106ce7e4e76f`.

## Building the SDK

Expand Down Expand Up @@ -179,6 +183,8 @@ The currently supported boards are:
* odroidc2
* odroidc4
* qemu_virt_aarch64
* qemu_virt_riscv64
* star64
* tqma8xqp1gb
* zcu102

Expand Down
126 changes: 111 additions & 15 deletions build_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
from sys import executable
from tarfile import open as tar_open, TarInfo
import platform as host_platform
from enum import IntEnum
import json

from typing import Dict, Union, List, Tuple
from typing import Any, Dict, Union, List, Tuple, Optional

NAME = "microkit"
VERSION = "1.3.0"
Expand All @@ -30,33 +32,53 @@

MICROKIT_EPOCH = 1616367257

# Due to only supporting AArch64 (for now), we hard-code
# the prefix of the toolchain used to compile seL4.
TOOLCHAIN_PREFIX = "aarch64-none-elf-"
TOOLCHAIN_AARCH64 = "aarch64-none-elf-"
TOOLCHAIN_RISCV = "riscv64-unknown-elf-"

KERNEL_CONFIG_TYPE = Union[bool, str]
KERNEL_OPTIONS = Dict[str, KERNEL_CONFIG_TYPE]
KERNEL_OPTIONS = Dict[str, Union[bool, str]]


class KernelArch(IntEnum):
AARCH64 = 1
RISCV64 = 2

def is_riscv(self) -> bool:
return self == KernelArch.RISCV64

def is_arm(self) -> bool:
return self == KernelArch.AARCH64

def to_str(self) -> str:
if self == KernelArch.AARCH64:
return "aarch64"
elif self == KernelArch.RISCV64:
return "riscv64"
else:
raise Exception(f"Unsupported arch {self}")


@dataclass
class BoardInfo:
name: str
gcc_cpu: str
arch: KernelArch
gcc_cpu: Optional[str]
loader_link_address: int
kernel_options: KERNEL_CONFIG_TYPE
kernel_options: KERNEL_OPTIONS
examples: Dict[str, Path]


@dataclass
class ConfigInfo:
name: str
debug: bool
kernel_options: KERNEL_CONFIG_TYPE
kernel_options: KERNEL_OPTIONS


SUPPORTED_BOARDS = (
BoardInfo(
name="tqma8xqp1gb",
arch=KernelArch.AARCH64,
gcc_cpu="cortex-a35",
loader_link_address=0x80280000,
kernel_options={
Expand All @@ -71,6 +93,7 @@ class ConfigInfo:
),
BoardInfo(
name="zcu102",
arch=KernelArch.AARCH64,
gcc_cpu="cortex-a53",
loader_link_address=0x40000000,
kernel_options={
Expand All @@ -86,6 +109,7 @@ class ConfigInfo:
),
BoardInfo(
name="maaxboard",
arch=KernelArch.AARCH64,
gcc_cpu="cortex-a53",
loader_link_address=0x40480000,
kernel_options={
Expand All @@ -100,6 +124,7 @@ class ConfigInfo:
),
BoardInfo(
name="imx8mm_evk",
arch=KernelArch.AARCH64,
gcc_cpu="cortex-a53",
loader_link_address=0x41000000,
kernel_options={
Expand All @@ -114,6 +139,7 @@ class ConfigInfo:
),
BoardInfo(
name="imx8mq_evk",
arch=KernelArch.AARCH64,
gcc_cpu="cortex-a53",
loader_link_address=0x41000000,
kernel_options={
Expand All @@ -128,6 +154,7 @@ class ConfigInfo:
),
BoardInfo(
name="odroidc2",
arch=KernelArch.AARCH64,
gcc_cpu="cortex-a53",
loader_link_address=0x20000000,
kernel_options={
Expand All @@ -142,6 +169,7 @@ class ConfigInfo:
),
BoardInfo(
name="odroidc4",
arch=KernelArch.AARCH64,
gcc_cpu="cortex-a55",
loader_link_address=0x20000000,
kernel_options={
Expand All @@ -156,6 +184,7 @@ class ConfigInfo:
),
BoardInfo(
name="qemu_virt_aarch64",
arch=KernelArch.AARCH64,
gcc_cpu="cortex-a53",
loader_link_address=0x70000000,
kernel_options={
Expand All @@ -172,6 +201,33 @@ class ConfigInfo:
"hierarchy": Path("example/qemu_virt_aarch64/hierarchy")
}
),
BoardInfo(
name="qemu_virt_riscv64",
arch=KernelArch.RISCV64,
gcc_cpu=None,
loader_link_address=0x80200000,
kernel_options={
"KernelPlatform": "qemu-riscv-virt",
"KernelIsMCS": True,
"QEMU_MEMORY": "2048",
},
examples={
"hello": Path("example/qemu_virt_riscv64/hello"),
}
),
BoardInfo(
name="star64",
arch=KernelArch.RISCV64,
gcc_cpu=None,
loader_link_address=0x60000000,
kernel_options={
"KernelIsMCS": True,
"KernelPlatform": "star64",
},
examples={
"hello": Path("example/star64/hello")
}
),
)

SUPPORTED_CONFIGS = (
Expand Down Expand Up @@ -201,6 +257,15 @@ class ConfigInfo:
)


def c_toolchain(arch: KernelArch) -> str:
if arch == KernelArch.AARCH64:
return TOOLCHAIN_AARCH64
elif arch == KernelArch.RISCV64:
return TOOLCHAIN_RISCV
else:
raise Exception("Unsupported toolchain architecture '{arch}'")


def tar_filter(tarinfo: TarInfo) -> TarInfo:
"""This is used to change the tarinfo when created the .tar.gz archive.

Expand Down Expand Up @@ -270,7 +335,7 @@ def build_sel4(
build_dir: Path,
board: BoardInfo,
config: ConfigInfo,
) -> None:
) -> Dict[str, Any]:
"""Build seL4"""
build_dir = build_dir / board.name / config.name / "sel4"
build_dir.mkdir(exist_ok=True, parents=True)
Expand All @@ -294,10 +359,11 @@ def build_sel4(
config_strs.append(s)
config_str = " ".join(config_strs)

toolchain = c_toolchain(board.arch)
cmd = (
f"cmake -GNinja -DCMAKE_INSTALL_PREFIX={sel4_install_dir.absolute()} "
f" -DPYTHON3={executable} "
f" -DCROSS_COMPILER_PREFIX={TOOLCHAIN_PREFIX}"
f" -DCROSS_COMPILER_PREFIX={toolchain}"
f" {config_str} "
f"-S {sel4_dir.absolute()} -B {sel4_build_dir.absolute()}")

Expand Down Expand Up @@ -337,6 +403,11 @@ def build_sel4(
copy(p, dest)
dest.chmod(0o744)

gen_config_path = sel4_install_dir / "libsel4/include/kernel/gen_config.json"
with open(gen_config_path, "r") as f:
gen_config = json.load(f)
return gen_config


def build_elf_component(
component_name: str,
Expand All @@ -353,9 +424,15 @@ def build_elf_component(
sel4_dir = root_dir / "board" / board.name / config.name
build_dir = build_dir / board.name / config.name / component_name
build_dir.mkdir(exist_ok=True, parents=True)
toolchain = c_toolchain(board.arch)
defines_str = " ".join(f"{k}={v}" for k, v in defines)
defines_str += f" ARCH={board.arch.to_str()} BOARD={board.name} BUILD_DIR={build_dir.absolute()} SEL4_SDK={sel4_dir.absolute()} TOOLCHAIN={toolchain}"

if board.gcc_cpu is not None:
defines_str += f" GCC_CPU={board.gcc_cpu}"

r = system(
f"BOARD={board.name} BUILD_DIR={build_dir.absolute()} GCC_CPU={board.gcc_cpu} SEL4_SDK={sel4_dir.absolute()} {defines_str} make -C {component_name}"
f"{defines_str} make -C {component_name}"
)
if r != 0:
raise Exception(
Expand All @@ -371,7 +448,7 @@ def build_elf_component(
dest.chmod(0o744)


def build_doc(root_dir):
def build_doc(root_dir: Path):
output = root_dir / "doc" / "microkit_user_manual.pdf"

environ["TEXINPUTS"] = "docs/style:"
Expand All @@ -393,8 +470,15 @@ def build_lib_component(
sel4_dir = root_dir / "board" / board.name / config.name
build_dir = build_dir / board.name / config.name / component_name
build_dir.mkdir(exist_ok=True, parents=True)

toolchain = c_toolchain(board.arch)
defines_str = f" ARCH={board.arch.to_str()} BUILD_DIR={build_dir.absolute()} SEL4_SDK={sel4_dir.absolute()} TOOLCHAIN={toolchain}"

if board.gcc_cpu is not None:
defines_str += f" GCC_CPU={board.gcc_cpu}"

r = system(
f"BUILD_DIR={build_dir.absolute()} GCC_CPU={board.gcc_cpu} SEL4_SDK={sel4_dir.absolute()} make -C {component_name}"
f"{defines_str} make -C {component_name}"
)
if r != 0:
raise Exception(
Expand Down Expand Up @@ -512,13 +596,25 @@ def main() -> None:
build_dir = Path("build")
for board in selected_boards:
for config in selected_configs:
build_sel4(sel4_dir, root_dir, build_dir, board, config)
sel4_gen_config = build_sel4(sel4_dir, root_dir, build_dir, board, config)
loader_printing = 1 if config.name == "debug" else 0
loader_defines = [
("LINK_ADDRESS", hex(board.loader_link_address)),
("PHYSICAL_ADDRESS_BITS", 40),
("PRINTING", loader_printing)
]
# There are some architecture dependent configuration options that the loader
# needs to know about, so we figure that out here
if board.arch.is_riscv():
loader_defines.append(("FIRST_HART_ID", sel4_gen_config["FIRST_HART_ID"]))
if board.arch.is_arm():
if sel4_gen_config["ARM_PA_SIZE_BITS_40"]:
arm_pa_size_bits = 40
elif sel4_gen_config["ARM_PA_SIZE_BITS_44"]:
arm_pa_size_bits = 44
else:
raise Exception("Unexpected ARM physical address bits defines")
loader_defines.append(("PHYSICAL_ADDRESS_BITS", arm_pa_size_bits))

build_elf_component("loader", root_dir, build_dir, board, config, loader_defines)
build_elf_component("monitor", root_dir, build_dir, board, config, [])
build_lib_component("libmicrokit", root_dir, build_dir, board, config)
Expand Down
Loading