AVB using OP-TEE
Subsystems (4)
v3 cover AVB using OP-TEE
Hi,
This adds support for storing AVB rollback indexes in the RPMB partition. The RPMB partition (content and key) is managed by OP-TEE
(https://www.op-tee.org/) which is a secure OS leveraging ARM TrustZone.
The Linux kernel can already support OP-TEE with reading and updating rollback indexes in the RPMB partition, the catch is that this is needed before the kernel has booted.
The design here is the same as what is in the Linux kernel, with the exception that the user space daemon tee-supplicant is integrated in the OP-TEE driver here (drivers/tee/optee/supplicant.c) instead. A new uclass (UCLASS_TEE) is introduced to provide an abstraction for interfacing with a Trusted Execution Environment (TEE). There's also the OP-TEE driver using UCLASS_TEE for registration.
A Trusted Application (TA) interface is added to be used by the AVB verify functions which are updated accordingly. The TA is managed by OP-TEE and is executed in a secure TrustZone protected environment.
The header files drivers/tee/optee/optee_{msg,msg_supplicant,smc}.h and include/tee/optee_ta_avb.h are copied from
https://github.com/OP-TEE/optee_os/tree/master more or less unmodified. They may need to be updated from time to time in order to support new features.
In MMC there's a new function, mmc_rpmb_route_frames(), which as the name suggests is used to route RPMB frames to/from the MMC. This saves OP-TEE from implementing an MMC driver which would need to share resources with its counterpart here in U-Boot.
This was tested on a Hikey (Kirin 620) board.
I've added myself as maintainer of the TEE stuff.
changes in v3:
* Addressed review comments from Simon Glass
* A few new patches
- "avb_verify: bugfix avb_ops_free() skipping free"
- "tee: add sandbox driver"
- "test_avb: Update pymark.buildconfigspec information for the AVB tests"
- "avb_verify: support sandbox configuration"
- "Kconfig: sandbox: enable cmd_avb and dependencies"
* "sandbox: imply CONFIG_TEE (TEE uclass)", replacing
"configs: sandbox: enable CONFIG_TEE (TEE uclass)"
* Moved sandbox driver to drivers/tee and added code to emulate the AVB TA
* Enabled a few AVB tests (test/py/tests/test_avb.py) for sandbox
* Bugfix tee_find_device()
* Commits "dm: fdt: scan for devices under /firmware too", "cmd: avb read_rb: print rb_idx in hexadecimal",
"cmd: avb: print error message if command fails",
"Add UCLASS_TEE for Trusted Execution Environment",
"tee: add OP-TEE driver",
"Documentation: tee uclass and op-tee driver",
"test: tee: test TEE uclass",
"arm: dt: hikey: Add optee node" and
"sandbox: dt: add sandbox_tee node"
changes in v2:
* Added sandbox driver and a test in test/dm for the new TEE uclass:
Commit ("test: tee: test TEE uclass") and the enabling commits ("sandbox: dt: add sandbox_tee node") and
("configs: sandbox: enable CONFIG_TEE (TEE uclass)")
* Added descriptions of exported structs and functions
* Added documentation for the TEE uclass and the OP-TEE driver with the new commit ("Documentation: tee uclass and op-tee driver")
* Added documentation for the changes in avb_verify
* Addressed review comments from Simon Glass
* Added the commit ("cmd: avb: print error message if command fails")
* Made a few functions static in the OP-TEE driver
* Commit ("cmd: avb read_rb: print rb_idx in hexadecimal") and ("tee: optee: support AVB trusted application");
Thanks,
Jens
Jens Wiklander (20):
dm: fdt: scan for devices under /firmware too
cmd: avb read_rb: print rb_idx in hexadecimal
cmd: avb: print error message if command fails
avb_verify: bugfix avb_ops_free() skipping free
mmc: rpmb: add mmc_rpmb_route_frames()
Add UCLASS_TEE for Trusted Execution Environment dt/bindings: add bindings for optee
tee: add OP-TEE driver
Documentation: tee uclass and op-tee driver
arm: dt: hikey: Add optee node
optee: support routing of rpmb data frames to mmc
tee: optee: support AVB trusted application
sandbox: dt: add sandbox_tee node
sandbox: imply CONFIG_TEE (TEE uclass)
tee: add sandbox driver
test: tee: test TEE uclass
avb_verify: support using OP-TEE TA AVB
test_avb: Update pymark.buildconfigspec information for the AVB tests
avb_verify: support sandbox configuration
Kconfig: sandbox: enable cmd_avb and dependencies
MAINTAINERS | 7 + arch/Kconfig | 5 + arch/arm/dts/hi6220-hikey.dts | 7 + arch/sandbox/dts/sandbox.dts | 4 + arch/sandbox/dts/sandbox64.dts | 4 + arch/sandbox/dts/test.dts | 4 + cmd/avb.c | 19 +- common/avb_verify.c | 120 +++- doc/README.avb2 | 13 + doc/README.tee | 112 +++ .../firmware/linaro,optee-tz.txt | 31 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/core/root.c | 15 +- drivers/fastboot/Kconfig | 2 + drivers/mmc/rpmb.c | 160 +++++ drivers/tee/Kconfig | 29 + drivers/tee/Makefile | 5 + drivers/tee/optee/Kconfig | 27 + drivers/tee/optee/Makefile | 5 + drivers/tee/optee/core.c | 662 ++++++++++++++++++ drivers/tee/optee/optee_msg.h | 425 +++++++++++ drivers/tee/optee/optee_msg_supplicant.h | 240 +++++++ drivers/tee/optee/optee_private.h | 65 ++ drivers/tee/optee/optee_smc.h | 450 ++++++++++++ drivers/tee/optee/rpmb.c | 181 +++++ drivers/tee/optee/supplicant.c | 96 +++ drivers/tee/sandbox.c | 299 ++++++++ drivers/tee/tee-uclass.c | 233 ++++++ include/avb_verify.h | 13 + include/dm/uclass-id.h | 1 + include/mmc.h | 2 + include/sandboxtee.h | 15 + include/tee.h | 374 ++++++++++ include/tee/optee_ta_avb.h | 48 ++ test/dm/Makefile | 1 + test/dm/tee.c | 98 +++ test/py/tests/test_avb.py | 8 +- 38 files changed, 3772 insertions(+), 11 deletions(-) create mode 100644 doc/README.tee create mode 100644 doc/device-tree-bindings/firmware/linaro,optee-tz.txt create mode 100644 drivers/tee/Kconfig create mode 100644 drivers/tee/Makefile create mode 100644 drivers/tee/optee/Kconfig create mode 100644 drivers/tee/optee/Makefile create mode 100644 drivers/tee/optee/core.c create mode 100644 drivers/tee/optee/optee_msg.h create mode 100644 drivers/tee/optee/optee_msg_supplicant.h create mode 100644 drivers/tee/optee/optee_private.h create mode 100644 drivers/tee/optee/optee_smc.h create mode 100644 drivers/tee/optee/rpmb.c create mode 100644 drivers/tee/optee/supplicant.c create mode 100644 drivers/tee/sandbox.c create mode 100644 drivers/tee/tee-uclass.c create mode 100644 include/sandboxtee.h create mode 100644 include/tee.h create mode 100644 include/tee/optee_ta_avb.h create mode 100644 test/dm/tee.c
Signature · 1 line
2.17.1
PATCH v3 1/20 dm: fdt: scan for devices under /firmware too
Just as /chosen may contain devices /firmware may contain devices, scan for devices under /firmware too.
--- drivers/core/root.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/core/root.c +10 -5
@@ -265,9 +265,15 @@ static int dm_scan_fdt_node(struct udevice *parent, const void *blob,for (offset =fdt_first_subnode (blob, offset); offset >0 ; offset =fdt_next_subnode (blob, offset)) { -/* "chosen" node isn't a device itself but may contain some: */ -if (!strcmp (fdt_get_name (blob, offset,NULL ),"chosen" )) { -pr_debug ("parsing subnodes of \"chosen\"\n" ); +const char *node_name =fdt_get_name (blob, offset,NULL ); + +/* +* The "chosen" and "firmware" nodes aren't devices +* themselves but may contain some: +*/ +if (!strcmp (node_name,"chosen" ) || + !strcmp (node_name,"firmware" )) { +pr_debug ("parsing subnodes of \"%s\"\n" , node_name); err =dm_scan_fdt_node (parent, blob, offset, pre_reloc_only);
@@ -286,8 +292,7 @@ static int dm_scan_fdt_node(struct udevice *parent, const void *blob, err =lists_bind_fdt (parent,offset_to_ofnode (offset),NULL );if (err && !ret) { ret = err; -debug ("%s: ret=%d\n" ,fdt_get_name (blob, offset,NULL ), - ret); +debug ("%s: ret=%d\n" , node_name, ret); } }
Signature · 1 line
2.17.1
PATCH v3 2/20 cmd: avb read_rb: print rb_idx in hexadecimal
In reply to Jens WiklanderPrior to this patch was do_avb_write_rb() reading supplied rb_idx as a hexadecimal number while do_avb_read_rb() printed the read out rb_idx as decimal number. For consistency change do_avb_read_rb() to print rb_idx as a hexadecimal number too.
--- cmd/avb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/avb.c +1 -1
@@ -158,7 +158,7 @@ int do_avb_read_rb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])if (avb_ops->read_rollback_index (avb_ops, index, &rb_idx) ==AVB_IO_RESULT_OK ) { -printf ("Rollback index: %llu\n" , rb_idx); +printf ("Rollback index: %llx\n" , rb_idx);return CMD_RET_SUCCESS ; }return CMD_RET_FAILURE ;
Signature · 1 line
2.17.1
PATCH v3 3/20 cmd: avb: print error message if command fails
In reply to Jens Wiklander--- cmd/avb.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
cmd/avb.c +17 -0
@@ -35,6 +35,8 @@ int do_avb_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])if (avb_ops)return CMD_RET_SUCCESS ; +printf ("Failed to initialize avb2\n" ); +return CMD_RET_FAILURE ; }
@@ -65,6 +67,8 @@ int do_avb_read_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])return CMD_RET_SUCCESS ; } +printf ("Failed to read from partition\n" ); +return CMD_RET_FAILURE ; }
@@ -108,6 +112,8 @@ int do_avb_read_part_hex(cmd_tbl_t *cmdtp, int flag, int argc,return CMD_RET_SUCCESS ; } +printf ("Failed to read from partition\n" ); +free (buffer);return CMD_RET_FAILURE ; }
@@ -138,6 +144,8 @@ int do_avb_write_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])return CMD_RET_SUCCESS ; } +printf ("Failed to write in partition\n" ); +return CMD_RET_FAILURE ; }
@@ -161,6 +169,9 @@ int do_avb_read_rb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])printf ("Rollback index: %llx\n" , rb_idx);return CMD_RET_SUCCESS ; } + +printf ("Failed to read rollback index\n" ); +return CMD_RET_FAILURE ; }
@@ -184,6 +195,8 @@ int do_avb_write_rb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) AVB_IO_RESULT_OK)return CMD_RET_SUCCESS ; +printf ("Failed to write rollback index\n" ); +return CMD_RET_FAILURE ; }
@@ -210,6 +223,8 @@ int do_avb_get_uuid(cmd_tbl_t *cmdtp, int flag,return CMD_RET_SUCCESS ; } +printf ("Failed to read UUID\n" ); +return CMD_RET_FAILURE ; }
@@ -320,6 +335,8 @@ int do_avb_is_unlocked(cmd_tbl_t *cmdtp, int flag,return CMD_RET_SUCCESS ; } +printf ("Can't determine device lock state.\n" ); +return CMD_RET_FAILURE ; }
Signature · 1 line
2.17.1
PATCH v3 4/20 avb_verify: bugfix avb_ops_free() skipping free
In reply to Jens WiklanderBefore this patch avb_ops_free() was returning early if supplied "ops" argument was not NULL. This patch fixes this by inverting the condition.
--- common/avb_verify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/avb_verify.c +1 -1
@@ -732,7 +732,7 @@ void avb_ops_free(AvbOps *ops) {struct AvbOpsData *ops_data; -if (ops) +if (!ops)return ; ops_data = ops->user_data;
Signature · 1 line
2.17.1
PATCH v3 4/20 avb_verify: bugfix avb_ops_free() skipping free
Quoted 7 lines · Jens Wiklander
Before this patch
avb_ops_free()was returning early if supplied "ops" argument was not NULL. This patch fixes this by inverting the condition.Signed-off-by Jens Wiklander <[email protected]>--- common/avb_verify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v3 5/20 mmc: rpmb: add mmc_rpmb_route_frames()
In reply to Jens WiklanderAdds mmc_rpmb_route_frames() to route RPMB data frames from/to an external entity.
--- drivers/mmc/rpmb.c | 160 +++++++++++++++++++++++++++++++++++++++++++++ include/mmc.h | 2 + 2 files changed, 162 insertions(+)
drivers/mmc/rpmb.c +160 -0
@@ -321,3 +321,163 @@ int mmc_rpmb_write(struct mmc *mmc, void *addr, unsigned short blk, }return i; } + +static int send_write_mult_block (struct mmc *mmc,const struct s_rpmb *frm, +unsigned short cnt) +{ +struct mmc_cmd cmd = { + .cmdidx =MMC_CMD_WRITE_MULTIPLE_BLOCK , + .resp_type = MMC_RSP_R1b, + }; +struct mmc_data data = { + .src = (const void *)frm, + .blocks = cnt, + .blocksize =sizeof (*frm), + .flags =MMC_DATA_WRITE , + }; + +return mmc_send_cmd (mmc, &cmd, &data); +} + +static int send_read_mult_block (struct mmc *mmc,struct s_rpmb *frm, +unsigned short cnt) +{ +struct mmc_cmd cmd = { + .cmdidx =MMC_CMD_READ_MULTIPLE_BLOCK , + .resp_type =MMC_RSP_R1 , + }; +struct mmc_data data = { + .dest = (void *)frm, + .blocks = cnt, + .blocksize =sizeof (*frm), + .flags =MMC_DATA_READ , + }; + +return mmc_send_cmd (mmc, &cmd, &data); +} + +static int rpmb_route_write_req (struct mmc *mmc,struct s_rpmb *req, +unsigned short req_cnt,struct s_rpmb *rsp, +unsigned short rsp_cnt) +{ +int ret; + +/* +* Send the write request. +*/ + ret =mmc_set_blockcount (mmc, req_cnt, true); +if (ret) +return ret; + + ret =send_write_mult_block (mmc, req, req_cnt); +if (ret) +return ret; + +/* +* Read the result of the request. +*/ + ret =mmc_set_blockcount (mmc,1 , false); +if (ret) +return ret; + +memset (rsp,0 ,sizeof (*rsp)); + rsp->request =cpu_to_be16 (RPMB_REQ_STATUS ); + ret =send_write_mult_block (mmc, rsp,1 ); +if (ret) +return ret; + + ret =mmc_set_blockcount (mmc,1 , false); +if (ret) +return ret; + +return send_read_mult_block (mmc, rsp,1 ); +} + +static int rpmb_route_read_req (struct mmc *mmc,struct s_rpmb *req, +unsigned short req_cnt,struct s_rpmb *rsp, +unsigned short rsp_cnt) +{ +int ret; + +/* +* Send the read request. +*/ + ret =mmc_set_blockcount (mmc,1 , false); +if (ret) +return ret; + + ret =send_write_mult_block (mmc, req,1 ); +if (ret) +return ret; + +/* +* Read the result of the request. +*/ + + ret =mmc_set_blockcount (mmc, rsp_cnt, false); +if (ret) +return ret; + +return send_read_mult_block (mmc, rsp, rsp_cnt); +} + +static int rpmb_route_frames (struct mmc *mmc,struct s_rpmb *req, +unsigned short req_cnt,struct s_rpmb *rsp, +unsigned short rsp_cnt) +{ +unsigned short n; + +/* +* If multiple request frames are provided, make sure that all are +* of the same type. +*/ +for (n =1 ; n < req_cnt; n++) +if (req[n].request != req->request) +return -EINVAL ; + +switch (be16_to_cpu (req->request)) { +case RPMB_REQ_KEY : +if (req_cnt !=1 || rsp_cnt !=1 ) +return -EINVAL ; +return rpmb_route_write_req (mmc, req, req_cnt, rsp, rsp_cnt); + +case RPMB_REQ_WRITE_DATA : +if (!req_cnt || rsp_cnt !=1 ) +return -EINVAL ; +return rpmb_route_write_req (mmc, req, req_cnt, rsp, rsp_cnt); + +case RPMB_REQ_WCOUNTER : +if (req_cnt !=1 || rsp_cnt !=1 ) +return -EINVAL ; +return rpmb_route_read_req (mmc, req, req_cnt, rsp, rsp_cnt); + +case RPMB_REQ_READ_DATA : +if (req_cnt !=1 || !req_cnt) +return -EINVAL ; +return rpmb_route_read_req (mmc, req, req_cnt, rsp, rsp_cnt); + +default : +debug ("Unsupported message type: %d\n" , +be16_to_cpu (req->request)); +return -EINVAL ; + } +} + +int mmc_rpmb_route_frames (struct mmc *mmc,void *req,unsigned long reqlen, +void *rsp,unsigned long rsplen) +{ +/* +* Whoever crafted the data supplied to this function knows how to +* format the PRMB frames and which response is expected. If +* there's some unexpected mismatch it's more helpful to report an +* error immediately than trying to guess what was the intention +* and possibly just delay an eventual error which will be harder +* to track down. +*/ + +if (reqlen %sizeof (struct s_rpmb ) || rsplen %sizeof (struct s_rpmb )) +return -EINVAL ; + +return rpmb_route_frames (mmc, req, reqlen /sizeof (struct s_rpmb ), + rsp, rsplen /sizeof (struct s_rpmb )); +}
include/mmc.h +2 -0
@@ -748,6 +748,8 @@ int mmc_rpmb_read(struct mmc *mmc, void *addr, unsigned short blk, unsigned short cnt, unsigned char *key);int mmc_rpmb_write (struct mmc *mmc,void *addr,unsigned short blk,unsigned short cnt,unsigned char *key); +int mmc_rpmb_route_frames (struct mmc *mmc,void *req,unsigned long reqlen, +void *rsp,unsigned long rsplen);#ifdef CONFIG_CMD_BKOPS_ENABLE int mmc_set_bkops_enable (struct mmc *mmc);#endif
Signature · 1 line
2.17.1
PATCH v3 5/20 mmc: rpmb: add mmc_rpmb_route_frames()
Hi Jens,
Quoted 10 lines · Jens Wiklander
Adds
mmc_rpmb_route_frames()to route RPMB data frames from/to an external entity.Tested-by Igor Opaniuk <[email protected]>Signed-off-by Jens Wiklander <[email protected]>--- drivers/mmc/rpmb.c | 160 +++++++++++++++++++++++++++++++++++++++++++++ include/mmc.h | 2 + 2 files changed, 162 insertions(+)
[..]
include/mmc.h int mmc_rpmb_read(struct mmc *mmc, void *addr, unsigned short blk, · line 752
Quoted 10 lines
include/mmc.h +2
-0@@ -748,6 +748,8 @@ int mmc_rpmb_read(struct mmc *mmc, void *addr, unsigned short blk, unsigned short cnt, unsigned char *key);int mmc_rpmb_write (struct mmc *mmc,void *addr,unsigned short blk,unsigned short cnt,unsigned char *key); +int mmc_rpmb_route_frames (struct mmc *mmc,void *req,unsigned long reqlen, +void *rsp,unsigned long rsplen);
Please can you add a full comment to this function? All header-file functions should be commented.
Quoted 6 lines
include/mmc.h +0
-1#ifdef CONFIG_CMD_BKOPS_ENABLE int mmc_set_bkops_enable (struct mmc *mmc);#endif --2.17.1
Regards,
Simon
PATCH v3 5/20 mmc: rpmb: add mmc_rpmb_route_frames()
Hi Simon,
Quoted 16 lines · Simon Glass
Hi Jens,
Quoted 10 lines · Jens Wiklander
Adds
mmc_rpmb_route_frames()to route RPMB data frames from/to an external entity.Tested-by Igor Opaniuk <[email protected]>Signed-off-by Jens Wiklander <[email protected]>--- drivers/mmc/rpmb.c | 160 +++++++++++++++++++++++++++++++++++++++++++++ include/mmc.h | 2 + 2 files changed, 162 insertions(+)[..]
Quoted 13 lines
include/mmc.h int mmc_rpmb_read(struct mmc *mmc, void *addr, unsigned short blk, · line 752
Quoted 10 lines
include/mmc.h +2
-0@@ -748,6 +748,8 @@ int mmc_rpmb_read(struct mmc *mmc, void *addr, unsigned short blk, unsigned short cnt, unsigned char *key);int mmc_rpmb_write (struct mmc *mmc,void *addr,unsigned short blk,unsigned short cnt,unsigned char *key); +int mmc_rpmb_route_frames (struct mmc *mmc,void *req,unsigned long reqlen, +void *rsp,unsigned long rsplen);Please can you add a full comment to this function? All header-file functions should be commented.
I'll fix.
Thanks,
Jens
PATCH v3 6/20 Add UCLASS_TEE for Trusted Execution Environment
In reply to Jens WiklanderAdds a uclass to interface with a TEE (Trusted Execution Environment).
A TEE driver is a driver that interfaces with a trusted OS running in some secure environment, for example, TrustZone on ARM cpus, or a separate secure co-processor etc.
The TEE subsystem can serve a TEE driver for a Global Platform compliant TEE, but it's not limited to only Global Platform TEEs.
The over all design is based on the TEE subsystem in the Linux kernel, tailored for U-Boot.
--- MAINTAINERS | 6 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/tee/Kconfig | 11 ++ drivers/tee/Makefile | 3 + drivers/tee/tee-uclass.c | 209 ++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/tee.h | 336 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 569 insertions(+) create mode 100644 drivers/tee/Kconfig create mode 100644 drivers/tee/Makefile create mode 100644 drivers/tee/tee-uclass.c create mode 100644 include/tee.h
MAINTAINERS +6 -0
@@ -571,6 +571,12 @@ TQ GROUP S: Orphaned (Since 2016-02) T: git git://git.denx.de/u-boot-tq-group.git +TEE +M: Jens Wiklander <[email protected]> +S: Maintained +F: drivers/tee/ +F: include/tee.h + UBI M: Kyungmin Park <[email protected]> M: Heiko Schocher <[email protected]>
drivers/Kconfig +2 -0
@@ -94,6 +94,8 @@ source "drivers/spmi/Kconfig" source "drivers/sysreset/Kconfig" +source "drivers/tee/Kconfig" + source "drivers/thermal/Kconfig" source "drivers/timer/Kconfig"
drivers/Makefile +1 -0
@@ -103,6 +103,7 @@ obj-y += smem/ obj-y += soc/ obj-$(CONFIG_REMOTEPROC) += remoteproc/ obj-y += thermal/ +obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_MACH_PIC32) += ddr/microchip/ endif
drivers/tee/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +# Generic Trusted Execution Environment Configuration +config TEE + bool "Trusted Execution Environment support" + depends on ARM && (ARM64 || CPU_V7A) + select ARM_SMCCC + help + This implements a generic interface towards a Trusted Execution + Environment (TEE). A TEE is a trusted OS running in some secure + environment, for example, TrustZone on ARM cpus, or a separate + secure co-processor etc. See also: + https://en.wikipedia.org/wiki/Trusted_execution_environment
drivers/tee/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-y += tee-uclass.o
drivers/tee/tee-uclass.c new file +209 -0
209 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -81,6 +81,7 @@ enum uclass_id {UCLASS_SPI_GENERIC ,/* Generic SPI flash target */ UCLASS_SYSCON ,/* System configuration device */ UCLASS_SYSRESET ,/* System reset device */ +UCLASS_TEE ,/* Trusted Execution Environment device */ UCLASS_THERMAL ,/* Thermal sensor */ UCLASS_TIMER ,/* Timer device */ UCLASS_TPM, /* Trusted Platform Module TIS interface */
include/tee.h new file +336 -0
336 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 7/20 dt/bindings: add bindings for optee
In reply to Jens WiklanderSync with c8bfafb15944 ("dt/bindings: add bindings for optee") from Linux kernel.
Introduces linaro prefix and adds bindings for ARM TrustZone based OP-TEE implementation.
--- .../firmware/linaro,optee-tz.txt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 doc/device-tree-bindings/firmware/linaro,optee-tz.txt
doc/device-tree-bindings/firmware/linaro,optee-tz.txt new file +31 -0
@@ -0,0 +1,31 @@ +OP-TEE Device Tree Bindings + +OP-TEE is a piece of software using hardware features to provide a Trusted +Execution Environment. The security can be provided with ARM TrustZone, but +also by virtualization or a separate chip. + +We're using "linaro" as the first part of the compatible property for +the reference implementation maintained by Linaro. + +* OP-TEE based on ARM TrustZone required properties: + +- compatible : should contain "linaro,optee-tz" + +- method : The method of calling the OP-TEE Trusted OS. Permitted + values are: + + "smc" : SMC #0, with the register assignments specified + in drivers/tee/optee/optee_smc.h + + "hvc" : HVC #0, with the register assignments specified + in drivers/tee/optee/optee_smc.h + + + +Example: + firmware { + optee { + compatible = "linaro,optee-tz"; + method = "smc"; + }; + };
Signature · 1 line
2.17.1
PATCH v3 7/20 dt/bindings: add bindings for optee
Quoted 11 lines · Jens Wiklander
Sync with
c8bfafb15944("dt/bindings: add bindings for optee") from Linux kernel.Introduces linaro prefix and adds bindings for ARM TrustZone based OP-TEE implementation.
Signed-off-by Jens Wiklander <[email protected]>--- .../firmware/linaro,optee-tz.txt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 doc/device-tree-bindings/firmware/linaro,optee-tz.txt
PATCH v3 8/20 tee: add OP-TEE driver
In reply to Jens WiklanderAdds a OP-TEE driver.
* Targets ARM and ARM64
* Supports using any U-Boot memory as shared memory
* Probes OP-TEE version using SMCs
* Uses OPTEE message protocol version 2 to communicate with secure world
--- drivers/tee/Kconfig | 10 + drivers/tee/Makefile | 1 + drivers/tee/optee/Kconfig | 11 + drivers/tee/optee/Makefile | 4 + drivers/tee/optee/core.c | 654 +++++++++++++++++++++++ drivers/tee/optee/optee_msg.h | 425 +++++++++++++++ drivers/tee/optee/optee_msg_supplicant.h | 240 +++++++++ drivers/tee/optee/optee_private.h | 12 + drivers/tee/optee/optee_smc.h | 450 ++++++++++++++++ drivers/tee/optee/supplicant.c | 93 ++++ 10 files changed, 1900 insertions(+) create mode 100644 drivers/tee/optee/Kconfig create mode 100644 drivers/tee/optee/Makefile create mode 100644 drivers/tee/optee/core.c create mode 100644 drivers/tee/optee/optee_msg.h create mode 100644 drivers/tee/optee/optee_msg_supplicant.h create mode 100644 drivers/tee/optee/optee_private.h create mode 100644 drivers/tee/optee/optee_smc.h create mode 100644 drivers/tee/optee/supplicant.c
drivers/tee/Kconfig +10 -0
@@ -9,3 +9,13 @@ config TEE environment, for example, TrustZone on ARM cpus, or a separate secure co-processor etc. See also: https://en.wikipedia.org/wiki/Trusted_execution_environment + +if TEE + +menu "TEE drivers" + +source "drivers/tee/optee/Kconfig" + +endmenu + +endif
drivers/tee/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0+ obj-y += tee-uclass.o +obj-$(CONFIG_OPTEE) += optee/
drivers/tee/optee/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +# OP-TEE Trusted Execution Environment Configuration +config OPTEE + bool "OP-TEE" + depends on ARM_SMCCC + help + This implements the OP-TEE Trusted Execution Environment (TEE) + driver. OP-TEE is a Trusted OS designed primarily to rely on the + ARM TrustZone(R) technology as the underlying hardware isolation + mechanism. This driver can request services from OP-TEE, but also + handle Remote Procedure Calls (RPC) from OP-TEE needed to + execute a service. For more information see: https://www.op-tee.org
drivers/tee/optee/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-y += core.o +obj-y += supplicant.o
drivers/tee/optee/core.c new file +654 -0
654 lines not on this page · raw message
drivers/tee/optee/optee_msg.h new file +425 -0
425 lines not on this page · raw message
drivers/tee/optee/optee_msg_supplicant.h new file +240 -0
240 lines not on this page · raw message
drivers/tee/optee/optee_private.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (c) 2018 Linaro Limited +*/ + +#ifndef __OPTEE_PRIVATE_H +#define __OPTEE_PRIVATE_H + +void *optee_alloc_and_init_page_list (void *buf,ulong len,u64 *phys_buf_ptr); +void optee_suppl_cmd (struct udevice *dev,void *shm,void **page_list); + +#endif /* __OPTEE_PRIVATE_H */
drivers/tee/optee/optee_smc.h new file +450 -0
450 lines not on this page · raw message
drivers/tee/optee/supplicant.c new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 9/20 Documentation: tee uclass and op-tee driver
In reply to Jens Wiklander--- doc/README.tee | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 doc/README.tee
doc/README.tee new file +112 -0
@@ -0,0 +1,112 @@ +============= +TEE uclass +============= + +This document describes the TEE uclass in U-Boot + +A TEE (Trusted Execution Environment) is a trusted OS running in some +secure environment, for example, TrustZone on ARM CPUs, or a separate +secure co-processor etc. A TEE driver handles the details needed to +communicate with the TEE. + +This uclass deals with: + +- Registration of TEE drivers + +- Managing shared memory between U-Boot and the TEE + +- Providing a generic API to the TEE + +The TEE interface +================= + +include/tee.h defines the generic interface to a TEE. + +A client finds the TEE device via tee_find_device(). Other important functions +when interfacing with a TEE are: + +- tee_shm_alloc(), tee_shm_register() and tee_shm_free() to manage shared + memory objects often needed when communicating with the TEE. + +- tee_get_version() lets the client know which the capabilities of the TEE + device. + +- tee_open_session() opens a session to a Trusted Application + +- tee_invoke_func() invokes a function in a Trusted Application + +- tee_close_session() closes a session to a Trusted Application + +Much of the communication between clients and the TEE is opaque to the +driver. The main job for the driver is to receive requests from the +clients, forward them to the TEE and send back the results. + +OP-TEE driver +============= + +The OP-TEE driver handles OP-TEE [1] based TEEs. Currently it is only the ARM +TrustZone based OP-TEE solution that is supported. + +Lowest level of communication with OP-TEE builds on ARM SMC Calling +Convention (SMCCC) [2], which is the foundation for OP-TEE's SMC interface +[3] used internally by the driver. Stacked on top of that is OP-TEE Message +Protocol [4]. + +OP-TEE SMC interface provides the basic functions required by SMCCC and some +additional functions specific for OP-TEE. The most interesting functions are: + +- OPTEE_SMC_FUNCID_CALLS_UID (part of SMCCC) returns the version information + which is then returned by TEE_IOC_VERSION + +- OPTEE_SMC_CALL_GET_OS_UUID returns the particular OP-TEE implementation, used + to tell, for instance, a TrustZone OP-TEE apart from an OP-TEE running on a + separate secure co-processor. + +- OPTEE_SMC_CALL_WITH_ARG drives the OP-TEE message protocol + +- OPTEE_SMC_GET_SHM_CONFIG lets the driver and OP-TEE agree on which memory + range to used for shared memory between Linux and OP-TEE. + +The GlobalPlatform TEE Client API [5] is implemented on top of the generic +TEE API. + +Picture of the relationship between the different components in the +OP-TEE architecture: + + U-Boot Secure world + ~~~~~~ ~~~~~~~~~~~~ + +------------+ +-------------+ + | Client | | Trusted | + | | | Application | + +------------+ +-------------+ + /\ /\ + || || + \/ \/ + +------------+ +-------------+ + | TEE | | TEE Internal| + | uclass | | API | + +------------+ +-------------+ + | OP-TEE | | OP-TEE | + | driver | | Trusted OS | + +------------+-----------+-------------+ + | OP-TEE MSG | + | SMCCC (OPTEE_SMC_CALL_*) | + +--------------------------------------+ + +RPC (Remote Procedure Call) are requests from secure world to the driver. +An RPC is identified by a special range of SMCCC return values from +OPTEE_SMC_CALL_WITH_ARG. + +References +========== + +[1] https://github.com/OP-TEE/optee_os + +[2] http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html + +[3] drivers/tee/optee/optee_smc.h + +[4] drivers/tee/optee/optee_msg.h + +[5] http://www.globalplatform.org/specificationsdevice.asp look for + "TEE Client API Specification v1.0" and click download.
Signature · 1 line
2.17.1
PATCH v3 10/20 arm: dt: hikey: Add optee node
In reply to Jens WiklanderSync with 14e21cb8f811 ("arm64: dt: hikey: Add optee node" from Linux kernel.
--- arch/arm/dts/hi6220-hikey.dts | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm/dts/hi6220-hikey.dts +7 -0
@@ -31,6 +31,13 @@ device_type = "memory"; reg = <0x0 0x0 0x0 0x40000000>; }; + + firmware { + optee { + compatible = "linaro,optee-tz"; + method = "smc"; + }; + }; }; &uart2 {
Signature · 1 line
2.17.1
PATCH v3 11/20 optee: support routing of rpmb data frames to mmc
In reply to Jens WiklanderAdds support in optee supplicant to route signed (MACed) RPMB frames from OP-TEE Secure OS to MMC and vice versa to manipulate the RPMB partition.
--- drivers/tee/optee/Makefile | 1 + drivers/tee/optee/core.c | 8 ++ drivers/tee/optee/optee_private.h | 55 ++++++++- drivers/tee/optee/rpmb.c | 181 ++++++++++++++++++++++++++++++ drivers/tee/optee/supplicant.c | 3 + 5 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 drivers/tee/optee/rpmb.c
drivers/tee/optee/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-y += core.o obj-y += supplicant.o +obj-$(CONFIG_SUPPORT_EMMC_RPMB) += rpmb.o
drivers/tee/optee/core.c +8 -0
@@ -315,6 +315,13 @@ static u32 do_call_with_arg(struct udevice *dev, struct optee_msg_arg *arg) param.a3 = res.a3;handle_rpc (dev, ¶m, &page_list); }else { +/* +* In case we've accessed RPMB to serve an RPC +* request we need to restore the previously +* selected partition as the caller may expect it +* to remain unchanged. +*/ +optee_suppl_rpmb_release (dev);return call_err_to_res (res.a0); } }
@@ -651,4 +658,5 @@ U_BOOT_DRIVER(optee) = { .probe = optee_probe, .ops = &optee_ops, .platdata_auto_alloc_size = sizeof(struct optee_pdata), + .priv_auto_alloc_size = sizeof(struct optee_private), };
drivers/tee/optee/optee_private.h +54 -1
61 lines not on this page · raw message
drivers/tee/optee/rpmb.c new file +181 -0
181 lines not on this page · raw message
drivers/tee/optee/supplicant.c +3 -0
@@ -85,6 +85,9 @@ void optee_suppl_cmd(struct udevice *dev, struct tee_shm *shm_arg,debug ("OPTEE_MSG_RPC_CMD_FS not implemented\n" ); arg->ret =TEE_ERROR_NOT_IMPLEMENTED ;break ; +case OPTEE_MSG_RPC_CMD_RPMB : +optee_suppl_cmd_rpmb (dev, arg); +break ;default : arg->ret =TEE_ERROR_NOT_IMPLEMENTED ; }
Signature · 1 line
2.17.1
PATCH v3 12/20 tee: optee: support AVB trusted application
In reply to Jens WiklanderAdds configuration option OPTEE_TA_AVB and a header file describing the interface to the Android Verified Boot 2.0 (AVB) trusted application provided by OP-TEE.
--- MAINTAINERS | 1 + drivers/tee/optee/Kconfig | 16 +++++++++++++ drivers/tee/tee-uclass.c | 24 +++++++++++++++++++ include/tee.h | 38 ++++++++++++++++++++++++++++++ include/tee/optee_ta_avb.h | 48 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 include/tee/optee_ta_avb.h
MAINTAINERS +1 -0
@@ -576,6 +576,7 @@ M: Jens Wiklander <[email protected]> S: Maintained F: drivers/tee/ F: include/tee.h +F: include/tee/ UBI M: Kyungmin Park <[email protected]>
drivers/tee/optee/Kconfig +16 -0
@@ -9,3 +9,19 @@ config OPTEE mechanism. This driver can request services from OP-TEE, but also handle Remote Procedure Calls (RPC) from OP-TEE needed to execute a service. For more information see: https://www.op-tee.org + +if OPTEE + +menu "OP-TEE options" + +config OPTEE_TA_AVB + bool "Support AVB TA" + default y + help + Enables support for the AVB Trusted Application (TA) in OP-TEE. + The TA can support the "avb" subcommands "read_rb", "write"rb" + and "is_unlocked". + +endmenu + +endif
drivers/tee/tee-uclass.c +24 -0
@@ -207,3 +207,27 @@ UCLASS_DRIVER(tee) = { .pre_probe = tee_pre_probe, .pre_remove = tee_pre_remove, }; + +void tee_optee_ta_uuid_from_octets (struct tee_optee_ta_uuid *d, +const u8 s[TEE_UUID_LEN ]) +{ + d->time_low = ((u32 )s[0 ] <<24 ) | ((u32 )s[1 ] <<16 ) | + ((u32 )s[2 ] <<8 ) | s[3 ], + d->time_mid = ((u32 )s[4 ] <<8 ) | s[5 ]; + d->time_hi_and_version = ((u32 )s[6 ] <<8 ) | s[7 ]; +memcpy (d->clock_seq_and_node, s +8 ,sizeof (d->clock_seq_and_node)); +} + +void tee_optee_ta_uuid_to_octets (u8 d[TEE_UUID_LEN ], +const struct tee_optee_ta_uuid *s) +{ + d[0 ] = s->time_low >>24 ; + d[1 ] = s->time_low >>16 ; + d[2 ] = s->time_low >>8 ; + d[3 ] = s->time_low; + d[4 ] = s->time_mid >>8 ; + d[5 ] = s->time_mid; + d[6 ] = s->time_hi_and_version >>8 ; + d[7 ] = s->time_hi_and_version; +memcpy (d +8 , s->clock_seq_and_node,sizeof (s->clock_seq_and_node)); +}
include/tee.h +38 -0
@@ -49,6 +49,22 @@#define TEE_ORIGIN_TRUSTED_APP 0x00000004struct udevice ; + +/** +* struct tee_optee_ta_uuid - OP-TEE Trusted Application (TA) UUID format +* +* Used to identify an OP-TEE TA and define suitable to initialize structs +* of this format is distributed with the interface of the TA. The +* individual fields of this struct doesn't have any special meaning in +* OP-TEE. See RFC4122 for details on the format. +*/ +struct tee_optee_ta_uuid { +u32 time_low; +u16 time_mid; +u16 time_hi_and_version; +u8 clock_seq_and_node[8 ]; +}; +/** * struct tee_shm - memory shared with the TEE * @dev: The TEE device
@@ -333,4 +349,26 @@ int tee_close_session(struct udevice *dev, u32 session);int tee_invoke_func (struct udevice *dev,struct tee_invoke_arg *arg,uint num_param,struct tee_param *param); +/** +* tee_optee_ta_uuid_from_octets() - Converts to struct tee_optee_ta_uuid +* @d: Destination struct +* @s: Source UUID octets +* +* Conversion to a struct tee_optee_ta_uuid represantion from binary octet +* representation. +*/ +void tee_optee_ta_uuid_from_octets (struct tee_optee_ta_uuid *d, +const u8 s[TEE_UUID_LEN ]); + +/** +* tee_optee_ta_uuid_to_octets() - Converts from struct tee_optee_ta_uuid +* @d: Destination UUID octets +* @s: Source struct +* +* Conversion from a struct tee_optee_ta_uuid represantion to binary octet +* representation. +*/ +void tee_optee_ta_uuid_to_octets (u8 d[TEE_UUID_LEN ], +const struct tee_optee_ta_uuid *s); +#endif /* __TEE_H */
include/tee/optee_ta_avb.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 13/20 sandbox: dt: add sandbox_tee node
In reply to Jens WiklanderAdds a sandbox_tee node to enable the sandbox tee driver in all the sandbox dts files.
--- arch/sandbox/dts/sandbox.dts | 4 ++++ arch/sandbox/dts/sandbox64.dts | 4 ++++ arch/sandbox/dts/test.dts | 4 ++++ 3 files changed, 12 insertions(+)
arch/sandbox/dts/sandbox.dts +4 -0
@@ -311,6 +311,10 @@ }; }; }; + + sandbox_tee { + compatible = "sandbox,tee"; + }; }; #include "cros-ec-keyboard.dtsi"
arch/sandbox/dts/sandbox64.dts +4 -0
@@ -311,6 +311,10 @@ }; }; }; + + sandbox_tee { + compatible = "sandbox,tee"; + }; }; #include "cros-ec-keyboard.dtsi"
arch/sandbox/dts/test.dts +4 -0
@@ -604,6 +604,10 @@ }; }; }; + + sandbox_tee { + compatible = "sandbox,tee"; + }; }; #include "sandbox_pmic.dtsi"
Signature · 1 line
2.17.1
PATCH v3 14/20 sandbox: imply CONFIG_TEE (TEE uclass)
In reply to Jens Wiklander--- arch/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/Kconfig +1 -0
@@ -91,6 +91,7 @@ config SANDBOX imply HASH_VERIFY imply LZMA imply SCSI + imply TEE config SH bool "SuperH architecture"
Signature · 1 line
2.17.1
PATCH v3 14/20 sandbox: imply CONFIG_TEE (TEE uclass)
Quoted 4 lines · Jens Wiklander
Signed-off-by Jens Wiklander <[email protected]>--- arch/Kconfig | 1 + 1 file changed, 1 insertion(+)
PATCH v3 15/20 tee: add sandbox driver
In reply to Jens WiklanderAdds a sandboxtee driver which emulates a generic TEE with the OP-TEE AVB TA.
--- drivers/tee/Kconfig | 12 +- drivers/tee/Makefile | 1 + drivers/tee/optee/Kconfig | 2 +- drivers/tee/sandbox.c | 299 ++++++++++++++++++++++++++++++++++++++ include/sandboxtee.h | 15 ++ 5 files changed, 326 insertions(+), 3 deletions(-) create mode 100644 drivers/tee/sandbox.c create mode 100644 include/sandboxtee.h
drivers/tee/Kconfig +10 -2
@@ -1,8 +1,8 @@ # Generic Trusted Execution Environment Configuration config TEE bool "Trusted Execution Environment support" - depends on ARM && (ARM64 || CPU_V7A) - select ARM_SMCCC + depends on (ARM && (ARM64 || CPU_V7A)) || SANDBOX + select ARM_SMCCC if ARM help This implements a generic interface towards a Trusted Execution Environment (TEE). A TEE is a trusted OS running in some secure
@@ -14,6 +14,14 @@ if TEE menu "TEE drivers" +config SANDBOX_TEE + bool "Sandbox TEE emulator" + depends on SANDBOX + default y + help + This emulates a generic TEE needed for testing including the AVB + TA. + source "drivers/tee/optee/Kconfig" endmenu
drivers/tee/Makefile +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ obj-y += tee-uclass.o +obj-$(CONFIG_SANDBOX) += sandbox.o obj-$(CONFIG_OPTEE) += optee/
drivers/tee/optee/Kconfig +1 -1
@@ -10,7 +10,7 @@ config OPTEE handle Remote Procedure Calls (RPC) from OP-TEE needed to execute a service. For more information see: https://www.op-tee.org -if OPTEE +if OPTEE || SANDBOX menu "OP-TEE options"
drivers/tee/sandbox.c new file +299 -0
299 lines not on this page · raw message
include/sandboxtee.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2018 Linaro Limited +*/ + +#ifndef __SANDBOXTEE_H +#define __SANDBOXTEE_H + +struct sandbox_tee_state { +u32 session; +int num_shms; +void *ta; +}; + +#endif /*__SANDBOXTEE_H*/
Signature · 1 line
2.17.1
PATCH v3 15/20 tee: add sandbox driver
Hi Jens,
Quoted 1 line · Jens Wiklander
Adds a sandboxtee driver which emulates a generic TEE with the OP-TEE
sandbox tee
Quoted 12 lines
AVB TA.
Signed-off-by Jens Wiklander <[email protected]>--- drivers/tee/Kconfig | 12 +- drivers/tee/Makefile | 1 + drivers/tee/optee/Kconfig | 2 +- drivers/tee/sandbox.c | 299 ++++++++++++++++++++++++++++++++++++++ include/sandboxtee.h | 15 ++ 5 files changed, 326 insertions(+), 3 deletions(-) create mode 100644 drivers/tee/sandbox.c create mode 100644 include/sandboxtee.h
nits below.
Quoted 17 lines
drivers/tee/Kconfig +2
-2@@ -1,8 +1,8 @@ # Generic Trusted Execution Environment Configuration config TEE bool "Trusted Execution Environment support" - depends on ARM && (ARM64 || CPU_V7A) - select ARM_SMCCC + depends on (ARM && (ARM64 || CPU_V7A)) || SANDBOX + select ARM_SMCCC if ARM help This implements a generic interface towards a Trusted Execution Environment (TEE). A TEE is a trusted OS running in some secure
drivers/tee/Kconfig if TEE · line 23
Quoted 10 lines
drivers/tee/Kconfig +7
-0@@ -14,6 +14,14 @@ if TEE menu "TEE drivers" +config SANDBOX_TEE + bool "Sandbox TEE emulator" + depends on SANDBOX + default y + help + This emulates a generic TEE needed for testing including the AVB + TA.
Can you please expand this? What features does it implement? How do you access it from the U-Boot command line?
Quoted 33 lines
drivers/tee/Kconfig +1
-0+ source "drivers/tee/optee/Kconfig" endmenudrivers/tee/Makefile +1
-0@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ obj-y += tee-uclass.o +obj-$(CONFIG_SANDBOX) += sandbox.o obj-$(CONFIG_OPTEE) += optee/drivers/tee/optee/Kconfig +1
-1@@ -10,7 +10,7 @@ config OPTEE handle Remote Procedure Calls (RPC) from OP-TEE needed to execute a service. For more information see: https://www.op-tee.org -if OPTEE +if OPTEE || SANDBOX menu "OP-TEE options"drivers/tee/sandbox.c new file +0
-0
drivers/tee/sandbox.c line 7
Quoted 7 lines
drivers/tee/sandbox.c new file +7
-0@@ -0,0 +1,299 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2018 Linaro Limited +*/ +#include <common.h> +#include <dm.h> +#include <sandboxtee.h>
Could this go in asm/ ?
drivers/tee/sandbox.c line 13
Quoted 6 lines
drivers/tee/sandbox.c new file +6
-0+#include <tee.h> +#include <tee/optee_ta_avb.h> + +/* +* The sandbox tee driver tries to emulate a generic TEE with the TA +* OPTEE_TA_AVB available.
What is TEE?
What is TA?
Please expand out the names once in this comment so people can see immediately what you are referring to.
drivers/tee/sandbox.c line 16
Quoted 6 lines
drivers/tee/sandbox.c new file +3
-0+*/ + +struct ta_entry {
What is this struct for? Please add a comment
Quoted 291 lines
drivers/tee/sandbox.c new file +283
-0+struct tee_optee_ta_uuid uuid; +u32 (*open_session)(uint num_params,struct tee_param *params); +u32 (*invoke_func)(u32 func,uint num_params,struct tee_param *params); +}; + +#ifdef CONFIG_OPTEE_TA_AVB +static u32 get_attr (uint n,uint num_params,struct tee_param *params) +{ +if (n >= num_params) +return TEE_PARAM_ATTR_TYPE_NONE ; + +return params[n].attr; +} + +static u32 check_params (u8 p0,u8 p1,u8 p2,u8 p3,uint num_params, +struct tee_param *params) +{ +u8 p[] = { p0, p1, p2, p3}; +uint n; + +for (n =0 ; n <ARRAY_SIZE (p); n++) +if (p[n] !=get_attr (n, num_params, params)) + goto bad_params; + +for (; n < num_params; n++) +if (get_attr (n, num_params, params)) + goto bad_params; + +return TEE_SUCCESS ; + +bad_params: +printf ("Bad param attrs\n" ); + +return TEE_ERROR_BAD_PARAMETERS ; +} + +static u64 ta_avb_rollback_indexes[TA_AVB_MAX_ROLLBACK_LOCATIONS ]; +static u32 ta_avb_lock_state; + +static u32 ta_avb_open_session (uint num_params,struct tee_param *params) +{ +/* +* We don't expect additional parameters when opening a session to +* this TA. +*/ +return check_params (TEE_PARAM_ATTR_TYPE_NONE ,TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE ,TEE_PARAM_ATTR_TYPE_NONE , + num_params, params); +} + +static u32 ta_avb_invoke_func (u32 func,uint num_params, +struct tee_param *params) +{ +u32 res; +uint slot; +u64 val; + +switch (func) { +case TA_AVB_CMD_READ_ROLLBACK_INDEX : + res =check_params (TEE_PARAM_ATTR_TYPE_VALUE_INPUT , +TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , + num_params, params); +if (res) +return res; + + slot = params[0 ].u.value.a; +if (slot >=ARRAY_SIZE (ta_avb_rollback_indexes)) { +printf ("Rollback index slot out of bounds %lu\n" , slot); +return TEE_ERROR_BAD_PARAMETERS ; + } + + val = ta_avb_rollback_indexes[slot]; + params[1 ].u.value.a = val >>32 ; + params[1 ].u.value.b = val; +return TEE_SUCCESS ; + +case TA_AVB_CMD_WRITE_ROLLBACK_INDEX : + res =check_params (TEE_PARAM_ATTR_TYPE_VALUE_INPUT , +TEE_PARAM_ATTR_TYPE_VALUE_INPUT , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , + num_params, params); +if (res) +return res; + + slot = params[0 ].u.value.a; +if (slot >=ARRAY_SIZE (ta_avb_rollback_indexes)) { +printf ("Rollback index slot out of bounds %lu\n" , slot); +return TEE_ERROR_BAD_PARAMETERS ; + } + + val = (u64 )params[1 ].u.value.a <<32 | params[1 ].u.value.b; +if (val < ta_avb_rollback_indexes[slot]) +return TEE_ERROR_SECURITY ; + + ta_avb_rollback_indexes[slot] = val; +return TEE_SUCCESS ; + +case TA_AVB_CMD_READ_LOCK_STATE : + res =check_params (TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , + num_params, params); +if (res) +return res; + + params[0 ].u.value.a = ta_avb_lock_state; +return TEE_SUCCESS ; + +case TA_AVB_CMD_WRITE_LOCK_STATE : + res =check_params (TEE_PARAM_ATTR_TYPE_VALUE_INPUT , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , + num_params, params); +if (res) +return res; + +if (ta_avb_lock_state != params[0 ].u.value.a) { + ta_avb_lock_state = params[0 ].u.value.a; +memset (ta_avb_rollback_indexes,0 , +sizeof (ta_avb_rollback_indexes)); + } + +return TEE_SUCCESS ; + +default : +return TEE_ERROR_NOT_SUPPORTED ; + } +} +#endif /*OPTEE_TA_AVB*/ + +static const struct ta_entry ta_entries[] = { +#ifdef CONFIG_OPTEE_TA_AVB + { .uuid =TA_AVB_UUID , + .open_session = ta_avb_open_session, + .invoke_func = ta_avb_invoke_func, + }, +#endif +}; + +static void sandbox_tee_get_version (struct udevice *dev, +struct tee_version_data *vers) +{ +struct tee_version_data v = { + .gen_caps =TEE_GEN_CAP_GP |TEE_GEN_CAP_REG_MEM , + }; + + *vers = v; +} + +static int sandbox_tee_close_session (struct udevice *dev,u32 session) +{ +struct sandbox_tee_state *state =dev_get_priv (dev); + +if (!state->ta || state->session != session) +return -EINVAL ; + + state->session =0 ; + state->ta =NULL ; + +return 0 ; +} + +static const struct ta_entry *find_ta_entry (u8 uuid[TEE_UUID_LEN ]) +{ +struct tee_optee_ta_uuid u; +uint n; + +tee_optee_ta_uuid_from_octets (&u, uuid); + +for (n =0 ; n <ARRAY_SIZE (ta_entries); n++) +if (!memcmp (&u, &ta_entries[n].uuid,sizeof (u))) +return ta_entries + n; + +return NULL ; +} + +static int sandbox_tee_open_session (struct udevice *dev, +struct tee_open_session_arg *arg, +uint num_params,struct tee_param *params) +{ +struct sandbox_tee_state *state =dev_get_priv (dev); +const struct ta_entry *ta; + +if (state->ta) { +printf ("A session is already open\n" ); +return -EBUSY ; + } + + ta =find_ta_entry (arg->uuid); +if (!ta) { +printf ("Cannot find TA\n" ); + arg->ret =TEE_ERROR_ITEM_NOT_FOUND ; + arg->ret_origin =TEE_ORIGIN_TEE ; + +return 0 ; + } + + arg->ret = ta->open_session (num_params, params); + arg->ret_origin =TEE_ORIGIN_TRUSTED_APP ; + +if (!arg->ret) { + state->ta = (void *)ta; + state->session =1 ; + arg->session = state->session; + }else { +printf ("Cannot open session, TA returns error\n" ); + } + +return 0 ; +} + +static int sandbox_tee_invoke_func (struct udevice *dev, +struct tee_invoke_arg *arg, +uint num_params,struct tee_param *params) +{ +struct sandbox_tee_state *state =dev_get_priv (dev); +struct ta_entry *ta = state->ta; + +if (!arg->session) { +printf ("Missing session\n" ); +return -EINVAL ; + } + +if (!ta) { +printf ("TA session not available\n" ); +return -EINVAL ; + } + +if (arg->session != state->session) { +printf ("Session mismatch\n" ); +return -EINVAL ; + } + + arg->ret = ta->invoke_func (arg->func, num_params, params); + arg->ret_origin =TEE_ORIGIN_TRUSTED_APP ; + +return 0 ; +} + +static int sandbox_tee_shm_register (struct udevice *dev,struct tee_shm *shm) +{ +struct sandbox_tee_state *state =dev_get_priv (dev); + + state->num_shms++; + +return 0 ; +} + +static int sandbox_tee_shm_unregister (struct udevice *dev,struct tee_shm *shm) +{ +struct sandbox_tee_state *state =dev_get_priv (dev); + + state->num_shms--; + +return 0 ; +} + +static const struct tee_driver_ops sandbox_tee_ops = { + .get_version = sandbox_tee_get_version, + .open_session = sandbox_tee_open_session, + .close_session = sandbox_tee_close_session, + .invoke_func = sandbox_tee_invoke_func, + .shm_register = sandbox_tee_shm_register, + .shm_unregister = sandbox_tee_shm_unregister, +}; + +static const struct udevice_id sandbox_tee_match[] = { + { .compatible ="sandbox,tee" }, + {}, +}; + +U_BOOT_DRIVER (sandbox_tee) = { + .name ="sandbox_tee" , + .id =UCLASS_TEE , + .of_match = sandbox_tee_match, + .ops = &sandbox_tee_ops, + .priv_auto_alloc_size =sizeof (struct sandbox_tee_state ), +};include/sandboxtee.h new file +2
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/*
include/sandboxtee.h line 12
Quoted 10 lines
include/sandboxtee.h new file +10
-0+* Copyright (C) 2018 Linaro Limited +*/ + +#ifndef __SANDBOXTEE_H +#define __SANDBOXTEE_H + +struct sandbox_tee_state { + u32 session; + int num_shms; + void *ta;
struct/members need comments
Quoted 6 lines
include/sandboxtee.h new file +3
-1+}; + +#endif /*__SANDBOXTEE_H*/ --2.17.1
Regards,
Simon
PATCH v3 15/20 tee: add sandbox driver
Hi Simon,
I have one question inline below.
Quoted 44 lines · Simon Glass
Hi Jens,
Quoted 1 line · Jens Wiklander
Adds a sandboxtee driver which emulates a generic TEE with the OP-TEE
sandbox tee
Quoted 12 lines
AVB TA.
Signed-off-by Jens Wiklander <[email protected]>--- drivers/tee/Kconfig | 12 +- drivers/tee/Makefile | 1 + drivers/tee/optee/Kconfig | 2 +- drivers/tee/sandbox.c | 299 ++++++++++++++++++++++++++++++++++++++ include/sandboxtee.h | 15 ++ 5 files changed, 326 insertions(+), 3 deletions(-) create mode 100644 drivers/tee/sandbox.c create mode 100644 include/sandboxtee.hReviewed-by Simon Glass <[email protected]>nits below.
Quoted 20 lines
drivers/tee/Kconfig +2
-2@@ -1,8 +1,8 @@ # Generic Trusted Execution Environment Configuration config TEE bool "Trusted Execution Environment support" - depends on ARM && (ARM64 || CPU_V7A) - select ARM_SMCCC + depends on (ARM && (ARM64 || CPU_V7A)) || SANDBOX + select ARM_SMCCC if ARM help This implements a generic interface towards a Trusted Execution Environment (TEE). A TEE is a trusted OS running in some secure@@ -14,6 +14,14 @@ if TEE menu "TEE drivers"
Quoted 10 lines
drivers/tee/Kconfig if TEE · line 23
Quoted 7 lines
drivers/tee/Kconfig +7
-0+config SANDBOX_TEE + bool "Sandbox TEE emulator" + depends on SANDBOX + default y + help + This emulates a generic TEE needed for testing including the AVB + TA.Can you please expand this? What features does it implement? How do you access it from the U-Boot command line?
I'll expand it.
Quoted 28 lines
Quoted 28 lines
drivers/tee/Kconfig +1
-0+ source "drivers/tee/optee/Kconfig" endmenudrivers/tee/Makefile +1
-0@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ obj-y += tee-uclass.o +obj-$(CONFIG_SANDBOX) += sandbox.o obj-$(CONFIG_OPTEE) += optee/drivers/tee/optee/Kconfig +1
-1@@ -10,7 +10,7 @@ config OPTEE handle Remote Procedure Calls (RPC) from OP-TEE needed to execute a service. For more information see: https://www.op-tee.org -if OPTEE +if OPTEE || SANDBOX menu "OP-TEE options"
Quoted 15 lines
drivers/tee/sandbox.c line 7
Quoted 13 lines
drivers/tee/sandbox.c new file +7
-0@@ -0,0 +1,299 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2018 Linaro Limited +*/ +#include <common.h> +#include <dm.h> +#include <sandboxtee.h> Could this go in asm/ ?
I don't understand. What should go into asm/ and which directory is that?
Quoted 15 lines
drivers/tee/sandbox.c line 13
Quoted 7 lines
drivers/tee/sandbox.c new file +6
-0+#include <tee.h> +#include <tee/optee_ta_avb.h> + +/* +* The sandbox tee driver tries to emulate a generic TEE with the TA +* OPTEE_TA_AVB available. What is TEE?
What is TA?
Please expand out the names once in this comment so people can see immediately what you are referring to.
Quoted 8 lines
drivers/tee/sandbox.c line 16
Quoted 6 lines
drivers/tee/sandbox.c new file +3
-0+*/ + +struct ta_entry {What is this struct for? Please add a comment
OK
Quoted 296 lines
Quoted 296 lines
drivers/tee/sandbox.c new file +283
-0+struct tee_optee_ta_uuid uuid; +u32 (*open_session)(uint num_params,struct tee_param *params); +u32 (*invoke_func)(u32 func,uint num_params,struct tee_param *params); +}; + +#ifdef CONFIG_OPTEE_TA_AVB +static u32 get_attr (uint n,uint num_params,struct tee_param *params) +{ +if (n >= num_params) +return TEE_PARAM_ATTR_TYPE_NONE ; + +return params[n].attr; +} + +static u32 check_params (u8 p0,u8 p1,u8 p2,u8 p3,uint num_params, +struct tee_param *params) +{ +u8 p[] = { p0, p1, p2, p3}; +uint n; + +for (n =0 ; n <ARRAY_SIZE (p); n++) +if (p[n] !=get_attr (n, num_params, params)) + goto bad_params; + +for (; n < num_params; n++) +if (get_attr (n, num_params, params)) + goto bad_params; + +return TEE_SUCCESS ; + +bad_params: +printf ("Bad param attrs\n" ); + +return TEE_ERROR_BAD_PARAMETERS ; +} + +static u64 ta_avb_rollback_indexes[TA_AVB_MAX_ROLLBACK_LOCATIONS ]; +static u32 ta_avb_lock_state; + +static u32 ta_avb_open_session (uint num_params,struct tee_param *params) +{ +/* +* We don't expect additional parameters when opening a session to +* this TA. +*/ +return check_params (TEE_PARAM_ATTR_TYPE_NONE ,TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE ,TEE_PARAM_ATTR_TYPE_NONE , + num_params, params); +} + +static u32 ta_avb_invoke_func (u32 func,uint num_params, +struct tee_param *params) +{ +u32 res; +uint slot; +u64 val; + +switch (func) { +case TA_AVB_CMD_READ_ROLLBACK_INDEX : + res =check_params (TEE_PARAM_ATTR_TYPE_VALUE_INPUT , +TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , + num_params, params); +if (res) +return res; + + slot = params[0 ].u.value.a; +if (slot >=ARRAY_SIZE (ta_avb_rollback_indexes)) { +printf ("Rollback index slot out of bounds %lu\n" , slot); +return TEE_ERROR_BAD_PARAMETERS ; + } + + val = ta_avb_rollback_indexes[slot]; + params[1 ].u.value.a = val >>32 ; + params[1 ].u.value.b = val; +return TEE_SUCCESS ; + +case TA_AVB_CMD_WRITE_ROLLBACK_INDEX : + res =check_params (TEE_PARAM_ATTR_TYPE_VALUE_INPUT , +TEE_PARAM_ATTR_TYPE_VALUE_INPUT , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , + num_params, params); +if (res) +return res; + + slot = params[0 ].u.value.a; +if (slot >=ARRAY_SIZE (ta_avb_rollback_indexes)) { +printf ("Rollback index slot out of bounds %lu\n" , slot); +return TEE_ERROR_BAD_PARAMETERS ; + } + + val = (u64 )params[1 ].u.value.a <<32 | params[1 ].u.value.b; +if (val < ta_avb_rollback_indexes[slot]) +return TEE_ERROR_SECURITY ; + + ta_avb_rollback_indexes[slot] = val; +return TEE_SUCCESS ; + +case TA_AVB_CMD_READ_LOCK_STATE : + res =check_params (TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , + num_params, params); +if (res) +return res; + + params[0 ].u.value.a = ta_avb_lock_state; +return TEE_SUCCESS ; + +case TA_AVB_CMD_WRITE_LOCK_STATE : + res =check_params (TEE_PARAM_ATTR_TYPE_VALUE_INPUT , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , +TEE_PARAM_ATTR_TYPE_NONE , + num_params, params); +if (res) +return res; + +if (ta_avb_lock_state != params[0 ].u.value.a) { + ta_avb_lock_state = params[0 ].u.value.a; +memset (ta_avb_rollback_indexes,0 , +sizeof (ta_avb_rollback_indexes)); + } + +return TEE_SUCCESS ; + +default : +return TEE_ERROR_NOT_SUPPORTED ; + } +} +#endif /*OPTEE_TA_AVB*/ + +static const struct ta_entry ta_entries[] = { +#ifdef CONFIG_OPTEE_TA_AVB + { .uuid =TA_AVB_UUID , + .open_session = ta_avb_open_session, + .invoke_func = ta_avb_invoke_func, + }, +#endif +}; + +static void sandbox_tee_get_version (struct udevice *dev, +struct tee_version_data *vers) +{ +struct tee_version_data v = { + .gen_caps =TEE_GEN_CAP_GP |TEE_GEN_CAP_REG_MEM , + }; + + *vers = v; +} + +static int sandbox_tee_close_session (struct udevice *dev,u32 session) +{ +struct sandbox_tee_state *state =dev_get_priv (dev); + +if (!state->ta || state->session != session) +return -EINVAL ; + + state->session =0 ; + state->ta =NULL ; + +return 0 ; +} + +static const struct ta_entry *find_ta_entry (u8 uuid[TEE_UUID_LEN ]) +{ +struct tee_optee_ta_uuid u; +uint n; + +tee_optee_ta_uuid_from_octets (&u, uuid); + +for (n =0 ; n <ARRAY_SIZE (ta_entries); n++) +if (!memcmp (&u, &ta_entries[n].uuid,sizeof (u))) +return ta_entries + n; + +return NULL ; +} + +static int sandbox_tee_open_session (struct udevice *dev, +struct tee_open_session_arg *arg, +uint num_params,struct tee_param *params) +{ +struct sandbox_tee_state *state =dev_get_priv (dev); +const struct ta_entry *ta; + +if (state->ta) { +printf ("A session is already open\n" ); +return -EBUSY ; + } + + ta =find_ta_entry (arg->uuid); +if (!ta) { +printf ("Cannot find TA\n" ); + arg->ret =TEE_ERROR_ITEM_NOT_FOUND ; + arg->ret_origin =TEE_ORIGIN_TEE ; + +return 0 ; + } + + arg->ret = ta->open_session (num_params, params); + arg->ret_origin =TEE_ORIGIN_TRUSTED_APP ; + +if (!arg->ret) { + state->ta = (void *)ta; + state->session =1 ; + arg->session = state->session; + }else { +printf ("Cannot open session, TA returns error\n" ); + } + +return 0 ; +} + +static int sandbox_tee_invoke_func (struct udevice *dev, +struct tee_invoke_arg *arg, +uint num_params,struct tee_param *params) +{ +struct sandbox_tee_state *state =dev_get_priv (dev); +struct ta_entry *ta = state->ta; + +if (!arg->session) { +printf ("Missing session\n" ); +return -EINVAL ; + } + +if (!ta) { +printf ("TA session not available\n" ); +return -EINVAL ; + } + +if (arg->session != state->session) { +printf ("Session mismatch\n" ); +return -EINVAL ; + } + + arg->ret = ta->invoke_func (arg->func, num_params, params); + arg->ret_origin =TEE_ORIGIN_TRUSTED_APP ; + +return 0 ; +} + +static int sandbox_tee_shm_register (struct udevice *dev,struct tee_shm *shm) +{ +struct sandbox_tee_state *state =dev_get_priv (dev); + + state->num_shms++; + +return 0 ; +} + +static int sandbox_tee_shm_unregister (struct udevice *dev,struct tee_shm *shm) +{ +struct sandbox_tee_state *state =dev_get_priv (dev); + + state->num_shms--; + +return 0 ; +} + +static const struct tee_driver_ops sandbox_tee_ops = { + .get_version = sandbox_tee_get_version, + .open_session = sandbox_tee_open_session, + .close_session = sandbox_tee_close_session, + .invoke_func = sandbox_tee_invoke_func, + .shm_register = sandbox_tee_shm_register, + .shm_unregister = sandbox_tee_shm_unregister, +}; + +static const struct udevice_id sandbox_tee_match[] = { + { .compatible ="sandbox,tee" }, + {}, +}; + +U_BOOT_DRIVER (sandbox_tee) = { + .name ="sandbox_tee" , + .id =UCLASS_TEE , + .of_match = sandbox_tee_match, + .ops = &sandbox_tee_ops, + .priv_auto_alloc_size =sizeof (struct sandbox_tee_state ), +};include/sandboxtee.h new file +6
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2018 Linaro Limited +*/ + +#ifndef __SANDBOXTEE_H
Quoted 8 lines
include/sandboxtee.h line 12
Quoted 6 lines
include/sandboxtee.h new file +6
-0+#define __SANDBOXTEE_H + +struct sandbox_tee_state { +u32 session; +int num_shms; +void *ta;struct/members need comments
OK
Thanks,
Jens
PATCH v3 15/20 tee: add sandbox driver
Hi Jens,
Quoted 6 lines · Jens Wiklander
Hi Simon,
I have one question inline below.
Quoted 1 line · Simon Glass
Hi Jens,
[..]
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/tee/sandbox.c new file +1
-0@@ -0,0 +1,299 @@ +// SPDX-License-Identifier: GPL-2.0+ Quoted 8 lines
drivers/tee/sandbox.c line 7
Quoted 6 lines
drivers/tee/sandbox.c new file +6
-0+/* +* Copyright (C) 2018 Linaro Limited +*/ +#include <common.h> +#include <dm.h> +#include <sandboxtee.h> Could this go in asm/ ?
Quoted 1 line
I don't understand. What should go into asm/ and which directory is that?
I mean arch/sandbox/include/asm, if this is a file that is only used on sandbox.
Regards,
Simon
PATCH v3 16/20 test: tee: test TEE uclass
In reply to Jens WiklanderTests the TEE uclass with a sandbox tee driver.
--- test/dm/Makefile | 1 + test/dm/tee.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 test/dm/tee.c
test/dm/Makefile +1 -0
@@ -44,4 +44,5 @@ obj-$(CONFIG_DM_VIDEO) += video.o obj-$(CONFIG_ADC) += adc.o obj-$(CONFIG_SPMI) += spmi.o obj-$(CONFIG_WDT) += wdt.o +obj-$(CONFIG_TEE) += tee.o endif
test/dm/tee.c new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 17/20 avb_verify: support using OP-TEE TA AVB
In reply to Jens WiklanderWith CONFIG_OPTEE_TA_AVB use the trusted application AVB provided by OP-TEE to manage rollback indexes and device lock status.
--- common/avb_verify.c | 118 ++++++++++++++++++++++++++++++++++++++++++- doc/README.avb2 | 13 +++++ include/avb_verify.h | 4 ++ 3 files changed, 134 insertions(+), 1 deletion(-)
common/avb_verify.c +117 -1
@@ -10,6 +10,8 @@#include <image.h> #include <malloc.h> #include <part.h> +#include <tee.h> +#include <tee/optee_ta_avb.h> const unsigned char avb_root_pub[1032 ] = {0x0 ,0x0 ,0x10 ,0x0 ,0x55 ,0xd9 ,0x4 ,0xad ,0xd8 ,0x4 ,
@@ -594,6 +596,65 @@ static AvbIOResult validate_vbmeta_public_key(AvbOps *ops,return AVB_IO_RESULT_OK ; } +#ifdef CONFIG_OPTEE_TA_AVB +static int get_open_session (struct AvbOpsData *ops_data) +{ +struct udevice *tee =NULL ; + +while (!ops_data->tee) { +const struct tee_optee_ta_uuid uuid =TA_AVB_UUID ; +struct tee_open_session_arg arg; +int rc; + + tee =tee_find_device (tee,NULL ,NULL ,NULL ); +if (!tee) +return -ENODEV ; + +memset (&arg,0 ,sizeof (arg)); +tee_optee_ta_uuid_to_octets (arg.uuid, &uuid); + rc =tee_open_session (tee, &arg,0 ,NULL ); +if (!rc) { + ops_data->tee = tee; + ops_data->session = arg.session; + } + } + +return 0 ; +} + +static AvbIOResult invoke_func (struct AvbOpsData *ops_data,u32 func, +ulong num_param,struct tee_param *param) +{ +struct tee_invoke_arg arg; + +if (get_open_session (ops_data)) +return AVB_IO_RESULT_ERROR_IO ; + +memset (&arg,0 ,sizeof (arg)); + arg.func = func; + arg.session = ops_data->session; + +if (tee_invoke_func (ops_data->tee, &arg, num_param, param)) +return AVB_IO_RESULT_ERROR_IO ; +switch (arg.ret) { +case TEE_SUCCESS : +return AVB_IO_RESULT_OK ; +case TEE_ERROR_OUT_OF_MEMORY : +return AVB_IO_RESULT_ERROR_OOM ; +case TEE_ERROR_TARGET_DEAD : +/* +* The TA has paniced, close the session to reload the TA +* for the next request. +*/ +tee_close_session (ops_data->tee, ops_data->session); + ops_data->tee =NULL ; +return AVB_IO_RESULT_ERROR_IO ; +default : +return AVB_IO_RESULT_ERROR_IO ; + } +} +#endif +/** * read_rollback_index() - gets the rollback index corresponding to the * location of given by @out_rollback_index.
@@ -609,6 +670,7 @@ static AvbIOResult read_rollback_index(AvbOps *ops,size_t rollback_index_slot, u64 *out_rollback_index) { +#ifndef CONFIG_OPTEE_TA_AVB/* For now we always return 0 as the stored rollback index. */ printf("%s not supported yet\n", __func__);
@@ -616,6 +678,27 @@ static AvbIOResult read_rollback_index(AvbOps *ops, *out_rollback_index =0 ;return AVB_IO_RESULT_OK ; +#else +AvbIOResult rc; +struct tee_param param[2 ]; + +if (rollback_index_slot >=TA_AVB_MAX_ROLLBACK_LOCATIONS ) +return AVB_IO_RESULT_ERROR_NO_SUCH_VALUE ; + +memset (param,0 ,sizeof (param)); + param[0 ].attr =TEE_PARAM_ATTR_TYPE_VALUE_INPUT ; + param[0 ].u.value.a = rollback_index_slot; + param[1 ].attr =TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT ; + + rc =invoke_func (ops->user_data,TA_AVB_CMD_READ_ROLLBACK_INDEX , +ARRAY_SIZE (param), param); +if (rc) +return rc; + + *out_rollback_index = (u64 )param[1 ].u.value.a <<32 | + (u32 )param[1 ].u.value.b; +return AVB_IO_RESULT_OK ; +#endif }/**
@@ -633,10 +716,27 @@ static AvbIOResult write_rollback_index(AvbOps *ops, size_t rollback_index_slot, u64 rollback_index) { +#ifndef CONFIG_OPTEE_TA_AVB /* For now this is a no-op. */ printf ("%s not supported yet\n" , __func__);return AVB_IO_RESULT_OK ; +#else +struct tee_param param[2 ]; + +if (rollback_index_slot >=TA_AVB_MAX_ROLLBACK_LOCATIONS ) +return AVB_IO_RESULT_ERROR_NO_SUCH_VALUE ; + +memset (param,0 ,sizeof (param)); + param[0 ].attr =TEE_PARAM_ATTR_TYPE_VALUE_INPUT ; + param[0 ].u.value.a = rollback_index_slot; + param[1 ].attr =TEE_PARAM_ATTR_TYPE_VALUE_INPUT ; + param[1 ].u.value.a = (u32)(rollback_index >>32 ); + param[1 ].u.value.b = (u32 )rollback_index; + +return invoke_func (ops->user_data,TA_AVB_CMD_WRITE_ROLLBACK_INDEX , +ARRAY_SIZE (param), param); +#endif }/**
@@ -652,6 +752,7 @@ static AvbIOResult write_rollback_index(AvbOps *ops,*/ static AvbIOResult read_is_device_unlocked (AvbOps *ops,bool *out_is_unlocked) { +#ifndef CONFIG_OPTEE_TA_AVB /* For now we always return that the device is unlocked. */ printf ("%s not supported yet\n" , __func__);
@@ -659,6 +760,16 @@ static AvbIOResult read_is_device_unlocked(AvbOps *ops, bool *out_is_unlocked) *out_is_unlocked = true;return AVB_IO_RESULT_OK ; +#else +AvbIOResult rc; +struct tee_param param = { .attr =TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT }; + + rc =invoke_func (ops->user_data,TA_AVB_CMD_READ_LOCK_STATE ,1 , ¶m); +if (rc) +return rc; + *out_is_unlocked = !param.u.value.a; +return AVB_IO_RESULT_OK ; +#endif }/**
@@ -737,6 +848,11 @@ void avb_ops_free(AvbOps *ops) ops_data = ops->user_data; -if (ops_data) +if (ops_data) { +#ifdef CONFIG_OPTEE_TA_AVB +if (ops_data->tee) +tee_close_session (ops_data->tee, ops_data->session); +#endif avb_free (ops_data); + } }
doc/README.avb2 +13 -0
@@ -18,6 +18,13 @@ Integrity of the bootloader (U-boot BLOB and environment) is out of scope. For additional details check: https://android.googlesource.com/platform/external/avb/+/master/README.md +1.1. AVB using OP-TEE (optional) +--------------------------------- +If AVB is configured to use OP-TEE (see 4. below) rollback indexes and +device lock state are stored in RPMB. The RPMB partition is managed by +OP-TEE (https://www.op-tee.org/) which is a secure OS leveraging ARM +TrustZone. + 2. AVB 2.0 U-BOOT SHELL COMMANDS -----------------------------------
@@ -61,6 +68,12 @@ CONFIG_LIBAVB=y CONFIG_AVB_VERIFY=y CONFIG_CMD_AVB=y +In addtion optionally if storing rollback indexes in RPMB with help of +OP-TEE: +CONFIG_TEE=y +CONFIG_OPTEE=y +CONFIG_OPTEE_TA_AVB=y +CONFIG_SUPPORT_EMMC_RPMB=y Then add `avb verify` invocation to your android boot sequence of commands, e.g.:
include/avb_verify.h +4 -0
@@ -27,6 +27,10 @@ struct AvbOpsData {struct AvbOps ops;int mmc_dev;enum avb_boot_state boot_state; +#ifdef CONFIG_OPTEE_TA_AVB +struct udevice *tee; +u32 session; +#endif };struct mmc_part {
Signature · 1 line
2.17.1
PATCH v3 17/20 avb_verify: support using OP-TEE TA AVB
Quoted 2 lines · Jens Wiklander
With
CONFIG_OPTEE_TA_AVBuse the trusted application AVB provided by OP-TEE to manage rollback indexes and device lock status.
Should this be device-lock status?
Quoted 7 lines
Signed-off-by Jens Wiklander <[email protected]>--- common/avb_verify.c | 118 ++++++++++++++++++++++++++++++++++++++++++- doc/README.avb2 | 13 +++++ include/avb_verify.h | 4 ++ 3 files changed, 134 insertions(+), 1 deletion(-)
PATCH v3 17/20 avb_verify: support using OP-TEE TA AVB
Quoted 5 lines · Simon Glass
Quoted 2 lines · Jens Wiklander
With
CONFIG_OPTEE_TA_AVBuse the trusted application AVB provided by OP-TEE to manage rollback indexes and device lock status.Should this be device-lock status?
Yes, I'll fix.
Quoted 10 lines
Quoted 8 lines
Signed-off-by Jens Wiklander <[email protected]>--- common/avb_verify.c | 118 ++++++++++++++++++++++++++++++++++++++++++- doc/README.avb2 | 13 +++++ include/avb_verify.h | 4 ++ 3 files changed, 134 insertions(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>
Thanks,
Jens
PATCH v3 18/20 test_avb: Update pymark.buildconfigspec information for the AVB tests
In reply to Jens WiklanderUpdate the pymark.buildconfigspec to depend on 'cmd_mmc' in addition to 'cmd_avb' for those tests that needs more a more complete MMC implementation or the "mmc" command.
--- test/py/tests/test_avb.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
test/py/tests/test_avb.py +5 -3
@@ -23,7 +23,7 @@ mmc_dev = 1 temp_addr = 0x90000000 temp_addr2 = 0x90002000 - at pytest.mark.buildconfigspec('cmd_avb') + at pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') def test_avb_verify(u_boot_console): """Run AVB 2.0 boot verification chain with avb subset of commands """
@@ -36,7 +36,7 @@ def test_avb_verify(u_boot_console): assert response.find(success_str) - at pytest.mark.buildconfigspec('cmd_avb') + at pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') def test_avb_mmc_uuid(u_boot_console): """Check if 'avb get_uuid' works, compare results with 'part list mmc 1' output
@@ -78,6 +78,7 @@ def test_avb_read_rb(u_boot_console): assert response == '' response = u_boot_console.run_command('avb read_rb 1') + assert response == 'Rollback index: 0' @pytest.mark.buildconfigspec('cmd_avb')
@@ -89,9 +90,10 @@ def test_avb_is_unlocked(u_boot_console): assert response == '' response = u_boot_console.run_command('avb is_unlocked') + assert response == 'Unlocked = 1' - at pytest.mark.buildconfigspec('cmd_avb') + at pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') def test_avb_mmc_read(u_boot_console): """Test mmc read operation """
Signature · 1 line
2.17.1
PATCH v3 18/20 test_avb: Update pymark.buildconfigspec information for the AVB tests
Quoted 8 lines · Jens Wiklander
Update the pymark.buildconfigspec to depend on '
cmd_mmc' in addition to 'cmd_avb' for those tests that needs more a more complete MMC implementation or the "mmc" command.Signed-off-by Jens Wiklander <[email protected]>--- test/py/tests/test_avb.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
PATCH v3 19/20 avb_verify: support sandbox configuration
In reply to Jens WiklanderWith CONFIG_SANDBOX malloc a buffer in get_sector_buf() and return that instead of returning CONFIG_FASTBOOT_BUF_ADDR since there's no such buffer reserved.
--- include/avb_verify.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/avb_verify.h +9 -0
@@ -76,7 +76,16 @@ static inline size_t get_sector_buf_size(void)static inline void *get_sector_buf (void ) { +#ifdef CONFIG_SANDBOX +static void *p; + +if (!p) + p =avb_malloc_ (get_sector_buf_size ()); + +return p; +#else return (void *)CONFIG_FASTBOOT_BUF_ADDR ; +#endif }static inline bool is_buf_unaligned (void *buffer)
Signature · 1 line
2.17.1
PATCH v3 19/20 avb_verify: support sandbox configuration
Hi Jens,
Quoted 16 lines · Jens Wiklander
With
CONFIG_SANDBOXmalloc a buffer inget_sector_buf()and return that instead of returningCONFIG_FASTBOOT_BUF_ADDRsince there's no such buffer reserved.Signed-off-by Jens Wiklander <[email protected]>--- include/avb_verify.h | 9 +++++++++ 1 file changed, 9 insertions(+)include/avb_verify.h +0
-0@@ -76,7 +76,16 @@ static inline size_t get_sector_buf_size(void)static inline void *get_sector_buf (void )
include/avb_verify.h static inline size_t get_sector_buf_size(void) · line 87
Quoted 10 lines
include/avb_verify.h +8
-0{ +#ifdef CONFIG_SANDBOX +static void *p; + +if (!p) + p =avb_malloc_ (get_sector_buf_size ()); + +return p; +#else return (void *)CONFIG_FASTBOOT_BUF_ADDR ;
Can you not define this on sandbox? We don't want sandbox to have special-case code if we can avoid it.
If you do define it, you should change the code to:
return map_sysmem(CONFIG_..., size);
which works on sandbox and other archs too.
Quoted 7 lines
include/avb_verify.h +1
-1+#endif }static inline bool is_buf_unaligned (void *buffer) --2.17.1
Regards,
Simon
PATCH v3 19/20 avb_verify: support sandbox configuration
Hi Simon,
Quoted 33 lines · Simon Glass
Hi Jens,
Quoted 16 lines · Jens Wiklander
With
CONFIG_SANDBOXmalloc a buffer inget_sector_buf()and return that instead of returningCONFIG_FASTBOOT_BUF_ADDRsince there's no such buffer reserved.Signed-off-by Jens Wiklander <[email protected]>--- include/avb_verify.h | 9 +++++++++ 1 file changed, 9 insertions(+)include/avb_verify.h +0
-0@@ -76,7 +76,16 @@ static inline size_t get_sector_buf_size(void)static inline void *get_sector_buf (void )include/avb_verify.h static inline size_t get_sector_buf_size(void) · line 87
Quoted 10 lines
include/avb_verify.h +8
-0{ +#ifdef CONFIG_SANDBOX +static void *p; + +if (!p) + p =avb_malloc_ (get_sector_buf_size ()); + +return p; +#else return (void *)CONFIG_FASTBOOT_BUF_ADDR ;Can you not define this on sandbox? We don't want sandbox to have special-case code if we can avoid it.
Quoted 5 lines
If you do define it, you should change the code to:
return
map_sysmem(CONFIG_..., size);which works on sandbox and other archs too.
Thanks, I'll use that.
--
Jens
PATCH v3 20/20 Kconfig: sandbox: enable cmd_avb and dependencies
In reply to Jens WiklanderEnables cmd_avb and its dependencies need to run the AVB tests.
--- arch/Kconfig | 4 ++++ drivers/fastboot/Kconfig | 2 ++ 2 files changed, 6 insertions(+)
arch/Kconfig +4 -0
@@ -92,6 +92,10 @@ config SANDBOX imply LZMA imply SCSI imply TEE + imply AVB_VERIFY + imply LIBAVB + imply CMD_AVB + imply UDP_FUNCTION_FASTBOOT config SH bool "SuperH architecture"
drivers/fastboot/Kconfig +2 -0
@@ -35,6 +35,7 @@ config FASTBOOT_BUF_ADDR ROCKCHIP_RK3399 default 0x280000 if ROCKCHIP_RK3368 default 0x100000 if ARCH_ZYNQMP + default 0 if SANDBOX help The fastboot protocol requires a large memory buffer for downloads. Define this to the starting RAM address to use for
@@ -45,6 +46,7 @@ config FASTBOOT_BUF_SIZE default 0x8000000 if ARCH_ROCKCHIP default 0x6000000 if ARCH_ZYNQMP default 0x2000000 if ARCH_SUNXI + default 0x8192 if SANDBOX default 0x7000000 help The fastboot protocol requires a large memory buffer for
Signature · 1 line
2.17.1
PATCH v3 20/20 Kconfig: sandbox: enable cmd_avb and dependencies
Quoted 7 lines · Jens Wiklander
Enables
cmd_avband its dependencies need to run the AVB tests.Signed-off-by Jens Wiklander <[email protected]>--- arch/Kconfig | 4 ++++ drivers/fastboot/Kconfig | 2 ++ 2 files changed, 6 insertions(+)