fdtdec: protect against another NULL phandlep in fdtdec_add_reserved_memory()
Subsystems (2)
PATCH v2 1/4 fdtdec: protect against another NULL phandlep in fdtdec_add_reserved_memory()
From: Heiko Stuebner <[email protected]>
The change adding fdtdec_add_reserved_memory() already protected the added phandle against the phandlep being NULL - making the phandlep var optional.
But in the early code checking for an already existing carveout this check was not done and thus the phandle assignment could run into trouble, so add a check there as well, which makes the function still return successfully if a matching region is found, even though no-one wants to work with the phandle.
---
changes in v2:
- add comment about phandlep allowed to be NULL
include/fdtdec.h | 1 + lib/fdtdec.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
include/fdtdec.h +1 -0
@@ -1078,6 +1078,7 @@ static inline int fdtdec_set_phandle(void *blob, int node, uint32_t phandle)* @param basename base name of the node to create * @param carveout information about the carveout region * @param phandlep return location for the phandle of the carveout region +* can be NULL * @return 0 on success or a negative error code on failure */ int fdtdec_add_reserved_memory(void *blob, const char *basename,
lib/fdtdec.c +2 -1
@@ -1363,7 +1363,8 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename, }if (addr == carveout->start && (addr + size) == carveout->end) { - *phandlep =fdt_get_phandle (blob, node); +if (phandlep) + *phandlep =fdt_get_phandle (blob, node);return 0 ; } }
Signature · 1 line
2.23.0
PATCH v2 2/4 fdtdec: only create phandle if caller wants it in fdtdec_add_reserved_memory()
From: Heiko Stuebner <[email protected]>
The phandlep pointer returning the phandle to the caller is optional and if it is not set when calling fdtdec_add_reserved_memory() it is highly likely that the caller is not interested in a phandle to the created reserved-memory area and really just wants that area added.
So just don't create a phandle in that case.
---
changes in v2:
- update function comment
include/fdtdec.h | 2 +- lib/fdtdec.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-)
include/fdtdec.h +1 -1
@@ -1078,7 +1078,7 @@ static inline int fdtdec_set_phandle(void *blob, int node, uint32_t phandle)* @param basename base name of the node to create * @param carveout information about the carveout region * @param phandlep return location for the phandle of the carveout region -* can be NULL +* can be NULL if no phandle should be added * @return 0 on success or a negative error code on failure */ int fdtdec_add_reserved_memory(void *blob, const char *basename,
lib/fdtdec.c +9 -7
@@ -1393,13 +1393,15 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename,if (node <0 )return node; - err =fdt_generate_phandle (blob, &phandle); -if (err <0 ) -return err; - - err =fdtdec_set_phandle (blob, node, phandle); -if (err <0 ) -return err; +if (phandlep) { + err =fdt_generate_phandle (blob, &phandle); +if (err <0 ) +return err; + + err =fdtdec_set_phandle (blob, node, phandle); +if (err <0 ) +return err; + }/* store one or two address cells */ if (na >1 )
Signature · 1 line
2.23.0
PATCH v2 2/4 fdtdec: only create phandle if caller wants it in fdtdec_add_reserved_memory()
Quoted 10 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
The phandlep pointer returning the phandle to the caller is optional and if it is not set when calling
fdtdec_add_reserved_memory()it is highly likely that the caller is not interested in a phandle to the created reserved-memory area and really just wants that area added.So just don't create a phandle in that case.
Quoted 8 lines
Signed-off-by Heiko Stuebner <[email protected]>---
changes in v2:
- update function commentinclude/fdtdec.h | 2 +- lib/fdtdec.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-)
PATCH v2 3/4 image: fdt: copy possible optee nodes to a loaded devicetree
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
The loading convention for optee or any other tee on arm64 is as bl32 parameter to the trusted-firmware. So TF-A gets invoked with the TEE as bl32 and main u-boot as bl33. Once it has done its startup TF-A jumps into the bl32 for the TEE startup, returns to TF-A and then jumps to bl33.
All of them get passed a devicetree as parameter and all components often get loaded from a FIT image.
OP-TEE will create additional nodes in that devicetree namely a firmware node and possibly multiple reserved-memory nodes.
While this devicetree is used in main u-boot, in most cases it won't be the one passed to the actual kernel. Instead most boot commands will load a new devicetree from somewhere like mass storage of the network, so if that happens u-boot should transfer the optee nodes to that new devicetree.
To make that happen introduce optee_copy_fdt_nodes() called from the dt setup function in image-fdt which after checking for the optee presence in the u-boot dt will make sure a optee node is present in the kernel dt and transfer any reserved-memory regions it can find.
---
changes in v2:
- don't create a new optee firmware-node, but instead copy the compatible+method properties from the old fdt blob.
common/image-fdt.c | 8 +++ include/tee/optee.h | 9 +++ lib/optee/optee.c | 132 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+)
common/image-fdt.c +8 -0
@@ -17,6 +17,7 @@#include <linux/libfdt.h> #include <mapmem.h> #include <asm/io.h> +#include <tee/optee.h> #ifndef CONFIG_SYS_FDT_PAD #define CONFIG_SYS_FDT_PAD 0x3000
@@ -561,6 +562,13 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob, } } + fdt_ret =optee_copy_fdt_nodes (gd->fdt_blob, blob); +if (fdt_ret) { +printf ("ERROR: transfer of optee nodes to new fdt failed: %s\n" , +fdt_strerror (fdt_ret)); + goto err; + } +/* Delete the old LMB reservation */ if (lmb) lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob,
include/tee/optee.h +9 -0
@@ -67,4 +67,13 @@ static inline int optee_verify_bootm_image(unsigned long image_addr, }#endif +#if defined(CONFIG_OPTEE ) && defined(CONFIG_OF_LIBFDT ) +int optee_copy_fdt_nodes (const void *old_blob,void *new_blob); +#else +static inline int optee_copy_fdt_nodes (const void *old_blob,void *new_blob) +{ +return 0 ; +} +#endif +#endif /* _OPTEE_H */
lib/optee/optee.c +132 -0
141 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH v2 3/4 image: fdt: copy possible optee nodes to a loaded devicetree
Quoted 29 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
The loading convention for optee or any other tee on arm64 is as bl32 parameter to the trusted-firmware. So TF-A gets invoked with the TEE as bl32 and main u-boot as bl33. Once it has done its startup TF-A jumps into the bl32 for the TEE startup, returns to TF-A and then jumps to bl33.
All of them get passed a devicetree as parameter and all components often get loaded from a FIT image.
OP-TEE will create additional nodes in that devicetree namely a firmware node and possibly multiple reserved-memory nodes.
While this devicetree is used in main u-boot, in most cases it won't be the one passed to the actual kernel. Instead most boot commands will load a new devicetree from somewhere like mass storage of the network, so if that happens u-boot should transfer the optee nodes to that new devicetree.
To make that happen introduce
optee_copy_fdt_nodes()called from the dt setup function in image-fdt which after checking for the optee presence in the u-boot dt will make sure a optee node is present in the kernel dt and transfer any reserved-memory regions it can find.Signed-off-by Heiko Stuebner <[email protected]>---
changes in v2:
- don't create a new optee firmware-node, but instead copy the compatible+method properties from the old fdt blob.
Quoted 5 lines
common/image-fdt.c | 8 +++ include/tee/optee.h | 9 +++ lib/optee/optee.c | 132 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+)
[snip]
Looks good to me:
Cheers,
Jens
PATCH v2 3/4 image: fdt: copy possible optee nodes to a loaded devicetree
Hi Jens and Heiko,
Quoted 35 lines
From: U-Boot <[email protected]> On Behalf Of Jens Wiklander
Sent: mercredi 23 octobre 2019 08:46Quoted 11 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
The loading convention for optee or any other tee on arm64 is as bl32 parameter to the trusted-firmware. So TF-A gets invoked with the TEE as
bl32 and main u-boot as bl33. Once it has done its startup TF-A jumps into the bl32 for the TEE startup, returns to TF-A and then jumps to bl33.All of them get passed a devicetree as parameter and all components often get loaded from a FIT image.
Quoted 7 lines
OP-TEE will create additional nodes in that devicetree namely a firmware node and possibly multiple reserved-memory nodes.
While this devicetree is used in main u-boot, in most cases it won't be the one passed to the actual kernel. Instead most boot commands will load a new devicetree from somewhere like mass storage of the network, so if that happens u-boot should transfer the optee nodes to that new
devicetree.
Quoted 12 lines
To make that happen introduce
optee_copy_fdt_nodes()called from the dt setup function in image-fdt which after checking for the optee presence in the u-boot dt will make sure a optee node is present in the kernel dt and transfer any reserved-memory regions it can find.Signed-off-by Heiko Stuebner <[email protected]>---
changes in v2:
- don't create a new optee firmware-node, but instead copy the compatible+method properties from the old fdt blob.
Quoted 6 lines
Quoted 5 lines
common/image-fdt.c | 8 +++ include/tee/optee.h | 9 +++ lib/optee/optee.c | 132 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+)[snip]
On STM32MP1 platform (armv7 with TF-A support),
we can use BL32 = OP-TEE or spmin provide by TF-A
So we are plan to have the same type of feature but with an inversed logical:
- Op-Tee nodes (firmwares and reserved) are present in kernel device tree
- U-Boot deactivated these nodes when TEE is not present, with the next function called in ft_system_setup:
static void stm32_fdt_disable_optee(void *blob)
{
int off, node;
off = fdt_node_offset_by_compatible(blob, -1, "linaro,optee-tz");
if (off >= 0 && fdtdec_get_is_enabled(blob, off))
fdt_status_disabled(blob, off);
/* Disabled "optee at ..." reserved-memory node */
off = fdt_path_offset(blob, "/reserved-memory/");
if (off < 0)
return;
for (node = fdt_first_subnode(blob, off);
node >= 0;
node = fdt_next_subnode(blob, node)) {
if (!strncmp(fdt_get_name(blob, node, NULL), "optee@", 6))
fdt_status_disabled(blob, node);
}
}What is the better for you ?
1/ Copy the U-Boot op-tee nodes in kernel device tree (where op-tee nodes was present) or
2/ Deactivate the op-tee nodes in kernel device tree (where op-tee nodes are present)
The advantage of us is to upstream a Linux Kernel device tree with the correct op-tee nodes...
Regards
Quoted 5 lines
Looks good to me:
Reviewed-by Jens Wiklander <[email protected]>Cheers,
Jens
Patrick
PATCH v2 3/4 image: fdt: copy possible optee nodes to a loaded devicetree
Hi Patrick,
Am Mittwoch, 23. Oktober 2019, 09:10:52 CEST schrieb Patrick DELAUNAY:
Quoted 42 lines
Hi Jens and Heiko,
Quoted 40 lines
From: U-Boot <[email protected]> On Behalf Of Jens Wiklander
Sent: mercredi 23 octobre 2019 08:46Quoted 11 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
The loading convention for optee or any other tee on arm64 is as bl32 parameter to the trusted-firmware. So TF-A gets invoked with the TEE as
bl32 and main u-boot as bl33. Once it has done its startup TF-A jumps into the bl32 for the TEE startup, returns to TF-A and then jumps to bl33.All of them get passed a devicetree as parameter and all components often get loaded from a FIT image.
Quoted 7 lines
OP-TEE will create additional nodes in that devicetree namely a firmware node and possibly multiple reserved-memory nodes.
While this devicetree is used in main u-boot, in most cases it won't be the one passed to the actual kernel. Instead most boot commands will load a new devicetree from somewhere like mass storage of the network, so if that happens u-boot should transfer the optee nodes to that new
devicetree.
Quoted 17 lines
To make that happen introduce
optee_copy_fdt_nodes()called from the dt setup function in image-fdt which after checking for the optee presence in the u-boot dt will make sure a optee node is present in the kernel dt and transfer any reserved-memory regions it can find.Signed-off-by Heiko Stuebner <[email protected]>---
changes in v2:
- don't create a new optee firmware-node, but instead copy the compatible+method properties from the old fdt blob.common/image-fdt.c | 8 +++ include/tee/optee.h | 9 +++ lib/optee/optee.c | 132 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+)
Quoted 4 lines
Quoted 1 line
[snip]
On STM32MP1 platform (armv7 with TF-A support),
we can use BL32 = OP-TEE or spmin provide by TF-A
That is the same I'm hoping to have at some point for the RK3288 soc I'm also working on :-D .
But why do you need different handling then? Except BL32 being baked into the TF-A binary on arm32, shouldn't the loading patch be somewhat similar (SPL -> TF-A -> OP-Tee -> U-Boot) so that OP-Tee also can insert its nodes there?
(Haven't looked too deeply at this yet)
Quoted 4 lines
So we are plan to have the same type of feature but with an inversed logical:
- Op-Tee nodes (firmwares and reserved) are present in kernel device tree
- U-Boot deactivated these nodes when TEE is not present, with the next function called inft_system_setup:
Having the OP-Tee nodes hard-coded in the devicetree in kernel sources sounds somewhat counter intuitive to me.
For the firmware node it shouldn't matter much, except that there may also be other TEEs other than OP-Tee that people may want to load.
But when the reserved memory is hard-coded in the kernel, you bind yourself to one specific version of your TEE. I.e. what happens when a future version of your platform support wants to move the memory region OP-Tee wants to occupy. With OP-Tee handling the reservation this should be somewhat transparent to bootloader and kernel, as just the reserved-memory changes.
Quoted 20 lines
static void
stm32_fdt_disable_optee(void *blob){ int off, node; off = fdt_node_offset_by_compatible(blob, -1, "linaro,optee-tz"); if (off >= 0 && fdtdec_get_is_enabled(blob, off)) fdt_status_disabled(blob, off); /* Disabled "optee at ..." reserved-memory node */ off = fdt_path_offset(blob, "/reserved-memory/"); if (off < 0) return; for (node = fdt_first_subnode(blob, off); node >= 0; node = fdt_next_subnode(blob, node)) { if (!strncmp(fdt_get_name(blob, node, NULL), "optee@", 6)) fdt_status_disabled(blob, node); } }
Quoted 6 lines
What is the better for you ?
1/ Copy the U-Boot op-tee nodes in kernel device tree (where op-tee nodes was present) or
2/ Deactivate the op-tee nodes in kernel device tree (where op-tee nodes are present)The advantage of us is to upstream a Linux Kernel device tree with the correct op-tee nodes...
In any case, the copying we're doing here should not affect any present OP-Tee nodes in the kernel dts and only proceed if both
(a) U-Boot dts does contain an OP-Tee node
(b) Kernel dts does _not yet_ contain an OP-Tee node
are valid.
Heiko
Quoted 8 lines
Quoted 5 lines
Looks good to me:
Reviewed-by Jens Wiklander <[email protected]>Cheers,
JensPatrick
PATCH v2 3/4 image: fdt: copy possible optee nodes to a loaded devicetree
Hi Heiko,
Quoted 56 lines
Hi Patrick,
Am Mittwoch, 23. Oktober 2019, 09:10:52 CEST schrieb Patrick DELAUNAY:
Quoted 14 lines
Hi Jens and Heiko,
Quoted 12 lines
From: U-Boot <[email protected]> On Behalf Of Jens Wiklander
Sent: mercredi 23 octobre 2019 08:46Quoted 7 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
The loading convention for optee or any other tee on arm64 is as bl32 parameter to the trusted-firmware. So TF-A gets invoked with the TEE as
bl32 and main u-boot as bl33. Once it has done its startup TF-A jumps into the bl32 for the TEE startup, returns to TF-A and then jumps tobl33.
Quoted 26 lines
Quoted 26 lines
Quoted 4 lines
All of them get passed a devicetree as parameter and all components often get loaded from a FIT image.
Quoted 8 lines
OP-TEE will create additional nodes in that devicetree namely a firmware node and possibly multiple reserved-memory nodes.
While this devicetree is used in main u-boot, in most cases it won't be the one passed to the actual kernel. Instead most boot commands will load a new devicetree from somewhere like mass storage of the network, so if that happens u-boot should transfer the optee nodes to that new
devicetree.
Quoted 13 lines
To make that happen introduce
optee_copy_fdt_nodes()called from the dt setup function in image-fdt which after checking for the optee presence in the u-boot dt will make sure a optee node is present in the kernel dt and transfer any reserved-memory regions it can find.Signed-off-by: Heiko Stuebner <[email protected]>
---
changes in v2:
- don't create a new optee firmware-node, but instead copy the compatible+method properties from the old fdt blob.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
common/image-fdt.c | 8 +++ include/tee/optee.h | 9 +++ lib/optee/optee.c | 132++++++++++++++++++++++++++++++++++++++++++++
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
3 files changed, 149 insertions(+)[snip]
On STM32MP1 platform (armv7 with TF-A support), we can use BL32 = OP-TEE or spmin provide by TF-A
Quoted 6 lines
That is the same I'm hoping to have at some point for the RK3288 soc I'm also working on :-D .
But why do you need different handling then? Except BL32 being baked into the TF-A binary on arm32, shouldn't the loading patch be somewhat similar (SPL -> TF-A -> OP-Tee -> U-Boot) so that OP-Tee also can insert its nodes there?
We have official 2 boot chains support by STM32MP15 serie in U-Boot
ROM code => TF-A (BL2 & spmin) => U-Boot => kernel = stm32mp15_trusted_defconfig
ROM code => TF-A (BL2) => OP-TEE => U-Boot => kernel = stm32mp15_optee_defconfig
We have also SPL but only for U-Boot test and with minimal PSCI support in u-boot (no low-power mode, no security support)
ROM code => SPL => U-Boot (install PSCI) => kernel = stm32mp15_basic_defconfig
For details:
https://wiki.st.com/stm32mpu/index.php/Boot_chains_overview#STM32MP15_case
Quoted 12 lines
(Haven't looked too deeply at this yet)
Quoted 5 lines
So we are plan to have the same type of feature but with an inversed logical:
- Op-Tee nodes (firmwares and reserved) are present in kernel device tree
- U-Boot deactivated these nodes when TEE is not present, with the nextfunction called in
ft_system_setup:Having the OP-Tee nodes hard-coded in the devicetree in kernel sources sounds somewhat counter intuitive to me.
Quoted 8 lines
For the firmware node it shouldn't matter much, except that there may also be other TEEs other than OP-Tee that people may want to load.
But when the reserved memory is hard-coded in the kernel, you bind yourself to one specific version of your TEE. I.e. what happens when a future version of your platform support wants to move the memory region OP-Tee wants to occupy. With OP-Tee handling the reservation this should be somewhat transparent to bootloader and kernel, as just the reserved-memory changes.
I don't check the code and architecture of OP-TEE since a long time and with your answer I just discover the non-secure device tree modification done by the OP-Tee (even it is present since v2.1.0)
Quoted 26 lines
Quoted 20 lines
static void stm32_fdt_disable_optee(void *blob) { int off, node; off = fdt_node_offset_by_compatible(blob, -1, "linaro,optee-tz"); if (off >= 0 && fdtdec_get_is_enabled(blob, off)) fdt_status_disabled(blob, off); /* Disabled "optee at ..." reserved-memory node */ off = fdt_path_offset(blob, "/reserved-memory/"); if (off < 0) return; for (node = fdt_first_subnode(blob, off); node >= 0; node = fdt_next_subnode(blob, node)) { if (!strncmp(fdt_get_name(blob, node, NULL), "optee@", 6)) fdt_status_disabled(blob, node); } }Quoted 6 lines
What is the better for you ?
1/ Copy the U-Boot op-tee nodes in kernel device tree (where op-tee nodes was present) or 2/ Deactivate the op-tee nodes in kernel device tree (where op-tee nodes are present)The advantage of us is to upstream a Linux Kernel device tree with the correct
Quoted 8 lines
op-tee nodes...
In any case, the copying we're doing here should not affect any present OP-Tee nodes in the kernel dts and only proceed if both
(a) U-Boot dts does contain an OP-Tee node
(b) Kernel dts does_notyet_contain an OP-Tee nodeare valid.
Now I understood your patch....
I need to check to correctly handle this behavior on my side as stm32mp15 TF-A don't using FIT and SPL is not used.
But I think that the U-Boot device tree need to be loaded by BL2 and no more integrated in U-Boot image thus OP-Tee can modify it.
ROM code => TF-A (BL2) = Load TF-A spmin & U-Boot & Device Tree
=> spmin => U-Boot => kernel
ROM code => TF-A (BL2) = Load OP-TEE & U-Boot & Device Tree
=> OP-TEE => U-Boot => kernel
Quoted 3 lines
Heiko
Thanks again for the answer.
Patrick
PATCH v2 4/4 tests: add OP-TEE test suite
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
OP-TEE can get supplied with a devicetree and will then insert its firmware node and reserved-memory sections into it. As this devicetree often is not the one supplied to a later loaded kernel, a previous commit added functionality to transfer these nodes onto that new devicetree.
To make sure this functionality stays intact, also add a test for the transfer functionality.
--- Makefile | 1 + include/test/optee.h | 14 +++ include/test/suites.h | 1 + test/Kconfig | 1 + test/cmd_ut.c | 6 ++ test/optee/Kconfig | 7 ++ test/optee/Makefile | 13 +++ test/optee/cmd_ut_optee.c | 143 +++++++++++++++++++++++++++++ test/optee/test-optee-base.dts | 13 +++ test/optee/test-optee-no-optee.dts | 13 +++ test/optee/test-optee-optee.dts | 32 +++++++ 11 files changed, 244 insertions(+) create mode 100644 include/test/optee.h create mode 100644 test/optee/Kconfig create mode 100644 test/optee/Makefile create mode 100644 test/optee/cmd_ut_optee.c create mode 100644 test/optee/test-optee-base.dts create mode 100644 test/optee/test-optee-no-optee.dts create mode 100644 test/optee/test-optee-optee.dts
Makefile +1 -0
@@ -746,6 +746,7 @@ libs-$(CONFIG_API) += api/ libs-$(CONFIG_HAS_POST) += post/ libs-$(CONFIG_UNIT_TEST) += test/ test/dm/ libs-$(CONFIG_UT_ENV) += test/env/ +libs-$(CONFIG_UT_OPTEE) += test/optee/ libs-$(CONFIG_UT_OVERLAY) += test/overlay/ libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
include/test/optee.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019, Theobroma Systems Design und Consulting GmbH +*/ + +#ifndef __TEST_OPTEE_H__ +#define __TEST_OPTEE_H__ + +#include <test/test.h> + +/* Declare a new environment test */ +#define OPTEE_TEST (_name, _flags) UNIT_TEST(_name, _flags, optee_test) + +#endif /* __TEST_OPTEE_H__ */
include/test/suites.h +1 -0
@@ -28,6 +28,7 @@ int do_ut_compression(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);int do_ut_dm (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]);int do_ut_env (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]);int do_ut_lib (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]); +int do_ut_optee (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]);int do_ut_overlay (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]);int do_ut_time (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]);int do_ut_unicode (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]);
test/Kconfig +1 -0
@@ -33,4 +33,5 @@ config UT_UNICODE source "test/dm/Kconfig" source "test/env/Kconfig" +source "test/optee/Kconfig" source "test/overlay/Kconfig"
test/cmd_ut.c +6 -0
@@ -43,6 +43,9 @@ static cmd_tbl_t cmd_ut_sub[] = {#if defined(CONFIG_UT_ENV ) U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),#endif +#ifdef CONFIG_UT_OPTEE + U_BOOT_CMD_MKENT(optee, CONFIG_SYS_MAXARGS, 1, do_ut_optee, "", ""), +#endif #ifdef CONFIG_UT_OVERLAY U_BOOT_CMD_MKENT(overlay, CONFIG_SYS_MAXARGS, 1, do_ut_overlay, "", ""),#endif
@@ -114,6 +117,9 @@ static char ut_help_text[] =#ifdef CONFIG_UT_LIB "ut lib [test-name] - test library functions\n"#endif +#ifdef CONFIG_UT_OPTEE + "ut optee [test-name]\n" +#endif #ifdef CONFIG_UT_OVERLAY "ut overlay [test-name]\n"#endif
test/optee/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config UT_OPTEE + bool "Enable OP-TEE Unit Tests" + depends on UNIT_TEST && OF_CONTROL && OPTEE + default y + help + This enables the 'ut optee' command which runs a series of unit + tests on the optee library code..
test/optee/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2019, Theobroma Systems Design und Consulting GmbH + +# Test files +obj-y += cmd_ut_optee.o + +DTC_FLAGS += -@ + +# DT overlays +obj-y += test-optee-base.dtb.o +obj-y += test-optee-optee.dtb.o +obj-y += test-optee-no-optee.dtb.o
test/optee/cmd_ut_optee.c new file +143 -0
143 lines not on this page · raw message
test/optee/test-optee-base.dts new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019, Theobroma Systems Design und Consulting GmbH + */ + +/dts-v1/; + +/ { + #address-cells = <2>; + #size-cells = <2>; +}; + +
test/optee/test-optee-no-optee.dts new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019, Theobroma Systems Design und Consulting GmbH + */ + +/dts-v1/; + +/ { + #address-cells = <2>; + #size-cells = <2>; +}; + +
test/optee/test-optee-optee.dts new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019, Theobroma Systems Design und Consulting GmbH + */ + +/dts-v1/; + +/ { + #address-cells = <2>; + #size-cells = <2>; + + firmware { + optee { + compatible = "linaro,optee-tz"; + method = "smc"; + }; + }; + + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + optee_shm at 32000000 { + reg = <0x00 0x32000000 0x00 0x400000>; + }; + + optee_core at 30000000 { + reg = <0x00 0x30000000 0x00 0x2000000>; + }; + }; +};
Signature · 1 line
2.23.0
PATCH v2 4/4 tests: add OP-TEE test suite
Quoted 25 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
OP-TEE can get supplied with a devicetree and will then insert its firmware node and reserved-memory sections into it. As this devicetree often is not the one supplied to a later loaded kernel, a previous commit added functionality to transfer these nodes onto that new devicetree.
To make sure this functionality stays intact, also add a test for the transfer functionality.
Signed-off-by Heiko Stuebner <[email protected]>--- Makefile | 1 + include/test/optee.h | 14 +++ include/test/suites.h | 1 + test/Kconfig | 1 + test/cmd_ut.c | 6 ++ test/optee/Kconfig | 7 ++ test/optee/Makefile | 13 +++ test/optee/cmd_ut_optee.c | 143 +++++++++++++++++++++++++++++ test/optee/test-optee-base.dts | 13 +++ test/optee/test-optee-no-optee.dts | 13 +++ test/optee/test-optee-optee.dts | 32 +++++++
Quoted 8 lines
11 files changed, 244 insertions(+) create mode 100644 include/test/optee.h create mode 100644 test/optee/Kconfig create mode 100644 test/optee/Makefile create mode 100644 test/optee/cmd_ut_optee.c create mode 100644 test/optee/test-optee-base.dts create mode 100644 test/optee/test-optee-no-optee.dts create mode 100644 test/optee/test-optee-optee.dts
PATCH v2 1/4 fdtdec: protect against another NULL phandlep in fdtdec_add_reserved_memory()
In reply to Heiko StuebnerQuoted 14 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
The change adding
fdtdec_add_reserved_memory()already protected the added phandle against the phandlep being NULL - making the phandlep var optional.But in the early code checking for an already existing carveout this check was not done and thus the phandle assignment could run into trouble, so add a check there as well, which makes the function still return successfully if a matching region is found, even though no-one wants to work with the phandle.
Fixes c9222a08b3f7 ("fdtdec: Implement fdtdec_add_reserved_memory()")Signed-off-by Heiko Stuebner <[email protected]>
Quoted 7 lines
---
changes in v2:
- add comment about phandlep allowed to be NULLinclude/fdtdec.h | 1 + lib/fdtdec.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)