Re: [PATCH] Revert "riscv: cpu: fu740: clear feature disable CSR"

2021-05-13 Thread Rick Chen
> From: Bin Meng 
> Sent: Friday, May 14, 2021 11:50 AM
> To: Green Wan 
> Cc: Rick Jian-Zhi Chen(陳建志) ; Sean Anderson 
> ; U-Boot Mailing List 
> Subject: Re: [PATCH] Revert "riscv: cpu: fu740: clear feature disable CSR"
>
> On Fri, May 14, 2021 at 11:45 AM Green Wan  wrote:
> >
> > Hi Bin,
> >
> > Thanks, I'll include that revert. Just traced back the git log. My original 
> > patch is based on fu740. I guess it was merged to fu540 since fu740 series 
> > wasn't present yet.
> >
> > Hi Rick,
> >
> > Not sure whether you'll pick fu740 series soon or if any parts need more 
> > revisement. Do you prefer that I append both this revert and "disable CSR" 
> > patch to fu740 patch series? If so, I will create v9 patch and 
> > include these 2 patches.
> >
> > Or if you prefer to keep them separate from fu740 series, we can wait for 
> > fu740 patch merge and I'll create a separate patch for this revert 
> > and CSR disable.
> >
> > What do you think? Many thanks.
> >
>
> There are multiple breakages in current u-boot/master for SiFive Unleashed 
> board.
>
> We'd better apply them as soon as possible.

OK

Leo will help to apply it ASAP.

Thanks,
Rick

>
> Regards,
> Bin


Re: [PATCH 1/2] reset: Do not return NULL on error for devm_reset_control_get_optional()

2021-05-13 Thread Kishon Vijay Abraham I
Hi Simon,

On 14/05/21 5:26 am, Simon Glass wrote:
> Hi Kishon,
> 
> On Thu, 13 May 2021 at 00:15, Kishon Vijay Abraham I  wrote:
>>
>> Hi Simon,
>>
>> On 11/05/21 10:09 pm, Simon Glass wrote:
>>> Hi Kishon,
>>>
>>> On Tue, 11 May 2021 at 00:26, Kishon Vijay Abraham I  wrote:

 Hi Simon,

 On 07/05/21 10:04 pm, Simon Glass wrote:
> Hi Kishon,
>
> On Fri, 7 May 2021 at 05:02, Kishon Vijay Abraham I  wrote:
>>
>> In order for client to know whether it was able to successfully get a
>> reset controller or not, do not return NULL on error for
>> devm_reset_control_get_optional() and
>> devm_reset_bulk_get_optional_by_node().
>>
>> Signed-off-by: Kishon Vijay Abraham I 
>> ---
>>  drivers/reset/reset-uclass.c   | 16 ++--
>>  drivers/reset/sandbox-reset-test.c |  2 +-
>>  2 files changed, 3 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
>> index ac89eaf098..906f58ce3d 100644
>> --- a/drivers/reset/reset-uclass.c
>> +++ b/drivers/reset/reset-uclass.c
>> @@ -299,12 +299,7 @@ struct reset_ctl *devm_reset_control_get(struct 
>> udevice *dev, const char *id)
>>  struct reset_ctl *devm_reset_control_get_optional(struct udevice *dev,
>>   const char *id)
>>  {
>> -   struct reset_ctl *r = devm_reset_control_get(dev, id);
>> -
>> -   if (IS_ERR(r))
>> -   return NULL;
>> -
>> -   return r;
>> +   return devm_reset_control_get(dev, id);
>>  }
>
> We need to get some updates to the API (function comments in the
> header) here. I'm not sure what the intent is.

 right, that has to be fixed.
>
> I thought these functions were going to return a valid (but possibly
> empty) reset_ctl always?

 I thought about it again and felt it might not be correct to return
 reset_ctl always. The reset control is optional only if the consumer
 node doesn't have populated reset properties.

 If we always return valid reset_ctl possibly with it's dev member
 initialized or not initialized, it would not be possible to tell it's
 not initialized because of the absence of reset property or due to some
 other valid error.
>>>
>>> reset_valid() should check if dev is NULL or not, like with clock and
>>> GPIO. Is that enough?
>>
>> clock compares with ENODATA and return "0" (code snippet below). For
>> reset we are modifying this to return ENODATA itself and use it for
>> comparing in the reset APIs.
>>
>> int clk_get_optional_nodev(ofnode node, const char *name, struct clk *clk)
>> {
>> int ret;
>>
>> ret = clk_get_by_name_nodev(node, name, clk);
>> if (ret == -ENODATA)
>> return 0;
>>
>> return ret;
>> }
>>
> 
> We must just be talking at cross-purposes. The function you show above
> returns an error code, so there is no need for the caller to check clk
> if an error is returned. For the -ENODATA case, note that
> clk_get_by_name_nodev() sets clk->dev to NULL, thus ensuring that
> clk_valid() works as expected.

hmm, I pointed to the wrong function from clk-uclass. The below clk
function is similar to our reset usecase

struct clk *devm_clk_get_optional(struct udevice *dev, const char *id)
{
struct clk *clk = devm_clk_get(dev, id);

if (PTR_ERR(clk) == -ENODATA)
return NULL;

return clk;
}

For this case, clk_valid() works because it checks for "clk" pointer and
for ENODATA case (get_optional), the client will have clk = NULL and
pass NULL to all the clock APIs.

IIUC, you don't prefer returning NULL to client on ENODATA (or any other
error)? And that's why unlike devm_clk_get_optional() which returns NULL
on ENODATA, $patch directly returns devm_reset_control_get().

So for reset it could return
1) valid reset_ctl pointer with dev initialized
2) -ENOMEM (if allocation of reset_ctl itself fails)
3) -ENODATA (if reset-names is not populated in DT)
4) -ENOENT/-EINVAL (for other DT errors)

clk-uclass has a separate class of APIs that ends with _nodev(). Here
the client allocates memory for clk and let clk framework populate
clk->dev. For the other APIs where clk framework itself returns clk
pointer, there is no case where clk framework returns a valid clk
pointer but without clk->dev initialized (the second case is what we
deal in reset).

Since reset at this point doesn't deal with _nodev(), the latter case
above for clk is what should be considered (i.e reset returns valid
reset_ctrl pointer with dev initialized or return an error value).

So again coming back to the return values mentioned above [ 1) valid
reset, 2) -ENOMEM, 3) -ENODATA, 4) -ENOENT/-EINVAL ].

For get_optional()
  1) Should we return NULL on -ENODATA (similar to devm_clk_get_optional())?
  2) If we 

Re: [PATCH 1/4] tools: mkeficapsule: add firmwware image signing

2021-05-13 Thread AKASHI Takahiro
On Thu, May 13, 2021 at 07:42:04PM +0300, Ilias Apalodimas wrote:
> [...]
> > > > FWIW I personally don't think we should even have a config option. But 
> > > > even
> > > > if we did it certainly must not be dictated by a hardware config.
> > > > 
> > > > When you install distro packages you accept whatever dependencies the
> > > > package has. mkeficapsule is a capsule creation and signing tool.  I 
> > > > don't
> > > > see any reason for keeping the creation and signing apart.
> > > 
> > > My question is, since the U-Boot binary is heavily dependent on the target
> > > platform, can we split the u-boot.bin creation (may include embedding 
> > > keys)
> > > and the capsule file creation (including signing)?
> > 
> > Building U-Boot and creating a capsule are totally separate. Maybe you
> > get the first capsule years after you buy your board. But this should
> > not stop us from building mkeficapsule when building U-Boot.
> > 
> 
> Based on what was discussed in the thread waht I think would make more
> sense is:
> - Build u-boot and use the script Akashi sent to inject the certificate. 
>   Whether we create a single binary (always signed if a config option is
>   there) or 2 binaries (1 signed. 1 unsigned) is an implemetation detail
>   and I am fine with either.

Let me make clear: "a single binary or 2 binaries" is not
an implementation detail, but it's a matter of user's (, distro's
or whoever wants to provide a capsule) policy.

> - Use mkefi capsule to create the final capsule

If signing feature is enabled in mkeficapsule, you can create
both a signed capsule and an unsigned capsule.
And yet, some users may totally had no need to authentication
for firmware update using UEFI interfaces on their systems.
For them, signing should be able to be disabled.

> 
> > If you want to build tools only, you can do so with 'make tools'. The
> > tools target must include mkeficapsule irrespective of configuration.
> > 
> > This line in tools/Makefile must be corrected:
> > 
> > -hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule
> > +hostprogs-y += mkeficapsule
> 
> So that's the point exactly. Building the tool is completely disjoint from
> building a u-boot binary.   Also you usually start adding config options to
> an app, when it starts getting to big and you want discrete functionality. 

I don't get your point.
As far as we maintain CONFIG_(HOST_)_EFI_CAPSULE_AUTHENTICATE,
we can and should guarantee the compatibility.

> I don't see any reason for making a simple tool, which is supposed to do 2
> things (create/sign), require config options and more over config options
> *for U-Boot*.

I don't get you point neither.

> I also think it's extremely unlikely to get any working distro 
> without libssl. 

Again, (major) distros are ones of users.
There may be bunch of users who may build/maintain their systems
on their way and not expect any authentication.

Having said that,
coincidentally there is happening a similar discussion
about building host tools and host-specific configs among Simon, Tom
and Alex[1].
(The background for the discussion is a bit different though.)

I'd like to see and follow the direction to be agreed there.

[1] https://lists.denx.de/pipermail/u-boot/2021-May/449050.html

-Takahiro Akashi

> > 
> > Best regards
> > 
> > Heinrich


Re: [PATCH 1/4] tools: mkeficapsule: add firmwware image signing

2021-05-13 Thread AKASHI Takahiro
On Thu, May 13, 2021 at 06:32:13PM +0200, Heinrich Schuchardt wrote:
> On 5/13/21 6:12 PM, Masami Hiramatsu wrote:
> > 2021年5月13日(木) 19:27 Ilias Apalodimas :
> > > 
> > > On Thu, May 13, 2021 at 05:38:51PM +0900, AKASHI Takahiro wrote:
> > > > On Thu, May 13, 2021 at 05:18:36PM +0900, Masami Hiramatsu wrote:
> > > > > 2021年5月13日(木) 16:24 AKASHI Takahiro :
> > > > > 
> > > > > > > > > > BTW, IMHO, if u-boot.bin can not find the ESL in the device 
> > > > > > > > > > tree,
> > > > > > > > > > it should skip authentication too.
> > > > > > > > > 
> > > > > > > > > In this case the capsule should be rejected (if
> > > > > > > > > CONFIG_EFI_CAPSULE_AUTHENTICATE=y).
> > > > > > > > 
> > > > > > > > That's basically right.
> > > > > > > > But as I mentioned in my comment against Sughosh's patch,
> > > > > > > > the authentication process will be enforced only if the capsule 
> > > > > > > > has
> > > > > > > > an attribute, IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED.
> > > > > > > > 
> > > > > > > 
> > > > > > > That would be a security desaster.
> > > > > > 
> > > > > > The requirement that I mentioned above is clearly described
> > > > > > in UEFI specification.
> > > > > > If you think that it is a disaster, please discuss the topic
> > > > > > in UEFI Forum first.
> > > > > 
> > > > > I confirmed UEFI specification, version 2.7, Section.23.1
> > > > > the last of EFI_FIRMWARE_MANAGEMENT_PROTOCOL.GetImageInfo()
> > > > > 
> > > > > -
> > > > > If IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED is supported and clear, 
> > > > > then
> > > > > authentication is not required to perform the firmware image 
> > > > > operations.
> > > > > -
> > > > 
> > > > Thank you for citing this.
> > > > 
> > > > > Oh, this is really crazy because deciding whether to authenticate the
> > > > > suspicious
> > > > > package or not, depends on whether the package said "please
> > > > > authenticate me" or not. :D
> > > > 
> > > > Well, the attributes can been fetched with GetInfo API, but
> > > > how it is managed depends on the implementation of FMP drivers.
> > > > 
> > > > As I proposed somewhere else, those attributes should be
> > > > maintained in a separate place (maybe as part of system's policy),
> > > > presumably ESRT or platform-specific internal database?
> > > 
> > > FWIW I personally don't think we should even have a config option. But 
> > > even
> > > if we did it certainly must not be dictated by a hardware config.
> > > 
> > > When you install distro packages you accept whatever dependencies the
> > > package has. mkeficapsule is a capsule creation and signing tool.  I don't
> > > see any reason for keeping the creation and signing apart.
> > 
> > My question is, since the U-Boot binary is heavily dependent on the target
> > platform, can we split the u-boot.bin creation (may include embedding keys)
> > and the capsule file creation (including signing)?
> 
> Building U-Boot and creating a capsule are totally separate. Maybe you
> get the first capsule years after you buy your board. But this should
> not stop us from building mkeficapsule when building U-Boot.
> 
> If you want to build tools only, you can do so with 'make tools'. The
> tools target must include mkeficapsule irrespective of configuration.

So far, we have been discussing whether CONFIG_EFI_CAPSULE_AUTHENTICATE
(or "host" version like CONFIG_HOST_EFI_CAPSULE_AUTHENITATE)
be honored in mkeficapsule.c or not.

> This line in tools/Makefile must be corrected:
> 
> -hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule
> +hostprogs-y += mkeficapsule

There exist lots of "hostprogs-$(CONFIG_...)" targets.
I think that this is a common practice in U-Boot.

-Takahiro Akashi

> Best regards
> 
> Heinrich


Re: [PATCH] Revert "riscv: cpu: fu740: clear feature disable CSR"

2021-05-13 Thread Bin Meng
On Fri, May 14, 2021 at 11:45 AM Green Wan  wrote:
>
> Hi Bin,
>
> Thanks, I'll include that revert. Just traced back the git log. My original 
> patch is based on fu740. I guess it was merged to fu540 since fu740 series 
> wasn't present yet.
>
> Hi Rick,
>
> Not sure whether you'll pick fu740 series soon or if any parts need more 
> revisement. Do you prefer that I append both this revert and "disable CSR" 
> patch to fu740 patch series? If so, I will create v9 patch and 
> include these 2 patches.
>
> Or if you prefer to keep them separate from fu740 series, we can wait for 
> fu740 patch merge and I'll create a separate patch for this revert 
> and CSR disable.
>
> What do you think? Many thanks.
>

There are multiple breakages in current u-boot/master for SiFive
Unleashed board.

We'd better apply them as soon as possible.

Regards,
Bin


Re: [PATCH] Revert "riscv: cpu: fu740: clear feature disable CSR"

2021-05-13 Thread Green Wan
Hi Bin,

Thanks, I'll include that revert. Just traced back the git log. My original
patch is based on fu740. I guess it was merged to fu540 since fu740 series
wasn't present yet.

Hi Rick,

Not sure whether you'll pick fu740 series soon or if any parts need more
revisement. Do you prefer that I append both this revert and "disable CSR"
patch to fu740 patch series? If so, I will create v9 patch and
include these 2 patches.

Or if you prefer to keep them separate from fu740 series, we can wait for
fu740 patch merge and I'll create a separate patch for this revert
and CSR disable.

What do you think? Many thanks.

Regards,
- Green

On Wed, May 12, 2021 at 11:28 PM Bin Meng  wrote:

> Hi Green,
>
> On Wed, May 12, 2021 at 11:13 PM Green Wan  wrote:
> >
> > Yes, noted. This patch should be applied based on the fu740 port. Thanks
> for the reminder.
> >
>
> Just to clarify, the reverted patch *content* should be in your fu740
> support series.
>
> @Rick, this revert patch itself should be applied in u-boot/master
> now, as the mainline U-Boot does not boot on the Unleashed board.
>
> Regards,
> Bin
>


[PATCH v3 1/1] clk: zynq: Add clock wizard driver

2021-05-13 Thread zhengxun
The Clocking Wizard IP supports clock circuits customized
to your clocking requirements. The wizard support for
dynamically reconfiguring the clocking primitives for
Multiply, Divide, Phase Shift/Offset, or Duty Cycle.

Limited by uboot clk uclass without set_phase API, this
patch only provides set_rate to modify the frequency.

Signed-off-by: zhengxun 
---
 drivers/clk/Kconfig |   9 ++
 drivers/clk/Makefile|   1 +
 drivers/clk/clk-xlnx-clock-wizard.c | 177 
 3 files changed, 187 insertions(+)
 create mode 100644 drivers/clk/clk-xlnx-clock-wizard.c

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 40a5a5dd88..dfaeac0204 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -128,6 +128,15 @@ config CLK_ZYNQ
  This clock driver adds support for clock related settings for
  Zynq platform.
 
+config COMMON_CLK_XLNX_CLKWZRD
+   bool "Xilinx Clocking Wizard"
+   depends on CLK
+   help
+ Support for the Xilinx Clocking Wizard IP core clock generator.
+ Adds support for clocking wizard and compatible.
+ This driver supports the Xilinx clocking wizard programmable clock
+ synthesizer.
+
 config CLK_ZYNQMP
bool "Enable clock driver support for ZynqMP"
depends on ARCH_ZYNQMP
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 645709b855..f4ddbe831a 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_CLK_UNIPHIER) += uniphier/
 obj-$(CONFIG_CLK_VEXPRESS_OSC) += clk_vexpress_osc.o
 obj-$(CONFIG_CLK_ZYNQ) += clk_zynq.o
 obj-$(CONFIG_CLK_ZYNQMP) += clk_zynqmp.o
+obj-$(CONFIG_COMMON_CLK_XLNX_CLKWZRD) += clk-xlnx-clock-wizard.o
 obj-$(CONFIG_ICS8N3QV01) += ics8n3qv01.o
 obj-$(CONFIG_MACH_PIC32) += clk_pic32.o
 obj-$(CONFIG_SANDBOX) += clk_sandbox.o
diff --git a/drivers/clk/clk-xlnx-clock-wizard.c 
b/drivers/clk/clk-xlnx-clock-wizard.c
new file mode 100644
index 00..9ca4144700
--- /dev/null
+++ b/drivers/clk/clk-xlnx-clock-wizard.c
@@ -0,0 +1,177 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Xilinx 'Clocking Wizard' driver
+ *
+ * Copyright (c) 2021 Macronix Inc.
+ *
+ * Author: Zhengxun Li 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SRR0x0
+
+#define SR 0x4
+#define SR_LOCKED  BIT(0)
+
+#define CCR(x) (0x200 + ((x) * 4))
+
+#define FBOUT_CFG  CCR(0)
+#define FBOUT_DIV(x)   (x)
+#define FBOUT_GET_DIV(x)   ((x) & GENMASK(7, 0))
+#define FBOUT_MUL(x)   ((x) << 8)
+#define FBOUT_GET_MUL(x)   (((x) & GENMASK(15, 8)) >> 8)
+#define FBOUT_FRAC(x)  ((x) << 16)
+#define FBOUT_GET_FRAC(x)  (((x) & GENMASK(25, 16)) >> 16)
+#define FBOUT_FRAC_EN  BIT(26)
+
+#define FBOUT_PHASECCR(1)
+
+#define OUT_CFG(x) CCR(2 + ((x) * 3))
+#define OUT_DIV(x) (x)
+#define OUT_GET_DIV(x) ((x) & GENMASK(7, 0))
+#define OUT_FRAC(x)((x) << 8)
+#define OUT_GET_FRAC(x)(((x) & GENMASK(17, 8)) >> 8)
+#define OUT_FRAC_ENBIT(18)
+
+#define OUT_PHASE(x)   CCR(3 + ((x) * 3))
+#define OUT_DUTY(x)CCR(4 + ((x) * 3))
+
+#define CTRL   CCR(23)
+#define CTRL_SEN   BIT(2)
+#define CTRL_SADDR BIT(1)
+#define CTRL_LOAD  BIT(0)
+
+/*
+ * struct clkwzrd - Clock wizard private data structure
+ *
+ * @base : memory base
+ * @vco_clk :  voltage-controlled oscillator frequency
+ */
+struct clkwzd {
+   void __iomem *base;
+   u64 vco_clk;
+};
+
+struct clkwzd_plat {
+   fdt_addr_t addr;
+};
+
+static int clk_wzrd_enable(struct clk *clk)
+{
+   struct clkwzd *priv = dev_get_priv(clk->dev);
+   int ret;
+   u32 val;
+
+   ret = readl_poll_sleep_timeout(priv->base + SR, val, val & SR_LOCKED,
+  1, 100);
+   if (!ret) {
+   writel(CTRL_SEN | CTRL_SADDR | CTRL_LOAD, priv->base + CTRL);
+   writel(CTRL_SADDR, priv->base + CTRL);
+   ret = readl_poll_sleep_timeout(priv->base + SR, val,
+  val & SR_LOCKED, 1, 100);
+   }
+
+   return ret;
+}
+
+static unsigned long clk_wzrd_set_rate(struct clk *clk, ulong rate)
+{
+   struct clkwzd *priv = dev_get_priv(clk->dev);
+   u64 div;
+   u32 cfg;
+
+   /* Get output clock divide value */
+   div = DIV_ROUND_DOWN_ULL(priv->vco_clk * 1000, rate);
+   if (div < 1000 || div > 255999)
+   return -EINVAL;
+
+   cfg = OUT_DIV((u32)div / 1000);
+
+   writel(cfg, priv->base + OUT_CFG(clk->id));
+
+   return 0;
+}
+
+static int clk_wzrd_of_to_plat(struct udevice *dev)
+{
+   struct clkwzd_plat *plat = dev_get_plat(dev);
+
+   plat->addr = dev_read_addr(dev);
+   if (plat->addr == 

[PATCH v3 0/1] Add Xilinx clock wizard driver support

2021-05-13 Thread zhengxun
Add support to enable clock wizard for zynq platform.

Changes in v3:
- remove incorrect usage in of_to_plat
- get frequencies via clock framework
- delete incorrect naming

Changes in v2:
- naming is aligned with linux
- delete inappropriate description and code

zhengxun (1):
  clk: zynq: Add clock wizard driver

 drivers/clk/Kconfig |   9 ++
 drivers/clk/Makefile|   1 +
 drivers/clk/clk-xlnx-clock-wizard.c | 177 
 3 files changed, 187 insertions(+)
 create mode 100644 drivers/clk/clk-xlnx-clock-wizard.c

-- 
2.17.1



RE: [PATCH] arm: dts: lx2162aqds: support eMMC HS400 mode on esdhc1

2021-05-13 Thread Y.b. Lu
Sent out v2 to update copyright.
Any comments on v2.

Thank you.

> -Original Message-
> From: Yangbo Lu 
> Sent: 2021年4月27日 16:28
> To: u-boot@lists.denx.de; Priyanka Jain ; Meenakshi
> Aggarwal 
> Cc: Y.b. Lu 
> Subject: [PATCH] arm: dts: lx2162aqds: support eMMC HS400 mode on esdhc1
> 
> Add properties related to eMMC HS400 mode for esdhc1.
> 
> Signed-off-by: Yangbo Lu 
> ---
>  arch/arm/dts/fsl-lx2162a-qds-sd1-17.dtsi | 6 ++
> arch/arm/dts/fsl-lx2162a-qds-sd1-18.dtsi | 6 ++
> arch/arm/dts/fsl-lx2162a-qds-sd1-20.dtsi | 6 ++
>  arch/arm/dts/fsl-lx2162a-qds.dts | 6 ++
>  4 files changed, 24 insertions(+)
> 
> diff --git a/arch/arm/dts/fsl-lx2162a-qds-sd1-17.dtsi
> b/arch/arm/dts/fsl-lx2162a-qds-sd1-17.dtsi
> index 60f5a4ee43..3b6fddba7c 100644
> --- a/arch/arm/dts/fsl-lx2162a-qds-sd1-17.dtsi
> +++ b/arch/arm/dts/fsl-lx2162a-qds-sd1-17.dtsi
> @@ -56,3 +56,9 @@
>   reg = <0x3>;
>   };
>  };
> +
> + {
> + mmc-hs200-1_8v;
> + mmc-hs400-1_8v;
> + bus-width = <8>;
> +};
> diff --git a/arch/arm/dts/fsl-lx2162a-qds-sd1-18.dtsi
> b/arch/arm/dts/fsl-lx2162a-qds-sd1-18.dtsi
> index 8e11b0680a..0f4329f587 100644
> --- a/arch/arm/dts/fsl-lx2162a-qds-sd1-18.dtsi
> +++ b/arch/arm/dts/fsl-lx2162a-qds-sd1-18.dtsi
> @@ -59,3 +59,9 @@
>   reg = <0x1>;
>   };
>  };
> +
> + {
> + mmc-hs200-1_8v;
> + mmc-hs400-1_8v;
> + bus-width = <8>;
> +};
> diff --git a/arch/arm/dts/fsl-lx2162a-qds-sd1-20.dtsi
> b/arch/arm/dts/fsl-lx2162a-qds-sd1-20.dtsi
> index faf4285eab..8c856a19d4 100644
> --- a/arch/arm/dts/fsl-lx2162a-qds-sd1-20.dtsi
> +++ b/arch/arm/dts/fsl-lx2162a-qds-sd1-20.dtsi
> @@ -24,3 +24,9 @@
>   reg = <0x0>;
>   };
>  };
> +
> + {
> + mmc-hs200-1_8v;
> + mmc-hs400-1_8v;
> + bus-width = <8>;
> +};
> diff --git a/arch/arm/dts/fsl-lx2162a-qds.dts
> b/arch/arm/dts/fsl-lx2162a-qds.dts
> index 341610ccf4..68cb328716 100644
> --- a/arch/arm/dts/fsl-lx2162a-qds.dts
> +++ b/arch/arm/dts/fsl-lx2162a-qds.dts
> @@ -135,3 +135,9 @@
>   reg = <2>;
>   };
>  };
> +
> + {
> + mmc-hs200-1_8v;
> + mmc-hs400-1_8v;
> + bus-width = <8>;
> +};
> --
> 2.25.1



RE: [PATCH] armv8: layerscape: enable eMMC HS400 workarounds for LX2160A/LX2162A

2021-05-13 Thread Y.b. Lu
Any comments.
Thanks!

> -Original Message-
> From: Yangbo Lu 
> Sent: 2021年4月27日 16:42
> To: u-boot@lists.denx.de; Priyanka Jain ; Meenakshi
> Aggarwal 
> Cc: Y.b. Lu 
> Subject: [PATCH] armv8: layerscape: enable eMMC HS400 workarounds for
> LX2160A/LX2162A
> 
> Enable eMMC HS400 workarounds for LX2160A/LX2162A.
> 
> Signed-off-by: Yangbo Lu 
> ---
>  arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> index 9d1ba4c771..395e5ccaad 100644
> --- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> +++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> @@ -224,6 +224,8 @@ config ARCH_LX2162A
>   select SYS_FSL_EC1
>   select SYS_FSL_EC2
>   select SYS_FSL_ERRATUM_A050106
> + select SYS_FSL_ERRATUM_A011334
> + select SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND
>   select SYS_FSL_HAS_RGMII
>   select SYS_FSL_HAS_SEC
>   select SYS_FSL_HAS_CCN508
> @@ -254,6 +256,8 @@ config ARCH_LX2160A
>   select SYS_FSL_EC1
>   select SYS_FSL_EC2
>   select SYS_FSL_ERRATUM_A050106
> + select SYS_FSL_ERRATUM_A011334
> + select SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND
>   select SYS_FSL_HAS_RGMII
>   select SYS_FSL_HAS_SEC
>   select SYS_FSL_HAS_CCN508
> --
> 2.25.1



[v2] arm: dts: lx2162aqds: support eMMC HS400 mode on esdhc1

2021-05-13 Thread Yangbo Lu
Add properties related to eMMC HS400 mode for esdhc1.

Signed-off-by: Yangbo Lu 
---
Changes for v2:
- Updated copyright.
---
 arch/arm/dts/fsl-lx2162a-qds-sd1-17.dtsi | 8 +++-
 arch/arm/dts/fsl-lx2162a-qds-sd1-18.dtsi | 8 +++-
 arch/arm/dts/fsl-lx2162a-qds-sd1-20.dtsi | 8 +++-
 arch/arm/dts/fsl-lx2162a-qds.dts | 8 +++-
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/arch/arm/dts/fsl-lx2162a-qds-sd1-17.dtsi 
b/arch/arm/dts/fsl-lx2162a-qds-sd1-17.dtsi
index 60f5a4ee43..d1e4a8567f 100644
--- a/arch/arm/dts/fsl-lx2162a-qds-sd1-17.dtsi
+++ b/arch/arm/dts/fsl-lx2162a-qds-sd1-17.dtsi
@@ -5,7 +5,7 @@
  * Some assumptions are made:
  ** mezzanine card M8 is connected to IO SLOT1 (25g-aui for DPMAC 3,4,5,6)
  *
- * Copyright 2020 NXP
+ * Copyright 2020-2021 NXP
  *
  */
 
@@ -56,3 +56,9 @@
reg = <0x3>;
};
 };
