Re: [PATCH 1/1] common: return type board_get_usable_ram_top

2023-08-13 Thread Heinrich Schuchardt




On 8/13/23 15:36, Simon Glass wrote:

Hi Heinrich,

On Sat, 12 Aug 2023 at 23:01, Heinrich Schuchardt
 wrote:


board_get_usable_ram_top() returns a physical address that is stored in
gd->ram_top. The return type of the function should be phys_addr_t like the
current type of gd->ram_top.

Signed-off-by: Heinrich Schuchardt 
---
  arch/arm/mach-imx/imx8m/soc.c   | 2 +-
  arch/arm/mach-mvebu/arm64-common.c  | 2 +-
  arch/arm/mach-rockchip/sdram.c  | 2 +-
  arch/arm/mach-stm32mp/dram_init.c   | 2 +-
  arch/arm/mach-sunxi/board.c | 2 +-
  arch/arm/mach-tegra/board2.c| 2 +-
  arch/mips/mach-jz47xx/jz4780/jz4780.c   | 2 +-
  arch/mips/mach-octeon/dram.c| 2 +-
  arch/riscv/cpu/fu540/dram.c | 2 +-
  arch/riscv/cpu/fu740/dram.c | 2 +-
  arch/riscv/cpu/generic/dram.c   | 2 +-
  arch/riscv/cpu/jh7110/dram.c| 2 +-
  arch/x86/cpu/broadwell/sdram.c  | 2 +-
  arch/x86/cpu/coreboot/sdram.c   | 2 +-
  arch/x86/cpu/efi/payload.c  | 2 +-
  arch/x86/cpu/efi/sdram.c| 2 +-
  arch/x86/cpu/ivybridge/sdram.c  | 2 +-
  arch/x86/cpu/qemu/dram.c| 2 +-
  arch/x86/cpu/quark/dram.c   | 2 +-
  arch/x86/cpu/slimbootloader/sdram.c | 2 +-
  arch/x86/cpu/tangier/sdram.c| 2 +-
  arch/x86/include/asm/u-boot-x86.h   | 2 +-
  arch/x86/lib/fsp1/fsp_dram.c| 2 +-
  arch/x86/lib/fsp2/fsp_dram.c| 2 +-
  board/broadcom/bcmns3/ns3.c | 2 +-
  board/imgtec/boston/ddr.c   | 2 +-
  board/menlo/m53menlo/m53menlo.c | 2 +-
  board/raspberrypi/rpi/rpi.c | 2 +-
  board/ti/am65x/evm.c| 2 +-
  board/ti/j721e/evm.c| 2 +-
  board/ti/j721s2/evm.c   | 2 +-
  board/toradex/verdin-am62/verdin-am62.c | 2 +-
  board/xilinx/common/board.c | 2 +-
  common/board_f.c| 2 +-
  include/init.h  | 2 +-
  35 files changed, 35 insertions(+), 35 deletions(-)


While you are here, could you please fix the function comment?

[..]


diff --git a/include/init.h b/include/init.h
index 8873081685..b1e1451166 100644
--- a/include/init.h
+++ b/include/init.h
@@ -304,7 +304,7 @@ int show_board_info(void);
   *
   * @param total_size   Size of U-Boot (unused?)


It seems confused about the param, and we should have a return value.


The parameter with the monitor length (size of U-Boot code) is not used 
anywhere (though it is passed on to functions like 
mrc_common_board_get_usable_ram_top() where it isn't used either).


We should try to eliminate the parameter in further patches.



Also should explain what this function is used for.


That explanation exists.

I will put the documentation fix into a separate patch so we can apply 
it to 2023.10. I don't know if Tom wants to apply this patch to next or 
to 2023.10.


Best regards

Heinrich




   */
-phys_size_t board_get_usable_ram_top(phys_size_t total_size);
+phys_addr_t board_get_usable_ram_top(phys_size_t total_size);

  int board_early_init_f(void);

--
2.40.1



Regards,
Simon


[PATCH 1/1] doc: description of board_get_usable_ram_top()

2023-08-13 Thread Heinrich Schuchardt
Improve the description of function board_get_usable_ram_top().

Signed-off-by: Heinrich Schuchardt 
---
 include/init.h | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/include/init.h b/include/init.h
index 8873081685..dc3c1f220c 100644
--- a/include/init.h
+++ b/include/init.h
@@ -296,13 +296,18 @@ int checkboard(void);
 int show_board_info(void);
 
 /**
- * Get the uppermost pointer that is valid to access
+ * board_get_usable_ram_top() - get uppermost address for U-Boot relocation
  *
- * Some systems may not map all of their address space. This function allows
- * boards to indicate what their highest support pointer value is for DRAM
- * access.
+ * Some systems have reserved memory areas in high memory. By implementing this
+ * function boards can indicate the highest address value to be used when
+ * relocating U-Boot. The returned address is exclusive (i.e. 1 byte above the
+ * last usable address).
  *
- * @param total_size   Size of U-Boot (unused?)
+ * Due to overflow on systems with 32bit phys_addr_t a value 0 is used instead
+ * of 4GiB.
+ *
+ * @total_size:monitor length in bytes (size of U-Boot code)
+ * Return: uppermost address for U-Boot relocation
  */
 phys_size_t board_get_usable_ram_top(phys_size_t total_size);
 
-- 
2.40.1



Re: [RFC PATCH 0/4] mtd: ubi: Enable accessing RO filesystems in UBI vols

2023-08-13 Thread Heiko Schocher
Hello Sam,

many thnkas for your patchset!

On 12.08.23 02:06, Sam Edwards wrote:
> Hi UBI maintainers,
> 
> My target's rootfs is a read-only filesystem stored in a static UBI volume,
> mounted via a "ubiblock" device after boot. I'd also like to keep the boot
> files in the same filesystem, so that it's all coupled together. To that end,
> I'm working on a patchset so that U-Boot can read static UBI volumes as
> read-only block devices (paralleling Linux's ubiblock mechanism).
> 
> I'm very happy with how the first 3 patches in this series turned out (so I'm
> not asking about them per se, though feedback is certainly welcome). The 
> fourth
> is where I got stuck: while the code definitely works, it requires bringing DM
> headers into disk/part.c, which certainly will not fly in mainline. I need to
> plumb this through drivers/block/blk-uclass.c to do it "properly."
> 
> Part of the problem here is that these are *volumes,* but they are 
> (optionally)
> *named.* In U-Boot's current view of block devices, it is only a partition, 
> and
> not a volume, that may have a name. These aren't "partitions" in U-Boot's 
> view,
> since a partition is a contiguous slice of a bigger block device, while these
> are (logically) separate block devices.
> 
> So, I would need to invent a new function that can look up a named 
> (sub)volume.
> I also probably need to invent new syntax, so that I'm not overloading the 0:1
> syntax for partitions. I'm not especially beholden to the ':', but I do want 
> to
> use the same syntax for volume numbers and volume names, to mirror Linux's
> `ubi.block=x,y` syntax.
> 
> I'm also trying to reclaim the name "ubi" to refer to a UBI volume, while
> U-Boot currently thinks it should refer to the presently-mounted UBIFS. In my
> current series, the meaning of "ubi" depends on whether ubifs is mounted, for
> backwards-compatibility. If this isn't palpable, I could consider other 
> options
> like "ubivol"/"ubiblock"/"ubiblk"/"ubistatic"/...
> 
> So, the feedback I'm hoping for would be:
> 1) What is a good syntax for referring to a logical volume by name or ID?
>Keeping in mind this may affect more than just UBI, if e.g. U-Boot learns 
> to
>peer inside LVM2s in the future.

Yes, we should have here some generic part...

> 2) What should I call the block functions for looking up a block device's
>subvolume by type+parentidx+{name,ID}?
> 3) Is my strategy of reclaiming "ubi" sound, or should I be conceding that to
>UBIFS and using a new type name for static UBI volumes?
> 4) Does my choose_blksz_for_volume() function make sense, or should I always 
> be
>using a preferred block size (like 512) if possible?

Your patches look good to me, and yes, we have to discuss changes in disk/part.c

I added Simon here as he has much more knowledge here, hope he can comment
this part.

bye,
Heiko
> 
> Cheers,
> Sam
> 
> Sam Edwards (4):
>   mtd: ubi: register UBI attachments as DM devices
>   mtd: ubi: bind block device driver for static volumes
>   disk: part: fall-through if "ubi" requested but ubifs not mounted
>   HACK: enable access to `ubi 0:volname` block devices
> 
>  cmd/ubi.c|  11 +++
>  disk/part.c  |  70 +++--
>  drivers/mtd/ubi/Makefile |   1 +
>  drivers/mtd/ubi/ubi-uclass.c | 184 +++
>  include/dm/uclass-id.h   |   1 +
>  include/ubi_uboot.h  |   5 +
>  6 files changed, 264 insertions(+), 8 deletions(-)
>  create mode 100644 drivers/mtd/ubi/ubi-uclass.c
> 

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


Re: [PATCH 0/2] patches used to enable u-boot video driver on raspberry pi 4B platform

2023-08-13 Thread Anatolij Gustschin
On Wed, 26 Jul 2023 10:42:33 +0800
Meng Li meng...@windriver.com wrote:

> From: Meng Li 
> 
> There are 2 patches as bleow:
> 0001-bcm2835-Add-simiple-framebuffer-for-use-with-fkms.patch
> 0002-rpi-set-the-correct-parameter-for-simple-framebuffer.patch
> The first one is used to enable u-boot video driver.
> The second one is used to fix the wired display status on monitor.
> 
> Jason Wessel (1):
>   bcm2835: Add simiple-framebuffer for use with fkms
> 
> Meng Li (1):
>   rpi: set the correct parameter for simple framebuffer node
> 
>  board/raspberrypi/rpi/rpi.c | 2 ++
>  drivers/video/bcm2835.c | 3 +++
>  2 files changed, 5 insertions(+)

applied to u-boot-video/master, thanks!

--
Anatolij


Re: [PATCH] video: kconfig: Fix a typo in SPL_VIDEO_REMOVE

2023-08-13 Thread Anatolij Gustschin
On Thu,  3 Aug 2023 18:40:08 +0800
Bin Meng bmeng...@gmail.com wrote:

> From: Bin Meng 
> 
> Add one space between 'before' and 'loading'.
> 
> Signed-off-by: Bin Meng 
> ---
> 
>  drivers/video/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

applied to u-boot-video/master, thanks!

--
Anatolij


Re: [PATCH] video: vidconsole: Fix null dereference of ops->measure

2023-08-13 Thread Anatolij Gustschin
On Thu,  3 Aug 2023 17:32:41 +0800
Bin Meng bm...@tinylab.org wrote:

> At present vidconsole_measure() tests ops->select_font before calling
> ops->measure, which would result in a null dereference when the console
> driver provides no ops for measure.
> 
> Fixes: b828ed7d7929 ("console: Allow measuring the bounding box of text")
> Signed-off-by: Bin Meng 
> ---
> 
>  drivers/video/vidconsole-uclass.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

applied to u-boot-video/master, thanks!

--
Anatolij


Please pull u-boot-video

2023-08-13 Thread Anatolij Gustschin
Hi Tom,

please pull video driver fixes for for v2023.10.

CI: https://source.denx.de/u-boot/custodians/u-boot-video/-/pipelines/17338

Thanks,
Anatolij

The following changes since commit a5899cc69a99379f01e8e2f9f98e0e09b24f1656:

  Merge https://source.denx.de/u-boot/custodians/u-boot-watchdog (2023-08-10 
11:40:09 -0400)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-video.git tags/video-20230814

for you to fetch changes up to 04cc66c047d959dc1b22a625b7949a26793ac52b:

  rpi: set the correct parameter for simple framebuffer node (2023-08-13 
23:57:46 +0200)


 - fix NULL dereference in vidconsole_measure()
 - fix simplefb format for raspberrypi-4b
 - fix typo in Kconfig


Bin Meng (2):
  video: vidconsole: Fix null dereference of ops->measure
  video: kconfig: Fix a typo in SPL_VIDEO_REMOVE

Jason Wessel (1):
  bcm2835: Add simiple-framebuffer for use with fkms

Meng Li (1):
  rpi: set the correct parameter for simple framebuffer node

 board/raspberrypi/rpi/rpi.c   | 2 ++
 drivers/video/Kconfig | 2 +-
 drivers/video/bcm2835.c   | 3 +++
 drivers/video/vidconsole-uclass.c | 2 +-
 4 files changed, 7 insertions(+), 2 deletions(-)


[PATCH 1/1] efi_loader: fix efi_add_known_memory()

2023-08-13 Thread Heinrich Schuchardt
In efi_add_known_memory() we currently call board_get_usable_ram_top() with
an incorrect value 0 of parameter total_size. This leads to an incorrect
value for ram_top depending on the code in board_get_usable_ram_top().

Use the value of gd->ram_top instead which is set before relocation by
calling board_get_usable_ram_top().

Fixes: 7b78d6438a2b ("efi_loader: Reserve unaccessible memory")
Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index ebf4a2d5fa..f752703b43 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -877,7 +877,7 @@ efi_status_t efi_add_conventional_memory_map(u64 ram_start, 
u64 ram_end,
  */
 __weak void efi_add_known_memory(void)
 {
-   u64 ram_top = board_get_usable_ram_top(0) & ~EFI_PAGE_MASK;
+   u64 ram_top = gd->ram_top & ~EFI_PAGE_MASK;
int i;
 
/*
-- 
2.40.1



Re: [PATCH] net: Fix the displayed value of bytes transferred

2023-08-13 Thread Siddharth Vadapalli



On 14/08/23 10:06, Siddharth Vadapalli wrote:
> Hello Tom,
> 
> On 11/08/23 21:45, Tom Rini wrote:
>> On Fri, Aug 11, 2023 at 10:49:23AM +0530, Siddharth Vadapalli wrote:
>>> Ravi,
>>>
>>> On 10/08/23 17:00, Ravi Gunasekaran wrote:

...

>>
>> Uh, maybe I'm just missing something, but I think there's two things.
>> First, this should be "%u" for "unsigned decimal".  Second,
>> doc/develop/printf.rst needs to be fixed since:
>> int %d, %x
>> unsigned int%d, %x
>>
>> Should is wrong and should say %u, %x, because, well, that's what would
>> be correct, yes?
> 
> Thank you for reviewing the patch. Yes, %u works well and can print u32 
> variable
> accurately. I tested it for 0x. %d prints -1 for the same. So, %lu 
> isn't
> necessary and %u is sufficient. I will replace %lu with %u and post the v2
> patch. Additionally, I will include a patch in the v2 series to update the
> Documentation as pointed out by you.

I have posted the v2 series at:
https://patchwork.ozlabs.org/project/uboot/list/?series=368661&state=%2A&archive=both

> 
>>
> 

-- 
Regards,
Siddharth.


[PATCH v2 2/2] doc: printf() codes: Fix format specifier for unsigned int

2023-08-13 Thread Siddharth Vadapalli
The format specifier for the "unsigned int" variable is documented as
"%d". However, it should be "%u". Thus, fix it.

Fixes: f5e9035043fb ("doc: printf() codes")
Reported-by: Tom Rini 
Signed-off-by: Siddharth Vadapalli 
---
 doc/develop/printf.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/develop/printf.rst b/doc/develop/printf.rst
index 7b9aea0687..05909a1f22 100644
--- a/doc/develop/printf.rst
+++ b/doc/develop/printf.rst
@@ -111,7 +111,7 @@ unsigned char   %u, %x
 short   %d, %x
 unsigned short  %u, %x
 int %d, %x
-unsigned int%d, %x
+unsigned int%u, %x
 long%ld, %lx
 unsigned long   %lu, %lx
 long long   %lld, %llx
-- 
2.34.1



[PATCH v2 1/2] net: Fix the displayed value of bytes transferred

2023-08-13 Thread Siddharth Vadapalli
In the case of NETLOOP_SUCCESS, the decimal value of the u32 variable
"net_boot_file_size" is printed using "%d", resulting in negative values
being reported for large file sizes. Fix this by using "%u" to print the
decimal value corresponding to the bytes transferred.

Fixes: 1411157d8578 ("net: cosmetic: Fixup var names related to boot file")
Signed-off-by: Siddharth Vadapalli 
---
 net/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/net.c b/net/net.c
index 43abbac7c3..e6f61f0f8f 100644
--- a/net/net.c
+++ b/net/net.c
@@ -716,7 +716,7 @@ restart:
case NETLOOP_SUCCESS:
net_cleanup_loop();
if (net_boot_file_size > 0) {
-   printf("Bytes transferred = %d (%x hex)\n",
+   printf("Bytes transferred = %u (%x hex)\n",
   net_boot_file_size, net_boot_file_size);
env_set_hex("filesize", net_boot_file_size);
env_set_hex("fileaddr", image_load_addr);
-- 
2.34.1



[PATCH v2 0/2] Fix format specifier for net_boot_file_size

2023-08-13 Thread Siddharth Vadapalli
Hello,

This series fixes the format specifier for printing the decimal value of
the variable "net_boot_file_size", changing it from "%d" to "%u". With
the format specifier being "%d", for large file sizes, the value
displayed is negative. Using "%u" fixes this.

Additionally, as reported by Tom Rini  in the mail
thread corresponding to the v1 patch of this series, the documentation
for the printf format specifiers needs to be fixed for the "unsigned
int" variable. Thus, update the documentation as well.

Regards,
Siddharth.

---
v1:
https://patchwork.ozlabs.org/project/uboot/patch/20230810091523.3168975-1-s-vadapa...@ti.com/

Changes since v1:
- Use "%u" instead of "%lu" to display the decimal value of the u32
  variable "net_boot_file_size", as suggested by Tom Rini.
- Add a new patch to update the documentation for printf format
  specifiers, changing the format specifier from "%d" to "%u" for the
  "unsigned int" variable, as reported by Tom Rini.

Siddharth Vadapalli (2):
  net: Fix the displayed value of bytes transferred
  doc: printf() codes: Fix format specifier for unsigned int

 doc/develop/printf.rst | 2 +-
 net/net.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.34.1



Re: [PATCH] net: Fix the displayed value of bytes transferred

2023-08-13 Thread Siddharth Vadapalli
Hello Tom,

On 11/08/23 21:45, Tom Rini wrote:
> On Fri, Aug 11, 2023 at 10:49:23AM +0530, Siddharth Vadapalli wrote:
>> Ravi,
>>
>> On 10/08/23 17:00, Ravi Gunasekaran wrote:
>>> Siddharth,
>>>
>>> On 8/10/23 2:45 PM, Siddharth Vadapalli wrote:
 In the case of NETLOOP_SUCCESS, the decimal value of the u32 variable
 "net_boot_file_size" is printed using "%d", resulting in negative values
 being reported for large file sizes. Fix this by using "%lu" to print
 the decimal value corresponding to the bytes transferred.

 Fixes: 1411157d8578 ("net: cosmetic: Fixup var names related to boot file")
 Signed-off-by: Siddharth Vadapalli 
 ---
  net/net.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/net/net.c b/net/net.c
 index 43abbac7c3..7aaeafc247 100644
 --- a/net/net.c
 +++ b/net/net.c
 @@ -716,7 +716,7 @@ restart:
case NETLOOP_SUCCESS:
net_cleanup_loop();
if (net_boot_file_size > 0) {
 -  printf("Bytes transferred = %d (%x hex)\n",
 +  printf("Bytes transferred = %lu (%x hex)\n",
>>>
>>> 'net_boot_file_size' is of type u32. Using "%lu" will throw a warning for 
>>> this.
>>> As per [0], format specifier for 'unsigned int' is "%d, %x'.
>>>
>>> You could perhaps change the data type of 'net_boot_file_size' to 'ulong' 
>>> as well.
>>
>> The issue here isn't the size of the variable itself, but the format 
>> specifier.
>> For large file sizes, the hex value printed for the variable is correct, but 
>> the
>> decimal value is negative.
>>
>>>
>>> [0] - https://u-boot.readthedocs.io/en/latest/develop/printf.html
> 
> Uh, maybe I'm just missing something, but I think there's two things.
> First, this should be "%u" for "unsigned decimal".  Second,
> doc/develop/printf.rst needs to be fixed since:
> int %d, %x
> unsigned int%d, %x
> 
> Should is wrong and should say %u, %x, because, well, that's what would
> be correct, yes?

Thank you for reviewing the patch. Yes, %u works well and can print u32 variable
accurately. I tested it for 0x. %d prints -1 for the same. So, %lu isn't
necessary and %u is sufficient. I will replace %lu with %u and post the v2
patch. Additionally, I will include a patch in the v2 series to update the
Documentation as pointed out by you.

> 

-- 
Regards,
Siddharth.


Re: [PATCH 12/24] fs/erofs: Quieten test for filesystem presence

2023-08-13 Thread Gao Xiang




On 2023/8/13 22:26, Simon Glass wrote:

At present listing a partition produces lots of errors about this
filesystem:

=> part list mmc 4
cannot find valid erofs superblock
cannot find valid erofs superblock
cannot read erofs superblock: -5
[9 more similar lines]

Use debugging rather than errors when unable to find a signature, as is
done with other filesystems.

Signed-off-by: Simon Glass 


Reviewed-by: Gao Xiang 

Thanks,
Gao Xiang


Re: [PATCH] Add support for more XMC series

2023-08-13 Thread Clus Tom
Hi Simon,
I'm not quite sure what you mean by v2, if it's the previous email, it only
removes the XM25QH128C part of the commit message compared to the previous
one.

Thanks,
SSunk

Simon Glass  于2023年8月13日周日 21:36写道:

> On Fri, 11 Aug 2023 at 21:19, SSunk  wrote:
> >
> > Add XMC XM25QH256C/XM25QU256C/XM25QH512C/XM25QU512C
> > site: https://www.xmcwh.com/site/product
> >
> > Signed-off-by: Kankan Sun 
> > ---
> >  configs/evb-ast2600_defconfig | 1 +
> >  drivers/mtd/spi/spi-nor-ids.c | 4 
> >  2 files changed, 5 insertions(+)
>
> Reviewed-by: Simon Glass 
>
> I think this is v2 so it should have that as well as a change list.
> You can use 'patman' to help with this.
>
> Regards,
> Simon
>
>
>
> >
> > diff --git a/configs/evb-ast2600_defconfig
> b/configs/evb-ast2600_defconfig
> > index 9244654c82..f06c0e1fe1 100644
> > --- a/configs/evb-ast2600_defconfig
> > +++ b/configs/evb-ast2600_defconfig
> > @@ -100,6 +100,7 @@ CONFIG_SPI_FLASH_SPANSION=y
> >  CONFIG_SPI_FLASH_STMICRO=y
> >  CONFIG_SPI_FLASH_SST=y
> >  CONFIG_SPI_FLASH_WINBOND=y
> > +CONFIG_SPI_FLASH_XMC=y
> >  # CONFIG_SPI_FLASH_USE_4K_SECTORS is not set
> >  CONFIG_PHY_REALTEK=y
> >  CONFIG_PHY_NCSI=y
> > diff --git a/drivers/mtd/spi/spi-nor-ids.c
> b/drivers/mtd/spi/spi-nor-ids.c
> > index 4587215984..80d7678293 100644
> > --- a/drivers/mtd/spi/spi-nor-ids.c
> > +++ b/drivers/mtd/spi/spi-nor-ids.c
> > @@ -531,6 +531,10 @@ const struct flash_info spi_nor_ids[] = {
> > { INFO("XM25QH64A", 0x207017, 0, 64 * 1024, 128, SECT_4K |
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
> > { INFO("XM25QH64C", 0x204017, 0, 64 * 1024, 128, SECT_4K |
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
> > { INFO("XM25QH128A", 0x207018, 0, 64 * 1024, 256, SECT_4K |
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
> > +   { INFO("XM25QH256C", 0x204019, 0, 64 * 1024, 512, SECT_4K |
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
> > +   { INFO("XM25QU256C", 0x204119, 0, 64 * 1024, 512, SECT_4K |
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
> > +   { INFO("XM25QH512C", 0x204020, 0, 64 * 1024, 1024, SECT_4K |
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
> > +   { INFO("XM25QU512C", 0x204120, 0, 64 * 1024, 1024, SECT_4K |
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
> >  #endif
> >  #ifdef CONFIG_SPI_FLASH_XTX
> > /* XTX Technology Limited */
> > --
> > 2.34.1
> >
>


Re: [PATCH] rockchip: rk356x: Enable poweroff command

2023-08-13 Thread Kever Yang

Hi Jonas,

    Please split this patch into two patch, one for update defconfig 
and one for update pmic Kconfig.



Thanks,

- Kever

On 2023/8/4 03:54, Jonas Karlman wrote:

With PMIC_RK8XX, SYSRESET and CMD_POWEROFF options enabled it is
possible to power down a board using the poweroff command and turn the
board back on using a power button.

Enable the poweroff command on RK356x boards that have a button wired
to PMIC pwron. Also update to use PMIC poweroff when PMIC_RK8XX is
enabled to avoid also having to enable the SYSRESET_CMD_POWEROFF option.

Signed-off-by: Jonas Karlman 
---
  configs/quartz64-a-rk3566_defconfig   | 1 +
  configs/quartz64-b-rk3566_defconfig   | 1 +
  configs/rock-3a-rk3568_defconfig  | 1 +
  configs/soquartz-model-a-rk3566_defconfig | 1 +
  drivers/power/pmic/Kconfig| 1 +
  5 files changed, 5 insertions(+)

diff --git a/configs/quartz64-a-rk3566_defconfig 
b/configs/quartz64-a-rk3566_defconfig
index d55b224feacd..6853cd6c44b4 100644
--- a/configs/quartz64-a-rk3566_defconfig
+++ b/configs/quartz64-a-rk3566_defconfig
@@ -52,6 +52,7 @@ CONFIG_CMD_GPT=y
  CONFIG_CMD_I2C=y
  CONFIG_CMD_MMC=y
  CONFIG_CMD_PCI=y
+CONFIG_CMD_POWEROFF=y
  CONFIG_CMD_USB=y
  # CONFIG_CMD_SETEXPR is not set
  CONFIG_CMD_PMIC=y
diff --git a/configs/quartz64-b-rk3566_defconfig 
b/configs/quartz64-b-rk3566_defconfig
index b98c81f9dcef..aa29fff14643 100644
--- a/configs/quartz64-b-rk3566_defconfig
+++ b/configs/quartz64-b-rk3566_defconfig
@@ -50,6 +50,7 @@ CONFIG_CMD_GPT=y
  CONFIG_CMD_I2C=y
  CONFIG_CMD_MMC=y
  CONFIG_CMD_PCI=y
+CONFIG_CMD_POWEROFF=y
  CONFIG_CMD_USB=y
  # CONFIG_CMD_SETEXPR is not set
  CONFIG_CMD_PMIC=y
diff --git a/configs/rock-3a-rk3568_defconfig b/configs/rock-3a-rk3568_defconfig
index 44ff054df665..409aa95acf06 100644
--- a/configs/rock-3a-rk3568_defconfig
+++ b/configs/rock-3a-rk3568_defconfig
@@ -49,6 +49,7 @@ CONFIG_CMD_GPT=y
  CONFIG_CMD_I2C=y
  CONFIG_CMD_MMC=y
  CONFIG_CMD_PCI=y
+CONFIG_CMD_POWEROFF=y
  CONFIG_CMD_USB=y
  # CONFIG_CMD_SETEXPR is not set
  CONFIG_CMD_PMIC=y
diff --git a/configs/soquartz-model-a-rk3566_defconfig 
b/configs/soquartz-model-a-rk3566_defconfig
index c3958579db73..a0884a797d58 100644
--- a/configs/soquartz-model-a-rk3566_defconfig
+++ b/configs/soquartz-model-a-rk3566_defconfig
@@ -43,6 +43,7 @@ CONFIG_CMD_GPT=y
  CONFIG_CMD_I2C=y
  CONFIG_CMD_MMC=y
  CONFIG_CMD_PCI=y
+CONFIG_CMD_POWEROFF=y
  CONFIG_CMD_USB=y
  # CONFIG_CMD_SETEXPR is not set
  CONFIG_CMD_PMIC=y
diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
index 176fb07c651a..4a6f0ce093ad 100644
--- a/drivers/power/pmic/Kconfig
+++ b/drivers/power/pmic/Kconfig
@@ -233,6 +233,7 @@ config PMIC_QCOM
  
  config PMIC_RK8XX

bool "Enable support for Rockchip PMIC RK8XX"
+   select SYSRESET_CMD_POWEROFF if SYSRESET && CMD_POWEROFF
---help---
The Rockchip RK808 PMIC provides four buck DC-DC convertors, 8 LDOs,
an RTC and two low Rds (resistance (drain to source)) switches. It is


Re: [PATCH] x86: Update cbmem driver

2023-08-13 Thread Alex Sadovsky
Dear Simon and other developers,
> - cursor = cbmem_console_p->buffer_cursor++;
> - if (cursor < cbmem_console_p->buffer_size)
> - cbmem_console_p->buffer_body[cursor] = data;
> + pos = cons->cursor++;
> + if (pos < cons->size)
> + cons->body[pos] = data;
While at it, is it OK to increment cons->cursor unconditionally,
even when the buffer is full?

It's better to do it after the check, isn't it? E.g.:

if (cons->cursor < cons->size)
cons->body[cons->cursor++] = data;

Cheers, Alex.



Re: [PATCH v2] pinctrl: rockchip: Fix drive and input schmitt on RK3568

2023-08-13 Thread Kever Yang



On 2023/8/14 08:28, Jonas Karlman wrote:

On RK3568 most pins have a configurable drive strength of level 0-5 and
some pins level 0-11. When rk3568_set_drive is called with a strength
value above 7 the drv value written to reg may overflow into the write
enable bits, resulting in a bad configuration.

This cause e.g. ethernet PHY on Radxa CM3-IO board not to work after
drive is configured according to the device tree.

   Could not get PHY for ethernet@fe01: addr 0

Level 6-11 can be configured using a second reg for some pins, however
the drv value is reused resulting in lower 6 bits being written to reg.

Input schmitt is configured in 2-bit fields on RK3568 compared to
earlier generation and 2'b10 should be used to enable input schmitt.

Change to use regmap_update_bits with a rmask to fix the overflow issue
and closer match the linux driver. Bit shift the drv value used for the
second reg to configure drive strength level 6-11. Also write correct
values for input schmitt setting.

Fixes: 1977d746aa54 ("rockchip: rk3568: add rk3568 pinctrl driver")
Signed-off-by: Jonas Karlman 
Reviewed-by: Simon Glass 

Reviewed-by: Kever Yang 

Thanks,
- Kever

---
Changes in v2:
- Restore use of second reg in rk3568_set_drive and write drv bit 11:6
   to the reg. TRM mention: PAD Strength control,DS[11:6]
- Collect r-b tag

  drivers/pinctrl/rockchip/pinctrl-rk3568.c | 56 +--
  1 file changed, 31 insertions(+), 25 deletions(-)

diff --git a/drivers/pinctrl/rockchip/pinctrl-rk3568.c 
b/drivers/pinctrl/rockchip/pinctrl-rk3568.c
index 314edb5a6064..1d4391982605 100644
--- a/drivers/pinctrl/rockchip/pinctrl-rk3568.c
+++ b/drivers/pinctrl/rockchip/pinctrl-rk3568.c
@@ -113,11 +113,9 @@ static int rk3568_set_mux(struct rockchip_pin_bank *bank, 
int pin, int mux)
struct rockchip_pinctrl_priv *priv = bank->priv;
int iomux_num = (pin / 8);
struct regmap *regmap;
-   int reg, ret, mask;
+   int reg, mask;
u8 bit;
-   u32 data;
-
-   debug("setting mux of GPIO%d-%d to %d\n", bank->bank_num, pin, mux);
+   u32 data, rmask;
  
  	if (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)

regmap = priv->regmap_pmu;
@@ -131,10 +129,10 @@ static int rk3568_set_mux(struct rockchip_pin_bank *bank, 
int pin, int mux)
mask = 0xf;
  
  	data = (mask << (bit + 16));

+   rmask = data | (data >> 16);
data |= (mux & mask) << bit;
-   ret = regmap_write(regmap, reg, data);
  
-	return ret;

+   return regmap_update_bits(regmap, reg, rmask, data);
  }
  
  #define RK3568_PULL_PMU_OFFSET		0x20

@@ -225,7 +223,7 @@ static int rk3568_set_pull(struct rockchip_pin_bank *bank,
struct regmap *regmap;
int reg, ret;
u8 bit, type;
-   u32 data;
+   u32 data, rmask;
  
  	if (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT)

return -ENOTSUPP;
@@ -249,52 +247,59 @@ static int rk3568_set_pull(struct rockchip_pin_bank *bank,
  
  	/* enable the write to the equivalent lower bits */

data = ((1 << ROCKCHIP_PULL_BITS_PER_PIN) - 1) << (bit + 16);
-
+   rmask = data | (data >> 16);
data |= (ret << bit);
-   ret = regmap_write(regmap, reg, data);
  
-	return ret;

+   return regmap_update_bits(regmap, reg, rmask, data);
  }
  
+#define GRF_GPIO1C5_DS		0x0840

+#define GRF_GPIO2A2_DS 0x0844
+#define GRF_GPIO2B0_DS 0x0848
+#define GRF_GPIO3A0_DS 0x084c
+#define GRF_GPIO3A6_DS 0x0850
+#define GRF_GPIO4A0_DS 0x0854
+
  static int rk3568_set_drive(struct rockchip_pin_bank *bank,
int pin_num, int strength)
  {
struct regmap *regmap;
-   int reg;
-   u32 data;
+   int reg, ret;
+   u32 data, rmask;
u8 bit;
int drv = (1 << (strength + 1)) - 1;
-   int ret = 0;
  
  	rk3568_calc_drv_reg_and_bit(bank, pin_num, ®map, ®, &bit);
  
  	/* enable the write to the equivalent lower bits */

data = ((1 << RK3568_DRV_BITS_PER_PIN) - 1) << (bit + 16);
+   rmask = data | (data >> 16);
data |= (drv << bit);
  
-	ret = regmap_write(regmap, reg, data);

+   ret = regmap_update_bits(regmap, reg, rmask, data);
if (ret)
return ret;
  
  	if (bank->bank_num == 1 && pin_num == 21)

-   reg = 0x0840;
+   reg = GRF_GPIO1C5_DS;
else if (bank->bank_num == 2 && pin_num == 2)
-   reg = 0x0844;
+   reg = GRF_GPIO2A2_DS;
else if (bank->bank_num == 2 && pin_num == 8)
-   reg = 0x0848;
+   reg = GRF_GPIO2B0_DS;
else if (bank->bank_num == 3 && pin_num == 0)
-   reg = 0x084c;
+   reg = GRF_GPIO3A0_DS;
else if (bank->bank_num == 3 && pin_num == 6)
-   reg = 0x0850;
+   reg = GRF_GPIO3A6_DS;
else if (bank->bank_num == 4 && pin_num == 0)
-   reg = 0x0854;
+   reg = GRF_GPIO4A0_DS;

Re: [PATCH] pinctrl: rockchip: Fix drive and input schmitt on RK3568

2023-08-13 Thread Jonas Karlman
Hi Kever and Steven,

On 2023-08-12 04:50, Kever Yang wrote:
> Add Steven Liu,
> 
> Hi Steven,
> 
>      Please help to review this patch.
> 
> 
> On 2023/8/4 01:44, Jonas Karlman wrote:
>> rk3568_set_drive configures a second reg for specific pins. Mainline
>> linux does not do this and vendor U-Boot only run similar code when bit
>> 14 and 15 are both 0 in PMU_GRF_SOC_CON0.
> 
> The base version of this driver also based on vendor U-Boot, right? But 
> this part of
> 
> logic is different? interesting...

Yes, this seemed strange.

I have sent a v2 of this patch that restore part of this code after
looking closer in Hardware Design Guide, PinOut and TRM documents.

If I understand correctly the first reg should contain DS[5:0] and the
second reg should contain DS[11:6], not a copy of DS[5:0].

Regards,
Jonas

> 
> 
> Thanks,
> 
> - Kever
> 
>>   Something that presumably only
>> early revisions of the SoC have, all my RK3566/RK3568 boards read back
>> bit 15 as 1, even on boards dated back to 21H1.
>>
>> This cause e.g. ethernet PHY on Radxa CM3-IO board not to work after
>> drive is configured according to the device tree.
>>
>> Input schmitt is configured in 2-bit fields on RK3568 compared to earlier
>> generation and 2'b10 should be used to enable input schmitt.
>>
>> Remove the code that presumably was intended for early pre-production
>> revisions of the SoC and write correct values for input schmitt setting.
>> Also change to use regmap_update_bits to closer match linux driver.
>>
>> Fixes: 1977d746aa54 ("rockchip: rk3568: add rk3568 pinctrl driver")
>> Signed-off-by: Jonas Karlman 
>> ---
>>   drivers/pinctrl/rockchip/pinctrl-rk3568.c | 52 ++-
>>   1 file changed, 14 insertions(+), 38 deletions(-)
>>

[...]


[PATCH v2] pinctrl: rockchip: Fix drive and input schmitt on RK3568

2023-08-13 Thread Jonas Karlman
On RK3568 most pins have a configurable drive strength of level 0-5 and
some pins level 0-11. When rk3568_set_drive is called with a strength
value above 7 the drv value written to reg may overflow into the write
enable bits, resulting in a bad configuration.

This cause e.g. ethernet PHY on Radxa CM3-IO board not to work after
drive is configured according to the device tree.

  Could not get PHY for ethernet@fe01: addr 0

Level 6-11 can be configured using a second reg for some pins, however
the drv value is reused resulting in lower 6 bits being written to reg.

Input schmitt is configured in 2-bit fields on RK3568 compared to
earlier generation and 2'b10 should be used to enable input schmitt.

Change to use regmap_update_bits with a rmask to fix the overflow issue
and closer match the linux driver. Bit shift the drv value used for the
second reg to configure drive strength level 6-11. Also write correct
values for input schmitt setting.

Fixes: 1977d746aa54 ("rockchip: rk3568: add rk3568 pinctrl driver")
Signed-off-by: Jonas Karlman 
Reviewed-by: Simon Glass 
---
Changes in v2:
- Restore use of second reg in rk3568_set_drive and write drv bit 11:6
  to the reg. TRM mention: PAD Strength control,DS[11:6]
- Collect r-b tag

 drivers/pinctrl/rockchip/pinctrl-rk3568.c | 56 +--
 1 file changed, 31 insertions(+), 25 deletions(-)

diff --git a/drivers/pinctrl/rockchip/pinctrl-rk3568.c 
b/drivers/pinctrl/rockchip/pinctrl-rk3568.c
index 314edb5a6064..1d4391982605 100644
--- a/drivers/pinctrl/rockchip/pinctrl-rk3568.c
+++ b/drivers/pinctrl/rockchip/pinctrl-rk3568.c
@@ -113,11 +113,9 @@ static int rk3568_set_mux(struct rockchip_pin_bank *bank, 
int pin, int mux)
struct rockchip_pinctrl_priv *priv = bank->priv;
int iomux_num = (pin / 8);
struct regmap *regmap;
-   int reg, ret, mask;
+   int reg, mask;
u8 bit;
-   u32 data;
-
-   debug("setting mux of GPIO%d-%d to %d\n", bank->bank_num, pin, mux);
+   u32 data, rmask;
 
if (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
regmap = priv->regmap_pmu;
@@ -131,10 +129,10 @@ static int rk3568_set_mux(struct rockchip_pin_bank *bank, 
int pin, int mux)
mask = 0xf;
 
data = (mask << (bit + 16));
+   rmask = data | (data >> 16);
data |= (mux & mask) << bit;
-   ret = regmap_write(regmap, reg, data);
 
-   return ret;
+   return regmap_update_bits(regmap, reg, rmask, data);
 }
 
 #define RK3568_PULL_PMU_OFFSET 0x20
@@ -225,7 +223,7 @@ static int rk3568_set_pull(struct rockchip_pin_bank *bank,
struct regmap *regmap;
int reg, ret;
u8 bit, type;
-   u32 data;
+   u32 data, rmask;
 
if (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT)
return -ENOTSUPP;
@@ -249,52 +247,59 @@ static int rk3568_set_pull(struct rockchip_pin_bank *bank,
 
/* enable the write to the equivalent lower bits */
data = ((1 << ROCKCHIP_PULL_BITS_PER_PIN) - 1) << (bit + 16);
-
+   rmask = data | (data >> 16);
data |= (ret << bit);
-   ret = regmap_write(regmap, reg, data);
 
-   return ret;
+   return regmap_update_bits(regmap, reg, rmask, data);
 }
 
+#define GRF_GPIO1C5_DS 0x0840
+#define GRF_GPIO2A2_DS 0x0844
+#define GRF_GPIO2B0_DS 0x0848
+#define GRF_GPIO3A0_DS 0x084c
+#define GRF_GPIO3A6_DS 0x0850
+#define GRF_GPIO4A0_DS 0x0854
+
 static int rk3568_set_drive(struct rockchip_pin_bank *bank,
int pin_num, int strength)
 {
struct regmap *regmap;
-   int reg;
-   u32 data;
+   int reg, ret;
+   u32 data, rmask;
u8 bit;
int drv = (1 << (strength + 1)) - 1;
-   int ret = 0;
 
rk3568_calc_drv_reg_and_bit(bank, pin_num, ®map, ®, &bit);
 
/* enable the write to the equivalent lower bits */
data = ((1 << RK3568_DRV_BITS_PER_PIN) - 1) << (bit + 16);
+   rmask = data | (data >> 16);
data |= (drv << bit);
 
-   ret = regmap_write(regmap, reg, data);
+   ret = regmap_update_bits(regmap, reg, rmask, data);
if (ret)
return ret;
 
if (bank->bank_num == 1 && pin_num == 21)
-   reg = 0x0840;
+   reg = GRF_GPIO1C5_DS;
else if (bank->bank_num == 2 && pin_num == 2)
-   reg = 0x0844;
+   reg = GRF_GPIO2A2_DS;
else if (bank->bank_num == 2 && pin_num == 8)
-   reg = 0x0848;
+   reg = GRF_GPIO2B0_DS;
else if (bank->bank_num == 3 && pin_num == 0)
-   reg = 0x084c;
+   reg = GRF_GPIO3A0_DS;
else if (bank->bank_num == 3 && pin_num == 6)
-   reg = 0x0850;
+   reg = GRF_GPIO3A6_DS;
else if (bank->bank_num == 4 && pin_num == 0)
-   reg = 0x0854;
+   reg = GRF_GPIO4A0_DS;
else
return 0;
 
data = ((

RE: [PATCH] Add support for more XMC series

2023-08-13 Thread ChiaWei Wang
> From: SSunk 
> Sent: Saturday, August 12, 2023 11:08 AM
> 
> Add XMC
> XM25QH128C/XM25QH256C/XM25QU256C/XM25QH512C/XM25QU512C
> site: https://www.xmcwh.com/site/product
> 
> Signed-off-by: Kankan Sun 

Reviewed-by: Chia-Wei Wang 


Re: [PATCH 1/2] drivers/mtd/nvmxip: Rework the read accessor to support 32bit systems

2023-08-13 Thread Marek Vasut

On 8/13/23 23:46, Marek Vasut wrote:

Get rid of nvmxip_mmio_rawread() and just implement the readl()/readq()
reader loop within nvmxip_blk_read(). Cast the destination buffer as
needed and increment the read by either 4 or 8 bytes depending on if
this is systemd with 32bit or 64bit physical address.

Signed-off-by: Marek Vasut 


These two patches need a bit more work, skip for now.


Re: [PATCH] usb: gadget: sdp: Option to enable SDP read register command

2023-08-13 Thread Marek Vasut

On 8/13/23 10:39, Loic Poulain wrote:

The SDP read register command can be used to read any memory
mapped address of the device (ddr, registers...). It can then
be exploited by an attacker to access sensitive data/values,
especially when running SDP from SPL, as SPL runs with highest
privileges in ARM secure mode.

Without read, SDP still useful to bootstrap and jump on (signed)
blob such as u-boot with write and jump commands, but reading
is optional in that case (debug purpose).

NXP SoCs usually have a dedicated SDP_READ_DISABLE fuse to disable
SDP read command in their ROM SDP implementation, so it seems quite
reasonable to make it optional from u-boot/spl as well.


If there is a fuse, why not read the fuse and disable READ based on that 
fuse instead ?


[PATCH 5/6] ufs: Use utp_transfer_req_desc pointer in ufshcd_get_tr_ocs

2023-08-13 Thread Marek Vasut
Use utp_transfer_req_desc pointer to reference to utrdl queue
instead of referencing the queue directly. This makes the code
more consistent. No functional change.

Signed-off-by: Marek Vasut 
---
Cc: Faiz Abbas 
---
 drivers/ufs/ufs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ufs/ufs.c b/drivers/ufs/ufs.c
index da1009e2c14..041caee714f 100644
--- a/drivers/ufs/ufs.c
+++ b/drivers/ufs/ufs.c
@@ -858,7 +858,9 @@ static inline int ufshcd_get_req_rsp(struct utp_upiu_rsp 
*ucd_rsp_ptr)
  */
 static inline int ufshcd_get_tr_ocs(struct ufs_hba *hba)
 {
-   return le32_to_cpu(hba->utrdl->header.dword_2) & MASK_OCS;
+   struct utp_transfer_req_desc *req_desc = hba->utrdl;
+
+   return le32_to_cpu(req_desc->header.dword_2) & MASK_OCS;
 }
 
 static inline int ufshcd_get_rsp_upiu_result(struct utp_upiu_rsp *ucd_rsp_ptr)
-- 
2.40.1



[PATCH 6/6] ufs: Implement cache management

2023-08-13 Thread Marek Vasut
Add function to flush and invalidate cache over request and response
queue entries, and perform flush and optional invalidate over block
layer data that are passed into the UFS layer. This makes it possible
to use UFS with caches enabled.

Signed-off-by: Marek Vasut 
---
Cc: Faiz Abbas 
---
 drivers/ufs/ufs.c | 42 +-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/drivers/ufs/ufs.c b/drivers/ufs/ufs.c
index 041caee714f..7c48d57f99d 100644
--- a/drivers/ufs/ufs.c
+++ b/drivers/ufs/ufs.c
@@ -692,6 +692,21 @@ static inline u8 ufshcd_get_upmcrs(struct ufs_hba *hba)
return (ufshcd_readl(hba, REG_CONTROLLER_STATUS) >> 8) & 0x7;
 }
 
+/**
+ * ufshcd_cache_flush_and_invalidate - Flush and invalidate cache
+ *
+ * Flush and invalidate cache in aligned address..address+size range.
+ * The invalidation is in place to avoid stale data in cache.
+ */
+static void ufshcd_cache_flush_and_invalidate(void *addr, unsigned long size)
+{
+   uintptr_t aaddr = (uintptr_t)addr & ~(ARCH_DMA_MINALIGN - 1);
+   unsigned long asize = ALIGN(size, ARCH_DMA_MINALIGN);
+
+   flush_dcache_range(aaddr, aaddr + asize);
+   invalidate_dcache_range(aaddr, aaddr + asize);
+}
+
 /**
  * ufshcd_prepare_req_desc_hdr() - Fills the requests header
  * descriptor according to request
@@ -735,6 +750,8 @@ static void ufshcd_prepare_req_desc_hdr(struct ufs_hba *hba,
req_desc->header.dword_3 = 0;
 
req_desc->prd_table_length = 0;
+
+   ufshcd_cache_flush_and_invalidate(req_desc, sizeof(*req_desc));
 }
 
 static void ufshcd_prepare_utp_query_req_upiu(struct ufs_hba *hba,
@@ -763,10 +780,15 @@ static void ufshcd_prepare_utp_query_req_upiu(struct 
ufs_hba *hba,
memcpy(&ucd_req_ptr->qr, &query->request.upiu_req, QUERY_OSF_SIZE);
 
/* Copy the Descriptor */
-   if (query->request.upiu_req.opcode == UPIU_QUERY_OPCODE_WRITE_DESC)
+   if (query->request.upiu_req.opcode == UPIU_QUERY_OPCODE_WRITE_DESC) {
memcpy(ucd_req_ptr + 1, query->descriptor, len);
+   ufshcd_cache_flush_and_invalidate(ucd_req_ptr, 2 * 
sizeof(*ucd_req_ptr));
+   } else {
+   ufshcd_cache_flush_and_invalidate(ucd_req_ptr, 
sizeof(*ucd_req_ptr));
+   }
 
memset(hba->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp));
+   ufshcd_cache_flush_and_invalidate(hba->ucd_rsp_ptr, 
sizeof(*hba->ucd_rsp_ptr));
 }
 
 static inline void ufshcd_prepare_utp_nop_upiu(struct ufs_hba *hba)
@@ -783,6 +805,9 @@ static inline void ufshcd_prepare_utp_nop_upiu(struct 
ufs_hba *hba)
ucd_req_ptr->header.dword_2 = 0;
 
memset(hba->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp));
+
+   ufshcd_cache_flush_and_invalidate(ucd_req_ptr, sizeof(*ucd_req_ptr));
+   ufshcd_cache_flush_and_invalidate(hba->ucd_rsp_ptr, 
sizeof(*hba->ucd_rsp_ptr));
 }
 
 /**
@@ -1409,6 +1434,8 @@ void ufshcd_prepare_utp_scsi_cmd_upiu(struct ufs_hba *hba,
memcpy(ucd_req_ptr->sc.cdb, pccb->cmd, cdb_len);
 
memset(hba->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp));
+   ufshcd_cache_flush_and_invalidate(ucd_req_ptr, sizeof(*ucd_req_ptr));
+   ufshcd_cache_flush_and_invalidate(hba->ucd_rsp_ptr, 
sizeof(*hba->ucd_rsp_ptr));
 }
 
 static inline void prepare_prdt_desc(struct ufshcd_sg_entry *entry,
@@ -1423,6 +1450,7 @@ static void prepare_prdt_table(struct ufs_hba *hba, 
struct scsi_cmd *pccb)
 {
struct utp_transfer_req_desc *req_desc = hba->utrdl;
struct ufshcd_sg_entry *prd_table = hba->ucd_prdt_ptr;
+   uintptr_t aaddr = (uintptr_t)(pccb->pdata) & ~(ARCH_DMA_MINALIGN - 1);
ulong datalen = pccb->datalen;
int table_length;
u8 *buf;
@@ -1430,9 +1458,19 @@ static void prepare_prdt_table(struct ufs_hba *hba, 
struct scsi_cmd *pccb)
 
if (!datalen) {
req_desc->prd_table_length = 0;
+   ufshcd_cache_flush_and_invalidate(req_desc, sizeof(*req_desc));
return;
}
 
+   if (pccb->dma_dir == DMA_TO_DEVICE) {   /* Write to device */
+   flush_dcache_range(aaddr, aaddr +
+  ALIGN(datalen, ARCH_DMA_MINALIGN));
+   }
+
+   /* In any case, invalidate cache to avoid stale data in it. */
+   invalidate_dcache_range(aaddr, aaddr +
+   ALIGN(datalen, ARCH_DMA_MINALIGN));
+
table_length = DIV_ROUND_UP(pccb->datalen, MAX_PRDT_ENTRY);
buf = pccb->pdata;
i = table_length;
@@ -1446,6 +1484,8 @@ static void prepare_prdt_table(struct ufs_hba *hba, 
struct scsi_cmd *pccb)
prepare_prdt_desc(&prd_table[table_length - i - 1], buf, datalen - 1);
 
req_desc->prd_table_length = table_length;
+   ufshcd_cache_flush_and_invalidate(prd_table, sizeof(*prd_table) * 
table_length);
+   ufshcd_cache_flush_and_invalidate(req_desc, sizeof(*req_desc));
 }
 
 static int ufs_scsi_exec(struct udevice *scsi_dev, struct scsi_cmd *pccb)
