Re: [PATCH] mtd: nand: denali: Add SPL image loader

2022-10-20 Thread Michael Nazzareno Trimarchi
Hi

On Fri, Oct 21, 2022 at 5:26 AM Jagan Teki  wrote:
>
> On Mon, Sep 5, 2022 at 7:44 PM Jit Loon Lim  wrote:
> >
> > From: Tien Fong Chee 
> >
> > Add image loader used by the NAND SPL into the full Denali NAND
> > driver. This allows usage of the full Denali NAND driver in SPL instead
> > of the reduced SPL-only version.
> >
> > Signed-off-by: Tien Fong Chee 
> > Signed-off-by: Jit Loon Lim 
> > ---
>
> + MTD Maintainers

Please take a look of commit 9f6a14c47ff95354185248ea6e7b1c695e64939e
and implement
nand_spl_adjust_offset. I think that same can be used by any cpu that
has enough space
inside the first stage boot.

Michael


Michael


Re: [PATCH] mtd: nand: denali: Add SPL image loader

2022-10-20 Thread Jagan Teki
On Mon, Sep 5, 2022 at 7:44 PM Jit Loon Lim  wrote:
>
> From: Tien Fong Chee 
>
> Add image loader used by the NAND SPL into the full Denali NAND
> driver. This allows usage of the full Denali NAND driver in SPL instead
> of the reduced SPL-only version.
>
> Signed-off-by: Tien Fong Chee 
> Signed-off-by: Jit Loon Lim 
> ---

+ MTD Maintainers


Re: [PATCH] mtd: nand: Allow full NAND framework in SPL

2022-10-20 Thread Jagan Teki
On Mon, Sep 5, 2022 at 7:41 PM Jit Loon Lim  wrote:
>
> From: Tien Fong Chee 
>
> Add configuration option to compile the entire NAND framework into
> U-Boot SPL. This is required by some drivers, like the Denali NAND,
> which use a lot of functionality from the NAND core.
>
> Signed-off-by: Marek Vasut 
> Signed-off-by: Tien Fong Chee 
> Signed-off-by: Jit Loon Lim 
> ---

+ MTD mainatainers


[PATCH] efi_loader: remove CONFIG_EFI_SETUP_EARLY

