Skip to content

Commit

Permalink
Merge pull request #53 from dkohlbre/dev-fix-hifive-qemu
Browse files Browse the repository at this point in the history
Fixed hifive qemu build to be possible, new run script for it
  • Loading branch information
dkohlbre committed Feb 26, 2019
2 parents 302e9ea + 11868b2 commit 0633f34
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 34 deletions.
10 changes: 0 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ before_install:
jobs:
include:
- stage: build everything & test
script:
- source ./source.sh
- travis_wait 120 make -j2
- travis_wait 10 ./scripts/travis.sh
- cd riscv-qemu; git clean -fxd;git reset --hard;rm -rf .git;mv ../riscv-qemu-git .git;cd ..
- cd riscv-linux;git clean -fxd;git reset --hard;rm -rf .git;mv ../riscv-linux-git .git;cd ..
after_failure:
- cat screenlog.0
- cat output.log
- stage: build hifive & test
script:
- source ./source.sh
- travis_wait 120 make -j2 hifive
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ QEMU=$(QEMU_DIR)/riscv64-softmmu/qemu-system-riscv64

NPROC=$(shell nproc)

all: $(BOOTROM) $(VMLINUX) $(SM) $(DISK) $(DRIVER) $(QEMU)
all: $(BOOTROM) $(VMLINUX) $(SM) $(DISK) $(DRIVER) $(QEMU) sdk
$(MAKE) -C $(SM_BUILD_DIR)
$(MAKE) -C $(SDK_DIR)
$(MAKE) -C $(SDK_DIR) copy-tests
$(MAKE) -C $(DRIVER_DIR) copy

qemu: all
./scripts/run-qemu.sh

hifive: hifive.mk
.PHONY: hifive
hifive: sdk $(QEMU) $(BOOTROM)
$(MAKE) -f hifive.mk
$(MAKE) -C hifive-work/buildroot_initramfs
$(MAKE) -f hifive.mk

.PHONY: sdk
sdk:
$(MAKE) -C $(SDK_DIR)

$(QEMU):
./scripts/apply-patch.sh
cd $(QEMU_DIR); ./configure --target-list=riscv64-softmmu,riscv32-softmmu;
Expand Down
2 changes: 1 addition & 1 deletion buildroot
2 changes: 2 additions & 0 deletions hifive-conf/buildroot_initramfs_config
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
BR2_riscv64=y
BR2_JLEVEL=2
BR2_ROOTFS_POST_BUILD_SCRIPT="board/keystone/br_copy_bins.sh"
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_PATH="$(RISCV)"
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="$(ARCH)-unknown-linux-gnu"
Expand Down
3 changes: 2 additions & 1 deletion hifive-conf/buildroot_rootfs_config
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
BR2_riscv64=y
BR2_JLEVEL=2
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_PATH="$(RISCV)"
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="$(ARCH)-unknown-linux-gnu"
BR2_TOOLCHAIN_EXTERNAL_GCC_7=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_6=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC=y
# BR2_TOOLCHAIN_EXTERNAL_INET_RPC is not set
BR2_TOOLCHAIN_EXTERNAL_INET_RPC=y
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV=y
BR2_TARGET_GENERIC_ROOT_PASSWD="sifive"
Expand Down
21 changes: 10 additions & 11 deletions hifive.mk
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ rootfs := $(wrkdir)/rootfs.bin
target := riscv64-unknown-linux-gnu

.PHONY: all
all: $(hex) $(linux_module)
all: $(hex) $(vmlinux) $(linux_module)
@echo
@echo "This image has been generated for an ISA of $(ISA) and an ABI of $(ABI)"
@echo "Find the image in hifive-work/bbl.bin, which should be written to a boot partition"
Expand All @@ -68,10 +68,10 @@ $(buildroot_initramfs_wrkdir)/.config: $(buildroot_srcdir)
rm -rf $(dir $@)
mkdir -p $(dir $@)
cp $(buildroot_initramfs_config) $@
$(MAKE) -C $< RISCV=$(RISCV) PATH=$(PATH) O=$(buildroot_initramfs_wrkdir) olddefconfig CROSS_COMPILE=riscv64-unknown-linux-gnu-
$(MAKE) -s -C $< RISCV=$(RISCV) PATH=$(PATH) O=$(buildroot_initramfs_wrkdir) olddefconfig CROSS_COMPILE=riscv64-unknown-linux-gnu-

$(buildroot_initramfs_tar): $(buildroot_srcdir) $(buildroot_initramfs_wrkdir)/.config $(RISCV)/bin/$(target)-gcc $(buildroot_initramfs_config)
$(MAKE) -C $< RISCV=$(RISCV) PATH=$(PATH) O=$(buildroot_initramfs_wrkdir)
$(MAKE) -s -C $< RISCV=$(RISCV) PATH=$(PATH) O=$(buildroot_initramfs_wrkdir)

.PHONY: buildroot_initramfs-menuconfig
buildroot_initramfs-menuconfig: $(buildroot_initramfs_wrkdir)/.config $(buildroot_srcdir)
Expand All @@ -83,10 +83,11 @@ $(buildroot_rootfs_wrkdir)/.config: $(buildroot_srcdir)
rm -rf $(dir $@)
mkdir -p $(dir $@)
cp $(buildroot_rootfs_config) $@
$(MAKE) -C $< RISCV=$(RISCV) PATH=$(PATH) O=$(buildroot_rootfs_wrkdir) olddefconfig
$(MAKE) -s -C $< RISCV=$(RISCV) PATH=$(PATH) O=$(buildroot_rootfs_wrkdir) olddefconfig

