Re: [GIT PULL] Please pull u-boot-imx-master-20240420

2024-04-20 Thread Tom Rini
On Sat, Apr 20, 2024 at 03:33:22PM -0300, Fabio Estevam wrote:

> Hi Tom,
> 
> Please pull from u-boot-imx/master, thanks.
> 
> The following changes since commit af04f37a78c7e61597fb9ed6db2c8f8d7f8b0f92:
> 
>   Merge tag 'u-boot-stm32-20240419' of 
> https://source.denx.de/u-boot/custodians/u-boot-stm (2024-04-19 14:25:04 
> -0600)
> 
> are available in the Git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-imx.git 
> tags/u-boot-imx-master-20240420
> 
> for you to fetch changes up to 8b8c699d88171b0d40f072e114f32cce93cb2987:
> 
>   imx8mm_venice_defconfig: Enable PCIe/NVMe support (2024-04-20 00:37:51 
> -0300)
> 
> u-boot-imx-master-20240420

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: Pull request efi-2024-07-rc1-3

2024-04-20 Thread Tom Rini
On Sat, Apr 20, 2024 at 12:09:37PM +0200, Heinrich Schuchardt wrote:

> Dear Tom,
> 
> The following changes since commit af04f37a78c7e61597fb9ed6db2c8f8d7f8b0f92:
> 
>   Merge tag 'u-boot-stm32-20240419' of
> https://source.denx.de/u-boot/custodians/u-boot-stm (2024-04-19 14:25:04
> -0600)
> 
> are available in the Git repository at:
> 
>   https://source.denx.de/u-boot/custodians/u-boot-efi.git
> tags/efi-2024-07-rc1-3
> 
> for you to fetch changes up to 52c62acc349a0ec1ba26ae497913ad34ee3de733:
> 
>   x86: all firmware tables must be paragraph aligned (2024-04-20
> 10:15:03 +0200)
> 
> Gitlab CI showed no issues:
> https://source.denx.de/u-boot/custodians/u-boot-efi/-/pipelines/20447
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v1 0/2] Simple panel improvements

2024-04-20 Thread Anatolij Gustschin
On Mon,  8 Jan 2024 18:44:59 +0200
Svyatoslav Ryhel clamo...@gmail.com wrote:

> Simplify platform data pass to simple DSI panels by direct
> asigning in udevice_id struct. 
> 
> Support EDID searching in case device tree provides no
> specific timings or device has different panels (like paz00).
> 
> Svyatoslav Ryhel (2):
>   video: simple_panel: simplify platform data pass
>   video: simple_panel: add EDID support
> 
>  drivers/video/Kconfig|  2 +
>  drivers/video/simple_panel.c | 87 +---
>  2 files changed, 63 insertions(+), 26 deletions(-)

Series applied to u-boot-video. Fixed dm_i2c_* build errors with patch 2.

--
Anatolij


Re: [PATCH v3 00/17] video: dw_hdmi: Support Vendor PHY

2024-04-20 Thread Anatolij Gustschin
On Thu, 14 Mar 2024 14:55:32 +0530
Jagan Teki ja...@amarulasolutions.com wrote:
...
> > > Jagan Teki (17):
> > >   video: rockchip: hdmi: Detect hpd after controller init
> > >   video: dw_hdmi: Add Vendor PHY handling
> > >   video: dw_hdmi: Extend the HPD detection
> > >   video: dw_hdmi: Add read_hpd hook
> > >   video: dw_hdmi: Add setup_hpd hook
> > >   video: rockchip: vop: Simplify rkvop_enable
> > >   video: rockchip: vop: Add win offset support
> > >   video: rockchip: vop: Add dsp offset support
> > >   clk: rockchip: rk3328: Add VOP clk support
> > >   clk: rk3328: Add get hdmiphy clock
> > >   phy: rockchip: Add Rockchip INNO HDMI PHY driver
> > >   video: rockchip: Add rk3328 hdmi support
> > >   video: rockchip: Add rk3328 vop support
> > >   ARM: dts: rk3328: Enable VOP for bootph-all
> > >   rockchip: Enable preconsole for rk3328
> > >   configs: evb-rk3328: Enable vidconsole for rk3328
> > >   configs: Enable HDMI Out for ROC-RK3328-CC  
> >
> > Any comments on this? Or is it okay if I send a PR for this?  
> 
> Any update?

Series applied to u-boot-video.

--
Anatolij


Re: [PATCH] video: dw_hdmi: Fix compiler warnings with gcc-14

2024-04-20 Thread Anatolij Gustschin
On Sat, 27 Jan 2024 14:54:59 -0800
Khem Raj raj.k...@gmail.com wrote:

> GCC-14 find more warnings like
> "make pointer from integer without a cast"
> fix them by adding a type cast.
> 
> Signed-off-by: Khem Raj 
> Cc: Anatolij Gustschin 
> Cc: Tom Rini 
> ---
>  drivers/video/dw_hdmi.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)

applied to u-boot-video.

--
Anatolij


Re: [PATCH] video: simplefb: modernise DT parsing

2024-04-20 Thread Anatolij Gustschin
On Fri, 16 Feb 2024 18:38:06 +
Caleb Connolly caleb.conno...@linaro.org wrote:

> simplefb was using old style FDT parsing which doesn't behave well in
> combination with livetree. Update it to use ofnode instead and add a
> missing null check for the "format" property.
> 
> Standardise the error logging while we're here.
> 
> Fixes: 971d7e64245d ("video: simplefb")
> Signed-off-by: Caleb Connolly 
> ---
>  drivers/video/simplefb.c | 32 
>  1 file changed, 20 insertions(+), 12 deletions(-)

applied to u-boot-video.

--
Anatolij


Re: [PATCH 0/4] Simplefb and fb reservation related updates

2024-04-20 Thread Anatolij Gustschin
On Fri, 8 Mar 2024 16:38:28 +0530
Devarsh Thakkar devar...@ti.com wrote:

> Hi Tom, Anatolij, Simon,
> 
> On 22/02/24 18:38, Devarsh Thakkar wrote:
> > This adds support for simple-framebuffer reservation using video handoff
> > when splash is enabled at SPL stage.
> > 
> > Also adds helper function to only enable framebuffer reservation without
> > enabling simple-framebuffer in case user want to continue display
> > bootloader splash without displaying anything else in between until
> > kernel boots up.
> > 
> > Lastly, it enables above support on AM62x.
> >   
> 
> I saw a RB on first 3 patches so just wanted to check if it looks good to you
> too then is it possible to pull in the first 3 patches if no further comments 
> ?

patches 1 to 3 applied to u-boot-video. Fixed build errors with patch 3.

--
Anatolij


Re: [PATCH v2 0/7] Tegra panel improvements

2024-04-20 Thread Anatolij Gustschin
On Wed, 31 Jan 2024 08:57:14 +0200
Svyatoslav Ryhel clamo...@gmail.com wrote:

> The current patch set improves the logic of existing panels and
> bridge used by Tegra 3 devices and brings support for additional
> DSI panels used by Tegra 4 devices.
> 
> New and existing drivers are fully reusable, contain no device
> specific parts, and are written according to existing datasheets.

Series applied to u-boot-video.

--
Anatolij


Re: [PATCH v6 00/18] Add T114 video support

2024-04-20 Thread Anatolij Gustschin
On Tue, 23 Jan 2024 19:16:15 +0200
Svyatoslav Ryhel clamo...@gmail.com wrote:

> T114 is not that different from T30 and all T30 drivers will work
> on T114 as well with some adjustments.
> 
> Patches propose general improvements for existing Tegra DC and DSI
> drivers as well Tegra 114 video support (experimentl).
> 
> Commits pass buildman for tegra.

Series applied to u-boot-video, except patch 06/18.

--
Anatolij


Re: [PATCH v3 1/3] clk: imx8mm: Add support for PCIe clocks

2024-04-20 Thread Fabio Estevam
On Fri, Apr 19, 2024 at 12:29 PM Tim Harvey  wrote:
>
> Add support for PCIe clocks required to enable PCIe support on
> iMX8MM SoC.
>
> Signed-off-by: Tim Harvey 
> ---
> v3: wrap pcie clk config around IS_ENABLED to avoid SPL growth as
> suggested by Marek

Applied all, thanks.


Re: [PATCH v1] board: toradex: imx: Remove not needed env variables

2024-04-20 Thread Fabio Estevam
On Thu, Apr 18, 2024 at 10:12 AM Francesco Dolcini  wrote:
>
> From: Francesco Dolcini 
>
> Remove not needed variables from environment and include config files.
>
>  - setup variable used to be executed from some bootscript, however
>it's not required and there is no point on having this small helper
>here
>  - boot_file, kernel_file, ip_dyn variables are not used anywhere
>  - fdt_fixup variable is just set empty
>  - defargs, vidargs variables used to be used from some bootscript,
>however there is no point on having it here and even old legacy
>bootscript can work without them
>  - removed CONFIG_ENABLE_DDR_TRAINING_DEBUG, this is a leftover from
>some copy/paste
>
> On colibri imx6ull/imx7 NAND module, remove consoleblank=0, this is
> already the Linux kernel default therefore useless.
>
> Various Linux Kernel command line options removed are not-existing
> left-over that applied to some old NXP i.MX downstream branch
>
> Signed-off-by: Francesco Dolcini 

Applied, thanks.


Re: [PATCH] imx8m*_venice_defconfig: enable ipv6, wget and tftpput

2024-04-20 Thread Fabio Estevam
On Wed, Apr 17, 2024 at 5:03 PM Tim Harvey  wrote:
>
> Enable ipv6, wget, and tftpput support
>
> Signed-off-by: Tim Harvey 

Applied, thanks.


Re: [PATCH] board: gateworks: venice: fix dt adjustment for gw73xx baseboard for imx8mp

2024-04-20 Thread Fabio Estevam
On Wed, Apr 17, 2024 at 5:01 PM Tim Harvey  wrote:
>
> The GW73xx baseboard needs a PCI dt adjustment for revC/D based on a
> change of the PCIe switch. Make sure we are only doing this for a pci
> based ethernet to avoid causing a boot hang when the ethernet1 alias
> points to eqos or fec. To know this is a pcie device ensure the alias
> begins with the pcie controller.
>
> Signed-off-by: Tim Harvey 

