[PATCH] net: sun8i-emac: Allow all RGMII PHY modes

2020-11-16 Thread Andre Przywara
So far all GBit users of the sun8i-emac driver were using the "rgmii"
PHY mode, even though this turns out to be mostly wrong. It just worked
because the PHY driver doesn't do the proper setup (yet).
In fact for most boards the "rgmii-id" or "rgmii-txid" PHY modes are the
correct ones.

To allow the DTs to describe the phy-mode correctly, and to stay
compatible with Linux, at least allow those other RGMII modes in the
driver.

This avoids breakage if mainline DTs will be synced with U-Boot.

An almost identical patch (f1239d8aa84d) was merged into the Linux driver
and has been backported to stable kernels.

Signed-off-by: Andre Przywara 
---
 drivers/net/sun8i_emac.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c
index 4524604126c..5db33f5c135 100644
--- a/drivers/net/sun8i_emac.c
+++ b/drivers/net/sun8i_emac.c
@@ -353,6 +353,9 @@ static int sun8i_emac_set_syscon(struct sun8i_eth_pdata 
*pdata,
/* default */
break;
case PHY_INTERFACE_MODE_RGMII:
+   case PHY_INTERFACE_MODE_RGMII_ID:
+   case PHY_INTERFACE_MODE_RGMII_RXID:
+   case PHY_INTERFACE_MODE_RGMII_TXID:
reg |= SC_EPIT | SC_ETCS_INT_GMII;
break;
case PHY_INTERFACE_MODE_RMII:
-- 
2.17.5



[PULL u-boot] Please pull u-boot-amlogic-20201116

2020-11-16 Thread Neil Armstrong
Hi Tom,

This PR fixes the MMC driver on SM1 based platforms, syncs the SoC Ids and 
fixes 2 potential
build warning.

The CI job is at 
https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic/pipelines/5354

Thanks,
Neil

The following changes since commit 832bfad7451e2e7bd23c96edff2be050905ac3f6:

  libfdt: Fix signedness comparison warnings (2020-11-10 14:31:08 -0500)

are available in the Git repository at:

  https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic.git 
tags/u-boot-amlogic-20201116

for you to fetch changes up to c87eab81616d671a6004ffc95847bad21b7eb005:

  ARM: dts: meson-sm1: add u-boot specific MMC controller compatible 
(2020-11-12 14:31:29 +0100)


- Clock fix MMC driver for SM1 based platforms
- sync SOC Ids from Linux 5.10-rc1
- fix potential build warning on meson_dw_hdmi and meson-g12a-usb2 phy


Jaehoon Chung (2):
  phy: meson-g12a-usb2: fix the potential build warning
  video: meson: meson_dw_hdmi: fix the potential build warning

Neil Armstrong (4):
  ARM: mach-meson: update SoC IDs
  mmc: meson-gx: move arch header to local header
  mmc: meson-gx: change clock phase value on SM1 SoCs
  ARM: dts: meson-sm1: add u-boot specific MMC controller compatible

 .../dts/meson-g12b-a311d-khadas-vim3-u-boot.dtsi   |  1 +
 arch/arm/dts/meson-khadas-vim3-u-boot.dtsi |  2 --
 arch/arm/dts/meson-sm1-khadas-vim3l-u-boot.dtsi|  1 +
 arch/arm/dts/meson-sm1-odroid-c4-u-boot.dtsi   |  2 +-
 arch/arm/dts/meson-sm1-sei610-u-boot.dtsi  |  2 +-
 arch/arm/dts/meson-sm1-u-boot.dtsi | 20 +++
 arch/arm/mach-meson/board-info.c   |  7 +-
 drivers/mmc/meson_gx_mmc.c | 29 ++
 .../sd_emmc.h => drivers/mmc/meson_gx_mmc.h| 10 +---
 drivers/phy/meson-g12a-usb2.c  |  4 +--
 drivers/video/meson/meson_dw_hdmi.c|  2 ++
 11 files changed, 64 insertions(+), 16 deletions(-)
 create mode 100644 arch/arm/dts/meson-sm1-u-boot.dtsi
 rename arch/arm/include/asm/arch-meson/sd_emmc.h => drivers/mmc/meson_gx_mmc.h 
(95%)


Re: [PATCH 08/26] clk: add support for setting clk rate from cmdline

2020-11-16 Thread Tero Kristo

On 15/11/2020 12:29, Lokesh Vutla wrote:

+Lucasz


This is just a nice to have patch. Found it quite useful while debugging 
the new drivers so decided to share.


-Tero



On 10/11/20 2:35 pm, Tero Kristo wrote:

Add new clk subcommand "clk setfreq", for setting up a clock rate
directly from u-boot cmdline. This is handy for any debugging purposes
towards clocks.

Signed-off-by: Tero Kristo 
---
  cmd/clk.c | 49 +++--
  1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/cmd/clk.c b/cmd/clk.c
index 0245b97136..fd7944c02e 100644
--- a/cmd/clk.c
+++ b/cmd/clk.c
@@ -98,8 +98,52 @@ static int do_clk_dump(struct cmd_tbl *cmdtp, int flag, int 
argc,
return ret;
  }
  
+struct udevice *clk_lookup(const char *name)

+{
+   int i = 0;
+   struct udevice *dev;
+
+   do {
+   uclass_get_device(UCLASS_CLK, i++, &dev);
+   if (!strcmp(name, dev->name))
+   return dev;
+   } while (dev);
+
+   return NULL;
+}
+
+static int do_clk_setfreq(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+   struct clk *clk = NULL;
+   s32 freq;
+   struct udevice *dev;
+
+   freq = simple_strtoul(argv[2], NULL, 10);
+
+   dev = clk_lookup(argv[1]);
+
+   if (dev)
+   clk = dev_get_clk_ptr(dev);
+
+   if (!clk) {
+   printf("clock '%s' not found.\n", argv[1]);
+   return -EINVAL;
+   }
+
+   freq = clk_set_rate(clk, freq);
+   if (freq < 0) {
+   printf("set_rate failed: %d\n", freq);
+   return CMD_RET_FAILURE;
+   }
+
+   printf("set_rate returns %u\n", freq);
+   return 0;
+}
+
  static struct cmd_tbl cmd_clk_sub[] = {
U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""),
+   U_BOOT_CMD_MKENT(setfreq, 3, 1, do_clk_setfreq, "", ""),
  };
  
  static int do_clk(struct cmd_tbl *cmdtp, int flag, int argc,

@@ -124,7 +168,8 @@ static int do_clk(struct cmd_tbl *cmdtp, int flag, int argc,
  
  #ifdef CONFIG_SYS_LONGHELP

  static char clk_help_text[] =
-   "dump - Print clock frequencies";
+   "dump - Print clock frequencies\n"
+   "setfreq [clk] [freq] - Set clock frequency";
  #endif
  
-U_BOOT_CMD(clk, 2, 1, do_clk, "CLK sub-system", clk_help_text);

+U_BOOT_CMD(clk, 4, 1, do_clk, "CLK sub-system", clk_help_text);



--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. 
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


Re: [PATCH 03/26] remoteproc: k3-r5: remove sysfw PM calls if not supported

2020-11-16 Thread Tero Kristo

On 15/11/2020 12:29, Lokesh Vutla wrote:



On 10/11/20 2:35 pm, Tero Kristo wrote:

With the sysfw rearch, sysfw PM calls are no longer available from SPL
level. To properly support this, remove the is_on checks and the reset
assertion from the R5 remoteproc driver as these are not supported.
Attempting to access unavailable services will cause the device to hang.

Signed-off-by: Tero Kristo 
---
  drivers/remoteproc/ti_k3_r5f_rproc.c | 4 
  1 file changed, 4 insertions(+)

diff --git a/drivers/remoteproc/ti_k3_r5f_rproc.c 
b/drivers/remoteproc/ti_k3_r5f_rproc.c
index 9332a63d21..b2902e7fd3 100644
--- a/drivers/remoteproc/ti_k3_r5f_rproc.c
+++ b/drivers/remoteproc/ti_k3_r5f_rproc.c
@@ -781,7 +781,9 @@ static int k3_r5f_probe(struct udevice *dev)
  {
struct k3_r5f_cluster *cluster = dev_get_priv(dev->parent);
struct k3_r5f_core *core = dev_get_priv(dev);
+#ifdef CONFIG_CLK_TI_SCI


Since we are checking for device state, can you make this guard under power
domain instead of clock?


Hmm right, that would work. Will change.




bool r_state;
+#endif
int ret;
  
  	dev_dbg(dev, "%s\n", __func__);

@@ -804,6 +806,7 @@ static int k3_r5f_probe(struct udevice *dev)
return ret;
}
  
+#ifdef CONFIG_CLK_TI_SCI


Can you also add a comment here on why we are doing this?


I can add an inline comment for this.

-Tero



Thanks and regards,
Lokesh


ret = core->tsp.sci->ops.dev_ops.is_on(core->tsp.sci, core->tsp.dev_id,
   &r_state, &core->in_use);
if (ret)
@@ -817,6 +820,7 @@ static int k3_r5f_probe(struct udevice *dev)
  
  	/* Make sure Local reset is asserted. Redundant? */

reset_assert(&core->reset);
+#endif
  
  	ret = k3_r5f_rproc_configure(core);

if (ret) {



--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. 
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


Re: [PATCH 00/26] TI J7 SoC HSM Rearch support series

2020-11-16 Thread Tero Kristo

On 16/11/2020 06:13, Lokesh Vutla wrote:



On 10/11/20 2:35 pm, Tero Kristo wrote:

Hello,

On TI J7 SoCs the device manager firmware is now split into two
portions instead of the existing one which supported all services via a
single firmware image running on DMSC core. Now, the existing DMSC core
is dedicated for secure services only, and the PM and RM functionality
is moved under a separate firmware image running on MCU R5 core. This
is completely transparent for the firmware users, as the existing
messaging mechanism (TI-SCI) routes everything to proper destination,
except for anything that runs on MCU R5, and in our case it happens
to be R5 SPL bootloader.


Can you update board/ti/j721e/README with the detail of the boot flow and build
steps?


Sure, I can craft additional patch for that purpose. Its good that j7 
has its separate doc actually, so am65x can stay in its current form.


-Tero



Thanks and regards,
Lokesh



--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. 
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


Re: [PATCH 19/26] arm: mach-k3: j721e: force enable A72 core 0 during spl shutdown

2020-11-16 Thread Tero Kristo

On 16/11/2020 06:21, Lokesh Vutla wrote:



On 10/11/20 2:35 pm, Tero Kristo wrote:

With the new raw register mode access PM drivers, A72 core is not
enabled via ti-sci services, leading into bad usecounts for the core.
This effectively shuts down the A72 core when SPL goes down. Prevent the


When you meant SPL that is R5 going down correct?. But in this case R5 can never
go down no? I am still trying to understand what happens if this patch is not
applied.

Is it that R5 gets reset before jumping to DM firmware? Also at this point DM
services are not available no? who services this get_device request?


This does not touch R5 as you see from the code, the device ID touched 
is A72SS0. Basically what happens is that A72 is booted directly by R5 
SPL, but once u-boot shutdown services kick in, they terminate A72 
power-domain because it is no longer used by any of the device drivers. 
Sysfw usecount is increased by A72 ATF, which keeps the core enabled in 
pure sysfw case, but our R5 SPL drivers do not have this info so they 
terminate it forcibly.


However, this might not be needed at all in the latest version of the 
code, as we always start a firmware image on MCU R5 and the 
release_resources_for_core_shutdown never gets called. Let me retry this 
once I re-spin this series.


-Tero



Thanks and regards,
Lokesh


problem by force enabling the A72 core once, which increases the use
count.

Signed-off-by: Tero Kristo 
---
  arch/arm/mach-k3/j721e_init.c | 14 ++
  1 file changed, 14 insertions(+)

diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
index a36e4ed603..d00a9477a2 100644
--- a/arch/arm/mach-k3/j721e_init.c
+++ b/arch/arm/mach-k3/j721e_init.c
@@ -306,6 +306,7 @@ u32 spl_boot_device(void)
  
  #ifdef CONFIG_SYS_K3_SPL_ATF
  
+#define J721E_DEV_A72SS0_CORE0			202

  #define J721E_DEV_MCU_RTI0262
  #define J721E_DEV_MCU_RTI1263
  #define J721E_DEV_MCU_ARMSS0_CPU0 250
@@ -324,10 +325,23 @@ void release_resources_for_core_shutdown(void)
J721E_DEV_MCU_RTI1,
};
  
+	const u32 get_device_ids[] = {

+   J721E_DEV_A72SS0_CORE0
+   };
+
ti_sci = get_ti_sci_handle();
dev_ops = &ti_sci->ops.dev_ops;
proc_ops = &ti_sci->ops.proc_ops;
  
+	/* Iterate through list of devices to get (enable) */

+   for (i = 0; i < ARRAY_SIZE(get_device_ids); i++) {
+   u32 id = get_device_ids[i];
+
+   ret = dev_ops->get_device(ti_sci, id);
+   if (ret)
+   panic("Failed to get device %u (%d)\n", id, ret);
+   }
+
/* Iterate through list of devices to put (shutdown) */
for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
u32 id = put_device_ids[i];



--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. 
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


Re: [PATCH 20/26] arm: mach-k3: do board config for PM and RM only if supported

2020-11-16 Thread Tero Kristo

On 16/11/2020 06:23, Lokesh Vutla wrote:



On 10/11/20 2:35 pm, Tero Kristo wrote:

If the raw PM support is built in, we are operating in the split
firmware approach mode where RM and PM support is not available. In this
case, skip the board config for these two.

Signed-off-by: Tero Kristo 
---
  arch/arm/mach-k3/sysfw-loader.c | 4 
  1 file changed, 4 insertions(+)

diff --git a/arch/arm/mach-k3/sysfw-loader.c b/arch/arm/mach-k3/sysfw-loader.c
index 78c158c63f..154d2df049 100644
--- a/arch/arm/mach-k3/sysfw-loader.c
+++ b/arch/arm/mach-k3/sysfw-loader.c
@@ -158,11 +158,13 @@ static void k3_sysfw_configure_using_fit(void *fit,
  ret);
  
  	/* Apply power/clock (PM) specific configuration to SYSFW */

+#ifdef CONFIG_CLK_TI_SCI


IMHO, using CONFIG_CLK_TI_SCI is hack here. Can we showhow derive this
information based on the images loaded in FIT?


At this point we have only loaded the sysfw image. DM image against 
which we could check this will only be loaded during A72 SPL FIT loading 
process, and it will only happen later.


-Tero



Thanks and regards,
Lokesh


ret = board_ops->board_config_pm(ti_sci,
 (u64)(u32)cfg_fragment_addr,
 (u32)cfg_fragment_size);
if (ret)
panic("Failed to set board PM configuration (%d)\n", ret);
+#endif
  
  	/* Extract resource management (RM) specific configuration from FIT */

ret = fit_get_data_by_name(fit, images, SYSFW_CFG_RM,
@@ -171,12 +173,14 @@ static void k3_sysfw_configure_using_fit(void *fit,
panic("Error accessing %s node in FIT (%d)\n", SYSFW_CFG_RM,
  ret);
  
+#ifdef CONFIG_CLK_TI_SCI

/* Apply resource management (RM) configuration to SYSFW */
ret = board_ops->board_config_rm(ti_sci,
 (u64)(u32)cfg_fragment_addr,
 (u32)cfg_fragment_size);
if (ret)
panic("Failed to set board RM configuration (%d)\n", ret);
+#endif
  
  	/* Extract security specific configuration from FIT */

ret = fit_get_data_by_name(fit, images, SYSFW_CFG_SEC,



--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. 
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


Re: [PATCH 21/26] arm: mach-k3: common: Drop main r5 start

2020-11-16 Thread Tero Kristo

On 16/11/2020 06:24, Lokesh Vutla wrote:



On 10/11/20 2:35 pm, Tero Kristo wrote:

From: Dave Gerlach 

Only start-up the non-linux remote cores if we are running in legacy
boot mode. HSM rearch is not yet supporting this.


This one, we can check against DM_FW image presence as it has been 
loaded already.


-Tero



Signed-off-by: Dave Gerlach 
---
  arch/arm/mach-k3/common.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 418d053610..5582ea6d7e 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -211,7 +211,9 @@ void __noreturn jump_to_image_no_args(struct spl_image_info 
*spl_image)
panic("rproc failed to be initialized (%d)\n", ret);
  
  	init_env();

+#ifdef CONFIG_CLK_TI_SCI


Again. This config ussage is a hack. Can we get a better way to do these things?

Thanks and regards,
Lokesh


start_non_linux_remote_cores();
+#endif
if (!fit_image_info[IMAGE_ID_DM_FW].image_start)
size = load_firmware("name_mcur5f0_0fw", "addr_mcur5f0_0load",
 &loadaddr);



--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. 
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


[PATCH v4 2/4] soc: Fix comments from SOC to SoC

2020-11-16 Thread Biju Das
Fix the comments from "an SOC" to "an SoC".

Signed-off-by: Biju Das 
Reviewed-by: Lad Prabhakar 
Reviewed-by: Simon Glass 
---
 v3->v4: No Change
 * Added Simon's Rb tag.
 v3: 
 * New patch
 (Ref: 
https://patchwork.ozlabs.org/project/uboot/patch/20201102150959.4793-3-biju.das...@bp.renesas.com/)
---
 include/soc.h | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/soc.h b/include/soc.h
index a55eb1b572..05058f9331 100644
--- a/include/soc.h
+++ b/include/soc.h
@@ -31,7 +31,7 @@ struct soc_attr {
 
 struct soc_ops {
/**
-* get_machine() - Get machine name of an SOC
+* get_machine() - Get machine name of an SoC
 *
 * @dev:Device to check (UCLASS_SOC)
 * @buf:Buffer to place string
@@ -41,7 +41,7 @@ struct soc_ops {
int (*get_machine)(struct udevice *dev, char *buf, int size);
 
/**
-* get_revision() - Get revision name of a SOC
+* get_revision() - Get revision name of an SoC
 *
 * @dev:Device to check (UCLASS_SOC)
 * @buf:Buffer to place string
@@ -51,7 +51,7 @@ struct soc_ops {
int (*get_revision)(struct udevice *dev, char *buf, int size);
 
/**
-* get_family() - Get family name of an SOC
+* get_family() - Get family name of an SoC
 *
 * @dev:Device to check (UCLASS_SOC)
 * @buf:Buffer to place string
@@ -76,7 +76,7 @@ struct soc_ops {
 int soc_get(struct udevice **devp);
 
 /**
- * soc_get_machine() - Get machine name of an SOC
+ * soc_get_machine() - Get machine name of an SoC
  * @dev:   Device to check (UCLASS_SOC)
  * @buf:   Buffer to place string
  * @size:  Size of string space
@@ -86,7 +86,7 @@ int soc_get(struct udevice **devp);
 int soc_get_machine(struct udevice *dev, char *buf, int size);
 
 /**
- * soc_get_revision() - Get revision name of an SOC
+ * soc_get_revision() - Get revision name of an SoC
  * @dev:   Device to check (UCLASS_SOC)
  * @buf:   Buffer to place string
  * @size:  Size of string space
@@ -96,7 +96,7 @@ int soc_get_machine(struct udevice *dev, char *buf, int size);
 int soc_get_revision(struct udevice *dev, char *buf, int size);
 
 /**
- * soc_get_family() - Get family name of an SOC
+ * soc_get_family() - Get family name of an SoC
  * @dev:   Device to check (UCLASS_SOC)
  * @buf:   Buffer to place string
  * @size:  Size of string space
-- 
2.17.1



[PATCH v4 0/4] Add Renesas SoC identification driver support

2020-11-16 Thread Biju Das
This patch series aims to support Renesas SoC identification driver.

Added a helper function of_match_node to find the matching of_match structure. 
This helper function can be used to replace the following code in u-boot [1] 
and [2]

[1] 
https://elixir.bootlin.com/u-boot/latest/source/drivers/serial/serial_uniphier.c#L129
[2] 
https://elixir.bootlin.com/u-boot/latest/source/drivers/usb/phy/rockchip_usb2_phy.c#L77

Also added soc_id attribute support in UCLASS_SOC which is required for Renesas 
SoC identification driver similar to mainline linux.

v3->v4
  * Added Simon's Rb tag
  * Updated patch description for SoC identification using soc_id
  * Updated probe function of Renesas SoC identification driver.

Biju Das (4):
  dm: core: Add of_match_node helper function
  soc: Fix comments from SOC to SoC
  dm: soc: Add SoC id for attribute matching
  dm: soc: SoC identification driver for Renesas SoC's

 drivers/core/device.c |  21 
 drivers/soc/Kconfig   |   7 ++
 drivers/soc/Makefile  |   1 +
 drivers/soc/soc-uclass.c  |  19 ++-
 drivers/soc/soc_renesas.c | 244 ++
 drivers/soc/soc_sandbox.c |   8 ++
 include/dm/device.h   |  13 ++
 include/soc.h |  39 +-
 test/dm/core.c|  31 +
 test/dm/soc.c |   8 ++
 10 files changed, 384 insertions(+), 7 deletions(-)
 create mode 100644 drivers/soc/soc_renesas.c

-- 
2.17.1



[PATCH v4 3/4] dm: soc: Add SoC id for attribute matching

2020-11-16 Thread Biju Das
Mainline kernel uses the "soc_id" attribute to identify the SoC for some
of the h/w platforms. Adding this attribute in u-boot will make SoC
identification similar to the mainline kernel, so that it can be easily
maintained.

Add a new attribute named "soc_id" to SOC uclass, in order to allow device
drivers for identifying the SoC using SoC identification string and also
for matching this attribute for selecting SoC specific data.

Signed-off-by: Biju Das 
Reviewed-by: Lad Prabhakar 
Reviewed-by: Simon Glass 
---
v3->v4:
 * Updated patch description
 * Added Simon's Rb tag.

v2->v3:
 * split the comments patch seperate.
 
Ref:https://patchwork.ozlabs.org/project/uboot/patch/20201102150959.4793-3-biju.das...@bp.renesas.com/

v1->v2: Changed the comments from "a SoC" to "an SoC"
 Ref: 
https://patchwork.ozlabs.org/project/uboot/patch/20201030140724.12773-1-biju.das...@bp.renesas.com/
---
 drivers/soc/soc-uclass.c  | 19 ++-
 drivers/soc/soc_sandbox.c |  8 
 include/soc.h | 27 +++
 test/dm/soc.c |  8 
 4 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/soc-uclass.c b/drivers/soc/soc-uclass.c
index c32d647864..a3f8be841b 100644
--- a/drivers/soc/soc-uclass.c
+++ b/drivers/soc/soc-uclass.c
@@ -46,6 +46,16 @@ int soc_get_revision(struct udevice *dev, char *buf, int 
size)
return ops->get_revision(dev, buf, size);
 }
 
+int soc_get_soc_id(struct udevice *dev, char *buf, int size)
+{
+   struct soc_ops *ops = soc_get_ops(dev);
+
+   if (!ops->get_soc_id)
+   return -ENOSYS;
+
+   return ops->get_soc_id(dev, buf, size);
+}
+
 const struct soc_attr *
 soc_device_match(const struct soc_attr *matches)
 {
@@ -61,7 +71,7 @@ soc_device_match(const struct soc_attr *matches)
 
while (1) {
if (!(matches->machine || matches->family ||
- matches->revision))
+ matches->revision || matches->soc_id))
break;
 
match = true;
@@ -87,6 +97,13 @@ soc_device_match(const struct soc_attr *matches)
}
}
 
+   if (matches->soc_id) {
+   if (!soc_get_soc_id(soc, str, SOC_MAX_STR_SIZE)) {
+   if (strcmp(matches->soc_id, str))
+   match = false;
+   }
+   }
+
if (match)
return matches;
 
diff --git a/drivers/soc/soc_sandbox.c b/drivers/soc/soc_sandbox.c
index 5c82ad84fc..1a81d3562a 100644
--- a/drivers/soc/soc_sandbox.c
+++ b/drivers/soc/soc_sandbox.c
@@ -31,10 +31,18 @@ int soc_sandbox_get_revision(struct udevice *dev, char 
*buf, int size)
return 0;
 }
 
+int soc_sandbox_get_soc_id(struct udevice *dev, char *buf, int size)
+{
+   snprintf(buf, size, "r8a774a1");
+
+   return 0;
+}
+
 static const struct soc_ops soc_sandbox_ops = {
.get_family = soc_sandbox_get_family,
.get_revision = soc_sandbox_get_revision,
.get_machine = soc_sandbox_get_machine,
+   .get_soc_id = soc_sandbox_get_soc_id,
 };
 
 int soc_sandbox_probe(struct udevice *dev)
diff --git a/include/soc.h b/include/soc.h
index 05058f9331..db0e8880d1 100644
--- a/include/soc.h
+++ b/include/soc.h
@@ -20,12 +20,14 @@
  *variants. Example: am33
  * @machine  - Name of a specific SoC. Example: am3352
  * @revision - Name of a specific SoC revision. Example: SR1.1
+ * @soc_id   - SoC identification string. Example: r8a774a1
  * @data - A pointer to user data for the SoC variant
  */
 struct soc_attr {
const char *family;
const char *machine;
const char *revision;
+   const char *soc_id;
const void *data;
 };
 
@@ -59,6 +61,16 @@ struct soc_ops {
 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
 */
int (*get_family)(struct udevice *dev, char *buf, int size);
+
+   /**
+* get_soc_id() - Get SoC identification name of an SoC
+*
+* @dev:Device to check (UCLASS_SOC)
+* @buf:Buffer to place string
+* @size:   Size of string space
+* @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
+*/
+   int (*get_soc_id)(struct udevice *dev, char *buf, int size);
 };
 
 #define soc_get_ops(dev)((struct soc_ops *)(dev)->driver->ops)
@@ -105,6 +117,16 @@ int soc_get_revision(struct udevice *dev, char *buf, int 
size);
  */
 int soc_get_family(struct udevice *dev, char *buf, int size);
 
+/**
+ * soc_get_soc_id() - Get SoC identification name of an SoC
+ * @dev:   Device to check (UCLASS_SOC)
+ * @buf:   Buffer to place string
+ * @size:  Size of string space
+ *
+ * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
+ */
+int soc_get_soc_id(struct udevice *dev, char *buf, int size);
+
 /**
  *

[PATCH v4 4/4] dm: soc: SoC identification driver for Renesas SoC's

2020-11-16 Thread Biju Das
Add SoC identification driver for Renesas SoC's. This allows
to identify the SoC type and revision based on Product Register.

This can be checked where needed using soc_device_match().

Signed-off-by: Biju Das 
Reviewed-by: Lad Prabhakar 
---
v3->v4: 
 * Updated Copy right information from Linux.
 * Updated probe function, use the prr address from DT.
v2->v3: No Change.
v2: New patch
---
 drivers/soc/Kconfig   |   7 ++
 drivers/soc/Makefile  |   1 +
 drivers/soc/soc_renesas.c | 244 ++
 3 files changed, 252 insertions(+)
 create mode 100644 drivers/soc/soc_renesas.c

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 864d00a885..475e94cd77 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -16,6 +16,13 @@ config SOC_DEVICE_TI_K3
  This allows Texas Instruments Keystone 3 SoCs to identify
  specifics about the SoC in use.
 
+config SOC_DEVICE_RENESAS
+   depends on SOC_DEVICE
+   bool "Enable SoC driver for Renesas SoCs"
+   help
+ This allows Renesas SoCs to identify specifics about the
+ SoC in use.
+
 source "drivers/soc/ti/Kconfig"
 
 endmenu
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 9ef20ca506..b143eac5fd 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -4,5 +4,6 @@
 
 obj-$(CONFIG_SOC_TI) += ti/
 obj-$(CONFIG_SOC_DEVICE) += soc-uclass.o
+obj-$(CONFIG_$(SPL_)SOC_DEVICE_RENESAS) += soc_renesas.o
 obj-$(CONFIG_SOC_DEVICE_TI_K3) += soc_ti_k3.o
 obj-$(CONFIG_SANDBOX) += soc_sandbox.o
diff --git a/drivers/soc/soc_renesas.c b/drivers/soc/soc_renesas.c
new file mode 100644
index 00..a42c6342fa
--- /dev/null
+++ b/drivers/soc/soc_renesas.c
@@ -0,0 +1,244 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2014-2016 Glider bvba
+ * Copyright (C) 2020 Renesas Electronics Corp.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct soc_renesas_priv {
+   const char *family;
+   const char *soc_id;
+   char revision[6];
+};
+
+struct renesas_family {
+   const char name[16];
+   u32 reg;/* CCCR or PRR, if not in DT */
+};
+
+static const struct renesas_family fam_rcar_gen3 __maybe_unused = {
+   .name   = "R-Car Gen3",
+   .reg= 0xfff00044,   /* PRR (Product Register) */
+};
+
+static const struct renesas_family fam_rzg2 __maybe_unused = {
+   .name   = "RZ/G2",
+   .reg= 0xfff00044,   /* PRR (Product Register) */
+};
+
+struct renesas_soc {
+   const struct renesas_family *family;
+   u8 id;
+};
+
+#ifdef CONFIG_R8A774A1
+static const struct renesas_soc soc_rz_g2m = {
+   .family = &fam_rzg2,
+   .id = 0x52,
+};
+#endif
+
+#ifdef CONFIG_R8A774B1
+static const struct renesas_soc soc_rz_g2n = {
+   .family = &fam_rzg2,
+   .id = 0x55,
+};
+#endif
+
+#ifdef CONFIG_R8A774C0
+static const struct renesas_soc soc_rz_g2e = {
+   .family = &fam_rzg2,
+   .id = 0x57,
+};
+#endif
+
+#ifdef CONFIG_R8A774E1
+static const struct renesas_soc soc_rz_g2h = {
+   .family = &fam_rzg2,
+   .id = 0x4f,
+};
+#endif
+
+#ifdef CONFIG_R8A7795
+static const struct renesas_soc soc_rcar_h3 = {
+   .family = &fam_rcar_gen3,
+   .id = 0x4f,
+};
+#endif
+
+#ifdef CONFIG_R8A7796
+static const struct renesas_soc soc_rcar_m3_w = {
+   .family = &fam_rcar_gen3,
+   .id = 0x52,
+};
+#endif
+
+#ifdef CONFIG_R8A77965
+static const struct renesas_soc soc_rcar_m3_n = {
+   .family = &fam_rcar_gen3,
+   .id = 0x55,
+};
+#endif
+
+#ifdef CONFIG_R8A77970
+static const struct renesas_soc soc_rcar_v3m = {
+   .family = &fam_rcar_gen3,
+   .id = 0x54,
+};
+#endif
+
+#ifdef CONFIG_R8A77980
+static const struct renesas_soc soc_rcar_v3h = {
+   .family = &fam_rcar_gen3,
+   .id = 0x56,
+};
+#endif
+
+#ifdef CONFIG_R8A77990
+static const struct renesas_soc soc_rcar_e3 = {
+   .family = &fam_rcar_gen3,
+   .id = 0x57,
+};
+#endif
+
+#ifdef CONFIG_R8A77995
+static const struct renesas_soc soc_rcar_d3 = {
+   .family = &fam_rcar_gen3,
+   .id = 0x58,
+};
+#endif
+
+static int soc_renesas_get_family(struct udevice *dev, char *buf, int size)
+{
+   struct soc_renesas_priv *priv = dev_get_priv(dev);
+
+   snprintf(buf, size, "%s", priv->family);
+
+   return 0;
+}
+
+static int soc_renesas_get_revision(struct udevice *dev, char *buf, int size)
+{
+   struct soc_renesas_priv *priv = dev_get_priv(dev);
+
+   snprintf(buf, size, "%s", priv->revision);
+
+   return 0;
+}
+
+static int soc_renesas_get_soc_id(struct udevice *dev, char *buf, int size)
+{
+   struct soc_renesas_priv *priv = dev_get_priv(dev);
+
+   snprintf(buf, size, "%s", priv->soc_id);
+
+   return 0;
+}
+
+static const struct udevice_id renesas_socs[] = {
+#ifdef CONFIG_R8A774A1
+   { .compatible = "renesas,r8a774a1", .data = (ulong)&soc_rz_g2m, },
+#endif
+#i

[PATCH v4 1/4] dm: core: Add of_match_node helper function

2020-11-16 Thread Biju Das
Add of_match_node() helper function to iterate over the device tree
and tell if a device_node has a matching of_match structure.

Signed-off-by: Biju Das 
Reviewed-by: Lad Prabhakar 
Reviewed-by: Simon Glass 
---
v3->v4: No change
 * Added Simon's Rb tag.
v2->v3:
 * Added a test case for of_match_node helper function.
 (Ref: 
https://patchwork.ozlabs.org/project/uboot/patch/20201102150959.4793-2-biju.das...@bp.renesas.com/)
v1->v2:
  * No Change.
---
 drivers/core/device.c | 21 +
 include/dm/device.h   | 13 +
 test/dm/core.c| 31 +++
 3 files changed, 65 insertions(+)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 4b3dcb3b37..5db4c5e78b 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -1010,6 +1010,27 @@ bool of_machine_is_compatible(const char *compat)
return !fdt_node_check_compatible(fdt, 0, compat);
 }
 
+static
+const struct udevice_id *__of_match_node(const struct udevice_id *matches,
+const ofnode node)
+{
+   if (!matches)
+   return NULL;
+
+   for (; matches->compatible; matches++) {
+   if (ofnode_device_is_compatible(node, matches->compatible))
+   return matches;
+   }
+
+   return NULL;
+}
+
+const struct udevice_id *of_match_node(const struct udevice_id *matches,
+  const ofnode node)
+{
+   return __of_match_node(matches, node);
+}
+
 int dev_disable_by_path(const char *path)
 {
struct uclass *uc;
diff --git a/include/dm/device.h b/include/dm/device.h
index 5bef484247..4c357d46ec 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -754,6 +754,19 @@ bool device_is_compatible(const struct udevice *dev, const 
char *compat);
  */
 bool of_machine_is_compatible(const char *compat);
 
+/**
+ * of_match_node() - Tell if a device_node has a matching of_match structure
+ *
+ *
+ * Low level utility function used by device matching.
+ *
+ * @matches:   array of of device match structures to search in
+ * @node:  the of device structure to match against
+ * @return matching structure on success, NULL if the match is not found
+ */
+const struct udevice_id *of_match_node(const struct udevice_id *matches,
+  const ofnode node);
+
 /**
  * dev_disable_by_path() - Disable a device given its device tree path
  *
diff --git a/test/dm/core.c b/test/dm/core.c
index 6f380a574c..b94b78d9ba 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1066,3 +1067,33 @@ static int dm_test_inactive_child(struct unit_test_state 
*uts)
return 0;
 }
 DM_TEST(dm_test_inactive_child, UT_TESTF_SCAN_PDATA);
+
+static int dm_test_of_match_node(struct unit_test_state *uts)
+{
+   const ulong test_data_expected = 0x1234;
+   ofnode root_node = ofnode_path("/");
+   const struct udevice_id *match;
+   unsigned long match_data;
+
+   const struct udevice_id soc_device_ids[] = {
+   { .compatible = "sandbox", .data = test_data_expected, },
+   { /* sentinel */ }
+   };
+
+   const struct udevice_id soc_device_nomatch_ids[] = {
+   { .compatible = "sandbox123", .data = test_data_expected, },
+   { /* sentinel */ }
+   };
+
+   match = of_match_node(soc_device_ids, root_node);
+   ut_assert(match);
+
+   match_data = match->data;
+   ut_asserteq(match_data, test_data_expected);
+
+   match = of_match_node(soc_device_nomatch_ids, root_node);
+   ut_asserteq_ptr(match, NULL);
+
+   return 0;
+}
+DM_TEST(dm_test_of_match_node, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
-- 
2.17.1



Re: [PATCH 08/26] clk: add support for setting clk rate from cmdline

2020-11-16 Thread Lukasz Majewski
Hi Tero,

> On 15/11/2020 12:29, Lokesh Vutla wrote:
> > +Lucasz  
> 
> This is just a nice to have patch. Found it quite useful while
> debugging the new drivers so decided to share.
> 
> -Tero
> 
> > 
> > On 10/11/20 2:35 pm, Tero Kristo wrote:  
> >> Add new clk subcommand "clk setfreq", for setting up a clock rate
> >> directly from u-boot cmdline. This is handy for any debugging
> >> purposes towards clocks.
> >>
> >> Signed-off-by: Tero Kristo 
> >> ---
> >>   cmd/clk.c | 49 +++--
> >>   1 file changed, 47 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/cmd/clk.c b/cmd/clk.c
> >> index 0245b97136..fd7944c02e 100644
> >> --- a/cmd/clk.c
> >> +++ b/cmd/clk.c
> >> @@ -98,8 +98,52 @@ static int do_clk_dump(struct cmd_tbl *cmdtp,
> >> int flag, int argc, return ret;
> >>   }
> >>   
> >> +struct udevice *clk_lookup(const char *name)
> >> +{
> >> +  int i = 0;
> >> +  struct udevice *dev;
> >> +
> >> +  do {
> >> +  uclass_get_device(UCLASS_CLK, i++, &dev);
> >> +  if (!strcmp(name, dev->name))
> >> +  return dev;
> >> +  } while (dev);
> >> +
> >> +  return NULL;
> >> +}
> >> +
> >> +static int do_clk_setfreq(struct cmd_tbl *cmdtp, int flag, int
> >> argc,
> >> +char *const argv[])
> >> +{
> >> +  struct clk *clk = NULL;
> >> +  s32 freq;
> >> +  struct udevice *dev;
> >> +
> >> +  freq = simple_strtoul(argv[2], NULL, 10);
> >> +
> >> +  dev = clk_lookup(argv[1]);
> >> +
> >> +  if (dev)
> >> +  clk = dev_get_clk_ptr(dev);
> >> +
> >> +  if (!clk) {
> >> +  printf("clock '%s' not found.\n", argv[1]);
> >> +  return -EINVAL;
> >> +  }
> >> +
> >> +  freq = clk_set_rate(clk, freq);
> >> +  if (freq < 0) {
> >> +  printf("set_rate failed: %d\n", freq);
> >> +  return CMD_RET_FAILURE;
> >> +  }
> >> +
> >> +  printf("set_rate returns %u\n", freq);
> >> +  return 0;
> >> +}
> >> +
> >>   static struct cmd_tbl cmd_clk_sub[] = {
> >>U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""),
> >> +  U_BOOT_CMD_MKENT(setfreq, 3, 1, do_clk_setfreq, "", ""),
> >>   };
> >>   
> >>   static int do_clk(struct cmd_tbl *cmdtp, int flag, int argc,
> >> @@ -124,7 +168,8 @@ static int do_clk(struct cmd_tbl *cmdtp, int
> >> flag, int argc, 
> >>   #ifdef CONFIG_SYS_LONGHELP
> >>   static char clk_help_text[] =
> >> -  "dump - Print clock frequencies";
> >> +  "dump - Print clock frequencies\n"
> >> +  "setfreq [clk] [freq] - Set clock frequency";
> >>   #endif
> >>   
> >> -U_BOOT_CMD(clk, 2, 1, do_clk, "CLK sub-system", clk_help_text);
> >> +U_BOOT_CMD(clk, 4, 1, do_clk, "CLK sub-system", clk_help_text);
> >>  
> 
> --
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

Acked-by: Lukasz Majewski 


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgp9qp8qni7A0.pgp
Description: OpenPGP digital signature


Re: Please pull u-boot-dm

2020-11-16 Thread Tom Rini
On Sun, Nov 15, 2020 at 07:11:35AM -0700, Simon Glass wrote:

> Hi Tom,
> 
> The following changes since commit 832bfad7451e2e7bd23c96edff2be050905ac3f6:
> 
>   libfdt: Fix signedness comparison warnings (2020-11-10 14:31:08 -0500)
> 
> are available in the Git repository at:
> 
>   git://git.denx.de/u-boot-dm.git tags/dm-pull-15nov20
> 
> for you to fetch changes up to a3e458524c15710e4ac9ce1556a5f0898084d09a:
> 
>   cros_ec: Handling EC_CMD_GET_NEXT_EVENT (2020-11-14 15:23:41 -0700)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v2 1/6] microblaze: Clean config file from ifdef mess

2020-11-16 Thread Michal Simek
A lot of configs has been moved to Kconfig and it ends up in ifdef mess
with no bodies. That's why remove all of them.

Signed-off-by: Michal Simek 
---

(no changes since v1)

 include/configs/microblaze-generic.h | 24 
 1 file changed, 24 deletions(-)

diff --git a/include/configs/microblaze-generic.h 
b/include/configs/microblaze-generic.h
index 2b4124235082..d5b2bd856608 100644
--- a/include/configs/microblaze-generic.h
+++ b/include/configs/microblaze-generic.h
@@ -67,24 +67,6 @@
 # define CONFIG_SYS_MAX_FLASH_BANKS1
 /* max number of sectors on one chip */
 # define CONFIG_SYS_MAX_FLASH_SECT 512
-/* hardware flash protection */
-/* use buffered writes (20x faster) */
-# ifdefRAMENV
-# else /* FLASH && !RAMENV */
-/* 128K(one sector) for env */
-# endif /* FLASH && !RAMBOOT */
-#else /* !FLASH */
-
-#ifdef SPIFLASH
-# ifdefRAMENV
-# else /* SPIFLASH && !RAMENV */
-/* 128K(two sectors) for env */
-/* Warning: adjust the offset in respect of other flash content and size */
-# endif /* SPIFLASH && !RAMBOOT */
-#else /* !SPIFLASH */
-
-/* ENV in RAM */
-#endif /* !SPIFLASH */
 #endif /* !FLASH */
 
 #define XILINX_USE_ICACHE 1
@@ -111,12 +93,6 @@
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
 
-#if defined(CONFIG_MTD_PARTITIONS)
-/* MTD partitions */
-
-/* default mtd partition table */
-#endif
-
 /* size of console buffer */
 #defineCONFIG_SYS_CBSIZE   512
 /* max number of command args */
-- 
2.29.2



[PATCH v2 2/6] microblaze: Simplify cache handling

2020-11-16 Thread Michal Simek
Enable caches by default. For now just simplify config file but it should
be read from DT or PVRs.

Signed-off-by: Michal Simek 
---

(no changes since v1)

 include/configs/microblaze-generic.h | 16 ++--
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/include/configs/microblaze-generic.h 
b/include/configs/microblaze-generic.h
index d5b2bd856608..05ea64b16312 100644
--- a/include/configs/microblaze-generic.h
+++ b/include/configs/microblaze-generic.h
@@ -69,20 +69,8 @@
 # define CONFIG_SYS_MAX_FLASH_SECT 512
 #endif /* !FLASH */
 
-#define XILINX_USE_ICACHE 1
-#define XILINX_USE_DCACHE 1
-
-#if defined(XILINX_USE_ICACHE)
-# define CONFIG_ICACHE
-#else
-# undef CONFIG_ICACHE
-#endif
-
-#if defined(XILINX_USE_DCACHE)
-# define CONFIG_DCACHE
-#else
-# undef CONFIG_DCACHE
-#endif
+#define CONFIG_ICACHE
+#define CONFIG_DCACHE
 
 #ifndef XILINX_DCACHE_BYTE_SIZE
 #define XILINX_DCACHE_BYTE_SIZE32768
-- 
2.29.2



[PATCH v2 3/6] microblaze: Get rid of xparameters.h

2020-11-16 Thread Michal Simek
There is no need to use this file anymore. Include it in main config file
and simplify logic based on it.

Signed-off-by: Michal Simek 
---

(no changes since v1)

 board/xilinx/microblaze-generic/xparameters.h | 18 --
 include/configs/microblaze-generic.h  |  7 ++-
 2 files changed, 6 insertions(+), 19 deletions(-)
 delete mode 100644 board/xilinx/microblaze-generic/xparameters.h

diff --git a/board/xilinx/microblaze-generic/xparameters.h 
b/board/xilinx/microblaze-generic/xparameters.h
deleted file mode 100644
index 5e0911faf633..
--- a/board/xilinx/microblaze-generic/xparameters.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * (C) Copyright 2007 Michal Simek
- *
- * Michal  SIMEK 
- *
- * CAUTION: This file is a faked configuration !!!
- *  There is no real target for the microblaze-generic
- *  configuration. You have to replace this file with
- *  the generated file from your Xilinx design flow.
- */
-
-/* Microblaze is microblaze_0 */
-#define XILINX_FSL_NUMBER  3
-
-/* Flash Memory is FLASH_2Mx32 */
-#define XILINX_FLASH_START 0x2c00
-#define XILINX_FLASH_SIZE  0x0080
diff --git a/include/configs/microblaze-generic.h 
b/include/configs/microblaze-generic.h
index 05ea64b16312..2cfcace7b066 100644
--- a/include/configs/microblaze-generic.h
+++ b/include/configs/microblaze-generic.h
@@ -8,7 +8,12 @@
 #ifndef __CONFIG_H
 #define __CONFIG_H
 
-#include "../board/xilinx/microblaze-generic/xparameters.h"
+/* Microblaze is microblaze_0 */
+#define XILINX_FSL_NUMBER  3
+
+/* Flash Memory is FLASH_2Mx32 */
+#define XILINX_FLASH_START 0x2c00
+#define XILINX_FLASH_SIZE  0x0080
 
 /* MicroBlaze CPU */
 #defineMICROBLAZE_V5   1
-- 
2.29.2



[PATCH v2 0/6] microblaze: Cleanup series

2020-11-16 Thread Michal Simek
Hi,

I looked at microblaze configs and clean up some things. All changes were
done in connection to detect nor flash based on information taken from DT.

Thanks
Michal

Changes in v2:
- Rework the whole patch because SPL_NOR is enabled by default.

Michal Simek (6):
  microblaze: Clean config file from ifdef mess
  microblaze: Simplify cache handling
  microblaze: Get rid of xparameters.h
  microblaze: Remove CONFIG_SYS_FDT_SIZE
  microblaze: Unify of setting for SPL_NOR/XIP support
  microblaze: Detect NOR flash based on DT

 board/xilinx/microblaze-generic/xparameters.h | 18 
 configs/microblaze-generic_defconfig  |  2 +
 include/configs/microblaze-generic.h  | 87 ++-
 scripts/config_whitelist.txt  |  1 -
 4 files changed, 11 insertions(+), 97 deletions(-)
 delete mode 100644 board/xilinx/microblaze-generic/xparameters.h

-- 
2.29.2



[PATCH v2 4/6] microblaze: Remove CONFIG_SYS_FDT_SIZE

2020-11-16 Thread Michal Simek
CONFIG_SYS_FDT_SIZE is not use anywhere that's why remove it.

Signed-off-by: Michal Simek 
---

(no changes since v1)

 include/configs/microblaze-generic.h | 1 -
 scripts/config_whitelist.txt | 1 -
 2 files changed, 2 deletions(-)

diff --git a/include/configs/microblaze-generic.h 
b/include/configs/microblaze-generic.h
index 2cfcace7b066..72550113cefa 100644
--- a/include/configs/microblaze-generic.h
+++ b/include/configs/microblaze-generic.h
@@ -171,7 +171,6 @@
 
 #define CONFIG_SYS_FDT_BASE(CONFIG_SYS_FLASH_BASE + \
 0x4)
-#define CONFIG_SYS_FDT_SIZE(16 << 10)
 #define CONFIG_SYS_SPL_ARGS_ADDR   (CONFIG_SYS_TEXT_BASE + \
 0x100)
 
diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt
index 0aabe7a45165..8b4fcba395a3 100644
--- a/scripts/config_whitelist.txt
+++ b/scripts/config_whitelist.txt
@@ -2170,7 +2170,6 @@ CONFIG_SYS_FCC_PSMR
 CONFIG_SYS_FDT_BASE
 CONFIG_SYS_FDT_LOAD_ADDR
 CONFIG_SYS_FDT_PAD
-CONFIG_SYS_FDT_SIZE
 CONFIG_SYS_FEC0_IOBASE
 CONFIG_SYS_FEC1_IOBASE
 CONFIG_SYS_FECI2C
-- 
2.29.2



[PATCH v2 5/6] microblaze: Unify of setting for SPL_NOR/XIP support

2020-11-16 Thread Michal Simek
XIP is not enabled in SPL. SPL_NOR is enabled but any macro setting with
using SYS_FLASH_BASE are wrong because it is not aligned with DM.
That's why change these macro and align them with TEXT_BASE macro.
Information should be find at run time based on DT but implementation is
not done yet.

Signed-off-by: Michal Simek 
---

Changes in v2:
- Rework the whole patch because SPL_NOR is enabled by default.

 include/configs/microblaze-generic.h | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/include/configs/microblaze-generic.h 
b/include/configs/microblaze-generic.h
index 72550113cefa..c31a7880743f 100644
--- a/include/configs/microblaze-generic.h
+++ b/include/configs/microblaze-generic.h
@@ -163,14 +163,12 @@
 
 /* SPL part */
 
-#ifdef CONFIG_SYS_FLASH_BASE
-# define CONFIG_SYS_UBOOT_BASE CONFIG_SYS_FLASH_BASE
-#endif
+#define CONFIG_SYS_UBOOT_BASE  CONFIG_SYS_TEXT_BASE
 
 /* for booting directly linux */
+#define CONFIG_SYS_FDT_BASE(CONFIG_SYS_TEXT_BASE + \
+   0x4)
 
-#define CONFIG_SYS_FDT_BASE(CONFIG_SYS_FLASH_BASE + \
-0x4)
 #define CONFIG_SYS_SPL_ARGS_ADDR   (CONFIG_SYS_TEXT_BASE + \
 0x100)
 
-- 
2.29.2



[PATCH v2 6/6] microblaze: Detect NOR flash based on DT

2020-11-16 Thread Michal Simek
Remove fixed configuration and detect flash based on DT.

Also increase amount of flash sectors to 2048 because on kc705 flash has
1027 sectors.

Bank # 1: CFI conformant flash (16 x 16)  Size: 128 MB in 1027 Sectors
  Intel Extended command set, Manufacturer ID: 0x89, Device ID: 0x8962
  Erase timeout: 4096 ms, write timeout: 2 ms
  Buffer write timeout: 5 ms, buffer size: 1024 bytes

Signed-off-by: Michal Simek 
---

(no changes since v1)

 configs/microblaze-generic_defconfig |  2 ++
 include/configs/microblaze-generic.h | 41 ++--
 2 files changed, 5 insertions(+), 38 deletions(-)

diff --git a/configs/microblaze-generic_defconfig 
b/configs/microblaze-generic_defconfig
index 08c88856dcd9..761cc65cbfab 100644
--- a/configs/microblaze-generic_defconfig
+++ b/configs/microblaze-generic_defconfig
@@ -48,8 +48,10 @@ CONFIG_DM_I2C=y
 CONFIG_LED=y
 CONFIG_LED_GPIO=y
 CONFIG_MTD=y
+CONFIG_DM_MTD=y
 CONFIG_MTD_NOR_FLASH=y
 CONFIG_FLASH_CFI_DRIVER=y
+CONFIG_CFI_FLASH=y
 CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y
 CONFIG_FLASH_CFI_MTD=y
 CONFIG_SYS_FLASH_PROTECTION=y
diff --git a/include/configs/microblaze-generic.h 
b/include/configs/microblaze-generic.h
index c31a7880743f..bc0bf0497378 100644
--- a/include/configs/microblaze-generic.h
+++ b/include/configs/microblaze-generic.h
@@ -11,26 +11,11 @@
 /* Microblaze is microblaze_0 */
 #define XILINX_FSL_NUMBER  3
 
-/* Flash Memory is FLASH_2Mx32 */
-#define XILINX_FLASH_START 0x2c00
-#define XILINX_FLASH_SIZE  0x0080
-
 /* MicroBlaze CPU */
 #defineMICROBLAZE_V5   1
 
 #define CONFIG_SYS_BOOTM_LEN   (64 * 1024 * 1024)
 
-/* linear and spi flash memory */
-#ifdef XILINX_FLASH_START
-#defineFLASH
-#undef SPIFLASH
-#undef RAMENV  /* hold environment in flash */
-#else
-#undef FLASH
-#undef SPIFLASH
-#defineRAMENV  /* hold environment in RAM */
-#endif
-
 /* uart */
 /* The following table includes the supported baudrates */
 # define CONFIG_SYS_BAUDRATE_TABLE \
@@ -45,34 +30,14 @@
 #define CONFIG_SYS_INIT_SP_OFFSET  (CONFIG_SYS_TEXT_BASE - \
 CONFIG_SYS_MALLOC_F_LEN)
 
-/*
- * CFI flash memory layout - Example
- * CONFIG_SYS_FLASH_BASE = 0x2200_;
- * CONFIG_SYS_FLASH_SIZE = 0x0080_;  8MB
- *
- * SECT_SIZE = 0x2;128kB is one sector
- * CONFIG_ENV_SIZE = SECT_SIZE;128kB environment store
- *
- * 0x2200_ CONFIG_SYS_FLASH_BASE
- * FREE256kB
- * 0x2204_ CONFIG_ENV_ADDR
- * ENV_AREA128kB
- * 0x2206_
- * FREE
- * 0x2280_ CONFIG_SYS_FLASH_BASE + CONFIG_SYS_FLASH_SIZE
- *
- */
-
-#ifdef FLASH
-# define CONFIG_SYS_FLASH_BASE XILINX_FLASH_START
-# define CONFIG_SYS_FLASH_SIZE XILINX_FLASH_SIZE
+#ifdef CONFIG_CFI_FLASH
 /* ?empty sector */
 # define CONFIG_SYS_FLASH_EMPTY_INFO   1
 /* max number of memory banks */
 # define CONFIG_SYS_MAX_FLASH_BANKS1
 /* max number of sectors on one chip */
-# define CONFIG_SYS_MAX_FLASH_SECT 512
-#endif /* !FLASH */
+# define CONFIG_SYS_MAX_FLASH_SECT 2048
+#endif
 
 #define CONFIG_ICACHE
 #define CONFIG_DCACHE
-- 
2.29.2



[GIT PULL] TI changes for v2021.01-rc3

2020-11-16 Thread Lokesh Vutla
Hi Tom,
Please find the PR containing TI related changes targeted for
v2020.01-rc3. Details about the PR are updated in the tag message

Travis CI build: 
https://travis-ci.org/github/lokeshvutla/u-boot/builds/743852867

The following changes since commit 832bfad7451e2e7bd23c96edff2be050905ac3f6:

  libfdt: Fix signedness comparison warnings (2020-11-10 14:31:08 -0500)

are available in the Git repository at:

  https://gitlab.denx.de/u-boot/custodians/u-boot-ti.git tags/ti-v2021.01-rc3

for you to fetch changes up to 914689a204308df47eb60dfbb394fa4cee4fda31:

  mtd: OneNAND: Set MTD type (2020-11-15 15:29:40 +0530)


- Fix Nokia RX-51 boot issues
- Fix CONFIG_LOGLEVEL on K3 devices
- Add phyBOARD REGOR support


Ivaylo Dimitrov (1):
  Nokia RX-51: Make onenand working

Pali Rohár (7):
  power: twl4030: Add twl4030_i2c_read() function
  Nokia RX-51: Convert to CONFIG_DM_I2C
  Nokia RX-51: Remove old comments from configs/nokia_rx51.h file
  Nokia RX-51: Fix crashing in U-Boot mmc function omap_hsmmc_stop_clock()
  Nokia RX-51: During init disable lp5523 led instead of resetting it
  Nokia RX-51: Update test script
  mtd: OneNAND: Set MTD type

Parthiban Nallathambi (1):
  ARM: am335x: Add phyBOARD REGOR support

Roger Quadros (1):
  configs: am65/j72x: Set CONFIG_LOGLEVEL to 7

 arch/arm/dts/Makefile  |   3 +-
 arch/arm/dts/am335x-regor-rdk-u-boot.dtsi  |  31 +
 arch/arm/dts/am335x-regor-rdk.dts  |  24 
 arch/arm/dts/am335x-regor.dtsi | 202 +
 board/nokia/rx51/rx51.c|  44 ++-
 board/nokia/rx51/rx51.h|   7 +
 board/phytec/phycore_am335x_r2/MAINTAINERS |   6 +-
 configs/am65x_evm_a53_defconfig|   1 +
 configs/am65x_hs_evm_a53_defconfig |   1 +
 configs/j7200_evm_a72_defconfig|   1 +
 configs/j721e_evm_a72_defconfig|   1 +
 configs/j721e_hs_evm_a72_defconfig |   1 +
 configs/nokia_rx51_defconfig   |   2 +
 configs/phycore-am335x-r2-regor_defconfig  |  88 +
 drivers/mtd/onenand/onenand_base.c |   1 +
 drivers/power/twl4030.c|   7 +-
 include/configs/nokia_rx51.h   |  12 --
 include/twl4030.h  |  12 +-
 test/nokia_rx51_test.sh|  27 ++--
 19 files changed, 431 insertions(+), 40 deletions(-)
 create mode 100644 arch/arm/dts/am335x-regor-rdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/am335x-regor-rdk.dts
 create mode 100644 arch/arm/dts/am335x-regor.dtsi
 create mode 100644 configs/phycore-am335x-r2-regor_defconfig
-- 
2.23.0



Re: [PATCH] mmc: display an error number to debug

2020-11-16 Thread Stephen Warren
On 11/6/20 4:23 AM, Jaehoon Chung wrote:
> It's useful to know an error number when it's debugging.

> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c

> @@ -2746,7 +2746,7 @@ static int mmc_power_on(struct mmc *mmc)
>   int ret = regulator_set_enable(mmc->vmmc_supply, true);
>  
>   if (ret) {
> - puts("Error enabling VMMC supply\n");
> + puts("Error enabling VMMC supply : %d\n", ret);

At least this one needs to be printf() not puts(). This causes build
failures for any board that compiles this code, i.e. anything with the
following enabled:

static int mmc_power_on(struct mmc *mmc)
{
#if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_REGULATOR)


Re: Pull request: u-boot-sunxi/master

2020-11-16 Thread Tom Rini
On Mon, Nov 16, 2020 at 12:42:53PM +0530, Jagan Teki wrote:

> Hi Tom, 
> 
> Please pull this PR.
> 
> Summary:
> - PinePhone support (Samuel)
> - V3/S3 support (Icenowy)
> 
> thanks,
> Jagan.
> 
> The following changes since commit de865f7ee1d9b6dff6e265dee44509c8274ea606:
> 
>   Merge tag 'efi-2021-01-rc3' of 
> https://gitlab.denx.de/u-boot/custodians/u-boot-efi (2020-11-14 09:47:33 
> -0500)
> 
> are available in the Git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-sunxi master
> 
> for you to fetch changes up to 27007e5d4a6c4ac1bbd1bc81fb4c19bc45191f35:
> 
>   sunxi: dts: sync Allwinner V3s-related DTs from Linux 5.10-rc1 (2020-11-16 
> 12:34:09 +0530)
> 

NAK.  A large number of sunxi boards fail to build with:
+board/sunxi/board.c:338:13: error: 'set_spl_dt_name' defined but not used 
[-Werror=unused-function]
+  338 | static void set_spl_dt_name(const char *name)
+  | ^~~
+cc1: all warnings being treated as errors
+make[2]: *** [board/sunxi/board.o] Error 1
+make[1]: *** [board/sunxi] Error 2
+make: *** [sub-make] Error 2

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 00/26] TI J7 SoC HSM Rearch support series

2020-11-16 Thread Tom Rini
On Mon, Nov 16, 2020 at 02:13:03PM +0200, Tero Kristo wrote:
> On 16/11/2020 06:13, Lokesh Vutla wrote:
> > 
> > 
> > On 10/11/20 2:35 pm, Tero Kristo wrote:
> > > Hello,
> > > 
> > > On TI J7 SoCs the device manager firmware is now split into two
> > > portions instead of the existing one which supported all services via a
> > > single firmware image running on DMSC core. Now, the existing DMSC core
> > > is dedicated for secure services only, and the PM and RM functionality
> > > is moved under a separate firmware image running on MCU R5 core. This
> > > is completely transparent for the firmware users, as the existing
> > > messaging mechanism (TI-SCI) routes everything to proper destination,
> > > except for anything that runs on MCU R5, and in our case it happens
> > > to be R5 SPL bootloader.
> > 
> > Can you update board/ti/j721e/README with the detail of the boot flow and 
> > build
> > steps?
> 
> Sure, I can craft additional patch for that purpose. Its good that j7 has
> its separate doc actually, so am65x can stay in its current form.

And can we please find some time to convert all of these to rST and move
under doc/board/ ?  Thanks!

-- 
Tom


signature.asc
Description: PGP signature


Antw: [EXT] [systemd-devel] [SPECIFICATION RFC] The firmware and bootloader log specification

2020-11-16 Thread Ulrich Windl
>>> Daniel Kiper  schrieb am 14.11.2020 um 00:52 in
Nachricht <20201113235242.k6fzlwmwm2xqh...@tomti.i.net-space.pl>:
...
> The members of struct bf_log_msg:
>   ‑ size: total size of bf_log_msg struct,
>   ‑ ts_nsec: timestamp expressed in nanoseconds starting from 0,

Who or what defines t == 0?
...

Regards,
Ulrich Windl



Re: Antw: [EXT] [systemd-devel] [SPECIFICATION RFC] The firmware and bootloader log specification

2020-11-16 Thread Rasmus Villemoes
On 16/11/2020 08.02, Ulrich Windl wrote:
 Daniel Kiper  schrieb am 14.11.2020 um 00:52 in
> Nachricht <20201113235242.k6fzlwmwm2xqh...@tomti.i.net-space.pl>:
> ...
>> The members of struct bf_log_msg:
>>   ‑ size: total size of bf_log_msg struct,
>>   ‑ ts_nsec: timestamp expressed in nanoseconds starting from 0,
> 
> Who or what defines t == 0?

Some sort of "clapperboard" log entry, stating "the RTC says X, the
cycle counter is Y, the onboard ACME atomic clock says Z, I'm now
starting to count ts_nsec from W" might be useful for some eventual
userspace tool to try to stitch together the log entries from the
various stages. I have no idea how a formal spec of such an entry would
look like or if it's even feasible to do formally. But even just such
entries in free-form prose could at least help a human consumer.

Rasmus


[BUG] U-boot does not detect emmc card in odroid-c2 for newer U-boot as 2020.04

2020-11-16 Thread Otto Meier

I tried to build  an actual u-boot from git for my odroid-c2 board.

It doesn't find the emmc card and therefore does not boot from it.
emmc is Ok and boots with u-boot 2020.04 fine.

Newer u-boot then 2020.04 show these messages:

GXBB:BL1:08dafd:0a8993;FEAT:EDFC318C;POC:3;RCY:0;EMMC:0;READ:0;CHK:0;
TE: 156394
no sdio debug board detected

BL2 Built : 11:44:26, Nov 25 2015.
gxb gfb13a3b-c2 - jcao@wonton

Board ID = 8
set vcck to 1100 mv
set vddee to 1050 mv
CPU clk: 1536MHz
DDR channel setting: DDR0 Rank0+1 same
DDR0: 2048MB(auto) @ 912MHz(2T)-13
DataBus test pass!
AddrBus test pass!
Load fip header from eMMC, src: 0xc200, des: 0x0140, size: 
0x00b0

Load bl30 from eMMC, src: 0x00010200, des: 0x0100, size: 0x9ef0
Sending bl30OK.
Run bl30...
Load bl301 from eMMC, src: 0x0001c200, des: 0x0100, size: 0x18c0
Wait bl30...Done
Sending bl301...OK.
Run bl301...
31 from eMMC, src: 0x00020200, des: 0x1010, size: 0x00011130


--- UART initialized after reboot ---
[Reset cause: unknown]
[Image: unknown, amlogic_v1.1.3046-00db630-dirty 2016-08-31 09:24:14 
tao.zeng@droid04]

bl30: check_permit, count is 1
bl30: check_permit: ok!
chipidLoad bl33 from eMMC, src: 0x00034200, des: 0x0100, size: 
0x0009e8f0

: ef be ad de d f0 ad ba ef be ad de not ES chip
[0.271464 Inits done]
secure task start!
high task start!
low task start!
NOTICE:  BL3-1: v1.0(debug):4d2e34d
NOTICE:  BL3-1: Built : 17:08:35, Oct 29 2015
INFO:BL3-1: Initializing runtime services
INFO:BL3-1: Preparing for EL3 exit to normal world
INFO:BL3-1: Next image address = 0x100
INFO:BL3-1: Next image spsr = 0x3c9


U-Boot 2021.01-rc2 (Nov 15 2020 - 19:06:55 +0100) odroid-c2

Model: Hardkernel ODROID-C2
SoC:   Amlogic Meson GXBB (S905) Revision 1f:c (0:1)
DRAM:  2 GiB
MMC:   mmc@72000: 0, mmc@74000: 1
In:serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@c941
Hit any key to stop autoboot:  0
Card did not respond to voltage select!
Card did not respond to voltage select!
MMC Device 2 not found
no mmc device at slot 2
starting USB...
Bus usb@c910: USB DWC2
scanning bus usb@c910 for devices... 2 USB Device(s) found


Does anybody know how to fixes this breakage?

Best regards

Otto



Re: Booting on RK3399[Please note, mail behalf by s...@google.com]

2020-11-16 Thread Piotr Lobacz
Hi all,
i also have a firefly-rk3399 and got problems booting atf >= 1.4 with
whatever optee i use. Only rockchip blob is working for me. I know that i'm
doing something wrong but dunno what. The command for building atf is:
 
# make CROSS_COMPILE=aarch64-linux-gnu- PLAT=rk3399 LOG_LEVEL=40 DEBUG=0
CRASH_REPORTING=1 SPD=opteed bl31

and i only generate uboot.img and trust.img using rockchip build.sh script
with command

# ./buid.sh uboot

Rockchip has added this trust_merger app to their u-boot source code. The
build.sh script builds u-boot and executes make.sh script from u-boot which
runs trust_merger. But for some reason it does not work atf >= 1.4. I don't
know what exectly but what i can tell, i do not see any logs from bl31. For
atf 1.3 with rockchip bl32 blob i can see logs:

No find bl30.bin
Load uboot, ReadLba = 4000
Load OK, addr=0x20, size=0xda214
RunBL31 0x1 @ 105506 us
NOTICE:  BL31: v1.3(release):d43a527de
NOTICE:  BL31: Built : 15:41:07, Nov 16 2020
INFO:GICv3 with legacy support detected. ARM GICV3 driver initialized in
EL3
INFO:plat_rockchip_pmu_init(1331): pd status 3e
INFO:BL31: Initializing runtime services
INFO:BL31: Initializing BL32
INF [0x0] TEE-CORE:init_primary_helper:337: Initializing
(1.1.0-266-gee81607c #1 Mon Aug 17 09:23:30 UTC 2020 aarch64)

INF [0x0] TEE-CORE:init_primary_helper:338: Release version: 1.2

INF [0x0] TEE-CORE:init_teecore:83: teecore inits done
INFO:BL31: Preparing for EL3 exit to normal world
INFO:Entry point address = 0x20
INFO:SPSR = 0x3c9


U-Boot 2017.09 (Nov 11 2020 - 10:27:07 +0100)

And this is what i get for 2.3 atf version:

find part:trust OK. first_lba:0x6000.
Trust Addr:0x6000, 0x58334c42
No find bl30.bin
Load uboot, ReadLba = 4000
Load OK, addr=0x20, size=0xda214
RunBL31 0x4 @ 105604 us


U-Boot 2017.09 (Nov 11 2020 - 10:27:07 +0100)

Model: Firefly-RK3399 Board
PreSerial: 2
DRAM:  3.8 GiB
Sysmem: init
Relocation Offset is: f5beb000
Using default environment

There is no NOTICE or INFO log. The bl32 blob is the same so i suspect for
99% that bl31 was not initialized.

Can anybody help me solving this issue? Because currently i'm with no more
ideas and this is really frustrating...

Best Regards
Piotr Łobacz





--
Sent from: http://u-boot.10912.n7.nabble.com/


Re: Pull request: u-boot-sunxi/master

2020-11-16 Thread André Przywara
On 16/11/2020 15:50, Tom Rini wrote:

Hi Tom,

> On Mon, Nov 16, 2020 at 12:42:53PM +0530, Jagan Teki wrote:
> 
>> Hi Tom, 
>>
>> Please pull this PR.
>>
>> Summary:
>> - PinePhone support (Samuel)
>> - V3/S3 support (Icenowy)
>>
>> thanks,
>> Jagan.
>>
>> The following changes since commit de865f7ee1d9b6dff6e265dee44509c8274ea606:
>>
>>   Merge tag 'efi-2021-01-rc3' of 
>> https://gitlab.denx.de/u-boot/custodians/u-boot-efi (2020-11-14 09:47:33 
>> -0500)
>>
>> are available in the Git repository at:
>>
>>   https://gitlab.denx.de/u-boot/custodians/u-boot-sunxi master
>>
>> for you to fetch changes up to 27007e5d4a6c4ac1bbd1bc81fb4c19bc45191f35:
>>
>>   sunxi: dts: sync Allwinner V3s-related DTs from Linux 5.10-rc1 (2020-11-16 
>> 12:34:09 +0530)
>>
> 
> NAK.  A large number of sunxi boards fail to build with:
> +board/sunxi/board.c:338:13: error: 'set_spl_dt_name' defined but not used 
> [-Werror=unused-function]
> +  338 | static void set_spl_dt_name(const char *name)
> +  | ^~~
> +cc1: all warnings being treated as errors
> +make[2]: *** [board/sunxi/board.o] Error 1
> +make[1]: *** [board/sunxi] Error 2
> +make: *** [sub-make] Error 2

Ouch, thanks for that heads up!
But this only happens after this very patch, and is fixed by a later
patch, right? ("sunxi: board: Set fdtfile to match the DT chosen by SPL"
introduces another user of set_spl_dt_name(), outside of any #ifdef's).

I will try to think about a solution, unless Samuel beats me to it.

Cheers,
Andre


Re: [PATCH v8 00/18] efi_loader: add capsule update support

2020-11-16 Thread Tom Rini
On Mon, Nov 16, 2020 at 09:37:23AM +0900, AKASHI Takahiro wrote:
> Heinrich,
> 
> On Fri, Nov 13, 2020 at 08:18:58AM +0100, Heinrich Schuchardt wrote:
> > On 11/13/20 5:14 AM, AKASHI Takahiro wrote:
> > > Summary
> > > ===
> > > 'UpdateCapsule' is one of runtime services defined in UEFI specification
> > > and its aim is to allow a caller (OS) to pass information to the firmware,
> > > i.e. U-Boot. This is mostly used to update firmware binary on devices by
> > > instructions from OS.
> > >
> > > While 'UpdateCapsule' is a runtime services function, it is, at least
> > > initially, supported only before exiting boot services alike other runtime
> > > functions, [Get/]SetVariable. This is because modifying storage which may
> > > be shared with OS must be carefully designed and there is no general
> > > assumption that we can do it.
> > >
> > > Therefore, we practically support only "capsule on disk"; any capsule can
> > > be handed over to UEFI subsystem as a file on a specific file system.
> > >
> > > In this patch series, all the related definitions and structures are given
> > > as UEFI specification describes, and basic framework for capsule support
> > > is provided. Currently supported is
> > >  * firmware update (Firmware Management Protocol or simply FMP)
> > >
> > > Most of functionality of firmware update is provided by FMP driver and
> > > it can be, by nature, system/platform-specific. So you can and should
> > > implement your own FMP driver(s) based on your system requirements.
> > > Under the current implementation, we provide two basic but generic
> > > drivers with two formats:
> > >   * FIT image format (as used in TFTP update and dfu)
> > >   * raw image format
> > >
> > > It's totally up to users which one, or both, should be used on users'
> > > system depending on user requirements.
> > >
> > > Quick usage
> > > ===
> > > 1. You can create a capsule file with the following host command:
> > >
> > >   $ mkeficapsule [--fit  | --raw ] 
> > >
> > > 2. Put the file under:
> > >
> > >   /EFI/UpdateCapsule of UEFI system partition
> > >
> > > 3. Specify firmware storage to be updated in "dfu_alt_info" variable
> > >(Please follow README.dfu for details.)
> > >
> > >   ==> env set dfu_alt_info '...'
> > >
> > > 4. After setting up UEFI's OsIndications variable, reboot U-Boot:
> > >
> > >   OsIndications <= EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED
> > >
> > > Patch structure
> > > ===
> > > Patch#1-#4,#12: preparatory patches
> > > Patch#5-#11,#13: main part of implementation
> > > Patch#14-#15: utilities
> > > Patch#16-#17: pytests
> > > Patch#18: for sandbox test
> > >
> > > [1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule
> > >
> > > Prerequisite patches
> > > 
> > > None
> > >
> > > Test
> > > 
> > > * passed all the pytests which are included in this patch series
> > >   on sandbox build locally.
> > > * skipped (or 'S', but it's not a failure, 'F') in Travis CI because
> > >   "virt-make-fs" cannot be executed.
> > 
> > Dear Takahiro,
> > 
> > please, rebase your series on origin/master. A prior version of the
> > first patches is already applied.
> 
> You can simply pick up and apply non-merged patches without problems
> except a function prototype change of efi_create_indexed_name() you made,
> which is not trivial to me.
> 
> But anyway, I will post a clean patch set soon.
> 
> > Testing on Gitlab CI, Travis CI, Amazon CI must be addressed for merging
> > the remaining patches.
> 
> Where can we find the results?
> I don't think there is no official information on those CI's.

If you submit a pull request against https://github.com/u-boot/u-boot
Azure will run automatically and show the results.  We don't have
anything similar setup for GitLab, but since it uses the same Docker
images as Azure, so long as the syntax is right (and there are linters
if you're unsure of a change), it would be expected to work too.

-- 
Tom


signature.asc
Description: PGP signature


Re: Pull request: u-boot-sunxi/master

2020-11-16 Thread Tom Rini
On Mon, Nov 16, 2020 at 04:09:42PM +, André Przywara wrote:
> On 16/11/2020 15:50, Tom Rini wrote:
> 
> Hi Tom,
> 
> > On Mon, Nov 16, 2020 at 12:42:53PM +0530, Jagan Teki wrote:
> > 
> >> Hi Tom, 
> >>
> >> Please pull this PR.
> >>
> >> Summary:
> >> - PinePhone support (Samuel)
> >> - V3/S3 support (Icenowy)
> >>
> >> thanks,
> >> Jagan.
> >>
> >> The following changes since commit 
> >> de865f7ee1d9b6dff6e265dee44509c8274ea606:
> >>
> >>   Merge tag 'efi-2021-01-rc3' of 
> >> https://gitlab.denx.de/u-boot/custodians/u-boot-efi (2020-11-14 09:47:33 
> >> -0500)
> >>
> >> are available in the Git repository at:
> >>
> >>   https://gitlab.denx.de/u-boot/custodians/u-boot-sunxi master
> >>
> >> for you to fetch changes up to 27007e5d4a6c4ac1bbd1bc81fb4c19bc45191f35:
> >>
> >>   sunxi: dts: sync Allwinner V3s-related DTs from Linux 5.10-rc1 
> >> (2020-11-16 12:34:09 +0530)
> >>
> > 
> > NAK.  A large number of sunxi boards fail to build with:
> > +board/sunxi/board.c:338:13: error: 'set_spl_dt_name' defined but not used 
> > [-Werror=unused-function]
> > +  338 | static void set_spl_dt_name(const char *name)
> > +  | ^~~
> > +cc1: all warnings being treated as errors
> > +make[2]: *** [board/sunxi/board.o] Error 1
> > +make[1]: *** [board/sunxi] Error 2
> > +make: *** [sub-make] Error 2
> 
> Ouch, thanks for that heads up!
> But this only happens after this very patch, and is fixed by a later
> patch, right? ("sunxi: board: Set fdtfile to match the DT chosen by SPL"
> introduces another user of set_spl_dt_name(), outside of any #ifdef's).

No, that's from the PR itself.

-- 
Tom


signature.asc
Description: PGP signature


Re: Pull request: u-boot-sunxi/master

2020-11-16 Thread André Przywara
On 16/11/2020 16:13, Tom Rini wrote:
> On Mon, Nov 16, 2020 at 04:09:42PM +, André Przywara wrote:
>> On 16/11/2020 15:50, Tom Rini wrote:
>>
>> Hi Tom,
>>
>>> On Mon, Nov 16, 2020 at 12:42:53PM +0530, Jagan Teki wrote:
>>>
 Hi Tom, 

 Please pull this PR.

 Summary:
 - PinePhone support (Samuel)
 - V3/S3 support (Icenowy)

 thanks,
 Jagan.

 The following changes since commit 
 de865f7ee1d9b6dff6e265dee44509c8274ea606:

   Merge tag 'efi-2021-01-rc3' of 
 https://gitlab.denx.de/u-boot/custodians/u-boot-efi (2020-11-14 09:47:33 
 -0500)

 are available in the Git repository at:

   https://gitlab.denx.de/u-boot/custodians/u-boot-sunxi master

 for you to fetch changes up to 27007e5d4a6c4ac1bbd1bc81fb4c19bc45191f35:

   sunxi: dts: sync Allwinner V3s-related DTs from Linux 5.10-rc1 
 (2020-11-16 12:34:09 +0530)

>>>
>>> NAK.  A large number of sunxi boards fail to build with:
>>> +board/sunxi/board.c:338:13: error: 'set_spl_dt_name' defined but not used 
>>> [-Werror=unused-function]
>>> +  338 | static void set_spl_dt_name(const char *name)
>>> +  | ^~~
>>> +cc1: all warnings being treated as errors
>>> +make[2]: *** [board/sunxi/board.o] Error 1
>>> +make[1]: *** [board/sunxi] Error 2
>>> +make: *** [sub-make] Error 2
>>
>> Ouch, thanks for that heads up!
>> But this only happens after this very patch, and is fixed by a later
>> patch, right? ("sunxi: board: Set fdtfile to match the DT chosen by SPL"
>> introduces another user of set_spl_dt_name(), outside of any #ifdef's).
> 
> No, that's from the PR itself.

Right, sorry, looked at the wrong function.
I found the culprit and have a fix, but I will run some actual tests on
my boards tonight to make sure it really works.
Jagan or me will send a new PR later then.

Thanks!
Andre.


Re: Pull request: u-boot-sunxi/master

2020-11-16 Thread Tom Rini
On Mon, Nov 16, 2020 at 04:51:32PM +, André Przywara wrote:
> On 16/11/2020 16:13, Tom Rini wrote:
> > On Mon, Nov 16, 2020 at 04:09:42PM +, André Przywara wrote:
> >> On 16/11/2020 15:50, Tom Rini wrote:
> >>
> >> Hi Tom,
> >>
> >>> On Mon, Nov 16, 2020 at 12:42:53PM +0530, Jagan Teki wrote:
> >>>
>  Hi Tom, 
> 
>  Please pull this PR.
> 
>  Summary:
>  - PinePhone support (Samuel)
>  - V3/S3 support (Icenowy)
> 
>  thanks,
>  Jagan.
> 
>  The following changes since commit 
>  de865f7ee1d9b6dff6e265dee44509c8274ea606:
> 
>    Merge tag 'efi-2021-01-rc3' of 
>  https://gitlab.denx.de/u-boot/custodians/u-boot-efi (2020-11-14 09:47:33 
>  -0500)
> 
>  are available in the Git repository at:
> 
>    https://gitlab.denx.de/u-boot/custodians/u-boot-sunxi master
> 
>  for you to fetch changes up to 27007e5d4a6c4ac1bbd1bc81fb4c19bc45191f35:
> 
>    sunxi: dts: sync Allwinner V3s-related DTs from Linux 5.10-rc1 
>  (2020-11-16 12:34:09 +0530)
> 
> >>>
> >>> NAK.  A large number of sunxi boards fail to build with:
> >>> +board/sunxi/board.c:338:13: error: 'set_spl_dt_name' defined but not 
> >>> used [-Werror=unused-function]
> >>> +  338 | static void set_spl_dt_name(const char *name)
> >>> +  | ^~~
> >>> +cc1: all warnings being treated as errors
> >>> +make[2]: *** [board/sunxi/board.o] Error 1
> >>> +make[1]: *** [board/sunxi] Error 2
> >>> +make: *** [sub-make] Error 2
> >>
> >> Ouch, thanks for that heads up!
> >> But this only happens after this very patch, and is fixed by a later
> >> patch, right? ("sunxi: board: Set fdtfile to match the DT chosen by SPL"
> >> introduces another user of set_spl_dt_name(), outside of any #ifdef's).
> > 
> > No, that's from the PR itself.
> 
> Right, sorry, looked at the wrong function.
> I found the culprit and have a fix, but I will run some actual tests on
> my boards tonight to make sure it really works.
> Jagan or me will send a new PR later then.

OK, thanks for the quick follow-up!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH 1/3] net: e1000: Remove unused bus_to_phys() macro

2020-11-16 Thread Stefan Roese
bus_to_phys() is defined but not referenced at all. This patch removes
it completely.

Signed-off-by: Stefan Roese 
Cc: Joe Hershberger 
Cc: Aaron Williams 
Cc: Chandrakala Chavva 
---
 drivers/net/e1000.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c
index 8e6c755f64..2c57786ec9 100644
--- a/drivers/net/e1000.c
+++ b/drivers/net/e1000.c
@@ -47,10 +47,8 @@ tested on both gig copper and gig fiber boards
 
 #ifdef CONFIG_DM_ETH
 #define virt_to_bus(devno, v)  dm_pci_virt_to_mem(devno, (void *) (v))
-#define bus_to_phys(devno, a)  dm_pci_mem_to_phys(devno, a)
 #else
 #define virt_to_bus(devno, v)  pci_virt_to_mem(devno, (void *) (v))
-#define bus_to_phys(devno, a)  pci_mem_to_phys(devno, a)
 #endif
 
 #define E1000_DEFAULT_PCI_PBA  0x0030
-- 
2.29.2



[PATCH 3/3] net: e1000: Add missing address translations

2020-11-16 Thread Stefan Roese
Add some missing address translations from virtual address in local DRAM
to physical address, which is needed for the DMA transactions to work
correctly.

This issue was detected while testing the e1000 driver on the MIPS
Octeon III platform, which needs address translation.

Signed-off-by: Stefan Roese 
Cc: Joe Hershberger 
Cc: Aaron Williams 
Cc: Chandrakala Chavva 
---
 drivers/net/e1000.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c
index bf6cd7d602..cf57ff067b 100644
--- a/drivers/net/e1000.c
+++ b/drivers/net/e1000.c
@@ -5143,7 +5143,7 @@ fill_rx(struct e1000_hw *hw)
rd = rx_base + rx_tail;
rx_tail = (rx_tail + 1) % 8;
memset(rd, 0, 16);
-   rd->buffer_addr = cpu_to_le64((unsigned long)packet);
+   rd->buffer_addr = cpu_to_le64(virt_to_phys(packet));
 
/*
 * Make sure there are no stale data in WB over this area, which
@@ -5174,8 +5174,8 @@ e1000_configure_tx(struct e1000_hw *hw)
unsigned long tipg, tarc;
uint32_t ipgr1, ipgr2;
 
-   E1000_WRITE_REG(hw, TDBAL, lower_32_bits((unsigned long)tx_base));
-   E1000_WRITE_REG(hw, TDBAH, upper_32_bits((unsigned long)tx_base));
+   E1000_WRITE_REG(hw, TDBAL, lower_32_bits(virt_to_phys(tx_base)));
+   E1000_WRITE_REG(hw, TDBAH, upper_32_bits(virt_to_phys(tx_base)));
 
E1000_WRITE_REG(hw, TDLEN, 128);
 
@@ -5319,8 +5319,8 @@ e1000_configure_rx(struct e1000_hw *hw)
E1000_WRITE_FLUSH(hw);
}
/* Setup the Base and Length of the Rx Descriptor Ring */
-   E1000_WRITE_REG(hw, RDBAL, lower_32_bits((unsigned long)rx_base));
-   E1000_WRITE_REG(hw, RDBAH, upper_32_bits((unsigned long)rx_base));
+   E1000_WRITE_REG(hw, RDBAL, lower_32_bits(virt_to_phys(rx_base)));
+   E1000_WRITE_REG(hw, RDBAH, upper_32_bits(virt_to_phys(rx_base)));
 
E1000_WRITE_REG(hw, RDLEN, 128);
 
-- 
2.29.2



[PATCH 2/3] net: e1000: Use virt_to_phys() instead of pci_virt_to_mem()

2020-11-16 Thread Stefan Roese
Using (dm_)pci_virt_to_mem() is incorrect to translate the virtual
address in local DRAM to a physical address. The correct macro here
is virt_to_phys() so switch to using this macro.

As virt_to_bus() is now not used any more, this patch also removes
both definitions (DM and non-DM).

This issue was detected while testing the e1000 driver on the MIPS
Octeon III platform, which needs address translation.

Signed-off-by: Stefan Roese 
Cc: Joe Hershberger 
Cc: Aaron Williams 
Cc: Chandrakala Chavva 
---
 drivers/net/e1000.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c
index 2c57786ec9..bf6cd7d602 100644
--- a/drivers/net/e1000.c
+++ b/drivers/net/e1000.c
@@ -45,12 +45,6 @@ tested on both gig copper and gig fiber boards
 
 #define TOUT_LOOP   10
 
-#ifdef CONFIG_DM_ETH
-#define virt_to_bus(devno, v)  dm_pci_virt_to_mem(devno, (void *) (v))
-#else
-#define virt_to_bus(devno, v)  pci_virt_to_mem(devno, (void *) (v))
-#endif
-
 #define E1000_DEFAULT_PCI_PBA  0x0030
 #define E1000_DEFAULT_PCIE_PBA 0x000a0026
 
@@ -5387,7 +5381,7 @@ static int _e1000_transmit(struct e1000_hw *hw, void 
*txpacket, int length)
txp = tx_base + tx_tail;
tx_tail = (tx_tail + 1) % 8;
 
-   txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet));
+   txp->buffer_addr = cpu_to_le64(virt_to_phys(nv_packet));
txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
txp->upper.data = 0;
 
-- 
2.29.2



Re: Pull request: u-boot-rockchip-20201113

2020-11-16 Thread Tom Rini
On Mon, Nov 16, 2020 at 10:42:54AM +0800, Kever Yang wrote:

> Hi Tom,
> 
> Please pull the rockchip updates/fixes:
> - Fix USB support for rk3399 Pinebook Pro;
> - Fix SPI boot for rk3399 boards other than Bob;
> - Fix 32bit boards firmware build without SPL_OPTEE support;
> - Fix rockchip display driver license;
> 
> Gitlab ci:
> https://gitlab.denx.de/u-boot/custodians/u-boot-rockchip/pipelines/5336
> 
> Thanks,
> - Kever
> 
> The following changes since commit 832bfad7451e2e7bd23c96edff2be050905ac3f6:
> 
>   libfdt: Fix signedness comparison warnings (2020-11-10 14:31:08 -0500)
> 
> are available in the Git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-rockchip.git 
> tags/u-boot-rockchip-20201113
> 
> for you to fetch changes up to b197c934b11f611dcc1a083d90e68019d1e010cf:
> 
>   rockchip: Pinebook Pro: Fix USB (2020-11-13 18:17:57 +0800)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PULL u-boot] Please pull u-boot-amlogic-20201116

2020-11-16 Thread Tom Rini
On Mon, Nov 16, 2020 at 11:23:19AM +0100, Neil Armstrong wrote:

> Hi Tom,
> 
> This PR fixes the MMC driver on SM1 based platforms, syncs the SoC Ids and 
> fixes 2 potential
> build warning.
> 
> The CI job is at 
> https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic/pipelines/5354
> 
> Thanks,
> Neil
> 
> The following changes since commit 832bfad7451e2e7bd23c96edff2be050905ac3f6:
> 
>   libfdt: Fix signedness comparison warnings (2020-11-10 14:31:08 -0500)
> 
> are available in the Git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic.git 
> tags/u-boot-amlogic-20201116
> 
> for you to fetch changes up to c87eab81616d671a6004ffc95847bad21b7eb005:
> 
>   ARM: dts: meson-sm1: add u-boot specific MMC controller compatible 
> (2020-11-12 14:31:29 +0100)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v3] env: mmc: Correct partition comparison in mmc_offset_try_partition

