Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
tags

*.d
*.o
*.dump
*.swp

source.sh

build
95 changes: 88 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,90 @@
all:
make -C musl
make -C lib
make -C demo
SDK_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

# Prefix for compiler to
# build enclave applications
CROSS_COMPILE ?= riscv64-unknown-elf-

# prefix for compiler to
# build host applications
CROSS_COMPILE_HOST ?= riscv64-unknown-linux-gnu-

# Now we assume that host applications
# and enclave applications share
# the same ARCH and ABI
RISCV_ARCH ?= rv64imac
RISCV_ABI ?= lp64

# All intermeidate files will
# be placed under OUT_DIR
OUT_DIR ?= $(SDK_DIR)/build

PENGLAI_SDK ?= $(OUT_DIR)/output

# All generated SDK files will
# be placed under INSTALL_DIR
INSTALL_DIR := $(PENGLAI_SDK)

# define CROSS_COMPILE toolchains and HOST toolchains
include mk/compile.mk

LIBS := app host
PREBUILD_LIBS := musl

# Define build scripts in SDK_BUILD_SCRIPTS that are
# required in the generated SDK
SDK_BUILD_SCRIPTS := mk/app.mk mk/host_app.mk mk/compile.mk mk/app.lds

.PHONY: all prebuild build install demo clean

all: build

# Updated when processing sub.mk
# defined under each library
TARGET_LIBS :=

# Updated by $(call add_prebuild_target,...)
PREBUILD_TARGETS :=

# Updated when processing sub.mk
# defined under each library,
# by including install_lib.mk
INSTALL_LIBS :=
INSTALL_HEADERS :=

# Updated by $(call install_buid_script,...)
INSTALL_BUILD_SCRIPTS :=

CLEAN_OBJS :=

# define prebuild recipe for each
# prebuild library
$(foreach lib,$(PREBUILD_LIBS),\
$(eval $(call add_prebuild_target,$(lib),PREBUILD_TARGETS)))

# include all lib/sub.mk, include prebuild libraries
include $(addprefix lib/,$(addsuffix /sub.mk, $(LIBS) $(PREBUILD_LIBS)))

$(foreach f,$(SDK_BUILD_SCRIPTS),\
$(eval $(call install_build_script,$(SDK_DIR)/$(f),$(INSTALL_DIR)/mk,INSTALL_BUILD_SCRIPTS)))

# Pre-building all libraries before
# generating SDK, shall be
# called at least once before calling
# `make` / `make install`
prebuild: $(PREBUILD_TARGETS)

build: $(TARGET_LIBS)

install: $(INSTALL_LIBS) $(INSTALL_HEADERS) $(INSTALL_BUILD_SCRIPTS)

demo: install
$(q)make PENGLAI_SDK=$(PENGLAI_SDK) -C demo

clean:
make -C musl clean
make -C lib clean
make -C demo clean
@echo ' CLEAN .'
$(q)rm -f $(CLEAN_OBJS)