Applied, thanks.


Re: [PATCH v1] arm: dts: verdin-imx8mm/imx8mp: use gpio-hog for sleep moci

2024-04-20 Thread Fabio Estevam
On Wed, Apr 17, 2024 at 5:49 AM Stefan Eichenberger  wrote:
>
> From: Stefan Eichenberger 
>
> In Linux, we allow sleep moci to be turned off when the carrier board
> supports it and the system is in suspend. In U-Boot, however, we want
> the sleep moci to be always on. So we use a gpio hog and disable the
> regulator. This change is necessary because we switched to upstream
> device tree files with commit 23fe2def1edf
> ("verdin-imx8mm/verdin-imx8mp: move imx verdins to OF_UPSTREAM"). A
> recent upstream patch removes the gpio hog from the Linux device tree,
> so we need to add it to the u-boot dtsi. The following patch will remove
> the gpio hog from the Linux device tree:
> https://lore.kernel.org/linux-devicetree/20240405160720.5977-1-eich...@gmail.com/
> The U-Boot patch can be applied without it and will not break the build.
>
> Signed-off-by: Stefan Eichenberger 

Applied, thanks.


Re: [PATCH] imx93: Move SoC and lifeclycle information to debug level

2024-04-20 Thread Fabio Estevam
On Mon, Apr 15, 2024 at 6:57 PM Fabio Estevam  wrote:
>
> From: Fabio Estevam 
>
> The following information printed on every boot is not very
> helpful for the users:
>
> SOC: 0xa0009300
> LC: 0x40040
>
> Move them to debug() level.
>
> Signed-off-by: Fabio Estevam 

Applied, thanks.


Re: [PATCH] imx8m*-venice: enable TPM support

2024-04-20 Thread Fabio Estevam
On Mon, Mar 25, 2024 at 1:27 PM Tim Harvey  wrote:
>
> Enable support for TPM2 devices. As the ATTPM20P TPM2 used on the
> Gateworks Venice boards hangs off the SPI bus we enable SPI support
> as well.
>
> Signed-off-by: Tim Harvey 

Applied, thanks.


[GIT PULL] Please pull u-boot-imx-master-20240420

2024-04-20 Thread Fabio Estevam
Hi Tom,

Please pull from u-boot-imx/master, thanks.

The following changes since commit af04f37a78c7e61597fb9ed6db2c8f8d7f8b0f92:

  Merge tag 'u-boot-stm32-20240419' of 
https://source.denx.de/u-boot/custodians/u-boot-stm (2024-04-19 14:25:04 -0600)

are available in the Git repository at:

  https://gitlab.denx.de/u-boot/custodians/u-boot-imx.git 
tags/u-boot-imx-master-20240420

for you to fetch changes up to 8b8c699d88171b0d40f072e114f32cce93cb2987:

  imx8mm_venice_defconfig: Enable PCIe/NVMe support (2024-04-20 00:37:51 -0300)

u-boot-imx-master-20240420
--

CI: https://source.denx.de/u-boot/custodians/u-boot-imx/-/pipelines/20444

- Make i.MX93 boot less verbose.
- Remove unneedd environment variables from Toradex i.MX boards.
- Use gpio-hog on verdin-imx8mm/imx8mp.
- Add PCIe support for i.MX8MM.
- Add TPM support for imx8m*-venice.

Fabio Estevam (1):
  imx93: Move SoC and lifeclycle information to debug level

Francesco Dolcini (1):
  board: toradex: imx: Remove not needed env variables

Stefan Eichenberger (1):
  arm: dts: verdin-imx8mm/imx8mp: use gpio-hog for sleep moci

Tim Harvey (6):
  imx8m*-venice: enable TPM support
  board: gateworks: venice: fix dt adjustment for gw73xx baseboard for 
imx8mp
  imx8m*_venice_defconfig: enable ipv6, wget and tftpput
  clk: imx8mm: Add support for PCIe clocks
  pci: dw_imx: add support for IMX8MM
  imx8mm_venice_defconfig: Enable PCIe/NVMe support

 arch/arm/dts/imx8mm-verdin-wifi-dev-u-boot.dtsi |  5 +
 arch/arm/dts/imx8mp-verdin-wifi-dev-u-boot.dtsi |  4 
 board/freescale/imx93_evk/spl.c |  4 ++--
 board/gateworks/venice/venice.c |  7 ---
 board/phytec/phycore_imx93/spl.c|  4 ++--
 board/variscite/imx93_var_som/spl.c |  4 ++--
 configs/imx8mm_venice_defconfig | 21 +++
 configs/imx8mn_venice_defconfig | 15 ++
 configs/imx8mp_venice_defconfig | 15 ++
 drivers/clk/imx/clk-imx8mm.c| 27 +
 drivers/pci/pcie_dw_imx.c   | 18 +++--
 include/configs/apalis-imx8.h   |  2 --
 include/configs/apalis_imx6.h   |  9 +
 include/configs/colibri-imx6ull.h   | 10 +++--
 include/configs/colibri-imx8x.h |  2 --
 include/configs/colibri_imx6.h  |  9 +
 include/configs/colibri_imx7.h  | 11 +++---
 include/configs/verdin-imx8mm.h |  3 ---
 include/configs/verdin-imx8mp.h |  5 -
 19 files changed, 121 insertions(+), 54 deletions(-)


Re: [PATCH 1/1] efi_loader: improve error handling in try_load_entry()

2024-04-20 Thread Ilias Apalodimas
Hi Heinrich,

On Sat, 20 Apr 2024 at 17:01, Heinrich Schuchardt
 wrote:
>
> The image is not unloaded if a security violation occurs.
>
> If efi_set_load_options() fails, we do not free the memory allocated for
> the optional data. We do not unload the image.
>
> If a load option is not active, we use a random value from the stack to
> allocate memory for the optional data of the load option.
>
> * Unload the image if a security violation occurs.
> * Free load_options if efi_set_load_options() fails.
> * Unload the image if efi_set_load_options() fails.
> * Do not allocate load_options with a random size from the stack
>   if the boot entry is not active.

Where is that happening?
Don't we always init the size in efi_get_var() &
efi_deserialize_load_option()_ which are called early?
efi_get_var() especially sets size = 0 even on failures

>
> Fixes: 53f6a5aa8626 ("efi_loader: Replace config option for initrd loading")

I think we also need a fix tag for 0ad64007feb93 as well?

> Signed-off-by: Heinrich Schuchardt 
> ---
>  lib/efi_loader/efi_bootmgr.c  | 97 +--
>  test/py/tests/test_efi_secboot/test_signed.py | 28 +++---
>  .../test_efi_secboot/test_signed_intca.py | 10 +-
>  .../tests/test_efi_secboot/test_unsigned.py   |  6 +-
>  4 files changed, 70 insertions(+), 71 deletions(-)
>
> diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
> index 4ac519228a6..ca2ebdaa32f 100644
> --- a/lib/efi_loader/efi_bootmgr.c
> +++ b/lib/efi_loader/efi_bootmgr.c
> @@ -613,9 +613,12 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
> *handle,
> void *load_option;
> efi_uintn_t size;
> efi_status_t ret;
> +   u32 attributes;
>
> -   efi_create_indexed_name(varname, sizeof(varname), "Boot", n);
> +   *handle = NULL;
> +   *load_options = NULL;
>
> +   efi_create_indexed_name(varname, sizeof(varname), "Boot", n);

> load_option = efi_get_var(varname, _global_variable_guid, );
> if (!load_option)
> return EFI_LOAD_ERROR;
> @@ -626,55 +629,54 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
> *handle,
> goto error;
> }
>
> -   if (lo.attributes & LOAD_OPTION_ACTIVE) {
> -   u32 attributes;
> -
> -   log_debug("trying to load \"%ls\" from %pD\n", lo.label,
> - lo.file_path);
> -
> -   if (EFI_DP_TYPE(lo.file_path, MEDIA_DEVICE, FILE_PATH)) {
> -   /* file_path doesn't contain a device path */
> -   ret = try_load_from_short_path(lo.file_path, handle);
> -   } else if (EFI_DP_TYPE(lo.file_path, MESSAGING_DEVICE, 
> MSG_URI)) {
> -   if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT))
> -   ret = try_load_from_uri_path(
> -   (struct efi_device_path_uri 
> *)lo.file_path,
> -   lo.label, handle);
> -   else
> -   ret = EFI_LOAD_ERROR;
> -   } else {
> -   ret = try_load_from_media(lo.file_path, handle);
> -   }
> -   if (ret != EFI_SUCCESS) {
> -   log_warning("Loading %ls '%ls' failed\n",
> -   varname, lo.label);
> -   goto error;
> -   }
> +   if (!(lo.attributes & LOAD_OPTION_ACTIVE)) {
> +   ret = EFI_LOAD_ERROR;
> +   goto error;
> +   }
>
> -   attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
> -EFI_VARIABLE_RUNTIME_ACCESS;
> -   ret = efi_set_variable_int(u"BootCurrent",
> -  _global_variable_guid,
> -  attributes, sizeof(n), , false);
> -   if (ret != EFI_SUCCESS)
> -   goto unload;
> -   /* try to register load file2 for initrd's */
> -   if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) {
> -   ret = efi_initrd_register();
> -   if (ret != EFI_SUCCESS)
> -   goto unload;
> -   }
> +   log_debug("trying to load \"%ls\" from %pD\n", lo.label, 
> lo.file_path);
>
> -   log_info("Booting: %ls\n", lo.label);
> +   if (EFI_DP_TYPE(lo.file_path, MEDIA_DEVICE, FILE_PATH)) {
> +   /* file_path doesn't contain a device path */
> +   ret = try_load_from_short_path(lo.file_path, handle);
> +   } else if (EFI_DP_TYPE(lo.file_path, MESSAGING_DEVICE, MSG_URI)) {
> +   if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT))
> +   ret = try_load_from_uri_path(
> +   (struct efi_device_path_uri *)lo.file_path,
> +   lo.label, handle);
> +   

Re: [PATCH v2 0/7] Tegra panel improvements

