.. _build: ##### build ##### Why this particular git? As it turns out it's totally possible to put together everything on your own. You can build all the individual components, os, client, xtest, Linux kernel, TF-A, TianoCore, QEMU, Buildroot_ etc and put all the binaries at correct locations and write your own command lines, Makefiles, shell-scripts etc that will work nicely on the devices you are interested in. If you know how to do that, fine, please go ahead. But for newcomers it's way too much behind the scenes to be able to setup a working environment. Also, if you want to run something in an automated way, then you need something else wrapping it up for you. With this particular git **built.git** our goal is to make it easy for newcomers to get started with OP-TEE using the devices we've listed in this document. git location ************ https://github.com/OP-TEE/build Why repo? ********* We discussed alternatives, initially we started out with having a simple shell-script, that worked to start with, but after getting more gits in use and support for more devices it started to be difficult to maintain. In the end we ended up choosing between repo_ from the Google AOSP project and `git submodules`_. No matter which you choose, there will always be some person arguing that one is better than the other. For us we decided to use repo. Not directly for the features itself from repo, but for the ability to simply work with different manifests containing both stable and non-stable release. Using some tips and tricks you can also speed up setup time significantly. For day to day work with commits, branches etc we tend to use git commands directly. .. _root_fs: Root filesystem *************** The rootfs in the builds that we cover here are as small as possible and is based on a stripped down Buildroot_ configuration adding just enough in the rootfs such that one can: - Boot OP-TEE. - Run xtest with no regressions. - Easily add additional developer tools like, strace, valgrind etc. .. note:: As a consequence of enabling "just enough", it is likely that **non-UART** based enviroments won't work out of the box. I.e., if you try to boot up an enviroment using HDMI and connect keyboards and other devices it is likely that things will not work. To make them work, you probably need to rebuild Linux kernel with correct drivers/frameworks enabled and in addition to that enable binaries/daemons in Buildroot that might be necessary (user space tools and drivers). How do I build using AOSP / OpenEmbedded? ***************************************** For guides how to build AOSP, please refer to our :ref:`aosp` page. For OpenEmbedded we have no guide ready. .. _optee_developer_setup: Platforms supported by build.git ******************************** Below is a table showing the platforms supported by build.git. OP-TEE as such supports many more platforms. To find out how to run OP-TEE on those, please reach out to the maintainer of that platform directly if you have build related questions etc. Please see the MAINTAINERS_ file for contact information. .. Please keep this list sorted in alphabetic order: .. list-table:: :header-rows: 1 * - Platform - Composite flag - Publicly available? * - `AMD/Xilinx Versal ACAP VCK190`_ - ``PLATFORM=versal`` - Yes * - `ARM Juno Board`_ - ``PLATFORM=vexpress-juno`` - Yes * - `ARM Foundation FVP`_ - ``PLATFORM=vexpress-fvp`` - Yes * - `DeveloperBox`_ - ``PLATFORM=synquacer`` - Yes * - `HiKey Kirin 620`_ - ``PLATFORM=hikey`` - Yes * - `HiKey 960`_ - ``PLATFORM=hikey-hikey960`` - Yes * - `MediaTek MT8173 EVB Board`_ (deprecated) - ``PLATFORM=mediatek-mt8173`` - No * - `Poplar`_ - ``PLATFORM=poplar`` - Yes * - `QEMU`_ - ``PLATFORM=vexpress-qemu_virt`` - Yes * - `QEMUv8`_ - ``PLATFORM=vexpress-qemu_armv8a`` - Yes * - `Raspberry Pi 3`_ - ``PLATFORM=rpi3`` - Yes * - `ROCK Pi 4`_ - ``PLATFORM=rockchip-rk3399`` - Yes * - `STM32MP135F-DK`_ - ``PLATFORM=stm32mp1-135F_DK`` - Yes * - `STM32MP157A-DK1`_ - ``PLATFORM=stm32mp1-157A_DK1`` - Yes * - `STM32MP157C-DK2`_ - ``PLATFORM=stm32mp1-157C_DK2`` - Yes * - `STM32MP157C-EV1`_ - ``PLATFORM=stm32mp1-157C_EV1`` - Yes * - `Texas Instruments DRA7xx`_ - ``PLATFORM=ti-dra7xx`` - Yes * - `Texas Instruments AM57xx`_ - ``PLATFORM=ti-am57xx`` - Yes * - `Texas Instruments AM43xx`_ - ``PLATFORM=ti-am43xx`` - Yes Manifests ********* .. _current_version: Current version =============== Here is a list of manifests for the devices currently supported in ``build.git``. With these you will get a setup containing the all necessary software components to run OP-TEE on the chosen device. Beware that this will run latest available on OP-TEE gits meaning that if you re-sync then you will most likely get new commits. If you need a stable/tagged version with non-moving gits, then please refer to the next section instead. .. Please keep this list sorted in alphabetic order: +----------------+-------------------+----------------------+ | Target | Manifest xml | Device documentation | +================+===================+======================+ | AM43xx | ``am43xx.xml`` | :ref:`ti` | +----------------+-------------------+----------------------+ | AM57xx | ``am57xx.xml`` | :ref:`ti` | +----------------+-------------------+----------------------+ | DeveloperBox | ``synquacer.xml`` | :ref:`devbox` | +----------------+-------------------+----------------------+ | ARM Juno board | ``juno.xml`` | :ref:`juno` | +----------------+-------------------+----------------------+ | DRA7xx | ``dra7xx.xml`` | :ref:`ti` | +----------------+-------------------+----------------------+ | FVP | ``fvp.xml`` | :ref:`fvp` | +----------------+-------------------+----------------------+ | HiKey 960 | ``hikey960.xml`` | :ref:`hikey960` | +----------------+-------------------+----------------------+ | HiKey | ``hikey.xml`` | :ref:`hikey` | +----------------+-------------------+----------------------+ | Poplar Debian | ``poplar.xml`` | | +----------------+-------------------+----------------------+ | QEMU | ``default.xml`` | :ref:`qemu_v7` | +----------------+-------------------+----------------------+ | QEMUv8 | ``qemu_v8.xml`` | :ref:`qemu_v8` | +----------------+-------------------+----------------------+ | Raspberry Pi 3 | ``rpi3.xml`` | :ref:`rpi3` | +----------------+-------------------+----------------------+ | ROCK Pi 4 | ``rockpi4.xml`` | :ref:`rockpi4` | +----------------+-------------------+----------------------+ | STM32MP1 | ``stm32mp1.xml`` | :ref:`stm32mp1` | +----------------+-------------------+----------------------+ | VCK190 | ``versal.xml`` | :ref:`versal` | +----------------+-------------------+----------------------+ Stable releases =============== Starting from OP-TEE ``v3.1`` you can check out stable releases by using the same manifests as for current version above, but with the difference that **you also need to specify a branch** where the name corresponds to the release version. I.e., when we are doing releases we are creating a branch with a name corresponding to the release version. So, let's for example say that you want to checkout a stable OP-TEE ``v3.12`` for Raspberry Pi 3, then you do like this instead of what is mentioned further down in section ":ref:`build_get_the_source`" (note the ``-b 3.12.0``): .. hint:: If there is no strong need for an older version, then we always recommend to use the most recent release. I.e., in the example here we do say ``3.12.0``, but there may very well be more recent version when you are reading this. To find out, please have a look at the ":ref:`release_dates`" page. .. code-block:: bash ... $ repo init -u https://github.com/OP-TEE/manifest.git -m rpi3.xml -b 3.12.0 ... Stable releases prior to OP-TEE v3.1 (v1.0.0 to v3.0.0) ======================================================= Before OP-TEE ``v3.1`` we used to have separate xml-manifest files for the stable builds. If you for some reason need an older stable release, please refer to ":ref:`build_legacy`". Stable releases prior to OP-TEE v3.9 (3.1.0 to 3.8.0) ===================================================== Due to a change in the Google repo tool, you might get an error when cloning OP-TEE repositories before version ``3.9.0``. In this case please refer to ":ref:`build_legacy_3_1_0-3_8_0`". .. _get_and_build_the_solution: Get and build the solution ************************** Below we will describe the general way of how to get the source, build the solution and how to run xtest on the device. For device specific instructions, please see the links in the table in the ":ref:`current_version`" section. .. _build_prerequisites: Step 1 - Prerequisites ====================== Install prerequisites according to the :ref:`prerequisites` page. .. _build_install_repo: Step 2 - Install Android repo ============================= Note that here you don't install a huge SDK, it's simply a Python script that you download and put in your ``$PATH``, that's it. Exactly how to "install" repo, can be found at the Google repo_ pages, so follow those instructions before continuing. .. _build_get_the_source: Step 3 - Get the source code ============================ Choose the manifest corresponding to the platform you intend to use (see the table in section ":ref:`current_version`". For example, if you intend to use Raspberry Pi3, then at line 3 below, ``${TARGET}.xml`` shall be ``rpi3.xml``. The ```` is whatever location where you want to store the entire OP-TEE developer setup. .. code-block:: bash :linenos: :emphasize-lines: 3 $ mkdir -p $ cd $ repo init -u https://github.com/OP-TEE/manifest.git -m ${TARGET}.xml [-b ${BRANCH}] $ repo sync -j4 --no-clone-bundle .. hint:: By referencing an existing and locally saved repo forest you can save lots of time. We are talking about doing repo sync in 30 seconds instead of 15-30 minutes (see the :ref:`tips_and_tricks` section for more details). .. _build_get_toolchains: Step 4 - Get the toolchains =========================== In OP-TEE we're using different toolchains for different targets (depends on ARMv7-A ARMv8-A 64/32bit solutions). In any case start by downloading the toolchains by: .. code-block:: bash $ cd /build $ make -j2 toolchains .. _build_make: Step 5 - Build the solution =========================== We've configured our repo manifests, so that repo will always automatically symlink the ``Makefile`` to the correct device specific makefile, that means that you simply start the build by running (still in ``/build``) .. code-block:: bash $ make -j `nproc` This step will also take some time, but you can speed up subsequent builds by enabling ccache_ (again see :ref:`tips_and_tricks`). .. hint:: **If you're having build issues**, then you can pipe the entire build log to a file, which makes it easier to search for the issue using a regular editor. In that case also avoid the ``-j`` flag so it's easier to see in what order things are happening. To create a ``build.log`` file do: ``$ make 2>&1 | tee build.log`` .. _build_flash: Step 6 - Flash the device ========================= On **non-emulated** solutions (this means that you shouldn't do this step when you are running QEMU-v7/v8 and FVP), you will need to flash the software in some way. We've tried to "hide" that under the following make target: .. code-block:: bash $ make flash But, since some devices are trickier to flash than others, please see the :ref:`device_specific`. See this just as a general instruction. Step 7 - Boot up the device =========================== This is device specific (see :ref:`device_specific`). .. _build_tee_supplicant: Step 8 - Load tee-supplicant ============================ On **most** solutions tee-supplicant is already running (check by running ``$ ps aux | grep tee-supplicant``) on others not. If it's **not** running, then start it by running: .. code-block:: bash $ tee-supplicant -d .. note:: If you've built using our manifest you should not need to modprobe any OP-TEE/TEE kernel driver since it's built into the kernel in all our setups. .. _build_run_xtest: Step 9 - Run xtest ================== The entire xtest test suite has been deployed when you we're making the builds in previous steps, i.e, in general there is no need to copy any binaries manually. Everything has been put into the :ref:`root_fs` automatically. So, to run xtest, you simply type: .. code-block:: bash $ xtest If there are no regressions / issues found, xtest should end with something like this: .. code-block:: none ... +----------------------------------------------------- 23476 subtests of which 0 failed 67 test cases of which 0 failed 0 test case was skipped TEE test application done! .. hint:: For other ways to run xtest, please refer to the ":ref:`optee_test_run_xtest`" page at :ref:`optee_test`. .. _tips_and_tricks: Tips and Tricks *************** Reference existing project to speed up repo sync ================================================ Doing a ``repo init``, ``repo sync`` from scratch can take a fair amount of time. The main reason for that is simply because of the size of some of the gits we are using, like for the Linux kernel and EDK2. With repo you can reference an existing forest and by doing so you can speed up repo sync to taking 30 seconds instead of 15-30 minutes. The way to do this are as follows. 1. Start by setup a clean forest that you will not touch, in this example, let us call that ``optee-ref`` and put that under for ``$HOME/devel/optee-ref``. This step will take somewhere between 15- to 45 minutes, depending on your connection speed to internet. 2. Then setup a cronjob (``crontab -e``) that does a ``repo sync`` in this folder particular folder once a night (that is more than enough). 3. Now you should setup your actual tree which you are going to use as your working tree. The way to do this is almost the same as stated in the instructions above (see the ":ref:`build_get_the_source`" section) , the only difference is that you **also** reference the other local forest when running ``repo init``, like this .. code-block:: bash $ repo init -u https://github.com/OP-TEE/manifest.git --partial-clone --reference $HOME/devel/optee-ref 4. The rest is the same above, but now it will only take less than a minute to clone a forest. Normally '1' and '2' above is something you will only do once. Also if you ignore step '2', then you will **still** get the latest from official git trees, since repo will also check for updates that aren't at the local reference. Use ccache ========== ccache_ is a tool that caches build object-files etc locally on the disc and can speed up build time significantly in subsequent builds. On Debian-based systems (Ubuntu, Mint etc) you simply install it by running: .. code-block:: bash $ sudo apt-get install ccache The makefiles in build.git are configured to automatically find and use ccache if ccache is installed on your system, so other than having it installed you don't have to think about anything. .. _Buildroot: https://buildroot.org .. _ccache: https://ccache.samba.org .. _git submodules: https://git-scm.com/book/en/v2/Git-Tools-Submodules .. _MAINTAINERS: https://github.com/OP-TEE/optee_os/blob/master/MAINTAINERS .. _repo: https://source.android.com/source/downloading.html .. Links to devices etc: .. _AMD/Xilinx Versal ACAP VCK190: https://www.xilinx.com/products/boards-and-kits/vck190.html .. _ARM Juno Board: http://www.arm.com/products/tools/development-boards/versatile-express/juno-arm-development-platform.php .. _ARM Foundation FVP: http://www.arm.com/fvp .. _DeveloperBox: https://www.96boards.org/product/developerbox .. _HiKey Kirin 620: https://www.96boards.org/products/hikey .. _HiKey 960: https://www.96boards.org/product/hikey960 .. _MediaTek MT8173 EVB Board: http://www.mediatek.com/en/products/mobile-communications/tablet/mt8173 .. _Poplar: https://www.96boards.org/product/poplar/ .. _QEMU: http://wiki.qemu.org/Main_Page .. _QEMUv8: http://wiki.qemu.org/Main_Page .. _Raspberry Pi 3: https://www.raspberrypi.org/products/raspberry-pi-3-model-b .. _ROCK Pi 4: https://wiki.radxa.com/Rockpi4 .. _STM32MP135F-DK: https://www.st.com/en/evaluation-tools/stm32mp135f-dk.html .. _STM32MP157A-DK1: https://www.st.com/en/evaluation-tools/stm32mp157a-dk1.html .. _STM32MP157C-DK2: https://www.st.com/en/evaluation-tools/stm32mp157c-dk2.html .. _STM32MP157C-EV1: https://www.st.com/en/evaluation-tools/stm32mp157c-ev1.html .. _Texas Instruments DRA7xx: http://www.ti.com/product/DRA746 .. _Texas Instruments AM57xx: http://www.ti.com/product/AM5728 .. _Texas Instruments AM43xx: http://www.ti.com/product/AM4379