# remove installed libs/headers
cleanclean: clean
@echo ' CLEAN INSTALL .'
$(q)rm -f $(INSTALL_LIBS) $(INSTALL_HEADERS) $(INSTALL_BUILD_SCRIPTS)
127 changes: 123 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,135 @@ This is the SDK for Penglai TEE (sPMP and PMP version).
If you are seeking for SDK for Penglai-TVM,
please refer [Penglai-SDK-TVM](https://github.com/Penglai-Enclave/Penglai-sdk-TVM)

This repo contains SDK to write host-side applications and enclave-apps, as well as some demos.
This repo contains SDK to build host-side apps and enclave apps, as well as some demos.

## Quick Start
## Build SDK

[Penglai (PMP)](https://github.com/Penglai-Enclave/Penglai-Enclave-sPMP) provides the instructions and scripts to build and run SDK demos.
SDK needs to be built from sources firstly, with the following commands.

```
# Specify cross compiler toolchain for enclave app and host app.
# riscv64-unknown-elf- is used for enclave app, and
# riscv64-unknown-linux-gnu- for host-side app, by default
export CROSS_COMPILE=<prefix_of_enclave_app_cross_compiler_toolchain>
export CROSS_COMPILE_HOST=<prefix_of_host_app_cross_compiler_toolchain>

# Specifiy architecture of target board,
# 'rv64imac' by default
export RISCV_ARCH=<arch_of_target_board>

# Specifiy abi of target board,
# 'lp64' by default
export RISCV_ABI=<abi_of_target_board>

# Pre-build all the required components for this SDK, i.e, musl.
# prebuild only needs to run once
make prebuild

# SDK is built under <repo_path>/build, by default
export OUT_DIR=/path/to/build

# SDK is installed under <repo_path>/build/output, by default
export PENGLAI_SDK=/path/to/to/penglai_sdk

make install
```

If needs to clean/rebuild SDK,

```
# clean build output of SDK
make clean

# clean installed files/headers
# under PENGLAI_SDK
make cleanclean

```

## Demos

The demo/ directory provides several example enclave applications, e.g., prime.
The demo/ directory contains example enclave/host apps.
You need to build and install SDK first before building demo apps.

```
# Build demo with SDK specified with PENGLAI_SDK
make demo
```

After Penglai is deployed on the target device,
you can run the demo with the following commands,
where the `enclave_app_file_name` is the file name
of enclave app, i.e, prime.

```
./host <enclave_app_file_name>
```

The `host` is a host app also included in the demo.
It's an enclave invoker that starts an enclave with the
corresponding enclave app ELF.

## How to build an enclave/a host app?

The SDK includes build scripts that could
help with building enclave app and host app.

To build an enclave/host app, the following variables
need to be defined,
```

# APP: name of the generated ELF
APP :=

# CFLAGS: compile flags for all the
# sources of this enclave
CFLAGS :=

# If needs to specify compile flags only for
# certain sources, defined variable <file_name>_CFLAGS,
# .i.e, main.c_CFLAGS
<file_name>_CFLAGS :=

# LDFLAGS: linking flags for
# this enclave app
LDFLAGS :=

# APP_C_SRCS .c sources of this enclave
APP_C_SRCS :=

# APP_A_SRCS .S sources of this enclave
APP_A_SRCS :=

# linker script for this app
# If not specified, use <sdk>/mk/app.lds by default
#
# This variable is not used for the
# building of host app
APP_LDS :=

```

`<sdk_path>/mk/app.mk` needs to be included
after defining the variables above when building
an enclave app, and similarly,
`<sdk_path>/mk/host_app.mk>` for a host app.

You could refer to build scripts in demo as examples.

Just as building the SDK, one should also define environment variables,
`PENGLAI_SDK`, `CROSS_COMPILE`, `CROSS_COMPILE_HOST`,
`RISCV_ARCH`, `RISCV_ABI` when building host apps and enclave apps.

`PENGLAI_SDK` must be specified.

The default values of `CROSS_COMPILE`, `CROSS_COMPILE_HOST`,
`RISCV_ARCH` and `RISCV_ABI` are the same with that when
building the SDK.

Developers could define 'O' as the output directory.
The default value of output directory is
current directory.

## Licenses

Expand Down
34 changes: 0 additions & 34 deletions app.mk

This file was deleted.

8 changes: 4 additions & 4 deletions demo/aes/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP = aes
APP_C_SRCS = aes.c
EXTRA_CLEAN = $(APP).dump
include $(PENGLAI_SDK)/app.mk
APP := aes
APP_C_SRCS := aes.c

include $(PENGLAI_SDK)/mk/app.mk
3 changes: 1 addition & 2 deletions demo/count/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
APP = count
APP_C_SRCS = count.c
EXTRA_CLEAN = $(APP).dump
include $(PENGLAI_SDK)/app.mk
include $(PENGLAI_SDK)/mk/app.mk
3 changes: 1 addition & 2 deletions demo/crypt/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
APP = crypt
APP_C_SRCS = crypt.c
EXTRA_CLEAN = $(APP).dump
include $(PENGLAI_SDK)/app.mk
include $(PENGLAI_SDK)/mk/app.mk
3 changes: 1 addition & 2 deletions demo/deadloop/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
APP = deadloop
APP_C_SRCS = deadloop.c
EXTRA_CLEAN = $(APP).dump
include $(PENGLAI_SDK)/app.mk
include $(PENGLAI_SDK)/mk/app.mk
12 changes: 5 additions & 7 deletions demo/host/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
CC=riscv64-unknown-linux-gnu-gcc
APP := host
APP_C_SRCS := host.c

HOST=host
CFLAGS := -static -pthread
LDFLAGS := -lpthread

all:
$(CC) -o $(HOST) -static -I $(PENGLAI_SDK)/lib/host/include/ host.c $(PENGLAI_SDK)/lib/libpenglai-enclave-host.a -lpthread

clean:
rm -f *.o $(HOST)
include $(PENGLAI_SDK)/mk/host_app.mk
12 changes: 5 additions & 7 deletions demo/host_stop_and_destroy/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
CC=riscv64-unknown-linux-gnu-gcc
APP := host
APP_C_SRCS := host.c

HOST=host
CFLAGS := -static -pthread
LDFLAGS := -lpthread

all:
$(CC) -o $(HOST) -static -I $(PENGLAI_SDK)/lib/host/include/ host.c $(PENGLAI_SDK)/lib/libpenglai-enclave-host.a -lpthread

clean:
rm -f *.o $(HOST)
include $(PENGLAI_SDK)/mk/host_app.mk
3 changes: 1 addition & 2 deletions demo/mem/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
APP = mem
APP_C_SRCS = mem.c
EXTRA_CLEAN = $(APP).dump
include $(PENGLAI_SDK)/app.mk
include $(PENGLAI_SDK)/mk/app.mk
8 changes: 4 additions & 4 deletions demo/prime/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP = prime
APP_C_SRCS = prime.c
EXTRA_CLEAN = $(APP).dump
include $(PENGLAI_SDK)/app.mk
APP := prime
APP_C_SRCS := prime.c

include $(PENGLAI_SDK)/mk/app.mk
Loading