Re: [U-Boot] [RFC PATCH] rockchip: tinker: Add boot from capability

2019-11-12 Thread Michael Nazzareno Trimarchi
Hi Kever

On Wed, Nov 13, 2019 at 2:03 AM Kever Yang  wrote:
>
>
> On 2019/11/12 下午6:02, Michael Nazzareno Trimarchi wrote:
> > Hi Kever
> >
> > On Tue, Nov 12, 2019 at 10:57 AM Kever Yang  
> > wrote:
> >> Hi Michael,
> >>
> >> On 2019/11/12 下午4:14, Michael Trimarchi wrote:
> >>> We need to know from what device we are booting
> >> Please make sure board_spl_was_booted_from() works for rk3288, which
> >>
> >> already work for rk3399, after that, we can move those functions from 
> >> rk3399
> >>
> >> only into common code to make everything work.
> >>
> >> We are not going to add "spl-boot-device".
> > That implementation has no sense in my use case. You need fit image. I
> > don't need any special change
>
>
> I don't understand what you want to do.
>
> The implementation is to get boot device from bootRom and convert it to
> the device in SPL dt,
>
> why it has no sense?

commit 75014470aec60580978962071972f2962695938d
Author: Philipp Tomsich 
Date:   Wed Sep 13 21:29:30 2017 +0200

spl: add a fdt_addr field to spl_image_info

When loading a full U-Boot with detached device-tree using the SPL FIT
backend, we should store the address of the FDT loaded as part of the
SPL image info: this allows us to fixup the FDT with additional info
we may want to propagate onward.

Signed-off-by: Philipp Tomsich 
Reviewed-by: Simon Glass 

The change rk3399 use is a detached device-tree. This not cover all
the use case. I'm using some place holder
to pass the information to next stage without detach it

Michael
>
>
> Thanks,
>
> - Kever
>
> > Michael
> >>
> >> Thanks,
> >>
> >> - Kever
> >>
> >>> in order
> >>> to save the enviroment in right place
> >>>
> >>> Signed-off-by: Michael Trimarchi 
> >>> ---
> >>>arch/arm/dts/rk3288-tinker-s-u-boot.dtsi |  1 +
> >>>arch/arm/mach-rockchip/rk3288/rk3288.c   | 46 
> >>>board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +
> >>>configs/tinker-rk3288_defconfig  |  2 +
> >>>configs/tinker-s-rk3288_defconfig|  2 +
> >>>5 files changed, 92 insertions(+)
> >>>
> >>> diff --git a/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi 
> >>> b/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi
> >>> index 538593359a..2193127514 100644
> >>> --- a/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi
> >>> +++ b/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi
> >>> @@ -10,6 +10,7 @@
> >>>chosen {
> >>>u-boot,spl-boot-order = \
> >>>"same-as-spl", , 
> >>> + u-boot,spl-boot-device = "/dwmmc@ff0f";
> >>>};
> >>>};
> >>>
> >>> diff --git a/arch/arm/mach-rockchip/rk3288/rk3288.c 
> >>> b/arch/arm/mach-rockchip/rk3288/rk3288.c
> >>> index 987b4e0d58..002d1508e5 100644
> >>> --- a/arch/arm/mach-rockchip/rk3288/rk3288.c
> >>> +++ b/arch/arm/mach-rockchip/rk3288/rk3288.c
> >>> @@ -3,6 +3,8 @@
> >>> * Copyright (c) 2016 Rockchip Electronics Co., Ltd
> >>> */
> >>>#include 
> >>> +#include 
> >>> +#include 
> >>>#include 
> >>>#include 
> >>>#include 
> >>> @@ -26,6 +28,50 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 
> >>> 1] = {
> >>>[BROM_BOOTSOURCE_SD] = "/dwmmc@ff0c",
> >>>};
> >>>
> >>> +#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
> >>> +const char *spl_decode_boot_device(u32 boot_device)
> >>> +{
> >>> + int i;
> >>> + static const struct {
> >>> + u32 boot_device;
> >>> + const char *ofpath;
> >>> + } spl_boot_devices_tbl[] = {
> >>> + { BOOT_DEVICE_MMC2, "/dwmmc@ff0f" },
> >>> + { BOOT_DEVICE_MMC1, "/dwmmc@ff0c" },
> >>> + };
> >>> +
> >>> + for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
> >>> + if (spl_boot_devices_tbl[i].boot_device == boot_device)
> >>> + return spl_boot_devices_tbl[i].ofpath;
> >>> +
> >>> + return NULL;
> >>> +}
> >>> +
> >>> +void spl_perform_fixups(struct spl_image_info *spl_image)
> >>> +{
> >>> + void *blob = (void *)gd->fdt_blob;
> >>> + const char *boot_ofpath;
> >>> + int chosen;
> >>> +
> >>> + if (!blob)
> >>> + return;
> >>> +
> >>> + boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
> >>> + if (!boot_ofpath) {
> >>> + pr_err("%s: could not map boot_device to ofpath\n", 
> >>> __func__);
> >>> + return;
> >>> + }
> >>> +
> >>> + chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
> >>> + if (chosen < 0) {
> >>> + pr_err("%s: could not find/create '/chosen'\n", __func__);
> >>> + return;
> >>> + }
> >>> + fdt_setprop_string(blob, chosen,
> >>> +"u-boot,spl-boot-device", boot_ofpath);
> >>> +}
> >>> +#endif
> >>> +
> >>>#ifdef CONFIG_SPL_BUILD
> >>>static void configure_l2ctlr(void)
> >>>{
> >>> diff --git a/board/rockchip/tinker_rk3288/tinker-rk3288.c 
> >>> 

Re: [U-Boot] [BUG] U-Boot hangs on fatload, commit ee88eacbdd840199a3dec707234579fb15ddd46a

2019-11-12 Thread Heinrich Schuchardt

On 11/12/19 11:55 PM, Gray Remlin wrote:



On Tue, 12 Nov 2019 at 19:50, Heinrich Schuchardt > wrote:


On 11/11/19 6:14 PM, Gray Remlin wrote:
 >
 > This content is getting very convoluted, if appropriate feel free to
 > crop it.
 > New point raised at very bottom.
 >
 > On Sun, 10 Nov 2019 at 08:41, Heinrich Schuchardt
mailto:xypron.g...@gmx.de>
 > >> wrote:
 >
 >     On 11/9/19 10:31 PM, Gray Remlin wrote:
 >      > On Sat, 9 Nov 2019 at 20:50, Heinrich Schuchardt
 >     mailto:xypron.g...@gmx.de>
>
 >      > 
      >
 >      >     On 11/9/19 8:42 PM, Gray Remlin wrote:
 >      >      > On Sat, 9 Nov 2019 at 18:40, Heinrich Schuchardt
 >      >     mailto:xypron.g...@gmx.de>
>
 >     
>>
 >      >      >  >
 >     
 wrote:
 >      >      >
 >      >      >     On 11/9/19 6:08 PM, Heinrich Schuchardt wrote:
 >      >      >      > On 11/9/19 4:11 PM, Gray Remlin wrote:
 >      >      >      >> On Fri, 8 Nov 2019 at 20:08, Heinrich
Schuchardt
 >      >      >     mailto:xypron.g...@gmx.de>
>
 >     
>>
 >      >     
>
 >     
      >      >      >> 
 >     >

 >     >>
 >      >     
>
 >     
> wrote:
 >      >      >      >>
 >      >      >      >>     On 11/8/19 7:32 PM, Gray Remlin wrote:
 >      >      >      >>  > Please excuse the noise. I would
like to file a
 >      >     bug report
 >      >      >      >>     against the
 >      >      >      >>  > above commit, a quick search of
www.denx.de 
 >     
 >      >     
 >      >      >      
 >      >      >      >>      did not
 >      >      >      >>  > reveal how I should proceed. Please
point me in
 >      >     the right
 >      >      >      >> direction.
 >      >      >      >>  >
 >      >      >      >>  >
 >      >      >      >>  > Issue:
 >      >      >      >>  > U-Boot hangs (i.e. during boot) whenever
 >     the command
 >      >      >     'fatload' is
 >      >      >      >>     used.
 >      >      >      >>  >
 >      >      >      >>  > Details:
 >      >      >      >>  > U-Boot 2019.10 compiled with either
 >      >     dreamplug_defconfig or
 >      >      >      >>  > guruplug_defconfig.
 >      >      >      >>  >
 >      >      >      >>  > After the commit do_load() now
additionally
 >     calls
 >      >      >      >> efi_set_bootdev()
 >      >      >      >>  > which was moved out of do_load_wrapper()
 >     which is
 >      >     only called
 >      >      >      >> by the
 >      >      >      >>  > 'load' command.
 >      >      >      >>  >
 >      >      >      >>  > Reverting the commit fixes this
issue for me.
 >      >      >      >>  >
 >      >      >      >>
 >      >      >      >>     Dear Gray,
 >      >      >      >>
 >      >      >      >>     thanks for reporting the issue with commit
 >      >      >      >>     fs: do_load: pass device path for efi
payload
 >      >      >      >>     ee88eacbdd840199a3dec707234579fb15ddd46a
 >      >      >      >>
 >      >      >      >>  

[U-Boot] [PATCH v4] armv8: Add workaround for USB erratum A-050106

2019-11-12 Thread Ran Wang
USB3.0 Receiver needs to enable fixed equalization
for each of PHY instances in an SOC. This is similar
to erratum A-009007, but this one is for LX2160A,
and the register value is different.

Signed-off-by: Ran Wang 
---
Change in v4:
- Include defines of USB_PHY_RX_EQ_VAL_3 and USB_PHY_RX_EQ_VAL_4 for
  LS1028A to fix compile failure.

Change in v3:
- Rebase patch for latest U-Boot (v2019.10)

Change in v2:
- Move function erratum_a050106() under the scope of
  CONFIG_FSL_LSCH3 to avoid compilation warning of
  'defined but not used'.

 arch/arm/cpu/armv8/fsl-layerscape/Kconfig  |  4 
 arch/arm/cpu/armv8/fsl-layerscape/soc.c| 12 +++-
 arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h |  6 ++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index f1578b1..c7f28b6 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
@@ -219,6 +219,7 @@ config ARCH_LX2160A
select SYS_FSL_DDR_VER_50
select SYS_FSL_EC1
select SYS_FSL_EC2
+   select SYS_FSL_ERRATUM_A050106
select SYS_FSL_HAS_RGMII
select SYS_FSL_HAS_SEC
select SYS_FSL_HAS_CCN508
@@ -348,6 +349,9 @@ config SYS_FSL_ERRATUM_A009008
 config SYS_FSL_ERRATUM_A009798
bool "Workaround for USB PHY erratum A009798"
 
+config SYS_FSL_ERRATUM_A050106
+   bool "Workaround for USB PHY erratum A050106"
+
 config SYS_FSL_ERRATUM_A010315
bool "Workaround for PCIe erratum A010315"
 
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/soc.c 
b/arch/arm/cpu/armv8/fsl-layerscape/soc.c
index f0df88c..909df5c 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/soc.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/soc.c
@@ -146,7 +146,7 @@ static void erratum_a008997(void)
out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
 
 #elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
-   defined(CONFIG_ARCH_LS1028A)
+   defined(CONFIG_ARCH_LS1028A) || defined(CONFIG_ARCH_LX2160A)
 
 #define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
@@ -180,6 +180,15 @@ static void erratum_a009007(void)
 }
 
 #if defined(CONFIG_FSL_LSCH3)
+static void erratum_a050106(void)
+{
+#if defined(CONFIG_ARCH_LX2160A)
+   void __iomem *dcsr = (void __iomem *)DCSR_BASE;
+
+   PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
+   PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
+#endif
+}
 /*
  * This erratum requires setting a value to eddrtqcr1 to
  * optimal the DDR performance.
@@ -331,6 +340,7 @@ void fsl_lsch3_early_init_f(void)
erratum_a009798();
erratum_a008997();
erratum_a009007();
+   erratum_a050106();
 #ifdef CONFIG_CHAIN_OF_TRUST
/* In case of Secure Boot, the IBR configures the SMMU
* to allow only Secure transactions.
diff --git a/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h 
b/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h
index d46477d..7670b56 100644
--- a/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h
+++ b/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h
@@ -252,8 +252,14 @@
 #define DCSR_USB_PHY_RX_OVRD_IN_HI 0x200C
 #define USB_PHY_RX_EQ_VAL_10x
 #define USB_PHY_RX_EQ_VAL_20x0080
+#if defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \
+   defined(CONFIG_ARCH_LS1028A)
 #define USB_PHY_RX_EQ_VAL_30x0380
 #define USB_PHY_RX_EQ_VAL_40x0b80
+#elif defined(CONFIG_ARCH_LX2160A)
+#define USB_PHY_RX_EQ_VAL_30x0080
+#define USB_PHY_RX_EQ_VAL_40x0880
+#endif
 #define DCSR_USB_IOCR1 0x108004
 #define DCSR_USB_PCSTXSWINGFULL0x71
 
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 6/6] mx7ulp: Add support for Embedded Artists COM board

2019-11-12 Thread Peng Fan

> Subject: Re: [PATCH v3 6/6] mx7ulp: Add support for Embedded Artists COM
> board
> 
> Hi Stefano and Peng,
> 
> Any comments, please?

I'll help collect patches if Stefano not pick up.

Regards,
Peng.

> 
> Thanks
> 
> On Tue, Nov 5, 2019 at 9:48 AM Fabio Estevam 
> wrote:
> >
> > The Embedded Artists COM board is based on NXP i.MX7ULP.
> >
> > It has a BD70528 PMIC from Rohm with discrete DCDC powering option and
> > improved current observability (compared to the existing NXP i.MX7ULP
> EVK).
> >
> > Add the initial support for the board.
> >
> > Signed-off-by: Fabio Estevam 
> > ---
> > Changes since v2:
> > - Add the imx7ulp-com.dts (Peng Fan)
> >
> >  arch/arm/dts/Makefile|   3 +-
> >  arch/arm/dts/imx7ulp-com.dts |  90 ++
> >  arch/arm/mach-imx/mx7ulp/Kconfig |   6 ++
> >  board/ea/mx7ulp_com/Kconfig  |  12 +++
> >  board/ea/mx7ulp_com/MAINTAINERS  |   6 ++
> >  board/ea/mx7ulp_com/Makefile |   6 ++
> >  board/ea/mx7ulp_com/imximage.cfg | 128
> > +++
> board/ea/mx7ulp_com/mx7ulp_com.c |  48 
> >  configs/mx7ulp_com_defconfig |  59 ++
> >  include/configs/mx7ulp_com.h | 107
> ++
> >  10 files changed, 464 insertions(+), 1 deletion(-)  create mode
> > 100644 arch/arm/dts/imx7ulp-com.dts  create mode 100644
> > board/ea/mx7ulp_com/Kconfig  create mode 100644
> > board/ea/mx7ulp_com/MAINTAINERS  create mode 100644
> > board/ea/mx7ulp_com/Makefile  create mode 100644
> > board/ea/mx7ulp_com/imximage.cfg  create mode 100644
> > board/ea/mx7ulp_com/mx7ulp_com.c  create mode 100644
> > configs/mx7ulp_com_defconfig  create mode 100644
> > include/configs/mx7ulp_com.h
> >
> > diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index
> > 251d32ca62..4ce0d813d4 100644
> > --- a/arch/arm/dts/Makefile
> > +++ b/arch/arm/dts/Makefile
> > @@ -648,7 +648,8 @@ dtb-$(CONFIG_MX7) += imx7d-sdb.dtb \
> > imx7d-pico-hobbit.dtb
> >
> >
> > -dtb-$(CONFIG_ARCH_MX7ULP) += imx7ulp-evk.dtb
> > +dtb-$(CONFIG_ARCH_MX7ULP) += imx7ulp-com.dtb \
> > +   imx7ulp-evk.dtb
> >
> >  dtb-$(CONFIG_ARCH_IMX8) += \
> > fsl-imx8qm-apalis.dtb \
> > diff --git a/arch/arm/dts/imx7ulp-com.dts
> > b/arch/arm/dts/imx7ulp-com.dts new file mode 100644 index
> > 00..c01e03dd06
> > --- /dev/null
> > +++ b/arch/arm/dts/imx7ulp-com.dts
> > @@ -0,0 +1,90 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +//
> > +// Copyright 2019 NXP
> > +// Author: Fabio Estevam 
> > +
> > +/dts-v1/;
> > +
> > +#include "imx7ulp.dtsi"
> > +
> > +/ {
> > +   model = "Embedded Artists i.MX7ULP COM";
> > +   compatible = "ea,imx7ulp-com", "fsl,imx7ulp";
> > +
> > +   chosen {
> > +   stdout-path = 
> > +   };
> > +
> > +   memory {
> > +   device_type = "memory";
> > +   reg = <0x6000 0x800>;
> > +   };
> > +};
> > +
> > + {
> > +   pinctrl-names = "default";
> > +   pinctrl-0 = <_lpuart4>;
> > +   status = "okay";
> > +};
> > +
> > + {
> > +   pinctrl-names = "default";
> > +   pinctrl-0 = <_usbotg1_id>;
> > +   srp-disable;
> > +   hnp-disable;
> > +   adp-disable;
> > +   status = "okay";
> > +};
> > +
> > + {
> > +   fsl,tx-d-cal = <88>;
> > +};
> > +
> > + {
> > +   pinctrl-names = "default";
> > +   pinctrl-0 = <_usdhc0>;
> > +   non-removable;
> > +   bus-width = <8>;
> > +   no-1-8-v;
> > +   status = "okay";
> > +};
> > +
> > + {
> > +   pinctrl-names = "default";
> > +   pinctrl-0 = <_hog_1>;
> > +
> > +   pinctrl_hog_1: hoggrp-1 {
> > +   fsl,pins = <
> > +   IMX7ULP_PAD_PTC1__PTC1
> 0x2
> > +   >;
> > +   };
> > +
> > +   pinctrl_lpuart4: lpuart4grp {
> > +   fsl,pins = <
> > +   IMX7ULP_PAD_PTC3__LPUART4_RX0x3
> > +   IMX7ULP_PAD_PTC2__LPUART4_TX0x3
> > +   >;
> > +   };
> > +
> > +   pinctrl_usdhc0: usdhc0grp {
> > +   fsl,pins = <
> > +   IMX7ULP_PAD_PTD1__SDHC0_CMD
> 0x43
> > +   IMX7ULP_PAD_PTD2__SDHC0_CLK
> 0x10042
> > +   IMX7ULP_PAD_PTD3__SDHC0_D7
> 0x43
> > +   IMX7ULP_PAD_PTD4__SDHC0_D6
> 0x43
> > +   IMX7ULP_PAD_PTD5__SDHC0_D5
> 0x43
> > +   IMX7ULP_PAD_PTD6__SDHC0_D4
> 0x43
> > +   IMX7ULP_PAD_PTD7__SDHC0_D3
> 0x43
> > +   IMX7ULP_PAD_PTD8__SDHC0_D2
> 0x43
> > +   IMX7ULP_PAD_PTD9__SDHC0_D1
> 0x43
> > +   IMX7ULP_PAD_PTD10__SDHC0_D0
> 0x43
> > +   IMX7ULP_PAD_PTD11__SDHC0_DQS
> 0x42
> > +   >;
> > +   };
> > +
> > +   pinctrl_usbotg1_id: otg1idgrp {
> > +   fsl,pins = <
> > +   IMX7ULP_PAD_PTC13__USB0_ID
> 0x10003
> > +   >;

Re: [U-Boot] [PATCH] armv8: layerscape: set HWCONFIG_BUFFER_SIZE

2019-11-12 Thread Priyanka Jain


>-Original Message-
>From: Michael Walle 
>Sent: Tuesday, November 12, 2019 2:20 PM
>To: Priyanka Jain 
>Cc: u-boot@lists.denx.de; Tom Rini 
>Subject: Re: [U-Boot] [PATCH] armv8: layerscape: set HWCONFIG_BUFFER_SIZE
>
>Am 2019-11-11 16:20, schrieb Priyanka Jain:
>>> -Original Message-
>>> From: U-Boot  On Behalf Of Michael
>>> Walle
>>> Sent: Monday, October 21, 2019 11:04 PM
>>> To: u-boot@lists.denx.de
>>> Cc: Tom Rini 
>>> Subject: [U-Boot] [PATCH] armv8: layerscape: set HWCONFIG_BUFFER_SIZE
>>>
>>> Set the HWCONFIG_BUFFER_SIZE if it is not already set. Otherwise
>>> compilation will fail if CONFIG_HWCONFIG and HWCONFIG_BUFFER_SIZE
>are
>>> not set.
>>>
>>> Taken from arch/powerpc/include/asm/config.h.
>>>
>>> Signed-off-by: Michael Walle 
>>> ---
>>
>> Applied to fsl-qoriq master, awaiting upstream.
>
>That one wasn't applied, was it? You said this patch breaks other boards. For
>now, I just had time to had a brief look at it. Seems like the culprit is that 
>the
>configs/bla_common.h for the these boards include ,
>although will be included later in include/config.h. So it is not possible to
>provide "defaults" for any macros. Do you think it is possible to remove the
>"#include " in your _common.h config files?
>
>-michael
Yes you are right. I dropped this patch at the last moment.
Sorry for confusion. 
Regarding dropping "#include " in your _common.h config files
This wont be simple. Can you please think of alternative way.

-priyankajain

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 4/8] riscv: andes_plic: Fix some wrong configurations

2019-11-12 Thread Rick Chen
Hi Lukas

>
> Hi Rick,
>
> On Mon, 2019-11-11 at 15:19 +0800, Rick Chen wrote:
> > Hi Lukas
> >
> > > Hi Rick,
> > >
> > > On Fri, 2019-11-08 at 15:27 +0800, Rick Chen wrote:
> > > > Hi Atish
> > > >
> > > > > Hi Atish
> > > > >
> > > > > > On Thu, 2019-11-07 at 19:41 +0800, Rick Chen wrote:
> > > > > > > Hi Anup & Lukas
> > > > > > >
> > > > > > > Anup Patel  於 2019年11月7日 週四 下午6:44寫道:
> > > > > > > > On Thu, Nov 7, 2019 at 3:11 PM Auer, Lukas
> > > > > > > >  wrote:
> > > > > > > > > On Thu, 2019-11-07 at 11:48 +0530, Anup Patel wrote:
> > > > > > > > > > On Thu, Nov 7, 2019 at 11:40 AM Rick Chen 
> > > > > > > > > >  > > > > > > > > > > wrote:
> > > > > > > > > > > Hi Anup
> > > > > > > > > > >
> > > > > > > > > > > > On Thu, Nov 7, 2019 at 10:45 AM Anup Patel <
> > > > > > > > > > > > a...@brainfault.org> wrote:
> > > > > > > > > > > > > On Thu, Nov 7, 2019 at 7:04 AM Rick Chen <
> > > > > > > > > > > > > rickche...@gmail.com> wrote:
> > > > > > > > > > > > > > Hi Anup
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > > On Wed, Nov 6, 2019 at 2:51 PM Rick Chen <
> > > > > > > > > > > > > > > rickche...@gmail.com> wrote:
> > > > > > > > > > > > > > > > Hi Anup
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > On Wed, Nov 6, 2019 at 2:18 PM Anup Patel <
> > > > > > > > > > > > > > > > > a...@brainfault.org> wrote:
> > > > > > > > > > > > > > > > > > On Wed, Nov 6, 2019 at 12:14 PM Rick Chen <
> > > > > > > > > > > > > > > > > > rickche...@gmail.com> wrote:
> > > > > > > > > > > > > > > > > > > Hi Anup
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > On Tue, Nov 5, 2019 at 7:19 AM Rick 
> > > > > > > > > > > > > > > > > > > > Chen <
> > > > > > > > > > > > > > > > > > > > rickche...@gmail.com> wrote:
> > > > > > > > > > > > > > > > > > > > > Hi Anup
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > On Thu, Oct 31, 2019 at 1:42 PM 
> > > > > > > > > > > > > > > > > > > > > > > Anup
> > > > > > > > > > > > > > > > > > > > > > > Patel  wrote:
> > > > > > > > > > > > > > > > > > > > > > > > On Thu, Oct 31, 2019 at 6:30 AM
> > > > > > > > > > > > > > > > > > > > > > > > Alan Kao 
> > > > > > > > > > > > > > > > > > > > > > > > wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > Hi Bin,
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Thanks for the critics.  
> > > > > > > > > > > > > > > > > > > > > > > > > Comments
> > > > > > > > > > > > > > > > > > > > > > > > > below.
> > > > > > > > > > > > > > > > > > > > > > > > > On Wed, Oct 30, 2019 at
> > > > > > > > > > > > > > > > > > > > > > > > > 06:38:00PM +0800, Bin Meng 
> > > > > > > > > > > > > > > > > > > > > > > > > wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > > Hi Rick,
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > On Wed, Oct 30, 2019 at 
> > > > > > > > > > > > > > > > > > > > > > > > > > 10:50
> > > > > > > > > > > > > > > > > > > > > > > > > > AM Rick Chen <
> > > > > > > > > > > > > > > > > > > > > > > > > > rickche...@gmail.com> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > > > Hi Bin
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > > Hi Rick,
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > > On Fri, Oct 25, 2019 at
> > > > > > > > > > > > > > > > > > > > > > > > > > > > 2:18 PM Andes <
> > > > > > > > > > > > > > > > > > > > > > > > > > > > ub...@andestech.com> 
> > > > > > > > > > > > > > > > > > > > > > > > > > > > wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > From: Rick Chen <
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > r...@andestech.com>
> > > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > It will work fine due 
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > hart 0 always will be
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > main
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > hart coincidentally. 
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > When
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > develop SPL flow, I 
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > try
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > force other harts to 
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > main hart. And it 
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > will go
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > wrong in sending IPI
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > flow. So fix it.
> > > > > > > > > > > > > > 

Re: [U-Boot] [PATCH 1/4] arm64: dts: rk3399-rock960: add vdd_log and its init value

2019-11-12 Thread Manivannan Sadhasivam
On Wed, Nov 13, 2019 at 11:14:09AM +0800, Kever Yang wrote:
> Add vdd_log node according to rock960 schematic V13.
> This patch affect two boards:
> - Rock960 Model A
> - Ficus
> 
> Signed-off-by: Kever Yang 

Acked-by: Manivannan Sadhasivam 

Thanks,
Mani

> ---
> 
>  arch/arm/dts/rk3399-rock960-u-boot.dtsi | 13 +
>  1 file changed, 13 insertions(+)
> 
> diff --git a/arch/arm/dts/rk3399-rock960-u-boot.dtsi 
> b/arch/arm/dts/rk3399-rock960-u-boot.dtsi
> index 4850debdf0..82f2c311af 100644
> --- a/arch/arm/dts/rk3399-rock960-u-boot.dtsi
> +++ b/arch/arm/dts/rk3399-rock960-u-boot.dtsi
> @@ -10,4 +10,17 @@
>   chosen {
>   u-boot,spl-boot-order = , 
>   };
> +
> + vdd_log: vdd-log {
> + compatible = "pwm-regulator";
> + pwms = < 0 25000 1>;
> + regulator-name = "vdd_log";
> + regulator-always-on;
> + regulator-boot-on;
> + regulator-min-microvolt = <80>;
> + regulator-max-microvolt = <140>;
> + regulator-init-microvolt = <95>;
> + vin-supply = <_sys>;
> + };
> +
>  };
> -- 
> 2.17.1
> 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 3/4] rockchip: rk3399: khadas-edge: Add init value for vdd_log

2019-11-12 Thread Kever Yang
We should set the init value when vdd_log is enabled, or else the
vdd_log output voltage may not in soc required range.

Signed-off-by: Kever Yang 
---

 arch/arm/dts/rk3399-khadas-edge-u-boot.dtsi | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/dts/rk3399-khadas-edge-u-boot.dtsi 
b/arch/arm/dts/rk3399-khadas-edge-u-boot.dtsi
index 35b9fdda77..a7039d74a0 100644
--- a/arch/arm/dts/rk3399-khadas-edge-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-khadas-edge-u-boot.dtsi
@@ -11,3 +11,7 @@
u-boot,spl-boot-order = "same-as-spl", , 
};
 };
+
+_log {
+   regulator-init-microvolt = <95>;
+};
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 4/4] rockchip: rk3399: orangepi: Add init value for vdd_log

2019-11-12 Thread Kever Yang
We should set the init value when vdd_log is enabled, or else the
vdd_log output voltage may not in soc required range.

Signed-off-by: Kever Yang 
---

 arch/arm/dts/rk3399-orangepi-u-boot.dtsi | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/dts/rk3399-orangepi-u-boot.dtsi 
b/arch/arm/dts/rk3399-orangepi-u-boot.dtsi
index 236b61d78d..d4327ea607 100644
--- a/arch/arm/dts/rk3399-orangepi-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-orangepi-u-boot.dtsi
@@ -5,3 +5,7 @@
 
 #include "rk3399-u-boot.dtsi"
 #include "rk3399-sdram-ddr3-1333.dtsi"
+
+_log {
+   regulator-init-microvolt = <95>;
+};
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/4] rockchip: rk3399: rock-pi4: Add init value for vdd_log

2019-11-12 Thread Kever Yang
We should set the init value when vdd_log is enabled, or else the
vdd_log output voltage may not in soc required range.

Signed-off-by: Kever Yang 
---

 arch/arm/dts/rk3399-rock-pi-4-u-boot.dtsi | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/dts/rk3399-rock-pi-4-u-boot.dtsi 
b/arch/arm/dts/rk3399-rock-pi-4-u-boot.dtsi
index 5bd869..c17e769f64 100644
--- a/arch/arm/dts/rk3399-rock-pi-4-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-rock-pi-4-u-boot.dtsi
@@ -11,3 +11,7 @@
u-boot,spl-boot-order = "same-as-spl", , 
};
 };
+
+_log {
+   regulator-init-microvolt = <95>;
+};
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/4] arm64: dts: rk3399-rock960: add vdd_log and its init value

2019-11-12 Thread Kever Yang
Add vdd_log node according to rock960 schematic V13.
This patch affect two boards:
- Rock960 Model A
- Ficus

Signed-off-by: Kever Yang 
---

 arch/arm/dts/rk3399-rock960-u-boot.dtsi | 13 +
 1 file changed, 13 insertions(+)

diff --git a/arch/arm/dts/rk3399-rock960-u-boot.dtsi 
b/arch/arm/dts/rk3399-rock960-u-boot.dtsi
index 4850debdf0..82f2c311af 100644
--- a/arch/arm/dts/rk3399-rock960-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-rock960-u-boot.dtsi
@@ -10,4 +10,17 @@
chosen {
u-boot,spl-boot-order = , 
};
+
+   vdd_log: vdd-log {
+   compatible = "pwm-regulator";
+   pwms = < 0 25000 1>;
+   regulator-name = "vdd_log";
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <140>;
+   regulator-init-microvolt = <95>;
+   vin-supply = <_sys>;
+   };
+
 };
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [RFC PATCH] rockchip: tinker: Add boot from capability

2019-11-12 Thread Kever Yang


On 2019/11/12 下午6:02, Michael Nazzareno Trimarchi wrote:

Hi Kever

On Tue, Nov 12, 2019 at 10:57 AM Kever Yang  wrote:

Hi Michael,

On 2019/11/12 下午4:14, Michael Trimarchi wrote:

We need to know from what device we are booting

Please make sure board_spl_was_booted_from() works for rk3288, which

already work for rk3399, after that, we can move those functions from rk3399

only into common code to make everything work.

We are not going to add "spl-boot-device".

That implementation has no sense in my use case. You need fit image. I
don't need any special change



I don't understand what you want to do.

The implementation is to get boot device from bootRom and convert it to 
the device in SPL dt,


why it has no sense?


Thanks,

- Kever


Michael


Thanks,

- Kever


in order
to save the enviroment in right place

Signed-off-by: Michael Trimarchi 
---
   arch/arm/dts/rk3288-tinker-s-u-boot.dtsi |  1 +
   arch/arm/mach-rockchip/rk3288/rk3288.c   | 46 
   board/rockchip/tinker_rk3288/tinker-rk3288.c | 41 +
   configs/tinker-rk3288_defconfig  |  2 +
   configs/tinker-s-rk3288_defconfig|  2 +
   5 files changed, 92 insertions(+)

diff --git a/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi 
b/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi
index 538593359a..2193127514 100644
--- a/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi
+++ b/arch/arm/dts/rk3288-tinker-s-u-boot.dtsi
@@ -10,6 +10,7 @@
   chosen {
   u-boot,spl-boot-order = \
   "same-as-spl", , 
+ u-boot,spl-boot-device = "/dwmmc@ff0f";
   };
   };

diff --git a/arch/arm/mach-rockchip/rk3288/rk3288.c 
b/arch/arm/mach-rockchip/rk3288/rk3288.c
index 987b4e0d58..002d1508e5 100644
--- a/arch/arm/mach-rockchip/rk3288/rk3288.c
+++ b/arch/arm/mach-rockchip/rk3288/rk3288.c
@@ -3,6 +3,8 @@
* Copyright (c) 2016 Rockchip Electronics Co., Ltd
*/
   #include 
+#include 
+#include 
   #include 
   #include 
   #include 
@@ -26,6 +28,50 @@ const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
   [BROM_BOOTSOURCE_SD] = "/dwmmc@ff0c",
   };

+#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
+const char *spl_decode_boot_device(u32 boot_device)
+{
+ int i;
+ static const struct {
+ u32 boot_device;
+ const char *ofpath;
+ } spl_boot_devices_tbl[] = {
+ { BOOT_DEVICE_MMC2, "/dwmmc@ff0f" },
+ { BOOT_DEVICE_MMC1, "/dwmmc@ff0c" },
+ };
+
+ for (i = 0; i < ARRAY_SIZE(spl_boot_devices_tbl); ++i)
+ if (spl_boot_devices_tbl[i].boot_device == boot_device)
+ return spl_boot_devices_tbl[i].ofpath;
+
+ return NULL;
+}
+
+void spl_perform_fixups(struct spl_image_info *spl_image)
+{
+ void *blob = (void *)gd->fdt_blob;
+ const char *boot_ofpath;
+ int chosen;
+
+ if (!blob)
+ return;
+
+ boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
+ if (!boot_ofpath) {
+ pr_err("%s: could not map boot_device to ofpath\n", __func__);
+ return;
+ }
+
+ chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
+ if (chosen < 0) {
+ pr_err("%s: could not find/create '/chosen'\n", __func__);
+ return;
+ }
+ fdt_setprop_string(blob, chosen,
+"u-boot,spl-boot-device", boot_ofpath);
+}
+#endif
+
   #ifdef CONFIG_SPL_BUILD
   static void configure_l2ctlr(void)
   {
diff --git a/board/rockchip/tinker_rk3288/tinker-rk3288.c 
b/board/rockchip/tinker_rk3288/tinker-rk3288.c
index 6c76c3c25c..66a7394d95 100644
--- a/board/rockchip/tinker_rk3288/tinker-rk3288.c
+++ b/board/rockchip/tinker_rk3288/tinker-rk3288.c
@@ -9,6 +9,34 @@
   #include 
   #include 

+static int tinker_boot_device = CONFIG_SYS_MMC_ENV_DEV;
+
+/*
+ * Select the boot device according to what was set in spl step
+ */
+static int setup_boottargets(void)
+{
+ const char *boot_device =
+ ofnode_get_chosen_prop("u-boot,spl-boot-device");
+
+ if (!boot_device) {
+ debug("%s: /chosen/u-boot,spl-boot-device not set\n",
+   __func__);
+ return -1;
+ }
+ debug("%s: booted from %s\n", __func__, boot_device);
+
+ if (!strcmp(boot_device, "/dwmmc@ff0f")) {
+ /* eMMC boot device */
+ tinker_boot_device = 1;
+ } else {
+ /* sdcard boot device */
+ tinker_boot_device = 0;
+ }
+
+ return 0;
+}
+
   static int get_ethaddr_from_eeprom(u8 *addr)
   {
   int ret;
@@ -33,3 +61,16 @@ int rk3288_board_late_init(void)

   return 0;
   }
+
+int misc_init_r(void)
+{
+ setup_boottargets();
+
+ return 0;
+}
+
+int mmc_get_env_dev(void)
+{
+ debug("boot device %d\n", tinker_boot_device);
+ return tinker_boot_device;
+}
diff --git a/configs/tinker-rk3288_defconfig b/configs/tinker-rk3288_defconfig
index c851a93f31..106e24e8ca 

[U-Boot] [PATCH 00/16] efi_loader: add secure boot support

2019-11-12 Thread AKASHI Takahiro
One of major missing features in current UEFI implementation is "secure boot."
The ultimate goal of my attempt is to implement image authentication based
on signature and provide UEFI secure boot support which would be fully
compliant with UEFI specification, section 32[1].
(The code was originally developed by Patrick Wildt.)

While this patch/RFC is still rough-edged, the aim here is to get early
feedbacks from the community as the patch is quite huge (in total) and also
as it's a security enhancement.

Please note, however, this patch doesn't work on its own; there are
a couple of functional dependencies[2] and [3], that I have submitted
before. For complete workable patch set, see my repository[4],
which also contains exeperimental timestamp-based revocation suuport.

My "non-volatile" support[5], which is under discussion, is not mandatory
and so not included here, but this inevitably implies that, for example,
signature database variables, like db and dbx, won't be persistent unless you
explicitly run "env save" command and that UEFI variables are not separated
from U-Boot environment. Anyhow, Linaro is also working on implementing
real "secure storage" solution based on TF-A and OP-TEE.


Supported features:
* image authentication based on db and dbx
* supported signature types are
EFI_CERT_SHA256_GUID (SHA256 digest for unsigned images)
EFI_CERT_X509_GUID (x509 certificate for signed images)
* SecureBoot/SignatureSupport variables
* SetupMode and user mode
* variable authentication based on PK and KEK
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
* basic pytest test cases

Unsupported features: (marked as TODO in most cases in the source code,
and won't be included in this series)
* hash algorithms other than SHA256
* dbt: timestamp(RFC6131)-based certificate revocation
* dbr: OS recovery 
* xxxDefault: default values for signature stores
* transition to AuditMode and DeployedMode
* recording rejected images in EFI_IMAGE_EXECUTION_INFO_TABLE
* verification "policy", in particular, check against signature's owner
* private authenticated variables
* variable authentication with EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS
* real secure storage support, including hardware-specific PK (Platform Key)
  installation

TODO's other than "Unsupported features": (won't be included in this series)
* struct efi_image_regions cannot have arbitrary number of regions
* fail recovery, in particular, in modifying authenticated variables
* support read-only attributes of well-defined global variables
  in particular, "SignatureSupport"
* Extensive test suite (or more test cases) to confirm compatibility
  with EDK2
=> I requested EDK SCT community to add tests[6].

Known issues:
* remove generic CONFIG_SECURE_BOOT option (on NXP/Freescale platforms)
  (I'm looking forward to fixes from NXP guys.)
* efitools is used in pytest, and its version must be v1.5.2 or later.
  (Solution: You can define EFITOOLS_PATH in defs.py for your own efitools.)
* Pytest depends on standalone "helloworld" app for sandbox
  (Solution: You can define HELLO_PATH in defs.py or Heinrich's [7].)

Test:
* my pytest, included in this patch set, passed.
* efi_selftest passed. (At least no reguression.)
* Travis CI passed. (But pytest itself was skipped.)


Hints about how to use:
(Please see other documents, or my pytest scripts, for details.)
* You can create your own certificates with openssl.
* You can sign your application with sbsign (on Ubuntu).
* You can create raw data for signature database with efitools, and
  install/manage authenticated variables with "env -set -e" command
  or efitools' "UpdateVars.efi" application.


[1] https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_final.pdf
[2] https://lists.denx.de/pipermail/u-boot/2019-November/390127.html
(import x509/pkcs7 parsers from linux)
[3] https://lists.denx.de/pipermail/u-boot/2019-November/390150.html
(extend rsa_verify() for UEFI secure boot)
[4] http://git.linaro.org/people/takahiro.akashi/u-boot.git/ efi/secboot
[5] https://lists.denx.de/pipermail/u-boot/2019-September/382835.html
(non-volatile variables support)
[6] https://bugzilla.tianocore.org/show_bug.cgi?id=2230
[7] https://lists.denx.de/pipermail/u-boot/2019-November/389593.html


Changes in v1 (Nov 13, 2019)
* rebased to v2020.01-rc
* remove already-merged patches
* re-work the patch set for easier reviews, including
  - move a config definition patch forward (patch#4)
  - refactor/rename verification functions (patch#5/#10)
  - split signature database parser as a separate patch (patch#6)
  - split secure state transition code as a separate patch (patch#8)
  - move most part of init_secure_boot() into init_variables() (patch#8)
  - split test environment setup from test patches (patch#14)
* add function descriptions (patch#5-#11)
* make sure the section list is sorted in ascending order in hash
  calculation of PE image (patch#10)
* add a new "-at" 

[U-Boot] [PATCH 06/16] efi_loader: add signature database parser

2019-11-12 Thread AKASHI Takahiro
efi_signature_parse_sigdb() is a helper function will be used to parse
signature database variable and instantiate a signature store structure
in later patches.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_loader.h   |   3 +
 lib/efi_loader/efi_signature.c | 227 +
 2 files changed, 230 insertions(+)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 5a3df557e9f2..92b683b7653a 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -694,6 +694,9 @@ bool efi_signature_verify_with_sigdb(struct 
efi_image_regions *regs,
 efi_status_t efi_image_region_add(struct efi_image_regions *regs,
  const void *start, const void *end,
  int nocheck);
+
+void efi_sigstore_free(struct efi_signature_store *sigstore);
+struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name);
 #endif /* CONFIG_EFI_SECURE_BOOT */
 
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c
index 04f43e47d1a3..3e2002446b43 100644
--- a/lib/efi_loader/efi_signature.c
+++ b/lib/efi_loader/efi_signature.c
@@ -597,4 +597,231 @@ efi_status_t efi_image_region_add(struct 
efi_image_regions *regs,
 
return EFI_SUCCESS;
 }
+
+/**
+ * efi_sigstore_free - free signature store
+ * @sigstore:  Pointer to signature store structure
+ *
+ * Feee all the memories held in signature store and itself,
+ * which were allocated by efi_sigstore_parse_sigdb().
+ */
+void efi_sigstore_free(struct efi_signature_store *sigstore)
+{
+   struct efi_signature_store *sigstore_next;
+   struct efi_sig_data *sig_data, *sig_data_next;
+
+   while (sigstore) {
+   sigstore_next = sigstore->next;
+
+   sig_data = sigstore->sig_data_list;
+   while (sig_data) {
+   if (sig_data)
+   sig_data_next = sig_data->next;
+   free(sig_data->data);
+   free(sig_data);
+   sig_data = sig_data_next;
+   }
+
+   free(sigstore);
+   sigstore = sigstore_next;
+   }
+}
+
+/**
+ * efi_sigstore_parse_siglist - parse a signature list
+ * @name:  Pointer to signature list
+ *
+ * Parse signature list and instantiate a signature store structure.
+ * Signature database is a simple concatenation of one or more
+ * signature list(s).
+ *
+ * Return: Pointer to signature store on success, NULL on error
+ */
+static struct efi_signature_store *
+efi_sigstore_parse_siglist(struct efi_signature_list *esl)
+{
+   struct efi_signature_store *siglist = NULL;
+   struct efi_sig_data *sig_data, *sig_data_next;
+   struct efi_signature_data *esd;
+   size_t left;
+
+   /*
+* UEFI specification defines certificate types:
+*   for non-signed images,
+*  EFI_CERT_SHA256_GUID
+*  EFI_CERT_RSA2048_GUID
+*  EFI_CERT_RSA2048_SHA256_GUID
+*  EFI_CERT_SHA1_GUID
+*  EFI_CERT_RSA2048_SHA_GUID
+*  EFI_CERT_SHA224_GUID
+*  EFI_CERT_SHA384_GUID
+*  EFI_CERT_SHA512_GUID
+*
+*   for signed images,
+*  EFI_CERT_X509_GUID
+*  NOTE: Each certificate will normally be in a separate
+*  EFI_SIGNATURE_LIST as the size may vary depending on
+*  its algo's.
+*
+*   for timestamp revocation of certificate,
+*  EFI_CERT_X509_SHA512_GUID
+*  EFI_CERT_X509_SHA256_GUID
+*  EFI_CERT_X509_SHA384_GUID
+*/
+
+   if (esl->signature_list_size
+   <= (sizeof(*esl) + esl->signature_header_size)) {
+   debug("Siglist in wrong format\n");
+   return NULL;
+   }
+
+   /* Create a head */
+   siglist = calloc(sizeof(*siglist), 1);
+   if (!siglist) {
+   debug("Out of memory\n");
+   goto err;
+   }
+   memcpy(>sig_type, >signature_type, sizeof(efi_guid_t));
+
+   /* Go through the list */
+   sig_data_next = NULL;
+   left = esl->signature_list_size
+   - (sizeof(*esl) + esl->signature_header_size);
+   esd = (struct efi_signature_data *)
+   ((u8 *)esl + sizeof(*esl) + esl->signature_header_size);
+
+   while ((left > 0) && left >= esl->signature_size) {
+   /* Signature must exist if there is remaining data. */
+   if (left < esl->signature_size) {
+   debug("Certificate is too small\n");
+   goto err;
+   }
+
+   sig_data = calloc(esl->signature_size
+   - sizeof(esd->signature_owner), 1);
+   if (!sig_data) {
+   debug("Out of memory\n");
+   goto err;
+   }

[U-Boot] [PATCH 16/16] efi_loader, pytest: add UEFI secure boot tests (image)

2019-11-12 Thread AKASHI Takahiro
Provide test cases for
 * image authentication for signed images
   (test_efi_secboot/test_signed.py)
 * image authentication for unsigned images
   (test_efi_secboot/test_unsigned.py)

Signed-off-by: AKASHI Takahiro 
---
 test/py/tests/test_efi_secboot/test_signed.py |  97 +
 .../tests/test_efi_secboot/test_unsigned.py   | 100 ++
 2 files changed, 197 insertions(+)
 create mode 100644 test/py/tests/test_efi_secboot/test_signed.py
 create mode 100644 test/py/tests/test_efi_secboot/test_unsigned.py

diff --git a/test/py/tests/test_efi_secboot/test_signed.py 
b/test/py/tests/test_efi_secboot/test_signed.py
new file mode 100644
index ..00f539462eb8
--- /dev/null
+++ b/test/py/tests/test_efi_secboot/test_signed.py
@@ -0,0 +1,97 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2019, Linaro Limited
+# Author: AKASHI Takahiro 
+#
+# U-Boot UEFI: Signed Image Authentication Test
+
+"""
+This test verifies image authentication for signed images.
+"""
+
+import pytest
+import re
+from defs import *
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('efi_secure_boot')
+@pytest.mark.buildconfigspec('cmd_efidebug')
+@pytest.mark.buildconfigspec('cmd_fat')
+@pytest.mark.buildconfigspec('cmd_nvedit_efi')
+@pytest.mark.slow
+class TestEfiSignedImage(object):
+def test_efi_signed_image_auth1(self, u_boot_console, efi_boot_env):
+"""
+Test Case 1 - authenticated by db
+"""
+disk_img = efi_boot_env
+with u_boot_console.log.section('Test Case 1a'):
+# Test Case 1a, run signed image if no db/dbx
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'efidebug boot add 1 HELLO1 host 0:1 /helloworld.efi.signed 
""',
+'efidebug boot next 1',
+'bootefi bootmgr'])
+assert(re.search('Hello, world!', ''.join(output)))
+
+with u_boot_console.log.section('Test Case 1b'):
+# Test Case 1b, run unsigned image if no db/dbx
+output = u_boot_console.run_command_list([
+'efidebug boot add 2 HELLO2 host 0:1 /helloworld.efi ""',
+'efidebug boot next 2',
+'bootefi bootmgr'])
+assert(re.search('Hello, world!', ''.join(output)))
+
+with u_boot_console.log.section('Test Case 1c'):
+# Test Case 1c, not authenticated by db
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 db.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize db',
+'fatload host 0:1 400 KEK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize KEK',
+'fatload host 0:1 400 PK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize PK'])
+assert(not re.search('Failed to set EFI variable', 
''.join(output)))
+output = u_boot_console.run_command_list([
+'efidebug boot next 2',
+'bootefi bootmgr'])
+assert(re.search('\'HELLO2\' failed', ''.join(output)))
+
+with u_boot_console.log.section('Test Case 1d'):
+# Test Case 1d, authenticated by db
+output = u_boot_console.run_command_list([
+'efidebug boot next 1',
+'bootefi bootmgr'])
+assert(re.search('Hello, world!', ''.join(output)))
+
+def test_efi_signed_image_auth2(self, u_boot_console, efi_boot_env):
+"""
+Test Case 2 - rejected by dbx
+"""
+disk_img = efi_boot_env
+with u_boot_console.log.section('Test Case 2a'):
+# Test Case 2a, rejected by dbx
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'fatload host 0:1 400 db.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize dbx',
+'fatload host 0:1 400 KEK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize KEK',
+'fatload host 0:1 400 PK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize PK'])
+assert(not re.search('Failed to set EFI variable', 
''.join(output)))
+output = u_boot_console.run_command_list([
+'efidebug boot add 1 HELLO host 0:1 /helloworld.efi.signed ""',
+'efidebug boot next 1',
+'bootefi bootmgr'])
+assert(re.search('\'HELLO\' failed', ''.join(output)))
+
+with u_boot_console.log.section('Test Case 2b'):
+# Test Case 2b, rejected by dbx even if db allows
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 db.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize db'])
+assert(not re.search('Failed to set EFI variable', 
''.join(output)))
+   

[U-Boot] [PATCH 08/16] efi_loader: variable: add secure boot state transition

2019-11-12 Thread AKASHI Takahiro
UEFI specification defines several global variables which are related to
the current secure boot state. In this commit, those values will be
maintained according to operations. Currently, AuditMode and DeployedMode
are defined but not implemented.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_variable.c | 231 +-
 1 file changed, 228 insertions(+), 3 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 7e7db8e4a10d..eb6135be6154 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -15,8 +15,16 @@
 #include 
 #include "../lib/crypto/pkcs7_parser.h"
 
+enum efi_secure_mode {
+   EFI_MODE_SETUP,
+   EFI_MODE_USER,
+   EFI_MODE_AUDIT,
+   EFI_MODE_DEPLOYED,
+};
+
 const efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
 static bool efi_secure_boot;
+static int efi_secure_mode;
 
 #define READ_ONLY BIT(31)
 
@@ -158,6 +166,210 @@ static const char *parse_attr(const char *str, u32 
*attrp, u64 *timep)
return str;
 }
 
+static efi_status_t efi_set_variable_internal(u16 *variable_name,
+ const efi_guid_t *vendor,
+ u32 attributes,
+ efi_uintn_t data_size,
+ const void *data,
+ bool ro_check);
+
+/**
+ * efi_transfer_secure_state - handle a secure boot state transition
+ * @mode:  new state
+ *
+ * Depending on @mode, secure boot related variables are updated.
+ * Those variables are *read-only* for users, efi_set_variable_internal()
+ * is called here.
+ *
+ * Return: EFI_SUCCESS on success, status code (negative) on error
+ */
+static efi_status_t efi_transfer_secure_state(enum efi_secure_mode mode)
+{
+   u32 attributes;
+   u8 val;
+   efi_status_t ret;
+
+   debug("Secure state from %d to %d\n", efi_secure_mode, mode);
+
+   attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
+EFI_VARIABLE_RUNTIME_ACCESS;
+   if (mode == EFI_MODE_DEPLOYED) {
+   val = 1;
+   ret = efi_set_variable_internal(L"SecureBoot",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+   sizeof(val), ,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+   val = 0;
+   ret = efi_set_variable_internal(L"SetupMode",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+   sizeof(val), ,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+   val = 0;
+   ret = efi_set_variable_internal(L"AuditMode",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+   sizeof(val), ,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+   val = 1;
+   ret = efi_set_variable_internal(L"DeployedMode",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+   sizeof(val), ,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+
+   efi_secure_boot = true;
+   } else if (mode == EFI_MODE_AUDIT) {
+   ret = efi_set_variable_internal(L"PK",
+   _global_variable_guid,
+   attributes,
+   0, NULL,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+   val = 0;
+   ret = efi_set_variable_internal(L"SecureBoot",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+   sizeof(val), ,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+   val = 1;
+   ret = efi_set_variable_internal(L"SetupMode",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+  

[U-Boot] [PATCH 14/16] efi_loader, pytest: set up secure boot environment

2019-11-12 Thread AKASHI Takahiro
A fixture for UEFI secure boot tests (image authentication and variable
authentication) is defined. A small file system with test data in a single
partition formatted in fat is created.

This test requires efitools v1.5.2 or later. If the system's efitools
is older, you have to build it on your own and define EFITOOLS_PATH.

Signed-off-by: AKASHI Takahiro 
---
 .travis.yml|   4 +
 test/py/README.md  |   4 +
 test/py/tests/test_efi_secboot/conftest.py | 128 +
 test/py/tests/test_efi_secboot/defs.py |  21 
 4 files changed, 157 insertions(+)
 create mode 100644 test/py/tests/test_efi_secboot/conftest.py
 create mode 100644 test/py/tests/test_efi_secboot/defs.py

diff --git a/.travis.yml b/.travis.yml
index 1e9837869508..edb87fc6396d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -38,6 +38,10 @@ addons:
 - libisl15
 - clang-7
 - srecord
+- coreutils
+- dosfstools
+- efitools
+- udisks2
 
 install:
  # Clone uboot-test-hooks
diff --git a/test/py/README.md b/test/py/README.md
index 3cbe01b73e28..bb8d6c9d21dd 100644
--- a/test/py/README.md
+++ b/test/py/README.md
@@ -38,6 +38,10 @@ will be required.  The following is an incomplete list:
 | sudo OR guestmount |
 | e2fsprogs  |
 | dosfstools |
+| coreutils  |
+| efitools   |
+| sbsigntools|
+| udisks2|
 
 Please use the apporirate commands for your distribution to match these tools
 up with the package that provides them.
diff --git a/test/py/tests/test_efi_secboot/conftest.py 
b/test/py/tests/test_efi_secboot/conftest.py
new file mode 100644
index ..e50f749ad1a6
--- /dev/null
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -0,0 +1,128 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2019, Linaro Limited
+# Author: AKASHI Takahiro 
+
+import os
+import os.path
+import pytest
+import re
+from subprocess import call, check_call, check_output, CalledProcessError
+from defs import *
+
+#
+# Fixture for UEFI secure boot test
+#
+# NOTE: yield_fixture was deprecated since pytest-3.0
+@pytest.yield_fixture()
+def efi_boot_env(request, u_boot_config):
+"""Set up a file system to be used in UEFI secure boot test.
+
+Args:
+request: Pytest request object.
+   u_boot_config: U-boot configuration.
+
+Return:
+A path to disk image to be used for testing
+"""
+global HELLO_PATH
+
+image_path = u_boot_config.persistent_data_dir
+image_path = image_path + '/' + EFI_SECBOOT_IMAGE_NAME
+image_size = EFI_SECBOOT_IMAGE_SIZE
+part_size = EFI_SECBOOT_PART_SIZE
+fs_type = EFI_SECBOOT_FS_TYPE
+
+if HELLO_PATH == '':
+HELLO_PATH = u_boot_config.build_dir + '/lib/efi_loader/helloworld.efi'
+
+try:
+# create a disk/partition
+check_call('dd if=/dev/zero of=%s bs=1MiB count=%d'
+% (image_path, image_size), shell=True)
+check_call('sgdisk %s -n 1:0:+%dMiB'
+% (image_path, part_size), shell=True)
+# create a file system
+check_call('dd if=/dev/zero of=%s.tmp bs=1MiB count=%d'
+% (image_path, part_size), shell=True)
+check_call('mkfs -t %s %s.tmp' % (fs_type, image_path), shell=True)
+check_call('dd if=%s.tmp of=%s bs=1MiB seek=1 count=%d conv=notrunc'
+% (image_path, image_path, 1), shell=True)
+check_call('rm %s.tmp' % image_path, shell=True)
+out_data = check_output('udisksctl loop-setup -f %s -o %d'
+% (image_path, 1048576), shell=True).decode()
+m = re.search('(?<= as )(.*)\.', out_data)
+loop_dev = m.group(1)
+# print 'loop device is: %s' % loop_dev
+out_data = check_output('udisksctl info -b %s' % loop_dev, 
shell=True).decode()
+m = re.search('MountPoints:[ \t]+(.*)', out_data)
+mnt_point = m.group(1)
+# print 'mount point is: %s' % mnt_point
+
+# suffix
+# *.key: RSA private key in PEM
+# *.crt: X509 certificate (self-signed) in PEM
+# *.esl: signature list
+# *.hash: message digest of image as signature list
+# *.auth: signed signature list in signature database format
+# *.efi: UEFI image
+# *.efi.signed: signed UEFI image
+
+# Create signature database
+## PK
+check_call('cd %s; openssl req -x509 -sha256 -newkey rsa:2048 -subj 
/CN=TEST_PK/ -keyout PK.key -out PK.crt -nodes -days 365'
+% mnt_point, shell=True)
+check_call('cd %s; %scert-to-efi-sig-list -g %s PK.crt PK.esl; 
%ssign-efi-sig-list -c PK.crt -k PK.key PK PK.esl PK.auth'
+% (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
+shell=True)
+## PK_null for deletion
+check_call('cd %s; sleep 2; touch PK_null.esl; %ssign-efi-sig-list 

[U-Boot] [PATCH 09/16] efi_loader: variable: add VendorKeys variable

2019-11-12 Thread AKASHI Takahiro
The following variable is exported as UEFI specification defines:
VendorKeys: whether the system is configured to use only vendor-provided
keys or not
The value will have to be modified if a platform has its own way of
initializing signature database, in particular, PK.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_variable.c | 69 ---
 1 file changed, 63 insertions(+), 6 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index eb6135be6154..c7138183b0b0 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -25,6 +25,7 @@ enum efi_secure_mode {
 const efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
 static bool efi_secure_boot;
 static int efi_secure_mode;
+static u8 efi_vendor_keys;
 
 #define READ_ONLY BIT(31)
 
@@ -342,6 +343,8 @@ static efi_status_t efi_transfer_secure_state(enum 
efi_secure_mode mode)
return EFI_INVALID_PARAMETER;
}
 
+   efi_secure_mode = mode;
+
return EFI_SUCCESS;
 
 err:
@@ -357,16 +360,46 @@ err:
  */
 static efi_status_t efi_init_secure_state(void)
 {
-   efi_uintn_t size = 0;
+   enum efi_secure_mode mode;
+   efi_uintn_t size;
efi_status_t ret;
 
+   /*
+* TODO:
+* Since there is currently no "platform-specific" installation
+* method of Platform Key, we can't say if VendorKeys is 0 or 1
+* precisely.
+*/
+
+   size = 0;
ret = EFI_CALL(efi_get_variable(L"PK", _global_variable_guid,
NULL, , NULL));
-   if (ret == EFI_BUFFER_TOO_SMALL && IS_ENABLED(CONFIG_EFI_SECURE_BOOT))
-   ret = efi_transfer_secure_state(EFI_MODE_USER);
-   else
-   ret = efi_transfer_secure_state(EFI_MODE_SETUP);
+   if (ret == EFI_BUFFER_TOO_SMALL) {
+   if (IS_ENABLED(CONFIG_EFI_SECURE_BOOT))
+   mode = EFI_MODE_USER;
+   else
+   mode = EFI_MODE_SETUP;
+
+   efi_vendor_keys = 0;
+   } else if (ret == EFI_NOT_FOUND) {
+   mode = EFI_MODE_SETUP;
+   efi_vendor_keys = 1;
+   } else {
+   goto err;
+   }
 
+   ret = efi_transfer_secure_state(mode);
+   if (ret == EFI_SUCCESS)
+   ret = efi_set_variable_internal(L"VendorKeys",
+   _global_variable_guid,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS
+| EFI_VARIABLE_RUNTIME_ACCESS
+| READ_ONLY,
+   sizeof(efi_vendor_keys),
+   _vendor_keys,
+   false);
+
+err:
return ret;
 }
 
@@ -1121,6 +1154,8 @@ out:
if (env_set(native_name, val)) {
ret = EFI_DEVICE_ERROR;
} else {
+   bool vendor_keys_modified = false;
+
if ((u16_strcmp(variable_name, L"PK") == 0 &&
 guidcmp(vendor, _global_variable_guid) == 0)) {
ret = efi_transfer_secure_state(
@@ -1128,8 +1163,30 @@ out:
  EFI_MODE_USER));
if (ret != EFI_SUCCESS)
goto err;
+
+   if (efi_secure_mode != EFI_MODE_SETUP)
+   vendor_keys_modified = true;
+   } else if ((u16_strcmp(variable_name, L"KEK") == 0 &&
+guidcmp(vendor, _global_variable_guid) == 0)) {
+   if (efi_secure_mode != EFI_MODE_SETUP)
+   vendor_keys_modified = true;
+   }
+
+   /* update VendorKeys */
+   if (vendor_keys_modified & efi_vendor_keys) {
+   efi_vendor_keys = 0;
+   ret = efi_set_variable_internal(
+   L"VendorKeys",
+   _global_variable_guid,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS
+| EFI_VARIABLE_RUNTIME_ACCESS
+| READ_ONLY,
+   sizeof(efi_vendor_keys),
+   _vendor_keys,
+   false);
+   } else {
+   ret = EFI_SUCCESS;
}
-   ret = EFI_SUCCESS;
}
 
 err:
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 01/16] include: pe.h: add signature-related definitions

2019-11-12 Thread AKASHI Takahiro
The index (IMAGE_DIRECTORY_ENTRY_CERTTABLE) in a table points to
a region containing authentication information (image's signature)
in PE format.

WIN_CERTIFICATE structure defines an embedded signature format.

Those definitions will be used in my UEFI secure boot patch.

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

diff --git a/include/pe.h b/include/pe.h
index bff3b0aa7a6c..650478ca78af 100644
--- a/include/pe.h
+++ b/include/pe.h
@@ -155,6 +155,7 @@ typedef struct _IMAGE_SECTION_HEADER {
uint32_t Characteristics;
 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
 
+#define IMAGE_DIRECTORY_ENTRY_CERTTABLE 4
 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5
 
 typedef struct _IMAGE_BASE_RELOCATION
@@ -252,4 +253,19 @@ typedef struct _IMAGE_RELOCATION
 #define IMAGE_REL_AMD64_PAIR0x000F
 #define IMAGE_REL_AMD64_SSPAN32 0x0010
 
+/* certificate appended to PE image */
+typedef struct _WIN_CERTIFICATE {
+   uint32_t dwLength;
+   uint16_t wRevision;
+   uint16_t wCertificateType;
+   uint8_t bCertificate[];
+} WIN_CERTIFICATE, *LPWIN_CERTIFICATE;
+
+#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
+#define WIN_CERT_TYPE_EFI_OKCS115  0x0EF0
+#define WIN_CERT_TYPE_EFI_GUID 0x0EF1
+
+#define WIN_CERT_REVISION_1_0  0x0100
+#define WIN_CERT_REVISION_2_0  0x0200
+
 #endif /* _PE_H */
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 07/16] efi_loader: variable: support variable authentication

2019-11-12 Thread AKASHI Takahiro
With this commit, EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
is supported for authenticated variables and the system secure state
will transfer between setup mode and user mode as UEFI specification
section 32.3 describes.

Internally, authentication data is stored as part of authenticated
variable's value. It is nothing but a pkcs7 message (but we need some
wrapper, see efi_variable_parse_signature()) and will be validated by
efi_variable_authenticate(), hence efi_signature_verify_with_db().

Associated time value will be encoded in "{...,time=...}" along with
other UEFI variable's attributes.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_loader.h  |   3 +
 lib/efi_loader/efi_variable.c | 664 --
 2 files changed, 563 insertions(+), 104 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 92b683b7653a..2922ee5089a8 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -175,6 +175,7 @@ extern const efi_guid_t efi_guid_image_security_database;
 extern const efi_guid_t efi_guid_sha256;
 extern const efi_guid_t efi_guid_cert_x509;
 extern const efi_guid_t efi_guid_cert_x509_sha256;
+extern const efi_guid_t efi_guid_cert_type_pkcs7;
 
 extern unsigned int __efi_runtime_start, __efi_runtime_stop;
 extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
@@ -697,6 +698,8 @@ efi_status_t efi_image_region_add(struct efi_image_regions 
*regs,
 
 void efi_sigstore_free(struct efi_signature_store *sigstore);
 struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name);
+
+bool efi_secure_boot_enabled(void);
 #endif /* CONFIG_EFI_SECURE_BOOT */
 
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 46f35bc60ba0..7e7db8e4a10d 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -10,7 +10,13 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
+#include "../lib/crypto/pkcs7_parser.h"
+
+const efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
+static bool efi_secure_boot;
 
 #define READ_ONLY BIT(31)
 
@@ -107,7 +113,7 @@ static const char *prefix(const char *str, const char 
*prefix)
  * @attrp: pointer to UEFI attributes
  * Return: pointer to remainder of U-Boot variable value
  */
-static const char *parse_attr(const char *str, u32 *attrp)
+static const char *parse_attr(const char *str, u32 *attrp, u64 *timep)
 {
u32 attr = 0;
char sep = '{';
@@ -130,6 +136,12 @@ static const char *parse_attr(const char *str, u32 *attrp)
attr |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
} else if ((s = prefix(str, "run"))) {
attr |= EFI_VARIABLE_RUNTIME_ACCESS;
+   } else if ((s = prefix(str, "time="))) {
+   attr |= 
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
+   hex2bin((u8 *)timep, s, sizeof(*timep));
+   s += sizeof(*timep) * 2;
+   } else if (*str == '}') {
+   break;
} else {
printf("invalid attribute: %s\n", str);
break;
@@ -147,48 +159,290 @@ static const char *parse_attr(const char *str, u32 
*attrp)
 }
 
 /**
- * efi_get_variable() - retrieve value of a UEFI variable
+ * efi_secure_boot_enabled - return if secure boot is enabled or not
  *
- * This function implements the GetVariable runtime service.
+ * Return: true if enabled, false if disabled
+ */
+bool efi_secure_boot_enabled(void)
+{
+   return efi_secure_boot;
+}
+
+#ifdef CONFIG_EFI_SECURE_BOOT
+static u8 pkcs7_hdr[] = {
+   /* SEQUENCE */
+   0x30, 0x82, 0x05, 0xc7,
+   /* OID: pkcs7-signedData */
+   0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02,
+   /* Context Structured? */
+   0xa0, 0x82, 0x05, 0xb8,
+};
+
+/**
+ * efi_variable_parse_signature - parse a signature in variable
+ * @buf:   Pointer to variable's value
+ * @buflen:Length of @buf
  *
- * See the Unified Extensible Firmware Interface (UEFI) specification for
- * details.
+ * Parse a signature embedded in variable's value and instantiate
+ * a pkcs7_message structure. Since pkcs7_parse_message() accepts only
+ * pkcs7's signedData, some header needed be prepended for correctly
+ * parsing authentication data, particularly for variable's.
  *
- * @variable_name: name of the variable
- * @vendor:vendor GUID
- * @attributes:attributes of the variable
- * @data_size: size of the buffer to which the variable value is copied
- * @data:  buffer to which the variable value is copied
- * Return: status code
+ * Return: Pointer to pkcs7_message structure on success, NULL on error
  */
-efi_status_t EFIAPI efi_get_variable(u16 *variable_name,
-const efi_guid_t *vendor, u32 

[U-Boot] [PATCH v3 0/6] rsa: extend rsa_verify() for UEFI secure boot

2019-11-12 Thread AKASHI Takahiro
# This patch set is a prerequisite for UEFI secure boot.

The current rsa_verify() requires five parameters for a RSA public key
for efficiency while RSA, in theory, requires only two. In addition,
those parameters are expected to come from FIT image.

So this function won't fit very well when we want to use it for the purpose
of implementing UEFI secure boot, in particular, image authentication
as well as variable authentication, where the essential two parameters
are set to be retrieved from one of X509 certificates in signature
database.

So, in this patch, additional three parameters will be calculated
on the fly when rsa_verify() is called without fdt which should contain
parameters above.

This calculation heavily relies on "big-number (or multi-precision)
library." Therefore some routines from BearSSL[1] under MIT license are
imported in this implementation. See Patch#4.
# Please let me know if this is not appropriate.

# Checkpatch will complain with lots of warnings/errors, but
# I intentionally don't fix them for maximum maintainability.

  [1] https://bearssl.org/
  [2] https://lists.denx.de/pipermail/u-boot/2019-October/388263.html

Changes in v3 (Nov 13, 2019)
* remove RSA_VERIFY_WITH_PKEY, which is to be added in patch#2 (patch#1)
* modify unit test Kconfg due to removal of test/lib/Kconfig (patch#6)

Changes in v2 (Oct 29, 2019)
* fix build errors at Travis CI
* not include linux/kconfig.h (patch#1)
* add a separate patch for adding CONFIG_RSA_VERIFY_WITH_PKEY (patch#2)
* take a prerequisite patch from my "secure boot patch" (patch#3)
* add a dependency on RSA_PUBLIC_KEY_PARSER (patch#4)
* remove "inline" directives (patch#4)
* add function descriptions, which mostly come from BearSSL's src/inner.h
  (patch#4)
* improve Kconfig help text after Simon's comment (patch#5)
* add function description of rsa_verify_with_pkey() (patch#5)
* modify rsa_verify() to use "if (CONFIG_IS_ENABLED(...) " style
  rather than "#ifdef CONFIG_..." (patch#5)
* add function tests (patch#6)

Changes in v1 (Oct 9, 2019)
* fix a build error on pine64-lts_defconfig (reported by Heinrich)
  by defining FIT_IMAGE_ENABLE_VERIFY flag and adding
  SPL_RSA_VERIFY config (patch#1)
* remove FIT-specific code from image-sig.c and put them to new
  image-fit-sig.c to allow us to disable CONFIG_FIT_SIGNATURE (patch#1)
* compile rsa-keyprop.c only if necessary (i.e. if
  CONFIG_RSA_VERIFY_WITH_PKEY) (patch#2)
* add SPDX license identifier in rsa-keyprop.c (patch#2)
* include  instead of  (patch#2)
* use U-Boot's byteorder helper functions instead of BearSSL's (patch#2)

AKASHI Takahiro (6):
  lib: rsa: decouple rsa from FIT image verification
  rsa: add CONFIG_RSA_VERIFY_WITH_PKEY config
  include: image.h: add key info to image_sign_info
  lib: rsa: generate additional parameters for public key
  lib: rsa: add rsa_verify_with_pkey()
  test: add rsa_verify() unit test

 Kconfig  |   1 +
 common/Makefile  |   3 +-
 common/image-fit-sig.c   | 417 
 common/image-fit.c   |   6 +-
 common/image-sig.c   | 396 ---
 include/image.h  |  23 +-
 include/u-boot/rsa-mod-exp.h |  21 +
 lib/rsa/Kconfig  |  27 ++
 lib/rsa/Makefile |   3 +-
 lib/rsa/rsa-keyprop.c| 717 +++
 lib/rsa/rsa-verify.c | 129 +--
 test/Kconfig |  12 +
 test/lib/Makefile|   1 +
 test/lib/rsa.c   | 207 ++
 tools/Makefile   |   2 +-
 15 files changed, 1530 insertions(+), 435 deletions(-)
 create mode 100644 common/image-fit-sig.c
 create mode 100644 lib/rsa/rsa-keyprop.c
 create mode 100644 test/lib/rsa.c

-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 04/16] efi_loader: add CONFIG_EFI_SECURE_BOOT config option

2019-11-12 Thread AKASHI Takahiro
Under this configuration, UEFI secure boot support will be added
in later patches.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/Kconfig | 13 +
 1 file changed, 13 insertions(+)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index c7027a967653..fb66766d2b7a 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -115,4 +115,17 @@ config EFI_GRUB_ARM32_WORKAROUND
  GRUB prior to version 2.04 requires U-Boot to disable caches. This
  workaround currently is also needed on systems with caches that
  cannot be managed via CP15.
+
+config EFI_SECURE_BOOT
+   bool "Enable EFI secure boot support"
+   depends on EFI_LOADER
+   depends on SECURE_BOOT
+   imply RSA_VERIFY_WITH_PKEY
+   default n
+   help
+ Select this option to enable EFI secure boot support.
+ Once SecureBoot mode is enforced, any EFI binary can run only if
+ it is signed with a trusted key. To do that, you need to install,
+ at least, PK, KEK and db.
+
 endif
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 12/16] cmd: env: use appropriate guid for authenticated UEFI variable

2019-11-12 Thread AKASHI Takahiro
A signature database variable is associated with a specific guid.
For convenience, if user doesn't supply any guid info, "env set|print -e"
should complement it.

Signed-off-by: AKASHI Takahiro 
---
 cmd/nvedit_efi.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c
index 8ea0da01283f..579cf430593c 100644
--- a/cmd/nvedit_efi.c
+++ b/cmd/nvedit_efi.c
@@ -41,6 +41,11 @@ static const struct {
 } efi_guid_text[] = {
/* signature database */
{EFI_GLOBAL_VARIABLE_GUID, "EFI_GLOBAL_VARIABLE_GUID"},
+   {EFI_IMAGE_SECURITY_DATABASE_GUID, "EFI_IMAGE_SECURITY_DATABASE_GUID"},
+   /* certificate type */
+   {EFI_CERT_SHA256_GUID, "EFI_CERT_SHA256_GUID"},
+   {EFI_CERT_X509_GUID, "EFI_CERT_X509_GUID"},
+   {EFI_CERT_TYPE_PKCS7_GUID, "EFI_CERT_TYPE_PKCS7_GUID"},
 };
 
 /* "----" */
@@ -525,9 +530,9 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
if (*ep != ',')
return CMD_RET_USAGE;
 
+   /* 0 should be allowed for delete */
size = simple_strtoul(++ep, NULL, 16);
-   if (!size)
-   return CMD_RET_FAILURE;
+
value_on_memory = true;
} else if (!strcmp(argv[0], "-v")) {
verbose = true;
@@ -539,8 +544,13 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
return CMD_RET_USAGE;
 
var_name = argv[0];
-   if (default_guid)
-   guid = efi_global_variable_guid;
+   if (default_guid) {
+   if (!strcmp(var_name, "db") || !strcmp(var_name, "dbx") ||
+   !strcmp(var_name, "dbt"))
+   guid = efi_guid_image_security_database;
+   else
+   guid = efi_global_variable_guid;
+   }
 
if (verbose) {
printf("GUID: %s\n", efi_guid_to_str((const efi_guid_t *)
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 6/6] test: add rsa_verify() unit test

2019-11-12 Thread AKASHI Takahiro
In this patch, a very simple test is added to verify that rsa_verify()
using rsa_verify_with_pkey() work correctly.

To keep the code simple, all the test data, either public key and
verified binary data, are embedded in the source.

Signed-off-by: AKASHI Takahiro 
---
 test/Kconfig  |  12 +++
 test/lib/Makefile |   1 +
 test/lib/rsa.c| 207 ++
 3 files changed, 220 insertions(+)
 create mode 100644 test/lib/rsa.c

diff --git a/test/Kconfig b/test/Kconfig
index cb7954041eda..64d76c3b20a5 100644
--- a/test/Kconfig
+++ b/test/Kconfig
@@ -28,6 +28,18 @@ config UT_LIB_ASN1
  Enables a test which exercises asn1 compiler and decoder function
  via various parsers.
 
+config UT_LIB_RSA
+   bool "Unit test for rsa_verify() function"
+   imply RSA
+   imply ASYMMETRIC_KEY_TYPE
+   imply ASYMMETRIC_PUBLIC_KEY_SUBTYPE
+   imply RSA_PUBLIC_KEY_PARSER
+   imply RSA_VERIFY_WITH_PKEY
+   default y
+   help
+ Enables rsa_verify() test, currently rsa_verify_with_pkey only()
+ only, at the 'ut lib' command.
+
 endif
 
 config UT_TIME
diff --git a/test/lib/Makefile b/test/lib/Makefile
index 72d2ec74b5f4..2bf6ef3935bb 100644
--- a/test/lib/Makefile
+++ b/test/lib/Makefile
@@ -8,3 +8,4 @@ obj-y += lmb.o
 obj-y += string.o
 obj-$(CONFIG_ERRNO_STR) += test_errno_str.o
 obj-$(CONFIG_UT_LIB_ASN1) += asn1.o
+obj-$(CONFIG_UT_LIB_RSA) += rsa.o
diff --git a/test/lib/rsa.c b/test/lib/rsa.c
new file mode 100644
index ..ef3860b59a2b
--- /dev/null
+++ b/test/lib/rsa.c
@@ -0,0 +1,207 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019 Linaro Limited
+ * Author: AKASHI Takahiro
+ *
+ * Unit test for rsa_verify() function
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#ifdef CONFIG_RSA_VERIFY_WITH_PKEY
+/*
+ * openssl genrsa 2048 -out private.pem
+ * openssl rsa -in private.pem -pubout -outform der -out public.der
+ * dd if=public.der of=public.raw bs=24 skip=1
+ */
+static unsigned char public_key[] = {
+   0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xca, 0x25, 0x23,
+   0xe0, 0x0a, 0x4d, 0x8f, 0x56, 0xfc, 0xc9, 0x06, 0x4c, 0xcc, 0x94, 0x43,
+   0xe0, 0x56, 0x44, 0x6e, 0x37, 0x54, 0x87, 0x12, 0x84, 0xf9, 0x07, 0x4f,
+   0xe4, 0x23, 0x40, 0xc3, 0x43, 0x84, 0x37, 0x86, 0xd3, 0x9d, 0x95, 0x1c,
+   0xe4, 0x8a, 0x66, 0x02, 0x09, 0xe2, 0x3d, 0xce, 0x2c, 0xc6, 0x02, 0x6a,
+   0xd4, 0x65, 0x61, 0xff, 0x85, 0x6f, 0x88, 0x63, 0xba, 0x31, 0x62, 0x1e,
+   0xb7, 0x95, 0xe9, 0x08, 0x3c, 0xe9, 0x35, 0xde, 0xfd, 0x65, 0x92, 0xb8,
+   0x9e, 0x71, 0xa4, 0xcd, 0x47, 0xfd, 0x04, 0x26, 0xb9, 0x78, 0xbf, 0x05,
+   0x0d, 0xfc, 0x00, 0x84, 0x08, 0xfc, 0xc4, 0x4b, 0xea, 0xf5, 0x97, 0x68,
+   0x0d, 0x97, 0xd7, 0xff, 0x4f, 0x92, 0x82, 0xd7, 0xbb, 0xef, 0xb7, 0x67,
+   0x8e, 0x72, 0x54, 0xe8, 0xc5, 0x9e, 0xfd, 0xd8, 0x38, 0xe9, 0xbe, 0x19,
+   0x37, 0x5b, 0x36, 0x8b, 0xbf, 0x49, 0xa1, 0x59, 0x3a, 0x9d, 0xad, 0x92,
+   0x08, 0x0b, 0xe3, 0xa4, 0xa4, 0x7d, 0xd3, 0x70, 0xc0, 0xb8, 0xfb, 0xc7,
+   0xda, 0xd3, 0x19, 0x86, 0x37, 0x9a, 0xcd, 0xab, 0x30, 0x96, 0xab, 0xa4,
+   0xa2, 0x31, 0xa0, 0x38, 0xfb, 0xbf, 0x85, 0xd3, 0x24, 0x39, 0xed, 0xbf,
+   0xe1, 0x31, 0xed, 0x6c, 0x39, 0xc1, 0xe5, 0x05, 0x2e, 0x12, 0x30, 0x36,
+   0x73, 0x5d, 0x62, 0xf3, 0x82, 0xaf, 0x38, 0xc8, 0xca, 0xfa, 0xa1, 0x99,
+   0x57, 0x3c, 0xe1, 0xc1, 0x7b, 0x05, 0x0b, 0xcc, 0x2e, 0xa9, 0x10, 0xc8,
+   0x68, 0xbd, 0x27, 0xb6, 0x19, 0x9c, 0xd2, 0xad, 0xb3, 0x1f, 0xca, 0x35,
+   0x6e, 0x84, 0x23, 0xa1, 0xe9, 0xa4, 0x4c, 0xab, 0x19, 0x09, 0x79, 0x6e,
+   0x3c, 0x7b, 0x74, 0xfc, 0x33, 0x05, 0xcf, 0xa4, 0x2e, 0xeb, 0x55, 0x60,
+   0x05, 0xc7, 0xcf, 0x3f, 0x92, 0xac, 0x2d, 0x69, 0x0b, 0x19, 0x16, 0x79,
+   0x75, 0x02, 0x03, 0x01, 0x00, 0x01
+};
+
+static unsigned int public_key_len = 270;
+
+/*
+ * dd if=/dev/urandom of=data.raw bs=512 count=1
+ */
+static unsigned char data_raw[] = {
+   0x3e, 0x48, 0x6e, 0xef, 0x83, 0xd1, 0x4c, 0xfd, 0x92, 0x47, 0x92, 0xd7,
+   0xf6, 0x16, 0x25, 0x0a, 0xdf, 0xe2, 0xb6, 0x6c, 0xe7, 0xe0, 0x55, 0xb2,
+   0x70, 0x66, 0xf0, 0xe5, 0xdc, 0xaf, 0xd3, 0x2e, 0xc1, 0x3e, 0x5c, 0x4b,
+   0xb5, 0xa7, 0x23, 0x1f, 0x2c, 0xce, 0xf8, 0x83, 0x00, 0x6d, 0xeb, 0xdd,
+   0x19, 0x71, 0x13, 0xb4, 0xae, 0x5c, 0xa8, 0xae, 0x52, 0xc8, 0xe1, 0x77,
+   0x9e, 0x98, 0x75, 0xbc, 0xef, 0x36, 0x9f, 0x0c, 0x14, 0xed, 0x1a, 0x0a,
+   0x4f, 0x6c, 0xa4, 0xb1, 0xbb, 0x0e, 0x43, 0x93, 0x12, 0xfc, 0x2e, 0x82,
+   0x93, 0x4e, 0xcb, 0xa2, 0xcd, 0x59, 0x3f, 0xc5, 0x11, 0x38, 0x3a, 0x88,
+   0xc3, 0xcf, 0xf9, 0x61, 0xa8, 0x9e, 0x96, 0xb6, 0xbf, 0xa6, 0x5b, 0x0d,
+   0xd9, 0xbd, 0x05, 0x4c, 0xbe, 0xed, 0x86, 0xca, 0x10, 0x63, 0x72, 0x75,
+   0x4b, 0xbd, 0x86, 0x42, 0x30, 0x9d, 0x54, 0x4e, 0x12, 0xda, 0xf4, 0xb4,
+   0xfd, 0xd9, 0x54, 0x95, 0x8f, 0x83, 0xc2, 0x63, 0x44, 0xdd, 0x96, 0x1a,
+ 

[U-Boot] [PATCH 13/16] cmd: env: add "-at" option to "env set -e" command

2019-11-12 Thread AKASHI Takahiro
With "-at" option, EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
will be passed to SetVariable() to authenticate the variable.

Signed-off-by: AKASHI Takahiro 
---
 cmd/nvedit.c | 5 +++--
 cmd/nvedit_efi.c | 5 -
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 99a3bc57b15f..30cd655b7260 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -1399,7 +1399,7 @@ static char env_help_text[] =
 #endif
 #endif
 #if defined(CONFIG_CMD_NVEDIT_EFI)
-   "env set -e [-nv][-bs][-rt][-a][-i addr,size][-v] name [arg ...]\n"
+   "env set -e [-nv][-bs][-rt][-at][-a][-i addr,size][-v] name [arg ...]\n"
"- set UEFI variable; unset if '-i' or 'arg' not specified\n"
 #endif
"env set [-f] name [arg ...]\n";
@@ -1461,13 +1461,14 @@ U_BOOT_CMD_COMPLETE(
setenv, CONFIG_SYS_MAXARGS, 0,  do_env_set,
"set environment variables",
 #if defined(CONFIG_CMD_NVEDIT_EFI)
-   "-e [-guid guid][-nv][-bs][-rt][-a][-v]\n"
+   "-e [-guid guid][-nv][-bs][-rt][-at][-a][-v]\n"
"[-i addr,size name], or [name [value ...]]\n"
"- set UEFI variable 'name' to 'value' ...'\n"
"  \"-guid\": set vendor guid\n"
"  \"-nv\": set non-volatile attribute\n"
"  \"-bs\": set boot-service attribute\n"
"  \"-rt\": set runtime attribute\n"
+   "  \"-at\": set time-based authentication attribute\n"
"  \"-a\": append-write\n"
"  \"-i addr,size\": use  as variable's value\n"
"  \"-v\": verbose message\n"
diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c
index 579cf430593c..837e39e02179 100644
--- a/cmd/nvedit_efi.c
+++ b/cmd/nvedit_efi.c
@@ -458,7 +458,7 @@ out:
  * Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE
  *
  * This function is for "env set -e" or "setenv -e" command:
- *   => env set -e [-guid guid][-nv][-bs][-rt][-a][-v]
+ *   => env set -e [-guid guid][-nv][-bs][-rt][-at][-a][-v]
  *[-i address,size] var, or
  * var [value ...]
  * Encode values specified and set given UEFI variable.
@@ -517,6 +517,9 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
attributes |= EFI_VARIABLE_RUNTIME_ACCESS;
} else if (!strcmp(argv[0], "-nv")) {
attributes |= EFI_VARIABLE_NON_VOLATILE;
+   } else if (!strcmp(argv[0], "-at")) {
+   attributes |=
+ EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
} else if (!strcmp(argv[0], "-a")) {
attributes |= EFI_VARIABLE_APPEND_WRITE;
} else if (!strcmp(argv[0], "-i")) {
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 10/16] efi_loader: image_loader: support image authentication

2019-11-12 Thread AKASHI Takahiro
With this commit, image validation can be enforced, as UEFI specification
section 32.5 describes, if CONFIG_EFI_SECURE_BOOT is enabled.

Currently we support
* authentication based on db and dbx,
  so dbx-validated image will always be rejected.
* following signature types:
EFI_CERT_SHA256_GUID (SHA256 digest for unsigned images)
EFI_CERT_X509_GUID (x509 certificate for signed images)
Timestamp-based certificate revocation is not supported here.

Internally, authentication data is stored in one of certificates tables
of PE image (See efi_image_parse()) and will be verified by
efi_image_authenticate() before loading a given image.

It seems that UEFI specifiction defines the verification process
in a bit ambiguous way. I tried to implement it as closely to as
EDK2 does.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_loader.h  |   7 +-
 lib/efi_loader/efi_boottime.c |   2 +-
 lib/efi_loader/efi_image_loader.c | 443 +-
 3 files changed, 438 insertions(+), 14 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 2922ee5089a8..a0fa85792f9f 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static inline int guidcmp(const void *g1, const void *g2)
 {
@@ -398,7 +399,8 @@ efi_status_t efi_set_watchdog(unsigned long timeout);
 /* Called from places to check whether a timer expired */
 void efi_timer_check(void);
 /* PE loader implementation */
-efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, void *efi,
+efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
+void *efi, size_t efi_size,
 struct efi_loaded_image *loaded_image_info);
 /* Called once to store the pristine gd pointer */
 void efi_save_gd(void);
@@ -700,6 +702,9 @@ void efi_sigstore_free(struct efi_signature_store 
*sigstore);
 struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name);
 
 bool efi_secure_boot_enabled(void);
+
+bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
+WIN_CERTIFICATE **auth, size_t *auth_len);
 #endif /* CONFIG_EFI_SECURE_BOOT */
 
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 493d906c641d..311681764034 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -1879,7 +1879,7 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy,
efi_dp_split_file_path(file_path, , );
ret = efi_setup_loaded_image(dp, fp, image_obj, );
if (ret == EFI_SUCCESS)
-   ret = efi_load_pe(*image_obj, dest_buffer, info);
+   ret = efi_load_pe(*image_obj, dest_buffer, source_size, info);
if (!source_buffer)
/* Release buffer to which file was loaded */
efi_free_pages((uintptr_t)dest_buffer,
diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index 13541cfa7a28..1cef5abf7e1b 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -9,7 +9,9 @@
 
 #include 
 #include 
+#include 
 #include 
+#include "../lib/crypto/pkcs7_parser.h"
 
 const efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
 const efi_guid_t efi_guid_device_path = EFI_DEVICE_PATH_PROTOCOL_GUID;
@@ -205,6 +207,356 @@ static void efi_set_code_and_data_type(
}
 }
 
+#ifdef CONFIG_EFI_SECURE_BOOT
+/**
+ * efi_image_parse - parse a PE image
+ * @efi:   Pointer to image
+ * @len:   Size of @efi
+ * @regs:  Pointer to a list of regions
+ * @auth:  Pointer to a pointer to authentication data in PE
+ * @auth_len:  Size of @auth
+ *
+ * Parse image binary in PE32(+) format, assuming that sanity of PE image
+ * has been checked by a caller.
+ * On success, an address of authentication data in @efi and its size will
+ * be returned in @auth and @auth_len, respectively.
+ *
+ * Return: true on success, false on error
+ */
+bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
+WIN_CERTIFICATE **auth, size_t *auth_len)
+{
+   struct efi_image_regions *regs;
+   IMAGE_DOS_HEADER *dos;
+   IMAGE_NT_HEADERS32 *nt;
+   IMAGE_SECTION_HEADER *sections, **sorted;
+   int num_sections, i, j;
+   int ctidx = IMAGE_DIRECTORY_ENTRY_CERTTABLE;
+   u32 align, size, authsz, authoff;
+   size_t bytes_hashed;
+
+   regs = calloc(1, sizeof(*regs));
+   if (!regs)
+   goto err;
+
+   dos = (void *)efi;
+   nt = (void *)(efi + dos->e_lfanew);
+
+   /*
+* Collect data regions for hash calculation
+* 1. File headers
+*/
+   if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
+   IMAGE_NT_HEADERS64 *nt64 = (void *)nt;
+   IMAGE_OPTIONAL_HEADER64 *opt = >OptionalHeader;
+
+   /* Skip 

[U-Boot] [PATCH v3 5/6] lib: rsa: add rsa_verify_with_pkey()

2019-11-12 Thread AKASHI Takahiro
This function, and hence rsa_verify(), will perform RSA verification
with two essential parameters for a RSA public key in contract of
rsa_verify_with_keynode(), which requires additional three parameters
stored in FIT image.

It will be used in implementing UEFI secure boot, i.e. image authentication
and variable authentication.

Signed-off-by: AKASHI Takahiro 
---
 lib/rsa/rsa-verify.c | 57 +++-
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/lib/rsa/rsa-verify.c b/lib/rsa/rsa-verify.c
index d2fd0692fa13..3f63bd9c175b 100644
--- a/lib/rsa/rsa-verify.c
+++ b/lib/rsa/rsa-verify.c
@@ -17,9 +17,14 @@
 #include "mkimage.h"
 #include 
 #endif
+#include 
 #include 
 #include 
 
+#ifndef __UBOOT__ /* for host tools */
+#undef CONFIG_RSA_VERIFY_WITH_PKEY
+#endif
+
 /* Default public exponent for backward compatibility */
 #define RSA_DEFAULT_PUBEXP 65537
 
@@ -270,7 +275,7 @@ out:
 }
 #endif
 
-#if CONFIG_IS_ENABLED(FIT_SIGNATURE)
+#if CONFIG_IS_ENABLED(FIT_SIGNATURE) || IS_ENABLED(CONFIG_RSA_VERIFY_WITH_PKEY)
 /**
  * rsa_verify_key() - Verify a signature against some data using RSA Key
  *
@@ -344,6 +349,49 @@ static int rsa_verify_key(struct image_sign_info *info,
 }
 #endif
 
+#ifdef CONFIG_RSA_VERIFY_WITH_PKEY
+/**
+ * rsa_verify_with_pkey() - Verify a signature against some data using
+ * only modulus and exponent as RSA key properties.
+ * @info:  Specifies key information
+ * @hash:  Pointer to the expected hash
+ * @sig:   Signature
+ * @sig_len:   Number of bytes in signature
+ *
+ * Parse a RSA public key blob in DER format pointed to in @info and fill
+ * a key_prop structure with properties of the key. Then verify a RSA PKCS1.5
+ * signature against an expected hash using the calculated properties.
+ *
+ * Return  0 if verified, -ve on error
+ */
+static int rsa_verify_with_pkey(struct image_sign_info *info,
+   const void *hash, uint8_t *sig, uint sig_len)
+{
+   struct key_prop *prop;
+   int ret;
+
+   /* Public key is self-described to fill key_prop */
+   prop = rsa_gen_key_prop(info->key, info->keylen);
+   if (!prop) {
+   debug("Generating necessary parameter for decoding failed\n");
+   return -EACCES;
+   }
+
+   ret = rsa_verify_key(info, prop, sig, sig_len, hash,
+info->crypto->key_len);
+
+   rsa_free_key_prop(prop);
+
+   return ret;
+}
+#else
+static int rsa_verify_with_pkey(struct image_sign_info *info,
+   const void *hash, uint8_t *sig, uint sig_len)
+{
+   return -EACCES;
+}
+#endif
+
 #if CONFIG_IS_ENABLED(FIT_SIGNATURE)
 /**
  * rsa_verify_with_keynode() - Verify a signature against some data using
@@ -434,6 +482,13 @@ int rsa_verify(struct image_sign_info *info,
return -EINVAL;
}
 
+   if (IS_ENABLED(CONFIG_RSA_VERIFY_WITH_PKEY) && !info->fdt_blob) {
+   /* don't rely on fdt properties */
+   ret = rsa_verify_with_pkey(info, hash, sig, sig_len);
+
+   return ret;
+   }
+
if (CONFIG_IS_ENABLED(FIT_SIGNATURE)) {
const void *blob = info->fdt_blob;
int ndepth, noffset;
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 03/16] secure boot: rename CONFIG_SECURE_BOOT config option

2019-11-12 Thread AKASHI Takahiro
The configuration, CONFIG_SECURE_BOOT, is defined multiple times in
different architecture directories for different implementation.
If UEFI secure boot will be added later, it will make things more messy.

So let's rename them, giving each implementation to different
configuration option. CONFIG_SECURE_BOOT still remains in order not to
break existing implicit dependency.

Signed-off-by: AKASHI Takahiro 
---
 Kconfig   | 7 +++
 arch/arm/cpu/armv7/ls102xa/Kconfig| 3 ++-
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 3 ++-
 arch/powerpc/cpu/mpc85xx/Kconfig  | 3 ++-
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/Kconfig b/Kconfig
index 63690514b261..fd7d10c4aa7d 100644
--- a/Kconfig
+++ b/Kconfig
@@ -283,6 +283,13 @@ config SYS_LDSCRIPT
 
 endmenu# General setup
 
+config SECURE_BOOT
+   bool "Secure Boot"
+   imply SHA256
+   help
+ Enable Secure Boot feature. The actual behavior may vary
+ from architecture to architecture.
+
 menu "Boot images"
 
 config ANDROID_BOOT_IMAGE
diff --git a/arch/arm/cpu/armv7/ls102xa/Kconfig 
b/arch/arm/cpu/armv7/ls102xa/Kconfig
index 94fa68250ddf..ce1bc580d23d 100644
--- a/arch/arm/cpu/armv7/ls102xa/Kconfig
+++ b/arch/arm/cpu/armv7/ls102xa/Kconfig
@@ -50,8 +50,9 @@ config MAX_CPUS
  cores, count the reserved ports. This will allocate enough memory
  in spin table to properly handle all cores.
 
-config SECURE_BOOT
+config FSL_ARMV7_ENABLE_SECURE_BOOT
bool"Secure Boot"
+   depends on SECURE_BOOT
help
Enable Freescale Secure Boot feature. Normally selected
by defconfig. If unsure, do not change.
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index 24c606a2328f..b4d455ee16f4 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
@@ -375,8 +375,9 @@ config EMC2305
 Enable the EMC2305 fan controller for configuration of fan
 speed.
 
-config SECURE_BOOT
+config FSI_ARMV8_ENABLE_SECURE_BOOT
bool "Secure Boot"
+   depends on SECURE_BOOT
help
Enable Freescale Secure Boot feature
 
diff --git a/arch/powerpc/cpu/mpc85xx/Kconfig b/arch/powerpc/cpu/mpc85xx/Kconfig
index c038a6ddb0f4..9cf6ebbfe3ce 100644
--- a/arch/powerpc/cpu/mpc85xx/Kconfig
+++ b/arch/powerpc/cpu/mpc85xx/Kconfig
@@ -1208,8 +1208,9 @@ config FSL_LAW
help
Use Freescale common code for Local Access Window
 
-config SECURE_BOOT
+config FSL_MPC_ENABLE_SECURE_BOOT
bool"Secure Boot"
+   depends on SECURE_BOOT
help
Enable Freescale Secure Boot feature. Normally selected
by defconfig. If unsure, do not change.
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 11/16] efi_loader: set up secure boot

2019-11-12 Thread AKASHI Takahiro
The following variable is exported as UEFI specification defines:
SignatureSupport: array of GUIDs representing the type of signatures
  supported by the platform firmware

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_setup.c | 38 ++
 1 file changed, 38 insertions(+)

diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index de7b616c6daa..50cef1b4dfde 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -82,6 +82,39 @@ out:
return ret;
 }
 
+#ifdef CONFIG_EFI_SECURE_BOOT
+/**
+ * efi_init_secure_boot - initialize secure boot state
+ *
+ * Return: EFI_SUCCESS on success, status code (negative) on error
+ */
+static efi_status_t efi_init_secure_boot(void)
+{
+   efi_guid_t signature_types[] = {
+   EFI_CERT_SHA256_GUID,
+   EFI_CERT_X509_GUID,
+   };
+   efi_status_t ret;
+
+   /* TODO: read-only */
+   ret = EFI_CALL(efi_set_variable(L"SignatureSupport",
+   _global_variable_guid,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS
+| EFI_VARIABLE_RUNTIME_ACCESS,
+   sizeof(signature_types),
+   _types));
+   if (ret != EFI_SUCCESS)
+   printf("EFI: cannot initialize SignatureSupport variable\n");
+
+   return ret;
+}
+#else
+static efi_status_t efi_init_secure_boot(void)
+{
+   return EFI_SUCCESS;
+}
+#endif /* CONFIG_EFI_SECURE_BOOT */
+
 /**
  * efi_init_obj_list() - Initialize and populate EFI object list
  *
@@ -122,6 +155,11 @@ efi_status_t efi_init_obj_list(void)
if (ret != EFI_SUCCESS)
goto out;
 
+   /* Secure boot */
+   ret = efi_init_secure_boot();
+   if (ret != EFI_SUCCESS)
+   goto out;
+
/* Indicate supported runtime services */
ret = efi_init_runtime_supported();
if (ret != EFI_SUCCESS)
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 1/6] lib: rsa: decouple rsa from FIT image verification

2019-11-12 Thread AKASHI Takahiro
Introduce new configuration, CONFIG_RSA_VERIFY which will decouple building
RSA functions from FIT verification and allow for adding a RSA-based
signature verification for other file formats, in particular PE file
for UEFI secure boot.

Signed-off-by: AKASHI Takahiro 
---
 Kconfig|   1 +
 common/Makefile|   3 +-
 common/image-fit-sig.c | 417 +
 common/image-fit.c |   6 +-
 common/image-sig.c | 396 --
 include/image.h|  13 +-
 lib/rsa/Kconfig|  12 ++
 lib/rsa/Makefile   |   2 +-
 lib/rsa/rsa-verify.c   |  78 +---
 tools/Makefile |   2 +-
 10 files changed, 493 insertions(+), 437 deletions(-)
 create mode 100644 common/image-fit-sig.c

diff --git a/Kconfig b/Kconfig
index 66b059f749a7..63690514b261 100644
--- a/Kconfig
+++ b/Kconfig
@@ -417,6 +417,7 @@ config SPL_FIT_SIGNATURE
depends on SPL_DM
select SPL_FIT
select SPL_RSA
+   select SPL_RSA_VERIFY
 
 config SPL_LOAD_FIT
bool "Enable SPL loading U-Boot as a FIT (basic fitImage features)"
diff --git a/common/Makefile b/common/Makefile
index 302d8beaf356..d66c0068bb88 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -112,7 +112,8 @@ obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
 obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o
 obj-$(CONFIG_$(SPL_)MULTI_DTB_FIT) += boot_fit.o common_fit.o
-obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += image-sig.o
+obj-$(CONFIG_$(SPL_)RSA_VERIFY) += image-sig.o
+obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += image-fit-sig.o
 obj-$(CONFIG_IO_TRACE) += iotrace.o
 obj-y += memsize.o
 obj-y += stdio.o
diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c
new file mode 100644
index ..f6caeb0c5901
--- /dev/null
+++ b/common/image-fit-sig.c
@@ -0,0 +1,417 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2013, Google Inc.
+ */
+
+#ifdef USE_HOSTCC
+#include "mkimage.h"
+#include 
+#else
+#include 
+#include 
+DECLARE_GLOBAL_DATA_PTR;
+#endif /* !USE_HOSTCC*/
+#include 
+#include 
+#include 
+
+#define IMAGE_MAX_HASHED_NODES 100
+
+#ifdef USE_HOSTCC
+void *host_blob;
+
+void image_set_host_blob(void *blob)
+{
+   host_blob = blob;
+}
+
+void *image_get_host_blob(void)
+{
+   return host_blob;
+}
+#endif
+
+/**
+ * fit_region_make_list() - Make a list of image regions
+ *
+ * Given a list of fdt_regions, create a list of image_regions. This is a
+ * simple conversion routine since the FDT and image code use different
+ * structures.
+ *
+ * @fit: FIT image
+ * @fdt_regions: Pointer to FDT regions
+ * @count: Number of FDT regions
+ * @region: Pointer to image regions, which must hold @count records. If
+ * region is NULL, then (except for an SPL build) the array will be
+ * allocated.
+ * @return: Pointer to image regions
+ */
+struct image_region *fit_region_make_list(const void *fit,
+ struct fdt_region *fdt_regions,
+ int count,
+ struct image_region *region)
+{
+   int i;
+
+   debug("Hash regions:\n");
+   debug("%10s %10s\n", "Offset", "Size");
+
+   /*
+* Use malloc() except in SPL (to save code size). In SPL the caller
+* must allocate the array.
+*/
+#ifndef CONFIG_SPL_BUILD
+   if (!region)
+   region = calloc(sizeof(*region), count);
+#endif
+   if (!region)
+   return NULL;
+   for (i = 0; i < count; i++) {
+   debug("%10x %10x\n", fdt_regions[i].offset,
+ fdt_regions[i].size);
+   region[i].data = fit + fdt_regions[i].offset;
+   region[i].size = fdt_regions[i].size;
+   }
+
+   return region;
+}
+
+static int fit_image_setup_verify(struct image_sign_info *info,
+ const void *fit, int noffset,
+ int required_keynode, char **err_msgp)
+{
+   char *algo_name;
+   const char *padding_name;
+
+   if (fdt_totalsize(fit) > CONFIG_FIT_SIGNATURE_MAX_SIZE) {
+   *err_msgp = "Total size too large";
+   return 1;
+   }
+
+   if (fit_image_hash_get_algo(fit, noffset, _name)) {
+   *err_msgp = "Can't get hash algo property";
+   return -1;
+   }
+
+   padding_name = fdt_getprop(fit, noffset, "padding", NULL);
+   if (!padding_name)
+   padding_name = RSA_DEFAULT_PADDING_NAME;
+
+   memset(info, '\0', sizeof(*info));
+   info->keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
+   info->fit = (void *)fit;
+   info->node_offset = noffset;
+   info->name = algo_name;
+   info->checksum = image_get_checksum_algo(algo_name);
+   info->crypto = image_get_crypto_algo(algo_name);
+   info->padding = 

[U-Boot] [PATCH 05/16] efi_loader: add signature verification functions

2019-11-12 Thread AKASHI Takahiro
In this commit, implemented are a couple of helper functions which will be
used to materialize variable authentication as well as image authentication
in later patches.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_api.h  |  47 +++
 include/efi_loader.h   |  46 +++
 lib/efi_loader/Makefile|   1 +
 lib/efi_loader/efi_signature.c | 600 +
 4 files changed, 694 insertions(+)
 create mode 100644 lib/efi_loader/efi_signature.c

diff --git a/include/efi_api.h b/include/efi_api.h
index 22396172e15f..24d034246927 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -18,6 +18,7 @@
 
 #include 
 #include 
+#include 
 
 #ifdef CONFIG_EFI_LOADER
 #include 
@@ -307,6 +308,10 @@ struct efi_runtime_services {
EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, \
 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
 
+#define EFI_IMAGE_SECURITY_DATABASE_GUID \
+   EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, \
+0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)
+
 #define EFI_FDT_GUID \
EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, \
 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
@@ -1616,4 +1621,46 @@ struct efi_unicode_collation_protocol {
 #define LOAD_OPTION_CATEGORY_BOOT  0x
 #define LOAD_OPTION_CATEGORY_APP   0x0100
 
+/* Secure boot */
+#define EFI_CERT_SHA256_GUID \
+   EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, \
+0x41, 0xf9, 0x36, 0x93, 0x43, 0x28)
+#define EFI_CERT_RSA2048_GUID \
+   EFI_GUID(0x3c5766e8, 0x269c, 0x4e34, 0xaa, 0x14, \
+0xed, 0x77, 0x6e, 0x85, 0xb3, 0xb6)
+#define EFI_CERT_X509_GUID \
+   EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, \
+0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72)
+#define EFI_CERT_X509_SHA256_GUID \
+   EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, \
+0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed)
+#define EFI_CERT_TYPE_PKCS7_GUID \
+   EFI_GUID(0x4aafd29d, 0x68df, 0x49ee, 0x8a, 0xa9, \
+0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7)
+
+struct win_certificate_uefi_guid {
+   WIN_CERTIFICATE hdr;
+   efi_guid_t  cert_type;
+   u8  cert_data[];
+} __attribute__((__packed__));
+
+struct efi_variable_authentication_2 {
+   struct efi_time  time_stamp;
+   struct win_certificate_uefi_guid auth_info;
+} __attribute__((__packed__));
+
+struct efi_signature_data {
+   efi_guid_t  signature_owner;
+   u8  signature_data[];
+} __attribute__((__packed__));
+
+struct efi_signature_list {
+   efi_guid_t  signature_type;
+   u32 signature_list_size;
+   u32 signature_header_size;
+   u32 signature_size;
+/* u8  signature_header[signature_header_size]; */
+/* struct efi_signature_data signatures[...][signature_size]; */
+} __attribute__((__packed__));
+
 #endif
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 381da80cdce0..5a3df557e9f2 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -21,6 +21,7 @@ static inline int guidcmp(const void *g1, const void *g2)
 #if CONFIG_IS_ENABLED(EFI_LOADER)
 
 #include 
+#include 
 
 /* Maximum number of configuration tables */
 #define EFI_MAX_CONFIGURATION_TABLES 16
@@ -169,6 +170,11 @@ extern const efi_guid_t 
efi_guid_hii_config_routing_protocol;
 extern const efi_guid_t efi_guid_hii_config_access_protocol;
 extern const efi_guid_t efi_guid_hii_database_protocol;
 extern const efi_guid_t efi_guid_hii_string_protocol;
+/* GUID for authentication */
+extern const efi_guid_t efi_guid_image_security_database;
+extern const efi_guid_t efi_guid_sha256;
+extern const efi_guid_t efi_guid_cert_x509;
+extern const efi_guid_t efi_guid_cert_x509_sha256;
 
 extern unsigned int __efi_runtime_start, __efi_runtime_stop;
 extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
@@ -650,6 +656,46 @@ void efi_deserialize_load_option(struct efi_load_option 
*lo, u8 *data);
 unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data);
 efi_status_t efi_bootmgr_load(efi_handle_t *handle);
 
+#ifdef CONFIG_EFI_SECURE_BOOT
+#include 
+
+#define EFI_REGS_MAX 16 /* currently good enough */
+
+struct efi_image_regions {
+   int num;
+   struct image_region reg[EFI_REGS_MAX];
+};
+
+struct efi_sig_data {
+   struct efi_sig_data *next;
+   efi_guid_t owner;
+   void *data;
+   size_t size;
+};
+
+struct efi_signature_store {
+   struct efi_signature_store *next;
+   efi_guid_t sig_type;
+   struct efi_sig_data *sig_data_list;
+};
+
+struct x509_certificate;
+struct pkcs7_message;
+
+bool efi_signature_verify_cert(struct x509_certificate *cert,
+  struct efi_signature_store *dbx);
+bool efi_signature_verify_signers(struct pkcs7_message *msg,
+ struct 

[U-Boot] [PATCH 15/16] efi_loader, pytest: add UEFI secure boot tests (authenticated variables)

2019-11-12 Thread AKASHI Takahiro
Provide a couple of test cases for variable authentication.

Signed-off-by: AKASHI Takahiro 
---
 .../py/tests/test_efi_secboot/test_authvar.py | 289 ++
 1 file changed, 289 insertions(+)
 create mode 100644 test/py/tests/test_efi_secboot/test_authvar.py

diff --git a/test/py/tests/test_efi_secboot/test_authvar.py 
b/test/py/tests/test_efi_secboot/test_authvar.py
new file mode 100644
index ..ed18b80084d6
--- /dev/null
+++ b/test/py/tests/test_efi_secboot/test_authvar.py
@@ -0,0 +1,289 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2019, Linaro Limited
+# Author: AKASHI Takahiro 
+#
+# U-Boot UEFI: Variable Authentication Test
+
+"""
+This test verifies variable authentication
+"""
+
+import pytest
+import re
+from defs import *
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('efi_secure_boot')
+@pytest.mark.buildconfigspec('cmd_fat')
+@pytest.mark.buildconfigspec('cmd_nvedit_efi')
+@pytest.mark.slow
+class TestEfiAuthVar(object):
+def test_efi_var_auth1(self, u_boot_console, efi_boot_env):
+"""
+Test Case 1 - Install signature database
+"""
+disk_img = efi_boot_env
+with u_boot_console.log.section('Test Case 1a'):
+# Test Case 1a, Initial secure state
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'printenv -e SecureBoot'])
+assert(re.search(': 00', ''.join(output)))
+
+output = u_boot_console.run_command(
+'printenv -e SecureBoot')
+assert(': 00' in output)
+output = u_boot_console.run_command(
+'printenv -e SetupMode')
+assert(': 01' in output)
+
+with u_boot_console.log.section('Test Case 1b'):
+# Test Case 1b, PK without AUTHENTICATED_WRITE_ACCESS
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'fatload host 0:1 400 PK.auth',
+'setenv -e -nv -bs -rt -i 400,$filesize PK'])
+assert(re.search('Failed to set EFI variable', ''.join(output)))
+
+with u_boot_console.log.section('Test Case 1c'):
+# Test Case 1c, install PK
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 PK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize PK',
+'printenv -e PK'])
+assert(re.search('PK:', ''.join(output)))
+
+output = u_boot_console.run_command(
+'printenv -e SecureBoot')
+assert(': 01' in output)
+output = u_boot_console.run_command(
+'printenv -e SetupMode')
+assert(': 00' in output)
+
+with u_boot_console.log.section('Test Case 1d'):
+# Test Case 1d, db/dbx without KEK
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 db.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize db'])
+assert(re.search('Failed to set EFI variable', ''.join(output)))
+
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 db.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize dbx'])
+assert(re.search('Failed to set EFI variable', ''.join(output)))
+
+with u_boot_console.log.section('Test Case 1e'):
+# Test Case 1e, install KEK
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 KEK.auth',
+'setenv -e -nv -bs -rt -i 400,$filesize KEK'])
+assert(re.search('Failed to set EFI variable', ''.join(output)))
+
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 KEK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize KEK',
+'printenv -e KEK'])
+assert(re.search('KEK:', ''.join(output)))
+
+output = u_boot_console.run_command(
+'printenv -e SecureBoot')
+assert(': 01' in output)
+
+with u_boot_console.log.section('Test Case 1f'):
+# Test Case 1f, install db
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 db.auth',
+'setenv -e -nv -bs -rt -i 400,$filesize db'])
+assert(re.search('Failed to set EFI variable', ''.join(output)))
+
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 db.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize db',
+'printenv -e -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db'])
+assert(not re.search('Failed to set EFI variable', 
''.join(output)))
+assert(re.search('db:', 

[U-Boot] [PATCH 02/16] include: image.h: export hash algorithm helper functions

2019-11-12 Thread AKASHI Takahiro
This commit allows us to use common/image-sig.c even if CONFIG_FIT
is disabled but CONFIG_EFI_LOADER is enabled.

Signed-off-by: AKASHI Takahiro 
---
 include/image.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/image.h b/include/image.h
index bff87f51f01b..b79424a39c22 100644
--- a/include/image.h
+++ b/include/image.h
@@ -53,7 +53,7 @@ struct fdt_region;
 
 #endif /* USE_HOSTCC */
 
-#if IMAGE_ENABLE_FIT
+#if IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT)
 #include 
 #include 
 #include 
@@ -86,13 +86,14 @@ struct fdt_region;
 #endif
 
 #if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT) || \
-   defined(CONFIG_SPL_SHA256_SUPPORT)
+   defined(CONFIG_SPL_SHA256_SUPPORT) || \
+   defined(CONFIG_EFI_SECURE_BOOT)
 #define IMAGE_ENABLE_SHA2561
 #else
 #define IMAGE_ENABLE_SHA2560
 #endif
 
-#endif /* IMAGE_ENABLE_FIT */
+#endif /* IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT) */
 
 #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
 # define IMAGE_BOOT_GET_CMDLINE1
@@ -1261,7 +1262,6 @@ struct crypto_algo *image_get_crypto_algo(const char 
*full_name);
 struct padding_algo *image_get_padding_algo(const char *name);
 
 #if IMAGE_ENABLE_FIT
-
 /**
  * fit_image_verify_required_sigs() - Verify signatures marked as 'required'
  *
@@ -1337,7 +1337,7 @@ static inline int fit_image_check_target_arch(const void 
*fdt, int node)
 #define fit_unsupported(msg)
 #define fit_unsupported_reset(msg)
 #endif /* CONFIG_FIT_VERBOSE */
-#endif /* CONFIG_FIT */
+#endif /* IMAGE_ENABLE_FIT */
 
 #if defined(CONFIG_ANDROID_BOOT_IMAGE)
 struct andr_img_hdr;
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 4/6] lib: rsa: generate additional parameters for public key

2019-11-12 Thread AKASHI Takahiro
In the current implementation of FIT_SIGNATURE, five parameters for
a RSA public key are required while only two of them are essential.
(See rsa-mod-exp.h and uImage.FIT/signature.txt)
This is a result of considering relatively limited computer power
and resources on embedded systems, while such a assumption may not
be quite practical for other use cases.

In this patch, added is a function, rsa_gen_key_prop(), which will
generate additional parameters for other uses, in particular
UEFI secure boot, on the fly.

Note: the current code uses some "big number" routines from BearSSL
for the calculation.

Signed-off-by: AKASHI Takahiro 
---
 include/u-boot/rsa-mod-exp.h |  21 +
 lib/rsa/Kconfig  |   1 +
 lib/rsa/Makefile |   1 +
 lib/rsa/rsa-keyprop.c| 717 +++
 4 files changed, 740 insertions(+)
 create mode 100644 lib/rsa/rsa-keyprop.c

diff --git a/include/u-boot/rsa-mod-exp.h b/include/u-boot/rsa-mod-exp.h
index 8a428c4b6a1a..374169b8304e 100644
--- a/include/u-boot/rsa-mod-exp.h
+++ b/include/u-boot/rsa-mod-exp.h
@@ -26,6 +26,27 @@ struct key_prop {
uint32_t exp_len;   /* Exponent length in number of uint8_t */
 };
 
+/**
+ * rsa_gen_key_prop() - Generate key properties of RSA public key
+ * @key:   Specifies key data in DER format
+ * @keylen:Length of @key
+ *
+ * This function takes a blob of encoded RSA public key data in DER
+ * format, parse it and generate all the relevant properties
+ * in key_prop structure.
+ *
+ * Return: Pointer to struct key_prop on success, NULL on error
+ */
+struct key_prop *rsa_gen_key_prop(const void *key, uint32_t keylen);
+
+/**
+ * rsa_free_key_prop() - Free key properties
+ * @prop:  Pointer to struct key_prop
+ *
+ * This function frees all the memories allocated by rsa_gen_key_prop().
+ */
+void rsa_free_key_prop(struct key_prop *prop);
+
 /**
  * rsa_mod_exp_sw() - Perform RSA Modular Exponentiation in sw
  *
diff --git a/lib/rsa/Kconfig b/lib/rsa/Kconfig
index 71e4c06bf883..d1d6f6cf64a3 100644
--- a/lib/rsa/Kconfig
+++ b/lib/rsa/Kconfig
@@ -33,6 +33,7 @@ config RSA_VERIFY
 config RSA_VERIFY_WITH_PKEY
bool "Execute RSA verification without key parameters from FDT"
depends on RSA
+   imply RSA_PUBLIC_KEY_PARSER
help
  The standard RSA-signature verification code (FIT_SIGNATURE) uses
  pre-calculated key properties, that are stored in fdt blob, in
diff --git a/lib/rsa/Makefile b/lib/rsa/Makefile
index c07305188e0c..14ed3cb4012b 100644
--- a/lib/rsa/Makefile
+++ b/lib/rsa/Makefile
@@ -6,4 +6,5 @@
 # Wolfgang Denk, DENX Software Engineering, w...@denx.de.
 
 obj-$(CONFIG_$(SPL_)RSA_VERIFY) += rsa-verify.o rsa-checksum.o
+obj-$(CONFIG_RSA_VERIFY_WITH_PKEY) += rsa-keyprop.o
 obj-$(CONFIG_RSA_SOFTWARE_EXP) += rsa-mod-exp.o
diff --git a/lib/rsa/rsa-keyprop.c b/lib/rsa/rsa-keyprop.c
new file mode 100644
index ..9458337cc608
--- /dev/null
+++ b/lib/rsa/rsa-keyprop.c
@@ -0,0 +1,717 @@
+// SPDX-License-Identifier: GPL-2.0+ and MIT
+/*
+ * RSA library - generate parameters for a public key
+ *
+ * Copyright (c) 2019 Linaro Limited
+ * Author: AKASHI Takahiro
+ *
+ * Big number routines in this file come from BearSSL:
+ * Copyright (c) 2016 Thomas Pornin 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * br_dec16be() - Convert 16-bit big-endian integer to native
+ * @src:   Pointer to data
+ * Return: Native-endian integer
+ */
+static unsigned br_dec16be(const void *src)
+{
+   return be16_to_cpup(src);
+}
+
+/**
+ * br_dec32be() - Convert 32-bit big-endian integer to native
+ * @src:   Pointer to data
+ * Return: Native-endian integer
+ */
+static uint32_t br_dec32be(const void *src)
+{
+   return be32_to_cpup(src);
+}
+
+/**
+ * br_enc32be() - Convert native 32-bit integer to big-endian
+ * @dst:   Pointer to buffer to store big-endian integer in
+ * @x: Native 32-bit integer
+ */
+static void br_enc32be(void *dst, uint32_t x)
+{
+   __be32 tmp;
+
+   tmp = cpu_to_be32(x);
+   memcpy(dst, , sizeof(tmp));
+}
+
+/* from BearSSL's src/inner.h */
+
+/*
+ * Negate a boolean.
+ */
+static uint32_t NOT(uint32_t ctl)
+{
+   return ctl ^ 1;
+}
+
+/*
+ * Multiplexer: returns x if ctl == 1, y if ctl == 0.
+ */
+static uint32_t MUX(uint32_t ctl, uint32_t x, uint32_t y)
+{
+   return y ^ (-ctl & (x ^ y));
+}
+
+/*
+ * Equality check: returns 1 if x == y, 0 otherwise.
+ */
+static uint32_t EQ(uint32_t x, uint32_t y)
+{
+   uint32_t q;
+
+   q = x ^ y;
+   return NOT((q | -q) >> 31);
+}
+
+/*
+ * Inequality check: returns 1 if x != y, 0 otherwise.
+ */
+static uint32_t NEQ(uint32_t x, uint32_t y)
+{
+   uint32_t q;
+
+   q = x ^ y;
+   return (q | -q) >> 31;
+}
+
+/*
+ * Comparison: returns 1 if x > y, 0 otherwise.
+ */
+static uint32_t GT(uint32_t x, uint32_t y)
+{
+   /*
+* If both x < 2^31 and y < 2^31, then y-x will 

[U-Boot] [PATCH v3 15/16] lib: crypto: add pkcs7 message parser

2019-11-12 Thread AKASHI Takahiro
Imported from linux kernel v5.3:
 pkcs7.asn1 without changes
 pkcs7.h with changes marked as __UBOOT__
 pkcs7_parser.h without changes
 pkcs7_parser.c with changes marked as __UBOOT__

Signed-off-by: AKASHI Takahiro 
---
 include/crypto/pkcs7.h|  47 +++
 lib/crypto/Kconfig|  10 +
 lib/crypto/Makefile   |  11 +
 lib/crypto/pkcs7.asn1 | 135 
 lib/crypto/pkcs7_parser.c | 693 ++
 lib/crypto/pkcs7_parser.h |  65 
 scripts/Makefile.build|   4 +-
 7 files changed, 962 insertions(+), 3 deletions(-)
 create mode 100644 include/crypto/pkcs7.h
 create mode 100644 lib/crypto/pkcs7.asn1
 create mode 100644 lib/crypto/pkcs7_parser.c
 create mode 100644 lib/crypto/pkcs7_parser.h

diff --git a/include/crypto/pkcs7.h b/include/crypto/pkcs7.h
new file mode 100644
index ..8f5c8a7ee3b9
--- /dev/null
+++ b/include/crypto/pkcs7.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* PKCS#7 crypto data parser
+ *
+ * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ */
+
+#ifndef _CRYPTO_PKCS7_H
+#define _CRYPTO_PKCS7_H
+
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+
+struct key;
+struct pkcs7_message;
+
+/*
+ * pkcs7_parser.c
+ */
+extern struct pkcs7_message *pkcs7_parse_message(const void *data,
+size_t datalen);
+extern void pkcs7_free_message(struct pkcs7_message *pkcs7);
+
+extern int pkcs7_get_content_data(const struct pkcs7_message *pkcs7,
+ const void **_data, size_t *_datalen,
+ size_t *_headerlen);
+
+#ifndef __UBOOT__
+/*
+ * pkcs7_trust.c
+ */
+extern int pkcs7_validate_trust(struct pkcs7_message *pkcs7,
+   struct key *trust_keyring);
+
+/*
+ * pkcs7_verify.c
+ */
+extern int pkcs7_verify(struct pkcs7_message *pkcs7,
+   enum key_being_used_for usage);
+
+extern int pkcs7_supply_detached_data(struct pkcs7_message *pkcs7,
+ const void *data, size_t datalen);
+#endif
+
+#endif /* _CRYPTO_PKCS7_H */
diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig
index aeb599c593ac..2b221b915aa6 100644
--- a/lib/crypto/Kconfig
+++ b/lib/crypto/Kconfig
@@ -39,4 +39,14 @@ config X509_CERTIFICATE_PARSER
  data and provides the ability to instantiate a crypto key from a
  public key packet found inside the certificate.
 
+config PKCS7_MESSAGE_PARSER
+   bool "PKCS#7 message parser"
+   depends on X509_CERTIFICATE_PARSER
+   select ASN1_DECODER
+   select ASN1_COMPILER
+   select OID_REGISTRY
+   help
+ This option provides support for parsing PKCS#7 format messages for
+ signature data and provides the ability to verify the signature.
+
 endif # ASYMMETRIC_KEY_TYPE
diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile
index d7e27be568a1..8267fee0a7b8 100644
--- a/lib/crypto/Makefile
+++ b/lib/crypto/Makefile
@@ -36,3 +36,14 @@ $(obj)/x509_cert_parser.o: \
 
 $(obj)/x509.asn1.o: $(obj)/x509.asn1.c $(obj)/x509.asn1.h
 $(obj)/x509_akid.asn1.o: $(obj)/x509_akid.asn1.c $(obj)/x509_akid.asn1.h
+
+#
+# PKCS#7 message handling
+#
+obj-$(CONFIG_PKCS7_MESSAGE_PARSER) += pkcs7_message.o
+pkcs7_message-y := \
+   pkcs7.asn1.o \
+   pkcs7_parser.o
+
+$(obj)/pkcs7_parser.o: $(obj)/pkcs7.asn1.h
+$(obj)/pkcs7.asn1.o: $(obj)/pkcs7.asn1.c $(obj)/pkcs7.asn1.h
diff --git a/lib/crypto/pkcs7.asn1 b/lib/crypto/pkcs7.asn1
new file mode 100644
index ..1eca740b816a
--- /dev/null
+++ b/lib/crypto/pkcs7.asn1
@@ -0,0 +1,135 @@
+PKCS7ContentInfo ::= SEQUENCE {
+   contentType ContentType ({ pkcs7_check_content_type }),
+   content [0] EXPLICIT SignedData OPTIONAL
+}
+
+ContentType ::= OBJECT IDENTIFIER ({ pkcs7_note_OID })
+
+SignedData ::= SEQUENCE {
+   version INTEGER ({ pkcs7_note_signeddata_version }),
+   digestAlgorithmsDigestAlgorithmIdentifiers,
+   contentInfo ContentInfo ({ pkcs7_note_content }),
+   certificatesCHOICE {
+   certSet [0] IMPLICIT 
ExtendedCertificatesAndCertificates,
+   certSequence[2] IMPLICIT Certificates
+   } OPTIONAL ({ pkcs7_note_certificate_list }),
+   crls CHOICE {
+   crlSet  [1] IMPLICIT CertificateRevocationLists,
+   crlSequence [3] IMPLICIT CRLSequence
+   } OPTIONAL,
+   signerInfos SignerInfos
+}
+
+ContentInfo ::= SEQUENCE {
+   contentType ContentType ({ pkcs7_note_OID }),
+   content [0] EXPLICIT Data OPTIONAL
+}
+
+Data ::= ANY ({ pkcs7_note_data })
+
+DigestAlgorithmIdentifiers ::= CHOICE {
+   daSet   SET OF DigestAlgorithmIdentifier,
+   daSequence  SEQUENCE OF DigestAlgorithmIdentifier
+}
+
+DigestAlgorithmIdentifier ::= SEQUENCE {
+   algorithm 

[U-Boot] [PATCH v3 3/6] include: image.h: add key info to image_sign_info

2019-11-12 Thread AKASHI Takahiro
For FIT verification, all the properties of a public key come from
"control fdt" pointed to by fdt_blob. In UEFI secure boot, on the other
hand, a public key is located and retrieved from dedicated signature
database stored as UEFI variables.

Added two fields may hold values of a public key if fdt_blob is NULL, and
will be used in rsa_verify_with_pkey() to verify a signature in UEFI
sub-system.

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

diff --git a/include/image.h b/include/image.h
index 7eb0b4b53184..bff87f51f01b 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1142,6 +1142,16 @@ struct image_sign_info {
int required_keynode;   /* Node offset of key to use: -1=any */
const char *require_keys;   /* Value for 'required' property */
const char *engine_id;  /* Engine to use for signing */
+   /*
+* Note: the following two fields
+* are always valid even w/o
+* RSA_VERIFY_WITH_PKEY in order
+* to make sure this structure is
+* the same on target and host.
+* Otherwise, vboot test may fail.
+*/
+   const void *key;/* Pointer to public key in DER */
+   int keylen; /* Length of public key */
 };
 
 /* A part of an image, used for hashing */
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 2/6] rsa: add CONFIG_RSA_VERIFY_WITH_PKEY config

2019-11-12 Thread AKASHI Takahiro
In the next couple of commits, under new CONFIG_RSA_VERIFY_WITH_PKEY,
rsa_verify() will be extended to be able to perform RSA decryption without
additional RSA key properties from FIT image, i.e. rr and n0inv.

Signed-off-by: AKASHI Takahiro 
---
 lib/rsa/Kconfig | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/lib/rsa/Kconfig b/lib/rsa/Kconfig
index 03ffa2969048..71e4c06bf883 100644
--- a/lib/rsa/Kconfig
+++ b/lib/rsa/Kconfig
@@ -30,6 +30,20 @@ config RSA_VERIFY
help
  Add RSA signature verification support.
 
+config RSA_VERIFY_WITH_PKEY
+   bool "Execute RSA verification without key parameters from FDT"
+   depends on RSA
+   help
+ The standard RSA-signature verification code (FIT_SIGNATURE) uses
+ pre-calculated key properties, that are stored in fdt blob, in
+ decrypting a signature.
+ This does not suit the use case where there is no way defined to
+ provide such additional key properties in standardized form,
+ particularly UEFI secure boot.
+ This options enables RSA signature verification with a public key
+ directly specified in image_sign_info, where all the necessary
+ key properties will be calculated on the fly in verification code.
+
 config RSA_SOFTWARE_EXP
bool "Enable driver for RSA Modular Exponentiation in software"
depends on DM
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 14/16] lib: crypto: add x509 parser

2019-11-12 Thread AKASHI Takahiro
Imported from linux kernel v5.3:
 x509.asn1 without changes
 x509_akid.asn1 without changes
 x509_parser.h without changes
 x509_cert_parser.c with changes marked as __UBOOT__
 x509_public_key.c with changes marked as __UBOOT__

Signed-off-by: AKASHI Takahiro 
---
 lib/Kconfig   |   1 +
 lib/Makefile  |   1 +
 lib/crypto/Kconfig|  12 +
 lib/crypto/Makefile   |  17 +
 lib/crypto/x509.asn1  |  60 +++
 lib/crypto/x509_akid.asn1 |  35 ++
 lib/crypto/x509_cert_parser.c | 697 ++
 lib/crypto/x509_parser.h  |  57 +++
 lib/crypto/x509_public_key.c  | 292 ++
 9 files changed, 1172 insertions(+)
 create mode 100644 lib/crypto/x509.asn1
 create mode 100644 lib/crypto/x509_akid.asn1
 create mode 100644 lib/crypto/x509_cert_parser.c
 create mode 100644 lib/crypto/x509_parser.h
 create mode 100644 lib/crypto/x509_public_key.c

diff --git a/lib/Kconfig b/lib/Kconfig
index 0431cfbd21f8..051ffce23b42 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -265,6 +265,7 @@ config AES
  present.
 
 source lib/rsa/Kconfig
+source lib/crypto/Kconfig
 
 config TPM
bool "Trusted Platform Module (TPM) Support"
diff --git a/lib/Makefile b/lib/Makefile
index 9b8305e3190f..0fb1710f5aca 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_CMD_DHRYSTONE) += dhry/
 obj-$(CONFIG_ARCH_AT91) += at91/
 obj-$(CONFIG_OPTEE) += optee/
 obj-$(CONFIG_ASN1_DECODER) += asn1_decoder.o
+obj-y += crypto/
 
 obj-$(CONFIG_AES) += aes.o
 
diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig
index 9572ea8c87f3..aeb599c593ac 100644
--- a/lib/crypto/Kconfig
+++ b/lib/crypto/Kconfig
@@ -27,4 +27,16 @@ config RSA_PUBLIC_KEY_PARSER
  public key data and provides the ability to instantiate a public
  key.
 
+config X509_CERTIFICATE_PARSER
+   bool "X.509 certificate parser"
+   depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE
+   select ASN1_DECODER
+   select ASN1_COMPILER
+   select OID_REGISTRY
+   select LIB_DATE
+   help
+ This option provides support for parsing X.509 format blobs for key
+ data and provides the ability to instantiate a crypto key from a
+ public key packet found inside the certificate.
+
 endif # ASYMMETRIC_KEY_TYPE
diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile
index 69330a9ebd27..d7e27be568a1 100644
--- a/lib/crypto/Makefile
+++ b/lib/crypto/Makefile
@@ -19,3 +19,20 @@ rsa_public_key-y := \
 
 $(obj)/rsapubkey.asn1.o: $(obj)/rsapubkey.asn1.c $(obj)/rsapubkey.asn1.h
 $(obj)/rsa_helper.o: $(obj)/rsapubkey.asn1.h
+
+#
+# X.509 Certificate handling
+#
+obj-$(CONFIG_X509_CERTIFICATE_PARSER) += x509_key_parser.o
+x509_key_parser-y := \
+   x509.asn1.o \
+   x509_akid.asn1.o \
+   x509_cert_parser.o \
+   x509_public_key.o
+
+$(obj)/x509_cert_parser.o: \
+   $(obj)/x509.asn1.h \
+   $(obj)/x509_akid.asn1.h
+
+$(obj)/x509.asn1.o: $(obj)/x509.asn1.c $(obj)/x509.asn1.h
+$(obj)/x509_akid.asn1.o: $(obj)/x509_akid.asn1.c $(obj)/x509_akid.asn1.h
diff --git a/lib/crypto/x509.asn1 b/lib/crypto/x509.asn1
new file mode 100644
index ..5c9f4e4a5231
--- /dev/null
+++ b/lib/crypto/x509.asn1
@@ -0,0 +1,60 @@
+Certificate ::= SEQUENCE {
+   tbsCertificate  TBSCertificate ({ x509_note_tbs_certificate }),
+   signatureAlgorithm  AlgorithmIdentifier,
+   signature   BIT STRING ({ x509_note_signature })
+   }
+
+TBSCertificate ::= SEQUENCE {
+   version   [ 0 ] Version DEFAULT,
+   serialNumberCertificateSerialNumber ({ x509_note_serial }),
+   signature   AlgorithmIdentifier ({ x509_note_pkey_algo }),
+   issuer  Name ({ x509_note_issuer }),
+   validityValidity,
+   subject Name ({ x509_note_subject }),
+   subjectPublicKeyInfoSubjectPublicKeyInfo,
+   issuerUniqueID[ 1 ] IMPLICIT UniqueIdentifier OPTIONAL,
+   subjectUniqueID   [ 2 ] IMPLICIT UniqueIdentifier OPTIONAL,
+   extensions[ 3 ] Extensions OPTIONAL
+   }
+
+Version ::= INTEGER
+CertificateSerialNumber ::= INTEGER
+
+AlgorithmIdentifier ::= SEQUENCE {
+   algorithm   OBJECT IDENTIFIER ({ x509_note_OID }),
+   parameters  ANY OPTIONAL ({ x509_note_params })
+}
+
+Name ::= SEQUENCE OF RelativeDistinguishedName
+
+RelativeDistinguishedName ::= SET OF AttributeValueAssertion
+
+AttributeValueAssertion ::= SEQUENCE {
+   attributeType   OBJECT IDENTIFIER ({ x509_note_OID }),
+   attributeValue  ANY ({ x509_extract_name_segment })
+   }
+
+Validity ::= SEQUENCE {
+   notBefore   Time ({ x509_note_not_before }),
+   notAfterTime ({ x509_note_not_after })
+   }
+
+Time ::= CHOICE {
+   utcTime UTCTime,
+   generalTime GeneralizedTime
+   }
+

[U-Boot] [PATCH v3 16/16] test: add asn1 unit test

2019-11-12 Thread AKASHI Takahiro
This test will exercise asn1 compiler as well as asn1 decoder functions
via various parsers.

Signed-off-by: AKASHI Takahiro 
---
 test/Kconfig  |  18 ++-
 test/lib/Makefile |   1 +
 test/lib/asn1.c   | 392 ++
 3 files changed, 410 insertions(+), 1 deletion(-)
 create mode 100644 test/lib/asn1.c

diff --git a/test/Kconfig b/test/Kconfig
index 48a0e501f88f..cb7954041eda 100644
--- a/test/Kconfig
+++ b/test/Kconfig
@@ -12,7 +12,23 @@ config UT_LIB
default y
help
  Enables the 'ut lib' command which tests library functions like
- memcat(), memcyp(), memmove().
+ memcat(), memcyp(), memmove() and ASN1 compiler/decoder.
+
+if UT_LIB
+
+config UT_LIB_ASN1
+   bool "Unit test for asn1 compiler and decoder function"
+   default y
+   imply ASYMMETRIC_KEY_TYPE
+   imply ASYMMETRIC_PUBLIC_KEY_SUBTYPE
+   imply X509_CERTIFICATE_PARSER
+   imply PKCS7_MESSAGE_PARSER
+   imply RSA_PUBLIC_KEY_PARSER
+   help
+ Enables a test which exercises asn1 compiler and decoder function
+ via various parsers.
+
+endif
 
 config UT_TIME
bool "Unit tests for time functions"
diff --git a/test/lib/Makefile b/test/lib/Makefile
index b13aaca7ce54..72d2ec74b5f4 100644
--- a/test/lib/Makefile
+++ b/test/lib/Makefile
@@ -7,3 +7,4 @@ obj-y += hexdump.o
 obj-y += lmb.o
 obj-y += string.o
 obj-$(CONFIG_ERRNO_STR) += test_errno_str.o
+obj-$(CONFIG_UT_LIB_ASN1) += asn1.o
diff --git a/test/lib/asn1.c b/test/lib/asn1.c
new file mode 100644
index ..d2b3f67e68da
--- /dev/null
+++ b/test/lib/asn1.c
@@ -0,0 +1,392 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019 Linaro Limited
+ * Author: AKASHI Takahiro
+ *
+ * Unit test for asn1 compiler and asn1 decoder function via various parsers
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef CONFIG_PKCS7_MESSAGE_PARSER
+#include "../../lib/crypto/pkcs7_parser.h"
+#else
+#ifdef CONFIG_X509_CERTIFICATE_PARSER
+#include "../../lib/crypto/x509_parser.h"
+#endif
+#endif
+
+#ifdef CONFIG_X509_CERTIFICATE_PARSER
+static const unsigned char cert_data[] = {
+   0x30, 0x82, 0x03, 0xc7, 0x30, 0x82, 0x02, 0xaf, 0xa0, 0x03, 0x02, 0x01,
+   0x02, 0x02, 0x09, 0x00, 0xd7, 0x17, 0x0a, 0x76, 0xd5, 0xd3, 0x4d, 0xeb,
+   0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
+   0x0b, 0x05, 0x00, 0x30, 0x7a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
+   0x04, 0x06, 0x13, 0x02, 0x4a, 0x50, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03,
+   0x55, 0x04, 0x08, 0x0c, 0x05, 0x54, 0x6f, 0x6b, 0x79, 0x6f, 0x31, 0x0e,
+   0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x05, 0x54, 0x6f, 0x6b,
+   0x79, 0x6f, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
+   0x06, 0x4c, 0x69, 0x6e, 0x61, 0x72, 0x6f, 0x31, 0x0b, 0x30, 0x09, 0x06,
+   0x03, 0x55, 0x04, 0x0b, 0x0c, 0x02, 0x53, 0x57, 0x31, 0x0f, 0x30, 0x0d,
+   0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x06, 0x54, 0x65, 0x73, 0x74, 0x65,
+   0x72, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
+   0x0d, 0x01, 0x09, 0x01, 0x16, 0x0d, 0x74, 0x65, 0x73, 0x74, 0x40, 0x74,
+   0x65, 0x73, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x30, 0x1e, 0x17, 0x0d, 0x31,
+   0x39, 0x31, 0x30, 0x31, 0x38, 0x30, 0x33, 0x31, 0x33, 0x33, 0x31, 0x5a,
+   0x17, 0x0d, 0x32, 0x30, 0x31, 0x30, 0x31, 0x37, 0x30, 0x33, 0x31, 0x33,
+   0x33, 0x31, 0x5a, 0x30, 0x7a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
+   0x04, 0x06, 0x13, 0x02, 0x4a, 0x50, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03,
+   0x55, 0x04, 0x08, 0x0c, 0x05, 0x54, 0x6f, 0x6b, 0x79, 0x6f, 0x31, 0x0e,
+   0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x05, 0x54, 0x6f, 0x6b,
+   0x79, 0x6f, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
+   0x06, 0x4c, 0x69, 0x6e, 0x61, 0x72, 0x6f, 0x31, 0x0b, 0x30, 0x09, 0x06,
+   0x03, 0x55, 0x04, 0x0b, 0x0c, 0x02, 0x53, 0x57, 0x31, 0x0f, 0x30, 0x0d,
+   0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x06, 0x54, 0x65, 0x73, 0x74, 0x65,
+   0x72, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
+   0x0d, 0x01, 0x09, 0x01, 0x16, 0x0d, 0x74, 0x65, 0x73, 0x74, 0x40, 0x74,
+   0x65, 0x73, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x30, 0x82, 0x01, 0x22, 0x30,
+   0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
+   0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
+   0x82, 0x01, 0x01, 0x00, 0x9f, 0x37, 0x4d, 0x95, 0x7e, 0x36, 0xb7, 0xaf,
+   0xf4, 0xd6, 0xce, 0x39, 0x04, 0xee, 0xbf, 0x36, 0xb2, 0xcc, 0xa3, 0x8b,
+   0x9e, 0xac, 0x62, 0x8a, 0xe9, 0xae, 0x18, 0xcf, 0xe8, 0x95, 0xfd, 0xcb,
+   0xad, 0x34, 0x8a, 0x5f, 0x55, 0xe6, 0x0c, 0x5e, 0xf8, 0x76, 0xc1, 0xa2,
+   0xc3, 0xd4, 0x73, 0x13, 0x8a, 0x71, 0x1b, 0xfd, 0x58, 0x27, 0xea, 0x4d,
+   0x41, 0xff, 0x63, 0xbb, 0xad, 0x97, 0x62, 0xba, 0xe4, 0xe5, 0x97, 0x45,
+   0xa3, 0x5b, 

[U-Boot] [PATCH v3 13/16] lib: crypto: add rsa public key parser

2019-11-12 Thread AKASHI Takahiro
Imported from linux kernel v5.3:
rsapubkey.asn1 without changes
rsa.h without changes
rsa_helper.c with changes marked as __UBOOT__

Signed-off-by: AKASHI Takahiro 
---
 include/crypto/internal/rsa.h |  57 ++
 lib/crypto/Kconfig|  11 ++
 lib/crypto/Makefile   |  11 ++
 lib/crypto/rsa_helper.c   | 198 ++
 lib/crypto/rsapubkey.asn1 |   4 +
 5 files changed, 281 insertions(+)
 create mode 100644 include/crypto/internal/rsa.h
 create mode 100644 lib/crypto/rsa_helper.c
 create mode 100644 lib/crypto/rsapubkey.asn1

diff --git a/include/crypto/internal/rsa.h b/include/crypto/internal/rsa.h
new file mode 100644
index ..e870133f4b77
--- /dev/null
+++ b/include/crypto/internal/rsa.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * RSA internal helpers
+ *
+ * Copyright (c) 2015, Intel Corporation
+ * Authors: Tadeusz Struk 
+ */
+#ifndef _RSA_HELPER_
+#define _RSA_HELPER_
+#include 
+
+/**
+ * rsa_key - RSA key structure
+ * @n   : RSA modulus raw byte stream
+ * @e   : RSA public exponent raw byte stream
+ * @d   : RSA private exponent raw byte stream
+ * @p   : RSA prime factor p of n raw byte stream
+ * @q   : RSA prime factor q of n raw byte stream
+ * @dp  : RSA exponent d mod (p - 1) raw byte stream
+ * @dq  : RSA exponent d mod (q - 1) raw byte stream
+ * @qinv: RSA CRT coefficient q^(-1) mod p raw byte stream
+ * @n_sz: length in bytes of RSA modulus n
+ * @e_sz: length in bytes of RSA public exponent
+ * @d_sz: length in bytes of RSA private exponent
+ * @p_sz: length in bytes of p field
+ * @q_sz: length in bytes of q field
+ * @dp_sz   : length in bytes of dp field
+ * @dq_sz   : length in bytes of dq field
+ * @qinv_sz : length in bytes of qinv field
+ */
+struct rsa_key {
+   const u8 *n;
+   const u8 *e;
+   const u8 *d;
+   const u8 *p;
+   const u8 *q;
+   const u8 *dp;
+   const u8 *dq;
+   const u8 *qinv;
+   size_t n_sz;
+   size_t e_sz;
+   size_t d_sz;
+   size_t p_sz;
+   size_t q_sz;
+   size_t dp_sz;
+   size_t dq_sz;
+   size_t qinv_sz;
+};
+
+int rsa_parse_pub_key(struct rsa_key *rsa_key, const void *key,
+ unsigned int key_len);
+
+int rsa_parse_priv_key(struct rsa_key *rsa_key, const void *key,
+  unsigned int key_len);
+
+extern struct crypto_template rsa_pkcs1pad_tmpl;
+#endif
diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig
index b8e8288d2f80..9572ea8c87f3 100644
--- a/lib/crypto/Kconfig
+++ b/lib/crypto/Kconfig
@@ -16,4 +16,15 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE
  appropriate hash algorithms (such as SHA-1) must be available.
  ENOPKG will be reported if the requisite algorithm is unavailable.
 
+config RSA_PUBLIC_KEY_PARSER
+   bool "RSA public key parser"
+   depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE
+   select ASN1_DECODER
+   select ASN1_COMPILER
+   select OID_REGISTRY
+   help
+ This option provides support for parsing a blob containing RSA
+ public key data and provides the ability to instantiate a public
+ key.
+
 endif # ASYMMETRIC_KEY_TYPE
diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile
index a284de9e0411..69330a9ebd27 100644
--- a/lib/crypto/Makefile
+++ b/lib/crypto/Makefile
@@ -8,3 +8,14 @@ obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o
 asymmetric_keys-y := asymmetric_type.o
 
 obj-$(CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o
+
+#
+# RSA public key parser
+#
+obj-$(CONFIG_RSA_PUBLIC_KEY_PARSER) += rsa_public_key.o
+rsa_public_key-y := \
+   rsapubkey.asn1.o \
+   rsa_helper.o
+
+$(obj)/rsapubkey.asn1.o: $(obj)/rsapubkey.asn1.c $(obj)/rsapubkey.asn1.h
+$(obj)/rsa_helper.o: $(obj)/rsapubkey.asn1.h
diff --git a/lib/crypto/rsa_helper.c b/lib/crypto/rsa_helper.c
new file mode 100644
index ..aca627a4a619
--- /dev/null
+++ b/lib/crypto/rsa_helper.c
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * RSA key extract helper
+ *
+ * Copyright (c) 2015, Intel Corporation
+ * Authors: Tadeusz Struk 
+ */
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+#include 
+#ifndef __UBOOT__
+#include 
+#endif
+#include 
+#include "rsapubkey.asn1.h"
+#ifndef __UBOOT__
+#include "rsaprivkey.asn1.h"
+#endif
+
+int rsa_get_n(void *context, size_t hdrlen, unsigned char tag,
+ const void *value, size_t vlen)
+{
+   struct rsa_key *key = context;
+#ifndef __UBOOT__
+   const u8 *ptr = value;
+   size_t n_sz = vlen;
+#endif
+
+   /* invalid key provided */
+   if (!value || !vlen)
+   return -EINVAL;
+
+#ifndef __UBOOT__
+   if (fips_enabled) {
+   while (n_sz && !*ptr) {
+   ptr++;
+   n_sz--;
+   }
+
+   /* In FIPS mode 

[U-Boot] [PATCH v3 11/16] lib: add oid registry utility

2019-11-12 Thread AKASHI Takahiro
Imported from linux kernel v5.3:
 build_OID_registry without changes
 oid_registry.h without changes
 oid_registry.c with changes marked as __UBOOT__

Signed-off-by: AKASHI Takahiro 
---
 include/linux/oid_registry.h | 117 
 lib/Kconfig  |   5 +
 lib/Makefile |  16 +++
 lib/oid_registry.c   | 179 ++
 scripts/build_OID_registry   | 203 +++
 5 files changed, 520 insertions(+)
 create mode 100644 include/linux/oid_registry.h
 create mode 100644 lib/oid_registry.c
 create mode 100755 scripts/build_OID_registry

diff --git a/include/linux/oid_registry.h b/include/linux/oid_registry.h
new file mode 100644
index ..657d6bf2c064
--- /dev/null
+++ b/include/linux/oid_registry.h
@@ -0,0 +1,117 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* ASN.1 Object identifier (OID) registry
+ *
+ * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ */
+
+#ifndef _LINUX_OID_REGISTRY_H
+#define _LINUX_OID_REGISTRY_H
+
+#include 
+
+/*
+ * OIDs are turned into these values if possible, or OID__NR if not held here.
+ *
+ * NOTE!  Do not mess with the format of each line as this is read by
+ *   build_OID_registry.pl to generate the data for look_up_OID().
+ */
+enum OID {
+   OID_id_dsa_with_sha1,   /* 1.2.840.10030.4.3 */
+   OID_id_dsa, /* 1.2.840.10040.4.1 */
+   OID_id_ecdsa_with_sha1, /* 1.2.840.10045.4.1 */
+   OID_id_ecPublicKey, /* 1.2.840.10045.2.1 */
+
+   /* PKCS#1 {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 
pkcs-1(1)} */
+   OID_rsaEncryption,  /* 1.2.840.113549.1.1.1 */
+   OID_md2WithRSAEncryption,   /* 1.2.840.113549.1.1.2 */
+   OID_md3WithRSAEncryption,   /* 1.2.840.113549.1.1.3 */
+   OID_md4WithRSAEncryption,   /* 1.2.840.113549.1.1.4 */
+   OID_sha1WithRSAEncryption,  /* 1.2.840.113549.1.1.5 */
+   OID_sha256WithRSAEncryption,/* 1.2.840.113549.1.1.11 */
+   OID_sha384WithRSAEncryption,/* 1.2.840.113549.1.1.12 */
+   OID_sha512WithRSAEncryption,/* 1.2.840.113549.1.1.13 */
+   OID_sha224WithRSAEncryption,/* 1.2.840.113549.1.1.14 */
+   /* PKCS#7 {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 
pkcs-7(7)} */
+   OID_data,   /* 1.2.840.113549.1.7.1 */
+   OID_signed_data,/* 1.2.840.113549.1.7.2 */
+   /* PKCS#9 {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 
pkcs-9(9)} */
+   OID_email_address,  /* 1.2.840.113549.1.9.1 */
+   OID_contentType,/* 1.2.840.113549.1.9.3 */
+   OID_messageDigest,  /* 1.2.840.113549.1.9.4 */
+   OID_signingTime,/* 1.2.840.113549.1.9.5 */
+   OID_smimeCapabilites,   /* 1.2.840.113549.1.9.15 */
+   OID_smimeAuthenticatedAttrs,/* 1.2.840.113549.1.9.16.2.11 */
+
+   /* {iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2)} */
+   OID_md2,/* 1.2.840.113549.2.2 */
+   OID_md4,/* 1.2.840.113549.2.4 */
+   OID_md5,/* 1.2.840.113549.2.5 */
+
+   /* Microsoft Authenticode & Software Publishing */
+   OID_msIndirectData, /* 1.3.6.1.4.1.311.2.1.4 */
+   OID_msStatementType,/* 1.3.6.1.4.1.311.2.1.11 */
+   OID_msSpOpusInfo,   /* 1.3.6.1.4.1.311.2.1.12 */
+   OID_msPeImageDataObjId, /* 1.3.6.1.4.1.311.2.1.15 */
+   OID_msIndividualSPKeyPurpose,   /* 1.3.6.1.4.1.311.2.1.21 */
+   OID_msOutlookExpress,   /* 1.3.6.1.4.1.311.16.4 */
+
+   OID_certAuthInfoAccess, /* 1.3.6.1.5.5.7.1.1 */
+   OID_sha1,   /* 1.3.14.3.2.26 */
+   OID_sha256, /* 2.16.840.1.101.3.4.2.1 */
+   OID_sha384, /* 2.16.840.1.101.3.4.2.2 */
+   OID_sha512, /* 2.16.840.1.101.3.4.2.3 */
+   OID_sha224, /* 2.16.840.1.101.3.4.2.4 */
+
+   /* Distinguished Name attribute IDs [RFC 2256] */
+   OID_commonName, /* 2.5.4.3 */
+   OID_surname,/* 2.5.4.4 */
+   OID_countryName,/* 2.5.4.6 */
+   OID_locality,   /* 2.5.4.7 */
+   OID_stateOrProvinceName,/* 2.5.4.8 */
+   OID_organizationName,   /* 2.5.4.10 */
+   OID_organizationUnitName,   /* 2.5.4.11 */
+   OID_title,  /* 2.5.4.12 */
+   OID_description,/* 2.5.4.13 */
+   OID_name,   /* 2.5.4.41 */
+   OID_givenName,  /* 2.5.4.42 */
+   OID_initials,   /* 2.5.4.43 */
+   OID_generationalQualifier,  /* 2.5.4.44 */
+
+   /* Certificate extension IDs */
+  

[U-Boot] [PATCH v3 12/16] lib: crypto: add public key utility

2019-11-12 Thread AKASHI Takahiro
Imported from linux kernel v5.3:
 asymmetric-type.h with changes marked as __UBOOT__
 asymmetric_type.c with changes marked as __UBOOT__
 public_key.h with changes marked as __UBOOT__
 public_key.c with changes marked as __UBOOT__

Signed-off-by: AKASHI Takahiro 
---
 include/crypto/public_key.h|  90 +
 include/keys/asymmetric-type.h |  88 +
 lib/crypto/Kconfig |  19 +
 lib/crypto/Makefile|  10 +
 lib/crypto/asymmetric_type.c   | 668 +
 lib/crypto/public_key.c| 376 +++
 6 files changed, 1251 insertions(+)
 create mode 100644 include/crypto/public_key.h
 create mode 100644 include/keys/asymmetric-type.h
 create mode 100644 lib/crypto/Kconfig
 create mode 100644 lib/crypto/Makefile
 create mode 100644 lib/crypto/asymmetric_type.c
 create mode 100644 lib/crypto/public_key.c

diff --git a/include/crypto/public_key.h b/include/crypto/public_key.h
new file mode 100644
index ..436a1ee1ee64
--- /dev/null
+++ b/include/crypto/public_key.h
@@ -0,0 +1,90 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Asymmetric public-key algorithm definitions
+ *
+ * See Documentation/crypto/asymmetric-keys.txt
+ *
+ * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ */
+
+#ifndef _LINUX_PUBLIC_KEY_H
+#define _LINUX_PUBLIC_KEY_H
+
+#ifdef __UBOOT__
+#include 
+#else
+#include 
+#endif
+#include 
+
+/*
+ * Cryptographic data for the public-key subtype of the asymmetric key type.
+ *
+ * Note that this may include private part of the key as well as the public
+ * part.
+ */
+struct public_key {
+   void *key;
+   u32 keylen;
+   enum OID algo;
+   void *params;
+   u32 paramlen;
+   bool key_is_private;
+   const char *id_type;
+   const char *pkey_algo;
+};
+
+extern void public_key_free(struct public_key *key);
+
+/*
+ * Public key cryptography signature data
+ */
+struct public_key_signature {
+   struct asymmetric_key_id *auth_ids[2];
+   u8 *s;  /* Signature */
+   u32 s_size; /* Number of bytes in signature */
+   u8 *digest;
+   u8 digest_size; /* Number of bytes in digest */
+   const char *pkey_algo;
+   const char *hash_algo;
+   const char *encoding;
+};
+
+extern void public_key_signature_free(struct public_key_signature *sig);
+
+#ifndef __UBOOT__
+extern struct asymmetric_key_subtype public_key_subtype;
+
+struct key;
+struct key_type;
+union key_payload;
+
+extern int restrict_link_by_signature(struct key *dest_keyring,
+ const struct key_type *type,
+ const union key_payload *payload,
+ struct key *trust_keyring);
+
+extern int restrict_link_by_key_or_keyring(struct key *dest_keyring,
+  const struct key_type *type,
+  const union key_payload *payload,
+  struct key *trusted);
+
+extern int restrict_link_by_key_or_keyring_chain(struct key *trust_keyring,
+const struct key_type *type,
+const union key_payload 
*payload,
+struct key *trusted);
+
+extern int query_asymmetric_key(const struct kernel_pkey_params *,
+   struct kernel_pkey_query *);
+
+extern int encrypt_blob(struct kernel_pkey_params *, const void *, void *);
+extern int decrypt_blob(struct kernel_pkey_params *, const void *, void *);
+extern int create_signature(struct kernel_pkey_params *, const void *, void *);
+extern int verify_signature(const struct key *,
+   const struct public_key_signature *);
+
+int public_key_verify_signature(const struct public_key *pkey,
+   const struct public_key_signature *sig);
+#endif /* !__UBOOT__ */
+
+#endif /* _LINUX_PUBLIC_KEY_H */
diff --git a/include/keys/asymmetric-type.h b/include/keys/asymmetric-type.h
new file mode 100644
index ..47d83917df2f
--- /dev/null
+++ b/include/keys/asymmetric-type.h
@@ -0,0 +1,88 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Asymmetric Public-key cryptography key type interface
+ *
+ * See Documentation/crypto/asymmetric-keys.txt
+ *
+ * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ */
+
+#ifndef _KEYS_ASYMMETRIC_TYPE_H
+#define _KEYS_ASYMMETRIC_TYPE_H
+
+#ifndef __UBOOT__
+#include 
+#include 
+
+extern struct key_type key_type_asymmetric;
+
+/*
+ * The key payload is four words.  The asymmetric-type key uses them as
+ * follows:
+ */
+enum asymmetric_payload_bits {
+   asym_crypto,/* The data representing the key */
+   asym_subtype,   /* Pointer to an 

[U-Boot] [PATCH v3 08/16] Makefile: add build script for asn1 parsers

2019-11-12 Thread AKASHI Takahiro
This rule will be used to build x509 and pkcs7 parsers.

Signed-off-by: AKASHI Takahiro 
---
 Makefile   | 1 +
 scripts/Makefile.build | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 3000d30be23c..3fb3ce51be82 100644
--- a/Makefile
+++ b/Makefile
@@ -1921,6 +1921,7 @@ clean: $(clean-dirs)
-o -name '*.ko.*' -o -name '*.su' -o -name '*.pyc' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
-o -name '*.lex.c' -o -name '*.tab.[ch]' \
+   -o -name '*.asn1.[ch]' \
-o -name '*.symtypes' -o -name 'modules.order' \
-o -name modules.builtin -o -name '.tmp_*.o.*' \
-o -name 'dsdt.aml' -o -name 'dsdt.asl.tmp' -o -name 'dsdt.c' \
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 26eb701f8dea..6d59ea91fac3 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -419,9 +419,11 @@ targets += $(multi-used-y) $(multi-used-m)
 intermediate_targets = $(foreach sfx, $(2), \
$(patsubst %$(strip $(1)),%$(sfx), \
$(filter %$(strip $(1)), $(targets
+# %.asn1.o <- %.asn1.[ch] <- %.asn1
 # %.lex.o <- %.lex.c <- %.l
 # %.tab.o <- %.tab.[ch] <- %.y
-targets += $(call intermediate_targets, .lex.o, .lex.c) \
+targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
+  $(call intermediate_targets, .lex.o, .lex.c) \
   $(call intermediate_targets, .tab.o, .tab.c .tab.h)
 
 # Descending
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 10/16] doc: add README for asn1 compiler and decoder

2019-11-12 Thread AKASHI Takahiro
This document gives a brief description about ASN1 compiler as well as
ASN1 decoder.

Signed-off-by: AKASHI Takahiro 
---
 doc/README.asn1 | 40 
 1 file changed, 40 insertions(+)
 create mode 100644 doc/README.asn1

diff --git a/doc/README.asn1 b/doc/README.asn1
new file mode 100644
index ..1359b93aef0b
--- /dev/null
+++ b/doc/README.asn1
@@ -0,0 +1,40 @@
+ASN1
+
+
+Abstract Syntax Notation One (or ASN1) is a standard by ITU-T and ISO/IEC
+and used as a description language for defining data structure in
+an independent manner.
+Any data described in ASN1 notation can be serialized (or encoded) and
+de-serialized (or decoded) with well-defined encoding rules.
+
+A combination of ASN1 compiler and ASN1 decoder library function will
+provide a function interface for parsing encoded binary into specific
+data structure:
+1) define data structure in a text file (*.asn1)
+2) define "action" routines for specific "tags" defined in (1)
+3) generate bytecode as a C file (*.asn1.[ch]) from *.asn1 file
+   with ASN1 compiler (tools/asn1_compiler)
+4) call a ASN1 decoder (asn1_ber_decoder()) with bytecode and data
+
+Usage of ASN1 compiler
+--
+  asn1_compiler [-v] [-d]   
+
+  :  ASN1 input file
+  :generated C file
+  :  generated include file
+
+Usage of ASN1 decoder
+-
+  int asn1_ber_decoder(const struct asn1_decoder *decoder, void *context,
+  const unsigned char *data, size_t datalen);
+
+  @decoder:bytecode binary
+  @context:context for decoder
+  @data:   data to be parsed
+  @datalen:size of data
+
+
+As of writing this, ASN1 compiler and decoder are used to implement
+X509 certificate parser, pcks7 message parser and RSA public key parser
+for UEFI secure boot.
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 09/16] lib: add asn1 decoder

2019-11-12 Thread AKASHI Takahiro
Imported from linux kernel v5.3:
 lib/asn1_decoder.c with changes marked as __UBOOT__

Signed-off-by: AKASHI Takahiro 
---
 lib/Kconfig|   5 +
 lib/Makefile   |   1 +
 lib/asn1_decoder.c | 527 +
 3 files changed, 533 insertions(+)
 create mode 100644 lib/asn1_decoder.c

diff --git a/lib/Kconfig b/lib/Kconfig
index a76ceb67c03e..66ac598ed759 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -569,6 +569,11 @@ endmenu
 config ASN1_COMPILER
bool
 
+config ASN1_DECODER
+   bool
+   help
+ Enable asn1 decoder library.
+
 source lib/efi/Kconfig
 source lib/efi_loader/Kconfig
 source lib/optee/Kconfig
diff --git a/lib/Makefile b/lib/Makefile
index 8d0b9d9513f0..6e019fd0581d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_OF_LIVE) += of_live.o
 obj-$(CONFIG_CMD_DHRYSTONE) += dhry/
 obj-$(CONFIG_ARCH_AT91) += at91/
 obj-$(CONFIG_OPTEE) += optee/
+obj-$(CONFIG_ASN1_DECODER) += asn1_decoder.o
 
 obj-$(CONFIG_AES) += aes.o
 
diff --git a/lib/asn1_decoder.c b/lib/asn1_decoder.c
new file mode 100644
index ..db222625dd0f
--- /dev/null
+++ b/lib/asn1_decoder.c
@@ -0,0 +1,527 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Decoder for ASN.1 BER/DER/CER encoded bytestream
+ *
+ * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ */
+
+#ifdef __UBOOT__
+#include 
+#else
+#include 
+#endif
+#include 
+#include 
+#ifndef __UBOOT__
+#include 
+#endif
+#include 
+#include 
+
+static const unsigned char asn1_op_lengths[ASN1_OP__NR] = {
+   /*  OPC TAG JMP ACT */
+   [ASN1_OP_MATCH] = 1 + 1,
+   [ASN1_OP_MATCH_OR_SKIP] = 1 + 1,
+   [ASN1_OP_MATCH_ACT] = 1 + 1 + 1,
+   [ASN1_OP_MATCH_ACT_OR_SKIP] = 1 + 1 + 1,
+   [ASN1_OP_MATCH_JUMP]= 1 + 1 + 1,
+   [ASN1_OP_MATCH_JUMP_OR_SKIP]= 1 + 1 + 1,
+   [ASN1_OP_MATCH_ANY] = 1,
+   [ASN1_OP_MATCH_ANY_OR_SKIP] = 1,
+   [ASN1_OP_MATCH_ANY_ACT] = 1 + 1,
+   [ASN1_OP_MATCH_ANY_ACT_OR_SKIP] = 1 + 1,
+   [ASN1_OP_COND_MATCH_OR_SKIP]= 1 + 1,
+   [ASN1_OP_COND_MATCH_ACT_OR_SKIP]= 1 + 1 + 1,
+   [ASN1_OP_COND_MATCH_JUMP_OR_SKIP]   = 1 + 1 + 1,
+   [ASN1_OP_COND_MATCH_ANY]= 1,
+   [ASN1_OP_COND_MATCH_ANY_OR_SKIP]= 1,
+   [ASN1_OP_COND_MATCH_ANY_ACT]= 1 + 1,
+   [ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP]= 1 + 1,
+   [ASN1_OP_COND_FAIL] = 1,
+   [ASN1_OP_COMPLETE]  = 1,
+   [ASN1_OP_ACT]   = 1 + 1,
+   [ASN1_OP_MAYBE_ACT] = 1 + 1,
+   [ASN1_OP_RETURN]= 1,
+   [ASN1_OP_END_SEQ]   = 1,
+   [ASN1_OP_END_SEQ_OF]= 1 + 1,
+   [ASN1_OP_END_SET]   = 1,
+   [ASN1_OP_END_SET_OF]= 1 + 1,
+   [ASN1_OP_END_SEQ_ACT]   = 1 + 1,
+   [ASN1_OP_END_SEQ_OF_ACT]= 1 + 1 + 1,
+   [ASN1_OP_END_SET_ACT]   = 1 + 1,
+   [ASN1_OP_END_SET_OF_ACT]= 1 + 1 + 1,
+};
+
+/*
+ * Find the length of an indefinite length object
+ * @data: The data buffer
+ * @datalen: The end of the innermost containing element in the buffer
+ * @_dp: The data parse cursor (updated before returning)
+ * @_len: Where to return the size of the element.
+ * @_errmsg: Where to return a pointer to an error message on error
+ */
+static int asn1_find_indefinite_length(const unsigned char *data, size_t 
datalen,
+  size_t *_dp, size_t *_len,
+  const char **_errmsg)
+{
+   unsigned char tag, tmp;
+   size_t dp = *_dp, len, n;
+   int indef_level = 1;
+
+next_tag:
+   if (unlikely(datalen - dp < 2)) {
+   if (datalen == dp)
+   goto missing_eoc;
+   goto data_overrun_error;
+   }
+
+   /* Extract a tag from the data */
+   tag = data[dp++];
+   if (tag == ASN1_EOC) {
+   /* It appears to be an EOC. */
+   if (data[dp++] != 0)
+   goto invalid_eoc;
+   if (--indef_level <= 0) {
+   *_len = dp - *_dp;
+   *_dp = dp;
+   return 0;
+   }
+   goto next_tag;
+   }
+
+   if (unlikely((tag & 0x1f) == ASN1_LONG_TAG)) {
+   do {
+   if (unlikely(datalen - dp < 2))
+   goto data_overrun_error;
+   tmp = data[dp++];
+  

[U-Boot] [PATCH v3 07/16] cmd: add asn1_compiler

2019-11-12 Thread AKASHI Takahiro
Imported from linux kernel v5.3:
 asn1.h without changes
 asn1_ber_bytecode.h without changes
 asn1_decoder.h without changes
 asn1_compiler.c without changes

This host command will be used to create a ASN1 parser, for example,
for pkcs7 messages or x509 certificates. More specifically, it will
generate *byte code* which will be interpreted by asn1 decoder library.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Heinrich Schuchardt 
---
 include/linux/asn1.h  |   65 ++
 include/linux/asn1_ber_bytecode.h |   89 ++
 include/linux/asn1_decoder.h  |   20 +
 lib/Kconfig   |3 +
 scripts/Makefile.build|4 +-
 tools/Makefile|3 +
 tools/asn1_compiler.c | 1611 +
 7 files changed, 1793 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/asn1.h
 create mode 100644 include/linux/asn1_ber_bytecode.h
 create mode 100644 include/linux/asn1_decoder.h
 create mode 100644 tools/asn1_compiler.c

diff --git a/include/linux/asn1.h b/include/linux/asn1.h
new file mode 100644
index ..a4d0bdd10711
--- /dev/null
+++ b/include/linux/asn1.h
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* ASN.1 BER/DER/CER encoding definitions
+ *
+ * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ */
+
+#ifndef _LINUX_ASN1_H
+#define _LINUX_ASN1_H
+
+/* Class */
+enum asn1_class {
+   ASN1_UNIV   = 0,/* Universal */
+   ASN1_APPL   = 1,/* Application */
+   ASN1_CONT   = 2,/* Context */
+   ASN1_PRIV   = 3 /* Private */
+};
+#define ASN1_CLASS_BITS0xc0
+
+
+enum asn1_method {
+   ASN1_PRIM   = 0,/* Primitive */
+   ASN1_CONS   = 1 /* Constructed */
+};
+#define ASN1_CONS_BIT  0x20
+
+/* Tag */
+enum asn1_tag {
+   ASN1_EOC= 0,/* End Of Contents or N/A */
+   ASN1_BOOL   = 1,/* Boolean */
+   ASN1_INT= 2,/* Integer */
+   ASN1_BTS= 3,/* Bit String */
+   ASN1_OTS= 4,/* Octet String */
+   ASN1_NULL   = 5,/* Null */
+   ASN1_OID= 6,/* Object Identifier  */
+   ASN1_ODE= 7,/* Object Description */
+   ASN1_EXT= 8,/* External */
+   ASN1_REAL   = 9,/* Real float */
+   ASN1_ENUM   = 10,   /* Enumerated */
+   ASN1_EPDV   = 11,   /* Embedded PDV */
+   ASN1_UTF8STR= 12,   /* UTF8 String */
+   ASN1_RELOID = 13,   /* Relative OID */
+   /* 14 - Reserved */
+   /* 15 - Reserved */
+   ASN1_SEQ= 16,   /* Sequence and Sequence of */
+   ASN1_SET= 17,   /* Set and Set of */
+   ASN1_NUMSTR = 18,   /* Numerical String */
+   ASN1_PRNSTR = 19,   /* Printable String */
+   ASN1_TEXSTR = 20,   /* T61 String / Teletext String */
+   ASN1_VIDSTR = 21,   /* Videotex String */
+   ASN1_IA5STR = 22,   /* IA5 String */
+   ASN1_UNITIM = 23,   /* Universal Time */
+   ASN1_GENTIM = 24,   /* General Time */
+   ASN1_GRASTR = 25,   /* Graphic String */
+   ASN1_VISSTR = 26,   /* Visible String */
+   ASN1_GENSTR = 27,   /* General String */
+   ASN1_UNISTR = 28,   /* Universal String */
+   ASN1_CHRSTR = 29,   /* Character String */
+   ASN1_BMPSTR = 30,   /* BMP String */
+   ASN1_LONG_TAG   = 31/* Long form tag */
+};
+
+#define ASN1_INDEFINITE_LENGTH 0x80
+
+#endif /* _LINUX_ASN1_H */
diff --git a/include/linux/asn1_ber_bytecode.h 
b/include/linux/asn1_ber_bytecode.h
new file mode 100644
index ..b38361953a48
--- /dev/null
+++ b/include/linux/asn1_ber_bytecode.h
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* ASN.1 BER/DER/CER parsing state machine internal definitions
+ *
+ * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ */
+
+#ifndef _LINUX_ASN1_BER_BYTECODE_H
+#define _LINUX_ASN1_BER_BYTECODE_H
+
+#ifdef __KERNEL__
+#include 
+#endif
+#include 
+
+typedef int (*asn1_action_t)(void *context,
+size_t hdrlen, /* In case of ANY type */
+unsigned char tag, /* In case of ANY type */
+const void *value, size_t vlen);
+
+struct asn1_decoder {
+   const unsigned char *machine;
+   size_t machlen;
+   const asn1_action_t *actions;
+};
+
+enum asn1_opcode {
+   /* The tag-matching ops come first and the odd-numbered slots
+* are for OR_SKIP ops.
+*/
+#define ASN1_OP_MATCH__SKIP  0x01
+#define ASN1_OP_MATCH__ACT   0x02
+#define ASN1_OP_MATCH__JUMP  0x04
+#define ASN1_OP_MATCH__ANY   0x08
+#define ASN1_OP_MATCH__COND  0x10
+
+   ASN1_OP_MATCH   = 0x00,
+   

[U-Boot] [PATCH v3 04/16] lib: add mktime64() for linux compatibility

2019-11-12 Thread AKASHI Takahiro
This function will be used  in lib/crypto/x509_cert_parser.c, which
will also be imported from linux code in a later commit.

Signed-off-by: AKASHI Takahiro 
---
 include/linux/time.h | 10 ++
 lib/date.c   | 20 
 2 files changed, 30 insertions(+)

diff --git a/include/linux/time.h b/include/linux/time.h
index b8d298eb4d68..dc9344a6d97b 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -1,6 +1,7 @@
 #ifndef _LINUX_TIME_H
 #define _LINUX_TIME_H
 
+#include 
 #include 
 
 #define _DEFUN(a,b,c) a(c)
@@ -150,4 +151,13 @@ _DEFUN (ctime_r, (tim_p, result),
 return asctime_r (localtime_r (tim_p, ), result);
 }
 
+/* for compatibility with linux code */
+typedef __s64 time64_t;
+
+#ifdef CONFIG_LIB_DATE
+time64_t mktime64(const unsigned int year, const unsigned int mon,
+ const unsigned int day, const unsigned int hour,
+ const unsigned int min, const unsigned int sec);
+#endif
+
 #endif
diff --git a/lib/date.c b/lib/date.c
index 63af4a142612..0456de78ab14 100644
--- a/lib/date.c
+++ b/lib/date.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #if defined(CONFIG_LIB_DATE) || defined(CONFIG_TIMESTAMP)
 
@@ -97,3 +98,22 @@ unsigned long rtc_mktime(const struct rtc_time *tm)
 }
 
 #endif /* CONFIG_LIB_DATE || CONFIG_TIMESTAMP */
+
+#ifdef CONFIG_LIB_DATE
+/* for compatibility with linux code */
+time64_t mktime64(const unsigned int year, const unsigned int mon,
+ const unsigned int day, const unsigned int hour,
+ const unsigned int min, const unsigned int sec)
+{
+   struct rtc_time time;
+
+   time.tm_year = year;
+   time.tm_mon = mon;
+   time.tm_mday = day;
+   time.tm_hour = hour;
+   time.tm_min = min;
+   time.tm_sec = sec;
+
+   return (time64_t)rtc_mktime((const struct rtc_time *));
+}
+#endif
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 06/16] linux/time.h: include vsprintf.h

2019-11-12 Thread AKASHI Takahiro
Without this commit, time.h possibly causes a build error as
asctime_r() uses sprintf().

Signed-off-by: AKASHI Takahiro 
---
 include/linux/time.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/time.h b/include/linux/time.h
index dc9344a6d97b..702dd276aea5 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -2,6 +2,7 @@
 #define _LINUX_TIME_H
 
 #include 
+#include 
 #include 
 
 #define _DEFUN(a,b,c) a(c)
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 05/16] include: kernel.h: include printk.h

2019-11-12 Thread AKASHI Takahiro
Adding "printk.h" will help improve portability from linux kernel
code (in my case, lib/asn1_decoder.c and others) where printf and
pr_* variant functions are used.

Signed-off-by: AKASHI Takahiro 
---
 include/linux/kernel.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 5c7e5f635b1a..564819a1c0a7 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -1,8 +1,8 @@
 #ifndef _LINUX_KERNEL_H
 #define _LINUX_KERNEL_H
 
-
 #include 
+#include  /* for printf/pr_* utilities */
 
 #define USHRT_MAX  ((u16)(~0U))
 #define SHRT_MAX   ((s16)(USHRT_MAX>>1))
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 02/16] rtc.h: add struct udevice declaration

2019-11-12 Thread AKASHI Takahiro
Without this change, including rtc.h solely will cause a build error.

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

diff --git a/include/rtc.h b/include/rtc.h
index 7386d52db1d7..8aabfc1162a4 100644
--- a/include/rtc.h
+++ b/include/rtc.h
@@ -18,6 +18,8 @@
 
 #ifdef CONFIG_DM_RTC
 
+struct udevice;
+
 struct rtc_ops {
/**
 * get() - get the current time
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 03/16] rtc: move date.c from drivers/rtc/ to lib/

2019-11-12 Thread AKASHI Takahiro
In the next commit, rtc_mktime(), for compatibility with linux, will be
implemented using rtc_mktime(), which is no longer drivers/rtc specific.
So move this file under lib/.

Signed-off-by: AKASHI Takahiro 
---
 cmd/Kconfig | 1 +
 drivers/rtc/Kconfig | 1 +
 drivers/rtc/Makefile| 1 -
 lib/Kconfig | 3 +++
 lib/Makefile| 2 ++
 {drivers/rtc => lib}/date.c | 5 ++---
 6 files changed, 9 insertions(+), 4 deletions(-)
 rename {drivers/rtc => lib}/date.c (96%)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index b08a7098579b..1b9045696267 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1620,6 +1620,7 @@ config CMD_LED
 config CMD_DATE
bool "date"
default y if DM_RTC
+   select LIB_DATE
help
  Enable the 'date' command for getting/setting the time/date in RTC
  devices.
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 8778cc7b264c..89e71cc7ebef 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -7,6 +7,7 @@ menu "Real Time Clock"
 config DM_RTC
bool "Enable Driver Model for RTC drivers"
depends on DM
+   select LIB_DATE
help
  Enable drver model for real-time-clock drivers. The RTC uclass
  then provides the rtc_get()/rtc_set() interface, delegating to
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index f97a6699820e..e8875ce10f5e 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -7,7 +7,6 @@
 obj-$(CONFIG_$(SPL_TPL_)DM_RTC) += rtc-uclass.o
 
 obj-$(CONFIG_RTC_AT91SAM9_RTT) += at91sam9_rtt.o
-obj-y += date.o
 obj-y += rtc-lib.o
 obj-$(CONFIG_RTC_DAVINCI) += davinci.o
 obj-$(CONFIG_RTC_DS1302) += ds1302.o
diff --git a/lib/Kconfig b/lib/Kconfig
index b8a8509d720f..642dc1ac872e 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -574,4 +574,7 @@ config TEST_FDTDEC
bool "enable fdtdec test"
depends on OF_LIBFDT
 
+config LIB_DATE
+   bool
+
 endmenu
diff --git a/lib/Makefile b/lib/Makefile
index d248d8626cea..8d0b9d9513f0 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -117,4 +117,6 @@ else
 obj-y += vsprintf.o strto.o strmhz.o
 endif
 
+obj-y += date.o
+
 subdir-ccflags-$(CONFIG_CC_OPTIMIZE_LIBS_FOR_SPEED) += -O2
diff --git a/drivers/rtc/date.c b/lib/date.c
similarity index 96%
rename from drivers/rtc/date.c
rename to lib/date.c
index c57317d2c267..63af4a142612 100644
--- a/drivers/rtc/date.c
+++ b/lib/date.c
@@ -9,8 +9,7 @@
 #include 
 #include 
 
-#if defined(CONFIG_CMD_DATE) || defined(CONFIG_DM_RTC) || \
-   defined(CONFIG_TIMESTAMP)
+#if defined(CONFIG_LIB_DATE) || defined(CONFIG_TIMESTAMP)
 
 #define FEBRUARY   2
 #defineSTARTOFTIME 1970
@@ -97,4 +96,4 @@ unsigned long rtc_mktime(const struct rtc_time *tm)
return (hours * 60 + tm->tm_min) * 60 + tm->tm_sec;
 }
 
-#endif
+#endif /* CONFIG_LIB_DATE || CONFIG_TIMESTAMP */
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 01/16] linux_compat: move kmemdup() from ubifs.c to linux_compat.c

2019-11-12 Thread AKASHI Takahiro
linux_compat.c is the best place for kmemdup(), which is currenly used
only in ubifs.c, but will also be used when other kernel files
(in my case, lib/crypto/x509_cert_parser.c and pkcs7_parser.c) will be
imported. So just move it.

Signed-off-by: AKASHI Takahiro 
---
 fs/ubifs/ubifs.c   | 19 +--
 lib/linux_compat.c | 19 +++
 2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 67a0e8caae70..1ffdfe0d9089 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -18,6 +18,7 @@
 #include "ubifs.h"
 #include 
 
+#include 
 #include 
 #include 
 
@@ -70,24 +71,6 @@ struct ubifs_compressor 
*ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
 
 
 #ifdef __UBOOT__
-/* from mm/util.c */
-
-/**
- * kmemdup - duplicate region of memory
- *
- * @src: memory region to duplicate
- * @len: memory region length
- * @gfp: GFP mask to use
- */
-void *kmemdup(const void *src, size_t len, gfp_t gfp)
-{
-   void *p;
-
-   p = kmalloc(len, gfp);
-   if (p)
-   memcpy(p, src, len);
-   return p;
-}
 
 struct crypto_comp {
int compressor;
diff --git a/lib/linux_compat.c b/lib/linux_compat.c
index 81ea8fb126fa..3f440deaa0d8 100644
--- a/lib/linux_compat.c
+++ b/lib/linux_compat.c
@@ -40,3 +40,22 @@ void *kmem_cache_alloc(struct kmem_cache *obj, int flag)
 {
return malloc_cache_aligned(obj->sz);
 }
+
+/**
+ * kmemdup - duplicate region of memory
+ *
+ * @src: memory region to duplicate
+ * @len: memory region length
+ * @gfp: GFP mask to use
+ *
+ * Return: newly allocated copy of @src or %NULL in case of error
+ */
+void *kmemdup(const void *src, size_t len, gfp_t gfp)
+{
+   void *p;
+
+   p = kmalloc(len, gfp);
+   if (p)
+   memcpy(p, src, len);
+   return p;
+}
-- 
2.21.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 00/16] import x509/pkcs7 parsers from linux

2019-11-12 Thread AKASHI Takahiro
# This patch set is a prerequisite for UEFI secure boot.
# This patch set should be merged first prior to my rsa extension patch
# due to some dependency.

Asn1 parsers of x509 certificates and pkcs7 messages are required
to implement image authentication and variable authentication as
part of UEFI secure boot feature.

As we discussed before in the thread[1], most people insisted that
we should re-use corresponding source code from Linux repository
for this purpose.

Here is my attempt to import all the necessary files from Linux; Those
will eventually be part of UEFI secure boot implementation, but I'd like
to get early feedback from other peoples before submitting the whole
patchset so that they will be better formatted for merging.

My approach here is
* files from the latest Linux
* modify files as little as possible
* mark/protect unavoidable changes with "#if(n)def __UBOOT__"
so that future fixes/differences in Linux repository will easily
be applied to U-Boot.

Known issues:
* checkpatch.pl
  Checkpatch.pl will complain with a bunch of warnings/errors but
  I intentionally left them unchanged for the sake of better
  maintainability I said above.

-Takahiro Akashi

[1] https://lists.denx.de/pipermail/u-boot/2019-April/366423.html

Changes in v3 (Nov 13, 2019)
* rebased to v2020.01-rc
* improve function description of kmemdup() (patch#1)
* remove test/lib/Kconfig (patch#16)
* declare variables in unit test as static (patch#16)

Changes in v2 (Oct 25, 2019)
* revise commit messages, describing what files are modified or not.
* move kmemdump() in ubifs.c to linux_compat.c for general use (patch#1)
* add patch#2
* move date.c to lib/ for general use (patch#3)
* implement mktime64() with rtc_mktime() (patch#4)
* move asn1_compiler.c to tools/ (patch#7)
* change CONFIG_BUILD_ASN1 to CONFIG_ASN1_COMPILER (patch#7)
* add clean rule to asn1_compiler-generated files to clean targets (patch#8)
* change CONFIG_ASN1 to CONFIG_ASN1_DECODER (patch#9)
* add README for asn1 compiler/decoder (patch#10)
* move build_oid_registry to scripts/ (patch#11)
* shuffle an order of patches (patch#13,#14,#15)
* add a new config CONFIG_RSA_PUBLIC_KEY_PARSER so that it can be
* modify Kconfig dependency (patch#13,#14,#15)
  compiled in independently (patch#13)
* add unit test (patch#16,#17)

Changes in v1 (Oct 11, 2019) from RFC
* change the kernel code base from v5.0 to v5.3
* add preparatory patches (#1, #2 and #3)
* comment off x509_check_for_self_signed() which is not useful
  for UEFI secure boot (patch#9)
* improve usages of "#if(n)def __UBOOT__* to minimize differences
  between U-Boot and linux kernel

AKASHI Takahiro (16):
  linux_compat: move kmemdup() from ubifs.c to linux_compat.c
  rtc.h: add struct udevice declaration
  rtc: move date.c from drivers/rtc/ to lib/
  lib: add mktime64() for linux compatibility
  include: kernel.h: include printk.h
  linux/time.h: include vsprintf.h
  cmd: add asn1_compiler
  Makefile: add build script for asn1 parsers
  lib: add asn1 decoder
  doc: add README for asn1 compiler and decoder
  lib: add oid registry utility
  lib: crypto: add public key utility
  lib: crypto: add rsa public key parser
  lib: crypto: add x509 parser
  lib: crypto: add pkcs7 message parser
  test: add asn1 unit test

 Makefile  |1 +
 cmd/Kconfig   |1 +
 doc/README.asn1   |   40 +
 drivers/rtc/Kconfig   |1 +
 drivers/rtc/Makefile  |1 -
 fs/ubifs/ubifs.c  |   19 +-
 include/crypto/internal/rsa.h |   57 +
 include/crypto/pkcs7.h|   47 +
 include/crypto/public_key.h   |   90 ++
 include/keys/asymmetric-type.h|   88 ++
 include/linux/asn1.h  |   65 ++
 include/linux/asn1_ber_bytecode.h |   89 ++
 include/linux/asn1_decoder.h  |   20 +
 include/linux/kernel.h|2 +-
 include/linux/oid_registry.h  |  117 +++
 include/linux/time.h  |   11 +
 include/rtc.h |2 +
 lib/Kconfig   |   17 +
 lib/Makefile  |   20 +
 lib/asn1_decoder.c|  527 ++
 lib/crypto/Kconfig|   52 +
 lib/crypto/Makefile   |   49 +
 lib/crypto/asymmetric_type.c  |  668 
 lib/crypto/pkcs7.asn1 |  135 +++
 lib/crypto/pkcs7_parser.c |  693 +
 lib/crypto/pkcs7_parser.h |   65 ++
 lib/crypto/public_key.c   |  376 +++
 lib/crypto/rsa_helper.c   |  198 
 lib/crypto/rsapubkey.asn1 |4 +
 lib/crypto/x509.asn1  |   60 ++
 lib/crypto/x509_akid.asn1 |   35 +
 lib/crypto/x509_cert_parser.c |  697 +
 lib/crypto/x509_parser.h  |   57 +
 lib/crypto/x509_public_key.c  |  292 ++
 {drivers/rtc => lib}/date.c   |   23 +-
 lib/linux_compat.c|   19 +
 lib/oid_registry.c|  179 
 

[U-Boot] [BUG] fs: fat: incorrect creation of files with Unicode file name

2019-11-12 Thread Heinrich Schuchardt

In the UEFI Shell I create a file with

FS0:\> echo привет_мир.текст > привет_мир.текст

FS0:\> ls
Directory of: FS0:\
00/00/  00:00  38  привет_мир.текст

The U-Boot console shows it correctly:

=> ls scsi 0:1
   38   привет_мир.текст

Now in Linux I mount the volume. ls shows an incorrect filename:

> ls /mnt
'пÑ'$'\302\200''ивеÑ'$'\302\202''_миÑ'$'\302\200''.Ñ'$'\302\202''екÑ'$'\302\201''Ñ'$'\302\202'

Now in Linux I create a file

# echo привет_мир.текст > /mnt/привет_мир.текст

U-Boot shows the file name incorrectly

=> ls scsi 0:1
   31   ?@825B_<8@.B5:AB

So U-Boot seems not to convert file names correctly to UTF-16 before saving.

Best regards

Heinrich
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [BUG] U-Boot hangs on fatload, commit ee88eacbdd840199a3dec707234579fb15ddd46a

2019-11-12 Thread Gray Remlin
On Tue, 12 Nov 2019 at 19:50, Heinrich Schuchardt 
wrote:

> On 11/11/19 6:14 PM, Gray Remlin wrote:
> >
> > This content is getting very convoluted, if appropriate feel free to
> > crop it.
> > New point raised at very bottom.
> >
> > On Sun, 10 Nov 2019 at 08:41, Heinrich Schuchardt  > > wrote:
> >
> > On 11/9/19 10:31 PM, Gray Remlin wrote:
> >  > On Sat, 9 Nov 2019 at 20:50, Heinrich Schuchardt
> > mailto:xypron.g...@gmx.de>
> >  > >> wrote:
> >  >
> >  > On 11/9/19 8:42 PM, Gray Remlin wrote:
> >  >  > On Sat, 9 Nov 2019 at 18:40, Heinrich Schuchardt
> >  > mailto:xypron.g...@gmx.de>
> > >
> >  >  > 
> >  >  >  >
> >  >  > On 11/9/19 6:08 PM, Heinrich Schuchardt wrote:
> >  >  >  > On 11/9/19 4:11 PM, Gray Remlin wrote:
> >  >  >  >> On Fri, 8 Nov 2019 at 20:08, Heinrich Schuchardt
> >  >  > mailto:xypron.g...@gmx.de>
> > >
> >  > 
> > >>
> >  >  >  >>  >   > >
> >  > 
> >  wrote:
> >  >  >  >>
> >  >  >  >> On 11/8/19 7:32 PM, Gray Remlin wrote:
> >  >  >  >>  > Please excuse the noise. I would like to
> file a
> >  > bug report
> >  >  >  >> against the
> >  >  >  >>  > above commit, a quick search of www.denx.de
> > 
> >  > 
> >  >  >  
> >  >  >  >>  did not
> >  >  >  >>  > reveal how I should proceed. Please point
> me in
> >  > the right
> >  >  >  >> direction.
> >  >  >  >>  >
> >  >  >  >>  >
> >  >  >  >>  > Issue:
> >  >  >  >>  > U-Boot hangs (i.e. during boot) whenever
> > the command
> >  >  > 'fatload' is
> >  >  >  >> used.
> >  >  >  >>  >
> >  >  >  >>  > Details:
> >  >  >  >>  > U-Boot 2019.10 compiled with either
> >  > dreamplug_defconfig or
> >  >  >  >>  > guruplug_defconfig.
> >  >  >  >>  >
> >  >  >  >>  > After the commit do_load() now additionally
> > calls
> >  >  >  >> efi_set_bootdev()
> >  >  >  >>  > which was moved out of do_load_wrapper()
> > which is
> >  > only called
> >  >  >  >> by the
> >  >  >  >>  > 'load' command.
> >  >  >  >>  >
> >  >  >  >>  > Reverting the commit fixes this issue for
> me.
> >  >  >  >>  >
> >  >  >  >>
> >  >  >  >> Dear Gray,
> >  >  >  >>
> >  >  >  >> thanks for reporting the issue with commit
> >  >  >  >> fs: do_load: pass device path for efi payload
> >  >  >  >> ee88eacbdd840199a3dec707234579fb15ddd46a
> >  >  >  >>
> >  >  >  >> Is it only the fatload command that fails on
> your
> >  > device or
> >  >  > also the
> >  >  >  >> load command?
> >  >  >  >>
> >  >  >  >> There is no bug tracker for U-Boot. So sending
> > a mail
> >  > to the
> >  >  > U-Boot
> >  >  >  >> mailing list, the patch author, and the
> > maintainer is the
> >  >  > best way to
> >  >  >  >> inform the developers about bugs.
> >  >  >  >>
> >  >  >  >> Best regards
> >  >  >  >>
> >  >  >  >> Heinrich
> >  >  >  >>
> >  >  >  >>
> >
> >
> > Distribution and version of GCC:
> >
> >  >  >  >> Additional information:
> >  >  >  >> cross-compiler
> >  > gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabi
> >  >  >  >>
> >  >  >  >> The U-Boot environment being used is the default
> > obtained by
> >  >  >  >> compiling U-Boot 2020.01-rc1-00100-gee93ef0c4b as
> >  >  > dreamplug_defconfig
> >  >  >  >>
> >  >  >  >> => printenv
> >  >  >  >> baudrate=115200

[U-Boot] [PATCH 1/1] efi_loader: call add_u_boot_and_runtime() on sandbox

2019-11-12 Thread Heinrich Schuchardt
On the sandbox we should mark the stack area as EFI runtime memory like we
do on any other architecture.

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_memory.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 83cbc9154f..d46001f608 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -738,8 +738,10 @@ static void add_u_boot_and_runtime(void)
unsigned long uboot_stack_size = 16 * 1024 * 1024;

/* Add U-Boot */
-   uboot_start = (gd->start_addr_sp - uboot_stack_size) & ~EFI_PAGE_MASK;
-   uboot_pages = (gd->ram_top - uboot_start) >> EFI_PAGE_SHIFT;
+   uboot_start = ((uintptr_t)map_sysmem(gd->start_addr_sp, 0) -
+  uboot_stack_size) & ~EFI_PAGE_MASK;
+   uboot_pages = ((uintptr_t)map_sysmem(gd->ram_top - 1, 0) -
+  uboot_start + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
efi_add_memory_map(uboot_start, uboot_pages, EFI_LOADER_DATA, false);

 #if defined(__aarch64__)
@@ -767,8 +769,7 @@ int efi_memory_init(void)
 {
efi_add_known_memory();

-   if (!IS_ENABLED(CONFIG_SANDBOX))
-   add_u_boot_and_runtime();
+   add_u_boot_and_runtime();

 #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
/* Request a 32bit 64MB bounce buffer region */
--
2.24.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 2/3] efi_loader: support building UEFI binaries on sandbox

2019-11-12 Thread Heinrich Schuchardt
On the sandbox the UEFI binaries must match the host architectures.

Adjust the Makefiles. Provide the PE/COFF header and relocation files.

Allow building helloworld.efi on the sandbox.

Signed-off-by: Heinrich Schuchardt 
---
v2:
no change
---
 Makefile | 19 +
 arch/sandbox/config.mk   | 28 
 arch/sandbox/lib/crt0_sandbox_efi.S  | 32 
 arch/sandbox/lib/reloc_sandbox_efi.c | 32 
 cmd/Kconfig  |  2 +-
 include/host_arch.h  | 24 +
 lib/efi_loader/Makefile  |  3 +++
 7 files changed, 139 insertions(+), 1 deletion(-)
 create mode 100644 arch/sandbox/lib/crt0_sandbox_efi.S
 create mode 100644 arch/sandbox/lib/reloc_sandbox_efi.c
 create mode 100644 include/host_arch.h

diff --git a/Makefile b/Makefile
index a9a78c30d6..c746de62be 100644
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,25 @@ NAME =
 # o Look for make include files relative to root of kernel src
 MAKEFLAGS += -rR --include-dir=$(CURDIR)

+# Determine host architecture
+include include/host_arch.h
+MK_ARCH="${shell uname -m}"
+unexport HOST_ARCH
+ifeq ("x86_64", $(MK_ARCH))
+  export HOST_ARCH=$(HOST_ARCH_X86_64)
+else ifneq (,$(findstring $(MK_ARCH), "i386" "i486" "i586" "i686"))
+  export HOST_ARCH=$(HOST_ARCH_X86)
+else ifneq (,$(findstring $(MK_ARCH), "aarch64" "armv8l"))
+  export HOST_ARCH=$(HOST_ARCH_AARCH64)
+else ifeq ("armv7l", $(MK_ARCH))
+  export HOST_ARCH=$(HOST_ARCH_ARM)
+else ifeq ("riscv32", $(MK_ARCH))
+  export HOST_ARCH=$(HOST_ARCH_RISCV32)
+else ifeq ("riscv64", $(MK_ARCH))
+  export HOST_ARCH=$(HOST_ARCH_RISCV64)
+endif
+undefine MK_ARCH
+
 # Avoid funny character set dependencies
 unexport LC_ALL
 LC_COLLATE=C
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
index 05fbbd7bcc..a225c9cbfa 100644
--- a/arch/sandbox/config.mk
+++ b/arch/sandbox/config.mk
@@ -27,3 +27,31 @@ cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T 
u-boot-spl.lds \
$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot-spl.map -Wl,--gc-sections)

 CONFIG_ARCH_DEVICE_TREE := sandbox
+
+ifeq ($(HOST_ARCH),$(HOST_ARCH_X86_64))
+EFI_LDS := ${SRCDIR}/../../../arch/x86/lib/elf_x86_64_efi.lds
+EFI_TARGET := --target=efi-app-x86_64
+else ifeq ($(HOST_ARCH),$(HOST_ARCH_X86))
+EFI_LDS := ${SRCDIR}/../../../arch/x86/lib/elf_ia32_efi.lds
+EFI_TARGET := --target=efi-app-ia32
+else ifeq ($(HOST_ARCH),$(HOST_ARCH_AARCH64))
+EFI_LDS := ${SRCDIR}/../../../arch/arm/lib/elf_aarch64_efi.lds
+OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .data \
+   -j .u_boot_list -j .rela.dyn -j .got -j .got.plt \
+   -j .binman_sym_table -j .text_rest \
+   -j .efi_runtime -j .efi_runtime_rel
+else ifeq ($(HOST_ARCH),$(HOST_ARCH_ARM))
+EFI_LDS := ${SRCDIR}/../../../arch/arm/lib/elf_arm_efi.lds
+OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .hash \
+   -j .data -j .got -j .got.plt -j .u_boot_list -j .rel.dyn \
+   -j .binman_sym_table -j .text_rest \
+   -j .efi_runtime -j .efi_runtime_rel
+else ifeq ($(HOST_ARCH),$(HOST_ARCH_RISCV32))
+EFI_LDS := ${SRCDIR}/../../../arch/riscv/lib/elf_riscv32_efi.lds
+else ifeq ($(HOST_ARCH),$(HOST_ARCH_RISCV64))
+EFI_LDS := ${SRCDIR}/../../../arch/riscv/lib/elf_riscv64_efi.lds
+endif
+EFI_CRT0 := crt0_sandbox_efi.o
+EFI_RELOC := reloc_sandbox_efi.o
+AFLAGS_crt0_sandbox_efi.o += -DHOST_ARCH="$(HOST_ARCH)"
+CFLAGS_reloc_sandbox_efi.o += -DHOST_ARCH="$(HOST_ARCH)"
diff --git a/arch/sandbox/lib/crt0_sandbox_efi.S 
b/arch/sandbox/lib/crt0_sandbox_efi.S
new file mode 100644
index 00..b15766c514
--- /dev/null
+++ b/arch/sandbox/lib/crt0_sandbox_efi.S
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * PE/COFF header for EFI applications
+ *
+ * Copyright (c) 2019 Heinrich Schuchardt
+ */
+
+#include 
+
+#if HOST_ARCH == HOST_ARCH_X86_64
+#include "../../../arch/x86/lib/crt0_x86_64_efi.S"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_X86
+#include "../../../arch/x86/lib/crt0_ia32_efi.S"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_AARCH64
+#include "../../../arch/arm/lib/crt0_aarch64_efi.S"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_ARM
+#include "../../../arch/arm/lib/crt0_arm_efi.S"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_RISCV32
+#include "../../../arch/riscv/lib/crt0_riscv_efi.S"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_RISCV64
+#include "../../../arch/riscv/lib/crt0_riscv_efi.S"
+#endif
diff --git a/arch/sandbox/lib/reloc_sandbox_efi.c 
b/arch/sandbox/lib/reloc_sandbox_efi.c
new file mode 100644
index 00..a21e6757c5
--- /dev/null
+++ b/arch/sandbox/lib/reloc_sandbox_efi.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * position independent shared object relocator
+ *
+ * Copyright (c) 2019 Heinrich Schuchardt
+ */
+
+#include 
+
+#if HOST_ARCH == HOST_ARCH_X86_64
+#include 

[U-Boot] [PATCH v2 1/3] efi_loader: call add_u_boot_and_runtime() on sandbox

2019-11-12 Thread Heinrich Schuchardt
On the sandbox we should mark the stack area as EFI runtime memory like we
do on any other architecture.

Signed-off-by: Heinrich Schuchardt 
---
v2:
no change
---
 lib/efi_loader/efi_memory.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 83cbc9154f..d46001f608 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -738,8 +738,10 @@ static void add_u_boot_and_runtime(void)
unsigned long uboot_stack_size = 16 * 1024 * 1024;

/* Add U-Boot */
-   uboot_start = (gd->start_addr_sp - uboot_stack_size) & ~EFI_PAGE_MASK;
-   uboot_pages = (gd->ram_top - uboot_start) >> EFI_PAGE_SHIFT;
+   uboot_start = ((uintptr_t)map_sysmem(gd->start_addr_sp, 0) -
+  uboot_stack_size) & ~EFI_PAGE_MASK;
+   uboot_pages = ((uintptr_t)map_sysmem(gd->ram_top - 1, 0) -
+  uboot_start + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
efi_add_memory_map(uboot_start, uboot_pages, EFI_LOADER_DATA, false);

 #if defined(__aarch64__)
@@ -767,8 +769,7 @@ int efi_memory_init(void)
 {
efi_add_known_memory();

-   if (!IS_ENABLED(CONFIG_SANDBOX))
-   add_u_boot_and_runtime();
+   add_u_boot_and_runtime();

 #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
/* Request a 32bit 64MB bounce buffer region */
--
2.24.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 0/3] efi_loader: support building UEFI binaries on sandbox

2019-11-12 Thread Heinrich Schuchardt
Building helloworld.efi and UEFI binaries needed for unit tests requires
that the build system considers the host architecture on which the
sandbox is built.

The patch series provides these adjustment and enables building both
helloworld.efi and unit test requiring UEFI binaries.

v2:
enable building UEFI unit tests requiring UEFI binaries

Heinrich Schuchardt (3):
  efi_loader: call add_u_boot_and_runtime() on sandbox
  efi_loader: support building UEFI binaries on sandbox
  efi_selftest: enable all UEFI unit tests on the sandbox

 Makefile | 19 +
 arch/sandbox/config.mk   | 28 
 arch/sandbox/lib/crt0_sandbox_efi.S  | 32 
 arch/sandbox/lib/reloc_sandbox_efi.c | 32 
 cmd/Kconfig  |  2 +-
 include/host_arch.h  | 24 +
 lib/efi_loader/Makefile  |  3 +++
 lib/efi_loader/efi_memory.c  |  9 
 lib/efi_selftest/Makefile|  7 --
 9 files changed, 149 insertions(+), 7 deletions(-)
 create mode 100644 arch/sandbox/lib/crt0_sandbox_efi.S
 create mode 100644 arch/sandbox/lib/reloc_sandbox_efi.c
 create mode 100644 include/host_arch.h

--
2.24.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 3/3] efi_selftest: enable all UEFI unit tests on the sandbox

2019-11-12 Thread Heinrich Schuchardt
As we can build relocation code for the sandbox now we should enable the
unit tests that had to be disabled up to now.

Signed-off-by: Heinrich Schuchardt 
---
v2:
new patch
---
 lib/efi_selftest/Makefile | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile
index 8348014077..487cb4c674 100644
--- a/lib/efi_selftest/Makefile
+++ b/lib/efi_selftest/Makefile
@@ -5,6 +5,9 @@
 # This file only gets included with CONFIG_EFI_LOADER set, so all
 # object inclusion implicitly depends on it

+asflags-y += -DHOST_ARCH="$(HOST_ARCH)"
+ccflags-y += -DHOST_ARCH="$(HOST_ARCH)"
+
 CFLAGS_efi_selftest_miniapp_exit.o := $(CFLAGS_EFI) -Os -ffreestanding
 CFLAGS_REMOVE_efi_selftest_miniapp_exit.o := $(CFLAGS_NON_EFI)
 CFLAGS_efi_selftest_miniapp_return.o := $(CFLAGS_EFI) -Os -ffreestanding
@@ -55,8 +58,8 @@ obj-y += efi_selftest_block_device.o
 endif

 # TODO: As of v2019.10 the relocation code for the EFI application cannot
-# be built on ARMv7-M and Sandbox.
-ifeq ($(CONFIG_SANDBOX)$(CONFIG_CPU_V7M),)
+# be built on ARMv7-M.
+ifeq ($(CONFIG_CPU_V7M),)

 obj-y += \
 efi_selftest_exception.o \
--
2.24.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/2] usb: dwc2: fix possible alignment issues

2019-11-12 Thread Simon Goldschmidt
Since upgrading to gcc9, warnings are issued:
"taking address of packed member of ‘...’ may result in an unaligned
pointer value"

Fix this by converting dwc2_fifo_read to use unaligned access since packed
structures may be on an unaligned address, depending on USB hardware.

Signed-off-by: Simon Goldschmidt 
---

 drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c 
b/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c
index 7eb632d3b1..dba221dad0 100644
--- a/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c
+++ b/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c
@@ -731,7 +731,7 @@ static int write_fifo_ep0(struct dwc2_ep *ep, struct 
dwc2_request *req)
return 0;
 }
 
-static int dwc2_fifo_read(struct dwc2_ep *ep, u32 *cp, int max)
+static int dwc2_fifo_read(struct dwc2_ep *ep, void *cp, int max)
 {
invalidate_dcache_range((unsigned long)cp, (unsigned long)cp +
ROUND(max, CONFIG_SYS_CACHELINE_SIZE));
@@ -1285,7 +1285,7 @@ static void dwc2_ep0_setup(struct dwc2_udc *dev)
nuke(ep, -EPROTO);
 
/* read control req from fifo (8 bytes) */
-   dwc2_fifo_read(ep, (u32 *)usb_ctrl, 8);
+   dwc2_fifo_read(ep, usb_ctrl, 8);
 
debug_cond(DEBUG_SETUP != 0,
   "%s: bRequestType = 0x%x(%s), bRequest = 0x%x"
-- 
2.20.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/2] usb: composite: fix possible alignment issues

2019-11-12 Thread Simon Goldschmidt
Since upgrading to gcc9, warnings are issued:
"taking address of packed member of ‘...’ may result in an unaligned
pointer value"

Fix this by converting two functions to use unaligned access since packed
structures may be on an unaligned address, depending on USB hardware.

Signed-off-by: Simon Goldschmidt 
---

 drivers/usb/gadget/composite.c | 24 +---
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 618a7d5016..cfc9512caa 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -12,8 +12,16 @@
 
 #define USB_BUFSIZ 4096
 
+/* Helper type for accessing packed u16 pointers */
+typedef struct { __le16 val; } __packed __le16_packed;
+
 static struct usb_composite_driver *composite;
 
+static inline void le16_add_cpu_packed(__le16_packed *var, u16 val)
+{
+   var->val = cpu_to_le16(le16_to_cpu(var->val) + val);
+}
+
 /**
  * usb_add_function() - add a function to a configuration
  * @config: the configuration
@@ -480,20 +488,20 @@ done:
  * the host side.
  */
 
-static void collect_langs(struct usb_gadget_strings **sp, __le16 *buf)
+static void collect_langs(struct usb_gadget_strings **sp, void *buf)
 {
const struct usb_gadget_strings *s;
u16 language;
-   __le16  *tmp;
+   __le16_packed   *tmp;
 
while (*sp) {
s = *sp;
language = cpu_to_le16(s->language);
-   for (tmp = buf; *tmp && tmp < [126]; tmp++) {
-   if (*tmp == language)
+   for (tmp = buf; tmp->val && tmp < [126]; tmp++) {
+   if (tmp->val == language)
goto repeat;
}
-   *tmp++ = language;
+   tmp->val = language;
 repeat:
sp++;
}
@@ -705,7 +713,8 @@ static int bos_desc(struct usb_composite_dev *cdev)
 */
usb_ext = cdev->req->buf + le16_to_cpu(bos->wTotalLength);
bos->bNumDeviceCaps++;
-   le16_add_cpu(>wTotalLength, USB_DT_USB_EXT_CAP_SIZE);
+   le16_add_cpu_packed((__le16_packed *)>wTotalLength,
+   USB_DT_USB_EXT_CAP_SIZE);
usb_ext->bLength = USB_DT_USB_EXT_CAP_SIZE;
usb_ext->bDescriptorType = USB_DT_DEVICE_CAPABILITY;
usb_ext->bDevCapabilityType = USB_CAP_TYPE_EXT;
@@ -721,7 +730,8 @@ static int bos_desc(struct usb_composite_dev *cdev)
 
ss_cap = cdev->req->buf + le16_to_cpu(bos->wTotalLength);
bos->bNumDeviceCaps++;
-   le16_add_cpu(>wTotalLength, USB_DT_USB_SS_CAP_SIZE);
+   le16_add_cpu_packed((__le16_packed *)>wTotalLength,
+   USB_DT_USB_SS_CAP_SIZE);
ss_cap->bLength = USB_DT_USB_SS_CAP_SIZE;
ss_cap->bDescriptorType = USB_DT_DEVICE_CAPABILITY;
ss_cap->bDevCapabilityType = USB_SS_CAP_TYPE;
-- 
2.20.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [BUG] U-Boot hangs on fatload, commit ee88eacbdd840199a3dec707234579fb15ddd46a

2019-11-12 Thread Heinrich Schuchardt

On 11/11/19 6:14 PM, Gray Remlin wrote:


This content is getting very convoluted, if appropriate feel free to
crop it.
New point raised at very bottom.

On Sun, 10 Nov 2019 at 08:41, Heinrich Schuchardt mailto:xypron.g...@gmx.de>> wrote:

On 11/9/19 10:31 PM, Gray Remlin wrote:
 > On Sat, 9 Nov 2019 at 20:50, Heinrich Schuchardt
mailto:xypron.g...@gmx.de>
 > >> wrote:
 >
 >     On 11/9/19 8:42 PM, Gray Remlin wrote:
 >      > On Sat, 9 Nov 2019 at 18:40, Heinrich Schuchardt
 >     mailto:xypron.g...@gmx.de>
>
 >      > 
      >
 >      >     On 11/9/19 6:08 PM, Heinrich Schuchardt wrote:
 >      >      > On 11/9/19 4:11 PM, Gray Remlin wrote:
 >      >      >> On Fri, 8 Nov 2019 at 20:08, Heinrich Schuchardt
 >      >     mailto:xypron.g...@gmx.de>
>
 >     
>>
 >      >      >>  >
 >     
 wrote:
 >      >      >>
 >      >      >>     On 11/8/19 7:32 PM, Gray Remlin wrote:
 >      >      >>  > Please excuse the noise. I would like to file a
 >     bug report
 >      >      >>     against the
 >      >      >>  > above commit, a quick search of www.denx.de

 >     
 >      >      
 >      >      >>      did not
 >      >      >>  > reveal how I should proceed. Please point me in
 >     the right
 >      >      >> direction.
 >      >      >>  >
 >      >      >>  >
 >      >      >>  > Issue:
 >      >      >>  > U-Boot hangs (i.e. during boot) whenever
the command
 >      >     'fatload' is
 >      >      >>     used.
 >      >      >>  >
 >      >      >>  > Details:
 >      >      >>  > U-Boot 2019.10 compiled with either
 >     dreamplug_defconfig or
 >      >      >>  > guruplug_defconfig.
 >      >      >>  >
 >      >      >>  > After the commit do_load() now additionally
calls
 >      >      >> efi_set_bootdev()
 >      >      >>  > which was moved out of do_load_wrapper()
which is
 >     only called
 >      >      >> by the
 >      >      >>  > 'load' command.
 >      >      >>  >
 >      >      >>  > Reverting the commit fixes this issue for me.
 >      >      >>  >
 >      >      >>
 >      >      >>     Dear Gray,
 >      >      >>
 >      >      >>     thanks for reporting the issue with commit
 >      >      >>     fs: do_load: pass device path for efi payload
 >      >      >>     ee88eacbdd840199a3dec707234579fb15ddd46a
 >      >      >>
 >      >      >>     Is it only the fatload command that fails on your
 >     device or
 >      >     also the
 >      >      >>     load command?
 >      >      >>
 >      >      >>     There is no bug tracker for U-Boot. So sending
a mail
 >     to the
 >      >     U-Boot
 >      >      >>     mailing list, the patch author, and the
maintainer is the
 >      >     best way to
 >      >      >>     inform the developers about bugs.
 >      >      >>
 >      >      >>     Best regards
 >      >      >>
 >      >      >>     Heinrich
 >      >      >>
 >      >      >>


Distribution and version of GCC:

 >      >      >> Additional information:
 >      >      >> cross-compiler
 >     gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabi
 >      >      >>
 >      >      >> The U-Boot environment being used is the default
obtained by
 >      >      >> compiling U-Boot 2020.01-rc1-00100-gee93ef0c4b as
 >      >     dreamplug_defconfig
 >      >      >>
 >      >      >> => printenv
 >      >      >> baudrate=115200
 >      >      >> bootcmd=setenv ethact egiga0; ${x_bootcmd_ethernet};
 >     setenv ethact
 >      >      >> egiga1; ${x_bootcmd_ethernet}; ${x_bootcmd_usb};
 >      >     ${x_bootcmd_kernel};
 >      >      >> setenv bootargs ${x_bootargs} ${x_bootargs_root};
bootm
 >     0x640;
 >      >      >> bootdelay=3
 >      >      >> ethact=egiga0
 >      >      >> fdtcontroladdr=1fb8e7c8
 >      >      >> stderr=serial
 >      >      >> stdin=serial

[U-Boot] [PATCH v3 33/42] common: Move interrupt functions into a new header

2019-11-12 Thread Simon Glass
These functions do not use driver model but are fairly widely used in
U-Boot. But it is not clear that they will use driver model anytime soon,
so we don't want to label them as 'legacy'.

Move them to a new irq_func.h header file. Avoid the name 'irq.h' since it
is widely used in U-Boot already.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Rename irq_legacy to irq_func to avoid the 'legacy' label
- Update commit message

Changes in v2: None

 arch/arc/lib/interrupts.c |  1 +
 arch/arm/lib/interrupts.c |  1 +
 arch/arm/lib/interrupts_64.c  |  1 +
 arch/arm/lib/interrupts_m.c   |  1 +
 arch/m68k/cpu/mcf5227x/interrupts.c   |  1 +
 arch/m68k/cpu/mcf523x/interrupts.c|  1 +
 arch/m68k/cpu/mcf52x2/interrupts.c|  1 +
 arch/m68k/cpu/mcf530x/interrupts.c|  1 +
 arch/m68k/cpu/mcf532x/interrupts.c|  1 +
 arch/m68k/cpu/mcf5445x/interrupts.c   |  1 +
 arch/m68k/cpu/mcf547x_8x/interrupts.c |  1 +
 arch/m68k/cpu/mcf547x_8x/slicetimer.c |  1 +
 arch/m68k/lib/interrupts.c|  1 +
 arch/m68k/lib/time.c  |  1 +
 arch/microblaze/cpu/interrupts.c  |  1 +
 arch/mips/cpu/interrupts.c|  1 +
 arch/mips/mach-jz47xx/jz4780/timer.c  |  1 +
 arch/nds32/cpu/n1213/ae3xx/cpu.c  |  2 +-
 arch/nds32/cpu/n1213/ag101/timer.c|  1 +
 arch/nds32/lib/interrupts.c   |  1 +
 arch/nios2/cpu/interrupts.c   |  1 +
 arch/powerpc/cpu/mpc83xx/interrupts.c |  1 +
 arch/powerpc/cpu/mpc85xx/interrupts.c |  1 +
 arch/powerpc/cpu/mpc85xx/traps.c  |  1 +
 arch/powerpc/cpu/mpc86xx/interrupts.c |  1 +
 arch/powerpc/cpu/mpc8xx/interrupts.c  |  1 +
 arch/powerpc/lib/interrupts.c |  1 +
 arch/riscv/cpu/ax25/cpu.c |  2 +-
 arch/riscv/lib/interrupts.c   |  1 +
 arch/sandbox/lib/interrupts.c |  1 +
 arch/sh/cpu/sh4/interrupts.c  |  1 +
 arch/x86/cpu/i386/interrupt.c |  1 +
 arch/x86/cpu/x86_64/interrupts.c  |  1 +
 arch/x86/lib/bios.c   |  1 +
 arch/x86/lib/interrupts.c |  1 +
 arch/x86/lib/spl.c|  1 +
 arch/xtensa/cpu/exceptions.c  |  1 +
 board/cirrus/edb93xx/edb93xx.c|  2 +-
 common/board_r.c  |  1 +
 common/spl/spl.c  |  1 +
 drivers/mtd/cfi_flash.c   |  1 +
 drivers/timer/mpc83xx_timer.c |  1 +
 include/common.h  |  7 ---
 include/exports.h |  2 ++
 include/irq_func.h| 19 +++
 post/cpu/mpc83xx/ecc.c|  2 +-
 46 files changed, 64 insertions(+), 11 deletions(-)
 create mode 100644 include/irq_func.h

diff --git a/arch/arc/lib/interrupts.c b/arch/arc/lib/interrupts.c
index 24ff751220..db21fbb114 100644
--- a/arch/arc/lib/interrupts.c
+++ b/arch/arc/lib/interrupts.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/arm/lib/interrupts.c b/arch/arm/lib/interrupts.c
index e78ca56d25..75b70d9125 100644
--- a/arch/arm/lib/interrupts.c
+++ b/arch/arm/lib/interrupts.c
@@ -20,6 +20,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/arm/lib/interrupts_64.c b/arch/arm/lib/interrupts_64.c
index a32a4b6868..dffdf57aa2 100644
--- a/arch/arm/lib/interrupts_64.c
+++ b/arch/arm/lib/interrupts_64.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/arm/lib/interrupts_m.c b/arch/arm/lib/interrupts_m.c
index 95df6cb1eb..e4373f3781 100644
--- a/arch/arm/lib/interrupts_m.c
+++ b/arch/arm/lib/interrupts_m.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 
 /*
  * Upon exception entry ARMv7-M processors automatically save stack
diff --git a/arch/m68k/cpu/mcf5227x/interrupts.c 
b/arch/m68k/cpu/mcf5227x/interrupts.c
index d38f01950b..5a6a88cd57 100644
--- a/arch/m68k/cpu/mcf5227x/interrupts.c
+++ b/arch/m68k/cpu/mcf5227x/interrupts.c
@@ -10,6 +10,7 @@
 
 /* CPU specific interrupt routine */
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/m68k/cpu/mcf523x/interrupts.c 
b/arch/m68k/cpu/mcf523x/interrupts.c
index 1d03724f15..b554c51fcb 100644
--- a/arch/m68k/cpu/mcf523x/interrupts.c
+++ b/arch/m68k/cpu/mcf523x/interrupts.c
@@ -7,6 +7,7 @@
 
 /* CPU specific interrupt routine */
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/m68k/cpu/mcf52x2/interrupts.c 
b/arch/m68k/cpu/mcf52x2/interrupts.c
index f874675b12..35ed1e7901 100644
--- a/arch/m68k/cpu/mcf52x2/interrupts.c
+++ b/arch/m68k/cpu/mcf52x2/interrupts.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/m68k/cpu/mcf530x/interrupts.c 
b/arch/m68k/cpu/mcf530x/interrupts.c
index cd85c69f12..2659e3478f 100644
--- a/arch/m68k/cpu/mcf530x/interrupts.c
+++ b/arch/m68k/cpu/mcf530x/interrupts.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/m68k/cpu/mcf532x/interrupts.c 
b/arch/m68k/cpu/mcf532x/interrupts.c
index 

[U-Boot] [PATCH v3 35/42] common: Move command functions out of common.h

2019-11-12 Thread Simon Glass
Move these functions into the command.h header file which is a better fit.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/mach-kirkwood/cpu.c|  1 +
 arch/sandbox/cpu/start.c|  1 +
 board/engicam/common/board.c|  1 +
 board/gdsys/a38x/keyprogram.c   |  1 +
 board/gdsys/p1022/controlcenterd-id.c   |  1 +
 board/grinn/liteboard/board.c   |  1 +
 board/inversepath/usbarmory/usbarmory.c |  1 +
 board/samsung/common/misc.c |  1 +
 common/autoboot.c   |  1 +
 common/cli.c|  1 +
 common/cli_simple.c |  1 +
 common/main.c   |  1 +
 common/splash_source.c  |  1 +
 drivers/fastboot/fb_command.c   |  1 +
 drivers/fastboot/fb_common.c|  1 +
 drivers/mtd/nand/raw/fsl_elbc_nand.c|  1 +
 drivers/mtd/nand/raw/fsl_ifc_nand.c |  1 +
 drivers/net/fsl-mc/mc.c |  1 +
 drivers/usb/gadget/f_thor.c |  1 +
 include/command.h   | 16 
 include/common.h| 17 +
 test/command_ut.c   |  1 +
 test/dm/sf.c|  1 +
 23 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/arch/arm/mach-kirkwood/cpu.c b/arch/arm/mach-kirkwood/cpu.c
index 6ad2543438..29c0e592e4 100644
--- a/arch/arm/mach-kirkwood/cpu.c
+++ b/arch/arm/mach-kirkwood/cpu.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index cfc542c806..fff9cbdd79 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/engicam/common/board.c b/board/engicam/common/board.c
index 0c47afe5b5..31ff297b75 100644
--- a/board/engicam/common/board.c
+++ b/board/engicam/common/board.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/gdsys/a38x/keyprogram.c b/board/gdsys/a38x/keyprogram.c
index 000897984a..853981aadb 100644
--- a/board/gdsys/a38x/keyprogram.c
+++ b/board/gdsys/a38x/keyprogram.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/gdsys/p1022/controlcenterd-id.c 
b/board/gdsys/p1022/controlcenterd-id.c
index d6798bd338..04d3809566 100644
--- a/board/gdsys/p1022/controlcenterd-id.c
+++ b/board/gdsys/p1022/controlcenterd-id.c
@@ -11,6 +11,7 @@
 #endif
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/grinn/liteboard/board.c b/board/grinn/liteboard/board.c
index 1558ea4b84..151041a789 100644
--- a/board/grinn/liteboard/board.c
+++ b/board/grinn/liteboard/board.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2016 Grinn
  */
 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/inversepath/usbarmory/usbarmory.c 
b/board/inversepath/usbarmory/usbarmory.c
index de4ad83226..19510184d8 100644
--- a/board/inversepath/usbarmory/usbarmory.c
+++ b/board/inversepath/usbarmory/usbarmory.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/samsung/common/misc.c b/board/samsung/common/misc.c
index 3ef1e79980..9117669f71 100644
--- a/board/samsung/common/misc.c
+++ b/board/samsung/common/misc.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/common/autoboot.c b/common/autoboot.c
index 8faac2005d..94a1b4abeb 100644
--- a/common/autoboot.c
+++ b/common/autoboot.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/common/cli.c b/common/cli.c
index 49b910666b..67ceb635a6 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/common/cli_simple.c b/common/cli_simple.c
index 6c881c133c..358e9b7fe1 100644
--- a/common/cli_simple.c
+++ b/common/cli_simple.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/common/main.c b/common/main.c
index 3a657c3d9a..a94df7ae04 100644
--- a/common/main.c
+++ b/common/main.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/common/splash_source.c b/common/splash_source.c
index d37b4b304c..2ff15208a7 100644
--- a/common/splash_source.c
+++ b/common/splash_source.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c
index 4864344853..3c4acfecf6 100644
--- a/drivers/fastboot/fb_command.c
+++ b/drivers/fastboot/fb_command.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index e76af8ecc3..c3735a44af 100644
--- 

[U-Boot] [PATCH v3 41/42] common: Drop get_endaddr()

2019-11-12 Thread Simon Glass
This is not used in U-Boot. Drop it.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 include/common.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/common.h b/include/common.h
index e946e4d9b7..64d0cf542e 100644
--- a/include/common.h
+++ b/include/common.h
@@ -144,7 +144,6 @@ voidrelocate_code(ulong);
 #else
 void   relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn));
 #endif
-ulong  get_endaddr   (void);
 
 void s_init(void);
 
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 39/42] common: Move pci_init_board() out of common.h

2019-11-12 Thread Simon Glass
This function can be dropped when all boards use driver model for PCI. For
now, move it into init.h with a comment.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 board/armltd/integrator/pci.c   | 1 +
 board/cavium/thunderx/thunderx.c| 1 +
 board/esd/vme8349/pci.c | 1 +
 board/freescale/b4860qds/pci.c  | 1 +
 board/freescale/common/p_corenet/pci.c  | 1 +
 board/freescale/m54455evb/m54455evb.c   | 1 +
 board/freescale/m547xevb/m547xevb.c | 1 +
 board/freescale/m548xevb/m548xevb.c | 1 +
 board/freescale/mpc8308rdb/mpc8308rdb.c | 1 +
 board/freescale/mpc8315erdb/mpc8315erdb.c   | 1 +
 board/freescale/mpc8323erdb/mpc8323erdb.c   | 1 +
 board/freescale/mpc832xemds/pci.c   | 1 +
 board/freescale/mpc8349emds/pci.c   | 1 +
 board/freescale/mpc8349itx/pci.c| 1 +
 board/freescale/mpc837xemds/pci.c   | 1 +
 board/freescale/mpc837xerdb/pci.c   | 1 +
 board/freescale/mpc8541cds/mpc8541cds.c | 1 +
 board/freescale/mpc8544ds/mpc8544ds.c   | 1 +
 board/freescale/mpc8548cds/mpc8548cds.c | 1 +
 board/freescale/mpc8555cds/mpc8555cds.c | 1 +
 board/freescale/mpc8568mds/mpc8568mds.c | 1 +
 board/freescale/mpc8610hpcd/mpc8610hpcd.c   | 1 +
 board/freescale/mpc8641hpcn/mpc8641hpcn.c   | 1 +
 board/freescale/qemu-ppce500/qemu-ppce500.c | 1 +
 board/freescale/t102xqds/pci.c  | 1 +
 board/freescale/t102xrdb/pci.c  | 1 +
 board/freescale/t1040qds/pci.c  | 1 +
 board/freescale/t104xrdb/pci.c  | 1 +
 board/freescale/t208xqds/pci.c  | 1 +
 board/freescale/t208xrdb/pci.c  | 1 +
 board/freescale/t4qds/pci.c | 1 +
 board/freescale/t4rdb/pci.c | 1 +
 board/gdsys/mpc8308/hrcon.c | 1 +
 board/gdsys/mpc8308/strider.c   | 1 +
 board/imgtec/malta/malta.c  | 1 +
 board/keymile/kmp204x/pci.c | 1 +
 board/mpc8308_p1m/mpc8308_p1m.c | 1 +
 board/renesas/r7780mp/r7780mp.c | 1 +
 board/sbc8349/pci.c | 1 +
 board/sbc8548/sbc8548.c | 1 +
 board/sbc8641d/sbc8641d.c   | 1 +
 board/tqc/tqm834x/pci.c | 1 +
 board/varisys/cyrus/pci.c   | 1 +
 board/ve8313/ve8313.c   | 1 +
 board/xes/common/fsl_8xxx_pci.c | 1 +
 drivers/pci/pci.c   | 1 +
 drivers/pci/pcie_imx.c  | 1 +
 include/common.h| 2 --
 include/init.h  | 3 +++
 49 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/board/armltd/integrator/pci.c b/board/armltd/integrator/pci.c
index 5e57f7f4c9..c189d23eec 100644
--- a/board/armltd/integrator/pci.c
+++ b/board/armltd/integrator/pci.c
@@ -20,6 +20,7 @@
  * Linus Walleij 
  */
 #include 
+#include 
 #include 
 #include 
 #include "integrator-sc.h"
diff --git a/board/cavium/thunderx/thunderx.c b/board/cavium/thunderx/thunderx.c
index cf55b633c3..940455de5b 100644
--- a/board/cavium/thunderx/thunderx.c
+++ b/board/cavium/thunderx/thunderx.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/esd/vme8349/pci.c b/board/esd/vme8349/pci.c
index 82347f258c..349e7b567c 100644
--- a/board/esd/vme8349/pci.c
+++ b/board/esd/vme8349/pci.c
@@ -10,6 +10,7 @@
  * Based on MPC8349 PCI support but w/o PIB related code.
  */
 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/freescale/b4860qds/pci.c b/board/freescale/b4860qds/pci.c
index 3663b14bc3..45dd461e77 100644
--- a/board/freescale/b4860qds/pci.c
+++ b/board/freescale/b4860qds/pci.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/freescale/common/p_corenet/pci.c 
b/board/freescale/common/p_corenet/pci.c
index a6abe66dc0..94e4715f1c 100644
--- a/board/freescale/common/p_corenet/pci.c
+++ b/board/freescale/common/p_corenet/pci.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/freescale/m54455evb/m54455evb.c 
b/board/freescale/m54455evb/m54455evb.c
index 98af3be595..146cd918c4 100644
--- a/board/freescale/m54455evb/m54455evb.c
+++ b/board/freescale/m54455evb/m54455evb.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/freescale/m547xevb/m547xevb.c 
b/board/freescale/m547xevb/m547xevb.c
index 9e1aa99bbc..e8d86113d6 100644
--- a/board/freescale/m547xevb/m547xevb.c
+++ b/board/freescale/m547xevb/m547xevb.c
@@ -9,6 +9,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/freescale/m548xevb/m548xevb.c 
b/board/freescale/m548xevb/m548xevb.c
index b491518468..40e01c6f24 100644
--- a/board/freescale/m548xevb/m548xevb.c
+++ b/board/freescale/m548xevb/m548xevb.c
@@ -9,6 +9,7 @@
 
 

[U-Boot] [PATCH v3 31/42] common: Move ARM cache operations out of common.h

2019-11-12 Thread Simon Glass
These functions are CPU-related and do not use driver model. Move them to
cpu_legacy.h

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/cpu/arm926ejs/lpc32xx/cpu.c   |  1 +
 arch/arm/cpu/armv7/cache_v7.c  |  1 +
 arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c  |  1 +
 arch/arm/cpu/armv8/sec_firmware.c  |  1 +
 arch/arm/cpu/pxa/cache.c   |  1 +
 arch/arm/lib/cache.c   |  1 +
 arch/arm/mach-bcm283x/mbox.c   |  1 +
 arch/arm/mach-imx/mx7/psci-mx7.c   |  1 +
 arch/arm/mach-omap2/sec-common.c   |  1 +
 arch/arm/mach-tegra/ivc.c  |  1 +
 arch/microblaze/lib/bootm.c|  1 +
 arch/mips/lib/reloc.c  |  1 +
 arch/mips/lib/traps.c  |  1 +
 arch/mips/mach-jz47xx/jz4780/jz4780.c  |  1 +
 arch/mips/mach-mtmips/ddr_calibrate.c  |  1 +
 arch/nds32/cpu/n1213/ae3xx/cpu.c   |  1 +
 arch/nios2/cpu/cpu.c   |  1 +
 arch/nios2/lib/bootm.c |  1 +
 arch/powerpc/lib/bootm.c   |  1 +
 arch/powerpc/lib/cache.c   |  1 +
 arch/riscv/cpu/ax25/cpu.c  |  1 +
 arch/riscv/lib/smp.c   |  1 +
 arch/riscv/lib/spl.c   |  1 +
 arch/sandbox/cpu/cpu.c |  1 +
 arch/x86/cpu/quark/dram.c  |  1 +
 arch/x86/cpu/quark/quark.c |  1 +
 arch/xtensa/lib/bootm.c|  1 +
 board/Arcturus/ucp1020/cmd_arc.c   |  1 +
 board/beckhoff/mx53cx9020/mx53cx9020.c |  1 +
 board/broadcom/bcmstb/bcmstb.c |  1 +
 board/cirrus/edb93xx/edb93xx.c |  1 +
 board/phytec/pfla02/pfla02.c   |  1 +
 board/sandbox/sandbox.c|  1 +
 cmd/disk.c |  1 +
 cmd/load.c |  1 +
 cmd/ximg.c |  1 +
 common/avb_verify.c|  1 +
 common/board_r.c   |  1 +
 common/bootm.c |  1 +
 common/bouncebuf.c |  1 +
 common/image.c |  1 +
 common/lcd.c   |  1 +
 common/spl/spl_opensbi.c   |  1 +
 common/update.c|  1 +
 drivers/ata/ahci.c |  1 +
 drivers/ata/dwc_ahsata.c   |  1 +
 drivers/ata/fsl_ahci.c |  1 +
 drivers/ata/fsl_sata.c |  1 +
 drivers/ata/sata_mv.c  |  1 +
 drivers/ata/sata_sil.c |  1 +
 drivers/bootcount/bootcount.c  |  1 +
 drivers/bootcount/bootcount_ram.c  |  1 +
 drivers/core/device.c  |  1 +
 drivers/crypto/fsl/fsl_blob.c  |  1 +
 drivers/crypto/fsl/fsl_hash.c  |  1 +
 drivers/crypto/fsl/jobdesc.c   |  1 +
 drivers/crypto/fsl/jr.c|  1 +
 drivers/dma/apbh_dma.c |  1 +
 drivers/dma/bcm6348-iudma.c|  1 +
 drivers/dma/dma-uclass.c   |  1 +
 drivers/dma/ti/k3-udma.c   |  1 +
 drivers/fpga/versalpl.c|  1 +
 drivers/fpga/zynqmppl.c|  1 +
 drivers/mmc/dw_mmc.c   |  1 +
 drivers/mmc/fsl_esdhc.c|  1 +
 drivers/mmc/fsl_esdhc_imx.c|  1 +
 drivers/mmc/fsl_esdhc_spl.c|  1 +
 drivers/mmc/meson_gx_mmc.c |  1 +
 drivers/mmc/omap_hsmmc.c   |  1 +
 drivers/mmc/sdhci.c|  1 +
 drivers/mmc/stm32_sdmmc2.c |  1 +
 drivers/mmc/tmio-common.c  |  1 +
 drivers/mtd/nand/raw/denali.c  |  1 +
 drivers/mtd/nand/raw/fsl_elbc_spl.c|  1 +
 drivers/mtd/nand/raw/fsl_ifc_spl.c |  1 +
 drivers/mtd/nand/raw/mxs_nand.c|  1 +
 drivers/mtd/pic32_flash.c  |  1 +
 drivers/mtd/spi/fsl_espi_spl.c |  1 +
 drivers/net/ag7xxx.c   |  1 +
 drivers/net/altera_tse.c   |  1 +
 drivers/net/bcm-sf2-eth-gmac.c |  1 +
 drivers/net/designware.c   |  1 +
 drivers/net/dwc_eth_qos.c  |  1 +
 drivers/net/e1000.c|  1 +
 drivers/net/ethoc.c|  1 +
 drivers/net/fec_mxc.c  |  1 +
 drivers/net/fsl-mc/mc.c|  1 +
 drivers/net/ftgmac100.c|  1 +
 drivers/net/ftmac100.c |  1 +
 drivers/net/higmacv300.c   |  1 +
 drivers/net/ldpaa_eth/ldpaa_eth.c  |  1 +
 drivers/net/macb.c |  1 +
 drivers/net/mt7628-eth.c   |  1 +
 drivers/net/mtk_eth.c  |  1 +
 drivers/net/mvneta.c  

[U-Boot] [PATCH v3 36/42] common: Drop board_show_dram()

2019-11-12 Thread Simon Glass
This function is not defined by any boards so the feature is not used.
Drop it.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 cmd/mem.c| 9 ++---
 include/common.h | 9 -
 2 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/cmd/mem.c b/cmd/mem.c
index c6b8038fc9..545534b1fc 100644
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -1212,16 +1212,11 @@ U_BOOT_CMD(
 #endif
 
 #ifdef CONFIG_CMD_MEMINFO
-__weak void board_show_dram(phys_size_t size)
-{
-   puts("DRAM:  ");
-   print_size(size, "\n");
-}
-
 static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
   char * const argv[])
 {
-   board_show_dram(gd->ram_size);
+   puts("DRAM:  ");
+   print_size(gd->ram_size, "\n");
 
return 0;
 }
diff --git a/include/common.h b/include/common.h
index 5bd778a4f4..16d4b0612f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -73,15 +73,6 @@ extern u8 __dtb_dt_begin[];  /* embedded device tree blob */
 extern u8 __dtb_dt_spl_begin[];/* embedded device tree blob for 
SPL/TPL */
 int mdm_init(void);
 
-/**
- * Show the DRAM size in a board-specific way
- *
- * This is used by boards to display DRAM information in their own way.
- *
- * @param size Size of DRAM (which should be displayed along with other info)
- */
-void board_show_dram(phys_size_t size);
-
 /**
  * Get the uppermost pointer that is valid to access
  *
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 25/42] common: Drop cpu_init()

2019-11-12 Thread Simon Glass
This function is not defined anywhere. Drop it.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 include/common.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/common.h b/include/common.h
index 4de05032b2..ce08bfe11f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -64,8 +64,6 @@ typedef void (interrupt_handler_t)(void *);
  */
 void   hang(void) __attribute__ ((noreturn));
 
-intcpu_init(void);
-
 #include 
 
 /* common/main.c */
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 23/42] common: Move mii_init() function out of common.h

2019-11-12 Thread Simon Glass
This function belongs in mii.h so move it over.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/cpu/armv8/fsl-layerscape/cpu.c | 1 +
 drivers/net/fsl_mcdmafec.c  | 1 +
 drivers/net/ldpaa_eth/ls1088a.c | 1 +
 drivers/net/ldpaa_eth/lx2160a.c | 1 +
 drivers/net/mcffec.c| 1 +
 drivers/net/mcfmii.c| 1 +
 drivers/net/mpc8xx_fec.c| 1 +
 drivers/net/pic32_eth.c | 1 +
 include/common.h| 3 ---
 include/linux/mii.h | 2 ++
 10 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c 
b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
index 59d03b167c..374fde6b65 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
@@ -39,6 +39,7 @@
 #include 
 #endif
 #endif
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
diff --git a/drivers/net/fsl_mcdmafec.c b/drivers/net/fsl_mcdmafec.c
index e66fb16de8..b2936b78d7 100644
--- a/drivers/net/fsl_mcdmafec.c
+++ b/drivers/net/fsl_mcdmafec.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #undef ET_DEBUG
 #undef MII_DEBUG
diff --git a/drivers/net/ldpaa_eth/ls1088a.c b/drivers/net/ldpaa_eth/ls1088a.c
index c3260d318c..54cb16e51b 100644
--- a/drivers/net/ldpaa_eth/ls1088a.c
+++ b/drivers/net/ldpaa_eth/ls1088a.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 
 u32 dpmac_to_devdisr[] = {
[WRIOP1_DPMAC1] = FSL_CHASSIS3_DEVDISR2_DPMAC1,
diff --git a/drivers/net/ldpaa_eth/lx2160a.c b/drivers/net/ldpaa_eth/lx2160a.c
index 1fbeb0d14b..9432b6eb85 100644
--- a/drivers/net/ldpaa_eth/lx2160a.c
+++ b/drivers/net/ldpaa_eth/lx2160a.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 
 u32 dpmac_to_devdisr[] = {
[WRIOP1_DPMAC1] = FSL_CHASSIS3_DEVDISR2_DPMAC1,
diff --git a/drivers/net/mcffec.c b/drivers/net/mcffec.c
index fb93041256..9a3a8455a1 100644
--- a/drivers/net/mcffec.c
+++ b/drivers/net/mcffec.c
@@ -18,6 +18,7 @@
 
 #include 
 #include 
+#include 
 
 #undef ET_DEBUG
 #undef MII_DEBUG
diff --git a/drivers/net/mcfmii.c b/drivers/net/mcfmii.c
index 961618b410..b8af2cc44b 100644
--- a/drivers/net/mcfmii.c
+++ b/drivers/net/mcfmii.c
@@ -15,6 +15,7 @@
 #include 
 #endif
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
diff --git a/drivers/net/mpc8xx_fec.c b/drivers/net/mpc8xx_fec.c
index f45f1e4677..0a80985192 100644
--- a/drivers/net/mpc8xx_fec.c
+++ b/drivers/net/mpc8xx_fec.c
@@ -13,6 +13,7 @@
 #include 
 
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
diff --git a/drivers/net/pic32_eth.c b/drivers/net/pic32_eth.c
index b0f7677154..39c4b10ab8 100644
--- a/drivers/net/pic32_eth.c
+++ b/drivers/net/pic32_eth.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "pic32_eth.h"
 
diff --git a/include/common.h b/include/common.h
index cc5f13ec7e..992675100d 100644
--- a/include/common.h
+++ b/include/common.h
@@ -254,9 +254,6 @@ voidreset_timer(void);
 void   enable_interrupts  (void);
 intdisable_interrupts (void);
 
-/* $(CPU)/.../ */
-void mii_init (void);
-
 /* arch/$(ARCH)/lib/cache.c */
 void   enable_caches(void);
 void   flush_cache   (unsigned long, unsigned long);
diff --git a/include/linux/mii.h b/include/linux/mii.h
index 21db032340..49e29ac314 100644
--- a/include/linux/mii.h
+++ b/include/linux/mii.h
@@ -225,4 +225,6 @@ static inline u8 mii_resolve_flowctrl_fdx(u16 lcladv, u16 
rmtadv)
return cap;
 }
 
+void mii_init(void);
+
 #endif /* __LINUX_MII_H__ */
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 40/42] common: Move trap_init() out of common.h

2019-11-12 Thread Simon Glass
Move this function into the init.h header file.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Add init.h header

Changes in v2:
- Move trap_init() into init.h instead; update commit message

 arch/m68k/lib/traps.c | 1 +
 arch/mips/lib/traps.c | 1 +
 include/common.h  | 1 -
 include/init.h| 2 ++
 4 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/m68k/lib/traps.c b/arch/m68k/lib/traps.c
index 5d80207745..2ccd55add0 100644
--- a/arch/m68k/lib/traps.c
+++ b/arch/m68k/lib/traps.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/mips/lib/traps.c b/arch/mips/lib/traps.c
index ff02d437a8..944fa60240 100644
--- a/arch/mips/lib/traps.c
+++ b/arch/mips/lib/traps.c
@@ -12,6 +12,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/include/common.h b/include/common.h
index a292d91939..e946e4d9b7 100644
--- a/include/common.h
+++ b/include/common.h
@@ -145,7 +145,6 @@ voidrelocate_code(ulong);
 void   relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn));
 #endif
 ulong  get_endaddr   (void);
-void   trap_init (ulong);
 
 void s_init(void);
 
diff --git a/include/init.h b/include/init.h
index 3b45e631fc..8b65b2afe4 100644
--- a/include/init.h
+++ b/include/init.h
@@ -208,6 +208,8 @@ int board_early_init_r(void);
 /* TODO(s...@chromium.org): Drop this when DM_PCI migration is completed */
 void pci_init_board(void);
 
+void trap_init(unsigned long reloc_addr);
+
 #endif /* __ASSEMBLY__ */
 /* Put only stuff here that the assembler can digest */
 
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 22/42] common: Move get_ticks() function out of common.h

2019-11-12 Thread Simon Glass
This function belongs in time.h so move it over and add a comment.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/cpu/arm920t/ep93xx/timer.c|  1 +
 arch/arm/cpu/arm920t/imx/timer.c   |  1 +
 arch/arm/cpu/arm926ejs/armada100/timer.c   |  1 +
 arch/arm/cpu/arm926ejs/lpc32xx/timer.c |  1 +
 arch/arm/cpu/arm926ejs/mx27/timer.c|  1 +
 arch/arm/cpu/arm926ejs/mxs/timer.c |  1 +
 arch/arm/cpu/arm926ejs/spear/timer.c   |  1 +
 arch/arm/cpu/armv7/arch_timer.c|  1 +
 arch/arm/cpu/armv7/iproc-common/timer.c|  1 +
 arch/arm/cpu/armv7/s5p-common/timer.c  |  1 +
 arch/arm/cpu/armv7/stv0991/timer.c |  1 +
 arch/arm/cpu/armv7/sunxi/timer.c   |  1 +
 arch/arm/cpu/armv7/vf610/timer.c   |  1 +
 arch/arm/cpu/armv7m/systick-timer.c|  1 +
 arch/arm/cpu/sa1100/timer.c|  1 +
 arch/arm/mach-at91/arm920t/timer.c |  1 +
 arch/arm/mach-davinci/timer.c  |  1 +
 arch/arm/mach-omap2/timer.c|  1 +
 arch/arm/mach-orion5x/timer.c  |  1 +
 arch/arm/mach-rmobile/timer.c  |  1 +
 arch/arm/mach-socfpga/clock_manager_gen5.c |  1 +
 arch/arm/mach-sunxi/dram_helpers.c |  1 +
 arch/arm/mach-sunxi/p2wi.c |  1 +
 arch/arm/mach-sunxi/rsb.c  |  1 +
 arch/arm/mach-tegra/clock.c|  1 +
 arch/microblaze/cpu/timer.c|  1 +
 arch/mips/mach-jz47xx/jz4780/timer.c   |  1 +
 arch/nds32/cpu/n1213/ag101/timer.c |  1 +
 arch/sh/lib/time_sh2.c |  1 +
 arch/xtensa/lib/time.c |  1 +
 board/armltd/integrator/timer.c|  1 +
 board/broadcom/bcmstb/bcmstb.c |  1 +
 board/xilinx/versal/board.c|  1 +
 common/autoboot.c  |  1 +
 common/bootretry.c |  1 +
 common/cli_readline.c  |  1 +
 common/iotrace.c   |  1 +
 drivers/clk/clk_stm32mp1.c |  1 +
 drivers/mailbox/mailbox-uclass.c   |  1 +
 drivers/misc/tegra186_bpmp.c   |  1 +
 drivers/mmc/bcm2835_sdhci.c|  1 +
 drivers/mmc/mxcmmc.c   |  1 +
 drivers/net/pic32_eth.c|  1 +
 drivers/nvme/nvme.c|  1 +
 drivers/power/pmic/stpmic1.c   |  1 +
 drivers/sound/broadwell_i2s.c  |  1 +
 drivers/spi/ath79_spi.c|  1 +
 drivers/spi/exynos_spi.c   |  1 +
 drivers/spi/rk_spi.c   |  1 +
 drivers/spi/tegra114_spi.c |  1 +
 drivers/spi/tegra20_sflash.c   |  1 +
 drivers/spi/tegra20_slink.c|  1 +
 drivers/spi/tegra210_qspi.c|  1 +
 drivers/spi/uniphier_spi.c |  1 +
 drivers/spi/zynq_spi.c |  1 +
 drivers/timer/tsc_timer.c  |  1 +
 drivers/video/sunxi/sunxi_display.c|  1 +
 drivers/video/sunxi/sunxi_dw_hdmi.c|  1 +
 include/common.h   |  7 ++-
 include/time.h | 10 ++
 lib/efi_loader/efi_boottime.c  |  1 +
 lib/efi_loader/efi_console.c   |  1 +
 lib/time.c |  1 +
 lib/trace.c|  1 +
 lib/uuid.c |  1 +
 net/nfs.c  |  1 +
 post/post.c|  1 +
 test/time_ut.c |  1 +
 68 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/arch/arm/cpu/arm920t/ep93xx/timer.c 
b/arch/arm/cpu/arm920t/ep93xx/timer.c
index 49bf49bbd3..4829c996be 100644
--- a/arch/arm/cpu/arm920t/ep93xx/timer.c
+++ b/arch/arm/cpu/arm920t/ep93xx/timer.c
@@ -12,6 +12,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/arm920t/imx/timer.c b/arch/arm/cpu/arm920t/imx/timer.c
index 96fff3f683..17081ddb6d 100644
--- a/arch/arm/cpu/arm920t/imx/timer.c
+++ b/arch/arm/cpu/arm920t/imx/timer.c
@@ -13,6 +13,7 @@
  */
 
 #include 
+#include 
 #if defined (CONFIG_IMX)
 
 #include 
diff --git a/arch/arm/cpu/arm926ejs/armada100/timer.c 
b/arch/arm/cpu/arm926ejs/armada100/timer.c
index d2ecbd07e2..6c6948a8ef 100644
--- a/arch/arm/cpu/arm926ejs/armada100/timer.c
+++ b/arch/arm/cpu/arm926ejs/armada100/timer.c
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/arm/cpu/arm926ejs/lpc32xx/timer.c 
b/arch/arm/cpu/arm926ejs/lpc32xx/timer.c
index b3ca686040..3a896d10ca 100644
--- a/arch/arm/cpu/arm926ejs/lpc32xx/timer.c
+++ b/arch/arm/cpu/arm926ejs/lpc32xx/timer.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/arm926ejs/mx27/timer.c 
b/arch/arm/cpu/arm926ejs/mx27/timer.c
index 94b5d454e9..f51f0df8ec 100644
--- 

[U-Boot] [PATCH v3 17/42] common: Add a new lz4.h header file

2019-11-12 Thread Simon Glass
Add a header file to house the lz4 compression function. Add a comment
while we are here, since it not even clear from the name what the function
actuall does.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 common/image.c |  1 +
 include/common.h   |  3 ---
 include/lz4.h  | 24 
 lib/lz4_wrapper.c  |  1 +
 test/compression.c |  1 +
 5 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 include/lz4.h

diff --git a/common/image.c b/common/image.c
index 992ebbad51..1c8ac2df70 100644
--- a/common/image.c
+++ b/common/image.c
@@ -20,6 +20,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT
diff --git a/include/common.h b/include/common.h
index f433db17ae..1e77ed393e 100644
--- a/include/common.h
+++ b/include/common.h
@@ -292,9 +292,6 @@ voidwait_ticks(unsigned long);
 ulong  usec2ticks(unsigned long usec);
 ulong  ticks2usec(unsigned long ticks);
 
-/* lib/lz4_wrapper.c */
-int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
-
 /* lib/uuid.c */
 #include 
 
diff --git a/include/lz4.h b/include/lz4.h
new file mode 100644
index 00..1276fb98a3
--- /dev/null
+++ b/include/lz4.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2019 Google LLC
+ */
+
+#ifndef __LZ4_H
+#define __LZ4_H
+
+/**
+ * ulz4fn() - Decompress LZ4 data
+ *
+ * @src: Source data to decompress
+ * @srcn: Length of source data
+ * @dst: Destination for uncompressed data
+ * @dstn: Returns length of uncompressed data
+ * @return 0 if OK, -EPROTONOSUPPORT if the magic number or version number are
+ * not recognised or independent blocks are used, -EINVAL if the reserved
+ * fields are non-zero, or input is overrun, -EENOBUFS if the destination
+ * buffer is overrun, -EEPROTO if the compressed data causes an error in
+ * the decompression algorithm
+ */
+int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
+
+#endif
diff --git a/lib/lz4_wrapper.c b/lib/lz4_wrapper.c
index 1c68e67452..1e1e8d5085 100644
--- a/lib/lz4_wrapper.c
+++ b/lib/lz4_wrapper.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/test/compression.c b/test/compression.c
index 08fef59d0a..48dccc0e89 100644
--- a/test/compression.c
+++ b/test/compression.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 26/42] common: Move checkcpu() out of common.h

2019-11-12 Thread Simon Glass
This function belongs in cpu.h so move it over.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/powerpc/cpu/mpc83xx/cpu.c   |  1 +
 arch/powerpc/cpu/mpc8xx/cpu.c|  1 +
 arch/sh/cpu/sh4/cpu.c|  1 +
 arch/x86/cpu/broadwell/cpu_from_spl.c|  1 +
 arch/x86/cpu/coreboot/coreboot.c |  1 +
 arch/x86/cpu/efi/app.c   |  1 +
 arch/x86/cpu/efi/payload.c   |  1 +
 arch/x86/cpu/ivybridge/cpu.c |  1 +
 arch/x86/cpu/qemu/qemu.c |  1 +
 arch/x86/cpu/quark/quark.c   |  1 +
 arch/x86/cpu/slimbootloader/slimbootloader.c |  1 +
 arch/x86/cpu/tangier/tangier.c   |  1 +
 arch/x86/cpu/x86_64/cpu.c|  1 +
 arch/x86/lib/fsp/fsp_common.c|  1 +
 common/board_f.c |  1 +
 include/common.h |  1 -
 include/cpu_legacy.h | 10 ++
 17 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/cpu/mpc83xx/cpu.c b/arch/powerpc/cpu/mpc83xx/cpu.c
index 363c0ffd28..1c0d0d2632 100644
--- a/arch/powerpc/cpu/mpc83xx/cpu.c
+++ b/arch/powerpc/cpu/mpc83xx/cpu.c
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/cpu/mpc8xx/cpu.c b/arch/powerpc/cpu/mpc8xx/cpu.c
index 6ad86e9a1d..36af7c1612 100644
--- a/arch/powerpc/cpu/mpc8xx/cpu.c
+++ b/arch/powerpc/cpu/mpc8xx/cpu.c
@@ -17,6 +17,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/sh/cpu/sh4/cpu.c b/arch/sh/cpu/sh4/cpu.c
index a8b50a9ff5..d79e6ea71d 100644
--- a/arch/sh/cpu/sh4/cpu.c
+++ b/arch/sh/cpu/sh4/cpu.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/x86/cpu/broadwell/cpu_from_spl.c 
b/arch/x86/cpu/broadwell/cpu_from_spl.c
index c3d4a8d547..feb0732ee9 100644
--- a/arch/x86/cpu/broadwell/cpu_from_spl.c
+++ b/arch/x86/cpu/broadwell/cpu_from_spl.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/coreboot/coreboot.c b/arch/x86/cpu/coreboot/coreboot.c
index 9686f8ed5b..67cfcb72d7 100644
--- a/arch/x86/cpu/coreboot/coreboot.c
+++ b/arch/x86/cpu/coreboot/coreboot.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/efi/app.c b/arch/x86/cpu/efi/app.c
index ba7c02bd7e..34bdc40e39 100644
--- a/arch/x86/cpu/efi/app.c
+++ b/arch/x86/cpu/efi/app.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/x86/cpu/efi/payload.c b/arch/x86/cpu/efi/payload.c
index 225aef7bf6..019e312527 100644
--- a/arch/x86/cpu/efi/payload.c
+++ b/arch/x86/cpu/efi/payload.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/ivybridge/cpu.c b/arch/x86/cpu/ivybridge/cpu.c
index 6db9da81b7..3dffc1697e 100644
--- a/arch/x86/cpu/ivybridge/cpu.c
+++ b/arch/x86/cpu/ivybridge/cpu.c
@@ -11,6 +11,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 5e8b4f068e..c76868fa90 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/quark/quark.c b/arch/x86/cpu/quark/quark.c
index d39edb2271..f598666a6b 100644
--- a/arch/x86/cpu/quark/quark.c
+++ b/arch/x86/cpu/quark/quark.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/slimbootloader/slimbootloader.c 
b/arch/x86/cpu/slimbootloader/slimbootloader.c
index e6b174ca88..16dd4d7381 100644
--- a/arch/x86/cpu/slimbootloader/slimbootloader.c
+++ b/arch/x86/cpu/slimbootloader/slimbootloader.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/arch/x86/cpu/tangier/tangier.c b/arch/x86/cpu/tangier/tangier.c
index df2c600be3..a758ac4f1e 100644
--- a/arch/x86/cpu/tangier/tangier.c
+++ b/arch/x86/cpu/tangier/tangier.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 
 /*
diff --git a/arch/x86/cpu/x86_64/cpu.c b/arch/x86/cpu/x86_64/cpu.c
index 42abb23a9e..7d291f60f5 100644
--- a/arch/x86/cpu/x86_64/cpu.c
+++ b/arch/x86/cpu/x86_64/cpu.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 
 /*
diff --git a/arch/x86/lib/fsp/fsp_common.c b/arch/x86/lib/fsp/fsp_common.c
index 40ba866d77..89ad12d1f9 100644
--- a/arch/x86/lib/fsp/fsp_common.c
+++ b/arch/x86/lib/fsp/fsp_common.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/common/board_f.c b/common/board_f.c
index 01044452bf..5dcecd66d6 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/include/common.h b/include/common.h
index 

[U-Boot] [PATCH v3 30/42] common: Drop checkicache() and checkdcache()

2019-11-12 Thread Simon Glass
These are used by only one arch and only within a single file. Drop the
declarations from the common file.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/powerpc/cpu/mpc8xx/cpu.c | 130 +-
 include/common.h  |   2 -
 2 files changed, 65 insertions(+), 67 deletions(-)

diff --git a/arch/powerpc/cpu/mpc8xx/cpu.c b/arch/powerpc/cpu/mpc8xx/cpu.c
index 36af7c1612..787c1bdc11 100644
--- a/arch/powerpc/cpu/mpc8xx/cpu.c
+++ b/arch/powerpc/cpu/mpc8xx/cpu.c
@@ -35,70 +35,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static int check_CPU(long clock, uint pvr, uint immr)
-{
-   immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
-   uint k;
-   char buf[32];
-
-   /* the highest 16 bits should be 0x0050 for a 860 */
-
-   if (PVR_VER(pvr) != PVR_VER(PVR_8xx))
-   return -1;
-
-   k = (immr << 16) |
-   in_be16(>im_cpm.cp_dparam16[PROFF_REVNUM / sizeof(u16)]);
-
-   /*
-* Some boards use sockets so different CPUs can be used.
-* We have to check chip version in run time.
-*/
-   switch (k) {
-   /* MPC866P/MPC866T/MPC859T/MPC859DSL/MPC852T */
-   case 0x08010004:/* Rev. A.0 */
-   printf("MPC866xxxZPnnA");
-   break;
-   case 0x0803:/* Rev. 0.3 */
-   printf("MPC866xxxZPnn");
-   break;
-   case 0x0900:/* 870/875/880/885 */
-   puts("MPC885ZPnn");
-   break;
-
-   default:
-   printf("unknown MPC86x (0x%08x)", k);
-   break;
-   }
-
-   printf(" at %s MHz: ", strmhz(buf, clock));
-
-   print_size(checkicache(), " I-Cache ");
-   print_size(checkdcache(), " D-Cache");
-
-   /* do we have a FEC (860T/P or 852/859/866/885)? */
-
-   out_be32(>im_cpm.cp_fec.fec_addr_low, 0x12345678);
-   if (in_be32(>im_cpm.cp_fec.fec_addr_low) == 0x12345678)
-   printf(" FEC present");
-
-   putc('\n');
-
-   return 0;
-}
-
-/* - */
-
-int checkcpu(void)
-{
-   ulong clock = gd->cpu_clk;
-   uint immr = get_immr(); /* Return full IMMR contents */
-   uint pvr = get_pvr();
-
-   puts("CPU:   ");
-
-   return check_CPU(clock, pvr, immr);
-}
-
 /* - */
 /* L1 i-cache*/
 
@@ -143,7 +79,7 @@ int checkicache(void)
 /* L1 d-cache*/
 /* call with cache disabled  */
 
-int checkdcache(void)
+static int checkdcache(void)
 {
immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
memctl8xx_t __iomem *memctl = >im_memctl;
@@ -175,6 +111,70 @@ int checkdcache(void)
return lines << 4;
 };
 
+static int check_CPU(long clock, uint pvr, uint immr)
+{
+   immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
+   uint k;
+   char buf[32];
+
+   /* the highest 16 bits should be 0x0050 for a 860 */
+
+   if (PVR_VER(pvr) != PVR_VER(PVR_8xx))
+   return -1;
+
+   k = (immr << 16) |
+   in_be16(>im_cpm.cp_dparam16[PROFF_REVNUM / sizeof(u16)]);
+
+   /*
+* Some boards use sockets so different CPUs can be used.
+* We have to check chip version in run time.
+*/
+   switch (k) {
+   /* MPC866P/MPC866T/MPC859T/MPC859DSL/MPC852T */
+   case 0x08010004:/* Rev. A.0 */
+   printf("MPC866xxxZPnnA");
+   break;
+   case 0x0803:/* Rev. 0.3 */
+   printf("MPC866xxxZPnn");
+   break;
+   case 0x0900:/* 870/875/880/885 */
+   puts("MPC885ZPnn");
+   break;
+
+   default:
+   printf("unknown MPC86x (0x%08x)", k);
+   break;
+   }
+
+   printf(" at %s MHz: ", strmhz(buf, clock));
+
+   print_size(checkicache(), " I-Cache ");
+   print_size(checkdcache(), " D-Cache");
+
+   /* do we have a FEC (860T/P or 852/859/866/885)? */
+
+   out_be32(>im_cpm.cp_fec.fec_addr_low, 0x12345678);
+   if (in_be32(>im_cpm.cp_fec.fec_addr_low) == 0x12345678)
+   printf(" FEC present");
+
+   putc('\n');
+
+   return 0;
+}
+
+/* - */
+
+int checkcpu(void)
+{
+   ulong clock = gd->cpu_clk;
+   uint immr = get_immr(); /* Return full IMMR contents */
+   uint pvr = get_pvr();
+
+   puts("CPU:   ");
+
+   return check_CPU(clock, pvr, immr);
+}
+
 /* - */
 
 void upmconfig(uint upm, uint *table, uint 

[U-Boot] [PATCH v3 37/42] common: Move board_get_usable_ram_top() out of common.h

2019-11-12 Thread Simon Glass
Move this function into init.h which seems to be designed for this sort
of thing. Also update the header to declare struct global_data so that it
can be included without global_data.h being needed.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/mach-mvebu/arm64-common.c|  1 +
 arch/arm/mach-rockchip/sdram_common.c |  1 +
 arch/arm/mach-tegra/board2.c  |  1 +
 arch/mips/mach-jz47xx/jz4780/jz4780.c |  1 +
 arch/riscv/cpu/generic/dram.c |  1 +
 arch/x86/cpu/broadwell/sdram.c|  1 +
 arch/x86/cpu/coreboot/sdram.c |  1 +
 arch/x86/cpu/efi/payload.c|  1 +
 arch/x86/cpu/efi/sdram.c  |  1 +
 arch/x86/cpu/intel_common/mrc.c   |  1 +
 arch/x86/cpu/ivybridge/sdram.c|  1 +
 arch/x86/cpu/qemu/dram.c  |  1 +
 arch/x86/cpu/quark/dram.c |  1 +
 arch/x86/cpu/slimbootloader/sdram.c   |  1 +
 arch/x86/lib/fsp/fsp_dram.c   |  1 +
 arch/x86/lib/init_helpers.c   |  1 +
 board/armadeus/apf27/apf27.c  |  1 +
 board/imgtec/boston/ddr.c |  1 +
 board/menlo/m53menlo/m53menlo.c   |  1 +
 board/raspberrypi/rpi/rpi.c   |  1 +
 board/ti/am65x/evm.c  |  1 +
 board/ti/j721e/evm.c  |  1 +
 common/board_f.c  |  1 +
 drivers/video/fsl_dcu_fb.c|  1 +
 drivers/video/sunxi/sunxi_display.c   |  1 +
 include/common.h  | 11 ---
 include/init.h| 20 ++--
 lib/efi_loader/efi_memory.c   |  1 +
 28 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/arch/arm/mach-mvebu/arm64-common.c 
b/arch/arm/mach-mvebu/arm64-common.c
index aaf7b7c447..40b98dbf08 100644
--- a/arch/arm/mach-mvebu/arm64-common.c
+++ b/arch/arm/mach-mvebu/arm64-common.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-rockchip/sdram_common.c 
b/arch/arm/mach-rockchip/sdram_common.c
index 22a4aca940..74a1223532 100644
--- a/arch/arm/mach-rockchip/sdram_common.c
+++ b/arch/arm/mach-rockchip/sdram_common.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-tegra/board2.c b/arch/arm/mach-tegra/board2.c
index 07f54f0684..d3497a2673 100644
--- a/arch/arm/mach-tegra/board2.c
+++ b/arch/arm/mach-tegra/board2.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/mips/mach-jz47xx/jz4780/jz4780.c 
b/arch/mips/mach-jz47xx/jz4780/jz4780.c
index 0949cbc3d0..967fc41be4 100644
--- a/arch/mips/mach-jz47xx/jz4780/jz4780.c
+++ b/arch/mips/mach-jz47xx/jz4780/jz4780.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/riscv/cpu/generic/dram.c b/arch/riscv/cpu/generic/dram.c
index b7b1207235..1dc77efeca 100644
--- a/arch/riscv/cpu/generic/dram.c
+++ b/arch/riscv/cpu/generic/dram.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/arch/x86/cpu/broadwell/sdram.c b/arch/x86/cpu/broadwell/sdram.c
index b31d78c092..dfd8afc35f 100644
--- a/arch/x86/cpu/broadwell/sdram.c
+++ b/arch/x86/cpu/broadwell/sdram.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/coreboot/sdram.c b/arch/x86/cpu/coreboot/sdram.c
index 664817feff..27e859885e 100644
--- a/arch/x86/cpu/coreboot/sdram.c
+++ b/arch/x86/cpu/coreboot/sdram.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/x86/cpu/efi/payload.c b/arch/x86/cpu/efi/payload.c
index 019e312527..8f8a933194 100644
--- a/arch/x86/cpu/efi/payload.c
+++ b/arch/x86/cpu/efi/payload.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/efi/sdram.c b/arch/x86/cpu/efi/sdram.c
index a45525f842..3143c079ad 100644
--- a/arch/x86/cpu/efi/sdram.c
+++ b/arch/x86/cpu/efi/sdram.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/arch/x86/cpu/intel_common/mrc.c b/arch/x86/cpu/intel_common/mrc.c
index b35102a3f0..755670a847 100644
--- a/arch/x86/cpu/intel_common/mrc.c
+++ b/arch/x86/cpu/intel_common/mrc.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/ivybridge/sdram.c b/arch/x86/cpu/ivybridge/sdram.c
index 8a58d0383d..51ca4ad301 100644
--- a/arch/x86/cpu/ivybridge/sdram.c
+++ b/arch/x86/cpu/ivybridge/sdram.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/cpu/qemu/dram.c b/arch/x86/cpu/qemu/dram.c
index 6707b7b363..19d92f27d8 100644
--- a/arch/x86/cpu/qemu/dram.c
+++ b/arch/x86/cpu/qemu/dram.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/x86/cpu/quark/dram.c b/arch/x86/cpu/quark/dram.c
index 

[U-Boot] [PATCH v3 19/42] common: Move wait_ticks functions out of common.h

2019-11-12 Thread Simon Glass
This function belongs in time.h so move it over and add a comment.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Drop include in pxa2xx.c since this is for pxa_wait_ticks()
- Update comment to wait_ticks() to indicate it is an internal function

Changes in v2: None

 drivers/timer/mpc83xx_timer.c |  1 +
 include/common.h  |  1 -
 include/time.h| 10 ++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/timer/mpc83xx_timer.c b/drivers/timer/mpc83xx_timer.c
index dfbc8672b2..69949d5333 100644
--- a/drivers/timer/mpc83xx_timer.c
+++ b/drivers/timer/mpc83xx_timer.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/include/common.h b/include/common.h
index 20d143deb8..091b54787f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -286,7 +286,6 @@ int cleanup_before_linux_select(int flags);
 
 /* arch/$(ARCH)/lib/ticks.S */
 uint64_t get_ticks(void);
-void   wait_ticks(unsigned long);
 
 /* lib/uuid.c */
 #include 
diff --git a/include/time.h b/include/time.h
index a1bdefc164..31d386729e 100644
--- a/include/time.h
+++ b/include/time.h
@@ -86,4 +86,14 @@ ulong usec2ticks(unsigned long usec);
  */
 ulong ticks2usec(unsigned long ticks);
 
+/**
+ * wait_ticks() - waits a given number of ticks
+ *
+ * This is an internal function typically used to implement udelay() and
+ * similar. Normally you should use udelay() or mdelay() instead.
+ *
+ * @ticks: Number of ticks to wait
+ */
+void wait_ticks(unsigned long ticks);
+
 #endif /* _TIME_H */
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 21/42] common: Move timer_get_us() function out of common.h

2019-11-12 Thread Simon Glass
This function belongs in time.h so move it over and update the comment
style.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 include/common.h | 3 ---
 include/time.h   | 7 +++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/common.h b/include/common.h
index 091b54787f..e68bed6407 100644
--- a/include/common.h
+++ b/include/common.h
@@ -251,9 +251,6 @@ voidirq_install_handler(int, interrupt_handler_t *, 
void *);
 void   irq_free_handler   (int);
 void   reset_timer(void);
 
-/* Return value of monotonic microsecond timer */
-unsigned long timer_get_us(void);
-
 void   enable_interrupts  (void);
 intdisable_interrupts (void);
 
diff --git a/include/time.h b/include/time.h
index 31d386729e..875a2b293e 100644
--- a/include/time.h
+++ b/include/time.h
@@ -96,4 +96,11 @@ ulong ticks2usec(unsigned long ticks);
  */
 void wait_ticks(unsigned long ticks);
 
+/**
+ * timer_get_us() - Get monotonic microsecond timer
+ *
+ * @return value of monotonic microsecond timer
+ */
+unsigned long timer_get_us(void);
+
 #endif /* _TIME_H */
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 32/42] arm: powerpc: Tidy up code style for interrupt functions

2019-11-12 Thread Simon Glass
Remove the unwanted space before the bracket.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/cpu/arm11/cpu.c  |  2 +-
 arch/arm/cpu/arm920t/cpu.c|  2 +-
 arch/arm/cpu/arm926ejs/cpu.c  |  2 +-
 arch/arm/cpu/arm946es/cpu.c   |  2 +-
 arch/arm/cpu/sa1100/cpu.c |  2 +-
 arch/arm/lib/interrupts.c |  6 +++---
 arch/m68k/lib/interrupts.c|  8 
 arch/nios2/cpu/interrupts.c   | 14 +++---
 arch/powerpc/cpu/mpc83xx/cpu.c|  2 +-
 arch/powerpc/cpu/mpc83xx/interrupts.c |  6 +++---
 arch/powerpc/cpu/mpc86xx/interrupts.c |  2 +-
 arch/powerpc/lib/interrupts.c |  8 
 arch/sh/cpu/sh4/interrupts.c  |  6 +++---
 board/cobra5272/flash.c   |  8 
 14 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/arch/arm/cpu/arm11/cpu.c b/arch/arm/cpu/arm11/cpu.c
index a546ec21de..280622fe33 100644
--- a/arch/arm/cpu/arm11/cpu.c
+++ b/arch/arm/cpu/arm11/cpu.c
@@ -30,7 +30,7 @@ int cleanup_before_linux (void)
 * we turn off caches etc ...
 */
 
-   disable_interrupts ();
+   disable_interrupts();
 
/* turn off I/D-cache */
icache_disable();
diff --git a/arch/arm/cpu/arm920t/cpu.c b/arch/arm/cpu/arm920t/cpu.c
index a98c86eaf3..e632aa52f8 100644
--- a/arch/arm/cpu/arm920t/cpu.c
+++ b/arch/arm/cpu/arm920t/cpu.c
@@ -28,7 +28,7 @@ int cleanup_before_linux (void)
 * we turn off caches etc ...
 */
 
-   disable_interrupts ();
+   disable_interrupts();
 
/* turn off I/D-cache */
icache_disable();
diff --git a/arch/arm/cpu/arm926ejs/cpu.c b/arch/arm/cpu/arm926ejs/cpu.c
index 6d06fb758a..f4b27d93be 100644
--- a/arch/arm/cpu/arm926ejs/cpu.c
+++ b/arch/arm/cpu/arm926ejs/cpu.c
@@ -28,7 +28,7 @@ int cleanup_before_linux (void)
 * we turn off caches etc ...
 */
 
-   disable_interrupts ();
+   disable_interrupts();
 
 
/* turn off I/D-cache */
diff --git a/arch/arm/cpu/arm946es/cpu.c b/arch/arm/cpu/arm946es/cpu.c
index 0a78ffbae1..19b805096f 100644
--- a/arch/arm/cpu/arm946es/cpu.c
+++ b/arch/arm/cpu/arm946es/cpu.c
@@ -29,7 +29,7 @@ int cleanup_before_linux (void)
 * we turn off caches etc ...
 */
 
-   disable_interrupts ();
+   disable_interrupts();
 
/* ARM926E-S needs the protection unit enabled for the icache to have
 * been enabled  - left for possible later use
diff --git a/arch/arm/cpu/sa1100/cpu.c b/arch/arm/cpu/sa1100/cpu.c
index 8ef9f294f2..ec408564c1 100644
--- a/arch/arm/cpu/sa1100/cpu.c
+++ b/arch/arm/cpu/sa1100/cpu.c
@@ -30,7 +30,7 @@ int cleanup_before_linux (void)
 * just disable everything that can disturb booting linux
 */
 
-   disable_interrupts ();
+   disable_interrupts();
 
/* turn off I-cache */
icache_disable();
diff --git a/arch/arm/lib/interrupts.c b/arch/arm/lib/interrupts.c
index ee775ce5d2..e78ca56d25 100644
--- a/arch/arm/lib/interrupts.c
+++ b/arch/arm/lib/interrupts.c
@@ -25,7 +25,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-int interrupt_init (void)
+int interrupt_init(void)
 {
/*
 * setup up stacks if necessary
@@ -35,11 +35,11 @@ int interrupt_init (void)
return 0;
 }
 
-void enable_interrupts (void)
+void enable_interrupts(void)
 {
return;
 }
-int disable_interrupts (void)
+int disable_interrupts(void)
 {
return 0;
 }
diff --git a/arch/m68k/lib/interrupts.c b/arch/m68k/lib/interrupts.c
index 2d1c6136a1..85ae3b4ee0 100644
--- a/arch/m68k/lib/interrupts.c
+++ b/arch/m68k/lib/interrupts.c
@@ -42,7 +42,7 @@ static __inline__ void set_sr (unsigned short sr)
 /*
  * Install and free an interrupt handler
  */
-void irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
+void irq_install_handler(int vec, interrupt_handler_t * handler, void *arg)
 {
if ((vec < 0) || (vec >= NR_IRQS)) {
printf ("irq_install_handler: wrong interrupt vector %d\n",
@@ -54,7 +54,7 @@ void irq_install_handler (int vec, interrupt_handler_t * 
handler, void *arg)
irq_vecs[vec].arg = arg;
 }
 
-void irq_free_handler (int vec)
+void irq_free_handler(int vec)
 {
if ((vec < 0) || (vec >= NR_IRQS)) {
return;
@@ -64,7 +64,7 @@ void irq_free_handler (int vec)
irq_vecs[vec].arg = NULL;
 }
 
-void enable_interrupts (void)
+void enable_interrupts(void)
 {
unsigned short sr;
 
@@ -72,7 +72,7 @@ void enable_interrupts (void)
set_sr (sr & ~0x0700);
 }
 
-int disable_interrupts (void)
+int disable_interrupts(void)
 {
unsigned short sr;
 
diff --git a/arch/nios2/cpu/interrupts.c b/arch/nios2/cpu/interrupts.c
index 6b5d0724e3..96c3020935 100644
--- a/arch/nios2/cpu/interrupts.c
+++ b/arch/nios2/cpu/interrupts.c
@@ -23,7 +23,7 @@ structirq_action {
 
 static struct irq_action vecs[32];
 
-int disable_interrupts (void)
+int 

[U-Boot] [PATCH v3 34/42] common: Move enable/disable_interrupts out of common.h

2019-11-12 Thread Simon Glass
Move these two functions into the irq_funcs.h header file. Also move
interrupt_handler_t as this is used by the irq_install_handler() function.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Rename irq_legacy to irq_func to avoid the 'legacy' label
- Update commit message

Changes in v2: None

 arch/arc/lib/bootm.c  | 1 +
 arch/arm/cpu/arm11/cpu.c  | 1 +
 arch/arm/cpu/arm920t/cpu.c| 1 +
 arch/arm/cpu/arm926ejs/cpu.c  | 1 +
 arch/arm/cpu/arm946es/cpu.c   | 1 +
 arch/arm/cpu/armv7/cpu.c  | 1 +
 arch/arm/cpu/armv7m/cpu.c | 1 +
 arch/arm/cpu/armv8/cpu.c  | 1 +
 arch/arm/cpu/pxa/pxa2xx.c | 1 +
 arch/arm/cpu/sa1100/cpu.c | 1 +
 arch/arm/lib/reset.c  | 1 +
 arch/arm/mach-tegra/cmd_enterrcm.c| 1 +
 arch/microblaze/include/asm/microblaze_intc.h | 2 ++
 arch/nds32/cpu/n1213/ag101/cpu.c  | 1 +
 arch/nios2/cpu/cpu.c  | 1 +
 arch/nios2/lib/bootm.c| 1 +
 arch/powerpc/cpu/mpc83xx/cpu.c| 1 +
 arch/powerpc/cpu/mpc83xx/ecc.c| 1 +
 arch/powerpc/cpu/mpc85xx/cpu.c| 1 +
 arch/riscv/cpu/generic/cpu.c  | 1 +
 arch/sh/cpu/sh4/cpu.c | 1 +
 arch/sh/lib/zimageboot.c  | 1 +
 arch/x86/lib/zimage.c | 1 +
 board/bosch/shc/board.c   | 1 +
 board/cobra5272/flash.c   | 1 +
 board/freescale/b4860qds/b4860qds.c   | 1 +
 board/freescale/common/vid.c  | 1 +
 board/freescale/m5253demo/flash.c | 1 +
 board/freescale/t4qds/t4240qds.c  | 1 +
 board/synopsys/hsdk/hsdk.c| 1 +
 cmd/booti.c   | 1 +
 cmd/bootz.c   | 1 +
 cmd/fdc.c | 1 +
 cmd/irq.c | 1 +
 common/board_r.c  | 1 +
 common/bootm.c| 1 +
 drivers/firmware/psci.c   | 1 +
 drivers/mtd/pic32_flash.c | 1 +
 include/common.h  | 6 --
 include/exports.h | 2 ++
 include/irq_func.h| 9 -
 lib/efi_loader/efi_boottime.c | 1 +
 post/lib_powerpc/andi.c   | 1 +
 post/lib_powerpc/b.c  | 1 +
 post/lib_powerpc/cmp.c| 1 +
 post/lib_powerpc/cmpi.c   | 1 +
 post/lib_powerpc/complex.c| 1 +
 post/lib_powerpc/cr.c | 1 +
 post/lib_powerpc/load.c   | 1 +
 post/lib_powerpc/multi.c  | 1 +
 post/lib_powerpc/rlwimi.c | 1 +
 post/lib_powerpc/rlwinm.c | 1 +
 post/lib_powerpc/rlwnm.c  | 1 +
 post/lib_powerpc/srawi.c  | 1 +
 post/lib_powerpc/store.c  | 1 +
 post/lib_powerpc/string.c | 1 +
 post/lib_powerpc/three.c  | 1 +
 post/lib_powerpc/threei.c | 1 +
 post/lib_powerpc/threex.c | 1 +
 post/lib_powerpc/two.c| 1 +
 post/lib_powerpc/twox.c   | 1 +
 61 files changed, 69 insertions(+), 7 deletions(-)

diff --git a/arch/arc/lib/bootm.c b/arch/arc/lib/bootm.c
index 254e0284b3..d38c18ef8f 100644
--- a/arch/arc/lib/bootm.c
+++ b/arch/arc/lib/bootm.c
@@ -3,6 +3,7 @@
  * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
  */
 
+#include 
 #include 
 #include 
 
diff --git a/arch/arm/cpu/arm11/cpu.c b/arch/arm/cpu/arm11/cpu.c
index 280622fe33..8db2510a49 100644
--- a/arch/arm/cpu/arm11/cpu.c
+++ b/arch/arm/cpu/arm11/cpu.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 static void cache_flush(void);
diff --git a/arch/arm/cpu/arm920t/cpu.c b/arch/arm/cpu/arm920t/cpu.c
index e632aa52f8..7469a661c9 100644
--- a/arch/arm/cpu/arm920t/cpu.c
+++ b/arch/arm/cpu/arm920t/cpu.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 static void cache_flush(void);
diff --git a/arch/arm/cpu/arm926ejs/cpu.c b/arch/arm/cpu/arm926ejs/cpu.c
index f4b27d93be..84e91c5e64 100644
--- a/arch/arm/cpu/arm926ejs/cpu.c
+++ b/arch/arm/cpu/arm926ejs/cpu.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 static void cache_flush(void);
diff --git a/arch/arm/cpu/arm946es/cpu.c b/arch/arm/cpu/arm946es/cpu.c
index 19b805096f..263343c944 100644
--- a/arch/arm/cpu/arm946es/cpu.c
+++ b/arch/arm/cpu/arm946es/cpu.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
diff --git 

[U-Boot] [PATCH v3 42/42] common: Move old EEPROM functions into a new header

2019-11-12 Thread Simon Glass
These functions do not use driver model but are still used. Move them to a
new eeprom.h header file.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Rename eeprom_legacy.h to eeprom.h since this may not be legacy code
- Update the commit message

Changes in v2: None

 board/atmel/common/mac_eeprom.c   |  1 +
 board/compulab/common/eeprom.c|  1 +
 board/corscience/tricorder/tricorder-eeprom.c |  1 +
 board/dhelectronics/dh_imx6/dh_imx6.c |  1 +
 board/freescale/mpc8323erdb/mpc8323erdb.c |  1 +
 board/kosagi/novena/novena.c  |  1 +
 board/phytec/phycore_rk3288/phycore-rk3288.c  |  1 +
 board/rockchip/tinker_rk3288/tinker-rk3288.c  |  1 +
 board/softing/vining_fpga/socfpga.c   |  1 +
 board/ti/am43xx/board.c   |  1 +
 board/ti/common/board_detect.c|  1 +
 board/ti/ks2_evm/board_k2g.c  |  1 +
 cmd/eeprom.c  |  1 +
 drivers/misc/i2c_eeprom.c |  1 +
 drivers/mtd/mw_eeprom.c   |  1 +
 drivers/rtc/rv3029.c  |  1 +
 env/eeprom.c  |  1 +
 include/common.h  | 15 
 include/eeprom.h  | 24 +++
 19 files changed, 41 insertions(+), 15 deletions(-)
 create mode 100644 include/eeprom.h

diff --git a/board/atmel/common/mac_eeprom.c b/board/atmel/common/mac_eeprom.c
index 83a7778e99..050aa51ee1 100644
--- a/board/atmel/common/mac_eeprom.c
+++ b/board/atmel/common/mac_eeprom.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/compulab/common/eeprom.c b/board/compulab/common/eeprom.c
index 81f69d3850..5206cf5c0a 100644
--- a/board/compulab/common/eeprom.c
+++ b/board/compulab/common/eeprom.c
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/corscience/tricorder/tricorder-eeprom.c 
b/board/corscience/tricorder/tricorder-eeprom.c
index b28189dafd..23c2ea9186 100644
--- a/board/corscience/tricorder/tricorder-eeprom.c
+++ b/board/corscience/tricorder/tricorder-eeprom.c
@@ -5,6 +5,7 @@
  * Andreas Bießmann 
  */
 #include 
+#include 
 #include 
 #include 
 
diff --git a/board/dhelectronics/dh_imx6/dh_imx6.c 
b/board/dhelectronics/dh_imx6/dh_imx6.c
index 037be01f8b..33ce7e8ff1 100644
--- a/board/dhelectronics/dh_imx6/dh_imx6.c
+++ b/board/dhelectronics/dh_imx6/dh_imx6.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/freescale/mpc8323erdb/mpc8323erdb.c 
b/board/freescale/mpc8323erdb/mpc8323erdb.c
index cbec8a44e4..6c47cb2b38 100644
--- a/board/freescale/mpc8323erdb/mpc8323erdb.c
+++ b/board/freescale/mpc8323erdb/mpc8323erdb.c
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/kosagi/novena/novena.c b/board/kosagi/novena/novena.c
index e4f0e81004..7eb833cf02 100644
--- a/board/kosagi/novena/novena.c
+++ b/board/kosagi/novena/novena.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/phytec/phycore_rk3288/phycore-rk3288.c 
b/board/phytec/phycore_rk3288/phycore-rk3288.c
index dac59cd55d..039ed0f1bc 100644
--- a/board/phytec/phycore_rk3288/phycore-rk3288.c
+++ b/board/phytec/phycore_rk3288/phycore-rk3288.c
@@ -4,6 +4,7 @@
  * Author: Wadim Egorov 
  */
 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/rockchip/tinker_rk3288/tinker-rk3288.c 
b/board/rockchip/tinker_rk3288/tinker-rk3288.c
index 93e9d2f465..9efbdc1a3c 100644
--- a/board/rockchip/tinker_rk3288/tinker-rk3288.c
+++ b/board/rockchip/tinker_rk3288/tinker-rk3288.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/softing/vining_fpga/socfpga.c 
b/board/softing/vining_fpga/socfpga.c
index d70c22f48f..5a88b6c8ad 100644
--- a/board/softing/vining_fpga/socfpga.c
+++ b/board/softing/vining_fpga/socfpga.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c
index 9353830969..d12f1ebfdf 100644
--- a/board/ti/am43xx/board.c
+++ b/board/ti/am43xx/board.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c
index bc89cc57bd..564d2f7046 100644
--- a/board/ti/common/board_detect.c
+++ b/board/ti/common/board_detect.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/ti/ks2_evm/board_k2g.c b/board/ti/ks2_evm/board_k2g.c
index a0fd03a39f..920d0d3420 100644
--- a/board/ti/ks2_evm/board_k2g.c
+++ b/board/ti/ks2_evm/board_k2g.c
@@ -6,6 +6,7 @@
  * Texas Instruments Incorporated, 
  */
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/cmd/eeprom.c b/cmd/eeprom.c
index 19953df082..4a1569baf3 100644
--- 

[U-Boot] [PATCH v3 38/42] common: Move some board functions out of common.h

2019-11-12 Thread Simon Glass
A number of board function belong in init.h with the others. Move them.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/cpu/armv8/fsl-layerscape/soc.c   | 1 +
 arch/arm/mach-imx/mx6/opos6ul.c   | 1 +
 arch/arm/mach-imx/mx6/soc.c   | 1 +
 arch/arm/mach-imx/mx7ulp/soc.c| 1 +
 arch/arm/mach-meson/board-common.c| 1 +
 arch/arm/mach-rockchip/board.c| 1 +
 arch/arm/mach-rockchip/rk3288/rk3288.c| 1 +
 arch/arm/mach-uniphier/board_late_init.c  | 1 +
 arch/arm/mach-zynqmp/spl.c| 1 +
 arch/powerpc/cpu/mpc85xx/cpu_init.c   | 1 +
 board/Arcturus/ucp1020/ucp1020.c  | 1 +
 board/BuR/brppt1/board.c  | 1 +
 board/BuR/brsmarc1/board.c| 1 +
 board/BuR/brxre1/board.c  | 1 +
 board/CZ.NIC/turris_mox/turris_mox.c  | 1 +
 board/CZ.NIC/turris_omnia/turris_omnia.c  | 1 +
 board/Marvell/mvebu_armada-8k/board.c | 1 +
 board/advantech/dms-ba16/dms-ba16.c   | 1 +
 board/aristainetos/aristainetos-v2.c  | 1 +
 board/armadeus/opos6uldev/board.c | 3 ++-
 board/atmark-techno/armadillo-800eva/armadillo-800eva.c   | 1 +
 board/atmel/at91sam9x5ek/at91sam9x5ek.c   | 1 +
 board/atmel/sama5d27_som1_ek/sama5d27_som1_ek.c   | 1 +
 board/atmel/sama5d2_icp/sama5d2_icp.c | 1 +
 board/atmel/sama5d2_ptc_ek/sama5d2_ptc_ek.c   | 1 +
 board/atmel/sama5d2_xplained/sama5d2_xplained.c   | 1 +
 board/atmel/sama5d3_xplained/sama5d3_xplained.c   | 1 +
 board/atmel/sama5d3xek/sama5d3xek.c   | 1 +
 board/atmel/sama5d4_xplained/sama5d4_xplained.c   | 1 +
 board/atmel/sama5d4ek/sama5d4ek.c | 1 +
 board/beckhoff/mx53cx9020/mx53cx9020.c| 1 +
 board/birdland/bav335x/board.c| 1 +
 board/bluewater/gurnard/gurnard.c | 1 +
 board/bosch/shc/board.c   | 1 +
 board/broadcom/bcmstb/bcmstb.c| 1 +
 board/cadence/xtfpga/xtfpga.c | 1 +
 board/ccv/xpress/xpress.c | 1 +
 board/chipspark/popmetal_rk3288/popmetal-rk3288.c | 1 +
 board/compulab/cl-som-imx7/cl-som-imx7.c  | 1 +
 board/compulab/cm_fx6/cm_fx6.c| 1 +
 board/congatec/cgtqmx6eval/cgtqmx6eval.c  | 1 +
 .../congatec/conga-qeval20-qa3-e3845/conga-qeval20-qa3.c  | 1 +
 board/coreboot/coreboot/coreboot.c| 1 +
 board/cssi/MCR3000/MCR3000.c  | 1 +
 board/dfi/dfi-bt700/dfi-bt700.c   | 1 +
 board/dhelectronics/dh_imx6/dh_imx6.c | 1 +
 board/eets/pdu001/board.c | 1 +
 board/efi/efi-x86_payload/payload.c   | 1 +
 board/el/el6x/el6x.c  | 1 +
 board/embest/mx6boards/mx6boards.c| 1 +
 board/emulation/qemu-riscv/qemu-riscv.c   | 1 +
 board/engicam/common/board.c  | 1 +
 board/freescale/b4860qds/b4860qds.c   | 1 +
 board/freescale/bsc9132qds/bsc9132qds.c   | 1 +
 board/freescale/c29xpcie/c29xpcie.c   | 1 +
 board/freescale/corenet_ds/corenet_ds.c   | 1 +
 board/freescale/imx8mq_evk/imx8mq_evk.c   | 1 +
 board/freescale/imx8qm_mek/imx8qm_mek.c   | 1 +
 board/freescale/imx8qxp_mek/imx8qxp_mek.c | 1 +
 board/freescale/ls1021aiot/ls1021aiot.c   | 1 +
 board/freescale/ls1021aqds/ls1021aqds.c   | 1 +
 board/freescale/ls1021atsn/ls1021atsn.c   | 1 +
 board/freescale/ls1021atwr/ls1021atwr.c   | 1 +
 board/freescale/mpc8313erdb/mpc8313erdb.c | 1 +
 board/freescale/mpc832xemds/mpc832xemds.c | 1 +
 board/freescale/mpc837xemds/mpc837xemds.c | 1 +
 board/freescale/mpc8536ds/mpc8536ds.c | 1 +
 board/freescale/mpc8569mds/mpc8569mds.c   | 1 +
 board/freescale/mpc8572ds/mpc8572ds.c | 1 +
 board/freescale/mx25pdk/mx25pdk.c | 1 +
 board/freescale/mx31pdk/mx31pdk.c | 1 +
 board/freescale/mx35pdk/mx35pdk.c | 1 +
 board/freescale/mx51evk/mx51evk.c | 1 +
 board/freescale/mx53evk/mx53evk.c | 1 +
 board/freescale/mx53loco/mx53loco.c

[U-Boot] [PATCH v3 27/42] common: Move some SMP functions out of common.h

2019-11-12 Thread Simon Glass
These functions belong in cpu_legacy.h so move them over.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/cpu/armv7/ls102xa/cpu.c| 1 +
 arch/arm/cpu/armv7/virt-v7.c| 1 +
 arch/arm/lib/bootm.c| 1 +
 arch/arm/mach-uniphier/arm32/psci.c | 1 +
 board/armltd/vexpress/vexpress_common.c | 1 +
 board/broadcom/bcm_ep/board.c   | 1 +
 board/samsung/arndale/arndale.c | 1 +
 board/synopsys/axs10x/axs10x.c  | 1 +
 board/xilinx/zynqmp/zynqmp.c| 1 +
 cmd/elf.c   | 1 +
 include/common.h| 3 ---
 include/cpu_legacy.h| 3 +++
 12 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/armv7/ls102xa/cpu.c b/arch/arm/cpu/armv7/ls102xa/cpu.c
index ec9984db79..0c61f31516 100644
--- a/arch/arm/cpu/armv7/ls102xa/cpu.c
+++ b/arch/arm/cpu/armv7/ls102xa/cpu.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/armv7/virt-v7.c b/arch/arm/cpu/armv7/virt-v7.c
index be14eb9376..1f01a7fd19 100644
--- a/arch/arm/cpu/armv7/virt-v7.c
+++ b/arch/arm/cpu/armv7/virt-v7.c
@@ -9,6 +9,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 488358a331..99e545e6d1 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -13,6 +13,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-uniphier/arm32/psci.c 
b/arch/arm/mach-uniphier/arm32/psci.c
index ef35923f6a..7f9c9d1fe5 100644
--- a/arch/arm/mach-uniphier/arm32/psci.c
+++ b/arch/arm/mach-uniphier/arm32/psci.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/armltd/vexpress/vexpress_common.c 
b/board/armltd/vexpress/vexpress_common.c
index 30b9dbbe8a..25da4c3904 100644
--- a/board/armltd/vexpress/vexpress_common.c
+++ b/board/armltd/vexpress/vexpress_common.c
@@ -16,6 +16,7 @@
  * Philippe Robin, 
  */
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/broadcom/bcm_ep/board.c b/board/broadcom/bcm_ep/board.c
index b2469dcb52..0c3aa3b05f 100644
--- a/board/broadcom/bcm_ep/board.c
+++ b/board/broadcom/bcm_ep/board.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/samsung/arndale/arndale.c b/board/samsung/arndale/arndale.c
index d06ab8f3c0..0d33f5c449 100644
--- a/board/samsung/arndale/arndale.c
+++ b/board/samsung/arndale/arndale.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/synopsys/axs10x/axs10x.c b/board/synopsys/axs10x/axs10x.c
index 7c4fcf281c..bd39d0c7d8 100644
--- a/board/synopsys/axs10x/axs10x.c
+++ b/board/synopsys/axs10x/axs10x.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index b94936474d..104c81b06f 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/cmd/elf.c b/cmd/elf.c
index 538562fda5..690c61791d 100644
--- a/cmd/elf.c
+++ b/cmd/elf.c
@@ -15,6 +15,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/include/common.h b/include/common.h
index 96bb42ce71..3f6a95d7e0 100644
--- a/include/common.h
+++ b/include/common.h
@@ -212,9 +212,6 @@ voidreset_cpu (ulong addr);
 void ft_cpu_setup(void *blob, bd_t *bd);
 void ft_pci_setup(void *blob, bd_t *bd);
 
-void smp_set_core_boot_addr(unsigned long addr, int corenr);
-void smp_kick_all_cpus(void);
-
 /* $(CPU)/speed.c */
 intget_clocks (void);
 ulong  get_bus_freq  (ulong);
diff --git a/include/cpu_legacy.h b/include/cpu_legacy.h
index 03feaa63e9..1741f7f7a6 100644
--- a/include/cpu_legacy.h
+++ b/include/cpu_legacy.h
@@ -49,4 +49,7 @@ int is_core_valid(unsigned int core);
  */
 int checkcpu(void);
 
+void smp_set_core_boot_addr(unsigned long addr, int corenr);
+void smp_kick_all_cpus(void);
+
 #endif
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 28/42] arm: powerpc: Tidy up code style for cache functions

2019-11-12 Thread Simon Glass
Remove the unwanted space before the bracket.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/lib/cache-cp15.c| 12 ++--
 arch/microblaze/cpu/cache.c  | 18 +++---
 board/armltd/integrator/integrator.c |  2 +-
 board/cobra5272/flash.c  | 12 ++--
 include/common.h |  2 +-
 post/lib_powerpc/cpu.c   |  6 +++---
 6 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/arch/arm/lib/cache-cp15.c b/arch/arm/lib/cache-cp15.c
index 47c223917a..8ca8e48380 100644
--- a/arch/arm/lib/cache-cp15.c
+++ b/arch/arm/lib/cache-cp15.c
@@ -253,17 +253,17 @@ static void cache_disable(uint32_t cache_bit)
 #endif
 
 #if CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
-void icache_enable (void)
+void icache_enable(void)
 {
return;
 }
 
-void icache_disable (void)
+void icache_disable(void)
 {
return;
 }
 
-int icache_status (void)
+int icache_status(void)
 {
return 0;   /* always off */
 }
@@ -285,17 +285,17 @@ int icache_status(void)
 #endif
 
 #if CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
-void dcache_enable (void)
+void dcache_enable(void)
 {
return;
 }
 
-void dcache_disable (void)
+void dcache_disable(void)
 {
return;
 }
 
-int dcache_status (void)
+int dcache_status(void)
 {
return 0;   /* always off */
 }
diff --git a/arch/microblaze/cpu/cache.c b/arch/microblaze/cpu/cache.c
index eebeb37830..94114555ff 100644
--- a/arch/microblaze/cpu/cache.c
+++ b/arch/microblaze/cpu/cache.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 
-int dcache_status (void)
+int dcache_status(void)
 {
int i = 0;
int mask = 0x80;
@@ -18,7 +18,7 @@ int dcache_status (void)
return i;
 }
 
-int icache_status (void)
+int icache_status(void)
 {
int i = 0;
int mask = 0x20;
@@ -28,28 +28,32 @@ int icache_status (void)
return i;
 }
 
-void   icache_enable (void) {
+void icache_enable(void)
+{
MSRSET(0x20);
 }
 
-void   icache_disable(void) {
+void icache_disable(void)
+{
/* we are not generate ICACHE size -> flush whole cache */
flush_cache(0, 32768);
MSRCLR(0x20);
 }
 
-void   dcache_enable (void) {
+void dcache_enable(void)
+{
MSRSET(0x80);
 }
 
-void   dcache_disable(void) {
+void dcache_disable(void)
+{
 #ifdef XILINX_USE_DCACHE
flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
 #endif
MSRCLR(0x80);
 }
 
-void flush_cache (ulong addr, ulong size)
+void flush_cache(ulong addr, ulong size)
 {
int i;
for (i = 0; i < size; i += 4)
diff --git a/board/armltd/integrator/integrator.c 
b/board/armltd/integrator/integrator.c
index 0a2baa7297..f0fbe2b417 100644
--- a/board/armltd/integrator/integrator.c
+++ b/board/armltd/integrator/integrator.c
@@ -109,7 +109,7 @@ extern void cm_remap(void);
writel(SC_CTRL_FLASHVPP | SC_CTRL_FLASHWP, SC_CTRLS);
 #endif
 
-   icache_enable ();
+   icache_enable();
 
return 0;
 }
diff --git a/board/cobra5272/flash.c b/board/cobra5272/flash.c
index e5edc2a040..9bf824889a 100644
--- a/board/cobra5272/flash.c
+++ b/board/cobra5272/flash.c
@@ -164,8 +164,8 @@ int flash_erase (flash_info_t * info, int s_first, int 
s_last)
 * chip is in programming mode.
 */
 
-   cflag = icache_status ();
-   icache_disable ();
+   cflag = icache_status();
+   icache_disable();
iflag = disable_interrupts ();
 
printf ("\n");
@@ -237,7 +237,7 @@ int flash_erase (flash_info_t * info, int s_first, int 
s_last)
enable_interrupts ();
 
if (cflag)
-   icache_enable ();
+   icache_enable();
 
return rc;
 }
@@ -267,8 +267,8 @@ static int write_word (flash_info_t * info, ulong dest, 
ulong data)
 * chip is in programming mode.
 */
 
-   cflag = icache_status ();
-   icache_disable ();
+   cflag = icache_status();
+   icache_disable();
iflag = disable_interrupts ();
 
MEM_FLASH_ADDR1 = CMD_UNLOCK1;
@@ -303,7 +303,7 @@ static int write_word (flash_info_t * info, ulong dest, 
ulong data)
enable_interrupts ();
 
if (cflag)
-   icache_enable ();
+   icache_enable();
 
return rc;
 }
diff --git a/include/common.h b/include/common.h
index 3f6a95d7e0..82b1abe698 100644
--- a/include/common.h
+++ b/include/common.h
@@ -189,7 +189,7 @@ int testdram(void);
 inticache_status (void);
 void   icache_enable (void);
 void   icache_disable(void);
-intdcache_status (void);
+intdcache_status(void);
 void   dcache_enable (void);
 void   dcache_disable(void);
 void   mmu_disable(void);
diff --git a/post/lib_powerpc/cpu.c b/post/lib_powerpc/cpu.c
index 109be38e16..6713039330 100644
--- a/post/lib_powerpc/cpu.c
+++ b/post/lib_powerpc/cpu.c
@@ -57,12 +57,12 @@ ulong cpu_post_makecr (long v)
 
 int cpu_post_test 

[U-Boot] [PATCH v3 13/42] common: Move env_get_ip() to net.h

2019-11-12 Thread Simon Glass
This function relates to networking, so move it out of the common.h
header file.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 include/common.h |  4 
 include/net.h| 21 -
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/include/common.h b/include/common.h
index f993e4bef3..4fda40cc1d 100644
--- a/include/common.h
+++ b/include/common.h
@@ -319,10 +319,6 @@ intserial_printf (const char *fmt, ...)
 
 /* lib/net_utils.c */
 #include 
-static inline struct in_addr env_get_ip(char *var)
-{
-   return string_to_ip(env_get(var));
-}
 
 #include 
 
diff --git a/include/net.h b/include/net.h
index d8d187d8af..11eca1bc6c 100644
--- a/include/net.h
+++ b/include/net.h
@@ -829,7 +829,13 @@ static inline void net_random_ethaddr(uchar *addr)
 /* Convert an IP address to a string */
 void ip_to_string(struct in_addr x, char *s);
 
-/* Convert a string to ip address */
+/**
+ * string_to_ip() - Convert a string to ip address
+ *
+ * @s: String to conver, in the format format a.b.c.d, where each value is a
+ * decimal number from 0 to 255
+ * @return IP address, or 0 if invalid
+ */
 struct in_addr string_to_ip(const char *s);
 
 /* Convert a VLAN id to a string */
@@ -887,4 +893,17 @@ int update_tftp(ulong addr, char *interface, char 
*devstring);
  */
 void eth_parse_enetaddr(const char *addr, uint8_t *enetaddr);
 
+/**
+ * env_get_ip() - Convert an environment value to to an ip address
+ *
+ * @var: Environment variable to convert. The value of this variable must be
+ * in the format format a.b.c.d, where each value is a decimal number from
+ * 0 to 255
+ * @return IP address, or 0 if invalid
+ */
+static inline struct in_addr env_get_ip(char *var)
+{
+   return string_to_ip(env_get(var));
+}
+
 #endif /* __NET_H__ */
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 20/42] arm: pxa: Drop pxa_wait_ticks()

2019-11-12 Thread Simon Glass
This function has a similar name to the common wait_ticks(). It is only
used in one place and seems small enough to drop.

Inline it.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Add new patch to inline pxa_wait_ticks()

Changes in v2: None

 arch/arm/cpu/pxa/pxa2xx.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/arm/cpu/pxa/pxa2xx.c b/arch/arm/cpu/pxa/pxa2xx.c
index 0b28f0a3ef..14fe307c1a 100644
--- a/arch/arm/cpu/pxa/pxa2xx.c
+++ b/arch/arm/cpu/pxa/pxa2xx.c
@@ -39,13 +39,6 @@ int cleanup_before_linux(void)
return 0;
 }
 
-void pxa_wait_ticks(int ticks)
-{
-   writel(0, OSCR);
-   while (readl(OSCR) < ticks)
-   asm volatile("" : : : "memory");
-}
-
 inline void writelrb(uint32_t val, uint32_t addr)
 {
writel(val, addr);
@@ -136,8 +129,11 @@ void pxa2xx_dram_init(void)
 
writelrb(CONFIG_SYS_MDCNFG_VAL &
~(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3), MDCNFG);
+
/* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
-   pxa_wait_ticks(0x300);
+   writel(0, OSCR);
+   while (readl(OSCR) < 0x300)
+   asm volatile("" : : : "memory");
 
/*
 * 8) Trigger a number (usually 8) refresh cycles by attempting
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 16/42] common: Move serial functions out of common.h

2019-11-12 Thread Simon Glass
These functions belong in serial.h so move them over.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/cpu/arm926ejs/mxs/spl_boot.c  | 1 +
 board/amarula/vyasa-rk3288/vyasa-rk3288.c  | 1 +
 board/astro/mcf5373l/mcf5373l.c| 1 +
 board/birdland/bav335x/board.c | 1 +
 board/bticino/mamoj/spl.c  | 1 +
 board/cssi/MCR3000/MCR3000.c   | 1 +
 board/engicam/common/spl.c | 1 +
 board/esd/meesc/meesc.c| 1 +
 board/gumstix/pepper/board.c   | 1 +
 board/isee/igep003x/board.c| 1 +
 board/isee/igep00x0/spl.c  | 1 +
 board/liebherr/display5/spl.c  | 1 +
 board/liebherr/mccmon6/mccmon6.c   | 1 +
 board/liebherr/mccmon6/spl.c   | 1 +
 board/logicpd/am3517evm/am3517evm.c| 1 +
 board/logicpd/imx6/imx6logic.c | 1 +
 board/logicpd/omap3som/omap3logic.c| 1 +
 board/overo/common.c   | 1 +
 board/siemens/common/board.c   | 1 +
 board/silica/pengwyn/board.c   | 1 +
 board/st/stm32f746-disco/stm32f746-disco.c | 1 +
 board/tcl/sl50/board.c | 1 +
 board/ti/am57xx/board.c| 1 +
 board/ti/beagle/beagle.c   | 1 +
 board/ti/dra7xx/evm.c  | 1 +
 board/ti/evm/evm.c | 1 +
 board/vscom/baltos/board.c | 1 +
 cmd/load.c | 1 +
 common/board_f.c   | 1 +
 common/kgdb_stubs.c| 1 +
 common/lcd_console.c   | 1 +
 common/spl/spl.c   | 1 +
 include/common.h   | 9 -
 include/serial.h   | 8 
 34 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/arch/arm/cpu/arm926ejs/mxs/spl_boot.c 
b/arch/arm/cpu/arm926ejs/mxs/spl_boot.c
index cb361ac65c..5b3b51ce15 100644
--- a/arch/arm/cpu/arm926ejs/mxs/spl_boot.c
+++ b/arch/arm/cpu/arm926ejs/mxs/spl_boot.c
@@ -8,6 +8,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/amarula/vyasa-rk3288/vyasa-rk3288.c 
b/board/amarula/vyasa-rk3288/vyasa-rk3288.c
index baf197c485..92e0698c53 100644
--- a/board/amarula/vyasa-rk3288/vyasa-rk3288.c
+++ b/board/amarula/vyasa-rk3288/vyasa-rk3288.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 
 #ifndef CONFIG_TPL_BUILD
 
diff --git a/board/astro/mcf5373l/mcf5373l.c b/board/astro/mcf5373l/mcf5373l.c
index 759ff49562..db157a83c8 100644
--- a/board/astro/mcf5373l/mcf5373l.c
+++ b/board/astro/mcf5373l/mcf5373l.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/birdland/bav335x/board.c b/board/birdland/bav335x/board.c
index 8811583ac6..1f3f44a867 100644
--- a/board/birdland/bav335x/board.c
+++ b/board/birdland/bav335x/board.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/bticino/mamoj/spl.c b/board/bticino/mamoj/spl.c
index c53bdce0ce..620e4d1de0 100644
--- a/board/bticino/mamoj/spl.c
+++ b/board/bticino/mamoj/spl.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 
 #include 
diff --git a/board/cssi/MCR3000/MCR3000.c b/board/cssi/MCR3000/MCR3000.c
index 445b84c180..dcd2c1c975 100644
--- a/board/cssi/MCR3000/MCR3000.c
+++ b/board/cssi/MCR3000/MCR3000.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/engicam/common/spl.c b/board/engicam/common/spl.c
index 4d293c8032..a9820a9028 100644
--- a/board/engicam/common/spl.c
+++ b/board/engicam/common/spl.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 
 #include 
diff --git a/board/esd/meesc/meesc.c b/board/esd/meesc/meesc.c
index 221048a91f..4271b0db19 100644
--- a/board/esd/meesc/meesc.c
+++ b/board/esd/meesc/meesc.c
@@ -11,6 +11,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/gumstix/pepper/board.c b/board/gumstix/pepper/board.c
index f5beb8c940..65e5e1e60f 100644
--- a/board/gumstix/pepper/board.c
+++ b/board/gumstix/pepper/board.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/isee/igep003x/board.c b/board/isee/igep003x/board.c
index a8c2b121a4..d59121296e 100644
--- a/board/isee/igep003x/board.c
+++ b/board/isee/igep003x/board.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/isee/igep00x0/spl.c b/board/isee/igep00x0/spl.c
index e092e1a418..f814fe1354 100644
--- a/board/isee/igep00x0/spl.c
+++ b/board/isee/igep00x0/spl.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/liebherr/display5/spl.c b/board/liebherr/display5/spl.c
index 311edaf939..e845edf068 100644
--- 

[U-Boot] [PATCH v3 09/42] spl: bootcount: Move code out of header file

2019-11-12 Thread Simon Glass
It is not good practice to write code in a header file. If it is included
multiple times then the code can cause duplicate functions.

Move the bootcount_store() and bootcount_load() functions into SPL.

Note: bootcount is a bit strange in that it uses driver model but does not
define proper drivers. This should be fixed.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 common/spl/spl.c| 11 +++
 include/bootcount.h |  4 
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index cc5507f757..a2ef13a41c 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -830,3 +830,14 @@ ulong spl_relocate_stack_gd(void)
return 0;
 #endif
 }
+
+#if defined(CONFIG_BOOTCOUNT_LIMIT) && !defined(CONFIG_SPL_BOOTCOUNT_LIMIT)
+void bootcount_store(ulong a)
+{
+}
+
+ulong bootcount_load(void)
+{
+   return 0;
+}
+#endif
diff --git a/include/bootcount.h b/include/bootcount.h
index 8fa8cf8218..a26a385233 100644
--- a/include/bootcount.h
+++ b/include/bootcount.h
@@ -127,10 +127,6 @@ static inline void bootcount_inc(void)
 #endif /* !CONFIG_SPL_BUILD */
 }
 
-#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_SPL_BOOTCOUNT_LIMIT)
-void bootcount_store(ulong a) {};
-ulong bootcount_load(void) { return 0; }
-#endif /* CONFIG_SPL_BUILD && !CONFIG_SPL_BOOTCOUNT_LIMIT */
 #else
 static inline int bootcount_error(void) { return 0; }
 static inline void bootcount_inc(void) {}
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 12/42] Move strtomhz() to vsprintf.h

2019-11-12 Thread Simon Glass
At present this function sits in its own file but it does not really
justify it. There are similar string functions in vsprintf.h, so move it
there. Also add the missing function comment.

Use the vsprintf.h include file explicitly where needed.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Put copyright info into vsprintf.c

Changes in v2: None

 arch/arc/lib/cpu.c|  1 +
 arch/arm/cpu/arm926ejs/mx25/generic.c |  1 +
 arch/arm/cpu/arm926ejs/mx27/generic.c |  1 +
 arch/arm/cpu/armv7/ls102xa/cpu.c  |  1 +
 arch/arm/cpu/armv8/fsl-layerscape/cpu.c   |  1 +
 arch/arm/mach-at91/arm926ejs/cpu.c|  1 +
 arch/arm/mach-at91/armv7/cpu.c|  1 +
 arch/m68k/cpu/mcf5227x/cpu.c  |  1 +
 arch/m68k/cpu/mcf523x/cpu.c   |  1 +
 arch/m68k/cpu/mcf52x2/cpu.c   |  1 +
 arch/m68k/cpu/mcf530x/cpu.c   |  1 +
 arch/m68k/cpu/mcf532x/cpu.c   |  1 +
 arch/m68k/cpu/mcf5445x/cpu.c  |  1 +
 arch/m68k/cpu/mcf547x_8x/cpu.c|  1 +
 arch/powerpc/cpu/mpc83xx/cpu.c|  1 +
 arch/powerpc/cpu/mpc83xx/spd_sdram.c  |  1 +
 arch/powerpc/cpu/mpc83xx/speed.c  |  1 +
 arch/powerpc/cpu/mpc85xx/cpu.c|  1 +
 arch/powerpc/cpu/mpc86xx/cpu.c|  1 +
 arch/powerpc/cpu/mpc8xx/cpu.c |  1 +
 arch/xtensa/cpu/cpu.c |  1 +
 board/Arcturus/ucp1020/ddr.c  |  1 +
 board/atmel/at91sam9261ek/at91sam9261ek.c |  1 +
 board/atmel/at91sam9263ek/at91sam9263ek.c |  1 +
 .../atmel/at91sam9m10g45ek/at91sam9m10g45ek.c |  1 +
 board/atmel/at91sam9n12ek/at91sam9n12ek.c |  1 +
 board/atmel/at91sam9rlek/at91sam9rlek.c   |  1 +
 board/atmel/common/video_display.c|  1 +
 board/esd/meesc/meesc.c   |  1 +
 board/freescale/bsc9131rdb/ddr.c  |  1 +
 board/freescale/bsc9132qds/ddr.c  |  1 +
 board/freescale/corenet_ds/ddr.c  |  1 +
 board/freescale/ls1043ardb/ddr.c  |  1 +
 board/freescale/mpc8541cds/mpc8541cds.c   |  1 +
 board/freescale/mpc8548cds/mpc8548cds.c   |  1 +
 board/freescale/mpc8555cds/mpc8555cds.c   |  1 +
 board/freescale/p1010rdb/ddr.c|  1 +
 board/freescale/p1_p2_rdb_pc/ddr.c|  1 +
 board/freescale/p1_twr/ddr.c  |  1 +
 board/mini-box/picosam9g45/picosam9g45.c  |  1 +
 board/ronetix/pm9261/pm9261.c |  1 +
 cmd/bdinfo.c  |  1 +
 drivers/clk/clk_stm32mp1.c|  1 +
 drivers/clk/mpc83xx_clk.c |  1 +
 drivers/cpu/mpc83xx_cpu.c |  1 +
 include/common.h  |  3 ---
 include/vsprintf.h| 10 +
 lib/Makefile  |  4 ++--
 lib/strmhz.c  | 21 ---
 lib/vsprintf.c| 19 +
 50 files changed, 76 insertions(+), 26 deletions(-)
 delete mode 100644 lib/strmhz.c

diff --git a/arch/arc/lib/cpu.c b/arch/arc/lib/cpu.c
index 01cca95d5b..83246550ec 100644
--- a/arch/arc/lib/cpu.c
+++ b/arch/arc/lib/cpu.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
diff --git a/arch/arm/cpu/arm926ejs/mx25/generic.c 
b/arch/arm/cpu/arm926ejs/mx25/generic.c
index 5fcf06ae1a..eeb61d0d10 100644
--- a/arch/arm/cpu/arm926ejs/mx25/generic.c
+++ b/arch/arm/cpu/arm926ejs/mx25/generic.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/arm926ejs/mx27/generic.c 
b/arch/arm/cpu/arm926ejs/mx27/generic.c
index 08b1b4de71..9bed0e91be 100644
--- a/arch/arm/cpu/arm926ejs/mx27/generic.c
+++ b/arch/arm/cpu/arm926ejs/mx27/generic.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/armv7/ls102xa/cpu.c b/arch/arm/cpu/armv7/ls102xa/cpu.c
index 9ccfe1042c..ec9984db79 100644
--- a/arch/arm/cpu/armv7/ls102xa/cpu.c
+++ b/arch/arm/cpu/armv7/ls102xa/cpu.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c 
b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
index 83a3319321..59d03b167c 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-at91/arm926ejs/cpu.c 
b/arch/arm/mach-at91/arm926ejs/cpu.c
index 6f5aa4274b..e9b4e06595 100644
--- a/arch/arm/mach-at91/arm926ejs/cpu.c
+++ b/arch/arm/mach-at91/arm926ejs/cpu.c
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-at91/armv7/cpu.c b/arch/arm/mach-at91/armv7/cpu.c
index 

[U-Boot] [PATCH v3 29/42] common: Move some cache and MMU functions out of common.h

2019-11-12 Thread Simon Glass
These functions belong in cpu_legacy.h. Another option would be cache.h
but that code uses driver model and we have not moved these cache
functions to use driver model. Since they are CPU-related it seems
reasonable to put them here.

Move them over.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arc/lib/cache.c|  1 +
 arch/arm/cpu/arm11/cpu.c|  1 +
 arch/arm/cpu/arm920t/cpu.c  |  1 +
 arch/arm/cpu/arm926ejs/armada100/cpu.c  |  1 +
 arch/arm/cpu/arm926ejs/cache.c  |  1 +
 arch/arm/cpu/arm926ejs/cpu.c|  1 +
 arch/arm/cpu/arm926ejs/spear/spr_misc.c |  1 +
 arch/arm/cpu/arm946es/cpu.c |  1 +
 arch/arm/cpu/armv7/cpu.c|  1 +
 arch/arm/cpu/armv7/exception_level.c|  1 +
 arch/arm/cpu/armv7/iproc-common/hwinit-common.c |  1 +
 arch/arm/cpu/armv7/kona-common/hwinit-common.c  |  1 +
 arch/arm/cpu/armv7/mpu_v7r.c|  1 +
 arch/arm/cpu/armv7/vf610/generic.c  |  1 +
 arch/arm/cpu/armv7m/cache.c |  1 +
 arch/arm/cpu/armv7m/cpu.c   |  1 +
 arch/arm/cpu/armv8/cache_v8.c   |  1 +
 arch/arm/cpu/armv8/cpu.c|  1 +
 arch/arm/cpu/armv8/exception_level.c|  1 +
 arch/arm/cpu/armv8/fsl-layerscape/spl.c |  1 +
 arch/arm/cpu/pxa/pxa2xx.c   |  1 +
 arch/arm/cpu/sa1100/cpu.c   |  1 +
 arch/arm/lib/cache-cp15.c   |  1 +
 arch/arm/mach-at91/armv7/cpu.c  |  1 +
 arch/arm/mach-bcm283x/init.c|  1 +
 arch/arm/mach-exynos/soc.c  |  1 +
 arch/arm/mach-imx/cache.c   |  1 +
 arch/arm/mach-imx/imx8/cpu.c|  1 +
 arch/arm/mach-imx/imx8m/soc.c   |  1 +
 arch/arm/mach-imx/mx5/soc.c |  1 +
 arch/arm/mach-keystone/init.c   |  1 +
 arch/arm/mach-mediatek/cpu.c|  1 +
 arch/arm/mach-mvebu/armada8k/cpu.c  |  1 +
 arch/arm/mach-mvebu/cpu.c   |  1 +
 arch/arm/mach-omap2/omap-cache.c|  1 +
 arch/arm/mach-orion5x/cpu.c |  1 +
 arch/arm/mach-rmobile/cpu_info.c|  1 +
 arch/arm/mach-rmobile/memmap-gen3.c |  1 +
 arch/arm/mach-rockchip/board.c  |  1 +
 arch/arm/mach-s5pc1xx/cache.c   |  1 +
 arch/arm/mach-socfpga/misc.c|  1 +
 arch/arm/mach-socfpga/spl_a10.c |  1 +
 arch/arm/mach-stm32mp/cpu.c |  1 +
 arch/arm/mach-sunxi/board.c |  1 +
 arch/arm/mach-tegra/board.c |  1 +
 arch/arm/mach-uniphier/arm32/cache-uniphier.c   |  1 +
 arch/arm/mach-zynq/cpu.c|  1 +
 arch/m68k/cpu/mcf5227x/cpu_init.c   |  1 +
 arch/m68k/cpu/mcf523x/cpu_init.c|  1 +
 arch/m68k/cpu/mcf52x2/cpu_init.c|  1 +
 arch/m68k/cpu/mcf530x/cpu_init.c|  1 +
 arch/m68k/cpu/mcf532x/cpu_init.c|  1 +
 arch/m68k/cpu/mcf5445x/cpu_init.c   |  1 +
 arch/m68k/cpu/mcf547x_8x/cpu_init.c |  1 +
 arch/m68k/lib/cache.c   |  1 +
 arch/microblaze/cpu/cache.c |  1 +
 arch/mips/lib/cache.c   |  1 +
 arch/nds32/cpu/n1213/ae3xx/cpu.c|  1 +
 arch/nds32/cpu/n1213/ag101/cpu.c|  1 +
 arch/nds32/lib/cache.c  |  1 +
 arch/nios2/lib/cache.c  |  1 +
 arch/powerpc/cpu/mpc83xx/spd_sdram.c|  1 +
 arch/powerpc/cpu/mpc8xx/cache.c |  1 +
 arch/riscv/cpu/ax25/cache.c |  1 +
 arch/riscv/cpu/ax25/cpu.c   |  1 +
 arch/riscv/lib/cache.c  |  1 +
 arch/sh/cpu/sh4/cache.c |  1 +
 arch/x86/cpu/cpu.c  |  1 +
 arch/x86/cpu/i386/cpu.c |  1 +
 arch/x86/cpu/mtrr.c |  1 +
 arch/x86/cpu/x86_64/cpu.c   |  1 +
 arch/x86/lib/spl.c  |  1 +
 arch/xtensa/lib/cache.c |  1 +
 board/armltd/integrator/integrator.c|  1 +
 board/cirrus/edb93xx/edb93xx.c  |  1 +
 board/cobra5272/flash.c |  1 +
 board/highbank/highbank.c   |  1 +
 board/st/stih410-b2260/board.c  |  1 +
 board/synopsys/hsdk/hsdk.c  |  1 +
 board/syteco/zmx25/zmx25.c  |  1 +
 board/toradex/colibri_pxa270/colibri_pxa270.c   |  1 +
 board/xilinx/zynqmp/cmds.c  |  1 +
 cmd/cache.c |  1 +
 cmd/ti/ddr3.c   

[U-Boot] [PATCH v3 07/42] crc: Fix code style with crc functions

2019-11-12 Thread Simon Glass
Some of these have a space before the bracket. Drop it to fix the style.
Add some missing function comments while here.

Note that u32 and u8 cannot be used here since crc.h is included on the
host side.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 cmd/i2c.c|  2 +-
 include/u-boot/crc.h | 75 +++-
 lib/crc32.c  |  4 +--
 tools/envcrc.c   |  4 +--
 4 files changed, 73 insertions(+), 12 deletions(-)

diff --git a/cmd/i2c.c b/cmd/i2c.c
index e0f8ece597..038f97c261 100644
--- a/cmd/i2c.c
+++ b/cmd/i2c.c
@@ -768,7 +768,7 @@ static int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int 
argc, char * const argv[]
 #endif
if (ret)
err++;
-   crc = crc32 (crc, , 1);
+   crc = crc32(crc, , 1);
addr++;
}
if (err > 0)
diff --git a/include/u-boot/crc.h b/include/u-boot/crc.h
index b42bcda2b3..1086d2168c 100644
--- a/include/u-boot/crc.h
+++ b/include/u-boot/crc.h
@@ -38,9 +38,47 @@ void crc16_ccitt_wd_buf(const uint8_t *in, uint len,
uint8_t *out, uint chunk_sz);
 
 /* lib/crc32.c */
-uint32_t crc32 (uint32_t, const unsigned char *, uint);
-uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
-uint32_t crc32_no_comp (uint32_t, const unsigned char *, uint);
+
+/**
+ * crc32 - Calculate the CRC32 for a block of data
+ *
+ * @crc: Input crc to chain from a previous calculution (use 0 to start a new
+ * calculation)
+ * @buf: Bytes to checksum
+ * @len: Number of bytes to checksum
+ * @return checksum value
+ */
+uint32_t crc32(uint32_t crc, const unsigned char *buf, uint len);
+
+/**
+ * crc32_wd - Calculate the CRC32 for a block of data (watchdog version)
+ *
+ * This checksums the data @chunk_sz bytes at a time, calling WATCHDOG_RESET()
+ * after each chunk, to prevent the watchdog from firing.
+ *
+ * @crc: Input crc to chain from a previous calculution (use 0 to start a new
+ * calculation)
+ * @buf: Bytes to checksum
+ * @len: Number of bytes to checksum
+ * @chunk_sz: Chunk size to use between watchdog resets
+ * @return checksum
+ */
+uint32_t crc32_wd(uint32_t crc, const unsigned char *buf, uint len,
+ uint chunk_sz);
+
+/**
+ * crc32_no_comp - Calculate the CRC32 for a block of data (no one's 
compliment)
+ *
+ * This version uses a different algorithm which doesn't use one's compliment.
+ * JFFS2 (and other things?) use this.
+ *
+ * @crc: Input crc to chain from a previous calculution (use 0 to start a new
+ * calculation)
+ * @buf: Bytes to checksum
+ * @len: Number of bytes to checksum
+ * @return checksum value
+ */
+uint32_t crc32_no_comp(uint32_t crc, const unsigned char *buf, uint len);
 
 /**
  * crc32_wd_buf - Perform CRC32 on a buffer and return result in buffer
@@ -50,11 +88,34 @@ uint32_t crc32_no_comp (uint32_t, const unsigned char *, 
uint);
  * @output:Place to put checksum result (4 bytes)
  * @chunk_sz:  Trigger watchdog after processing this many bytes
  */
-void crc32_wd_buf(const unsigned char *input, uint ilen,
-   unsigned char *output, uint chunk_sz);
+void crc32_wd_buf(const uint8_t *input, uint ilen, uint8_t *output,
+ uint chunk_sz);
 
 /* lib/crc32c.c */
-void crc32c_init(uint32_t *, uint32_t);
-uint32_t crc32c_cal(uint32_t, const char *, int, uint32_t *);
+
+/**
+ * crc32c_init() - Set up a the CRC32 table
+ *
+ * This sets up 256-item table to aid in CRC32 calculation
+ *
+ * @crc32c_table: Place to put table
+ * @pol: polynomial to use
+ */
+void crc32c_init(uint32_t *crc32c_table, uint32_t pol);
+
+/**
+ * crc32c_cal() - Perform CRC32 on a buffer given a table
+ *
+ * This algorithm uses the table (set up by crc32c_init() to speed up
+ * processing.
+ *
+ * @crc: Previous crc (use 0 at start)
+ * @data: Data bytes to checksum
+ * @length: Number of bytes to process
+ * @crc32c_table:: CRC table
+ * @return checksum value
+ */
+uint32_t crc32c_cal(uint32_t crc, const char *data, int length,
+   uint32_t *crc32c_table);
 
 #endif /* _UBOOT_CRC_H */
diff --git a/lib/crc32.c b/lib/crc32.c
index eee21f8d73..dc7e183f18 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -244,12 +244,12 @@ uint32_t crc32_wd(uint32_t crc, const unsigned char *buf, 
uInt len,
chunk = end - curr;
if (chunk > chunk_sz)
chunk = chunk_sz;
-   crc = crc32 (crc, curr, chunk);
+   crc = crc32(crc, curr, chunk);
curr += chunk;
WATCHDOG_RESET ();
}
 #else
-   crc = crc32 (crc, buf, len);
+   crc = crc32(crc, buf, len);
 #endif
 
return crc;
diff --git a/tools/envcrc.c b/tools/envcrc.c
index 672ef4d675..09b49b49f9 100644
--- a/tools/envcrc.c
+++ b/tools/envcrc.c
@@ -64,7 +64,7 @@ extern unsigned int env_size;
 extern env_t embedded_environment;
 #endif /* CONFIG_BUILD_ENVCRC */
 
-extern 

[U-Boot] [PATCH v3 18/42] common: Move some time functions out of common.h

2019-11-12 Thread Simon Glass
These functions belong in time.h so move them over and add comments.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/cpu/armv7/ls102xa/timer.c|  1 +
 arch/arm/cpu/armv8/generic_timer.c|  1 +
 arch/arm/mach-imx/syscounter.c|  1 +
 arch/arm/mach-imx/timer.c |  1 +
 arch/m68k/lib/time.c  |  1 +
 arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c |  1 +
 arch/powerpc/cpu/mpc8xxx/srio.c   |  1 +
 arch/powerpc/lib/time.c   |  1 +
 drivers/crypto/fsl/jr.c   |  1 +
 drivers/i2c/fsl_i2c.c |  1 +
 include/common.h  |  4 
 include/time.h| 16 
 12 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/arch/arm/cpu/armv7/ls102xa/timer.c 
b/arch/arm/cpu/armv7/ls102xa/timer.c
index e79360ada8..a5f4e31ac7 100644
--- a/arch/arm/cpu/armv7/ls102xa/timer.c
+++ b/arch/arm/cpu/armv7/ls102xa/timer.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/armv8/generic_timer.c 
b/arch/arm/cpu/armv8/generic_timer.c
index c1706dcec1..46e63294fe 100644
--- a/arch/arm/cpu/armv8/generic_timer.c
+++ b/arch/arm/cpu/armv8/generic_timer.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/arch/arm/mach-imx/syscounter.c b/arch/arm/mach-imx/syscounter.c
index c888a93938..5a292c3964 100644
--- a/arch/arm/mach-imx/syscounter.c
+++ b/arch/arm/mach-imx/syscounter.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-imx/timer.c b/arch/arm/mach-imx/timer.c
index ed5eb1c8a7..5fe5c51f6a 100644
--- a/arch/arm/mach-imx/timer.c
+++ b/arch/arm/mach-imx/timer.c
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/m68k/lib/time.c b/arch/m68k/lib/time.c
index a6345a0bc9..c76c5fedc9 100644
--- a/arch/m68k/lib/time.c
+++ b/arch/m68k/lib/time.c
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c 
b/arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c
index fcfa730233..ebdcd29c13 100644
--- a/arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c
+++ b/arch/powerpc/cpu/mpc85xx/fsl_corenet_serdes.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #ifdef CONFIG_SYS_P4080_ERRATUM_SERDES8
 #include 
 #endif
diff --git a/arch/powerpc/cpu/mpc8xxx/srio.c b/arch/powerpc/cpu/mpc8xxx/srio.c
index ea7dac6e66..a1f9403559 100644
--- a/arch/powerpc/cpu/mpc8xxx/srio.c
+++ b/arch/powerpc/cpu/mpc8xxx/srio.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/lib/time.c b/arch/powerpc/lib/time.c
index a22a73abfa..e1494fa129 100644
--- a/arch/powerpc/lib/time.c
+++ b/arch/powerpc/lib/time.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 
 /* - */
diff --git a/drivers/crypto/fsl/jr.c b/drivers/crypto/fsl/jr.c
index 3121762364..1ea9db6850 100644
--- a/drivers/crypto/fsl/jr.c
+++ b/drivers/crypto/fsl/jr.c
@@ -11,6 +11,7 @@
 #include "jr.h"
 #include "jobdesc.h"
 #include "desc_constr.h"
+#include 
 #ifdef CONFIG_FSL_CORENET
 #include 
 #endif
diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c
index bf8d52d5ad..bbbd6ef5bf 100644
--- a/drivers/i2c/fsl_i2c.c
+++ b/drivers/i2c/fsl_i2c.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include/* Functional interface */
+#include 
 #include 
 #include/* HW definitions */
 #include 
diff --git a/include/common.h b/include/common.h
index 1e77ed393e..20d143deb8 100644
--- a/include/common.h
+++ b/include/common.h
@@ -288,10 +288,6 @@ int cleanup_before_linux_select(int flags);
 uint64_t get_ticks(void);
 void   wait_ticks(unsigned long);
 
-/* arch/$(ARCH)/lib/time.c */
-ulong  usec2ticks(unsigned long usec);
-ulong  ticks2usec(unsigned long ticks);
-
 /* lib/uuid.c */
 #include 
 
diff --git a/include/time.h b/include/time.h
index a1149522ed..a1bdefc164 100644
--- a/include/time.h
+++ b/include/time.h
@@ -70,4 +70,20 @@ uint64_t usec_to_tick(unsigned long usec);
(time_after_eq(a,b) && \
 time_before(a,c))
 
+/**
+ * usec2ticks() - Convert microseconds to internal ticks
+ *
+ * @usec: Value of microseconds to convert
+ * @return Corresponding internal ticks value, calculated using get_tbclk()
+ */
+ulong usec2ticks(unsigned long usec);
+
+/**
+ * ticks2usec() - Convert internal ticks to microseconds
+ *
+ * @ticks: Value of ticks to convert
+ * @return Corresponding microseconds value, calculated using get_tbclk()
+ */
+ulong ticks2usec(unsigned long ticks);
+
 #endif /* _TIME_H */
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de

[U-Boot] [PATCH v3 14/42] serial: usb: Correct the usbtty_...() prototypes

2019-11-12 Thread Simon Glass
The function declarations in serial.h are not in sync with what is
currently used in usbtty. Fix this by updating the header and including
it, to help catch future such problems.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 drivers/serial/usbtty.c |  1 +
 include/serial.h| 18 ++
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c
index 76d9c8a3a6..f1c1a260da 100644
--- a/drivers/serial/usbtty.c
+++ b/drivers/serial/usbtty.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "usbtty.h"
diff --git a/include/serial.h b/include/serial.h
index c1368c68b6..38a1cc99ae 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -50,18 +50,20 @@ extern void serial_reinit_all(void);
 /* For usbtty */
 #ifdef CONFIG_USB_TTY
 
-extern int usbtty_getc(void);
-extern void usbtty_putc(const char c);
-extern void usbtty_puts(const char *str);
-extern int usbtty_tstc(void);
+struct stdio_dev;
+
+int usbtty_getc(struct stdio_dev *dev);
+void usbtty_putc(struct stdio_dev *dev, const char c);
+void usbtty_puts(struct stdio_dev *dev, const char *str);
+int usbtty_tstc(struct stdio_dev *dev);
 
 #else
 
 /* stubs */
-#define usbtty_getc() 0
-#define usbtty_putc(a)
-#define usbtty_puts(a)
-#define usbtty_tstc() 0
+#define usbtty_getc(dev) 0
+#define usbtty_putc(dev, a)
+#define usbtty_puts(dev, a)
+#define usbtty_tstc(dev) 0
 
 #endif /* CONFIG_USB_TTY */
 
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 24/42] common: Move some CPU functions out of common.h

2019-11-12 Thread Simon Glass
These functions belong in cpu_legacy.h since they do not use driver model.
Move them over. Don't bother adding comments since these functions should
be deleted.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 arch/arm/cpu/armv8/fsl-layerscape/cpu.c   |  1 +
 .../armv8/fsl-layerscape/fsl_lsch2_speed.c|  1 +
 .../armv8/fsl-layerscape/fsl_lsch3_speed.c|  1 +
 arch/arm/cpu/armv8/s32v234/cpu.c  |  1 +
 arch/powerpc/cpu/mpc85xx/speed.c  |  1 +
 arch/powerpc/cpu/mpc86xx/cpu.c|  1 +
 arch/powerpc/cpu/mpc8xxx/cpu.c|  1 +
 arch/powerpc/cpu/mpc8xxx/fdt.c|  1 +
 board/freescale/qemu-ppce500/qemu-ppce500.c   |  1 +
 include/common.h  | 20 ---
 include/cpu_legacy.h  | 19 ++
 11 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c 
b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
index 374fde6b65..e4e0ac888b 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/fsl_lsch2_speed.c 
b/arch/arm/cpu/armv8/fsl-layerscape/fsl_lsch2_speed.c
index df4df9aca7..500c06642b 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/fsl_lsch2_speed.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/fsl_lsch2_speed.c
@@ -5,6 +5,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/fsl_lsch3_speed.c 
b/arch/arm/cpu/armv8/fsl-layerscape/fsl_lsch3_speed.c
index bbd550b036..795528107e 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/fsl_lsch3_speed.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/fsl_lsch3_speed.c
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/cpu/armv8/s32v234/cpu.c b/arch/arm/cpu/armv8/s32v234/cpu.c
index b4cb67a66a..bc4b8bf86f 100644
--- a/arch/arm/cpu/armv8/s32v234/cpu.c
+++ b/arch/arm/cpu/armv8/s32v234/cpu.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/cpu/mpc85xx/speed.c b/arch/powerpc/cpu/mpc85xx/speed.c
index acc2f2bb81..c6026f3381 100644
--- a/arch/powerpc/cpu/mpc85xx/speed.c
+++ b/arch/powerpc/cpu/mpc85xx/speed.c
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/cpu/mpc86xx/cpu.c b/arch/powerpc/cpu/mpc86xx/cpu.c
index 1c3c78217c..5ee3a56b47 100644
--- a/arch/powerpc/cpu/mpc86xx/cpu.c
+++ b/arch/powerpc/cpu/mpc86xx/cpu.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/cpu/mpc8xxx/cpu.c b/arch/powerpc/cpu/mpc8xxx/cpu.c
index 467eac4a2e..333dfa3090 100644
--- a/arch/powerpc/cpu/mpc8xxx/cpu.c
+++ b/arch/powerpc/cpu/mpc8xxx/cpu.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/cpu/mpc8xxx/fdt.c b/arch/powerpc/cpu/mpc8xxx/fdt.c
index 0d877c43be..40ee46c24a 100644
--- a/arch/powerpc/cpu/mpc8xxx/fdt.c
+++ b/arch/powerpc/cpu/mpc8xxx/fdt.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/freescale/qemu-ppce500/qemu-ppce500.c 
b/board/freescale/qemu-ppce500/qemu-ppce500.c
index fb36d8366c..6814bed27c 100644
--- a/board/freescale/qemu-ppce500/qemu-ppce500.c
+++ b/board/freescale/qemu-ppce500/qemu-ppce500.c
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/include/common.h b/include/common.h
index 992675100d..4de05032b2 100644
--- a/include/common.h
+++ b/include/common.h
@@ -203,26 +203,6 @@ void   relocate_code(ulong, gd_t *, ulong) 
__attribute__ ((noreturn));
 ulong  get_endaddr   (void);
 void   trap_init (ulong);
 
-/* $(CPU)/cpu.c */
-static inline int cpumask_next(int cpu, unsigned int mask)
-{
-   for (cpu++; !((1 << cpu) & mask); cpu++)
-   ;
-
-   return cpu;
-}
-
-#define for_each_cpu(iter, cpu, num_cpus, mask) \
-   for (iter = 0, cpu = cpumask_next(-1, mask); \
-   iter < num_cpus; \
-   iter++, cpu = cpumask_next(cpu, mask)) \
-
-intcpu_numcores  (void);
-intcpu_num_dspcores(void);
-u32cpu_mask  (void);
-u32cpu_dsp_mask(void);
-intis_core_valid (unsigned int);
-
 void s_init(void);
 
 intcheckcpu  (void);
diff --git a/include/cpu_legacy.h b/include/cpu_legacy.h
index a99b69b976..75b93bc11e 100644
--- a/include/cpu_legacy.h
+++ b/include/cpu_legacy.h
@@ -20,4 +20,23 @@ int cpu_reset(u32 nr);
 int cpu_disable(u32 nr);
 int cpu_release(u32 nr, int argc, char * const argv[]);
 
+static inline int cpumask_next(int cpu, unsigned int mask)
+{
+   for (cpu++; !((1 << cpu) & mask); cpu++)
+   ;
+
+   return cpu;
+}
+
+#define for_each_cpu(iter, cpu, num_cpus, mask) \
+   for (iter = 0, cpu = 

[U-Boot] [PATCH v3 15/42] common: Move serial_printf() to the serial header

2019-11-12 Thread Simon Glass
Move this function header to serial.h since this function is clearly
related to serial. The function itself stays in console.c since we don't
have a single serial file. DM and non-DM each has a separate file so we
would have to either create a new common serial file, or repeat the
function in both serial.c and serial-uclass.c, neither of which seem
worthwhile.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 drivers/usb/gadget/core.c   |  1 +
 drivers/usb/gadget/designware_udc.c |  1 +
 drivers/usb/gadget/ep0.c|  3 ++-
 drivers/usb/musb-new/omap2430.c |  1 +
 drivers/usb/musb/musb_udc.c |  1 +
 drivers/usb/musb/omap3.c|  1 +
 include/common.h|  7 ---
 include/serial.h| 11 +++
 8 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/gadget/core.c b/drivers/usb/gadget/core.c
index ffaf161fb7..7e1e51db96 100644
--- a/drivers/usb/gadget/core.c
+++ b/drivers/usb/gadget/core.c
@@ -16,6 +16,7 @@
  */
 
 #include 
+#include 
 #include 
 
 #define MAX_INTERFACES 2
diff --git a/drivers/usb/gadget/designware_udc.c 
b/drivers/usb/gadget/designware_udc.c
index 432f312cee..70c5c678c3 100644
--- a/drivers/usb/gadget/designware_udc.c
+++ b/drivers/usb/gadget/designware_udc.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 
 #include 
diff --git a/drivers/usb/gadget/ep0.c b/drivers/usb/gadget/ep0.c
index a36d9ec03d..6fabee24ce 100644
--- a/drivers/usb/gadget/ep0.c
+++ b/drivers/usb/gadget/ep0.c
@@ -37,6 +37,7 @@
  */
 
 #include 
+#include 
 #include 
 
 #if 0
@@ -581,7 +582,7 @@ int ep0_recv_setup (struct urb *urb)
device->interface = le16_to_cpu (request->wIndex);
device->alternate = le16_to_cpu (request->wValue);
/*dbg_ep0(2, "set interface: %d alternate: %d", 
device->interface, device->alternate); */
-   serial_printf ("DEVICE_SET_INTERFACE.. event?\n");
+   serial_printf("DEVICE_SET_INTERFACE.. event?\n");
return 0;
 
case USB_REQ_GET_STATUS:
diff --git a/drivers/usb/musb-new/omap2430.c b/drivers/usb/musb-new/omap2430.c
index cca1653f1e..05059ce3cb 100644
--- a/drivers/usb/musb-new/omap2430.c
+++ b/drivers/usb/musb-new/omap2430.c
@@ -10,6 +10,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/usb/musb/musb_udc.c b/drivers/usb/musb/musb_udc.c
index 7620114bec..584564bac2 100644
--- a/drivers/usb/musb/musb_udc.c
+++ b/drivers/usb/musb/musb_udc.c
@@ -38,6 +38,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include "../gadget/ep0.h"
diff --git a/drivers/usb/musb/omap3.c b/drivers/usb/musb/omap3.c
index b2e4c32baf..080bd78523 100644
--- a/drivers/usb/musb/omap3.c
+++ b/drivers/usb/musb/omap3.c
@@ -16,6 +16,7 @@
  * 
  */
 
+#include 
 #include 
 #include 
 #include 
diff --git a/include/common.h b/include/common.h
index 4fda40cc1d..f97a7b6e14 100644
--- a/include/common.h
+++ b/include/common.h
@@ -310,13 +310,6 @@ int ulz4fn(const void *src, size_t srcn, void *dst, size_t 
*dstn);
 /* lib/vsprintf.c */
 #include 
 
-/*
- * STDIO based functions (can always be used)
- */
-/* serial stuff */
-intserial_printf (const char *fmt, ...)
-   __attribute__ ((format (__printf__, 1, 2)));
-
 /* lib/net_utils.c */
 #include 
 
diff --git a/include/serial.h b/include/serial.h
index 38a1cc99ae..8d1803c800 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -324,4 +324,15 @@ void pl01x_serial_initialize(void);
 void pxa_serial_initialize(void);
 void sh_serial_initialize(void);
 
+/**
+ * serial_printf() - Write a formatted string to the serial console
+ *
+ * The total size of the output must be less than CONFIG_SYS_PBSIZE.
+ *
+ * @fmt: Printf format string, followed by format arguments
+ * @return number of characters written
+ */
+int serial_printf(const char *fmt, ...)
+   __attribute__ ((format (__printf__, 1, 2)));
+
 #endif
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 11/42] common: Move sorting functions to their own header file

2019-11-12 Thread Simon Glass
These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 cmd/efi.c   |  1 +
 common/bootstage.c  |  1 +
 env/common.c|  1 +
 fs/yaffs2/yaffs_qsort.c |  1 +
 include/common.h|  5 -
 include/sort.h  | 34 ++
 lib/hashtable.c |  1 +
 lib/qsort.c |  1 +
 8 files changed, 40 insertions(+), 5 deletions(-)
 create mode 100644 include/sort.h

diff --git a/cmd/efi.c b/cmd/efi.c
index 919cb2fcfd..ea239a01f0 100644
--- a/cmd/efi.c
+++ b/cmd/efi.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static const char *const type_name[] = {
"reserved",
diff --git a/common/bootstage.c b/common/bootstage.c
index e8b7bbf81a..79972e46f2 100644
--- a/common/bootstage.c
+++ b/common/bootstage.c
@@ -11,6 +11,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/env/common.c b/env/common.c
index 0edb6fb04c..1fd1bd01d3 100644
--- a/env/common.c
+++ b/env/common.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/fs/yaffs2/yaffs_qsort.c b/fs/yaffs2/yaffs_qsort.c
index b463569815..32c767f359 100644
--- a/fs/yaffs2/yaffs_qsort.c
+++ b/fs/yaffs2/yaffs_qsort.c
@@ -5,6 +5,7 @@
  */
 
 #include "yportenv.h"
+#include 
 /* #include  */
 
 /*
diff --git a/include/common.h b/include/common.h
index 97b661181b..d17a2b2642 100644
--- a/include/common.h
+++ b/include/common.h
@@ -304,11 +304,6 @@ ulong  ticks2usec(unsigned long ticks);
 /* lib/lz4_wrapper.c */
 int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
 
-/* lib/qsort.c */
-void qsort(void *base, size_t nmemb, size_t size,
-  int(*compar)(const void *, const void *));
-int strcmp_compar(const void *, const void *);
-
 /* lib/uuid.c */
 #include 
 
diff --git a/include/sort.h b/include/sort.h
new file mode 100644
index 00..0c6b588fcb
--- /dev/null
+++ b/include/sort.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2019 Google LLC
+ */
+
+#ifndef __SORT_H
+#define __SORT_H
+
+/**
+ * qsort() - Use the quicksort algorithm to sort some values
+ *
+ * @base: Base address of array to sort
+ * @nmemb: Number of members to sort
+ * @size: Size of each member in bytes
+ * @compar: Comparison function which should return:
+ * < 0 if element at s1 < element at s2,
+ *   0 if element at s1 == element at s2,
+ * > 0 if element at s1 > element at s2,
+ */
+void qsort(void *base, size_t nmemb, size_t size,
+  int (*compar)(const void *s1, const void *s2));
+
+/**
+ * strcmp_compar() - compar function for string arrays
+ *
+ * This can be passed to qsort when a string array is being sorted
+ *
+ * @s1: First string to compare
+ * @s2: Second string to compare
+ * @return comparison value (less than, equal to, or greater than 0)
+ */
+int strcmp_compar(const void *s1, const void *s2);
+
+#endif
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 2caab0a4c6..907e8a642f 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -14,6 +14,7 @@
 
 #include 
 #include 
+#include 
 
 #ifdef USE_HOSTCC  /* HOST build */
 # include 
diff --git a/lib/qsort.c b/lib/qsort.c
index 57098841f9..f63d4ef726 100644
--- a/lib/qsort.c
+++ b/lib/qsort.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 void qsort(void  *base,
   size_t nel,
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 08/42] crc32: Use the crc.h header for crc functions

2019-11-12 Thread Simon Glass
Drop inclusion of crc.h in common.h and use the correct header directly
instead.

With this we can drop the conflicting definition in fw_env.h and rely on
the crc.h header, which is already included.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 api/api.c | 1 +
 arch/arm/mach-meson/board-common.c| 1 +
 arch/arm/mach-rockchip/misc.c | 1 +
 board/CZ.NIC/turris_omnia/turris_omnia.c  | 1 +
 board/corscience/tricorder/tricorder-eeprom.c | 1 +
 board/freescale/common/sys_eeprom.c   | 1 +
 board/freescale/mpc8323erdb/mpc8323erdb.c | 1 +
 board/gardena/smart-gateway-mt7688/board.c| 1 +
 board/gdsys/a38x/hre.c| 1 +
 board/gdsys/p1022/controlcenterd-id.c | 1 +
 board/sunxi/board.c   | 1 +
 board/theobroma-systems/puma_rk3399/puma-rk3399.c | 1 +
 board/varisys/common/sys_eeprom.c | 1 +
 cmd/i2c.c | 1 +
 cmd/nvedit.c  | 1 +
 common/android_ab.c   | 1 +
 common/bloblist.c | 1 +
 common/board_r.c  | 1 +
 common/hash.c | 1 +
 common/image-fit.c| 1 +
 common/image.c| 1 +
 common/iotrace.c  | 1 +
 common/spl/spl.c  | 1 +
 disk/part_efi.c   | 1 +
 drivers/misc/atsha204a-i2c.c  | 1 +
 drivers/mtd/ubi/attach.c  | 1 +
 drivers/mtd/ubi/crc32.c   | 1 +
 drivers/mtd/ubi/eba.c | 1 +
 drivers/mtd/ubi/fastmap.c | 1 +
 drivers/mtd/ubi/io.c  | 1 +
 drivers/mtd/ubi/vtbl.c| 1 +
 drivers/mtd/ubispl/ubispl.c   | 1 +
 drivers/net/fm/fdt.c  | 1 +
 drivers/net/fm/fm.c   | 1 +
 drivers/qe/qe.c   | 1 +
 env/common.c  | 1 +
 env/eeprom.c  | 1 +
 env/flash.c   | 1 +
 env/nand.c| 1 +
 env/nvram.c   | 1 +
 env/remote.c  | 1 +
 env/sf.c  | 1 +
 examples/api/glue.c   | 1 +
 fs/jffs2/jffs2_1pass.c| 1 +
 fs/ubifs/io.c | 1 +
 fs/ubifs/recovery.c   | 1 +
 fs/ubifs/tnc.c| 1 +
 include/common.h  | 3 ---
 lib/crc32.c   | 1 +
 lib/efi_loader/efi_boottime.c | 1 +
 lib/efi_loader/efi_runtime.c  | 1 +
 lib/efi_loader/efi_variable.c | 1 +
 lib/efi_selftest/efi_selftest_config_table.c  | 1 +
 lib/efi_selftest/efi_selftest_crc32.c | 1 +
 lib/gunzip.c  | 1 +
 lib/zlib/deflate.c| 1 +
 tools/default_image.c | 1 +
 tools/env/fw_env.c| 1 +
 tools/env/fw_env.h| 2 --
 tools/envcrc.c| 1 +
 tools/mkenvimage.c| 1 +
 tools/mxsimage.c  | 1 +
 tools/pbl_crc32.c | 1 +
 tools/pblimage.c  | 1 +
 tools/socfpgaimage.c  | 1 +
 65 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/api/api.c b/api/api.c
index 71fa03804e..4fc451a83d 100644
--- a/api/api.c
+++ b/api/api.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "api_private.h"
 
diff --git a/arch/arm/mach-meson/board-common.c 
b/arch/arm/mach-meson/board-common.c
index d261b4ea33..6c77e37966 100644
--- a/arch/arm/mach-meson/board-common.c
+++ b/arch/arm/mach-meson/board-common.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #if CONFIG_IS_ENABLED(FASTBOOT)
 #include 
diff --git a/arch/arm/mach-rockchip/misc.c b/arch/arm/mach-rockchip/misc.c
index c0e4fdbc00..186ea84d77 100644
--- a/arch/arm/mach-rockchip/misc.c
+++ b/arch/arm/mach-rockchip/misc.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c 
b/board/CZ.NIC/turris_omnia/turris_omnia.c
index 1d8d08a847..4d21e62e73 100644
--- a/board/CZ.NIC/turris_omnia/turris_omnia.c
+++ 

[U-Boot] [PATCH v3 10/42] common: Move bootcount functions to their header file

2019-11-12 Thread Simon Glass
These don't need to be in common.h so move them out.

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 board/BuR/brppt1/board.c |  1 +
 include/bootcount.h  | 10 ++
 include/common.h |  4 
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/board/BuR/brppt1/board.c b/board/BuR/brppt1/board.c
index ef4f5c9501..e0d1707ac1 100644
--- a/board/BuR/brppt1/board.c
+++ b/board/BuR/brppt1/board.c
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/include/bootcount.h b/include/bootcount.h
index a26a385233..cd30403984 100644
--- a/include/bootcount.h
+++ b/include/bootcount.h
@@ -59,6 +59,16 @@ int dm_bootcount_set(struct udevice *dev, u32 bootcount);
 
 #endif
 
+/** bootcount_store() - store the current bootcount */
+void bootcount_store(ulong);
+
+/**
+ * bootcount_load() - load the current bootcount
+ *
+ * @return bootcount, read from the appropriate location
+ */
+ulong bootcount_load(void);
+
 #if defined(CONFIG_SPL_BOOTCOUNT_LIMIT) || defined(CONFIG_BOOTCOUNT_LIMIT)
 
 #if !defined(CONFIG_SYS_BOOTCOUNT_LE) && !defined(CONFIG_SYS_BOOTCOUNT_BE)
diff --git a/include/common.h b/include/common.h
index 9c454fb1c8..97b661181b 100644
--- a/include/common.h
+++ b/include/common.h
@@ -266,10 +266,6 @@ unsigned long timer_get_us(void);
 void   enable_interrupts  (void);
 intdisable_interrupts (void);
 
-/* $(CPU)/.../commproc.c */
-void   bootcount_store (ulong);
-ulong  bootcount_load (void);
-
 /* $(CPU)/.../ */
 void mii_init (void);
 
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 05/42] common: Move random-number functions into their own header

2019-11-12 Thread Simon Glass
Create a new rand.h header file and move functions into it, to reduce
the size of common.h

Signed-off-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 include/common.h |  6 --
 include/net.h|  1 +
 include/rand.h   | 40 
 lib/rand.c   |  1 +
 net/link_local.c |  1 +
 5 files changed, 43 insertions(+), 6 deletions(-)
 create mode 100644 include/rand.h

diff --git a/include/common.h b/include/common.h
index 52bcc2e591..b09c7aeddd 100644
--- a/include/common.h
+++ b/include/common.h
@@ -325,12 +325,6 @@ char * strmhz(char *buf, unsigned long hz);
 /* lib/crc32.c */
 #include 
 
-/* lib/rand.c */
-#define RAND_MAX -1U
-void srand(unsigned int seed);
-unsigned int rand(void);
-unsigned int rand_r(unsigned int *seedp);
-
 /*
  * STDIO based functions (can always be used)
  */
diff --git a/include/net.h b/include/net.h
index 75a16e4c8f..d8d187d8af 100644
--- a/include/net.h
+++ b/include/net.h
@@ -16,6 +16,7 @@
 #include  /* for nton* / ntoh* stuff */
 #include 
 #include 
+#include 
 
 #define DEBUG_LL_STATE 0   /* Link local state machine changes */
 #define DEBUG_DEV_PKT 0/* Packets or info directed to the 
device */
diff --git a/include/rand.h b/include/rand.h
new file mode 100644
index 00..c9d15f50a1
--- /dev/null
+++ b/include/rand.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, w...@denx.de.
+ */
+
+#ifndef __RAND_H
+#define __RAND_H
+
+#define RAND_MAX -1U
+
+/**
+ * srand() - Set the random-number seed value
+ *
+ * This can be used to restart the pseudo-random-number sequence from a known
+ * point. This affects future calls to rand() to start from that point
+ *
+ * @seed: New seed
+ */
+void srand(unsigned int seed);
+
+/**
+ * rand() - Get a 32-bit pseudo-random number
+ *
+ * @returns next random number in the sequence
+ */
+unsigned int rand(void);
+
+/**
+ * rand_r() - Get a 32-bit pseudo-random number
+ *
+ * This version of the function allows multiple sequences to be used at the
+ * same time, since it requires the caller to store the seed value.
+ *
+ * @seed value to use, updated on exit
+ * @returns next random number in the sequence
+ */
+unsigned int rand_r(unsigned int *seedp);
+
+#endif
diff --git a/lib/rand.c b/lib/rand.c
index af4cf3a0e8..d256baf5ce 100644
--- a/lib/rand.c
+++ b/lib/rand.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 
 static unsigned int y = 1U;
 
diff --git a/net/link_local.c b/net/link_local.c
index dd9fcad087..1986b9b9d3 100644
--- a/net/link_local.c
+++ b/net/link_local.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "arp.h"
 #include "net_rand.h"
 
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


  1   2   >