Skip to content

Commit

Permalink
Merge pull request #135 from keystone-enclave/dev-prepare-0.4
Browse files Browse the repository at this point in the history
Prepare for 0.4 release
  • Loading branch information
dayeol committed Dec 8, 2019
2 parents c35ff3e + 571ebe4 commit ab4e758
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 107 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@
[submodule "buildroot"]
path = buildroot
url = https://github.com/buildroot/buildroot.git
shallow = true
[submodule "linux"]
path = linux
url = https://github.com/torvalds/linux
shallow = true
[submodule "qemu"]
path = qemu
url = https://github.com/qemu/qemu
[submodule "riscv-linux"]
shallow = true
[submodule "riscv-qemu"]
shallow = true
99 changes: 75 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
cmake_minimum_required(VERSION 3.5)
project(keystone C)
include(ProcessorCount)
set(CMAKE_VERBOSE_MAKEFILE ON)

if(NOT DEFINED ENV{RISCV})
message(FATAL_ERROR "set RISCV environment variable")
endif()

if(NOT DEFINED platform)
set(platform "default")
endif()
message(STATUS "platform=${platform}")

if(Debug)
message(STATUS "debug")
set(CFLAGS -g)
Expand Down Expand Up @@ -48,15 +54,23 @@ set(tests_srcdir ${CMAKE_SOURCE_DIR}/tests)
set(final_image ${CMAKE_BINARY_DIR}/bbl.bin)
set(initramfs_sysroot ${CMAKE_BINARY_DIR}/initramfs-sysroot)

set(USE_RUST_SM FALSE CACHE BOOL "Use Rust version of the security monitor. WARNING: Applies globally.")
if (${USE_RUST_SM})
set(enabled_sm sm_rs)
else()
set(enabled_sm sm_c)
endif()

# QEMU
set(qemu_system ${qemu_wrkdir}/riscv${BITS}-softmmu/qemu-system-riscv${BITS})
add_custom_target("qemu" ALL DEPENDS ${qemu_system})
add_custom_command(OUTPUT ${qemu_system} COMMAND $(MAKE) -C ${qemu_srcdir} DEPENDS "qemu-config")
add_custom_command(OUTPUT ${qemu_system} COMMAND $(MAKE) -C ${qemu_srcdir} DEPENDS "qemu-config" COMMENT "Building QEMU")
add_custom_target("qemu-config" ALL DEPENDS ${qemu_srcdir} ${CMAKE_SOURCE_DIR}/patches/qemu
WORKING_DIRECTORY ${qemu_srcdir}
COMMAND patch --forward -p0 < ${patchdir}/qemu/qemu-pmp-bug.patch || true
COMMAND patch --forward -p0 < ${patchdir}/qemu/qemu-secure-boot.patch || true
COMMAND ./configure --target-list=riscv${BITS}-softmmu,riscv${BITS}-linux-user
COMMENT "Configuring QEMU"
)

# buildroot
Expand All @@ -65,6 +79,7 @@ add_custom_command(OUTPUT ${overlay_dir} COMMAND mkdir -p ${overlay_dir})
add_custom_command(OUTPUT ${buildroot_wrkdir} COMMAND mkdir -p ${buildroot_wrkdir})
add_custom_target("buildroot" ALL DEPENDS ${buildroot_srcdir} ${buildroot_wrkdir}/.config ${overlay_root} ${buildroot_wrkdir}
COMMAND $(MAKE) -s -C ${buildroot_srcdir} RISCV=$ENV{RISCV} PATH=$ENV{PATH} O=${buildroot_wrkdir}
COMMENT "Building buildroot"
)

string(REPLACE "/" "\\/" overlay_dir_stripped ${overlay_dir})
Expand All @@ -74,19 +89,23 @@ add_custom_command(DEPENDS ${buildroot_config} OUTPUT ${buildroot_wrkdir}/.confi
COMMAND sed \"s/^BR2_ROOTFS_OVERLAY=.*/BR2_ROOTFS_OVERLAY=\\\"${overlay_dir_stripped}\\\"/g\" -i ${buildroot_wrkdir}/.config
COMMAND $(MAKE) -s -C ${buildroot_srcdir} RISCV=$ENV{RISCV} PATH=$ENV{PATH}
O=${buildroot_wrkdir} CROSS_COMPILE=${cross_compile} olddefconfig
COMMENT "Configuring buildroot (overlay = ${overlay_dir})"
)

