linaro-swg / optee_examples

OP-TEE Sample Applications
Other
163 stars 140 forks source link

how to add new examples in existing optee_examples using yocto #95

Closed kuldeepmarker-eaton closed 2 years ago

kuldeepmarker-eaton commented 2 years ago

I want to test fTPM TA so I thought of making use of optee-examples. I am using OPENSTLinux distro. In that there is a recipe which builds the existing optee-examples and it can be included in my final image. So I want to use that recipe and add my example code which can be build using the same recipe. I am not getting how should I proceed since my files will be local files and how it can be made part of optee_examples build. Following is the recipe used by me.

SUMMARY = "OP-TEE examples"
HOMEPAGE = "https://github.com/linaro-swg/optee_examples"

LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://${S}/LICENSE;md5=cd95ab417e23b94f381dafc453d70c30"

DEPENDS = "optee-client virtual/optee-os python3-pycryptodomex-native python3-pycrypto-native"

inherit python3native

SRC_URI = "git://github.com/linaro-swg/optee_examples.git"
SRCREV = "9a755dcf4d8ef6117af59dfd1b1a82315cee58ca"

S = "${WORKDIR}/git"

OPTEE_CLIENT_EXPORT = "${STAGING_DIR_HOST}${prefix}"
TEEC_EXPORT = "${STAGING_DIR_HOST}${prefix}"
TA_DEV_KIT_DIR = "${STAGING_INCDIR}/optee/export-user_ta"

EXTRA_OEMAKE = " TA_DEV_KIT_DIR=${TA_DEV_KIT_DIR} \
                 OPTEE_CLIENT_EXPORT=${OPTEE_CLIENT_EXPORT} \
                 TEEC_EXPORT=${TEEC_EXPORT} \
                 HOST_CROSS_COMPILE=${TARGET_PREFIX} \
                 TA_CROSS_COMPILE=${TARGET_PREFIX} \
                 V=1 \
                 LIBGCC_LOCATE_CFLAGS='--sysroot=${STAGING_DIR_HOST}' \
               "

do_compile() {
    oe_runmake
}

do_install () {
    mkdir -p ${D}${nonarch_base_libdir}/optee_armtz
    mkdir -p ${D}${bindir}
    install -D -p -m0755 ${S}/out/ca/* ${D}${bindir}
    install -D -p -m0444 ${S}/out/ta/* ${D}${nonarch_base_libdir}/optee_armtz
}

# Avoid QA Issue: No GNU_HASH in the elf binary
INSANE_SKIP_${PN} += "ldflags"

FILES_${PN} += "${nonarch_base_libdir}/optee_armtz/"

# Imports machine specific configs from staging to build
PACKAGE_ARCH = "${MACHINE_ARCH}"
jforissier commented 2 years ago

@kuldeepmarker-eaton this is a bit beyond the scope of optee_examples I think, and I am still learning about Yocto myself... but here is what I can say.

Examples can easily be extended by adding a new sub-directory similar to the existing ones (aes/, hello_world/ etc.). You can remove everything you don't need, for example if you want to test the fTPM TA you don't need any TA code. With Yocto you can add INHERIT += "rm_work" in your local config so that the source directory is preserved, then use bitbake -c compile -f optee-examples to build only that. One you have something working you generate a local patch (Git comit and git format-patch HEAD^) and then you add it to the Yocto recipe via SRC_URI:append = "file://<your-patch-name>.patch".

HTH.

github-actions[bot] commented 2 years ago

This issue has been marked as a stale issue because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment, otherwise this issue will automatically be closed in 5 days. Note, that you can always re-open a closed issue at any time.