[PATCH] mtd: spinand: Add support for XTX XT26xxxDxxxxx

2023-12-25 Thread Bruce Suen
Add Support XTX Technology XT26G01DX, XT26G11DX, XT26Q01DX,
XT26G02DX, XT26G12DX, XT26Q02DX, XT26G04DX, and
XT26Q04DX SPI NAND.

These are 3V/1.8V 1G/2G/4Gbit serial SLC NAND flash device with on-die
ECC(8bit strength per 512bytes).

Datasheet Links:
- http://www.xtxtech.com/download/?AId=458
- http://www.xtxtech.com/download/?AId=495

Signed-off-by: Bruce Suen 
---
 drivers/mtd/nand/spi/Makefile |   1 +
 drivers/mtd/nand/spi/core.c   |   1 +
 drivers/mtd/nand/spi/xtx.c| 180 ++
 include/linux/mtd/spinand.h   |   1 +
 4 files changed, 183 insertions(+)
 create mode 100644 drivers/mtd/nand/spi/xtx.c

diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
index 3051de4f7e..e46cfed446 100644
--- a/drivers/mtd/nand/spi/Makefile
+++ b/drivers/mtd/nand/spi/Makefile
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 
 spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o 
winbond.o
+spinand-objs += xtx.o
 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 597b088ca7..0b4c067425 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -828,6 +828,7 @@ static const struct spinand_manufacturer 
*spinand_manufacturers[] = {
_spinand_manufacturer,
_spinand_manufacturer,
_spinand_manufacturer,
+   _spinand_manufacturer,
 };
 
 static int spinand_manufacturer_match(struct spinand_device *spinand,
diff --git a/drivers/mtd/nand/spi/xtx.c b/drivers/mtd/nand/spi/xtx.c
new file mode 100644
index 00..602861c77b
--- /dev/null
+++ b/drivers/mtd/nand/spi/xtx.c
@@ -0,0 +1,180 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2018 Stefan Roese 
+ *
+ * Derived from drivers/mtd/nand/spi/micron.c
+ *   Copyright (c) 2016-2017 Micron Technology, Inc.
+ */
+
+#ifndef __UBOOT__
+#include 
+#include 
+#endif
+#include 
+#include 
+
+#define SPINAND_MFR_XTX0x0B
+
+#define XT26XXXD_STATUS_ECC3_ECC2_MASK GENMASK(7, 6)
+#define XT26XXXD_STATUS_ECC_NO_DETECTED (0)
+#define XT26XXXD_STATUS_ECC_1_7_CORRECTED   (1)
+#define XT26XXXD_STATUS_ECC_8_CORRECTED (3)
+#define XT26XXXD_STATUS_ECC_UNCOR_ERROR (2)
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+   SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+   SPINAND_PROG_LOAD(true, 0, NULL, 0));
+
+static SPINAND_OP_VARIANTS(update_cache_variants,
+   SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
+   SPINAND_PROG_LOAD(false, 0, NULL, 0));
+
+static int xt26xxxd_ooblayout_ecc(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *region)
+{
+   if (section)
+   return -ERANGE;
+
+   region->offset = mtd->oobsize / 2;
+   region->length = mtd->oobsize / 2;
+
+   return 0;
+}
+
+static int xt26xxxd_ooblayout_free(struct mtd_info *mtd, int section,
+  struct mtd_oob_region *region)
+{
+   if (section)
+   return -ERANGE;
+
+   region->offset = 2;
+   region->length = mtd->oobsize / 2 - 2;
+
+   return 0;
+}
+
+static const struct mtd_ooblayout_ops xt26xxxd_ooblayout = {
+   .ecc = xt26xxxd_ooblayout_ecc,
+   .rfree = xt26xxxd_ooblayout_free,
+};
+
+static int xt26xxxd_ecc_get_status(struct spinand_device *spinand,
+  u8 status)
+{
+   switch (FIELD_GET(STATUS_ECC_MASK, status)) {
+   case XT26XXXD_STATUS_ECC_NO_DETECTED:
+   return 0;
+   case XT26XXXD_STATUS_ECC_UNCOR_ERROR:
+   return -EBADMSG;
+   case XT26XXXD_STATUS_ECC_1_7_CORRECTED:
+   return 4 + FIELD_GET(XT26XXXD_STATUS_ECC3_ECC2_MASK, status);
+   case XT26XXXD_STATUS_ECC_8_CORRECTED:
+   return 8;
+   default:
+   break;
+   }
+
+   return -EINVAL;
+}
+
+static const struct spinand_info xtx_spinand_table[] = {
+   SPINAND_INFO("XT26G01D",
+SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x31),
+NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
+NAND_ECCREQ(8, 512),
+SPINAND_INFO_OP_VARIANTS(_cache_variants,
+ _cache_variants,
+ _cache_variants),
+0,
+SPINAND_ECCINFO(_ooblayout,
+

Re: [PATCH v2 0/8] An effort to bring DT bindings compliance within U-Boot

2023-12-25 Thread Sumit Garg
On Fri, 22 Dec 2023 at 21:23, Krzysztof Kozlowski
 wrote:
>
> On 22/12/2023 16:45, Conor Dooley wrote:
> >>>
> >>> I suppose we have to relay information to kernel sub-arch maintainers
> >>> who aren't the same as maintaining U-Boot counterparts. How about
> >>> adding U-Boot ML to CC for whichever DT change gets submitted in the
> >>
> >> And every other project? Just setup lei filters.
> >>
> >>> kernel? Otherwise adding U-Boot sub-arch maintainers as reviewers for
> >>> corresponding kernel DT changes works too if that's acceptable.
> >>
> >> You just entirely ignored my proposal without addressing it... ok let it
> >> be. No, CC-ing U-boot maintainers changes nothing because as I said, I
> >> want kernel maintainers and contributors to be aware.
> >
> > I don't think that adding U-Boot platform maintainers as reviewers for
> > the platforms in the kernel is a terrible idea. Certainly kernel
> > platform maintainers for which U-Boot platform maintainers are added to
> > the MAINTAINERS entry will be aware. That said, something like your
>
> The point is it does not solve my concern here. I did not express
> problem that U-Boot maintainers are not aware. They can easily be aware
> by setting simple lei filters.

I thought your major concern was how we can enforce DTS backward and
forward compatibility although the DT ABI stability is already
documented here [1]. My suggestion was really based on recognising
people who really care about DT ABI for particular platforms. I think
adding people from other projects would certainly help with DT ABI
stability since the kernel is the single point of contribution. There
will be DT contributors from other projects too like you may have
already seen people contributing bootloader (U-Boot) specific
bindings/DTS changes.

[1] https://docs.kernel.org/process/maintainer-soc.html#devicetree-abi-stability

>
> The problem I want to solve is the kernel maintainers to be aware.
>

Although Tom has already expressed in the other thread that U-Boot has
been a long time user of upstream DT but if we want to make it more
formal from an enforcement point of view then I liked Conor's idea. If
you agree then I can create maintainer profile entry as per following
example for Amlogic platforms to start with:

ARM/Amlogic Meson SoC support
M:  Neil Armstrong 
M:  Kevin Hilman 
R:  Jerome Brunet 
R:  Martin Blumenstingl 
L:  linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
L:  linux-amlo...@lists.infradead.org
S:  Maintained
P:  Documentation/process/maintainer-soc-u-boot-dt-abi.rst
W:  http://linux-meson.com/
F:  Documentation/devicetree/bindings/phy/amlogic*
F:  arch/arm/boot/dts/amlogic/
F:  arch/arm/mach-meson/
F:  arch/arm64/boot/dts/amlogic/
F:  drivers/pmdomain/amlogic/
F:  drivers/mmc/host/meson*
F:  drivers/phy/amlogic/
F:  drivers/pinctrl/meson/
F:  drivers/rtc/rtc-meson*
F:  drivers/soc/amlogic/
N:  meson

-Sumit


Re: [PATCH v2 6/6] andes: ae350: Enable MISC_INIT_R for ae350 platform

2023-12-25 Thread Yu-Chien Peter Lin
On Tue, Dec 26, 2023 at 02:54:41PM +0800, Leo Yu-Chi Liang wrote:
> Enable MISC_INIT_R for ae350 to support CPU name detection
> and re-sync the configs via make savedefconfig.
> 
> Signed-off-by: Leo Yu-Chi Liang 

Reviewed-by: Yu Chien Peter Lin 

> ---
>  configs/ae350_rv32_defconfig | 5 +++--
>  configs/ae350_rv32_spl_defconfig | 5 +++--
>  configs/ae350_rv32_spl_xip_defconfig | 5 +++--
>  configs/ae350_rv32_xip_defconfig | 5 +++--
>  configs/ae350_rv64_defconfig | 5 +++--
>  configs/ae350_rv64_spl_defconfig | 5 +++--
>  configs/ae350_rv64_spl_xip_defconfig | 5 +++--
>  configs/ae350_rv64_xip_defconfig | 5 +++--
>  8 files changed, 24 insertions(+), 16 deletions(-)
> 
> diff --git a/configs/ae350_rv32_defconfig b/configs/ae350_rv32_defconfig
> index 06cd972a0d..3bfa3e9f8e 100644
> --- a/configs/ae350_rv32_defconfig
> +++ b/configs/ae350_rv32_defconfig
> @@ -11,14 +11,15 @@ CONFIG_SYS_LOAD_ADDR=0x10
>  CONFIG_TARGET_ANDES_AE350=y
>  CONFIG_SYS_MONITOR_BASE=0x8800
>  CONFIG_FIT=y
> +CONFIG_SYS_BOOTM_LEN=0x400
>  CONFIG_DISTRO_DEFAULTS=y
>  CONFIG_BOOTDELAY=3
> +CONFIG_SYS_PBSIZE=1050
>  CONFIG_DISPLAY_CPUINFO=y
>  CONFIG_DISPLAY_BOARDINFO=y
>  CONFIG_BOARD_EARLY_INIT_F=y
> +CONFIG_MISC_INIT_R=y
>  CONFIG_SYS_PROMPT="RISC-V # "
> -CONFIG_SYS_PBSIZE=1050
> -CONFIG_SYS_BOOTM_LEN=0x400
>  CONFIG_CMD_IMLS=y
>  CONFIG_CMD_MMC=y
>  CONFIG_CMD_SF_TEST=y
> diff --git a/configs/ae350_rv32_spl_defconfig 
> b/configs/ae350_rv32_spl_defconfig
> index f469d5bb2b..aeb50206d2 100644
> --- a/configs/ae350_rv32_spl_defconfig
> +++ b/configs/ae350_rv32_spl_defconfig
> @@ -16,19 +16,20 @@ CONFIG_RISCV_SMODE=y
>  CONFIG_SYS_MONITOR_BASE=0x8800
>  CONFIG_FIT=y
>  CONFIG_SPL_LOAD_FIT_ADDRESS=0x1000
> +CONFIG_SYS_BOOTM_LEN=0x400
>  CONFIG_DISTRO_DEFAULTS=y
>  CONFIG_BOOTDELAY=3
> +CONFIG_SYS_PBSIZE=1050
>  CONFIG_DISPLAY_CPUINFO=y
>  CONFIG_DISPLAY_BOARDINFO=y
>  CONFIG_BOARD_EARLY_INIT_F=y
> +CONFIG_MISC_INIT_R=y
>  CONFIG_SPL_MAX_SIZE=0x10
>  CONFIG_SPL_BSS_START_ADDR=0x40
>  CONFIG_SPL_BOARD_INIT=y
>  CONFIG_SPL_CACHE=y
>  CONFIG_SPL_OPENSBI_SCRATCH_OPTIONS=0x0
>  CONFIG_SYS_PROMPT="RISC-V # "
> -CONFIG_SYS_PBSIZE=1050
> -CONFIG_SYS_BOOTM_LEN=0x400
>  CONFIG_CMD_IMLS=y
>  CONFIG_CMD_MMC=y
>  CONFIG_CMD_SF_TEST=y
> diff --git a/configs/ae350_rv32_spl_xip_defconfig 
> b/configs/ae350_rv32_spl_xip_defconfig
> index 9672a19c23..f15ec301ce 100644
> --- a/configs/ae350_rv32_spl_xip_defconfig
> +++ b/configs/ae350_rv32_spl_xip_defconfig
> @@ -17,19 +17,20 @@ CONFIG_SPL_XIP=y
>  CONFIG_SYS_MONITOR_BASE=0x8800
>  CONFIG_FIT=y
>  CONFIG_SPL_LOAD_FIT_ADDRESS=0x8001
> +CONFIG_SYS_BOOTM_LEN=0x400
>  CONFIG_DISTRO_DEFAULTS=y
>  CONFIG_BOOTDELAY=3
> +CONFIG_SYS_PBSIZE=1050
>  CONFIG_DISPLAY_CPUINFO=y
>  CONFIG_DISPLAY_BOARDINFO=y
>  CONFIG_BOARD_EARLY_INIT_F=y
> +CONFIG_MISC_INIT_R=y
>  CONFIG_SPL_MAX_SIZE=0x10
>  CONFIG_SPL_BSS_START_ADDR=0x40
>  CONFIG_SPL_BOARD_INIT=y
>  CONFIG_SPL_CACHE=y
>  CONFIG_SPL_OPENSBI_SCRATCH_OPTIONS=0x0
>  CONFIG_SYS_PROMPT="RISC-V # "
> -CONFIG_SYS_PBSIZE=1050
> -CONFIG_SYS_BOOTM_LEN=0x400
>  CONFIG_CMD_IMLS=y
>  CONFIG_CMD_MMC=y
>  CONFIG_CMD_SF_TEST=y
> diff --git a/configs/ae350_rv32_xip_defconfig 
> b/configs/ae350_rv32_xip_defconfig
> index b90200a97e..c40eb043c5 100644
> --- a/configs/ae350_rv32_xip_defconfig
> +++ b/configs/ae350_rv32_xip_defconfig
> @@ -12,14 +12,15 @@ CONFIG_TARGET_ANDES_AE350=y
>  CONFIG_XIP=y
>  CONFIG_SYS_MONITOR_BASE=0x8800
>  CONFIG_FIT=y
> +CONFIG_SYS_BOOTM_LEN=0x400
>  CONFIG_DISTRO_DEFAULTS=y
>  CONFIG_BOOTDELAY=3
> +CONFIG_SYS_PBSIZE=1050
>  CONFIG_DISPLAY_CPUINFO=y
>  CONFIG_DISPLAY_BOARDINFO=y
>  CONFIG_BOARD_EARLY_INIT_F=y
> +CONFIG_MISC_INIT_R=y
>  CONFIG_SYS_PROMPT="RISC-V # "
> -CONFIG_SYS_PBSIZE=1050
> -CONFIG_SYS_BOOTM_LEN=0x400
>  CONFIG_CMD_IMLS=y
>  CONFIG_CMD_MMC=y
>  CONFIG_CMD_SF_TEST=y
> diff --git a/configs/ae350_rv64_defconfig b/configs/ae350_rv64_defconfig
> index a4b9ad6162..7ae938aeb2 100644
> --- a/configs/ae350_rv64_defconfig
> +++ b/configs/ae350_rv64_defconfig
> @@ -11,14 +11,15 @@ CONFIG_TARGET_ANDES_AE350=y
>  CONFIG_ARCH_RV64I=y
>  CONFIG_SYS_MONITOR_BASE=0x8800
>  CONFIG_FIT=y
> +CONFIG_SYS_BOOTM_LEN=0x400
>  CONFIG_DISTRO_DEFAULTS=y
>  CONFIG_BOOTDELAY=3
> +CONFIG_SYS_PBSIZE=1050
>  CONFIG_DISPLAY_CPUINFO=y
>  CONFIG_DISPLAY_BOARDINFO=y
>  CONFIG_BOARD_EARLY_INIT_F=y
> +CONFIG_MISC_INIT_R=y
>  CONFIG_SYS_PROMPT="RISC-V # "
> -CONFIG_SYS_PBSIZE=1050
> -CONFIG_SYS_BOOTM_LEN=0x400
>  CONFIG_CMD_IMLS=y
>  CONFIG_CMD_MMC=y
>  CONFIG_CMD_SF_TEST=y
> diff --git a/configs/ae350_rv64_spl_defconfig 
> b/configs/ae350_rv64_spl_defconfig
> index 834a0fbbdd..68ac4325ab 100644
> --- a/configs/ae350_rv64_spl_defconfig
> +++ b/configs/ae350_rv64_spl_defconfig
> @@ -16,19 +16,20 @@ CONFIG_RISCV_SMODE=y
>  CONFIG_SYS_MONITOR_BASE=0x8800
>  CONFIG_FIT=y
>  CONFIG_SPL_LOAD_FIT_ADDRESS=0x1000
> +CONFIG_SYS_BOOTM_LEN=0x400
>  

Re: [PATCH v2 5/6] andes: ae350: Save cpu name to env

2023-12-25 Thread Yu-Chien Peter Lin
On Tue, Dec 26, 2023 at 02:54:27PM +0800, Leo Yu-Chi Liang wrote:
> Detect CPU name through marchid and then save it to env.
> 
> Signed-off-by: Leo Yu-Chi Liang 

Reviewed-by: Yu Chien Peter Lin 

> ---
>  board/AndesTech/ae350/ae350.c | 23 +++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/board/AndesTech/ae350/ae350.c b/board/AndesTech/ae350/ae350.c
> index bef9e3149e..4e53fee5d2 100644
> --- a/board/AndesTech/ae350/ae350.c
> +++ b/board/AndesTech/ae350/ae350.c
> @@ -13,7 +13,9 @@
>  #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
>  #include 
>  #endif
> +#include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -27,6 +29,27 @@ DECLARE_GLOBAL_DATA_PTR;
>  /*
>   * Miscellaneous platform dependent initializations
>   */
> +#if IS_ENABLED(CONFIG_MISC_INIT_R)
> +int misc_init_r(void)
> +{
> +long csr_marchid = 0;
> +const long mask_64 = 0x8000;
> +const long mask_cpu = 0xff;
> +char cpu_name[10] = {};
> +
> +#if CONFIG_IS_ENABLED(RISCV_SMODE)
> +sbi_get_marchid(_marchid);
> +#elif CONFIG_IS_ENABLED(RISCV_MMODE)
> +csr_marchid = csr_read(CSR_MARCHID);
> +#endif
> +if (mask_64 & csr_marchid)
> +snprintf(cpu_name, sizeof(cpu_name), "ax%lx", (mask_cpu & 
> csr_marchid));
> +else
> +snprintf(cpu_name, sizeof(cpu_name), "a%lx", (mask_cpu & 
> csr_marchid));
> +
> +return env_set("cpu", cpu_name);
> +}
> +#endif
>  
>  #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
>  #define ANDES_SPL_FDT_ADDR   (CONFIG_TEXT_BASE - 0x10)
> -- 
> 2.34.1
> 


Re: [PATCH v2 4/6] andes: cpu: Enable cache and TLB ECC support

2023-12-25 Thread Yu-Chien Peter Lin
On Tue, Dec 26, 2023 at 02:17:35PM +0800, Leo Yu-Chi Liang wrote:
> Andes CPU supports cache and TLB ECC.
> Enable them by default.
> 
> Signed-off-by: Leo Yu-Chi Liang 

Reviewed-by: Yu Chien Peter Lin 

> ---
>  arch/riscv/cpu/andesv5/cpu.c| 3 ++-
>  arch/riscv/include/asm/arch-andes/csr.h | 3 +++
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/cpu/andesv5/cpu.c b/arch/riscv/cpu/andesv5/cpu.c
> index a23b7948d9..d25ecba0e8 100644
> --- a/arch/riscv/cpu/andesv5/cpu.c
> +++ b/arch/riscv/cpu/andesv5/cpu.c
> @@ -35,7 +35,8 @@ void harts_early_init(void)
>  
>   mcache_ctl_val |= (MCACHE_CTL_CCTL_SUEN | \
>   MCACHE_CTL_IC_PREFETCH_EN | 
> MCACHE_CTL_DC_PREFETCH_EN | \
> - MCACHE_CTL_DC_WAROUND_EN | 
> MCACHE_CTL_L2C_WAROUND_EN);
> + MCACHE_CTL_DC_WAROUND_EN | 
> MCACHE_CTL_L2C_WAROUND_EN | \
> + MCACHE_CTL_IC_ECCEN | MCACHE_CTL_DC_ECCEN | 
> MCACHE_CTL_TLB_ECCEN);
>  
>   if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
>   mcache_ctl_val |= MCACHE_CTL_IC_EN;
> diff --git a/arch/riscv/include/asm/arch-andes/csr.h 
> b/arch/riscv/include/asm/arch-andes/csr.h
> index 3f3f05b348..028fd01c2f 100644
> --- a/arch/riscv/include/asm/arch-andes/csr.h
> +++ b/arch/riscv/include/asm/arch-andes/csr.h
> @@ -18,11 +18,14 @@
>  
>  #define MCACHE_CTL_IC_EN BIT(0)
>  #define MCACHE_CTL_DC_EN BIT(1)
> +#define MCACHE_CTL_IC_ECCEN  BIT(3)
> +#define MCACHE_CTL_DC_ECCEN  BIT(5)
>  #define MCACHE_CTL_CCTL_SUEN BIT(8)
>  #define MCACHE_CTL_IC_PREFETCH_ENBIT(9)
>  #define MCACHE_CTL_DC_PREFETCH_ENBIT(10)
>  #define MCACHE_CTL_DC_WAROUND_EN BIT(13)
>  #define MCACHE_CTL_L2C_WAROUND_ENBIT(15)
> +#define MCACHE_CTL_TLB_ECCEN BIT(18)
>  #define MCACHE_CTL_DC_COHEN  BIT(19)
>  #define MCACHE_CTL_DC_COHSTA BIT(20)
>  
> -- 
> 2.34.1
> 


Re: [PATCH v2 3/6] andes: cpu: Enable memboost feature

2023-12-25 Thread Yu-Chien Peter Lin
On Tue, Dec 26, 2023 at 02:17:34PM +0800, Leo Yu-Chi Liang wrote:
> Andes CPU has memboost feature including prefetch,
> write-around and non-blocking load. Enable them by default.
> 
> Signed-off-by: Leo Yu-Chi Liang 

Reviewed-by: Yu Chien Peter Lin 

> ---
>  arch/riscv/cpu/andesv5/cpu.c| 9 -
>  arch/riscv/include/asm/arch-andes/csr.h | 6 ++
>  2 files changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/cpu/andesv5/cpu.c b/arch/riscv/cpu/andesv5/cpu.c
> index e764f6c5c0..a23b7948d9 100644
> --- a/arch/riscv/cpu/andesv5/cpu.c
> +++ b/arch/riscv/cpu/andesv5/cpu.c
> @@ -31,8 +31,11 @@ void harts_early_init(void)
>   /* Enable I/D-cache in SPL */
>   if (CONFIG_IS_ENABLED(RISCV_MMODE)) {
>   unsigned long mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
> + unsigned long mmisc_ctl_val = csr_read(CSR_MMISC_CTL);
>  
> - mcache_ctl_val |= MCACHE_CTL_CCTL_SUEN;
> + mcache_ctl_val |= (MCACHE_CTL_CCTL_SUEN | \
> + MCACHE_CTL_IC_PREFETCH_EN | 
> MCACHE_CTL_DC_PREFETCH_EN | \
> + MCACHE_CTL_DC_WAROUND_EN | 
> MCACHE_CTL_L2C_WAROUND_EN);
>  
>   if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
>   mcache_ctl_val |= MCACHE_CTL_IC_EN;
> @@ -52,5 +55,9 @@ void harts_early_init(void)
>   while (!(csr_read(CSR_MCACHE_CTL) & 
> MCACHE_CTL_DC_COHSTA));
>   }
>   }
> +
> + mmisc_ctl_val |= MMISC_CTL_NON_BLOCKING_EN;
> +
> + csr_write(CSR_MMISC_CTL, mmisc_ctl_val);
>   }
>  }
> diff --git a/arch/riscv/include/asm/arch-andes/csr.h 
> b/arch/riscv/include/asm/arch-andes/csr.h
> index 12d5eb6f6c..3f3f05b348 100644
> --- a/arch/riscv/include/asm/arch-andes/csr.h
> +++ b/arch/riscv/include/asm/arch-andes/csr.h
> @@ -19,9 +19,15 @@
>  #define MCACHE_CTL_IC_EN BIT(0)
>  #define MCACHE_CTL_DC_EN BIT(1)
>  #define MCACHE_CTL_CCTL_SUEN BIT(8)
> +#define MCACHE_CTL_IC_PREFETCH_ENBIT(9)
> +#define MCACHE_CTL_DC_PREFETCH_ENBIT(10)
> +#define MCACHE_CTL_DC_WAROUND_EN BIT(13)
> +#define MCACHE_CTL_L2C_WAROUND_ENBIT(15)
>  #define MCACHE_CTL_DC_COHEN  BIT(19)
>  #define MCACHE_CTL_DC_COHSTA BIT(20)
>  
> +/* mmisc_ctl register */
> +#define MMISC_CTL_NON_BLOCKING_ENBIT(8)
>  
>  #define CCTL_L1D_WBINVAL_ALL 6
>  
> -- 
> 2.34.1
> 


