Skip to content

Commit

Permalink
Bump new SDK and remove duplicate tests. Use SDK examples/tests inste…
Browse files Browse the repository at this point in the history
…ad (#201)

SDK has been largely refactored and restructured.
(1) KEYSTONE_SDK_DIR needs to point the "install directory" of SDK, not
the source directory
(2) We reuse the tests in sdk/examples/tests instead of duplicating
test enclaves. Now everything is configured and built with CMake

This consists of the following changes:
* Fix Travis to not set KEYSTONE_SDK_DIR
* Bump SDK that doesn't have Gtest as a requirement
* Fix CMake dependency
* Do not copy unnecessary packages
* Update documentation
  • Loading branch information
dayeol committed Aug 26, 2020
1 parent a2d7e02 commit 0a3116a
Show file tree
Hide file tree
Showing 55 changed files with 163 additions and 9,503 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ git:
depth: 1

env:
- RISCV=$TRAVIS_BUILD_DIR/riscv PATH=$PATH:$RISCV/bin KEYSTONE_SDK_DIR=$TRAVIS_BUILD_DIR/sdk
- RISCV=$TRAVIS_BUILD_DIR/riscv PATH=$PATH:$RISCV/bin

addons:
apt:
Expand Down
21 changes: 13 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ set(linux_vmlinux ${linux_wrkdir}/vmlinux)
set(linux_vmlinux_stripped ${linux_wrkdir}/vmlinux-stripped)
set(driver_srcdir ${CMAKE_SOURCE_DIR}/linux-keystone-driver)
set(driver_wrkdir ${CMAKE_BINARY_DIR}/linux-keystone-driver.build)
set(tests_srcdir ${CMAKE_SOURCE_DIR}/tests)
set(tests_wrkdir ${CMAKE_BINARY_DIR}/tests.build)
set(final_image ${CMAKE_BINARY_DIR}/bbl.bin)
set(initramfs_sysroot ${CMAKE_BINARY_DIR}/initramfs-sysroot)

Expand Down Expand Up @@ -261,16 +259,23 @@ add_custom_target("sm" ALL DEPENDS ${sm_wrkdir}/Makefile "linux" ${sm_patches} W
COMMENT "Building sm"
)

if(firesim)
add_patch("riscv-pk" "riscv-pk.firesim.patch" ${sm_srcdir} "sm")
elseif(sifive)
add_patch("riscv-pk" "riscv-pk.sifive.patch" ${sm_srcdir} "sm")
endif()

###############################################################################
## COMPONENT: tests
###############################################################################
set(example_wrkdir examples)
add_subdirectory(sdk/examples ${example_wrkdir})
set_target_properties(examples PROPERTIES EXCLUDE_FROM_ALL YES)

add_custom_command(OUTPUT ${tests_wrkdir} COMMAND mkdir -p ${tests_wrkdir})
add_custom_target("tests" DEPENDS ${tests_srcdir} ${tests_wrkdir}
COMMAND OUTPUT_DIR=${overlay_root} ARTIFACTS_DIR=${tests_wrkdir} ${tests_srcdir}/tests/vault.sh
COMMENT "Building tests"
)

add_custom_target("tests" DEPENDS examples ${overlay_root}
COMMAND find ${example_wrkdir} -name "tests.ke" | xargs -I{} rsync {} ${overlay_root}
COMMENT "Copying example enclave packages"
)

###############################################################################
## COMPONENT: image
Expand Down
2 changes: 0 additions & 2 deletions docs/source/Building-Components/Eyrie.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@ Example::

Will cleanly rebuild Eyrie with free memory management and libc-style
environment initialization.

An example of using the wrapper can be seen in :doc:`vault.sh<Vault>`.
72 changes: 0 additions & 72 deletions docs/source/Building-Components/Vault.rst

This file was deleted.

27 changes: 13 additions & 14 deletions docs/source/Getting-Started/QEMU-Compile-Sources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Build All Components (RV64)
We use `CMake <https://cmake.org/>`_ as a build system. It lets you generate the Makefile for a
given configuration.

``PATH`` must include the RISC-V tool path.
``PATH`` must include the RISC-V toolchain.

::

Expand Down Expand Up @@ -64,7 +64,7 @@ Thus, rebuilding QEMU may require ``make clean`` in ``qemu``.
Keystone requires patches for QEMU (1) to emulate the secure boot via on-chip bootrom and (2) to
apply not-yet-upstreamed bug fixes. All patches are located at ``patches/qemu/``

The following command will configure and build QEMU after applying the patches:
The following command will configure and build QEMU after applying the patches:

::

Expand All @@ -75,7 +75,7 @@ Build Linux Kernel
##############################################################

Kernel config files are located at ``conf/``. RV64 linux will use ``conf/linux-v5.0-defconfig-rv64``.
The following command will build the linux
The following command will build the linux

Keystone requires patches for the Linux kernel to reserve CMA region at boot.
The patch is located at ``patches/linux/``
Expand Down Expand Up @@ -104,25 +104,25 @@ Optionally, you can specify the target platform when you run ``cmake``.
make sm

The default platform is "default", which does not have any platform-specific features.
See ``riscv-pk/sm/platform/`` for available platforms.
See ``riscv-pk/sm/platform/`` for available platforms.
See :doc:`../Building-Components/Security-Monitor-Platform-Build` for details.

Build Root-of-Trust Boot ROM
##############################################################

This is used for secure boot. With our patch for QEMU, compiled boot code will be copied to the boot
ROM in QEMU.
ROM in QEMU.

::

# in your <build directory>
make bootrom

Build Keystone Driver (in-tree)
Build Keystone Driver
##############################################################

Linux module does not support in-tree build. Rebuilding the driver may require ``make clean`` in
``linux-keystone-driver``.
Linux module does not support in-tree build.
Thus, we ``rsync`` the entire source code directory with a build directory and build the driver there.

The following command will build the linux driver for Keystone.

Expand All @@ -131,24 +131,23 @@ The following command will build the linux driver for Keystone.
# in your <build directory>
make driver

Build Tests (in-tree)
Build Tests
##############################################################

The tests will be built in-tree. We will make it out-of-tree soon.
Rebuilding the tests may require ``make clean`` in ``tests/tests``.
The tests are a part of Keystone SDK's example enclaves.
Thus, we build them using ``sdk/examples/CMakeLists.txt``.

The following command will build the tests
The following command will build the tests and copy the package into the buildroot overlay directory.

::

# in your <build directory>
make tests


Updating Images
##############################################################

Once you have built every component, you may need to update the final images by running
Once you have built every component, you may need to update the final buildroot image by running

::

Expand Down
18 changes: 9 additions & 9 deletions docs/source/Getting-Started/QEMU-Run-Tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ If you wish to compile and run tests by your self, follow the following instruct
Build Test Binaries
#############################

Simple tests live under ``tests/tests``.
You can build the tests by executing ``tests/tests/vault.sh`` (See :doc:`../Building-Components/Vault`).
Note that ``KEYSTONE_SDK_DIR`` must be set to a built SDK path.
Test enclaves are a part of Keysonte SDK's examples.
You can build the tests by executing ``make tests``.
Note that ``KEYSTONE_SDK_DIR`` must be set to the install path of the SDK.

::

./tests/tests/vault.sh
make tests

This command will generate the enclave package named ``tests.ke`` in
``<build directory>/overlay`` directory.
This command will build the enclave package named ``tests.ke``
and copy it into ``<build directory>/overlay`` directory.

Build Disk Image
#############################
Expand Down Expand Up @@ -82,10 +82,10 @@ You can run the test enclaves by using a self-extracting keystone archive called

./tests.ke

In order to extract the package, run
In order to extract the package without execution, run

::

./tests.ke --target <dst>
./tests.ke --noexec --target <dst>

Run ``./tests.ke --help`` for more information.
Run ``./tests.ke --help`` for more information.
46 changes: 25 additions & 21 deletions docs/source/Getting-Started/QEMU-Setup-Repository.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,30 @@ If you want to compile RISC-V tools from source code, run
``./setup.sh`` instead. This may be necessary on some platforms due to
library issues.

To keep environment variables, add following lines to your ``.bashrc``.
The script also installs Keystone SDK if ``KEYSTONE_SDK_DIR`` environment variable is not set.
The default install directory of Keystone SDK is ``$(pwd)/sdk/build``.
If you want to change the install directory,
please follow `SDK's README <https://github.com/keystone-enclave/keystone-sdk/blob/master/README.md>`_
before running ``fast-setup.sh``.

If everything went well, you should see the following message:

::

export RISCV=<path/to/keystone>/riscv
export PATH=$PATH:$RISCV/bin
export KEYSTONE_SDK_DIR=<path/to/keystone>/sdk
RISC-V toolchain and Keystone SDK have been fully setup

You can also manually run ``source source.sh`` to set the environment variables.
After you run ``fast-setup.sh``, run the following command to set relevant environment variables:

::

source source.sh

To keep the environment variables, add the lines in ``source.sh`` to your shell's startup file.
For example, if you're using bash, then try:

::

cat source.sh >> $HOME/.bashrc

.. _QEMUSetupManual:

Expand Down Expand Up @@ -62,34 +77,23 @@ See `riscv-gnu-toolchain <https://github.com/riscv/riscv-gnu-toolchain>`_ for de
./configure --prefix=$(pwd)/../riscv
make; make linux

Install the Keystone SDK and prepare Eyrie runtime source code.
Install the Keystone SDK by following
`SDK's README <https://github.com/keystone-enclave/keystone-sdk/blob/master/README.md>`_.

::

cd sdk
mkdir build
cd build
cmake .. -DOUTPUT_DIR=$(pwd)/../lib
export KEYSTONE_SDK_DIR=<keystone/sdk/install/directory>
cmake ..
make
make install

Initialize the runtime (i.e., Eyrie) source code.

::

./sdk/scripts/init.sh

This initializes the runtime source code at ``./sdk/rts`` based on the version specified in
``./sdk/rts/eyrie.version``.

For more usage of the script, try the script with ``--help`` flag.

To keep environment variables, add following lines to your ``.bashrc``.

::

export RISCV=<path/to/keystone>/riscv
export PATH=$PATH:$RISCV/bin
export KEYSTONE_SDK_DIR=<path/to/keystone>/sdk
export KEYSTONE_SDK_DIR=<keystone/sdk/install/directory>

You can also manually run ``source source.sh`` to set the environment variables.

0 comments on commit 0a3116a

Please sign in to comment.