From a201c08fa8df439cb2488ae74c755157304af97d Mon Sep 17 00:00:00 2001 From: ZhaoXi Date: Thu, 28 Sep 2023 15:36:31 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=93=83=20docs(README=20=20=20build=5F?= =?UTF-8?q?opensbi.sh=20=20=20=20run=5Fopeneuler.sh):=20Modify=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modify README to support opensbi0.9/1.0/1.2 and openeuler 20-23 --- .gitmodules | 3 ++ README.md | 82 +++++++++++++++++++++++++++---- run_openeuler.sh | 102 +++++++++++++++++++++++++++++++++++++-- scripts/build_opensbi.sh | 64 +++++++++++++++++++++++- u-boot | 1 + 5 files changed, 238 insertions(+), 14 deletions(-) create mode 160000 u-boot diff --git a/.gitmodules b/.gitmodules index fa53b5a23..3c580c2f8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "riscv-qemu"] path = riscv-qemu url = https://github.com/Penglai-Enclave/penglai-qemu.git +[submodule "u-boot"] + path = u-boot + url = git@github.com:Fly0307/u-boot.git diff --git a/README.md b/README.md index 9de5fd7ab..b433f4b36 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,17 @@ Therefore, the only requirement to build and run penglai-demo is: - [Docker](https://docs.docker.com): for building/running Penglai - Git: for downloading the code -- Qemu for RISC-V (RV64): suggested version >= 5.2.0. You can download the qemu [here](https://www.qemu.org/) and follow the [instructions](https://wiki.qemu.org/Documentation/Platforms/RISCV) to build and install qemu. +- Qemu for RISC-V (RV64): suggested version >= 5.2.0. You can download the qemu [here](https://www.qemu.org/) and follow the [instructions](https://wiki.qemu.org/Documentation/Platforms/RISCV) to build and install qemu.For openEuler version 2303, we tests using qemu-8.0. + +### Build uboot + +Follow the instructions in openeuler riscv gitee to compile uboot for OE-23.X. + +``` +cd ./u-boot +make qemu-riscv64_defconfig +make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- -j$(nproc) +``` ### Build openEuler Kernel @@ -50,7 +60,10 @@ For example, download the OKL-5.10 in current directory, and compile with pengla # In the docker image ./scripts/build_euler_kernel.sh +Note:The kernel image needs to be compiled only when openeuler version is less than 23 + ### Build OpenSBI (with Penglai supports) +For openEuler version < 23: docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --rm -it ddnirvana/penglai-enclave:v0.5 bash # In the docker image @@ -60,17 +73,29 @@ For example, download the OKL-5.10 in current directory, and compile with pengla Note: the /home/penglai/penglai-enclave/Image is the image compiled openEuler Kernel Image. +For openEuler version >= 23: + +``` +docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --rm -it ddnirvana/penglai-enclave:v0.5 bash +cd ../Penglai-Enclave-sPMP/opensbi-1.2 +rm -rf build-oe/qemu-virt +mkdir -p build-oe/qemu-virt +CROSS_COMPILE=riscv64-unknown-linux-gnu- make O=build-oe/qemu-virt PLATFORM=generic FW_PAYLOAD=y FW_PAYLOAD_PATH=../Penglai-Enclave-sPMP/u-boot.bin -j$(nproc) +``` + A simpler way: - ./docker_cmd.sh docker - #In the docker image - ./scripts/build_opensbi.sh +``` +./docker_cmd.sh docker +#In the docker image,build opensbi 1.2 for OE20.03 +./scripts/build_opensbi.sh -v 1.2 -k 2003 +``` -**Note**: if you use the simpler way, please **copy** your latest kernel image to the root dir of the repo. +**Note**: if you use the simpler way, please **copy** your latest kernel *Image* file to the root dir of the repo. ### Build Penglai SDK -Following the commands to build enclave driver: +When openeuler version is less than 23,following the commands to build enclave driver: ./docker_cmd.sh docker # In the docker image @@ -78,7 +103,28 @@ Following the commands to build enclave driver: It will generate penglai.ko in the penglai-enclave-driver dir. -Following the commnads to build user-level sdk and demos: +**Note:When openEuler version is >= 23,you need to start openEuler in qemu After starting the VM as the next step *Run openEuler with Penglai Supports* before compiling penglai-driver.** + +For openEuler version greater than 23, get the source code in the qemu VM and execute compile kernel moudle: + +``` +#in VM +cd ~/ +sudo dnf install -y kernel-devel kernel-source +``` + +The kernel source code will be downloaded locally,the path is `/usr/lib/modules/6.1.19-2.oe2303.riscv64`. + +Copy penglai-enclave-driver to the root/ directory of the oe VM. Go to the penglai-enclave-driver directory and modify the original kernel source path openeuler-kernel in the Makefile to `/usr/lib/modules/6.1.19-2.oe2303.riscv64/build/`. Compile and install the kernel module: + +``` +cd penglai-enclave-driver +vim Makefile #modify source path +make -j$(nproc) +insmod penglai.ko +``` + +When penglai.ko is completed,following the commnads to build user-level sdk and demos: # Fetch the sdk submodule git submodule update --init --recursive @@ -90,8 +136,19 @@ Following the commnads to build user-level sdk and demos: ### Run openEuler with Penglai Supports -You should download the disk image of openEuler (i.e., openEuler-preview.riscv64.qcow2) from [here](https://repo.openeuler.org/openEuler-preview/RISC-V/Image/) +You should download the disk image of openEuler (i.e., openEuler-preview.riscv64.qcow2) and raname image file to openEuler-xxxx-qemu-riscv64.qcow2. + +You can download OE 2303 from [openEuler-23.03-V1-riscv64](https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/preview/openEuler-23.03-V1-riscv64/QEMU/)(i.e., openEuler-23.03-V1-base-qemu-preview.qcow2)or download [openEuler 20.03](http://pan.sjtu.edu.cn/web/share/6ec2212dcc10ac97345e9db1cb7595e9). +``` +wget https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/preview/openEuler-23.03-V1-riscv64/QEMU/openEuler-23.03-V1-base-qemu-preview.qcow2.zst +unzstd openEuler-23.03-V1-base-qemu-preview.qcow2.zst +mv openEuler-23.03-V1-base-qemu-preview.qcow2 openEuler-2303-qemu-riscv64.qcow2 +``` + +Run VM in QEMU: + + # For openEuler version is 20.03 qemu-system-riscv64 -nographic -machine virt \ -smp 4 -m 2G \ -kernel ./opensbi-0.9/build-oe/qemu-virt/platform/generic/firmware/fw_payload.elf \ @@ -112,9 +169,17 @@ You should download the disk image of openEuler (i.e., openEuler-preview.riscv64 Note: a script, run_openeuler.sh is provided to execute the above command easily +``` +#when openEuler version less than 23,eg 2003 +./run_openeuler.sh -k 2003 -o 1.2 +#when openEuler version is greater than or equal 23,eg 2303 +./run_openeuler.sh -k 2303 -o 1.2 +``` If everything is fine, you will enter a Linux terminal booted by Qemu with Penglai-installed. +### RUN demo + **Copy files to openEuler Qemu** You can copy any files to the VM using *scp*. @@ -187,4 +252,3 @@ We thank all of our collaborators (companies, organizations, and communities). ## Acknowledgements The design of Penglai was inspired by Sanctum, Keystone and HexFive, thanks to their great work! - diff --git a/run_openeuler.sh b/run_openeuler.sh index 6db3904e9..4c719b71c 100755 --- a/run_openeuler.sh +++ b/run_openeuler.sh @@ -1,8 +1,79 @@ #!/bin/bash -qemu-system-riscv64 -nographic -machine virt \ - -smp 1 -m 2G \ - -kernel ./opensbi-0.9/build-oe/qemu-virt/platform/generic/firmware/fw_payload.elf \ - -drive file=openEuler-preview.riscv64.qcow2,format=qcow2,id=hd0 \ + +kernel_version=2003 +opensbi_version=1.2 + +function print_usage() { + RED='\033[0;31m' + BLUE='\033[0;34m' + BOLD='\033[1m' + NONE='\033[0m' + + echo -e "\n${RED}Usage${NONE}: + .${BOLD}/run_openeuler.sh${NONE} [OPTION]" + + echo -e "\n${RED}OPTIONS${NONE}: + ${BLUE}-k${NONE}: Select the openeuler version,default use openEuler2003 + ${BLUE}-o${NONE}: Select the opensbi version,default use opensbi-1.2 + " + echo -e "\n${RED}EXAMPLE${NONE}: + ${BLUE}./run_openeuler.sh -k 2003 -o 1.2${NONE}" +} + +if [[ $1 == *"help"* ]]; then + print_usage + exit 0 +fi + +while getopts ":k:o:" opt; do + case $opt in + k) + kernel_version=$OPTARG + ;; + o) + opensbi_version=$OPTARG + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + print_usage + exit 1 + ;; + esac +done + +if (($kernel_version == 2003)) +then + imagepath=openEuler-2003-qemu-riscv64.qcow2 +elif (($kernel_version == 2303)) +then + imagepath=openEuler-2303-qemu-riscv64.qcow2 +else + echo "Invalid kernel version: $kernel_version" >&2 + print_usage + exit 1 +fi + +if [ $(echo "$opensbi_version == 0.9" | bc -l) -eq 1 ] +then + opensbi_path=opensbi-0.9 +elif [ $(echo "$opensbi_version == 1.0" | bc -l) -eq 1 ] +then + opensbi_path=opensbi-1.0 +elif [ $(echo "$opensbi_version == 1.2" | bc -l) -eq 1 ] +then + opensbi_path=opensbi-1.2 +else + echo "Invalid opensbi version: $opensbi_version" >&2 + print_usage + exit 1 +fi + + +function run_qemu_1(){ + qemu-system-riscv64 -nographic -machine virt \ + -smp 4 -m 2G \ + -kernel ./${2}/build-oe/qemu-virt/platform/generic/firmware/fw_payload.elf \ + -drive file=${1},format=qcow2,id=hd0 \ -object rng-random,filename=/dev/urandom,id=rng0 \ -device virtio-rng-device,rng=rng0 \ -device virtio-blk-device,drive=hd0 \ @@ -10,6 +81,29 @@ qemu-system-riscv64 -nographic -machine virt \ -netdev user,id=usernet,hostfwd=tcp::12055-:22 \ -append 'root=/dev/vda1 rw console=ttyS0 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem=4096M earlycon' \ -bios none +} + +function run_qemu_2(){ + qemu-system-riscv64 -nographic -machine virt \ + -smp 4 -m 2G \ + -bios ./${2}/build-oe/qemu-virt/platform/generic/firmware/fw_payload.bin \ + -drive file=${1},format=qcow2,id=hd0 \ + -object rng-random,filename=/dev/urandom,id=rng0 \ + -device virtio-rng-device,rng=rng0 \ + -device virtio-blk-device,drive=hd0 \ + -device virtio-net-device,netdev=usernet \ + -netdev user,id=usernet,hostfwd=tcp::12055-:22 \ + -device qemu-xhci -usb -device usb-kbd -device usb-tablet +} + +if ((kernel_version < 2303)) +then + run_qemu_1 $imagepath $opensbi_path + exit 0 +else + run_qemu_2 $imagepath $opensbi_path + exit 0 +fi ## For v1.0, use the following path #-kernel ./opensbi-1.0/build-oe/qemu-virt/platform/generic/firmware/fw_payload.elf \ diff --git a/scripts/build_opensbi.sh b/scripts/build_opensbi.sh index 6d173bc6f..08a4b5a81 100755 --- a/scripts/build_opensbi.sh +++ b/scripts/build_opensbi.sh @@ -3,8 +3,70 @@ ## Author: Dong Du, dd_nirvana@sjtu.edu.cn ## Description: This script is for building opensbi v0.9 ## For older version (e.g., v0.6), please find other scripts +opensbi_version = 1.2 +kernel_version = 2003 -cd /home/penglai/penglai-enclave/opensbi-0.9 +function build_opensbi_1() { + # build opensbi + cd /home/penglai/penglai-enclave/opensbi-${1} mkdir -p build-oe/qemu-virt CROSS_COMPILE=riscv64-unknown-linux-gnu- make O=build-oe/qemu-virt PLATFORM=generic FW_PAYLOAD=y FW_PAYLOAD_PATH=/home/penglai/penglai-enclave/Image #cp build-oe/qemu-virt/platform/qemu/virt/firmware/fw_payload.elf build-oe/qemu-virt/boot/fw_payload_oe_qemuvirt.elf +} + +function build_opensbi_2() { + cd ../Penglai-Enclave-sPMP/opensbi-${1} + rm -rf build-oe/qemu-virt + mkdir -p build-oe/qemu-virt + CROSS_COMPILE=riscv64-unknown-linux-gnu- make O=build-oe/qemu-virt PLATFORM=generic FW_PAYLOAD=y FW_PAYLOAD_PATH=../Penglai-Enclave-sPMP/u-boot/u-boot.bin -j$(nproc) +} + +function print_usage() { + RED='\033[0;31m' + BLUE='\033[0;34m' + BOLD='\033[1m' + NONE='\033[0m' + + echo -e "\n${RED}Usage${NONE}: + .${BOLD}/build_opensbi.sh${NONE} [OPTION]" + + echo -e "\n${RED}OPTIONS${NONE}: + ${BLUE}-v${NONE}: Select the opensbi version,default use 1.2 + ${BLUE}-k${NONE}: Select the openeuler version,default use openEuler-2003 + help: print usage" + echo -e "\n${RED}EXAMPLE${NONE}: + ${BLUE}./build_opensbi.sh -v 1.2 -k 2003${NONE} + " +} + +if [[ $1 == *"help"* ]]; then + print_usage + exit 0 +fi + +while getopts ":v:" opt; do + case $opt in + v) + opensbi_version=$OPTARG + ;; + k) + kernel_version=$OPTARG + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + print_usage + exit 1 + ;; + esac +done + +if + +if [ $(echo "$kernel_version < 2303" | bc -l) -eq 1 ] +then + build_opensbi_1 $opensbi_path + exit 0 +else + build_opensbi_2 $opensbi_path + exit 0 +fi \ No newline at end of file diff --git a/u-boot b/u-boot new file mode 160000 index 000000000..964aae164 --- /dev/null +++ b/u-boot @@ -0,0 +1 @@ +Subproject commit 964aae164414b15ef91a0319decb13e7e2c06b52 From 595ad56e0d619465f1a81fb410c868a952104376 Mon Sep 17 00:00:00 2001 From: ZhaoXi Date: Sat, 7 Oct 2023 23:03:09 +0800 Subject: [PATCH 2/4] Update README and tool scripts --- .gitmodules | 2 +- README.md | 121 ++++++++++++++++++++++++++------------- run_openeuler.sh | 2 + scripts/build_opensbi.sh | 2 + 4 files changed, 86 insertions(+), 41 deletions(-) diff --git a/.gitmodules b/.gitmodules index 3c580c2f8..a32a53f74 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,4 +6,4 @@ url = https://github.com/Penglai-Enclave/penglai-qemu.git [submodule "u-boot"] path = u-boot - url = git@github.com:Fly0307/u-boot.git + url = https://github.com/u-boot/u-boot.git diff --git a/README.md b/README.md index b433f4b36..78e37d056 100644 --- a/README.md +++ b/README.md @@ -9,19 +9,18 @@ ## Introduction -Penglai is a RISC-V TEE system, which is designed to be **secure**, **high-performant**, and **scalable**. -This repo maintains OpenSBI version of Penglai Enclave based on PMP. +Penglai is a RISC-V TEE system, which is designed to be **secure**, **high-performant**, and **scalable**. This repo maintains OpenSBI version of Penglai Enclave based on PMP. **How to use?** -Simply replace the OpenSBI used in your system with opensbi-0.9 in the top directory in the repo. +Simply replace the OpenSBI used in your system with opensbi-0.9/1.0/1.2 in the top directory in the repo. You can use our SDK and enclave-driver to build your trusted applications, or even write your own SDKs. ## Status and Info - Status: experimental: it's still experimental version now, please refer our TVM version for more features. -- Hardware requirement: riscv qemu (suggested version: >= 5.2.0) is fine +- Hardware requirement:for openEuler version $\le$ 20.03, riscv qemu version: $\geq$ 5.2.0 is fine;for openEuler version $\ge$ 22, qemu version:$\geq$ 8.0 is suggested. - Supported software system: This repo contains resources to run openEuler with Penglai TEE. - Real devices: Penglai for Nuclei devices is maintained in [Nuclei Linux SDK](https://github.com/Nuclei-Software/nuclei-linux-sdk/tree/dev_flash_penglai_spmp). @@ -33,18 +32,25 @@ You can refer our [Penglai-TVM](https://github.com/Penglai-Enclave/Penglai-Encla ### Requirements -Penglai uses Docker for building and uses submodules to track different componets. -Therefore, the only requirement to build and run penglai-demo is: +Penglai uses Docker for building and uses submodules to track different componets. Therefore, the only requirement to build and run penglai-demo is: - [Docker](https://docs.docker.com): for building/running Penglai - Git: for downloading the code -- Qemu for RISC-V (RV64): suggested version >= 5.2.0. You can download the qemu [here](https://www.qemu.org/) and follow the [instructions](https://wiki.qemu.org/Documentation/Platforms/RISCV) to build and install qemu.For openEuler version 2303, we tests using qemu-8.0. +- Qemu for RISC-V (RV64): suggested version >= 8.0. You can download the qemu [here](https://www.qemu.org/) and follow the [instructions](https://wiki.qemu.org/Documentation/Platforms/RISCV) to build and install qemu. ### Build uboot +**For openEuler version $\lt$ 23:** + +There is no need to compile uboot. + +**For openEuler version $\ge$ 23:** + Follow the instructions in openeuler riscv gitee to compile uboot for OE-23.X. ``` +# Fetch the uboot submodule +git submodule update --init --recursive cd ./u-boot make qemu-riscv64_defconfig make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- -j$(nproc) @@ -52,6 +58,8 @@ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- -j$(nproc) ### Build openEuler Kernel +**For openEuler version $\lt$ 23:** + Follow the instructions in openeuler riscv gitee to compile openEuler kernel. For example, download the OKL-5.10 in current directory, and compile with penglai's docker image: @@ -60,11 +68,14 @@ For example, download the OKL-5.10 in current directory, and compile with pengla # In the docker image ./scripts/build_euler_kernel.sh -Note:The kernel image needs to be compiled only when openeuler version is less than 23 +**For openEuler version $\ge$ 23:** + +For oe versions greater than 23, you can access the source code after [Run openEuler with Penglai Supports](#run-openeuler-with-penglai-supports) and don't need to compile the image like in the previous step for version $\lt$ 23. ### Build OpenSBI (with Penglai supports) -For openEuler version < 23: +**For openEuler version < 23:** + copy openeuler-kernel/arch/riscv/boot/Image . docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --rm -it ddnirvana/penglai-enclave:v0.5 bash # In the docker image cd /home/penglai/penglai-enclave/opensbi-0.9 @@ -73,9 +84,10 @@ For openEuler version < 23: Note: the /home/penglai/penglai-enclave/Image is the image compiled openEuler Kernel Image. -For openEuler version >= 23: +**For openEuler version >= 23:** ``` +copy ../Penglai-Enclave-sPMP/u-boot/u-boot.bin docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --rm -it ddnirvana/penglai-enclave:v0.5 bash cd ../Penglai-Enclave-sPMP/opensbi-1.2 rm -rf build-oe/qemu-virt @@ -88,6 +100,7 @@ A simpler way: ``` ./docker_cmd.sh docker #In the docker image,build opensbi 1.2 for OE20.03 +#./scripts/build_opensbi.sh -v [opensbi version] -k [openEuler version] ./scripts/build_opensbi.sh -v 1.2 -k 2003 ``` @@ -95,6 +108,8 @@ A simpler way: ### Build Penglai SDK +**For openEuler version < 23:** + When openeuler version is less than 23,following the commands to build enclave driver: ./docker_cmd.sh docker @@ -103,32 +118,17 @@ When openeuler version is less than 23,following the commands to build enclave d It will generate penglai.ko in the penglai-enclave-driver dir. -**Note:When openEuler version is >= 23,you need to start openEuler in qemu After starting the VM as the next step *Run openEuler with Penglai Supports* before compiling penglai-driver.** - -For openEuler version greater than 23, get the source code in the qemu VM and execute compile kernel moudle: - -``` -#in VM -cd ~/ -sudo dnf install -y kernel-devel kernel-source -``` +**For openEuler version >= 23:** -The kernel source code will be downloaded locally,the path is `/usr/lib/modules/6.1.19-2.oe2303.riscv64`. +When openEuler version is >= 23, you need to start openEuler in qemu as the next step [Run openEuler with Penglai Supports](#run-openeuler-with-penglai-supports) finished before compiling penglai-driver. -Copy penglai-enclave-driver to the root/ directory of the oe VM. Go to the penglai-enclave-driver directory and modify the original kernel source path openeuler-kernel in the Makefile to `/usr/lib/modules/6.1.19-2.oe2303.riscv64/build/`. Compile and install the kernel module: -``` -cd penglai-enclave-driver -vim Makefile #modify source path -make -j$(nproc) -insmod penglai.ko -``` When penglai.ko is completed,following the commnads to build user-level sdk and demos: - # Fetch the sdk submodule + #In host, fetch the sdk submodule git submodule update --init --recursive - + ./docker_cmd.sh docker # In the docker image cd sdk @@ -138,7 +138,7 @@ When penglai.ko is completed,following the commnads to build user-level sdk and You should download the disk image of openEuler (i.e., openEuler-preview.riscv64.qcow2) and raname image file to openEuler-xxxx-qemu-riscv64.qcow2. -You can download OE 2303 from [openEuler-23.03-V1-riscv64](https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/preview/openEuler-23.03-V1-riscv64/QEMU/)(i.e., openEuler-23.03-V1-base-qemu-preview.qcow2)or download [openEuler 20.03](http://pan.sjtu.edu.cn/web/share/6ec2212dcc10ac97345e9db1cb7595e9). +You can download OE 2303 from [openEuler-23.03-V1-riscv64](https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/preview/openEuler-23.03-V1-riscv64/QEMU/)(i.e., openEuler-23.03-V1-base-qemu-preview.qcow2)or download openEuler 20.03 from [here](http://pan.sjtu.edu.cn/web/share/4440d1d40d859f141d9e6cf18b89bb4d). ``` wget https://mirror.iscas.ac.cn/openeuler-sig-riscv/openEuler-RISC-V/preview/openEuler-23.03-V1-riscv64/QEMU/openEuler-23.03-V1-base-qemu-preview.qcow2.zst @@ -146,6 +146,8 @@ unzstd openEuler-23.03-V1-base-qemu-preview.qcow2.zst mv openEuler-23.03-V1-base-qemu-preview.qcow2 openEuler-2303-qemu-riscv64.qcow2 ``` +**For openEuler version < 23:** + Run VM in QEMU: # For openEuler version is 20.03 @@ -162,7 +164,7 @@ Run VM in QEMU: -bios none -- The test qemu version is 5.2.0. +- The test qemu version is 5.2.0 or 8.0.0. - The fw_payload.elf is the opensbi file. - The openEuler-preview.riscv64.qcow2 is the disk image for openEuler (You can download from https://repo.openeuler.org/openEuler-preview/RISC-V/Image/). - To login, username is "root", passwd is "openEuler12#$" @@ -170,6 +172,7 @@ Run VM in QEMU: Note: a script, run_openeuler.sh is provided to execute the above command easily ``` +./run_openeuler.sh -k [openEuler version] -o [opensbi version] #when openEuler version less than 23,eg 2003 ./run_openeuler.sh -k 2003 -o 1.2 #when openEuler version is greater than or equal 23,eg 2303 @@ -178,6 +181,36 @@ Note: a script, run_openeuler.sh is provided to execute the above command easily If everything is fine, you will enter a Linux terminal booted by Qemu with Penglai-installed. +**For openEuler version >= 23:** + +For openEuler version greater than 23, get the source code in the qemu VM and execute compile kernel moudle with penglai-driver. + +Copy penglai-enclave-driver to the root/ directory of the oe VM: + +``` +#in host +scp -P 12055 penglai-enclave-driver root@localhost:~/ +``` + +Execute the following commands and the kernel source code will be downloaded locally,the path is `/usr/lib/modules/6.1.19-2.oe2303.riscv64`. + +``` +#in VM +cd ~/ +sudo dnf install -y kernel-devel kernel-source +``` + +Go into the penglai-enclave-driver directory and modify the original kernel source path openeuler-kernel in the Makefile from `../openeuler-kernel/`to `/usr/lib/modules/6.1.19-2.oe2303.riscv64/build/`. + +Compile and install the kernel module: + +``` +cd ~/penglai-enclave-driver +vim Makefile #modify source path +make -j$(nproc) +insmod penglai.ko +``` + ### RUN demo **Copy files to openEuler Qemu** @@ -194,11 +227,17 @@ The passwd is "openEuler12#$" **Insmod the enclave-driver** -`insmod penglai.ko` +If you already installed in the previous step, you don't need to repeat it + +``` +insmod penglai.ko +``` And the, you can run a demo, e.g., a prime enclave, using -`./host prime` +``` +./host prime +``` Here, the `host` is an enclave invoker, which will start an enclave (name from input). @@ -209,6 +248,8 @@ Mulan Permissive Software License,Version 1 (Mulan PSL v1) ## Code Structures - opensbi-0.9: The Penglai-equipped OpenSBI, version 0.9 +- opensbi-1.0: The Penglai-equipped OpenSBI, version 1.0 +- opensbi-1.2: The Penglai-equipped OpenSBI, version 1.2 - openeuler-kernel: openEuler Kernel - riscv-qemu: The modified qemu (4.1) to support sPMP (you can also use the standard qemu) - scripts: some scripts to build/run Penglai demo @@ -241,14 +282,14 @@ To cite Penglai, please consider using the following bibtex: We thank all of our collaborators (companies, organizations, and communities). -[Huawei](https://www.huawei.com/) |[nuclei](https://www.nucleisys.com/) |[StarFive](https://starfivetech.com/) |[ISCAS](http://www.is.cas.cn/) | -:---: |:---: |:---: |:---: | -[Huawei (华为)](https://www.huawei.com/) |[Nuclei (芯来科技)](https://www.nucleisys.com/) |[StarFive (赛昉科技)](https://starfivetech.com/) |[ISCAS(中科院软件所)](http://www.is.cas.cn/) | +| [Huawei](https://www.huawei.com/) | [nuclei](https://www.nucleisys.com/) | [StarFive](https://starfivetech.com/) | [ISCAS](http://www.is.cas.cn/) | +| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | +| [Huawei (华为)](https://www.huawei.com/) | [Nuclei (芯来科技)](https://www.nucleisys.com/) | [StarFive (赛昉科技)](https://starfivetech.com/) | [ISCAS(中科院软件所)](http://www.is.cas.cn/) | -[openEuler](https://openeuler.org/) |[OpenHarmony](https://www.openharmony.cn/) |[secGear](https://gitee.com/openeuler/secGear) | -:---: |:---: |:---: | -[openEuler community](https://openeuler.org/) |[OpenHarmony community](https://www.openharmony.cn/) |[secGear framework](https://gitee.com/openeuler/secGear)| +| [openEuler](https://openeuler.org/) | [OpenHarmony](https://www.openharmony.cn/) | [secGear](https://gitee.com/openeuler/secGear) | +| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | +| [openEuler community](https://openeuler.org/) | [OpenHarmony community](https://www.openharmony.cn/) | [secGear framework](https://gitee.com/openeuler/secGear) | ## Acknowledgements -The design of Penglai was inspired by Sanctum, Keystone and HexFive, thanks to their great work! +The design of Penglai was inspired by Sanctum, Keystone and HexFive, thanks to their great work! \ No newline at end of file diff --git a/run_openeuler.sh b/run_openeuler.sh index 4c719b71c..b134f6199 100755 --- a/run_openeuler.sh +++ b/run_openeuler.sh @@ -98,9 +98,11 @@ function run_qemu_2(){ if ((kernel_version < 2303)) then + echo "Run openEuer $kernel_version with opensbi $opensbi_version" run_qemu_1 $imagepath $opensbi_path exit 0 else + echo "Run openEuer $kernel_version with opensbi $opensbi_version" run_qemu_2 $imagepath $opensbi_path exit 0 fi diff --git a/scripts/build_opensbi.sh b/scripts/build_opensbi.sh index 08a4b5a81..9f443ef20 100755 --- a/scripts/build_opensbi.sh +++ b/scripts/build_opensbi.sh @@ -64,9 +64,11 @@ if if [ $(echo "$kernel_version < 2303" | bc -l) -eq 1 ] then + echo "Begin build opensbi $opensbi_version for openEuler $kernel_version" build_opensbi_1 $opensbi_path exit 0 else + echo "Begin build opensbi $opensbi_version for openEuler $kernel_version" build_opensbi_2 $opensbi_path exit 0 fi \ No newline at end of file From e8d8f5c0b083670465c3888be024b7f05d8e5d83 Mon Sep 17 00:00:00 2001 From: ZhaoXi Date: Sat, 7 Oct 2023 23:08:16 +0800 Subject: [PATCH 3/4] Update README Add startup instructions for oe-23 Update README.md --- README.md | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 78e37d056..d5bcb1775 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ For example, download the OKL-5.10 in current directory, and compile with pengla For oe versions greater than 23, you can access the source code after [Run openEuler with Penglai Supports](#run-openeuler-with-penglai-supports) and don't need to compile the image like in the previous step for version $\lt$ 23. ### Build OpenSBI (with Penglai supports) -**For openEuler version < 23:** +**For openEuler version $\lt$ 23:** copy openeuler-kernel/arch/riscv/boot/Image . docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --rm -it ddnirvana/penglai-enclave:v0.5 bash @@ -84,10 +84,10 @@ For oe versions greater than 23, you can access the source code after [Run openE Note: the /home/penglai/penglai-enclave/Image is the image compiled openEuler Kernel Image. -**For openEuler version >= 23:** +**For openEuler version $\ge$ 23:** ``` -copy ../Penglai-Enclave-sPMP/u-boot/u-boot.bin +cp ../Penglai-Enclave-sPMP/u-boot/u-boot.bin docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --rm -it ddnirvana/penglai-enclave:v0.5 bash cd ../Penglai-Enclave-sPMP/opensbi-1.2 rm -rf build-oe/qemu-virt @@ -108,7 +108,7 @@ A simpler way: ### Build Penglai SDK -**For openEuler version < 23:** +**For openEuler version $\lt$ 23:** When openeuler version is less than 23,following the commands to build enclave driver: @@ -118,7 +118,7 @@ When openeuler version is less than 23,following the commands to build enclave d It will generate penglai.ko in the penglai-enclave-driver dir. -**For openEuler version >= 23:** +**For openEuler version $\ge$ 23:** When openEuler version is >= 23, you need to start openEuler in qemu as the next step [Run openEuler with Penglai Supports](#run-openeuler-with-penglai-supports) finished before compiling penglai-driver. @@ -146,7 +146,7 @@ unzstd openEuler-23.03-V1-base-qemu-preview.qcow2.zst mv openEuler-23.03-V1-base-qemu-preview.qcow2 openEuler-2303-qemu-riscv64.qcow2 ``` -**For openEuler version < 23:** +**For openEuler version $\lt$ 23:** Run VM in QEMU: @@ -175,15 +175,36 @@ Note: a script, run_openeuler.sh is provided to execute the above command easily ./run_openeuler.sh -k [openEuler version] -o [opensbi version] #when openEuler version less than 23,eg 2003 ./run_openeuler.sh -k 2003 -o 1.2 -#when openEuler version is greater than or equal 23,eg 2303 -./run_openeuler.sh -k 2303 -o 1.2 ``` If everything is fine, you will enter a Linux terminal booted by Qemu with Penglai-installed. -**For openEuler version >= 23:** +**For openEuler version $\ge$ 23:** + +Run VM in QEMU: + +``` +qemu-system-riscv64 -nographic -machine virt \ + -smp 4 -m 2G \ + -bios ./opensbi-1.2/build-oe/qemu-virt/platform/generic/firmware/fw_payload.bin \ + -drive file=openEuler-2303-qemu-riscv64.qcow2,format=qcow2,id=hd0 \ + -object rng-random,filename=/dev/urandom,id=rng0 \ + -device virtio-rng-device,rng=rng0 \ + -device virtio-blk-device,drive=hd0 \ + -device virtio-net-device,netdev=usernet \ + -netdev user,id=usernet,hostfwd=tcp::12055-:22 \ + -device qemu-xhci -usb -device usb-kbd -device usb-tablet +``` + +a simple way: + +``` +./run_openeuler.sh -k [openEuler version] -o [opensbi version] +#when openEuler version is greater than or equal 23,eg 2303 +./run_openeuler.sh -k 2303 -o 1.2 +``` -For openEuler version greater than 23, get the source code in the qemu VM and execute compile kernel moudle with penglai-driver. +After starting the VM, you need to get the source code in the qemu VM and execute compile kernel moudle with penglai-driver for openEuler version $\ge$ 23. Copy penglai-enclave-driver to the root/ directory of the oe VM: @@ -192,7 +213,7 @@ Copy penglai-enclave-driver to the root/ directory of the oe VM: scp -P 12055 penglai-enclave-driver root@localhost:~/ ``` -Execute the following commands and the kernel source code will be downloaded locally,the path is `/usr/lib/modules/6.1.19-2.oe2303.riscv64`. +Execute the following commands and the kernel source code will be downloaded locally, the path is `/usr/lib/modules/6.1.19-2.oe2303.riscv64`. ``` #in VM @@ -292,4 +313,4 @@ We thank all of our collaborators (companies, organizations, and communities). ## Acknowledgements -The design of Penglai was inspired by Sanctum, Keystone and HexFive, thanks to their great work! \ No newline at end of file +The design of Penglai was inspired by Sanctum, Keystone and HexFive, thanks to their great work! From 7ad064d7f18600760d7bc127e943bae1d63243f9 Mon Sep 17 00:00:00 2001 From: ZhaoXi Date: Tue, 10 Oct 2023 23:13:00 +0800 Subject: [PATCH 4/4] fix build scripts and update README --- README.md | 28 ++++++++++++++-------------- scripts/build_opensbi.sh | 20 ++++++++------------ 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d5bcb1775..8b0a394c5 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ For oe versions greater than 23, you can access the source code after [Run openE ### Build OpenSBI (with Penglai supports) **For openEuler version $\lt$ 23:** - copy openeuler-kernel/arch/riscv/boot/Image . + cp openeuler-kernel/arch/riscv/boot/Image . docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --rm -it ddnirvana/penglai-enclave:v0.5 bash # In the docker image cd /home/penglai/penglai-enclave/opensbi-0.9 @@ -87,12 +87,12 @@ Note: the /home/penglai/penglai-enclave/Image is the image compiled openEuler Ke **For openEuler version $\ge$ 23:** ``` -cp ../Penglai-Enclave-sPMP/u-boot/u-boot.bin +cp ../Penglai-Enclave-sPMP/u-boot/u-boot.bin . docker run -v $(pwd):/home/penglai/penglai-enclave -w /home/penglai/penglai-enclave --rm -it ddnirvana/penglai-enclave:v0.5 bash -cd ../Penglai-Enclave-sPMP/opensbi-1.2 +cd /home/penglai/penglai-enclave/opensbi-1.2 rm -rf build-oe/qemu-virt mkdir -p build-oe/qemu-virt -CROSS_COMPILE=riscv64-unknown-linux-gnu- make O=build-oe/qemu-virt PLATFORM=generic FW_PAYLOAD=y FW_PAYLOAD_PATH=../Penglai-Enclave-sPMP/u-boot.bin -j$(nproc) +CROSS_COMPILE=riscv64-unknown-linux-gnu- make O=build-oe/qemu-virt PLATFORM=generic FW_PAYLOAD=y FW_PAYLOAD_PATH=/home/penglai/penglai-enclave/u-boot.bin -j$(nproc) ``` A simpler way: @@ -152,16 +152,16 @@ Run VM in QEMU: # For openEuler version is 20.03 qemu-system-riscv64 -nographic -machine virt \ - -smp 4 -m 2G \ - -kernel ./opensbi-0.9/build-oe/qemu-virt/platform/generic/firmware/fw_payload.elf \ - -drive file=openEuler-preview.riscv64.qcow2,format=qcow2,id=hd0 \ - -object rng-random,filename=/dev/urandom,id=rng0 \ - -device virtio-rng-device,rng=rng0 \ - -device virtio-blk-device,drive=hd0 \ - -device virtio-net-device,netdev=usernet \ - -netdev user,id=usernet,hostfwd=tcp::12055-:22 \ - -append 'root=/dev/vda1 rw console=ttyS0 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem=4096M earlycon' \ - -bios none + -smp 4 -m 2G \ + -kernel ./opensbi-0.9/build-oe/qemu-virt/platform/generic/firmware/fw_payload.elf \ + -drive file=openEuler-preview.riscv64.qcow2,format=qcow2,id=hd0 \ + -object rng-random,filename=/dev/urandom,id=rng0 \ + -device virtio-rng-device,rng=rng0 \ + -device virtio-blk-device,drive=hd0 \ + -device virtio-net-device,netdev=usernet \ + -netdev user,id=usernet,hostfwd=tcp::12055-:22 \ + -append 'root=/dev/vda1 rw console=ttyS0 systemd.default_timeout_start_sec=600 selinux=0 highres=off mem=4096M earlycon' \ + -bios none - The test qemu version is 5.2.0 or 8.0.0. diff --git a/scripts/build_opensbi.sh b/scripts/build_opensbi.sh index 9f443ef20..31922d0bd 100755 --- a/scripts/build_opensbi.sh +++ b/scripts/build_opensbi.sh @@ -3,22 +3,21 @@ ## Author: Dong Du, dd_nirvana@sjtu.edu.cn ## Description: This script is for building opensbi v0.9 ## For older version (e.g., v0.6), please find other scripts -opensbi_version = 1.2 -kernel_version = 2003 +opensbi_version=1.2 +kernel_version=2003 function build_opensbi_1() { # build opensbi cd /home/penglai/penglai-enclave/opensbi-${1} -mkdir -p build-oe/qemu-virt -CROSS_COMPILE=riscv64-unknown-linux-gnu- make O=build-oe/qemu-virt PLATFORM=generic FW_PAYLOAD=y FW_PAYLOAD_PATH=/home/penglai/penglai-enclave/Image -#cp build-oe/qemu-virt/platform/qemu/virt/firmware/fw_payload.elf build-oe/qemu-virt/boot/fw_payload_oe_qemuvirt.elf + mkdir -p build-oe/qemu-virt + CROSS_COMPILE=riscv64-unknown-linux-gnu- make O=build-oe/qemu-virt PLATFORM=generic FW_PAYLOAD=y FW_PAYLOAD_PATH=/home/penglai/penglai-enclave/Image } function build_opensbi_2() { cd ../Penglai-Enclave-sPMP/opensbi-${1} rm -rf build-oe/qemu-virt mkdir -p build-oe/qemu-virt - CROSS_COMPILE=riscv64-unknown-linux-gnu- make O=build-oe/qemu-virt PLATFORM=generic FW_PAYLOAD=y FW_PAYLOAD_PATH=../Penglai-Enclave-sPMP/u-boot/u-boot.bin -j$(nproc) + CROSS_COMPILE=riscv64-unknown-linux-gnu- make O=build-oe/qemu-virt PLATFORM=generic FW_PAYLOAD=y FW_PAYLOAD_PATH=/home/penglai/penglai-enclave/u-boot/u-boot.bin -j$(nproc) } function print_usage() { @@ -44,7 +43,7 @@ if [[ $1 == *"help"* ]]; then exit 0 fi -while getopts ":v:" opt; do +while getopts ":v:k:" opt; do case $opt in v) opensbi_version=$OPTARG @@ -60,15 +59,12 @@ while getopts ":v:" opt; do esac done -if if [ $(echo "$kernel_version < 2303" | bc -l) -eq 1 ] then - echo "Begin build opensbi $opensbi_version for openEuler $kernel_version" - build_opensbi_1 $opensbi_path + build_opensbi_1 $opensbi_version exit 0 else - echo "Begin build opensbi $opensbi_version for openEuler $kernel_version" - build_opensbi_2 $opensbi_path + build_opensbi_2 $opensbi_version exit 0 fi \ No newline at end of file