Re: [PATCH v2 2/2] efi_loader: identify EFI system partition

2020-04-13 Thread Heinrich Schuchardt
Am April 14, 2020 5:20:38 AM UTC schrieb AKASHI Takahiro 
:
>Heinrich,
>
>On Mon, Apr 06, 2020 at 02:31:35PM +0900, AKASHI Takahiro wrote:
>> On Mon, Apr 06, 2020 at 07:12:56AM +0200, Heinrich Schuchardt wrote:
>> > On 4/6/20 6:21 AM, AKASHI Takahiro wrote:
>> > > Heinrich,
>> > >
>> > > On Sun, Apr 05, 2020 at 11:28:18AM +0200, Heinrich Schuchardt
>wrote:
>> > >> For capsule updates we need to identify the EFI system
>partition.
>> > >
>> > > Right, but
>> > >
>> > >> Signed-off-by: Heinrich Schuchardt 
>> > >> ---
>> > >> v2:
>> > >> no change
>> > >> ---
>> > >>  include/efi_loader.h  |  7 +++
>> > >>  lib/efi_loader/efi_disk.c | 20 
>> > >>  2 files changed, 27 insertions(+)
>> > >>
>> > >> diff --git a/include/efi_loader.h b/include/efi_loader.h
>> > >> index 3f2792892f..4a45033476 100644
>> > >> --- a/include/efi_loader.h
>> > >> +++ b/include/efi_loader.h
>> > >> @@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const
>void *src)
>> > >>  /* Root node */
>> > >>  extern efi_handle_t efi_root;
>> > >>
>> > >> +/* EFI system partition */
>> > >> +extern struct efi_system_partition {
>> > >> +   enum if_type if_type;
>> > >> +   int devnum;
>> > >> +   u8 part;
>> > >> +} efi_system_partition;
>> > >> +
>> > >>  int __efi_entry_check(void);
>> > >>  int __efi_exit_check(void);
>> > >>  const char *__efi_nesting(void);
>> > >> diff --git a/lib/efi_loader/efi_disk.c
>b/lib/efi_loader/efi_disk.c
>> > >> index fc0682bc48..2f752a5e99 100644
>> > >> --- a/lib/efi_loader/efi_disk.c
>> > >> +++ b/lib/efi_loader/efi_disk.c
>> > >> @@ -13,6 +13,8 @@
>> > >>  #include 
>> > >>  #include 
>> > >>
>> > >> +struct efi_system_partition efi_system_partition;
>> > >> +
>> > >>  const efi_guid_t efi_block_io_guid =
>EFI_BLOCK_IO_PROTOCOL_GUID;
>> > >>
>> > >>  /**
>> > >> @@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev(
>> > >> diskobj->ops.media = >media;
>> > >> if (disk)
>> > >> *disk = diskobj;
>> > >> +
>> > >> +   /* Store first EFI system partition */
>> > >
>> > > I don't think that the policy, first comes first serves as system
>> > > partition, is a right decision as
>> > > - the order of device probe on U-Boot is indeterministic, and
>> > 
>> > Indeterministic would mean that on two runs with the same media
>provided
>> > you will get different results. I cannot see any source for such
>> > randomness in the U-Boot code. In dm_init_and_scan() the device
>tree is
>> > scanned and drivers and bound in the sequence of occurrence in the
>> > device tree.
>> > 
>> > > - there can be several partitions that hold a system partition
>bit.
>> > >   You may have OS installed on eMMC, but also may have bootable
>DVD
>> > >   on the system.
>> > 
>> > This is a similar logic like finding the relevant boot.scr script
>to run.
>> > 
>> > What would be the alternative?
>> 
>> I think that most UEFI systems have ability for user to specify
>> "boot order."
>
>Any comment?
>The discussion and your patch will have some impact on
>my efi capsule patch.

Concerning capsules the spec says we should use the boot device. So my patch 
doesn't help you there.

For the storage of variables I still need this patch. I will adjust the commit 
message.

Best regards

Heinrich

>
>-Takahiro Akashi
>
>> -Takahiro Akashi
>> > 
>> > Definition via Kconfig would mean that a Linux distribution like
>Debian
>> > would have to provide a separate U-Boot build for each boot medium
>that
>> > a user might possibly use (eMMC, SD-card, USB, NVME, SCSI).
>> > 
>> > Best regards
>> > 
>> > Heinrich
>> > 
>> > >
>> > > -Takahiro Akashi
>> > >
>> > >> +   if (part && !efi_system_partition.if_type) {
>> > >> +   int r;
>> > >> +   disk_partition_t info;
>> > >> +
>> > >> +   r = part_get_info(desc, part, );
>> > >> +   if (r)
>> > >> +   return EFI_DEVICE_ERROR;
>> > >> +   if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
>> > >> +   efi_system_partition.if_type = desc->if_type;
>> > >> +   efi_system_partition.devnum = desc->devnum;
>> > >> +   efi_system_partition.part = part;
>> > >> +   EFI_PRINT("EFI system partition: %s %d:%d\n",
>> > >> + blk_get_if_type_name(desc->if_type),
>> > >> + desc->devnum, part);
>> > >> +   }
>> > >> +   }
>> > >> return EFI_SUCCESS;
>> > >>  }
>> > >>
>> > >> --
>> > >> 2.25.1
>> > >>
>> > 



[PATCH v4] mmc: zynq: parse dt when probing

2020-04-13 Thread Benedikt Grassl
Currently, the entry "bus-width = <8>" in the ZynqMP's sdhci nodes
is not evaluated. This results in the bus width staying at its default
value (4 bit in HS200 mode).
Fix this by calling mmc_of_parse. This function also checks for the
"no-1-8-v" and "max-frequency" entries. Remove the handling of those
nodes from this driver.

Signed-off-by: Benedikt Grassl 
---
 drivers/mmc/sdhci.c  |  3 +--
 drivers/mmc/zynq_sdhci.c | 15 ++-
 include/sdhci.h  |  1 -
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 520c9f9feb..372dc0a820 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -839,8 +839,7 @@ int sdhci_setup_cfg(struct mmc_config *cfg, struct 
sdhci_host *host,
cfg->host_caps &= ~MMC_MODE_HS_52MHz;
}
 
-   if (!(cfg->voltages & MMC_VDD_165_195) ||
-   (host->quirks & SDHCI_QUIRK_NO_1_8_V))
+   if (!(cfg->voltages & MMC_VDD_165_195))
caps_1 &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 |
SDHCI_SUPPORT_DDR50);
 
diff --git a/drivers/mmc/zynq_sdhci.c b/drivers/mmc/zynq_sdhci.c
index da3ff53da1..18925d01fa 100644
--- a/drivers/mmc/zynq_sdhci.c
+++ b/drivers/mmc/zynq_sdhci.c
@@ -22,14 +22,12 @@ DECLARE_GLOBAL_DATA_PTR;
 struct arasan_sdhci_plat {
struct mmc_config cfg;
struct mmc mmc;
-   unsigned int f_max;
 };
 
 struct arasan_sdhci_priv {
struct sdhci_host *host;
u8 deviceid;
u8 bank;
-   u8 no_1p8;
 };
 
 #if defined(CONFIG_ARCH_ZYNQMP)
@@ -238,8 +236,11 @@ static int arasan_sdhci_probe(struct udevice *dev)
host->quirks |= SDHCI_QUIRK_BROKEN_HISPD_MODE;
 #endif
 
-   if (priv->no_1p8)
-   host->quirks |= SDHCI_QUIRK_NO_1_8_V;
+   plat->cfg.f_max = CONFIG_ZYNQ_SDHCI_MAX_FREQ;
+
+   ret = mmc_of_parse(dev, >cfg);
+   if (ret)
+   return ret;
 
host->max_clk = clock;
 
@@ -247,7 +248,7 @@ static int arasan_sdhci_probe(struct udevice *dev)
host->mmc->dev = dev;
host->mmc->priv = host;
 
-   ret = sdhci_setup_cfg(>cfg, host, plat->f_max,
+   ret = sdhci_setup_cfg(>cfg, host, plat->cfg.f_max,
  CONFIG_ZYNQ_SDHCI_MIN_FREQ);
if (ret)
return ret;
@@ -258,7 +259,6 @@ static int arasan_sdhci_probe(struct udevice *dev)
 
 static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)
 {
-   struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
struct arasan_sdhci_priv *priv = dev_get_priv(dev);
 
priv->host = calloc(1, sizeof(struct sdhci_host));
@@ -277,10 +277,7 @@ static int arasan_sdhci_ofdata_to_platdata(struct udevice 
*dev)
 
priv->deviceid = dev_read_u32_default(dev, "xlnx,device_id", -1);
priv->bank = dev_read_u32_default(dev, "xlnx,mio_bank", -1);
-   priv->no_1p8 = dev_read_bool(dev, "no-1-8-v");
 
-   plat->f_max = dev_read_u32_default(dev, "max-frequency",
-  CONFIG_ZYNQ_SDHCI_MAX_FREQ);
return 0;
 }
 
diff --git a/include/sdhci.h b/include/sdhci.h
index aa4378fd57..0ef8c2ed62 100644
--- a/include/sdhci.h
+++ b/include/sdhci.h
@@ -243,7 +243,6 @@
 #define SDHCI_QUIRK_BROKEN_HISPD_MODE  BIT(5)
 #define SDHCI_QUIRK_WAIT_SEND_CMD  (1 << 6)
 #define SDHCI_QUIRK_USE_WIDE8  (1 << 8)
-#define SDHCI_QUIRK_NO_1_8_V   (1 << 9)
 
 /* to make gcc happy */
 struct sdhci_host;
-- 
2.17.1


Re: [PATCH v2 1/2] part: detect EFI system partition

2020-04-13 Thread AKASHI Takahiro
Heinrich,

On Sun, Apr 05, 2020 at 11:28:17AM +0200, Heinrich Schuchardt wrote:
> Up to now for MBR and GPT partitions the info field 'bootable' was set to 1
> if either the partition was an EFI system partition or the bootable flag
> was set.
> 
> Turn info field 'bootable' into a bit mask with separate bits for bootable
> and EFI system partition.
> 
> This will allow us to identify the EFI system partition in the UEFI
> sub-system.
> 
> Signed-off-by: Heinrich Schuchardt 
> ---
> v2:
>   used BIT() macro to define bit mask
> ---
>  disk/part_dos.c | 10 --
>  disk/part_efi.c | 12 
>  include/part.h  | 11 ++-
>  3 files changed, 26 insertions(+), 7 deletions(-)
> 
> diff --git a/disk/part_dos.c b/disk/part_dos.c
> index 83ff40d310..0ec7f1628e 100644
> --- a/disk/part_dos.c
> +++ b/disk/part_dos.c
> @@ -45,9 +45,15 @@ static inline int is_extended(int part_type)
>   part_type == 0x85);
>  }
> 
> -static inline int is_bootable(dos_partition_t *p)
> +static int is_bootable(dos_partition_t *p)
>  {
> - return (p->sys_ind == 0xef) || (p->boot_ind == 0x80);
> + int ret = 0;
> +
> + if (p->sys_ind == 0xef)
> + ret |= PART_EFI_SYSTEM_PARTITION;
> + if (p->boot_ind == 0x80)
> + ret |= PART_BOOTABLE;
> + return ret;
>  }

The return value is no longer boolean, so the function's name
should be changed to avoid confusion. Say, get_bootable_flags()?
Then  another function, or inline function should be provided.

bool part_is_bootable(blk_desc *bdev)

for checking if the device is "bootable."

