Re: [Uboot-stm32] [PATCH v2 03/11] stm32mp1: Add support for falcon mode boot from SD card

2021-10-07 Thread Alex G.




On 10/4/21 9:57 AM, Patrick DELAUNAY wrote:

Hi,

=> if OPTEE is loaded after SPL the U-Boot configuration change (running 
in secure world or not)


I am starting to work on these issues in the branch

https://github.com/u-boot/u-boot/compare/master...patrickdelaunay:spl_optee_W2140 
https://github.com/u-boot/u-boot/commit/04ad553e9c6bee62781460d2952df4962e58ae14 
https://github.com/u-boot/u-boot/commit/aebb687a1557590bf070cf5d347854420ca1 


But it is still not working, OP-TEE is not correctly started


What do you mean by "OP-TEE is not correctly started". Here's the .its 
that I use for my FIT image. I hope this will be helpful.


/dts-v1/
;/ {
description = "U-Boot fitImage for stm32mp1";
#address-cells = <1>;
images {
optee-1 {
description = "OP-TEE secure world firmware";
data = /incbin/("firmware/tee.bin");
type = "tee";
arch = "arm";
os = "tee";
compression = "none";
load = <0xdde4>;
entry = <0xde00>;
hash-1 {
algo = "sha256";
};
};
kernel-1 {
description = "Linux kernel";
data = /incbin/("kernel/zImage");
type = "kernel";
arch = "arm";
os = "linux";
compression = "none";
load = <0xc240>;
entry = <0xc240>;
hash-1 {
algo = "sha256";
};
};
fdt-stm32mp157c-ev1.dtb {
description = "Flattened Device Tree blob";
data = /incbin/("kernel/stm32mp157c-ev1.dtb");
type = "flat_dt";
arch = "arm";
compression = "none";
hash-1 {
algo = "sha256";
};
};
fdt-stm32mp157c-dk2.dtb {
description = "Flattened Device Tree blob";
data = /incbin/("kernel/stm32mp157c-dk2.dtb");
type = "flat_dt";
arch = "arm";
compression = "none";
hash-1 {
algo = "sha256";
};
};
fdt-dk2-optee.dto {
description = "Flattened Device Tree blob";
data = /incbin/("firmware/dk2-optee.dto");
type = "flat_dt";
arch = "arm";
compression = "none";
hash-1 {
algo = "sha256";
};
};
fdt-dk2-can1-enable.dto {
description = "Flattened Device Tree blob";
data = /incbin/("firmware/dk2-can1-enable.dto");
type = "flat_dt";
arch = "arm";
compression = "none";
hash-1 {
algo = "sha256";
};
};
fdt-bootargs.dto {
description = "Flattened Device Tree blob";
data = /incbin/("firmware/bootargs.dto");
type = "flat_dt";
arch = "arm";
compression = "none";
hash-1 {
algo = "sha256";
};
};
};
configurations {
default = "secure-stm32mp157c-ev1.dtb";
secure-stm32mp157c-ev1.dtb {
description = "Linux with OP-TEE for 
stm32mp157c-ev1.dtb";
kernel = "optee-1";
fdt = "fdt-stm32mp157c-ev1.dtb", "fdt-bootargs.dto";
loadables = "kernel-1";
hash-1 {
algo = "sha256";
};
};
secure-stm32mp157c-dk2.dtb {
description = "Linux with OP-TEE for 
stm32mp157c-dk2.dtb";
kernel = "optee-1";
			fdt = "fdt-stm32mp157c-dk2.dtb", "fdt-bootargs.dto", 
"fdt-dk2-can1-enable.dto", "fdt-dk2-optee.dto";

loadables = "kernel-1";
hash-1 {
algo = "sha256";
};
};
};
};



Re: [Uboot-stm32] [PATCH v2 03/11] stm32mp1: Add support for falcon mode boot from SD card

2021-10-04 Thread Patrick DELAUNAY

Hi,

On 9/8/21 1:59 AM, Alexandru Gagniuc wrote:

Falcon mode requires a board-specific mechanism to select between
fast and normal boot. This is done via spl_start_uboot()

Use the USER2 button as the selection mechanism. This is connected to
GPIO PA13. This GPIO is already accessible via the "st,fastboot-gpios"
devicetree node, but is is also aliased as "u-boot,falcon-gpios". This
is the only button on DK2 which accessible simultaneously to the RESET
button. USER2 is too close, and I can't fit my fingers to press both.

The fact that USER2 is also used for android fastboot is of no
consequence. One can let go of USER2 after SPL but before being
sampled by u-boot. If that is missed, it's okay, u-boot tries to
initialize the ethernet, which can be stopped with a Ctr-C. This
conveniently opens up a u-boot shell.