2024-04-20 Thread Anatolij Gustschin
On Fri, 19 Apr 2024 08:05:22 -0600
Tom Rini tr...@konsulko.com wrote:

> On Fri, Apr 19, 2024 at 02:29:20PM +0300, Svyatoslav Ryhel wrote:
> 
> > Hello Tom! This patch set is hanging in patchwork for 3 month
> > without any comments. If no one has anything to say, may you
> > pick it into master?  
> 
> There's a number of video related patches outstanding currently,
> Anatolij will you be able to put together a PR soon? Thanks.

I'll prepare a new PR today.

--
Anatolij


Re: [PATCH] cmd: terminate efidebug test bootmgr early on error

2024-04-20 Thread Ilias Apalodimas
On Sat, 20 Apr 2024 at 17:06, Heinrich Schuchardt
 wrote:
>
> If efi_bootmgr_load() fails, there is no point in trying to start an image
> that has not been loaded.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  cmd/efidebug.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> index a587860e2a5..5103ada29a5 100644
> --- a/cmd/efidebug.c
> +++ b/cmd/efidebug.c
> @@ -1397,6 +1397,8 @@ static __maybe_unused int do_efi_test_bootmgr(struct 
> cmd_tbl *cmdtp, int flag,
>
> ret = efi_bootmgr_load(, _options);
> printf("efi_bootmgr_load() returned: %ld\n", ret & ~EFI_ERROR_MASK);
> +   if (ret != EFI_SUCCESS)
> +   return CMD_RET_SUCCESS;
>
> /* We call efi_start_image() even if error for test purpose. */
> ret = EFI_CALL(efi_start_image(image, _data_size, _data));
> --
> 2.43.0
>

Reviewed-by: Ilias Apalodimas 


[PATCH] cmd: terminate efidebug test bootmgr early on error

2024-04-20 Thread Heinrich Schuchardt
If efi_bootmgr_load() fails, there is no point in trying to start an image
that has not been loaded.

Signed-off-by: Heinrich Schuchardt 
---
 cmd/efidebug.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index a587860e2a5..5103ada29a5 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -1397,6 +1397,8 @@ static __maybe_unused int do_efi_test_bootmgr(struct 
cmd_tbl *cmdtp, int flag,
 
ret = efi_bootmgr_load(, _options);
printf("efi_bootmgr_load() returned: %ld\n", ret & ~EFI_ERROR_MASK);
+   if (ret != EFI_SUCCESS)
+   return CMD_RET_SUCCESS;
 
/* We call efi_start_image() even if error for test purpose. */
ret = EFI_CALL(efi_start_image(image, _data_size, _data));
-- 
2.43.0



[PATCH 1/1] efi_loader: improve error handling in try_load_entry()

2024-04-20 Thread Heinrich Schuchardt
The image is not unloaded if a security violation occurs.

If efi_set_load_options() fails, we do not free the memory allocated for
the optional data. We do not unload the image.

If a load option is not active, we use a random value from the stack to
allocate memory for the optional data of the load option.

* Unload the image if a security violation occurs.
* Free load_options if efi_set_load_options() fails.
* Unload the image if efi_set_load_options() fails.
* Do not allocate load_options with a random size from the stack
  if the boot entry is not active.

Fixes: 53f6a5aa8626 ("efi_loader: Replace config option for initrd loading")
Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_bootmgr.c  | 97 +--
 test/py/tests/test_efi_secboot/test_signed.py | 28 +++---
 .../test_efi_secboot/test_signed_intca.py | 10 +-
 .../tests/test_efi_secboot/test_unsigned.py   |  6 +-
 4 files changed, 70 insertions(+), 71 deletions(-)

diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 4ac519228a6..ca2ebdaa32f 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -613,9 +613,12 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
*handle,
void *load_option;
efi_uintn_t size;
efi_status_t ret;
+   u32 attributes;
 
-   efi_create_indexed_name(varname, sizeof(varname), "Boot", n);
+   *handle = NULL;
+   *load_options = NULL;
 
+   efi_create_indexed_name(varname, sizeof(varname), "Boot", n);
load_option = efi_get_var(varname, _global_variable_guid, );
if (!load_option)
return EFI_LOAD_ERROR;
@@ -626,55 +629,54 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
*handle,
goto error;
}
 
-   if (lo.attributes & LOAD_OPTION_ACTIVE) {
-   u32 attributes;
-
-   log_debug("trying to load \"%ls\" from %pD\n", lo.label,
- lo.file_path);
-
-   if (EFI_DP_TYPE(lo.file_path, MEDIA_DEVICE, FILE_PATH)) {
-   /* file_path doesn't contain a device path */
-   ret = try_load_from_short_path(lo.file_path, handle);
-   } else if (EFI_DP_TYPE(lo.file_path, MESSAGING_DEVICE, 
MSG_URI)) {
-   if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT))
-   ret = try_load_from_uri_path(
-   (struct efi_device_path_uri 
*)lo.file_path,
-   lo.label, handle);
-   else
-   ret = EFI_LOAD_ERROR;
-   } else {
-   ret = try_load_from_media(lo.file_path, handle);
-   }
-   if (ret != EFI_SUCCESS) {
-   log_warning("Loading %ls '%ls' failed\n",
-   varname, lo.label);
-   goto error;
-   }
+   if (!(lo.attributes & LOAD_OPTION_ACTIVE)) {
+   ret = EFI_LOAD_ERROR;
+   goto error;
+   }
 
-   attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
-EFI_VARIABLE_RUNTIME_ACCESS;
-   ret = efi_set_variable_int(u"BootCurrent",
-  _global_variable_guid,
-  attributes, sizeof(n), , false);
-   if (ret != EFI_SUCCESS)
-   goto unload;
-   /* try to register load file2 for initrd's */
-   if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) {
-   ret = efi_initrd_register();
-   if (ret != EFI_SUCCESS)
-   goto unload;
-   }
+   log_debug("trying to load \"%ls\" from %pD\n", lo.label, lo.file_path);
 