+
+ {
+   mmc-hs200-1_8v;
+   mmc-hs400-1_8v;
+   bus-width = <8>;
+};
diff --git a/arch/arm/dts/fsl-lx2162a-qds-sd1-18.dtsi 
b/arch/arm/dts/fsl-lx2162a-qds-sd1-18.dtsi
index 8e11b0680a..e9a743b3a2 100644
--- a/arch/arm/dts/fsl-lx2162a-qds-sd1-18.dtsi
+++ b/arch/arm/dts/fsl-lx2162a-qds-sd1-18.dtsi
@@ -6,7 +6,7 @@
  ** mezzanine card M11 is connected to IO SLOT1 (usxgmii for DPMAC 3,4)
  ** mezzanine card M13/M8 is connected to IO SLOT6 (25g-aui for DPMAC 5,6)
  *
- * Copyright 2020 NXP
+ * Copyright 2020-2021 NXP
  *
  */
 
@@ -59,3 +59,9 @@
reg = <0x1>;
};
 };
+
+ {
+   mmc-hs200-1_8v;
+   mmc-hs400-1_8v;
+   bus-width = <8>;
+};
diff --git a/arch/arm/dts/fsl-lx2162a-qds-sd1-20.dtsi 
b/arch/arm/dts/fsl-lx2162a-qds-sd1-20.dtsi
index faf4285eab..d9ad1c6a4b 100644
--- a/arch/arm/dts/fsl-lx2162a-qds-sd1-20.dtsi
+++ b/arch/arm/dts/fsl-lx2162a-qds-sd1-20.dtsi
@@ -6,7 +6,7 @@
  ** Mezzanine card M8 is connected to IO SLOT1
  *(xlaui4 for DPMAC 1)
  *
- * Copyright 2020 NXP
+ * Copyright 2020-2021 NXP
  *
  */
 
@@ -24,3 +24,9 @@
reg = <0x0>;
};
 };
+
+ {
+   mmc-hs200-1_8v;
+   mmc-hs400-1_8v;
+   bus-width = <8>;
+};
diff --git a/arch/arm/dts/fsl-lx2162a-qds.dts b/arch/arm/dts/fsl-lx2162a-qds.dts
index 341610ccf4..0ca30df862 100644
--- a/arch/arm/dts/fsl-lx2162a-qds.dts
+++ b/arch/arm/dts/fsl-lx2162a-qds.dts
@@ -2,7 +2,7 @@
 /*
  * NXP LX2162AQDS device tree source
  *
- * Copyright 2020 NXP
+ * Copyright 2020-2021 NXP
  *
  */
 
@@ -135,3 +135,9 @@
reg = <2>;
};
 };
+
+ {
+   mmc-hs200-1_8v;
+   mmc-hs400-1_8v;
+   bus-width = <8>;
+};
-- 
2.25.1



Re: [PATCH 2/4] tools: mkeficapsule: remove device-tree related operation

2021-05-13 Thread Masami Hiramatsu
Hi Heinrich,

2021年5月14日(金) 2:42 Heinrich Schuchardt :
>
> On 5/13/21 9:13 AM, AKASHI Takahiro wrote:
> > On Thu, May 13, 2021 at 07:08:12AM +0200, Heinrich Schuchardt wrote:
> >> On 5/13/21 4:33 AM, AKASHI Takahiro wrote:
> >>> On Wed, May 12, 2021 at 12:01:32PM +0200, Heinrich Schuchardt wrote:
>  On 12.05.21 10:01, Ilias Apalodimas wrote:
> > On Wed, May 12, 2021 at 04:49:02PM +0900, Masami Hiramatsu wrote:
> >> Hi Ilias,
> >>
> >> 2021年5月12日(水) 16:21 Ilias Apalodimas :
> >>>
> >>> Akashi-san,
> >>>
> >>> On Wed, May 12, 2021 at 01:57:51PM +0900, AKASHI Takahiro wrote:
>  As we discussed, "-K" and "-D" options have nothing to do with
>  creating a capsule file. The same result can be obtained by
>  using standard commands like:
>  === signature.dts ===
>  /dts-v1/;
>  /plugin/;
> 
>  &{/} {
>    signature {
>    capsule-key = /incbin/("SIGNER.esl");
>    };
>  };
>  ===
>  $ dtc -@ -I dts -O dtb -o signature.dtbo signature.dts
>  $ fdtoverlay -i test.dtb -o test_sig.dtb -v signature.dtbo
> 
>  So just remove this feature.
>  (Effectively revert the commit 322c813f4bec ("mkeficapsule: Add 
>  support
>  for embedding public key in a dtb").)
> 
>  The same feature is implemented by a shell script (tools/fdtsig.sh).
> >>>
> >>>
> >>> The only reason I can see to keep this, is if mkeficapsule gets 
> >>> included
> >>> intro distro packages in the future.  That would make end users life 
> >>> a bit
> >>> easier, since they would need a single binary to create the whole
> >>> CapsuleUpdate sequence.
> >>
> >> Hmm, I think it is better to write a manpage of mkeficapsule which
> >> also describes
> >> how to embed the key into dtb as in the above example if it is so 
> >> short.
> >> Or, distros can package the above shell script with mkeficapsule.
> >>
> >> Embedding a key and signing a capsule are different operations but
> >> using the same tool may confuse users (at least me).
> >
> > Sure fair enough.  I am merely pointing out we need a way to explain 
> > all of
> > those to users.
> 
>  This is currently our only documentation:
> 
>  https://u-boot.readthedocs.io/en/latest/board/emulation/qemu_capsule_update.html?highlight=mkeficapsule
> >>>
> >>> As I mentioned several times (and TODO in the cover letter),
> >>> this text must be reviewed, revised and generalized
> >>> as a platform-independent document.
> >>> It contains a couple of errors.
> >>>
>  For mkimage we have a man-page ./doc/mkimage.1 that is packaged with
>  Debians u-boot-tools package. Please, provide a similar man-page as
>  ./doc/mkeficapsule.1.
> >>>
> >>> So after all do you agree to removing "-K/-D"?
> >>
> >> I see no need to replicate in U-Boot what is already in the device tree
> >> compiler package.
> >
> > This is another reason that we should remove Sughosh's change.
> >
> >> In the current workflow the fdt command is used to load the public key.
> >> This is insecure and not usable for production.
> >
> > I totally disagree.
> > Why is using fdt command (what do you mean by fdt command, dtc/fdtoverlay?)
> > insecure?
>
> A user can load an insecure capsule.
>
> The fdt command is in /cmd/fdt.c and you are referring to it in
> board/emulation/qemu_capsule_update.rst.

Hmm, this seems like a testing manual.

>
> >
> >> The public key used to verify the capsule must be built into the U-Boot
> >> binary. This will supplant the -K and -D options.
> >
> > I don't get your point. You don't understand my code.
> >
> > Even with Sughosh's original patch, the public key (as I said,
> > it is not a public key but a X509 certificate in ESL format) is
> > embedded in the U-Boot's "control device tree".
>
> No, the ESL file it is not built into U-Boot's control device tree.
>
> A user is loading it and updating the control device tree.

In my case (I've tested it on the DeveloperBox), the key is embedded in
the U-Boot's control device tree.

>
> You shouldn't trust anything a user has loaded. You need at least the
> public key of the root CA built somewhere into U-Boot.

However, I agreed this point. If we use the public key in the device
tree, it must be loaded as a part of U-Boot itself, and must not overwritten
by the user given fdt.

>
> The 'fdt resize' command may overwrite code. This is not what you want
> to do with the control device tree.
>
> If CONFIG_OF_LIVE=y, the active device tree is not at $fdtcontroladdr
> but in a hierarchical structure. You cannot update it via the fdt command.
>
> >
> > Even after applying my patch, this is true.
> >
> > Or are you insisting that the key should not be in the device tree?
>
> The public key of the root CA 

Re: [PATCH 2/4] tools: mkeficapsule: remove device-tree related operationy

2021-05-13 Thread AKASHI Takahiro
Heinrich,

You are discussing two different issues:
1. if we should remove "-K/-D" options from mkeficapsule
2. if it is safe or not to store a key in device tree

It makes the discussion in this thread confusing.

On Thu, May 13, 2021 at 07:42:23PM +0200, Heinrich Schuchardt wrote:
> On 5/13/21 9:13 AM, AKASHI Takahiro wrote:
> > On Thu, May 13, 2021 at 07:08:12AM +0200, Heinrich Schuchardt wrote:
> > > On 5/13/21 4:33 AM, AKASHI Takahiro wrote:
> > > > On Wed, May 12, 2021 at 12:01:32PM +0200, Heinrich Schuchardt wrote:
> > > > > On 12.05.21 10:01, Ilias Apalodimas wrote:
> > > > > > On Wed, May 12, 2021 at 04:49:02PM +0900, Masami Hiramatsu wrote:
> > > > > > > Hi Ilias,
> > > > > > > 
> > > > > > > 2021年5月12日(水) 16:21 Ilias Apalodimas 
> > > > > > > :
> > > > > > > > 
> > > > > > > > Akashi-san,
> > > > > > > > 
> > > > > > > > On Wed, May 12, 2021 at 01:57:51PM +0900, AKASHI Takahiro wrote:
> > > > > > > > > As we discussed, "-K" and "-D" options have nothing to do with
> > > > > > > > > creating a capsule file. The same result can be obtained by
> > > > > > > > > using standard commands like:
> > > > > > > > > === signature.dts ===
> > > > > > > > > /dts-v1/;
> > > > > > > > > /plugin/;
> > > > > > > > > 
> > > > > > > > > &{/} {
> > > > > > > > >   signature {
> > > > > > > > >   capsule-key = /incbin/("SIGNER.esl");
> > > > > > > > >   };
> > > > > > > > > };
> > > > > > > > > ===
> > > > > > > > > $ dtc -@ -I dts -O dtb -o signature.dtbo signature.dts
> > > > > > > > > $ fdtoverlay -i test.dtb -o test_sig.dtb -v signature.dtbo
> > > > > > > > > 
> > > > > > > > > So just remove this feature.
> > > > > > > > > (Effectively revert the commit 322c813f4bec ("mkeficapsule: 
> > > > > > > > > Add support
> > > > > > > > > for embedding public key in a dtb").)
> > > > > > > > > 
> > > > > > > > > The same feature is implemented by a shell script 
> > > > > > > > > (tools/fdtsig.sh).
> > > > > > > > 
> > > > > > > > 
> > > > > > > > The only reason I can see to keep this, is if mkeficapsule gets 
> > > > > > > > included
> > > > > > > > intro distro packages in the future.  That would make end users 
> > > > > > > > life a bit
> > > > > > > > easier, since they would need a single binary to create the 
> > > > > > > > whole
> > > > > > > > CapsuleUpdate sequence.
> > > > > > > 
> > > > > > > Hmm, I think it is better to write a manpage of mkeficapsule which
> > > > > > > also describes
> > > > > > > how to embed the key into dtb as in the above example if it is so 
> > > > > > > short.
> > > > > > > Or, distros can package the above shell script with mkeficapsule.
> > > > > > > 
> > > > > > > Embedding a key and signing a capsule are different operations but
> > > > > > > using the same tool may confuse users (at least me).
> > > > > > 
> > > > > > Sure fair enough.  I am merely pointing out we need a way to 
> > > > > > explain all of
> > > > > > those to users.
> > > > > 
> > > > > This is currently our only documentation:
> > > > > 
> > > > > https://u-boot.readthedocs.io/en/latest/board/emulation/qemu_capsule_update.html?highlight=mkeficapsule
> > > > 
> > > > As I mentioned several times (and TODO in the cover letter),
> > > > this text must be reviewed, revised and generalized
> > > > as a platform-independent document.
> > > > It contains a couple of errors.
> > > > 
> > > > > For mkimage we have a man-page ./doc/mkimage.1 that is packaged with
> > > > > Debians u-boot-tools package. Please, provide a similar man-page as
> > > > > ./doc/mkeficapsule.1.
> > > > 
> > > > So after all do you agree to removing "-K/-D"?

Regarding (1), you should clarify your opinion here first.

> > > I see no need to replicate in U-Boot what is already in the device tree
> > > compiler package.
> > 
> > This is another reason that we should remove Sughosh's change.

Hereafter, you are talking about (2).

> > > In the current workflow the fdt command is used to load the public key.
> > > This is insecure and not usable for production.
> > 
> > I totally disagree.
> > Why is using fdt command (what do you mean by fdt command, dtc/fdtoverlay?)
> > insecure?
> 
> A user can load an insecure capsule.
> 
> The fdt command is in /cmd/fdt.c and you are referring to it in
> board/emulation/qemu_capsule_update.rst.

OK, you meant U-Boot's fdt command.

> > 
> > > The public key used to verify the capsule must be built into the U-Boot
> > > binary. This will supplant the -K and -D options.
> > 
> > I don't get your point. You don't understand my code.
> > 
> > Even with Sughosh's original patch, the public key (as I said,
> > it is not a public key but a X509 certificate in ESL format) is
> > embedded in the U-Boot's "control device tree".
> 
> No, the ESL file it is not built into U-Boot's control device tree.

What I meant by "control device tree" is the feature
provided by OF_CONTROL+OF_EMBED with Sughosh's patch[1]
which is also a prerequisite for my patch 

[PATCH v2 16/16] RFC: clk: Return error code from clk_set_default_get_by_id()

2021-05-13 Thread Simon Glass
At present the error code is never returned. Fix it.

With this change, the following error is produced:

   test/dm/clk.c:50, dm_test_clk():
  0 == uclass_get_device_by_name(UCLASS_CLK, "clk-sbox", _clk):
  Expected 0x0 (0), got 0xfffe (-2)
   Test: dm_test_clk: clk.c (flat tree)
   test/dm/clk.c:50, dm_test_clk():
  0 == uclass_get_device_by_name(UCLASS_CLK, "clk-sbox", _clk):
  Expected 0x0 (0), got 0xfffe (-2)

Also this causes a crash in sandbox:

   Test: dm_test_clk: clk.c

   Program received signal SIGSEGV, Segmentation fault.
   sandbox_clk_query_enable (dev=, id=id@entry=0)
   at drivers/clk/clk_sandbox.c:164
   164  return priv->enabled[id];
   (gdb) q

A few other tests fail also, as marked.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 312946)
---

Changes in v2:
- Disable dm_test_simple_pm_bus() also, since it fails
- Drop patch: sandbox: Indicate NULL-pointer access in 'sigsegv' command

 drivers/clk/clk-uclass.c | 2 +-
 test/dm/clk.c| 9 +
 test/dm/simple-pm-bus.c  | 4 
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 2a2e1cfbd61..c6bf2a36645 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -199,7 +199,7 @@ static struct clk *clk_set_default_get_by_id(struct clk 
*clk)
if (ret) {
debug("%s(): could not get parent clock pointer, id 
%lu\n",
  __func__, clk->id);
-   ERR_PTR(ret);
+   return ERR_PTR(ret);
}
}
 
diff --git a/test/dm/clk.c b/test/dm/clk.c
index 21997ed8922..0d964fe1930 100644
--- a/test/dm/clk.c
+++ b/test/dm/clk.c
@@ -25,6 +25,9 @@ static int dm_test_clk_base(struct unit_test_state *uts)
/* Get the device using the clk device */
ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test", ));
 
+   /* TODO: Avoid failure */
+   return 0;
+
/* Get the same clk port in 2 different ways and compare */
ut_assertok(clk_get_by_index(dev, 1, _method1));
ut_assertok(clk_get_by_index_nodev(dev_ofnode(dev), 1, _method2));
@@ -47,6 +50,9 @@ static int dm_test_clk(struct unit_test_state *uts)
ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-fixed-factor",
  _fixed_factor));
 
+   /* TODO: Avoid crash */
+   return 0;
+
ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox",
  _clk));
ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
@@ -189,6 +195,9 @@ static int dm_test_clk_bulk(struct unit_test_state *uts)
 {
struct udevice *dev_clk, *dev_test;
 
+   /* TODO: Avoid failure */
+   return 0;
+
ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox",
  _clk));
ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test",
diff --git a/test/dm/simple-pm-bus.c b/test/dm/simple-pm-bus.c
index 792c7450580..da0f1d66216 100644
--- a/test/dm/simple-pm-bus.c
+++ b/test/dm/simple-pm-bus.c
@@ -23,6 +23,10 @@ static int dm_test_simple_pm_bus(struct unit_test_state *uts)
 
ut_assertok(uclass_get_device_by_name(UCLASS_POWER_DOMAIN,
  "power-domain", ));
+
+   /* TODO: Avoid failure */
+   return 0;
+
ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox",
  ));
ut_asserteq(0, sandbox_power_domain_query(power, TEST_POWER_ID));
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 14/16] sandbox: Silence coverity warning in state_read_file()

2021-05-13 Thread Simon Glass
In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 165109)
---

Changes in v2:
- Add a standard comment instead of a Coverity annotation

 arch/sandbox/cpu/state.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c
index f63cfd38ee4..a4d99bade41 100644
--- a/arch/sandbox/cpu/state.c
+++ b/arch/sandbox/cpu/state.c
@@ -78,6 +78,10 @@ static int state_read_file(struct sandbox_state *state, 
const char *fname)
 err_read:
os_close(fd);
 err_open:
+   /*
+* tainted scalar, since size is obtained from the file. But we can rely
+* on os_malloc() to handle invalid values.
+*/
os_free(state->state_fdt);
state->state_fdt = NULL;
 
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 15/16] clk: Detect failure to set defaults

2021-05-13 Thread Simon Glass
When the default clocks cannot be set, the clock is silently probed and
the error is ignored. This is incorrect, since having the clocks at the
correct speed may be important for operation of the system.

Fix it by checking the return code.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/clk/clk-uclass.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 4ab3c402ed8..2a2e1cfbd61 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -796,13 +796,17 @@ void devm_clk_put(struct udevice *dev, struct clk *clk)
 
 int clk_uclass_post_probe(struct udevice *dev)
 {
+   int ret;
+
/*
 * when a clock provider is probed. Call clk_set_defaults()
 * also after the device is probed. This takes care of cases
 * where the DT is used to setup default parents and rates
 * using assigned-clocks
 */
-   clk_set_defaults(dev, 1);
+   ret = clk_set_defaults(dev, 1);
+   if (ret)
+   return log_ret(ret);
 
return 0;
 }
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 12/16] pinctrl: Avoid coverity warning when checking width

2021-05-13 Thread Simon Glass
The width is set up in single_of_to_plat() and can only have three values,
all of which result in a non-zero divisor. Add a comment.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 331154)
---

Changes in v2:
- Add a standard comment instead of a Coverity annotation

 drivers/pinctrl/pinctrl-single.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index ebb7602dde8..d95722c5104 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -471,6 +471,7 @@ static int single_probe(struct udevice *dev)
return -ENOMEM;
#endif
 
+   /* looks like a possible divide by 0, but data->width avoids this */
priv->npins = size / (pdata->width / BITS_PER_BYTE);
if (pdata->bits_per_mux) {
if (!pdata->mask) {
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 13/16] tpm: Check outgoing command size

2021-05-13 Thread Simon Glass
In tpm_sendrecv_command() the command buffer is passed in. If a mistake is
somehow made in setting this up, the size could be out of range. Add a
sanity check for this.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 331152)
---

(no changes since v1)

 lib/tpm-common.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/lib/tpm-common.c b/lib/tpm-common.c
index 4277846fdd0..82ffdc5341b 100644
--- a/lib/tpm-common.c
+++ b/lib/tpm-common.c
@@ -176,6 +176,11 @@ u32 tpm_sendrecv_command(struct udevice *dev, const void 
*command,
}
 
size = tpm_command_size(command);
+
+   /* sanity check, which also helps coverity */
+   if (size > COMMAND_BUFFER_SIZE)
+   return log_msg_ret("size", -E2BIG);
+
log_debug("TPM request [size:%d]: ", size);
for (i = 0; i < size; i++)
log_debug("%02x ", ((u8 *)command)[i]);
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 11/16] cbfs: Check offset range when reading a file

2021-05-13 Thread Simon Glass
Add a check that the offset is within the allowed range.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 331155)
---

(no changes since v1)

 fs/cbfs/cbfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c
index 415ea28b871..3e905c74e58 100644
--- a/fs/cbfs/cbfs.c
+++ b/fs/cbfs/cbfs.c
@@ -167,6 +167,8 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, void 
*start, int size,
}
 
swap_file_header(, file_header);
+   if (header.offset >= size)
+   return log_msg_ret("range", -E2BIG);
ret = fill_node(node, start, );
if (ret) {
priv->result = CBFS_BAD_FILE;
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 08/16] dm: core: Check uclass_get() return value when dumping

2021-05-13 Thread Simon Glass
Update dm_dump_drivers() to use the return value from uclass_get() to
check the validity of uc. This is equivalent and should be more attractive
to Coverity.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 316601)
---

(no changes since v1)

 drivers/core/dump.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index f8afea30a93..f2f9cacc56c 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -130,18 +130,19 @@ void dm_dump_drivers(void)
struct driver *entry;
struct udevice *udev;
struct uclass *uc;
+   int ret;
int i;
 
puts("Driveruid uclass   Devices\n");
puts("--\n");
 
for (entry = d; entry < d + n_ents; entry++) {
-   uclass_get(entry->id, );
+   ret = uclass_get(entry->id, );
 
printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
-  uc ? uc->uc_drv->name : "");
+  !ret ? uc->uc_drv->name : "");
 
-   if (!uc) {
+   if (ret) {
puts("\n");
continue;
}
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 10/16] sandbox: cros_ec: Update error handling when reading matrix

2021-05-13 Thread Simon Glass
At present the return value of ofnode_get_property() is not checked, which
causes a coverity warning. While we are here, use logging for the errors.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 331157)
---

(no changes since v1)

 drivers/misc/cros_ec_sandbox.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c
index bc01df0904e..1cb5494f4f4 100644
--- a/drivers/misc/cros_ec_sandbox.c
+++ b/drivers/misc/cros_ec_sandbox.c
@@ -5,6 +5,8 @@
  * Copyright (c) 2013 The Chromium OS Authors.
  */
 
+#define LOG_CATEGORY UCLASS_CROS_EC
+
 #include 
 #include 
 #include 
@@ -214,11 +216,12 @@ static int keyscan_read_fdt_matrix(struct ec_state *ec, 
ofnode node)
int len;
 
cell = ofnode_get_property(node, "linux,keymap", );
+   if (!cell)
+   return log_msg_ret("prop", -EINVAL);
ec->matrix_count = len / 4;
ec->matrix = calloc(ec->matrix_count, sizeof(*ec->matrix));
if (!ec->matrix) {
-   debug("%s: Out of memory for key matrix\n", __func__);
-   return -1;
+   return log_msg_ret("mem", -ENOMEM);
}
 
/* Now read the data */
@@ -236,13 +239,12 @@ static int keyscan_read_fdt_matrix(struct ec_state *ec, 
ofnode node)
matrix->col >= KEYBOARD_COLS) {
debug("%s: Matrix pos out of range (%d,%d)\n",
  __func__, matrix->row, matrix->col);
-   return -1;
+   return log_msg_ret("matrix", -ERANGE);
}
}
 
if (upto != ec->matrix_count) {
-   debug("%s: Read mismatch from key matrix\n", __func__);
-   return -1;
+   return log_msg_ret("matrix", -E2BIG);
}
 
return 0;
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 09/16] sandbox: scmi: Indicate dead code for coverity

2021-05-13 Thread Simon Glass
This code is not used due to the value of SCMI_TEST_DEVICES_RD_COUNT.
However, it might increase one day. Add a comment.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 312942)
---

Changes in v2:
- Add a standard comment instead of a Coverity annotation

 drivers/firmware/scmi/sandbox-scmi_devices.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/firmware/scmi/sandbox-scmi_devices.c 
b/drivers/firmware/scmi/sandbox-scmi_devices.c
index 66a67928817..fc2dad69c97 100644
--- a/drivers/firmware/scmi/sandbox-scmi_devices.c
+++ b/drivers/firmware/scmi/sandbox-scmi_devices.c
@@ -121,6 +121,7 @@ err_regul:
n = SCMI_TEST_DEVICES_RD_COUNT;
 err_reset:
for (; n > 0; n--)
+   /* dead code, if SCMI_TEST_DEVICES_RD_COUNT < 2 */
reset_free(priv->devices.reset + n - 1);
 
return ret;
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 04/16] tools: Avoid showing return value of clock_gettime()

2021-05-13 Thread Simon Glass
This value is either 0 for success or -1 for error. Coverity reports that
"ret" is passed to a parameter that cannot be negative, pointing to the
condition 'if (ret < 0)'.

Adjust it to just check for non-zero and avoid showing -1 in the error
message, which is pointless. Perhaps these changes will molify Coverity.

Reported-by: Coverity (CID: 312956)
Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/image-host.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/image-host.c b/tools/image-host.c
index 270d36fe451..be7066d9433 100644
--- a/tools/image-host.c
+++ b/tools/image-host.c
@@ -327,7 +327,7 @@ static int get_random_data(void *data, int size)
 {
unsigned char *tmp = data;
struct timespec date;
-   int i, ret = 0;
+   int i, ret;
 
if (!tmp) {
printf("%s: pointer data is NULL\n", __func__);
@@ -336,9 +336,9 @@ static int get_random_data(void *data, int size)
}
 
ret = clock_gettime(CLOCK_MONOTONIC, );
-   if (ret < 0) {
-   printf("%s: clock_gettime has failed (err=%d, str=%s)\n",
-  __func__, ret, strerror(errno));
+   if (ret) {
+   printf("%s: clock_gettime has failed (%s)\n", __func__,
+  strerror(errno));
goto out;
}
 
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 07/16] test: Avoid random numbers in dm_test_devm_regmap()

2021-05-13 Thread Simon Glass
There is no good reason to use a sequence from rand() here. We may as well
invent our own sequence.

This should molify Coverity which does not use rand() being used.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 312949)
---

(no changes since v1)

 test/dm/regmap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/test/dm/regmap.c b/test/dm/regmap.c
index 372a73ca0c3..04bb1645d1b 100644
--- a/test/dm/regmap.c
+++ b/test/dm/regmap.c
@@ -306,9 +306,8 @@ static int dm_test_devm_regmap(struct unit_test_state *uts)
  ));
priv = dev_get_priv(dev);
 
-   srand(get_ticks() + rand());
for (i = 0; i < REGMAP_TEST_BUF_SZ; i++) {
-   pattern[i] = rand();
+   pattern[i] = i * 0x87654321;
ut_assertok(regmap_write(priv->cfg_regmap, i, pattern[i]));
}
for (i = 0; i < REGMAP_TEST_BUF_SZ; i++) {
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 03/16] test: Rename final check in setexpr_test_backref()

2021-05-13 Thread Simon Glass
The bug in setexpr is fixed now, so this test can be enabled.

Reported-by: Coverity (CID: 316346)

Signed-off-by: Simon Glass 
---

(no changes since v1)

 test/cmd/setexpr.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c
index c537e893538..08b6e6e7243 100644
--- a/test/cmd/setexpr.c
+++ b/test/cmd/setexpr.c
@@ -270,8 +270,6 @@ static int setexpr_test_backref(struct unit_test_state *uts)
ut_asserteq_str("us this is surely! a test is it? yes us this is 
indeed! a test",
buf);
 
-   /* The following checks fail at present due to a bug in setexpr */
-   return 0;
for (i = BUF_SIZE; i < 0x1000; i++) {
ut_assertf(buf[i] == (char)i,
   "buf byte at %x should be %02x, got %02x)\n",
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 06/16] reset: Avoid a warning in devm_regmap_init()

2021-05-13 Thread Simon Glass
The devres_alloc() function is intended to avoid the need for freeing
memory, although in practice it may not be enabled, thus leading to a true
leak.

Nevertheless this is intended. Add a comment.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 312951)
---

Changes in v2:
- Add a standard comment instead of a Coverity annotation

 drivers/core/regmap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index b51ce108c14..982c2ee9fab 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -293,6 +293,7 @@ struct regmap *devm_regmap_init(struct udevice *dev,
int rc;
struct regmap **mapp, *map;
 
+   /* this looks like a leak, but devres takes care of it */
mapp = devres_alloc(devm_regmap_release, sizeof(struct regmap *),
__GFP_ZERO);
if (unlikely(!mapp))
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 05/16] reset: Avoid a warning in devm_reset_bulk_get_by_node()

2021-05-13 Thread Simon Glass
The devres_alloc() function is intended to avoid the need for freeing
memory, although in practice it may not be enabled, thus leading to a true
leak.

Nevertheless this is intended. Add a comment to explain this.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 312952)
---

Changes in v2:
- Add a standard comment instead of a Coverity annotation

 drivers/reset/reset-uclass.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
index ac89eaf098a..a3a088d1b5c 100644
--- a/drivers/reset/reset-uclass.c
+++ b/drivers/reset/reset-uclass.c
@@ -323,6 +323,8 @@ struct reset_ctl_bulk *devm_reset_bulk_get_by_node(struct 
udevice *dev,
bulk = devres_alloc(devm_reset_bulk_release,
sizeof(struct reset_ctl_bulk),
__GFP_ZERO);
+
+   /* this looks like a leak, but devres takes care of it */
if (unlikely(!bulk))
return ERR_PTR(-ENOMEM);
 
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 01/16] sandbox: net: Ensure host name is always a valid string