Re: [PATCH v2 2/6] andes: ae350: Implement cache switch via Kconfig

2023-12-25 Thread Yu-Chien Peter Lin
On Tue, Dec 26, 2023 at 02:17:33PM +0800, Leo Yu-Chi Liang wrote:
> Kconfig provides SYS_[I|D]CACHE_OFF config options to switch off caches.
> Provide the corresponding implementation to the options.
> 
> Signed-off-by: Leo Yu-Chi Liang 

Reviewed-by: Yu Chien Peter Lin 

> ---
>  arch/riscv/cpu/andesv5/cpu.c  | 25 -
>  board/AndesTech/ae350/ae350.c |  3 ++-
>  2 files changed, 18 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/riscv/cpu/andesv5/cpu.c b/arch/riscv/cpu/andesv5/cpu.c
> index 63bc24cdfc..e764f6c5c0 100644
> --- a/arch/riscv/cpu/andesv5/cpu.c
> +++ b/arch/riscv/cpu/andesv5/cpu.c
> @@ -32,18 +32,25 @@ void harts_early_init(void)
>   if (CONFIG_IS_ENABLED(RISCV_MMODE)) {
>   unsigned long mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
>  
> - mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_IC_EN |
> -MCACHE_CTL_DC_EN | MCACHE_CTL_CCTL_SUEN);
> + mcache_ctl_val |= MCACHE_CTL_CCTL_SUEN;
> +
> + if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
> + mcache_ctl_val |= MCACHE_CTL_IC_EN;
> +
> + if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
> + mcache_ctl_val |= (MCACHE_CTL_DC_EN | 
> MCACHE_CTL_DC_COHEN);
>  
>   csr_write(CSR_MCACHE_CTL, mcache_ctl_val);
>  
> - /*
> -  * Check mcache_ctl.DC_COHEN, we assume this platform does
> -  * not support CM if the bit is hard-wired to 0.
> -  */
> - if (csr_read(CSR_MCACHE_CTL) & MCACHE_CTL_DC_COHEN) {
> - /* Wait for DC_COHSTA bit to be set */
> - while (!(csr_read(CSR_MCACHE_CTL) & 
> MCACHE_CTL_DC_COHSTA));
> + if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) {
> + /*
> +  * Check mcache_ctl.DC_COHEN, we assume this platform 
> does
> +  * not support CM if the bit is hard-wired to 0.
> +  */
> + if (csr_read(CSR_MCACHE_CTL) & MCACHE_CTL_DC_COHEN) {
> + /* Wait for DC_COHSTA bit to be set */
> + while (!(csr_read(CSR_MCACHE_CTL) & 
> MCACHE_CTL_DC_COHSTA));
> + }
>   }
>   }
>  }
> diff --git a/board/AndesTech/ae350/ae350.c b/board/AndesTech/ae350/ae350.c
> index 772c6bf1ee..bef9e3149e 100644
> --- a/board/AndesTech/ae350/ae350.c
> +++ b/board/AndesTech/ae350/ae350.c
> @@ -102,7 +102,8 @@ void *board_fdt_blob_setup(int *err)
>  void spl_board_init()
>  {
>   /* enable v5l2 cache */
> - enable_caches();
> + if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
> + enable_caches();
>  }
>  #endif
>  
> -- 
> 2.34.1
> 


Re: [PATCH v2 1/6] andes: csr.h: Clean up CSR definition

2023-12-25 Thread Yu-Chien Peter Lin
On Tue, Dec 26, 2023 at 02:17:32PM +0800, Leo Yu-Chi Liang wrote:
> Signed-off-by: Leo Yu-Chi Liang 

Reviewed-by: Yu Chien Peter Lin 

>  arch/riscv/include/asm/arch-andes/csr.h | 20 
>  arch/riscv/include/asm/csr.h|  1 +
>  2 files changed, 9 insertions(+), 12 deletions(-)
> 
> diff --git a/arch/riscv/include/asm/arch-andes/csr.h 
> b/arch/riscv/include/asm/arch-andes/csr.h
> index 393d51c6dd..12d5eb6f6c 100644
> --- a/arch/riscv/include/asm/arch-andes/csr.h
> +++ b/arch/riscv/include/asm/arch-andes/csr.h
> @@ -12,20 +12,16 @@
>  
>  #define CSR_MCACHE_CTL 0x7ca
>  #define CSR_MMISC_CTL 0x7d0
> -#define CSR_MARCHID 0xf12
>  #define CSR_MCCTLCOMMAND 0x7cc
>  
> -#define MCACHE_CTL_IC_EN_OFFSET 0
> -#define MCACHE_CTL_DC_EN_OFFSET 1
> -#define MCACHE_CTL_CCTL_SUEN_OFFSET 8
> -#define MCACHE_CTL_DC_COHEN_OFFSET 19
> -#define MCACHE_CTL_DC_COHSTA_OFFSET 20
> -
> -#define MCACHE_CTL_IC_EN BIT(MCACHE_CTL_IC_EN_OFFSET)
> -#define MCACHE_CTL_DC_EN BIT(MCACHE_CTL_DC_EN_OFFSET)
> -#define MCACHE_CTL_CCTL_SUEN BIT(MCACHE_CTL_CCTL_SUEN_OFFSET)
> -#define MCACHE_CTL_DC_COHEN BIT(MCACHE_CTL_DC_COHEN_OFFSET)
> -#define MCACHE_CTL_DC_COHSTA BIT(MCACHE_CTL_DC_COHSTA_OFFSET)
> +/* mcache_ctl register */
> +
> +#define MCACHE_CTL_IC_EN BIT(0)
> +#define MCACHE_CTL_DC_EN BIT(1)
> +#define MCACHE_CTL_CCTL_SUEN BIT(8)
> +#define MCACHE_CTL_DC_COHEN  BIT(19)
> +#define MCACHE_CTL_DC_COHSTA BIT(20)
> +
>  
>  #define CCTL_L1D_WBINVAL_ALL 6
>  
> diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
> index 1a15089cae..986f951c31 100644
> --- a/arch/riscv/include/asm/csr.h
> +++ b/arch/riscv/include/asm/csr.h
> @@ -142,6 +142,7 @@
>  #define CSR_CYCLEH   0xc80
>  #define CSR_TIMEH0xc81
>  #define CSR_INSTRETH 0xc82
> +#define CSR_MARCHID  0xf12
>  #define CSR_MHARTID  0xf14
>  
>  #ifndef __ASSEMBLY__
> -- 
> 2.34.1
> 


[PATCH v2 6/6] andes: ae350: Enable MISC_INIT_R for ae350 platform

2023-12-25 Thread Leo Yu-Chi Liang
Enable MISC_INIT_R for ae350 to support CPU name detection
and re-sync the configs via make savedefconfig.

Signed-off-by: Leo Yu-Chi Liang 
---
 configs/ae350_rv32_defconfig | 5 +++--
 configs/ae350_rv32_spl_defconfig | 5 +++--
 configs/ae350_rv32_spl_xip_defconfig | 5 +++--
 configs/ae350_rv32_xip_defconfig | 5 +++--
 configs/ae350_rv64_defconfig | 5 +++--
 configs/ae350_rv64_spl_defconfig | 5 +++--
 configs/ae350_rv64_spl_xip_defconfig | 5 +++--
 configs/ae350_rv64_xip_defconfig | 5 +++--
 8 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/configs/ae350_rv32_defconfig b/configs/ae350_rv32_defconfig
index 06cd972a0d..3bfa3e9f8e 100644
--- a/configs/ae350_rv32_defconfig
+++ b/configs/ae350_rv32_defconfig
@@ -11,14 +11,15 @@ CONFIG_SYS_LOAD_ADDR=0x10
 CONFIG_TARGET_ANDES_AE350=y
 CONFIG_SYS_MONITOR_BASE=0x8800
 CONFIG_FIT=y
+CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=3
+CONFIG_SYS_PBSIZE=1050
 CONFIG_DISPLAY_CPUINFO=y
 CONFIG_DISPLAY_BOARDINFO=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_MISC_INIT_R=y
 CONFIG_SYS_PROMPT="RISC-V # "
-CONFIG_SYS_PBSIZE=1050
-CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
diff --git a/configs/ae350_rv32_spl_defconfig b/configs/ae350_rv32_spl_defconfig
index f469d5bb2b..aeb50206d2 100644
--- a/configs/ae350_rv32_spl_defconfig
+++ b/configs/ae350_rv32_spl_defconfig
@@ -16,19 +16,20 @@ CONFIG_RISCV_SMODE=y
 CONFIG_SYS_MONITOR_BASE=0x8800
 CONFIG_FIT=y
 CONFIG_SPL_LOAD_FIT_ADDRESS=0x1000
+CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=3
+CONFIG_SYS_PBSIZE=1050
 CONFIG_DISPLAY_CPUINFO=y
 CONFIG_DISPLAY_BOARDINFO=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_MISC_INIT_R=y
 CONFIG_SPL_MAX_SIZE=0x10
 CONFIG_SPL_BSS_START_ADDR=0x40
 CONFIG_SPL_BOARD_INIT=y
 CONFIG_SPL_CACHE=y
 CONFIG_SPL_OPENSBI_SCRATCH_OPTIONS=0x0
 CONFIG_SYS_PROMPT="RISC-V # "
-CONFIG_SYS_PBSIZE=1050
-CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
diff --git a/configs/ae350_rv32_spl_xip_defconfig 
b/configs/ae350_rv32_spl_xip_defconfig
index 9672a19c23..f15ec301ce 100644
--- a/configs/ae350_rv32_spl_xip_defconfig
+++ b/configs/ae350_rv32_spl_xip_defconfig
@@ -17,19 +17,20 @@ CONFIG_SPL_XIP=y
 CONFIG_SYS_MONITOR_BASE=0x8800
 CONFIG_FIT=y
 CONFIG_SPL_LOAD_FIT_ADDRESS=0x8001
+CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=3
+CONFIG_SYS_PBSIZE=1050
 CONFIG_DISPLAY_CPUINFO=y
 CONFIG_DISPLAY_BOARDINFO=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_MISC_INIT_R=y
 CONFIG_SPL_MAX_SIZE=0x10
 CONFIG_SPL_BSS_START_ADDR=0x40
 CONFIG_SPL_BOARD_INIT=y
 CONFIG_SPL_CACHE=y
 CONFIG_SPL_OPENSBI_SCRATCH_OPTIONS=0x0
 CONFIG_SYS_PROMPT="RISC-V # "
-CONFIG_SYS_PBSIZE=1050
-CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
diff --git a/configs/ae350_rv32_xip_defconfig b/configs/ae350_rv32_xip_defconfig
index b90200a97e..c40eb043c5 100644
--- a/configs/ae350_rv32_xip_defconfig
+++ b/configs/ae350_rv32_xip_defconfig
@@ -12,14 +12,15 @@ CONFIG_TARGET_ANDES_AE350=y
 CONFIG_XIP=y
 CONFIG_SYS_MONITOR_BASE=0x8800
 CONFIG_FIT=y
+CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=3
+CONFIG_SYS_PBSIZE=1050
 CONFIG_DISPLAY_CPUINFO=y
 CONFIG_DISPLAY_BOARDINFO=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_MISC_INIT_R=y
 CONFIG_SYS_PROMPT="RISC-V # "
-CONFIG_SYS_PBSIZE=1050
-CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
diff --git a/configs/ae350_rv64_defconfig b/configs/ae350_rv64_defconfig
index a4b9ad6162..7ae938aeb2 100644
--- a/configs/ae350_rv64_defconfig
+++ b/configs/ae350_rv64_defconfig
@@ -11,14 +11,15 @@ CONFIG_TARGET_ANDES_AE350=y
 CONFIG_ARCH_RV64I=y
 CONFIG_SYS_MONITOR_BASE=0x8800
 CONFIG_FIT=y
+CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=3
+CONFIG_SYS_PBSIZE=1050
 CONFIG_DISPLAY_CPUINFO=y
 CONFIG_DISPLAY_BOARDINFO=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_MISC_INIT_R=y
 CONFIG_SYS_PROMPT="RISC-V # "
-CONFIG_SYS_PBSIZE=1050
-CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_IMLS=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
diff --git a/configs/ae350_rv64_spl_defconfig b/configs/ae350_rv64_spl_defconfig
index 834a0fbbdd..68ac4325ab 100644
--- a/configs/ae350_rv64_spl_defconfig
+++ b/configs/ae350_rv64_spl_defconfig
@@ -16,19 +16,20 @@ CONFIG_RISCV_SMODE=y
 CONFIG_SYS_MONITOR_BASE=0x8800
 CONFIG_FIT=y
 CONFIG_SPL_LOAD_FIT_ADDRESS=0x1000
+CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=3
+CONFIG_SYS_PBSIZE=1050
 CONFIG_DISPLAY_CPUINFO=y
 CONFIG_DISPLAY_BOARDINFO=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_MISC_INIT_R=y
 CONFIG_SPL_MAX_SIZE=0x10
 CONFIG_SPL_BSS_START_ADDR=0x40
 CONFIG_SPL_BOARD_INIT=y
 CONFIG_SPL_CACHE=y
 CONFIG_SPL_OPENSBI_SCRATCH_OPTIONS=0x0
 CONFIG_SYS_PROMPT="RISC-V # "
-CONFIG_SYS_PBSIZE=1050
-CONFIG_SYS_BOOTM_LEN=0x400
 

[PATCH v2 5/6] andes: ae350: Save cpu name to env

2023-12-25 Thread Leo Yu-Chi Liang
Detect CPU name through marchid and then save it to env.

Signed-off-by: Leo Yu-Chi Liang 
---
 board/AndesTech/ae350/ae350.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/board/AndesTech/ae350/ae350.c b/board/AndesTech/ae350/ae350.c
index bef9e3149e..4e53fee5d2 100644
--- a/board/AndesTech/ae350/ae350.c
+++ b/board/AndesTech/ae350/ae350.c
@@ -13,7 +13,9 @@
 #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
 #include 
 #endif
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -27,6 +29,27 @@ DECLARE_GLOBAL_DATA_PTR;
 /*
  * Miscellaneous platform dependent initializations
  */
+#if IS_ENABLED(CONFIG_MISC_INIT_R)
+int misc_init_r(void)
+{
+long csr_marchid = 0;
+const long mask_64 = 0x8000;
+const long mask_cpu = 0xff;
+char cpu_name[10] = {};
+
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+sbi_get_marchid(_marchid);
+#elif CONFIG_IS_ENABLED(RISCV_MMODE)
+csr_marchid = csr_read(CSR_MARCHID);
+#endif
+if (mask_64 & csr_marchid)
+snprintf(cpu_name, sizeof(cpu_name), "ax%lx", (mask_cpu & 
csr_marchid));
+else
+snprintf(cpu_name, sizeof(cpu_name), "a%lx", (mask_cpu & csr_marchid));
+
+return env_set("cpu", cpu_name);
+}
+#endif
 
 #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
 #define ANDES_SPL_FDT_ADDR (CONFIG_TEXT_BASE - 0x10)
-- 
2.34.1



[PATCH v2 2/2] efi_loader: auto-generate removable media boot option first

2023-12-25 Thread Masahisa Kojima
This commit auto-generates the boot option for removable
block io devices followed by fixed block io devices.
This is what EDK II reference implementation does.