-   log_info("Booting: %ls\n", lo.label);
+   if (EFI_DP_TYPE(lo.file_path, MEDIA_DEVICE, FILE_PATH)) {
+   /* file_path doesn't contain a device path */
+   ret = try_load_from_short_path(lo.file_path, handle);
+   } else if (EFI_DP_TYPE(lo.file_path, MESSAGING_DEVICE, MSG_URI)) {
+   if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT))
+   ret = try_load_from_uri_path(
+   (struct efi_device_path_uri *)lo.file_path,
+   lo.label, handle);
+   else
+   ret = EFI_LOAD_ERROR;
} else {
-   ret = EFI_LOAD_ERROR;
+   ret = try_load_from_media(lo.file_path, handle);
+   }
+   if (ret != EFI_SUCCESS) {
+   log_warning("Loading %ls '%ls' failed\n",
+   varname, lo.label);
+   goto error;
+   }
+
+   attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
+EFI_VARIABLE_RUNTIME_ACCESS;
+   ret = efi_set_variable_int(u"BootCurrent", 

Re: [PATCH v3 0/4]

2024-04-20 Thread Ilias Apalodimas
On Sat, 20 Apr 2024 at 10:20, Heinrich Schuchardt  wrote:
>
> On 4/18/24 14:54, Ilias Apalodimas wrote:
> > Hi!
> > This is v3 of SetVariable at runtime [0]
> >
> > Nothing changed drastically from v2.
> > A few more test cases have been added, comments/suggestions have been
> > addressed and a bug where deleting a variable by setting 'attributes' to
> > 0 has been fixed.
> >
> > Changes since v2:
> > - Add more selftests checking for variable deletion as well as the
> >VarToFile header format
> > - Use unaligned sized variables on tests
> > - Add a new function to get the variable entry length instead of
> >repurposing efi_var_mem_compare()
> > - Converted VarToFile to RO
> > - Added a few comments requested by Heinrich
> > - Fixed a bug where SetVariable with attributes set to 0 did not delete
> >the variable but returned EFI_INVALID_PARAMETER instead
> > - Run FWTS 'uefitests' and attach the log in patch #1
> > - Added r-b tags from Heinrich
> >
> > Changes since v1:
> > - Instead of Creating VarToFile at SetVariable, create it on GetVariable.
> >This allows us to get rid of the preallocated RT buffer, since the
> >address is user provided
> > - convert Set/GetVariableRT -> Set/GetVariable at runtime
> > - return EFI_INVALID_PARAM is NV is not set at runtime
> > - Heinrich sent me the efi_var_collect_mem() variant
> >
> > Changes since the RFC:
> > - Return EFI_INVALID_PARAM if attributes are not volatile
> > - Add EFI_WRITE_PROTECTED checks for BS, RT *only* variables
> > - Add 2 EFI variables and allow userspace to write the file
> > - Add selftests
> >
> > I also have a patch enable QueryVariableInfo [1], but I don't want to
> > introduce new patches now. This also needs a few more testcases of its
> > own so I'll send it once we finalize this one.
> >
> > [0] 
> > https://lore.kernel.org/u-boot/20240417101928.119115-1-ilias.apalodi...@linaro.org/T/
> > [1] 
> > https://source.denx.de/u-boot/custodians/u-boot-tpm/-/commit/ce35270aaeb93686d7e013f3b028808e8af88cc0
> >
> > Regards
> > /Ilias
> >
> > Ilias Apalodimas (4):
> >efi_loader: conditionally enable SetvariableRT
> >efi_loader: Add OS notifications for SetVariable at runtime
> >efi_loader: add an EFI variable with the file contents
> >efi_selftest: add tests for setvariableRT
>
> I am missing a defconfig change which is needed to run the unit test in
> Gitlab CI. I would prefer testing this on the sandbox.
>
> Best regards

Ok I'll send a followup since you already sent a PR with these

Thanks!
/Ilias
>
> Heinrich
>
> >
> >   include/efi_loader.h  |   4 +
> >   include/efi_variable.h|  16 +-
> >   lib/charset.c |   2 +-
> >   lib/efi_loader/Kconfig|  16 ++
> >   lib/efi_loader/efi_runtime.c  |  42 
> >   lib/efi_loader/efi_var_common.c   |   6 +-
> >   lib/efi_loader/efi_var_mem.c  | 151 -
> >   lib/efi_loader/efi_variable.c | 122 --
> >   lib/efi_loader/efi_variable_tee.c |   5 -
> >   .../efi_selftest_variables_runtime.c  | 211 +-
> >   10 files changed, 495 insertions(+), 80 deletions(-)
> >
> > --
> > 2.40.1
> >
>


Re: [PATCH v3 4/4] efi_selftest: add tests for setvariableRT

2024-04-20 Thread Ilias Apalodimas
Hi Heinrich,

I was about to fix and send a v4, but I see you fixed them up on the PR.
Thanks!

On Sat, 20 Apr 2024 at 10:23, Heinrich Schuchardt  wrote:
>
> On 4/18/24 14:54, Ilias Apalodimas wrote:
> > Since we support SetVariableRT now add the relevant tests
> >
> > - Search for the RTStorageVolatile and VarToFile variables after EBS
> > - Try to update with invalid variales (BS, RT only)
> > - Try to write a variable bigger than our backend storage
> > - Write a variable that fits and check VarToFile has been updated
> >correclty
> > - Append to the variable and check VarToFile changes
> > - Try to delete VarToFile which is write protected
> > - Try to add/delete runtime variables
> > - Verify VarToFile contains a valid file format
> >
> > Signed-off-by: Ilias Apalodimas 
> > ---
> >   .../efi_selftest_variables_runtime.c  | 197 +-
> >   1 file changed, 196 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/efi_selftest/efi_selftest_variables_runtime.c 
> > b/lib/efi_selftest/efi_selftest_variables_runtime.c
> > index 986924b881dd..28b4e9e7afa5 100644
> > --- a/lib/efi_selftest/efi_selftest_variables_runtime.c
> > +++ b/lib/efi_selftest/efi_selftest_variables_runtime.c
> > @@ -10,6 +10,8 @@
> >*/
> >
> >   #include 
> > +#include 
> > +#include 
> >
> >   #define EFI_ST_MAX_DATA_SIZE 16
> >   #define EFI_ST_MAX_VARNAME_SIZE 40
> > @@ -17,6 +19,8 @@
> >   static struct efi_boot_services *boottime;
> >   static struct efi_runtime_services *runtime;
> >   static const efi_guid_t guid_vendor0 = EFI_GLOBAL_VARIABLE_GUID;
> > +static const efi_guid_t __efi_runtime_data efi_rt_var_guid =
> > + U_BOOT_EFI_RT_VAR_FILE_GUID;
> >
> >   /*
> >* Setup unit test.
> > @@ -41,15 +45,18 @@ static int setup(const efi_handle_t img_handle,
> >   static int execute(void)
> >   {
> >   efi_status_t ret;
> > - efi_uintn_t len;
> > + efi_uintn_t len, avail, append_len = 17;
> >   u32 attr;
> >   u8 v[16] = {0x5d, 0xd1, 0x5e, 0x51, 0x5a, 0x05, 0xc7, 0x0c,
> >   0x35, 0x4a, 0xae, 0x87, 0xa5, 0xdf, 0x0f, 0x65,};
> > + u8 v2[CONFIG_EFI_VAR_BUF_SIZE];
> >   u8 data[EFI_ST_MAX_DATA_SIZE];
> > + u8 data2[CONFIG_EFI_VAR_BUF_SIZE];
> >   u16 varname[EFI_ST_MAX_VARNAME_SIZE];
> >   efi_guid_t guid;
> >   u64 max_storage, rem_storage, max_size;
> >
> > + memset(v2, 0x1, sizeof(v2));
> >   ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
> >  _storage, _storage,
> >  _size);
> > @@ -63,11 +70,199 @@ static int execute(void)
> >   EFI_VARIABLE_RUNTIME_ACCESS,
> >   3, v + 4);
> >   if (IS_ENABLED(CONFIG_EFI_RT_VOLATILE_STORE)) {
> > + efi_uintn_t prev_len, delta;
> > + struct efi_var_entry *var;
> > + struct efi_var_file *hdr;
> > +
> >   /* At runtime only non-volatile variables may be set. */
> >   if (ret != EFI_INVALID_PARAMETER) {
> >   efi_st_error("SetVariable failed\n");
> >   return EFI_ST_FAILURE;
> >   }
> > +
> > + /* runtime atttribute must be set */
> > + ret = runtime->set_variable(u"efi_st_var0", _vendor0,
> > + EFI_VARIABLE_BOOTSERVICE_ACCESS |
> > + EFI_VARIABLE_NON_VOLATILE,
> > + 3, v + 4);
> > + if (ret != EFI_INVALID_PARAMETER) {
> > + efi_st_error("SetVariable failed\n");
> > + return EFI_ST_FAILURE;
> > + }
> > +
> > + len = sizeof(data);
> > + ret = runtime->get_variable(u"RTStorageVolatile",
> > + _rt_var_guid,
> > + , , data);
> > + if (ret != EFI_SUCCESS) {
> > + efi_st_error("GetVariable failed\n");
> > + return EFI_ST_FAILURE;
> > + }
>
> We should check data against EFI_VAR_FILE_NAME.
>
> +   if (len != sizeof(EFI_VAR_FILE_NAME) ||
> +   memcmp(data, EFI_VAR_FILE_NAME,
> +  sizeof(EFI_VAR_FILE_NAME))) {
> +   data[len - 1] = 0;
> +   efi_st_error("RTStorageVolatile = %s\n", data);
> +   return EFI_ST_FAILURE;
> +   }
> +
>
> (memcmp() because we want to be able to carve out efi_selftest as a
> standalone binary in future).
>
> > +
> > + len = sizeof(data2);
> > + ret = runtime->get_variable(u"VarToFile", _rt_var_guid,
> > + , , data2);
> > + if (ret != EFI_SUCCESS) {
> > + efi_st_error("GetVariable 

Re: [PATCH] riscv: dts: jh7110: Enable PLL node in SPL

2024-04-20 Thread E Shattow
On Fri, Apr 19, 2024 at 5:51 PM Bo Gan  wrote:
>
...snip...
>
> If without the change (reverted), can you read/write the same SD media in 
> U-boot
> proper? (U-boot proper will switch BUS_ROOT to PLL2).

I tested again this change in commit e6b7aeef, before this change in
parent commit e6b7aeef~, af04f37a HEAD from today 19th Apr 2024 (which
due to not matching EEPROM product_id will be in the fall-through case
of board/starfive/visionfive2/spl.c), af04f37a with applied patchset
"board: starfive: add Milk-V Mars CM support" from 15th Apr 2024, and
af04f37a reverting changes from e6b7aeef also with applied patchset
"board: starfive: add Milk-V Mars CM support" from 15th Apr 2024.

In all builds is OpenSBI at commit d4d2582e HEAD from today 19 Apr 2024.

For each build tested per vendor Milk-V the Mars CM Lite (SD Card only
non-eMMC) has pinmux of GPIO22 instead of GPIO62:

-- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
@@ -233,7 +233,7 @@

mmc0_pins: mmc0-pins {
 mmc0-pins-rest {
-   pinmux = ;
bias-pull-up;
drive-strength = <12>;

U-Boot config is simply starfive_visionfive2_defconfig.

Results are as follows.

StarFive # mac
EEPROM INFO
Vendor : MILK-V
Product full SN: MARC-V10-2340-D004E000-06DF
data version: 0x2
PCB revision: 0xc1
BOM revision: A
Ethernet MAC0 address: 6c:cf:39:00:83:11
Ethernet MAC1 address: 6c:cf:39:00:83:12
EEPROM INFO

e6b7aeef: 2GB microSD (no speed class markings)
af04f37a: 2GB microSD (no speed class markings)
af04f37a with Mars CM patchset: 2GB microSD (no speed class markings)
StarFive # mmc rescan ; mmc info
unable to select a mode
unable to select a mode

e6b7aeef~: 2GB microSD (no speed class markings)
af04f37a revert e6b7aeef with Mars CM patchset: 2GB microSD (no speed
class markings)
StarFive # mmc rescan ; mmc info
Device: mmc@1601
Manufacturer ID: 1c
OEM: 5356
Name: USD
Bus Speed: 5000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 2.0
High Capacity: No
Capacity: 1.9 GiB
Bus Width: 1-bit
Erase Group Size: 512 Bytes

e6b7aeef: 8GB microSD Class 4
e6b7aeef~: 8GB microSD Class 4
af04f37a: 8GB microSD Class 4
af04f37a with Mars CM patchset: 8GB microSD Class 4
af04f37a revert e6b7aeef with Mars CM patchset: 8GB microSD Class 4
StarFive # mmc rescan ; mmc info
Device: mmc@1601
Manufacturer ID: 2
OEM: 544d
Name: SA08G
Bus Speed: 5000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 7.4 GiB
Bus Width: 1-bit
Erase Group Size: 512 Bytes

e6b7aeef: 8GB microSD Class 10
e6b7aeef~: 8GB microSD Class 10
af04f37a: 8GB microSD Class 10
af04f37a with Mars CM patchset: 8GB microSD Class 10
af04f37a revert e6b7aeef with Mars CM patchset: 8GB microSD Class 10
StarFive # mmc rescan ; mmc info
Device: mmc@1601
Manufacturer ID: 74
OEM: 4a60
Name: USD
Bus Speed: 5000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 7.5 GiB
Bus Width: 1-bit
Erase Group Size: 512 Bytes

e6b7aeef: 32GB microSD Class 10 A1 U1 HC1
e6b7aeef~: 32GB microSD Class 10 A1 U1 HC1
af04f37a: 32GB microSD Class 10 A1 U1 HC1
af04f37a with Mars CM patchset: 32GB microSD Class 10 A1 U1 HC1
af04f37a revert e6b7aeef with Mars CM patchset: 32GB microSD Class 10 A1 U1 HC1
StarFive # mmc rescan ; mmc info
Device: mmc@1601
Manufacturer ID: 3
OEM: 5344
Name: SC32G
Bus Speed: 5000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 29.7 GiB
Bus Width: 1-bit
Erase Group Size: 512 Bytes

e6b7aeef: 200GB microSD Class 10 A1 U1 XC1
e6b7aeef~: 200GB microSD Class 10 A1 U1 XC1
af04f37a: 200GB microSD Class 10 A1 U1 XC1
af04f37a with Mars CM patchset: 200GB microSD Class 10 A1 U1 XC1
af04f37a revert e6b7aeef with Mars CM patchset: 200GB microSD Class 10 A1 U1 XC1
StarFive # mmc rescan ; mmc info
Device: mmc@1601
Manufacturer ID: 3
OEM: 5344
Name: SC200
Bus Speed: 5000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 183.3 GiB
Bus Width: 1-bit
Erase Group Size: 512 Bytes

e6b7aeef: 256GB microSD Class U3 XC1
e6b7aeef~: 256GB microSD Class U3 XC1
af04f37a: 256GB microSD Class U3 XC1
af04f37a with Mars CM patchset: 256GB microSD Class U3 XC1
af04f37a revert e6b7aeef with Mars CM patchset: 256GB microSD Class U3 XC1
StarFive # mmc rescan ; mmc info
Device: mmc@1601
Manufacturer ID: 1b
OEM: 534d
Name: GE4S5
Bus Speed: 5000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 238.8 GiB
Bus Width: 1-bit
Erase Group Size: 512 Bytes

> One potential problem I
> could think of is perhaps the SPL built is without SPL_PINCTRL_STARFIVE/JH7110
> or the u-boot dts is missing the pinctrl that properly sets drive-strength and
> other properties of the mmc0/1 pins. What dtb are you using? I tested this 
> with
> 

[PATCH 3/3] configs: milkv_duo: Add spi nor configs

2024-04-20 Thread Kongyang Liu
Add configs related to spi nor flash for Sophgo Milk-V Duo board

Signed-off-by: Kongyang Liu 
---

 configs/milkv_duo_defconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/configs/milkv_duo_defconfig b/configs/milkv_duo_defconfig
index e8413d7aa9..c69eab5fad 100644
--- a/configs/milkv_duo_defconfig
+++ b/configs/milkv_duo_defconfig
@@ -28,5 +28,8 @@ CONFIG_MMC_UHS_SUPPORT=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_ADMA=y
 CONFIG_MMC_SDHCI_CV1800B=y
+CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_SYS_NS16550=y
 CONFIG_SYS_NS16550_MEM32=y
+CONFIG_SPI=y
+CONFIG_CV1800B_SPIF=y
-- 
2.41.0



[PATCH 2/3] riscv: dts: sophgo: Add spi nor flash controller node

2024-04-20 Thread Kongyang Liu
Add spi nor flash controller node for cv18xx SoCs

Signed-off-by: Kongyang Liu 
---

 arch/riscv/dts/cv1800b-milkv-duo.dts | 13 +
 arch/riscv/dts/cv18xx.dtsi   | 17 +
 2 files changed, 30 insertions(+)

diff --git a/arch/riscv/dts/cv1800b-milkv-duo.dts 
b/arch/riscv/dts/cv1800b-milkv-duo.dts
index 94e64ddce8..dd2c9cd17c 100644
--- a/arch/riscv/dts/cv1800b-milkv-duo.dts
+++ b/arch/riscv/dts/cv1800b-milkv-duo.dts
@@ -41,6 +41,19 @@
no-sdio;
 };
 
+ {
+   status = "okay";
+
+   spiflash@0 {
+   compatible = "jedec,spi-nor";
+   reg = <0>;
+   spi-max-frequency = <7500>;
+   spi-tx-bus-width = <4>;
+   spi-rx-bus-width = <4>;
+   m25p,fast-read;
+   };
+}
+
  {
status = "okay";
 };
diff --git a/arch/riscv/dts/cv18xx.dtsi b/arch/riscv/dts/cv18xx.dtsi
index ec99c4deeb..1623e354df 100644
--- a/arch/riscv/dts/cv18xx.dtsi
+++ b/arch/riscv/dts/cv18xx.dtsi
@@ -52,6 +52,13 @@
#clock-cells = <0>;
};
 
+   spif_clk: spi-flash-clock {
+   compatible = "fixed-clock";
+   clock-frequency = <3>;
+   clock-output-names = "spif_clk";
+   #clock-cells = <0>;
+   };
+
soc {
compatible = "simple-bus";
interrupt-parent = <>;
@@ -197,6 +204,16 @@
status = "disabled";
};
 
+   spif: spi-nor@1000 {
+   compatible = "sophgo,cv1800b-spif";
+   reg = <0x1000 0x1000>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   clocks = <_clk>;
+   interrupts = <95 IRQ_TYPE_LEVEL_HIGH>;
+   status = "disabled";
+   };
+
plic: interrupt-controller@7000 {
reg = <0x7000 0x400>;
interrupts-extended = <_intc 11>, <_intc 9>;
-- 
2.41.0



[PATCH 1/3] spi: cv1800b: Add spi nor flash controller driver for cv1800b SoC

2024-04-20 Thread Kongyang Liu
Add spi nor flash controller driver for cv1800b SoC

Signed-off-by: Kongyang Liu 

---

 drivers/spi/Kconfig|   8 +
 drivers/spi/Makefile   |   1 +
 drivers/spi/cv1800b_spif.c | 321 +
 3 files changed, 330 insertions(+)
 create mode 100644 drivers/spi/cv1800b_spif.c

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 612434633b..35030ab355 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -168,6 +168,14 @@ config CF_SPI
   Enable the ColdFire SPI driver. This driver can be used on
   some m68k SoCs.
 
+config CV1800B_SPIF
+   bool "Sophgo cv1800b SPI Flash Controller driver"
+   depends on SPI_MEM
+   help
+ Enable the Sophgo cv1800b SPI Flash Controller driver. This driver
+ can be used to access the SPI NOR flash on platforms embedding this
+ Sophgo cv1800b IP core.
+
 config DAVINCI_SPI
bool "Davinci & Keystone SPI driver"
depends on ARCH_DAVINCI || ARCH_KEYSTONE
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 14bdb97f18..32d7bf7237 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_BCM63XX_SPI) += bcm63xx_spi.o
 obj-$(CONFIG_BCMSTB_SPI) += bcmstb_spi.o
 obj-$(CONFIG_CF_SPI) += cf_spi.o
 obj-$(CONFIG_CORTINA_SFLASH) += ca_sflash.o
+obj-$(CONFIG_CV1800B_SPIF) += cv1800b_spif.o
 obj-$(CONFIG_DAVINCI_SPI) += davinci_spi.o
 obj-$(CONFIG_DESIGNWARE_SPI) += designware_spi.o
 obj-$(CONFIG_EXYNOS_SPI) += exynos_spi.o
diff --git a/drivers/spi/cv1800b_spif.c b/drivers/spi/cv1800b_spif.c
new file mode 100644
index 00..9c077f3ff9
--- /dev/null
+++ b/drivers/spi/cv1800b_spif.c
@@ -0,0 +1,321 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2024, Kongyang Liu 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define CV1800B_SPI_CTRL_SCK_DIV_MASKGENMASK(10, 0)
+#define CV1800B_SPI_CTRL_CPHABIT(12)
+#define CV1800B_SPI_CTRL_CPOLBIT(13)
+
+#define CV1800B_SPI_CE_MANUALBIT(0)
+#define CV1800B_SPI_CE_MANUAL_EN BIT(1)
+#define CV1800B_SPI_CE_ENABLE(CV1800B_SPI_CE_MANUAL | \
+ CV1800B_SPI_CE_MANUAL_EN)
+#define CV1800B_SPI_CE_DISABLE   CV1800B_SPI_CE_MANUAL_EN
+#define CV1800B_SPI_CE_HARDWARE  0
+
+#define CV1800B_SPI_DLY_CTRL_NEG_SAMPLE  BIT(14)
+
+#define CV1800B_SPI_TRAN_MODE_RX BIT(0)
+#define CV1800B_SPI_TRAN_MODE_TX BIT(1)
+#define CV1800B_SPI_TRAN_FAST_MODE   BIT(3)
+#define CV1800B_SPI_TRAN_BUS_WIDTH_1_BIT 0x0
+#define CV1800B_SPI_TRAN_BUS_WIDTH_2_BIT BIT(4)
+#define CV1800B_SPI_TRAN_BUS_WIDTH_4_BIT BIT(5)
+#define CV1800B_SPI_TRAN_ADDR_3_BYTES(3 << 8)
+#define CV1800B_SPI_TRAN_ADDR_4_BYTES(4 << 8)
+#define CV1800B_SPI_TRAN_WITH_CMDBIT(11)
+#define CV1800B_SPI_TRAN_GO_BUSY BIT(15)
+#define CV1800B_SPI_TRAN_DUMMY_CYC_MASK  GENMASK(19, 16)
+#define CV1800B_SPI_TRAN_DUMMY_CYC_OFFSET16
+#define CV1800B_SPI_TRAN_BYTE4_ENBIT(20)
+#define CV1800B_SPI_TRAN_BYTE4_CMD   BIT(21)
+
+#define CV1800B_SPI_FF_PT_AVAILABLE_MASK GENMASK(3, 0)
+
+#define CV1800B_SPI_INT_TRAN_DONEBIT(0)
+#define CV1800B_SPI_INT_RD_FIFO  BIT(2)
+#define CV1800B_SPI_INT_WR_FIFO  BIT(3)
+
+#define CV1800B_FIFO_CAPACITY   8
+#define CV1800B_DEFAULT_DIV 4
+
+struct cv1800b_spif_regs {
+   u32 spi_ctrl;
+   u32 ce_ctrl;
+   u32 dly_ctrl;
+   u32 dmmr_ctrl;
+   u32 tran_csr;
+   u32 tran_num;
+   u32 ff_port;
+   u32 reserved0;
+   u32 ff_pt;
+   u32 reserved1;
+   u32 int_sts;
+   u32 int_en;
+};
+
+struct cv1800b_spi_priv {
+   struct cv1800b_spif_regs *regs;
+   uint clk_freq;
+   uint mode;
+   int div;
+};
+
+static int cv1800b_spi_probe(struct udevice *bus)
+{
+   struct cv1800b_spi_priv *priv = dev_get_priv(bus);
+   struct clk clkdev;
+   int ret;
+
+   priv->regs = (struct cv1800b_spif_regs *)dev_read_addr_ptr(bus);
+   if (priv->regs == 0)
+   return -EINVAL;
+
+   ret = clk_get_by_index(bus, 0, );
+   if (ret)
+   return ret;
+   priv->clk_freq = clk_get_rate();
+
+   /* DMMR mode is enabled by default, disable it */
+   writel(0, >regs->dmmr_ctrl);
+
+   return 0;
+}
+
+static void cv1800b_spi_config_dmmr(struct cv1800b_spi_priv *priv, struct 
spi_nor *flash)
+{
+   struct cv1800b_spif_regs *regs = priv->regs;
+   u32 read_cmd = flash->read_opcode;
+   u32 val;
+
+   val = 

[PATCH 0/3] spi: sophgo: milkv_duo: Add spi nor flash support for Milk-V Duo board

2024-04-20 Thread Kongyang Liu
This series add spi nor flash controller driver for cv1800b SoC and enable it
for Sophgo Milk-V Duo board.


Kongyang Liu (3):
  spi: cv1800b: Add spi nor flash controller driver for cv1800b SoC
  riscv: dts: sophgo: Add spi nor flash controller node
  configs: milkv_duo: Add spi nor configs

 arch/riscv/dts/cv1800b-milkv-duo.dts |  13 ++
 arch/riscv/dts/cv18xx.dtsi   |  17 ++
 configs/milkv_duo_defconfig  |   3 +
 drivers/spi/Kconfig  |   8 +
 drivers/spi/Makefile |   1 +
 drivers/spi/cv1800b_spif.c   | 321 +++
 6 files changed, 363 insertions(+)
 create mode 100644 drivers/spi/cv1800b_spif.c

-- 
2.41.0



[PATCH v2 3/3] configs: milkv_duo: Add ethernet configs

2024-04-20 Thread Kongyang Liu
Add configs related to ethernet and ethernet boot command for Sophgo Milk-V
Duo board

Signed-off-by: Kongyang Liu 
Reviewed-by: Leo Yu-Chi Liang 
---

(no changes since v1)

 configs/milkv_duo_defconfig | 4 
 1 file changed, 4 insertions(+)

diff --git a/configs/milkv_duo_defconfig b/configs/milkv_duo_defconfig
index e8413d7aa9..f66c4c5358 100644
--- a/configs/milkv_duo_defconfig
+++ b/configs/milkv_duo_defconfig
@@ -19,14 +19,18 @@ CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="milkv_duo# "
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PART=y
+CONFIG_CMD_DHCP=y
+CONFIG_CMD_PXE=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_ENV_OVERWRITE=y
+CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_MMC=y
 CONFIG_MMC_IO_VOLTAGE=y
 CONFIG_MMC_UHS_SUPPORT=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_ADMA=y
 CONFIG_MMC_SDHCI_CV1800B=y
+CONFIG_ETH_DESIGNWARE=y
 CONFIG_SYS_NS16550=y
 CONFIG_SYS_NS16550_MEM32=y
-- 
2.41.0



[PATCH v2 2/3] riscv: dts: sophgo: Add ethernet node

2024-04-20 Thread Kongyang Liu
Add ethernet node for cv1800b SoC

Signed-off-by: Kongyang Liu 

---

Changes in v2:
- Change compatible
- Add clocks and interrupt properties.

 arch/riscv/dts/cv1800b-milkv-duo.dts |  7 ++-
 arch/riscv/dts/cv18xx.dtsi   | 23 +++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/dts/cv1800b-milkv-duo.dts 
b/arch/riscv/dts/cv1800b-milkv-duo.dts
index 94e64ddce8..c1e6611e33 100644
--- a/arch/riscv/dts/cv1800b-milkv-duo.dts
+++ b/arch/riscv/dts/cv1800b-milkv-duo.dts
@@ -29,6 +29,11 @@
};
 };
 
+ {
+   status = "okay";
+   phy-mode = "rmii";
+};
+
  {
clock-frequency = <2500>;
 };
@@ -39,7 +44,7 @@
no-1-8-v;
no-mmc;
no-sdio;
-};
+}
 
  {
status = "okay";
diff --git a/arch/riscv/dts/cv18xx.dtsi b/arch/riscv/dts/cv18xx.dtsi
index ec99c4deeb..c95bac77be 100644
--- a/arch/riscv/dts/cv18xx.dtsi
+++ b/arch/riscv/dts/cv18xx.dtsi
@@ -50,6 +50,20 @@
clock-frequency = <37500>;
clock-output-names = "sdhci_clk";
#clock-cells = <0>;
+   }
+
+   eth_csrclk: eth-csrclk {
+   compatible = "fixed-clock";
+   clock-frequency = <25000>;
+   clock-output-names = "eth_csrclk";
+   #clock-cells = <0x0>;
+   };
+
+   eth_ptpclk: eth-ptpclk {
+   compatible = "fixed-clock";
+   clock-frequency = <5000>;
+   clock-output-names = "eth_ptpclk";
+   #clock-cells = <0x0>;
};
 