2021-05-13 Thread Simon Glass
At present if ifname is exactly IFNAMSIZ characters then it will result
in an unterminated string. Fix this by using strlcpy() instead.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 316358)
---

Changes in v2:
- Put 'Reported-by:' after the sign-off

 drivers/net/sandbox-raw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/sandbox-raw.c b/drivers/net/sandbox-raw.c
index ce66ff781ff..99eb7a3bbff 100644
--- a/drivers/net/sandbox-raw.c
+++ b/drivers/net/sandbox-raw.c
@@ -161,7 +161,7 @@ static int sb_eth_raw_of_to_plat(struct udevice *dev)
 
ifname = dev_read_string(dev, "host-raw-interface");
if (ifname) {
-   strncpy(priv->host_ifname, ifname, IFNAMSIZ);
+   strlcpy(priv->host_ifname, ifname, IFNAMSIZ);
printf(": Using %s from DT\n", priv->host_ifname);
}
if (dev_read_u32(dev, "host-raw-interface-idx",
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH v2 02/16] video: Check return value in pwm_backlight_of_to_plat()

2021-05-13 Thread Simon Glass
This cannot actually fail, but check the value anyway to keep coverity
happy.

Signed-off-by: Simon Glass 
Reported-by: Coverity (CID: 316351)
---

(no changes since v1)

 drivers/video/pwm_backlight.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/video/pwm_backlight.c b/drivers/video/pwm_backlight.c
index 4c86215bd73..d7c096923b3 100644
--- a/drivers/video/pwm_backlight.c
+++ b/drivers/video/pwm_backlight.c
@@ -235,8 +235,10 @@ static int pwm_backlight_of_to_plat(struct udevice *dev)
priv->levels = malloc(len);
if (!priv->levels)
return log_ret(-ENOMEM);
-   dev_read_u32_array(dev, "brightness-levels", priv->levels,
-  count);
+   ret = dev_read_u32_array(dev, "brightness-levels", priv->levels,
+count);
+   if (ret)
+   return log_msg_ret("levels", ret);
priv->num_levels = count;
priv->default_level = priv->levels[index];
priv->max_level = priv->levels[count - 1];
-- 
2.31.1.751.gd2f1c929bd-goog



[PATCH 3/3] arm: dts: k3-am642-sk: Add sysreset controller node

2021-05-13 Thread Suman Anna
The AM64x SoC uses a central Device Management and Security Controller
(DMSC) processor that manages all the low-level device controls
including the system-wide SoC reset. The system-wide reset is managed
through the system reset driver.

Add a sysreset controller node as a child of the dmsc node to enable
the "reset" command from U-Boot prompt for the K3 AM642 SK.

Signed-off-by: Suman Anna 
---
 arch/arm/dts/k3-am642-sk-u-boot.dtsi | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/dts/k3-am642-sk-u-boot.dtsi 
b/arch/arm/dts/k3-am642-sk-u-boot.dtsi
index 4ac7f5db9135..35b49df85106 100644
--- a/arch/arm/dts/k3-am642-sk-u-boot.dtsi
+++ b/arch/arm/dts/k3-am642-sk-u-boot.dtsi
@@ -60,6 +60,10 @@
 
  {
u-boot,dm-spl;
+   k3_sysreset: sysreset-controller {
+   compatible = "ti,sci-sysreset";
+   u-boot,dm-spl;
+   };
 };
 
 _pds {
-- 
2.30.1



[PATCH 2/3] arm: dts: k3-am642-evm: Add sysreset controller node

2021-05-13 Thread Suman Anna
The AM64x SoC uses a central Device Management and Security Controller
(DMSC) processor that manages all the low-level device controls
including the system-wide SoC reset. The system-wide reset is managed
through the system reset driver.

Add a sysreset controller node as a child of the dmsc node to enable
the "reset" command from U-Boot prompt for the K3 AM642 EVM.

Signed-off-by: Suman Anna 
---
 arch/arm/dts/k3-am642-evm-u-boot.dtsi | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/dts/k3-am642-evm-u-boot.dtsi 
b/arch/arm/dts/k3-am642-evm-u-boot.dtsi
index 9b0ba6b721b3..10dea7a1cc46 100644
--- a/arch/arm/dts/k3-am642-evm-u-boot.dtsi
+++ b/arch/arm/dts/k3-am642-evm-u-boot.dtsi
@@ -60,6 +60,10 @@
 
  {
u-boot,dm-spl;
+   k3_sysreset: sysreset-controller {
+   compatible = "ti,sci-sysreset";
+   u-boot,dm-spl;
+   };
 };
 
 _pds {
-- 
2.30.1



[PATCH 1/3] firmware: ti_sci: Update ti_sci_msg_req_reboot to include domain

2021-05-13 Thread Suman Anna
From: Dave Gerlach 

The ti_sci_msg_req_reboot message payload has been extended to include a
domain field, but for the purposes of u-boot this should be zero to
reset the entire SoC as it did before. Include domain for completeness
and set to zero to ensure proper operation.

Signed-off-by: Dave Gerlach 
Signed-off-by: Suman Anna 
---
 drivers/firmware/ti_sci.c | 1 +
 drivers/firmware/ti_sci.h | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
index 2aec2e34d303..4671a5e3a8a6 100644
--- a/drivers/firmware/ti_sci.c
+++ b/drivers/firmware/ti_sci.c
@@ -1588,6 +1588,7 @@ static int ti_sci_cmd_core_reboot(const struct 
ti_sci_handle *handle)
dev_err(info->dev, "Message alloc failed(%d)\n", ret);
return ret;
}
+   req.domain = 0;
 
ret = ti_sci_do_xfer(info, xfer);
if (ret) {
diff --git a/drivers/firmware/ti_sci.h b/drivers/firmware/ti_sci.h
index eec488f06509..e4a087c2baf4 100644
--- a/drivers/firmware/ti_sci.h
+++ b/drivers/firmware/ti_sci.h
@@ -137,12 +137,14 @@ struct ti_sci_msg_resp_version {
 /**
  * struct ti_sci_msg_req_reboot - Reboot the SoC
  * @hdr:   Generic Header
+ * @domain:Domain to be reset, 0 for full SoC reboot.
  *
  * Request type is TI_SCI_MSG_SYS_RESET, responded with a generic
  * ACK/NACK message.
  */
 struct ti_sci_msg_req_reboot {
struct ti_sci_msg_hdr hdr;
+   u8 domain;
 } __packed;
 
 /**
-- 
2.30.1



[PATCH 0/3] Fix 'reset' for TI K3 AM64x and J721E/J7200 boards

2021-05-13 Thread Suman Anna
Hi Lokesh,

The following patches fix the 'reset' command functionality for various
TI K3 SoCs. Patches are based on the latest master that includes the
AM64x board support, commit ea184cbff99e ("Merge tag 'ti-v2021.07-rc3'
of https://source.denx.de/u-boot/custodians/u-boot-ti;).

The first patch is needed for J721E/J7200 SoCs with newer System
Firmwares (anything newer that 2020.04 SYSFW) and is backward
compatible. Without this, the 'reset' command throws the following
warnings,
  => reset
  resetting ...
  ti-sci-sysreset sysreset-controller: ti_sci_sysreset_request: reboot_device 
failed (-19)
  ti-sci-sysreset sysreset-controller: ti_sci_sysreset_request: reboot_device 
failed (-19)
  ti-sci-sysreset sysreset-controller: ti_sci_sysreset_request: reboot_device 
failed (-19)
  System reset not supported on this platform
  ### ERROR ### Please RESET the board ###

The second and third patches add the required ti-sci sysreset nodes
for the AM64x EVM and SK boards respectively. The required SYSRESET
and SYSRESET_TI_SCI configs are already enabled in the
am64x_evm_a53_defconfig.

regards
Suman

Dave Gerlach (1):
  firmware: ti_sci: Update ti_sci_msg_req_reboot to include domain

Suman Anna (2):
  arm: dts: k3-am642-evm: Add sysreset controller node
  arm: dts: k3-am642-sk: Add sysreset controller node

 arch/arm/dts/k3-am642-evm-u-boot.dtsi | 4 
 arch/arm/dts/k3-am642-sk-u-boot.dtsi  | 4 
 drivers/firmware/ti_sci.c | 1 +
 drivers/firmware/ti_sci.h | 2 ++
 4 files changed, 11 insertions(+)

-- 
2.30.1



Re: [PATCH 1/1] sandbox: add symbol _init for RISC-V compilation

2021-05-13 Thread Bin Meng
On Fri, May 14, 2021 at 7:56 AM Simon Glass  wrote:
>
> Hi Heinrich,
>
> On Thu, 13 May 2021 at 08:46, Heinrich Schuchardt  wrote:
> >
> > The sandbox does not build on RISC-V when _init is not defined. Errors like
> > the following were observed. Which function was referred to depended on the
> > configuration.
> >
> > /usr/bin/ld: common/built-in.o: in function `parse_stream_outer':
> > /common/cli_hush.c:3175: undefined reference to `_init'
> > collect2: error: ld returned 1 exit status
> > make: *** [Makefile:1726: u-boot] Error 1
> >
> > /usr/bin/ld: common/built-in.o: in function `bootdelay_process':
> > common/autoboot.c:335: undefined reference to `_init'
> > collect2: error: ld returned 1 exit status
> > make: *** [Makefile:1726: u-boot] Error 1
> >
> > Signed-off-by: Heinrich Schuchardt 
> > ---
> >  arch/sandbox/cpu/u-boot.lds | 2 ++
> >  1 file changed, 2 insertions(+)
>
> Is this a toolchain bug?

+Jim who might know.

>
> Reviewed-by: Simon Glass 
>
>
> >
> > diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds
> > index a1f509c9ab..d9e7ffcea3 100644
> > --- a/arch/sandbox/cpu/u-boot.lds
> > +++ b/arch/sandbox/cpu/u-boot.lds
> > @@ -9,6 +9,8 @@ SECTIONS
> >  {
> >
> > . = ALIGN(4);
> > +   /* RISC-V GCC wants this dummy symbol */
> > +   _init = .;
> > .u_boot_list : {
> > KEEP(*(SORT(.u_boot_list*)));
> > }

Regards,
Bin


[PATCH v8 3/3] efi_loader: add PE/COFF image measurement

2021-05-13 Thread Masahisa Kojima
"TCG PC Client Platform Firmware Profile Specification"
requires to measure every attempt to load and execute
a OS Loader(a UEFI application) into PCR[4].
This commit adds the PE/COFF image measurement, extends PCR,
and appends measurement into Event Log.

Acked-by: Ilias Apalodimas 
Tested-by: Ilias Apalodimas 
Signed-off-by: Masahisa Kojima 
---

(no changes since v7)

Changes in v7:
- include hash-checksum.h instead of rsa.h
- select HASH_CALCULATE in Kconfig, not to update lib/Makefile
- rebased the base code

Changes in v6:
- update lib/Makefile to add hash-checksum.c as a compilation target

(no changes since v2)

Changes in v2:
- Remove duplicate  include
- Remove unnecessary __packed attribute
- Add all EV_EFI_* event definition
- Create common function to prepare 8-byte aligned image
- Add measurement for EV_EFI_BOOT_SERVICES_DRIVER and
  EV_EFI_RUNTIME_SERVICES_DRIVER
- Use efi_search_protocol() to get device_path
- Add function comment

 include/efi_loader.h  |   6 +
 include/efi_tcg2.h|   9 ++
 include/tpm-v2.h  |  18 +++
 lib/efi_loader/Kconfig|   1 +
 lib/efi_loader/efi_image_loader.c |  59 +++--
 lib/efi_loader/efi_tcg2.c | 207 --
 6 files changed, 276 insertions(+), 24 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index de1a496a97..9f2854a255 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -426,6 +426,10 @@ efi_status_t efi_disk_register(void);
 efi_status_t efi_rng_register(void);
 /* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */
 efi_status_t efi_tcg2_register(void);
+/* measure the pe-coff image, extend PCR and add Event Log */
+efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size,
+  struct efi_loaded_image_obj *handle,
+  struct efi_loaded_image *loaded_image_info);
 /* Create handles and protocols for the partitions of a block device */
 int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
   const char *if_typename, int diskid,
@@ -847,6 +851,8 @@ bool efi_secure_boot_enabled(void);
 
 bool efi_capsule_auth_enabled(void);
 
+void *efi_prepare_aligned_image(void *efi, u64 *efi_size, void **new_efi);
+
 bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
 WIN_CERTIFICATE **auth, size_t *auth_len);
 
diff --git a/include/efi_tcg2.h b/include/efi_tcg2.h
index 40e241ce31..bcfb98168a 100644
--- a/include/efi_tcg2.h
+++ b/include/efi_tcg2.h
@@ -9,6 +9,7 @@
 #if !defined _EFI_TCG2_PROTOCOL_H_
 #define _EFI_TCG2_PROTOCOL_H_
 
+#include 
 #include 
 
 #define EFI_TCG2_PROTOCOL_GUID \
@@ -53,6 +54,14 @@ struct efi_tcg2_event {
u8 event[];
 } __packed;
 
+struct uefi_image_load_event {
+   efi_physical_addr_t image_location_in_memory;
+   u64 image_length_in_memory;
+   u64 image_link_time_address;
+   u64 length_of_device_path;
+   struct efi_device_path device_path[];
+};
+
 struct efi_tcg2_boot_service_capability {
u8 size;
struct efi_tcg2_version structure_version;
diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index 7de7d6a57d..247b386967 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -70,6 +70,24 @@ struct udevice;
 #define EV_TABLE_OF_DEVICES((u32)0x000B)
 #define EV_COMPACT_HASH((u32)0x000C)
 
+/*
+ * event types, cf.
+ * "TCG PC Client Platform Firmware Profile Specification", Family "2.0"
+ * rev 1.04, June 3, 2019
+ */
+#define EV_EFI_EVENT_BASE  ((u32)0x8000)
+#define EV_EFI_VARIABLE_DRIVER_CONFIG  ((u32)0x8001)
+#define EV_EFI_VARIABLE_BOOT   ((u32)0x8002)
+#define EV_EFI_BOOT_SERVICES_APPLICATION   ((u32)0x8003)
+#define EV_EFI_BOOT_SERVICES_DRIVER((u32)0x8004)
+#define EV_EFI_RUNTIME_SERVICES_DRIVER ((u32)0x8005)
+#define EV_EFI_GPT_EVENT   ((u32)0x8006)
+#define EV_EFI_ACTION  ((u32)0x8007)
+#define EV_EFI_PLATFORM_FIRMWARE_BLOB  ((u32)0x8008)
+#define EV_EFI_HANDOFF_TABLES  ((u32)0x8009)
+#define EV_EFI_HCRTM_EVENT ((u32)0x8010)
+#define EV_EFI_VARIABLE_AUTHORITY  ((u32)0x80E0)
+
 /* TPMS_TAGGED_PROPERTY Structure */
 struct tpms_tagged_property {
u32 property;
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 98845b8ba3..0e6200fa25 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -309,6 +309,7 @@ config EFI_TCG2_PROTOCOL
select SHA512_ALGO
select SHA384
select SHA512
+   select HASH_CALCULATE
help
  Provide a EFI_TCG2_PROTOCOL implementation using the TPM hardware
  of the platform.
diff --git a/lib/efi_loader/efi_image_loader.c 

[PATCH v8 2/3] efi_loader: expose efi_image_parse() even if UEFI Secure Boot is disabled

2021-05-13 Thread Masahisa Kojima
This is preparation for PE/COFF measurement support.
PE/COFF image hash calculation is same in both
UEFI Secure Boot image verification and measurement in
measured boot. PE/COFF image parsing functions are
gathered into efi_image_loader.c, and exposed even if
UEFI Secure Boot is not enabled.

This commit also adds the EFI_SIGNATURE_SUPPORT option
to decide if efi_signature.c shall be compiled.

Signed-off-by: Masahisa Kojima 
---

Changes in v8:
- remove superfluous "depends on" in Kconfig

(no changes since v4)

Changes in v4:
- revert #ifdef instead of using "if (!IS_ENABLED())" statement,
  not to rely on the compiler optimization.

Changes in v3:
- hide EFI_SIGNATURE_SUPPORT option

Changes in v2:
- Remove all #ifdef from efi_image_loader.c and efi_signature.c
- Add EFI_SIGNATURE_SUPPORT option
- Explicitly include 
- Gather PE/COFF parsing functions into efi_image_loader.c
- Move efi_guid_t efi_guid_image_security_database in efi_var_common.c

 lib/efi_loader/Kconfig|  5 +++
 lib/efi_loader/Makefile   |  2 +-
 lib/efi_loader/efi_image_loader.c | 64 -
 lib/efi_loader/efi_signature.c| 67 +--
 lib/efi_loader/efi_var_common.c   |  3 ++
 5 files changed, 73 insertions(+), 68 deletions(-)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index eb5c4d6f29..98845b8ba3 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -175,6 +175,7 @@ config EFI_CAPSULE_AUTHENTICATE
select PKCS7_VERIFY
select IMAGE_SIGN_INFO
select HASH_CALCULATE
+   select EFI_SIGNATURE_SUPPORT
default n
help
  Select this option if you want to enable capsule
@@ -344,6 +345,7 @@ config EFI_SECURE_BOOT
select PKCS7_MESSAGE_PARSER
select PKCS7_VERIFY
select HASH_CALCULATE
+   select EFI_SIGNATURE_SUPPORT
default n
help
  Select this option to enable EFI secure boot support.
@@ -351,6 +353,9 @@ config EFI_SECURE_BOOT
  it is signed with a trusted key. To do that, you need to install,
  at least, PK, KEK and db.
 
+config EFI_SIGNATURE_SUPPORT
+   bool
+
 config EFI_ESRT
bool "Enable the UEFI ESRT generation"
depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 8bd343e258..fd344cea29 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -63,7 +63,7 @@ obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o
 obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o
 obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o
 obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o
-obj-y += efi_signature.o
+obj-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o
 
 EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE))
 $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE)
diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index f53ef367ec..fe1ee198e2 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -213,7 +213,68 @@ static void efi_set_code_and_data_type(
}
 }
 
