Skip to content

Commit

Permalink
Open-source the TEE Core
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Brand <pascal.brand@st.com>
  • Loading branch information
Pascal Brand committed Jun 12, 2014
0 parents commit b010477
Show file tree
Hide file tree
Showing 616 changed files with 99,101 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.swp
cscope.*
out
.cproject
.project
27 changes: 27 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Unless it has its own copyright/license embedded in its body, each source file
is subject to the following license terms:

Copyright (c) 2014, STMicroelectronics International N.V.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
SHELL = /bin/bash

.PHONY: all
all:

# Make these default for now
ARCH ?= arm32
PLATFORM ?= orly2
O ?= out/$(ARCH)-plat-$(PLATFORM)

arch_$(ARCH) := y

cmd-fixdep := ./scripts/fixdep

ifneq ($O,)
out-dir := $O/
endif

ifneq ($V,1)
q := @
cmd-echo := true
else
q :=
cmd-echo := echo
endif

include core/core.mk

include ta/ta.mk

.PHONY: clean
clean:
@echo Cleaning
${q}rm -f $(cleanfiles)

.PHONY: cscope
cscope:
@echo Creating cscope database
${q}rm -f cscope.*
${q}find $(PWD) -name "*.[chSs]" > cscope.files
${q}cscope -b -q -k
35 changes: 35 additions & 0 deletions Notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
OP-TEE
=======

This is the repository of OP-TEE (Open Portable Trusted Execution Environment), the open-source TEE maintained by STMicroelectronics, with initial contributions from STMicroelectronics, Ericsson, the Linaro industry association.

What OP-TEE is
------

OP-TEE is designed primarily to rely on the ARM TrustZone(R) technology as the underlying hardware isolation mechanism. However, it has been structured to be compatible with any isolation technology suitable for the TEE concept and goals, such as running as a virtual machine or on a dedicated CPU.

The main design goals for OP-TEE are:
- Isolation - the TEE provides isolation from the Rich OS (typically, Linux/Android) and it protects the Trusted Applications (TAs) it executes from each other, using underlying HW support,
- Small footprint - the TEE should remain small enough so that the TEE core, including all the code and data required to provide isolation, can reside in a reasonable amount of on-chip memory,
- Portability - the TEE must be easily pluggable to different architectures and available HW, and it has to support various setups such as multiple TEEs or multiple client OSes.

Repository structure
------

OP-TEE is composed of three gits:
- The optee-client git, containing the source code for the TEE client library in Linux. This component provides the TEE Client API as defined by the <a href="https://www.globalplatform.org/specificationsdevice.asp">GlobalPlatform TEE standard</a>. It is distributed under the BSD 2-clause open-source license.
- The optee_os git, containing the source code for the TEE OS itself. This component provides the TEE Internal APIs as defined by the GlobalPlatform TEE standard to the Trusted Applications that it executes. It is distributed under the BSD 2-clause open-source license.
- The optee_linuxdriver git, containing the source code for the TEE driver in Linux. This component implements a generic TEE driver, designed primarily for TEE implementations that rely on the ARM TrustZone(R)technology. It is distributed under the GPLv2 open-source license. Please note that re-distribution under other versions of the GPL license is not allowed. The rationale behind this limitation is to ensure that this code may be used on products which have security devices which prevent reloading the code. Such security devices would be incompatible with some licenses such as GPLv3 and so distribution under those licenses would be inconsistent with this goal. Therefore it is recommended that care be taken before redistributing any of the components under other license terms than those provided here.

Contributions
------

Contributions to OP-TEE are managed by the OP-TEE gatekeepers, whose contact email is op-tee-support[at]st[.]com.

Contributions must be original work of the contributor. In order to preserve the rights of the contributor while allowing distribution to and protection of the recipients of OP-TEE, the contributor must complete, sign and send the Contribution Agreement or a scanned copy to ST for counter-signature, prior to any contribution. The address where to send the agreement and other details will be provided upon contact with the OP-TEE gatekeepers.
Once the Contribution Agreement is complete, the contributor may propose contributions to the OP-TEE gatekeepers. Proposed Contributions are reviewed for acceptance by the OP-TEE gatekeepers and the OP-TEE community.

Submission of non-original work
------

You may submit work that is not your original creation separately from any Contribution, identifying the complete details of its source and of any license or other restriction of which you are personally aware. Such submissions are not subject to the Contribution Agreement. They are reviewed for acceptance by the OP-TEE gatekeepers and the OP-TEE community.
161 changes: 161 additions & 0 deletions core/arch/arm32/include/arm32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef ARM32_H
#define ARM32_H

#ifndef ASM
#include <stdint.h>
#endif

#define CPSR_MODE_MASK 0x1f
#define CPSR_MODE_USR 0x10
#define CPSR_MODE_FIQ 0x11
#define CPSR_MODE_IRQ 0x12
#define CPSR_MODE_SVC 0x13
#define CPSR_MODE_MON 0x16
#define CPSR_MODE_ABT 0x17
#define CPSR_MODE_UND 0x1b
#define CPSR_MODE_SYS 0x1f