soc {
@@ -138,6 +152,15 @@
};
};
 
+   ethernet0: ethernet@407 {
+   compatible = "sophgo,cv1800b-dwmac";
+   reg = <0x0407 0x1>;
+   interrupts = <31 IRQ_TYPE_LEVEL_HIGH>;
+   clocks = <_csrclk>, <_ptpclk>;
+   clock-names = "stmmaceth", "ptp_ref";
+   status = "disabled";
+   };
+
uart0: serial@414 {
compatible = "snps,dw-apb-uart";
reg = <0x0414 0x100>;
-- 
2.41.0



[PATCH v2 1/3] board: milkv_duo: Add init code for Milk-V Duo ethernet

2024-04-20 Thread Kongyang Liu
Initialize register in cv1800b ethernet phy to make it compatible with
generic phy driver

Signed-off-by: Kongyang Liu 
Reviewed-by: Leo Yu-Chi Liang 

---

(no changes since v1)

 board/sophgo/milkv_duo/Makefile   |  3 +-
 board/sophgo/milkv_duo/board.c|  4 ++
 board/sophgo/milkv_duo/ethernet.c | 79 +++
 board/sophgo/milkv_duo/ethernet.h | 11 +
 drivers/net/designware.c  |  1 +
 5 files changed, 97 insertions(+), 1 deletion(-)
 create mode 100644 board/sophgo/milkv_duo/ethernet.c
 create mode 100644 board/sophgo/milkv_duo/ethernet.h

diff --git a/board/sophgo/milkv_duo/Makefile b/board/sophgo/milkv_duo/Makefile
index a087013f5c..d0525eba85 100644
--- a/board/sophgo/milkv_duo/Makefile
+++ b/board/sophgo/milkv_duo/Makefile
@@ -2,4 +2,5 @@
 #
 # Copyright (c) 2024, Kongyang Liu 
 
-obj-y := board.o
+obj-y += board.o
+obj-$(CONFIG_NET) += ethernet.o
diff --git a/board/sophgo/milkv_duo/board.c b/board/sophgo/milkv_duo/board.c
index eaa47be173..311576fe1c 100644
--- a/board/sophgo/milkv_duo/board.c
+++ b/board/sophgo/milkv_duo/board.c
@@ -3,7 +3,11 @@
  * Copyright (c) 2024, Kongyang Liu 
  */
 
+#include "ethernet.h"
+
 int board_init(void)
 {
+   if (IS_ENABLED(CONFIG_NET))
+   cv1800b_ephy_init();
return 0;
 }
diff --git a/board/sophgo/milkv_duo/ethernet.c 
b/board/sophgo/milkv_duo/ethernet.c
new file mode 100644
index 00..e997ce1037
--- /dev/null
+++ b/board/sophgo/milkv_duo/ethernet.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2024, Kongyang Liu 
+ */
+
+#include 
+#include 
+#include 
+
+#define REG_EPHY_TOP_WRAP (u32 *)0x03009800
+#define REG_EPHY_BASE (u32 *)0x03009000
+
+#define REG_EPHY_CTL REG_EPHY_TOP_WRAP
+#define REG_EPHY_APB_RW_SEL  REG_EPHY_TOP_WRAP + 1
+
+/* Page 0 register */
+#define REG_PHY_ID1  REG_EPHY_BASE + MII_PHYSID1
+#define REG_PHY_ID2  REG_EPHY_BASE + MII_PHYSID2
+#define REG_PHY_PAGE_SEL REG_EPHY_BASE + 0x1f
+
+/* Page 5 register */
+#define REG_PD_EN_CTLREG_EPHY_BASE + 0x10
+
+/* REG_EPHY_CTL */
+#define REG_EPHY_SHUTDOWNBIT(0)
+#define REG_EPHY_ANA_RST_N   BIT(1)
+#define REG_EPHY_DIG_RST_N   BIT(2)
+#define REG_EPHY_MAIN_RST_N  BIT(3)
+
+/* REG_PD_EN_CTL */
+#define REG_EN_ETH_TXRT  BIT(0)
+#define REG_EN_ETH_CLK100M   BIT(1)
+#define REG_EN_ETH_CLK125M   BIT(2)
+#define REG_EN_ETH_PLL_LCKDETBIT(3)
+#define REG_EN_ETH_RXADC BIT(4)
+#define REG_EN_ETH_RXPGA BIT(5)
+#define REG_EN_ETH_RXRT  BIT(6)
+#define REG_EN_ETH_TXCROSSOVER   BIT(7)
+#define REG_PD_ETH_PLL   BIT(8)
+#define REG_PD_ETH_TXDAC BIT(9)
+#define REG_PD_ETH_TXDACBST  BIT(10)
+#define REG_PD_ETH_TXECHOBIT(11)
+#define REG_PD_ETH_TXDRV_NMOSBIT(12)
+#define REG_PD_ETH_TXLDO BIT(13)
+
+void cv1800b_ephy_init(void)
+{
+   u32 reg;
+   u32 phy_id = 1;
+
+   /* enable direct memory access for phy register */
+   writel(1, REG_EPHY_APB_RW_SEL);
+
+   reg = readl(REG_EPHY_CTL);
+   reg &= ~REG_EPHY_SHUTDOWN;
+   reg |= REG_EPHY_ANA_RST_N | REG_EPHY_DIG_RST_N | REG_EPHY_MAIN_RST_N;
+   writel(reg, REG_EPHY_CTL);
+
+   /* switch to page 5 */
+   writel(5 << 8, REG_PHY_PAGE_SEL);
+   reg = readl(REG_PD_EN_CTL);
+   reg &= ~(REG_PD_ETH_TXLDO | REG_PD_ETH_TXDRV_NMOS | REG_PD_ETH_TXDAC | 
REG_PD_ETH_PLL);
+   reg |= REG_EN_ETH_TXRT | REG_EN_ETH_CLK100M | REG_EN_ETH_CLK125M
+   | REG_EN_ETH_PLL_LCKDET | REG_EN_ETH_RXADC | REG_EN_ETH_RXPGA | 
REG_EN_ETH_RXRT;
+   writel(reg, REG_PD_EN_CTL);
+
+   /* switch to page 0 */
+   writel(0 << 8, REG_PHY_PAGE_SEL);
+   /*
+* As the phy_id in the cv1800b PHY register is initialized to 0, it
+* is necessary to manually initialize the phy_id to an arbitrary
+* value so that it could corresponds to the generic PHY driver.
+*/
+   writel(phy_id >> 16, REG_PHY_ID1);
+   writel(phy_id & 0x, REG_PHY_ID2);
+
+   /* switch to MDIO control */
+   writel(0, REG_EPHY_APB_RW_SEL);
+}
diff --git a/board/sophgo/milkv_duo/ethernet.h 
b/board/sophgo/milkv_duo/ethernet.h
new file mode 100644
index 00..7b21f1b0f6
--- /dev/null
+++ b/board/sophgo/milkv_duo/ethernet.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2024, Kongyang Liu 
+ */
+
+#ifndef __CV1800B_ETHERNET_H
+#define __CV1800B_ETHERNET_H
+
+void cv1800b_ephy_init(void);
+
+#endif
diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 4c1642b29a..682045cea2 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -871,6 +871,7 @@ static const struct udevice_id designware_eth_ids[] = {
{ .compatible = "amlogic,meson6-dwmac" },
{ .compatible = "st,stm32-dwmac" },
{ .compatible = "snps,arc-dwmac-3.70a" },
+   { .compatible = "sophgo,cv1800b-dwmac" },
{ }
 };
 
-- 
2.41.0



[PATCH v2 0/3] board: sophgo: milkv_duo: Add ethernet support for Milk-V Duo board

2024-04-20 Thread Kongyang Liu
This series add init code for cv1800b ethernet phy and enable ethernet
support for Sophgo Milk-V Duo board.

In cv1800b, as the PHY register phy_id being initialized to 0, it is
necessary to initialize the PHY before the ethernet driver initialization.
Therefore, the initialization code is placed in the board_init function.

For the Linux kernel, due to the presence of a hibernation mechanism, whether
the phy id will be reset to 0 after hibernation and how to reassign it
thereafter remains an issue to consider. Once this issue is resolved, the
Ethernet driver for the Milk-V Duo will be sent to the kernel.

Changes in v2:
- Change compatible
- Add clocks and interrupt properties.

Kongyang Liu (3):
  board: milkv_duo: Add init code for Milk-V Duo ethernet
  riscv: dts: sophgo: Add ethernet node
  configs: milkv_duo: Add ethernet configs

 arch/riscv/dts/cv1800b-milkv-duo.dts |  7 ++-
 arch/riscv/dts/cv18xx.dtsi   | 23 
 board/sophgo/milkv_duo/Makefile  |  3 +-
 board/sophgo/milkv_duo/board.c   |  4 ++
 board/sophgo/milkv_duo/ethernet.c| 79 
 board/sophgo/milkv_duo/ethernet.h| 11 
 configs/milkv_duo_defconfig  |  4 ++
 drivers/net/designware.c |  1 +
 8 files changed, 130 insertions(+), 2 deletions(-)
 create mode 100644 board/sophgo/milkv_duo/ethernet.c
 create mode 100644 board/sophgo/milkv_duo/ethernet.h

-- 
2.41.0



Pull request efi-2024-07-rc1-3

2024-04-20 Thread Heinrich Schuchardt

Dear Tom,

The following changes since commit af04f37a78c7e61597fb9ed6db2c8f8d7f8b0f92:

  Merge tag 'u-boot-stm32-20240419' of
https://source.denx.de/u-boot/custodians/u-boot-stm (2024-04-19 14:25:04
-0600)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-efi.git
tags/efi-2024-07-rc1-3

