Skip to content

Commit

Permalink
Initial support for QEMU's ARM virt platform
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Velickovic <[email protected]>
  • Loading branch information
Ivan-Velickovic committed Mar 25, 2024
1 parent ddb4c54 commit 0d024f8
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ The currently supported boards are:
* maaxboard
* odroidc2
* odroidc4
* qemu_virt_aarch64
* tqma8xqp1gb
* zcu102

Expand Down
14 changes: 14 additions & 0 deletions build_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ class ConfigInfo:
"timer": Path("example/odroidc4/timer")
}
),
BoardInfo(
name="qemu_virt_aarch64",
gcc_cpu="cortex-a53",
loader_link_address=0x70000000,
kernel_options={
"KernelPlatform": "qemu-arm-virt",
"KernelIsMCS": True,
"KernelArmExportPCNTUser": True,
"QEMU_MEMORY": "2048",
},
examples={
"hello": Path("example/qemu_virt_aarch64/hello")
}
),
)

SUPPORTED_CONFIGS = (
Expand Down
15 changes: 15 additions & 0 deletions docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,21 @@ Rather than typing these each time you can create a U-Boot script:

When debugging is enabled the kernel will use the same UART as U-Boot.

## QEMU virt (AArch64)

Support is available for the virtual AArch64 QEMU platform. This is a platform that is not based
on any specific SoC or hardware platform and is intended for simulating systems for
development or testing.

You can use the following command to simulate a Microkit system:

$ qemu-system-aarch64 \
-machine virt \
-cpu cortex-a53 \
-nographic \
-serial mon:stdio \
-device loader,file=[SYSTEM IMAGE],addr=0x70000000,cpu-num=0 \
-m size=2G

## ZCU102

Expand Down
55 changes: 55 additions & 0 deletions example/qemu_virt_aarch64/hello/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Copyright 2021, Breakaway Consulting Pty. Ltd.
#
# SPDX-License-Identifier: BSD-2-Clause
#
ifeq ($(strip $(BUILD_DIR)),)
$(error BUILD_DIR must be specified)
endif

ifeq ($(strip $(MICROKIT_SDK)),)
$(error MICROKIT_SDK must be specified)
endif

ifeq ($(strip $(MICROKIT_BOARD)),)
$(error MICROKIT_BOARD must be specified)
endif

ifeq ($(strip $(MICROKIT_CONFIG)),)
$(error MICROKIT_CONFIG must be specified)
endif

TOOLCHAIN := aarch64-none-elf

CPU := cortex-a53

CC := $(TOOLCHAIN)-gcc
LD := $(TOOLCHAIN)-ld
AS := $(TOOLCHAIN)-as
MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit

HELLO_OBJS := hello.o

BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG)

IMAGES := hello.elf
CFLAGS := -mcpu=$(CPU) -mstrict-align -nostdlib -ffreestanding -g -O3 -Wall -Wno-unused-function -Werror -I$(BOARD_DIR)/include
LDFLAGS := -L$(BOARD_DIR)/lib
LIBS := -lmicrokit -Tmicrokit.ld

IMAGE_FILE = $(BUILD_DIR)/loader.img
REPORT_FILE = $(BUILD_DIR)/report.txt

all: $(IMAGE_FILE)

$(BUILD_DIR)/%.o: %.c Makefile
$(CC) -c $(CFLAGS) $< -o $@

$(BUILD_DIR)/%.o: %.s Makefile
$(AS) -g -mcpu=$(CPU) $< -o $@

$(BUILD_DIR)/hello.elf: $(addprefix $(BUILD_DIR)/, $(HELLO_OBJS))
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@

$(IMAGE_FILE) $(REPORT_FILE): $(addprefix $(BUILD_DIR)/, $(IMAGES)) hello.system
$(MICROKIT_TOOL) hello.system --search-path $(BUILD_DIR) --board $(MICROKIT_BOARD) --config $(MICROKIT_CONFIG) -o $(IMAGE_FILE) -r $(REPORT_FILE)
16 changes: 16 additions & 0 deletions example/qemu_virt_aarch64/hello/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2021, Breakaway Consulting Pty. Ltd.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <stdint.h>
#include <microkit.h>

void init(void)
{
microkit_dbg_puts("hello, world\n");
}

void notified(microkit_channel ch)
{
}
11 changes: 11 additions & 0 deletions example/qemu_virt_aarch64/hello/hello.system
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2021, Breakaway Consulting Pty. Ltd.
SPDX-License-Identifier: BSD-2-Clause
-->
<system>
<protection_domain name="hello" priority="254">
<program_image path="hello.elf" />
</protection_domain>
</system>
18 changes: 16 additions & 2 deletions loader/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ _Static_assert(sizeof(uintptr_t) == 8 || sizeof(uintptr_t) == 4, "Expect uintptr
#if defined(BOARD_zcu102)
#define GICD_BASE 0x00F9010000UL
#define GICC_BASE 0x00F9020000UL
#elif defined(BOARD_qemu_virt_aarch64)
#define GICD_BASE 0x8010000UL
#define GICC_BASE 0x8020000UL
#endif

#define REGION_TYPE_DATA 1
Expand Down Expand Up @@ -179,6 +182,17 @@ static void putc(uint8_t ch)
while ((*UART_REG(UART_STATUS) & UART_TX_FULL));
*UART_REG(UART_WFIFO) = ch;
}
#elif defined(BOARD_qemu_virt_aarch64)
#define UART_BASE 0x9000000
#define UARTDR 0x000
#define UARTFR 0x018
#define PL011_UARTFR_TXFF (1 << 5)

static void putc(uint8_t ch)
{
while ((*UART_REG(UARTFR) & PL011_UARTFR_TXFF) != 0);
*UART_REG(UARTDR) = ch;
}
#else
#error Board not defined
#endif
Expand Down Expand Up @@ -490,7 +504,7 @@ static void start_kernel(void)
);
}

#if defined(BOARD_zcu102)
#if defined(BOARD_zcu102) || defined(BOARD_qemu_virt_aarch64)
static void configure_gicv2(void)
{
/* The ZCU102 start in EL3, and then we drop to EL1(NS).
Expand Down Expand Up @@ -554,7 +568,7 @@ int main(void)
*/
copy_data();

#if defined(BOARD_zcu102)
#if defined(BOARD_zcu102) || defined(BOARD_qemu_virt_aarch64)
configure_gicv2();
#endif

Expand Down

0 comments on commit 0d024f8

Please sign in to comment.