2020-11-16 Thread Wolfgang Denk
Dear Hoyeonjiki Kim,

In message <20201115172544.548-1-jigi@gmail.com> you wrote:
> The function mmc_offset_try_partition searches the MMC partition for
> locating environment data, by comparing the partition names with config
> "u-boot,mmc-env-parition". However, it only compares the first word-size
> bytes (size of 'const char *'), which may make the function to find
> unintended partition.
>
> Correct the function not to partially compare the partition name with
> config "u-boot,mmc-env-partition".
>
> Fixes: c9e87ba66540 ("env: Save environment at the end of an MMC partition")
> Signed-off-by: Hoyeonjiki Kim 
> Reviewed-by: Jaehoon Chung 
> Reviewed-by: Jorge Ramire-Ortiz 
> Reviewed-by: Wolfgang Denk 
> ---

Reviewed-by: Wolfgang Denk 


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
God made the integers; all else is the work of Man.   - Kronecker


[PATCH] common: fit: add missing newline

2020-11-16 Thread Michael Walle
The debug statement doesn't end with a newline. Add it.

Signed-off-by: Michael Walle 
---
 common/common_fit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/common_fit.c b/common/common_fit.c
index a993308100..219674d467 100644
--- a/common/common_fit.c
+++ b/common/common_fit.c
@@ -67,7 +67,7 @@ int fit_find_config_node(const void *fdt)
if (board_fit_config_name_match(name))
continue;
 