>  static void print_one_part(dos_partition_t *p, lbaint_t ext_part_sector,
> diff --git a/disk/part_efi.c b/disk/part_efi.c
> index b2e157d9c1..19f1f43f4e 100644
> --- a/disk/part_efi.c
> +++ b/disk/part_efi.c
> @@ -71,11 +71,15 @@ static char *print_efiname(gpt_entry *pte)
> 
>  static const efi_guid_t system_guid = PARTITION_SYSTEM_GUID;
> 
> -static inline int is_bootable(gpt_entry *p)
> +static int is_bootable(gpt_entry *p)
>  {
> - return p->attributes.fields.legacy_bios_bootable ||
> - !memcmp(&(p->partition_type_guid), _guid,
> - sizeof(efi_guid_t));
> + int ret = 0;
> +
> + if (!memcmp(>partition_type_guid, _guid, sizeof(efi_guid_t)))
> + ret |=  PART_EFI_SYSTEM_PARTITION;
> + if (p->attributes.fields.legacy_bios_bootable)
> + ret |=  PART_BOOTABLE;
> + return ret;
>  }

ditto, and again

bool part_is_efi_system()

-Takahiro Akashi

>  static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba,
> diff --git a/include/part.h b/include/part.h
> index 0b5cf3d5e8..f3442ef85d 100644
> --- a/include/part.h
> +++ b/include/part.h
> @@ -51,13 +51,22 @@ struct block_drvr {
>  #define PART_TYPE_LEN 32
>  #define MAX_SEARCH_PARTITIONS 64
> 
> +#define PART_BOOTABLEBIT(0)
> +#define PART_EFI_SYSTEM_PARTITIONBIT(1)
> +
>  typedef struct disk_partition {
>   lbaint_tstart;  /* # of first block in partition*/
>   lbaint_tsize;   /* number of blocks in partition*/
>   ulong   blksz;  /* block size in bytes  */
>   uchar   name[PART_NAME_LEN];/* partition name   
> */
>   uchar   type[PART_TYPE_LEN];/* string type description  
> */
> - int bootable;   /* Active/Bootable flag is set  */
> + /*
> +  * The bootable is a bitmask with the following fields:
> +  *
> +  * PART_BOOTABLEthe MBR bootable flag is set
> +  * PART_EFI_SYSTEM_PARTITIONthe partition is an EFI system partition
> +  */
> + int bootable;
>  #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
>   charuuid[UUID_STR_LEN + 1]; /* filesystem UUID as string, if exists 
> */
>  #endif
> --
> 2.25.1
> 


Re: [PATCH v2 2/2] efi_loader: identify EFI system partition

2020-04-13 Thread AKASHI Takahiro
Heinrich,

On Mon, Apr 06, 2020 at 02:31:35PM +0900, AKASHI Takahiro wrote:
> On Mon, Apr 06, 2020 at 07:12:56AM +0200, Heinrich Schuchardt wrote:
> > On 4/6/20 6:21 AM, AKASHI Takahiro wrote:
> > > Heinrich,
> > >
> > > On Sun, Apr 05, 2020 at 11:28:18AM +0200, Heinrich Schuchardt wrote:
> > >> For capsule updates we need to identify the EFI system partition.
> > >
> > > Right, but
> > >
> > >> Signed-off-by: Heinrich Schuchardt 
> > >> ---
> > >> v2:
> > >>  no change
> > >> ---
> > >>  include/efi_loader.h  |  7 +++
> > >>  lib/efi_loader/efi_disk.c | 20 
> > >>  2 files changed, 27 insertions(+)
> > >>
> > >> diff --git a/include/efi_loader.h b/include/efi_loader.h
> > >> index 3f2792892f..4a45033476 100644
> > >> --- a/include/efi_loader.h
> > >> +++ b/include/efi_loader.h
> > >> @@ -45,6 +45,13 @@ static inline void *guidcpy(void *dst, const void 
> > >> *src)
> > >>  /* Root node */
> > >>  extern efi_handle_t efi_root;
> > >>
> > >> +/* EFI system partition */
> > >> +extern struct efi_system_partition {
> > >> +enum if_type if_type;
> > >> +int devnum;
> > >> +u8 part;
> > >> +} efi_system_partition;
> > >> +
> > >>  int __efi_entry_check(void);
> > >>  int __efi_exit_check(void);
> > >>  const char *__efi_nesting(void);
> > >> diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
> > >> index fc0682bc48..2f752a5e99 100644
> > >> --- a/lib/efi_loader/efi_disk.c
> > >> +++ b/lib/efi_loader/efi_disk.c
> > >> @@ -13,6 +13,8 @@
> > >>  #include 
> > >>  #include 
> > >>
> > >> +struct efi_system_partition efi_system_partition;
> > >> +
> > >>  const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
> > >>
> > >>  /**
> > >> @@ -372,6 +374,24 @@ static efi_status_t efi_disk_add_dev(
> > >>  diskobj->ops.media = >media;
> > >>  if (disk)
> > >>  *disk = diskobj;
> > >> +
> > >> +/* Store first EFI system partition */
> > >
> > > I don't think that the policy, first comes first serves as system
> > > partition, is a right decision as
> > > - the order of device probe on U-Boot is indeterministic, and
> > 
> > Indeterministic would mean that on two runs with the same media provided
> > you will get different results. I cannot see any source for such
> > randomness in the U-Boot code. In dm_init_and_scan() the device tree is
> > scanned and drivers and bound in the sequence of occurrence in the
> > device tree.
> > 
> > > - there can be several partitions that hold a system partition bit.
> > >   You may have OS installed on eMMC, but also may have bootable DVD
> > >   on the system.
> > 
> > This is a similar logic like finding the relevant boot.scr script to run.
> > 
> > What would be the alternative?
> 
> I think that most UEFI systems have ability for user to specify
> "boot order."

Any comment?
The discussion and your patch will have some impact on
my efi capsule patch.

-Takahiro Akashi

> -Takahiro Akashi
> > 
> > Definition via Kconfig would mean that a Linux distribution like Debian
> > would have to provide a separate U-Boot build for each boot medium that
> > a user might possibly use (eMMC, SD-card, USB, NVME, SCSI).
> > 
> > Best regards
> > 
> > Heinrich
> > 
> > >
> > > -Takahiro Akashi
> > >
> > >> +if (part && !efi_system_partition.if_type) {
> > >> +int r;
> > >> +disk_partition_t info;
> > >> +
> > >> +r = part_get_info(desc, part, );
> > >> +if (r)
> > >> +return EFI_DEVICE_ERROR;
> > >> +if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
> > >> +efi_system_partition.if_type = desc->if_type;
> > >> +efi_system_partition.devnum = desc->devnum;
> > >> +efi_system_partition.part = part;
> > >> +EFI_PRINT("EFI system partition: %s %d:%d\n",
> > >> +  blk_get_if_type_name(desc->if_type),
> > >> +  desc->devnum, part);
> > >> +}
> > >> +}
> > >>  return EFI_SUCCESS;
> > >>  }
> > >>
> > >> --
> > >> 2.25.1
> > >>
> > 


[PATCH][RESEND] arm: lpc32xx: move SoC to mach-lpc32xx

2020-04-13 Thread Trevor Woerner
Following the example of most other SoCs in arch/$(ARCH)/cpu/$(CPU)/$(SOC)
move the lpc32xx code from arch/arm/cpu/arm926ejs/lpc32xx to
arch/arm/mach-lpc32xx.

Following the checklist from
commit 01f14456306c ("ARM: prepare for moving SoC sources into mach-*"):

[1] move files from arch/arm/cpu/arm926ejs/lpc32xx to arch/arm/mach-lpx32xx
[2] add machine entry to arch/arm/Makefile
[3] remove "obj-y += ..." from arch/arm/cpu/arm926ejs/Makefile
[4] fix the Kconfig file path in arch/arm/Kconfig
[5] (no MAINTAINERS update)

Signed-off-by: Trevor Woerner 
---
 arch/arm/Kconfig| 2 +-
 arch/arm/Makefile   | 1 +
 arch/arm/cpu/arm926ejs/Makefile | 1 -
 arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/Kconfig| 0
 arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/Makefile   | 0
 arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/clk.c  | 0
 arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/cpu.c  | 0
 arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/devices.c  | 0
 arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/dram.c | 0
 .../arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/lowlevel_init.S | 0
 arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/timer.c| 0
 11 files changed, 2 insertions(+), 2 deletions(-)
 rename arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/Kconfig (100%)
 rename arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/Makefile (100%)
 rename arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/clk.c (100%)
 rename arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/cpu.c (100%)
 rename arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/devices.c (100%)
 rename arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/dram.c (100%)
 rename arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/lowlevel_init.S (100%)
 rename arch/arm/{cpu/arm926ejs/lpc32xx => mach-lpc32xx}/timer.c (100%)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index bbb1e2738b..3096b97c6f 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1732,7 +1732,7 @@ source "arch/arm/mach-keystone/Kconfig"
 
 source "arch/arm/mach-kirkwood/Kconfig"
 
-source "arch/arm/cpu/arm926ejs/lpc32xx/Kconfig"
+source "arch/arm/mach-lpc32xx/Kconfig"
 
 source "arch/arm/mach-mvebu/Kconfig"
 
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index e25bb0e594..33bb8923bf 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -62,6 +62,7 @@ machine-$(CONFIG_ARCH_K3) += k3
 machine-$(CONFIG_ARCH_KEYSTONE)+= keystone
 # TODO: rename CONFIG_KIRKWOOD -> CONFIG_ARCH_KIRKWOOD
 machine-$(CONFIG_KIRKWOOD) += kirkwood
+machine-$(CONFIG_ARCH_LPC32XX) += lpc32xx
 machine-$(CONFIG_ARCH_MEDIATEK)+= mediatek
 machine-$(CONFIG_ARCH_MESON)   += meson
 machine-$(CONFIG_ARCH_MVEBU)   += mvebu
diff --git a/arch/arm/cpu/arm926ejs/Makefile b/arch/arm/cpu/arm926ejs/Makefile
index b051025bb0..af63d5cc5e 100644
--- a/arch/arm/cpu/arm926ejs/Makefile
+++ b/arch/arm/cpu/arm926ejs/Makefile
@@ -13,7 +13,6 @@ endif
 endif
 
 obj-$(CONFIG_ARMADA100) += armada100/
-obj-$(if $(filter lpc32xx,$(SOC)),y) += lpc32xx/
 obj-$(CONFIG_MX25) += mx25/
 obj-$(CONFIG_MX27) += mx27/
 obj-$(if $(filter mxs,$(SOC)),y) += mxs/
diff --git a/arch/arm/cpu/arm926ejs/lpc32xx/Kconfig 
b/arch/arm/mach-lpc32xx/Kconfig
similarity index 100%
rename from arch/arm/cpu/arm926ejs/lpc32xx/Kconfig
rename to arch/arm/mach-lpc32xx/Kconfig
diff --git a/arch/arm/cpu/arm926ejs/lpc32xx/Makefile 
b/arch/arm/mach-lpc32xx/Makefile
similarity index 100%
rename from arch/arm/cpu/arm926ejs/lpc32xx/Makefile
rename to arch/arm/mach-lpc32xx/Makefile
diff --git a/arch/arm/cpu/arm926ejs/lpc32xx/clk.c b/arch/arm/mach-lpc32xx/clk.c
similarity index 100%
rename from arch/arm/cpu/arm926ejs/lpc32xx/clk.c
rename to arch/arm/mach-lpc32xx/clk.c
diff --git a/arch/arm/cpu/arm926ejs/lpc32xx/cpu.c b/arch/arm/mach-lpc32xx/cpu.c
similarity index 100%
rename from arch/arm/cpu/arm926ejs/lpc32xx/cpu.c
rename to arch/arm/mach-lpc32xx/cpu.c
diff --git a/arch/arm/cpu/arm926ejs/lpc32xx/devices.c 
b/arch/arm/mach-lpc32xx/devices.c
similarity index 100%
rename from arch/arm/cpu/arm926ejs/lpc32xx/devices.c
rename to arch/arm/mach-lpc32xx/devices.c
diff --git a/arch/arm/cpu/arm926ejs/lpc32xx/dram.c 
b/arch/arm/mach-lpc32xx/dram.c
similarity index 100%
rename from arch/arm/cpu/arm926ejs/lpc32xx/dram.c
rename to arch/arm/mach-lpc32xx/dram.c
diff --git a/arch/arm/cpu/arm926ejs/lpc32xx/lowlevel_init.S 
b/arch/arm/mach-lpc32xx/lowlevel_init.S
similarity index 100%
rename from arch/arm/cpu/arm926ejs/lpc32xx/lowlevel_init.S
rename to arch/arm/mach-lpc32xx/lowlevel_init.S
diff --git a/arch/arm/cpu/arm926ejs/lpc32xx/timer.c 
b/arch/arm/mach-lpc32xx/timer.c
similarity index 100%
rename from arch/arm/cpu/arm926ejs/lpc32xx/timer.c
rename to arch/arm/mach-lpc32xx/timer.c
-- 
2.26.0.106.g9fadedd637



Re: [RFC 00/14] efi_loader: add capsule update support

2020-04-13 Thread AKASHI Takahiro
Heinrich,

On Tue, Mar 31, 2020 at 01:36:19PM +0900, AKASHI Takahiro wrote:
> Heinrich,
> 
> On Wed, Mar 18, 2020 at 11:04:05AM +0900, AKASHI Takahiro wrote:
> > Heinrich,
> > 
> > Thank you for your quick review.
> > 
> > On Tue, Mar 17, 2020 at 08:49:12AM +0100, Heinrich Schuchardt wrote:
> > > On 3/17/20 3:12 AM, AKASHI Takahiro wrote:
> > > > Summary
> > > > ===
> > > > 'UpdateCapsule' is one of runtime services defined in UEFI specification
> > > > and its aim is to allow a caller to pass information to the firmware.
> > > > This is mostly used to update firmware binary on devices by instructions
> > > > from OS.
> > > > 
> > > > In this patch series, all the related definitions and structures are 
> > > > given
> > > > as UEFI specification describes and basic framework for capsule support 
> > > > is
> > > > implemented. Currently supported types of capsule are
> > > >   * firmware update (Firmware Management Protocol or simply FMP)
> > > >   * variable update
> > > > 
> > > > UpdateCapsule is a runtime services function, but is, at least 
> > > > initially,
> > > > provided only before exiting boot services alike other runtime 
> > > > functions.
> > > > This is because modifying storage which may be shared with OS must be
> > > > carefully designed and there is no general assumption to do that as in
> > > > the case of [Get/]SetVariable.
> > > > Instead, any capsule can be handed over to the firmware as a file on
> > > > a specific file system. In other words, we only support "capsules on 
> > > > disk"
> > > > for now.
> > > > 
> > > > Regarding firmware update, most of functionality is provided by FMP
> > > > driver and it will be by nature system/platform-specific. So you can and
> > > > should implement FMP drivers based on your system requirements.
> > > > In this patch series, only a simple FMP driver based on FIT image for
> > > > a single region is supported.  (So it is "for reference only")
> > > > See more details in "efi_loader: capsule: add simple firmware management
> > > > protocol."
> > > > 
> > > > Regarding variable update, the implementation here is based on a draft
> > > > proposal[1] by Peter in Boot-arch ML. The specification should be 
> > > > discussed
> > > > and finalized first. So the code doesn't fully implement Peter's idea.
> > > > 
> > > > [1] 
> > > > https://lists.linaro.org/pipermail/boot-architecture/2018-October/000883.html
> > > 
> > > I do not like the idea of exposing variables as a configuration table as
> > > operating system users may start doing strange things like accessing
> > > variables via the configuration table. Why not keep the pointer to the
> > > internal storage of variable hidden in your runtime code and expose the
> > > runtime services defined in the UEFI spec?
> > > 
> > > Please, elaborate on the benefit of your approach.
> > 
> > I have already commented on your reply to my patch#11.
> > 
> > Rather, my aim of this patch is to discuss the following points:
> 
> Do you have any comments on them?

No comment?
Do you mind my posting v1 without addressing any TODO list below?
(I'm going to add some enhancement to address "timing of executing
capsule" issue in v1.)

Thanks,
-Takahiro Akashi


> > > > Issues
> > > > ==
> > > > * Timing of executing capsules-on-disk
> > > >Currently, processing a capsule is triggered only as part of
> > > >UEFI subsystem initialization. This means that, for example,
> > > >firmware update, may not take place at system booting time and
> > > >will potentially be delayed until a first call of any UEFI functions.
> 
> We, Linaro, internally discussed this issue and agreed that the current
> capsule handling should be split from UEFI initialization code,
> efi_init_obj_list(), and that both of them should be called respectively
> as early as possible in U-Boot initialization time, probably in 
> board_init_r().
> 
> We may restrict this behavior only if CAPSULE is enabled.
> 
> > 
> > and
> > 
> > > > TODO's
> > > > ==
> > > > (May or may not be addressed in future versions of this series.)
> > > > * capsule authentication
> > > > * capsule dependency (dependency expression instruction set)
> > > > * loading drivers in a capsule
> > > > * handling RESET flag in a capsule and QeuryCapsuleCaps
> > > > * full semantics of ESRT (EFI System Resource Table)
> > > > * enabling capsule API at runtime
> > > > * json capsule
> > > > * recovery from update failure
> > 
> > What functionality should be initially included in my first implementation
> > for capsule support.
> 
> Do you have any primary requirements so that you will be happy to
> accept my patch series?
> 
> -Takahiro Akashi
> 
> 
> > FYI, Sughosh is going to work on
> >   * capsule authentication
> >   * recovery from update failure (or at least, A/B partition)
> > in the coming months.
> > 
> > Thanks,
> > -Takahiro Akashi
> >   
> > 
> > 
> > > > 
> > > > 
> > > > Changes
> > > > ===
> > > > Initial release as RFC (March 17, 

Re: [PATCH] tiny-printf: Support %i

2020-04-13 Thread Tom Rini
On Tue, Apr 14, 2020 at 03:17:16AM +0200, Marek Vasut wrote:
> On 4/14/20 1:27 AM, Tom Rini wrote:
> > On Fri, Apr 10, 2020 at 08:54:49PM +0200, Marek Vasut wrote:
> > 
> >> The most basic printf("%i", value) formating string was missing,
> >> add it for the sake of convenience.
> >>
> >> Signed-off-by: Marek Vasut 
> >> Cc: Simon Glass 
> >> Cc: Stefan Roese 
> >> ---
> >>  lib/tiny-printf.c | 3 ++-
> >>  1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
> >> index 1138c7012a..8fc7e48d99 100644
> >> --- a/lib/tiny-printf.c
> >> +++ b/lib/tiny-printf.c
> >> @@ -242,6 +242,7 @@ static int _vprintf(struct printf_info *info, const 
> >> char *fmt, va_list va)
> >>goto abort;
> >>case 'u':
> >>case 'd':
> >> +  case 'i':
> >>div = 10;
> >>if (islong) {
> >>num = va_arg(va, unsigned long);
> >> @@ -251,7 +252,7 @@ static int _vprintf(struct printf_info *info, const 
> >> char *fmt, va_list va)
> >>num = va_arg(va, unsigned int);
> >>}
> >>  
> >> -  if (ch == 'd') {
> >> +  if (ch != 'u') {
> >>if (islong && (long)num < 0) {
> >>num = -(long)num;
> >>out(info, '-');
> > 
> > How much does the size change and where do we see this as a problem?
> 
> Any code which uses %i in SPL just misbehaves, e.g.
> printf("%s[%i] value=%x", __func__, __LINE__, val);
> prints function name and then incorrect value, because %i is ignored.
> This is also documented in the commit message.
> 
> U-Boot grows in size massively due to all the DM/DT bloat which is being
> forced upon everyone, but there the uncontrolled growth is apparently OK
> even if it brings no obvious improvement, rather the opposite. And yet
> here, size increase suddenly matters? Sorry, that's not right.
> 
> The code grows by 6 bytes.

Yes, it matters for _tiny-printf_ as that's where we have little to no
room for growth.  So it's just debug prints you were doing that ran in
to a problem?  Thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v7 17/17] efi_loader: add some description about UEFI secure boot

2020-04-13 Thread AKASHI Takahiro
A small text in docs/uefi/uefi.rst was added to explain how we can
configure and utilise UEFI secure boot feature on U-Boot.

Signed-off-by: AKASHI Takahiro 
Acked-by: Ilias Apalodimas 
---
 doc/uefi/uefi.rst | 77 +++
 1 file changed, 77 insertions(+)

diff --git a/doc/uefi/uefi.rst b/doc/uefi/uefi.rst
index cfe2d84a4c64..a35fbd331c1f 100644
--- a/doc/uefi/uefi.rst
+++ b/doc/uefi/uefi.rst
@@ -97,6 +97,83 @@ Below you find the output of an example session starting 
GRUB::
 
 See doc/uImage.FIT/howto.txt for an introduction to FIT images.
 
+Configuring UEFI secure boot
+
+
+UEFI specification[1] defines a secure way of executing UEFI images
+by verifying a signature (or message digest) of image with certificates.
+This feature on U-Boot is enabled with::
+
+CONFIG_UEFI_SECURE_BOOT=y
+
+To make the boot sequence safe, you need to establish a chain of trust;
+In UEFI secure boot, you can make it with the UEFI variables, "PK"
+(Platform Key), "KEK" (Key Exchange Keys), "db" (white list database)
+and "dbx" (black list database).
+
+There are many online documents that describe what UEFI secure boot is
+and how it works. Please consult some of them for details.
+
+Here is a simple example that you can follow for your initial attempt
+(Please note that the actual steps would absolutely depend on your system
+and environment.):
+
+1. Install utility commands on your host
+* openssl
+* efitools
+* sbsigntool
+
+2. Create signing keys and key database files on your host
+for PK::
+
+$ openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=TEST_PK/ \
+-keyout PK.key -out PK.crt -nodes -days 365
+$ cert-to-efi-sig-list -g ----123456789abc \
+PK.crt PK.esl;
+$ sign-efi-sig-list -c PK.crt -k PK.key PK PK.esl PK.auth
+
+for KEK::
+
+$ openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=TEST_KEK/ \
+-keyout KEK.key -out KEK.crt -nodes -days 365
+$ cert-to-efi-sig-list -g ----123456789abc \
+KEK.crt KEK.esl
+$ sign-efi-sig-list -c PK.crt -k PK.key KEK KEK.esl KEK.auth
+
+for db::
+
+$ openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=TEST_db/ \
+-keyout db.key -out db.crt -nodes -days 365
+$ cert-to-efi-sig-list -g ----123456789abc \
+db.crt db.esl
+$ sign-efi-sig-list -c KEK.crt -k KEK.key db db.esl db.auth
+
+Copy \*.auth to media, say mmc, that is accessible from U-Boot.
+
+3. Sign an image with one key in "db" on your host::
+
+$ sbsign --key db.key --cert db.crt helloworld.efi
+
+4. Install keys on your board::
+
+==> fatload mmc 0:1  PK.auth
+==> setenv -e -nv -bs -rt -at -i ,$filesize PK
+==> fatload mmc 0:1  KEK.auth
+==> setenv -e -nv -bs -rt -at -i ,$filesize KEK
+==> fatload mmc 0:1  db.auth
+==> setenv -e -nv -bs -rt -at -i ,$filesize db
+
+5. Set up boot parameters on your board::
+
+==> efidebug boot add 1 HELLO mmc 0:1 /helloworld.efi.signed ""
+
+Then your board runs that image from Boot manager (See below).
+You can also try this sequence by running Pytest, test_efi_secboot,
+on sandbox::
+
+$ cd 
+$ pytest.py test/py/tests/test_efi_secboot/test_signed.py --bd sandbox
+
 Executing the boot manager
 ~~
 
-- 
2.25.2



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

2020-04-13 Thread AKASHI Takahiro
Provide a couple of test cases for variable authentication.

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

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

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

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

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

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

diff --git a/.travis.yml b/.travis.yml
index c59bd7790b66..b08dd030ef02 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -40,6 +40,14 @@ addons:
 - clang-7
 - srecord
 - graphviz
+- coreutils
+- util-linux
+- dosfstools
+- gdisk
+- mount
+- mtools
+- openssl
+- sbsigntool
 
 install:
  # Clone uboot-test-hooks
@@ -60,10 +68,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.25.2



[PATCH v7 15/17] sandbox: add extra configurations for UEFI and related tests

2020-04-13 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 8ca17d621bbf..60fbc9a89cc7 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -27,6 +27,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
@@ -53,6 +54,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
@@ -203,6 +205,7 @@ CONFIG_RSA_VERIFY_WITH_PKEY=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 cc90f0006e24..72e1de3086ee 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -31,6 +31,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
@@ -62,6 +63,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
@@ -229,6 +231,7 @@ CONFIG_RSA_VERIFY_WITH_PKEY=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.25.2



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

2020-04-13 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 | 117 +
 .../tests/test_efi_secboot/test_unsigned.py   | 121 ++
 2 files changed, 238 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 ..584282b338bc
--- /dev/null
+++ b/test/py/tests/test_efi_secboot/test_signed.py
@@ -0,0 +1,117 @@
+# 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)))
+output = u_boot_console.run_command_list([
+'efidebug boot next 2',
+'efidebug test bootmgr'])
+assert(re.search('efi_start_image[(][)] returned: 26',
+''.join(output)))
+assert(not re.search('Hello, world!', ''.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)))

[PATCH v7 11/17] cmd: efidebug: add "test bootmgr" sub-command

2020-04-13 Thread AKASHI Takahiro
This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

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

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index bb7c13d6a1ce..9769aeeac58b 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -1087,6 +1087,78 @@ static int do_efi_boot_opt(cmd_tbl_t *cmdtp, int flag,
return cp->cmd(cmdtp, flag, argc, argv);
 }
 
+/**
+ * do_efi_test_bootmgr() - run simple bootmgr for test
+ *
+ * @cmdtp: Command table
+ * @flag:  Command flag
+ * @argc:  Number of arguments
+ * @argv:  Argument array
+ * Return: CMD_RET_SUCCESS on success,
+ * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
+ *
+ * Implement efidebug "test bootmgr" sub-command.
+ * Run simple bootmgr for test.
+ *
+ * efidebug test bootmgr
+ */
+static int do_efi_test_bootmgr(cmd_tbl_t *cmdtp, int flag,
+  int argc, char * const argv[])
+{
+   efi_handle_t image;
+   efi_uintn_t exit_data_size = 0;
+   u16 *exit_data = NULL;
+   efi_status_t ret;
+
+   ret = efi_bootmgr_load();
+   printf("efi_bootmgr_load() returned: %ld\n", ret & ~EFI_ERROR_MASK);
+
+   /* We call efi_start_image() even if error for test purpose. */
+   ret = EFI_CALL(efi_start_image(image, _data_size, _data));
+   printf("efi_start_image() returned: %ld\n", ret & ~EFI_ERROR_MASK);
+   if (ret && exit_data)
+   efi_free_pool(exit_data);
+
+   efi_restore_gd();
+
+   return CMD_RET_SUCCESS;
+}
+
+static cmd_tbl_t cmd_efidebug_test_sub[] = {
+   U_BOOT_CMD_MKENT(bootmgr, CONFIG_SYS_MAXARGS, 1, do_efi_test_bootmgr,
+"", ""),
+};
+
+/**
+ * do_efi_test() - manage UEFI load options
+ *
+ * @cmdtp: Command table
+ * @flag:  Command flag
+ * @argc:  Number of arguments
+ * @argv:  Argument array
+ * Return: CMD_RET_SUCCESS on success,
+ * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure
+ *
+ * Implement efidebug "test" sub-command.
+ */
+static int do_efi_test(cmd_tbl_t *cmdtp, int flag,
+  int argc, char * const argv[])
+{
+   cmd_tbl_t *cp;
+
+   if (argc < 2)
+   return CMD_RET_USAGE;
+
+   argc--; argv++;
+
+   cp = find_cmd_tbl(argv[0], cmd_efidebug_test_sub,
+ ARRAY_SIZE(cmd_efidebug_test_sub));
+   if (!cp)
+   return CMD_RET_USAGE;
+
+   return cp->cmd(cmdtp, flag, argc, argv);
+}
+
 static cmd_tbl_t cmd_efidebug_sub[] = {
U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""),
U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices,
@@ -1101,6 +1173,8 @@ static cmd_tbl_t cmd_efidebug_sub[] = {
 "", ""),
U_BOOT_CMD_MKENT(tables, CONFIG_SYS_MAXARGS, 1, do_efi_show_tables,
 "", ""),
+   U_BOOT_CMD_MKENT(test, CONFIG_SYS_MAXARGS, 1, do_efi_test,
+"", ""),
 };
 
 /**
@@ -1170,7 +1244,9 @@ static char efidebug_help_text[] =
"efidebug memmap\n"
"  - show UEFI memory map\n"
"efidebug tables\n"
-   "  - show UEFI configuration tables\n";
+   "  - show UEFI configuration tables\n"
+   "efidebug test bootmgr\n"
+   "  - run simple bootmgr for test\n";
 #endif
 
 U_BOOT_CMD(
-- 
2.25.2



[PATCH v7 12/17] efi_loader, pytest: set up secure boot environment

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

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

Signed-off-by: AKASHI Takahiro 
---
 test/py/README.md  |   8 ++
 test/py/tests/test_efi_secboot/conftest.py | 151 +
 test/py/tests/test_efi_secboot/defs.py |  21 +++
 3 files changed, 180 insertions(+)
 create mode 100644 test/py/tests/test_efi_secboot/conftest.py
 create mode 100644 test/py/tests/test_efi_secboot/defs.py

diff --git a/test/py/README.md b/test/py/README.md
index 3cbe01b73e28..aa8a5607b064 100644
--- a/test/py/README.md
+++ b/test/py/README.md
@@ -37,7 +37,15 @@ will be required.  The following is an incomplete list:
 | openssl|
 | sudo OR guestmount |
 | e2fsprogs  |
+| util-linux |
+| coreutils  |
 | dosfstools |
+| efitools   |
+| mount  |
+| mtools |
+| sbsigntool |
+| udisks2|
+
 
 Please use the apporirate commands for your distribution to match these tools
 up with the package that provides them.
diff --git a/test/py/tests/test_efi_secboot/conftest.py 
b/test/py/tests/test_efi_secboot/conftest.py
new file mode 100644
index ..e542fef6e819
--- /dev/null
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -0,0 +1,151 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2019, Linaro Limited
+# Author: AKASHI Takahiro 
+
+import os
+import os.path
+import pytest
+import re
+from subprocess import call, check_call, check_output, CalledProcessError
+from defs import *
+
+# from test/py/conftest.py
+def tool_is_in_path(tool):
+for path in os.environ["PATH"].split(os.pathsep):
+fn = os.path.join(path, tool)
+if os.path.isfile(fn) and os.access(fn, os.X_OK):
+return True
+return False
+
+#
+# Fixture for UEFI secure boot test
+#
+@pytest.fixture(scope='session')
+def efi_boot_env(request, u_boot_config):
+"""Set up a file system to be used in UEFI secure boot test.
+
+Args:
+request: Pytest request object.
+   u_boot_config: U-boot configuration.
+
+Return:
+A path to disk image to be used for testing
+"""
+global HELLO_PATH
+
+image_path = u_boot_config.persistent_data_dir
+image_path = image_path + '/' + EFI_SECBOOT_IMAGE_NAME
+image_size = EFI_SECBOOT_IMAGE_SIZE
+part_size = EFI_SECBOOT_PART_SIZE
+fs_type = EFI_SECBOOT_FS_TYPE
+
+if HELLO_PATH == '':
+HELLO_PATH = u_boot_config.build_dir + '/lib/efi_loader/helloworld.efi'
+
+try:
+non_root = tool_is_in_path('udisksctl')
+
+# create a disk/partition
+check_call('dd if=/dev/zero of=%s bs=1MiB count=%d'
+% (image_path, image_size), shell=True)
+check_call('sgdisk %s -n 1:0:+%dMiB'
+% (image_path, part_size), shell=True)
+# create a file system
+check_call('dd if=/dev/zero of=%s.tmp bs=1MiB count=%d'
+% (image_path, part_size), shell=True)
+check_call('mkfs -t %s %s.tmp' % (fs_type, image_path), shell=True)
+check_call('dd if=%s.tmp of=%s bs=1MiB seek=1 count=%d conv=notrunc'
+% (image_path, image_path, 1), shell=True)
+check_call('rm %s.tmp' % image_path, shell=True)
+if non_root:
+out_data = check_output('udisksctl loop-setup -f %s -o %d'
+% (image_path, 1048576), shell=True).decode()
+m = re.search('(?<= as )(.*)\.', out_data)
+loop_dev = m.group(1)
+# print 'loop device is: %s' % loop_dev
+out_data = check_output('udisksctl info -b %s'
+% loop_dev, shell=True).decode()
+m = re.search('MountPoints:[ \t]+(.*)', out_data)
+mnt_point = m.group(1)
+else:
+loop_dev = check_output('sudo losetup -o 1MiB --sizelimit %dMiB 
--show -f %s | tr -d "\n"'
+% (part_size, image_path), shell=True).decode()
+mnt_point = '/mnt'
+check_output('sudo mount -t %s -o umask=000 %s %s'
+% (fs_type, loop_dev, mnt_point), shell=True)
+
+# print 'mount point is: %s' % mnt_point
+
+# suffix
+# *.key: RSA private key in PEM
+# *.crt: X509 certificate (self-signed) in PEM
+# *.esl: signature list
+# *.hash: message digest of image as signature list
+# *.auth: signed signature list in signature database format
+# *.efi: UEFI image
+# *.efi.signed: signed UEFI image
+
+# Create signature database
+## PK
+check_call('cd %s; openssl req -x509 -sha256 -newkey rsa:2048 -subj 
/CN=TEST_PK/ 

[PATCH v7 08/17] efi_loader: set up secure boot

2020-04-13 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 b458093dfbd5..1b648c84673a 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -82,6 +82,39 @@ out:
return ret;
 }
 
+#ifdef CONFIG_EFI_SECURE_BOOT
+/**
+ * efi_init_secure_boot - initialize secure boot state
+ *
+ * Return: EFI_SUCCESS on success, status code (negative) on error
+ */
+static efi_status_t efi_init_secure_boot(void)
+{
+   efi_guid_t signature_types[] = {
+   EFI_CERT_SHA256_GUID,
+   EFI_CERT_X509_GUID,
+   };
+   efi_status_t ret;
+
+   /* TODO: read-only */
+   ret = EFI_CALL(efi_set_variable(L"SignatureSupport",
+   _global_variable_guid,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS
+| EFI_VARIABLE_RUNTIME_ACCESS,
+   sizeof(signature_types),
+   _types));
+   if (ret != EFI_SUCCESS)
+   printf("EFI: cannot initialize SignatureSupport variable\n");
+
+   return ret;
+}
+#else
+static efi_status_t efi_init_secure_boot(void)
+{
+   return EFI_SUCCESS;
+}
+#endif /* CONFIG_EFI_SECURE_BOOT */
+
 /**
  * efi_init_obj_list() - Initialize and populate EFI object list
  *
@@ -127,6 +160,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.25.2



[PATCH v7 09/17] cmd: env: use appropriate guid for authenticated UEFI variable

2020-04-13 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.25.2



[PATCH v7 10/17] cmd: env: add "-at" option to "env set -e" command

2020-04-13 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 81d94cd193c6..966c13405956 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -1417,7 +1417,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";
@@ -1479,13 +1479,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.25.2



[PATCH v7 07/17] efi_loader: image_loader: support image authentication

2020-04-13 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  |  13 +-
 lib/efi_loader/efi_boottime.c |  10 +-
 lib/efi_loader/efi_image_loader.c | 462 +-
 3 files changed, 469 insertions(+), 16 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index ef8d184a6ee7..0ba9a1f702a6 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)
 {
@@ -263,6 +264,11 @@ struct efi_object {
enum efi_object_type type;
 };
 
+enum efi_image_auth_status {
+   EFI_IMAGE_AUTH_FAILED = 0,
+   EFI_IMAGE_AUTH_PASSED,
+};
+
 /**
  * struct efi_loaded_image_obj - handle of a loaded image
  *
@@ -282,6 +288,7 @@ struct efi_loaded_image_obj {
EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,
 struct efi_system_table *st);
u16 image_type;
+   enum efi_image_auth_status auth_status;
 };
 
 /**
@@ -415,7 +422,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);
@@ -756,6 +764,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 3b79a88a480f..a3f11eaf6228 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -1882,12 +1882,12 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy,
efi_dp_split_file_path(file_path, , );
ret = efi_setup_loaded_image(dp, fp, image_obj, );
if (ret == EFI_SUCCESS)
-   ret = efi_load_pe(*image_obj, dest_buffer, info);
+   ret = efi_load_pe(*image_obj, dest_buffer, source_size, info);
if (!source_buffer)
/* Release buffer to which file was loaded */
efi_free_pages((uintptr_t)dest_buffer,
   efi_size_in_pages(source_size));
-   if (ret == EFI_SUCCESS) {
+   if (ret == EFI_SUCCESS || ret == EFI_SECURITY_VIOLATION) {
info->system_table = 
info->parent_handle = parent_image;
} else {
@@ -2885,10 +2885,16 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t 
image_handle,
 
EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
 
+   if (!efi_search_obj(image_handle))
+   return EFI_EXIT(EFI_INVALID_PARAMETER);
+
/* Check parameters */
if (image_obj->header.type != EFI_OBJECT_TYPE_LOADED_IMAGE)
return EFI_EXIT(EFI_INVALID_PARAMETER);
 
+   if (image_obj->auth_status != EFI_IMAGE_AUTH_PASSED)
+   return EFI_EXIT(EFI_SECURITY_VIOLATION);
+
ret = EFI_CALL(efi_open_protocol(image_handle, _guid_loaded_image,
 , NULL, NULL,
 EFI_OPEN_PROTOCOL_GET_PROTOCOL));
diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index d5de6df16d84..6c270ce94f44 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -10,7 +10,10 @@
 #include 
 #include 
 #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;
@@ -206,6 +209,386 @@ static 

[PATCH v7 05/17] efi_loader: variable: add secure boot state transition

2020-04-13 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 adb78470f2d6..fd5c41f830b1 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -16,8 +16,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)
 
@@ -160,6 +168,210 @@ static const char *parse_attr(const char *str, u32 
*attrp, u64 *timep)
return str;
 }
 
+static efi_status_t efi_set_variable_internal(u16 *variable_name,
+ const efi_guid_t *vendor,
+ u32 attributes,
+ efi_uintn_t data_size,
+ const void *data,
+ bool ro_check);
+
+/**
+ * efi_transfer_secure_state - handle a secure boot state transition
+ * @mode:  new state
+ *
+ * Depending on @mode, secure boot related variables are updated.
+ * Those variables are *read-only* for users, efi_set_variable_internal()
+ * is called here.
+ *
+ * Return: EFI_SUCCESS on success, status code (negative) on error
+ */
+static efi_status_t efi_transfer_secure_state(enum efi_secure_mode mode)
+{
+   u32 attributes;
+   u8 val;
+   efi_status_t ret;
+
+   debug("Secure state from %d to %d\n", efi_secure_mode, mode);
+
+   attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
+EFI_VARIABLE_RUNTIME_ACCESS;
+   if (mode == EFI_MODE_DEPLOYED) {
+   val = 1;
+   ret = efi_set_variable_internal(L"SecureBoot",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+   sizeof(val), ,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+   val = 0;
+   ret = efi_set_variable_internal(L"SetupMode",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+   sizeof(val), ,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+   val = 0;
+   ret = efi_set_variable_internal(L"AuditMode",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+   sizeof(val), ,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+   val = 1;
+   ret = efi_set_variable_internal(L"DeployedMode",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+   sizeof(val), ,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+
+   efi_secure_boot = true;
+   } else if (mode == EFI_MODE_AUDIT) {
+   ret = efi_set_variable_internal(L"PK",
+   _global_variable_guid,
+   attributes,
+   0, NULL,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+   val = 0;
+   ret = efi_set_variable_internal(L"SecureBoot",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+   sizeof(val), ,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+   val = 1;
+   ret = efi_set_variable_internal(L"SetupMode",
+   _global_variable_guid,
+   attributes | READ_ONLY,
+  

[PATCH v7 02/17] efi_loader: add signature verification functions

2020-04-13 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 | 583 +
 4 files changed, 743 insertions(+)
 create mode 100644 lib/efi_loader/efi_signature.c

diff --git a/include/efi_api.h b/include/efi_api.h
index 1c40ffc4f56c..77d6bf2660b9 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -18,6 +18,7 @@
 
 #include 
 #include 
+#include 
 
 #ifdef CONFIG_EFI_LOADER
 #include 
@@ -329,6 +330,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)
@@ -1682,4 +1687,86 @@ struct efi_load_file_protocol {
 #define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL_VENDOR_RANGE_MIN 0x1000
 #define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL_VENDOR_RANGE_MAX 0x4000
 
+/* 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 3f2792892f34..8cf85d2fb7e2 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -26,6 +26,7 @@ static inline void *guidcpy(void *dst, const void *src)
 #if CONFIG_IS_ENABLED(EFI_LOADER)
 
 #include 
+#include 
 
 /* Maximum number of configuration tables */
 #define EFI_MAX_CONFIGURATION_TABLES 16
@@ -178,6 +179,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 

[PATCH v7 04/17] efi_loader: variable: support variable authentication

2020-04-13 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 | 666 --
 2 files changed, 565 insertions(+), 104 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index fea2ead02e93..ef8d184a6ee7 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -184,6 +184,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;
 
 /* GUID of RNG protocol */
 extern const efi_guid_t efi_guid_rng_protocol;
@@ -753,6 +754,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 fe2f26459136..adb78470f2d6 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -10,8 +10,14 @@
 #include 
 #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)
 
@@ -106,9 +112,10 @@ static const char *prefix(const char *str, const char 
*prefix)
  *
  * @str:   value of U-Boot variable
  * @attrp: pointer to UEFI attributes
+ * @timep: pointer to time attribute
  * 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 = '{';
@@ -131,6 +138,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;
@@ -148,48 +161,291 @@ static const char *parse_attr(const char *str, u32 
*attrp)
 }
 
 /**
- * efi_get_variable() - retrieve value of a UEFI variable
+ * efi_secure_boot_enabled - return if secure boot is enabled or not
  *
- * This function implements the GetVariable runtime service.
+ * Return: true if enabled, false if disabled
+ */
+bool efi_secure_boot_enabled(void)
+{
+   return efi_secure_boot;
+}
+
+#ifdef CONFIG_EFI_SECURE_BOOT
+static u8 pkcs7_hdr[] = {
+   /* SEQUENCE */
+   0x30, 0x82, 0x05, 0xc7,
+   /* OID: pkcs7-signedData */
+   0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02,
+   /* Context Structured? */
+   0xa0, 0x82, 0x05, 0xb8,
+};
+
+/**
+ * efi_variable_parse_signature - parse a signature in variable
+ * @buf:   Pointer to variable's value
+ * @buflen:Length of @buf
  *
- * See the Unified Extensible Firmware Interface (UEFI) specification for
- * details.
+ * Parse a signature embedded in variable's value and instantiate
+ * a pkcs7_message structure. Since pkcs7_parse_message() accepts only
+ * pkcs7's signedData, some header needed be prepended for correctly
+ * parsing authentication data, particularly for variable's.
  *
- * @variable_name: name of the variable
- * @vendor:vendor GUID
- * @attributes:attributes of the variable
- * @data_size: size of the buffer to which the variable value is copied
- * @data:  buffer to which the variable value is copied
- * Return: status code
+ * Return: Pointer to pkcs7_message structure on success, NULL on error
  */
-efi_status_t EFIAPI efi_get_variable(u16 *variable_name,
- 

[PATCH v7 03/17] efi_loader: add signature database parser

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

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

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

[PATCH v7 06/17] efi_loader: variable: add VendorKeys variable

2020-04-13 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 fd5c41f830b1..7df881a74b44 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -26,6 +26,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)
 
@@ -344,6 +345,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:
@@ -359,16 +362,46 @@ err:
  */
 static efi_status_t efi_init_secure_state(void)
 {
-   efi_uintn_t size = 0;
+   enum efi_secure_mode mode;
+   efi_uintn_t size;
efi_status_t ret;
 
+   /*
+* TODO:
+* Since there is currently no "platform-specific" installation
+* method of Platform Key, we can't say if VendorKeys is 0 or 1
+* precisely.
+*/
+
+   size = 0;
ret = EFI_CALL(efi_get_variable(L"PK", _global_variable_guid,
NULL, , NULL));
-   if (ret == EFI_BUFFER_TOO_SMALL && IS_ENABLED(CONFIG_EFI_SECURE_BOOT))
-   ret = efi_transfer_secure_state(EFI_MODE_USER);
-   else
-   ret = efi_transfer_secure_state(EFI_MODE_SETUP);
+   if (ret == EFI_BUFFER_TOO_SMALL) {
+   if (IS_ENABLED(CONFIG_EFI_SECURE_BOOT))
+   mode = EFI_MODE_USER;
+   else
+   mode = EFI_MODE_SETUP;
+
+   efi_vendor_keys = 0;
+   } else if (ret == EFI_NOT_FOUND) {
+   mode = EFI_MODE_SETUP;
+   efi_vendor_keys = 1;
+   } else {
+   goto err;
+   }
 
+   ret = efi_transfer_secure_state(mode);
+   if (ret == EFI_SUCCESS)
+   ret = efi_set_variable_internal(L"VendorKeys",
+   _global_variable_guid,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS
+| EFI_VARIABLE_RUNTIME_ACCESS
+| READ_ONLY,
+   sizeof(efi_vendor_keys),
+   _vendor_keys,
+   false);
+
+err:
return ret;
 }
 
@@ -1125,6 +1158,8 @@ out:
if (env_set(native_name, val)) {
ret = EFI_DEVICE_ERROR;
} else {
+   bool vendor_keys_modified = false;
+
if ((u16_strcmp(variable_name, L"PK") == 0 &&
 guidcmp(vendor, _global_variable_guid) == 0)) {
ret = efi_transfer_secure_state(
@@ -1132,8 +1167,30 @@ out:
  EFI_MODE_USER));
if (ret != EFI_SUCCESS)
goto err;
+
+   if (efi_secure_mode != EFI_MODE_SETUP)
+   vendor_keys_modified = true;
+   } else if ((u16_strcmp(variable_name, L"KEK") == 0 &&
+guidcmp(vendor, _global_variable_guid) == 0)) {
+   if (efi_secure_mode != EFI_MODE_SETUP)
+   vendor_keys_modified = true;
+   }
+
+   /* update VendorKeys */
+   if (vendor_keys_modified & efi_vendor_keys) {
+   efi_vendor_keys = 0;
+   ret = efi_set_variable_internal(
+   L"VendorKeys",
+   _global_variable_guid,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS
+| EFI_VARIABLE_RUNTIME_ACCESS
+| READ_ONLY,
+   sizeof(efi_vendor_keys),
+   _vendor_keys,
+   false);
+   } else {
+   ret = EFI_SUCCESS;
}
-   ret = EFI_SUCCESS;
}
 
 err:
-- 
2.25.2



[PATCH v7 00/17] efi_loader: add secure boot support

2020-04-13 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.)

This patch set requires one prerequisite[2]. For complete workable cod,
see my repository[3].

My "non-volatile" support[4], 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.
Anyhow, Linaro is also working on implementing real "secure storage"
solution based on TF-A and OP-TEE.


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

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

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

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

Known issues:
* efitools is used in pytest, and its version must be v1.5.2 or later.
  (Solution: You can define EFITOOLS_PATH in defs.py for your own efitools.)


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/2020-January/398057.html
(extend rsa_verify() for UEFI secure boot)
[3] http://git.linaro.org/people/takahiro.akashi/u-boot.git/ efi/secboot
[4] https://lists.denx.de/pipermail/u-boot/2019-September/382835.html
(non-volatile variables support)
[5] https://bugzilla.tianocore.org/show_bug.cgi?id=2230
[6] https://lists.denx.de/pipermail/u-boot/2020-February/399446.html


Changes in v7 (Apr 14, 2020)
* fix a usage of qsort() in efi_image_parse() (patch#7)
* merge my document patch[6] (patch#17)

Changes in v6 (Feb 26, 2020)
* fix 'make htmldocs' warnings (patch#4,#7)
* refactor efi_load_pe() to avoid test_efi_fit.py error (patch#7)
* fix pytest warnings (patch#14)

Changes in v5 (Jan 28, 2020)
* rebased to pre-v2020.04-rc1 (fixed some merge conflicts)
* remove already-merged commits (v4's patch#1)
* fix a compile error caused by gcc 9.x (patch#4)
* return SECURITY_VIOLATION instead of ACCESS_DENIED if authentication fails
  (patch#7)
* use qsort() for section sorting (patch#7)
* add "efidebug test" sub-command (patch#11)
* add efi_start_image(SECURITY_VIOLATION) test (patch#14)

Changes in v4 (Dec 18, 2019)
* adjust EFI_SECURE_BOOT dependencies due to a change of RSA extension patch v5
  (patch#2)
* change "imply" to "select" against kconfig dependencies (patch#2)
* otherwise, no functional changes

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

Changes in v2 (Nov 26, 2019)
* rebased to v2020.01-rc3
* rename IMAGE_DIRECTORY_ENTRY_CERTTABLE to IMAGE_DIRECTORY_ENTRY_SECURITY
  (patch#1,#9)
* add comments (patch#1)
* drop v1's patch#2 as it is no longer necessary
* drop v1's patch#3 as other "SECURE_BOOT" architectures have renamed
  this option and no longer use it
* add structure descriptions (patch#3)
* rework hash calculation code in efi_signature_verify() 

[PATCH v7 01/17] efi_loader: add CONFIG_EFI_SECURE_BOOT config option

2020-04-13 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 | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 9890144d4161..71a0d003c914 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -145,4 +145,22 @@ config EFI_INITRD_FILESPEC
help
  Full path of the initramfs file, e.g. mmc 0:2 initramfs.cpio.gz.
 
+config EFI_SECURE_BOOT
+   bool "Enable EFI secure boot support"
+   depends on EFI_LOADER
+   select SHA256
+   select RSA
+   select RSA_VERIFY_WITH_PKEY
+   select IMAGE_SIGN_INFO
+   select ASYMMETRIC_KEY_TYPE
+   select ASYMMETRIC_PUBLIC_KEY_SUBTYPE
+   select X509_CERTIFICATE_PARSER
+   select PKCS7_MESSAGE_PARSER
+   default n
+   help
+ Select this option to enable EFI secure boot support.
+ Once SecureBoot mode is enforced, any EFI binary can run only if
+ it is signed with a trusted key. To do that, you need to install,
+ at least, PK, KEK and db.
+
 endif
-- 
2.25.2



Re: [PATCH] tiny-printf: Support %i

2020-04-13 Thread Simon Glass
Hi Marek,

On Mon, 13 Apr 2020 at 19:18, Marek Vasut  wrote:
>
> On 4/14/20 1:27 AM, Tom Rini wrote:
> > On Fri, Apr 10, 2020 at 08:54:49PM +0200, Marek Vasut wrote:
> >
> >> The most basic printf("%i", value) formating string was missing,
> >> add it for the sake of convenience.
> >>
> >> Signed-off-by: Marek Vasut 
> >> Cc: Simon Glass 
> >> Cc: Stefan Roese 
> >> ---
> >>  lib/tiny-printf.c | 3 ++-
> >>  1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
> >> index 1138c7012a..8fc7e48d99 100644
> >> --- a/lib/tiny-printf.c
> >> +++ b/lib/tiny-printf.c
> >> @@ -242,6 +242,7 @@ static int _vprintf(struct printf_info *info, const 
> >> char *fmt, va_list va)
> >>  goto abort;
> >>  case 'u':
> >>  case 'd':
> >> +case 'i':
> >>  div = 10;
> >>  if (islong) {
> >>  num = va_arg(va, unsigned long);
> >> @@ -251,7 +252,7 @@ static int _vprintf(struct printf_info *info, const 
> >> char *fmt, va_list va)
> >>  num = va_arg(va, unsigned int);
> >>  }
> >>
> >> -if (ch == 'd') {
> >> +if (ch != 'u') {
> >>  if (islong && (long)num < 0) {
> >>  num = -(long)num;
> >>  out(info, '-');
> >
> > How much does the size change and where do we see this as a problem?
>
> Any code which uses %i in SPL just misbehaves, e.g.
> printf("%s[%i] value=%x", __func__, __LINE__, val);
> prints function name and then incorrect value, because %i is ignored.
> This is also documented in the commit message.
>
> U-Boot grows in size massively due to all the DM/DT bloat which is being
> forced upon everyone, but there the uncontrolled growth is apparently OK
> even if it brings no obvious improvement, rather the opposite. And yet
> here, size increase suddenly matters? Sorry, that's not right.
>
> The code grows by 6 bytes.

This is not an issue of code size. It is simply that we have a lot of
untested code, and we all need to club together to fix that.

Re DM/DT, if you have thoughts on how to improve it, please let me
know. I am very concerned about it also.

If some of the most senior maintainers in U-Boot are so opposed to
adding tests with new code, how do we expect others to make the
effort? Marek, you were one of the most vocal advocates of a longer
release cycle because you were seeing lots of breakage that
maintainers didn't have time to find. How do I square that with the
avoidance of adding tests?

Regards,
Simon


Re: [PATCH 1/1] imx: Kconfig: fix references to doc/README.mxc_hab

2020-04-13 Thread Heinrich Schuchardt
On 4/14/20 3:28 AM, Breno Matheus Lima wrote:
> Hi Heinrich,
>
> Em seg., 13 de abr. de 2020 às 11:04, Heinrich Schuchardt
>  escreveu:
>>
>> Am April 13, 2020 2:49:00 PM UTC schrieb Breno Matheus Lima 
>> :
>>> Hi Heinrich,
>>>
>>> Em dom., 12 de abr. de 2020 às 17:35, Heinrich Schuchardt
>>>  escreveu:

 On 4/12/20 6:16 PM, Fabio Estevam wrote:
> Hi Heinrich,
>
> On Sun, Apr 12, 2020 at 11:23 AM Heinrich Schuchardt
>>>  wrote:
>>
>> doc/README.mxc_hab was moved to
>>> doc/imx/habv4/guides/encrypted_boot.txt by
>> commit df11b0c4d4e3 ("doc: imx: reorganize i.MX documentation"),
>>> commit
>> dfe9ff9cc79b ("doc: imx: hab: Reorganize High Assurance Boot
>> documentation"), commit 8a23fc9c94bf ("doc: imx: habv4: Remove
>>> extra hab,
>> directory for a cleaner documentation structure"), and commit
>>> 364c0a89bcfa
>> ("doc: imx: habv4: Move encrypted boot guide").
>>
>> Fixes: df11b0c4d4e3 ("doc: imx: reorganize i.MX documentation")
>> Fixes: dfe9ff9cc79b ("doc: imx: hab: Reorganize High Assurance
>>> Boot
>> documentation")
>> Fixes: 8a23fc9c94bf ("doc: imx: habv4: Remove extra hab, directory
>> for a cleaner documentation structure")
>> Fixes: commit 364c0a89bcfa ("doc: imx: habv4: Move encrypted boot
>>> guide").
>> Signed-off-by: Heinrich Schuchardt 
>> ---
>>  arch/arm/mach-imx/Kconfig | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
>> index aa140c4798..44b47780ee 100644
>> --- a/arch/arm/mach-imx/Kconfig
>> +++ b/arch/arm/mach-imx/Kconfig
>> @@ -41,7 +41,7 @@ config IMX_HAB
>> imply CMD_DEKBLOB
>> help
>>   This option enables the support for secure boot (HAB).
>> - See doc/README.mxc_hab for more details.
>> + See doc/imx/habv4/guides/encrypted_boot.txt for more
>>> details.
>
> Thanks for your patch.
>
> Indeed, doc/README.mxc_hab is gone and we should replace it, but I
>>> was
> wondering if we should point the file to
> doc/imx/habv4/guides/mx6_mx7_secure_boot.txt instead.
>
> Breno,
>
> What do you think?

 It is doc/imx/habv4/guides/encrypted_boot.txt that mentions
 CONFIG_IMX_HAB and CONFIG_CMD_DEKBLOB.

 Maybe both files can be merged. Anyway the imx directory should move
>>> to
 doc/board and be integrated into doc/board/index.rst.

 Shouldn't the content of folder doc/imx be moved to
>>> doc/board/freescale/
 and linked in doc/board/freescale/index.rst?

 We should be able to generate HTML documentation for imx using 'make
 htmldocs'.
>>>
>>> Thanks for your feedback.
>>>
>>> Do you think we can convert this documentation to sphinx format and
>>> create an index.rst at doc/imx/? The HABv4 documentation is SoC
>>> specific and not board related.
>>
>> Maybe besides an arch and a board folder we should have a doc/soc/ folder.
>>
>
> Thanks for your suggestion, do we have similar documentation for other SoCs?
>
> Please take a look in commit df11b0c4 ("doc: imx: reorganize i.MX
> documentation") all i.MX documentation that were located at U-Boot doc
> root directory.

df11b0c4 was a good step forward.

doc/mvebu/armada-8k-memory.txt
seems to be another SoC related file.

A lot of other SoC files are at doc/README.*.

Overall the doc/ directory is not in a good state yet. Many documents
are not yet integrated into the generated documentation.

Best regards

Heinrich

>
> Thanks,
> Breno Lima
>



Re: [PATCH 1/1] imx: Kconfig: fix references to doc/README.mxc_hab

2020-04-13 Thread Breno Matheus Lima
Hi Heinrich,

Em seg., 13 de abr. de 2020 às 11:04, Heinrich Schuchardt
 escreveu:
>
> Am April 13, 2020 2:49:00 PM UTC schrieb Breno Matheus Lima 
> :
> >Hi Heinrich,
> >
> >Em dom., 12 de abr. de 2020 às 17:35, Heinrich Schuchardt
> > escreveu:
> >>
> >> On 4/12/20 6:16 PM, Fabio Estevam wrote:
> >> > Hi Heinrich,
> >> >
> >> > On Sun, Apr 12, 2020 at 11:23 AM Heinrich Schuchardt
> > wrote:
> >> >>
> >> >> doc/README.mxc_hab was moved to
> >doc/imx/habv4/guides/encrypted_boot.txt by
> >> >> commit df11b0c4d4e3 ("doc: imx: reorganize i.MX documentation"),
> >commit
> >> >> dfe9ff9cc79b ("doc: imx: hab: Reorganize High Assurance Boot
> >> >> documentation"), commit 8a23fc9c94bf ("doc: imx: habv4: Remove
> >extra hab,
> >> >> directory for a cleaner documentation structure"), and commit
> >364c0a89bcfa
> >> >> ("doc: imx: habv4: Move encrypted boot guide").
> >> >>
> >> >> Fixes: df11b0c4d4e3 ("doc: imx: reorganize i.MX documentation")
> >> >> Fixes: dfe9ff9cc79b ("doc: imx: hab: Reorganize High Assurance
> >Boot
> >> >> documentation")
> >> >> Fixes: 8a23fc9c94bf ("doc: imx: habv4: Remove extra hab, directory
> >> >> for a cleaner documentation structure")
> >> >> Fixes: commit 364c0a89bcfa ("doc: imx: habv4: Move encrypted boot
> >guide").
> >> >> Signed-off-by: Heinrich Schuchardt 
> >> >> ---
> >> >>  arch/arm/mach-imx/Kconfig | 6 +++---
> >> >>  1 file changed, 3 insertions(+), 3 deletions(-)
> >> >>
> >> >> diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
> >> >> index aa140c4798..44b47780ee 100644
> >> >> --- a/arch/arm/mach-imx/Kconfig
> >> >> +++ b/arch/arm/mach-imx/Kconfig
> >> >> @@ -41,7 +41,7 @@ config IMX_HAB
> >> >> imply CMD_DEKBLOB
> >> >> help
> >> >>   This option enables the support for secure boot (HAB).
> >> >> - See doc/README.mxc_hab for more details.
> >> >> + See doc/imx/habv4/guides/encrypted_boot.txt for more
> >details.
> >> >
> >> > Thanks for your patch.
> >> >
> >> > Indeed, doc/README.mxc_hab is gone and we should replace it, but I
> >was
> >> > wondering if we should point the file to
> >> > doc/imx/habv4/guides/mx6_mx7_secure_boot.txt instead.
> >> >
> >> > Breno,
> >> >
> >> > What do you think?
> >>
> >> It is doc/imx/habv4/guides/encrypted_boot.txt that mentions
> >> CONFIG_IMX_HAB and CONFIG_CMD_DEKBLOB.
> >>
> >> Maybe both files can be merged. Anyway the imx directory should move
> >to
> >> doc/board and be integrated into doc/board/index.rst.
> >>
> >> Shouldn't the content of folder doc/imx be moved to
> >doc/board/freescale/
> >> and linked in doc/board/freescale/index.rst?
> >>
> >> We should be able to generate HTML documentation for imx using 'make
> >> htmldocs'.
> >
> >Thanks for your feedback.
> >
> >Do you think we can convert this documentation to sphinx format and
> >create an index.rst at doc/imx/? The HABv4 documentation is SoC
> >specific and not board related.
>
> Maybe besides an arch and a board folder we should have a doc/soc/ folder.
>

Thanks for your suggestion, do we have similar documentation for other SoCs?

Please take a look in commit df11b0c4 ("doc: imx: reorganize i.MX
documentation") all i.MX documentation that were located at U-Boot doc
root directory.

Thanks,
Breno Lima


Re: [PATCH] tiny-printf: Support %i

2020-04-13 Thread Marek Vasut
On 4/14/20 1:42 AM, Simon Glass wrote:
> Hi Marek,
> 
> On Fri, 10 Apr 2020 at 14:52, Marek Vasut  wrote:
>>
>> On 4/10/20 10:47 PM, Simon Glass wrote:
>>> Hi Marek,
>>>
>>> On Fri, 10 Apr 2020 at 12:54, Marek Vasut  wrote:

 The most basic printf("%i", value) formating string was missing,
 add it for the sake of convenience.

 Signed-off-by: Marek Vasut 
 Cc: Simon Glass 
 Cc: Stefan Roese 
 ---
  lib/tiny-printf.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> Can you add to the test in print_ut.c?
>>
>> Sure, is that a hard-requirement for such a minor patch ?
>> Is there an example for the other %u / %d variants ?
> 
> I think we should promote adding tests.
> 
> Just add a few lines and then others can contribute more.
> 
> The current tests use sprintf(). But there is a
> ut_check_console_line() that should help. It's really easy to use.
> 
> See here for an example:
> 
> https://gitlab.denx.de/u-boot/custodians/u-boot-dm/-/blob/corp6-working/test/dm/acpi.c#L262

These look like ACPI tests, not printf() tests ?

Also, please answer my question -- there are currently no tests for the
other variants, so you expect me to implement those as well, correct ?


Re: [PATCH] tiny-printf: Support %i

2020-04-13 Thread Marek Vasut
On 4/14/20 1:27 AM, Tom Rini wrote:
> On Fri, Apr 10, 2020 at 08:54:49PM +0200, Marek Vasut wrote:
> 
>> The most basic printf("%i", value) formating string was missing,
>> add it for the sake of convenience.
>>
>> Signed-off-by: Marek Vasut 
>> Cc: Simon Glass 
>> Cc: Stefan Roese 
>> ---
>>  lib/tiny-printf.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
>> index 1138c7012a..8fc7e48d99 100644
>> --- a/lib/tiny-printf.c
>> +++ b/lib/tiny-printf.c
>> @@ -242,6 +242,7 @@ static int _vprintf(struct printf_info *info, const char 
>> *fmt, va_list va)
>>  goto abort;
>>  case 'u':
>>  case 'd':
>> +case 'i':
>>  div = 10;
>>  if (islong) {
>>  num = va_arg(va, unsigned long);
>> @@ -251,7 +252,7 @@ static int _vprintf(struct printf_info *info, const char 
>> *fmt, va_list va)
>>  num = va_arg(va, unsigned int);
>>  }
>>  
>> -if (ch == 'd') {
>> +if (ch != 'u') {
>>  if (islong && (long)num < 0) {
>>  num = -(long)num;
>>  out(info, '-');
> 
> How much does the size change and where do we see this as a problem?

Any code which uses %i in SPL just misbehaves, e.g.
printf("%s[%i] value=%x", __func__, __LINE__, val);
prints function name and then incorrect value, because %i is ignored.
This is also documented in the commit message.

U-Boot grows in size massively due to all the DM/DT bloat which is being
forced upon everyone, but there the uncontrolled growth is apparently OK
even if it brings no obvious improvement, rather the opposite. And yet
here, size increase suddenly matters? Sorry, that's not right.

The code grows by 6 bytes.


Re: [PATCH] tiny-printf: Support %i

2020-04-13 Thread Simon Glass
Hi Marek,

On Fri, 10 Apr 2020 at 14:52, Marek Vasut  wrote:
>
> On 4/10/20 10:47 PM, Simon Glass wrote:
> > Hi Marek,
> >
> > On Fri, 10 Apr 2020 at 12:54, Marek Vasut  wrote:
> >>
> >> The most basic printf("%i", value) formating string was missing,
> >> add it for the sake of convenience.
> >>
> >> Signed-off-by: Marek Vasut 
> >> Cc: Simon Glass 
> >> Cc: Stefan Roese 
> >> ---
> >>  lib/tiny-printf.c | 3 ++-
> >>  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > Can you add to the test in print_ut.c?
>
> Sure, is that a hard-requirement for such a minor patch ?
> Is there an example for the other %u / %d variants ?

I think we should promote adding tests.

Just add a few lines and then others can contribute more.

The current tests use sprintf(). But there is a
ut_check_console_line() that should help. It's really easy to use.

See here for an example:

https://gitlab.denx.de/u-boot/custodians/u-boot-dm/-/blob/corp6-working/test/dm/acpi.c#L262

Regards,
Simon


Re: [PATCH] common: Add Kconfig option for FDT mem alignment

2020-04-13 Thread Heinrich Schuchardt
On 4/13/20 10:03 AM, Michal Simek wrote:
> From: Ashok Reddy Soma 
>
> FDT memory is aligned by 4KB. This is hardcoded in common/board_f.c.
> Add Kconfig option, assign default value of 0x1000 and enable option to
> change this value.

Please, describe why this patch is needed.

>
> Signed-off-by: Ashok Reddy Soma 
> Signed-off-by: Michal Simek 
> ---
>
>  common/board_f.c | 3 ++-
>  dts/Kconfig  | 7 +++
>  2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/common/board_f.c b/common/board_f.c
> index 82a164752aa3..928874e03555 100644
> --- a/common/board_f.c
> +++ b/common/board_f.c
> @@ -546,7 +546,8 @@ static int reserve_fdt(void)
>* will be relocated with other data.
>*/
>   if (gd->fdt_blob) {
> - gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
> + gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) +
> +  CONFIG_FDT_MEM_ALIGN_SIZE, 32);
>
>   gd->start_addr_sp -= gd->fdt_size;
>   gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);

This change does not relate to the commit message. You are not adjusting
the alignment of the device tree location. You are adjusting the size of
the memory available for the device tree.

reserve_fdt() is called after reserve_global_data() where we have:
gd->start_addr_sp -= sizeof(gd_t).

A typical debug output from reserve_global_data() is:
Reserving 544 Bytes for Global Data at: bf740d98

So in this case the device tree will have an alignment of 8 no matter
what power of 2 (>= 8) you choose for CONFIG_FDT_MEM_ALIGN_SIZE.

What about other places where we allocate memory for device trees like
copy_fdt() in cmd/bootefi.?

> diff --git a/dts/Kconfig b/dts/Kconfig
> index 046a54a17366..696c0b71afaf 100644
> --- a/dts/Kconfig
> +++ b/dts/Kconfig
> @@ -121,6 +121,13 @@ config DEFAULT_DEVICE_TREE
> It can be overridden from the command line:
> $ make DEVICE_TREE=
>
> +config FDT_MEM_ALIGN_SIZE
> + hex "FDT memory alignment size"
> + default 0x1000
> + help
> +   This option is used to set the default alignment when reserving memory

%s/is used to set the default alignment/sets the alignment/

Please, mention if this value should be a power of 2.

Best regards

Heinrich

> +   for fdt.
> +
>  config OF_LIST
>   string "List of device tree files to include for DT control"
>   depends on SPL_LOAD_FIT || MULTI_DTB_FIT
>



Re: [PATCH] tiny-printf: Support %i

2020-04-13 Thread Tom Rini
On Fri, Apr 10, 2020 at 08:54:49PM +0200, Marek Vasut wrote:

> The most basic printf("%i", value) formating string was missing,
> add it for the sake of convenience.
> 
> Signed-off-by: Marek Vasut 
> Cc: Simon Glass 
> Cc: Stefan Roese 
> ---
>  lib/tiny-printf.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
> index 1138c7012a..8fc7e48d99 100644
> --- a/lib/tiny-printf.c
> +++ b/lib/tiny-printf.c
> @@ -242,6 +242,7 @@ static int _vprintf(struct printf_info *info, const char 
> *fmt, va_list va)
>   goto abort;
>   case 'u':
>   case 'd':
> + case 'i':
>   div = 10;
>   if (islong) {
>   num = va_arg(va, unsigned long);
> @@ -251,7 +252,7 @@ static int _vprintf(struct printf_info *info, const char 
> *fmt, va_list va)
>   num = va_arg(va, unsigned int);
>   }
>  
> - if (ch == 'd') {
> + if (ch != 'u') {
>   if (islong && (long)num < 0) {
>   num = -(long)num;
>   out(info, '-');

How much does the size change and where do we see this as a problem?
Thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 1/6] riscv: Add boot hartid to Device tree

2020-04-13 Thread Bin Meng
Hi Heinrich,

On Tue, Apr 14, 2020 at 7:05 AM Heinrich Schuchardt  wrote:
>
> On 4/6/20 10:44 PM, Atish Patra wrote:
> > Linux booting protocol mandates that register "a0" contains the hartid.
> > However, U-boot can not pass the hartid via a0 during via standard UEFI
> > protocol. DT nodes are commonly used to pass such information to the OS.
> >
> > Add a DT node under chosen node to indicate the boot hartid. EFI stub
> > in Linux kernel will parse this node and pass it to the real kernel
> > in "a0" before jumping to it.
> >
> > Signed-off-by: Atish Patra 
> > Reviewed-by: Rick Chen 
> > ---
> >  arch/riscv/lib/bootm.c | 22 ++
> >  1 file changed, 22 insertions(+)
> >
> > diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
> > index fad16901c5f2..87cadad5016d 100644
> > --- a/arch/riscv/lib/bootm.c
> > +++ b/arch/riscv/lib/bootm.c
> > @@ -28,6 +28,28 @@ __weak void board_quiesce_devices(void)
> >
> >  int arch_fixup_fdt(void *blob)
> >  {
> > +#ifdef CONFIG_EFI_LOADER
> > + int err;
> > + u32 size;
> > + int chosen_offset;
> > +
> > + size = fdt_totalsize(blob);
> > + err  = fdt_open_into(blob, blob, size + 32);
> > + if (err < 0) {
> > + printf("Device Tree can't be expanded to accommodate new 
> > node");
> > + return err;
> > + }
> > + chosen_offset = fdt_path_offset(blob, "/chosen");
> > + if (chosen_offset < 0) {
> > + err = fdt_add_subnode(blob, 0, "chosen");
> > + if (err < 0) {
> > + printf("chosen node can not be added\n");
> > + return err;
> > + }
> > + }
> > + /* Overwrite the boot-hartid as U-Boot is the last stage BL */
> > + fdt_setprop_u32(blob, chosen_offset, "boot-hartid", 
> > gd->arch.boot_hart);
> > +#endif
> >   return 0;
> >  }
> >
> >
>
> I have tested this on qemu-riscv64_defconfig by comparing the device
> tree before and after running helloworld.efi:
>
> => fdt addr $fdtcontroladdr
> => fdt print /chosen
> chosen {
> bootargs = "";
> stdout-path = "/uart@1000";
> };
> ...
> => dhcp $kernel_addr_r helloworld.efi
> => bootefi $kernel_addr_r
> ...
> => fdt addr 0x87F0
> => fdt print /chosen
> chosen {
> riscv,kernel-end = <0x 0x>;
> riscv,kernel-start = <0x 0x>;
> boot-hartid = <0x>;
> bootargs = "";
> stdout-path = "/uart@1000";
> };
>
> The entry for boot-hardid seems to be ok.
>
> But the riscv,kernel-end and riscv,kernel-start values are just some
> dummy values introduced in:
>
> board/emulation/qemu-riscv/qemu-riscv.c:84
> commit 897206c5cc5c ("riscv: qemu: clear kernel-start/-end in device
> tree as workaround for BBL)"
>
> @Lukas:
> Why are these values set to zero and not deleted (using fdt_delprop())
> from the device tree? I cannot see that we need them when booting via UEFI.
>

This should be removed as BBL is legacy and we only support working
with OpenSBI.

> Tested-by: Heinrich Schuchardt 

Regards,
Bin


Re: [PATCH v5 1/6] riscv: Add boot hartid to Device tree

2020-04-13 Thread Heinrich Schuchardt
On 4/6/20 10:44 PM, Atish Patra wrote:
> Linux booting protocol mandates that register "a0" contains the hartid.
> However, U-boot can not pass the hartid via a0 during via standard UEFI
> protocol. DT nodes are commonly used to pass such information to the OS.
>
> Add a DT node under chosen node to indicate the boot hartid. EFI stub
> in Linux kernel will parse this node and pass it to the real kernel
> in "a0" before jumping to it.
>
> Signed-off-by: Atish Patra 
> Reviewed-by: Rick Chen 
> ---
>  arch/riscv/lib/bootm.c | 22 ++
>  1 file changed, 22 insertions(+)
>
> diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
> index fad16901c5f2..87cadad5016d 100644
> --- a/arch/riscv/lib/bootm.c
> +++ b/arch/riscv/lib/bootm.c
> @@ -28,6 +28,28 @@ __weak void board_quiesce_devices(void)
>
>  int arch_fixup_fdt(void *blob)
>  {
> +#ifdef CONFIG_EFI_LOADER
> + int err;
> + u32 size;
> + int chosen_offset;
> +
> + size = fdt_totalsize(blob);
> + err  = fdt_open_into(blob, blob, size + 32);
> + if (err < 0) {
> + printf("Device Tree can't be expanded to accommodate new node");
> + return err;
> + }
> + chosen_offset = fdt_path_offset(blob, "/chosen");
> + if (chosen_offset < 0) {
> + err = fdt_add_subnode(blob, 0, "chosen");
> + if (err < 0) {
> + printf("chosen node can not be added\n");
> + return err;
> + }
> + }
> + /* Overwrite the boot-hartid as U-Boot is the last stage BL */
> + fdt_setprop_u32(blob, chosen_offset, "boot-hartid", gd->arch.boot_hart);
> +#endif
>   return 0;
>  }
>
>

I have tested this on qemu-riscv64_defconfig by comparing the device
tree before and after running helloworld.efi:

=> fdt addr $fdtcontroladdr
=> fdt print /chosen
chosen {
bootargs = "";
stdout-path = "/uart@1000";
};
...
=> dhcp $kernel_addr_r helloworld.efi
=> bootefi $kernel_addr_r
...
=> fdt addr 0x87F0
=> fdt print /chosen
chosen {
riscv,kernel-end = <0x 0x>;
riscv,kernel-start = <0x 0x>;
boot-hartid = <0x>;
bootargs = "";
stdout-path = "/uart@1000";
};

The entry for boot-hardid seems to be ok.

But the riscv,kernel-end and riscv,kernel-start values are just some
dummy values introduced in:

board/emulation/qemu-riscv/qemu-riscv.c:84
commit 897206c5cc5c ("riscv: qemu: clear kernel-start/-end in device
tree as workaround for BBL)"

@Lukas:
Why are these values set to zero and not deleted (using fdt_delprop())
from the device tree? I cannot see that we need them when booting via UEFI.

Tested-by: Heinrich Schuchardt 


Re: [PATCH v5 0/6] RISC-V DT related fixes for reserved memory & UEFI

2020-04-13 Thread Bin Meng
Hi Atish,

On Tue, Apr 14, 2020 at 6:02 AM Atish Patra  wrote:
>
> On Tue, Apr 7, 2020 at 10:35 AM Atish Patra  wrote:
> >
> > On Mon, Apr 6, 2020 at 11:51 PM Ard Biesheuvel
> >  wrote:
> > >
> > > On Tue, 7 Apr 2020 at 08:46, Heinrich Schuchardt  
> > > wrote:
> > > >
> > > > On 4/6/20 11:01 PM, Ard Biesheuvel wrote:
> > > > > On Mon, 6 Apr 2020 at 22:45, Atish Patra  wrote:
> > > > >>
> > > > >> This series adds few DT related fixes required for Linux EFI stub to 
> > > > >> work
> > > > >> on RISC-V.
> > > > >>
> > > > >
> > > > > I'm not sure how this is supposed to work, since DT reserved memory
> > > > > regions are not used by EFI. If you want to reserve memory on a UEFI
> > > > > system, you have to reserve it in the UEFI memory map from firmware.
> > > > > The DT reserved-memory node is taken into account too late, the
> > > > > /memreserve/ entries are ignored entirely.
> > > >
> > > > Hello Ard,
> > > >
> > > > thanks for reviewing.
> > > >
> > > > What do you mean by "The DT reserved-memory node is taken into account
> > > > too late"?
> > > >
> > > > Cf. commit 7be64b885a36 ("cmd: bootefi: Parse reserved-memory node from 
> > > > DT")
> > > >
> > >
> > > What I mean is that the EFI stub in Linux uses memory allocation
> > > functions, expecting the firmware to ensure that those allocations do
> > > not conflict with memory descriptions and reservations in DT. So if
> > > the firmware wants to express this redundantly, by passing
> > > reservations in both reserved-memory and in the EFI memory map, that
> > > is probably fine.
> > >
> > > Also, I must sheepishly admit that I only realize now that this patch
> > > set is against u-boot not Linux :-)
> > >
> > :)
> >
> > > So if fixed reserved-memory regions are only being used to seed the
> > > reserved regions in the EFI memory map, you can safely ignore me.
> >
> > Yeah. That's the purpose. Having reserved memory nodes in the final DT
> > used by linux
> > also ensures that proper Linux adds a reserved memory block or removes
> > it from memblock
> > entries depending on "no-map" property.
> >
> > > Apologies for the noise.
> >
> >
> >
> > --
> > Regards,
> > Atish
>
> Any other comments on the series ? It would be great if this series
> could be merged before
> v2020.07 release.

I hope so if no one objects the proposed solution here in U-Boot vs.
the PMP SBI extension. I need have another look at the latest version
of patches though.

Regards,
Bin


Re: [PATCH v5 0/6] RISC-V DT related fixes for reserved memory & UEFI

2020-04-13 Thread Atish Patra
On Tue, Apr 7, 2020 at 10:35 AM Atish Patra  wrote:
>
> On Mon, Apr 6, 2020 at 11:51 PM Ard Biesheuvel
>  wrote:
> >
> > On Tue, 7 Apr 2020 at 08:46, Heinrich Schuchardt  wrote:
> > >
> > > On 4/6/20 11:01 PM, Ard Biesheuvel wrote:
> > > > On Mon, 6 Apr 2020 at 22:45, Atish Patra  wrote:
> > > >>
> > > >> This series adds few DT related fixes required for Linux EFI stub to 
> > > >> work
> > > >> on RISC-V.
> > > >>
> > > >
> > > > I'm not sure how this is supposed to work, since DT reserved memory
> > > > regions are not used by EFI. If you want to reserve memory on a UEFI
> > > > system, you have to reserve it in the UEFI memory map from firmware.
> > > > The DT reserved-memory node is taken into account too late, the
> > > > /memreserve/ entries are ignored entirely.
> > >
> > > Hello Ard,
> > >
> > > thanks for reviewing.
> > >
> > > What do you mean by "The DT reserved-memory node is taken into account
> > > too late"?
> > >
> > > Cf. commit 7be64b885a36 ("cmd: bootefi: Parse reserved-memory node from 
> > > DT")
> > >
> >
> > What I mean is that the EFI stub in Linux uses memory allocation
> > functions, expecting the firmware to ensure that those allocations do
> > not conflict with memory descriptions and reservations in DT. So if
> > the firmware wants to express this redundantly, by passing
> > reservations in both reserved-memory and in the EFI memory map, that
> > is probably fine.
> >
> > Also, I must sheepishly admit that I only realize now that this patch
> > set is against u-boot not Linux :-)
> >
> :)
>
> > So if fixed reserved-memory regions are only being used to seed the
> > reserved regions in the EFI memory map, you can safely ignore me.
>
> Yeah. That's the purpose. Having reserved memory nodes in the final DT
> used by linux
> also ensures that proper Linux adds a reserved memory block or removes
> it from memblock
> entries depending on "no-map" property.
>
> > Apologies for the noise.
>
>
>
> --
> Regards,
> Atish

Any other comments on the series ? It would be great if this series
could be merged before
v2020.07 release.

-- 
Regards,
Atish


[PATCH v2 0/3] patman: Add changelog customization options

2020-04-13 Thread Sean Anderson
This series adds a few changes I have been using locally as new behaviour
for patman.

Changes in v2:
- Add a note when there are no changes in the current revision
- Add documentation for new tags
- Add patch for multi-line changes in changelogs
- Switch to using commit tags for changelog control, instead of
  command-line options

Sean Anderson (3):
  patman: Add option to suppress empty changelog entries
  patman: Add new tags for finer-grained changelog control
  patman: Support multi-line changes in changelogs

 tools/patman/README | 27 ++-
 tools/patman/patchstream.py | 96 +
 tools/patman/patman.py  |  2 +-
 tools/patman/series.py  | 49 ++-
 4 files changed, 129 insertions(+), 45 deletions(-)

-- 
2.25.1



[PATCH v2 3/3] patman: Support multi-line changes in changelogs

2020-04-13 Thread Sean Anderson
This patch adds support to multi-line changes. That is, if one has a line
in a changelog like
- Do a thing but
  it spans multiple lines
Using Series-process-log sort would sort as if those lines were unrelated.
With this patch, any change line starting with whitespace will be
considered part of the change before it.

Signed-off-by: Sean Anderson 
---

Changes in v2:
- New

 tools/patman/README | 10 --
 tools/patman/patchstream.py | 35 +++
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/tools/patman/README b/tools/patman/README
index ce912aacbb..433bbf1683 100644
--- a/tools/patman/README
+++ b/tools/patman/README
@@ -270,8 +270,14 @@ Patch-cc: Their Name 
interpreted by git send-email if you use it.
 
 Series-process-log: sort, uniq
-   This tells patman to sort and/or uniq the change logs. It is
-   assumed that each change log entry is only a single line long.
+   This tells patman to sort and/or uniq the change logs. Changes may be
+   multiple lines long, as long as each subsequent line of a change begins
+   with a whitespace character. For example,
+
+- This change
+  continues onto the next line
+- But this change is separate
+
Use 'sort' to sort the entries, and 'uniq' to include only
unique entries. If omitted, no change log processing is done.
Separate each tag with a comma.
diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py
index f29ad87e70..eeac5d268e 100644
--- a/tools/patman/patchstream.py
+++ b/tools/patman/patchstream.py
@@ -45,6 +45,9 @@ re_commit = re.compile('^commit ([0-9a-f]*)$')
 # We detect these since checkpatch doesn't always do it
 re_space_before_tab = re.compile('^[+].* \t')
 
+# Match indented lines for changes
+re_leading_whitespace = re.compile('^\s')
+
 # States we can be in - can we use range() and still have comments?
 STATE_MSG_HEADER = 0# Still in the message header
 STATE_PATCH_SUBJECT = 1 # In patch subject (first line of log for a commit)
@@ -72,6 +75,7 @@ class PatchStream:
 self.is_log = is_log # True if indent like git log
 self.in_change = None# Name of the change list we are in
 self.change_version = 0  # Non-zero if we are in a change list
+self.change_lines = []   # Lines of the current change
 self.blank_count = 0 # Number of blank lines stored up
 self.state = STATE_MSG_HEADER# What state are we in?
 self.signoff = []# Contents of signoff line
@@ -130,6 +134,20 @@ class PatchStream:
 raise ValueError("%s: Cannot decode version info '%s'" %
 (self.commit.hash, line))
 
+def FinalizeChange(self):
+"""Finalize a (multi-line) change and add it to the series or commit"""
+if not self.change_lines:
+return
+change = '\n'.join(self.change_lines)
+
+if self.in_change == 'Series':
+self.series.AddChange(self.change_version, self.commit, change)
+elif self.in_change == 'Cover':
+self.series.AddChange(self.change_version, None, change)
+elif self.in_change == 'Commit':
+self.commit.AddChange(self.change_version, change)
+self.change_lines = []
+
 def ProcessLine(self, line):
 """Process a single line of a patch file or commit log
 
@@ -170,6 +188,7 @@ class PatchStream:
 commit_tag_match = re_commit_tag.match(line)
 cover_match = re_cover.match(line)
 signoff_match = re_signoff.match(line)
+leading_whitespace_match = re_leading_whitespace.match(line)
 tag_match = None
 if self.state == STATE_PATCH_HEADER:
 tag_match = re_tag.match(line)
@@ -210,6 +229,7 @@ class PatchStream:
 # is missing, fix it up.
 if self.in_change:
 self.warn.append("Missing 'blank line' in section 
'%s-changes'" % self.in_change)
+self.FinalizeChange()
 self.in_change = None
 self.change_version = 0
 
@@ -264,20 +284,18 @@ class PatchStream:
 elif self.in_change:
 if is_blank:
 # Blank line ends this change list
+self.FinalizeChange()
 self.in_change = None
 self.change_version = 0
 elif line == '---':
+self.FinalizeChange()
 self.in_change = None
 self.change_version = 0
 out = self.ProcessLine(line)
-else:
-if self.is_log:
-if self.in_change == 'Series':
-self.series.AddChange(self.change_version, 
self.commit, line)
-elif self.in_change == 'Cover':
-self.series.AddChange(self.change_version, None, line)
-elif self.in_change == 'Commit':
-  

[PATCH v2 2/3] patman: Add new tags for finer-grained changelog control

2020-04-13 Thread Sean Anderson
By default patman generates a combined changelog for the cover letter. This
may not always be desireable.

Many patches may have the same changes. These can be coalesced with
"Series-process-log: uniq", but this is imperfect. Similar changes like
"Move foo to patch 7" will not be merged with the similar "Move foo to this
patch from patch 6".

Changes may not make sense outside of the patch they are written for. For
example, a change line of "Add check for bar" does not make sense outside
of the context in which bar might be checked for. Some changes like "New"
or "Lint" may be repeated many times throughout different change logs, but
carry no useful information in a summary.

Lastly, I like to summarize the broad strokes of the changes I have made in
the cover letter, while documenting all the details in the appropriate
patches. I think this make it easier to get a good feel for what has
changed, without making it difficult to wade through every change in the
whole series.

This patch adds two new tags to add changelog entries which only appear in the
cover letter, or only appear in the commit. Changes documented with
"Commit-changes" will only appear in the commit, and will not appear in the
cover letter. Changes documented with "Cover-changes" will not appear in any
commit, and will only appear in the cover letter.

Signed-off-by: Sean Anderson 
---

Changes in v2:
- Add documentation for new tags
- Switch to using commit tags for changelog control, instead of
  command-line options

 tools/patman/README | 17 +
 tools/patman/patchstream.py | 71 ++---
 tools/patman/patman.py  |  2 +-
 tools/patman/series.py  | 13 +--
 4 files changed, 72 insertions(+), 31 deletions(-)

diff --git a/tools/patman/README b/tools/patman/README
index 02d5829744..ce912aacbb 100644
--- a/tools/patman/README
+++ b/tools/patman/README
@@ -247,6 +247,23 @@ Series-changes: n
to update the log there and then, knowing that the script will
do the rest.
 
+Commit-changes: n
+- This line will not appear in the cover-letter changelog
+
+   This tag is like Series-changes, except changes in this changelog will
+   only appear in the changelog of the commit this tag is in. This is
+   useful when you want to add notes which may not make sense in the cover
+   letter. For example, you can have short changes such as "New" or
+   "Lint".
+
+Cover-changes: n
+- This line will only appear in the cover letter
+
+   This tag is like Series-changes, except changes in this changelog will
+   only appear in the cover-letter changelog. This is useful to summarize
+   changes made with Commit-changes, or to add additional context to
+   changes.
+
 Patch-cc: Their Name 
This copies a single patch to another email address. Note that the
Cc: used by git send-email is ignored by patman, but will be
diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py
index a83497d79f..f29ad87e70 100644
--- a/tools/patman/patchstream.py
+++ b/tools/patman/patchstream.py
@@ -24,11 +24,8 @@ re_allowed_after_test = re.compile('^Signed-off-by:')
 # Signoffs
 re_signoff = re.compile('^Signed-off-by: *(.*)')
 
-# The start of the cover letter
-re_cover = re.compile('^Cover-letter:')
-
-# A cover letter Cc
-re_cover_cc = re.compile('^Cover-letter-cc: *(.*)')
+# Cover letter tag
+re_cover = re.compile('^Cover-([a-z-]*): *(.*)')
 
 # Patch series tag
 re_series_tag = re.compile('^Series-([a-z-]*): *(.*)')
@@ -65,7 +62,7 @@ class PatchStream:
 def __init__(self, series, name=None, is_log=False):
 self.skip_blank = False  # True to skip a single blank line
 self.found_test = False  # Found a TEST= line
-self.lines_after_test = 0# MNumber of lines found after TEST=
+self.lines_after_test = 0# Number of lines found after TEST=
 self.warn = []   # List of warnings we have collected
 self.linenum = 1 # Output line number we are up to
 self.in_section = None   # Name of start...END section we are 
in
@@ -73,7 +70,8 @@ class PatchStream:
 self.section = []# The current section...END section
 self.series = series # Info about the patch series
 self.is_log = is_log # True if indent like git log
-self.in_change = 0   # Non-zero if we are in a change list
+self.in_change = None# Name of the change list we are in
+self.change_version = 0  # Non-zero if we are in a change list
 self.blank_count = 0 # Number of blank lines stored up
 self.state = STATE_MSG_HEADER# What state are we in?
 self.signoff = []# Contents of signoff line
@@ -124,6 +122,14 @@ class PatchStream:
 self.skip_blank = True
 self.section = []
 
+def 

[PATCH v2 1/3] patman: Add option to suppress empty changelog entries

2020-04-13 Thread Sean Anderson
Patman outputs a line for every edition of the series in every patch,
regardless of whether any changes were made. This can result in many
redundant lines in patch changelogs, especially when a patch did not exist
before a certain revision. For example, the existing behaviour could result
in a changelog of

Changes in v7: None
Changes in v6: None
Changes in v5:
- Make a change

Changes in v4: None

Changes in v3:
- New

Changes in v2: None

With this patch applied and with --no-empty-changes, the same patch would
look like

(no changes since v5)

Changes in v5:
- Make a change

Changes in v3:
- New

This is entirely aesthetic, but I think it reduces clutter, especially for
patches added later on in a series.

Signed-off-by: Sean Anderson 
---

Changes in v2:
- Add a note when there are no changes in the current revision
- Make this the default behaviour, and remove the option

 tools/patman/patchstream.py |  2 +-
 tools/patman/series.py  | 40 +++--
 2 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py
index df3eb7483b..a83497d79f 100644
--- a/tools/patman/patchstream.py
+++ b/tools/patman/patchstream.py
@@ -340,7 +340,7 @@ class PatchStream:
 elif line == '---':
 self.state = STATE_DIFFS
 
-# Output the tags (signeoff first), then change list
+# Output the tags (signoff first), then change list
 out = []
 log = self.series.MakeChangeLog(self.commit)
 out += [line]
diff --git a/tools/patman/series.py b/tools/patman/series.py
index a15f7625ed..ca42e5e966 100644
--- a/tools/patman/series.py
+++ b/tools/patman/series.py
@@ -146,38 +146,56 @@ class Series(dict):
 Changes in v4:
 - Jog the dial back closer to the widget
 
-Changes in v3: None
 Changes in v2:
 - Fix the widget
 - Jog the dial
 
-etc.
+If there are no new changes in a patch, a note will be added
+
+(no changes since v2)
+
+Changes in v2:
+- Fix the widget
+- Jog the dial
 """
+versions = sorted(self.changes, reverse=True)
+newest_version = 1
+try:
+newest_version = max(int(self.version), versions[0])
+except (IndexError, ValueError):
+pass
+
 final = []
 process_it = self.get('process_log', '').split(',')
 process_it = [item.strip() for item in process_it]
 need_blank = False
-for change in sorted(self.changes, reverse=True):
+for version in versions:
 out = []
-for this_commit, text in self.changes[change]:
+for this_commit, text in self.changes[version]:
 if commit and this_commit != commit:
 continue
 if 'uniq' not in process_it or text not in out:
 out.append(text)
-line = 'Changes in v%d:' % change
-have_changes = len(out) > 0
 if 'sort' in process_it:
 out = sorted(out)
+have_changes = len(out) > 0
+line = 'Changes in v%d:' % version
 if have_changes:
 out.insert(0, line)
-else:
-out = [line + ' None']
-if need_blank:
-out.insert(0, '')
+if version < newest_version:
+out.insert(0, '')
+out.insert(0, '(no changes since v%d)' % version)
+newest_version = 0
+# Only add a new line if we output something
+if need_blank:
+out.insert(0, '')
 final += out
 need_blank = have_changes
-if self.changes:
+
+if len(final) > 0:
 final.append('')
+else:
+final = ['(no changes since v1)', '']
 return final
 
 def DoChecks(self):
-- 
2.25.1



Re: [PATCH v3] mmc: zynq: parse dt when probing

2020-04-13 Thread Jaehoon Chung
On 4/13/20 5:15 PM, Michal Simek wrote:
> On 11. 04. 20 11:03, Benedikt Grassl wrote:
>> Currently, the entry "bus-width = <8>" in the ZynqMP's sdhci nodes
>> is not evaluated. This results in the bus width staying at its default
>> value (4 bit in HS200 mode).
>> Fix this by calling mmc_of_parse. This function also checks for the
>> "no-1-8-v" and "max-frequency" entries. Remove the handling of those
>> nodes from this driver.
>>
>> Signed-off-by: Benedikt Grassl 

Reviewed-by: Jaehoon Chung 

Added just minor comment.

>> ---
>>  drivers/mmc/sdhci.c  |  3 +--
>>  drivers/mmc/zynq_sdhci.c | 16 +++-
>>  include/sdhci.h  |  1 -
>>  3 files changed, 8 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
>> index 520c9f9feb..372dc0a820 100644
>> --- a/drivers/mmc/sdhci.c
>> +++ b/drivers/mmc/sdhci.c
>> @@ -839,8 +839,7 @@ int sdhci_setup_cfg(struct mmc_config *cfg, struct 
>> sdhci_host *host,
>>  cfg->host_caps &= ~MMC_MODE_HS_52MHz;
>>  }
>>  
>> -if (!(cfg->voltages & MMC_VDD_165_195) ||
>> -(host->quirks & SDHCI_QUIRK_NO_1_8_V))
>> +if (!(cfg->voltages & MMC_VDD_165_195))
>>  caps_1 &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 |
>>  SDHCI_SUPPORT_DDR50);
>>  
>> diff --git a/drivers/mmc/zynq_sdhci.c b/drivers/mmc/zynq_sdhci.c
>> index da3ff53da1..d0a43d9539 100644
>> --- a/drivers/mmc/zynq_sdhci.c
>> +++ b/drivers/mmc/zynq_sdhci.c
>> @@ -22,14 +22,12 @@ DECLARE_GLOBAL_DATA_PTR;
>>  struct arasan_sdhci_plat {
>>  struct mmc_config cfg;
>>  struct mmc mmc;
>> -unsigned int f_max;
>>  };
>>  
>>  struct arasan_sdhci_priv {
>>  struct sdhci_host *host;
>>  u8 deviceid;
>>  u8 bank;
>> -u8 no_1p8;
>>  };
>>  
>>  #if defined(CONFIG_ARCH_ZYNQMP)
>> @@ -238,8 +236,11 @@ static int arasan_sdhci_probe(struct udevice *dev)
>>  host->quirks |= SDHCI_QUIRK_BROKEN_HISPD_MODE;
>>  #endif
>>  
>> -if (priv->no_1p8)
>> -host->quirks |= SDHCI_QUIRK_NO_1_8_V;
>> +plat->cfg.f_max = CONFIG_ZYNQ_SDHCI_MAX_FREQ;
>> +
>> +ret = mmc_of_parse(dev, >cfg);
>> +if (ret)
>> +return ret;
>>  
>>  host->max_clk = clock;
>>  
>> @@ -247,10 +248,11 @@ static int arasan_sdhci_probe(struct udevice *dev)
>>  host->mmc->dev = dev;
>>  host->mmc->priv = host;
>>  
>> -ret = sdhci_setup_cfg(>cfg, host, plat->f_max,
>> +ret = sdhci_setup_cfg(>cfg, host, plat->cfg.f_max,
>>CONFIG_ZYNQ_SDHCI_MIN_FREQ);
>>  if (ret)
>>  return ret;
>> +

Unnecessary white space.

>>  upriv->mmc = host->mmc;
>>  
>>  return sdhci_probe(dev);
>> @@ -258,7 +260,6 @@ static int arasan_sdhci_probe(struct udevice *dev)
>>  
>>  static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)
>>  {
>> -struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
>>  struct arasan_sdhci_priv *priv = dev_get_priv(dev);
>>  
>>  priv->host = calloc(1, sizeof(struct sdhci_host));
>> @@ -277,10 +278,7 @@ static int arasan_sdhci_ofdata_to_platdata(struct 
>> udevice *dev)
>>  
>>  priv->deviceid = dev_read_u32_default(dev, "xlnx,device_id", -1);
>>  priv->bank = dev_read_u32_default(dev, "xlnx,mio_bank", -1);
>> -priv->no_1p8 = dev_read_bool(dev, "no-1-8-v");
>>  
>> -plat->f_max = dev_read_u32_default(dev, "max-frequency",
>> -   CONFIG_ZYNQ_SDHCI_MAX_FREQ);
>>  return 0;
>>  }
>>  
>> diff --git a/include/sdhci.h b/include/sdhci.h
>> index aa4378fd57..0ef8c2ed62 100644
>> --- a/include/sdhci.h
>> +++ b/include/sdhci.h
>> @@ -243,7 +243,6 @@
>>  #define SDHCI_QUIRK_BROKEN_HISPD_MODE   BIT(5)
>>  #define SDHCI_QUIRK_WAIT_SEND_CMD   (1 << 6)
>>  #define SDHCI_QUIRK_USE_WIDE8   (1 << 8)
>> -#define SDHCI_QUIRK_NO_1_8_V(1 << 9)
>>  
>>  /* to make gcc happy */
>>  struct sdhci_host;
>>
> 
> Looks good. Will apply.
> 
> M
> 
> 



Merged 'next' to master

2020-04-13 Thread Tom Rini
JFYI, I've now merged the next branch to master.

-- 
Tom


signature.asc
Description: PGP signature


[PULL] u-boot-socfpga/master

2020-04-13 Thread Marek Vasut
The following changes since commit 995972ddbbcc5fccd324ab384bca9af90e710755:

  Merge tag 'dm-pull9apr20' of git://git.denx.de/u-boot-dm (2020-04-10
11:40:28 -0400)

are available in the Git repository at:

  git://git.denx.de/u-boot-socfpga.git master

for you to fetch changes up to 3958ef307e09a28ce649dd7d6e0cb398996dcaa5:

  arm: socfpga: arria10: Enable cache driver in SPL (2020-04-13 13:49:51
+0200)


Ley Foon Tan (3):
  arm: dts: arria10: Move uboot specific properties to u-boot.dtsi
  arm: dts: arria10: Update dtsi/dts from Linux
  arm: socfpga: arria10: Enable cache driver in SPL

Marek Vasut (1):
  ARM: socfpga: Enable DM RTC bootcount on ABB SECU1

 arch/arm/dts/socfpga_arria10-u-boot.dtsi | 142

 arch/arm/dts/socfpga_arria10.dtsi| 118
++
 arch/arm/dts/socfpga_arria10_socdk-u-boot.dtsi   |  17 ++
 arch/arm/dts/socfpga_arria10_socdk.dtsi  |  66
-
 arch/arm/dts/socfpga_arria10_socdk_sdmmc-u-boot.dtsi |  46
++
 arch/arm/dts/socfpga_arria10_socdk_sdmmc.dts |  53
++
 arch/arm/dts/socfpga_arria5_secu1.dts|   6 
 arch/arm/mach-socfpga/Kconfig|   1 +
 configs/socfpga_secu1_defconfig  |   5 +++
 9 files changed, 308 insertions(+), 146 deletions(-)
 create mode 100644 arch/arm/dts/socfpga_arria10-u-boot.dtsi
 create mode 100644 arch/arm/dts/socfpga_arria10_socdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/socfpga_arria10_socdk_sdmmc-u-boot.dtsi


[PULL] u-boot-usb/master

2020-04-13 Thread Marek Vasut
The following changes since commit 995972ddbbcc5fccd324ab384bca9af90e710755:

  Merge tag 'dm-pull9apr20' of git://git.denx.de/u-boot-dm (2020-04-10
11:40:28 -0400)

are available in the Git repository at:

  git://git.denx.de/u-boot-usb.git master

for you to fetch changes up to 9cadf059589c8fd18b58b35d6b99489f2fd0bd3e:

  drivers: usb: host: Add BRCM xHCI driver (2020-04-13 13:48:41 +0200)


Kever Yang (3):
  usb: dwc3-of-simple: Drop redundant inclding header file
  usb: ehci-msm: Use dev interface to get device address
  usb: Migrate to support live DT for some driver

Rayagonda Kokatanur (1):
  drivers: usb: host: Add BRCM xHCI driver

 drivers/usb/cdns3/core.c   | 15 ++-
 drivers/usb/cdns3/gadget.c |  2 +-
 drivers/usb/common/common.c| 12 +---
 drivers/usb/dwc3/dwc3-generic.c| 16 +++-
 drivers/usb/dwc3/dwc3-meson-g12a.c |  2 +-
 drivers/usb/gadget/dwc2_udc_otg.c  |  5 ++---
 drivers/usb/host/Kconfig   |  8 
 drivers/usb/host/Makefile  |  1 +
 drivers/usb/host/dwc3-of-simple.c  |  1 -
 drivers/usb/host/dwc3-sti-glue.c   | 20 +++-
 drivers/usb/host/ehci-msm.c|  4 +---
 drivers/usb/host/ehci-mx6.c|  2 +-
 drivers/usb/host/xhci-brcm.c   | 98
++
 drivers/usb/host/xhci-dwc3.c   |  3 +--
 drivers/usb/musb-new/ti-musb.c | 12 +---
 include/linux/usb/otg.h| 10 ++
 16 files changed, 150 insertions(+), 61 deletions(-)
 create mode 100644 drivers/usb/host/xhci-brcm.c


Re: [U-Boot] [PATCH v2 5/5] sifive: fu540: Enable spi-nor flash support

2020-04-13 Thread Jagan Teki
On Tue, Apr 7, 2020 at 9:48 PM Sagar Kadam  wrote:
>
> Hello Jagan,
>
> > -Original Message-
> > From: Jagan Teki 
> > Sent: Monday, April 6, 2020 9:30 PM
> > To: Sagar Kadam 
> > Cc: Bin Meng ; Palmer Dabbelt
> > ; U-Boot Mailing List ; linux-
> > amarula 
> > Subject: Re: [U-Boot] [PATCH v2 5/5] sifive: fu540: Enable spi-nor flash
> > support
> >
> > [External Email] Do not click links or attachments unless you recognize the
> > sender and know the content is safe
> >
> > Hi Sagar,
> >
> > On Sun, Apr 5, 2020 at 12:29 AM Sagar Kadam 
> > wrote:
> > >
> > > Hello Jagan,
> > >
> > > > -Original Message-
> > > > From: Jagan Teki 
> > > > Sent: Saturday, April 4, 2020 11:45 PM
> > > > To: Sagar Kadam 
> > > > Cc: Bin Meng ; Palmer Dabbelt
> > > > ; U-Boot Mailing List ;
> > linux-
> > > > amarula 
> > > > Subject: Re: [U-Boot] [PATCH v2 5/5] sifive: fu540: Enable spi-nor flash
> > > > support
> > > >
> > > > [External Email] Do not click links or attachments unless you recognize
> > the
> > > > sender and know the content is safe
> > > >
> > > > Hi Sagar,
> > > >
> > > > On Mon, Nov 18, 2019 at 2:29 AM Sagar Kadam
> > 
> > > > wrote:
> > > > >
> > > > >
> > > > > Hello Jagan/Bin,
> > > > >
> > > > > > -Original Message-
> > > > > > From: U-Boot  On Behalf Of Bin
> > Meng
> > > > > > Sent: Monday, November 11, 2019 8:02 PM
> > > > > > To: Jagan Teki 
> > > > > > Cc: Palmer Dabbelt ( Sifive) ; U-Boot Mailing
> > List
> > > >  > > > > > b...@lists.denx.de>; linux-amarula  > > > amar...@amarulasolutions.com>
> > > > > > Subject: Re: [U-Boot] [PATCH v2 5/5] sifive: fu540: Enable spi-nor
> > flash
> > > > > > support
> > > > > >
> > > > > > Hi Jagan,
> > > > > >
> > > > > > On Sat, Nov 9, 2019 at 7:57 PM Jagan Teki
> > > > 
> > > > > > wrote:
> > > > > > >
> > > > > > > Hi Bin,
> > > > > > >
> > > > > > > On Tue, Oct 29, 2019 at 3:50 PM Bin Meng 
> > > > wrote:
> > > > > > > >
> > > > > > > > Hi Jagan,
> > > > > > > >
> > > > > > > > On Tue, Oct 29, 2019 at 5:38 PM Bin Meng
> > 
> > > > > > wrote:
> > > > > > > > >
> > > > > > > > > Hi Jagan,
> > > > > > > > >
> > > > > > > > > On Wed, Oct 16, 2019 at 10:58 PM Jagan Teki
> > > > > >  wrote:
> > > > > > > > > >
> > > > > > > > > > HiFive Unleashed A00 support is25wp256 spi-nor flash,
> > > > > > > > > > So enable the same and add test result log for future
> > > > > > > > > > reference.
> > > > > > > > > >
> > > > > > > > > > Tested on SiFive FU540 board.
> > > > > > > > > >
> > > > > > > > > > Signed-off-by: Jagan Teki 
> > > > > > > > > > Reviewed-by: Bin Meng 
> > > > > > > > > > Tested-by: Bin Meng 
> > > > > > > > > > ---
> > > > > > > > > >  .../dts/hifive-unleashed-a00-u-boot.dtsi  |  1 +
> > > > > > > > > >  board/sifive/fu540/Kconfig|  3 +++
> > > > > > > > > >  doc/board/sifive/fu540.rst| 19
> > > > +++
> > > > > > > > > >  3 files changed, 23 insertions(+)
> > > > > > > > > >
> > > > > > > > > > diff --git a/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
> > > > > > b/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
> > > > > > > > > > index 25ec8265a5..d7a64134db 100644
> > > > > > > > > > --- a/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
> > > > > > > > > > +++ b/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
> > > > > > > > > > @@ -5,6 +5,7 @@
> > > > > > > > > >
> > > > > > > > > >  / {
> > > > > > > > > > aliases {
> > > > > > > > > > +   spi0 = 
> > > > > > > > > > spi2 = 
> > > > > > > > > > };
> > > > > > > > > >  };
> > > > > > > > > > diff --git a/board/sifive/fu540/Kconfig
> > > > b/board/sifive/fu540/Kconfig
> > > > > > > > > > index 5d65080429..c5a1bca03c 100644
> > > > > > > > > > --- a/board/sifive/fu540/Kconfig
> > > > > > > > > > +++ b/board/sifive/fu540/Kconfig
> > > > > > > > > > @@ -26,6 +26,7 @@ config BOARD_SPECIFIC_OPTIONS #
> > dummy
> > > > > > > > > > imply CMD_FS_GENERIC
> > > > > > > > > > imply CMD_NET
> > > > > > > > > > imply CMD_PING
> > > > > > > > > > +   imply CMD_SF
> > > > > > > > > > imply CLK_SIFIVE
> > > > > > > > > > imply CLK_SIFIVE_FU540_PRCI
> > > > > > > > > > imply DOS_PARTITION
> > > > > > > > > > @@ -40,6 +41,8 @@ config BOARD_SPECIFIC_OPTIONS #
> > dummy
> > > > > > > > > > imply SIFIVE_SERIAL
> > > > > > > > > > imply SPI
> > > > > > > > > > imply SPI_SIFIVE
> > > > > > > > > > +   imply SPI_FLASH
> > > > > > > > > > +   imply SPI_FLASH_ISSI
> > > > > > > > > > imply MMC
> > > > > > > > > > imply MMC_SPI
> > > > > > > > > > imply MMC_BROKEN_CD
> > > > > > > > > > diff --git a/doc/board/sifive/fu540.rst
> > > > b/doc/board/sifive/fu540.rst
> > > > > > > > > > index 91b94ee06f..2e70cad02e 100644
> > > > > > > > > > --- a/doc/board/sifive/fu540.rst
> > > > > > > > > > +++ b/doc/board/sifive/fu540.rst
> > > > > > > > > > @@ -366,3 +366,22 @@ load uImage.
> > > > > > > > > 

Re: [PATCH v2 21/22] Use __ASSEMBLY__ as the assembly macros

2020-04-13 Thread Masahiro Yamada
On Fri, Apr 10, 2020 at 5:18 AM Simon Glass  wrote:
>
> Some places use __ASSEMBLER__ instead which does not work since the
> Makefile does not define it. Fix them.


In my understanding,
__ASSEMBLER__ is passed by the compiler
while building *.S files.

On which compiler didn't this work for you?




>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v2:
> - Add new patch to fix occurances of __ASSEMBLER__
>
>  arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h | 2 +-
>  arch/arm/include/asm/arch-mx27/regs-rtc.h  | 2 +-
>  arch/arm/include/asm/arch-mx5/imx-regs.h   | 2 +-
>  arch/arm/include/asm/arch-mx6/imx-regs.h   | 2 +-
>  arch/arm/include/asm/arch-mx7/imx-regs.h   | 2 +-
>  arch/arm/include/asm/arch-s32v234/imx-regs.h   | 2 +-
>  arch/arm/include/asm/arch-vf610/imx-regs.h | 2 +-
>  arch/arm/mach-socfpga/include/mach/clock_manager.h | 2 +-
>  arch/arm/mach-socfpga/include/mach/clock_manager_arria10.h | 4 ++--
>  arch/arm/mach-socfpga/include/mach/clock_manager_gen5.h| 4 ++--
>  arch/arm/mach-socfpga/include/mach/sdram_arria10.h | 2 +-
>  arch/arm/mach-stm32mp/include/mach/stm32.h | 2 +-
>  arch/x86/include/asm/mtrr.h| 2 +-
>  arch/x86/include/asm/sipi.h| 4 ++--
>  include/atf_common.h   | 2 +-
>  include/elf.h  | 4 ++--
>  16 files changed, 20 insertions(+), 20 deletions(-)
>
> 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 299201b1570..5d8a2d49a1d 100644
> --- a/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h
> +++ b/arch/arm/include/asm/arch-fsl-layerscape/immap_lsch3.h
> @@ -584,5 +584,5 @@ struct ccsr_serdes {
> u8 res5[0x19fc - 0xa00];
>  };
>
> -#endif /*__ASSEMBLY__*/
> +#endif /*__ASSEMBLY__ */
>  #endif /* __ARCH_FSL_LSCH3_IMMAP_H_ */
> diff --git a/arch/arm/include/asm/arch-mx27/regs-rtc.h 
> b/arch/arm/include/asm/arch-mx27/regs-rtc.h
> index d373ab15839..8434f4c1cb1 100644
> --- a/arch/arm/include/asm/arch-mx27/regs-rtc.h
> +++ b/arch/arm/include/asm/arch-mx27/regs-rtc.h
> @@ -21,6 +21,6 @@ struct rtc_regs {
> u32 dayr;
> u32 dayalarm;
>  };
> -#endif /* __ASSEMBLY__*/
> +#endif /* __ASSEMBLY__ */
>
>  #endif /* __MX28_REGS_RTC_H__ */
> diff --git a/arch/arm/include/asm/arch-mx5/imx-regs.h 
> b/arch/arm/include/asm/arch-mx5/imx-regs.h
> index fbb6e599b6d..3d1cc683228 100644
> --- a/arch/arm/include/asm/arch-mx5/imx-regs.h
> +++ b/arch/arm/include/asm/arch-mx5/imx-regs.h
> @@ -557,6 +557,6 @@ struct pwm_regs {
> u32 cnr;
>  };
>
> -#endif /* __ASSEMBLER__*/
> +#endif /* __ASSEMBLY__ */
>
>  #endif /* __ASM_ARCH_MX5_IMX_REGS_H__ */
> diff --git a/arch/arm/include/asm/arch-mx6/imx-regs.h 
> b/arch/arm/include/asm/arch-mx6/imx-regs.h
> index 4f01b20aedf..5b41a7a4b8b 100644
> --- a/arch/arm/include/asm/arch-mx6/imx-regs.h
> +++ b/arch/arm/include/asm/arch-mx6/imx-regs.h
> @@ -1003,5 +1003,5 @@ struct pwm_regs {
>   */
>  #defineis_boot_from_usb(void) (!(readl(USB_PHY0_BASE_ADDR) & 
> (1<<20)))
>
> -#endif /* __ASSEMBLER__*/
> +#endif /* __ASSEMBLY__ */
>  #endif /* __ASM_ARCH_MX6_IMX_REGS_H__ */
> diff --git a/arch/arm/include/asm/arch-mx7/imx-regs.h 
> b/arch/arm/include/asm/arch-mx7/imx-regs.h
> index 63365140072..7b23abbc7eb 100644
> --- a/arch/arm/include/asm/arch-mx7/imx-regs.h
> +++ b/arch/arm/include/asm/arch-mx7/imx-regs.h
> @@ -1223,5 +1223,5 @@ struct bootrom_sw_info {
> u32 reserved_3[3];
>  };
>
> -#endif /* __ASSEMBLER__*/
> +#endif /* __ASSEMBLY__ */
>  #endif /* __ASM_ARCH_MX7_IMX_REGS_H__ */
> diff --git a/arch/arm/include/asm/arch-s32v234/imx-regs.h 
> b/arch/arm/include/asm/arch-s32v234/imx-regs.h
> index 9a779cce965..1472a43f1bc 100644
> --- a/arch/arm/include/asm/arch-s32v234/imx-regs.h
> +++ b/arch/arm/include/asm/arch-s32v234/imx-regs.h
> @@ -323,6 +323,6 @@ struct mscm_ir {
> u32 ipcie[4];   /* Interconnect Parity Checking Injection 
> Enable Register   */
>  };
>
> -#endif /* __ASSEMBLER__ */
> +#endif /* __ASSEMBLY__ */
>
>  #endif /* __ASM_ARCH_IMX_REGS_H__ */
> diff --git a/arch/arm/include/asm/arch-vf610/imx-regs.h 
> b/arch/arm/include/asm/arch-vf610/imx-regs.h
> index ae0a187c4db..03def8e3c54 100644
> --- a/arch/arm/include/asm/arch-vf610/imx-regs.h
> +++ b/arch/arm/include/asm/arch-vf610/imx-regs.h
> @@ -474,6 +474,6 @@ struct mscm {
> u32 cpxcfg3;
>  };
>
> -#endif /* __ASSEMBLER__*/
> +#endif /* __ASSEMBLY__ */
>
>  #endif /* __ASM_ARCH_IMX_REGS_H__ */
> diff --git a/arch/arm/mach-socfpga/include/mach/clock_manager.h 
> b/arch/arm/mach-socfpga/include/mach/clock_manager.h
> index c6830582a5a..1f734bcd65e 100644
> --- a/arch/arm/mach-socfpga/include/mach/clock_manager.h
> +++ 

Re: XHCI bringup on the Raspberry Pi 4

2020-04-13 Thread Nicolas Saenz Julienne
Hi Bin,
sorry for the late reply but I was off for easter.

On Fri, 2020-04-03 at 13:54 +0800, Bin Meng wrote:
> Hi Nicolas,
> This is probably caused by the required structure setup by U-Boot is
> viewed as buggy by the xHCI controller, hence there is no response to
> the first "enable slot" command.

Yes, that's my impression too. That said I can't seem to find the faulty
config.

Since I wasn't all that clear on my previous mail, this is a VIA805 chip,
directly soldered on the board and interfaced with trough RPi4's PCIe bus (the
PCIe bus isn't exposed, so it's the only user). The Linux version of this works
fine, and is already supported upstream.

> Could you please compare all the data structures, with the one set up
> by the Linux kernel?

I've attached some logs comparing u-boot's and Linux's view of the registers. I
dumped them before and after calling the 'enable slot' command. I left all the
debuging information just in case it's helpful and also attached some patches
to show my changes.

Note that I thoughfully compared them myself. The only odd thing I found was
"USBSTS: 0x10" (Port Detect Change is set), which isn't the case in Linux. I
tried to clear it at different places (before and after changing the individual
port status), without effect.

That's all. If the data I sent is a little bit too dense, please tell me and
I'll remove all the less important stuff :).

Regards,
Nicolas

[8.764830] brcm-pcie fd50.pcie: host bridge /scb/pcie@7d50 ranges:
[8.775111] brcm-pcie fd50.pcie:   No bus range found for /scb/pcie@7d50, using [bus 00-ff]
[8.791685] brcm-pcie fd50.pcie:  MEM 0x06..0x0603ff -> 0x00f800
[8.805042] brcm-pcie fd50.pcie:   IB MEM 0x00..0x00bfff -> 0x00
[8.867783] brcm-pcie fd50.pcie: link up, 5.0 GT/s PCIe x1 (SSC)
[8.875862] brcm-pcie fd50.pcie: PCI host bridge to bus :00
[8.882702] pci_bus :00: root bus resource [bus 00-ff]
[8.893595] pci_bus :00: root bus resource [mem 0x6-0x603ff] (bus address [0xf800-0xfbff])
[8.905107] probe:pci_scan_child_bus_extend: pci_bus :00: scanning bus
[8.912665] pci :00:00.0: [14e4:2711] type 01 class 0x060400
[8.919467] pci :00:00.0: PME# supported from D0 D3hot
[8.925688] pci:pci_pme_active: pci :00:00.0: PME# disabled
[8.936010] probe:pci_scan_child_bus_extend: pci_bus :00: fixups for bus
[8.943491] probe:pci_scan_bridge_extend: pci :00:00.0: scanning [bus 00-00] behind bridge, pass 0
[8.953362] pci :00:00.0: bridge configuration invalid ([bus 00-00]), reconfiguring
[8.962120] probe:pci_scan_bridge_extend: pci :00:00.0: scanning [bus 00-00] behind bridge, pass 1
[8.968690] raspberrypi-clk raspberrypi-clk: CPU frequency range: min 6, max 15
[8.972081] probe:pci_scan_child_bus_extend: pci_bus :01: scanning bus
[8.988099] pci :01:00.0: [1106:3483] type 00 class 0x0c0330
[8.994591] pci :01:00.0: reg 0x10: [mem 0x-0x0fff 64bit]
[9.002104] pci :01:00.0: PME# supported from D0 D3cold
[9.008205] pci:pci_pme_active: pci :01:00.0: PME# disabled
[9.029244] probe:pci_scan_child_bus_extend: pci_bus :01: fixups for bus
[9.037199] probe:pci_scan_child_bus_extend: pci_bus :01: bus scan returning with max=01
[9.045944] pci_bus :01: busn_res: [bus 01-ff] end is updated to 01
[9.052744] probe:pci_scan_child_bus_extend: pci_bus :00: bus scan returning with max=01
[9.061428] pci :00:00.0: BAR 14: assigned [mem 0x6-0x6000f]
[9.068689] pci :01:00.0: BAR 0: assigned [mem 0x6-0x60fff 64bit]
[9.076400] pci :00:00.0: PCI bridge to [bus 01]
[9.081518] pci :00:00.0:   bridge window [mem 0x6-0x6000f]
[9.089020] pcieport :00:00.0: enabling device ( -> 0002)
[9.095340] pci:__pci_set_master: pcieport :00:00.0: enabling bus mastering
[9.103071] pcieport :00:00.0: PME: Signaling with IRQ 41
[9.109558] pcieport :00:00.0: AER: enabled with IRQ 41
[9.115694] pci:pci_save_state: pcieport :00:00.0: saving config space at offset 0x0 (reading 0x271114e4)
[9.125886] pci:pci_save_state: pcieport :00:00.0: saving config space at offset 0x4 (reading 0x16)
[9.135882] pci:pci_save_state: pcieport :00:00.0: saving config space at offset 0x8 (reading 0x6040010)
[9.145948] pci:pci_save_state: pcieport :00:00.0: saving config space at offset 0xc (reading 0x1)
[9.155870] pci:pci_save_state: pcieport :00:00.0: saving config space at offset 0x10 (reading 0x0)
[9.165505] pci:pci_save_state: pcieport :00:00.0: saving config space at offset 0x14 (reading 0x0)
[9.175111] pci:pci_save_state: pcieport :00:00.0: saving config space at offset 0x18 (reading 0x10100)
[9.185084] pci:pci_save_state: pcieport :00:00.0: saving config space at 

Re: [PATCH v1] colibri_t20: change maintainer

2020-04-13 Thread Igor Opaniuk
Hi Lucas,

On Mon, Apr 13, 2020 at 6:11 PM Igor Opaniuk  wrote:
>
> From: Igor Opaniuk 
>
> Take over maintainership for Colibri T20 module.
>
> Signed-off-by: Igor Opaniuk 
> ---
>
>  board/toradex/colibri_t20/MAINTAINERS | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/board/toradex/colibri_t20/MAINTAINERS 
> b/board/toradex/colibri_t20/MAINTAINERS
> index b251c000fe..2a8e6fb74b 100644
> --- a/board/toradex/colibri_t20/MAINTAINERS
> +++ b/board/toradex/colibri_t20/MAINTAINERS
> @@ -1,5 +1,5 @@
>  COLIBRI_T20
> -M: Lucas Stach 
> +M: Igor Opaniuk 
>  S: Maintained
>  F: board/toradex/colibri_t20/
>  F: include/configs/colibri_t20.h
> --
> 2.17.1
>

As you suggested before in PM, here is a patch for
taking ownership for Colibri T20.

Thanks

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


[PATCH v1] colibri_t20: change maintainer

2020-04-13 Thread Igor Opaniuk
From: Igor Opaniuk 

Take over maintainership for Colibri T20 module.

Signed-off-by: Igor Opaniuk 
---

 board/toradex/colibri_t20/MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/board/toradex/colibri_t20/MAINTAINERS 
b/board/toradex/colibri_t20/MAINTAINERS
index b251c000fe..2a8e6fb74b 100644
--- a/board/toradex/colibri_t20/MAINTAINERS
+++ b/board/toradex/colibri_t20/MAINTAINERS
@@ -1,5 +1,5 @@
 COLIBRI_T20
-M: Lucas Stach 
+M: Igor Opaniuk 
 S: Maintained
 F: board/toradex/colibri_t20/
 F: include/configs/colibri_t20.h
-- 
2.17.1



Re: [PATCH 1/1] imx: Kconfig: fix references to doc/README.mxc_hab

2020-04-13 Thread Heinrich Schuchardt
Am April 13, 2020 2:49:00 PM UTC schrieb Breno Matheus Lima 
:
>Hi Heinrich,
>
>Em dom., 12 de abr. de 2020 às 17:35, Heinrich Schuchardt
> escreveu:
>>
>> On 4/12/20 6:16 PM, Fabio Estevam wrote:
>> > Hi Heinrich,
>> >
>> > On Sun, Apr 12, 2020 at 11:23 AM Heinrich Schuchardt
> wrote:
>> >>
>> >> doc/README.mxc_hab was moved to
>doc/imx/habv4/guides/encrypted_boot.txt by
>> >> commit df11b0c4d4e3 ("doc: imx: reorganize i.MX documentation"),
>commit
>> >> dfe9ff9cc79b ("doc: imx: hab: Reorganize High Assurance Boot
>> >> documentation"), commit 8a23fc9c94bf ("doc: imx: habv4: Remove
>extra hab,
>> >> directory for a cleaner documentation structure"), and commit
>364c0a89bcfa
>> >> ("doc: imx: habv4: Move encrypted boot guide").
>> >>
>> >> Fixes: df11b0c4d4e3 ("doc: imx: reorganize i.MX documentation")
>> >> Fixes: dfe9ff9cc79b ("doc: imx: hab: Reorganize High Assurance
>Boot
>> >> documentation")
>> >> Fixes: 8a23fc9c94bf ("doc: imx: habv4: Remove extra hab, directory
>> >> for a cleaner documentation structure")
>> >> Fixes: commit 364c0a89bcfa ("doc: imx: habv4: Move encrypted boot
>guide").
>> >> Signed-off-by: Heinrich Schuchardt 
>> >> ---
>> >>  arch/arm/mach-imx/Kconfig | 6 +++---
>> >>  1 file changed, 3 insertions(+), 3 deletions(-)
>> >>
>> >> diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
>> >> index aa140c4798..44b47780ee 100644
>> >> --- a/arch/arm/mach-imx/Kconfig
>> >> +++ b/arch/arm/mach-imx/Kconfig
>> >> @@ -41,7 +41,7 @@ config IMX_HAB
>> >> imply CMD_DEKBLOB
>> >> help
>> >>   This option enables the support for secure boot (HAB).
>> >> - See doc/README.mxc_hab for more details.
>> >> + See doc/imx/habv4/guides/encrypted_boot.txt for more
>details.
>> >
>> > Thanks for your patch.
>> >
>> > Indeed, doc/README.mxc_hab is gone and we should replace it, but I
>was
>> > wondering if we should point the file to
>> > doc/imx/habv4/guides/mx6_mx7_secure_boot.txt instead.
>> >
>> > Breno,
>> >
>> > What do you think?
>>
>> It is doc/imx/habv4/guides/encrypted_boot.txt that mentions
>> CONFIG_IMX_HAB and CONFIG_CMD_DEKBLOB.
>>
>> Maybe both files can be merged. Anyway the imx directory should move
>to
>> doc/board and be integrated into doc/board/index.rst.
>>
>> Shouldn't the content of folder doc/imx be moved to
>doc/board/freescale/
>> and linked in doc/board/freescale/index.rst?
>>
>> We should be able to generate HTML documentation for imx using 'make
>> htmldocs'.
>
>Thanks for your feedback.
>
>Do you think we can convert this documentation to sphinx format and
>create an index.rst at doc/imx/? The HABv4 documentation is SoC
>specific and not board related.

Maybe besides an arch and a board folder we should have a doc/soc/ folder.

>
>Thanks,
>Breno Lima



[ANN] U-Boot v2020.04 released

2020-04-13 Thread Tom Rini
Hey all,

As I announced last week, I pushed v2020.04 out a week to handle some
regressions.  Things are looking better now, so here's the release.  As
I've been taking pull requests for the next branch, we're going to stick
with the general schedule for v2020.07 at this time.  If it becomes an
issue, I'll probably end up taking a few bigger pull requests than I
would like for -rc2.  Given the state of the world, if it takes people a
little longer to pull something together, that'll be just fine.

In terms of a changelog, 
git log --merges v2020.04-rc5..v2020.04
or
git log --merges v2020.01..v2020.04

The merge window is once again open and I plan to tag -rc1 on April
27th, bi-weekly -rcs thereafter and final release on July 6th, 2020.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/1] imx: Kconfig: fix references to doc/README.mxc_hab

2020-04-13 Thread Breno Matheus Lima
Hi Heinrich,

Em dom., 12 de abr. de 2020 às 17:35, Heinrich Schuchardt
 escreveu:
>
> On 4/12/20 6:16 PM, Fabio Estevam wrote:
> > Hi Heinrich,
> >
> > On Sun, Apr 12, 2020 at 11:23 AM Heinrich Schuchardt  
> > wrote:
> >>
> >> doc/README.mxc_hab was moved to doc/imx/habv4/guides/encrypted_boot.txt by
> >> commit df11b0c4d4e3 ("doc: imx: reorganize i.MX documentation"), commit
> >> dfe9ff9cc79b ("doc: imx: hab: Reorganize High Assurance Boot
> >> documentation"), commit 8a23fc9c94bf ("doc: imx: habv4: Remove extra hab,
> >> directory for a cleaner documentation structure"), and commit 364c0a89bcfa
> >> ("doc: imx: habv4: Move encrypted boot guide").
> >>
> >> Fixes: df11b0c4d4e3 ("doc: imx: reorganize i.MX documentation")
> >> Fixes: dfe9ff9cc79b ("doc: imx: hab: Reorganize High Assurance Boot
> >> documentation")
> >> Fixes: 8a23fc9c94bf ("doc: imx: habv4: Remove extra hab, directory
> >> for a cleaner documentation structure")
> >> Fixes: commit 364c0a89bcfa ("doc: imx: habv4: Move encrypted boot guide").
> >> Signed-off-by: Heinrich Schuchardt 
> >> ---
> >>  arch/arm/mach-imx/Kconfig | 6 +++---
> >>  1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
> >> index aa140c4798..44b47780ee 100644
> >> --- a/arch/arm/mach-imx/Kconfig
> >> +++ b/arch/arm/mach-imx/Kconfig
> >> @@ -41,7 +41,7 @@ config IMX_HAB
> >> imply CMD_DEKBLOB
> >> help
> >>   This option enables the support for secure boot (HAB).
> >> - See doc/README.mxc_hab for more details.
> >> + See doc/imx/habv4/guides/encrypted_boot.txt for more details.
> >
> > Thanks for your patch.
> >
> > Indeed, doc/README.mxc_hab is gone and we should replace it, but I was
> > wondering if we should point the file to
> > doc/imx/habv4/guides/mx6_mx7_secure_boot.txt instead.
> >
> > Breno,
> >
> > What do you think?
>
> It is doc/imx/habv4/guides/encrypted_boot.txt that mentions
> CONFIG_IMX_HAB and CONFIG_CMD_DEKBLOB.
>
> Maybe both files can be merged. Anyway the imx directory should move to
> doc/board and be integrated into doc/board/index.rst.
>
> Shouldn't the content of folder doc/imx be moved to doc/board/freescale/
> and linked in doc/board/freescale/index.rst?
>
> We should be able to generate HTML documentation for imx using 'make
> htmldocs'.

Thanks for your feedback.

Do you think we can convert this documentation to sphinx format and
create an index.rst at doc/imx/? The HABv4 documentation is SoC
specific and not board related.

Thanks,
Breno Lima


Re: [PATCH 2/2] clk: set flags in the ccf registration routines

2020-04-13 Thread dariobin


> Il 13 aprile 2020 alle 15.02 Sean Anderson  ha scritto:
> 
> 
> On 4/13/20 8:36 AM, Dario Binacchi wrote:
> > The top-level framework flags are passed as parameter to the common
> > clock framework (ccf) registration routines without being used.
> > Checks of the flags setting added by the patch have been added in the
> > ccf test.
> > 
> > Signed-off-by: Dario Binacchi 
> 
> Are you planning on making behaviour depend on the flags? 
No, I am not planning developments depending on flags. 
Except that during the implementation of a driver for an omap clock divider I 
had the opportunity to take a look at the code of the ccf clock-divider driver, 
and more generally to the ccf drivers. I was amazed that in the registration 
routines the flags parameter was not assigned to the clk structure flags field.

Thanks and regards
Dario Binacchi
> As far as I
> can tell, none of them are actually used in the CCF. It seems like they
> were carried over from Linux.
> 
> --Sean


Re: [PATCH 2/2] clk: set flags in the ccf registration routines

2020-04-13 Thread Sean Anderson
On 4/13/20 8:36 AM, Dario Binacchi wrote:
> The top-level framework flags are passed as parameter to the common
> clock framework (ccf) registration routines without being used.
> Checks of the flags setting added by the patch have been added in the
> ccf test.
> 
> Signed-off-by: Dario Binacchi 

Are you planning on making behaviour depend on the flags? As far as I
can tell, none of them are actually used in the CCF. It seems like they
were carried over from Linux.

--Sean


[PATCH 2/2] clk: set flags in the ccf registration routines

2020-04-13 Thread Dario Binacchi
The top-level framework flags are passed as parameter to the common
clock framework (ccf) registration routines without being used.
Checks of the flags setting added by the patch have been added in the
ccf test.

Signed-off-by: Dario Binacchi 

---

 drivers/clk/clk-composite.c| 1 +
 drivers/clk/clk-divider.c  | 1 +
 drivers/clk/clk-fixed-factor.c | 1 +
 drivers/clk/clk-gate.c | 1 +
 drivers/clk/clk-mux.c  | 1 +
 drivers/clk/clk_sandbox_ccf.c  | 3 ++-
 test/dm/clk_ccf.c  | 7 +++
 7 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
index 414185031e..fac524a32e 100644
--- a/drivers/clk/clk-composite.c
+++ b/drivers/clk/clk-composite.c
@@ -140,6 +140,7 @@ struct clk *clk_register_composite(struct device *dev, 
const char *name,
}
 
clk = >clk;
+   clk->flags = flags;
ret = clk_register(clk, UBOOT_DM_CLK_COMPOSITE, name,
   parent_names[clk_composite_get_parent(clk)]);
if (ret) {
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index d79ae367b8..bbd4c20be1 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -213,6 +213,7 @@ static struct clk *_register_divider(struct device *dev, 
const char *name,
 
/* register the clock */
clk = >clk;
+   clk->flags = flags;
 
ret = clk_register(clk, UBOOT_DM_CLK_CCF_DIVIDER, name, parent_name);
if (ret) {
diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
index 2ceb6bb171..386bf63e87 100644
--- a/drivers/clk/clk-fixed-factor.c
+++ b/drivers/clk/clk-fixed-factor.c
@@ -50,6 +50,7 @@ struct clk *clk_hw_register_fixed_factor(struct device *dev,
fix->mult = mult;
fix->div = div;
clk = >clk;
+   clk->flags = flags;
 
ret = clk_register(clk, UBOOT_DM_CLK_IMX_FIXED_FACTOR, name,
   parent_name);
diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index 6415c2f1b9..b684dbd5fa 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -143,6 +143,7 @@ struct clk *clk_register_gate(struct device *dev, const 
char *name,
 #endif
 
clk = >clk;
+   clk->flags = flags;
 
ret = clk_register(clk, UBOOT_DM_CLK_GATE, name, parent_name);
if (ret) {
diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index b9d2ae6778..c10409bada 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -188,6 +188,7 @@ struct clk *clk_hw_register_mux_table(struct device *dev, 
const char *name,
 #endif
 
clk = >clk;
+   clk->flags = flags;
 
/*
 * Read the current mux setup - so we assign correct parent.
diff --git a/drivers/clk/clk_sandbox_ccf.c b/drivers/clk/clk_sandbox_ccf.c
index b1bcbadc6d..78fd15e623 100644
--- a/drivers/clk/clk_sandbox_ccf.c
+++ b/drivers/clk/clk_sandbox_ccf.c
@@ -129,6 +129,7 @@ struct clk *sandbox_clk_register_gate2(struct device *dev, 
const char *name,
 
gate->state = 0;
clk = >clk;
+   clk->flags = flags;
 
ret = clk_register(clk, "sandbox_clk_gate2", name, parent_name);
if (ret) {
@@ -271,7 +272,7 @@ static int sandbox_clk_ccf_probe(struct udevice *dev)
reg = BIT(28) | BIT(24) | BIT(16);
clk_dm(SANDBOX_CLK_I2C,
   sandbox_clk_composite("i2c", i2c_sels, ARRAY_SIZE(i2c_sels),
-, 0));
+, CLK_SET_RATE_UNGATE));
 
clk_dm(SANDBOX_CLK_I2C_ROOT,
   sandbox_clk_gate2("i2c_root", "i2c", base + 0x7c, 0));
diff --git a/test/dm/clk_ccf.c b/test/dm/clk_ccf.c
index d37c6f9f09..bb5f4db1f7 100644
--- a/test/dm/clk_ccf.c
+++ b/test/dm/clk_ccf.c
@@ -29,11 +29,13 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
ret = clk_get_by_id(SANDBOX_CLK_ECSPI_ROOT, );
ut_assertok(ret);
ut_asserteq_str("ecspi_root", clk->dev->name);
+   ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
 
/* Test for clk_get_parent_rate() */
ret = clk_get_by_id(SANDBOX_CLK_ECSPI1, );
ut_assertok(ret);
ut_asserteq_str("ecspi1", clk->dev->name);
+   ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
 
rate = clk_get_parent_rate(clk);
ut_asserteq(rate, 2000);
@@ -42,6 +44,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
ret = clk_get_by_id(SANDBOX_CLK_ECSPI0, );
ut_assertok(ret);
ut_asserteq_str("ecspi0", clk->dev->name);
+   ut_asserteq(CLK_SET_RATE_PARENT, clk->flags);
 
rate = clk_get_parent_rate(clk);
ut_asserteq(rate, 2000);
@@ -50,6 +53,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
ret = clk_get_by_id(SANDBOX_CLK_USDHC1_SEL, );
ut_assertok(ret);
ut_asserteq_str("usdhc1_sel", clk->dev->name);
+   ut_asserteq(CLK_SET_RATE_NO_REPARENT, clk->flags);
 
rate = 

[PATCH 0/2] Set clock flags in the ccf registration routines

2020-04-13 Thread Dario Binacchi


Test for ccf gated clock has been added too.


Dario Binacchi (2):
  dm: test: clk: add the test for the ccf gated clock
  clk: set flags in the ccf registration routines

 drivers/clk/clk-composite.c|  1 +
 drivers/clk/clk-divider.c  |  1 +
 drivers/clk/clk-fixed-factor.c |  1 +
 drivers/clk/clk-gate.c |  1 +
 drivers/clk/clk-mux.c  |  1 +
 drivers/clk/clk_sandbox_ccf.c  |  7 ++-
 include/sandbox-clk.h  |  8 
 test/dm/clk_ccf.c  | 15 +++
 8 files changed, 34 insertions(+), 1 deletion(-)

-- 
2.17.1



[PATCH 1/2] dm: test: clk: add the test for the ccf gated clock

2020-04-13 Thread Dario Binacchi
Unlike the other clock types, in the case of the gated clock, a new
driver has been developed which does not use the registering routine
provided by the common clock framework.
The addition of the ecspi0 clock to sandbox therefore allows testing
the ccf gate clock.

Signed-off-by: Dario Binacchi 
---

 drivers/clk/clk_sandbox_ccf.c | 4 
 include/sandbox-clk.h | 8 
 test/dm/clk_ccf.c | 8 
 3 files changed, 20 insertions(+)

diff --git a/drivers/clk/clk_sandbox_ccf.c b/drivers/clk/clk_sandbox_ccf.c
index 3543bea70d..b1bcbadc6d 100644
--- a/drivers/clk/clk_sandbox_ccf.c
+++ b/drivers/clk/clk_sandbox_ccf.c
@@ -249,6 +249,10 @@ static int sandbox_clk_ccf_probe(struct udevice *dev)
clk_dm(SANDBOX_CLK_ECSPI_ROOT,
   sandbox_clk_divider("ecspi_root", "pll3_60m", , 19, 6));
 
+   reg = 0;
+   clk_dm(SANDBOX_CLK_ECSPI0,
+  sandbox_clk_gate("ecspi0", "ecspi_root", , 0, 0));
+
clk_dm(SANDBOX_CLK_ECSPI1,
   sandbox_clk_gate2("ecspi1", "ecspi_root", base + 0x6c, 0));
 
diff --git a/include/sandbox-clk.h b/include/sandbox-clk.h
index 296cddfbb0..c2616c27a4 100644
--- a/include/sandbox-clk.h
+++ b/include/sandbox-clk.h
@@ -50,6 +50,14 @@ static inline struct clk *sandbox_clk_divider(const char 
*name,
reg, shift, width, 0);
 }
 
+static inline struct clk *sandbox_clk_gate(const char *name, const char 
*parent,
+  void __iomem *reg, u8 bit_idx,
+  u8 clk_gate_flags)
+{
+   return clk_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT,
+reg, bit_idx, clk_gate_flags, NULL);
+}
+
 struct clk *sandbox_clk_register_gate2(struct device *dev, const char *name,
   const char *parent_name,
   unsigned long flags,
diff --git a/test/dm/clk_ccf.c b/test/dm/clk_ccf.c
index ae3a4d8a76..d37c6f9f09 100644
--- a/test/dm/clk_ccf.c
+++ b/test/dm/clk_ccf.c
@@ -38,6 +38,14 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
rate = clk_get_parent_rate(clk);
ut_asserteq(rate, 2000);
 
+   /* test the gate of CCF */
+   ret = clk_get_by_id(SANDBOX_CLK_ECSPI0, );
+   ut_assertok(ret);
+   ut_asserteq_str("ecspi0", clk->dev->name);
+
+   rate = clk_get_parent_rate(clk);
+   ut_asserteq(rate, 2000);
+
/* Test the mux of CCF */
ret = clk_get_by_id(SANDBOX_CLK_USDHC1_SEL, );
ut_assertok(ret);
-- 
2.17.1



Re: [PATCH 3/3] rockchip: evb-rv1108: enable board early init

2020-04-13 Thread Otavio Salvador
On Sun, Apr 12, 2020 at 10:39 PM Kever Yang  wrote:
>
> Enable board early init callback to init board specific hardware.
>
> Signed-off-by: Kever Yang 

Please send the same patch to elgin-rv1108 config.


-- 
Otavio Salvador O.S. Systems
http://www.ossystems.com.brhttp://code.ossystems.com.br
Mobile: +55 (53) 9 9981-7854  Mobile: +1 (347) 903-9750


[PATCH] rockchip: rk3328: add rock-pi-e-rk3328_defconfig

2020-04-13 Thread b.l.huang
The ROCK-PI-E is a credit card size SBC based on Rockchip RK3328
Quad-Core ARM Cortex A53.

Net - Dual ethernet port, 1 X Gbe, 1 X 100M
USB - USB 3.0
DC  - USB-Type C, 5V 2A
Storage - TF card, eMMC

Just build u-boot-dtb.bin for Rockpi E board and follow the blow
steps to replace the relevant partition.

  ./rkbin/tools/loaderimage --pack --uboot u-boot-dtb.bin \
  uboot.img 0x20 --size 1024 1
  dd if=uboot.img of=/dev/sdcard seek=16384 conv=notrunc

Signed-off-by: banglang.huang 
---

Changes for v3

- rename to rock-pi-e

Changes for v2

- add introduction for rockpie in doc/README.rockchip
- enable CONFIG_MISC_INIT_R, CONFIG_SMBIOS_MANUFACTURER,
  and CONFIG_SMBIOS_PRODUCT_NAME

 arch/arm/dts/Makefile |   3 +-
 arch/arm/dts/rk3328-rock-pi-e-u-boot.dtsi |  12 +
 arch/arm/dts/rk3328-rock-pi-e.dts | 256 ++
 board/rockchip/evb_rk3328/MAINTAINERS |   7 +
 configs/rock-pi-e-rk3328_defconfig|  99 +
 doc/README.rockchip   |   3 +-
 6 files changed, 378 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/dts/rk3328-rock-pi-e-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3328-rock-pi-e.dts
 create mode 100644 configs/rock-pi-e-rk3328_defconfig

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 820ee9733a..f0897f2928 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -104,7 +104,8 @@ dtb-$(CONFIG_ROCKCHIP_RK3308) += \
 
 dtb-$(CONFIG_ROCKCHIP_RK3328) += \
rk3328-evb.dtb \
-   rk3328-rock64.dtb
+   rk3328-rock64.dtb \
+   rk3328-rock-pi-e.dtb
 
 dtb-$(CONFIG_ROCKCHIP_RK3368) += \
rk3368-lion.dtb \
diff --git a/arch/arm/dts/rk3328-rock-pi-e-u-boot.dtsi 
b/arch/arm/dts/rk3328-rock-pi-e-u-boot.dtsi
new file mode 100644
index 00..012209110a
--- /dev/null
+++ b/arch/arm/dts/rk3328-rock-pi-e-u-boot.dtsi
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2020 Radxa
+ */
+
+#include "rk3328-u-boot.dtsi"
+#include "rk3328-sdram-ddr3-666.dtsi"
+
+_host0_xhci {
+   vbus-supply = <_host_xhci>;
+   status = "okay";
+};
diff --git a/arch/arm/dts/rk3328-rock-pi-e.dts 
b/arch/arm/dts/rk3328-rock-pi-e.dts
new file mode 100644
index 00..56b8c3f1e6
--- /dev/null
+++ b/arch/arm/dts/rk3328-rock-pi-e.dts
@@ -0,0 +1,256 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2020 Radxa
+ */
+
+/dts-v1/;
+#include "rk3328.dtsi"
+
+/ {
+   model = "Radxa Rockpi E";
+   compatible = "radxa,rockpie", "rockchip,rk3328";
+
+   chosen {
+   stdout-path = 
+   };
+
+   gmac_clkin: external-gmac-clock {
+   compatible = "fixed-clock";
+   clock-frequency = <12500>;
+   clock-output-names = "gmac_clkin";
+   #clock-cells = <0>;
+   };
+
+   vcc3v3_sdmmc: sdmmc-pwren {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc3v3";
+   gpio = < 30 GPIO_ACTIVE_LOW>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_gpio>;
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   vin-supply = <_io>;
+   };
+
+   vcc5v0_host_xhci: vcc5v0-host-xhci-drv {
+   compatible = "regulator-fixed";
+   enable-active-high;
+   regulator-name = "vcc5v0_host_xhci";
+   gpio = < 7 GPIO_ACTIVE_HIGH>;
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   };
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   bus-width = <4>;
+   cap-mmc-highspeed;
+   cap-sd-highspeed;
+   card-detect-delay = <200>;
+   disable-wp;
+   max-frequency = <15000>;
+   num-slots = <1>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_clk>, <_cmd>, <_dectn>, 
<_bus4>;
+   supports-sd;
+   vmmc-supply = <_sdmmc>;
+   status = "okay";
+};
+
+ {
+   bus-width = <8>;
+   cap-mmc-highspeed;
+   mmc-hs200-1_8v;
+   supports-emmc;
+   disable-wp;
+   non-removable;
+   num-slots = <1>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_clk _cmd _bus8>;
+   vmmc-supply = <_io>;
+   vqmmc-supply = <_18emmc>;
+   status = "okay";
+};
+
+ {
+   phy-supply = <_io>;
+   phy-mode = "rgmii";
+   clock_in_out = "input";
+   snps,reset-gpio = < RK_PC2 GPIO_ACTIVE_LOW>;
+   snps,reset-active-low;
+   snps,reset-delays-us = <0 1 5>;
+   assigned-clocks = < SCLK_MAC2IO>, < SCLK_MAC2IO_EXT>;
+   assigned-clock-parents = <_clkin>, <_clkin>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   tx_delay = <0x26>;
+   rx_delay = <0x11>;
+   status = "okay";
+};
+
+_host0_ehci {
+   

[PATCH] rockchip: rk3328: add rock-pi-e-rk3328_defconfig

2020-04-13 Thread b.l.huang
The ROCK-PI-E is a credit card size SBC based on Rockchip RK3328
Quad-Core ARM Cortex A53.

Net - Dual ethernet port, 1 X Gbe, 1 X 100M
USB - USB 3.0
DC  - USB-Type C, 5V 2A
Storage - TF card, eMMC

Just build u-boot-dtb.bin for Rockpi E board and follow the blow
steps to replace the relevant partition.

  ./rkbin/tools/loaderimage --pack --uboot u-boot-dtb.bin \
  uboot.img 0x20 --size 1024 1
  dd if=uboot.img of=/dev/sdcard seek=16384 conv=notrunc

Signed-off-by: banglang.huang 
---

Changes for v3

- rename to rock-pi-e

Changes for v2

- add introduction for rockpie in doc/README.rockchip
- enable CONFIG_MISC_INIT_R, CONFIG_SMBIOS_MANUFACTURER,
  and CONFIG_SMBIOS_PRODUCT_NAME

 arch/arm/dts/Makefile |   3 +-
 arch/arm/dts/rk3328-rock-pi-e-u-boot.dtsi |  12 +
 arch/arm/dts/rk3328-rock-pi-e.dts | 256 ++
 board/rockchip/evb_rk3328/MAINTAINERS |   7 +
 configs/rock-pi-e-rk3328_defconfig|  99 +
 doc/README.rockchip   |   3 +-
 6 files changed, 378 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/dts/rk3328-rock-pi-e-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3328-rock-pi-e.dts
 create mode 100644 configs/rock-pi-e-rk3328_defconfig

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 820ee9733a..f0897f2928 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -104,7 +104,8 @@ dtb-$(CONFIG_ROCKCHIP_RK3308) += \
 
 dtb-$(CONFIG_ROCKCHIP_RK3328) += \
rk3328-evb.dtb \
-   rk3328-rock64.dtb
+   rk3328-rock64.dtb \
+   rk3328-rock-pi-e.dtb
 
 dtb-$(CONFIG_ROCKCHIP_RK3368) += \
rk3368-lion.dtb \
diff --git a/arch/arm/dts/rk3328-rock-pi-e-u-boot.dtsi 
b/arch/arm/dts/rk3328-rock-pi-e-u-boot.dtsi
new file mode 100644
index 00..012209110a
--- /dev/null
+++ b/arch/arm/dts/rk3328-rock-pi-e-u-boot.dtsi
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2020 Radxa
+ */
+
+#include "rk3328-u-boot.dtsi"
+#include "rk3328-sdram-ddr3-666.dtsi"
+
+_host0_xhci {
+   vbus-supply = <_host_xhci>;
+   status = "okay";
+};
diff --git a/arch/arm/dts/rk3328-rock-pi-e.dts 
b/arch/arm/dts/rk3328-rock-pi-e.dts
new file mode 100644
index 00..56b8c3f1e6
--- /dev/null
+++ b/arch/arm/dts/rk3328-rock-pi-e.dts
@@ -0,0 +1,256 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2020 Radxa
+ */
+
+/dts-v1/;
+#include "rk3328.dtsi"
+
+/ {
+   model = "Radxa Rockpi E";
+   compatible = "radxa,rockpie", "rockchip,rk3328";
+
+   chosen {
+   stdout-path = 
+   };
+
+   gmac_clkin: external-gmac-clock {
+   compatible = "fixed-clock";
+   clock-frequency = <12500>;
+   clock-output-names = "gmac_clkin";
+   #clock-cells = <0>;
+   };
+
+   vcc3v3_sdmmc: sdmmc-pwren {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc3v3";
+   gpio = < 30 GPIO_ACTIVE_LOW>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_gpio>;
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   vin-supply = <_io>;
+   };
+
+   vcc5v0_host_xhci: vcc5v0-host-xhci-drv {
+   compatible = "regulator-fixed";
+   enable-active-high;
+   regulator-name = "vcc5v0_host_xhci";
+   gpio = < 7 GPIO_ACTIVE_HIGH>;
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   };
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   bus-width = <4>;
+   cap-mmc-highspeed;
+   cap-sd-highspeed;
+   card-detect-delay = <200>;
+   disable-wp;
+   max-frequency = <15000>;
+   num-slots = <1>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_clk>, <_cmd>, <_dectn>, 
<_bus4>;
+   supports-sd;
+   vmmc-supply = <_sdmmc>;
+   status = "okay";
+};
+
+ {
+   bus-width = <8>;
+   cap-mmc-highspeed;
+   mmc-hs200-1_8v;
+   supports-emmc;
+   disable-wp;
+   non-removable;
+   num-slots = <1>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_clk _cmd _bus8>;
+   vmmc-supply = <_io>;
+   vqmmc-supply = <_18emmc>;
+   status = "okay";
+};
+
+ {
+   phy-supply = <_io>;
+   phy-mode = "rgmii";
+   clock_in_out = "input";
+   snps,reset-gpio = < RK_PC2 GPIO_ACTIVE_LOW>;
+   snps,reset-active-low;
+   snps,reset-delays-us = <0 1 5>;
+   assigned-clocks = < SCLK_MAC2IO>, < SCLK_MAC2IO_EXT>;
+   assigned-clock-parents = <_clkin>, <_clkin>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   tx_delay = <0x26>;
+   rx_delay = <0x11>;
+   status = "okay";
+};
+
+_host0_ehci {
+   

Re: [PATCH 00/11] Fixes for Nokia RX-51

2020-04-13 Thread Pali Rohár
On Wednesday 01 April 2020 00:35:07 Pali Rohár wrote:
> This patch series contain fixes for Nokia RX-51 board (aka N900).
> After these changes it is possible to run U-Boot in qemu emulator again.
> And U-Boot can boot kernel image from RAM, eMMC or OneNAND memory without
> problem.
> 
> Pali Rohár (11):
>   Nokia RX-51: Update my email address
>   Nokia RX-51: Add README.nokia_rx51 file to MAINTAINERS
>   Nokia RX-51: Move comment about CONFIG_SYS_TEXT_BASE to correct place
>   Nokia RX-51: Move code from defconfig back to C header file
>   Nokia RX-51: Revert back onenand defitions
>   Nokia RX-51: Remove PART* macros
>   Nokia RX-51: Remember setup_console_atag option
>   Nokia RX-51: Enable CONFIG_CONSOLE_MUX
>   Nokia RX-51: Disable some unused features to decrease size of u-boot
> binary
>   Nokia RX-51: Update README.nokia_rx51
>   Nokia RX-51: Add automated test for running RX-51 build in qemu

Hello! Could you please review this patch series?

>  .travis.yml  |  10 ++
>  board/nokia/rx51/MAINTAINERS |   3 +-
>  board/nokia/rx51/lowlevel_init.S |  11 +-
>  board/nokia/rx51/rx51.c  |  43 ---
>  board/nokia/rx51/rx51.h  |   2 +-
>  board/nokia/rx51/tag_omap.h  |   4 +-
>  cmd/bootmenu.c   |   2 +-
>  configs/nokia_rx51_defconfig |  27 +++-
>  doc/README.bootmenu  |   2 +-
>  doc/README.nokia_rx51|  32 +++--
>  include/ansi.h   |   2 +-
>  include/configs/nokia_rx51.h |  88 -
>  test/rx51_test.sh| 208 +++
>  13 files changed, 327 insertions(+), 107 deletions(-)
>  create mode 100755 test/rx51_test.sh
> 
> -- 
> 2.20.1
> 


Re: [PATCH v3] mmc: zynq: parse dt when probing

2020-04-13 Thread Michal Simek
On 11. 04. 20 11:03, Benedikt Grassl wrote:
> Currently, the entry "bus-width = <8>" in the ZynqMP's sdhci nodes
> is not evaluated. This results in the bus width staying at its default
> value (4 bit in HS200 mode).
> Fix this by calling mmc_of_parse. This function also checks for the
> "no-1-8-v" and "max-frequency" entries. Remove the handling of those
> nodes from this driver.
> 
> Signed-off-by: Benedikt Grassl 
> ---
>  drivers/mmc/sdhci.c  |  3 +--
>  drivers/mmc/zynq_sdhci.c | 16 +++-
>  include/sdhci.h  |  1 -
>  3 files changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
> index 520c9f9feb..372dc0a820 100644
> --- a/drivers/mmc/sdhci.c
> +++ b/drivers/mmc/sdhci.c
> @@ -839,8 +839,7 @@ int sdhci_setup_cfg(struct mmc_config *cfg, struct 
> sdhci_host *host,
>   cfg->host_caps &= ~MMC_MODE_HS_52MHz;
>   }
>  
> - if (!(cfg->voltages & MMC_VDD_165_195) ||
> - (host->quirks & SDHCI_QUIRK_NO_1_8_V))
> + if (!(cfg->voltages & MMC_VDD_165_195))
>   caps_1 &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 |
>   SDHCI_SUPPORT_DDR50);
>  
> diff --git a/drivers/mmc/zynq_sdhci.c b/drivers/mmc/zynq_sdhci.c
> index da3ff53da1..d0a43d9539 100644
> --- a/drivers/mmc/zynq_sdhci.c
> +++ b/drivers/mmc/zynq_sdhci.c
> @@ -22,14 +22,12 @@ DECLARE_GLOBAL_DATA_PTR;
>  struct arasan_sdhci_plat {
>   struct mmc_config cfg;
>   struct mmc mmc;
> - unsigned int f_max;
>  };
>  
>  struct arasan_sdhci_priv {
>   struct sdhci_host *host;
>   u8 deviceid;
>   u8 bank;
> - u8 no_1p8;
>  };
>  
>  #if defined(CONFIG_ARCH_ZYNQMP)
> @@ -238,8 +236,11 @@ static int arasan_sdhci_probe(struct udevice *dev)
>   host->quirks |= SDHCI_QUIRK_BROKEN_HISPD_MODE;
>  #endif
>  
> - if (priv->no_1p8)
> - host->quirks |= SDHCI_QUIRK_NO_1_8_V;
> + plat->cfg.f_max = CONFIG_ZYNQ_SDHCI_MAX_FREQ;
> +
> + ret = mmc_of_parse(dev, >cfg);
> + if (ret)
> + return ret;
>  
>   host->max_clk = clock;
>  
> @@ -247,10 +248,11 @@ static int arasan_sdhci_probe(struct udevice *dev)
>   host->mmc->dev = dev;
>   host->mmc->priv = host;
>  
> - ret = sdhci_setup_cfg(>cfg, host, plat->f_max,
> + ret = sdhci_setup_cfg(>cfg, host, plat->cfg.f_max,
> CONFIG_ZYNQ_SDHCI_MIN_FREQ);
>   if (ret)
>   return ret;
> +
>   upriv->mmc = host->mmc;
>  
>   return sdhci_probe(dev);
> @@ -258,7 +260,6 @@ static int arasan_sdhci_probe(struct udevice *dev)
>  
>  static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)
>  {
> - struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
>   struct arasan_sdhci_priv *priv = dev_get_priv(dev);
>  
>   priv->host = calloc(1, sizeof(struct sdhci_host));
> @@ -277,10 +278,7 @@ static int arasan_sdhci_ofdata_to_platdata(struct 
> udevice *dev)
>  
>   priv->deviceid = dev_read_u32_default(dev, "xlnx,device_id", -1);
>   priv->bank = dev_read_u32_default(dev, "xlnx,mio_bank", -1);
> - priv->no_1p8 = dev_read_bool(dev, "no-1-8-v");
>  
> - plat->f_max = dev_read_u32_default(dev, "max-frequency",
> -CONFIG_ZYNQ_SDHCI_MAX_FREQ);
>   return 0;
>  }
>  
> diff --git a/include/sdhci.h b/include/sdhci.h
> index aa4378fd57..0ef8c2ed62 100644
> --- a/include/sdhci.h
> +++ b/include/sdhci.h
> @@ -243,7 +243,6 @@
>  #define SDHCI_QUIRK_BROKEN_HISPD_MODEBIT(5)
>  #define SDHCI_QUIRK_WAIT_SEND_CMD(1 << 6)
>  #define SDHCI_QUIRK_USE_WIDE8(1 << 8)
> -#define SDHCI_QUIRK_NO_1_8_V (1 << 9)
>  
>  /* to make gcc happy */
>  struct sdhci_host;
> 

Looks good. Will apply.

M


[PATCH] arm64: zynqmp: Fix irps5401 device nodes

2020-04-13 Thread Michal Simek
- Do not use irps54012 as device node which is not correct.
- Fix addresses of irps5401/u180 on zcu104 revisions.
- Remove clock-cells property. It is PMIC without any clock output.
- Define irps5401 nodes in zynqmp-e-a2197

Signed-off-by: Michal Simek 
---

 arch/arm/dts/zynqmp-e-a2197-00-revA.dts | 16 +---
 arch/arm/dts/zynqmp-zcu104-revA.dts | 10 --
 arch/arm/dts/zynqmp-zcu104-revC.dts | 10 --
 arch/arm/dts/zynqmp-zcu111-revA.dts |  9 +++--
 arch/arm/dts/zynqmp-zcu208-revA.dts |  6 ++
 arch/arm/dts/zynqmp-zcu216-revA.dts |  6 ++
 6 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/arch/arm/dts/zynqmp-e-a2197-00-revA.dts 
b/arch/arm/dts/zynqmp-e-a2197-00-revA.dts
index 65cf5914945d..bf982e221830 100644
--- a/arch/arm/dts/zynqmp-e-a2197-00-revA.dts
+++ b/arch/arm/dts/zynqmp-e-a2197-00-revA.dts
@@ -198,9 +198,6 @@
#size-cells = <0>;
reg = <0>;
/* u152 IR35215 0x16/0x46 vcc_soc */
-   /* u160 IRPS5401 0x17/0x47 */
-   /* u167 IRPS5401 0x1c/0x4c */
-   /* u175 IRPS5401 0x1d/0x4d */
/* u179 ir38164 0x19/0x49 vcco_500 */
/* u181 ir38164 0x1a/0x4a vcco_501 */
/* u183 ir38164 0x1b/0x4b vcco_502 */
@@ -209,6 +206,19 @@
/* u189 ir38164 0x20/0x50 mgtyavtt */
/* u194 ir38164 0x13/0x43 vdd1_1v8_lp4 */
/* u195 ir38164 0x14/0x44 vdd2_1v8_lp4 */
+
+   irps5401_47: irps5401@47 { /* IRPS5401 - u160 */
+   compatible = "infineon,irps5401";
+   reg = <0x47>; /* pmbus / i2c 0x17 */
+   };
+   irps5401_4c: irps5401@4c { /* IRPS5401 - u167 */
+   compatible = "infineon,irps5401";
+   reg = <0x4c>; /* pmbus / i2c 0x1c */
+   };
+   irps5401_4d: irps5401@4d { /* IRPS5401 - u175 */
+   compatible = "infineon,irps5401";
+   reg = <0x4d>; /* pmbus / i2c 0x1d */
+   };
};
i2c@1 { /* PMBUS1_INA226 */
#address-cells = <1>;
diff --git a/arch/arm/dts/zynqmp-zcu104-revA.dts 
b/arch/arm/dts/zynqmp-zcu104-revA.dts
index 3ceb39dce02b..a4bd6b800a18 100644
--- a/arch/arm/dts/zynqmp-zcu104-revA.dts
+++ b/arch/arm/dts/zynqmp-zcu104-revA.dts
@@ -147,15 +147,13 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <2>;
-   irps5401_43: irps54012@43 { /* IRPS5401 - u175 */
-   #clock-cells = <0>;
+   irps5401_43: irps5401@43 { /* IRPS5401 - u175 */
compatible = "infineon,irps5401";
-   reg = <0x43>;
+   reg = <0x43>; /* pmbus / i2c 0x13 */
};
-   irps5401_4d: irps54012@4d { /* IRPS5401 - u180 */
-   #clock-cells = <0>;
+   irps5401_44: irps5401@44 { /* IRPS5401 - u180 */
compatible = "infineon,irps5401";
-   reg = <0x4d>;
+   reg = <0x44>; /* pmbus / i2c 0x14 */
};
};
 
diff --git a/arch/arm/dts/zynqmp-zcu104-revC.dts 
b/arch/arm/dts/zynqmp-zcu104-revC.dts
index 7dad4523deb0..d4b3769a27cc 100644
--- a/arch/arm/dts/zynqmp-zcu104-revC.dts
+++ b/arch/arm/dts/zynqmp-zcu104-revC.dts
@@ -172,15 +172,13 @@
#address-cells = <1>;
#size-cells = <0>;
reg = <2>;
-   irps5401_43: irps54012@43 { /* IRPS5401 - u175 */
-   #clock-cells = <0>;
+   irps5401_43: irps5401@43 { /* IRPS5401 - u175 */
compatible = "infineon,irps5401";
-   reg = <0x43>;
+   reg = <0x43>; /* pmbus / i2c 0x13 */
};
-   irps5401_4d: irps54012@4d { /* IRPS5401 - u180 */
-   #clock-cells = <0>;
+   irps5401_44: irps5401@44 { /* IRPS5401 - u180 */
compatible = "infineon,irps5401";
-   reg = <0x4d>;
+   reg = <0x44>; /* pmbus / i2c 0x14 */
};
};
 
diff --git a/arch/arm/dts/zynqmp-zcu111-revA.dts 
b/arch/arm/dts/zynqmp-zcu111-revA.dts
index d16bf8ac7ac7..63e285fe9a9a 100644
--- a/arch/arm/dts/zynqmp-zcu111-revA.dts
+++ 

[PATCH] common: Add Kconfig option for FDT mem alignment

2020-04-13 Thread Michal Simek
From: Ashok Reddy Soma 

FDT memory is aligned by 4KB. This is hardcoded in common/board_f.c.
Add Kconfig option, assign default value of 0x1000 and enable option to
change this value.

Signed-off-by: Ashok Reddy Soma 
Signed-off-by: Michal Simek 
---

 common/board_f.c | 3 ++-
 dts/Kconfig  | 7 +++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/common/board_f.c b/common/board_f.c
index 82a164752aa3..928874e03555 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -546,7 +546,8 @@ static int reserve_fdt(void)
 * will be relocated with other data.
 */
if (gd->fdt_blob) {
-   gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
+   gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) +
+CONFIG_FDT_MEM_ALIGN_SIZE, 32);
 
gd->start_addr_sp -= gd->fdt_size;
gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
diff --git a/dts/Kconfig b/dts/Kconfig
index 046a54a17366..696c0b71afaf 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -121,6 +121,13 @@ config DEFAULT_DEVICE_TREE
  It can be overridden from the command line:
  $ make DEVICE_TREE=
 
+config FDT_MEM_ALIGN_SIZE
+   hex "FDT memory alignment size"
+   default 0x1000
+   help
+ This option is used to set the default alignment when reserving memory
+ for fdt.
+
 config OF_LIST
string "List of device tree files to include for DT control"
depends on SPL_LOAD_FIT || MULTI_DTB_FIT
-- 
2.26.0



[PATCH 2/2] xilinx: Move bootmode detection to separate function

2020-04-13 Thread Michal Simek
Create special function for reading bootmode on Versal and ZynqMP.
Zynq is using specific function (without mask) already.
Future patches will be calling this function from different location too.

Signed-off-by: Michal Simek 
---

 board/xilinx/versal/board.c  | 23 ---
 board/xilinx/zynqmp/zynqmp.c | 28 +++-
 2 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/board/xilinx/versal/board.c b/board/xilinx/versal/board.c
index 2900dfb44e93..483e3ce2f79a 100644
--- a/board/xilinx/versal/board.c
+++ b/board/xilinx/versal/board.c
@@ -82,9 +82,23 @@ int board_early_init_r(void)
return 0;
 }
 
-int board_late_init(void)
+static u8 versal_get_bootmode(void)
 {
+   u8 bootmode;
u32 reg = 0;
+
+   reg = readl(_base->boot_mode_usr);
+
+   if (reg >> BOOT_MODE_ALT_SHIFT)
+   reg >>= BOOT_MODE_ALT_SHIFT;
+
+   bootmode = reg & BOOT_MODES_MASK;
+
+   return bootmode;
+}
+
+int board_late_init(void)
+{
u8 bootmode;
struct udevice *dev;
int bootseq = -1;
@@ -99,12 +113,7 @@ int board_late_init(void)
return 0;
}
 
-   reg = readl(_base->boot_mode_usr);
-
-   if (reg >> BOOT_MODE_ALT_SHIFT)
-   reg >>= BOOT_MODE_ALT_SHIFT;
-
-   bootmode = reg & BOOT_MODES_MASK;
+   bootmode = versal_get_bootmode();
 
puts("Bootmode: ");
switch (bootmode) {
diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index 66a43974e68d..a2a0d563318e 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -552,9 +552,26 @@ static int set_fdtfile(void)
return 0;
 }
 
-int board_late_init(void)
+static u8 zynqmp_get_bootmode(void)
 {
+   u8 bootmode;
u32 reg = 0;
+   int ret;
+
+   ret = zynqmp_mmio_read((ulong)_base->boot_mode, );
+   if (ret)
+   return -EINVAL;
+
+   if (reg >> BOOT_MODE_ALT_SHIFT)
+   reg >>= BOOT_MODE_ALT_SHIFT;
+
+   bootmode = reg & BOOT_MODES_MASK;
+
+   return bootmode;
+}
+
+int board_late_init(void)
+{
u8 bootmode;
struct udevice *dev;
int bootseq = -1;
@@ -578,14 +595,7 @@ int board_late_init(void)
if (ret)
return ret;
 
-   ret = zynqmp_mmio_read((ulong)_base->boot_mode, );
-   if (ret)
-   return -EINVAL;
-
-   if (reg >> BOOT_MODE_ALT_SHIFT)
-   reg >>= BOOT_MODE_ALT_SHIFT;
-
-   bootmode = reg & BOOT_MODES_MASK;
+   bootmode = zynqmp_get_bootmode();
 
puts("Bootmode: ");
switch (bootmode) {
-- 
2.26.0



[PATCH 1/2] xilinx: Move initrd_high setup to common location

2020-04-13 Thread Michal Simek
Moving to common location initrd_high is also setup for Zynq which hasn't
done in run time code.

Signed-off-by: Michal Simek 
---

 board/xilinx/common/board.c   | 7 +++
 board/xilinx/versal/board.c   | 6 --
 board/xilinx/zynqmp/zynqmp.c  | 6 --
 include/configs/zynq-common.h | 1 -
 4 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index 7c191e53fb71..294a59df77da 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "board.h"
 
 int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
@@ -75,7 +76,13 @@ void *board_fdt_blob_setup(void)
 
 int board_late_init_xilinx(void)
 {
+   ulong initrd_hi;
+
env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET);
 
+   initrd_hi = gd->start_addr_sp - CONFIG_STACK_SIZE;
+   initrd_hi = round_down(initrd_hi, SZ_16M);
+   env_set_addr("initrd_high", (void *)initrd_hi);
+
return 0;
 }
diff --git a/board/xilinx/versal/board.c b/board/xilinx/versal/board.c
index 908ea87163f8..2900dfb44e93 100644
--- a/board/xilinx/versal/board.c
+++ b/board/xilinx/versal/board.c
@@ -16,7 +16,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "../common/board.h"
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -94,7 +93,6 @@ int board_late_init(void)
const char *mode;
char *new_targets;
char *env_targets;
-   ulong initrd_hi;
 
if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
debug("Saved variables - Skipping\n");
@@ -201,10 +199,6 @@ int board_late_init(void)
 
env_set("boot_targets", new_targets);
 
-   initrd_hi = gd->start_addr_sp - CONFIG_STACK_SIZE;
-   initrd_hi = round_down(initrd_hi, SZ_16M);
-   env_set_addr("initrd_high", (void *)initrd_hi);
-
return board_late_init_xilinx();
 }
 
diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index b2172356ad0a..66a43974e68d 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "../common/board.h"
 
 #include "pm_cfg_obj.h"
@@ -565,7 +564,6 @@ int board_late_init(void)
char *new_targets;
char *env_targets;
int ret;
-   ulong initrd_hi;
 
 #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
usb_ether_init();
@@ -692,10 +690,6 @@ int board_late_init(void)
 
env_set("boot_targets", new_targets);
 
-   initrd_hi = gd->start_addr_sp - CONFIG_STACK_SIZE;
-   initrd_hi = round_down(initrd_hi, SZ_16M);
-   env_set_addr("initrd_high", (void *)initrd_hi);
-
reset_reason();
 
return board_late_init_xilinx();
diff --git a/include/configs/zynq-common.h b/include/configs/zynq-common.h
index 1eaf65b0a2a1..4ccc31e37655 100644
--- a/include/configs/zynq-common.h
+++ b/include/configs/zynq-common.h
@@ -198,7 +198,6 @@
 #ifndef CONFIG_EXTRA_ENV_SETTINGS
 #define CONFIG_EXTRA_ENV_SETTINGS  \
"fdt_high=0x2000\0" \
-   "initrd_high=0x2000\0"  \
"scriptaddr=0x2\0"  \
"script_size_f=0x4\0"   \
"fdt_addr_r=0x1f0\0"\
-- 
2.26.0



[PATCH] arm64: zynqmp: Add label to GPIO lines for boot mode and POR

2020-04-13 Thread Michal Simek
From: Saeed Nowshadi 

Add label to GPIO lines controlling boot mode and POR EMIO pins so System
Controller can assert those lines on Versal.

Signed-off-by: Saeed Nowshadi 
Signed-off-by: Michal Simek 
---

 arch/arm/dts/zynqmp-e-a2197-00-revA.dts | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/dts/zynqmp-e-a2197-00-revA.dts 
b/arch/arm/dts/zynqmp-e-a2197-00-revA.dts
index 39b5d7fff9ac..65cf5914945d 100644
--- a/arch/arm/dts/zynqmp-e-a2197-00-revA.dts
+++ b/arch/arm/dts/zynqmp-e-a2197-00-revA.dts
@@ -162,9 +162,9 @@
  "", "", "", "", "", /* 65 - 69 */
  "", "", "", "", "", /* 70 - 74 */
  "", "ETH_MDC", "ETH_MDIO", /* 75 - 77, MIO end and EMIO start 
*/
- "", "", /* 78 - 79 */
- "", "", "", "", "", /* 80 - 84 */
- "", "", "", "", "", /* 85 -89 */
+ "SYSCTLR_VERSAL_MODE0", "SYSCTLR_VERSAL_MODE1", /* 78 - 79 */
+ "SYSCTLR_VERSAL_MODE2", "SYSCTLR_VERSAL_MODE3", 
"SYSCTLR_POR_B_LS", "", "", /* 80 - 84 */
+ "", "", "", "", "", /* 85 - 89 */
  "", "", "", "", "", /* 90 - 94 */
  "", "", "", "", "", /* 95 - 99 */
  "", "", "", "", "", /* 100 - 104 */
-- 
2.26.0



[PATCH] clk: versal: Fix watchdog clock issue

2020-04-13 Thread Michal Simek
From: T Karthik Reddy 

Enable mux based clocks to populate LPD_LSBUS clock to xilinx_wwdt
driver. Skip reading clock rate for the mux based clocks with
parent clock id is zero.

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

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

diff --git a/drivers/clk/clk_versal.c b/drivers/clk/clk_versal.c
index d3673a5c8b81..075a08380d84 100644
--- a/drivers/clk/clk_versal.c
+++ b/drivers/clk/clk_versal.c
@@ -503,6 +503,9 @@ static u64 versal_clock_calc(u32 clk_id)
 NODE_CLASS_MASK) == NODE_SUBCLASS_CLOCK_REF)
return versal_clock_ref(clk_id);
 
+   if (!parent_id)
+   return 0;
+
clk_rate = versal_clock_calc(parent_id);
 
if (versal_clock_div(clk_id)) {
@@ -526,7 +529,7 @@ static int versal_clock_get_rate(u32 clk_id, u64 *clk_rate)
 NODE_CLASS_MASK) == NODE_SUBCLASS_CLOCK_OUT &&
((clk_id >> NODE_CLASS_SHIFT) &
 NODE_CLASS_MASK) == NODE_CLASS_CLOCK) {
-   if (!versal_clock_gate(clk_id))
+   if (!versal_clock_gate(clk_id) && !versal_clock_mux(clk_id))
return -EINVAL;
*clk_rate = versal_clock_calc(clk_id);
return 0;
-- 
2.26.0