Offsets for raw MMC loading are defined. These point to the partition
after "ssbl". Offsets for SPI are not defined, and thus SPL_LOAD_SPI
must be disabled to avoid a build failure. The only way to accommodate
this is to add a new defconfig, adventurously named stm32mp1_falcon.

The baudrate is set to 2 Mbaud, as the point of this config is to boot
fast. The default devicetree is set to -dk2. This is because EV1 does
not have a crypto-enabled CPU, and thus enabling ECDSA support would
have made far less sense. That and all the goodies with FIT in SPL
are enabled to give this config some continuous integration TLC.

Signed-off-by: Alexandru Gagniuc 
---
  arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi |   2 +
  board/st/stm32mp1/spl.c  |  39 +
  configs/stm32mp15_falcon_defconfig   | 181 +++
  3 files changed, 222 insertions(+)
  create mode 100644 configs/stm32mp15_falcon_defconfig

diff --git a/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi 
b/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi
index 0101962ea5..b314ce2dac 100644
--- a/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi
+++ b/arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi
@@ -16,6 +16,8 @@
u-boot,boot-led = "heartbeat";
u-boot,error-led = "error";
u-boot,mmc-env-partition = "fip";
+   /* This is the same as fastboot-gpios. This is on purpose */
+   u-boot,falcon-gpios = < 13 (GPIO_ACTIVE_LOW | 
GPIO_PULL_UP)>;
st,adc_usb_pd = < 18>, < 19>;
st,fastboot-gpios = < 13 (GPIO_ACTIVE_LOW | 
GPIO_PULL_UP)>;
st,stm32prog-gpios = < 14 (GPIO_ACTIVE_LOW | 
GPIO_PULL_UP)>;
diff --git a/board/st/stm32mp1/spl.c b/board/st/stm32mp1/spl.c
index 8e4549a1b3..921d0190e0 100644
--- a/board/st/stm32mp1/spl.c
+++ b/board/st/stm32mp1/spl.c
@@ -8,6 +8,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  #include "../common/stpmic1.h"
@@ -29,6 +30,44 @@ int board_early_init_f(void)
return 0;
  }
  
+#if IS_ENABLED(CONFIG_SPL_OS_BOOT)

+int spl_start_uboot(void)
+{
+   ofnode node;
+   struct gpio_desc gpio;
+   int boot_uboot = 1;
+
+   node = ofnode_path("/config");
+   if (!ofnode_valid(node)) {
+   pr_warn("%s: no /config node?\n", __func__);
+   return 0;
+   }
+
+   if (gpio_request_by_name_nodev(node, "u-boot,falcon-gpios", 0, ,
+  GPIOD_IS_IN)) {
+   pr_warn("%s: could not find a /config/u-boot,falcon-gpios\n",
+   __func__);
+   return 1;
+   }
+
+   boot_uboot = dm_gpio_get_value();
+   dm_gpio_free(NULL, );
+
+   return boot_uboot;
+}
+


I don't like the duplicated function for one key...


To avoid conflict with GPIO key already used for other purpose fastboot,

the Falcon mode activation can also use U-Boot environment

=> benefit:

1/ U-Boot can be requested by Linux before reset (set env boot_os=0)

2/ for first boot, the U-Boot is started to execute "spl export" before 
to set "boot_os=1"



And / or with console to force U-Boot as it is done by many other board 
(check 'c' character)



/*
* Return
* 0 if booting into OS is selected
* 1 if booting into U-Boot is selected
*/
intspl_start_uboot(void)
{/* Break into full U-Boot on 'c' */ if (serial_tstc() && serial_getc() 
== 'c') return 1;

/* check environment for falcon mode activation */
env_init();
if(env_get_yesno("boot_os") != 0)
return0;
return1;
}


+#if IS_ENABLED(CONFIG_ARMV7_NONSEC)
+/*
+ * A bit of a hack, but armv7_boot_nonsec() is provided by bootm.c. This is not
+ * available in SPL, so we have to provide an implementation.
+ */
+bool armv7_boot_nonsec(void)
+{
+   return 0;
+}



This hack can be avoid => CONFIG_ARMV7_NONSEC not activated


U-Boot is running in normal world after OP-TEE / loaded by SPL :

it is the same for PSCI / SCMI support !


config STM32MP15x
    bool "Support STMicroelectronics STM32MP15x Soc"
    select ARCH_SUPPORT_PSCI if !TFABOOT && !SPL_OPTEE_IMAGE
    select ARM_SMCCC if TFABOOT || SPL_OPTEE_IMAGE
    select CPU_V7A
    select