-- 
2.40.

[PATCH 4/6] ufs: Pass hba pointer to ufshcd_prepare_req_desc_hdr()

2023-08-13 Thread Marek Vasut
Pass the hba pointer itself to ufshcd_prepare_req_desc_hdr()
instead of duplicating utp_transfer_req_desc access at each
call site. No functional change.

Signed-off-by: Marek Vasut 
---
Cc: Faiz Abbas 
---
 drivers/ufs/ufs.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/ufs/ufs.c b/drivers/ufs/ufs.c
index 58830c8ddca..da1009e2c14 100644
--- a/drivers/ufs/ufs.c
+++ b/drivers/ufs/ufs.c
@@ -696,10 +696,11 @@ static inline u8 ufshcd_get_upmcrs(struct ufs_hba *hba)
  * ufshcd_prepare_req_desc_hdr() - Fills the requests header
  * descriptor according to request
  */
-static void ufshcd_prepare_req_desc_hdr(struct utp_transfer_req_desc *req_desc,
+static void ufshcd_prepare_req_desc_hdr(struct ufs_hba *hba,
u32 *upiu_flags,
enum dma_data_direction cmd_dir)
 {
+   struct utp_transfer_req_desc *req_desc = hba->utrdl;
u32 data_direction;
u32 dword_0;
 
@@ -793,11 +794,10 @@ static int ufshcd_comp_devman_upiu(struct ufs_hba *hba,
 {
u32 upiu_flags;
int ret = 0;
-   struct utp_transfer_req_desc *req_desc = hba->utrdl;
 
hba->dev_cmd.type = cmd_type;
 
-   ufshcd_prepare_req_desc_hdr(req_desc, &upiu_flags, DMA_NONE);
+   ufshcd_prepare_req_desc_hdr(hba, &upiu_flags, DMA_NONE);
switch (cmd_type) {
case DEV_CMD_TYPE_QUERY:
ufshcd_prepare_utp_query_req_upiu(hba, upiu_flags);
@@ -1449,12 +1449,11 @@ static void prepare_prdt_table(struct ufs_hba *hba, 
struct scsi_cmd *pccb)
 static int ufs_scsi_exec(struct udevice *scsi_dev, struct scsi_cmd *pccb)
 {
struct ufs_hba *hba = dev_get_uclass_priv(scsi_dev->parent);
-   struct utp_transfer_req_desc *req_desc = hba->utrdl;
u32 upiu_flags;
int ocs, result = 0;
u8 scsi_status;
 
-   ufshcd_prepare_req_desc_hdr(req_desc, &upiu_flags, pccb->dma_dir);
+   ufshcd_prepare_req_desc_hdr(hba, &upiu_flags, pccb->dma_dir);
ufshcd_prepare_utp_scsi_cmd_upiu(hba, pccb, upiu_flags);
prepare_prdt_table(hba, pccb);
 
-- 
2.40.1



[PATCH 3/6] ufs: Handle UFS 3.0 controllers

2023-08-13 Thread Marek Vasut
Extend the version check to handle UFS 3.0 controllers as well.
Tested on R-Car S4 UFS 3.0 controller.

Signed-off-by: Marek Vasut 
---
Cc: Faiz Abbas 
---
 drivers/ufs/ufs.c | 3 ++-
 drivers/ufs/ufs.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ufs/ufs.c b/drivers/ufs/ufs.c
index 261ae2843c2..58830c8ddca 100644
--- a/drivers/ufs/ufs.c
+++ b/drivers/ufs/ufs.c
@@ -1903,7 +1903,8 @@ int ufshcd_probe(struct udevice *ufs_dev, struct 
ufs_hba_ops *hba_ops)
if (hba->version != UFSHCI_VERSION_10 &&
hba->version != UFSHCI_VERSION_11 &&
hba->version != UFSHCI_VERSION_20 &&
-   hba->version != UFSHCI_VERSION_21)
+   hba->version != UFSHCI_VERSION_21 &&
+   hba->version != UFSHCI_VERSION_30)
dev_err(hba->dev, "invalid UFS version 0x%x\n",
hba->version);
 
diff --git a/drivers/ufs/ufs.h b/drivers/ufs/ufs.h
index 33ca5f29812..ef7728fc39e 100644
--- a/drivers/ufs/ufs.h
+++ b/drivers/ufs/ufs.h
@@ -781,6 +781,7 @@ enum {
UFSHCI_VERSION_11 = 0x00010100, /* 1.1 */
UFSHCI_VERSION_20 = 0x0200, /* 2.0 */
UFSHCI_VERSION_21 = 0x0210, /* 2.1 */
+   UFSHCI_VERSION_30 = 0x0300, /* 3.0 */
 };
 
 /* Interrupt disable masks */
-- 
2.40.1



[PATCH 1/6] ufs: Add UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS

2023-08-13 Thread Marek Vasut
Add UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS for host controllers which do not
support 64-bit addressing.

Ported from Linux kernel commit
6554400d6f66 ("scsi: ufs: core: Add UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS")
with ufs_scsi_buffer_aligned() based on U-Boot generic bounce buffer.

Signed-off-by: Marek Vasut 
---
Cc: Faiz Abbas 
---
 drivers/ufs/ufs.c | 26 ++
 drivers/ufs/ufs.h |  6 ++
 2 files changed, 32 insertions(+)

diff --git a/drivers/ufs/ufs.c b/drivers/ufs/ufs.c
index 3bf1a95e7f2..da0550d98c6 100644
--- a/drivers/ufs/ufs.c
+++ b/drivers/ufs/ufs.c
@@ -8,6 +8,7 @@
  * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -1889,6 +1890,8 @@ int ufshcd_probe(struct udevice *ufs_dev, struct 
ufs_hba_ops *hba_ops)
 
/* Read capabilties registers */
hba->capabilities = ufshcd_readl(hba, REG_CONTROLLER_CAPABILITIES);
+   if (hba->quirks & UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS)
+   hba->capabilities &= ~MASK_64_ADDRESSING_SUPPORT;
 
/* Get UFS version supported by the controller */
hba->version = ufshcd_get_ufs_version(hba);
@@ -1942,8 +1945,31 @@ int ufs_scsi_bind(struct udevice *ufs_dev, struct 
udevice **scsi_devp)
return ret;
 }
 
+#if IS_ENABLED(CONFIG_BOUNCE_BUFFER)
+static int ufs_scsi_buffer_aligned(struct udevice *scsi_dev, struct 
bounce_buffer *state)
+{
+#ifdef CONFIG_PHYS_64BIT
+   struct ufs_hba *hba = dev_get_uclass_priv(scsi_dev->parent);
+   uintptr_t ubuf = (uintptr_t)state->user_buffer;
+   size_t len = state->len_aligned;
+
+   /* Check if below 32bit boundary */
+   if ((hba->quirks & UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS) &&
+   ((ubuf >> 32) || (ubuf + len) >> 32)) {
+   dev_dbg(scsi_dev, "Buffer above 32bit boundary %lx-%lx\n",
+   ubuf, ubuf + len);
+   return 0;
+   }
+#endif
+   return 1;
+}
+#endif /* CONFIG_BOUNCE_BUFFER */
+
 static struct scsi_ops ufs_ops = {
.exec   = ufs_scsi_exec,
+#if IS_ENABLED(CONFIG_BOUNCE_BUFFER)
+   .buffer_aligned = ufs_scsi_buffer_aligned,
+#endif /* CONFIG_BOUNCE_BUFFER */
 };
 
 int ufs_probe_dev(int index)
diff --git a/drivers/ufs/ufs.h b/drivers/ufs/ufs.h
index 8a38832b05f..070db0dce68 100644
--- a/drivers/ufs/ufs.h
+++ b/drivers/ufs/ufs.h
@@ -719,6 +719,12 @@ struct ufs_hba {
  */
 #define UFSHCD_QUIRK_BROKEN_LCC0x1
 
+/*
+ * This quirk needs to be enabled if the host controller has
+ * 64-bit addressing supported capability but it doesn't work.
+ */
+#define UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS  0x2
+
/* Virtual memory reference */
struct utp_transfer_cmd_desc *ucdl;
struct utp_transfer_req_desc *utrdl;
-- 
2.40.1



[PATCH 2/6] ufs: Add UFSHCD_QUIRK_HIBERN_FASTAUTO

2023-08-13 Thread Marek Vasut
Add UFSHCD_QUIRK_HIBERN_FASTAUTO quirk for host controllers which supports
auto-hibernate the capability but only FASTAUTO mode.

Ported from Linux kernel commit
2f11bbc2c7f3 ("scsi: ufs: core: Add UFSHCD_QUIRK_HIBERN_FASTAUTO")

Signed-off-by: Marek Vasut 
---
Cc: Faiz Abbas 
---
 drivers/ufs/ufs.c | 9 +++--
 drivers/ufs/ufs.h | 6 ++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/ufs/ufs.c b/drivers/ufs/ufs.c
index da0550d98c6..261ae2843c2 100644
--- a/drivers/ufs/ufs.c
+++ b/drivers/ufs/ufs.c
@@ -1631,8 +1631,13 @@ static int ufshcd_get_max_pwr_mode(struct ufs_hba *hba)
if (hba->max_pwr_info.is_valid)
return 0;
 
-   pwr_info->pwr_tx = FAST_MODE;
-   pwr_info->pwr_rx = FAST_MODE;
+   if (hba->quirks & UFSHCD_QUIRK_HIBERN_FASTAUTO) {
+   pwr_info->pwr_tx = FASTAUTO_MODE;
+   pwr_info->pwr_rx = FASTAUTO_MODE;
+   } else {
+   pwr_info->pwr_tx = FAST_MODE;
+   pwr_info->pwr_rx = FAST_MODE;
+   }
pwr_info->hs_rate = PA_HS_MODE_B;
 
/* Get the connected lane count */
diff --git a/drivers/ufs/ufs.h b/drivers/ufs/ufs.h
index 070db0dce68..33ca5f29812 100644
--- a/drivers/ufs/ufs.h
+++ b/drivers/ufs/ufs.h
@@ -725,6 +725,12 @@ struct ufs_hba {
  */
 #define UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS  0x2
 
+/*
+ * This quirk needs to be enabled if the host controller has
+ * auto-hibernate capability but it's FASTAUTO only.
+ */
+#define UFSHCD_QUIRK_HIBERN_FASTAUTO   0x4
+
/* Virtual memory reference */
struct utp_transfer_cmd_desc *ucdl;
struct utp_transfer_req_desc *utrdl;
-- 
2.40.1



[PATCH] clk: Add GPIO-controlled clock gate driver

2023-08-13 Thread Marek Vasut
Add driver which implements GPIO-controlled clock. The GPIO is used
as a gate to enable/disable the clock. This matches linux clk-gpio.c
driver, however this does not implement the GPIO mux part, which in
U-Boot DM would be better fit in separate driver.

Signed-off-by: Marek Vasut 
---
Cc: Lukasz Majewski 
Cc: Sean Anderson 
---
 drivers/clk/Kconfig| 13 +
 drivers/clk/Makefile   |  1 +
 drivers/clk/clk-gpio.c | 66 ++
 3 files changed, 80 insertions(+)
 create mode 100644 drivers/clk/clk-gpio.c

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 29859cdfa15..bfd23a99046 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -83,6 +83,19 @@ config CLK_COMPOSITE_CCF
  Enable this option if you want to (re-)use the Linux kernel's Common
  Clock Framework [CCF] composite code in U-Boot's clock driver.
 
+config CLK_GPIO
+   bool "GPIO-controlled clock gate driver"
+   depends on CLK
+   help
+ Enable this option to add GPIO-controlled clock gate driver.
+
+config SPL_CLK_GPIO
+   bool "GPIO-controlled clock gate driver in SPL"
+   depends on SPL_CLK
+   help
+ Enable this option to add GPIO-controlled clock gate driver
+ in U-Boot SPL.
+
 config CLK_BCM6345
bool "Clock controller driver for BCM6345"
depends on CLK && ARCH_BMIPS
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index e22c8cf291f..26bf429acbc 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_$(SPL_TPL_)CLK) += clk_fixed_factor.o
 obj-$(CONFIG_$(SPL_TPL_)CLK_CCF) += clk.o clk-divider.o clk-mux.o clk-gate.o
 obj-$(CONFIG_$(SPL_TPL_)CLK_CCF) += clk-fixed-factor.o
 obj-$(CONFIG_$(SPL_TPL_)CLK_COMPOSITE_CCF) += clk-composite.o
+obj-$(CONFIG_$(SPL_TPL_)CLK_GPIO) += clk-gpio.o
 
 obj-y += analogbits/
 obj-y += imx/
diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c
new file mode 100644
index 000..26d795b9783
--- /dev/null
+++ b/drivers/clk/clk-gpio.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Marek Vasut 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+struct clk_gpio_priv {
+   struct gpio_descenable;
+};
+
+static int clk_gpio_enable(struct clk *clk)
+{
+   struct clk_gpio_priv *priv = dev_get_priv(clk->dev);
+
+   dm_gpio_set_value(&priv->enable, 1);
+
+   return 0;
+}
+
+static int clk_gpio_disable(struct clk *clk)
+{
+   struct clk_gpio_priv *priv = dev_get_priv(clk->dev);
+
+   dm_gpio_set_value(&priv->enable, 0);
+
+   return 0;
+}
+
+const struct clk_ops clk_gpio_ops = {
+   .enable = clk_gpio_enable,
+   .disable= clk_gpio_disable,
+};
+
+static int clk_gpio_probe(struct udevice *dev)
+{
+   struct clk_gpio_priv *priv = dev_get_priv(dev);
+
+   return gpio_request_by_name(dev, "enable-gpios", 0,
+   &priv->enable, GPIOD_IS_OUT);
+}
+
+/*
+ * When implementing clk-mux-clock, use gpio_request_list_by_name
+ * and implement get_rate/set_rate/set_parent ops. This should be
+ * in a separate driver and with separate Kconfig option to enable
+ * that driver, since unlike Linux implementation, the U-Boot DM
+ * integration would be orthogonal to this driver.
+ */
+static const struct udevice_id clk_gpio_match[] = {
+   { .compatible = "gpio-gate-clock" },
+   { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(gpio_gate_clock) = {
+   .name   = "gpio_clock",
+   .id = UCLASS_CLK,
+   .of_match   = clk_gpio_match,
+   .probe  = clk_gpio_probe,
+   .priv_auto  = sizeof(struct clk_gpio_priv),
+   .ops= &clk_gpio_ops,
+   .flags  = DM_FLAG_PRE_RELOC,
+};
-- 
2.40.1



[PATCH 1/2] blk: Add bounce buffer support to read/write operations

2023-08-13 Thread Marek Vasut
Some devices have limited DMA capabilities and require that the
buffers passed to them fit specific properties. Add new optional
callback which can be used at driver level to indicate whether a
buffer alignment is suitable for the device DMA or not, and
trigger use of generic bounce buffer implementation to help use
of unsuitable buffers at the expense of performance degradation.

Signed-off-by: Marek Vasut 
---
Cc: Abdellatif El Khlifi 
Cc: Bin Meng 
Cc: Heinrich Schuchardt 
Cc: Mattijs Korpershoek 
Cc: Michal Suchanek 
Cc: Simon Glass 
Cc: Tobias Waldekranz 
---
 drivers/block/blk-uclass.c | 62 --
 include/blk.h  | 19 
 2 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 6aac92d9962..885513893f6 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -446,6 +446,26 @@ int blk_get_device(int uclass_id, int devnum, struct 
udevice **devp)
return device_probe(*devp);
 }
 
+struct blk_bounce_buffer {
+   struct udevice  *dev;
+   struct bounce_bufferstate;
+};
+
+static int blk_buffer_aligned(struct bounce_buffer *state)
+{
+#if IS_ENABLED(CONFIG_BOUNCE_BUFFER)
+   struct blk_bounce_buffer *bbstate =
+   container_of(state, struct blk_bounce_buffer, state);
+   struct udevice *dev = bbstate->dev;
+   const struct blk_ops *ops = blk_get_ops(dev);
+
+   if (ops->buffer_aligned)
+   return ops->buffer_aligned(dev, state);
+#endif /* CONFIG_BOUNCE_BUFFER */
+
+   return 1;   /* Default, any buffer is OK */
+}
+
 long blk_read(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, void *buf)
 {
struct blk_desc *desc = dev_get_uclass_plat(dev);
@@ -458,7 +478,25 @@ long blk_read(struct udevice *dev, lbaint_t start, 
lbaint_t blkcnt, void *buf)
if (blkcache_read(desc->uclass_id, desc->devnum,
  start, blkcnt, desc->blksz, buf))
return blkcnt;
-   blks_read = ops->read(dev, start, blkcnt, buf);
+
+   if (IS_ENABLED(CONFIG_BOUNCE_BUFFER)) {
+   struct blk_bounce_buffer bbstate = { .dev = dev };
+   int ret;
+
+   ret = bounce_buffer_start_extalign(&bbstate.state, buf,
+  blkcnt * desc->blksz,
+  GEN_BB_WRITE, desc->blksz,
+  blk_buffer_aligned);
+   if (ret)
+   return ret;
+
+   blks_read = ops->read(dev, start, blkcnt, 
bbstate.state.bounce_buffer);
+
+   bounce_buffer_stop(&bbstate.state);
+   } else {
+   blks_read = ops->read(dev, start, blkcnt, buf);
+   }
+
if (blks_read == blkcnt)
blkcache_fill(desc->uclass_id, desc->devnum, start, blkcnt,
  desc->blksz, buf);
@@ -471,13 +509,33 @@ long blk_write(struct udevice *dev, lbaint_t start, 
lbaint_t blkcnt,
 {
struct blk_desc *desc = dev_get_uclass_plat(dev);
const struct blk_ops *ops = blk_get_ops(dev);
+   long blks_written;
 
if (!ops->write)
return -ENOSYS;
 
blkcache_invalidate(desc->uclass_id, desc->devnum);
 
-   return ops->write(dev, start, blkcnt, buf);
+   if (IS_ENABLED(CONFIG_BOUNCE_BUFFER)) {
+   struct blk_bounce_buffer bbstate = { .dev = dev };
+   int ret;
+
+   ret = bounce_buffer_start_extalign(&bbstate.state, (void *)buf,
+  blkcnt * desc->blksz,
+  GEN_BB_READ, desc->blksz,
+  blk_buffer_aligned);
+   if (ret)
+   return ret;
+
+   blks_written = ops->write(dev, start, blkcnt,
+ bbstate.state.bounce_buffer);
+
+   bounce_buffer_stop(&bbstate.state);
+   } else {
+   blks_written = ops->write(dev, start, blkcnt, buf);
+   }
+
+   return blks_written;
 }
 
 long blk_erase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt)
diff --git a/include/blk.h b/include/blk.h
index 8986e953e5a..b819f97c2f1 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -7,6 +7,7 @@
 #ifndef BLK_H
 #define BLK_H
 
+#include 
 #include 
 #include 
 
@@ -260,6 +261,24 @@ struct blk_ops {
 * @return 0 if OK, -ve on error
 */
int (*select_hwpart)(struct udevice *dev, int hwpart);
+
+#if IS_ENABLED(CONFIG_BOUNCE_BUFFER)
+   /**
+* buffer_aligned() - test memory alignment of block operation buffer
+*
+* Some devices have limited DMA capabilities and require that the
+* buffers passed to them fit specific properties. This optional
+* callback can be used to indicate wh

[PATCH 2/2] scsi: Add buffer_aligned check pass-through

2023-08-13 Thread Marek Vasut
Some devices have limited DMA capabilities and require that the
buffers passed to them fit specific properties. Add new optional
callback which can be used at driver level to indicate whether a
buffer alignment is suitable for the device DMA or not. This is
a pass-through callback from block uclass to drivers.

Signed-off-by: Marek Vasut 
---
Cc: Abdellatif El Khlifi 
Cc: Bin Meng 
Cc: Heinrich Schuchardt 
Cc: Mattijs Korpershoek 
Cc: Michal Suchanek 
Cc: Simon Glass 
Cc: Tobias Waldekranz 
---
 drivers/scsi/scsi.c | 15 +++
 include/scsi.h  | 19 +++
 2 files changed, 34 insertions(+)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 6498f998ad6..7411660d465 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -274,6 +274,18 @@ static ulong scsi_write(struct udevice *dev, lbaint_t 
blknr, lbaint_t blkcnt,
  __func__, start, smallblks, buf_addr);
return blkcnt;
 }
+
+#if IS_ENABLED(CONFIG_BOUNCE_BUFFER)
+static int scsi_buffer_aligned(struct udevice *dev, struct bounce_buffer 
*state)
+{
+   struct scsi_ops *ops = scsi_get_ops(dev->parent);
+
+   if (ops->buffer_aligned)
+   return ops->buffer_aligned(dev->parent, state);
+
+   return 1;
+}
+#endif /* CONFIG_BOUNCE_BUFFER */
 #endif
 
 #if defined(CONFIG_PCI) && !defined(CONFIG_SCSI_AHCI_PLAT) && \
@@ -720,6 +732,9 @@ int scsi_scan(bool verbose)
 static const struct blk_ops scsi_blk_ops = {
.read   = scsi_read,
.write  = scsi_write,
+#if IS_ENABLED(CONFIG_BOUNCE_BUFFER)
+   .buffer_aligned = scsi_buffer_aligned,
+#endif /* CONFIG_BOUNCE_BUFFER */
 };
 
 U_BOOT_DRIVER(scsi_blk) = {
diff --git a/include/scsi.h b/include/scsi.h
index 9efefea99bb..ee9d622680d 100644
--- a/include/scsi.h
+++ b/include/scsi.h
@@ -7,6 +7,7 @@
  #define _SCSI_H
 
 #include 
+#include 
 #include 
 
 /* Fix this to the maximum */
@@ -298,6 +299,24 @@ struct scsi_ops {
 * @return 0 if OK, -ve on error
 */
int (*bus_reset)(struct udevice *dev);
+
+#if IS_ENABLED(CONFIG_BOUNCE_BUFFER)
+   /**
+* buffer_aligned() - test memory alignment of block operation buffer
+*
+* Some devices have limited DMA capabilities and require that the
+* buffers passed to them fit specific properties. This optional
+* callback can be used to indicate whether a buffer alignment is
+* suitable for the device DMA or not, and trigger use of generic
+* bounce buffer implementation to help use of unsuitable buffers
+* at the expense of performance degradation.
+*
+* @dev:Block device associated with the request
+* @state:  Bounce buffer state
+* @return 1 if OK, 0 if unaligned
+*/
+   int (*buffer_aligned)(struct udevice *dev, struct bounce_buffer *state);
+#endif /* CONFIG_BOUNCE_BUFFER */
 };
 
 #define scsi_get_ops(dev)((struct scsi_ops *)(dev)->driver->ops)
-- 
2.40.1



[PATCH] disk: dos: Infer MBR partition sector size from underlying drive sector size

2023-08-13 Thread Marek Vasut
Block devices with 4k sectors imply the MBR sectors are also 4k instead
of regular 512B. Avoid hard-coding the 512B sector size and isntead read
the current block device sector size from it, and if the sector size is
larger than 512B, use the block device sector size.

Signed-off-by: Marek Vasut 
---
Cc: Simon Glass 
---
 disk/part_dos.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 56e61884def..1b81297d967 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -207,8 +207,9 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
  struct disk_partition *info, uint disksig)
 {
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
+   struct disk_partition wdinfo = { 0 };
dos_partition_t *pt;
-   int i;
+   int i, ret;
int dos_type;
 
/* set a maximum recursion level */
@@ -236,6 +237,10 @@ static int part_get_info_extended(struct blk_desc 
*dev_desc,
disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]);
 #endif
 
+   ret = part_get_info_whole_disk(dev_desc, &wdinfo);
+   if (ret)
+   return ret;
+
/* Print all primary/logical partitions */
pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
for (i = 0; i < 4; i++, pt++) {
@@ -247,7 +252,10 @@ static int part_get_info_extended(struct blk_desc 
*dev_desc,
(pt->sys_ind != 0) &&
(part_num == which_part) &&
(ext_part_sector == 0 || is_extended(pt->sys_ind) == 0)) {
-   info->blksz = DOS_PART_DEFAULT_SECTOR;
+   if (wdinfo.blksz > DOS_PART_DEFAULT_SECTOR)
+   info->blksz = wdinfo.blksz;
+   else
+   info->blksz = DOS_PART_DEFAULT_SECTOR;
info->start = (lbaint_t)(ext_part_sector +
get_unaligned_le32(pt->start4));
info->size  = (lbaint_t)get_unaligned_le32(pt->size4);
@@ -289,7 +297,10 @@ static int part_get_info_extended(struct blk_desc 
*dev_desc,
if (dos_type == DOS_PBR) {
info->start = 0;
info->size = dev_desc->lba;
-   info->blksz = DOS_PART_DEFAULT_SECTOR;
+   if (wdinfo.blksz > DOS_PART_DEFAULT_SECTOR)
+   info->blksz = wdinfo.blksz;
+   else
+   info->blksz = DOS_PART_DEFAULT_SECTOR;
info->bootable = 0;
strcpy((char *)info->type, "U-Boot");
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
-- 
2.40.1



[PATCH] common: bouncebuf: Add missing cast to dma_addr_t

2023-08-13 Thread Marek Vasut
Fix the following warning produced on qemu-x86_64_defconfig:

"
common/bouncebuf.c: In function ‘bounce_buffer_stop’:
common/bouncebuf.c:82:34: warning: cast from pointer to integer of different 
size [-Wpointer-to-int-cast]
   82 | dma_unmap_single((dma_addr_t)state->bounce_buffer,
  |  ^
"

The warning is valid, the pointer has to be up-cast first.

Signed-off-by: Marek Vasut 
---
Cc: Andrew Davis 
Cc: Simon Glass 
---
 common/bouncebuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/bouncebuf.c b/common/bouncebuf.c
index 93a35668cc2..934b83f7ec3 100644
--- a/common/bouncebuf.c
+++ b/common/bouncebuf.c
@@ -79,7 +79,7 @@ int bounce_buffer_stop(struct bounce_buffer *state)
 {
if (state->flags & GEN_BB_WRITE) {
/* Invalidate cache so that CPU can see any newly DMA'd data */
-   dma_unmap_single((dma_addr_t)state->bounce_buffer,
+   dma_unmap_single((dma_addr_t)(uintptr_t)state->bounce_buffer,
 state->len_aligned,
 DMA_BIDIRECTIONAL);
}
-- 
2.40.1



[PATCH 5/8] disk: Extend disk_blk_part_validate() with range checking

2023-08-13 Thread Marek Vasut
Check whether access is out of bounds of the partition and
return an error. This way there is no danger of esp. write
or erase outside of the confines of partition.

Signed-off-by: Marek Vasut 
---
Cc: AKASHI Takahiro 
Cc: Abdellatif El Khlifi 
Cc: Bin Meng 
Cc: Heinrich Schuchardt 
Cc: Joshua Watt 
Cc: Michal Suchanek 
Cc: Simon Glass 
Cc: Tobias Waldekranz 
---
 disk/disk-uclass.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index 32722cf9176..f262105375b 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -27,9 +27,17 @@
  */
 static int disk_blk_part_validate(struct udevice *dev, lbaint_t start, 
lbaint_t blkcnt)
 {
+   struct disk_part *part = dev_get_uclass_plat(dev);
+
if (device_get_uclass_id(dev) != UCLASS_PARTITION)
return -ENOSYS;
 
+   if (start >= part->gpt_part_info.size)
+   return -E2BIG;
+
+   if ((start + blkcnt) > part->gpt_part_info.size)
+   return -ERANGE;
+
return 0;
 }
 
-- 
2.40.1



[PATCH 8/8] disk: Make blk_get_ops() internal to blk uclass

2023-08-13 Thread Marek Vasut
Move the macro into blk-uclass.c , since it is only used there.

Signed-off-by: Marek Vasut 
---
Cc: AKASHI Takahiro 
Cc: Abdellatif El Khlifi 
Cc: Bin Meng 
Cc: Heinrich Schuchardt 
Cc: Joshua Watt 
Cc: Michal Suchanek 
Cc: Simon Glass 
Cc: Tobias Waldekranz 
---
 drivers/block/blk-uclass.c | 2 ++
 include/blk.h  | 2 --
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 9521b3eb878..6aac92d9962 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -17,6 +17,8 @@
 #include 
 #include 
 
+#define blk_get_ops(dev)   ((struct blk_ops *)(dev)->driver->ops)
+
 static struct {
enum uclass_id id;
const char *name;
diff --git a/include/blk.h b/include/blk.h
index 2c9c7985a88..8986e953e5a 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -262,8 +262,6 @@ struct blk_ops {
int (*select_hwpart)(struct udevice *dev, int hwpart);
 };
 
-#define blk_get_ops(dev)   ((struct blk_ops *)(dev)->driver->ops)
-
 /*
  * These functions should take struct udevice instead of struct blk_desc,
  * but this is convenient for migration to driver model. Add a 'd' prefix
-- 
2.40.1



[PATCH 4/8] disk: Handle partition to block device offset conversion

2023-08-13 Thread Marek Vasut
Convert the read/write/erase offset from one within a partition
to one within a block device, to correctly access the data on
the block device for both write and erase operations.

Signed-off-by: Marek Vasut 
---
Cc: AKASHI Takahiro 
Cc: Abdellatif El Khlifi 
Cc: Bin Meng 
Cc: Heinrich Schuchardt 
Cc: Joshua Watt 
Cc: Michal Suchanek 
Cc: Simon Glass 
Cc: Tobias Waldekranz 
---
 disk/disk-uclass.c | 68 +++---
 1 file changed, 52 insertions(+), 16 deletions(-)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index 5cb1594e015..32722cf9176 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -17,6 +17,36 @@
 #include 
 #include 
 
+/**
+ * disk_blk_part_validate() - Check whether access to partition is within 
limits
+ *
+ * @dev: Device (partition udevice)
+ * @start: Start block for the access(from start of partition)
+ * @blkcnt: Number of blocks to access (within the partition)
+ * @return 0 on valid block range, or -ve on error.
+ */
+static int disk_blk_part_validate(struct udevice *dev, lbaint_t start, 
lbaint_t blkcnt)
+{
+   if (device_get_uclass_id(dev) != UCLASS_PARTITION)
+   return -ENOSYS;
+
+   return 0;
+}
+
+/**
+ * disk_blk_part_offset() - Compute offset from start of block device
+ *
+ * @dev: Device (partition udevice)
+ * @start: Start block for the access (from start of partition)
+ * @return Start block for the access (from start of block device)
+ */
+static lbaint_t disk_blk_part_offset(struct udevice *dev, lbaint_t start)
+{
+   struct disk_part *part = dev_get_uclass_plat(dev);
+
+   return start + part->gpt_part_info.start;
+}
+
 int part_create_block_devices(struct udevice *blk_dev)
 {
int part, count;
@@ -162,21 +192,21 @@ U_BOOT_DRIVER(blk_partition) = {
 unsigned long disk_blk_read(struct udevice *dev, lbaint_t start,
lbaint_t blkcnt, void *buffer)
 {
-   struct disk_part *part = dev_get_uclass_plat(dev);
+   int ret = disk_blk_part_validate(dev, start, blkcnt);
 
-   if (device_get_uclass_id(dev) != UCLASS_PARTITION)
-   return -ENOSYS;
+   if (ret)
+   return ret;
 
-   return blk_read(dev_get_parent(dev), start + part->gpt_part_info.start,
+   return blk_read(dev_get_parent(dev), disk_blk_part_offset(dev, start),
blkcnt, buffer);
 }
 
 /**
  * disk_blk_write() - Write to a block device
  *
- * @dev: Device to write to
- * @start: Start block for the write
- * @blkcnt: Number of blocks to write
+ * @dev: Device to write to (partition udevice)
+ * @start: Start block for the write (from start of partition)
+ * @blkcnt: Number of blocks to write (within the partition)
  * @buffer: Data to write
  * @return number of blocks written (which may be less than @blkcnt),
  * or -ve on error. This never returns 0 unless @blkcnt is 0
@@ -184,28 +214,34 @@ 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)
 {
-   if (device_get_uclass_id(dev) != UCLASS_PARTITION)
-   return -ENOSYS;
+   int ret = disk_blk_part_validate(dev, start, blkcnt);
+
+   if (ret)
+   return ret;
 
-   return blk_write(dev_get_parent(dev), start, blkcnt, buffer);
+   return blk_write(dev_get_parent(dev), disk_blk_part_offset(dev, start),
+blkcnt, buffer);
 }
 
 /**
  * disk_blk_erase() - Erase part of a block device
  *
- * @dev: Device to erase
- * @start: Start block for the erase
- * @blkcnt: Number of blocks to erase
+ * @dev: Device to erase (partition udevice)
+ * @start: Start block for the erase (from start of partition)
+ * @blkcnt: Number of blocks to erase (within the partition)
  * @return number of blocks erased (which may be less than @blkcnt),
  * or -ve on error. This never returns 0 unless @blkcnt is 0
  */
 unsigned long disk_blk_erase(struct udevice *dev, lbaint_t start,
 lbaint_t blkcnt)
 {
-   if (device_get_uclass_id(dev) != UCLASS_PARTITION)
-   return -ENOSYS;
+   int ret = disk_blk_part_validate(dev, start, blkcnt);
+
+   if (ret)
+   return ret;
 
-   return blk_erase(dev_get_parent(dev), start, blkcnt);
+   return blk_erase(dev_get_parent(dev), disk_blk_part_offset(dev, start),
+blkcnt);
 }
 
 UCLASS_DRIVER(partition) = {
-- 
2.40.1



[PATCH 7/8] disk: Move part_create_block_devices() to blk uclass

2023-08-13 Thread Marek Vasut
Move part_create_block_devices() to blk uclass and unexpose
the function. This can now be internal to the block uclass.

Signed-off-by: Marek Vasut 
---
Cc: AKASHI Takahiro 
Cc: Abdellatif El Khlifi 
Cc: Bin Meng 
Cc: Heinrich Schuchardt 
Cc: Joshua Watt 
Cc: Michal Suchanek 
Cc: Simon Glass 
Cc: Tobias Waldekranz 
---
 disk/disk-uclass.c | 48 --
 drivers/block/blk-uclass.c | 48 ++
 include/part.h |  9 ---
 3 files changed, 48 insertions(+), 57 deletions(-)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index 90a7c6f0f8a..efe4bf1f949 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -55,54 +55,6 @@ static lbaint_t disk_blk_part_offset(struct udevice *dev, 
lbaint_t start)
return start + part->gpt_part_info.start;
 }
 
-int part_create_block_devices(struct udevice *blk_dev)
-{
-   int part, count;
-   struct blk_desc *desc = dev_get_uclass_plat(blk_dev);
-   struct disk_partition info;
-   struct disk_part *part_data;
-   char devname[32];
-   struct udevice *dev;
-   int ret;
-
-   if (!CONFIG_IS_ENABLED(PARTITIONS) || !blk_enabled())
-   return 0;
-
-   if (device_get_uclass_id(blk_dev) != UCLASS_BLK)
-   return 0;
-
-   /* Add devices for each partition */
-   for (count = 0, part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
-   if (part_get_info(desc, part, &info))
-   continue;
-   snprintf(devname, sizeof(devname), "%s:%d", blk_dev->name,
-part);
-
-   ret = device_bind_driver(blk_dev, "blk_partition",
-strdup(devname), &dev);
-   if (ret)
-   return ret;
-
-   part_data = dev_get_uclass_plat(dev);
-   part_data->partnum = part;
-   part_data->gpt_part_info = info;
-   count++;
-
-   ret = device_probe(dev);
-   if (ret) {
-   debug("Can't probe\n");
-   count--;
-   device_unbind(dev);
-
-   continue;
-   }
-   }
-   debug("%s: %d partitions found in %s\n", __func__, count,
- blk_dev->name);
-
-   return 0;
-}
-
 /*
  * BLOCK IO APIs
  */
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 614b975e25c..9521b3eb878 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -766,6 +766,54 @@ int blk_unbind_all(int uclass_id)
return 0;
 }
 
+static int part_create_block_devices(struct udevice *blk_dev)
+{
+   int part, count;
+   struct blk_desc *desc = dev_get_uclass_plat(blk_dev);
+   struct disk_partition info;
+   struct disk_part *part_data;
+   char devname[32];
+   struct udevice *dev;
+   int ret;
+
+   if (!CONFIG_IS_ENABLED(PARTITIONS) || !blk_enabled())
+   return 0;
+
+   if (device_get_uclass_id(blk_dev) != UCLASS_BLK)
+   return 0;
+
+   /* Add devices for each partition */
+   for (count = 0, part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
+   if (part_get_info(desc, part, &info))
+   continue;
+   snprintf(devname, sizeof(devname), "%s:%d", blk_dev->name,
+part);
+
+   ret = device_bind_driver(blk_dev, "blk_partition",
+strdup(devname), &dev);
+   if (ret)
+   return ret;
+
+   part_data = dev_get_uclass_plat(dev);
+   part_data->partnum = part;
+   part_data->gpt_part_info = info;
+   count++;
+
+   ret = device_probe(dev);
+   if (ret) {
+   debug("Can't probe\n");
+   count--;
+   device_unbind(dev);
+
+   continue;
+   }
+   }
+   debug("%s: %d partitions found in %s\n", __func__, count,
+ blk_dev->name);
+
+   return 0;
+}
+
 static int blk_post_probe(struct udevice *dev)
 {
if (CONFIG_IS_ENABLED(PARTITIONS) && blk_enabled()) {
diff --git a/include/part.h b/include/part.h
index edc46f8dcbe..74e4d42263e 100644
--- a/include/part.h
+++ b/include/part.h
@@ -306,15 +306,6 @@ part_get_info_by_dev_and_name_or_num(const char *dev_iface,
 int part_get_bootable(struct blk_desc *desc);
 
 struct udevice;
-/**
- * part_create_block_devices - Create block devices for disk partitions
- *
- * Create UCLASS_PARTITION udevices for each of disk partitions in @parent
- *
- * @blk_dev:   Whole disk device
- */
-int part_create_block_devices(struct udevice *blk_dev);
-
 /**
  * disk_blk_read() - read blocks from a disk partition
  *
-- 
2.40.1



[PATCH 6/8] disk: Switch part_blk_*() functions to disk_blk_*()

2023-08-13 Thread Marek Vasut
The behavior of the part_blk_*() functions is now identical
to disk_blk_*() functions, switch the former to the later.

Signed-off-by: Marek Vasut 
---
Cc: AKASHI Takahiro 
Cc: Abdellatif El Khlifi 
Cc: Bin Meng 
Cc: Heinrich Schuchardt 
Cc: Joshua Watt 
Cc: Michal Suchanek 
Cc: Simon Glass 
Cc: Tobias Waldekranz 
---
 disk/disk-uclass.c | 93 ++
 1 file changed, 12 insertions(+), 81 deletions(-)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index f262105375b..90a7c6f0f8a 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -103,87 +103,6 @@ int part_create_block_devices(struct udevice *blk_dev)
return 0;
 }
 
-static ulong part_blk_read(struct udevice *dev, lbaint_t start,
-  lbaint_t blkcnt, void *buffer)
-{
-   struct udevice *parent;
-   struct disk_part *part;
-   const struct blk_ops *ops;
-
-   parent = dev_get_parent(dev);
-   ops = blk_get_ops(parent);
-   if (!ops->read)
-   return -ENOSYS;
-
-   part = dev_get_uclass_plat(dev);
-   if (start >= part->gpt_part_info.size)
-   return 0;
-
-   if ((start + blkcnt) > part->gpt_part_info.size)
-   blkcnt = part->gpt_part_info.size - start;
-   start += part->gpt_part_info.start;
-
-   return ops->read(parent, start, blkcnt, buffer);
-}
-
-static ulong part_blk_write(struct udevice *dev, lbaint_t start,
-   lbaint_t blkcnt, const void *buffer)
-{
-   struct udevice *parent;
-   struct disk_part *part;
-   const struct blk_ops *ops;
-
-   parent = dev_get_parent(dev);
-   ops = blk_get_ops(parent);
-   if (!ops->write)
-   return -ENOSYS;
-
-   part = dev_get_uclass_plat(dev);
-   if (start >= part->gpt_part_info.size)
-   return 0;
-
-   if ((start + blkcnt) > part->gpt_part_info.size)
-   blkcnt = part->gpt_part_info.size - start;
-   start += part->gpt_part_info.start;
-
-   return ops->write(parent, start, blkcnt, buffer);
-}
-
-static ulong part_blk_erase(struct udevice *dev, lbaint_t start,
-   lbaint_t blkcnt)
-{
-   struct udevice *parent;
-   struct disk_part *part;
-   const struct blk_ops *ops;
-
-   parent = dev_get_parent(dev);
-   ops = blk_get_ops(parent);
-   if (!ops->erase)
-   return -ENOSYS;
-
-   part = dev_get_uclass_plat(dev);
-   if (start >= part->gpt_part_info.size)
-   return 0;
-
-   if ((start + blkcnt) > part->gpt_part_info.size)
-   blkcnt = part->gpt_part_info.size - start;
-   start += part->gpt_part_info.start;
-
-   return ops->erase(parent, start, blkcnt);
-}
-
-static const struct blk_ops blk_part_ops = {
-   .read   = part_blk_read,
-   .write  = part_blk_write,
-   .erase  = part_blk_erase,
-};
-
-U_BOOT_DRIVER(blk_partition) = {
-   .name   = "blk_partition",
-   .id = UCLASS_PARTITION,
-   .ops= &blk_part_ops,
-};
-
 /*
  * BLOCK IO APIs
  */
@@ -257,3 +176,15 @@ UCLASS_DRIVER(partition) = {
.per_device_plat_auto   = sizeof(struct disk_part),
.name   = "partition",
 };
+
+static const struct blk_ops blk_part_ops = {
+   .read   = disk_blk_read,
+   .write  = disk_blk_write,
+   .erase  = disk_blk_erase,
+};
+
+U_BOOT_DRIVER(blk_partition) = {
+   .name   = "blk_partition",
+   .id = UCLASS_PARTITION,
+   .ops= &blk_part_ops,
+};
-- 
2.40.1



[PATCH 3/8] disk: Simplify disk_blk_{write, erase}() using blk_{write, erase}()

2023-08-13 Thread Marek Vasut
These two functions are basically identical, just call the blk_*()
functions from disk_blk_*() functions. The only difference is that
the disk_blk_*() functions have to use parent block device as the
udevice implementing block device operations.

Add documentation on what those functions really do. The documentation
is not wrong even though it likely does look that way. The write/erase
functions really do not take into account the partition offset. This
will be fixed in the next patch.

Signed-off-by: Marek Vasut 
---
Cc: AKASHI Takahiro 
Cc: Abdellatif El Khlifi 
Cc: Bin Meng 
Cc: Heinrich Schuchardt 
Cc: Joshua Watt 
Cc: Michal Suchanek 
Cc: Simon Glass 
Cc: Tobias Waldekranz 
---
 disk/disk-uclass.c | 66 --
 1 file changed, 23 insertions(+), 43 deletions(-)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index 6daece1288f..5cb1594e015 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -149,25 +149,6 @@ U_BOOT_DRIVER(blk_partition) = {
 /*
  * BLOCK IO APIs
  */
-static struct blk_desc *dev_get_blk(struct udevice *dev)
-{
-   struct blk_desc *desc;
-
-   switch (device_get_uclass_id(dev)) {
-   /*
-* We won't support UCLASS_BLK with dev_* interfaces.
-*/
-   case UCLASS_PARTITION:
-   desc = dev_get_uclass_plat(dev_get_parent(dev));
-   break;
-   default:
-   desc = NULL;
-   break;
-   }
-
-   return desc;
-}
-
 /**
  * disk_blk_read() - Read from a block device partition
  *
@@ -190,42 +171,41 @@ unsigned long disk_blk_read(struct udevice *dev, lbaint_t 
start,
blkcnt, buffer);
 }
 
+/**
+ * disk_blk_write() - Write to a block device
+ *
+ * @dev: Device to write to
+ * @start: Start block for the write
+ * @blkcnt: Number of blocks to write
+ * @buffer: Data to write
+ * @return number of blocks written (which may be less than @blkcnt),
+ * or -ve on error. This never returns 0 unless @blkcnt is 0
+ */
 unsigned long disk_blk_write(struct udevice *dev, lbaint_t start,
 lbaint_t blkcnt, const void *buffer)
 {
-   struct blk_desc *desc;
-   const struct blk_ops *ops;
-
-   desc = dev_get_blk(dev);
-   if (!desc)
-   return -ENOSYS;
-
-   ops = blk_get_ops(dev);
-   if (!ops->write)
+   if (device_get_uclass_id(dev) != UCLASS_PARTITION)
return -ENOSYS;
 
-   blkcache_invalidate(desc->uclass_id, desc->devnum);
-
-   return ops->write(dev, start, blkcnt, buffer);
+   return blk_write(dev_get_parent(dev), start, blkcnt, buffer);
 }
 
+/**
+ * disk_blk_erase() - Erase part of a block device
+ *
+ * @dev: Device to erase
+ * @start: Start block for the erase
+ * @blkcnt: Number of blocks to erase
+ * @return number of blocks erased (which may be less than @blkcnt),
+ * or -ve on error. This never returns 0 unless @blkcnt is 0
+ */
 unsigned long disk_blk_erase(struct udevice *dev, lbaint_t start,
 lbaint_t blkcnt)
 {
-   struct blk_desc *desc;
-   const struct blk_ops *ops;
-
-   desc = dev_get_blk(dev);
-   if (!desc)
-   return -ENOSYS;
-
-   ops = blk_get_ops(dev);
-   if (!ops->erase)
+   if (device_get_uclass_id(dev) != UCLASS_PARTITION)
return -ENOSYS;
 
-   blkcache_invalidate(desc->uclass_id, desc->devnum);
-
-   return ops->erase(dev, start, blkcnt);
+   return blk_erase(dev_get_parent(dev), start, blkcnt);
 }
 
 UCLASS_DRIVER(partition) = {
-- 
2.40.1



[PATCH 2/8] disk: Simplify disk_blk_read() using blk_read()

2023-08-13 Thread Marek Vasut
The disk_blk_read() can be simplified using blk_read(), the only
things which needs to be handled are the read offset based on the
partition properties, and the block device ops which are coming
from the parent udevice, not the partition udevice.

The later is currently not implemented correctly as far as I can
tell, since the current code extracts block device descriptor from
the parent udevice which is OK, but extracts block device operations
from the partition udevice, which does not seem OK.

Switching to the blk_read() fixes that too.

The dev_get_blk() usage is simplified using UCLASS_PARTITION check.

Add non-confusing documentation what this really does.

Signed-off-by: Marek Vasut 
---
Cc: AKASHI Takahiro 
Cc: Abdellatif El Khlifi 
Cc: Bin Meng 
Cc: Heinrich Schuchardt 
Cc: Joshua Watt 
Cc: Michal Suchanek 
Cc: Simon Glass 
Cc: Tobias Waldekranz 
---
 disk/disk-uclass.c | 38 ++
 1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index 5974dd8c2ec..6daece1288f 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -168,36 +168,26 @@ static struct blk_desc *dev_get_blk(struct udevice *dev)
return desc;
 }
 
+/**
+ * disk_blk_read() - Read from a block device partition
+ *
+ * @dev: Device to read from (partition udevice)
+ * @start: Start block for the read (from start of partition)
+ * @blkcnt: Number of blocks to read (within the partition)
+ * @buffer: 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 @blkcnt is 0
+ */
 unsigned long disk_blk_read(struct udevice *dev, lbaint_t start,
lbaint_t blkcnt, void *buffer)
 {
-   struct blk_desc *desc;
-   const struct blk_ops *ops;
-   struct disk_part *part;
-   lbaint_t start_in_disk;
-   ulong blks_read;
-
-   desc = dev_get_blk(dev);
-   if (!desc)
-   return -ENOSYS;
+   struct disk_part *part = dev_get_uclass_plat(dev);
 
-   ops = blk_get_ops(dev);
-   if (!ops->read)
+   if (device_get_uclass_id(dev) != UCLASS_PARTITION)
return -ENOSYS;
 
-   start_in_disk = start;
-   part = dev_get_uclass_plat(dev);
-   start_in_disk += part->gpt_part_info.start;
-
-   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(desc->uclass_id, desc->devnum, start_in_disk,
- blkcnt, desc->blksz, buffer);
-
-   return blks_read;
+   return blk_read(dev_get_parent(dev), start + part->gpt_part_info.start,
+   blkcnt, buffer);
 }
 
 unsigned long disk_blk_write(struct udevice *dev, lbaint_t start,
-- 
2.40.1



[PATCH 1/8] disk: Drop always true conditional check

2023-08-13 Thread Marek Vasut
if (device_get_uclass_id(dev) == UCLASS_PARTITION) is always
true, because this disk_blk_read() function calls dev_get_blk()
above and checks its return value for non-NULL. The dev_get_blk()
performs the same device_get_uclass_id(dev) check and returns NULL
if not UCLASS_PARTITION. Drop the duplicate check.

Signed-off-by: Marek Vasut 
---
Cc: AKASHI Takahiro 
Cc: Abdellatif El Khlifi 
Cc: Bin Meng 
Cc: Heinrich Schuchardt 
Cc: Joshua Watt 
Cc: Michal Suchanek 
Cc: Simon Glass 
Cc: Tobias Waldekranz 
---
 disk/disk-uclass.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index d32747e2242..5974dd8c2ec 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -186,10 +186,8 @@ unsigned long disk_blk_read(struct udevice *dev, lbaint_t 
start,
return -ENOSYS;
 
start_in_disk = start;
-   if (device_get_uclass_id(dev) == UCLASS_PARTITION) {
-   part = dev_get_uclass_plat(dev);
-   start_in_disk += part->gpt_part_info.start;
-   }
+   part = dev_get_uclass_plat(dev);
+   start_in_disk += part->gpt_part_info.start;
 
if (blkcache_read(desc->uclass_id, desc->devnum, start_in_disk, blkcnt,
  desc->blksz, buffer))
-- 
2.40.1



[PATCH 2/2] configs: sandbox: test: dm: blk: Enable NVMXIP QSPI and update test

2023-08-13 Thread Marek Vasut
Enable NVMXIP QSPI driver on sandbox, since it is already enabled
on sandbox64. Update blk tests to match.

Signed-off-by: Marek Vasut 
---
Cc: Abdellatif El Khlifi 
Cc: Simon Glass 
---
 configs/sandbox_defconfig |  1 +
 test/dm/blk.c | 63 +++
 2 files changed, 52 insertions(+), 12 deletions(-)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 1cd1c2ed7cd..f451a94362e 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -227,6 +227,7 @@ CONFIG_SPI_FLASH_SPANSION=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_SST=y
 CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_NVMXIP_QSPI=y
 CONFIG_MULTIPLEXER=y
 CONFIG_MUX_MMIO=y
 CONFIG_NVME_PCI=y
diff --git a/test/dm/blk.c b/test/dm/blk.c
index 446c4423e6f..d268a441c99 100644
--- a/test/dm/blk.c
+++ b/test/dm/blk.c
@@ -82,12 +82,12 @@ static int dm_test_blk_usb(struct unit_test_state *uts)
ut_asserteq_ptr(usb_dev, dev_get_parent(dev));
 
/* Check we have one block device for each mass storage device */
-   ut_asserteq(6, count_blk_devices());
+   ut_asserteq(8, count_blk_devices());
 
/* Now go around again, making sure the old devices were unbound */
ut_assertok(usb_stop());
ut_assertok(usb_init());
-   ut_asserteq(6, count_blk_devices());
+   ut_asserteq(8, count_blk_devices());
ut_assertok(usb_stop());
 
return 0;
@@ -184,6 +184,10 @@ static int dm_test_blk_iter(struct unit_test_state *uts)
 */
ut_assertok(blk_first_device_err(BLKF_FIXED, &dev));
ut_asserteq_str("mmc2.blk", dev->name);
+   ut_assertok(blk_next_device_err(BLKF_FIXED, &dev));
+   ut_asserteq_str("nvmxip-qs...@0800.blk#1", dev->name);
+   ut_assertok(blk_next_device_err(BLKF_FIXED, &dev));
+   ut_asserteq_str("nvmxip-qs...@0820.blk#2", dev->name);
ut_asserteq(-ENODEV, blk_next_device_err(BLKF_FIXED, &dev));
 
ut_assertok(blk_first_device_err(BLKF_REMOVABLE, &dev));
@@ -198,16 +202,23 @@ static int dm_test_blk_iter(struct unit_test_state *uts)
ut_asserteq_str("mmc1.blk", dev->name);
ut_assertok(blk_next_device_err(BLKF_BOTH, &dev));
ut_asserteq_str("mmc0.blk", dev->name);
+   ut_assertok(blk_next_device_err(BLKF_BOTH, &dev));
+   ut_asserteq_str("nvmxip-qs...@0800.blk#1", dev->name);
+   ut_assertok(blk_next_device_err(BLKF_BOTH, &dev));
+   ut_asserteq_str("nvmxip-qs...@0820.blk#2", dev->name);
ut_asserteq(-ENODEV, blk_next_device_err(BLKF_FIXED, &dev));
 
-   ut_asserteq(1, blk_count_devices(BLKF_FIXED));
+   ut_asserteq(3, blk_count_devices(BLKF_FIXED));
ut_asserteq(2, blk_count_devices(BLKF_REMOVABLE));
-   ut_asserteq(3, blk_count_devices(BLKF_BOTH));
+   ut_asserteq(5, blk_count_devices(BLKF_BOTH));
 
i = 0;
blk_foreach_probe(BLKF_FIXED, dev)
-   ut_asserteq_str((i++, "mmc2.blk"), dev->name);
-   ut_asserteq(1, i);
+   ut_asserteq_str((++i == 1 ? "mmc2.blk" :
+   i == 2 ? "nvmxip-qs...@0800.blk#1" :
+   "nvmxip-qs...@0820.blk#2"),
+   dev->name);
+   ut_asserteq(3, i);
 
i = 0;
blk_foreach_probe(BLKF_REMOVABLE, dev)
@@ -216,9 +227,13 @@ static int dm_test_blk_iter(struct unit_test_state *uts)
 
i = 0;
blk_foreach_probe(BLKF_BOTH, dev)
-   ut_asserteq_str((++i == 1 ? "mmc2.blk" : i == 2 ?
-   "mmc1.blk" : "mmc0.blk"), dev->name);
-   ut_asserteq(3, i);
+   ut_asserteq_str((++i == 1 ? "mmc2.blk" :
+   i == 2 ? "mmc1.blk" :
+   i == 3 ? "mmc0.blk" :
+   i == 4 ? "nvmxip-qs...@0800.blk#1" :
+   "nvmxip-qs...@0820.blk#2"),
+   dev->name);
+   ut_asserteq(5, i);
 
return 0;
 }
@@ -242,6 +257,14 @@ static int dm_test_blk_flags(struct unit_test_state *uts)
ut_assertnonnull(dev);
ut_asserteq_str("mmc0.blk", dev->name);
 
+   ut_assertok(blk_find_next(BLKF_BOTH, &dev));
+   ut_assertnonnull(dev);
+   ut_asserteq_str("nvmxip-qs...@0800.blk#1", dev->name);
+
+   ut_assertok(blk_find_next(BLKF_BOTH, &dev));
+   ut_assertnonnull(dev);
+   ut_asserteq_str("nvmxip-qs...@0820.blk#2", dev->name);
+
ut_asserteq(-ENODEV, blk_find_next(BLKF_BOTH, &dev));
ut_assertnull(dev);
 
@@ -265,6 +288,14 @@ static int dm_test_blk_flags(struct unit_test_state *uts)
ut_assertnonnull(dev);
ut_asserteq_str("mmc0.blk", dev->name);
 
+   ut_assertok(blk_next_device_err(BLKF_BOTH, &dev));
+   ut_assertnonnull(dev);
+   ut_asserteq_str("nvmxip-qs...@0800.blk#1", dev->name);
+
+   ut_assertok(blk_next_device_err(BLKF_BOTH, &dev));
+   ut_assertnonnull(dev);
+   ut_a

[PATCH 1/2] drivers/mtd/nvmxip: Rework the read accessor to support 32bit systems

2023-08-13 Thread Marek Vasut
Get rid of nvmxip_mmio_rawread() and just implement the readl()/readq()
reader loop within nvmxip_blk_read(). Cast the destination buffer as
needed and increment the read by either 4 or 8 bytes depending on if
this is systemd with 32bit or 64bit physical address.

Signed-off-by: Marek Vasut 
---
Cc: Abdellatif El Khlifi 
Cc: Simon Glass 
---
 drivers/mtd/nvmxip/nvmxip.c | 38 -
 1 file changed, 12 insertions(+), 26 deletions(-)

diff --git a/drivers/mtd/nvmxip/nvmxip.c b/drivers/mtd/nvmxip/nvmxip.c
index a359e3b4822..0bd98d64275 100644
--- a/drivers/mtd/nvmxip/nvmxip.c
+++ b/drivers/mtd/nvmxip/nvmxip.c
@@ -15,23 +15,6 @@
 #include 
 #include "nvmxip.h"
 
-/**
- * nvmxip_mmio_rawread() - read from the XIP flash
- * @address:   address of the data
- * @value: pointer to where storing the value read
- *
- * Read raw data from the XIP flash.
- *
- * Return:
- *
- * Always return 0.
- */
-static int nvmxip_mmio_rawread(const phys_addr_t address, u64 *value)
-{
-   *value = readq(address);
-   return 0;
-}
-
 /**
  * nvmxip_blk_read() - block device read operation
  * @dev:   the block device
@@ -49,15 +32,14 @@ static ulong nvmxip_blk_read(struct udevice *dev, lbaint_t 
blknr, lbaint_t blkcn
 {
struct nvmxip_plat *plat = dev_get_plat(dev->parent);
struct blk_desc *desc = dev_get_uclass_plat(dev);
-   /* number of the u64 words to read */
-   u32 qwords = (blkcnt * desc->blksz) / sizeof(u64);
+   /* number of bytes to read */
+   u32 size = blkcnt * desc->blksz;
/* physical address of the first block to read */
phys_addr_t blkaddr = plat->phys_base + blknr * desc->blksz;
-   u64 *virt_blkaddr;
-   u64 *pdst = buffer;
+   void *virt_blkaddr;
uint qdata_idx;
 
-   if (!pdst)
+   if (!buffer)
return -EINVAL;
 
log_debug("[%s]: reading from blknr: %lu , blkcnt: %lu\n", dev->name, 
blknr, blkcnt);
@@ -66,12 +48,16 @@ static ulong nvmxip_blk_read(struct udevice *dev, lbaint_t 
blknr, lbaint_t blkcn
 
/* assumption: the data is virtually contiguous */
 
-   for (qdata_idx = 0 ; qdata_idx < qwords ; qdata_idx++)
-   nvmxip_mmio_rawread((phys_addr_t)(virt_blkaddr + qdata_idx), 
pdst++);
-
+#if IS_ENABLED(CONFIG_PHYS_64BIT)
+   for (qdata_idx = 0 ; qdata_idx < size; qdata_idx += sizeof(u64))
+   *(u64 *)(buffer + qdata_idx) = readq(virt_blkaddr + qdata_idx);
+#else
+   for (qdata_idx = 0 ; qdata_idx < size; qdata_idx += sizeof(u32))
+   *(u32 *)(buffer + qdata_idx) = readl(virt_blkaddr + qdata_idx);
+#endif
log_debug("[%s]: src[0]: 0x%llx , dst[0]: 0x%llx , src[-1]: 0x%llx 
, dst[-1]: 0x%llx\n",
  dev->name,
- *virt_blkaddr,
+ *(u64 *)virt_blkaddr,
  *(u64 *)buffer,
  *(u64 *)((u8 *)virt_blkaddr + desc->blksz * blkcnt - 
sizeof(u64)),
  *(u64 *)((u8 *)buffer + desc->blksz * blkcnt - sizeof(u64)));
-- 
2.40.1



Re: [PATCH] x86: Update cbmem driver

2023-08-13 Thread Simon Glass
+Paul Menzel 

On Sun, 13 Aug 2023 at 14:10, Simon Glass  wrote:
>
> This driver is not actually built since a Kconfig was never created for
> it.
>
> Add a Kconfig (which is already implied by COREBOOT) and update the
> implementation to avoid using unnecessary memory. Drop the #ifdef at the
> top since we can rely on Kconfig to get that right.
>
> To enable it (in addition to serial and video), use:
>
>setenv stdout serial,vidconsole,cbmem
>
> Signed-off-by: Simon Glass 
> ---
>
>  drivers/misc/Kconfig |  8 
>  drivers/misc/cbmem_console.c | 26 +-
>  2 files changed, 17 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index b9f5c7a37aed..3df57a5bfbd9 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -122,6 +122,14 @@ config VEXPRESS_CONFIG
>   configuration bus on the Arm Versatile Express boards via
>   a sysreg driver.
>
> +config CBMEM_CONSOLE
> +   bool "Write console output to coreboot cbmem"
> +   depends on X86
> +   help
> + Enables console output to the cbmem console, which is a memory
> + region set up by coreboot to hold a record of all console output.
> + Enable this only if booting from coreboot.
> +
>  config CMD_CROS_EC
> bool "Enable crosec command"
> depends on CROS_EC
> diff --git a/drivers/misc/cbmem_console.c b/drivers/misc/cbmem_console.c
> index 8bbe33d414da..6ae1389a23e0 100644
> --- a/drivers/misc/cbmem_console.c
> +++ b/drivers/misc/cbmem_console.c
> @@ -5,27 +5,20 @@
>
>  #include 
>  #include 
> -#ifndef CONFIG_SYS_COREBOOT
> -#error This driver requires coreboot
> -#endif
> -
>  #include 
>
> -struct cbmem_console {
> -   u32 buffer_size;
> -   u32 buffer_cursor;
> -   u8  buffer_body[0];
> -}  __attribute__ ((__packed__));
> -
> -static struct cbmem_console *cbmem_console_p;
> -
>  void cbmemc_putc(struct stdio_dev *dev, char data)
>  {
> -   int cursor;
> +   const struct sysinfo_t *sysinfo = cb_get_sysinfo();
> +   struct cbmem_console *cons = sysinfo ? sysinfo->cbmem_cons : NULL;
> +   int pos;
> +
> +   if (!cons)
> +   return;
>
> -   cursor = cbmem_console_p->buffer_cursor++;
> -   if (cursor < cbmem_console_p->buffer_size)
> -   cbmem_console_p->buffer_body[cursor] = data;
> +   pos = cons->cursor++;
> +   if (pos < cons->size)
> +   cons->body[pos] = data;
>  }
>
>  void cbmemc_puts(struct stdio_dev *dev, const char *str)
> @@ -40,7 +33,6 @@ int cbmemc_init(void)
>  {
> int rc;
> struct stdio_dev cons_dev;
> -   cbmem_console_p = lib_sysinfo.cbmem_cons;
>
> memset(&cons_dev, 0, sizeof(cons_dev));
>
> --
> 2.41.0.640.ga95def55d0-goog
>


[PATCH] x86: Update cbmem driver

2023-08-13 Thread Simon Glass
This driver is not actually built since a Kconfig was never created for
it.

Add a Kconfig (which is already implied by COREBOOT) and update the
implementation to avoid using unnecessary memory. Drop the #ifdef at the
top since we can rely on Kconfig to get that right.

To enable it (in addition to serial and video), use:

   setenv stdout serial,vidconsole,cbmem

Signed-off-by: Simon Glass 
---

 drivers/misc/Kconfig |  8 
 drivers/misc/cbmem_console.c | 26 +-
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index b9f5c7a37aed..3df57a5bfbd9 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -122,6 +122,14 @@ config VEXPRESS_CONFIG
  configuration bus on the Arm Versatile Express boards via
  a sysreg driver.
 
+config CBMEM_CONSOLE
+   bool "Write console output to coreboot cbmem"
+   depends on X86
+   help
+ Enables console output to the cbmem console, which is a memory
+ region set up by coreboot to hold a record of all console output.
+ Enable this only if booting from coreboot.
+
 config CMD_CROS_EC
bool "Enable crosec command"
depends on CROS_EC
diff --git a/drivers/misc/cbmem_console.c b/drivers/misc/cbmem_console.c
index 8bbe33d414da..6ae1389a23e0 100644
--- a/drivers/misc/cbmem_console.c
+++ b/drivers/misc/cbmem_console.c
@@ -5,27 +5,20 @@
 
 #include 
 #include 
-#ifndef CONFIG_SYS_COREBOOT
-#error This driver requires coreboot
-#endif
-
 #include 
 
-struct cbmem_console {
-   u32 buffer_size;
-   u32 buffer_cursor;
-   u8  buffer_body[0];
-}  __attribute__ ((__packed__));
-
-static struct cbmem_console *cbmem_console_p;
-
 void cbmemc_putc(struct stdio_dev *dev, char data)
 {
-   int cursor;
+   const struct sysinfo_t *sysinfo = cb_get_sysinfo();
+   struct cbmem_console *cons = sysinfo ? sysinfo->cbmem_cons : NULL;
+   int pos;
+
+   if (!cons)
+   return;
 
-   cursor = cbmem_console_p->buffer_cursor++;
-   if (cursor < cbmem_console_p->buffer_size)
-   cbmem_console_p->buffer_body[cursor] = data;
+   pos = cons->cursor++;
+   if (pos < cons->size)
+   cons->body[pos] = data;
 }
 
 void cbmemc_puts(struct stdio_dev *dev, const char *str)
@@ -40,7 +33,6 @@ int cbmemc_init(void)
 {
int rc;
struct stdio_dev cons_dev;
-   cbmem_console_p = lib_sysinfo.cbmem_cons;
 
memset(&cons_dev, 0, sizeof(cons_dev));
 
-- 
2.41.0.640.ga95def55d0-goog



[PATCH] test: cpu: Handle both 32bit and 64bit CPUs

2023-08-13 Thread Marek Vasut
Handle both 32bit and 64bit systems, i.e. sandbox and sandbox64
the same way drivers/cpu/cpu_sandbox.c does, that is in case
CONFIG_PHYS_64BIT is enabled, assume 64bit address width, else
assume 32bit address width. This fixes ut_dm_dm_test_cpu test
failure on sandbox64.

Signed-off-by: Marek Vasut 
---
Cc: Simon Glass 
---
 test/dm/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/dm/cpu.c b/test/dm/cpu.c
index d7e596ee396..5734cd0a92d 100644
--- a/test/dm/cpu.c
+++ b/test/dm/cpu.c
@@ -37,7 +37,7 @@ static int dm_test_cpu(struct unit_test_state *uts)
ut_assertok(cpu_get_info(dev, &info));
ut_asserteq(info.cpu_freq, 42 * 42 * 42 * 42 * 42);
ut_asserteq(info.features, 0x42424242);
-   ut_asserteq(info.address_width, 32);
+   ut_asserteq(info.address_width, IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 
32);
 
ut_asserteq(cpu_get_count(dev), 42);
 
-- 
2.40.1



[PATCH] configs: sandbox64: Enable PCI register multi-entry support

2023-08-13 Thread Marek Vasut
Align the sandbox64 defconfig with sandbox defconfig. Enable missing
PCI register multi-entry support. This fixes ut_dm_dm_test_pci_bus_to_phys
test .

Signed-off-by: Marek Vasut 
---
Cc: Simon Glass 
---
 configs/sandbox64_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index 933c9e95810..14c9d1b04cb 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -179,6 +179,7 @@ CONFIG_SPI_FLASH_SST=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_NVMXIP_QSPI=y
 CONFIG_NVME_PCI=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
 CONFIG_PCI_SANDBOX=y
 CONFIG_PHY=y
 CONFIG_PHY_SANDBOX=y
-- 
2.40.1



[PATCH] configs: sandbox64: Enable clock CCF driver

2023-08-13 Thread Marek Vasut
Align the sandbox64 defconfig with sandbox defconfig. Enable missing
CCF and Sandbox CCF drivers. This fixes ut_dm_dm_test_clk_ccf test .

Signed-off-by: Marek Vasut 
---
Cc: Simon Glass 
---
 configs/sandbox64_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index 1db69ec65c7..933c9e95810 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -127,8 +127,10 @@ CONFIG_BUTTON=y
 CONFIG_BUTTON_ADC=y
 CONFIG_BUTTON_GPIO=y
 CONFIG_CLK=y
+CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_K210=y
 CONFIG_CLK_K210_SET_RATE=y
+CONFIG_SANDBOX_CLK_CCF=y
 CONFIG_CPU=y
 CONFIG_DM_DEMO=y
 CONFIG_DM_DEMO_SIMPLE=y
-- 
2.40.1



[PATCH v2 1/2] net: add hifemac Ethernet driver for HiSilicon platform

2023-08-13 Thread Yang Xiwen via B4 Relay
From: Yang Xiwen 

It adds the driver for HIFEMAC Ethernet controller found on HiSilicon
SoCs like Hi3798MV200.  It's based on the mainstream linux driver, but
quite a lot of code gets rewritten and cleaned up to adopt u-boot driver
model.

Signed-off-by: Yang Xiwen 
---
 drivers/net/Kconfig   |   9 +
 drivers/net/Makefile  |   1 +
 drivers/net/hifemac.c | 481 ++
 3 files changed, 491 insertions(+)

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 39eee98ca7..bc1d6e3905 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -886,6 +886,15 @@ config MEDIATEK_ETH
  This Driver support MediaTek Ethernet GMAC
  Say Y to enable support for the MediaTek Ethernet GMAC.
 
+config HIFEMAC_ETH
+   bool "HiSilicon Fast Ethernet Controller"
+   select DM_CLK
+   select DM_RESET
+   select PHYLIB
+   help
+ This driver supports HIFEMAC Ethernet controller found on
+ HiSilicon SoCs.
+
 config HIGMACV300_ETH
bool "HiSilicon Gigabit Ethernet Controller"
select DM_RESET
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 46a40e2ed9..de6bf1d014 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -45,6 +45,7 @@ obj-$(CONFIG_FSL_PFE) += pfe_eth/
 obj-$(CONFIG_FTGMAC100) += ftgmac100.o
 obj-$(CONFIG_FTMAC100) += ftmac100.o
 obj-$(CONFIG_GMAC_ROCKCHIP) += gmac_rockchip.o
+obj-$(CONFIG_HIFEMAC_ETH) += hifemac.o
 obj-$(CONFIG_HIGMACV300_ETH) += higmacv300.o
 obj-$(CONFIG_KS8851_MLL) += ks8851_mll.o
 obj-$(CONFIG_KSZ9477) += ksz9477.o
diff --git a/drivers/net/hifemac.c b/drivers/net/hifemac.c
new file mode 100644
index 00..b61a29e636
--- /dev/null
+++ b/drivers/net/hifemac.c
@@ -0,0 +1,481 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hisilicon Fast Ethernet MAC Driver
+ * Adapted from linux
+ *
+ * Copyright (c) 2016 HiSilicon Technologies Co., Ltd.
+ * Copyright (c) 2023 Yang Xiwen 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* MAC control register list */
+#define MAC_PORTSEL0x0200
+#define MAC_PORTSEL_STAT_CPU   BIT(0)
+#define MAC_PORTSEL_RMII   BIT(1)
+#define MAC_PORTSET0x0208
+#define MAC_PORTSET_DUPLEX_FULLBIT(0)
+#define MAC_PORTSET_LINKED BIT(1)
+#define MAC_PORTSET_SPEED_100M BIT(2)
+#define MAC_SET0x0210
+#define MAX_FRAME_SIZE 1600
+#define MAX_FRAME_SIZE_MASKGENMASK(10, 0)
+#define BIT_PAUSE_EN   BIT(18)
+#define RX_COALESCE_SET0x0340
+#define RX_COALESCED_FRAME_OFFSET  24
+#define RX_COALESCED_FRAMES8
+#define RX_COALESCED_TIMER 0x74
+#define QLEN_SET   0x0344
+#define RX_DEPTH_OFFSET8
+#define MAX_HW_FIFO_DEPTH  64
+#define HW_TX_FIFO_DEPTH   1
+#define MAX_HW_RX_FIFO_DEPTH   (MAX_HW_FIFO_DEPTH - HW_TX_FIFO_DEPTH)
+#define HW_RX_FIFO_DEPTH   min(PKTBUFSRX, MAX_HW_RX_FIFO_DEPTH)
+#define IQFRM_DES  0x0354
+#define RX_FRAME_LEN_MASK  GENMASK(11, 0)
+#define RX_FRAME_IN_INDEX_MASK GENMASK(17, 12)
+#define IQ_ADDR0x0358
+#define EQ_ADDR0x0360
+#define EQFRM_LEN  0x0364
+#define ADDRQ_STAT 0x036C
+#define TX_CNT_INUSE_MASK  GENMASK(5, 0)
+#define BIT_TX_READY   BIT(24)
+#define BIT_RX_READY   BIT(25)
+/* global control register list */
+#define GLB_HOSTMAC_L320x
+#define GLB_HOSTMAC_H160x0004
+#define GLB_SOFT_RESET 0x0008
+#define SOFT_RESET_ALL BIT(0)
+#define GLB_FWCTRL 0x0010
+#define FWCTRL_VLAN_ENABLE BIT(0)
+#define FWCTRL_FW2CPU_ENA  BIT(5)
+#define FWCTRL_FWALL2CPU   BIT(7)
+#define GLB_MACTCTRL   0x0014
+#define MACTCTRL_UNI2CPU   BIT(1)
+#define MACTCTRL_MULTI2CPU BIT(3)
+#define MACTCTRL_BROAD2CPU BIT(5)
+#define MACTCTRL_MACT_ENA  BIT(7)
+#define GLB_IRQ_STAT   0x0030
+#define GLB_IRQ_ENA0x0034
+#define IRQ_ENA_PORT0_MASK GENMASK(7, 0)
+#define IRQ_ENA_PORT0  BIT(18)
+#define IRQ_ENA_ALLBIT(19)
+#define GLB_IRQ_RAW0x0038
+#define IRQ_INT_RX_RDY BIT(0)
+#define IRQ_INT_TX_PER_PACKET  BIT(1)
+#define IRQ_INT_TX_FIFO_EMPTY  BIT(6)
+#define IRQ_INT_MULTI_RXRDYBIT(7)
+#define DEF_INT_MASK   (IRQ_INT_MULTI_RXRDY | \
+   IRQ_INT_TX_PER_PACKET | \
+  

[PATCH v2 0/2] net: add support for HiSilicon Fast Ethernet Controller driver

2023-08-13 Thread Yang Xiwen via B4 Relay
This core is found on many HiSilicon chips. This patchset adds support
for it and the integrated MDIO bus.

The driver code comes from linux kernel driver, downstream u-boot driver
and the datasheet. It's already tested on a Hi3798MV200 based STB.

Note that currently this driver can't be used for Hi3798MV200 since the
clock driver is missing. I will implement and submit the clock driver
and the framework in a later patchset.

Signed-off-by: Yang Xiwen 
---
Changes in v2:
- hisi_femac: clear previous irq before sending
- Link to v1: 
https://lore.kernel.org/r/20230725-wip-hisi_femac-trunk-v1-0-88469a170...@outlook.com

---
Yang Xiwen (2):
  net: add hifemac Ethernet driver for HiSilicon platform
  net: add hifemac_mdio MDIO bus driver for HiSilicon platform

 drivers/net/Kconfig|  17 ++
 drivers/net/Makefile   |   2 +
 drivers/net/hifemac.c  | 481 +
 drivers/net/hifemac_mdio.c | 116 +++
 4 files changed, 616 insertions(+)
---
base-commit: 580eb31199be8a822e62f20965854a242f895d03
change-id: 20230724-wip-hisi_femac-trunk-1f57f0986f0c

Best regards,
-- 
Yang Xiwen 



[PATCH v2 2/2] net: add hifemac_mdio MDIO bus driver for HiSilicon platform

2023-08-13 Thread Yang Xiwen via B4 Relay
From: Yang Xiwen 

It adds the driver for the internal MDIO bus of HIFEMAC Ethernet
controller.  It's based on the mainstream linux driver.

Signed-off-by: Yang Xiwen 
---
 drivers/net/Kconfig|   8 
 drivers/net/Makefile   |   1 +
 drivers/net/hifemac_mdio.c | 116 +
 3 files changed, 125 insertions(+)

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index bc1d6e3905..5c5bfb1263 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -895,6 +895,14 @@ config HIFEMAC_ETH
  This driver supports HIFEMAC Ethernet controller found on
  HiSilicon SoCs.
 
+config HIFEMAC_MDIO
+   bool "HiSilicon Fast Ethernet Controller MDIO interface"
+   depends on DM_MDIO
+   select DM_CLK
+   help
+ This driver supports the internal MDIO interface of HIFEMAC
+ Ethernet controller.
+
 config HIGMACV300_ETH
bool "HiSilicon Gigabit Ethernet Controller"
select DM_RESET
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index de6bf1d014..b2d3da6934 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -46,6 +46,7 @@ obj-$(CONFIG_FTGMAC100) += ftgmac100.o
 obj-$(CONFIG_FTMAC100) += ftmac100.o
 obj-$(CONFIG_GMAC_ROCKCHIP) += gmac_rockchip.o
 obj-$(CONFIG_HIFEMAC_ETH) += hifemac.o
+obj-$(CONFIG_HIFEMAC_MDIO) += hifemac_mdio.o
 obj-$(CONFIG_HIGMACV300_ETH) += higmacv300.o
 obj-$(CONFIG_KS8851_MLL) += ks8851_mll.o
 obj-$(CONFIG_KSZ9477) += ksz9477.o
diff --git a/drivers/net/hifemac_mdio.c b/drivers/net/hifemac_mdio.c
new file mode 100644
index 00..343c5f3a38
--- /dev/null
+++ b/drivers/net/hifemac_mdio.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Hisilicon Fast Ethernet MDIO Bus Driver
+ *
+ * Copyright (c) 2016 HiSilicon Technologies Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MDIO_RWCTRL0x00
+#define MDIO_RO_DATA   0x04
+#define MDIO_WRITE BIT(13)
+#define MDIO_RW_FINISH BIT(15)
+#define BIT_PHY_ADDR_OFFSET8
+#define BIT_WR_DATA_OFFSET 16
+
+struct hisi_femac_mdio_data {
+   struct clk *clk;
+   void __iomem *membase;
+};
+
+static int hisi_femac_mdio_wait_ready(struct hisi_femac_mdio_data *data)
+{
+   u32 val;
+
+   return readl_poll_timeout(data->membase + MDIO_RWCTRL,
+ val, val & MDIO_RW_FINISH, 1);
+}
+
+static int hisi_femac_mdio_read(struct udevice *dev, int addr, int devad, int 
reg)
+{
+   struct hisi_femac_mdio_data *data = dev_get_priv(dev);
+   int ret;
+
+   ret = hisi_femac_mdio_wait_ready(data);
+   if (ret)
+   return ret;
+
+   writel((addr << BIT_PHY_ADDR_OFFSET) | reg,
+  data->membase + MDIO_RWCTRL);
+
+   ret = hisi_femac_mdio_wait_ready(data);
+   if (ret)
+   return ret;
+
+   return readl(data->membase + MDIO_RO_DATA) & 0x;
+}
+
+static int hisi_femac_mdio_write(struct udevice *dev, int addr, int devad, int 
reg, u16 val)
+{
+   struct hisi_femac_mdio_data *data = dev_get_priv(dev);
+   int ret;
+
+   ret = hisi_femac_mdio_wait_ready(data);
+   if (ret)
+   return ret;
+
+   writel(MDIO_WRITE | (val << BIT_WR_DATA_OFFSET) |
+  (addr << BIT_PHY_ADDR_OFFSET) | reg,
+  data->membase + MDIO_RWCTRL);
+
+   return hisi_femac_mdio_wait_ready(data);
+}
+
+static int hisi_femac_mdio_of_to_plat(struct udevice *dev)
+{
+   struct hisi_femac_mdio_data *data = dev_get_priv(dev);
+   int ret;
+
+   data->membase = dev_remap_addr(dev);
+   if (IS_ERR(data->membase)) {
+   ret = PTR_ERR(data->membase);
+   return log_msg_ret("Failed to remap base addr", ret);
+   }
+
+   // clk is optional
+   data->clk = devm_clk_get_optional(dev, NULL);
+
+   return 0;
+}
+
+static int hisi_femac_mdio_probe(struct udevice *dev)
+{
+   struct hisi_femac_mdio_data *data = dev_get_priv(dev);
+   int ret;
+
+   ret = clk_prepare_enable(data->clk);
+   if (ret)
+   return log_msg_ret("Failed to enable clk", ret);
+
+   return 0;
+}
+
+static const struct mdio_ops hisi_femac_mdio_ops = {
+   .read = hisi_femac_mdio_read,
+   .write = hisi_femac_mdio_write,
+};
+
+static const struct udevice_id hisi_femac_mdio_dt_ids[] = {
+   { .compatible = "hisilicon,hisi-femac-mdio" },
+   { }
+};
+
+U_BOOT_DRIVER(hisi_femac_mdio_driver) = {
+   .name = "hisi-femac-mdio",
+   .id = UCLASS_MDIO,
+   .of_match = hisi_femac_mdio_dt_ids,
+   .of_to_plat = hisi_femac_mdio_of_to_plat,
+   .probe = hisi_femac_mdio_probe,
+   .ops = &hisi_femac_mdio_ops,
+   .priv_auto = sizeof(struct hisi_femac_mdio_data),
+};

-- 
2.34.1



Re: Problem upon startup with halted USB device on RaspberryPi 4

2023-08-13 Thread Michal Suchánek
Hello,

On Sat, Aug 12, 2023 at 08:31:56PM +0200, Massimo Pegorer wrote:
> Hi Harry,
> 
> Il giorno lun 7 ago 2023 alle ore 11:02 Harry Waschkeit <
> harry.waschk...@conplement.de> ha scritto:
> 
> > Hi,
> >
> > I have a RaspberryPi 4 where on one USB port a Sierra Wireless LTE
> > module (EM7455) is attached via an PCIe-to-USB adapter.
> > The boot image I use gets built by Yocto with the help of poky
> > (kirkstone) and meta-raspberry (beside a few other layers) which
> > incorporates U-Boot 22.01.
> >
> > When I apply power to the board it will come up until scanning USB
> > devices (for potential boot devices), but then throw a BUG end reset the
> > board.
> 
> 
> Do you need USB boot devices? If not, I would build U-Boot without USB
> support.

That would be great workaround, However, enabling a device should not
break the board. If that's the case the driver is clearly broken.

Also rPi typically uses USB keyboard for boot-time input which makes the
workaround not so great.

Thanks

Michal

> 
> Massimo
> 
> > This continues as long as the modem is unplugged.
> > The exact error message is:
> >
> > scanning bus xhci_pci for devices... WARN halted endpoint, queuing URB
> > anyway.
> > Unexpected XHCI event TRB, skipping... (3af519b0 0004 1300
> > 02008401)
> > BUG at drivers/usb/host/xhci-ring.c:503/abort_td()!
> > BUG!
> > resetting ...
> >
> > Some internet research brought up a patch (1) for
> > drivers/usb/host/xhci-ring.c where halted devices simply get ignored
> > during enumeration:
> >
> > diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> > index acf437104a..6d995f446e 100644
> > --- a/drivers/usb/host/xhci-ring.c
> > +++ b/drivers/usb/host/xhci-ring.c
> > @@ -227,7 +227,8 @@ static int prepare_ring(struct xhci_ctrl *ctrl,
> > struct xhci_ring *ep_ring,
> > puts("WARN waiting for error on ep to be cleared\n");
> > return -EINVAL;
> > case EP_STATE_HALTED:
> > - puts("WARN halted endpoint, queueing URB anyway.\n");
> > + puts("WARN halted endpoint.\n");
> > + return -EPIPE;
> > case EP_STATE_STOPPED:
> > case EP_STATE_RUNNING:
> > debug("EP STATE RUNNING.\n");
> >
> > The driver file itself stems from the Linux sources, so I'm pretty sure
> > that it is correct in that context.
> > Even though I'm not really into USB stuff and therefore I cannot not
> > really follow the discussion for the proposed change, in my eyes the
> > patch could be reasonable for U-Boot nevertheless given that a) in my
> > experience driver code is often used in a simplified way in U-Boot
> > compared to Linux kernel, and b) it's all about board start-up only and
> > not about full OS use with all bells, whistles and full error handling.
> >
> > Of course, I might be wrong while missing some important other use or
> > corner cases, so I wanted to check here :-)
> >
> > At least, what I can say: with this patch I see a bunch of these warning
> > messages but the board comes up and is usable in the end by Linux.
> >
> > fwiw: my internet search also showed another patch labelled in the first
> > place "[PATCH] pi4: fix crash when issuing usb reset" (2) that didn't
> > make it into the particular U-Boot 22.01 but was integrated right after
> > that version in commit "Prepare v2022.04" with hash
> > e4b6ebd3de982ae7185dbf689a030e73fd06e0d2 (3).
> > As I first hoped I could address my problem by just adding this patch I
> > got promptly disappointed. The only thing I gained was to now get
> > endless error messages followed by retries until I power-cycled the
> > board (causing to start all over):
> >
> > USB XHCI 1.00
> > scanning bus xhci_pci for devices... WARN halted endpoint, queueing URB
> > anyway.
> > Unexpected XHCI event TRB, skipping... (3afd6b30 0004 1300
> > 02008401)
> > XHCI abort timeout
> > WARN halted endpoint, queueing URB anyway.
> > Unexpected XHCI event TRB, skipping... (3afd6b40 0004 1300
> > 02008401)
> > XHCI abort timeout
> > WARN halted endpoint, queueing URB anyway.
> > Unexpected XHCI event TRB, skipping... (3afd6b50 0004 1300
> > 02008401)
> > XHCI abort timeout
> > WARN halted endpoint, queueing URB anyway.
> > [...]
> >
> > To me it means that this specific PCIe-to-USB bridge might misbehave
> > somehow,
> > but the final question is: what are the odds to get that patch into
> > official U-boot, or any other fix/quirk to make my hardware combo working?
> >
> > And also interesting: if I cannot hope for an upstream change, what
> > potential risks I would have to accept when keeping my patch?
> >
> > Regards,
> > Harry
> >
> > (1)
> >
> > https://linux-usb.vger.kernel.narkive.com/VW4VTVDU/patch-usb-host-xhci-fix-halted-endpoint-handling
> > (2)
> > https://lore.kernel.org/all/3d4ece94-932a-25dd-ef29-0ddfb4a51...@denx.de/T/
> > (3)
> >
> > https://source.denx.de/u-boot/u-boot/-/commit/e4b6ebd3de982ae7185dbf689a030e73fd06e0d2
> >
> > --
> > i.A. Harry Waschkeit
> > Senior Embedded Engineer
> > conplement AG
> > Südwestpark 92
> > 90449 Nürn

Re: Strange gitlab idea

2023-08-13 Thread Tom Rini
On Sat, Aug 12, 2023 at 09:14:45PM -0600, Simon Glass wrote:

> Hi Tom,
> 
> I notice that the runners are not utilised much by the QEMU jobs,
> since we only run one at a time.
> 
> I wonder if we could improve this, perhaps by using a different tag
> for the QEMU ones and then having a machine that only runs those (and
> runs 40 in parallel)?
> 
> In general our use of the runners seems a bit primitive, since the
> main use of parallelism is in the world builds.

I'm honestly not sure. I think there's a few tweaks that we should do,
like putting the opensbi and coreboot files in to the Dockerfile logic
instead.  And maybe seeing if just like we can have a docker registry
cache, if we can setup local pypi cache too?  I'm not otherwise sure
what's taking 23 seconds or so of
https://source.denx.de/u-boot/u-boot/-/jobs/673565#L34 since the build
and run parts aren't much.

My first big worry about running 2 or 3 qemu jobs at the same time on a
host is that any wins get from a shorter queue will be lost to buildman
doing "make -j$(nproc)" 2 or 3 times at once and so we build slower.

My second big worry is that getting the right tags on runners will be a
little tricky.

My third big worry (but this is something you can test easy enough at
least) is that running the big sandbox tests, 2 or 3 times at once on
the same host will get much slower. I think, but profiling would be
helpful, that those get slow due to I/O and not CPU.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v8 4/9] sandbox: Build the mkeficapsule tool for the sandbox variants

2023-08-13 Thread Tom Rini
On Sun, Aug 13, 2023 at 07:36:45AM -0600, Simon Glass wrote:
> Hi Tom,
> 
> On Sun, 13 Aug 2023 at 06:40, Tom Rini  wrote:
> >
> > On Sat, Aug 12, 2023 at 06:14:45PM -0600, Simon Glass wrote:
> > > Hi Tom,
> > >
> > > On Sat, 12 Aug 2023 at 16:38, Tom Rini  wrote:
> > > >
> > > > On Sat, Aug 12, 2023 at 11:03:36AM -0600, Simon Glass wrote:
> > > > > Hi Tom,
> > > > >
> > > > > On Sat, 12 Aug 2023 at 08:28, Tom Rini  wrote:
> > > > > >
> > > > > > On Sat, Aug 12, 2023 at 08:24:59AM -0600, Simon Glass wrote:
> > > > > > > Hi Tom,
> > > > > > >
> > > > > > > On Sat, 12 Aug 2023 at 08:22, Tom Rini  wrote:
> > > > > > > >
> > > > > > > > On Sat, Aug 12, 2023 at 07:08:44AM -0600, Simon Glass wrote:
> > > > > > > > > Hi Tom,
> > > > > > > > >
> > > > > > > > > On Fri, 11 Aug 2023 at 09:56, Tom Rini  
> > > > > > > > > wrote:
> > > > > > > > > >
> > > > > > > > > > On Fri, Aug 11, 2023 at 08:26:36AM -0600, Simon Glass wrote:
> > > > > > > > > > > Hi Sughosh,
> > > > > > > > > > >
> > > > > > > > > > > On Fri, 11 Aug 2023 at 08:23, Sughosh Ganu 
> > > > > > > > > > > 
> > > > > > > > > wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > On Fri, 11 Aug 2023 at 19:28, Tom Rini 
> > > > > > > > > > > >  wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > On Fri, Aug 11, 2023 at 04:29:37PM +0530, Sughosh 
> > > > > > > > > > > > > Ganu wrote:
> > > > > > > > > > > > > > On Thu, 10 Aug 2023 at 22:47, Tom Rini 
> > > > > > > > > > > > > >  wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > On Thu, Aug 10, 2023 at 10:39:06PM +0530, Sughosh 
> > > > > > > > > > > > > > > Ganu wrote:
> > > > > > > > > > > > > > > > On Thu, 10 Aug 2023 at 21:22, Tom Rini 
> > > > > > > > > > > > > > > > 
> > > > > > > > > wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > On Thu, Aug 10, 2023 at 07:53:33PM +0530, 
> > > > > > > > > > > > > > > > > Sughosh Ganu
> > > > > > > > > wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Build the mkeficapsule tool for all the 
> > > > > > > > > > > > > > > > > > sandbox variants.
> > > > > > > > > This tool
> > > > > > > > > > > > > > > > > > will be used subsequently for testing 
> > > > > > > > > > > > > > > > > > capsule generation
> > > > > > > > > in binman.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Signed-off-by: Sughosh Ganu 
> > > > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > > > ---
> > > > > > > > > > > > > > > > > > Changes since V7: None
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >  tools/Kconfig | 6 +++---
> > > > > > > > > > > > > > > > > >  1 file changed, 3 insertions(+), 3 
> > > > > > > > > > > > > > > > > > deletions(-)
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > diff --git a/tools/Kconfig b/tools/Kconfig
> > > > > > > > > > > > > > > > > > index 6e23f44d55..353a855243 100644
> > > > > > > > > > > > > > > > > > --- a/tools/Kconfig
> > > > > > > > > > > > > > > > > > +++ b/tools/Kconfig
> > > > > > > > > > > > > > > > > > @@ -91,10 +91,10 @@ config TOOLS_SHA512
> > > > > > > > > > > > > > > > > > Enable SHA512 support in the tools 
> > > > > > > > > > > > > > > > > > builds
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >  config TOOLS_MKEFICAPSULE
> > > > > > > > > > > > > > > > > > - bool "Build efimkcapsule command"
> > > > > > > > > > > > > > > > > > - default y if EFI_CAPSULE_ON_DISK
> > > > > > > > > > > > > > > > > > + bool "Build mkeficapsule tool"
> > > > > > > > > > > > > > > > > > + default y if EFI_CAPSULE_ON_DISK || 
> > > > > > > > > > > > > > > > > > SANDBOX
> > > > > > > > > > > > > > > > > >   help
> > > > > > > > > > > > > > > > > > -   This command allows users to create 
> > > > > > > > > > > > > > > > > > a UEFI
> > > > > > > > > capsule file and,
> > > > > > > > > > > > > > > > > > +   This tool allows users to create a 
> > > > > > > > > > > > > > > > > > UEFI capsule
> > > > > > > > > file and,
> > > > > > > > > > > > > > > > > > optionally sign that file. If you 
> > > > > > > > > > > > > > > > > > want to enable
> > > > > > > > > UEFI capsule
> > > > > > > > > > > > > > > > > > update feature on your target, you 
> > > > > > > > > > > > > > > > > > certainly need
> > > > > > > > > this.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Sorry, what is this fixing exactly?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > The tool is required to be supported on the 
> > > > > > > > > > > > > > > > sandbox_spl
> > > > > > > > > variant, since
> > > > > > > > > > > > > > > > that is used for the binman tests in CI. Simon 
> > > > > > > > > > > > > > > > had then asked
> > > > > > > > > me to
> > > > > > > > > > > > > > > > add support for the tool on all sandbox 
> > > > > > > > > > > > > > > > variants. I missed
> > > > > > > > > putting his
> > > > > > > > > > > > > > > > R-b on 

Re: [PATCH v1] board: rockchip: Add Bananapi R2Pro Board

2023-08-13 Thread Frank Wunderlich
Am 12. August 2023 03:50:14 MESZ schrieb Kever Yang :
>Hi Frank,
>
>On 2023/8/8 01:14, Frank Wunderlich wrote:
>> From: Frank Wunderlich 
>> 
>> Add rk3568 based Bananapi R2 Pro board.
>> 
>> Signed-off-by: Frank Wunderlich 
>> ---
>> because iodomain is different to evb and now iodomain driver is sent as
>> patch we need to separate between EVB and R2Pro else board can be bricked.
>What's the detail difference before and after the iodomain driver for this 
>board?

Sorry, missed this question somehow.

Evb defines these iodomains

&pmu_io_domains {
pmuio1-supply = <&vcc3v3_pmu>;
pmuio2-supply = <&vcc3v3_pmu>;
vccio1-supply = <&vccio_acodec>;
vccio2-supply = <&vcc_1v8>;
vccio3-supply = <&vccio_sd>;
vccio4-supply = <&vcc_1v8>;
vccio5-supply = <&vcc_3v3>;
vccio6-supply = <&vcc_1v8>;
vccio7-supply = <&vcc_3v3>;
status = "okay";
};

So vccio2 and vccio4 are 1v8 too which will brick these 2 io if still using 
this dts on r2pro which has these 2 3v3 (default).

>> diff --git a/arch/arm/dts/rk3568-bpi-r2pro.dts 
>> b/arch/arm/dts/rk3568-bpi-r2pro.dts
>> new file mode 100644
>> index ..9295e9836a56
>> --- /dev/null
>> +++ b/arch/arm/dts/rk3568-bpi-r2pro.dts
...
>> +&pmu_io_domains {
>> +pmuio1-supply = <&vcc3v3_pmu>;
>> +pmuio2-supply = <&vcc3v3_pmu>;
>> +vccio1-supply = <&vccio_acodec>;
>> +vccio3-supply = <&vccio_sd>;
>> +vccio4-supply = <&vcc_3v3>;
>> +vccio5-supply = <&vcc_3v3>;
>> +vccio6-supply = <&vcc_1v8>;
>> +vccio7-supply = <&vcc_3v3>;
>> +status = "okay";
>> +};


regards Frank


[PATCH 24/24] CI: Add ChromiumOS utilities

2023-08-13 Thread Simon Glass
We need cgpt and futility for building test images. Add them.

Signed-off-by: Simon Glass 
---

 tools/docker/Dockerfile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
index 3d2b64a355f3..6e6ae9ebed40 100644
--- a/tools/docker/Dockerfile
+++ b/tools/docker/Dockerfile
@@ -39,6 +39,7 @@ RUN apt-get update && apt-get install -y \
binutils-dev \
bison \
build-essential \
+   cgpt \
clang-16 \
coreutils \
cpio \
@@ -115,6 +116,8 @@ RUN apt-get update && apt-get install -y \
util-linux \
uuid-dev \
virtualenv \
+   vboot-kernel-utils \
+   vboot-utils \
xxd \
zip \
&& rm -rf /var/lib/apt/lists/*
-- 
2.41.0.640.ga95def55d0-goog



[PATCH 23/24] bootstd: cros: Allow detection of any kernel partition

2023-08-13 Thread Simon Glass
The existing ChromiumOS bootmeth only supports reading a single kernel
partition, either 2 or 4. In fact there are normally two options
available.

Use the GUID to detect kernel partitions, with the BOOTMETHF_ANY_PART
flag, so that bootstd does not require a valid filesystem before calling
the bootmeth.

Tidy up and improve the logging while we are here.

Signed-off-by: Simon Glass 
Suggested-by: Alper Nebi Yasak 
---

 boot/Kconfig |  2 ++
 boot/bootmeth_cros.c | 48 +++-
 test/boot/bootflow.c |  5 +++--
 3 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index 5e2d4286aeaa..b385902b53fe 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -466,6 +466,8 @@ config BOOTMETH_CROS
bool "Bootdev support for Chromium OS"
depends on X86 || ARM || SANDBOX
default y if !ARM
+   select PARTITION_TYPE_GUID
+   select PARTITION_UUIDS
help
  Enables support for booting Chromium OS using bootdevs. This uses the
  kernel A slot and obtains the kernel command line from the parameters
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c
index 1776fb1838c6..20e0b1e89c36 100644
--- a/boot/bootmeth_cros.c
+++ b/boot/bootmeth_cros.c
@@ -16,16 +16,19 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include "bootmeth_cros.h"
 
+static const efi_guid_t cros_kern_type = PARTITION_CROS_KERNEL;
+
 /*
  * Layout of the ChromeOS kernel
  *
- * Partitions 2 and 4 contain kernels
+ * Partitions 2 and 4 contain kernels with type GUID_CROS_KERNEL
  *
  * Contents are:
  *
@@ -145,13 +148,25 @@ static int scan_part(struct udevice *blk, int partnum,
 {
struct blk_desc *desc = dev_get_uclass_plat(blk);
struct vb2_keyblock *hdr;
+   struct uuid type;
ulong num_blks;
int ret;
 
+   if (!partnum)
+   return log_msg_ret("efi", -ENOENT);
+
ret = part_get_info(desc, partnum, info);
if (ret)
return log_msg_ret("part", ret);
 
+   /* Check for kernel partition type */
+   log_debug("part %x: type=%s\n", partnum, info->type_guid);
+   if (uuid_str_to_bin(info->type_guid, (u8 *)&type, UUID_STR_FORMAT_GUID))
+   return log_msg_ret("typ", -EINVAL);
+
+   if (memcmp(&cros_kern_type, &type, sizeof(type)))
+   return log_msg_ret("typ", -ENOEXEC);
+
/* Make a buffer for the header information */
num_blks = PROBE_SIZE >> desc->log2blksz;
log_debug("Reading header, blk=%s, start=%lx, blocks=%lx\n",
@@ -167,6 +182,7 @@ static int scan_part(struct udevice *blk, int partnum,
 
if (memcmp(VB2_KEYBLOCK_MAGIC, hdr->magic, VB2_KEYBLOCK_MAGIC_SIZE)) {
free(hdr);
+   log_debug("no magic\n");
return -ENOENT;
}
 
@@ -340,24 +356,16 @@ static int cros_read_bootflow(struct udevice *dev, struct 
bootflow *bflow)
struct vb2_keyblock *hdr;
const char *uuid = NULL;
struct cros_priv *priv;
-   int part, ret;
-
-   log_debug("starting, part=%d\n", bflow->part);
+   int ret;
 
-   /* We consider the whole disk, not any one partition */
-   if (bflow->part)
-   return log_msg_ret("max", -ENOENT);
+   log_debug("starting, part=%x\n", bflow->part);
 
-   /* Check partition 2 then 4 */
-   part = 2;
-   ret = scan_part(bflow->blk, part, &info, &hdr);
+   /* Check for kernel partitions */
+   ret = scan_part(bflow->blk, bflow->part, &info, &hdr);
if (ret) {
-   part = 4;
-   ret = scan_part(bflow->blk, part, &info, &hdr);
-   if (ret)
-   return log_msg_ret("scan", ret);
+   log_debug("- scan failed: err=%d\n", ret);
+   return log_msg_ret("scan", ret);
}
-   bflow->part = part;
 
priv = malloc(sizeof(struct cros_priv));
if (!priv) {
@@ -366,8 +374,8 @@ static int cros_read_bootflow(struct udevice *dev, struct 
bootflow *bflow)
}
bflow->bootmeth_priv = priv;
 
-   log_info("Selected partition %d, header at %lx\n", bflow->part,
-(ulong)map_to_sysmem(hdr));
+   log_debug("Selected partition %d, header at %lx\n", bflow->part,
+ (ulong)map_to_sysmem(hdr));
 
/* Grab a few things from the preamble */
preamble = (void *)hdr + hdr->keyblock_size;
@@ -381,8 +389,11 @@ static int cros_read_bootflow(struct udevice *dev, struct 
bootflow *bflow)
ret = cros_read_info(bflow, uuid, preamble);
preamble = NULL;
free(hdr);
-   if (ret)
+   if (ret) {
+   free(priv->info_buf);
+   free(priv);
return log_msg_ret("inf", ret);
+   }
bflow->size = priv->body_size;
bflow->state = BOOTFLOWST_READY;
 
@@ -437,6 +448,7 @@ static int cros_bootmeth_bind(struct udevice 

[PATCH 22/24] uuid: Add ChromiumOS partition types

2023-08-13 Thread Simon Glass
Add some GUIDs for ChromiumOS so we can detect the partitions.

Signed-off-by: Simon Glass 
---

 include/part_efi.h | 14 ++
 lib/uuid.c |  7 +++
 2 files changed, 21 insertions(+)

diff --git a/include/part_efi.h b/include/part_efi.h
index c68529b4dafe..59b7895b8a23 100644
--- a/include/part_efi.h
+++ b/include/part_efi.h
@@ -60,6 +60,20 @@
EFI_GUID( 0x3de21764, 0x95bd, 0x54bd, \
0xa5, 0xc3, 0x4a, 0xbe, 0x78, 0x6f, 0x38, 0xa8)
 
+/* Special ChromiumOS things */
+#define PARTITION_CROS_KERNEL \
+   EFI_GUID(0xfe3a2a5d, 0x4f32, 0x41a7, \
+0xb7, 0x25, 0xac, 0xcc, 0x32, 0x85, 0xa3, 0x09)
+#define PARTITION_CROS_ROOT \
+   EFI_GUID(0x3cb8e202, 0x3b7e, 0x47dd, \
+0x8a, 0x3c, 0x7f, 0xf2, 0xa1, 0x3c, 0xfc, 0xec)
+#define PARTITION_CROS_FIRMWARE \
+   EFI_GUID(0xcab6e88e, 0xabf3, 0x4102, \
+0xa0, 0x7a, 0xd4, 0xbb, 0x9b, 0xe3, 0xc1, 0xd3)
+#define PARTITION_CROS_RESERVED \
+   EFI_GUID(0x2e0a753d, 0x9e48, 0x43b0, \
+0x83, 0x37, 0xb1, 0x51, 0x92, 0xcb, 0x1b, 0x5e)
+
 /* linux/include/efi.h */
 typedef u16 efi_char16_t;
 
diff --git a/lib/uuid.c b/lib/uuid.c
index 61cd146d63ea..bab676019ff3 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -3,6 +3,8 @@
  * Copyright 2011 Calxeda, Inc.
  */
 
+#define LOG_CATEGOT LOGC_CORE
+
 #include 
 #include 
 #include 
@@ -57,6 +59,10 @@ static const struct {
{"swap",PARTITION_LINUX_SWAP_GUID},
{"lvm", PARTITION_LINUX_LVM_GUID},
{"u-boot-env",  PARTITION_U_BOOT_ENVIRONMENT},
+   {"cros-kern",   PARTITION_CROS_KERNEL},
+   {"cros-root",   PARTITION_CROS_ROOT},
+   {"cros-fw", PARTITION_CROS_FIRMWARE},
+   {"cros-rsrv",   PARTITION_CROS_RESERVED},
 #endif
 #if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI)
{
@@ -254,6 +260,7 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char 
*uuid_bin,
uint64_t tmp64;
 
if (!uuid_str_valid(uuid_str)) {
+   log_debug("not valid\n");
 #ifdef CONFIG_PARTITION_TYPE_GUID
if (!uuid_guid_get_bin(uuid_str, uuid_bin))
return 0;
-- 
2.41.0.640.ga95def55d0-goog



[PATCH 21/24] bootstd: Support bootmeths which can scan any partition

2023-08-13 Thread Simon Glass
Some bootmeths support scanning a partition without a filesystem on it.
Add a flag to support this.

This will allow the ChromiumOS bootmeth to find kernel partition, which
are stored in a special format, without a filesystem.

Signed-off-by: Simon Glass 
---

 boot/bootdev-uclass.c   | 17 ++---
 doc/develop/bootstd.rst | 11 ++-
 include/bootmeth.h  |  3 +++
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 00dc28e623a2..eab89088b63d 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -111,6 +111,8 @@ int bootdev_bind(struct udevice *parent, const char 
*drv_name, const char *name,
 int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk,
struct bootflow_iter *iter, struct bootflow *bflow)
 {
+   struct bootmeth_uc_plat *plat = dev_get_uclass_plat(bflow->method);
+   bool allow_any_part = plat->flags & BOOTMETHF_ANY_PART;
struct blk_desc *desc = dev_get_uclass_plat(blk);
struct disk_partition info;
char partstr[20];
@@ -142,6 +144,7 @@ int bootdev_find_in_blk(struct udevice *dev, struct udevice 
*blk,
 * us whether there is valid media there
 */
ret = part_get_info(desc, iter->part, &info);
+   log_debug("part_get_info() returned %d\n", ret);
if (!iter->part && ret == -ENOENT)
ret = 0;
 
@@ -154,7 +157,7 @@ int bootdev_find_in_blk(struct udevice *dev, struct udevice 
*blk,
ret = -ESHUTDOWN;
else
bflow->state = BOOTFLOWST_MEDIA;
-   if (ret) {
+   if (ret && !allow_any_part) {
/* allow partition 1 to be missing */
if (iter->part == 1) {
iter->max_part = 3;
@@ -174,9 +177,15 @@ int bootdev_find_in_blk(struct udevice *dev, struct 
udevice *blk,
if (!iter->part) {
iter->first_bootable = part_get_bootable(desc);
log_debug("checking bootable=%d\n", iter->first_bootable);
+   } else if (allow_any_part) {
+   /*
+* allow any partition to be scanned, by skipping any checks
+* for filesystems or partition contents on this disk
+*/
 
/* if there are bootable partitions, scan only those */
-   } else if (iter->first_bootable ? !info.bootable : iter->part != 1) {
+   } else if (iter->first_bootable >= 0 &&
+  (iter->first_bootable ? !info.bootable : iter->part != 1)) {
return log_msg_ret("boot", -EINVAL);
} else {
ret = fs_set_blk_dev_with_part(desc, bflow->part);
@@ -193,6 +202,7 @@ int bootdev_find_in_blk(struct udevice *dev, struct udevice 
*blk,
bflow->state = BOOTFLOWST_FS;
}
 
+   log_debug("method %s\n", bflow->method->name);
ret = bootmeth_read_bootflow(bflow->method, bflow);
if (ret)
return log_msg_ret("method", ret);
@@ -555,7 +565,8 @@ int bootdev_get_bootflow(struct udevice *dev, struct 
bootflow_iter *iter,
 {
const struct bootdev_ops *ops = bootdev_get_ops(dev);
 
-   log_debug("->get_bootflow %s=%p\n", dev->name, ops->get_bootflow);
+   log_debug("->get_bootflow %s,%x=%p\n", dev->name, iter->part,
+ ops->get_bootflow);
bootflow_init(bflow, dev, iter->method);
if (!ops->get_bootflow)
return default_get_bootflow(dev, iter, bflow);
diff --git a/doc/develop/bootstd.rst b/doc/develop/bootstd.rst
index 7a2a69fdfcec..23ea46d6c304 100644
--- a/doc/develop/bootstd.rst
+++ b/doc/develop/bootstd.rst
@@ -677,11 +677,12 @@ Assuming the bootmeth is happy, or at least indicates 
that it is willing to try
 partition. If that works it tries to detect a file system. If that works then 
it
 calls the bootmeth device once more, this time to read the bootflow.
 
-Note: At present a filesystem is needed for the bootmeth to be called on block
-devices, simply because we don't have any examples where this is not the case.
-This feature can be added as needed. Note that sandbox is a special case, since
-in that case the host filesystem can be accessed even though the block device
-is NULL.
+Note: Normally a filesystem is needed for the bootmeth to be called on block
+devices, but bootmeths which don't need that can set the BOOTMETHF_ANY_PART
+flag to indicate that they can scan any partition. An example is the ChromiumOS
+bootmeth which can store a kernel in a raw partition. Note also that sandbox is
+a special case, since in that case the host filesystem can be accessed even
+though the block device is NULL.
 
 If we take the example of the `bootmeth_extlinux` driver, this call ends up at
 `extlinux_read_bootflow()`. It has the filesystem ready, so tries various
diff --git a/include/bootmeth.h b/include/bootmeth.h
index d3d8d608cd78..0fc36104ece0 100644
--- a/include/bootmeth.h
+++ b/include/bootmeth.h
@@ -16,9 +1

[PATCH 20/24] part: Add a fallback for part_get_bootable()

2023-08-13 Thread Simon Glass
This function can be called when partition support is disabled. Add a
static inline to handle this.

Signed-off-by: Simon Glass 
---

 include/part.h | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/include/part.h b/include/part.h
index c3de317fcce8..5a6367a7c507 100644
--- a/include/part.h
+++ b/include/part.h
@@ -364,14 +364,6 @@ part_get_info_by_dev_and_name_or_num(const char *dev_iface,
 }
 #endif
 
-/**
- * part_get_bootable() - Find the first bootable partition
- *
- * @desc: Block-device descriptor
- * @return first bootable partition, or 0 if there is none
- */
-int part_get_bootable(struct blk_desc *desc);
-
 struct udevice;
 /**
  * part_create_block_devices - Create block devices for disk partitions
@@ -666,12 +658,24 @@ static inline struct part_driver 
*part_driver_get_first(void)
  */
 int part_get_type_by_name(const char *name);
 
+/**
+ * part_get_bootable() - Find the first bootable partition
+ *
+ * @desc: Block-device descriptor
+ * @return first bootable partition, or 0 if there is none
+ */
+int part_get_bootable(struct blk_desc *desc);
+
 #else
 static inline int part_driver_get_count(void)
 { return 0; }
 
 static inline struct part_driver *part_driver_get_first(void)
 { return NULL; }
+
+static inline bool part_get_bootable(struct blk_desc *desc)
+{ return false; }
+
 #endif /* CONFIG_PARTITIONS */
 
 #endif /* _PART_H */
-- 
2.41.0.640.ga95def55d0-goog



[PATCH 19/24] bootstd: Add a test for bootmeth_cros

2023-08-13 Thread Simon Glass
The ChromiumOS bootmeth has no tests at present. Before adding more
features. add a basic test.

This creates a disk which can be scanned by the bootmeth, so make sure
things work. It is quite rudimentary, since the kernel is faked, the root
disk is missing and there is no cmdline stored.

Enable the bootmeth for snow so it can build the unit test.

Signed-off-by: Simon Glass 
---

 arch/sandbox/dts/test.dts |   9 +++
 configs/snow_defconfig|   1 +
 test/boot/bootflow.c  |  33 -
 test/py/tests/test_ut.py  | 142 ++
 4 files changed, 183 insertions(+), 2 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index b5509eee8cfe..3a683b551080 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -39,6 +39,8 @@
mmc1 = "/mmc1";
mmc2 = "/mmc2";
mmc3 = "/mmc3";
+   mmc4 = "/mmc4";
+   mmc5 = "/mmc5";
pci0 = &pci0;
pci1 = &pci1;
pci2 = &pci2;
@@ -1055,6 +1057,13 @@
filename = "mmc4.img";
};
 
+   /* This is used for ChromiumOS tests */
+   mmc5 {
+   status = "disabled";
+   compatible = "sandbox,mmc";
+   filename = "mmc5.img";
+   };
+
pch {
compatible = "sandbox,pch";
};
diff --git a/configs/snow_defconfig b/configs/snow_defconfig
index bb066a645991..22ec8e5141f6 100644
--- a/configs/snow_defconfig
+++ b/configs/snow_defconfig
@@ -29,6 +29,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_FIT=y
 CONFIG_FIT_BEST_MATCH=y
 CONFIG_BOOTSTD_FULL=y
+CONFIG_BOOTMETH_CROS=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_SILENT_CONSOLE=y
 CONFIG_BLOBLIST=y
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 54a878c4bd5d..ae34370981cb 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -27,6 +27,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+extern U_BOOT_DRIVER(bootmeth_cros);
 extern U_BOOT_DRIVER(bootmeth_script);
 
 static int inject_response(struct unit_test_state *uts)
@@ -514,7 +515,8 @@ BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | 
UT_TESTF_SCAN_FDT);
  * @mmc_dev: MMC device to use, e.g. "mmc4"
  * Returns 0 on success, -ve on failure
  */
-static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev)
+static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
+   bool bind_cros)
 {
const char *order[] = {"mmc2", "mmc1", mmc_dev, NULL};
struct udevice *dev, *bootstd;
@@ -533,6 +535,13 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, 
const char *mmc_dev)
ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_script),
"bootmeth_script", 0, ofnode_null(), &dev));
 
+   /* Enable the cros bootmeth if needed */
+   if (bind_cros) {
+   ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
+   ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_cros),
+   "cros", 0, ofnode_null(), &dev));
+   }
+
/* Change the order to include the device */
std = dev_get_priv(bootstd);
old_order = std->bootdev_order;
@@ -556,7 +565,7 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, 
const char *mmc_dev)
  */
 static int prep_mmc4_bootdev(struct unit_test_state *uts)
 {
-   ut_assertok(prep_mmc_bootdev(uts, "mmc4"));
+   ut_assertok(prep_mmc_bootdev(uts, "mmc4", false));
 
return 0;
 }
@@ -963,3 +972,23 @@ static int bootflow_cmdline(struct unit_test_state *uts)
return 0;
 }
 BOOTSTD_TEST(bootflow_cmdline, 0);
+
+/* Test ChromiumOS bootmeth */
+static int bootflow_cros(struct unit_test_state *uts)
+{
+   ut_assertok(prep_mmc_bootdev(uts, "mmc5", true));
+   ut_assertok(run_command("bootflow list", 0));
+
+   ut_assert_nextlinen("Showing all");
+   ut_assert_nextlinen("Seq");
+   ut_assert_nextlinen("---");
+   ut_assert_nextlinen("  0  extlinux");
+   ut_assert_nextlinen("  1  cros ready   mmc  2  
mmc5.bootdev.whole   ");
+   ut_assert_nextlinen("---");
+   ut_assert_skip_to_line("(2 bootflows, 2 valid)");
+
+   ut_assert_console_end();
+
+   return 0;
+}
+BOOTSTD_TEST(bootflow_cros, 0);
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index 3cc41c2ffb13..856eaf1b7f22 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
 
+import collections
 import getpass
 import gzip
 import os
@@ -282,6 +283,146 @@ label Fedora-Workstation-armhfp-31-1.9 
(5.3.7-301.fc31.armv7hl)
 copy_prepared_image(cons, mmc_dev, fname)
 
 
+def setup_cros_image(cons):
+"""Create a 20MB disk image with ChromiumOS partitions"""
+Partition = collections.namedtuple('part', 'sta

[PATCH 18/24] bootstd: test: Allow binding and using any mmc device

2023-08-13 Thread Simon Glass
We currently use mmc4 for tests. Update the function which sets this up
so that it can handle any device.

Signed-off-by: Simon Glass 
---

 test/boot/bootflow.c | 28 ++--
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 649237a9e229..54a878c4bd5d 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -508,21 +508,24 @@ static int bootflow_cmd_boot(struct unit_test_state *uts)
 BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
 
 /**
- * prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake 
Armbian
+ * prep_mmc_bootdev() - Set up an mmc bootdev so we can access other distros
  *
  * @uts: Unit test state
+ * @mmc_dev: MMC device to use, e.g. "mmc4"
  * Returns 0 on success, -ve on failure
  */
-static int prep_mmc4_bootdev(struct unit_test_state *uts)
+static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev)
 {
-   static const char *order[] = {"mmc2", "mmc1", "mmc4", NULL};
+   const char *order[] = {"mmc2", "mmc1", mmc_dev, NULL};
struct udevice *dev, *bootstd;
struct bootstd_priv *std;
const char **old_order;
-   ofnode node;
+   ofnode root, node;
 
/* Enable the mmc4 node since we need a second bootflow */
-   node = ofnode_path("/mmc4");
+   root = oftree_root(oftree_default());
+   node = ofnode_find_subnode(root, mmc_dev);
+   ut_assert(ofnode_valid(node));
ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
 
/* Enable the script bootmeth too */
@@ -530,7 +533,7 @@ static int prep_mmc4_bootdev(struct unit_test_state *uts)
ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_script),
"bootmeth_script", 0, ofnode_null(), &dev));
 
-   /* Change the order to include mmc4 */
+   /* Change the order to include the device */
std = dev_get_priv(bootstd);
old_order = std->bootdev_order;
std->bootdev_order = order;
@@ -545,6 +548,19 @@ static int prep_mmc4_bootdev(struct unit_test_state *uts)
return 0;
 }
 
+/**
+ * prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake 
Armbian
+ *
+ * @uts: Unit test state
+ * Returns 0 on success, -ve on failure
+ */
+static int prep_mmc4_bootdev(struct unit_test_state *uts)
+{
+   ut_assertok(prep_mmc_bootdev(uts, "mmc4"));
+
+   return 0;
+}
+
 /* Check 'bootflow menu' to select a bootflow */
 static int bootflow_cmd_menu(struct unit_test_state *uts)
 {
-- 
2.41.0.640.ga95def55d0-goog



[PATCH 17/24] bootflow: Show an empty filename when there is none

2023-08-13 Thread Simon Glass
At present 'bootflow list' shows  for the filename when it is not
present. Show an empty string instead, since that is more user-friendly.

Signed-off-by: Simon Glass 
---

 cmd/bootflow.c   |  2 +-
 test/boot/bootflow.c | 22 --
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index 3c3abaf8a3b2..300ad3aaa760 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -71,7 +71,7 @@ static void show_bootflow(int index, struct bootflow *bflow, 
bool errors)
printf("%3x  %-11s  %-6s  %-9.9s %4x  %-25.25s %s\n", index,
   bflow->method->name, bootflow_state_get_name(bflow->state),
   bflow->dev ? dev_get_uclass_name(dev_get_parent(bflow->dev)) :
-  "(none)", bflow->part, bflow->name, bflow->fname);
+  "(none)", bflow->part, bflow->name, bflow->fname ?: "");
if (errors)
report_bootflow_err(bflow, bflow->err);
 }
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 8a4e090e9bcf..649237a9e229 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -167,21 +167,22 @@ static int bootflow_cmd_scan_e(struct unit_test_state 
*uts)
ut_assert_nextline("Seq  Method   State   UclassPart  Name  
Filename");
ut_assert_nextlinen("---");
ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
-   ut_assert_nextline("  0  extlinux media   mmc  0  
mmc2.bootdev.whole");
+   ut_assert_nextline("  0  extlinux media   mmc  0  
mmc2.bootdev.whole");
ut_assert_nextline(" ** No partition found, err=-93: Protocol not 
supported");
-   ut_assert_nextline("  1  efi  media   mmc  0  
mmc2.bootdev.whole");
+   ut_assert_nextline("  1  efi  media   mmc  0  
mmc2.bootdev.whole");
ut_assert_nextline(" ** No partition found, err=-93: Protocol not 
supported");
 
ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
-   ut_assert_nextline("  2  extlinux media   mmc  0  
mmc1.bootdev.whole");
+   ut_assert_nextline("  2  extlinux media   mmc  0  
mmc1.bootdev.whole");
ut_assert_nextline(" ** No partition found, err=-2: No such file or 
directory");
-   ut_assert_nextline("  3  efi  media   mmc  0  
mmc1.bootdev.whole");
+   ut_assert_nextline("  3  efi  media   mmc  0  
mmc1.bootdev.whole");
ut_assert_nextline(" ** No partition found, err=-2: No such file or 
directory");
ut_assert_nextline("  4  extlinux ready   mmc  1  
mmc1.bootdev.part_1   /extlinux/extlinux.conf");
ut_assert_nextline("  5  efi  fs  mmc  1  
mmc1.bootdev.part_1   efi/boot/bootsbox.efi");
 
ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':");
-   ut_assert_skip_to_line(" 3f  efi  media   mmc  0  
mmc0.bootdev.whole");
+   ut_assert_skip_to_line(
+   " 3f  efi  media   mmc  0  mmc0.bootdev.whole   
 ");
ut_assert_nextline(" ** No partition found, err=-93: Protocol not 
supported");
ut_assert_nextline("No more bootdevs");
ut_assert_nextlinen("---");
@@ -192,10 +193,11 @@ static int bootflow_cmd_scan_e(struct unit_test_state 
*uts)
ut_assert_nextline("Showing all bootflows");
ut_assert_nextline("Seq  Method   State   UclassPart  Name  
Filename");
ut_assert_nextlinen("---");
-   ut_assert_nextline("  0  extlinux media   mmc  0  
mmc2.bootdev.whole");
-   ut_assert_nextline("  1  efi  media   mmc  0  
mmc2.bootdev.whole");
-   ut_assert_skip_to_line("  4  extlinux ready   mmc  1  
mmc1.bootdev.part_1   /extlinux/extlinux.conf");
-   ut_assert_skip_to_line(" 3f  efi  media   mmc  0  
mmc0.bootdev.whole");
+   ut_assert_nextline("  0  extlinux media   mmc  0  
mmc2.bootdev.whole");
+   ut_assert_nextline("  1  efi  media   mmc  0  
mmc2.bootdev.whole");
+   ut_assert_skip_to_line(
+   "  4  extlinux ready   mmc  1  mmc1.bootdev.part_1  
 /extlinux/extlinux.conf");
+   ut_assert_skip_to_line(" 3f  efi  media   mmc  0  
mmc0.bootdev.whole");
ut_assert_nextlinen("---");
ut_assert_nextline("(64 bootflows, 1 valid)");
ut_assert_console_end();
@@ -384,7 +386,7 @@ static int bootflow_system(struct unit_test_state *uts)
console_record_reset_enable();
ut_assertok(run_command("bootflow scan -lH", 0));
ut_assert_skip_to_line(
-   "  0  efi_mgr  ready   (none)   0 
 ");
+   "  0  efi_mgr  ready   (n

[PATCH 16/24] test: Move 1MB.fat32.img and 2MB.ext2.img

2023-08-13 Thread Simon Glass
These are currently created in the source directory, which is not ideal.
Move them to the persistent-data directory instead. Update the test so
skip validating the filename, since it now includes a full path.

Signed-off-by: Simon Glass 
---

 test/dm/host.c | 44 ++
 test/py/tests/fs_helper.py |  6 ++
 test/py/tests/test_ut.py   |  6 ++
 3 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/test/dm/host.c b/test/dm/host.c
index 355ba7770afa..85f21f9839e2 100644
--- a/test/dm/host.c
+++ b/test/dm/host.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -15,9 +16,6 @@
 #include 
 #include 
 
-static const char filename[] = "2MB.ext2.img";
-static const char filename2[] = "1MB.fat32.img";
-
 /* Basic test of host interface */
 static int dm_test_host(struct unit_test_state *uts)
 {
@@ -25,6 +23,7 @@ static int dm_test_host(struct unit_test_state *uts)
struct udevice *dev, *part, *chk, *blk;
struct host_sb_plat *plat;
struct blk_desc *desc;
+   char fname[256];
ulong mem_start;
loff_t actwrite;
 
@@ -40,13 +39,15 @@ static int dm_test_host(struct unit_test_state *uts)
ut_assert(label != plat->label);
ut_asserteq(0, plat->fd);
 
-   /* Attach a file created in test_host.py */
-   ut_assertok(host_attach_file(dev, filename));
+   /* Attach a file created in test_ut_dm_init */
+   ut_assertok(os_persistent_file(fname, sizeof(fname), "2MB.ext2.img"));
+
+   ut_assertok(host_attach_file(dev, fname));
ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
ut_asserteq_ptr(chk, dev);
 
-   ut_asserteq_str(filename, plat->filename);
-   ut_assert(filename != plat->filename);
+   ut_asserteq_str(fname, plat->filename);
+   ut_assert(fname != plat->filename);
ut_assert(plat->fd != 0);
 
/* Get the block device */
@@ -79,12 +80,14 @@ static int dm_test_host_dup(struct unit_test_state *uts)
 {
static char label[] = "test";
struct udevice *dev, *chk;
+   char fname[256];
 
ut_asserteq(0, uclass_id_count(UCLASS_HOST));
ut_assertok(host_create_device(label, true, &dev));
 
-   /* Attach a file created in test_host.py */
-   ut_assertok(host_attach_file(dev, filename));
+   /* Attach a file created in test_ut_dm_init */
+   ut_assertok(os_persistent_file(fname, sizeof(fname), "2MB.ext2.img"));
+   ut_assertok(host_attach_file(dev, fname));
ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
ut_asserteq_ptr(chk, dev);
ut_asserteq(1, uclass_id_count(UCLASS_HOST));
@@ -92,8 +95,10 @@ static int dm_test_host_dup(struct unit_test_state *uts)
/* Create another device with the same label (should remove old one) */
ut_assertok(host_create_device(label, true, &dev));
 
-   /* Attach a different file created in test_host.py */
-   ut_assertok(host_attach_file(dev, filename2));
+   /* Attach a different file created in test_ut_dm_init */
+   ut_assertok(os_persistent_file(fname, sizeof(fname), "1MB.fat32.img"));
+   ut_assertok(host_attach_file(dev, fname));
+
ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
ut_asserteq_ptr(chk, dev);
 
@@ -109,6 +114,7 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
 {
struct udevice *dev, *blk;
struct blk_desc *desc;
+   char fname[256];
 
console_record_reset();
 
@@ -117,7 +123,8 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
ut_assert_nextline("dev   blocks label   path");
ut_assert_console_end();
 
-   ut_assertok(run_commandf("host bind -r test2 %s", filename));
+   ut_assertok(os_persistent_file(fname, sizeof(fname), "2MB.ext2.img"));
+   ut_assertok(run_commandf("host bind -r test2 %s", fname));
 
/* Check the -r flag worked */
ut_assertok(uclass_first_device_err(UCLASS_HOST, &dev));
@@ -127,10 +134,11 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
 
ut_assertok(run_command("host info", 0));
ut_assert_nextline("dev   blocks label   path");
-   ut_assert_nextline("  0 4096 test2   2MB.ext2.img");
+   ut_assert_nextlinen("  0 4096 test2");
ut_assert_console_end();
 
-   ut_assertok(run_commandf("host bind fat %s", filename2));
+   ut_assertok(os_persistent_file(fname, sizeof(fname), "1MB.fat32.img"));
+   ut_assertok(run_commandf("host bind fat %s", fname));
 
/* Check it is not removable (no '-r') */
ut_assertok(uclass_next_device_err(&dev));
@@ -140,8 +148,8 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
 
ut_assertok(run_command("host info", 0));
ut_assert_nextline("dev   blocks label   path");
-   ut_assert_nextline("  0 4096 test2   2MB.e

[PATCH 15/24] sandbox: Add a way to access persistent test files

2023-08-13 Thread Simon Glass
Some pytests create files in the persistent-data directory. It is useful
to be able to access these files in C tests. Add a function which can
locate a file given its leaf name, using the environment variable set
up in test/py/conftest.py

Signed-off-by: Simon Glass 
---

 arch/sandbox/cpu/os.c | 24 
 include/os.h  | 10 ++
 2 files changed, 34 insertions(+)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 9e93a0fa571f..85d0d6a17035 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -258,6 +258,30 @@ int os_unmap(void *buf, int size)
return 0;
 }
 
+int os_persistent_file(char *buf, int maxsize, const char *fname)
+{
+   const char *dirname = getenv("U_BOOT_PERSISTENT_DATA_DIR");
+   char *ptr;
+   int len;
+
+   len = strlen(fname) + (dirname ? strlen(dirname) + 1 : 0) + 1;
+   if (len > maxsize)
+   return -ENOSPC;
+
+   ptr = buf;
+   if (dirname) {
+   strcpy(ptr, dirname);
+   ptr += strlen(dirname);
+   *ptr++ = '/';
+   }
+   strcpy(ptr, fname);
+
+   if (access(buf, F_OK) == -1)
+   return -ENOENT;
+
+   return 0;
+}
+
 /* Restore tty state when we exit */
 static struct termios orig_term;
 static bool term_setup;
diff --git a/include/os.h b/include/os.h
index 968412b0a822..fc8a1b15cbf0 100644
--- a/include/os.h
+++ b/include/os.h
@@ -98,6 +98,16 @@ int os_close(int fd);
  */
 int os_unlink(const char *pathname);
 
+/** os_persistent_fname() - Find the path to a test file
+ *
+ * @buf: Buffer to hold path
+ * @maxsize: Maximum size of buffer
+ * @fname: Leaf filename to find
+ * Returns: 0 on success, -ENOENT if file is not found, -ENOSPC if the buffer 
is
+ * too small
+ */
+int os_persistent_file(char *buf, int maxsize, const char *fname);
+
 /**
  * os_exit() - access to the OS exit() system call
  *
-- 
2.41.0.640.ga95def55d0-goog



[PATCH 14/24] uuid: Move function comments to header file

2023-08-13 Thread Simon Glass
These should be in the header file for easy browsing, not in the source
code. Move them and add a missing Return on one of the functions.

Signed-off-by: Simon Glass 
---

 include/uuid.h | 94 ++
 lib/uuid.c | 86 -
 2 files changed, 94 insertions(+), 86 deletions(-)

diff --git a/include/uuid.h b/include/uuid.h
index 4a4883d3b5b6..61decb79c9b5 100644
--- a/include/uuid.h
+++ b/include/uuid.h
@@ -8,6 +8,51 @@
 
 #include 
 
+/*
+ * UUID - Universally Unique IDentifier - 128 bits unique number.
+ *There are 5 versions and one variant of UUID defined by RFC4122
+ *specification. A UUID contains a set of fields. The set varies
+ *depending on the version of the UUID, as shown below:
+ *- time, MAC address(v1),
+ *- user ID(v2),
+ *- MD5 of name or URL(v3),
+ *- random data(v4),
+ *- SHA-1 of name or URL(v5),
+ *
+ * Layout of UUID:
+ * timestamp - 60-bit: time_low, time_mid, time_hi_and_version
+ * version   - 4 bit (bit 4 through 7 of the time_hi_and_version)
+ * clock seq - 14 bit: clock_seq_hi_and_reserved, clock_seq_low
+ * variant:  - bit 6 and 7 of clock_seq_hi_and_reserved
+ * node  - 48 bit
+ *
+ * source: https://www.ietf.org/rfc/rfc4122.txt
+ *
+ * UUID binary format (16 bytes):
+ *
+ * 4B-2B-2B-2B-6B (big endian - network byte order)
+ *
+ * UUID string is 36 length of characters (36 bytes):
+ *
+ * 0914   19   24
+ * ----
+ *be be   be   be   be
+ *
+ * where x is a hexadecimal character. Fields are separated by '-'s.
+ * When converting to a binary UUID, le means the field should be converted
+ * to little endian and be means it should be converted to big endian.
+ *
+ * UUID is also used as GUID (Globally Unique Identifier) with the same binary
+ * format but it differs in string format like below.
+ *
+ * GUID:
+ * 0914   19   24
+ * ----
+ *le le   le   be   be
+ *
+ * GUID is used e.g. in GPT (GUID Partition Table) as a partiions unique id.
+ */
+
 /* This is structure is in big-endian */
 struct uuid {
unsigned int time_low;
@@ -36,12 +81,61 @@ struct uuid {
 #define UUID_VARIANT   0x1
 
 int uuid_str_valid(const char *uuid);
+
+/*
+ * uuid_str_to_bin() - convert string UUID or GUID to big endian binary data.
+ *
+ * @param uuid_str - pointer to UUID or GUID string [37B] or GUID shorcut
+ * @param uuid_bin - pointer to allocated array for big endian output [16B]
+ * @str_format - UUID string format: 0 - UUID; 1 - GUID
+ * Return: 0 if OK, -EINVAL if the string is not a valid UUID
+ */
 int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
int str_format);
+
+/*
+ * uuid_bin_to_str() - convert big endian binary data to string UUID or GUID.
+ *
+ * @param uuid_bin:pointer to binary data of UUID (big endian) [16B]
+ * @param uuid_str:pointer to allocated array for output string [37B]
+ * @str_format:bit 0: 0 - UUID; 1 - GUID
+ * bit 1: 0 - lower case; 2 - upper case
+ */
 void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str,
 int str_format);
+
+/*
+ * uuid_guid_get_bin() - this function get GUID bin for string
+ *
+ * @param guid_str - pointer to partition type string
+ * @param guid_bin - pointer to allocated array for big endian output [16B]
+ */
 int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin);
+
+/*
+ * uuid_guid_get_str() - this function get string for GUID.
+ *
+ * @param guid_bin - pointer to string with partition type guid [16B]
+ *
+ * Returns NULL if the type GUID is not known.
+ */
 const char *uuid_guid_get_str(const unsigned char *guid_bin);
+
+/*
+ * gen_rand_uuid() - this function generates a random binary UUID version 4.
+ *   In this version all fields beside 4 bits of version and
+ *   2 bits of variant are randomly generated.
+ *
+ * @param uuid_bin - pointer to allocated array [16B]. Output is in big endian.
+ */
 void gen_rand_uuid(unsigned char *uuid_bin);
+
+/*
+ * gen_rand_uuid_str() - this function generates UUID v4 (random) in two string
+ *   formats UUID or GUID.
+ *
+ * @param uuid_str - pointer to allocated array [37B].
+ * @param  - uuid output type: UUID - 0, GUID - 1
+ */
 void gen_rand_uuid_str(char *uuid_str, int str_format);
 #endif
diff --git a/lib/uuid.c b/lib/uuid.c
index ab30fbf9152f..61cd146d63ea 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -19,50 +19,6 @@
 #include 
 #include 
 
-/*
- * UUID - Universally Unique IDentifier - 128 bits unique number.
- *There are 5 versions and one variant of UUID defined by RFC4122
- *specification. A UUID contains a set of fields. The set varies
- *depending on the version of the UUID, as shown below:
- *- time

[PATCH 13/24] dm: core: Correct error handling when event fails

2023-08-13 Thread Simon Glass
Follow the correct path in device_probe() when and event handler fails.
This avoids getting into a strange state where the device appears to be
activated but is not.

Signed-off-by: Simon Glass 
---

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

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 6e26b64fb812..60f8d6700ad4 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -598,9 +598,10 @@ int device_probe(struct udevice *dev)
 
ret = device_notify(dev, EVT_DM_POST_PROBE);
if (ret)
-   return ret;
+   goto fail_event;
 
return 0;
+fail_event:
 fail_uclass:
if (device_remove(dev, DM_REMOVE_NORMAL)) {
dm_warn("%s: Device '%s' failed to remove on error path\n",
-- 
2.41.0.640.ga95def55d0-goog



[PATCH 12/24] fs/erofs: Quieten test for filesystem presence

2023-08-13 Thread Simon Glass
At present listing a partition produces lots of errors about this
filesystem:

   => part list mmc 4
   cannot find valid erofs superblock
   cannot find valid erofs superblock
   cannot read erofs superblock: -5
   [9 more similar lines]

Use debugging rather than errors when unable to find a signature, as is
done with other filesystems.

Signed-off-by: Simon Glass 
---

 fs/erofs/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index d33926281b47..d405d488fd27 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -68,14 +68,14 @@ int erofs_read_superblock(void)
 
ret = erofs_blk_read(data, 0, erofs_blknr(sizeof(data)));
if (ret < 0) {
-   erofs_err("cannot read erofs superblock: %d", ret);
+   erofs_dbg("cannot read erofs superblock: %d", ret);
return -EIO;
}
dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
 
ret = -EINVAL;
if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) {
-   erofs_err("cannot find valid erofs superblock");
+   erofs_dbg("cannot find valid erofs superblock");
return ret;
}
 
-- 
2.41.0.640.ga95def55d0-goog



[PATCH 11/24] part: efi: Add debugging for the signature check

2023-08-13 Thread Simon Glass
Add a little more debugging for the initial signature check. Drop the
pointless check for NULL. Also set a log category while we are here.

Signed-off-by: Simon Glass 
---

 disk/part_efi.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 208675213822..39382c5faee0 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -9,6 +9,9 @@
  *   when CONFIG_SYS_64BIT_LBA is not defined, lbaint_t is 32 bits; this
  *   limits the maximum size of addressable storage to < 2 tebibytes
  */
+
+#define LOG_CATEGORY LOGC_FS
+
 #include 
 #include 
 #include 
@@ -976,17 +979,23 @@ static int pmbr_part_valid(struct partition *part)
 /*
  * is_pmbr_valid(): test Protective MBR for validity
  *
+ * @mbr: Pointer to Master Boot-Record data
+ *
  * Returns: 1 if PMBR is valid, 0 otherwise.
  * Validity depends on two things:
  *  1) MSDOS signature is in the last two bytes of the MBR
  *  2) One partition of type 0xEE is found, checked by pmbr_part_valid()
  */
-static int is_pmbr_valid(legacy_mbr * mbr)
+static int is_pmbr_valid(legacy_mbr *mbr)
 {
+   uint sig = le16_to_cpu(mbr->signature);
int i = 0;
 
-   if (!mbr || le16_to_cpu(mbr->signature) != MSDOS_MBR_SIGNATURE)
+   if (sig != MSDOS_MBR_SIGNATURE) {
+   log_debug("Invalid signature %x\n", sig);
return 0;
+   }
+   log_debug("Signature %x valid\n", sig);
 
for (i = 0; i < 4; i++) {
if (pmbr_part_valid(&mbr->partition_record[i])) {
-- 
2.41.0.640.ga95def55d0-goog



[PATCH 10/24] part: Add an accessor for struct disk_partition sys_ind

2023-08-13 Thread Simon Glass
This field is only present when a CONFIG is set. To avoid annoying #ifdefs
in the source code, add an accessor. Update the only usage.

Note that the accessor is optional. It can be omitted if it is known that
the option is enabled.

Signed-off-by: Simon Glass 
---

 boot/bootdev-uclass.c |  7 +++
 include/part.h| 12 
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 3f2c8d7153a4..00dc28e623a2 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -184,12 +184,11 @@ int bootdev_find_in_blk(struct udevice *dev, struct 
udevice *blk,
if (ret)
return log_msg_ret("fs", ret);
 
-   /* Use an #ifdef due to info.sys_ind */
-#ifdef CONFIG_DOS_PARTITION
log_debug("%s: Found partition %x type %x fstype %d\n",
- blk->name, bflow->part, info.sys_ind,
+ blk->name, bflow->part,
+ IS_ENABLED(CONFIG_DOS_PARTITION) ?
+ disk_partition_sys_ind(&info) : 0,
  ret ? -1 : fs_get_type());
-#endif
bflow->blk = blk;
bflow->state = BOOTFLOWST_FS;
}
diff --git a/include/part.h b/include/part.h
index aa96516ba353..c3de317fcce8 100644
--- a/include/part.h
+++ b/include/part.h
@@ -135,6 +135,18 @@ static inline void disk_partition_clr_type_guid(struct 
disk_partition *info)
 #endif
 }
 
+/* Accessors for struct disk_partition field ->sys_ind */
+extern int __invalid_use_of_disk_partition_sys_ind;
+
+static inline uint disk_partition_sys_ind(const struct disk_partition *info)
+{
+#ifdef CONFIG_DOS_PARTITION
+   return info->sys_ind;
+#else
+   return __invalid_use_of_disk_partition_sys_ind;
+#endif
+}
+
 struct disk_part {
int partnum;
struct disk_partition gpt_part_info;
-- 
2.41.0.640.ga95def55d0-goog



[PATCH 09/24] part: Add accessors for struct disk_partition type_uuid

2023-08-13 Thread Simon Glass
This field is only present when a CONFIG is set. To avoid annoying #ifdefs
in the source code, add accessors. Update all code to use it.

Note that the accessor is optional. It can be omitted if it is known that
the option is enabled.

Signed-off-by: Simon Glass 
---

 disk/part.c |  8 ++--
 disk/part_efi.c |  9 +
 include/part.h  | 28 
 3 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index 91c6ac42cc83..72241b7b232c 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -370,9 +370,7 @@ int part_get_info_by_type(struct blk_desc *desc, int part, 
int part_type,
if (blk_enabled()) {
/* The common case is no UUID support */
disk_partition_clr_uuid(info);
-#ifdef CONFIG_PARTITION_TYPE_GUID
-   info->type_guid[0] = 0;
-#endif
+   disk_partition_clr_type_guid(info);
 
if (part_type == PART_TYPE_UNKNOWN) {
drv = part_driver_lookup_type(desc);
@@ -415,9 +413,7 @@ int part_get_info_whole_disk(struct blk_desc *desc,
strcpy((char *)info->type, BOOT_PART_TYPE);
strcpy((char *)info->name, "Whole Disk");
disk_partition_clr_uuid(info);
-#ifdef CONFIG_PARTITION_TYPE_GUID
-   info->type_guid[0] = 0;
-#endif
+   disk_partition_clr_type_guid(info);
 
return 0;
 }
diff --git a/disk/part_efi.c b/disk/part_efi.c
index a6f7375cd38a..208675213822 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -294,10 +294,11 @@ int part_get_info_efi(struct blk_desc *desc, int part,
(char *)disk_partition_uuid(info),
UUID_STR_FORMAT_GUID);
}
-#ifdef CONFIG_PARTITION_TYPE_GUID
-   uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b,
-   info->type_guid, UUID_STR_FORMAT_GUID);
-#endif
+   if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) {
+   uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b,
+   (char *)disk_partition_type_uuid(info),
+   UUID_STR_FORMAT_GUID);
+   }
 
log_debug("start 0x" LBAF ", size 0x" LBAF ", name %s\n", info->start,
  info->size, info->name);
diff --git a/include/part.h b/include/part.h
index 303ccd036754..aa96516ba353 100644
--- a/include/part.h
+++ b/include/part.h
@@ -107,6 +107,34 @@ static inline void disk_partition_clr_uuid(struct 
disk_partition *info)
 #endif
 }
 
+/* Accessors for struct disk_partition field ->type_guid */
+extern char *__invalid_use_of_disk_partition_type_uuid;
+
+static inline const
+char *disk_partition_type_uuid(const struct disk_partition *info)
+{
+#ifdef CONFIG_PARTITION_TYPE_GUID
+   return info->type_guid;
+#else
+   return __invalid_use_of_disk_partition_type_uuid;
+#endif
+}
+
+static inline void disk_partition_set_type_guid(struct disk_partition *info,
+   const char *val)
+{
+#ifdef CONFIG_PARTITION_TYPE_GUID
+   strlcpy(info->type_guid, val, UUID_STR_LEN + 1);
+#endif
+}
+
+static inline void disk_partition_clr_type_guid(struct disk_partition *info)
+{
+#ifdef CONFIG_PARTITION_TYPE_GUID
+   *info->type_guid = '\0';
+#endif
+}
+
 struct disk_part {
int partnum;
struct disk_partition gpt_part_info;
-- 
2.41.0.640.ga95def55d0-goog



[PATCH 08/24] part: Add accessors for struct disk_partition uuid

2023-08-13 Thread Simon Glass
This field is only present when a CONFIG is set. To avoid annoying #ifdefs
in the source code, add accessors. Update all code to use it.

Note that the accessor is optional. It can be omitted if it is known that
the option is enabled.

Signed-off-by: Simon Glass 
---

 cmd/gpt.c   | 10 --
 disk/part.c |  8 ++--
 disk/part_dos.c | 17 -
 disk/part_efi.c | 31 ---
 fs/fat/fat.c|  4 +---
 include/part.h  | 27 +++
 6 files changed, 58 insertions(+), 39 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 007a68eaa72a..8969efba8c80 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -211,12 +211,10 @@ static struct disk_part *allocate_disk_part(struct 
disk_partition *info,
PART_TYPE_LEN);
newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0';
newpart->gpt_part_info.bootable = info->bootable;
-#ifdef CONFIG_PARTITION_UUIDS
-   strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid,
-   UUID_STR_LEN);
-   /* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars 
*/
-   newpart->gpt_part_info.uuid[UUID_STR_LEN] = '\0';
-#endif
+   if (IS_ENABLED(CONFIG_PARTITION_UUIDS)) {
+   strlcpy(newpart->gpt_part_info.uuid, disk_partition_uuid(info),
+   UUID_STR_LEN + 1);
+   }
newpart->partnum = partnum;
 
return newpart;
diff --git a/disk/part.c b/disk/part.c
index 9190e8806187..91c6ac42cc83 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -368,10 +368,8 @@ int part_get_info_by_type(struct blk_desc *desc, int part, 
int part_type,
struct part_driver *drv;
 
if (blk_enabled()) {
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
/* The common case is no UUID support */
-   info->uuid[0] = 0;
-#endif
+   disk_partition_clr_uuid(info);
 #ifdef CONFIG_PARTITION_TYPE_GUID
info->type_guid[0] = 0;
 #endif
@@ -416,9 +414,7 @@ int part_get_info_whole_disk(struct blk_desc *desc,
info->bootable = 0;
strcpy((char *)info->type, BOOT_PART_TYPE);
strcpy((char *)info->name, "Whole Disk");
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
-   info->uuid[0] = 0;
-#endif
+   disk_partition_clr_uuid(info);
 #ifdef CONFIG_PARTITION_TYPE_GUID
info->type_guid[0] = 0;
 #endif
diff --git a/disk/part_dos.c b/disk/part_dos.c
index f94d2172d772..f576e9368edb 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -230,10 +230,8 @@ static int part_get_info_extended(struct blk_desc *desc,
return -1;
}
 
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
-   if (!ext_part_sector)
+   if (CONFIG_IS_ENABLED(PARTITION_UUIDS) && !ext_part_sector)
disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]);
-#endif
 
/* Print all primary/logical partitions */
pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
@@ -255,9 +253,12 @@ static int part_get_info_extended(struct blk_desc *desc,
/* sprintf(info->type, "%d, pt->sys_ind); */
strcpy((char *)info->type, "U-Boot");
info->bootable = get_bootable(pt);
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
-   sprintf(info->uuid, "%08x-%02x", disksig, part_num);
-#endif
+   if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
+   char str[12];
+
+   sprintf(str, "%08x-%02x", disksig, part_num);
+   disk_partition_set_uuid(info, str);
+   }
info->sys_ind = pt->sys_ind;
return 0;
}
@@ -291,9 +292,7 @@ static int part_get_info_extended(struct blk_desc *desc,
info->blksz = DOS_PART_DEFAULT_SECTOR;
info->bootable = 0;
strcpy((char *)info->type, "U-Boot");
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
-   info->uuid[0] = 0;
-#endif
+   disk_partition_clr_uuid(info);
return 0;
}
 
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 4ac21868d088..a6f7375cd38a 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -289,10 +289,11 @@ int part_get_info_efi(struct blk_desc *desc, int part,
 print_efiname(&gpt_pte[part - 1]));
strcpy((char *)info->type, "U-Boot");
info->bootable = get_bootable(&gpt_pte[part - 1]);
-#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
-   uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid,
-   UUID_STR_FORMAT_GUID);
-#endif
+   if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
+   uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b,
+   (char *)disk_partition_uuid(info),
+   UUID_STR_FORMAT_GUID);
+   }
 #ifdef CONFIG_PARTITION_TYPE_GUID
uuid_bin_to_str(g

[PATCH 07/24] part: Add comments for static functions

2023-08-13 Thread Simon Glass
Some internal functions could do with a few comments, to explain what they
do. Add these, to make the code easier to follow.

Signed-off-by: Simon Glass 
---

 disk/part.c | 32 
 1 file changed, 32 insertions(+)

diff --git a/disk/part.c b/disk/part.c
index 8035dcb8a429..9190e8806187 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -26,6 +26,12 @@
 /* Check all partition types */
 #define PART_TYPE_ALL  -1
 
+/**
+ * part_driver_get_type() - Get a driver given its type
+ *
+ * @part_type: Partition type to find the driver for
+ * Return: Driver for that type, or NULL if none
+ */
 static struct part_driver *part_driver_get_type(int part_type)
 {
struct part_driver *drv =
@@ -42,6 +48,22 @@ static struct part_driver *part_driver_get_type(int 
part_type)
return NULL;
 }
 
+/**
+ * part_driver_lookup_type() - Look up the partition driver for a blk device
+ *
+ * If @desc->part_type is PART_TYPE_UNKNOWN, this checks each parition driver
+ * against the blk device to see if there is a valid partition table acceptable
+ * to that driver.
+ *
+ * If @desc->part_type is already set, it just returns the driver for that
+ * type, without testing if the driver can find a valid partition on the
+ * descriptor.
+ *
+ * On success it updates @desc->part_type if set to PART_TYPE_UNKNOWN on entry
+ *
+ * @dev_desc: Device descriptor
+ * Return: Driver found, or NULL if none
+ */
 static struct part_driver *part_driver_lookup_type(struct blk_desc *desc)
 {
struct part_driver *drv =
@@ -83,6 +105,16 @@ int part_get_type_by_name(const char *name)
return PART_TYPE_UNKNOWN;
 }
 
+/**
+ * get_dev_hwpart() - Get the descriptor for a device with hardware partitions
+ *
+ * @ifname:Interface name (e.g. "ide", "scsi")
+ * @dev:   Device number (0 for first device on that interface, 1 for
+ * second, etc.
+ * @hwpart: Hardware partition, or 0 if none (used for MMC)
+ * Return: pointer to the block device, or NULL if not available, or an
+ *error occurred.
+ */
 static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
 {
struct blk_desc *desc;
-- 
2.41.0.640.ga95def55d0-goog



[PATCH 05/24] part: iso: Use desc instead of dev_desc

2023-08-13 Thread Simon Glass
The dev_ prefix is a hangover from the pre-driver model days. The device
is now a different thing, with driver model. Update the iso code to
just use 'desc'.

Signed-off-by: Simon Glass 
---

 disk/part_iso.c | 52 -
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/disk/part_iso.c b/disk/part_iso.c
index 4cd619bf46d3..6ac6d95be921 100644
--- a/disk/part_iso.c
+++ b/disk/part_iso.c
@@ -46,7 +46,7 @@ unsigned long iso_dread(struct blk_desc *block_dev, lbaint_t 
start,
 }
 
 /* only boot records will be listed as valid partitions */
-int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
+int part_get_info_iso_verb(struct blk_desc *desc, int part_num,
   struct disk_partition *info, int verb)
 {
int i,offset,entry_num;
@@ -58,23 +58,23 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int 
part_num,
iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf;
iso_init_def_entry_t *pide;
 
-   if ((dev_desc->blksz != CD_SECTSIZE) && (dev_desc->blksz != 512))
+   if (desc->blksz != CD_SECTSIZE && desc->blksz != 512)
return -1;
 
/* the first sector (sector 0x10) must be a primary volume desc */
blkaddr=PVD_OFFSET;
-   if (iso_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
+   if (iso_dread(desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
return -1;
if(ppr->desctype!=0x01) {
if(verb)
printf ("** First descriptor is NOT a primary desc on 
%d:%d **\n",
-   dev_desc->devnum, part_num);
+   desc->devnum, part_num);
return (-1);
}
if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) {
if(verb)
printf ("** Wrong ISO Ident: %s on %d:%d **\n",
-   ppr->stand_ident, dev_desc->devnum, part_num);
+   ppr->stand_ident, desc->devnum, part_num);
return (-1);
}
lastsect = le32_to_cpu(ppr->firstsek_LEpathtab1_LE);
@@ -83,14 +83,14 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int 
part_num,
PRINTF(" Lastsect:%08lx\n",lastsect);
for(i=blkaddr;idesctype==0x00)
break; /* boot entry found */
if(ppr->desctype==0xff) {
if(verb)
printf ("** No valid boot catalog found on 
%d:%d **\n",
-   dev_desc->devnum, part_num);
+   desc->devnum, part_num);
return (-1);
}
}
@@ -98,15 +98,15 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int 
part_num,
if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) {
if(verb)
printf ("** Wrong El Torito ident: %s on %d:%d **\n",
-   pbr->ident_str, dev_desc->devnum, part_num);
+   pbr->ident_str, desc->devnum, part_num);
return (-1);
}
bootaddr = get_unaligned_le32(pbr->pointer);
PRINTF(" Boot Entry at: %08lX\n",bootaddr);
-   if (iso_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
+   if (iso_dread(desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
if(verb)
printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
-   bootaddr, dev_desc->devnum, part_num);
+   bootaddr, desc->devnum, part_num);
return (-1);
}
chksum=0;
@@ -116,20 +116,20 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int 
part_num,
if(chksum!=0) {
if(verb)
printf("** Checksum Error in booting catalog validation 
entry on %d:%d **\n",
-  dev_desc->devnum, part_num);
+  desc->devnum, part_num);
return (-1);
}
if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) {
if(verb)
printf ("** Key 0x55 0xAA error on %d:%d **\n",
-   dev_desc->devnum, part_num);
+   desc->devnum, part_num);
return(-1);
}
 #ifdef CHECK_FOR_POWERPC_PLATTFORM
if(pve->platform!=0x01) {
if(verb)
printf ("** No PowerPC platform CD on %d:%d **\n",
-   dev_desc->devnum, part_num);
+   desc->devnum, part_num);
return(-1);
}
 #endif
@@ -137,7 +137,7 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int 
part_num,
entry_num=1;
offset=0x20;
strcpy((char *)info->type, "U-Boot");
-   part_set_generic_nam

[PATCH 06/24] part: nac: Use desc instead of dev_desc

2023-08-13 Thread Simon Glass
The dev_ prefix is a hangover from the pre-driver model days. The device
is now a different thing, with driver model. Update the mac code to
just use 'desc'.

Signed-off-by: Simon Glass 
---

 disk/part_mac.c | 59 ++---
 1 file changed, 27 insertions(+), 32 deletions(-)

diff --git a/disk/part_mac.c b/disk/part_mac.c
index ae8263f755ae..db5e203be592 100644
--- a/disk/part_mac.c
+++ b/disk/part_mac.c
@@ -31,21 +31,20 @@ extern ldiv_t ldiv (long int __numer, long int __denom);
 #endif
 
 
-static int part_mac_read_ddb(struct blk_desc *dev_desc,
-mac_driver_desc_t *ddb_p);
-static int part_mac_read_pdb(struct blk_desc *dev_desc, int part,
+static int part_mac_read_ddb(struct blk_desc *desc, mac_driver_desc_t *ddb_p);
+static int part_mac_read_pdb(struct blk_desc *desc, int part,
 mac_partition_t *pdb_p);
 
 /*
  * Test for a valid MAC partition
  */
-static int part_test_mac(struct blk_desc *dev_desc)
+static int part_test_mac(struct blk_desc *desc)
 {
ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
ulong i, n;
 
-   if (part_mac_read_ddb (dev_desc, ddesc)) {
+   if (part_mac_read_ddb(desc, ddesc)) {
/*
 * error reading Driver Descriptor Block,
 * or no valid Signature
@@ -55,8 +54,8 @@ static int part_test_mac(struct blk_desc *dev_desc)
 
n = 1;  /* assuming at least one partition */
for (i=1; i<=n; ++i) {
-   if ((blk_dread(dev_desc, i, 1, (ulong *)mpart) != 1) ||
-   (mpart->signature != MAC_PARTITION_MAGIC) ) {
+   if ((blk_dread(desc, i, 1, (ulong *)mpart) != 1) ||
+   mpart->signature != MAC_PARTITION_MAGIC) {
return (-1);
}
/* update partition count */
@@ -65,14 +64,14 @@ static int part_test_mac(struct blk_desc *dev_desc)
return (0);
 }
 
-static void part_print_mac(struct blk_desc *dev_desc)
+static void part_print_mac(struct blk_desc *desc)
 {
ulong i, n;
ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1);
ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1);
ldiv_t mb, gb;
 
-   if (part_mac_read_ddb (dev_desc, ddesc)) {
+   if (part_mac_read_ddb(desc, ddesc)) {
/*
 * error reading Driver Descriptor Block,
 * or no valid Signature
@@ -110,15 +109,15 @@ static void part_print_mac(struct blk_desc *dev_desc)
char c;
 
printf ("%4ld: ", i);
-   if (blk_dread(dev_desc, i, 1, (ulong *)mpart) != 1) {
+   if (blk_dread(desc, i, 1, (ulong *)mpart) != 1) {
printf ("** Can't read Partition Map on %d:%ld **\n",
-   dev_desc->devnum, i);
+   desc->devnum, i);
return;
}
 
if (mpart->signature != MAC_PARTITION_MAGIC) {
printf("** Bad Signature on %d:%ld - expected 0x%04x, 
got 0x%04x\n",
-  dev_desc->devnum, i, MAC_PARTITION_MAGIC,
+  desc->devnum, i, MAC_PARTITION_MAGIC,
   mpart->signature);
return;
}
@@ -154,10 +153,9 @@ static void part_print_mac(struct blk_desc *dev_desc)
 /*
  * Read Device Descriptor Block
  */
-static int part_mac_read_ddb(struct blk_desc *dev_desc,
-mac_driver_desc_t *ddb_p)
+static int part_mac_read_ddb(struct blk_desc *desc, mac_driver_desc_t *ddb_p)
 {
-   if (blk_dread(dev_desc, 0, 1, (ulong *)ddb_p) != 1) {
+   if (blk_dread(desc, 0, 1, (ulong *)ddb_p) != 1) {
debug("** Can't read Driver Descriptor Block **\n");
return (-1);
}
@@ -171,7 +169,7 @@ static int part_mac_read_ddb(struct blk_desc *dev_desc,
 /*
  * Read Partition Descriptor Block
  */
-static int part_mac_read_pdb(struct blk_desc *dev_desc, int part,
+static int part_mac_read_pdb(struct blk_desc *desc, int part,
 mac_partition_t *pdb_p)
 {
int n = 1;
@@ -182,15 +180,15 @@ static int part_mac_read_pdb(struct blk_desc *dev_desc, 
int part,
 * partition 1 first since this is the only way to
 * know how many partitions we have.
 */
-   if (blk_dread(dev_desc, n, 1, (ulong *)pdb_p) != 1) {
-   printf ("** Can't read Partition Map on %d:%d **\n",
-   dev_desc->devnum, n);
+   if (blk_dread(desc, n, 1, (ulong *)pdb_p) != 1) {
+   printf("** Can't read Partition Map on %d:%d **\n",
+  desc->devnum, n);
return (-1);
}
 
  

[PATCH 04/24] part: efi: Use desc instead of dev_desc

2023-08-13 Thread Simon Glass
The dev_ prefix is a hangover from the pre-driver model days. The device
is now a different thing, with driver model. Update the efi code to
just use 'desc'.

Signed-off-by: Simon Glass 
---

 disk/part_efi.c | 228 
 1 file changed, 112 insertions(+), 116 deletions(-)

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 80a44dc9f072..4ac21868d088 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -51,12 +51,12 @@ static inline u32 efi_crc32(const void *buf, u32 len)
 
 static int pmbr_part_valid(struct partition *part);
 static int is_pmbr_valid(legacy_mbr * mbr);
-static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
-   gpt_header *pgpt_head, gpt_entry **pgpt_pte);
-static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc,
+static int is_gpt_valid(struct blk_desc *desc, u64 lba, gpt_header *pgpt_head,
+   gpt_entry **pgpt_pte);
+static gpt_entry *alloc_read_gpt_entries(struct blk_desc *desc,
 gpt_header *pgpt_head);
 static int is_pte_valid(gpt_entry * pte);
-static int find_valid_gpt(struct blk_desc *dev_desc, gpt_header *gpt_head,
+static int find_valid_gpt(struct blk_desc *desc, gpt_header *gpt_head,
  gpt_entry **pgpt_pte);
 
 static char *print_efiname(gpt_entry *pte)
@@ -195,14 +195,14 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h)
  * UUID is displayed as 32 hexadecimal digits, in 5 groups,
  * separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters
  */
-int get_disk_guid(struct blk_desc * dev_desc, char *guid)
+int get_disk_guid(struct blk_desc *desc, char *guid)
 {
-   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
+   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
gpt_entry *gpt_pte = NULL;
unsigned char *guid_bin;
 
/* This function validates AND fills in the GPT header and PTE */
-   if (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1)
+   if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1)
return -EINVAL;
 
guid_bin = gpt_head->disk_guid.b;
@@ -213,15 +213,15 @@ int get_disk_guid(struct blk_desc * dev_desc, char *guid)
return 0;
 }
 
-void part_print_efi(struct blk_desc *dev_desc)
+void part_print_efi(struct blk_desc *desc)
 {
-   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
+   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
gpt_entry *gpt_pte = NULL;
int i = 0;
unsigned char *uuid;
 
/* This function validates AND fills in the GPT header and PTE */
-   if (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1)
+   if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1)
return;
 
debug("%s: gpt-entry at %p\n", __func__, gpt_pte);
@@ -255,10 +255,10 @@ void part_print_efi(struct blk_desc *dev_desc)
return;
 }
 
-int part_get_info_efi(struct blk_desc *dev_desc, int part,
+int part_get_info_efi(struct blk_desc *desc, int part,
  struct disk_partition *info)
 {
-   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz);
+   ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz);
gpt_entry *gpt_pte = NULL;
 
/* "part" argument must be at least 1 */
@@ -268,7 +268,7 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part,
}
 
/* This function validates AND fills in the GPT header and PTE */
-   if (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1)
+   if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1)
return -EINVAL;
 
if (part > le32_to_cpu(gpt_head->num_partition_entries) ||
@@ -283,7 +283,7 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part,
/* The ending LBA is inclusive, to calculate size, add 1 to it */
info->size = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1
 - info->start;
-   info->blksz = dev_desc->blksz;
+   info->blksz = desc->blksz;
 
snprintf((char *)info->name, sizeof(info->name), "%s",
 print_efiname(&gpt_pte[part - 1]));
@@ -306,12 +306,12 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part,
return 0;
 }
 
-static int part_test_efi(struct blk_desc *dev_desc)
+static int part_test_efi(struct blk_desc *desc)
 {
-   ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz);
+   ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, desc->blksz);
 
/* Read legacy MBR from block 0 and validate it */
-   if ((blk_dread(dev_desc, 0, 1, (ulong *)legacymbr) != 1)
+   if ((blk_dread(desc, 0, 1, (ulong *)legacymbr) != 1)
|| (is_pmbr_valid(legacymbr) != 1)) {
return -1;
}
@@ -320,23 +320,23 @@ static int part_test_efi(struct blk_desc *dev_desc)
 

[PATCH 03/24] part: dos: Use desc instead of dev_desc

2023-08-13 Thread Simon Glass
The dev_ prefix is a hangover from the pre-driver model days. The device
is now a different thing, with driver model. Update the dos code to
just use 'desc'.

Signed-off-by: Simon Glass 
---

 disk/part_dos.c | 61 -
 1 file changed, 30 insertions(+), 31 deletions(-)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 56e61884deff..f94d2172d772 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -98,27 +98,26 @@ static int test_block_type(unsigned char *buffer)
return -1;
 }
 
-static int part_test_dos(struct blk_desc *dev_desc)
+static int part_test_dos(struct blk_desc *desc)
 {
 #ifndef CONFIG_SPL_BUILD
ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr,
-   DIV_ROUND_UP(dev_desc->blksz, sizeof(legacy_mbr)));
+   DIV_ROUND_UP(desc->blksz, sizeof(legacy_mbr)));
 
-   if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1)
+   if (blk_dread(desc, 0, 1, (ulong *)mbr) != 1)
return -1;
 
if (test_block_type((unsigned char *)mbr) != DOS_MBR)
return -1;
 
-   if (dev_desc->sig_type == SIG_TYPE_NONE &&
-   mbr->unique_mbr_signature != 0) {
-   dev_desc->sig_type = SIG_TYPE_MBR;
-   dev_desc->mbr_sig = mbr->unique_mbr_signature;
+   if (desc->sig_type == SIG_TYPE_NONE && mbr->unique_mbr_signature) {
+   desc->sig_type = SIG_TYPE_MBR;
+   desc->mbr_sig = mbr->unique_mbr_signature;
}
 #else
-   ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
+   ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz);
 
-   if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1)
+   if (blk_dread(desc, 0, 1, (ulong *)buffer) != 1)
return -1;
 
if (test_block_type(buffer) != DOS_MBR)
@@ -130,12 +129,12 @@ static int part_test_dos(struct blk_desc *dev_desc)
 
 /*  Print a partition that is relative to its Extended partition table
  */
-static void print_partition_extended(struct blk_desc *dev_desc,
+static void print_partition_extended(struct blk_desc *desc,
 lbaint_t ext_part_sector,
 lbaint_t relative,
 int part_num, unsigned int disksig)
 {
-   ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
+   ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz);
dos_partition_t *pt;
int i;
 
@@ -146,9 +145,9 @@ static void print_partition_extended(struct blk_desc 
*dev_desc,
return;
 }
 
-   if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
+   if (blk_dread(desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
printf ("** Can't read partition table on %d:" LBAFU " **\n",
-   dev_desc->devnum, ext_part_sector);
+   desc->devnum, ext_part_sector);
return;
}
i=test_block_type(buffer);
@@ -189,9 +188,9 @@ static void print_partition_extended(struct blk_desc 
*dev_desc,
lbaint_t lba_start
= get_unaligned_le32 (pt->start4) + relative;
 
-   print_partition_extended(dev_desc, lba_start,
-   ext_part_sector == 0  ? lba_start : relative,
-   part_num, disksig);
+   print_partition_extended(desc, lba_start,
+!ext_part_sector ? lba_start :
+relative, part_num, disksig);
}
}
 
@@ -201,12 +200,12 @@ static void print_partition_extended(struct blk_desc 
*dev_desc,
 
 /*  Print a partition that is relative to its Extended partition table
  */
-static int part_get_info_extended(struct blk_desc *dev_desc,
+static int part_get_info_extended(struct blk_desc *desc,
  lbaint_t ext_part_sector, lbaint_t relative,
  int part_num, int which_part,
  struct disk_partition *info, uint disksig)
 {
-   ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
+   ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz);
dos_partition_t *pt;
int i;
int dos_type;
@@ -218,9 +217,9 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
return -1;
 }
 
-   if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
+   if (blk_dread(desc, ext_part_sector, 1, (ulong *)buffer) != 1) {
printf ("** Can't read partition table on %d:" LBAFU " **\n",
-   dev_desc->devnum, ext_part_sector);
+   desc->devnum, ext_part_sector);
return -1;
}
if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 ||
@@ -251,7 +250,7

[PATCH 01/24] part: Use desc instead of dev_desc

2023-08-13 Thread Simon Glass
The dev_ prefix is a hangover from the pre-driver model days. The device
is now a different thing, with driver model. Update the partition code to
just use 'desc', as is done with driver model.

Signed-off-by: Simon Glass 
---

 disk/part.c| 178 -
 include/part.h | 128 +--
 2 files changed, 149 insertions(+), 157 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index eec02f58988d..8035dcb8a429 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -42,25 +42,25 @@ static struct part_driver *part_driver_get_type(int 
part_type)
return NULL;
 }
 
-static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
+static struct part_driver *part_driver_lookup_type(struct blk_desc *desc)
 {
struct part_driver *drv =
ll_entry_start(struct part_driver, part_driver);
const int n_ents = ll_entry_count(struct part_driver, part_driver);
struct part_driver *entry;
 
-   if (dev_desc->part_type == PART_TYPE_UNKNOWN) {
+   if (desc->part_type == PART_TYPE_UNKNOWN) {
for (entry = drv; entry != drv + n_ents; entry++) {
int ret;
 
-   ret = entry->test(dev_desc);
+   ret = entry->test(desc);
if (!ret) {
-   dev_desc->part_type = entry->part_type;
+   desc->part_type = entry->part_type;
return entry;
}
}
} else {
-   return part_driver_get_type(dev_desc->part_type);
+   return part_driver_get_type(desc->part_type);
}
 
/* Not found */
@@ -85,25 +85,25 @@ int part_get_type_by_name(const char *name)
 
 static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
 {
-   struct blk_desc *dev_desc;
+   struct blk_desc *desc;
int ret;
 
if (!blk_enabled())
return NULL;
-   dev_desc = blk_get_devnum_by_uclass_idname(ifname, dev);
-   if (!dev_desc) {
+   desc = blk_get_devnum_by_uclass_idname(ifname, dev);
+   if (!desc) {
debug("%s: No device for iface '%s', dev %d\n", __func__,
  ifname, dev);
return NULL;
}
-   ret = blk_dselect_hwpart(dev_desc, hwpart);
+   ret = blk_dselect_hwpart(desc, hwpart);
if (ret) {
debug("%s: Failed to select h/w partition: err-%d\n", __func__,
  ret);
return NULL;
}
 
-   return dev_desc;
+   return desc;
 }
 
 struct blk_desc *blk_get_dev(const char *ifname, int dev)
@@ -140,29 +140,24 @@ static lba512_t lba512_muldiv(lba512_t block_count, 
lba512_t mul_by,
return bc_quot * mul_by + ((bc_rem * mul_by) >> right_shift);
 }
 
-void dev_print(struct blk_desc *dev_desc)
+void dev_print(struct blk_desc *desc)
 {
lba512_t lba512; /* number of blocks if 512bytes block size */
 
-   if (dev_desc->type == DEV_TYPE_UNKNOWN) {
+   if (desc->type == DEV_TYPE_UNKNOWN) {
puts ("not available\n");
return;
}
 
-   switch (dev_desc->uclass_id) {
+   switch (desc->uclass_id) {
case UCLASS_SCSI:
-   printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n",
-   dev_desc->target,dev_desc->lun,
-   dev_desc->vendor,
-   dev_desc->product,
-   dev_desc->revision);
+   printf("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n", desc->target,
+  desc->lun, desc->vendor, desc->product, desc->revision);
break;
case UCLASS_IDE:
case UCLASS_AHCI:
-   printf ("Model: %s Firm: %s Ser#: %s\n",
-   dev_desc->vendor,
-   dev_desc->revision,
-   dev_desc->product);
+   printf("Model: %s Firm: %s Ser#: %s\n", desc->vendor,
+  desc->revision, desc->product);
break;
case UCLASS_MMC:
case UCLASS_USB:
@@ -171,27 +166,27 @@ void dev_print(struct blk_desc *dev_desc)
case UCLASS_HOST:
case UCLASS_BLKMAP:
printf ("Vendor: %s Rev: %s Prod: %s\n",
-   dev_desc->vendor,
-   dev_desc->revision,
-   dev_desc->product);
+   desc->vendor,
+   desc->revision,
+   desc->product);
break;
case UCLASS_VIRTIO:
-   printf("%s VirtIO Block Device\n", dev_desc->vendor);
+   printf("%s VirtIO Block Device\n", desc->vendor);
break;
case UCLASS_EFI_MEDIA:
-   printf("EFI media Block Device %d\n", dev_desc->devnum);
+   printf("EFI media B

[PATCH 02/24] part: amiga: Use desc instead of dev_desc

2023-08-13 Thread Simon Glass
The dev_ prefix is a hangover from the pre-driver model days. The device
is now a different thing, with driver model. Update the amiga code to
just use 'desc'.

Signed-off-by: Simon Glass 
---

 disk/part_amiga.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/disk/part_amiga.c b/disk/part_amiga.c
index 45d3a7048669..65e30fea558d 100644
--- a/disk/part_amiga.c
+++ b/disk/part_amiga.c
@@ -125,7 +125,7 @@ static void print_part_info(struct partition_block *p)
  * the ID AMIGA_ID_RDISK ('RDSK') and needs to have a valid
  * sum-to-zero checksum
  */
-struct rigid_disk_block *get_rdisk(struct blk_desc *dev_desc)
+struct rigid_disk_block *get_rdisk(struct blk_desc *desc)
 {
 int i;
 int limit;
@@ -139,7 +139,7 @@ struct rigid_disk_block *get_rdisk(struct blk_desc 
*dev_desc)
 
 for (i=0; i

[PATCH 00/24] bootstd: Support ChromiumOS better

2023-08-13 Thread Simon Glass
This updates the ChromiumOS bootmeth to detect multiple kernel partitions
on a disk.

It also includes minor code improvements to the partition drivers,
including accessors for the optional fields.

This series also includes some other related tweaks in testing.

It is available at u-boot-dm/methb-working


Simon Glass (24):
  part: Use desc instead of dev_desc
  part: amiga: Use desc instead of dev_desc
  part: dos: Use desc instead of dev_desc
  part: efi: Use desc instead of dev_desc
  part: iso: Use desc instead of dev_desc
  part: nac: Use desc instead of dev_desc
  part: Add comments for static functions
  part: Add accessors for struct disk_partition uuid
  part: Add accessors for struct disk_partition type_uuid
  part: Add an accessor for struct disk_partition sys_ind
  part: efi: Add debugging for the signature check
  fs/erofs: Quieten test for filesystem presence
  dm: core: Correct error handling when event fails
  uuid: Move function comments to header file
  sandbox: Add a way to access persistent test files
  test: Move 1MB.fat32.img and 2MB.ext2.img
  bootflow: Show an empty filename when there is none
  bootstd: test: Allow binding and using any mmc device
  bootstd: Add a test for bootmeth_cros
  part: Add a fallback for part_get_bootable()
  bootstd: Support bootmeths which can scan any partition
  uuid: Add ChromiumOS partition types
  bootstd: cros: Allow detection of any kernel partition
  CI: Add ChromiumOS utilities

 arch/sandbox/cpu/os.c  |  24 
 arch/sandbox/dts/test.dts  |   9 ++
 boot/Kconfig   |   2 +
 boot/bootdev-uclass.c  |  24 +++-
 boot/bootmeth_cros.c   |  48 ---
 cmd/bootflow.c |   2 +-
 cmd/gpt.c  |  10 +-
 configs/snow_defconfig |   1 +
 disk/part.c| 226 +++--
 disk/part_amiga.c  |  34 ++---
 disk/part_dos.c|  78 +-
 disk/part_efi.c| 281 +++--
 disk/part_iso.c|  52 +++
 disk/part_mac.c|  59 
 doc/develop/bootstd.rst|  11 +-
 drivers/core/device.c  |   3 +-
 fs/erofs/super.c   |   4 +-
 fs/fat/fat.c   |   4 +-
 include/bootmeth.h |   3 +
 include/os.h   |  10 ++
 include/part.h | 215 ++--
 include/part_efi.h |  14 ++
 include/uuid.h |  94 +
 lib/uuid.c |  93 +---
 test/boot/bootflow.c   |  80 ---
 test/dm/host.c |  44 +++---
 test/py/tests/fs_helper.py |   6 +-
 test/py/tests/test_ut.py   | 148 ++-
 tools/docker/Dockerfile|   3 +
 29 files changed, 982 insertions(+), 600 deletions(-)

-- 
2.41.0.640.ga95def55d0-goog



Re: [PATCH 1/1] common: return type board_get_usable_ram_top

2023-08-13 Thread Simon Glass
Hi Heinrich,

On Sat, 12 Aug 2023 at 23:01, Heinrich Schuchardt
 wrote:
>
> board_get_usable_ram_top() returns a physical address that is stored in
> gd->ram_top. The return type of the function should be phys_addr_t like the
> current type of gd->ram_top.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  arch/arm/mach-imx/imx8m/soc.c   | 2 +-
>  arch/arm/mach-mvebu/arm64-common.c  | 2 +-
>  arch/arm/mach-rockchip/sdram.c  | 2 +-
>  arch/arm/mach-stm32mp/dram_init.c   | 2 +-
>  arch/arm/mach-sunxi/board.c | 2 +-
>  arch/arm/mach-tegra/board2.c| 2 +-
>  arch/mips/mach-jz47xx/jz4780/jz4780.c   | 2 +-
>  arch/mips/mach-octeon/dram.c| 2 +-
>  arch/riscv/cpu/fu540/dram.c | 2 +-
>  arch/riscv/cpu/fu740/dram.c | 2 +-
>  arch/riscv/cpu/generic/dram.c   | 2 +-
>  arch/riscv/cpu/jh7110/dram.c| 2 +-
>  arch/x86/cpu/broadwell/sdram.c  | 2 +-
>  arch/x86/cpu/coreboot/sdram.c   | 2 +-
>  arch/x86/cpu/efi/payload.c  | 2 +-
>  arch/x86/cpu/efi/sdram.c| 2 +-
>  arch/x86/cpu/ivybridge/sdram.c  | 2 +-
>  arch/x86/cpu/qemu/dram.c| 2 +-
>  arch/x86/cpu/quark/dram.c   | 2 +-
>  arch/x86/cpu/slimbootloader/sdram.c | 2 +-
>  arch/x86/cpu/tangier/sdram.c| 2 +-
>  arch/x86/include/asm/u-boot-x86.h   | 2 +-
>  arch/x86/lib/fsp1/fsp_dram.c| 2 +-
>  arch/x86/lib/fsp2/fsp_dram.c| 2 +-
>  board/broadcom/bcmns3/ns3.c | 2 +-
>  board/imgtec/boston/ddr.c   | 2 +-
>  board/menlo/m53menlo/m53menlo.c | 2 +-
>  board/raspberrypi/rpi/rpi.c | 2 +-
>  board/ti/am65x/evm.c| 2 +-
>  board/ti/j721e/evm.c| 2 +-
>  board/ti/j721s2/evm.c   | 2 +-
>  board/toradex/verdin-am62/verdin-am62.c | 2 +-
>  board/xilinx/common/board.c | 2 +-
>  common/board_f.c| 2 +-
>  include/init.h  | 2 +-
>  35 files changed, 35 insertions(+), 35 deletions(-)

While you are here, could you please fix the function comment?

[..]

> diff --git a/include/init.h b/include/init.h
> index 8873081685..b1e1451166 100644
> --- a/include/init.h
> +++ b/include/init.h
> @@ -304,7 +304,7 @@ int show_board_info(void);
>   *
>   * @param total_size   Size of U-Boot (unused?)

It seems confused about the param, and we should have a return value.

Also should explain what this function is used for.

>   */
> -phys_size_t board_get_usable_ram_top(phys_size_t total_size);
> +phys_addr_t board_get_usable_ram_top(phys_size_t total_size);
>
>  int board_early_init_f(void);
>
> --
> 2.40.1
>

Regards,
Simon


Re: [PATCH v8 4/9] sandbox: Build the mkeficapsule tool for the sandbox variants

2023-08-13 Thread Simon Glass
Hi Tom,

On Sun, 13 Aug 2023 at 06:40, Tom Rini  wrote:
>
> On Sat, Aug 12, 2023 at 06:14:45PM -0600, Simon Glass wrote:
> > Hi Tom,
> >
> > On Sat, 12 Aug 2023 at 16:38, Tom Rini  wrote:
> > >
> > > On Sat, Aug 12, 2023 at 11:03:36AM -0600, Simon Glass wrote:
> > > > Hi Tom,
> > > >
> > > > On Sat, 12 Aug 2023 at 08:28, Tom Rini  wrote:
> > > > >
> > > > > On Sat, Aug 12, 2023 at 08:24:59AM -0600, Simon Glass wrote:
> > > > > > Hi Tom,
> > > > > >
> > > > > > On Sat, 12 Aug 2023 at 08:22, Tom Rini  wrote:
> > > > > > >
> > > > > > > On Sat, Aug 12, 2023 at 07:08:44AM -0600, Simon Glass wrote:
> > > > > > > > Hi Tom,
> > > > > > > >
> > > > > > > > On Fri, 11 Aug 2023 at 09:56, Tom Rini  
> > > > > > > > wrote:
> > > > > > > > >
> > > > > > > > > On Fri, Aug 11, 2023 at 08:26:36AM -0600, Simon Glass wrote:
> > > > > > > > > > Hi Sughosh,
> > > > > > > > > >
> > > > > > > > > > On Fri, 11 Aug 2023 at 08:23, Sughosh Ganu 
> > > > > > > > > > 
> > > > > > > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > On Fri, 11 Aug 2023 at 19:28, Tom Rini 
> > > > > > > > > > >  wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > On Fri, Aug 11, 2023 at 04:29:37PM +0530, Sughosh Ganu 
> > > > > > > > > > > > wrote:
> > > > > > > > > > > > > On Thu, 10 Aug 2023 at 22:47, Tom Rini 
> > > > > > > > > > > > >  wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > On Thu, Aug 10, 2023 at 10:39:06PM +0530, Sughosh 
> > > > > > > > > > > > > > Ganu wrote:
> > > > > > > > > > > > > > > On Thu, 10 Aug 2023 at 21:22, Tom Rini 
> > > > > > > > > > > > > > > 
> > > > > > > > wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > On Thu, Aug 10, 2023 at 07:53:33PM +0530, 
> > > > > > > > > > > > > > > > Sughosh Ganu
> > > > > > > > wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Build the mkeficapsule tool for all the 
> > > > > > > > > > > > > > > > > sandbox variants.
> > > > > > > > This tool
> > > > > > > > > > > > > > > > > will be used subsequently for testing capsule 
> > > > > > > > > > > > > > > > > generation
> > > > > > > > in binman.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Signed-off-by: Sughosh Ganu 
> > > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > > ---
> > > > > > > > > > > > > > > > > Changes since V7: None
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >  tools/Kconfig | 6 +++---
> > > > > > > > > > > > > > > > >  1 file changed, 3 insertions(+), 3 
> > > > > > > > > > > > > > > > > deletions(-)
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > diff --git a/tools/Kconfig b/tools/Kconfig
> > > > > > > > > > > > > > > > > index 6e23f44d55..353a855243 100644
> > > > > > > > > > > > > > > > > --- a/tools/Kconfig
> > > > > > > > > > > > > > > > > +++ b/tools/Kconfig
> > > > > > > > > > > > > > > > > @@ -91,10 +91,10 @@ config TOOLS_SHA512
> > > > > > > > > > > > > > > > > Enable SHA512 support in the tools 
> > > > > > > > > > > > > > > > > builds
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >  config TOOLS_MKEFICAPSULE
> > > > > > > > > > > > > > > > > - bool "Build efimkcapsule command"
> > > > > > > > > > > > > > > > > - default y if EFI_CAPSULE_ON_DISK
> > > > > > > > > > > > > > > > > + bool "Build mkeficapsule tool"
> > > > > > > > > > > > > > > > > + default y if EFI_CAPSULE_ON_DISK || 
> > > > > > > > > > > > > > > > > SANDBOX
> > > > > > > > > > > > > > > > >   help
> > > > > > > > > > > > > > > > > -   This command allows users to create a 
> > > > > > > > > > > > > > > > > UEFI
> > > > > > > > capsule file and,
> > > > > > > > > > > > > > > > > +   This tool allows users to create a 
> > > > > > > > > > > > > > > > > UEFI capsule
> > > > > > > > file and,
> > > > > > > > > > > > > > > > > optionally sign that file. If you 
> > > > > > > > > > > > > > > > > want to enable
> > > > > > > > UEFI capsule
> > > > > > > > > > > > > > > > > update feature on your target, you 
> > > > > > > > > > > > > > > > > certainly need
> > > > > > > > this.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Sorry, what is this fixing exactly?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > The tool is required to be supported on the 
> > > > > > > > > > > > > > > sandbox_spl
> > > > > > > > variant, since
> > > > > > > > > > > > > > > that is used for the binman tests in CI. Simon 
> > > > > > > > > > > > > > > had then asked
> > > > > > > > me to
> > > > > > > > > > > > > > > add support for the tool on all sandbox variants. 
> > > > > > > > > > > > > > > I missed
> > > > > > > > putting his
> > > > > > > > > > > > > > > R-b on this patch.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > OK, moving forward just depend on:
> > > > > > > > > > > > > >
> > > > > > > > https://patchwork.ozlabs.org/project/uboot/patch/20230810165224.514772-1-tr...@konsulko.com/
> > > > > > > > > > > > > > inste

Re: [PATCH] docs: fix wrong usage of proftool

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 23:18, Puhan Zhou  wrote:
>
> The usage of proftool in docs is incorrect. If proftool is used without
> '-o' argument, it will show the usage like following
>
> $ ./sandbox/tools/proftool -m sandbox/System.map -t trace -f funcgraph 
> dump-ftrace >trace.dat
> Must provide trace data, System.map file and output file
> Usage: proftool [-cmtv]  
>
> Change '>' to '-o' to fix it.
>
> Signed-off-by: Puhan Zhou 
> ---
>  doc/develop/trace.rst | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 2/2] configs: sandbox64: Enable PINCTRL_SINGLE driver

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 21:32, Marek Vasut
 wrote:
>
> Align the sandbox64 defconfig with sandbox defconfig. Enable missing
> PINCTRL single driver. This fixes ut_dm_dm_test_pinctrl_single test .
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Simon Glass 
> ---
>  configs/sandbox64_defconfig | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Simon Glass 


Re: [PATCH] configs: sandbox64: Enable MC34708 driver

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 20:57, Marek Vasut
 wrote:
>
> Align the sandbox64 defconfig with sandbox defconfig. Enable missing
> MC34708 PMIC driver. This fixes ut_dm_dm_test_power_pmic_mc34708_get test .
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Simon Glass 
> ---
>  configs/sandbox64_defconfig | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Simon Glass 


Re: [PATCH] test: Fix the help for the ut command

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 16:16, Marek Vasut
 wrote:
>
> Drop the 'ut' prefix, this is superfluous and not present in
> any of the other ut tests.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Heinrich Schuchardt 
> Cc: Linus Walleij 
> Cc: Simon Glass 
> Cc: Stephen Carlson 
> ---
>  test/cmd_ut.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH 1/2] test: dm: pinmux: Handle %pa in pinctrl-single mux output

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 21:32, Marek Vasut
 wrote:
>
> The pinctrl-single driver uses %pa to print register value
> in its single_get_pin_muxing() output. Handle this properly
> in the test based on CONFIG_PHYS_64BIT .
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Simon Glass 
> ---
>  test/dm/pinmux.c | 92 +++-
>  1 file changed, 51 insertions(+), 41 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 2/2] configs: sandbox64: Enable video 12x22 font support

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 23:15, Marek Vasut
 wrote:
>
> Align the sandbox64 defconfig with sandbox defconfig. Enable missing
> 12x22 font support. This fixes ut_dm_dm_test_video_text_12x22 test .
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Simon Glass 
> ---
>  configs/sandbox64_defconfig | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Simon Glass 


Re: [PATCH] test: acpi: Handle both 32bit and 64bit ACPI tables

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 19:26, Marek Vasut
 wrote:
>
> Handle both 32bit and 64bit systems, i.e. sandbox and sandbox64
> the same way drivers/cpu/cpu_sandbox.c sets those ACPI tables up.
> This fixes "$ ./u-boot -Tc 'ut dm dm_test_acpi_write_tables'"
> test failure on sandbox64.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Simon Glass 
> ---
>  test/dm/acpi.c | 12 
>  1 file changed, 8 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass 


>
> diff --git a/test/dm/acpi.c b/test/dm/acpi.c
> index 77eb524b59f..5997bda649b 100644
> --- a/test/dm/acpi.c
> +++ b/test/dm/acpi.c
> @@ -221,7 +221,8 @@ static int dm_test_acpi_create_dmar(struct 
> unit_test_state *uts)
> ut_assertnonnull(cpu);
> ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP));
> ut_asserteq(DMAR_INTR_REMAP, dmar.flags);
> -   ut_asserteq(32 - 1, dmar.host_address_width);
> +   ut_asserteq((IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32) - 1,
> +   dmar.host_address_width);
>
> return 0;
>  }
> @@ -277,13 +278,16 @@ static int dm_test_acpi_write_tables(struct 
> unit_test_state *uts)
>  */
> ut_asserteq_ptr(dmar + 3, ctx.current);
> ut_asserteq(DMAR_INTR_REMAP, dmar->flags);
> -   ut_asserteq(32 - 1, dmar->host_address_width);
> +   ut_asserteq((IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32) - 1,
> +   dmar->host_address_width);
>
> ut_asserteq(DMAR_INTR_REMAP, dmar[1].flags);
> -   ut_asserteq(32 - 1, dmar[1].host_address_width);
> +   ut_asserteq((IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32) - 1,
> +   dmar[1].host_address_width);
>
> ut_asserteq(DMAR_INTR_REMAP, dmar[2].flags);
> -   ut_asserteq(32 - 1, dmar[2].host_address_width);
> +   ut_asserteq((IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32) - 1,
> +   dmar[2].host_address_width);
>
> /* Check that the pointers were added correctly */
> for (i = 0; i < 3; i++) {
> --
> 2.40.1
>


Re: [PATCH] configs: sandbox64: Enable BUTTON_ADC driver

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 21:06, Marek Vasut
 wrote:
>
> Align the sandbox64 defconfig with sandbox defconfig. Enable missing
> BUTTON ADC driver. This fixes ut_dm_dm_test_button_keys_adc test .
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Simon Glass 
> ---
>  configs/sandbox64_defconfig | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Simon Glass 

As Tom mentioned there is likely not that much reason to have as many
differences between the sandbox configs as we do...so you could do a
bulk meld if it is easier.


Re: [PATCH 1/2] configs: sandbox64: Enable video 16bpp and 24bpp support

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 23:15, Marek Vasut
 wrote:
>
> Align the sandbox64 defconfig with sandbox defconfig. Enable missing
> 16bpp and 24bpp video support. This fixes ut_dm_dm_test_video_bmp16
> and ut_dm_dm_test_video_bmp24 tests .
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Simon Glass 
> ---
>  configs/sandbox64_defconfig | 2 ++
>  1 file changed, 2 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH] configs: sandbox64: Enable SF bootdev

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 18:16, Marek Vasut
 wrote:
>
> Align the sandbox64 defconfig with sandbox defconfig. Enable missing
> SPI NOT bootdev. This fixes ut_bootstd_bootdev_test_cmd_hunt test .
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Mario Six 
> Cc: Simon Glass 
> ---
>  configs/sandbox64_defconfig | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Simon Glass 


Re: [PATCH] configs: sandbox64: Increase console record size to 0x6000

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 19:18, Marek Vasut
 wrote:
>
> Align the sandbox64 defconfig with sandbox defconfig. Increase the
> console record size. This fixes ut_bootstd_bootflow_cmd_scan_e .
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Mario Six 
> Cc: Simon Glass 
> ---
>  configs/sandbox64_defconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH] Add support for more XMC series

2023-08-13 Thread Simon Glass
On Fri, 11 Aug 2023 at 21:19, SSunk  wrote:
>
> Add XMC XM25QH256C/XM25QU256C/XM25QH512C/XM25QU512C
> site: https://www.xmcwh.com/site/product
>
> Signed-off-by: Kankan Sun 
> ---
>  configs/evb-ast2600_defconfig | 1 +
>  drivers/mtd/spi/spi-nor-ids.c | 4 
>  2 files changed, 5 insertions(+)

Reviewed-by: Simon Glass 

I think this is v2 so it should have that as well as a change list.
You can use 'patman' to help with this.

Regards,
Simon



>
> diff --git a/configs/evb-ast2600_defconfig b/configs/evb-ast2600_defconfig
> index 9244654c82..f06c0e1fe1 100644
> --- a/configs/evb-ast2600_defconfig
> +++ b/configs/evb-ast2600_defconfig
> @@ -100,6 +100,7 @@ CONFIG_SPI_FLASH_SPANSION=y
>  CONFIG_SPI_FLASH_STMICRO=y
>  CONFIG_SPI_FLASH_SST=y
>  CONFIG_SPI_FLASH_WINBOND=y
> +CONFIG_SPI_FLASH_XMC=y
>  # CONFIG_SPI_FLASH_USE_4K_SECTORS is not set
>  CONFIG_PHY_REALTEK=y
>  CONFIG_PHY_NCSI=y
> diff --git a/drivers/mtd/spi/spi-nor-ids.c b/drivers/mtd/spi/spi-nor-ids.c
> index 4587215984..80d7678293 100644
> --- a/drivers/mtd/spi/spi-nor-ids.c
> +++ b/drivers/mtd/spi/spi-nor-ids.c
> @@ -531,6 +531,10 @@ const struct flash_info spi_nor_ids[] = {
> { INFO("XM25QH64A", 0x207017, 0, 64 * 1024, 128, SECT_4K | 
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
> { INFO("XM25QH64C", 0x204017, 0, 64 * 1024, 128, SECT_4K | 
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
> { INFO("XM25QH128A", 0x207018, 0, 64 * 1024, 256, SECT_4K | 
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
> +   { INFO("XM25QH256C", 0x204019, 0, 64 * 1024, 512, SECT_4K | 
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
> +   { INFO("XM25QU256C", 0x204119, 0, 64 * 1024, 512, SECT_4K | 
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
> +   { INFO("XM25QH512C", 0x204020, 0, 64 * 1024, 1024, SECT_4K | 
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
> +   { INFO("XM25QU512C", 0x204120, 0, 64 * 1024, 1024, SECT_4K | 
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
>  #endif
>  #ifdef CONFIG_SPI_FLASH_XTX
> /* XTX Technology Limited */
> --
> 2.34.1
>


Re: [PATCH v2 1/1] lmb: description lmb_is_reserved, lmb_is_reserved_flags

2023-08-13 Thread Simon Glass
On Sat, 12 Aug 2023 at 12:23, Heinrich Schuchardt
 wrote:
>
> * provide a description for function lmb_is_reserved()
> * improve the description of funciton lmb_is_reserved_flags()
>
> Signed-off-by: Heinrich Schuchardt 
> ---
> v2:
> fix lmb_is_reserved description
> ---
>  include/lmb.h | 22 +++---
>  1 file changed, 19 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v8 4/9] sandbox: Build the mkeficapsule tool for the sandbox variants

2023-08-13 Thread Tom Rini
On Sat, Aug 12, 2023 at 06:14:45PM -0600, Simon Glass wrote:
> Hi Tom,
> 
> On Sat, 12 Aug 2023 at 16:38, Tom Rini  wrote:
> >
> > On Sat, Aug 12, 2023 at 11:03:36AM -0600, Simon Glass wrote:
> > > Hi Tom,
> > >
> > > On Sat, 12 Aug 2023 at 08:28, Tom Rini  wrote:
> > > >
> > > > On Sat, Aug 12, 2023 at 08:24:59AM -0600, Simon Glass wrote:
> > > > > Hi Tom,
> > > > >
> > > > > On Sat, 12 Aug 2023 at 08:22, Tom Rini  wrote:
> > > > > >
> > > > > > On Sat, Aug 12, 2023 at 07:08:44AM -0600, Simon Glass wrote:
> > > > > > > Hi Tom,
> > > > > > >
> > > > > > > On Fri, 11 Aug 2023 at 09:56, Tom Rini  wrote:
> > > > > > > >
> > > > > > > > On Fri, Aug 11, 2023 at 08:26:36AM -0600, Simon Glass wrote:
> > > > > > > > > Hi Sughosh,
> > > > > > > > >
> > > > > > > > > On Fri, 11 Aug 2023 at 08:23, Sughosh Ganu 
> > > > > > > > > 
> > > > > > > wrote:
> > > > > > > > > >
> > > > > > > > > > On Fri, 11 Aug 2023 at 19:28, Tom Rini  
> > > > > > > > > > wrote:
> > > > > > > > > > >
> > > > > > > > > > > On Fri, Aug 11, 2023 at 04:29:37PM +0530, Sughosh Ganu 
> > > > > > > > > > > wrote:
> > > > > > > > > > > > On Thu, 10 Aug 2023 at 22:47, Tom Rini 
> > > > > > > > > > > >  wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > On Thu, Aug 10, 2023 at 10:39:06PM +0530, Sughosh 
> > > > > > > > > > > > > Ganu wrote:
> > > > > > > > > > > > > > On Thu, 10 Aug 2023 at 21:22, Tom Rini 
> > > > > > > > > > > > > > 
> > > > > > > wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > On Thu, Aug 10, 2023 at 07:53:33PM +0530, Sughosh 
> > > > > > > > > > > > > > > Ganu
> > > > > > > wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Build the mkeficapsule tool for all the sandbox 
> > > > > > > > > > > > > > > > variants.
> > > > > > > This tool
> > > > > > > > > > > > > > > > will be used subsequently for testing capsule 
> > > > > > > > > > > > > > > > generation
> > > > > > > in binman.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Signed-off-by: Sughosh Ganu 
> > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > ---
> > > > > > > > > > > > > > > > Changes since V7: None
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >  tools/Kconfig | 6 +++---
> > > > > > > > > > > > > > > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > diff --git a/tools/Kconfig b/tools/Kconfig
> > > > > > > > > > > > > > > > index 6e23f44d55..353a855243 100644
> > > > > > > > > > > > > > > > --- a/tools/Kconfig
> > > > > > > > > > > > > > > > +++ b/tools/Kconfig
> > > > > > > > > > > > > > > > @@ -91,10 +91,10 @@ config TOOLS_SHA512
> > > > > > > > > > > > > > > > Enable SHA512 support in the tools 
> > > > > > > > > > > > > > > > builds
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >  config TOOLS_MKEFICAPSULE
> > > > > > > > > > > > > > > > - bool "Build efimkcapsule command"
> > > > > > > > > > > > > > > > - default y if EFI_CAPSULE_ON_DISK
> > > > > > > > > > > > > > > > + bool "Build mkeficapsule tool"
> > > > > > > > > > > > > > > > + default y if EFI_CAPSULE_ON_DISK || 
> > > > > > > > > > > > > > > > SANDBOX
> > > > > > > > > > > > > > > >   help
> > > > > > > > > > > > > > > > -   This command allows users to create a 
> > > > > > > > > > > > > > > > UEFI
> > > > > > > capsule file and,
> > > > > > > > > > > > > > > > +   This tool allows users to create a UEFI 
> > > > > > > > > > > > > > > > capsule
> > > > > > > file and,
> > > > > > > > > > > > > > > > optionally sign that file. If you want 
> > > > > > > > > > > > > > > > to enable
> > > > > > > UEFI capsule
> > > > > > > > > > > > > > > > update feature on your target, you 
> > > > > > > > > > > > > > > > certainly need
> > > > > > > this.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Sorry, what is this fixing exactly?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > The tool is required to be supported on the 
> > > > > > > > > > > > > > sandbox_spl
> > > > > > > variant, since
> > > > > > > > > > > > > > that is used for the binman tests in CI. Simon had 
> > > > > > > > > > > > > > then asked
> > > > > > > me to
> > > > > > > > > > > > > > add support for the tool on all sandbox variants. I 
> > > > > > > > > > > > > > missed
> > > > > > > putting his
> > > > > > > > > > > > > > R-b on this patch.
> > > > > > > > > > > > >
> > > > > > > > > > > > > OK, moving forward just depend on:
> > > > > > > > > > > > >
> > > > > > > https://patchwork.ozlabs.org/project/uboot/patch/20230810165224.514772-1-tr...@konsulko.com/
> > > > > > > > > > > > > instead please, thanks.
> > > > > > > > > > > >
> > > > > > > > > > > > I will base my changes on top of your patch. However, 
> > > > > > > > > > > > we would
> > > > > > > still
> > > > > > > > > > > > need this patch as part of the series, since Simon 
> > > > > > > > > > > > wants the
> > > > > > > capsules
> > > > > >

[PATCH] docs: fix wrong usage of proftool

2023-08-13 Thread Puhan Zhou
The usage of proftool in docs is incorrect. If proftool is used without
'-o' argument, it will show the usage like following

$ ./sandbox/tools/proftool -m sandbox/System.map -t trace -f funcgraph 
dump-ftrace >trace.dat
Must provide trace data, System.map file and output file
Usage: proftool [-cmtv]  

Change '>' to '-o' to fix it.

Signed-off-by: Puhan Zhou 
---
 doc/develop/trace.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/doc/develop/trace.rst b/doc/develop/trace.rst
index 9bbe1345d2..546862020b 100644
--- a/doc/develop/trace.rst
+++ b/doc/develop/trace.rst
@@ -139,7 +139,7 @@ There is a -f option available to select a function graph:
 
 .. code-block:: console
 
-$ ./sandbox/tools/proftool -m sandbox/System.map -t trace -f funcgraph 
dump-ftrace >trace.dat
+$ ./sandbox/tools/proftool -m sandbox/System.map -t trace -f funcgraph 
dump-ftrace -o trace.dat
 
 Again, you can use kernelshark or trace-cmd to look at the output. In this case
 you will see the time taken by each function shown against its exit record.
@@ -171,7 +171,7 @@ command:
 
 .. code-block:: console
 
-$ ./sandbox/tools/proftool -m sandbox/System.map -t trace dump-flamegraph 
>trace.fg
+$ ./sandbox/tools/proftool -m sandbox/System.map -t trace dump-flamegraph 
-o trace.fg
 $ flamegraph.pl trace.fg >trace.svg
 
 You can load the .svg file into a viewer. If you use Chrome (and some other
@@ -191,7 +191,7 @@ spend in each call stack:
 
 .. code-block:: console
 
-$ ./sandbox/tools/proftool -m sandbox/System.map -t trace dump-flamegraph 
-f timing >trace.fg
+$ ./sandbox/tools/proftool -m sandbox/System.map -t trace dump-flamegraph 
-f timing -o trace.fg
 $ flamegraph.pl trace.fg >trace.svg
 
 Note that trace collection does slow down execution so the timings will be
-- 
2.34.1



[PATCH] usb: gadget: sdp: Option to enable SDP read register command

2023-08-13 Thread Loic Poulain
The SDP read register command can be used to read any memory
mapped address of the device (ddr, registers...). It can then
be exploited by an attacker to access sensitive data/values,
especially when running SDP from SPL, as SPL runs with highest
privileges in ARM secure mode.

Without read, SDP still useful to bootstrap and jump on (signed)
blob such as u-boot with write and jump commands, but reading
is optional in that case (debug purpose).

NXP SoCs usually have a dedicated SDP_READ_DISABLE fuse to disable
SDP read command in their ROM SDP implementation, so it seems quite
reasonable to make it optional from u-boot/spl as well.

Signed-off-by: Loic Poulain 
---
 drivers/usb/gadget/Kconfig | 14 ++
 drivers/usb/gadget/f_sdp.c |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 1cfe602284..50cf7c0dae 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -195,6 +195,13 @@ config USB_FUNCTION_SDP
  allows to download images into memory and execute (jump to) them
  using the same protocol as implemented by the i.MX family's boot ROM.
 
+config SDP_READ
+   bool "Enable SDP READ command"
+   depends on USB_FUNCTION_SDP
+   default n
+   help
+ Enable SDP secure sensitive SDP read register command.
+
 config USB_FUNCTION_THOR
bool "Enable USB THOR gadget"
help
@@ -344,6 +351,13 @@ config SPL_USB_SDP_SUPPORT
  allows to download images into memory and execute (jump to) them
  using the same protocol as implemented by the i.MX family's boot ROM.
 
+config SPL_SDP_READ
+   bool "Enable SDP READ command in SPL"
+   depends on SPL_USB_SDP_SUPPORT
+   default n
+   help
+ Enable SDP secure sensitive SDP read register command.
+
 config SPL_SDP_USB_DEV
int "SDP USB controller index in SPL"
default 0
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index 4da5a160a0..48a68a50d9 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -310,6 +310,7 @@ static void sdp_rx_command_complete(struct usb_ep *ep, 
struct usb_request *req)
  be32_to_cpu(cmd->addr), be32_to_cpu(cmd->cnt));
 
switch (be16_to_cpu(cmd->cmd)) {
+#if CONFIG_IS_ENABLED(SDP_READ)
case SDP_READ_REGISTER:
sdp->always_send_status = false;
sdp->error_status = 0x0;
@@ -321,6 +322,7 @@ static void sdp_rx_command_complete(struct usb_ep *ep, 
struct usb_request *req)
printf("Reading %d registers at 0x%08x... ",
   sdp->dnl_bytes_remaining, sdp->dnl_address);
break;
+#endif
case SDP_WRITE_FILE:
sdp->always_send_status = true;
sdp->error_status = SDP_WRITE_FILE_COMPLETE;
-- 
2.34.1



Re: [PATCH v2 06/10] ARM: dts: rockchip: rk3588-rock-5b-u-boot: add bootph-all to gadget nodes

2023-08-13 Thread Eugen Hristev

On 8/12/23 05:53, Kever Yang wrote:

Hi Eugen,

On 2023/8/1 15:28, Eugen Hristev wrote:

Add bootph-all to gadget nodes to have the gadget available in SPL.


Does this gadget available on both USB2 and USB3? I think only USB2 is 
enough?




Hi Kever,

This board has one USB type C that is connected on USB3. This type C 
port is used for maskrom, to flash using rkdeveloptool and to power the 
board. It is only natural that this port is used for gadget, because 
everyone who boot this board, use rockusb to boot, will already have a 
cable connected to the host.


Also, on this device RK3588 USB2 controller does not support gadget 
mode, only host, so I am forced to use USB3 anyway.


Eugen


Thanks,

- Kever



Signed-off-by: Eugen Hristev 
---
  arch/arm/dts/rk3588-rock-5b-u-boot.dtsi | 6 ++
  1 file changed, 6 insertions(+)

diff --git a/arch/arm/dts/rk3588-rock-5b-u-boot.dtsi 
b/arch/arm/dts/rk3588-rock-5b-u-boot.dtsi

index 5a3292699640..f453aeeaf526 100644
--- a/arch/arm/dts/rk3588-rock-5b-u-boot.dtsi
+++ b/arch/arm/dts/rk3588-rock-5b-u-boot.dtsi
@@ -221,10 +221,12 @@
  };
  &u2phy0 {
+    bootph-all;
  status = "okay";
  };
  &u2phy0_otg {
+    bootph-all;
  rockchip,typec-vbus-det;
  status = "okay";
  };
@@ -271,6 +273,7 @@
  };
  &usbdp_phy0 {
+    bootph-all;
  orientation-switch;
  svid = <0xff01>;
  sbu1-dc-gpios = <&gpio4 RK_PA6 GPIO_ACTIVE_HIGH>;
@@ -293,14 +296,17 @@
  };
  &usbdp_phy0_u3 {
+    bootph-all;
  status = "okay";
  };
  &usbdrd3_0 {
+    bootph-all;
  status = "okay";
  };
  &usbdrd_dwc3_0 {
+    bootph-all;
  dr_mode = "otg";
  usb-role-switch;




  1   2   >