# boot ROM
add_custom_command(OUTPUT ${bootrom_wrkdir} COMMAND mkdir -p ${bootrom_wrkdir})
add_custom_target("bootrom" ALL
COMMAND $(MAKE) -C ${bootrom_srcdir} O=${bootrom_wrkdir}
DEPENDS ${bootrom_wrkdir} ${bootrom_srcdir})
DEPENDS ${bootrom_wrkdir} ${bootrom_srcdir}
COMMENT "Building bootrom"
)

# linux
add_custom_command(OUTPUT ${linux_wrkdir}/.config DEPENDS ${linux_defconfig}
COMMAND mkdir -p ${linux_wrkdir}
COMMAND cp ${linux_defconfig} ${linux_wrkdir}/.config
COMMAND $(MAKE) -C ${linux_srcdir} O=${linux_wrkdir} ARCH=riscv olddefconfig
COMMENT "Configuring linux"
)

if(initramfs)
Expand All @@ -108,13 +127,15 @@ if(initramfs)
CONFIG_DEVTMPFS=y CONFIG_DEVTMPFS_MOUNT=y
CROSS_COMPILE=${cross_compile} ARCH=riscv vmlinux
COMMAND ${cross_compile}strip -o ${linux_vmlinux_stripped} ${linux_vmlinux}
COMMENT "Building linux (initramfs)"
)
else()
add_custom_command(OUTPUT ${linux_wrkdir} COMMAND mkdir -p ${linux_wrkdir})
add_custom_target("linux" ALL DEPENDS ${linux_srcdir} ${linux_wrkdir}/.config
COMMAND cd ${linux_srcdir} \; patch --forward -p0 < ${patchdir}/linux/linux.patch || true
COMMAND $(MAKE) -C ${linux_srcdir} O=${linux_wrkdir} CROSS_COMPILE=${cross_compile} ARCH=riscv vmlinux
COMMAND ${cross_compile}strip -o ${linux_vmlinux_stripped} ${linux_vmlinux}
COMMENT "Building linux"
)
endif()

