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

Allow building the SDK with a custom toolchain prefix #228

Merged
merged 2 commits into from
Oct 22, 2024
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ Testing has been performed using commit `4cae30a6ef166a378d4d23697b00106ce7e4e76

$ ./pyenv/bin/python build_sdk.py --sel4=<path to sel4>

The SDK will be in `release/`.

See the help menu of `build_sdk.py` for configuring how the SDK is built:

$ ./pyenv/bin/python build_sdk.py --help

## Using the SDK

After building the SDK you probably want to build a system!
Expand Down
30 changes: 16 additions & 14 deletions build_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

MICROKIT_EPOCH = 1616367257

TOOLCHAIN_AARCH64 = "aarch64-none-elf-"
TOOLCHAIN_RISCV = "riscv64-unknown-elf-"
TOOLCHAIN_AARCH64 = "aarch64-none-elf"
TOOLCHAIN_RISCV = "riscv64-unknown-elf"

KERNEL_CONFIG_TYPE = Union[bool, str]
KERNEL_OPTIONS = Dict[str, Union[bool, str]]
Expand All @@ -43,6 +43,14 @@ class KernelArch(IntEnum):
AARCH64 = 1
RISCV64 = 2

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

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

Expand Down Expand Up @@ -286,15 +294,6 @@ 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 @@ -385,7 +384,7 @@ def build_sel4(
config_strs.append(s)
config_str = " ".join(config_strs)

toolchain = c_toolchain(board.arch)
toolchain = f"{board.arch.c_toolchain()}-"
cmd = (
f"cmake -GNinja -DCMAKE_INSTALL_PREFIX={sel4_install_dir.absolute()} "
f" -DPYTHON3={executable} "
Expand Down Expand Up @@ -450,7 +449,7 @@ 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)
toolchain = f"{board.arch.c_toolchain()}-"
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}"

Expand Down Expand Up @@ -497,7 +496,7 @@ def build_lib_component(
build_dir = build_dir / board.name / config.name / component_name
build_dir.mkdir(exist_ok=True, parents=True)

toolchain = c_toolchain(board.arch)
toolchain = f"{board.arch.c_toolchain()}-"
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:
Expand Down Expand Up @@ -549,6 +548,9 @@ def main() -> None:
parser.add_argument("--skip-docs", action="store_true", help="Docs will not be built")
parser.add_argument("--skip-tar", action="store_true", help="SDK and source tarballs will not be built")
parser.add_argument("--version", default=VERSION, help="SDK version")
for arch in KernelArch:
arch_str = arch.name.lower()
parser.add_argument(f"--toolchain-prefix-{arch_str}", default=arch.c_toolchain(), help=f"C toolchain prefix when compiling for {arch_str}, e.g {arch_str}-none-elf")

args = parser.parse_args()

Expand Down
Loading