Skip to content

Commit

Permalink
Merge pull request #193 from keystone-enclave/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dayeol authored Aug 31, 2020
2 parents be61c6e + c5cdc6b commit 21c7718
Show file tree
Hide file tree
Showing 61 changed files with 369 additions and 9,315 deletions.
12 changes: 11 additions & 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 Expand Up @@ -93,3 +93,13 @@ jobs:
after_failure:
- cat screenlog.0
- cat output.log
- stage: build (sifive)
script:
- source ./source.sh
- mkdir build
- cd build
- cmake -DLINUX_SIFIVE=y -DSM_PLATFORM=fu540 ../
- travis_wait 120 make -j3
- cd ..
- cd qemu; git clean -fxd > /dev/null;git reset --hard > /dev/null;rm -rf .git;mv ../qemu-git .git;cd ..
- cd linux;git clean -fxd > /dev/null;git reset --hard > /dev/null;rm -rf .git;mv ../linux-git .git;cd ..
49 changes: 30 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ endif()

set(linux_srcdir ${CMAKE_SOURCE_DIR}/linux)
mkdir(linux_wrkdir ${CMAKE_BINARY_DIR}/linux.build)
set(linux_symvers ${linux_wrkdir}/Modules.symvers)
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 @@ -164,14 +163,15 @@ add_custom_target("bootrom" ALL


###############################################################################
## COMPONENT: linux kernel
## COMPONENT: linux kernel
###############################################################################

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

if(firesim)
add_patch("linux" "linux${BITS}.firesim.patch" ${linux_srcdir} linux_patches)
Expand All @@ -193,7 +193,7 @@ if(initramfs)
COMMAND tar -xpf ${buildroot_wrkdir}/images/rootfs.tar -C ${initramfs_sysroot} --exclude ./dev --exclude ./usr/share/locale
COMMAND echo "::sysinit:/bin/mount -t devtmpfs devtmpfs /dev" >> ${initramfs_sysroot}/etc/inittab
)
add_custom_command(OUTPUT ${linux_vmlinux_stripped} ${linux_vmlinux} DEPENDS "sysroot" ${linux_srcdir} ${linux_wrkdir}/.config ${linux_patches}
add_custom_command(OUTPUT ${linux_vmlinux_stripped} ${linux_vmlinux} DEPENDS "sysroot" ${linux_srcdir} "linux-symvers"
COMMAND $(MAKE) -C ${linux_srcdir}
O=${linux_wrkdir} CONFIG_INITRAMFS_SOURCE="${confdir}/initramfs.txt ${initramfs_sysroot}"
CONFIG_INITRAMFS_ROOT_UID=${uid} CONFIG_INITRAMFS_ROOT_GID=${gid}
Expand All @@ -203,23 +203,29 @@ if(initramfs)
COMMENT "Building linux (initramfs)"
)
else()
add_custom_command(OUTPUT ${linux_vmlinux_stripped} ${linux_vmlinux} DEPENDS ${linux_srcdir} ${linux_wrkdir}/.config ${linux_patches}
add_custom_command(OUTPUT ${linux_vmlinux_stripped} ${linux_vmlinux} DEPENDS ${linux_srcdir} "linux-symvers"
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()

add_custom_command(OUTPUT ${linux_symvers} DEPENDS ${linux_srcdir} "linux-config" ${linux_patches}
COMMAND $(MAKE) -C ${linux_srcdir} O=${linux_wrkdir} CROSS_COMPILE=${cross_compile} ARCH=riscv modules
COMMENT "Building linux symvers"
)
add_custom_target("linux-symvers" DEPENDS ${linux_symvers})
add_custom_target("linux" ALL DEPENDS ${linux_vmlinux_stripped} ${linux_vmlinux})


###############################################################################
## COMPONENT: linux driver
###############################################################################

add_custom_command(OUTPUT ${driver_wrkdir} COMMAND mkdir -p ${driver_wrkdir})
add_custom_target("driver-sync" DEPENDS ${driver_srcdir} ${driver_wrkdir}
COMMAND rsync -r ${driver_srcdir}/ ${driver_wrkdir})
add_custom_target("driver" ALL DEPENDS ${driver_srcdir} ${linux_srcdir} "linux" "driver-sync"
add_custom_target("driver" ALL DEPENDS ${driver_srcdir} ${linux_srcdir} "linux-symvers" "driver-sync"
COMMAND $(MAKE) -C ${linux_wrkdir} O=${linux_wrkdir} CROSS_COMPILE=${cross_compile} ARCH=riscv
M=${driver_wrkdir} modules
COMMENT "Building driver"
Expand All @@ -236,13 +242,19 @@ else()
set(enabled_sm --enable-sm)
endif()

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

add_custom_command(OUTPUT ${sm_wrkdir}/Makefile WORKING_DIRECTORY ${sm_wrkdir}
DEPENDS ${sm_wrkdir_exists} "linux"
DEPENDS ${sm_wrkdir_exists}
COMMAND ${sm_srcdir}/configure --host=riscv${BITS}-unknown-linux-gnu --with-payload=${linux_vmlinux_stripped}
--enable-logo --with-logo=${confdir}/sifive_logo.txt ${enabled_sm} ${SM_CONFIGURE_ARGS} --with-target-platform=${platform}
COMMENT "Configuring sm"
)
add_custom_target("sm" ALL DEPENDS ${sm_wrkdir}/Makefile WORKING_DIRECTORY ${sm_wrkdir}
add_custom_target("sm" ALL DEPENDS ${sm_wrkdir}/Makefile "linux" ${sm_patches} WORKING_DIRECTORY ${sm_wrkdir}
COMMAND env CFLAGS='${CFLAGS} -mabi=${ABI} -march=${ISA}' $(MAKE) -C ${sm_wrkdir}
COMMENT "Building sm"
)
Expand All @@ -253,26 +265,26 @@ 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
###############################################################################

add_custom_target("image-deps" DEPENDS "sm" "tests" "driver"
add_custom_target("image-deps" DEPENDS "tests" "driver"
COMMAND find ${driver_wrkdir} -name "*.ko" -exec cp {} ${overlay_root} \\\\;
)
add_custom_target("image" DEPENDS "buildroot"
add_custom_target("image" DEPENDS "buildroot" "sm"
COMMAND ${cross_compile}objcopy -S -O binary --change-addresses -0x80000000 ${sm_wrkdir}/bbl ${final_image}
COMMENT "Generating image"
)
Expand All @@ -283,7 +295,6 @@ add_dependencies("buildroot" "image-deps")
## QEMU scripts
###############################################################################

# scripts
set(scripts ${CMAKE_BINARY_DIR}/scripts)
add_custom_command(OUTPUT ${scripts} COMMAND mkdir -p ${scripts})

Expand All @@ -305,7 +316,7 @@ add_custom_command(OUTPUT ${scripts}/run-qemu.sh DEPENDS ${scripts}
export HOST_PORT=\${HOST_PORT:=\"\$((3000 + RANDOM % 3000))\"}; \
echo \"**** Running QEMU SSH on port \${HOST_PORT} ****\"; \
export SMP=1; \
while [ \"\$1\" != \"\" ]; do if [ \"\$1\" = \"-debug\" ]; then DEBUG=\"-gdb tcp::\$((HOST_PORT + 1)) -S -d in_asm -D debug.log\"; fi; if [ \"\$1\" = \"-smp\" ]; then SMP=\"\$2\"; shift; fi; shift; done; \
while [ \"\$1\" != \"\" ]; do if [ \"\$1\" = \"-debug\" ]; then echo \"**** GDB port \$((HOST_PORT + 1)) ****\"; DEBUG=\"-gdb tcp::\$((HOST_PORT + 1)) -S -d in_asm -D debug.log\"; fi; if [ \"\$1\" = \"-smp\" ]; then SMP=\"\$2\"; shift; fi; shift; done; \
${qemu_system} \
\$DEBUG \
-m 2G \
Expand Down
4 changes: 2 additions & 2 deletions KEYSTONE-FPGA.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Git clone and checkout the SiFive freedom:
```sh
$ git clone https://github.com/sifive/freedom.git
$ cd freedom/
$ git checkout 37207f100227f4c34994db067b5fea3e383299ce0
$ git checkout 37207f100227f4c34994db067b5fea3e383299ce
$ git submodule update --init --recursive
```

Expand Down Expand Up @@ -184,7 +184,7 @@ $ export PATH=${PATH}:/opt/Xilinx/Vivado/2016.4/bin:${RISCV}/bin

From the top folder of freedom:

This is for generate the verilog file:
This is for generate the verilog file:
```sh
$ make BOOTROM_DIR=`pwd`/bootrom/freedom-u540-c000-bootloader -f Makefile.vc707-u500devkit verilog -j`nproc`
```
Expand Down
27 changes: 27 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ubuntu:18.04
ARG CHECKOUT=master
RUN apt update

RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata

RUN apt -y install autoconf automake autotools-dev bc \
bison build-essential curl expat libexpat1-dev flex gawk gcc git \
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 cmake

RUN git clone https://github.com/keystone-enclave/keystone /keystone
RUN cd /keystone && \
git checkout $CHECKOUT && \
rmdir linux qemu buildroot && \
./fast-setup.sh && \
. ./source.sh && \
rm -rf firesim-riscv-tools-prebuilt-* && \
rm -f 2.0.tar.gz && \
mkdir -p build && \
cd build && \
cmake .. && \
make -j$(nproc)

ENTRYPOINT cd /keystone && . ./source.sh && cd /keystone/build && make run-tests
17 changes: 17 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Building Docker Image

To build the image with master branch:
```bash
docker build -t keystoneenclaveorg/keystone:master
```

dev branch:

```bash
docker build -t keystoneenclaveorg/keystone:dev --build-arg CHECKOUT=dev .
```

any other branches or tags:
```bash
docker build -t keystoneenclaveorg/keystone:<tag> --build-arg CHECKOUT=<tag> .
```
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.

4 changes: 2 additions & 2 deletions docs/source/Getting-Started/How-to-Debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ If you want to debug with the kernel's debug information
riscv64-unknown-linux-gnu-gdb ./riscv-linux/vmlinux
```

Then, attach to QEMU:
Then, attach to QEMU on the port printed by the starting qemu script:

```bash
(gdb) target remote localhost:1234
(gdb) target remote localhost:$PORT
```

Now, you can start debugging the SM (bbl) or the kernel.
Expand Down
Loading

0 comments on commit 21c7718

Please sign in to comment.