Re: [U-Boot] [PATCH v5 024/101] sandbox: Add PCI driver and test for p2sb

2019-11-25 Thread Bin Meng
Hi Simon,

On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> Add a sandbox driver and PCI-device emulator for p2sb. Also add a test
> which uses a simple 'adder' driver to test the p2sb functionality.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4:
> - Drop change to message about a missing uclass
> - Drop empty operations struct since p2sb does not need it
> - Drop pmic_pm8916 driver name and use a sandbox name instead
> - Split out mmio changes into a separate patch
>
> Changes in v3:
> - Fix build errors in sandbox_spl, etc
>
> Changes in v2: None
>
>  arch/sandbox/dts/test.dts  |  13 ++
>  arch/sandbox/include/asm/test.h|   1 +
>  configs/sandbox64_defconfig|   2 +
>  configs/sandbox_defconfig  |   3 +-
>  configs/sandbox_flattree_defconfig |   3 +
>  configs/sandbox_spl_defconfig  |   2 +
>  configs/tools-only_defconfig   |   2 +
>  drivers/misc/Makefile  |   2 +
>  drivers/misc/p2sb_emul.c   | 272 +
>  drivers/misc/p2sb_sandbox.c|  40 +
>  drivers/misc/sandbox_adder.c   |  60 +++
>  test/dm/Makefile   |   1 +
>  test/dm/p2sb.c |  28 +++
>  13 files changed, 428 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/misc/p2sb_emul.c
>  create mode 100644 drivers/misc/p2sb_sandbox.c
>  create mode 100644 drivers/misc/sandbox_adder.c
>  create mode 100644 test/dm/p2sb.c
>
> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> index 99905677ab..9c8c4e2709 100644
> --- a/arch/sandbox/dts/test.dts
> +++ b/arch/sandbox/dts/test.dts
> @@ -471,6 +471,16 @@
>0x01000810 0 0 0 0>;
> sandbox,emul = <&swap_case_emul0_1>;
> };
> +   p2sb-pci@2,0 {
> +   compatible = "sandbox,p2sb";
> +   reg = <0x02001010 0 0 0 0>;
> +   sandbox,emul = <&p2sb_emul>;
> +
> +   adder {
> +   intel,p2sb-port-id = <3>;
> +   compatible = "sandbox,adder";
> +   };
> +   };
> pci@1e,0 {
> compatible = "sandbox,pmc";
> reg = <0xf000 0 0 0 0>;
> @@ -502,6 +512,9 @@
> swap_case_emul0_1f: emul0@1f,0 {
> compatible = "sandbox,swap-case";
> };
> +   p2sb_emul: emul@2,0 {
> +   compatible = "sandbox,p2sb-emul";
> +   };
> pmc_emul1e: emul@1e,0 {
> compatible = "sandbox,pmc-emul";
> };
> diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h
> index fa40d21f3f..fdb0ecfed1 100644
> --- a/arch/sandbox/include/asm/test.h
> +++ b/arch/sandbox/include/asm/test.h
> @@ -14,6 +14,7 @@
>  #define SANDBOX_PCI_VENDOR_ID  0x1234
>  #define SANDBOX_PCI_SWAP_CASE_EMUL_ID  0x5678
>  #define SANDBOX_PCI_PMC_EMUL_ID0x5677
> +#define SANDBOX_PCI_P2SB_EMUL_ID   0x5676
>  #define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM
>  #define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIAL
>
> diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
> index 716096abc5..229e268972 100644
> --- a/configs/sandbox64_defconfig
> +++ b/configs/sandbox64_defconfig
> @@ -83,6 +83,8 @@ CONFIG_DEVRES=y
>  CONFIG_DEBUG_DEVRES=y
>  CONFIG_ADC=y
>  CONFIG_ADC_SANDBOX=y
> +CONFIG_AXI=y
> +CONFIG_AXI_SANDBOX=y

Is this needed for this patch, or another patch?

>  CONFIG_CLK=y
>  CONFIG_CPU=y
>  CONFIG_DM_DEMO=y
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> index 5a3c4f151d..f3d5c2319a 100644
> --- a/configs/sandbox_defconfig
> +++ b/configs/sandbox_defconfig
> @@ -132,6 +132,8 @@ CONFIG_CROS_EC_I2C=y
>  CONFIG_CROS_EC_LPC=y
>  CONFIG_CROS_EC_SANDBOX=y
>  CONFIG_CROS_EC_SPI=y
> +CONFIG_IRQ=y

CONFIG_IRQ looks to be another patch.

> +CONFIG_P2SB=y
>  CONFIG_PWRSEQ=y
>  CONFIG_SPL_PWRSEQ=y
>  CONFIG_I2C_EEPROM=y
> @@ -151,7 +153,6 @@ CONFIG_PCI=y
>  CONFIG_DM_PCI=y
>  CONFIG_DM_PCI_COMPAT=y
>  CONFIG_PCI_SANDBOX=y
> -CONFIG_P2SB=y

Oops. so P2SB is already enabled on Sandbox?

>  CONFIG_PHY=y
>  CONFIG_PHY_SANDBOX=y
>  CONFIG_PINCTRL=y
> diff --git a/configs/sandbox_flattree_defconfig 
> b/configs/sandbox_flattree_defconfig
> index 774c278bce..ab4d26d012 100644
> --- a/configs/sandbox_flattree_defconfig
> +++ b/configs/sandbox_flattree_defconfig
> @@ -67,6 +67,8 @@ CONFIG_DEVRES=y
>  CONFIG_DEBUG_DEVRES=y
>  CONFIG_ADC=y
>  CONFIG_ADC_SANDBOX=y
> +CONFIG_AXI=y
> +CONFIG_AXI_SANDBOX=y
>  CONFIG_CLK=y
>  CONFIG_CLK_COMPOSITE_CCF=y
>  CONFIG_SANDBOX_CLK_CCF=y
> @@ -117,6 +119,7 @@ CONFIG_PCI=y
>  CONFIG_DM_PCI=y
>  CONFIG_DM_PCI_COMPAT=y
>  CONFIG_PCI_SANDBOX=y
> +CONFIG_P2SB=y
>  CONFIG_PHY=y
>  CONFIG_PHY_SANDBOX=y
>  CONFIG

Re: [U-Boot] [PATCH v5 025/101] x86: Move UCLASS_IRQ into a separate file

2019-11-25 Thread Bin Meng
On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> Update this uclass to support the needs of the Apollo Lake ITSS. It
> supports four operations.
>
> Move the uclass into a separate directory so that sandbox can use it too.
> Add a new Kconfig to control it and enable this on x86.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4:
> - Drop itss uclass in Makefile
> - Fix 'enabled' typo
> - apollolake -> Apollo Lake
>
> Changes in v3:
> - Add two more operations to IRQ
> - Use the IRQ uclass instead of creating a new ITSS uclass
>
> Changes in v2: None
>
>  arch/Kconfig  |  1 +
>  arch/x86/cpu/irq.c|  5 ---
>  drivers/misc/Kconfig  |  9 
>  drivers/misc/Makefile |  1 +
>  drivers/misc/irq-uclass.c | 53 +++
>  include/irq.h | 88 +++
>  6 files changed, 152 insertions(+), 5 deletions(-)
>  create mode 100644 drivers/misc/irq-uclass.c
>  create mode 100644 include/irq.h
>

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


Re: [U-Boot] [PATCH v5 023/101] sandbox: Disable mmio by default in tests

2019-11-25 Thread Bin Meng
On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> When reseting sandbox for tests, disable mmio support since that is the
> default state.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4:
> - Split out into a separate patch
>
> Changes in v3: None
> Changes in v2: None
>
>  arch/sandbox/cpu/state.c | 1 +
>  1 file changed, 1 insertion(+)
>

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


Re: [U-Boot] [PATCH v5 022/101] pci: Add support for p2sb uclass

2019-11-25 Thread Bin Meng
On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> The Primary-to-Sideband bus (P2SB) is used to access various peripherals
> through memory-mapped I/O in a large chunk of PCI space. The space is
> segmented into different channels and peripherals are accessed by
> device-specific means within those channels. Devices should be added in
> the device tree as subnodes of the p2sb.
>
> This adds a uclass and enables it for sandbox.
>
> Signed-off-by: Simon Glass 
>
> ---
>
> Changes in v5:
> - Add a way to obtain the port ID for a device
>
> Changes in v4:
> - Adjust condition for binding children
>
> Changes in v3: None
> Changes in v2: None
>
>  configs/sandbox_defconfig |   1 +
>  configs/sandbox_spl_defconfig |   1 +
>  drivers/misc/Kconfig  |  33 ++
>  drivers/misc/Makefile |   1 +
>  drivers/misc/p2sb-uclass.c| 216 ++
>  include/dm/uclass-id.h|   1 +
>  include/p2sb.h| 135 +
>  7 files changed, 388 insertions(+)
>  create mode 100644 drivers/misc/p2sb-uclass.c
>  create mode 100644 include/p2sb.h
>
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> index a8144436eb..5a3c4f151d 100644
> --- a/configs/sandbox_defconfig
> +++ b/configs/sandbox_defconfig
> @@ -151,6 +151,7 @@ CONFIG_PCI=y
>  CONFIG_DM_PCI=y
>  CONFIG_DM_PCI_COMPAT=y
>  CONFIG_PCI_SANDBOX=y
> +CONFIG_P2SB=y
>  CONFIG_PHY=y
>  CONFIG_PHY_SANDBOX=y
>  CONFIG_PINCTRL=y
> diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig
> index 02702fa7a5..478e4bd9d4 100644
> --- a/configs/sandbox_spl_defconfig
> +++ b/configs/sandbox_spl_defconfig
> @@ -136,6 +136,7 @@ CONFIG_PCI=y
>  CONFIG_DM_PCI=y
>  CONFIG_DM_PCI_COMPAT=y
>  CONFIG_PCI_SANDBOX=y
> +CONFIG_P2SB=y
>  CONFIG_PHY=y
>  CONFIG_PHY_SANDBOX=y
>  CONFIG_PINCTRL=y
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 82bb093c56..71643af9c2 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -226,6 +226,39 @@ config NUVOTON_NCT6102D
>   disable the legacy UART, the watchdog or other devices
>   in the Nuvoton Super IO chips on X86 platforms.
>
> +config P2SB
> +   bool "Intel Primary-to-Sideband Bus"
> +   depends on X86 || SANDBOX
> +   help
> + This enables support for the Intel Primary-to-Sideband bus,
> + abbreviated to P2SB. The P2SB is used to access various peripherals
> + such as eSPI, GPIO, through memory-mapped I/O in a large chunk of 
> PCI
> + space. The space is segmented into different channels and 
> peripherals
> + are accessed by device-specific means within those channels. Devices
> + should be added in the device tree as subnodes of the P2SB. A
> + Peripheral Channel Register? (PCR) API is provided to access those
> + devices - see pcr_readl(), etc.
> +
> +config SPL_P2SB
> +   bool "Intel Primary-to-Sideband Bus in SPL"
> +   depends on SPL && (X86 || SANDBOX)
> +   help
> + The Primary-to-Sideband bus is used to access various peripherals
> + through memory-mapped I/O in a large chunk of PCI space. The space 
> is
> + segmented into different channels and peripherals are accessed by
> + device-specific means within those channels. Devices should be added
> + in the device tree as subnodes of the p2sb.
> +
> +config TPL_P2SB
> +   bool "Intel Primary-to-Sideband Bus in TPL"
> +   depends on TPL && (X86 || SANDBOX)
> +   help
> + The Primary-to-Sideband bus is used to access various peripherals
> + through memory-mapped I/O in a large chunk of PCI space. The space 
> is
> + segmented into different channels and peripherals are accessed by
> + device-specific means within those channels. Devices should be added
> + in the device tree as subnodes of the p2sb.
> +
>  config PWRSEQ
> bool "Enable power-sequencing drivers"
> depends on DM
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index 55976d6be5..78b598b367 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -49,6 +49,7 @@ obj-$(CONFIG_MXC_OCOTP) += mxc_ocotp.o
>  obj-$(CONFIG_MXS_OCOTP) += mxs_ocotp.o
>  obj-$(CONFIG_NS87308) += ns87308.o
>  obj-$(CONFIG_NUVOTON_NCT6102D) += nuvoton_nct6102d.o
> +obj-$(CONFIG_P2SB) += p2sb-uclass.o
>  obj-$(CONFIG_PCA9551_LED) += pca9551_led.o
>  obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
>  obj-$(CONFIG_QFW) += qfw.o
> diff --git a/drivers/misc/p2sb-uclass.c b/drivers/misc/p2sb-uclass.c
> new file mode 100644
> index 00..a198700b5f
> --- /dev/null
> +++ b/drivers/misc/p2sb-uclass.c
> @@ -0,0 +1,216 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Uclass for Primary-to-sideband bus, used to access various peripherals
> + *
> + * Copyright 2019 Google LLC
> + * Written by Simon Glass 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#incl

Re: [U-Boot] [PATCH v5 021/101] x86: power: Add a 'pmc' command

2019-11-25 Thread Bin Meng
On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> Add a simple command to show information about the PMC.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4: None
> Changes in v3:
> - Rename power-mgr uclass to acpi-pmc
>
> Changes in v2: None
>
>  arch/Kconfig |  1 +
>  cmd/Kconfig  |  8 ++
>  cmd/Makefile |  1 +
>  cmd/pmc.c| 81 
>  4 files changed, 91 insertions(+)
>  create mode 100644 cmd/pmc.c
>

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


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

2019-11-25 Thread Heinrich Schuchardt

On 11/26/19 4:56 AM, Heinrich Schuchardt wrote:

On 11/13/19 1:44 AM, AKASHI Takahiro wrote:

Without this commit, time.h possibly causes a build error as
asctime_r() uses sprintf().


asctime_r() is not a Linux symbol (as of next-20191119)

ctime_r() and asctime_r() are defined as inline functions. ctime_r() is
used in multiple places and so we may end up duplicating code. So I
would prefer the inline functions in time.h to be moved to a separate C
file in lib/.

Best regards

Heinrich


Could it be that in one of your C files you simply didn't follow the
U-Boot coding style convention to include common.h first and we don't
need this patch at all?

https://www.denx.de/wiki/U-Boot/CodingStyle#Include_files

Best regards

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


Re: [U-Boot] [RFC PATCH] spi: spi-nor: Add dual flash support in spi-nor framework

2019-11-25 Thread Michal Simek
On 19. 11. 19 15:20, Ashok Reddy Soma wrote:
> Add dual parallel and dual stacked support in spi-nor framework.
> Add dual flash support for nor-scan, read and write.
> 
> Signed-off-by: Ashok Reddy Soma 
> ---
> Hi,
> 
> I have added dual parallel and dual stacked related changes to the
> spi-nor framework. I have tested this for dual parallel configuration
> on zynqmp platform. I am in process of testing dual stacked
> configuration.
> 
> Please let me know if my approach is correct. If it is okay, i will
> split this in to meaningful patches and send.
> 
> Thanks in advance,
> Ashok Reddy Soma
> ---
>  drivers/mtd/spi/sf_internal.h  |   9 +
>  drivers/mtd/spi/spi-nor-core.c | 363 -
>  drivers/spi/spi-mem.c  |  19 +-
>  include/linux/mtd/spi-nor.h|   4 +
>  include/spi.h  |   9 +
>  5 files changed, 351 insertions(+), 53 deletions(-)
> 
> diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
> index 5c643034c6..d836261f01 100644
> --- a/drivers/mtd/spi/sf_internal.h
> +++ b/drivers/mtd/spi/sf_internal.h
> @@ -15,6 +15,15 @@
>  #define SPI_NOR_MAX_ID_LEN   6
>  #define SPI_NOR_MAX_ADDR_WIDTH   4
>  
> +/* Dual SPI flash memories - see SPI_COMM_DUAL_... */
> +enum spi_dual_flash {
> + SF_SINGLE_FLASH = 0,
> + SF_DUAL_STACKED_FLASH   = BIT(0),
> + SF_DUAL_PARALLEL_FLASH  = BIT(1),
> +};
> +
> +#define SPI_FLASH_16MB_BOUN 0x100
> +
>  struct flash_info {
>  #if !CONFIG_IS_ENABLED(SPI_FLASH_TINY)
>   char*name;
> diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
> index 5a8c084255..a53c78ff22 100644
> --- a/drivers/mtd/spi/spi-nor-core.c
> +++ b/drivers/mtd/spi/spi-nor-core.c
> @@ -21,6 +21,7 @@
>  #include 
>  #include 
>  
> +#include 
>  #include "sf_internal.h"
>  
>  /* Define max times to check status register before we give up. */
> @@ -34,6 +35,11 @@
>  
>  #define DEFAULT_READY_WAIT_JIFFIES   (40UL * HZ)
>  
> +#define SPI_MASTER_QUAD_MODEBIT(6)   /* support quad mode */
> +#define SPI_MASTER_DATA_STRIPE  BIT(7)   /* support data stripe */
> +#define SPI_MASTER_BOTH_CS  BIT(8)  /* assert both chip selects 
> */
> +#define SPI_MASTER_U_PAGE   BIT(9)   /* select upper flash */
> +
>  static int spi_nor_read_write_reg(struct spi_nor *nor, struct spi_mem_op
>   *op, void *buf)
>  {
> @@ -146,15 +152,24 @@ static ssize_t spi_nor_write_data(struct spi_nor *nor, 
> loff_t to, size_t len,
>  static int read_sr(struct spi_nor *nor)
>  {
>   int ret;
> - u8 val;
> + u8 val[2];
>  
> - ret = nor->read_reg(nor, SPINOR_OP_RDSR, &val, 1);
> - if (ret < 0) {
> + if (nor->isparallel) {
> + ret = nor->read_reg(nor, SPINOR_OP_RDSR, &val[0], 2);
> + if (ret < 0) {
> + pr_debug("error %d reading SR\n", (int)ret);
> + return ret;
> + }
> + val[0] |= val[1];
> + } else {
> + ret = nor->read_reg(nor, SPINOR_OP_RDSR, &val[0], 1);
> + if (ret < 0) {
>   pr_debug("error %d reading SR\n", (int)ret);
>   return ret;
> + }
>   }
>  
> - return val;
> + return val[0];
>  }
>  
>  /*
> @@ -165,15 +180,24 @@ static int read_sr(struct spi_nor *nor)
>  static int read_fsr(struct spi_nor *nor)
>  {
>   int ret;
> - u8 val;
> + u8 val[2];
>  
> - ret = nor->read_reg(nor, SPINOR_OP_RDFSR, &val, 1);
> - if (ret < 0) {
> + if (nor->isparallel) {
> + ret = nor->read_reg(nor, SPINOR_OP_RDFSR, &val[0], 2);
> + if (ret < 0) {
> + pr_debug("error %d reading SR\n", (int)ret);
> + return ret;
> + }
> + val[0] &= val[1];
> + } else {
> + ret = nor->read_reg(nor, SPINOR_OP_RDFSR, &val[0], 1);
> + if (ret < 0) {
>   pr_debug("error %d reading FSR\n", ret);
>   return ret;
> + }
>   }
>  
> - return val;
> + return val[0];
>  }
>  
>  /*
> @@ -288,12 +312,17 @@ static u8 spi_nor_convert_3to4_erase(u8 opcode)
>  static void spi_nor_set_4byte_opcodes(struct spi_nor *nor,
> const struct flash_info *info)
>  {
> + bool shift = 0;
> +
> + if (nor->isparallel)
> + shift = 1;
> +
>   /* Do some manufacturer fixups first */
>   switch (JEDEC_MFR(info)) {
>   case SNOR_MFR_SPANSION:
>   /* No small sector erase for 4-byte command set */
>   nor->erase_opcode = SPINOR_OP_SE;
> - nor->mtd.erasesize = info->sector_size;
> + nor->mtd.erasesize = info->sector_size << shift;
>   break;
>  
>   default:
> @@ -465,12 +494,19 @@ static int clean_bar(struct spi_nor *nor)
>  
>  static int write_bar(struct spi_nor *nor, u32 offset)
>  {
> - u8 cmd, bank_sel;
> + u8 cmd, bank_sel, upage_curr;
>   int ret;
>  
> - bank_sel = offset / SZ_16M;
>

Re: [U-Boot] [PATCH v5 020/101] x86: sandbox: Add a PMC emulator and test

2019-11-25 Thread Bin Meng
On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> Add a simple PMC for sandbox to permit tests to run.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4: None
> Changes in v3:
> - Rename power-mgr uclass to acpi-pmc
> - Tidy up Makefile rules to reduce duplication
>
> Changes in v2: None
>
>  arch/Kconfig  |   2 +
>  arch/sandbox/dts/sandbox.dtsi |  14 ++
>  arch/sandbox/dts/test.dts |  14 ++
>  arch/sandbox/include/asm/test.h   |   1 +
>  drivers/Makefile  |   1 +
>  drivers/power/acpi_pmc/Kconfig|   9 ++
>  drivers/power/acpi_pmc/Makefile   |   1 +
>  drivers/power/acpi_pmc/pmc_emul.c | 246 ++
>  drivers/power/acpi_pmc/sandbox.c  |  97 
>  test/dm/Makefile  |   1 +
>  test/dm/pmc.c |  33 
>  11 files changed, 419 insertions(+)
>  create mode 100644 drivers/power/acpi_pmc/pmc_emul.c
>  create mode 100644 drivers/power/acpi_pmc/sandbox.c
>  create mode 100644 test/dm/pmc.c
>

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


Re: [U-Boot] [PATCH v5 018/101] x86: Drop unnecessary interrupt code for TPL

2019-11-25 Thread Bin Meng
On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> We don't expect an exception in TPL and don't need to set up interrupts in
> TPL. Drop this whole file.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4:
> - Drop the whole interrupt file for TPL
>
> Changes in v3: None
> Changes in v2: None
>
>  arch/x86/cpu/i386/Makefile | 2 ++
>  1 file changed, 2 insertions(+)
>

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


Re: [U-Boot] [PATCH v5 017/101] x86: Drop unnecessary cpu code for TPL

2019-11-25 Thread Bin Meng
On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> We don't need to know every detail about the CPU in TPL. Drop some
> superfluous functions to reduce code size. Add a simple CPU detection
> algorithm which just supports Intel and AMD, since we only support TPL
> on Intel, so far.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4:
> - Drop 'if (0)' call to deep_magic_nexgen_probe() and use #ifndef instead
> - Fix 'what' typo
>
> Changes in v3: None
> Changes in v2: None
>
>  arch/x86/cpu/cpu.c  |  4 
>  arch/x86/cpu/i386/cpu.c | 41 +
>  2 files changed, 41 insertions(+), 4 deletions(-)
>

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


Re: [U-Boot] [PATCH v5 016/101] x86: timer: Reduce timer code size in TPL on Intel CPUs

2019-11-25 Thread Bin Meng
On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> Most of the timer-calibration methods are not needed on recent Intel CPUs
> and just increase code size. Add an option to use the known-good way to
> get the clock frequency in TPL. Size reduction is about 700 bytes.
>
> Note that version 1 of this commit caused bootstage to crash since the CPU
> was not identified. This is corrected by changes previously applied to
> make sure that the CPU is identified before spl_init() is called, such as
>
>39146a2e0b x86: Move CPU init to before spl_init()
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4:
> - Update commit message to indicate that CPU-identity bug is fixed
>
> Changes in v3: None
> Changes in v2: None
>
>  drivers/timer/Kconfig | 9 +
>  drivers/timer/tsc_timer.c | 7 +--
>  2 files changed, 14 insertions(+), 2 deletions(-)
>

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


[U-Boot] [PATCH] configs/lx2160a: Add CONFIG_ENV_SECT_SIZE in defconfig

2019-11-25 Thread Priyanka Jain
Define CONFIG_ENV_SECT_SIZE as 0x2 in lx2160a related defconfigs:
lx2160ardb_tfa_defconfig, lx2160ardb_tfa_SECURE_BOOT_defconfig,
lx2160aqds_tfa_defconfig, lx2160aqds_tfa_SECURE_BOOT_defconfig

Signed-off-by: Priyanka Jain 
---
 configs/lx2160aqds_tfa_SECURE_BOOT_defconfig | 1 +
 configs/lx2160aqds_tfa_defconfig | 1 +
 configs/lx2160ardb_tfa_SECURE_BOOT_defconfig | 1 +
 configs/lx2160ardb_tfa_defconfig | 1 +
 4 files changed, 4 insertions(+)

diff --git a/configs/lx2160aqds_tfa_SECURE_BOOT_defconfig 
b/configs/lx2160aqds_tfa_SECURE_BOOT_defconfig
index 4ab7582fc7..19635d4ac6 100644
--- a/configs/lx2160aqds_tfa_SECURE_BOOT_defconfig
+++ b/configs/lx2160aqds_tfa_SECURE_BOOT_defconfig
@@ -5,6 +5,7 @@ CONFIG_SYS_TEXT_BASE=0x8200
 CONFIG_SYS_MALLOC_F_LEN=0x6000
 CONFIG_NXP_ESBC=y
 CONFIG_ENV_SIZE=0x2000
+CONFIG_ENV_SECT_SIZE=0x2
 CONFIG_NR_DRAM_BANKS=3
 CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT=y
 CONFIG_SEC_FIRMWARE_ARMV8_PSCI=y
diff --git a/configs/lx2160aqds_tfa_defconfig b/configs/lx2160aqds_tfa_defconfig
index a35f1cc38d..8f2cfad3b3 100644
--- a/configs/lx2160aqds_tfa_defconfig
+++ b/configs/lx2160aqds_tfa_defconfig
@@ -4,6 +4,7 @@ CONFIG_TFABOOT=y
 CONFIG_SYS_TEXT_BASE=0x8200
 CONFIG_SYS_MALLOC_F_LEN=0x6000
 CONFIG_ENV_SIZE=0x2000
+CONFIG_ENV_SECT_SIZE=0x2
 CONFIG_ENV_OFFSET=0x50
 CONFIG_NR_DRAM_BANKS=3
 CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT=y
diff --git a/configs/lx2160ardb_tfa_SECURE_BOOT_defconfig 
b/configs/lx2160ardb_tfa_SECURE_BOOT_defconfig
index 87c54b00f6..f490d10da1 100644
--- a/configs/lx2160ardb_tfa_SECURE_BOOT_defconfig
+++ b/configs/lx2160ardb_tfa_SECURE_BOOT_defconfig
@@ -6,6 +6,7 @@ CONFIG_SYS_MALLOC_F_LEN=0x6000
 CONFIG_NXP_ESBC=y
 CONFIG_EMC2305=y
 CONFIG_ENV_SIZE=0x2000
+CONFIG_ENV_SECT_SIZE=0x2
 CONFIG_NR_DRAM_BANKS=3
 CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT=y
 CONFIG_SEC_FIRMWARE_ARMV8_PSCI=y
diff --git a/configs/lx2160ardb_tfa_defconfig b/configs/lx2160ardb_tfa_defconfig
index 18057b20b1..4122fb3d1f 100644
--- a/configs/lx2160ardb_tfa_defconfig
+++ b/configs/lx2160ardb_tfa_defconfig
@@ -5,6 +5,7 @@ CONFIG_SYS_TEXT_BASE=0x8200
 CONFIG_SYS_MALLOC_F_LEN=0x6000
 CONFIG_EMC2305=y
 CONFIG_ENV_SIZE=0x2000
+CONFIG_ENV_SECT_SIZE=0x2
 CONFIG_ENV_OFFSET=0x50
 CONFIG_NR_DRAM_BANKS=3
 CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT=y
-- 
2.17.1

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


Re: [U-Boot] [PATCH v5 015/101] x86: timer: use a timer base of 0

2019-11-25 Thread Bin Meng
On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> On x86 platforms the timer is reset to 0 when the SoC is reset. Having
> this as the timer base is useful since it provides an indication of how
> long it takes before U-Boot is running.
>
> When U-Boot sets the timer base to something else, time is lost and we
> no-longer have an accurate account of the time since reset. This
> particularly affects bootstage.
>
> Change the default to not read the timer base, leaving it at 0. Add an
> option for when U-Boot is the secondary bootloader.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4:
> - Enable option for slimbootloader, coreboot, efi
> - Reverse the sense of the CONFIG option
>
> Changes in v3: None
> Changes in v2: None
>
>  arch/x86/cpu/coreboot/Kconfig   |  1 +
>  arch/x86/cpu/slimbootloader/Kconfig |  1 +
>  drivers/timer/Kconfig   | 14 ++
>  drivers/timer/tsc_timer.c   |  3 ++-
>  lib/efi/Kconfig |  1 +
>  5 files changed, 19 insertions(+), 1 deletion(-)
>

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


Re: [U-Boot] [PATCH v5 013/101] RFC: sandbox: net: Suppress the MAC-address warnings

2019-11-25 Thread Bin Meng
Hi Simon, Joe,

On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> These warnings appear every thing sandbox is run (see below) and dwarf the
> actual useful output. Suppress them in two ways:
>
> 1. For the mismatch warnings, only set the ethaddr environment
> variables when running tests.
>
> 2. For the 'MAC address from ROM' warning, never print this on sandbox.
>
> Signed-off-by: Simon Glass 
> ---
> Unfortunately this breaks the tests so is not applicable as is:
>
> $ /tmp/b/sandbox/u-boot -T -c "ut dm eth_prime"

What's our solution to the problem described here? As this commit will
be reverted by the next patch in this series ...

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


Re: [U-Boot] [PATCH v5 012/101] board_r: Move early-timer init later

2019-11-25 Thread Bin Meng
Hi Simon,

On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> At present the early timer init happens as soon as driver mode is set up.

mode -> model

> This makes it impossible to do any in that needs driver model but must run

in -> thing?

> before devices are problem (as needed with Intel's FSP-S, for example).

problem -> probed?

>
> In any case it is not a good idea to tie probing of particular drivers too
> closely to the DM init.
>
> Create a new function to init the timer and put it a bit later in the
> sequence.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4:
> - Add new patch to move early-timer init later
>
> Changes in v3: None
> Changes in v2: None
>
>  common/board_r.c| 19 ++-
>  drivers/pinctrl/Kconfig | 14 ++
>  2 files changed, 28 insertions(+), 5 deletions(-)
>
> diff --git a/common/board_r.c b/common/board_r.c
> index e385696a6d..70736397e4 100644
> --- a/common/board_r.c
> +++ b/common/board_r.c
> @@ -306,16 +306,24 @@ static int initr_dm(void)
> bootstage_accum(BOOTSTATE_ID_ACCUM_DM_R);
> if (ret)
> return ret;
> -#ifdef CONFIG_TIMER_EARLY
> -   ret = dm_timer_init();
> -   if (ret)
> -   return ret;
> -#endif
>
> return 0;
>  }
>  #endif
>
> +static int initr_dm_devices(void)
> +{
> +   int ret;
> +
> +   if (IS_ENABLED(CONFIG_TIMER_EARLY)) {
> +   ret = dm_timer_init();
> +   if (ret)
> +   return ret;
> +   }
> +
> +   return 0;
> +}
> +
>  static int initr_bootstage(void)
>  {
> bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
> @@ -702,6 +710,7 @@ static init_fnc_t init_sequence_r[] = {
> efi_memory_init,
>  #endif
> initr_binman,
> +   initr_dm_devices,
> stdio_init_tables,
> initr_serial,
> initr_announce,
> diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
> index eadcfd6652..449f614eb2 100644
> --- a/drivers/pinctrl/Kconfig
> +++ b/drivers/pinctrl/Kconfig
> @@ -82,6 +82,13 @@ config SPL_PINCTRL
>   This option is an SPL-variant of the PINCTRL option.
>   See the help of PINCTRL for details.
>
> +config TPL_PINCTRL
> +   bool "Support pin controllers in TPL"
> +   depends on TPL && TPL_DM
> +   help
> + This option is an TPL variant of the PINCTRL option.
> + See the help of PINCTRL for details.
> +
>  config SPL_PINCTRL_FULL
> bool "Support full pin controllers in SPL"
> depends on SPL_PINCTRL && SPL_OF_CONTROL
> @@ -91,6 +98,13 @@ config SPL_PINCTRL_FULL
>   This option is an SPL-variant of the PINCTRL_FULL option.
>   See the help of PINCTRL_FULL for details.
>
> +config TPL_PINCTRL_FULL
> +   bool "Support full pin controllers in TPL"
> +   depends on TPL_PINCTRL && TPL_OF_CONTROL
> +   help
> + This option is an TPL-variant of the PINCTRL_FULL option.
> + See the help of PINCTRL_FULL for details.
> +
>  config SPL_PINCTRL_GENERIC
> bool "Support generic pin controllers in SPL"
> depends on SPL_PINCTRL_FULL
> --

The above 2 Kconfig changes should not be in this commit.

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


Re: [U-Boot] [PATCH v5 011/101] fdt: Show the preprocessed .dts file on error

2019-11-25 Thread Bin Meng
Hi Simon,

On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> When device-tree compilation fails it is sometimes tricky to see which
> line is broken, since the input file to dtc is a pre-processed version
> of the device tree.
>
> Add a line that points to the file that needs to be checked:
>
> When the error is in the main .dts file, output is something like this:
>
>output: 'Error: arch/x86/dts/.chromebook_coral.dtb.pre.tmp:478.46-47
> syntax error
>FATAL ERROR: Unable to parse input tree
>
> but in fact looking at that file shows nothing useful:
>
>PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_157, UP_20K, DEEP, NF1, HIZCRX1, DISPUPD)
>
> Instead we need to look at the preprocessed file, which shows:
>
>163 ((1U << 30) | (1 << 10)) ((0xb << 10) | PAD_CFG1_IOSSTATE_HIZCRX1)
>
> Here it is clear that PAD_CFG1_IOSSTATE_HIZCRX1 is not defined and so is
> not being resolved by the preprocessor.
>
> This commit adds an additional useful message:
>
>Check arch/x86/dts/.chromebook_coral.dtb.dts.tmp for errors
>
> Note that if the error is reported in an included file, such as
> u-boot.dtsi then the output is the following:
>
>Error: arch/x86/dts/u-boot.dtsi:137.14-15 syntax error
>FATAL ERROR: Unable to parse input tree
>
> But again, if the error is due to a preprocessor failure, like this:
>
>filename = CONFIG_IFW_INPUT_FILE;
>
> then you can't tell what the problem is by looking at the source. All you
> see is the original code:
>
> intel-ifwi {
> filename = CONFIG_IFW_INPUT_FILE;
> ...
> };
> };
> intel-fsp-m {
> filename = CONFIG_FSP_FILE_M;
> };
>
> Everything looks fine. But looking at the output of the preprocessor:
>
>  intel-ifwi {
>   filename = CONFIG_IFW_INPUT_FILE;
>   ...
>  };
>  intel-fsp-m {
>   filename = "fsp_m.bin";
>  };
>
> This shows that the filename (normally "fitimage.bin") has not been
> inserted the preprocess, leading to the realisation that the value should
> be CONFIG_IFWI_INPUT_FILE.
>
> If the above does not make sense, I encourage people to try introducing
> errors in the device tree preprocessed values.
>

This makes sense now. Thanks for the detailed description. It helps
people understand what the real problem is.

> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4:
> - One last desperate attempt to try to explain the purpose of this commit
> - Update the message to mention the preprocessed file, not un-preprocessed
>
> Changes in v3:
> - Update example error message to better show the intended purpose
>
> Changes in v2: None
>
>  scripts/Makefile.lib | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>

Reviewed-by: Bin Meng 

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


Re: [U-Boot] [PATCH v5 010/101] x86: spi: Add helper functions for Intel Fast SPI

2019-11-25 Thread Bin Meng
On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> Most x86 CPUs use a mechanism where the SPI flash is mapped into the very
> top of 32-bit address space, so that it can be executed in place and read
> simply by copying from memory. For an 8MB ROM the mapping starts at
> 0xff80.
>
> However some recent Intel CPUs do not use a simple 1:1 memory map. Instead
> the map starts at a different address and not all of the SPI flash is
> accessible through the map. This 'Fast SPI' feature requires that U-Boot
> check the location of the map. It is also possible (optionally) to read
> from the SPI flash using a driver.
>
> Add support for booting from Fast SPI. The memory-mapped version is used
> by both TPL and SPL on Apollo Lake.
>
> In respect of a SPI flash driver, the actual SPI driver is ich.c - this
> just adds a few helper functions and definitions.
>
> This is used by Apollo Lake.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4: None
> Changes in v3:
> - Add support for of-platdata for TPL
> - Add the missing header file
> - Change Fast-SPI driver into a helper file used by ICH SPI
> - Don't include write() and erase() in TPL
> - Drop 'a4' comment for register offset
> - Merge in patch "x86: Add support for booting from Fast SPI"
> - Reorder file so that write() and erase() are together
> - Use pci_get_devfn()
>
> Changes in v2: None
>
>  arch/x86/cpu/intel_common/Makefile   |  1 +
>  arch/x86/cpu/intel_common/fast_spi.c | 73 
>  arch/x86/include/asm/fast_spi.h  | 68 ++
>  arch/x86/include/asm/spl.h   |  1 +
>  4 files changed, 143 insertions(+)
>  create mode 100644 arch/x86/cpu/intel_common/fast_spi.c
>  create mode 100644 arch/x86/include/asm/fast_spi.h
>

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


Re: [U-Boot] [PATCH v5 009/101] i2c: designware: Support use in SPL

2019-11-25 Thread Bin Meng
Hi Simon,

On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> Allow this driver to set up an IO address in SPL using an 'early-regs'
> property. This allows SPL to use the I2C driver without having to enable
> the full PCI stack.
>
> Also split out ofdata_to_platdata in designware driver since this is more
> correct, and more convenient for the new logic.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v5: None
> Changes in v4:
> - Add new patch to allow designware I2C driver to work in SPL
>
> Changes in v3: None
> Changes in v2: None
>
>  drivers/i2c/designware_i2c_pci.c | 46 +---
>  1 file changed, 43 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/i2c/designware_i2c_pci.c 
> b/drivers/i2c/designware_i2c_pci.c
> index 8d6bb37f5c..2bf90eaa4b 100644
> --- a/drivers/i2c/designware_i2c_pci.c
> +++ b/drivers/i2c/designware_i2c_pci.c
> @@ -7,6 +7,7 @@
>
>  #include 
>  #include 
> +#include 
>  #include "designware_i2c.h"
>
>  /* BayTrail HCNT/LCNT/SDA hold time */
> @@ -18,17 +19,49 @@ static struct dw_scl_sda_cfg byt_config = {
> .sda_hold = 0x6,
>  };
>
> -static int designware_i2c_pci_probe(struct udevice *dev)
> +/* Have a weak function for now - possibly should be a new uclass */
> +__weak void lpss_reset_release(void *regs);

This function is not called in this driver. Maybe this should belong
to another commit?

> +
> +static int designware_i2c_pci_ofdata_to_platdata(struct udevice *dev)
>  {
> struct dw_i2c *priv = dev_get_priv(dev);
>
> +   if (spl_phase() < PHASE_SPL) {
> +   u32 base;
> +   int ret;
> +
> +   ret = dev_read_u32(dev, "early-regs", &base);
> +   if (ret)
> +   return log_msg_ret("early-regs", ret);
> +
> +   /* Set i2c base address */
> +   dm_pci_write_config32(dev, PCI_BASE_ADDRESS_0, base);
> +
> +   /* Enable memory access and bus master */
> +   dm_pci_write_config32(dev, PCI_COMMAND, PCI_COMMAND_MEMORY |
> + PCI_COMMAND_MASTER);
> +   }
> +
> +   if (spl_phase() < PHASE_BOARD_F) {
> +   /* Handle early, fixed mapping into a different address space 
> */
> +   priv->regs = (struct i2c_regs *)dm_pci_read_bar32(dev, 0);
> +   } else {
> +   priv->regs = (struct i2c_regs *)
> +   dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0, 
> PCI_REGION_MEM);
> +   }
> +   if (!priv->regs)
> +   return -EINVAL;
> +
> /* Save base address from PCI BAR */
> -   priv->regs = (struct i2c_regs *)
> -   dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
> if (IS_ENABLED(CONFIG_INTEL_BAYTRAIL))
> /* Use BayTrail specific timing values */
> priv->scl_sda_cfg = &byt_config;
>
> +   return 0;
> +}
> +
> +static int designware_i2c_pci_probe(struct udevice *dev)
> +{
> return designware_i2c_probe(dev);
>  }
>
> @@ -56,10 +89,17 @@ static int designware_i2c_pci_bind(struct udevice *dev)
> return 0;
>  }
>
> +static const struct udevice_id designware_i2c_pci_ids[] = {
> +   { .compatible = "snps,designware-i2c-pci" },
> +   { }
> +};
> +
>  U_BOOT_DRIVER(i2c_designware_pci) = {
> .name   = "i2c_designware_pci",
> .id = UCLASS_I2C,
> +   .of_match = designware_i2c_pci_ids,
> .bind   = designware_i2c_pci_bind,
> +   .ofdata_to_platdata = designware_i2c_pci_ofdata_to_platdata,
> .probe  = designware_i2c_pci_probe,
> .priv_auto_alloc_size = sizeof(struct dw_i2c),
> .remove = designware_i2c_remove,
> --

Looks good otherwise:

Reviewed-by: Bin Meng 

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


Re: [U-Boot] [PATCH v5 007/101] i2c: designware: Tidy up PCI support

2019-11-25 Thread Bin Meng
Hi Simon,


On Mon, Nov 25, 2019 at 12:11 PM Simon Glass  wrote:
>
> This is hacked into the driver at present. It seems better to have it as
> a separate driver that uses the base driver. Create a new file and put
> the X86 code into it.
>
> Actually the Baytrail settings should really come from the device tree.
>
> Note that 'has_max_speed' is added as well. This is currently always false
> but since only Baytrail provides the config, it does not affect operation
> for other devices.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Heiko Schocher 
> ---
>
> Changes in v5: None
> Changes in v4:
> - Add a comment about the speed logic in __dw_i2c_set_bus_speed()
> - Add a comment in the commit message about why has_max_speed is added
> - Drop unwanted debug printf("bad\n")
> - Fix indentation nit
> - Rename new file to designware_i2c_pci.c
>
> Changes in v3: None
> Changes in v2: None
>
>  drivers/i2c/Makefile |   3 +
>  drivers/i2c/designware_i2c.c | 106 +--
>  drivers/i2c/designware_i2c.h |  35 ++
>  drivers/i2c/designware_i2c_pci.c |  79 +++
>  4 files changed, 134 insertions(+), 89 deletions(-)
>  create mode 100644 drivers/i2c/designware_i2c_pci.c
>
> diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
> index c2f75d8755..f5a471f887 100644
> --- a/drivers/i2c/Makefile
> +++ b/drivers/i2c/Makefile
> @@ -14,6 +14,9 @@ obj-$(CONFIG_SYS_I2C_AT91) += at91_i2c.o
>  obj-$(CONFIG_SYS_I2C_CADENCE) += i2c-cdns.o
>  obj-$(CONFIG_SYS_I2C_DAVINCI) += davinci_i2c.o
>  obj-$(CONFIG_SYS_I2C_DW) += designware_i2c.o
> +ifdef CONFIG_DM_PCI
> +obj-$(CONFIG_SYS_I2C_DW) += designware_i2c_pci.o
> +endif
>  obj-$(CONFIG_SYS_I2C_FSL) += fsl_i2c.o
>  obj-$(CONFIG_SYS_I2C_IHS) += ihs_i2c.o
>  obj-$(CONFIG_SYS_I2C_INTEL) += intel_i2c.o
> diff --git a/drivers/i2c/designware_i2c.c b/drivers/i2c/designware_i2c.c
> index 6daa90e744..99b7d09bb2 100644
> --- a/drivers/i2c/designware_i2c.c
> +++ b/drivers/i2c/designware_i2c.c
> @@ -13,34 +13,6 @@
>  #include 
>  #include "designware_i2c.h"
>
> -struct dw_scl_sda_cfg {
> -   u32 ss_hcnt;
> -   u32 fs_hcnt;
> -   u32 ss_lcnt;
> -   u32 fs_lcnt;
> -   u32 sda_hold;
> -};
> -
> -#ifdef CONFIG_X86
> -/* BayTrail HCNT/LCNT/SDA hold time */
> -static struct dw_scl_sda_cfg byt_config = {
> -   .ss_hcnt = 0x200,
> -   .fs_hcnt = 0x55,
> -   .ss_lcnt = 0x200,
> -   .fs_lcnt = 0x99,
> -   .sda_hold = 0x6,
> -};
> -#endif
> -
> -struct dw_i2c {
> -   struct i2c_regs *regs;
> -   struct dw_scl_sda_cfg *scl_sda_cfg;
> -   struct reset_ctl_bulk resets;
> -#if CONFIG_IS_ENABLED(CLK)
> -   struct clk clk;
> -#endif
> -};
> -
>  #ifdef CONFIG_SYS_I2C_DW_ENABLE_STATUS_UNSUPPORTED
>  static int  dw_i2c_enable(struct i2c_regs *i2c_base, bool enable)
>  {
> @@ -90,7 +62,9 @@ static unsigned int __dw_i2c_set_bus_speed(struct i2c_regs 
> *i2c_base,
> unsigned int ena;
> int i2c_spd;
>
> -   if (speed >= I2C_MAX_SPEED)
> +   /* Allow max speed if there is no config , or the config allows it */

nits: remove the space before ,

> +   if (speed >= I2C_MAX_SPEED &&
> +   (!scl_sda_cfg || scl_sda_cfg->has_max_speed))

So with this change, for Baytrail, this new logic does not match the old codes.

Baytrail has the config, but its config does not have the
has_max_speed, so the if () logic evaluates to false.

> i2c_spd = IC_SPEED_MODE_MAX;
> else if (speed >= I2C_FAST_SPEED)
> i2c_spd = IC_SPEED_MODE_FAST;
> @@ -106,7 +80,6 @@ static unsigned int __dw_i2c_set_bus_speed(struct i2c_regs 
> *i2c_base,
> cntl = (readl(&i2c_base->ic_con) & (~IC_CON_SPD_MSK));
>
> switch (i2c_spd) {
> -#ifndef CONFIG_X86 /* No High-speed for BayTrail yet */
> case IC_SPEED_MODE_MAX:
> cntl |= IC_CON_SPD_SS;
> if (scl_sda_cfg) {
> @@ -119,7 +92,6 @@ static unsigned int __dw_i2c_set_bus_speed(struct i2c_regs 
> *i2c_base,
> writel(hcnt, &i2c_base->ic_hs_scl_hcnt);
> writel(lcnt, &i2c_base->ic_hs_scl_lcnt);
> break;
> -#endif
>
> case IC_SPEED_MODE_STANDARD:
> cntl |= IC_CON_SPD_SS;
> @@ -565,24 +537,19 @@ static int designware_i2c_probe_chip(struct udevice 
> *bus, uint chip_addr,
> return ret;
>  }
>
> -static int designware_i2c_probe(struct udevice *bus)
> +static int designware_i2c_ofdata_to_platdata(struct udevice *bus)
>  {
> struct dw_i2c *priv = dev_get_priv(bus);
> -   int ret;
>
> -   if (device_is_on_pci_bus(bus)) {
> -#ifdef CONFIG_DM_PCI
> -   /* Save base address from PCI BAR */
> -   priv->regs = (struct i2c_regs *)
> -   dm_pci_map_bar(bus, PCI_BASE_ADDRESS_0, 
> PCI_REGION_MEM);
> -#ifdef CONFIG_X86
> -   /* Use BayTrail specific timing values */
> -   priv->scl_sda_cfg = &byt_config;
> -#endif
> -#en

Re: [U-Boot] [PATCH v3 01/20] arch: powerpc: add eSDHC node to p1020 dts

2019-11-25 Thread Priyanka Jain


>-Original Message-
>From: Yinbo Zhu 
>Sent: Tuesday, October 15, 2019 2:51 PM
>To: Wolfgang Denk ; Priyanka Jain ;
>Shengzhou Liu ; u-boot@lists.denx.de
>Cc: Yinbo Zhu ; Xiaobo Xie ;
>Jiafei Pan ; Prabhakar X
>; Bin Meng ; Simon
>Goldschmidt ; Adam Ford
>; Patrick Delaunay ; Jeremy
>Gebben ; Joe Hershberger
>; Y.b. Lu 
>Subject: [PATCH v3 01/20] arch: powerpc: add eSDHC node to p1020 dts
>
>Add eSDHC node to p1020 dts
>
>Signed-off-by: Yinbo Zhu 
>---
> arch/powerpc/dts/p1020-post.dtsi | 7 +++
> 1 file changed, 7 insertions(+)
>
>diff --git a/arch/powerpc/dts/p1020-post.dtsi b/arch/powerpc/dts/p1020-
>post.dtsi
>index 1e5e678..fb3b203 100644
>--- a/arch/powerpc/dts/p1020-post.dtsi
>+++ b/arch/powerpc/dts/p1020-post.dtsi
>@@ -24,6 +24,13 @@
>   single-cpu-affinity;
>   last-interrupt-source = <255>;
>   };
>+
>+  esdhc: esdhc@2e000 {
>+  compatible = "fsl,esdhc";
>+  reg = <0x2e000 0x1000>;
>+  /* Filled in by U-Boot */
>+  clock-frequency = <0>;
>+  };
> };
>
> /* PCIe controller base address 0x9000 */
>--
>2.9.5
Series applied to mpc85xx master after rebased to top of tree, awaiting 
upstream.

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


[U-Boot] pull request u-boot-mpc85xx

2019-11-25 Thread Priyanka Jain
Dear Tom,

Please find my pull-request for u-boot-mpc85xx/master
https://travis-ci.org/p-priyanka-jain/u-boot/builds/616526169

Summary
powerpc: Fix DM_MMC related build warnings by adding
eSDHC device module support for T4240RDB, T2080RDB, T1042D4RDB,
T1024RDB, P5040DS, P4080DS, P3041DS, P2041RDB, P2020RDB,
P1020RDB platforms

priyankajain

The following changes since commit 9a0cbae22a613dfd55e15565785749b74c19fdf0:

  Merge tag 'u-boot-rockchip-20191124' of 
https://gitlab.denx.de/u-boot/custodians/u-boot-rockchip (2019-11-23 20:50:11 
-0500)

are available in the Git repository at:

  https://gitlab.denx.de/u-boot/custodians/u-boot-mpc85xx.git HEAD

for you to fetch changes up to 3fca56ee429f1188a44113ec35d426a85068a9d2:

  configs: enable eSDHC device module for T4240RDB board (2019-11-25 11:54:28 
+0530)


Yinbo Zhu (20):
  arch: powerpc: add eSDHC node to p1020 dts
  arch: powerpc: add eSDHC node to p2020 dts
  arch: powerpc: add eSDHC node to p2041 dts
  arch: powerpc: add eSDHC node to p3041 dts
  arch: powerpc: add eSDHC node to p4080 dts
  arch: powerpc: add eSDHC node to p5040 dts
  arch: powerpc: add eSDHC node to t102x dts
  arch: powerpc: add eSDHC node to t104x dts
  arch: powerpc: add eSDHC node to t4240 dts
  board: sdhc: Use block layer to read from mmc
  configs: enable eSDHC device module for P1020RDB board
  configs: enable eSDHC device module for P2020RDB board
  configs: enable eSDHC device module for P2041RDB board
  configs: enable eSDHC device module for P3041DS board
  configs: enable eSDHC device module for P4080DS board
  configs: enable eSDHC device module for P5040DS board
  configs: enable eSDHC device module for T1024RDB board
  configs: enable eSDHC device module for T1042D4RDB board
  configs: enable eSDHC device module for T2080RDB board
  configs: enable eSDHC device module for T4240RDB board

 arch/powerpc/dts/p1020-post.dtsi | 7 +++
 arch/powerpc/dts/p2020-post.dtsi | 7 +++
 arch/powerpc/dts/p2041.dtsi  | 6 ++
 arch/powerpc/dts/p3041.dtsi  | 6 ++
 arch/powerpc/dts/p4080.dtsi  | 6 ++
 arch/powerpc/dts/p5040.dtsi  | 6 ++
 arch/powerpc/dts/t102x.dtsi  | 6 ++
 arch/powerpc/dts/t104x.dtsi  | 6 ++
 arch/powerpc/dts/t4240.dtsi  | 6 ++
 board/freescale/common/sdhc_boot.c   | 4 
 configs/P1020RDB-PC_36BIT_NAND_defconfig | 1 +
 configs/P1020RDB-PC_36BIT_SDCARD_defconfig   | 1 +
 configs/P1020RDB-PC_36BIT_SPIFLASH_defconfig | 1 +
 configs/P1020RDB-PC_36BIT_defconfig  | 1 +
 configs/P1020RDB-PC_NAND_defconfig   | 1 +
 configs/P1020RDB-PC_SDCARD_defconfig | 1 +
 configs/P1020RDB-PC_SPIFLASH_defconfig   | 1 +
 configs/P1020RDB-PC_defconfig| 1 +
 configs/P1020RDB-PD_NAND_defconfig   | 1 +
 configs/P1020RDB-PD_SDCARD_defconfig | 1 +
 configs/P1020RDB-PD_SPIFLASH_defconfig   | 1 +
 configs/P1020RDB-PD_defconfig| 1 +
 configs/P2020RDB-PC_36BIT_NAND_defconfig | 1 +
 configs/P2020RDB-PC_36BIT_SDCARD_defconfig   | 1 +
 configs/P2020RDB-PC_36BIT_SPIFLASH_defconfig | 1 +
 configs/P2020RDB-PC_36BIT_defconfig  | 1 +
 configs/P2020RDB-PC_NAND_defconfig   | 1 +
 configs/P2020RDB-PC_SDCARD_defconfig | 1 +
 configs/P2020RDB-PC_SPIFLASH_defconfig   | 1 +
 configs/P2020RDB-PC_defconfig| 1 +
 configs/P2041RDB_NAND_defconfig  | 1 +
 configs/P2041RDB_SDCARD_defconfig| 1 +
 configs/P2041RDB_SPIFLASH_defconfig  | 1 +
 configs/P2041RDB_defconfig   | 1 +
 configs/P3041DS_NAND_defconfig   | 1 +
 configs/P3041DS_SDCARD_defconfig | 1 +
 configs/P3041DS_SPIFLASH_defconfig   | 1 +
 configs/P3041DS_defconfig| 1 +
 configs/P4080DS_SDCARD_defconfig | 1 +
 configs/P4080DS_SPIFLASH_defconfig   | 1 +
 configs/P4080DS_defconfig| 1 +
 configs/P5040DS_NAND_defconfig   | 1 +
 configs/P5040DS_SDCARD_defconfig | 1 +
 configs/P5040DS_SPIFLASH_defconfig   | 1 +
 configs/P5040DS_defconfig| 1 +
 configs/T1024RDB_NAND_defconfig  | 1 +
 configs/T1024RDB_SDCARD_defconfig| 1 +
 configs/T1024RDB_SPIFLASH_defconfig  | 1 +
 configs/T1024RDB_defconfig   | 1 +
 configs/T1042D4RDB_NAND_defconfig| 1 +
 configs/T1042D4RDB_SDCARD_defconfig  | 1 +
 configs/T1042D4RDB_SPIFLASH_defconfig| 1 +
 configs/T1042D4RDB_defconfig | 1 +
configs/T2080RDB_NAND_defconfig  | 1 +
 configs/T2080RDB_SDCARD_defconfig| 1 +
 configs/T2080RDB_SPIFLASH_defconfig  | 1 +
 configs

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

2019-11-25 Thread Heinrich Schuchardt

On 11/13/19 1:44 AM, AKASHI Takahiro wrote:

Without this commit, time.h possibly causes a build error as
asctime_r() uses sprintf().


asctime_r() is not a Linux symbol (as of next-20191119)

ctime_r() and asctime_r() are defined as inline functions. ctime_r() is
used in multiple places and so we may end up duplicating code. So I
would prefer the inline functions in time.h to be moved to a separate C
file in lib/.

Best regards

Heinrich



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

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

  #include 
+#include 
  #include 

  #define _DEFUN(a,b,c) a(c)



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


Re: [U-Boot] [PATCH v3] armv8: ls1046afrwy: Add support for LS1046AFRWY Rev B board

2019-11-25 Thread Priyanka Jain


>-Original Message-
>From: Pramod Kumar 
>Sent: Monday, November 25, 2019 6:28 PM
>To: u-boot@lists.denx.de
>Cc: Priyanka Jain ; Pramod Kumar
>
>Subject: [PATCH v3] armv8: ls1046afrwy: Add support for LS1046AFRWY Rev B
>board
Is it v3?If yes, please add change history
>
>Add rev B board support
Please add small description on what changes you are adding for Rev B
>
>Signed-off-by: Pramod Kumar 
>---
> board/freescale/ls1046afrwy/ls1046afrwy.c | 9 +++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
>diff --git a/board/freescale/ls1046afrwy/ls1046afrwy.c
>b/board/freescale/ls1046afrwy/ls1046afrwy.c
>index ac2f8ee..3134feb 100644
>--- a/board/freescale/ls1046afrwy/ls1046afrwy.c
>+++ b/board/freescale/ls1046afrwy/ls1046afrwy.c
>@@ -24,7 +24,7 @@
> #define LS1046A_PORSR1_REG 0x1EE
> #define BOOT_SRC_SD0x2000
> #define BOOT_SRC_MASK0xFF80
>-#define BOARD_REV_GPIO13
>+#define BOARD_REV_GPIO_SHIFT  17
> #define USB2_SEL_MASK0x0100
>
> #define BYTE_SWAP_32(word)  word) & 0xff00) >> 24) |  \ @@ -88,9
>+88,14 @@ int board_early_init_f(void)  static inline uint8_t
>get_board_version(void)  {
>   u8 val;
>+  u32 gpio_val;
>   struct ccsr_gpio *pgpio = (void *)(GPIO2_BASE_ADDR);
>
>-  val = (in_le32(&pgpio->gpdat) >> BOARD_REV_GPIO) & 0x03;
>+  /* GPIO 13 and GPIO 14 are use for Board Rev */
>+  gpio_val = ((in_be32(&pgpio->gpdat) >> BOARD_REV_GPIO_SHIFT)) &
>0x03;
Please don't use magic numbers.
>+
>+  /* GPIO's are 0..31 in Big Endiness, swap GPIO 13 and GPIO 14 */
>+  val = ((gpio_val >> 1) | (gpio_val << 1)) & 0x03;
>
>   return val;
> }
>--
>2.7.4
-priyankajain
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


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

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

Signed-off-by: Ran Wang 
---
Change in v5:
- Add paragraph to describe config SYS_FSL_ERRATUM_A050106 in Kconfig

Change in v4:
- Include defines of USB_PHY_RX_EQ_VAL_3 and USB_PHY_RX_EQ_VAL_4 for
  LS1028A to fix compile failure.

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

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

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

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

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


Re: [U-Boot] [PATCH 2/3] mtd: rawnand: denali: Allow operation without clock driver

2019-11-25 Thread Masahiro Yamada
On Thu, Nov 21, 2019 at 6:38 AM Marek Vasut  wrote:
>
> The SoCFPGA Gen5 does not have a clock driver yet, let the NAND driver
> work without a clock driver by falling back to the default frequencies.
>
> Signed-off-by: Marek Vasut 
> Cc: Masahiro Yamada 
> ---
>  drivers/mtd/nand/raw/denali_dt.c | 12 
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/denali_dt.c 
> b/drivers/mtd/nand/raw/denali_dt.c
> index 0ce81324b9..2c9e249ab6 100644
> --- a/drivers/mtd/nand/raw/denali_dt.c
> +++ b/drivers/mtd/nand/raw/denali_dt.c
> @@ -62,7 +62,6 @@ static int denali_dt_probe(struct udevice *dev)
>  {
> struct denali_nand_info *denali = dev_get_priv(dev);
> const struct denali_dt_data *data;
> -   struct clk clk, clk_x, clk_ecc;
> struct resource res;
> int ret;
>
> @@ -87,11 +86,14 @@ static int denali_dt_probe(struct udevice *dev)
>
> denali->host = devm_ioremap(dev, res.start, resource_size(&res));
>
> +#if CONFIG_IS_ENABLED(CLK)
> +   struct clk clk, clk_x, clk_ecc;
> +
> ret = clk_get_by_name(dev, "nand", &clk);
> if (ret)
> ret = clk_get_by_index(dev, 0, &clk);
> if (ret)
> -   return ret;
> +   clk.dev = NULL;

This line changes the 'clk' optional.
Do you need additional #if CONFIG_IS_ENABLED(CLK) ?



BTW, in Linux, clk_get() and clk_enable() are no-op
when CONFIG_HAVE_CLK is unset.

The U-Boot's clk_get() returns -ENOSYS, hence
drivers tend to be ugly.
I already stopped caring the U-Boot code, though.



> ret = clk_get_by_name(dev, "nand_x", &clk_x);
> if (ret)
> @@ -117,10 +119,12 @@ static int denali_dt_probe(struct udevice *dev)
> return ret;
> }
>
> -   if (clk_x.dev) {
> +   if (clk.dev && clk_x.dev) {
> denali->clk_rate = clk_get_rate(&clk);
> denali->clk_x_rate = clk_get_rate(&clk_x);
> -   } else {
> +   } else
> +#endif
> +   {
> /*
>  * Hardcode the clock rates for the backward compatibility.
>  * This works for both SOCFPGA and UniPhier.
> --
> 2.24.0.432.g9d3f5f5b63
>
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot



--
Best Regards

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


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

2019-11-25 Thread Heinrich Schuchardt

On 11/13/19 1:44 AM, AKASHI Takahiro wrote:

Adding "printk.h" will help improve portability from linux kernel
code (in my case, lib/asn1_decoder.c and others) where printf and


nits:

%s/printf/printk/g

You anyway change the includes in lib/crypto/public_key.c in patch 12/16
and lib/asn1_decoder in patch 09/16. So why not add linux/printk.h there?

Otherwise I would expect this patch to remove #include 
in all files where it becomes obsolete due to this patch, e.g.

board/synopsys/hsdk/hsdk.c
arch/arm/mach-uniphier/fdt-fixup.c
arch/arm/mach-uniphier/dram_init.c
arch/arm/mach-uniphier/arm32/psci.c
arch/arm/mach-uniphier/dram/ddrphy-training.c

Best regards

Heinrich


pr_* variant functions are used.

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

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 5c7e5f635b1a..564819a1c0a7 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -1,8 +1,8 @@
  #ifndef _LINUX_KERNEL_H
  #define _LINUX_KERNEL_H

-
  #include 
+#include  /* for printf/pr_* utilities */

  #define USHRT_MAX ((u16)(~0U))
  #define SHRT_MAX  ((s16)(USHRT_MAX>>1))



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


Re: [U-Boot] [PATCH v2 5/5] board: ti: beagleboneai: enable in am57xx_evm_defconfig

2019-11-25 Thread Lokesh Vutla


On 25/11/19 8:26 PM, Caleb Robey wrote:
> Adding the configurations to the evm_defconfig file
> 
> Signed-off-by: Jason Kridner 
> Signed-off-by: Caleb Robey 

Reviewed-by: Lokesh Vutla 

Thanks and regards,
Lokesh


> 
> ---
> 
> v2 Changes:
>   - addition of CONFIG_PREBOOT for console configuration
>   - removal of changes that hardcoded CONSOLEDEV value
> 
>  configs/am57xx_evm_defconfig  | 3 ++-
>  include/environment/ti/boot.h | 2 ++
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/configs/am57xx_evm_defconfig b/configs/am57xx_evm_defconfig
> index 588e58947d..8823e350f7 100644
> --- a/configs/am57xx_evm_defconfig
> +++ b/configs/am57xx_evm_defconfig
> @@ -16,6 +16,7 @@ CONFIG_SPL_LOAD_FIT=y
>  CONFIG_OF_BOARD_SETUP=y
>  CONFIG_USE_BOOTARGS=y
>  CONFIG_BOOTARGS="androidboot.serialno=${serial#} console=ttyS2,115200 
> androidboot.console=ttyS2 androidboot.hardware=beagle_x15board"
> +CONFIG_PREBOOT="if $board_name=am5729_beaglebonai; then setenv console 
> ttyS0,115200; fi;"
>  # CONFIG_USE_BOOTCOMMAND is not set
>  CONFIG_SYS_CONSOLE_INFO_QUIET=y
>  # CONFIG_MISC_INIT_R is not set
> @@ -38,7 +39,7 @@ CONFIG_CMD_BCB=y
>  CONFIG_OF_CONTROL=y
>  CONFIG_SPL_OF_CONTROL=y
>  CONFIG_DEFAULT_DEVICE_TREE="am572x-idk"
> -CONFIG_OF_LIST="am57xx-beagle-x15 am57xx-beagle-x15-revb1 
> am57xx-beagle-x15-revc am572x-idk am571x-idk am574x-idk"
> +CONFIG_OF_LIST="am57xx-beagle-x15 am57xx-beagle-x15-revb1 
> am57xx-beagle-x15-revc am5729-beagleboneai am572x-idk am571x-idk am574x-idk"
>  CONFIG_ENV_IS_IN_MMC=y
>  CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
>  CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
> diff --git a/include/environment/ti/boot.h b/include/environment/ti/boot.h
> index 684a744f31..6313f3e328 100644
> --- a/include/environment/ti/boot.h
> +++ b/include/environment/ti/boot.h
> @@ -185,6 +185,8 @@
>   "setenv fdtfile am57xx-beagle-x15-revb1.dtb; fi;" \
>   "if test $board_name = beagle_x15_revc; then " \
>   "setenv fdtfile am57xx-beagle-x15-revc.dtb; fi;" \
> + "if test $board_name = am5729_beagleboneai; then " \
> + "setenv fdtfile am5729-beagleboneai.dtb; fi;" \
>   "if test $board_name = am572x_idk; then " \
>   "setenv fdtfile am572x-idk.dtb; fi;" \
>   "if test $board_name = am574x_idk; then " \
> 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 4/5] board: ti: beagleboneai: add dts file

2019-11-25 Thread Lokesh Vutla


On 25/11/19 8:26 PM, Caleb Robey wrote:
> From: Jason Kridner 
> 
> BeagleBoard.org BeagleBone AI is an open source hardware single
> board computer based on the Texas Instruments AM5729 SoC featuring
> dual-core 1.5GHz Arm Cortex-A15 processor, dual-core C66 digital
> signal processor (DSP), quad-core embedded vision engine (EVE),
> Arm Cortex-M4 processors, dual programmable realtime unit
> industrial control subsystems and more. The board features 1GB
> DDR3L, USB3.0 Type-C, USB HS Type-A, microHDMI, 16GB eMMC flash,
> 1G Ethernet, 802.11ac 2/5GHz, Bluetooth, and BeagleBone expansion
> headers.
> 
> For more information, refer to:
> https://beaglebone.ai
> 
> The corresponding patch against the mainline linux kernel
> can be found at: https://patchwork.kernel.org/patch/11254903/
> 
> This patch introduces the BeagleBone AI device tree.
> 
> Note that the device use the "ti,tpd12s016" component which is
> software compatible with "ti,tpd12s015". Thus we only use the
> latter driver.
> 
> Due to small modifications in ocp, a tag was added to dra7.dtsi
> in the ocp component.
> 
> Signed-off-by: Jason Kridner 
> Signed-off-by: Caleb Robey 
> Cc: Robert Nelson 

Reviewed-by: Lokesh Vutla 

Thanks and regards,
Lokesh


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


Re: [U-Boot] [PATCH v2 3/5] board: ti: beagleboneai: IODELAY and pinmux changes

2019-11-25 Thread Lokesh Vutla


On 25/11/19 8:26 PM, Caleb Robey wrote:
> This patch configures the pinmux settings for the BeagleBone AI after
> the emmc read has completed.
> 
> Signed-off-by: Jason Kridner 
> Signed-off-by: Caleb Robey 
> Cc: Robert Nelson 

Reviewed-by: Lokesh Vutla 

Thanks and regards,
Lokesh
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 2/5] board: ti: beagleboneai: add initial support

2019-11-25 Thread Lokesh Vutla


On 25/11/19 8:26 PM, Caleb Robey wrote:
> These are necessities for beaglebone ai boot.
> 
> Signed-off-by: Jason Kridner 
> Signed-off-by: Caleb Robey 


Reviewed-by: Lokesh Vutla 

Thanks and regards,
Lokesh


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


Re: [U-Boot] [PATCH v2 1/5] board: ti: beagleboneai: emmc read changes

2019-11-25 Thread Lokesh Vutla


On 25/11/19 8:26 PM, Caleb Robey wrote:
> BeagleBoard.org BeagleBone AI rev A1 does not include a board
> identifier I2C EEPROM due to a design oversight. These boards have
> been put into production and are generally available now.
> 
> The board identifier information, however, has been included in the
> second eMMC linear boot partition (/dev/mmcblk1boot1).
> 
> This patch works by:
> * First, looking for a board identifier I2C EEPROM and if not found,
> * Then seeing if the boot mode matches BeagleBone AI with eMMC in the
>   boot chain to make sure we don't enable eMMC pinmuxes on boards
>   that don't support it, and
> * Finally, initializes the eMMC pins and reading the header.
> 
> Signed-off-by: Jason Kridner 
> Signed-off-by: Caleb Robey 
> Cc: Robert Nelson 

Reviewed-by: Lokesh Vutla 

Thanks and regards,
Lokesh
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


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

2019-11-25 Thread Heinrich Schuchardt

On 11/13/19 1:44 AM, AKASHI Takahiro wrote:

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

Signed-off-by: AKASHI Takahiro


km_kirkwood_defconfig with CONFIG_UBIFS=y compiles.

Reviewed-by: Heinrich Schuchardt 

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


Re: [U-Boot] [PATCH v2 1/6] remoteproc: elf_loader: Add elf resource table load support

2019-11-25 Thread Lokesh Vutla


On 30/10/19 7:08 PM, Fabien Dessenne wrote:
> Add rproc_elf_load_rsc_table(), which searches for a resource table in
> an elf64/elf32 image, and if found, copies it to device memory.
> Add also the elf32 and elf64 variants of this API.
> Add a test for this.
> 
> Signed-off-by: Fabien Dessenne 

Reviewed-by: Lokesh Vutla 

Thanks and regards,
Lokesh

> ---
>  drivers/remoteproc/rproc-elf-loader.c | 269 
> ++
>  include/remoteproc.h  |  70 +
>  test/dm/remoteproc.c  |  91 ++--
>  3 files changed, 419 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/remoteproc/rproc-elf-loader.c 
> b/drivers/remoteproc/rproc-elf-loader.c
> index b38a226..9127ea5 100644
> --- a/drivers/remoteproc/rproc-elf-loader.c
> +++ b/drivers/remoteproc/rproc-elf-loader.c
> @@ -7,6 +7,39 @@
>  #include 
>  #include 
>  
> +/**
> + * struct resource_table - firmware resource table header
> + * @ver: version number
> + * @num: number of resource entries
> + * @reserved: reserved (must be zero)
> + * @offset: array of offsets pointing at the various resource entries
> + *
> + * A resource table is essentially a list of system resources required
> + * by the remote processor. It may also include configuration entries.
> + * If needed, the remote processor firmware should contain this table
> + * as a dedicated ".resource_table" ELF section.
> + *
> + * Some resources entries are mere announcements, where the host is informed
> + * of specific remoteproc configuration. Other entries require the host to
> + * do something (e.g. allocate a system resource). Sometimes a negotiation
> + * is expected, where the firmware requests a resource, and once allocated,
> + * the host should provide back its details (e.g. address of an allocated
> + * memory region).
> + *
> + * The header of the resource table, as expressed by this structure,
> + * contains a version number (should we need to change this format in the
> + * future), the number of available resource entries, and their offsets
> + * in the table.
> + *
> + * Immediately following this header are the resource entries themselves.
> + */
> +struct resource_table {
> + u32 ver;
> + u32 num;
> + u32 reserved[2];
> + u32 offset[0];
> +} __packed;
> +
>  /* Basic function to verify ELF32 image format */
>  int rproc_elf32_sanity_check(ulong addr, ulong size)
>  {
> @@ -275,3 +308,239 @@ ulong rproc_elf_get_boot_addr(struct udevice *dev, 
> ulong addr)
>   else
>   return rproc_elf32_get_boot_addr(addr);
>  }
> +
> +/*
> + * Search for the resource table in an ELF32 image.
> + * Returns the address of the resource table section if found, NULL if there 
> is
> + * no resource table section, or error pointer.
> + */
> +static Elf32_Shdr *rproc_elf32_find_rsc_table(struct udevice *dev,
> +   ulong fw_addr, ulong fw_size)
> +{
> + int ret;
> + unsigned int i;
> + const char *name_table;
> + struct resource_table *table;
> + const u8 *elf_data = (void *)fw_addr;
> + Elf32_Ehdr *ehdr = (Elf32_Ehdr *)fw_addr;
> + Elf32_Shdr *shdr;
> +
> + ret = rproc_elf32_sanity_check(fw_addr, fw_size);
> + if (ret) {
> + pr_debug("Invalid ELF32 Image %d\n", ret);
> + return ERR_PTR(ret);
> + }
> +
> + /* look for the resource table and handle it */
> + shdr = (Elf32_Shdr *)(elf_data + ehdr->e_shoff);
> + name_table = (const char *)(elf_data +
> + shdr[ehdr->e_shstrndx].sh_offset);
> +
> + for (i = 0; i < ehdr->e_shnum; i++, shdr++) {
> + u32 size = shdr->sh_size;
> + u32 offset = shdr->sh_offset;
> +
> + if (strcmp(name_table + shdr->sh_name, ".resource_table"))
> + continue;
> +
> + table = (struct resource_table *)(elf_data + offset);
> +
> + /* make sure we have the entire table */
> + if (offset + size > fw_size) {
> + pr_debug("resource table truncated\n");
> + return ERR_PTR(-ENOSPC);
> + }
> +
> + /* make sure table has at least the header */
> + if (sizeof(*table) > size) {
> + pr_debug("header-less resource table\n");
> + return ERR_PTR(-ENOSPC);
> + }
> +
> + /* we don't support any version beyond the first */
> + if (table->ver != 1) {
> + pr_debug("unsupported fw ver: %d\n", table->ver);
> + return ERR_PTR(-EPROTONOSUPPORT);
> + }
> +
> + /* make sure reserved bytes are zeroes */
> + if (table->reserved[0] || table->reserved[1]) {
> + pr_debug("non zero reserved bytes\n");
> + return ERR_PTR(-EBADF);
> + }
> +
> + /* make sure the offsets array isn't truncated */

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

2019-11-25 Thread Heinrich Schuchardt

On 11/26/19 1:51 AM, AKASHI Takahiro wrote:

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(+)


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


Re: [U-Boot] [EXT] Re: [PATCHv2 1/2] PCI: layerscape: Add Support for ls2088 PCIe EP mode

2019-11-25 Thread Xiaowei Bao
H Ramon,

Thanks for your comments.
If we reimplement the PCIe EP driver base on PCIe UCLASS, we must test it in 
u-boot, but I have no idea how to test the actual device, do I need to 
implement our own test case, how to verify the cadence-ep actual device?

Best regards
Xiaowei


From: Ramon Fried 
Sent: 2019年11月25日 20:15
To: Xiaowei Bao 
Cc: Bin Meng ; Simon Glass ; M.h. Lian 
; Z.q. Hou ; Mingkai Hu 
; Hongbo Wang ; York Sun 
; u-boot@lists.denx.de
Subject: Re: [EXT] Re: [U-Boot] [PATCHv2 1/2] PCI: layerscape: Add Support for 
ls2088 PCIe EP mode



Hi Ramon,

I need your help on this, could you help explain how to start the PCIe EP test 
in
u-boot? Thanks a lot.
Hi, you just need to run the test suite and it will test the PCIe EP sandbox 
class automatically.
See test/README
Why do you care about the EP testing, it's testing the PCIe UCLASS 
implementation.
To test your implementation you need to test on actual device.
Thanks,
Ramon.

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


Re: [U-Boot] [PATCH 3/3] mtd: rawnand: denali: Do not reset the block on SoCFPGA

2019-11-25 Thread Masahiro Yamada
On Thu, Nov 21, 2019 at 6:38 AM Marek Vasut  wrote:
>
> Legacy kernel versions for SoCFPGA may not implement proper reset
> handling.

What is "legacy kernel versions" ?



> Apply the same approach as SoCFPGA reset driver, check
> environment variable "socfpga_legacy_reset_compat", and if it is
> set, do not reset the IP before booting Linux. This way, even the
> older kernel versions can be booted by up to date U-Boot.
>
> Signed-off-by: Marek Vasut 
> Cc: Masahiro Yamada 
> ---
>  drivers/mtd/nand/raw/denali_dt.c | 12 
>  1 file changed, 12 insertions(+)
>
> diff --git a/drivers/mtd/nand/raw/denali_dt.c 
> b/drivers/mtd/nand/raw/denali_dt.c
> index 2c9e249ab6..d35f2a3543 100644
> --- a/drivers/mtd/nand/raw/denali_dt.c
> +++ b/drivers/mtd/nand/raw/denali_dt.c
> @@ -148,6 +148,18 @@ static int denali_dt_remove(struct udevice *dev)
>  {
> struct denali_nand_info *denali = dev_get_priv(dev);
>
> +#if CONFIG_IS_ENABLED(ARCH_SOCFPGA)
> +   /*
> +* Legacy kernel versions do not implement proper reset handling on
> +* SoCFPGA. To let those older kernel versions work, reuse the same
> +* approach as the SoCFPGA reset driver does -- check environment
> +* variable socfpga_legacy_reset_compat and avoid resetting the IP
> +* before booting the kernel if it is set to 1.
> +*/
> +   if (env_get_ulong("socfpga_legacy_reset_compat", 10, 0))
> +   return 0;
> +#endif
> +


How about removing denali_dt_remove() entirely ?


Not only SOCFPGA, but also my boards are broken.

I am really annoyed since the following commit:




commit ed784ac3822b7d7019679a41a17907296e2dadbe
Author: Simon Goldschmidt 
AuthorDate: Fri Mar 1 20:12:34 2019 +0100
Commit: Marek Vasut 
CommitDate: Wed Apr 17 22:20:16 2019 +0200

mtd: rawnand: denali: add reset handling

This adds reset handling to the devicetree-enabled Denali NAND driver.

For backwards compatibility, only a warning is printed when failing to
get reset handles.

Signed-off-by: Simon Goldschmidt 



> return reset_release_bulk(&denali->resets);
>  }
>
> --
> 2.24.0.432.g9d3f5f5b63
>
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot



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


Re: [U-Boot] [PATCH 1/3] mtd: rawnand: denali-spl: Add missing hardware init

2019-11-25 Thread Masahiro Yamada
On Thu, Nov 21, 2019 at 6:37 AM Marek Vasut  wrote:
>
> While the Denali NAND is initialized by the BootROM in SPL, there
> are still a couple of settings which are missing. These can trigger
> subtle corruption of the data read out of the NAND. Fill these
> settings in just like they are filled in by the full Denali NAND
> driver in denali_hw_init().

I'd like to know this in more detailed.

I assume these registers are set up by the BootROM,
and SPL is supposed to read data in the same manner as the Boot ROM.

In which situation does the data get corrupted?


> Signed-off-by: Marek Vasut 
> Cc: Masahiro Yamada 
> ---
>  drivers/mtd/nand/raw/denali_spl.c | 7 +++
>  1 file changed, 7 insertions(+)
>
> diff --git a/drivers/mtd/nand/raw/denali_spl.c 
> b/drivers/mtd/nand/raw/denali_spl.c
> index dbaba3cab2..b8b29812aa 100644
> --- a/drivers/mtd/nand/raw/denali_spl.c
> +++ b/drivers/mtd/nand/raw/denali_spl.c
> @@ -173,6 +173,13 @@ void nand_init(void)
> page_size = readl(denali_flash_reg + DEVICE_MAIN_AREA_SIZE);
> oob_size = readl(denali_flash_reg + DEVICE_SPARE_AREA_SIZE);
> pages_per_block = readl(denali_flash_reg + PAGES_PER_BLOCK);
> +
> +   /* Do as denali_hw_init() does. */
> +   writel(CONFIG_NAND_DENALI_SPARE_AREA_SKIP_BYTES,
> +  denali_flash_reg + SPARE_AREA_SKIP_BYTES);

I guess you tested this for SOCFPGA.

Please tell me the value of CONFIG_NAND_DENALI_SPARE_AREA_SKIP_BYTES.






> +   writel(0x0F, denali_flash_reg + RB_PIN_ENABLED);
> +   writel(CHIP_EN_DONT_CARE__FLAG, denali_flash_reg + 
> CHIP_ENABLE_DONT_CARE);
> +   writel(0x, denali_flash_reg + SPARE_AREA_MARKER);
>  }
>
>  int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)
> --
> 2.24.0.432.g9d3f5f5b63
>
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot



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


[U-Boot] [PATCH 3/3] dts: rk3308: Enable ethernet function supported for Firefly ROC_RK3308_CC

2019-11-25 Thread David Wu
The Firefly ROC_RK3308_CC use ref_clock of input mode,
and rmii pins of m1 group.

Signed-off-by: David Wu 
---
 arch/arm/dts/rk3308-roc-cc.dts | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/dts/rk3308-roc-cc.dts b/arch/arm/dts/rk3308-roc-cc.dts
index e10aa638a3..b4a54a852c 100644
--- a/arch/arm/dts/rk3308-roc-cc.dts
+++ b/arch/arm/dts/rk3308-roc-cc.dts
@@ -143,6 +143,15 @@
};
 };
 
+&mac {
+   assigned-clocks = <&cru SCLK_MAC>;
+   assigned-clock-parents = <&mac_clkin>;
+   clock_in_out = "input";
+   pinctrl-names = "default";
+   pinctrl-0 = <&rmiim1_pins &macm1_refclk>;
+   status = "okay";
+};
+
 &pwm5 {
status = "okay";
pinctrl-names = "active";
-- 
2.19.1



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


[U-Boot] [PATCH 2/3] arm: dts: Add mac node for rk3308 at dtsi level

2019-11-25 Thread David Wu
The rk3308 only support RMII mode, and if it is output clock
mode, better to use ref_clk pin with drive strength 12ma.

Signed-off-by: David Wu 
---
 arch/arm/dts/rk3308.dtsi | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/arch/arm/dts/rk3308.dtsi b/arch/arm/dts/rk3308.dtsi
index 0eeec165d4..a5c0b72ae0 100644
--- a/arch/arm/dts/rk3308.dtsi
+++ b/arch/arm/dts/rk3308.dtsi
@@ -627,6 +627,28 @@
status = "disabled";
};
 
+   mac: ethernet@ff4e {
+   compatible = "rockchip,rk3308-mac";
+   reg = <0x0 0xff4e 0x0 0x1>;
+   rockchip,grf = <&grf>;
+   interrupts = ;
+   interrupt-names = "macirq";
+   clocks = <&cru SCLK_MAC>, <&cru SCLK_MAC_RX_TX>,
+<&cru SCLK_MAC_RX_TX>, <&cru SCLK_MAC_REF>,
+<&cru SCLK_MAC>, <&cru ACLK_MAC>,
+<&cru PCLK_MAC>, <&cru SCLK_MAC_RMII>;
+   clock-names = "stmmaceth", "mac_clk_rx",
+ "mac_clk_tx", "clk_mac_ref",
+ "clk_mac_refout", "aclk_mac",
+ "pclk_mac", "clk_mac_speed";
+   phy-mode = "rmii";
+   pinctrl-names = "default";
+   pinctrl-0 = <&rmii_pins &mac_refclk_12ma>;
+   resets = <&cru SRST_MAC_A>;
+   reset-names = "stmmaceth";
+   status = "disabled";
+   };
+
cru: clock-controller@ff50 {
compatible = "rockchip,rk3308-cru";
reg = <0x0 0xff50 0x0 0x1000>;
-- 
2.19.1



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


[U-Boot] [PATCH 1/3] net: gmac_rockchip: Add support for rk3308

2019-11-25 Thread David Wu
Add the glue code to allow the rk3308 variant of the Rockchip gmac
to provide network functionality.

Signed-off-by: David Wu 
---
 drivers/net/gmac_rockchip.c | 65 +
 1 file changed, 65 insertions(+)

diff --git a/drivers/net/gmac_rockchip.c b/drivers/net/gmac_rockchip.c
index d2c52b4c46..e152faf083 100644
--- a/drivers/net/gmac_rockchip.c
+++ b/drivers/net/gmac_rockchip.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -173,6 +174,47 @@ static int rk3288_gmac_fix_mac_speed(struct dw_eth_dev 
*priv)
return 0;
 }
 
+static int rk3308_gmac_fix_mac_speed(struct dw_eth_dev *priv)
+{
+   struct rk3308_grf *grf;
+   struct clk clk_speed;
+   int speed, ret;
+   enum {
+   RK3308_GMAC_SPEED_SHIFT = 0x0,
+   RK3308_GMAC_SPEED_MASK  = BIT(0),
+   RK3308_GMAC_SPEED_10M   = 0,
+   RK3308_GMAC_SPEED_100M  = BIT(0),
+   };
+
+   ret = clk_get_by_name(priv->phydev->dev, "clk_mac_speed",
+ &clk_speed);
+   if (ret)
+   return ret;
+
+   switch (priv->phydev->speed) {
+   case 10:
+   speed = RK3308_GMAC_SPEED_10M;
+   ret = clk_set_rate(&clk_speed, 250);
+   if (ret)
+   return ret;
+   break;
+   case 100:
+   speed = RK3308_GMAC_SPEED_100M;
+   ret = clk_set_rate(&clk_speed, 2500);
+   if (ret)
+   return ret;
+   break;
+   default:
+   debug("Unknown phy speed: %d\n", priv->phydev->speed);
+   return -EINVAL;
+   }
+
+   grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
+   rk_clrsetreg(&grf->mac_con0, RK3308_GMAC_SPEED_MASK, speed);
+
+   return 0;
+}
+
 static int rk3328_gmac_fix_mac_speed(struct dw_eth_dev *priv)
 {
struct rk3328_grf_regs *grf;
@@ -377,6 +419,22 @@ static void rk3288_gmac_set_to_rgmii(struct 
gmac_rockchip_platdata *pdata)
 pdata->tx_delay << RK3288_CLK_TX_DL_CFG_GMAC_SHIFT);
 }
 
+static void rk3308_gmac_set_to_rmii(struct gmac_rockchip_platdata *pdata)
+{
+   struct rk3308_grf *grf;
+   enum {
+   RK3308_GMAC_PHY_INTF_SEL_SHIFT = 2,
+   RK3308_GMAC_PHY_INTF_SEL_MASK  = GENMASK(4, 2),
+   RK3308_GMAC_PHY_INTF_SEL_RMII  = BIT(4),
+   };
+
+   grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
+
+   rk_clrsetreg(&grf->mac_con0,
+RK3308_GMAC_PHY_INTF_SEL_MASK,
+RK3308_GMAC_PHY_INTF_SEL_RMII);
+}
+
 static void rk3328_gmac_set_to_rgmii(struct gmac_rockchip_platdata *pdata)
 {
struct rk3328_grf_regs *grf;
@@ -646,6 +704,11 @@ const struct rk_gmac_ops rk3288_gmac_ops = {
.set_to_rgmii = rk3288_gmac_set_to_rgmii,
 };
 
+const struct rk_gmac_ops rk3308_gmac_ops = {
+   .fix_mac_speed = rk3308_gmac_fix_mac_speed,
+   .set_to_rmii = rk3308_gmac_set_to_rmii,
+};
+
 const struct rk_gmac_ops rk3328_gmac_ops = {
.fix_mac_speed = rk3328_gmac_fix_mac_speed,
.set_to_rgmii = rk3328_gmac_set_to_rgmii,
@@ -673,6 +736,8 @@ static const struct udevice_id rockchip_gmac_ids[] = {
  .data = (ulong)&rk3228_gmac_ops },
{ .compatible = "rockchip,rk3288-gmac",
  .data = (ulong)&rk3288_gmac_ops },
+   { .compatible = "rockchip,rk3308-mac",
+ .data = (ulong)&rk3308_gmac_ops },
{ .compatible = "rockchip,rk3328-gmac",
  .data = (ulong)&rk3328_gmac_ops },
{ .compatible = "rockchip,rk3368-gmac",
-- 
2.19.1



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


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

2019-11-25 Thread AKASHI Takahiro
Some updates,

On Tue, Nov 26, 2019 at 09:51:04AM +0900, AKASHI Takahiro wrote:
> One of major missing features in current UEFI implementation is "secure boot."
> The ultimate goal of my attempt is to implement image authentication based
> on signature and provide UEFI secure boot support which would be fully
> compliant with UEFI specification, section 32[1].
> (The code was originally developed by Patrick Wildt.)
> 
> While this patch/RFC is still rough-edged, the aim here is to get early
> feedbacks from the community as the patch is quite huge (in total) and also
> as it's a security enhancement.

Oops, this sentence should have been deleted.

[...]

> Test:
> * my pytest, included in this patch set, passed.
> * efi_selftest passed. (At least no reguression.)
> * Travis CI tests, except the following two, have passed:
>   - test/py sandbox
> test/py/tests/test_fs/test_unlink.py test_unlink2

I cannot reproduce this issue even if I re-submit a specific job.
It may be a transient error as Heinrich has reported on fat write before?

>   - test/py sandbox with clang
> cmd/efidebug.c:703:15: error: result of comparison of constant 
> 9223372036854775822 with expression of type 'int' is always false 
> [-Werror,-Wtautological-constant-out-of-range-compare]

Sent out a patch.

Thanks,
-Takahiro Akashi

>   But as you can see, those have nothing to do with my UEFI secure boot
>   patch and are existing bugs.
> 
> 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].)
> * Travis CI errors mentioned above
> => I will send *separate* bug-fix patches once fixed.
> 
> 
> Hints about how to use:
> (Please see other documents, or my pytest scripts, for details.)
> * You can create your own certificates with openssl.
> * You can sign your application with sbsign (on Ubuntu).
> * You can create raw data for signature database with efitools, and
>   install/manage authenticated variables with "env -set -e" command
>   or efitools' "UpdateVars.efi" application.
> 
> 
> [1] https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_final.pdf
> [2] https://lists.denx.de/pipermail/u-boot/2019-November/390127.html
> (import x509/pkcs7 parsers from linux)
> [3] https://lists.denx.de/pipermail/u-boot/2019-November/390150.html
> (extend rsa_verify() for UEFI secure boot)
> [4] http://git.linaro.org/people/takahiro.akashi/u-boot.git/ efi/secboot
> [5] https://lists.denx.de/pipermail/u-boot/2019-September/382835.html
> (non-volatile variables support)
> [6] https://bugzilla.tianocore.org/show_bug.cgi?id=2230
> [7] https://lists.denx.de/pipermail/u-boot/2019-November/389593.html
> 
> 
> Changes in 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 seprate patch (patch#12, #16)
> * yield_fixture() -> fixture() (patch#12)
> * call console.restart_uboot() at every test case (13,#14)
> * add patch#15; enable UEFI-related configurations by default on sandbox
> * add patch#16; modify Travis CI environment to run UEFI secure boot test
> 
> Changes in v1 (Nov 13, 2019)
> * rebased to v2020.01-rc
> * remove already-merged patches
> * re-work the patch set for easier reviews, including
>   - move a config definition patch forward (patch#4)
>   - refactor/rename verification functions (patch#5/#10)
>   - split signature database parser as a separate patch (patch#6)
>   - split secure state transition code as a separate patch (patch#8)
>   - move most part of init_secure_boot() into init_variables() (patch#8)
>   - split test environment setup from test patches (patch#14)
> * add function descriptions (patch#5-#11)
> * make sure the section list is sorted in ascending order in hash
>   calculation of PE image (patch#10)
> * add a new "-at" (authenticated access) option to "env -e" (patch#13)
> * list required host packages, in particular udisks2, in pytest
>   (patch#14)
> * modify conftest.py to run under python3 (patch#14)
> * use a partition on a disk instead of a whole disk without partition
>   table (patch#14)
> * reduce depencendy on efitools, yet relying on its host tools (patch#14)
> * modify pytests to catch up wth latest changes of "env -e" syntax
>   (patch#15,#16)
> 
> RFC (Sept 18, 2019)
> 
> AKASHI Takahiro (16):
>   include: pe.h: add signature-related definitions
>   efi_loader: add CONFIG

Re: [U-Boot] [PATCH v2] cmd: efidebug: fix a build error in show_efi_boot_opt()

2019-11-25 Thread Heinrich Schuchardt

On 11/26/19 2:11 AM, AKASHI Takahiro wrote:

I detected the following error in sandbox with Clang on Travis CI:
 +cmd/efidebug.c:703:15: error: result of comparison of constant
  9223372036854775822 with expression of type 'int' is always false
  [-Werror,-Wtautological-constant-out-of-range-compare]
 +else if (ret == EFI_NOT_FOUND)
 + ~~~ ^  ~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro 


Reviewed-by: Heinrich Schuchardt 


---
  cmd/efidebug.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index ef97e19d0735..1fff4390deae 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -684,7 +684,7 @@ static void show_efi_boot_opt(int id)
efi_guid_t guid;
void *data = NULL;
efi_uintn_t size;
-   int ret;
+   efi_status_t ret;

sprintf(var_name, "Boot%04X", id);
p = var_name16;
@@ -693,7 +693,7 @@ static void show_efi_boot_opt(int id)

size = 0;
ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL));
-   if (ret == (int)EFI_BUFFER_TOO_SMALL) {
+   if (ret == EFI_BUFFER_TOO_SMALL) {
data = malloc(size);
ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
data));



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


[U-Boot] [PATCH v2] cmd: efidebug: fix a build error in show_efi_boot_opt()

2019-11-25 Thread AKASHI Takahiro
I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
 9223372036854775822 with expression of type 'int' is always false
 [-Werror,-Wtautological-constant-out-of-range-compare]
+else if (ret == EFI_NOT_FOUND)
+ ~~~ ^  ~

Simply changing a type of 'ret' to efi_status_t will fix this error.

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

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index ef97e19d0735..1fff4390deae 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -684,7 +684,7 @@ static void show_efi_boot_opt(int id)
efi_guid_t guid;
void *data = NULL;
efi_uintn_t size;
-   int ret;
+   efi_status_t ret;
 
sprintf(var_name, "Boot%04X", id);
p = var_name16;
@@ -693,7 +693,7 @@ static void show_efi_boot_opt(int id)
 
size = 0;
ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL));
-   if (ret == (int)EFI_BUFFER_TOO_SMALL) {
+   if (ret == EFI_BUFFER_TOO_SMALL) {
data = malloc(size);
ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
data));
-- 
2.24.0

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


Re: [U-Boot] [PATCH] cmd: efidebug: fix a build error in show_efi_boot_opt()

2019-11-25 Thread AKASHI Takahiro
On Tue, Nov 26, 2019 at 02:01:53AM +0100, Heinrich Schuchardt wrote:
> On 11/26/19 1:57 AM, AKASHI Takahiro wrote:
> >I detected the following error in sandbox with Clang on Travis CI:
> > +cmd/efidebug.c:703:15: error: result of comparison of constant
> >  9223372036854775822 with expression of type 'int' is always false
> >  [-Werror,-Wtautological-constant-out-of-range-compare]
> > +else if (ret == EFI_NOT_FOUND)
> > + ~~~ ^  ~
> >
> >Simply changing a type of 'ret' to efi_status_t will fix this error.
> >
> >Signed-off-by: AKASHI Takahiro 
> >---
> >  cmd/efidebug.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> >index ef97e19d0735..09ac84e5ef0a 100644
> >--- a/cmd/efidebug.c
> >+++ b/cmd/efidebug.c
> >@@ -684,7 +684,7 @@ static void show_efi_boot_opt(int id)
> > efi_guid_t guid;
> > void *data = NULL;
> > efi_uintn_t size;
> >-int ret;
> >+efi_status_t ret;
> >
> > sprintf(var_name, "Boot%04X", id);
> > p = var_name16;
> >
> 
> Thanks for reporting this issue.
> 
> Please, adjust this line too:
> 
> if (ret == (int)EFI_BUFFER_TOO_SMALL) {

Sure.
-Takahiro Akashi

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


[U-Boot] [PATCH 2/2] pinctrl: rockchip: Add pinctrl support for rk3308

2019-11-25 Thread David Wu
The most pins of rk3308 are 2bits iomux, but the banks's register
width is 0x8.

Signed-off-by: David Wu 
---
 drivers/pinctrl/rockchip/Makefile |   1 +
 drivers/pinctrl/rockchip/pinctrl-rk3308.c | 464 ++
 .../pinctrl/rockchip/pinctrl-rockchip-core.c  |   3 +-
 drivers/pinctrl/rockchip/pinctrl-rockchip.h   |   1 +
 4 files changed, 468 insertions(+), 1 deletion(-)
 create mode 100644 drivers/pinctrl/rockchip/pinctrl-rk3308.c

diff --git a/drivers/pinctrl/rockchip/Makefile 
b/drivers/pinctrl/rockchip/Makefile
index 83913f668f..fcf19f877a 100644
--- a/drivers/pinctrl/rockchip/Makefile
+++ b/drivers/pinctrl/rockchip/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_ROCKCHIP_RK3128) += pinctrl-rk3128.o
 obj-$(CONFIG_ROCKCHIP_RK3188) += pinctrl-rk3188.o
 obj-$(CONFIG_ROCKCHIP_RK322X) += pinctrl-rk322x.o
 obj-$(CONFIG_ROCKCHIP_RK3288) += pinctrl-rk3288.o
+obj-$(CONFIG_ROCKCHIP_RK3308) += pinctrl-rk3308.o
 obj-$(CONFIG_ROCKCHIP_RK3328) += pinctrl-rk3328.o
 obj-$(CONFIG_ROCKCHIP_RK3368) += pinctrl-rk3368.o
 obj-$(CONFIG_ROCKCHIP_RK3399) += pinctrl-rk3399.o
diff --git a/drivers/pinctrl/rockchip/pinctrl-rk3308.c 
b/drivers/pinctrl/rockchip/pinctrl-rk3308.c
new file mode 100644
index 00..abd57e54a5
--- /dev/null
+++ b/drivers/pinctrl/rockchip/pinctrl-rk3308.c
@@ -0,0 +1,464 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2019 Rockchip Electronics Co., Ltd
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "pinctrl-rockchip.h"
+
+static struct rockchip_mux_recalced_data rk3308_mux_recalced_data[] = {
+   {
+   .num = 1,
+   .pin = 14,
+   .reg = 0x28,
+   .bit = 12,
+   .mask = 0xf
+   }, {
+   .num = 1,
+   .pin = 15,
+   .reg = 0x2c,
+   .bit = 0,
+   .mask = 0x3
+   }, {
+   .num = 1,
+   .pin = 18,
+   .reg = 0x30,
+   .bit = 4,
+   .mask = 0xf
+   }, {
+   .num = 1,
+   .pin = 19,
+   .reg = 0x30,
+   .bit = 8,
+   .mask = 0xf
+   }, {
+   .num = 1,
+   .pin = 20,
+   .reg = 0x30,
+   .bit = 12,
+   .mask = 0xf
+   }, {
+   .num = 1,
+   .pin = 21,
+   .reg = 0x34,
+   .bit = 0,
+   .mask = 0xf
+   }, {
+   .num = 1,
+   .pin = 22,
+   .reg = 0x34,
+   .bit = 4,
+   .mask = 0xf
+   }, {
+   .num = 1,
+   .pin = 23,
+   .reg = 0x34,
+   .bit = 8,
+   .mask = 0xf
+   }, {
+   .num = 3,
+   .pin = 12,
+   .reg = 0x68,
+   .bit = 8,
+   .mask = 0xf
+   }, {
+   .num = 3,
+   .pin = 13,
+   .reg = 0x68,
+   .bit = 12,
+   .mask = 0xf
+   }, {
+   .num = 2,
+   .pin = 2,
+   .reg = 0x608,
+   .bit = 0,
+   .mask = 0x7
+   }, {
+   .num = 2,
+   .pin = 3,
+   .reg = 0x608,
+   .bit = 4,
+   .mask = 0x7
+   }, {
+   .num = 2,
+   .pin = 16,
+   .reg = 0x610,
+   .bit = 8,
+   .mask = 0x7
+   }, {
+   .num = 3,
+   .pin = 10,
+   .reg = 0x610,
+   .bit = 0,
+   .mask = 0x7
+   }, {
+   .num = 3,
+   .pin = 11,
+   .reg = 0x610,
+   .bit = 4,
+   .mask = 0x7
+   },
+};
+
+static struct rockchip_mux_route_data rk3308_mux_route_data[] = {
+   {
+   /* rtc_clk */
+   .bank_num = 0,
+   .pin = 19,
+   .func = 1,
+   .route_offset = 0x314,
+   .route_val = BIT(16 + 0) | BIT(0),
+   }, {
+   /* uart2_rxm0 */
+   .bank_num = 1,
+   .pin = 22,
+   .func = 2,
+   .route_offset = 0x314,
+   .route_val = BIT(16 + 2) | BIT(16 + 3),
+   }, {
+   /* uart2_rxm1 */
+   .bank_num = 4,
+   .pin = 26,
+   .func = 2,
+   .route_offset = 0x314,
+   .route_val = BIT(16 + 2) | BIT(16 + 3) | BIT(2),
+   }, {
+   /* i2c3_sdam0 */
+   .bank_num = 0,
+   .pin = 15,
+   .func = 2,
+   .route_offset = 0x608,
+   .route_val = BIT(16 + 8) | BIT(16 + 9),
+   }, {
+   /* i2c3_sdam1 */
+   .bank_num = 3,
+   .pin = 12,
+   .func = 2,
+   .route_offset = 0x608,
+   .route_va

[U-Boot] [PATCH 1/2] arm: rockchip: rk3308: Initialize the iomux configuration

2019-11-25 Thread David Wu
When we want to use plus iomux feature, we need to enable
them at spl.

Signed-off-by: David Wu 
---
 arch/arm/mach-rockchip/rk3308/rk3308.c | 33 ++
 1 file changed, 33 insertions(+)

diff --git a/arch/arm/mach-rockchip/rk3308/rk3308.c 
b/arch/arm/mach-rockchip/rk3308/rk3308.c
index f27f9e8c0b..bd99899094 100644
--- a/arch/arm/mach-rockchip/rk3308/rk3308.c
+++ b/arch/arm/mach-rockchip/rk3308/rk3308.c
@@ -72,6 +72,11 @@ enum {
UART2_IO_SEL_M1,
UART2_IO_SEL_USB,
 
+   GPIO2C0_SEL_SRC_CTRL_SHIFT  = 11,
+   GPIO2C0_SEL_SRC_CTRL_MASK   = BIT(11),
+   GPIO2C0_SEL_SRC_CTRL_IOMUX  = 0,
+   GPIO2C0_SEL_SRC_CTRL_SEL_PLUS,
+
GPIO3B3_SEL_SRC_CTRL_SHIFT  = 7,
GPIO3B3_SEL_SRC_CTRL_MASK   = BIT(7),
GPIO3B3_SEL_SRC_CTRL_IOMUX  = 0,
@@ -97,6 +102,18 @@ enum {
GPIO3B2_SEL_PLUS_EMMC_RSTN,
GPIO3B2_SEL_PLUS_SPI1_MISO,
GPIO3B2_SEL_PLUS_LCDC_D22_M1,
+
+   I2C3_IOFUNC_SRC_CTRL_SHIFT  = 10,
+   I2C3_IOFUNC_SRC_CTRL_MASK   = BIT(10),
+   I2C3_IOFUNC_SRC_CTRL_SEL_PLUS   = 1,
+
+   GPIO2A3_SEL_SRC_CTRL_SHIFT  = 7,
+   GPIO2A3_SEL_SRC_CTRL_MASK   = BIT(7),
+   GPIO2A3_SEL_SRC_CTRL_SEL_PLUS   = 1,
+
+   GPIO2A2_SEL_SRC_CTRL_SHIFT  = 3,
+   GPIO2A2_SEL_SRC_CTRL_MASK   = BIT(3),
+   GPIO2A2_SEL_SRC_CTRL_SEL_PLUS   = 1,
 };
 
 enum {
@@ -166,10 +183,26 @@ __weak void board_debug_uart_init(void)
 int arch_cpu_init(void)
 {
static struct rk3308_sgrf * const sgrf = (void *)SGRF_BASE;
+   static struct rk3308_grf * const grf = (void *)GRF_BASE;
 
/* Set CRYPTO SDMMC EMMC NAND SFC USB master bus to be secure access */
rk_clrreg(&sgrf->con_secure0, 0x2b83);
 
+
+   rk_clrsetreg(&grf->soc_con13,
+I2C3_IOFUNC_SRC_CTRL_MASK | GPIO2A3_SEL_SRC_CTRL_MASK |
+GPIO2A2_SEL_SRC_CTRL_MASK,
+I2C3_IOFUNC_SRC_CTRL_SEL_PLUS << 
I2C3_IOFUNC_SRC_CTRL_SHIFT |
+GPIO2A3_SEL_SRC_CTRL_SEL_PLUS << 
GPIO2A3_SEL_SRC_CTRL_SHIFT |
+GPIO2A2_SEL_SRC_CTRL_SEL_PLUS << 
GPIO2A2_SEL_SRC_CTRL_SHIFT);
+
+   rk_clrsetreg(&grf->soc_con15,
+GPIO2C0_SEL_SRC_CTRL_MASK | GPIO3B3_SEL_SRC_CTRL_MASK |
+GPIO3B2_SEL_SRC_CTRL_MASK,
+GPIO2C0_SEL_SRC_CTRL_SEL_PLUS << 
GPIO2C0_SEL_SRC_CTRL_SHIFT |
+GPIO3B3_SEL_SRC_CTRL_SEL_PLUS << 
GPIO3B3_SEL_SRC_CTRL_SHIFT |
+GPIO3B3_SEL_SRC_CTRL_SEL_PLUS << 
GPIO3B2_SEL_SRC_CTRL_SHIFT);
+
return 0;
 }
 #endif
-- 
2.19.1



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


[U-Boot] Raspberry Pi Compute Module 1 mini-UART

2019-11-25 Thread edrose
Hi,

I'm working on a project that uses the Raspberry Pi Compute Module 1. Much
like the CM 3, the CM 1 has two UART interfaces - the main UART at ttyAMA0,
and a second "mini-UART" at ttyS0. The project uses the main UART since it
works better at high speeds, so the console has been bumped over to the
mini-UART. This works fine for kernel messages and as a TTY console for
logging in and interacting with the device, however I've been unable to get
u-boot to present it's console over the mini-UART.

I've worked deep enough into this to know that u-boot doesn't use the device
tree that is set-up in config.txt, so the parameters that I've put in there
to activate and remap the mini-UART (UART1 in dts files) to pins 40/41
doesn't apply to u-boot. I'm using the bcm2835-rpi-b dts file currently
since it's the best fit for the hardware, but it leaves the mini-UART port
disabled. I've tried playing around with the dts files to enable/remap the
mini-UART port however I've been unsuccessful.

Can anyone give me any pointers as to how I modify the dts files to enable
and map the second UART for u-boot to be able to use it?

Kindest regards,
Ed



--
Sent from: http://u-boot.10912.n7.nabble.com/
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] cmd: efidebug: fix a build error in show_efi_boot_opt()

2019-11-25 Thread Heinrich Schuchardt

On 11/26/19 1:57 AM, AKASHI Takahiro wrote:

I detected the following error in sandbox with Clang on Travis CI:
 +cmd/efidebug.c:703:15: error: result of comparison of constant
  9223372036854775822 with expression of type 'int' is always false
  [-Werror,-Wtautological-constant-out-of-range-compare]
 +else if (ret == EFI_NOT_FOUND)
 + ~~~ ^  ~

Simply changing a type of 'ret' to efi_status_t will fix this error.

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

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index ef97e19d0735..09ac84e5ef0a 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -684,7 +684,7 @@ static void show_efi_boot_opt(int id)
efi_guid_t guid;
void *data = NULL;
efi_uintn_t size;
-   int ret;
+   efi_status_t ret;

sprintf(var_name, "Boot%04X", id);
p = var_name16;



Thanks for reporting this issue.

Please, adjust this line too:

if (ret == (int)EFI_BUFFER_TOO_SMALL) {

Best regards

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


Re: [U-Boot] [PATCH v3] arm: add acpi support for the arm

2019-11-25 Thread Heinrich Schuchardt

On 11/26/19 12:40 AM, Simon Glass wrote:

Hi,

On Mon, 25 Nov 2019 at 15:57, Heinrich Schuchardt  wrote:


On 11/25/19 3:42 AM, Steven Hao wrote:> 获取 Outlook for iOS



*发件人:* Bin Meng 
*发送时间:* Monday, November 25, 2019 10:13:40 AM
*收件人:* Steven Hao 
*抄送:* xypron.g...@gmx.de ; liu...@phytium.com.cn
; ag...@csgraf.de ;
ja...@amarulasolutions.com ;
marek.va...@gmail.com ; s...@denx.de ;
patrice.chot...@st.com ; a...@ti.com
; horatiu.vul...@microchip.com
; narmstr...@baylibre.com
; ryder@mediatek.com
; igor.opan...@gmail.com
; patrick.delau...@st.com
; eugen.hris...@microchip.com
; s...@chromium.org ;
judge.pack...@gmail.com ;
yamada.masah...@socionext.com ;
swar...@nvidia.com ; michal.si...@xilinx.com
; u-boot@lists.denx.de ;
Andy Shevchenko 
*主题:* Re: [PATCH v3] arm: add acpi support for the arm
Hi Steven,

On Mon, Nov 25, 2019 at 10:09 AM Steven Hao 
wrote:


Dear Bin:

Firstly:
I know that acpi about x86 is existing. And it is usefull for x86

platfporm. If it  is used to arm platform,some modification may have to
do. For example,facs table is useless for arm.


In adition,The acpi table is writed statically and then modified

dynamically in my patch. It is a new method.


I want to consult that whether my method is helpful or not.

Secondly:
If i want to reuse the x86-acpi. I will overwrite the

write_acpi_tables function. But the definition about acpi strcuture is
placed in arch/x86/include/asm directory. It can not be used to arm
plateform. If the acpi library need to surport for all platform,i  think
it should move to /include directory.




Yes, we all are aware that modifications are needed to the existing
x86 ACPI support to support ARM. We don't want to create 2 ACP
implementation in U-Boot.

Regards,
Bin> Dear Bin:

I have a suggetion that the acpi specification definition such as all
acpi table structure definition  should be place in /include directory.
and write_acpi_tables function can be placed in platform directory.
   Creating acpi table mothod  can be diffrent between x86 and arm.

Thank you
Steven Hao



Currently we are using CPU specific C files generating ACPI tables, e.g.
arch/x86/cpu/tangier/acpi.c.

I would prefer if we would generate the ACPI tables and definition
blocks completely from text files instead of using C code. This would
avoid any architecture specific code.


I am finding with Apollo Lake that this isn't possible - we need to
insert run-time information into the tables set up with .asl files.


For device trees we generate the binary form with a compiler. Then we
patch the device tree with runtime information in image_setup_libfdt().

Couldn't we go a similar way for ACPI?

Best regards

Heinrich





Such table generation is already in use in the Windows world. See:
https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/generate-acpi-tables-by-using-acpigenfx


That looks like a programmatic way to create ACPI tables. If so, I'm
trying to bring something similar over from coreboot.

Regards,
Simon



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


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

2019-11-25 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

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


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

2019-11-25 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/ -k

[U-Boot] [PATCH] cmd: efidebug: fix a build error in show_efi_boot_opt()

2019-11-25 Thread AKASHI Takahiro
I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
 9223372036854775822 with expression of type 'int' is always false
 [-Werror,-Wtautological-constant-out-of-range-compare]
+else if (ret == EFI_NOT_FOUND)
+ ~~~ ^  ~

Simply changing a type of 'ret' to efi_status_t will fix this error.

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

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index ef97e19d0735..09ac84e5ef0a 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -684,7 +684,7 @@ static void show_efi_boot_opt(int id)
efi_guid_t guid;
void *data = NULL;
efi_uintn_t size;
-   int ret;
+   efi_status_t ret;
 
sprintf(var_name, "Boot%04X", id);
p = var_name16;
-- 
2.24.0

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


[U-Boot] [PATCH v2 15/16] sandbox: add extra configurations for UEFI and related tests

2019-11-25 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

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


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

2019-11-25 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 outp

[U-Boot] [PATCH v2 16/16] travis: add packages for UEFI secure boot test

2019-11-25 Thread AKASHI Takahiro
Pytest for UEFI secure boot will use several host commands.
In paricular, 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

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


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

2019-11-25 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'])
+  

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

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

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

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

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

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

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

2019-11-25 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",
+   &efi_global_variable_guid,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS
+| EFI_VARIABLE_RUNTIME_ACCESS,
+   sizeof(signature_types),
+   &signature_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

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


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

2019-11-25 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 | 443 +-
 3 files changed, 438 insertions(+), 14 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 15c77494ef54..27da5cd2f050 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, &dp, &fp);
ret = efi_setup_loaded_image(dp, fp, image_obj, &info);
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..9c1a5f2808a5 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -9,7 +9,9 @@
 
 #include 
 #include 
+#include 
 #include 
+#include "../lib/crypto/pkcs7_parser.h"
 
 const efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
 const efi_guid_t efi_guid_device_path = EFI_DEVICE_PATH_PROTOCOL_GUID;
@@ -205,6 +207,356 @@ static void efi_set_code_and_data_type(
}
 }
 
+#ifdef CONFIG_EFI_SECURE_BOOT
+/**
+ * efi_image_parse - parse a PE image
+ * @efi:   Pointer to image
+ * @len:   Size of @efi
+ * @regs:  Pointer to a list of regions
+ * @auth:  Pointer to a pointer to authentication data in PE
+ * @auth_len:  Size of @auth
+ *
+ * Parse image binary in PE32(+) format, assuming that sanity of PE image
+ * has been checked by a caller.
+ * On success, an address of authentication data in @efi and its size will
+ * be returned in @auth and @auth_len, respectively.
+ *
+ * Return: true on success, false on error
+ */
+bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
+WIN_CERTIFICATE **auth, size_t *auth_len)
+{
+   struct efi_image_regions *regs;
+   IMAGE_DOS_HEADER *dos;
+   IMAGE_NT_HEADERS32 *nt;
+   IMAGE_SECTION_HEADER *sections, **sorted;
+   int num_sections, i, j;
+   int ctidx = IMAGE_DIRECTORY_ENTRY_SECURITY;
+   u32 align, size, authsz, authoff;
+   size_t bytes_hashed;
+
+   regs = calloc(1, sizeof(*regs));
+   if (!regs)
+   goto err;
+
+   dos = (void *)efi;
+   nt = (void *)(efi + dos->e_lfanew);
+
+   /*
+* Collect data regions for hash calculation
+* 1. File headers
+*/
+   if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
+   IMAGE_NT_HEADERS64 *nt64 = (void *)nt;
+   IMAGE_OPTIONAL_HEADER64 *opt = &nt64->OptionalHeader;
+
+  

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

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

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

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

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


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

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

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

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

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

2019-11-25 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..622bae6a6906 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 efi_gu

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

2019-11-25 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

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


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

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

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

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

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

2019-11-25 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 
---
 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

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


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

2019-11-25 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 | 16 
 1 file changed, 16 insertions(+)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index c7027a967653..fc4199838c98 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -115,4 +115,20 @@ 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
+   imply SHA256
+depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE
+imply RSA_VERIFY_WITH_PKEY
+imply X509_CERTIFICATE_PARSER
+imply PCKS7_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

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


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

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

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

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

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


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

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

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

Test:
* my pytest, included in this patch set, passed.
* efi_selftest passed. (At least no reguression.)
* Travis CI tests, except the following two, have passed:
  - test/py sandbox
test/py/tests/test_fs/test_unlink.py test_unlink2
  - test/py sandbox with clang
cmd/efidebug.c:703:15: error: result of comparison of constant 
9223372036854775822 with expression of type 'int' is always false 
[-Werror,-Wtautological-constant-out-of-range-compare]
  But as you can see, those have nothing to do with my UEFI secure boot
  patch and are existing bugs.

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].)
* Travis CI errors mentioned above
=> I will send *separate* bug-fix patches once fixed.


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


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


Changes in 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

Re: [U-Boot] imx8mq-evk boot regression

2019-11-25 Thread Fabio Estevam
Hi Patrick,

On Mon, Nov 25, 2019 at 8:49 PM Patrick Wildt  wrote:
>
> Hi,
>
> maybe I can find some time tomorrow to have a look at it.  One thing
> you can try is https://patchwork.ozlabs.org/patch/1197351/ .  On my
> employer's product this fixes a regression introduced by commit id
> 9e094455495081979cd20ac730a42508717e37b5.  But I think that should have
> hit you somewhere before the print that you are seeing, so I guess that
> is not it.

Thanks for the suggestion. I tested the patch, but it did not help.

Maybe Peng has any suggestions?

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


Re: [U-Boot] imx8mq-evk boot regression

2019-11-25 Thread Patrick Wildt
Hi,

maybe I can find some time tomorrow to have a look at it.  One thing
you can try is https://patchwork.ozlabs.org/patch/1197351/ .  On my
employer's product this fixes a regression introduced by commit id
9e094455495081979cd20ac730a42508717e37b5.  But I think that should have
hit you somewhere before the print that you are seeing, so I guess that
is not it.

Thanks,
Patrick

On Mon, Nov 25, 2019 at 04:03:55PM -0300, Fabio Estevam wrote:
> Adding Patrick in case he has some suggestions.
> 
> Thanks
> 
> On Mon, Nov 25, 2019 at 1:18 PM Fabio Estevam  wrote:
> >
> > Hi,
> >
> > Just tried to boot imx8mq-evk using latest U-Boot master and this is what I 
> > get:
> >
> > U-Boot SPL 2020.01-rc3-00070-g9a0cbae22a (Nov 25 2019 - 13:08:24 -0300)
> > PMIC:  PFUZE100 ID=0x10
> > DDRINFO: start DRAM init
> > DDRINFO:ddrphy calibration done
> > DDRINFO: ddrmix config done
> > Normal Boot
> > Trying to boot from MMC2
> >
> > (It hangs here)
> >
> > I haven't tried to debug this yet, but just wanted to let you know in
> > case this is a known issue.
> >
> > Any ideas?
> >
> > Thanks,
> >
> > Fabio Estevam
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3] arm: add acpi support for the arm

2019-11-25 Thread Simon Glass
Hi,

On Mon, 25 Nov 2019 at 15:57, Heinrich Schuchardt  wrote:
>
> On 11/25/19 3:42 AM, Steven Hao wrote:> 获取 Outlook for iOS
> 
> > 
> > *发件人:* Bin Meng 
> > *发送时间:* Monday, November 25, 2019 10:13:40 AM
> > *收件人:* Steven Hao 
> > *抄送:* xypron.g...@gmx.de ; liu...@phytium.com.cn
> > ; ag...@csgraf.de ;
> > ja...@amarulasolutions.com ;
> > marek.va...@gmail.com ; s...@denx.de ;
> > patrice.chot...@st.com ; a...@ti.com
> > ; horatiu.vul...@microchip.com
> > ; narmstr...@baylibre.com
> > ; ryder@mediatek.com
> > ; igor.opan...@gmail.com
> > ; patrick.delau...@st.com
> > ; eugen.hris...@microchip.com
> > ; s...@chromium.org ;
> > judge.pack...@gmail.com ;
> > yamada.masah...@socionext.com ;
> > swar...@nvidia.com ; michal.si...@xilinx.com
> > ; u-boot@lists.denx.de ;
> > Andy Shevchenko 
> > *主题:* Re: [PATCH v3] arm: add acpi support for the arm
> > Hi Steven,
> >
> > On Mon, Nov 25, 2019 at 10:09 AM Steven Hao 
> > wrote:
> >>
> >> Dear Bin:
> >>
> >> Firstly:
> >> I know that acpi about x86 is existing. And it is usefull for x86
> platfporm. If it  is used to arm platform,some modification may have to
> do. For example,facs table is useless for arm.
> >>
> >> In adition,The acpi table is writed statically and then modified
> dynamically in my patch. It is a new method.
> >>
> >> I want to consult that whether my method is helpful or not.
> >>
> >> Secondly:
> >> If i want to reuse the x86-acpi. I will overwrite the
> write_acpi_tables function. But the definition about acpi strcuture is
> placed in arch/x86/include/asm directory. It can not be used to arm
> plateform. If the acpi library need to surport for all platform,i  think
> it should move to /include directory.
> >>
> >
> > Yes, we all are aware that modifications are needed to the existing
> > x86 ACPI support to support ARM. We don't want to create 2 ACP
> > implementation in U-Boot.
> >
> > Regards,
> > Bin> Dear Bin:
> >
> > I have a suggetion that the acpi specification definition such as all
> > acpi table structure definition  should be place in /include directory.
> > and write_acpi_tables function can be placed in platform directory.
> >   Creating acpi table mothod  can be diffrent between x86 and arm.
> >
> > Thank you
> > Steven Hao
> >
>
> Currently we are using CPU specific C files generating ACPI tables, e.g.
> arch/x86/cpu/tangier/acpi.c.
>
> I would prefer if we would generate the ACPI tables and definition
> blocks completely from text files instead of using C code. This would
> avoid any architecture specific code.

I am finding with Apollo Lake that this isn't possible - we need to
insert run-time information into the tables set up with .asl files.

>
> Such table generation is already in use in the Windows world. See:
> https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/generate-acpi-tables-by-using-acpigenfx

That looks like a programmatic way to create ACPI tables. If so, I'm
trying to bring something similar over from coreboot.

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


[U-Boot] [RFC] Eliminate boards not using CONFIG_DM=y

2019-11-25 Thread Heinrich Schuchardt

Dear maintainers,

we have been trying to move to the driver model for several years now.
Starting in 2018 we have added warnings to the Makefile that boards not
supporting the driver model will be eliminated. Still 24 % of the
configuration files have not been converted and do not even use CONFIG_DM=y.

If we want to get rid of legacy drivers, at some point we have to remove
the 347 configuration files in the list below not using the driver model.

I suggest to do this directly after the release of v2020.01 scheduled
January 6th.

This should not stop the maintainers from reinserting the boards after
conversion to the driver model.

Best regards

Heinrich

am3517_crane_defconfig
apf27_defconfig
apx4devkit_defconfig
aristainetos2b_defconfig
aristainetos2_defconfig
aristainetos_defconfig
aspenite_defconfig
at91rm9200ek_defconfig
at91rm9200ek_ram_defconfig
B4420QDS_defconfig
B4420QDS_NAND_defconfig
B4420QDS_SPIFLASH_defconfig
B4860QDS_defconfig
B4860QDS_NAND_defconfig
B4860QDS_SPIFLASH_defconfig
B4860QDS_SRIO_PCIE_BOOT_defconfig
bcm11130_defconfig
bcm11130_nand_defconfig
bcm23550_w1d_defconfig
bcm28155_ap_defconfig
bcm28155_w1d_defconfig
bcm911360_entphn_defconfig
bcm911360_entphn-ns_defconfig
bcm911360k_defconfig
bcm958300k_defconfig
bcm958300k-ns_defconfig
bcm958305k_defconfig
bcm958622hr_defconfig
bcm958712k_defconfig
bg0900_defconfig
BSC9131RDB_NAND_defconfig
BSC9131RDB_NAND_SYSCLK100_defconfig
BSC9131RDB_SPIFLASH_defconfig
BSC9131RDB_SPIFLASH_SYSCLK100_defconfig
BSC9132QDS_NAND_DDRCLK100_defconfig
BSC9132QDS_NAND_DDRCLK133_defconfig
BSC9132QDS_NOR_DDRCLK100_defconfig
BSC9132QDS_NOR_DDRCLK133_defconfig
BSC9132QDS_SDCARD_DDRCLK100_defconfig
BSC9132QDS_SDCARD_DDRCLK133_defconfig
BSC9132QDS_SPIFLASH_DDRCLK100_defconfig
BSC9132QDS_SPIFLASH_DDRCLK133_defconfig
C29XPCIE_defconfig
C29XPCIE_NAND_defconfig
C29XPCIE_SPIFLASH_defconfig
caddy2_defconfig
cm_t35_defconfig
cm_t54_defconfig
Cyrus_P5020_defconfig
Cyrus_P5040_defconfig
d2net_v2_defconfig
dms-ba16-1g_defconfig
dms-ba16_defconfig
dockstar_defconfig
duovero_defconfig
edb9315a_defconfig
edminiv2_defconfig
flea3_defconfig
gplugd_defconfig
highbank_defconfig
hrcon_defconfig
hrcon_dh_defconfig
ib62x0_defconfig
iconnect_defconfig
inetspace_v2_defconfig
kc1_defconfig
kmcoge4_defconfig
kmcoge5ne_defconfig
kmeter1_defconfig
kmopti2_defconfig
kmsupx5_defconfig
kmtegr1_defconfig
kmtepr2_defconfig
ls2080a_emu_defconfig
ls2080a_simu_defconfig
MigoR_defconfig
mpc8308_p1m_defconfig
MPC8308RDB_defconfig
MPC8313ERDB_33_defconfig
MPC8313ERDB_66_defconfig
MPC8313ERDB_NAND_33_defconfig
MPC8313ERDB_NAND_66_defconfig
MPC8315ERDB_defconfig
MPC8323ERDB_defconfig
MPC832XEMDS_ATM_defconfig
MPC832XEMDS_defconfig
MPC832XEMDS_HOST_33_defconfig
MPC832XEMDS_HOST_66_defconfig
MPC832XEMDS_SLAVE_defconfig
MPC8349EMDS_defconfig
MPC8349EMDS_PCI64_defconfig
MPC8349EMDS_SDRAM_defconfig
MPC8349EMDS_SLAVE_defconfig
MPC8349ITX_defconfig
MPC8349ITXGP_defconfig
MPC8349ITX_LOWBOOT_defconfig
MPC837XEMDS_defconfig
MPC837XEMDS_HOST_defconfig
MPC837XEMDS_SLAVE_defconfig
MPC837XERDB_defconfig
MPC837XERDB_SLAVE_defconfig
MPC8536DS_36BIT_defconfig
MPC8536DS_defconfig
MPC8536DS_SDCARD_defconfig
MPC8536DS_SPIFLASH_defconfig
MPC8541CDS_defconfig
MPC8541CDS_legacy_defconfig
MPC8544DS_defconfig
MPC8555CDS_defconfig
MPC8555CDS_legacy_defconfig
MPC8568MDS_defconfig
MPC8569MDS_ATM_defconfig
MPC8569MDS_defconfig
MPC8572DS_36BIT_defconfig
MPC8572DS_defconfig
MPC8610HPCD_defconfig
MPC8641HPCN_36BIT_defconfig
MPC8641HPCN_defconfig
mx23evk_defconfig
mx23_olinuxino_defconfig
mx25pdk_defconfig
mx28evk_auart_console_defconfig
mx28evk_defconfig
mx28evk_nand_defconfig
mx28evk_spi_defconfig
mx31pdk_defconfig
mx35pdk_defconfig
mx51evk_defconfig
mx53ard_defconfig
mx53evk_defconfig
mx53loco_defconfig
mx53smd_defconfig
mx6dlarm2_defconfig
mx6dlarm2_lpddr2_defconfig
mx6memcal_defconfig
mx6qarm2_defconfig
mx6qarm2_lpddr2_defconfig
net2big_v2_defconfig
netspace_lite_v2_defconfig
netspace_max_v2_defconfig
netspace_mini_v2_defconfig
netspace_v2_defconfig
nokia_rx51_defconfig
nsa310s_defconfig
omap3_ha_defconfig
omap4_panda_defconfig
omap4_sdp4430_defconfig
omap5_uevm_defconfig
openrd_base_defconfig
openrd_client_defconfig
openrd_ultimate_defconfig
P1010RDB-PA_36BIT_NAND_defconfig
P1010RDB-PA_36BIT_NOR_defconfig
P1010RDB-PA_36BIT_SDCARD_defconfig
P1010RDB-PA_36BIT_SPIFLASH_defconfig
P1010RDB-PA_NAND_defconfig
P1010RDB-PA_NOR_defconfig
P1010RDB-PA_SDCARD_defconfig
P1010RDB-PA_SPIFLASH_defconfig
P1010RDB-PB_36BIT_NAND_defconfig
P1010RDB-PB_36BIT_NOR_defconfig
P1010RDB-PB_36BIT_SDCARD_defconfig
P1010RDB-PB_36BIT_SPIFLASH_defconfig
P1010RDB-PB_NAND_defconfig
P1010RDB-PB_NOR_defconfig
P1010RDB-PB_SDCARD_defconfig
P1010RDB-PB_SPIFLASH_defconfig
P1020MBG-PC_36BIT_defconfig
P1020MBG-PC_36BIT_SDCARD_defconfig
P1020MBG-PC_defconfig
P1020MBG-PC_SDCARD_defconfig
P1020UTM-PC_36BIT_defconfig
P1020UTM-PC_36BIT_SDCARD_defconfig
P1020UTM-PC_defconfig
P1020UTM-PC_SDCARD_defconfig
P1021RDB-PC_36BIT_defconfig
P1021RDB-PC_36BIT_NAND_defconfig
P1021RDB-PC_

Re: [U-Boot] [PATCH v3] arm: add acpi support for the arm

2019-11-25 Thread Heinrich Schuchardt

On 11/25/19 3:42 AM, Steven Hao wrote:> 获取 Outlook for iOS



*发件人:* Bin Meng 
*发送时间:* Monday, November 25, 2019 10:13:40 AM
*收件人:* Steven Hao 
*抄送:* xypron.g...@gmx.de ; liu...@phytium.com.cn
; ag...@csgraf.de ;
ja...@amarulasolutions.com ;
marek.va...@gmail.com ; s...@denx.de ;
patrice.chot...@st.com ; a...@ti.com
; horatiu.vul...@microchip.com
; narmstr...@baylibre.com
; ryder@mediatek.com
; igor.opan...@gmail.com
; patrick.delau...@st.com
; eugen.hris...@microchip.com
; s...@chromium.org ;
judge.pack...@gmail.com ;
yamada.masah...@socionext.com ;
swar...@nvidia.com ; michal.si...@xilinx.com
; u-boot@lists.denx.de ;
Andy Shevchenko 
*主题:* Re: [PATCH v3] arm: add acpi support for the arm
Hi Steven,

On Mon, Nov 25, 2019 at 10:09 AM Steven Hao 
wrote:


Dear Bin:

Firstly:
I know that acpi about x86 is existing. And it is usefull for x86

platfporm. If it  is used to arm platform,some modification may have to
do. For example,facs table is useless for arm.


In adition,The acpi table is writed statically and then modified

dynamically in my patch. It is a new method.


I want to consult that whether my method is helpful or not.

Secondly:
If i want to reuse the x86-acpi. I will overwrite the

write_acpi_tables function. But the definition about acpi strcuture is
placed in arch/x86/include/asm directory. It can not be used to arm
plateform. If the acpi library need to surport for all platform,i  think
it should move to /include directory.




Yes, we all are aware that modifications are needed to the existing
x86 ACPI support to support ARM. We don't want to create 2 ACP
implementation in U-Boot.

Regards,
Bin> Dear Bin:

I have a suggetion that the acpi specification definition such as all
acpi table structure definition  should be place in /include directory.
and write_acpi_tables function can be placed in platform directory.
  Creating acpi table mothod  can be diffrent between x86 and arm.

Thank you
Steven Hao



Currently we are using CPU specific C files generating ACPI tables, e.g.
arch/x86/cpu/tangier/acpi.c.

I would prefer if we would generate the ACPI tables and definition
blocks completely from text files instead of using C code. This would
avoid any architecture specific code.

Such table generation is already in use in the Windows world. See:
https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/generate-acpi-tables-by-using-acpigenfx

Best regards

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


Re: [U-Boot] Please pull u-boot-video

2019-11-25 Thread Tom Rini
On Sun, Nov 24, 2019 at 10:07:40PM +0100, Anatolij Gustschin wrote:

> Hi Tom,
> 
> The following changes since commit 9a0cbae22a613dfd55e15565785749b74c19fdf0:
> 
>   Merge tag 'u-boot-rockchip-20191124' of 
> https://gitlab.denx.de/u-boot/custodians/u-boot-rockchip (2019-11-23 20:50:11 
> -0500)
> 
> are available in the Git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-video.git 
> tags/fixes-for-v2020.01
> 
> for you to fetch changes up to beeb57f0a66658aacad3f12f1a31e65f5d22e46d:
> 
>   Revert "video: mxsfb: Configure the clock after eLCDIF reset" (2019-11-24 
> 21:50:44 +0100)
> 

Applied to u-boot/master, thanks!

-- 
Tom


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


Re: [U-Boot] [GIT PULL resed] Raspberry Pi updates for v2020.01

2019-11-25 Thread Tom Rini
On Sun, Nov 24, 2019 at 10:36:30PM +0100, Matthias Brugger wrote:

> Hi Tom,
> 
> This is a new pull request for the RPi updates for v2020.01.
> 
> After you noticed that the first pull request broke FAT implementation I 
> deleted
> the corresponding patch series from the pull request. In the meantime the one
> binary support for RPi is ready to be merged, so I added the series.
> 
> Please have a look, you can find the travis-ci here:
> https://travis-ci.org/mbgg/u-boot/builds/616217762
> 
> Regards,
> Matthias

Tested on my Pi 3 in both rpi_3, rpi3_32b and rpi_arm64 mode.

Applied to u-boot/master, thanks!

-- 
Tom


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


Re: [U-Boot] [PATCH 2/2] drivers: usb: host: Add BRCM xHCI driver

2019-11-25 Thread Vladimir Olovyannikov
HI Marek,

> On 11/23/19 12:31 AM, Vladimir Olovyannikov wrote:
> [...]
>
> > +#define USBAXI_AWCACHE 0xF
> > +#define USBAXI_ARCACHE 0xF
> > +#define USBAXI_AWPROT  0x8
> > +#define USBAXI_ARPROT  0x8
> > +#define USBAXIWR_SA_VAL((USBAXI_AWCACHE << 4 |
> USBAXI_AWPROT) << 0)
>
> Are the parenthesis correct here ?
> Might make sense to rewrite it as ((AWCACHE << 4) | AWPROT)
>
> > +#define USBAXIWR_SA_MASK   (0xff)
>
> Here the parenthesis are not needed.
>
> > +#define USBAXIWR_UA_VAL((USBAXI_AWCACHE << 4 |
> USBAXI_AWPROT) << 16)
> > +#define USBAXIWR_UA_MASK   ((0xff) << 16)
> > +#define USBAXIRD_SA_VAL((USBAXI_ARCACHE << 4 |
> USBAXI_ARPROT) << 0)
> > +#define USBAXIRD_SA_MASK   (0xff)
> > +#define USBAXIRD_UA_VAL((USBAXI_ARCACHE << 4 |
> USBAXI_ARPROT) << 16)
> > +#define USBAXIRD_UA_MASK   ((0xff) << 16)
> > +
> > +struct brcm_xhci_platdata {
> > +   unsigned int arcache;
> > +   unsigned int awcache;
> > +};
> > +
> > +static int xhci_brcm_probe(struct udevice *dev) {
> > +   struct xhci_hccr *hcd;
> > +   struct xhci_hcor *hcor;
> > +   struct brcm_xhci_platdata *plat = dev_get_platdata(dev);
> > +   int len, ret = 0;
> > +
> > +   if (!plat) {
> > +   dev_err(dev, "Can't get xHCI Plat data\n");
> > +   return -ENOMEM;
> > +   }
> > +
> > +   hcd = dev_read_addr_ptr(dev);
> > +   if (!hcd) {
> > +   dev_err(dev, "Can't get the xHCI register base address\n");
> > +   return -ENXIO;
> > +   }
> > +
> > +   len = HC_LENGTH(xhci_readl(&(hcd)->cr_capbase));
> > +   hcor = (struct xhci_hcor *)((uintptr_t)hcd + len);
>
> Please clean up the extraneous parenthesis ^
>
> > +   /* Save the default values of AXI read and write attributes */
> > +   plat->awcache = readl((uintptr_t)hcd +
> DRD2U3H_XHC_REGS_AXIWRA);
> > +   plat->arcache = readl((uintptr_t)hcd +
> DRD2U3H_XHC_REGS_AXIRDA);
> > +
> > +   /* Enable AXI read and write attributes. */
> > +   clrsetbits_le32(((uintptr_t)hcd + DRD2U3H_XHC_REGS_AXIWRA),
> > +   (USBAXIWR_UA_MASK | USBAXIWR_SA_MASK),
> > +   (USBAXIWR_UA_VAL | USBAXIWR_SA_VAL));
> > +   clrsetbits_le32(((uintptr_t)hcd + DRD2U3H_XHC_REGS_AXIRDA),
> > +   (USBAXIRD_UA_MASK | USBAXIRD_SA_MASK),
> > +   (USBAXIRD_UA_VAL | USBAXIRD_SA_VAL));
> > +
> > +   ret = xhci_register(dev, hcd, hcor);
> > +   if (ret)
> > +   dev_err(dev, "Failed to register xHCI\n");
> > +
> > +   return ret;
> > +}
> > +
> > +static int xhci_brcm_deregister(struct udevice *dev) {
> > +   struct xhci_hccr *hcd;
> > +   struct brcm_xhci_platdata *plat = dev_get_platdata(dev);
> > +
> > +   hcd = (struct xhci_hccr *)((uintptr_t)dev_read_addr(dev));
> > +
> > +   /* Restore the default values for AXI read and write attributes */
> > +   writel(plat->awcache, ((uintptr_t)hcd +
> DRD2U3H_XHC_REGS_AXIWRA));
> > +   writel(plat->arcache, ((uintptr_t)hcd +
> DRD2U3H_XHC_REGS_AXIRDA));
>
> Here too.
>
> Looks good otherwise, thanks.
Thanks for review Marek,
Issues will be resolved with the next patch set.
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] imx8mq-evk boot regression

2019-11-25 Thread Fabio Estevam
Adding Patrick in case he has some suggestions.

Thanks

On Mon, Nov 25, 2019 at 1:18 PM Fabio Estevam  wrote:
>
> Hi,
>
> Just tried to boot imx8mq-evk using latest U-Boot master and this is what I 
> get:
>
> U-Boot SPL 2020.01-rc3-00070-g9a0cbae22a (Nov 25 2019 - 13:08:24 -0300)
> PMIC:  PFUZE100 ID=0x10
> DDRINFO: start DRAM init
> DDRINFO:ddrphy calibration done
> DDRINFO: ddrmix config done
> Normal Boot
> Trying to boot from MMC2
>
> (It hangs here)
>
> I haven't tried to debug this yet, but just wanted to let you know in
> case this is a known issue.
>
> Any ideas?
>
> Thanks,
>
> Fabio Estevam
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] Reboot is broken on RockPro64 with mainline u-boot and ATF

2019-11-25 Thread Vasily Khoruzhick
Hey guys,

Looks like reboot is broken on RockPro64 (RK3399-based) with mainline
u-boot and ATF (ATF already has a fix [1]).

When I type 'reboot' in linux I get back to u-boot, but subsequent
linux boot hangs in most cases. Sometimes I get this warning:

[   62.400363] rcu: INFO: rcu_sched detected stalls on CPUs/tasks:
[   62.418095] rcu: 4-...!: (3 ticks this GP)
idle=332/1/0x4000 softirq=23/24 fqs=13
[   62.444137] Task dump for CPU 4:
[   62.453791] kworker/4:1 R  running task042  2 0x002a
[   62.474907] Workqueue: pm genpd_power_off_work_fn
[   62.489013] rcu: rcu_sched kthread starved for 5976 jiffies! g-1147
f0x0 RCU_GP_WAIT_FQS(5) ->state=0x0 ->cpu=1
[   62.519205] rcu: RCU grace-period kthread stack dump:
[   62.534316] rcu_sched   R  running task010  2 0x0028

I already checked that regulators are configured correctly, also I
tried to disable big CPU cluster in linux and re-initializing CPU
voltages in u-boot but unfortunately nothing helps.

There were other reports on #linux-rockchip at freenode that reboot is broken.

Any ideas how to debug it or what could be wrong?

Regards,
Vasily

[1] https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/2512
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 1/6] remoteproc: elf_loader: Add elf resource table load support

2019-11-25 Thread Patrick DELAUNAY
Hi Fabien,

> From: Fabien DESSENNE 
> Sent: mercredi 30 octobre 2019 14:38
> 
> Add rproc_elf_load_rsc_table(), which searches for a resource table in an
> elf64/elf32 image, and if found, copies it to device memory.
> Add also the elf32 and elf64 variants of this API.
> Add a test for this.
> 
> Signed-off-by: Fabien Dessenne 

At least for STM32MP1 platform,  I test a M4 elf firmware without resource 
table and it is working.

Acked-by: Patrick Delaunay 

Thanks

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


Re: [U-Boot] [PATCH v2 6/6] remoteproc: stm32: load resource table from firmware

2019-11-25 Thread Patrick DELAUNAY
Hi Fabien,

> From: Fabien DESSENNE 
> Sent: mercredi 30 octobre 2019 14:39
> 
> Load the optional resource table from the firmware, and write its address in 
> the
> dedicated backup register.
> 
> Signed-off-by: Fabien Dessenne 

Acked-by: Patrick Delaunay 

Thanks

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


Re: [U-Boot] [PATCH v2 5/6] stm32mp1: remove copro_state environment variable

2019-11-25 Thread Patrick DELAUNAY
Hi Fabien,

> From: Fabien DESSENNE 
> Sent: mercredi 30 octobre 2019 14:39
> 
> Since the coprocessor state is tracked in a backup register, there is no more 
> need
> for tracking it in an environment variable : remove it.
> 
> Signed-off-by: Fabien Dessenne 

Acked-by: Patrick Delaunay 

Thanks

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


Re: [U-Boot] [PATCH v2 3/6] stm32mp1: reset coprocessor status at cold boot

2019-11-25 Thread Patrick DELAUNAY
Hi Fabien,

> From: Fabien DESSENNE 
> Sent: mercredi 30 octobre 2019 14:39
> 
> Reset ResourceTableAddress and CoprocessorState at cold boot, preserve these
> values at standby wakeup.
> 
> Signed-off-by: Fabien Dessenne 

Acked-by: Patrick Delaunay 

Thanks

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


Re: [U-Boot] [PATCH v2 4/6] remoteproc: stm32: track the coprocessor state in a backup register

2019-11-25 Thread Patrick DELAUNAY
Hi Fabien,

> From: Fabien DESSENNE 
> Sent: mercredi 30 octobre 2019 14:39
> 
> Update the dedicated backup register to track the coprocessor state and rely 
> on
> that register to compute the .is_running() value (which expects a return 
> value of 0
> -not 1- if the processor is running).
> 
> Signed-off-by: Fabien Dessenne 


Acked-by: Patrick Delaunay 

Thanks

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


Re: [U-Boot] [PATCH v2 2/6] stm32mp1: declare backup registers for coprocessor

2019-11-25 Thread Patrick DELAUNAY
Hi Fabien,

> From: Fabien DESSENNE 
> Sent: mercredi 30 octobre 2019 14:38
> 
> Use the backup register #17 as coprocessor resource table address and backup
> register #18 as coprocessor state.
> 
> Signed-off-by: Fabien Dessenne 

Acked-by: Patrick Delaunay 

Thanks

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


[U-Boot] [PATCH 4/4] boards/km_arm: enable support for Macronix SPI NOR flash

2019-11-25 Thread Holger Brunck
The M25P80 and M25P32 SPI flashes from Numonix/Micron
will be replaced by Marconix MX25L80 and MX25L32 flashes.

Signed-off-by: Holger Brunck 
CC: Stefan Roese 
CC: Valentin Longchamp 
---
 configs/km_kirkwood_128m16_defconfig | 1 +
 configs/km_kirkwood_defconfig| 1 +
 configs/kmcoge5un_defconfig  | 1 +
 configs/kmnusa_defconfig | 1 +
 4 files changed, 4 insertions(+)

diff --git a/configs/km_kirkwood_128m16_defconfig 
b/configs/km_kirkwood_128m16_defconfig
index 73b4054dcc..c05b789897 100644
--- a/configs/km_kirkwood_128m16_defconfig
+++ b/configs/km_kirkwood_128m16_defconfig
@@ -42,6 +42,7 @@ CONFIG_BOOTCOUNT_BOOTLIMIT=3
 # CONFIG_MMC is not set
 CONFIG_SF_DEFAULT_SPEED=810
 CONFIG_SPI_FLASH_STMICRO=y
+CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_MVGBE=y
 CONFIG_MII=y
 CONFIG_SYS_NS16550=y
diff --git a/configs/km_kirkwood_defconfig b/configs/km_kirkwood_defconfig
index ea8af60fa5..a17cfdd92c 100644
--- a/configs/km_kirkwood_defconfig
+++ b/configs/km_kirkwood_defconfig
@@ -42,6 +42,7 @@ CONFIG_BOOTCOUNT_BOOTLIMIT=3
 # CONFIG_MMC is not set
 CONFIG_SF_DEFAULT_SPEED=810
 CONFIG_SPI_FLASH_STMICRO=y
+CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_MVGBE=y
 CONFIG_MII=y
 CONFIG_SYS_NS16550=y
diff --git a/configs/kmcoge5un_defconfig b/configs/kmcoge5un_defconfig
index f2c835029a..a44df06e1b 100644
--- a/configs/kmcoge5un_defconfig
+++ b/configs/kmcoge5un_defconfig
@@ -46,6 +46,7 @@ CONFIG_BOOTCOUNT_BOOTLIMIT=3
 # CONFIG_MMC is not set
 CONFIG_SF_DEFAULT_SPEED=810
 CONFIG_SPI_FLASH_STMICRO=y
+CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_MVGBE=y
 CONFIG_MII=y
 CONFIG_SYS_NS16550=y
diff --git a/configs/kmnusa_defconfig b/configs/kmnusa_defconfig
index 0b5a0e4e22..ffd8cb03f9 100644
--- a/configs/kmnusa_defconfig
+++ b/configs/kmnusa_defconfig
@@ -46,6 +46,7 @@ CONFIG_BOOTCOUNT_BOOTLIMIT=3
 # CONFIG_MMC is not set
 CONFIG_SF_DEFAULT_SPEED=810
 CONFIG_SPI_FLASH_STMICRO=y
+CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_MV88E6352_SWITCH=y
 CONFIG_MVGBE=y
 CONFIG_MII=y
-- 
2.24.0.rc1

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


[U-Boot] [PATCH 3/4] arm/km: remove board KMCOGE3UN

2019-11-25 Thread Holger Brunck
This target is out of maintenance and can be removed.

Signed-off-by: Holger Brunck 
CC: Stefan Roese 
CC: Valentin Longchamp 
---
 board/keymile/km_arm/MAINTAINERS |  1 -
 board/keymile/km_arm/km_arm.c| 55 +---
 configs/mgcoge3un_defconfig  | 52 --
 include/configs/km_kirkwood.h| 10 +-
 scripts/config_whitelist.txt |  1 -
 5 files changed, 2 insertions(+), 117 deletions(-)
 delete mode 100644 configs/mgcoge3un_defconfig

diff --git a/board/keymile/km_arm/MAINTAINERS b/board/keymile/km_arm/MAINTAINERS
index d80589ded7..17926017c3 100644
--- a/board/keymile/km_arm/MAINTAINERS
+++ b/board/keymile/km_arm/MAINTAINERS
@@ -10,4 +10,3 @@ F:configs/kmcoge5un_defconfig
 F: configs/kmnusa_defconfig
 F: configs/kmsugp1_defconfig
 F: configs/kmsuv31_defconfig
-F: configs/mgcoge3un_defconfig
diff --git a/board/keymile/km_arm/km_arm.c b/board/keymile/km_arm/km_arm.c
index 2724d8bd48..d39a6b6362 100644
--- a/board/keymile/km_arm/km_arm.c
+++ b/board/keymile/km_arm/km_arm.c
@@ -121,26 +121,6 @@ static const u32 kwmpp_config[] = {
 
 static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
 
-#if defined(CONFIG_KM_MGCOGE3UN)
-/*
- * Wait for startup OK from mgcoge3ne
- */
-static int startup_allowed(void)
-{
-   unsigned char buf;
-
-   /*
-* Read CIRQ16 bit (bit 0)
-*/
-   if (i2c_read(BOCO, REG_IRQ_CIRQ2, 1, &buf, 1) != 0)
-   printf("%s: Error reading Boco\n", __func__);
-   else
-   if ((buf & MASK_RBI_DEFECT_16) == MASK_RBI_DEFECT_16)
-   return 1;
-   return 0;
-}
-#endif
-
 #if (defined(CONFIG_KM_PIGGY4_88E6061)|defined(CONFIG_KM_PIGGY4_88E6352))
 /*
  * All boards with PIGGY4 connected via a simple switch have ethernet always
@@ -198,39 +178,6 @@ static void set_bootcount_addr(void)
 
 int misc_init_r(void)
 {
-#if defined(CONFIG_KM_MGCOGE3UN)
-   char *wait_for_ne;
-   u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
-   wait_for_ne = env_get("waitforne");
-
-   if ((wait_for_ne != NULL) && (dip_switch == 0)) {
-   if (strcmp(wait_for_ne, "true") == 0) {
-   int cnt = 0;
-   int abort = 0;
-   puts("NE go: ");
-   while (startup_allowed() == 0) {
-   if (tstc()) {
-   (void) getc(); /* consume input */
-   abort = 1;
-   break;
-   }
-   udelay(20);
-   cnt++;
-   if (cnt == 5)
-   puts("wait\b\b\b\b");
-   if (cnt == 10) {
-   cnt = 0;
-   puts("\b\b\b\b");
-   }
-   }
-   if (abort == 1)
-   printf("\nAbort waiting for ne\n");
-   else
-   puts("OK\n");
-   }
-   }
-#endif
-
ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
 
@@ -293,7 +240,7 @@ int board_init(void)
 
 int board_late_init(void)
 {
-#if (defined(CONFIG_KM_COGE5UN) | defined(CONFIG_KM_MGCOGE3UN))
+#if defined(CONFIG_KM_COGE5UN)
u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
 
/* if pin 1 do full erase */
diff --git a/configs/mgcoge3un_defconfig b/configs/mgcoge3un_defconfig
deleted file mode 100644
index 24f6b4656c..00
--- a/configs/mgcoge3un_defconfig
+++ /dev/null
@@ -1,52 +0,0 @@
-CONFIG_ARM=y
-CONFIG_SYS_DCACHE_OFF=y
-CONFIG_ARCH_CPU_INIT=y
-CONFIG_KIRKWOOD=y
-CONFIG_SYS_TEXT_BASE=0x07d0
-CONFIG_TARGET_KM_KIRKWOOD=y
-CONFIG_PIGGY_MAC_ADDRESS_OFFSET=3
-CONFIG_KM_PIGGY4_88E6061=y
-CONFIG_ENV_SIZE=0x2000
-CONFIG_ENV_OFFSET=0x0
-CONFIG_IDENT_STRING="\nKeymile COGE3UN"
-CONFIG_SYS_EXTRA_OPTIONS="KM_MGCOGE3UN"
-CONFIG_MISC_INIT_R=y
-CONFIG_VERSION_VARIABLE=y
-# CONFIG_DISPLAY_BOARDINFO is not set
-CONFIG_HUSH_PARSER=y
-CONFIG_AUTOBOOT_KEYED=y
-CONFIG_AUTOBOOT_PROMPT="Hit  key to stop autoboot in %2ds\n"
-CONFIG_AUTOBOOT_STOP_STR=" "
-CONFIG_CMD_ASKENV=y
-CONFIG_CMD_GREPENV=y
-CONFIG_CMD_EEPROM=y
-# CONFIG_CMD_FLASH is not set
-CONFIG_CMD_I2C=y
-CONFIG_CMD_NAND=y
-CONFIG_CMD_DHCP=y
-CONFIG_CMD_MII=y
-CONFIG_CMD_PING=y
-CONFIG_CMD_JFFS2=y
-CONFIG_CMD_MTDPARTS=y
-CONFIG_MTDIDS_DEFAULT="nand0=orion_nand"
-CONFIG_MTDPARTS_DEFAULT="mtdparts=orion_nand:-(ubi0);"
-CONFIG_CMD_UBI=y
-# CONFIG_CMD_UBIFS is not set
-CONFIG_OF_CONTROL=y
-CONFIG_DEFAULT_DEVICE_TREE="kirkwood-km_kirkwood"
-CONFIG_ENV_IS_IN_EEPROM=y
-CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
-CONFIG_ENV_OFFSET_REDUND=0x2000
-CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_

[U-Boot] [PATCH 2/4] km/boards: add MAC address offset as argument to ivm_populate_env

2019-11-25 Thread Holger Brunck
For upcoming SECU board we have different MAC address offsets depending
on which functional unit we are running. In this case we need to pass
this value to the ivm_populate_env function instead of using the hard
coded config option there.

Signed-off-by: Holger Brunck 
CC: Stefan Roese 
CC: Valentin Longchamp 
CC: Marek Vasut 
---
 board/keymile/common/common.h   |  2 +-
 board/keymile/common/ivm.c  | 12 ++--
 board/keymile/km83xx/km83xx.c   |  3 ++-
 board/keymile/km_arm/km_arm.c   |  3 ++-
 board/keymile/kmp204x/kmp204x.c |  3 ++-
 5 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/board/keymile/common/common.h b/board/keymile/common/common.h
index 42b760dc6e..8251de4db8 100644
--- a/board/keymile/common/common.h
+++ b/board/keymile/common/common.h
@@ -121,7 +121,7 @@ struct bfticu_iomap {
 };
 
 int ethernet_present(void);
-int ivm_read_eeprom(unsigned char *buf, int len);
+int ivm_read_eeprom(unsigned char *buf, int len, int mac_address_offset);
 int ivm_analyze_eeprom(unsigned char *buf, int len);
 
 int trigger_fpga_config(void);
diff --git a/board/keymile/common/ivm.c b/board/keymile/common/ivm.c
index 429e9c7914..fee7f03c8c 100644
--- a/board/keymile/common/ivm.c
+++ b/board/keymile/common/ivm.c
@@ -297,7 +297,7 @@ int ivm_analyze_eeprom(unsigned char *buf, int len)
return 0;
 }
 
-static int ivm_populate_env(unsigned char *buf, int len)
+static int ivm_populate_env(unsigned char *buf, int len, int 
mac_address_offset)
 {
unsigned char   *page2;
unsigned char   valbuf[MAC_STR_SZ];
@@ -309,23 +309,23 @@ static int ivm_populate_env(unsigned char *buf, int len)
 
 #ifndef CONFIG_KMTEGR1
/* if an offset is defined, add it */
-   process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADDRESS_OFFSET, true);
+   process_mac(valbuf, page2, mac_address_offset, true);
env_set((char *)"ethaddr", (char *)valbuf);
 #else
 /* KMTEGR1 has a special setup. eth0 has no connection to the outside and
  * gets an locally administred MAC address, eth1 is the debug interface and
  * gets the official MAC address from the IVM
  */
-   process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADDRESS_OFFSET, false);
+   process_mac(valbuf, page2, mac_address_offset, false);
env_set((char *)"ethaddr", (char *)valbuf);
-   process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADDRESS_OFFSET, true);
+   process_mac(valbuf, page2, mac_address_offset, true);
env_set((char *)"eth1addr", (char *)valbuf);
 #endif
 
return 0;
 }
 
-int ivm_read_eeprom(unsigned char *buf, int len)
+int ivm_read_eeprom(unsigned char *buf, int len, int mac_address_offset)
 {
int ret;
 
@@ -339,5 +339,5 @@ int ivm_read_eeprom(unsigned char *buf, int len)
return -2;
}
 
-   return ivm_populate_env(buf, len);
+   return ivm_populate_env(buf, len, mac_address_offset);
 }
diff --git a/board/keymile/km83xx/km83xx.c b/board/keymile/km83xx/km83xx.c
index 8846b64f7d..59347a3990 100644
--- a/board/keymile/km83xx/km83xx.c
+++ b/board/keymile/km83xx/km83xx.c
@@ -185,7 +185,8 @@ int board_early_init_r(void)
 
 int misc_init_r(void)
 {
-   ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
+   ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
+   CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
return 0;
 }
 
diff --git a/board/keymile/km_arm/km_arm.c b/board/keymile/km_arm/km_arm.c
index 922cc621f7..2724d8bd48 100644
--- a/board/keymile/km_arm/km_arm.c
+++ b/board/keymile/km_arm/km_arm.c
@@ -231,7 +231,8 @@ int misc_init_r(void)
}
 #endif
 
-   ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
+   ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
+   CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
 
initialize_unit_leds();
set_km_env();
diff --git a/board/keymile/kmp204x/kmp204x.c b/board/keymile/kmp204x/kmp204x.c
index 4d1e38aa3a..e7c321c326 100644
--- a/board/keymile/kmp204x/kmp204x.c
+++ b/board/keymile/kmp204x/kmp204x.c
@@ -195,7 +195,8 @@ int misc_init_r(void)
}
}
 