Signed-off-by: Masahisa Kojima 
---
 lib/efi_loader/efi_bootmgr.c | 35 +++
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 747f75ee82..a146428a65 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -584,7 +584,6 @@ static efi_status_t try_load_from_media(struct 
efi_device_path *file_path,
efi_status_t ret = EFI_SUCCESS;
struct efi_device_path *rem, *dp = NULL;
struct efi_device_path *final_dp = file_path;
-
h = efi_dp_find_obj(file_path, _block_io_guid, );
if (h) {
if (rem->type == DEVICE_PATH_TYPE_END) {
@@ -788,15 +787,19 @@ error:
  * efi_bootmgr_enumerate_boot_option() - enumerate the possible bootable media
  *
  * @opt:   pointer to the media boot option structure
+ * @index: index of the opt array to store the boot option
  * @handles:   pointer to the efi handles
  * @count: number of efi handle
+ * @removable: flag to parse removable only
  * Return: status code
  */
 static efi_status_t efi_bootmgr_enumerate_boot_option(struct 
eficonfig_media_boot_option *opt,
+ efi_uintn_t index,
  efi_handle_t *handles,
- efi_uintn_t *count)
+ efi_uintn_t *count,
+ bool removable)
 {
-   u32 i, num = 0;
+   u32 i, num = index;
struct efi_handler *handler;
efi_status_t ret = EFI_SUCCESS;
 
@@ -816,6 +819,9 @@ static efi_status_t 
efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo
if (blkio->media->logical_partition)
continue;
 
+   if (removable != (blkio->media->removable_media != 0))
+   continue;
+
ret = efi_search_protocol(handles[i], _guid_device_path, 
);
if (ret != EFI_SUCCESS)
continue;
@@ -857,6 +863,9 @@ static efi_status_t 
efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo
optional_data = (char *)opt[num].lo + (opt[num].size - 
u16_strsize(u"1234567"));
memcpy(optional_data, _guid_bootmenu_auto_generated, 
sizeof(efi_guid_t));
num++;
+
+   if (num >= *count)
+   break;
}
 
 out:
@@ -1105,7 +1114,7 @@ efi_status_t 
efi_bootmgr_update_media_device_boot_option(void)
 {
u32 i;
efi_status_t ret;
-   efi_uintn_t count;
+   efi_uintn_t count, num, total;
efi_handle_t *handles = NULL;
struct eficonfig_media_boot_option *opt = NULL;
 
@@ -1122,22 +1131,32 @@ efi_status_t 
efi_bootmgr_update_media_device_boot_option(void)
goto out;
}
 
-   ret = efi_bootmgr_enumerate_boot_option(opt, handles, );
+   /* parse removable block io followed by fixed block io */
+   num = count;
+   ret = efi_bootmgr_enumerate_boot_option(opt, 0, handles, , true);
if (ret != EFI_SUCCESS)
goto out;
 
+   total = num;
+   num = count;
+   ret = efi_bootmgr_enumerate_boot_option(opt, total, handles, , 
false);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   total = num;
+
/*
 * System hardware configuration may vary depending on the user setup.
 * The boot option is automatically added by the bootmenu.
 * If the device is not attached to the system, the boot option needs
 * to be deleted.
 */
-   ret = efi_bootmgr_delete_invalid_boot_option(opt, count);
+   ret = efi_bootmgr_delete_invalid_boot_option(opt, total);
if (ret != EFI_SUCCESS)
goto out;
 
/* add non-existent boot option */
-   for (i = 0; i < count; i++) {
+   for (i = 0; i < total; i++) {
u32 boot_index;
u16 var_name[9];
 
@@ -1166,7 +1185,7 @@ efi_status_t 
efi_bootmgr_update_media_device_boot_option(void)
 
 out:
if (opt) {
-   for (i = 0; i < count; i++)
+   for (i = 0; i < total; i++)
free(opt[i].lo);
}
free(opt);
-- 
2.34.1



[PATCH v2 1/2] efi_loader: auto-generate boot option for each blkio device

2023-12-25 Thread Masahisa Kojima
Current efibootmgr auto-generates the boot option for all
disks and partitions installing EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
while EDK II reference implementation auto-generates the boot option
for all devices installing  EFI_BLOCK_IO_PROTOCOL with
eliminating logical partitions.

This commit modifies the efibootmgr to get aligned to EDK II.

Signed-off-by: Masahisa Kojima 
---
 lib/efi_loader/efi_bootmgr.c | 94 +++-
 1 file changed, 71 insertions(+), 23 deletions(-)

diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 56d97f2382..747f75ee82 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -560,6 +560,50 @@ err:
return ret;
 }
 
+/**
+ * try_load_from_media() - load file from media
+ *
+ * @file_path: file path
+ * @handle:pointer to handle for newly installed image
+ *
+ * If @file_path contains a file name, load the file.
+ * If @file_path does not have a file name, search the architecture-specific
+ * default file and load it.
+ * TODO: If the FilePathList[0] device does not support
+ * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL but supports EFI_BLOCK_IO_PROTOCOL,
+ * call EFI_BOOT_SERVICES.ConnectController()
+ * TODO: FilePathList[0] device supports EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
+ * not based on EFI_BLOCK_IO_PROTOCOL
+ *
+ * Return: status code
+ */
+static efi_status_t try_load_from_media(struct efi_device_path *file_path,
+   efi_handle_t *handle)
+{
+   efi_handle_t h;
+   efi_status_t ret = EFI_SUCCESS;
+   struct efi_device_path *rem, *dp = NULL;
+   struct efi_device_path *final_dp = file_path;
+
+   h = efi_dp_find_obj(file_path, _block_io_guid, );
+   if (h) {
+   if (rem->type == DEVICE_PATH_TYPE_END) {
+   /* no file name present, try default file */
+   ret = check_disk_has_default_file(h->dev, );
+   if (ret != EFI_SUCCESS)
+   return ret;
+
+   final_dp = dp;
+   }
+   }
+
+   ret = EFI_CALL(efi_load_image(true, efi_root, final_dp, NULL, 0, 
handle));
+
+   efi_free_pool(dp);
+
+   return ret;
+}
+
 /**
  * try_load_entry() - try to load image for boot option
  *
@@ -594,7 +638,6 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
*handle,
}
 
if (lo.attributes & LOAD_OPTION_ACTIVE) {
-   struct efi_device_path *file_path;
u32 attributes;
 
log_debug("trying to load \"%ls\" from %pD\n", lo.label,
@@ -611,10 +654,7 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
*handle,
else
ret = EFI_LOAD_ERROR;
} else {
-   file_path = expand_media_path(lo.file_path);
-   ret = EFI_CALL(efi_load_image(true, efi_root, file_path,
- NULL, 0, handle));
-   efi_free_pool(file_path);
+   ret = try_load_from_media(lo.file_path, handle);
}
if (ret != EFI_SUCCESS) {
log_warning("Loading %ls '%ls' failed\n",
@@ -748,19 +788,19 @@ error:
  * efi_bootmgr_enumerate_boot_option() - enumerate the possible bootable media
  *
  * @opt:   pointer to the media boot option structure
- * @volume_handles:pointer to the efi handles
+ * @handles:   pointer to the efi handles
  * @count: number of efi handle
  * Return: status code
  */
 static efi_status_t efi_bootmgr_enumerate_boot_option(struct 
eficonfig_media_boot_option *opt,
- efi_handle_t 
*volume_handles,
- efi_status_t count)
+ efi_handle_t *handles,
+ efi_uintn_t *count)
 {
-   u32 i;
+   u32 i, num = 0;
struct efi_handler *handler;
efi_status_t ret = EFI_SUCCESS;
 
-   for (i = 0; i < count; i++) {
+   for (i = 0; i < *count; i++) {
u16 *p;
u16 dev_name[BOOTMENU_DEVICE_NAME_MAX];
char *optional_data;
@@ -768,8 +808,15 @@ static efi_status_t 
efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo
char buf[BOOTMENU_DEVICE_NAME_MAX];
struct efi_device_path *device_path;
struct efi_device_path *short_dp;
+   struct efi_block_io *blkio;
+
+   ret = efi_search_protocol(handles[i], _block_io_guid, 
);
+   blkio = handler->protocol_interface;
 
-   ret = efi_search_protocol(volume_handles[i], 
_guid_device_path, );
+   if (blkio->media->logical_partition)
+   continue;
+
+

[PATCH v2 0/2] fix auto-generated boot options

2023-12-25 Thread Masahisa Kojima
This series aims to get aligned to the EDK II reference
implementation for auto-generated boot options, and tries
to address the following issue.
https://source.denx.de/u-boot/custodians/u-boot-efi/-/issues/13

This series is based on the efi-next-20231217 tag.

[Changelog]
v1 -> v2
- fix make htmldocs error
- fix bootmenu python test failure

Masahisa Kojima (2):
  efi_loader: auto-generate boot option for each blkio device
  efi_loader: auto-generate removable media boot option first

 lib/efi_loader/efi_bootmgr.c | 121 +++
 1 file changed, 94 insertions(+), 27 deletions(-)

-- 
2.34.1



Re: [PATHv2 2/9] net: sandbox: fix NULL pointer derefences

2023-12-25 Thread Sean Anderson

On 12/26/23 01:18, Maxim Uvarov wrote:



On Tue, 26 Dec 2023 at 04:43, Sean Anderson mailto:sean...@gmail.com>> wrote:

On 12/25/23 10:39, Maxim Uvarov wrote:
 > Add additional checks for NULL pointers.
 >
 > Signed-off-by: Maxim Uvarov mailto:maxim.uva...@linaro.org>>
 > ---
 >   drivers/net/sandbox.c | 3 +++
 >   1 file changed, 3 insertions(+)
 >
 > diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
 > index 13022addb6..d91935e032 100644
 > --- a/drivers/net/sandbox.c
 > +++ b/drivers/net/sandbox.c
 > @@ -65,6 +65,9 @@ int sandbox_eth_arp_req_to_reply(struct udevice *dev, 
void *packet,
 >       struct ethernet_hdr *eth_recv;
 >       struct arp_hdr *arp_recv;
 >
 > +     if (!priv)
 > +             return -EAGAIN;
 > +

When can priv be NULL?

--Sean


Function
struct eth_sandbox_priv *priv = dev_get_priv(dev)
can return NULL. If you ask why it doesn't return NULL without lwip patches and 
can return NULL with lwip patch while there is no clear code dependency..
Then I can not say right now and need additional investigation. But anyway the 
return code of dev_dev_priv() has to be checked I think.


If you set priv_auto to a nonzero value, dev_get_priv will always return 
non-null
and does not need to be checked. So this is a NACK from me until you can 
justify this.

--Sean


Re: [PATCH 0/2] fix auto-generated boot options

2023-12-25 Thread Masahisa Kojima
On Tue, 26 Dec 2023 at 02:14, Heinrich Schuchardt  wrote:
>
> On 12/20/23 09:41, Masahisa Kojima wrote:
> > This series aims to get aligned to the EDK II reference
> > implementation for auto-generated boot options, and tries
> > to address the following issue.
> > https://source.denx.de/u-boot/custodians/u-boot-efi/-/issues/13
> >
> > This series is based on the efi-next-20231217 tag.
> >
> > Masahisa Kojima (2):
> >efi_loader: auto-generate boot option for each blkio device
> >efi_loader: auto-generate removable media boot option first
> >
> >   lib/efi_loader/efi_bootmgr.c | 123 +++
> >   1 file changed, 96 insertions(+), 27 deletions(-)
> >
>
> Hello Masahisa,
>
> please, have a look at the test failures in
> https://source.denx.de/u-boot/custodians/u-boot-efi/-/pipelines/19089

I fixed the error, v2 will be sent shortly.

Thanks,
Masahis Kojima

>
> Best regards
>
> Heinrich


Re: [PATHv2 8/9] omap3: use device specific naming for mem_init

2023-12-25 Thread Maxim Uvarov
On Tue, 26 Dec 2023 at 04:49, Sean Anderson  wrote:

> On 12/25/23 10:39, Maxim Uvarov wrote:
> > Use device specific naming for functions so as to not overlap
> > with common function names.
> >
> > Signed-off-by: Maxim Uvarov 
> > Reviewed-by: Tom Rini 
> > ---
> >   arch/arm/include/asm/arch-omap3/mem.h | 2 +-
> >   arch/arm/mach-omap2/omap3/board.c | 2 +-
> >   arch/arm/mach-omap2/omap3/emif4.c | 4 ++--
> >   arch/arm/mach-omap2/omap3/sdrc.c  | 6 +++---
> >   4 files changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/arch/arm/include/asm/arch-omap3/mem.h
> b/arch/arm/include/asm/arch-omap3/mem.h
> > index 569779c55e..fce3568eca 100644
> > --- a/arch/arm/include/asm/arch-omap3/mem.h
> > +++ b/arch/arm/include/asm/arch-omap3/mem.h
> > @@ -475,7 +475,7 @@ enum {
> >   #ifndef __ASSEMBLY__
> >
> >   /* Function prototypes */
> > -void mem_init(void);
> > +void omap3_mem_init(void);
> >
> >   u32 is_mem_sdr(void);
> >   u32 mem_ok(u32 cs);
> > diff --git a/arch/arm/mach-omap2/omap3/board.c
> b/arch/arm/mach-omap2/omap3/board.c
> > index 8b70251457..c76a95dd5d 100644
> > --- a/arch/arm/mach-omap2/omap3/board.c
> > +++ b/arch/arm/mach-omap2/omap3/board.c
> > @@ -216,7 +216,7 @@ void s_init(void)
> >   void board_init_f(ulong dummy)
> >   {
> >   early_system_init();
> > - mem_init();
> > + omap3_mem_init();
> >   /*
> >   * Save the boot parameters passed from romcode.
> >   * We cannot delay the saving further than this,
> > diff --git a/arch/arm/mach-omap2/omap3/emif4.c
> b/arch/arm/mach-omap2/omap3/emif4.c
> > index 7e5a281922..4fbfb387ab 100644
> > --- a/arch/arm/mach-omap2/omap3/emif4.c
> > +++ b/arch/arm/mach-omap2/omap3/emif4.c
> > @@ -159,10 +159,10 @@ int dram_init_banksize(void)
> >   }
> >
> >   /*
> > - * mem_init() -
> > + * omap3_mem_init() -
> >*  - Initialize memory subsystem
> >*/
> > -void mem_init(void)
> > +void omap3_mem_init(void)
> >   {
> >   do_emif4_init();
> >   }
> > diff --git a/arch/arm/mach-omap2/omap3/sdrc.c
> b/arch/arm/mach-omap2/omap3/sdrc.c
> > index 5d43e7c9cf..f2a0769b9d 100644
> > --- a/arch/arm/mach-omap2/omap3/sdrc.c
> > +++ b/arch/arm/mach-omap2/omap3/sdrc.c
> > @@ -4,7 +4,7 @@
> >*
> >* This file has been created after exctracting and consolidating
> >* the SDRC related content from mem.c and board.c, also created
> > - * generic init function (mem_init).
> > + * generic init function (omap3_mem_init).
> >*
> >* Copyright (C) 2004-2010
> >* Texas Instruments Incorporated - https://www.ti.com/
> > @@ -232,11 +232,11 @@ int dram_init_banksize(void)
> >   }
> >
> >   /*
> > - * mem_init -
> > + * map3_mem_init -
>
> nit: omap3
>
>
thanks, will add to v3.



> >*  - Init the sdrc chip,
> >*  - Selects CS0 and CS1,
> >*/
> > -void mem_init(void)
> > +void omap3_mem_init(void)
> >   {
> >   /* only init up first bank here */
> >   do_sdrc_init(CS0, EARLY_INIT);
>
>


Re: [PATHv2 2/9] net: sandbox: fix NULL pointer derefences

2023-12-25 Thread Maxim Uvarov
On Tue, 26 Dec 2023 at 04:43, Sean Anderson  wrote:

> On 12/25/23 10:39, Maxim Uvarov wrote:
> > Add additional checks for NULL pointers.
> >
> > Signed-off-by: Maxim Uvarov 
> > ---
> >   drivers/net/sandbox.c | 3 +++
> >   1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
> > index 13022addb6..d91935e032 100644
> > --- a/drivers/net/sandbox.c
> > +++ b/drivers/net/sandbox.c
> > @@ -65,6 +65,9 @@ int sandbox_eth_arp_req_to_reply(struct udevice *dev,
> void *packet,
> >   struct ethernet_hdr *eth_recv;
> >   struct arp_hdr *arp_recv;
> >
> > + if (!priv)
> > + return -EAGAIN;
> > +
>
> When can priv be NULL?
>
> --Sean
>
>
Function
struct eth_sandbox_priv *priv = dev_get_priv(dev)
can return NULL. If you ask why it doesn't return NULL without lwip patches
and can return NULL with lwip patch while there is no clear code
dependency..
Then I can not say right now and need additional investigation. But anyway
the return code of dev_dev_priv() has to be checked I think.

BR,
Maxim.



> >   if (ntohs(eth->et_protlen) != PROT_ARP)
> >   return -EAGAIN;
> >
>
>


[PATCH v2 4/6] andes: cpu: Enable cache and TLB ECC support

2023-12-25 Thread Leo Yu-Chi Liang
Andes CPU supports cache and TLB ECC.
Enable them by default.

Signed-off-by: Leo Yu-Chi Liang 
---
 arch/riscv/cpu/andesv5/cpu.c| 3 ++-
 arch/riscv/include/asm/arch-andes/csr.h | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/cpu/andesv5/cpu.c b/arch/riscv/cpu/andesv5/cpu.c
index a23b7948d9..d25ecba0e8 100644
--- a/arch/riscv/cpu/andesv5/cpu.c
+++ b/arch/riscv/cpu/andesv5/cpu.c
@@ -35,7 +35,8 @@ void harts_early_init(void)
 
mcache_ctl_val |= (MCACHE_CTL_CCTL_SUEN | \
MCACHE_CTL_IC_PREFETCH_EN | 
MCACHE_CTL_DC_PREFETCH_EN | \
-   MCACHE_CTL_DC_WAROUND_EN | 
MCACHE_CTL_L2C_WAROUND_EN);
+   MCACHE_CTL_DC_WAROUND_EN | 
MCACHE_CTL_L2C_WAROUND_EN | \
+   MCACHE_CTL_IC_ECCEN | MCACHE_CTL_DC_ECCEN | 
MCACHE_CTL_TLB_ECCEN);
 
if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
mcache_ctl_val |= MCACHE_CTL_IC_EN;
diff --git a/arch/riscv/include/asm/arch-andes/csr.h 
b/arch/riscv/include/asm/arch-andes/csr.h
index 3f3f05b348..028fd01c2f 100644
--- a/arch/riscv/include/asm/arch-andes/csr.h
+++ b/arch/riscv/include/asm/arch-andes/csr.h
@@ -18,11 +18,14 @@
 
 #define MCACHE_CTL_IC_EN   BIT(0)
 #define MCACHE_CTL_DC_EN   BIT(1)
+#define MCACHE_CTL_IC_ECCENBIT(3)
+#define MCACHE_CTL_DC_ECCENBIT(5)
 #define MCACHE_CTL_CCTL_SUEN   BIT(8)
 #define MCACHE_CTL_IC_PREFETCH_EN  BIT(9)
 #define MCACHE_CTL_DC_PREFETCH_EN  BIT(10)
 #define MCACHE_CTL_DC_WAROUND_EN   BIT(13)
 #define MCACHE_CTL_L2C_WAROUND_EN  BIT(15)
+#define MCACHE_CTL_TLB_ECCEN   BIT(18)
 #define MCACHE_CTL_DC_COHENBIT(19)
 #define MCACHE_CTL_DC_COHSTA   BIT(20)
 
-- 
2.34.1



[PATCH v2 3/6] andes: cpu: Enable memboost feature

2023-12-25 Thread Leo Yu-Chi Liang
Andes CPU has memboost feature including prefetch,
write-around and non-blocking load. Enable them by default.

Signed-off-by: Leo Yu-Chi Liang 
---
 arch/riscv/cpu/andesv5/cpu.c| 9 -
 arch/riscv/include/asm/arch-andes/csr.h | 6 ++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/cpu/andesv5/cpu.c b/arch/riscv/cpu/andesv5/cpu.c
index e764f6c5c0..a23b7948d9 100644
--- a/arch/riscv/cpu/andesv5/cpu.c
+++ b/arch/riscv/cpu/andesv5/cpu.c
@@ -31,8 +31,11 @@ void harts_early_init(void)
/* Enable I/D-cache in SPL */
if (CONFIG_IS_ENABLED(RISCV_MMODE)) {
unsigned long mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
+   unsigned long mmisc_ctl_val = csr_read(CSR_MMISC_CTL);
 
-   mcache_ctl_val |= MCACHE_CTL_CCTL_SUEN;
+   mcache_ctl_val |= (MCACHE_CTL_CCTL_SUEN | \
+   MCACHE_CTL_IC_PREFETCH_EN | 
MCACHE_CTL_DC_PREFETCH_EN | \
+   MCACHE_CTL_DC_WAROUND_EN | 
MCACHE_CTL_L2C_WAROUND_EN);
 
if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
mcache_ctl_val |= MCACHE_CTL_IC_EN;
@@ -52,5 +55,9 @@ void harts_early_init(void)
while (!(csr_read(CSR_MCACHE_CTL) & 
MCACHE_CTL_DC_COHSTA));
}
}
+
+   mmisc_ctl_val |= MMISC_CTL_NON_BLOCKING_EN;
+
+   csr_write(CSR_MMISC_CTL, mmisc_ctl_val);
}
 }
diff --git a/arch/riscv/include/asm/arch-andes/csr.h 
b/arch/riscv/include/asm/arch-andes/csr.h
index 12d5eb6f6c..3f3f05b348 100644
--- a/arch/riscv/include/asm/arch-andes/csr.h
+++ b/arch/riscv/include/asm/arch-andes/csr.h
@@ -19,9 +19,15 @@
 #define MCACHE_CTL_IC_EN   BIT(0)
 #define MCACHE_CTL_DC_EN   BIT(1)
 #define MCACHE_CTL_CCTL_SUEN   BIT(8)
+#define MCACHE_CTL_IC_PREFETCH_EN  BIT(9)
+#define MCACHE_CTL_DC_PREFETCH_EN  BIT(10)
+#define MCACHE_CTL_DC_WAROUND_EN   BIT(13)
+#define MCACHE_CTL_L2C_WAROUND_EN  BIT(15)
 #define MCACHE_CTL_DC_COHENBIT(19)
 #define MCACHE_CTL_DC_COHSTA   BIT(20)
 
+/* mmisc_ctl register */
+#define MMISC_CTL_NON_BLOCKING_EN  BIT(8)
 
 #define CCTL_L1D_WBINVAL_ALL 6
 
-- 
2.34.1



[PATCH v2 2/6] andes: ae350: Implement cache switch via Kconfig

2023-12-25 Thread Leo Yu-Chi Liang
Kconfig provides SYS_[I|D]CACHE_OFF config options to switch off caches.
Provide the corresponding implementation to the options.

Signed-off-by: Leo Yu-Chi Liang 
---
 arch/riscv/cpu/andesv5/cpu.c  | 25 -
 board/AndesTech/ae350/ae350.c |  3 ++-
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/arch/riscv/cpu/andesv5/cpu.c b/arch/riscv/cpu/andesv5/cpu.c
index 63bc24cdfc..e764f6c5c0 100644
--- a/arch/riscv/cpu/andesv5/cpu.c
+++ b/arch/riscv/cpu/andesv5/cpu.c
@@ -32,18 +32,25 @@ void harts_early_init(void)
if (CONFIG_IS_ENABLED(RISCV_MMODE)) {
unsigned long mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
 
-   mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_IC_EN |
-  MCACHE_CTL_DC_EN | MCACHE_CTL_CCTL_SUEN);
+   mcache_ctl_val |= MCACHE_CTL_CCTL_SUEN;
+
+   if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
+   mcache_ctl_val |= MCACHE_CTL_IC_EN;
+
+   if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
+   mcache_ctl_val |= (MCACHE_CTL_DC_EN | 
MCACHE_CTL_DC_COHEN);
 
csr_write(CSR_MCACHE_CTL, mcache_ctl_val);
 
-   /*
-* Check mcache_ctl.DC_COHEN, we assume this platform does
-* not support CM if the bit is hard-wired to 0.
-*/
-   if (csr_read(CSR_MCACHE_CTL) & MCACHE_CTL_DC_COHEN) {
-   /* Wait for DC_COHSTA bit to be set */
-   while (!(csr_read(CSR_MCACHE_CTL) & 
MCACHE_CTL_DC_COHSTA));
+   if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) {
+   /*
+* Check mcache_ctl.DC_COHEN, we assume this platform 
does
+* not support CM if the bit is hard-wired to 0.
+*/
+   if (csr_read(CSR_MCACHE_CTL) & MCACHE_CTL_DC_COHEN) {
+   /* Wait for DC_COHSTA bit to be set */
+   while (!(csr_read(CSR_MCACHE_CTL) & 
MCACHE_CTL_DC_COHSTA));
+   }
}
}
 }
diff --git a/board/AndesTech/ae350/ae350.c b/board/AndesTech/ae350/ae350.c
index 772c6bf1ee..bef9e3149e 100644
--- a/board/AndesTech/ae350/ae350.c
+++ b/board/AndesTech/ae350/ae350.c
@@ -102,7 +102,8 @@ void *board_fdt_blob_setup(int *err)
 void spl_board_init()
 {
/* enable v5l2 cache */
-   enable_caches();
+   if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
+   enable_caches();
 }
 #endif
 
-- 
2.34.1



[PATCH v2 1/6] andes: csr.h: Clean up CSR definition

2023-12-25 Thread Leo Yu-Chi Liang
Signed-off-by: Leo Yu-Chi Liang 
---
 arch/riscv/include/asm/arch-andes/csr.h | 20 
 arch/riscv/include/asm/csr.h|  1 +
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/arch/riscv/include/asm/arch-andes/csr.h 
b/arch/riscv/include/asm/arch-andes/csr.h
index 393d51c6dd..12d5eb6f6c 100644
--- a/arch/riscv/include/asm/arch-andes/csr.h
+++ b/arch/riscv/include/asm/arch-andes/csr.h
@@ -12,20 +12,16 @@
 
 #define CSR_MCACHE_CTL 0x7ca
 #define CSR_MMISC_CTL 0x7d0
-#define CSR_MARCHID 0xf12
 #define CSR_MCCTLCOMMAND 0x7cc
 
-#define MCACHE_CTL_IC_EN_OFFSET 0
-#define MCACHE_CTL_DC_EN_OFFSET 1
-#define MCACHE_CTL_CCTL_SUEN_OFFSET 8
-#define MCACHE_CTL_DC_COHEN_OFFSET 19
-#define MCACHE_CTL_DC_COHSTA_OFFSET 20
-
-#define MCACHE_CTL_IC_EN BIT(MCACHE_CTL_IC_EN_OFFSET)
-#define MCACHE_CTL_DC_EN BIT(MCACHE_CTL_DC_EN_OFFSET)
-#define MCACHE_CTL_CCTL_SUEN BIT(MCACHE_CTL_CCTL_SUEN_OFFSET)
-#define MCACHE_CTL_DC_COHEN BIT(MCACHE_CTL_DC_COHEN_OFFSET)
-#define MCACHE_CTL_DC_COHSTA BIT(MCACHE_CTL_DC_COHSTA_OFFSET)
+/* mcache_ctl register */
+
+#define MCACHE_CTL_IC_EN   BIT(0)
+#define MCACHE_CTL_DC_EN   BIT(1)
+#define MCACHE_CTL_CCTL_SUEN   BIT(8)
+#define MCACHE_CTL_DC_COHENBIT(19)
+#define MCACHE_CTL_DC_COHSTA   BIT(20)
+
 
 #define CCTL_L1D_WBINVAL_ALL 6
 
diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
index 1a15089cae..986f951c31 100644
--- a/arch/riscv/include/asm/csr.h
+++ b/arch/riscv/include/asm/csr.h
@@ -142,6 +142,7 @@
 #define CSR_CYCLEH 0xc80
 #define CSR_TIMEH  0xc81
 #define CSR_INSTRETH   0xc82
+#define CSR_MARCHID0xf12
 #define CSR_MHARTID0xf14
 
 #ifndef __ASSEMBLY__
-- 
2.34.1



[PATCH v1] reset: npcm: Add support for Nuvoton NPCM BMC family

2023-12-25 Thread Jim Liu
Add reset controller driver for Nuvoton BMCs.
The npcm reset driver not only supports reset each module reset
but setting initial value of reset Control Registers.

And The driver support each module reset.

Signed-off-by: Jim Liu 
---
 drivers/reset/Kconfig  |   7 ++
 drivers/reset/Makefile |   1 +
 drivers/reset/reset-npcm.c | 133 +
 3 files changed, 141 insertions(+)
 create mode 100644 drivers/reset/reset-npcm.c

diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index 73bbd30692..ccd4182682 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -114,6 +114,13 @@ config RESET_MESON
help
  Support for reset controller on Amlogic Meson SoC.
 
+config RESET_NPCM
+   bool "Reset controller driver for Nuvoton BMCs"
+   depends on DM_RESET && ARCH_NPCM
+   default y
+   help
+ Support for reset controller on Nuvotom BMCs.
+
 config RESET_SOCFPGA
bool "Reset controller driver for SoCFPGA"
depends on DM_RESET && ARCH_SOCFPGA
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index e2239a250a..8cc947fc34 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_RESET_AST2500) += reset-ast2500.o
 obj-$(CONFIG_RESET_AST2600) += reset-ast2600.o
 obj-$(CONFIG_RESET_ROCKCHIP) += reset-rockchip.o rst-rk3588.o
 obj-$(CONFIG_RESET_MESON) += reset-meson.o
+obj-$(CONFIG_RESET_NPCM) += reset-npcm.o
 obj-$(CONFIG_RESET_SOCFPGA) += reset-socfpga.o
 obj-$(CONFIG_RESET_MEDIATEK) += reset-mediatek.o
 obj-$(CONFIG_RESET_MTMIPS) += reset-mtmips.o
diff --git a/drivers/reset/reset-npcm.c b/drivers/reset/reset-npcm.c
new file mode 100644
index 00..d8d629b28e
--- /dev/null
+++ b/drivers/reset/reset-npcm.c
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2023 Nuvoton Technology Corp.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+struct npcm_reset_priv {
+   void __iomem *base;
+};
+
+static int npcm_reset_request(struct reset_ctl *rst)
+{
+   return 0;
+}
+
+static int npcm_reset_free(struct reset_ctl *rst)
+{
+   return 0;
+}
+
+static int npcm_reset_assert(struct reset_ctl *rst)
+{
+   struct npcm_reset_priv *priv = dev_get_priv(rst->dev);
+   u32 val;
+
+   debug("%s: id 0x%lx, data %ld\n", __func__, rst->id, rst->data);
+   val = readl(priv->base + rst->id);
+   val |= BIT(rst->data);
+   writel(val, priv->base + rst->id);
+
+   return 0;
+}
+
+static int npcm_reset_deassert(struct reset_ctl *rst)
+{
+   struct npcm_reset_priv *priv = dev_get_priv(rst->dev);
+   u32 val;
+
+   debug("%s: id 0x%lx, data %ld\n", __func__, rst->id, rst->data);
+   val = readl(priv->base + rst->id);
+   val &= ~BIT(rst->data);
+   writel(val, priv->base + rst->id);
+
+   return 0;
+}
+
+static int npcm_reset_xlate(struct reset_ctl *rst,
+   struct ofnode_phandle_args *args)
+{
+   if (args->args_count != 2) {
+   dev_err(rst->dev, "Invalid args_count: %d\n", args->args_count);
+   return -EINVAL;
+   }
+
+   /* Use id field as register offset and data field as reset bit 
positiion */
+   rst->id = args->args[0];
+   rst->data = args->args[1];
+
+   return 0;
+}
+
+static int npcm_reset_bind(struct udevice *dev)
+{
+   struct npcm_reset_priv *priv = dev_get_priv(dev);
+   u32 *rcr_values;
+   int num_fields;
+   u32 reg, val;
+   int ret, i;
+
+   priv->base = dev_remap_addr(dev);
+   if (!priv->base)
+   return -EINVAL;
+
+   /*
+* Set RCR initial value
+* The rcr-initial-values cell is 
+*/
+   num_fields = dev_read_size(dev, "rcr-initial-values");
+   if (num_fields < 2)
+   return 0;
+
+   num_fields /= sizeof(u32);
+   if (num_fields % 2)
+   return -EINVAL;
+
+   num_fields = num_fields / 2;
+   rcr_values = malloc(num_fields * 2 * sizeof(u32));
+   if (!rcr_values)
+   return -ENOMEM;
+
+   ret = dev_read_u32_array(dev, "rcr-initial-values", rcr_values,
+num_fields * 2);
+   if (ret < 0) {
+   free(rcr_values);
+   return -EINVAL;
+   }
+
+   for (i = 0; i < num_fields; i++) {
+   reg = rcr_values[2 * i];
+   val = rcr_values[2 * i + 1];
+   writel(val, priv->base + reg);
+   }
+   free(rcr_values);
+
+   return 0;
+}
+
+static const struct udevice_id npcm_reset_ids[] = {
+   { .compatible = "nuvoton,npcm845-reset" },
+   { .compatible = "nuvoton,npcm750-reset" },
+   { }
+};
+
+struct reset_ops npcm_reset_ops = {
+   .request = npcm_reset_request,
+   .rfree = npcm_reset_free,
+   .rst_assert = npcm_reset_assert,
+   .rst_deassert = npcm_reset_deassert,
+   .of_xlate = npcm_reset_xlate,
+};
+
+U_BOOT_DRIVER(npcm_reset) = {

[PATCH v1] spi: npcm_pspi: Fix the wrong clock divider calculation

2023-12-25 Thread Jim Liu
Fix the wrong clock divider calculation.

Signed-off-by: Jim Liu 
---
 drivers/spi/npcm_pspi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/npcm_pspi.c b/drivers/spi/npcm_pspi.c
index 37bab70967..eb14185273 100644
--- a/drivers/spi/npcm_pspi.c
+++ b/drivers/spi/npcm_pspi.c
@@ -144,7 +144,7 @@ static int npcm_pspi_set_speed(struct udevice *bus, uint 
speed)
if (speed > priv->max_hz)
speed = priv->max_hz;
 
-   divisor = DIV_ROUND_CLOSEST(apb_clock, (2 * speed) - 1);
+   divisor = DIV_ROUND_CLOSEST(apb_clock, (2 * speed)) - 1;
if (divisor > MAX_DIV)
divisor = MAX_DIV;
 
-- 
2.25.1



Re: [PATCH 1/2] efi_loader: auto-generate boot option for each blkio device

2023-12-25 Thread Masahisa Kojima
On Mon, 25 Dec 2023 at 21:22, Heinrich Schuchardt  wrote:
>
> On 12/20/23 09:41, Masahisa Kojima wrote:
> > Current efibootmgr auto-generates the boot option for all
> > disks and partitions installing EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
> > while EDK II reference implementation auto-generates the boot option
> > for all devices installing  EFI_BLOCK_IO_PROTOCOL with
> > eliminating logical partitions.
> >
> > This commit modifies the efibootmgr to get aligned to EDK II.
> >
> > Signed-off-by: Masahisa Kojima 
> > ---
> >   lib/efi_loader/efi_bootmgr.c | 94 +++-
> >   1 file changed, 71 insertions(+), 23 deletions(-)
> >
> > diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
> > index 56d97f2382..636f01e2eb 100644
> > --- a/lib/efi_loader/efi_bootmgr.c
> > +++ b/lib/efi_loader/efi_bootmgr.c
> > @@ -560,6 +560,50 @@ err:
> >   return ret;
> >   }
> >
> > +/**
> > + * try_load_from_media() - load file from media
> > + *
> > + * @fp:  file path
>
> This does not match the parameter name of the function leading to a
> 'make htmldocs' build error.

Sorry, I will fix it.

>
> > + * @handle:  pointer to handle for newly installed image
> > + *
> > + * If @fp contains a file name, load the file.
> > + * If @fp does not have a file name, search the architecture-specific
>
> ditto

OK.

Thanks,
Masahisa Kojima


>
> Best regards
>
> Heinrich
>
> > + * default file and load it.
> > + * TODO: If the FilePathList[0] device does not support
> > + * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL but supports EFI_BLOCK_IO_PROTOCOL,
> > + * call EFI_BOOT_SERVICES.ConnectController()
> > + * TODO: FilePathList[0] device supports EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
> > + * not based on EFI_BLOCK_IO_PROTOCOL
> > + *
> > + * Return:   status code
> > + */
> > +static efi_status_t try_load_from_media(struct efi_device_path *file_path,
> > + efi_handle_t *handle)
> > +{
> > + efi_handle_t h;
> > + efi_status_t ret = EFI_SUCCESS;
> > + struct efi_device_path *rem, *dp = NULL;
> > + struct efi_device_path *final_dp = file_path;
> > +
> > + h = efi_dp_find_obj(file_path, _block_io_guid, );
> > + if (h) {
> > + if (rem->type == DEVICE_PATH_TYPE_END) {
> > + /* no file name present, try default file */
> > + ret = check_disk_has_default_file(h->dev, );
> > + if (ret != EFI_SUCCESS)
> > + return ret;
> > +
> > + final_dp = dp;
> > + }
> > + }
> > +
> > + ret = EFI_CALL(efi_load_image(true, efi_root, final_dp, NULL, 0, 
> > handle));
> > +
> > + efi_free_pool(dp);
> > +
> > + return ret;
> > +}
> > +
> >   /**
> >* try_load_entry() - try to load image for boot option
> >*
> > @@ -594,7 +638,6 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
> > *handle,
> >   }
> >
> >   if (lo.attributes & LOAD_OPTION_ACTIVE) {
> > - struct efi_device_path *file_path;
> >   u32 attributes;
> >
> >   log_debug("trying to load \"%ls\" from %pD\n", lo.label,
> > @@ -611,10 +654,7 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
> > *handle,
> >   else
> >   ret = EFI_LOAD_ERROR;
> >   } else {
> > - file_path = expand_media_path(lo.file_path);
> > - ret = EFI_CALL(efi_load_image(true, efi_root, 
> > file_path,
> > -   NULL, 0, handle));
> > - efi_free_pool(file_path);
> > + ret = try_load_from_media(lo.file_path, handle);
> >   }
> >   if (ret != EFI_SUCCESS) {
> >   log_warning("Loading %ls '%ls' failed\n",
> > @@ -748,19 +788,19 @@ error:
> >* efi_bootmgr_enumerate_boot_option() - enumerate the possible bootable 
> > media
> >*
> >* @opt:pointer to the media boot option structure
> > - * @volume_handles:  pointer to the efi handles
> > + * @handles: pointer to the efi handles
> >* @count:  number of efi handle
> >* Return:  status code
> >*/
> >   static efi_status_t efi_bootmgr_enumerate_boot_option(struct 
> > eficonfig_media_boot_option *opt,
> > -   efi_handle_t 
> > *volume_handles,
> > -   efi_status_t count)
> > +   efi_handle_t *handles,
> > +   efi_uintn_t *count)
> >   {
> > - u32 i;
> > + u32 i, num = 0;
> >   struct efi_handler *handler;
> >   efi_status_t ret = EFI_SUCCESS;
> >
> > - for (i = 0; i < count; i++) {
> > + for (i = 0; i < *count; i++) {
> >   u16 *p;
> >   u16 

Re: [PATCH 3/3] efi_loader: create common function to free struct efi_disk_obj

2023-12-25 Thread Masahisa Kojima
On Mon, 25 Dec 2023 at 19:31, Heinrich Schuchardt  wrote:
>
> On 12/25/23 05:43, Masahisa Kojima wrote:
> > Current error handling of creating raw disk/partition has
> > following issues.
> >   - duplicate free for efi handle, efi handle is already freed
> > in efi_delete_handle()
>
> I cannot see where this patch reduces the number of efi_delete_handle()
> invocations.

Duplicate free() calls occur here in the original code:
> > - efi_delete_handle(>header);
> > - free(diskobj->volume);
> > - free(diskobj);

efi_delete_handle(>header) will free the handle(=
>header, = diskobj).
So calling  free(diskobj) should be avoided.

>
> >   - missing free for struct efi_device_path and
> > struct efi_simple_file_system_protocol in some error paths
> >
> > To address those issue, this commit creates the common function
> > to free the struct efi_disk_obj resources and calls it in case
> > of error.
> >
> > Signed-off-by: Masahisa Kojima 
> > ---
> >   lib/efi_loader/efi_disk.c | 23 ---
> >   1 file changed, 16 insertions(+), 7 deletions(-)
> >
> > diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
> > index 415d8601ba..d2ac2fab9b 100644
> > --- a/lib/efi_loader/efi_disk.c
> > +++ b/lib/efi_loader/efi_disk.c
> > @@ -372,6 +372,19 @@ static int efi_fs_exists(struct blk_desc *desc, int 
> > part)
> >   return 1;
> >   }
> >
> > +static void efi_disk_free_diskobj(struct efi_disk_obj *diskobj)
> > +{
> > + struct efi_device_path *dp = NULL;
>
> This NULL value is never used.

Yes, initialize it with diskobj->dp.

>
> > + struct efi_simple_file_system_protocol *volume = NULL;
>
> ditto

OK.

>
> > +
> > + dp = diskobj->dp;
> > + volume = diskobj->volume;
> > +
> > + efi_delete_handle(>header);
>
> efi_delete_handle() may fail.

I assume this function efi_disk_free_diskobj() is called only from
the error path.(I should note as a comment)
I think it is better to ignore errors in efi_delete_handle() and proceed to
free the other resources.

>
> > + efi_free_pool(dp);
>
> The device path may only be freed if it has been uninstalled from the
> handle.

Sorry, I'm not sure if I understand this comment correctly, but device_path
is uninstalled in efi_delete_handle().

>
> > + free(volume);
>
> The simple file protocol interface may only be freed if it has been
> uninstalled from the handle.

Same as above, all protocols on the handle are uninstalled in
efi_delete_handle().

>
> > +}
> > +
> >   /**
> >* efi_disk_add_dev() - create a handle for a partition or disk
> >*
> > @@ -529,9 +542,7 @@ static efi_status_t efi_disk_add_dev(
> >   }
> >   return EFI_SUCCESS;
> >   error:
> > - efi_delete_handle(>header);
> > - free(diskobj->volume);
> > - free(diskobj);
> > + efi_disk_free_diskobj(diskobj);
> >   return ret;
> >   }
> >
> > @@ -570,8 +581,7 @@ static int efi_disk_create_raw(struct udevice *dev, 
> > efi_handle_t agent_handle)
> >   return ret;
> >   }
> >   if (efi_link_dev(>header, dev)) {
> > - efi_free_pool(disk->dp);
> > - efi_delete_handle(>header);
> > + efi_disk_free_diskobj(disk);
> >
> >   return -EINVAL;
> >   }
> > @@ -625,8 +635,7 @@ static int efi_disk_create_part(struct udevice *dev, 
> > efi_handle_t agent_handle)
> >   return -1;
> >   }
> >   if (efi_link_dev(>header, dev)) {
> > - efi_free_pool(disk->dp);
> > - efi_delete_handle(>header);
> > + efi_disk_free_diskobj(disk);
>
> In efi_disk_add_dev we have opened a protocol interface. We must close
> it before removing the partition handle otherwise the disk handle can
> never be removed.
>
> To do this all properly we will need to re-implement this code using
> proper EFI drivers which expose a driver binding protocol. Please, add a
> TODO: comment here that closing the protocol is missing.

OK, I will check on this.

Thanks,
Masahisa Kojima


>
> Best regards
>
> Heinrich
>
> >
> >   return -1;
> >   }
>


Re: [PATCH 2/3] efi_loader: avoid pointer access after calling efi_delete_handle

2023-12-25 Thread Heinrich Schuchardt



Am 26. Dezember 2023 02:13:08 MEZ schrieb Masahisa Kojima 
:
>Hi Heinrich,
>
>On Mon, 25 Dec 2023 at 19:05, Heinrich Schuchardt  wrote:
>>
>> On 12/25/23 05:43, Masahisa Kojima wrote:
>> > efi_delete_handle() calls efi_purge_handle(), then it finally
>> > frees the efi handle.
>> > Both diskobj and handle variables in efi_disk_remove() have
>> > the same pointer, we can not access diskobj->dp after calling
>> > efi_delete_handle().
>> >
>> > This commit saves the struct efi_device_path pointer before
>> > calling efi_delete_handle(). This commit also fixes the
>> > missing free for volume member in struct efi_disk_obj.
>> >
>> > Signed-off-by: Masahisa Kojima 
>> > ---
>> >   lib/efi_loader/efi_disk.c | 12 +---
>> >   1 file changed, 9 insertions(+), 3 deletions(-)
>> >
>> > diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
>> > index a2f8b531a3..415d8601ba 100644
>> > --- a/lib/efi_loader/efi_disk.c
>> > +++ b/lib/efi_loader/efi_disk.c
>> > @@ -701,7 +701,9 @@ int efi_disk_remove(void *ctx, struct event *event)
>> >   struct udevice *dev = event->data.dm.dev;
>> >   efi_handle_t handle;
>> >   struct blk_desc *desc;
>> > + struct efi_device_path *dp = NULL;
>> >   struct efi_disk_obj *diskobj = NULL;
>> > + struct efi_simple_file_system_protocol *volume = NULL;
>> >   efi_status_t ret;
>> >
>> >   if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)))
>> > @@ -722,14 +724,18 @@ int efi_disk_remove(void *ctx, struct event *event)
>> >   return 0;
>> >   }
>> >
>> > + if (diskobj) {
>>
>>
>>diskobj = container_of(handle, struct efi_disk_obj, header);
>>
>> can be replaced by
>>
>>diskobj = handle
>>
>> We should check the handle immediately after dev_tag_get_ptr() and
>> return 0 if the handle == NULL.
>
>OK, I will try to improve the efi_disk_remove() function.
>
>>
>> > + dp = diskobj->dp;
>> > + volume = diskobj->volume;
>> > + }
>> > +
>> >   ret = efi_delete_handle(handle);
>>
>> We must not delete the handle in case of UCLASS_EFI_LOADER.
>>
>> Instead of calling efi_delete_handle we should uninstall all protocols
>> that we have installed. If no protocol is left the handle will go away.
>>
>> To make the protocols to delete tractable they should be opened with
>> BY_DRIVER.
>
>efi_delete_handle() calls efi_remove_all_protocols(), and frees the efi handle
>if no protocol is left on the handle.
>So I think efi_delete_handle() does all the required processes mentioned above.

Given an EFI application like iPXE that provides a handle with the block IO 
protocol implemented by the application: Why should U-Boot remove the block IO 
protocol or the device path protocol when the application calls 
DisconnectController()?

Best regards

Heinrich

>
>>
>> When a partition is removed we must close the protocol interfaces opened
>> with EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER (cf. efi_disk_add_dev()).
>
>OK, I will fix this.
>
>Thanks,
>Masahisa Kojima
>
>>
>> Best regards
>>
>> Heinrich
>>
>> >   /* Do not delete DM device if there are still EFI drivers attached. 
>> > */
>> >   if (ret != EFI_SUCCESS)
>> >   return -1;
>> >
>> > - if (diskobj)
>> > - efi_free_pool(diskobj->dp);
>> > -
>> > + efi_free_pool(dp);
>> > + free(volume);
>> >   dev_tag_del(dev, DM_TAG_EFI);
>> >
>> >   return 0;
>>


Re: [PATCH 2/3] efi_loader: avoid pointer access after calling efi_delete_handle

2023-12-25 Thread Masahisa Kojima
Hi Heinrich,

On Mon, 25 Dec 2023 at 19:05, Heinrich Schuchardt  wrote:
>
> On 12/25/23 05:43, Masahisa Kojima wrote:
> > efi_delete_handle() calls efi_purge_handle(), then it finally
> > frees the efi handle.
> > Both diskobj and handle variables in efi_disk_remove() have
> > the same pointer, we can not access diskobj->dp after calling
> > efi_delete_handle().
> >
> > This commit saves the struct efi_device_path pointer before
> > calling efi_delete_handle(). This commit also fixes the
> > missing free for volume member in struct efi_disk_obj.
> >
> > Signed-off-by: Masahisa Kojima 
> > ---
> >   lib/efi_loader/efi_disk.c | 12 +---
> >   1 file changed, 9 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
> > index a2f8b531a3..415d8601ba 100644
> > --- a/lib/efi_loader/efi_disk.c
> > +++ b/lib/efi_loader/efi_disk.c
> > @@ -701,7 +701,9 @@ int efi_disk_remove(void *ctx, struct event *event)
> >   struct udevice *dev = event->data.dm.dev;
> >   efi_handle_t handle;
> >   struct blk_desc *desc;
> > + struct efi_device_path *dp = NULL;
> >   struct efi_disk_obj *diskobj = NULL;
> > + struct efi_simple_file_system_protocol *volume = NULL;
> >   efi_status_t ret;
> >
> >   if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)))
> > @@ -722,14 +724,18 @@ int efi_disk_remove(void *ctx, struct event *event)
> >   return 0;
> >   }
> >
> > + if (diskobj) {
>
>
>diskobj = container_of(handle, struct efi_disk_obj, header);
>
> can be replaced by
>
>diskobj = handle
>
> We should check the handle immediately after dev_tag_get_ptr() and
> return 0 if the handle == NULL.

OK, I will try to improve the efi_disk_remove() function.

>
> > + dp = diskobj->dp;
> > + volume = diskobj->volume;
> > + }
> > +
> >   ret = efi_delete_handle(handle);
>
> We must not delete the handle in case of UCLASS_EFI_LOADER.
>
> Instead of calling efi_delete_handle we should uninstall all protocols
> that we have installed. If no protocol is left the handle will go away.
>
> To make the protocols to delete tractable they should be opened with
> BY_DRIVER.