for you to fetch changes up to 52c62acc349a0ec1ba26ae497913ad34ee3de733:

  x86: all firmware tables must be paragraph aligned (2024-04-20
10:15:03 +0200)

Gitlab CI showed no issues:
https://source.denx.de/u-boot/custodians/u-boot-efi/-/pipelines/20447


Pull request efi-2024-07-rc1-3

Documentation:

* sort env sub-commands alphabetically
* update list of aliases for the env command

UEFI:

* allow enabling SetVariable at runtime
  for future OS supported writing to ubootefi.var
* use event callback for initrd deregistration

Others:

* correct alignment of x86 firmware tables


Heinrich Schuchardt (5):
  doc: sort env sub-commands alphabetically
  doc: update list of aliases for the env command
  cmd: eficonfig: check initrd path allocation
  efi_loader: typo mstching
  x86: all firmware tables must be paragraph aligned

Ilias Apalodimas (4):
  efi_loader: conditionally enable SetvariableRT
  efi_loader: Add OS notifications for SetVariable at runtime
  efi_loader: add an EFI variable with the file contents
  efi_selftest: add tests for setvariableRT

Masahisa Kojima (1):
  efi_loader: use event callback for initrd deregistration

 arch/x86/lib/tables.c |   2 +
 cmd/eficonfig.c   |   2 +-
 doc/usage/cmd/env.rst |  35 ++--
 include/efi_loader.h  |   4 +
 include/efi_variable.h|  16 +-
 lib/charset.c |   2 +-
 lib/efi_loader/Kconfig|  16 ++
 lib/efi_loader/efi_helper.c   |   5 -
 lib/efi_loader/efi_load_initrd.c  |  82 +---
 lib/efi_loader/efi_runtime.c  |  42 
 lib/efi_loader/efi_var_common.c   |   8 +-
 lib/efi_loader/efi_var_mem.c  | 151 +--
 lib/efi_loader/efi_variable.c | 122 ++--
 lib/efi_loader/efi_variable_tee.c |   5 -
 lib/efi_selftest/efi_selftest_variables_runtime.c | 222
