[PATCH] usb: dwc3: Fix UTMI/UTMIW phy interface initialization

2019-12-17 Thread Jagan Teki
DWC3 support phy interfaces like 8/16-bit UTMI+. phy interface
initialization code would handle them properly along with UNKNOWN
type by default if none of the user/board doesn't need to use the
phy interfaces at all.

The current code is masking the 8/16-bit UTMI+ interface bits globally
which indeed effect the UNKNOWN cases, therefore it effects the platforms
which are not using phy interfaces at all.

So, handle the phy masking bits accordingly on respective interface
type cases.

Fixes: 6b7ebff00190 ("usb: dwc3: Add phy interface for dwc3_uboot")
Reported-by: Andy Shevchenko 
Signed-off-by: Jagan Teki 
---
 drivers/usb/dwc3/core.c | 12 
 drivers/usb/dwc3/core.h | 20 
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 0f9a632816..77c555e769 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -622,15 +622,19 @@ static void dwc3_uboot_hsphy_mode(struct dwc3_device 
*dwc3_dev,
 
/* Set dwc3 usb2 phy config */
reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
-   reg |= DWC3_GUSB2PHYCFG_PHYIF;
-   reg &= ~DWC3_GUSB2PHYCFG_USBTRDTIM_MASK;
 
switch (hsphy_mode) {
case USBPHY_INTERFACE_MODE_UTMI:
-   reg |= DWC3_GUSB2PHYCFG_USBTRDTIM_8BIT;
+   reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
+   DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
+   reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) |
+   DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT);
break;
case USBPHY_INTERFACE_MODE_UTMIW:
-   reg |= DWC3_GUSB2PHYCFG_USBTRDTIM_16BIT;
+   reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
+   DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
+   reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_16_BIT) |
+   DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_16_BIT);
break;
default:
break;
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index bff53e072b..1c08a2c5b6 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -162,18 +162,14 @@
 /* Global USB2 PHY Configuration Register */
 #define DWC3_GUSB2PHYCFG_PHYSOFTRST(1 << 31)
 #define DWC3_GUSB2PHYCFG_SUSPHY(1 << 6)
-#define DWC3_GUSB2PHYCFG_PHYIF BIT(3)
-
-/* Global USB2 PHY Configuration Mask */
-#define DWC3_GUSB2PHYCFG_USBTRDTIM_MASK(0xf << 10)
-
-/* Global USB2 PHY Configuration Offset */
-#define DWC3_GUSB2PHYCFG_USBTRDTIM_OFFSET  10
-
-#define DWC3_GUSB2PHYCFG_USBTRDTIM_16BIT   (0x5 << \
-   DWC3_GUSB2PHYCFG_USBTRDTIM_OFFSET)
-#define DWC3_GUSB2PHYCFG_USBTRDTIM_8BIT(0x9 << \
-   DWC3_GUSB2PHYCFG_USBTRDTIM_OFFSET)
+#define DWC3_GUSB2PHYCFG_PHYIF(n)  ((n) << 3)
+#define DWC3_GUSB2PHYCFG_PHYIF_MASKDWC3_GUSB2PHYCFG_PHYIF(1)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM(n)  ((n) << 10)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_MASKDWC3_GUSB2PHYCFG_USBTRDTIM(0xf)
+#define USBTRDTIM_UTMI_8_BIT   9
+#define USBTRDTIM_UTMI_16_BIT  5
+#define UTMI_PHYIF_16_BIT  1
+#define UTMI_PHYIF_8_BIT   0
 
 /* Global USB3 PIPE Control Register */
 #define DWC3_GUSB3PIPECTL_PHYSOFTRST   (1 << 31)
-- 
2.18.0.321.gffc6fa0e3



[PATCH] ARM: stm32: Permit multiple board targets

2019-12-17 Thread Marek Vasut
Setting TARGET_STM32MP1 in Kconfig always forces SYS_BOARD, SYS_VENDOR
and SYS_CONFIG_NAME to values set by the ST reference platforms. Allow
changing that by pulling out the TARGET_STM32MP157C_DK2 and making the
ST reference platform settings conditional on TARGET_STM32MP157C_DK2 .
Other platforms can now define a different TARGET_ and thus override
the SYS_ settings in their Kconfig.

Signed-off-by: Marek Vasut 
Cc: Patrick Delaunay 
Cc: Patrice Chotard 
---
 board/st/stm32mp1/Kconfig | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/board/st/stm32mp1/Kconfig b/board/st/stm32mp1/Kconfig
index 4fa2360b4f..c84aa41f06 100644
--- a/board/st/stm32mp1/Kconfig
+++ b/board/st/stm32mp1/Kconfig
@@ -1,4 +1,8 @@
-if TARGET_STM32MP1
+config TARGET_STM32MP157C_DK2
+   bool "support of STMicroelectronics STM32MP157C-DK2 Discovery Board"
+   default y
+
+if TARGET_STM32MP157C_DK2
 
 config SYS_BOARD
default "stm32mp1"
@@ -22,8 +26,4 @@ config CMD_STBOARD
  This compile the stboard command to
  read and write the board in the OTP.
 
-config TARGET_STM32MP157C_DK2
-   bool "support of STMicroelectronics STM32MP157C-DK2 Discovery Board"
-   default y
-
 endif
-- 
2.24.1



[PATCH] ARM: stm32: Fill in missing loadaddr

2019-12-17 Thread Marek Vasut
Since CONFIG_LOADADDR is not set, the default value of $loadaddr
variable is not set in the environment either. Set the default
load address to 256 MiB from the start of DRAM.

Signed-off-by: Marek Vasut 
Cc: Patrick Delaunay 
Cc: Patrice Chotard 
---
 include/configs/stm32mp1.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/configs/stm32mp1.h b/include/configs/stm32mp1.h
index dfc397c63c..59a86aee79 100644
--- a/include/configs/stm32mp1.h
+++ b/include/configs/stm32mp1.h
@@ -36,6 +36,7 @@
  * Needed by "loadb"
  */
 #define CONFIG_SYS_LOAD_ADDR   STM32_DDR_BASE
+#define CONFIG_LOADADDR0xd000
 
 /* ATAGs */
 #define CONFIG_CMDLINE_TAG
-- 
2.24.1



[PATCH] ARM: stm32: Allow overriding setup_mac_address()

2019-12-17 Thread Marek Vasut
Let board code override setup_mac_address(), which is useful e.g. if the
board derives the MAC address from another source, like an I2C EEPROM.

Signed-off-by: Marek Vasut 
Cc: Patrick Delaunay 
Cc: Patrice Chotard 
---
 arch/arm/mach-stm32mp/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
index ed7d9f61dc..856c7ced7a 100644
--- a/arch/arm/mach-stm32mp/cpu.c
+++ b/arch/arm/mach-stm32mp/cpu.c
@@ -449,7 +449,7 @@ static void setup_boot_mode(void)
  * If there is no MAC address in the environment, then it will be initialized
  * (silently) from the value in the OTP.
  */
-static int setup_mac_address(void)
+__weak int setup_mac_address(void)
 {
 #if defined(CONFIG_NET)
int ret;
-- 
2.24.1



[PATCH] stm32mp1: configs: Make all boot devices in distro boot conditional

2019-12-17 Thread Marek Vasut
Not all systems have all the boot devices enabled, e.g. not all systems
have MTD devices and thus do not enable UBI. Make all the boot devices
in the distro bootcmd conditional to avoid failures.

Signed-off-by: Marek Vasut 
Cc: Patrick Delaunay 
Cc: Patrice Chotard 
---
 include/configs/stm32mp1.h | 34 --
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/include/configs/stm32mp1.h b/include/configs/stm32mp1.h
index d42a7860be..dfc397c63c 100644
--- a/include/configs/stm32mp1.h
+++ b/include/configs/stm32mp1.h
@@ -98,12 +98,34 @@
 
 #if !defined(CONFIG_SPL_BUILD)
 
-#define BOOT_TARGET_DEVICES(func) \
-   func(MMC, mmc, 1) \
-   func(UBIFS, ubifs, 0) \
-   func(MMC, mmc, 0) \
-   func(MMC, mmc, 2) \
-   func(PXE, pxe, na)
+#ifdef CONFIG_CMD_MMC
+#define BOOT_TARGET_DEVICE_MMC0(func)  func(MMC, mmc, 0)
+#define BOOT_TARGET_DEVICE_MMC1(func)  func(MMC, mmc, 1)
+#define BOOT_TARGET_DEVICE_MMC2(func)  func(MMC, mmc, 2)
+#else
+#define BOOT_TARGET_DEVICE_MMC0(func)
+#define BOOT_TARGET_DEVICE_MMC1(func)
+#define BOOT_TARGET_DEVICE_MMC2(func)
+#endif
+
+#ifdef CONFIG_NET
+#define BOOT_TARGET_DEVICE_PXE(func)   func(PXE, pxe, na)
+#else
+#define BOOT_TARGET_DEVICE_PXE(func)
+#endif
+
+#ifdef CONFIG_CMD_UBIFS
+#define BOOT_TARGET_DEVICE_UBIFS(func) func(UBIFS, ubifs, 0)
+#else
+#define BOOT_TARGET_DEVICE_UBIFS(func)
+#endif
+
+#define BOOT_TARGET_DEVICES(func)  \
+   BOOT_TARGET_DEVICE_MMC1(func)   \
+   BOOT_TARGET_DEVICE_UBIFS(func)  \
+   BOOT_TARGET_DEVICE_MMC0(func)   \
+   BOOT_TARGET_DEVICE_MMC2(func)   \
+   BOOT_TARGET_DEVICE_PXE(func)
 
 /*
  * bootcmd for stm32mp1:
-- 
2.24.1



[PATCH] net: dwc_eth_qos: Pass -1 to phy_connect() to scan for all PHYs

2019-12-17 Thread Marek Vasut
PHY address 0 is a valid PHY address, to scan for all PHYs, pass -1 to
phy_connect(). Passing 0 used to work before be accident, but does no
longer.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Patrice Chotard 
Cc: Patrick Delaunay 
Cc: Ramon Fried 
---
 drivers/net/dwc_eth_qos.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c
index da5b696c9d..4632111635 100644
--- a/drivers/net/dwc_eth_qos.c
+++ b/drivers/net/dwc_eth_qos.c
@@ -1045,7 +1045,7 @@ static int eqos_start(struct udevice *dev)
 * don't need to reconnect/reconfigure again
 */
if (!eqos->phy) {
-   eqos->phy = phy_connect(eqos->mii, 0, dev,
+   eqos->phy = phy_connect(eqos->mii, -1, dev,
eqos->config->interface(dev));
if (!eqos->phy) {
pr_err("phy_connect() failed");
-- 
2.24.1



[PATCH 2/2] doc: intel: Update serial driver changes in slimbootloader.rst

2019-12-17 Thread Park, Aiden
Now, Slim Bootloader uses NS16550_DYNAMIC to support serial port
configuration at runtime, so no more code change is required.
Therefore, remove unnecessary steps and fix minor typo.

Signed-off-by: Aiden Park 
---
 doc/board/intel/slimbootloader.rst | 35 +++---
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/doc/board/intel/slimbootloader.rst 
b/doc/board/intel/slimbootloader.rst
index 375e676804..a8c41b1aa7 100644
--- a/doc/board/intel/slimbootloader.rst
+++ b/doc/board/intel/slimbootloader.rst
@@ -111,35 +111,16 @@ Download it from 
http://downloads.yoctoproject.org/releases/yocto/yocto-2.0/mach
 Build Instruction for Slim Bootloader for LeafHill (APL) target
 ---
 
-LeafHill is using PCI UART2 device as a serial port.
-For MEM32 serial port, CONFIG_SYS_NS16550_MEM32 needs to be enabled in U-Boot.
+Prepare U-Boot and Slim Bootloader as described at the beginning of this page.
+Also, the PayloadId needs to be set for APL board.
 
-1. Enable CONFIG_SYS_NS16550_MEM32 in U-Boot::
-
-$ vi include/configs/slimbootloader.h
-+#define CONFIG_SYS_NS16550_MEM32
- #ifdef CONFIG_SYS_NS16550_MEM3
-
-2. Build U-Boot::
-
-   $ make disclean
-   $ make slimbootloader_defconfig
-   $ make all
-
-3. Copy u-boot-dtb.bin to Slim Bootloader.
-   Slim Bootloader looks for a payload from the specific location.
-   Copy the build u-boot-dtb.bin to the expected location::
-
-   $ mkdir -p /PayloadPkg/PayloadBins/
-   $ cp /u-boot-dtb.bin /PayloadPkg/PayloadBins/u-boot-dtb.bin
-
-4. Update PayloadId. Let's use 'U-BT' as an example::
+1. Update PayloadId. Let's use 'U-BT' as an example::
 
 $ vi Platform/ApollolakeBoardPkg/CfgData/CfgData_Int_LeafHill.dlt
 -GEN_CFG_DATA.PayloadId | 'AUTO
 +GEN_CFG_DATA.PayloadId | 'U-BT'
 
-5. Update payload text base.
+2. Update payload text base.
 
 * PAYLOAD_EXE_BASE must be the same as U-Boot CONFIG_SYS_TEXT_BASE
   in board/intel/slimbootloader/Kconfig.
@@ -149,18 +130,18 @@ For MEM32 serial port, CONFIG_SYS_NS16550_MEM32 needs to 
be enabled in U-Boot.
 +   self.PAYLOAD_LOAD_HIGH= 0
 +   self.PAYLOAD_EXE_BASE = 0x0010
 
-6. Build APL target. Make sure u-boot-dtb.bin and U-BT PayloadId
+3. Build APL target. Make sure u-boot-dtb.bin and U-BT PayloadId
in build command. The output is Outputs/apl/Stitch_Components.zip::
 
$ python BuildLoader.py build apl -p 
"OsLoader.efi:LLDR:Lz4;u-boot-dtb.bin:U-BT:Lzma"
 
-7. Stitch IFWI.
+4. Stitch IFWI.
 
Refer to Apollolake_ page in Slim Bootloader document site::
 
$ python Platform/ApollolakeBoardPkg/Script/StitchLoader.py -i  -s Outputs/apl/Stitch_Components.zip -o 
 
-8. Flash IFWI.
+5. Flash IFWI.
 
Use DediProg to flash IFWI. You should reach at U-Boot serial console.
 
@@ -175,7 +156,7 @@ Build Instruction to use ELF U-Boot
 
 2. Build U-Boot::
 
-   $ make disclean
+   $ make distclean
$ make slimbootloader_defconfig
$ make all
$ strip u-boot (removing symbol for reduced size)
-- 
2.20.1



Re: [U-Boot] [PATCH] net/phy: Fix phy_connect() for phy addr 0

2019-12-17 Thread Marek Vasut
On 12/18/19 3:06 AM, Joe Hershberger wrote:
> On Tue, Dec 17, 2019 at 1:04 PM Marek Vasut  wrote:
>>
>> On 12/17/19 7:47 PM, Joe Hershberger wrote:
>>> On Tue, Dec 17, 2019 at 11:46 AM Marek Vasut  wrote:

 On 12/17/19 5:25 PM, Joe Hershberger wrote:
> Hi Marek,

 Hi Joe,

> On Tue, Dec 17, 2019 at 1:39 AM Marek Vasut  wrote:
>>
>> On 11/7/19 9:04 PM, Joe Hershberger wrote:
>>> On Thu, Nov 7, 2019 at 1:16 PM Tom Rini  wrote:

 On Tue, Nov 05, 2019 at 04:05:11AM +, Priyanka Jain wrote:

> Fix 'mask' calculation in phy_connect() for phy addr '0'.
> 'mask' is getting set to '0x' for phy addr '0'
> in phy_connect() whereas expected value is '0'.
>
>
> Signed-off-by: Priyanka Jain 

 Reported-by: tetsu-aoki via github
>>>
>>> Acked-by: Joe Hershberger 
>>
>> Sadly, this breaks systems where a PHY is at address 0.
>> I have such an STM32MP1 system with LAN8720 PHY and since this patch, I
>> cannot use ethernet. Please revert.
>
> It seems like a case that shouldn't have worked before.

 Eh? PHY at address 0 definitely did work before and must work now.
>>>
>>> Agreed that a phy at address 0 should work. Not agreed that because
>>> the value "0" used to work due to a bug that it must still. Which of
>>> these is the statement you are making? Do we already agree or
>>> disagree?
>>
>> I am saying that because a board worked on rc4 and does not work on rc5,
>> this is a bug introduced by this patch in rc5 and must be fixed before
>> the release.
>>
>> The address 0 is a PHY broadcast address for some PHYs, it's a fixed
>> address for other PHYs. Thus, a PHY at address 0 must work. If this is
>> broken now, it's a bug.
> 
> The only thing this patch should change is to not access addresses
> other than 0. I read the data sheet for the LAN8720 and it doesn't
> mention anything about any broadcast behavior, so I'm not sure what
> you're trying to state here.

Read [1] section 3.7.1 PHYAD[2:0]: PHY ADDRESS CONFIGURATION

What I am saying is that there are two types of PHYs, ones which treat
PHY address 0 as broadcast and ones which treat it as regular address.
This one is the later and is configured as such in my case.

http://ww1.microchip.com/downloads/en/DeviceDoc/2164B.pdf

> What about
> this board requires the mask to be all 'f's, other than specifying the
> wrong phy address? It seems that in your case the phy address is not
> actually 0 (or the computed mask would find it), but your board dts
> may be setting it to 0 as an "unknown" value, but the correct unknown
> value should be "-1". It seems the issue is with these boards.

 Nope, the address is actually configured to 0 in hardware.
>>>
>>> Can you double check that?
>>
>> No, sorry, I know the hardware is fixed to 0. Checking it again will not
>> change this fact.
> 
> It seems there is no phy driver for this in U-Boot so the generic
> behavior is being used. I'm at a disadvantage of not having this board
> to try. Can you revert this patch and run with debug enabled for
> drivers/net/phy/phy.c to determine what is happening for this board? I
> would appreciate you helping with this.

It only says "connected to Generic PHY" .

So looking at the commit message, I am not really sure which board or
issue does this patch fix. But if I understand the commit message right,
then the aim is to set mask to 0 instead of 0x for address 0.
But that's not right either, the mask should be BIT(0) = 1 for address
0, and that's what the patch actually does. I guess this then fails
somewhere further down the road ...


Re: [EXT] Re: [PATCH v1] T1024RDB: USB: Add a 10808 us delay in usb_scan_port

2019-12-17 Thread Marek Vasut
On 12/18/19 4:27 AM, Yinbo Zhu wrote:

Hi,

[...]

>>> diff --git a/common/usb_hub.c b/common/usb_hub.c index 
>>> 33aaeb8e44..6dd06696b2 100644
>>> --- a/common/usb_hub.c
>>> +++ b/common/usb_hub.c
>>> @@ -486,6 +486,9 @@ static int usb_scan_port(struct usb_device_scan 
>>> *usb_scan)
>>> return 0;
>>> }
>>>
>>> +#ifdef CONFIG_TARGET_T1024RDB
>>> +   udelay(10808);
>>> +#endif
>>
>> This looks like a workaround. Is this a silicon errata?
> 
>  > Does setting usb_pgood_delay to e.g. 2000 help ?
> 
> Hi Marek Casut,
> 
> Thanks your feedback, I test it 2000, usb start can list device, in fact, 120 
> is enough,
> In addition, if it is some usb storage issue, I think add it into bootargs it 
> is reasonable, but I test some usb storage,
> It is all encounter issue, so I think add it that delay into usb driver code.
> => setenv usb_pgood_delay 120 
> => usb start
> starting USB...
> USB0:   USB EHCI 1.00
> USB1:   USB EHCI 1.00
> scanning bus 0 for devices... 2 USB Device(s) found
> scanning bus 1 for devices... 1 USB Device(s) found
>scanning usb for storage devices... 1 Storage Device(s) found
> =>

So does setting the usb_pgood_delay resolve the issue ? The variable
increases the time between turning on Vbus and starting scanning the
bus, it's a common issue on various boards and this is the way to solve it.


[PATCH 1/2] x86: serial: Use NS16550_DYNAMIC in Slim Bootloader

2019-12-17 Thread Park, Aiden
Slim Bootloader provides serial port info in its HOB to support
both IO or MMIO serial ports, but it's controlled by SYS_NS16550_MEM32
or SYS_NS16550_PORT_MAPPED in U-Boot.
To support both serial port configurations dynamically at runtime,
Slim Bootloader serial driver leverages NS16550_DYNAMIC.

Signed-off-by: Aiden Park 
---
 arch/x86/cpu/slimbootloader/serial.c |  5 +
 include/configs/slimbootloader.h | 13 -
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/arch/x86/cpu/slimbootloader/serial.c 
b/arch/x86/cpu/slimbootloader/serial.c
index 7b44a59bff..0f45b3ba72 100644
--- a/arch/x86/cpu/slimbootloader/serial.c
+++ b/arch/x86/cpu/slimbootloader/serial.c
@@ -45,7 +45,12 @@ static int slimbootloader_serial_ofdata_to_platdata(struct 
udevice *dev)
plat->base = data->base;
/* ns16550 uses reg_shift, then covert stride to shift */
plat->reg_shift = data->stride >> 1;
+   plat->reg_width = data->stride;
plat->clock = data->clk;
+   plat->fcr = UART_FCR_DEFVAL;
+   plat->flags = 0;
+   if (data->type == 1)
+   plat->flags |= NS16550_FLAG_IO;
 
return 0;
 }
diff --git a/include/configs/slimbootloader.h b/include/configs/slimbootloader.h
index e0011ed446..b8169072cc 100644
--- a/include/configs/slimbootloader.h
+++ b/include/configs/slimbootloader.h
@@ -8,19 +8,6 @@
 
 #include 
 
-/*
- * By default, CONFIG_SYS_NS16550_PORT_MAPPED is enabled for port io serial.
- * To use mmio base serial, enable CONFIG_SYS_NS16550_MEM32 and disable
- * CONFIG_SYS_NS16550_PORT_MAPPED until ns16550 driver supports serial port
- * configuration in run-time.
- *
- * #define CONFIG_SYS_NS16550_MEM32
- * #undef CONFIG_SYS_NS16550_PORT_MAPPED
- */
-#ifdef CONFIG_SYS_NS16550_MEM32
-#undef CONFIG_SYS_NS16550_PORT_MAPPED
-#endif
-
 #define CONFIG_STD_DEVICES_SETTINGS\
"stdin=serial,i8042-kbd,usbkbd\0"   \
"stdout=serial\0"   \
-- 
2.20.1



[PATCH 0/2] x86: serial: Use NS16550_DYNAMIC in Slim Bootloader

2019-12-17 Thread Park, Aiden
Slim Bootloader provides serial port info in its HOB to support
both IO or MMIO serial ports, but it's controlled by SYS_NS16550_MEM32
or SYS_NS16550_PORT_MAPPED in U-Boot.
To support both serial port configurations dynamically at runtime,
Slim Bootloader serial driver leverages NS16550_DYNAMIC.

Aiden Park (2):
  x86: serial: Use NS16550_DYNAMIC in Slim Bootloader driver
  doc: intel: Update serial driver changes in slimbootloader.rst

 arch/x86/cpu/slimbootloader/serial.c |  5 
 doc/board/intel/slimbootloader.rst   | 35 +++-
 include/configs/slimbootloader.h | 13 ---
 3 files changed, 13 insertions(+), 40 deletions(-)

-- 
2.20.1


Re: [U-Boot] [PATCH] net/phy: Fix phy_connect() for phy addr 0

2019-12-17 Thread Marek Vasut
On 12/18/19 12:35 AM, Tom Rini wrote:
> On Tue, Dec 17, 2019, 2:04 PM Marek Vasut  wrote:
> 
>> On 12/17/19 7:47 PM, Joe Hershberger wrote:
>>> On Tue, Dec 17, 2019 at 11:46 AM Marek Vasut  wrote:

 On 12/17/19 5:25 PM, Joe Hershberger wrote:
> Hi Marek,

 Hi Joe,

> On Tue, Dec 17, 2019 at 1:39 AM Marek Vasut  wrote:
>>
>> On 11/7/19 9:04 PM, Joe Hershberger wrote:
>>> On Thu, Nov 7, 2019 at 1:16 PM Tom Rini  wrote:

 On Tue, Nov 05, 2019 at 04:05:11AM +, Priyanka Jain wrote:

> Fix 'mask' calculation in phy_connect() for phy addr '0'.
> 'mask' is getting set to '0x' for phy addr '0'
> in phy_connect() whereas expected value is '0'.
>
>
> Signed-off-by: Priyanka Jain 

 Reported-by: tetsu-aoki via github
>>>
>>> Acked-by: Joe Hershberger 
>>
>> Sadly, this breaks systems where a PHY is at address 0.
>> I have such an STM32MP1 system with LAN8720 PHY and since this patch,
>> I
>> cannot use ethernet. Please revert.
>
> It seems like a case that shouldn't have worked before.

 Eh? PHY at address 0 definitely did work before and must work now.
>>>
>>> Agreed that a phy at address 0 should work. Not agreed that because
>>> the value "0" used to work due to a bug that it must still. Which of
>>> these is the statement you are making? Do we already agree or
>>> disagree?
>>
>> I am saying that because a board worked on rc4 and does not work on rc5,
>> this is a bug introduced by this patch in rc5 and must be fixed before
>> the release.
>>
>> The address 0 is a PHY broadcast address for some PHYs, it's a fixed
>> address for other PHYs. Thus, a PHY at address 0 must work. If this is
>> broken now, it's a bug.
>>
> What about
> this board requires the mask to be all 'f's, other than specifying the
> wrong phy address? It seems that in your case the phy address is not
> actually 0 (or the computed mask would find it), but your board dts
> may be setting it to 0 as an "unknown" value, but the correct unknown
> value should be "-1". It seems the issue is with these boards.

 Nope, the address is actually configured to 0 in hardware.
>>>
>>> Can you double check that?
>>
>> No, sorry, I know the hardware is fixed to 0. Checking it again will not
>> change this fact.
>>
>>> The code as is should compute a mask of
>>> "0x01" which should match the offset for address 0. If it really is at
>>> 0 in hardware, maybe there is a different bug. Otherwise I don't see
>>> how this patch would work for the author.
>>
>> Reverting this patch makes things work again for me.
>>
> 
> Ok but breaking other boards again to fix your board is also unacceptable.
> It's not a theoretical case that something else failed previously.

At least it restores the behavior in -rc4 , so that is the last option
if there is no better patch.


RE: [Patch v2 1/7] spi: Transform the FSL QuadSPI driver to use the SPI MEM API

2019-12-17 Thread Kuldeep Singh
Hi Priyanka,

> -Original Message-
> From: Priyanka Jain 
> Sent: Tuesday, December 17, 2019 10:38 AM
> To: Kuldeep Singh ; u-boot@lists.denx.de
> Cc: ja...@amarulasolutions.com; s...@denx.de; Ashish Kumar
> ; frieder.schre...@kontron.de; Kuldeep Singh
> ; Ashish Kumar 
> Subject: RE: [Patch v2 1/7] spi: Transform the FSL QuadSPI driver to use the 
> SPI
> MEM API
> 
> 
> 
> >-Original Message-
> >From: Kuldeep Singh 
> >Sent: Monday, December 16, 2019 5:19 PM
> >To: u-boot@lists.denx.de
> >Cc: ja...@amarulasolutions.com; Priyanka Jain ;
> >s...@denx.de; Ashish Kumar ;
> >frieder.schre...@kontron.de; Kuldeep Singh ;
> >Ashish Kumar 
> >Subject: [Patch v2 1/7] spi: Transform the FSL QuadSPI driver to use
> >the SPI MEM API
> >
> >To support the SPI MEM API, instead of modifying the existing U-Boot
> >driver, this patch adds a port of the existing Linux driver.
> >This also has the advantage that porting changes and fixes from Linux
> >will be easier.
> >Porting of driver left most of the functions unchanged while few of the
> >changes are:
> >-Remove lock(mutexes) and irq handler as uboot is a single core execution.
> >-Remove clock support as the changing spi speed is not supported in
> >uboot and nor in linux.
> >
> >Currently tested on LS1088ARDB, LS1012ARDB, LS1046ARDB, LS1046AFRWY,
> >LS1043AQDS, LS1021ATWR, LS2080ARDB
> >
> >Signed-off-by: Frieder Schrempf 
> >Signed-off-by: Ashish Kumar 
> >Signed-off-by: Kuldeep Singh 
> >---
> > drivers/spi/fsl_qspi.c | 1562 +++-
> > drivers/spi/fsl_qspi.h |  145 
> > 2 files changed, 593 insertions(+), 1114 deletions(-)  delete mode
> >100644 drivers/spi/fsl_qspi.h
> >
> >diff --git a/drivers/spi/fsl_qspi.c b/drivers/spi/fsl_qspi.c index
> >8e2a09df36..96178c06bc 100644
> >--- a/drivers/spi/fsl_qspi.c
> >+++ b/drivers/spi/fsl_qspi.c
> >@@ -1,1142 +1,766 @@
> > // SPDX-License-Identifier: GPL-2.0+
> >+
> > /*
> >- * Copyright 2013-2015 Freescale Semiconductor, Inc.
> >+ * Freescale QuadSPI driver.
> >+ *
> >+ * Copyright (C) 2013 Freescale Semiconductor, Inc.
> >+ * Copyright (C) 2018 Bootlin
> >+ * Copyright (C) 2018 exceet electronics GmbH
> >+ * Copyright (C) 2018 Kontron Electronics GmbH
> >+ * Copyright (C) 2019-2020 NXP
> Please check copyright format
> It seems the changes have been brought from Linux driver.
> If yes, it would be good to mention that in File header

Ok. I will mention that information on top.

> >  *
> >- * Freescale Quad Serial Peripheral Interface (QSPI) driver
> >+ * Based on the original fsl-quadspi.c spi-nor driver.
> >+ * Transition to spi-mem in spi-fsl-qspi.c
> >  */
> >
> > #include 
> >-#include 
> >-#include 
> > #include 
> >-#include 
> >-#include 
> > #include 
> >-#include 
> >-#include 
> >-#include 
> >-#include "fsl_qspi.h"
> >+#include 
> >+#include 
> >+#include 
> >+#include 
> >
> > DECLARE_GLOBAL_DATA_PTR;
> >
> >-#define OFFSET_BITS_MASKGENMASK(23, 0)
> >-
> >-#define FLASH_STATUS_WEL0x02
> >-
> >-/* SEQID */
> >-#define SEQID_WREN  1
> >-#define SEQID_FAST_READ 2
> >-#define SEQID_RDSR  3
> >-#define SEQID_SE4
> >-#define SEQID_CHIP_ERASE5
> >-#define SEQID_PP6
> >-#define SEQID_RDID  7
> >-#define SEQID_BE_4K 8
> >-#ifdef CONFIG_SPI_FLASH_BAR
> >-#define SEQID_BRRD  9
> >-#define SEQID_BRWR  10
> >-#define SEQID_RDEAR 11
> >-#define SEQID_WREAR 12
> >-#endif
> >-#define SEQID_WRAR  13
> >-#define SEQID_RDAR  14
> >-
> >-/* QSPI CMD */
> >-#define QSPI_CMD_PP 0x02/* Page program (up to 256
> bytes) */
> >-#define QSPI_CMD_RDSR   0x05/* Read status register */
> >-#define QSPI_CMD_WREN   0x06/* Write enable */
> >-#define QSPI_CMD_FAST_READ  0x0b/* Read data bytes (high
> >frequency) */
> >-#define QSPI_CMD_BE_4K  0x20/* 4K erase */
> >-#define QSPI_CMD_CHIP_ERASE 0xc7/* Erase whole flash chip */
> >-#define QSPI_CMD_SE 0xd8/* Sector erase (usually 64KiB)
> */
> >-#define QSPI_CMD_RDID   0x9f/* Read JEDEC ID */
> >-
> >-/* Used for Micron, winbond and Macronix flashes */
> >-#define QSPI_CMD_WREAR  0xc5/* EAR register write
> */
> >-#define QSPI_CMD_RDEAR  0xc8/* EAR reigster read
> */
> >-
> >-/* Used for Spansion flashes only. */
> >-#define QSPI_CMD_BRRD   0x16/* Bank register read
> >*/
> >-#define QSPI_CMD_BRWR   0x17/* Bank register
> write
> >*/
> >-
> >-/* Used for Spansion S25FS-S family flash only. */
> >-#define QSPI_CMD_RDAR   0x65/* Read any device register
> */
> >-#define QSPI_CMD_WRAR   0x71/* Write any device register
> */
> >-
> >-/* 4-byte address QSPI CMD - used on Spansion and some Macronix flashes
> */
> >-#define QSPI_CMD_FAST_READ_4B   0x0c/* Read data bytes (high
> >frequency) */
> >-#define QSPI_CMD_PP_4B  