2022-10-20 Thread AKASHI Takahiro
Since the commit a9bf024b2933 ("efi_loader: disk: a helper function to
create efi_disk objects from udevice"), CONFIG_EFI_SETUP_EARLY option is
by default on and will never be turned off.

So just remove this option.

Signed-off-by: AKASHI Takahiro 
---
 common/board_r.c   |  2 +-
 lib/efi_loader/Kconfig |  5 -
 lib/efi_loader/efi_setup.c | 43 ++
 3 files changed, 12 insertions(+), 38 deletions(-)

diff --git a/common/board_r.c b/common/board_r.c
index 92ca2066ee3a..683c045b617c 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -692,7 +692,7 @@ static init_fnc_t init_sequence_r[] = {
/* initialize higher level parts of CPU like time base and timers */
cpu_init_r,
 #endif
-#ifdef CONFIG_EFI_SETUP_EARLY
+#ifdef CONFIG_EFI_LOADER
efi_init_early,
 #endif
 #ifdef CONFIG_CMD_NAND
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 41756ea53961..7b50f4b38545 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -42,10 +42,6 @@ config CMD_BOOTEFI_BOOTMGR
  via UEFI variables Boot, BootOrder, and BootNext. This enables the
  'bootefi bootmgr' command.
 
-config EFI_SETUP_EARLY
-   bool
-   default y
-
 choice
prompt "Store for non-volatile UEFI variables"
default EFI_VARIABLE_FILE_STORE
@@ -161,7 +157,6 @@ config EFI_IGNORE_OSINDICATIONS
 config EFI_CAPSULE_ON_DISK_EARLY
bool "Initiate capsule-on-disk at U-Boot boottime"
depends on EFI_CAPSULE_ON_DISK
-   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.
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index 9d7189336dc4..af66076bd3d0 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -175,16 +175,15 @@ static efi_status_t efi_init_os_indications(void)
 }
 
 /**
- * __efi_init_early() - handle initialization at early stage
+ * efi_init_early() - handle initialization at early stage
  *
- * This function is called in efi_init_obj_list() only if
- * !CONFIG_EFI_SETUP_EARLY.
+ * expected to be called in board_init_r().
  *
  * Return: status code
  */
-static efi_status_t __efi_init_early(void)
+int efi_init_early(void)
 {
-   efi_status_t ret = EFI_SUCCESS;
+   efi_status_t ret;
 
/* Allow unaligned memory access */
allow_unaligned();
@@ -200,29 +199,15 @@ static efi_status_t __efi_init_early(void)
 
/* Initialize EFI driver uclass */
ret = efi_driver_init();
-out:
-   return ret;
-}
-
-/**
- * efi_init_early() - handle initialization at early stage
- *
- * external version of __efi_init_early(); expected to be called in
- * board_init_r().
- *
- * Return: status code
- */
-int efi_init_early(void)
-{
-   efi_status_t ret;
+   if (ret != EFI_SUCCESS)
+   goto out;
 
-   ret = __efi_init_early();
-   if (ret != EFI_SUCCESS) {
-   /* never re-init UEFI subsystem */
-   efi_obj_list_initialized = ret;
-   return -1;
-   }
return 0;
+out:
+   /* never re-init UEFI subsystem */
+   efi_obj_list_initialized = ret;
+
+   return -1;
 }
 
 /**
@@ -238,12 +223,6 @@ efi_status_t efi_init_obj_list(void)
if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED)
return efi_obj_list_initialized;
 
-   if (!IS_ENABLED(CONFIG_EFI_SETUP_EARLY)) {
-   ret = __efi_init_early();
-   if (ret != EFI_SUCCESS)
-   goto out;
-   }
-
/* Set up console modes */
efi_setup_console_size();
 
-- 
2.37.3



Re: [PATCH v2 00/28] ARM: Add Rockchip RV1126 support

2022-10-20 Thread Jagan Teki
Hi Kever,

On Mon, 17 Oct 2022 at 19:03, Jagan Teki  wrote:
>
> Hi Kever,
>
> On Mon, 17 Oct 2022 at 18:59, Kever Yang  wrote:
> >
> > Hi Jagan,
> >
> >  Could you resend this patch set? There are some merge conflict when
> > I try to apply.
> >
> >  For dts related patch, please add the commit number available on
> > mainline kernel,
> >
> > or else I will  merge other patches except dts.
>
> dts files in the Mainline kernel are holding for the next version.
> Please merge the rest of them. I will wrap and send dts files once I
> send them to Mainline linux.

Any update on this?

Jagan.


Pull request: u-boot-rockchip-20221020

2022-10-20 Thread Kever Yang
Hi Tom,

Please pull the rockchip updates:
- dts update and sync for rk356x, rk3288, rk3399 from Linux;
- Add rk3399 EAIDK-610 board support;
- Update for puma-rk3399 board;
- some fix and typo fix in different drivers;

Gitlab ci:
https://gitlab.denx.de/u-boot/custodians/u-boot-rockchip/pipelines/13856

Thanks,
- Kever

The following changes since commit 8710676635574bb457159fd6fa1c92d065ddb144:


The following changes since commit e2ff1d0fa777b11ad6b26432cb7613ab433b15d6:

  Merge tag 'efi-2023-01-rc1-3' of 
https://source.denx.de/u-boot/custodians/u-boot-efi (2022-10-16 20:23:47 -0400)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-rockchip.git 
tags/u-boot-rockchip-20221020

for you to fetch changes up to 85a8ef1264fca77827f7702594272d17c7c39ce1:

  arm: dts: rockchip: rk356x: sync with Linux 6.0 (2022-10-19 19:30:49 +0800)


Andy Yan (1):
  rockchip: rk3399: Add EAIDK-610 support

FUKAUMI Naoki (1):
  arm: dts: rockchip: rk356x: sync with Linux 6.0

Johan Jonker (4):
  rockchip: phycore_rk3288: remove phycore_init() function
  arm: dts: rockchip: rk3288: move thermal sub nodes to dtsi
  arm: dts: rockchip: update cpu and gpu nodes
  arm: dts: rockchip: rk3288: partial sync from Linux

Quentin Schulz (16):
  rockchip: rk3399: fix incorrect ifdef check on SPL_DM_REGULATOR
  rockchip: rk3399: fix incorrect ifdef check on SPL_GPIO
  rockchip: px30: support debug uart on UART0
  ram: rockchip: fix typo in KConfig option label
  rockchip: puma-rk3399: remove dead code
  rockchip: puma-rk3399: fix boot_targets swap depending on U-Boot proper 
load medium
  rockchip: puma-rk3399: use gpio-hog instead of fixed-regulator for 
enabling eMMC/SPI-NOR
  rockchip: puma-rk3399: allow non-SD-Card-loaded SPL to load U-Boot proper 
from SD-Card
  rockchip: puma-rk3399: remove unused default ENV_OFFSET for SPI flashes
  rockchip: puma-rk3399: load environment from same MMC as used for loading 
U-Boot proper
  rockchip: puma-rk3399: allow loading environment from SPI-NOR flash
  rockchip: puma-rk3399: load environment from same medium as one used to 
load U-Boot proper
  rockchip: puma-rk3399: remove useless CONFIG_SYS_SPI_U_BOOT_OFFS
  rockchip: puma-rk3399: migrate to TPL
  rockchip: puma-rk3399: migrate to u-boot-rockchip.bin
  rockchip: puma-rk3399: migrate to u-boot-rockchip-spi.bin

Simon Glass (2):
  phycore-rk3288: Avoid enabling partition support in SPL
  rockchip: jerry: Enable RESET driver

Xavier Drudis Ferran (1):
  arm: rockchip: rk3399: Program PLL clock for DDR at 50 MHz in documented 
range

 arch/arm/dts/Makefile  |1 +
 arch/arm/dts/rk3288-thermal.dtsi   |   87 -
 arch/arm/dts/rk3288-veyron-jerry.dts   |6 -
 arch/arm/dts/rk3288-veyron.dtsi|4 -
 arch/arm/dts/rk3288.dtsi   |  570 +--
 arch/arm/dts/rk3399-eaidk-610-u-boot.dtsi  |   18 +
 arch/arm/dts/rk3399-eaidk-610.dts  |  939 +++
 arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi|   75 +-
 arch/arm/dts/rk3566.dtsi   |   35 +
 arch/arm/dts/rk3568-evb-u-boot.dtsi|2 +-
 arch/arm/dts/rk3568-pinctrl.dtsi   |9 +
 arch/arm/dts/rk3568.dtsi   |  848 ++
 .../dts/{rk3568-u-boot.dtsi => rk356x-u-boot.dtsi} |7 +-
 arch/arm/dts/rk356x.dtsi   | 1706 
 arch/arm/include/asm/arch-rockchip/cru_px30.h  |   19 +
 arch/arm/mach-rockchip/px30/px30.c |   37 +-
 arch/arm/mach-rockchip/rk3288/Kconfig  |1 -
 arch/arm/mach-rockchip/rk3399/rk3399.c |   67 +-
 board/phytec/phycore_rk3288/phycore-rk3288.c   |   46 -
 board/rockchip/evb_rk3399/MAINTAINERS  |6 +
 board/theobroma-systems/puma_rk3399/Kconfig|3 -
 board/theobroma-systems/puma_rk3399/README |   22 +-
 board/theobroma-systems/puma_rk3399/puma-rk3399.c  |  100 +-
 configs/chromebook_jerry_defconfig |1 +
 configs/eaidk-610-rk3399_defconfig |   61 +
 configs/phycore-rk3288_defconfig   |1 +
 configs/puma-rk3399_defconfig  |   16 +-
 drivers/clk/rockchip/clk_rk3399.c  |2 +-
 drivers/ram/rockchip/Kconfig   |2 +-
 include/dt-bindings/power/rk3568-power.h   |   32 +
 30 files changed, 3631 insertions(+), 1092 deletions(-)
 delete mode 100644 arch/arm/dts/rk3288-thermal.dtsi
 create mode 100644 arch/arm/dts/rk3399-eaidk-610-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3399-eaidk-610.dts
 create mode 100644 arch/arm/dts/rk3566.dtsi
 rename arch/arm/dts/{rk3568-u-boot.dtsi => rk356x-u-boot.dtsi} (94%)
 create mode 10064

Re: [PATCH v2 11/12] rockchip: lion-rk3368: migrate to u-boot-rockchip.bin

2022-10-20 Thread Kever Yang



On 2022/10/19 22:10, quentin.sch...@theobroma-systems.com wrote:

Hi Kever,

On 10/19/22 2:47 PM, Kever Yang  wrote:

Hi Quentin,

 This is report by the  denx ci system:

https://urldefense.proofpoint.com/v2/url?u=https-3A__source.denx.de_u-2Dboot_custodians_u-2Dboot-2Drockchip_-2D_jobs_515913=DwIDaQ=_sEr5x9kUWhuk4_nFwjJtA=LYjLexDn7rXIzVmkNPvw5ymA1XTSqHGq8yBP6m6qZZ4njZguQhZhkI_-172IIy1t=jlsoDVbl-1nmumJr2buEbP1CHgfZWWOLR9Xh-ycxj-II1AQbLWozSLgCKBSYz-3o=dMfyQSyv3NY0elXedC3GxMELp8oSMp8hCy5WZniPV2U= 



I cannot see this page, probably a custodian account on that gitlab 
instance is required?



 And I can reproduce it with buildman sheep-rk3568



I can reproduce by building for sheep-3368_defconfig indeed.

CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR is not defined for this board 
and it is used in the lion dts.


Since the Lion dts is built for any RK3368-based board, it needs to be 
defined for all boards based on RK3368 which is not the case for the 
Sheep board.


The lion dts is only used for this board, the sheep board have its own 
dts, I didn't see any sheep dts include lion dts, but it's strange why 
the sheep-rk3368 fail with lion change.





Was it a deliberate choice to build all DTS from a specific SoC, 
whatever the board you're building for?


I would have imagined that using CONFIG_TARGET_LION_RK3368 instead of 
CONFIG_ROCKCHIP_RK3368 in arch/arm/dts/Makefile for deciding whether 
to build a device tree would make more sense?


For the time being, please just drop this patch, we don't really need 
it at the moment so I'll have a look on how to do this properly when I 
have time.


OK, you  can send the follow up patch if we figure out the reason.


Thanks,

- Kever



Thanks!
Quentin



Thanks,

- Kever

On 2022/10/19 20:11, Quentin Schulz wrote:
> Hi Kever,
>
> On 10/19/22 13:28, Kever Yang wrote:
>> Hi Quentin,
>>
>>  I got below error when apply this patch, could you help to check
>>
>> +Error: arch/arm/dts/rk3368-lion-haikou-u-boot.dtsi:44.16-17 
syntax >> error

>> +FATAL ERROR: Unable to parse input tree
>> +make[3]: *** [arch/arm/dts/rk3368-lion-haikou.dtb] Error 1
>> +make[2]: *** [arch-dtbs] Error 2
>>
>
> Did you run make lion-rk3368_defconfig before trying to compile the 
DTS?

>
> I ran:
> ```
> git checkout 3724ddf157
> b4 shazam --add-link --add-my-sob > 
https://urldefense.proofpoint.com/v2/url?u=https-3A__lore.kernel.org_u-2Dboot_20220915091432.789294-2D1-2Dfoss-2Buboot-400leil.net_=DwIDaQ=_sEr5x9kUWhuk4_nFwjJtA=LYjLexDn7rXIzVmkNPvw5ymA1XTSqHGq8yBP6m6qZZ4njZguQhZhkI_-172IIy1t=jlsoDVbl-1nmumJr2buEbP1CHgfZWWOLR9Xh-ycxj-II1AQbLWozSLgCKBSYz-3o=lpPi8rny7_X2xST4eJ40go_Uv41ZYqpuCeU46CpJCz4= 
make CROSS_COMPILE="ccache aarch64-linux-gnu-" lion-rk3368_defconfig

> make CROSS_COMPILE="ccache aarch64-linux-gnu-" j`nproc`
> ```
> and it compiled without any problem.
>
> Cheers,
> Quentin



[PATCH v3 16/43] disk: Rename block_dev to desc

2022-10-20 Thread Simon Glass
The use of 'block_dev' in this context is confusing, since it is not a
pointer to a device, just to some information about it. Rename this to
'desc', as is more commonly used, since it is a block descriptor.

Signed-off-by: Simon Glass 
Acked-by: Heinrich Schuchardt 
---

(no changes since v2)

Changes in v2:
- Add new patch to rename block_dev to desc in disc-uclass.c

 disk/disk-uclass.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index 3bfb828044c..d32747e2242 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -151,34 +151,34 @@ U_BOOT_DRIVER(blk_partition) = {
  */
 static struct blk_desc *dev_get_blk(struct udevice *dev)
 {
-   struct blk_desc *block_dev;
+   struct blk_desc *desc;
 
switch (device_get_uclass_id(dev)) {
/*
 * We won't support UCLASS_BLK with dev_* interfaces.
 */
case UCLASS_PARTITION:
-   block_dev = dev_get_uclass_plat(dev_get_parent(dev));
+   desc = dev_get_uclass_plat(dev_get_parent(dev));
break;
default:
-   block_dev = NULL;
+   desc = NULL;
break;
}
 
-   return block_dev;
+   return desc;
 }
 
 unsigned long disk_blk_read(struct udevice *dev, lbaint_t start,
lbaint_t blkcnt, void *buffer)
 {
-   struct blk_desc *block_dev;
+   struct blk_desc *desc;
const struct blk_ops *ops;
struct disk_part *part;
lbaint_t start_in_disk;
ulong blks_read;
 
-   block_dev = dev_get_blk(dev);
-   if (!block_dev)
+   desc = dev_get_blk(dev);
+   if (!desc)
return -ENOSYS;
 
ops = blk_get_ops(dev);
@@ -191,13 +191,13 @@ unsigned long disk_blk_read(struct udevice *dev, lbaint_t 
start,
start_in_disk += part->gpt_part_info.start;
}
 
-   if (blkcache_read(block_dev->uclass_id, block_dev->devnum,
- start_in_disk, blkcnt, block_dev->blksz, buffer))
+   if (blkcache_read(desc->uclass_id, desc->devnum, start_in_disk, blkcnt,
+ desc->blksz, buffer))
return blkcnt;
blks_read = ops->read(dev, start, blkcnt, buffer);
if (blks_read == blkcnt)
-   blkcache_fill(block_dev->uclass_id, block_dev->devnum,
- start_in_disk, blkcnt, block_dev->blksz, buffer);
+   blkcache_fill(desc->uclass_id, desc->devnum, start_in_disk,
+ blkcnt, desc->blksz, buffer);
 
return blks_read;
 }
@@ -205,18 +205,18 @@ unsigned long disk_blk_read(struct udevice *dev, lbaint_t 
start,
 unsigned long disk_blk_write(struct udevice *dev, lbaint_t start,
 lbaint_t blkcnt, const void *buffer)
 {
-   struct blk_desc *block_dev;
+   struct blk_desc *desc;
const struct blk_ops *ops;
 
-   block_dev = dev_get_blk(dev);
-   if (!block_dev)
+   desc = dev_get_blk(dev);
+   if (!desc)
return -ENOSYS;
 
ops = blk_get_ops(dev);
if (!ops->write)
return -ENOSYS;
 
-   blkcache_invalidate(block_dev->uclass_id, block_dev->devnum);
+   blkcache_invalidate(desc->uclass_id, desc->devnum);
 
return ops->write(dev, start, blkcnt, buffer);
 }
@@ -224,18 +224,18 @@ unsigned long disk_blk_write(struct udevice *dev, 
lbaint_t start,
 unsigned long disk_blk_erase(struct udevice *dev, lbaint_t start,
 lbaint_t blkcnt)
 {
-   struct blk_desc *block_dev;
+   struct blk_desc *desc;
const struct blk_ops *ops;
 
-   block_dev = dev_get_blk(dev);
-   if (!block_dev)
+   desc = dev_get_blk(dev);
+   if (!desc)
return -ENOSYS;
 
ops = blk_get_ops(dev);
if (!ops->erase)
return -ENOSYS;
 
-   blkcache_invalidate(block_dev->uclass_id, block_dev->devnum);
+   blkcache_invalidate(desc->uclass_id, desc->devnum);
 
return ops->erase(dev, start, blkcnt);
 }
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 15/43] disk: Rename block functions

2022-10-20 Thread Simon Glass
Use the uclass type as the first part of the function name, to be
consistent with the methods in other block drivers.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Add comments to the renamed functions

Changes in v2:
- Add new patch to rename block functions

 disk/disk-uclass.c| 24 +++---
 include/part.h| 42 +--
 lib/efi_loader/efi_disk.c |  6 --
 3 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index 551f8b1dca4..3bfb828044c 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -65,7 +65,7 @@ int part_create_block_devices(struct udevice *blk_dev)
return 0;
 }
 
-static ulong blk_part_read(struct udevice *dev, lbaint_t start,
+static ulong part_blk_read(struct udevice *dev, lbaint_t start,
   lbaint_t blkcnt, void *buffer)
 {
struct udevice *parent;
@@ -88,7 +88,7 @@ static ulong blk_part_read(struct udevice *dev, lbaint_t 
start,
return ops->read(parent, start, blkcnt, buffer);
 }
 
-static ulong blk_part_write(struct udevice *dev, lbaint_t start,
+static ulong part_blk_write(struct udevice *dev, lbaint_t start,
lbaint_t blkcnt, const void *buffer)
 {
struct udevice *parent;
@@ -111,7 +111,7 @@ static ulong blk_part_write(struct udevice *dev, lbaint_t 
start,
return ops->write(parent, start, blkcnt, buffer);
 }
 
-static ulong blk_part_erase(struct udevice *dev, lbaint_t start,
+static ulong part_blk_erase(struct udevice *dev, lbaint_t start,
lbaint_t blkcnt)
 {
struct udevice *parent;
@@ -135,9 +135,9 @@ static ulong blk_part_erase(struct udevice *dev, lbaint_t 
start,
 }
 
 static const struct blk_ops blk_part_ops = {
-   .read   = blk_part_read,
-   .write  = blk_part_write,
-   .erase  = blk_part_erase,
+   .read   = part_blk_read,
+   .write  = part_blk_write,
+   .erase  = part_blk_erase,
 };
 
 U_BOOT_DRIVER(blk_partition) = {
@@ -168,8 +168,8 @@ static struct blk_desc *dev_get_blk(struct udevice *dev)
return block_dev;
 }
 
-unsigned long dev_read(struct udevice *dev, lbaint_t start,
-  lbaint_t blkcnt, void *buffer)
+unsigned long disk_blk_read(struct udevice *dev, lbaint_t start,
+   lbaint_t blkcnt, void *buffer)
 {
struct blk_desc *block_dev;
const struct blk_ops *ops;
@@ -202,8 +202,8 @@ unsigned long dev_read(struct udevice *dev, lbaint_t start,
return blks_read;
 }
 
-unsigned long dev_write(struct udevice *dev, lbaint_t start,
-   lbaint_t blkcnt, const void *buffer)
+unsigned long disk_blk_write(struct udevice *dev, lbaint_t start,
+lbaint_t blkcnt, const void *buffer)
 {
struct blk_desc *block_dev;
const struct blk_ops *ops;
@@ -221,8 +221,8 @@ unsigned long dev_write(struct udevice *dev, lbaint_t start,
return ops->write(dev, start, blkcnt, buffer);
 }
 
-unsigned long dev_erase(struct udevice *dev, lbaint_t start,
-   lbaint_t blkcnt)
+unsigned long disk_blk_erase(struct udevice *dev, lbaint_t start,
+lbaint_t blkcnt)
 {
struct blk_desc *block_dev;
const struct blk_ops *ops;
diff --git a/include/part.h b/include/part.h
index 6f604e7315a..807370d9429 100644
--- a/include/part.h
+++ b/include/part.h
@@ -313,12 +313,42 @@ struct udevice;
  */
 int part_create_block_devices(struct udevice *blk_dev);
 
-unsigned long dev_read(struct udevice *dev, lbaint_t start,
-  lbaint_t blkcnt, void *buffer);
-unsigned long dev_write(struct udevice *dev, lbaint_t start,
-   lbaint_t blkcnt, const void *buffer);
-unsigned long dev_erase(struct udevice *dev, lbaint_t start,
-   lbaint_t blkcnt);
+/**
+ * disk_blk_read() - read blocks from a disk partition
+ *
+ * @dev:   Device to read from (UCLASS_PARTITION)
+ * @start: Start block number to read in the partition (0=first)
+ * @blkcnt:Number of blocks to read
+ * @buffer:Destination buffer for data read
+ * Returns: number of blocks read, or -ve error number (see the
+ * IS_ERR_VALUE() macro
+ */
+ulong disk_blk_read(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
+   void *buffer);
+
+/**
+ * disk_blk_write() - write to a disk partition
+ *
+ * @dev:   Device to write to (UCLASS_PARTITION)
+ * @start: Start block number to write in the partition (0=first)
+ * @blkcnt:Number of blocks to write
+ * @buffer:Source buffer for data to write
+ * Returns: number of blocks written, or -ve error number (see the
+ * IS_ERR_VALUE() macro
+ */
+ulong disk_blk_write(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
+const void *buffer);
+
+/**
+ * disk_blk_erase() - erase a section of a disk partition
+ *
+ * @dev:   Device to 

[PATCH v3 25/43] sandbox: Add a way to specify the sandbox executable

2022-10-20 Thread Simon Glass
At present the sandbox executable is assumed to be arg[0] but this only
works for a single jump (e.g. from SPL to U-Boot). Add a new arg to solve
this issue, along with a detailed comment.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/sandbox/cpu/start.c | 30 ++
 arch/sandbox/include/asm/state.h |  3 ++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index 642be164a39..622df41f54c 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -244,6 +244,36 @@ static int sandbox_cmdline_cb_jump(struct sandbox_state 
*state,
 }
 SANDBOX_CMDLINE_OPT_SHORT(jump, 'j', 1, "Jumped from previous U-Boot");
 
+static int sandbox_cmdline_cb_program(struct sandbox_state *state,
+ const char *arg)
+{
+   /*
+* Record the program name to use when jumping to future phases. This
+* is the original executable which holds all the phases. We need to
+* use this instead of argv[0] since each phase is started by
+* extracting a particular binary from the full program, then running
+* it. Therefore in that binary, argv[0] contains only the
+* current-phase executable.
+*
+* For example, sandbox TPL may be started using image file:
+*
+* ./image.bin
+*
+* but then TPL needs to run VPL, which it does by extracting the VPL
+* image from the image.bin file.
+*
+*./temp-vpl
+*
+* When VPL runs it needs access to the original image.bin so it can
+* extract the next phase (SPL). This works if we use '-f image.bin'
+* when starting the original image.bin file.
+*/
+   state->prog_fname = arg;
+
+   return 0;
+}
+SANDBOX_CMDLINE_OPT_SHORT(program, 'p', 1, "U-Boot program name");
+
 static int sandbox_cmdline_cb_memory(struct sandbox_state *state,
 const char *arg)
 {
diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h
index fd42daad51c..49ea483d332 100644
--- a/arch/sandbox/include/asm/state.h
+++ b/arch/sandbox/include/asm/state.h
@@ -71,7 +71,8 @@ struct sandbox_state {
const char *parse_err;  /* Error to report from parsing */
int argc;   /* Program arguments */
char **argv;/* Command line arguments */
-   const char *jumped_fname;   /* Jumped from previous U_Boot */
+   const char *jumped_fname;   /* Jumped from previous U-Boot */
+   const char *prog_fname; /* U-Boot executable filename */
uint8_t *ram_buf;   /* Emulated RAM buffer */
unsigned long ram_size; /* Size of RAM buffer */
const char *ram_buf_fname;  /* Filename to use for RAM buffer */
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 43/43] vbe: Add a test for the VBE flow into U-Boot proper

2022-10-20 Thread Simon Glass
Add a test which checks that VBE boots correctly from TPL through to
U-Boot proper.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Drop patch 'rsa: Avoid warning in padding_pss_verify()'

 arch/sandbox/dts/test.dts | 37 ++
 test/py/tests/test_vbe_vpl.py | 38 +++
 2 files changed, 75 insertions(+)
 create mode 100644 test/py/tests/test_vbe_vpl.py

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 09956ad7f97..82fff688e81 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -37,6 +37,8 @@
i2c0 = "/i2c@0";
mmc0 = "/mmc0";
mmc1 = "/mmc1";
+   mmc2 = "/mmc2";
+   mmc3 = "/mmc3";
pci0 = 
pci1 = 
pci2 = 
@@ -92,6 +94,11 @@
compatible = "u-boot,distro-efi";
};
 
+   /*
+* This is used for the VBE OS-request tests. A FAT filesystem
+* created in a partition with the VBE information appearing
+* before the parititon starts
+*/
firmware0 {
u-boot,dm-vpl;
compatible = "fwupd,vbe-simple";
@@ -104,6 +111,28 @@
version-offset = <0x800>;
version-size = <0x100>;
};
+
+   /*
+* This is used for the VBE VPL tests. The MMC device holds the
+* binman image.bin file. The test progresses through each phase
+* of U-Boot, loading each in turn from MMC.
+*
+* Note that the test enables this node (and mmc3) before
+* running U-Boot
+*/
+   firmware1 {
+   u-boot,dm-vpl;
+   status = "disabled";
+   compatible = "fwupd,vbe-simple";
+   storage = "mmc3";
+   skip-offset = <0x40>;
+   area-start = <0>;
+   area-size = <0xe0>;
+   state-offset = <0xdffc00>;
+   state-size = <0x40>;
+   version-offset = <0xdffe00>;
+   version-size = <0x100>;
+   };
};
 
fuzzing-engine {
@@ -972,6 +1001,14 @@
compatible = "sandbox,mmc";
};
 
+   /* This is used for VBE VPL tests */
+   mmc3 {
+   status = "disabled";
+   compatible = "sandbox,mmc";
+   filename = "image.bin";
+   non-removable;
+   };
+
pch {
compatible = "sandbox,pch";
};
diff --git a/test/py/tests/test_vbe_vpl.py b/test/py/tests/test_vbe_vpl.py
new file mode 100644
index 000..d1c9d0548ae
--- /dev/null
+++ b/test/py/tests/test_vbe_vpl.py
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2022 Google LLC
+#
+# Test addition of VBE
+
+import os
+
+import pytest
+import u_boot_utils
+
+@pytest.mark.boardspec('sandbox_vpl')
+@pytest.mark.requiredtool('dtc')
+def test_vbe_vpl(u_boot_console):
+cons = u_boot_console
+#cmd = [cons.config.build_dir + fname, '-v']
+ram = os.path.join(cons.config.build_dir, 'ram.bin')
+fdt = os.path.join(cons.config.build_dir, 'arch/sandbox/dts/test.dtb')
+
+# Enable firmware1 and the mmc that it uses. These are needed for the full
+# VBE flow.
+u_boot_utils.run_and_log(
+cons, f'fdtput -t s {fdt} /bootstd/firmware0 status disabled')
+u_boot_utils.run_and_log(
+cons, f'fdtput -t s {fdt} /bootstd/firmware1 status okay')
+u_boot_utils.run_and_log(
+cons, f'fdtput -t s {fdt} /mmc3 status okay')
+
+# Remove any existing RAM file, so we don't have old data present
+if os.path.exists(ram):
+os.remove(ram)
+flags = ['-p', os.path.join(cons.config.build_dir, 'image.bin'), '-w',
+ '-s', 'state.dtb']
+cons.restart_uboot_with_flags(flags)
+
+# Make sure that VBE was used in both VPL (to load SPL) and SPL (to load
+# U-Boot
+output = cons.run_command('vbe state')
+assert output == 'Phases: VPL SPL'
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 37/43] vbe: Add info about the VBE device to the fwupd node

2022-10-20 Thread Simon Glass
At present we put the driver in the /chosen node in U-Boot. This is a bit
strange, since U-Boot doesn't normally use that node itself. It is better
to put it under the bootstd node.

To make this work we need to copy create the node under /chosen when
fixing up the device tree. Copy over all the properties so that fwupd
knows what to do.

Update the sandbox device tree accordingly.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/sandbox/dts/test.dts | 29 ++---
 boot/vbe_simple_os.c  | 26 ++
 test/boot/vbe_simple.c|  7 ++-
 3 files changed, 38 insertions(+), 24 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index b853e13f922..eed72cb71d8 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -78,6 +78,7 @@
};
 
bootstd {
+   u-boot,dm-vpl;
compatible = "u-boot,boot-std";
 
filename-prefixes = "/", "/boot/";
@@ -90,6 +91,19 @@
efi {
compatible = "u-boot,distro-efi";
};
+
+   firmware0 {
+   u-boot,dm-vpl;
+   compatible = "fwupd,vbe-simple";
+   storage = "mmc1";
+   skip-offset = <0x200>;
+   area-start = <0x400>;
+   area-size = <0x1000>;
+   state-offset = <0x400>;
+   state-size = <0x40>;
+   version-offset = <0x800>;
+   version-size = <0x100>;
+   };
};
 
fuzzing-engine {
@@ -1398,21 +1412,6 @@
compatible = "denx,u-boot-fdt-test";
reg = <9 1>;
};
-
-   fwupd {
-   compatible = "simple-bus";
-   firmware0 {
-   compatible = "fwupd,vbe-simple";
-   storage = "mmc1";
-   area-start = <0x400>;
-   area-size = <0x1000>;
-   skip-offset = <0x200>;
-   state-offset = <0x400>;
-   state-size = <0x40>;
-   version-offset = <0x800>;
-   version-size = <0x100>;
-   };
-   };
};
 
translation-test@8000 {
diff --git a/boot/vbe_simple_os.c b/boot/vbe_simple_os.c
index 87778bba97e..b2041a95a30 100644
--- a/boot/vbe_simple_os.c
+++ b/boot/vbe_simple_os.c
@@ -62,24 +62,34 @@ static int bootmeth_vbe_simple_ft_fixup(void *ctx, struct 
event *event)
 */
for (vbe_find_first_device(); dev; vbe_find_next_device()) {
struct simple_state state;
-   ofnode node, subnode;
+   ofnode node, subnode, chosen;
int ret;
 
if (strcmp("vbe_simple", dev->driver->name))
continue;
 
-   /* Check if there is a node to fix up */
-   node = oftree_path(tree, "/chosen/fwupd");
-   if (!ofnode_valid(node))
-   continue;
-   subnode = ofnode_find_subnode(node, dev->name);
-   if (!ofnode_valid(subnode))
+   /* Check if there is a node to fix up, adding if not */
+   chosen = oftree_path(tree, "/chosen");
+   if (!ofnode_valid(chosen))
continue;
+   ret = ofnode_add_subnode(chosen, "fwupd", );
+   if (ret && ret != -EEXIST)
+   return log_msg_ret("fwu", ret);
+
+   ret = ofnode_add_subnode(node, dev->name, );
+   if (ret && ret != -EEXIST)
+   return log_msg_ret("dev", ret);
 
-   log_debug("Fixing up: %s\n", dev->name);
ret = device_probe(dev);
if (ret)
return log_msg_ret("probe", ret);
+
+   /* Copy over the vbe properties for fwupd */
+   log_debug("Fixing up: %s\n", dev->name);
+   ret = ofnode_copy_props(dev_ofnode(dev), subnode);
+   if (ret)
+   return log_msg_ret("cp", ret);
+
ret = vbe_simple_read_state(dev, );
if (ret)
return log_msg_ret("read", ret);
diff --git a/test/boot/vbe_simple.c b/test/boot/vbe_simple.c
index a50785dbbf6..5e61840652c 100644
--- a/test/boot/vbe_simple.c
+++ b/test/boot/vbe_simple.c
@@ -16,7 +16,12 @@
 #include 
 #include "bootstd_common.h"
 
-/* Basic test of reading nvdata and updating a fwupd node in the device tree */
+/*
+ * Basic test of reading nvdata and updating a fwupd node in the device tree
+ *
+ * This sets up its own VBE info in the device, using bootstd_setup_for_tests()
+ * then does a VBE 

[PATCH v3 26/43] image: Add the concept of a phase to FIT

2022-10-20 Thread Simon Glass
We want to be able to mark an image as related to a phase, so we can
easily load all the images for SPL or for U-Boot proper.

Add this to the FIT specification, along with some access functions.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Attach the phase to the image node instead of the configuration node
- Update the documentation too

 boot/image.c  | 18 +++
 doc/uImage.FIT/source_file_format.txt |  3 ++
 include/image.h   | 74 ++-
 test/boot/Makefile|  1 +
 test/boot/image.c | 36 +
 5 files changed, 130 insertions(+), 2 deletions(-)
 create mode 100644 test/boot/image.c

diff --git a/boot/image.c b/boot/image.c
index 9f95b3260a8..b33d1dfc6b3 100644
--- a/boot/image.c
+++ b/boot/image.c
@@ -194,6 +194,13 @@ static const table_entry_t uimage_comp[] = {
{   -1, "", "", },
 };
 
+static const table_entry_t uimage_phase[] = {
+   {   IH_PHASE_NONE,  "none", "any",  },
+   {   IH_PHASE_U_BOOT, "u-boot",  "U-Boot phase", },
+   {   IH_PHASE_SPL,   "spl",  "SPL Phase",},
+   {   -1, "", "", },
+};
+
 struct table_info {
const char *desc;
int count;
@@ -215,6 +222,7 @@ static const struct table_info table_info[IH_COUNT] = {
{ "compression", IH_COMP_COUNT, uimage_comp },
{ "operating system", IH_OS_COUNT, uimage_os },
{ "image type", IH_TYPE_COUNT, uimage_type },
+   { "phase", IH_PHASE_COUNT, uimage_phase },
 };
 
 /*/
@@ -656,6 +664,11 @@ const char *genimg_get_comp_name(uint8_t comp)
comp));
 }
 
+const char *genimg_get_phase_name(enum image_phase_t phase)
+{
+   return get_table_entry_name(uimage_phase, "Unknown Phase", phase);
+}
+
 static const char *genimg_get_short_name(const table_entry_t *table, int val)
 {
table = get_table_entry(table, val);
@@ -731,3 +744,8 @@ int genimg_get_comp_id(const char *name)
 {
return (get_table_entry_id(uimage_comp, "Compression", name));
 }
+
+int genimg_get_phase_id(const char *name)
+{
+   return get_table_entry_id(uimage_phase, "Phase", name);
+}
diff --git a/doc/uImage.FIT/source_file_format.txt 
b/doc/uImage.FIT/source_file_format.txt
index 0a03c942bda..4640e38e3cc 100644
--- a/doc/uImage.FIT/source_file_format.txt
+++ b/doc/uImage.FIT/source_file_format.txt
@@ -190,6 +190,9 @@ the '/images' node should have the following layout:
 Xilinx Zynq UltraScale+ (ZymqMP) device.
 "u-boot,zynqmp-fpga-enc" - encrypted FPGA bitstream for Xilinx Zynq
 UltraScale+ (ZynqMP) device.
+  - phase : U-Boot phase for which the image is intended.
+"spl" - image is an SPL image
+"u-boot" - image is a U-Boot image
 
   Optional nodes:
   - hash-1 : Each hash sub-node represents separate hash or checksum
diff --git a/include/image.h b/include/image.h
index 92efec0f04b..7c3dcc407c0 100644
--- a/include/image.h
+++ b/include/image.h
@@ -58,6 +58,7 @@ enum ih_category {
IH_COMP,
IH_OS,
IH_TYPE,
+   IH_PHASE,
 
IH_COUNT,
 };
@@ -184,8 +185,7 @@ enum {
  * New IDs *MUST* be appended at the end of the list and *NEVER*
  * inserted for backward compatibility.
  */
-
-enum {
+enum image_type_t {
IH_TYPE_INVALID = 0,/* Invalid Image*/
IH_TYPE_STANDALONE, /* Standalone Program   */
IH_TYPE_KERNEL, /* OS Kernel Image  */
@@ -252,6 +252,59 @@ enum {
IH_COMP_COUNT,
 };
 
+/**
+ * Phases - images intended for particular U-Boot phases (SPL, etc.)
+ *
+ * @IH_PHASE_NONE: No phase information, can be loaded by any phase
+ * @IH_PHASE_U_BOOT: Only for U-Boot proper
+ * @IH_PHASE_SPL: Only for SPL
+ */
+enum image_phase_t {
+   IH_PHASE_NONE   = 0,
+   IH_PHASE_U_BOOT,
+   IH_PHASE_SPL,
+
+   IH_PHASE_COUNT,
+};
+
+#define IMAGE_PHASE_SHIFT  8
+#define IMAGE_PHASE_MASK   (0xff << IMAGE_PHASE_SHIFT)
+#define IMAGE_TYPE_MASK0xff
+
+/**
+ * image_ph() - build a composite value combining and type
+ *
+ * @phase: Image phase value
+ * @type: Image type value
+ * Returns: Composite value containing both
+ */
+static inline int image_ph(enum image_phase_t phase, enum image_type_t type)
+{
+   return type | (phase << IMAGE_PHASE_SHIFT);
+}
+
+/**
+ * image_ph_phase() - obtain the phase from a composite phase/type value
+ *
+ * @image_ph_type: Composite value to convert
+ * Returns: Phase value taken from the composite value
+ */
+static inline int image_ph_phase(int image_ph_type)
+{
+   return (image_ph_type & IMAGE_PHASE_MASK) >> IMAGE_PHASE_SHIFT;
+}
+
+/**
+ * image_ph_type() - obtain the type from a composite 

[PATCH v3 32/43] vbe: Support selecting operations by SPL phase

2022-10-20 Thread Simon Glass
VBE supports booting firmware during the SPL phases, i.e. so that VPL can
start SPL and SPL can start U-Boot.

It also supports booting an OS, when in U-Boot.

As a first step towards these features, add functions to indicate the
current VBE phase. The firmware selection is done in VPL and the OS
selection is done in U-Boot proper.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/vbe.h | 28 
 1 file changed, 28 insertions(+)

diff --git a/include/vbe.h b/include/vbe.h
index b83f6f0c519..ece2697b5dc 100644
--- a/include/vbe.h
+++ b/include/vbe.h
@@ -10,6 +10,34 @@
 #ifndef __VBE_H
 #define __VBE_H
 
+/**
+ * enum vbe_phase_t - current phase of VBE
+ *
+ * VBE operates in two distinct phases. In VPL it has to choose which firmware
+ * to run (SPL, U-Boot, OP-TEE, etc.). It then carries on running until it gets
+ * to U-Boot, where it decides which OS to run
+ *
+ * @VBE_PHASE_FIRMWARE: Selecting the firmware to run
+ * @VBE_PHASE_OS: Selecting the Operating System to run
+ */
+enum vbe_phase_t {
+   VBE_PHASE_FIRMWARE,
+   VBE_PHASE_OS,
+};
+
+/**
+ * vbe_phase() - get current VBE phase
+ *
+ * Returns: Current VBE phase
+ */
+static inline enum vbe_phase_t vbe_phase(void)
+{
+   if (IS_ENABLED(CONFIG_SPL_BUILD))
+   return VBE_PHASE_FIRMWARE;
+
+   return VBE_PHASE_OS;
+}
+
 /**
  * vbe_list() - List the VBE bootmeths
  *
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 42/43] vbe: Add a command to show the VBE state

2022-10-20 Thread Simon Glass
Add a VBE comment which shows the current state. Currently this is just
the phases which booted via VBE.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/vbe.c | 31 ++-
 include/spl.h |  2 ++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/cmd/vbe.c b/cmd/vbe.c
index a5737edc047..befaf07c64d 100644
--- a/cmd/vbe.c
+++ b/cmd/vbe.c
@@ -7,9 +7,11 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 static int do_vbe_list(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -74,14 +76,41 @@ static int do_vbe_info(struct cmd_tbl *cmdtp, int flag, int 
argc,
return 0;
 }
 
+static int do_vbe_state(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[])
+{
+   struct vbe_handoff *handoff;
+   int i;
+
+   handoff = bloblist_find(BLOBLISTT_VBE, sizeof(struct vbe_handoff));
+   if (!handoff) {
+   printf("No VBE state\n");
+   return CMD_RET_FAILURE;
+   }
+
+   printf("Phases:");
+   for (i = PHASE_NONE; i < PHASE_COUNT; i++) {
+   if (handoff->phases & (1 << i))
+   printf(" %s", spl_phase_name(i));
+
+   }
+   if (!handoff->phases)
+   printf(" (none)");
+   printf("\n");
+
+   return 0;
+}
+
 #ifdef CONFIG_SYS_LONGHELP
 static char vbe_help_text[] =
"list   - list VBE bootmeths\n"
"vbe select - select a VBE bootmeth by sequence or name\n"
-   "vbe info   - show information about a VBE bootmeth";
+   "vbe info   - show information about a VBE bootmeth\n"
+   "vbe state  - show VBE state";
 #endif
 
 U_BOOT_CMD_WITH_SUBCMDS(vbe, "Verified Boot for Embedded", vbe_help_text,
U_BOOT_SUBCMD_MKENT(list, 1, 1, do_vbe_list),
U_BOOT_SUBCMD_MKENT(select, 2, 1, do_vbe_select),
+   U_BOOT_SUBCMD_MKENT(state, 2, 1, do_vbe_state),
U_BOOT_SUBCMD_MKENT(info, 2, 1, do_vbe_info));
diff --git a/include/spl.h b/include/spl.h
index e407c7fe55b..ab62813c4fe 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -66,6 +66,8 @@ enum u_boot_phase {
PHASE_SPL,  /* Running in SPL */
PHASE_BOARD_F,  /* Running in U-Boot before relocation */
PHASE_BOARD_R,  /* Running in U-Boot after relocation */
+
+   PHASE_COUNT,
 };
 
 /**
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 34/43] vbe: Move OS implementation into a separate file

2022-10-20 Thread Simon Glass
Move this into its own file so it can be built only by U-Boot proper.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/Makefile|   1 +
 boot/vbe_simple.c| 102 +--
 boot/vbe_simple.h|  34 +++
 boot/vbe_simple_os.c |  89 +++
 test/py/tests/test_event_dump.py |   1 -
 5 files changed, 126 insertions(+), 101 deletions(-)
 create mode 100644 boot/vbe_simple_os.c

diff --git a/boot/Makefile b/boot/Makefile
index e5c27900ea7..f0c31549213 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -50,3 +50,4 @@ endif
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += vbe.o vbe_request.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_FW) += vbe_simple_fw.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_OS) += vbe_simple_os.o
diff --git a/boot/vbe_simple.c b/boot/vbe_simple.c
index 1ccd416e4bb..59676d8613f 100644
--- a/boot/vbe_simple.c
+++ b/boot/vbe_simple.c
@@ -17,37 +17,11 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include "vbe_simple.h"
 
-enum {
-   MAX_VERSION_LEN = 256,
-
-   NVD_HDR_VER_SHIFT   = 0,
-   NVD_HDR_VER_MASK= 0xf,
-   NVD_HDR_SIZE_SHIFT  = 4,
-   NVD_HDR_SIZE_MASK   = 0xf << NVD_HDR_SIZE_SHIFT,
-
-   /* Firmware key-version is in the top 16 bits of fw_ver */
-   FWVER_KEY_SHIFT = 16,
-   FWVER_FW_MASK   = 0x,
-
-   NVD_HDR_VER_CUR = 1,/* current version */
-};
-
-/** struct simple_state - state information read from media
- *
- * @fw_version: Firmware version string
- * @fw_vernum: Firmware version number
- */
-struct simple_state {
-   char fw_version[MAX_VERSION_LEN];
-   u32 fw_vernum;
-};
-
 /** struct simple_nvdata - storage format for non-volatile data */
 struct simple_nvdata {
u8 crc8;
@@ -116,7 +90,7 @@ static int simple_read_nvdata(struct udevice *dev, struct 
blk_desc *desc,
return 0;
 }
 
-static int simple_read_state(struct udevice *dev, struct simple_state *state)
+int vbe_simple_read_state(struct udevice *dev, struct simple_state *state)
 {
ALLOC_CACHE_ALIGN_BUFFER(u8, buf, MMC_MAX_BLOCK_LEN);
struct simple_priv *priv = dev_get_priv(dev);
@@ -157,7 +131,7 @@ static int vbe_simple_get_state_desc(struct udevice *dev, 
char *buf,
struct simple_state state;
int ret;
 
-   ret = simple_read_state(dev, );
+   ret = vbe_simple_read_state(dev, );
if (ret)
return log_msg_ret("read", ret);
 
@@ -206,78 +180,6 @@ static struct bootmeth_ops bootmeth_vbe_simple_ops = {
.read_file  = vbe_simple_read_file,
 };
 
-int vbe_simple_fixup_node(ofnode node, struct simple_state *state)
-{
-   char *version;
-   int ret;
-
-   version = strdup(state->fw_version);
-   if (!version)
-   return log_msg_ret("dup", -ENOMEM);
-
-   ret = ofnode_write_string(node, "cur-version", version);
-   if (ret)
-   return log_msg_ret("ver", ret);
-   ret = ofnode_write_u32(node, "cur-vernum", state->fw_vernum);
-   if (ret)
-   return log_msg_ret("num", ret);
-   ret = ofnode_write_string(node, "bootloader-version", version_string);
-   if (ret)
-   return log_msg_ret("bl", ret);
-
-   return 0;
-}
-
-/**
- * bootmeth_vbe_simple_ft_fixup() - Write out all VBE simple data to the DT
- *
- * @ctx: Context for event
- * @event: Event to process
- * @return 0 if OK, -ve on error
- */
-static int bootmeth_vbe_simple_ft_fixup(void *ctx, struct event *event)
-{
-   oftree tree = event->data.ft_fixup.tree;
-   struct udevice *dev;
-
-   /*
-* Ideally we would have driver model support for fixups, but that does
-* not exist yet. It is a step too far to try to do this before VBE is
-* in place.
-*/
-   for (vbe_find_first_device(); dev; vbe_find_next_device()) {
-   struct simple_state state;
-   ofnode node, subnode;
-   int ret;
-
-   if (strcmp("vbe_simple", dev->driver->name))
-   continue;
-
-   /* Check if there is a node to fix up */
-   node = oftree_path(tree, "/chosen/fwupd");
-   if (!ofnode_valid(node))
-   continue;
-   subnode = ofnode_find_subnode(node, dev->name);
-   if (!ofnode_valid(subnode))
-   continue;
-
-   log_debug("Fixing up: %s\n", dev->name);
-   ret = device_probe(dev);
-   if (ret)
-   return log_msg_ret("probe", ret);
-   ret = simple_read_state(dev, );
-   if (ret)
-   return log_msg_ret("read", ret);
-
-   ret = vbe_simple_fixup_node(subnode, );
-   if (ret)
- 

[PATCH v3 41/43] vbe: Record which phases loaded using VBE

2022-10-20 Thread Simon Glass
We expect VPL and SPL to load using VBE. Add a record of this so we can
check it in U-Boot proper.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/vbe_simple_fw.c | 10 ++
 include/bloblist.h   |  1 +
 include/vbe.h|  9 +
 3 files changed, 20 insertions(+)

diff --git a/boot/vbe_simple_fw.c b/boot/vbe_simple_fw.c
index fc05e9e2bd1..0a49d286703 100644
--- a/boot/vbe_simple_fw.c
+++ b/boot/vbe_simple_fw.c
@@ -9,6 +9,7 @@
 #define LOG_CATEGORY LOGC_BOOT
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -154,11 +155,17 @@ static int simple_load_from_image(struct spl_image_info 
*spl_image,
struct udevice *meth, *bdev;
struct simple_priv *priv;
struct bootflow bflow;
+   struct vbe_handoff *handoff;
int ret;
 
if (spl_phase() != PHASE_VPL && spl_phase() != PHASE_SPL)
return -ENOENT;
 
+   ret = bloblist_ensure_size(BLOBLISTT_VBE, sizeof(struct vbe_handoff),
+  0, (void **));
+   if (ret)
+   return log_msg_ret("ro", ret);
+
vbe_find_first_device();
if (!meth)
return log_msg_ret("vd", -ENODEV);
@@ -190,6 +197,9 @@ static int simple_load_from_image(struct spl_image_info 
*spl_image,
/* this is not used from now on, so free it */
bootflow_free();
 
+   /* Record that VBE was used in this phase */
+   handoff->phases |= 1 << spl_phase();
+
return 0;
 }
 SPL_LOAD_IMAGE_METHOD("vbe_simple", 5, BOOT_DEVICE_VBE,
diff --git a/include/bloblist.h b/include/bloblist.h
index 9684bfd5f4b..2a2f1700eb0 100644
--- a/include/bloblist.h
+++ b/include/bloblist.h
@@ -112,6 +112,7 @@ enum bloblist_tag_t {
 */
BLOBLISTT_PROJECT_AREA = 0x8000,
BLOBLISTT_U_BOOT_SPL_HANDOFF = 0x8000, /* Hand-off info from SPL */
+   BLOBLISTT_VBE   = 0x8001,   /* VBE per-phase state */
 
/*
 * Vendor-specific tags are permitted here. Projects can be open source
diff --git a/include/vbe.h b/include/vbe.h
index ece2697b5dc..5ede8181b98 100644
--- a/include/vbe.h
+++ b/include/vbe.h
@@ -25,6 +25,15 @@ enum vbe_phase_t {
VBE_PHASE_OS,
 };
 
+/**
+ * struct vbe_handoff - information about VBE progress
+ *
+ * @phases: Indicates which phases used the VBE bootmeth (1 << PHASE_...)
+ */
+struct vbe_handoff {
+   u8 phases;
+};
+
 /**
  * vbe_phase() - get current VBE phase
  *
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 36/43] vbe: Add Kconfig options for VPL

2022-10-20 Thread Simon Glass
Enable the various features needed in VPL, by adding Kconfig options.

Update the defconfig for sandbox_vpl so that the build for each phase
includes what is needed. Drop LZMA for now and make sure partition support
is omitted in SPL, since it is not needed.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/Kconfig | 137 +++
 boot/vbe_simple_os.c |   2 +-
 common/spl/Kconfig.vpl   |  30 +++
 configs/sandbox_vpl_defconfig|  13 ++-
 test/py/tests/test_event_dump.py |   1 +
 5 files changed, 181 insertions(+), 2 deletions(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index 6eb056def05..93344975a63 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -292,6 +292,57 @@ config SPL_FIT_GENERATOR
 
 endif # SPL
 
+if VPL
+
+config VPL_FIT
+   bool "Support Flattened Image Tree within VPL"
+   depends on VPL
+   default y
+   select VPL_HASH
+   select VPL_OF_LIBFDT
+
+config VPL_FIT_PRINT
+   bool "Support FIT printing within VPL"
+   depends on VPL_FIT
+   default y
+   help
+ Support printing the content of the fitImage in a verbose manner in 
VPL.
+
+config VPL_FIT_FULL_CHECK
+   bool "Do a full check of the FIT before using it"
+   default y
+   help
+ Enable this do a full check of the FIT to make sure it is valid. This
+ helps to protect against carefully crafted FITs which take advantage
+ of bugs or omissions in the code. This includes a bad structure,
+ multiple root nodes and the like.
+
+config VPL_FIT_SIGNATURE
+   bool "Enable signature verification of FIT firmware within VPL"
+   depends on VPL_DM
+   depends on VPL_LOAD_FIT || VPL_LOAD_FIT_FULL
+   default y
+   select FIT_SIGNATURE
+   select VPL_FIT
+   select VPL_CRYPTO
+   select VPL_HASH
+   imply VPL_RSA
+   imply VPL_RSA_VERIFY
+   select VPL_IMAGE_SIGN_INFO
+   select VPL_FIT_FULL_CHECK
+
+config VPL_FIT_SIGNATURE_MAX_SIZE
+   hex "Max size of signed FIT structures in VPL"
+   depends on VPL_FIT_SIGNATURE
+   default 0x1000
+   help
+ This option sets a max size in bytes for verified FIT uImages.
+ A sane value of 256MB protects corrupted DTB structures from 
overlapping
+ device memory. Assure this size does not extend past expected storage
+ space.
+
+endif # VPL
+
 endif # FIT
 
 config PXE_UTILS
@@ -334,6 +385,26 @@ config BOOTSTD_FULL
  - support for selecting the ordering of bootdevs using the devicetree
as well as the "boot_targets" environment variable
 
+config SPL_BOOTSTD
+   bool "Standard boot support in VPL"
+   depends on SPL && SPL_DM && SPL_OF_CONTROL && SPL_BLK
+   default y if VPL
+   help
+ This enables standard boot in SPL. This is neeeded so that VBE
+ (Verified Boot for Embedded) can be used, since it depends on standard
+ boot. It is enabled by default since the main purpose of VPL is to
+ handle the firmware part of VBE.
+
+config VPL_BOOTSTD
+   bool "Standard boot support in VPL"
+   depends on VPL && VPL_DM && VPL_OF_CONTROL && VPL_BLK
+   default y
+   help
+ This enables standard boot in SPL. This is neeeded so that VBE
+ (Verified Boot for Embedded) can be used, since it depends on standard
+ boot. It is enabled by default since the main purpose of VPL is to
+ handle the firmware part of VBE.
+
 if BOOTSTD
 
 config BOOTSTD_BOOTCOMMAND
@@ -408,6 +479,24 @@ config BOOTMETH_VBE
  supports selection of various firmware components, seleciton of an OS 
to
  boot as well as updating these using fwupd.
 
+config SPL_BOOTMETH_VBE
+   bool "Bootdev support for Verified Boot for Embedded (SPL)"
+   depends on SPL && FIT
+   default y if VPL
+   help
+ Enables support for VBE boot. This is a standard boot method which
+ supports selection of various firmware components, seleciton of an OS 
to
+ boot as well as updating these using fwupd.
+
+config VPL_BOOTMETH_VBE
+   bool "Bootdev support for Verified Boot for Embedded (VPL)"
+   depends on VPL && FIT
+   default y
+   help
+ Enables support for VBE boot. This is a standard boot method which
+ supports selection of various firmware components, seleciton of an OS 
to
+ boot as well as updating these using fwupd.
+
 if BOOTMETH_VBE
 
 config BOOTMETH_VBE_SIMPLE
@@ -418,6 +507,54 @@ config BOOTMETH_VBE_SIMPLE
  firmware image in boot media such as MMC. It does not support any sort
  of rollback, recovery or A/B boot.
 
+config BOOTMETH_VBE_SIMPLE_OS
+   bool "Bootdev support for VBE 'simple' method OS phase"
+   default y
+   help
+ Enables support for the OS parts of VBE 'simple' boot. This includes
+ fixing up the device tree with the required VBE 

[PATCH v3 38/43] sandbox: Add an image for VPL

2022-10-20 Thread Simon Glass
Use binman to build an image which includes all the U-Boot phases so that
a full VBE boot can take place with just that image.bin file. Attach the
image file to mmc2 so it can be loaded.

VBE is used to load images in two phases:

   - In VPL, VBE decides which SPL image to load
   - In SPL, VBE decides which U-Boot image to load

The latter should really be determined by VPL, since it does the full
signature verification on the selected configuration. However, we have
separate configurations for SPL and U-Boot proper, so for now we keep it
simple and have SPL do its own verification. This will need to be
tidied up later.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Attach the phase to the image node instead of the configuration node
- Add signature checking / hashing to make the image more realistic

 arch/sandbox/dts/sandbox.dts  |  7 +++
 arch/sandbox/dts/sandbox_vpl.dtsi | 84 +++
 arch/sandbox/dts/test.dts |  6 ++-
 3 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 arch/sandbox/dts/sandbox_vpl.dtsi

diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 21f00fcab5e..1b60914a01c 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -21,6 +21,9 @@
spi0 = 
};
 
+   binman: binman {
+   };
+
memory {
reg = <0 CONFIG_SYS_SDRAM_SIZE>;
};
@@ -103,3 +106,7 @@
 #include "sandbox.dtsi"
 #include "cros-ec-keyboard.dtsi"
 #include "sandbox_pmic.dtsi"
+
+#ifdef CONFIG_SANDBOX_VPL
+#include "sandbox_vpl.dtsi"
+#endif
diff --git a/arch/sandbox/dts/sandbox_vpl.dtsi 
b/arch/sandbox/dts/sandbox_vpl.dtsi
new file mode 100644
index 000..1fba537f135
--- /dev/null
+++ b/arch/sandbox/dts/sandbox_vpl.dtsi
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Devicetree file for VPL (Verifying Program Loader)
+ */
+
+ {
+   u-boot-tpl-elf {
+   no-expanded;
+   };
+   u-boot-vpl-elf {
+   no-expanded;
+   };
+   fw-update {
+   type = "section";
+
+   /*
+* provide plenty of space for ELF files with debug info so that
+* gdb can be used
+*/
+   offset = <0x40>;
+   size = <0xdffc00>;
+
+   fit {
+   fit,external-offset = <0>;
+   description = "AP firmware";
+   images {
+   spl {
+   description = "U-Boot SPL";
+   type = "firmware";
+   phase = "spl";
+   arch = "sandbox";
+   os = "u-boot";
+   compression = "none";
+
+   hash-1 {
+   algo = "sha256";
+   };
+
+   u-boot-spl-elf {
+   };
+   };
+   u-boot {
+   description = "U-Boot";
+   type = "firmware";
+   phase = "u-boot";
+   arch = "sandbox";
+   os = "u-boot";
+   compression = "none";
+
+   hash-1 {
+   algo = "sha256";
+   };
+
+   u-boot-elf {
+   };
+   };
+   };
+
+   configurations {
+   conf-1 {
+   compatible = "sandbox";
+   description = "AP Firmware v1";
+   firmware = "spl", "u-boot";
+   signature {
+   algo = "sha1,rsa2048";
+   key-name-hint = "dev";
+   sign-images = "firmware";
+   };
+   };
+   };
+   };
+   };
+   state {
+   type = "fill";
+   size = <0x200>;
+   };
+   version {
+   type = "text";
+   text = "1.2.3";
+   size = <0x200>;
+   };
+   fdtmap {
+   };
+};
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index eed72cb71d8..09956ad7f97 100644
--- 

[PATCH v3 39/43] vpl: Allow signature verification

2022-10-20 Thread Simon Glass
Add the required Kconfig option so that signatures can be verified when
loading a configuration.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add new patch to allow signature verification

 boot/Kconfig   | 1 -
 common/Kconfig | 7 +++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index 93344975a63..d5c582ebe8c 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -320,7 +320,6 @@ config VPL_FIT_FULL_CHECK
 config VPL_FIT_SIGNATURE
bool "Enable signature verification of FIT firmware within VPL"
depends on VPL_DM
-   depends on VPL_LOAD_FIT || VPL_LOAD_FIT_FULL
default y
select FIT_SIGNATURE
select VPL_FIT
diff --git a/common/Kconfig b/common/Kconfig
index 5926645b3c3..e2c9114f538 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1065,6 +1065,13 @@ config SPL_IMAGE_SIGN_INFO
help
  Enable image_sign_info helper functions in SPL.
 
+config VPL_IMAGE_SIGN_INFO
+   bool
+   select SHA1
+   select SHA256
+   help
+ Enable image_sign_info helper functions in SPL.
+
 endif
 
 config FDT_SIMPLEFB
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 31/43] sandbox: Support obtaining the next phase from an image

2022-10-20 Thread Simon Glass
At present sandbox runs the next phase from discrete executables, so for
example u-boot-tpl runs u-boot-vpl to get to the next phase.

In some cases the phases are all built into a single firmware image, as is
done for real boards. Add support for this to sandbox.

Make it higher priority so that it takes precedence over the existing
method.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/sandbox/cpu/spl.c | 52 +-
 include/spl.h  |  3 +++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 2678370481a..75f4601fdfb 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -78,7 +78,48 @@ static int spl_board_load_file(struct spl_image_info 
*spl_image,
 
return 0;
 }
-SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_file);
+SPL_LOAD_IMAGE_METHOD("sandbox_file", 9, BOOT_DEVICE_BOARD,
+ spl_board_load_file);
+
+static int load_from_image(struct spl_image_info *spl_image,
+  struct spl_boot_device *bootdev)
+{
+   struct sandbox_state *state = state_get_current();
+   enum u_boot_phase next_phase;
+   const char *fname;
+   ulong pos, size;
+   int full_size;
+   void *buf;
+   int ret;
+
+   if (!IS_ENABLED(CONFIG_SANDBOX_VPL))
+   return -ENOENT;
+
+   next_phase = spl_next_phase();
+   pos = spl_get_image_pos();
+   size = spl_get_image_size();
+   if (pos == BINMAN_SYM_MISSING || size == BINMAN_SYM_MISSING) {
+   log_debug("No image found\n");
+   return -ENOENT;
+   }
+   log_info("Reading from pos %lx size %lx\n", pos, size);
+
+   /*
+* Set up spl_image to boot from jump_to_image_no_args(). Allocate this
+* outside the RAM buffer (i.e. don't use strdup()).
+*/
+   fname = state->prog_fname ? state->prog_fname : state->argv[0];
+   ret = os_read_file(fname, , _size);
+   if (ret)
+   return log_msg_ret("rd", -ENOMEM);
+   spl_image->flags = SPL_SANDBOXF_ARG_IS_BUF;
+   spl_image->arg = buf;
+   spl_image->offset = pos;
+   spl_image->size = size;
+
+   return 0;
+}
+SPL_LOAD_IMAGE_METHOD("sandbox_image", 7, BOOT_DEVICE_BOARD, load_from_image);
 
 void spl_board_init(void)
 {
@@ -109,6 +150,15 @@ void __noreturn jump_to_image_no_args(struct 
spl_image_info *spl_image)
}
break;
}
+   case SPL_SANDBOXF_ARG_IS_BUF: {
+   int ret;
+
+   ret = os_jump_to_image(spl_image->arg + spl_image->offset,
+  spl_image->size);
+   if (ret)
+   log_err("Failed to load image\n");
+   break;
+   }
default:
log_err("Invalid flags\n");
break;
diff --git a/include/spl.h b/include/spl.h
index e711fb13654..e407c7fe55b 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -232,9 +232,12 @@ static inline const char *spl_phase_prefix(enum 
u_boot_phase phase)
  * enum spl_sandbox_flags - flags for sandbox's use of spl_image_info->flags
  *
  * @SPL_SANDBOXF_ARG_IS_FNAME: arg is the filename to jump to (default)
+ * @SPL_SANDBOXF_ARG_IS_BUF: arg is the containing image to jump to, @offset is
+ * the start offset within the image, @size is the size of the image
  */
 enum spl_sandbox_flags {
SPL_SANDBOXF_ARG_IS_FNAME = 0,
+   SPL_SANDBOXF_ARG_IS_BUF,
 };
 
 struct spl_image_info {
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 35/43] vbe: Drop the U-Boot prefix from the version

2022-10-20 Thread Simon Glass
We don't need the U-Boot prefix on the version and in fact it is harmful
since pytest gets confused seeing the U-Boot banner bring displayed when
the version is printed.

Drop the prefix from the string.

We could produce an entirely new string from the component parts, but this
adds to the rodata size and would break the use of version_string as the
only thing which holds this information.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/vbe_simple_os.c   | 9 +++--
 test/boot/vbe_simple.c | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/boot/vbe_simple_os.c b/boot/vbe_simple_os.c
index 7761b9ef656..058db6154b0 100644
--- a/boot/vbe_simple_os.c
+++ b/boot/vbe_simple_os.c
@@ -18,7 +18,7 @@
 
 int vbe_simple_fixup_node(ofnode node, struct simple_state *state)
 {
-   char *version;
+   const char *version, *str;
int ret;
 
version = strdup(state->fw_version);
@@ -31,7 +31,12 @@ int vbe_simple_fixup_node(ofnode node, struct simple_state 
*state)
ret = ofnode_write_u32(node, "cur-vernum", state->fw_vernum);
if (ret)
return log_msg_ret("num", ret);
-   ret = ofnode_write_string(node, "bootloader-version", version_string);
+
+   /* Drop the 'U-Boot ' at the start */
+   str = version_string;
+   if (!strncmp("U-Boot ", str, 7))
+   str += 7;
+   ret = ofnode_write_string(node, "bootloader-version", str);
if (ret)
return log_msg_ret("bl", ret);
 
diff --git a/test/boot/vbe_simple.c b/test/boot/vbe_simple.c
index faba9e8f90b..a50785dbbf6 100644
--- a/test/boot/vbe_simple.c
+++ b/test/boot/vbe_simple.c
@@ -77,7 +77,7 @@ static int vbe_simple_test_base(struct unit_test_state *uts)
 
bl_version = ofnode_read_string(node, "bootloader-version");
ut_assertnonnull(bl_version);
-   ut_asserteq_str(version_string, bl_version);
+   ut_asserteq_str(version_string + 7, bl_version);
 
return 0;
 }
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 27/43] image: Allow loading a FIT image for a particular phase

2022-10-20 Thread Simon Glass
Add support for filtering out FIT images by phase. Rather than adding yet
another argument to this already overloaded function, use a composite
value, where the phase is only added in if needed.

The FIT config is still selected (and verified) as normal, but the images
are selected based on the phase.

Tests for this come in a little later, as part of the updated VPL test.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Attach the phase to the image node instead of the configuration node

 boot/image-fit.c | 83 +++-
 doc/uImage.FIT/howto.txt |  6 +++
 include/image.h  | 12 +++---
 3 files changed, 86 insertions(+), 15 deletions(-)

diff --git a/boot/image-fit.c b/boot/image-fit.c
index 02f1d28c771..3cc556b727f 100644
--- a/boot/image-fit.c
+++ b/boot/image-fit.c
@@ -802,6 +802,40 @@ int fit_image_get_comp(const void *fit, int noffset, 
uint8_t *comp)
return 0;
 }
 
+/**
+ * fit_image_get_phase() - get the phase for a configuration node
+ * @fit: pointer to the FIT format image header
+ * @offset: configuration-node offset
+ * @phasep: returns the phase
+ *
+ * Finds the phase property in a given configuration node. If the property is
+ * found, its (string) value is translated to the numeric id which is returned
+ * to the caller.
+ *
+ * Returns: 0 on success, -ENOENT if missing, -EINVAL for invalid value
+ */
+int fit_image_get_phase(const void *fit, int offset, enum image_phase_t 
*phasep)
+{
+   const void *data;
+   int len, ret;
+
+   /* Get phase name from property data */
+   data = fdt_getprop(fit, offset, FIT_PHASE_PROP, );
+   if (!data) {
+   fit_get_debug(fit, offset, FIT_PHASE_PROP, len);
+   *phasep = 0;
+   return -ENOENT;
+   }
+
+   /* Translate phase name to id */
+   ret = genimg_get_phase_id(data);
+   if (ret < 0)
+   return ret;
+   *phasep = ret;
+
+   return 0;
+}
+
 static int fit_image_get_address(const void *fit, int noffset, char *name,
  ulong *load)
 {
@@ -1867,10 +1901,37 @@ int fit_conf_get_prop_node_index(const void *fit, int 
noffset,
return fit_image_get_node(fit, uname);
 }
 
-int fit_conf_get_prop_node(const void *fit, int noffset,
-   const char *prop_name)
+int fit_conf_get_prop_node(const void *fit, int noffset, const char *prop_name,
+  enum image_phase_t sel_phase)
 {
-   return fit_conf_get_prop_node_index(fit, noffset, prop_name, 0);
+   int i, count;
+
+   if (sel_phase == IH_PHASE_NONE)
+   return fit_conf_get_prop_node_index(fit, noffset, prop_name, 0);
+
+   count = fit_conf_get_prop_node_count(fit, noffset, prop_name);
+   if (count < 0)
+   return count;
+
+   /* check each image in the list */
+   for (i = 0; i < count; i++) {
+   enum image_phase_t phase;
+   int ret, node;
+
+   node = fit_conf_get_prop_node_index(fit, noffset, prop_name, i);
+   ret = fit_image_get_phase(fit, node, );
+
+   /* if the image is for any phase, let's use it */
+   if (ret == -ENOENT)
+   return node;
+   else if (ret < 0)
+   return ret;
+
+   if (phase == sel_phase)
+   return node;
+   }
+
+   return -ENOENT;
 }
 
 static int fit_get_data_tail(const void *fit, int noffset,
@@ -1906,7 +1967,8 @@ int fit_get_data_conf_prop(const void *fit, const char 
*prop_name,
 {
int noffset = fit_conf_get_node(fit, NULL);
 
-   noffset = fit_conf_get_prop_node(fit, noffset, prop_name);
+   noffset = fit_conf_get_prop_node(fit, noffset, prop_name,
+IH_PHASE_NONE);
return fit_get_data_tail(fit, noffset, data, size);
 }
 
@@ -1944,7 +2006,8 @@ int fit_get_node_from_config(struct bootm_headers *images,
return -EINVAL;
}
 
-   noffset = fit_conf_get_prop_node(fit_hdr, cfg_noffset, prop_name);
+   noffset = fit_conf_get_prop_node(fit_hdr, cfg_noffset, prop_name,
+IH_PHASE_NONE);
if (noffset < 0) {
debug("*  %s: no '%s' in config\n", prop_name, prop_name);
return -ENOENT;
@@ -1990,9 +2053,10 @@ static const char *fit_get_image_type_property(int type)
 
 int fit_image_load(struct bootm_headers *images, ulong addr,
   const char **fit_unamep, const char **fit_uname_configp,
-  int arch, int image_type, int bootstage_id,
+  int arch, int ph_type, int bootstage_id,
   enum fit_load_op load_op, ulong *datap, ulong *lenp)
 {
+   int image_type = image_ph_type(ph_type);
int cfg_noffset, noffset;
const char *fit_uname;
const char *fit_uname_config;
@@ -2038,8 +2102,7 @@ int 

[PATCH v3 30/43] spl: Allow multiple loaders of the same time

2022-10-20 Thread Simon Glass
At present we only support a single loader of each time. Extra ones are
ignored. This means that only one BOOT_DEVICE_BOARD can be used in the SPL
image.

This is inconvenient since we sometimes want to provide several
board-specific drivers, albeit at different priorties. Add support for
this.

This should have no functional change for existing boards.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/spl/spl.c | 56 +---
 1 file changed, 25 insertions(+), 31 deletions(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 4635e77e979..6f2014b0e22 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -630,23 +630,6 @@ __weak void board_boot_order(u32 *spl_boot_list)
spl_boot_list[0] = spl_boot_device();
 }
 
-static struct spl_image_loader *spl_ll_find_loader(uint boot_device)
-{
-   struct spl_image_loader *drv =
-   ll_entry_start(struct spl_image_loader, spl_image_loader);
-   const int n_ents =
-   ll_entry_count(struct spl_image_loader, spl_image_loader);
-   struct spl_image_loader *entry;
-
-   for (entry = drv; entry != drv + n_ents; entry++) {
-   if (boot_device == entry->boot_device)
-   return entry;
-   }
-
-   /* Not found */
-   return NULL;
-}
-
 __weak int spl_check_board_image(struct spl_image_info *spl_image,
 const struct spl_boot_device *bootdev)
 {
@@ -693,6 +676,10 @@ static int spl_load_image(struct spl_image_info *spl_image,
 static int boot_from_devices(struct spl_image_info *spl_image,
 u32 spl_boot_list[], int count)
 {
+   struct spl_image_loader *drv =
+   ll_entry_start(struct spl_image_loader, spl_image_loader);
+   const int n_ents =
+   ll_entry_count(struct spl_image_loader, spl_image_loader);
int ret = -ENODEV;
int i;
 
@@ -702,20 +689,27 @@ static int boot_from_devices(struct spl_image_info 
*spl_image,
 
if (CONFIG_IS_ENABLED(SHOW_ERRORS))
ret = -ENXIO;
-   loader = spl_ll_find_loader(bootdev);
-   if (!CONFIG_IS_ENABLED(SILENT_CONSOLE)) {
-   if (loader)
-   printf("Trying to boot from %s\n",
-  spl_loader_name(loader));
-   else if (CONFIG_IS_ENABLED(SHOW_ERRORS))
-   printf(SPL_TPL_PROMPT
-  "Unsupported Boot Device %d\n", bootdev);
-   else
-   puts(SPL_TPL_PROMPT "Unsupported Boot 
Device!\n");
-   }
-   if (loader && !spl_load_image(spl_image, loader)) {
-   spl_image->boot_device = bootdev;
-   return 0;
+   for (loader = drv; loader != drv + n_ents; loader++) {
+   if (bootdev != loader->boot_device)
+   continue;
+   if (!CONFIG_IS_ENABLED(SILENT_CONSOLE)) {
+   if (loader)
+   printf("Trying to boot from %s\n",
+  spl_loader_name(loader));
+   else if (CONFIG_IS_ENABLED(SHOW_ERRORS)) {
+   printf(SPL_TPL_PROMPT
+  "Unsupported Boot Device %d\n",
+  bootdev);
+   } else {
+   puts(SPL_TPL_PROMPT
+"Unsupported Boot Device!\n");
+   }
+   }
+   if (loader &&
+   !spl_load_image(spl_image, loader)) {
+   spl_image->boot_device = bootdev;
+   return 0;
+   }
}
}
 
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 22/43] sandbox: Drop message about writing sandbox state

2022-10-20 Thread Simon Glass
This happens every time sandbox moves to the next phase so is not very
interesting. Display the message only when debugging.

Signed-off-by: Simon Glass 
Reviewed-by: Heinrich Schuchardt 
---

(no changes since v1)

 arch/sandbox/cpu/state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c
index fcc4a337e59..a681e472ab6 100644
--- a/arch/sandbox/cpu/state.c
+++ b/arch/sandbox/cpu/state.c
@@ -470,7 +470,7 @@ int state_uninit(void)
int err;
 
if (state->write_ram_buf || state->write_state)
-   log_info("Writing sandbox state\n");
+   log_debug("Writing sandbox state\n");
state = _state;
 
/* Finish the bloblist, so that it is correct before writing memory */
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 33/43] vbe: Support reading the next SPL phase via VBE

2022-10-20 Thread Simon Glass
Add an SPL loader to obtain the next-phase binary from a FIT provided
by the VBE driver.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/sandbox/cpu/spl.c |   3 +-
 arch/sandbox/include/asm/spl.h |   1 +
 boot/Makefile  |   1 +
 boot/vbe_request.c |   2 +-
 boot/vbe_simple.c  |  46 +---
 boot/vbe_simple.h  |  37 +++
 boot/vbe_simple_fw.c   | 196 +
 include/bootstage.h|   2 +
 8 files changed, 269 insertions(+), 19 deletions(-)
 create mode 100644 boot/vbe_simple.h
 create mode 100644 boot/vbe_simple_fw.c

diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 75f4601fdfb..0faf34cc00a 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -51,7 +51,8 @@ void board_init_f(ulong flag)
 
 void board_boot_order(u32 *spl_boot_list)
 {
-   spl_boot_list[0] = BOOT_DEVICE_BOARD;
+   spl_boot_list[0] = BOOT_DEVICE_VBE;
+   spl_boot_list[1] = BOOT_DEVICE_BOARD;
 }
 
 static int spl_board_load_file(struct spl_image_info *spl_image,
diff --git a/arch/sandbox/include/asm/spl.h b/arch/sandbox/include/asm/spl.h
index 312aef72086..2f8b5fcfcfe 100644
--- a/arch/sandbox/include/asm/spl.h
+++ b/arch/sandbox/include/asm/spl.h
@@ -11,6 +11,7 @@ enum {
BOOT_DEVICE_MMC2,
BOOT_DEVICE_MMC2_2,
BOOT_DEVICE_BOARD,
+   BOOT_DEVICE_VBE,
 };
 
 /**
diff --git a/boot/Makefile b/boot/Makefile
index 19d628d748a..e5c27900ea7 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -49,3 +49,4 @@ endif
 
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += vbe.o vbe_request.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_FW) += vbe_simple_fw.o
diff --git a/boot/vbe_request.c b/boot/vbe_request.c
index 312edfa2bdb..45f1d2b7e17 100644
--- a/boot/vbe_request.c
+++ b/boot/vbe_request.c
@@ -36,7 +36,7 @@ static int handle_random_req(ofnode node, int default_size,
u32 size;
int ret;
 
-   if (!IS_ENABLED(CONFIG_DM_RNG))
+   if (!CONFIG_IS_ENABLED(DM_RNG))
return -ENOTSUPP;
 
if (ofnode_read_u32(node, "vbe,size", )) {
diff --git a/boot/vbe_simple.c b/boot/vbe_simple.c
index 076b650c25a..1ccd416e4bb 100644
--- a/boot/vbe_simple.c
+++ b/boot/vbe_simple.c
@@ -9,18 +9,19 @@
 #define LOG_CATEGORY LOGC_BOOT
 
 #include 
-#include 
-#include 
-#include 
+#include 
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include "vbe_simple.h"
 
 enum {
MAX_VERSION_LEN = 256,
@@ -37,18 +38,6 @@ enum {
NVD_HDR_VER_CUR = 1,/* current version */
 };
 
-/** struct simple_priv - information read from the device tree */
-struct simple_priv {
-   u32 area_start;
-   u32 area_size;
-   u32 skip_offset;
-   u32 state_offset;
-   u32 state_size;
-   u32 version_offset;
-   u32 version_size;
-   const char *storage;
-};
-
 /** struct simple_state - state information read from media
  *
  * @fw_version: Firmware version string
@@ -183,15 +172,38 @@ static int vbe_simple_get_state_desc(struct udevice *dev, 
char *buf,
 
 static int vbe_simple_read_bootflow(struct udevice *dev, struct bootflow 
*bflow)
 {
-   /* To be implemented */
+   int ret;
+
+   if (vbe_phase() == VBE_PHASE_FIRMWARE) {
+   ret = vbe_simple_read_bootflow_fw(dev, bflow);
+   if (ret)
+   return log_msg_ret("fw", ret);
+   return 0;
+   }
 
return -EINVAL;
 }
 
+static int vbe_simple_read_file(struct udevice *dev, struct bootflow *bflow,
+   const char *file_path, ulong addr, ulong *sizep)
+{
+   int ret;
+
+   if (vbe_phase() == VBE_PHASE_OS) {
+   ret = bootmeth_common_read_file(dev, bflow, file_path, addr,
+   sizep);
+   if (ret)
+   return log_msg_ret("os", ret);
+   }
+
+   /* To be implemented */
+   return -EINVAL;
+}
+
 static struct bootmeth_ops bootmeth_vbe_simple_ops = {
.get_state_desc = vbe_simple_get_state_desc,
.read_bootflow  = vbe_simple_read_bootflow,
-   .read_file  = bootmeth_common_read_file,
+   .read_file  = vbe_simple_read_file,
 };
 
 int vbe_simple_fixup_node(ofnode node, struct simple_state *state)
diff --git a/boot/vbe_simple.h b/boot/vbe_simple.h
new file mode 100644
index 000..e37a9fae379
--- /dev/null
+++ b/boot/vbe_simple.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Verified Boot for Embedded (VBE) vbe-simple common file
+ *
+ * Copyright 2022 Google LLC
+ * Written by Simon Glass 
+ */
+
+#ifndef __VBE_SIMPLE_H
+#define __VBE_SIMPLE_H
+
+/** struct simple_priv - information read from the device tree */
+struct simple_priv {
+   u32 area_start;
+   u32 area_size;
+   

[PATCH v3 24/43] sandbox: Generalise SPL booting

2022-10-20 Thread Simon Glass
At present sandbox only supports jumping to a file, to get to the next
U-Boot phase. We want to support other methods, so update the code to
use an enum for the method. Also use the

Use board_boot_order() to set the order, so we can add more options.
Also add the MMC methods into the BOOT_DEVICE enum so that booting
from MMC can be supported.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/sandbox/cpu/spl.c | 33 +
 arch/sandbox/include/asm/spl.h |  3 +++
 include/spl.h  |  9 +
 3 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 9c59cc26163..2678370481a 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -49,13 +49,13 @@ void board_init_f(ulong flag)
preloader_console_init();
 }
 
-u32 spl_boot_device(void)
+void board_boot_order(u32 *spl_boot_list)
 {
-   return BOOT_DEVICE_BOARD;
+   spl_boot_list[0] = BOOT_DEVICE_BOARD;
 }
 
-static int spl_board_load_image(struct spl_image_info *spl_image,
-   struct spl_boot_device *bootdev)
+static int spl_board_load_file(struct spl_image_info *spl_image,
+  struct spl_boot_device *bootdev)
 {
char fname[256];
int ret;
@@ -74,10 +74,11 @@ static int spl_board_load_image(struct spl_image_info 
*spl_image,
if (!spl_image->arg)
return log_msg_ret("exec", -ENOMEM);
strcpy(spl_image->arg, fname);
+   spl_image->flags = SPL_SANDBOXF_ARG_IS_FNAME;
 
return 0;
 }
-SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
+SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_file);
 
 void spl_board_init(void)
 {
@@ -96,13 +97,21 @@ void spl_board_init(void)
 
 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
 {
-   const char *fname = spl_image->arg;
-
-   if (fname) {
-   os_fd_restore();
-   os_spl_to_uboot(fname);
-   } else {
-   printf("No filename provided for U-Boot\n");
+   switch (spl_image->flags) {
+   case SPL_SANDBOXF_ARG_IS_FNAME: {
+   const char *fname = spl_image->arg;
+
+   if (fname) {
+   os_fd_restore();
+   os_spl_to_uboot(fname);
+   } else {
+   log_err("No filename provided for U-Boot\n");
+   }
+   break;
+   }
+   default:
+   log_err("Invalid flags\n");
+   break;
}
hang();
 }
diff --git a/arch/sandbox/include/asm/spl.h b/arch/sandbox/include/asm/spl.h
index bf5a585622b..312aef72086 100644
--- a/arch/sandbox/include/asm/spl.h
+++ b/arch/sandbox/include/asm/spl.h
@@ -7,6 +7,9 @@
 #define __asm_spl_h
 
 enum {
+   BOOT_DEVICE_MMC1,
+   BOOT_DEVICE_MMC2,
+   BOOT_DEVICE_MMC2_2,
BOOT_DEVICE_BOARD,
 };
 
diff --git a/include/spl.h b/include/spl.h
index a89830d24fd..e711fb13654 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -228,6 +228,15 @@ static inline const char *spl_phase_prefix(enum 
u_boot_phase phase)
 # define SPL_TPL_PROMPT""
 #endif
 
+/**
+ * enum spl_sandbox_flags - flags for sandbox's use of spl_image_info->flags
+ *
+ * @SPL_SANDBOXF_ARG_IS_FNAME: arg is the filename to jump to (default)
+ */
+enum spl_sandbox_flags {
+   SPL_SANDBOXF_ARG_IS_FNAME = 0,
+};
+
 struct spl_image_info {
const char *name;
u8 os;
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 40/43] vbe: Use a manual test

2022-10-20 Thread Simon Glass
Use a manual test for the VBE test, so we can make the pytest and the
C unit test work together properly.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 test/boot/vbe_fixup.c | 19 ---
 test/py/tests/test_vbe.py |  7 ++-
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/test/boot/vbe_fixup.c b/test/boot/vbe_fixup.c
index 7f0f809499a..eba5c4ebe6c 100644
--- a/test/boot/vbe_fixup.c
+++ b/test/boot/vbe_fixup.c
@@ -13,21 +13,18 @@
 #include 
 #include "bootstd_common.h"
 
-/* Basic test of reading nvdata and updating a fwupd node in the device tree */
-static int vbe_test_fixup(struct unit_test_state *uts)
+/*
+ * Basic test of reading nvdata and updating a fwupd node in the device tree
+ * This test works when called from test_vbe.py and it must use the flat tree,
+ * since device tree fix-ups do not yet support live tree.
+ */
+static int vbe_test_fixup_norun(struct unit_test_state *uts)
 {
ofnode chosen, node;
const char *data;
oftree tree;
int size;
 
-   /*
-* This test works when called from test_vbe.py and it must use the
-* flat tree, since device tree fix-ups do not yet support live tree.
-*/
-   if (!working_fdt)
-   return -EAGAIN;
-
tree = oftree_from_fdt(working_fdt);
ut_assert(oftree_valid(tree));
 
@@ -55,5 +52,5 @@ static int vbe_test_fixup(struct unit_test_state *uts)
 
return 0;
 }
-BOOTSTD_TEST(vbe_test_fixup,
-UT_TESTF_DM | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+BOOTSTD_TEST(vbe_test_fixup_norun, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
+UT_TESTF_FLAT_TREE | UT_TESTF_MANUAL);
diff --git a/test/py/tests/test_vbe.py b/test/py/tests/test_vbe.py
index 559c2918868..50b6c1cd911 100644
--- a/test/py/tests/test_vbe.py
+++ b/test/py/tests/test_vbe.py
@@ -85,7 +85,7 @@ bootm loados
 bootm prep
 fdt addr
 fdt print
-ut bootstd vbe_test_fixup
+ut bootstd -f vbe_test_fixup_norun
 '''
 
 @pytest.mark.boardspec('sandbox_flattree')
@@ -117,7 +117,4 @@ def test_vbe(u_boot_console):
 with cons.log.section('Kernel load'):
 output = cons.run_command_list(cmd.splitlines())
 
-# This is a little wonky since there are two tests running in CI. The final
-# one is the 'ut bootstd' command above
-failures = [line for line in output if 'Failures' in line]
-assert len(failures) >= 1 and 'Failures: 0' in failures[-1]
+assert 'Failures: 0' in output[-1]
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 29/43] vbe: Use a warning for a failed requests

2022-10-20 Thread Simon Glass
Optional requests should present a warning rather than an error. Update
the log call.

Signed-off-by: Simon Glass 
---

(no changes since v1)

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

diff --git a/boot/vbe_request.c b/boot/vbe_request.c
index fa018924637..312edfa2bdb 100644
--- a/boot/vbe_request.c
+++ b/boot/vbe_request.c
@@ -195,8 +195,8 @@ static int bootmeth_vbe_ft_fixup(void *ctx, struct event 
*event)
ret = vbe_process_request(dest, );
if (ret) {
result.errnum = ret;
-   log_err("Failed to process VBE request %s (err=%d)\n",
-   ofnode_get_name(dest), ret);
+   log_warning("Failed to process VBE request %s 
(err=%d)\n",
+   ofnode_get_name(dest), ret);
if (*result.err_str) {
char *msg = strdup(result.err_str);
 
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 18/43] usb: Update the test to cover reading and writing

2022-10-20 Thread Simon Glass
Add test coverage for blk_write() as well.

The blk_erase() is not tested for now as the USB stor interface does not
support erase.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Rebase to master

 drivers/scsi/scsi_emul.c |  9 
 drivers/usb/emul/sandbox_flash.c | 35 
 include/scsi.h   | 10 +
 include/scsi_emul.h  | 16 +++
 test/dm/usb.c| 19 -
 5 files changed, 80 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/scsi_emul.c b/drivers/scsi/scsi_emul.c
index 5ba364bdac7..6b8468f7994 100644
--- a/drivers/scsi/scsi_emul.c
+++ b/drivers/scsi/scsi_emul.c
@@ -62,6 +62,15 @@ int sb_scsi_emul_command(struct scsi_emul_info *info,
ret = SCSI_EMUL_DO_READ;
break;
}
+   case SCSI_WRITE10: {
+   const struct scsi_write10_req *write_req = (void *)req;
+
+   info->seek_block = be32_to_cpu(write_req->lba);
+   info->write_len = be16_to_cpu(write_req->xfer_len);
+   info->buff_used = info->write_len * info->block_size;
+   ret = SCSI_EMUL_DO_WRITE;
+   break;
+   }
default:
debug("Command not supported: %x\n", req->cmd[0]);
ret = -EPROTONOSUPPORT;
diff --git a/drivers/usb/emul/sandbox_flash.c b/drivers/usb/emul/sandbox_flash.c
index 2589c708d88..6e8cfe1650a 100644
--- a/drivers/usb/emul/sandbox_flash.c
+++ b/drivers/usb/emul/sandbox_flash.c
@@ -4,6 +4,8 @@
  * Written by Simon Glass 
  */
 
+#define LOG_CATEGORY   UCLASS_USB
+
 #include 
 #include 
 #include 
@@ -190,7 +192,8 @@ static int handle_ufi_command(struct sandbox_flash_priv 
*priv, const void *buff,
ret = sb_scsi_emul_command(info, req, len);
if (!ret) {
setup_response(priv);
-   } else if (ret == SCSI_EMUL_DO_READ && priv->fd != -1) {
+   } else if ((ret == SCSI_EMUL_DO_READ || ret == SCSI_EMUL_DO_WRITE) &&
+  priv->fd != -1) {
os_lseek(priv->fd, info->seek_block * info->block_size,
 OS_SEEK_SET);
setup_response(priv);
@@ -217,6 +220,7 @@ static int sandbox_flash_bulk(struct udevice *dev, struct 
usb_device *udev,
case SCSIPH_START:
info->alloc_len = 0;
info->read_len = 0;
+   info->write_len = 0;
if (priv->error || len != UMASS_BBB_CBW_SIZE ||
cbw->dCBWSignature != CBWSIGNATURE)
goto err;
@@ -230,8 +234,31 @@ static int sandbox_flash_bulk(struct udevice *dev, struct 
usb_device *udev,
return handle_ufi_command(priv, cbw->CBWCDB,
  cbw->bCDBLength);
case SCSIPH_DATA:
-   debug("data out\n");
-   break;
+   log_debug("data out, len=%x, info->write_len=%x\n", len,
+ info->write_len);
+   info->transfer_len = cbw->dCBWDataTransferLength;
+   priv->tag = cbw->dCBWTag;
+   if (!info->write_len)
+   return 0;
+   if (priv->fd != -1) {
+   ulong bytes_written;
+
+   bytes_written = os_write(priv->fd, buff, len);
+   log_debug("bytes_written=%lx", bytes_written);
+   if (bytes_written != len)
+   return -EIO;
+   info->write_len -= len / info->block_size;
+   if (!info->write_len)
+   info->phase = SCSIPH_STATUS;
+   } else {
+   if (info->alloc_len && len > info->alloc_len)
+   len = info->alloc_len;
+   if (len > SANDBOX_FLASH_BUF_SIZE)
+   len = SANDBOX_FLASH_BUF_SIZE;
+   memcpy(info->buff, buff, len);
+   info->phase = SCSIPH_STATUS;
+   }
+   return len;
default:
break;
}
@@ -310,7 +337,7 @@ static int sandbox_flash_probe(struct udevice *dev)
struct scsi_emul_info *info = >eminfo;
int ret;
 
-   priv->fd = os_open(plat->pathname, OS_O_RDONLY);
+   priv->fd = os_open(plat->pathname, OS_O_RDWR);
if (priv->fd != -1) {
ret = os_get_filesize(plat->pathname, >file_size);
if (ret)
diff --git a/include/scsi.h b/include/scsi.h
index 94e1d8ccb28..9efefea99bb 100644
--- a/include/scsi.h
+++ 

[PATCH v3 14/43] bootstd: Add a way to set up a bootflow

2022-10-20 Thread Simon Glass
Add a function to init a bootflow, to reduce code duplication.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/bootdev-uclass.c  |  5 +
 boot/bootflow.c|  9 +
 boot/bootmeth-uclass.c |  5 +
 include/bootflow.h | 12 
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 9d98bee4549..affe0d3e04e 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -440,10 +440,7 @@ int bootdev_get_bootflow(struct udevice *dev, struct 
bootflow_iter *iter,
 
if (!ops->get_bootflow)
return -ENOSYS;
-   memset(bflow, '\0', sizeof(*bflow));
-   bflow->dev = dev;
-   bflow->method = iter->method;
-   bflow->state = BOOTFLOWST_BASE;
+   bootflow_init(bflow, dev, iter->method);
 
return ops->get_bootflow(dev, iter, bflow);
 }
diff --git a/boot/bootflow.c b/boot/bootflow.c
index 5d94a27ff84..f9ad4099244 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -339,6 +339,15 @@ int bootflow_scan_next(struct bootflow_iter *iter, struct 
bootflow *bflow)
} while (1);
 }
 
+void bootflow_init(struct bootflow *bflow, struct udevice *bootdev,
+  struct udevice *meth)
+{
+   memset(bflow, '\0', sizeof(*bflow));
+   bflow->dev = bootdev;
+   bflow->method = meth;
+   bflow->state = BOOTFLOWST_BASE;
+}
+
 void bootflow_free(struct bootflow *bflow)
 {
free(bflow->name);
diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c
index 2d7652edeab..25552dd96f6 100644
--- a/boot/bootmeth-uclass.c
+++ b/boot/bootmeth-uclass.c
@@ -77,10 +77,7 @@ int bootmeth_get_bootflow(struct udevice *dev, struct 
bootflow *bflow)
 
if (!ops->read_bootflow)
return -ENOSYS;
-   memset(bflow, '\0', sizeof(*bflow));
-   bflow->dev = NULL;
-   bflow->method = dev;
-   bflow->state = BOOTFLOWST_BASE;
+   bootflow_init(bflow, NULL, dev);
 
return ops->read_bootflow(dev, bflow);
 }
diff --git a/include/bootflow.h b/include/bootflow.h
index 6aa3d1fff8d..32de261 100644
--- a/include/bootflow.h
+++ b/include/bootflow.h
@@ -144,6 +144,18 @@ struct bootflow_iter {
bool doing_global;
 };
 
+/**
+ * bootflow_init() - Set up a bootflow struct
+ *
+ * The bootflow is zeroed and set to state BOOTFLOWST_BASE
+ *
+ * @bflow: Struct to set up
+ * @bootdev: Bootdev to use
+ * @meth: Bootmeth to use
+ */
+void bootflow_init(struct bootflow *bflow, struct udevice *bootdev,
+  struct udevice *meth);
+
 /**
  * bootflow_iter_init() - Reset a bootflow iterator
  *
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 23/43] image: Move comment for fit_conf_find_compat()

2022-10-20 Thread Simon Glass
Move this comment to the header file, where the APIs should be defined.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Update the comment style

 boot/image-fit.c | 43 ---
 include/image.h  | 41 +
 2 files changed, 41 insertions(+), 43 deletions(-)

diff --git a/boot/image-fit.c b/boot/image-fit.c
index 6e503f827dd..02f1d28c771 100644
--- a/boot/image-fit.c
+++ b/boot/image-fit.c
@@ -1686,49 +1686,6 @@ int fit_check_format(const void *fit, ulong size)
return 0;
 }
 
-/**
- * fit_conf_find_compat
- * @fit: pointer to the FIT format image header
- * @fdt: pointer to the device tree to compare against
- *
- * fit_conf_find_compat() attempts to find the configuration whose fdt is the
- * most compatible with the passed in device tree.
- *
- * Example:
- *
- * / o image-tree
- *   |-o images
- *   | |-o fdt-1
- *   | |-o fdt-2
- *   |
- *   |-o configurations
- * |-o config-1
- * | |-fdt = fdt-1
- * |
- * |-o config-2
- *   |-fdt = fdt-2
- *
- * / o U-Boot fdt
- *   |-compatible = "foo,bar", "bim,bam"
- *
- * / o kernel fdt1
- *   |-compatible = "foo,bar",
- *
- * / o kernel fdt2
- *   |-compatible = "bim,bam", "baz,biz"
- *
- * Configuration 1 would be picked because the first string in U-Boot's
- * compatible list, "foo,bar", matches a compatible string in the root of fdt1.
- * "bim,bam" in fdt2 matches the second string which isn't as good as fdt1.
- *
- * As an optimization, the compatible property from the FDT's root node can be
- * copied into the configuration node in the FIT image. This is required to
- * match configurations with compressed FDTs.
- *
- * returns:
- * offset to the configuration to use if one was found
- * -1 otherwise
- */
 int fit_conf_find_compat(const void *fit, const void *fdt)
 {
int ndepth = 0;
diff --git a/include/image.h b/include/image.h
index d7d6a3fe5b8..92efec0f04b 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1206,6 +1206,47 @@ int fit_image_check_comp(const void *fit, int noffset, 
uint8_t comp);
  */
 int fit_check_format(const void *fit, ulong size);
 
+/**
+ * fit_conf_find_compat() - find most compatible configuration
+ * @fit: pointer to the FIT format image header
+ * @fdt: pointer to the device tree to compare against
+ *
+ * Attempts to find the configuration whose fdt is the most compatible with the
+ * passed in device tree
+ *
+ * Example::
+ *
+ */ o image-tree
+ *  |-o images
+ *  | |-o fdt-1
+ *  | |-o fdt-2
+ *  |
+ *  |-o configurations
+ *|-o config-1
+ *| |-fdt = fdt-1
+ *|
+ *|-o config-2
+ *  |-fdt = fdt-2
+ *
+ */ o U-Boot fdt
+ *  |-compatible = "foo,bar", "bim,bam"
+ *
+ */ o kernel fdt1
+ *  |-compatible = "foo,bar",
+ *
+ */ o kernel fdt2
+ *  |-compatible = "bim,bam", "baz,biz"
+ *
+ * Configuration 1 would be picked because the first string in U-Boot's
+ * compatible list, "foo,bar", matches a compatible string in the root of fdt1.
+ * "bim,bam" in fdt2 matches the second string which isn't as good as fdt1.
+ *
+ * As an optimization, the compatible property from the FDT's root node can be
+ * copied into the configuration node in the FIT image. This is required to
+ * match configurations with compressed FDTs.
+ *
+ * Returns: offset to the configuration to use if one was found, -1 otherwise
+ */
 int fit_conf_find_compat(const void *fit, const void *fdt);
 
 /**
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 28/43] vbe: Rename vbe_fixup to vbe_request

2022-10-20 Thread Simon Glass
The vbe_fixup file handles device tree fixups, but these are called OS
requests in VBE. Rename the file to reflect its wider purpose.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/Makefile   | 2 +-
 boot/{vbe_fixup.c => vbe_request.c} | 2 +-
 test/py/tests/test_event_dump.py| 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
 rename boot/{vbe_fixup.c => vbe_request.c} (98%)

diff --git a/boot/Makefile b/boot/Makefile
index dd45d786f8c..19d628d748a 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -47,5 +47,5 @@ ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o
 endif
 
-obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += vbe.o vbe_fixup.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += vbe.o vbe_request.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o
diff --git a/boot/vbe_fixup.c b/boot/vbe_request.c
similarity index 98%
rename from boot/vbe_fixup.c
rename to boot/vbe_request.c
index 53d88678c92..fa018924637 100644
--- a/boot/vbe_fixup.c
+++ b/boot/vbe_request.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Verified Boot for Embedded (VBE) device tree fixup functions
+ * Verified Boot for Embedded (VBE) OS request (device tree fixup) functions
  *
  * Copyright 2022 Google LLC
  * Written by Simon Glass 
diff --git a/test/py/tests/test_event_dump.py b/test/py/tests/test_event_dump.py
index e63c25df537..46d6384eb3a 100644
--- a/test/py/tests/test_event_dump.py
+++ b/test/py/tests/test_event_dump.py
@@ -16,7 +16,7 @@ def test_event_dump(u_boot_console):
 out = util.run_and_log(cons, ['scripts/event_dump.py', sandbox])
 expect = '''.*Event typeId  Source 
location
   --  
--
-EVT_FT_FIXUP  bootmeth_vbe_ft_fixup   .*boot/vbe_fixup.c:.*
+EVT_FT_FIXUP  bootmeth_vbe_ft_fixup   .*boot/vbe_request.c:.*
 EVT_FT_FIXUP  bootmeth_vbe_simple_ft_fixup.*boot/vbe_simple.c:.*
 EVT_MISC_INIT_F   sandbox_misc_init_f 
.*arch/sandbox/cpu/start.c:'''
 assert re.match(expect, out, re.MULTILINE) is not None
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 17/43] dm: blk: Add udevice functions

2022-10-20 Thread Simon Glass
At present we have functions called blk_dread(), etc., which take a
struct blk_desc * to refer to the block device. Add some functions which
use udevice instead, since this is more in keeping with how driver model
is supposed to work.

Update one of the tests to use this.

Note that it would be nice to update the functions in disk-uclass.c to use
these new functions. However they are not quite the same. For example,
disk_blk_read() adds the partition offset to 'start' when calling the
cache read/fill functions, but does not with part_blk_read(), which does
the addition itself. So as designed the code is duplicated.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add a note as to why we have almost-duplicated code in two places

 drivers/block/blk-uclass.c | 51 +-
 include/blk.h  | 39 -
 test/dm/usb.c  | 11 +---
 3 files changed, 80 insertions(+), 21 deletions(-)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index bcc14a684be..e82789f4a38 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -444,53 +444,70 @@ int blk_get_device(int uclass_id, int devnum, struct 
udevice **devp)
return device_probe(*devp);
 }
 
-unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
-   lbaint_t blkcnt, void *buffer)
+long blk_read(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, void *buf)
 {
-   struct udevice *dev = block_dev->bdev;
+   struct blk_desc *desc = dev_get_uclass_plat(dev);
const struct blk_ops *ops = blk_get_ops(dev);
ulong blks_read;
 
if (!ops->read)
return -ENOSYS;
 
-   if (blkcache_read(block_dev->uclass_id, block_dev->devnum,
- start, blkcnt, block_dev->blksz, buffer))
+   if (blkcache_read(desc->uclass_id, desc->devnum,
+ start, blkcnt, desc->blksz, buf))
return blkcnt;
-   blks_read = ops->read(dev, start, blkcnt, buffer);
+   blks_read = ops->read(dev, start, blkcnt, buf);
if (blks_read == blkcnt)
-   blkcache_fill(block_dev->uclass_id, block_dev->devnum,
- start, blkcnt, block_dev->blksz, buffer);
+   blkcache_fill(desc->uclass_id, desc->devnum, start, blkcnt,
+ desc->blksz, buf);
 
return blks_read;
 }
 
-unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
-lbaint_t blkcnt, const void *buffer)
+long blk_write(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
+  const void *buf)
 {
-   struct udevice *dev = block_dev->bdev;
+   struct blk_desc *desc = dev_get_uclass_plat(dev);
const struct blk_ops *ops = blk_get_ops(dev);
 
if (!ops->write)
return -ENOSYS;
 
-   blkcache_invalidate(block_dev->uclass_id, block_dev->devnum);
-   return ops->write(dev, start, blkcnt, buffer);
+   blkcache_invalidate(desc->uclass_id, desc->devnum);
+
+   return ops->write(dev, start, blkcnt, buf);
 }
 
-unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
-lbaint_t blkcnt)
+long blk_erase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt)
 {
-   struct udevice *dev = block_dev->bdev;
+   struct blk_desc *desc = dev_get_uclass_plat(dev);
const struct blk_ops *ops = blk_get_ops(dev);
 
if (!ops->erase)
return -ENOSYS;
 
-   blkcache_invalidate(block_dev->uclass_id, block_dev->devnum);
+   blkcache_invalidate(desc->uclass_id, desc->devnum);
+
return ops->erase(dev, start, blkcnt);
 }
 
+ulong blk_dread(struct blk_desc *desc, lbaint_t start, lbaint_t blkcnt,
+   void *buffer)
+{
+   return blk_read(desc->bdev, start, blkcnt, buffer);
+}
+
+ulong blk_dwrite(struct blk_desc *desc, lbaint_t start, lbaint_t blkcnt,
+const void *buffer)
+{
+   return blk_write(desc->bdev, start, blkcnt, buffer);
+}
+
+ulong blk_derase(struct blk_desc *desc, lbaint_t start, lbaint_t blkcnt)
+{
+   return blk_erase(desc->bdev, start, blkcnt);
+}
+
 int blk_get_from_parent(struct udevice *parent, struct udevice **devp)
 {
struct udevice *dev;
diff --git a/include/blk.h b/include/blk.h
index 8806c382d4e..4f9d74b6e19 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -273,6 +273,43 @@ unsigned long blk_dwrite(struct blk_desc *block_dev, 
lbaint_t start,
 unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
 lbaint_t blkcnt);
 
+/**
+ * blk_read() - Read from a block device
+ *
+ * @dev: Device to read from
+ * @start: Start block for the read
+ * @blkcnt: Number of blocks to read
+ * @buf: Place to put the data
+ * @return number of blocks read (which may be less than @blkcnt),
+ * or -ve on error. This never returns 0 unless 

[PATCH v3 19/43] bloblist: Drop debugging

2022-10-20 Thread Simon Glass
Disable debugging by default since this implementation is stable now.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/bloblist.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/common/bloblist.c b/common/bloblist.c
index 8488663354b..0d63b6e8817 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -4,7 +4,6 @@
  * Written by Simon Glass 
  */
 
-#define LOG_DEBUG
 #define LOG_CATEGORY   LOGC_BLOBLIST
 
 #include 
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 21/43] dm: mmc: Allow sandbox emulator to build without writes

2022-10-20 Thread Simon Glass
When MMC_WRITE is disabled this driver produced a build error. Fix this.

Also update a comment while we are here.

Signed-off-by: Simon Glass 
Reviewed-by: Jaehoon Chung 
---

(no changes since v1)

 drivers/mmc/sandbox_mmc.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/sandbox_mmc.c b/drivers/mmc/sandbox_mmc.c
index 451fe4a4e5a..ba79a5565c3 100644
--- a/drivers/mmc/sandbox_mmc.c
+++ b/drivers/mmc/sandbox_mmc.c
@@ -23,6 +23,8 @@ struct sandbox_mmc_plat {
 #define MMC_CMULT  8 /* 8 because the card is high-capacity */
 #define MMC_BL_LEN_SHIFT   10
 #define MMC_BL_LEN BIT(MMC_BL_LEN_SHIFT)
+
+/* Granularity of priv->csize - this is 1MB */
 #define SIZE_MULTIPLE  ((1 << (MMC_CMULT + 2)) * MMC_BL_LEN)
 
 struct sandbox_mmc_priv {
@@ -41,7 +43,6 @@ static int sandbox_mmc_send_cmd(struct udevice *dev, struct 
mmc_cmd *cmd,
struct mmc_data *data)
 {
struct sandbox_mmc_priv *priv = dev_get_priv(dev);
-   struct mmc *mmc = mmc_get_mmc_dev(dev);
static ulong erase_start, erase_end;
 
switch (cmd->cmdidx) {
@@ -95,10 +96,15 @@ static int sandbox_mmc_send_cmd(struct udevice *dev, struct 
mmc_cmd *cmd,
case SD_CMD_ERASE_WR_BLK_END:
erase_end = cmd->cmdarg;
break;
-   case MMC_CMD_ERASE:
+#if CONFIG_IS_ENABLED(MMC_WRITE)
+   case MMC_CMD_ERASE: {
+   struct mmc *mmc = mmc_get_mmc_dev(dev);
+
memset(>buf[erase_start * mmc->write_bl_len], '\0',
   (erase_end - erase_start + 1) * mmc->write_bl_len);
break;
+   }
+#endif
case SD_CMD_APP_SEND_OP_COND:
cmd->response[0] = OCR_BUSY | OCR_HCS;
cmd->response[1] = 0;
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 20/43] dm: blk: mmc: Tidy up some Makefile rules for SPL

2022-10-20 Thread Simon Glass
Use the correct SPL_TPL_ variable so that these features can be enabled in
TPL and VPL as needed.

Disable it by default in TPL to avoid any code-size increase. No boards
are actually using it since the Makefile rules don't allow including
drivers/block/ with TPL_DM enabled. It can be manually enabled as needed.

Signed-off-by: Simon Glass 
Reviewed-by: Jaehoon Chung 
---

(no changes since v2)

Changes in v2:
- Disable TPL_BLK by default

 drivers/Makefile   | 2 +-
 drivers/block/Kconfig  | 1 -
 drivers/block/Makefile | 2 +-
 drivers/mmc/Makefile   | 2 +-
 4 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/Makefile b/drivers/Makefile
index 9d9f69a3c9a..a1700c819de 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0+
 
+obj-$(CONFIG_$(SPL_TPL_)BLK) += block/
 obj-$(CONFIG_$(SPL_TPL_)BOOTCOUNT_LIMIT) += bootcount/
 obj-$(CONFIG_$(SPL_TPL_)BUTTON) += button/
 obj-$(CONFIG_$(SPL_TPL_)CACHE) += cache/
@@ -60,7 +61,6 @@ obj-$(CONFIG_SPL_USB_HOST) += usb/host/
 obj-$(CONFIG_OMAP_USB_PHY) += usb/phy/
 obj-$(CONFIG_SPL_SATA) += ata/ scsi/
 obj-$(CONFIG_SPL_LEGACY_BLOCK) += block/
-obj-$(CONFIG_SPL_BLK) += block/
 obj-$(CONFIG_SPL_THERMAL) += thermal/
 
 endif
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 707e2bcd238..e95da48bdc0 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -37,7 +37,6 @@ config SPL_BLK
 config TPL_BLK
bool "Support block devices in TPL"
depends on TPL_DM && BLK
-   default y
help
  Enable support for block devices, such as SCSI, MMC and USB
  flash sticks. These provide a block-level interface which permits
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index f48d3e12140..19d9317c825 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -3,7 +3,7 @@
 # (C) Copyright 2000-2007
 # Wolfgang Denk, DENX Software Engineering, w...@denx.de.
 
-obj-$(CONFIG_$(SPL_)BLK) += blk-uclass.o
+obj-$(CONFIG_$(SPL_TPL_)BLK) += blk-uclass.o
 
 ifndef CONFIG_$(SPL_)BLK
 obj-$(CONFIG_SPL_LEGACY_BLOCK) += blk_legacy.o
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index 5d5104bbf1d..3a664c2ebbb 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -10,7 +10,7 @@ ifdef CONFIG_$(SPL_TPL_)DM_MMC
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += mmc_bootdev.o
 endif
 
-obj-$(CONFIG_$(SPL_)MMC_WRITE) += mmc_write.o
+obj-$(CONFIG_$(SPL_TPL_)MMC_WRITE) += mmc_write.o
 obj-$(CONFIG_MMC_PWRSEQ) += mmc-pwrseq.o
 obj-$(CONFIG_MMC_SDHCI_ADMA_HELPERS) += sdhci-adma.o
 
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 12/43] test: Update tests to use the skip feature

2022-10-20 Thread Simon Glass
Some tests currently return 0 when they want to be skipped. Update them to
return -EAGAIN instead, so they are counted as skipped.

A few tests are in two parts, with the latter part being skipped in
certain situations. Split these into two and use the correct condition for
the second part.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 test/boot/bootflow.c  |  4 ++--
 test/boot/bootmeth.c  | 13 ++---
 test/boot/vbe_fixup.c |  2 +-
 test/dm/of_platdata.c |  2 +-
 test/dm/ofnode.c  | 25 +++--
 5 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 1e8ea754bcd..e1e07082105 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -330,7 +330,7 @@ static int bootflow_system(struct unit_test_state *uts)
struct udevice *dev;
 
if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR))
-   return 0;
+   return -EAGAIN;
ut_assertok(uclass_get_device_by_name(UCLASS_BOOTMETH, "efi_mgr",
  ));
sandbox_set_fake_efi_mgr_dev(dev, true);
@@ -395,7 +395,7 @@ BOOTSTD_TEST(bootflow_iter_disable, UT_TESTF_DM | 
UT_TESTF_SCAN_FDT);
 static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts)
 {
if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL))
-   return 0;
+   return -EAGAIN;
 
ut_assertok(bootstd_test_drop_bootdev_order(uts));
 
diff --git a/test/boot/bootmeth.c b/test/boot/bootmeth.c
index f0b5ab9adb3..0098ef3efd0 100644
--- a/test/boot/bootmeth.c
+++ b/test/boot/bootmeth.c
@@ -103,10 +103,17 @@ static int bootmeth_cmd_order(struct unit_test_state *uts)
ut_asserteq_str("efi syslinux", env_get("bootmeths"));
ut_assert_console_end();
 
-   /* Try with global bootmeths */
+   return 0;
+}
+BOOTSTD_TEST(bootmeth_cmd_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+
+/* Check 'bootmeth order' command with global bootmeths */
+static int bootmeth_cmd_order_glob(struct unit_test_state *uts)
+{
if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL))
-   return 0;
+   return -EAGAIN;
 
+   console_record_reset_enable();
ut_assertok(run_command("bootmeth order \"efi firmware0\"", 0));
ut_assert_console_end();
ut_assertok(run_command("bootmeth list", 0));
@@ -122,7 +129,7 @@ static int bootmeth_cmd_order(struct unit_test_state *uts)
 
return 0;
 }
-BOOTSTD_TEST(bootmeth_cmd_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootmeth_cmd_order_glob, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
 
 /* Check 'bootmeths' env var */
 static int bootmeth_env(struct unit_test_state *uts)
diff --git a/test/boot/vbe_fixup.c b/test/boot/vbe_fixup.c
index 1b488e25ab6..7f0f809499a 100644
--- a/test/boot/vbe_fixup.c
+++ b/test/boot/vbe_fixup.c
@@ -26,7 +26,7 @@ static int vbe_test_fixup(struct unit_test_state *uts)
 * flat tree, since device tree fix-ups do not yet support live tree.
 */
if (!working_fdt)
-   return 0;
+   return -EAGAIN;
 
tree = oftree_from_fdt(working_fdt);
ut_assert(oftree_valid(tree));
diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c
index 7af798b8d35..a241c427936 100644
--- a/test/dm/of_platdata.c
+++ b/test/dm/of_platdata.c
@@ -150,7 +150,7 @@ static int dm_test_of_plat_dev(struct unit_test_state *uts)
 
/* Skip this test if there is no platform data */
if (!CONFIG_IS_ENABLED(OF_PLATDATA_DRIVER_RT))
-   return 0;
+   return -EAGAIN;
 
/* Record the indexes that are found */
memset(found, '\0', sizeof(found));
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index 41811ec3bb5..8077affabb7 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -753,10 +753,7 @@ static int make_ofnode_fdt(struct unit_test_state *uts, 
void *fdt, int size,
 
 static int dm_test_ofnode_root(struct unit_test_state *uts)
 {
-   char fdt[256];
-   oftree tree;
ofnode node;
-   int ret;
 
/* Check that aliases work on the control FDT */
node = ofnode_get_aliases_node("ethernet3");
@@ -765,14 +762,22 @@ static int dm_test_ofnode_root(struct unit_test_state 
*uts)
 
ut_assert(!oftree_valid(oftree_null()));
 
-   ut_assertok(make_ofnode_fdt(uts, fdt, sizeof(fdt), 0));
-   ret = get_oftree(uts, fdt, );
+   return 0;
+}
+DM_TEST(dm_test_ofnode_root, UT_TESTF_SCAN_FDT);
 
-   /* skip the rest of this test if multiple FDTs are not supported */
-   if (ret == -EOVERFLOW)
-   return 0;
+static int dm_test_ofnode_root_mult(struct unit_test_state *uts)
+{
+   char fdt[256];
+   oftree tree;
+   ofnode node;
 
-   ut_assertok(ret);
+   /* skip this test if multiple FDTs are not supported */
+   if (!IS_ENABLED(CONFIG_OFNODE_MULTI_TREE))
+   return -EAGAIN;
+
+   ut_assertok(make_ofnode_fdt(uts, fdt, sizeof(fdt), 0));
+   

[PATCH v3 13/43] test: Support tests which can only be run manually

2022-10-20 Thread Simon Glass
At present we normally write tests either in Python or in C. But most
Python tests end up doing a lot of checks which would be better done in C.
Checks done in C are orders of magnitude faster and it is possible to get
full access to U-Boot's internal workings, rather than just relying on
the command line.

The model is to have a Python test set up some things and then use C code
(in a unit test) to check that they were done correctly. But we don't want
those checks to happen as part of normal test running, since each C unit
tests is dependent on the associate Python tests, so cannot run without
it.

To acheive this, add a new UT_TESTF_MANUAL flag to use with the C 'check'
tests, so that they can be skipped by default when the 'ut' command is
used. Require that tests have a name ending with '_norun', so that pytest
knows to skip them.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Rebase to master
- Expand docs a little to clarify that manual tests are otherwise normal

 arch/sandbox/cpu/spl.c|  2 +-
 doc/develop/tests_writing.rst | 27 +++
 include/test/test.h   |  8 
 include/test/ut.h |  4 +++-
 test/cmd_ut.c | 16 +---
 test/dm/test-dm.c |  2 +-
 test/py/conftest.py   |  8 +++-
 test/test-main.c  | 27 ++-
 8 files changed, 86 insertions(+), 8 deletions(-)

diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 1d49a9bd102..9c59cc26163 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -89,7 +89,7 @@ void spl_board_init(void)
int ret;
 
ret = ut_run_list("spl", NULL, tests, count,
- state->select_unittests, 1);
+ state->select_unittests, 1, false);
/* continue execution into U-Boot */
}
 }
diff --git a/doc/develop/tests_writing.rst b/doc/develop/tests_writing.rst
index 1ddf7a353a7..bb1145da268 100644
--- a/doc/develop/tests_writing.rst
+++ b/doc/develop/tests_writing.rst
@@ -74,6 +74,33 @@ NOT rely on running with sandbox, but instead should 
function correctly on any
 board supported by U-Boot.
 
 
+Mixing Python and C
+---
+
+The best of both worlds is sometimes to have a Python test set things up and
+perform some operations, with a 'checker' C unit test doing the checks
+afterwards. This can be achieved with these steps:
+
+- Add the `UT_TESTF_MANUAL` flag to the checker test so that the `ut` command
+  does not run it by default
+- Add a `_norun` suffix to the name so that pytest knows to skip it too
+
+In your Python test use the `-f` flag to the `ut` command to force the checker
+test to run it, e.g.::
+
+   # Do the Python part
+   host load ...
+   bootm ...
+
+   # Run the checker to make sure that everything worked
+   ut -f bootstd vbe_test_fixup_norun
+
+Note that apart from the `UT_TESTF_MANUAL` flag, the code in a 'manual' C test
+is just like any other C test. It still uses ut_assert...() and other such
+constructs, in this case to check that the expected things happened in the
+Python test.
+
+
 How slow are Python tests?
 --
 
diff --git a/include/test/test.h b/include/test/test.h
index c1853ce471b..4ad74614afc 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -28,6 +28,7 @@
  * @other_fdt_size: Size of the other FDT (UT_TESTF_OTHER_FDT)
  * @of_other: Live tree for the other FDT
  * @runs_per_test: Number of times to run each test (typically 1)
+ * @force_run: true to run tests marked with the UT_TESTF_MANUAL flag
  * @expect_str: Temporary string used to hold expected string value
  * @actual_str: Temporary string used to hold actual string value
  */
@@ -48,6 +49,7 @@ struct unit_test_state {
int other_fdt_size;
struct device_node *of_other;
int runs_per_test;
+   bool force_run;
char expect_str[512];
char actual_str[512];
 };
@@ -63,6 +65,12 @@ enum {
/* do extra driver model init and uninit */
UT_TESTF_DM = BIT(6),
UT_TESTF_OTHER_FDT  = BIT(7),   /* read in other device tree */
+   /*
+* Only run if explicitly requested with 'ut -f  '. The
+* test name must end in "_norun" so that pytest detects this also,
+* since it cannot access the flags.
+*/
+   UT_TESTF_MANUAL = BIT(8),
 };
 
 /**
diff --git a/include/test/ut.h b/include/test/ut.h
index f7217aa8ac5..e0e618b58c2 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -409,9 +409,11 @@ void test_set_state(struct unit_test_state *uts);
  * @select_name: Name of a single test to run (from the list provided). If NULL
  * then all tests are run
  * @runs_per_test: Number of times to run each test (typically 1)
+ * @force_run: Run tests that are marked as manual-only (UT_TESTF_MANUAL)
  * Return: 0 if all tests passed, -1 if 

[PATCH v3 09/43] binman: Handle writing ELF symbols in the Entry class

2022-10-20 Thread Simon Glass
This feature is used by several etypes and we plan to add more that use
it. Make symbol writing a feature of the base class to reduce the code
duplication.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/entry.py  | 13 +++--
 tools/binman/etype/blob.py |  5 +++--
 tools/binman/etype/u_boot_spl.py   |  7 ++-
 tools/binman/etype/u_boot_spl_nodtb.py |  6 +-
 tools/binman/etype/u_boot_tpl.py   |  6 +-
 tools/binman/etype/u_boot_tpl_nodtb.py |  6 +-
 tools/binman/etype/u_boot_vpl.py   |  6 +-
 tools/binman/etype/u_boot_vpl_nodtb.py |  6 +-
 8 files changed, 21 insertions(+), 34 deletions(-)

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 63ec5cea3b2..bdf53ddd922 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -12,6 +12,7 @@ import sys
 import time
 
 from binman import bintool
+from binman import elf
 from dtoc import fdt_util
 from patman import tools
 from patman.tools import to_hex, to_hex_size
@@ -86,10 +87,15 @@ class Entry(object):
 fake_fname: Fake filename, if one was created, else None
 required_props (dict of str): Properties which must be present. This 
can
 be added to by subclasses
+elf_fname (str): Filename of the ELF file, if this entry holds an ELF
+file, or is a binary file produced from an ELF file
+auto_write_symbols (bool): True to write ELF symbols into this entry's
+contents
 """
 fake_dir = None
 
-def __init__(self, section, etype, node, name_prefix=''):
+def __init__(self, section, etype, node, name_prefix='',
+ auto_write_symbols=False):
 # Put this here to allow entry-docs and help to work without libfdt
 global state
 from binman import state
@@ -125,6 +131,8 @@ class Entry(object):
 self.fake_fname = None
 self.required_props = []
 self.comp_bintool = None
+self.elf_fname = None
+self.auto_write_symbols = auto_write_symbols
 
 @staticmethod
 def FindEntryClass(etype, expanded):
@@ -647,7 +655,8 @@ class Entry(object):
 Args:
   section: Section containing the entry
 """
-pass
+if self.auto_write_symbols:
+elf.LookupAndWriteSymbols(self.elf_fname, self, section.GetImage())
 
 def CheckEntries(self):
 """Check that the entry offsets are correct
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index ceaefb07b73..a50a8068901 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -31,8 +31,9 @@ class Entry_blob(Entry):
 the node (if enabled with -u) which provides the uncompressed size of the
 data.
 """
-def __init__(self, section, etype, node):
-super().__init__(section, etype, node)
+def __init__(self, section, etype, node, auto_write_symbols=False):
+super().__init__(section, etype, node,
+ auto_write_symbols=auto_write_symbols)
 self._filename = fdt_util.GetString(self._node, 'filename', self.etype)
 
 def ObtainContents(self, fake_size=0):
diff --git a/tools/binman/etype/u_boot_spl.py b/tools/binman/etype/u_boot_spl.py
index 6f79bf59f9f..d1aa3b4fdad 100644
--- a/tools/binman/etype/u_boot_spl.py
+++ b/tools/binman/etype/u_boot_spl.py
@@ -5,7 +5,6 @@
 # Entry-type module for spl/u-boot-spl.bin
 #
 
-from binman import elf
 from binman.entry import Entry
 from binman.etype.blob import Entry_blob
 
@@ -35,11 +34,9 @@ class Entry_u_boot_spl(Entry_blob):
 unless --no-expanded is used or the node has a 'no-expanded' property.
 """
 def __init__(self, section, etype, node):
-super().__init__(section, etype, node)
+super().__init__(section, etype, node, auto_write_symbols=True)
 self.elf_fname = 'spl/u-boot-spl'
+self.auto_write_symbols = True
 
 def GetDefaultFilename(self):
 return 'spl/u-boot-spl.bin'
-
-def WriteSymbols(self, section):
-elf.LookupAndWriteSymbols(self.elf_fname, self, section.GetImage())
diff --git a/tools/binman/etype/u_boot_spl_nodtb.py 
b/tools/binman/etype/u_boot_spl_nodtb.py
index 316b38172ef..50a126dc7ef 100644
--- a/tools/binman/etype/u_boot_spl_nodtb.py
+++ b/tools/binman/etype/u_boot_spl_nodtb.py
@@ -5,7 +5,6 @@
 # Entry-type module for 'u-boot-spl-nodtb.bin'
 #
 
-from binman import elf
 from binman.entry import Entry
 from binman.etype.blob import Entry_blob
 
@@ -32,11 +31,8 @@ class Entry_u_boot_spl_nodtb(Entry_blob):
 binman uses that to look up symbols to write into the SPL binary.
 """
 def __init__(self, section, etype, node):
-super().__init__(section, etype, node)
+super().__init__(section, etype, node, auto_write_symbols=True)
 self.elf_fname = 'spl/u-boot-spl'
 
 def GetDefaultFilename(self):
 return 'spl/u-boot-spl-nodtb.bin'
-
-def WriteSymbols(self, 

[PATCH v3 11/43] test: Report skippped tests

2022-10-20 Thread Simon Glass
At present it is possible for a test to skip itself by returning -EAGAIN
but this is not recorded. An existing example is in test_pre_run() with
the "Console recording disabled" check.

Keep a track of skipped tests and report the total at the end.

Signed-off-by: Simon Glass 
Acked-by: Heinrich Schuchardt 
---

Changes in v3:
- Update commit message to mention an existing example

 include/test/test.h |  2 ++
 test/test-main.c| 23 ---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/include/test/test.h b/include/test/test.h
index 3bbd77c38b5..c1853ce471b 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -13,6 +13,7 @@
  * struct unit_test_state - Entire state of test system
  *
  * @fail_count: Number of tests that failed
+ * @skip_count: Number of tests that were skipped
  * @start: Store the starting mallinfo when doing leak test
  * @of_live: true to use livetree if available, false to use flattree
  * @of_root: Record of the livetree root node (used for setting up tests)
@@ -32,6 +33,7 @@
  */
 struct unit_test_state {
int fail_count;
+   int skip_count;
struct mallinfo start;
struct device_node *of_root;
bool of_live;
diff --git a/test/test-main.c b/test/test-main.c
index a98a77d68fc..2323cbaece5 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -356,6 +356,19 @@ static int test_post_run(struct unit_test_state *uts, 
struct unit_test *test)
return 0;
 }
 
+/**
+ * skip_test() - Handle skipping a test
+ *
+ * @uts: Test state to update
+ * @return -EAGAIN (always)
+ */
+static int skip_test(struct unit_test_state *uts)
+{
+   uts->skip_count++;
+
+   return -EAGAIN;
+}
+
 /**
  * ut_run_test() - Run a single test
  *
@@ -386,11 +399,13 @@ static int ut_run_test(struct unit_test_state *uts, 
struct unit_test *test,
 
ret = test_pre_run(uts, test);
if (ret == -EAGAIN)
-   return -EAGAIN;
+   return skip_test(uts);
if (ret)
return ret;
 
-   test->func(uts);
+   ret = test->func(uts);
+   if (ret == -EAGAIN)
+   skip_test(uts);
 
ret = test_post_run(uts, test);
if (ret)
@@ -424,7 +439,7 @@ static int ut_run_test_live_flat(struct unit_test_state 
*uts,
int runs;
 
if ((test->flags & UT_TESTF_OTHER_FDT) && !IS_ENABLED(CONFIG_SANDBOX))
-   return -EAGAIN;
+   return skip_test(uts);
 
/* Run with the live tree if possible */
runs = 0;
@@ -558,6 +573,8 @@ int ut_run_list(const char *category, const char *prefix,
os_free(uts.other_fdt);
}
 
+   if (uts.skip_count)
+   printf("Skipped: %d, ", uts.skip_count);
if (ret == -ENOENT)
printf("Test '%s' not found\n", select_name);
else
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 10/43] binman: Support writing symbols into ELF files

2022-10-20 Thread Simon Glass
In some cases the ELF version of SPL builds may be packaged, rather
than a binary .bin file. Add support for this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/elf.py   | 41 +++
 tools/binman/entry.py |  5 ++-
 tools/binman/etype/section.py |  2 +-
 tools/binman/etype/u_boot_spl_elf.py  |  3 +-
 tools/binman/etype/u_boot_tpl_elf.py  |  3 +-
 tools/binman/etype/u_boot_vpl_elf.py  | 25 
 tools/binman/ftest.py | 57 +++
 tools/binman/test/256_symbols_elf.dts | 27 +
 8 files changed, 151 insertions(+), 12 deletions(-)
 create mode 100644 tools/binman/etype/u_boot_vpl_elf.py
 create mode 100644 tools/binman/test/256_symbols_elf.dts

diff --git a/tools/binman/elf.py b/tools/binman/elf.py
index fec2116880b..fe50bf542c3 100644
--- a/tools/binman/elf.py
+++ b/tools/binman/elf.py
@@ -210,7 +210,7 @@ def GetPackString(sym, msg):
 raise ValueError('%s has size %d: only 4 and 8 are supported' %
  (msg, sym.size))
 
-def LookupAndWriteSymbols(elf_fname, entry, section):
+def LookupAndWriteSymbols(elf_fname, entry, section, is_elf=False):
 """Replace all symbols in an entry with their correct values
 
 The entry contents is updated so that values for referenced symbols will be
@@ -226,27 +226,52 @@ def LookupAndWriteSymbols(elf_fname, entry, section):
 """
 fname = tools.get_input_filename(elf_fname)
 syms = GetSymbols(fname, ['image', 'binman'])
+if is_elf:
+if not ELF_TOOLS:
+msg = ("Section '%s': entry '%s'" %
+   (section.GetPath(), entry.GetPath()))
+raise ValueError(f'{msg}: Cannot write symbols to an ELF file 
without Python elftools')
+new_syms = {}
+with open(fname, 'rb') as fd:
+elf = ELFFile(fd)
+for name, sym in syms.items():
+offset = _GetFileOffset(elf, sym.address)
+new_syms[name] = Symbol(sym.section, sym.address, sym.size,
+sym.weak, offset)
+syms = new_syms
+
 if not syms:
+tout.debug('LookupAndWriteSymbols: no syms')
 return
 base = syms.get('__image_copy_start')
-if not base:
+if not base and not is_elf:
+tout.debug('LookupAndWriteSymbols: no base')
 return
+base_addr = 0 if is_elf else base.address
 for name, sym in syms.items():
 if name.startswith('_binman'):
 msg = ("Section '%s': Symbol '%s'\n   in entry '%s'" %
(section.GetPath(), name, entry.GetPath()))
-offset = sym.address - base.address
-if offset < 0 or offset + sym.size > entry.contents_size:
-raise ValueError('%s has offset %x (size %x) but the contents '
- 'size is %x' % (entry.GetPath(), offset,
- sym.size, 
entry.contents_size))
+if is_elf:
+# For ELF files, use the file offset
+offset = sym.offset
+else:
+# For blobs use the offset of the symbol, calculated by
+# subtracting the base address which by definition is at the
+# start
+offset = sym.address - base.address
+if offset < 0 or offset + sym.size > entry.contents_size:
+raise ValueError('%s has offset %x (size %x) but the 
contents '
+ 'size is %x' % (entry.GetPath(), offset,
+ sym.size,
+ entry.contents_size))
 pack_string = GetPackString(sym, msg)
 if name == '_binman_sym_magic':
 value = BINMAN_SYM_MAGIC_VALUE
 else:
 # Look up the symbol in our entry tables.
 value = section.GetImage().LookupImageSymbol(name, sym.weak,
- msg, base.address)
+ msg, base_addr)
 if value is None:
 value = -1
 pack_string = pack_string.lower()
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index bdf53ddd922..1be31a05e00 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -656,7 +656,10 @@ class Entry(object):
   section: Section containing the entry
 """
 if self.auto_write_symbols:
-elf.LookupAndWriteSymbols(self.elf_fname, self, section.GetImage())
+# Check if we are writing symbols into an ELF file
+is_elf = self.GetDefaultFilename() == self.elf_fname
+elf.LookupAndWriteSymbols(self.elf_fname, self, section.GetImage(),
+  is_elf)
 
 def 

[PATCH v3 07/43] binman: Allow obtaining a symbol value

2022-10-20 Thread Simon Glass
Provide a function to obtain the integer value of an ELF symbol. This will
be used

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/elf.py | 53 ++---
 1 file changed, 45 insertions(+), 8 deletions(-)

diff --git a/tools/binman/elf.py b/tools/binman/elf.py
index 6d440ddf21d..fec2116880b 100644
--- a/tools/binman/elf.py
+++ b/tools/binman/elf.py
@@ -188,6 +188,28 @@ def GetSymbolAddress(fname, sym_name):
 return None
 return sym.address
 
+def GetPackString(sym, msg):
+"""Get the struct.pack/unpack string to use with a given symbol
+
+Args:
+sym (Symbol): Symbol to check. Only the size member is checked
+@msg (str): String which indicates the entry being processed, used for
+errors
+
+Returns:
+str: struct string to use, .e.g. '

[PATCH v3 08/43] binman: Split out looking up a symbol into a function

2022-10-20 Thread Simon Glass
Move this code into its own function so it can be used from tests.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/etype/section.py | 60 ++-
 1 file changed, 45 insertions(+), 15 deletions(-)

diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 621950893f3..f7ef5f89837 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -510,6 +510,50 @@ class Entry_section(Entry):
 source_entry.Raise("Cannot find entry for node '%s'" % node.name)
 return entry.GetData(required)
 
+def LookupEntry(self, entries, sym_name, msg):
+"""Look up the entry for an ENF  symbol
+
+Args:
+entries (dict): entries to search:
+key: entry name
+value: Entry object
+sym_name: Symbol name in the ELF file to look up in the format
+_binman__prop_ where  is the name of
+the entry and  is the property to find (e.g.
+_binman_u_boot_prop_offset). As a special case, you can append
+_any to  to have it search for any matching entry. E.g.
+_binman_u_boot_any_prop_offset will match entries called 
u-boot,
+u-boot-img and u-boot-nodtb)
+msg: Message to display if an error occurs
+
+Returns:
+tuple:
+Entry: entry object that was found
+str: name used to search for entries (uses '-' instead of the
+'_' used by the symbol name)
+str: property name the symbol refers to, e.g. 'image_pos'
+
+Raises:
+ValueError:the symbol name cannot be decoded, e.g. does not have
+a '_binman_' prefix
+"""
+m = re.match(r'^_binman_(\w+)_prop_(\w+)$', sym_name)
+if not m:
+raise ValueError("%s: Symbol '%s' has invalid format" %
+ (msg, sym_name))
+entry_name, prop_name = m.groups()
+entry_name = entry_name.replace('_', '-')
+entry = entries.get(entry_name)
+if not entry:
+if entry_name.endswith('-any'):
+root = entry_name[:-4]
+for name in entries:
+if name.startswith(root):
+rest = name[len(root):]
+if rest in ['', '-img', '-nodtb']:
+entry = entries[name]
+return entry, entry_name, prop_name
+
 def LookupSymbol(self, sym_name, optional, msg, base_addr, entries=None):
 """Look up a symbol in an ELF file
 
@@ -547,23 +591,9 @@ class Entry_section(Entry):
 ValueError if the symbol is invalid or not found, or references a
 property which is not supported
 """
-m = re.match(r'^_binman_(\w+)_prop_(\w+)$', sym_name)
-if not m:
-raise ValueError("%s: Symbol '%s' has invalid format" %
- (msg, sym_name))
-entry_name, prop_name = m.groups()
-entry_name = entry_name.replace('_', '-')
 if not entries:
 entries = self._entries
-entry = entries.get(entry_name)
-if not entry:
-if entry_name.endswith('-any'):
-root = entry_name[:-4]
-for name in entries:
-if name.startswith(root):
-rest = name[len(root):]
-if rest in ['', '-img', '-nodtb']:
-entry = entries[name]
+entry, entry_name, prop_name = self.LookupEntry(entries, sym_name, msg)
 if not entry:
 err = ("%s: Entry '%s' not found in list (%s)" %
(msg, entry_name, ','.join(entries.keys(
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 05/43] spl: Refactor controls for console output

2022-10-20 Thread Simon Glass
The expression in boot_from_devices() is fairly long and appears to be an
artefact from before we could easily call printf(...) and have the call be
nop'd out. So update it to just check CONFIG_SILENT_CONSOLE.

Signed-off-by: Simon Glass 
Suggested-by: Tom Rini 
---

(no changes since v1)

 common/spl/spl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 10475cd3d11..91b4adc4004 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -703,9 +703,7 @@ static int boot_from_devices(struct spl_image_info 
*spl_image,
if (CONFIG_IS_ENABLED(SHOW_ERRORS))
ret = -ENXIO;
loader = spl_ll_find_loader(bootdev);
-   if (CONFIG_IS_ENABLED(SERIAL) &&
-   CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT) &&
-   !IS_ENABLED(CONFIG_SILENT_CONSOLE)) {
+   if (!IS_ENABLED(CONFIG_SILENT_CONSOLE)) {
if (loader)
printf("Trying to boot from %s\n",
   spl_loader_name(loader));
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 06/43] spl: Add a separate silence option for SPL

2022-10-20 Thread Simon Glass
Add an option to allow silent console to be controlled separately in SPL,
so that boot progress can be shown. Disable it by default for sandbox
since it is useful to see what is going on there.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Refactor based on a change to the earlier patch in spl.c

 common/Kconfig   | 22 ++
 common/spl/spl.c |  2 +-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/common/Kconfig b/common/Kconfig
index 6608a4f0fc1..5926645b3c3 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -113,6 +113,28 @@ config SILENT_CONSOLE
  GD_FLG_SILENT flag is set. Changing the environment variable later
  will update the flag.
 
+config SPL_SILENT_CONSOLE
+   bool "Use a silent console in SPL"
+   default y if SILENT_CONSOLE && !SANDBOX
+   help
+ This selects a silent console in SPL. When enabled it drops some
+ output messages. The GD_FLG_SILENT flag is not used in SPL so there
+ is no run-time control of console messages in SPL.
+
+ Future work may allow the SPL console to be silenced completely using
+ this option.
+
+config TPL_SILENT_CONSOLE
+   bool "Use a silent console in TPL"
+   default y if SILENT_CONSOLE && !SANDBOX
+   help
+ This selects a silent console in TPL. When enabled it drops some
+ output messages. The GD_FLG_SILENT flag is not used in TPL so there
+ is no run-time control of console messages in TPL.
+
+ Future work may allow the TPL console to be silenced completely using
+ this option.
+
 config SILENT_U_BOOT_ONLY
bool "Only silence the U-Boot console"
depends on SILENT_CONSOLE
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 91b4adc4004..4635e77e979 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -703,7 +703,7 @@ static int boot_from_devices(struct spl_image_info 
*spl_image,
if (CONFIG_IS_ENABLED(SHOW_ERRORS))
ret = -ENXIO;
loader = spl_ll_find_loader(bootdev);
-   if (!IS_ENABLED(CONFIG_SILENT_CONSOLE)) {
+   if (!CONFIG_IS_ENABLED(SILENT_CONSOLE)) {
if (loader)
printf("Trying to boot from %s\n",
   spl_loader_name(loader));
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 04/43] spl: Use binman suffix allow symbols of any SPL etype

2022-10-20 Thread Simon Glass
At present we use symbols for the u-boot-spl entry, but this is not always
what we want. For example, sandbox actually jumps to a u-boot-spl-elf
entry, since sandbox executables are ELF files.

We already handle this with U-Boot by using the '-any' suffix. Add it for
SPL as well.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/spl/spl.c | 16 
 include/spl.h|  8 
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 41594fc6121..10475cd3d11 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -59,13 +59,13 @@ binman_sym_declare(ulong, u_boot_any, image_pos);
 binman_sym_declare(ulong, u_boot_any, size);
 
 #ifdef CONFIG_TPL
-binman_sym_declare(ulong, u_boot_spl, image_pos);
-binman_sym_declare(ulong, u_boot_spl, size);
+binman_sym_declare(ulong, u_boot_spl_any, image_pos);
+binman_sym_declare(ulong, u_boot_spl_any, size);
 #endif
 
 #ifdef CONFIG_VPL
-binman_sym_declare(ulong, u_boot_vpl, image_pos);
-binman_sym_declare(ulong, u_boot_vpl, size);
+binman_sym_declare(ulong, u_boot_vpl_any, image_pos);
+binman_sym_declare(ulong, u_boot_vpl_any, size);
 #endif
 
 #endif /* BINMAN_UBOOT_SYMBOLS */
@@ -164,10 +164,10 @@ ulong spl_get_image_pos(void)
 
 #ifdef CONFIG_VPL
if (spl_next_phase() == PHASE_VPL)
-   return binman_sym(ulong, u_boot_vpl, image_pos);
+   return binman_sym(ulong, u_boot_vpl_any, image_pos);
 #endif
return spl_next_phase() == PHASE_SPL ?
-   binman_sym(ulong, u_boot_spl, image_pos) :
+   binman_sym(ulong, u_boot_spl_any, image_pos) :
binman_sym(ulong, u_boot_any, image_pos);
 }
 
@@ -178,10 +178,10 @@ ulong spl_get_image_size(void)
 
 #ifdef CONFIG_VPL
if (spl_next_phase() == PHASE_VPL)
-   return binman_sym(ulong, u_boot_vpl, size);
+   return binman_sym(ulong, u_boot_vpl_any, size);
 #endif
return spl_next_phase() == PHASE_SPL ?
-   binman_sym(ulong, u_boot_spl, size) :
+   binman_sym(ulong, u_boot_spl_any, size) :
binman_sym(ulong, u_boot_any, size);
 }
 
diff --git a/include/spl.h b/include/spl.h
index bac5ea29b7d..a89830d24fd 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -286,10 +286,10 @@ struct spl_load_info {
  */
 binman_sym_extern(ulong, u_boot_any, image_pos);
 binman_sym_extern(ulong, u_boot_any, size);
-binman_sym_extern(ulong, u_boot_spl, image_pos);
-binman_sym_extern(ulong, u_boot_spl, size);
-binman_sym_extern(ulong, u_boot_vpl, image_pos);
-binman_sym_extern(ulong, u_boot_vpl, size);
+binman_sym_extern(ulong, u_boot_spl_any, image_pos);
+binman_sym_extern(ulong, u_boot_spl_any, size);
+binman_sym_extern(ulong, u_boot_vpl_any, image_pos);
+binman_sym_extern(ulong, u_boot_vpl_any, size);
 
 /**
  * spl_get_image_pos() - get the image position of the next phase
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 03/43] disk: Drop debug messages in part_efi

2022-10-20 Thread Simon Glass
This is monstrously verbose when something goes wrong. It should work by
recording the problem and reporting it (once) at the command level. At
present it sometimes outputs hundreds of lines of CRC mismatches.

For now, just silence it all.

  GUID Partition Table Entry Array CRC is wrong: 0xaebfebf2 != 0xc916f712
  find_valid_gpt: *** ERROR: Invalid GPT ***
  find_valid_gpt: ***Using Backup GPT ***
  GUID Partition Table Entry Array CRC is wrong: 0xaebfebf2 != 0xc916f712
  find_valid_gpt: *** ERROR: Invalid GPT ***
  find_valid_gpt: ***Using Backup GPT ***
  ...

While we are error, remove the '*** ERROR: ' text as it is already clear
that this is unexpected

Signed-off-by: Simon Glass 
Suggested-by: Heinrich Schuchardt 
---

Changes in v3:
- Drop the *** from strings also

Changes in v2:
- Drop the '*** ERROR: ' text as it is already clear that it is unexpected
- Fix exceds typo

 disk/part_efi.c | 150 +++-
 1 file changed, 72 insertions(+), 78 deletions(-)

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 26738a57d5d..18f7e584050 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -94,10 +94,10 @@ static int validate_gpt_header(gpt_header *gpt_h, lbaint_t 
lba,
 
/* Check the GPT header signature */
if (le64_to_cpu(gpt_h->signature) != GPT_HEADER_SIGNATURE_UBOOT) {
-   printf("%s signature is wrong: 0x%llX != 0x%llX\n",
-  "GUID Partition Table Header",
-  le64_to_cpu(gpt_h->signature),
-  GPT_HEADER_SIGNATURE_UBOOT);
+   log_debug("%s signature is wrong: %#llX != %#llX\n",
+ "GUID Partition Table Header",
+ le64_to_cpu(gpt_h->signature),
+ GPT_HEADER_SIGNATURE_UBOOT);
return -1;
}
 
@@ -111,9 +111,9 @@ static int validate_gpt_header(gpt_header *gpt_h, lbaint_t 
lba,
memcpy(_h->header_crc32, _backup, sizeof(crc32_backup));
 
if (calc_crc32 != le32_to_cpu(crc32_backup)) {
-   printf("%s CRC is wrong: 0x%x != 0x%x\n",
-  "GUID Partition Table Header",
-  le32_to_cpu(crc32_backup), calc_crc32);
+   log_debug("%s: CRC is wrong: %#x != %#x\n",
+ "GUID Partition Table Header",
+ le32_to_cpu(crc32_backup), calc_crc32);
return -1;
}
 
@@ -121,9 +121,8 @@ static int validate_gpt_header(gpt_header *gpt_h, lbaint_t 
lba,
 * Check that the my_lba entry points to the LBA that contains the GPT
 */
if (le64_to_cpu(gpt_h->my_lba) != lba) {
-   printf("GPT: my_lba incorrect: %llX != " LBAF "\n",
-  le64_to_cpu(gpt_h->my_lba),
-  lba);
+   log_debug("GPT: my_lba incorrect: %llX != " LBAF "\n",
+ le64_to_cpu(gpt_h->my_lba), lba);
return -1;
}
 
@@ -132,13 +131,13 @@ static int validate_gpt_header(gpt_header *gpt_h, 
lbaint_t lba,
 * within the disk.
 */
if (le64_to_cpu(gpt_h->first_usable_lba) > lastlba) {
-   printf("GPT: first_usable_lba incorrect: %llX > " LBAF "\n",
-  le64_to_cpu(gpt_h->first_usable_lba), lastlba);
+   log_debug("GPT: first_usable_lba incorrect: %llX > " LBAF "\n",
+ le64_to_cpu(gpt_h->first_usable_lba), lastlba);
return -1;
}
if (le64_to_cpu(gpt_h->last_usable_lba) > lastlba) {
-   printf("GPT: last_usable_lba incorrect: %llX > " LBAF "\n",
-  le64_to_cpu(gpt_h->last_usable_lba), lastlba);
+   log_debug("GPT: last_usable_lba incorrect: %llX > " LBAF "\n",
+ le64_to_cpu(gpt_h->last_usable_lba), lastlba);
return -1;
}
 
@@ -159,10 +158,10 @@ static int validate_gpt_entries(gpt_header *gpt_h, 
gpt_entry *gpt_e)
le32_to_cpu(gpt_h->sizeof_partition_entry));
 
if (calc_crc32 != le32_to_cpu(gpt_h->partition_entry_array_crc32)) {
-   printf("%s: 0x%x != 0x%x\n",
-  "GUID Partition Table Entry Array CRC is wrong",
-  le32_to_cpu(gpt_h->partition_entry_array_crc32),
-  calc_crc32);
+   log_debug("%s: %#x != %#x\n",
+ "GUID Partition Table Entry Array CRC is wrong",
+ le32_to_cpu(gpt_h->partition_entry_array_crc32),
+ calc_crc32);
return -1;
}
 
@@ -274,7 +273,7 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part,
 
if (part > le32_to_cpu(gpt_head->num_partition_entries) ||
!is_pte_valid(_pte[part - 1])) {
-   log_debug("*** ERROR: Invalid partition number %d ***\n", part);
+   log_debug("Invalid partition 

[PATCH v3 01/43] WIP: gitlab: Install pyelftools

2022-10-20 Thread Simon Glass
This should not need to be applied if the Dockerfile update is taken.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Move the gitlab change into an RFC patch

 .gitlab-ci.yml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6f4c34fc4a3..4882fe4c3e9 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -34,6 +34,7 @@ stages:
 # If we've been asked to use clang only do one configuration.
 - export UBOOT_TRAVIS_BUILD_DIR=/tmp/${TEST_PY_BD}
 - echo BUILD_ENV ${BUILD_ENV}
+- pip install pyelftools
 - tools/buildman/buildman -o ${UBOOT_TRAVIS_BUILD_DIR} -w -E -W -e
 --board ${TEST_PY_BD} ${OVERRIDE}
 - cp ~/grub_x86.efi $UBOOT_TRAVIS_BUILD_DIR/
@@ -112,6 +113,7 @@ build all PowerPC platforms:
 build all other platforms:
   stage: world build
   script:
+- pip install pyelftools
 - ret=0;
   ./tools/buildman/buildman -o /tmp -P -E -W -x arm,powerpc || ret=$?;
   if [[ $ret -ne 0 ]]; then
-- 
2.38.0.135.g90850a2211-goog



[PATCH v3 00/43] vbe: Implement the full firmware flow

2022-10-20 Thread Simon Glass
This series provides an implementation of VBE from TPL through to U-Boot
proper, using VBE to load the relevant firmware stages. It buils a single
image.bin file containing all the phases:

   TPL - initial phase, loads VPL using binman symbols
   VPL - main firmware phase, loads SPL using VBE parameters
   SPL - loads U-Boot proper using VBE parameters
   U-Boot - final firmware phase, where OS booting is processed

This series does not include the OS-booting phase. That will be the
subject of a future series.

The implementation is entirely handled by sandbox. It should be possible
to enable this on a real board without much effort, but that is also the
subject of a future series.

Changes in v3:
- Drop the *** from strings also
- Update commit message to mention an existing example
- Add comments to the renamed functions

Changes in v2:
- Move the gitlab change into an RFC patch
- Rebase to master
- Drop the '*** ERROR: ' text as it is already clear that it is unexpected
- Fix exceds typo
- Refactor based on a change to the earlier patch in spl.c
- Rebase to master
- Expand docs a little to clarify that manual tests are otherwise normal
- Add new patch to rename block functions
- Add new patch to rename block_dev to desc in disc-uclass.c
- Add a note as to why we have almost-duplicated code in two places
- Rebase to master
- Disable TPL_BLK by default
- Update the comment style
- Attach the phase to the image node instead of the configuration node
- Update the documentation too
- Attach the phase to the image node instead of the configuration node
- Attach the phase to the image node instead of the configuration node
- Add signature checking / hashing to make the image more realistic
- Add new patch to allow signature verification
- Drop patch 'rsa: Avoid warning in padding_pss_verify()'

Simon Glass (43):
  WIP: gitlab: Install pyelftools
  Rename CONFIG_SYS_TEXT_BASE to CONFIG_TEXT_BASE
  disk: Drop debug messages in part_efi
  spl: Use binman suffix allow symbols of any SPL etype
  spl: Refactor controls for console output
  spl: Add a separate silence option for SPL
  binman: Allow obtaining a symbol value
  binman: Split out looking up a symbol into a function
  binman: Handle writing ELF symbols in the Entry class
  binman: Support writing symbols into ELF files
  test: Report skippped tests
  test: Update tests to use the skip feature
  test: Support tests which can only be run manually
  bootstd: Add a way to set up a bootflow
  disk: Rename block functions
  disk: Rename block_dev to desc
  dm: blk: Add udevice functions
  usb: Update the test to cover reading and writing
  bloblist: Drop debugging
  dm: blk: mmc: Tidy up some Makefile rules for SPL
  dm: mmc: Allow sandbox emulator to build without writes
  sandbox: Drop message about writing sandbox state
  image: Move comment for fit_conf_find_compat()
  sandbox: Generalise SPL booting
  sandbox: Add a way to specify the sandbox executable
  image: Add the concept of a phase to FIT
  image: Allow loading a FIT image for a particular phase
  vbe: Rename vbe_fixup to vbe_request
  vbe: Use a warning for a failed requests
  spl: Allow multiple loaders of the same time
  sandbox: Support obtaining the next phase from an image
  vbe: Support selecting operations by SPL phase
  vbe: Support reading the next SPL phase via VBE
  vbe: Move OS implementation into a separate file
  vbe: Drop the U-Boot prefix from the version
  vbe: Add Kconfig options for VPL
  vbe: Add info about the VBE device to the fwupd node
  sandbox: Add an image for VPL
  vpl: Allow signature verification
  vbe: Use a manual test
  vbe: Record which phases loaded using VBE
  vbe: Add a command to show the VBE state
  vbe: Add a test for the VBE flow into U-Boot proper

 .gitlab-ci.yml|   2 +
 Kconfig   |   2 +-
 Makefile  |  26 +-
 arch/arc/cpu/u-boot.lds   |   2 +-
 arch/arm/Kconfig  |   2 +-
 arch/arm/cpu/arm1176/start.S  |   2 +-
 arch/arm/cpu/arm926ejs/mxs/Makefile   |   4 +-
 arch/arm/cpu/armv7/ls102xa/fdt.c  |   6 +-
 .../armv8/linux-kernel-image-header-vars.h|   2 +-
 arch/arm/cpu/armv8/start.S|   2 +-
 .../dts/fsl-ls1028a-kontron-sl28-u-boot.dtsi  |   2 +-
 arch/arm/dts/imx8mm-u-boot.dtsi   |   2 +-
 arch/arm/dts/imx8mn-beacon-kit-u-boot.dtsi|   2 +-
 .../dts/imx8mn-bsh-smm-s2-u-boot-common.dtsi  |   2 +-
 arch/arm/dts/imx8mn-ddr4-evk-u-boot.dtsi  |   2 +-
 arch/arm/dts/imx8mn-evk-u-boot.dtsi   |   2 +-
 .../dts/imx8mn-var-som-symphony-u-boot.dtsi   |   2 +-
 arch/arm/dts/imx8mn-venice-u-boot.dtsi|   2 +-
 arch/arm/dts/imx8mp-u-boot.dtsi   |   2 +-
 arch/arm/dts/imx8mq-cm-u-boot.dtsi|   2 +-
 arch/arm/dts/imx8mq-u-boot.dtsi   |   2 +-
 arch/arm/dts/rockchip-optee.dtsi  |   2 +-

[PATCH 3/3] highbank: switch to use the Arm SP804 DM_TIMER driver

2022-10-20 Thread Andre Przywara
So far the Calxeda machines were using the CONFIG_SYS_TIMER_* macros to
simply hardcode the address of the counter register of the SP804 timer.
This method is deprecated and scheduled for removal.

Use the newly introduced SP804 DM_TIMER driver to provide timer
functionality on Highbank and Midway machines. The base address and base
frequency are taken from the devicetree.

Signed-off-by: Andre Przywara 
---
 arch/arm/Kconfig   | 2 ++
 include/configs/highbank.h | 4 
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 2e833940525..3269d0c5196 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -793,6 +793,8 @@ config ARCH_HIGHBANK
select AHCI
select DM_ETH
select PHYS_64BIT
+   select TIMER
+   select SP804_TIMER
imply OF_HAS_PRIOR_STAGE
 
 config ARCH_INTEGRATOR
diff --git a/include/configs/highbank.h b/include/configs/highbank.h
index bb6cc957261..5e2b50bbac1 100644
--- a/include/configs/highbank.h
+++ b/include/configs/highbank.h
@@ -8,10 +8,6 @@
 
 #define CONFIG_SYS_BOOTMAPSZ   (16 << 20)
 
-#define CONFIG_SYS_TIMER_RATE  (15000/256)
-#define CONFIG_SYS_TIMER_COUNTER   (0xFFF34000 + 0x4)
-#define CONFIG_SYS_TIMER_COUNTS_DOWN
-
 #define CONFIG_PL011_CLOCK 15000
 
 /*
-- 
2.25.1



[PATCH 2/3] highbank: scan into hb_sregs DT subnodes

2022-10-20 Thread Andre Przywara
The DT used for Calxeda Highbank and Midway systems exposes a "system
registers" block, modeled as a DT subnode.
This includes several clocks, including the two fixed clocks for the
main oscillator and timer.

So far U-Boot was ignorant of this special construct (a "clocks" node
within the "hb-sregs" node), as it didn't need the PLL clocks in there.
But that also meant we lost the fixed clocks, which form the base for
the UART baudrate generator and also the SP804 timer.

To allow the generic PL011 and SP804 driver to read the clock rate,
add a simple bus driver, which triggers the DT node discovery inside this
special node. As we only care about the fixed clocks (we don't have
drivers for the PLLs anyway), just ignore the address translation (for
now).

The binding is described in bindings/arm/calxeda/hb-sregs.yaml, the DT
snippet in question looks like:

===
sregs@fff3c000 {
compatible = "calxeda,hb-sregs";
reg = <0xfff3c000 0x1000>;

clocks {
#address-cells = <1>;
#size-cells = <0>;

osc: oscillator {
#clock-cells = <0>;
compatible = "fixed-clock";
clock-frequency = <3000>;
};

};
};
===

Signed-off-by: Andre Przywara 
---
 board/highbank/Makefile   |  2 +-
 board/highbank/hb_sregs.c | 45 +++
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 board/highbank/hb_sregs.c

diff --git a/board/highbank/Makefile b/board/highbank/Makefile
index 57f7f2e2a65..9e432119849 100644
--- a/board/highbank/Makefile
+++ b/board/highbank/Makefile
@@ -3,4 +3,4 @@
 # (C) Copyright 2000-2006
 # Wolfgang Denk, DENX Software Engineering, w...@denx.de.
 
-obj-y  := highbank.o ahci.o
+obj-y  := highbank.o ahci.o hb_sregs.o
diff --git a/board/highbank/hb_sregs.c b/board/highbank/hb_sregs.c
new file mode 100644
index 000..d9dd2c2bf67
--- /dev/null
+++ b/board/highbank/hb_sregs.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Calxeda Highbank/Midway "system registers" bus driver
+ *
+ * There is a "clocks" subnode inside the top node, which groups all clocks,
+ * both programmable PLLs as well as fixed clocks.
+ * Simple allow the DT enumeration to look inside this node, so that we can
+ * read the fixed clock frequencies using the DM clock framework.
+ *
+ * Copyright (C) 2019 Arm Ltd.
+ */
+
+#include 
+#include 
+#include 
+
+static int hb_sregs_scan_fdt_dev(struct udevice *dev)
+{
+   ofnode clock_node, node;
+
+   /* Search for subnode called "clocks". */
+   ofnode_for_each_subnode(clock_node, dev_ofnode(dev)) {
+   if (!ofnode_name_eq(clock_node, "clocks"))
+   continue;
+
+   /* Enumerate all nodes inside this "clocks" subnode. */
+   ofnode_for_each_subnode(node, clock_node)
+   lists_bind_fdt(dev, node, NULL, NULL, false);
+   return 0;
+   }
+
+   return -ENOENT;
+}
+
+static const struct udevice_id highbank_sreg_ids[] = {
+   { .compatible = "calxeda,hb-sregs" },
+   {}
+};
+
+U_BOOT_DRIVER(hb_sregs) = {
+   .name = "hb-sregs",
+   .id = UCLASS_SIMPLE_BUS,
+   .bind = hb_sregs_scan_fdt_dev,
+   .of_match = highbank_sreg_ids,
+};
-- 
2.25.1



[PATCH 1/3] timer: add SP804 UCLASS timer driver

2022-10-20 Thread Andre Przywara
The "Arm Ltd. Dual-Timer Module (SP804)" is a simple 32-bit count-down
timer IP with interrupt functionality, and is used in some SoCs from
various vendors.

Add a simple DM compliant timer driver, to allow users of the SP804 to
switch to DM_TIMER.

This relies on the input clock to be accessible via the DM clock
framework, which should be fine as we probably look at fixed-clock's
here anyway.
We re-program the control register in the probe() function, but keep
the divider in place, in case this has been set to something on purpose
before.

The TRM for the timer IP can be found here:
https://developer.arm.com/documentation/ddi0271/latest

Signed-off-by: Andre Przywara 
---
 drivers/timer/Kconfig   |   6 ++
 drivers/timer/Makefile  |   1 +
 drivers/timer/sp804_timer.c | 108 
 3 files changed, 115 insertions(+)
 create mode 100644 drivers/timer/sp804_timer.c

diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
index fd8745ffc2e..22da516f045 100644
--- a/drivers/timer/Kconfig
+++ b/drivers/timer/Kconfig
@@ -230,6 +230,12 @@ config SANDBOX_TIMER
  Select this to enable an emulated timer for sandbox. It gets
  time from host os.
 
+config SP804_TIMER
+   bool "ARM SP804 timer support"
+   depends on TIMER
+   help
+ ARM SP804 dual timer IP support
+
 config STI_TIMER
bool "STi timer support"
depends on TIMER
diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
index 7bfb7749e97..ec332943876 100644
--- a/drivers/timer/Makefile
+++ b/drivers/timer/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_RENESAS_OSTM_TIMER) += ostm_timer.o
 obj-$(CONFIG_RISCV_TIMER) += riscv_timer.o
 obj-$(CONFIG_ROCKCHIP_TIMER) += rockchip_timer.o
 obj-$(CONFIG_SANDBOX_TIMER)+= sandbox_timer.o
+obj-$(CONFIG_SP804_TIMER)  += sp804_timer.o
 obj-$(CONFIG_$(SPL_)SIFIVE_CLINT) += sifive_clint_timer.o
 obj-$(CONFIG_STI_TIMER)+= sti-timer.o
 obj-$(CONFIG_STM32_TIMER)  += stm32_timer.o
diff --git a/drivers/timer/sp804_timer.c b/drivers/timer/sp804_timer.c
new file mode 100644
index 000..8fd4afb15a5
--- /dev/null
+++ b/drivers/timer/sp804_timer.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * ARM PrimeCell Dual-Timer Module (SP804) driver
+ * Copyright (C) 2022 Arm Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define SP804_TIMERX_LOAD  0x00
+#define SP804_TIMERX_VALUE 0x04
+#define SP804_TIMERX_CONTROL   0x08
+
+#define SP804_CTRL_TIMER_ENABLE(1U << 7)
+#define SP804_CTRL_TIMER_PERIODIC  (1U << 6)
+#define SP804_CTRL_INT_ENABLE  (1U << 5)
+#define SP804_CTRL_TIMER_PRESCALE_SHIFT2
+#define SP804_CTRL_TIMER_PRESCALE_MASK (3U << SP804_CTRL_TIMER_PRESCALE_SHIFT)
+#define SP804_CTRL_TIMER_32BIT (1U << 1)
+#define SP804_CTRL_ONESHOT (1U << 0)
+
+
+struct sp804_timer_plat {
+   uintptr_t base;
+};
+
+static u64 sp804_timer_get_count(struct udevice *dev)
+{
+   struct sp804_timer_plat *plat = dev_get_plat(dev);
+   uint32_t cntr = readl(plat->base + SP804_TIMERX_VALUE);
+
+   /* timers are down-counting */
+   return ~0u - cntr;
+}
+
+static int sp804_clk_of_to_plat(struct udevice *dev)
+{
+   struct sp804_timer_plat *plat = dev_get_plat(dev);
+
+   plat->base = dev_read_addr(dev);
+   if (!plat->base)
+   return -ENOENT;
+
+   return 0;
+}
+
+static int sp804_timer_probe(struct udevice *dev)
+{
+   struct sp804_timer_plat *plat = dev_get_plat(dev);
+   struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+   struct clk base_clk;
+   unsigned int divider = 1;
+   uint32_t ctlr;
+   int ret;
+
+   ctlr = readl(plat->base + SP804_TIMERX_CONTROL);
+   ctlr &= SP804_CTRL_TIMER_PRESCALE_MASK;
+   switch (ctlr >> SP804_CTRL_TIMER_PRESCALE_SHIFT) {
+   case 0x0: divider = 1; break;
+   case 0x1: divider = 16; break;
+   case 0x2: divider = 256; break;
+   case 0x3: printf("illegal!\n"); break;
+   }
+
+   ret = clk_get_by_index(dev, 0, _clk);
+   if (ret) {
+   printf("could not find SP804 timer base clock in DT\n");
+   return ret;
+   }
+
+   uc_priv->clock_rate = clk_get_rate(_clk) / divider;
+
+   /* keep divider, free-running, wrapping, no IRQs, 32-bit mode */
+   ctlr |= SP804_CTRL_TIMER_32BIT | SP804_CTRL_TIMER_ENABLE;
+   writel(ctlr, plat->base + SP804_TIMERX_CONTROL);
+
+   return 0;
+}
+
+static const struct timer_ops sp804_timer_ops = {
+   .get_count = sp804_timer_get_count,
+};
+
+static const struct udevice_id sp804_timer_ids[] = {
+   { .compatible = "arm,sp804" },
+   {}
+};
+
+U_BOOT_DRIVER(arm_sp804_timer) = {
+   .name   = "arm_sp804_timer",
+   .id = UCLASS_TIMER,
+   .of_match  

[PATCH 0/3] timer: add SP804 DM_TIMER driver (and use it)

2022-10-20 Thread Andre Przywara
Some boards were using an ARM SP804 timer IP, but were driving that
using hardcoded addresses and input frequencies, using the
CONFIG_SYS_TIMER_* macros. This is deprecated and scheduled for removal.

This series adds a DM_TIMER compliant SP804 driver in patch 1, and lets
the Highbank board use that (patch 3).
Since the Highbank DT somewhat hides the timer base fixed-clock inside
a subnode, we need some simple-bus like driver in patch 2 to help the
driver find the timer frequency.

The SP804 driver should be usable by other SoCs using the SP804 timer,
but I don't have any to test it there.

Cheers,
Andre

Andre Przywara (3):
  timer: add SP804 UCLASS timer driver
  highbank: scan into hb_sregs DT subnodes
  highbank: switch to use the Arm SP804 DM_TIMER driver

 arch/arm/Kconfig|   2 +
 board/highbank/Makefile |   2 +-
 board/highbank/hb_sregs.c   |  45 +++
 drivers/timer/Kconfig   |   6 ++
 drivers/timer/Makefile  |   1 +
 drivers/timer/sp804_timer.c | 108 
 include/configs/highbank.h  |   4 --
 7 files changed, 163 insertions(+), 5 deletions(-)
 create mode 100644 board/highbank/hb_sregs.c
 create mode 100644 drivers/timer/sp804_timer.c

-- 
2.25.1



[PATCH] arm: armada: dts: Add clock to armada-ap80x uart1

2022-10-20 Thread Hamish Martin
The uart1 node was missing the 'clock-frequency' property. This meant
the driver for this device would fail at probe.
The clock for uart1 is fed from the same source as uart0 and is a fixed
200MHz clock. This is confirmed via documentation for the CN9130 SoC
and from the equivalent code in Linux at:
/arch/arm64/boot/dts/marvell/armada-ap80x.dtsi
where uart0 and uart1 share a common 'clocks' definition.

Signed-off-by: Hamish Martin 
---
 arch/arm/dts/armada-ap80x.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/dts/armada-ap80x.dtsi b/arch/arm/dts/armada-ap80x.dtsi
index 8787a872d85e..ab3c32e0e586 100644
--- a/arch/arm/dts/armada-ap80x.dtsi
+++ b/arch/arm/dts/armada-ap80x.dtsi
@@ -181,7 +181,7 @@
reg-io-width = <1>;
clocks = <_syscon 3>;
status = "disabled";
-
+   clock-frequency = <2>;
};
 
watchdog: watchdog@61 {
-- 
2.37.3



Re: [maemo-leste] Broken u-boot on n900 hw (possibly CONFIG_POSITION_INDEPENDENT)

2022-10-20 Thread Pali Rohár
On Monday 10 October 2022 23:30:21 Sicelo wrote:
> On Sun, Oct 09, 2022 at 09:33:17PM +0200, Pali Rohár wrote:
> > Hello!
> > 
> > Current u-boot from master branch does not work on n900 hw. It does not
> > show anything on display, there just nokia logo.
> > 
> > In qemu it is working fine and all tests are passing. Also in qemu is
> > display working without any problem.
> > 
> > Could you help me to debug it? Maybe something is printed to serial
> > console? Or maybe serial console could be used for printf-debugging?
> > 
> > I just figured out that disabling CONFIG_POSITION_INDEPENDENT u-boot
> > option make it working again. But it requires to restoring older version
> > of lowlevel_init.S file which does not depend on POSITION_INDEPENDENT:
> > 
> > git checkout 7c4ad9821758f98db127e9d6864671c906c02d3b -- 
> > board/nokia/rx51/lowlevel_init.S
> > 
> > And also setting CONFIG_SYS_TEXT_BASE=0x80008000 (to some value in RAM).
> 
> Hi
> 
> I have a really crude serial console setup in place now, but very little
> time, and even less experience with u-boot. I should be able to do the
> tests for you on Saturday night (UTC+2). Perhaps over IRC might be a
> good idea, in case I need some hand-holding, and if you still need the
> help by then.
> 
> Regards
> Sicelo

Well, I do not know where to start or how to instruct somebody who is
not experienced with u-boot debugging. I think that the first step
should be to look if U-Boot prints something on the serial console or
not. If it prints then try to find via printf-driven-debugging place
where it stuck. If it does not print anything on the console then try to
setup debug early console, check if it prints something now and do same
type of debugging. And if even early debug console does not work then
probably initialize serial console directly in lowlevel_init.S file,
prints something to serial, then move code for printing to later stage
and try to figure out what is broken...

Anybody else with serial console can look at it?

Or maybe look at the code if you spot some issue there?


Re: [PATCH v2 2/5] Makefile: Correct a missing FORCE on the binman rule

2022-10-20 Thread Pali Rohár
On Wednesday 19 October 2022 19:55:43 Simon Glass wrote:
> Hi Pali,
> 
> On Sun, 16 Oct 2022 at 04:16, Pali Rohár  wrote:
> >
> > On Tuesday 11 October 2022 23:35:22 Masahiro Yamada wrote:
> > > On Tue, Oct 11, 2022 at 11:16 PM Simon Glass  wrote:
> > > >
> > > > This is required for if_changed to work correctly. Add it.
> > > >
> > > > Signed-off-by: Simon Glass 
> > > > Reviewed-by: Pali Rohár 
> > > > ---
> > > >
> > > > (no changes since v1)
> > > >
> > > >  Makefile | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/Makefile b/Makefile
> > > > index 3866cc62f9a..d28e8b4e316 100644
> > > > --- a/Makefile
> > > > +++ b/Makefile
> > > > @@ -,7 +,7 @@ endef
> > > >  PHONY += inputs
> > > >  inputs: $(INPUTS-y)
> > > >
> > > > -all: .binman_stamp inputs
> > > > +all: .binman_stamp inputs FORCE
> > > >  ifeq ($(CONFIG_BINMAN),y)
> > > > $(call if_changed,binman)
> > >
> > >
> > >
> > > 'all' is usually used as a phony target.
> > >
> > >
> > > I think this went wrong.
> > >
> > > if_changed should never be used for a phony target.
> > > In other words, if_changed should produce a build artifact.
> > >
> > >
> > >
> > > FORCE is never used for a phony target because
> > > it is added to 'PHONY'.
> > >
> > > PHONY += all
> > >
> > >
> >
> > I agree, this is really written in the wrong way.
> >
> > Target "all:" should be really phony target and should only depends on
> > other target, it should not have any body / commands.
> 
> OK, will need to figure out where to put the binman thing then.
> 
> >
> > And binman call should be moved to different non-phony target with the
> > correct output file name.
> 
> Binman can generate all sorts of files. I will see if I can use
> .binman-stamp since that is always generated.
> 
> Regards,
> Simon

Would not something like this work?

BINMAN_INPUTS :=  # fill this
BINMAN_OUTPUTS :=  # fill this

INPUTS-$(CONFIG_BINMAN) += .binman_stamp

.binman_stamp: $(BINMAN_INPUTS) FORCE
$(call if_changed,binman)

$(BINMAN_OUTPUTS): .binman_stamp

all: inputs


[PATCH v2] mkimage: fit: Fix signing of configs with external data

2022-10-20 Thread Sean Anderson
Just like we exclude data-size, data-position, and data-offset from
fit_config_check_sig, we must exclude them while signing as well.

While we're at it, use the FIT_DATA_* defines for fit_config_check_sig
as welll.

Fixes: 8edecd3110e ("fit: Fix verification of images with external data")
Fixes: c522949a29d ("rsa: sig: fix config signature check for fit with padding")
Signed-off-by: Sean Anderson 
---

Changes in v2:
- Use FIT_DATA_* defines

 boot/image-fit-sig.c | 8 
 tools/image-host.c   | 7 ++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/boot/image-fit-sig.c b/boot/image-fit-sig.c
index a461d591a0e..12369896fe3 100644
--- a/boot/image-fit-sig.c
+++ b/boot/image-fit-sig.c
@@ -260,10 +260,10 @@ static int fit_config_check_sig(const void *fit, int 
noffset, int conf_noffset,
char **err_msgp)
 {
static char * const exc_prop[] = {
-   "data",
-   "data-size",
-   "data-position",
-   "data-offset"
+   FIT_DATA_PROP,
+   FIT_DATA_SIZE_PROP,
+   FIT_DATA_POSITION_PROP,
+   FIT_DATA_OFFSET_PROP,
};
 
const char *prop, *end, *name;
diff --git a/tools/image-host.c b/tools/image-host.c
index 698adfb3e1d..4a4e1c10d1e 100644
--- a/tools/image-host.c
+++ b/tools/image-host.c
@@ -917,7 +917,12 @@ static int fit_config_get_regions(const void *fit, int 
conf_noffset,
  int *region_countp, char **region_propp,
  int *region_proplen)
 {
-   char * const exc_prop[] = {"data"};
+   char * const exc_prop[] = {
+   FIT_DATA_PROP,
+   FIT_DATA_SIZE_PROP,
+   FIT_DATA_POSITION_PROP,
+   FIT_DATA_OFFSET_PROP,
+   };
struct strlist node_inc;
struct image_region *region;
struct fdt_region fdt_regions[100];
-- 
2.35.1.1320.gc452695387.dirty



[PATCH v2 4/4] cmd: source: Support specifying config name

2022-10-20 Thread Sean Anderson
As discussed previously [1,2], the source command is not safe to use with
verified boot unless there is a key with required = "images" (which has its
own problems). This is because if such a key is absent, signatures are
verified but not required. It is assumed that configuration nodes will
provide the signature. Because the source command does not use
configurations to determine the image to source, effectively no
verification takes place.

To address this, allow specifying configuration nodes. We use the same
syntax as the bootm command (helpfully provided for us by fit_parse_conf).
By default, we first try the default config and then the default image. To
force using a config, # must be present in the command (e.g. `source
$loadaddr#my-conf`). For convenience, the config may be omitted, just like
the address may be (e.g. `source \#`). This also works for images
(`source \:` behaves exactly like `source` currently does).

[1] 
https://lore.kernel.org/u-boot/7d711133-d513-5bcb-52f2-a9dbaa9ee...@prevas.dk/
[2] 
https://lore.kernel.org/u-boot/042dcb34-f85f-351e-1b0e-513f89005...@gmail.com/

Signed-off-by: Sean Anderson 
---

(no changes since v1)

 .../cmd_stm32prog/cmd_stm32prog.c |  2 +-
 boot/bootmeth_script.c|  2 +-
 cmd/source.c  | 73 +--
 doc/uImage.FIT/source_file_format.txt |  3 +
 drivers/usb/gadget/f_sdp.c|  2 +-
 include/image.h   | 19 +++--
 test/py/tests/test_source.py  | 11 ++-
 7 files changed, 82 insertions(+), 30 deletions(-)

diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c 
b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
index 9b4098da461..b26dcfddbc6 100644
--- a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
+++ b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
@@ -154,7 +154,7 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, 
int argc,
do_bootz(cmdtp, 0, 4, bootm_argv);
}
if (data->script)
-   image_source_script(data->script, NULL);
+   image_source_script(data->script, NULL, NULL);
 
if (reset) {
puts("Reset...\n");
diff --git a/boot/bootmeth_script.c b/boot/bootmeth_script.c
index d1c3f940037..6c84721d1cd 100644
--- a/boot/bootmeth_script.c
+++ b/boot/bootmeth_script.c
@@ -101,7 +101,7 @@ static int script_boot(struct udevice *dev, struct bootflow 
*bflow)
log_debug("mmc_bootdev: %s\n", env_get("mmc_bootdev"));
 
addr = map_to_sysmem(bflow->buf);
-   ret = image_source_script(addr, NULL);
+   ret = image_source_script(addr, NULL, NULL);
if (ret)
return log_msg_ret("boot", ret);
 
diff --git a/cmd/source.c b/cmd/source.c
index f08e6d34172..17300bdc746 100644
--- a/cmd/source.c
+++ b/cmd/source.c
@@ -42,7 +42,7 @@ static const char *get_default_image(const void *fit)
 }
 #endif
 
-int image_source_script(ulong addr, const char *fit_uname)
+int image_source_script(ulong addr, const char *fit_uname, const char 
*confname)
 {
ulong   len;
 #if defined(CONFIG_LEGACY_IMAGE_FORMAT)
@@ -112,19 +112,46 @@ int image_source_script(ulong addr, const char *fit_uname)
return 1;
}
 
-   if (!fit_uname)
-   fit_uname = get_default_image(fit_hdr);
-
if (!fit_uname) {
-   puts("No FIT subimage unit name\n");
-   return 1;
-   }
+   /* If confname is empty, use the default */
+   if (confname && *confname)
+   noffset = fit_conf_get_node(fit_hdr, confname);
+   else
+   noffset = fit_conf_get_node(fit_hdr, NULL);
+   if (noffset < 0) {
+   if (!confname)
+   goto fallback;
+   printf("Could not find config %s\n", confname);
+   return 1;
+   }
 
-   /* get script component image node offset */
-   noffset = fit_image_get_node (fit_hdr, fit_uname);
-   if (noffset < 0) {
-   printf ("Can't find '%s' FIT subimage\n", fit_uname);
-   return 1;
+   if (verify && fit_config_verify(fit_hdr, noffset))
+   return 1;
+
+   noffset = fit_conf_get_prop_node(fit_hdr, noffset,
+FIT_SCRIPT_PROP);
+   if (noffset < 0) {
+   if (!confname)
+   goto fallback;
+   printf("Could not find script in %s\n", 
confname);
+   return 1;
+ 

[PATCH v2 2/4] treewide: Use NULL for script image name

2022-10-20 Thread Sean Anderson
Two callers of image_source_script specify an image name. However, both
use the deprecated @ syntax, indicating that they have not been updated
in a while. If CONFIG_FIT_SIGNATURE is enabled, we will reject such
names outright. Back in commit 152576a598c ("stm32mp: stm32prog: handle
U-Boot script in flashlayout alternate"), we even renamed one of the
nodes. Instead of hard-coding a script image name, just use the default
image.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---
This has a non-zero chance of breaking something, especially for SDP.
It's not strictly necessary for the following patches, so I can drop it
if there are any issues.

(no changes since v1)

 arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c | 2 +-
 drivers/usb/gadget/f_sdp.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c 
b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
index f59414e716f..9b4098da461 100644
--- a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
+++ b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
@@ -154,7 +154,7 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, 
int argc,
do_bootz(cmdtp, 0, 4, bootm_argv);
}
if (data->script)
-   image_source_script(data->script, "script@stm32prog");
+   image_source_script(data->script, NULL);
 
if (reset) {
puts("Reset...\n");
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index 0fa7230b992..c80698663cd 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -868,7 +868,7 @@ static int sdp_handle_in_ep(struct spl_image_info 
*spl_image,
jump_to_image_no_args(_image);
 #else
/* In U-Boot, allow jumps to scripts */
-   image_source_script(sdp_func->jmp_address, "script@1");
+   image_source_script(sdp_func->jmp_address, NULL);
 #endif
}
 
-- 
2.35.1.1320.gc452695387.dirty



[PATCH v2 3/4] cmd: source: Clean up a few lines

2022-10-20 Thread Sean Anderson
This simplifies a few lines and corrects an error message.

Signed-off-by: Sean Anderson 
Reviewed-by: Simon Glass 
---

(no changes since v1)

 cmd/source.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/cmd/source.c b/cmd/source.c
index bb98255fe86..f08e6d34172 100644
--- a/cmd/source.c
+++ b/cmd/source.c
@@ -128,16 +128,14 @@ int image_source_script(ulong addr, const char *fit_uname)
}
 
if (!fit_image_check_type (fit_hdr, noffset, IH_TYPE_SCRIPT)) {
-   puts ("Not a image image\n");
+   puts("Not a script image\n");
return 1;
}
 
/* verify integrity */
-   if (verify) {
-   if (!fit_image_verify(fit_hdr, noffset)) {
-   puts ("Bad Data Hash\n");
-   return 1;
-   }
+   if (verify && !fit_image_verify(fit_hdr, noffset)) {
+   puts("Bad Data Hash\n");
+   return 1;
}
 
/* get script subimage data address and length */
-- 
2.35.1.1320.gc452695387.dirty



[PATCH v2 0/4] cmd: source: Support specifying config name

2022-10-20 Thread Sean Anderson
This series adds support for using configs with the source command. See
the third patch for details.

Changes in v2:
- Add test for source command

Sean Anderson (4):
  test: Add test for source command
  treewide: Use NULL for script image name
  cmd: source: Clean up a few lines
  cmd: source: Support specifying config name

 .../cmd_stm32prog/cmd_stm32prog.c |  2 +-
 boot/bootmeth_script.c|  2 +-
 cmd/source.c  | 83 +--
 doc/uImage.FIT/source_file_format.txt |  3 +
 drivers/usb/gadget/f_sdp.c|  2 +-
 include/image.h   | 19 +++--
 test/py/tests/source.its  | 43 ++
 test/py/tests/test_source.py  | 37 +
 8 files changed, 156 insertions(+), 35 deletions(-)
 create mode 100644 test/py/tests/source.its
 create mode 100644 test/py/tests/test_source.py

-- 
2.35.1.1320.gc452695387.dirty



[PATCH v2 1/4] test: Add test for source command

2022-10-20 Thread Sean Anderson
This adds a basic test for FIT image handling by the source command.
It's a python test becase we need to run mkimage.

Signed-off-by: Sean Anderson 
---

Changes in v2:
- New

 test/py/tests/source.its | 43 
 test/py/tests/test_source.py | 28 +++
 2 files changed, 71 insertions(+)
 create mode 100644 test/py/tests/source.its
 create mode 100644 test/py/tests/test_source.py

diff --git a/test/py/tests/source.its b/test/py/tests/source.its
new file mode 100644
index 000..3c62f777f17
--- /dev/null
+++ b/test/py/tests/source.its
@@ -0,0 +1,43 @@
+/dts-v1/;
+
+/ {
+description = "FIT image to test the source command";
+#address-cells = <1>;
+
+images {
+default = "script-1";
+
+script-1 {
+data = "echo 1";
+type = "script";
+arch = "sandbox";
+compression = "none";
+};
+
+script-2 {
+data = "echo 2";
+type = "script";
+arch = "sandbox";
+compression = "none";
+};
+
+not-a-script {
+data = "echo 3";
+type = "kernel";
+arch = "sandbox";
+compression = "none";
+};
+};
+
+configurations {
+default = "conf-2";
+
+conf-1 {
+script = "script-1";
+};
+
+conf-2 {
+script = "script-2";
+};
+};
+};
diff --git a/test/py/tests/test_source.py b/test/py/tests/test_source.py
new file mode 100644
index 000..85751ee6f76
--- /dev/null
+++ b/test/py/tests/test_source.py
@@ -0,0 +1,28 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022 Sean Anderson 
+
+import os
+import pytest
+import u_boot_utils as util
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_echo')
+@pytest.mark.buildconfigspec('cmd_source')
+@pytest.mark.buildconfigspec('fit')
+def test_source(u_boot_console):
+# Compile our test script image
+cons = u_boot_console
+mkimage = os.path.join(cons.config.build_dir, "tools/mkimage")
+its = os.path.join(cons.config.source_dir, "test/py/tests/source.its")
+fit = os.path.join(cons.config.build_dir, "source.itb")
+util.run_and_log(cons, (mkimage, '-f', its, fit))
+cons.run_command(f"host load hostfs - $loadaddr {fit}")
+
+assert "1" in cons.run_command("source")
+assert "1" in cons.run_command("source :script-1")
+assert "2" in cons.run_command("source :script-2")
+assert "Fail" in cons.run_command("source :not-a-script || echo Fail")
+
+cons.run_command("fdt addr $loadaddr")
+cons.run_command("fdt rm /images default")
+assert "Fail" in cons.run_command("source || echo Fail")
-- 
2.35.1.1320.gc452695387.dirty



Re: [PULL] u-boot-riscv/master

2022-10-20 Thread Tom Rini
On Thu, Oct 20, 2022 at 12:36:23PM +, Leo Liang wrote:

> Hi Tom,
> 
> The following changes since commit 3724ddf157aab3bd009c1da234b9a1af1621b544:
> 
>   Merge branch '2022-10-18-TI-platform-updates' (2022-10-18 18:13:39 -0400)
> 
> are available in the Git repository at:
> 
>   https://source.denx.de/u-boot/custodians/u-boot-riscv.git
> 
> for you to fetch changes up to b3b44c674a473bdd3d53cf5196fae897107af619:
> 
>   riscv: ae350: Check firmware_fdt_addr header (2022-10-20 15:26:31 +0800)
> 
> CI result shows no issue: 
> https://source.denx.de/u-boot/custodians/u-boot-riscv/-/pipelines/13866
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [GIT PULL] clk changes for v2023.01

2022-10-20 Thread Tom Rini
On Wed, Oct 19, 2022 at 07:56:17PM -0400, Sean Anderson wrote:

> The following changes since commit d3ccdc0fce206c1d54fbdc607333de6184e19e75:
> 
>   Merge tag 'efi-2022-10-rc6' of 
> https://source.denx.de/u-boot/custodians/u-boot-efi (2022-09-30 08:30:38 
> -0400)
> 
> are available in the Git repository at:
> 
>   https://source.denx.de/u-boot/custodians/u-boot-clk.git tags/clk-2023.01
> 
> for you to fetch changes up to 19fb40a5e7ee815a703ffdcc7c0fdb7933762256:
> 
>   clk: update clk_clean_rate_cache to use private clk struct (2022-10-19 
> 12:28:30 -0400)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: Pull request: u-boot-sunxi/master for 2023.01

2022-10-20 Thread Tom Rini
On Thu, Oct 20, 2022 at 12:54:27AM +0100, Andre Przywara wrote:

> Hi Tom,
> 
> please pull the first bunch of the sunxi pull request for this cycle.
> Beside some rather unexciting sync of the DTs from the kernel tree, and
> some Kconfig cleanup, there are some improvements for the ARMv5 Allwinner
> family, to support boards with the F1C200s (64MB DRAM) better. We will
> get actual board support as soon as the DTs have passed the Linux review
> process.
> There is also support for the X96 Mate TV Box, featuring the H616 SoC and
> a full 4GB of DRAM.
> Also we found the secret to enable SPI booting on the H616 (pin PC5 must
> be pulled to GND), so the SPI boot support patch is now good to go.
> 
> Passed the gitlab CI, plus briefly tested on Pine64-LTS, LicheePi Nano,
> X96 Mate and OrangePi Zero.
> 
> Thanks,
> Andre
> 
> 
> The following changes since commit e2ff1d0fa777b11ad6b26432cb7613ab433b15d6:
> 
>   Merge tag 'efi-2023-01-rc1-3' of 
> https://source.denx.de/u-boot/custodians/u-boot-efi (2022-10-16 20:23:47 
> -0400)
> 
> are available in the Git repository at:
> 
>   https://source.denx.de/u-boot/custodians/u-boot-sunxi.git master
> 
> for you to fetch changes up to 843ed983a07ee5d8d4e4ac5baa39fc53f12b5f33:
> 
>   suniv: add UART1 support (2022-10-19 14:15:02 +0100)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH] arm: mach-omap2: Move common image process functions out of board files

2022-10-20 Thread Andrew Davis
The functions board_fit_image_post_process() and board_tee_image_process()
are not actually board specific (despite their names). Any board using the
OMAP2 family can use these functions. Move them to boot-common.c.

Signed-off-by: Andrew Davis 
---
 arch/arm/mach-omap2/boot-common.c | 16 
 board/ti/am335x/board.c   |  9 -
 board/ti/am43xx/board.c   | 17 -
 board/ti/am57xx/board.c   | 17 -
 board/ti/dra7xx/evm.c | 17 -
 5 files changed, 16 insertions(+), 60 deletions(-)

diff --git a/arch/arm/mach-omap2/boot-common.c 
b/arch/arm/mach-omap2/boot-common.c
index c463c96c74..f955d49471 100644
--- a/arch/arm/mach-omap2/boot-common.c
+++ b/arch/arm/mach-omap2/boot-common.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -22,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -331,3 +333,17 @@ void arch_preboot_os(void)
ahci_reset((void __iomem *)DWC_AHSATA_BASE);
 }
 #endif
+
+#ifdef CONFIG_TI_SECURE_DEVICE
+void board_fit_image_post_process(const void *fit, int node, void **p_image,
+ size_t *p_size)
+{
+   secure_boot_verify_image(p_image, p_size);
+}
+
+static void tee_image_process(ulong tee_image, size_t tee_size)
+{
+   secure_tee_install((u32)tee_image);
+}
+U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, tee_image_process);
+#endif
diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c
index b97fe5..2a09b6480b 100644
--- a/board/ti/am335x/board.c
+++ b/board/ti/am335x/board.c
@@ -33,7 +33,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -983,14 +982,6 @@ int board_fit_config_name_match(const char *name)
 }
 #endif
 
-#ifdef CONFIG_TI_SECURE_DEVICE
-void board_fit_image_post_process(const void *fit, int node, void **p_image,
- size_t *p_size)
-{
-   secure_boot_verify_image(p_image, p_size);
-}
-#endif
-
 #if !CONFIG_IS_ENABLED(OF_CONTROL)
 static const struct omap_hsmmc_plat am335x_mmc0_plat = {
.base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c
index 529129ecc7..9fa894d700 100644
--- a/board/ti/am43xx/board.c
+++ b/board/ti/am43xx/board.c
@@ -9,7 +9,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -20,7 +19,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -867,18 +865,3 @@ int embedded_dtb_select(void)
return 0;
 }
 #endif
-
-#ifdef CONFIG_TI_SECURE_DEVICE
-void board_fit_image_post_process(const void *fit, int node, void **p_image,
- size_t *p_size)
-{
-   secure_boot_verify_image(p_image, p_size);
-}
-
-void board_tee_image_process(ulong tee_image, size_t tee_size)
-{
-   secure_tee_install((u32)tee_image);
-}
-
-U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
-#endif
diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c
index cfc825e52a..511c44104e 100644
--- a/board/ti/am57xx/board.c
+++ b/board/ti/am57xx/board.c
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -22,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -1197,18 +1195,3 @@ static int board_bootmode_has_emmc(void)
return 0;
 }
 #endif
-
-#ifdef CONFIG_TI_SECURE_DEVICE
-void board_fit_image_post_process(const void *fit, int node, void **p_image,
- size_t *p_size)
-{
-   secure_boot_verify_image(p_image, p_size);
-}
-
-void board_tee_image_process(ulong tee_image, size_t tee_size)
-{
-   secure_tee_install((u32)tee_image);
-}
-
-U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
-#endif
diff --git a/board/ti/dra7xx/evm.c b/board/ti/dra7xx/evm.c
index a854d615c1..0b1fc99b94 100644
--- a/board/ti/dra7xx/evm.c
+++ b/board/ti/dra7xx/evm.c
@@ -13,7 +13,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -26,7 +25,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -1063,18 +1061,3 @@ int fastboot_set_reboot_flag(enum fastboot_reboot_reason 
reason)
return 0;
 }
 #endif
-
-#ifdef CONFIG_TI_SECURE_DEVICE
-void board_fit_image_post_process(const void *fit, int node, void **p_image,
- size_t *p_size)
-{
-   secure_boot_verify_image(p_image, p_size);
-}
-
-void board_tee_image_process(ulong tee_image, size_t tee_size)
-{
-   secure_tee_install((u32)tee_image);
-}
-
-U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
-#endif
-- 
2.37.3



Re: [uboot] mtd NAND recognition regression

2022-10-20 Thread Michael Nazzareno Trimarchi
Hi Marcin

On Thu, Oct 20, 2022 at 6:13 PM Michael Nazzareno Trimarchi
 wrote:
>
> Hi
>
> On Thu, Oct 20, 2022 at 5:58 PM Marcin Gołaś  wrote:
> >
> > Hi,
> >
> > after uboot update from 2022.07 to 2022.10 SAMSUNG NAND is not recognized
> > correctly.
> > I use device with SAMSUNG K9K8G08U0F flash which does not support ONFI and
> > JEDEC.
> > Both uboot versions read 8-byte id_data in the same way: 0xD3ECC65A9551D3EC.
> > However 2022.07 recognized flash correctly as:
> > nand_base: 1024 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size:
> > 64
> > 1024 MiB
> > The new 2022.10 recognized flash incorrectly:
> > nand_base: 1024 MiB, SLC, erase size: 4096 KiB, page size: 4096, OOB size:
> > 128
> > 1024 MiB
> >
> > This behavior is caused by not setting chip->bits_per_cell value which is
> > in my case equal to zero.
> > To fix the issue we need to set it before we enter to function
> > nand_manufacturer_detect.
> > Following patch do this:
> >
> > diff --git a/drivers/mtd/nand/raw/nand_base.c
> > b/drivers/mtd/nand/raw/nand_base.c
> > index 4b09a11288..143d3cb755 100644
> > --- a/drivers/mtd/nand/raw/nand_base.c
> > +++ b/drivers/mtd/nand/raw/nand_base.c
> > @@ -4375,6 +4375,8 @@ struct nand_flash_dev *nand_get_flash_type(struct
> > nand_chip *chip, int *maf_id,
> >
> > chip->chipsize = (uint64_t)type->chipsize << 20;
> >
> > +   chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]);
> > +
> > if (!type->pagesize) {
> > nand_manufacturer_detect(chip);
> > } else {
> >
>
> Can you please send a patch for it? I will check this regression

--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4171,10 +4171,13 @@ static void nand_manufacturer_detect(struct
nand_chip *chip)
 * nand_decode_ext_id() otherwise.
 */
if (chip->manufacturer.desc && chip->manufacturer.desc->ops &&
-   chip->manufacturer.desc->ops->detect)
+   chip->manufacturer.desc->ops->detect) {
+   /* The 3rd id byte holds MLC / multichip data */
+   chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]);
chip->manufacturer.desc->ops->detect(chip);
-   else
+   } else {
nand_decode_ext_id(chip);
+   }
 }

Can you test this one?

Michael
>
> Michael
>
> >
> > BR,
> > Marcin
>
>
>
> --
> Michael Nazzareno Trimarchi
> Co-Founder & Chief Executive Officer
> M. +39 347 913 2170
> mich...@amarulasolutions.com
> __
>
> Amarula Solutions BV
> Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
> T. +31 (0)85 111 9172
> i...@amarulasolutions.com
> www.amarulasolutions.com



-- 
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
mich...@amarulasolutions.com
__

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
i...@amarulasolutions.com
www.amarulasolutions.com


Re: [uboot] mtd NAND recognition regression

2022-10-20 Thread Michael Nazzareno Trimarchi
Hi

On Thu, Oct 20, 2022 at 5:58 PM Marcin Gołaś  wrote:
>
> Hi,
>
> after uboot update from 2022.07 to 2022.10 SAMSUNG NAND is not recognized
> correctly.
> I use device with SAMSUNG K9K8G08U0F flash which does not support ONFI and
> JEDEC.
> Both uboot versions read 8-byte id_data in the same way: 0xD3ECC65A9551D3EC.
> However 2022.07 recognized flash correctly as:
> nand_base: 1024 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size:
> 64
> 1024 MiB
> The new 2022.10 recognized flash incorrectly:
> nand_base: 1024 MiB, SLC, erase size: 4096 KiB, page size: 4096, OOB size:
> 128
> 1024 MiB
>
> This behavior is caused by not setting chip->bits_per_cell value which is
> in my case equal to zero.
> To fix the issue we need to set it before we enter to function
> nand_manufacturer_detect.
> Following patch do this:
>
> diff --git a/drivers/mtd/nand/raw/nand_base.c
> b/drivers/mtd/nand/raw/nand_base.c
> index 4b09a11288..143d3cb755 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -4375,6 +4375,8 @@ struct nand_flash_dev *nand_get_flash_type(struct
> nand_chip *chip, int *maf_id,
>
> chip->chipsize = (uint64_t)type->chipsize << 20;
>
> +   chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]);
> +
> if (!type->pagesize) {
> nand_manufacturer_detect(chip);
> } else {
>

Can you please send a patch for it? I will check this regression

Michael

>
> BR,
> Marcin



-- 
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
mich...@amarulasolutions.com
__

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
i...@amarulasolutions.com
www.amarulasolutions.com


Re: [PATCH] drivers: pci: pcie_dw_common: add upper-limit to iATU

2022-10-20 Thread Bin Meng
Hi Ben,

On Thu, Oct 20, 2022 at 11:51 PM Ben Dooks  wrote:
>
> The 4.6 spec added an upper 32bits to the ATU limit, and since this
> driver is already assuming the unrolled feature added in the 4.8
> specification this really should be set.
>
> This is causing a bug with testing against the QEMU model as it

I guess you are testing QEMU sifive_u machine with some mods to add a
DW PCIe controller, with U-Boot sifive_unmatched defconfig?

Could you please document the QEMU command line in the commit message?

> defaults the viewports to fully open and not setting this causes
> the config viewport to become most of memory (obviously stopping
> the emulated system working correctly)
>
> Signed-off-by: Ben Dooks 
> ---
>  drivers/pci/pcie_dw_common.c | 2 ++
>  drivers/pci/pcie_dw_common.h | 1 +
>  2 files changed, 3 insertions(+)
>
> diff --git a/drivers/pci/pcie_dw_common.c b/drivers/pci/pcie_dw_common.c
> index e66fb1490a..9f8b016d11 100644
> --- a/drivers/pci/pcie_dw_common.c
> +++ b/drivers/pci/pcie_dw_common.c
> @@ -73,6 +73,8 @@ int pcie_dw_prog_outbound_atu_unroll(struct pcie_dw *pci, 
> int index,
>  upper_32_bits(cpu_addr));
> dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LIMIT,
>  lower_32_bits(cpu_addr + size - 1));
> +   dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_LIMIT,
> +upper_32_bits(cpu_addr + size - 1));
> dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_TARGET,
>  lower_32_bits(pci_addr));
> dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET,
> diff --git a/drivers/pci/pcie_dw_common.h b/drivers/pci/pcie_dw_common.h
> index 60bf966d5e..8ec6834fa1 100644
> --- a/drivers/pci/pcie_dw_common.h
> +++ b/drivers/pci/pcie_dw_common.h
> @@ -32,6 +32,7 @@
>  #define PCIE_ATU_UNR_LIMIT 0x10
>  #define PCIE_ATU_UNR_LOWER_TARGET  0x14
>  #define PCIE_ATU_UNR_UPPER_TARGET  0x18
> +#define PCIE_ATU_UNR_UPPER_LIMIT   0x20
>
>  #define PCIE_ATU_REGION_INDEX2 (0x2 << 0)
>  #define PCIE_ATU_REGION_INDEX1 (0x1 << 0)
> --

Regards,
Bin


[PATCH] drivers: pci: pcie_dw_common: add upper-limit to iATU

2022-10-20 Thread Ben Dooks
The 4.6 spec added an upper 32bits to the ATU limit, and since this
driver is already assuming the unrolled feature added in the 4.8
specification this really should be set.

This is causing a bug with testing against the QEMU model as it
defaults the viewports to fully open and not setting this causes
the config viewport to become most of memory (obviously stopping
the emulated system working correctly)

Signed-off-by: Ben Dooks 
---
 drivers/pci/pcie_dw_common.c | 2 ++
 drivers/pci/pcie_dw_common.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/drivers/pci/pcie_dw_common.c b/drivers/pci/pcie_dw_common.c
index e66fb1490a..9f8b016d11 100644
--- a/drivers/pci/pcie_dw_common.c
+++ b/drivers/pci/pcie_dw_common.c
@@ -73,6 +73,8 @@ int pcie_dw_prog_outbound_atu_unroll(struct pcie_dw *pci, int 
index,
 upper_32_bits(cpu_addr));
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LIMIT,
 lower_32_bits(cpu_addr + size - 1));
+   dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_LIMIT,
+upper_32_bits(cpu_addr + size - 1));
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_TARGET,
 lower_32_bits(pci_addr));
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET,
diff --git a/drivers/pci/pcie_dw_common.h b/drivers/pci/pcie_dw_common.h
index 60bf966d5e..8ec6834fa1 100644
--- a/drivers/pci/pcie_dw_common.h
+++ b/drivers/pci/pcie_dw_common.h
@@ -32,6 +32,7 @@
 #define PCIE_ATU_UNR_LIMIT 0x10
 #define PCIE_ATU_UNR_LOWER_TARGET  0x14
 #define PCIE_ATU_UNR_UPPER_TARGET  0x18
+#define PCIE_ATU_UNR_UPPER_LIMIT   0x20
 
 #define PCIE_ATU_REGION_INDEX2 (0x2 << 0)
 #define PCIE_ATU_REGION_INDEX1 (0x1 << 0)
-- 
2.35.1



Re: [PATCH 3/6] net: (actually/better) deal with CVE-2022-{30790, 30552}

2022-10-20 Thread Artur Łącki
I tested these patches with my exploit. At the moment it looks like the
vulnerability has been fixed.


[uboot] mtd NAND recognition regression

2022-10-20 Thread Marcin Gołaś
Hi,

after uboot update from 2022.07 to 2022.10 SAMSUNG NAND is not recognized
correctly.
I use device with SAMSUNG K9K8G08U0F flash which does not support ONFI and
JEDEC.
Both uboot versions read 8-byte id_data in the same way: 0xD3ECC65A9551D3EC.
However 2022.07 recognized flash correctly as:
nand_base: 1024 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size:
64
1024 MiB
The new 2022.10 recognized flash incorrectly:
nand_base: 1024 MiB, SLC, erase size: 4096 KiB, page size: 4096, OOB size:
128
1024 MiB

This behavior is caused by not setting chip->bits_per_cell value which is
in my case equal to zero.
To fix the issue we need to set it before we enter to function
nand_manufacturer_detect.
Following patch do this:

diff --git a/drivers/mtd/nand/raw/nand_base.c
b/drivers/mtd/nand/raw/nand_base.c
index 4b09a11288..143d3cb755 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4375,6 +4375,8 @@ struct nand_flash_dev *nand_get_flash_type(struct
nand_chip *chip, int *maf_id,

chip->chipsize = (uint64_t)type->chipsize << 20;

+   chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]);
+
if (!type->pagesize) {
nand_manufacturer_detect(chip);
} else {


BR,
Marcin


Re: [PATCH 6/6] sunxi: add CherryPi-F1C200s support

2022-10-20 Thread Giulio Benetti

Hi Andre,

On 18/10/22 16:01, Andre Przywara wrote:

On Fri, 14 Oct 2022 01:04:18 -0400
Jesse Taube  wrote:

Hi Jesse, Giulio,

thanks for having a look and for the testing!


You're welcome:
Tested-by: Giulio Benetti 

Best regards
--
Giulio Benetti
CEO/CTO@Benetti Engineering sas


On 10/13/22 05:53, Andre Przywara wrote:

On 13/10/2022 09:33, Clément Péron wrote:

Hi Clément,
   

On Wed, 12 Oct 2022 at 18:35, Andre Przywara  wrote:


The CherryPi F1C200s board is a small development board, featuring the
F1C200s with 64MB of co-packaged DRAM. It comes with two USB-C sockets,
of which one is connected to a USB-UART chip, that provides easy access
to UART1.


A similar board is trying to been upstreamed by Icenowy:

see : https://lore.kernel.org/lkml/20221012055602.1544944-11-...@icenowy.me/
[PATCH v2 10/10] ARM: dts: suniv: add device tree for PopStick v1.1

Maybe we should take into account the remarks that Krzysztof Kozlowski
made to follow the same device-tree rules on U-boot.


Yeah, thanks for the heads up, I saw that. I just wanted to post this to
demonstrate what needs to be done. I will be sending a Linux DT patch
anyway, since DTs need to go via Linux anyway.

Thanks,
Andre
   


Regards,
Clement
  

Beside the usual micro-SD card slot, the board comes with a SPI NAND
flash chip, which is not yet supported.

Signed-off-by: Andre Przywara 
---
.../dts/suniv-f1c100s-cherrypi-f1c200s.dts| 45 +++
configs/cherrypi_f1c200s_defconfig| 11 +
2 files changed, 56 insertions(+)
create mode 100644 arch/arm/dts/suniv-f1c100s-cherrypi-f1c200s.dts
create mode 100644 configs/cherrypi_f1c200s_defconfig

diff --git a/arch/arm/dts/suniv-f1c100s-cherrypi-f1c200s.dts 
b/arch/arm/dts/suniv-f1c100s-cherrypi-f1c200s.dts
new file mode 100644
index 000..f0ebcb6d893
--- /dev/null
+++ b/arch/arm/dts/suniv-f1c100s-cherrypi-f1c200s.dts
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR X11)
+/*
+ * Copyright 2022 Arm Ltd.
+ * based on another DT, which is:
+ *   Copyright 2018 Icenowy Zheng 

Her email changed IDK if it is proper to change here.

+ */
+
+/dts-v1/;
+#include "suniv-f1c100s.dtsi"
+
+/ {
+   model = "Cherry Pi F1C200s";
+   compatible = "lctech,cherrypi-f1c200s", "allwinner,suniv-f1c100s";
+
+   aliases {
+   mmc0 = 
+   serial0 = 
+   spi0 = 

no need for spi.

+   };
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+
+   reg_vcc3v3: vcc3v3 {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   };
+};
+
+ {
+   broken-cd;
+   bus-width = <4>;
+   disable-wp;
+   status = "okay";
+   vmmc-supply = <_vcc3v3>;
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pa_pins>;
+   status = "okay";
+};
diff --git a/configs/cherrypi_f1c200s_defconfig 
b/configs/cherrypi_f1c200s_defconfig
new file mode 100644
index 000..306d363f485
--- /dev/null
+++ b/configs/cherrypi_f1c200s_defconfig
@@ -0,0 +1,11 @@
+CONFIG_ARM=y
+CONFIG_SYS_DCACHE_OFF=y
+CONFIG_ARCH_SUNXI=y
+CONFIG_DEFAULT_DEVICE_TREE="suniv-f1c100s-cherrypi-f1c200s"
+CONFIG_SPL=y
+CONFIG_MACH_SUNIV=y
+CONFIG_DRAM_CLK=156
+CONFIG_DRAM_ZQ=0

You need
+CONFIG_SPL_STACK=0x8000


I posted "[PATCH 1/2] sunxi: Kconfig: use SoC-wide values for some symbols"
(https://lore.kernel.org/u-boot/20220913234335.24902-2-andre.przyw...@arm.com/)
that solves that issue.
That patch is applied before this series in the tree, so no change should
be needed.

Thanks for the report!

Cheers,
Andre




I will test this on both 100s and 200s.
Thanks,
Jesse Taube

+CONFIG_SUNXI_MINIMUM_DRAM_MB=64
+# CONFIG_VIDEO_SUNXI is not set
+CONFIG_CONS_INDEX=2
--
2.25.1

  
   






Re: [PATCH v4 1/2] mx7ulp: add base SPL support for mx7ulp

2022-10-20 Thread Stefano Babic

Hi Oleksandr, Ricardo,

On 05.08.22 20:19, Oleksandr Suvorov wrote:

From: Ricardo Salveti 

Add a base implementation of mx7ulp SPL config header and soc,
and changes in makefiles in order to allow building SPL on mx7ulp
based devices.

Signed-off-by: Ricardo Salveti 
Co-developed-by: Oleksandr Suvorov 
Signed-off-by: Oleksandr Suvorov 
---

Changes in v4:
- rebase to the current master
- fix a reference to a non-existent option SPL_MMC_SUPPORT

Changes in v3:
- rebase the patch to the current codebase

  arch/arm/mach-imx/Makefile |  2 +-
  arch/arm/mach-imx/mx7ulp/soc.c |  2 +-
  arch/arm/mach-imx/spl.c|  6 --
  include/configs/imx7ulp_spl.h  | 39 ++
  4 files changed, 45 insertions(+), 4 deletions(-)
  create mode 100644 include/configs/imx7ulp_spl.h

diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 80c497e6d81..71e6cac2f63 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -29,7 +29,7 @@ endif
  obj-$(CONFIG_GPT_TIMER) += timer.o
  obj-$(CONFIG_SYS_I2C_MXC) += i2c-mxv7.o
  endif
-ifeq ($(SOC),$(filter $(SOC),mx7 mx6 mxs imx8m imx8 imx9 imxrt))
+ifeq ($(SOC),$(filter $(SOC),mx7 mx7ulp mx6 mxs imx8m imx8 imx9 imxrt))
  obj-y += misc.o
  obj-$(CONFIG_CMD_PRIBLOB) += priblob.o
  obj-$(CONFIG_SPL_BUILD)   += spl.o
diff --git a/arch/arm/mach-imx/mx7ulp/soc.c b/arch/arm/mach-imx/mx7ulp/soc.c
index 217b7c45867..951b1888c58 100644
--- a/arch/arm/mach-imx/mx7ulp/soc.c
+++ b/arch/arm/mach-imx/mx7ulp/soc.c
@@ -234,7 +234,7 @@ void s_init(void)
  }
  #endif
  
-#ifndef CONFIG_ULP_WATCHDOG

+#if !CONFIG_IS_ENABLED(ULP_WATCHDOG) || CONFIG_IS_ENABLED(SPL_BUILD)
  void reset_cpu(void)
  {
setbits_le32(SIM0_RBASE, SIM_SOPT1_A7_SW_RESET);
diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
index ef00969a5e0..bca0b1123a7 100644
--- a/arch/arm/mach-imx/spl.c
+++ b/arch/arm/mach-imx/spl.c
@@ -147,7 +147,7 @@ u32 spl_boot_device(void)
return BOOT_DEVICE_NONE;
  }
  
-#elif defined(CONFIG_MX7) || defined(CONFIG_IMX8M) || defined(CONFIG_IMX8) || defined(CONFIG_IMX9)

+#elif defined(CONFIG_MX7) || defined(CONFIG_MX7ULP) || defined(CONFIG_IMX8M) 
|| defined(CONFIG_IMX8) || defined(CONFIG_IMX9)
  /* Translate iMX7/i.MX8M boot device to the SPL boot device enumeration */
  u32 spl_boot_device(void)
  {
@@ -160,7 +160,9 @@ u32 spl_boot_device(void)
 */
if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
return BOOT_DEVICE_BOARD;
+#endif
  
+#if defined(CONFIG_MX7) || defined(CONFIG_MX7ULP)

/*
 * The above method does not detect that the boot ROM used
 * serial downloader in case the boot ROM decided to use the
@@ -178,7 +180,7 @@ u32 spl_boot_device(void)
  
  	return spl_board_boot_device(boot_device_spl);

  }
-#endif /* CONFIG_MX7 || CONFIG_IMX8M || CONFIG_IMX8 */
+#endif /* CONFIG_MX7 || CONFIG_MX7ULP || CONFIG_IMX8M || CONFIG_IMX8 */
  
  #ifdef CONFIG_SPL_USB_GADGET

  int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
diff --git a/include/configs/imx7ulp_spl.h b/include/configs/imx7ulp_spl.h
new file mode 100644
index 000..516238ec02e
--- /dev/null
+++ b/include/configs/imx7ulp_spl.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * SPL definitions for the i.MX7ULP SPL
+ *
+ * (C) Copyright 2019 Foundries.io
+ */
+
+#ifndef __IMX7ULP_SPL_CONFIG_H
+#define __IMX7ULP_SPL_CONFIG_H
+
+#if CONFIG_IS_ENABLED(SPL)
+/*
+ * see figure 35-5 in i.MX 7ULP Reference manual:
+ *  - IMX7ULP A7 OCRAM free area RAM is from 0x2F01 to 0x2F03FF00.
+ *  - Set the stack at the end of the free area section, at 0x2003FEB8.
+ *  - The BOOT ROM loads what they consider the firmware image
+ *which consists of a 4K header in front of us that contains the IVT, DCD,
+ *and some padding thus 'our' max size is really 0x2F03FF00 - 0x2F011000.
+ *187KB is more than enough for the SPL.
+ */
+#define CONFIG_SPL_STACK   0x2F03FEB8
+
+/* MMC support */
+#if CONFIG_IS_ENABLED(SPL_MMC)
+#define CONFIG_SYS_MMCSD_FS_BOOT_PARTITION 1


This should be in defconfig and it is not accepted anymore in header, it 
raises an error. See :


https://source.denx.de/u-boot/custodians/u-boot-imx/-/jobs/516648

Best regards,
Stefano



+#define CONFIG_SYS_MONITOR_LEN 409600  /* 400 KB */
+#endif
+
+/* Define the payload for FAT/EXT support */
+#if CONFIG_IS_ENABLED(SPL_FS_FAT) || CONFIG_IS_ENABLED(SPL_FS_EXT4)
+#define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME"u-boot-dtb.img"
+#endif
+
+#define CONFIG_SYS_SPL_MALLOC_START0x6830
+#define CONFIG_SYS_SPL_MALLOC_SIZE 0x10/* 1 MB */
+
+#endif /* CONFIG_SPL */
+
+#endif /* __IMX7ULP_SPL_CONFIG_H */


--
=
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, 82194 Groebenzell, Germany
Phone: 

Re: [PATCH v4 5/5] arm: imx8mp: Initial MSC SM2S iMX8MP support

2022-10-20 Thread Stefano Babic

On 04.10.22 13:07, Martyn Welch wrote:

Add support for the MSC SM2S-IMX8PLUS SMARC Module. Tested in conjunction
with the MSC SM2-MB-EP1 Mini-ITX Carrier Board.


I see at least some issues:

- MAINTAINERS file is missing
- a lot of symbols are set in include/configs/msc_sm2s_imx8mp.h instead 
of moving to Kbuild. Running first CI, the following are reported:


Unmigrated symbols found in include/configs/msc_sm2s_imx8mp.h:
CONFIG_ETHPRIME
CONFIG_SPL_BSS_START_ADDR
CONFIG_SPL_STACK
CONFIG_SYS_BARGSIZE
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
CONFIG_SYS_SPL_MALLOC_SIZE
Unmigrated symbols found in include/configs/imx7ulp_spl.h:
CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
CONFIG_SPL_STACK
CONFIG_SYS_MMCSD_FS_BOOT_PARTITION
CONFIG_SYS_SPL_MALLOC_SIZE

Best regards,
Stefano



Signed-off-by: Martyn Welch 
---

Changes in v2:
  - Renamed FDT to closer match kernel
  - Sync with kernel FDT
  - Update for changes made in U-Boot

Changes in v3:
  - Use imx8mp-u-boot.dtsi
  - Switch to use of DM PMIC support in SPL

Changes in v4:
  - Rebased to latest imx master branch

  arch/arm/dts/Makefile |1 +
  arch/arm/dts/imx8mp-msc-sm2s-u-boot.dtsi  |   65 +
  arch/arm/dts/imx8mp-msc-sm2s.dts  |  820 
  arch/arm/mach-imx/imx8m/Kconfig   |8 +
  board/msc/sm2s_imx8mp/Kconfig |   15 +
  board/msc/sm2s_imx8mp/Makefile|   12 +
  board/msc/sm2s_imx8mp/imximage-8mp-lpddr4.cfg |8 +
  board/msc/sm2s_imx8mp/lpddr4_timing.c | 1842 +
  board/msc/sm2s_imx8mp/sm2s_imx8mp.c   |   60 +
  board/msc/sm2s_imx8mp/spl.c   |  273 +++
  configs/msc_sm2s_imx8mp_defconfig |   91 +
  include/configs/msc_sm2s_imx8mp.h |   96 +
  12 files changed, 3291 insertions(+)
  create mode 100644 arch/arm/dts/imx8mp-msc-sm2s-u-boot.dtsi
  create mode 100644 arch/arm/dts/imx8mp-msc-sm2s.dts
  create mode 100644 board/msc/sm2s_imx8mp/Kconfig
  create mode 100644 board/msc/sm2s_imx8mp/Makefile
  create mode 100644 board/msc/sm2s_imx8mp/imximage-8mp-lpddr4.cfg
  create mode 100644 board/msc/sm2s_imx8mp/lpddr4_timing.c
  create mode 100644 board/msc/sm2s_imx8mp/sm2s_imx8mp.c
  create mode 100644 board/msc/sm2s_imx8mp/spl.c
  create mode 100644 configs/msc_sm2s_imx8mp_defconfig
  create mode 100644 include/configs/msc_sm2s_imx8mp.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 965895bc2a..a5de6e1b5e 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -970,6 +970,7 @@ dtb-$(CONFIG_ARCH_IMX8M) += \
imx8mq-phanbell.dtb \
imx8mp-dhcom-pdk2.dtb \
imx8mp-evk.dtb \
+   imx8mp-msc-sm2s.dtb \
imx8mp-phyboard-pollux-rdk.dtb \
imx8mp-venice.dtb \
imx8mp-venice-gw74xx.dtb \
diff --git a/arch/arm/dts/imx8mp-msc-sm2s-u-boot.dtsi 
b/arch/arm/dts/imx8mp-msc-sm2s-u-boot.dtsi
new file mode 100644
index 00..cf591adf5a
--- /dev/null
+++ b/arch/arm/dts/imx8mp-msc-sm2s-u-boot.dtsi
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ */
+
+#include "imx8mp-u-boot.dtsi"
+
+/ {
+   model = "MSC SM2S-IMX8MPLUS";
+   compatible = "avnet,sm2s-imx8mp", "fsl,imx8mp";
+
+   wdt-reboot {
+   compatible = "wdt-reboot";
+   wdt = <>;
+   u-boot,dm-spl;
+   };
+};
+
+_usdhc2_vmmc {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+_i2c6 {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
diff --git a/arch/arm/dts/imx8mp-msc-sm2s.dts b/arch/arm/dts/imx8mp-msc-sm2s.dts
new file mode 100644
index 00..5dbec71747
--- /dev/null
+++ b/arch/arm/dts/imx8mp-msc-sm2s.dts
@@ -0,0 +1,820 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022 Avnet Embedded GmbH
+ */
+
+/dts-v1/;
+
+#include "imx8mp.dtsi"
+#include 
+
+/ {
+   aliases {
+   rtc0 = _rtc;
+   rtc1 = _rtc;
+   };
+
+   chosen {
+   stdout-path = 
+   };
+
+   reg_usb0_host_vbus: regulator-usb0-vbus {
+   compatible = "regulator-fixed";
+   regulator-name = "usb0_host_vbus";
+   pinctrl-names = "default";
+   pinctrl-0 = <_usb0_vbus>;
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   gpio = < 12 GPIO_ACTIVE_HIGH>;
+   enable-active-high;
+   };
+
+   reg_usb1_host_vbus: regulator-usb1-vbus {
+   compatible = "regulator-fixed";
+   regulator-name = "usb1_host_vbus";
+   pinctrl-names = "default";
+   pinctrl-0 = <_usb1_vbus>;
+   

i2c-gpio: condition is always false

2022-10-20 Thread Sergei Antonov
Hello!
Please look at this code from drivers/i2c/i2c-gpio.c:

static int i2c_gpio_of_to_plat(struct udevice *dev)
{
struct i2c_gpio_bus *bus = dev_get_priv(dev);
int ret;

/* "gpios" is deprecated and replaced by "sda-gpios" + "scl-gpios". */
ret = gpio_request_list_by_name(dev, "gpios", bus->gpios,
ARRAY_SIZE(bus->gpios), 0);
if (ret == -ENOENT) {

The condition is always false because in
gpio_request_list_by_name_nodev(), if entry is not found, this code
will work:
if (ret == -ENOENT)
break;
and then
return count;
return zero.


Re: [PATCH v14 15/15] FWU: doc: Add documentation for the FWU feature

2022-10-20 Thread Etienne Carriere
Hi Sughosh,

For info I successfully tested your v14 series on my boards.
(note i did not test case with a power failure in between mdata
partition updates, discussed in patch v14 02/15).
I'll run another tests round on next v15 to post my Tested-by tag.

Br,
Etienne

On Tue, 18 Oct 2022 at 13:45, Sughosh Ganu  wrote:
>
> Add documentation for the FWU Multi Bank Update feature. The document
> describes the steps needed for setting up the platform for the
> feature, as well as steps for enabling the feature on the platform.
>
> Signed-off-by: Sughosh Ganu 
> ---
> Changes since V13: None
>
>  doc/develop/uefi/fwu_updates.rst | 184 +++
>  doc/develop/uefi/index.rst   |   1 +
>  doc/develop/uefi/uefi.rst|  12 ++
>  3 files changed, 197 insertions(+)
>  create mode 100644 doc/develop/uefi/fwu_updates.rst
>
> diff --git a/doc/develop/uefi/fwu_updates.rst 
> b/doc/develop/uefi/fwu_updates.rst
> new file mode 100644
> index 00..068616ce83
> --- /dev/null
> +++ b/doc/develop/uefi/fwu_updates.rst
> @@ -0,0 +1,184 @@
> +.. SPDX-License-Identifier: GPL-2.0+
> +.. Copyright (c) 2022 Linaro Limited
> +
> +FWU Multi Bank Updates in U-Boot
> +
> +
> +The FWU Multi Bank Update feature implements the firmware update
> +mechanism described in the PSA Firmware Update for A-profile Arm
> +Architecture specification [1]. Certain aspects of the Dependable
> +Boot specification [2] are also implemented. The feature provides a
> +mechanism to have multiple banks of updatable firmware images and for
> +updating the firmware images on the non-booted bank. On a successful
> +update, the platform boots from the updated bank on subsequent
> +boot. The UEFI capsule-on-disk update feature is used for performing
> +the actual updates of the updatable firmware images.
> +
> +The bookkeeping of the updatable images is done through a structure
> +called metadata. Currently, the FWU metadata supports identification
> +of images based on image GUIDs stored on a GPT partitioned storage
> +media. There are plans to extend the metadata structure for non GPT
> +partitioned devices as well.
> +
> +Accessing the FWU metadata is done through generic API's which are
> +defined in a driver which complies with the U-Boot's driver model. A
> +new uclass UCLASS_FWU_MDATA has been added for accessing the FWU
> +metadata. Individual drivers can be added based on the type of storage
> +media, and its partitioning method. Details of the storage device
> +containing the FWU metadata partitions are specified through a U-Boot
> +specific device tree property `fwu-mdata-store`. Please refer to
> +U-Boot `doc `__
> +for the device tree bindings.
> +
> +Enabling the FWU Multi Bank Update feature
> +--
> +
> +The feature can be enabled by specifying the following configs::
> +
> +CONFIG_EFI_CAPSULE_ON_DISK=y
> +CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT=y
> +CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
> +
> +CONFIG_FWU_MULTI_BANK_UPDATE=y
> +CONFIG_FWU_MDATA=y
> +CONFIG_FWU_MDATA_GPT_BLK=y
> +CONFIG_FWU_NUM_BANKS=
> +CONFIG_FWU_NUM_IMAGES_PER_BANK=
> +
> +in the .config file
> +
> +By enabling the CONFIG_CMD_FWU_METADATA config option, the
> +fwu_mdata_read command can be used to check the current state of the
> +FWU metadata structure.
> +
> +The first group of configuration settings enable the UEFI
> +capsule-on-disk update functionality. The second group of configs
> +enable the FWU Multi Bank Update functionality. Please refer to the
> +section :ref:`uefi_capsule_update_ref` for more details on generation
> +of the UEFI capsule.
> +
> +Setting up the device for GPT partitioned storage
> +-
> +
> +Before enabling the functionality in U-Boot, a GPT partitioned storage
> +device is required. Assuming a GPT partitioned storage device, the
> +storage media needs to be partitioned with the correct number of
> +partitions, given the number of banks and number of images per bank
> +that the platform is going to support. Each updatable firmware image
> +will be stored on a separate partition. In addition, the two copies
> +of the FWU metadata will be stored on two separate partitions. These
> +partitions need to be created at the time of the platform's
> +provisioning.
> +
> +As an example, a platform supporting two banks with each bank
> +containing three images would need to have 2 * 3 = 6 partitions plus
> +the two metadata partitions, or 8 partitions. In addition the storage
> +media can have additional partitions of non-updatable images, like the
> +EFI System Partition(ESP), a partition for the root file system
> +etc. An example list of images on the storage medium would be
> +
> +* FWU metadata 1
> +* U-Boot 1
> +* OP-TEE 1
> +* FWU metadata 2
> +* OP-TEE 2
> +* U-Boot 2
> +* ESP
> +* rootfs
> +
> +When generating the partitions, a few aspects need to be taken care
> +of. Each 

[PATCH] i2c: i2c-gpio: add newline

2022-10-20 Thread Sergei Antonov
Add newline at the end of the printed string.

Signed-off-by: Sergei Antonov 
---
 drivers/i2c/i2c-gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-gpio.c b/drivers/i2c/i2c-gpio.c
index 1aedad5c8ede..4ed9e9e7cddd 100644
--- a/drivers/i2c/i2c-gpio.c
+++ b/drivers/i2c/i2c-gpio.c
@@ -362,7 +362,7 @@ static int i2c_gpio_of_to_plat(struct udevice *dev)
 
return 0;
 error:
-   pr_err("Can't get %s gpios! Error: %d", dev->name, ret);
+   pr_err("Can't get %s gpios! Error: %d\n", dev->name, ret);
return ret;
 }
 
-- 
2.34.1



Re: [PATCH v14 14/15] mkeficapsule: Add support for setting OEM flags in capsule header

2022-10-20 Thread Etienne Carriere
On Thu, 20 Oct 2022 at 16:11, Sughosh Ganu  wrote:
>
> On Thu, 20 Oct 2022 at 19:25, Etienne Carriere
>  wrote:
> >
> > On Tue, 18 Oct 2022 at 13:44, Sughosh Ganu  wrote:
> > >
> > > Add support for setting OEM flags in the capsule header. As per the
> > > UEFI specification, bits 0-15 of the flags member of the capsule
> > > header can be defined per capsule GUID.
> > >
> > > The oemflags will be used for the FWU Multi Bank update feature, as
> > > specified by the Dependable Boot specification[1]. Bit
> > > 15 of the flags member will be used to determine if the
> > > acceptance/rejection of the updated images is to be done by the
> > > firmware or an external component like the OS.
> > >
> > > [1] - 
> > > https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf
> > >
> > > Signed-off-by: Sughosh Ganu 
> > > Reviewed-by: Ilias Apalodimas 
> > > ---
> > > Changes since V13: None
> > >
> > >  doc/mkeficapsule.1   |  4 
> > >  tools/mkeficapsule.c | 17 ++---
> > >  2 files changed, 18 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/doc/mkeficapsule.1 b/doc/mkeficapsule.1
> > > index 77ca061efd..6fb2dd0810 100644
> > > --- a/doc/mkeficapsule.1
> > > +++ b/doc/mkeficapsule.1
> > > @@ -72,6 +72,10 @@ Generate a firmware acceptance empty capsule
> > >  .BI "-R\fR,\fB --fw-revert "
> > >  Generate a firmware revert empty capsule
> > >
> > > +.TP
> > > +.BI "-o\fR,\fB --capoemflag "
> > > +Capsule OEM flag, value between 0x to 0x
> > > +
> > >  .TP
> > >  .BR -h ", " --help
> > >  Print a help message
> > > diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
> > > index 25bfb39e5b..b24f873b48 100644
> > > --- a/tools/mkeficapsule.c
> > > +++ b/tools/mkeficapsule.c
> > > @@ -29,7 +29,7 @@ static const char *tool_name = "mkeficapsule";
> > >  efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
> > >  efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
> > >
> > > -static const char *opts_short = "g:i:I:v:p:c:m:dhAR";
> > > +static const char *opts_short = "g:i:I:v:p:c:m:o:dhAR";
> > >
> > >  enum {
> > > CAPSULE_NORMAL_BLOB = 0,
> > > @@ -47,6 +47,7 @@ static struct option options[] = {
> > > {"dump-sig", no_argument, NULL, 'd'},
> > > {"fw-accept", no_argument, NULL, 'A'},
> > > {"fw-revert", no_argument, NULL, 'R'},
> > > +   {"capoemflag", required_argument, NULL, 'o'},
> > > {"help", no_argument, NULL, 'h'},
> > > {NULL, 0, NULL, 0},
> > >  };
> > > @@ -65,6 +66,7 @@ static void print_usage(void)
> > > "\t-d, --dump_sig  dump signature (*.p7)\n"
> > > "\t-A, --fw-accept  firmware accept capsule, requires 
> > > GUID, no image blob\n"
> > > "\t-R, --fw-revert  firmware revert capsule, takes no 
> > > GUID, no image blob\n"
> > > +   "\t-o, --capoemflag Capsule OEM Flag, an integer between 
> > > 0x and 0x\n"
> > > "\t-h, --help  print a help message\n",
> > > tool_name);
> > >  }
> > > @@ -387,6 +389,7 @@ static void free_sig_data(struct auth_context *ctx)
> > >   * @mcount:Monotonic count in authentication information
> > >   * @private_file:  Path to a private key file
> > >   * @cert_file: Path to a certificate file
> > > + * @oemflags:  Capsule OEM Flags, bits 0-15
> > >   *
> > >   * This function actually does the job of creating an uefi capsule file.
> > >   * All the arguments must be supplied.
> > > @@ -399,7 +402,8 @@ static void free_sig_data(struct auth_context *ctx)
> > >   */
> > >  static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
> > > unsigned long index, unsigned long instance,
> > > -   uint64_t mcount, char *privkey_file, char 
> > > *cert_file)
> > > +   uint64_t mcount, char *privkey_file, char 
> > > *cert_file,
> > > +   uint16_t oemflags)
> > >  {
> > > struct efi_capsule_header header;
> > > struct efi_firmware_management_capsule_header capsule;
> > > @@ -464,6 +468,8 @@ static int create_fwbin(char *path, char *bin, 
> > > efi_guid_t *guid,
> > > header.header_size = sizeof(header);
> > > /* TODO: The current implementation ignores flags */
> > > header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET;
> > > +   if (oemflags)
> > > +   header.flags |= oemflags;
> > > header.capsule_image_size = sizeof(header)
> > > + sizeof(capsule) + 
> > > sizeof(uint64_t)
> > > + sizeof(image)
> > > @@ -635,6 +641,7 @@ int main(int argc, char **argv)
> > > unsigned char uuid_buf[16];
> > > unsigned long index, instance;
> > > uint64_t mcount;
> > > +   uint16_t oemflags;
> > > char *privkey_file, *cert_file;
> > > int c, 

Re: [PATCH v14 08/15] event: Add an event for main_loop

2022-10-20 Thread Etienne Carriere
On Tue, 18 Oct 2022 at 13:44, Sughosh Ganu  wrote:
>
> Add an event type EVT_MAIN_LOOP that can be used for registering
> events that need to be run after the platform has been initialised and
> before the main_loop function is called.
>
> Signed-off-by: Sughosh Ganu 
> Reviewed-by: Simon Glass 
> Reviewed-by: Ilias Apalodimas 
> ---
> Changes since V13: None
>

Acked-by: Etienne Carriere 


>  common/board_r.c | 3 +++
>  common/event.c   | 3 +++
>  include/event.h  | 3 +++
>  3 files changed, 9 insertions(+)
>
> diff --git a/common/board_r.c b/common/board_r.c
> index 92ca2066ee..62e5e783f1 100644
> --- a/common/board_r.c
> +++ b/common/board_r.c
> @@ -579,6 +579,9 @@ static int run_main_loop(void)
>  #ifdef CONFIG_SANDBOX
> sandbox_main_loop_init();
>  #endif
> +
> +   event_notify_null(EVT_MAIN_LOOP);
> +
> /* main_loop() can return to retry autoboot, if so just run it again 
> */
> for (;;)
> main_loop();
> diff --git a/common/event.c b/common/event.c
> index 3e34550978..231b9e6ffd 100644
> --- a/common/event.c
> +++ b/common/event.c
> @@ -38,6 +38,9 @@ const char *const type_name[] = {
>
> /* fdt hooks */
> "ft_fixup",
> +
> +   /* main loop events */
> +   "main_loop",
>  };
>
>  _Static_assert(ARRAY_SIZE(type_name) == EVT_COUNT, "event type_name size");
> diff --git a/include/event.h b/include/event.h
> index 3e6dcbc3dd..e4580b6835 100644
> --- a/include/event.h
> +++ b/include/event.h
> @@ -34,6 +34,9 @@ enum event_t {
> /* Device tree fixups before booting */
> EVT_FT_FIXUP,
>
> +   /* To be called once, before calling main_loop() */
> +   EVT_MAIN_LOOP,
> +
> EVT_COUNT
>  };
>
> --
> 2.34.1
>


Re: [PATCH v14 07/15] FWU: STM32MP1: Add support to read boot index from backup register

2022-10-20 Thread Etienne Carriere
On Tue, 18 Oct 2022 at 13:44, Sughosh Ganu  wrote:
>
> The FWU Multi Bank Update feature allows the platform to boot the
> firmware images from one of the partitions(banks). The first stage
> bootloader(fsbl) passes the value of the boot index, i.e. the bank
> from which the firmware images were booted from to U-Boot. On the
> STM32MP157C-DK2 board, this value is passed through one of the SoC's
> backup register. Add a function to read the boot index value from the
> backup register.
>
> Signed-off-by: Sughosh Ganu 
> Reviewed-by: Patrick Delaunay 
> Acked-by: Ilias Apalodimas 
> ---
> Changes since V13: None
>

Acked-by: Etienne Carriere 

>  arch/arm/mach-stm32mp/include/mach/stm32.h |  5 +
>  board/st/stm32mp1/stm32mp1.c   | 21 +
>  include/fwu.h  | 12 
>  3 files changed, 38 insertions(+)
>
> diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h 
> b/arch/arm/mach-stm32mp/include/mach/stm32.h
> index c70375a723..c85ae6a34e 100644
> --- a/arch/arm/mach-stm32mp/include/mach/stm32.h
> +++ b/arch/arm/mach-stm32mp/include/mach/stm32.h
> @@ -112,11 +112,16 @@ enum boot_device {
>  #ifdef CONFIG_STM32MP15x
>  #define TAMP_BACKUP_MAGIC_NUMBER   TAMP_BACKUP_REGISTER(4)
>  #define TAMP_BACKUP_BRANCH_ADDRESS TAMP_BACKUP_REGISTER(5)
> +#define TAMP_FWU_BOOT_INFO_REG TAMP_BACKUP_REGISTER(10)
>  #define TAMP_COPRO_RSC_TBL_ADDRESS TAMP_BACKUP_REGISTER(17)
>  #define TAMP_COPRO_STATE   TAMP_BACKUP_REGISTER(18)
>  #define TAMP_BOOT_CONTEXT  TAMP_BACKUP_REGISTER(20)
>  #define TAMP_BOOTCOUNT TAMP_BACKUP_REGISTER(21)
>
> +#define TAMP_FWU_BOOT_IDX_MASK GENMASK(3, 0)
> +
> +#define TAMP_FWU_BOOT_IDX_OFFSET   0
> +
>  #define TAMP_COPRO_STATE_OFF   0
>  #define TAMP_COPRO_STATE_INIT  1
>  #define TAMP_COPRO_STATE_CRUN  2
> diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
> index 98e96d9e0b..47b3d1bf4c 100644
> --- a/board/st/stm32mp1/stm32mp1.c
> +++ b/board/st/stm32mp1/stm32mp1.c
> @@ -957,3 +957,24 @@ static void board_copro_image_process(ulong fw_image, 
> size_t fw_size)
>  }
>
>  U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);
> +
> +#if defined(CONFIG_FWU_MULTI_BANK_UPDATE)
> +
> +#include 
> +
> +/**
> + * fwu_plat_get_bootidx() - Get the value of the boot index
> + * @boot_idx: Boot index value
> + *
> + * Get the value of the bank(partition) from which the platform
> + * has booted. This value is passed to U-Boot from the earlier
> + * stage bootloader which loads and boots all the relevant
> + * firmware images
> + *
> + */
> +void fwu_plat_get_bootidx(uint *boot_idx)
> +{
> +   *boot_idx = (readl(TAMP_FWU_BOOT_INFO_REG) >>
> +   TAMP_FWU_BOOT_IDX_OFFSET) & TAMP_FWU_BOOT_IDX_MASK;
> +}
> +#endif /* CONFIG_FWU_MULTI_BANK_UPDATE */
> diff --git a/include/fwu.h b/include/fwu.h
> index b80ae1b35c..7d38cb5856 100644
> --- a/include/fwu.h
> +++ b/include/fwu.h
> @@ -333,4 +333,16 @@ int fwu_plat_get_alt_num(struct udevice *dev, efi_guid_t 
> *image_guid,
>   *
>   */
>  int fwu_plat_get_update_index(uint *update_idx);
> +
> +/**
> + * fwu_plat_get_bootidx() - Get the value of the boot index
> + * @boot_idx: Boot index value
> + *
> + * Get the value of the bank(partition) from which the platform
> + * has booted. This value is passed to U-Boot from the earlier
> + * stage bootloader which loads and boots all the relevant
> + * firmware images
> + *
> + */
> +void fwu_plat_get_bootidx(uint *boot_idx);
>  #endif /* _FWU_H_ */
> --
> 2.34.1
>


Re: [PATCH v14 13/15] mkeficapsule: Add support for generating empty capsules

2022-10-20 Thread Etienne Carriere
On Tue, 18 Oct 2022 at 13:44, Sughosh Ganu  wrote:
>
> The Dependable Boot specification[1] describes the structure of the
> firmware accept and revert capsules. These are empty capsules which
> are used for signalling the acceptance or rejection of the updated
> firmware by the OS. Add support for generating these empty capsules.
>
> [1] - 
> https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf
>
> Signed-off-by: Sughosh Ganu 
> Acked-by: Ilias Apalodimas 
> ---
> Changes since V13: None
>
>  doc/mkeficapsule.1   | 29 +
>  tools/eficapsule.h   |  8 
>  tools/mkeficapsule.c | 96 
>  3 files changed, 119 insertions(+), 14 deletions(-)
>

Acked-by: Etienne Carriere 


> diff --git a/doc/mkeficapsule.1 b/doc/mkeficapsule.1
> index 09bdc24295..77ca061efd 100644
> --- a/doc/mkeficapsule.1
> +++ b/doc/mkeficapsule.1
> @@ -8,7 +8,7 @@ mkeficapsule \- Generate EFI capsule file for U-Boot
>
>  .SH SYNOPSIS
>  .B mkeficapsule
> -.RI [ options "] " image-blob " " capsule-file
> +.RI [ options ] " " [ image-blob ] " " capsule-file
>
>  .SH "DESCRIPTION"
>  .B mkeficapsule
> @@ -23,8 +23,13 @@ Optionally, a capsule file can be signed with a given 
> private key.
>  In this case, the update will be authenticated by verifying the signature
>  before applying.
>
> +Additionally, an empty capsule file can be generated for acceptance or
> +rejection of firmware images by a governing component like an Operating
> +System. The empty capsules do not require an image-blob input file.
> +
> +
>  .B mkeficapsule
> -takes any type of image files, including:
> +takes any type of image files when generating non empty capsules, including:
>  .TP
>  .I raw image
>  format is a single binary blob of any type of firmware.
> @@ -36,18 +41,16 @@ multiple binary blobs in a single capsule file.
>  This type of image file can be generated by
>  .BR mkimage .
>
> -.PP
> -If you want to use other types than above two, you should explicitly
> -specify a guid for the FMP driver.
> -
>  .SH "OPTIONS"
> +
>  .TP
>  .BI "-g\fR,\fB --guid " guid-string
>  Specify guid for image blob type. The format is:
>  ----
>
>  The first three elements are in little endian, while the rest
> -is in big endian.
> +is in big endian. The option must be specified for all non empty and
> +image acceptance capsules
>
>  .TP
>  .BI "-i\fR,\fB --index " index
> @@ -57,6 +60,18 @@ Specify an image index
>  .BI "-I\fR,\fB --instance " instance
>  Specify a hardware instance
>
> +.PP
> +For generation of firmware accept empty capsule
> +.BR --guid
> +is mandatory
> +.TP
> +.BI "-A\fR,\fB --fw-accept "
> +Generate a firmware acceptance empty capsule
> +
> +.TP
> +.BI "-R\fR,\fB --fw-revert "
> +Generate a firmware revert empty capsule
> +
>  .TP
>  .BR -h ", " --help
>  Print a help message
> diff --git a/tools/eficapsule.h b/tools/eficapsule.h
> index d63b831443..072a4b5598 100644
> --- a/tools/eficapsule.h
> +++ b/tools/eficapsule.h
> @@ -41,6 +41,14 @@ typedef struct {
> EFI_GUID(0x4aafd29d, 0x68df, 0x49ee, 0x8a, 0xa9, \
>  0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7)
>
> +#define FW_ACCEPT_OS_GUID \
> +   EFI_GUID(0x0c996046, 0xbcc0, 0x4d04, 0x85, 0xec, \
> +0xe1, 0xfc, 0xed, 0xf1, 0xc6, 0xf8)
> +
> +#define FW_REVERT_OS_GUID \
> +   EFI_GUID(0xacd58b4b, 0xc0e8, 0x475f, 0x99, 0xb5, \
> +0x6b, 0x3f, 0x7e, 0x07, 0xaa, 0xf0)
> +
>  /* flags */
>  #define CAPSULE_FLAGS_PERSIST_ACROSS_RESET  0x0001
>
> diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
> index 5f74d23b9e..25bfb39e5b 100644
> --- a/tools/mkeficapsule.c
> +++ b/tools/mkeficapsule.c
> @@ -29,7 +29,13 @@ static const char *tool_name = "mkeficapsule";
>  efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
>  efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
>
> -static const char *opts_short = "g:i:I:v:p:c:m:dh";
> +static const char *opts_short = "g:i:I:v:p:c:m:dhAR";
> +
> +enum {
> +   CAPSULE_NORMAL_BLOB = 0,
> +   CAPSULE_ACCEPT,
> +   CAPSULE_REVERT,
> +} capsule_type;
>
>  static struct option options[] = {
> {"guid", required_argument, NULL, 'g'},
> @@ -39,6 +45,8 @@ static struct option options[] = {
> {"certificate", required_argument, NULL, 'c'},
> {"monotonic-count", required_argument, NULL, 'm'},
> {"dump-sig", no_argument, NULL, 'd'},
> +   {"fw-accept", no_argument, NULL, 'A'},
> +   {"fw-revert", no_argument, NULL, 'R'},
> {"help", no_argument, NULL, 'h'},
> {NULL, 0, NULL, 0},
>  };
> @@ -55,6 +63,8 @@ static void print_usage(void)
> "\t-c, --certificate  signer's certificate 
> file\n"
> "\t-m, --monotonic-count  monotonic count\n"
> "\t-d, --dump_sig  dump signature (*.p7)\n"
> +   "\t-A, --fw-accept 

Re: [PATCH v14 14/15] mkeficapsule: Add support for setting OEM flags in capsule header

2022-10-20 Thread Sughosh Ganu
On Thu, 20 Oct 2022 at 19:25, Etienne Carriere
 wrote:
>
> On Tue, 18 Oct 2022 at 13:44, Sughosh Ganu  wrote:
> >
> > Add support for setting OEM flags in the capsule header. As per the
> > UEFI specification, bits 0-15 of the flags member of the capsule
> > header can be defined per capsule GUID.
> >
> > The oemflags will be used for the FWU Multi Bank update feature, as
> > specified by the Dependable Boot specification[1]. Bit
> > 15 of the flags member will be used to determine if the
> > acceptance/rejection of the updated images is to be done by the
> > firmware or an external component like the OS.
> >
> > [1] - 
> > https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf
> >
> > Signed-off-by: Sughosh Ganu 
> > Reviewed-by: Ilias Apalodimas 
> > ---
> > Changes since V13: None
> >
> >  doc/mkeficapsule.1   |  4 
> >  tools/mkeficapsule.c | 17 ++---
> >  2 files changed, 18 insertions(+), 3 deletions(-)
> >
> > diff --git a/doc/mkeficapsule.1 b/doc/mkeficapsule.1
> > index 77ca061efd..6fb2dd0810 100644
> > --- a/doc/mkeficapsule.1
> > +++ b/doc/mkeficapsule.1
> > @@ -72,6 +72,10 @@ Generate a firmware acceptance empty capsule
> >  .BI "-R\fR,\fB --fw-revert "
> >  Generate a firmware revert empty capsule
> >
> > +.TP
> > +.BI "-o\fR,\fB --capoemflag "
> > +Capsule OEM flag, value between 0x to 0x
> > +
> >  .TP
> >  .BR -h ", " --help
> >  Print a help message
> > diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
> > index 25bfb39e5b..b24f873b48 100644
> > --- a/tools/mkeficapsule.c
> > +++ b/tools/mkeficapsule.c
> > @@ -29,7 +29,7 @@ static const char *tool_name = "mkeficapsule";
> >  efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
> >  efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
> >
> > -static const char *opts_short = "g:i:I:v:p:c:m:dhAR";
> > +static const char *opts_short = "g:i:I:v:p:c:m:o:dhAR";
> >
> >  enum {
> > CAPSULE_NORMAL_BLOB = 0,
> > @@ -47,6 +47,7 @@ static struct option options[] = {
> > {"dump-sig", no_argument, NULL, 'd'},
> > {"fw-accept", no_argument, NULL, 'A'},
> > {"fw-revert", no_argument, NULL, 'R'},
> > +   {"capoemflag", required_argument, NULL, 'o'},
> > {"help", no_argument, NULL, 'h'},
> > {NULL, 0, NULL, 0},
> >  };
> > @@ -65,6 +66,7 @@ static void print_usage(void)
> > "\t-d, --dump_sig  dump signature (*.p7)\n"
> > "\t-A, --fw-accept  firmware accept capsule, requires GUID, 
> > no image blob\n"
> > "\t-R, --fw-revert  firmware revert capsule, takes no GUID, 
> > no image blob\n"
> > +   "\t-o, --capoemflag Capsule OEM Flag, an integer between 
> > 0x and 0x\n"
> > "\t-h, --help  print a help message\n",
> > tool_name);
> >  }
> > @@ -387,6 +389,7 @@ static void free_sig_data(struct auth_context *ctx)
> >   * @mcount:Monotonic count in authentication information
> >   * @private_file:  Path to a private key file
> >   * @cert_file: Path to a certificate file
> > + * @oemflags:  Capsule OEM Flags, bits 0-15
> >   *
> >   * This function actually does the job of creating an uefi capsule file.
> >   * All the arguments must be supplied.
> > @@ -399,7 +402,8 @@ static void free_sig_data(struct auth_context *ctx)
> >   */
> >  static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
> > unsigned long index, unsigned long instance,
> > -   uint64_t mcount, char *privkey_file, char 
> > *cert_file)
> > +   uint64_t mcount, char *privkey_file, char 
> > *cert_file,
> > +   uint16_t oemflags)
> >  {
> > struct efi_capsule_header header;
> > struct efi_firmware_management_capsule_header capsule;
> > @@ -464,6 +468,8 @@ static int create_fwbin(char *path, char *bin, 
> > efi_guid_t *guid,
> > header.header_size = sizeof(header);
> > /* TODO: The current implementation ignores flags */
> > header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET;
> > +   if (oemflags)
> > +   header.flags |= oemflags;
> > header.capsule_image_size = sizeof(header)
> > + sizeof(capsule) + sizeof(uint64_t)
> > + sizeof(image)
> > @@ -635,6 +641,7 @@ int main(int argc, char **argv)
> > unsigned char uuid_buf[16];
> > unsigned long index, instance;
> > uint64_t mcount;
> > +   uint16_t oemflags;
> > char *privkey_file, *cert_file;
> > int c, idx;
> >
> > @@ -646,6 +653,7 @@ int main(int argc, char **argv)
> > cert_file = NULL;
> > dump_sig = 0;
> > capsule_type = CAPSULE_NORMAL_BLOB;
> > +   oemflags = 0;
> > for (;;) {
> > c = getopt_long(argc, argv, opts_short, 

Re: [PATCH v14 15/15] FWU: doc: Add documentation for the FWU feature

2022-10-20 Thread Etienne Carriere
On Tue, 18 Oct 2022 at 16:26, Ilias Apalodimas
 wrote:
>
> On Tue, Oct 18, 2022 at 05:13:37PM +0530, Sughosh Ganu wrote:
> > Add documentation for the FWU Multi Bank Update feature. The document
> > describes the steps needed for setting up the platform for the
> > feature, as well as steps for enabling the feature on the platform.
> >
> > Signed-off-by: Sughosh Ganu 
> > ---
> > Changes since V13: None
> >
> >  doc/develop/uefi/fwu_updates.rst | 184 +++
> >  doc/develop/uefi/index.rst   |   1 +
> >  doc/develop/uefi/uefi.rst|  12 ++
> >  3 files changed, 197 insertions(+)
> >  create mode 100644 doc/develop/uefi/fwu_updates.rst
> >
> > diff --git a/doc/develop/uefi/fwu_updates.rst 
> > b/doc/develop/uefi/fwu_updates.rst
> > new file mode 100644
> > index 00..068616ce83
> > --- /dev/null
> > +++ b/doc/develop/uefi/fwu_updates.rst
> > @@ -0,0 +1,184 @@
> > +.. SPDX-License-Identifier: GPL-2.0+
> > +.. Copyright (c) 2022 Linaro Limited
> > +
> > +FWU Multi Bank Updates in U-Boot
> > +
> > +
> > +The FWU Multi Bank Update feature implements the firmware update
> > +mechanism described in the PSA Firmware Update for A-profile Arm
> > +Architecture specification [1]. Certain aspects of the Dependable
> > +Boot specification [2] are also implemented. The feature provides a
> > +mechanism to have multiple banks of updatable firmware images and for
> > +updating the firmware images on the non-booted bank. On a successful
> > +update, the platform boots from the updated bank on subsequent
> > +boot. The UEFI capsule-on-disk update feature is used for performing
> > +the actual updates of the updatable firmware images.
> > +
> > +The bookkeeping of the updatable images is done through a structure
> > +called metadata. Currently, the FWU metadata supports identification
> > +of images based on image GUIDs stored on a GPT partitioned storage
> > +media. There are plans to extend the metadata structure for non GPT
> > +partitioned devices as well.
> > +
> > +Accessing the FWU metadata is done through generic API's which are
> > +defined in a driver which complies with the U-Boot's driver model. A
> > +new uclass UCLASS_FWU_MDATA has been added for accessing the FWU
> > +metadata. Individual drivers can be added based on the type of storage
> > +media, and its partitioning method. Details of the storage device
> > +containing the FWU metadata partitions are specified through a U-Boot
> > +specific device tree property `fwu-mdata-store`. Please refer to
> > +U-Boot `doc `__
> > +for the device tree bindings.
> > +
> > +Enabling the FWU Multi Bank Update feature
> > +--
> > +
> > +The feature can be enabled by specifying the following configs::
> > +
> > +CONFIG_EFI_CAPSULE_ON_DISK=y
> > +CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT=y
> > +CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
> > +
> > +CONFIG_FWU_MULTI_BANK_UPDATE=y
> > +CONFIG_FWU_MDATA=y
> > +CONFIG_FWU_MDATA_GPT_BLK=y
> > +CONFIG_FWU_NUM_BANKS=
> > +CONFIG_FWU_NUM_IMAGES_PER_BANK=
> > +
> > +in the .config file
> > +
> > +By enabling the CONFIG_CMD_FWU_METADATA config option, the
> > +fwu_mdata_read command can be used to check the current state of the
> > +FWU metadata structure.
> > +
> > +The first group of configuration settings enable the UEFI
> > +capsule-on-disk update functionality. The second group of configs
> > +enable the FWU Multi Bank Update functionality. Please refer to the
> > +section :ref:`uefi_capsule_update_ref` for more details on generation
> > +of the UEFI capsule.
> > +
> > +Setting up the device for GPT partitioned storage
> > +-
> > +
> > +Before enabling the functionality in U-Boot, a GPT partitioned storage
> > +device is required. Assuming a GPT partitioned storage device, the
> > +storage media needs to be partitioned with the correct number of
> > +partitions, given the number of banks and number of images per bank
> > +that the platform is going to support. Each updatable firmware image
> > +will be stored on a separate partition. In addition, the two copies
> > +of the FWU metadata will be stored on two separate partitions. These
> > +partitions need to be created at the time of the platform's
> > +provisioning.
> > +
> > +As an example, a platform supporting two banks with each bank
> > +containing three images would need to have 2 * 3 = 6 partitions plus
> > +the two metadata partitions, or 8 partitions. In addition the storage
> > +media can have additional partitions of non-updatable images, like the
> > +EFI System Partition(ESP), a partition for the root file system
> > +etc. An example list of images on the storage medium would be
> > +
> > +* FWU metadata 1
> > +* U-Boot 1
> > +* OP-TEE 1
> > +* FWU metadata 2
> > +* OP-TEE 2
> > +* U-Boot 2
> > +* ESP
> > +* rootfs
> > +
> > +When generating the partitions, a few aspects need to be taken 

Re: [PATCH v14 14/15] mkeficapsule: Add support for setting OEM flags in capsule header

2022-10-20 Thread Etienne Carriere
On Tue, 18 Oct 2022 at 13:44, Sughosh Ganu  wrote:
>
> Add support for setting OEM flags in the capsule header. As per the
> UEFI specification, bits 0-15 of the flags member of the capsule
> header can be defined per capsule GUID.
>
> The oemflags will be used for the FWU Multi Bank update feature, as
> specified by the Dependable Boot specification[1]. Bit
> 15 of the flags member will be used to determine if the
> acceptance/rejection of the updated images is to be done by the
> firmware or an external component like the OS.
>
> [1] - 
> https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf
>
> Signed-off-by: Sughosh Ganu 
> Reviewed-by: Ilias Apalodimas 
> ---
> Changes since V13: None
>
>  doc/mkeficapsule.1   |  4 
>  tools/mkeficapsule.c | 17 ++---
>  2 files changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/doc/mkeficapsule.1 b/doc/mkeficapsule.1
> index 77ca061efd..6fb2dd0810 100644
> --- a/doc/mkeficapsule.1
> +++ b/doc/mkeficapsule.1
> @@ -72,6 +72,10 @@ Generate a firmware acceptance empty capsule
>  .BI "-R\fR,\fB --fw-revert "
>  Generate a firmware revert empty capsule
>
> +.TP
> +.BI "-o\fR,\fB --capoemflag "
> +Capsule OEM flag, value between 0x to 0x
> +
>  .TP
>  .BR -h ", " --help
>  Print a help message
> diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
> index 25bfb39e5b..b24f873b48 100644
> --- a/tools/mkeficapsule.c
> +++ b/tools/mkeficapsule.c
> @@ -29,7 +29,7 @@ static const char *tool_name = "mkeficapsule";
>  efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
>  efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
>
> -static const char *opts_short = "g:i:I:v:p:c:m:dhAR";
> +static const char *opts_short = "g:i:I:v:p:c:m:o:dhAR";
>
>  enum {
> CAPSULE_NORMAL_BLOB = 0,
> @@ -47,6 +47,7 @@ static struct option options[] = {
> {"dump-sig", no_argument, NULL, 'd'},
> {"fw-accept", no_argument, NULL, 'A'},
> {"fw-revert", no_argument, NULL, 'R'},
> +   {"capoemflag", required_argument, NULL, 'o'},
> {"help", no_argument, NULL, 'h'},
> {NULL, 0, NULL, 0},
>  };
> @@ -65,6 +66,7 @@ static void print_usage(void)
> "\t-d, --dump_sig  dump signature (*.p7)\n"
> "\t-A, --fw-accept  firmware accept capsule, requires GUID, 
> no image blob\n"
> "\t-R, --fw-revert  firmware revert capsule, takes no GUID, 
> no image blob\n"
> +   "\t-o, --capoemflag Capsule OEM Flag, an integer between 
> 0x and 0x\n"
> "\t-h, --help  print a help message\n",
> tool_name);
>  }
> @@ -387,6 +389,7 @@ static void free_sig_data(struct auth_context *ctx)
>   * @mcount:Monotonic count in authentication information
>   * @private_file:  Path to a private key file
>   * @cert_file: Path to a certificate file
> + * @oemflags:  Capsule OEM Flags, bits 0-15
>   *
>   * This function actually does the job of creating an uefi capsule file.
>   * All the arguments must be supplied.
> @@ -399,7 +402,8 @@ static void free_sig_data(struct auth_context *ctx)
>   */
>  static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
> unsigned long index, unsigned long instance,
> -   uint64_t mcount, char *privkey_file, char *cert_file)
> +   uint64_t mcount, char *privkey_file, char *cert_file,
> +   uint16_t oemflags)
>  {
> struct efi_capsule_header header;
> struct efi_firmware_management_capsule_header capsule;
> @@ -464,6 +468,8 @@ static int create_fwbin(char *path, char *bin, efi_guid_t 
> *guid,
> header.header_size = sizeof(header);
> /* TODO: The current implementation ignores flags */
> header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET;
> +   if (oemflags)
> +   header.flags |= oemflags;
> header.capsule_image_size = sizeof(header)
> + sizeof(capsule) + sizeof(uint64_t)
> + sizeof(image)
> @@ -635,6 +641,7 @@ int main(int argc, char **argv)
> unsigned char uuid_buf[16];
> unsigned long index, instance;
> uint64_t mcount;
> +   uint16_t oemflags;
> char *privkey_file, *cert_file;
> int c, idx;
>
> @@ -646,6 +653,7 @@ int main(int argc, char **argv)
> cert_file = NULL;
> dump_sig = 0;
> capsule_type = CAPSULE_NORMAL_BLOB;
> +   oemflags = 0;
> for (;;) {
> c = getopt_long(argc, argv, opts_short, options, );
> if (c == -1)
> @@ -709,6 +717,9 @@ int main(int argc, char **argv)
> }
> capsule_type = CAPSULE_REVERT;
> break;
> +   case 'o':
> +   oemflags = strtoul(optarg, 

Re: [PATCH v2] spl: fit: Report fdt error for loading u-boot

2022-10-20 Thread Mark Kettenis
> From: Simon Glass 
> Date: Wed, 19 Oct 2022 08:15:35 -0600
> 
> Hi Mark,
> 
> On Wed, 19 Oct 2022 at 08:08, Mark Kettenis  wrote:
> >
> > > From: Simon Glass 
> > > Date: Wed, 19 Oct 2022 07:18:10 -0600
> > >
> > > Hi,
> > >
> > > On Mon, 17 Oct 2022 at 05:53, Su, Bao Cheng  
> > > wrote:
> > > >
> > > > Hi Simon,
> > > >
> > >
> > > +Tom Rini for guidance
> > >
> > > > On Sat, 2022-07-30 at 19:27 -0600, Simon Glass wrote:
> > > > > Hi Bao Cheng,
> > > > >
> > > > > On Sat, 30 Jul 2022 at 03:05, Su, Bao Cheng  
> > > > > wrote:
> > > > > >
> > > > > > Commit 71551055cbdb ("spl: fit: Load devicetree when a Linux 
> > > > > > payload is
> > > > > > found") made a change to not report the spl_fit_append_fdt error at 
> > > > > > all
> > > > > > if next-stage image is u-boot.
> > > > > >
> > > > > > However for u-boot image without CONFIG_OF_EMBED, the error should 
> > > > > > be
> > > > > > reported to uplevel caller. Otherwise, uplevel caller would think 
> > > > > > the
> > > > > > fdt is already loaded which is obviously not true.
> > > > > >
> > > > > > Signed-off-by: Baocheng Su 
> > > > > > ---
> > > > > >
> > > > > > Changes in v2:
> > > > > > - Fix the wrong wrapping
> > > > > >
> > > > > >  common/spl/spl_fit.c | 8 ++--
> > > > > >  1 file changed, 6 insertions(+), 2 deletions(-)
> > > > > >
> > > > > > diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
> > > > > > index a35be52965..00404935cb 100644
> > > > > > --- a/common/spl/spl_fit.c
> > > > > > +++ b/common/spl/spl_fit.c
> > > > > > @@ -770,8 +770,12 @@ int spl_load_simple_fit(struct spl_image_info 
> > > > > > *spl_image,
> > > > > >  */
> > > > > > if (os_takes_devicetree(spl_image->os)) {
> > > > > > ret = spl_fit_append_fdt(spl_image, info, sector, 
> > > > > > );
> > > > > > -   if (ret < 0 && spl_image->os != IH_OS_U_BOOT)
> > > > > > -   return ret;
> > > > > > +   if (ret < 0) {
> > > > > > +   if (spl_image->os != IH_OS_U_BOOT)
> > > > > > +   return ret;
> > > > > > +   else if (!IS_ENABLED(CONFIG_OF_EMBED))
> > > > > > +   return ret;
> > > > >
> > > > > This is a pretty unpleasant condition. I think we would be better to
> > > > > report the error and let the caller figure it out.
> > > > >
> > > > > There are no tests associated with this, so it is hard to know what is
> > > > > actually going on.
> > > > >
> > > > > If we must have this workaround, I suggest adding a Kconfig so boards
> > > > > that need it can turn it on, and other boards can use normal
> > > > > operation, which is to report errors.
> > > > >
> > > >
> > > > Since there is no particular error code stands for such kind of
> > > > scenario, it would be hard for the caller to determine which step has
> > > > the problem.
> > > >
> > > > Or below code is more clear?
> > > >
> > > > if (os_takes_devicetree(spl_image->os)) {
> > > > ret = spl_fit_append_fdt(spl_image, info, sector, );
> > > > -   if (ret < 0 && spl_image->os != IH_OS_U_BOOT)
> > > > -   return ret;
> > > > +   if (ret < 0
> > > > +&& (spl_image->os != IH_OS_U_BOOT
> > > > +  || !IS_ENABLED(CONFIG_OF_EMBED)))
> > > > +   return ret;
> > > > }
> > > >
> > > > Actually there is already the `CONFIG_OF_EMBED` to tell them apart, see
> > > > the previous logic before commit 71551055cbdb:
> > > >
> > > >  * Booting a next-stage U-Boot may require us to append the FDT.
> > > >  * We allow this to fail, as the U-Boot image might embed its
> > > > FDT.
> > > >  */
> > > > -   if (spl_image->os == IH_OS_U_BOOT) {
> > > > +   if (os_takes_devicetree(spl_image->os)) {
> > > > ret = spl_fit_append_fdt(spl_image, info, sector, );
> > > > -   if (!IS_ENABLED(CONFIG_OF_EMBED) && ret < 0)
> > > > +   if (ret < 0 && spl_image->os != IH_OS_U_BOOT)
> > > > return ret;
> > > > }
> > > >
> > > > So before the commit 71551055cbdb, the normal case would be to report
> > > > the error, but the commit in question changed this to not report the
> > > > error for normal spl to boot u-boot, only reports error for SPL to boot
> > > > kernel, i.e. falcon mode.
> > >
> > > We don't (or shouldn't) have boards which use OF_EMBED in mainline, so
> > > that condition doesn't seem to make sense to me.
> >
> > We have plenty of boards that set OF_EMBED, and as some of us have
> > pointed out to you more than once before, there are several valid use
> > cases for it.
> 
> Can you point me to the discussion about the valid use cases?

Not easily since there were several lengthy discussions about device
trees.

Most of the use cases boil down to the following:

* There is some low-level firmware or virtualization 

[u-boot][PATCH v3 4/4] memory: Add TI GPMC driver

2022-10-20 Thread Roger Quadros
The GPMC is a unified memory controller dedicated for interfacing
with external memory devices like
 - Asynchronous SRAM-like memories and ASICs
 - Asynchronous, synchronous, and page mode burst NOR flash
 - NAND flash
 - Pseudo-SRAM devices

This driver will take care of setting up the GPMC based on
the settings specified in the Device tree and then
probe its children.

Signed-off-by: Roger Quadros 
---
 drivers/memory/Kconfig|   19 +
 drivers/memory/Makefile   |1 +
 drivers/memory/ti-gpmc.c  | 1240 +
 drivers/memory/ti-gpmc.h  |  298 
 include/linux/mtd/omap_gpmc.h |3 +
 5 files changed, 1561 insertions(+)
 create mode 100644 drivers/memory/ti-gpmc.c
 create mode 100644 drivers/memory/ti-gpmc.h

diff --git a/drivers/memory/Kconfig b/drivers/memory/Kconfig
index c621f5bba3..56b89f17be 100644
--- a/drivers/memory/Kconfig
+++ b/drivers/memory/Kconfig
@@ -41,4 +41,23 @@ config TI_AEMIF
  of 256M bytes of any of these memories can be accessed at a given
  time via four chip selects with 64M byte access per chip select.
 
+config TI_GPMC
+   bool "Texas Instruments GPMC driver"
+   depends on ARCH_OMAP2PLUS || ARCH_KEYSTONE || ARCH_K3
+   depends on MEMORY && CLK && OF_CONTROL
+   help
+ This driver is for the General Purpose Memory Controller (GPMC)
+  present on Texas Instruments SoCs (e.g. OMAP2+). GPMC allows
+  interfacing to a variety of asynchronous as well as synchronous
+  memory drives like NOR, NAND, OneNAND, SRAM.
+
+if TI_GPMC
+config TI_GPMC_DEBUG
+   bool "Debug Texas Instruments GPMC timings"
+   default n
+   help
+ Enable this to print GPMC timings before and after the GPMC registers
+ are programmed. This should not be left enabled on production systems.
+endif
+
 endmenu
diff --git a/drivers/memory/Makefile b/drivers/memory/Makefile
index b27f701865..2b196d78c0 100644
--- a/drivers/memory/Makefile
+++ b/drivers/memory/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_MEMORY) += memory-uclass.o
 obj-$(CONFIG_SANDBOX_MEMORY) += memory-sandbox.o
 obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o
 obj-$(CONFIG_TI_AEMIF) += ti-aemif.o
+obj-$(CONFIG_TI_GPMC) += ti-gpmc.o
diff --git a/drivers/memory/ti-gpmc.c b/drivers/memory/ti-gpmc.c
new file mode 100644
index 00..f511a529b1
--- /dev/null
+++ b/drivers/memory/ti-gpmc.c
@@ -0,0 +1,1240 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Texas Instruments GPMC Driver
+ *
+ * Copyright (C) 2021 Texas Instruments Incorporated - http://www.ti.com/
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "ti-gpmc.h"
+
+enum gpmc_clk_domain {
+   GPMC_CD_FCLK,
+   GPMC_CD_CLK
+};
+
+struct gpmc_cs_data {
+   const char *name;
+#define GPMC_CS_RESERVED   BIT(0)
+   u32 flags;
+};
+
+struct ti_gpmc {
+   void __iomem *base;
+   u32 cs_num;
+   u32 nr_waitpins;
+   struct clk *l3_clk;
+   u32 capability_flags;
+   struct resource data;
+};
+
+static struct gpmc_cs_data gpmc_cs[GPMC_CS_NUM];
+static unsigned int gpmc_cs_num = GPMC_CS_NUM;
+static unsigned int gpmc_nr_waitpins;
+static unsigned int gpmc_capability;
+static void __iomem *gpmc_base;
+static struct clk *gpmc_l3_clk;
+
+/* Public, as required by nand/raw/omap_gpmc.c */
+const struct gpmc *gpmc_cfg;
+
+/*
+ * The first 1MB of GPMC address space is typically mapped to
+ * the internal ROM. Never allocate the first page, to
+ * facilitate bug detection; even if we didn't boot from ROM.
+ * As GPMC minimum partition size is 16MB we can only start from
+ * there.
+ */
+#define GPMC_MEM_START 0x100
+#define GPMC_MEM_END   0x3FFF
+
+static void gpmc_write_reg(int idx, u32 val)
+{
+   writel_relaxed(val, gpmc_base + idx);
+}
+
+static u32 gpmc_read_reg(int idx)
+{
+   return readl_relaxed(gpmc_base + idx);
+}
+
+static void gpmc_cs_write_reg(int cs, int idx, u32 val)
+{
+   void __iomem *reg_addr;
+
+   reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
+   writel_relaxed(val, reg_addr);
+}
+
+static u32 gpmc_cs_read_reg(int cs, int idx)
+{
+   void __iomem *reg_addr;
+
+   reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
+   return readl_relaxed(reg_addr);
+}
+
+static unsigned long gpmc_get_fclk_period(void)
+{
+   unsigned long rate = clk_get_rate(gpmc_l3_clk);
+
+   rate /= 1000;
+   rate = 10 / rate;   /* In picoseconds */
+
+   return rate;
+}
+
+/**
+ * gpmc_get_clk_period - get period of selected clock domain in ps
+ * @cs: Chip Select Region.
+ * @cd: Clock Domain.
+ *
+ * GPMC_CS_CONFIG1 GPMCFCLKDIVIDER for cs has to be setup
+ * prior to calling this function with GPMC_CD_CLK.
+ */
+static unsigned long gpmc_get_clk_period(int cs, enum gpmc_clk_domain cd)
+{
+   unsigned long tick_ps = 

[u-boot][PATCH v3 3/4] dt/bindings: memory: Add bindings for TI GPMC driver

2022-10-20 Thread Roger Quadros
GPMC stands for General Purpose Memory Controller and it is
present on many Texas Instruments SoCs.

It supports a number of Asynchronous and Synchronous interfaces
and has various settings to configure the bus interface.

The DT bindings define all the various GPMC settings.

As the GPMC supports multiple devices on the bus, each
device is represented as a child and the respective
GPMC settings are situated there. (see ti,gpmc-child.yaml)

These binding docs are picked up from the Linux kernel.

Signed-off-by: Roger Quadros 
---
 .../memory/ti,gpmc-child.yaml | 252 ++
 doc/device-tree-bindings/memory/ti,gpmc.yaml  | 190 +
 2 files changed, 442 insertions(+)
 create mode 100644 doc/device-tree-bindings/memory/ti,gpmc-child.yaml
 create mode 100644 doc/device-tree-bindings/memory/ti,gpmc.yaml

diff --git a/doc/device-tree-bindings/memory/ti,gpmc-child.yaml 
b/doc/device-tree-bindings/memory/ti,gpmc-child.yaml
new file mode 100644
index 00..8e541acdb1
--- /dev/null
+++ b/doc/device-tree-bindings/memory/ti,gpmc-child.yaml
@@ -0,0 +1,252 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/memory-controllers/ti,gpmc-child.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: device tree bindings for children of the Texas Instruments GPMC
+
+maintainers:
+  - Tony Lindgren 
+  - Roger Quadros 
+
+description:
+  This binding is meant for the child nodes of the GPMC node. The node
+  represents any device connected to the GPMC bus. It may be a Flash chip,
+  RAM chip or Ethernet controller, etc. These properties are meant for
+  configuring the GPMC settings/timings and will accompany the bindings
+  supported by the respective device.
+
+properties:
+  reg: true
+
+# GPMC Timing properties for child nodes. All are optional and default to 0.
+  gpmc,sync-clk-ps:
+description: Minimum clock period for synchronous mode
+default: 0
+
+# Chip-select signal timings corresponding to GPMC_CONFIG2:
+  gpmc,cs-on-ns:
+description: Assertion time
+default: 0
+
+  gpmc,cs-rd-off-ns:
+description: Read deassertion time
+default: 0
+
+  gpmc,cs-wr-off-ns:
+description: Write deassertion time
+default: 0
+
+# ADV signal timings corresponding to GPMC_CONFIG3:
+  gpmc,adv-on-ns:
+description: Assertion time
+default: 0
+
+  gpmc,adv-rd-off-ns:
+description: Read deassertion time
+default: 0
+
+  gpmc,adv-wr-off-ns:
+description: Write deassertion time
+default: 0
+
+  gpmc,adv-aad-mux-on-ns:
+description: Assertion time for AAD
+default: 0
+
+  gpmc,adv-aad-mux-rd-off-ns:
+description: Read deassertion time for AAD
+default: 0
+
+  gpmc,adv-aad-mux-wr-off-ns:
+description: Write deassertion time for AAD
+default: 0
+
+# WE signals timings corresponding to GPMC_CONFIG4:
+  gpmc,we-on-ns:
+description: Assertion time
+default: 0
+
+  gpmc,we-off-ns:
+description: Deassertion time
+default: 0
+
+# OE signals timings corresponding to GPMC_CONFIG4:
+  gpmc,oe-on-ns:
+description: Assertion time
+default: 0
+
+  gpmc,oe-off-ns:
+description: Deassertion time
+default: 0
+
+  gpmc,oe-aad-mux-on-ns:
+description: Assertion time for AAD
+default: 0
+
+  gpmc,oe-aad-mux-off-ns:
+description: Deassertion time for AAD
+default: 0
+
+# Access time and cycle time timings (in nanoseconds) corresponding to
+# GPMC_CONFIG5:
+  gpmc,page-burst-access-ns:
+description: Multiple access word delay
+default: 0
+
+  gpmc,access-ns:
+description: Start-cycle to first data valid delay
+default: 0
+
+  gpmc,rd-cycle-ns:
+description: Total read cycle time
+default: 0
+
+  gpmc,wr-cycle-ns:
+description: Total write cycle time
+default: 0
+
+  gpmc,bus-turnaround-ns:
+description: Turn-around time between successive accesses
+default: 0
+
+  gpmc,cycle2cycle-delay-ns:
+description: Delay between chip-select pulses
+default: 0
+
+  gpmc,clk-activation-ns:
+description: GPMC clock activation time
+default: 0
+
+  gpmc,wait-monitoring-ns:
+description: Start of wait monitoring with regard to valid data
+default: 0
+
+# Boolean timing parameters. If property is present, parameter is enabled
+# otherwise disabled.
+  gpmc,adv-extra-delay:
+description: ADV signal is delayed by half GPMC clock
+type: boolean
+
+  gpmc,cs-extra-delay:
+description: CS signal is delayed by half GPMC clock
+type: boolean
+
+  gpmc,cycle2cycle-diffcsen:
+description: |
+  Add "cycle2cycle-delay" between successive accesses
+  to a different CS
+type: boolean
+
+  gpmc,cycle2cycle-samecsen:
+description: |
+  Add "cycle2cycle-delay" between successive accesses
+  to the same CS
+type: boolean
+
+  gpmc,oe-extra-delay:
+description: OE signal is delayed by half GPMC clock
+type: boolean
+
+  

[u-boot][PATCH v3 2/4] scripts: Makefile.spl: Enable memory drivers to be built for SPL

2022-10-20 Thread Roger Quadros
Introduce CONFIG_SPL_MEMORY to allow Memory drivers to
be built for SPL.

Signed-off-by: Roger Quadros 
---
 common/spl/Kconfig   | 7 +++
 scripts/Makefile.spl | 1 +
 2 files changed, 8 insertions(+)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 70d97815f0..186131a699 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -789,6 +789,13 @@ config SPL_DM_MAILBOX
  this option to build the drivers in drivers/mailbox as part of
  SPL build.
 
+config SPL_MEMORY
+   bool "Support Memory controller drivers"
+   help
+ Enable support for Memory Controller drivers within SPL.
+ These devices provide Memory bus interface to various devices like
+ SRAM, Ethernet adapters, FPGAs, etc.
+
 config SPL_MMC
bool "Support MMC"
depends on MMC
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 3bafeb4fe9..a1892bff7f 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -114,6 +114,7 @@ libs-$(CONFIG_PARTITIONS) += disk/
 endif
 
 libs-y += drivers/
+libs-$(CONFIG_SPL_MEMORY) += drivers/memory/
 libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/dwc3/
 libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/cdns3/
 libs-y += dts/
-- 
2.17.1



[u-boot][PATCH v3 1/4] dm: memory: Introduce new uclass

2022-10-20 Thread Roger Quadros
Introduce UCLASS_MEMORY for future Memory Controller
device drivers.

Signed-off-by: Roger Quadros 
Reviewed-by: Simon Glass 
---
 arch/sandbox/dts/test.dts   |  4 
 drivers/memory/Kconfig  | 17 +
 drivers/memory/Makefile |  2 ++
 drivers/memory/memory-sandbox.c | 18 ++
 drivers/memory/memory-uclass.c  | 13 +
 include/dm/uclass-id.h  |  1 +
 test/dm/Makefile|  1 +
 test/dm/memory.c| 21 +
 8 files changed, 77 insertions(+)
 create mode 100644 drivers/memory/memory-sandbox.c
 create mode 100644 drivers/memory/memory-uclass.c
 create mode 100644 test/dm/memory.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 2761588f0d..d65b2d2dcb 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -926,6 +926,10 @@
};
};
 
+   memory-controller {
+   compatible = "sandbox,memory";
+   };
+
misc-test {
#address-cells = <1>;
#size-cells = <1>;
diff --git a/drivers/memory/Kconfig b/drivers/memory/Kconfig
index 7271892763..c621f5bba3 100644
--- a/drivers/memory/Kconfig
+++ b/drivers/memory/Kconfig
@@ -4,6 +4,23 @@
 
 menu "Memory Controller drivers"
 
+config MEMORY
+   bool "Enable Driver Model for Memory Controller drivers"
+   depends on DM
+   help
+ Enable driver model for Memory Controller devices.
+ These devices provide Memory bus interface to various devices like
+ SRAM, Ethernet adapters, FPGAs, etc.
+ For now this uclass has no methods yet.
+
+config SANDBOX_MEMORY
+   bool "Enable Sandbox Memory Controller driver"
+   depends on SANDBOX && MEMORY
+   help
+ This is a driver model based Memory Controller driver for sandbox.
+ Currently it is a stub only, as there are no usable uclass methods
+ yet.
+
 config STM32_FMC2_EBI
bool "Support for FMC2 External Bus Interface on STM32MP SoCs"
depends on ARCH_STM32MP
diff --git a/drivers/memory/Makefile b/drivers/memory/Makefile
index fec52efb60..b27f701865 100644
--- a/drivers/memory/Makefile
+++ b/drivers/memory/Makefile
@@ -1,3 +1,5 @@
 
+obj-$(CONFIG_MEMORY) += memory-uclass.o
+obj-$(CONFIG_SANDBOX_MEMORY) += memory-sandbox.o
 obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o
 obj-$(CONFIG_TI_AEMIF) += ti-aemif.o
diff --git a/drivers/memory/memory-sandbox.c b/drivers/memory/memory-sandbox.c
new file mode 100644
index 00..f2ede50863
--- /dev/null
+++ b/drivers/memory/memory-sandbox.c
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2022
+ * Texas Instruments Incorporated, 
+ */
+
+#include 
+
+static const struct udevice_id sandbox_memory_match[] = {
+   { .compatible = "sandbox,memory" },
+   { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(sandbox_memory) = {
+   .name   = "sandbox_memory",
+   .id = UCLASS_MEMORY,
+   .of_match = sandbox_memory_match,
+};
diff --git a/drivers/memory/memory-uclass.c b/drivers/memory/memory-uclass.c
new file mode 100644
index 00..d6d37fe777
--- /dev/null
+++ b/drivers/memory/memory-uclass.c
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2022
+ * Texas Instruments Incorporated, 
+ */
+
+#include 
+
+UCLASS_DRIVER(memory) = {
+   .name = "memory",
+   .id = UCLASS_MEMORY,
+   .post_bind = dm_scan_fdt_dev,
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index a432e43871..936a16c5d9 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -76,6 +76,7 @@ enum uclass_id {
UCLASS_MASS_STORAGE,/* Mass storage device */
UCLASS_MDIO,/* MDIO bus */
UCLASS_MDIO_MUX,/* MDIO MUX/switch */
+   UCLASS_MEMORY,  /* Memory Controller device */
UCLASS_MISC,/* Miscellaneous device */
UCLASS_MMC, /* SD / MMC card or chip */
UCLASS_MOD_EXP, /* RSA Mod Exp device */
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 7543df8823..1082e65c41 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -47,6 +47,7 @@ ifneq ($(CONFIG_EFI_PARTITION),)
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
 endif
 obj-$(CONFIG_FIRMWARE) += firmware.o
+obj-$(CONFIG_MEMORY) += memory.o
 obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o
 obj-$(CONFIG_DM_I2C) += i2c.o
 obj-$(CONFIG_SOUND) += i2s.o
diff --git a/test/dm/memory.c b/test/dm/memory.c
new file mode 100644
index 00..7d9500aa91
--- /dev/null
+++ b/test/dm/memory.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2022
+ * Texas Instruments Incorporated, 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+static int dm_test_memory(struct unit_test_state *uts)
+{
+   struct udevice *dev;
+
+   ut_assertok(uclass_first_device_err(UCLASS_MEMORY, ));
+
+   return 0;
+}
+

[u-boot][PATCH v3 0/4] Introduce MEMORY uclass and TI GPMC driver

2022-10-20 Thread Roger Quadros
Hi,

This series introduces the MEMORY controller uclass for the drivers
that exist in drivers/memory directory.

With that, we add the TI GPMC Memory controller driver as the first
user of this uclass.

The GPMC is a unified memory controller dedicated for interfacing
with external memory devices like
 - Asynchronous SRAM-like memories and ASICs
 - Asynchronous, synchronous, and page mode burst NOR flash
 - NAND flash
 - Pseudo-SRAM devices

The driver is pulled straight from the Linux kernel and adapted
for u-boot.

This driver will take care of setting up the GPMC based on
the settings specified in the Device tree and then
probe its children.

cheers,
-roger

Changelog:
v3:
- Use CONFIG_MEMORY instead of CONFIG_DM_MEMORY
- Introduce CONFIG_SPL_MEMORY and use it to gate inclusion of
of drivers/memory for SPL build
- Make TI_GPMC depend on OF_CONTROL and CLK as well

v2:
- Introduce MEMORY uclass

Roger Quadros (4):
  dm: memory: Introduce new uclass
  scripts: Makefile.spl: Enable memory drivers to be built for SPL
  dt/bindings: memory: Add bindings for TI GPMC driver
  memory: Add TI GPMC driver

 arch/sandbox/dts/test.dts |4 +
 common/spl/Kconfig|7 +
 .../memory/ti,gpmc-child.yaml |  252 
 doc/device-tree-bindings/memory/ti,gpmc.yaml  |  190 +++
 drivers/memory/Kconfig|   36 +
 drivers/memory/Makefile   |3 +
 drivers/memory/memory-sandbox.c   |   18 +
 drivers/memory/memory-uclass.c|   13 +
 drivers/memory/ti-gpmc.c  | 1240 +
 drivers/memory/ti-gpmc.h  |  298 
 include/dm/uclass-id.h|1 +
 include/linux/mtd/omap_gpmc.h |3 +
 scripts/Makefile.spl  |1 +
 test/dm/Makefile  |1 +
 test/dm/memory.c  |   21 +
 15 files changed, 2088 insertions(+)
 create mode 100644 doc/device-tree-bindings/memory/ti,gpmc-child.yaml
 create mode 100644 doc/device-tree-bindings/memory/ti,gpmc.yaml
 create mode 100644 drivers/memory/memory-sandbox.c
 create mode 100644 drivers/memory/memory-uclass.c
 create mode 100644 drivers/memory/ti-gpmc.c
 create mode 100644 drivers/memory/ti-gpmc.h
 create mode 100644 test/dm/memory.c

-- 
2.17.1



[PULL] u-boot-riscv/master

2022-10-20 Thread Leo Liang
Hi Tom,

The following changes since commit 3724ddf157aab3bd009c1da234b9a1af1621b544:

  Merge branch '2022-10-18-TI-platform-updates' (2022-10-18 18:13:39 -0400)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-riscv.git

for you to fetch changes up to b3b44c674a473bdd3d53cf5196fae897107af619:

  riscv: ae350: Check firmware_fdt_addr header (2022-10-20 15:26:31 +0800)

CI result shows no issue: 
https://source.denx.de/u-boot/custodians/u-boot-riscv/-/pipelines/13866


Bin Meng (1):
  riscv: qemu: spl: Fix booting Linux kernel with OpenSBI 1.0+

Heinrich Schuchardt (5):
  cmd/sbi: format RustSBI version number
  cmd/sbi: error message for failure to get spec version
  cmd/sbi: user friendly short texts
  riscv: support building double-float modules
  k210: fix k210_pll_calc_config()

Rick Chen (1):
  riscv: ae350: Check firmware_fdt_addr header

Yu Chien Peter Lin (1):
  riscv: andes_plic.c: use modified IPI scheme

 arch/riscv/Kconfig  | 15 +++
 arch/riscv/Makefile | 15 ---
 arch/riscv/lib/andes_plic.c |  7 ---
 board/AndesTech/ax25-ae350/ax25-ae350.c |  2 +-
 board/emulation/qemu-riscv/Kconfig  |  2 +-
 cmd/riscv/sbi.c | 26 +++---
 drivers/clk/clk_k210.c  |  2 +-
 test/dm/k210_pll.c  |  2 +-
 8 files changed, 50 insertions(+), 21 deletions(-)

Best regards,
Leo


Re: [u-boot][PATCH v2 2/4] scripts: Makefile.spl: Enable memory drivers to be built for SPL

2022-10-20 Thread Tom Rini
On Thu, Oct 20, 2022 at 03:23:42PM +0300, Roger Quadros wrote:
> Hi Tom,
> 
> On 19/10/2022 15:54, Tom Rini wrote:
> > On Wed, Oct 19, 2022 at 11:17:35AM +0300, Roger Quadros wrote:
> >>
> >>
> >> On 18/10/2022 20:40, Tom Rini wrote:
> >>> On Thu, Oct 06, 2022 at 04:23:58PM +0300, Roger Quadros wrote:
>  We will need ti-gpmc driver for SPL. Allow memory drivers
>  do be built for SPL.
> 
>  Signed-off-by: Roger Quadros 
>  ---
>   scripts/Makefile.spl | 1 +
>   1 file changed, 1 insertion(+)
> 
>  diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
>  index 3bafeb4fe9..110076b22f 100644
>  --- a/scripts/Makefile.spl
>  +++ b/scripts/Makefile.spl
>  @@ -114,6 +114,7 @@ libs-$(CONFIG_PARTITIONS) += disk/
>   endif
>   
>   libs-y += drivers/
>  +libs-y += drivers/memory/
>   libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/dwc3/
>   libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/cdns3/
>   libs-y += dts/
> >>>
> >>> This ends up being the wrong approach as it then pulls in
> >>> drivers/memory/stm32-fmc2-ebi.o on all of those platforms, in SPL, which
> >>> is not what's intended. We need an SPL_MEMORY symbol and then gate the
> >>> directory on that.
> >>>
> 
> I have a question about how CONFIG_SPL_MEMORY works together with 
> CONFIG_MEMORY.
> 
> Do we use CONFIG_SPL_MEMORY only to gate the drivers/memory directory 
> inclusion?
> Then continue to use CONFIG_MEMORY and others to enable/disable driver
> build for both non-SPL and SPL case?
> 
> So drivers/memory/Makefile remains as it is?

Well, for consistency code should use IS_ENABLED(MEMORY) which will be
true for CONFIG_MEMORY or CONFIG_SPL_MEMORY.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v14 09/15] FWU: Add boot time checks as highlighted by the FWU specification

2022-10-20 Thread Ilias Apalodimas
Hi Sughosh, 

> > > + }
> > > +
> > > + return 0;
> > > +}
> > > +
> > > +static int fwu_trial_state_check(void)
> > > +{
> > > + int ret;
> > > + struct udevice *dev;
> > > + efi_status_t status;
> > > + efi_uintn_t var_size;
> > > + u16 trial_state_ctr;
> > > + struct fwu_mdata mdata = { 0 };
> > > +
> > > + ret = fwu_get_dev_mdata(, );
> > > + if (ret)
> > > + return ret;
> > > +
> > > + trial_state = in_trial_state();
> > > + if (trial_state) {
> > > + var_size = (efi_uintn_t)sizeof(trial_state_ctr);
> > > + log_info("System booting in Trial State\n");
> > > + status = efi_get_variable_int(u"TrialStateCtr",
> > > +   _global_variable_guid,
> > > +   NULL,
> > > +   _size, _state_ctr,
> > > +   NULL);
> > > + if (status != EFI_SUCCESS) {
> > > + log_err("Unable to read TrialStateCtr variable\n");
> > > + ret = -1;
> > > + goto out;
> > > + }
> > > +
> > > + ++trial_state_ctr;
> > > + if (trial_state_ctr > CONFIG_FWU_TRIAL_STATE_CNT) {
> > > + log_info("Trial State count exceeded. Revert back 
> > > to previous_active_index\n");
> > > + ret = fwu_revert_boot_index();
> > > + if (ret) {
> > > + log_err("Unable to revert active_index\n");
> > > + goto out;
> > > + }
> > > +
> > > + /* Delete the TrialStateCtr variable */
> > > + ret = trial_counter_update(NULL);
> > > + if (ret) {
> > > + log_err("Unable to delete TrialStateCtr 
> > > variable\n");
> > > + goto out;
> > > + }
> >
> > This is a bit confusing for me.  If the trial_state_ctr we need to goto out
> > anyway right?  So why don't we explicitly add a goto out at the end and get
> > rid of the else that's following ?
> 
> Actually, we don't need the goto statement above, as well as the one
> used below, in the else part. I can get rid of it. Personally I feel
> that this provides more clarity as to how the code flow is, but I can
> get rid of it if you so prefer. Thanks.
> 
> -sughosh

My previous reply wasn't that clear let me try again. 
Indeed the goto's aren't needed and that's the first confusing thing. On
top of that the fwu_trial_state_check() is a bit misleading as well, since
it does a lot more than checking. So that functions does
- check the trial state counter
- remove it if not on trial state
- bump the counter
- if the counter exceeds a threshold try to delete it
Also due to the fact that this runs from the event loop, the return codes
are a bit confusing

However this is only called from a fwu_boottime_checks() so we can break it
up in smaller pieces that would be easier to read. 
In fwu_trial_state_check() you only need the metadata to check whether you
are in trial state or not. 

So I would suggest 
1. Create a trial_counter_read() which only reads the EFI variable
2. move the metadata code in fwu_boottime_checks()a instead of
   fwu_trial_state_check()
3. rename fwu_trial_state_check() -> fwu_try_update_cnt()


static u8 trial_state; -> s/trial_state/in_trial/

static int fwu_boottime_checks(void *ctx, struct event *event)
{
.

ret = fwu_get_dev_mdata(, );
if (ret)
return ret;(NULL);

in_trial = in_trial_state() + 1;
cnt = trial_counter_read();

if (in_trial && cnt < CONFIG_FWU_TRIAL_STATE_CNT)
ret = fwu_try_update_cnt()
if (fail)
trial_counter_update
else
trial_counter_update(NULL);

There will be an extra GetVariable call since we unconditionally read the
counter now, but we can add if (in_trial), although it doesn't matter that
much.


Can you give it a shot and see if that works for you?

Thanks
/Ilias

> 
> >
> > > + } else {
> > > + ret = trial_counter_update(_state_ctr);
> > > + if (ret) {
> > > + log_err("Unable to increment TrialStateCtr 
> > > variable\n");
> > > + goto out;
> > > + }
> > > + }
> > > + } else {
> > > + /* Delete the variable */
> > > + ret = trial_counter_update(NULL);
> > > + if (ret) {
> > > + log_err("Unable to delete TrialStateCtr 
> > > variable\n");
> > > + }
> > > + }
> > > +
> > > +out:
> > > + return ret;
> > > +}
> > > +
> > >  static int 

Re: [u-boot][PATCH v2 2/4] scripts: Makefile.spl: Enable memory drivers to be built for SPL

2022-10-20 Thread Roger Quadros
Hi Tom,

On 19/10/2022 15:54, Tom Rini wrote:
> On Wed, Oct 19, 2022 at 11:17:35AM +0300, Roger Quadros wrote:
>>
>>
>> On 18/10/2022 20:40, Tom Rini wrote:
>>> On Thu, Oct 06, 2022 at 04:23:58PM +0300, Roger Quadros wrote:
 We will need ti-gpmc driver for SPL. Allow memory drivers
 do be built for SPL.

 Signed-off-by: Roger Quadros 
 ---
  scripts/Makefile.spl | 1 +
  1 file changed, 1 insertion(+)

 diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
 index 3bafeb4fe9..110076b22f 100644
 --- a/scripts/Makefile.spl
 +++ b/scripts/Makefile.spl
 @@ -114,6 +114,7 @@ libs-$(CONFIG_PARTITIONS) += disk/
  endif
  
  libs-y += drivers/
 +libs-y += drivers/memory/
  libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/dwc3/
  libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/cdns3/
  libs-y += dts/
>>>
>>> This ends up being the wrong approach as it then pulls in
>>> drivers/memory/stm32-fmc2-ebi.o on all of those platforms, in SPL, which
>>> is not what's intended. We need an SPL_MEMORY symbol and then gate the
>>> directory on that.
>>>

I have a question about how CONFIG_SPL_MEMORY works together with CONFIG_MEMORY.

Do we use CONFIG_SPL_MEMORY only to gate the drivers/memory directory inclusion?
Then continue to use CONFIG_MEMORY and others to enable/disable driver
build for both non-SPL and SPL case?

So drivers/memory/Makefile remains as it is?

>>
>> That's right. I'll fix it up. Will wait for your comments on the rest
>> of the series before re-spin.
> 
> Everything else is fine, I was about to merge it (with a
> %s/DM_MEMORY/MEMORY) when I saw the stm32 platforms increasing in size
> and dug in.
> 

cheers,
-roger


Re: [PATCH v17 1/2] net: Add TCP protocol

2022-10-20 Thread Duncan Hare
I used a server on Linux for testing.
Sent from Yahoo Mail on Android 
 
  On Tue, Oct 18, 2022 at 9:59, Simon Glass wrote:   Hi 
PaulLiu,

On Mon, 17 Oct 2022 at 01:03, PaulLiu  wrote:
>
> Hi Simon,
>
> I think it is a bit hard for me to test it right now. It seems that we need 
> to setup a fake HTTP server?
> It can be easily done by some python scripts but I'm not sure how to start.
> Is there some example on testing the network commands? Like tftp or nfs?

See test/dm/eth.c for some examples.

It is better if you can have the test contained, rather than requiring
starting up a separate server. E.g. you can write a small test in C
which sends an http request, handles the reply and then checks that
the data is received. At present sandbox supports storing one packet,
but that could be extended if not enough.

Regards,
Simon


>
> Yours,
> Paul
>
>
> On Tue, Jul 12, 2022 at 7:00 PM Simon Glass  wrote:
>>
>> Hi Ying-Chun,
>>
>> On Fri, 8 Jul 2022 at 12:02, Ying-Chun Liu (PaulLiu)
>>  wrote:
>> >
>> > From: "Ying-Chun Liu (PaulLiu)" 
>> >
>> > Currently file transfers are done using tftp or NFS both
>> > over udp. This requires a request to be sent from client
>> > (u-boot) to the boot server.
>> >
>> > The current standard is TCP with selective acknowledgment.
>> >
>> > Signed-off-by: Duncan Hare 
>> > Signed-off-by: Duncan Hare 
>> > Signed-off-by: Ying-Chun Liu (PaulLiu) 
>> > Cc: Christian Gmeiner 
>> > Cc: Joe Hershberger 
>> > Cc: Michal Simek 
>> > Cc: Ramon Fried 
>> > ---
>> > v1-v12: Made by Duncan, didn't tracked.
>> > v13: Fix some issues which is reviewed by Christian
>> > v14: Add options to enable/disable SACK.
>> > v15: Fix various syntax errors reviewed by Michal.
>> >      Remove magic numbers. Use kernel-doc format.
>> > v16: Add more kernel-doc. Fix more double spaces.
>> > ---
>> >  include/net.h    |  36 ++-
>> >  include/net/tcp.h | 312 
>> >  net/Kconfig      |  16 ++
>> >  net/Makefile      |  1 +
>> >  net/net.c        |  30 ++
>> >  net/tcp.c        | 720 ++
>> >  6 files changed, 1106 insertions(+), 9 deletions(-)
>> >  create mode 100644 include/net/tcp.h
>> >  create mode 100644 net/tcp.c
>>
>> This looks good to me.
>>
>> Reviewed-by: Simon Glass 
>>
>> Can we get a test for this? Perhaps a fake Ethernet driver in sandbox
>> / drivers/net?
  


Re: [PATCH] spi: spi-mem: ease checks in dtr_supports_op()

2022-10-20 Thread Dhruva Gole

Forgot to add in CC,
+ Jagan Teki  (maintainer:SPI)

On 20/10/22 14:04, Dhruva Gole wrote:

Remove the extra conditions that cause some cases to fail prematurely
like if the data number of bytes is odd. The controller can handle odd
number of bytes data read in DTR Mode. Don't fail supports op for this
condition.

Signed-off-by: Dhruva Gole 
---

For a deeper context, refer to a cover letter from an earlier patch
series:
https://lore.kernel.org/u-boot/20221019064759.493607-1-d-g...@ti.com/T/#m3fd93bdcc30b3b5faada6abe45a4104388afc300
Here, I am trying to boot from OSPI Flash present on board the AM62-SK
EVM. However, despite enabling the necessary configs and DT nodes, my
boot flow seemed to be failing. I then came to know that the condition
causing this failure was that my generated DTB was of odd number of
bytes.
So, while loading the dtb from the Octal SPI NOR Flash to the memory,
the data.nbytes was odd which made the supports_op
function return false. This check feels a little too strict at the
spi-mem stage and we should let the controller decide what to do in case
of odd bytes in DTR. After applying this patch, I was able to
succesfully boot the AM62SK EVM without any issues.

I would also like to justify this patch by pointing the community to the
equivalent code in the linux kernel, in drivers/spi/spi-mem.c, where this check
is absent as well.

The controller does work with odd number of bytes and I have not seen
any sort of bugs in the absence of this supports_op check. Hence, feel
that it is safe enough to discard this check from here.

  drivers/spi/spi-mem.c | 4 
  1 file changed, 4 deletions(-)

diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 8e8995fc537f..eecc13bec90d 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -181,10 +181,6 @@ bool spi_mem_dtr_supports_op(struct spi_slave *slave,
if (op->dummy.nbytes && op->dummy.buswidth == 8 && op->dummy.nbytes % 2)
return false;
  
-	if (op->data.dir != SPI_MEM_NO_DATA &&

-   op->dummy.buswidth == 8 && op->data.nbytes % 2)
-   return false;
-
return spi_mem_check_buswidth(slave, op);
  }
  EXPORT_SYMBOL_GPL(spi_mem_dtr_supports_op);


--
Thanks and Regards,
Dhruva Gole


[PATCH] spi: spi-mem: ease checks in dtr_supports_op()

2022-10-20 Thread Dhruva Gole
Remove the extra conditions that cause some cases to fail prematurely
like if the data number of bytes is odd. The controller can handle odd
number of bytes data read in DTR Mode. Don't fail supports op for this
condition.

Signed-off-by: Dhruva Gole 
---

For a deeper context, refer to a cover letter from an earlier patch
series:
https://lore.kernel.org/u-boot/20221019064759.493607-1-d-g...@ti.com/T/#m3fd93bdcc30b3b5faada6abe45a4104388afc300
Here, I am trying to boot from OSPI Flash present on board the AM62-SK
EVM. However, despite enabling the necessary configs and DT nodes, my
boot flow seemed to be failing. I then came to know that the condition
causing this failure was that my generated DTB was of odd number of
bytes.
So, while loading the dtb from the Octal SPI NOR Flash to the memory,
the data.nbytes was odd which made the supports_op
function return false. This check feels a little too strict at the
spi-mem stage and we should let the controller decide what to do in case
of odd bytes in DTR. After applying this patch, I was able to
succesfully boot the AM62SK EVM without any issues.

I would also like to justify this patch by pointing the community to the
equivalent code in the linux kernel, in drivers/spi/spi-mem.c, where this check
is absent as well.

The controller does work with odd number of bytes and I have not seen
any sort of bugs in the absence of this supports_op check. Hence, feel
that it is safe enough to discard this check from here.

 drivers/spi/spi-mem.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 8e8995fc537f..eecc13bec90d 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -181,10 +181,6 @@ bool spi_mem_dtr_supports_op(struct spi_slave *slave,
if (op->dummy.nbytes && op->dummy.buswidth == 8 && op->dummy.nbytes % 2)
return false;
 
-   if (op->data.dir != SPI_MEM_NO_DATA &&
-   op->dummy.buswidth == 8 && op->data.nbytes % 2)
-   return false;
-
return spi_mem_check_buswidth(slave, op);
 }
 EXPORT_SYMBOL_GPL(spi_mem_dtr_supports_op);
-- 
2.25.1



Re: [PATCH v14 02/15] FWU: Add FWU metadata structure and driver for accessing metadata

2022-10-20 Thread Ilias Apalodimas
Hi Sughosh, Etienne

[...]

> > > +  * Check if the platform has defined its own
> > > +  * function to check the metadata partitions'
> > > +  * validity. If so, that takes precedence.
> > > +  */
> > > + ret = fwu_mdata_check(dev);
> >
> > Isn't this a bit dangerous?  Let's say a device defines it's own check
> > function but for some reason returns -ENOSYS.  I am wondering if we should
> > just return 0 if the platform defined functions aren't defined.
>
> A driver should return ENOSYS only if a driver method has not been
> defined. That is what I see being used in other drivers as well. So I
> think that the current implementation of returning ENOSYS for a non
> defined method is correct. If a driver is returning ENOSYS for any
> other purpose I feel that should be fixed instead.
>

Fair enough

> >
> > > + if (!ret || ret != -ENOSYS)
> > > + return ret;
> > > +
> > > + /*
> > > +  * Two FWU metadata partitions are expected.
> > > +  * If we don't have two, user needs to create
> > > +  * them first
> > > +  */
> > > + valid_partitions = 0;
> > > + ret = fwu_get_mdata_part_num(dev, mdata_parts);
> > > + if (ret < 0) {
> > > + log_debug("Error getting the FWU metadata partitions\n");
> > > + return -ENOENT;
> > > + }
> > > +
> > > + ret = fwu_read_mdata_partition(dev, _mdata, mdata_parts[0]);
> > > + if (!ret) {
> > > + ret = fwu_verify_mdata(_mdata, 1);
> > > + if (!ret)
> > > + valid_partitions |= PRIMARY_PART;
> > > + }
> > > +
> > > + ret = fwu_read_mdata_partition(dev, _mdata, 
> > > mdata_parts[1]);
> > > + if (!ret) {
> > > + ret = fwu_verify_mdata(_mdata, 0);
> > > + if (!ret)
> > > + valid_partitions |= SECONDARY_PART;
> > > + }
> > > +
> > > + if (valid_partitions == (PRIMARY_PART | SECONDARY_PART)) {
> > > + /*
> > > +  * Before returning, check that both the
> > > +  * FWU metadata copies are the same. If not,
> > > +  * the FWU metadata copies need to be
> > > +  * re-populated.
> > > +  */
> > > + if (!memcmp(_mdata, _mdata,
> > > + sizeof(struct fwu_mdata))) {
> > > + ret = 0;
> > > + } else {
> > > + log_info("Both FWU metadata copies are valid but do 
> > > not match. Please check!\n");
> >
> > Check what ? Just remove that part please
>
> Okay. I will restore the secondary partition from the primary
> partition as Etienne has suggested.

Yep, I agree on that.  I vaguely remember discussing the same thing a
few versions ago, but that somehow slipped away.  Good catch!

>
> >
> > > + ret = -1;
> > > + }
> > > + goto out;
> > > + }
> > > +
> > > + if (!(valid_partitions & BOTH_PARTS)) {
> > > + ret = -1;
> >
> > In general we should try to avoid returning -1 etc.  Is there an errno that
> > would make sense?
>
> Even I am not sure what is relevant here(EINVAL?). I think I can add a
> log_info mentioning the error case?

EBADMSG could also be an option here I guess, but there's not POSIX
errnor I am aware of that means "data corrupted"

>
> >
> > > + goto out;
> > > + }
> > > +
> > > + invalid_partitions = valid_partitions ^ BOTH_PARTS;
> > > + ret = fwu_write_mdata_partition(dev,
> > > + (invalid_partitions == 
> > > PRIMARY_PART) ?
> > > + _mdata : _mdata,
> > > + (invalid_partitions == 
> > > PRIMARY_PART) ?
> > > + mdata_parts[0] : mdata_parts[1]);
> > > +
> > > + if (ret < 0)
> > > + log_info("Restoring %s FWU metadata partition failed\n",
> > > +   (invalid_partitions == PRIMARY_PART) ?
> > > +   "primary" : "secondary");
> > > +
> > > +out:
> > > + return ret;
> > > +}
> > > +
> > > +/**
> > > + * fwu_get_active_index() - Get active_index from the FWU metadata
> > > + * @active_idx: active_index value to be read
> > > + *
> > > + * Read the active_index field from the FWU metadata and place it in
> > > + * the variable pointed to be the function argument.
> > > + *
> > > + * Return: 0 if OK, -ve on error
> > > + *
> > > + */
> > > +int fwu_get_active_index(uint *active_idx)
> > > +{
> > > + int ret;
> > > + struct udevice *dev;
> > > + struct fwu_mdata mdata = { 0 };
> > > +
> > > + ret = fwu_get_dev_mdata(, );
> > > + if (ret)
> > > + return ret;
> > > +
> > > + /*
> > > +  * Found the FWU metadata partition, now read the active_index
> > > +  * value
> > > +  */
> > > + *active_idx = mdata.active_index;
> > > + if (*active_idx >= CONFIG_FWU_NUM_BANKS) {
> > > + 

  1   2   >