-   ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
+   ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
+   CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
return 0;
 }
 
-- 
2.24.0.rc1

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


[U-Boot] [PATCH 1/4] km/boards: fix typo for MAC address offset config option

2019-11-25 Thread Holger Brunck
This patch only fixes a typo.

Signed-off-by: Holger Brunck 
CC: Stefan Roese 
CC: Valentin Longchamp 
---
 board/keymile/Kconfig   | 2 +-
 board/keymile/common/ivm.c  | 6 +++---
 configs/kmcoge5un_defconfig | 2 +-
 configs/mgcoge3un_defconfig | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/board/keymile/Kconfig b/board/keymile/Kconfig
index acaa9289f7..ba1960f3d0 100644
--- a/board/keymile/Kconfig
+++ b/board/keymile/Kconfig
@@ -70,7 +70,7 @@ config KM_COMMON_ETH_INIT
  Use the Ethernet initialization implemented in common code, which
  detects if a Piggy board is present.
 
-config PIGGY_MAC_ADRESS_OFFSET
+config PIGGY_MAC_ADDRESS_OFFSET
int "Piggy Address Offset"
default 0
help
diff --git a/board/keymile/common/ivm.c b/board/keymile/common/ivm.c
index 50df44d1c1..429e9c7914 100644
--- a/board/keymile/common/ivm.c
+++ b/board/keymile/common/ivm.c
@@ -309,16 +309,16 @@ static int ivm_populate_env(unsigned char *buf, int len)
 
 #ifndef CONFIG_KMTEGR1