-#ifdef CONFIG_EFI_SECURE_BOOT
+/**
+ * efi_image_region_add() - add an entry of region
+ * @regs:  Pointer to array of regions
+ * @start: Start address of region (included)
+ * @end:   End address of region (excluded)
+ * @nocheck:   flag against overlapped regions
+ *
+ * Take one entry of region [@start, @end[ and insert it into the list.
+ *
+ * * If @nocheck is false, the list will be sorted ascending by address.
+ *   Overlapping entries will not be allowed.
+ *
+ * * If @nocheck is true, the list will be sorted ascending by sequence
+ *   of adding the entries. Overlapping is allowed.
+ *
+ * Return: status code
+ */
+efi_status_t efi_image_region_add(struct efi_image_regions *regs,
+ const void *start, const void *end,
+ int nocheck)
+{
+   struct image_region *reg;
+   int i, j;
+
+   if (regs->num >= regs->max) {
+   EFI_PRINT("%s: no more room for regions\n", __func__);
+   return EFI_OUT_OF_RESOURCES;
+   }
+
+   if (end < start)
+   return EFI_INVALID_PARAMETER;
+
+   for (i = 0; i < regs->num; i++) {
+   reg = >reg[i];
+   if (nocheck)
+   continue;
+
+   /* new data after registered region */
+   if (start >= reg->data + reg->size)
+   continue;
+
+   /* new data preceding registered region */
+   if (end <= reg->data) {
+   for (j = regs->num - 1; j >= i; j--)
+   memcpy(>reg[j + 1], >reg[j],
+  sizeof(*reg));
+   break;
+   }
+
+   /* new data overlapping registered region */
+   EFI_PRINT("%s: new region 

[PATCH v8 1/3] lib: introduce HASH_CALCULATE option

2021-05-13 Thread Masahisa Kojima
Build error occurs when CONFIG_EFI_SECURE_BOOT or
CONFIG_EFI_CAPSULE_AUTHENTICATE is enabled,
because hash-checksum.c is not compiled.

Since hash_calculate() implemented in hash-checksum.c can be
commonly used aside from FIT image signature verification,
this commit itroduces HASH_CALCULATE option to decide
if hash-checksum.c shall be compiled.

Signed-off-by: Masahisa Kojima 
---

(no changes since v7)

Changes in v7:
- newly introduce HASH_CALCULATE option

Changes in v6:
- update lib/Makefile to compile hash-checksum.c, instead of
  selecting FIT_SIGNATURE in secure boot and capsule authentication.

Changes in v5:
- Missing option for EFI_TCG2_PROTOROL already added in different commit.
  This commit adds FIT_SIGNATURE only.

Changes in v4:
- newly added in this patch series, due to rebasing
  the base code.

 common/Kconfig.boot| 1 +
 lib/Kconfig| 3 +++
 lib/Makefile   | 2 +-
 lib/efi_loader/Kconfig | 2 ++
 4 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/common/Kconfig.boot b/common/Kconfig.boot
index 5a18d62d78..56608226cc 100644
--- a/common/Kconfig.boot
+++ b/common/Kconfig.boot
@@ -80,6 +80,7 @@ config FIT_SIGNATURE
select RSA_VERIFY
select IMAGE_SIGN_INFO
select FIT_FULL_CHECK
+   select HASH_CALCULATE
help
  This option enables signature verification of FIT uImages,
  using a hash signed and verified using RSA. If
diff --git a/lib/Kconfig b/lib/Kconfig
index 6d2d41de30..df67eb0503 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -428,6 +428,9 @@ config CRC32C
 config XXHASH
bool
 
+config HASH_CALCULATE
+   bool
+
 endmenu
 
 menu "Compression Support"
diff --git a/lib/Makefile b/lib/Makefile
index 6825671955..0835ea292c 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -61,7 +61,7 @@ endif
 obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi/
 obj-$(CONFIG_$(SPL_)MD5) += md5.o
 obj-$(CONFIG_$(SPL_)RSA) += rsa/
-obj-$(CONFIG_FIT_SIGNATURE) += hash-checksum.o
+obj-$(CONFIG_HASH_CALCULATE) += hash-checksum.o
 obj-$(CONFIG_SHA1) += sha1.o
 obj-$(CONFIG_SHA256) += sha256.o
 obj-$(CONFIG_SHA512_ALGO) += sha512.o
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index c259abe033..eb5c4d6f29 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -174,6 +174,7 @@ config EFI_CAPSULE_AUTHENTICATE
select PKCS7_MESSAGE_PARSER
select PKCS7_VERIFY
select IMAGE_SIGN_INFO
+   select HASH_CALCULATE
default n
help
  Select this option if you want to enable capsule
@@ -342,6 +343,7 @@ config EFI_SECURE_BOOT
select X509_CERTIFICATE_PARSER
select PKCS7_MESSAGE_PARSER
select PKCS7_VERIFY
+   select HASH_CALCULATE
default n
help
  Select this option to enable EFI secure boot support.
-- 
2.17.1



[PATCH v8 0/3] PE/COFF measurement support

2021-05-13 Thread Masahisa Kojima
This patch series add the PE/COFF measurement support.
Extending PCR and Event Log is tested with fTPM
running as a OP-TEE TA.
Unit test will be added in the separate series.

Masahisa Kojima (3):
  lib: introduce HASH_CALCULATE option
  efi_loader: expose efi_image_parse() even if UEFI Secure Boot is
disabled
  efi_loader: add PE/COFF image measurement

 common/Kconfig.boot   |   1 +
 include/efi_loader.h  |   6 +
 include/efi_tcg2.h|   9 ++
 include/tpm-v2.h  |  18 +++
 lib/Kconfig   |   3 +
 lib/Makefile  |   2 +-
 lib/efi_loader/Kconfig|   8 ++
 lib/efi_loader/Makefile   |   2 +-
 lib/efi_loader/efi_image_loader.c | 123 +++---
 lib/efi_loader/efi_signature.c|  67 +-
 lib/efi_loader/efi_tcg2.c | 207 --
 lib/efi_loader/efi_var_common.c   |   3 +
 12 files changed, 356 insertions(+), 93 deletions(-)

-- 
2.17.1



Re: [PATCH v7 2/3] efi_loader: expose efi_image_parse() even if UEFI Secure Boot is disabled

2021-05-13 Thread Masahisa Kojima
On Fri, 14 May 2021 at 00:33, Heinrich Schuchardt  wrote:
>
> On 5/13/21 4:48 PM, Masahisa Kojima wrote:
> > This is preparation for PE/COFF measurement support.
> > PE/COFF image hash calculation is same in both
> > UEFI Secure Boot image verification and measurement in
> > measured boot. PE/COFF image parsing functions are
> > gathered into efi_image_loader.c, and exposed even if
> > UEFI Secure Boot is not enabled.
> >
> > This commit also adds the EFI_SIGNATURE_SUPPORT option
> > to decide if efi_signature.c shall be compiled.
> >
> > Signed-off-by: Masahisa Kojima 
> > ---
> >
> > (no changes since v4)
> >
> > Changes in v4:
> > - revert #ifdef instead of using "if (!IS_ENABLED())" statement,
> >not to rely on the compiler optimization.
> >
> > Changes in v3:
> > - hide EFI_SIGNATURE_SUPPORT option
> >
> > Changes in v2:
> > - Remove all #ifdef from efi_image_loader.c and efi_signature.c
> > - Add EFI_SIGNATURE_SUPPORT option
> > - Explicitly include 
> > - Gather PE/COFF parsing functions into efi_image_loader.c
> > - Move efi_guid_t efi_guid_image_security_database in efi_var_common.c
> >
> >   lib/efi_loader/Kconfig|  6 +++
> >   lib/efi_loader/Makefile   |  2 +-
> >   lib/efi_loader/efi_image_loader.c | 64 -
> >   lib/efi_loader/efi_signature.c| 67 +--
> >   lib/efi_loader/efi_var_common.c   |  3 ++
> >   5 files changed, 74 insertions(+), 68 deletions(-)
> >
> > diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
> > index eb5c4d6f29..dff85cea26 100644
> > --- a/lib/efi_loader/Kconfig
> > +++ b/lib/efi_loader/Kconfig
> > @@ -175,6 +175,7 @@ config EFI_CAPSULE_AUTHENTICATE
> >   select PKCS7_VERIFY
> >   select IMAGE_SIGN_INFO
> >   select HASH_CALCULATE
> > + select EFI_SIGNATURE_SUPPORT
> >   default n
> >   help
> > Select this option if you want to enable capsule
> > @@ -344,6 +345,7 @@ config EFI_SECURE_BOOT
> >   select PKCS7_MESSAGE_PARSER
> >   select PKCS7_VERIFY
> >   select HASH_CALCULATE
> > + select EFI_SIGNATURE_SUPPORT
> >   default n
> >   help
> > Select this option to enable EFI secure boot support.
> > @@ -351,6 +353,10 @@ config EFI_SECURE_BOOT
> > it is signed with a trusted key. To do that, you need to install,
> > at least, PK, KEK and db.
> >
> > +config EFI_SIGNATURE_SUPPORT
> > + bool
> > + depends on EFI_SECURE_BOOT || EFI_CAPSULE_AUTHENTICATE
>
> This line is superfluous. As it has no label the symbol will be false if
> not selected by EFI_SECURE_BOOT or EFI_CAPSULE_AUTHENTICATE.

I will remove this "depends on" line.

Thanks,
Masahisa Kojima

>
> Best regards
>
> Heinrich
>
> > +
> >   config EFI_ESRT
> >   bool "Enable the UEFI ESRT generation"
> >   depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
> > diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
> > index 8bd343e258..fd344cea29 100644
> > --- a/lib/efi_loader/Makefile
> > +++ b/lib/efi_loader/Makefile
> > @@ -63,7 +63,7 @@ obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o
> >   obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o
> >   obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o
> >   obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o
> > -obj-y += efi_signature.o
> > +obj-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o
> >
> >   EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE))
> >   $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE)
> > diff --git a/lib/efi_loader/efi_image_loader.c 
> > b/lib/efi_loader/efi_image_loader.c
> > index f53ef367ec..fe1ee198e2 100644
> > --- a/lib/efi_loader/efi_image_loader.c
> > +++ b/lib/efi_loader/efi_image_loader.c
> > @@ -213,7 +213,68 @@ static void efi_set_code_and_data_type(
> >   }
> >   }
> >
> > -#ifdef CONFIG_EFI_SECURE_BOOT
> > +/**
> > + * efi_image_region_add() - add an entry of region
> > + * @regs:Pointer to array of regions
> > + * @start:   Start address of region (included)
> > + * @end: End address of region (excluded)
> > + * @nocheck: flag against overlapped regions
> > + *
> > + * Take one entry of region [@start, @end[ and insert it into the list.
> > + *
> > + * * If @nocheck is false, the list will be sorted ascending by address.
> > + *   Overlapping entries will not be allowed.
> > + *
> > + * * If @nocheck is true, the list will be sorted ascending by sequence
> > + *   of adding the entries. Overlapping is allowed.
> > + *
> > + * Return:   status code
> > + */
> > +efi_status_t efi_image_region_add(struct efi_image_regions *regs,
> > +   const void *start, const void *end,
> > +   int nocheck)
> > +{
> > + struct image_region *reg;
> > + int i, j;
> > +
> > + if (regs->num >= regs->max) {
> > + EFI_PRINT("%s: no more room for regions\n", __func__);
> > + return EFI_OUT_OF_RESOURCES;
> > + }
> > +
> > + if (end < start)
> > +  

[PATCH] arm: dts: k3-j721e: Fix up MAIN R5FSS cluster mode back to Split-mode

2021-05-13 Thread Suman Anna
The default U-Boot environment variables and design are all set up for
both the MAIN R5FSS clusters to be in Split-mode. This is the setting
in v2021.01 U-Boot and the dt nodes are synched with the kernel binding
property names in commit 468ec2f3ef8f ("remoteproc: k3_r5: Sync to
upstreamed kernel DT property names") merged in v2021.04-rc2.

The modes for both the clusters got switched back to LockStep mode by
mistake in commit 70e167495ab2 ("arm: dts: k3-j721e: Sync Linux v5.11-rc6
dts into U-Boot") also in v2021.04-rc2. This throws the following warning
messages when early-booting the cores using default env variables,

  k3_r5f_rproc r5f@5d0: Invalid op: Trying to start secondary core 7 in 
lockstep mode
  Load Remote Processor 3 with data@addr=0x8200 98484 bytes: Failed!
  k3_r5f_rproc r5f@5f0: Invalid op: Trying to start secondary core 9 in 
lockstep mode
  Load Remote Processor 5 with data@addr=0x8200 98484 bytes: Failed!

Fix this by switching back both the clusters to the expected Split-mode.

Fixes: 70e167495ab2 ("arm: dts: k3-j721e: Sync Linux v5.11-rc6 dts into U-Boot")
Reported-by: Minas Hambardzumyan 
Signed-off-by: Suman Anna 
---
 arch/arm/dts/k3-j721e-main.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/k3-j721e-main.dtsi b/arch/arm/dts/k3-j721e-main.dtsi
index 07b489679ed9..b331282f51a2 100644
--- a/arch/arm/dts/k3-j721e-main.dtsi
+++ b/arch/arm/dts/k3-j721e-main.dtsi
@@ -1581,7 +1581,7 @@
 
main_r5fss0: r5fss@5c0 {
compatible = "ti,j721e-r5fss";
-   ti,cluster-mode = <1>;
+   ti,cluster-mode = <0>;
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x5c0 0x00 0x5c0 0x2>,
@@ -1621,7 +1621,7 @@
 
main_r5fss1: r5fss@5e0 {
compatible = "ti,j721e-r5fss";
-   ti,cluster-mode = <1>;
+   ti,cluster-mode = <0>;
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x5e0 0x00 0x5e0 0x2>,
-- 
2.30.1



Re: [PATCH 1/2] reset: Do not return NULL on error for devm_reset_control_get_optional()

2021-05-13 Thread Simon Glass
Hi Kishon,

On Thu, 13 May 2021 at 00:15, Kishon Vijay Abraham I  wrote:
>
> Hi Simon,
>
> On 11/05/21 10:09 pm, Simon Glass wrote:
> > Hi Kishon,
> >
> > On Tue, 11 May 2021 at 00:26, Kishon Vijay Abraham I  wrote:
> >>
> >> Hi Simon,
> >>
> >> On 07/05/21 10:04 pm, Simon Glass wrote:
> >>> Hi Kishon,
> >>>
> >>> On Fri, 7 May 2021 at 05:02, Kishon Vijay Abraham I  wrote:
> 
>  In order for client to know whether it was able to successfully get a
>  reset controller or not, do not return NULL on error for
>  devm_reset_control_get_optional() and
>  devm_reset_bulk_get_optional_by_node().
> 
>  Signed-off-by: Kishon Vijay Abraham I 
>  ---
>   drivers/reset/reset-uclass.c   | 16 ++--
>   drivers/reset/sandbox-reset-test.c |  2 +-
>   2 files changed, 3 insertions(+), 15 deletions(-)
> 
>  diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
>  index ac89eaf098..906f58ce3d 100644
>  --- a/drivers/reset/reset-uclass.c
>  +++ b/drivers/reset/reset-uclass.c
>  @@ -299,12 +299,7 @@ struct reset_ctl *devm_reset_control_get(struct 
>  udevice *dev, const char *id)
>   struct reset_ctl *devm_reset_control_get_optional(struct udevice *dev,
>    const char *id)
>   {
>  -   struct reset_ctl *r = devm_reset_control_get(dev, id);
>  -
>  -   if (IS_ERR(r))
>  -   return NULL;
>  -
>  -   return r;
>  +   return devm_reset_control_get(dev, id);
>   }
> >>>
> >>> We need to get some updates to the API (function comments in the
> >>> header) here. I'm not sure what the intent is.
> >>
> >> right, that has to be fixed.
> >>>
> >>> I thought these functions were going to return a valid (but possibly
> >>> empty) reset_ctl always?
> >>
> >> I thought about it again and felt it might not be correct to return
> >> reset_ctl always. The reset control is optional only if the consumer
> >> node doesn't have populated reset properties.
> >>
> >> If we always return valid reset_ctl possibly with it's dev member
> >> initialized or not initialized, it would not be possible to tell it's
> >> not initialized because of the absence of reset property or due to some
> >> other valid error.
> >
> > reset_valid() should check if dev is NULL or not, like with clock and
> > GPIO. Is that enough?
>
> clock compares with ENODATA and return "0" (code snippet below). For
> reset we are modifying this to return ENODATA itself and use it for
> comparing in the reset APIs.
>
> int clk_get_optional_nodev(ofnode node, const char *name, struct clk *clk)
> {
> int ret;
>
> ret = clk_get_by_name_nodev(node, name, clk);
> if (ret == -ENODATA)
> return 0;
>
> return ret;
> }
>

We must just be talking at cross-purposes. The function you show above
returns an error code, so there is no need for the caller to check clk
if an error is returned. For the -ENODATA case, note that
clk_get_by_name_nodev() sets clk->dev to NULL, thus ensuring that
clk_valid() works as expected.

But all of your patches are about a function that returns a pointer,
which is a different thing

> I can add reset_valid() and add the conditional checks corresponding to
> the changes made for reset (like return -ENODATA instead of 0).

I'm a bit lost at this point...will look at what you send.

Regards,
Simon


Re: [PATCH 1/1] sandbox: add symbol _init for RISC-V compilation

2021-05-13 Thread Simon Glass
Hi Heinrich,

On Thu, 13 May 2021 at 08:46, Heinrich Schuchardt  wrote:
>
> The sandbox does not build on RISC-V when _init is not defined. Errors like
> the following were observed. Which function was referred to depended on the
> configuration.
>
> /usr/bin/ld: common/built-in.o: in function `parse_stream_outer':
> /common/cli_hush.c:3175: undefined reference to `_init'
> collect2: error: ld returned 1 exit status
> make: *** [Makefile:1726: u-boot] Error 1
>
> /usr/bin/ld: common/built-in.o: in function `bootdelay_process':
> common/autoboot.c:335: undefined reference to `_init'
> collect2: error: ld returned 1 exit status
> make: *** [Makefile:1726: u-boot] Error 1
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  arch/sandbox/cpu/u-boot.lds | 2 ++
>  1 file changed, 2 insertions(+)

Is this a toolchain bug?

Reviewed-by: Simon Glass 


>
> diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds
> index a1f509c9ab..d9e7ffcea3 100644
> --- a/arch/sandbox/cpu/u-boot.lds
> +++ b/arch/sandbox/cpu/u-boot.lds
> @@ -9,6 +9,8 @@ SECTIONS
>  {
>
> . = ALIGN(4);
> +   /* RISC-V GCC wants this dummy symbol */
> +   _init = .;
> .u_boot_list : {
> KEEP(*(SORT(.u_boot_list*)));
> }
> --
> 2.30.2
>


Re: [PATCH 1/1] sandbox: ensure that state->ram_buf is in low memory

2021-05-13 Thread Simon Glass
Hi Heinrich,

On Thu, 13 May 2021 at 08:53, Heinrich Schuchardt  wrote:
>
> On 5/13/21 4:36 PM, Simon Glass wrote:
> > Hi Heinrich,
> >
> > On Wed, 12 May 2021 at 15:28, Heinrich Schuchardt  
> > wrote:
> >>
> >> Am 12. Mai 2021 18:01:17 MESZ schrieb Simon Glass :
> >>> Hi Heinrich,
> >>>
> >>> On Tue, 11 May 2021 at 13:03, Heinrich Schuchardt 
> >>> wrote:
> 
>  Addresses in state->ram_buf must be in the low 4 GiB of the address
> >>> space.
>  Otherwise we cannot correctly fill SMBIOS tables. This shows up in
> >>> warnings
>  like:
> 
>   WARNING: SMBIOS table_address overflow 7f752735e020
> >>>
> >>> This sounds like a bug in the smbios-table code. For sandbox it should
> >>> perhaps use addresses instead of pointers.
> >>>
> >>> I think that code (that I unfortunately wrote) was an expeditious way
> >>> of getting it running, but is not correct.
> >>
> >> The field you are filling is only 32bit wide. I wonder how that table is 
> >> meant to work on systems where the lowest memory address is above 4 GiB. 
> >> Such ARMv8 systems exist.
> >
> > map_to_sysmem() will give you a 32-bit wide address. Yes SMBIOS is
> > legacy and designed for 4GB.
>
> I know map_to_sysmem(). But you wrote in lib/smbios.c:487:
>
> /*
>   * We must use a pointer here so things work correctly on sandbox. The
>   * user of this table is not aware of the mapping of addresses to
>   * sandbox's DRAM buffer.
>   */
>
> For testing you could start a binary with command 'bootefi' or 'booti'
> and that binary would analyze the table. So yes, your comment holds true
> and you must not use map_to_sysmem() here.

Yes, that is a good point. Perhaps I was not mad when I wrote that.
What is using the tables on sandbox?

Regards,
SImon


Re: [PATCH 3/3] hash: Allow for SHA512 hardware implementations

2021-05-13 Thread Simon Glass
Hi Heinrich,

On Thu, 13 May 2021 at 09:38, Heinrich Schuchardt  wrote:
>
> On 5/13/21 4:36 PM, Simon Glass wrote:
> > Hi Heinrich,
> >
> > On Wed, 12 May 2021 at 15:27, Heinrich Schuchardt  
> > wrote:
> >>
> >> Am 12. Mai 2021 19:32:42 MESZ schrieb Simon Glass :
> >>> Hi Heinrich,
> >>>
> >>> On Wed, 12 May 2021 at 10:25, Heinrich Schuchardt 
> >>> wrote:
> 
>  On 12.05.21 18:05, Simon Glass wrote:
> > Hi Heinrich,
> >
> > On Wed, 12 May 2021 at 10:01, Heinrich Schuchardt
> >>>  wrote:
> >>
> >> On 17.02.21 04:20, Joel Stanley wrote:
> >>> Similar to support for SHA1 and SHA256, allow the use of hardware
> >>> hashing
> >>> engine by enabling the algorithm and setting  CONFIG_SHA_HW_ACCEL
> >>> /
> >>> CONFIG_SHA_PROG_HW_ACCEL.
> >>>
> >>> Signed-off-by: Joel Stanley 
> >>
> >> This merged patch leads to errors compiling the EFI TCG2 protocol
> >>> on
> >> boards with CONFIG_SHA_HW_ACCEL.
> >>
> >> There is not as single implementation of hw_sha384 and hw_sha512.
> >>> You
> >> could only use CONFIG_SHA_HW_ACCEL for selecting these functions
> >>> if
> >> these were implemented for *all* boards with
> >>> CONFIG_SHA_HW_ACCEL=y. But
> >> this will never happen.
> >>
> >> *This patch needs to be reverted.*
> >>
> >> Why do we have CONFIG_SHA_HW_ACCEL at all and don't use weak
> >>> functions
> >> instead?
> >
> > This is all a mess. We should not use weak functions IMO, but
> >>> instead
> > have a driver interface, like we do with filesystems.
> >
> > Part of the challenge is the need to keep code size small for
> > platforms that only need one algorithm.
> 
>  If a function is not referenced, the linker will eliminate it. But
> >>> with
>  a driver interface every function in the interface is referenced.
> >>>
> >>> Indeed, but we can still have an option for enabling the progressive
> >>> interface. My point is that the implementation (software or hardware)
> >>> should use a driver.
> >>>
> >>> Regards,
> >>> Simon
> >>
> >> Anyway that should not stop us from reverting a problematic patch. We can 
> >> work on refactoring afterwards.
> >
> > Well the patch was applied because tests passed. We should be careful
> > about reverting a patch due to problems it causes in the future.
>
> The code compiled because SHA384 and SHA512 were not used together with
> CONFIG_SHA_HW_ACCEL=y. But we need these functions to implement the TCG2
> protocol on boards with TPMv2.

Let's fix it then. The patch makes all the hashing algorithms work the
same, which seems right to me. If we come to converting this to a
linker list, which we should, then it will be easier with this patch
applied than not.

>
> Gitlab CI had no issues with reverting the patch.

OK. It's up to Tom what he wants to do. But how about sending a patch
to do what you want, instead?

Regards,
SImon


Re: [PATCH v2 16/50] image: Add Kconfig options for FIT in the host build

2021-05-13 Thread Simon Glass
Hi Alex,

On Thu, 13 May 2021 at 10:21, Alex G.  wrote:
>
>
>
> On 5/12/21 12:30 PM, Simon Glass wrote:
> > Hi Alex,
> >
> > On Wed, 12 May 2021 at 10:18, Alex G.  wrote:
> >>
> >>
> >>
> >> On 5/12/21 10:54 AM, Simon Glass wrote:
> >>> Hi Alex,
> >>>
> >>> On Wed, 12 May 2021 at 09:48, Alex G.  wrote:
> 
> 
> 
>  On 5/12/21 9:51 AM, Simon Glass wrote:
> > Hi Alex,
> >
> > On Tue, 11 May 2021 at 13:57, Alex G.  wrote:
> >>
> >> On 5/6/21 9:24 AM, Simon Glass wrote:
> 
>  [snip]
> 
> >>
> >>> +
> >>> +config HOST_FIT_PRINT
> >>> + def_bool y
> >>> + help
> >>> +   Print the content of the FIT verbosely in the host build
> >>
> >> This option also doesn't make sense.This seems to do what 'mkimage -l'
> >> already supports.
> >
> > Are you sure you have looked at the goal of the CONFIG_IS_ENABLED()
> > changes? This is here purely to avoid #ifdefs in the share code.
> 
>  On the one hand, we have the cosmetic inconvenience caused by #ifdefs.
>  On the other hand we have the config system. To most users, the config
>  system is likely more visible, while it's mostly developers who will
>  ever see the ifdefs.
> 
>  Therefore, in order to get the developer convenience of less ifdefs, we
>  have to sacrifice user convenience by cloberring the Kconfig options. I
>  think this is back-to-front.
> >>>
> >>> These Kconfig options are not visible to users. They cannot be updated
> >>> in defconfig, nor in 'make menuconfig', etc. They are purely there for
> >>> the build system.
> >>>
> 
>  Can we reduce the host config count to just SLL/NOSSL?
> >>>
> >>> The point here is that the code has a special case for host builds,
> >>> and this is a means to remove that special case and make the code
> >>> easier to maintain and follow.
> >>
> >> I understand where you're coming from. Without these changes, the code
> >> knows what it should and should not do, correct? My argument is that if
> >> the code has the logic to do the correct thing, that logic should not be
> >> split with the config system.
> >>
> >> I agree with the goal of reducing clutter in the source code. I disagree
> >> with this specific course of fixing it. Instead, I propose a single
> >> kconfig for host tools for SSL on/off.
> >>
> >> The disadvantage of my proposal is that we have to refactor the common
> >> code in a way consistent with the goals, instead of just changing some
> >> #ifdefs to if(CONFIG_IS_ENABLED()). I admit that, off the top of my
> >> head, I don't have a detailed plan on how to achieve this.
> >
> > You are mostly describing the status quo, so far as I understand it.
> > The problem is with the code that is built for both boards and tools.
> > For boards, we want this code to be compiled conditionally, depending
> > on what options are enabled. For tools, we want the code to be
> > compiled unconditionally.
> >
> > I can think of only three ways to do this:
> >
> > - status quo (add #ifdefs USE_HOSTCC wherever we need to)
> > - my series (make use of hidden Kconfig options to avoid that)
> > - put every single feature and associated lines of code in separate
> > files and compile them conditionally for boards, but always for tools
> >
> > I believe the last option is actually impossible, or at least
> > impractical. It would cause an explosion of source files to deal with
> > all the various combinations, and would be quite painful to maintain
> > also.
>
> I don't think the status quo is such a terrible solution, so I am
> looking at the aspects that can benefit from improvement. Hence why it
> may appear I am talking about the status quo.
>
> Let's assume CONFIG_IS_ENABLED() returns true on host builds, and for
> those cases where you need to know if IS_HOST_BUILD(), there's a macro
> for that. You have the oddball case that uses a CONFIG_ value that's
> only defined on the target, and those you would have to split according
> to your option #3.
>
> I don't think the above is as dire an explosion in source files as it seems.
>
> Another point of contention is checksum_algos and crypto_algos arrays
> image-sig.c. On the target side, these should be in .u-boot-list. Status
> quo is the definition of rsa_verify is hidden behind #if macros, which
> just pushes the complexity out into the rsa.h headers.
>
> The two ideas here are CONFIG_IS_ENABLED() returns true for host code,
> and image-sig.c is split bwtween host and target versions, the target
> version making use of .uboot-list. Using these as the starting points, I
> think we can get to a much better solution

I did consider simply defining CONFIG_IS_ENABLED() to true for the
host, but rejected that because I worried it would break down at some
point. Examples I can think of at the moment:

- conflicting or alternative options (OF_LIVE, OF_HOST_FILE, OF_SEPARATE)
- code that is not actually wanted on the host (WATCHDOG,

Re: [PATCH v3] mmc: Update environment variable with active partition

2021-05-13 Thread Jaehoon Chung
On 5/14/21 7:17 AM, Reuben Dowle wrote:
> 
>>
>> Could you also update doc/usage/mmc.rst?
>>
> 
> I have sent a v4 patch that also updates the documentation.

Thank you!

Best Regards,
Jaehoon Chung

> 
> 
> [cid:4RFLogo(Custom)(2)_0f31a7de-6dd6-43cf-bc6a-a097a2b80b69.jpg]
> Reuben Dowle
> Software Architect
> 
> Phone:
> 
> Fax:
> E-Mail:
> Website:
> 
> 
> +64 4 499 6000
> 
> +64 4 473 4447
> reuben.do...@4rf.com
> https://protect2.fireeye.com/v1/url?k=36d0d29e-694beb95-36d159d1-002590f5b904-2debe5e0a90c035e=1=ff3585ce-8e60-46cc-9aaf-ae5b55b985c7=https%3A%2F%2Fwww.4rf.com%2F
> 
> 
> 
> 
> [cid:Family_53c410b1-7227-4a5f-9acb-f09bd7617a39.png] 
> 
> 
> 
> The information in this email communication (inclusive of attachments) is 
> confidential to 4RF Limited and the intended recipient(s). If you are not the 
> intended recipient(s), please note that any use, disclosure, distribution or 
> copying of this information or any part thereof is strictly prohibited and 
> that the author accepts no liability for the consequences of any action taken 
> on the basis of the information provided. If you have received this email in 
> error, please notify the sender immediately by return email and then delete 
> all instances of this email from your system. 4RF Limited will not accept 
> responsibility for any consequences associated with the use of this email 
> (including, but not limited to, damages sustained as a result of any viruses 
> and/or any action or lack of action taken in reliance on it).
> 



Re: [PATCH v4] mmc: Update environment variable with active partition

2021-05-13 Thread Jaehoon Chung
On 5/14/21 7:15 AM, Reuben Dowle wrote:
> This patch allows uboot scripts make choices about where to boot from based
> on the active mmc boot partition. This allows having two copies of kernel,
> filesystems etc, and choosing which to boot from based off of the active
> bootloader partition.
> 
> Signed-off-by: Reuben Dowle 

Reviewed-by: Jaehoon Chung 

Best Regards,
Jaehoon Chung

> ---
>  cmd/mmc.c | 14 +-
>  doc/usage/mmc.rst |  4 +++-
>  2 files changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/cmd/mmc.c b/cmd/mmc.c
> index a10f137..b942576 100644
> --- a/cmd/mmc.c
> +++ b/cmd/mmc.c
> @@ -808,7 +808,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int 
> flag,
>   return CMD_RET_SUCCESS;
>  }
>  
> -static int mmc_partconf_print(struct mmc *mmc)
> +static int mmc_partconf_print(struct mmc *mmc, const char *varname)
>  {
>   u8 ack, access, part;
>  
> @@ -821,6 +821,9 @@ static int mmc_partconf_print(struct mmc *mmc)
>   ack = EXT_CSD_EXTRACT_BOOT_ACK(mmc->part_config);
>   part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
>  
> + if(varname)
> + env_set_hex(varname, part);
> +
>   printf("EXT_CSD[179], PARTITION_CONFIG:\n"
>   "BOOT_ACK: 0x%x\n"
>   "BOOT_PARTITION_ENABLE: 0x%x\n"
> @@ -836,7 +839,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int 
> flag,
>   struct mmc *mmc;
>   u8 ack, part_num, access;
>  
> - if (argc != 2 && argc != 5)
> + if (argc != 2 && argc != 3 && argc != 5)
>   return CMD_RET_USAGE;
>  
>   dev = simple_strtoul(argv[1], NULL, 10);
> @@ -850,8 +853,8 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int 
> flag,
>   return CMD_RET_FAILURE;
>   }
>  
> - if (argc == 2)
> - return mmc_partconf_print(mmc);
> + if (argc == 2 || argc == 3)
> + return mmc_partconf_print(mmc, argc == 3 ? argv[2] : NULL);
>  
>   ack = simple_strtoul(argv[2], NULL, 10);
>   part_num = simple_strtoul(argv[3], NULL, 10);
> @@ -1061,8 +1064,9 @@ U_BOOT_CMD(
>   " - Set the BOOT_BUS_WIDTH field of the specified device\n"
>   "mmc bootpart-resize   \n"
>   " - Change sizes of boot and RPMB partitions of specified device\n"
> - "mmc partconf  [boot_ack boot_partition partition_access]\n"
> + "mmc partconf  [[varname] | [  
> ]]\n"
>   " - Show or change the bits of the PARTITION_CONFIG field of the 
> specified device\n"
> + "   If showing the bits, optionally store the boot_partition field into 
> varname\n"
>   "mmc rst-function  \n"
>   " - Change the RST_n_FUNCTION field of the specified device\n"
>   "   WARNING: This is a write-once field and 0 / 1 / 2 are the only 
> valid values.\n"
> diff --git a/doc/usage/mmc.rst b/doc/usage/mmc.rst
> index 57284ed..b72e5f8 100644
> --- a/doc/usage/mmc.rst
> +++ b/doc/usage/mmc.rst
> @@ -19,7 +19,7 @@ Synopsis
>  mmc wp
>  mmc bootbus
>  mmc bootpart-resize   
> -mmc partconf  [boot_ack boot_partition partition_access]
> +mmc partconf  [[varname] | [  
> ]]
>  mmc rst-function  
>  
>  Description
> @@ -92,6 +92,8 @@ The 'mmc bootbus' command sets the BOOT_BUS_WIDTH field. 
> (*Refer to eMMC specifi
>  
>  The 'mmc partconf' command shows or changes PARTITION_CONFIG field.
>  
> +varname
> +When showing the PARTITION_CONFIG, an optional environment variable 
> to store the current boot_partition value into.
>  boot_ack
>  boot acknowledge value
>  boot_partition
> 



Re: [PATCH 1/1] sandbox: add symbol _init for RISC-V compilation

2021-05-13 Thread Bin Meng
On Thu, May 13, 2021 at 10:46 PM Heinrich Schuchardt  wrote:
>
> The sandbox does not build on RISC-V when _init is not defined. Errors like
> the following were observed. Which function was referred to depended on the
> configuration.
>
> /usr/bin/ld: common/built-in.o: in function `parse_stream_outer':
> /common/cli_hush.c:3175: undefined reference to `_init'
> collect2: error: ld returned 1 exit status
> make: *** [Makefile:1726: u-boot] Error 1
>
> /usr/bin/ld: common/built-in.o: in function `bootdelay_process':
> common/autoboot.c:335: undefined reference to `_init'
> collect2: error: ld returned 1 exit status
> make: *** [Makefile:1726: u-boot] Error 1
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  arch/sandbox/cpu/u-boot.lds | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds
> index a1f509c9ab..d9e7ffcea3 100644
> --- a/arch/sandbox/cpu/u-boot.lds
> +++ b/arch/sandbox/cpu/u-boot.lds
> @@ -9,6 +9,8 @@ SECTIONS
>  {
>
> . = ALIGN(4);
> +   /* RISC-V GCC wants this dummy symbol */

Native GCC on RISC-V?

RISC-V GCC sounds like cross-compile for RISC-V

> +   _init = .;
> .u_boot_list : {
> KEEP(*(SORT(.u_boot_list*)));
> }
> --


Regards,
Bin


RE: [PATCH v3] mmc: Update environment variable with active partition

2021-05-13 Thread Reuben Dowle

> 
> Could you also update doc/usage/mmc.rst?
> 

I have sent a v4 patch that also updates the documentation.


[PATCH v4] mmc: Update environment variable with active partition

2021-05-13 Thread Reuben Dowle
This patch allows uboot scripts make choices about where to boot from based
on the active mmc boot partition. This allows having two copies of kernel,
filesystems etc, and choosing which to boot from based off of the active
bootloader partition.

Signed-off-by: Reuben Dowle 
---
 cmd/mmc.c | 14 +-
 doc/usage/mmc.rst |  4 +++-
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/cmd/mmc.c b/cmd/mmc.c
index a10f137..b942576 100644
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -808,7 +808,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int 
flag,
return CMD_RET_SUCCESS;
 }
 
-static int mmc_partconf_print(struct mmc *mmc)
+static int mmc_partconf_print(struct mmc *mmc, const char *varname)
 {
u8 ack, access, part;
 
@@ -821,6 +821,9 @@ static int mmc_partconf_print(struct mmc *mmc)
ack = EXT_CSD_EXTRACT_BOOT_ACK(mmc->part_config);
part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
 
+   if(varname)
+   env_set_hex(varname, part);
+
printf("EXT_CSD[179], PARTITION_CONFIG:\n"
"BOOT_ACK: 0x%x\n"
"BOOT_PARTITION_ENABLE: 0x%x\n"
@@ -836,7 +839,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
struct mmc *mmc;
u8 ack, part_num, access;
 
-   if (argc != 2 && argc != 5)
+   if (argc != 2 && argc != 3 && argc != 5)
return CMD_RET_USAGE;
 
dev = simple_strtoul(argv[1], NULL, 10);
@@ -850,8 +853,8 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
return CMD_RET_FAILURE;
}
 
-   if (argc == 2)
-   return mmc_partconf_print(mmc);
+   if (argc == 2 || argc == 3)
+   return mmc_partconf_print(mmc, argc == 3 ? argv[2] : NULL);
 
ack = simple_strtoul(argv[2], NULL, 10);
part_num = simple_strtoul(argv[3], NULL, 10);
@@ -1061,8 +1064,9 @@ U_BOOT_CMD(
" - Set the BOOT_BUS_WIDTH field of the specified device\n"
"mmc bootpart-resize   \n"
" - Change sizes of boot and RPMB partitions of specified device\n"
-   "mmc partconf  [boot_ack boot_partition partition_access]\n"
+   "mmc partconf  [[varname] | [  
]]\n"
" - Show or change the bits of the PARTITION_CONFIG field of the 
specified device\n"
+   "   If showing the bits, optionally store the boot_partition field into 
varname\n"
"mmc rst-function  \n"
" - Change the RST_n_FUNCTION field of the specified device\n"
"   WARNING: This is a write-once field and 0 / 1 / 2 are the only 
valid values.\n"
diff --git a/doc/usage/mmc.rst b/doc/usage/mmc.rst
index 57284ed..b72e5f8 100644
--- a/doc/usage/mmc.rst
+++ b/doc/usage/mmc.rst
@@ -19,7 +19,7 @@ Synopsis
 mmc wp
 mmc bootbus
 mmc bootpart-resize   
-mmc partconf  [boot_ack boot_partition partition_access]
+mmc partconf  [[varname] | [  
]]
 mmc rst-function  
 
 Description
@@ -92,6 +92,8 @@ The 'mmc bootbus' command sets the BOOT_BUS_WIDTH field. 
(*Refer to eMMC specifi
 
 The 'mmc partconf' command shows or changes PARTITION_CONFIG field.
 
+varname
+When showing the PARTITION_CONFIG, an optional environment variable to 
store the current boot_partition value into.
 boot_ack
 boot acknowledge value
 boot_partition
-- 
2.7.4



Re: [PATCH v3] mmc: Update environment variable with active partition

2021-05-13 Thread Jaehoon Chung
Hi Reuben,

On 5/13/21 12:40 PM, Reuben Dowle wrote:
> This patch allows uboot scripts make choices about where to boot from based
> on the active mmc boot partition. This allows having two copies of kernel,
> filesystems etc, and choosing which to boot from based off of the active
> bootloader partition.

Could you also update doc/usage/mmc.rst?

> 
> Signed-off-by: Reuben Dowle 

Reviewed-by: Jaehoon Chung 

Best Regards,
Jaehoon Chung

> ---
>  cmd/mmc.c | 14 +-
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/cmd/mmc.c b/cmd/mmc.c
> index a10f137..b942576 100644
> --- a/cmd/mmc.c
> +++ b/cmd/mmc.c
> @@ -808,7 +808,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int 
> flag,
>   return CMD_RET_SUCCESS;
>  }
>  
> -static int mmc_partconf_print(struct mmc *mmc)
> +static int mmc_partconf_print(struct mmc *mmc, const char *varname)
>  {
>   u8 ack, access, part;
>  
> @@ -821,6 +821,9 @@ static int mmc_partconf_print(struct mmc *mmc)
>   ack = EXT_CSD_EXTRACT_BOOT_ACK(mmc->part_config);
>   part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
>  
> + if(varname)
> + env_set_hex(varname, part);
> +
>   printf("EXT_CSD[179], PARTITION_CONFIG:\n"
>   "BOOT_ACK: 0x%x\n"
>   "BOOT_PARTITION_ENABLE: 0x%x\n"
> @@ -836,7 +839,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int 
> flag,
>   struct mmc *mmc;
>   u8 ack, part_num, access;
>  
> - if (argc != 2 && argc != 5)
> + if (argc != 2 && argc != 3 && argc != 5)
>   return CMD_RET_USAGE;
>  
>   dev = simple_strtoul(argv[1], NULL, 10);
> @@ -850,8 +853,8 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int 
> flag,
>   return CMD_RET_FAILURE;
>   }
>  
> - if (argc == 2)
> - return mmc_partconf_print(mmc);
> + if (argc == 2 || argc == 3)
> + return mmc_partconf_print(mmc, argc == 3 ? argv[2] : NULL);
>  
>   ack = simple_strtoul(argv[2], NULL, 10);
>   part_num = simple_strtoul(argv[3], NULL, 10);
> @@ -1061,8 +1064,9 @@ U_BOOT_CMD(
>   " - Set the BOOT_BUS_WIDTH field of the specified device\n"
>   "mmc bootpart-resize   \n"
>   " - Change sizes of boot and RPMB partitions of specified device\n"
> - "mmc partconf  [boot_ack boot_partition partition_access]\n"
> + "mmc partconf  [[varname] | [  
> ]]\n"
>   " - Show or change the bits of the PARTITION_CONFIG field of the 
> specified device\n"
> + "   If showing the bits, optionally store the boot_partition field into 
> varname\n"
>   "mmc rst-function  \n"
>   " - Change the RST_n_FUNCTION field of the specified device\n"
>   "   WARNING: This is a write-once field and 0 / 1 / 2 are the only 
> valid values.\n"
> 



Re: [PATCH] efi_loader: consider no-map property of reserved memory

2021-05-13 Thread Mark Kettenis
> From: Heinrich Schuchardt 
> Date: Thu, 13 May 2021 21:41:40 +0200

Hi Heinrich & Atish,

> On 5/11/21 1:47 AM, Atish Patra wrote:
> > On Wed, Sep 2, 2020 at 12:10 AM Heinrich Schuchardt  
> > wrote:
> >>
> >> On 31.08.20 20:08, Atish Patra wrote:
> >>> On Thu, Aug 27, 2020 at 9:16 AM Heinrich Schuchardt  
> >>> wrote:
> 
>  If a reserved memory node in the device tree has the property no-map,
>  remove it from the UEFI memory map provided by GetMemoryMap().
> 
>  Signed-off-by: Heinrich Schuchardt 
> >>
> >> In the mail-thread starting a
> >>
> >> [PATCH 1/1] EBBR: GetMemoryMap(), handling of no-map DT property
> >> https://lists.linaro.org/pipermail/boot-architecture/2020-September/001389.html
> >>
> >> the issue has been discussed. The conclusion was that we should not
> >> change the current behavior.
> >>
> >
> > Digging some old threads :)
> >
> > The merged version of the patch marks any reserved memory as
> > EFI_BOOT_SERVICES_DATA.
> > AFAIK, these memory regions will be available after ExitBootservice.
> > If the operating system chooses to
> > map these region and access them, it violates the purpose of the
> > reserved memory region specified by the firmware.
> >
> > Did I miss something ?
> 
> The no-map property is neither described in the EBBR nor in the
> Devicetree specification v0.3 but only in Linux' reserved-memory.txt.

It is described (quite explicitly) in the current devicetree
specification draft.

> In
> https://lists.linaro.org/pipermail/boot-architecture/2020-September/001418.html
> Ard requested that no-map memory shall be marked EfiReservedMemory
> because Linux will not map EfiReservedMemory, see Linux function
> is_usable_memory().
> 
> All reserved memory that is not marked as no-map shall be mapped by
> Linux. It may for instance serve as DMA pool or as video memory. Or it
> may even be reusable. See reserved-memory.txt.
> 
> Only drivers will access their own reserved memory if the region is not
> marked as reusable.

I suspect Atish is asking because of the issue I opened for opensbi:

  https://github.com/riscv/opensbi/issues/210

On many RISC-V platforms, opensbi runs in "machine mode" (somewhat
equivalent to EL3 on ARMv8) and allocates some memory for itself.  It
sets up protections for this memory such that "supervisor mode"
(somewhat equivalent to EL1 on ARMv8) can't access this memory.

Older versions of opensbi marked this memory area as "no-map",
resulting in that memory area being marked as EfiReservedMemoryType,
and evrything is fine.

However, according to reserved-memory.txt, "no-map" means the the area
isn't supposed to be mapped by the OS at all.  That is deemed
undesirable since it prevents the OS from using a large 2MB or 1G page
table entry to map the memory range that happens to include the memory
reserved for opensbi.  That is sub-optimal as it means the OS has to
allocated more levels of page tables for this memory block and has to
use 4K pages which will increase TLB pressure.  So newer versions of
opensbi dropped the "no-map" property resulting in the area being
marked as EfiBootServicesData.  But that is obviously wrong since the
OS can't actually access that memory range.

Now somewhat by accident the Linux kernel didn't actually attempt to
use this memory area so the issue wasn't noticed.  But we're working
on OpenBSD/riscv64 and when I added code to use the EFI memory map the
OpenBSD kernel tried to use that inaccessable memory, which obviously
didn't end well.

I suspect differences between the ARMv8 and RISC-V architecture are at
play here.  On ARMv8 "secure" memory areas like this are not supposed
to be mapped as speculative access might trigger a fault.  But on
RISC-V mapping a "protected" memory area is fine as long as you don't
try to actually access it.

So the question really is how opensbi can express that a certain
memory area is reserved (and should end up as EfiReservedMemoryType in
the EFI memory map) but that it is ok to map it.  Possible solution
include:

* Change the interpretation of the "no-map" property for RISC-V such
  that it is clear that the region in question can be mapped but can
  not be accessed.  This only makes sense if the RISC-V architecture
  guarantees that creating a mapping for physical memory will never
  cause problems even if those areas can't be accessed.

* Invent a new property that conveys the desired semantics.

* Always flag memory ranges under /reserved-memory as
  EfiReserbedMemoryType unless that memory range is marked as
  "reusable".

Cheers,

Mark


Re: [EXT] [PATCH] mtd: mxs_nand: default to legacy bch and rename to modern bch option

2021-05-13 Thread han.xu
On 21/05/11 07:08AM, Sean Nyekjaer wrote:
> Caution: EXT Email
> 
> On 11/05/2021 04.49, han.xu wrote:
> > On 21/05/10 12:00PM, Sean Nyekjaer wrote:
> >> Caution: EXT Email
> >>
> >> Linux kernel defaults to use legacy bch setting, this was creating a
> >> mismatch between U-boot and Linux default settings.
> > Kernel uses the NAND chip specified minimum ecc strength and steps by 
> > default
> > not the legacy bch setting, unless users enable it in DT file.
> >
> 
> Hi,
> 
> Adding, mtd-list and Miquel
> 
> With u-boot dtb:
>  {
> pinctrl-names = "default";
> pinctrl-0 = <_gpmi_nand1>;
> compatible = "fsl,imx7d-gpmi-nand";
> nand-on-flash-bbt;
> status = "okay";
> };
> 
> With linux dtb (mainline 5.10):
>  {
> pinctrl-names = "default";
> pinctrl-0 = <_gpmi_nand1>;
> nand-on-flash-bbt;
> status = "okay";
> };
> 
> U-boot prior to commit 51cdf83eea selected 18 bit ECC, after that commit it 
> selects 8 bits.
> With legacy option it selects 18.
> Linux is selecting 18 bits ;) So now we have a mismatch.
> 
> I have been searching for the legacy option in the mainline kernel can't find 
> it ;)
> Please show me where it is (is it in the NXP fork?)

You are right, it's only fixed in NXP fork, with kernel driver modification. We
prefer the current u-boot bch geometry, so I will send out a kernel patch to
make them align.

> 
> /Sean


[PATCH] dm: core: fix no null pointer detection in ofnode_get_addr_size_index()

2021-05-13 Thread chenguanqiao
From: Chen Guanqiao 

Fixed a defect of a null pointer being discovered by Coverity Scan:
   CID 331544:  Null pointer dereferences  (REVERSE_INULL)
   Null-checking "size" suggests that it may be null, but it has already been 
dereferenced on all paths leading to the check.

Signed-off-by: Chen Guanqiao 
---
 drivers/core/ofnode.c | 13 +++--
 include/dm/ofnode.h   |  2 +-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 6c771e364f..554af95114 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -299,11 +299,10 @@ ofnode ofnode_get_by_phandle(uint phandle)
return node;
 }

-fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
+fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t 
*psize)
 {
int na, ns;
-
-   *size = FDT_SIZE_T_NONE;
+   fdt_size_t size = FDT_SIZE_T_NONE;

if (ofnode_is_np(node)) {
const __be32 *prop_val;
@@ -314,8 +313,7 @@ fdt_addr_t ofnode_get_addr_size_index(ofnode node, int 
index, fdt_size_t *size)
  );
if (!prop_val)
return FDT_ADDR_T_NONE;
-   if (size)
-   *size = size64;
+   size = size64;

ns = of_n_size_cells(ofnode_to_np(node));

@@ -330,9 +328,12 @@ fdt_addr_t ofnode_get_addr_size_index(ofnode node, int 
index, fdt_size_t *size)
ns = ofnode_read_simple_size_cells(ofnode_get_parent(node));
return fdtdec_get_addr_size_fixed(gd->fdt_blob,
  ofnode_to_offset(node), "reg",
- index, na, ns, size, true);
+ index, na, ns, psize, true);
}

+   if (size)
+   *psize = size;
+
return FDT_ADDR_T_NONE;
 }

diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 8a69fd87da..e38d39dcf3 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -487,7 +487,7 @@ int ofnode_read_size(ofnode node, const char *propname);
  * @return address, or FDT_ADDR_T_NONE if not present or invalid
  */
 phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
-  fdt_size_t *size);
+  fdt_size_t *psize);

 /**
  * ofnode_get_addr_index() - get an address from a node
--
2.27.0



Re: 【外部邮件!】[scan-ad...@coverity.com: New Defects reported by Coverity Scan for Das U-Boot]

2021-05-13 Thread 陈冠桥
Hi

Sorry, A null pointer detection is missing here, I will fix it later.


On May 13, 2021, at 6:30 AM, Tom Rini 
mailto:tr...@konsulko.com>> wrote:

- Forwarded message from 
scan-ad...@coverity.com -

Date: Mon, 10 May 2021 21:17:32 + (UTC)
From: scan-ad...@coverity.com
To: tom.r...@gmail.com
Subject: New Defects reported by Coverity Scan for Das U-Boot

Hi,

Please find the latest report on new defect(s) introduced to Das U-Boot found 
with Coverity Scan.

1 new defect(s) introduced to Das U-Boot found with Coverity Scan.
3 defect(s), reported by Coverity Scan earlier, were marked fixed in the recent 
build analyzed by Coverity Scan.

New defect(s) Reported-by: Coverity Scan
Showing 1 of 1 defect(s)


** CID 331544:  Null pointer dereferences  (REVERSE_INULL)
/drivers/core/ofnode.c: 317 in ofnode_get_addr_size_index()



*** CID 331544:  Null pointer dereferences  (REVERSE_INULL)
/drivers/core/ofnode.c: 317 in ofnode_get_addr_size_index()
311  uint flags;
312
313  prop_val = of_get_address(ofnode_to_np(node), index, ,
314   );
315  if (!prop_val)
316  return FDT_ADDR_T_NONE;
   CID 331544:  Null pointer dereferences  (REVERSE_INULL)
   Null-checking "size" suggests that it may be null, but it has already been 
dereferenced on all paths leading to the check.
317  if (size)
318  *size = size64;
319
320  ns = of_n_size_cells(ofnode_to_np(node));
321
322  if (IS_ENABLED(CONFIG_OF_TRANSLATE) &&



To view the defects in Coverity Scan visit, 
https://u15810271.ct.sendgrid.net/ls/click?upn=HRESupC-2F2Czv4BOaCWWCy7my0P0qcxCbhZ31OYv50yoA22WlOQ-2By3ieUvdbKmOyw68TMVT4Kip-2BBzfOGWXJ5yIiYplmPF9KAnKIja4Zd7tU-3DG8yI_EEm8SbLgSDsaDZif-2Bv7ch8WqhKpLoKErHi4nXpwDNTtU1-2Brl29AQnRBl5SDIhsdlk4JL-2BC60Yy99Ru0XHXKZmudWSFasqNbw3J8c8YsieibEgnFne8AQZsraqyZc6bSorO2VVj4yo2EYbDylqVK-2BNvmB4zxqglhPpQGYCxEyim-2BCmtR1oyAQcyUT-2F0UpwA2s3mUEbsptAVDqX6MTucjWlw-3D-3D

 To manage Coverity Scan email notifications for 
"tom.r...@gmail.com", click 
https://u15810271.ct.sendgrid.net/ls/click?upn=HRESupC-2F2Czv4BOaCWWCy7my0P0qcxCbhZ31OYv50yped04pjJnmXOsUBtKYNIXxWeIHzDeopm-2BEWQ6S6K-2FtUHv9ZTk8qZbuzkkz9sa-2BJFw4elYDyedRVZOC-2ButxjBZdouVmTGuWB6Aj6G7lm7t25-2Biv1B-2B9082pHzCCex2kqMs-3DcN-g_EEm8SbLgSDsaDZif-2Bv7ch8WqhKpLoKErHi4nXpwDNTtU1-2Brl29AQnRBl5SDIhsdlpXdtm0ziQZhCdYNwPtYo9juOCfJRYvUSD6RBDul3PpPJtEbQAvJyD64um9NlavMb-2FNhtaCPCgg1OZOg6fyHdjqmNc-2BSac4T2ShWFTENHS5073Orso2HRCvi56uwUJuZ8ILMBdsEOC5-2FtuCAU-2BmbVBQ-3D-3D


- End forwarded message -

—
Tom

--
Chen Guanqiao




Re: [PATCH] efi_loader: consider no-map property of reserved memory

2021-05-13 Thread Heinrich Schuchardt

On 5/11/21 1:47 AM, Atish Patra wrote:

On Wed, Sep 2, 2020 at 12:10 AM Heinrich Schuchardt  wrote:


On 31.08.20 20:08, Atish Patra wrote:

On Thu, Aug 27, 2020 at 9:16 AM Heinrich Schuchardt  wrote:


If a reserved memory node in the device tree has the property no-map,
remove it from the UEFI memory map provided by GetMemoryMap().

Signed-off-by: Heinrich Schuchardt 


In the mail-thread starting a

[PATCH 1/1] EBBR: GetMemoryMap(), handling of no-map DT property
https://lists.linaro.org/pipermail/boot-architecture/2020-September/001389.html

the issue has been discussed. The conclusion was that we should not
change the current behavior.



Digging some old threads :)

The merged version of the patch marks any reserved memory as
EFI_BOOT_SERVICES_DATA.
AFAIK, these memory regions will be available after ExitBootservice.
If the operating system chooses to
map these region and access them, it violates the purpose of the
reserved memory region specified by the firmware.

Did I miss something ?


The no-map property is neither described in the EBBR nor in the
Devicetree specification v0.3 but only in Linux' reserved-memory.txt.

In
https://lists.linaro.org/pipermail/boot-architecture/2020-September/001418.html
Ard requested that no-map memory shall be marked EfiReservedMemory
because Linux will not map EfiReservedMemory, see Linux function
is_usable_memory().

All reserved memory that is not marked as no-map shall be mapped by
Linux. It may for instance serve as DMA pool or as video memory. Or it
may even be reusable. See reserved-memory.txt.

Only drivers will access their own reserved memory if the region is not
marked as reusable.

Best regards

Heinrich




Best regards

Heinrich


---
  cmd/bootefi.c   | 34 --
  include/efi.h   |  3 +++
  lib/efi_loader/efi_memory.c |  7 +--
  3 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 40d5ef2b3a..f173105251 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -135,12 +135,29 @@ done:
 return ret;
  }

-static void efi_reserve_memory(u64 addr, u64 size)
+/**
+ * efi_reserve_memory() - add reserved memory to memory map
+ *
+ * @addr:  start address of the reserved memory range
+ * @size:  size of the reserved memory range
+ * @nomap: indicates that the memory range shall be hidden from the memory
+ * map
+ */
+static void efi_reserve_memory(u64 addr, u64 size, bool nomap)
  {
+   int type;
+   efi_uintn_t ret;
+
 /* Convert from sandbox address space. */
 addr = (uintptr_t)map_sysmem(addr, 0);
-   if (efi_add_memory_map(addr, size,
-  EFI_RESERVED_MEMORY_TYPE) != EFI_SUCCESS)
+
+   if (nomap)
+   type = EFI_NO_MAP_MEMORY;
+   else
+   type = EFI_RESERVED_MEMORY_TYPE;
+
+   ret = efi_add_memory_map(addr, size, type);
+   if (ret != EFI_SUCCESS)
 log_err("Reserved memory mapping failed addr %llx size %llx\n",
 addr, size);
  }