RE: [EXT] Re: [PATCH v1] T1024RDB: USB: Add a 10808 us delay in usb_scan_port

2019-12-17 Thread Yinbo Zhu


-Original Message-
From: Marek Vasut  
Sent: 2019年12月16日 16:33
To: Bin Meng ; Yinbo Zhu 
Cc: U-Boot Mailing List ; Peter Chen 
; Xiaobo Xie ; Joe Hershberger 
; Jiafei Pan ; Ran Wang 
; Jun Li 
Subject: [EXT] Re: [PATCH v1] T1024RDB: USB: Add a 10808 us delay in 
usb_scan_port

Caution: EXT Email

On 12/16/19 4:17 AM, Bin Meng wrote:
> +Marek,
>
> On Mon, Dec 16, 2019 at 11:13 AM Yinbo Zhu  wrote:
>>
>> T1024RDB usb controller doesn't detect usb device at first usb start 
>> Add a delay that is greater than 10808 us can fix that issue, which 
>> delay if is less than 10808 us, issue is probabilistic occurrence
>>
>> => usb start
>> starting USB...
>> USB0:   USB EHCI 1.00
>> USB1:   USB EHCI 1.00
>> scanning bus 0 for devices... 1 USB Device(s) found scanning bus 1 
>> for devices... 1 USB Device(s) found
>>scanning usb for storage devices... 0 Storage Device(s) found 
>> => usb stop stopping USB..
>> => usb start
>> starting USB...
>> USB0:   USB EHCI 1.00
>> USB1:   USB EHCI 1.00
>> scanning bus 0 for devices... 2 USB Device(s) found scanning bus 1 
>> for devices... 1 USB Device(s) found
>>scanning usb for storage devices... 1 Storage Device(s) found 
>> =>
>>
>> Signed-off-by: Yinbo Zhu 
>> ---
>>  common/usb_hub.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/common/usb_hub.c b/common/usb_hub.c index 
>> 33aaeb8e44..6dd06696b2 100644
>> --- a/common/usb_hub.c
>> +++ b/common/usb_hub.c
>> @@ -486,6 +486,9 @@ static int usb_scan_port(struct usb_device_scan 
>> *usb_scan)
>> return 0;
>> }
>>
>> +#ifdef CONFIG_TARGET_T1024RDB
>> +   udelay(10808);
>> +#endif
>
> This looks like a workaround. Is this a silicon errata?

 > Does setting usb_pgood_delay to e.g. 2000 help ?

Hi Marek Casut,

Thanks your feedback, I test it 2000, usb start can list device, in fact, 120 
is enough,
In addition, if it is some usb storage issue, I think add it into bootargs it 
is reasonable, but I test some usb storage,
It is all encounter issue, so I think add it that delay into usb driver code.
=> setenv usb_pgood_delay 120 
=> usb start
starting USB...
USB0:   USB EHCI 1.00
USB1:   USB EHCI 1.00
scanning bus 0 for devices... 2 USB Device(s) found
scanning bus 1 for devices... 1 USB Device(s) found
   scanning usb for storage devices... 1 Storage Device(s) found
=>

Thanks,
Yinbo


Re: [U-Boot] [PATCH] net/phy: Fix phy_connect() for phy addr 0

2019-12-17 Thread Joe Hershberger
On Tue, Dec 17, 2019 at 1:04 PM Marek Vasut  wrote:
>
> On 12/17/19 7:47 PM, Joe Hershberger wrote:
> > On Tue, Dec 17, 2019 at 11:46 AM Marek Vasut  wrote:
> >>
> >> On 12/17/19 5:25 PM, Joe Hershberger wrote:
> >>> Hi Marek,
> >>
> >> Hi Joe,
> >>
> >>> On Tue, Dec 17, 2019 at 1:39 AM Marek Vasut  wrote:
> 
>  On 11/7/19 9:04 PM, Joe Hershberger wrote:
> > On Thu, Nov 7, 2019 at 1:16 PM Tom Rini  wrote:
> >>
> >> On Tue, Nov 05, 2019 at 04:05:11AM +, Priyanka Jain wrote:
> >>
> >>> Fix 'mask' calculation in phy_connect() for phy addr '0'.
> >>> 'mask' is getting set to '0x' for phy addr '0'
> >>> in phy_connect() whereas expected value is '0'.
> >>>
> >>>
> >>> Signed-off-by: Priyanka Jain 
> >>
> >> Reported-by: tetsu-aoki via github
> >
> > Acked-by: Joe Hershberger 
> 
>  Sadly, this breaks systems where a PHY is at address 0.
>  I have such an STM32MP1 system with LAN8720 PHY and since this patch, I
>  cannot use ethernet. Please revert.
> >>>
> >>> It seems like a case that shouldn't have worked before.
> >>
> >> Eh? PHY at address 0 definitely did work before and must work now.
> >
> > Agreed that a phy at address 0 should work. Not agreed that because
> > the value "0" used to work due to a bug that it must still. Which of
> > these is the statement you are making? Do we already agree or
> > disagree?
>
> I am saying that because a board worked on rc4 and does not work on rc5,
> this is a bug introduced by this patch in rc5 and must be fixed before
> the release.
>
> The address 0 is a PHY broadcast address for some PHYs, it's a fixed
> address for other PHYs. Thus, a PHY at address 0 must work. If this is
> broken now, it's a bug.

The only thing this patch should change is to not access addresses
other than 0. I read the data sheet for the LAN8720 and it doesn't
mention anything about any broadcast behavior, so I'm not sure what
you're trying to state here.

> >>> What about
> >>> this board requires the mask to be all 'f's, other than specifying the
> >>> wrong phy address? It seems that in your case the phy address is not
> >>> actually 0 (or the computed mask would find it), but your board dts
> >>> may be setting it to 0 as an "unknown" value, but the correct unknown
> >>> value should be "-1". It seems the issue is with these boards.
> >>
> >> Nope, the address is actually configured to 0 in hardware.
> >
> > Can you double check that?
>
> No, sorry, I know the hardware is fixed to 0. Checking it again will not
> change this fact.

It seems there is no phy driver for this in U-Boot so the generic
behavior is being used. I'm at a disadvantage of not having this board
to try. Can you revert this patch and run with debug enabled for
drivers/net/phy/phy.c to determine what is happening for this board? I
would appreciate you helping with this.

> > The code as is should compute a mask of
> > "0x01" which should match the offset for address 0. If it really is at
> > 0 in hardware, maybe there is a different bug. Otherwise I don't see
> > how this patch would work for the author.
>
> Reverting this patch makes things work again for me.


Sunxi (pine64-lts) SPL load BL32

2019-12-17 Thread adam parker
I am attempting to boot the Pine64-lts with a Trusted OS.  In the ARM-TF
documentation it states "make sure the loader (SPL) loads the Trusted OS
binary to the beginning of DRAM (0x4000)."  I have yet to find a
mechanism by which U-Boot's SPL for this platform can be configured to do
this.  Any help would be appreciated.

Thanks,
Adam


Re: Query: Error: Unable to find signature node in Verified boot

2019-12-17 Thread Dhananjay Phadke
Signature node must be in u-boot's FDT, written by mkimage -K 
...


On Tue, Dec 17, 2019 at 4:38 AM Priyanka Singh 
wrote:

> Hi,
>
> I was trying to test the Verified boot feature on NXP's LX2160ARDB board
> and I am facing the following issue during the same:
>
> 1. U-boot is unable to verify the signatures of the images and
> configurations. I added more logs to debug this issue and found that U-boot
> is unable to find the signature node and returns from common/image-sig.c
> line: 260.
> Log snippet:
> Verifying Hash Integrity ... sha1,rsa2048:dev- OK
>
> The signing of the images and configuration has been done using mkimage.
>
> Can someone please suggest how can I correct this.
>
> Thanks,
> Priyanka Singh
>


Re: [U-Boot] [PATCH] qemu-riscv64_smode, sifive-fu540: fix extlinux (define preboot)

2019-12-17 Thread Vagrant Cascadian
On 2019-09-25, Vagrant Cascadian wrote:
> On 2019-08-21, David Abdurachmanov wrote:
>> Commit 37304aaf60bf92a5dc3ef222ba520698bd862a44 removed preboot
>> commands in RISC-V targets and broke extlinux support as reported
>> by Fu Wei .
>>
>> The patch finishes migration of CONFIG_USE_PREBOOT and CONFIG_REBOOT
>> to Kconfig.
>
> Tested using qemu-riscv64_smode and it fixes extlinux booting. Thanks!
>
> Please CC me on future updates to the patch series.
>
> Tested-by: Vagrant Cascadian 

This patch, or something like it, is still needed with u-boot
v2020.01-rc5 for extlinux support to load the device-tree from the boot
firmware.

Is there a new approach in the works, or any chance to see something
like this get merged soon?

Thanks!


live well,
  vagrant

>> Signed-off-by: David Abdurachmanov 
>> ---
>>  configs/qemu-riscv64_smode_defconfig | 2 ++
>>  configs/sifive_fu540_defconfig   | 2 ++
>>  include/configs/sifive-fu540.h   | 4 
>>  3 files changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/configs/qemu-riscv64_smode_defconfig 
>> b/configs/qemu-riscv64_smode_defconfig
>> index 74743a5ebe..2e1f7fa91f 100644
>> --- a/configs/qemu-riscv64_smode_defconfig
>> +++ b/configs/qemu-riscv64_smode_defconfig
>> @@ -9,3 +9,5 @@ CONFIG_DISPLAY_CPUINFO=y
>>  CONFIG_DISPLAY_BOARDINFO=y
>>  # CONFIG_CMD_MII is not set
>>  CONFIG_OF_PRIOR_STAGE=y
>> +CONFIG_USE_PREBOOT=y
>> +CONFIG_PREBOOT="setenv fdt_addr ${fdtcontroladdr}; fdt addr 
>> ${fdtcontroladdr};"
>> diff --git a/configs/sifive_fu540_defconfig b/configs/sifive_fu540_defconfig
>> index 48865e5f11..a852579309 100644
>> --- a/configs/sifive_fu540_defconfig
>> +++ b/configs/sifive_fu540_defconfig
>> @@ -9,3 +9,5 @@ CONFIG_MISC_INIT_R=y
>>  CONFIG_DISPLAY_CPUINFO=y
>>  CONFIG_DISPLAY_BOARDINFO=y
>>  CONFIG_OF_PRIOR_STAGE=y
>> +CONFIG_USE_PREBOOT=y
>> +CONFIG_PREBOOT="setenv fdt_addr ${fdtcontroladdr}; fdt addr 
>> ${fdtcontroladdr};"
>> diff --git a/include/configs/sifive-fu540.h b/include/configs/sifive-fu540.h
>> index 858b7a7da1..ba4aa0652c 100644
>> --- a/include/configs/sifive-fu540.h
>> +++ b/include/configs/sifive-fu540.h
>> @@ -40,8 +40,4 @@
>>  "ramdisk_addr_r=0x8830\0" \
>>  BOOTENV
>>  
>> -#define CONFIG_PREBOOT \
>> -"setenv fdt_addr ${fdtcontroladdr};" \
>> -"fdt addr ${fdtcontroladdr};"
>> -
>>  #endif /* __CONFIG_H */


signature.asc
Description: PGP signature


[PATCH v4 15/16] sandbox: add extra configurations for UEFI and related tests

2019-12-17 Thread AKASHI Takahiro
Adding those extra configurations allows us to successfully run UEFI
secure boot pytest on Travis CI.

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

diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index b0abf99386b9..c40e1d93465b 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -26,6 +26,7 @@ CONFIG_CMD_ASKENV=y
 CONFIG_CMD_GREPENV=y
 CONFIG_CMD_ENV_CALLBACK=y
 CONFIG_CMD_ENV_FLAGS=y
+CONFIG_CMD_NVEDIT_EFI=y
 CONFIG_LOOPW=y
 CONFIG_CMD_MD5SUM=y
 CONFIG_CMD_MEMINFO=y
@@ -52,6 +53,7 @@ CONFIG_CMD_DNS=y
 CONFIG_CMD_LINK_LOCAL=y
 CONFIG_CMD_ETHSW=y
 CONFIG_CMD_BMP=y
+CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_TIMER=y
 CONFIG_CMD_SOUND=y
@@ -194,6 +196,7 @@ CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
 CONFIG_ERRNO_STR=y
+CONFIG_EFI_SECURE_BOOT=y
 CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index ee0ec3f233d0..3246348341a4 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -29,6 +29,7 @@ CONFIG_CMD_ASKENV=y
 CONFIG_CMD_GREPENV=y
 CONFIG_CMD_ENV_CALLBACK=y
 CONFIG_CMD_ENV_FLAGS=y
+CONFIG_CMD_NVEDIT_EFI=y
 CONFIG_LOOPW=y
 CONFIG_CMD_MD5SUM=y
 CONFIG_CMD_MEMINFO=y
@@ -60,6 +61,7 @@ CONFIG_CMD_LINK_LOCAL=y
 CONFIG_CMD_ETHSW=y
 CONFIG_CMD_BMP=y
 CONFIG_CMD_BOOTCOUNT=y
+CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_TIMER=y
 CONFIG_CMD_SOUND=y
@@ -221,6 +223,7 @@ CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
 CONFIG_ERRNO_STR=y
+CONFIG_EFI_SECURE_BOOT=y
 CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
-- 
2.24.0



[PATCH v4 14/16] efi_loader, pytest: add UEFI secure boot tests (image)

2019-12-17 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 |  99 +
 .../tests/test_efi_secboot/test_unsigned.py   | 103 ++
 2 files changed, 202 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 ..b185e36af2e3
--- /dev/null
+++ b/test/py/tests/test_efi_secboot/test_signed.py
@@ -0,0 +1,99 @@
+# 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
+"""
+u_boot_console.restart_uboot()
+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
+"""
+u_boot_console.restart_uboot()
+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'])
+  

[PATCH v4 16/16] travis: add packages for UEFI secure boot test