/* if an offset is defined, add it */
-   process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET, true);
+   process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADDRESS_OFFSET, true);
env_set((char *)"ethaddr", (char *)valbuf);
 #else
 /* KMTEGR1 has a special setup. eth0 has no connection to the outside and
  * gets an locally administred MAC address, eth1 is the debug interface and
  * gets the official MAC address from the IVM
  */
-   process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET, false);
+   process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADDRESS_OFFSET, false);
env_set((char *)"ethaddr", (char *)valbuf);
-   process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADRESS_OFFSET, true);
+   process_mac(valbuf, page2, CONFIG_PIGGY_MAC_ADDRESS_OFFSET, true);
env_set((char *)"eth1addr", (char *)valbuf);
 #endif
 
diff --git a/configs/kmcoge5un_defconfig b/configs/kmcoge5un_defconfig
index ff23af3060..f2c835029a 100644
--- a/configs/kmcoge5un_defconfig
+++ b/configs/kmcoge5un_defconfig
@@ -4,7 +4,7 @@ CONFIG_ARCH_CPU_INIT=y
 CONFIG_KIRKWOOD=y
 CONFIG_SYS_TEXT_BASE=0x07d0
 CONFIG_TARGET_KM_KIRKWOOD=y
-CONFIG_PIGGY_MAC_ADRESS_OFFSET=3
+CONFIG_PIGGY_MAC_ADDRESS_OFFSET=3
 CONFIG_KM_ENV_IS_IN_SPI_NOR=y
 CONFIG_KM_PIGGY4_88E6352=y
 CONFIG_ENV_SIZE=0x2000
