[PATCH] arm64: a37xx: increase CONFIG_SYS_BOOTM_LEN to 64MB

2020-09-06 Thread Andre Heider
From: Vladimir Vid 

Increase max gunzip size, required for booting itb recovery images on
uDPU.

Signed-off-by: Vladimir Vid 
[a.heider: adapt to mainline]
Signed-off-by: Andre Heider 
---

Patch taken from OpenWRT's uboot-mvebu package.

 include/configs/mvebu_armada-37xx.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/configs/mvebu_armada-37xx.h 
b/include/configs/mvebu_armada-37xx.h
index 905ce09b7a..27428d5a0f 100644
--- a/include/configs/mvebu_armada-37xx.h
+++ b/include/configs/mvebu_armada-37xx.h
@@ -6,6 +6,8 @@
 #ifndef _CONFIG_MVEBU_ARMADA_37XX_H
 #define _CONFIG_MVEBU_ARMADA_37XX_H
 
+#include 
+
 /*
  * High Level Configuration Options (easy to change)
  */
@@ -13,6 +15,8 @@
 /* additions for new ARM relocation support */
 #define CONFIG_SYS_SDRAM_BASE  0x
 
+#define CONFIG_SYS_BOOTM_LEN   SZ_64M /* Increase max gunzip size */
+
 /* auto boot */
 
 #define CONFIG_SYS_BAUDRATE_TABLE  { 9600, 19200, 38400, 57600, \
-- 
2.28.0



[PATCH] mtd: spi-nor-ids: add support for Macronix mx25u12835f flash

2020-09-06 Thread Andre Heider
From: Vladimir Vid 

Some of Marvell A3700 boards use mx25u12835f, specifically uDPU
and ESPRESSObin v7.

Signed-off-by: Vladimir Vid 
[a.heider: adapt commit message to mainline]
Signed-off-by: Andre Heider 
---

Patch taken from OpenWRT's uboot-mvebu package.

 drivers/mtd/spi/spi-nor-ids.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/spi/spi-nor-ids.c b/drivers/mtd/spi/spi-nor-ids.c