efi_delete_handle() calls efi_remove_all_protocols(), and frees the efi handle
if no protocol is left on the handle.
So I think efi_delete_handle() does all the required processes mentioned above.

>
> When a partition is removed we must close the protocol interfaces opened
> with EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER (cf. efi_disk_add_dev()).

OK, I will fix this.

Thanks,
Masahisa Kojima

>
> Best regards
>
> Heinrich
>
> >   /* Do not delete DM device if there are still EFI drivers attached. */
> >   if (ret != EFI_SUCCESS)
> >   return -1;
> >
> > - if (diskobj)
> > - efi_free_pool(diskobj->dp);
> > -
> > + efi_free_pool(dp);
> > + free(volume);
> >   dev_tag_del(dev, DM_TAG_EFI);
> >
> >   return 0;
>


Re: [PATHv2 8/9] omap3: use device specific naming for mem_init

2023-12-25 Thread Sean Anderson

On 12/25/23 10:39, Maxim Uvarov wrote:

Use device specific naming for functions so as to not overlap
with common function names.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
---
  arch/arm/include/asm/arch-omap3/mem.h | 2 +-
  arch/arm/mach-omap2/omap3/board.c | 2 +-
  arch/arm/mach-omap2/omap3/emif4.c | 4 ++--
  arch/arm/mach-omap2/omap3/sdrc.c  | 6 +++---
  4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/arm/include/asm/arch-omap3/mem.h 