diff --git a/configs/mgcoge3un_defconfig b/configs/mgcoge3un_defconfig
index cae6645832..24f6b4656c 100644
--- a/configs/mgcoge3un_defconfig
+++ b/configs/mgcoge3un_defconfig
@@ -4,7 +4,7 @@ CONFIG_ARCH_CPU_INIT=y
 CONFIG_KIRKWOOD=y
 CONFIG_SYS_TEXT_BASE=0x07d0
 CONFIG_TARGET_KM_KIRKWOOD=y
-CONFIG_PIGGY_MAC_ADRESS_OFFSET=3
+CONFIG_PIGGY_MAC_ADDRESS_OFFSET=3
 CONFIG_KM_PIGGY4_88E6061=y
 CONFIG_ENV_SIZE=0x2000
 CONFIG_ENV_OFFSET=0x0
-- 
2.24.0.rc1

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


Re: [U-Boot] SPDX header might be wrong in 4 files from Android Open Source Project

2019-11-25 Thread Igor Opaniuk
+ Alex Deymo

Hi Zdenek

On Mon, Nov 25, 2019 at 6:05 PM zdenek.bou...@siemens.com
 wrote:
>
> Hello,
>
> SPDX-License-Identifier: BSD-3-Clause might be wrong in the following 4 files 
> from Android Open Source Project (AOSP):
>
> include/android_bootloader_message.h
> include/sparse_format.h
> include/dt_table.h
> include/android_image.h