@@ -166,7 +183,7 @@ static void efi_carve_out_dt_rsv(void *fdt)
 for (i = 0; i < nr_rsv; i++) {
 if (fdt_get_mem_rsv(fdt, i, , ) != 0)
 continue;
-   efi_reserve_memory(addr, size);
+   efi_reserve_memory(addr, size, false);
 }

 /* process reserved-memory */
@@ -186,8 +203,13 @@ static void efi_carve_out_dt_rsv(void *fdt)
  * a size instead of a reg property.
  */
 if (fdt_addr != FDT_ADDR_T_NONE &&
-   fdtdec_get_is_enabled(fdt, subnode))
-   efi_reserve_memory(fdt_addr, fdt_size);
+   fdtdec_get_is_enabled(fdt, subnode)) {
+   bool nomap;
+
+   nomap = !!fdt_getprop(fdt, subnode, "no-map",
+ NULL);
+   efi_reserve_memory(fdt_addr, fdt_size, nomap);
+   }
 subnode = fdt_next_subnode(fdt, subnode);
 }
 }
diff --git a/include/efi.h b/include/efi.h
index f986aad877..50190021ef 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -181,6 +181,9 @@ enum efi_mem_type {

 EFI_MAX_MEMORY_TYPE,
 EFI_TABLE_END,  /* For efi_build_mem_table() */
+
+   /* Memory that shall not be mapped */
+   EFI_NO_MAP_MEMORY,


Should it be named as EFI_NO_MAP_RSVD_MEMORY to avoid ambiguity ?


  };

  /* Attribute values */
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 7be756e370..d156b9533c 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -251,7 +251,7 @@ static efi_status_t efi_add_memory_map_pg(u64 start, u64 
pages,
 EFI_PRINT("%s: 0x%llx 0x%llx %d %s\n", __func__,

Re: [PATCH v5 10/10] am335x: add support for cape detect functionality

2021-05-13 Thread Tom Rini
On Tue, May 04, 2021 at 07:31:30PM +0200, Kory Maincent wrote:

> Update the Kconfig and the board file to make the am335x board compatible
> with cape detection.
> 
> Signed-off-by: Kory Maincent 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 09/10] arm: am335x: add support for i2c2 bus

2021-05-13 Thread Tom Rini
On Tue, May 04, 2021 at 07:31:29PM +0200, Kory Maincent wrote:

> The am335x from BeagleBone use i2c EEPROM to detect capes.
> The memory is wired to i2c bus 2 therefore it need to be enabled.
> 
> Add i2c2 clock, pinmux description and pinmux enable function.
> 
> Signed-off-by: Kory Maincent 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 08/10] configs: CHIP: add support for DIP detect functionality

2021-05-13 Thread Tom Rini
On Tue, May 04, 2021 at 07:31:28PM +0200, Kory Maincent wrote:

> This commit enables using the extension board detection mechanism on
> CHIP boards
> 
> Signed-off-by: Kory Maincent 
> Acked-by: Maxime Ripard 
> Acked-by: Andre Przywara 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 06/10] w1: replace dt detection by automatic detection

2021-05-13 Thread Tom Rini
On Tue, May 04, 2021 at 07:31:26PM +0200, Kory Maincent wrote:

> This patch changes the functioning of the detection of w1 devices.
> The old way was a comparison between detected w1 and the ones described in
> the device tree. Now it will just look for the driver matching the family
> id of the w1 detected.
> 
> The patch is inspired from Maxime Ripard code.
> 
> Signed-off-by: Kory Maincent 
> Reviewed-by: Maxime Ripard 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 07/10] arm: sunxi: add support for DIP detection to CHIP board

2021-05-13 Thread Tom Rini
On Tue, May 04, 2021 at 07:31:27PM +0200, Kory Maincent wrote:

> Add the extension_board_scan specific function to scan the information
> of the EEPROM on one-wire and fill the extension struct.
> Add the Kconfig symbol to enable the needs to detect DIPs.
> 
> Signed-off-by: Kory Maincent 
> Reviewed-by: Maxime Ripard 
> Acked-by: Andre Przywara 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 05/10] am57xx: add support for cape detect functionality

2021-05-13 Thread Tom Rini
On Tue, May 04, 2021 at 07:31:25PM +0200, Kory Maincent wrote:

> This commit enables using the extension board detection mechanism on
> AM57xx based platforms.
> 
> Signed-off-by: Kory Maincent 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 03/10] pytest: add sandbox test for "extension" command

2021-05-13 Thread Tom Rini
On Tue, May 04, 2021 at 07:31:23PM +0200, Kory Maincent wrote:

> This commit extends the sandbox to implement a dummy
> extension_board_scan() function and enables the extension command in
> the sandbox configuration. It then adds a test that checks the proper
> functionality of the extension command by applying two Device Tree
> overlays to the sandbox Device Tree.
> 
> Signed-off-by: Kory Maincent 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 04/10] ti/common: add support for extension_scan_board function

2021-05-13 Thread Tom Rini
On Tue, May 04, 2021 at 07:31:24PM +0200, Kory Maincent wrote:

> The BeagleBone platforms all use a common mechanism to discover and
> identify extension boards (called "capes"): each extension board has an
> I2C-connected EEPROM describing itself.
> 
> This patch implements a generic extension_scan_board() feature that can
> be used by all BeagleBone platforms to read those I2C EEPROMs and fill
> in the list of "extension" structures.
> 
> Following commits will enable this common logic on two BeagleBone
> platforms.
> 
> Signed-off-by: Kory Maincent 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 02/10] cmd: add support for a new "extension" command

2021-05-13 Thread Tom Rini
On Tue, May 04, 2021 at 07:31:22PM +0200, Kory Maincent wrote:

> This patch adds a new "extension" command, which aims at detecting
> extension boards connected to the hardware platform, and apply the
> Device Tree overlays that describe the hardware present on those
> extension boards.
> 
> In order to enable this mechanism, board-specific code must implement
> the extension_board_scan() function that fills in a linked list of
> "struct extension", each describing one extension board. In addition,
> the board-specific code must select the SUPPORT_EXTENSION_SCAN Kconfig
> boolean.
> 
> Based on this:
> 
>  - "extension scan" makes the generic code call the board-specific
>extension_board_scan() function to retrieve the list of detected
>extension boards.
> 
>  - "extension list" allows to list the detected extension boards.
> 
>  - "extension apply |all" allows to apply the Device Tree
>overlay(s) corresponding to one, or all, extension boards
> 
> The latter requires two environment variables to exist and set one variable
> to run:
> 
>  - extension_overlay_addr: the RAM address where to load the Device
>Tree overlays
> 
>  - extension_overlay_cmd: the U-Boot command to load one overlay.
>Indeed, the location and mechanism to load DT overlays is very setup
>specific.
> 
>  - extension_overlay_name: set by the command: the name of the DT which
>will be load during the execution.
> 
> When calling the command described in the extension_overlay_cmd
> variable, the variable extension_overlay_name will be defined. So a
> typical extension_overlay_cmd will look like this:
> 
>   extension_overlay_cmd=load mmc 0:1 $extension_overlay_addr 
> /boot/$extension_overlay_name
> 
> Here is an example on how to use it:
> => run loadfdt
> => fdt addr $fdtaddr
> => setenv extension_overlay_addr 0x1000
> => setenv extension_overlay_cmd 'load mmc 0:1 ${extension_overlay_addr} 
> /boot/${extension_overlay_name}'
> => extension scan
> Found 1 extension board(s).
> => extension apply 0
> 519 bytes read in 3 ms (168.9 KiB/s)
> 
> Signed-off-by: Kory Maincent 
> Reviewed-by: Maxime Ripard 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 01/10] fdt_support: move fdt_valid from cmd_fdt.c to fdt_support.c

2021-05-13 Thread Tom Rini
On Tue, May 04, 2021 at 07:31:21PM +0200, Kory Maincent wrote:

> Move the fdt_valid function to fdt_support.
> This changes allow to be able to test the validity of a devicetree in
> other c files.
> 
> Update code syntax.
> 
> Signed-off-by: Kory Maincent 
> Reviewed-by: Tom Rini 
> Reviewed-by: Maxime Ripard 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/4] tools: mkeficapsule: add firmwware image signing

2021-05-13 Thread Heinrich Schuchardt

On 5/13/21 10:18 AM, Masami Hiramatsu wrote:

2021年5月13日(木) 16:24 AKASHI Takahiro :


BTW, IMHO, if u-boot.bin can not find the ESL in the device tree,
it should skip authentication too.


In this case the capsule should be rejected (if
CONFIG_EFI_CAPSULE_AUTHENTICATE=y).


That's basically right.
But as I mentioned in my comment against Sughosh's patch,
the authentication process will be enforced only if the capsule has
an attribute, IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED.



That would be a security desaster.


The requirement that I mentioned above is clearly described
in UEFI specification.
If you think that it is a disaster, please discuss the topic
in UEFI Forum first.


I confirmed UEFI specification, version 2.7, Section.23.1
the last of EFI_FIRMWARE_MANAGEMENT_PROTOCOL.GetImageInfo()

-
If IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED is supported and clear, then
authentication is not required to perform the firmware image operations.
-


IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED bit is a property of the FMP driver.

Best regards

Heinrich



Oh, this is really crazy because deciding whether to authenticate the
suspicious
package or not, depends on whether the package said "please
authenticate me" or not. :D

Anyway, since this behavior follows the specification, it should be
kept by default,
but also IMHO, there should be a CONFIG option to enforce capsule
authentication always.

Thank you,







Re: [PATCH] efi_loader: consider no-map property of reserved memory

2021-05-13 Thread Atish Patra
On Mon, May 10, 2021 at 4:47 PM Atish Patra  wrote:
>
> On Wed, Sep 2, 2020 at 12:10 AM Heinrich Schuchardt  
> wrote:
> >
> > On 31.08.20 20:08, Atish Patra wrote:
> > > On Thu, Aug 27, 2020 at 9:16 AM Heinrich Schuchardt  
> > > wrote:
> > >>
> > >> If a reserved memory node in the device tree has the property no-map,
> > >> remove it from the UEFI memory map provided by GetMemoryMap().
> > >>
> > >> Signed-off-by: Heinrich Schuchardt 
> >
> > In the mail-thread starting a
> >
> > [PATCH 1/1] EBBR: GetMemoryMap(), handling of no-map DT property
> > https://lists.linaro.org/pipermail/boot-architecture/2020-September/001389.html
> >
> > the issue has been discussed. The conclusion was that we should not
> > change the current behavior.
> >
>
> Digging some old threads :)
>
> The merged version of the patch marks any reserved memory as
> EFI_BOOT_SERVICES_DATA.
> AFAIK, these memory regions will be available after ExitBootservice.
> If the operating system chooses to
> map these region and access them, it violates the purpose of the
> reserved memory region specified by the firmware.
>
> Did I miss something ?
>

