Skip to content

Commit f974c18

Browse files
Matt RossouwIvan-Velickovic
authored andcommitted
Support for Cheshire on Digilent Genesys 2
Signed-off-by: Matt Rossouw <matthew.rossouw@unsw.edu.au>
1 parent 2f54567 commit f974c18

File tree

5 files changed

+197
-27
lines changed

5 files changed

+197
-27
lines changed

build_sdk.py

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ class ConfigInfo:
254254
"KernelRiscvExtF": True,
255255
},
256256
),
257+
BoardInfo(
258+
name="cheshire",
259+
arch=KernelArch.RISCV64,
260+
gcc_cpu=None,
261+
loader_link_address=0x90000000,
262+
kernel_options={
263+
"KernelIsMCS": True,
264+
"KernelPlatform": "cheshire",
265+
"KernelRiscvExtD": True,
266+
"KernelRiscvExtF": True,
267+
},
268+
),
257269
)
258270

259271
SUPPORTED_CONFIGS = (
@@ -370,9 +382,11 @@ def build_sel4(
370382
sel4_install_dir.mkdir(exist_ok=True, parents=True)
371383
sel4_build_dir.mkdir(exist_ok=True, parents=True)
372384

373-
print(f"Building sel4: {sel4_dir=} {root_dir=} {build_dir=} {board=} {config=}")
385+
print(
386+
f"Building sel4: {sel4_dir=} {root_dir=} {build_dir=} {board=} {config=}")
374387

375-
config_args = list(board.kernel_options.items()) + list(config.kernel_options.items())
388+
config_args = list(board.kernel_options.items()) + \
389+
list(config.kernel_options.items())
376390
config_strs = []
377391
for arg, val in sorted(config_args):
378392
if isinstance(val, bool):
@@ -415,7 +429,8 @@ def build_sel4(
415429
dest.chmod(0o744)
416430

417431
invocations_all = sel4_build_dir / "generated" / "invocations_all.json"
418-
dest = (root_dir / "board" / board.name / config.name / "invocations_all.json")
432+
dest = (root_dir / "board" / board.name /
433+
config.name / "invocations_all.json")
419434
dest.unlink(missing_ok=True)
420435
copy(invocations_all, dest)
421436
dest.chmod(0o744)
@@ -470,7 +485,8 @@ def build_elf_component(
470485
)
471486
elf = build_dir / f"{component_name}.elf"
472487
dest = (
473-
root_dir / "board" / board.name / config.name / "elf" / f"{component_name}.elf"
488+
root_dir / "board" / board.name /
489+
config.name / "elf" / f"{component_name}.elf"
474490
)
475491
dest.unlink(missing_ok=True)
476492
copy(elf, dest)
@@ -545,17 +561,25 @@ def build_lib_component(
545561
def main() -> None:
546562
parser = ArgumentParser()
547563
parser.add_argument("--sel4", type=Path, required=True)
548-
parser.add_argument("--tool-target-triple", default=get_tool_target_triple(), help="Compile the Microkit tool for this target triple")
549-
parser.add_argument("--boards", metavar="BOARDS", help="Comma-separated list of boards to support. When absent, all boards are supported.")
550-
parser.add_argument("--configs", metavar="CONFIGS", help="Comma-separated list of configurations to support. When absent, all configurations are supported.")
551-
parser.add_argument("--skip-tool", action="store_true", help="Tool will not be built")
552-
parser.add_argument("--skip-sel4", action="store_true", help="seL4 will not be built")
553-
parser.add_argument("--skip-docs", action="store_true", help="Docs will not be built")
554-
parser.add_argument("--skip-tar", action="store_true", help="SDK and source tarballs will not be built")
564+
parser.add_argument("--tool-target-triple", default=get_tool_target_triple(),
565+
help="Compile the Microkit tool for this target triple")
566+
parser.add_argument("--boards", metavar="BOARDS",
567+
help="Comma-separated list of boards to support. When absent, all boards are supported.")
568+
parser.add_argument("--configs", metavar="CONFIGS",
569+
help="Comma-separated list of configurations to support. When absent, all configurations are supported.")
570+
parser.add_argument("--skip-tool", action="store_true",
571+
help="Tool will not be built")
572+
parser.add_argument("--skip-sel4", action="store_true",
573+
help="seL4 will not be built")
574+
parser.add_argument("--skip-docs", action="store_true",
575+
help="Docs will not be built")
576+
parser.add_argument("--skip-tar", action="store_true",
577+
help="SDK and source tarballs will not be built")
555578
parser.add_argument("--version", default=VERSION, help="SDK version")
556579
for arch in KernelArch:
557580
arch_str = arch.name.lower()
558-
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")
581+
parser.add_argument(f"--toolchain-prefix-{arch_str}", default=arch.c_toolchain(
582+
), help=f"C toolchain prefix when compiling for {arch_str}, e.g {arch_str}-none-elf")
559583

560584
args = parser.parse_args()
561585

@@ -567,22 +591,28 @@ def main() -> None:
567591
version = args.version
568592

569593
if args.boards is not None:
570-
supported_board_names = frozenset(board.name for board in SUPPORTED_BOARDS)
594+
supported_board_names = frozenset(
595+
board.name for board in SUPPORTED_BOARDS)
571596
selected_board_names = frozenset(args.boards.split(","))
572597
for board_name in selected_board_names:
573598
if board_name not in supported_board_names:
574-
raise Exception(f"Trying to build a board: {board_name} that does not exist in supported list.")
575-
selected_boards = [board for board in SUPPORTED_BOARDS if board.name in selected_board_names]
599+
raise Exception(
600+
f"Trying to build a board: {board_name} that does not exist in supported list.")
601+
selected_boards = [
602+
board for board in SUPPORTED_BOARDS if board.name in selected_board_names]
576603
else:
577604
selected_boards = SUPPORTED_BOARDS
578605

579606
if args.configs is not None:
580-
supported_config_names = frozenset(config.name for config in SUPPORTED_CONFIGS)
607+
supported_config_names = frozenset(
608+
config.name for config in SUPPORTED_CONFIGS)
581609
selected_config_names = frozenset(args.configs.split(","))
582610
for config_name in selected_config_names:
583611
if config_name not in supported_config_names:
584-
raise Exception(f"Trying to build a configuration: {config_name} that does not exist in supported list.")
585-
selected_configs = [config for config in SUPPORTED_CONFIGS if config.name in selected_config_names]
612+
raise Exception(
613+
f"Trying to build a configuration: {config_name} that does not exist in supported list.")
614+
selected_configs = [
615+
config for config in SUPPORTED_CONFIGS if config.name in selected_config_names]
586616
else:
587617
selected_configs = SUPPORTED_CONFIGS
588618

@@ -642,7 +672,8 @@ def main() -> None:
642672
for board in selected_boards:
643673
for config in selected_configs:
644674
if not args.skip_sel4:
645-
sel4_gen_config = build_sel4(sel4_dir, root_dir, build_dir, board, config)
675+
sel4_gen_config = build_sel4(
676+
sel4_dir, root_dir, build_dir, board, config)
646677
loader_printing = 1 if config.name == "debug" else 0
647678
loader_defines = [
648679
("LINK_ADDRESS", hex(board.loader_link_address)),
@@ -651,19 +682,25 @@ def main() -> None:
651682
# There are some architecture dependent configuration options that the loader
652683
# needs to know about, so we figure that out here
653684
if board.arch.is_riscv():
654-
loader_defines.append(("FIRST_HART_ID", sel4_gen_config["FIRST_HART_ID"]))
685+
loader_defines.append(
686+
("FIRST_HART_ID", sel4_gen_config["FIRST_HART_ID"]))
655687
if board.arch.is_arm():
656688
if sel4_gen_config["ARM_PA_SIZE_BITS_40"]:
657689
arm_pa_size_bits = 40
658690
elif sel4_gen_config["ARM_PA_SIZE_BITS_44"]:
659691
arm_pa_size_bits = 44
660692
else:
661-
raise Exception("Unexpected ARM physical address bits defines")
662-
loader_defines.append(("PHYSICAL_ADDRESS_BITS", arm_pa_size_bits))
663-
664-
build_elf_component("loader", root_dir, build_dir, board, config, loader_defines)
665-
build_elf_component("monitor", root_dir, build_dir, board, config, [])
666-
build_lib_component("libmicrokit", root_dir, build_dir, board, config)
693+
raise Exception(
694+
"Unexpected ARM physical address bits defines")
695+
loader_defines.append(
696+
("PHYSICAL_ADDRESS_BITS", arm_pa_size_bits))
697+
698+
build_elf_component("loader", root_dir, build_dir,
699+
board, config, loader_defines)
700+
build_elf_component("monitor", root_dir,
701+
build_dir, board, config, [])
702+
build_lib_component("libmicrokit", root_dir,
703+
build_dir, board, config)
667704

668705
# Setup the examples
669706
for example, example_path in EXAMPLES.items():
@@ -691,7 +728,8 @@ def main() -> None:
691728
source_prefix = Path(f"{NAME}-source-{version}")
692729
with tar_open(source_tar_file, "w:gz") as tar:
693730
for filename in filenames:
694-
tar.add(filename, arcname=source_prefix / filename, filter=tar_filter)
731+
tar.add(filename, arcname=source_prefix /
732+
filename, filter=tar_filter)
695733

696734

697735
if __name__ == "__main__":

docs/manual.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,61 @@ If you are booting from U-Boot, use the following command to start the system im
981981
Note that the OpenSBI version from the CVA6 SDK at the time of writing has issues when
982982
booting. It is recommended to use the mainline OpenSBI.
983983

984+
## Cheshire
985+
986+
Support is available for [Cheshire](https://github.com/pulp-platform/cheshire). It is an SoC design based on the CVA6 core, implementing a 64-bit RISC-V CPU. The design supports the hypervisor extension but currently is not supported in seL4.
987+
988+
Microkit outputs a raw binary for this device. Several steps are required in order to boot.
989+
990+
A custom version of OpenSBI is required. It can be found [here](https://github.com/pulp-platform/opensbi/tree/cheshire). Build the firmware payload using platform `fpga/cheshire`.
991+
992+
### Using U-Boot
993+
994+
With a system pre-configured with the Cheshire ZSBL, OpenSBI and U-boot:
995+
996+
=> go 0x90000000
997+
998+
### Raw systerm with no bootloader
999+
1000+
Without any firmware present on the SD card, it is still possible to boot Cheshire with a Microkit system.
1001+
1002+
Using a GDB prompt via openOCD:
1003+
1004+
1. Reset board
1005+
> monitor reset halt
1006+
1007+
2. Load a device tree blob (DTS available in Cheshire repo or seL4) to memory and set the a0 and a1 registers to point at it:
1008+
1009+
> restore /path/to/cheshire.dtb binary 0xa0000000
1010+
1011+
(tell openSBI where DTB is)
1012+
1013+
> set $a0=0xa0000000
1014+
1015+
(tell openSBI that the default hart is #0)
1016+
1017+
> set $a1=0
1018+
1019+
3. Load openSBI
1020+
1021+
> load /path/to/opensbi/fw_payload.elf
1022+
1023+
4. Allow openSBI to boot, and interrupt it once the line `Test payload running` is emitted on serial.
1024+
1025+
> continue
1026+
1027+
(wait for output)
1028+
1029+
> (Ctrl+C)
1030+
1031+
5. Load Microkit image and execute
1032+
1033+
> restore /path/to/loader.img binary 0x90000000
1034+
1035+
(execute)
1036+
1037+
> continue
1038+
9841039
## Adding Platform Support
9851040

9861041
The following section is a guide for adding support for a new platform to Microkit.

example/cheshire/hello/Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Copyright 2024, UNSW
3+
#
4+
# SPDX-License-Identifier: BSD-2-Clause
5+
#
6+
ifeq ($(strip $(BUILD_DIR)),)
7+
$(error BUILD_DIR must be specified)
8+
endif
9+
10+
ifeq ($(strip $(MICROKIT_SDK)),)
11+
$(error MICROKIT_SDK must be specified)
12+
endif
13+
14+
ifeq ($(strip $(MICROKIT_BOARD)),)
15+
$(error MICROKIT_BOARD must be specified)
16+
endif
17+
18+
ifeq ($(strip $(MICROKIT_CONFIG)),)
19+
$(error MICROKIT_CONFIG must be specified)
20+
endif
21+
22+
TOOLCHAIN := riscv64-unknown-elf
23+
24+
CC := $(TOOLCHAIN)-gcc
25+
LD := $(TOOLCHAIN)-ld
26+
AS := $(TOOLCHAIN)-as
27+
MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit
28+
29+
HELLO_OBJS := hello.o
30+
31+
BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG)
32+
33+
IMAGES := hello.elf
34+
CFLAGS := -mstrict-align -nostdlib -ffreestanding -g -O3 -Wall -Wno-unused-function -Werror -I$(BOARD_DIR)/include -march=rv64imafdc_zicsr_zifencei -mabi=lp64d
35+
LDFLAGS := -L$(BOARD_DIR)/lib
36+
LIBS := -lmicrokit -Tmicrokit.ld
37+
38+
IMAGE_FILE = $(BUILD_DIR)/loader.img
39+
REPORT_FILE = $(BUILD_DIR)/report.txt
40+
41+
all: $(IMAGE_FILE)
42+
43+
$(BUILD_DIR)/%.o: %.c Makefile
44+
$(CC) -c $(CFLAGS) $< -o $@
45+
46+
$(BUILD_DIR)/hello.elf: $(addprefix $(BUILD_DIR)/, $(HELLO_OBJS))
47+
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@
48+
49+
$(IMAGE_FILE) $(REPORT_FILE): $(addprefix $(BUILD_DIR)/, $(IMAGES)) hello.system
50+
$(MICROKIT_TOOL) hello.system --search-path $(BUILD_DIR) --board $(MICROKIT_BOARD) --config $(MICROKIT_CONFIG) -o $(IMAGE_FILE) -r $(REPORT_FILE)

example/cheshire/hello/hello.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2024, UNSW
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
#include <stdint.h>
7+
#include <microkit.h>
8+
9+
void init(void)
10+
{
11+
microkit_dbg_puts("hello, world\n");
12+
}
13+
14+
void notified(microkit_channel ch)
15+
{
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2024, UNSW
4+
5+
SPDX-License-Identifier: BSD-2-Clause
6+
-->
7+
<system>
8+
<protection_domain name="hello" priority="254">
9+
<program_image path="hello.elf" />
10+
</protection_domain>
11+
</system>

0 commit comments

Comments
 (0)