index 114ebacde1..bc9d4f7e9f 100644
--- a/drivers/mtd/spi/spi-nor-ids.c
+++ b/drivers/mtd/spi/spi-nor-ids.c
@@ -151,6 +151,7 @@ const struct flash_info spi_nor_ids[] = {
{ INFO("mx25u3235f",  0xc22536, 0, 4 * 1024,  1024, SECT_4K) },
{ INFO("mx25u6435f",  0xc22537, 0, 64 * 1024, 128, SECT_4K) },
{ INFO("mx25l12805d", 0xc22018, 0, 64 * 1024, 256, 0) },
+   { INFO("mx25u12835f", 0xc22538, 0, 64 * 1024, 256, SECT_4K) },
{ INFO("mx25l12855e", 0xc22618, 0, 64 * 1024, 256, 0) },
{ INFO("mx25l25635e", 0xc22019, 0, 64 * 1024, 512, SPI_NOR_DUAL_READ | 
SPI_NOR_QUAD_READ) },
{ INFO("mx25u25635f", 0xc22539, 0, 64 * 1024, 512, SECT_4K | 
SPI_NOR_4B_OPCODES) },
-- 
2.28.0



Re: [PATCH 3/5] spi: spi-uclass: Block dm_scan_fdt_dev with OF_CONTROL to prevent build failures

2020-09-06 Thread Lokesh Vutla
Jagan,

On 02/09/20 4:48 pm, Faiz Abbas wrote:
> There are devices which don't use OF_CONTROL or OF_PLATDATA but instead
> rely on statically defined platdata. Block dm_scan_fdt_dev() with both
> configs to avoid build failures under this condition.
> 
> Signed-off-by: Faiz Abbas 

Can you ack this patch?

Thanks and regards,
Lokesh

> ---
>  drivers/spi/spi-uclass.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
> index cffd9cf0b0..55a8eed890 100644
> --- a/drivers/spi/spi-uclass.c
> +++ b/drivers/spi/spi-uclass.c
> @@ -497,7 +497,7 @@ UCLASS_DRIVER(spi) = {
>   .id = UCLASS_SPI,
>   .name   = "spi",
>   .flags  = DM_UC_FLAG_SEQ_ALIAS,
> -#if !CONFIG_IS_ENABLED(OF_PLATDATA)
> +#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
>   .post_bind  = dm_scan_fdt_dev,
>  #endif
>   .post_probe = spi_post_probe,
> 


Re: [PATCH 5/5] arm: mach-omap2: am33xx: Add device structure for spi

2020-09-06 Thread Lokesh Vutla



On 02/09/20 4:48 pm, Faiz Abbas wrote:
> Add platform data and a device structure for the spi device
> present on am335x-icev2. This requires moving all omap3_spi
> platform data structures and symbols to an omap3_spi.h so that
> the board file can access them.
> 
> Signed-off-by: Faiz Abbas 
> ---
>  arch/arm/mach-omap2/am33xx/board.c | 12 +
>  drivers/spi/omap3_spi.c| 70 +--
>  include/configs/am335x_evm.h   |  4 ++
>  include/omap3_spi.h| 78 ++
>  4 files changed, 95 insertions(+), 69 deletions(-)
>  create mode 100644 include/omap3_spi.h
> 
> diff --git a/arch/arm/mach-omap2/am33xx/board.c 
> b/arch/arm/mach-omap2/am33xx/board.c
> index a7b56b6bb3..2c2b38721f 100644
> --- a/arch/arm/mach-omap2/am33xx/board.c
> +++ b/arch/arm/mach-omap2/am33xx/board.c
> @@ -14,6 +14,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -142,6 +143,17 @@ U_BOOT_DEVICES(am33xx_gpios) = {
>  #endif
>  };
>  #endif
> +#if CONFIG_IS_ENABLED(DM_SPI) && !CONFIG_IS_ENABLED(OF_CONTROL)
> +static const struct omap3_spi_plat omap3_spi_pdata = {
> + .regs = (struct mcspi *)AM33XX_SPI_OFFSET,
> + .pin_dir = MCSPI_PINDIR_D0_IN_D1_OUT,
> +};
> +
> +U_BOOT_DEVICE(am33xx_spi) = {
> + .name = "omap3_spi",
> + .platdata = &omap3_spi_pdata,
> +};
> +#endif
>  #endif
>  
>  #if !CONFIG_IS_ENABLED(DM_GPIO)
> diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
> index 08daacf6f0..56cb217486 100644
> --- a/drivers/spi/omap3_spi.c
> +++ b/drivers/spi/omap3_spi.c
> @@ -22,82 +22,14 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  DECLARE_GLOBAL_DATA_PTR;
>  
> -#define OMAP4_MCSPI_REG_OFFSET   0x100
> -
>  struct omap2_mcspi_platform_config {
>   unsigned int regs_offset;
>  };
>  
> -/* per-register bitmasks */
> -#define OMAP3_MCSPI_SYSCONFIG_SMARTIDLE (2 << 3)
> -#define OMAP3_MCSPI_SYSCONFIG_ENAWAKEUP BIT(2)
> -#define OMAP3_MCSPI_SYSCONFIG_AUTOIDLE   BIT(0)
> -#define OMAP3_MCSPI_SYSCONFIG_SOFTRESET BIT(1)
> -
> -#define OMAP3_MCSPI_SYSSTATUS_RESETDONE BIT(0)
> -
> -#define OMAP3_MCSPI_MODULCTRL_SINGLE BIT(0)
> -#define OMAP3_MCSPI_MODULCTRL_MS BIT(2)
> -#define OMAP3_MCSPI_MODULCTRL_STEST  BIT(3)
> -
> -#define OMAP3_MCSPI_CHCONF_PHA   BIT(0)
> -#define OMAP3_MCSPI_CHCONF_POL   BIT(1)
> -#define OMAP3_MCSPI_CHCONF_CLKD_MASK GENMASK(5, 2)
> -#define OMAP3_MCSPI_CHCONF_EPOL  BIT(6)
> -#define OMAP3_MCSPI_CHCONF_WL_MASK   GENMASK(11, 7)
> -#define OMAP3_MCSPI_CHCONF_TRM_RX_ONLY   BIT(12)
> -#define OMAP3_MCSPI_CHCONF_TRM_TX_ONLY   BIT(13)
> -#define OMAP3_MCSPI_CHCONF_TRM_MASK  GENMASK(13, 12)
> -#define OMAP3_MCSPI_CHCONF_DMAW  BIT(14)
> -#define OMAP3_MCSPI_CHCONF_DMAR  BIT(15)
> -#define OMAP3_MCSPI_CHCONF_DPE0  BIT(16)
> -#define OMAP3_MCSPI_CHCONF_DPE1  BIT(17)
> -#define OMAP3_MCSPI_CHCONF_ISBIT(18)
> -#define OMAP3_MCSPI_CHCONF_TURBO BIT(19)
> -#define OMAP3_MCSPI_CHCONF_FORCE BIT(20)
> -
> -#define OMAP3_MCSPI_CHSTAT_RXS   BIT(0)
> -#define OMAP3_MCSPI_CHSTAT_TXS   BIT(1)
> -#define OMAP3_MCSPI_CHSTAT_EOT   BIT(2)
> -
> -#define OMAP3_MCSPI_CHCTRL_ENBIT(0)
> -#define OMAP3_MCSPI_CHCTRL_DIS   (0 << 0)
> -
> -#define OMAP3_MCSPI_WAKEUPENABLE_WKENBIT(0)
> -#define MCSPI_PINDIR_D0_IN_D1_OUT0
> -#define MCSPI_PINDIR_D0_OUT_D1_IN1
> -
> -#define OMAP3_MCSPI_MAX_FREQ 4800
> -#define SPI_WAIT_TIMEOUT 10
> -
> -/* OMAP3 McSPI registers */
> -struct mcspi_channel {
> - unsigned int chconf;/* 0x2C, 0x40, 0x54, 0x68 */
> - unsigned int chstat;/* 0x30, 0x44, 0x58, 0x6C */
> - unsigned int chctrl;/* 0x34, 0x48, 0x5C, 0x70 */
> - unsigned int tx;/* 0x38, 0x4C, 0x60, 0x74 */
> - unsigned int rx;/* 0x3C, 0x50, 0x64, 0x78 */
> -};
> -
> -struct mcspi {
> - unsigned char res1[0x10];
> - unsigned int sysconfig; /* 0x10 */
> - unsigned int sysstatus; /* 0x14 */
> - unsigned int irqstatus; /* 0x18 */
> - unsigned int irqenable; /* 0x1C */
> - unsigned int wakeupenable;  /* 0x20 */
> - unsigned int syst;  /* 0x24 */
> - unsigned int modulctrl; /* 0x28 */
> - struct mcspi_channel channel[4];
> - /* channel0: 0x2C - 0x3C, bus 0 & 1 & 2 & 3 */
> - /* channel1: 0x40 - 0x50, bus 0 & 1 */
> - /* channel2: 0x54 - 0x64, bus 0 & 1 */
> - /* channel3: 0x68 - 0x78, bus 0 */
> -};
> -
>  struct omap3_spi_priv {
>   struct mcspi *regs;
>   unsigned int cs;
> diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h
> index 9c4ef369c5..db1a89ad30 100644
> --- a/include/configs/am335x_evm.h
> +++ b/include/configs/am335x_evm.h
> @@ -281,6 +281,10 @@
>

[PATCH v4] arm: socfpga: add board support for ic-automation Moritz III

2020-09-06 Thread Nico Becker

Hello,
sorry for the e-mail again.
i check the repo today, but the board is still missing.
can you tell me how long it take to push it in the main branch?
will it be there in future, or was the patch rejected.

thanks a lot, i wish you a great start into the week.



Re: [PATCH v3 01/12] binman: Allow entry args to be required

2020-09-06 Thread Michal Simek
Hi Simon,

On 05. 09. 20 23:10, Simon Glass wrote:
> If an entry argument is needed by an entry but the entry argument is not
> present, then a strange error can occur when trying to read the file.
> 
> Fix this by allowing arguments to be required. Select this option for the
> cros-ec-rw entry. If a filename is provided in the node, allow that to be
> used.
> 
> Also tidy up a few related tests to make the error string easier to find,
> and fully ignore unused return values.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> (no changes since v1)
> 
>  tools/binman/README.entries |  7 ++-
>  tools/binman/etype/blob_named_by_arg.py | 10 ++
>  tools/binman/etype/cros_ec_rw.py|  3 +--
>  tools/binman/ftest.py   | 15 +++
>  4 files changed, 24 insertions(+), 11 deletions(-)
> 
> Applied to u-boot-dm/next, thanks!

Did you start to use patman for sending this?
Just curios because I am missing indentation in origin message.

Thanks,
Michal



[PATCH v6 16/17] test/py: efi_capsule: test for FIT image capsule

2020-09-06 Thread AKASHI Takahiro
The test can run on sandbox build and it attempts to execute a firmware
update via a capsule-on-disk, using a FIT image capsule,
CONFIG_EFI_CAPSULE_FIT.

To run this test successfully, you need configure U-Boot specifically;
See test_capsule_firmware.py for requirements, and hence it won't run
on Travis CI, at least, for now.

Signed-off-by: AKASHI Takahiro 
---
 test/py/tests/test_efi_capsule/conftest.py|  69 +++
 test/py/tests/test_efi_capsule/defs.py|  12 ++
 .../test_efi_capsule/test_capsule_firmware.py | 178 ++
 .../tests/test_efi_capsule/uboot_bin_env.its  |  36 
 tools/mkeficapsule.c  |   3 +-
 5 files changed, 297 insertions(+), 1 deletion(-)
 create mode 100644 test/py/tests/test_efi_capsule/conftest.py
 create mode 100644 test/py/tests/test_efi_capsule/defs.py
 create mode 100644 test/py/tests/test_efi_capsule/test_capsule_firmware.py
 create mode 100644 test/py/tests/test_efi_capsule/uboot_bin_env.its

diff --git a/test/py/tests/test_efi_capsule/conftest.py 
b/test/py/tests/test_efi_capsule/conftest.py
new file mode 100644
index ..4e7c36f04ba5
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/conftest.py
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2020, Linaro Limited
+# Author: AKASHI Takahiro 
+
+import os
+import os.path
+import re
+from subprocess import call, check_call, check_output, CalledProcessError
+import pytest
+from defs import *
+
+#
+# Fixture for UEFI secure boot test
+#
+
+
+@pytest.fixture(scope='session')
+def efi_capsule_data(request, u_boot_config):
+"""Set up a file system to be used in UEFI capsule test.
+
+Args:
+request: Pytest request object.
+u_boot_config: U-boot configuration.
+
+Return:
+A path to disk image to be used for testing
+"""
+mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
+data_dir = mnt_point + CAPSULE_DATA_DIR
+install_dir = mnt_point + CAPSULE_INSTALL_DIR
+image_path = u_boot_config.persistent_data_dir + '/test_efi_capsule.img'
+
+try:
+# Create a target device
+check_call('dd if=/dev/zero of=./spi.bin bs=1MiB count=16', shell=True)
+
+check_call('rm -rf %s' % mnt_point, shell=True)
+check_call('mkdir -p %s' % data_dir, shell=True)
+check_call('mkdir -p %s' % install_dir, shell=True)
+
+# Create capsule files
+# two regions: one for u-boot.bin and the other for u-boot.env
+check_call('cd %s; echo -n u-boot:Old > u-boot.bin.old; echo -n 
u-boot:New > u-boot.bin.new; echo -n u-boot-env:Old -> u-boot.env.old; echo -n 
u-boot-env:New > u-boot.env.new' % data_dir,
+   shell=True)
+check_call('sed -e \"s?BINFILE1?u-boot.bin.new?\" -e 
\"s?BINFILE2?u-boot.env.new?\" 
%s/test/py/tests/test_efi_capsule/uboot_bin_env.its > %s/uboot_bin_env.its' %
+   (u_boot_config.source_dir, data_dir),
+   shell=True)
+check_call('cd %s; %s/tools/mkimage -f uboot_bin_env.its 
uboot_bin_env.itb' %
+   (data_dir, u_boot_config.build_dir),
+   shell=True)
+check_call('cd %s; %s/tools/mkeficapsule --fit uboot_bin_env.itb 
--version 1 --index 1 Test01' %
+   (data_dir, u_boot_config.build_dir),
+   shell=True)
+
+# Create a disk image with EFI system partition
+check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' 
%
+   (mnt_point, image_path), shell=True)
+check_call('sgdisk %s -A 1:set:0 -t 
1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B' %
+   image_path, shell=True)
+
+except CalledProcessError as exception:
+pytest.skip('Setup failed: %s' % exception.cmd)
+return
+else:
+yield image_path
+finally:
+call('rm -rf %s' % mnt_point, shell=True)
+call('rm -f %s' % image_path, shell=True)
+call('rm -f ./spi.bin', shell=True)
diff --git a/test/py/tests/test_efi_capsule/defs.py 
b/test/py/tests/test_efi_capsule/defs.py
new file mode 100644
index ..2c5b0ee49beb
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/defs.py
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier:  GPL-2.0+
+
+# Size in MiB
+EFI_BOOTDEV_IMAGE_SIZE = 16
+EFI_BOOTDEV_PART_SIZE = 8
+
+# Owner guid
+GUID = '----123456789abc'
+
+# Directories
+CAPSULE_DATA_DIR = '/EFI/CapsuleTestData'
+CAPSULE_INSTALL_DIR = '/EFI/UpdateCapsule'
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware.py 
b/test/py/tests/test_efi_capsule/test_capsule_firmware.py
new file mode 100644
index ..ab7c2a7d6bea
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware.py
@@ -0,0 +1,178 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2020, Linaro Limited
+# Author: AKASHI Takahiro 
+#
+# U-Boot UEFI: Firmware Update Test
+
+"""
+This test verifies capsule-on-disk fi

[PATCH v6 17/17] test/py: efi_capsule: test for raw image capsule

2020-09-06 Thread AKASHI Takahiro
The test can run on sandbox build and it attempts to execute a firmware
update via a capsule-on-disk, using a raw image capsule,
CONFIG_EFI_CAPSULE_RAW.

To run this test successfully, you need configure U-Boot specifically;
See test_capsule_firmware.py for requirements, and hence it won't run
on Travis CI, at least, for now.

Signed-off-by: AKASHI Takahiro 
---
 test/py/tests/test_efi_capsule/conftest.py|  3 +
 .../test_efi_capsule/test_capsule_firmware.py | 63 +++
 2 files changed, 66 insertions(+)

diff --git a/test/py/tests/test_efi_capsule/conftest.py 
b/test/py/tests/test_efi_capsule/conftest.py
index 4e7c36f04ba5..4544a24d5351 100644
--- a/test/py/tests/test_efi_capsule/conftest.py
+++ b/test/py/tests/test_efi_capsule/conftest.py
@@ -51,6 +51,9 @@ def efi_capsule_data(request, u_boot_config):
 check_call('cd %s; %s/tools/mkeficapsule --fit uboot_bin_env.itb 
--version 1 --index 1 Test01' %
(data_dir, u_boot_config.build_dir),
shell=True)
+check_call('cd %s; %s/tools/mkeficapsule --raw u-boot.bin.new 
--version 1 --index 1 Test02' %
+   (data_dir, u_boot_config.build_dir),
+   shell=True)
 
 # Create a disk image with EFI system partition
 check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' 
%
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware.py 
b/test/py/tests/test_efi_capsule/test_capsule_firmware.py
index ab7c2a7d6bea..c9b180ac65e8 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware.py
@@ -15,6 +15,7 @@ from defs import *
 
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.buildconfigspec('efi_capsule_firmware_fit')
+@pytest.mark.buildconfigspec('efi_capsule_firmware_raw')
 @pytest.mark.buildconfigspec('efi_capsule_on_disk')
 @pytest.mark.buildconfigspec('dfu')
 @pytest.mark.buildconfigspec('dfu_sf')
@@ -176,3 +177,65 @@ class TestEfiCapsuleFirmwareFit(object):
 'sf read 400 15 10',
 'md.b 400 10'])
 assert 'u-boot-env:New' in ''.join(output)
+
+def test_efi_capsule_fw3(
+self, u_boot_config, u_boot_console, efi_capsule_data):
+"""
+Test Case 3 - Update U-Boot on SPI Flash, raw image format
+  0x10-0x15: U-Boot binary (but dummy)
+"""
+disk_img = efi_capsule_data
+with u_boot_console.log.section('Test Case 3-a, before reboot'):
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'efidebug boot add 1 TEST host 0:1 /helloworld.efi ""',
+'efidebug boot order 1',
+'env set -e -nv -bs -rt OsIndications =0x0004',
+'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x10 
0x5;u-boot-env raw 0x15 0x20"',
+'env save'])
+
+# initialize content
+output = u_boot_console.run_command_list([
+'sf probe 0:0',
+'fatload host 0:1 400 %s/u-boot.bin.old' % 
CAPSULE_DATA_DIR,
+'sf write 400 10 10',
+'sf read 500 10 10',
+'md.b 500 10'])
+assert 'Old' in ''.join(output)
+
+# place a capsule file
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 %s/Test02' % CAPSULE_DATA_DIR,
+'fatwrite host 0:1 400 %s/Test02 $filesize' % 
CAPSULE_INSTALL_DIR,
+'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+assert 'Test02' in ''.join(output)
+
+# reboot
+u_boot_console.restart_uboot()
+
+capsule_early = u_boot_config.buildconfig.get(
+'config_efi_capsule_on_disk_early')
+with u_boot_console.log.section('Test Case 3-b, after reboot'):
+if not capsule_early:
+# make sure that dfu_alt_info exists even persistent variables
+# are not available.
+output = u_boot_console.run_command_list([
+'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x10 
0x5;u-boot-env raw 0x15 0x20"',
+'host bind 0 %s' % disk_img,
+'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+assert 'Test02' in ''.join(output)
+
+# need to run uefi command to initiate capsule handling
+output = u_boot_console.run_command(
+'env print -e -all Capsule')
+
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
+assert 'Test02' not in ''.join(output)
+
+output = u_boot_console.run_command_list([
+'sf probe 0:0',
+'sf read 400

[PATCH v6 14/17] cmd: add "efidebug capsule" command

2020-09-06 Thread AKASHI Takahiro
"efidebug capsule" is more or less a debugging utility.
  efidebug capsule update: invoke UpdateCapsule against data on memory
  efidebug capsule show: show a capsule header
  efidebug capsule result: dump a capsule result variable

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

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 9874838b005a..ad7aa4a304a2 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -18,6 +18,228 @@
 #include 
 
 #define BS systab.boottime
+#define RT systab.runtime
+
+#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
+/**
+ * do_efi_capsule_update() - process a capsule update
+ *
+ * @cmdtp: Command table
+ * @flag:  Command flag
+ * @argc:  Number of arguments
+ * @argv:  Argument array
+ * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
+ *
+ * Implement efidebug "capsule update" sub-command.
+ * process a capsule update.
+ *
+ * efidebug capsule update [-v] 
+ */
+static int do_efi_capsule_update(struct cmd_tbl *cmdtp, int flag,
+int argc, char * const argv[])
+{
+   struct efi_capsule_header *capsule;
+   int verbose = 0;
+   char *endp;
+   efi_status_t ret;
+
+   if (argc != 2 && argc != 3)
+   return CMD_RET_USAGE;
+
+   if (argc == 3) {
+   if (strcmp(argv[1], "-v"))
+   return CMD_RET_USAGE;
+
+   verbose = 1;
+   argc--;
+   argv++;
+   }
+
+   capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16);
+   if (endp == argv[1]) {
+   printf("Invalid address: %s", argv[1]);
+   return CMD_RET_FAILURE;
+   }
+
+   if (verbose) {
+   printf("Capsule guid: %pUl\n", &capsule->capsule_guid);
+   printf("Capsule flags: 0x%x\n", capsule->flags);
+   printf("Capsule header size: 0x%x\n", capsule->header_size);
+   printf("Capsule image size: 0x%x\n",
+  capsule->capsule_image_size);
+   }
+
+   ret = EFI_CALL(RT->update_capsule(&capsule, 1, (u64)NULL));
+   if (ret) {
+   printf("Cannot handle a capsule at %p", capsule);
+   return CMD_RET_FAILURE;
+   }
+
+   return CMD_RET_SUCCESS;
+}
+
+/**
+ * do_efi_capsule_show() - show capsule information
+ *
+ * @cmdtp: Command table
+ * @flag:  Command flag
+ * @argc:  Number of arguments
+ * @argv:  Argument array
+ * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
+ *
+ * Implement efidebug "capsule show" sub-command.
+ * show capsule information.
+ *
+ * efidebug capsule show 
+ */
+static int do_efi_capsule_show(struct cmd_tbl *cmdtp, int flag,
+  int argc, char * const argv[])
+{
+   struct efi_capsule_header *capsule;
+   char *endp;
+
+   if (argc != 2)
+   return CMD_RET_USAGE;
+
+   capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16);
+   if (endp == argv[1]) {
+   printf("Invalid address: %s", argv[1]);
+   return CMD_RET_FAILURE;
+   }
+
+   printf("Capsule guid: %pUl\n", &capsule->capsule_guid);
+   printf("Capsule flags: 0x%x\n", capsule->flags);
+   printf("Capsule header size: 0x%x\n", capsule->header_size);
+   printf("Capsule image size: 0x%x\n",
+  capsule->capsule_image_size);
+
+   return CMD_RET_SUCCESS;
+}
+
+/**
+ * do_efi_capsule_res() - show a capsule update result
+ *
+ * @cmdtp: Command table
+ * @flag:  Command flag
+ * @argc:  Number of arguments
+ * @argv:  Argument array
+ * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
+ *
+ * Implement efidebug "capsule result" sub-command.
+ * show a capsule update result.
+ * If result number is not specified, CapsuleLast will be shown.
+ *
+ * efidebug capsule result []
+ */
+static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
+ int argc, char * const argv[])
+{
+   int capsule_id;
+   char *endp;
+   char var_name[12];
+   u16 var_name16[12], *p;
+   efi_guid_t guid;
+   struct efi_capsule_result_variable_header *result = NULL;
+   efi_uintn_t size;
+   efi_status_t ret;
+
+   if (argc != 1 && argc != 2)
+   return CMD_RET_USAGE;
+
+   guid = efi_guid_capsule_report;
+   if (argc == 1) {
+   size = sizeof(var_name16);
+   ret = EFI_CALL(RT->get_variable(L"CapsuleLast", &guid, NULL,
+   &size, var_name16));
+   if (ret != EFI_SUCCESS) {
+   if (ret == EFI_NOT_FOUND)
+   printf("CapsuleLast doesn't exist\n");
+   else
+   printf("Failed to get CapsuleLast\n");
+
+

[PATCH v6 15/17] tools: add mkeficapsule command for UEFI capsule update

2020-09-06 Thread AKASHI Takahiro
This is a utility mainly for test purpose.
  mkeficapsule -f: create a test capsule file for FIT image firmware

Having said that, you will be able to customize the code to fit
your specific requirements for your platform.

Signed-off-by: AKASHI Takahiro 
---
 tools/Makefile   |   2 +
 tools/mkeficapsule.c | 238 +++
 2 files changed, 240 insertions(+)
 create mode 100644 tools/mkeficapsule.c

diff --git a/tools/Makefile b/tools/Makefile
index 51123fd92983..66d9376803e3 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs
 hostprogs-$(CONFIG_ASN1_COMPILER)  += asn1_compiler
 HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include
 
+hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule
+
 # We build some files with extra pedantic flags to try to minimize things
 # that won't build on some weird host compiler -- though there are lots of
 # exceptions for files that aren't complaint.
diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
new file mode 100644
index ..db95426457cc
--- /dev/null
+++ b/tools/mkeficapsule.c
@@ -0,0 +1,238 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2018 Linaro Limited
+ * Author: AKASHI Takahiro
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+typedef __u8 u8;
+typedef __u16 u16;
+typedef __u32 u32;
+typedef __u64 u64;
+typedef __s16 s16;
+typedef __s32 s32;
+
+#define aligned_u64 __aligned_u64
+
+#ifndef __packed
+#define __packed __attribute__((packed))
+#endif
+
+#include 
+#include 
+
+static const char *tool_name = "mkeficapsule";
+
+efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
+efi_guid_t efi_guid_image_type_uboot_fit =
+   EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID;
+efi_guid_t efi_guid_image_type_uboot_raw =
+   EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID;
+
+static struct option options[] = {
+   {"fit", required_argument, NULL, 'f'},
+   {"raw", required_argument, NULL, 'r'},
+   {"index", required_argument, NULL, 'i'},
+   {"instance", required_argument, NULL, 'I'},
+   {"version", required_argument, NULL, 'v'},
+   {"help", no_argument, NULL, 'h'},
+   {NULL, 0, NULL, 0},
+};
+
+static void print_usage(void)
+{
+   printf("Usage: %s [options] \n"
+  "Options:\n"
+  "\t--fit   new FIT image file\n"
+  "\t--raw   new raw image file\n"
+  "\t--index update image index\n"
+  "\t--instance   update hardware instance\n"
+  "\t--version firmware version\n"
+  "\t--help print a help message\n",
+  tool_name);
+}
+
+static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
+   unsigned long version, unsigned long index,
+   unsigned long instance)
+{
+   struct efi_capsule_header header;
+   struct efi_firmware_management_capsule_header capsule;
+   struct efi_firmware_management_capsule_image_header image;
+   FILE *f, *g;
+   struct stat bin_stat;
+   u8 *data;
+   size_t size;
+
+#ifdef DEBUG
+   printf("For output: %s\n", path);
+   printf("\tbin: %s\n\ttype: %pUl\n" bin, guid);
+   printf("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n",
+  version, index, instance);
+#endif
+
+   g = fopen(bin, "r");
+   if (!g) {
+   printf("cannot open %s\n", bin);
+   return -1;
+   }
+   if (stat(bin, &bin_stat) < 0) {
+   printf("cannot determine the size of %s\n", bin);
+   goto err_1;
+   }
+   data = malloc(bin_stat.st_size);
+   if (!data) {
+   printf("cannot allocate memory: %lx\n", bin_stat.st_size);
+   goto err_1;
+   }
+   f = fopen(path, "w");
+   if (!f) {
+   printf("cannot open %s\n", path);
+   goto err_2;
+   }
+   header.capsule_guid = efi_guid_fm_capsule;
+   header.header_size = sizeof(header);
+   header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET; /* TODO */
+   header.capsule_image_size = sizeof(header)
+   + sizeof(capsule) + sizeof(u64)
+   + sizeof(image)
+   + bin_stat.st_size;
+
+   size = fwrite(&header, 1, sizeof(header), f);
+   if (size < sizeof(header)) {
+   printf("write failed (%lx)\n", size);
+   goto err_3;
+   }
+
+   capsule.version = 0x0001;
+   capsule.embedded_driver_count = 0;
+   capsule.payload_item_count = 1;
+   capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64);
+   size = fwrite(&capsule, 1, sizeof(capsule) + sizeof(u64), f);
+   if (size < (sizeof(capsule) + sizeof(u64))) {
+   pri

[PATCH v6 13/17] efi_loader: add firmware management protocol for raw image

2020-09-06 Thread AKASHI Takahiro
In this commit, a very simple firmware management protocol driver
is implemented. It will take a binary image in a capsule file and
apply the data using dfu backend storage drivers via dfu_write_by_alt()
interface.

So "dfu_alt_info" variable should be properly set to specify a device
and location to be updated. Please read README.dfu.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_api.h |   4 +
 include/efi_loader.h  |   1 +
 lib/efi_loader/Kconfig|  16 +++
 lib/efi_loader/Makefile   |   2 +-
 lib/efi_loader/efi_capsule.c  |   8 ++
 lib/efi_loader/efi_firmware.c | 226 +-
 6 files changed, 199 insertions(+), 58 deletions(-)

diff --git a/include/efi_api.h b/include/efi_api.h
index 071d0ba866c7..c7038f863ab2 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -1853,6 +1853,10 @@ struct efi_signature_list {
EFI_GUID(0xae13ff2d, 0x9ad4, 0x4e25, 0x9a, 0xc8, \
 0x6d, 0x80, 0xb3, 0xb2, 0x21, 0x47)
 
+#define EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID \
+   EFI_GUID(0xe2bb9c06, 0x70e9, 0x4b14, 0x97, 0xa3, \
+0x5a, 0x79, 0x13, 0x17, 0x6e, 0x3f)
+
 #define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE0x0001
 #define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0002
 #define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED0x0004
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 6959f62b80a9..d9ffc24d 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -811,6 +811,7 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t 
n);
 u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index);
 
 extern const struct efi_firmware_management_protocol efi_fmp_fit;
+extern const struct efi_firmware_management_protocol efi_fmp_raw;
 
 /* Capsule update */
 efi_status_t EFIAPI efi_update_capsule(
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index bc12f0afb4aa..ae8c3f07b320 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -126,6 +126,10 @@ config EFI_CAPSULE_ON_DISK_EARLY
  executed as part of U-Boot initialisation so that they will
  surely take place whatever is set to distro_bootcmd.
 
+config EFI_CAPSULE_FIRMWARE
+   bool
+   default n
+
 config EFI_CAPSULE_FIRMWARE_MANAGEMENT
bool "Capsule: Firmware Management Protocol"
depends on EFI_HAVE_CAPSULE_SUPPORT
@@ -140,11 +144,23 @@ config EFI_CAPSULE_FIRMWARE_FIT
depends on FIT
select UPDATE_FIT
select DFU
+   select EFI_CAPSULE_FIRMWARE
default n
help
  Select this option if you want to enable firmware management protocol
  driver for FIT image
 
+config EFI_CAPSULE_FIRMWARE_RAW
+   bool "FMP driver for raw image"
+   depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
+   select DFU
+   select DFU_ALT
+   select EFI_CAPSULE_FIRMWARE
+   default n
+   help
+ Select this option if you want to enable firmware management protocol
+ driver for raw image
+
 config EFI_DEVICE_PATH_TO_TEXT
bool "Device path to text protocol"
default y
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 23b1828b0fe0..a7631d92a3b0 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -24,7 +24,7 @@ obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
 obj-y += efi_bootmgr.o
 obj-y += efi_boottime.o
 obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o
-obj-$(CONFIG_EFI_CAPSULE_FIRMWARE_FIT) += efi_firmware.o
+obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_firmware.o
 obj-y += efi_console.o
 obj-y += efi_device_path.o
 obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o
diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index a44f81daaee9..af40b4a1599e 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -814,6 +814,14 @@ efi_status_t __weak arch_efi_load_capsule_drivers(void)
&efi_fmp_fit, NULL));
}
 
+   if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)) {
+   handle = NULL;
+   ret = EFI_CALL(efi_install_multiple_protocol_interfaces(
+   &efi_root,
+   &efi_guid_firmware_management_protocol,
+   &efi_fmp_raw, NULL));
+   }
+
return ret;
 }
 
diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index 4c395f4eb5d9..7e5607738319 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -13,16 +13,66 @@
 #include 
 #include 
 
-/*
- * This FIRMWARE_MANAGEMENT_PROTOCOL driver provides a firmware update
- * method with existing FIT image format, and handles
- *   - multiple regions of firmware via DFU
- * but doesn't support
- *   - versioning of firmware image
- *   - package information
- */
-const efi_guid_t efi_firmware_image_typ

[PATCH v6 11/17] efi_loader: add firmware management protocol for FIT image

2020-09-06 Thread AKASHI Takahiro
In this commit, a very simple firmware management protocol driver
is implemented. It will take a common FIT image firmware in a capsule
file and apply the data using dfu backend storage drivers via
update_fit() interface.

So "dfu_alt_info" variable should be properly set to specify a device
and location to be updated. Please read README.dfu.

Fit image is a common file format for firmware update on U-Boot, and
this protocol works neatly just as a wrapper for one.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_api.h |   4 +
 include/efi_loader.h  |   2 +
 lib/efi_loader/Kconfig|  11 ++
 lib/efi_loader/Makefile   |   1 +
 lib/efi_loader/efi_capsule.c  |  12 +-
 lib/efi_loader/efi_firmware.c | 291 ++
 6 files changed, 320 insertions(+), 1 deletion(-)
 create mode 100644 lib/efi_loader/efi_firmware.c

diff --git a/include/efi_api.h b/include/efi_api.h
index 966bc6e590bf..071d0ba866c7 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -1849,6 +1849,10 @@ struct efi_signature_list {
EFI_GUID(0x86c77a67, 0x0b97, 0x4633, 0xa1, 0x87, \
 0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7)
 
+#define EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID \
+   EFI_GUID(0xae13ff2d, 0x9ad4, 0x4e25, 0x9a, 0xc8, \
+0x6d, 0x80, 0xb3, 0xb2, 0x21, 0x47)
+
 #define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE0x0001
 #define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0002
 #define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED0x0004
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 9adc7e857b93..6959f62b80a9 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -810,6 +810,8 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t 
n);
 /* commonly used helper function */
 u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index);
 
+extern const struct efi_firmware_management_protocol efi_fmp_fit;
+
 /* Capsule update */
 efi_status_t EFIAPI efi_update_capsule(
struct efi_capsule_header **capsule_header_array,
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 98bbf6d4ca27..bc12f0afb4aa 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -134,6 +134,17 @@ config EFI_CAPSULE_FIRMWARE_MANAGEMENT
  Select this option if you want to enable capsule-based
  firmware update using Firmware Management Protocol.
 
+config EFI_CAPSULE_FIRMWARE_FIT
+   bool "FMP driver for FIT image"
+   depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
+   depends on FIT
+   select UPDATE_FIT
+   select DFU
+   default n
+   help
+ Select this option if you want to enable firmware management protocol
+ driver for FIT image
+
 config EFI_DEVICE_PATH_TO_TEXT
bool "Device path to text protocol"
default y
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index c7d231f0e57d..23b1828b0fe0 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
 obj-y += efi_bootmgr.o
 obj-y += efi_boottime.o
 obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o
+obj-$(CONFIG_EFI_CAPSULE_FIRMWARE_FIT) += efi_firmware.o
 obj-y += efi_console.o
 obj-y += efi_device_path.o
 obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o
diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index 2015929e3708..a44f81daaee9 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -804,7 +804,17 @@ static void efi_capsule_scan_done(void)
  */
 efi_status_t __weak arch_efi_load_capsule_drivers(void)
 {
-   return EFI_SUCCESS;
+   __maybe_unused efi_handle_t handle;
+   efi_status_t ret = EFI_SUCCESS;
+
+   if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)) {
+   handle = NULL;
+   ret = EFI_CALL(efi_install_multiple_protocol_interfaces(
+   &handle, &efi_guid_firmware_management_protocol,
+   &efi_fmp_fit, NULL));
+   }
+
+   return ret;
 }
 
 /**
diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
new file mode 100644
index ..4c395f4eb5d9
--- /dev/null
+++ b/lib/efi_loader/efi_firmware.c
@@ -0,0 +1,291 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * EFI Firmware management protocol
+ *
+ *  Copyright (c) 2020 Linaro Limited
+ * Author: AKASHI Takahiro
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * This FIRMWARE_MANAGEMENT_PROTOCOL driver provides a firmware update
+ * method with existing FIT image format, and handles
+ *   - multiple regions of firmware via DFU
+ * but doesn't support
+ *   - versioning of firmware image
+ *   - package information
+ */
+const efi_guid_t efi_firmware_image_type_uboot_fit =
+   EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID;
+
+/**
+ * 

[PATCH v6 08/17] efi_loader: capsule: add capsule_on_disk support

2020-09-06 Thread AKASHI Takahiro
Capsule data can be loaded into the system either via UpdateCapsule
runtime service or files on a file system (of boot device).
The latter case is called "capsules on disk", and actual updates will
take place at the next boot time.

In this commit, we will support capsule on disk mechanism.

Please note that U-Boot itself has no notion of "boot device" and
all the capsule files to be executed will be detected only if they
are located in a specific directory, \EFI\UpdateCapsule, on a device
that is identified as a boot device by "Boot" variables.

Signed-off-by: AKASHI Takahiro 
---
 common/main.c|   4 +
 include/efi_loader.h |   9 +
 lib/efi_loader/Kconfig   |  22 ++
 lib/efi_loader/efi_capsule.c | 498 +++
 lib/efi_loader/efi_setup.c   |   8 +
 5 files changed, 541 insertions(+)

diff --git a/common/main.c b/common/main.c
index 4b3cd302c3e2..ae5bcdb32f8b 100644
--- a/common/main.c
+++ b/common/main.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static void run_preboot_environment_command(void)
 {
@@ -53,6 +54,9 @@ void main_loop(void)
if (IS_ENABLED(CONFIG_UPDATE_TFTP))
update_tftp(0UL, NULL, NULL);
 
+   if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY))
+   efi_launch_capsules();
+
s = bootdelay_process();
if (cli_process_fdt(&s))
cli_secure_boot_cmd(s);
diff --git a/include/efi_loader.h b/include/efi_loader.h
index ca50e1c2a18b..157c560034fc 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -819,6 +819,11 @@ efi_status_t EFIAPI efi_query_capsule_caps(
u64 *maximum_capsule_size,
u32 *reset_type);
 
+#define EFI_CAPSULE_DIR L"\\EFI\\UpdateCapsule\\"
+
+/* Hook at initialization */
+efi_status_t efi_launch_capsules(void);
+
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
 
 /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
@@ -835,6 +840,10 @@ static inline void efi_set_bootdev(const char *dev, const 
char *devnr,
   const char *path) { }
 static inline void efi_net_set_dhcp_ack(void *pkt, int len) { }
 static inline void efi_print_image_infos(void *pc) { }
+static inline efi_status_t efi_launch_capsules(void)
+{
+   return EFI_SUCCESS;
+}
 
 #endif /* CONFIG_IS_ENABLED(EFI_LOADER) */
 
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index ee9ebe348ad9..6e35cbe64c7f 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -104,6 +104,28 @@ config EFI_RUNTIME_UPDATE_CAPSULE
  Select this option if you want to use UpdateCapsule and
  QueryCapsuleCapabilities API's.
 
+config EFI_CAPSULE_ON_DISK
+   bool "Enable capsule-on-disk support"
+   select EFI_HAVE_CAPSULE_SUPPORT
+   default n
+   help
+ Select this option if you want to use capsule-on-disk feature,
+ that is, capsules can be fetched and executed from files
+ under a specific directory on UEFI system partition instead of
+ via UpdateCapsule API.
+
+config EFI_CAPSULE_ON_DISK_EARLY
+   bool "Initiate capsule-on-disk at U-Boot boottime"
+   depends on EFI_CAPSULE_ON_DISK
+   default y
+   select EFI_SETUP_EARLY
+   help
+ Normally, without this option enabled, capsules will be
+ executed only at the first time of invoking one of efi command.
+ If this option is enabled, capsules will be enforced to be
+ executed as part of U-Boot initialisation so that they will
+ surely take place whatever is set to distro_bootcmd.
+
 config EFI_DEVICE_PATH_TO_TEXT
bool "Device path to text protocol"
default y
diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index 02a8435cd3d1..2259bfbf3d19 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -11,10 +11,16 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
 
+#ifdef CONFIG_EFI_CAPSULE_ON_DISK
+/* for file system access */
+static struct efi_file_handle *bootdev_root;
+#endif
+
 /**
  * get_last_capsule - get the last capsule index
  *
@@ -163,3 +169,495 @@ efi_status_t EFIAPI efi_query_capsule_caps(
 out:
return EFI_EXIT(ret);
 }
+
+#ifdef CONFIG_EFI_CAPSULE_ON_DISK
+/**
+ * get_dp_device - retrieve a device  path from boot variable
+ * @boot_var:  Boot variable name
+ * @device_dp  Device path
+ *
+ * Retrieve a device patch from boot variable, @boot_var.
+ *
+ * Return: status code
+ */
+static efi_status_t get_dp_device(u16 *boot_var,
+ struct efi_device_path **device_dp)
+{
+   void *buf = NULL;
+   efi_uintn_t size;
+   struct efi_load_option lo;
+   struct efi_device_path *file_dp;
+   efi_status_t ret;
+
+   size = 0;
+   ret = efi_get_variable_int(boot_var, &efi_global_variable_guid,
+ 

[PATCH v6 12/17] dfu: add dfu_write_by_alt()

2020-09-06 Thread AKASHI Takahiro
This function is a variant of dfu_write_by_name() and takes a DFU alt
setting number for dfu configuration.

It will be utilised to implement UEFI capsule management protocol for
raw image in a later commit.

Signed-off-by: AKASHI Takahiro 
---
 drivers/dfu/dfu_alt.c | 47 +++
 include/dfu.h | 26 +++-
 2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/drivers/dfu/dfu_alt.c b/drivers/dfu/dfu_alt.c
index 7528806cd163..d5827812070c 100644
--- a/drivers/dfu/dfu_alt.c
+++ b/drivers/dfu/dfu_alt.c
@@ -76,3 +76,50 @@ done:
 
return ret;
 }
+
+/**
+ * dfu_write_by_alt() - write data to DFU medium
+ * @dfu_alt_num:DFU alt setting number
+ * @addr:   Address of data buffer to write
+ * @len:Number of bytes
+ * @interface:  Destination DFU medium (e.g. "mmc")
+ * @devstring:  Instance number of destination DFU medium (e.g. "1")
+ *
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_alt_name.
+ *
+ * Return:  0 - on success, error code - otherwise
+ */
+int dfu_write_by_alt(int dfu_alt_num, void *addr, unsigned int len,
+char *interface, char *devstring)
+{
+   struct dfu_entity *dfu;
+   int ret;
+
+   debug("%s: alt: %d addr: 0x%p len: %d device: %s:%s\n", __func__,
+ dfu_alt_num, addr, len, interface, devstring);
+
+   ret = dfu_init_env_entities(interface, devstring);
+   if (ret)
+   goto done;
+
+   if (dfu_alt_num < 0) {
+   pr_err("Invalid alt number: %d", dfu_alt_num);
+   ret = -ENODEV;
+   goto done;
+   }
+
+   dfu = dfu_get_entity(dfu_alt_num);
+   if (!dfu) {
+   pr_err("DFU entity for alt: %d not found!", dfu_alt_num);
+   ret = -ENODEV;
+   goto done;
+   }
+
+   ret = dfu_write_from_mem_addr(dfu, (void *)(uintptr_t)addr, len);
+
+done:
+   dfu_free_entities();
+
+   return ret;
+}
diff --git a/include/dfu.h b/include/dfu.h
index 015d1bf895d0..6c5b4aaa5963 100644
--- a/include/dfu.h
+++ b/include/dfu.h
@@ -496,6 +496,7 @@ static inline int dfu_fill_entity_virt(struct dfu_entity 
*dfu, char *devstr,
 }
 #endif
 
+#if CONFIG_IS_ENABLED(DFU_ALT)
 /**
  * dfu_write_by_name() - write data to DFU medium
  * @dfu_entity_name:   Name of DFU entity to write
@@ -509,9 +510,24 @@ static inline int dfu_fill_entity_virt(struct dfu_entity 
*dfu, char *devstr,
  *
  * Return: 0 - on success, error code - otherwise
  */
-#if CONFIG_IS_ENABLED(DFU_ALT)
 int dfu_write_by_name(char *dfu_entity_name, void *addr,
  unsigned int len, char *interface, char *devstring);
+
+/**
+ * dfu_write_by_alt() - write data to DFU medium
+ * @dfu_alt_num:   DFU alt setting number
+ * @addr:  Address of data buffer to write
+ * @len:   Number of bytes
+ * @interface: Destination DFU medium (e.g. "mmc")
+ * @devstring: Instance number of destination DFU medium (e.g. "1")
+ *
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_alt_name.
+ *
+ * Return: 0 - on success, error code - otherwise
+ */
+int dfu_write_by_alt(int dfu_alt_num, void *addr, unsigned int len,
+char *interface, char *devstring);
 #else
 static inline int dfu_write_by_name(char *dfu_entity_name, void *addr,
unsigned int len, char *interface,
@@ -520,6 +536,14 @@ static inline int dfu_write_by_name(char *dfu_entity_name, 
void *addr,
puts("write support for DFU not available!\n");
return -ENOSYS;
 }
+
+static inline int dfu_write_by_alt(int dfu_alt_num, void *addr,
+  unsigned int len, char *interface,
+  char *devstring)
+{
+   puts("write support for DFU not available!\n");
+   return -ENOSYS;
+}
 #endif
 
 int dfu_add(struct usb_configuration *c);
-- 
2.28.0



[PATCH v6 06/17] efi_loader: add efi_create_indexed_name()

2020-09-06 Thread AKASHI Takahiro
This function will be used from several places in UEFI subsystem
to generate some specific form of utf-16 variable name.
For example, L"Capsule0001"

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

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 0baa1d2324c8..a4a123c149fd 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -803,6 +803,9 @@ bool efi_image_parse(void *efi, size_t len, struct 
efi_image_regions **regp,
 /* runtime implementation of memcpy() */
 void efi_memcpy_runtime(void *dest, const void *src, size_t n);
 
+/* commonly used helper function */
+u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index);
+
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
 
 /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index 6196c0a06cd7..a09a7b607e11 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -230,3 +231,32 @@ out:
efi_obj_list_initialized = ret;
return ret;
 }
+
+/**
+ * efi_create_indexed_name - create a string name with an index
+ * @buffer:Buffer
+ * @name:  Name string
+ * @index: Index
+ *
+ * Create a utf-16 string with @name, appending @index.
+ * For example, L"Capsule0001"
+ * This function is expected to be called only from several places
+ * in EFI subsystem. A caller should ensure that the buffer have
+ * enough space for a resulting string, including L"\0".
+ * No strict check against the length will be done here.
+ *
+ * Return: A pointer to the next position after the created string
+ * in @buffer, or NULL otherwise
+ */
+u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index)
+{
+   u16 *p;
+   char index_buf[5];
+
+   u16_strcpy(buffer, name);
+   p = buffer + utf16_strnlen(name, SIZE_MAX);
+   sprintf(index_buf, "%04X", index);
+   utf8_utf16_strcpy(&p, index_buf);
+
+   return p;
+}
-- 
2.28.0



[PATCH v6 10/17] efi_loader: capsule: support firmware update

2020-09-06 Thread AKASHI Takahiro
A capsule tagged with the guid, EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID,
is handled as a firmware update object.
What efi_update_capsule() basically does is to load any firmware management
protocol (or fmp) drivers contained in a capsule, find out an appropriate
fmp driver and then invoke its set_image() interface against each binary
in a capsule.
In this commit, however, loading drivers is not supported.

The result of applying a capsule is set to be stored in "Capsule"
variable, but its implementation is deferred to a fmp driver.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_api.h| 129 +++
 include/efi_loader.h |   2 +
 lib/efi_loader/Kconfig   |   8 ++
 lib/efi_loader/efi_capsule.c | 238 ++-
 lib/efi_loader/efi_setup.c   |   4 +
 5 files changed, 380 insertions(+), 1 deletion(-)

diff --git a/include/efi_api.h b/include/efi_api.h
index 7a2a087c60ed..966bc6e590bf 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -217,6 +217,9 @@ enum efi_reset_type {
 #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE0x0002
 #define CAPSULE_FLAGS_INITIATE_RESET   0x0004
 
+#define CAPSULE_SUPPORT_AUTHENTICATION 0x0001
+#define CAPSULE_SUPPORT_DEPENDENCY 0x0002
+
 #define EFI_CAPSULE_REPORT_GUID \
EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \
 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)
@@ -225,6 +228,10 @@ enum efi_reset_type {
EFI_GUID(0xde9f0ec, 0x88b6, 0x428f, 0x97, 0x7a, \
 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72)
 
+#define EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID \
+   EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \
+0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a)
+
 struct efi_capsule_header {
efi_guid_t capsule_guid;
u32 header_size;
@@ -253,6 +260,33 @@ struct efi_memory_range_capsule {
struct efi_memory_range memory_ranges[];
 } __packed;
 
+struct efi_firmware_management_capsule_header {
+   u32 version;
+   u16 embedded_driver_count;
+   u16 payload_item_count;
+   u64 item_offset_list[];
+} __packed;
+
+struct efi_firmware_management_capsule_image_header {
+   u32 version;
+   efi_guid_t update_image_type_id;
+   u8 update_image_index;
+   u8 reserved[3];
+   u32 update_image_size;
+   u32 update_vendor_code_size;
+   u64 update_hardware_instance;
+   u64 image_capsule_support;
+} __packed;
+
+struct efi_capsule_result_variable_fmp {
+   u16 version;
+   u8 payload_index;
+   u8 update_image_index;
+   efi_guid_t update_image_type_id;
+   // u16 capsule_file_name[];
+   // u16 capsule_target[];
+} __packed;
+
 #define EFI_RT_SUPPORTED_GET_TIME  0x0001
 #define EFI_RT_SUPPORTED_SET_TIME  0x0002
 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME   0x0004
@@ -1808,4 +1842,99 @@ struct efi_signature_list {
 /* struct efi_signature_data signatures[...][signature_size]; */
 } __attribute__((__packed__));
 
+/*
+ * Firmware management protocol
+ */
+#define EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID \
+   EFI_GUID(0x86c77a67, 0x0b97, 0x4633, 0xa1, 0x87, \
+0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7)
+
+#define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE0x0001
+#define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0002
+#define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED0x0004
+#define IMAGE_ATTRIBUTE_IN_USE 0x0008
+#define IMAGE_ATTRIBUTE_UEFI_IMAGE 0x0010
+#define IMAGE_ATTRIBUTE_DEPENDENCY 0x0020
+
+#define IMAGE_COMPATIBILITY_CHECK_SUPPORTED0x0001
+
+#define IMAGE_UPDATABLE_VALID  0x0001
+#define IMAGE_UPDATABLE_INVALID0x0002
+#define IMAGE_UPDATABLE_INVALID_TYPE   0x0004
+#define IMAGE_UPDATABLE_INVALID_OLLD   0x0008
+#define IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE 0x0010
+
+#define PACKAGE_ATTRIBUTE_VERSION_UPDATABLE0x0001
+#define PACKAGE_ATTRIBUTE_RESET_REQUIRED   0x0002
+#define PACKAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED  0x0004
+
+#define EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION  4
+
+typedef struct efi_firmware_image_dependencies {
+   u8 dependencies[0];
+} efi_firmware_image_dep_t;
+
+struct efi_firmware_image_descriptor {
+   u8 image_index;
+   efi_guid_t image_type_id;
+   u64 image_id;
+   u16 *image_id_name;
+   u32 version;
+   u16 *version_name;
+   efi_uintn_t size;
+   u64 attributes_supported;
+   u64 attributes_setting;
+   u64 compatibilities;
+   u32 lowest_supported_image_version;
+   u32 last_attempt_version;
+   u32 last_attempt_status;
+   u64 hardware_instance;
+   efi_firmware_image_d

[PATCH v6 04/17] dfu: export dfu_list

2020-09-06 Thread AKASHI Takahiro
This variable will be utilized to enumerate all dfu entities
for UEFI capsule firmware update in a later commit.

Signed-off-by: AKASHI Takahiro 
---
 drivers/dfu/dfu.c | 2 +-
 include/dfu.h | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
index a298c2c43999..501a60b34400 100644
--- a/drivers/dfu/dfu.c
+++ b/drivers/dfu/dfu.c
@@ -18,7 +18,7 @@
 #include 
 #include 
 
-static LIST_HEAD(dfu_list);
+LIST_HEAD(dfu_list);
 static int dfu_alt_num;
 static int alt_num_cnt;
 static struct hash_algo *dfu_hash_algo;
diff --git a/include/dfu.h b/include/dfu.h
index 2299a83a3d94..015d1bf895d0 100644
--- a/include/dfu.h
+++ b/include/dfu.h
@@ -158,6 +158,9 @@ struct dfu_entity {
unsigned int inited:1;
 };
 
+struct list_head;
+extern struct list_head dfu_list;
+
 #ifdef CONFIG_SET_DFU_ALT_INFO
 /**
  * set_dfu_alt_info() - set dfu_alt_info environment variable
-- 
2.28.0



[PATCH v6 09/17] efi_loader: capsule: add memory range capsule definitions

2020-09-06 Thread AKASHI Takahiro
Memory range capsule gives us a way to notify that some memory regions
should be left untouched across the next reset.
See UEFI specification, section 8.5.3.

Since how we should handle this kind of capsule is totally up to
the system, no implementation will be added in this commit.

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

diff --git a/include/efi_api.h b/include/efi_api.h
index c128a0a66ce8..7a2a087c60ed 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -221,6 +221,10 @@ enum efi_reset_type {
EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \
 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)
 
+#define EFI_MEMORY_RANGE_CAPSULE_GUID \
+   EFI_GUID(0xde9f0ec, 0x88b6, 0x428f, 0x97, 0x7a, \
+0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72)
+
 struct efi_capsule_header {
efi_guid_t capsule_guid;
u32 header_size;
@@ -236,6 +240,19 @@ struct efi_capsule_result_variable_header {
efi_status_t capsule_status;
 } __packed;
 
+struct efi_memory_range {
+   efi_physical_addr_t address;
+   u64 length;
+};
+
+struct efi_memory_range_capsule {
+   struct efi_capsule_header *header;
+   /* EFI_MEMORY_TYPE: 0x8000-0x */
+   enum efi_mem_type os_requested_memory_type;
+   u64 number_of_memory_ranges;
+   struct efi_memory_range memory_ranges[];
+} __packed;
+
 #define EFI_RT_SUPPORTED_GET_TIME  0x0001
 #define EFI_RT_SUPPORTED_SET_TIME  0x0002
 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME   0x0004
-- 
2.28.0



[PATCH v6 05/17] efi_loader: add option to initialise EFI subsystem early

2020-09-06 Thread AKASHI Takahiro
If this option, CONFIG_EFI_SETUP_EARLY, is enabled, the initialisation
of UEFI subsystem will be done as part of U-Boot initialisation.

Please note that this option won't be enabled explicitly by users,
instead, should be enabled implicitly by other configuration options.

Specifically, this feature will be utilised in implementing capsule-on-disk
feature.

Signed-off-by: AKASHI Takahiro 
---
 common/board_r.c   | 6 ++
 lib/efi_loader/Kconfig | 4 
 2 files changed, 10 insertions(+)

diff --git a/common/board_r.c b/common/board_r.c
index 9b2fec701a55..0391a1b6acb7 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -72,6 +72,9 @@
 #if defined(CONFIG_GPIO_HOG)
 #include 
 #endif
+#ifdef CONFIG_EFI_SETUP_EARLY
+#include 
+#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -877,6 +880,9 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 #if defined(CONFIG_PRAM)
initr_mem,
+#endif
+#ifdef CONFIG_EFI_SETUP_EARLY
+   (init_fnc_t)efi_init_obj_list,
 #endif
run_main_loop,
 };
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index bad1a29ba804..cbd8fe8c0ad2 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -27,6 +27,10 @@ config EFI_LOADER
 
 if EFI_LOADER
 
+config EFI_SETUP_EARLY
+   bool
+   default n
+
 choice
prompt "Store for non-volatile UEFI variables"
default EFI_VARIABLE_FILE_STORE
-- 
2.28.0



[PATCH v6 07/17] efi_loader: define UpdateCapsule api

2020-09-06 Thread AKASHI Takahiro
In this commit, skeleton functions for capsule-related API's are
added under CONFIG_EFI_UPDATE_CAPSULE configuration.
Detailed implementation for a specific capsule type will be added
in the succeeding patches.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_api.h|  12 +++
 include/efi_loader.h |  13 +++
 lib/efi_loader/Kconfig   |  11 +++
 lib/efi_loader/Makefile  |   1 +
 lib/efi_loader/efi_capsule.c | 165 +++
 lib/efi_loader/efi_runtime.c | 104 --
 lib/efi_loader/efi_setup.c   |  64 +++---
 7 files changed, 316 insertions(+), 54 deletions(-)
 create mode 100644 lib/efi_loader/efi_capsule.c

diff --git a/include/efi_api.h b/include/efi_api.h
index 5744f6aed86d..c128a0a66ce8 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -217,6 +217,10 @@ enum efi_reset_type {
 #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE0x0002
 #define CAPSULE_FLAGS_INITIATE_RESET   0x0004
 
+#define EFI_CAPSULE_REPORT_GUID \
+   EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \
+0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)
+
 struct efi_capsule_header {
efi_guid_t capsule_guid;
u32 header_size;
@@ -224,6 +228,14 @@ struct efi_capsule_header {
u32 capsule_image_size;
 } __packed;
 
+struct efi_capsule_result_variable_header {
+   u32 variable_total_size;
+   u32 reserved;
+   efi_guid_t capsule_guid;
+   struct efi_time capsule_processed;
+   efi_status_t capsule_status;
+} __packed;
+
 #define EFI_RT_SUPPORTED_GET_TIME  0x0001
 #define EFI_RT_SUPPORTED_SET_TIME  0x0002
 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME   0x0004
diff --git a/include/efi_loader.h b/include/efi_loader.h
index a4a123c149fd..ca50e1c2a18b 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -208,6 +208,8 @@ extern const efi_guid_t efi_guid_cert_type_pkcs7;
 
 /* GUID of RNG protocol */
 extern const efi_guid_t efi_guid_rng_protocol;
+/* GUID of capsule update result */
+extern const efi_guid_t efi_guid_capsule_report;
 
 extern unsigned int __efi_runtime_start, __efi_runtime_stop;
 extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
@@ -806,6 +808,17 @@ void efi_memcpy_runtime(void *dest, const void *src, 
size_t n);
 /* commonly used helper function */
 u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index);
 
+/* Capsule update */
+efi_status_t EFIAPI efi_update_capsule(
+   struct efi_capsule_header **capsule_header_array,
+   efi_uintn_t capsule_count,
+   u64 scatter_gather_list);
+efi_status_t EFIAPI efi_query_capsule_caps(
+   struct efi_capsule_header **capsule_header_array,
+   efi_uintn_t capsule_count,
+   u64 *maximum_capsule_size,
+   u32 *reset_type);
+
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
 
 /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index cbd8fe8c0ad2..ee9ebe348ad9 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -93,6 +93,17 @@ config EFI_SET_TIME
  Provide the SetTime() runtime service at boottime. This service
  can be used by an EFI application to adjust the real time clock.
 
+config EFI_HAVE_CAPSULE_SUPPORT
+   bool
+
+config EFI_RUNTIME_UPDATE_CAPSULE
+   bool "UpdateCapsule() runtime service"
+   default n
+   select EFI_HAVE_CAPSULE_SUPPORT
+   help
+ Select this option if you want to use UpdateCapsule and
+ QueryCapsuleCapabilities API's.
+
 config EFI_DEVICE_PATH_TO_TEXT
bool "Device path to text protocol"
default y
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 9bad1d159b03..c7d231f0e57d 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -23,6 +23,7 @@ endif
 obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
 obj-y += efi_bootmgr.o
 obj-y += efi_boottime.o
+obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o
 obj-y += efi_console.o
 obj-y += efi_device_path.o
 obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o
diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
new file mode 100644
index ..02a8435cd3d1
--- /dev/null
+++ b/lib/efi_loader/efi_capsule.c
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  EFI Capsule
+ *
+ *  Copyright (c) 2018 Linaro Limited
+ * Author: AKASHI Takahiro
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID;
+
+/**
+ * get_last_capsule - get the last capsule index
+ *
+ * Retrieve the index of the capsule invoked last time from "CapsuleLast"
+ * variable.
+ *
+ * Return:
+ * * > 0   - the last capsule index invoked
+ * * 0x- on error, or no caps

[PATCH v6 03/17] common: update: add a generic interface for FIT image

2020-09-06 Thread AKASHI Takahiro
The main purpose of this patch is to separate a generic interface for
updating firmware using DFU drivers from "auto-update" via tftp.

This function will also be used in implementing UEFI capsule update
in a later commit.

Signed-off-by: AKASHI Takahiro 
---
 common/Kconfig  | 15 ++
 common/Makefile |  3 +-
 common/update.c | 71 +
 drivers/dfu/Kconfig |  1 +
 include/image.h | 12 
 5 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index c58f08ba91bf..36998e382bda 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1050,9 +1050,15 @@ endmenu
 
 menu "Update support"
 
+config UPDATE_COMMON
+   bool
+   default n
+   select DFU_ALT
+
 config UPDATE_TFTP
bool "Auto-update using fitImage via TFTP"
depends on FIT
+   select UPDATE_COMMON
help
  This option allows performing update of NOR with data in fitImage
  sent via TFTP boot.
@@ -1067,6 +1073,15 @@ config UPDATE_TFTP_MSEC_MAX
default 100
depends on UPDATE_TFTP
 
+config UPDATE_FIT
+   bool "Firmware update using fitImage"
+   depends on FIT
+   depends on DFU
+   select UPDATE_COMMON
+   help
+ This option allows performing update of DFU-capable storage with
+ data in fitImage.
+
 config ANDROID_AB
bool "Android A/B updates"
default n
diff --git a/common/Makefile b/common/Makefile
index 2e7a090588d9..bcf352d01652 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -53,8 +53,7 @@ obj-$(CONFIG_LCD_ROTATION) += lcd_console_rotation.o
 obj-$(CONFIG_LCD_DT_SIMPLEFB) += lcd_simplefb.o
 obj-$(CONFIG_LYNXKDI) += lynxkdi.o
 obj-$(CONFIG_MENU) += menu.o
-obj-$(CONFIG_UPDATE_TFTP) += update.o
-obj-$(CONFIG_DFU_TFTP) += update.o
+obj-$(CONFIG_UPDATE_COMMON) += update.o
 obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
 obj-$(CONFIG_CMDLINE) += cli_readline.o cli_simple.o
 
diff --git a/common/update.c b/common/update.c
index 8dd6ee8b7ddb..808be0880dfd 100644
--- a/common/update.c
+++ b/common/update.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 
+#ifdef CONFIG_DFU_TFTP
 /* env variable holding the location of the update file */
 #define UPDATE_FILE_ENV"updatefile"
 
@@ -98,6 +99,7 @@ static int update_load(char *filename, ulong msec_max, int 
cnt_max, ulong addr)
 
return rv;
 }
+#endif /* CONFIG_DFU_TFTP */
 
 #ifdef CONFIG_MTD_NOR_FLASH
 static int update_flash_protect(int prot, ulong addr_first, ulong addr_last)
@@ -231,6 +233,7 @@ static int update_fit_getparams(const void *fit, int 
noffset, ulong *addr,
return 0;
 }
 
+#ifdef CONFIG_DFU_TFTP
 int update_tftp(ulong addr, char *interface, char *devstring)
 {
char *filename, *env_addr, *fit_image_name;
@@ -337,3 +340,71 @@ next_node:
 
return ret;
 }
+#endif /* CONFIG_DFU_UPDATE */
+
+#ifdef CONFIG_UPDATE_FIT
+/**
+ * fit_update - update storage with FIT image
+ * @fit:   Pointer to FIT image
+ *
+ * Update firmware on storage using FIT image as input.
+ * The storage area to be update will be identified by the name
+ * in FIT and matching it to "dfu_alt_info" variable.
+ *
+ * Return:  0 - on success, non-zero - otherwise
+ */
+int fit_update(const void *fit)
+{
+   char *fit_image_name;
+   ulong update_addr, update_fladdr, update_size;
+   int images_noffset, ndepth, noffset;
+   int ret = 0;
+
+   if (!fit)
+   return -EINVAL;
+
+   if (!fit_check_format((void *)fit)) {
+   printf("Bad FIT format of the update file, aborting 
auto-update\n");
+   return -EINVAL;
+   }
+
+   /* process updates */
+   images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
+
+   ndepth = 0;
+   noffset = fdt_next_node(fit, images_noffset, &ndepth);
+   while (noffset >= 0 && ndepth > 0) {
+   if (ndepth != 1)
+   goto next_node;
+
+   fit_image_name = (char *)fit_get_name(fit, noffset, NULL);
+   printf("Processing update '%s' :", fit_image_name);
+
+   if (!fit_image_verify(fit, noffset)) {
+   printf("Error: invalid update hash, aborting\n");
+   ret = 1;
+   goto next_node;
+   }
+
+   printf("\n");
+   if (update_fit_getparams(fit, noffset, &update_addr,
+&update_fladdr, &update_size)) {
+   printf("Error: can't get update parameters, 
aborting\n");
+   ret = 1;
+   goto next_node;
+   }
+
+   if (fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE)) {
+   ret = dfu_write_by_name(fit_image_name,
+   (void *)update_addr,
+   update_size, NULL, NULL);
+   

[PATCH v6 02/17] dfu: modify an argument type for an address

2020-09-06 Thread AKASHI Takahiro
The range of an addressable pointer can go beyond 'integer'.
So change the argument type to a void pointer.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Heinrich Schuchardt 
---
 common/update.c   | 3 ++-
 drivers/dfu/dfu_alt.c | 6 +++---
 include/dfu.h | 4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/common/update.c b/common/update.c
index 39946776d74f..8dd6ee8b7ddb 100644
--- a/common/update.c
+++ b/common/update.c
@@ -324,7 +324,8 @@ got_update_file:
}
} else if (fit_image_check_type(fit, noffset,
IH_TYPE_FIRMWARE)) {
-   ret = dfu_write_by_name(fit_image_name, update_addr,
+   ret = dfu_write_by_name(fit_image_name,
+   (void *)update_addr,
update_size, interface,
devstring);
if (ret)
diff --git a/drivers/dfu/dfu_alt.c b/drivers/dfu/dfu_alt.c
index 5b1b13d7170d..7528806cd163 100644
--- a/drivers/dfu/dfu_alt.c
+++ b/drivers/dfu/dfu_alt.c
@@ -23,14 +23,14 @@
  *
  * Return:  0 - on success, error code - otherwise
  */
-int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+int dfu_write_by_name(char *dfu_entity_name, void *addr,
  unsigned int len, char *interface, char *devstring)
 {
char *s, *sb;
int alt_setting_num, ret;
struct dfu_entity *dfu;
 
-   debug("%s: name: %s addr: 0x%x len: %d device: %s:%s\n", __func__,
+   debug("%s: name: %s addr: 0x%p len: %d device: %s:%s\n", __func__,
  dfu_entity_name, addr, len, interface, devstring);
 
ret = dfu_init_env_entities(interface, devstring);
@@ -69,7 +69,7 @@ int dfu_write_by_name(char *dfu_entity_name, unsigned int 
addr,
goto done;
}
 
-   ret = dfu_write_from_mem_addr(dfu, (void *)(uintptr_t)addr, len);
+   ret = dfu_write_from_mem_addr(dfu, (void *)addr, len);
 
 done:
dfu_free_entities();
diff --git a/include/dfu.h b/include/dfu.h
index cecfbd76597b..2299a83a3d94 100644
--- a/include/dfu.h
+++ b/include/dfu.h
@@ -507,10 +507,10 @@ static inline int dfu_fill_entity_virt(struct dfu_entity 
*dfu, char *devstr,
  * Return: 0 - on success, error code - otherwise
  */
 #if CONFIG_IS_ENABLED(DFU_ALT)
-int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+int dfu_write_by_name(char *dfu_entity_name, void *addr,
  unsigned int len, char *interface, char *devstring);
 #else
-static inline int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+static inline int dfu_write_by_name(char *dfu_entity_name, void *addr,
unsigned int len, char *interface,
char *devstring)
 {
-- 
2.28.0



[PATCH v6 01/17] dfu: rename dfu_tftp_write() to dfu_write_by_name()

2020-09-06 Thread AKASHI Takahiro
This function is essentially independent from tftp, and will also be
utilised in implementing UEFI capsule update in a later commit.
So just give it a more generic name.
In addition, a new configuration option, CONFIG_DFU_ALT, was introduced
so that the file will be compiled with different options, particularly
one added in a later commit.

Signed-off-by: AKASHI Takahiro 
---
 common/update.c   |  5 +++--
 drivers/dfu/Kconfig   |  5 +
 drivers/dfu/Makefile  |  2 +-
 drivers/dfu/{dfu_tftp.c => dfu_alt.c} | 17 --
 include/dfu.h | 32 +--
 5 files changed, 40 insertions(+), 21 deletions(-)
 rename drivers/dfu/{dfu_tftp.c => dfu_alt.c} (67%)

diff --git a/common/update.c b/common/update.c
index 36b6b7523d50..39946776d74f 100644
--- a/common/update.c
+++ b/common/update.c
@@ -324,8 +324,9 @@ got_update_file:
}
} else if (fit_image_check_type(fit, noffset,
IH_TYPE_FIRMWARE)) {
-   ret = dfu_tftp_write(fit_image_name, update_addr,
-update_size, interface, devstring);
+   ret = dfu_write_by_name(fit_image_name, update_addr,
+   update_size, interface,
+   devstring);
if (ret)
return ret;
}
diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig
index 0eec00ba734d..78f901ff348a 100644
--- a/drivers/dfu/Kconfig
+++ b/drivers/dfu/Kconfig
@@ -14,8 +14,13 @@ config DFU_OVER_TFTP
depends on NET
 
 if DFU
+config DFU_ALT
+   bool
+   default n
+
 config DFU_TFTP
bool "DFU via TFTP"
+   select DFU_ALT
select DFU_OVER_TFTP
help
  This option allows performing update of DFU-managed medium with data
diff --git a/drivers/dfu/Makefile b/drivers/dfu/Makefile
index 0d7925c083ef..cc7de1d3ed9b 100644
--- a/drivers/dfu/Makefile
+++ b/drivers/dfu/Makefile
@@ -9,5 +9,5 @@ obj-$(CONFIG_$(SPL_)DFU_MTD) += dfu_mtd.o
 obj-$(CONFIG_$(SPL_)DFU_NAND) += dfu_nand.o
 obj-$(CONFIG_$(SPL_)DFU_RAM) += dfu_ram.o
 obj-$(CONFIG_$(SPL_)DFU_SF) += dfu_sf.o
-obj-$(CONFIG_$(SPL_)DFU_TFTP) += dfu_tftp.o
+obj-$(CONFIG_$(SPL_)DFU_ALT) += dfu_alt.o
 obj-$(CONFIG_$(SPL_)DFU_VIRT) += dfu_virt.o
diff --git a/drivers/dfu/dfu_tftp.c b/drivers/dfu/dfu_alt.c
similarity index 67%
rename from drivers/dfu/dfu_tftp.c
rename to drivers/dfu/dfu_alt.c
index ffae4bb54f80..5b1b13d7170d 100644
--- a/drivers/dfu/dfu_tftp.c
+++ b/drivers/dfu/dfu_alt.c
@@ -10,8 +10,21 @@
 #include 
 #include 
 
-int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len,
-  char *interface, char *devstring)
+/**
+ * dfu_write_by_name() - write data to DFU medium
+ * @dfu_entity_name:Name of DFU entity to write
+ * @addr:   Address of data buffer to write
+ * @len:Number of bytes
+ * @interface:  Destination DFU medium (e.g. "mmc")
+ * @devstring:  Instance number of destination DFU medium (e.g. "1")
+ *
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_entity_name.
+ *
+ * Return:  0 - on success, error code - otherwise
+ */
+int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+ unsigned int len, char *interface, char *devstring)
 {
char *s, *sb;
int alt_setting_num, ret;
diff --git a/include/dfu.h b/include/dfu.h
index 84abdc79acd1..cecfbd76597b 100644
--- a/include/dfu.h
+++ b/include/dfu.h
@@ -494,27 +494,27 @@ static inline int dfu_fill_entity_virt(struct dfu_entity 
*dfu, char *devstr,
 #endif
 
 /**
- * dfu_tftp_write() - write TFTP data to DFU medium
+ * dfu_write_by_name() - write data to DFU medium
+ * @dfu_entity_name:   Name of DFU entity to write
+ * @addr:  Address of data buffer to write
+ * @len:   Number of bytes
+ * @interface: Destination DFU medium (e.g. "mmc")
+ * @devstring: Instance number of destination DFU medium (e.g. "1")
  *
- * This function is storing data received via TFTP on DFU supported medium.
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_entity_name.
  *
- * @dfu_entity_name:   name of DFU entity to write
- * @addr:  address of data buffer to write
- * @len:   number of bytes
- * @interface: destination DFU medium (e.g. "mmc")
- * @devstring: instance number of destination DFU medium (e.g. "1")
- *
- * Return: 0 on success, otherwise error code
+ * Return: 0 - on success, error code - otherwise
  */
-#if CONFIG_IS_ENABLED(DFU_TFTP)
-int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len,
-  

[PATCH v6 00/17] efi_loader: add capsule update support

2020-09-06 Thread AKASHI Takahiro
Summary
===
'UpdateCapsule' is one of runtime services defined in UEFI specification
and its aim is to allow a caller (OS) to pass information to the firmware,
i.e. U-Boot. This is mostly used to update firmware binary on devices by
instructions from OS.

While 'UpdateCapsule' is a runtime services function, it is, at least
initially, supported only before exiting boot services alike other runtime
functions, [Get/]SetVariable. This is because modifying storage which may
be shared with OS must be carefully designed and there is no general
assumption that we can do it.

Therefore, we practically support only "capsule on disk"; any capsule can
be handed over to UEFI subsystem as a file on a specific file system.

In this patch series, all the related definitions and structures are given
as UEFI specification describes, and basic framework for capsule support
is provided. Currently supported is
 * firmware update (Firmware Management Protocol or simply FMP)

Most of functionality of firmware update is provided by FMP driver and
it can be, by nature, system/platform-specific. So you can and should
implement your own FMP driver(s) based on your system requirements.
Under the current implementation, we provide two basic but generic
drivers with two formats:
  * FIT image format (as used in TFTP update and dfu)
  * raw image format

It's totally up to users which one, or both, should be used on users'
system depending on user requirements.

Quick usage
===
1. You can create a capsule file with the following host command:

  $ mkeficapsule [--fit  | --raw ] 

2. Put the file under:

  /EFI/UpdateCapsule of UEFI system partition

3. Specify firmware storage to be updated in "dfu_alt_info" variable
   (Please follow README.dfu for details.)

  ==> env set dfu_alt_info '...'

4. After setting up UEFI's OsIndications variable, reboot U-Boot:

  OsIndications <= EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED

Patch structure
===
Patch#1-#4,#12: preparatory patches
Patch#5-#11,#13: main part of implementation
Patch#14-#15: utilities
Patch#16-#17: pytests

[1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule

Prerequisite patches

In this version, the DFU change by Heinrich[2] is, at least temporarily,
not a prerequisite due to the discussions[3].

[2] https://lists.denx.de/pipermail/u-boot/2020-July/420950.html
[3] https://lists.denx.de/pipermail/u-boot/2020-August/424716.html

Test

* passed all the pytests which are included in this patch series
  on sandbox build locally.

Please note that the capsule pytest itself won't be run in the CI
partly because some specific configuration for sandbox build is
required and partly because there is a problem with virt-make-fs.
See test_efi_capsule_firmware.py.

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.
=> See patch#5 for my proposal
* A bunch of warnings like
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef'
where possible
  I don't think that fixing those improves anything.
* Add a document in uefi.rst

TODO's
==
(Won't be addressed in this series.)
* capsule authentication
* capsule dependency (dependency expression instruction set, or depex)
* 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

Changes
===
v6 (September 7, 2020)
* temporarily drop the prerequisite patch[2]
* add a missing field (dependencies) in efi_api.h (but never used) (Patch#10)
* add a missing field (image_capsule_support) and related definitions
  in efi_api.h (Patch#10, #15)
* cosmetic changes on constant definitions in efi_api.h (Patch#10)
* strict check for INVALID_PARAMETER at GET_IMAGE_INFO api (Patch#11,#13)
* fix warnings in pytest (Patch#16,#17)

v5 (August 3, 2020)
* removed superfluous type conversion at dfu_write_from_mem_addr()
  (Patch#2)
* introduced a common helper function, efi_create_indexed_name()
  (Patch#6,#7,#8)
* use efi_[get|set]_variable_int(), if necessary, with READ_ONLY
  (Patch#7,#8)
* return EFI_UNSUPPORTED at Patch#7
* changed the word, number, to 'index' (Patch#7,#8)
* removed 'ifdef CONFIG_EFI_CAPSULE_ON_DISK' from a header (Patch#8)
* initialize 'CapsuleLast' in efi_init_obj_list() (Patch#7,#8)
* added 'const' qualifier for filename argument at
  efi_capsule_[read|delete]_file() (Patch#8)

v4 (July 22, 2020)
* rebased to Heinrich's current efi-2020-10
* rework dfu-related code to align with Heinrich's change (Patch#1,#3)
* change a type of 'addr' argument from int to 'void *' per Sughosh's
  comment (Patch#2-#3,#11-#12)
* rework/s

Re: [PATCH v2 19/30] pwm: ti: am33xx: add subsystem driver

2020-09-06 Thread Lokesh Vutla
Hi Dario,

On 06/09/20 5:41 pm, Dario Binacchi wrote:
> The TI PWMSS driver is a simple bus driver for providing clock and power
> management for the PWM peripherals on TI AM33xx SoCs, namely eCAP,
> eHRPWM and eQEP.
> 
> Based on more recent versions of the device tree inside the linux kernel,
> I added the clock domain for each subsystem in am33x.dtsi so it can be
> enabled before probing the peripheral child device and disabled after
> its removal.
> 
> Signed-off-by: Dario Binacchi 
> ---
> 
> (no changes since v1)
> 
>  arch/arm/dts/am33xx.dtsi  |  9 +++
>  doc/device-tree-bindings/pwm/ti,pwmss.txt | 58 ++
>  drivers/pwm/Kconfig   |  9 ++-
>  drivers/pwm/Makefile  |  1 +
>  drivers/pwm/pwm-ti-pwmss.c| 95 +++
>  5 files changed, 171 insertions(+), 1 deletion(-)
>  create mode 100644 doc/device-tree-bindings/pwm/ti,pwmss.txt
>  create mode 100644 drivers/pwm/pwm-ti-pwmss.c
> 
> diff --git a/arch/arm/dts/am33xx.dtsi b/arch/arm/dts/am33xx.dtsi
> index d3dd6a16e7..fa7492a9b6 100644
> --- a/arch/arm/dts/am33xx.dtsi
> +++ b/arch/arm/dts/am33xx.dtsi
> @@ -758,6 +758,9 @@
> 0x48300180 0x48300180 0x80   /* EQEP */
> 0x48300200 0x48300200 0x80>; /* EHRPWM */
>  
> + clocks = <&l4_per_clkctrl AM3_EPWMSS0_CLKCTRL 0>;
> + clock-names = "fck";
> +
>   ecap0: ecap@48300100 {
>   compatible = "ti,am3352-ecap",
>"ti,am33xx-ecap";
> @@ -792,6 +795,9 @@
> 0x48302180 0x48302180 0x80   /* EQEP */
> 0x48302200 0x48302200 0x80>; /* EHRPWM */
>  
> + clocks = <&l4_per_clkctrl AM3_EPWMSS1_CLKCTRL 0>;
> + clock-names = "fck";
> +
>   ecap1: ecap@48302100 {
>   compatible = "ti,am3352-ecap",
>"ti,am33xx-ecap";
> @@ -826,6 +832,9 @@
> 0x48304180 0x48304180 0x80   /* EQEP */
> 0x48304200 0x48304200 0x80>; /* EHRPWM */
>  
> + clocks = <&l4_per_clkctrl AM3_EPWMSS2_CLKCTRL 0>;
> + clock-names = "fck";


hmm..I do not see these changes in upstream kernel v5.9-rc3 DT. Which version of
kernel are you using? I see al PWM nodes under am33xx-l4.dtsi

> +
>   ecap2: ecap@48304100 {
>   compatible = "ti,am3352-ecap",
>"ti,am33xx-ecap";
> diff --git a/doc/device-tree-bindings/pwm/ti,pwmss.txt 
> b/doc/device-tree-bindings/pwm/ti,pwmss.txt
> new file mode 100644
> index 00..4633697fbd
> --- /dev/null
> +++ b/doc/device-tree-bindings/pwm/ti,pwmss.txt
> @@ -0,0 +1,58 @@
> +TI SOC based PWM Subsystem
> +
> +Required properties:
> +- compatible: Must be "ti,-pwmss".
> +  for am33xx  - compatible = "ti,am33xx-pwmss";
> +  for am4372  - compatible = "ti,am4372-pwmss","ti,am33xx-pwmss";
> +  for dra746 - compatible = "ti,dra746-pwmss", "ti,am33xx-pwmss"
> +
> +- reg: physical base address and size of the registers map.
> +- address-cells: Specify the number of u32 entries needed in child nodes.
> +   Should set to 1.
> +- size-cells: specify number of u32 entries needed to specify child nodes 
> size
> + in reg property. Should set to 1.
> +- ranges: describes the address mapping of a memory-mapped bus. Should set to
> +physical address map of child's base address, physical address within
> +parent's address  space and length of the address map. For am33xx,
> +3 set of child register maps present, ECAP register space, EQEP
> +register space, EHRPWM register space.
> +
> +Also child nodes should also populated under PWMSS DT node.
> +
> +Example:
> +epwmss0: epwmss@4830 { /* PWMSS for am33xx */
> + compatible = "ti,am33xx-pwmss";
> + reg = <0x4830 0x10>;
> + ti,hwmods = "epwmss0";
> + #address-cells = <1>;
> + #size-cells = <1>;
> + ranges = <0x48300100 0x48300100 0x80   /* ECAP */
> +   0x48300180 0x48300180 0x80   /* EQEP */
> +   0x48300200 0x48300200 0x80>; /* EHRPWM */
> +
> + /* child nodes go here */
> +};
> +
> +epwmss0: epwmss@4830 { /* PWMSS for am4372 */
> + compatible = "ti,am4372-pwmss","ti,am33xx-pwmss"
> + reg = <0x4830 0x10>;
> + ti,hwmods = "epwmss0";
> + #address-cells = <1>;
> + #size-cells = <1>;
> + ranges = <0x48300100 0x48300100 0x80   /* ECAP */
> +   0x48300180 0x48300180 0x80   /* EQEP */
> +   0x48300200 0x48300200 0x80>; /* EHRPWM */
> +
> + /* child nodes go here */
> +};
> +
> +epwmss0: epwmss@4843e000 { /* PWMSS for DRA7xx */
> + compatible = "ti,dra746-pwm

Re: [PATCH] arm: mvebu: Espressobin: Set environment variable fdtfile

2020-09-06 Thread Andre Heider

Hi Marek,

On 06/09/2020 20:56, Marek Behun wrote:

On Sun, 6 Sep 2020 20:48:57 +0200
Andre Heider  wrote:


On 06/09/2020 18:12, Marek Behun wrote:

On Sun, 6 Sep 2020 11:32:47 +0200
Pali Rohár  wrote:
   

Adding Marek to loop.

On Saturday 05 September 2020 14:07:44 Andre Heider wrote:

Required for the generic distro mechanism.

Linux ships with 4 variants:
marvell/armada-3720-espressobin-v7-emmc.dtb
marvell/armada-3720-espressobin-v7.dtb
marvell/armada-3720-espressobin-emmc.dtb
marvell/armada-3720-espressobin.dtb

Use available information to determine the appropriate filename.

Tested on a v5 board without eMMC.

Signed-off-by: Andre Heider 
---
   arch/arm/mach-mvebu/Kconfig |  1 +
   board/Marvell/mvebu_armada-37xx/board.c | 42 +
   2 files changed, 43 insertions(+)

diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
index 0d8e0922a2..31f5d26dc2 100644
--- a/arch/arm/mach-mvebu/Kconfig
+++ b/arch/arm/mach-mvebu/Kconfig
@@ -100,6 +100,7 @@ config TARGET_HELIOS4
   config TARGET_MVEBU_ARMADA_37XX
bool "Support Armada 37xx platforms"
select ARMADA_3700
+   select BOARD_LATE_INIT


This should go into espressobin defconfig file. Other Armada 37xx board
do not need to have this option enabled.


I agree with this.
   

imply SCSI
   
   config TARGET_DB_88F6720

diff --git a/board/Marvell/mvebu_armada-37xx/board.c 
b/board/Marvell/mvebu_armada-37xx/board.c
index 90bfc139aa..3bf0a08897 100644
--- a/board/Marvell/mvebu_armada-37xx/board.c
+++ b/board/Marvell/mvebu_armada-37xx/board.c
@@ -5,6 +5,7 @@
   
   #include 

   #include 
+#include 
   #include 
   #include 
   #include 
@@ -50,6 +51,22 @@ DECLARE_GLOBAL_DATA_PTR;
   #define MVEBU_G2_SMI_PHY_CMD_REG (24)
   #define MVEBU_G2_SMI_PHY_DATA_REG(25)
   
+/*

+ * Memory Controller Registers
+ *
+ * Assembled based on public information:
+ * 
https://gitlab.nic.cz/turris/mox-boot-builder/-/blob/master/wtmi/main.c#L332-336
+ * 
https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell/blob/mv_ddr-armada-18.12/drivers/mv_ddr_mc6.h#L309-L332
+ *
+ * And checked against the written register values for the various topologies:
+ * 
https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell/blob/mv_ddr-armada-atf-mainline/a3700/mv_ddr_tim.h
+ */
+#define A3700_CH0_MC_CTRL2_REG MVEBU_REGISTER(0x002c4)
+#define A3700_MC_CTRL2_SDRAM_TYPE_MASK 0xf
+#define A3700_MC_CTRL2_SDRAM_TYPE_OFFS 4
+#define A3700_MC_CTRL2_SDRAM_TYPE_DDR3 2
+#define A3700_MC_CTRL2_SDRAM_TYPE_DDR4 3
+
   int board_early_init_f(void)
   {
return 0;
@@ -63,6 +80,31 @@ int board_init(void)
return 0;
   }
   
+int board_late_init(void)

+{
+   bool ddr4, emmc;
+
+   if (!of_machine_is_compatible("globalscale,espressobin"))
+   return 0;
+
+   /* If the memory controller has been configured for DDR4, we're running 
on v7 */
+   ddr4 = ((readl(A3700_CH0_MC_CTRL2_REG) >> 
A3700_MC_CTRL2_SDRAM_TYPE_OFFS)
+   & A3700_MC_CTRL2_SDRAM_TYPE_MASK) == 
A3700_MC_CTRL2_SDRAM_TYPE_DDR4;


Marek, is this correct way to determining V5 vs V7?


If for all ESPRESSObin board versions it is true that
"all v7 boards are DDR4 only and all v5 boards are DDR3 only"
then yes, you can differentiate with this code.


I believe that's the case.
There may be other ways to detect the board, this was just the most
obvious one to me.


This register is set
early in boot process, by the code in TIM image, and if it was set
incorrectly, the board would not boot into U-Boot.
   

+
+   emmc = of_machine_is_compatible("globalscale,espressobin-emmc");
+
+   if (ddr4 && emmc)
+   env_set("fdtfile", 
"marvell/armada-3720-espressobin-v7-emmc.dtb");
+   else if (ddr4)
+   env_set("fdtfile", "marvell/armada-3720-espressobin-v7.dtb");
+   else if (emmc)
+   env_set("fdtfile", "marvell/armada-3720-espressobin-emmc.dtb");
+   else
+   env_set("fdtfile", "marvell/armada-3720-espressobin.dtb");


This code would overwrite user's value of fdtfile variable. And any
change done by saveenv for fdtfile would be lost. I do not think this is
correct way as it would break booting other distributions/forks (e.g.
Marvell one) which DTB file has different name.

Also user would not be able to adjust usage of its own DTB file if this
code would overwrite it at every boot.

Cannot be put value of this variable only to default set? Like all other
variables? So value would be restored/overwritten only by 'env default'
call.


There are special U-Boot variables $soc, $board, and $boardver.
In include/config_distro_bootcmd.h look at line
"setenv efi_fdtfile ${soc}-${board}${boardver}.dtb; "
I think you should be setting $boardver env variable in your code, and
have default bootscript somehow build fdtfile name from this.


That's protected by
#if defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
though, so 32bit only.


Hi,
I meant 

Re: [PATCH 1/1] espresso7420: remove unused symbol CONFIG_DEFAULT_CONSOLE

2020-09-06 Thread Minkyu Kang
Dear Heinrich Schuchardt,

On 07/09/2020 04:33, Heinrich Schuchardt wrote:
> On 9/6/20 9:00 PM, Andre Heider wrote:
>> On 05/09/2020 12:02, Heinrich Schuchardt wrote:
>>> Symbol CONFIG_DEFAULT_CONSOLE in include/configs/espresso7420.h is not
>>> used
>>> for espresso7420_defconfig.
>>>
>>> Signed-off-by: Heinrich Schuchardt 
>>
>> I noticed that too while grepping for CONFIG_DEFAULT_CONSOLE. Afaict
>> there're quite some boards with it set but unused:
> 
> Thanks for reviewing. As the boards have different maintainers we should
> treat them in separate patches.
> 

Because those are all Samsung boards, I can approve them.
If you want please send changes to patch-set or single patch with adding 
maintainers as a CC.

thomas.ab seems to exited from company.
I will find new maintainer soon.

Thanks,
Minkyu Kang.



[PATCH 5/7] cmd: bcb: Add support for processing const string literals in bcb_set()

2020-09-06 Thread Roman Kovalivskyi
From: Eugeniu Rosca 

On request/suggestion from Simon Glass back in May 22 2019 [1], the
'strsep' mechanism implemented in bcb_set() was set to work directly
with user-provided argv strings, to avoid duplicating memory and for
the sake of simpler implementation.

However, since we recently exposed bcb_write_reboot_reason() API to be
called by U-Boot fastboot, the idea is to be able to pass const string
literals to this new BCB API, carrying the reboot reason.

Since 'strsep' (just like its older/superseded sibling 'strtok')
modifies the input string passed as parameter, BCB command in its
current state would attempt to perform in-place modifications in a
readonly string, which might lead to unexpected results.

Fix the above with the cost of one dynamic memory allocation ('strdup').
This will also ensure no compiler warnings when passing string literals
to bcb_write_reboot_reason().

[1] 
http://u-boot.10912.n7.nabble.com/PATCH-v2-0-2-Add-bcb-command-to-read-modify-write-Android-BCB-td369934i20.html#a370456

Cc: Simon Glass 
Signed-off-by: Eugeniu Rosca 
Signed-off-by: Roman Kovalivskyi 
---
 cmd/bcb.c | 17 -
 include/bcb.h |  4 ++--
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/cmd/bcb.c b/cmd/bcb.c
index 5da3526142ad..6b6f1e9a2f10 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 enum bcb_cmd {
BCB_CMD_LOAD,
@@ -179,10 +180,10 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, 
int argc,
return __bcb_load(devnum, argv[2]);
 }
 
-static int __bcb_set(char *fieldp, char *valp)
+static int __bcb_set(char *fieldp, const char *valp)
 {
int size, len;
-   char *field, *str, *found;
+   char *field, *str, *found, *tmp;
 
if (bcb_field_get(fieldp, &field, &size))
return CMD_RET_FAILURE;
@@ -193,14 +194,20 @@ static int __bcb_set(char *fieldp, char *valp)
   valp, len, size, fieldp);
return CMD_RET_FAILURE;
}
-   str = valp;
+   str = strdup(valp);
+   if (!str) {
+   printf("Error: Out of memory while strdup\n");
+   return CMD_RET_FAILURE;
+   }
 
+   tmp = str;
field[0] = '\0';
-   while ((found = strsep(&str, ":"))) {
+   while ((found = strsep(&tmp, ":"))) {
if (field[0] != '\0')
strcat(field, "\n");
strcat(field, found);
}
+   free(str);
 
return CMD_RET_SUCCESS;
 }
@@ -308,7 +315,7 @@ static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, 
int argc,
return __bcb_store();
 }
 
-int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp)
+int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp)
 {
int ret;
 
diff --git a/include/bcb.h b/include/bcb.h
index 9b662d1203a6..9ef4928642ca 100644
--- a/include/bcb.h
+++ b/include/bcb.h
@@ -9,9 +9,9 @@
 #define __BCB_H__
 
 #if CONFIG_IS_ENABLED(CMD_BCB)
-int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp);
+int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp);
 #else
-static inline int bcb_write_reboot_reason(int devnum, char *partp, char 
*reasonp)
+static inline int bcb_write_reboot_reason(int devnum, char *partp, const char 
*reasonp)
 {
return -EOPNOTSUPP;
 }
-- 
2.17.1



[PATCH 6/7] Revert "fastboot: Add default fastboot_set_reboot_flag implementation"

2020-09-06 Thread Roman Kovalivskyi
This reverts commit 0ebf9842e56c5b8cb7cb1f990bb452cc14af6225.

Current generic implementation of fastboot_set_reboot_flag is somewhat
messy and requires some additional configuration option to be enabled
besides CMD_BCB, so it reverts that implementtion in order to bring a
new cleaner one.

Next commit introduces new generic implementation of
fastboot_set_reboot_flag.

Signed-off-by: Roman Kovalivskyi 
---
 drivers/fastboot/Kconfig   | 12 --
 drivers/fastboot/Makefile  |  1 -
 drivers/fastboot/fb_bcb_impl.c | 43 --
 include/fastboot.h |  9 ---
 4 files changed, 65 deletions(-)
 delete mode 100644 drivers/fastboot/fb_bcb_impl.c

diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
index 4352ba67a713..d4436dfc9173 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -165,18 +165,6 @@ config FASTBOOT_CMD_OEM_FORMAT
  relies on the env variable partitions to contain the list of
  partitions as required by the gpt command.
 
-config FASTBOOT_USE_BCB_SET_REBOOT_FLAG
-   bool "Use BCB by fastboot to set boot reason"
-   depends on CMD_BCB && !ARCH_MESON && !ARCH_ROCKCHIP && !TARGET_KC1 && \
- !TARGET_SNIPER && !TARGET_AM57XX_EVM && !TARGET_DRA7XX_EVM
-   default y
-   help
- Fastboot could implement setting of reboot reason in a generic fashion
- via BCB commands. BCB commands are able to write reboot reason into
- command field of boot control block. In general case it is sufficient
- implementation if your platform supports BCB commands and doesn't
- require any specific reboot reason handling.
-
 endif # FASTBOOT
 
 endmenu
diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile
index 2b2c390fe4de..048af5aa8234 100644
--- a/drivers/fastboot/Makefile
+++ b/drivers/fastboot/Makefile
@@ -5,4 +5,3 @@ obj-y += fb_getvar.o
 obj-y += fb_command.o
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_mmc.o
 obj-$(CONFIG_FASTBOOT_FLASH_NAND) += fb_nand.o
-obj-$(CONFIG_FASTBOOT_USE_BCB_SET_REBOOT_FLAG) += fb_bcb_impl.o
diff --git a/drivers/fastboot/fb_bcb_impl.c b/drivers/fastboot/fb_bcb_impl.c
deleted file mode 100644
index 89ec3601b6f6..
--- a/drivers/fastboot/fb_bcb_impl.c
+++ /dev/null
@@ -1,43 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright 2020 GlobalLogic.
- * Roman Kovalivskyi 
- */
-
-#include 
-#include 
-
-/**
- * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
- *
- * Set flag which indicates that we should reboot into the bootloader
- * following the reboot that fastboot executes after this function.
- *
- * This function should be overridden in your board file with one
- * which sets whatever flag your board specific Android bootloader flow
- * requires in order to re-enter the bootloader.
- */
-int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
-{
-   char cmd[64];
-
-   if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
-   return -EINVAL;
-
-   snprintf(cmd, sizeof(cmd), "bcb load %d misc",
-CONFIG_FASTBOOT_FLASH_MMC_DEV);
-
-   if (run_command(cmd, 0))
-   return -ENODEV;
-
-   snprintf(cmd, sizeof(cmd), "bcb set command %s",
-fastboot_boot_cmds[reason]);
-
-   if (run_command(cmd, 0))
-   return -ENOEXEC;
-
-   if (run_command("bcb store", 0))
-   return -EIO;
-
-   return 0;
-}
diff --git a/include/fastboot.h b/include/fastboot.h
index 8e9ee80907df..b86b508e69fd 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -52,15 +52,6 @@ enum fastboot_reboot_reason {
FASTBOOT_REBOOT_REASONS_COUNT
 };
 
-/**
- * BCB boot commands
- */
-static const char * const fastboot_boot_cmds[] = {
-   [FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader",
-   [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot",
-   [FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery"
-};
-
 /**
  * fastboot_response() - Writes a response of the form "$tag$reason".
  *
-- 
2.17.1



[PATCH 7/7] fastboot: Implement generic fastboot_set_reboot_flag

2020-09-06 Thread Roman Kovalivskyi
It is possible to implement fastboot_set_reboot_flag in a generic way
if BCB commands are turned on for a target. Using
bcb_set_reboot_reason allows to do this by simply passing string with
correct reboot reason that should be handled during next boot process.

If BCB are turned off, then bcb_set_reboot_reason would simply return
error, so it won't introduce any new behaviour for such targets.

Signed-off-by: Roman Kovalivskyi 
---
 drivers/fastboot/fb_common.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index 736ce1cd024f..005dccf3c967 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -10,6 +10,7 @@
  * Rob Herring 
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -90,7 +91,16 @@ void fastboot_okay(const char *reason, char *response)
  */
 int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
 {
-   return -ENOSYS;
+   static const char * const boot_cmds[] = {
+   [FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader",
+   [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot",
+   [FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery"
+   };
+
+   if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
+   return -EINVAL;
+
+   return bcb_write_reboot_reason(CONFIG_FASTBOOT_FLASH_MMC_DEV, "misc", 
boot_cmds[reason]);
 }
 
 /**
-- 
2.17.1



[PATCH 4/7] cmd: bcb: Expose 'bcb_write_reboot_reason' to external callers

2020-09-06 Thread Roman Kovalivskyi
From: Eugeniu Rosca 

Fastboot is evolving and beginning with commit [1], the
upstream implementation expects bootloaders to offer support for:
 - reboot-recovery
 - reboot-fastboot

The most natural way to achieve the above is through a set of
pre-defined "reboot reason" strings, written into / read from
the BCB "command" field, e.g.:
 - bootonce-bootloader [2]
 - boot-fastboot [3]
 - boot-recovery [4]

Expose the first 'bcb' API meant to be called by e.g. fastboot stack,
to allow updating the BCB reboot reason via the BCB 'command' field.

[1] https://android.googlesource.com/platform/system/core/+/dea91b4b5354af2
("Add fastbootd.")
[2] https://android.googlesource.com/platform/bootable/recovery/+/cba7fa88d8b9
("Add 'reboot bootloader' to bootloader_message.")
[3] https://android.googlesource.com/platform/bootable/recovery/+/eee4e260f9f6
("recovery: Add "boot-fastboot" command to BCB.")
[4] https://android.googlesource.com/platform/system/core/+/5e98b633a748695f
("init: Write the reason in BCB on "reboot recovery"")

Signed-off-by: Eugeniu Rosca 
Signed-off-by: Roman Kovalivskyi 
---
 cmd/bcb.c | 20 
 include/bcb.h | 20 
 2 files changed, 40 insertions(+)
 create mode 100644 include/bcb.h

diff --git a/cmd/bcb.c b/cmd/bcb.c
index b9cd20ea3d56..5da3526142ad 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -307,6 +308,25 @@ static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, 
int argc,
return __bcb_store();
 }
 
+int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp)
+{
+   int ret;
+
+   ret = __bcb_load(devnum, partp);
+   if (ret != CMD_RET_SUCCESS)
+   return ret;
+
+   ret = __bcb_set("command", reasonp);
+   if (ret != CMD_RET_SUCCESS)
+   return ret;
+
+   ret = __bcb_store();
+   if (ret != CMD_RET_SUCCESS)
+   return ret;
+
+   return 0;
+}
+
 static struct cmd_tbl cmd_bcb_sub[] = {
U_BOOT_CMD_MKENT(load, CONFIG_SYS_MAXARGS, 1, do_bcb_load, "", ""),
U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 1, do_bcb_set, "", ""),
diff --git a/include/bcb.h b/include/bcb.h
new file mode 100644
index ..9b662d1203a6
--- /dev/null
+++ b/include/bcb.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Eugeniu Rosca 
+ *
+ * Android Bootloader Control Block Header
+ */
+
+#ifndef __BCB_H__
+#define __BCB_H__
+
+#if CONFIG_IS_ENABLED(CMD_BCB)
+int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp);
+#else
+static inline int bcb_write_reboot_reason(int devnum, char *partp, char 
*reasonp)
+{
+   return -EOPNOTSUPP;
+}
+#endif
+
+#endif /* __BCB_H__ */
-- 
2.17.1



[PATCH 2/2] fastboot: Implement generic fastboot_set_reboot_flag

2020-09-06 Thread Roman Kovalivskyi
It is possible to implement fastboot_set_reboot_flag in a generic way
if BCB commands are turned on for a target. Using
bcb_set_reboot_reason allows to do this by simply passing string with
correct reboot reason that should be handled during next boot process.

If BCB are turned off, then bcb_set_reboot_reason would simply return
error, so it won't introduce any new behaviour for such targets.

Signed-off-by: Roman Kovalivskyi 
---
 drivers/fastboot/fb_common.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index 736ce1cd024f..005dccf3c967 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -10,6 +10,7 @@
  * Rob Herring 
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -90,7 +91,16 @@ void fastboot_okay(const char *reason, char *response)
  */
 int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
 {
-   return -ENOSYS;
+   static const char * const boot_cmds[] = {
+   [FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader",
+   [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot",
+   [FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery"
+   };
+
+   if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
+   return -EINVAL;
+
+   return bcb_write_reboot_reason(CONFIG_FASTBOOT_FLASH_MMC_DEV, "misc", 
boot_cmds[reason]);
 }
 
 /**
-- 
2.17.1



[PATCH 2/7] cmd: bcb: Extract '__bcb_set' from 'do_bcb_set' for internal needs

2020-09-06 Thread Roman Kovalivskyi
From: Eugeniu Rosca 

Enriching the functionality of U-Boot 'bcb' may assume using the
existing sub-commands as building blocks for the next ones.

A clean way to achive the above is to expose a number of static
routines, each mapped to an existing user command (e.g. load/set/store),
with a user/caller-friendly prototype (i.e. do not force the caller
to wrap an integer into a string).

This second patch makes '__bcb_set' available for internal needs.

No functional change intended.

Signed-off-by: Eugeniu Rosca 
Signed-off-by: Roman Kovalivskyi 
---
 cmd/bcb.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/cmd/bcb.c b/cmd/bcb.c
index 2ed8b801a3e2..113f04ffe6b2 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -178,22 +178,21 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, 
int argc,
return __bcb_load(devnum, argv[2]);
 }
 
-static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
+static int __bcb_set(char *fieldp, char *valp)
 {
int size, len;
char *field, *str, *found;
 
-   if (bcb_field_get(argv[1], &field, &size))
+   if (bcb_field_get(fieldp, &field, &size))
return CMD_RET_FAILURE;
 
-   len = strlen(argv[2]);
+   len = strlen(valp);
if (len >= size) {
printf("Error: sizeof('%s') = %d >= %d = sizeof(bcb.%s)\n",
-  argv[2], len, size, argv[1]);
+  valp, len, size, fieldp);
return CMD_RET_FAILURE;
}
-   str = argv[2];
+   str = valp;
 
field[0] = '\0';
while ((found = strsep(&str, ":"))) {
@@ -205,6 +204,12 @@ static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int 
argc,
return CMD_RET_SUCCESS;
 }
 
+static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+   return __bcb_set(argv[1], argv[2]);
+}
+
 static int do_bcb_clear(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
 {
-- 
2.17.1



[PATCH 1/2] Revert "fastboot: Add default fastboot_set_reboot_flag implementation"

2020-09-06 Thread Roman Kovalivskyi
This reverts commit 0ebf9842e56c5b8cb7cb1f990bb452cc14af6225.

Current generic implementation of fastboot_set_reboot_flag is somewhat
messy and requires some additional configuration option to be enabled
besides CMD_BCB, so it reverts that implementtion in order to bring a
new cleaner one.

Next commit introduces new generic implementation of
fastboot_set_reboot_flag.

Signed-off-by: Roman Kovalivskyi 
---
 drivers/fastboot/Kconfig   | 12 --
 drivers/fastboot/Makefile  |  1 -
 drivers/fastboot/fb_bcb_impl.c | 43 --
 include/fastboot.h |  9 ---
 4 files changed, 65 deletions(-)
 delete mode 100644 drivers/fastboot/fb_bcb_impl.c

diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
index 4352ba67a713..d4436dfc9173 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -165,18 +165,6 @@ config FASTBOOT_CMD_OEM_FORMAT
  relies on the env variable partitions to contain the list of
  partitions as required by the gpt command.
 
-config FASTBOOT_USE_BCB_SET_REBOOT_FLAG
-   bool "Use BCB by fastboot to set boot reason"
-   depends on CMD_BCB && !ARCH_MESON && !ARCH_ROCKCHIP && !TARGET_KC1 && \
- !TARGET_SNIPER && !TARGET_AM57XX_EVM && !TARGET_DRA7XX_EVM
-   default y
-   help
- Fastboot could implement setting of reboot reason in a generic fashion
- via BCB commands. BCB commands are able to write reboot reason into
- command field of boot control block. In general case it is sufficient
- implementation if your platform supports BCB commands and doesn't
- require any specific reboot reason handling.
-
 endif # FASTBOOT
 
 endmenu
diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile
index 2b2c390fe4de..048af5aa8234 100644
--- a/drivers/fastboot/Makefile
+++ b/drivers/fastboot/Makefile
@@ -5,4 +5,3 @@ obj-y += fb_getvar.o
 obj-y += fb_command.o
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_mmc.o
 obj-$(CONFIG_FASTBOOT_FLASH_NAND) += fb_nand.o
-obj-$(CONFIG_FASTBOOT_USE_BCB_SET_REBOOT_FLAG) += fb_bcb_impl.o
diff --git a/drivers/fastboot/fb_bcb_impl.c b/drivers/fastboot/fb_bcb_impl.c
deleted file mode 100644
index 89ec3601b6f6..
--- a/drivers/fastboot/fb_bcb_impl.c
+++ /dev/null
@@ -1,43 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright 2020 GlobalLogic.
- * Roman Kovalivskyi 
- */
-
-#include 
-#include 
-
-/**
- * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
- *
- * Set flag which indicates that we should reboot into the bootloader
- * following the reboot that fastboot executes after this function.
- *
- * This function should be overridden in your board file with one
- * which sets whatever flag your board specific Android bootloader flow
- * requires in order to re-enter the bootloader.
- */
-int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
-{
-   char cmd[64];
-
-   if (reason >= FASTBOOT_REBOOT_REASONS_COUNT)
-   return -EINVAL;
-
-   snprintf(cmd, sizeof(cmd), "bcb load %d misc",
-CONFIG_FASTBOOT_FLASH_MMC_DEV);
-
-   if (run_command(cmd, 0))
-   return -ENODEV;
-
-   snprintf(cmd, sizeof(cmd), "bcb set command %s",
-fastboot_boot_cmds[reason]);
-
-   if (run_command(cmd, 0))
-   return -ENOEXEC;
-
-   if (run_command("bcb store", 0))
-   return -EIO;
-
-   return 0;
-}
diff --git a/include/fastboot.h b/include/fastboot.h
index 8e9ee80907df..b86b508e69fd 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -52,15 +52,6 @@ enum fastboot_reboot_reason {
FASTBOOT_REBOOT_REASONS_COUNT
 };
 
-/**
- * BCB boot commands
- */
-static const char * const fastboot_boot_cmds[] = {
-   [FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader",
-   [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot",
-   [FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery"
-};
-
 /**
  * fastboot_response() - Writes a response of the form "$tag$reason".
  *
-- 
2.17.1



[PATCH 3/7] cmd: bcb: Extract '__bcb_store' from 'do_bcb_store' for internal needs

2020-09-06 Thread Roman Kovalivskyi
From: Eugeniu Rosca 

Enriching the functionality of U-Boot 'bcb' may assume using the
existing sub-commands as building blocks for the next ones.

A clean way to achive the above is to expose a number of static
routines, each mapped to an existing user command (e.g. load/set/store),
with a user/caller-friendly prototype (i.e. do not force the caller
to wrap an integer into a string).

This third patch makes '__bcb_store' available for internal needs.

No functional change intended.

Signed-off-by: Eugeniu Rosca 
Signed-off-by: Roman Kovalivskyi 
---
 cmd/bcb.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/cmd/bcb.c b/cmd/bcb.c
index 113f04ffe6b2..b9cd20ea3d56 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -270,8 +270,7 @@ static int do_bcb_dump(struct cmd_tbl *cmdtp, int flag, int 
argc,
return CMD_RET_SUCCESS;
 }
 
-static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,
-   char *const argv[])
+static int __bcb_store(void)
 {
struct blk_desc *desc;
struct disk_partition info;
@@ -302,6 +301,12 @@ err:
return CMD_RET_FAILURE;
 }
 
+static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,
+   char * const argv[])
+{
+   return __bcb_store();
+}
+
 static struct cmd_tbl cmd_bcb_sub[] = {
U_BOOT_CMD_MKENT(load, CONFIG_SYS_MAXARGS, 1, do_bcb_load, "", ""),
U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 1, do_bcb_set, "", ""),
-- 
2.17.1



[PATCH 0/7] Refactor generic fastboot_set_reboot_flag implementation

2020-09-06 Thread Roman Kovalivskyi
Current generic implementation of fastboot_set_reboot_flag is somewhat
messy and requires some additional configuration option to be enabled
besides CMD_BCB, so it reverts that implementtion in order to bring a
new cleaner one.

New function called bcb_set_reboot_reason should be exposed by BCB
commands, so that all of the details could be put there instead of
dealing with it in fastboot implementation directly. After that,
fastboot_set_reboot_flag could simply pass correct reboot reason
string to the BCB implementation. If CMD_BCB is disabled then the
whole operation would return error code, which is no different
behaviour than the current implementation.

Eugeniu Rosca (5):
  cmd: bcb: Extract '__bcb_load' from 'do_bcb_load' for internal needs
  cmd: bcb: Extract '__bcb_set' from 'do_bcb_set' for internal needs
  cmd: bcb: Extract '__bcb_store' from 'do_bcb_store' for internal needs
  cmd: bcb: Expose 'bcb_write_reboot_reason' to external callers
  cmd: bcb: Add support for processing const string literals in
bcb_set()

Roman Kovalivskyi (2):
  Revert "fastboot: Add default fastboot_set_reboot_flag implementation"
  fastboot: Implement generic fastboot_set_reboot_flag

 cmd/bcb.c  | 88 +++---
 drivers/fastboot/Kconfig   | 12 -
 drivers/fastboot/Makefile  |  1 -
 drivers/fastboot/fb_bcb_impl.c | 43 -
 drivers/fastboot/fb_common.c   | 12 -
 include/bcb.h  | 20 
 include/fastboot.h |  9 
 7 files changed, 101 insertions(+), 84 deletions(-)
 delete mode 100644 drivers/fastboot/fb_bcb_impl.c
 create mode 100644 include/bcb.h

-- 
2.17.1



[PATCH 1/7] cmd: bcb: Extract '__bcb_load' from 'do_bcb_load' for internal needs

2020-09-06 Thread Roman Kovalivskyi
From: Eugeniu Rosca 

Enriching the functionality of U-Boot 'bcb' may assume using the
existing sub-commands as building blocks for the next ones.

A clean way to achive the above is to expose a number of static
routines, each mapped to an existing user command (e.g. load/set/store),
with a user/caller-friendly prototype (i.e. do not force the caller
to wrap an integer into a string).

This first patch makes '__bcb_load' available for internal needs.

No functional change, except for a tiny update in error handling.

Signed-off-by: Eugeniu Rosca 
Signed-off-by: Roman Kovalivskyi 
---
 cmd/bcb.c | 31 +++
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/cmd/bcb.c b/cmd/bcb.c
index e03218066bf2..2ed8b801a3e2 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -110,8 +110,7 @@ static int bcb_field_get(char *name, char **fieldp, int 
*sizep)
return 0;
 }
 
-static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
-  char *const argv[])
+static int __bcb_load(int devnum, const char *partp)
 {
struct blk_desc *desc;
struct disk_partition info;
@@ -119,17 +118,19 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, 
int argc,
char *endp;
int part, ret;
 
-   ret = blk_get_device_by_str("mmc", argv[1], &desc);
-   if (ret < 0)
+   desc = blk_get_devnum_by_type(IF_TYPE_MMC, devnum);
+   if (!desc) {
+   ret = -ENODEV;
goto err_read_fail;
+   }
 
-   part = simple_strtoul(argv[2], &endp, 0);
+   part = simple_strtoul(partp, &endp, 0);
if (*endp == '\0') {
ret = part_get_info(desc, part, &info);
if (ret)
goto err_read_fail;
} else {
-   part = part_get_info_by_name(desc, argv[2], &info);
+   part = part_get_info_by_name(desc, partp, &info);
if (part < 0) {
ret = part;
goto err_read_fail;
@@ -151,10 +152,10 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, 
int argc,
 
return CMD_RET_SUCCESS;
 err_read_fail:
-   printf("Error: mmc %s:%s read failed (%d)\n", argv[1], argv[2], ret);
+   printf("Error: mmc %d:%s read failed (%d)\n", devnum, partp, ret);
goto err;
 err_too_small:
-   printf("Error: mmc %s:%s too small!", argv[1], argv[2]);
+   printf("Error: mmc %d:%s too small!", devnum, partp);
goto err;
 err:
bcb_dev = -1;
@@ -163,6 +164,20 @@ err:
return CMD_RET_FAILURE;
 }
 
+static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
+  char * const argv[])
+{
+   char *endp;
+   int devnum = simple_strtoul(argv[1], &endp, 0);
+
+   if (*endp != '\0') {
+   printf("Error: Device id '%s' not a number\n", argv[1]);
+   return CMD_RET_FAILURE;
+   }
+
+   return __bcb_load(devnum, argv[2]);
+}
+
 static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[])
 {
-- 
2.17.1



RE: [v4, 00/11] mmc: fsl_esdhc: support eMMC HS200/HS400 modes

2020-09-06 Thread Y.b. Lu
Hi Jaehoon and Peng,

Any comments on the v4 patch-set?
Thank you.

Best regards,
Yangbo Lu

> -Original Message-
> From: Yangbo Lu 
> Sent: Tuesday, September 1, 2020 4:58 PM
> To: u-boot@lists.denx.de; Peng Fan ; Priyanka Jain
> ; 'Jaehoon Chung' 
> Cc: Y.b. Lu 
> Subject: [v4, 00/11] mmc: fsl_esdhc: support eMMC HS200/HS400 modes
> 
> This patch-set is to support eMMC HS200 and HS400 speed modes for
> eSDHC, and enable them on LX2160ARDB board.
> 
> CI build link
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftravis-ci
> .org%2Fgithub%2Fyangbolu1991%2Fu-boot-test%2Fbuilds%2F720875619&a
> mp;data=02%7C01%7Cyangbo.lu%40nxp.com%7Caf6b8adab90444f93e1208d
> 84e563a07%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637345
> 479527036436&sdata=L26QnuiL3ETvLbr4P1oJqxVJAoVlYY3ROg%2FWpb
> J%2B6cc%3D&reserved=0
> 
> Changes for v2:
>   - Added two patches to fix stability issue.
> Changes for v3:
>   - Explained more in commit messages.
>   - Added HS400 exit code for downgrade.
> Changes for v4:
>   - Checked returning of mmc_hs400_prepare_ddr().
>   - Added Reviewed-by.
>   - Rebased.
> 
> Yangbo Lu (11):
>   mmc: add a reinit() API
>   mmc: fsl_esdhc: add a reinit() callback
>   mmc: fsl_esdhc: support tuning for eMMC HS200
>   mmc: fsl_esdhc: clean TBCTL[TB_EN] manually during init
>   mmc: add a hs400_tuning flag
>   mmc: add a mmc_hs400_prepare_ddr() interface
>   mmc: fsl_esdhc: support eMMC HS400 mode
>   mmc: fsl_esdhc: fix mmc->clock with actual clock
>   mmc: fsl_esdhc: fix eMMC HS400 stability issue
>   arm: dts: lx2160ardb: support eMMC HS400 mode
>   configs: lx2160ardb: enable eMMC HS400 mode support
> 
>  arch/arm/dts/fsl-lx2160a-rdb.dts |   2 +
>  configs/lx2160ardb_tfa_SECURE_BOOT_defconfig |   1 +
>  configs/lx2160ardb_tfa_defconfig |   1 +
>  configs/lx2160ardb_tfa_stmm_defconfig|   1 +
>  drivers/mmc/fsl_esdhc.c  | 176
> ++-
>  drivers/mmc/mmc-uclass.c |  30 +
>  drivers/mmc/mmc.c|  14 ++-
>  include/fsl_esdhc.h  |  29 -
>  include/mmc.h|  26 +++-
>  9 files changed, 270 insertions(+), 10 deletions(-)
> 
> --
> 2.7.4



Re: [PATCH v7 05/21] arm: mvebu: x530: Use tiny SPI NOR

2020-09-06 Thread Pratyush Yadav
On 06/09/20 08:34PM, Chris Packham wrote:
> 
> On 5/09/20 3:39 am, Pratyush Yadav wrote:
> > Chris,
> >
> > On 04/09/20 09:04PM, Pratyush Yadav wrote:
> >> The SPI NOR core will get Octal DTR in following commits. This has
> >> presented a significant challenge of keeping the SPL size in check on
> >> the x530 platform.
> >>
> >> On a previous iteration of the series, adding a set of compile-time
> >> switches got the build working. But rebasing on the latest master breaks
> >> the build again. We are fighting a losing battle here. Every addition to
> >> either the SPI NOR core in the future, or any other core part of U-Boot
> >> will potentially lead to the SPL size going beyond the limit and the
> >> build failing.
> >>
> >> To combat this we will have to keep adding more and more compile-time
> >> switches, increasing the complexity of the code in the process. This is
> >> not sustainable. So use tiny SPI NOR instead. It is designed with
> >> size-limited SPL binaries in mind, and will afford us more breathing
> >> room.
> >>
> >> To enable tiny SPI NOR, CONFIG_SPI_FLASH_BAR has to be disabled.
> >>
> >> Signed-off-by: Pratyush Yadav 
> >> ---
> >>   configs/x530_defconfig | 1 -
> >>   1 file changed, 1 deletion(-)
> > Can you please test these changes on your board and confirm that tiny
> > SPI NOR works for you?
> >   
> I'll take a look when I get a chance. I'm not actually sure what the 
> true SPL size limit is for Armada-385. It's possible we could avoid the 
> build issues simply by bumping the limit up.

Bumping the limit up would be the best solution. Please check if we can 
do that.

> >> diff --git a/configs/x530_defconfig b/configs/x530_defconfig
> >> index 890c94b5c1..0570dbe9ea 100644
> >> --- a/configs/x530_defconfig
> >> +++ b/configs/x530_defconfig
> >> @@ -62,7 +62,6 @@ CONFIG_SYS_NAND_USE_FLASH_BBT=y
> >>   CONFIG_NAND_PXA3XX=y
> >>   CONFIG_SF_DEFAULT_BUS=1
> >>   CONFIG_SF_DEFAULT_SPEED=5000
> >> -CONFIG_SPI_FLASH_BAR=y
> >>   CONFIG_SPI_FLASH_MACRONIX=y
> >>   CONFIG_SPI_FLASH_STMICRO=y
> >>   CONFIG_SPI_FLASH_SST=y

-- 
Regards,
Pratyush Yadav
Texas Instruments India


RE: [PATCH v2 3/3] cosmetic: aspeed: Modify for SPDX-License

2020-09-06 Thread ChiaWei Wang
> -Original Message-
> From: Ryan Chen 
> Sent: Monday, August 31, 2020 2:03 PM
> To: Ryan Chen ; ChiaWei Wang
> ; Lukasz Majewski ;
> c...@kaod.org; Eddie James ; Simon Glass
> ; u-boot@lists.denx.de
> Subject: [PATCH v2 3/3] cosmetic: aspeed: Modify for SPDX-License
> 
> Modify SPDX-License for furture patch warning
> 
> Signed-off-by: Ryan Chen 
> ---
>  arch/arm/dts/ast2500-u-boot.dtsi | 1 +
>  include/dt-bindings/clock/aspeed-clock.h | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Chia-Wei, Wang 


RE: [PATCH v2 1/3] cosmetic: aspeed: ast2500: Rename clock header

2020-09-06 Thread ChiaWei Wang
> -Original Message-
> From: Ryan Chen 
> Sent: Monday, August 31, 2020 2:03 PM
> To: Ryan Chen ; ChiaWei Wang
> ; Lukasz Majewski ;
> c...@kaod.org; Eddie James ; Simon Glass
> ; u-boot@lists.denx.de
> Subject: [PATCH v2 1/3] cosmetic: aspeed: ast2500: Rename clock header
> 
> Rename the ast2500-scu.h to aspeed-clock.h.
> 
> Signed-off-by: Ryan Chen 
> ---
>  arch/arm/dts/ast2500-u-boot.dtsi| 2 +-
>  arch/arm/mach-aspeed/ast2500/sdram_ast2500.c| 2 +-
>  drivers/clk/aspeed/clk_ast2500.c| 2 +-
>  include/dt-bindings/clock/{ast2500-scu.h => aspeed-clock.h} | 0
>  4 files changed, 3 insertions(+), 3 deletions(-)  rename
> include/dt-bindings/clock/{ast2500-scu.h => aspeed-clock.h} (100%)
> 
Reviewed-by: Chia-Wei, Wang 



RE: [PATCH v2 2/3] clock:aspeed: Sync with Linux kernel clock header define

2020-09-06 Thread ChiaWei Wang
> -Original Message-
> From: Ryan Chen 
> Sent: Monday, August 31, 2020 2:03 PM
> To: Ryan Chen ; ChiaWei Wang
> ; Lukasz Majewski ;
> c...@kaod.org; Eddie James ; Simon Glass
> ; u-boot@lists.denx.de
> Subject: [PATCH v2 2/3] clock:aspeed: Sync with Linux kernel clock header
> define
> 
> v2: modify title description aspeed:clock -> clock:aspeed
> 
> Use kernel include/dt-bindings/clock/aspeed-clock.h define for clock driver.
> 
> Signed-off-by: Ryan Chen 
> ---
>  arch/arm/dts/ast2500-u-boot.dtsi | 20 +++
>  drivers/clk/aspeed/clk_ast2500.c | 38 +++--
>  include/dt-bindings/clock/aspeed-clock.h | 68 ++--
>  3 files changed, 68 insertions(+), 58 deletions(-)

Reviewed-by: Chia-Wei, Wang 


Re: [PATCH] time: Fix get_ticks being non-monotonic

2020-09-06 Thread Sean Anderson
On 9/6/20 9:43 PM, Simon Glass wrote:
> Hi Sean,
> 
> On Tue, 1 Sep 2020 at 13:56, Sean Anderson  wrote:
>>
>> get_ticks does not always succeed. Sometimes it can be called before the
>> timer has been initialized. If it does, it returns a negative errno.
>> This causes the timer to appear non-monotonic, because the value will
>> become much smaller after the timer is initialized.
>>
>> No users of get_ticks which I checked handle errors of this kind. Further,
>> functions like tick_to_time mangle the result of get_ticks, making it very
>> unlikely that one could check for an error without suggesting a patch such
>> as this one.
>>
>> This patch changes get_ticks to always return 0 when there is an error.
>> 0 is the least unsigned integer, ensuring get_ticks appears monotonic. This
>> has the side effect of time apparently not passing until the timer is
>> initialized. However, without this patch, time does not pass anyway,
>> because the error value is likely to be the same.
>>
>> Fixes: c8a7ba9e6a5
>> Signed-off-by: Sean Anderson 
>> ---
>>
>>  lib/time.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> Would it be better to panic so people can fix the bug?

I thought this was expected behavior. It's only a bug if you do
something like udelay before any timers are created. We just can't
report errors through get_ticks, because its users assume that it always
returns a time of some kind.

--Sean


Re: [RFC PATCH 1/1] image: add anti rollback protection for FIT Images

2020-09-06 Thread Simon Glass
Hi Thirupathaiah,

On Tue, 1 Sep 2020 at 14:48, Thirupathaiah Annapureddy
 wrote:
>
> Anti rollback protection is required when there is a need to retire
> previous versions of FIT images due to security flaws in them.
> Currently U-Boot Verified boot does not have rollback protection to
> protect against known security flaws.
>
> This change adds anti-rollback protection for FIT images.
>
> Signed-off-by: Thirupathaiah Annapureddy 
> ---
>  Kconfig|  9 +
>  common/image-fit-sig.c | 79 ++
>  common/image-fit.c | 24 +
>  include/image.h| 23 
>  4 files changed, 135 insertions(+)

Good to see this. I have a few comments though. This needs to be done
very carefully as it affects security.

>
> diff --git a/Kconfig b/Kconfig
> index 883e3f71d0..3959a6592c 100644
> --- a/Kconfig
> +++ b/Kconfig
> @@ -533,6 +533,15 @@ config FIT_CIPHER
>   Enable the feature of data ciphering/unciphering in the tool mkimage
>   and in the u-boot support of the FIT image.
>
> +config FIT_ARBP

How about using ROLLBACK instead of ARBP. It is easier to understand.

> +   bool "Enable Anti rollback version check for FIT images"

anti-rollback (add hyphen)

> +   depends on FIT_SIGNATURE
> +   default n
> +   help
> + Enable this to activate anti-rollback protection. This is required
> + when a platform needs to retire previous versions of FIT images due 
> to
> + security flaws in in them.

in

> +
>  config FIT_VERBOSE
> bool "Show verbose messages when FIT images fail"
> help
> diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c
> index cc1967109e..5103508894 100644
> --- a/common/image-fit-sig.c
> +++ b/common/image-fit-sig.c
> @@ -78,6 +78,35 @@ struct image_region *fit_region_make_list(const void *fit,
> return region;
>  }
>
> +#if !defined(USE_HOSTCC)
> +static int fit_image_verify_arbvn(const void *fit, int image_noffset)

Please add a comment as to what this does and what it checks

> +{
> +   uint8_t type;
> +   uint32_t image_arbvn;
> +   uint32_t plat_arbvn = 0;

Those three can be uint.

> +   int ret;
> +
> +   ret = fit_image_get_arbvn(fit, image_noffset, &image_arbvn);
> +   if (ret)
> +   return 0;
> +
> +   ret = fit_image_get_type(fit, image_noffset, &type);
> +   if (ret)
> +   return 0;
> +
> +   ret = board_get_arbvn(type, &plat_arbvn);
> +
> +   if (image_arbvn < plat_arbvn) {
> +   return -EPERM;
> +   } else if (image_arbvn > plat_arbvn) {
> +   ret = board_set_arbvn(type, image_arbvn);
> +   return ret;
> +   }
> +
> +   return 0;
> +}
> +#endif
> +
>  static int fit_image_setup_verify(struct image_sign_info *info,
>   const void *fit, int noffset,
>   int required_keynode, char **err_msgp)
> @@ -181,6 +210,14 @@ static int fit_image_verify_sig(const void *fit, int 
> image_noffset,
> goto error;
> }
>
> +#if !defined(USE_HOSTCC)
> +   if (IMAGE_ENABLE_ARBP && verified) {
> +   ret = fit_image_verify_arbvn(fit, image_noffset);
> +   if (ret)
> +   verified = 0;
> +   }
> +#endif
> +
> return verified ? 0 : -EPERM;
>
>  error:
> @@ -370,6 +407,40 @@ static int fit_config_check_sig(const void *fit, int 
> noffset,
> return 0;
>  }
>
> +#if !defined(USE_HOSTCC)
> +static int fit_config_verify_arbvn(const void *fit, int conf_noffset,
> +  int sig_offset)
> +{
> +   static const char default_list[] = FIT_KERNEL_PROP "\0"
> +   FIT_FDT_PROP;
> +   int ret, len;
> +   const char *prop, *iname, *end;
> +   int image_noffset;
> +
> +   /* If there is "sign-images" property, use that */
> +   prop = fdt_getprop(fit, sig_offset, "sign-images", &len);
> +   if (!prop) {
> +   prop = default_list;
> +   len = sizeof(default_list);
> +   }
> +
> +   /* Locate the images */
> +   end = prop + len;
> +   for (iname = prop; iname < end; iname += strlen(iname) + 1) {
> +   image_noffset = fit_conf_get_prop_node(fit, conf_noffset,
> +  iname);
> +   if (image_noffset < 0)
> +   return -ENOENT;
> +
> +   ret = fit_image_verify_arbvn(fit, image_noffset);
> +   if (ret)
> +   return ret;
> +   }
> +
> +   return 0;
> +}
> +#endif
> +
>  static int fit_config_verify_sig(const void *fit, int conf_noffset,
>  const void *sig_blob, int sig_offset)
>  {
> @@ -401,6 +472,14 @@ static int fit_config_verify_sig(const void *fit, int 
> conf_noffset,
> goto error;
> }
>
> +#if

Re: [PATCH] time: Fix get_ticks being non-monotonic

2020-09-06 Thread Simon Glass
Hi Sean,

On Tue, 1 Sep 2020 at 13:56, Sean Anderson  wrote:
>
> get_ticks does not always succeed. Sometimes it can be called before the
> timer has been initialized. If it does, it returns a negative errno.
> This causes the timer to appear non-monotonic, because the value will
> become much smaller after the timer is initialized.
>
> No users of get_ticks which I checked handle errors of this kind. Further,
> functions like tick_to_time mangle the result of get_ticks, making it very
> unlikely that one could check for an error without suggesting a patch such
> as this one.
>
> This patch changes get_ticks to always return 0 when there is an error.
> 0 is the least unsigned integer, ensuring get_ticks appears monotonic. This
> has the side effect of time apparently not passing until the timer is
> initialized. However, without this patch, time does not pass anyway,
> because the error value is likely to be the same.
>
> Fixes: c8a7ba9e6a5
> Signed-off-by: Sean Anderson 
> ---
>
>  lib/time.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Would it be better to panic so people can fix the bug?

Regards,
Simon


Re: [PATCH] spl: Kconfig: Record proper dependency for SPL_ATF

2020-09-06 Thread Simon Glass
On Thu, 3 Sep 2020 at 04:02, Michal Simek  wrote:
>
> ATF support was all the time based on FIT image support but this dependency
> is not recorded anywhere.
> For !SPL_FIT && SPL_ATF there is compilation error:
> common/spl/spl.c: In function 'board_init_r':
> common/spl/spl.c:689:26: error: 'struct spl_image_info' has no member named 
> 'fdt_addr'
>   689 |   spl_fixup_fdt(spl_image.fdt_addr);
>
> Signed-off-by: Michal Simek 
> ---
>
>  common/spl/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [RFC 3/4] dtoc: add support for generate stuct udevice_id

2020-09-06 Thread Simon Glass
Hi Walter,

On Fri, 7 Aug 2020 at 11:23, Walter Lozano  wrote:
>
> Hi Simon
>
> On 7/8/20 13:23, Simon Glass wrote:
> > Hi Walter,
> >
> > On Wed, 29 Jul 2020 at 10:00, Walter Lozano  
> > wrote:
> >> Hi Simon,
> >>
> >> On 28/7/20 23:42, Simon Glass wrote:
> >>> Hi Walter,
> >>>
> >>> On Sun, 26 Jul 2020 at 20:16, Walter Lozano  
> >>> wrote:
>  Hi Simon,
> 
>  On 26/7/20 11:53, Simon Glass wrote:
> > Hi Walter,
> >
> > On Tue, 7 Jul 2020 at 08:08, Walter Lozano 
> >  wrote:
> >> Hi Simon
> >>
> >> On 6/7/20 16:21, Simon Glass wrote:
> >>> Hi Walter,
> >>>
> >>> On Fri, 19 Jun 2020 at 15:12, Walter Lozano 
> >>>  wrote:
>  Based on several reports there is an increasing concern in the impact
>  of adding additional features to drivers based on compatible strings.
>  A good example of this situation is found in [1].
> 
>  In order to reduce this impact and as an initial step for further
>  reduction, propose a new way to declare compatible strings, which 
>  allows
>  to only include the useful ones.
> >>> What are the useful ones?
> >> The useful ones would be those that are used by the selected DTB by the
> >> current configuration. The idea of this patch is to declare all the
> >> possible compatible strings in a way that dtoc can generate code for
> >> only those which are going to be used, and in this way avoid lots of
> >> #ifdef like the ones shows in
> >>
> >> http://patchwork.ozlabs.org/project/uboot/patch/20200525202429.2146-1-ag...@denx.de/
> >>
> >>
>  The idea is to define compatible strings in a way to be easily 
>  parsed by
>  dtoc, which will be responsible to build struct udevice_id [] based 
>  on
>  the compatible strings present in the dtb.
> 
>  Additional features can be easily added, such as define constants
>  depending on the presence of compatible strings, which allows to 
>  enable
>  code blocks only in such cases without the need of adding additional
>  configuration options.
> 
>  [1] 
>  http://patchwork.ozlabs.org/project/uboot/patch/20200525202429.2146-1-ag...@denx.de/
> 
>  Signed-off-by: Walter Lozano 
>  ---
>   tools/dtoc/dtb_platdata.py | 32 
>   1 file changed, 32 insertions(+)
> >>> I think dtoc should be able to parse the compatible strings as they
> >>> are today - e.g. see the tiny-dm stuff.
> >> Yes, I agree. My idea is that dtoc parses compatible strings as they 
> >> are
> >> today but also in this new way. The reason for this is to allow dtoc to
> >> generate the code to include the useful compatible strings. Of course,
> >> this only makes sense if the idea of generating the compatible string
> >> associated  code is accepted.
> >>
> >> What do you think?
> > I think this is useful and better than using #ifdef in the source code
> > for this sort of thing. We need a way to specify the driver_data value
> > as well, right?
>  Yes, I agree, it is better than #ifdef and c/ould give us some extra
>  functionality.
> 
>  What doe you mean by driver_data value? Are you referring to the data
>  field? like
> 
>  static struct esdhc_soc_data usdhc_imx7d_data = {
> .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
> | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
> | ESDHC_FLAG_HS400,
>  };
> 
> >>> Actually I was talking about the .data member in struct udevice_id.
> >> So my example is correct, as usdhc_imx7d_data is the value for .data in
> >> one case as shown bellow.
>  If that is the case, I was thinking in defining a constant when specific
>  compatible strings are enabled by dtoc, based in the above case
> 
>  #ifdef FSL_ESDHC_IMX_V2
>  static struct esdhc_soc_data usdhc_imx7d_data = {
> .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
> | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
> | ESDHC_FLAG_HS400,
>  };
>  #endif
> 
>  COMPATIBLE(FSL_ESDHC, "fsl,imx7d-usdhc", &usdhc_imx7d_data, 
>  FSL_ESDHC_IMX_V2)
> 
>  So when dtoc parses COMPATIBLE and determines that compatible
>  "fsl,imx7d-usdhc" should be added it also defines FSL_ESDHC_IMX_V2.
> >>> I think we can put that data in the dt-platdata.c file perhaps.
> >> I thought the same at the beginning, but then I changed my mind, because
> >>
> >> 1- in order to work dt-platdata.c will need to include several different
> >> .h, in this example, only for fsl_esdhc_imx to work, we will need to
> >> include fsl_esdhc_imx.h where all the flags are defined.
> > Yes I hit that problem

Re: chromebook_coral: build failure

2020-09-06 Thread Simon Glass
Hi Wolfgang,

On Tue, 4 Aug 2020 at 01:59, Wolfgang Wallner
 wrote:
>
> Hi Simon,
>
> -"Simon Glass"  schrieb: -
> > Betreff: Re: chromebook_coral: build failure
> >
> > Hi Wolfgang,
> >
> > On Fri, 31 Jul 2020 at 05:44, Wolfgang Wallner
> >  wrote:
> > >
> > > Hi Simon,
> > >
> > > while trying out your ACPI patches I tried to compile
> > chromebook_coral_defconfig
> > > as a reference. Building this defconfig fails for multiple
> > definitions
> > > of "_X86EMU_env":
> > >
> > > $ git checkout v2020.07
> > > $ make distclean
> > > $ make chromebook_coral_defconfig
> > > $ make
> > >
> > > [...]
> > >   LDS u-boot.lds
> > >   LD  u-boot
> > > ld.bfd: drivers/built-in.o:(.bss._X86EMU_env+0x0): multiple
> > definition of `_X86EMU_env';
> > arch/x86/lib/built-in.o:(.bss._X86EMU_env+0x0): first defined here
> > > make: *** [Makefile:1755: u-boot] Error 1
> > >
> > > A quick and dirty workaround was to drop "#define CONFIG_BIOSEMU"
> > from
> > > include/configs/x86-chromebook.h. With this change
> > chromebook_coral_defconfig
> > > compiles fine.
> > >
> > > Do you know what is going on here, and what might be a proper fix?
> >
> > I don't see that problem myself, [...]
>
> It seems to be triggered by a change of default flags in GCC 10.
>
> I can reliably reproduce the build error on my main machine (Arch Linux with
> GCC 10), but it builds fine on a Debian 10 with GCC 8.
> A colleague told me about "-fno-common", which was changed to be on by default
> in GCC 10:
>
> https://gcc.gnu.org/gcc-10/porting_to.html
>
> I can build chromebook_coral_defconfig on my Arch with GCC 10 with:
>
>make KCFLAGS="-fcommon"
>
> However, I'm not sure what the initial problem is, as I don't know the 
> relevant
> code parts. Both of the following files declare a global variable
> "_X86EMU_env":
>
>   drivers/bios_emulator/x86emu/sys.c
>   arch/x86/lib/bios.c
>
> Should they both be part of the build for Chromebook Coral?

I think I figured this out and sent a patch. Thanks for explanation.

>
> > [...] but I do see an ACPI compile problem
> > now. that I rebase. I have added a patch for that and pushed the tree
> > to u-boot-dm/coral-working
>
> Yes, this is the reason why I wanted to compile chromebook_coral_defconfig
> as a reference :) I saw the ACPI compile problem when I tried your ACPI
> patches on my APL board and wanted to see whether I had broken something.
>
> Could you please move the fix to the beginning of the part D series when you
> send V2? It might make testing individual patches of that series easier if
> the fix is at the beginning.
>

I can't remember what the ACPI compile problem is, sorry.

Regards,
Simon


Re: [PATCH] acpi: device: Fix check for sequence number

2020-09-06 Thread Simon Glass
Hi Wolfgang,

On Thu, 13 Aug 2020 at 01:23, Wolfgang Wallner
 wrote:
>
> Hi Simon,
>
> -"Simon Glass"  schrieb: -
> > Betreff: Re: [PATCH] acpi: device: Fix check for sequence number
> >
> > Hi Wolfgang,
> >
> > On Thu, 30 Jul 2020 at 06:47, Wolfgang Wallner
> >  wrote:
> > >
> > > Currently the function acpi_check_seq() checks whether dev->req_seq is
> > > unequal to "-1", but it should actually check dev->seq. Change it to
> > > check dev->seq.
> > >
> > > For req_seq the value "-1" would be a valid (meaning 'any'), while for
> > > seq the value "-1" means 'none' and is not valid.
> > >
> > > Quoting the description of udevice in device.h:
> > >  * @req_seq: Requested sequence number for this device (-1 = any)
> > >  * @seq: Allocated sequence number for this device (-1 = none).
> > >  *   This is set up when the device is probed and will be unique
> > >  *   within the device's uclass.
> > >
> > > Signed-off-by: Wolfgang Wallner 
> > >
> > > Fixes: commit fefac0b0643b ("dm: acpi: Enhance acpi_get_name()")
> > >
> > > ---
> > >
> > >  lib/acpi/acpi_device.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> >
> > What problem are you seeing without this patch?
>
> I see the following warning: "Device 'serial@18,2' has no seq".
>
> In my case req_seq for the UART is -1 ("any"), while seq is 0.
> Why would we check for req_seq and not for seq in this function?
>
> > At present the ACPI device may not always be probed, and probing is
> > when the sequence number is currently set up.
>
> In my case the UART is already probed before the ACPI tables are generated.

I would expect req_seq to be set to the UART number, i.e. the value of
the alias (uart0, uart1) that points to the node.

I wonder why that doesn't work in your case?

Are you sure that all UARTs are probed before ACPI tables are created?
Normally U-Boot would only probe the one being used for the console.

>
> >
> > I have been thinking about dropping req_seq and doing everything when
> > the device is bound, but haven't dug into it in detail yet.
>
> regards, Wolfgang

Regards,
Simon


Re: [PATCH v2 15/30] fdt: translate address if #size-cells = <0>

2020-09-06 Thread Simon Glass
Hi Dario,

On Sun, 6 Sep 2020 at 06:13, Dario Binacchi  wrote:
>
> The __of_translate_address routine translates an address from the
> device tree into a CPU physical address. A note in the description of
> the routine explains that the crossing of any level with
> #size-cells = <0> is to be considered an error not by specification but
> since inherited from IBM. This does not happen for Texas Instruments, or
> at least for the beaglebone device tree. Without this patch, in fact,
> the translation into physical addresses of the registers contained in the
> am33xx-clocks.dtsi nodes would not be possible. They all have a parent
> with #size-cells = <0>.
>
> The CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS symbol makes translation
> possible even in the case of crossing levels with #size-cells = <0>.
>
> The patch acts conservatively on address translation, except for
> removing a check within the of_translate_one function in the
> drivers/core/of_addr.c file:
>
> +
> ranges = of_get_property(parent, rprop, &rlen);
> -   if (ranges == NULL && !of_empty_ranges_quirk(parent)) {
> -   debug("no ranges; cannot translate\n");
> -   return 1;
> -   }
> if (ranges == NULL || rlen == 0) {
> offset = of_read_number(addr, na);
> memset(addr, 0, pna * 4);
> debug("empty ranges; 1:1 translation\n");
>
> There are two reasons:
> 1 The function of_empty_ranges_quirk always returns false, invalidating
>   the following if statement in case of null ranges. Therefore one of
>   the two checks is useless.
>
> 2 The implementation of the of_translate_one function found in the
>   common/fdt_support.c file has removed this check while keeping the one
>   about the 1:1 translation.
>
> The patch adds a test and modifies a check for the correctness of an
> address in the case of enabling translation also for zero size cells.
> The added test checks translations of addresses generated by nodes of
> a device tree similar to those you can find in the files am33xx.dtsi
> and am33xx-clocks.dtsi for which the patch was created.
>
> The patch was also tested on a beaglebone black board. The addresses
> generated for the registers of the loaded drivers are those specified
> by the AM335x reference manual.
>
> Signed-off-by: Dario Binacchi 
> Tested-by: Dario Binacchi 
>
> ---
>
> Changes in v2:
> - Fix a missing line in the commit message.
> - Add dm_flags to global_data structure and GD_DM_FLG_SIZE_CELLS_0 macro
>   to test without recompiling.
> - Update the OF_CHECK_COUNTS macro in order to have just one
>   #define by bringing the GD_DM_FLG_SIZE_CELLS_0 into the expression.
> - Lower-case the 0xC019 hex number.
>
>  arch/sandbox/dts/test.dts | 21 ++
>  common/fdt_support.c  |  6 ++-
>  drivers/core/Kconfig  | 12 ++
>  drivers/core/fdtaddr.c|  2 +-
>  drivers/core/of_addr.c| 14 ++-
>  drivers/core/ofnode.c |  7 +++-
>  drivers/core/root.c   |  3 ++
>  include/asm-generic/global_data.h |  6 +++
>  test/dm/test-fdt.c| 68 ++-
>  9 files changed, 123 insertions(+), 16 deletions(-)

Looks very nice.

Reviewed-by: Simon Glass 

+Stefan Roese as an example of using run-time control in tests to
handle both cases in sandbox.

Nit below

[..]

> diff --git a/include/asm-generic/global_data.h 
> b/include/asm-generic/global_data.h
> index d4a4e2215d..d0014e812c 100644
> --- a/include/asm-generic/global_data.h
> +++ b/include/asm-generic/global_data.h
> @@ -64,6 +64,7 @@ typedef struct global_data {
> struct global_data *new_gd; /* relocated global data */
>
>  #ifdef CONFIG_DM
> +   unsigned long dm_flags;

comment

> struct udevice  *dm_root;   /* Root instance for Driver Model */
> struct udevice  *dm_root_f; /* Pre-relocation root instance */
> struct list_head uclass_root;   /* Head of core tree */
> @@ -169,4 +170,9 @@ typedef struct global_data {
>  #define GD_FLG_SKIP_LL_INIT0x2 /* Don't perform low-level init*/
>  #define GD_FLG_SMP_READY   0x4 /* SMP init is complete*/
>
> +/*
> + * Global Data Driver Model Flags
> + */
> +#define GD_DM_FLG_SIZE_CELLS_0 0x1 /* Enable #size-cells=<0> translation 
> */
> +
>  #endif /* __ASM_GENERIC_GBL_DATA_H */

Regards,
Simon


Re: [PATCH v2 02/30] clk: export generic routines

2020-09-06 Thread Simon Glass
On Sun, 6 Sep 2020 at 06:09, Dario Binacchi  wrote:
>
> Export routines that can be used by other drivers avoiding duplicating
> code.
>
> Signed-off-by: Dario Binacchi 
>
> ---
>
> Changes in v2:
> - Add the clk_ prefix to the divider functions.
> - Add kernel-doc comments to the exported functions.
>
>  drivers/clk/clk-divider.c| 24 +++
>  include/linux/clk-provider.h | 57 
>  2 files changed, 69 insertions(+), 12 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH] Makefile: mrproper shall delete doc/output/

2020-09-06 Thread Simon Glass
On Sat, 5 Sep 2020 at 03:13, Heinrich Schuchardt  wrote:
>
> HTML documentation is generated in doc/output/. This directory shall be
> deleted by 'make mrproper'
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH 2/2] spl: fdt: Record load/entry fit-images entries in 64bit format

2020-09-06 Thread Simon Glass
Hi Michal,

On Thu, 3 Sep 2020 at 05:03, Michal Simek  wrote:
>
> The commit 9f45aeb93727 ("spl: fit: implement fdt_record_loadable") which
> introduced fdt_record_loadable() state there spl_fit.c is not 64bit safe.
> Based on my tests on Xilinx ZynqMP zcu102 platform there shouldn't be a
> problem to record these addresses in 64bit format.
> The patch adds support for systems which need to load images above 4GB.

But what about 32-bit systems who read this as a 32-bit number?
Perhaps we should write 32-bit if !CONFIG_PHYS_64BIT?

>
> Signed-off-by: Michal Simek 
> ---
>
>  common/fdt_support.c | 9 ++---
>  1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/common/fdt_support.c b/common/fdt_support.c
> index b8a8768a2147..5ae75df3c658 100644
> --- a/common/fdt_support.c
> +++ b/common/fdt_support.c
> @@ -611,14 +611,9 @@ int fdt_record_loadable(void *blob, u32 index, const 
> char *name,
> if (node < 0)
> return node;
>
> -   /*
> -* We record these as 32bit entities, possibly truncating addresses.
> -* However, spl_fit.c is not 64bit safe either: i.e. we should not
> -* have an issue here.
> -*/
> -   fdt_setprop_u32(blob, node, "load", load_addr);
> +   fdt_setprop_u64(blob, node, "load", load_addr);
> if (entry_point != -1)
> -   fdt_setprop_u32(blob, node, "entry", entry_point);
> +   fdt_setprop_u64(blob, node, "entry", entry_point);
> fdt_setprop_u32(blob, node, "size", size);
> if (type)
> fdt_setprop_string(blob, node, "type", type);
> --
> 2.28.0
>

Regards,
SImon


Re: [PATCH 0/2] Add support for loading images above 4GB

2020-09-06 Thread Simon Glass
Hi Michal,

On Thu, 3 Sep 2020 at 06:30, Michal Simek  wrote:
>
> Hi,
>
> On 03. 09. 20 13:16, Heinrich Schuchardt wrote:
> > On 9/3/20 1:03 PM, Michal Simek wrote:
> >> Hi,
> >>
> >> We have several use cases where customers want to partition memory by
> >> putting NS images above 4GB. On Xilinx arm 64bit SOC 0-2GB can be used for
> >> others CPU in the systems (like R5) or for secure sw.
> >> Currently there is limitation in SPL to record load/entry addresses in
> >> 64bit format because they are recorded in 32bit only.
> >> This series add support for it.
> >> Patches have been tested on Xilinx ZynqMP zcu102 board in SD bootmode with
> >> images generated by binman. Because u-boot is using
> >> CONFIG_POSITION_INDEPENDENT it can be put to others 4k aligned addresses
> >> and there is no real need to build it to certain offset.
> >>
> >> Thanks,
> >> Michal
> >
> > Hello Michal,
> >
> > does this series require changes to doc/uImage.FIT/source_file_format.txt?
>
> I am not changing fit format. I am just changing how SPL records
> loadables in DT fit-images node. And also series is using FIT functions
> for reading these properties (at least in this version).

Well I think there should be some mention of the 32/64 bit issue added
to the FIT docs. How about adding an example with 64-bit addresses?

Regards,
Simon
'


Re: [PATCH v3 7/7] riscv: Enable watchdog for the k210

2020-09-06 Thread Simon Glass
On Tue, 1 Sep 2020 at 14:08, Sean Anderson  wrote:
>
> This enables the necessary config options.
>
> Signed-off-by: Sean Anderson 
> ---
>
> Changes in v3:
> - Note dependency on "time: Fix get_ticks being non-monotonic"
> - Add a few signed-off-bys which were sent for version 1
>
>  board/sipeed/maix/Kconfig | 2 ++
>  1 file changed, 2 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH 1/2] spl: Use standard FIT entries

2020-09-06 Thread Simon Glass
Hi Michal,

On Thu, 3 Sep 2020 at 05:03, Michal Simek  wrote:
>
> SPL is creating fit-images DT node when loadables are recorded in selected
> configuration. Entries which are created are using entry-point and
> load-addr property names. But there shouldn't be a need to use non standard
> properties because entry/load are standard FIT properties. But using
> standard FIT properties enables option to use generic FIT functions to
> descrease SPL size. Here is result for ZynqMP virt configuration:
> xilinx_zynqmp_virt: spl/u-boot-spl:all -82 spl/u-boot-spl:rodata -22 
> spl/u-boot-spl:text -60
>
> The patch causes change in run time fit image record.
> Before:
> fit-images {
> uboot {
> os = "u-boot";
> type = "firmware";
> size = <0xfd520>;
> entry-point = <0x800>;
> load-addr = <0x800>;
> };
> };
>
> After:
> fit-images {
> uboot {
> os = "u-boot";
> type = "firmware";
> size = <0xfd520>;
> entry = <0x800>;
> load = <0x800>;
> };
> };
>
> Replacing calling fdt_getprop_u32() by fit_image_get_entry/load() also
> enables support for reading entry/load properties recorded in 64bit format.
>
> Signed-off-by: Michal Simek 
> ---

Reviewed-by: Simon Glass 

Isn't there a test that could be updated here?

>
> Would be good to know history of fit-images and it's property names but
> there shouldn't be a need to use non standard names where we have
> FIT_*_PROP recorded as macros in include/image.h.

I agree.

> Concern regarding backward compatibility is definitely valid but not sure
> how many systems can be affected by this change.

Me neither. Probably a good idea to fix it.

>
> Adding temporary support for entry-point/load-addr is also possible.
> Or second way around is to create new wrappers as
> fit_image_get_entry_point()/fit_image_get_load_addr() or
> call fit_image_get_address() directly.
>
> ---
>  common/fdt_support.c | 4 ++--
>  common/spl/spl_atf.c | 7 ---
>  common/spl/spl_fit.c | 6 +-
>  3 files changed, 11 insertions(+), 6 deletions(-)
>

Regards,
SImon


Re: [PATCH v3 1/7] wdt: dw: Switch to using fls for log2

2020-09-06 Thread Simon Glass
On Tue, 1 Sep 2020 at 14:08, Sean Anderson  wrote:
>
> log_2_n_round_up is only found in arm. fls performs the same job and is
> generic.
>
> Signed-off-by: Sean Anderson 
> ---
>
> (no changes since v2)
>
> Changes in v2:
> - Fix fls being off-by-one when compared to log_2_n_round_up
>
>  drivers/watchdog/designware_wdt.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH 2/5] binman: Show an error when a file is missing

2020-09-06 Thread Simon Glass
Hi Andy,

On Fri, 4 Sep 2020 at 03:33, Andy Shevchenko
 wrote:
>
> On Thu, Sep 03, 2020 at 07:28:53PM -0600, Simon Glass wrote:
> > The recent support for missing external binaries does not show an error
> > message when a file is genuinely missing (i.e. it is missing but not
> > marked as 'external'). This means that when -m is passed to binman, it
> > will never report a missing file.
> >
> > Fix this and add a test.
>
> Acked-by: Andy Shevchenko 
>
> One note below.
>
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >  tools/binman/etype/blob.py |  7 ---
> >  tools/binman/ftest.py  |  7 +++
> >  tools/binman/test/173_missing_blob.dts | 14 ++
> >  3 files changed, 25 insertions(+), 3 deletions(-)
> >  create mode 100644 tools/binman/test/173_missing_blob.dts
> >
> > diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
> > index c5f97c85a38..66cf243976e 100644
> > --- a/tools/binman/etype/blob.py
> > +++ b/tools/binman/etype/blob.py
> > @@ -37,13 +37,14 @@ class Entry_blob(Entry):
> >
> >  def ObtainContents(self):
> >  self._filename = self.GetDefaultFilename()
> > -self._pathname = tools.GetInputFilename(self._filename,
> > -
> > self.section.GetAllowMissing())
> > +self._pathname = tools.GetInputFilename(
> > +self._filename, self.external and 
> > self.section.GetAllowMissing())
>
> I hope you know that 'and' has a bit different semantics in Python than in C 
> for example.

I think I understand it, in the sense that 'x and y' returns y if x is
true. Is that what you mean?

> And why to move first parameter to new line?

I think the style is to either line up the params agained the '(' or
indented 4 from the start of the line. I'll flip it back as pylint3
doesn't seem to mind either way.

Regards,
Simon


Re: Fwd: [PATCH 1/1] espresso7420: remove unused symbol CONFIG_DEFAULT_CONSOLE

2020-09-06 Thread Thomas Abraham
Sorry, Heinrich. Unfortunately, we are not the same person.

Best regards,

Tom Abraham

On 9/5/20 6:55 AM, Heinrich Schuchardt wrote:
> Hello Thomas,
>
> I tried to send an U-Boot patch to Thomas Abraham
> . But the email address thomas...@samsung.com
> does not exist anymore.
>
> I assume that you are the same person.
>
> What shall happen with board/samsung/espresso7420/MAINTAINERS?
>
> Best regards
>
> Heinrich
>
>  Forwarded Message 
> Subject: [PATCH 1/1] espresso7420: remove unused symbol
> CONFIG_DEFAULT_CONSOLE
> Date: Sat,  5 Sep 2020 12:02:10 +0200
> From: Heinrich Schuchardt 
> To: Thomas Abraham 
> CC: u-boot@lists.denx.de, Heinrich Schuchardt 
>
> Symbol CONFIG_DEFAULT_CONSOLE in include/configs/espresso7420.h is not used
> for espresso7420_defconfig.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  include/configs/espresso7420.h | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/include/configs/espresso7420.h b/include/configs/espresso7420.h
> index 5aeb009f03..2495db93f8 100644
> --- a/include/configs/espresso7420.h
> +++ b/include/configs/espresso7420.h
> @@ -18,9 +18,6 @@
>  #define CONFIG_SPL_STACK CONFIG_IRAM_END
>  #define CONFIG_SYS_INIT_SP_ADDR  CONFIG_IRAM_END
>
> -/* select serial console configuration */
> -#define CONFIG_DEFAULT_CONSOLE   "console=ttySAC1,115200n8\0"
> -
>  /* DRAM Memory Banks */
>  #define SDRAM_BANK_SIZE  (256UL << 20UL) /* 256 MB */
>
> --
> 2.28.0
>


pEpkey.asc
Description: application/pgp-keys


U-boot command prompt failed to load in Raspberry pi 4

2020-09-06 Thread satish reddy
Hi,

I'm porting u-boot for raspberry pi 4. I cross compiled u-boot for
Raspberry pi 4 and copied u-boot.bin and latest firmware files start4.elf
and fixup4.dat from git into a SD card. My configuration file contains
enable_uart=1
arm_64bit=1
uart_2ndstage=1
kernel=u-boot.bin

Inserted SD card into pi and started monitoring logs from serial port.
it got stuck at starting start3.elf @ 0xfec00200
I am not able to find the solution for this issue. Please kindly help to
resolve this u-boot bug in raspberry pi 4.

Regards,
Satish


Re: [PATCH 0/8] PinePhone automatic device tree selection

2020-09-06 Thread André Przywara
On 03/09/2020 06:07, Samuel Holland wrote:

Hi Samuel,

> This patch series implements a feature to automatically choose the
> right PinePhone device tree by probing the hardware. It then extends
> the functionality to pass the chosen DTB name to the boot command.
> Finally, I add device trees and a defconfig for the PinePhone.
> 
> I'm aware that Andre has concerns about updating the device tree files.
> It would be unfortunate for this to block new hardware support.

I agree that it shouldn't block it.

> Since
> the device trees are primarily maintained in the Linux repository, and
> only copied here, I believe compatibility concerns should be directed
> there, not here.

Sigh. I tried that there, multiple times, and was basically dismissed.
IIRC the main argument was that we (as the sunxi community) do not have
the resources to pull off something like compatible DTs. The DTs are
being created and written as we go, so maintaining forward compatibility
is not something the Linux maintainers wanted to subscribe to.
And while I see that's *some* extra effort, I argued that it's worth it,
even providing solutions. Otherwise I am afraid that we end up in the
embedded rabbit hole that we see today, where dozens of images are
traded around, even though there are generic distributions available.

We parted by agreeing on putting those necessary DT changes into U-Boot
instead. Commit ababb5920e899 is one example of this. I tried to prevent
further changes, but failed.

> In any case, the first 6 patches can be merged
> independently, so I request that they be merged even if patches 7-8 are
> not. I am mainly including the last two patches for ease of testing.

So I have some easy patches that improve DT compatibility, I guess we
can just apply them later. The most prominent issue is the change of the
RTC compatible name. This seems to cost us the RTC (bearable?) and, in
turn, the debouncing feature of the GPIO controller (through the newly
introduced clock in the RTC).
There seem to be more issues that popped up in testing. I guess we would
need to define some supported kernels, and test them. The effort for
this depends on how far back we want to support Linux kernels and with
what feature set. I ran a headless board fine here with Ubuntu's 18.04
original kernel, which is 4.15 based. I might concede to give this up,
if needed, to go back to only 4.19 (Debian), or maybe 4.18 (Ubuntu
18.04.2 HWE kernel).

I will have a look at the other patches later. It seems like you jump
through some hoops to be able to set fdtfile in U-Boot proper later? I
consider this conceptually dodgy ($fdtcontroladdr should be all you
need), but don't care enough, as it does not seem to break things.

Cheers,
Andre

> Samuel Holland (8):
>   sunxi: board: Use a more descriptive variable name
>   sunxi: board: Add a helper to get the SPL DT name
>   sunxi: board: Simplify Pine A64 DT selection logic
>   sunxi: board: Add PinePhone DT selection logic
>   sunxi: board: Save the chosen DT name in the SPL header
>   sunxi: board: Set fdtfile to match the DT chosen by SPL
>   sunxi: DT: A64: update device tree files
>   sunxi: a64: Add a defconfig for the PinePhone
> 
>  arch/arm/dts/Makefile |   4 +
>  arch/arm/dts/axp803.dtsi  |  82 +--
>  arch/arm/dts/sun50i-a64-amarula-relic.dts | 109 +++-
>  arch/arm/dts/sun50i-a64-bananapi-m64.dts  | 118 ++--
>  arch/arm/dts/sun50i-a64-cpu-opp.dtsi  |  75 +++
>  arch/arm/dts/sun50i-a64-nanopi-a64.dts|  70 +--
>  .../dts/sun50i-a64-oceanic-5205-5inmfd.dts|  31 +-
>  arch/arm/dts/sun50i-a64-olinuxino-emmc.dts|  12 +-
>  arch/arm/dts/sun50i-a64-olinuxino.dts | 113 ++--
>  arch/arm/dts/sun50i-a64-orangepi-win.dts  | 127 +++--
>  arch/arm/dts/sun50i-a64-pine64-lts.dts|   7 +-
>  arch/arm/dts/sun50i-a64-pine64-plus.dts   |  52 +-
>  arch/arm/dts/sun50i-a64-pine64.dts|  97 ++--
>  arch/arm/dts/sun50i-a64-pinebook-u-boot.dtsi  |  17 -
>  arch/arm/dts/sun50i-a64-pinebook.dts  | 237 ++--
>  arch/arm/dts/sun50i-a64-pinephone-1.0.dts |  11 +
>  arch/arm/dts/sun50i-a64-pinephone-1.1.dts |  30 +
>  arch/arm/dts/sun50i-a64-pinephone-1.2.dts |  40 ++
>  arch/arm/dts/sun50i-a64-pinephone.dtsi| 429 ++
>  arch/arm/dts/sun50i-a64-pinetab.dts   | 460 +++
>  arch/arm/dts/sun50i-a64-sopine-baseboard.dts  | 113 ++--
>  arch/arm/dts/sun50i-a64-sopine.dtsi   |  69 +--
>  arch/arm/dts/sun50i-a64-teres-i-u-boot.dtsi   |  41 --
>  arch/arm/dts/sun50i-a64-teres-i.dts   | 138 -
>  arch/arm/dts/sun50i-a64.dtsi  | 532 ++
>  arch/arm/mach-sunxi/Kconfig   |   7 +
>  board/sunxi/board.c   |  97 +++-
>  configs/pinephone_defconfig   |  12 +
>  include/dt-bindings/clock/sun50i-a64-ccu.h|   4 +-
>  include/dt-bindings/clock/sun8i-de2.h |   3 +
>  inclu

Re: [PATCH v7 05/21] arm: mvebu: x530: Use tiny SPI NOR

2020-09-06 Thread Chris Packham

On 7/09/20 11:07 am, Chris Packham wrote:
> Hi Pratyush,
>
> On 5/09/20 3:39 am, Pratyush Yadav wrote:
>> Chris,
>>
>> On 04/09/20 09:04PM, Pratyush Yadav wrote:
>>> The SPI NOR core will get Octal DTR in following commits. This has
>>> presented a significant challenge of keeping the SPL size in check on
>>> the x530 platform.
>>>
>>> On a previous iteration of the series, adding a set of compile-time
>>> switches got the build working. But rebasing on the latest master 
>>> breaks
>>> the build again. We are fighting a losing battle here. Every 
>>> addition to
>>> either the SPI NOR core in the future, or any other core part of U-Boot
>>> will potentially lead to the SPL size going beyond the limit and the
>>> build failing.
>>>
>>> To combat this we will have to keep adding more and more compile-time
>>> switches, increasing the complexity of the code in the process. This is
>>> not sustainable. So use tiny SPI NOR instead. It is designed with
>>> size-limited SPL binaries in mind, and will afford us more breathing
>>> room.
>>>
>>> To enable tiny SPI NOR, CONFIG_SPI_FLASH_BAR has to be disabled.
>>>
>>> Signed-off-by: Pratyush Yadav 
>>> ---
>>>   configs/x530_defconfig | 1 -
>>>   1 file changed, 1 deletion(-)
>> Can you please test these changes on your board and confirm that tiny
>> SPI NOR works for you?
>
> It booted OK but when I try to write something to SPI flash I get an 
> error
>
> => sf probe
> SF: Detected n25q128a13 with page size 256 Bytes, erase size 4 KiB, 
> total 16 MiB
> => sf update ${fileaddr} 0 ${filesize} device 0 offset 0x0, size 0x10
> SPI flash failed in erase step
>
> => sf erase 0 0x10
> SF: 1048576 bytes @ 0x0 Erased: ERROR
>
> Unfortunately I didn't test this before applying your series so I'm 
> not sure if it is because of your changes or a preexisting issue with 
> v2020.10-rc3
>
Booting with v2020.10-rc3-00086-ge5df264e7aac (i.e. master as of this 
morning) I can write to SPI flash so it looks like it is something in 
your series. Let me know if you want me to try something else out.
>>> diff --git a/configs/x530_defconfig b/configs/x530_defconfig
>>> index 890c94b5c1..0570dbe9ea 100644
>>> --- a/configs/x530_defconfig
>>> +++ b/configs/x530_defconfig
>>> @@ -62,7 +62,6 @@ CONFIG_SYS_NAND_USE_FLASH_BBT=y
>>>   CONFIG_NAND_PXA3XX=y
>>>   CONFIG_SF_DEFAULT_BUS=1
>>>   CONFIG_SF_DEFAULT_SPEED=5000
>>> -CONFIG_SPI_FLASH_BAR=y
>>>   CONFIG_SPI_FLASH_MACRONIX=y
>>>   CONFIG_SPI_FLASH_STMICRO=y
>>>   CONFIG_SPI_FLASH_SST=y

Re: [PATCH v7 05/21] arm: mvebu: x530: Use tiny SPI NOR

2020-09-06 Thread Chris Packham
Hi Pratyush,

On 5/09/20 3:39 am, Pratyush Yadav wrote:
> Chris,
>
> On 04/09/20 09:04PM, Pratyush Yadav wrote:
>> The SPI NOR core will get Octal DTR in following commits. This has
>> presented a significant challenge of keeping the SPL size in check on
>> the x530 platform.
>>
>> On a previous iteration of the series, adding a set of compile-time
>> switches got the build working. But rebasing on the latest master breaks
>> the build again. We are fighting a losing battle here. Every addition to
>> either the SPI NOR core in the future, or any other core part of U-Boot
>> will potentially lead to the SPL size going beyond the limit and the
>> build failing.
>>
>> To combat this we will have to keep adding more and more compile-time
>> switches, increasing the complexity of the code in the process. This is
>> not sustainable. So use tiny SPI NOR instead. It is designed with
>> size-limited SPL binaries in mind, and will afford us more breathing
>> room.
>>
>> To enable tiny SPI NOR, CONFIG_SPI_FLASH_BAR has to be disabled.
>>
>> Signed-off-by: Pratyush Yadav 
>> ---
>>   configs/x530_defconfig | 1 -
>>   1 file changed, 1 deletion(-)
> Can you please test these changes on your board and confirm that tiny
> SPI NOR works for you?

It booted OK but when I try to write something to SPI flash I get an error

=> sf probe
SF: Detected n25q128a13 with page size 256 Bytes, erase size 4 KiB, 
total 16 MiB
=> sf update ${fileaddr} 0 ${filesize} device 0 offset 0x0, size 0x10
SPI flash failed in erase step

=> sf erase 0 0x10
SF: 1048576 bytes @ 0x0 Erased: ERROR

Unfortunately I didn't test this before applying your series so I'm not 
sure if it is because of your changes or a preexisting issue with 
v2020.10-rc3

>   
>> diff --git a/configs/x530_defconfig b/configs/x530_defconfig
>> index 890c94b5c1..0570dbe9ea 100644
>> --- a/configs/x530_defconfig
>> +++ b/configs/x530_defconfig
>> @@ -62,7 +62,6 @@ CONFIG_SYS_NAND_USE_FLASH_BBT=y
>>   CONFIG_NAND_PXA3XX=y
>>   CONFIG_SF_DEFAULT_BUS=1
>>   CONFIG_SF_DEFAULT_SPEED=5000
>> -CONFIG_SPI_FLASH_BAR=y
>>   CONFIG_SPI_FLASH_MACRONIX=y
>>   CONFIG_SPI_FLASH_STMICRO=y
>>   CONFIG_SPI_FLASH_SST=y

[PATCH v2] configs: powerpc: Don't set CONFIG_ENV_ADDR for QorIQ SPIFLASH

2020-09-06 Thread Chris Packham
Setting CONFIG_ENV_ADDR to something other than 0 stops gd->env_addr
from being allocated dynamically. When the environment is in SPI we need
it to be allocated as we can't use a direct memory mapped address.

Signed-off-by: Chris Packham 
---

Changes in v2:
- Update the other SPIFLASH_defconfigs

 configs/T1023RDB_SPIFLASH_defconfig| 1 -
 configs/T1024RDB_SPIFLASH_defconfig| 1 -
 configs/T1040D4RDB_SPIFLASH_defconfig  | 1 -
 configs/T1040RDB_SPIFLASH_defconfig| 1 -
 configs/T1042D4RDB_SPIFLASH_defconfig  | 1 -
 configs/T1042RDB_PI_SPIFLASH_defconfig | 1 -
 configs/T2080QDS_SPIFLASH_defconfig| 1 -
 configs/T2080RDB_SPIFLASH_defconfig| 1 -
 configs/T2081QDS_SPIFLASH_defconfig| 1 -
 9 files changed, 9 deletions(-)

diff --git a/configs/T1023RDB_SPIFLASH_defconfig 
b/configs/T1023RDB_SPIFLASH_defconfig
index b33bf44c1198..0b16784b616b 100644
--- a/configs/T1023RDB_SPIFLASH_defconfig
+++ b/configs/T1023RDB_SPIFLASH_defconfig
@@ -50,7 +50,6 @@ 
CONFIG_MTDIDS_DEFAULT="nor0=fe800.nor,nand0=fff80.flash,spi0=spife11
 
CONFIG_MTDPARTS_DEFAULT="mtdparts=fe800.nor:1m(uboot),5m(kernel),128k(dtb),96m(fs),-(user);fff80.flash:1m(uboot),5m(kernel),128k(dtb),96m(fs),-(user);spife11.0:1m(uboot),5m(kernel),128k(dtb),-(user)"
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_ENV_ADDR=0xFFFC9000
 CONFIG_FSL_CAAM=y
 CONFIG_FSL_ESDHC=y
 CONFIG_MTD=y
diff --git a/configs/T1024RDB_SPIFLASH_defconfig 
b/configs/T1024RDB_SPIFLASH_defconfig
index 31cbc7a95591..784d125bceb6 100644
--- a/configs/T1024RDB_SPIFLASH_defconfig
+++ b/configs/T1024RDB_SPIFLASH_defconfig
@@ -53,7 +53,6 @@ 
CONFIG_MTDPARTS_DEFAULT="mtdparts=fe800.nor:1m(uboot),5m(kernel),128k(dtb),9
 CONFIG_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_ENV_ADDR=0xFFFC9000
 CONFIG_DM=y
 CONFIG_FSL_CAAM=y
 CONFIG_SYS_FSL_DDR3=y
diff --git a/configs/T1040D4RDB_SPIFLASH_defconfig 
b/configs/T1040D4RDB_SPIFLASH_defconfig
index 04578bf7c19c..ed3a7bfa1d8a 100644
--- a/configs/T1040D4RDB_SPIFLASH_defconfig
+++ b/configs/T1040D4RDB_SPIFLASH_defconfig
@@ -47,7 +47,6 @@ 
CONFIG_MTDIDS_DEFAULT="nor0=fe800.nor,nand0=fff80.flash,spi0=spife11
 
CONFIG_MTDPARTS_DEFAULT="mtdparts=fe800.nor:1m(uboot),5m(kernel),128k(dtb),96m(fs),-(user);fff80.flash:2m(uboot),9m(kernel),128k(dtb),96m(fs),-(user);spife11.0:2m(uboot),9m(kernel),128k(dtb),-(user)"
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_ENV_ADDR=0xFFFC9000
 CONFIG_FSL_CAAM=y
 CONFIG_FSL_ESDHC=y
 CONFIG_MTD=y
diff --git a/configs/T1040RDB_SPIFLASH_defconfig 
b/configs/T1040RDB_SPIFLASH_defconfig
index 4b674d5955a2..f162019ab3e7 100644
--- a/configs/T1040RDB_SPIFLASH_defconfig
+++ b/configs/T1040RDB_SPIFLASH_defconfig
@@ -47,7 +47,6 @@ 
CONFIG_MTDIDS_DEFAULT="nor0=fe800.nor,nand0=fff80.flash,spi0=spife11
 
CONFIG_MTDPARTS_DEFAULT="mtdparts=fe800.nor:1m(uboot),5m(kernel),128k(dtb),96m(fs),-(user);fff80.flash:2m(uboot),9m(kernel),128k(dtb),96m(fs),-(user);spife11.0:2m(uboot),9m(kernel),128k(dtb),-(user)"
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_ENV_ADDR=0xFFFC9000
 CONFIG_FSL_CAAM=y
 CONFIG_SYS_FSL_DDR3=y
 CONFIG_FSL_ESDHC=y
diff --git a/configs/T1042D4RDB_SPIFLASH_defconfig 
b/configs/T1042D4RDB_SPIFLASH_defconfig
index e670f068e698..fae57883a474 100644
--- a/configs/T1042D4RDB_SPIFLASH_defconfig
+++ b/configs/T1042D4RDB_SPIFLASH_defconfig
@@ -50,7 +50,6 @@ 
CONFIG_MTDPARTS_DEFAULT="mtdparts=fe800.nor:1m(uboot),5m(kernel),128k(dtb),9
 CONFIG_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_ENV_ADDR=0xFFFC9000
 CONFIG_DM=y
 CONFIG_FSL_CAAM=y
 CONFIG_DM_I2C=y
diff --git a/configs/T1042RDB_PI_SPIFLASH_defconfig 
b/configs/T1042RDB_PI_SPIFLASH_defconfig
index afeb65aa4732..3b4e2a4fbfdd 100644
--- a/configs/T1042RDB_PI_SPIFLASH_defconfig
+++ b/configs/T1042RDB_PI_SPIFLASH_defconfig
@@ -49,7 +49,6 @@ 
CONFIG_MTDIDS_DEFAULT="nor0=fe800.nor,nand0=fff80.flash,spi0=spife11
 
CONFIG_MTDPARTS_DEFAULT="mtdparts=fe800.nor:1m(uboot),5m(kernel),128k(dtb),96m(fs),-(user);fff80.flash:2m(uboot),9m(kernel),128k(dtb),96m(fs),-(user);spife11.0:2m(uboot),9m(kernel),128k(dtb),-(user)"
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_ENV_ADDR=0xFFFC9000
 CONFIG_FSL_CAAM=y
 CONFIG_SYS_FSL_DDR3=y
 CONFIG_FSL_ESDHC=y
diff --git a/configs/T2080QDS_SPIFLASH_defconfig 
b/configs/T2080QDS_SPIFLASH_defconfig
index 0e787ea440af..cd5e445db14c 100644
--- a/configs/T2080QDS_SPIFLASH_defconfig
+++ b/configs/T2080QDS_SPIFLASH_defconfig
@@ -46,7 +46,6 @@ 
CONFIG_MTDPARTS_DEFAULT="mtdparts=fe800.nor:1m(uboot),5m(kernel),128k(dtb),9
 CONFIG_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_ENV_ADDR=0xFFFC9000
 CONFIG_DM=y
 CONFIG_FSL_CAAM=y
 CONFIG_DM_I2C=y
diff --git a/configs/T2080RDB_SPIFLASH_defconfig 
b/configs/T2080RDB_SPIFLASH_defconfig
index 62cbab1f0734..ba4ac1010502 100644
--- a/configs/T2080RDB_SPIFLASH_def

Re: [PATCH v2 1/3] arm64: Mention 4K aligned load addresses in the PIE Kconfig help

2020-09-06 Thread André Przywara
On 04/09/2020 19:42, Stephen Warren wrote:
> On 9/4/20 3:07 AM, Edgar E. Iglesias wrote:
>> From: "Edgar E. Iglesias" 
>>
>> Mention the requirement of 4K aligned load addresses in the
>> help section for the POSITION_INDEPENDENT option.
>>
>> Suggested-by: Michal Simek 
>> Signed-off-by: Edgar E. Iglesias 
>> ---
>>  arch/arm/Kconfig | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
>> index f30c2639ec..c144c08612 100644
>> --- a/arch/arm/Kconfig
>> +++ b/arch/arm/Kconfig
>> @@ -21,6 +21,9 @@ config POSITION_INDEPENDENT
>>information that is embedded in the binary to support U-Boot
>>relocating itself to the top-of-RAM later during execution.
>>  
>> +  When this option is enabled, U-Boot needs to be loaded at a
>> +  4K aligned address.
> 
> I don't believe this restriction should be documented as part of
> POSITION_INDEPENDENT; the restriction always exists at least for 64-bit
> ARM, since arch/arm/lib/relocate_64.S relocate_code uses the same
> assembly sequence that imposes this restriction, and IIUC that code is
> unconditionally used.

While this is true, the difference is that without POSITION_INDEPENDENT
the alignment is easily determined by the hardcoded load address. So we
should actually have a build time check on this.

With POSITION_INDEPENDENT, however, the load address is only known at
runtime (somewhat under the user's control, if you like). So a warning
or hint here might be useful. But maybe it should be noted as a general
restriction in the paragraph above:
" ... from almost any address" => "from almost any 4K aligned address"

Cheers,
Andre.


[PATCH v3 57/57] x86: coral: Update config and device tree for ACPI

2020-09-06 Thread Simon Glass
Enable new features and provide require device-tree config so that U-Boot
produces the correct ACPI tables on Coral.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Rebase to master

Changes in v2:
- Rebase to master

Changes in v1:
- Add NHLT information
- Fix i2c PCI addresses
- Rename acpi-probed to linux,probed
- Rename cpi,hid-desc-reg-offset to hid-desc-addr
- UIse hid-over-i2 compatible string
- Update ACPI ordering to include multiple CPUs
- Use acpi,ddn instead of acpi,desc

 arch/x86/dts/chromebook_coral.dts  | 224 +++--
 configs/chromebook_coral_defconfig |  11 +-
 2 files changed, 220 insertions(+), 15 deletions(-)

diff --git a/arch/x86/dts/chromebook_coral.dts 
b/arch/x86/dts/chromebook_coral.dts
index a17a9c28003..8c08259b001 100644
--- a/arch/x86/dts/chromebook_coral.dts
+++ b/arch/x86/dts/chromebook_coral.dts
@@ -15,14 +15,20 @@
 #include "flashmap-16mb-rw.dtsi"
 #endif
 
+#include 
+#include 
+#include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 / {
model = "Google Coral";
@@ -40,6 +46,14 @@
i2c5 = &i2c_5;
i2c6 = &i2c_6;
i2c7 = &i2c_7;
+   mmc1 = &sdmmc;
+   };
+
+   board: board {
+   compatible = "google,coral";
+   recovery-gpios = <&gpio_nw (-1) GPIO_ACTIVE_LOW>;
+   write-protect-gpios = <&gpio_nw GPIO_75 GPIO_ACTIVE_HIGH>;
+   phase-enforce-gpios = <&gpio_n GPIO_10 GPIO_ACTIVE_HIGH>;
};
 
config {
@@ -48,6 +62,15 @@
 
chosen {
stdout-path = &serial;
+   e820-entries = /bits/ 64 <
+   IOMAP_P2SB_BAR IOMAP_P2SB_SIZE E820_RESERVED
+   MCH_BASE_ADDRESS MCH_SIZE  E820_RESERVED>;
+   u-boot,acpi-ssdt-order = <&cpu_0 &cpu_1 &cpu_2 &cpu_3
+   &i2c_0 &i2c_1 &i2c_2 &i2c_3 &i2c_4 &i2c_5
+   &sdmmc &maxim_codec &wifi &da_codec &tpm
+   &elan_touchscreen &raydium_touchscreen
+   &elan_touchpad &synaptics_touchpad &wacom_digitizer>;
+   u-boot,acpi-dsdt-order = <&board &lpc>;
};
 
clk: clock {
@@ -60,7 +83,7 @@
#address-cells = <1>;
#size-cells = <0>;
 
-   cpu@0 {
+   cpu_0: cpu@0 {
u-boot,dm-pre-reloc;
device_type = "cpu";
compatible = "intel,apl-cpu";
@@ -68,21 +91,21 @@
intel,apic-id = <0>;
};
 
-   cpu@1 {
+   cpu_1: cpu@1 {
device_type = "cpu";
compatible = "intel,apl-cpu";
reg = <1>;
intel,apic-id = <2>;
};
 
-   cpu@2 {
+   cpu_2: cpu@2 {
device_type = "cpu";
compatible = "intel,apl-cpu";
reg = <2>;
intel,apic-id = <4>;
};
 
-   cpu@3 {
+   cpu_3: cpu@3 {
device_type = "cpu";
compatible = "intel,apl-cpu";
reg = <3>;
@@ -128,6 +151,10 @@
 */
fsp_s: fsp-s {
};
+
+   nhlt {
+   intel,dmic-channels = <4>;
+   };
};
 
punit@0,1 {
@@ -136,21 +163,29 @@
compatible = "intel,apl-punit";
};
 
+   gma@2,0 {
+   reg = <0x1000 0 0 0 0>;
+   compatible = "vesa-fb";
+   };
+
p2sb: p2sb@d,0 {
u-boot,dm-pre-reloc;
reg = <0x02006810 0 0 0 0>;
compatible = "intel,p2sb";
early-regs = ;
+   pci,no-autoconfig;
 
n {
compatible = "intel,apl-pinctrl";
u-boot,dm-pre-reloc;
intel,p2sb-port-id = ;
+   acpi,path = "\\_SB.GPO0";
gpio_n: gpio-n {
compatible = "intel,gpio";
u-boot,dm-pre-reloc;
gpio-controller;
#gpio-cells = <2>;
+   linux-name = "INT3452:00";
};
};
 
@@ -159,11 +194,13 @@
compatible = "intel,apl-pinctrl";
intel,p2sb-port-id = ;
  

[PATCH v3 55/57] x86: Add a way to add to the e820 memory table

2020-09-06 Thread Simon Glass
Some boards want to reserve extra regions of memory. Add a 'chosen'
property to support this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/lib/fsp/fsp_dram.c | 17 +
 doc/device-tree-bindings/chosen.txt | 18 ++
 2 files changed, 35 insertions(+)

diff --git a/arch/x86/lib/fsp/fsp_dram.c b/arch/x86/lib/fsp/fsp_dram.c
index faa819fab4b..a76497d4e01 100644
--- a/arch/x86/lib/fsp/fsp_dram.c
+++ b/arch/x86/lib/fsp/fsp_dram.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -92,6 +93,8 @@ unsigned int install_e820_map(unsigned int max_entries,
unsigned int num_entries = 0;
const struct hob_header *hdr;
struct hob_res_desc *res_desc;
+   const fdt64_t *prop;
+   int size;
 
hdr = gd->arch.hob_list;
 
@@ -133,6 +136,20 @@ unsigned int install_e820_map(unsigned int max_entries,
num_entries++;
}
 
+   prop = ofnode_read_chosen_prop("e820-entries", &size);
+   if (prop) {
+   int count = size / (sizeof(u64) * 3);
+   int i;
+
+   if (num_entries + count >= max_entries)
+   return -ENOSPC;
+   for (i = 0; i < count; i++, num_entries++, prop += 3) {
+   entries[num_entries].addr = fdt64_to_cpu(prop[0]);
+   entries[num_entries].size = fdt64_to_cpu(prop[1]);
+   entries[num_entries].type = fdt64_to_cpu(prop[2]);
+   }
+   }
+
return num_entries;
 }
 
diff --git a/doc/device-tree-bindings/chosen.txt 
b/doc/device-tree-bindings/chosen.txt
index d4dfc05847b..e5ba6720ce1 100644
--- a/doc/device-tree-bindings/chosen.txt
+++ b/doc/device-tree-bindings/chosen.txt
@@ -143,3 +143,21 @@ This provides the ordering to use when writing device data 
to the ACPI SSDT
 node to add. The ACPI information is written in this order.
 
 If the ordering does not include all nodes, an error is generated.
+
+e820-entries
+
+
+This provides a way to add entries to the e820 table which tells the OS about
+the memory map. The property contains three sets of 64-bit values:
+
+   address   - Start address of region
+   size  - Size of region
+   flags - Flags (E820_...)
+
+Example:
+
+chosen {
+   e820-entries = /bits/ 64 <
+   IOMAP_P2SB_BAR IOMAP P2SB_SIZE E820_RESERVED
+   MCH_BASE_ADDRESS MCH_SIZE  E820_RESERVED>;
+};
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 52/57] x86: fsp: Add more debugging for silicon init

2020-09-06 Thread Simon Glass
If locating the FSP header hangs for whatever reason it is useful to see
where it got stuck. Add a debug print. Also show the address of the FSP-S
entry point as a sanity check.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/lib/fsp2/fsp_silicon_init.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/lib/fsp2/fsp_silicon_init.c 
b/arch/x86/lib/fsp2/fsp_silicon_init.c
index 0f221a864fb..ead3493de82 100644
--- a/arch/x86/lib/fsp2/fsp_silicon_init.c
+++ b/arch/x86/lib/fsp2/fsp_silicon_init.c
@@ -26,8 +26,10 @@ int fsp_silicon_init(bool s3wake, bool use_spi_flash)
struct binman_entry entry;
struct udevice *dev;
ulong rom_offset = 0;
+   u32 init_addr;
int ret;
 
+   log_debug("Locating FSP\n");
ret = fsp_locate_fsp(FSP_S, &entry, use_spi_flash, &dev, &hdr,
 &rom_offset);
if (ret)
@@ -44,7 +46,7 @@ int fsp_silicon_init(bool s3wake, bool use_spi_flash)
ret = fsps_update_config(dev, rom_offset, &upd);
if (ret)
return log_msg_ret("Could not setup config", ret);
-   log_debug("Silicon init...");
+   log_debug("Silicon init @ %x...", init_addr);
bootstage_start(BOOTSTAGE_ID_ACCUM_FSP_S, "fsp-s");
func = (fsp_silicon_init_func)(hdr->img_base + hdr->fsp_silicon_init);
ret = func(&upd);
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 54/57] acpi: Use defines for field lengths

2020-09-06 Thread Simon Glass
A few fields have an open-coded length. Use the defines for this purpose
instead.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/acpi/acpi_table.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
index 9fba6536f50..3a243bf19ce 100644
--- a/include/acpi/acpi_table.h
+++ b/include/acpi/acpi_table.h
@@ -13,6 +13,7 @@
 #ifndef __ACPI_TABLE_H__
 #define __ACPI_TABLE_H__
 
+#include 
 #include 
 
 #define RSDP_SIG   "RSD PTR "  /* RSDP pointer signature */
@@ -48,7 +49,7 @@ struct acpi_rsdp {
 
 /* Generic ACPI header, provided by (almost) all tables */
 struct __packed acpi_table_header {
-   char signature[4];  /* ACPI signature (4 ASCII characters) */
+   char signature[ACPI_NAME_LEN];  /* ACPI signature (4 ASCII chars) */
u32 length; /* Table length in bytes (incl. header) */
u8 revision;/* Table version (not ACPI version!) */
volatile u8 checksum;   /* To make sum of entire table == 0 */
@@ -263,7 +264,7 @@ struct __packed acpi_fadt {
 
 /* FACS (Firmware ACPI Control Structure) */
 struct acpi_facs {
-   char signature[4];  /* "FACS" */
+   char signature[ACPI_NAME_LEN];  /* "FACS" */
u32 length; /* Length in bytes (>= 64) */
u32 hardware_signature; /* Hardware signature */
u32 firmware_waking_vector; /* Firmware waking vector */
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 56/57] x86: Move include of bitops out of ACPI region

2020-09-06 Thread Simon Glass
At present linux/bitops.h is included in ACPI code. This is not needed and
can cause a problem in fls64.h since BITS_PER_LONG is not defined. Move
the #include into the part not used by ACPI.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add new patch to move include of bitops out of ACPI region

 include/acpi/acpi_table.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
index 3a243bf19ce..abbca6530db 100644
--- a/include/acpi/acpi_table.h
+++ b/include/acpi/acpi_table.h
@@ -14,7 +14,6 @@
 #define __ACPI_TABLE_H__
 
 #include 
-#include 
 
 #define RSDP_SIG   "RSD PTR "  /* RSDP pointer signature */
 #define OEM_ID "U-BOOT"/* U-Boot */
@@ -29,6 +28,8 @@
 
 #if !defined(__ACPI__)
 
+#include 
+
 struct acpi_ctx;
 
 /*
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 50/57] x86: coral: Add audio descriptor files

2020-09-06 Thread Simon Glass
Add files describing the various audio configurations supported on coral.
These are passed to Linux in the ACPI tables.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Add new patch with coral audio descriptor files

 .../chromebook_coral/dialog-2ch-48khz-24b.dat| Bin 0 -> 100 bytes
 .../chromebook_coral/dmic-1ch-48khz-16b.dat  | Bin 0 -> 3048 bytes
 .../chromebook_coral/dmic-2ch-48khz-16b.dat  | Bin 0 -> 3048 bytes
 .../chromebook_coral/dmic-4ch-48khz-16b.dat  | Bin 0 -> 3048 bytes
 .../max98357-render-2ch-48khz-24b.dat| Bin 0 -> 116 bytes
 5 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 board/google/chromebook_coral/dialog-2ch-48khz-24b.dat
 create mode 100644 board/google/chromebook_coral/dmic-1ch-48khz-16b.dat
 create mode 100644 board/google/chromebook_coral/dmic-2ch-48khz-16b.dat
 create mode 100644 board/google/chromebook_coral/dmic-4ch-48khz-16b.dat
 create mode 100644 
board/google/chromebook_coral/max98357-render-2ch-48khz-24b.dat

diff --git a/board/google/chromebook_coral/dialog-2ch-48khz-24b.dat 
b/board/google/chromebook_coral/dialog-2ch-48khz-24b.dat
new file mode 100644
index 
..46c0efbd0adc0883564cf8404503fa1de7c4cc33
GIT binary patch
literal 100
zcmZQzU|?WnWOx?=qy_%}|8E4u0zd*AHfO)k$iPr=0H_oQW->7YNf2go01_a;&(5v@
Oq?n-iKR*Kl2m=7w%Nqy)

literal 0
HcmV?d1

diff --git a/board/google/chromebook_coral/dmic-1ch-48khz-16b.dat 
b/board/google/chromebook_coral/dmic-1ch-48khz-16b.dat
new file mode 100644
index 
..6a7f2cef4efea7707f4b2c57f8278962a53ca7c6
GIT binary patch
literal 3048
zcmeH{?Q5207{-tL@yX`Po^x&`v;5##(}YE((R^uH$tuM#U0sSgT?D0{yFuU;8_>nsFU%595k~&|1!xVg3wf4xSI4XZ~IM
zY{u4OjJKW(t!KS{tklW=ulhpU*;^6P0DDUQ2)*1Nn#uTKoNYK0YV8eWFO^=pQd-I0
z4}N0qY^Y_5bg&qWj)y9{Lw%E^wyUN7lcDKfgf?OCmRV9IYAydL)XScJf;e}r)beHM
z_<>LtHcFRDi~kJm&4%vc{(=XH`x@!#_Ru|Vg*Gmfvh@Vbnf|8G{n+blmX?-D->)O4
zH$$VJl0M!jjcp6PSQ~mDKQ23r7WiB~BXsLF{Ogc5(^4Bk^9w>ZRG{tTL``=~SDnmg
zurf6H6Y0@A5+#R1Z$FvQsz*ZaEJxIJi5l+?&TJ00kYFn1loqbYfo;15a!WEU$kY3-SV;wC^4jai)*M(3w`PqrCb?Cnu
z-N%ueZKp#E>F1))64vIi?^({Zz{h*!^?B@OX@mUtGB?0ljy;FTbFjaL)_~n=?l?vm
zi`chi3{v96cKT_IbNDl#GdKMen##Rh+}Dl|6POzhTN(DP&q!axLp@yF#@WTp-;CWU
z_;>nu_@Pywf=TY%%G!ZK7@i25S4b-e`a#bAjDK6O`+864As8zDG4#wYp%1xl8mxSC
zxzt)N9i1+1nkwyrrya1`0Z(Pe(EM{a`!v*ZB(#V7W)b)G-+78{jp#6
z&wkop`)&UnhvRWvj?ZyAUdQeDt%LQjF4o67Sug8m{j8()w650II$Lk+ZvCAH=fin%
zew-)g%XxGDoJZ%=d3AoBXXo2_cmB%(>8dU4&jeq2YcC)bth%XQ{@bKSZA
pT!*+YRF|&Lq3`1RF6@u|2r>V@!&m-&&%f{a_dWl<|KHyCe*hgO-4Xx*

literal 0
HcmV?d1

diff --git a/board/google/chromebook_coral/dmic-2ch-48khz-16b.dat 
b/board/google/chromebook_coral/dmic-2ch-48khz-16b.dat
new file mode 100644
index 
..71d7648202154b6e8116dcf99cb7336f92731ac9
GIT binary patch
literal 3048
zcmeH{?Q7O$6vw~6dv`V;cAq_zX!*jirU{EmqxsOXl2wXfy54A^^}^Or(~PZpv(f~M
zYQ_R>L~rgn5i3N4A)!6_7(J{A3$0a-qODMKwp84@`+R3_g#LoKZ@Bi`bzSE=*E!$w
zIaea7cxomel!jnim<3P$+v<-Zc9O_!`L-}rat{odq?|J?K9
zT*f*sS;b{_Y3b>dG(HzPITWg9ua^1CeBWUH=HH=}%mLwj3%;IYzWID;E&C0lq%Q2g>JM$jwlbtaY|8!!y*3b<#{98jsqt*6tuK_lQhN1T
zX*sqZ|HRt4Q0qkLKq)$$2vzlj`o~M{*GmJZLQ}p7ZNT3h)1@lZT6!?lhs^*7Px^oNhbxIoaIO_TKBTTM;Wx_|;{QI@2HDGDbA&nv_O*;g{MK;C
zanhKN-KLR9Nf2B4PG+7Xo;jSk?XS=z?(OEj4q_-_Z47K>uv?pvzJ`YexVVe63s}D$
zzY~e?%jHsSZJ-q52kRQhA+`Cmf&xozbRv{gmB5jx??SQ9ku-XYv<;T(db2$4n)O$3vi~FXN_s!IB=PYb$(F2_iakdRs
z=i~poy`h=gLNj1uXJ=^D4{%*39i1yJX@uPurIXFf;qO;+`V7|gEJOc_(Bjh2Z!<$>
zoZWagI*(1X_hO>e$5NVx_^*#iYejW>`0KgXy>C0)`<&0)kNw%N{reu@=X-s><8VBV
z%keo*$LqKqzw>ZD&dd2ZPv`5roxgRk9@fSBSSRac-K?K=w4T=0`dVk}ZQZTE>)?90
zF0PO3Rnp5*?Zq2VbHqYkTe4BIgZtl&$`@sF+zHooIPuwr=8~2a<$o=HLa(}tc+;8qX
n_n-Ta5Qh8G{YeP<_ub5)SN?s^zwi0?Jw5#1=im4L$NT;ddMe!=

literal 0
HcmV?d1

diff --git a/board/google/chromebook_coral/dmic-4ch-48khz-16b.dat 
b/board/google/chromebook_coral/dmic-4ch-48khz-16b.dat
new file mode 100644
index 
..142ab353f3736f110f30e9befbd72f7e8ae4264b
GIT binary patch
literal 3048
zcmeH{?Q7O$6vw~6dv`V;cAq_zX!*jirU{F1M)RR%C94#}biJ`c>xHeMrWsrHW~B)h
z)rSg%;;f7Sg5UX6m5l?v!&wJ-RC=dBlH)mel!P0(0>3P$482}`6!e}?vEL-%lh;X~wogY;}?=)Si@8x}~}Mv~^tU`yyh{B^fVOUkA1
z*OJp)p;6CBpKOrEbc9~64}Cx!R~<$RVy>tT-M*Fhx};5v)cVl8!q82XXgeuU%e~Td
zr!pF@3QhV{di<_L$)V6YPiM69vCzBA5Or;$<_AJgo-5Lui$kNk6V>0GQVn_Tsx8vK
z6-7FYpPJSJ?d?sgvm~vKr77J#AZ6xCvkE0b0Ucswe20z=j4U;5rbay%L%q~z7rHi}
z|0;AJOKrBE2`%6|2YnW^Hy69-IoAds?^D+o@tb7~^M5~UL+s_SIZT}c`#MGwervho
z7-=lTZu4lQB#0e+r!vnG&pgiD@>ggI_x5mKCoz<;HV(Ej*saS*-@rp7T-?FgMXcY7
z-^s*x=6CpE)SiY(?%TrNfg%_l51ZFW%SrlS&i+h%oALWbU+57SD*Z9^+%KVzxNj<~
ze0#OjULhTwCT*M|y$(-1VYLgM%8#M>7jX7jsP9N<5BJR^@9ETV_Z)2M&;y+hakd>+
z7vlf;{?P25p;<7oyDPN%2e>Yij?9C0)`<&0)kNw%N{reu@=X-s><8VBV
z%keo*$LqKqzw>ZD&dd2ZPv`5roxgRk9@fSBSSRac-K?K=w4T=0`dVk}ZQZTE>)?90
zF0PO3Rnp5*?Zq2VbHqYkTe4BIgZtl&$`@sF+zHooIPuwr=8~2a<$o=HLa(}tc+;8qX
n_n-Ta5Jvja{YeP<_ub5)SN?s^zwi0?Jw5W?=im4L$NT;dsY=};

literal 0
HcmV?d1

diff --git a/board/google/chromebook_coral/max98357-render-2ch-4

[PATCH v3 53/57] x86: fsp: Show FSP-S or FSP-M address in fsp_get_header()

2020-09-06 Thread Simon Glass
At present this function only supports FSP-M but it is also used to read
FSP-S, in which case FSP-M may be zero. Add support for showing whichever
address is present in the FSP binary.

Also change the debug() statements to log_debug() while here.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/lib/fsp2/fsp_support.c | 22 ++
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/arch/x86/lib/fsp2/fsp_support.c b/arch/x86/lib/fsp2/fsp_support.c
index 3f2ca840dc9..f220ef498b0 100644
--- a/arch/x86/lib/fsp2/fsp_support.c
+++ b/arch/x86/lib/fsp2/fsp_support.c
@@ -35,7 +35,8 @@ int fsp_get_header(ulong offset, ulong size, bool 
use_spi_flash,
 *
 * You are in a maze of twisty little headers all alike.
 */
-   debug("offset=%x buf=%x\n", (uint)offset, (uint)buf);
+   log_debug("offset=%x buf=%x, use_spi_flash=%d\n", (uint)offset,
+ (uint)buf, use_spi_flash);
if (use_spi_flash) {
ret = uclass_first_device_err(UCLASS_SPI_FLASH, &dev);
if (ret)
@@ -52,16 +53,16 @@ int fsp_get_header(ulong offset, ulong size, bool 
use_spi_flash,
fv = ptr;
 
/* Check the FV signature, _FVH */
-   debug("offset=%x sign=%x\n", (uint)offset, (uint)fv->sign);
+   log_debug("offset=%x sign=%x\n", (uint)offset, (uint)fv->sign);
if (fv->sign != EFI_FVH_SIGNATURE)
return log_msg_ret("Base FV signature", -EINVAL);
 
/* Go to the end of the FV header and align the address */
-   debug("fv->ext_hdr_off = %x\n", fv->ext_hdr_off);
+   log_debug("fv->ext_hdr_off = %x\n", fv->ext_hdr_off);
ptr += fv->ext_hdr_off;
exhdr = ptr;
ptr += ALIGN(exhdr->ext_hdr_size, 8);
-   debug("ptr=%x\n", ptr - (void *)buf);
+   log_debug("ptr=%x\n", ptr - (void *)buf);
 
/* Check the FFS GUID */
file_hdr = ptr;
@@ -71,7 +72,7 @@ int fsp_get_header(ulong offset, ulong size, bool 
use_spi_flash,
ptr = file_hdr + 1;
 
raw = ptr;
-   debug("raw->type = %x\n", raw->type);
+   log_debug("raw->type = %x\n", raw->type);
if (raw->type != EFI_SECTION_RAW)
return log_msg_ret("Section type not RAW", -ENOEXEC);
 
@@ -80,13 +81,18 @@ int fsp_get_header(ulong offset, ulong size, bool 
use_spi_flash,
fsp = ptr;
 
/* Check the FSPH header */
-   debug("fsp %x\n", (uint)fsp);
+   log_debug("fsp %x, fsp-buf=%x, si=%x\n", (uint)fsp, ptr - (void *)buf,
+ (void *)&fsp->fsp_silicon_init - (void *)buf);
if (fsp->sign != EFI_FSPH_SIGNATURE)
return log_msg_ret("Base FSPH signature", -EACCES);
 
base = (void *)fsp->img_base;
-   debug("Image base %x\n", (uint)base);
-   debug("Image addr %x\n", (uint)fsp->fsp_mem_init);
+   log_debug("image base %x\n", (uint)base);
+   if (fsp->fsp_mem_init)
+   log_debug("mem_init offset %x\n", (uint)fsp->fsp_mem_init);
+   else if (fsp->fsp_silicon_init)
+   log_debug("silicon_init offset %x\n",
+ (uint)fsp->fsp_silicon_init);
if (use_spi_flash) {
ret = spi_flash_read_dm(dev, offset, size, base);
if (ret)
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 48/57] acpi: tpm: Add a TPM1 table

2020-09-06 Thread Simon Glass
This provides information about a v1 TPM in the system. Generate this
table if the TPM is present.

Add a required new bloblist type and correct the header order of one
header file.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/lib/acpi_table.c | 54 ++-
 include/acpi/acpi_table.h |  7 +
 include/bloblist.h|  1 +
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 9b13880f996..a3db94b8318 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -215,6 +215,47 @@ static void acpi_create_mcfg(struct acpi_mcfg *mcfg)
header->checksum = table_compute_checksum((void *)mcfg, header->length);
 }
 
+/**
+ * acpi_create_tcpa() - Create a TCPA table
+ *
+ * @tcpa: Pointer to place to put table
+ *
+ * Trusted Computing Platform Alliance Capabilities Table
+ * TCPA PC Specific Implementation SpecificationTCPA is defined in the PCI
+ * Firmware Specification 3.0
+ */
+static int acpi_create_tcpa(struct acpi_tcpa *tcpa)
+{
+   struct acpi_table_header *header = &tcpa->header;
+   u32 current = (u32)tcpa + sizeof(struct acpi_tcpa);
+   int size = 0x1; /* Use this as the default size */
+   void *log;
+   int ret;
+
+   if (!CONFIG_IS_ENABLED(BLOBLIST))
+   return -ENXIO;
+   memset(tcpa, '\0', sizeof(struct acpi_tcpa));
+
+   /* Fill out header fields */
+   acpi_fill_header(header, "TCPA");
+   header->length = sizeof(struct acpi_tcpa);
+   header->revision = 1;
+
+   ret = bloblist_ensure_size_ret(BLOBLISTT_TCPA_LOG, &size, &log);
+   if (ret)
+   return log_msg_ret("blob", ret);
+
+   tcpa->platform_class = 0;
+   tcpa->laml = size;
+   tcpa->lasa = (ulong)log;
+
+   /* (Re)calculate length and checksum */
+   header->length = current - (u32)tcpa;
+   header->checksum = table_compute_checksum((void *)tcpa, header->length);
+
+   return 0;
+}
+
 static int get_tpm2_log(void **ptrp, int *sizep)
 {
const int tpm2_default_log_len = 0x1;
@@ -455,11 +496,13 @@ ulong write_acpi_tables(ulong start_addr)
struct acpi_fadt *fadt;
struct acpi_table_header *ssdt;
struct acpi_mcfg *mcfg;
+   struct acpi_tcpa *tcpa;
struct acpi_madt *madt;
struct acpi_csrt *csrt;
struct acpi_spcr *spcr;
void *start;
ulong addr;
+   int ret;
int i;
 
start = map_sysmem(start_addr, 0);
@@ -547,7 +590,6 @@ ulong write_acpi_tables(ulong start_addr)
 
if (IS_ENABLED(CONFIG_TPM_V2)) {
struct acpi_tpm2 *tpm2;
-   int ret;
 
debug("ACPI:* TPM2\n");
tpm2 = (struct acpi_tpm2 *)ctx->current;
@@ -566,6 +608,16 @@ ulong write_acpi_tables(ulong start_addr)
acpi_inc_align(ctx, madt->header.length);
acpi_add_table(ctx, madt);
 
+   debug("ACPI:* TCPA\n");
+   tcpa = (struct acpi_tcpa *)ctx->current;
+   ret = acpi_create_tcpa(tcpa);
+   if (ret) {
+   log_warning("Failed to create TCPA table (err=%d)\n", ret);
+   } else {
+   acpi_inc_align(ctx, tcpa->header.length);
+   acpi_add_table(ctx, tcpa);
+   }
+
debug("ACPI:* CSRT\n");
csrt = ctx->current;
if (!acpi_create_csrt(csrt)) {
diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
index c7ee8b55da4..9fba6536f50 100644
--- a/include/acpi/acpi_table.h
+++ b/include/acpi/acpi_table.h
@@ -104,6 +104,13 @@ struct __packed acpi_tpm2 {
u64 lasa;
 };
 
+struct __packed acpi_tcpa {
+   struct acpi_table_header header;
+   u16 platform_class;
+   u32 laml;
+   u64 lasa;
+};
+
 /* FADT Preferred Power Management Profile */
 enum acpi_pm_profile {
ACPI_PM_UNSPECIFIED = 0,
diff --git a/include/bloblist.h b/include/bloblist.h
index dc7d80bd851..5784c2226e7 100644
--- a/include/bloblist.h
+++ b/include/bloblist.h
@@ -34,6 +34,7 @@ enum bloblist_tag_t {
BLOBLISTT_ACPI_GNVS,
BLOBLISTT_INTEL_VBT,/* Intel Video-BIOS table */
BLOBLISTT_TPM2_TCG_LOG, /* TPM v2 log space */
+   BLOBLISTT_TCPA_LOG, /* TPM log space */
 };
 
 /**
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 49/57] x86: acpi: Set the log category for x86 table generation

2020-09-06 Thread Simon Glass
This file doesn't currently have a log category. Add one so that items
are logged correctly.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/lib/acpi_table.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index a3db94b8318..faab9d9de3c 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -6,6 +6,8 @@
  * Copyright (C) 2016, Bin Meng 
  */
 
+#define LOG_CATEGORY LOGC_ACPI
+
 #include 
 #include 
 #include 
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 47/57] acpi: tpm: Add a TPM2 table

2020-09-06 Thread Simon Glass
This provides information about a v2 TPM in the system. Generate this
table if the TPM is present.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/lib/acpi_table.c | 74 +++
 include/acpi/acpi_table.h | 11 ++
 include/bloblist.h|  1 +
 3 files changed, 86 insertions(+)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 667059b5ace..9b13880f996 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -214,6 +215,64 @@ static void acpi_create_mcfg(struct acpi_mcfg *mcfg)
header->checksum = table_compute_checksum((void *)mcfg, header->length);
 }
 
+static int get_tpm2_log(void **ptrp, int *sizep)
+{
+   const int tpm2_default_log_len = 0x1;
+   int size;
+   int ret;
+
+   *sizep = 0;
+   size = tpm2_default_log_len;
+   ret = bloblist_ensure_size_ret(BLOBLISTT_TPM2_TCG_LOG, &size, ptrp);
+   if (ret)
+   return log_msg_ret("blob", ret);
+   *sizep = size;
+
+   return 0;
+}
+
+static int acpi_create_tpm2(struct acpi_tpm2 *tpm2)
+{
+   struct acpi_table_header *header = &tpm2->header;
+   int tpm2_log_len;
+   void *lasa;
+   int ret;
+
+   memset((void *)tpm2, 0, sizeof(struct acpi_tpm2));
+
+   /*
+* Some payloads like SeaBIOS depend on log area to use TPM2.
+* Get the memory size and address of TPM2 log area or initialize it.
+*/
+   ret = get_tpm2_log(&lasa, &tpm2_log_len);
+   if (ret)
+   return ret;
+
+   /* Fill out header fields. */
+   acpi_fill_header(header, "TPM2");
+   memcpy(header->aslc_id, ASLC_ID, 4);
+
+   header->length = sizeof(struct acpi_tpm2);
+   header->revision = acpi_get_table_revision(ACPITAB_TPM2);
+
+   /* Hard to detect for coreboot. Just set it to 0 */
+   tpm2->platform_class = 0;
+
+   /* Must be set to 0 for FIFO-interface support */
+   tpm2->control_area = 0;
+   tpm2->start_method = 6;
+   memset(tpm2->msp, 0, sizeof(tpm2->msp));
+
+   /* Fill the log area size and start address fields. */
+   tpm2->laml = tpm2_log_len;
+   tpm2->lasa = (uintptr_t)lasa;
+
+   /* Calculate checksum. */
+   header->checksum = table_compute_checksum((void *)tpm2, header->length);
+
+   return 0;
+}
+
 __weak u32 acpi_fill_csrt(u32 current)
 {
return 0;
@@ -486,6 +545,21 @@ ulong write_acpi_tables(ulong start_addr)
acpi_inc_align(ctx, mcfg->header.length);
acpi_add_table(ctx, mcfg);
 
+   if (IS_ENABLED(CONFIG_TPM_V2)) {
+   struct acpi_tpm2 *tpm2;
+   int ret;
+
+   debug("ACPI:* TPM2\n");
+   tpm2 = (struct acpi_tpm2 *)ctx->current;
+   ret = acpi_create_tpm2(tpm2);
+   if (!ret) {
+   acpi_inc_align(ctx, tpm2->header.length);
+   acpi_add_table(ctx, tpm2);
+   } else {
+   log_warning("TPM2 table creation failed\n");
+   }
+   }
+
debug("ACPI:* MADT\n");
madt = ctx->current;
acpi_create_madt(madt);
diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
index a2e510cf56e..c7ee8b55da4 100644
--- a/include/acpi/acpi_table.h
+++ b/include/acpi/acpi_table.h
@@ -93,6 +93,17 @@ struct __packed acpi_hpet {
u8 attributes;
 };
 
+struct __packed acpi_tpm2 {
+   struct acpi_table_header header;
+   u16 platform_class;
+   u8  reserved[2];
+   u64 control_area;
+   u32 start_method;
+   u8  msp[12];
+   u32 laml;
+   u64 lasa;
+};
+
 /* FADT Preferred Power Management Profile */
 enum acpi_pm_profile {
ACPI_PM_UNSPECIFIED = 0,
diff --git a/include/bloblist.h b/include/bloblist.h
index 7d8480548e0..dc7d80bd851 100644
--- a/include/bloblist.h
+++ b/include/bloblist.h
@@ -33,6 +33,7 @@ enum bloblist_tag_t {
 */
BLOBLISTT_ACPI_GNVS,
BLOBLISTT_INTEL_VBT,/* Intel Video-BIOS table */
+   BLOBLISTT_TPM2_TCG_LOG, /* TPM v2 log space */
 };
 
 /**
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 46/57] x86: Correct handling of MADT table CPUs

2020-09-06 Thread Simon Glass
At present if hyperthreading is disabled the CPU numbering is not
sequential. Fix this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/lib/acpi_table.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index b0cc1f123e2..667059b5ace 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -66,14 +66,17 @@ int acpi_create_madt_lapics(u32 current)
 {
struct udevice *dev;
int total_length = 0;
+   int cpu_num = 0;
 
for (uclass_find_first_device(UCLASS_CPU, &dev);
 dev;
 uclass_find_next_device(&dev)) {
struct cpu_platdata *plat = dev_get_parent_platdata(dev);
-   int length = acpi_create_madt_lapic(
-   (struct acpi_madt_lapic *)current,
-   plat->cpu_id, plat->cpu_id);
+   int length;
+
+   length = acpi_create_madt_lapic(
+   (struct acpi_madt_lapic *)current, cpu_num++,
+   plat->cpu_id);
current += length;
total_length += length;
}
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 51/57] x86: apl: Check low-level init in FSP-S pre-init

2020-09-06 Thread Simon Glass
If U-Boot is not running FSP-S it should not do the pre-init either. Add a
condition to handle this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/cpu/apollolake/fsp_s.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/cpu/apollolake/fsp_s.c b/arch/x86/cpu/apollolake/fsp_s.c
index e54b0ac1047..715ceab6ac7 100644
--- a/arch/x86/cpu/apollolake/fsp_s.c
+++ b/arch/x86/cpu/apollolake/fsp_s.c
@@ -157,6 +157,8 @@ int arch_fsps_preinit(void)
struct udevice *itss;
int ret;
 
+   if (!ll_boot_init())
+   return 0;
ret = irq_first_device_type(X86_IRQT_ITSS, &itss);
if (ret)
return log_msg_ret("no itss", ret);
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 45/57] x86: Add a header guard to asm/acpi_table.h

2020-09-06 Thread Simon Glass
This file cannot currently be included in ASL files. Add a header guard
to permit this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/include/asm/acpi_table.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/include/asm/acpi_table.h 
b/arch/x86/include/asm/acpi_table.h
index faf31730730..1b49ccadc0c 100644
--- a/arch/x86/include/asm/acpi_table.h
+++ b/arch/x86/include/asm/acpi_table.h
@@ -9,6 +9,8 @@
 #ifndef __ASM_ACPI_TABLE_H__
 #define __ASM_ACPI_TABLE_H__
 
+#ifndef __ACPI__
+
 struct acpi_facs;
 struct acpi_fadt;
 struct acpi_global_nvs;
@@ -213,4 +215,6 @@ void acpi_fadt_common(struct acpi_fadt *fadt, struct 
acpi_facs *facs,
  */
 void intel_acpi_fill_fadt(struct acpi_fadt *fadt);
 
+#endif /* !__ACPI__ */
+
 #endif /* __ASM_ACPI_TABLE_H__ */
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 44/57] x86: Correct the assembly guard in e820.h

2020-09-06 Thread Simon Glass
This is currently in the wrong place, so including the file in the device
tree fails. Fix it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Update commit message with a comma

 arch/x86/include/asm/e820.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
index 9d29f82f972..87af0f492ec 100644
--- a/arch/x86/include/asm/e820.h
+++ b/arch/x86/include/asm/e820.h
@@ -21,10 +21,9 @@ struct e820_entry {
 #define ISA_START_ADDRESS  0xa
 #define ISA_END_ADDRESS0x10
 
-#endif /* __ASSEMBLY__ */
-
 /* Implementation defined function to install an e820 map */
 unsigned int install_e820_map(unsigned int max_entries,
  struct e820_entry *);
+#endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_X86_E820_H */
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 43/57] x86: Notify the FSP of the 'end firmware' event

2020-09-06 Thread Simon Glass
Send this notification when U-Boot is about to boot into Linux, as
requested by the FSP.

Currently this causes a crash with the APL FSP, so leave it disabled for
now.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/cpu/cpu.c| 15 +++
 arch/x86/lib/fsp/fsp_common.c | 16 
 2 files changed, 31 insertions(+)

diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
index 69c14189d1f..f8692753963 100644
--- a/arch/x86/cpu/cpu.c
+++ b/arch/x86/cpu/cpu.c
@@ -189,6 +189,14 @@ __weak void board_final_init(void)
 {
 }
 
+/*
+ * Implement a weak default function for boards that need to do some final
+ * processing before booting the OS.
+ */
+__weak void board_final_cleanup(void)
+{
+}
+
 int last_stage_init(void)
 {
struct acpi_fadt __maybe_unused *fadt;
@@ -218,6 +226,13 @@ int last_stage_init(void)
}
}
 
+   /*
+* TODO(s...@chromium.org): Move this to bootm_announce_and_cleanup()
+* once APL FSP-S at 0x20 does not overlap with the bzimage at
+* 0x10.
+*/
+   board_final_cleanup();
+
return 0;
 }
 #endif
diff --git a/arch/x86/lib/fsp/fsp_common.c b/arch/x86/lib/fsp/fsp_common.c
index ea529547254..4061fa244c4 100644
--- a/arch/x86/lib/fsp/fsp_common.c
+++ b/arch/x86/lib/fsp/fsp_common.c
@@ -60,6 +60,22 @@ void board_final_init(void)
debug("OK\n");
 }
 
+void board_final_cleanup(void)
+{
+   u32 status;
+
+   /* TODO(s...@chromium.org): This causes Linux to crash */
+   return;
+
+   /* call into FspNotify */
+   debug("Calling into FSP (notify phase INIT_PHASE_END_FIRMWARE): ");
+   status = fsp_notify(NULL, INIT_PHASE_END_FIRMWARE);
+   if (status)
+   debug("fail, error code %x\n", status);
+   else
+   debug("OK\n");
+}
+
 int fsp_save_s3_stack(void)
 {
struct udevice *dev;
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 42/57] x86: Sort the MTRR table

2020-09-06 Thread Simon Glass
At present the MTRR registers are programmed with the list the U-Boot
builds up in the same order. In some cases this list may be out of order.
It looks better in Linux to have the registers in order, so sort them,

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/cpu/mtrr.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/x86/cpu/mtrr.c b/arch/x86/cpu/mtrr.c
index 2468d88a80a..08fa80f8bc7 100644
--- a/arch/x86/cpu/mtrr.c
+++ b/arch/x86/cpu/mtrr.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -124,6 +125,16 @@ static int mtrr_copy_to_aps(void)
return 0;
 }
 
+static int h_comp_mtrr(const void *p1, const void *p2)
+{
+   const struct mtrr_request *req1 = p1;
+   const struct mtrr_request *req2 = p2;
+
+   s64 diff = req1->start - req2->start;
+
+   return diff < 0 ? -1 : diff > 0 ? 1 : 0;
+}
+
 int mtrr_commit(bool do_caches)
 {
struct mtrr_request *req = gd->arch.mtrr_req;
@@ -139,6 +150,7 @@ int mtrr_commit(bool do_caches)
debug("open\n");
mtrr_open(&state, do_caches);
debug("open done\n");
+   qsort(req, gd->arch.mtrr_req_count, sizeof(*req), h_comp_mtrr);
for (i = 0; i < gd->arch.mtrr_req_count; i++, req++)
set_var_mtrr(i, req->type, req->start, req->size);
 
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 38/57] x86: apl: Drop unnecessary code in PMC driver

2020-09-06 Thread Simon Glass
We don't have CONFIG_PCI in TPL but it is present in SPL, etc. So this
code is not needed. Drop it, and fix a code-style nit just above.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/cpu/apollolake/pmc.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/x86/cpu/apollolake/pmc.c b/arch/x86/cpu/apollolake/pmc.c
index 192dec7109a..576d0187570 100644
--- a/arch/x86/cpu/apollolake/pmc.c
+++ b/arch/x86/cpu/apollolake/pmc.c
@@ -118,7 +118,8 @@ int apl_pmc_ofdata_to_uc_platdata(struct udevice *dev)
int size;
int ret;
 
-   ret = dev_read_u32_array(dev, "early-regs", base, ARRAY_SIZE(base));
+   ret = dev_read_u32_array(dev, "early-regs", base,
+ARRAY_SIZE(base));
if (ret)
return log_msg_ret("Missing/short early-regs", ret);
if (spl_phase() == PHASE_TPL) {
@@ -133,11 +134,6 @@ int apl_pmc_ofdata_to_uc_platdata(struct udevice *dev)
}
upriv->acpi_base = base[4];
 
-   /* Since PCI is not enabled, we must get the BDF manually */
-   plat->bdf = pci_get_devfn(dev);
-   if (plat->bdf < 0)
-   return log_msg_ret("Cannot get PMC PCI address", plat->bdf);
-
/* Get the dwX values for pmc gpe settings */
size = dev_read_size(dev, "gpe0-dw");
if (size < 0)
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 41/57] x86: cpu: Report address width from cpu_get_info()

2020-09-06 Thread Simon Glass
Add support for this new field in the common code used by most x86 CPU
drivers.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/cpu/i386/cpu.c | 23 +++
 arch/x86/cpu/intel_common/cpu.c |  1 +
 arch/x86/cpu/x86_64/cpu.c   |  5 +
 arch/x86/include/asm/cpu.h  |  9 +
 4 files changed, 38 insertions(+)

diff --git a/arch/x86/cpu/i386/cpu.c b/arch/x86/cpu/i386/cpu.c
index 8f342dd06e2..7517b756f43 100644
--- a/arch/x86/cpu/i386/cpu.c
+++ b/arch/x86/cpu/i386/cpu.c
@@ -34,6 +34,10 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#define CPUID_FEATURE_PAE  BIT(6)
+#define CPUID_FEATURE_PSE36BIT(17)
+#define CPUID_FEAURE_HTT   BIT(28)
+
 /*
  * Constructor for a conventional segment GDT (or LDT) entry
  * This is a macro so it can be used in initialisers
@@ -388,6 +392,25 @@ static void setup_identity(void)
}
 }
 
+static uint cpu_cpuid_extended_level(void)
+{
+   return cpuid_eax(0x8000);
+}
+
+int cpu_phys_address_size(void)
+{
+   if (!has_cpuid())
+   return 32;
+
+   if (cpu_cpuid_extended_level() >= 0x8008)
+   return cpuid_eax(0x8008) & 0xff;
+
+   if (cpuid_edx(1) & (CPUID_FEATURE_PAE | CPUID_FEATURE_PSE36))
+   return 36;
+
+   return 32;
+}
+
 /* Don't allow PCI region 3 to use memory in the 2-4GB memory hole */
 static void setup_pci_ram_top(void)
 {
diff --git a/arch/x86/cpu/intel_common/cpu.c b/arch/x86/cpu/intel_common/cpu.c
index d8a3d60ae72..39aa0f63c65 100644
--- a/arch/x86/cpu/intel_common/cpu.c
+++ b/arch/x86/cpu/intel_common/cpu.c
@@ -127,6 +127,7 @@ int cpu_intel_get_info(struct cpu_info *info, int bclk)
info->cpu_freq = ((msr.lo >> 8) & 0xff) * bclk * 100;
info->features = 1 << CPU_FEAT_L1_CACHE | 1 << CPU_FEAT_MMU |
1 << CPU_FEAT_UCODE | 1 << CPU_FEAT_DEVICE_ID;
+   info->address_width = cpu_phys_address_size();
 
return 0;
 }
diff --git a/arch/x86/cpu/x86_64/cpu.c b/arch/x86/cpu/x86_64/cpu.c
index 1b4d3971b04..90a766c3c57 100644
--- a/arch/x86/cpu/x86_64/cpu.c
+++ b/arch/x86/cpu/x86_64/cpu.c
@@ -70,3 +70,8 @@ int x86_cpu_reinit_f(void)
 {
return 0;
 }
+
+int cpu_phys_address_size(void)
+{
+   return CONFIG_CPU_ADDR_BITS;
+}
diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
index 21a05dab7de..5b001bbee21 100644
--- a/arch/x86/include/asm/cpu.h
+++ b/arch/x86/include/asm/cpu.h
@@ -288,4 +288,13 @@ u32 cpu_get_family_model(void);
  */
 u32 cpu_get_stepping(void);
 
+/**
+ * cpu_phys_address_size() - Get the physical address size in bits
+ *
+ * This is 32 for older CPUs but newer ones may support 36.
+ *
+ * @return address size (typically 32 or 36)
+ */
+int cpu_phys_address_size(void);
+
 #endif
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 39/57] tpm: cr50: Add ACPI support

2020-09-06 Thread Simon Glass
Generate ACPI information for this device so that Linux can use it
correctly.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Capitalise ACPI_OPS_PTR
- Update for acpi_device_write_i2c_dev() return-value change
- Use acpi,ddn instead of acpi,desc

 drivers/tpm/cr50_i2c.c | 55 ++
 1 file changed, 55 insertions(+)

diff --git a/drivers/tpm/cr50_i2c.c b/drivers/tpm/cr50_i2c.c
index 1942c07c605..64831a42232 100644
--- a/drivers/tpm/cr50_i2c.c
+++ b/drivers/tpm/cr50_i2c.c
@@ -14,11 +14,14 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 enum {
TIMEOUT_INIT_MS = 3, /* Very long timeout for TPM init */
@@ -581,6 +584,53 @@ static int cr50_i2c_cleanup(struct udevice *dev)
return 0;
 }
 
+static int cr50_acpi_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx)
+{
+   char scope[ACPI_PATH_MAX];
+   char name[ACPI_NAME_MAX];
+   const char *hid;
+   int ret;
+
+   ret = acpi_device_scope(dev, scope, sizeof(scope));
+   if (ret)
+   return log_msg_ret("scope", ret);
+   ret = acpi_get_name(dev, name);
+   if (ret)
+   return log_msg_ret("name", ret);
+
+   hid = dev_read_string(dev, "acpi,hid");
+   if (!hid)
+   return log_msg_ret("hid", ret);
+
+   /* Device */
+   acpigen_write_scope(ctx, scope);
+   acpigen_write_device(ctx, name);
+   acpigen_write_name_string(ctx, "_HID", hid);
+   acpigen_write_name_integer(ctx, "_UID",
+  dev_read_u32_default(dev, "acpi,uid", 0));
+   acpigen_write_name_string(ctx, "_DDN",
+ dev_read_string(dev, "acpi,ddn"));
+   acpigen_write_sta(ctx, acpi_device_status(dev));
+
+   /* Resources */
+   acpigen_write_name(ctx, "_CRS");
+   acpigen_write_resourcetemplate_header(ctx);
+   ret = acpi_device_write_i2c_dev(ctx, dev);
+   if (ret < 0)
+   return log_msg_ret("i2c", ret);
+   ret = acpi_device_write_interrupt_or_gpio(ctx, (struct udevice *)dev,
+ "ready-gpios");
+   if (ret < 0)
+   return log_msg_ret("irq_gpio", ret);
+
+   acpigen_write_resourcetemplate_footer(ctx);
+
+   acpigen_pop_len(ctx); /* Device */
+   acpigen_pop_len(ctx); /* Scope */
+
+   return 0;
+}
+
 enum {
TPM_TIMEOUT_MS  = 5,
SHORT_TIMEOUT_MS= 750,
@@ -653,6 +703,10 @@ static int cr50_i2c_probe(struct udevice *dev)
return 0;
 }
 
+struct acpi_ops cr50_acpi_ops = {
+   .fill_ssdt  = cr50_acpi_fill_ssdt,
+};
+
 static const struct tpm_ops cr50_i2c_ops = {
.open   = cr50_i2c_open,
.get_desc   = cr50_i2c_get_desc,
@@ -675,5 +729,6 @@ U_BOOT_DRIVER(cr50_i2c) = {
.probe  = cr50_i2c_probe,
.remove = cr50_i2c_cleanup,
.priv_auto_alloc_size = sizeof(struct cr50_priv),
+   ACPI_OPS_PTR(&cr50_acpi_ops)
.flags  = DM_FLAG_OS_PREPARE,
 };
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 36/57] x86: apl: Generate CPU tables

2020-09-06 Thread Simon Glass
Add ACPI generation to the APL CPU driver.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Capitalise ACPI_OPS_PTR
- Handle table generation without callbacks

 arch/x86/cpu/apollolake/cpu.c  | 77 ++
 arch/x86/lib/Makefile  |  3 +-
 configs/chromebook_coral_defconfig |  1 +
 3 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/arch/x86/cpu/apollolake/cpu.c b/arch/x86/cpu/apollolake/cpu.c
index 0a6d2ad7a4a..8da2e64e226 100644
--- a/arch/x86/cpu/apollolake/cpu.c
+++ b/arch/x86/cpu/apollolake/cpu.c
@@ -6,14 +6,90 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
+#include 
+#include 
+#include 
+
+#define CSTATE_RES(address_space, width, offset, address)  \
+   {   \
+   .space_id = address_space,  \
+   .bit_width = width, \
+   .bit_offset = offset,   \
+   .addrl = address,   \
+   }
+
+static struct acpi_cstate cstate_map[] = {
+   {
+   /* C1 */
+   .ctype = 1, /* ACPI C1 */
+   .latency = 1,
+   .power = 1000,
+   .resource = {
+   .space_id = ACPI_ADDRESS_SPACE_FIXED,
+   },
+   }, {
+   .ctype = 2, /* ACPI C2 */
+   .latency = 50,
+   .power = 10,
+   .resource = {
+   .space_id = ACPI_ADDRESS_SPACE_IO,
+   .bit_width = 8,
+   .addrl = 0x415,
+   },
+   }, {
+   .ctype = 3, /* ACPI C3 */
+   .latency = 150,
+   .power = 10,
+   .resource = {
+   .space_id = ACPI_ADDRESS_SPACE_IO,
+   .bit_width = 8,
+   .addrl = 0x419,
+   },
+   },
+};
 
 static int apl_get_info(const struct udevice *dev, struct cpu_info *info)
 {
return cpu_intel_get_info(info, INTEL_BCLK_MHZ);
 }
 
+static int acpi_cpu_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx)
+{
+   uint core_id = dev->req_seq;
+   int cores_per_package;
+   int ret;
+
+   cores_per_package = cpu_get_cores_per_package();
+   ret = acpi_generate_cpu_header(ctx, core_id, cstate_map,
+  ARRAY_SIZE(cstate_map));
+
+   /* Generate P-state tables */
+   generate_p_state_entries(ctx, core_id, cores_per_package);
+
+   /* Generate T-state tables */
+   generate_t_state_entries(ctx, core_id, cores_per_package, NULL, 0);
+
+   acpigen_pop_len(ctx);
+
+   if (device_is_last_sibling(dev)) {
+   ret = acpi_generate_cpu_package_final(ctx, cores_per_package);
+
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
+struct acpi_ops apl_cpu_acpi_ops = {
+   .fill_ssdt  = acpi_cpu_fill_ssdt,
+};
+
 static const struct cpu_ops cpu_x86_apl_ops = {
.get_desc   = cpu_x86_get_desc,
.get_info   = apl_get_info,
@@ -32,5 +108,6 @@ U_BOOT_DRIVER(cpu_x86_apl_drv) = {
.of_match   = cpu_x86_apl_ids,
.bind   = cpu_x86_bind,
.ops= &cpu_x86_apl_ops,
+   ACPI_OPS_PTR(&apl_cpu_acpi_ops)
.flags  = DM_FLAG_PRE_RELOC,
 };
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index f04d275dd9a..1bcbb49a61f 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -38,7 +38,8 @@ obj-y += sfi.o
 obj-y  += acpi.o
 obj-$(CONFIG_HAVE_ACPI_RESUME) += acpi_s3.o
 ifndef CONFIG_QEMU
-obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o acpigen.o
+obj-y += acpigen.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
 endif
 obj-y  += tables.o
 ifndef CONFIG_SPL_BUILD
diff --git a/configs/chromebook_coral_defconfig 
b/configs/chromebook_coral_defconfig
index c9006e2f934..ef4dabbe26e 100644
--- a/configs/chromebook_coral_defconfig
+++ b/configs/chromebook_coral_defconfig
@@ -72,6 +72,7 @@ CONFIG_ENV_OVERWRITE=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
 CONFIG_SPL_OF_TRANSLATE=y
+CONFIG_INTEL_ACPIGEN=y
 CONFIG_CPU=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_DW=y
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 40/57] x86: fsp: Update the FSP API with the end-firmware method

2020-09-06 Thread Simon Glass
This new method is intended to be called when UEFI shuts down the 'boot
services', i.e. any lingering code in the boot loader that might be used
by the OS.

Add a definition for this new method and update the comments a little.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/include/asm/fsp/fsp_api.h | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/fsp/fsp_api.h 
b/arch/x86/include/asm/fsp/fsp_api.h
index 4941e2d74f0..3a9b61903c0 100644
--- a/arch/x86/include/asm/fsp/fsp_api.h
+++ b/arch/x86/include/asm/fsp/fsp_api.h
@@ -10,9 +10,18 @@
 
 enum fsp_phase {
/* Notification code for post PCI enuermation */
-   INIT_PHASE_PCI  = 0x20,
-   /* Notification code before transferring control to the payload */
-   INIT_PHASE_BOOT = 0x40
+   INIT_PHASE_PCI  = 0x20,
+   /*
+* Notification code before transferring control to the payload.
+* This is issued at the end of init before starting main(), i.e.
+* the command line / boot script.
+*/
+   INIT_PHASE_BOOT = 0x40,
+   /*
+* Notification code before existing boot services. This is issued
+* just before removing devices and booting the kernel.
+*/
+   INIT_PHASE_END_FIRMWARE = 0xf0,
 };
 
 struct fsp_notify_params {
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 37/57] x86: apl: Generate ACPI table for LPC

2020-09-06 Thread Simon Glass
Add an ACPI table for the LPC on Apollo Lake.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Capitalise ACPI_OPS_PTR

 arch/x86/cpu/apollolake/lpc.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/x86/cpu/apollolake/lpc.c b/arch/x86/cpu/apollolake/lpc.c
index b81a458f2eb..a29832c879a 100644
--- a/arch/x86/cpu/apollolake/lpc.c
+++ b/arch/x86/cpu/apollolake/lpc.c
@@ -9,10 +9,14 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 void lpc_enable_fixed_io_ranges(uint io_enables)
@@ -110,6 +114,19 @@ void lpc_io_setup_comm_a_b(void)
lpc_enable_fixed_io_ranges(com_enable);
 }
 
+static int apl_acpi_lpc_get_name(const struct udevice *dev, char *out_name)
+{
+   return acpi_copy_name(out_name, "LPCB");
+}
+
+struct acpi_ops apl_lpc_acpi_ops = {
+   .get_name   = apl_acpi_lpc_get_name,
+#ifdef CONFIG_GENERATE_ACPI_TABLE
+   .write_tables   = intel_southbridge_write_acpi_tables,
+#endif
+   .inject_dsdt= southbridge_inject_dsdt,
+};
+
 static const struct udevice_id apl_lpc_ids[] = {
{ .compatible = "intel,apl-lpc" },
{ }
@@ -120,4 +137,5 @@ U_BOOT_DRIVER(apl_lpc_drv) = {
.name   = "intel_apl_lpc",
.id = UCLASS_LPC,
.of_match   = apl_lpc_ids,
+   ACPI_OPS_PTR(&apl_lpc_acpi_ops)
 };
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 35/57] x86: apl: Add support for hostbridge ACPI generation

2020-09-06 Thread Simon Glass
Support generating a DMAR table and add a few helper routines as well.
Also set up NHLT so that audio works.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Add support for NHLT table
- Capitalise ACPI_OPS_PTR
- Move the acpi.h header file to this commit
- Update commit message

 arch/x86/cpu/apollolake/hostbridge.c | 221 +--
 1 file changed, 212 insertions(+), 9 deletions(-)

diff --git a/arch/x86/cpu/apollolake/hostbridge.c 
b/arch/x86/cpu/apollolake/hostbridge.c
index 056f7e57a9a..cf60fd8b021 100644
--- a/arch/x86/cpu/apollolake/hostbridge.c
+++ b/arch/x86/cpu/apollolake/hostbridge.c
@@ -1,17 +1,45 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright 2019 Google LLC
+ * Copyright (C) 2015 - 2017 Intel Corp.
+ * Copyright (C) 2017 - 2019 Siemens AG
+ * (Written by Alexandru Gagniuc  for Intel 
Corp.)
+ * (Written by Andrey Petrov  for Intel Corp.)
+ *
+ * Portions from coreboot soc/intel/apollolake/chip.c
  */
 
+#define LOG_CATEGORY UCLASS_NORTHBRIDGE
+
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
+#include 
+#include 
+
+enum {
+   PCIEXBAR= 0x60,
+   PCIEXBAR_LENGTH_256MB   = 0,
+   PCIEXBAR_LENGTH_128MB,
+   PCIEXBAR_LENGTH_64MB,
+
+   PCIEXBAR_PCIEXBAREN = 1 << 0,
+
+   BGSM= 0xb4,  /* Base GTT Stolen Memory */
+   TSEG= 0xb8,  /* TSEG base */
+   TOLUD   = 0xbc,
+};
 
 /**
  * struct apl_hostbridge_platdata - platform data for hostbridge
@@ -32,17 +60,100 @@ struct apl_hostbridge_platdata {
pci_dev_t bdf;
 };
 
-enum {
-   PCIEXBAR= 0x60,
-   PCIEXBAR_LENGTH_256MB   = 0,
-   PCIEXBAR_LENGTH_128MB,
-   PCIEXBAR_LENGTH_64MB,
+static const struct nhlt_format_config dmic_1ch_formats[] = {
+   /* 48 KHz 16-bits per sample. */
+   {
+   .num_channels = 1,
+   .sample_freq_khz = 48,
+   .container_bits_per_sample = 16,
+   .valid_bits_per_sample = 16,
+   .settings_file = "dmic-1ch-48khz-16b.dat",
+   },
+};
 
-   PCIEXBAR_PCIEXBAREN = 1 << 0,
+static const struct nhlt_dmic_array_config dmic_1ch_mic_config = {
+   .tdm_config = {
+   .config_type = NHLT_TDM_MIC_ARRAY,
+   },
+   .array_type = NHLT_MIC_ARRAY_VENDOR_DEFINED,
+};
 
-   BGSM= 0xb4,  /* Base GTT Stolen Memory */
-   TSEG= 0xb8,  /* TSEG base */
-   TOLUD   = 0xbc,
+static const struct nhlt_endp_descriptor dmic_1ch_descriptors[] = {
+   {
+   .link = NHLT_LINK_PDM,
+   .device = NHLT_PDM_DEV,
+   .direction = NHLT_DIR_CAPTURE,
+   .vid = NHLT_VID,
+   .did = NHLT_DID_DMIC,
+   .cfg = &dmic_1ch_mic_config,
+   .cfg_size = sizeof(dmic_1ch_mic_config),
+   .formats = dmic_1ch_formats,
+   .num_formats = ARRAY_SIZE(dmic_1ch_formats),
+   },
+};
+
+static const struct nhlt_format_config dmic_2ch_formats[] = {
+   /* 48 KHz 16-bits per sample. */
+   {
+   .num_channels = 2,
+   .sample_freq_khz = 48,
+   .container_bits_per_sample = 16,
+   .valid_bits_per_sample = 16,
+   .settings_file = "dmic-2ch-48khz-16b.dat",
+   },
+};
+
+static const struct nhlt_dmic_array_config dmic_2ch_mic_config = {
+   .tdm_config = {
+   .config_type = NHLT_TDM_MIC_ARRAY,
+   },
+   .array_type = NHLT_MIC_ARRAY_2CH_SMALL,
+};
+
+static const struct nhlt_endp_descriptor dmic_2ch_descriptors[] = {
+   {
+   .link = NHLT_LINK_PDM,
+   .device = NHLT_PDM_DEV,
+   .direction = NHLT_DIR_CAPTURE,
+   .vid = NHLT_VID,
+   .did = NHLT_DID_DMIC,
+   .cfg = &dmic_2ch_mic_config,
+   .cfg_size = sizeof(dmic_2ch_mic_config),
+   .formats = dmic_2ch_formats,
+   .num_formats = ARRAY_SIZE(dmic_2ch_formats),
+   },
+};
+
+static const struct nhlt_format_config dmic_4ch_formats[] = {
+   /* 48 KHz 16-bits per sample. */
+   {
+   .num_channels = 4,
+   .sample_freq_khz = 48,
+   .container_bits_per_sample = 16,
+   .valid_bits_per_sample = 16,
+   .settings_file = "dmic-4ch-48khz-16b.dat",
+   },
+};
+
+static const struct nhlt_dmic_array_config dmic_4ch_mic_config = {
+   .tdm_config = {
+   .config_type = NHLT_TDM_MIC_ARRAY,
+   },
+   .array_type = NHLT_MIC_ARRAY_4CH_L_SHAPED,
+};
+
+static const struct nhlt_endp_descriptor dmic_4ch_descriptors[] = {
+   {
+   .link = NHLT_LINK_PDM,
+   .device = NHLT_PDM_DEV,
+   .direction = NHLT_DIR_CAPTURE,
+   

[PATCH v3 28/57] acpi: Add more support for generating processor tables

2020-09-06 Thread Simon Glass
This adds tables relating to P-States and C-States.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/acpi/acpigen.h | 162 +++
 lib/acpi/acpigen.c | 167 +++
 test/dm/acpigen.c  | 294 +
 3 files changed, 623 insertions(+)

diff --git a/include/acpi/acpigen.h b/include/acpi/acpigen.h
index 3a2c6339d5e..976f4dbb9af 100644
--- a/include/acpi/acpigen.h
+++ b/include/acpi/acpigen.h
@@ -10,8 +10,10 @@
 #ifndef __ACPI_ACPIGEN_H
 #define __ACPI_ACPIGEN_H
 
+#include 
 #include 
 
+struct acpi_cstate;
 struct acpi_ctx;
 struct acpi_gen_regaddr;
 struct acpi_gpio;
@@ -87,6 +89,53 @@ enum psd_coord {
HW_ALL = 0xfe
 };
 
+/**
+ * enum csd_coord -  Coordination types for C-states
+ *
+ * The type of coordination that exists (hardware) or is required (software) as
+ * a result of the underlying hardware dependency
+ */
+enum csd_coord {
+   CSD_HW_ALL = 0xfe,
+};
+
+/**
+ * struct acpi_cstate - Information about a C-State
+ *
+ * @ctype: C State type (1=C1, 2=C2, 3=C3)
+ * @latency: Worst-case latency to enter and exit the C State (in uS)
+ * @power: Average power consumption of the processor when in this C-State (mW)
+ * @resource: Register to read to place the processor in this state
+ */
+struct acpi_cstate {
+   uint ctype;
+   uint latency;
+   uint power;
+   struct acpi_gen_regaddr resource;
+};
+
+/**
+ * struct acpi_tstate - Information about a Throttling Supported State
+ *
+ * See ACPI v6.3 section 8.4.5.2: _TSS (Throttling Supported States)
+ *
+ * @percent: Percent of the core CPU operating frequency that will be
+ * available when this throttling state is invoked
+ * @power: Throttling state’s maximum power dissipation (mw)
+ * @latency: Worst-case latency (uS) that the CPU is unavailable during a
+ * transition from any throttling state to this throttling state
+ * @control: Value to be written to the Processor Control Register
+ * (THROTTLE_CTRL) to initiate a transition to this throttling state
+ * @status: Value in THROTTLE_STATUS when in this state
+ */
+struct acpi_tstate {
+   uint percent;
+   uint power;
+   uint latency;
+   uint control;
+   uint status;
+};
+
 /**
  * acpigen_get_current() - Get the current ACPI code output pointer
  *
@@ -816,4 +865,117 @@ void acpigen_write_processor_package(struct acpi_ctx 
*ctx, const char *name,
  */
 void acpigen_write_processor_cnot(struct acpi_ctx *ctx, const uint num_cores);
 
+/**
+ * acpigen_write_ppc() - generates a function returning max P-states
+ *
+ * @ctx: ACPI context pointer
+ * @num_pstates: Number of pstates to return
+ */
+void acpigen_write_ppc(struct acpi_ctx *ctx, uint num_pstates);
+
+/**
+ * acpigen_write_ppc() - generates a function returning PPCM
+ *
+ * This returns the maximum number of supported P-states, as saved in the
+ * variable PPCM
+ *
+ * @ctx: ACPI context pointer
+ */
+void acpigen_write_ppc_nvs(struct acpi_ctx *ctx);
+
+/**
+ * acpigen_write_tpc() - Write a _TPC method that returns the TPC limit
+ *
+ * @ctx: ACPI context pointer
+ * @gnvs_tpc_limit: Variable that holds the TPC limit
+ */
+void acpigen_write_tpc(struct acpi_ctx *ctx, const char *gnvs_tpc_limit);
+
+/**
+ * acpigen_write_pss_package() - Write a PSS package
+ *
+ * See ACPI v6.3 section 8.4.6: Processor Performance Control
+ *
+ * @ctx: ACPI context pointer
+ * @corefreq: CPU core frequency in MHz
+ * @translat: worst-case latency in uS that the CPU is unavailable during a
+ * transition from any performance state to this performance state
+ * @busmlat: worst-case latency in microseconds that Bus Masters are prevented
+ * from accessing memory during a transition from any performance state to
+ * this performance state
+ * @control: Value to write to PERF_CTRL to move to this performance state
+ * @status: Expected PERF_STATUS value when in this state
+ */
+void acpigen_write_pss_package(struct acpi_ctx *ctx, uint corefreq, uint power,
+  uint translat, uint busmlat, uint control,
+  uint status);
+
+/**
+ * acpigen_write_psd_package() - Write a PSD package
+ *
+ * Writes a P-State dependency package
+ *
+ * See ACPI v6.3 section 8.4.6.5: _PSD (P-State Dependency)
+ *
+ * @ctx: ACPI context pointer
+ * @domain: Dependency domain number to which this P state entry belongs
+ * @numprocs: Number of processors belonging to the domain for this logical
+ * processor’s P-states
+ * @coordtype: Coordination type
+ */
+void acpigen_write_psd_package(struct acpi_ctx *ctx, uint domain, uint 
numprocs,
+  enum psd_coord coordtype);
+
+/**
+ * acpigen_write_cst_package() - Write a _CST package
+ *
+ * See ACPI v6.3 section 8.4.2.1: _CST (C States)
+ *
+ * @ctx: ACPI context pointer
+ * @entry: Array of entries
+ * @nentries; Number of entries
+ */
+void acpigen_write_cst_package(struct acpi_ctx *ctx,
+   

[PATCH v3 34/57] x86: apl: Generate required ACPI tables

2020-09-06 Thread Simon Glass
Add support for generating various ACPI tables for Apollo Lake. Add a few
S3 definitions that are needed.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Drop unnecessary callbacks

 arch/x86/cpu/apollolake/Makefile|   1 +
 arch/x86/cpu/apollolake/acpi.c  | 211 
 arch/x86/include/asm/arch-apollolake/acpi.h |  18 ++
 include/acpi/acpi_s3.h  |   4 +
 4 files changed, 234 insertions(+)
 create mode 100644 arch/x86/cpu/apollolake/acpi.c
 create mode 100644 arch/x86/include/asm/arch-apollolake/acpi.h

diff --git a/arch/x86/cpu/apollolake/Makefile b/arch/x86/cpu/apollolake/Makefile
index 3aa2a556765..2ddf4af62c5 100644
--- a/arch/x86/cpu/apollolake/Makefile
+++ b/arch/x86/cpu/apollolake/Makefile
@@ -16,6 +16,7 @@ obj-y += fsp_m.o
 endif
 endif
 ifndef CONFIG_SPL_BUILD
+obj-y += acpi.o
 obj-y += fsp_s.o
 endif
 
diff --git a/arch/x86/cpu/apollolake/acpi.c b/arch/x86/cpu/apollolake/acpi.c
new file mode 100644
index 000..69b544f0d98
--- /dev/null
+++ b/arch/x86/cpu/apollolake/acpi.c
@@ -0,0 +1,211 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2016 Intel Corp.
+ * Copyright (C) 2017-2019 Siemens AG
+ * (Written by Lance Zhao  for Intel Corp.)
+ * Copyright 2019 Google LLC
+ *
+ * Modified from coreboot apollolake/acpi.c
+ */
+
+#define LOG_CATEGORY LOGC_ACPI
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int arch_read_sci_irq_select(void)
+{
+   struct acpi_pmc_upriv *upriv;
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
+   if (ret)
+   return log_msg_ret("pmc", ret);
+   upriv = dev_get_uclass_priv(dev);
+
+   return readl(upriv->pmc_bar0 + IRQ_REG);
+}
+
+int arch_write_sci_irq_select(uint scis)
+{
+   struct acpi_pmc_upriv *upriv;
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
+   if (ret)
+   return log_msg_ret("pmc", ret);
+   upriv = dev_get_uclass_priv(dev);
+   writel(scis, upriv->pmc_bar0 + IRQ_REG);
+
+   return 0;
+}
+
+int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
+{
+   struct udevice *cpu;
+   int ret;
+
+   /* Clear out GNV */
+   memset(gnvs, '\0', sizeof(*gnvs));
+
+   /* TODO(s...@chromium.org): Add the console log to gnvs->cbmc */
+
+#ifdef CONFIG_CHROMEOS
+   /* Initialise Verified Boot data */
+   chromeos_init_acpi(&gnvs->chromeos);
+   gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
+#endif
+   /* Set unknown wake source */
+   gnvs->pm1i = ~0ULL;
+
+   /* CPU core count */
+   gnvs->pcnt = 1;
+   ret = uclass_find_first_device(UCLASS_CPU, &cpu);
+   if (cpu) {
+   ret = cpu_get_count(cpu);
+   if (ret > 0)
+   gnvs->pcnt = ret;
+   }
+
+   return 0;
+}
+
+uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en)
+{
+   /*
+* WAK_STS bit is set when the system is in one of the sleep states
+* (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
+* this bit, the PMC will transition the system to the ON state and
+* can only be set by hardware and can only be cleared by writing a one
+* to this bit position.
+*/
+   generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
+
+   return generic_pm1_en;
+}
+
+int arch_madt_sci_irq_polarity(int sci)
+{
+   return MP_IRQ_POLARITY_LOW;
+}
+
+void fill_fadt(struct acpi_fadt *fadt)
+{
+   fadt->pm_tmr_blk = IOMAP_ACPI_BASE + PM1_TMR;
+
+   fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
+   fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
+
+   fadt->pm_tmr_len = 4;
+   fadt->duty_width = 3;
+
+   fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
+
+   fadt->x_pm_tmr_blk.space_id = 1;
+   fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
+   fadt->x_pm_tmr_blk.addrl = IOMAP_ACPI_BASE + PM1_TMR;
+}
+
+void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
+ void *dsdt)
+{
+   struct acpi_table_header *header = &fadt->header;
+
+   acpi_fadt_common(fadt, facs, dsdt);
+   intel_acpi_fill_fadt(fadt);
+   fill_fadt(fadt);
+   header->checksum = table_compute_checksum(fadt, header->length);
+}
+
+int apl_acpi_fill_dmar(struct acpi_ctx *ctx)
+{
+   struct udevice *dev, *sa_dev;
+   u64 gfxvtbar = readq(MCHBAR_REG(GFXVTBAR)) & VTBAR_MASK;
+   u64 defvtbar = readq(MCHBAR_REG(DEFVTBAR)) & VTBAR_MASK;
+   bool gfxvten = readl(MCHBAR_REG(GFXVTBAR)) & VTBAR_ENABLED;
+   bool defvten = readl(MCHBAR_REG(DEFVTBAR)) & VTBAR_ENABLED;
+   void *tmp;
+   

[PATCH v3 33/57] p2sb: Add some definitions used for ACPI

2020-09-06 Thread Simon Glass
Allow this header to be included in ASL files by adding a header guard and
a few definitions that are needed.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/p2sb.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/p2sb.h b/include/p2sb.h
index 93e1155dca6..a25170e3d11 100644
--- a/include/p2sb.h
+++ b/include/p2sb.h
@@ -10,6 +10,12 @@
 /* Port Id lives in bits 23:16 and register offset lives in 15:0 of address */
 #define PCR_PORTID_SHIFT   16
 
+#if !defined(__ACPI__)
+
+/* These registers contain IOAPIC and HPET devfn */
+#define PCH_P2SB_IBDF  0x6c
+#define PCH_P2SB_HBDF  0x70
+
 /**
  * struct p2sb_child_platdata - Information about each child of a p2sb device
  *
@@ -164,4 +170,6 @@ int p2sb_get_port_id(struct udevice *dev);
  */
 void *pcr_reg_address(struct udevice *dev, uint offset);
 
+#endif /* !__ACPI__ */
+
 #endif
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 31/57] x86: acpi: Add support for additional Intel tables

2020-09-06 Thread Simon Glass
Apollo Lake needs to generate a few more table types used on Intel SoCs.
Add support for these into the x86 ACPI code.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Move this code into an x86-specific file
- Update commit message
- Use OEM_TABLE_ID instead of ACPI_TABLE_CREATOR

 arch/x86/include/asm/acpi_table.h | 115 ++
 arch/x86/lib/acpi_table.c | 111 
 include/acpi/acpi_table.h |  43 +++
 3 files changed, 269 insertions(+)

diff --git a/arch/x86/include/asm/acpi_table.h 
b/arch/x86/include/asm/acpi_table.h
index 3245e447813..faf31730730 100644
--- a/arch/x86/include/asm/acpi_table.h
+++ b/arch/x86/include/asm/acpi_table.h
@@ -98,4 +98,119 @@ int arch_write_sci_irq_select(uint scis);
  */
 int arch_madt_sci_irq_polarity(int sci);
 
+/**
+ * acpi_create_dmar_drhd() - Create a table for DMA remapping with the IOMMU
+ *
+ * See here for the specification
+ * 
https://software.intel.com/sites/default/files/managed/c5/15/vt-directed-io-spec.pdf
+ *
+ * @ctx: ACPI context pointer
+ * @flags: (DRHD_INCLUDE_...)
+ * @segment: PCI segment asscociated with this unit
+ * @bar: Base address of remapping hardware register-set for this unit
+ */
+void acpi_create_dmar_drhd(struct acpi_ctx *ctx, uint flags, uint segment,
+  u64 bar);
+
+/**
+ * acpi_create_dmar_rmrr() - Set up an RMRR
+ *
+ * This sets up a Reserved-Memory Region Reporting structure, used to allow
+ * DMA to regions used by devices that the BIOS controls.
+ *
+ * @ctx: ACPI context pointer
+ * @segment: PCI segment asscociated with this unit
+ * @bar: Base address of mapping
+ * @limit: End address of mapping
+ */
+void acpi_create_dmar_rmrr(struct acpi_ctx *ctx, uint segment, u64 bar,
+  u64 limit);
+
+/**
+ * acpi_dmar_drhd_fixup() - Set the length of an DRHD
+ *
+ * This sets the DRHD length field based on the current ctx->current
+ *
+ * @ctx: ACPI context pointer
+ * @base: Address of the start of the DRHD
+ */
+void acpi_dmar_drhd_fixup(struct acpi_ctx *ctx, void *base);
+
+/**
+ * acpi_dmar_rmrr_fixup() - Set the length of an RMRR
+ *
+ * This sets the RMRR length field based on the current ctx->current
+ *
+ * @ctx: ACPI context pointer
+ * @base: Address of the start of the RMRR
+ */
+void acpi_dmar_rmrr_fixup(struct acpi_ctx *ctx, void *base);
+
+/**
+ * acpi_create_dmar_ds_pci() - Set up a DMAR scope for a PCI device
+ *
+ * @ctx: ACPI context pointer
+ * @bdf: PCI device to add
+ * @return length of mapping in bytes
+ */
+int acpi_create_dmar_ds_pci(struct acpi_ctx *ctx, pci_dev_t bdf);
+
+/**
+ * acpi_create_dmar_ds_pci_br() - Set up a DMAR scope for a PCI bridge
+ *
+ * This is used to provide a mapping for a PCI bridge
+ *
+ * @ctx: ACPI context pointer
+ * @bdf: PCI device to add
+ * @return length of mapping in bytes
+ */
+int acpi_create_dmar_ds_pci_br(struct acpi_ctx *ctx, pci_dev_t bdf);
+
+/**
+ * acpi_create_dmar_ds_ioapic() - Set up a DMAR scope for an IOAPIC device
+ *
+ * @ctx: ACPI context pointer
+ * @enumeration_id: Enumeration ID (typically 2)
+ * @bdf: PCI device to add
+ * @return length of mapping in bytes
+ */
+int acpi_create_dmar_ds_ioapic(struct acpi_ctx *ctx, uint enumeration_id,
+  pci_dev_t bdf);
+
+/**
+ * acpi_create_dmar_ds_msi_hpet() - Set up a DMAR scope for an HPET
+ *
+ * Sets up a scope for a High-Precision Event Timer that supports
+ * Message-Signalled Interrupts
+ *
+ * @ctx: ACPI context pointer
+ * @enumeration_id: Enumeration ID (typically 0)
+ * @bdf: PCI device to add
+ * @return length of mapping in bytes
+ */
+int acpi_create_dmar_ds_msi_hpet(struct acpi_ctx *ctx, uint enumeration_id,
+pci_dev_t bdf);
+
+/**
+ * acpi_fadt_common() - Handle common parts of filling out an FADT
+ *
+ * This sets up the Fixed ACPI Description Table
+ *
+ * @fadt: Pointer to place to put FADT
+ * @facs: Pointer to the FACS
+ * @dsdt: Pointer to the DSDT
+ */
+void acpi_fadt_common(struct acpi_fadt *fadt, struct acpi_facs *facs,
+ void *dsdt);
+
+/**
+ * intel_acpi_fill_fadt() - Set up the contents of the FADT
+ *
+ * This sets up parts of the Fixed ACPI Description Table that are common to
+ * Intel chips
+ *
+ * @fadt: Pointer to place to put FADT
+ */
+void intel_acpi_fill_fadt(struct acpi_fadt *fadt);
+
 #endif /* __ASM_ACPI_TABLE_H__ */
diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 28a27103342..b0cc1f123e2 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -616,3 +616,114 @@ int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct 
udevice *dev,
 
return 0;
 }
+
+void acpi_fadt_common(struct acpi_fadt *fadt, struct acpi_facs *facs,
+ void *dsdt)
+{
+   struct acpi_table_header *header = &fadt->header;
+
+   memset((void *)fadt, '\0', sizeof(struct acpi_fadt));
+
+   acpi_fill_header(header, "

[PATCH v3 26/57] acpi: Add support for generating processor tables

2020-09-06 Thread Simon Glass
ACPI has a number of CPU-related tables. Add utility functions to write
out the basic packages.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/acpi/acpigen.h |  39 +++
 lib/acpi/acpigen.c |  55 +
 test/dm/acpigen.c  | 106 +
 3 files changed, 200 insertions(+)

diff --git a/include/acpi/acpigen.h b/include/acpi/acpigen.h
index c412898169e..3a2c6339d5e 100644
--- a/include/acpi/acpigen.h
+++ b/include/acpi/acpigen.h
@@ -64,7 +64,9 @@ enum {
OR_OP   = 0x7d,
NOT_OP  = 0x80,
DEVICE_OP   = 0x82,
+   PROCESSOR_OP= 0x83,
POWER_RES_OP= 0x84,
+   NOTIFY_OP   = 0x86,
LEQUAL_OP   = 0x93,
TO_BUFFER_OP= 0x96,
TO_INTEGER_OP   = 0x99,
@@ -777,4 +779,41 @@ void acpigen_write_dsm_uuid_end(struct acpi_ctx *ctx);
  */
 void acpigen_write_dsm_end(struct acpi_ctx *ctx);
 
+/**
+ * acpigen_write_processor() - Write a Processor package
+ *
+ * This emits a Processor package header with the required information. The
+ * caller must complete the information and call acpigen_pop_len() at the end
+ *
+ * @ctx: ACPI context pointer
+ * @cpuindex: CPU number
+ * @pblock_addr: PBlk system IO address
+ * @pblock_len: PBlk length
+ */
+void acpigen_write_processor(struct acpi_ctx *ctx, uint cpuindex,
+u32 pblock_addr, uint pblock_len);
+
+/**
+ * acpigen_write_processor_package() - Write a package containing the 
processors
+ *
+ * The package containins the name of each processor in the SoC
+ *
+ * @ctx: ACPI context pointer
+ * @name: Package name (.e.g "PPKG")
+ * @first_core: Number of the first core (e.g. 0)
+ * @core_count: Number of cores (e.g. 4)
+ */
+void acpigen_write_processor_package(struct acpi_ctx *ctx, const char *name,
+uint first_core, uint core_count);
+
+/**
+ * acpigen_write_processor_cnot() - Write a processor notification method
+ *
+ * This writes a method that notifies all CPU cores
+ *
+ * @ctx: ACPI context pointer
+ * @num_cores: Number of CPU cores
+ */
+void acpigen_write_processor_cnot(struct acpi_ctx *ctx, const uint num_cores);
+
 #endif
diff --git a/lib/acpi/acpigen.c b/lib/acpi/acpigen.c
index d859f378413..b9985075cde 100644
--- a/lib/acpi/acpigen.c
+++ b/lib/acpi/acpigen.c
@@ -17,6 +17,9 @@
 #include 
 #include 
 
+/* CPU path format */
+#define ACPI_CPU_STRING "\\_PR.CP%02d"
+
 u8 *acpigen_get_current(struct acpi_ctx *ctx)
 {
return ctx->current;
@@ -340,6 +343,58 @@ void acpigen_write_method_serialized(struct acpi_ctx *ctx, 
const char *name,
  ACPI_METHOD_SERIALIZED_MASK);
 }
 
+void acpigen_write_processor(struct acpi_ctx *ctx, uint cpuindex,
+u32 pblock_addr, uint pblock_len)
+{
+   /*
+* Processor (\_PR.CPnn, cpuindex, pblock_addr, pblock_len)
+* {
+*/
+   char pscope[16];
+
+   acpigen_emit_ext_op(ctx, PROCESSOR_OP);
+   acpigen_write_len_f(ctx);
+
+   snprintf(pscope, sizeof(pscope), ACPI_CPU_STRING, cpuindex);
+   acpigen_emit_namestring(ctx, pscope);
+   acpigen_emit_byte(ctx, cpuindex);
+   acpigen_emit_dword(ctx, pblock_addr);
+   acpigen_emit_byte(ctx, pblock_len);
+}
+
+void acpigen_write_processor_package(struct acpi_ctx *ctx,
+const char *const name,
+const uint first_core,
+const uint core_count)
+{
+   uint i;
+   char pscope[16];
+
+   acpigen_write_name(ctx, name);
+   acpigen_write_package(ctx, core_count);
+   for (i = first_core; i < first_core + core_count; ++i) {
+   snprintf(pscope, sizeof(pscope), ACPI_CPU_STRING, i);
+   acpigen_emit_namestring(ctx, pscope);
+   }
+   acpigen_pop_len(ctx);
+}
+
+void acpigen_write_processor_cnot(struct acpi_ctx *ctx, const uint num_cores)
+{
+   int core_id;
+
+   acpigen_write_method(ctx, "\\_PR.CNOT", 1);
+   for (core_id = 0; core_id < num_cores; core_id++) {
+   char buffer[30];
+
+   snprintf(buffer, sizeof(buffer), ACPI_CPU_STRING, core_id);
+   acpigen_emit_byte(ctx, NOTIFY_OP);
+   acpigen_emit_namestring(ctx, buffer);
+   acpigen_emit_byte(ctx, ARG0_OP);
+   }
+   acpigen_pop_len(ctx);
+}
+
 void acpigen_write_device(struct acpi_ctx *ctx, const char *name)
 {
acpigen_emit_ext_op(ctx, DEVICE_OP);
diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c
index 381fcb97022..74b7e23aab3 100644
--- a/test/dm/acpigen.c
+++ b/test/dm/acpigen.c
@@ -1344,3 +1344,109 @@ static int dm_test_acpi_write_i2c_dsm(struct 
unit_test_state *uts)
 }
 DM_TEST(dm_test_acpi_write_i2c_dsm, 0);
 
+/* Test emitting a processor */
+static int dm_test_acpi_write_

[PATCH v3 25/57] x86: acpi: Support generation of the DBG2 table

2020-09-06 Thread Simon Glass
Add an implementation of the DBG2 (Debug Port Table 2) ACPI table.
Adjust one of the header includes to be in the correct order, before
adding more.

Note that the DBG2 table is generic but the PCI UART is x86-specific at
present since it assumes an ns16550 UART. It can be generalised later
if necessary.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Move ASL_REVISION define into this patch
- Move acpi_create_dbg2() into generic code
- Update commit message

 arch/x86/include/asm/acpi_table.h | 11 ++
 arch/x86/lib/acpi_table.c | 41 
 include/acpi/acpi_table.h | 40 +++
 lib/acpi/acpi_table.c | 64 +++
 4 files changed, 156 insertions(+)

diff --git a/arch/x86/include/asm/acpi_table.h 
b/arch/x86/include/asm/acpi_table.h
index 7047ee6c772..1b7ff509516 100644
--- a/arch/x86/include/asm/acpi_table.h
+++ b/arch/x86/include/asm/acpi_table.h
@@ -46,6 +46,17 @@ u32 acpi_fill_csrt(u32 current);
  */
 int acpi_write_hpet(struct acpi_ctx *ctx);
 
+/**
+ * acpi_write_dbg2_pci_uart() - Write out a DBG2 table
+ *
+ * @ctx: Current ACPI context
+ * @dev: Debug UART device to describe
+ * @access_size: Access size for UART (e.g. ACPI_ACCESS_SIZE_DWORD_ACCESS)
+ * @return 0 if OK, -ve on error
+ */
+int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct udevice *dev,
+uint access_size);
+
 /**
  * acpi_create_gnvs() - Create a GNVS (Global Non Volatile Storage) table
  *
diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index e1900ffe42f..28a27103342 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -575,3 +576,43 @@ int acpi_write_hpet(struct acpi_ctx *ctx)
 
return 0;
 }
+
+int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct udevice *dev,
+uint access_size)
+{
+   struct acpi_dbg2_header *dbg2 = ctx->current;
+   char path[ACPI_PATH_MAX];
+   struct acpi_gen_regaddr address;
+   phys_addr_t addr;
+   int ret;
+
+   if (!device_active(dev)) {
+   log_info("Device not enabled\n");
+   return -EACCES;
+   }
+   /*
+* PCI devices don't remember their resource allocation information in
+* U-Boot at present. We assume that MMIO is used for the UART and that
+* the address space is 32 bytes: ns16550 uses 8 registers of up to
+* 32-bits each. This is only for debugging so it is not a big deal.
+*/
+   addr = dm_pci_read_bar32(dev, 0);
+   printf("UART addr %lx\n", (ulong)addr);
+
+   memset(&address, '\0', sizeof(address));
+   address.space_id = ACPI_ADDRESS_SPACE_MEMORY;
+   address.addrl = (uint32_t)addr;
+   address.addrh = (uint32_t)((addr >> 32) & 0x);
+   address.access_size = access_size;
+
+   ret = acpi_device_path(dev, path, sizeof(path));
+   if (ret)
+   return log_msg_ret("path", ret);
+   acpi_create_dbg2(dbg2, ACPI_DBG2_SERIAL_PORT,
+ACPI_DBG2_16550_COMPATIBLE, &address, 0x1000, path);
+
+   acpi_inc_align(ctx, dbg2->header.length);
+   acpi_add_table(ctx, dbg2);
+
+   return 0;
+}
diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
index f8140446a59..c826a797f5b 100644
--- a/include/acpi/acpi_table.h
+++ b/include/acpi/acpi_table.h
@@ -448,6 +448,29 @@ struct __packed acpi_dmar {
 
 #define ACPI_DBG2_UNKNOWN  0x00FF
 
+/* DBG2: Microsoft Debug Port Table 2 header */
+struct __packed acpi_dbg2_header {
+   struct acpi_table_header header;
+   u32 devices_offset;
+   u32 devices_count;
+};
+
+/* DBG2: Microsoft Debug Port Table 2 device entry */
+struct __packed acpi_dbg2_device {
+   u8  revision;
+   u16 length;
+   u8 address_count;
+   u16 namespace_string_length;
+   u16 namespace_string_offset;
+   u16 oem_data_length;
+   u16 oem_data_offset;
+   u16 port_type;
+   u16 port_subtype;
+   u8  reserved[2];
+   u16 base_address_offset;
+   u16 address_size_offset;
+};
+
 /* SPCR (Serial Port Console Redirection table) */
 struct __packed acpi_spcr {
struct acpi_table_header header;
@@ -522,6 +545,23 @@ int acpi_get_table_revision(enum acpi_tables table);
  */
 int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags);
 
+/**
+ * acpi_create_dbg2() - Create a DBG2 table
+ *
+ * This table describes how to access the debug UART
+ *
+ * @dbg2: Place to put information
+ * @port_type: Serial port type (see ACPI_DBG2_...)
+ * @port_subtype: Serial port sub-type (see ACPI_DBG2_...)
+ * @address: ACPI address of port
+ * @address_size: Size of address space
+ * @device_path: Path of device (created using acpi_device_path())
+ */
+void acpi_create_dbg2(struct acpi_dbg2_header *dbg2,
+   

[PATCH v3 32/57] x86: apl: Allow reading hostbridge base addresses

2020-09-06 Thread Simon Glass
Add a few functions to permit reading of various useful base addresses
provided by the hostbridge.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Add comments

 arch/x86/cpu/apollolake/hostbridge.c  | 27 
 .../include/asm/arch-apollolake/systemagent.h | 31 +++
 2 files changed, 58 insertions(+)

diff --git a/arch/x86/cpu/apollolake/hostbridge.c 
b/arch/x86/cpu/apollolake/hostbridge.c
index cb46ec6c0bb..056f7e57a9a 100644
--- a/arch/x86/cpu/apollolake/hostbridge.c
+++ b/arch/x86/cpu/apollolake/hostbridge.c
@@ -40,7 +40,9 @@ enum {
 
PCIEXBAR_PCIEXBAREN = 1 << 0,
 
+   BGSM= 0xb4,  /* Base GTT Stolen Memory */
TSEG= 0xb8,  /* TSEG base */
+   TOLUD   = 0xbc,
 };
 
 static int apl_hostbridge_early_init_pinctrl(struct udevice *dev)
@@ -165,6 +167,31 @@ static int apl_hostbridge_probe(struct udevice *dev)
return 0;
 }
 
+static ulong sa_read_reg(struct udevice *dev, int reg)
+{
+   u32 val;
+
+   /* All regions concerned for have 1 MiB alignment */
+   dm_pci_read_config32(dev, BGSM, &val);
+
+   return ALIGN_DOWN(val, 1 << 20);
+}
+
+ulong sa_get_tolud_base(struct udevice *dev)
+{
+   return sa_read_reg(dev, TOLUD);
+}
+
+ulong sa_get_gsm_base(struct udevice *dev)
+{
+   return sa_read_reg(dev, BGSM);
+}
+
+ulong sa_get_tseg_base(struct udevice *dev)
+{
+   return sa_read_reg(dev, TSEG);
+}
+
 static const struct udevice_id apl_hostbridge_ids[] = {
{ .compatible = "intel,apl-hostbridge" },
{ }
diff --git a/arch/x86/include/asm/arch-apollolake/systemagent.h 
b/arch/x86/include/asm/arch-apollolake/systemagent.h
index 9e7bd62751a..788a63d7999 100644
--- a/arch/x86/include/asm/arch-apollolake/systemagent.h
+++ b/arch/x86/include/asm/arch-apollolake/systemagent.h
@@ -35,4 +35,35 @@
  */
 void enable_bios_reset_cpl(void);
 
+/**
+ * sa_get_tolud_base() - Get the TOLUD base address
+ *
+ * This returns the Top Of Low Useable DRAM, marking the top of usable DRAM
+ * below 4GB
+ *
+ * @dev: hostbridge device
+ * @return TOLUD address
+ */
+ulong sa_get_tolud_base(struct udevice *dev);
+
+/**
+ * sa_get_gsm_base() - Get the GSM base address
+ *
+ * This returns the base of GTT Stolen Memory, marking the start of memory used
+ * for Graphics Translation Tables.
+ *
+ * @dev: hostbridge device
+ * @return GSM address
+ */
+ulong sa_get_gsm_base(struct udevice *dev);
+
+/**
+ * sa_get_tseg_base() - Get the TSEG base address
+ *
+ * This returns the top address of DRAM available below 4GB
+ *
+ * @return TSEG base
+ */
+ulong sa_get_tseg_base(struct udevice *dev);
+
 #endif
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 29/57] x86: acpi: Add common Intel ACPI tables

2020-09-06 Thread Simon Glass
Add various tables that are common to Intel CPUs. These functions can be
used by arch-specific CPU code.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/cpu/intel_common/Makefile |   2 +
 arch/x86/cpu/intel_common/acpi.c   | 377 +
 arch/x86/cpu/intel_common/cpu.c|  14 ++
 arch/x86/include/asm/acpi_table.h  |  22 ++
 arch/x86/include/asm/cpu_common.h  |   7 +
 arch/x86/include/asm/intel_acpi.h  |  52 
 drivers/core/Kconfig   |   9 +
 7 files changed, 483 insertions(+)
 create mode 100644 arch/x86/cpu/intel_common/acpi.c
 create mode 100644 arch/x86/include/asm/intel_acpi.h

diff --git a/arch/x86/cpu/intel_common/Makefile 
b/arch/x86/cpu/intel_common/Makefile
index f1d1513a981..4a5cf17e41d 100644
--- a/arch/x86/cpu/intel_common/Makefile
+++ b/arch/x86/cpu/intel_common/Makefile
@@ -2,6 +2,8 @@
 #
 # Copyright (c) 2016 Google, Inc
 
+obj-$(CONFIG_INTEL_ACPIGEN) += acpi.o
+
 ifdef CONFIG_HAVE_MRC
 obj-$(CONFIG_$(SPL_TPL_)X86_16BIT_INIT) += car.o
 obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += me_status.o
diff --git a/arch/x86/cpu/intel_common/acpi.c b/arch/x86/cpu/intel_common/acpi.c
new file mode 100644
index 000..a4d5fbd38a7
--- /dev/null
+++ b/arch/x86/cpu/intel_common/acpi.c
@@ -0,0 +1,377 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Generic Intel ACPI table generation
+ *
+ * Copyright (C) 2017 Intel Corp.
+ * Copyright 2019 Google LLC
+ *
+ * Modified from coreboot src/soc/intel/common/block/acpi.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+u32 acpi_fill_mcfg(u32 current)
+{
+   /* PCI Segment Group 0, Start Bus Number 0, End Bus Number is 255 */
+   current += acpi_create_mcfg_mmconfig((void *)current,
+CONFIG_MMCONF_BASE_ADDRESS, 0, 0,
+(CONFIG_SA_PCIEX_LENGTH >> 20)
+- 1);
+   return current;
+}
+
+static int acpi_sci_irq(void)
+{
+   int sci_irq = 9;
+   uint scis;
+   int ret;
+
+   ret = arch_read_sci_irq_select();
+   if (IS_ERR_VALUE(ret))
+   return log_msg_ret("sci_irq", ret);
+   scis = ret;
+   scis &= SCI_IRQ_MASK;
+   scis >>= SCI_IRQ_SHIFT;
+
+   /* Determine how SCI is routed. */
+   switch (scis) {
+   case SCIS_IRQ9:
+   case SCIS_IRQ10:
+   case SCIS_IRQ11:
+   sci_irq = scis - SCIS_IRQ9 + 9;
+   break;
+   case SCIS_IRQ20:
+   case SCIS_IRQ21:
+   case SCIS_IRQ22:
+   case SCIS_IRQ23:
+   sci_irq = scis - SCIS_IRQ20 + 20;
+   break;
+   default:
+   log_warning("Invalid SCI route! Defaulting to IRQ9\n");
+   sci_irq = 9;
+   break;
+   }
+
+   log_debug("SCI is IRQ%d\n", sci_irq);
+
+   return sci_irq;
+}
+
+static unsigned long acpi_madt_irq_overrides(unsigned long current)
+{
+   int sci = acpi_sci_irq();
+   u16 flags = MP_IRQ_TRIGGER_LEVEL;
+
+   if (sci < 0)
+   return log_msg_ret("sci irq", sci);
+
+   /* INT_SRC_OVR */
+   current += acpi_create_madt_irqoverride((void *)current, 0, 0, 2, 0);
+
+   flags |= arch_madt_sci_irq_polarity(sci);
+
+   /* SCI */
+   current +=
+   acpi_create_madt_irqoverride((void *)current, 0, sci, sci, flags);
+
+   return current;
+}
+
+u32 acpi_fill_madt(u32 current)
+{
+   /* Local APICs */
+   current += acpi_create_madt_lapics(current);
+
+   /* IOAPIC */
+   current += acpi_create_madt_ioapic((void *)current, 2, IO_APIC_ADDR, 0);
+
+   return acpi_madt_irq_overrides(current);
+}
+
+void intel_acpi_fill_fadt(struct acpi_fadt *fadt)
+{
+   const u16 pmbase = IOMAP_ACPI_BASE;
+
+   /* Use ACPI 3.0 revision. */
+   fadt->header.revision = acpi_get_table_revision(ACPITAB_FADT);
+
+   fadt->sci_int = acpi_sci_irq();
+   fadt->smi_cmd = APM_CNT;
+   fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
+   fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
+   fadt->s4bios_req = 0x0;
+   fadt->pstate_cnt = 0;
+
+   fadt->pm1a_evt_blk = pmbase + PM1_STS;
+   fadt->pm1b_evt_blk = 0x0;
+   fadt->pm1a_cnt_blk = pmbase + PM1_CNT;
+   fadt->pm1b_cnt_blk = 0x0;
+
+   fadt->gpe0_blk = pmbase + GPE0_STS;
+
+   fadt->pm1_evt_len = 4;
+   fadt->pm1_cnt_len = 2;
+
+   /* GPE0 STS/EN pairs each 32 bits wide. */
+   fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t);
+
+   fadt->flush_size = 0x400;   /* twice of cache size */
+   fadt->flush_stride = 0x10;  /* Cache line width  */
+   fadt->duty_offset = 1;
+   fadt->day_alrm = 0xd;
+
+   fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
+   ACPI_FADT_C2_M

[PATCH v3 23/57] x86: Add a few common Intel CPU functions

2020-09-06 Thread Simon Glass
Add functions to query CPU information, needed for ACPI.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Add more comments and rename cpu_get_bus_clock to cpu_get_bus_clock_khz()

 arch/x86/cpu/intel_common/cpu.c   | 64 +++
 arch/x86/include/asm/cpu_common.h | 49 +++
 include/acpi/acpigen.h| 12 ++
 3 files changed, 125 insertions(+)

diff --git a/arch/x86/cpu/intel_common/cpu.c b/arch/x86/cpu/intel_common/cpu.c
index 509730aea96..cb4ef84013a 100644
--- a/arch/x86/cpu/intel_common/cpu.c
+++ b/arch/x86/cpu/intel_common/cpu.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -227,3 +228,66 @@ void cpu_set_eist(bool eist_status)
msr.lo &= ~MISC_ENABLE_ENHANCED_SPEEDSTEP;
msr_write(MSR_IA32_MISC_ENABLE, msr);
 }
+
+int cpu_get_coord_type(void)
+{
+   return HW_ALL;
+}
+
+int cpu_get_min_ratio(void)
+{
+   msr_t msr;
+
+   /* Get bus ratio limits and calculate clock speeds */
+   msr = msr_read(MSR_PLATFORM_INFO);
+
+   return (msr.hi >> 8) & 0xff;/* Max Efficiency Ratio */
+}
+
+int cpu_get_max_ratio(void)
+{
+   u32 ratio_max;
+   msr_t msr;
+
+   if (cpu_config_tdp_levels()) {
+   /* Set max ratio to nominal TDP ratio */
+   msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
+   ratio_max = msr.lo & 0xff;
+   } else {
+   msr = msr_read(MSR_PLATFORM_INFO);
+   /* Max Non-Turbo Ratio */
+   ratio_max = (msr.lo >> 8) & 0xff;
+   }
+
+   return ratio_max;
+}
+
+int cpu_get_bus_clock_khz(void)
+{
+   /*
+* CPU bus clock is set by default here to 100MHz. This function returns
+* the bus clock in KHz.
+*/
+   return INTEL_BCLK_MHZ * 1000;
+}
+
+int cpu_get_power_max(void)
+{
+   int power_unit;
+   msr_t msr;
+
+   msr = msr_read(MSR_PKG_POWER_SKU_UNIT);
+   power_unit = 2 << ((msr.lo & 0xf) - 1);
+   msr = msr_read(MSR_PKG_POWER_SKU);
+
+   return (msr.lo & 0x7fff) * 1000 / power_unit;
+}
+
+int cpu_get_max_turbo_ratio(void)
+{
+   msr_t msr;
+
+   msr = msr_read(MSR_TURBO_RATIO_LIMIT);
+
+   return msr.lo & 0xff;
+}
diff --git a/arch/x86/include/asm/cpu_common.h 
b/arch/x86/include/asm/cpu_common.h
index cdd99a90b76..a7b7112d417 100644
--- a/arch/x86/include/asm/cpu_common.h
+++ b/arch/x86/include/asm/cpu_common.h
@@ -128,4 +128,53 @@ void cpu_set_eist(bool eist_status);
  */
 void cpu_set_p_state_to_turbo_ratio(void);
 
+/**
+ * cpu_get_coord_type() - Get the type of coordination for P-State transition
+ *
+ * See ACPI spec v6.3 section 8.4.6.5 _PSD (P-State Dependency)
+ *
+ * @return HW_ALL (always)
+ */
+int cpu_get_coord_type(void);
+
+/**
+ * cpu_get_min_ratio() - get minimum support frequency ratio for CPU
+ *
+ * @return minimum ratio
+ */
+int cpu_get_min_ratio(void);
+
+/**
+ * cpu_get_max_ratio() - get nominal TDP ration or max non-turbo ratio
+ *
+ * If a nominal TDP ratio is available, it is returned. Otherwise this returns
+ * the  maximum non-turbo frequency ratio for this processor
+ *
+ * @return max ratio
+ */
+int cpu_get_max_ratio(void);
+
+/**
+ * cpu_get_bus_clock_khz() - Get the bus clock frequency in KHz
+ *
+ * This is the value the clock ratio is multiplied with
+ *
+ * @return bus-block frequency in KHz
+ */
+int cpu_get_bus_clock_khz(void);
+
+/**
+ * cpu_get_power_max() - Get maximum CPU TDP
+ *
+ * @return maximum CPU TDP (Thermal-design power) in mW
+ */
+int cpu_get_power_max(void);
+
+/**
+ * cpu_get_max_turbo_ratio() - Get maximum turbo ratio
+ *
+ * @return maximum ratio
+ */
+int cpu_get_max_turbo_ratio(void);
+
 #endif
diff --git a/include/acpi/acpigen.h b/include/acpi/acpigen.h
index 34b3115bc9c..c412898169e 100644
--- a/include/acpi/acpigen.h
+++ b/include/acpi/acpigen.h
@@ -73,6 +73,18 @@ enum {
RETURN_OP   = 0xa4,
 };
 
+/**
+ * enum psd_coord - Coordination types for P-states
+ *
+ * The type of coordination that exists (hardware) or is required (software) as
+ * a result of the underlying hardware dependency
+ */
+enum psd_coord {
+   SW_ALL = 0xfc,
+   SW_ANY = 0xfd,
+   HW_ALL = 0xfe
+};
+
 /**
  * acpigen_get_current() - Get the current ACPI code output pointer
  *
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 27/57] x86: acpi: Add PCT and PTC tables

2020-09-06 Thread Simon Glass
These are needed for the CPU tables. Add them into an x86-specific file
since we do not support them on sandbox, or include tests.

Signed-off-by: Simon Glass 
---

(no changes since v1)

Changes in v1:
- Split PCT and PTC tables into a separate patch

 arch/x86/include/asm/acpigen.h | 35 +
 arch/x86/lib/Makefile  |  2 +-
 arch/x86/lib/acpigen.c | 96 ++
 3 files changed, 132 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/include/asm/acpigen.h
 create mode 100644 arch/x86/lib/acpigen.c

diff --git a/arch/x86/include/asm/acpigen.h b/arch/x86/include/asm/acpigen.h
new file mode 100644
index 000..c531dd61d53
--- /dev/null
+++ b/arch/x86/include/asm/acpigen.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Generation of x86-specific ACPI tables
+ *
+ * Copyright 2020 Google LLC
+ */
+
+#ifndef __ASM_ACPIGEN_H__
+#define __ASM_ACPIGEN_H__
+
+struct acpi_ctx;
+
+/**
+ * acpigen_write_empty_pct() - Write an empty PCT
+ *
+ * See ACPI v6.3 section 8.4.6.1: _PCT (Performance Control)
+ *
+ * This writes an empty table so that CPU performance works as expected
+ *
+ * @ctx: ACPI context pointer
+ */
+void acpigen_write_empty_pct(struct acpi_ctx *ctx);
+
+/**
+ * acpigen_write_empty_ptc() - Write an empty PTC
+ *
+ * See ACPI v6.3 section 8.4.5.1: _PTC (Processor Throttling Control)
+ *
+ * This writes an empty table so that CPU performance works as expected
+ *
+ * @ctx: ACPI context pointer
+ */
+void acpigen_write_empty_ptc(struct acpi_ctx *ctx);
+
+#endif /* __ASM_ACPI_H__ */
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index 1185a88c27c..f04d275dd9a 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -38,7 +38,7 @@ obj-y += sfi.o
 obj-y  += acpi.o
 obj-$(CONFIG_HAVE_ACPI_RESUME) += acpi_s3.o
 ifndef CONFIG_QEMU
-obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o acpigen.o
 endif
 obj-y  += tables.o
 ifndef CONFIG_SPL_BUILD
diff --git a/arch/x86/lib/acpigen.c b/arch/x86/lib/acpigen.c
new file mode 100644
index 000..ea2ec2a9083
--- /dev/null
+++ b/arch/x86/lib/acpigen.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Google LLC
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+void acpigen_write_empty_pct(struct acpi_ctx *ctx)
+{
+   /*
+* Name (_PCT, Package (0x02)
+* {
+*  ResourceTemplate ()
+*  {
+*  Register (FFixedHW,
+*  0x00,   // Bit Width
+*  0x00,   // Bit Offset
+*  0x, // Address
+*  ,)
+*  },
+*
+*  ResourceTemplate ()
+*  {
+*  Register (FFixedHW,
+*  0x00,   // Bit Width
+*  0x00,   // Bit Offset
+*  0x, // Address
+*  ,)
+*  }
+* })
+*/
+   static char stream[] = {
+   /* 0030"0._PCT.," */
+   0x08, 0x5f, 0x50, 0x43, 0x54, 0x12, 0x2c,
+   /* 0038"" */
+   0x02, 0x11, 0x14, 0x0a, 0x11, 0x82, 0x0c, 0x00,
+   /* 0040"" */
+   0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   /* 0048"y..." */
+   0x00, 0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14,
+   /* 0050"" */
+   0x0a, 0x11, 0x82, 0x0c, 0x00, 0x7f, 0x00, 0x00,
+   /* 0058"" */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x79, 0x00
+   };
+   acpigen_emit_stream(ctx, stream, ARRAY_SIZE(stream));
+}
+
+void acpigen_write_empty_ptc(struct acpi_ctx *ctx)
+{
+   /*
+* Name (_PTC, Package (0x02)
+* {
+*  ResourceTemplate ()
+*  {
+*  Register (FFixedHW,
+*  0x00,   // Bit Width
+*  0x00,   // Bit Offset
+*  0x, // Address
+*  ,)
+*  },
+*
+*  ResourceTemplate ()
+*  {
+*  Register (FFixedHW,
+*  0x00,   // Bit Width
+*  0x00,   // Bit Offset
+*  0x, // Address
+*  ,)
+*  }
+* })
+*/
+   struct acpi_gen_regaddr addr = {
+   .space_id= ACPI_ADDRESS_SPACE_FIXED,
+   .bit_width   = 0,
+   .bit_offset  = 0,
+   .access_si

[PATCH v3 30/57] x86: Support Atom SoCs using SWSMISCI rather than the SWSCI

2020-09-06 Thread Simon Glass
Some Atom SoCs use SWSMISCI for SMI control. Add a Kconfig to select this.
It is used on Apollo Lake.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/Kconfig| 6 ++
 arch/x86/cpu/apollolake/Kconfig | 1 +
 2 files changed, 7 insertions(+)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 495629d32ed..eddf2a774ef 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1017,4 +1017,10 @@ config INTEL_GENERIC_WIFI
  network functionality. It is only here to generate the ACPI tables
  required by Linux.
 
+config INTEL_GMA_SWSMISCI
+   bool
+   help
+ Select this option for Atom-based platforms which use the SWSMISCI
+ register (0xe0) rather than the SWSCI register (0xe8).
+
 endmenu
diff --git a/arch/x86/cpu/apollolake/Kconfig b/arch/x86/cpu/apollolake/Kconfig
index 319f12684b7..35a425cd1bc 100644
--- a/arch/x86/cpu/apollolake/Kconfig
+++ b/arch/x86/cpu/apollolake/Kconfig
@@ -17,6 +17,7 @@ config INTEL_APOLLOLAKE
select PCH_SUPPORT
select P2SB
select SMP_AP_WORK
+   select INTEL_GMA_SWSMISCI
select ACPI_GNVS_EXTERNAL
imply ENABLE_MRC_CACHE
imply AHCI_PCI
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v3 22/57] x86: apl: Update iomap for ACPI

2020-09-06 Thread Simon Glass
Add some more definitions to the iomap. These will be used by
ACPI-generation code as well as the device tree.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/include/asm/arch-apollolake/iomap.h | 16 
 1 file changed, 16 insertions(+)

diff --git a/arch/x86/include/asm/arch-apollolake/iomap.h 
b/arch/x86/include/asm/arch-apollolake/iomap.h
index 4ce10170558..21c5f33021a 100644
--- a/arch/x86/include/asm/arch-apollolake/iomap.h
+++ b/arch/x86/include/asm/arch-apollolake/iomap.h
@@ -11,11 +11,27 @@
 
 /* Put p2sb at 0xd000 in TPL */
 #define IOMAP_P2SB_BAR 0xd000
+#define IOMAP_P2SB_SIZE0x1000
 
 #define IOMAP_SPI_BASE 0xfe01
 
 #define IOMAP_ACPI_BASE0x400
 #define IOMAP_ACPI_SIZE0x100
+#define ACPI_BASE_ADDRESS  IOMAP_ACPI_BASE
+
+#define PMC_BAR0   0xfe042000
+
+#define MCH_BASE_ADDRESS   0xfed1
+#define MCH_SIZE   0x8000
+
+#ifdef __ACPI__
+#define HPET_BASE_ADDRESS  0xfed0
+
+#define SRAM_BASE_00xfe90
+#define SRAM_SIZE_0(8 * KiB)
+#define SRAM_BASE_20xfe902000
+#define SRAM_SIZE_2(4 * KiB)
+#endif
 
 /*
  * Use UART2. To use UART1 you need to set '2' to '1', change device tree 
serial
-- 
2.28.0.526.ge36021eeef-goog



  1   2   >