-   debug("Selecting config '%s'", name);
+   debug("Selecting config '%s'\n", name);
 
return node;
}
-- 
2.20.1



Re: [PATCH] mmc: display an error number to debug

2020-11-16 Thread Jaehoon Chung
Dear Stephen,

On 11/17/20 12:39 AM, Stephen Warren wrote:
> On 11/6/20 4:23 AM, Jaehoon Chung wrote:
>> It's useful to know an error number when it's debugging.
> 
>> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> 
>> @@ -2746,7 +2746,7 @@ static int mmc_power_on(struct mmc *mmc)
>>  int ret = regulator_set_enable(mmc->vmmc_supply, true);
>>  
>>  if (ret) {
>> -puts("Error enabling VMMC supply\n");
>> +puts("Error enabling VMMC supply : %d\n", ret);
> 
> At least this one needs to be printf() not puts(). This causes build
> failures for any board that compiles this code, i.e. anything with the
> following enabled:

Thanks for pointing out! Will fix.

Best Regards,
Jaehoon Chung

> 
> static int mmc_power_on(struct mmc *mmc)
> {
> #if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_REGULATOR)
> 



[PATCH 0/8] spl: atf: add support for LOAD_IMAGE_V2

2020-11-16 Thread Michael Walle
Newer TF-A versions provide a new image loading protocol. This is used on
(newer?) NXP's SoCs. Normally, the bootflow is bl1 -> bl2 -> bl31 ->
u-boot. With this series it is possible that U-Boot SPL loads the bl31
directly and thus replacing bl1 and bl2 from the TF-A.

This was tested on the Kontron sl28 board using NXPs bl31 and the upstream
version of the OP-TEE Trusted OS.

Michael Walle (8):
  treewide: use CONFIG_IS_ENABLED() for ARMV8_SEC_FIRMWARE_SUPPORT
  spl: atf: move storage for bl31_params into function
  spl: atf: provide a bl2_plat_get_bl31_params_default()
  spl: atf: remove helper structure from common header
  spl: atf: add support for LOAD_IMAGE_V2
  armv8: layerscape: don't initialize GIC in SPL
  board: sl28: add ATF support (bl31)
  board: sl28: add OP-TEE Trusted OS support (bl32)

 arch/arm/cpu/armv8/cpu-dt.c   |   2 +-
 arch/arm/cpu/armv8/fsl-layerscape/fdt.c   |   8 +-
 arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S  |   2 +
 arch/arm/cpu/armv8/fsl-layerscape/ppa.c   |   2 +-
 .../dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi  |  77 ++-
 arch/arm/lib/bootm-fdt.c  |   2 +-
 arch/arm/lib/psci-dt.c|   6 +-
 board/kontron/sl28/Kconfig|  33 +
 board/kontron/sl28/Makefile   |   6 +-
 board/kontron/sl28/sl28.c |   7 +
 board/kontron/sl28/spl_atf.c  |  49 +++
 common/spl/Kconfig|   9 ++
 common/spl/spl_atf.c  | 129 --
 include/atf_common.h  |  42 --
 include/spl.h |  70 --
 15 files changed, 401 insertions(+), 43 deletions(-)
 create mode 100644 board/kontron/sl28/spl_atf.c

-- 
2.20.1



[PATCH 1/8] treewide: use CONFIG_IS_ENABLED() for ARMV8_SEC_FIRMWARE_SUPPORT

2020-11-16 Thread Michael Walle
There is SPL_ARMV8_SEC_FIRMWARE_SUPPORT and ARMV8_SEC_FIRMWARE_SUPPORT.
Thus use CONFIG_IS_ENABLED() instead of the simple #ifdef.

Signed-off-by: Michael Walle 
---
 arch/arm/cpu/armv8/cpu-dt.c | 2 +-
 arch/arm/cpu/armv8/fsl-layerscape/fdt.c | 8 
 arch/arm/cpu/armv8/fsl-layerscape/ppa.c | 2 +-
 arch/arm/lib/bootm-fdt.c| 2 +-
 arch/arm/lib/psci-dt.c  | 6 +++---
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/arm/cpu/armv8/cpu-dt.c b/arch/arm/cpu/armv8/cpu-dt.c
index 97d4473a68..61c38b17cb 100644
--- a/arch/arm/cpu/armv8/cpu-dt.c
+++ b/arch/arm/cpu/armv8/cpu-dt.c
@@ -9,7 +9,7 @@
 #include 
 #include 
 
-#ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
+#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
 int psci_update_dt(void *fdt)
 {
/*
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c 
b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
index 6d3391db3b..598ee2ffa2 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/fdt.c
@@ -26,7 +26,7 @@
 #endif
 #include 
 #include 
-#ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
+#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
 #include 
 #endif
 #include 
@@ -81,7 +81,7 @@ void ft_fixup_cpu(void *blob)
"device_type", "cpu", 4);
}
 
-#if defined(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT) && \
+#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT) && \
defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
int node;
u32 psci_ver;
@@ -383,7 +383,7 @@ static void fdt_fixup_msi(void *blob)
 }
 #endif
 
-#ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
+#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
 /* Remove JR node used by SEC firmware */
 void fdt_fixup_remove_jr(void *blob)
 {
@@ -488,7 +488,7 @@ void ft_cpu_setup(void *blob, struct bd_info *bd)
else {
ccsr_sec_t __iomem *sec;
 
-#ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
+#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
fdt_fixup_remove_jr(blob);
fdt_fixup_kaslr(blob);
 #endif
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/ppa.c 
b/arch/arm/cpu/armv8/fsl-layerscape/ppa.c
index 1ddb267093..2285296ea0 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/ppa.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/ppa.c
@@ -16,7 +16,7 @@
 #elif defined(CONFIG_FSL_LSCH2)
 #include 
 #endif
-#ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
+#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
 #include 
 #endif
 #ifdef CONFIG_CHAIN_OF_TRUST
diff --git a/arch/arm/lib/bootm-fdt.c b/arch/arm/lib/bootm-fdt.c
index 02a49a8e10..fe46a7d7c9 100644
--- a/arch/arm/lib/bootm-fdt.c
+++ b/arch/arm/lib/bootm-fdt.c
@@ -63,7 +63,7 @@ int arch_fixup_fdt(void *blob)
 #endif
 
 #if defined(CONFIG_ARMV7_NONSEC) || defined(CONFIG_ARMV8_PSCI) || \
-   defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
+   CONFIG_IS_ENABLED(SEC_FIRMWARE_ARMV8_PSCI)
ret = psci_update_dt(blob);
if (ret)
return ret;
diff --git a/arch/arm/lib/psci-dt.c b/arch/arm/lib/psci-dt.c
index 0ed29a43f1..903b335704 100644
--- a/arch/arm/lib/psci-dt.c
+++ b/arch/arm/lib/psci-dt.c
@@ -10,7 +10,7 @@
 #include 
 #include 
 #include 
-#ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
+#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
 #include 
 #endif
 
@@ -64,7 +64,7 @@ int fdt_psci(void *fdt)
return nodeoff;
 
 init_psci_node:
-#ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
+#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
psci_ver = sec_firmware_support_psci_version();
 #elif defined(CONFIG_ARMV7_PSCI_1_0) || defined(CONFIG_ARMV8_PSCI)
psci_ver = ARM_PSCI_VER_1_0;
@@ -85,7 +85,7 @@ init_psci_node:
return tmp;
}
 
-#ifndef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
+#if !CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
/*
 * The Secure firmware framework isn't able to support PSCI version 0.1.
 */
-- 
2.20.1



[PATCH 3/8] spl: atf: provide a bl2_plat_get_bl31_params_default()

2020-11-16 Thread Michael Walle
Move the actual implementation of the bl2_plat_get_bl31_params() to its
own function. The weak function will just call the default
implementation. This has the advantage that board code can still call
the original implementation if it just want to modify minor things.

Signed-off-by: Michael Walle 
---
 common/spl/spl_atf.c | 14 +++---
 include/spl.h| 35 +++
 2 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/common/spl/spl_atf.c b/common/spl/spl_atf.c
index df0a198d55..63af6a6207 100644
--- a/common/spl/spl_atf.c
+++ b/common/spl/spl_atf.c
@@ -18,9 +18,9 @@
 #include 
 #include 
 
-__weak struct bl31_params *bl2_plat_get_bl31_params(uintptr_t bl32_entry,
-   uintptr_t bl33_entry,
-   uintptr_t fdt_addr)
+struct bl31_params *bl2_plat_get_bl31_params_default(uintptr_t bl32_entry,
+uintptr_t bl33_entry,
+uintptr_t fdt_addr)
 {
static struct bl2_to_bl31_params_mem bl31_params_mem;
struct bl31_params *bl2_to_bl31_params;
@@ -77,6 +77,14 @@ __weak struct bl31_params 
*bl2_plat_get_bl31_params(uintptr_t bl32_entry,
return bl2_to_bl31_params;
 }
 
+__weak struct bl31_params *bl2_plat_get_bl31_params(uintptr_t bl32_entry,
+   uintptr_t bl33_entry,
+   uintptr_t fdt_addr)
+{
+   return bl2_plat_get_bl31_params_default(bl32_entry, bl33_entry,
+   fdt_addr);
+}
+
 static inline void raw_write_daif(unsigned int daif)
 {
__asm__ __volatile__("msr DAIF, %0\n\t" : : "r" (daif) : "memory");
diff --git a/include/spl.h b/include/spl.h
index b72dfc7e3d..dccf515511 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -526,18 +526,17 @@ int spl_ymodem_load_image(struct spl_image_info 
*spl_image,
 void spl_invoke_atf(struct spl_image_info *spl_image);
 
 /**
- * bl2_plat_get_bl31_params() - prepare params for bl31.
+ * bl2_plat_get_bl31_params() - return params for bl31.
  * @bl32_entry address of BL32 executable (secure)
  * @bl33_entry address of BL33 executable (non secure)
  * @fdt_addr   address of Flat Device Tree
  *
- * This function assigns a pointer to the memory that the platform has kept
- * aside to pass platform specific and trusted firmware related information
- * to BL31. This memory is allocated by allocating memory to
- * bl2_to_bl31_params_mem structure which is a superset of all the
- * structure whose information is passed to BL31
- * NOTE: This function should be called only once and should be done
- * before generating params to BL31
+ * This is a weak function which might be overridden by the board code. By
+ * default it will just call bl2_plat_get_bl31_params_default().
+ *
+ * If you just want to manipulate or add some parameters, you can override
+ * this function, call bl2_plat_get_bl31_params_default and operate on the
+ * returned bl31 params.
  *
  * @return bl31 params structure pointer
  */
@@ -545,6 +544,26 @@ struct bl31_params *bl2_plat_get_bl31_params(uintptr_t 
bl32_entry,
 uintptr_t bl33_entry,
 uintptr_t fdt_addr);
 
+/**
+ * bl2_plat_get_bl31_params_default() - prepare params for bl31.
+ * @bl32_entry address of BL32 executable (secure)
+ * @bl33_entry address of BL33 executable (non secure)
+ * @fdt_addr   address of Flat Device Tree
+ *
+ * This is the default implementation of bl2_plat_get_bl31_params(). It assigns
+ * a pointer to the memory that the platform has kept aside to pass platform
+ * specific and trusted firmware related information to BL31. This memory is
+ * allocated by allocating memory to bl2_to_bl31_params_mem structure which is
+ * a superset of all the structure whose information is passed to BL31
+ *
+ * NOTE: The memory is statically allocated, thus this function should be
+ * called only once. All subsequent calls will overwrite any changes.
+ *
+ * @return bl31 params structure pointer
+ */
+struct bl31_params *bl2_plat_get_bl31_params_default(uintptr_t bl32_entry,
+uintptr_t bl33_entry,
+uintptr_t fdt_addr);
 /**
  * spl_optee_entry - entry function for optee
  *
-- 
2.20.1



[PATCH 4/8] spl: atf: remove helper structure from common header

2020-11-16 Thread Michael Walle
bl2_to_bl31_params_mem is just an implementation detail of the SPL ATF
support and is not needed anywhere else. Move it from the header to the
actual module.

Signed-off-by: Michael Walle 
---
 common/spl/spl_atf.c | 11 +++
 include/atf_common.h | 14 --
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/common/spl/spl_atf.c b/common/spl/spl_atf.c
index 63af6a6207..51b45d5dc6 100644
--- a/common/spl/spl_atf.c
+++ b/common/spl/spl_atf.c
@@ -18,6 +18,17 @@
 #include 
 #include 
 
+/* Holds all the structures we need for bl31 parameter passing */
+struct bl2_to_bl31_params_mem {
+   struct bl31_params bl31_params;
+   struct atf_image_info bl31_image_info;
+   struct atf_image_info bl32_image_info;
+   struct atf_image_info bl33_image_info;
+   struct entry_point_info bl33_ep_info;
+   struct entry_point_info bl32_ep_info;
+   struct entry_point_info bl31_ep_info;
+};
+
 struct bl31_params *bl2_plat_get_bl31_params_default(uintptr_t bl32_entry,
 uintptr_t bl33_entry,
 uintptr_t fdt_addr)
diff --git a/include/atf_common.h b/include/atf_common.h
index fd5454c55b..e173a10ca9 100644
--- a/include/atf_common.h
+++ b/include/atf_common.h
@@ -162,20 +162,6 @@ struct bl31_params {
struct atf_image_info *bl33_image_info;
 };
 
-/***
- * This structure represents the superset of information that is passed to
- * BL31, e.g. while passing control to it from BL2, bl31_params
- * and other platform specific params
- 
**/
-struct bl2_to_bl31_params_mem {
-   struct bl31_params bl31_params;
-   struct atf_image_info bl31_image_info;
-   struct atf_image_info bl32_image_info;
-   struct atf_image_info bl33_image_info;
-   struct entry_point_info bl33_ep_info;
-   struct entry_point_info bl32_ep_info;
-   struct entry_point_info bl31_ep_info;
-};
 
 #endif /*__ASSEMBLY__ */
 
-- 
2.20.1



[PATCH 2/8] spl: atf: move storage for bl31_params into function

2020-11-16 Thread Michael Walle
There is no need to have the storage available globally. This is also a
preparation for LOAD_IMAGE_V2 support. That will introduce a similar
generator function which also has its own storage.

Signed-off-by: Michael Walle 
---
 common/spl/spl_atf.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/common/spl/spl_atf.c b/common/spl/spl_atf.c
index 9bd25f6b32..df0a198d55 100644
--- a/common/spl/spl_atf.c
+++ b/common/spl/spl_atf.c
@@ -18,13 +18,12 @@
 #include 
 #include 
 
-static struct bl2_to_bl31_params_mem bl31_params_mem;
-static struct bl31_params *bl2_to_bl31_params;
-
 __weak struct bl31_params *bl2_plat_get_bl31_params(uintptr_t bl32_entry,
uintptr_t bl33_entry,
uintptr_t fdt_addr)
 {
+   static struct bl2_to_bl31_params_mem bl31_params_mem;
+   struct bl31_params *bl2_to_bl31_params;
struct entry_point_info *bl32_ep_info;
struct entry_point_info *bl33_ep_info;
 
-- 
2.20.1



[PATCH 6/8] armv8: layerscape: don't initialize GIC in SPL

2020-11-16 Thread Michael Walle
The BL31 expects the GIC to be uninitialized. Thus, if we are loading
the BL31 by the SPL we must not initialize it. If u-boot is loaded by
the SPL directly, it will initialize the GIC again (in the same
lowlevel_init()).

This was tested on a custom board with SPL loading the BL31 and jumping
to u-boot as BL33 as well as loading u-boot directly by the SPL. In case
the ATF BL1/BL2 is used, this patch won't change anything, because no
SPL is used at all.

Signed-off-by: Michael Walle 
---
 arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S 
b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S
index a519f6ed67..d8803738f1 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S
+++ b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S
@@ -192,6 +192,7 @@ ENTRY(lowlevel_init)
 #endif
 
/* Initialize GIC Secure Bank Status */
+#if !defined(CONFIG_SPL_BUILD)
 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
branch_if_slave x0, 1f
bl  get_gic_offset
@@ -205,6 +206,7 @@ ENTRY(lowlevel_init)
bl  gic_init_secure_percpu
 #endif
 #endif
+#endif
 
 100:
branch_if_master x0, x1, 2f
-- 
2.20.1



[PATCH 5/8] spl: atf: add support for LOAD_IMAGE_V2

2020-11-16 Thread Michael Walle
Newer platforms use the LOAD_IMAGE_V2 parameter passing method. Add
support for it.

Signed-off-by: Michael Walle 
---
 common/spl/Kconfig   |  9 
 common/spl/spl_atf.c | 99 ++--
 include/atf_common.h | 30 ++
 include/spl.h| 35 
 4 files changed, 169 insertions(+), 4 deletions(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index d8086bd9e8..6d980be0b7 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -1276,6 +1276,15 @@ config SPL_ATF
  is loaded by SPL (which is considered as BL2 in ATF terminology).
  More detail at: https://github.com/ARM-software/arm-trusted-firmware
 
+config SPL_ATF_LOAD_IMAGE_V2
+   bool "Use the new LOAD_IMAGE_V2 parameter passing"
+   depends on SPL_ATF
+   help
+ Some platforms use the newer LOAD_IMAGE_V2 parameter passing.
+
+ If you want to load a bl31 image from the SPL and need the new
+ method, say Y.
+
 config SPL_ATF_NO_PLATFORM_PARAM
 bool "Pass no platform parameter"
depends on SPL_ATF
diff --git a/common/spl/spl_atf.c b/common/spl/spl_atf.c
index 51b45d5dc6..e1b68dd561 100644
--- a/common/spl/spl_atf.c
+++ b/common/spl/spl_atf.c
@@ -29,6 +29,19 @@ struct bl2_to_bl31_params_mem {
struct entry_point_info bl31_ep_info;
 };
 
+struct bl2_to_bl31_params_mem_v2 {
+   struct bl_params bl_params;
+   struct bl_params_node bl31_params_node;
+   struct bl_params_node bl32_params_node;
+   struct bl_params_node bl33_params_node;
+   struct atf_image_info bl31_image_info;
+   struct atf_image_info bl32_image_info;
+   struct atf_image_info bl33_image_info;
+   struct entry_point_info bl33_ep_info;
+   struct entry_point_info bl32_ep_info;
+   struct entry_point_info bl31_ep_info;
+};
+
 struct bl31_params *bl2_plat_get_bl31_params_default(uintptr_t bl32_entry,
 uintptr_t bl33_entry,
 uintptr_t fdt_addr)
@@ -96,6 +109,79 @@ __weak struct bl31_params 
*bl2_plat_get_bl31_params(uintptr_t bl32_entry,
fdt_addr);
 }
 
+struct bl_params *bl2_plat_get_bl31_params_v2_default(uintptr_t bl32_entry,
+ uintptr_t bl33_entry,
+ uintptr_t fdt_addr)
+{
+   static struct bl2_to_bl31_params_mem_v2 bl31_params_mem;
+   struct bl_params *bl_params;
+   struct bl_params_node *bl_params_node;
+
+   /*
+* Initialise the memory for all the arguments that needs to
+* be passed to BL31
+*/
+   memset(&bl31_params_mem, 0, sizeof(bl31_params_mem));
+
+   /* Assign memory for TF related information */
+   bl_params = &bl31_params_mem.bl_params;
+   SET_PARAM_HEAD(bl_params, ATF_PARAM_BL_PARAMS, ATF_VERSION_2, 0);
+   bl_params->head = &bl31_params_mem.bl31_params_node;
+
+   /* Fill BL31 related information */
+   bl_params_node = &bl31_params_mem.bl31_params_node;
+   bl_params_node->image_id = ATF_BL31_IMAGE_ID;
+   bl_params_node->image_info = &bl31_params_mem.bl31_image_info;
+   bl_params_node->ep_info = &bl31_params_mem.bl31_ep_info;
+   bl_params_node->next_params_info = &bl31_params_mem.bl32_params_node;
+   SET_PARAM_HEAD(bl_params_node->image_info, ATF_PARAM_IMAGE_BINARY,
+  ATF_VERSION_2, 0);
+
+   /* Fill BL32 related information */
+   bl_params_node = &bl31_params_mem.bl32_params_node;
+   bl_params_node->image_id = ATF_BL32_IMAGE_ID;
+   bl_params_node->image_info = &bl31_params_mem.bl32_image_info;
+   bl_params_node->ep_info = &bl31_params_mem.bl32_ep_info;
+   bl_params_node->next_params_info = &bl31_params_mem.bl33_params_node;
+   SET_PARAM_HEAD(bl_params_node->ep_info, ATF_PARAM_EP,
+  ATF_VERSION_2, ATF_EP_SECURE);
+
+   /* secure payload is optional, so set pc to 0 if absent */
+   bl_params_node->ep_info->args.arg3 = fdt_addr;
+   bl_params_node->ep_info->pc = bl32_entry ? bl32_entry : 0;
+   bl_params_node->ep_info->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX,
+   DISABLE_ALL_EXECPTIONS);
+   SET_PARAM_HEAD(bl_params_node->image_info, ATF_PARAM_IMAGE_BINARY,
+  ATF_VERSION_2, 0);
+
+   /* Fill BL33 related information */
+   bl_params_node = &bl31_params_mem.bl33_params_node;
+   bl_params_node->image_id = ATF_BL33_IMAGE_ID;
+   bl_params_node->image_info = &bl31_params_mem.bl33_image_info;
+   bl_params_node->ep_info = &bl31_params_mem.bl33_ep_info;
+   bl_params_node->next_params_info = NULL;
+   SET_PARAM_HEAD(bl_params_node->ep_info, ATF_PARAM_EP,
+  ATF_VERSION_2, ATF_EP_NON_SECURE);
+
+   /* BL33 expects to receive the primary CPU MPID (t

[PATCH 7/8] board: sl28: add ATF support (bl31)

2020-11-16 Thread Michael Walle
Add support to load the bl31 part of the ARM Trusted Firmware by the
SPL.

Signed-off-by: Michael Walle 
---
 .../dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi  | 41 +-
 board/kontron/sl28/Kconfig| 10 
 board/kontron/sl28/Makefile   |  6 ++-
 board/kontron/sl28/spl_atf.c  | 54 +++
 4 files changed, 109 insertions(+), 2 deletions(-)
 create mode 100644 board/kontron/sl28/spl_atf.c

diff --git a/arch/arm/dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi 
b/arch/arm/dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi
index 2375549c6e..4b97e9d388 100644
--- a/arch/arm/dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi
+++ b/arch/arm/dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi
@@ -16,7 +16,7 @@
ethernet3 = &enetc6;
};
 
-   binman {
+   binman: binman {
filename = "u-boot.rom";
pad-byte = <0xff>;
 
@@ -102,6 +102,45 @@
};
 };
 
+#ifdef CONFIG_SL28_SPL_LOADS_ATF_BL31
+&binman {
+   fit {
+   images {
+   bl31 {
+   description = "ARM Trusted Firmware (bl31)";
+   type = "firmware";
+   arch = "arm";
+   os = "arm-trusted-firmware";
+   compression = "none";
+   load = ;
+   entry = ;
+
+   blob-ext {
+   filename = "bl31.bin";
+   };
+   };
+   };
+
+   configurations {
+   conf-1 {
+   firmware = "bl31";
+   loadables = "uboot", "bl31";
+   };
+
+   conf-2 {
+   firmware = "bl31";
+   loadables = "uboot", "bl31";
+   };
+
+   conf-3 {
+   firmware = "bl31";
+   loadables = "uboot", "bl31";
+   };
+   };
+   };
+};
+#endif
+
 &i2c0 {
rtc: rtc@32 {
};
diff --git a/board/kontron/sl28/Kconfig b/board/kontron/sl28/Kconfig
index cdec39be01..aba49fc115 100644
--- a/board/kontron/sl28/Kconfig
+++ b/board/kontron/sl28/Kconfig
@@ -15,4 +15,14 @@ config SYS_CONFIG_NAME
 config SYS_TEXT_BASE
default 0x9600
 
+config SL28_SPL_LOADS_ATF_BL31
+   bool "SPL loads BL31 of the ARM Trusted Firmware"
+   select SPL_ATF
+   select SPL_ATF_LOAD_IMAGE_V2
+   select ARMV8_SEC_FIRMWARE_SUPPORT
+   select SEC_FIRMWARE_ARMV8_PSCI
+   help
+ Enable this to load a BL31 image by the SPL. You have to
+ provde a bl31.bin in u-boot's root directory.
+
 endif
diff --git a/board/kontron/sl28/Makefile b/board/kontron/sl28/Makefile
index 74d8012f0f..5d220f0744 100644
--- a/board/kontron/sl28/Makefile
+++ b/board/kontron/sl28/Makefile
@@ -5,4 +5,8 @@ obj-y += sl28.o cmds.o
 endif
 
 obj-y += common.o ddr.o
-obj-$(CONFIG_SPL_BUILD) += spl.o
+
+ifdef CONFIG_SPL_BUILD
+obj-y += spl.o
+obj-$(CONFIG_SPL_ATF) += spl_atf.o
+endif
diff --git a/board/kontron/sl28/spl_atf.c b/board/kontron/sl28/spl_atf.c
new file mode 100644
index 00..5438b5239c
--- /dev/null
+++ b/board/kontron/sl28/spl_atf.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * LS1028A TF-A calling support
+ *
+ * Copyright (c) 2020 Michael Walle 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct region_info {
+   u64 addr;
+   u64 size;
+};
+
+struct dram_regions_info {
+   u64 num_dram_regions;
+   u64 total_dram_size;
+   struct region_info region[CONFIG_NR_DRAM_BANKS];
+};
+
+struct bl_params *bl2_plat_get_bl31_params_v2(uintptr_t bl32_entry,
+ uintptr_t bl33_entry,
+ uintptr_t fdt_addr)
+{
+   static struct dram_regions_info dram_regions_info = { 0 };
+   struct bl_params *bl_params;
+   struct bl_params_node *node;
+   void *dcfg_ccsr = (void *)DCFG_BASE;
+   int i;
+
+   dram_regions_info.num_dram_regions = CONFIG_NR_DRAM_BANKS;
+   for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+   dram_regions_info.region[i].addr = gd->bd->bi_dram[i].start;
+   dram_regions_info.region[i].size = gd->bd->bi_dram[i].size;
+   dram_regions_info.total_dram_size += gd->bd->bi_dram[i].size;
+   }
+
+   bl_params = bl2_plat_get_bl31_params_v2_default(bl32_entry, bl33_entry,
+   fdt_addr);
+
+   for_each_bl_params_node(bl_params, node) {
+   if (node->image_id == ATF_BL31_IMAGE_ID) {
+   node->ep_info->args.arg3 = 
(uintptr_t)&dram_regions_info;
+ 

[PATCH 8/8] board: sl28: add OP-TEE Trusted OS support (bl32)

2020-11-16 Thread Michael Walle
Add support to load the OP-TEE Trusted OS by the SPL.

Signed-off-by: Michael Walle 
---
 .../dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi  | 36 +++
 board/kontron/sl28/Kconfig| 23 
 board/kontron/sl28/sl28.c |  7 
 3 files changed, 66 insertions(+)

diff --git a/arch/arm/dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi 
b/arch/arm/dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi
index 4b97e9d388..b89ae15c74 100644
--- a/arch/arm/dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi
+++ b/arch/arm/dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi
@@ -141,6 +141,42 @@
 };
 #endif
 
+#ifdef CONFIG_SL28_SPL_LOADS_OPTEE_BL32
+&binman {
+   fit {
+   images {
+   bl32 {
+   description = "OP-TEE Trusted OS (bl32)";
+   type = "firmware";
+   arch = "arm";
+   os = "tee";
+   compression = "none";
+   load = ;
+   entry = ;
+
+   blob-ext {
+   filename = "tee.bin";
+   };
+   };
+   };
+
+   configurations {
+   conf-1 {
+   loadables = "uboot", "bl31", "bl32";
+   };
+
+   conf-2 {
+   loadables = "uboot", "bl31", "bl32";
+   };
+
+   conf-3 {
+   loadables = "uboot", "bl31", "bl32";
+   };
+   };
+   };
+};
+#endif
+
 &i2c0 {
rtc: rtc@32 {
};
diff --git a/board/kontron/sl28/Kconfig b/board/kontron/sl28/Kconfig
index aba49fc115..4078ef186b 100644
--- a/board/kontron/sl28/Kconfig
+++ b/board/kontron/sl28/Kconfig
@@ -25,4 +25,27 @@ config SL28_SPL_LOADS_ATF_BL31
  Enable this to load a BL31 image by the SPL. You have to
  provde a bl31.bin in u-boot's root directory.
 
+if SL28_SPL_LOADS_ATF_BL31
+
+config SL28_BL31_ENTRY_ADDR
+   hex "Entry point of the BL31 image"
+   default 0xfbe0
+
+endif
+
+config SL28_SPL_LOADS_OPTEE_BL32
+   bool "SPL loads OP-TEE Trusted OS as BL32"
+   depends on SL28_SPL_LOADS_ATF_BL31
+   help
+ Enable this to load a BL32 image by the SPL. You have to
+ provde a tee.bin in u-boot's root directory.
+
+if SL28_SPL_LOADS_OPTEE_BL32
+
+config SL28_BL32_ENTRY_ADDR
+   hex "Entry point of the BL32 image"
+   default 0xfc00
+
+endif
+
 endif
diff --git a/board/kontron/sl28/sl28.c b/board/kontron/sl28/sl28.c
index b18127c4d1..34f17b486b 100644
--- a/board/kontron/sl28/sl28.c
+++ b/board/kontron/sl28/sl28.c
@@ -50,6 +50,7 @@ int ft_board_setup(void *blob, struct bd_info *bd)
u64 base[CONFIG_NR_DRAM_BANKS];
u64 size[CONFIG_NR_DRAM_BANKS];
int nbanks = CONFIG_NR_DRAM_BANKS;
+   int node;
int i;
 
ft_cpu_setup(blob, bd);
@@ -64,5 +65,11 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 
fdt_fixup_icid(blob);
 
+   if (CONFIG_IS_ENABLED(SL28_SPL_LOADS_OPTEE_BL32)) {
+   node = fdt_node_offset_by_compatible(blob, -1, 
"linaro,optee-tz");
+   if (node)
+   fdt_set_node_status(blob, node, FDT_STATUS_OKAY, 0);
+   }
+
return 0;
 }
-- 
2.20.1



[PATCH V2] mmc: display an error number to debug

2020-11-16 Thread Jaehoon Chung
It's useful to know an error number when it's debugging.

Signed-off-by: Jaehoon Chung 
Reviewed-by: Peng Fan 
---
Changelog on V2
- Change from "put" to "printf" to fix build error
---
 drivers/mmc/mmc.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index a47700e313cb..39682f9df1be 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -2179,7 +2179,7 @@ static int mmc_select_mode_and_width(struct mmc *mmc, 
uint card_caps)
err = mmc_execute_tuning(mmc,
 mwt->tuning);
if (err) {
-   pr_debug("tuning failed\n");
+   pr_debug("tuning failed : 
%d\n", err);
goto error;
}
}
@@ -2200,7 +2200,7 @@ error:
}
}
 
-   pr_err("unable to select a mode\n");
+   pr_err("unable to select a mode : %d\n", err);
 
return -ENOTSUPP;
 }
@@ -2746,7 +2746,7 @@ static int mmc_power_on(struct mmc *mmc)
int ret = regulator_set_enable(mmc->vmmc_supply, true);
 
if (ret) {
-   puts("Error enabling VMMC supply\n");
+   printf("Error enabling VMMC supply : %d\n", ret);
return ret;
}
}
@@ -2762,7 +2762,7 @@ static int mmc_power_off(struct mmc *mmc)
int ret = regulator_set_enable(mmc->vmmc_supply, false);
 
if (ret) {
-   pr_debug("Error disabling VMMC supply\n");
+   pr_debug("Error disabling VMMC supply : %d\n", ret);
return ret;
}
}
@@ -2866,7 +2866,7 @@ retry:
 
if (err) {
 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
-   pr_err("Card did not respond to voltage select!\n");
+   pr_err("Card did not respond to voltage select! : 
%d\n", err);
 #endif
return -EOPNOTSUPP;
}
-- 
2.29.0



Re: [BUG] U-boot does not detect emmc card in odroid-c2 for newer U-boot as 2020.04

2020-11-16 Thread Jaehoon Chung
Dear Otto,

On 11/16/20 11:16 PM, Otto Meier wrote:
> I tried to build  an actual u-boot from git for my odroid-c2 board.

Which git repository did you use?
If you can enable CONFIG_MMC_TRACE, it's more helpful to debug.


Best Regards,
Jaehoon Chung

> 
> It doesn't find the emmc card and therefore does not boot from it.
> emmc is Ok and boots with u-boot 2020.04 fine.
> 
> Newer u-boot then 2020.04 show these messages:
> 
> GXBB:BL1:08dafd:0a8993;FEAT:EDFC318C;POC:3;RCY:0;EMMC:0;READ:0;CHK:0;
> TE: 156394
> no sdio debug board detected
> 
> BL2 Built : 11:44:26, Nov 25 2015.
> gxb gfb13a3b-c2 - jcao@wonton
> 
> Board ID = 8
> set vcck to 1100 mv
> set vddee to 1050 mv
> CPU clk: 1536MHz
> DDR channel setting: DDR0 Rank0+1 same
> DDR0: 2048MB(auto) @ 912MHz(2T)-13
> DataBus test pass!
> AddrBus test pass!
> Load fip header from eMMC, src: 0xc200, des: 0x0140, size: 0x00b0
> Load bl30 from eMMC, src: 0x00010200, des: 0x0100, size: 0x9ef0
> Sending bl30OK.
> Run bl30...
> Load bl301 from eMMC, src: 0x0001c200, des: 0x0100, size: 0x18c0
> Wait bl30...Done
> Sending bl301...OK.
> Run bl301...
> 31 from eMMC, src: 0x00020200, des: 0x1010, size: 0x00011130
> 
> 
> --- UART initialized after reboot ---
> [Reset cause: unknown]
> [Image: unknown, amlogic_v1.1.3046-00db630-dirty 2016-08-31 09:24:14 
> tao.zeng@droid04]
> bl30: check_permit, count is 1
> bl30: check_permit: ok!
> chipidLoad bl33 from eMMC, src: 0x00034200, des: 0x0100, size: 0x0009e8f0
> : ef be ad de d f0 ad ba ef be ad de not ES chip
> [0.271464 Inits done]
> secure task start!
> high task start!
> low task start!
> NOTICE:  BL3-1: v1.0(debug):4d2e34d
> NOTICE:  BL3-1: Built : 17:08:35, Oct 29 2015
> INFO:    BL3-1: Initializing runtime services
> INFO:    BL3-1: Preparing for EL3 exit to normal world
> INFO:    BL3-1: Next image address = 0x100
> INFO:    BL3-1: Next image spsr = 0x3c9
> 
> 
> U-Boot 2021.01-rc2 (Nov 15 2020 - 19:06:55 +0100) odroid-c2
> 
> Model: Hardkernel ODROID-C2
> SoC:   Amlogic Meson GXBB (S905) Revision 1f:c (0:1)
> DRAM:  2 GiB
> MMC:   mmc@72000: 0, mmc@74000: 1
> In:    serial
> Out:   serial
> Err:   serial
> Net:   eth0: ethernet@c941
> Hit any key to stop autoboot:  0
> Card did not respond to voltage select!
> Card did not respond to voltage select!
> MMC Device 2 not found
> no mmc device at slot 2
> starting USB...
> Bus usb@c910: USB DWC2
> scanning bus usb@c910 for devices... 2 USB Device(s) found
> 
> 
> Does anybody know how to fixes this breakage?
> 
> Best regards
> 
> Otto
> 
> 



Re: [GIT PULL] TI changes for v2021.01-rc3

2020-11-16 Thread Tom Rini
On Mon, Nov 16, 2020 at 08:33:09PM +0530, Lokesh Vutla wrote:

> Hi Tom,
>   Please find the PR containing TI related changes targeted for
> v2020.01-rc3. Details about the PR are updated in the tag message
> 
> Travis CI build: 
> https://travis-ci.org/github/lokeshvutla/u-boot/builds/743852867
> 
> The following changes since commit 832bfad7451e2e7bd23c96edff2be050905ac3f6:
> 
>   libfdt: Fix signedness comparison warnings (2020-11-10 14:31:08 -0500)
> 
> are available in the Git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-ti.git tags/ti-v2021.01-rc3
> 
> for you to fetch changes up to 914689a204308df47eb60dfbb394fa4cee4fda31:
> 
>   mtd: OneNAND: Set MTD type (2020-11-15 15:29:40 +0530)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [dwi2c PATCH v1] dwi2c add offsets to reads

2020-11-16 Thread Simon Glass
+Heiko Schocher who might know more about this I2C question

On Mon, 9 Nov 2020 at 15:09, Duffin, CooperX  wrote:
>
> -Original Message-
> From: Simon Glass 
> Sent: Saturday, November 7, 2020 1:33 PM
> To: Duffin, CooperX 
> Cc: U-Boot Mailing List ; uboot-snps-...@synopsys.com; 
> Tom Rini ; Robert Beckett ; 
> Heiko Schocher ; Wolgang Denk ; Ian Ray 
> 
> Subject: Re: [dwi2c PATCH v1] dwi2c add offsets to reads
>
> Hi CooperX,
>
> On Fri, 6 Nov 2020 at 16:08, Duffin, CooperX  wrote:
> >
> > Hello Simon,
> >
> > I wasn’t using the test/dm/i2c I this was tested using hardware where I was 
> > using the dm_i2c_read() function. I just tried to use the test/dm/i2c where 
> > I am following the README but I keep getting  "sdl2-config: Command not 
> > found". I suspect it would also fail where it is trying to read but I will 
> > have to get test/dm/i2c working before I know for sure.
> >
> > Essentially my test was
> >
> > int uboot_app (int argc, char * const argv[]) {
> > uint8_t buf[10];
> > uint8_t read_buf[5];
> > uint8_t dev_addr;
> > uint32_t bus_speed;
> > //i2c_bus device pointer
> > struct udevice *i2c_led;
> > struct udevice *bus;
> > app_startup(argv);
> > /* Print the ABI version */
> > printf ("Example expects ABI version %d\n", XF_VERSION);
> > printf ("Actual U-Boot ABI version %d\n", (int)get_version());
> >
> > dev_addr = 0x60;
> > bus_speed = 10; //100KHz
> > printf("starting test i2c\n");
> > buf[0] = 'b';
> > buf[1] = 'o';
> > buf[2] = 'o';
> > buf[3] = 't';
> > //Get i2c chip, init the code
> > printf("init starting\n");
> > if(i2c_get_chip_for_busnum(0 , 0x60, 1, &i2c_led)!=0){
> > printf("ERROR: no device found at %x \n",dev_addr);
> > return (0);
> > }
> > uclass_get_device_by_seq(UCLASS_I2C, 0, &bus);
> > printf("Setting bus speed to %d\n", bus_speed);
> > if(dm_i2c_set_bus_speed(bus,bus_speed)!=0){
> > printf("ERROR: Cannot set buspeed\n");
> > return (0);
> > }
> > printf("i2c_led name is %s\n",i2c_led->name);
> > if(i2c_led == NULL){
> > printf("ERROR i2c_led 0 is null\n");
> > return (0);
> > }
> > printf("Writing\n");
> > for(unsigned int a =0; a< 4; a++){
> > if(dm_i2c_write(i2c_led,a,&buf[a],1)!=0){
> > printf("ERROR writing\n");
> > return (0);
> > }
> > }
> >
> > printf("Reading\n");
> > for(unsigned int a =0; a< 4; a++){
> > if(dm_i2c_read(i2c_led,a,&read_buf[a],1)!=0){
> > printf("ERROR writing\n");
> > return (0);
> > }
> > }
> > printf("read buffer is %c, %c, %c, %c \n",read_buf[0],read_buf[1], 
> > read_buf[2],read_buf[3]);
> > printf ("\n\n");
> > return (0);
> > }
> >
> > ## Starting application at 0x0C10 ...
> > Example expects ABI version 10
> > Actual U-Boot ABI version 10
> > starting test i2c
> > init starting
> > Setting bus speed to 10
> > i2c_led name is generic_60
> > Writing
> > Reading
> > read buffer is o, o, o, o
> >
> > with the fix I get:
> >
> > ## Starting application at 0x0C10 ...
> > Example expects ABI version 10
> > Actual U-Boot ABI version 10
> > starting test i2c
> > init starting
> > Setting bus speed to 10
> > i2c_led name is generic_60
> > Writing
> > Reading
> > read buffer is b, o, o, t
> >
> > which is correct. Similarly if I stop auto boot I get a similar result:
> >
> > Hit any key to stop autoboot:  0
> > device # i2c
> > i2c - I2C sub-system
> >
> > Assuming I write "boot" to the device
> > device # i2c dev 0
> > Setting bus to 0
> > device # i2c md 0x60 0 4
> > : 6f 6f 6f 6f
> >
> > With the fix/patch I get:
> >
> > device# i2c md 0x60 0 4
> > : 62 6f 6f 74boot
> >
> > Which is correct. Also the reads were working in linux leading to my 
> > original suspicion that there might be something going on in the driver. 
> > Hopefully that answers your question let me know if you have anymore.
>
> I had a bit of a look at this. If you look at dm_i2c_read() it actually 
> builds the address into the buffer it sends. So when it gets to 
> __dw_i2c_write() the alen parameter is always 0. That function is actually a 
> holdover from before driver model, so one day the alen and addr parameters 
> will go away.
>
> I wonder if your device does not support multiple-byte reads or writes? Can 
> you try the i2c md with a single byte? There is a DM_I2C_CHIP_WR_ADDRESS 
> option to handle this - see the 'i2c flags'
> command.
>
> In the designware_i2c_xfer(), try printing out the bytes that it gets in each 
> message using i2c_dump_msgs().
>
> Also check

Re: [PATCH] rockchip: Enable BINMAN for boards enable SPL_OPTEE

2020-11-16 Thread Simon Glass
Hi Kever,

On Mon, 9 Nov 2020 at 20:43, Kever Yang  wrote:
>
> Rockchip has many 32bit SoCs and some of them are support SPL_OPTEE now,
> only boards with SPL_OPTEE support can fit BINMAN well, other boards
> will fail at initr_binman() in U-Boot proper after below patch,
> eg. rv1108 board.
> 83187546ae binman: Support multiple images in the library

Is the problem that binman_init() adds too much code? If so, we could
have a new BINMAN_RUNTIME option that enables binman.c and thus allow
boards to disable it.

I imagine that most boards will end up using binman, but many will not
need to access the image definition at runtime.

>
> Fixes: 79030a4861 ("rockchip: Add Single boot image (with binman, pad_cat)")
> Signed-off-by: Kever Yang 
> ---
>
>  arch/arm/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index b2f7fcbd6e..5903c09370 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -1721,7 +1721,7 @@ config ARCH_STM32MP
>  config ARCH_ROCKCHIP
> bool "Support Rockchip SoCs"
> select BLK
> -   select BINMAN if !ARM64
> +   select BINMAN if SPL_OPTEE
> select DM
> select DM_GPIO
> select DM_I2C
> --
> 2.25.1
>
>
>

Regards,
Simon


Re: [PATCH v5 18/27] misc: am33xx: add control module driver

2020-11-16 Thread Simon Glass
Hi Dario,

On Sun, 8 Nov 2020 at 03:50, Dario Binacchi  wrote:
>
> Hi Simon,
> I still have some doubts and therefore I would like to also add
> Lokesh on this matter to finally decide what to do.
>
> > Il 03/11/2020 16:12 Simon Glass  ha scritto:
> >
> >
> > Hi Dario,
> >
> > On Sun, 1 Nov 2020 at 02:13, Dario Binacchi  wrote:
> > >
> > > Hi Simon,
> > >
> > > > Il 28/10/2020 03:10 Simon Glass  ha scritto:
> > > >
> > > >
> > > > On Sun, 25 Oct 2020 at 06:40, Dario Binacchi  wrote:
> > > > >
> > > > > The implementation of this driver was needed to bind the device tree
> > > > > sub-nodes of the 'clocks' node. In fact, the lack of the compatible
> > > > > property in the 'clocks' node does not allow the generic 'syscon' or
> > > > > 'simple-bus' drivers linked to the 'scm_conf@0' node to bind the
> > > > > 'clocks' node and in turn its sub-nodes.
> > > > > The 'scm@21' node is therefore the node closest to the 'clocks' 
> > > > > node
> > > > > whose driver can bind all the 'clocks' sub-nodes. In this way, the
> > > > > address translation functions are able to walk along the device tree
> > > > > towards the upper nodes until the address composition is completed.
> > > > >
> > > > > scm: scm@21 {
> > > > > compatible = "ti,am3-scm", "simple-bus";
> > > > > ...
> > > > >
> > > > > scm_conf: scm_conf@0 {
> > > > > compatible = "syscon", "simple-bus";
> > > > > #address-cells = <1>;
> > > > > #size-cells = <1>;
> > > > > ranges = <0 0 0x800>;
> > > > >
> > > > > scm_clocks: clocks {
> > > > > #address-cells = <1>;
> > > > > #size-cells = <0>;
> > > > > };
> > > > > };
> > > > > };
> > > > >
> > > > > For DT binding details see Linux doc:
> > > > > - Documentation/devicetree/bindings/arm/omap/ctrl.txt
> > > > >
> > > > > Signed-off-by: Dario Binacchi 
> > > > >
> > > > > ---
> > > > >
> > > > > (no changes since v4)
> > > > >
> > > > > Changes in v4:
> > > > > - Include device_compat.h header for dev_xxx macros.
> > > > >
> > > > > Changes in v3:
> > > > > - Remove doc/device-tree-bindings/arm/omap,ctrl.txt.
> > > > > - Remove doc/device-tree-bindings/pinctrl/pinctrl-single.txt.
> > > > > - Add to commit message the references to linux kernel dt binding
> > > > >   documentation.
> > > > >
> > > > > Changes in v2:
> > > > > - Remove the 'ti_am3_scm_clocks' driver. Handle 'scm_clocks' node in
> > > > >   the 'ti_am3_scm' driver.
> > > > > - Update the commit message.
> > > > >
> > > > >  drivers/misc/Kconfig  |  7 
> > > > >  drivers/misc/Makefile |  1 +
> > > > >  drivers/misc/ti-am3-scm.c | 82 
> > > > > +++
> > > > >  3 files changed, 90 insertions(+)
> > > > >  create mode 100644 drivers/misc/ti-am3-scm.c
> > > > >
> > > > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > > > > index b67e906a76..9e8b676637 100644
> > > > > --- a/drivers/misc/Kconfig
> > > > > +++ b/drivers/misc/Kconfig
> > > > > @@ -500,4 +500,11 @@ config ESM_PMIC
> > > > >   Support ESM (Error Signal Monitor) on PMIC devices. ESM is 
> > > > > used
> > > > >   typically to reboot the board in error condition.
> > > > >
> > > > > +config TI_AM3_SCM
> > > > > +   bool "AM33XX specific control module support (SCM)"
> > > > > +   depends on ARCH_OMAP2PLUS
> > > > > +   help
> > > > > +The control module includes status and control logic not 
> > > > > addressed
> > > > > +within the peripherals or the rest of the device 
> > > > > infrastructure.
> > > > > +
> > > > >  endmenu
> > > > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> > > > > index 947bd3a647..056fb3b522 100644
> > > > > --- a/drivers/misc/Makefile
> > > > > +++ b/drivers/misc/Makefile
> > > > > @@ -75,3 +75,4 @@ obj-$(CONFIG_MICROCHIP_FLEXCOM) += 
> > > > > microchip_flexcom.o
> > > > >  obj-$(CONFIG_K3_AVS0) += k3_avs.o
> > > > >  obj-$(CONFIG_ESM_K3) += k3_esm.o
> > > > >  obj-$(CONFIG_ESM_PMIC) += esm_pmic.o
> > > > > +obj-$(CONFIG_TI_AM3_SCM) += ti-am3-scm.o
> > > > > diff --git a/drivers/misc/ti-am3-scm.c b/drivers/misc/ti-am3-scm.c
> > > > > new file mode 100644
> > > > > index 00..ed886e6916
> > > > > --- /dev/null
> > > > > +++ b/drivers/misc/ti-am3-scm.c
> > > > > @@ -0,0 +1,82 @@
> > > > > +// SPDX-License-Identifier: GPL-2.0+
> > > > > +/*
> > > > > + * AM335x specific control module (scm)
> > > > > + *
> > > > > + * Copyright (C) 2020 Dario Binacchi 
> > > > > + */
> > > > > +
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +
> > > > > +static int ti_am3_scm_bind(struct udevice *dev)
> > > > > +{
> > > > > +   ofnode clocks_node, conf_node, node;
> > > > > +   struct udevice *conf_dev;
> > > > > +   int err;
> > > > > +
> > > > > +   if (!strcmp("clocks", ofnode_get_name(dev_o

Re: [PATCH 4/5] env: allow default environment to be amended from control dtb

2020-11-16 Thread Simon Glass
Hi Rasmus,

On Thu, 12 Nov 2020 at 12:59, Wolfgang Denk  wrote:
>
> Dear Rasmus Villemoes,
>
> In message <20201110202603.20944-5-rasmus.villem...@prevas.dk> you wrote:
> > It can be useful to use the same U-Boot binary for multiple purposes,
> > say the normal one, one for developers that allow breaking into the
> > U-Boot shell, and one for use during bootstrapping which runs a
> > special-purpose bootcmd. To that end, allow the control dtb to contain
> > a /config/default-enviroment property, whose value will be used to
> > amend the default environment baked into the U-Boot binary itself.
>
> No, this is not what should be done.
>
> Please try to get used to the idea behind the so called "default
> environment".  Only now I realize that this was a badly chosen name,
> but last_resort_in_case_of_emergencies_environment would have had
> other problems.
>
> The default environment is something which is NOT INTENDED for
> regular use.  it is what you will fall back to in case (and ONLY in
> that case) when your regular persistent environment cannot be used,
> for example because it is not readable (I/O errors or such) or not
> properly initialized or corrupted (CRC checksum error).
>
> It is not the intended use but still somewhat acceptable to use it
> as initial data to populate the regular environment in other cases,
> too.  But that's it.
>
> Apending data to it is not acceptable.  If you need to append data,
> then only to the regular environment.
>
>
> And please, for the sake of avoiding further confusiion, please do
> not name this "default-environment".

Apart from what Wolfgang says here, it does seem useful.

I wonder if we should have a way to load the (whole) environment from DT?

Regards,
Simon


Re: [PATCH v2 3/4] efi_selftest: implement exception test for sandbox

2020-11-16 Thread Simon Glass
On Wed, 11 Nov 2020 at 16:30, Heinrich Schuchardt  wrote:
>
> Provide a unit test that causes an illegal instruction to occur.
>
> The test can be run with the following commands:
>
> => setenv efi_selftest exception
> => bootefi selftest
>
> This might be the output:
>
> Executing 'exception'
> EFI application triggers exception.
> Illegal instruction
> pc = 0x1444d016, pc_reloc = 0xaa078e8dd016
> UEFI image [0x:0x] '/\selftest'
> UEFI image [0x1444b000:0x14451fff] pc=0x2016 '/bug.efi'
> Resetting ...
>
> It would tell us that the exception was triggered by an instruction
> 0x2016 bytes after the load address of the binary with filename /bug.efi.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
> v2:
> no change
> ---
>  lib/efi_selftest/efi_selftest_miniapp_exception.c | 2 ++
>  1 file changed, 2 insertions(+)

Reviewed-by: Simon Glass 

>
> diff --git a/lib/efi_selftest/efi_selftest_miniapp_exception.c 
> b/lib/efi_selftest/efi_selftest_miniapp_exception.c
> index 63c63d75f1..59b7e5100a 100644
> --- a/lib/efi_selftest/efi_selftest_miniapp_exception.c
> +++ b/lib/efi_selftest/efi_selftest_miniapp_exception.c
> @@ -33,6 +33,8 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
> asm volatile (".word 0xe7f7defb\n");
>  #elif defined(CONFIG_RISCV)
> asm volatile (".word 0x\n");
> +#elif defined(CONFIG_SANDBOX)
> +   asm volatile (".word 0x\n");

Does this work on ARM hosts?


>  #elif defined(CONFIG_X86)
> asm volatile (".word 0x\n");
>  #endif
> --
> 2.28.0
>


Re: [PATCH v2 1/4] sandbox: add handler for exceptions

2020-11-16 Thread Simon Glass
Hi Heinrich,

On Wed, 11 Nov 2020 at 16:30, Heinrich Schuchardt  wrote:
>
> Add a handler for SIGILL, SIGBUS, SIGSEGV.
>
> When an exception occurs print the program counter and the loaded
> UEFI binaries and reset the system if CONFIG_SANDBOX_CRASH_RESET=y
> or exit to the OS otherwise.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
> v2:
> add a customizing switch
> set SA_NODEFER flag for sigaction
> ---
>  arch/sandbox/Kconfig  |  9 
>  arch/sandbox/cpu/os.c | 40 +++
>  arch/sandbox/cpu/start.c  |  4 
>  arch/sandbox/lib/interrupts.c | 35 ++
>  include/os.h  | 17 +++
>  5 files changed, 105 insertions(+)

Reviewed-by: Simon Glass 

Do you think a command-line flag might be useful too/instead?


Re: [PATCH] common/board_r: make sure to call initr_dm() before initr_trace()

2020-11-16 Thread Simon Glass
Hi,

On Sun, 15 Nov 2020 at 05:16, Pragnesh Patel
 wrote:
>
> Hi Heinrich,
>
> >-Original Message-
> >From: Heinrich Schuchardt 
> >Sent: 12 November 2020 18:02
> >To: Pragnesh Patel 
> >Cc: U-Boot Mailing List ; Simon Glass
> >
> >Subject: Re: [PATCH] common/board_r: make sure to call initr_dm() before
> >initr_trace()
> >
> >[External Email] Do not click links or attachments unless you recognize the
> >sender and know the content is safe
> >
> >On 11/12/20 12:18 PM, Pragnesh Patel wrote:
> >> Tracing need timer ticks and initr_dm() will make gd->timer and
> >> gd->dm_root is equal to NULL, so make sure that initr_dm() to
> >> call before tracing got enabled.
> >>
> >> Signed-off-by: Pragnesh Patel 
> >> ---
> >>  common/board_r.c | 6 +++---
> >>  1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/common/board_r.c b/common/board_r.c index
> >> 29dd7d26d9..7140a39947 100644
> >> --- a/common/board_r.c
> >> +++ b/common/board_r.c
> >> @@ -693,6 +693,9 @@ static int run_main_loop(void)
> >>   * TODO: perhaps reset the watchdog in the initcall function after each 
> >> call?
> >>   */
> >>  static init_fnc_t init_sequence_r[] = {
> >> +#ifdef CONFIG_DM
> >> + initr_dm,
> >> +#endif
> >>   initr_trace,
> >>   initr_reloc,
> >>   /* TODO: could x86/PPC have this also perhaps? */ @@ -718,9
> >> +721,6 @@ static init_fnc_t init_sequence_r[] = {
> >>   initr_noncached,
> >>  #endif
> >>   initr_of_live,
> >> -#ifdef CONFIG_DM
> >> - initr_dm,
> >> -#endif
> >
> >You are moving initr_of_live before initr_of_live. I doubt this will work 
> >for boards
> >that have CONFIG_OF_LIVE=y.
>
> yes you are right. It will not work for CONFIG_OF_LIVE.
>
> >
> >Can't we move initr_trace down in the code to after both initr_of_live and
> >initr_dm?
> >
> >@Simon:
> >Please, advise.
>
> I am okay with this suggestion.

Actually can we use the early timer for this case?

DM init is a part of U-Boot and not being able to trace it would be unfortunate.

Regards,
Simon


Re: [PATCH] tools: image-host.c: use correct variable for strerrno

2020-11-16 Thread Simon Glass
Hi Philippe,

On Fri, 13 Nov 2020 at 07:15, Philippe Reynes
 wrote:
>
> In the function get_random_data, strerrno is called with
> the variable ret (which is the return of the function
> clock_gettime). It should be called with errnor. This
> commit fixes this mistake.
>
> Reported-by: Coverity (CID: 312956)
> Signed-off-by: Philippe Reynes 
> ---
>  tools/image-host.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [Patch] fdt: Use phandle to distinguish DT nodes with same name

2020-11-16 Thread Simon Glass
Hi Aswath,

On Wed, 11 Nov 2020 at 07:26, Aswath Govindraju  wrote:
>
> While assigning the sequence number to subsystem instances by reading the
> aliases property, only DT nodes names are compared and not the complete
> path. This causes a problem when there are two DT nodes with same name but
> have different paths.
>
> Fix it by comparing the phandles of DT nodes after the node names match.
>
> Signed-off-by: Aswath Govindraju 
> ---
>  lib/fdtdec.c | 5 +
>  1 file changed, 5 insertions(+)

fdt_path_offset() is slow. Could we just add this for the livetree
case perhaps, thus avoiding the speed penalty?

Can you also add a case where this causes a problem?

>
> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index 2015907dee7d..9e1bfe0b519e 100644
> --- a/lib/fdtdec.c
> +++ b/lib/fdtdec.c
> @@ -478,6 +478,11 @@ int fdtdec_get_alias_seq(const void *blob, const char 
> *base, int offset,
> slash = strrchr(prop, '/');
> if (strcmp(slash + 1, find_name))
> continue;
> +
> +   if (fdt_get_phandle(blob, offset) !=
> +   fdt_get_phandle(blob, fdt_path_offset(blob, prop)))
> +   continue;
> +
> val = trailing_strtol(name);
> if (val != -1) {
> *seqp = val;
> --
> 2.17.1
>

Regards,
Simon


Re: [PATCH] tools: image-host.c: use random instead of rand

2020-11-16 Thread Simon Glass
On Fri, 13 Nov 2020 at 08:38, Philippe Reynes
 wrote:
>
> According to the manpage of rand, it is recommended
> to use random instead of rand. This commit updates
> the function get_random_data to use random.
>
> Reported-by: Coverity (CID: 312953)
> Signed-off-by: Philippe Reynes 
> ---
>  tools/image-host.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v2 4/4] test: unit test for exception command

2020-11-16 Thread Simon Glass
On Wed, 11 Nov 2020 at 16:30, Heinrich Schuchardt  wrote:
>
> Test that an exception SIGILL is answered by a reset on the sandbox if
> CONFIG_SANDBOX_CRASH_RESET=y or by exiting to the OS otherwise.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
> v2:
> new patch
> ---
>  arch/Kconfig   |  1 +
>  test/py/tests/test_sandbox_exit.py | 24 
>  2 files changed, 25 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH 1/5] fdtdec: make fdtdec_get_config_string() return const char*

2020-11-16 Thread Simon Glass
On Tue, 10 Nov 2020 at 13:26, Rasmus Villemoes
 wrote:
>
> Nobody should modify the string returned by
> fdtdec_get_config_string(), so make it return a const pointer.
>
> Signed-off-by: Rasmus Villemoes 
> ---
>  arch/arm/mach-exynos/include/mach/mipi_dsim.h | 2 +-
>  arch/arm/mach-rockchip/rk3188/rk3188.c| 2 +-
>  board/dhelectronics/dh_stm32mp1/board.c   | 2 +-
>  board/firefly/firefly-rk3288/firefly-rk3288.c | 2 +-
>  board/st/stm32mp1/stm32mp1.c  | 2 +-
>  common/cli.c  | 2 +-
>  include/fdtdec.h  | 2 +-
>  lib/fdtdec.c  | 4 ++--
>  8 files changed, 9 insertions(+), 9 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 2/5] fdtdec: introduce fdtdec_get_config_property

2020-11-16 Thread Simon Glass
Hi Rasmus,

On Tue, 10 Nov 2020 at 13:26, Rasmus Villemoes
 wrote:
>
> Add a wrapper for retrieving a given property from the /config node as
> a (blob, length) pair. A later patch will need the length of the
> property and thus cannot just use fdtdec_get_config_string(). Rewrite
> that to use the new wrapper.
>
> Signed-off-by: Rasmus Villemoes 
> ---
>  include/fdtdec.h | 14 ++
>  lib/fdtdec.c | 27 +--
>  2 files changed, 27 insertions(+), 14 deletions(-)
>

Reviewed-by: Simon Glass 

But please adjust the fdtdec_get_config_bool() to use your new function too.

Also fdtdec_get_config_prop() is a better name IMO because it is shorter.

> diff --git a/include/fdtdec.h b/include/fdtdec.h
> index a037f6ed9c..ff1453a100 100644
> --- a/include/fdtdec.h
> +++ b/include/fdtdec.h
> @@ -747,6 +747,20 @@ int fdtdec_get_bool(const void *blob, int node, const 
> char *prop_name);
>   */
>  int fdtdec_get_child_count(const void *blob, int node);
>
> +/**
> + * Look in the FDT for a config item with the given name and a pointer
> + * to its value.
> + *
> + * @param blob  FDT blob
> + * @param prop_name property name to look up
> + * @param lenp  if non-NULL and the property is found, *lenp is
> + *  set to the length of the property value
> + *
> + * @returns property value, NULL on error.
> + */
> +const void *fdtdec_get_config_property(const void *blob, const char 
> *prop_name,
> +   int *lenp);
> +
>  /**
>   * Look in the FDT for a config item with the given name and return its value
>   * as a 32-bit integer. The property must have at least 4 bytes of data. The
> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index 25a71bc8f9..2442470af8 100644
> --- a/lib/fdtdec.c
> +++ b/lib/fdtdec.c
> @@ -853,6 +853,18 @@ const u8 *fdtdec_locate_byte_array(const void *blob, int 
> node,
> return cell;
>  }
>
> +const void *fdtdec_get_config_property(const void *blob, const char 
> *prop_name,
> +  int *len)
> +{
> +   int config_node;
> +
> +   debug("%s: %s\n", __func__, prop_name);
> +   config_node = fdt_path_offset(blob, "/config");
> +   if (config_node < 0)
> +   return NULL;
> +   return fdt_getprop(blob, config_node, prop_name, len);
> +}
> +
>  int fdtdec_get_config_int(const void *blob, const char *prop_name,
>   int default_val)
>  {
> @@ -881,20 +893,7 @@ int fdtdec_get_config_bool(const void *blob, const char 
> *prop_name)
>
>  const char *fdtdec_get_config_string(const void *blob, const char *prop_name)
>  {
> -   const char *nodep;
> -   int nodeoffset;
> -   int len;
> -
> -   debug("%s: %s\n", __func__, prop_name);
> -   nodeoffset = fdt_path_offset(blob, "/config");
> -   if (nodeoffset < 0)
> -   return NULL;
> -
> -   nodep = fdt_getprop(blob, nodeoffset, prop_name, &len);
> -   if (!nodep)
> -   return NULL;
> -
> -   return nodep;
> +   return fdtdec_get_config_property(blob, prop_name, NULL);
>  }
>
>  u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells)
> --
> 2.23.0
>

Regards,
Simon


Re: [PATCH v8 00/18] efi_loader: add capsule update support

2020-11-16 Thread AKASHI Takahiro
On Mon, Nov 16, 2020 at 11:10:12AM -0500, Tom Rini wrote:
> On Mon, Nov 16, 2020 at 09:37:23AM +0900, AKASHI Takahiro wrote:
> > Heinrich,
> > 
> > On Fri, Nov 13, 2020 at 08:18:58AM +0100, Heinrich Schuchardt wrote:
> > > On 11/13/20 5:14 AM, AKASHI Takahiro wrote:
> > > > Summary
> > > > ===
> > > > 'UpdateCapsule' is one of runtime services defined in UEFI specification
> > > > and its aim is to allow a caller (OS) to pass information to the 
> > > > firmware,
> > > > i.e. U-Boot. This is mostly used to update firmware binary on devices by
> > > > instructions from OS.
> > > >
> > > > While 'UpdateCapsule' is a runtime services function, it is, at least
> > > > initially, supported only before exiting boot services alike other 
> > > > runtime
> > > > functions, [Get/]SetVariable. This is because modifying storage which 
> > > > may
> > > > be shared with OS must be carefully designed and there is no general
> > > > assumption that we can do it.
> > > >
> > > > Therefore, we practically support only "capsule on disk"; any capsule 
> > > > can
> > > > be handed over to UEFI subsystem as a file on a specific file system.
> > > >
> > > > In this patch series, all the related definitions and structures are 
> > > > given
> > > > as UEFI specification describes, and basic framework for capsule support
> > > > is provided. Currently supported is
> > > >  * firmware update (Firmware Management Protocol or simply FMP)
> > > >
> > > > Most of functionality of firmware update is provided by FMP driver and
> > > > it can be, by nature, system/platform-specific. So you can and should
> > > > implement your own FMP driver(s) based on your system requirements.
> > > > Under the current implementation, we provide two basic but generic
> > > > drivers with two formats:
> > > >   * FIT image format (as used in TFTP update and dfu)
> > > >   * raw image format
> > > >
> > > > It's totally up to users which one, or both, should be used on users'
> > > > system depending on user requirements.
> > > >
> > > > Quick usage
> > > > ===
> > > > 1. You can create a capsule file with the following host command:
> > > >
> > > >   $ mkeficapsule [--fit  | --raw ] 
> > > >
> > > > 2. Put the file under:
> > > >
> > > >   /EFI/UpdateCapsule of UEFI system partition
> > > >
> > > > 3. Specify firmware storage to be updated in "dfu_alt_info" variable
> > > >(Please follow README.dfu for details.)
> > > >
> > > >   ==> env set dfu_alt_info '...'
> > > >
> > > > 4. After setting up UEFI's OsIndications variable, reboot U-Boot:
> > > >
> > > >   OsIndications <= EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED
> > > >
> > > > Patch structure
> > > > ===
> > > > Patch#1-#4,#12: preparatory patches
> > > > Patch#5-#11,#13: main part of implementation
> > > > Patch#14-#15: utilities
> > > > Patch#16-#17: pytests
> > > > Patch#18: for sandbox test
> > > >
> > > > [1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule
> > > >
> > > > Prerequisite patches
> > > > 
> > > > None
> > > >
> > > > Test
> > > > 
> > > > * passed all the pytests which are included in this patch series
> > > >   on sandbox build locally.
> > > > * skipped (or 'S', but it's not a failure, 'F') in Travis CI because
> > > >   "virt-make-fs" cannot be executed.
> > > 
> > > Dear Takahiro,
> > > 
> > > please, rebase your series on origin/master. A prior version of the
> > > first patches is already applied.
> > 
> > You can simply pick up and apply non-merged patches without problems
> > except a function prototype change of efi_create_indexed_name() you made,
> > which is not trivial to me.
> > 
> > But anyway, I will post a clean patch set soon.
> > 
> > > Testing on Gitlab CI, Travis CI, Amazon CI must be addressed for merging
> > > the remaining patches.
> > 
> > Where can we find the results?
> > I don't think there is no official information on those CI's.
> 
> If you submit a pull request against https://github.com/u-boot/u-boot
> Azure will run automatically and show the results.  We don't have

We can get a free account for Azure, but yet it requires us to give
our credit card information to Azure. I don't want to accept it.
So I believe requiring Azure test results is just inappropriate.

-Takahiro Akashi


> anything similar setup for GitLab, but since it uses the same Docker
> images as Azure, so long as the syntax is right (and there are linters
> if you're unsure of a change), it would be expected to work too.
> 
> -- 
> Tom




[PATCH] common: update: fix an "unused" warning against update_flash()

2020-11-16 Thread AKASHI Takahiro
Since update_flash() is used only in update_tftp(), it should be
guarded with appropriate config options.

Fixes: 3149e524fc1e ("common: update: add a generic interface for FIT
   image")
Signed-off-by: AKASHI Takahiro 
---
 common/update.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/update.c b/common/update.c
index 808be0880dfd..a5879cb52c41 100644
--- a/common/update.c
+++ b/common/update.c
@@ -29,7 +29,7 @@
 #include 
 #include 
 
-#ifdef CONFIG_DFU_TFTP
+#if defined(CONFIG_DFU_TFTP) || defined(CONFIG_UPDATE_TFTP)
 /* env variable holding the location of the update file */
 #define UPDATE_FILE_ENV"updatefile"
 
@@ -99,7 +99,6 @@ static int update_load(char *filename, ulong msec_max, int 
cnt_max, ulong addr)
 
return rv;
 }
-#endif /* CONFIG_DFU_TFTP */
 
 #ifdef CONFIG_MTD_NOR_FLASH
 static int update_flash_protect(int prot, ulong addr_first, ulong addr_last)
@@ -216,6 +215,7 @@ static int update_flash(ulong addr_source, ulong 
addr_first, ulong size)
 #endif
return 0;
 }
+#endif /* CONFIG_DFU_TFTP || CONFIG_UPDATE_TFTP */
 
 static int update_fit_getparams(const void *fit, int noffset, ulong *addr,
ulong *fladdr, ulong *size)
@@ -233,7 +233,7 @@ static int update_fit_getparams(const void *fit, int 
noffset, ulong *addr,
return 0;
 }
 
-#ifdef CONFIG_DFU_TFTP
+#if defined(CONFIG_DFU_TFTP) || defined(CONFIG_UPDATE_TFTP)
 int update_tftp(ulong addr, char *interface, char *devstring)
 {
char *filename, *env_addr, *fit_image_name;
@@ -340,7 +340,7 @@ next_node:
 
return ret;
 }
-#endif /* CONFIG_DFU_UPDATE */
+#endif /* CONFIG_DFU_UPDATE || CONFIG_UPDATE_TFTP */
 
 #ifdef CONFIG_UPDATE_FIT
 /**
-- 
2.28.0



[PATCH] dfu: simplify the dependencies of DFU_TFTP

2020-11-16 Thread AKASHI Takahiro
Since CONFIG_UPDATE_COMMON always selects CONFIG_DFU_WRITE_ALT, we can
drop the latter from dependencies of CONFIG_DFU_TFTP.

Fixes: 3149e524fc1e ("common: update: add a generic interface for FIT
   image")
Signed-off-by: AKASHI Takahiro 
---
 drivers/dfu/Kconfig | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig
index b7427fc4f0d6..121dc54f5463 100644
--- a/drivers/dfu/Kconfig
+++ b/drivers/dfu/Kconfig
@@ -20,9 +20,8 @@ config DFU_WRITE_ALT
 
 config DFU_TFTP
bool "DFU via TFTP"
-   select DFU_WRITE_ALT
-   select DFU_OVER_TFTP
select UPDATE_COMMON
+   select DFU_OVER_TFTP
help
  This option allows performing update of DFU-managed medium with data
  sent via TFTP boot.
-- 
2.28.0



[PATCH v9 00/11] efi_loader: add capsule update support

2020-11-16 Thread AKASHI Takahiro
Summary
===
'UpdateCapsule' is one of runtime services defined in UEFI specification
and its aim is to allow a caller (OS) to pass information to the firmware,
i.e. U-Boot. This is mostly used to update firmware binary on devices by
instructions from OS.

While 'UpdateCapsule' is a runtime services function, it is, at least
initially, supported only before exiting boot services alike other runtime
functions, [Get/]SetVariable. This is because modifying storage which may
be shared with OS must be carefully designed and there is no general
assumption that we can do it.

Therefore, we practically support only "capsule on disk"; any capsule can
be handed over to UEFI subsystem as a file on a specific file system.

In this patch series, all the related definitions and structures are given
as UEFI specification describes, and basic framework for capsule support
is provided. Currently supported is
 * firmware update (Firmware Management Protocol or simply FMP)

Most of functionality of firmware update is provided by FMP driver and
it can be, by nature, system/platform-specific. So you can and should
implement your own FMP driver(s) based on your system requirements.
Under the current implementation, we provide two basic but generic
drivers with two formats:
  * FIT image format (as used in TFTP update and dfu)
  * raw image format

It's totally up to users which one, or both, should be used on users'
system depending on user requirements.

Quick usage
===
1. You can create a capsule file with the following host command:

  $ mkeficapsule [--fit  | --raw ] 

2. Put the file under:

  /EFI/UpdateCapsule of UEFI system partition

3. Specify firmware storage to be updated in "dfu_alt_info" variable
   (Please follow README.dfu for details.)

  ==> env set dfu_alt_info '...'

4. After setting up UEFI's OsIndications variable, reboot U-Boot:

  OsIndications <= EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED

Patch structure
===
Patch#1-#6: main part of implementation
Patch#7-#8: utilities
Patch#9-#10: pytests
Patch#11: for sandbox test

[1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule

Prerequisite patches

None

Test

* passed all the pytests which are included in this patch series
  on sandbox build locally.
* In Travis CI, all tests skipped (or 'S', but it's not a failure, 'F')
  because "virt-make-fs" cannot be executed.

Issues
==
* Timing of executing capsules-on-disk
  Currently, processing a capsule is triggered only as part of
  UEFI subsystem initialization. This means that, for example,
  firmware update, may not take place at system booting time and
  will potentially be delayed until a first call of any UEFI functions.
=> See patch#5 for my proposal
* A bunch of warnings like
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef'
where possible
  I don't think that fixing those improves anything.
* Add a document in uefi.rst

TODO's
==
(Won't be addressed in this series.)
* capsule authentication
* capsule dependency (dependency expression instruction set, or depex)
* loading drivers in a capsule
* handling RESET flag in a capsule and QeuryCapsuleCaps
* full semantics of ESRT (EFI System Resource Table)
* enabling capsule API at runtime
* json capsule
* recovery from update failure

Changes
===
v9 (November 17, 2020)
* rebased on v2021.01-rc2
* removed already-merged patches
* aligned with a function prototype change of efi_create_indexed_name()
  (Patch#1-2)
# See Travis CI status in v8 below

v8 (November 13, 2020)
* fix a "not used" warning against update_load() in some configuration
  (Patch#3)
* fix failures (marked as 'F') in *secure boot* test in Travis CI by
  making "EFI_CAPSULE_ON_DISK_EARLY" 'default n' (Patch#8)
* fix failures (marked as 'E') at pytest setup in Travis CI by changing
  a python file's name along with removing unused definitions (Patch#16)
* add Patch#18 to enable tests to be run with default sandbox config
  (Patch#18)

v7 (October 29, 2020)
* rename CONFIG_DFU_ALT to CONFIG_DFU_WRITE_ALT (Patch#1,#3,#13)

v6 RESEND (October 29, 2020)
* rebased on v2021.01-rc1

v6 (September 7, 2020)
* temporarily drop the prerequisite patch[2]
* add a missing field (dependencies) in efi_api.h (but never used) (Patch#10)
* add a missing field (image_capsule_support) and related definitions
  in efi_api.h (Patch#10, #15)
* cosmetic changes on constant definitions in efi_api.h (Patch#10)
* strict check for INVALID_PARAMETER at GET_IMAGE_INFO api (Patch#11,#13)
* fix warnings in pytest (Patch#16,#17)

v5 (August 3, 2020)
* removed superfluous type conversion at dfu_write_from_mem_addr()
  (Patch#2)
* introduced a common helper function, efi_create_indexed_name()
  (Patch#6,#7,#8)
* use efi_[get|set]_variable_int(), if necessary, with READ_ONLY
  (Patch#7,#8)
* return EFI_UNSUPPORTED at Patch#7
* changed the word, number, to 'index' (Patch#7,#8)
* removed 'ifdef CONFIG_EFI_CAPSULE_ON_DIS

[PATCH v9 01/11] efi_loader: define UpdateCapsule api

2020-11-16 Thread AKASHI Takahiro
In this commit, skeleton functions for capsule-related API's are
added under CONFIG_EFI_UPDATE_CAPSULE configuration.
Detailed implementation for a specific capsule type will be added
in the succeeding patches.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_api.h|  12 +++
 include/efi_loader.h |  13 +++
 lib/efi_loader/Kconfig   |  11 +++
 lib/efi_loader/Makefile  |   1 +
 lib/efi_loader/efi_capsule.c | 165 +++
 lib/efi_loader/efi_runtime.c | 104 --
 lib/efi_loader/efi_setup.c   |  64 +++---
 7 files changed, 316 insertions(+), 54 deletions(-)
 create mode 100644 lib/efi_loader/efi_capsule.c

diff --git a/include/efi_api.h b/include/efi_api.h
index 5744f6aed86d..c128a0a66ce8 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -217,6 +217,10 @@ enum efi_reset_type {
 #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE0x0002
 #define CAPSULE_FLAGS_INITIATE_RESET   0x0004
 
+#define EFI_CAPSULE_REPORT_GUID \
+   EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \
+0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)
+
 struct efi_capsule_header {
efi_guid_t capsule_guid;
u32 header_size;
@@ -224,6 +228,14 @@ struct efi_capsule_header {
u32 capsule_image_size;
 } __packed;
 
+struct efi_capsule_result_variable_header {
+   u32 variable_total_size;
+   u32 reserved;
+   efi_guid_t capsule_guid;
+   struct efi_time capsule_processed;
+   efi_status_t capsule_status;
+} __packed;
+
 #define EFI_RT_SUPPORTED_GET_TIME  0x0001
 #define EFI_RT_SUPPORTED_SET_TIME  0x0002
 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME   0x0004
diff --git a/include/efi_loader.h b/include/efi_loader.h
index f550ced56876..d22f7a43ad09 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -207,6 +207,8 @@ extern const efi_guid_t efi_guid_cert_type_pkcs7;
 
 /* GUID of RNG protocol */
 extern const efi_guid_t efi_guid_rng_protocol;
+/* GUID of capsule update result */
+extern const efi_guid_t efi_guid_capsule_report;
 
 extern unsigned int __efi_runtime_start, __efi_runtime_stop;
 extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
@@ -807,6 +809,17 @@ void efi_memcpy_runtime(void *dest, const void *src, 
size_t n);
 /* commonly used helper function */
 u16 *efi_create_indexed_name(u16 *buffer, const char *name, unsigned int 
index);
 
+/* Capsule update */
+efi_status_t EFIAPI efi_update_capsule(
+   struct efi_capsule_header **capsule_header_array,
+   efi_uintn_t capsule_count,
+   u64 scatter_gather_list);
+efi_status_t EFIAPI efi_query_capsule_caps(
+   struct efi_capsule_header **capsule_header_array,
+   efi_uintn_t capsule_count,
+   u64 *maximum_capsule_size,
+   u32 *reset_type);
+
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
 
 /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 075481428cdf..3ca396df3646 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -93,6 +93,17 @@ config EFI_SET_TIME
  Provide the SetTime() runtime service at boottime. This service
  can be used by an EFI application to adjust the real time clock.
 
+config EFI_HAVE_CAPSULE_SUPPORT
+   bool
+
+config EFI_RUNTIME_UPDATE_CAPSULE
+   bool "UpdateCapsule() runtime service"
+   default n
+   select EFI_HAVE_CAPSULE_SUPPORT
+   help
+ Select this option if you want to use UpdateCapsule and
+ QueryCapsuleCapabilities API's.
+
 config EFI_DEVICE_PATH_TO_TEXT
bool "Device path to text protocol"
default y
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 8892fb01e125..8d729abdfa78 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -23,6 +23,7 @@ endif
 obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
 obj-y += efi_bootmgr.o
 obj-y += efi_boottime.o
+obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o
 obj-y += efi_console.o
 obj-y += efi_device_path.o
 obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o
diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
new file mode 100644
index ..575fa75b0a2f
--- /dev/null
+++ b/lib/efi_loader/efi_capsule.c
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  EFI Capsule
+ *
+ *  Copyright (c) 2018 Linaro Limited
+ * Author: AKASHI Takahiro
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
+
+/**
+ * get_last_capsule - get the last capsule index
+ *
+ * Retrieve the index of the capsule invoked last time from "CapsuleLast"
+ * variable.
+ *
+ * Return:
+ * * > 0   - the last capsule index invoked
+ * * 0x- on error, or no ca

[PATCH v9 02/11] efi_loader: capsule: add capsule_on_disk support

2020-11-16 Thread AKASHI Takahiro
Capsule data can be loaded into the system either via UpdateCapsule
runtime service or files on a file system (of boot device).
The latter case is called "capsules on disk", and actual updates will
take place at the next boot time.

In this commit, we will support capsule on disk mechanism.

Please note that U-Boot itself has no notion of "boot device" and
all the capsule files to be executed will be detected only if they
are located in a specific directory, \EFI\UpdateCapsule, on a device
that is identified as a boot device by "Boot" variables.

Signed-off-by: AKASHI Takahiro 
---
 common/main.c|   4 +
 include/efi_loader.h |   9 +
 lib/efi_loader/Kconfig   |  22 ++
 lib/efi_loader/efi_capsule.c | 498 +++
 lib/efi_loader/efi_setup.c   |   8 +
 5 files changed, 541 insertions(+)

diff --git a/common/main.c b/common/main.c
index 4b3cd302c3e2..ae5bcdb32f8b 100644
--- a/common/main.c
+++ b/common/main.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static void run_preboot_environment_command(void)
 {
@@ -53,6 +54,9 @@ void main_loop(void)
if (IS_ENABLED(CONFIG_UPDATE_TFTP))
update_tftp(0UL, NULL, NULL);
 
+   if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY))
+   efi_launch_capsules();
+
s = bootdelay_process();
if (cli_process_fdt(&s))
cli_secure_boot_cmd(s);
diff --git a/include/efi_loader.h b/include/efi_loader.h
index d22f7a43ad09..eb57e7455eb1 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -820,6 +820,11 @@ efi_status_t EFIAPI efi_query_capsule_caps(
u64 *maximum_capsule_size,
u32 *reset_type);
 
+#define EFI_CAPSULE_DIR L"\\EFI\\UpdateCapsule\\"
+
+/* Hook at initialization */
+efi_status_t efi_launch_capsules(void);
+
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
 
 /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
@@ -836,6 +841,10 @@ static inline void efi_set_bootdev(const char *dev, const 
char *devnr,
   const char *path) { }
 static inline void efi_net_set_dhcp_ack(void *pkt, int len) { }
 static inline void efi_print_image_infos(void *pc) { }
+static inline efi_status_t efi_launch_capsules(void)
+{
+   return EFI_SUCCESS;
+}
 
 #endif /* CONFIG_IS_ENABLED(EFI_LOADER) */
 
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 3ca396df3646..e1ac5ac055de 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -104,6 +104,28 @@ config EFI_RUNTIME_UPDATE_CAPSULE
  Select this option if you want to use UpdateCapsule and
  QueryCapsuleCapabilities API's.
 
+config EFI_CAPSULE_ON_DISK
+   bool "Enable capsule-on-disk support"
+   select EFI_HAVE_CAPSULE_SUPPORT
+   default n
+   help
+ Select this option if you want to use capsule-on-disk feature,
+ that is, capsules can be fetched and executed from files
+ under a specific directory on UEFI system partition instead of
+ via UpdateCapsule API.
+
+config EFI_CAPSULE_ON_DISK_EARLY
+   bool "Initiate capsule-on-disk at U-Boot boottime"
+   depends on EFI_CAPSULE_ON_DISK
+   default n
+   select EFI_SETUP_EARLY
+   help
+ Normally, without this option enabled, capsules will be
+ executed only at the first time of invoking one of efi command.
+ If this option is enabled, capsules will be enforced to be
+ executed as part of U-Boot initialisation so that they will
+ surely take place whatever is set to distro_bootcmd.
+
 config EFI_DEVICE_PATH_TO_TEXT
bool "Device path to text protocol"
default y
diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index 575fa75b0a2f..b3c7d1b735b6 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -11,10 +11,16 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
 
+#ifdef CONFIG_EFI_CAPSULE_ON_DISK
+/* for file system access */
+static struct efi_file_handle *bootdev_root;
+#endif
+
 /**
  * get_last_capsule - get the last capsule index
  *
@@ -163,3 +169,495 @@ efi_status_t EFIAPI efi_query_capsule_caps(
 out:
return EFI_EXIT(ret);
 }
+
+#ifdef CONFIG_EFI_CAPSULE_ON_DISK
+/**
+ * get_dp_device - retrieve a device  path from boot variable
+ * @boot_var:  Boot variable name
+ * @device_dp  Device path
+ *
+ * Retrieve a device patch from boot variable, @boot_var.
+ *
+ * Return: status code
+ */
+static efi_status_t get_dp_device(u16 *boot_var,
+ struct efi_device_path **device_dp)
+{
+   void *buf = NULL;
+   efi_uintn_t size;
+   struct efi_load_option lo;
+   struct efi_device_path *file_dp;
+   efi_status_t ret;
+
+   size = 0;
+   ret = efi_get_variable_int(boot_var, &efi_global_variable_guid,
+ 

[PATCH v9 06/11] efi_loader: add firmware management protocol for raw image

2020-11-16 Thread AKASHI Takahiro
In this commit, a very simple firmware management protocol driver
is implemented. It will take a binary image in a capsule file and
apply the data using dfu backend storage drivers via dfu_write_by_alt()
interface.

So "dfu_alt_info" variable should be properly set to specify a device
and location to be updated. Please read README.dfu.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_api.h |   4 +
 include/efi_loader.h  |   1 +
 lib/efi_loader/Kconfig|  16 +++
 lib/efi_loader/Makefile   |   2 +-
 lib/efi_loader/efi_capsule.c  |   8 ++
 lib/efi_loader/efi_firmware.c | 226 +-
 6 files changed, 199 insertions(+), 58 deletions(-)

diff --git a/include/efi_api.h b/include/efi_api.h
index 071d0ba866c7..c7038f863ab2 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -1853,6 +1853,10 @@ struct efi_signature_list {
EFI_GUID(0xae13ff2d, 0x9ad4, 0x4e25, 0x9a, 0xc8, \
 0x6d, 0x80, 0xb3, 0xb2, 0x21, 0x47)
 
+#define EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID \
+   EFI_GUID(0xe2bb9c06, 0x70e9, 0x4b14, 0x97, 0xa3, \
+0x5a, 0x79, 0x13, 0x17, 0x6e, 0x3f)
+
 #define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE0x0001
 #define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0002
 #define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED0x0004
diff --git a/include/efi_loader.h b/include/efi_loader.h
index d24d0ff0e78a..1b19faf76941 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -812,6 +812,7 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t 
n);
 u16 *efi_create_indexed_name(u16 *buffer, const char *name, unsigned int 
index);
 
 extern const struct efi_firmware_management_protocol efi_fmp_fit;
+extern const struct efi_firmware_management_protocol efi_fmp_raw;
 
 /* Capsule update */
 efi_status_t EFIAPI efi_update_capsule(
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 159400fec39e..8332a5072d42 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -126,6 +126,10 @@ config EFI_CAPSULE_ON_DISK_EARLY
  executed as part of U-Boot initialisation so that they will
  surely take place whatever is set to distro_bootcmd.
 
+config EFI_CAPSULE_FIRMWARE
+   bool
+   default n
+
 config EFI_CAPSULE_FIRMWARE_MANAGEMENT
bool "Capsule: Firmware Management Protocol"
depends on EFI_HAVE_CAPSULE_SUPPORT
@@ -140,11 +144,23 @@ config EFI_CAPSULE_FIRMWARE_FIT
depends on FIT
select UPDATE_FIT
select DFU
+   select EFI_CAPSULE_FIRMWARE
default n
help
  Select this option if you want to enable firmware management protocol
  driver for FIT image
 
+config EFI_CAPSULE_FIRMWARE_RAW
+   bool "FMP driver for raw image"
+   depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
+   select DFU
+   select DFU_WRITE_ALT
+   select EFI_CAPSULE_FIRMWARE
+   default n
+   help
+ Select this option if you want to enable firmware management protocol
+ driver for raw image
+
 config EFI_DEVICE_PATH_TO_TEXT
bool "Device path to text protocol"
default y
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index dedb702c5d43..9a3496350ea4 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -24,7 +24,7 @@ obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
 obj-y += efi_bootmgr.o
 obj-y += efi_boottime.o
 obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o
-obj-$(CONFIG_EFI_CAPSULE_FIRMWARE_FIT) += efi_firmware.o
+obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_firmware.o
 obj-y += efi_console.o
 obj-y += efi_device_path.o
 obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o
diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index 8265aac226f2..f385e5837805 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -814,6 +814,14 @@ efi_status_t __weak arch_efi_load_capsule_drivers(void)
&efi_fmp_fit, NULL));
}
 
+   if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)) {
+   handle = NULL;
+   ret = EFI_CALL(efi_install_multiple_protocol_interfaces(
+   &efi_root,
+   &efi_guid_firmware_management_protocol,
+   &efi_fmp_raw, NULL));
+   }
+
return ret;
 }
 
diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index 4c395f4eb5d9..7e5607738319 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -13,16 +13,66 @@
 #include 
 #include 
 
-/*
- * This FIRMWARE_MANAGEMENT_PROTOCOL driver provides a firmware update
- * method with existing FIT image format, and handles
- *   - multiple regions of firmware via DFU
- * but doesn't support
- *   - versioning of firmware image
- *   - package information
- */
-const efi_guid_t efi_firmware_i

[PATCH v9 04/11] efi_loader: capsule: support firmware update

2020-11-16 Thread AKASHI Takahiro
A capsule tagged with the guid, EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID,
is handled as a firmware update object.
What efi_update_capsule() basically does is to load any firmware management
protocol (or fmp) drivers contained in a capsule, find out an appropriate
fmp driver and then invoke its set_image() interface against each binary
in a capsule.
In this commit, however, loading drivers is not supported.

The result of applying a capsule is set to be stored in "Capsule"
variable, but its implementation is deferred to a fmp driver.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_api.h| 129 +++
 include/efi_loader.h |   2 +
 lib/efi_loader/Kconfig   |   8 ++
 lib/efi_loader/efi_capsule.c | 238 ++-
 lib/efi_loader/efi_setup.c   |   4 +
 5 files changed, 380 insertions(+), 1 deletion(-)

diff --git a/include/efi_api.h b/include/efi_api.h
index 7a2a087c60ed..966bc6e590bf 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -217,6 +217,9 @@ enum efi_reset_type {
 #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE0x0002
 #define CAPSULE_FLAGS_INITIATE_RESET   0x0004
 
+#define CAPSULE_SUPPORT_AUTHENTICATION 0x0001
+#define CAPSULE_SUPPORT_DEPENDENCY 0x0002
+
 #define EFI_CAPSULE_REPORT_GUID \
EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \
 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)
@@ -225,6 +228,10 @@ enum efi_reset_type {
EFI_GUID(0xde9f0ec, 0x88b6, 0x428f, 0x97, 0x7a, \
 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72)
 
+#define EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID \
+   EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \
+0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a)
+
 struct efi_capsule_header {
efi_guid_t capsule_guid;
u32 header_size;
@@ -253,6 +260,33 @@ struct efi_memory_range_capsule {
struct efi_memory_range memory_ranges[];
 } __packed;
 
+struct efi_firmware_management_capsule_header {
+   u32 version;
+   u16 embedded_driver_count;
+   u16 payload_item_count;
+   u64 item_offset_list[];
+} __packed;
+
+struct efi_firmware_management_capsule_image_header {
+   u32 version;
+   efi_guid_t update_image_type_id;
+   u8 update_image_index;
+   u8 reserved[3];
+   u32 update_image_size;
+   u32 update_vendor_code_size;
+   u64 update_hardware_instance;
+   u64 image_capsule_support;
+} __packed;
+
+struct efi_capsule_result_variable_fmp {
+   u16 version;
+   u8 payload_index;
+   u8 update_image_index;
+   efi_guid_t update_image_type_id;
+   // u16 capsule_file_name[];
+   // u16 capsule_target[];
+} __packed;
+
 #define EFI_RT_SUPPORTED_GET_TIME  0x0001
 #define EFI_RT_SUPPORTED_SET_TIME  0x0002
 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME   0x0004
@@ -1808,4 +1842,99 @@ struct efi_signature_list {
 /* struct efi_signature_data signatures[...][signature_size]; */
 } __attribute__((__packed__));
 
+/*
+ * Firmware management protocol
+ */
+#define EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID \
+   EFI_GUID(0x86c77a67, 0x0b97, 0x4633, 0xa1, 0x87, \
+0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7)
+
+#define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE0x0001
+#define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0002
+#define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED0x0004
+#define IMAGE_ATTRIBUTE_IN_USE 0x0008
+#define IMAGE_ATTRIBUTE_UEFI_IMAGE 0x0010
+#define IMAGE_ATTRIBUTE_DEPENDENCY 0x0020
+
+#define IMAGE_COMPATIBILITY_CHECK_SUPPORTED0x0001
+
+#define IMAGE_UPDATABLE_VALID  0x0001
+#define IMAGE_UPDATABLE_INVALID0x0002
+#define IMAGE_UPDATABLE_INVALID_TYPE   0x0004
+#define IMAGE_UPDATABLE_INVALID_OLLD   0x0008
+#define IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE 0x0010
+
+#define PACKAGE_ATTRIBUTE_VERSION_UPDATABLE0x0001
+#define PACKAGE_ATTRIBUTE_RESET_REQUIRED   0x0002
+#define PACKAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED  0x0004
+
+#define EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION  4
+
+typedef struct efi_firmware_image_dependencies {
+   u8 dependencies[0];
+} efi_firmware_image_dep_t;
+
+struct efi_firmware_image_descriptor {
+   u8 image_index;
+   efi_guid_t image_type_id;
+   u64 image_id;
+   u16 *image_id_name;
+   u32 version;
+   u16 *version_name;
+   efi_uintn_t size;
+   u64 attributes_supported;
+   u64 attributes_setting;
+   u64 compatibilities;
+   u32 lowest_supported_image_version;
+   u32 last_attempt_version;
+   u32 last_attempt_status;
+   u64 hardware_instance;
+   efi_firmware_image_d

[PATCH v9 07/11] cmd: add "efidebug capsule" command

2020-11-16 Thread AKASHI Takahiro
"efidebug capsule" is more or less a debugging utility.
  efidebug capsule update: invoke UpdateCapsule against data on memory
  efidebug capsule show: show a capsule header
  efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro 
---
 cmd/efidebug.c | 235 +
 1 file changed, 235 insertions(+)

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 5288b9920b4d..7d327c82681f 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -19,6 +19,228 @@
 #include 
 
 #define BS systab.boottime
+#define RT systab.runtime
+
+#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
+/**
+ * do_efi_capsule_update() - process a capsule update
+ *
+ * @cmdtp: Command table
+ * @flag:  Command flag
+ * @argc:  Number of arguments
+ * @argv:  Argument array
+ * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
+ *
+ * Implement efidebug "capsule update" sub-command.
+ * process a capsule update.
+ *
+ * efidebug capsule update [-v] 
+ */
+static int do_efi_capsule_update(struct cmd_tbl *cmdtp, int flag,
+int argc, char * const argv[])
+{
+   struct efi_capsule_header *capsule;
+   int verbose = 0;
+   char *endp;
+   efi_status_t ret;
+
+   if (argc != 2 && argc != 3)
+   return CMD_RET_USAGE;
+
+   if (argc == 3) {
+   if (strcmp(argv[1], "-v"))
+   return CMD_RET_USAGE;
+
+   verbose = 1;
+   argc--;
+   argv++;
+   }
+
+   capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16);
+   if (endp == argv[1]) {
+   printf("Invalid address: %s", argv[1]);
+   return CMD_RET_FAILURE;
+   }
+
+   if (verbose) {
+   printf("Capsule guid: %pUl\n", &capsule->capsule_guid);
+   printf("Capsule flags: 0x%x\n", capsule->flags);
+   printf("Capsule header size: 0x%x\n", capsule->header_size);
+   printf("Capsule image size: 0x%x\n",
+  capsule->capsule_image_size);
+   }
+
+   ret = EFI_CALL(RT->update_capsule(&capsule, 1, (u64)NULL));
+   if (ret) {
+   printf("Cannot handle a capsule at %p", capsule);
+   return CMD_RET_FAILURE;
+   }
+
+   return CMD_RET_SUCCESS;
+}
+
+/**
+ * do_efi_capsule_show() - show capsule information
+ *
+ * @cmdtp: Command table
+ * @flag:  Command flag
+ * @argc:  Number of arguments
+ * @argv:  Argument array
+ * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
+ *
+ * Implement efidebug "capsule show" sub-command.
+ * show capsule information.
+ *
+ * efidebug capsule show 
+ */
+static int do_efi_capsule_show(struct cmd_tbl *cmdtp, int flag,
+  int argc, char * const argv[])
+{
+   struct efi_capsule_header *capsule;
+   char *endp;
+
+   if (argc != 2)
+   return CMD_RET_USAGE;
+
+   capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16);
+   if (endp == argv[1]) {
+   printf("Invalid address: %s", argv[1]);
+   return CMD_RET_FAILURE;
+   }
+
+   printf("Capsule guid: %pUl\n", &capsule->capsule_guid);
+   printf("Capsule flags: 0x%x\n", capsule->flags);
+   printf("Capsule header size: 0x%x\n", capsule->header_size);
+   printf("Capsule image size: 0x%x\n",
+  capsule->capsule_image_size);
+
+   return CMD_RET_SUCCESS;
+}
+
+/**
+ * do_efi_capsule_res() - show a capsule update result
+ *
+ * @cmdtp: Command table
+ * @flag:  Command flag
+ * @argc:  Number of arguments
+ * @argv:  Argument array
+ * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
+ *
+ * Implement efidebug "capsule result" sub-command.
+ * show a capsule update result.
+ * If result number is not specified, CapsuleLast will be shown.
+ *
+ * efidebug capsule result []
+ */
+static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
+ int argc, char * const argv[])
+{
+   int capsule_id;
+   char *endp;
+   char var_name[12];
+   u16 var_name16[12], *p;
+   efi_guid_t guid;
+   struct efi_capsule_result_variable_header *result = NULL;
+   efi_uintn_t size;
+   efi_status_t ret;
+
+   if (argc != 1 && argc != 2)
+   return CMD_RET_USAGE;
+
+   guid = efi_guid_capsule_report;
+   if (argc == 1) {
+   size = sizeof(var_name16);
+   ret = EFI_CALL(RT->get_variable(L"CapsuleLast", &guid, NULL,
+   &size, var_name16));
+   if (ret != EFI_SUCCESS) {
+   if (ret == EFI_NOT_FOUND)
+   printf("CapsuleLast doesn't exist\n");
+   else
+   printf("Failed to get CapsuleLast\n");
+
+

[PATCH v9 03/11] efi_loader: capsule: add memory range capsule definitions

2020-11-16 Thread AKASHI Takahiro
Memory range capsule gives us a way to notify that some memory regions
should be left untouched across the next reset.
See UEFI specification, section 8.5.3.

Since how we should handle this kind of capsule is totally up to
the system, no implementation will be added in this commit.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_api.h | 17 +
 1 file changed, 17 insertions(+)

diff --git a/include/efi_api.h b/include/efi_api.h
index c128a0a66ce8..7a2a087c60ed 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -221,6 +221,10 @@ enum efi_reset_type {
EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \
 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)
 
+#define EFI_MEMORY_RANGE_CAPSULE_GUID \
+   EFI_GUID(0xde9f0ec, 0x88b6, 0x428f, 0x97, 0x7a, \
+0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72)
+
 struct efi_capsule_header {
efi_guid_t capsule_guid;
u32 header_size;
@@ -236,6 +240,19 @@ struct efi_capsule_result_variable_header {
efi_status_t capsule_status;
 } __packed;
 
+struct efi_memory_range {
+   efi_physical_addr_t address;
+   u64 length;
+};
+
+struct efi_memory_range_capsule {
+   struct efi_capsule_header *header;
+   /* EFI_MEMORY_TYPE: 0x8000-0x */
+   enum efi_mem_type os_requested_memory_type;
+   u64 number_of_memory_ranges;
+   struct efi_memory_range memory_ranges[];
+} __packed;
+
 #define EFI_RT_SUPPORTED_GET_TIME  0x0001
 #define EFI_RT_SUPPORTED_SET_TIME  0x0002
 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME   0x0004
-- 
2.28.0



[PATCH v9 05/11] efi_loader: add firmware management protocol for FIT image

2020-11-16 Thread AKASHI Takahiro
In this commit, a very simple firmware management protocol driver
is implemented. It will take a common FIT image firmware in a capsule
file and apply the data using dfu backend storage drivers via
update_fit() interface.

So "dfu_alt_info" variable should be properly set to specify a device
and location to be updated. Please read README.dfu.

Fit image is a common file format for firmware update on U-Boot, and
this protocol works neatly just as a wrapper for one.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_api.h |   4 +
 include/efi_loader.h  |   2 +
 lib/efi_loader/Kconfig|  11 ++
 lib/efi_loader/Makefile   |   1 +
 lib/efi_loader/efi_capsule.c  |  12 +-
 lib/efi_loader/efi_firmware.c | 291 ++
 6 files changed, 320 insertions(+), 1 deletion(-)
 create mode 100644 lib/efi_loader/efi_firmware.c

diff --git a/include/efi_api.h b/include/efi_api.h
index 966bc6e590bf..071d0ba866c7 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -1849,6 +1849,10 @@ struct efi_signature_list {
EFI_GUID(0x86c77a67, 0x0b97, 0x4633, 0xa1, 0x87, \
 0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7)
 
+#define EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID \
+   EFI_GUID(0xae13ff2d, 0x9ad4, 0x4e25, 0x9a, 0xc8, \
+0x6d, 0x80, 0xb3, 0xb2, 0x21, 0x47)
+
 #define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE0x0001
 #define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0002
 #define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED0x0004
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 1a728bf9702d..d24d0ff0e78a 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -811,6 +811,8 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t 
n);
 /* commonly used helper function */
 u16 *efi_create_indexed_name(u16 *buffer, const char *name, unsigned int 
index);
 
+extern const struct efi_firmware_management_protocol efi_fmp_fit;
+
 /* Capsule update */
 efi_status_t EFIAPI efi_update_capsule(
struct efi_capsule_header **capsule_header_array,
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 5cb34687c26a..159400fec39e 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -134,6 +134,17 @@ config EFI_CAPSULE_FIRMWARE_MANAGEMENT
  Select this option if you want to enable capsule-based
  firmware update using Firmware Management Protocol.
 
+config EFI_CAPSULE_FIRMWARE_FIT
+   bool "FMP driver for FIT image"
+   depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
+   depends on FIT
+   select UPDATE_FIT
+   select DFU
+   default n
+   help
+ Select this option if you want to enable firmware management protocol
+ driver for FIT image
+
 config EFI_DEVICE_PATH_TO_TEXT
bool "Device path to text protocol"
default y
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 8d729abdfa78..dedb702c5d43 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
 obj-y += efi_bootmgr.o
 obj-y += efi_boottime.o
 obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o
+obj-$(CONFIG_EFI_CAPSULE_FIRMWARE_FIT) += efi_firmware.o
 obj-y += efi_console.o
 obj-y += efi_device_path.o
 obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o
diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index 2f41c17f5057..8265aac226f2 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -804,7 +804,17 @@ static void efi_capsule_scan_done(void)
  */
 efi_status_t __weak arch_efi_load_capsule_drivers(void)
 {
-   return EFI_SUCCESS;
+   __maybe_unused efi_handle_t handle;
+   efi_status_t ret = EFI_SUCCESS;
+
+   if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)) {
+   handle = NULL;
+   ret = EFI_CALL(efi_install_multiple_protocol_interfaces(
+   &handle, &efi_guid_firmware_management_protocol,
+   &efi_fmp_fit, NULL));
+   }
+
+   return ret;
 }
 
 /**
diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
new file mode 100644
index ..4c395f4eb5d9
--- /dev/null
+++ b/lib/efi_loader/efi_firmware.c
@@ -0,0 +1,291 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * EFI Firmware management protocol
+ *
+ *  Copyright (c) 2020 Linaro Limited
+ * Author: AKASHI Takahiro
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * This FIRMWARE_MANAGEMENT_PROTOCOL driver provides a firmware update
+ * method with existing FIT image format, and handles
+ *   - multiple regions of firmware via DFU
+ * but doesn't support
+ *   - versioning of firmware image
+ *   - package information
+ */
+const efi_guid_t efi_firmware_image_type_uboot_fit =
+   EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID;
+
+/**
+ 

[PATCH v9 10/11] test/py: efi_capsule: test for raw image capsule

2020-11-16 Thread AKASHI Takahiro
The test can run on sandbox build and it attempts to execute a firmware
update via a capsule-on-disk, using a raw image capsule,
CONFIG_EFI_CAPSULE_RAW.

To run this test successfully, you need configure U-Boot specifically;
See test_capsule_firmware.py for requirements, and hence it won't run
on Travis CI, at least, for now.

Signed-off-by: AKASHI Takahiro 
---
 test/py/tests/test_efi_capsule/conftest.py|  3 +
 .../test_efi_capsule/test_capsule_firmware.py | 63 +++
 2 files changed, 66 insertions(+)

diff --git a/test/py/tests/test_efi_capsule/conftest.py 
b/test/py/tests/test_efi_capsule/conftest.py
index 147266189912..e037bd20560d 100644
--- a/test/py/tests/test_efi_capsule/conftest.py
+++ b/test/py/tests/test_efi_capsule/conftest.py
@@ -53,6 +53,9 @@ def efi_capsule_data(request, u_boot_config):
 check_call('cd %s; %s/tools/mkeficapsule --fit uboot_bin_env.itb 
--version 1 --index 1 Test01' %
(data_dir, u_boot_config.build_dir),
shell=True)
+check_call('cd %s; %s/tools/mkeficapsule --raw u-boot.bin.new 
--version 1 --index 1 Test02' %
+   (data_dir, u_boot_config.build_dir),
+   shell=True)
 
 # Create a disk image with EFI system partition
 check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' 
%
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware.py 
b/test/py/tests/test_efi_capsule/test_capsule_firmware.py
index d8e27707fd79..f006fa95d650 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware.py
@@ -15,6 +15,7 @@ from capsule_defs import *
 
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.buildconfigspec('efi_capsule_firmware_fit')
+@pytest.mark.buildconfigspec('efi_capsule_firmware_raw')
 @pytest.mark.buildconfigspec('efi_capsule_on_disk')
 @pytest.mark.buildconfigspec('dfu')
 @pytest.mark.buildconfigspec('dfu_sf')
@@ -176,3 +177,65 @@ class TestEfiCapsuleFirmwareFit(object):
 'sf read 400 15 10',
 'md.b 400 10'])
 assert 'u-boot-env:New' in ''.join(output)
+
+def test_efi_capsule_fw3(
+self, u_boot_config, u_boot_console, efi_capsule_data):
+"""
+Test Case 3 - Update U-Boot on SPI Flash, raw image format
+  0x10-0x15: U-Boot binary (but dummy)
+"""
+disk_img = efi_capsule_data
+with u_boot_console.log.section('Test Case 3-a, before reboot'):
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'efidebug boot add 1 TEST host 0:1 /helloworld.efi ""',
+'efidebug boot order 1',
+'env set -e -nv -bs -rt OsIndications =0x0004',
+'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x10 
0x5;u-boot-env raw 0x15 0x20"',
+'env save'])
+
+# initialize content
+output = u_boot_console.run_command_list([
+'sf probe 0:0',
+'fatload host 0:1 400 %s/u-boot.bin.old' % 
CAPSULE_DATA_DIR,
+'sf write 400 10 10',
+'sf read 500 10 10',
+'md.b 500 10'])
+assert 'Old' in ''.join(output)
+
+# place a capsule file
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 %s/Test02' % CAPSULE_DATA_DIR,
+'fatwrite host 0:1 400 %s/Test02 $filesize' % 
CAPSULE_INSTALL_DIR,
+'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+assert 'Test02' in ''.join(output)
+
+# reboot
+u_boot_console.restart_uboot()
+
+capsule_early = u_boot_config.buildconfig.get(
+'config_efi_capsule_on_disk_early')
+with u_boot_console.log.section('Test Case 3-b, after reboot'):
+if not capsule_early:
+# make sure that dfu_alt_info exists even persistent variables
+# are not available.
+output = u_boot_console.run_command_list([
+'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x10 
0x5;u-boot-env raw 0x15 0x20"',
+'host bind 0 %s' % disk_img,
+'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+assert 'Test02' in ''.join(output)
+
+# need to run uefi command to initiate capsule handling
+output = u_boot_console.run_command(
+'env print -e -all Capsule')
+
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+assert 'Test02' not in ''.join(output)
+
+output = u_boot_console.run_command_list([
+'sf probe 0:0',
+'sf 

[PATCH v9 08/11] tools: add mkeficapsule command for UEFI capsule update

2020-11-16 Thread AKASHI Takahiro
This is a utility mainly for test purpose.
  mkeficapsule -f: create a test capsule file for FIT image firmware

Having said that, you will be able to customize the code to fit
your specific requirements for your platform.

Signed-off-by: AKASHI Takahiro 
---
 tools/Makefile   |   2 +
 tools/mkeficapsule.c | 238 +++
 2 files changed, 240 insertions(+)
 create mode 100644 tools/mkeficapsule.c

diff --git a/tools/Makefile b/tools/Makefile
index 51123fd92983..66d9376803e3 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs
 hostprogs-$(CONFIG_ASN1_COMPILER)  += asn1_compiler
 HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include
 
+hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule
+
 # We build some files with extra pedantic flags to try to minimize things
 # that won't build on some weird host compiler -- though there are lots of
 # exceptions for files that aren't complaint.
diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
new file mode 100644
index ..db95426457cc
--- /dev/null
+++ b/tools/mkeficapsule.c
@@ -0,0 +1,238 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2018 Linaro Limited
+ * Author: AKASHI Takahiro
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+typedef __u8 u8;
+typedef __u16 u16;
+typedef __u32 u32;
+typedef __u64 u64;
+typedef __s16 s16;
+typedef __s32 s32;
+
+#define aligned_u64 __aligned_u64
+
+#ifndef __packed
+#define __packed __attribute__((packed))
+#endif
+
+#include 
+#include 
+
+static const char *tool_name = "mkeficapsule";
+
+efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
+efi_guid_t efi_guid_image_type_uboot_fit =
+   EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID;
+efi_guid_t efi_guid_image_type_uboot_raw =
+   EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID;
+
+static struct option options[] = {
+   {"fit", required_argument, NULL, 'f'},
+   {"raw", required_argument, NULL, 'r'},
+   {"index", required_argument, NULL, 'i'},
+   {"instance", required_argument, NULL, 'I'},
+   {"version", required_argument, NULL, 'v'},
+   {"help", no_argument, NULL, 'h'},
+   {NULL, 0, NULL, 0},
+};
+
+static void print_usage(void)
+{
+   printf("Usage: %s [options] \n"
+  "Options:\n"
+  "\t--fit   new FIT image file\n"
+  "\t--raw   new raw image file\n"
+  "\t--index update image index\n"
+  "\t--instance   update hardware instance\n"
+  "\t--version firmware version\n"
+  "\t--help print a help message\n",
+  tool_name);
+}
+
+static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
+   unsigned long version, unsigned long index,
+   unsigned long instance)
+{
+   struct efi_capsule_header header;
+   struct efi_firmware_management_capsule_header capsule;
+   struct efi_firmware_management_capsule_image_header image;
+   FILE *f, *g;
+   struct stat bin_stat;
+   u8 *data;
+   size_t size;
+
+#ifdef DEBUG
+   printf("For output: %s\n", path);
+   printf("\tbin: %s\n\ttype: %pUl\n" bin, guid);
+   printf("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n",
+  version, index, instance);
+#endif
+
+   g = fopen(bin, "r");
+   if (!g) {
+   printf("cannot open %s\n", bin);
+   return -1;
+   }
+   if (stat(bin, &bin_stat) < 0) {
+   printf("cannot determine the size of %s\n", bin);
+   goto err_1;
+   }
+   data = malloc(bin_stat.st_size);
+   if (!data) {
+   printf("cannot allocate memory: %lx\n", bin_stat.st_size);
+   goto err_1;
+   }
+   f = fopen(path, "w");
+   if (!f) {
+   printf("cannot open %s\n", path);
+   goto err_2;
+   }
+   header.capsule_guid = efi_guid_fm_capsule;
+   header.header_size = sizeof(header);
+   header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET; /* TODO */
+   header.capsule_image_size = sizeof(header)
+   + sizeof(capsule) + sizeof(u64)
+   + sizeof(image)
+   + bin_stat.st_size;
+
+   size = fwrite(&header, 1, sizeof(header), f);
+   if (size < sizeof(header)) {
+   printf("write failed (%lx)\n", size);
+   goto err_3;
+   }
+
+   capsule.version = 0x0001;
+   capsule.embedded_driver_count = 0;
+   capsule.payload_item_count = 1;
+   capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64);
+   size = fwrite(&capsule, 1, sizeof(capsule) + sizeof(u64), f);
+   if (size < (sizeof(capsule) + sizeof(u64))) {
+   pri

[PATCH v9 09/11] test/py: efi_capsule: test for FIT image capsule

2020-11-16 Thread AKASHI Takahiro
The test can run on sandbox build and it attempts to execute a firmware
update via a capsule-on-disk, using a FIT image capsule,
CONFIG_EFI_CAPSULE_FIT.

To run this test successfully, you need configure U-Boot specifically;
See test_capsule_firmware.py for requirements, and hence it won't run
on Travis CI, at least, for now.

Signed-off-by: AKASHI Takahiro 
---
 .../py/tests/test_efi_capsule/capsule_defs.py |   5 +
 test/py/tests/test_efi_capsule/conftest.py|  71 +++
 .../test_efi_capsule/test_capsule_firmware.py | 178 ++
 .../tests/test_efi_capsule/uboot_bin_env.its  |  36 
 tools/mkeficapsule.c  |   3 +-
 5 files changed, 292 insertions(+), 1 deletion(-)
 create mode 100644 test/py/tests/test_efi_capsule/capsule_defs.py
 create mode 100644 test/py/tests/test_efi_capsule/conftest.py
 create mode 100644 test/py/tests/test_efi_capsule/test_capsule_firmware.py
 create mode 100644 test/py/tests/test_efi_capsule/uboot_bin_env.its

diff --git a/test/py/tests/test_efi_capsule/capsule_defs.py 
b/test/py/tests/test_efi_capsule/capsule_defs.py
new file mode 100644
index ..4fd6353c2040
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/capsule_defs.py
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier:  GPL-2.0+
+
+# Directories
+CAPSULE_DATA_DIR = '/EFI/CapsuleTestData'
+CAPSULE_INSTALL_DIR = '/EFI/UpdateCapsule'
diff --git a/test/py/tests/test_efi_capsule/conftest.py 
b/test/py/tests/test_efi_capsule/conftest.py
new file mode 100644
index ..147266189912
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/conftest.py
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2020, Linaro Limited
+# Author: AKASHI Takahiro 
+
+import os
+import os.path
+import re
+from subprocess import call, check_call, check_output, CalledProcessError
+import pytest
+from capsule_defs import *
+
+#
+# Fixture for UEFI secure boot test
+#
+
+
+@pytest.fixture(scope='session')
+def efi_capsule_data(request, u_boot_config):
+"""Set up a file system to be used in UEFI capsule test.
+
+Args:
+request: Pytest request object.
+u_boot_config: U-boot configuration.
+
+Return:
+A path to disk image to be used for testing
+"""
+global CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
+
+mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
+data_dir = mnt_point + CAPSULE_DATA_DIR
+install_dir = mnt_point + CAPSULE_INSTALL_DIR
+image_path = u_boot_config.persistent_data_dir + '/test_efi_capsule.img'
+
+try:
+# Create a target device
+check_call('dd if=/dev/zero of=./spi.bin bs=1MiB count=16', shell=True)
+
+check_call('rm -rf %s' % mnt_point, shell=True)
+check_call('mkdir -p %s' % data_dir, shell=True)
+check_call('mkdir -p %s' % install_dir, shell=True)
+
+# Create capsule files
+# two regions: one for u-boot.bin and the other for u-boot.env
+check_call('cd %s; echo -n u-boot:Old > u-boot.bin.old; echo -n 
u-boot:New > u-boot.bin.new; echo -n u-boot-env:Old -> u-boot.env.old; echo -n 
u-boot-env:New > u-boot.env.new' % data_dir,
+   shell=True)
+check_call('sed -e \"s?BINFILE1?u-boot.bin.new?\" -e 
\"s?BINFILE2?u-boot.env.new?\" 
%s/test/py/tests/test_efi_capsule/uboot_bin_env.its > %s/uboot_bin_env.its' %
+   (u_boot_config.source_dir, data_dir),
+   shell=True)
+check_call('cd %s; %s/tools/mkimage -f uboot_bin_env.its 
uboot_bin_env.itb' %
+   (data_dir, u_boot_config.build_dir),
+   shell=True)
+check_call('cd %s; %s/tools/mkeficapsule --fit uboot_bin_env.itb 
--version 1 --index 1 Test01' %
+   (data_dir, u_boot_config.build_dir),
+   shell=True)
+
+# Create a disk image with EFI system partition
+check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' 
%
+   (mnt_point, image_path), shell=True)
+check_call('sgdisk %s -A 1:set:0 -t 
1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B' %
+   image_path, shell=True)
+
+except CalledProcessError as exception:
+pytest.skip('Setup failed: %s' % exception.cmd)
+return
+else:
+yield image_path
+finally:
+call('rm -rf %s' % mnt_point, shell=True)
+call('rm -f %s' % image_path, shell=True)
+call('rm -f ./spi.bin', shell=True)
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware.py 
b/test/py/tests/test_efi_capsule/test_capsule_firmware.py
new file mode 100644
index ..d8e27707fd79
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware.py
@@ -0,0 +1,178 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2020, Linaro Limited
+# Author: AKASHI Takahiro 
+#
+# U-Boot UEFI: Firmware Update Test
+
+"""
+This test verifies capsule-on-disk firmware update
+"""
+
+from subprocess import c

[PATCH v9 11/11] sandbox: enable capsule update for testing

2020-11-16 Thread AKASHI Takahiro
Add more configuration options to allow for efi capsule update
on sandbox.

Signed-off-by: AKASHI Takahiro 
---
 configs/sandbox64_defconfig | 6 ++
 configs/sandbox_defconfig   | 6 ++
 2 files changed, 12 insertions(+)

diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index dc993cd13aaa..661830763feb 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -231,3 +231,9 @@ CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
+#
+CONFIG_DFU_SF=y
+CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y
+CONFIG_EFI_CAPSULE_ON_DISK=y
+CONFIG_EFI_CAPSULE_FIRMWARE_FIT=y
+CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index f2a767a4cdea..e385425b7d91 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -274,3 +274,9 @@ CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
+#
+CONFIG_DFU_SF=y
+CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y
+CONFIG_EFI_CAPSULE_ON_DISK=y
+CONFIG_EFI_CAPSULE_FIRMWARE_FIT=y
+CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
-- 
2.28.0



Re: [PATCH v8 00/18] efi_loader: add capsule update support

2020-11-16 Thread Tom Rini
On Tue, Nov 17, 2020 at 09:16:26AM +0900, AKASHI Takahiro wrote:
> On Mon, Nov 16, 2020 at 11:10:12AM -0500, Tom Rini wrote:
> > On Mon, Nov 16, 2020 at 09:37:23AM +0900, AKASHI Takahiro wrote:
> > > Heinrich,
> > > 
> > > On Fri, Nov 13, 2020 at 08:18:58AM +0100, Heinrich Schuchardt wrote:
> > > > On 11/13/20 5:14 AM, AKASHI Takahiro wrote:
> > > > > Summary
> > > > > ===
> > > > > 'UpdateCapsule' is one of runtime services defined in UEFI 
> > > > > specification
> > > > > and its aim is to allow a caller (OS) to pass information to the 
> > > > > firmware,
> > > > > i.e. U-Boot. This is mostly used to update firmware binary on devices 
> > > > > by
> > > > > instructions from OS.
> > > > >
> > > > > While 'UpdateCapsule' is a runtime services function, it is, at least
> > > > > initially, supported only before exiting boot services alike other 
> > > > > runtime
> > > > > functions, [Get/]SetVariable. This is because modifying storage which 
> > > > > may
> > > > > be shared with OS must be carefully designed and there is no general
> > > > > assumption that we can do it.
> > > > >
> > > > > Therefore, we practically support only "capsule on disk"; any capsule 
> > > > > can
> > > > > be handed over to UEFI subsystem as a file on a specific file system.
> > > > >
> > > > > In this patch series, all the related definitions and structures are 
> > > > > given
> > > > > as UEFI specification describes, and basic framework for capsule 
> > > > > support
> > > > > is provided. Currently supported is
> > > > >  * firmware update (Firmware Management Protocol or simply FMP)
> > > > >
> > > > > Most of functionality of firmware update is provided by FMP driver and
> > > > > it can be, by nature, system/platform-specific. So you can and should
> > > > > implement your own FMP driver(s) based on your system requirements.
> > > > > Under the current implementation, we provide two basic but generic
> > > > > drivers with two formats:
> > > > >   * FIT image format (as used in TFTP update and dfu)
> > > > >   * raw image format
> > > > >
> > > > > It's totally up to users which one, or both, should be used on users'
> > > > > system depending on user requirements.
> > > > >
> > > > > Quick usage
> > > > > ===
> > > > > 1. You can create a capsule file with the following host command:
> > > > >
> > > > >   $ mkeficapsule [--fit  | --raw ] 
> > > > >
> > > > > 2. Put the file under:
> > > > >
> > > > >   /EFI/UpdateCapsule of UEFI system partition
> > > > >
> > > > > 3. Specify firmware storage to be updated in "dfu_alt_info" variable
> > > > >(Please follow README.dfu for details.)
> > > > >
> > > > >   ==> env set dfu_alt_info '...'
> > > > >
> > > > > 4. After setting up UEFI's OsIndications variable, reboot U-Boot:
> > > > >
> > > > >   OsIndications <= EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED
> > > > >
> > > > > Patch structure
> > > > > ===
> > > > > Patch#1-#4,#12: preparatory patches
> > > > > Patch#5-#11,#13: main part of implementation
> > > > > Patch#14-#15: utilities
> > > > > Patch#16-#17: pytests
> > > > > Patch#18: for sandbox test
> > > > >
> > > > > [1] https://git.linaro.org/people/takahiro.akashi/u-boot.git 
> > > > > efi/capsule
> > > > >
> > > > > Prerequisite patches
> > > > > 
> > > > > None
> > > > >
> > > > > Test
> > > > > 
> > > > > * passed all the pytests which are included in this patch series
> > > > >   on sandbox build locally.
> > > > > * skipped (or 'S', but it's not a failure, 'F') in Travis CI because
> > > > >   "virt-make-fs" cannot be executed.
> > > > 
> > > > Dear Takahiro,
> > > > 
> > > > please, rebase your series on origin/master. A prior version of the
> > > > first patches is already applied.
> > > 
> > > You can simply pick up and apply non-merged patches without problems
> > > except a function prototype change of efi_create_indexed_name() you made,
> > > which is not trivial to me.
> > > 
> > > But anyway, I will post a clean patch set soon.
> > > 
> > > > Testing on Gitlab CI, Travis CI, Amazon CI must be addressed for merging
> > > > the remaining patches.
> > > 
> > > Where can we find the results?
> > > I don't think there is no official information on those CI's.
> > 
> > If you submit a pull request against https://github.com/u-boot/u-boot
> > Azure will run automatically and show the results.  We don't have
> 
> We can get a free account for Azure, but yet it requires us to give
> our credit card information to Azure. I don't want to accept it.
> So I believe requiring Azure test results is just inappropriate.

That's not correct, as far as I can tell.  You just need to submit a
pull request against the repository I mentioned above and that triggers
one.  For example: https://github.com/u-boot/u-boot/pull/35/checks is
the result of one such PR.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v8 00/18] efi_loader: add capsule update support

2020-11-16 Thread AKASHI Takahiro
Hi Tom,

On Mon, Nov 16, 2020 at 07:36:26PM -0500, Tom Rini wrote:
> On Tue, Nov 17, 2020 at 09:16:26AM +0900, AKASHI Takahiro wrote:
> > On Mon, Nov 16, 2020 at 11:10:12AM -0500, Tom Rini wrote:
> > > On Mon, Nov 16, 2020 at 09:37:23AM +0900, AKASHI Takahiro wrote:
> > > > Heinrich,
> > > > 
> > > > On Fri, Nov 13, 2020 at 08:18:58AM +0100, Heinrich Schuchardt wrote:
> > > > > On 11/13/20 5:14 AM, AKASHI Takahiro wrote:
> > > > > > Summary
> > > > > > ===
> > > > > > 'UpdateCapsule' is one of runtime services defined in UEFI 
> > > > > > specification
> > > > > > and its aim is to allow a caller (OS) to pass information to the 
> > > > > > firmware,
> > > > > > i.e. U-Boot. This is mostly used to update firmware binary on 
> > > > > > devices by
> > > > > > instructions from OS.
> > > > > >
> > > > > > While 'UpdateCapsule' is a runtime services function, it is, at 
> > > > > > least
> > > > > > initially, supported only before exiting boot services alike other 
> > > > > > runtime
> > > > > > functions, [Get/]SetVariable. This is because modifying storage 
> > > > > > which may
> > > > > > be shared with OS must be carefully designed and there is no general
> > > > > > assumption that we can do it.
> > > > > >
> > > > > > Therefore, we practically support only "capsule on disk"; any 
> > > > > > capsule can
> > > > > > be handed over to UEFI subsystem as a file on a specific file 
> > > > > > system.
> > > > > >
> > > > > > In this patch series, all the related definitions and structures 
> > > > > > are given
> > > > > > as UEFI specification describes, and basic framework for capsule 
> > > > > > support
> > > > > > is provided. Currently supported is
> > > > > >  * firmware update (Firmware Management Protocol or simply FMP)
> > > > > >
> > > > > > Most of functionality of firmware update is provided by FMP driver 
> > > > > > and
> > > > > > it can be, by nature, system/platform-specific. So you can and 
> > > > > > should
> > > > > > implement your own FMP driver(s) based on your system requirements.
> > > > > > Under the current implementation, we provide two basic but generic
> > > > > > drivers with two formats:
> > > > > >   * FIT image format (as used in TFTP update and dfu)
> > > > > >   * raw image format
> > > > > >
> > > > > > It's totally up to users which one, or both, should be used on 
> > > > > > users'
> > > > > > system depending on user requirements.
> > > > > >
> > > > > > Quick usage
> > > > > > ===
> > > > > > 1. You can create a capsule file with the following host command:
> > > > > >
> > > > > >   $ mkeficapsule [--fit  | --raw ]  > > > > > file>
> > > > > >
> > > > > > 2. Put the file under:
> > > > > >
> > > > > >   /EFI/UpdateCapsule of UEFI system partition
> > > > > >
> > > > > > 3. Specify firmware storage to be updated in "dfu_alt_info" variable
> > > > > >(Please follow README.dfu for details.)
> > > > > >
> > > > > >   ==> env set dfu_alt_info '...'
> > > > > >
> > > > > > 4. After setting up UEFI's OsIndications variable, reboot U-Boot:
> > > > > >
> > > > > >   OsIndications <= 
> > > > > > EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED
> > > > > >
> > > > > > Patch structure
> > > > > > ===
> > > > > > Patch#1-#4,#12: preparatory patches
> > > > > > Patch#5-#11,#13: main part of implementation
> > > > > > Patch#14-#15: utilities
> > > > > > Patch#16-#17: pytests
> > > > > > Patch#18: for sandbox test
> > > > > >
> > > > > > [1] https://git.linaro.org/people/takahiro.akashi/u-boot.git 
> > > > > > efi/capsule
> > > > > >
> > > > > > Prerequisite patches
> > > > > > 
> > > > > > None
> > > > > >
> > > > > > Test
> > > > > > 
> > > > > > * passed all the pytests which are included in this patch series
> > > > > >   on sandbox build locally.
> > > > > > * skipped (or 'S', but it's not a failure, 'F') in Travis CI because
> > > > > >   "virt-make-fs" cannot be executed.
> > > > > 
> > > > > Dear Takahiro,
> > > > > 
> > > > > please, rebase your series on origin/master. A prior version of the
> > > > > first patches is already applied.
> > > > 
> > > > You can simply pick up and apply non-merged patches without problems
> > > > except a function prototype change of efi_create_indexed_name() you 
> > > > made,
> > > > which is not trivial to me.
> > > > 
> > > > But anyway, I will post a clean patch set soon.
> > > > 
> > > > > Testing on Gitlab CI, Travis CI, Amazon CI must be addressed for 
> > > > > merging
> > > > > the remaining patches.
> > > > 
> > > > Where can we find the results?
> > > > I don't think there is no official information on those CI's.
> > > 
> > > If you submit a pull request against https://github.com/u-boot/u-boot
> > > Azure will run automatically and show the results.  We don't have
> > 
> > We can get a free account for Azure, but yet it requires us to give
> > our credit card information to Azure. I don't want to accept it.
> > So I believe requiring Azure test results is just inappropr

Pull request: u-boot-sunxi/pr-2020-11-17

2020-11-16 Thread Andre Przywara
Hi Tom,

please pull this branch, containing the fixed version of yesterday's PR.
Beside the one issue you found there was an intermediate issue (a few
commits in-between failing to compile), which I fixed as well.
I also added the missing commit to actually introduce the
pinephone_defconfig, without which most of the other commits are
somewhat useless.
Compile-tested HEAD for all 152 sunxi boards, compile-tested all commits
for Pine64 and OrangePi Zero, boot-tested on Pine64-LTS and OrangePi Zero.

Summary:
- PinePhone support (Samuel)
- V3/S3 support (Icenowy)

Thanks,
Andre

==

The following changes since commit 9324c9a823ed91d901fb56954f438f9854b19bb5:

  Merge tag 'ti-v2021.01-rc3' of 
https://gitlab.denx.de/u-boot/custodians/u-boot-ti (2020-11-16 13:42:29 -0500)

are available in the Git repository at:

  https://gitlab.denx.de/u-boot/custodians/u-boot-sunxi.git pr-2020-11-17

for you to fetch changes up to 6d5d6bb50d2930319fd6421554b98e17ebdb5fb6:

  sunxi: dts: sync Allwinner V3s-related DTs from Linux 5.10-rc1 (2020-11-17 
00:42:21 +)


Icenowy Zheng (5):
  sunxi: add V3/S3 support
  sunxi: gpio: introduce compatible string for V3 GPIO
  clk: sunxi: add compatible string for V3
  sunxi: allow to use AXP20[39] attached to I2C0 on V3 series
  sunxi: dts: sync Allwinner V3s-related DTs from Linux 5.10-rc1

Samuel Holland (8):
  sunxi: board: Use a more descriptive variable name
  sunxi: board: Add a helper to get the SPL DT name
  sunxi: board: Simplify Pine A64 DT selection logic
  sunxi: board: Add PinePhone DT selection logic
  sunxi: board: Save the chosen DT name in the SPL header
  sunxi: board: Set fdtfile to match the DT chosen by SPL
  sunxi: DT: A64: update device tree files
  sunxi: a64: Add a defconfig for the PinePhone

 arch/arm/dts/Makefile   |   4 +
 arch/arm/dts/axp803.dtsi|  82 ++--
 arch/arm/dts/sun50i-a64-amarula-relic.dts   | 109 -
 arch/arm/dts/sun50i-a64-bananapi-m64.dts| 118 --
 arch/arm/dts/sun50i-a64-cpu-opp.dtsi|  75 
 arch/arm/dts/sun50i-a64-nanopi-a64.dts  |  70 +---
 arch/arm/dts/sun50i-a64-oceanic-5205-5inmfd.dts |  31 +-
 arch/arm/dts/sun50i-a64-olinuxino-emmc.dts  |  12 +-
 arch/arm/dts/sun50i-a64-olinuxino.dts   | 113 +++--
 arch/arm/dts/sun50i-a64-orangepi-win.dts| 127 --
 arch/arm/dts/sun50i-a64-pine64-lts.dts  |   7 +-
 arch/arm/dts/sun50i-a64-pine64-plus.dts |  52 +--
 arch/arm/dts/sun50i-a64-pine64.dts  |  97 +++--
 arch/arm/dts/sun50i-a64-pinebook-u-boot.dtsi|  17 -
 arch/arm/dts/sun50i-a64-pinebook.dts| 237 ---
 arch/arm/dts/sun50i-a64-pinephone-1.0.dts   |  11 +
 arch/arm/dts/sun50i-a64-pinephone-1.1.dts   |  30 ++
 arch/arm/dts/sun50i-a64-pinephone-1.2.dts   |  40 ++
 arch/arm/dts/sun50i-a64-pinephone.dtsi  | 429 +++
 arch/arm/dts/sun50i-a64-pinetab.dts | 460 
 arch/arm/dts/sun50i-a64-sopine-baseboard.dts| 113 +++--
 arch/arm/dts/sun50i-a64-sopine.dtsi |  69 ++-
 arch/arm/dts/sun50i-a64-teres-i-u-boot.dtsi |  41 --
 arch/arm/dts/sun50i-a64-teres-i.dts | 138 +-
 arch/arm/dts/sun50i-a64.dtsi| 532 +++-
 arch/arm/dts/sun8i-s3-lichee-zero-plus.dts  |  53 +++
 arch/arm/dts/sun8i-s3-pinecube.dts  | 235 +++
 arch/arm/dts/sun8i-v3.dtsi  |  27 ++
 arch/arm/dts/sun8i-v3s-licheepi-zero-dock.dts   |  96 +
 arch/arm/dts/sun8i-v3s-licheepi-zero.dts|  26 +-
 arch/arm/dts/sun8i-v3s.dtsi | 318 --
 arch/arm/include/asm/arch-sunxi/gpio.h  |   1 +
 arch/arm/mach-sunxi/Kconfig |  10 +-
 board/sunxi/MAINTAINERS |   5 +
 board/sunxi/board.c | 102 -
 configs/pinephone_defconfig |  12 +
 drivers/clk/sunxi/clk_v3s.c |   2 +
 drivers/gpio/sunxi_gpio.c   |   1 +
 drivers/power/Kconfig   |   4 +-
 include/dt-bindings/clock/sun50i-a64-ccu.h  |   4 +-
 include/dt-bindings/clock/sun8i-de2.h   |   3 +
 include/dt-bindings/reset/sun8i-de2.h   |   1 +
 42 files changed, 3230 insertions(+), 684 deletions(-)
 create mode 100644 arch/arm/dts/sun50i-a64-cpu-opp.dtsi
 delete mode 100644 arch/arm/dts/sun50i-a64-pinebook-u-boot.dtsi
 create mode 100644 arch/arm/dts/sun50i-a64-pinephone-1.0.dts
 create mode 100644 arch/arm/dts/sun50i-a64-pinephone-1.1.dts
 create mode 100644 arch/arm/dts/sun50i-a64-pinephone-1.2.dts
 create mode 100644 arch/arm/dts/sun50i-a64-pinephone.dtsi
 create mode 100644 arch/arm/dts/sun50i-a64-pinetab.dts
 delete mode 100644 arch/arm/dts/sun50i-a64-teres-i-u-boot.dtsi
 c

Re: [PATCH v3] env: mmc: Correct partition comparison in mmc_offset_try_partition

2020-11-16 Thread Hoyeonjiki Kim
Dear Wolfgang Denk,

On Tue, Nov 17, 2020 at 4:17 AM Wolfgang Denk  wrote:
>
> Dear Hoyeonjiki Kim,
>
> In message <20201115172544.548-1-jigi@gmail.com> you wrote:
> > The function mmc_offset_try_partition searches the MMC partition for
> > locating environment data, by comparing the partition names with config
> > "u-boot,mmc-env-parition". However, it only compares the first word-size
> > bytes (size of 'const char *'), which may make the function to find
> > unintended partition.
> >
> > Correct the function not to partially compare the partition name with
> > config "u-boot,mmc-env-partition".
> >
> > Fixes: c9e87ba66540 ("env: Save environment at the end of an MMC partition")
> > Signed-off-by: Hoyeonjiki Kim 
> > Reviewed-by: Jaehoon Chung 
> > Reviewed-by: Jorge Ramire-Ortiz 
> > Reviewed-by: Wolfgang Denk 
> > ---
>
> Reviewed-by: Wolfgang Denk 
>
>
> Best regards,
>
> Wolfgang Denk
>
> --
> DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
> God made the integers; all else is the work of Man.   - Kronecker

Thanks for all the reviews for this patch.
I'll bring the patch with it.

Best Regards,
Hoyeonjiki Kim


Re: Pull request: u-boot-sunxi/master

2020-11-16 Thread Samuel Holland
On 11/16/20 10:58 AM, Tom Rini wrote:
> On Mon, Nov 16, 2020 at 04:51:32PM +, André Przywara wrote:
>> On 16/11/2020 16:13, Tom Rini wrote:
>>> On Mon, Nov 16, 2020 at 04:09:42PM +, André Przywara wrote:
 On 16/11/2020 15:50, Tom Rini wrote:

 Hi Tom,

> On Mon, Nov 16, 2020 at 12:42:53PM +0530, Jagan Teki wrote:
>
>> Hi Tom, 
>>
>> Please pull this PR.
>>
>> Summary:
>> - PinePhone support (Samuel)
>> - V3/S3 support (Icenowy)
>>
>> thanks,
>> Jagan.
>>
>> The following changes since commit 
>> de865f7ee1d9b6dff6e265dee44509c8274ea606:
>>
>>   Merge tag 'efi-2021-01-rc3' of 
>> https://gitlab.denx.de/u-boot/custodians/u-boot-efi (2020-11-14 09:47:33 
>> -0500)
>>
>> are available in the Git repository at:
>>
>>   https://gitlab.denx.de/u-boot/custodians/u-boot-sunxi master
>>
>> for you to fetch changes up to 27007e5d4a6c4ac1bbd1bc81fb4c19bc45191f35:
>>
>>   sunxi: dts: sync Allwinner V3s-related DTs from Linux 5.10-rc1 
>> (2020-11-16 12:34:09 +0530)
>>
>
> NAK.  A large number of sunxi boards fail to build with:
> +board/sunxi/board.c:338:13: error: 'set_spl_dt_name' defined but not 
> used [-Werror=unused-function]
> +  338 | static void set_spl_dt_name(const char *name)
> +  | ^~~
> +cc1: all warnings being treated as errors
> +make[2]: *** [board/sunxi/board.o] Error 1
> +make[1]: *** [board/sunxi] Error 2
> +make: *** [sub-make] Error 2

 Ouch, thanks for that heads up!
 But this only happens after this very patch, and is fixed by a later
 patch, right? ("sunxi: board: Set fdtfile to match the DT chosen by SPL"
 introduces another user of set_spl_dt_name(), outside of any #ifdef's).
>>>
>>> No, that's from the PR itself.
>>
>> Right, sorry, looked at the wrong function.
>> I found the culprit and have a fix, but I will run some actual tests on
>> my boards tonight to make sure it really works.
>> Jagan or me will send a new PR later then.
> 
> OK, thanks for the quick follow-up!

Thank you, Andre, and sorry for the breakage. For what it's worth,
I am happy with the fixups you made.

Samuel


Re: [PATCH v3 5/7] riscv: dts: Add device tree for Microchip Icicle Kit

2020-11-16 Thread Bin Meng
On Tue, Nov 10, 2020 at 6:46 PM Padmarao Begari
 wrote:
>
> Add device tree for Microchip PolarFire SoC Icicle Kit.
>
> Signed-off-by: Padmarao Begari 
> Reviewed-by: Anup Patel 
> ---
>  arch/riscv/dts/Makefile   |   1 +
>  .../dts/microchip-mpfs-icicle-kit-u-boot.dtsi |  15 +
>  arch/riscv/dts/microchip-mpfs-icicle-kit.dts  | 421 ++
>  3 files changed, 437 insertions(+)
>  create mode 100644 arch/riscv/dts/microchip-mpfs-icicle-kit-u-boot.dtsi
>  create mode 100644 arch/riscv/dts/microchip-mpfs-icicle-kit.dts
>
> diff --git a/arch/riscv/dts/Makefile b/arch/riscv/dts/Makefile
> index 3a6f96c67d..01331b0aa1 100644
> --- a/arch/riscv/dts/Makefile
> +++ b/arch/riscv/dts/Makefile
> @@ -3,6 +3,7 @@
>  dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb
>  dtb-$(CONFIG_TARGET_SIFIVE_FU540) += hifive-unleashed-a00.dtb
>  dtb-$(CONFIG_TARGET_SIPEED_MAIX) += k210-maix-bit.dtb
> +dtb-$(CONFIG_TARGET_MICROCHIP_ICICLE) += microchip-mpfs-icicle-kit.dtb
>
>  targets += $(dtb-y)
>
> diff --git a/arch/riscv/dts/microchip-mpfs-icicle-kit-u-boot.dtsi 
> b/arch/riscv/dts/microchip-mpfs-icicle-kit-u-boot.dtsi
> new file mode 100644
> index 00..f1738c8a24
> --- /dev/null
> +++ b/arch/riscv/dts/microchip-mpfs-icicle-kit-u-boot.dtsi
> @@ -0,0 +1,15 @@
> +// SPDX-License-Identifier: (GPL-2.0 OR MIT)
> +/*
> + * Copyright (C) 2020 Microchip Technology Inc.
> + * Padmarao Begari 
> + */
> +
> +/ {
> +   aliases {
> +   cpu1 = &cpu1;
> +   cpu2 = &cpu2;
> +   cpu3 = &cpu3;
> +   cpu4 = &cpu4;
> +   };
> +};
> +
> diff --git a/arch/riscv/dts/microchip-mpfs-icicle-kit.dts 
> b/arch/riscv/dts/microchip-mpfs-icicle-kit.dts
> new file mode 100644
> index 00..67e797255b
> --- /dev/null
> +++ b/arch/riscv/dts/microchip-mpfs-icicle-kit.dts
> @@ -0,0 +1,421 @@
> +// SPDX-License-Identifier: GPL-2.0+

Please make this dual-licensed, GPL or MIT.
See 
https://github.com/polarfire-soc/meta-polarfire-soc-yocto-bsp/blob/master/recipes-kernel/linux/files/icicle-kit-es/icicle-kit-es-a000-microchip.dts

> +/* Copyright (c) 2020 Microchip Technology Inc */
> +
> +/dts-v1/;
> +#include "dt-bindings/clock/microchip,pfsoc-clock.h"
> +
> +/* Clock frequency (in Hz) of the rtcclk */
> +#define RTCCLK_FREQ100
> +
> +/ {
> +   #address-cells = <2>;
> +   #size-cells = <2>;
> +   model = "Microchip PolarFire-SoC";
> +   compatible = "microchip,polarfire-soc";
> +
> +   aliases {
> +   serial0 = &uart0;
> +   ethernet0 = &emac1;
> +   };
> +
> +   chosen {
> +   stdout-path = "serial0";
> +   };
> +
> +   cpucomplex: cpus {
> +   #address-cells = <1>;
> +   #size-cells = <0>;
> +   timebase-frequency = ;
> +   cpu0: cpu@0 {
> +   clocks = <&clkcfg CLK_CPU>;
> +   compatible = "sifive,e51", "sifive,rocket0", "riscv";
> +   device_type = "cpu";
> +   i-cache-block-size = <64>;
> +   i-cache-sets = <128>;
> +   i-cache-size = <16384>;
> +   reg = <0>;
> +   riscv,isa = "rv64imac";
> +   status = "disabled";
> +   operating-points = <
> +   /* kHz  uV */
> +   60  110
> +   30   95
> +   15   75
> +   >;
> +   cpu0intc: interrupt-controller {
> +   #interrupt-cells = <1>;
> +   compatible = "riscv,cpu-intc";
> +   interrupt-controller;
> +   };
> +   };
> +   cpu1: cpu@1 {
> +   clocks = <&clkcfg CLK_CPU>;
> +   compatible = "sifive,u54-mc", "sifive,rocket0", 
> "riscv";
> +   d-cache-block-size = <64>;
> +   d-cache-sets = <64>;
> +   d-cache-size = <32768>;
> +   d-tlb-sets = <1>;
> +   d-tlb-size = <32>;
> +   device_type = "cpu";
> +   i-cache-block-size = <64>;
> +   i-cache-sets = <64>;
> +   i-cache-size = <32768>;
> +   i-tlb-sets = <1>;
> +   i-tlb-size = <32>;
> +   mmu-type = "riscv,sv39";
> +   reg = <1>;
> +   riscv,isa = "rv64imafdc";
> +   tlb-split;
> +   status = "okay";
> +   operating-points = <
> +   /* kHz  uV */
> +   60  110
> +   3000

[PATCH v5] env: mmc: Correct partition comparison in mmc_offset_try_partition

2020-11-16 Thread Hoyeonjiki Kim
The function mmc_offset_try_partition searches the MMC partition for
locating environment data, by comparing the partition names with config
"u-boot,mmc-env-parition". However, it only compares the first word-size
bytes (size of 'const char *'), which may make the function to find
unintended partition.

Correct the function not to partially compare the partition name with
config "u-boot,mmc-env-partition".

Fixes: c9e87ba66540 ("env: Save environment at the end of an MMC partition")
Signed-off-by: Hoyeonjiki Kim 
Reviewed-by: Wolfgang Denk 
---
 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/env/mmc.c b/env/mmc.c
index 4e67180b23..ee376c3e0c 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -42,7 +42,7 @@ static inline int mmc_offset_try_partition(const char *str, 
int copy, s64 *val)
if (ret < 0)
return ret;
 
-   if (!strncmp((const char *)info.name, str, sizeof(str)))
+   if (!strncmp((const char *)info.name, str, sizeof(info.name)))
break;
}
 
-- 
2.25.1



Re: [PATCH v2 1/2] tools: mkimage: Add Allwinner eGON support

2020-11-16 Thread Samuel Holland
Hi Andre,

On 11/11/20 6:52 AM, Andre Przywara wrote:
> So far we used the separate mksunxiboot tool for generating a bootable
> image for Allwinner SPLs, probably just for historical reasons.
> 
> Use the mkimage framework to generate a so called eGON image the
> Allwinner BROM expects.
> The new image type is called "sunxi_egon", to differentiate it
> from the (still to be implemented) secure boot TOC0 image.
> 
> Signed-off-by: Andre Przywara 
> Reviewed-by: Simon Glass 
> Reviewed-by: Jagan Teki 
> Tested-by: Jagan Teki  # BPI-M64
> 
> ---
>  common/image.c |   1 +
>  include/image.h|   1 +
>  tools/Makefile |   1 +
>  tools/sunxi_egon.c | 133 +
>  4 files changed, 136 insertions(+)
>  create mode 100644 tools/sunxi_egon.c
> 
> diff --git a/common/image.c b/common/image.c
> index 451fc689a89..6923dac7c07 100644
> --- a/common/image.c
> +++ b/common/image.c
> @@ -189,6 +189,7 @@ static const table_entry_t uimage_type[] = {
>   {   IH_TYPE_STM32IMAGE, "stm32image", "STMicroelectronics STM32 
> Image" },
>   {   IH_TYPE_MTKIMAGE,   "mtk_image",   "MediaTek BootROM loadable 
> Image" },
>   {   IH_TYPE_COPRO, "copro", "Coprocessor Image"},
> + {   IH_TYPE_SUNXI_EGON, "sunxi_egon",  "Allwinner eGON Boot Image" 
> },
>   {   -1, "",   "",   },
>  };
>  
> diff --git a/include/image.h b/include/image.h
> index 00bc03bebec..89bfca2155a 100644
> --- a/include/image.h
> +++ b/include/image.h
> @@ -308,6 +308,7 @@ enum {
>   IH_TYPE_IMX8MIMAGE, /* Freescale IMX8MBoot Image*/
>   IH_TYPE_IMX8IMAGE,  /* Freescale IMX8Boot Image */
>   IH_TYPE_COPRO,  /* Coprocessor Image for remoteproc*/
> + IH_TYPE_SUNXI_EGON, /* Allwinner eGON Boot Image */
>  
>   IH_TYPE_COUNT,  /* Number of image types */
>  };
> diff --git a/tools/Makefile b/tools/Makefile
> index 51123fd9298..2c9a0c4c4e7 100644
> --- a/tools/Makefile
> +++ b/tools/Makefile
> @@ -104,6 +104,7 @@ dumpimage-mkimage-objs := aisimage.o \
>   stm32image.o \
>   $(ROCKCHIP_OBS) \
>   socfpgaimage.o \
> + sunxi_egon.o \
>   lib/crc16.o \
>   lib/sha1.o \
>   lib/sha256.o \
> diff --git a/tools/sunxi_egon.c b/tools/sunxi_egon.c
> new file mode 100644
> index 000..8dcc4c87413
> --- /dev/null
> +++ b/tools/sunxi_egon.c
> @@ -0,0 +1,133 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * (C) Copyright 2018 Arm Ltd.
> + */
> +
> +#include "imagetool.h"
> +#include 
> +
> +#include 
> +
> +/* checksum initialiser value */
> +#define STAMP_VALUE 0x5F0A6C39

Using spaces here seems unintentional.

> +
> +/*
> + * NAND requires 8K padding. SD/eMMC gets away with 512 bytes,
> + * but let's use the larger padding to cover both.
> + */
> +#define PAD_SIZE 8192
> +
> +static int egon_check_params(struct image_tool_params *params)
> +{
> + /* We just need a binary image file. */
> + return !params->dflag;
> +}
> +
> +static int egon_verify_header(unsigned char *ptr, int image_size,
> +   struct image_tool_params *params)
> +{
> + const struct boot_file_head *header = (void *)ptr;
> + uint32_t length;
> +
> + /* First 4 bytes must be an ARM branch instruction. */
> + if ((le32_to_cpu(header->b_instruction) & 0xff00) != 0xea00)
> + return EXIT_FAILURE;
> +
> + if (memcmp(header->magic, BOOT0_MAGIC, 8))

sizeof(header->magic)? (same for the memcpy below)

> + return EXIT_FAILURE;
> +
> + length = le32_to_cpu(header->length);
> + /* Must be at least 512 byte aligned. */
> + if (length & 511)
> + return EXIT_FAILURE;
> +
> + /*
> +  * Image could also contain U-Boot proper, so could be bigger.
> +  * But it must not be shorter.
> +  */
> + if (image_size < length)
> + return EXIT_FAILURE;
> +
> + return EXIT_SUCCESS;
> +}
> +
> +static void egon_print_header(const void *buf)
> +{
> + const struct boot_file_head *header = buf;
> +
> + printf("Allwinner eGON header, size: %d bytes\n",
> +le32_to_cpu(header->length));

While the data being printed comes from the header, it describes the image /
image type as a whole, so "image" seems more appropriate.

> + if (!memcmp(header->spl_signature, SPL_SIGNATURE, 3))
> + printf("\tSPL header version %d.%d\n",
> +header->spl_signature[3] >> SPL_MINOR_BITS,
> +header->spl_signature[3] & ((1U << SPL_MINOR_BITS) - 1));
> + if (header->spl_signature[3] >= SPL_DT_HEADER_VERSION)
> + printf("\tDT name: %s\n",
> +(char *)buf + le32_to_cpu(header->dt_name_offset));

This needs to be insid

RE: [PATCH] common/board_r: make sure to call initr_dm() before initr_trace()

2020-11-16 Thread Pragnesh Patel
Hi,

>-Original Message-
>From: Simon Glass 
>Sent: 17 November 2020 05:23
>To: Pragnesh Patel 
>Cc: Heinrich Schuchardt ; U-Boot Mailing List b...@lists.denx.de>
>Subject: Re: [PATCH] common/board_r: make sure to call initr_dm() before
>initr_trace()
>
>[External Email] Do not click links or attachments unless you recognize the
>sender and know the content is safe
>
>Hi,
>
>On Sun, 15 Nov 2020 at 05:16, Pragnesh Patel 
>wrote:
>>
>> Hi Heinrich,
>>
>> >-Original Message-
>> >From: Heinrich Schuchardt 
>> >Sent: 12 November 2020 18:02
>> >To: Pragnesh Patel 
>> >Cc: U-Boot Mailing List ; Simon Glass
>> >
>> >Subject: Re: [PATCH] common/board_r: make sure to call initr_dm()
>> >before
>> >initr_trace()
>> >
>> >[External Email] Do not click links or attachments unless you
>> >recognize the sender and know the content is safe
>> >
>> >On 11/12/20 12:18 PM, Pragnesh Patel wrote:
>> >> Tracing need timer ticks and initr_dm() will make gd->timer and
>> >> gd->dm_root is equal to NULL, so make sure that initr_dm() to
>> >> call before tracing got enabled.
>> >>
>> >> Signed-off-by: Pragnesh Patel 
>> >> ---
>> >>  common/board_r.c | 6 +++---
>> >>  1 file changed, 3 insertions(+), 3 deletions(-)
>> >>
>> >> diff --git a/common/board_r.c b/common/board_r.c index
>> >> 29dd7d26d9..7140a39947 100644
>> >> --- a/common/board_r.c
>> >> +++ b/common/board_r.c
>> >> @@ -693,6 +693,9 @@ static int run_main_loop(void)
>> >>   * TODO: perhaps reset the watchdog in the initcall function after each 
>> >> call?
>> >>   */
>> >>  static init_fnc_t init_sequence_r[] = {
>> >> +#ifdef CONFIG_DM
>> >> + initr_dm,
>> >> +#endif
>> >>   initr_trace,
>> >>   initr_reloc,
>> >>   /* TODO: could x86/PPC have this also perhaps? */ @@ -718,9
>> >> +721,6 @@ static init_fnc_t init_sequence_r[] = {
>> >>   initr_noncached,
>> >>  #endif
>> >>   initr_of_live,
>> >> -#ifdef CONFIG_DM
>> >> - initr_dm,
>> >> -#endif
>> >
>> >You are moving initr_of_live before initr_of_live. I doubt this will
>> >work for boards that have CONFIG_OF_LIVE=y.
>>
>> yes you are right. It will not work for CONFIG_OF_LIVE.
>>
>> >
>> >Can't we move initr_trace down in the code to after both
>> >initr_of_live and initr_dm?
>> >
>> >@Simon:
>> >Please, advise.
>>
>> I am okay with this suggestion.
>
>Actually can we use the early timer for this case?
>
>DM init is a part of U-Boot and not being able to trace it would be 
>unfortunate.

Got it.

If someone wants to use tracing without TIMER_EARLY then

- initr_dm() will make gd->dm_root = NULL; and gd->timer = NULL; and
__cyg_profile_func_enter () will call timer_get_us() -> get_ticks() -> 
dm_timer_init().

dm_timer_init() will not able to initialize timer and return an error.

We need to find any solution for this.

>
>Regards,
>Simon


Re: [PATCH 20/26] arm: mach-k3: do board config for PM and RM only if supported

2020-11-16 Thread Lokesh Vutla



On 16/11/20 5:57 pm, Tero Kristo wrote:
> On 16/11/2020 06:23, Lokesh Vutla wrote:
>>
>>
>> On 10/11/20 2:35 pm, Tero Kristo wrote:
>>> If the raw PM support is built in, we are operating in the split
>>> firmware approach mode where RM and PM support is not available. In this
>>> case, skip the board config for these two.
>>>
>>> Signed-off-by: Tero Kristo 
>>> ---
>>>   arch/arm/mach-k3/sysfw-loader.c | 4 
>>>   1 file changed, 4 insertions(+)
>>>
>>> diff --git a/arch/arm/mach-k3/sysfw-loader.c 
>>> b/arch/arm/mach-k3/sysfw-loader.c
>>> index 78c158c63f..154d2df049 100644
>>> --- a/arch/arm/mach-k3/sysfw-loader.c
>>> +++ b/arch/arm/mach-k3/sysfw-loader.c
>>> @@ -158,11 +158,13 @@ static void k3_sysfw_configure_using_fit(void *fit,
>>>     ret);
>>>     /* Apply power/clock (PM) specific configuration to SYSFW */
>>> +#ifdef CONFIG_CLK_TI_SCI
>>
>> IMHO, using CONFIG_CLK_TI_SCI is hack here. Can we showhow derive this
>> information based on the images loaded in FIT?
> 
> At this point we have only loaded the sysfw image. DM image against which we

This sysfw.itb contains all the board configurations?
If yes, then we are adding board configurations in sysfw.itb that does not
belong here.

If no, then can we check for the entries before loading?

Thanks and regards,
Lokesh

> could check this will only be loaded during A72 SPL FIT loading process, and 
> it
> will only happen later.
> 
> -Tero
> 
>>
>> Thanks and regards,
>> Lokesh
>>
>>>   ret = board_ops->board_config_pm(ti_sci,
>>>    (u64)(u32)cfg_fragment_addr,
>>>    (u32)cfg_fragment_size);
>>>   if (ret)
>>>   panic("Failed to set board PM configuration (%d)\n", ret);
>>> +#endif
>>>     /* Extract resource management (RM) specific configuration from FIT 
>>> */
>>>   ret = fit_get_data_by_name(fit, images, SYSFW_CFG_RM,
>>> @@ -171,12 +173,14 @@ static void k3_sysfw_configure_using_fit(void *fit,
>>>   panic("Error accessing %s node in FIT (%d)\n", SYSFW_CFG_RM,
>>>     ret);
>>>   +#ifdef CONFIG_CLK_TI_SCI
>>>   /* Apply resource management (RM) configuration to SYSFW */
>>>   ret = board_ops->board_config_rm(ti_sci,
>>>    (u64)(u32)cfg_fragment_addr,
>>>    (u32)cfg_fragment_size);
>>>   if (ret)
>>>   panic("Failed to set board RM configuration (%d)\n", ret);
>>> +#endif
>>>     /* Extract security specific configuration from FIT */
>>>   ret = fit_get_data_by_name(fit, images, SYSFW_CFG_SEC,
>>>
> 
> -- 
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


Re: [PATCH 1/1] riscv: Fix efi header size for RV32

2020-11-16 Thread Leo Liang
On Thu, Nov 12, 2020 at 03:05:23PM +0100, Heinrich Schuchardt wrote:
> On 12.11.20 14:43, Leo Liang wrote:
> > Date: Thu, 12 Nov 2020 10:09:52 +0800
> > From: Leo Yu-Chi Liang 
> > Subject: [PATCH 1/1] riscv: Fix efi header size for RV32
> >
> > This patch depends on Atish's patch.
> > (https://patchwork.ozlabs.org/project/uboot/patch/20201013192331.3236458-1-atish.pa...@wdc.com/)
> >
> > Modify the size of the Optional Header "Windows-Specific Fields" to fit 
> > with the specification.
> > (https://docs.microsoft.com/en-us/windows/win32/debug/pe-format)
> 
> With both patches applied on RISCV-64 I get SizeOfOptionalHeader = 0xa0
> instead of expected 0xf0.
> 
> Best regards
> 
> Heinrich
Hi Heinrich,

I will drop this patch and send a new patchset later.

Best regards,
Leo
> 
> >
> > Signed-off-by: Leo Yu-Chi Liang 
> > Cc: r...@andestech.com
> > Cc: alan...@andestech.com
> > Cc: atish.pa...@wdc.com
> > Cc: xypron.g...@gmx.de
> > Cc: bmeng...@gmail.com
> > ---
> >  arch/riscv/lib/crt0_riscv_efi.S | 17 ++---
> >  1 file changed, 14 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/riscv/lib/crt0_riscv_efi.S 
> > b/arch/riscv/lib/crt0_riscv_efi.S
> > index 4aaa49ad07..48ff89553b 100644
> > --- a/arch/riscv/lib/crt0_riscv_efi.S
> > +++ b/arch/riscv/lib/crt0_riscv_efi.S
> > @@ -15,13 +15,13 @@
> >  #define SAVE_LONG(reg, idx)sd  reg, (idx*SIZE_LONG)(sp)
> >  #define LOAD_LONG(reg, idx)ld  reg, (idx*SIZE_LONG)(sp)
> >  #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV64
> > -#define PE_MAGICIMAGE_NT_OPTIONAL_HDR64_MAGIC
> > +#define PE_MAGICIMAGE_NT_OPTIONAL_HDR64_MAGIC
> >  #else
> >  #define SIZE_LONG  4
> >  #define SAVE_LONG(reg, idx)sw  reg, (idx*SIZE_LONG)(sp)
> >  #define LOAD_LONG(reg, idx)lw  reg, (idx*SIZE_LONG)(sp)
> >  #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV32
> > -#define PE_MAGICIMAGE_NT_OPTIONAL_HDR32_MAGIC
> > +#define PE_MAGICIMAGE_NT_OPTIONAL_HDR32_MAGIC
> >  #endif
> >
> >
> > @@ -50,7 +50,7 @@ coff_header:
> >  IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
> >  IMAGE_FILE_DEBUG_STRIPPED)
> >  optional_header:
> > -   .short  PE_MAGIC/* PE32+ format */
> > +   .short  PE_MAGIC/* PE32(+) format */
> > .byte   0x02/* MajorLinkerVersion */
> > .byte   0x14/* MinorLinkerVersion */
> > .long   _edata - _start /* SizeOfCode */
> > @@ -63,7 +63,11 @@ optional_header:
> >  #endif
> >
> >  extra_header_fields:
> > +#if __riscv_xlen == 32
> > +   .long   0   /* ImageBase */
> > +#else
> > .quad   0   /* ImageBase */
> > +#endif
> > .long   0x20/* SectionAlignment */
> > .long   0x8 /* FileAlignment */
> > .short  0   /* MajorOperatingSystemVersion 
> > */
> > @@ -83,10 +87,17 @@ extra_header_fields:
> > .long   0   /* CheckSum */
> > .short  IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
> > .short  0   /* DllCharacteristics */
> > +#if __riscv_xlen == 32
> > +   .long   0   /* SizeOfStackReserve */
> > +   .long   0   /* SizeOfStackCommit */
> > +   .long   0   /* SizeOfHeapReserve */
> > +   .long   0   /* SizeOfHeapCommit */
> > +#else
> > .quad   0   /* SizeOfStackReserve */
> > .quad   0   /* SizeOfStackCommit */
> > .quad   0   /* SizeOfHeapReserve */
> > .quad   0   /* SizeOfHeapCommit */
> > +#endif
> > .long   0   /* LoaderFlags */
> > .long   0x6 /* NumberOfRvaAndSizes */
> >
> >
>