they were re-licensed by one of the Google employees specifically for
U-boot [1].

>
> As you can see in the comments the content is from AOSP.
>
> But these files have Apache License, Version 2.0 in AOSP:
> https://android.googlesource.com/platform/bootable/recovery/+/master/bootloader_message/include/bootloader_message/bootloader_message.h
> https://android.googlesource.com/platform/system/core/+/28fa5bc347390480fe190294c6c385b6a9f0d68b/libsparse/sparse_format.h
> https://android.googlesource.com/platform/system/libufdt/+/2626d8b9e4d8e8c6cc67ceb1dc4e05a47779785c/utils/src/dt_table.h
> https://android.googlesource.com/platform/system/tools/mkbootimg/+/e55998a0f2b61b685d5eb4a486ca3a0c680b1a2f/include/bootimg/bootimg.h
>
> I am afraid, that there could be a license compatibility problem with 
> creating one binary from both source files with GPL2-only license and source 
> files with Apache 2 license.
>
> Am I wrong? Is it possible to re-license from Apache 2 to BSD 3 license if 
> there are only simple structs and defines in those files?
> With best regards,
> Zdenek Bouska
>
> Siemens, s.r.o.
> Internet of Things
> Development Services
> IOT DS EU CZ AE
> Siemensova 1
> 155 00 Prague 13, Czech Republic
>
> zdenek.bou...@siemens.com
>
>
> [cid:image003.png@01D5A3B2.56B02BF0]
>
>
>
>
>
>
> Siemens, s.r.o. - CEO: Ing. Eduard Palíšek, Ph.D., MBA, CFO: Dipl.-Kfm. 
> Michael Axmann - registered in the Commercial Register of the Municipal Court 
> in Prague, Sec. C, File 625
> Registered office: Siemensova 1, 155 00 Prague 13, Czech Republic
> IČ: 00268577, DIČ: CZ00268577, ID of data box: h6vchd6, Bank connection: 
> UniCredit Bank Czech Republic and Slovakia, a.s., Želetavská 1525/1, 140 92 
> Prague 4, Czech Republic;   Acc. Nr. CZK: 1013384001/2700, Acc. Nr. EUR: 
> 1013384394/2700
>
> Important Note:  This message is only of informative nature. The content of 
> this message shall not be binding for sender and sender does neither intend 
> to conclude contract, accept offer or confirm the conclusion of the contract 
> by this message nor this message represents pre-contractual liability of the 
> sender, unless the sender states in the message excplicitly otherwise.
>
> The content of this message (including appendices) shall be confidential. 
> Should you are not intended receiver of this message, any access, copying, 
> distribution or use of the content of this message is strictly prohibited and 
> in such case, please immediately notify the sender and subsequently delete 
> the entire message (including apppendices) from your system.
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot

[1] https://patchwork.ozlabs.org/patch/1099689/

-- 
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opan...@gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] spl: fix entry_point equal to load_addr

2019-11-25 Thread Giulio Benetti
At the moment entry_point is set to image_get_load(header) that sets it
to "load address" instead of "entry point", assuming entry_point is
equal to load_addr, but it's not true. Then load_addr is set to
"entry_point - header_size", but this is wrong too since load_addr is
not an entry point.

So use image_get_ep() for entry_point assignment and image_get_load()
for load_addr assignment.

Signed-off-by: Giulio Benetti 
---
 common/spl/spl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index f1ad8dc9da..cdae346753 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -261,9 +261,9 @@ int spl_parse_image_header(struct spl_image_info *spl_image,
spl_image->entry_point = image_get_ep(header);
spl_image->size = image_get_data_size(header);
} else {
-   spl_image->entry_point = image_get_load(header);
+   spl_image->entry_point = image_get_ep(header);
/* Load including the header */
-   spl_image->load_addr = spl_image->entry_point -
+   spl_image->load_addr = image_get_load(header) -
header_size;
spl_image->size = image_get_data_size(header) +
header_size;
-- 
2.20.1

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


[U-Boot] imx8mq-evk boot regression

2019-11-25 Thread Fabio Estevam
Hi,

Just tried to boot imx8mq-evk using latest U-Boot master and this is what I get:

U-Boot SPL 2020.01-rc3-00070-g9a0cbae22a (Nov 25 2019 - 13:08:24 -0300)
PMIC:  PFUZE100 ID=0x10
DDRINFO: start DRAM init
DDRINFO:ddrphy calibration done
DDRINFO: ddrmix config done
Normal Boot
Trying to boot from MMC2

(It hangs here)

I haven't tried to debug this yet, but just wanted to let you know in
case this is a known issue.

Any ideas?

Thanks,

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


[U-Boot] SPDX header might be wrong in 4 files from Android Open Source Project

2019-11-25 Thread zdenek.bou...@siemens.com
Hello,

SPDX-License-Identifier: BSD-3-Clause might be wrong in the following 4 files 
from Android Open Source Project (AOSP):

include/android_bootloader_message.h
include/sparse_format.h
include/dt_table.h
include/android_image.h

As you can see in the comments the content is from AOSP.

But these files have Apache License, Version 2.0 in AOSP:
https://android.googlesource.com/platform/bootable/recovery/+/master/bootloader_message/include/bootloader_message/bootloader_message.h
https://android.googlesource.com/platform/system/core/+/28fa5bc347390480fe190294c6c385b6a9f0d68b/libsparse/sparse_format.h
https://android.googlesource.com/platform/system/libufdt/+/2626d8b9e4d8e8c6cc67ceb1dc4e05a47779785c/utils/src/dt_table.h
https://android.googlesource.com/platform/system/tools/mkbootimg/+/e55998a0f2b61b685d5eb4a486ca3a0c680b1a2f/include/bootimg/bootimg.h

I am afraid, that there could be a license compatibility problem with creating 
one binary from both source files with GPL2-only license and source files with 
Apache 2 license.

Am I wrong? Is it possible to re-license from Apache 2 to BSD 3 license if 
there are only simple structs and defines in those files?
With best regards,
Zdenek Bouska

Siemens, s.r.o.
Internet of Things
Development Services
IOT DS EU CZ AE
Siemensova 1
155 00 Prague 13, Czech Republic

zdenek.bou...@siemens.com


[cid:image003.png@01D5A3B2.56B02BF0]






Siemens, s.r.o. - CEO: Ing. Eduard Palíšek, Ph.D., MBA, CFO: Dipl.-Kfm. Michael 
Axmann - registered in the Commercial Register of the Municipal Court in 
Prague, Sec. C, File 625
Registered office: Siemensova 1, 155 00 Prague 13, Czech Republic
IČ: 00268577, DIČ: CZ00268577, ID of data box: h6vchd6, Bank connection: 
UniCredit Bank Czech Republic and Slovakia, a.s., Želetavská 1525/1, 140 92 
Prague 4, Czech Republic;   Acc. Nr. CZK: 1013384001/2700, Acc. Nr. EUR: 
1013384394/2700

Important Note:  This message is only of informative nature. The content of 
this message shall not be binding for sender and sender does neither intend to 
conclude contract, accept offer or confirm the conclusion of the contract by 
this message nor this message represents pre-contractual liability of the 
sender, unless the sender states in the message excplicitly otherwise.

The content of this message (including appendices) shall be confidential. 
Should you are not intended receiver of this message, any access, copying, 
distribution or use of the content of this message is strictly prohibited and 
in such case, please immediately notify the sender and subsequently delete the 
entire message (including apppendices) from your system.
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [EXT] Re: [PATCHv2 1/2] PCI: layerscape: Add Support for ls2088 PCIe EP mode

2019-11-25 Thread Ramon Fried
>
> Hi Ramon,
>
> I need your help on this, could you help explain how to start the PCIe EP
> test in
> u-boot? Thanks a lot.
>
> Hi, you just need to run the test suite and it will test the PCIe EP
sandbox class automatically.
See test/README
Why do you care about the EP testing, it's testing the PCIe UCLASS
implementation.
To test your implementation you need to test on actual device.
Thanks,
Ramon.
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] drivers: net: fsl_enetc: register internal MDIO bus