ping ?

> > Best regards
> >
> > Heinrich
> >
> > >> ---
> > >>  cmd/bootefi.c   | 34 --
> > >>  include/efi.h   |  3 +++
> > >>  lib/efi_loader/efi_memory.c |  7 +--
> > >>  3 files changed, 36 insertions(+), 8 deletions(-)
> > >>
> > >> diff --git a/cmd/bootefi.c b/cmd/bootefi.c
> > >> index 40d5ef2b3a..f173105251 100644
> > >> --- a/cmd/bootefi.c
> > >> +++ b/cmd/bootefi.c
> > >> @@ -135,12 +135,29 @@ done:
> > >> return ret;
> > >>  }
> > >>
> > >> -static void efi_reserve_memory(u64 addr, u64 size)
> > >> +/**
> > >> + * efi_reserve_memory() - add reserved memory to memory map
> > >> + *
> > >> + * @addr:  start address of the reserved memory range
> > >> + * @size:  size of the reserved memory range
> > >> + * @nomap: indicates that the memory range shall be hidden from the 
> > >> memory
> > >> + * map
> > >> + */
> > >> +static void efi_reserve_memory(u64 addr, u64 size, bool nomap)
> > >>  {
> > >> +   int type;
> > >> +   efi_uintn_t ret;
> > >> +
> > >> /* Convert from sandbox address space. */
> > >> addr = (uintptr_t)map_sysmem(addr, 0);
> > >> -   if (efi_add_memory_map(addr, size,
> > >> -  EFI_RESERVED_MEMORY_TYPE) != EFI_SUCCESS)
> > >> +
> > >> +   if (nomap)
> > >> +   type = EFI_NO_MAP_MEMORY;
> > >> +   else
> > >> +   type = EFI_RESERVED_MEMORY_TYPE;
> > >> +
> > >> +   ret = efi_add_memory_map(addr, size, type);
> > >> +   if (ret != EFI_SUCCESS)
> > >> log_err("Reserved memory mapping failed addr %llx size 
> > >> %llx\n",
> > >> addr, size);
> > >>  }
> > >> @@ -166,7 +183,7 @@ static void efi_carve_out_dt_rsv(void *fdt)
> > >> for (i = 0; i < nr_rsv; i++) {
> > >> if (fdt_get_mem_rsv(fdt, i, , ) != 0)
> > >> continue;
> > >> -   efi_reserve_memory(addr, size);
> > >> +   efi_reserve_memory(addr, size, false);
> > >> }
> > >>
> > >> /* process reserved-memory */
> > >> @@ -186,8 +203,13 @@ static void efi_carve_out_dt_rsv(void *fdt)
> > >>  * a size instead of a reg property.
> > >>  */
> > >> if (fdt_addr != FDT_ADDR_T_NONE &&
> > >> -   fdtdec_get_is_enabled(fdt, subnode))
> > >> -   efi_reserve_memory(fdt_addr, fdt_size);
> > >> +   fdtdec_get_is_enabled(fdt, subnode)) {
> > >> +   bool nomap;
> > >> +
> > >> +   nomap = !!fdt_getprop(fdt, subnode, 
> > >> "no-map",
> > >> + NULL);
> > >> +   efi_reserve_memory(fdt_addr, fdt_size, 
> > >> nomap);
> > >> +   }
> > >> subnode = fdt_next_subnode(fdt, subnode);
> > >> }
> > >> }
> > >> diff --git a/include/efi.h b/include/efi.h
> > >> index f986aad877..50190021ef 100644
> > >> --- a/include/efi.h
> > >> +++ b/include/efi.h
> > >> @@ -181,6 +181,9 @@ enum efi_mem_type {
> > >>
> > >> EFI_MAX_MEMORY_TYPE,
> > >> EFI_TABLE_END,  /* For efi_build_mem_table() */
> > >> +
> > >> +   /* Memory that shall not be mapped */
> > >> +   EFI_NO_MAP_MEMORY,
> > >
> > > Should it be named as EFI_NO_MAP_RSVD_MEMORY to avoid ambiguity ?
> > >
> > >>  };
> > >>
> > >>  /* Attribute values */
> > >> diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
> > >> index 7be756e370..d156b9533c 100644
> > >> --- a/lib/efi_loader/efi_memory.c
> > >> +++ b/lib/efi_loader/efi_memory.c
> > >> @@ -251,7 +251,7 @@ static efi_status_t efi_add_memory_map_pg(u64 

Re: [PATCH 2/4] tools: mkeficapsule: remove device-tree related operation

2021-05-13 Thread Heinrich Schuchardt

On 5/13/21 9:13 AM, AKASHI Takahiro wrote:

On Thu, May 13, 2021 at 07:08:12AM +0200, Heinrich Schuchardt wrote:

On 5/13/21 4:33 AM, AKASHI Takahiro wrote:

On Wed, May 12, 2021 at 12:01:32PM +0200, Heinrich Schuchardt wrote:

On 12.05.21 10:01, Ilias Apalodimas wrote:

On Wed, May 12, 2021 at 04:49:02PM +0900, Masami Hiramatsu wrote:

Hi Ilias,

2021年5月12日(水) 16:21 Ilias Apalodimas :


Akashi-san,

On Wed, May 12, 2021 at 01:57:51PM +0900, AKASHI Takahiro wrote:

As we discussed, "-K" and "-D" options have nothing to do with
creating a capsule file. The same result can be obtained by
using standard commands like:
=== signature.dts ===
/dts-v1/;
/plugin/;

&{/} {
  signature {
  capsule-key = /incbin/("SIGNER.esl");
  };
};
===
$ dtc -@ -I dts -O dtb -o signature.dtbo signature.dts
$ fdtoverlay -i test.dtb -o test_sig.dtb -v signature.dtbo

So just remove this feature.
(Effectively revert the commit 322c813f4bec ("mkeficapsule: Add support
for embedding public key in a dtb").)

The same feature is implemented by a shell script (tools/fdtsig.sh).



The only reason I can see to keep this, is if mkeficapsule gets included
intro distro packages in the future.  That would make end users life a bit
easier, since they would need a single binary to create the whole
CapsuleUpdate sequence.


Hmm, I think it is better to write a manpage of mkeficapsule which
also describes
how to embed the key into dtb as in the above example if it is so short.
Or, distros can package the above shell script with mkeficapsule.

Embedding a key and signing a capsule are different operations but
using the same tool may confuse users (at least me).


Sure fair enough.  I am merely pointing out we need a way to explain all of
those to users.


This is currently our only documentation:

https://u-boot.readthedocs.io/en/latest/board/emulation/qemu_capsule_update.html?highlight=mkeficapsule


As I mentioned several times (and TODO in the cover letter),
this text must be reviewed, revised and generalized
as a platform-independent document.
It contains a couple of errors.


For mkimage we have a man-page ./doc/mkimage.1 that is packaged with
Debians u-boot-tools package. Please, provide a similar man-page as
./doc/mkeficapsule.1.


So after all do you agree to removing "-K/-D"?


I see no need to replicate in U-Boot what is already in the device tree
compiler package.


This is another reason that we should remove Sughosh's change.


In the current workflow the fdt command is used to load the public key.
This is insecure and not usable for production.


I totally disagree.
Why is using fdt command (what do you mean by fdt command, dtc/fdtoverlay?)
insecure?


A user can load an insecure capsule.

The fdt command is in /cmd/fdt.c and you are referring to it in
board/emulation/qemu_capsule_update.rst.




The public key used to verify the capsule must be built into the U-Boot
binary. This will supplant the -K and -D options.


I don't get your point. You don't understand my code.

Even with Sughosh's original patch, the public key (as I said,
it is not a public key but a X509 certificate in ESL format) is
embedded in the U-Boot's "control device tree".


No, the ESL file it is not built into U-Boot's control device tree.

A user is loading it and updating the control device tree.

You shouldn't trust anything a user has loaded. You need at least the
public key of the root CA built somewhere into U-Boot.

The 'fdt resize' command may overwrite code. This is not what you want
to do with the control device tree.

If CONFIG_OF_LIVE=y, the active device tree is not at $fdtcontroladdr
but in a hierarchical structure. You cannot update it via the fdt command.



Even after applying my patch, this is true.

Or are you insisting that the key should not be in the device tree?


The public key of the root CA must not be in a place where it can be
changed by a user while the device is in deployed mode.

The device-tree based design is a good feasibility study but not
suitable for production.

Best regards

Heinrich


Re: [PATCH 2/2] reset: Let reset API's handle gracefully if reset_ctl is -ENODATA

2021-05-13 Thread Simon Glass
Hi Kishon,

On Thu, 13 May 2021 at 00:30, Kishon Vijay Abraham I  wrote:
>
> Hi Simon,
>
> On 07/05/21 10:04 pm, Simon Glass wrote:
> > Hi Kishon,
> >
> > On Fri, 7 May 2021 at 05:02, Kishon Vijay Abraham I  wrote:
> >>
> >> Let reset API's (like reset_assert(), reset_deassert(), ..) handle
> >> gracefully if the argument reset_ctl is -ENODATA. This is for seamlessly
> >> handling client drivers which get optional reset controller using
> >> devm_reset_control_get_optional().
> >>
> >> Signed-off-by: Kishon Vijay Abraham I 
> >> ---
> >>  drivers/reset/reset-uclass.c | 35 +--
> >>  1 file changed, 29 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
> >> index 906f58ce3d..077ca956f4 100644
> >> --- a/drivers/reset/reset-uclass.c
> >> +++ b/drivers/reset/reset-uclass.c
> >> @@ -162,7 +162,12 @@ int reset_get_by_name(struct udevice *dev, const char 
> >> *name,
> >>
> >>  int reset_request(struct reset_ctl *reset_ctl)
> >>  {
> >> -   struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
> >> +   struct reset_ops *ops;
> >> +
> >> +   if (IS_ERR(reset_ctl) && PTR_ERR(reset_ctl) == -ENODATA)
> >> +   return 0;
> >
> > This should call reset_valid(), not do things here. Also I thought we
> > came to the conclusion that reset_ctl would always be a valid pointer?
> >
> > In any case, if you change the logic of these function, you must also
> > change the header, otherwise there is no docs.
> >
> > Finally, can you please update the tests?
>
> Patch 1 updates sandbox_reset_test_get_devm() in sandbox-reset-test.c.
> That's the only test I saw was using optional reset APIs. Do you think
> any thing else needs to be updated?

My point is that if you are changing the logic of reset_request(), you
should add a test for it and you need to update the docs.

Do you have someone at TI that can work through this with you? I am
not the maintainer of this subsystem, nor the expert here, but I feel
it could use a review with someone else as well, to really nut out all
the issues once and for all.

Regards,
Simon


Re: [PATCH 1/4] tools: mkeficapsule: add firmwware image signing

2021-05-13 Thread Ilias Apalodimas
[...]
> > > FWIW I personally don't think we should even have a config option. But 
> > > even
> > > if we did it certainly must not be dictated by a hardware config.
> > > 
> > > When you install distro packages you accept whatever dependencies the
> > > package has. mkeficapsule is a capsule creation and signing tool.  I don't
> > > see any reason for keeping the creation and signing apart.
> > 
> > My question is, since the U-Boot binary is heavily dependent on the target
> > platform, can we split the u-boot.bin creation (may include embedding keys)
> > and the capsule file creation (including signing)?
> 
> Building U-Boot and creating a capsule are totally separate. Maybe you
> get the first capsule years after you buy your board. But this should
> not stop us from building mkeficapsule when building U-Boot.
> 

Based on what was discussed in the thread waht I think would make more
sense is:
- Build u-boot and use the script Akashi sent to inject the certificate. 
  Whether we create a single binary (always signed if a config option is
  there) or 2 binaries (1 signed. 1 unsigned) is an implemetation detail
  and I am fine with either.
- Use mkefi capsule to create the final capsule

> If you want to build tools only, you can do so with 'make tools'. The
> tools target must include mkeficapsule irrespective of configuration.
> 
> This line in tools/Makefile must be corrected:
> 
> -hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule
> +hostprogs-y += mkeficapsule

So that's the point exactly. Building the tool is completely disjoint from
building a u-boot binary.   Also you usually start adding config options to
an app, when it starts getting to big and you want discrete functionality. 
I don't see any reason for making a simple tool, which is supposed to do 2
things (create/sign), require config options and more over config options
*for U-Boot*. I also think it's extremely unlikely to get any working distro 
without libssl. 

> 
> Best regards
> 
> Heinrich


Re: [PATCH 1/4] tools: mkeficapsule: add firmwware image signing

2021-05-13 Thread Heinrich Schuchardt

On 5/13/21 6:12 PM, Masami Hiramatsu wrote:

2021年5月13日(木) 19:27 Ilias Apalodimas :


On Thu, May 13, 2021 at 05:38:51PM +0900, AKASHI Takahiro wrote:

On Thu, May 13, 2021 at 05:18:36PM +0900, Masami Hiramatsu wrote:

2021年5月13日(木) 16:24 AKASHI Takahiro :


BTW, IMHO, if u-boot.bin can not find the ESL in the device tree,
it should skip authentication too.


In this case the capsule should be rejected (if
CONFIG_EFI_CAPSULE_AUTHENTICATE=y).


That's basically right.
But as I mentioned in my comment against Sughosh's patch,
the authentication process will be enforced only if the capsule has
an attribute, IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED.



That would be a security desaster.


The requirement that I mentioned above is clearly described
in UEFI specification.
If you think that it is a disaster, please discuss the topic
in UEFI Forum first.


I confirmed UEFI specification, version 2.7, Section.23.1
the last of EFI_FIRMWARE_MANAGEMENT_PROTOCOL.GetImageInfo()

-
If IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED is supported and clear, then
authentication is not required to perform the firmware image operations.
-


Thank you for citing this.


Oh, this is really crazy because deciding whether to authenticate the
suspicious
package or not, depends on whether the package said "please
authenticate me" or not. :D


Well, the attributes can been fetched with GetInfo API, but
how it is managed depends on the implementation of FMP drivers.

As I proposed somewhere else, those attributes should be
maintained in a separate place (maybe as part of system's policy),
presumably ESRT or platform-specific internal database?


FWIW I personally don't think we should even have a config option. But even
if we did it certainly must not be dictated by a hardware config.

When you install distro packages you accept whatever dependencies the
package has. mkeficapsule is a capsule creation and signing tool.  I don't
see any reason for keeping the creation and signing apart.


My question is, since the U-Boot binary is heavily dependent on the target
platform, can we split the u-boot.bin creation (may include embedding keys)
and the capsule file creation (including signing)?


Building U-Boot and creating a capsule are totally separate. Maybe you
get the first capsule years after you buy your board. But this should
not stop us from building mkeficapsule when building U-Boot.

If you want to build tools only, you can do so with 'make tools'. The
tools target must include mkeficapsule irrespective of configuration.

This line in tools/Makefile must be corrected:

-hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule
+hostprogs-y += mkeficapsule

Best regards

Heinrich


Re: [PATCH v2 16/50] image: Add Kconfig options for FIT in the host build

2021-05-13 Thread Alex G.




On 5/12/21 12:30 PM, Simon Glass wrote:

Hi Alex,

On Wed, 12 May 2021 at 10:18, Alex G.  wrote:




On 5/12/21 10:54 AM, Simon Glass wrote:

Hi Alex,

On Wed, 12 May 2021 at 09:48, Alex G.  wrote:




On 5/12/21 9:51 AM, Simon Glass wrote:

Hi Alex,

On Tue, 11 May 2021 at 13:57, Alex G.  wrote:


On 5/6/21 9:24 AM, Simon Glass wrote:


[snip]




+
+config HOST_FIT_PRINT
+ def_bool y
+ help
+   Print the content of the FIT verbosely in the host build


This option also doesn't make sense.This seems to do what 'mkimage -l'
already supports.


Are you sure you have looked at the goal of the CONFIG_IS_ENABLED()
changes? This is here purely to avoid #ifdefs in the share code.


On the one hand, we have the cosmetic inconvenience caused by #ifdefs.
On the other hand we have the config system. To most users, the config
system is likely more visible, while it's mostly developers who will
ever see the ifdefs.

Therefore, in order to get the developer convenience of less ifdefs, we
have to sacrifice user convenience by cloberring the Kconfig options. I
think this is back-to-front.


These Kconfig options are not visible to users. They cannot be updated
in defconfig, nor in 'make menuconfig', etc. They are purely there for
the build system.



Can we reduce the host config count to just SLL/NOSSL?


The point here is that the code has a special case for host builds,
and this is a means to remove that special case and make the code
easier to maintain and follow.


I understand where you're coming from. Without these changes, the code
knows what it should and should not do, correct? My argument is that if
the code has the logic to do the correct thing, that logic should not be
split with the config system.

I agree with the goal of reducing clutter in the source code. I disagree
with this specific course of fixing it. Instead, I propose a single
kconfig for host tools for SSL on/off.

The disadvantage of my proposal is that we have to refactor the common
code in a way consistent with the goals, instead of just changing some
#ifdefs to if(CONFIG_IS_ENABLED()). I admit that, off the top of my
head, I don't have a detailed plan on how to achieve this.


You are mostly describing the status quo, so far as I understand it.
The problem is with the code that is built for both boards and tools.
For boards, we want this code to be compiled conditionally, depending
on what options are enabled. For tools, we want the code to be
compiled unconditionally.

I can think of only three ways to do this:

- status quo (add #ifdefs USE_HOSTCC wherever we need to)
- my series (make use of hidden Kconfig options to avoid that)
- put every single feature and associated lines of code in separate
files and compile them conditionally for boards, but always for tools

I believe the last option is actually impossible, or at least
impractical. It would cause an explosion of source files to deal with
all the various combinations, and would be quite painful to maintain
also.


I don't think the status quo is such a terrible solution, so I am 
looking at the aspects that can benefit from improvement. Hence why it 
may appear I am talking about the status quo.


Let's assume CONFIG_IS_ENABLED() returns true on host builds, and for 
those cases where you need to know if IS_HOST_BUILD(), there's a macro 
for that. You have the oddball case that uses a CONFIG_ value that's 
only defined on the target, and those you would have to split according 
to your option #3.


I don't think the above is as dire an explosion in source files as it seems.

Another point of contention is checksum_algos and crypto_algos arrays 
image-sig.c. On the target side, these should be in .u-boot-list. Status 
quo is the definition of rsa_verify is hidden behind #if macros, which 
just pushes the complexity out into the rsa.h headers.


The two ideas here are CONFIG_IS_ENABLED() returns true for host code, 
and image-sig.c is split bwtween host and target versions, the target 
version making use of .uboot-list. Using these as the starting points, I 
think we can get to a much better solution


Alex




Re: [PATCH 1/4] tools: mkeficapsule: add firmwware image signing

2021-05-13 Thread Masami Hiramatsu
2021年5月13日(木) 19:27 Ilias Apalodimas :
>
> On Thu, May 13, 2021 at 05:38:51PM +0900, AKASHI Takahiro wrote:
> > On Thu, May 13, 2021 at 05:18:36PM +0900, Masami Hiramatsu wrote:
> > > 2021年5月13日(木) 16:24 AKASHI Takahiro :
> > >
> > > > > >> > BTW, IMHO, if u-boot.bin can not find the ESL in the device tree,
> > > > > >> > it should skip authentication too.
> > > > > >>
> > > > > >> In this case the capsule should be rejected (if
> > > > > >> CONFIG_EFI_CAPSULE_AUTHENTICATE=y).
> > > > > >
> > > > > >That's basically right.
> > > > > >But as I mentioned in my comment against Sughosh's patch,
> > > > > >the authentication process will be enforced only if the capsule has
> > > > > >an attribute, IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED.
> > > > > >
> > > > >
> > > > > That would be a security desaster.
> > > >
> > > > The requirement that I mentioned above is clearly described
> > > > in UEFI specification.
> > > > If you think that it is a disaster, please discuss the topic
> > > > in UEFI Forum first.
> > >
> > > I confirmed UEFI specification, version 2.7, Section.23.1
> > > the last of EFI_FIRMWARE_MANAGEMENT_PROTOCOL.GetImageInfo()
> > >
> > > -
> > > If IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED is supported and clear, then
> > > authentication is not required to perform the firmware image operations.
> > > -
> >
> > Thank you for citing this.
> >
> > > Oh, this is really crazy because deciding whether to authenticate the
> > > suspicious
> > > package or not, depends on whether the package said "please
> > > authenticate me" or not. :D
> >
> > Well, the attributes can been fetched with GetInfo API, but
> > how it is managed depends on the implementation of FMP drivers.
> >
> > As I proposed somewhere else, those attributes should be
> > maintained in a separate place (maybe as part of system's policy),
> > presumably ESRT or platform-specific internal database?
>
> FWIW I personally don't think we should even have a config option. But even
> if we did it certainly must not be dictated by a hardware config.
>
> When you install distro packages you accept whatever dependencies the
> package has. mkeficapsule is a capsule creation and signing tool.  I don't
> see any reason for keeping the creation and signing apart.

My question is, since the U-Boot binary is heavily dependent on the target
platform, can we split the u-boot.bin creation (may include embedding keys)
and the capsule file creation (including signing)?

Thank you,

-- 
Masami Hiramatsu


Re: [PATCH] fastboot: Fix overflow when calculating chunk size

2021-05-13 Thread Sean Anderson

Hi Lukasz,

Can this make it into 2020.07? Thanks,

--Sean

On 4/16/21 5:58 PM, Sean Anderson wrote:

If a chunk was larger than 4GiB, then chunk_data_sz would overflow and
blkcnt would not be calculated correctly. Upgrade it to a u64 and cast
its multiplicands as well. Also fix bytes_written while we're at it.

Signed-off-by: Sean Anderson 
---

  lib/image-sparse.c | 12 ++--
  1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/image-sparse.c b/lib/image-sparse.c
index 187ac28cd3..52c8dcc08c 100644
--- a/lib/image-sparse.c
+++ b/lib/image-sparse.c
@@ -55,10 +55,10 @@ int write_sparse_image(struct sparse_storage *info,
lbaint_t blk;
lbaint_t blkcnt;
lbaint_t blks;
-   uint32_t bytes_written = 0;
+   uint64_t bytes_written = 0;
unsigned int chunk;
unsigned int offset;
-   unsigned int chunk_data_sz;
+   uint64_t chunk_data_sz;
uint32_t *fill_buf = NULL;
uint32_t fill_val;
sparse_header_t *sparse_header;
@@ -132,7 +132,7 @@ int write_sparse_image(struct sparse_storage *info,
 sizeof(chunk_header_t));
}
  
-		chunk_data_sz = sparse_header->blk_sz * chunk_header->chunk_sz;

+   chunk_data_sz = ((u64)sparse_header->blk_sz) * 
chunk_header->chunk_sz;
blkcnt = chunk_data_sz / info->blksz;
switch (chunk_header->chunk_type) {
case CHUNK_TYPE_RAW:
@@ -162,7 +162,7 @@ int write_sparse_image(struct sparse_storage *info,
return -1;
}
blk += blks;
-   bytes_written += blkcnt * info->blksz;
+   bytes_written += ((u64)blkcnt) * info->blksz;
total_blocks += chunk_header->chunk_sz;
data += chunk_data_sz;
break;
@@ -222,7 +222,7 @@ int write_sparse_image(struct sparse_storage *info,
blk += blks;
i += j;
}
-   bytes_written += blkcnt * info->blksz;
+   bytes_written += ((u64)blkcnt) * info->blksz;
total_blocks += chunk_data_sz / sparse_header->blk_sz;
free(fill_buf);
break;
@@ -253,7 +253,7 @@ int write_sparse_image(struct sparse_storage *info,
  
  	debug("Wrote %d blocks, expected to write %d blocks\n",

  total_blocks, sparse_header->total_blks);
-   printf(" wrote %u bytes to '%s'\n", bytes_written, part_name);
+   printf(" wrote %llu bytes to '%s'\n", bytes_written, part_name);
  
  	if (total_blocks != sparse_header->total_blks) {

info->mssg("sparse image write failure", response);



Re: Please pull u-boot-marvell/master

2021-05-13 Thread Tom Rini
On Thu, May 13, 2021 at 12:21:38PM +0200, Stefan Roese wrote:

> Hi Tom,
> 
> please pull the next batch of Marvell Armada related patches. Here the
> summary log:
> 
> 
> - Add base support for Marvell OcteonTX2 CN9130 DB (mostly done
>   by Kostya)
> - Sync Armada mvpp2 ethernet driver with Marvell version (misc Marvell
>   authors)
> - Sync Armada 8k MMU setup with Marvell version (misc Marvell
>   authors)
> - spi: kirkwood: Some fixes especially for baudrate generation
>   (misc Marvell authors)
> - mvebu: x530: Reduce SPL image size (Stefan)
> - Rename "rx_training" to "mvebu_comphy_rx_training" (Stefan)
> 
> 
> Here the Azure build:
> 
> https://dev.azure.com/sr0718/u-boot/_build/results?buildId=87=results

Note that this isn't publicly viewable, I think there's some permission
stuff on your profile you need to adjust.

> It shows some issues with xilinx_versal_virt, which seem to be not
> related to this patch set and also occurred yesterday.

I bisected this down to:
commit 368b3f6db4540f913c436e5287be8356bc9a2891
Author: Stefan Chulski 
Date:   Mon May 3 08:08:44 2021 +0200

phy: introduce 1000BaseX and 2500BaseX modes

Signed-off-by: Stefan Chulski 
Signed-off-by: Stefan Roese 

And while I'm not sure off-hand how it does it, it's causing the
breakage.  Maybe something is overflowing now?

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 3/3] hash: Allow for SHA512 hardware implementations

2021-05-13 Thread Heinrich Schuchardt

On 5/13/21 4:36 PM, Simon Glass wrote:

Hi Heinrich,

On Wed, 12 May 2021 at 15:27, Heinrich Schuchardt  wrote:


Am 12. Mai 2021 19:32:42 MESZ schrieb Simon Glass :

Hi Heinrich,

On Wed, 12 May 2021 at 10:25, Heinrich Schuchardt 
wrote:


On 12.05.21 18:05, Simon Glass wrote:

Hi Heinrich,

On Wed, 12 May 2021 at 10:01, Heinrich Schuchardt

 wrote:


On 17.02.21 04:20, Joel Stanley wrote:

Similar to support for SHA1 and SHA256, allow the use of hardware

hashing

engine by enabling the algorithm and setting  CONFIG_SHA_HW_ACCEL

/

CONFIG_SHA_PROG_HW_ACCEL.

Signed-off-by: Joel Stanley 


This merged patch leads to errors compiling the EFI TCG2 protocol

on

boards with CONFIG_SHA_HW_ACCEL.

There is not as single implementation of hw_sha384 and hw_sha512.

You

could only use CONFIG_SHA_HW_ACCEL for selecting these functions

if

these were implemented for *all* boards with

CONFIG_SHA_HW_ACCEL=y. But

this will never happen.

*This patch needs to be reverted.*

Why do we have CONFIG_SHA_HW_ACCEL at all and don't use weak

functions

instead?


This is all a mess. We should not use weak functions IMO, but

instead

have a driver interface, like we do with filesystems.

Part of the challenge is the need to keep code size small for
platforms that only need one algorithm.


If a function is not referenced, the linker will eliminate it. But

with

a driver interface every function in the interface is referenced.


Indeed, but we can still have an option for enabling the progressive
interface. My point is that the implementation (software or hardware)
should use a driver.

Regards,
Simon


Anyway that should not stop us from reverting a problematic patch. We can work 
on refactoring afterwards.


Well the patch was applied because tests passed. We should be careful
about reverting a patch due to problems it causes in the future.


The code compiled because SHA384 and SHA512 were not used together with
CONFIG_SHA_HW_ACCEL=y. But we need these functions to implement the TCG2
protocol on boards with TPMv2.

Gitlab CI had no issues with reverting the patch.

Best regards

Heinrich


Re: [PATCH v7 2/3] efi_loader: expose efi_image_parse() even if UEFI Secure Boot is disabled

2021-05-13 Thread Heinrich Schuchardt

On 5/13/21 4:48 PM, Masahisa Kojima wrote:

This is preparation for PE/COFF measurement support.
PE/COFF image hash calculation is same in both
UEFI Secure Boot image verification and measurement in
measured boot. PE/COFF image parsing functions are
gathered into efi_image_loader.c, and exposed even if
UEFI Secure Boot is not enabled.

This commit also adds the EFI_SIGNATURE_SUPPORT option
to decide if efi_signature.c shall be compiled.

Signed-off-by: Masahisa Kojima 
---

(no changes since v4)

Changes in v4:
- revert #ifdef instead of using "if (!IS_ENABLED())" statement,
   not to rely on the compiler optimization.

Changes in v3:
- hide EFI_SIGNATURE_SUPPORT option

Changes in v2:
- Remove all #ifdef from efi_image_loader.c and efi_signature.c
- Add EFI_SIGNATURE_SUPPORT option
- Explicitly include 
- Gather PE/COFF parsing functions into efi_image_loader.c
- Move efi_guid_t efi_guid_image_security_database in efi_var_common.c

  lib/efi_loader/Kconfig|  6 +++
  lib/efi_loader/Makefile   |  2 +-
  lib/efi_loader/efi_image_loader.c | 64 -
  lib/efi_loader/efi_signature.c| 67 +--
  lib/efi_loader/efi_var_common.c   |  3 ++
  5 files changed, 74 insertions(+), 68 deletions(-)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index eb5c4d6f29..dff85cea26 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -175,6 +175,7 @@ config EFI_CAPSULE_AUTHENTICATE
select PKCS7_VERIFY
select IMAGE_SIGN_INFO
select HASH_CALCULATE
+   select EFI_SIGNATURE_SUPPORT
default n
help
  Select this option if you want to enable capsule
@@ -344,6 +345,7 @@ config EFI_SECURE_BOOT
select PKCS7_MESSAGE_PARSER
select PKCS7_VERIFY
select HASH_CALCULATE
+   select EFI_SIGNATURE_SUPPORT
default n
help
  Select this option to enable EFI secure boot support.
@@ -351,6 +353,10 @@ config EFI_SECURE_BOOT
  it is signed with a trusted key. To do that, you need to install,
  at least, PK, KEK and db.

+config EFI_SIGNATURE_SUPPORT
+   bool
+   depends on EFI_SECURE_BOOT || EFI_CAPSULE_AUTHENTICATE


This line is superfluous. As it has no label the symbol will be false if
not selected by EFI_SECURE_BOOT or EFI_CAPSULE_AUTHENTICATE.

Best regards

Heinrich


+
  config EFI_ESRT
bool "Enable the UEFI ESRT generation"
depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 8bd343e258..fd344cea29 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -63,7 +63,7 @@ obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o
  obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o
  obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o
  obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o
-obj-y += efi_signature.o
+obj-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o

  EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE))
  $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE)
diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index f53ef367ec..fe1ee198e2 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -213,7 +213,68 @@ static void efi_set_code_and_data_type(
}
  }

-#ifdef CONFIG_EFI_SECURE_BOOT
+/**
+ * efi_image_region_add() - add an entry of region
+ * @regs:  Pointer to array of regions
+ * @start: Start address of region (included)
+ * @end:   End address of region (excluded)
+ * @nocheck:   flag against overlapped regions
+ *
+ * Take one entry of region [@start, @end[ and insert it into the list.
+ *
+ * * If @nocheck is false, the list will be sorted ascending by address.
+ *   Overlapping entries will not be allowed.
+ *
+ * * If @nocheck is true, the list will be sorted ascending by sequence
+ *   of adding the entries. Overlapping is allowed.
+ *
+ * Return: status code
+ */
+efi_status_t efi_image_region_add(struct efi_image_regions *regs,
+ const void *start, const void *end,
+ int nocheck)
+{
+   struct image_region *reg;
+   int i, j;
+
+   if (regs->num >= regs->max) {
+   EFI_PRINT("%s: no more room for regions\n", __func__);
+   return EFI_OUT_OF_RESOURCES;
+   }
+
+   if (end < start)
+   return EFI_INVALID_PARAMETER;
+
+   for (i = 0; i < regs->num; i++) {
+   reg = >reg[i];
+   if (nocheck)
+   continue;
+
+   /* new data after registered region */
+   if (start >= reg->data + reg->size)
+   continue;
+
+   /* new data preceding registered region */
+   if (end <= reg->data) {
+   for (j = regs->num - 1; j >= i; j--)
+   memcpy(>reg[j + 1], 

Re: [PATCH v7 1/3] lib: introduce HASH_CALCULATE option

2021-05-13 Thread Heinrich Schuchardt

On 5/13/21 4:48 PM, Masahisa Kojima wrote:

Build error occurs when CONFIG_EFI_SECURE_BOOT or
CONFIG_EFI_CAPSULE_AUTHENTICATE is enabled,
because hash-checksum.c is not compiled.

Since hash_calculate() implemented in hash-checksum.c can be
commonly used aside from FIT image signature verification,
this commit itroduces HASH_CALCULATE option to decide
if hash-checksum.c shall be compiled.

Signed-off-by: Masahisa Kojima 


Reviewed-by: Heinrich Schuchardt 


Re: [PATCH] Fix flash and erase of EMMC_BOOT2 with fastboot

2021-05-13 Thread Sean Anderson




On 5/13/21 11:07 AM, Oleh Kravchenko wrote:
> Hello Sean,
> I've used these commands:
>> fastboot flash mmc0boot0 u-boot-o4-imx6ull-nano.bin
>> fastboot flash mmc0boot1 u-boot-o4-imx6ull-nano.bin
>
>
> But these ones, doesn't work:
>> fastboot flash 0.0 u-boot-o4-imx6ull-nano.bin
>> Couldn't find partition mmc 0.0
>
>> fastboot flash 0.1 u-boot-o4-imx6ull-nano.bin
>> Couldn't find partition mmc 0.1

Hm, can you send me the U-Boot output?

Can you also try adding :0? I noticed it in my partition aliases:

"fastboot_aliases=setenv fastboot_partition_alias_user ${mmcdev}.0:0; " 
\
"setenv fastboot_partition_alias_boot0 ${mmcdev}.1:0; " \
"setenv fastboot_partition_alias_boot1 ${mmcdev}.2:0;\0" \

--Sean

>
>
> 13.05.21 18:01, Sean Anderson пише:
>> Hi,
>>
>> Have you considered trying to flash using e.g.
>>
>> flashboot flash 0.1 foo.img
>>
>> instead of
>>
>> fastboot flash boot0
>>
>> ? I would like to remove these MMC_BOOT2 options but I haven't gotten around 
to it.
>>
>> On 5/12/21 6:43 PM, Oleh Kravchenko wrote:
>>> The current U-Boot version has the next matches for boot partitions:
 mmc0boot0 to EMMC_BOOT1
 mmc0boot1 to EMMC_BOOT1 (should be EMMC_BOOT2)
>>> This patch fixes a typo for the boot partition number.
>>>
>>> Signed-off-by: Oleh Kravchenko 
>>> Cc: Pantelis Antoniou 
>>> Cc: Marek Vasut 
>>> ---
>>>
>>>drivers/fastboot/fb_mmc.c | 4 ++--
>>>1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
>>> index 8e74e50e91..1827ce5d12 100644
>>> --- a/drivers/fastboot/fb_mmc.c
>>> +++ b/drivers/fastboot/fb_mmc.c
>>> @@ -525,7 +525,7 @@ void fastboot_mmc_flash_write(const char *cmd, void 
*download_buffer,
>>>if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT2_NAME) == 0) {
>>>dev_desc = fastboot_mmc_get_dev(response);
>>>if (dev_desc)
>>> -fb_mmc_boot_ops(dev_desc, download_buffer, 1,
>>> +fb_mmc_boot_ops(dev_desc, download_buffer, 2,
>>>download_bytes, response);
>>>return;
>>>}
>>> @@ -655,7 +655,7 @@ void fastboot_mmc_erase(const char *cmd, char *response)
>>>/* erase EMMC boot2 */
>>>dev_desc = fastboot_mmc_get_dev(response);
>>>if (dev_desc)
>>> -fb_mmc_boot_ops(dev_desc, NULL, 1, 0, response);
>>> +fb_mmc_boot_ops(dev_desc, NULL, 2, 0, response);
>>>return;
>>>}
>>>#endif
>>>
>>
>> In any case,
>>
>> Reviewed-by: Sean Anderson 
>


Re: [PATCH] Fix flash and erase of EMMC_BOOT2 with fastboot

2021-05-13 Thread Oleh Kravchenko
Hello Sean,
I've used these commands:
> fastboot flash mmc0boot0 u-boot-o4-imx6ull-nano.bin
> fastboot flash mmc0boot1 u-boot-o4-imx6ull-nano.bin


But these ones, doesn't work:
> fastboot flash 0.0 u-boot-o4-imx6ull-nano.bin
> Couldn't find partition mmc 0.0

> fastboot flash 0.1 u-boot-o4-imx6ull-nano.bin
> Couldn't find partition mmc 0.1


13.05.21 18:01, Sean Anderson пише:
> Hi,
> 
> Have you considered trying to flash using e.g.
> 
> flashboot flash 0.1 foo.img
> 
> instead of
> 
> fastboot flash boot0
> 
> ? I would like to remove these MMC_BOOT2 options but I haven't gotten around 
> to it.
> 
> On 5/12/21 6:43 PM, Oleh Kravchenko wrote:
>> The current U-Boot version has the next matches for boot partitions:
>>> mmc0boot0 to EMMC_BOOT1
>>> mmc0boot1 to EMMC_BOOT1 (should be EMMC_BOOT2)
>> This patch fixes a typo for the boot partition number.
>>
>> Signed-off-by: Oleh Kravchenko 
>> Cc: Pantelis Antoniou 
>> Cc: Marek Vasut 
>> ---
>>
>>   drivers/fastboot/fb_mmc.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
>> index 8e74e50e91..1827ce5d12 100644
>> --- a/drivers/fastboot/fb_mmc.c
>> +++ b/drivers/fastboot/fb_mmc.c
>> @@ -525,7 +525,7 @@ void fastboot_mmc_flash_write(const char *cmd, void 
>> *download_buffer,
>>   if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT2_NAME) == 0) {
>>   dev_desc = fastboot_mmc_get_dev(response);
>>   if (dev_desc)
>> -    fb_mmc_boot_ops(dev_desc, download_buffer, 1,
>> +    fb_mmc_boot_ops(dev_desc, download_buffer, 2,
>>   download_bytes, response);
>>   return;
>>   }
>> @@ -655,7 +655,7 @@ void fastboot_mmc_erase(const char *cmd, char *response)
>>   /* erase EMMC boot2 */
>>   dev_desc = fastboot_mmc_get_dev(response);
>>   if (dev_desc)
>> -    fb_mmc_boot_ops(dev_desc, NULL, 1, 0, response);
>> +    fb_mmc_boot_ops(dev_desc, NULL, 2, 0, response);
>>   return;
>>   }
>>   #endif
>>
> 
> In any case,
> 
> Reviewed-by: Sean Anderson 

-- 
Best regards,
Oleh Kravchenko
Phone: +380972763224 | o...@kaa.org.ua | Skype: oleg_krava


Re: [PATCH] Fix flash and erase of EMMC_BOOT2 with fastboot

2021-05-13 Thread Sean Anderson

Hi,

Have you considered trying to flash using e.g.

flashboot flash 0.1 foo.img

instead of

fastboot flash boot0

? I would like to remove these MMC_BOOT2 options but I haven't gotten around to 
it.

On 5/12/21 6:43 PM, Oleh Kravchenko wrote:

The current U-Boot version has the next matches for boot partitions:

mmc0boot0 to EMMC_BOOT1
mmc0boot1 to EMMC_BOOT1 (should be EMMC_BOOT2)

This patch fixes a typo for the boot partition number.

Signed-off-by: Oleh Kravchenko 
Cc: Pantelis Antoniou 
Cc: Marek Vasut 
---

  drivers/fastboot/fb_mmc.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 8e74e50e91..1827ce5d12 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -525,7 +525,7 @@ void fastboot_mmc_flash_write(const char *cmd, void 
*download_buffer,
if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT2_NAME) == 0) {
dev_desc = fastboot_mmc_get_dev(response);
if (dev_desc)
-   fb_mmc_boot_ops(dev_desc, download_buffer, 1,
+   fb_mmc_boot_ops(dev_desc, download_buffer, 2,
download_bytes, response);
return;
}
@@ -655,7 +655,7 @@ void fastboot_mmc_erase(const char *cmd, char *response)
/* erase EMMC boot2 */
dev_desc = fastboot_mmc_get_dev(response);
if (dev_desc)
-   fb_mmc_boot_ops(dev_desc, NULL, 1, 0, response);
+   fb_mmc_boot_ops(dev_desc, NULL, 2, 0, response);
return;
}
  #endif



In any case,

Reviewed-by: Sean Anderson 


Re: [PATCH v7 1/3] lib: introduce HASH_CALCULATE option

2021-05-13 Thread Heinrich Schuchardt

On 5/13/21 4:48 PM, Masahisa Kojima wrote:

Build error occurs when CONFIG_EFI_SECURE_BOOT or
CONFIG_EFI_CAPSULE_AUTHENTICATE is enabled,
because hash-checksum.c is not compiled.

Since hash_calculate() implemented in hash-checksum.c can be
commonly used aside from FIT image signature verification,
this commit itroduces HASH_CALCULATE option to decide
if hash-checksum.c shall be compiled.

Signed-off-by: Masahisa Kojima 
---

Changes in v7:
- newly introduce HASH_CALCULATE option

Changes in v6:
- update lib/Makefile to compile hash-checksum.c, instead of
   selecting FIT_SIGNATURE in secure boot and capsule authentication.

Changes in v5:
- Missing option for EFI_TCG2_PROTOROL already added in different commit.
   This commit adds FIT_SIGNATURE only.

Changes in v4:
- newly added in this patch series, due to rebasing
   the base code.

  common/Kconfig.boot| 1 +
  lib/Kconfig| 3 +++
  lib/Makefile   | 2 +-
  lib/efi_loader/Kconfig | 2 ++
  4 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/common/Kconfig.boot b/common/Kconfig.boot
index 5a18d62d78..56608226cc 100644
--- a/common/Kconfig.boot
+++ b/common/Kconfig.boot
@@ -80,6 +80,7 @@ config FIT_SIGNATURE
select RSA_VERIFY
select IMAGE_SIGN_INFO
select FIT_FULL_CHECK
+   select HASH_CALCULATE
help
  This option enables signature verification of FIT uImages,
  using a hash signed and verified using RSA. If
diff --git a/lib/Kconfig b/lib/Kconfig
index 6d2d41de30..df67eb0503 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -428,6 +428,9 @@ config CRC32C
  config XXHASH
bool

+config HASH_CALCULATE
+   bool
+
  endmenu

  menu "Compression Support"
diff --git a/lib/Makefile b/lib/Makefile
index 6825671955..0835ea292c 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -61,7 +61,7 @@ endif
  obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi/
  obj-$(CONFIG_$(SPL_)MD5) += md5.o
  obj-$(CONFIG_$(SPL_)RSA) += rsa/
-obj-$(CONFIG_FIT_SIGNATURE) += hash-checksum.o


CONFIG_FIT_SIGNATURE has to select CONFIG_HASH_CALCULATE too?

Best regards

Heinrich


+obj-$(CONFIG_HASH_CALCULATE) += hash-checksum.o
  obj-$(CONFIG_SHA1) += sha1.o
  obj-$(CONFIG_SHA256) += sha256.o
  obj-$(CONFIG_SHA512_ALGO) += sha512.o
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index c259abe033..eb5c4d6f29 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -174,6 +174,7 @@ config EFI_CAPSULE_AUTHENTICATE
select PKCS7_MESSAGE_PARSER
select PKCS7_VERIFY
select IMAGE_SIGN_INFO
+   select HASH_CALCULATE
default n
help
  Select this option if you want to enable capsule
@@ -342,6 +343,7 @@ config EFI_SECURE_BOOT
select X509_CERTIFICATE_PARSER
select PKCS7_MESSAGE_PARSER
select PKCS7_VERIFY
+   select HASH_CALCULATE
default n
help
  Select this option to enable EFI secure boot support.





Re: [PATCH 1/1] sandbox: ensure that state->ram_buf is in low memory

2021-05-13 Thread Heinrich Schuchardt

On 5/13/21 4:36 PM, Simon Glass wrote:

Hi Heinrich,

On Wed, 12 May 2021 at 15:28, Heinrich Schuchardt  wrote:


Am 12. Mai 2021 18:01:17 MESZ schrieb Simon Glass :

Hi Heinrich,

On Tue, 11 May 2021 at 13:03, Heinrich Schuchardt 
wrote:


Addresses in state->ram_buf must be in the low 4 GiB of the address

space.

Otherwise we cannot correctly fill SMBIOS tables. This shows up in

warnings

like:

 WARNING: SMBIOS table_address overflow 7f752735e020


This sounds like a bug in the smbios-table code. For sandbox it should
perhaps use addresses instead of pointers.

I think that code (that I unfortunately wrote) was an expeditious way
of getting it running, but is not correct.


The field you are filling is only 32bit wide. I wonder how that table is meant 
to work on systems where the lowest memory address is above 4 GiB. Such ARMv8 
systems exist.


map_to_sysmem() will give you a 32-bit wide address. Yes SMBIOS is
legacy and designed for 4GB.


I know map_to_sysmem(). But you wrote in lib/smbios.c:487:

/*
 * We must use a pointer here so things work correctly on sandbox. The
 * user of this table is not aware of the mapping of addresses to
 * sandbox's DRAM buffer.
 */

For testing you could start a binary with command 'bootefi' or 'booti'
and that binary would analyze the table. So yes, your comment holds true
and you must not use map_to_sysmem() here.

Best regards

Heinrich



[PATCH v7 3/3] efi_loader: add PE/COFF image measurement

2021-05-13 Thread Masahisa Kojima
"TCG PC Client Platform Firmware Profile Specification"
requires to measure every attempt to load and execute
a OS Loader(a UEFI application) into PCR[4].
This commit adds the PE/COFF image measurement, extends PCR,
and appends measurement into Event Log.

Acked-by: Ilias Apalodimas 
Tested-by: Ilias Apalodimas 
Signed-off-by: Masahisa Kojima 
---

Changes in v7:
- include hash-checksum.h instead of rsa.h
- select HASH_CALCULATE in Kconfig, not to update lib/Makefile
- rebased the base code

Changes in v6:
- update lib/Makefile to add hash-checksum.c as a compilation target

(no changes since v2)

Changes in v2:
- Remove duplicate  include
- Remove unnecessary __packed attribute
- Add all EV_EFI_* event definition
- Create common function to prepare 8-byte aligned image
- Add measurement for EV_EFI_BOOT_SERVICES_DRIVER and
  EV_EFI_RUNTIME_SERVICES_DRIVER
- Use efi_search_protocol() to get device_path
- Add function comment

 include/efi_loader.h  |   6 +
 include/efi_tcg2.h|   9 ++
 include/tpm-v2.h  |  18 +++
 lib/efi_loader/Kconfig|   1 +
 lib/efi_loader/efi_image_loader.c |  59 +++--
 lib/efi_loader/efi_tcg2.c | 207 --
 6 files changed, 276 insertions(+), 24 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index de1a496a97..9f2854a255 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -426,6 +426,10 @@ efi_status_t efi_disk_register(void);
 efi_status_t efi_rng_register(void);
 /* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */
 efi_status_t efi_tcg2_register(void);
+/* measure the pe-coff image, extend PCR and add Event Log */
+efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size,
+  struct efi_loaded_image_obj *handle,
+  struct efi_loaded_image *loaded_image_info);
 /* Create handles and protocols for the partitions of a block device */
 int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
   const char *if_typename, int diskid,
@@ -847,6 +851,8 @@ bool efi_secure_boot_enabled(void);
 
 bool efi_capsule_auth_enabled(void);
 
+void *efi_prepare_aligned_image(void *efi, u64 *efi_size, void **new_efi);
+
 bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
 WIN_CERTIFICATE **auth, size_t *auth_len);
 
diff --git a/include/efi_tcg2.h b/include/efi_tcg2.h
index 40e241ce31..bcfb98168a 100644
--- a/include/efi_tcg2.h
+++ b/include/efi_tcg2.h
@@ -9,6 +9,7 @@
 #if !defined _EFI_TCG2_PROTOCOL_H_
 #define _EFI_TCG2_PROTOCOL_H_
 
+#include 
 #include 
 
 #define EFI_TCG2_PROTOCOL_GUID \
@@ -53,6 +54,14 @@ struct efi_tcg2_event {
u8 event[];
 } __packed;
 
+struct uefi_image_load_event {
+   efi_physical_addr_t image_location_in_memory;
+   u64 image_length_in_memory;
+   u64 image_link_time_address;
+   u64 length_of_device_path;
+   struct efi_device_path device_path[];
+};
+
 struct efi_tcg2_boot_service_capability {
u8 size;
struct efi_tcg2_version structure_version;
diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index 7de7d6a57d..247b386967 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -70,6 +70,24 @@ struct udevice;
 #define EV_TABLE_OF_DEVICES((u32)0x000B)
 #define EV_COMPACT_HASH((u32)0x000C)
 
+/*
+ * event types, cf.
+ * "TCG PC Client Platform Firmware Profile Specification", Family "2.0"
+ * rev 1.04, June 3, 2019
+ */
+#define EV_EFI_EVENT_BASE  ((u32)0x8000)
+#define EV_EFI_VARIABLE_DRIVER_CONFIG  ((u32)0x8001)
+#define EV_EFI_VARIABLE_BOOT   ((u32)0x8002)
+#define EV_EFI_BOOT_SERVICES_APPLICATION   ((u32)0x8003)
+#define EV_EFI_BOOT_SERVICES_DRIVER((u32)0x8004)
+#define EV_EFI_RUNTIME_SERVICES_DRIVER ((u32)0x8005)
+#define EV_EFI_GPT_EVENT   ((u32)0x8006)
+#define EV_EFI_ACTION  ((u32)0x8007)
+#define EV_EFI_PLATFORM_FIRMWARE_BLOB  ((u32)0x8008)
+#define EV_EFI_HANDOFF_TABLES  ((u32)0x8009)
+#define EV_EFI_HCRTM_EVENT ((u32)0x8010)
+#define EV_EFI_VARIABLE_AUTHORITY  ((u32)0x80E0)
+
 /* TPMS_TAGGED_PROPERTY Structure */
 struct tpms_tagged_property {
u32 property;
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index dff85cea26..312cc8cbbf 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -309,6 +309,7 @@ config EFI_TCG2_PROTOCOL
select SHA512_ALGO
select SHA384
select SHA512
+   select HASH_CALCULATE
help
  Provide a EFI_TCG2_PROTOCOL implementation using the TPM hardware
  of the platform.
diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index 

[PATCH v7 2/3] efi_loader: expose efi_image_parse() even if UEFI Secure Boot is disabled

2021-05-13 Thread Masahisa Kojima
This is preparation for PE/COFF measurement support.
PE/COFF image hash calculation is same in both
UEFI Secure Boot image verification and measurement in
measured boot. PE/COFF image parsing functions are
gathered into efi_image_loader.c, and exposed even if
UEFI Secure Boot is not enabled.

This commit also adds the EFI_SIGNATURE_SUPPORT option
to decide if efi_signature.c shall be compiled.

Signed-off-by: Masahisa Kojima 
---

(no changes since v4)

Changes in v4:
- revert #ifdef instead of using "if (!IS_ENABLED())" statement,
  not to rely on the compiler optimization.

Changes in v3:
- hide EFI_SIGNATURE_SUPPORT option

Changes in v2:
- Remove all #ifdef from efi_image_loader.c and efi_signature.c
- Add EFI_SIGNATURE_SUPPORT option
- Explicitly include 
- Gather PE/COFF parsing functions into efi_image_loader.c
- Move efi_guid_t efi_guid_image_security_database in efi_var_common.c

 lib/efi_loader/Kconfig|  6 +++
 lib/efi_loader/Makefile   |  2 +-
 lib/efi_loader/efi_image_loader.c | 64 -
 lib/efi_loader/efi_signature.c| 67 +--
 lib/efi_loader/efi_var_common.c   |  3 ++
 5 files changed, 74 insertions(+), 68 deletions(-)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index eb5c4d6f29..dff85cea26 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -175,6 +175,7 @@ config EFI_CAPSULE_AUTHENTICATE
select PKCS7_VERIFY
select IMAGE_SIGN_INFO
select HASH_CALCULATE
+   select EFI_SIGNATURE_SUPPORT
default n
help
  Select this option if you want to enable capsule
@@ -344,6 +345,7 @@ config EFI_SECURE_BOOT
select PKCS7_MESSAGE_PARSER
select PKCS7_VERIFY
select HASH_CALCULATE
+   select EFI_SIGNATURE_SUPPORT
default n
help
  Select this option to enable EFI secure boot support.
@@ -351,6 +353,10 @@ config EFI_SECURE_BOOT
  it is signed with a trusted key. To do that, you need to install,
  at least, PK, KEK and db.
 
+config EFI_SIGNATURE_SUPPORT
+   bool
+   depends on EFI_SECURE_BOOT || EFI_CAPSULE_AUTHENTICATE
+
 config EFI_ESRT
bool "Enable the UEFI ESRT generation"
depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 8bd343e258..fd344cea29 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -63,7 +63,7 @@ obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o
 obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o
 obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o
 obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o
-obj-y += efi_signature.o
+obj-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o
 
 EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE))
 $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE)
diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index f53ef367ec..fe1ee198e2 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -213,7 +213,68 @@ static void efi_set_code_and_data_type(
}
 }
 
-#ifdef CONFIG_EFI_SECURE_BOOT
+/**
+ * efi_image_region_add() - add an entry of region
+ * @regs:  Pointer to array of regions
+ * @start: Start address of region (included)
+ * @end:   End address of region (excluded)
+ * @nocheck:   flag against overlapped regions
+ *
+ * Take one entry of region [@start, @end[ and insert it into the list.
+ *
+ * * If @nocheck is false, the list will be sorted ascending by address.
+ *   Overlapping entries will not be allowed.
+ *
+ * * If @nocheck is true, the list will be sorted ascending by sequence
+ *   of adding the entries. Overlapping is allowed.
+ *
+ * Return: status code
+ */
+efi_status_t efi_image_region_add(struct efi_image_regions *regs,
+ const void *start, const void *end,
+ int nocheck)
+{
+   struct image_region *reg;
+   int i, j;
+
+   if (regs->num >= regs->max) {
+   EFI_PRINT("%s: no more room for regions\n", __func__);
+   return EFI_OUT_OF_RESOURCES;
+   }
+
+   if (end < start)
+   return EFI_INVALID_PARAMETER;
+
+   for (i = 0; i < regs->num; i++) {
+   reg = >reg[i];
+   if (nocheck)
+   continue;
+
+   /* new data after registered region */
+   if (start >= reg->data + reg->size)
+   continue;
+
+   /* new data preceding registered region */
+   if (end <= reg->data) {
+   for (j = regs->num - 1; j >= i; j--)
+   memcpy(>reg[j + 1], >reg[j],
+  sizeof(*reg));
+   break;
+   }
+
+   /* new data overlapping registered region */
+   EFI_PRINT("%s: new region 

[PATCH v7 1/3] lib: introduce HASH_CALCULATE option

2021-05-13 Thread Masahisa Kojima
Build error occurs when CONFIG_EFI_SECURE_BOOT or
CONFIG_EFI_CAPSULE_AUTHENTICATE is enabled,
because hash-checksum.c is not compiled.

Since hash_calculate() implemented in hash-checksum.c can be
commonly used aside from FIT image signature verification,
this commit itroduces HASH_CALCULATE option to decide
if hash-checksum.c shall be compiled.

Signed-off-by: Masahisa Kojima 
---

Changes in v7:
- newly introduce HASH_CALCULATE option

Changes in v6:
- update lib/Makefile to compile hash-checksum.c, instead of
  selecting FIT_SIGNATURE in secure boot and capsule authentication.

Changes in v5:
- Missing option for EFI_TCG2_PROTOROL already added in different commit.
  This commit adds FIT_SIGNATURE only.

Changes in v4:
- newly added in this patch series, due to rebasing
  the base code.

 common/Kconfig.boot| 1 +
 lib/Kconfig| 3 +++
 lib/Makefile   | 2 +-
 lib/efi_loader/Kconfig | 2 ++
 4 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/common/Kconfig.boot b/common/Kconfig.boot
index 5a18d62d78..56608226cc 100644
--- a/common/Kconfig.boot
+++ b/common/Kconfig.boot
@@ -80,6 +80,7 @@ config FIT_SIGNATURE
select RSA_VERIFY
select IMAGE_SIGN_INFO
select FIT_FULL_CHECK
+   select HASH_CALCULATE
help
  This option enables signature verification of FIT uImages,
  using a hash signed and verified using RSA. If
diff --git a/lib/Kconfig b/lib/Kconfig
index 6d2d41de30..df67eb0503 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -428,6 +428,9 @@ config CRC32C
 config XXHASH
bool
 
+config HASH_CALCULATE
+   bool
+
 endmenu
 
 menu "Compression Support"
diff --git a/lib/Makefile b/lib/Makefile
index 6825671955..0835ea292c 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -61,7 +61,7 @@ endif
 obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi/
 obj-$(CONFIG_$(SPL_)MD5) += md5.o
 obj-$(CONFIG_$(SPL_)RSA) += rsa/
-obj-$(CONFIG_FIT_SIGNATURE) += hash-checksum.o
+obj-$(CONFIG_HASH_CALCULATE) += hash-checksum.o
 obj-$(CONFIG_SHA1) += sha1.o
 obj-$(CONFIG_SHA256) += sha256.o
 obj-$(CONFIG_SHA512_ALGO) += sha512.o
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index c259abe033..eb5c4d6f29 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -174,6 +174,7 @@ config EFI_CAPSULE_AUTHENTICATE
select PKCS7_MESSAGE_PARSER
select PKCS7_VERIFY
select IMAGE_SIGN_INFO
+   select HASH_CALCULATE
default n
help
  Select this option if you want to enable capsule
@@ -342,6 +343,7 @@ config EFI_SECURE_BOOT
select X509_CERTIFICATE_PARSER
select PKCS7_MESSAGE_PARSER
select PKCS7_VERIFY
+   select HASH_CALCULATE
default n
help
  Select this option to enable EFI secure boot support.
-- 
2.17.1



[PATCH v7 0/3] PE/COFF measurement support

2021-05-13 Thread Masahisa Kojima
This patch series add the PE/COFF measurement support.
Extending PCR and Event Log is tested with fTPM
running as a OP-TEE TA.
Unit test will be added in the separate series.

Masahisa Kojima (3):
  lib: introduce HASH_CALCULATE option
  efi_loader: expose efi_image_parse() even if UEFI Secure Boot is
disabled
  efi_loader: add PE/COFF image measurement

 common/Kconfig.boot   |   1 +
 include/efi_loader.h  |   6 +
 include/efi_tcg2.h|   9 ++
 include/tpm-v2.h  |  18 +++
 lib/Kconfig   |   3 +
 lib/Makefile  |   2 +-
 lib/efi_loader/Kconfig|   9 ++
 lib/efi_loader/Makefile   |   2 +-
 lib/efi_loader/efi_image_loader.c | 123 +++---
 lib/efi_loader/efi_signature.c|  67 +-
 lib/efi_loader/efi_tcg2.c | 207 --
 lib/efi_loader/efi_var_common.c   |   3 +
 12 files changed, 357 insertions(+), 93 deletions(-)

-- 
2.17.1



[PATCH 1/1] sandbox: add symbol _init for RISC-V compilation

2021-05-13 Thread Heinrich Schuchardt
The sandbox does not build on RISC-V when _init is not defined. Errors like
the following were observed. Which function was referred to depended on the
configuration.

/usr/bin/ld: common/built-in.o: in function `parse_stream_outer':
/common/cli_hush.c:3175: undefined reference to `_init'
collect2: error: ld returned 1 exit status
make: *** [Makefile:1726: u-boot] Error 1

/usr/bin/ld: common/built-in.o: in function `bootdelay_process':
common/autoboot.c:335: undefined reference to `_init'
collect2: error: ld returned 1 exit status
make: *** [Makefile:1726: u-boot] Error 1

Signed-off-by: Heinrich Schuchardt 
---
 arch/sandbox/cpu/u-boot.lds | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds
index a1f509c9ab..d9e7ffcea3 100644
--- a/arch/sandbox/cpu/u-boot.lds
+++ b/arch/sandbox/cpu/u-boot.lds
@@ -9,6 +9,8 @@ SECTIONS
 {

. = ALIGN(4);
+   /* RISC-V GCC wants this dummy symbol */
+   _init = .;
.u_boot_list : {
KEEP(*(SORT(.u_boot_list*)));
}
--
2.30.2



Re: [PATCH 1/1] sandbox: ensure that state->ram_buf is in low memory

2021-05-13 Thread Simon Glass
Hi Heinrich,

On Wed, 12 May 2021 at 15:28, Heinrich Schuchardt  wrote:
>
> Am 12. Mai 2021 18:01:17 MESZ schrieb Simon Glass :
> >Hi Heinrich,
> >
> >On Tue, 11 May 2021 at 13:03, Heinrich Schuchardt 
> >wrote:
> >>
> >> Addresses in state->ram_buf must be in the low 4 GiB of the address
> >space.
> >> Otherwise we cannot correctly fill SMBIOS tables. This shows up in
> >warnings
> >> like:
> >>
> >> WARNING: SMBIOS table_address overflow 7f752735e020
> >
> >This sounds like a bug in the smbios-table code. For sandbox it should
> >perhaps use addresses instead of pointers.
> >
> >I think that code (that I unfortunately wrote) was an expeditious way
> >of getting it running, but is not correct.
>
> The field you are filling is only 32bit wide. I wonder how that table is 
> meant to work on systems where the lowest memory address is above 4 GiB. Such 
> ARMv8 systems exist.

map_to_sysmem() will give you a 32-bit wide address. Yes SMBIOS is
legacy and designed for 4GB.

Regards,
Simon


Re: [PATCH 3/3] hash: Allow for SHA512 hardware implementations

2021-05-13 Thread Simon Glass
Hi Heinrich,

On Wed, 12 May 2021 at 15:27, Heinrich Schuchardt  wrote:
>
> Am 12. Mai 2021 19:32:42 MESZ schrieb Simon Glass :
> >Hi Heinrich,
> >
> >On Wed, 12 May 2021 at 10:25, Heinrich Schuchardt 
> >wrote:
> >>
> >> On 12.05.21 18:05, Simon Glass wrote:
> >> > Hi Heinrich,
> >> >
> >> > On Wed, 12 May 2021 at 10:01, Heinrich Schuchardt
> > wrote:
> >> >>
> >> >> On 17.02.21 04:20, Joel Stanley wrote:
> >> >>> Similar to support for SHA1 and SHA256, allow the use of hardware
> >hashing
> >> >>> engine by enabling the algorithm and setting  CONFIG_SHA_HW_ACCEL
> >/
> >> >>> CONFIG_SHA_PROG_HW_ACCEL.
> >> >>>
> >> >>> Signed-off-by: Joel Stanley 
> >> >>
> >> >> This merged patch leads to errors compiling the EFI TCG2 protocol
> >on
> >> >> boards with CONFIG_SHA_HW_ACCEL.
> >> >>
> >> >> There is not as single implementation of hw_sha384 and hw_sha512.
> >You
> >> >> could only use CONFIG_SHA_HW_ACCEL for selecting these functions
> >if
> >> >> these were implemented for *all* boards with
> >CONFIG_SHA_HW_ACCEL=y. But
> >> >> this will never happen.
> >> >>
> >> >> *This patch needs to be reverted.*
> >> >>
> >> >> Why do we have CONFIG_SHA_HW_ACCEL at all and don't use weak
> >functions
> >> >> instead?
> >> >
> >> > This is all a mess. We should not use weak functions IMO, but
> >instead
> >> > have a driver interface, like we do with filesystems.
> >> >
> >> > Part of the challenge is the need to keep code size small for
> >> > platforms that only need one algorithm.
> >>
> >> If a function is not referenced, the linker will eliminate it. But
> >with
> >> a driver interface every function in the interface is referenced.
> >
> >Indeed, but we can still have an option for enabling the progressive
> >interface. My point is that the implementation (software or hardware)
> >should use a driver.
> >
> >Regards,
> >Simon
>
> Anyway that should not stop us from reverting a problematic patch. We can 
> work on refactoring afterwards.

Well the patch was applied because tests passed. We should be careful
about reverting a patch due to problems it causes in the future.

Regards,
Simon


Re: [PATCH v2] Fix flashing of eMMC user area with Fastboot

2021-05-13 Thread Oleh Kravchenko
Hello guys,
Could you please review this patch?

> 13 трав. 2021 р. о 17:23 Oleh Kravchenko  пише:
> 
> 'gpt' and 'mmc0' fastboot partitions have been treated as the same device,
> but it is wrong.
> 
> Signed-off-by: Oleh Kravchenko 
> Cc: Pantelis Antoniou 
> Cc: Marek Vasut 
> ---
> 
> drivers/fastboot/fb_mmc.c | 21 -
> 1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
> index 8e74e50e91..a590c23a79 100644
> --- a/drivers/fastboot/fb_mmc.c
> +++ b/drivers/fastboot/fb_mmc.c
> @@ -532,12 +532,7 @@ void fastboot_mmc_flash_write(const char *cmd, void 
> *download_buffer,
> #endif
> 
> #if CONFIG_IS_ENABLED(EFI_PARTITION)
> -#ifndef CONFIG_FASTBOOT_MMC_USER_SUPPORT
>if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
> -#else
> -if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0 ||
> -strcmp(cmd, CONFIG_FASTBOOT_MMC_USER_NAME) == 0) {
> -#endif
>dev_desc = fastboot_mmc_get_dev(response);
>if (!dev_desc)
>return;
> @@ -599,9 +594,25 @@ void fastboot_mmc_flash_write(const char *cmd, void 
> *download_buffer,
>}
> #endif
> 
> +if (IS_ENABLED(CONFIG_FASTBOOT_MMC_USER_SUPPORT) &&
> +strcmp(cmd, CONFIG_FASTBOOT_MMC_USER_NAME) == 0) {
> +dev_desc = fastboot_mmc_get_dev(response);
> +if (!dev_desc)
> +return;
> +
> +memset(, 0, sizeof(info));
> +info.start= 0;
> +info.size= dev_desc->lba;
> +info.blksz= dev_desc->blksz;
> +strlcpy((char *), cmd, sizeof(info.name));
> +
> +goto flash_image;
> +}
> +
>if (fastboot_mmc_get_part_info(cmd, _desc, , response) < 0)
>return;
> 
> +flash_image:
>if (is_sparse_image(download_buffer)) {
>struct fb_mmc_sparse sparse_priv;
>struct sparse_storage sparse;
> -- 
> 2.26.3
> 



[PATCH v2] Fix flashing of eMMC user area with Fastboot

2021-05-13 Thread Oleh Kravchenko
'gpt' and 'mmc0' fastboot partitions have been treated as the same device,
but it is wrong.

Signed-off-by: Oleh Kravchenko 
Cc: Pantelis Antoniou 
Cc: Marek Vasut 
---

 drivers/fastboot/fb_mmc.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 8e74e50e91..a590c23a79 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -532,12 +532,7 @@ void fastboot_mmc_flash_write(const char *cmd, void 
*download_buffer,
 #endif
 
 #if CONFIG_IS_ENABLED(EFI_PARTITION)
-#ifndef CONFIG_FASTBOOT_MMC_USER_SUPPORT
if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
-#else
-   if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0 ||
-   strcmp(cmd, CONFIG_FASTBOOT_MMC_USER_NAME) == 0) {
-#endif
dev_desc = fastboot_mmc_get_dev(response);
if (!dev_desc)
return;
@@ -599,9 +594,25 @@ void fastboot_mmc_flash_write(const char *cmd, void 
*download_buffer,
}
 #endif
 
+   if (IS_ENABLED(CONFIG_FASTBOOT_MMC_USER_SUPPORT) &&
+   strcmp(cmd, CONFIG_FASTBOOT_MMC_USER_NAME) == 0) {
+   dev_desc = fastboot_mmc_get_dev(response);
+   if (!dev_desc)
+   return;
+
+   memset(, 0, sizeof(info));
+   info.start  = 0;
+   info.size   = dev_desc->lba;
+   info.blksz  = dev_desc->blksz;
+   strlcpy((char *), cmd, sizeof(info.name));
+
+   goto flash_image;
+   }
+
if (fastboot_mmc_get_part_info(cmd, _desc, , response) < 0)
return;
 
+flash_image:
if (is_sparse_image(download_buffer)) {
struct fb_mmc_sparse sparse_priv;
struct sparse_storage sparse;
-- 
2.26.3



[PATCH] Fix flashing of eMMC user area with Fastboot

2021-05-13 Thread Oleh Kravchenko
Signed-off-by: Oleh Kravchenko 
Cc: Pantelis Antoniou 
Cc: Marek Vasut 
---
 drivers/fastboot/fb_mmc.c | 22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 8e74e50e91..7e61fbac17 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -532,12 +532,7 @@ void fastboot_mmc_flash_write(const char *cmd, void 
*download_buffer,
 #endif
 
 #if CONFIG_IS_ENABLED(EFI_PARTITION)
-#ifndef CONFIG_FASTBOOT_MMC_USER_SUPPORT
if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
-#else
-   if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0 ||
-   strcmp(cmd, CONFIG_FASTBOOT_MMC_USER_NAME) == 0) {
-#endif
dev_desc = fastboot_mmc_get_dev(response);
if (!dev_desc)
return;
@@ -599,9 +594,26 @@ void fastboot_mmc_flash_write(const char *cmd, void 
*download_buffer,
}
 #endif
 
+#if CONFIG_IS_ENABLED(FASTBOOT_MMC_USER_SUPPORT)
+   if (strcmp(cmd, CONFIG_FASTBOOT_MMC_USER_NAME) == 0) {
+   dev_desc = fastboot_mmc_get_dev(response);
+   if (!dev_desc)
+   return;
+
+   memset(, 0, sizeof(info));
+   info.start  = 0;
+   info.size   = dev_desc->lba;
+   info.blksz  = dev_desc->blksz;
+   strlcpy((char *), cmd, sizeof(info.name));
+
+   goto flash_image;
+   }
+#endif
+
if (fastboot_mmc_get_part_info(cmd, _desc, , response) < 0)
return;
 
+flash_image:
if (is_sparse_image(download_buffer)) {
struct fb_mmc_sparse sparse_priv;
struct sparse_storage sparse;
-- 
2.26.3



Re: [PATCH v6 1/3] lib: fix build error for secure boot and capsule authentication

2021-05-13 Thread Masahisa Kojima
On Thu, 13 May 2021 at 16:52, Takahiro Akashi
 wrote:
>
> On Thu, May 13, 2021 at 04:18:29PM +0900, Masahisa Kojima wrote:
> > Build error occurs when CONFIG_EFI_SECURE_BOOT or
> > CONFIG_EFI_CAPSULE_AUTHENTICATE is enabled,
> > because hash-checksum.c is not compiled.
> >
> > This commit adds hash-checksum.c as a compilation target
> > if CONFIG_EFI_SECURE_BOOT or CONFIG_EFI_CAPSULE_AUTHENTICATE
> > is enabled.
> >
> > Signed-off-by: Masahisa Kojima 
> > ---
> >
> > Changes in v6:
> > - update lib/Makefile to compile hash-checksum.c, instead of
> >   selecting FIT_SIGNATURE in secure boot and capsule authentication.
> >
> > Changes in v5:
> > - Missing option for EFI_TCG2_PROTOROL already added in different commit.
> >   This commit adds FIT_SIGNATURE only.
> >
> > Changes in v4:
> > - newly added in this patch series, due to rebasing
> >   the base code.
> >
> >  lib/Makefile | 5 -
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/Makefile b/lib/Makefile
> > index 6825671955..bd022dd5d3 100644
> > --- a/lib/Makefile
> > +++ b/lib/Makefile
> > @@ -61,7 +61,10 @@ endif
> >  obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi/
> >  obj-$(CONFIG_$(SPL_)MD5) += md5.o
> >  obj-$(CONFIG_$(SPL_)RSA) += rsa/
> > -obj-$(CONFIG_FIT_SIGNATURE) += hash-checksum.o
> > +ifneq (,$(filter y,$(CONFIG_FIT_SIGNATURE)$(CONFIG_EFI_SECURE_BOOT)\
> > +$(CONFIG_EFI_CAPSULE_AUTHENTICATE)))
> > +obj-y += hash-checksum.o
> > +endif
>
> Why not create a new kconfig option here?
> There is a good reason to do so if there are more than one users.
>
> Otherwise, every new user of hash_calculate() needs
> to modify generic Makefile.

I agree with this suggestion, I will send new patch.
Thank you for your comment.

Thanks,
Masahisa Kojima
>
> -Takahiro Akashi
>
>
> >  obj-$(CONFIG_SHA1) += sha1.o
> >  obj-$(CONFIG_SHA256) += sha256.o
> >  obj-$(CONFIG_SHA512_ALGO) += sha512.o
> > --
> > 2.17.1
> >


Re: [PATCH v5 00/10] Add support for extension boards detection and DT overlays application

2021-05-13 Thread Thomas Petazzoni
On Thu, 13 May 2021 08:18:53 -0400
Tom Rini  wrote:

> > Do not hesitate to let us know what is needed to get this series
> > considered for merging.  
> 
> Thanks for the reminder.  I've fixed up a small issue with the test (it
> needs to only run on sandbox and not say real hardware wit CMD_FDT) and
> am otherwise world build testing it again now.

Excellent, thanks. Once again, do not hesitate to let us know if
there's any remaining issue to investigate and fix, or any concern
about the overall design/approach.

Best regards,

Thomas Petazzoni
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


Re: [PATCH v5 00/10] Add support for extension boards detection and DT overlays application

2021-05-13 Thread Tom Rini
On Wed, May 12, 2021 at 10:37:49PM +0200, Thomas Petazzoni wrote:
> Hello Tom,
> 
> On Tue,  4 May 2021 19:31:20 +0200
> Kory Maincent  wrote:
> 
> > Kory Maincent (10):
> >   fdt_support: move fdt_valid from cmd_fdt.c to fdt_support.c
> >   cmd: add support for a new "extension" command
> >   pytest: add sandbox test for "extension" command
> >   ti/common: add support for extension_scan_board function
> >   am57xx: add support for cape detect functionality
> >   w1: replace dt detection by automatic detection
> >   arm: sunxi: add support for DIP detection to CHIP board
> >   configs: CHIP: add support for DIP detect functionality
> >   arm: am335x: add support for i2c2 bus
> >   am335x: add support for cape detect functionality
> 
> This series has gone through 5 iterations since the first posting
> mid-February. On version 4, we haven't received any feedback except
> your request to resend an updated version based on the latest master.
> 
> What are the plans with this series? Do you expect to receive more
> reviews? Or do you plan to apply it? Indeed, as the only comment on v4
> was to rebase on master and v5 doesn't get apply soon enough, it will
> again no longer cleanly apply on master :-)
> 
> Do not hesitate to let us know what is needed to get this series
> considered for merging.

Thanks for the reminder.  I've fixed up a small issue with the test (it
needs to only run on sandbox and not say real hardware wit CMD_FDT) and
am otherwise world build testing it again now.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] riscv: Fix arch_fixup_fdt always failing without /chosen

2021-05-13 Thread Bin Meng
Hi Sean,

On Sun, May 9, 2021 at 12:24 AM Sean Anderson  wrote:
>
> On 5/8/21 12:22 PM, Bin Meng wrote:
> > On Sun, May 9, 2021 at 12:13 AM Sean Anderson  wrote:
> >>
> >> If /chosen was missing, chosen_offset would never get updated with the new
> >> /chosen node. This would cause fdt_setprop_u32 to fail. This patch fixes
> >> this by setting chosen_offset. In addition, log any errors from setting
> >> boot-hartid as well.
> >>
> >> Fixes: 177c53fe6c6 ("riscv: Move all fdt fixups together")
> >
> > I think the correct commit id to fix is:
> > commit 5370478d1c7afb8b2a8a0a00b31ff97c3a2c0451 ("riscv: Add boot
> > hartid to device tree")
>
> Ah, so it is.
>

Would you send v2 with the correct commit id?

Regards,
Bin


[PATCH 1/1] test: revert Don't unmount not (yet) mounted system

2021-05-13 Thread Heinrich Schuchardt
Since commit 1ba21bb06b08 ("test: Don't unmount not (yet) mounted system")
the following tests are skipped:

test/py/tests/test_fs/test_basic.py
test/py/tests/test_fs/test_ext.py

SKIPPED [13] test/py/tests/test_fs/conftest.py:350: Setup failed for
filesystem: ext4. Command 'guestmount -a
build-sandbox/persistent-data/3GB.ext4.img -m /dev/sda
build-sandbox/persistent-data/mnt' returned non-zero exit status 1.

Let's revert the patch to get our tests back.

Fixes: 1ba21bb06b08 ("test: Don't unmount not (yet) mounted system")
Signed-off-by: Heinrich Schuchardt 
---
 test/py/tests/test_fs/conftest.py | 78 +--
 test/run  |  8 ++--
 2 files changed, 26 insertions(+), 60 deletions(-)

diff --git a/test/py/tests/test_fs/conftest.py 
b/test/py/tests/test_fs/conftest.py
index 50af9efcf7..ec70e8c4ef 100644
--- a/test/py/tests/test_fs/conftest.py
+++ b/test/py/tests/test_fs/conftest.py
@@ -270,20 +270,9 @@ def fs_obj_basic(request, u_boot_config):

 # 3GiB volume
 fs_img = mk_fs(u_boot_config, fs_type, 0xc000, '3GB')
-except CalledProcessError as err:
-pytest.skip('Creating failed for filesystem: ' + fs_type + '. 
{}'.format(err))
-return
-
-try:
-check_call('mkdir -p %s' % mount_dir, shell=True)
-except CalledProcessError as err:
-pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type 
+ '. {}'.format(err))
-return
-finally:
-call('rm -f %s' % fs_img, shell=True)

-try:
 # Mount the image so we can populate it.
+check_call('mkdir -p %s' % mount_dir, shell=True)
 mount_fs(fs_type, fs_img, mount_dir)

 # Create a subdirectory.
@@ -346,15 +335,18 @@ def fs_obj_basic(request, u_boot_config):
% big_file, shell=True).decode()
 md5val.append(out.split()[0])

+umount_fs(mount_dir)
 except CalledProcessError as err:
-pytest.skip('Setup failed for filesystem: ' + fs_type + '. 
{}'.format(err))
+pytest.skip('Setup failed for filesystem: ' + fs_type + \
+'. {}'.format(err))
 return
 else:
 yield [fs_ubtype, fs_img, md5val]
 finally:
 umount_fs(mount_dir)
 call('rmdir %s' % mount_dir, shell=True)
-call('rm -f %s' % fs_img, shell=True)
+if fs_img:
+call('rm -f %s' % fs_img, shell=True)

 #
 # Fixture for extended fs test
@@ -386,20 +378,9 @@ def fs_obj_ext(request, u_boot_config):

 # 128MiB volume
 fs_img = mk_fs(u_boot_config, fs_type, 0x800, '128MB')
-except CalledProcessError as err:
-pytest.skip('Creating failed for filesystem: ' + fs_type + '. 
{}'.format(err))
-return
-
-try:
-check_call('mkdir -p %s' % mount_dir, shell=True)
-except CalledProcessError as err:
-pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type 
+ '. {}'.format(err))
-return
-finally:
-call('rm -f %s' % fs_img, shell=True)

-try:
 # Mount the image so we can populate it.
+check_call('mkdir -p %s' % mount_dir, shell=True)
 mount_fs(fs_type, fs_img, mount_dir)

 # Create a test directory
@@ -441,6 +422,7 @@ def fs_obj_ext(request, u_boot_config):
 md5val.append(out.split()[0])

 check_call('rm %s' % tmp_file, shell=True)
+umount_fs(mount_dir)
 except CalledProcessError:
 pytest.skip('Setup failed for filesystem: ' + fs_type)
 return
@@ -449,7 +431,8 @@ def fs_obj_ext(request, u_boot_config):
 finally:
 umount_fs(mount_dir)
 call('rmdir %s' % mount_dir, shell=True)
-call('rm -f %s' % fs_img, shell=True)
+if fs_img:
+call('rm -f %s' % fs_img, shell=True)

 #
 # Fixture for mkdir test
@@ -477,10 +460,11 @@ def fs_obj_mkdir(request, u_boot_config):
 fs_img = mk_fs(u_boot_config, fs_type, 0x800, '128MB')
 except:
 pytest.skip('Setup failed for filesystem: ' + fs_type)
-return
 else:
 yield [fs_ubtype, fs_img]
-call('rm -f %s' % fs_img, shell=True)
+finally:
+if fs_img:
+call('rm -f %s' % fs_img, shell=True)

 #
 # Fixture for unlink test
@@ -509,20 +493,9 @@ def fs_obj_unlink(request, u_boot_config):

 # 128MiB volume
 fs_img = mk_fs(u_boot_config, fs_type, 0x800, '128MB')
-except CalledProcessError as err:
-pytest.skip('Creating failed for filesystem: ' + fs_type + '. 
{}'.format(err))
-return
-
-try:
-check_call('mkdir -p %s' % mount_dir, shell=True)
-except CalledProcessError as err:
-pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type 
+ '. {}'.format(err))
-return
-finally:
-call('rm -f %s' % fs_img, shell=True)

-try:
 # Mount the image so we can populate it.
+check_call('mkdir -p %s' % mount_dir, shell=True)
 

Re: [PATCH v2 4/4] test: Don't unmount not (yet) mounted system

2021-05-13 Thread Heinrich Schuchardt

On 2/11/21 3:40 PM, Andy Shevchenko wrote:

When test suite tries to create a file for a new filesystem test case and fails,
the clean up of the exception tries to unmount the image, that has not yet been
mounted. When it happens, the fuse_mounted global variable is set to False and
inconveniently the test case tries to use sudo, so without this change the
admin of the machine gets an (annoying) email:

   Subject: *** SECURITY information for example.com ***

   example.com : Feb  5 19:43:47 : ... COMMAND=/bin/umount 
.../build-sandbox/persistent-data/mnt

and second run of the test cases on uncleaned build folder will ask for sudo
which is not what expected.

Besides that there is a double unmount calls during successfully run test case.

All of these due to over engineered Python try-except clause and people didn't
get it properly at all. The rule of thumb is that don't use more keywords than
try-except in the exception handling code. Nevertheless, here we adjust code
to be less intrusive to the initial logic behind that complex and unclear
constructions in the test case, although it adds a lot of lines of the code,
i.e. splits one exception handler to three, so on each step we know what
cleanup shall perform.

Signed-off-by: Andy Shevchenko 


Dear Andy,

with this merged patch the following tests are not executed anymore locally:

test/py/tests/test_fs/test_basic.py
test/py/tests/test_fs/test_ext.py

SKIPPED [13] test/py/tests/test_fs/conftest.py:350: Setup failed for
filesystem: ext4. Command 'guestmount -a
build-sandbox/persistent-data/3GB.ext4.img -m /dev/sda
build-sandbox/persistent-data/mnt' returned non-zero exit status 1.

Please, revert the patch or fix it.

Best regards

Heinrich


Reviewed-by: Simon Glass 
---
v2: new patch
  test/py/tests/test_fs/conftest.py | 78 ++-
  1 file changed, 56 insertions(+), 22 deletions(-)

diff --git a/test/py/tests/test_fs/conftest.py 
b/test/py/tests/test_fs/conftest.py
index ec70e8c4ef3f..50af9efcf768 100644
--- a/test/py/tests/test_fs/conftest.py
+++ b/test/py/tests/test_fs/conftest.py
@@ -270,9 +270,20 @@ def fs_obj_basic(request, u_boot_config):

  # 3GiB volume
  fs_img = mk_fs(u_boot_config, fs_type, 0xc000, '3GB')
+except CalledProcessError as err:
+pytest.skip('Creating failed for filesystem: ' + fs_type + '. 
{}'.format(err))
+return

-# Mount the image so we can populate it.
+try:
  check_call('mkdir -p %s' % mount_dir, shell=True)
+except CalledProcessError as err:
+pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type 
+ '. {}'.format(err))
+return
+finally:
+call('rm -f %s' % fs_img, shell=True)
+
+try:
+# Mount the image so we can populate it.
  mount_fs(fs_type, fs_img, mount_dir)

  # Create a subdirectory.
@@ -335,18 +346,15 @@ def fs_obj_basic(request, u_boot_config):
% big_file, shell=True).decode()
  md5val.append(out.split()[0])

-umount_fs(mount_dir)
  except CalledProcessError as err:
-pytest.skip('Setup failed for filesystem: ' + fs_type + \
-'. {}'.format(err))
+pytest.skip('Setup failed for filesystem: ' + fs_type + '. 
{}'.format(err))
  return
  else:
  yield [fs_ubtype, fs_img, md5val]
  finally:
  umount_fs(mount_dir)
  call('rmdir %s' % mount_dir, shell=True)
-if fs_img:
-call('rm -f %s' % fs_img, shell=True)
+call('rm -f %s' % fs_img, shell=True)

  #
  # Fixture for extended fs test
@@ -378,9 +386,20 @@ def fs_obj_ext(request, u_boot_config):

  # 128MiB volume
  fs_img = mk_fs(u_boot_config, fs_type, 0x800, '128MB')
+except CalledProcessError as err:
+pytest.skip('Creating failed for filesystem: ' + fs_type + '. 
{}'.format(err))
+return

-# Mount the image so we can populate it.
+try:
  check_call('mkdir -p %s' % mount_dir, shell=True)
+except CalledProcessError as err:
+pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type 
+ '. {}'.format(err))
+return
+finally:
+call('rm -f %s' % fs_img, shell=True)
+
+try:
+# Mount the image so we can populate it.
  mount_fs(fs_type, fs_img, mount_dir)

  # Create a test directory
@@ -422,7 +441,6 @@ def fs_obj_ext(request, u_boot_config):
  md5val.append(out.split()[0])

  check_call('rm %s' % tmp_file, shell=True)
-umount_fs(mount_dir)
  except CalledProcessError:
  pytest.skip('Setup failed for filesystem: ' + fs_type)
  return
@@ -431,8 +449,7 @@ def fs_obj_ext(request, u_boot_config):
  finally:
  umount_fs(mount_dir)
  call('rmdir %s' % mount_dir, shell=True)
-if fs_img:
-call('rm -f %s' % fs_img, shell=True)
+call('rm -f %s' % fs_img, shell=True)

  #
  # Fixture for 

  1   2   >