+-
 15 files changed, 583 insertions(+), 131 deletions(-)


Re: [PATCH v2 00/16] pxe: Allow extlinux booting without CMDLINE enabled

2024-04-20 Thread Jonas Karlman
Hi Tom and Simon,

On 2024-04-18 20:13, Tom Rini wrote:
> On Sun, Apr 14, 2024 at 06:58:03PM +0200, Jonas Karlman wrote:
>> Hi Tom and Simon,
>>
>> On 2024-04-11 03:45, Tom Rini wrote:
>>> On Thu, 14 Dec 2023 21:18:58 -0700, Simon Glass wrote:
>>>
 This series is the culmanation of the current line of refactoring
 series. It adjusts pxe to call the booting functionality directly
 rather than going through the command-line interface.

 With this is is possible to boot using the extlinux bootmeth without
 the command line enabled.

 [...]
>>>
>>> Applied to u-boot/master, thanks!
>>>
>>
>> This series is causing boot issues using extlinux in bootm_run_states():
>>
>>   ERROR: booting os 'Invalid OS' (0) is not supported
>>
>> Following extlinux.conf was used:
>>
>>   label linux
>>  kernel /Image.gz
>>  initrd /initramfs.cpio.gz
>>
>> Before this series booting works, bootm_run_states() is first called
>> with states=0x1 (BOOTM_STATE_START):
>>
>>   Scanning bootdev 'mmc@fe2b.bootdev':
>> 1  extlinux ready   mmc  1  m...@fe2b.bootdev.part 
>> /extlinux/extlinux.conf
>>   ** Booting bootflow 'mmc@fe2b.bootdev.part_1' with extlinux
>>   1:  linux
>>   Retrieving file: /Image.gz
>>   Retrieving file: /initramfs.cpio.gz
>>   bootm_run_states(): images->state: 0, states: 1
>>   bootm_run_states(): images->os.os: 0
>>   bootm_run_states(): images->os.arch: 0
>>   bootm_run_states(): boot_fn: , need_boot_fn: 0
>>  Uncompressing Kernel Image to 0
>>   ## Flattened Device Tree blob at edef8410
>>  Booting using the fdt blob at 0xedef8410
>>   Working FDT set to edef8410
>>   bootm_run_states(): images->state: 1, states: 1710
>>  Loading Ramdisk to ecdfd000, end eceb274d ... OK
>>   bootm_run_states(): images->os.os: 5
>>   bootm_run_states(): images->os.arch: 16
>>   boot_fn: eff2b83c, need_boot_fn: 0
>>  Loading Device Tree to ecde8000, end ecdfc97f ... OK
>>   Working FDT set to ecde8000
>>
>> After this series booting fails, bootm_run_states() is first called
>> with states=0x1710.
>>
>>   Scanning bootdev 'mmc@fe2b.bootdev':
>> 1  extlinux ready   mmc  1  m...@fe2b.bootdev.part 
>> /extlinux/extlinux.conf
>>   ** Booting bootflow 'mmc@fe2b.bootdev.part_1' with extlinux
>>   1:  linux
>>   Retrieving file: /Image.gz
>>   Retrieving file: /initramfs.cpio.gz
>>   bootm_run_states(): images->state: 0, states: 1710
>>   bootm_run_states(): images->os.os: 0
>>   bootm_run_states(): images->os.arch: 0
>>   bootm_run_states(): boot_fn: , need_boot_fn: 0
>>   ERROR: booting os 'Invalid OS' (0) is not supported
>>   Boot failed (err=-14)
>>
>> Looks like booti_start() -> bootm_run_states(bmi, BOOTM_STATE_START) is
>> no longer called due to changes in this series.
> 
> I think the problem is with:
> commit 6d803ec9cc757bda0c48f2fd419cb6878eab92c4
> Author: Simon Glass 
> Date:   Thu Dec 14 21:19:12 2023 -0700
> 
> pxe: Allow booting without CMDLINE for bootm methods
> 
> Use bootm_run() and booti_run() to boot rather than the command line.
> This allows extlinux to be used without CMDLINE being enabled.
> 
> Collect any error but do not return it, to match the existing code.
> 
> Signed-off-by: Simon Glass 
> 
> diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
> [snip]
> @@ -641,23 +644,18 @@ static int label_run_boot(struct pxe_context *ctx, 
> struct pxe_label *label,
>   if (!fdt_addr && genimg_get_format(buf) != IMAGE_FORMAT_FIT)
>   fdt_addr = env_get("fdtcontroladdr");
>  
> - if (fdt_addr) {
> - if (!bootm_argv[2])
> - bootm_argv[2] = "-";
> - bootm_argc = 4;
> - }
> - bootm_argv[3] = (char *)fdt_addr;
> + bmi.conf_fdt = fdt_addr;
>  
>   /* Try bootm for legacy and FIT format image */
>   if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID &&
> -IS_ENABLED(CONFIG_CMD_BOOTM))
> - do_bootm(ctx->cmdtp, 0, bootm_argc, bootm_argv);
> + IS_ENABLED(CONFIG_BOOTM))
> + ret = bootm_run();
>   /* Try booting an AArch64 Linux kernel image */
> - else if (IS_ENABLED(CONFIG_CMD_BOOTI))
> - do_booti(ctx->cmdtp, 0, bootm_argc, bootm_argv);
> + else if (IS_ENABLED(CONFIG_BOOTM))
> + ret = booti_run();
>   /* Try booting a Image */
> - else if (IS_ENABLED(CONFIG_CMD_BOOTZ))
> - do_bootz(ctx->cmdtp, 0, bootm_argc, bootm_argv);
> + else if (IS_ENABLED(CONFIG_BOOTM))
> + ret = bootz_run();
>   /* Try booting an x86_64 Linux kernel image */
>   else if (IS_ENABLED(CONFIG_CMD_ZBOOT))
>   do_zboot_parent(ctx->cmdtp, 0, zboot_argc, zboot_argv, NULL);
> 
> And this doesn't seem equivalent really. The logic used to be checking
> if we had bootm/booti/bootz and now it's always checking for
> CONFIG_BOOTM. Jonas, can you 

