Skip to content
Closed
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: 3 additions & 3 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[target.riscv64gc-unknown-none-elf]
rustflags = [
"-Clink-arg=-Tscripts/qemu-riscv64.ld",
"-Clink-arg=-T../platform/riscv64/qemu/linker.ld",
"-Cforce-frame-pointers=yes"
]

[target.aarch64-unknown-none]
rustflags = [
"-Clink-arg=-Tscripts/qemu-aarch64.ld",
"-Clink-arg=-T../platform/aarch64/qemu/linker.ld",
"-Ctarget-feature=+a53,+v8a,+strict-align,-neon,-fp-armv8",
"-Cforce-frame-pointers=yes",
]

[target.loongarch64-unknown-none]
linker = "loongarch64-unknown-linux-gnu-gcc"
rustflags = [
"-Clink-arg=-Tscripts/3a5000-loongarch64.ld",
"-Clink-arg=-T../platform/loongarch64/3a5000/linker.ld",
"-Cforce-frame-pointers=yes",
]
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/target
/qemu-test
/test-img
/hvisor.S
/hvisor-elf.txt
/disa
/images/aarch64/virtdisk/*
/images/aarch64/kernel/*
/images/aarch64/devicetree/*.dtb
Expand All @@ -24,3 +23,4 @@ Image*
*.ext4
*.qcow2
*.dtb
hvisor.bin
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
// "rust-analyzer.cargo.target": "riscv64gc-unknown-none-elf",
// "rust-analyzer.cargo.target": "loongarch64-unknown-none",
"rust-analyzer.checkOnSave.allTargets": false,
// "rust-analyzer.cargo.features": [
// "board_qemu"
// ]
"rust-analyzer.cargo.features": [
"platform_qemu"
]
}
5 changes: 0 additions & 5 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ buddy_system_allocator = "0.8"
tock-registers = "0.8"
lazy_static = { version = "1.4", features = ["spin_no_std"] }
bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator", rev = "03bd9909" }
fdt = { path = "./vendor/fdt" }

[target.'cfg(target_arch = "aarch64")'.dependencies]
aarch64-cpu = "9.4.0"
Expand Down
58 changes: 37 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Basic settings
PLATFORM ?= qemu
ARCH ?= aarch64
LOG ?= info
STATS ?= off
PORT ?= 2333
MODE ?= debug

OBJCOPY ?= rust-objcopy --binary-architecture=$(ARCH)
KDIR ?= ../../linux
FEATURES ?= platform_qemu

# Check the value of ARCH and set corresponding RUSTC_TARGET and GDB_ARCH values.
ifeq ($(ARCH),aarch64)
RUSTC_TARGET := aarch64-unknown-none
RUSTC_TARGET := aarch64-unknown-none
GDB_ARCH := aarch64
else ifeq ($(ARCH),riscv64)
RUSTC_TARGET := riscv64gc-unknown-none-elf
Expand All @@ -18,68 +19,83 @@ else ifeq ($(ARCH),loongarch64)
RUSTC_TARGET := loongarch64-unknown-none
GDB_ARCH := loongarch64
else
# Error out if an unsupported ARCH value is provided.
$(error Unsupported ARCH value: $(ARCH))
endif

# Export these variables so that they can be accessed in other parts of the build process (e.g., included scripts).
export MODE
export LOG
export ARCH
export PLATFORM

# Build paths
build_path := target/$(RUSTC_TARGET)/$(MODE)
hvisor_elf := $(build_path)/hvisor
hvisor_bin := $(build_path)/hvisor.bin
image_dir := images/$(ARCH)
hvisor_bin := $(shell pwd)/hvisor.bin

ifeq ($(ARCH),aarch64)
hvisor_bin_command := if ! command -v mkimage > /dev/null; then \
sudo apt update; sudo apt install u-boot-tools; \
fi && \
$(OBJCOPY) $(hvisor_elf) --strip-all -O binary $(hvisor_bin).tmp && \
mkimage -n hvisor_img -A arm64 -O linux -C none -a 0x40400000 -e 0x40400000 \
-T kernel -d $(hvisor_bin).tmp $(hvisor_bin) && rm -rf $(hvisor_bin).tmp
else
hvisor_bin_command := $(OBJCOPY) $(hvisor_elf) --strip-all -O binary $@
endif

# Build arguments
build_args :=
build_args += --features "$(FEATURES)"
# Add the platform feature with the 'platform_' prefix concatenated with the PLATFORM value.
# This is to match the feature naming convention in the Cargo.toml file for building.
build_args += --features "platform_$(PLATFORM)"
build_args += --target $(RUSTC_TARGET)
build_args += -Z build-std=core,alloc
build_args += -Z build-std-features=compiler-builtins-mem


ifeq ($(MODE), release)
build_args += --release
endif

# Targets
.PHONY: all elf disa run gdb monitor clean tools rootfs
# Declare these targets asphony to avoid conflicts with actual files (if any).
.PHONY: all elf disa run gdb monitor show-features jlink-server cp clean

all: $(hvisor_bin)

$(hvisor_bin): elf
$(hvisor_bin_command)

elf:
cargo build $(build_args)

disa:
readelf -a $(hvisor_elf) > hvisor-elf.txt
rust-objdump --disassemble $(hvisor_elf) > hvisor.S

run: all
$(QEMU) $(QEMU_ARGS)

gdb: all
$(QEMU) $(QEMU_ARGS) -s -S
mkdir -p disa
readelf -a $(hvisor_elf) > disa/hvisor-elf.txt
rust-objdump --disassemble $(hvisor_elf) > disa/hvisor.S

show-features:
# Print the target features for the specified RUSTC_TARGET using rustc.
rustc --print=target-features --target=$(RUSTC_TARGET)

monitor:
# Use gdb-multiarch to set up a debugging session for the hvisor ELF file.
# Set the architecture and connect to the remote target.
gdb-multiarch \
-ex 'file $(hvisor_elf)' \
-ex 'set arch $(GDB_ARCH)' \
-ex 'target remote:1234'

jlink-server:
# Start the JLinkGDBServer with specific options like selecting USB, JTAG interface, device, and port.
JLinkGDBServer -select USB -if JTAG -device Cortex-A53 -port 1234

cp: all
# Copy the hvisor binary file to the specified location (~/tftp).
cp $(hvisor_bin) ~/tftp

clean:
# Clean the build artifacts using cargo clean command.
cargo clean

ifeq ($(ARCH),loongarch64)
include scripts/3a5000-loongarch64.mk
else
include scripts/qemu-$(ARCH).mk
endif
Binary file removed images/aarch64/bootloader/u-boot-atf.bin
Binary file not shown.
Binary file removed images/aarch64/bootloader/u-boot.bin
Binary file not shown.
16 changes: 0 additions & 16 deletions images/aarch64/devicetree/Makefile

This file was deleted.

102 changes: 0 additions & 102 deletions images/aarch64/devicetree/imx8mp-ruxos.dts

This file was deleted.

Loading