2019-11-25 Thread Alex Marginean
This bus is used to access internal SoC PHYs.  These PHYs are configured
by the ENETC driver directly, but it's useful to have command line access
to this MDIO to debug the system especially when using new external PHYs.

Signed-off-by: Alex Marginean 
---
 drivers/net/fsl_enetc.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c
index e86f3dddb5..02c1ee70d9 100644
--- a/drivers/net/fsl_enetc.c
+++ b/drivers/net/fsl_enetc.c
@@ -156,19 +156,14 @@ static void enetc_start_pcs(struct udevice *dev)
 
priv->if_type = PHY_INTERFACE_MODE_NONE;
 
-   /* check internal mdio capability, not all ports need it */
+   /* register internal MDIO for debug purposes */
if (enetc_read_port(priv, ENETC_PCAPR0) & ENETC_PCAPRO_MDIO) {
-   /*
-* set up internal MDIO, this is part of ETH PCI function and is
-* used to access serdes / internal SoC PHYs.
-* We don't currently register it as a MDIO bus as it goes away
-* when the interface is removed, so it can't practically be
-* used in the console.
-*/
priv->imdio.read = enetc_mdio_read;
priv->imdio.write = enetc_mdio_write;
priv->imdio.priv = priv->port_regs + ENETC_PM_IMDIO_BASE;
strncpy(priv->imdio.name, dev->name, MDIO_NAME_LEN);
+   if (!miiphy_get_dev_by_name(priv->imdio.name))
+   mdio_register(&priv->imdio);
}
 