$(buildroot_rootfs_ext): $(buildroot_srcdir) $(buildroot_rootfs_wrkdir)/.config $(RISCV)/bin/$(target)-gcc $(buildroot_rootfs_config)
$(MAKE) -C $< RISCV=$(RISCV) PATH=$(PATH) O=$(buildroot_rootfs_wrkdir)
$(MAKE) -s -C $< RISCV=$(RISCV) PATH=$(PATH) O=$(buildroot_rootfs_wrkdir)


.PHONY: buildroot_rootfs-menuconfig
buildroot_rootfs-menuconfig: $(buildroot_rootfs_wrkdir)/.config $(buildroot_srcdir)
Expand Down Expand Up @@ -124,21 +125,19 @@ $(vmlinux): $(linux_srcdir) $(linux_wrkdir)/.config $(buildroot_initramfs_sysroo
ARCH=riscv \
vmlinux

$(vmlinux_stripped): $(vmlinux)
$(target)-strip -o $@ $<

$(linux_module): $(vmlinux)
rm -rf $(linux_module_wrkdir)
mkdir -p $(linux_module_wrkdir)
cp -r $(linux_module_srcdir)/* $(linux_module_wrkdir)
$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir)\
CONFIG_INITRAMFS_SOURCE="$(confdir)/initramfs.txt $(buildroot_initramfs_sysroot)" \
CONFIG_INITRAMFS_ROOT_UID=$(shell id -u) \
CONFIG_INITRAMFS_ROOT_GID=$(shell id -g) \
CROSS_COMPILE=riscv64-unknown-linux-gnu- \
ARCH=riscv \
M=$(linux_module_wrkdir) \
modules
cp $(linux_module) $(buildroot_initramfs_wrkdir)/target/root/

$(vmlinux_stripped): $(vmlinux)
$(target)-strip -o $@ $<

.PHONY: linux-menuconfig
linux-menuconfig: $(linux_wrkdir)/.config
Expand Down
16 changes: 16 additions & 0 deletions scripts/hifive-travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Launch QEMU test
screen -L -dmS qemu ./scripts/run-hifive-qemu.sh
sleep 10
./scripts/test-hifive-qemu.sh

diff output.log tests/test-hifive-qemu.expected.log
if [ $? -eq 0 ]
then
echo "[PASS] output.log matches with the expected output"
exit 0
else
echo "[FAIL] output.log does not match with the expected output"
exit 1
fi
10 changes: 10 additions & 0 deletions scripts/run-hifive-qemu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
./riscv-qemu/riscv64-softmmu/qemu-system-riscv64 \
-D debug.log \
-m 4G \
-bios bootrom/bootrom.elf \
-nographic \
-machine virt \
-kernel hifive-work/riscv-pk/bbl \
-netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::5555-:22 \
-device virtio-net-device,netdev=net0
18 changes: 11 additions & 7 deletions scripts/run-qemu.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env bash
./riscv-qemu/riscv64-softmmu/qemu-system-riscv64 -D debug.log -nographic -m 4G -machine virt\
-bios bootrom/bootrom.elf \
-kernel riscv-pk/build/bbl -append "root=/dev/vda ro console=ttyS0" \
-drive file=busybear-linux/busybear.bin,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::5555-:22 \
-device virtio-net-device,netdev=net0
./riscv-qemu/riscv64-softmmu/qemu-system-riscv64 \
-D debug.log \
-m 4G \
-bios bootrom/bootrom.elf \
-nographic \
-machine virt\
-kernel riscv-pk/build/bbl -append "root=/dev/vda ro console=ttyS0" \
-drive file=busybear-linux/busybear.bin,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::5555-:22 \
-device virtio-net-device,netdev=net0
15 changes: 15 additions & 0 deletions scripts/test-hifive-qemu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/expect

set timeout 60
spawn ssh -o "UserKnownHostsFile /dev/null" root@localhost -p 5555
expect "yes/no" {
send "yes\r"
expect "*?assword" { send "sifive\r" }
} "*?assword" { send "sifive\r" }

log_file -noappend output.log

expect "# " { send "insmod keystone-driver.ko\r" }
expect "# " { send "./test\r" }
expect "# " { send "poweroff\r" }
expect eof
2 changes: 1 addition & 1 deletion sdk
Submodule sdk updated 5 files
+17 −14 Makefile
+8 −8 lib/Makefile
+1 −1 runtime
+2 −2 samples/Makefile
+2 −2 tests/Makefile
19 changes: 19 additions & 0 deletions tests/test-hifive-qemu.expected.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# insmod keystone-driver.ko
# ./test
testing stack
testing fibonacci
testing long-nop
testing loop
testing malloc
testing fib-bench
testing untrusted
Enclave said: hello world!
Enclave said: 2nd hello world!
Enclave said value: 13
Enclave said value: 20
testing attestation
Attestation report SIGNATURE is valid
# poweroff
# Connection to localhost closed by remote host.
Connection to localhost closed.
Expand Down

0 comments on commit 0633f34

Please sign in to comment.