2019-12-17 Thread AKASHI Takahiro
Pytest for UEFI secure boot will use several host commands.
In particular, Test setup relies on efitools, whose version must be v1.5.2
or later. So fetch a new version of deb package directly.
Please note it has a dependency on mtools, which must also be installed
along wih efitools.

In addition, the path, '/sbin', is added to PATH for use of sgdisk and
mkfs.

Signed-off-by: AKASHI Takahiro 
---
 .travis.yml | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index f6aec9677083..91b6d23ace98 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -38,6 +38,14 @@ addons:
 - libisl15
 - clang-7
 - srecord
+- coreutils
+- util-linux
+- dosfstools
+- gdisk
+- mount
+- mtools
+- openssl
+- sbsigntool
 
 install:
  # Clone uboot-test-hooks
@@ -58,10 +66,11 @@ install:
  - mkdir ~/grub2-arm64
  - ( cd ~/grub2-arm64; wget -O - 
http://download.opensuse.org/ports/aarch64/distribution/leap/42.2/repo/oss/suse/aarch64/grub2-arm64-efi-2.02~beta2-87.1.aarch64.rpm
 | rpm2cpio | cpio -di )
  - wget 
http://mirrors.kernel.org/ubuntu/pool/main/m/mpfr4/libmpfr4_3.1.4-1_amd64.deb 
&& sudo dpkg -i libmpfr4_3.1.4-1_amd64.deb && rm libmpfr4_3.1.4-1_amd64.deb
+ - wget 
http://mirrors.kernel.org/ubuntu/pool/universe/e/efitools/efitools_1.8.1-0ubuntu2_amd64.deb
 && sudo dpkg -i efitools_1.8.1-0ubuntu2_amd64.deb && rm 
efitools_1.8.1-0ubuntu2_amd64.deb
 
 env:
   global:
-- 
PATH=/tmp/qemu-install/bin:/tmp/uboot-test-hooks/bin:/usr/bin:/bin:/usr/local/bin
+- 
PATH=/tmp/qemu-install/bin:/tmp/uboot-test-hooks/bin:/sbin:/usr/bin:/bin:/usr/local/bin
 - PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci
 - BUILD_DIR=build
 - HOSTCC="cc"
-- 
2.24.0



[PATCH v4 13/16] efi_loader, pytest: add UEFI secure boot tests (authenticated variables)

2019-12-17 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 | 282 ++
 1 file changed, 282 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 ..55dcaa95f1ea