#define CPSR_T (1 << 5)
#define CPSR_F (1 << 6)
#define CPSR_I (1 << 7)

#define MPIDR_CPU_MASK 0xff
#define MPIDR_CLUSTER_MASK (0xff << 8)

#define SCR_NS (1 << 0)
#define SCR_IRQ (1 << 1)
#define SCR_FIQ (1 << 2)
#define SCR_EA (1 << 3)
#define SCR_FW (1 << 4)
#define SCR_AW (1 << 5)
#define SCR_NET (1 << 6)
#define SCR_SCD (1 << 7)
#define SCR_HCE (1 << 8)
#define SCR_SIF (1 << 9)

#define SCTLR_M (1 << 0)
#define SCTLR_A (1 << 1)
#define SCTLR_C (1 << 2)
#define SCTLR_CP15BEN (1 << 5)
#define SCTLR_SW (1 << 10)
#define SCTLR_Z (1 << 11)
#define SCTLR_I (1 << 12)
#define SCTLR_V (1 << 13)
#define SCTLR_RR (1 << 14)
#define SCTLR_HA (1 << 17)
#define SCTLR_WXN (1 << 19)
#define SCTLR_UWXN (1 << 20)
#define SCTLR_FI (1 << 21)
#define SCTLR_VE (1 << 24)
#define SCTLR_EE (1 << 25)
#define SCTLR_NMFI (1 << 26)
#define SCTLR_TRE (1 << 28)
#define SCTLR_AFE (1 << 29)
#define SCTLR_TE (1 << 30)

#ifndef ASM
static inline uint32_t read_mpidr(void)
{
uint32_t mpidr;

asm ("mrc p15, 0, %[mpidr], c0, c0, 5"
: [mpidr] "=r" (mpidr)
);

return mpidr;
}

static inline uint32_t read_sctlr(void)
{
uint32_t sctlr;

asm ("mrc p15, 0, %[sctlr], c1, c0, 0"
: [sctlr] "=r" (sctlr)
);

return sctlr;
}

static inline void write_sctlr(uint32_t sctlr)
{
asm ("mcr p15, 0, %[sctlr], c1, c0, 0"
: : [sctlr] "r" (sctlr)
);
}

static inline void write_ttbr0(uint32_t ttbr0)
{
asm ("mcr p15, 0, %[ttbr0], c2, c0, 0"
: : [ttbr0] "r" (ttbr0)
);
}

static inline void write_dacr(uint32_t dacr)
{
asm ("mcr p15, 0, %[dacr], c3, c0, 0"
: : [dacr] "r" (dacr)
);
}

static inline void isb(void)
{
asm ("isb");
}

static inline void dsb(void)
{
asm ("dsb");
}

static inline void write_tlbiallis(void)
{
/* Invalidate entire unified TLB Inner Shareable, r0 ignored */
asm ("mcr p15, 0, r0, c8, c3, 0");
}

static inline uint32_t read_cpsr(void)
{
uint32_t cpsr;

asm ("mrs %[cpsr], cpsr"
: [cpsr] "=r" (cpsr)
);
return cpsr;
}

static inline void write_cpsr(uint32_t cpsr)
{
asm ("msr cpsr, %[cpsr]"
: : [cpsr] "r" (cpsr)
);
}
#endif

#endif /*ARM32_H*/
54 changes: 54 additions & 0 deletions core/arch/arm32/include/arm32_macros.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

.macro read_sctlr reg
mrc p15, 0, \reg, c1, c0, 0
.endm

.macro write_sctlr reg
mcr p15, 0, \reg, c1, c0, 0
.endm

.macro read_scr reg
mrc p15, 0, \reg, c1, c1, 0
.endm

.macro write_scr reg
mcr p15, 0, \reg, c1, c1, 0
.endm

.macro read_mpidr reg
mrc p15, 0, \reg, c0, c0, 5
.endm

.macro write_vbar reg
mcr p15, 0, \reg, c12, c0, 0
.endm

.macro write_mvbar reg
mcr p15, 0, \reg, c12, c0, 1
.endm
33 changes: 33 additions & 0 deletions core/arch/arm32/include/kernel/arch_debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef KERNEL_ARCH_DEBUG_H
#define KERNEL_ARCH_DEBUG_H

void check_canaries(void);

#endif /*KERNEL_ARCH_DEBUG_H*/
35 changes: 35 additions & 0 deletions core/arch/arm32/include/kernel/asc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ASC_H
#define ASC_H

extern int asc_init(void);
extern int __asc_xmit_char(const char p);
extern int __asc_xmit(const char *s);
extern void __asc_flush(void);

#endif

0 comments on commit b010477

Please sign in to comment.