b/arch/arm/include/asm/arch-omap3/mem.h
index 569779c55e..fce3568eca 100644
--- a/arch/arm/include/asm/arch-omap3/mem.h
+++ b/arch/arm/include/asm/arch-omap3/mem.h
@@ -475,7 +475,7 @@ enum {
  #ifndef __ASSEMBLY__
  
  /* Function prototypes */

-void mem_init(void);
+void omap3_mem_init(void);
  
  u32 is_mem_sdr(void);

  u32 mem_ok(u32 cs);
diff --git a/arch/arm/mach-omap2/omap3/board.c 
b/arch/arm/mach-omap2/omap3/board.c
index 8b70251457..c76a95dd5d 100644
--- a/arch/arm/mach-omap2/omap3/board.c
+++ b/arch/arm/mach-omap2/omap3/board.c
@@ -216,7 +216,7 @@ void s_init(void)
  void board_init_f(ulong dummy)
  {
early_system_init();
-   mem_init();
+   omap3_mem_init();
/*
* Save the boot parameters passed from romcode.
* We cannot delay the saving further than this,
diff --git a/arch/arm/mach-omap2/omap3/emif4.c 
b/arch/arm/mach-omap2/omap3/emif4.c
index 7e5a281922..4fbfb387ab 100644
--- a/arch/arm/mach-omap2/omap3/emif4.c
+++ b/arch/arm/mach-omap2/omap3/emif4.c
@@ -159,10 +159,10 @@ int dram_init_banksize(void)
  }
  
  /*

- * mem_init() -
+ * omap3_mem_init() -
   *  - Initialize memory subsystem
   */
-void mem_init(void)
+void omap3_mem_init(void)
  {
do_emif4_init();
  }
diff --git a/arch/arm/mach-omap2/omap3/sdrc.c b/arch/arm/mach-omap2/omap3/sdrc.c
index 5d43e7c9cf..f2a0769b9d 100644
--- a/arch/arm/mach-omap2/omap3/sdrc.c
+++ b/arch/arm/mach-omap2/omap3/sdrc.c
@@ -4,7 +4,7 @@
   *
   * This file has been created after exctracting and consolidating
   * the SDRC related content from mem.c and board.c, also created
- * generic init function (mem_init).
+ * generic init function (omap3_mem_init).
   *
   * Copyright (C) 2004-2010
   * Texas Instruments Incorporated - https://www.ti.com/
@@ -232,11 +232,11 @@ int dram_init_banksize(void)
  }
  
  /*

- * mem_init -
+ * map3_mem_init -


nit: omap3


   *  - Init the sdrc chip,
   *  - Selects CS0 and CS1,
   */
-void mem_init(void)
+void omap3_mem_init(void)
  {
/* only init up first bank here */
do_sdrc_init(CS0, EARLY_INIT);




Re: [PATHv2 2/9] net: sandbox: fix NULL pointer derefences

2023-12-25 Thread Sean Anderson

On 12/25/23 10:39, Maxim Uvarov wrote:

Add additional checks for NULL pointers.

Signed-off-by: Maxim Uvarov 
---
  drivers/net/sandbox.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
index 13022addb6..d91935e032 100644
--- a/drivers/net/sandbox.c
+++ b/drivers/net/sandbox.c
@@ -65,6 +65,9 @@ int sandbox_eth_arp_req_to_reply(struct udevice *dev, void 
*packet,
struct ethernet_hdr *eth_recv;
struct arp_hdr *arp_recv;
  
+	if (!priv)

+   return -EAGAIN;
+


When can priv be NULL?

--Sean


if (ntohs(eth->et_protlen) != PROT_ARP)
return -EAGAIN;
  




Re: [PATCH 0/2] fix auto-generated boot options

2023-12-25 Thread Heinrich Schuchardt

On 12/20/23 09:41, Masahisa Kojima wrote:

This series aims to get aligned to the EDK II reference
implementation for auto-generated boot options, and tries
to address the following issue.
https://source.denx.de/u-boot/custodians/u-boot-efi/-/issues/13

This series is based on the efi-next-20231217 tag.

Masahisa Kojima (2):
   efi_loader: auto-generate boot option for each blkio device
   efi_loader: auto-generate removable media boot option first

  lib/efi_loader/efi_bootmgr.c | 123 +++
  1 file changed, 96 insertions(+), 27 deletions(-)



Hello Masahisa,

please, have a look at the test failures in
https://source.denx.de/u-boot/custodians/u-boot-efi/-/pipelines/19089

Best regards

Heinrich


[PATHv2 9/9] Makefile: add dtbs to clean

2023-12-25 Thread Maxim Uvarov
CI test checks that generated dtb has to be cleaned up.

Signed-off-by: Maxim Uvarov 
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 220411a293..ab603191ad 100644
--- a/Makefile
+++ b/Makefile
@@ -2165,7 +2165,8 @@ CLEAN_FILES += include/autoconf.mk* include/bmp_logo.h 
include/bmp_logo_data.h \
   mkimage-out.spl.mkimage mkimage.spl.mkimage imx-boot.map \
   itb.fit.fit itb.fit.itb itb.map spl.map mkimage-out.rom.mkimage \
   mkimage.rom.mkimage mkimage-in-simple-bin* rom.map simple-bin* \
-  idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb
+  idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb \
+  ./*/*.dtb *.dtb
 
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config include/generated spl tpl vpl \
-- 
2.30.2



[PATHv2 8/9] omap3: use device specific naming for mem_init

2023-12-25 Thread Maxim Uvarov
Use device specific naming for functions so as to not overlap
with common function names.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
---
 arch/arm/include/asm/arch-omap3/mem.h | 2 +-
 arch/arm/mach-omap2/omap3/board.c | 2 +-
 arch/arm/mach-omap2/omap3/emif4.c | 4 ++--
 arch/arm/mach-omap2/omap3/sdrc.c  | 6 +++---
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/arm/include/asm/arch-omap3/mem.h 
b/arch/arm/include/asm/arch-omap3/mem.h
index 569779c55e..fce3568eca 100644
--- a/arch/arm/include/asm/arch-omap3/mem.h
+++ b/arch/arm/include/asm/arch-omap3/mem.h
@@ -475,7 +475,7 @@ enum {
 #ifndef __ASSEMBLY__
 
 /* Function prototypes */
-void mem_init(void);
+void omap3_mem_init(void);
 
 u32 is_mem_sdr(void);
 u32 mem_ok(u32 cs);
diff --git a/arch/arm/mach-omap2/omap3/board.c 
b/arch/arm/mach-omap2/omap3/board.c
index 8b70251457..c76a95dd5d 100644
--- a/arch/arm/mach-omap2/omap3/board.c
+++ b/arch/arm/mach-omap2/omap3/board.c
@@ -216,7 +216,7 @@ void s_init(void)
 void board_init_f(ulong dummy)
 {
early_system_init();
-   mem_init();
+   omap3_mem_init();
/*
* Save the boot parameters passed from romcode.
* We cannot delay the saving further than this,
diff --git a/arch/arm/mach-omap2/omap3/emif4.c 
b/arch/arm/mach-omap2/omap3/emif4.c
index 7e5a281922..4fbfb387ab 100644
--- a/arch/arm/mach-omap2/omap3/emif4.c
+++ b/arch/arm/mach-omap2/omap3/emif4.c
@@ -159,10 +159,10 @@ int dram_init_banksize(void)
 }
 
 /*
- * mem_init() -
+ * omap3_mem_init() -
  *  - Initialize memory subsystem
  */
-void mem_init(void)
+void omap3_mem_init(void)
 {
do_emif4_init();
 }
diff --git a/arch/arm/mach-omap2/omap3/sdrc.c b/arch/arm/mach-omap2/omap3/sdrc.c
index 5d43e7c9cf..f2a0769b9d 100644
--- a/arch/arm/mach-omap2/omap3/sdrc.c
+++ b/arch/arm/mach-omap2/omap3/sdrc.c
@@ -4,7 +4,7 @@
  *
  * This file has been created after exctracting and consolidating
  * the SDRC related content from mem.c and board.c, also created
- * generic init function (mem_init).
+ * generic init function (omap3_mem_init).
  *
  * Copyright (C) 2004-2010
  * Texas Instruments Incorporated - https://www.ti.com/
@@ -232,11 +232,11 @@ int dram_init_banksize(void)
 }
 
 /*
- * mem_init -
+ * map3_mem_init -
  *  - Init the sdrc chip,
  *  - Selects CS0 and CS1,
  */
-void mem_init(void)
+void omap3_mem_init(void)
 {
/* only init up first bank here */
do_sdrc_init(CS0, EARLY_INIT);
-- 
2.30.2



[PATHv2 7/9] bcm_ns3: use device specific naming for variables

2023-12-25 Thread Maxim Uvarov
Use device specific naming for variables so as to not overlap
with common function names.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
Reviewed-by: Peter Robinson 
---
 include/configs/bcm_ns3.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/configs/bcm_ns3.h b/include/configs/bcm_ns3.h
index 47de4bc201..7c6e0725a6 100644
--- a/include/configs/bcm_ns3.h
+++ b/include/configs/bcm_ns3.h
@@ -45,11 +45,11 @@
 #define PCIE_ARGS "pcie_args=pci=pcie_bus_safe pcie_ports=native 
vfio_pci.disable_idle_d3=1\0"
 
 #ifdef CONFIG_BCM_SF2_ETH
-#define ETH_ADDR "ethaddr=00:0A:F7:95:65:A4\0"
+#define BCM_ETH_ADDR "ethaddr=00:0A:F7:95:65:A4\0"
 #define NET_ARGS "bgmac_platform.ethaddr=${ethaddr} " \
"ip=${ipaddr}::${gatewayip}:${netmask}::${ethif}:off"
 #else
-#define ETH_ADDR
+#define BMC_ETH_ADDR
 #define NET_ARGS
 #endif
 
@@ -749,7 +749,7 @@
OS_LOG_LEVEL \
EXTRA_ARGS \
PCIE_ARGS \
-   ETH_ADDR \
+   BMC_ETH_ADDR \
RESERVED_MEM \
SETBOOTARGS \
UPDATEME_FLASH_PARAMS \
-- 
2.30.2



[PATHv2 6/9] mach-socfpga: do not overlap defines with lwip

2023-12-25 Thread Maxim Uvarov
Fix compilation issue with overlapping lwip and march defines.

Signed-off-by: Maxim Uvarov 
---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 6 --
 arch/arm/mach-socfpga/wrap_handoff_soc64.c | 9 +
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h 
b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
index 902fc6bfb5..9b85e5865b 100644
--- a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
+++ b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
@@ -78,12 +78,6 @@
 
 #ifndef __ASSEMBLY__
 #include 
-enum endianness {
-   LITTLE_ENDIAN = 0,
-   BIG_ENDIAN,
-   UNKNOWN_ENDIANNESS
-};
-
 int socfpga_get_handoff_size(void *handoff_address);
 int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len);
 #endif
diff --git a/arch/arm/mach-socfpga/wrap_handoff_soc64.c 
b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
index e7cb5ea89c..df0701ec85 100644
--- a/arch/arm/mach-socfpga/wrap_handoff_soc64.c
+++ b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
@@ -10,6 +10,15 @@
 #include 
 #include "log.h"
 
+#ifndef __ASSEMBLY__
+#include 
+enum endianness {
+   LITTLE_ENDIAN = 0,
+   BIG_ENDIAN,
+   UNKNOWN_ENDIANNESS
+};
+#endif
+
 static enum endianness check_endianness(u32 handoff)
 {
switch (handoff) {
-- 
2.30.2



[PATHv2 5/9] driver/net/rtl8139: remove debug print

2023-12-25 Thread Maxim Uvarov
debug print delays reset of the driver. Finally I see
bunch of "rx error " errors in the screen. CI can
not handle many prints. While network works fine there

Reproduced with:
make CROSS_COMPILE=sh2-linux- r2dplus_defconfig all
qemu-system-sh4 -M r2d -nographic -serial null \
-serial mon:stdio -net user,tftp=`pwd` \
-net nic,model=rtl8139 -kernel ./u-boot.bin

Signed-off-by: Maxim Uvarov 
---
 drivers/net/rtl8139.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/rtl8139.c b/drivers/net/rtl8139.c
index 106bc1c7ae..d8f24ec81a 100644
--- a/drivers/net/rtl8139.c
+++ b/drivers/net/rtl8139.c
@@ -453,7 +453,7 @@ static int rtl8139_recv_common(struct rtl8139_priv *priv, 
unsigned char *rxdata,
  RTL_STS_RXBADALIGN)) ||
(rx_size < ETH_ZLEN) ||
(rx_size > ETH_FRAME_LEN + 4)) {
-   printf("rx error %hX\n", rx_status);
+   debug("rx error %hX\n", rx_status);
/* this clears all interrupts still pending */
rtl8139_reset(priv);
return 0;
-- 
2.30.2



[PATHv2 4/9] sandbox: eth-raw-os: successful return code is 0

2023-12-25 Thread Maxim Uvarov
all network drivers return 0 on the successful
transmission.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Simon Glass 
---
 arch/sandbox/cpu/eth-raw-os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c
index e59b96be5f..92c35aed95 100644
--- a/arch/sandbox/cpu/eth-raw-os.c
+++ b/arch/sandbox/cpu/eth-raw-os.c
@@ -256,7 +256,7 @@ int sandbox_eth_raw_os_send(void *packet, int length,
   strerror(errno));
return -errno;
}
-   return retval;
+   return 0;
 }
 
 int sandbox_eth_raw_os_recv(void *packet, int *length,
-- 
2.30.2



[PATHv2 3/9] net/smc911x: fix return from smc911x_send

2023-12-25 Thread Maxim Uvarov
return value of smc911x_send is ignored, but on sucesseful
send we need return 0 and or error -ETIMEOUT, not opposite.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
---
 drivers/net/smc911x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 5c5ad8b84a..616b7ce174 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -403,7 +403,7 @@ static int smc911x_send(struct udevice *dev, void *packet, 
int length)
 
ret = smc911x_send_common(priv, packet, length);
 
-   return ret ? 0 : -ETIMEDOUT;
+   return ret ? -ETIMEDOUT : 0;
 }
 
 static int smc911x_recv(struct udevice *dev, int flags, uchar **packetp)
-- 
2.30.2



[PATHv2 2/9] net: sandbox: fix NULL pointer derefences

2023-12-25 Thread Maxim Uvarov
Add additional checks for NULL pointers.

Signed-off-by: Maxim Uvarov 
---
 drivers/net/sandbox.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
index 13022addb6..d91935e032 100644
--- a/drivers/net/sandbox.c
+++ b/drivers/net/sandbox.c
@@ -65,6 +65,9 @@ int sandbox_eth_arp_req_to_reply(struct udevice *dev, void 
*packet,
struct ethernet_hdr *eth_recv;
struct arp_hdr *arp_recv;
 
+   if (!priv)
+   return -EAGAIN;
+
if (ntohs(eth->et_protlen) != PROT_ARP)
return -EAGAIN;
 
-- 
2.30.2



[PATHv2 1/9] test_net: print out net list

2023-12-25 Thread Maxim Uvarov
Printing net list is useful in CI log files.

Signed-off-by: Maxim Uvarov 
---
 test/py/tests/test_net.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
index b2241ae6a4..cd5b791a6a 100644
--- a/test/py/tests/test_net.py
+++ b/test/py/tests/test_net.py
@@ -96,6 +96,8 @@ def test_net_pre_commands(u_boot_console):
 if init_pci:
 u_boot_console.run_command('pci enum')
 
+u_boot_console.run_command('net list')
+
 @pytest.mark.buildconfigspec('cmd_dhcp')
 def test_net_dhcp(u_boot_console):
 """Test the dhcp command.
-- 
2.30.2



[PATHv2 0/9] net fixes prior lwip

2023-12-25 Thread Maxim Uvarov
Add small net fixes prior lwip patches.

v2: - rebase on the top of master tree with descriptions fixes
  suggested in review comments.

Maxim Uvarov (9):
  test_net: print out net list
  net: sandbox: fix NULL pointer derefences
  net/smc911x: fix return from smc911x_send
  sandbox: eth-raw-os: successful return code is 0
  driver/net/rtl8139: remove debug print
  mach-socfpga: do not overlap defines with lwip
  bcm_ns3: use device specific naming for variables
  omap3: use device specific naming for mem_init
  Makefile: add dtbs to clean

 Makefile   | 3 ++-
 arch/arm/include/asm/arch-omap3/mem.h  | 2 +-
 arch/arm/mach-omap2/omap3/board.c  | 2 +-
 arch/arm/mach-omap2/omap3/emif4.c  | 4 ++--
 arch/arm/mach-omap2/omap3/sdrc.c   | 6 +++---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 6 --
 arch/arm/mach-socfpga/wrap_handoff_soc64.c | 9 +
 arch/sandbox/cpu/eth-raw-os.c  | 2 +-
 drivers/net/rtl8139.c  | 2 +-
 drivers/net/sandbox.c  | 3 +++
 drivers/net/smc911x.c  | 2 +-
 include/configs/bcm_ns3.h  | 6 +++---
 test/py/tests/test_net.py  | 2 ++
 13 files changed, 29 insertions(+), 20 deletions(-)

-- 
2.30.2



Re: [PATCH RFC] dt-bindings: nvmem: u-boot, env: add any-name MAC cells compatible

2023-12-25 Thread Krzysztof Kozlowski
On 18/12/2023 23:02, Rafał Miłecki wrote:
> On 14.12.2023 22:27, Simon Glass wrote:
>> On Thu, 14 Dec 2023 at 08:36, Rafał Miłecki  wrote:
>>>
>>> From: Rafał Miłecki 
>>>
>>> So far we had a property for "ethaddr" NVMEM cell containing base
>>> Ethernet MAC address. The problem is vendors often pick non-standard
>>> names for storing MAC(s) (other than "ethaddr"). A few names were
>>> noticed over years:
>>> 1. "wanaddr" (Edimax, ELECOM, EnGenius, I-O DATA, Sitecom)
>>> 2. "et1macaddr" (ASUS)
>>> 3. "eth1addr" (Buffalo)
>>> 4. "athaddr" (EnGenius)
>>> 5. "baseMAC" (Netgear)
>>> 6. "mac" (Netgear)
>>> 7. "mac_addr" (Moxa)
>>> and more ("HW_LAN_MAC", "HW_WAN_MAC", "INIC_MAC_ADDR", "LAN_MAC_ADDR",
>>> "RADIOADDR0", "RADIOADDR1", "WAN_MAC_ADDR", "lan1_mac_addr", "wanmac",
>>> "wmac1", "wmac2").
>>>
>>> It doesn't make sense to add property for every possible MAC cell name.
>>> Instead allow specifying cells with "mac" compatible.
>>>
>>> Signed-off-by: Rafał Miłecki 
>>> ---
>>> List of devices and their U-Boot MAC variables:
>>> alphanetworks,asl56026) wanmac
>>> asus,rt-ac65p) et1macaddr
>>> asus,rt-ac85p) et1macaddr
>>> belkin,f9k1109v1) HW_WAN_MAC + HW_LAN_MAC
>>> buffalo,ls220de) eth1addr
>>> buffalo,ls421de) eth1addr
>>> checkpoint,l-50) lan1_mac_addr
>>> dovado,tiny-ac) INIC_MAC_ADDR
>>> dovado,tiny-ac) LAN_MAC_ADDR + WAN_MAC_ADDR
>>> edimax,ra21s) wanaddr
>>> edimax,rg21s) wanaddr
>>> elecom,wrc-2533ghbk-i) wanaddr
>>> elecom,wrc-2533ghbk2-t) wanaddr
>>> engenius,ecb1200) athaddr
>>> engenius,ecb1750) athaddr
>>> engenius,epg5000) wanaddr
>>> engenius,epg600) wanaddr
>>> engenius,esr1200) wanaddr
>>> engenius,esr1750) wanaddr
>>> engenius,esr600) wanaddr
>>> engenius,esr600h) wanaddr
>>> engenius,esr900) wanaddr
>>> enterasys,ws-ap3705i) RADIOADDR0 + RADIOADDR1
>>> iodata,wn-ac1167dgr) wanaddr
>>> iodata,wn-ac1167gr) wanaddr
>>> iodata,wn-ac1600dgr) wanaddr
>>> iodata,wn-ac1600dgr2) wanaddr
>>> iodata,wn-ac733gr3) wanaddr
>>> iodata,wn-ag300dgr) wanaddr
>>> iodata,wnpr2600g) wanaddr
>>> moxa,awk-1137c) mac_addr
>>> netgear,wax220) mac
>>> netgear,wndap620) baseMAC
>>> netgear,wndap660) baseMAC
>>> ocedo,panda) wmac1 + wmac2
>>> sitecom,wlr-7100) wanaddr
>>> sitecom,wlr-8100) wanaddr
>>>
>>>   .../devicetree/bindings/nvmem/u-boot,env.yaml | 33 +++
>>>   1 file changed, 33 insertions(+)
>>>
>>
>> Are these upstream U-Boots, or just vendor forks?
> 
> I guess most of those devices don't have upstream U-Boot support. Please

We do not document properties used in all possible projects, like vendor
forks. Only upstream U-Boot matters.

> note that while upstreaming vendors changes would be great in most cases
> it doesn't happen. Most vendors sadly don't care and most end users
> don't have enough time for that. In practice we often stick with vendor
> provided bootloader to flash and boot self build Linux system (like
> OpenWrt).
> 
> I'm not sure if/how does it help with this PATCH but please note that
> upstream U-Boot code also supports few extra variables.
> 
> There is generic eth_env_get_enetaddr_by_index() that supports variables
> like "<%s><%d>addr" and "<%s>addr". Right now it's used only for
> "eth<%d>addr" and "ethaddr" so that mostly limits us to "ethaddr",
> "eth1addr", "eth2addr" and "eth3addr".
> 
>  From some rare cases: there are also "usbnet_devaddr" and "wolpassword".
> 
> So given that U-Boot oficially supports at least 6 env variables for
> MAC and there are many used with custom U-Boots and firmwares this
> binding would help a lot.

Please limit this to upstream U-Boot. Drop all custom and firmware ones.

Then, just fix upstream U-Boot to have only one property...

Best regards,
Krzysztof



[PATCH 5/5] andes: ae350: Save cpu name to env

2023-12-25 Thread Leo Yu-Chi Liang
Detect CPU name through marchid and then save it to env.

Signed-off-by: Leo Yu-Chi Liang 
---
 board/AndesTech/ae350/ae350.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/board/AndesTech/ae350/ae350.c b/board/AndesTech/ae350/ae350.c
index bef9e3149e..9faf46d96e 100644
--- a/board/AndesTech/ae350/ae350.c
+++ b/board/AndesTech/ae350/ae350.c
@@ -28,6 +28,26 @@ DECLARE_GLOBAL_DATA_PTR;
  * Miscellaneous platform dependent initializations
  */
 
+int misc_init_r(void)
+{
+long csr_marchid = 0;
+const long mask_64 = 0x8000;
+const long mask_cpu = 0xff;
+char cpu_name[10] = {};
+
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+sbi_get_marchid(_marchid);
+#elif CONFIG_IS_ENABLED(RISCV_MMODE)
+csr_marchid = csr_read(CSR_MARCHID);
+#endif
+if (mask_64 & csr_marchid)
+snprintf(cpu_name, sizeof(cpu_name), "ax%lx", (mask_cpu & 
csr_marchid));
+else
+snprintf(cpu_name, sizeof(cpu_name), "a%lx", (mask_cpu & csr_marchid));
+
+return env_set("cpu", cpu_name);
+}
+
 #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
 #define ANDES_SPL_FDT_ADDR (CONFIG_TEXT_BASE - 0x10)
 void spl_perform_fixups(struct spl_image_info *spl_image)
-- 
2.34.1



[PATCH 4/5] andes: cpu: Enable cache and TLB ECC support

2023-12-25 Thread Leo Yu-Chi Liang
Andes CPU supports cache and TLB ECC.
Enable them by default.

Signed-off-by: Leo Yu-Chi Liang 
---
 arch/riscv/cpu/andesv5/cpu.c| 1 +
 arch/riscv/include/asm/arch-andes/csr.h | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/arch/riscv/cpu/andesv5/cpu.c b/arch/riscv/cpu/andesv5/cpu.c
index c9288dcb51..c011c00a94 100644
--- a/arch/riscv/cpu/andesv5/cpu.c
+++ b/arch/riscv/cpu/andesv5/cpu.c
@@ -36,6 +36,7 @@ void harts_early_init(void)
mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_CCTL_SUEN | 
\
MCACHE_CTL_IC_PREFETCH_EN | 
MCACHE_CTL_DC_PREFETCH_EN | \
MCACHE_CTL_DC_WAROUND_EN | 
MCACHE_CTL_L2C_WAROUND_EN | \
+   MCACHE_CTL_IC_ECCEN | MCACHE_CTL_DC_ECCEN | 
MCACHE_CTL_TLB_ECCEN);
 
if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
mcache_ctl |= MCACHE_CTL_IC_EN;
diff --git a/arch/riscv/include/asm/arch-andes/csr.h 
b/arch/riscv/include/asm/arch-andes/csr.h
index 755504c3c4..1a34618066 100644
--- a/arch/riscv/include/asm/arch-andes/csr.h
+++ b/arch/riscv/include/asm/arch-andes/csr.h
@@ -19,11 +19,14 @@
 
 #define MCACHE_CTL_IC_EN   BIT(0)
 #define MCACHE_CTL_DC_EN   BIT(1)
+#define MCACHE_CTL_IC_ECCENBIT(3)
+#define MCACHE_CTL_DC_ECCENBIT(5)
 #define MCACHE_CTL_CCTL_SUEN   BIT(8)
 #define MCACHE_CTL_IC_PREFETCH_EN  BIT(9)
 #define MCACHE_CTL_DC_PREFETCH_EN  BIT(10)
 #define MCACHE_CTL_DC_WAROUND_EN   BIT(13)
 #define MCACHE_CTL_L2C_WAROUND_EN  BIT(15)
+#define MCACHE_CTL_TLB_ECCEN   BIT(18)
 #define MCACHE_CTL_DC_COHENBIT(19)
 #define MCACHE_CTL_DC_COHSTA   BIT(20)
 
-- 
2.34.1



[PATCH 3/5] andes: cpu: Enable memboost feature

2023-12-25 Thread Leo Yu-Chi Liang
Andes CPU has memboost feature including prefetch,
write-around and non-blocking load. Enable them by default.

Signed-off-by: Leo Yu-Chi Liang 
---
 arch/riscv/cpu/andesv5/cpu.c| 7 +++
 arch/riscv/include/asm/arch-andes/csr.h | 6 ++
 2 files changed, 13 insertions(+)

diff --git a/arch/riscv/cpu/andesv5/cpu.c b/arch/riscv/cpu/andesv5/cpu.c
index 50cd31905d..c9288dcb51 100644
--- a/arch/riscv/cpu/andesv5/cpu.c
+++ b/arch/riscv/cpu/andesv5/cpu.c
@@ -31,8 +31,11 @@ void harts_early_init(void)
/* Enable I/D-cache in SPL */
if (CONFIG_IS_ENABLED(RISCV_MMODE)) {
unsigned long mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
+   unsigned long mmisc_ctl_val = csr_read(CSR_MMISC_CTL);
 
mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_CCTL_SUEN | 
\
+   MCACHE_CTL_IC_PREFETCH_EN | 
MCACHE_CTL_DC_PREFETCH_EN | \
+   MCACHE_CTL_DC_WAROUND_EN | 
MCACHE_CTL_L2C_WAROUND_EN | \
 
if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
mcache_ctl |= MCACHE_CTL_IC_EN;
@@ -51,4 +54,8 @@ void harts_early_init(void)
while (!(csr_read(CSR_MCACHE_CTL) & 
MCACHE_CTL_DC_COHSTA));
}
}
+   mmisc_ctl_val |= MMISC_CTL_NON_BLOCKING_EN;
+
+   csr_write(CSR_MMISC_CTL, mmisc_ctl_val);
+   }
 }
diff --git a/arch/riscv/include/asm/arch-andes/csr.h 
b/arch/riscv/include/asm/arch-andes/csr.h
index 93aa8b2343..755504c3c4 100644
--- a/arch/riscv/include/asm/arch-andes/csr.h
+++ b/arch/riscv/include/asm/arch-andes/csr.h
@@ -20,9 +20,15 @@
 #define MCACHE_CTL_IC_EN   BIT(0)
 #define MCACHE_CTL_DC_EN   BIT(1)
 #define MCACHE_CTL_CCTL_SUEN   BIT(8)
+#define MCACHE_CTL_IC_PREFETCH_EN  BIT(9)
+#define MCACHE_CTL_DC_PREFETCH_EN  BIT(10)
+#define MCACHE_CTL_DC_WAROUND_EN   BIT(13)
+#define MCACHE_CTL_L2C_WAROUND_EN  BIT(15)
 #define MCACHE_CTL_DC_COHENBIT(19)
 #define MCACHE_CTL_DC_COHSTA   BIT(20)
 
+/* mmisc_ctl register */
+#define MMISC_CTL_NON_BLOCKING_EN  BIT(8)
 
 #define CCTL_L1D_WBINVAL_ALL 6
 
-- 
2.34.1



[PATCH 2/5] andes: ae350: Implement cache switch via Kconfig

2023-12-25 Thread Leo Yu-Chi Liang
Kconfig provides SYS_[I|D]CACHE_OFF config options
to switch off caches. Implement the corresponding options.

Signed-off-by: Leo Yu-Chi Liang 
---
 arch/riscv/cpu/andesv5/cpu.c  | 9 +++--
 board/AndesTech/ae350/ae350.c | 3 ++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/cpu/andesv5/cpu.c b/arch/riscv/cpu/andesv5/cpu.c
index 63bc24cdfc..50cd31905d 100644
--- a/arch/riscv/cpu/andesv5/cpu.c
+++ b/arch/riscv/cpu/andesv5/cpu.c
@@ -32,8 +32,13 @@ void harts_early_init(void)
if (CONFIG_IS_ENABLED(RISCV_MMODE)) {
unsigned long mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
 
-   mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_IC_EN |
-  MCACHE_CTL_DC_EN | MCACHE_CTL_CCTL_SUEN);
+   mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_CCTL_SUEN | 
\
+
+   if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
+   mcache_ctl |= MCACHE_CTL_IC_EN;
+
+   if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) {
+   mcache_ctl |= MCACHE_CTL_DC_EN;
 
csr_write(CSR_MCACHE_CTL, mcache_ctl_val);
 
diff --git a/board/AndesTech/ae350/ae350.c b/board/AndesTech/ae350/ae350.c
index 772c6bf1ee..bef9e3149e 100644
--- a/board/AndesTech/ae350/ae350.c
+++ b/board/AndesTech/ae350/ae350.c
@@ -102,7 +102,8 @@ void *board_fdt_blob_setup(int *err)
 void spl_board_init()
 {
/* enable v5l2 cache */
-   enable_caches();
+   if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
+   enable_caches();
 }
 #endif
 
-- 
2.34.1



[PATCH 1/5] andes: csr.h: Clean up CSR definition

2023-12-25 Thread Leo Yu-Chi Liang
Signed-off-by: Leo Yu-Chi Liang 
---
 arch/riscv/include/asm/arch-andes/csr.h | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/riscv/include/asm/arch-andes/csr.h 
b/arch/riscv/include/asm/arch-andes/csr.h
index 393d51c6dd..93aa8b2343 100644
--- a/arch/riscv/include/asm/arch-andes/csr.h
+++ b/arch/riscv/include/asm/arch-andes/csr.h
@@ -15,17 +15,14 @@
 #define CSR_MARCHID 0xf12
 #define CSR_MCCTLCOMMAND 0x7cc
 
-#define MCACHE_CTL_IC_EN_OFFSET 0
-#define MCACHE_CTL_DC_EN_OFFSET 1
-#define MCACHE_CTL_CCTL_SUEN_OFFSET 8
-#define MCACHE_CTL_DC_COHEN_OFFSET 19
-#define MCACHE_CTL_DC_COHSTA_OFFSET 20
-
-#define MCACHE_CTL_IC_EN BIT(MCACHE_CTL_IC_EN_OFFSET)
-#define MCACHE_CTL_DC_EN BIT(MCACHE_CTL_DC_EN_OFFSET)
-#define MCACHE_CTL_CCTL_SUEN BIT(MCACHE_CTL_CCTL_SUEN_OFFSET)
-#define MCACHE_CTL_DC_COHEN BIT(MCACHE_CTL_DC_COHEN_OFFSET)
-#define MCACHE_CTL_DC_COHSTA BIT(MCACHE_CTL_DC_COHSTA_OFFSET)
+/* mcache_ctl register */
+
+#define MCACHE_CTL_IC_EN   BIT(0)
+#define MCACHE_CTL_DC_EN   BIT(1)
+#define MCACHE_CTL_CCTL_SUEN   BIT(8)
+#define MCACHE_CTL_DC_COHENBIT(19)
+#define MCACHE_CTL_DC_COHSTA   BIT(20)
+
 
 #define CCTL_L1D_WBINVAL_ALL 6
 
-- 
2.34.1



[PATCH V4] ARM add initial support for the Phytium Pe2201 Board.

2023-12-25 Thread TracyMg_Li
From: TracyMg_Li 

Add pe2201 platform code and the device tree of pe2201 platform board.
The initial support comprises the UART and PCIe.

Signed-off-by: TracyMg_Li 
Changes since v1:
fix space corrupt.
Changes since v2:
switch to bootstd and text environment.
Changes since v3:
add environment variables.
---
 arch/arm/Kconfig |   7 ++
 arch/arm/dts/Makefile|   1 +
 arch/arm/dts/phytium-pe2201.dts  |  43 +++
 board/phytium/pe2201/Kconfig |  12 ++
 board/phytium/pe2201/MAINTAINERS |   8 ++
 board/phytium/pe2201/Makefile|  12 ++
 board/phytium/pe2201/cpu.h   |  64 +++
 board/phytium/pe2201/ddr.c   | 190 +++
 board/phytium/pe2201/pcie.c  |  60 ++
 board/phytium/pe2201/pe2201.c|  92 +++
 board/phytium/pe2201/pe2201.env  |  25 
 board/phytium/pe2201/pll.c   |  75 
 board/phytium/pe2201/sec.c   |  37 ++
 configs/pe2201_defconfig |  42 +++
 include/configs/pe2201.h |  16 +++
 15 files changed, 684 insertions(+)
 create mode 100644 arch/arm/dts/phytium-pe2201.dts
 create mode 100644 board/phytium/pe2201/Kconfig
 create mode 100644 board/phytium/pe2201/MAINTAINERS
 create mode 100644 board/phytium/pe2201/Makefile
 create mode 100644 board/phytium/pe2201/cpu.h
 create mode 100644 board/phytium/pe2201/ddr.c
 create mode 100644 board/phytium/pe2201/pcie.c
 create mode 100644 board/phytium/pe2201/pe2201.c
 create mode 100644 board/phytium/pe2201/pe2201.env
 create mode 100644 board/phytium/pe2201/pll.c
 create mode 100644 board/phytium/pe2201/sec.c
 create mode 100644 configs/pe2201_defconfig
 create mode 100644 include/configs/pe2201.h

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index d812685c98..358c515a93 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -2060,6 +2060,12 @@ config TARGET_POMELO
   Support for pomelo platform.
   It has 8GB Sdram, uart and pcie.
 
+config TARGET_PE2201
+   bool "Support Phytium PE2201 Platform"
+   select ARM64
+   help
+ Support for pe2201 platform.It has 2GB Sdram, uart and pcie.
+
 config TARGET_PRESIDIO_ASIC
bool "Support Cortina Presidio ASIC Platform"
select ARM64
@@ -2336,6 +2342,7 @@ source "board/variscite/dart_6ul/Kconfig"
 source "board/vscom/baltos/Kconfig"
 source "board/phytium/durian/Kconfig"
 source "board/phytium/pomelo/Kconfig"
+source "board/phytium/pe2201/Kconfig"
 source "board/xen/xenguest_arm64/Kconfig"
 
 source "arch/arm/Kconfig.debug"
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 5fc888680b..ce2fc626b0 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1469,6 +1469,7 @@ dtb-$(CONFIG_TARGET_TOTAL_COMPUTE) += total_compute.dtb
 
 dtb-$(CONFIG_TARGET_DURIAN) += phytium-durian.dtb
 dtb-$(CONFIG_TARGET_POMELO) += phytium-pomelo.dtb
+dtb-$(CONFIG_TARGET_PE2201) += phytium-pe2201.dtb
 
 dtb-$(CONFIG_TARGET_PRESIDIO_ASIC) += ca-presidio-engboard.dtb
 
diff --git a/arch/arm/dts/phytium-pe2201.dts b/arch/arm/dts/phytium-pe2201.dts
new file mode 100644
index 00..959584fbbb
--- /dev/null
+++ b/arch/arm/dts/phytium-pe2201.dts
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  dts file for Phytium pe2201 board
+ *  Copyright (C) 2023, Phytium Technology Co., Ltd.
+ * lixinde 
+ * weichangzheng   
+ */
+/dts-v1/;
+
+/ {
+   model = "Phytium pe2201 Board";
+   compatible = "phytium,pe2201";
+   #address-cells = <2>;
+   #size-cells = <2>;
+
+   aliases {
+   serial0 = 
+   };
+
+   uart0: serial@2800c000 {
+   compatible = "arm,pl011", "arm,primecell";
+   reg = <0x0 0x2800c000 0x0 0x1000>;
+   clock = <1>;
+   };
+
+   soc {
+   compatible = "simple-bus";
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   pcie@4000 {
+   compatible = "pci-host-ecam-generic";
+   device_type = "pci";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   reg = <0x0 0x4000 0x0 0x1000>;
+   ranges = <0x0100 0x00 0x 0x0 0x5000 0x0 
0x00F0>,
+   <0x0200 0x00 0x5800 0x0 0x5800 0x0 
0x2800>,
+   <0x4300 0x10 0x 0x10 0x 0x10 
0x>;
+   };
+   };
+};
diff --git a/board/phytium/pe2201/Kconfig b/board/phytium/pe2201/Kconfig
new file mode 100644
index 00..f2f222b5d3
--- /dev/null
+++ b/board/phytium/pe2201/Kconfig
@@ -0,0 +1,12 @@
+if TARGET_PE2201
+
+config SYS_BOARD
+   default "pe2201"
+
+config SYS_VENDOR
+   default "phytium"
+
+config SYS_CONFIG_NAME
+   default "pe2201"
+
+endif
diff --git a/board/phytium/pe2201/MAINTAINERS 

[PATCH v2] android_ab: don't ignore ab_control_store return code

2023-12-25 Thread Alexey Romanov
ab_control_store() can return an error if writing to disk fails.
In this case, we have to pass the error code to the caller.

Signed-off-by: Alexey Romanov 
Reviewed-by: Mattijs Korpershoek 
---
 boot/android_ab.c | 16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/boot/android_ab.c b/boot/android_ab.c
index 73b55c196c..af3c375e07 100644
--- a/boot/android_ab.c
+++ b/boot/android_ab.c
@@ -337,7 +337,14 @@ int ab_select_slot(struct blk_desc *dev_desc, struct 
disk_partition *part_info,
 
if (store_needed) {
abc->crc32_le = ab_control_compute_crc(abc);
-   ab_control_store(dev_desc, part_info, abc, 0);
+   ret = ab_control_store(dev_desc, part_info, abc, 0);
+   if (ret < 0) {
+#if ANDROID_AB_BACKUP_OFFSET
+   free(backup_abc);
+#endif
+   free(abc);
+   return ret;
+   }
}
 
 #if ANDROID_AB_BACKUP_OFFSET
@@ -346,8 +353,13 @@ int ab_select_slot(struct blk_desc *dev_desc, struct 
disk_partition *part_info,
 * to the backup offset
 */
if (memcmp(backup_abc, abc, sizeof(*abc)) != 0) {
-   ab_control_store(dev_desc, part_info, abc,
+   ret = ab_control_store(dev_desc, part_info, abc,
 ANDROID_AB_BACKUP_OFFSET);
+   if (ret < 0) {
+   free(backup_abc);
+   free(abc);
+   return ret;
+   }
}
free(backup_abc);
 #endif
-- 
2.39.2



Re: [PATCH v3 3/4] net: tftp: remove explicit efi configuration dependency

2023-12-25 Thread Tom Rini
On Mon, Dec 25, 2023 at 10:23:35AM +0100, Heinrich Schuchardt wrote:
> On 12/18/23 03:38, AKASHI Takahiro wrote:
> > Now it is clear that the feature actually depends on efi interfaces,
> > not "bootefi" command. efi_set_bootdev() will automatically be nullified
> > if necessary efi component is disabled.
> > 
> > Signed-off-by: AKASHI Takahiro 
> > ---
> >   net/tftp.c | 10 --
> >   1 file changed, 4 insertions(+), 6 deletions(-)
> > 
> > diff --git a/net/tftp.c b/net/tftp.c
> > index 88e71e67de35..2e335413492b 100644
> > --- a/net/tftp.c
> > +++ b/net/tftp.c
> > @@ -302,12 +302,10 @@ static void tftp_complete(void)
> > time_start * 1000, "/s");
> > }
> > puts("\ndone\n");
> > -   if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) {
> > -   if (!tftp_put_active)
> > -   efi_set_bootdev("Net", "", tftp_filename,
> > -   map_sysmem(tftp_load_addr, 0),
> > -   net_boot_file_size);
> > -   }
> > +   if (!tftp_put_active)
> > +   efi_set_bootdev("Net", "", tftp_filename,
> 
> Function efi_set_bootdev() will not be compiled for CONFIG_EFI_LOADER=n.
> So this change may lead to build failures.

In the EFI_LOADER=n case  has an empty inline instead so
this should be fine.

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/2] efi_loader: auto-generate boot option for each blkio device

2023-12-25 Thread Heinrich Schuchardt

On 12/20/23 09:41, Masahisa Kojima wrote:

Current efibootmgr auto-generates the boot option for all
disks and partitions installing EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
while EDK II reference implementation auto-generates the boot option
for all devices installing  EFI_BLOCK_IO_PROTOCOL with
eliminating logical partitions.

This commit modifies the efibootmgr to get aligned to EDK II.

Signed-off-by: Masahisa Kojima 
---
  lib/efi_loader/efi_bootmgr.c | 94 +++-
  1 file changed, 71 insertions(+), 23 deletions(-)

diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 56d97f2382..636f01e2eb 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -560,6 +560,50 @@ err:
return ret;
  }

+/**
+ * try_load_from_media() - load file from media
+ *
+ * @fp:file path


This does not match the parameter name of the function leading to a
'make htmldocs' build error.


+ * @handle:pointer to handle for newly installed image
+ *
+ * If @fp contains a file name, load the file.
+ * If @fp does not have a file name, search the architecture-specific


ditto

Best regards

Heinrich


+ * default file and load it.
+ * TODO: If the FilePathList[0] device does not support
+ * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL but supports EFI_BLOCK_IO_PROTOCOL,
+ * call EFI_BOOT_SERVICES.ConnectController()
+ * TODO: FilePathList[0] device supports EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
+ * not based on EFI_BLOCK_IO_PROTOCOL
+ *
+ * Return: status code
+ */
+static efi_status_t try_load_from_media(struct efi_device_path *file_path,
+   efi_handle_t *handle)
+{
+   efi_handle_t h;
+   efi_status_t ret = EFI_SUCCESS;
+   struct efi_device_path *rem, *dp = NULL;
+   struct efi_device_path *final_dp = file_path;
+
+   h = efi_dp_find_obj(file_path, _block_io_guid, );
+   if (h) {
+   if (rem->type == DEVICE_PATH_TYPE_END) {
+   /* no file name present, try default file */
+   ret = check_disk_has_default_file(h->dev, );
+   if (ret != EFI_SUCCESS)
+   return ret;
+
+   final_dp = dp;
+   }
+   }
+
+   ret = EFI_CALL(efi_load_image(true, efi_root, final_dp, NULL, 0, 
handle));
+
+   efi_free_pool(dp);
+
+   return ret;
+}
+
  /**
   * try_load_entry() - try to load image for boot option
   *
@@ -594,7 +638,6 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
*handle,
}

if (lo.attributes & LOAD_OPTION_ACTIVE) {
-   struct efi_device_path *file_path;
u32 attributes;

log_debug("trying to load \"%ls\" from %pD\n", lo.label,
@@ -611,10 +654,7 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
*handle,
else
ret = EFI_LOAD_ERROR;
} else {
-   file_path = expand_media_path(lo.file_path);
-   ret = EFI_CALL(efi_load_image(true, efi_root, file_path,
- NULL, 0, handle));
-   efi_free_pool(file_path);
+   ret = try_load_from_media(lo.file_path, handle);
}
if (ret != EFI_SUCCESS) {
log_warning("Loading %ls '%ls' failed\n",
@@ -748,19 +788,19 @@ error:
   * efi_bootmgr_enumerate_boot_option() - enumerate the possible bootable media
   *
   * @opt:  pointer to the media boot option structure
- * @volume_handles:pointer to the efi handles
+ * @handles:   pointer to the efi handles
   * @count:number of efi handle
   * Return:status code
   */
  static efi_status_t efi_bootmgr_enumerate_boot_option(struct 
eficonfig_media_boot_option *opt,
- efi_handle_t 
*volume_handles,
- efi_status_t count)
+ efi_handle_t *handles,
+ efi_uintn_t *count)
  {
-   u32 i;
+   u32 i, num = 0;
struct efi_handler *handler;
efi_status_t ret = EFI_SUCCESS;

-   for (i = 0; i < count; i++) {
+   for (i = 0; i < *count; i++) {
u16 *p;
u16 dev_name[BOOTMENU_DEVICE_NAME_MAX];
char *optional_data;
@@ -768,8 +808,15 @@ static efi_status_t 
efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo
char buf[BOOTMENU_DEVICE_NAME_MAX];
struct efi_device_path *device_path;
struct efi_device_path *short_dp;
+   struct efi_block_io *blkio;
+
+   ret = efi_search_protocol(handles[i], _block_io_guid, 
);
+   blkio = handler->protocol_interface;

-  

Re: [PATCH 1/2] efi_loader: auto-generate boot option for each blkio device

2023-12-25 Thread Heinrich Schuchardt

On 12/25/23 12:00, Heinrich Schuchardt wrote:

On 12/20/23 09:41, Masahisa Kojima wrote:

Current efibootmgr auto-generates the boot option for all
disks and partitions installing EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
while EDK II reference implementation auto-generates the boot option
for all devices installing  EFI_BLOCK_IO_PROTOCOL with
eliminating logical partitions.

This commit modifies the efibootmgr to get aligned to EDK II.

Signed-off-by: Masahisa Kojima 
---
  lib/efi_loader/efi_bootmgr.c | 94 +++-
  1 file changed, 71 insertions(+), 23 deletions(-)

diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 56d97f2382..636f01e2eb 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -560,6 +560,50 @@ err:
  return ret;
  }

+/**
+ * try_load_from_media() - load file from media
+ *
+ * @fp:    file path
+ * @handle:    pointer to handle for newly installed image
+ *
+ * If @fp contains a file name, load the file.
+ * If @fp does not have a file name, search the architecture-specific
+ * default file and load it.
+ * TODO: If the FilePathList[0] device does not support
+ * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL but supports EFI_BLOCK_IO_PROTOCOL,
+ * call EFI_BOOT_SERVICES.ConnectController()
+ * TODO: FilePathList[0] device supports EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
+ * not based on EFI_BLOCK_IO_PROTOCOL
+ *
+ * Return:    status code
+ */
+static efi_status_t try_load_from_media(struct efi_device_path 
*file_path,

+    efi_handle_t *handle)
+{
+    efi_handle_t h;
+    efi_status_t ret = EFI_SUCCESS;
+    struct efi_device_path *rem, *dp = NULL;
+    struct efi_device_path *final_dp = file_path;
+
+    h = efi_dp_find_obj(file_path, _block_io_guid, );
+    if (h) {
+    if (rem->type == DEVICE_PATH_TYPE_END) {
+    /* no file name present, try default file */
+    ret = check_disk_has_default_file(h->dev, );
+    if (ret != EFI_SUCCESS)
+    return ret;
+
+    final_dp = dp;
+    }
+    }
+
+    ret = EFI_CALL(efi_load_image(true, efi_root, final_dp, NULL, 0, 
handle));

+
+    efi_free_pool(dp);
+
+    return ret;
+}
+
  /**
   * try_load_entry() - try to load image for boot option
   *
@@ -594,7 +638,6 @@ static efi_status_t try_load_entry(u16 n, 
efi_handle_t *handle,

  }

  if (lo.attributes & LOAD_OPTION_ACTIVE) {
-    struct efi_device_path *file_path;
  u32 attributes;

  log_debug("trying to load \"%ls\" from %pD\n", lo.label,
@@ -611,10 +654,7 @@ static efi_status_t try_load_entry(u16 n, 
efi_handle_t *handle,

  else
  ret = EFI_LOAD_ERROR;


This line does not exist in efi/next. Am I missing a prerequisite patch?


My fault.





Best regards

Heinrich


  } else {
-    file_path = expand_media_path(lo.file_path);
-    ret = EFI_CALL(efi_load_image(true, efi_root, file_path,
-  NULL, 0, handle));
-    efi_free_pool(file_path);
+    ret = try_load_from_media(lo.file_path, handle);
  }
  if (ret != EFI_SUCCESS) {
  log_warning("Loading %ls '%ls' failed\n",
@@ -748,19 +788,19 @@ error:
   * efi_bootmgr_enumerate_boot_option() - enumerate the possible 
bootable media

   *
   * @opt:    pointer to the media boot option structure
- * @volume_handles:    pointer to the efi handles
+ * @handles:    pointer to the efi handles
   * @count:    number of efi handle
   * Return:    status code
   */
  static efi_status_t efi_bootmgr_enumerate_boot_option(struct 
eficonfig_media_boot_option *opt,

-  efi_handle_t *volume_handles,
-  efi_status_t count)
+  efi_handle_t *handles,
+  efi_uintn_t *count)
  {
-    u32 i;
+    u32 i, num = 0;
  struct efi_handler *handler;
  efi_status_t ret = EFI_SUCCESS;

-    for (i = 0; i < count; i++) {
+    for (i = 0; i < *count; i++) {
  u16 *p;
  u16 dev_name[BOOTMENU_DEVICE_NAME_MAX];
  char *optional_data;
@@ -768,8 +808,15 @@ static efi_status_t 
efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo

  char buf[BOOTMENU_DEVICE_NAME_MAX];
  struct efi_device_path *device_path;
  struct efi_device_path *short_dp;
+    struct efi_block_io *blkio;
+
+    ret = efi_search_protocol(handles[i], _block_io_guid, 
);

+    blkio = handler->protocol_interface;

-    ret = efi_search_protocol(volume_handles[i], 
_guid_device_path, );

+    if (blkio->media->logical_partition)
+    continue;
+
+    ret = efi_search_protocol(handles[i], _guid_device_path, 
);

  if (ret != EFI_SUCCESS)
  continue;
  ret = efi_protocol_open(handler, (void **)_path,
@@ -777,7 +824,7 @@ static efi_status_t 
efi_bootmgr_enumerate_boot_option(struct 

Re: [PATCH 1/2] efi_loader: auto-generate boot option for each blkio device

2023-12-25 Thread Heinrich Schuchardt

On 12/20/23 09:41, Masahisa Kojima wrote:

Current efibootmgr auto-generates the boot option for all
disks and partitions installing EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
while EDK II reference implementation auto-generates the boot option
for all devices installing  EFI_BLOCK_IO_PROTOCOL with
eliminating logical partitions.

This commit modifies the efibootmgr to get aligned to EDK II.

Signed-off-by: Masahisa Kojima 
---
  lib/efi_loader/efi_bootmgr.c | 94 +++-
  1 file changed, 71 insertions(+), 23 deletions(-)

diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 56d97f2382..636f01e2eb 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -560,6 +560,50 @@ err:
return ret;
  }

+/**
+ * try_load_from_media() - load file from media
+ *
+ * @fp:file path
+ * @handle:pointer to handle for newly installed image
+ *
+ * If @fp contains a file name, load the file.
+ * If @fp does not have a file name, search the architecture-specific
+ * default file and load it.
+ * TODO: If the FilePathList[0] device does not support
+ * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL but supports EFI_BLOCK_IO_PROTOCOL,
+ * call EFI_BOOT_SERVICES.ConnectController()
+ * TODO: FilePathList[0] device supports EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
+ * not based on EFI_BLOCK_IO_PROTOCOL
+ *
+ * Return: status code
+ */
+static efi_status_t try_load_from_media(struct efi_device_path *file_path,
+   efi_handle_t *handle)
+{
+   efi_handle_t h;
+   efi_status_t ret = EFI_SUCCESS;
+   struct efi_device_path *rem, *dp = NULL;
+   struct efi_device_path *final_dp = file_path;
+
+   h = efi_dp_find_obj(file_path, _block_io_guid, );
+   if (h) {
+   if (rem->type == DEVICE_PATH_TYPE_END) {
+   /* no file name present, try default file */
+   ret = check_disk_has_default_file(h->dev, );
+   if (ret != EFI_SUCCESS)
+   return ret;
+
+   final_dp = dp;
+   }
+   }
+
+   ret = EFI_CALL(efi_load_image(true, efi_root, final_dp, NULL, 0, 
handle));
+
+   efi_free_pool(dp);
+
+   return ret;
+}
+
  /**
   * try_load_entry() - try to load image for boot option
   *
@@ -594,7 +638,6 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
*handle,
}

if (lo.attributes & LOAD_OPTION_ACTIVE) {
-   struct efi_device_path *file_path;
u32 attributes;

log_debug("trying to load \"%ls\" from %pD\n", lo.label,
@@ -611,10 +654,7 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
*handle,
else
ret = EFI_LOAD_ERROR;


This line does not exist in efi/next. Am I missing a prerequisite patch?

Best regards

Heinrich


} else {
-   file_path = expand_media_path(lo.file_path);
-   ret = EFI_CALL(efi_load_image(true, efi_root, file_path,
- NULL, 0, handle));
-   efi_free_pool(file_path);
+   ret = try_load_from_media(lo.file_path, handle);
}
if (ret != EFI_SUCCESS) {
log_warning("Loading %ls '%ls' failed\n",
@@ -748,19 +788,19 @@ error:
   * efi_bootmgr_enumerate_boot_option() - enumerate the possible bootable media
   *
   * @opt:  pointer to the media boot option structure
- * @volume_handles:pointer to the efi handles
+ * @handles:   pointer to the efi handles
   * @count:number of efi handle
   * Return:status code
   */
  static efi_status_t efi_bootmgr_enumerate_boot_option(struct 
eficonfig_media_boot_option *opt,
- efi_handle_t 
*volume_handles,
- efi_status_t count)
+ efi_handle_t *handles,
+ efi_uintn_t *count)
  {
-   u32 i;
+   u32 i, num = 0;
struct efi_handler *handler;
efi_status_t ret = EFI_SUCCESS;

-   for (i = 0; i < count; i++) {
+   for (i = 0; i < *count; i++) {
u16 *p;
u16 dev_name[BOOTMENU_DEVICE_NAME_MAX];
char *optional_data;
@@ -768,8 +808,15 @@ static efi_status_t 
efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo
char buf[BOOTMENU_DEVICE_NAME_MAX];
struct efi_device_path *device_path;
struct efi_device_path *short_dp;
+   struct efi_block_io *blkio;
+
+   ret = efi_search_protocol(handles[i], _block_io_guid, 
);
+   blkio = handler->protocol_interface;

-   ret = 

Re: [PATCH v4 1/1] efi: Avoid using dm_scan_other()

2023-12-25 Thread Heinrich Schuchardt

On 12/19/23 15:27, Simon Glass wrote:

This function is defined by bootstd so using it precludes using that
feature. Use the board_early_init_r() feature instead.

Nove the affected code into a new file, so that it is clear that
this relates to board init.

Signed-off-by: Simon Glass 


Reviewed-by: Heinrich Schuchardt 


---

Changes in v4:
- Create a new file inside lib/efi instead of board/

Changes in v2:
- Drop duplicate acpi_xsdt patch
- Put the board_early_init_r code into board/

  configs/efi-x86_app64_defconfig |   1 +
  lib/efi/Makefile|   2 +-
  lib/efi/efi_app.c   | 187 -
  lib/efi/efi_app_init.c  | 205 
  4 files changed, 207 insertions(+), 188 deletions(-)
  create mode 100644 lib/efi/efi_app_init.c

diff --git a/configs/efi-x86_app64_defconfig b/configs/efi-x86_app64_defconfig
index 14b5cd0fa0ee..ed0506fe25cb 100644
--- a/configs/efi-x86_app64_defconfig
+++ b/configs/efi-x86_app64_defconfig
@@ -17,6 +17,7 @@ CONFIG_USE_BOOTCOMMAND=y
  CONFIG_BOOTCOMMAND="ext2load scsi 0:3 0100 /boot/vmlinuz; zboot 0100"
  CONFIG_SYS_CONSOLE_INFO_QUIET=y
  CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_BOARD_EARLY_INIT_R=y
  CONFIG_HUSH_PARSER=y
  CONFIG_SYS_PBSIZE=532
  CONFIG_CMD_BOOTZ=y
diff --git a/lib/efi/Makefile b/lib/efi/Makefile
index a790d2d554cd..232fa684360e 100644
--- a/lib/efi/Makefile
+++ b/lib/efi/Makefile
@@ -2,7 +2,7 @@
  #
  # (C) Copyright 2015 Google, Inc

-obj-$(CONFIG_EFI_APP) += efi_app.o efi.o
+obj-$(CONFIG_EFI_APP) += efi_app.o efi.o efi_app_init.o
  obj-$(CONFIG_EFI_STUB) += efi_info.o

  CFLAGS_REMOVE_efi_stub.o := -mregparm=3 \
diff --git a/lib/efi/efi_app.c b/lib/efi/efi_app.c
index c5eb816655ea..e79fa5dad176 100644
--- a/lib/efi/efi_app.c
+++ b/lib/efi/efi_app.c
@@ -68,49 +68,6 @@ int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, 
uint *keyp,
return 0;
  }

-/**
- * efi_bind_block() - bind a new block device to an EFI device
- *
- * Binds a new top-level EFI_MEDIA device as well as a child block device so
- * that the block device can be accessed in U-Boot.
- *
- * The device can then be accessed using 'part list efi 0', 'fat ls efi 0:1',
- * for example, just like any other interface type.
- *
- * @handle: handle of the controller on which this driver is installed
- * @blkio: block io protocol proxied by this driver
- * @device_path: EFI device path structure for this
- * @len: Length of @device_path in bytes
- * @devp: Returns the bound device
- * Return: 0 if OK, -ve on error
- */
-int efi_bind_block(efi_handle_t handle, struct efi_block_io *blkio,
-  struct efi_device_path *device_path, int len,
-  struct udevice **devp)
-{
-   struct efi_media_plat plat;
-   struct udevice *dev;
-   char name[18];
-   int ret;
-
-   plat.handle = handle;
-   plat.blkio = blkio;
-   plat.device_path = malloc(device_path->length);
-   if (!plat.device_path)
-   return log_msg_ret("path", -ENOMEM);
-   memcpy(plat.device_path, device_path, device_path->length);
-   ret = device_bind(dm_root(), DM_DRIVER_GET(efi_media), "efi_media",
- , ofnode_null(), );
-   if (ret)
-   return log_msg_ret("bind", ret);
-
-   snprintf(name, sizeof(name), "efi_media_%x", dev_seq(dev));
-   device_set_name(dev, name);
-   *devp = dev;
-
-   return 0;
-}
-
  static efi_status_t setup_memory(struct efi_priv *priv)
  {
struct efi_boot_services *boot = priv->boot;
@@ -179,150 +136,6 @@ static void free_memory(struct efi_priv *priv)
global_data_ptr = NULL;
  }

-/**
- * devpath_is_partition() - Figure out if a device path is a partition
- *
- * Checks if a device path refers to a partition on some media device. This
- * works by checking for a valid partition number in a hard-driver media device
- * as the final component of the device path.
- *
- * @path:  device path
- * Return: true if a partition, false if not
- * (e.g. it might be media which contains partitions)
- */
-static bool devpath_is_partition(const struct efi_device_path *path)
-{
-   const struct efi_device_path *p;
-   bool was_part = false;
-
-   for (p = path; p->type != DEVICE_PATH_TYPE_END;
-p = (void *)p + p->length) {
-   was_part = false;
-   if (p->type == DEVICE_PATH_TYPE_MEDIA_DEVICE &&
-   p->sub_type == DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH) {
-   struct efi_device_path_hard_drive_path *hd =
-   (void *)path;
-
-   if (hd->partition_number)
-   was_part = true;
-   }
-   }
-
-   return was_part;
-}
-
-/**
- * setup_block() - Find all block devices and setup EFI devices for them
- *
- * Partitions are ignored, since U-Boot has partition handling. Errors with
- * particular 

Re: [PATCH 3/3] efi_loader: create common function to free struct efi_disk_obj

2023-12-25 Thread Heinrich Schuchardt

On 12/25/23 05:43, Masahisa Kojima wrote:

Current error handling of creating raw disk/partition has
following issues.
  - duplicate free for efi handle, efi handle is already freed
in efi_delete_handle()


I cannot see where this patch reduces the number of efi_delete_handle()
invocations.


  - missing free for struct efi_device_path and
struct efi_simple_file_system_protocol in some error paths

To address those issue, this commit creates the common function
to free the struct efi_disk_obj resources and calls it in case
of error.

Signed-off-by: Masahisa Kojima 
---
  lib/efi_loader/efi_disk.c | 23 ---
  1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 415d8601ba..d2ac2fab9b 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -372,6 +372,19 @@ static int efi_fs_exists(struct blk_desc *desc, int part)
return 1;
  }

+static void efi_disk_free_diskobj(struct efi_disk_obj *diskobj)
+{
+   struct efi_device_path *dp = NULL;


This NULL value is never used.


+   struct efi_simple_file_system_protocol *volume = NULL;


ditto


+
+   dp = diskobj->dp;
+   volume = diskobj->volume;
+
+   efi_delete_handle(>header);


efi_delete_handle() may fail.


+   efi_free_pool(dp);


The device path may only be freed if it has been uninstalled from the
handle.


+   free(volume);


The simple file protocol interface may only be freed if it has been
uninstalled from the handle.


+}
+
  /**
   * efi_disk_add_dev() - create a handle for a partition or disk
   *
@@ -529,9 +542,7 @@ static efi_status_t efi_disk_add_dev(
}
return EFI_SUCCESS;
  error:
-   efi_delete_handle(>header);
-   free(diskobj->volume);
-   free(diskobj);
+   efi_disk_free_diskobj(diskobj);
return ret;
  }

@@ -570,8 +581,7 @@ static int efi_disk_create_raw(struct udevice *dev, 
efi_handle_t agent_handle)
return ret;
}
if (efi_link_dev(>header, dev)) {
-   efi_free_pool(disk->dp);
-   efi_delete_handle(>header);
+   efi_disk_free_diskobj(disk);

return -EINVAL;
}
@@ -625,8 +635,7 @@ static int efi_disk_create_part(struct udevice *dev, 
efi_handle_t agent_handle)
return -1;
}
if (efi_link_dev(>header, dev)) {
-   efi_free_pool(disk->dp);
-   efi_delete_handle(>header);
+   efi_disk_free_diskobj(disk);


In efi_disk_add_dev we have opened a protocol interface. We must close
it before removing the partition handle otherwise the disk handle can
never be removed.

To do this all properly we will need to re-implement this code using
proper EFI drivers which expose a driver binding protocol. Please, add a
TODO: comment here that closing the protocol is missing.

Best regards

Heinrich



return -1;
}




Re: [PATCH 2/3] efi_loader: avoid pointer access after calling efi_delete_handle

2023-12-25 Thread Heinrich Schuchardt

On 12/25/23 05:43, Masahisa Kojima wrote:

efi_delete_handle() calls efi_purge_handle(), then it finally
frees the efi handle.
Both diskobj and handle variables in efi_disk_remove() have
the same pointer, we can not access diskobj->dp after calling
efi_delete_handle().

This commit saves the struct efi_device_path pointer before
calling efi_delete_handle(). This commit also fixes the
missing free for volume member in struct efi_disk_obj.

Signed-off-by: Masahisa Kojima 
---
  lib/efi_loader/efi_disk.c | 12 +---
  1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index a2f8b531a3..415d8601ba 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -701,7 +701,9 @@ int efi_disk_remove(void *ctx, struct event *event)
struct udevice *dev = event->data.dm.dev;
efi_handle_t handle;
struct blk_desc *desc;
+   struct efi_device_path *dp = NULL;
struct efi_disk_obj *diskobj = NULL;
+   struct efi_simple_file_system_protocol *volume = NULL;
efi_status_t ret;

if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)))
@@ -722,14 +724,18 @@ int efi_disk_remove(void *ctx, struct event *event)
return 0;
}

+   if (diskobj) {



  diskobj = container_of(handle, struct efi_disk_obj, header);

can be replaced by

  diskobj = handle

We should check the handle immediately after dev_tag_get_ptr() and
return 0 if the handle == NULL.


+   dp = diskobj->dp;
+   volume = diskobj->volume;
+   }
+
ret = efi_delete_handle(handle);


We must not delete the handle in case of UCLASS_EFI_LOADER.

Instead of calling efi_delete_handle we should uninstall all protocols
that we have installed. If no protocol is left the handle will go away.

To make the protocols to delete tractable they should be opened with
BY_DRIVER.

When a partition is removed we must close the protocol interfaces opened
with EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER (cf. efi_disk_add_dev()).

Best regards

Heinrich


/* Do not delete DM device if there are still EFI drivers attached. */
if (ret != EFI_SUCCESS)
return -1;

-   if (diskobj)
-   efi_free_pool(diskobj->dp);
-
+   efi_free_pool(dp);
+   free(volume);
dev_tag_del(dev, DM_TAG_EFI);

return 0;




Re: [PATCH 1/3] efi_loader: remove unused members from struct efi_disk_obj

2023-12-25 Thread Heinrich Schuchardt

On 12/25/23 05:43, Masahisa Kojima wrote:

part and dev_index in struct efi_disk_obj are not used,
let's remove it.

This commit also removes the invalid structure comment
for @dev, it does not exist.

Signed-off-by: Masahisa Kojima 


Reviewed-by: Heinrich Schuchardt 


---
  lib/efi_loader/efi_disk.c | 15 +++
  1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index f0d76113b0..a2f8b531a3 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -32,20 +32,15 @@ const efi_guid_t efi_system_partition_guid = 
PARTITION_SYSTEM_GUID;
   *
   * @header:   EFI object header
   * @ops:  EFI disk I/O protocol interface
- * @dev_index: device index of block device
   * @media:block I/O media information
   * @dp:   device path to the block device
- * @part:  partition
   * @volume:   simple file system protocol of the partition
- * @dev:   associated DM device
   */
  struct efi_disk_obj {
struct efi_object header;
struct efi_block_io ops;
-   int dev_index;
struct efi_block_io_media media;
struct efi_device_path *dp;
-   unsigned int part;
struct efi_simple_file_system_protocol *volume;
  };

@@ -383,7 +378,6 @@ static int efi_fs_exists(struct blk_desc *desc, int part)
   * @parent:   parent handle
   * @dp_parent:parent device path
   * @desc: internal block device
- * @dev_index: device index for block device
   * @part_info:partition info
   * @part: partition
   * @disk: pointer to receive the created handle
@@ -394,7 +388,6 @@ static efi_status_t efi_disk_add_dev(
efi_handle_t parent,
struct efi_device_path *dp_parent,
struct blk_desc *desc,
-   int dev_index,
struct disk_partition *part_info,
unsigned int part,
struct efi_disk_obj **disk,
@@ -456,7 +449,6 @@ static efi_status_t efi_disk_add_dev(
diskobj->dp = efi_dp_from_part(desc, part);
diskobj->media.last_block = desc->lba - 1;
}
-   diskobj->part = part;

/*
 * Install the device path and the block IO protocol.
@@ -499,7 +491,6 @@ static efi_status_t efi_disk_add_dev(
goto error;
}
diskobj->ops = block_io_disk_template;
-   diskobj->dev_index = dev_index;

/* Fill in EFI IO Media info (for read/write callbacks) */
diskobj->media.removable_media = desc->removable;
@@ -519,7 +510,7 @@ static efi_status_t efi_disk_add_dev(

EFI_PRINT("BlockIO: part %u, present %d, logical %d, removable %d"
  ", last_block %llu\n",
- diskobj->part,
+ part,
  diskobj->media.media_present,
  diskobj->media.logical_partition,
  diskobj->media.removable_media,
@@ -566,7 +557,7 @@ static int efi_disk_create_raw(struct udevice *dev, 
efi_handle_t agent_handle)
diskid = desc->devnum;

ret = efi_disk_add_dev(NULL, NULL, desc,
-  diskid, NULL, 0, , agent_handle);
+  NULL, 0, , agent_handle);
if (ret != EFI_SUCCESS) {
if (ret == EFI_NOT_READY) {
log_notice("Disk %s not ready\n", dev->name);
@@ -627,7 +618,7 @@ static int efi_disk_create_part(struct udevice *dev, 
efi_handle_t agent_handle)
return -1;
dp_parent = (struct efi_device_path *)handler->protocol_interface;

-   ret = efi_disk_add_dev(parent, dp_parent, desc, diskid,
+   ret = efi_disk_add_dev(parent, dp_parent, desc,
   info, part, , agent_handle);
if (ret != EFI_SUCCESS) {
log_err("Adding partition for %s failed\n", dev->name);




Re: [PATCH v3 3/4] net: tftp: remove explicit efi configuration dependency

2023-12-25 Thread Heinrich Schuchardt

On 12/18/23 03:38, AKASHI Takahiro wrote:

Now it is clear that the feature actually depends on efi interfaces,
not "bootefi" command. efi_set_bootdev() will automatically be nullified
if necessary efi component is disabled.

Signed-off-by: AKASHI Takahiro 
---
  net/tftp.c | 10 --
  1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 88e71e67de35..2e335413492b 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -302,12 +302,10 @@ static void tftp_complete(void)
time_start * 1000, "/s");
}
puts("\ndone\n");
-   if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) {
-   if (!tftp_put_active)
-   efi_set_bootdev("Net", "", tftp_filename,
-   map_sysmem(tftp_load_addr, 0),
-   net_boot_file_size);
-   }
+   if (!tftp_put_active)
+   efi_set_bootdev("Net", "", tftp_filename,


Function efi_set_bootdev() will not be compiled for CONFIG_EFI_LOADER=n.
So this change may lead to build failures.

Best regards

Heinrich


+   map_sysmem(tftp_load_addr, 0),
+   net_boot_file_size);
net_set_state(NETLOOP_SUCCESS);
  }





Re: [PATCH v3 1/4] efi_loader: split unrelated code from efi_bootmgr.c

2023-12-25 Thread Heinrich Schuchardt

On 12/18/23 03:38, AKASHI Takahiro wrote:

Some code moved from cmd/bootefi.c is actually necessary only for "bootefi
" command (starting an image manually loaded by a user using U-Boot
load commands or other methods (like JTAG debugger).

The code will never been opted out as unused code by a compiler which
doesn't know how EFI boot manager is implemented. So introduce a new
configuration, CONFIG_EFI_BINARY_EXEC, to enforce theem opted out
explicitly.


We build with -ffunction-sections. The linker removes unreferenced
functions.



Signed-off-by: AKASHI Takahiro 
---
  boot/Kconfig |   4 +-
  cmd/Kconfig  |   6 +-
  include/efi_loader.h |  28 +-
  lib/efi_loader/Kconfig   |   9 +
  lib/efi_loader/efi_bootmgr.c | 493 --
  lib/efi_loader/efi_device_path.c |   3 +-
  lib/efi_loader/efi_helper.c  | 499 ++-


We expect that after each patch we can compile the code. This requires
that the Makefile change is in the same patch as the creation of
efi_helper.c.


  7 files changed, 529 insertions(+), 513 deletions(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index 987ca7314117..8ab7e6f63d34 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -523,7 +523,7 @@ config BOOTMETH_EXTLINUX_PXE

  config BOOTMETH_EFILOADER
bool "Bootdev support for EFI boot"
-   depends on BOOTEFI_BOOTMGR
+   depends on EFI_BINARY_EXEC


Why do we need a symbol CONFIG_EFI_BINARY_EXEC? CONFIG_EFI_LOADER=y
without the ability to execute an EFI binary makes no sense to me.

Best regards

Heinrich


default y
help
  Enables support for EFI boot using bootdevs. This makes the
@@ -558,7 +558,7 @@ config BOOTMETH_DISTRO
select BOOTMETH_SCRIPT if CMDLINE # E.g. Armbian uses scripts
select BOOTMETH_EXTLINUX  # E.g. Debian uses these
select BOOTMETH_EXTLINUX_PXE if CMD_PXE && CMD_NET && DM_ETH
-   select BOOTMETH_EFILOADER if BOOTEFI_BOOTMGR # E.g. Ubuntu uses this
+   select BOOTMETH_EFILOADER if EFI_BINARY_EXEC # E.g. Ubuntu uses this

  config SPL_BOOTMETH_VBE
bool "Bootdev support for Verified Boot for Embedded (SPL)"
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 24bfbe505722..2c993496b70e 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -273,7 +273,7 @@ config CMD_BOOTMETH

  config BOOTM_EFI
bool "Support booting UEFI FIT images"
-   depends on BOOTEFI_BOOTMGR && CMD_BOOTM && FIT
+   depends on EFI_BINARY_EXEC && CMD_BOOTM && FIT
default y
help
  Support booting UEFI FIT images via the bootm command.
@@ -365,7 +365,7 @@ config CMD_BOOTEFI
  if CMD_BOOTEFI
  config CMD_BOOTEFI_BINARY
bool "Allow booting an EFI binary directly"
-   depends on BOOTEFI_BOOTMGR
+   depends on EFI_BINARY_EXEC
default y
help
  Select this option to enable direct execution of binary at 'bootefi'.
@@ -395,7 +395,7 @@ config CMD_BOOTEFI_HELLO_COMPILE

  config CMD_BOOTEFI_HELLO
bool "Allow booting a standard EFI hello world for testing"
-   depends on CMD_BOOTEFI_HELLO_COMPILE
+   depends on CMD_BOOTEFI_BINARY && CMD_BOOTEFI_HELLO_COMPILE
default y if CMD_BOOTEFI_SELFTEST
help
  This adds a standard EFI hello world application to U-Boot so that
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 34e7fbbf1840..484c9fad239f 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -90,11 +90,7 @@ efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len);
   * back to u-boot world
   */
  void efi_restore_gd(void);
-/* Call this to unset the current device name */
-void efi_clear_bootdev(void);
-/* Call this to set the current device name */
-void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
-void *buffer, size_t buffer_size);
+
  /* Called by networking code to memorize the dhcp ack package */
  void efi_net_set_dhcp_ack(void *pkt, int len);
  /* Print information about all loaded images */
@@ -116,10 +112,6 @@ static inline efi_status_t efi_add_runtime_mmio(void 
*mmio_ptr, u64 len)

  /* No loader configured, stub out EFI_ENTRY */
  static inline void efi_restore_gd(void) { }
-static inline void efi_clear_bootdev(void) { }
-static inline void efi_set_bootdev(const char *dev, const char *devnr,
-  const char *path, void *buffer,
-  size_t buffer_size) { }
  static inline void efi_net_set_dhcp_ack(void *pkt, int len) { }
  static inline void efi_print_image_infos(void *pc) { }
  static inline efi_status_t efi_launch_capsules(void)
@@ -129,6 +121,20 @@ static inline efi_status_t efi_launch_capsules(void)

  #endif /* CONFIG_IS_ENABLED(EFI_LOADER) */

+#if CONFIG_IS_ENABLED(EFI_BINARY_EXEC)
+/* Call this to unset the current device name */
+void efi_clear_bootdev(void);
+/* Call this to set the current device name */
+void