Re: [PATCH v3 0/4]

2024-04-20 Thread Heinrich Schuchardt

On 4/18/24 14:54, Ilias Apalodimas wrote:

Hi!
This is v3 of SetVariable at runtime [0]

Nothing changed drastically from v2.
A few more test cases have been added, comments/suggestions have been
addressed and a bug where deleting a variable by setting 'attributes' to
0 has been fixed.

Changes since v2:
- Add more selftests checking for variable deletion as well as the
   VarToFile header format
- Use unaligned sized variables on tests
- Add a new function to get the variable entry length instead of
   repurposing efi_var_mem_compare()
- Converted VarToFile to RO
- Added a few comments requested by Heinrich
- Fixed a bug where SetVariable with attributes set to 0 did not delete
   the variable but returned EFI_INVALID_PARAMETER instead
- Run FWTS 'uefitests' and attach the log in patch #1
- Added r-b tags from Heinrich

Changes since v1:
- Instead of Creating VarToFile at SetVariable, create it on GetVariable.
   This allows us to get rid of the preallocated RT buffer, since the
   address is user provided
- convert Set/GetVariableRT -> Set/GetVariable at runtime
- return EFI_INVALID_PARAM is NV is not set at runtime
- Heinrich sent me the efi_var_collect_mem() variant

Changes since the RFC:
- Return EFI_INVALID_PARAM if attributes are not volatile
- Add EFI_WRITE_PROTECTED checks for BS, RT *only* variables
- Add 2 EFI variables and allow userspace to write the file
- Add selftests

I also have a patch enable QueryVariableInfo [1], but I don't want to
introduce new patches now. This also needs a few more testcases of its
own so I'll send it once we finalize this one.

[0] 
https://lore.kernel.org/u-boot/20240417101928.119115-1-ilias.apalodi...@linaro.org/T/
[1] 
https://source.denx.de/u-boot/custodians/u-boot-tpm/-/commit/ce35270aaeb93686d7e013f3b028808e8af88cc0

Regards
/Ilias

Ilias Apalodimas (4):
   efi_loader: conditionally enable SetvariableRT
   efi_loader: Add OS notifications for SetVariable at runtime
   efi_loader: add an EFI variable with the file contents
   efi_selftest: add tests for setvariableRT


I am missing a defconfig change which is needed to run the unit test in
Gitlab CI. I would prefer testing this on the sandbox.

Best regards

Heinrich



  include/efi_loader.h  |   4 +
  include/efi_variable.h|  16 +-
  lib/charset.c |   2 +-
  lib/efi_loader/Kconfig|  16 ++
  lib/efi_loader/efi_runtime.c  |  42 
  lib/efi_loader/efi_var_common.c   |   6 +-
  lib/efi_loader/efi_var_mem.c  | 151 -
  lib/efi_loader/efi_variable.c | 122 --
  lib/efi_loader/efi_variable_tee.c |   5 -
  .../efi_selftest_variables_runtime.c  | 211 +-
  10 files changed, 495 insertions(+), 80 deletions(-)

--
2.40.1





Re: [PATCH v3 4/4] efi_selftest: add tests for setvariableRT

2024-04-20 Thread Heinrich Schuchardt

On 4/18/24 14:54, Ilias Apalodimas wrote:

Since we support SetVariableRT now add the relevant tests

- Search for the RTStorageVolatile and VarToFile variables after EBS
- Try to update with invalid variales (BS, RT only)
- Try to write a variable bigger than our backend storage
- Write a variable that fits and check VarToFile has been updated
   correclty
- Append to the variable and check VarToFile changes
- Try to delete VarToFile which is write protected
- Try to add/delete runtime variables
- Verify VarToFile contains a valid file format

Signed-off-by: Ilias Apalodimas 
---
  .../efi_selftest_variables_runtime.c  | 197 +-
  1 file changed, 196 insertions(+), 1 deletion(-)

diff --git a/lib/efi_selftest/efi_selftest_variables_runtime.c 
b/lib/efi_selftest/efi_selftest_variables_runtime.c
index 986924b881dd..28b4e9e7afa5 100644
--- a/lib/efi_selftest/efi_selftest_variables_runtime.c
+++ b/lib/efi_selftest/efi_selftest_variables_runtime.c
@@ -10,6 +10,8 @@
   */

  #include 
+#include 
+#include 

  #define EFI_ST_MAX_DATA_SIZE 16
  #define EFI_ST_MAX_VARNAME_SIZE 40
@@ -17,6 +19,8 @@
  static struct efi_boot_services *boottime;
  static struct efi_runtime_services *runtime;
  static const efi_guid_t guid_vendor0 = EFI_GLOBAL_VARIABLE_GUID;
+static const efi_guid_t __efi_runtime_data efi_rt_var_guid =
+   U_BOOT_EFI_RT_VAR_FILE_GUID;

  /*
   * Setup unit test.
@@ -41,15 +45,18 @@ static int setup(const efi_handle_t img_handle,
  static int execute(void)
  {
efi_status_t ret;
-   efi_uintn_t len;
+   efi_uintn_t len, avail, append_len = 17;
u32 attr;
u8 v[16] = {0x5d, 0xd1, 0x5e, 0x51, 0x5a, 0x05, 0xc7, 0x0c,
0x35, 0x4a, 0xae, 0x87, 0xa5, 0xdf, 0x0f, 0x65,};
+   u8 v2[CONFIG_EFI_VAR_BUF_SIZE];
u8 data[EFI_ST_MAX_DATA_SIZE];
+   u8 data2[CONFIG_EFI_VAR_BUF_SIZE];
u16 varname[EFI_ST_MAX_VARNAME_SIZE];
efi_guid_t guid;
u64 max_storage, rem_storage, max_size;

+   memset(v2, 0x1, sizeof(v2));
ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
   _storage, _storage,
   _size);
@@ -63,11 +70,199 @@ static int execute(void)
EFI_VARIABLE_RUNTIME_ACCESS,
3, v + 4);
if (IS_ENABLED(CONFIG_EFI_RT_VOLATILE_STORE)) {
+   efi_uintn_t prev_len, delta;
+   struct efi_var_entry *var;
+   struct efi_var_file *hdr;
+
/* At runtime only non-volatile variables may be set. */
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
+
+   /* runtime atttribute must be set */
+   ret = runtime->set_variable(u"efi_st_var0", _vendor0,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS |
+   EFI_VARIABLE_NON_VOLATILE,
+   3, v + 4);
+   if (ret != EFI_INVALID_PARAMETER) {
+   efi_st_error("SetVariable failed\n");
+   return EFI_ST_FAILURE;
+   }
+
+   len = sizeof(data);
+   ret = runtime->get_variable(u"RTStorageVolatile",
+   _rt_var_guid,
+   , , data);
+   if (ret != EFI_SUCCESS) {
+   efi_st_error("GetVariable failed\n");
+   return EFI_ST_FAILURE;
+   }


We should check data against EFI_VAR_FILE_NAME.

+   if (len != sizeof(EFI_VAR_FILE_NAME) ||
+   memcmp(data, EFI_VAR_FILE_NAME,
+  sizeof(EFI_VAR_FILE_NAME))) {
+   data[len - 1] = 0;
+   efi_st_error("RTStorageVolatile = %s\n", data);
+   return EFI_ST_FAILURE;
+   }
+

(memcmp() because we want to be able to carve out efi_selftest as a
standalone binary in future).


+
+   len = sizeof(data2);
+   ret = runtime->get_variable(u"VarToFile", _rt_var_guid,
+   , , data2);
+   if (ret != EFI_SUCCESS) {
+   efi_st_error("GetVariable failed\n");
+   return EFI_ST_FAILURE;
+   }
+   /*
+* VarToFile size must change once a variable is inserted
+* Store it now, we'll use it later
+*/
+   prev_len = len;
+   ret = runtime->set_variable(u"efi_st_var0", _vendor0,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS |
+