diff --git a/README.md b/README.md index e660af1..29db171 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,6 @@ looks as follows: Testing Wolfssl-py and Wolfcrypt-py ----------------------------------- - To test the python wrapper for wolfSSL and wolfcrypt in a yocto build it will require python3, python3-pytest, python3-cffi and wolfSSL are built on the target system. @@ -342,6 +341,65 @@ to add a DNS server to /etc/resolv.conf like such with root perms echo "nameserver 8.8.8.8" >> /etc/resolv.conf ``` +Running Image on the QEMU +------------------------- + +To run meta-wolfssl image on the QEMU (Quick EMUlator) you can follow these +general steps. For this example we will use the Yocto Project Poky. + +1. Initialize the Build +This can be done by running these commands: + +``` +$ cd poky +$ source oe-init-build-env +``` + +This will initialize the build environment and let you run +bitbake in the build directory. + +2. Run bitbake +Next you can run bitbake to build the OS image that you want. Make sure +you have the correct variables added in the `local.conf` For this example +we will run `core-image-base`. Which can be built by running this comamnd +from the `build` directoy: + +``` +$ bitbake core-image-base +``` + +This will run bitbake and build the image with your added +meta-wolfssl recipes. + +3. Run the Image in QEMU +You can now simulate your image with the QEMU This can be done by running +the qemu that comes in your Yocto Project the default system is usually +`qemux86-64` but you can find what its set to by looking at your `local.conf`. +We can run this command to start the emulator: + +``` +$ runqemu qemux86-64 +``` + +4. Run Your Recipes +Now that you are in the QEMU you can navigate your way to the `usr/bin` +directory which contains the your wolfssl your applications. Lets say we +included these images in our `local.conf` + +``` +IMAGE_INSTALL:append = " wolfssl wolfcrypttest wolfcryptbenchmark " +``` + +In that case we can run wolfcrypttest and wolfcryptbenchmark examples from +the `usr/bin` directory like so: + +``` +$ ./wolfcrypttest +$ ./wolfcryptbenchmark +``` + +This will run the wolfcrypt test and benchmark examples from the QEMU. + wolfProvider ------------ To build wolfProvider view the instructions in this [README](recipes-wolfssl/wolfprovider/README.md) diff --git a/conf/layer.conf b/conf/layer.conf index f1df7d7..064bbe3 100644 --- a/conf/layer.conf +++ b/conf/layer.conf @@ -40,6 +40,11 @@ BBFILES += "${@bb.utils.contains('IMAGE_INSTALL', \ '${LAYERDIR}/recipes-wolfssl/wolftpm/*.bb ${LAYERDIR}/recipes-wolfssl/wolftpm/*.bbappend', \ '', d)}" +BBFILES += "${@bb.utils.contains('IMAGE_INSTALL', \ + 'wolftpm-examples', \ + '${LAYERDIR}/recipes-examples/wolftpm/*.bb ${LAYERDIR}/recipes-examples/wolftpm/*.bbappend', \ + '', d)}" + BBFILES += "${@bb.utils.contains('IMAGE_INSTALL', \ 'wolfssl-py', \ '${LAYERDIR}/recipes-wolfssl/wolfssl-py/*.bb ${LAYERDIR}/recipes-wolfssl/wolfssl-py/*.bbappend', \ diff --git a/recipes-examples/wolftpm/README.md b/recipes-examples/wolftpm/README.md new file mode 100644 index 0000000..6cf4d07 --- /dev/null +++ b/recipes-examples/wolftpm/README.md @@ -0,0 +1,67 @@ +wolfTPM Examples +================ + +Several wolfTPM example applications are included in this +layer, these include: + +- attestation +- endorsement +- keygen +- pcr +- seal +- bench +- firmware +- management +- pkcs7 +- timestamp +- boot +- gpio +- native +- tls +- wrap +- csr +- nvram + +The recipe for these applications is located at: +``` +meta-wolfssl/recipes-examples/wolftpm/wolftpm-examples.bb +``` + +You'll need to compile wolTPM and the examples directory. +This can be done with these commands in the build directory: + +``` +$ bitbake wolftpm +$ bitbake wolftpm-examples +``` + +To install these applications into your image, you will +need to edit your "build/conf/local.conf" file and add +`wolftpm` and `wolftpm-examples` to your "IMAGE_INSTALL" +variable like so: + +- For Dunfell and newer versions of Yocto +``` +IMAGE_INSTALL:append = " wolftpm wolftpm-examples" +``` + +- For versions of Yocto older than Dunfell +``` +IMAGE_INSTALL_append = " wolftpm wolftpm-examples" +``` + +When your image builds, these will be installed to the +`/usr/bin/examples` system directory. When inside your +executing image, you can run them from the terminal. + +For example, we can run the benchmark from the examples +directory like so: + +``` +$ cd bench +$ ./bench +``` + +Refer to the [wolfTPM Examples README](https://github.com/wolfSSL/wolfTPM/blob/master/examples/README.md) for more information on the examples directory. + +Refer to the [meta-wolfssl README](https://github.com/wolfSSL/meta-wolfssl/blob/master/README.md) for more information on setting up your layer. diff --git a/recipes-examples/wolftpm/wolftpm-examples.bb b/recipes-examples/wolftpm/wolftpm-examples.bb new file mode 100644 index 0000000..5810f61 --- /dev/null +++ b/recipes-examples/wolftpm/wolftpm-examples.bb @@ -0,0 +1,45 @@ +SUMMARY = "wolfTPM Examples Directory" +DESCRIPTION = "wolfTPM examples directory used to demonstrate \ + features of a TPM 2.0 module" +HOMEPAGE = "https://www.wolfssl.com/products/wolftpm" +BUGTRACKER = "https://github.com/wolfssl/wolftpm/issues" +SECTION = "libs" + +LICENSE = "GPL-2.0-only" +LIC_FILES_CHKSUM = "file://LICENSE;md5=b234ee4d69f5fce4486a80fdaf4a4263" +S = "${WORKDIR}/git" +DEPENDS += "wolfssl" + +SRC_URI = "git://github.com/wolfssl/wolfTPM.git;nobranch=1;protocol=https;rev=1fa15951eb91a8fe89b3326077b9be6fb105edeb" + +do_configure[noexec] = "1" +do_compile[noexec] = "1" + +WOLFTPM_EXAMPLES_DIR = "${datadir}/wolftpm-examples" +WOLFTPM_EXAMPLES_INSTALL_DIR = "${D}${WOLFTPM_EXAMPLES_DIR}" +WOLFTPM_EXAMPLES_README = "README.txt" +WOLFTPM_EXAMPLES_README_DIR = "${WOLFTPM_EXAMPLES_INSTALL_DIR}/${WOLFTPM_EXAMPLES_README}" + +python () { + distro_version = d.getVar('DISTRO_VERSION', True) + wofltpm_examples_dir = d.getVar('WOLFTPM_EXAMPLES_DIR', True) + wolftpm_examples_install_dir = d.getVar('WOLFTPM_EXAMPLES_INSTALL_DIR', True) + wolftpm_examples_readme_dir = d.getVar('WOLFTPM_EXAMPLES_README_DIR', True) + + bb.note("Installing dummy file for wolfTPM examples") + installDir = 'install -m 0755 -d "%s"\n' % wolftpm_examples_install_dir + makeDummy = 'echo "This is a dummy package" > "%s"\n' % wolftpm_examples_readme_dir + + d.appendVar('do_install', installDir) + d.appendVar('do_install', makeDummy) + + pn = d.getVar('PN', True) + if distro_version and (distro_version.startswith('2.') or distro_version.startswith('3.')): + files_var_name = 'FILES_' + pn + else: + files_var_name = 'FILES:' + pn + + current_files = d.getVar(files_var_name, True) or "" + new_files = current_files + ' ' + wofltpm_examples_dir + '/*' + d.setVar(files_var_name, new_files) +} diff --git a/recipes-examples/wolftpm/wolftpm_%.bbappend b/recipes-examples/wolftpm/wolftpm_%.bbappend new file mode 100644 index 0000000..bb279c3 --- /dev/null +++ b/recipes-examples/wolftpm/wolftpm_%.bbappend @@ -0,0 +1,23 @@ +#wolfTPM Examples +WOLFTPM_EXAMPLES_DIR = "${B}/examples" +WOLFTPM_INSTALL_DIR = "${D}${bindir}" + +# Bash dependency for .sh +RDEPENDS:${PN} += "bash" + +python () { + # Get the environment variables + wolftpm_examples_dir = d.getVar('WOLFTPM_EXAMPLES_DIR', True) + wolftpm_install_dir = d.getVar('WOLFTPM_INSTALL_DIR', True) + + bbnote = 'bbnote "Installing wolfTPM Examples"\n' + installDir = 'install -m 0755 -d "%s"\n' % (wolftpm_install_dir) + cpExamples = 'cp -r "%s/" "%s/"\n' % (wolftpm_examples_dir, wolftpm_install_dir) + + d.appendVar('do_install', bbnote) + d.appendVar('do_install', installDir) + d.appendVar('do_install', cpExamples) +} + +# Ensure consistent locale +export LC_ALL = "C"