--- /dev/null
+++ b/test/py/tests/test_efi_secboot/test_authvar.py
@@ -0,0 +1,282 @@
+# 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
+"""
+u_boot_console.restart_uboot()
+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(': 00' in ''.join(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([
+'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 -n 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 -n 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 -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f 
db'])
+assert(not re.search('Failed to set EFI variable', 
''.join(output)))
+assert(re.search('db:', ''.join(output)))
+
+output = u_boot_console.run_command(
+'printenv -e SecureBoot')
+assert(': 01' in 

[PATCH v4 11/16] cmd: env: add "-at" option to "env set -e" command

2019-12-17 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.24.0



[PATCH v4 12/16] efi_loader, pytest: set up secure boot environment

2019-12-17 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 
---
 test/py/README.md  |   8 ++
 test/py/tests/test_efi_secboot/conftest.py | 151 +
 test/py/tests/test_efi_secboot/defs.py |  21 +++
 3 files changed, 180 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/test/py/README.md b/test/py/README.md
index 3cbe01b73e28..aa8a5607b064 100644
--- a/test/py/README.md
+++ b/test/py/README.md
@@ -37,7 +37,15 @@ will be required.  The following is an incomplete list:
 | openssl|
 | sudo OR guestmount |
 | e2fsprogs  |
+| util-linux |
+| coreutils  |
 | dosfstools |
+| efitools   |
+| mount  |
+| mtools |
+| sbsigntool |
+| 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 ..e542fef6e819
--- /dev/null
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -0,0 +1,151 @@
+# 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 *
+
+# from test/py/conftest.py
+def tool_is_in_path(tool):
+for path in os.environ["PATH"].split(os.pathsep):
+fn = os.path.join(path, tool)
+if os.path.isfile(fn) and os.access(fn, os.X_OK):
+return True
+return False
+
+#
+# Fixture for UEFI secure boot test
+#
+@pytest.fixture(scope='session')
+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:
+non_root = tool_is_in_path('udisksctl')
+
+# 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)
+if non_root:
+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)
+else:
+loop_dev = check_output('sudo losetup -o 1MiB --sizelimit %dMiB 
--show -f %s | tr -d "\n"'
+% (part_size, image_path), shell=True).decode()
+mnt_point = '/mnt'
+check_output('sudo mount -t %s -o umask=000 %s %s'
+% (fs_type, loop_dev, mnt_point), shell=True)
+
+# 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/ 

[PATCH v4 07/16] efi_loader: variable: add VendorKeys variable

2019-12-17 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 2e7570bc9b4f..f967704fc2b6 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;
 }
 
@@ -1122,6 +1155,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(
@@ -1129,8 +1164,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.24.0



[PATCH v4 08/16] efi_loader: image_loader: support image authentication

2019-12-17 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 specification 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 | 454 +-
 3 files changed, 449 insertions(+), 14 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 1f88caf86709..e12b49098fb0 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);
@@ -726,6 +728,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..939758e61e3c 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,367 @@ 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_regions, num_sections, i, j;
+   int ctidx = IMAGE_DIRECTORY_ENTRY_SECURITY;
+   u32 align, size, authsz, authoff;
+   size_t bytes_hashed;
+
+   dos = (void *)efi;
+   nt = (void *)(efi + dos->e_lfanew);
+
+   /*
+* Count maximum number of regions to be digested.
+* We don't have to have an exact number here.
+* See efi_image_region_add()'s in parsing below.
+*/
+   num_regions = 3; /* for header */
+   num_regions += nt->FileHeader.NumberOfSections;
+   num_regions++; /* for extra */
+
+   regs = calloc(sizeof(*regs) + sizeof(struct image_region) 

[PATCH v4 09/16] efi_loader: set up secure boot

2019-12-17 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.24.0



[PATCH v4 10/16] cmd: env: use appropriate guid for authenticated UEFI variable

2019-12-17 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.24.0



[PATCH v4 06/16] efi_loader: variable: add secure boot state transition

2019-12-17 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 171b4abb4c58..2e7570bc9b4f 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,
+  

[PATCH v4 04/16] efi_loader: add signature database parser

2019-12-17 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 | 226 +
 2 files changed, 229 insertions(+)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 3ca68f9bbb6e..3b3618e0be24 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -720,6 +720,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 823d3311e010..98302e1ab3d3 100644
--- a/lib/efi_loader/efi_signature.c
+++ b/lib/efi_loader/efi_signature.c
@@ -581,4 +581,230 @@ 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) {
+   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;
+   }
+
+   /* Append signature data */

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

2019-12-17 Thread AKASHI Takahiro
The index (IMAGE_DIRECTORY_ENTRY_SECURITY) 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 
Reviewed-by: Heinrich Schuchardt 
---
 include/pe.h | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/include/pe.h b/include/pe.h
index bff3b0aa7a6c..086f2b860e99 100644
--- a/include/pe.h
+++ b/include/pe.h
@@ -155,6 +155,8 @@ typedef struct _IMAGE_SECTION_HEADER {
uint32_t Characteristics;
 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
 
+/* Indices for Optional Header Data Directories */
+#define IMAGE_DIRECTORY_ENTRY_SECURITY 4
 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5
 
 typedef struct _IMAGE_BASE_RELOCATION
@@ -252,4 +254,20 @@ 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;
+
+/* Definitions for the contents of the certs data block */
+#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.24.0



[PATCH v4 00/16] efi_loader: add secure boot support

2019-12-17 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.)

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 experimental 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)
* 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].

Test:
* my pytest, included in this patch set, passed.
* efi_selftest passed. (At least no regression.)
* Travis CI tests have passed.

Known issues:
* 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].)


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-December/393977.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 v4 (Dec 18, 2019)
* adjust EFI_SECURE_BOOT dependencies due to a change of RSA extension patch v5
  (patch#2)
* change "imply" to "select" against kconfig dependencies (patch#2)
* otherwise, no functional changes

Changes in v3 (Dec 9, 2019)
* allow for arbitrary number of regions in efi_image_region_add()
  (patch#3, #5 and #8)
* remove a redundant check in a while loop at efi_sigstore_free() (patch#4)

Changes in v2 (Nov 26, 2019)
* rebased to v2020.01-rc3
* rename IMAGE_DIRECTORY_ENTRY_CERTTABLE to IMAGE_DIRECTORY_ENTRY_SECURITY
  (patch#1,#9)
* add comments (patch#1)
* drop v1's patch#2 as it is no longer necessary
* drop v1's patch#3 as other "SECURE_BOOT" architectures have renamed
  this option and no longer use it
* add structure descriptions (patch#3)
* rework hash calculation code in efi_signature_verify() and remove
  an odd constant, WinIndrectSha256 (patch#3)
* move travis.yml changes to a separate patch (patch#12, #16)
* yield_fixture() -> fixture() (patch#12)
* call console.restart_uboot() at every test case (13,#14)
* add patch#15; 

[PATCH v4 05/16] efi_loader: variable: support variable authentication

2019-12-17 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 | 665 --
 2 files changed, 564 insertions(+), 104 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 3b3618e0be24..1f88caf86709 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;
@@ -723,6 +724,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..171b4abb4c58 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,291 @@ 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 

[PATCH v4 03/16] efi_loader: add signature verification functions

2019-12-17 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  |  87 +
 include/efi_loader.h   |  72 
 lib/efi_loader/Makefile|   1 +
 lib/efi_loader/efi_signature.c | 584 +
 4 files changed, 744 insertions(+)
 create mode 100644 lib/efi_loader/efi_signature.c

diff --git a/include/efi_api.h b/include/efi_api.h
index 22396172e15f..47f24fc90873 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,86 @@ struct efi_unicode_collation_protocol {
 #define LOAD_OPTION_CATEGORY_BOOT  0x
 #define LOAD_OPTION_CATEGORY_APP   0x0100
 
+/* Certificate types in signature database */
+#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)
+
+/**
+ * win_certificate_uefi_guid - A certificate that encapsulates
+ * a GUID-specific signature
+ *
+ * @hdr:   Windows certificate header
+ * @cert_type: Certificate type
+ * @cert_data: Certificate data
+ */
+struct win_certificate_uefi_guid {
+   WIN_CERTIFICATE hdr;
+   efi_guid_t  cert_type;
+   u8  cert_data[];
+} __attribute__((__packed__));
+
+/**
+ * efi_variable_authentication_2 - A time-based authentication method
+ * descriptor
+ *
+ * This structure describes an authentication information for
+ * a variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
+ * and should be included as part of a variable's value.
+ * Only EFI_CERT_TYPE_PKCS7_GUID is accepted.
+ *
+ * @time_stamp:Descriptor's time stamp
+ * @auth_info: Authentication info
+ */
+struct efi_variable_authentication_2 {
+   struct efi_time  time_stamp;
+   struct win_certificate_uefi_guid auth_info;
+} __attribute__((__packed__));
+
+/**
+ * efi_signature_data - A format of signature
+ *
+ * This structure describes a single signature in signature database.
+ *
+ * @signature_owner:   Signature owner
+ * @signature_data:Signature data
+ */
+struct efi_signature_data {
+   efi_guid_t  signature_owner;
+   u8  signature_data[];
+} __attribute__((__packed__));
+
+/**
+ * efi_signature_list - A format of signature database
+ *
+ * This structure describes a list of signatures with the same type.
+ * An authenticated variable's value is a concatenation of one or more
+ * efi_signature_list's.
+ *
+ * @signature_type:Signature type
+ * @signature_list_size:   Size of signature list
+ * @signature_header_size: Size of signature header
+ * @signature_size:Size of signature
+ */
+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..3ca68f9bbb6e 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;
+/* GUIDs for authentication */
+extern const 

[PATCH v4 02/16] efi_loader: add CONFIG_EFI_SECURE_BOOT config option

2019-12-17 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 | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index c7027a967653..d1c092a1d80a 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -115,4 +115,23 @@ 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
+   select SHA256
+   select RSA
+   select RSA_VERIFY_WITH_PKEY
+   select IMAGE_SIGN_INFO
+   select ASYMMETRIC_KEY_TYPE
+   select ASYMMETRIC_PUBLIC_KEY_SUBTYPE
+   select X509_CERTIFICATE_PARSER
+   select PKCS7_MESSAGE_PARSER
+   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.24.0



Re: [U-Boot] [PATCH] net/phy: Fix phy_connect() for phy addr 0

2019-12-17 Thread Tom Rini
On Tue, Dec 17, 2019, 2:04 PM Marek Vasut  wrote:

> On 12/17/19 7:47 PM, Joe Hershberger wrote:
> > On Tue, Dec 17, 2019 at 11:46 AM Marek Vasut  wrote:
> >>
> >> On 12/17/19 5:25 PM, Joe Hershberger wrote:
> >>> Hi Marek,
> >>
> >> Hi Joe,
> >>
> >>> On Tue, Dec 17, 2019 at 1:39 AM Marek Vasut  wrote:
> 
>  On 11/7/19 9:04 PM, Joe Hershberger wrote:
> > On Thu, Nov 7, 2019 at 1:16 PM Tom Rini  wrote:
> >>
> >> On Tue, Nov 05, 2019 at 04:05:11AM +, Priyanka Jain wrote:
> >>
> >>> Fix 'mask' calculation in phy_connect() for phy addr '0'.
> >>> 'mask' is getting set to '0x' for phy addr '0'
> >>> in phy_connect() whereas expected value is '0'.
> >>>
> >>>
> >>> Signed-off-by: Priyanka Jain 
> >>
> >> Reported-by: tetsu-aoki via github
> >
> > Acked-by: Joe Hershberger 
> 
>  Sadly, this breaks systems where a PHY is at address 0.
>  I have such an STM32MP1 system with LAN8720 PHY and since this patch,
> I
>  cannot use ethernet. Please revert.
> >>>
> >>> It seems like a case that shouldn't have worked before.
> >>
> >> Eh? PHY at address 0 definitely did work before and must work now.
> >
> > Agreed that a phy at address 0 should work. Not agreed that because
> > the value "0" used to work due to a bug that it must still. Which of
> > these is the statement you are making? Do we already agree or
> > disagree?
>
> I am saying that because a board worked on rc4 and does not work on rc5,
> this is a bug introduced by this patch in rc5 and must be fixed before
> the release.
>
> The address 0 is a PHY broadcast address for some PHYs, it's a fixed
> address for other PHYs. Thus, a PHY at address 0 must work. If this is
> broken now, it's a bug.
>
> >>> What about
> >>> this board requires the mask to be all 'f's, other than specifying the
> >>> wrong phy address? It seems that in your case the phy address is not
> >>> actually 0 (or the computed mask would find it), but your board dts
> >>> may be setting it to 0 as an "unknown" value, but the correct unknown
> >>> value should be "-1". It seems the issue is with these boards.
> >>
> >> Nope, the address is actually configured to 0 in hardware.
> >
> > Can you double check that?
>
> No, sorry, I know the hardware is fixed to 0. Checking it again will not
> change this fact.
>
> > The code as is should compute a mask of
> > "0x01" which should match the offset for address 0. If it really is at
> > 0 in hardware, maybe there is a different bug. Otherwise I don't see
> > how this patch would work for the author.
>
> Reverting this patch makes things work again for me.
>

Ok but breaking other boards again to fix your board is also unacceptable.
It's not a theoretical case that something else failed previously.

>


Re: [U-Boot] [PATCH v2 2/2] ARM: i.MX6: TARGET_NITROGEN6X: add 'select MX6QDL'

2019-12-17 Thread Fabio Estevam
On Sun, Nov 3, 2019 at 11:20 PM Troy Kisky
 wrote:
>
> This fixes commit <91435cd40d30> "ARM: i.MX6: exclude the ARM errata
>  from i.MX6 UP system"
>
> for nitrogen6x. The above commit removed the errata for the board
> since MX6Q/MXDL/MX6S is selected via CONFIG_SYS_EXTRA_OPTIONS
>
> This restores the errata configs.
>
> Signed-off-by: Troy Kisky 

Reviewed-by: Fabio Estevam 


OMAP L138 LCDK - giving up maintainership

2019-12-17 Thread Peter Howard
Tom and others,

I finish at my current job on Friday, as such I will have no immediate
involvement with the L138 chip (not that I've had that much in recent
times).  So it makes sense to remove me as maintainer.  Especially as
the email listed for me will start bouncing.  so is the simplest way
just to submit a patch clearing out the maintainer entry in
board/davinci/da8xxevm/MAINTAINERS ?  Also does anyone on the list wish
to take over?  Adam, I know you don't have the time from recent emails.
Bartosz?  Sekhar - do you want to nominate someone from TI?


-- 
Peter Howard 
Peter Howard 


signature.asc
Description: This is a digitally signed message part


[PATCH v4 3/3] arm: dts: ls1028a: fix interrupt properties

2019-12-17 Thread Michael Walle
Sync the interrupt properties with the ones from Linux. Also use the
constants provided by the dt-bindings header. Please note, that there
are actual changes/fixes in the irq flags. U-Boot won't use the
interrupt properties anyway. It's just to be consistent with the Linux
device tree.

Signed-off-by: Michael Walle 
---
changes since v1:
 - n/a
changes since v2:
 - new patch
changes since v3:
 - none

 arch/arm/dts/fsl-ls1028a.dtsi | 55 ---
 1 file changed, 31 insertions(+), 24 deletions(-)

diff --git a/arch/arm/dts/fsl-ls1028a.dtsi b/arch/arm/dts/fsl-ls1028a.dtsi
index 774e477542..5365bfb1a8 100644
--- a/arch/arm/dts/fsl-ls1028a.dtsi
+++ b/arch/arm/dts/fsl-ls1028a.dtsi
@@ -6,6 +6,8 @@
  *
  */
 
+#include 
+
 / {
compatible = "fsl,ls1028a";
interrupt-parent = <>;
@@ -38,15 +40,20 @@
  <0x0 0x0604 0 0x4>;
#interrupt-cells = <3>;
interrupt-controller;
-   interrupts = <1 9 0x4>;
+   interrupts = ;
};
 
timer {
compatible = "arm,armv8-timer";
-   interrupts = <1 13 0x8>, /* Physical Secure PPI, active-low */
-<1 14 0x8>, /* Physical Non-Secure PPI, active-low 
*/
-<1 11 0x8>, /* Virtual PPI, active-low */
-<1 10 0x8>; /* Hypervisor PPI, active-low */
+   interrupts = ,
+,
+,
+;
};
 
fspi: flexspi@20c {
@@ -58,7 +65,7 @@
reg-names = "fspi_base", "fspi_mmap";
clocks = < 4 3>, < 4 3>;
clock-names = "fspi_en", "fspi";
-   interrupts = <0 25 0x4>;
+   interrupts = ;
status = "disabled";
};
 
@@ -66,7 +73,7 @@
device_type = "serial";
compatible = "fsl,ns16550", "ns16550a";
reg = <0x0 0x21c0500 0x0 0x100>;
-   interrupts = <0 32 0x1>; /* edge triggered */
+   interrupts = ;
status = "disabled";
};
 
@@ -74,7 +81,7 @@
device_type = "serial";
compatible = "fsl,ns16550", "ns16550a";
reg = <0x0 0x21c0600 0x0 0x100>;
-   interrupts = <0 32 0x1>; /* edge triggered */
+   interrupts = ;
status = "disabled";
};
 
@@ -150,7 +157,7 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <0x0 0x200 0x0 0x1>;
-   interrupts = <0 34 0x4>;
+   interrupts = ;
clock-names = "i2c";
clocks = < 4 0>;
status = "disabled";
@@ -161,7 +168,7 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <0x0 0x201 0x0 0x1>;
-   interrupts = <0 34 0x4>;
+   interrupts = ;
clock-names = "i2c";
clocks = < 4 0>;
status = "disabled";
@@ -172,7 +179,7 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <0x0 0x202 0x0 0x1>;
-   interrupts = <0 35 0x4>;
+   interrupts = ;
clock-names = "i2c";
clocks = < 4 0>;
status = "disabled";
@@ -183,7 +190,7 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <0x0 0x203 0x0 0x1>;
-   interrupts = <0 35 0x4>;
+   interrupts = ;
clock-names = "i2c";
clocks = < 4 0>;
status = "disabled";
@@ -194,7 +201,7 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <0x0 0x204 0x0 0x1>;
-   interrupts = <0 74 0x4>;
+   interrupts = ;
clock-names = "i2c";
clocks = < 4 0>;
status = "disabled";
@@ -205,7 +212,7 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <0x0 0x205 0x0 0x1>;
-   interrupts = <0 74 0x4>;
+   interrupts = ;
clock-names = "i2c";
clocks = < 4 0>;
status = "disabled";
@@ -216,7 +223,7 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <0x0 0x206 0x0 0x1>;
-   interrupts = <0 75 0x4>;
+   interrupts = ;
clock-names = "i2c";
clocks = < 4 0>;
status = "disabled";
@@ -227,7 +234,7 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <0x0 0x207 0x0 0x1>;
-   interrupts = <0 75 0x4>;
+   interrupts = ;

[PATCH v4 2/3] arm: ls1028a: use the new flexspi driver

2019-12-17 Thread Michael Walle
Also align the fspi node with the kernel one.

Signed-off-by: Michael Walle 
Reviewed-by: Kuldeep Singh 
---
changes since v1:
 - none
changes since v2:
 - none
changes since v3:
 - none

 arch/arm/dts/fsl-ls1028a.dtsi | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/arm/dts/fsl-ls1028a.dtsi b/arch/arm/dts/fsl-ls1028a.dtsi
index 43a154e8e7..774e477542 100644
--- a/arch/arm/dts/fsl-ls1028a.dtsi
+++ b/arch/arm/dts/fsl-ls1028a.dtsi
@@ -49,14 +49,16 @@
 <1 10 0x8>; /* Hypervisor PPI, active-low */
};
 
-   fspi: flexspi@20C {
-   compatible = "nxp,dn-fspi";
+   fspi: flexspi@20c {
+   compatible = "nxp,lx2160a-fspi";
#address-cells = <1>;
#size-cells = <0>;
-   reg = <0x0 0x20C 0x0 0x1>,
-   <0x0 0x2000 0x0 0x1000>; /*64MB flash*/
-   reg-names = "FSPI", "FSPI-memory";
-   num-cs = <1>;
+   reg = <0x0 0x20c 0x0 0x1>,
+ <0x0 0x2000 0x0 0x1000>;
+   reg-names = "fspi_base", "fspi_mmap";
+   clocks = < 4 3>, < 4 3>;
+   clock-names = "fspi_en", "fspi";
+   interrupts = <0 25 0x4>;
status = "disabled";
};
 
-- 
2.20.1



[PATCH v4 1/3] spi: nxp_fspi: new driver for the FlexSPI controller

2019-12-17 Thread Michael Walle
This is a port of the kernel's spi-nxp-fspi driver. It uses the new
spi-mem interface and does not expose the more generic spi-xfer
interface. The source was taken from the v5.3-rc3 tag.

The port was straightforward:
 - remove the interrupt handling and the completion by busy polling the
   controller
 - remove locks
 - move the setup of the memory windows into claim_bus()
 - move the setup of the speed into set_speed()
 - port the device tree bindings from the original fspi_probe() to
   ofdata_to_platdata()

There were only some style change fixes, no change in any logic. For
example, there are busy loops where the return code is not handled
correctly, eg. only prints a warning with WARN_ON(). This port
intentionally left most functions unchanged to ease future bugfixes.

This was tested on a custom LS1028A board. Because the LS1028A doesn't
have proper clock framework support, changing the clock speed was not
tested. This also means that it is not possible to change the SPI
speed on LS1028A for now (neither is it possible in the linux driver).

Signed-off-by: Michael Walle 
Reviewed-by: Jagan Teki 
Tested-by: Kuldeep Singh 
---
changes since v1:
 - fixed typo, thanks Jagan
changes since v2:
 - none
changes since v3:
 - move original copyright to the top

 drivers/spi/Kconfig|   7 +
 drivers/spi/Makefile   |   1 +
 drivers/spi/nxp_fspi.c | 996 +
 3 files changed, 1004 insertions(+)
 create mode 100644 drivers/spi/nxp_fspi.c

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 8588866489..d8d34fc021 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -192,6 +192,13 @@ config MVEBU_A3700_SPI
  used to access the SPI NOR flash on platforms embedding this
  Marvell IP core.
 
+config NXP_FSPI
+   bool "NXP FlexSPI driver"
+   depends on SPI_MEM
+   help
+ Enable the NXP FlexSPI (FSPI) driver. This driver can be used to
+ access the SPI NOR flash on platforms embedding this NXP IP core.
+
 config PIC32_SPI
bool "Microchip PIC32 SPI driver"
depends on MACH_PIC32
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index ae4f2958f8..52462e19a3 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_MSCC_BB_SPI) += mscc_bb_spi.o
 obj-$(CONFIG_MVEBU_A3700_SPI) += mvebu_a3700_spi.o
 obj-$(CONFIG_MXC_SPI) += mxc_spi.o
 obj-$(CONFIG_MXS_SPI) += mxs_spi.o
+obj-$(CONFIG_NXP_FSPI) += nxp_fspi.o
 obj-$(CONFIG_ATCSPI200_SPI) += atcspi200_spi.o
 obj-$(CONFIG_OMAP3_SPI) += omap3_spi.o
 obj-$(CONFIG_PIC32_SPI) += pic32_spi.o
diff --git a/drivers/spi/nxp_fspi.c b/drivers/spi/nxp_fspi.c
new file mode 100644
index 00..a2fab7ad0a
--- /dev/null
+++ b/drivers/spi/nxp_fspi.c
@@ -0,0 +1,996 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * NXP FlexSPI(FSPI) controller driver.
+ *
+ * Copyright (c) 2019 Michael Walle 
+ * Copyright (c) 2019 NXP
+ *
+ * This driver was originally ported from the linux kernel v5.4-rc3, which had
+ * the following notes:
+ *
+ * FlexSPI is a flexsible SPI host controller which supports two SPI
+ * channels and up to 4 external devices. Each channel supports
+ * Single/Dual/Quad/Octal mode data transfer (1/2/4/8 bidirectional
+ * data lines).
+ *
+ * FlexSPI controller is driven by the LUT(Look-up Table) registers
+ * LUT registers are a look-up-table for sequences of instructions.
+ * A valid sequence consists of four LUT registers.
+ * Maximum 32 LUT sequences can be programmed simultaneously.
+ *
+ * LUTs are being created at run-time based on the commands passed
+ * from the spi-mem framework, thus using single LUT index.
+ *
+ * Software triggered Flash read/write access by IP Bus.
+ *
+ * Memory mapped read access by AHB Bus.
+ *
+ * Based on SPI MEM interface and spi-fsl-qspi.c driver.
+ *
+ * Author:
+ * Yogesh Narayan Gaur 
+ * Boris Brezillon 
+ * Frieder Schrempf 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * The driver only uses one single LUT entry, that is updated on
+ * each call of exec_op(). Index 0 is preset at boot with a basic
+ * read operation, so let's use the last entry (31).
+ */
+#defineSEQID_LUT   31
+
+/* Registers used by the driver */
+#define FSPI_MCR0  0x00
+#define FSPI_MCR0_AHB_TIMEOUT(x)   ((x) << 24)
+#define FSPI_MCR0_IP_TIMEOUT(x)((x) << 16)
+#define FSPI_MCR0_LEARN_EN BIT(15)
+#define FSPI_MCR0_SCRFRUN_EN   BIT(14)
+#define FSPI_MCR0_OCTCOMB_EN   BIT(13)
+#define FSPI_MCR0_DOZE_EN  BIT(12)
+#define FSPI_MCR0_HSEN BIT(11)
+#define FSPI_MCR0_SERCLKDIVBIT(8)
+#define FSPI_MCR0_ATDF_EN  BIT(7)
+#define FSPI_MCR0_ARDF_EN  BIT(6)
+#define FSPI_MCR0_RXCLKSRC(x)  ((x) << 4)
+#define FSPI_MCR0_END_CFG(x)   ((x) << 2)
+#define 

Re: [PATCH v2 2/2] ARM: i.MX6: TARGET_NITROGEN6X: add 'select MX6QDL'

2019-12-17 Thread Troy Kisky
On 11/3/2019 6:20 PM, Troy Kisky wrote:
> This fixes commit <91435cd40d30> "ARM: i.MX6: exclude the ARM errata
>  from i.MX6 UP system"
> 
> for nitrogen6x. The above commit removed the errata for the board
> since MX6Q/MXDL/MX6S is selected via CONFIG_SYS_EXTRA_OPTIONS
> 
> This restores the errata configs.
> 
> Signed-off-by: Troy Kisky 
> 
> ---
> Note:
> marsboard, mx6qarm2, seem to have same problem.
> 
> v2: unchanged
> ---
>  arch/arm/mach-imx/mx6/Kconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm/mach-imx/mx6/Kconfig b/arch/arm/mach-imx/mx6/Kconfig
> index 00e3c486bc..3fa0b4b477 100644
> --- a/arch/arm/mach-imx/mx6/Kconfig
> +++ b/arch/arm/mach-imx/mx6/Kconfig
> @@ -417,6 +417,7 @@ config TARGET_NITROGEN6X
>   imply USB_ETHER_MCS7830
>   imply USB_ETHER_SMSC95XX
>   imply USB_HOST_ETHER
> + select MX6QDL
>  
>  config TARGET_OPOS6ULDEV
>   bool "Armadeus OPOS6ULDev board"
> 

Could these two be applied for 2020.01?

Thanks
Troy


[PATCH 1/1] sunxi: remove __packed from struct sunxi_prcm_reg

2019-12-17 Thread Heinrich Schuchardt
struct sunxi_prcm_reg is naturally packed. There is no need to define it as
packed. Defining it as packed leads to compilation errors with GCC 9.2.1:

  CC  arch/arm/lib/reloc_arm_efi.o
arch/arm/cpu/armv7/sunxi/psci.c: In function ‘sunxi_cpu_set_power’:
:qarch/arm/cpu/armv7/sunxi/psci.c:163:21: error: taking address of packed
member of ‘struct sunxi_prcm_reg’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
  163 |  sunxi_power_switch(>cpu_pwr_clamp[cpu], >cpu_pwroff,
  | ^

Remove __packed attribute from struct sunxi_prcm_reg.

Signed-off-by: Heinrich Schuchardt 
---
 arch/arm/include/asm/arch-sunxi/prcm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/arch-sunxi/prcm.h 
b/arch/arm/include/asm/arch-sunxi/prcm.h
index 58a36895e6..767d1ff98d 100644
--- a/arch/arm/include/asm/arch-sunxi/prcm.h
+++ b/arch/arm/include/asm/arch-sunxi/prcm.h
@@ -202,7 +202,7 @@
 #ifndef __ASSEMBLY__
 #include 

-struct __packed sunxi_prcm_reg {
+struct sunxi_prcm_reg {
u32 cpus_cfg;   /* 0x000 */
u8 res0[0x8];   /* 0x004 */
u32 apb0_ratio; /* 0x00c */
--
2.24.0



Re: [PATCH v3 5/5] test/py: Create a test for launching UEFI binaries from FIT images

2019-12-17 Thread Heinrich Schuchardt

On 12/17/19 8:47 AM, Cristian Ciocaltea wrote:

This test verifies the implementation of the 'bootm' extension that
handles UEFI binaries inside FIT images (enabled via CONFIG_BOOTM_EFI).

Signed-off-by: Cristian Ciocaltea 
---
  test/py/tests/test_efi_fit.py | 233 ++
  1 file changed, 233 insertions(+)
  create mode 100644 test/py/tests/test_efi_fit.py

diff --git a/test/py/tests/test_efi_fit.py b/test/py/tests/test_efi_fit.py
new file mode 100644
index 00..52b415b198
--- /dev/null
+++ b/test/py/tests/test_efi_fit.py
@@ -0,0 +1,233 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019, Cristian Ciocaltea 
+
+# Test launching UEFI binaries from FIT images.
+
+import os
+import pytest
+import u_boot_utils as util
+
+# Define the parametrized ITS data to be used for FIT image generation.
+its_data = '''
+/dts-v1/;
+
+/ {
+description = "EFI image with FDT blob";
+#address-cells = <1>;
+
+images {
+efi {
+description = "Sandbox EFI";
+data = /incbin/("%(efi-bin)s");
+type = "%(kernel-type)s";
+arch = "sandbox";
+os = "efi";
+compression = "%(efi-comp)s";
+load = <0x0>;
+entry = <0x0>;
+};
+fdt {
+description = "Sandbox FDT";
+data = /incbin/("%(fdt-bin)s");
+type = "flat_dt";
+arch = "sandbox";
+compression = "%(fdt-comp)s";
+};
+};
+
+configurations {
+default = "config-efi-fdt";
+config-efi-fdt {
+description = "EFI FIT w/ FDT";
+kernel = "efi";
+fdt = "fdt";
+};
+config-efi-nofdt {
+description = "EFI FIT w/o FDT";
+kernel = "efi";
+};
+};
+};
+'''
+
+# Define the parametrized FDT data.
+fdt_data = '''
+/dts-v1/;
+
+/ {
+model = "Sandbox %(fdt_type) EFI FIT Boot Test ";
+compatible = "sandbox";
+
+reset@0 {
+compatible = "sandbox,reset";


This produces a warning:

+dtc ./test-efi-fit-sandbox-internal.dts -O dtb -o
./test-efi-fit-sandbox-internal.dtb
./test-efi-fit-sandbox-internal.dts:8.13-10.7: Warning
(unit_address_vs_reg): /reset@0: node has a unit name, but no reg property


+};
+};
+'''
+
+@pytest.mark.boardspec('sandbox')


This test looks ok in principal. But why should we restrict it to the
sandbox?

Best regards

Heinrich


+@pytest.mark.buildconfigspec('bootm_efi')
+@pytest.mark.buildconfigspec('cmd_bootefi_hello_compile')
+@pytest.mark.requiredtool('dtc')
+def test_efi_fit(u_boot_console):
+"""Test handling of UEFI binaries inside FIT images.
+
+The tests are trying to launch U-Boot's helloworld.efi embedded into
+FIT images, in uncompressed or gzip compressed format.
+
+Additionally, a sample FDT blob is created and embedded into the above
+mentioned FIT images, in uncompressed or gzip compressed format.
+
+The following test cases are currently defined and enabled:
+- Launch uncompressed FIT EFI & FIT FDT
+- Launch compressed FIT EFI & FIT FDT
+- Launch uncompressed FIT EFI & internal FDT
+- Launch compressed FIT EFI & internal FDT
+"""
+
+def make_fpath(fname):
+"""Compute the path of a given (temporary) file.
+
+Args:
+fname: The name of a file within U-Boot build dir.
+Return:
+The computed file path.
+"""
+return os.path.join(u_boot_console.config.build_dir, fname)
+
+def make_efi(fname, comp):
+"""Create an UEFI binary.
+
+This simply copies lib/efi_loader/helloworld.efi into U-Boot
+build dir and, optionally, compresses the file using gzip.
+
+Args:
+fname: The target file name within U-Boot build dir.
+comp: Flag to enable gzip compression.
+Return:
+The path of the created file.
+"""
+bin_path = make_fpath(fname)
+os.system('cp %s %s' % (make_fpath('lib/efi_loader/helloworld.efi'), 
bin_path))
+if comp:
+util.run_and_log(u_boot_console, ['gzip', '-f', bin_path])
+bin_path += '.gz'
+return bin_path
+
+def make_dtb(fdt_type, comp):
+"""Create a sample DTB file.
+
+Creates a DTS file and compiles it to a DTB.
+
+Args:
+fdt_type: The type of the FDT, i.e. internal, user.
+comp: Flag to enable gzip compression.
+Returns:
+The path of the created file.
+"""
+dts = make_fpath('test-efi-fit-sandbox-%s.dts' % fdt_type)
+dtb = make_fpath('test-efi-fit-sandbox-%s.dtb' % fdt_type)
+with open(dts, 'w') as fd:
+fd.write(fdt_data)
+util.run_and_log(u_boot_console, ['dtc', dts, '-O', 'dtb', '-o', dtb])
+if comp:
+util.run_and_log(u_boot_console, ['gzip', '-f', dtb])
+dtb += '.gz'
+return dtb
+
+def 

Re: [PATCH v3 2/5] bootm: Add a bootm command for type IH_OS_EFI

2019-12-17 Thread Heinrich Schuchardt

On 12/17/19 8:46 AM, Cristian Ciocaltea wrote:

Add support for booting EFI binaries contained in FIT images.
A typical usage scenario is chain-loading GRUB2 in a verified
boot environment.

Signed-off-by: Cristian Ciocaltea 


You missed the current changes in common/bootm_os.c. I will rebase the
patch.

Reviewed-by: Heinrich Schuchardt 


Re: [PATCH v3 1/5] image: Add IH_OS_EFI for EFI chain-load boot

2019-12-17 Thread Heinrich Schuchardt

On 12/17/19 8:46 AM, Cristian Ciocaltea wrote:

Add a new OS type to be used for chain-loading an EFI compatible
firmware or boot loader like GRUB2, possibly in a verified boot
scenario.

Bellow is sample ITS file that generates a FIT image supporting
secure boot. Please note the presence of 'os = "efi";' line, which
identifies the currently introduced OS type:

/ {
 #address-cells = <1>;

 images {
 efi-grub {
 description = "GRUB EFI";
 data = /incbin/("bootarm.efi");
 type = "kernel_noload";
 arch = "arm";
 os = "efi";
 compression = "none";
 load = <0x0>;
 entry = <0x0>;
 hash-1 {
 algo = "sha256";
 };
 };
 };

 configurations {
 default = "config-grub";
 config-grub {
 kernel = "efi-grub";
 signature-1 {
 algo = "sha256,rsa2048";
 sign-images = "kernel";
 };
 };
 };
};

Signed-off-by: Cristian Ciocaltea 


Reviewed-by: Heinrich Schuchardt 


Re: [PATCH 1/1] usb: avoid -Werror=address-of-packed-member

2019-12-17 Thread Marek Vasut
On 12/17/19 8:32 PM, Heinrich Schuchardt wrote:
> On 12/17/19 1:19 PM, Marek Vasut wrote:
>> On 12/17/19 12:59 PM, Heinrich Schuchardt wrote:
>>> On 12/17/19 12:19 PM, Marek Vasut wrote:
 On 12/17/19 12:14 PM, Heinrich Schuchardt wrote:
> On 12/17/19 11:00 AM, Marek Vasut wrote:
>> On 12/17/19 10:27 AM, Heinrich Schuchardt wrote:
>>> With GCC 9.2.1 errors of type -Werror=address-of-packed-member occur
>>> when
>>> passing a member of a packed structure to le16_to_cpus() on a big
>>> endian
>>> system (e.g. P2041RDB_defconfig).
>>>
>>> Replace le16_to_cpus() by get_unaligned_le16(). Check
>>> defined(__BIG_ENDIAN)
>>> to avoid the introduction of unnecessary instructions on little
>>> endian
>>> systems as seen on aarch64.
>>
>> I would expect the compiler would optimize such stuff out ?
>> Can we do without the ifdef ?
>
> When compiling qemu_arm64_defconfig without the #ifdef the GCC 9.2.1
> adds assembler instructions:

 Why ?

>>>
>>> I am not a GCC developer. I simply observed that GCC currently cannot
>>> optimize this away on its own. That is why I added the #ifdef.
>>
>> Are we now adding workarounds instead of solving issues properly?
>>
>>> Identifying that bit operations like << 8 in __get_unaligned_le16() have
>>> zero effect is not an easy task when developing a compiler. You would
>>> have to follow the flow of every bit.
>>
>> Maybe the fix is then to somehow optimize the get_unaligned_le16() to
>> help the compiler ?
> 
> Inside get_unaligned_le16() it is not known that we will be reassigning
> to the same memory location. So I cannot imagine what to improve here.
> 
> You could invent new functions for in place byte swapping. But that
> would only move the #ifdef to a different place.

Isn't there already such a function in Linux ?

Also, why would you need the ifdef if the compiler would now know that
the operation is noop ?


Re: [PATCH 1/1] usb: avoid -Werror=address-of-packed-member

2019-12-17 Thread Heinrich Schuchardt

On 12/17/19 1:19 PM, Marek Vasut wrote:

On 12/17/19 12:59 PM, Heinrich Schuchardt wrote:

On 12/17/19 12:19 PM, Marek Vasut wrote:

On 12/17/19 12:14 PM, Heinrich Schuchardt wrote:

On 12/17/19 11:00 AM, Marek Vasut wrote:

On 12/17/19 10:27 AM, Heinrich Schuchardt wrote:

With GCC 9.2.1 errors of type -Werror=address-of-packed-member occur
when
passing a member of a packed structure to le16_to_cpus() on a big
endian
system (e.g. P2041RDB_defconfig).

Replace le16_to_cpus() by get_unaligned_le16(). Check
defined(__BIG_ENDIAN)
to avoid the introduction of unnecessary instructions on little endian
systems as seen on aarch64.


I would expect the compiler would optimize such stuff out ?
Can we do without the ifdef ?


When compiling qemu_arm64_defconfig without the #ifdef the GCC 9.2.1
adds assembler instructions:


Why ?



I am not a GCC developer. I simply observed that GCC currently cannot
optimize this away on its own. That is why I added the #ifdef.


Are we now adding workarounds instead of solving issues properly?


Identifying that bit operations like << 8 in __get_unaligned_le16() have
zero effect is not an easy task when developing a compiler. You would
have to follow the flow of every bit.


Maybe the fix is then to somehow optimize the get_unaligned_le16() to
help the compiler ?


Inside get_unaligned_le16() it is not known that we will be reassigning
to the same memory location. So I cannot imagine what to improve here.

You could invent new functions for in place byte swapping. But that
would only move the #ifdef to a different place.

Best regards

Heinrich


Re: [PATCH] cmd_ut: add a parameter prefix to the function cmd_ut_category

2019-12-17 Thread Heinrich Schuchardt

On 12/17/19 7:07 PM, Philippe Reynes wrote:

There is black magic in the file conftest.py that list
all the test unit. Then, all those test unit are called
in pytest. This call is done with the end of the name
(for example checksum if the full name is bloblist_test_checksum).

The result is that only test for dm are really executed.
by pytest, all others tests are listed but never executed.

This behaviour happens because the dm test unit only check
the end of the name and others tests checks the full name.

To fix this issue, I've added a prefix to the function
cmd_ut_category, and this prefix is removed when looking
for the unit test.

Signed-off-by: Philippe Reynes
---


I added a bug into the test/unicode_ut.c by inverting the logical
condition of an assert.

The 'ut all' command inside the sandbox reports the error with and
without this patch.

The problem was not reported without your patch when running 'make
tests'. With the patch it is reported by 'make tests'.

Tested-by: Heinrich Schuchardt 

Cc-ing Tom as maintainer of REST


Re: [U-Boot] [PATCH] net/phy: Fix phy_connect() for phy addr 0

2019-12-17 Thread Marek Vasut
On 12/17/19 7:47 PM, Joe Hershberger wrote:
> On Tue, Dec 17, 2019 at 11:46 AM Marek Vasut  wrote:
>>
>> On 12/17/19 5:25 PM, Joe Hershberger wrote:
>>> Hi Marek,
>>
>> Hi Joe,
>>
>>> On Tue, Dec 17, 2019 at 1:39 AM Marek Vasut  wrote:

 On 11/7/19 9:04 PM, Joe Hershberger wrote:
> On Thu, Nov 7, 2019 at 1:16 PM Tom Rini  wrote:
>>
>> On Tue, Nov 05, 2019 at 04:05:11AM +, Priyanka Jain wrote:
>>
>>> Fix 'mask' calculation in phy_connect() for phy addr '0'.
>>> 'mask' is getting set to '0x' for phy addr '0'
>>> in phy_connect() whereas expected value is '0'.
>>>
>>>
>>> Signed-off-by: Priyanka Jain 
>>
>> Reported-by: tetsu-aoki via github
>
> Acked-by: Joe Hershberger 

 Sadly, this breaks systems where a PHY is at address 0.
 I have such an STM32MP1 system with LAN8720 PHY and since this patch, I
 cannot use ethernet. Please revert.
>>>
>>> It seems like a case that shouldn't have worked before.
>>
>> Eh? PHY at address 0 definitely did work before and must work now.
> 
> Agreed that a phy at address 0 should work. Not agreed that because
> the value "0" used to work due to a bug that it must still. Which of
> these is the statement you are making? Do we already agree or
> disagree?

I am saying that because a board worked on rc4 and does not work on rc5,
this is a bug introduced by this patch in rc5 and must be fixed before
the release.

The address 0 is a PHY broadcast address for some PHYs, it's a fixed
address for other PHYs. Thus, a PHY at address 0 must work. If this is
broken now, it's a bug.

>>> What about
>>> this board requires the mask to be all 'f's, other than specifying the
>>> wrong phy address? It seems that in your case the phy address is not
>>> actually 0 (or the computed mask would find it), but your board dts
>>> may be setting it to 0 as an "unknown" value, but the correct unknown
>>> value should be "-1". It seems the issue is with these boards.
>>
>> Nope, the address is actually configured to 0 in hardware.
> 
> Can you double check that?

No, sorry, I know the hardware is fixed to 0. Checking it again will not
change this fact.

> The code as is should compute a mask of
> "0x01" which should match the offset for address 0. If it really is at
> 0 in hardware, maybe there is a different bug. Otherwise I don't see
> how this patch would work for the author.

Reverting this patch makes things work again for me.


Re: [U-Boot] [PATCH] net/phy: Fix phy_connect() for phy addr 0

2019-12-17 Thread Joe Hershberger
On Tue, Dec 17, 2019 at 11:46 AM Marek Vasut  wrote:
>
> On 12/17/19 5:25 PM, Joe Hershberger wrote:
> > Hi Marek,
>
> Hi Joe,
>
> > On Tue, Dec 17, 2019 at 1:39 AM Marek Vasut  wrote:
> >>
> >> On 11/7/19 9:04 PM, Joe Hershberger wrote:
> >>> On Thu, Nov 7, 2019 at 1:16 PM Tom Rini  wrote:
> 
>  On Tue, Nov 05, 2019 at 04:05:11AM +, Priyanka Jain wrote:
> 
> > Fix 'mask' calculation in phy_connect() for phy addr '0'.
> > 'mask' is getting set to '0x' for phy addr '0'
> > in phy_connect() whereas expected value is '0'.
> >
> >
> > Signed-off-by: Priyanka Jain 
> 
>  Reported-by: tetsu-aoki via github
> >>>
> >>> Acked-by: Joe Hershberger 
> >>
> >> Sadly, this breaks systems where a PHY is at address 0.
> >> I have such an STM32MP1 system with LAN8720 PHY and since this patch, I
> >> cannot use ethernet. Please revert.
> >
> > It seems like a case that shouldn't have worked before.
>
> Eh? PHY at address 0 definitely did work before and must work now.

Agreed that a phy at address 0 should work. Not agreed that because
the value "0" used to work due to a bug that it must still. Which of
these is the statement you are making? Do we already agree or
disagree?

> > What about
> > this board requires the mask to be all 'f's, other than specifying the
> > wrong phy address? It seems that in your case the phy address is not
> > actually 0 (or the computed mask would find it), but your board dts
> > may be setting it to 0 as an "unknown" value, but the correct unknown
> > value should be "-1". It seems the issue is with these boards.
>
> Nope, the address is actually configured to 0 in hardware.

Can you double check that? The code as is should compute a mask of
"0x01" which should match the offset for address 0. If it really is at
0 in hardware, maybe there is a different bug. Otherwise I don't see
how this patch would work for the author.

Thanks,
-Joe


Re: [PATCH 14/20] serial_lpuart: add clock enable if CONFIG_CLK is defined

2019-12-17 Thread Giulio Benetti

Hi Lukasz and all,

On 12/10/19 12:48 AM, Lukasz Majewski wrote:

On Mon, 9 Dec 2019 16:20:10 +0100
Giulio Benetti  wrote:


Hi Lukasz,

On 12/8/19 3:52 PM, Lukasz Majewski wrote:

On Wed,  4 Dec 2019 18:44:33 +0100
Giulio Benetti  wrote:
   

This driver assumes that lpuart clock is already enabled before
probing but using DM only lpuart won't be automatically enabled so
add clk_enable() when probing if CONFIG_CLK is defined.

Signed-off-by: Giulio Benetti
 ---
   drivers/serial/serial_lpuart.c | 13 +
   1 file changed, 13 insertions(+)

diff --git a/drivers/serial/serial_lpuart.c
b/drivers/serial/serial_lpuart.c index 4b0a964d1b..52bd2baf7d
100644 --- a/drivers/serial/serial_lpuart.c
+++ b/drivers/serial/serial_lpuart.c
@@ -483,6 +483,19 @@ static int lpuart_serial_pending(struct
udevice *dev, bool input)
   static int lpuart_serial_probe(struct udevice *dev)
   {
+#if CONFIG_IS_ENABLED(CLK)
+   struct clk per_clk;
+   int ret;
+
+   ret = clk_get_by_name(dev, "per", _clk);


While adding support for OF_PLATDATA, I've realized that when using 
OF_PLATDATA I can only use clk_get_by_index_platdata() but often imx 
peripheral drivers(as done in Linux) get clock by name("per" clock) 
instead of other clock sources. So here the problem is that I can't know 
for sure which id "per" clock source will have. I wouldn't use 0 as 
default clock-id since it's not sure "per" will be the 0 index.

And this will occur for fsl_esdhc_imx.c driver too.

Do you have any suggestions?

Thanks in advance

Best regards
--
Giulio Benetti
Benetti Engineering sas


[PATCH] cmd_ut: add a parameter prefix to the function cmd_ut_category

2019-12-17 Thread Philippe Reynes
There is black magic in the file conftest.py that list
all the test unit. Then, all those test unit are called
in pytest. This call is done with the end of the name
(for example checksum if the full name is bloblist_test_checksum).

The result is that only test for dm are really executed.
by pytest, all others tests are listed but never executed.

This behaviour happens because the dm test unit only check
the end of the name and others tests checks the full name.

To fix this issue, I've added a prefix to the function
cmd_ut_category, and this prefix is removed when looking
for the unit test.

Signed-off-by: Philippe Reynes 
---
 include/test/suites.h |  4 +++-
 test/bloblist.c   |  3 ++-
 test/cmd_ut.c | 12 ++--
 test/compression.c|  3 ++-
 test/env/cmd_ut_env.c |  3 ++-
 test/lib/cmd_ut_lib.c |  2 +-
 test/optee/cmd_ut_optee.c |  6 +++---
 test/overlay/cmd_ut_overlay.c |  2 +-
 test/unicode_ut.c |  3 ++-
 9 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/include/test/suites.h b/include/test/suites.h
index 20970f0..0748185 100644
--- a/include/test/suites.h
+++ b/include/test/suites.h
@@ -13,6 +13,7 @@ struct unit_test;
  * cmd_ut_category() - Run a category of unit tests
  *
  * @name:  Category name
+ * @prefix:Prefix of test name
  * @tests: List of tests to run
  * @n_ents:Number of tests in @tests
  * @argc:  Argument count provided. Must be >= 1. If this is 1 then all
@@ -20,7 +21,8 @@ struct unit_test;
  * @argv:  Arguments: argv[1] is the test to run (if @argc >= 2)
  * @return 0 if OK, CMD_RET_FAILURE on failure
  */
-int cmd_ut_category(const char *name, struct unit_test *tests, int n_ents,
+int cmd_ut_category(const char *name, const char *prefix,
+   struct unit_test *tests, int n_ents,
int argc, char * const argv[]);
 
 int do_ut_bloblist(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
diff --git a/test/bloblist.c b/test/bloblist.c
index 89bdb01..d0f7296 100644
--- a/test/bloblist.c
+++ b/test/bloblist.c
@@ -183,5 +183,6 @@ int do_ut_bloblist(cmd_tbl_t *cmdtp, int flag, int argc, 
char *const argv[])
 bloblist_test);
const int n_ents = ll_entry_count(struct unit_test, bloblist_test);
 
-   return cmd_ut_category("bloblist", tests, n_ents, argc, argv);
+   return cmd_ut_category("bloblist", "bloblist_test_",
+  tests, n_ents, argc, argv);
 }
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 2781f8b..400719e 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -11,17 +11,25 @@
 
 static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const 
argv[]);
 
-int cmd_ut_category(const char *name, struct unit_test *tests, int n_ents,
+int cmd_ut_category(const char *name, const char *prefix,
+   struct unit_test *tests, int n_ents,
int argc, char * const argv[])
 {
struct unit_test_state uts = { .fail_count = 0 };
struct unit_test *test;
+   int prefix_len = prefix ? strlen(prefix) : 0;
 
if (argc == 1)
printf("Running %d %s tests\n", n_ents, name);
 
for (test = tests; test < tests + n_ents; test++) {
-   if (argc > 1 && strcmp(argv[1], test->name))
+   const char *test_name = test->name;
+
+   /* Remove the prefix */
+   if (!strncmp(test_name, prefix, prefix_len))
+   test_name += prefix_len;
+
+   if (argc > 1 && strcmp(argv[1], test_name))
continue;
printf("Test: %s\n", test->name);
 
diff --git a/test/compression.c b/test/compression.c
index 48dccc0..cf040d7 100644
--- a/test/compression.c
+++ b/test/compression.c
@@ -540,5 +540,6 @@ int do_ut_compression(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 compression_test);
const int n_ents = ll_entry_count(struct unit_test, compression_test);
 
-   return cmd_ut_category("compression", tests, n_ents, argc, argv);
+   return cmd_ut_category("compression", "compression_test_",
+  tests, n_ents, argc, argv);
 }
diff --git a/test/env/cmd_ut_env.c b/test/env/cmd_ut_env.c
index 54041a0..ad67dbe 100644
--- a/test/env/cmd_ut_env.c
+++ b/test/env/cmd_ut_env.c
@@ -15,5 +15,6 @@ int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * 
const argv[])
struct unit_test *tests = ll_entry_start(struct unit_test, env_test);
const int n_ents = ll_entry_count(struct unit_test, env_test);
 
-   return cmd_ut_category("environment", tests, n_ents, argc, argv);
+   return cmd_ut_category("environment", "env_test_",
+  tests, n_ents, argc, argv);
 }
diff --git a/test/lib/cmd_ut_lib.c b/test/lib/cmd_ut_lib.c
index eb90e53..c73e8d7 100644
--- 

Re: [U-Boot] [PATCH] net/phy: Fix phy_connect() for phy addr 0

2019-12-17 Thread Marek Vasut
On 12/17/19 5:25 PM, Joe Hershberger wrote:
> Hi Marek,

Hi Joe,

> On Tue, Dec 17, 2019 at 1:39 AM Marek Vasut  wrote:
>>
>> On 11/7/19 9:04 PM, Joe Hershberger wrote:
>>> On Thu, Nov 7, 2019 at 1:16 PM Tom Rini  wrote:

 On Tue, Nov 05, 2019 at 04:05:11AM +, Priyanka Jain wrote:

> Fix 'mask' calculation in phy_connect() for phy addr '0'.
> 'mask' is getting set to '0x' for phy addr '0'
> in phy_connect() whereas expected value is '0'.
>
>
> Signed-off-by: Priyanka Jain 

 Reported-by: tetsu-aoki via github
>>>
>>> Acked-by: Joe Hershberger 
>>
>> Sadly, this breaks systems where a PHY is at address 0.
>> I have such an STM32MP1 system with LAN8720 PHY and since this patch, I
>> cannot use ethernet. Please revert.
> 
> It seems like a case that shouldn't have worked before.

Eh? PHY at address 0 definitely did work before and must work now.

> What about
> this board requires the mask to be all 'f's, other than specifying the
> wrong phy address? It seems that in your case the phy address is not
> actually 0 (or the computed mask would find it), but your board dts
> may be setting it to 0 as an "unknown" value, but the correct unknown
> value should be "-1". It seems the issue is with these boards.

Nope, the address is actually configured to 0 in hardware.


Re: [U-Boot] [PATCH] net/phy: Fix phy_connect() for phy addr 0

2019-12-17 Thread Joe Hershberger
Hi Marek,

On Tue, Dec 17, 2019 at 1:39 AM Marek Vasut  wrote:
>
> On 11/7/19 9:04 PM, Joe Hershberger wrote:
> > On Thu, Nov 7, 2019 at 1:16 PM Tom Rini  wrote:
> >>
> >> On Tue, Nov 05, 2019 at 04:05:11AM +, Priyanka Jain wrote:
> >>
> >>> Fix 'mask' calculation in phy_connect() for phy addr '0'.
> >>> 'mask' is getting set to '0x' for phy addr '0'
> >>> in phy_connect() whereas expected value is '0'.
> >>>
> >>>
> >>> Signed-off-by: Priyanka Jain 
> >>
> >> Reported-by: tetsu-aoki via github
> >
> > Acked-by: Joe Hershberger 
>
> Sadly, this breaks systems where a PHY is at address 0.
> I have such an STM32MP1 system with LAN8720 PHY and since this patch, I
> cannot use ethernet. Please revert.

It seems like a case that shouldn't have worked before. What about
this board requires the mask to be all 'f's, other than specifying the
wrong phy address? It seems that in your case the phy address is not
actually 0 (or the computed mask would find it), but your board dts
may be setting it to 0 as an "unknown" value, but the correct unknown
value should be "-1". It seems the issue is with these boards.

Cheers,
-Joe


i.MX8QXP MEK does not boot with latest U-Boot

2019-12-17 Thread Fabio Estevam
Hi Peng,

I am trying to boot the latest U-Boot mainline on a imx8qxp mek board
and this is what I get:

U-Boot SPL 2020.01-rc5-1-g3dd6a9300b-dirty (Dec 17 2019 - 12:33:57 -0300)
Normal Boot
WDT:   Not found!
Trying to boot from MMC2_2
Load image from MMC/SD 0x46800

U-Boot 2020.01-rc5-1-g3dd6a9300b-dirty (Dec 17 2019 - 12:33:57 -0300)

CPU:   NXP i.MX8QXP RevB A35 at 1200 MHz at 31C

Model: Freescale i.MX8QXP MEK
Board: iMX8QXP MEK
Build: SCFW 550f3079, SECO-FW d7523fe8, ATF f92d379
Boot:  SD1
DRAM:  3 GiB
Failed to enable ipg clk
MMC:   FSL_SDHC: 0, FSL_SDHC: 1
Loading Environment from MMC... *** Warning - bad CRC, using default environment

In:serial@5a06
Out:   serial@5a06
Err:   serial@5a06
Net:   Failed to enable ipg clk

Error: ethernet@5b04 address not set.

(It hangs here).

I am using the SC and seco firmware from the 4.19.35 release.

Here is the updated README that I am following:
http://code.bulix.org/i8bhp8-1018627

Any ideas as to how to fix this boot problem?

Thanks


Re: [PATCH v3] board_f.c: Insure gd->new_bootstage alignment

2019-12-17 Thread Simon Glass
Hi Patrice,

On Wed, 27 Nov 2019 at 02:11, Patrice Chotard  wrote:
>
> In reserve_bootstage(), in case size is odd, gd->new_bootstage
> is not aligned. In bootstage_relocate(), the platform hangs when
> getting access to data->record[i].name.
> To avoid this issue, make gd->new_bootstage 16 byte aligned.
>
> To insure that new_bootstage is 16 byte aligned (at least needed for
> x86_64 and ARMv8) and new_bootstage starts down to get enough space,
> ALIGN_DOWN macro is used.
>
> Fixes: ac9cd4805c8b ("bootstage: Correct relocation algorithm")
>
> Signed-off-by: Patrice Chotard 
> Reviewed-by: Vikas MANOCHA 
> Reviewed-by: Patrick Delaunay 
> Tested-by: Patrick Delaunay 

For this patch I think it would be better to update reserve_fdt() to
keep things aligned, assuming that is the problem.

At some point we should also document that reservations must keep
things aligned.

Perhaps this should be handled by a separate function called from all
these places, which subtracts gd->start_addr_sp and ensures 16-byte
alignment.

Regards,
Simon


[PATCH] arm64: zynqmp: Move PANIC to Kconfig

2019-12-17 Thread Michal Simek
Convert another option Kconfig.

Reported-by: Robert P. J. Day 
Signed-off-by: Michal Simek 
---

 configs/avnet_ultrazedev_cc_v1_0_ultrazedev_som_v1_0_defconfig | 1 +
 configs/xilinx_zynqmp_mini_defconfig   | 1 +
 configs/xilinx_zynqmp_mini_emmc0_defconfig | 1 +
 configs/xilinx_zynqmp_mini_emmc1_defconfig | 1 +
 configs/xilinx_zynqmp_mini_nand_defconfig  | 1 +
 configs/xilinx_zynqmp_mini_nand_single_defconfig   | 1 +
 configs/xilinx_zynqmp_mini_qspi_defconfig  | 1 +
 configs/xilinx_zynqmp_virt_defconfig   | 1 +
 configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig   | 1 +
 configs/xilinx_zynqmp_zc1751_xm017_dc3_defconfig   | 1 +
 include/configs/xilinx_zynqmp.h| 1 -
 11 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/configs/avnet_ultrazedev_cc_v1_0_ultrazedev_som_v1_0_defconfig 
b/configs/avnet_ultrazedev_cc_v1_0_ultrazedev_som_v1_0_defconfig
index 280983d187a1..71e0d2726ed0 100644
--- a/configs/avnet_ultrazedev_cc_v1_0_ultrazedev_som_v1_0_defconfig
+++ b/configs/avnet_ultrazedev_cc_v1_0_ultrazedev_som_v1_0_defconfig
@@ -56,5 +56,6 @@ CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_ZYNQ_SERIAL=y
 CONFIG_SPI=y
 CONFIG_ZYNQMP_GQSPI=y
+CONFIG_PANIC_HANG=y
 CONFIG_OF_LIBFDT_OVERLAY=y
 CONFIG_EFI_LOADER_BOUNCE_BUFFER=y
diff --git a/configs/xilinx_zynqmp_mini_defconfig 
b/configs/xilinx_zynqmp_mini_defconfig
index e861cf691056..d953c91a66ed 100644
--- a/configs/xilinx_zynqmp_mini_defconfig
+++ b/configs/xilinx_zynqmp_mini_defconfig
@@ -49,4 +49,5 @@ CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 # CONFIG_DM_WARN is not set
 # CONFIG_DM_DEVICE_REMOVE is not set
 # CONFIG_MMC is not set
+CONFIG_PANIC_HANG=y
 # CONFIG_EFI_LOADER is not set
diff --git a/configs/xilinx_zynqmp_mini_emmc0_defconfig 
b/configs/xilinx_zynqmp_mini_emmc0_defconfig
index 644223633bc7..cb2983d2476e 100644
--- a/configs/xilinx_zynqmp_mini_emmc0_defconfig
+++ b/configs/xilinx_zynqmp_mini_emmc0_defconfig
@@ -55,4 +55,5 @@ CONFIG_SPL_DM_SEQ_ALIAS=y
 CONFIG_SUPPORT_EMMC_BOOT=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_ZYNQ=y
+CONFIG_PANIC_HANG=y
 # CONFIG_EFI_LOADER is not set
diff --git a/configs/xilinx_zynqmp_mini_emmc1_defconfig 
b/configs/xilinx_zynqmp_mini_emmc1_defconfig
index 5b468f1cfab6..f7bec364c386 100644
--- a/configs/xilinx_zynqmp_mini_emmc1_defconfig
+++ b/configs/xilinx_zynqmp_mini_emmc1_defconfig
@@ -55,4 +55,5 @@ CONFIG_SPL_DM_SEQ_ALIAS=y
 CONFIG_SUPPORT_EMMC_BOOT=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_ZYNQ=y
+CONFIG_PANIC_HANG=y
 # CONFIG_EFI_LOADER is not set
diff --git a/configs/xilinx_zynqmp_mini_nand_defconfig 
b/configs/xilinx_zynqmp_mini_nand_defconfig
index d490f357b7ac..01e097199155 100644
--- a/configs/xilinx_zynqmp_mini_nand_defconfig
+++ b/configs/xilinx_zynqmp_mini_nand_defconfig
@@ -51,4 +51,5 @@ CONFIG_MTD=y
 CONFIG_MTD_RAW_NAND=y
 CONFIG_NAND_ARASAN=y
 CONFIG_SYS_NAND_MAX_CHIPS=2
+CONFIG_PANIC_HANG=y
 # CONFIG_EFI_LOADER is not set
diff --git a/configs/xilinx_zynqmp_mini_nand_single_defconfig 
b/configs/xilinx_zynqmp_mini_nand_single_defconfig
index 21aafe1d275e..20e76cb11e8b 100644
--- a/configs/xilinx_zynqmp_mini_nand_single_defconfig
+++ b/configs/xilinx_zynqmp_mini_nand_single_defconfig
@@ -50,4 +50,5 @@ CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_MTD=y
 CONFIG_MTD_RAW_NAND=y
 CONFIG_NAND_ARASAN=y
+CONFIG_PANIC_HANG=y
 # CONFIG_EFI_LOADER is not set
diff --git a/configs/xilinx_zynqmp_mini_qspi_defconfig 
b/configs/xilinx_zynqmp_mini_qspi_defconfig
index 902dceb0f622..c6e03cd256d4 100644
--- a/configs/xilinx_zynqmp_mini_qspi_defconfig
+++ b/configs/xilinx_zynqmp_mini_qspi_defconfig
@@ -62,4 +62,5 @@ CONFIG_SPI_FLASH_WINBOND=y
 # CONFIG_SPI_FLASH_USE_4K_SECTORS is not set
 CONFIG_SPI=y
 CONFIG_ZYNQMP_GQSPI=y
+CONFIG_PANIC_HANG=y
 # CONFIG_EFI_LOADER is not set
diff --git a/configs/xilinx_zynqmp_virt_defconfig 
b/configs/xilinx_zynqmp_virt_defconfig
index 4047475d3c11..ab46d16791ab 100644
--- a/configs/xilinx_zynqmp_virt_defconfig
+++ b/configs/xilinx_zynqmp_virt_defconfig
@@ -123,6 +123,7 @@ CONFIG_USB_HOST_ETHER=y
 CONFIG_USB_ETHER_ASIX=y
 CONFIG_WDT=y
 CONFIG_WDT_CDNS=y
+CONFIG_PANIC_HANG=y
 CONFIG_SPL_GZIP=y
 CONFIG_OF_LIBFDT_OVERLAY=y
 CONFIG_EFI_LOADER_BOUNCE_BUFFER=y
diff --git a/configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig 
b/configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig
index ae85bb480526..0dfd38d46981 100644
--- a/configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig
+++ b/configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig
@@ -85,4 +85,5 @@ CONFIG_USB_GADGET_MANUFACTURER="Xilinx"
 CONFIG_USB_GADGET_VENDOR_NUM=0x03FD
 CONFIG_USB_GADGET_PRODUCT_NUM=0x0300
 CONFIG_USB_FUNCTION_THOR=y
+CONFIG_PANIC_HANG=y
 CONFIG_EFI_LOADER_BOUNCE_BUFFER=y
diff --git a/configs/xilinx_zynqmp_zc1751_xm017_dc3_defconfig 
b/configs/xilinx_zynqmp_zc1751_xm017_dc3_defconfig
index 3532ff27841a..6d27cc761fcc 100644
--- 

Re: xilinx_zynqmp.h: erroneous(?) "#define CONFIG_PANIC_HANG"

2019-12-17 Thread Michal Simek
On 17. 12. 19 15:17, Robert P. J. Day wrote:
> 
>   long story short, colleague came to me with a petalinux project
> wherein the compile of u-boot was failing due to a redefinition of the
> macro "CONFIG_PANIC_HANG" ... rather than mess with petalinux, i just
> set up the current master of u-boot (aarch64), used the same
> configuration and, sure enough:
> 
>   CC  lib/asm-offsets.s
> In file included from include/config.h:5,
>  from include/common.h:23,
>  from lib/asm-offsets.c:14:
> include/configs/xilinx_zynqmp.h:97: warning: "CONFIG_PANIC_HANG" redefined
>  #define CONFIG_PANIC_HANG
> 
> In file included from ././include/linux/kconfig.h:4,
>  from :
> include/generated/autoconf.h:410: note: this is the location of the previous 
> definition
>  #define CONFIG_PANIC_HANG 1
> 
>   it would *appear* that this is because xilinx_zynqmp.h defines:
> 
>   #define CONFIG_PANIC_HANG
> 
> but that symbol has been migrated to the Kconfig system, lib/Kconfig:
> 
>   config PANIC_HANG
> bool "Do not reset the system on fatal error"
>   help
> Define this option to stop the system in case of a fatal error,
> so that you have to reset it manually. This is probably NOT a good
> idea for an embedded system where you want the system to reboot
> automatically as fast as possible, but it may be useful during
> development since you can try to debug the conditions that lead to
> the situation.
> 
>   is it safe to assume that this is the problem? i can certainly see
> how that combination would generate two different macro definitions,
> and it's just our luck that it seems that is the only header file that
> does that.

It should be removed from include/configs/zynqmp.h to Kconfig.
I have created patch and building it now. Will send it shortly.

Thanks,
Michal


-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs




signature.asc
Description: OpenPGP digital signature


[PATCH] travis: Setup latest qemu version for Versal

2019-12-17 Thread Michal Simek
Qemu v4.2.0 maps bootmode registers to address space which was the reason
why board_late_init() was disabled and accesses were failing.

With new Qemu board_late_init() can be called without any issue.

Signed-off-by: Michal Simek 
---

Not sure which qemu version azure and gitlab are using but I think that
also make sense to move the whole travis to v4.2.
As of now I am sending this patch to open that discussion.
---
 .travis.yml  | 1 +
 configs/xilinx_versal_virt_defconfig | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 5da046ca7ed5..168455bd9f68 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -514,6 +514,7 @@ matrix:
 - TEST_PY_BD="xilinx_versal_virt"
   TEST_PY_TEST_SPEC="not sleep"
   QEMU_TARGET="aarch64-softmmu"
+  QEMU_VERSION="v4.2.0"
   TEST_PY_ID="--id qemu"
   BUILDMAN="^xilinx_versal_virt$"
 - name: "test/py xtfpga"
diff --git a/configs/xilinx_versal_virt_defconfig 
b/configs/xilinx_versal_virt_defconfig
index 11428e1e03c1..6488bca2c004 100644
--- a/configs/xilinx_versal_virt_defconfig
+++ b/configs/xilinx_versal_virt_defconfig
@@ -9,7 +9,6 @@ CONFIG_FIT_VERBOSE=y
 # CONFIG_ARCH_FIXUP_FDT_MEMORY is not set
 CONFIG_BOOTDELAY=5
 CONFIG_SUPPORT_RAW_INITRD=y
-# CONFIG_BOARD_LATE_INIT is not set
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_HUSH_PARSER=y
-- 
2.24.0



xilinx_zynqmp.h: erroneous(?) "#define CONFIG_PANIC_HANG"

2019-12-17 Thread Robert P. J. Day


  long story short, colleague came to me with a petalinux project
wherein the compile of u-boot was failing due to a redefinition of the
macro "CONFIG_PANIC_HANG" ... rather than mess with petalinux, i just
set up the current master of u-boot (aarch64), used the same
configuration and, sure enough:

  CC  lib/asm-offsets.s
In file included from include/config.h:5,
 from include/common.h:23,
 from lib/asm-offsets.c:14:
include/configs/xilinx_zynqmp.h:97: warning: "CONFIG_PANIC_HANG" redefined
 #define CONFIG_PANIC_HANG

In file included from ././include/linux/kconfig.h:4,
 from :
include/generated/autoconf.h:410: note: this is the location of the previous 
definition
 #define CONFIG_PANIC_HANG 1

  it would *appear* that this is because xilinx_zynqmp.h defines:

  #define CONFIG_PANIC_HANG

but that symbol has been migrated to the Kconfig system, lib/Kconfig:

  config PANIC_HANG
bool "Do not reset the system on fatal error"
  help
Define this option to stop the system in case of a fatal error,
so that you have to reset it manually. This is probably NOT a good
idea for an embedded system where you want the system to reboot
automatically as fast as possible, but it may be useful during
development since you can try to debug the conditions that lead to
the situation.

  is it safe to assume that this is the problem? i can certainly see
how that combination would generate two different macro definitions,
and it's just our luck that it seems that is the only header file that
does that.

rday



[PATCH] arm64: zynqmp: Fix emmc boot mode boot_target sequennce

2019-12-17 Thread Michal Simek
From: T Karthik Reddy 

Emmc boot devcie is mounted to mmc@ff16 controller on zynqmp.
Detect mmc alias at run time for setting up proper boot_targets
sequence instead of setting boot_targets manually.
Removed setting "modeboot" variable as it not longer need as we
switched to distro boot.

Signed-off-by: T Karthik Reddy 
Signed-off-by: Michal Simek 
---

 board/xilinx/zynqmp/zynqmp.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index aac2eb7bc1a2..b72eade43eea 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -580,8 +580,17 @@ int board_late_init(void)
break;
case EMMC_MODE:
puts("EMMC_MODE\n");
-   mode = "mmc0";
-   env_set("modeboot", "emmcboot");
+   if (uclass_get_device_by_name(UCLASS_MMC,
+ "mmc@ff16", ) &&
+   uclass_get_device_by_name(UCLASS_MMC,
+ "sdhci@ff16", )) {
+   puts("Boot from EMMC but without SD0 enabled!\n");
+   return -1;
+   }
+   debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
+
+   mode = "mmc";
+   bootseq = dev->seq;
break;
case SD_MODE:
puts("SD_MODE\n");
-- 
2.24.0



Re: [ANN] U-Boot v2020.01-rc5 released

2019-12-17 Thread Andy Shevchenko
On Mon, Dec 16, 2019 at 9:11 PM Jagan Teki  wrote:
> On Tue, Dec 17, 2019 at 12:21 AM Andy Shevchenko
>  wrote:
> > On Mon, Dec 16, 2019 at 2:41 PM Tom Rini  wrote:

...

> > Sorry to answering here (I already removed rc4 announce).
> >
> > The commit 6b7ebff00190649d2136b34f6feebc0dbe85bfdc
> > Author: Jagan Teki 
> > Date:   Tue Nov 19 13:56:20 2019 +0530
> >
> >usb: dwc3: Add phy interface for dwc3_uboot
> >
> > broke DFU on Intel Edison. Revert helps. (symptoms dfu-util stops
> > seeing device completely).
> > Please fix before release, or revert!
>
> Thanks for the notice, will come back for the fix or comments.

Okay, if you want me to test something, let me know soon, I will be
off for xmas holidays next two weeks.
Tom, if this is not going to be settled soon (till Friday), I ask to revert it.

-- 
With Best Regards,
Andy Shevchenko


Re: Please pull u-boot-x86/next to next branch

2019-12-17 Thread Bin Meng
Hi Tom,

On Tue, Dec 17, 2019 at 8:52 PM Tom Rini  wrote:
>
> On Sun, Dec 15, 2019 at 09:16:29PM +0800, Bin Meng wrote:
>
> > Hi Tom,
> >
> > This PR includes the following changes for u-boot/next branch.
> >
> > - Various x86 common codes updated for TPL/SPL
> > - I2C designware driver updated for PCI
> > - ICH SPI driver updated to support Apollo Lake
> > - Add Intel FSP2 base support
> > - Intel Apollo Lake platform specific drivers support
> > - Add a new board Google Chromebook Coral
> >
> > The following changes since commit 553cb06887825314e74a9bdac337467c77d1db88:
> >
> >   Merge tag 'dm-next-13dec19' of
> > https://gitlab.denx.de/u-boot/custodians/u-boot-dm into next
> > (2019-12-12 08:18:59 -0500)
> >
> > are available in the git repository at:
> >
> >   https://gitlab.denx.de/u-boot/custodians/u-boot-x86 next
> >
> > for you to fetch changes up to a1d6dc3f84071f05574044f337dbdca70fae495d:
> >
> >   x86: Add chromebook_coral (2019-12-15 11:44:30 +0800)
> >
>
> +(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) 
> ../drivers/misc/p2sb_emul.c: In function 'sandbox_p2sb_emul_map_physmem':
> +(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) 
> ../drivers/misc/p2sb_emul.c:236:6: error: 'child' may be used uninitialized 
> in this function [-Werror=maybe-uninitialized]
> +(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only)   ret = 
> axi_read(child, offset, priv->regs, AXI_SIZE_32);
> +(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only)   ^
> +(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) cc1: all 
> warnings being treated as errors
> +(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) make[3]: *** 
> [drivers/misc/p2sb_emul.o] Error 1
> +(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) make[2]: *** 
> [drivers/misc] Error 2
> +(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) make[1]: *** 
> [drivers] Error 2
>
> Is what I see with this applied, please address, thanks!
>

That's weird. As both GitLab and Azure did not complain anything. See:

https://gitlab.denx.de/u-boot/custodians/u-boot-x86/pipelines/1647
https://dev.azure.com/bmeng/GitHub/_build/results?buildId=146=results

Regards,
Bin


Re: [PATCH v5] mx7ulp: Add support for Embedded Artists COM board

2019-12-17 Thread Fabio Estevam
Hi Stefano,

On Mon, Dec 9, 2019 at 10:43 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 

Could this one be applied for 2020.01?

Thanks


Re: [U-Boot] [PATCH] net/phy: Fix phy_connect() for phy addr 0

2019-12-17 Thread Marek Vasut
On 12/17/19 1:52 PM, Tom Rini wrote:
> On Tue, Dec 17, 2019 at 08:38:48AM +0100, Marek Vasut wrote:
>> On 11/7/19 9:04 PM, Joe Hershberger wrote:
>>> On Thu, Nov 7, 2019 at 1:16 PM Tom Rini  wrote:

 On Tue, Nov 05, 2019 at 04:05:11AM +, Priyanka Jain wrote:

> Fix 'mask' calculation in phy_connect() for phy addr '0'.
> 'mask' is getting set to '0x' for phy addr '0'
> in phy_connect() whereas expected value is '0'.
>
>
> Signed-off-by: Priyanka Jain 

 Reported-by: tetsu-aoki via github
>>>
>>> Acked-by: Joe Hershberger 
>>
>> Sadly, this breaks systems where a PHY is at address 0.
>> I have such an STM32MP1 system with LAN8720 PHY and since this patch, I
>> cannot use ethernet. Please revert.
> 
> Well, a simple revert breaks the other boards that this fixes.  So we
> need to think about how to fix all of the cases involved here, thanks!

That's probably task for the author of the patch.

btw -rc4 worked fine, -rc5 does not work.


Re: [U-Boot] [PATCH] net/phy: Fix phy_connect() for phy addr 0

2019-12-17 Thread Tom Rini
On Tue, Dec 17, 2019 at 08:38:48AM +0100, Marek Vasut wrote:
> On 11/7/19 9:04 PM, Joe Hershberger wrote:
> > On Thu, Nov 7, 2019 at 1:16 PM Tom Rini  wrote:
> >>
> >> On Tue, Nov 05, 2019 at 04:05:11AM +, Priyanka Jain wrote:
> >>
> >>> Fix 'mask' calculation in phy_connect() for phy addr '0'.
> >>> 'mask' is getting set to '0x' for phy addr '0'
> >>> in phy_connect() whereas expected value is '0'.
> >>>
> >>>
> >>> Signed-off-by: Priyanka Jain 
> >>
> >> Reported-by: tetsu-aoki via github
> > 
> > Acked-by: Joe Hershberger 
> 
> Sadly, this breaks systems where a PHY is at address 0.
> I have such an STM32MP1 system with LAN8720 PHY and since this patch, I
> cannot use ethernet. Please revert.

Well, a simple revert breaks the other boards that this fixes.  So we
need to think about how to fix all of the cases involved here, thanks!

-- 
Tom


Re: Please pull u-boot-x86/next to next branch

2019-12-17 Thread Tom Rini
On Sun, Dec 15, 2019 at 09:16:29PM +0800, Bin Meng wrote:

> Hi Tom,
> 
> This PR includes the following changes for u-boot/next branch.
> 
> - Various x86 common codes updated for TPL/SPL
> - I2C designware driver updated for PCI
> - ICH SPI driver updated to support Apollo Lake
> - Add Intel FSP2 base support
> - Intel Apollo Lake platform specific drivers support
> - Add a new board Google Chromebook Coral
> 
> The following changes since commit 553cb06887825314e74a9bdac337467c77d1db88:
> 
>   Merge tag 'dm-next-13dec19' of
> https://gitlab.denx.de/u-boot/custodians/u-boot-dm into next
> (2019-12-12 08:18:59 -0500)
> 
> are available in the git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-x86 next
> 
> for you to fetch changes up to a1d6dc3f84071f05574044f337dbdca70fae495d:
> 
>   x86: Add chromebook_coral (2019-12-15 11:44:30 +0800)
> 

+(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) 
../drivers/misc/p2sb_emul.c: In function 'sandbox_p2sb_emul_map_physmem':
+(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) 
../drivers/misc/p2sb_emul.c:236:6: error: 'child' may be used uninitialized in 
this function [-Werror=maybe-uninitialized]
+(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only)   ret = 
axi_read(child, offset, priv->regs, AXI_SIZE_32);
+(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only)   ^
+(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) cc1: all warnings 
being treated as errors
+(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) make[3]: *** 
[drivers/misc/p2sb_emul.o] Error 1
+(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) make[2]: *** 
[drivers/misc] Error 2
+(sandbox,sandbox64,sandbox_flattree,sandbox_spl,tools-only) make[1]: *** 
[drivers] Error 2

Is what I see with this applied, please address, thanks!

-- 
Tom


Re: [PATCH v3] board_f.c: Insure gd->new_bootstage alignment

2019-12-17 Thread Tom Rini
On Mon, Dec 16, 2019 at 11:53:48AM +, Patrick DELAUNAY wrote:
> Hi Tom,
> 
> > From: Patrice CHOTARD 
> > Sent: mercredi 27 novembre 2019 10:12
> > 
> > In reserve_bootstage(), in case size is odd, gd->new_bootstage is not 
> > aligned. In
> > bootstage_relocate(), the platform hangs when getting access to data-
> > >record[i].name.
> > To avoid this issue, make gd->new_bootstage 16 byte aligned.
> > 
> > To insure that new_bootstage is 16 byte aligned (at least needed for
> > x86_64 and ARMv8) and new_bootstage starts down to get enough space,
> > ALIGN_DOWN macro is used.
> > 
> > Fixes: ac9cd4805c8b ("bootstage: Correct relocation algorithm")
> > 
> > Signed-off-by: Patrice Chotard 
> > Reviewed-by: Vikas MANOCHA 
> > Reviewed-by: Patrick Delaunay 
> > Tested-by: Patrick Delaunay 
> > 
> 
> Do you plan to merge this fixe for the next rc for v2020.01 ?
> Or do you expect some change / review.
>
> This patch is mandatory for stm32mp1 (ARM plaform with bootstage
> feature activated).
> Without this patch, the boot failed (at least for v2020.01-rc3 : crash
> has struct pointer new_bootstage is not aligned).
> 
> Or I will deactivate the BOOTSTAGE feature...
 
I think at this point I would prefer dropping BOOTSTAGE from those
boards for the release.  There's already been more than one "I think
this is safe" followed by "this broke ..." changes I've tried.  Sorry!

-- 
Tom


Re: [PATCH 17/17] imx: add i.MX8MN DDR4 board support

2019-12-17 Thread Fabio Estevam
Hi Peng,

On Mon, Sep 16, 2019 at 12:09 AM Peng Fan  wrote:
>
> Support pinctrl/clk/sdhc, include ddr4 timing data.
>
> Log:
> U-Boot SPL 2019.10-rc3-00356-g497c500423-dirty (Sep 16 2019 - 10:54:58 +0800)
> Normal Boot
> Trying to boot from BOOTROM
> image offset 0x8000, pagesize 0x200, ivt offset 0x0
>
> U-Boot 2019.10-rc3-00356-g497c500423-dirty (Sep 16 2019 - 10:54:58 +0800)
>
> CPU:   Freescale i.MX8MNano rev1.0 at 24 MHz

Is this reported frequency correct? Only 24MHz?

Could you please submit a README file for this board?

Thanks


[PATCH v1] mailmap: Update mail address for Igor Opaniuk

2019-12-17 Thread Igor Opaniuk
My address at Linaro doesn't exist anymore, so people
keep getting mail delivery error responses. Map this address
to the actual one.

Signed-off-by: Igor Opaniuk 
---

 .mailmap | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.mailmap b/.mailmap
index 98d2131e97..61802f97f6 100644
--- a/.mailmap
+++ b/.mailmap
@@ -29,6 +29,7 @@ Jagan Teki 
 Jagan Teki 
 Jagan Teki 
 Jagan Teki 
+Igor Opaniuk  
 Markus Klotzbuecher 
 Paul Burton  
 Prabhakar Kushwaha 
-- 
2.17.1



Query: Error: Unable to find signature node in Verified boot

2019-12-17 Thread Priyanka Singh
Hi,

I was trying to test the Verified boot feature on NXP's LX2160ARDB board and I 
am facing the following issue during the same: 

1. U-boot is unable to verify the signatures of the images and 
configurations. I added more logs to debug this issue and found that U-boot is 
unable to find the signature node and returns from common/image-sig.c line: 260.
Log snippet: 
Verifying Hash Integrity ... sha1,rsa2048:dev- OK

The signing of the images and configuration has been done using mkimage.

Can someone please suggest how can I correct this.

Thanks,
Priyanka Singh


[PATCH] include: fix 'ulong' definition on musl targets

2019-12-17 Thread Sergei Trofimovich
The build failure was originally reported on arm64-musl
target at https://bugs.gentoo.org/703132. Here is the amd64-musl
variant:

```
$ LANG=C make CROSS_COMPILE=x86_64-gentoo-linux-musl- tools-only_defconfig 
-j$(nproc)
$ LANG=C make CROSS_COMPILE=x86_64-gentoo-linux-musl- tools-all
-j$(nproc)
...
In file included from tools/env/../../env/flags.c:7,
 from tools/env/env_flags.c:1:
include/env.h:159:1: error: unknown type name 'ulong'; did you mean 'long'?
  159 | ulong env_get_ulong(const char *name, int base, ulong default_val);
  | ^
  | long
```

Note: 'ulong' is not defined there.

On glibc 'ulong' comes from :

```c
/* Old compatibility names for C types.  */
typedef unsigned long int ulong;
```

On musl it comes from  as well but from under different guards:

```c
typedef unsigned long u_long, ulong;
```

The change inlines 'ulong' define similar to 'uint' define.

Bug: https://bugs.gentoo.org/703132
Signed-off-by: Sergei Trofimovich 
---
 include/compiler.h   | 2 +-
 include/u-boot/crc.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/compiler.h b/include/compiler.h
index 29507f9840..90372f239c 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -46,7 +46,6 @@
 # include 
 #elif defined(__MACH__) || defined(__FreeBSD__)
 # include 
-typedef unsigned long ulong;
 #endif
 #ifdef __FreeBSD__
 # include  /* htole32 and friends */
@@ -66,6 +65,7 @@ typedef uint8_t __u8;
 typedef uint16_t __u16;
 typedef uint32_t __u32;
 typedef unsigned int uint;
+typedef unsigned long ulong;
 
 #define uswap_16(x) \
x) & 0xff00) >> 8) | \
diff --git a/include/u-boot/crc.h b/include/u-boot/crc.h
index 1086d2168c..b96b50d98b 100644
--- a/include/u-boot/crc.h
+++ b/include/u-boot/crc.h
@@ -8,6 +8,8 @@
 #ifndef _UBOOT_CRC_H
 #define _UBOOT_CRC_H
 
+#include  /* unit definition */
+
 /**
  * crc8() - Calculate and return CRC-8 of the data
  *
-- 
2.24.1



[RESEND PATCH 7/7] phy: phy-mtk-tphy: make ref clock optional

2019-12-17 Thread Chunfeng Yun
If make the ref clock optional, no need refer to fixed-clock when
the ref clock is always on or comes from oscillator directly.

Signed-off-by: Chunfeng Yun 
---
 drivers/phy/phy-mtk-tphy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index c4fb404f20..fd33062ae4 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -338,7 +338,8 @@ static int mtk_tphy_probe(struct udevice *dev)
tphy->phys[index] = instance;
index++;
 
-   err = clk_get_by_index_nodev(subnode, 0, >ref_clk);
+   err = clk_get_optional_nodev(subnode, "ref",
+>ref_clk);
if (err)
return err;
}
-- 
2.24.0


[RESEND PATCH 5/7] clk: fixed_rate: add dummy enable() function

2019-12-17 Thread Chunfeng Yun
This is used to avoid clk_enable() return -ENOSYS.

Signed-off-by: Chunfeng Yun 
---
 drivers/clk/clk_fixed_rate.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/clk/clk_fixed_rate.c b/drivers/clk/clk_fixed_rate.c
index f51126793e..2c20eddb0b 100644
--- a/drivers/clk/clk_fixed_rate.c
+++ b/drivers/clk/clk_fixed_rate.c
@@ -13,8 +13,15 @@ static ulong clk_fixed_rate_get_rate(struct clk *clk)
return to_clk_fixed_rate(clk->dev)->fixed_rate;
 }
 
+/* avoid clk_enable() return -ENOSYS */
+static int dummy_enable(struct clk *clk)
+{
+   return 0;
+}
+
 const struct clk_ops clk_fixed_rate_ops = {
.get_rate = clk_fixed_rate_get_rate,
+   .enable = dummy_enable,
 };
 
 static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev)
-- 
2.24.0


[RESEND PATCH 1/7] clk: mediatek: mt7629: add support for ssusbsys

2019-12-17 Thread Chunfeng Yun
The SSUSB IP's clocks come from ssusbsys module on mt7629,
so add its driver

Signed-off-by: Chunfeng Yun 
---
 drivers/clk/mediatek/clk-mt7629.c | 42 +++
 1 file changed, 42 insertions(+)

diff --git a/drivers/clk/mediatek/clk-mt7629.c 
b/drivers/clk/mediatek/clk-mt7629.c
index 30a919f224..858be85d15 100644
--- a/drivers/clk/mediatek/clk-mt7629.c
+++ b/drivers/clk/mediatek/clk-mt7629.c
@@ -539,6 +539,29 @@ static const struct mtk_gate sgmii_cgs[] = {
GATE_SGMII(CLK_SGMII_CDR_FB, CLK_TOP_SSUSB_CDR_FB, 5),
 };
 
+static const struct mtk_gate_regs ssusb_cg_regs = {
+   .set_ofs = 0x30,
+   .clr_ofs = 0x30,
+   .sta_ofs = 0x30,
+};
+
+#define GATE_SSUSB(_id, _parent, _shift) { \
+   .id = _id,  \
+   .parent = _parent,  \
+   .regs = _cg_regs, \
+   .shift = _shift,\
+   .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN,  \
+}
+
+static const struct mtk_gate ssusb_cgs[] = {
+   GATE_SSUSB(CLK_SSUSB_U2_PHY_1P_EN, CLK_TOP_TO_U2_PHY_1P, 0),
+   GATE_SSUSB(CLK_SSUSB_U2_PHY_EN, CLK_TOP_TO_U2_PHY, 1),
+   GATE_SSUSB(CLK_SSUSB_REF_EN, CLK_TOP_TO_USB3_REF, 5),
+   GATE_SSUSB(CLK_SSUSB_SYS_EN, CLK_TOP_TO_USB3_SYS, 6),
+   GATE_SSUSB(CLK_SSUSB_MCU_EN, CLK_TOP_TO_USB3_MCU, 7),
+   GATE_SSUSB(CLK_SSUSB_DMA_EN, CLK_TOP_TO_USB3_DMA, 8),
+};
+
 static const struct mtk_clk_tree mt7629_clk_tree = {
.xtal_rate = 40 * MHZ,
.xtal2_rate = 20 * MHZ,
@@ -621,6 +644,11 @@ static int mt7629_sgmiisys_probe(struct udevice *dev)
return mtk_common_clk_gate_init(dev, _clk_tree, sgmii_cgs);
 }
 
+static int mt7629_ssusbsys_probe(struct udevice *dev)
+{
+   return mtk_common_clk_gate_init(dev, _clk_tree, ssusb_cgs);
+}
+
 static const struct udevice_id mt7629_apmixed_compat[] = {
{ .compatible = "mediatek,mt7629-apmixedsys" },
{ }
@@ -651,6 +679,11 @@ static const struct udevice_id mt7629_sgmiisys_compat[] = {
{ }
 };
 
+static const struct udevice_id mt7629_ssusbsys_compat[] = {
+   { .compatible = "mediatek,mt7629-ssusbsys" },
+   { }
+};
+
 static const struct udevice_id mt7629_mcucfg_compat[] = {
{ .compatible = "mediatek,mt7629-mcucfg" },
{ }
@@ -722,3 +755,12 @@ U_BOOT_DRIVER(mtk_clk_sgmiisys) = {
.priv_auto_alloc_size = sizeof(struct mtk_cg_priv),
.ops = _clk_gate_ops,
 };
+
+U_BOOT_DRIVER(mtk_clk_ssusbsys) = {
+   .name = "mt7629-clock-ssusbsys",
+   .id = UCLASS_CLK,
+   .of_match = mt7629_ssusbsys_compat,
+   .probe = mt7629_ssusbsys_probe,
+   .priv_auto_alloc_size = sizeof(struct mtk_cg_priv),
+   .ops = _clk_gate_ops,
+};
-- 
2.24.0


[RESEND PATCH 3/7] clk: check valid clock by clk_valid()

2019-12-17 Thread Chunfeng Yun
Add valid check for clk->dev, it's useful when get optional
clock even when the clk point is valid, but its dev will be
NULL.

Signed-off-by: Chunfeng Yun 
---
 drivers/clk/clk-uclass.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 2778b504c0..b7e18668cb 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -391,7 +391,7 @@ int clk_free(struct clk *clk)
const struct clk_ops *ops;
 
debug("%s(clk=%p)\n", __func__, clk);
-   if (!clk)
+   if (!clk_valid(clk))
return 0;
ops = clk_dev_ops(clk->dev);
 
@@ -406,7 +406,7 @@ ulong clk_get_rate(struct clk *clk)
const struct clk_ops *ops;
 
debug("%s(clk=%p)\n", __func__, clk);
-   if (!clk)
+   if (!clk_valid(clk))
return 0;
ops = clk_dev_ops(clk->dev);
 
@@ -422,7 +422,7 @@ struct clk *clk_get_parent(struct clk *clk)
struct clk *pclk;
 
debug("%s(clk=%p)\n", __func__, clk);
-   if (!clk)
+   if (!clk_valid(clk))
return NULL;
 
pdev = dev_get_parent(clk->dev);
@@ -439,7 +439,7 @@ long long clk_get_parent_rate(struct clk *clk)
struct clk *pclk;
 
debug("%s(clk=%p)\n", __func__, clk);
-   if (!clk)
+   if (!clk_valid(clk))
return 0;
 
pclk = clk_get_parent(clk);
@@ -462,7 +462,7 @@ ulong clk_set_rate(struct clk *clk, ulong rate)
const struct clk_ops *ops;
 
debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate);
-   if (!clk)
+   if (!clk_valid(clk))
return 0;
ops = clk_dev_ops(clk->dev);
 
@@ -477,7 +477,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
const struct clk_ops *ops;
 
debug("%s(clk=%p, parent=%p)\n", __func__, clk, parent);
-   if (!clk)
+   if (!clk_valid(clk))
return 0;
ops = clk_dev_ops(clk->dev);
 
@@ -494,7 +494,7 @@ int clk_enable(struct clk *clk)
int ret;
 
debug("%s(clk=%p)\n", __func__, clk);
-   if (!clk)
+   if (!clk_valid(clk))
return 0;
ops = clk_dev_ops(clk->dev);
 
@@ -554,7 +554,7 @@ int clk_disable(struct clk *clk)
int ret;
 
debug("%s(clk=%p)\n", __func__, clk);
-   if (!clk)
+   if (!clk_valid(clk))
return 0;
ops = clk_dev_ops(clk->dev);
 
-- 
2.24.0


[RESEND PATCH 4/7] clk: add APIs to get (optional) clock by name without a device

2019-12-17 Thread Chunfeng Yun
Sometimes we may need get (optional) clock without a device,
that means use ofnode.
e.g. when the phy node has subnode, and there is no device created
for subnode, in this case, we need these new APIs to get subnode's
clock.

Signed-off-by: Chunfeng Yun 
---
 drivers/clk/clk-uclass.c | 28 
 include/clk.h| 40 
 2 files changed, 68 insertions(+)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index b7e18668cb..93cb490eb5 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -344,6 +344,34 @@ int clk_get_by_name(struct udevice *dev, const char *name, 
struct clk *clk)
return clk_get_by_index(dev, index, clk);
 }
 
+int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk)
+{
+   int index;
+
+   debug("%s(node=%p, name=%s, clk=%p)\n", __func__,
+   ofnode_get_name(node), name, clk);
+   clk->dev = NULL;
+
+   index = ofnode_stringlist_search(node, "clock-names", name);
+   if (index < 0) {
+   debug("fdt_stringlist_search() failed: %d\n", index);
+   return index;
+   }
+
+   return clk_get_by_index_nodev(node, index, clk);
+}
+
+int clk_get_optional_nodev(ofnode node, const char *name, struct clk *clk)
+{
+   int ret;
+
+   ret = clk_get_by_name_nodev(node, name, clk);
+   if (ret == -ENODATA)
+   return 0;
+
+   return ret;
+}
+
 int clk_release_all(struct clk *clk, int count)
 {
int i, ret;
diff --git a/include/clk.h b/include/clk.h
index a5ee53d94a..3336301815 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -154,6 +154,34 @@ int clk_get_bulk(struct udevice *dev, struct clk_bulk 
*bulk);
  */
 int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk);
 
+/**
+ * clk_get_by_name_nodev - Get/request a clock by name without a device.
+ *
+ * This is a version of clk_get_by_name() that does not use a device.
+ *
+ * @node:  The client ofnode.
+ * @name:  The name of the clock to request, within the client's list of
+ * clocks.
+ * @clock: A pointer to a clock struct to initialize.
+ * @return 0 if OK, or a negative error code.
+ */
+int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk);
+
+/**
+ * clock_get_optional_nodev - Get/request an optinonal clock by name
+ * without a device.
+ * @node:  The client ofnode.
+ * @name:  The name of the clock to request.
+ * @name:  The name of the clock to request, within the client's list of
+ * clocks.
+ * @clock: A pointer to a clock struct to initialize.
+ *
+ * Behaves the same as clk_get_by_name_nodev() except where there is
+ * no clock producer, in this case, skip the error number -ENODATA, and
+ * the function returns 0.
+ */
+int clk_get_optional_nodev(ofnode node, const char *name, struct clk *clk);
+
 /**
  * devm_clk_get - lookup and obtain a managed reference to a clock producer.
  * @dev: device for clock "consumer"
@@ -230,6 +258,18 @@ static inline int clk_get_by_name(struct udevice *dev, 
const char *name,
return -ENOSYS;
 }
 
+static inline int
+clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk)
+{
+   return -ENOSYS;
+}
+
+static inline int
+clk_get_optional_nodev(ofnode node, const char *name, struct clk *clk)
+{
+   return -ENOSYS;
+}
+
 static inline int clk_release_all(struct clk *clk, int count)
 {
return -ENOSYS;
-- 
2.24.0


[RESEND PATCH 6/7] phy: phy-mtk-tphy: remove the check of -ENOSYS

2019-12-17 Thread Chunfeng Yun
No need check -ENOSYS anymore after add dummy_enable() for
fixed-clock.

Signed-off-by: Chunfeng Yun 
---
 drivers/phy/phy-mtk-tphy.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index 3701481256..c4fb404f20 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -204,9 +204,8 @@ static int mtk_phy_init(struct phy *phy)
struct mtk_phy_instance *instance = tphy->phys[phy->id];
int ret;
 
-   /* we may use a fixed-clock here */
ret = clk_enable(>ref_clk);
-   if (ret && ret != -ENOSYS)
+   if (ret)
return ret;
 
switch (instance->type) {
-- 
2.24.0


[RESEND PATCH 2/7] clk: fix error check for devm_clk_get_optional()

2019-12-17 Thread Chunfeng Yun
If skip all return error number, it may skip some real error cases,
so only skip the error when the clock is not provided in DTS

Signed-off-by: Chunfeng Yun 
---
 drivers/clk/clk-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 9aa8537004..2778b504c0 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -678,7 +678,7 @@ struct clk *devm_clk_get_optional(struct udevice *dev, 
const char *id)
 {
struct clk *clk = devm_clk_get(dev, id);
 
-   if (IS_ERR(clk))
+   if (PTR_ERR(clk) == -ENODATA)
return NULL;
 
return clk;
-- 
2.24.0


Re: [PATCH 1/1] usb: avoid -Werror=address-of-packed-member

2019-12-17 Thread Marek Vasut
On 12/17/19 12:59 PM, Heinrich Schuchardt wrote:
> On 12/17/19 12:19 PM, Marek Vasut wrote:
>> On 12/17/19 12:14 PM, Heinrich Schuchardt wrote:
>>> On 12/17/19 11:00 AM, Marek Vasut wrote:
 On 12/17/19 10:27 AM, Heinrich Schuchardt wrote:
> With GCC 9.2.1 errors of type -Werror=address-of-packed-member occur
> when
> passing a member of a packed structure to le16_to_cpus() on a big
> endian
> system (e.g. P2041RDB_defconfig).
>
> Replace le16_to_cpus() by get_unaligned_le16(). Check
> defined(__BIG_ENDIAN)
> to avoid the introduction of unnecessary instructions on little endian
> systems as seen on aarch64.

 I would expect the compiler would optimize such stuff out ?
 Can we do without the ifdef ?
>>>
>>> When compiling qemu_arm64_defconfig without the #ifdef the GCC 9.2.1
>>> adds assembler instructions:
>>
>> Why ?
>>
> 
> I am not a GCC developer. I simply observed that GCC currently cannot
> optimize this away on its own. That is why I added the #ifdef.

Are we now adding workarounds instead of solving issues properly?

> Identifying that bit operations like << 8 in __get_unaligned_le16() have
> zero effect is not an easy task when developing a compiler. You would
> have to follow the flow of every bit.

Maybe the fix is then to somehow optimize the get_unaligned_le16() to
help the compiler ?


[PATCH v1] Revert "core: device: use dev_power_domain_on"

2019-12-17 Thread Igor Opaniuk
From: Igor Opaniuk 

This reverts commit f0cc4eae9a1702a768817ea25d9f23cece69d021

This was previously reported that f0cc4eae9a ("core: device:
use dev_power_domain_on") breaks initial boot on Colibri iMX8X and
IMX8 QM ROM 7720a1 board. Revert it until the problem is properly fixed.

Signed-off-by: Igor Opaniuk 
---

 drivers/core/device.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 4e037083a6..c5b232c259 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -313,6 +313,7 @@ static void *alloc_priv(int size, uint flags)
 
 int device_probe(struct udevice *dev)
 {
+   struct power_domain pd;
const struct driver *drv;
int size = 0;
int ret;
@@ -396,9 +397,8 @@ int device_probe(struct udevice *dev)
if (CONFIG_IS_ENABLED(POWER_DOMAIN) && dev->parent &&
(device_get_uclass_id(dev) != UCLASS_POWER_DOMAIN) &&
!(drv->flags & DM_FLAG_DEFAULT_PD_CTRL_OFF)) {
-   ret = dev_power_domain_on(dev);
-   if (ret)
-   goto fail;
+   if (!power_domain_get(dev, ))
+   power_domain_on();
}
 
ret = uclass_pre_probe_device(dev);
-- 
2.17.1



[U-Boot] Please pull from u-boot-i2c next

2019-12-17 Thread Heiko Schocher

Hello Tom,

please pull from uboot-i2c next branch:

The following changes since commit 553cb06887825314e74a9bdac337467c77d1db88:

  Merge tag 'dm-next-13dec19' of https://gitlab.denx.de/u-boot/custodians/u-boot-dm into next 
(2019-12-12 08:18:59 -0500)


are available in the Git repository at:

  https://gitlab.denx.de/u-boot/custodians/u-boot-i2c.git tags/20191217-for-next

for you to fetch changes up to 033e18b47bd020610f84ca88c5ce3b88215d563a:

  misc: i2c_eeprom: add size query (2019-12-17 06:58:19 +0100)


i2c: for next
- misc: i2c_eeprom:
  Add partition support and add ability to query size
  of eeprom device and partitions
- i2c common:
  add support for offset overflow in to address and add
  sandbox tests for it.


Robert Beckett (5):
  i2c: add support for offset overflow in to address
  dm: i2c: EEPROM simulator allow tests visibility of addr and offset
  dm: i2c: EEPROM simulator add tests for addr offset mask
  misc: i2c_eeprom: add fixed partitions support
  misc: i2c_eeprom: add size query

 arch/sandbox/include/asm/test.h |   7 
 drivers/i2c/i2c-uclass.c|  34 
 drivers/misc/i2c_eeprom.c   | 243 
++---

 drivers/misc/i2c_eeprom_emul.c  |  80 
++---
 include/i2c.h   |  33 +++
 include/i2c_eeprom.h|  12 +++
 test/dm/i2c.c   | 113 

 7 files changed, 463 insertions(+), 59 deletions(-)

travis build:
https://travis-ci.org/hsdenx/u-boot-i2c/builds/626040609

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


Re: [U-Boot][PATCH 1/2] misc: i2c_eeprom: add fixed partitions support

2019-12-17 Thread Heiko Schocher

Hello Robert,

Am 28.10.2019 um 19:29 schrieb Robert Beckett:

Add ability to partition eeprom via devicetree bindings

Signed-off-by: Robert Beckett 
---

  drivers/misc/i2c_eeprom.c | 98 +++
  1 file changed, 98 insertions(+)


Applied to u-boot-i2c next branch.

Thanks!

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


Re: [U-Boot][PATCH 2/2] misc: i2c_eeprom: add size query

2019-12-17 Thread Heiko Schocher

Hello Robert,

Am 28.10.2019 um 19:29 schrieb Robert Beckett:

Add ability to query size of eeprom device and partitions

Signed-off-by: Robert Beckett 
---

  drivers/misc/i2c_eeprom.c | 145 +-
  include/i2c_eeprom.h  |  12 
  2 files changed, 138 insertions(+), 19 deletions(-)


Applied to u-boot-i2c next branch.

Thanks!

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


Re: [PATCH 1/1] usb: avoid -Werror=address-of-packed-member

2019-12-17 Thread Heinrich Schuchardt

On 12/17/19 12:19 PM, Marek Vasut wrote:

On 12/17/19 12:14 PM, Heinrich Schuchardt wrote:

On 12/17/19 11:00 AM, Marek Vasut wrote:

On 12/17/19 10:27 AM, Heinrich Schuchardt wrote:

With GCC 9.2.1 errors of type -Werror=address-of-packed-member occur
when
passing a member of a packed structure to le16_to_cpus() on a big endian
system (e.g. P2041RDB_defconfig).

Replace le16_to_cpus() by get_unaligned_le16(). Check
defined(__BIG_ENDIAN)
to avoid the introduction of unnecessary instructions on little endian
systems as seen on aarch64.


I would expect the compiler would optimize such stuff out ?
Can we do without the ifdef ?


When compiling qemu_arm64_defconfig without the #ifdef the GCC 9.2.1
adds assembler instructions:


Why ?



I am not a GCC developer. I simply observed that GCC currently cannot
optimize this away on its own. That is why I added the #ifdef.

Identifying that bit operations like << 8 in __get_unaligned_le16() have
zero effect is not an easy task when developing a compiler. You would
have to follow the flow of every bit.

Best regards

Heinrich


Re: [U-Boot][PATCH 3/3] dm: i2c: EEPROM simulator add tests for addr offset mask

2019-12-17 Thread Heiko Schocher

Hello Robert,

Am 28.10.2019 um 18:44 schrieb Robert Beckett:

Add support for setting the chip address offset mask to EEPROM sumulator
and add tests to test it.

Signed-off-by: Robert Beckett 
---

  arch/sandbox/include/asm/test.h |  3 ++
  drivers/misc/i2c_eeprom_emul.c  | 19 +++---
  test/dm/i2c.c   | 64 +
  3 files changed, 81 insertions(+), 5 deletions(-)


Applied to u-boot-i2c next branch.

Thanks!

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


Re: [U-Boot][PATCH 2/3] dm: i2c: EEPROM simulator allow tests visibility of addr and offset

2019-12-17 Thread Heiko Schocher

Hello Robert,

Am 28.10.2019 um 18:44 schrieb Robert Beckett:

Improve i2c EEPROM simulator testing by providing access functions to
check the previous chip addr and offset.

Given that we can now directly test the offsets, also simplified the
offset mapping and allow for wrapping acceses.

Signed-off-by: Robert Beckett 
---

  arch/sandbox/include/asm/test.h |  4 +++
  drivers/misc/i2c_eeprom_emul.c  | 61 +
  test/dm/i2c.c   | 50 +++
  3 files changed, 86 insertions(+), 29 deletions(-)


Applied to u-boot-i2c next branch.

Thanks!

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


Re: [U-Boot][PATCH 1/3] i2c: add support for offset overflow in to address

2019-12-17 Thread Heiko Schocher

Hello Robert,

Am 28.10.2019 um 18:44 schrieb Robert Beckett:

Some devices (2 wire eeproms for example) use some bits from the chip
address to represent the high bits of the offset instead of or as well
as using multiple bytes for the offset, effectively stealing chip
addresses on the bus.

Add a chip offset mask that can be set for any i2c chip which gets
filled with the offset overflow during offset setup.

Signed-off-by: Robert Beckett 
Signed-off-by: Ian Ray 
---

  drivers/i2c/i2c-uclass.c | 34 +++---
  include/i2c.h| 33 +
  2 files changed, 60 insertions(+), 7 deletions(-)


Applied to u-boot-i2c next branch.

Thanks!

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


[PATCH v4 6/8] configs: sandbox: Enable random number generator(rng) device

2019-12-17 Thread Sughosh Ganu
Enable support for random number generator on sandbox configs. This is
aimed primarily at adding unit test support for rng uclass.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Patrice Chotard 
Reviewed-by: Patrick Delaunay 
---
 configs/sandbox64_defconfig | 2 ++
 configs/sandbox_defconfig   | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index cc536ff..a21d832 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -158,6 +158,8 @@ CONFIG_REGULATOR_RK8XX=y
 CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
 CONFIG_REGULATOR_TPS65090=y
+CONFIG_DM_RNG=y
+CONFIG_RNG_SANDBOX=y
 CONFIG_DM_PWM=y
 CONFIG_PWM_SANDBOX=y
 CONFIG_RAM=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 64245f7..9bdc0f5 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -179,6 +179,8 @@ CONFIG_REGULATOR_RK8XX=y
 CONFIG_REGULATOR_S5M8767=y
 CONFIG_DM_REGULATOR_SANDBOX=y
 CONFIG_REGULATOR_TPS65090=y
+CONFIG_DM_RNG=y
+CONFIG_RNG_SANDBOX=y
 CONFIG_DM_PWM=y
 CONFIG_PWM_SANDBOX=y
 CONFIG_RAM=y
-- 
2.7.4



[PATCH v4 8/8] virtio: rng: Add a random number generator(rng) driver

2019-12-17 Thread Sughosh Ganu
Add a driver for the virtio-rng device on the qemu platform. The
device uses pci as a transport medium. The driver can be enabled with
the following configs

CONFIG_VIRTIO
CONFIG_DM_RNG
CONFIG_VIRTIO_PCI
CONFIG_VIRTIO_RNG

Signed-off-by: Sughosh Ganu 
---
 drivers/virtio/Kconfig |  6 
 drivers/virtio/Makefile|  1 +
 drivers/virtio/virtio-uclass.c |  1 +
 drivers/virtio/virtio_rng.c| 72 ++
 include/virtio.h   |  4 ++-
 5 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 drivers/virtio/virtio_rng.c

diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index a9d5fd0..2e3dd3b 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -59,4 +59,10 @@ config VIRTIO_BLK
  This is the virtual block driver for virtio. It can be used with
  QEMU based targets.
 
+config VIRTIO_RNG
+   bool "virtio rng driver"
+   depends on VIRTIO
+   help
+ This is the virtual random number generator driver. It can be used
+with Qemu based targets.
 endmenu
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 4579044..dc88809 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_VIRTIO_PCI) += virtio_pci_legacy.o 
virtio_pci_modern.o
 obj-$(CONFIG_VIRTIO_SANDBOX) += virtio_sandbox.o
 obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
 obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
+obj-$(CONFIG_VIRTIO_RNG) += virtio_rng.o
diff --git a/drivers/virtio/virtio-uclass.c b/drivers/virtio/virtio-uclass.c
index 34397d7..436faa4 100644
--- a/drivers/virtio/virtio-uclass.c
+++ b/drivers/virtio/virtio-uclass.c
@@ -24,6 +24,7 @@
 static const char *const virtio_drv_name[VIRTIO_ID_MAX_NUM] = {
[VIRTIO_ID_NET] = VIRTIO_NET_DRV_NAME,
[VIRTIO_ID_BLOCK]   = VIRTIO_BLK_DRV_NAME,
+   [VIRTIO_ID_RNG] = VIRTIO_RNG_DRV_NAME,
 };
 
 int virtio_get_config(struct udevice *vdev, unsigned int offset,
diff --git a/drivers/virtio/virtio_rng.c b/drivers/virtio/virtio_rng.c
new file mode 100644
index 000..19a0cc1
--- /dev/null
+++ b/drivers/virtio/virtio_rng.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct virtio_rng_priv {
+   struct virtqueue *rng_vq;
+};
+
+static int virtio_rng_read(struct udevice *dev, void *data, size_t len)
+{
+   struct virtio_sg sg = { data, len };
+   struct virtio_sg *sgs[] = {  };
+   struct virtio_rng_priv *priv = dev_get_priv(dev);
+   unsigned int rsize;
+   int ret;
+
+   ret = virtqueue_add(priv->rng_vq, sgs, 0, 1);
+   if (ret)
+   return ret;
+
+   virtqueue_kick(priv->rng_vq);
+
+   while (!virtqueue_get_buf(priv->rng_vq, ))
+   ;
+
+   return rsize;
+}
+
+static int virtio_rng_bind(struct udevice *dev)
+{
+   struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(dev->parent);
+
+   /* Indicate what driver features we support */
+   virtio_driver_features_init(uc_priv, NULL, 0, NULL, 0);
+
+   return 0;
+}
+
+static int virtio_rng_probe(struct udevice *dev)
+{
+   struct virtio_rng_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   ret = virtio_find_vqs(dev, 1, >rng_vq);
+   if (ret < 0)
+   return ret;
+
+   return 0;
+}
+
+static const struct dm_rng_ops virtio_rng_ops = {
+   .read   = virtio_rng_read,
+};
+
+U_BOOT_DRIVER(virtio_rng) = {
+   .name   = VIRTIO_RNG_DRV_NAME,
+   .id = UCLASS_RNG,
+   .bind   = virtio_rng_bind,
+   .probe  = virtio_rng_probe,
+   .remove = virtio_reset,
+   .ops= _rng_ops,
+   .priv_auto_alloc_size = sizeof(struct virtio_rng_priv),
+   .flags  = DM_FLAG_ACTIVE_DMA,
+};
diff --git a/include/virtio.h b/include/virtio.h
index 654fdf1..561dcc3 100644
--- a/include/virtio.h
+++ b/include/virtio.h
@@ -22,10 +22,12 @@
 
 #define VIRTIO_ID_NET  1 /* virtio net */
 #define VIRTIO_ID_BLOCK2 /* virtio block */
-#define VIRTIO_ID_MAX_NUM  3
+#define VIRTIO_ID_RNG  4 /* virtio rng */
+#define VIRTIO_ID_MAX_NUM  5
 
 #define VIRTIO_NET_DRV_NAME"virtio-net"
 #define VIRTIO_BLK_DRV_NAME"virtio-blk"
+#define VIRTIO_RNG_DRV_NAME"virtio-rng"
 
 /* Status byte for guest to report progress, and synchronize features */
 
-- 
2.7.4



[PATCH v4 5/8] sandbox: rng: Add a random number generator(rng) driver

2019-12-17 Thread Sughosh Ganu
Add a sandbox driver for random number generation. Mostly aimed at
providing a unit test for rng uclass.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Patrice Chotard 
---
Changes since V3:
 Handle review comments from Patrick Delaunay.

 arch/sandbox/dts/test.dts |  4 
 drivers/rng/Kconfig   |  7 +++
 drivers/rng/Makefile  |  1 +
 drivers/rng/sandbox_rng.c | 39 +++
 4 files changed, 51 insertions(+)
 create mode 100644 drivers/rng/sandbox_rng.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index fdb08f2..2c85540 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -599,6 +599,10 @@
reset-names = "other", "test";
};
 
+   rng@0 {
+   compatible = "sandbox,sandbox-rng";
+   };
+
rproc_1: rproc@1 {
compatible = "sandbox,test-processor";
remoteproc-name = "remoteproc-test-dev1";
diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig
index 5fc11db..3a1d3f0 100644
--- a/drivers/rng/Kconfig
+++ b/drivers/rng/Kconfig
@@ -6,6 +6,13 @@ config DM_RNG
  This interface is used to initialise the rng device and to
  read the random seed from the device.
 
+config RNG_SANDBOX
+   bool "Sandbox random number generator"
+   depends on SANDBOX && DM_RNG
+   help
+ Enable random number generator for sandbox. This is an
+emulation of a rng device.
+
 config RNG_STM32MP1
bool "Enable random number generator for STM32MP1"
depends on ARCH_STM32MP && DM_RNG
diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile
index 699beb3..3517005 100644
--- a/drivers/rng/Makefile
+++ b/drivers/rng/Makefile
@@ -4,4 +4,5 @@
 #
 
 obj-$(CONFIG_DM_RNG) += rng-uclass.o
+obj-$(CONFIG_RNG_SANDBOX) += sandbox_rng.o
 obj-$(CONFIG_RNG_STM32MP1) += stm32mp1_rng.o
diff --git a/drivers/rng/sandbox_rng.c b/drivers/rng/sandbox_rng.c
new file mode 100644
index 000..8262e0d
--- /dev/null
+++ b/drivers/rng/sandbox_rng.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+
+static unsigned long random = 0xdeadbeef;
+
+static int sandbox_rng_read(struct udevice *dev, void *data, size_t len)
+{
+   if (len != sizeof(random))
+   return -EINVAL;
+
+   random ^= ~0UL;
+   *(unsigned long *)data = random;
+
+   return 0;
+}
+
+static const struct dm_rng_ops sandbox_rng_ops = {
+   .read = sandbox_rng_read,
+};
+
+static const struct udevice_id sandbox_rng_match[] = {
+   {
+   .compatible = "sandbox,sandbox-rng",
+   },
+   {},
+};
+
+U_BOOT_DRIVER(sandbox_rng) = {
+   .name = "sandbox-rng",
+   .id = UCLASS_RNG,
+   .of_match = sandbox_rng_match,
+   .ops = _rng_ops,
+};
-- 
2.7.4



[PATCH v4 7/8] test: rng: Add basic test for random number generator(rng) uclass

2019-12-17 Thread Sughosh Ganu
Add a unit test for testing the rng uclass functionality using the
sandbox rng driver.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Patrice Chotard 
---
Changes since V3:
 Handle review comments from Patrick Delaunay.

 test/dm/Makefile |  1 +
 test/dm/rng.c| 28 
 2 files changed, 29 insertions(+)
 create mode 100644 test/dm/rng.c

diff --git a/test/dm/Makefile b/test/dm/Makefile
index 0c2fd5c..f61bf65 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -65,4 +65,5 @@ obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
 obj-$(CONFIG_DMA) += dma.o
 obj-$(CONFIG_DM_MDIO) += mdio.o
 obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o
+obj-$(CONFIG_DM_RNG) += rng.o
 endif
diff --git a/test/dm/rng.c b/test/dm/rng.c
new file mode 100644
index 000..d533cf6
--- /dev/null
+++ b/test/dm/rng.c
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Basic test of the rng uclass */
+static int dm_test_rng_read(struct unit_test_state *uts)
+{
+   unsigned long rand1 = 0, rand2 = 0;
+   struct udevice *dev;
+
+   ut_assertok(uclass_get_device(UCLASS_RNG, 0, ));
+   ut_assertnonnull(dev);
+   ut_assertok(dm_rng_read(dev, , sizeof(rand1)));
+   ut_assertok(dm_rng_read(dev, , sizeof(rand2)));
+   ut_assert(rand1 != rand2);
+   ut_asserteq(0x21524110, rand1);
+   ut_asserteq(0xdeadbeef, rand2);
+
+   return 0;
+}
+DM_TEST(dm_test_rng_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.7.4



[PATCH v4 3/8] stm32mp1: rng: Add a driver for random number generator(rng) device

2019-12-17 Thread Sughosh Ganu
Add a driver for the rng device found on stm32mp1 platforms. The
driver provides a routine for reading the random number seed from the
hardware device.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Patrice Chotard 
Acked-by: Patrick Delaunay 
---
Changes since V3:
 Return 0 for a successful read.

 drivers/rng/Kconfig|   7 ++
 drivers/rng/Makefile   |   1 +
 drivers/rng/stm32mp1_rng.c | 157 +
 3 files changed, 165 insertions(+)
 create mode 100644 drivers/rng/stm32mp1_rng.c

diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig
index dd44cc0..5fc11db 100644
--- a/drivers/rng/Kconfig
+++ b/drivers/rng/Kconfig
@@ -5,3 +5,10 @@ config DM_RNG
  Enable driver model for random number generator(rng) devices.
  This interface is used to initialise the rng device and to
  read the random seed from the device.
+
+config RNG_STM32MP1
+   bool "Enable random number generator for STM32MP1"
+   depends on ARCH_STM32MP && DM_RNG
+   default n
+   help
+ Enable STM32MP1 rng driver.
diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile
index 311705b..699beb3 100644
--- a/drivers/rng/Makefile
+++ b/drivers/rng/Makefile
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_DM_RNG) += rng-uclass.o
+obj-$(CONFIG_RNG_STM32MP1) += stm32mp1_rng.o
diff --git a/drivers/rng/stm32mp1_rng.c b/drivers/rng/stm32mp1_rng.c
new file mode 100644
index 000..6ef8f16
--- /dev/null
+++ b/drivers/rng/stm32mp1_rng.c
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define RNG_CR 0x00
+#define RNG_CR_RNGEN BIT(2)
+#define RNG_CR_CED BIT(5)
+
+#define RNG_SR 0x04
+#define RNG_SR_SEIS BIT(6)
+#define RNG_SR_CEIS BIT(5)
+#define RNG_SR_SECS BIT(2)
+#define RNG_SR_DRDY BIT(0)
+
+#define RNG_DR 0x08
+
+struct stm32_rng_platdata {
+   fdt_addr_t base;
+   struct clk clk;
+   struct reset_ctl rst;
+};
+
+static int stm32_rng_read(struct udevice *dev, void *data, size_t len)
+{
+   int retval = 0, i;
+   u32 sr, count, reg;
+   size_t increment;
+   struct stm32_rng_platdata *pdata = dev_get_platdata(dev);
+
+   while (len > 0) {
+   retval = readl_poll_timeout(pdata->base + RNG_SR, sr,
+   sr & RNG_SR_DRDY, 1);
+   if (retval)
+   return retval;
+
+   if (sr & (RNG_SR_SEIS | RNG_SR_SECS)) {
+   /* As per SoC TRM */
+   clrbits_le32(pdata->base + RNG_SR, RNG_SR_SEIS);
+   for (i = 0; i < 12; i++)
+   readl(pdata->base + RNG_DR);
+   if (readl(pdata->base + RNG_SR) & RNG_SR_SEIS) {
+   printf("RNG Noise");
+   return -EIO;
+   }
+   /* start again */
+   continue;
+   }
+
+   count = 4;
+   while (len && count) {
+   reg = readl(pdata->base + RNG_DR);
+   memcpy(data, , min(len, sizeof(u32)));
+   increment = min(len, sizeof(u32));
+   data += increment;
+   len -= increment;
+   count--;
+   }
+   }
+
+   return 0;
+}
+
+static int stm32_rng_init(struct stm32_rng_platdata *pdata)
+{
+   int err;
+
+   err = clk_enable(>clk);
+   if (err)
+   return err;
+
+   /* Disable CED */
+   writel(RNG_CR_RNGEN | RNG_CR_CED, pdata->base + RNG_CR);
+
+   /* clear error indicators */
+   writel(0, pdata->base + RNG_SR);
+
+   return 0;
+}
+
+static int stm32_rng_cleanup(struct stm32_rng_platdata *pdata)
+{
+
+   writel(0, pdata->base + RNG_CR);
+
+   return clk_disable(>clk);
+}
+
+static int stm32_rng_probe(struct udevice *dev)
+{
+   struct stm32_rng_platdata *pdata = dev_get_platdata(dev);
+
+   reset_assert(>rst);
+   udelay(20);
+   reset_deassert(>rst);
+
+   return stm32_rng_init(pdata);
+}
+
+static int stm32_rng_remove(struct udevice *dev)
+{
+   struct stm32_rng_platdata *pdata = dev_get_platdata(dev);
+
+   return stm32_rng_cleanup(pdata);
+}
+
+static int stm32_rng_ofdata_to_platdata(struct udevice *dev)
+{
+   struct stm32_rng_platdata *pdata = dev_get_platdata(dev);
+   int err;
+
+   pdata->base = dev_read_addr(dev);
+   if (!pdata->base)
+   return -ENOMEM;
+
+   err = clk_get_by_index(dev, 0, >clk);
+   if (err)
+   return err;
+
+   err = reset_get_by_index(dev, 0, >rst);
+   if (err)
+   return err;
+
+   return 0;
+}
+
+static const struct dm_rng_ops stm32_rng_ops = {
+   .read = stm32_rng_read,
+};
+
+static const struct 

[PATCH v4 2/8] clk: stm32mp1: Add a clock entry for RNG1 device

2019-12-17 Thread Sughosh Ganu
Add an entry for allowing clock enablement for the random number
generator peripheral, RNG1.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Patrice Chotard 
Acked-by: Patrick Delaunay 
---
 drivers/clk/clk_stm32mp1.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/clk/clk_stm32mp1.c b/drivers/clk/clk_stm32mp1.c
index 3718970..da66bde 100644
--- a/drivers/clk/clk_stm32mp1.c
+++ b/drivers/clk/clk_stm32mp1.c
@@ -563,6 +563,7 @@ static const struct stm32mp1_clk_gate stm32mp1_clk_gate[] = 
{
STM32MP1_CLK_SET_CLR(RCC_MP_AHB4ENSETR, 10, GPIOK, _UNKNOWN_SEL),
 
STM32MP1_CLK_SET_CLR(RCC_MP_AHB5ENSETR, 0, GPIOZ, _UNKNOWN_SEL),
+   STM32MP1_CLK_SET_CLR(RCC_MP_AHB5ENSETR, 6, RNG1_K, _UNKNOWN_SEL),
 
STM32MP1_CLK_SET_CLR(RCC_MP_AHB6ENSETR, 7, ETHCK_K, _ETH_SEL),
STM32MP1_CLK_SET_CLR(RCC_MP_AHB6ENSETR, 8, ETHTX, _UNKNOWN_SEL),
-- 
2.7.4



[PATCH v4 0/8] Add a random number generator uclass

2019-12-17 Thread Sughosh Ganu
Add a random number generator(rng) uclass to facilitate adding drivers
for rng devices. I plan to add an implementation of the
EFI_RNG_PROTOCOL, which would get the random number from the rng
uclass -- the protocol would be used by the efi stub for getting a
random number for the kaslr feature.

The patch series also adds a driver for the rng device found on the
stm32mp1 and qemu platforms. A dummy rng driver for sandbox has also
been added, along with the unit test for the rng uclass.

Changes since V3:
* Handle review comments from Patrick Delaunay

Changes since V2:
* Add a driver for the virtio-rng device on qemu platform

Changes since V1:
* Add a SPDX header in rng.h
* Change the UCLASS_DRIVER name from hwrng to rng, consistent with the
  rest of the naming convention
* Handle review comment from Patrice Chotard


Sughosh Ganu (8):
  dm: rng: Add random number generator(rng) uclass
  clk: stm32mp1: Add a clock entry for RNG1 device
  stm32mp1: rng: Add a driver for random number generator(rng) device
  configs: stm32mp15: Enable random number generator(rng) device
  sandbox: rng: Add a random number generator(rng) driver
  configs: sandbox: Enable random number generator(rng) device
  test: rng: Add basic test for random number generator(rng) uclass
  virtio: rng: Add a random number generator(rng) driver

 arch/sandbox/dts/test.dts   |   4 +
 configs/sandbox64_defconfig |   2 +
 configs/sandbox_defconfig   |   2 +
 configs/stm32mp15_basic_defconfig   |   2 +
 configs/stm32mp15_optee_defconfig   |   2 +
 configs/stm32mp15_trusted_defconfig |   2 +
 drivers/Kconfig |   2 +
 drivers/Makefile|   1 +
 drivers/clk/clk_stm32mp1.c  |   1 +
 drivers/rng/Kconfig |  21 +
 drivers/rng/Makefile|   8 ++
 drivers/rng/rng-uclass.c|  23 ++
 drivers/rng/sandbox_rng.c   |  39 +
 drivers/rng/stm32mp1_rng.c  | 157 
 drivers/virtio/Kconfig  |   6 ++
 drivers/virtio/Makefile |   1 +
 drivers/virtio/virtio-uclass.c  |   1 +
 drivers/virtio/virtio_rng.c |  72 +
 include/dm/uclass-id.h  |   1 +
 include/rng.h   |  32 
 include/virtio.h|   4 +-
 test/dm/Makefile|   1 +
 test/dm/rng.c   |  28 +++
 23 files changed, 411 insertions(+), 1 deletion(-)
 create mode 100644 drivers/rng/Kconfig
 create mode 100644 drivers/rng/Makefile
 create mode 100644 drivers/rng/rng-uclass.c
 create mode 100644 drivers/rng/sandbox_rng.c
 create mode 100644 drivers/rng/stm32mp1_rng.c
 create mode 100644 drivers/virtio/virtio_rng.c
 create mode 100644 include/rng.h
 create mode 100644 test/dm/rng.c

-- 
2.7.4



[PATCH v4 1/8] dm: rng: Add random number generator(rng) uclass

2019-12-17 Thread Sughosh Ganu
Add a uclass for reading a random number seed from a random number
generator device.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Patrice Chotard 
---
Changes since V3:
 Handle review comments from Patrick Delaunay.

 drivers/Kconfig  |  2 ++
 drivers/Makefile |  1 +
 drivers/rng/Kconfig  |  7 +++
 drivers/rng/Makefile |  6 ++
 drivers/rng/rng-uclass.c | 23 +++
 include/dm/uclass-id.h   |  1 +
 include/rng.h| 32 
 7 files changed, 72 insertions(+)
 create mode 100644 drivers/rng/Kconfig
 create mode 100644 drivers/rng/Makefile
 create mode 100644 drivers/rng/rng-uclass.c
 create mode 100644 include/rng.h

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 9d99ce0..e34a227 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -90,6 +90,8 @@ source "drivers/remoteproc/Kconfig"
 
 source "drivers/reset/Kconfig"
 
+source "drivers/rng/Kconfig"
+
 source "drivers/rtc/Kconfig"
 
 source "drivers/scsi/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index e977f19..6c619b1 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -115,4 +115,5 @@ obj-$(CONFIG_W1_EEPROM) += w1-eeprom/
 
 obj-$(CONFIG_MACH_PIC32) += ddr/microchip/
 obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock/
+obj-$(CONFIG_DM_RNG) += rng/
 endif
diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig
new file mode 100644
index 000..dd44cc0
--- /dev/null
+++ b/drivers/rng/Kconfig
@@ -0,0 +1,7 @@
+config DM_RNG
+   bool "Driver support for Random Number Generator devices"
+   depends on DM
+   help
+ Enable driver model for random number generator(rng) devices.
+ This interface is used to initialise the rng device and to
+ read the random seed from the device.
diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile
new file mode 100644
index 000..311705b
--- /dev/null
+++ b/drivers/rng/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2019, Linaro Limited
+#
+
+obj-$(CONFIG_DM_RNG) += rng-uclass.o
diff --git a/drivers/rng/rng-uclass.c b/drivers/rng/rng-uclass.c
new file mode 100644
index 000..b6af3b8
--- /dev/null
+++ b/drivers/rng/rng-uclass.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+
+int dm_rng_read(struct udevice *dev, void *buffer, size_t size)
+{
+   const struct dm_rng_ops *ops = device_get_ops(dev);
+
+   if (!ops->read)
+   return -ENOSYS;
+
+   return ops->read(dev, buffer, size);
+}
+
+UCLASS_DRIVER(rng) = {
+   .name = "rng",
+   .id = UCLASS_RNG,
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 0c563d8..192202d 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -86,6 +86,7 @@ enum uclass_id {
UCLASS_REGULATOR,   /* Regulator device */
UCLASS_REMOTEPROC,  /* Remote Processor device */
UCLASS_RESET,   /* Reset controller device */
+   UCLASS_RNG, /* Random Number Generator */
UCLASS_RTC, /* Real time clock device */
UCLASS_SCSI,/* SCSI device */
UCLASS_SERIAL,  /* Serial UART */
diff --git a/include/rng.h b/include/rng.h
new file mode 100644
index 000..80891fc
--- /dev/null
+++ b/include/rng.h
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019, Linaro Limited
+ */
+
+#if !defined _RNG_H_
+#define _RNG_H_
+
+#include 
+
+/**
+ * dm_rng_read() - read a random number seed from the rng device
+ * @buffer:input buffer to put the read random seed into
+ * @size:  number of bytes of random seed read
+ * @return 0 if OK, -ve on error
+ *
+ */
+int dm_rng_read(struct udevice *dev, void *buffer, size_t size);
+
+/* struct dm_rng_ops - Operations for the hwrng uclass */
+struct dm_rng_ops {
+   /**
+* @read() - read a random number seed
+*
+* @data:   input buffer to read the random seed
+* @max:total number of bytes to read
+* @return 0 if OK, -ve on error
+*/
+   int (*read)(struct udevice *dev, void *data, size_t max);
+};
+
+#endif /* _RNG_H_ */
-- 
2.7.4



[PATCH v4 4/8] configs: stm32mp15: Enable random number generator(rng) device

2019-12-17 Thread Sughosh Ganu
Enable support for the rng device on the stm32mp15 configs.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Patrice Chotard 
Acked-by: Patrick Delaunay 
---
 configs/stm32mp15_basic_defconfig   | 2 ++
 configs/stm32mp15_optee_defconfig   | 2 ++
 configs/stm32mp15_trusted_defconfig | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/configs/stm32mp15_basic_defconfig 
b/configs/stm32mp15_basic_defconfig
index 358c2cd..5ca40e0 100644
--- a/configs/stm32mp15_basic_defconfig
+++ b/configs/stm32mp15_basic_defconfig
@@ -143,3 +143,5 @@ CONFIG_VIDEO_STM32_DSI=y
 CONFIG_VIDEO_STM32_MAX_XRES=1280
 CONFIG_VIDEO_STM32_MAX_YRES=800
 CONFIG_FDT_FIXUP_PARTITIONS=y
+CONFIG_DM_RNG=y
+CONFIG_RNG_STM32MP1=y
diff --git a/configs/stm32mp15_optee_defconfig 
b/configs/stm32mp15_optee_defconfig
index a065d3e..b161cd1 100644
--- a/configs/stm32mp15_optee_defconfig
+++ b/configs/stm32mp15_optee_defconfig
@@ -127,3 +127,5 @@ CONFIG_VIDEO_STM32_DSI=y
 CONFIG_VIDEO_STM32_MAX_XRES=1280
 CONFIG_VIDEO_STM32_MAX_YRES=800
 CONFIG_FDT_FIXUP_PARTITIONS=y
+CONFIG_DM_RNG=y
+CONFIG_RNG_STM32MP1=y
diff --git a/configs/stm32mp15_trusted_defconfig 
b/configs/stm32mp15_trusted_defconfig
index 632f11f..ddf244d 100644
--- a/configs/stm32mp15_trusted_defconfig
+++ b/configs/stm32mp15_trusted_defconfig
@@ -126,3 +126,5 @@ CONFIG_VIDEO_STM32_DSI=y
 CONFIG_VIDEO_STM32_MAX_XRES=1280
 CONFIG_VIDEO_STM32_MAX_YRES=800
 CONFIG_FDT_FIXUP_PARTITIONS=y
+CONFIG_DM_RNG=y
+CONFIG_RNG_STM32MP1=y
-- 
2.7.4



Re: [U-Boot] [PATCH V3 2/2] core: device: use dev_power_domain_on

2019-12-17 Thread Fabio Estevam
Hi Igor,

On Tue, Dec 17, 2019 at 8:21 AM Igor Opaniuk  wrote:

> Sorry for the noise about mmc, there was a bug introduced in
> c20851b3d8("dm: pinctrl: introduce PINCONF_RECURSIVE option"), which
> is already fixed in 44510daea4("dm: pinctrl: fix for introduce
> PINCONF_RECURSIVE option")

Excellent: one less regression for us to care about then :-)


Re: [U-Boot] [PATCH V3 2/2] core: device: use dev_power_domain_on

2019-12-17 Thread Fabio Estevam
Hi Igor,

On Tue, Dec 17, 2019 at 7:56 AM Igor Opaniuk  wrote:

> U-Boot 2019.10-00071-g9c1e982218 (Dec 17 2019 - 12:37:14 +0200)

Does it also happen with 2020.01-rc5?

> CPU:   NXP i.MX8QXP RevB A35 at 1200 MHz
>
> DRAM:  2 GiB
> MMC:   FSL_SDHC: 0, FSL_SDHC: 1
> Loading Environment from MMC... Card did not respond to voltage select!

Looks like a different MMC issue than the one we saw with i.MX8MM EVK.

> BTW, we are currently working (internally in Toradex) on LAVA-based
> solution for testing both U-boot (hopefully Linaro finally added support for
> testing bootloaders, [1]) and Linux kernel.
>
> We plan to automate testing of both BSP downstream and mainline
> trees, so it makes sense to configure (that's still under discussion)
> some interaction with ML, for example sending notification about
> regressions/automatic bi-secting results (analog of
> syzbot emails in LKML) etc.
>
> If you have any ideas - we're open to any suggestions/input.

It would be very helpful to have regression notifications in the
U-Boot mailing lists.

Thanks


  1   2   >