if (!ofnode_valid(dev->node)) {
@@ -451,6 +446,10 @@ static void enetc_stop(struct udevice *dev)
 {
/* FLR is sufficient to quiesce the device */
dm_pci_flr(dev);
+   /* leave the BARs accessible after we stop, this is needed to use
+* internal MDIO in command line.
+*/
+   dm_pci_clrset_config16(dev, PCI_COMMAND, 0, PCI_COMMAND_MEMORY);
 }
 
 /*
-- 
2.17.1

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


Re: [U-Boot] [PATCH 2/5] common: add blkcache init

2019-11-25 Thread Eric Nelson

Hi Angelo,

On 11/25/19 2:59 AM, Angelo Dureghello wrote:

Hi Eric,

On Sun, Nov 24, 2019 at 5:00 PM Eric Nelson  wrote:


Hi Angelo,

On 11/23/19 3:47 PM, Angelo Dureghello wrote:

From: Angelo Durgehello 

On m68k, block_cache list is relocated, but next and prev list
pointers are not adjusted to the relocated struct list_head address,
so the first iteration over the block_cache list hangs.

This patch initializes the block_cache list after relocation.

Signed-off-by: Angelo Durgehello 
---
   common/board_r.c | 12 
   drivers/block/blkcache.c |  7 ++-
   include/blk.h|  6 ++
   3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/common/board_r.c b/common/board_r.c
index 65720849cd..13e70a5ffb 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -628,6 +628,15 @@ static int initr_bedbug(void)
   }
   #endif

+#ifdef CONFIG_BLOCK_CACHE
+static int initr_blkcache(void)
+{
+ blkcache_init();
+
+ return 0;
+}
+#endif
+


Why the extra level of indirection?


   static int run_main_loop(void)
   {
   #ifdef CONFIG_SANDBOX
@@ -832,6 +841,9 @@ static init_fnc_t init_sequence_r[] = {
   #endif
   #if defined(CONFIG_PRAM)
   initr_mem,
+#endif
+#ifdef CONFIG_BLOCK_CACHE


It seems you could call blkcache_init from here directly:



reason for this is to maintain "initr_" naming convention, used from
quite all the initr_ calls,
as i.e. static int initr_mmc(void) that's doing the same.



Okay. I think this isn't a hard rule though (see log_init,
stdio_init_tables, etc).

I'm not sure that it would be a bad thing to rename blkcache_init
to initr_blkcache to indicate the usage.




+ initr_blkcache,
   #endif
   run_main_loop,
   };
diff --git a/drivers/block/blkcache.c b/drivers/block/blkcache.c
index 1fa64989d3..bf0fa1ea6f 100644
--- a/drivers/block/blkcache.c
+++ b/drivers/block/blkcache.c
@@ -21,13 +21,18 @@ struct block_cache_node {
   char *cache;
   };

-static LIST_HEAD(block_cache);
+static struct list_head block_cache;

   static struct block_cache_stats _stats = {
   .max_blocks_per_entry = 8,
   .max_entries = 32
   };

+void blkcache_init(void)
+{
+ INIT_LIST_HEAD(&block_cache);
+}
+
   static struct block_cache_node *cache_find(int iftype, int devnum,
  lbaint_t start, lbaint_t blkcnt,
  unsigned long blksz)
diff --git a/include/blk.h b/include/blk.h
index d0c033aece..7070fd6af3 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -113,6 +113,12 @@ struct blk_desc {
   (PAD_SIZE(size, blk_desc->blksz))

   #if CONFIG_IS_ENABLED(BLOCK_CACHE)
+
+/**
+ * blkcache_init() - initialize the block cache list pointers
+ */
+void blkcache_init(void);
+
   /**
* blkcache_read() - attempt to read a set of blocks from cache
*




Regards,
--
Angelo Dureghello



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


Re: [U-Boot] [PATCH 2/5] common: add blkcache init

2019-11-25 Thread Eric Nelson

Hi Angelo,

On 11/25/19 2:59 AM, Angelo Dureghello wrote:

Hi Eric,

On Sun, Nov 24, 2019 at 5:00 PM Eric Nelson  wrote:


Hi Angelo,

On 11/23/19 3:47 PM, Angelo Dureghello wrote:

From: Angelo Durgehello 

On m68k, block_cache list is relocated, but next and prev list
pointers are not adjusted to the relocated struct list_head address,
so the first iteration over the block_cache list hangs.

This patch initializes the block_cache list after relocation.

Signed-off-by: Angelo Durgehello 
---
   common/board_r.c | 12 
   drivers/block/blkcache.c |  7 ++-
   include/blk.h|  6 ++
   3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/common/board_r.c b/common/board_r.c
index 65720849cd..13e70a5ffb 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -628,6 +628,15 @@ static int initr_bedbug(void)
   }
   #endif

+#ifdef CONFIG_BLOCK_CACHE
+static int initr_blkcache(void)
+{
+ blkcache_init();
+
+ return 0;
+}
+#endif
+


Why the extra level of indirection?


   static int run_main_loop(void)
   {
   #ifdef CONFIG_SANDBOX
@@ -832,6 +841,9 @@ static init_fnc_t init_sequence_r[] = {
   #endif
   #if defined(CONFIG_PRAM)
   initr_mem,
+#endif
+#ifdef CONFIG_BLOCK_CACHE


It seems you could call blkcache_init from here directly:



reason for this is to maintain "initr_" naming convention, used from
quite all the initr_ calls,
as i.e. static int initr_mmc(void) that's doing the same.



Okay. I think this isn't a hard rule though (see log_init,
stdio_init_tables, etc).

I'm not sure that it would be a bad thing to rename blkcache_init
to initr_blkcache to indicate the usage.




+ initr_blkcache,
   #endif
   run_main_loop,
   };
diff --git a/drivers/block/blkcache.c b/drivers/block/blkcache.c
index 1fa64989d3..bf0fa1ea6f 100644
--- a/drivers/block/blkcache.c
+++ b/drivers/block/blkcache.c
@@ -21,13 +21,18 @@ struct block_cache_node {
   char *cache;
   };

-static LIST_HEAD(block_cache);
+static struct list_head block_cache;

   static struct block_cache_stats _stats = {
   .max_blocks_per_entry = 8,
   .max_entries = 32
   };

+void blkcache_init(void)
+{
+ INIT_LIST_HEAD(&block_cache);
+}
+
   static struct block_cache_node *cache_find(int iftype, int devnum,
  lbaint_t start, lbaint_t blkcnt,
  unsigned long blksz)
diff --git a/include/blk.h b/include/blk.h
index d0c033aece..7070fd6af3 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -113,6 +113,12 @@ struct blk_desc {
   (PAD_SIZE(size, blk_desc->blksz))

   #if CONFIG_IS_ENABLED(BLOCK_CACHE)
+
+/**
+ * blkcache_init() - initialize the block cache list pointers
+ */
+void blkcache_init(void);
+
   /**
* blkcache_read() - attempt to read a set of blocks from cache
*




Regards,
--
Angelo Dureghello



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


[U-Boot] [PATCH v2 6/6] configs: ls1028a: enable the Ethernet switch driver in defconfig

2019-11-25 Thread Alex Marginean
The switch driver for LS1028A Ethernet switch is now compiled in for
both LS1028A boards.

Signed-off-by: Alex Marginean 
---
 configs/ls1028aqds_tfa_SECURE_BOOT_defconfig | 3 ++-
 configs/ls1028aqds_tfa_defconfig | 3 ++-
 configs/ls1028ardb_tfa_SECURE_BOOT_defconfig | 3 ++-
 configs/ls1028ardb_tfa_defconfig | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/configs/ls1028aqds_tfa_SECURE_BOOT_defconfig 
b/configs/ls1028aqds_tfa_SECURE_BOOT_defconfig
index 713a088e42..931c78ab46 100644
--- a/configs/ls1028aqds_tfa_SECURE_BOOT_defconfig
+++ b/configs/ls1028aqds_tfa_SECURE_BOOT_defconfig
@@ -49,8 +49,9 @@ CONFIG_PHY_ATHEROS=y
 CONFIG_PHY_VITESSE=y
 CONFIG_DM_ETH=y
 CONFIG_DM_MDIO=y
+CONFIG_DM_DSA=y
 CONFIG_E1000=y
-CONFIG_FSL_ENETC=y
+CONFIG_MSCC_FELIX_SWITCH=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
 CONFIG_DM_PCI_COMPAT=y
diff --git a/configs/ls1028aqds_tfa_defconfig b/configs/ls1028aqds_tfa_defconfig
index b5eb872148..ad5c783e16 100644
--- a/configs/ls1028aqds_tfa_defconfig
+++ b/configs/ls1028aqds_tfa_defconfig
@@ -52,8 +52,9 @@ CONFIG_PHY_ATHEROS=y
 CONFIG_PHY_VITESSE=y
 CONFIG_DM_ETH=y
 CONFIG_DM_MDIO=y
+CONFIG_DM_DSA=y
 CONFIG_E1000=y
-CONFIG_FSL_ENETC=y
+CONFIG_MSCC_FELIX_SWITCH=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
 CONFIG_DM_PCI_COMPAT=y
diff --git a/configs/ls1028ardb_tfa_SECURE_BOOT_defconfig 
b/configs/ls1028ardb_tfa_SECURE_BOOT_defconfig
index dc07a0a4d7..e30fb96344 100644
--- a/configs/ls1028ardb_tfa_SECURE_BOOT_defconfig
+++ b/configs/ls1028ardb_tfa_SECURE_BOOT_defconfig
@@ -48,9 +48,10 @@ CONFIG_PHY_ATHEROS=y
 CONFIG_PHY_VITESSE=y
 CONFIG_DM_ETH=y
 CONFIG_DM_MDIO=y
+CONFIG_DM_DSA=y
 CONFIG_PHY_GIGE=y
 CONFIG_E1000=y
-CONFIG_FSL_ENETC=y
+CONFIG_MSCC_FELIX_SWITCH=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
 CONFIG_DM_PCI_COMPAT=y
diff --git a/configs/ls1028ardb_tfa_defconfig b/configs/ls1028ardb_tfa_defconfig
index 644c5ac6bb..87e4fdd18e 100644
--- a/configs/ls1028ardb_tfa_defconfig
+++ b/configs/ls1028ardb_tfa_defconfig
@@ -52,9 +52,10 @@ CONFIG_PHY_ATHEROS=y
 CONFIG_PHY_VITESSE=y
 CONFIG_DM_ETH=y
 CONFIG_DM_MDIO=y
+CONFIG_DM_DSA=y
 CONFIG_PHY_GIGE=y
 CONFIG_E1000=y
-CONFIG_FSL_ENETC=y
+CONFIG_MSCC_FELIX_SWITCH=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
 CONFIG_DM_PCI_COMPAT=y
-- 
2.17.1

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


[U-Boot] [PATCH v2 3/6] test: dm: add a simple unit test for DSA class

2019-11-25 Thread Alex Marginean
The test pings the local IP address though different ports of a sandbox
DSA device.  Port traffic is filtered and the test verifies that ping
works only on enabled ports.
The additional interfaces require MAC addresses, these have been added
to sandbox default environment.

Signed-off-by: Alex Marginean 
---
 arch/Kconfig  |  1 +
 arch/sandbox/dts/test.dts | 49 +
 include/configs/sandbox.h |  4 +++
 test/dm/Makefile  |  1 +
 test/dm/dsa.c | 58 +++
 test/dm/test-fdt.c|  2 +-
 6 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 test/dm/dsa.c

diff --git a/arch/Kconfig b/arch/Kconfig
index 141e48bc43..70907d69a1 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -133,6 +133,7 @@ config SANDBOX
imply PHYLIB
imply DM_MDIO
imply DM_MDIO_MUX
+   imply DM_DSA
 
 config SH
bool "SuperH architecture"
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index fdb08f2111..0f565f066a 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -40,6 +40,10 @@
usb2 = &usb_2;
axi0 = &axi;
osd0 = "/osd";
+   eth8 = &swp_0;
+   eth9 = &swp_1;
+   eth10 = &swp_2;
+   eth11 = &dsa_eth0;
};
 
audio: audio-codec {
@@ -889,6 +893,51 @@
mdio: mdio-test {
compatible = "sandbox,mdio";
};
+
+   dsa_eth0: dsa-test-eth {
+   compatible = "sandbox,dsa-eth";
+   };
+
+   dsa-test {
+   compatible = "sandbox,dsa";
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   swp_0: port@0 {
+   reg = <0>;
+   label = "lan0";
+   };
+
+   swp_1: port@1 {
+   reg = <1>;
+   label = "lan1";
+   phy-mode = "rgmii-txid";
+   fixed-link {
+   speed = <1000>;
+   full-duplex;
+   };
+   };
+
+   swp_2: port@2 {
+   reg = <2>;
+   label = "lan2";
+   fixed-link {
+   speed = <100>;
+   full-duplex;
+   };
+   };
+
+   port@3 {
+   reg = <3>;
+   ethernet = <&dsa_eth0>;
+   fixed-link {
+   speed = <100>;
+   full-duplex;
+   };
+   };
+   };
+   };
 };
 
 #include "sandbox_pmic.dtsi"
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index 5d75021ed6..a586a93415 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -102,6 +102,10 @@
"eth1addr=00:00:11:22:33:45\0" \
"eth3addr=00:00:11:22:33:46\0" \
"eth5addr=00:00:11:22:33:47\0" \
+   "eth8addr=00:00:11:22:33:48\0" \
+   "eth9addr=00:00:11:22:33:49\0" \
+   "eth10addr=00:00:11:22:33:4a\0" \
+   "eth11addr=00:00:11:22:33:4b\0" \
"ipaddr=1.2.3.4\0"
 
 #define MEM_LAYOUT_ENV_SETTINGS \
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 0c2fd5cb5e..69e9feed91 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_DSA) += dsa.o
 endif
diff --git a/test/dm/dsa.c b/test/dm/dsa.c
new file mode 100644
index 00..c8e76be16f
--- /dev/null
+++ b/test/dm/dsa.c
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 NXP
+ */
+
+#include 
+#include 
+#include 
+
+extern int dsa_sandbox_port_mask;
+
+/* this test sends ping requests with the local address through each DSA port
+ * via the dummy DSA master Eth.
+ * The dummy Eth filters traffic based on DSA port used to Tx and the port
+ * mask set here, so we can check that port information gets trough correctly.
+ */
+static int dm_test_dsa(struct unit_test_state *uts)
+{
+   dsa_sandbox_port_mask = 0x5;
+
+   env_set("ethrotate", "no");
+   net_ping_ip = string_to_ip("1.2.3.4");
+
+   env_se

[U-Boot] [PATCH v2 5/6] arm: dts: ls1028a: adds Ethernet switch node and its dependencies

2019-11-25 Thread Alex Marginean
The definition follows the DSA binding in kernel and describes the switch,
its ports and PHYs.
ENETC PF6 is the 2nd Eth controller linked to the switch on LS1028A, it is
not used in U-Boot and was disabled.

Signed-off-by: Alex Marginean 
Tested-by: Michael Walle 
---
 arch/arm/dts/fsl-ls1028a-rdb.dts | 36 ++
 arch/arm/dts/fsl-ls1028a.dtsi| 44 +++-
 2 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/arch/arm/dts/fsl-ls1028a-rdb.dts b/arch/arm/dts/fsl-ls1028a-rdb.dts
index 3d5e8ade21..700fc067a4 100644
--- a/arch/arm/dts/fsl-ls1028a-rdb.dts
+++ b/arch/arm/dts/fsl-ls1028a-rdb.dts
@@ -114,9 +114,45 @@
phy-handle = <&rdb_phy0>;
 };
 
+ðsw_ports {
+   port@0 {
+   status = "okay";
+   phy-mode = "qsgmii";
+   phy-handle = <&sw_phy0>;
+   };
+   port@1 {
+   status = "okay";
+   phy-mode = "qsgmii";
+   phy-handle = <&sw_phy1>;
+   };
+   port@2 {
+   status = "okay";
+   phy-mode = "qsgmii";
+   phy-handle = <&sw_phy2>;
+   };
+   port@3 {
+   status = "okay";
+   phy-mode = "qsgmii";
+   phy-handle = <&sw_phy3>;
+   };
+};
+
 &mdio0 {
status = "okay";
rdb_phy0: phy@2 {
reg = <2>;
};
+
+   sw_phy0: phy@10 {
+   reg = <0x10>;
+   };
+   sw_phy1: phy@11 {
+   reg = <0x11>;
+   };
+   sw_phy2: phy@12 {
+   reg = <0x12>;
+   };
+   sw_phy3: phy@13 {
+   reg = <0x13>;
+   };
 };
diff --git a/arch/arm/dts/fsl-ls1028a.dtsi b/arch/arm/dts/fsl-ls1028a.dtsi
index 43a154e8e7..97c7d4de4d 100644
--- a/arch/arm/dts/fsl-ls1028a.dtsi
+++ b/arch/arm/dts/fsl-ls1028a.dtsi
@@ -136,9 +136,51 @@
reg = <0x000300 0 0 0 0>;
status = "disabled";
};
+   ethsw: pci@0,5 {
+   #address-cells=<0>;
+   #size-cells=<1>;
+   reg = <0x000500 0 0 0 0>;
+
+   ethsw_ports: ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+   status = "disabled";
+   label = "swp0";
+   };
+   port@1 {
+   reg = <1>;
+   status = "disabled";
+   label = "swp1";
+   };
+   port@2 {
+   reg = <2>;
+   status = "disabled";
+   label = "swp2";
+   };
+   port@3 {
+   reg = <3>;
+   status = "disabled";
+   label = "swp3";
+   };
+   port@4 {
+   reg = <4>;
+   phy-mode = "internal";
+   status = "okay";
+   ethernet = <&enetc2>;
+   };
+   port@5 {
+   reg = <5>;
+   phy-mode = "internal";
+   status = "disabled";
+   };
+   };
+   };
enetc6: pci@0,6 {
reg = <0x000600 0 0 0 0>;
-   status = "okay";
+   status = "disabled";
phy-mode = "internal";
};
};
-- 
2.17.1

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


[U-Boot] [PATCH v2 4/6] drivers: net: add Felix DSA switch driver

2019-11-25 Thread Alex Marginean
This driver is used for the Ethernet switch integrated into LS1028A NXP.
Felix on LS1028A has 4 front panel ports and two internal ports, I/O
to/from the switch is done through an ENETC Ethernet interface.
The 4 front panel ports are available as Ethernet interfaces and can be
used with the typical network commands like tftp.

Signed-off-by: Alex Marginean 
Tested-by: Michael Walle 
---
 drivers/net/fsl_enetc.h |   5 +
 drivers/net/mscc_eswitch/Kconfig|   8 +
 drivers/net/mscc_eswitch/Makefile   |   1 +
 drivers/net/mscc_eswitch/felix_switch.c | 454 
 4 files changed, 468 insertions(+)
 create mode 100644 drivers/net/mscc_eswitch/felix_switch.c

diff --git a/drivers/net/fsl_enetc.h b/drivers/net/fsl_enetc.h
index 9a36cdad80..29e7781b5e 100644
--- a/drivers/net/fsl_enetc.h
+++ b/drivers/net/fsl_enetc.h
@@ -200,6 +200,11 @@ struct enetc_priv {
 /* PCS replicator block for USXGMII */
 #define ENETC_PCS_DEVAD_REPL   0x1f
 
+#define ENETC_PCS_REPL_LINK_TIMER_10x12
+#define  ENETC_PCS_REPL_LINK_TIMER_1_DEF   0x0003
+#define ENETC_PCS_REPL_LINK_TIMER_20x13
+#define  ENETC_PCS_REPL_LINK_TIMER_2_DEF   0x06a0
+
 /* ENETC external MDIO registers */
 #define ENETC_MDIO_BASE0x1c00
 #define ENETC_MDIO_CFG 0x00
diff --git a/drivers/net/mscc_eswitch/Kconfig b/drivers/net/mscc_eswitch/Kconfig
index 80dd22f98b..11fb08edaa 100644
--- a/drivers/net/mscc_eswitch/Kconfig
+++ b/drivers/net/mscc_eswitch/Kconfig
@@ -36,3 +36,11 @@ config MSCC_SERVAL_SWITCH
select PHYLIB
help
  This driver supports the Serval network switch device.
+
+config MSCC_FELIX_SWITCH
+   bool "Felix switch driver"
+   depends on DM_DSA && DM_PCI
+   select FSL_ENETC
+   help
+ This driver supports the Ethernet switch integrated in LS1028A NXP
+ SoC.
diff --git a/drivers/net/mscc_eswitch/Makefile 
b/drivers/net/mscc_eswitch/Makefile
index d583fe9fc4..22342ed114 100644
--- a/drivers/net/mscc_eswitch/Makefile
+++ b/drivers/net/mscc_eswitch/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_MSCC_LUTON_SWITCH) += luton_switch.o mscc_xfer.o 
mscc_mac_table.o m
 obj-$(CONFIG_MSCC_JR2_SWITCH) += jr2_switch.o mscc_xfer.o mscc_miim.o
 obj-$(CONFIG_MSCC_SERVALT_SWITCH) += servalt_switch.o mscc_xfer.o mscc_miim.o
 obj-$(CONFIG_MSCC_SERVAL_SWITCH) += serval_switch.o mscc_xfer.o 
mscc_mac_table.o mscc_miim.o
+obj-$(CONFIG_MSCC_FELIX_SWITCH) += felix_switch.o
diff --git a/drivers/net/mscc_eswitch/felix_switch.c 
b/drivers/net/mscc_eswitch/felix_switch.c
new file mode 100644
index 00..120973bda2
--- /dev/null
+++ b/drivers/net/mscc_eswitch/felix_switch.c
@@ -0,0 +1,454 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Felix Ethernet switch driver
+ * Copyright 2018-2019 NXP
+ */
+
+/*
+ * This driver is used for the Ethernet switch integrated into LS1028A NXP.
+ * Felix switch is derived from Microsemi Ocelot but there are several NXP
+ * adaptations that makes the two U-Boot drivers largely incompatible.
+ *
+ * Felix on LS1028A has 4 front panel ports and two internal ports, connected
+ * to ENETC interfaces.  We're using one of the ENETC interfaces to push 
traffic
+ * into the switch.  Injection/extraction headers are used to identify
+ * egress/ingress ports in the switch for Tx/Rx.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* defines especially around PCS are reused from enetc */
+#include "../fsl_enetc.h"
+
+#define PCI_DEVICE_ID_FELIX_ETHSW  0xEEF0
+
+/* Felix has in fact 6 ports, but we don't use the last internal one */
+#define FELIX_PORT_COUNT   5
+/* Front panel port mask */
+#define FELIX_FP_PORT_MASK 0xf
+
+/* Register map for BAR4 */
+#define FELIX_SYS  0x01
+#define FELIX_ES0  0x04
+#define FELIX_IS1  0x05
+#define FELIX_IS2  0x06
+#define FELIX_GMII(port)   (0x10 + (port) * 0x1)
+#define FELIX_QSYS 0x20
+
+#define FELIX_SYS_SYSTEM   (FELIX_SYS + 0x0E00)
+#define  FELIX_SYS_SYSTEM_EN   BIT(0)
+#define FELIX_SYS_RAM_CTRL (FELIX_SYS + 0x0F24)
+#define  FELIX_SYS_RAM_CTRL_INIT   BIT(1)
+#define FELIX_SYS_SYSTEM_PORT_MODE(a)  (FELIX_SYS_SYSTEM + 0xC + (a) * 4)
+#define  FELIX_SYS_SYSTEM_PORT_MODE_CPU0x001e
+
+#define FELIX_ES0_TCAM_CTRL(FELIX_ES0 + 0x03C0)
+#define  FELIX_ES0_TCAM_CTRL_ENBIT(0)
+#define FELIX_IS1_TCAM_CTRL(FELIX_IS1 + 0x03C0)
+#define  FELIX_IS1_TCAM_CTRL_ENBIT(0)
+#define FELIX_IS2_TCAM_CTRL(FELIX_IS2 + 0x03C0)
+#define  FELIX_IS2_TCAM_CTRL_ENBIT(0)
+
+#define FELIX_GMII_CLOCK_CFG(port) (FELIX_GMII(port) + 0x)
+#define  FELIX_GMII_CLOCK_CFG_LINK_1G  1
+#define  FELIX_GMII_CLOCK_CFG_LINK_100M2
+#define  FELIX_GMII_CLOCK_CFG_LINK_10M 3
+#de

[U-Boot] [PATCH v2 2/6] drivers: net: add a DSA sandbox driver

2019-11-25 Thread Alex Marginean
The DSA sandbox driver is used for DSA unit testing.  It implements a
simple 4 port switch that uses a very simple tag to identify the ports.
The DSA driver comes paired with an Ethernet driver that loops packets
back and can selectively filter traffic on DSA switch ports.

Signed-off-by: Alex Marginean 
---
 drivers/net/Kconfig   |   8 ++
 drivers/net/Makefile  |   1 +
 drivers/net/dsa_sandbox.c | 272 ++
 3 files changed, 281 insertions(+)
 create mode 100644 drivers/net/dsa_sandbox.c

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index a4157cb122..ac420cb474 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -70,6 +70,14 @@ config MDIO_MUX_SANDBOX
 
  This driver is used for testing in test/dm/mdio.c
 
+config DSA_SANDBOX
+   depends on DM_DSA && SANDBOX
+   default y
+   bool "Sandbox: Mocked DSA driver"
+   help
+ This driver implements a dummy switch and a dummy Ethernet device used
+ to test DSA class code.
+
 menuconfig NETDEVICES
bool "Network device support"
depends on NET
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 30991834ec..8be49f6335 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -82,3 +82,4 @@ obj-y += mscc_eswitch/
 obj-$(CONFIG_HIGMACV300_ETH) += higmacv300.o
 obj-$(CONFIG_MDIO_SANDBOX) += mdio_sandbox.o
 obj-$(CONFIG_FSL_ENETC) += fsl_enetc.o fsl_enetc_mdio.o
+obj-$(CONFIG_DSA_SANDBOX) += dsa_sandbox.o
diff --git a/drivers/net/dsa_sandbox.c b/drivers/net/dsa_sandbox.c
new file mode 100644
index 00..07230eb033
--- /dev/null
+++ b/drivers/net/dsa_sandbox.c
@@ -0,0 +1,272 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2019 NXP
+ */
+
+#include 
+
+#define DSA_SANDBOX_MAGIC  0x00415344
+#define DSA_SANDBOX_TAG_LENsizeof(struct dsa_sandbox_tag)
+/*
+ * This global flag is used to enable DSA just for DSA test so it doesn't 
affect
+ * the existing eth unit test.
+ */
+int dsa_sandbox_port_mask;
+
+struct dsa_sandbox_priv {
+   int enabled;
+   int port_enabled;
+};
+
+struct dsa_sandbox_tag {
+   u32 magic;
+   u32 port;
+};
+
+static int dsa_sandbox_port_enable(struct udevice *dev, int port,
+  struct phy_device *phy)
+{
+   struct dsa_sandbox_priv *priv = dev->priv;
+
+   if (!priv->enabled)
+   return -EFAULT;
+
+   priv->port_enabled |= BIT(port);
+
+   return 0;
+}
+
+static void dsa_sandbox_port_disable(struct udevice *dev, int port,
+struct phy_device *phy)
+{
+   struct dsa_sandbox_priv *priv = dev->priv;
+
+   if (!priv->enabled)
+   return;
+
+   priv->port_enabled &= ~BIT(port);
+}
+
+static int dsa_sandbox_xmit(struct udevice *dev, int port, void *packet,
+   int length)
+{
+   struct dsa_sandbox_priv *priv = dev->priv;
+   struct dsa_sandbox_tag *tag = packet;
+
+   if (!priv->enabled)
+   return -EFAULT;
+
+   if (!(priv->port_enabled & BIT(port)))
+   return -EFAULT;
+
+   tag->magic = DSA_SANDBOX_MAGIC;
+   tag->port = port;
+
+   return 0;
+}
+
+static int dsa_sandbox_rcv(struct udevice *dev, int *port, void *packet,
+  int length)
+{
+   struct dsa_sandbox_priv *priv = dev->priv;
+   struct dsa_sandbox_tag *tag = packet;
+
+   if (!priv->enabled)
+   return -EFAULT;
+
+   if (tag->magic != DSA_SANDBOX_MAGIC)
+   return -EFAULT;
+
+   *port = tag->port;
+   if (!(priv->port_enabled & BIT(*port)))
+   return -EFAULT;
+
+   return 0;
+}
+
+static const struct dsa_ops dsa_sandbox_ops = {
+   .port_enable = dsa_sandbox_port_enable,
+   .port_disable = dsa_sandbox_port_disable,
+   .xmit = dsa_sandbox_xmit,
+   .rcv = dsa_sandbox_rcv,
+};
+
+static int dsa_sandbox_bind(struct udevice *dev)
+{
+   struct dsa_perdev_platdata *pdata = dev->platdata;
+
+   /* must be at least 4 to match sandbox test DT */
+   pdata->num_ports = 4;
+   pdata->headroom = DSA_SANDBOX_TAG_LEN;
+
+   return 0;
+}
+
+static int dsa_sandbox_probe(struct udevice *dev)
+{
+   struct dsa_sandbox_priv *priv = dev_get_priv(dev);
+
+   /*
+* return error if DSA is not being tested so we don't break existing
+* eth test.
+*/
+   if (!dsa_sandbox_port_mask)
+   return -EINVAL;
+
+   priv->enabled = 1;
+
+   return 0;
+}
+
+static int dsa_sandbox_remove(struct udevice *dev)
+{
+   struct dsa_sandbox_priv *priv = dev_get_priv(dev);
+
+   priv->enabled = 0;
+
+   return 0;
+}
+
+static const struct udevice_id dsa_sandbox_ids[] = {
+   { .compatible = "sandbox,dsa" },
+   { }
+};
+
+U_BOOT_DRIVER(dsa_sandbox) = {
+   .name   = "dsa_sandbox",
+   .id = UCLASS_DSA,
+   .of_match   = dsa_sandbox_ids,

  1   2   >