Expand All @@ -125,63 +146,93 @@ add_custom_target("driver" ALL DEPENDS ${driver_srcdir} ${linux_srcdir} ${linux_
M=${driver_srcdir} modules
COMMAND $(MAKE) -C ${linux_srcdir} O=${linux_wrkdir} CROSS_COMPILE=${cross_compile} ARCH=riscv
M=${driver_srcdir} modules_install INSTALL_MOD_PATH=${driver_wrkdir}
COMMENT "Building driver"
)

# bbl + sm
add_custom_command(OUTPUT ${sm_wrkdir} COMMAND mkdir -p ${sm_wrkdir})
add_custom_target("sm" ALL DEPENDS ${sm_srcdir} ${sm_wrkdir} ${linux_vmlinux_stripped} WORKING_DIRECTORY ${sm_wrkdir}
COMMAND ln -rsnf ${sm_srcdir}/${enabled_sm} ${sm_srcdir}/sm
COMMAND ${sm_srcdir}/configure --enable-sm --host=riscv${BITS}-unknown-linux-gnu --with-payload=${linux_vmlinux_stripped}
--enable-logo --with-logo=${confdir}/sifive_logo.txt --with-target-platform=default
--enable-logo --with-logo=${confdir}/sifive_logo.txt --with-target-platform=${platform}
CFLAGS=${CFLAGS}
COMMAND env CFLAGS='-g -mabi=${ABI} -march=${ISA}' $(MAKE) -C ${sm_wrkdir}
COMMENT "Building sm"
)
add_dependencies("sm" "linux")
add_dependencies("driver" "linux")

add_custom_target("tests" DEPENDS "driver" ${overlay_root} ${tests_srcdir}
COMMAND OUTPUT_DIR=${overlay_root} ${tests_srcdir}/tests/vault.sh
COMMAND find ${driver_wrkdir} -name "*.ko" -exec cp {} ${overlay_root} \\\\;
COMMENT "Building tests"
)

add_custom_target("image" DEPENDS "sm" "tests" ${buildroot_srcdir} ${buildroot_wrkdir}/.config ${overlay_root}
COMMAND $(MAKE) -s -C ${buildroot_srcdir} RISCV=$ENV{RISCV} PATH=$ENV{PATH} O=${buildroot_wrkdir}
COMMAND ${cross_compile}objcopy -S -O binary --change-addresses -0x80000000 ${sm_wrkdir}/bbl ${final_image}
COMMENT "Generating image"
)

# scripts
set(scripts ${CMAKE_BINARY_DIR}/scripts)
add_custom_command(OUTPUT ${scripts} COMMAND mkdir -p ${scripts})
add_custom_command(OUTPUT ${scripts}/run-qemu.sh
WORKING_DIRECTORY ${scripts}
COMMAND echo "\
${qemu_system} \
-m 2G \
-nographic \
-machine virt \
-bios ${bootrom_wrkdir}/bootrom.bin \
-kernel ${sm_wrkdir}/bbl \
-append \"console=ttyS0 ro root=/dev/vda\" \
-drive file=${buildroot_wrkdir}/images/rootfs.ext2,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::\$\{HOST_PORT\}-:22 \
-device virtio-net-device,netdev=net0" > run-qemu.sh
VERBATIM
COMMAND
chmod +x run-qemu.sh

if(initramfs)
add_custom_command(OUTPUT ${scripts}/run-qemu.sh
WORKING_DIRECTORY ${scripts}
COMMAND echo "\
export HOST_PORT=\${HOST_PORT:=\"\$((3000 + RANDOM % 3000))\"}; \
echo \"**** Running QEMU SSH on port \${HOST_PORT} ****\"; \
${qemu_system} \
-m 2G \
-nographic \
-machine virt \
-bios ${bootrom_wrkdir}/bootrom.bin \
-kernel ${sm_wrkdir}/bbl \
-netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::\$\{HOST_PORT\}-:22 \
-device virtio-net-device,netdev=net0" > run-qemu.sh
VERBATIM
COMMAND
chmod +x run-qemu.sh
)
add_custom_command(OUTPUT ${scripts}/test-qemu.sh DEPENDS ${CMAKE_SOURCE_DIR}/scripts
else()
add_custom_command(OUTPUT ${scripts}/run-qemu.sh DEPENDS ${scripts}
WORKING_DIRECTORY ${scripts}
COMMAND echo "\
export HOST_PORT=\${HOST_PORT:=\"\$((3000 + RANDOM % 3000))\"}; \
echo \"**** Running QEMU SSH on port \${HOST_PORT} ****\"; \
${qemu_system} \
-m 2G \
-nographic \
-machine virt \
-bios ${bootrom_wrkdir}/bootrom.bin \
-kernel ${sm_wrkdir}/bbl \
-append \"console=ttyS0 ro root=/dev/vda\" \
-drive file=${buildroot_wrkdir}/images/rootfs.ext2,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::\$\{HOST_PORT\}-:22 \
-device virtio-net-device,netdev=net0" > run-qemu.sh
VERBATIM
COMMAND
chmod +x run-qemu.sh
)
endif()
add_custom_command(OUTPUT ${scripts}/test-qemu.sh DEPENDS ${CMAKE_SOURCE_DIR}/scripts ${scripts}
COMMAND cp ${CMAKE_SOURCE_DIR}/scripts/test-qemu.sh ${scripts})
add_custom_command(OUTPUT ${scripts}/travis.sh DEPENDS ${CMAKE_SOURCE_DIR}/scripts
add_custom_command(OUTPUT ${scripts}/travis.sh DEPENDS ${CMAKE_SOURCE_DIR}/scripts ${scripts}
COMMAND cp ${CMAKE_SOURCE_DIR}/scripts/travis.sh ${scripts})

add_custom_target(
"all-scripts" ALL
"tools" ALL
DEPENDS ${scripts} ${scripts}/run-qemu.sh ${scripts}/test-qemu.sh ${scripts}/travis.sh
COMMENT "Generating scripts and tools"
)

add_custom_target(
"run-tests"
DEPENDS "all-scripts" "image"
DEPENDS "tools" "image"
COMMAND
./scripts/travis.sh ${CMAKE_SOURCE_DIR}/tests
COMMENT "Running tests"
)
2 changes: 1 addition & 1 deletion docs/source/Getting-Started/Install-Dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Ubuntu
gperf libgmp-dev libmpc-dev libmpfr-dev libtool texinfo tmux \
patchutils zlib1g-dev wget bzip2 patch vim-common lbzip2 python \
pkg-config libglib2.0-dev libpixman-1-dev libssl-dev screen \
device-tree-compiler expect makeself unzip cpio rsync
device-tree-compiler expect makeself unzip cpio rsync cmake

0 comments on commit ab4e758

Please sign in to comment.