Re: [PATCH v2 0/9] Add DM support for atmel NAND driver

2022-08-28 Thread Michael Nazzareno Trimarchi
Hi

On Mon, Aug 29, 2022 at 8:19 AM Balamanikandan Gunasundar
 wrote:
>
> Change include:
>
> - Adapt GPIO descriptor apis for U-Boot. Use
>   gpio_request_by_name_nodev, dm_gpio_get_value etc.
> - Use U_BOOT_DRIVER instead of platform_driver.
> - Replace struct platform_device with struct udevice
> - Check the status of nfc exec operation by polling the status
>   register instead of interrupt based handling
> - DMA operations not supported. Remove it
> - Adapt DT parsing to U-Boot APIs
>
> v2:
>
> - Add linux reference version in the commit message from which the
>   driver is ported from
> - Reword the commit message to describe the changes clearly
>

Thank you to repost it again, I will review it and try to include soon

Michael

> Balamanikandan Gunasundar (9):
>   nand: atmel: Add DM based NAND driver
>   nand: atmel: Add pmecc driver
>   mfd: syscon: Add atmel-matrix registers definition
>   memory: atmel-ebi: add Atmel EBI (External Bus Interface) driver
>   mfd: syscon: atmel-smc: Add driver for atmel SMC
>   configs: at91: sam9x60ek: Enable DM based nand driver
>   ARM: dts: at91: sam9x60: Add nodes for EBI and NAND
>   ARM: dts: at91: sam9x60ek: Enable NAND support
>   board: sam9x60ek: remove nand init from board file
>
>  MAINTAINERS  |1 +
>  arch/arm/dts/sam9x60.dtsi|   42 +
>  arch/arm/dts/sam9x60ek.dts   |  103 +
>  board/atmel/sam9x60ek/sam9x60ek.c|   59 -
>  configs/sam9x60ek_mmc_defconfig  |9 +-
>  configs/sam9x60ek_nandflash_defconfig|9 +-
>  configs/sam9x60ek_qspiflash_defconfig|8 +-
>  drivers/Kconfig  |2 +
>  drivers/Makefile |1 +
>  drivers/memory/Kconfig   |7 +
>  drivers/memory/Makefile  |1 +
>  drivers/memory/atmel_ebi.c   |   37 +
>  drivers/mfd/Kconfig  |4 +
>  drivers/mfd/Makefile |1 +
>  drivers/mfd/atmel-smc.c  |  364 +++
>  drivers/mtd/nand/raw/Kconfig |8 +
>  drivers/mtd/nand/raw/Makefile|1 +
>  drivers/mtd/nand/raw/atmel/Makefile  |5 +
>  drivers/mtd/nand/raw/atmel/nand-controller.c | 2293 ++
>  drivers/mtd/nand/raw/atmel/pmecc.c   |  965 
>  drivers/mtd/nand/raw/atmel/pmecc.h   |   94 +
>  include/configs/sam9x60ek.h  |5 -
>  include/linux/mfd/syscon/atmel-matrix.h  |  112 +
>  include/linux/mfd/syscon/atmel-smc.h |  119 +
>  24 files changed, 4177 insertions(+), 73 deletions(-)
>  create mode 100644 drivers/memory/atmel_ebi.c
>  create mode 100644 drivers/mfd/Kconfig
>  create mode 100644 drivers/mfd/Makefile
>  create mode 100644 drivers/mfd/atmel-smc.c
>  create mode 100644 drivers/mtd/nand/raw/atmel/Makefile
>  create mode 100644 drivers/mtd/nand/raw/atmel/nand-controller.c
>  create mode 100644 drivers/mtd/nand/raw/atmel/pmecc.c
>  create mode 100644 drivers/mtd/nand/raw/atmel/pmecc.h
>  create mode 100644 include/linux/mfd/syscon/atmel-matrix.h
>  create mode 100644 include/linux/mfd/syscon/atmel-smc.h
>
> --
> 2.34.1
>


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

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


[PATCH v2] tee: optee: rework TA bus scanning code

2022-08-28 Thread Ilias Apalodimas
Late versions of OP-TEE support a pseudo bus.  TAs that behave as
hardware blocks (e.g TPM, RNG etc) present themselves on a bus which we can
scan.  Unfortunately U-Boot doesn't support that yet. It's worth noting
that we already have a workaround for RNG.  The details are in
commit 70812bb83da6 ("tee: optee: bind rng optee driver")

So let's add a list of devices based on U-Boot Kconfig options that we will
scan until we properly implement the tee-bus functionality.

While at it change the behaviour of the tee core itself wrt to device
binding.  If some device binding fails, print a warning instead of
disabling OP-TEE.

Signed-off-by: Ilias Apalodimas 
---
Changes since v1:
- remove a macro and use ARRAY_SIZE directly
- print a warning instead of disabling op-tee if a driver binding fails

 drivers/tee/optee/core.c | 23 +++
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index a89d62aaf0b3..3cc92f09d299 100644
--- a/drivers/tee/optee/core.c
+++ b/drivers/tee/optee/core.c
@@ -31,6 +31,18 @@ struct optee_pdata {
optee_invoke_fn *invoke_fn;
 };
 
+static const struct {
+   const char *drv_name;
+   const char *dev_name;
+} optee_bus_probe[] = {
+#ifdef CONFIG_RNG_OPTEE
+   { "optee-rng", "optee-rng" },
+#endif
+#ifdef CONFIG_TPM2_FTPM_TEE
+   { "ftpm-tee", "ftpm-tee" },
+#endif
+};
+
 struct rpc_param {
u32 a0;
u32 a1;
@@ -643,7 +655,7 @@ static int optee_probe(struct udevice *dev)
struct optee_pdata *pdata = dev_get_plat(dev);
u32 sec_caps;
struct udevice *child;
-   int ret;
+   int ret, i;
 
if (!is_optee_api(pdata->invoke_fn)) {
dev_err(dev, "OP-TEE api uid mismatch\n");
@@ -672,10 +684,13 @@ static int optee_probe(struct udevice *dev)
 * in U-Boot, the discovery of TA on the TEE bus is not supported:
 * only bind the drivers associated to the supported OP-TEE TA
 */
-   if (IS_ENABLED(CONFIG_RNG_OPTEE)) {
-   ret = device_bind_driver(dev, "optee-rng", "optee-rng", &child);
+
+   for (i = 0; i < ARRAY_SIZE(optee_bus_probe); i++) {
+   ret = device_bind_driver(dev, optee_bus_probe[i].drv_name,
+optee_bus_probe[i].dev_name, &child);
if (ret)
-   return ret;
+   dev_warn(dev, "Failed to bind device %s\n",
+optee_bus_probe[i].dev_name);
}
 
return 0;
-- 
2.34.1



[PATCH 1/1] usb: request only 8 bytes for USB_SPEED_FULL bMaxPacketSize0 discovery

2022-08-28 Thread Janne Grunau
Fixes probing of various keyboards with DWC3 as integrated into Apple
silicon SoCs. The problem appears to be requesting more data than the
devices's bMaxPacketSize0 of 8. Older Logitech unifying receivers
(bcdDevice 12.03 or 12.10) are for eaxample affected.

Signed-off-by: Janne Grunau 
Tested-by: Thomas Glanzmann 
---
 common/usb.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/common/usb.c b/common/usb.c
index 6fcf1e8428e9..48a310e8599d 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -993,10 +993,12 @@ static int usb_setup_descriptor(struct usb_device *dev, 
bool do_read)
 *
 * At least the DWC2 controller needs to be programmed with
 * the number of packets in addition to the number of bytes.
-* A request for 64 bytes of data with the maxpacket guessed
-* as 64 (above) yields a request for 1 packet.
+* Requesting more than 8 bytes causes probing errors on the
+* DWC3 controller integrated into Apple silicon SoCs with
+* devices with bMaxPacketSize0 of 8. So limit the read request
+* to the used size of 8 bytes.
 */
-   err = get_descriptor_len(dev, 64, 8);
+   err = get_descriptor_len(dev, 8, 8);
if (err)
return err;
}
-- 
2.35.1



Re: [PATCH] nvmem: u-boot-env: fix crc32 casting type

2022-08-28 Thread Ahmad Fatoum
Hello Rafał,

On 18.08.22 06:38, Rafał Miłecki wrote:
> From: Rafał Miłecki 
> 
> This fixes:
> drivers/nvmem/u-boot-env.c:141:17: sparse: sparse: cast to restricted __le32
> 
> Reported-by: kernel test robot 
> Fixes: f955dc1445069 ("nvmem: add driver handling U-Boot environment 
> variables")
> Signed-off-by: Rafał Miłecki 
> ---
>  drivers/nvmem/u-boot-env.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c
> index 9b9abfb8f187..fb993ef4249f 100644
> --- a/drivers/nvmem/u-boot-env.c
> +++ b/drivers/nvmem/u-boot-env.c
> @@ -138,7 +138,7 @@ static int u_boot_env_parse(struct u_boot_env *priv)
>   data_offset = offsetof(struct u_boot_env_image_redundant, data);
>   break;
>   }
> - crc32 = le32_to_cpu(*(uint32_t *)(buf + crc32_offset));
> + crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset));

I had to do a double take to make sure alignment is not violated.
It's not, because crc32_offset is always zero.

How about rewriting this as

  /* CRC32 is always at offset 0 */
  crc32 = le32_to_cpup(buf);

To make the alignment clear to the reader?

>   crc32_data_len = priv->mtd->size - crc32_data_offset;
>   data_len = priv->mtd->size - data_offset;
>  

Cheers,
Ahmad

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


[RFC PATCH 4/8] cyclic: Use schedule() instead of WATCHDOG_RESET()

2022-08-28 Thread Stefan Roese
Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese 
---
 arch/arm/mach-at91/phy.c  |  2 +-
 arch/arm/mach-imx/i2c-mxv7.c  |  2 +-
 arch/arm/mach-socfpga/spl_a10.c   |  8 ++---
 .../cmd_stm32prog/stm32prog_serial.c  |  6 ++--
 arch/m68k/lib/time.c  |  2 +-
 arch/powerpc/cpu/mpc8xx/cpu_init.c|  2 +-
 arch/powerpc/lib/bootm.c  |  6 ++--
 arch/powerpc/lib/cache.c  |  2 +-
 arch/powerpc/lib/interrupts.c |  2 +-
 board/astro/mcf5373l/fpga.c   |  4 +--
 board/dhelectronics/dh_stm32mp1/board.c   |  2 +-
 board/liebherr/display5/spl.c |  2 +-
 board/nokia/rx51/rx51.c   |  2 +-
 board/st/stm32mp1/stm32mp1.c  |  2 +-
 boot/bootretry.c  |  2 +-
 boot/image-board.c|  2 +-
 cmd/fastboot.c|  2 +-
 cmd/mem.c | 16 -
 cmd/usb_mass_storage.c|  2 +-
 cmd/ximg.c|  2 +-
 common/board_f.c  |  4 +--
 common/board_r.c  |  2 +-
 common/cli_readline.c |  4 +--
 common/console.c  |  2 +-
 common/dfu.c  |  2 +-
 common/lcd.c  | 10 +++---
 common/menu.c |  6 ++--
 common/usb_kbd.c  |  2 +-
 common/xyzModem.c |  2 +-
 drivers/block/ide.c   |  8 ++---
 drivers/crypto/aspeed/aspeed_hace.c   |  2 +-
 drivers/crypto/hash/hash_sw.c |  2 +-
 drivers/ddr/altera/sdram_arria10.c|  4 +--
 drivers/ddr/altera/sdram_n5x.c|  4 +--
 drivers/ddr/altera/sdram_soc64.c  |  2 +-
 drivers/fpga/intel_sdm_mb.c   |  8 ++---
 drivers/fpga/socfpga_arria10.c|  8 ++---
 drivers/i2c/mxc_i2c.c |  4 +--
 drivers/mmc/octeontx_hsmmc.c  | 12 +++
 drivers/mmc/sh_mmcif.c|  6 ++--
 drivers/mmc/stm32_sdmmc2.c|  2 +-
 drivers/mtd/cfi_flash.c   |  4 +--
 drivers/mtd/nand/core.c   |  2 +-
 drivers/mtd/nand/raw/atmel_nand.c |  6 ++--
 drivers/mtd/nand/raw/nand_base.c  | 10 +++---
 drivers/mtd/nand/raw/nand_util.c  |  6 ++--
 drivers/mtd/nand/spi/core.c   |  4 +--
 drivers/mtd/onenand/onenand_base.c|  4 +--
 drivers/mtd/spi/spi-nor-core.c|  4 +--
 drivers/net/octeontx2/nix.c   |  2 +-
 drivers/net/octeontx2/nix_af.c| 32 -
 drivers/ram/stm32mp1/stm32mp1_tests.c |  2 +-
 drivers/serial/atmel_usart.c  |  2 +-
 drivers/serial/ns16550.c  |  6 ++--
 drivers/serial/serial-uclass.c|  2 +-
 drivers/serial/serial_bcm283x_mu.c|  2 +-
 drivers/serial/serial_lpuart.c|  8 ++---
 drivers/serial/serial_mpc8xx.c|  4 +--
 drivers/serial/serial_mt7620.c|  2 +-
 drivers/serial/serial_mtk.c   |  4 +--
 drivers/serial/serial_mxc.c   |  6 ++--
 drivers/serial/serial_octeon_bootcmd.c|  2 +-
 drivers/serial/serial_octeon_pcie_console.c   |  4 +--
 drivers/serial/serial_pl01x.c |  8 ++---
 drivers/serial/serial_sifive.c|  2 +-
 drivers/serial/serial_zynq.c  |  2 +-
 drivers/spi/mtk_snfi_spi.c|  2 +-
 drivers/spi/octeon_spi.c  |  2 +-
 drivers/spi/stm32_qspi.c  |  2 +-
 drivers/timer/mpc83xx_timer.c |  4 +--
 drivers/usb/eth/lan7x.h   |  4 +--
 drivers/usb/gadget/f_acm.c|  4 +--
 drivers/usb/gadget/f_sdp.c|  4 +--
 drivers/usb/host/ehci-hcd.c   |  2 +-
 drivers/usb/musb-new/musb_uboot.c |  2 +-
 drivers/video/video_bmp.c |  4 +--
 env/common.c  |  2 +-
 fs/cramfs/uncompress.c|  3 +-
 fs/jffs2/jffs2_1pass.c|  2 +-
 include/linux/compat.h|  2 +-
 include/wait_bit.h|  2 +-
 include/watchdog.h|  8 -
 lib/bzip2/bzlib.c |  2 +-
 lib/bzip2/bzlib_decompress.c  |  8 ++---
 lib/crc32.c   |  2 +-
 lib/efi_loader/efi_boottime.c |  4 +

[RFC PATCH 7/8] watchdog: Further cleanup

2022-08-28 Thread Stefan Roese
Remove some now unused macros and #ifdef's.

Signed-off-by: Stefan Roese 
---
 include/watchdog.h | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/include/watchdog.h b/include/watchdog.h
index 91506d3327a8..ac5f11e376fa 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -10,7 +10,6 @@
 #ifndef _WATCHDOG_H_
 #define _WATCHDOG_H_
 
-#if !defined(__ASSEMBLY__)
 #include 
 
 /*
@@ -20,7 +19,6 @@
  * and the legacy arch//board.c code.
  */
 int init_func_watchdog_reset(void);
-#endif
 
 #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
 #define INIT_FUNC_WATCHDOG_INITinit_func_watchdog_init,
@@ -38,11 +36,11 @@ int init_func_watchdog_reset(void);
  * Prototypes from $(CPU)/cpu.c.
  */
 
-#if (defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)) && 
!defined(__ASSEMBLY__)
+#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
void hw_watchdog_init(void);
 #endif
 
-#if defined(CONFIG_MPC85xx) && !defined(__ASSEMBLY__)
+#if defined(CONFIG_MPC85xx)
void init_85xx_watchdog(void);
 #endif
 #endif /* _WATCHDOG_H_ */
-- 
2.37.2



[RFC PATCH 8/8] WIP: .azure-pipelines.yml: Remove evb-ast2600

2022-08-28 Thread Stefan Roese
The evb-ast2600 target always runs into an timeout error when run via
Azure CI. For test purpose only, this patch removes this CI build
target so that the world build can be run.

Joel, Chia-Wei, could you perhaps take a look at this and help to fix
the problems that I'm seeing with this build target here?

Signed-off-by: Stefan Roese 
Cc: Joel Stanley 
Cc: Chia-Wei Wang 
---
 .azure-pipelines.yml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index 0fa92479b4c4..e48f1667f8de 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -261,9 +261,6 @@ stages:
 evb_ast2500:
   TEST_PY_BD: "evb-ast2500"
   TEST_PY_ID: "--id qemu"
-evb_ast2600:
-  TEST_PY_BD: "evb-ast2600"
-  TEST_PY_ID: "--id qemu"
 vexpress_ca9x4:
   TEST_PY_BD: "vexpress_ca9x4"
   TEST_PY_ID: "--id qemu"
-- 
2.37.2



[RFC PATCH 5/8] watchdog: Get rid of ASSEMBLY hacks

2022-08-28 Thread Stefan Roese
Only one occurance of WATCHDOG_RESET is left in one assembler file.
This patch changes this occurance to a direct call to watchdog_reset
and then removes all the ASSEMBLY ifdef'ery in watchdog.h, as it's not
needed any more to clean this mess a bit up.

Signed-off-by: Stefan Roese 
---
 arch/powerpc/lib/ticks.S |  5 ++--
 include/watchdog.h   | 50 +---
 2 files changed, 19 insertions(+), 36 deletions(-)

diff --git a/arch/powerpc/lib/ticks.S b/arch/powerpc/lib/ticks.S
index c487f938fa8d..8647d77cc9ad 100644
--- a/arch/powerpc/lib/ticks.S
+++ b/arch/powerpc/lib/ticks.S
@@ -9,7 +9,6 @@
 #include 
 #include 
 #include 
-#include 
 
 /*
  * unsigned long long get_ticks(void);
@@ -42,7 +41,9 @@ wait_ticks:
addcr14, r4, r14/* Compute end time lower */
addze   r15, r3 /* and end time upper */
 
-   WATCHDOG_RESET  /* Trigger watchdog, if needed */
+#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
+   bl  schedule/* Trigger watchdog, if needed */
+#endif
 1: bl  get_ticks   /* Get current time */
subfc   r4, r4, r14 /* Subtract current time from end time */
subfe.  r3, r3, r15
diff --git a/include/watchdog.h b/include/watchdog.h
index 7a09346a0959..1365b154a295 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -38,54 +38,36 @@ int init_func_watchdog_reset(void);
  * Hardware watchdog
  */
 #ifdef CONFIG_HW_WATCHDOG
-   #if defined(__ASSEMBLY__)
-   #define WATCHDOG_RESET bl hw_watchdog_reset
-   #else
-   extern void hw_watchdog_reset(void);
+   extern void hw_watchdog_reset(void);
 
-   #define WATCHDOG_RESET hw_watchdog_reset
-   #endif /* __ASSEMBLY__ */
+   #define WATCHDOG_RESET hw_watchdog_reset
 #else
/*
 * Maybe a software watchdog?
 */
#if defined(CONFIG_WATCHDOG)
-   #if defined(__ASSEMBLY__)
-   /* Don't require the watchdog to be enabled in SPL */
-   #if defined(CONFIG_SPL_BUILD) &&\
-   !defined(CONFIG_SPL_WATCHDOG)
-   #define WATCHDOG_RESET /*XXX 
DO_NOT_DEL_THIS_COMMENT*/
-   #else
-   #define WATCHDOG_RESET bl watchdog_reset
-   #endif
+   /* Don't require the watchdog to be enabled in SPL */
+   #if defined(CONFIG_SPL_BUILD) &&\
+   !defined(CONFIG_SPL_WATCHDOG)
+   #define WATCHDOG_RESET() { \
+   cyclic_run(); \
+   }
#else
-   /* Don't require the watchdog to be enabled in SPL */
-   #if defined(CONFIG_SPL_BUILD) &&\
-   !defined(CONFIG_SPL_WATCHDOG)
-   #define WATCHDOG_RESET() { \
-   cyclic_run(); \
-   }
-   #else
-   extern void watchdog_reset(void);
+   extern void watchdog_reset(void);
 
-   #define WATCHDOG_RESET() { \
-   watchdog_reset(); \
-   cyclic_run(); \
-   }
-   #endif
+   #define WATCHDOG_RESET() { \
+   watchdog_reset(); \
+   cyclic_run(); \
+   }
#endif
#else
/*
 * No hardware or software watchdog.
 */
-   #if defined(__ASSEMBLY__)
-   #define WATCHDOG_RESET /*XXX DO_NOT_DEL_THIS_COMMENT*/
-   #else
-   #define WATCHDOG_RESET() { \
-   cyclic_run(); \
+   #define WATCHDOG_RESET() { \
+   cyclic_run(); \
}
-   #endif /* __ASSEMBLY__ */
-   #endif /* CONFIG_WATCHDOG && !__ASSEMBLY__ */
+   #endif /* CONFIG_WATCHDOG */
 #endif /* CONFIG_HW_WATCHDOG */
 
 /*
-- 
2.37.2



[RFC PATCH 6/8] watchdog: Remove WATCHDOG_RESET macro

2022-08-28 Thread Stefan Roese
Now that we've globally replaced all WATCHDOG_RESET occurances, let's
remove the ugly macro itself in the header.

Signed-off-by: Stefan Roese 
---
 include/watchdog.h | 36 
 1 file changed, 36 deletions(-)

diff --git a/include/watchdog.h b/include/watchdog.h
index 1365b154a295..91506d3327a8 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -34,42 +34,6 @@ int init_func_watchdog_reset(void);
 #  error "Configuration error: CONFIG_HW_WATCHDOG and CONFIG_WATCHDOG can't be 
used together."
 #endif
 
-/*
- * Hardware watchdog
- */
-#ifdef CONFIG_HW_WATCHDOG
-   extern void hw_watchdog_reset(void);
-
-   #define WATCHDOG_RESET hw_watchdog_reset
-#else
-   /*
-* Maybe a software watchdog?
-*/
-   #if defined(CONFIG_WATCHDOG)
-   /* Don't require the watchdog to be enabled in SPL */
-   #if defined(CONFIG_SPL_BUILD) &&\
-   !defined(CONFIG_SPL_WATCHDOG)
-   #define WATCHDOG_RESET() { \
-   cyclic_run(); \
-   }
-   #else
-   extern void watchdog_reset(void);
-
-   #define WATCHDOG_RESET() { \
-   watchdog_reset(); \
-   cyclic_run(); \
-   }
-   #endif
-   #else
-   /*
-* No hardware or software watchdog.
-*/
-   #define WATCHDOG_RESET() { \
-   cyclic_run(); \
-   }
-   #endif /* CONFIG_WATCHDOG */
-#endif /* CONFIG_HW_WATCHDOG */
-
 /*
  * Prototypes from $(CPU)/cpu.c.
  */
-- 
2.37.2



[RFC PATCH 3/8] cyclic: Introduce schedule() function

2022-08-28 Thread Stefan Roese
This patch introduces a schedule() function, which shall be used instead
of the old WATCHDOG_RESET. Follow-up patches will make sure, that this
new function is used.

Signed-off-by: Stefan Roese 
---
 common/cyclic.c  | 11 +++
 include/cyclic.h |  5 +
 2 files changed, 16 insertions(+)

diff --git a/common/cyclic.c b/common/cyclic.c
index 766a98382596..6402af4542e9 100644
--- a/common/cyclic.c
+++ b/common/cyclic.c
@@ -20,6 +20,8 @@ struct list_head cyclic_list;
 static bool cyclic_ready;
 static bool cyclic_running;
 
+void hw_watchdog_reset(void);
+
 struct cyclic_info *cyclic_register(cyclic_func_t func, uint64_t delay_us,
const char *name, void *ctx)
 {
@@ -93,6 +95,15 @@ void cyclic_run(void)
cyclic_running = false;
 }
 
+void schedule(void)
+{
+   /* The HW watchdog is not integrated into the cyclic IF (yet) */
+   if (IS_ENABLED(CONFIG_HW_WATCHDOG))
+   hw_watchdog_reset();
+
+   cyclic_run();
+}
+
 int cyclic_uninit(void)
 {
struct cyclic_info *cyclic, *tmp;
diff --git a/include/cyclic.h b/include/cyclic.h
index 2ae1cba32f20..5cea3fb3e9b4 100644
--- a/include/cyclic.h
+++ b/include/cyclic.h
@@ -78,6 +78,7 @@ int cyclic_init(void);
 int cyclic_uninit(void);
 
 void cyclic_run(void);
+void schedule(void);
 #else
 static inline struct cyclic_info *cyclic_register(cyclic_func_t func,
  uint64_t delay_us,
@@ -96,6 +97,10 @@ static inline void cyclic_run(void)
 {
 }
 
+static inline void schedule(void)
+{
+}
+
 static inline int cyclic_init(void)
 {
return 0;
-- 
2.37.2



[RFC PATCH 2/8] watchdog: Integrate watchdog triggering into the cyclic framework

2022-08-28 Thread Stefan Roese
This patch integrates the watchdog triggering into the recently added
cyclic infrastructure. Each watchdog device that shall be triggered
registers it's own cyclic function. This way, multiple watchdog devices
are still supported, each via a cyclic function with separate trigger
intervals.

Signed-off-by: Stefan Roese 
---
 drivers/watchdog/Kconfig  |  2 +
 drivers/watchdog/wdt-uclass.c | 80 +--
 2 files changed, 50 insertions(+), 32 deletions(-)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 50e6a1efba51..e55deaf906b5 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -3,6 +3,7 @@ menu "Watchdog Timer Support"
 config WATCHDOG
bool "Enable U-Boot watchdog reset"
depends on !HW_WATCHDOG
+   select CYCLIC
help
  This option enables U-Boot watchdog support where U-Boot is using
  watchdog_reset function to service watchdog device in U-Boot. Enable
@@ -74,6 +75,7 @@ config WDT
bool "Enable driver model for watchdog timer drivers"
depends on DM
imply WATCHDOG
+   select CYCLIC
help
  Enable driver model for watchdog timer. At the moment the API
  is very simple and only supports four operations:
diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c
index dbf556467d3c..1bf1298d0ecf 100644
--- a/drivers/watchdog/wdt-uclass.c
+++ b/drivers/watchdog/wdt-uclass.c
@@ -6,6 +6,7 @@
 #define LOG_CATEGORY UCLASS_WDT
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -38,8 +39,33 @@ struct wdt_priv {
bool running;
/* No autostart */
bool noautostart;
+
+   struct cyclic_info *cyclic;
 };
 
+static void wdt_cyclic(void *ctx)
+{
+   struct udevice *dev = ctx;
+   struct wdt_priv *priv;
+   struct uclass *uc;
+
+   /* Exit if GD is not ready or watchdog is not initialized yet */
+   if (!gd || !(gd->flags & GD_FLG_WDT_READY))
+   return;
+
+   if (uclass_get(UCLASS_WDT, &uc))
+   return;
+
+   if (!device_active(dev))
+   return;
+
+   priv = dev_get_uclass_priv(dev);
+   if (!priv->running)
+   return;
+
+   wdt_reset(dev);
+}
+
 static void init_watchdog_dev(struct udevice *dev)
 {
struct wdt_priv *priv;
@@ -64,9 +90,6 @@ static void init_watchdog_dev(struct udevice *dev)
printf("WDT:   Failed to start %s\n", dev->name);
return;
}
-
-   printf("WDT:   Started %s with%s servicing (%ds timeout)\n", dev->name,
-  IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", priv->timeout);
 }
 
 int initr_watchdog(void)
@@ -105,8 +128,28 @@ int wdt_start(struct udevice *dev, u64 timeout_ms, ulong 
flags)
ret = ops->start(dev, timeout_ms, flags);
if (ret == 0) {
struct wdt_priv *priv = dev_get_uclass_priv(dev);
+   char str[16];
 
priv->running = true;
+
+   memset(str, 0, 16);
+   if (IS_ENABLED(CONFIG_WATCHDOG)) {
+   /* Register the watchdog driver as a cyclic function */
+   priv->cyclic = cyclic_register(wdt_cyclic,
+  priv->reset_period * 
1000,
+  dev->name, dev);
+   if (!priv->cyclic) {
+   printf("cyclic_register for %s failed\n",
+  dev->name);
+   } else {
+   snprintf(str, 16, "all %ldms",
+priv->reset_period);
+   }
+   }
+
+   printf("WDT:   Started %s with%s servicing %s (%ds timeout)\n",
+  dev->name, IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out",
+  str, priv->timeout);
}
 
return ret;
@@ -194,37 +237,10 @@ int wdt_expire_now(struct udevice *dev, ulong flags)
  */
 void watchdog_reset(void)
 {
-   struct wdt_priv *priv;
-   struct udevice *dev;
-   struct uclass *uc;
-   ulong now;
-
-   /* Exit if GD is not ready or watchdog is not initialized yet */
-   if (!gd || !(gd->flags & GD_FLG_WDT_READY))
-   return;
-
-   if (uclass_get(UCLASS_WDT, &uc))
-   return;
-
/*
-* All devices bound to the wdt uclass should have been probed
-* in initr_watchdog(). But just in case something went wrong,
-* check device_active() before accessing the uclass private
-* data.
+* Empty function for now. The actual WDT handling is now done in
+* the cyclic function instead.
 */
-   uclass_foreach_dev(dev, uc) {
-   if (!device_active(dev))
-   continue;
-   priv = dev_get_uclass_priv(dev);
-   if (!priv->runni

[RFC PATCH 0/8] Migrate watchdog reset to cyclic infrastructure

2022-08-28 Thread Stefan Roese
This patchset migrates the watchdog triggering (WATCHDOG_RESET calls)
to the newly introduced cyclic execution framework. For this, the
watchdog driver now registers a cyclic execution function for each
WDT device that needs to get serviced. Additionally the cyclic IF is
a bit extended to also support the CONFIG_HW_WATCHDOG users. It might
make sense to deprecate this HW_WATCHDOG usage at some point.

Please note that this migration work is based on the cyclic execution
infrastructure, which I posted in the last few weeks. So these cyclic
patches need to be applied for this migration to work.

Please also note that I'm currently seeing Azure CI build issues with
the "test.ph evb_ast2600" build target, which runs into a timeout. I've
temporarily removed this target from the Azure CI builds, so that the
world build can continue to run. Hopefully I will get some hints /
assistance to fix this specific issue.

Some further cleanup and improvements are possible after this patch.
E.g. Heinrich mentioned that the WATCHDOG_RESET call locations need to
get improved / changed in some places.

I've pushed a working branch here for anyone who wants to do some
testing with this patchset:

https://source.denx.de/u-boot/custodians/u-boot-watchdog/-/commits/watchdog-migration-to-cyclic-v1-2022-08-29

Here the log from octeon_ebb7304 compiled on this branch:

U-Boot 2022.10-rc3-00063-g1050cb3e6d8e (Aug 29 2022 - 07:57:07 +0200)

SoC:   Octeon CN73xx (16 cores)
Model: cavium,ebb7304
DRAM:  256 MiB (16 GiB total)
Core:  31 devices, 24 uclasses, devicetree: separate
WDT:   Started interrupt-controller@10100 with servicing all 1000ms 
(60s timeout)
Flash: 8 MiB
MMC:   octeontx-mmc0: 0, octeontx-mmc1: 1
Loading Environment from Flash... OK
QLM 0: PCIe gen3 root complex, x4 lanes
QLM 2: SGMII
QLM 3: XLAUI
QLM 5: SGMII
Net:   eth0: ethernet-mac-nexus@11800e000
=> cyclic list
function: interrupt-controller@10100, cpu-time: 4 us, frequency: 1.11 
times/s
=> wdt list
interrupt-controller@10100 (wdt_octeontx)

Any comments and suggestions are welcome.

Thanks,
Stefan

Stefan Roese (8):
  cmd/cyclic: Use div64 macros for division and remainder
  watchdog: Integrate watchdog triggering into the cyclic framework
  cyclic: Introduce schedule() function
  cyclic: Use schedule() instead of WATCHDOG_RESET()
  watchdog: Get rid of ASSEMBLY hacks
  watchdog: Remove WATCHDOG_RESET macro
  watchdog: Further cleanup
  WIP: .azure-pipelines.yml: Remove evb-ast2600

 .azure-pipelines.yml  |  3 -
 arch/arm/mach-at91/phy.c  |  2 +-
 arch/arm/mach-imx/i2c-mxv7.c  |  2 +-
 arch/arm/mach-socfpga/spl_a10.c   |  8 +-
 .../cmd_stm32prog/stm32prog_serial.c  |  6 +-
 arch/m68k/lib/time.c  |  2 +-
 arch/powerpc/cpu/mpc8xx/cpu_init.c|  2 +-
 arch/powerpc/lib/bootm.c  |  6 +-
 arch/powerpc/lib/cache.c  |  2 +-
 arch/powerpc/lib/interrupts.c |  2 +-
 arch/powerpc/lib/ticks.S  |  5 +-
 board/astro/mcf5373l/fpga.c   |  4 +-
 board/dhelectronics/dh_stm32mp1/board.c   |  2 +-
 board/liebherr/display5/spl.c |  2 +-
 board/nokia/rx51/rx51.c   |  2 +-
 board/st/stm32mp1/stm32mp1.c  |  2 +-
 boot/bootretry.c  |  2 +-
 boot/image-board.c|  2 +-
 cmd/cyclic.c  |  7 +-
 cmd/fastboot.c|  2 +-
 cmd/mem.c | 16 ++--
 cmd/usb_mass_storage.c|  2 +-
 cmd/ximg.c|  2 +-
 common/board_f.c  |  4 +-
 common/board_r.c  |  2 +-
 common/cli_readline.c |  4 +-
 common/console.c  |  2 +-
 common/cyclic.c   | 11 +++
 common/dfu.c  |  2 +-
 common/lcd.c  | 10 +--
 common/menu.c |  6 +-
 common/usb_kbd.c  |  2 +-
 common/xyzModem.c |  2 +-
 drivers/block/ide.c   |  8 +-
 drivers/crypto/aspeed/aspeed_hace.c   |  2 +-
 drivers/crypto/hash/hash_sw.c |  2 +-
 drivers/ddr/altera/sdram_arria10.c|  4 +-
 drivers/ddr/altera/sdram_n5x.c|  4 +-
 drivers/ddr/altera/sdram_soc64.c  |  2 +-
 drivers/fpga/intel_sdm_mb.c   |  8 +-
 drivers/fpga/socfpga_arria10.c|  8 +-
 drivers/i2c/mxc_i2c.c |  4 +-
 drivers/mmc/octeontx_hsmmc.c  | 12 +--
 drivers/mmc/sh_mmcif.c|  6 +-
 drivers/mmc/stm32_sdmmc2.c|  2 +-
 drivers/mtd/cfi_flash.

[RFC PATCH 1/8] cmd/cyclic: Use div64 macros for division and remainder

2022-08-28 Thread Stefan Roese
Use the do_div etc for divisions to fix the compile breakage seen on
edison:

cmd/cyclic.c:70: undefined reference to `__udivmoddi4'

and for e.g. MIPS netgear_cg3100d_ram:

cmd/cyclic.c:(.text.do_cyclic_list+0x180): undefined reference to `__umoddi3'

Signed-off-by: Stefan Roese 
---
 cmd/cyclic.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/cmd/cyclic.c b/cmd/cyclic.c
index d936f3b8d099..6d14c22e4215 100644
--- a/cmd/cyclic.c
+++ b/cmd/cyclic.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -67,10 +68,10 @@ static int do_cyclic_list(struct cmd_tbl *cmdtp, int flag, 
int argc,
 
list_for_each_entry_safe(cyclic, tmp, &cyclic_list, list) {
cnt = cyclic->run_cnt * 100ULL * 100ULL;
-   freq = cnt / (timer_get_us() - cyclic->start_time_us);
-   printf("function: %s, cpu-time: %lld us, frequency: %lld.%02lld 
times/s\n",
+   freq = lldiv(cnt, timer_get_us() - cyclic->start_time_us);
+   printf("function: %s, cpu-time: %lld us, frequency: %lld.%02d 
times/s\n",
   cyclic->name, cyclic->cpu_time_us,
-  freq / 100, freq % 100);
+  lldiv(freq, 100), do_div(freq, 100));
}
 
return 0;
-- 
2.37.2



[PATCH v2 9/9] board: sam9x60ek: remove nand init from board file

2022-08-28 Thread Balamanikandan Gunasundar
Move this out of board file as this is done by the DM based NAND flash
driver. The EBI chip select configuration, iomux and timings are
handled by the driver

Signed-off-by: Balamanikandan Gunasundar 

---
 board/atmel/sam9x60ek/sam9x60ek.c | 59 ---
 include/configs/sam9x60ek.h   |  5 ---
 2 files changed, 64 deletions(-)

diff --git a/board/atmel/sam9x60ek/sam9x60ek.c 
b/board/atmel/sam9x60ek/sam9x60ek.c
index 7035fab878..d8d2c3a18f 100644
--- a/board/atmel/sam9x60ek/sam9x60ek.c
+++ b/board/atmel/sam9x60ek/sam9x60ek.c
@@ -24,62 +24,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 void at91_prepare_cpu_var(void);
 
-#ifdef CONFIG_CMD_NAND
-static void sam9x60ek_nand_hw_init(void)
-{
-   struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
-   struct atmel_sfr *sfr = (struct atmel_sfr *)ATMEL_BASE_SFR;
-   unsigned int csa;
-
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 0, 1);   /* NAND OE */
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 1, 1);   /* NAND WE */
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 2, 0);   /* NAND ALE */
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 3, 0);   /* NAND CLE */
-   /* Enable NandFlash */
-   at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
-   /* Configure RDY/BSY */
-   at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 6, 1);
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 7, 1);
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 8, 1);
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 9, 1);
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 10, 1);
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 11, 1);
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 12, 1);
-   at91_pio3_set_a_periph(AT91_PIO_PORTD, 13, 1);
-
-   at91_periph_clk_enable(ATMEL_ID_PIOD);
-
-   /* Enable CS3 */
-   csa = readl(&sfr->ebicsa);
-   csa |= AT91_SFR_CCFG_EBI_CSA(3, 1) | AT91_SFR_CCFG_NFD0_ON_D16;
-
-   /* Configure IO drive */
-   csa &= ~AT91_SFR_CCFG_EBI_DRIVE_SAM9X60;
-
-   writel(csa, &sfr->ebicsa);
-
-   /* Configure SMC CS3 for NAND/SmartMedia */
-   writel(AT91_SMC_SETUP_NWE(4), &smc->cs[3].setup);
-
-   writel(AT91_SMC_PULSE_NWE(10) | AT91_SMC_PULSE_NCS_WR(20) |
-  AT91_SMC_PULSE_NRD(10) | AT91_SMC_PULSE_NCS_RD(20),
-  &smc->cs[3].pulse);
-
-   writel(AT91_SMC_CYCLE_NWE(20) | AT91_SMC_CYCLE_NRD(20),
-  &smc->cs[3].cycle);
-
-   writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
-#ifdef CONFIG_SYS_NAND_DBW_16
-  AT91_SMC_MODE_DBW_16 |
-#else /* CONFIG_SYS_NAND_DBW_8 */
-  AT91_SMC_MODE_DBW_8 |
-#endif
-  AT91_SMC_MODE_TDF | AT91_SMC_MODE_TDF_CYCLE(15),
-  &smc->cs[3].mode);
-}
-#endif
-
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
@@ -122,9 +66,6 @@ int board_init(void)
/* address of boot parameters */
gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
 
-#ifdef CONFIG_CMD_NAND
-   sam9x60ek_nand_hw_init();
-#endif
return 0;
 }
 
diff --git a/include/configs/sam9x60ek.h b/include/configs/sam9x60ek.h
index b9b56d9f1a..72c089512f 100644
--- a/include/configs/sam9x60ek.h
+++ b/include/configs/sam9x60ek.h
@@ -29,11 +29,6 @@
 /* NAND flash */
 #ifdef CONFIG_CMD_NAND
 #define CONFIG_SYS_MAX_NAND_DEVICE 1
-#define CONFIG_SYS_NAND_BASE   0x4000
-#define CONFIG_SYS_NAND_MASK_ALE   BIT(21)
-#define CONFIG_SYS_NAND_MASK_CLE   BIT(22)
-#define CONFIG_SYS_NAND_ENABLE_PIN AT91_PIN_PD4
-#define CONFIG_SYS_NAND_READY_PIN  AT91_PIN_PD5
 #endif
 
 #endif
-- 
2.34.1



[PATCH v2 8/9] ARM: dts: at91: sam9x60ek: Enable NAND support

2022-08-28 Thread Balamanikandan Gunasundar
Enable the EBI and NAND flash controller. Define the pinctrl and
partition table

Signed-off-by: Balamanikandan Gunasundar 

---
 arch/arm/dts/sam9x60ek.dts | 103 +
 1 file changed, 103 insertions(+)

diff --git a/arch/arm/dts/sam9x60ek.dts b/arch/arm/dts/sam9x60ek.dts
index 54c694bd78..6cb81dd90f 100644
--- a/arch/arm/dts/sam9x60ek.dts
+++ b/arch/arm/dts/sam9x60ek.dts
@@ -80,6 +80,44 @@
};
 
pinctrl {
+   nand {
+   pinctrl_nand_oe_we: 
nand-oe-we-0 {
+   atmel,pins =
+   ;
+   };
+
+   pinctrl_nand_rb: nand-rb-0 {
+   atmel,pins =
+   ;
+   };
+
+   pinctrl_nand_cs: nand-cs-0 {
+   atmel,pins =
+   ;
+   };
+   };
+
+   ebi {
+   pinctrl_ebi_data_0_7: 
ebi-data-lsb-0 {
+   atmel,pins =
+   ;
+   };
+
+   pinctrl_ebi_addr_nand: 
ebi-addr-0 {
+   atmel,pins =
+   ;
+   };
+   };
+
pinctrl_qspi: qspi {
atmel,pins =
;
+   status = "okay";
+
+   nand_controller: nand-controller {
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_nand_oe_we &pinctrl_nand_cs 
&pinctrl_nand_rb>;
+   status = "okay";
+
+   nand@3 {
+   reg = <0x3 0x0 0x80>;
+   rb-gpios = <&pioD 5 GPIO_ACTIVE_HIGH>;
+   cs-gpios = <&pioD 4 GPIO_ACTIVE_HIGH>;
+   nand-bus-width = <8>;
+   nand-ecc-mode = "hw";
+   nand-ecc-strength = <8>;
+   nand-ecc-step-size = <512>;
+   nand-on-flash-bbt;
+   label = "atmel_nand";
+
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   at91bootstrap@0 {
+   label = "at91bootstrap";
+   reg = <0x0 0x4>;
+   };
+
+   uboot@4 {
+   label = "u-boot";
+   reg = <0x4 0xc>;
+   };
+
+   ubootenvred@10 {
+   label = "U-Boot Env Redundant";
+   reg = <0x10 0x4>;
+   };
+
+   ubootenv@14 {
+   label = "U-Boot Env";
+   reg = <0x14 0x4>;
+   };
+
+   dtb@18 {
+   label = "device tree";
+   reg = <0x18 0x8>;
+   };
+
+   kernel@20 {
+   label = "kernel";
+   reg = <0x20 0x60>;
+   };
+
+   rootfs@80 {
+   label = "rootfs";
+   reg = <0x80 0x1f80>;
+   };
+   };
+   };
+   };
+};
+
 &macb0 {
phy-mode = "rmii";
status = "okay";
-- 
2.34.1



[PATCH v2 7/9] ARM: dts: at91: sam9x60: Add nodes for EBI and NAND

2022-08-28 Thread Balamanikandan Gunasundar
Add new bindings for EBI and NAND controller

Signed-off-by: Balamanikandan Gunasundar 

---
 arch/arm/dts/sam9x60.dtsi | 42 +++
 1 file changed, 42 insertions(+)

diff --git a/arch/arm/dts/sam9x60.dtsi b/arch/arm/dts/sam9x60.dtsi
index a5c429eb3a..17224ef771 100644
--- a/arch/arm/dts/sam9x60.dtsi
+++ b/arch/arm/dts/sam9x60.dtsi
@@ -69,6 +69,32 @@
#size-cells = <1>;
ranges;
 
+   ebi: ebi@1000 {
+   compatible = "microchip,sam9x60-ebi";
+   #address-cells = <2>;
+   #size-cells = <1>;
+   atmel,smc = <&smc>;
+   microchip,sfr = <&sfr>;
+   reg = <0x1000 0x6000>;
+   ranges = <0x0 0x0 0x1000 0x1000
+ 0x1 0x0 0x2000 0x1000
+ 0x2 0x0 0x3000 0x1000
+ 0x3 0x0 0x4000 0x1000
+ 0x4 0x0 0x5000 0x1000
+ 0x5 0x0 0x6000 0x1000>;
+   clocks = <&pmc PMC_TYPE_CORE 11>;
+   status = "disabled";
+
+   nand_controller: nand-controller {
+   compatible = 
"microchip,sam9x60-nand-controller";
+   ecc-engine = <&pmecc>;
+   #address-cells = <2>;
+   #size-cells = <1>;
+   ranges;
+   status = "disabled";
+   };
+   };
+
sdhci0: sdhci-host@8000 {
compatible = "microchip,sam9x60-sdhci";
reg = <0x8000 0x300>;
@@ -119,6 +145,11 @@
status = "disabled";
};
 
+   sfr: sfr@f805 {
+   compatible = "microchip,sam9x60-sfr", "syscon";
+   reg = <0xf805 0x100>;
+   };
+
dbgu: serial@f200 {
compatible = "atmel,at91sam9260-dbgu", 
"atmel,at91sam9260-usart";
reg = <0xf200 0x200>;
@@ -182,6 +213,17 @@
};
};
 
+   pmecc: ecc-engine@e000 {
+   compatible = "microchip,sam9x60-pmecc", 
"atmel,at91sam9g45-pmecc";
+   reg = <0xe000 0x300>,
+ <0xe600 0x100>;
+   };
+
+   smc: smc@ea00 {
+   compatible = "microchip,sam9x60-smc", 
"atmel,at91sam9260-smc", "syscon";
+   reg = <0xea00 0x100>;
+   };
+
pioA: gpio@f400 {
compatible = "atmel,at91sam9x5-gpio", 
"atmel,at91rm9200-gpio";
reg = <0xf400 0x200>;
-- 
2.34.1



[PATCH v2 6/9] configs: at91: sam9x60ek: Enable DM based nand driver

2022-08-28 Thread Balamanikandan Gunasundar
Enable Device model supported NAND driver and remove legacy Atmel NAND
driver.

Signed-off-by: Balamanikandan Gunasundar 

---
 configs/sam9x60ek_mmc_defconfig   | 9 ++---
 configs/sam9x60ek_nandflash_defconfig | 9 ++---
 configs/sam9x60ek_qspiflash_defconfig | 8 +---
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/configs/sam9x60ek_mmc_defconfig b/configs/sam9x60ek_mmc_defconfig
index c50aa6b5c5..d989681eb6 100644
--- a/configs/sam9x60ek_mmc_defconfig
+++ b/configs/sam9x60ek_mmc_defconfig
@@ -53,6 +53,8 @@ CONFIG_ENV_IS_IN_FAT=y
 CONFIG_ENV_FAT_DEVICE_AND_PART="0:1"
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_CLK=y
 CONFIG_CLK_CCF=y
 CONFIG_CLK_AT91=y
@@ -62,15 +64,16 @@ CONFIG_CPU=y
 CONFIG_AT91_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_AT91=y
+CONFIG_ATMEL_EBI=y
+CONFIG_MFD_ATMEL_SMC=y
 CONFIG_I2C_EEPROM=y
 CONFIG_MICROCHIP_FLEXCOM=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_ATMEL=y
 CONFIG_MTD=y
+CONFIG_DM_MTD=y
 CONFIG_MTD_RAW_NAND=y
-CONFIG_NAND_ATMEL=y
-CONFIG_ATMEL_NAND_HW_PMECC=y
-CONFIG_PMECC_CAP=8
+CONFIG_DM_NAND_ATMEL=y
 CONFIG_SYS_NAND_ONFI_DETECTION=y
 CONFIG_DM_SPI_FLASH=y
 CONFIG_SF_DEFAULT_SPEED=5000
diff --git a/configs/sam9x60ek_nandflash_defconfig 
b/configs/sam9x60ek_nandflash_defconfig
index d8d2383fed..6bc78a73e2 100644
--- a/configs/sam9x60ek_nandflash_defconfig
+++ b/configs/sam9x60ek_nandflash_defconfig
@@ -55,6 +55,8 @@ CONFIG_ENV_IS_IN_NAND=y
 CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_CLK=y
 CONFIG_CLK_CCF=y
 CONFIG_CLK_AT91=y
@@ -64,14 +66,15 @@ CONFIG_CPU=y
 CONFIG_AT91_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_AT91=y
+CONFIG_ATMEL_EBI=y
+CONFIG_MFD_ATMEL_SMC=y
 CONFIG_I2C_EEPROM=y
 CONFIG_MICROCHIP_FLEXCOM=y
 CONFIG_GENERIC_ATMEL_MCI=y
 CONFIG_MTD=y
+CONFIG_DM_MTD=y
 # CONFIG_SYS_NAND_USE_FLASH_BBT is not set
-CONFIG_NAND_ATMEL=y
-CONFIG_ATMEL_NAND_HW_PMECC=y
-CONFIG_PMECC_CAP=8
+CONFIG_DM_NAND_ATMEL=y
 CONFIG_SYS_NAND_ONFI_DETECTION=y
 CONFIG_DM_SPI_FLASH=y
 CONFIG_SF_DEFAULT_SPEED=5000
diff --git a/configs/sam9x60ek_qspiflash_defconfig 
b/configs/sam9x60ek_qspiflash_defconfig
index fc4108cdc4..c17722ab35 100644
--- a/configs/sam9x60ek_qspiflash_defconfig
+++ b/configs/sam9x60ek_qspiflash_defconfig
@@ -55,6 +55,8 @@ CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_ENV_SPI_MAX_HZ=5000
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_CLK=y
 CONFIG_CLK_CCF=y
 CONFIG_CLK_AT91=y
@@ -64,6 +66,8 @@ CONFIG_CPU=y
 CONFIG_AT91_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_AT91=y
+CONFIG_ATMEL_EBI=y
+CONFIG_MFD_ATMEL_SMC=y
 CONFIG_I2C_EEPROM=y
 CONFIG_MICROCHIP_FLEXCOM=y
 CONFIG_GENERIC_ATMEL_MCI=y
@@ -71,9 +75,7 @@ CONFIG_MTD=y
 CONFIG_DM_MTD=y
 CONFIG_MTD_RAW_NAND=y
 # CONFIG_SYS_NAND_USE_FLASH_BBT is not set
-CONFIG_NAND_ATMEL=y
-CONFIG_ATMEL_NAND_HW_PMECC=y
-CONFIG_PMECC_CAP=8
+CONFIG_DM_NAND_ATMEL=y
 CONFIG_SYS_NAND_ONFI_DETECTION=y
 CONFIG_DM_SPI_FLASH=y
 CONFIG_SPI_FLASH_MACRONIX=y
-- 
2.34.1



[PATCH v2 5/9] mfd: syscon: atmel-smc: Add driver for atmel SMC

2022-08-28 Thread Balamanikandan Gunasundar
Add driver for atmel Static Memory Controller. Add helper functions to
configure SMC. This file is inherited from the work done by Boris
Brezillon for Linux

Signed-off-by: Balamanikandan Gunasundar 

---
 drivers/Kconfig  |   2 +
 drivers/Makefile |   1 +
 drivers/mfd/Kconfig  |   4 +
 drivers/mfd/Makefile |   1 +
 drivers/mfd/atmel-smc.c  | 364 +++
 include/linux/mfd/syscon/atmel-smc.h | 119 +
 6 files changed, 491 insertions(+)
 create mode 100644 drivers/mfd/Kconfig
 create mode 100644 drivers/mfd/Makefile
 create mode 100644 drivers/mfd/atmel-smc.c
 create mode 100644 include/linux/mfd/syscon/atmel-smc.h

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 8b6fead351..ffc06ed65e 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -60,6 +60,8 @@ source "drivers/mailbox/Kconfig"
 
 source "drivers/memory/Kconfig"
 
+source "drivers/mfd/Kconfig"
+
 source "drivers/misc/Kconfig"
 
 source "drivers/mmc/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index eba9940231..5a8e80d4fe 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -101,6 +101,7 @@ obj-$(CONFIG_QE) += qe/
 obj-$(CONFIG_U_QE) += qe/
 obj-y += mailbox/
 obj-y += memory/
+obj-y += mfd/
 obj-y += mtd/
 obj-y += pwm/
 obj-y += reset/
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
new file mode 100644
index 00..ae53b02f27
--- /dev/null
+++ b/drivers/mfd/Kconfig
@@ -0,0 +1,4 @@
+config MFD_ATMEL_SMC
+   bool "Atmel Static Memory Controller driver"
+   help
+   Say yes here to support Atmel Static Memory Controller driver.
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
new file mode 100644
index 00..4454815a98
--- /dev/null
+++ b/drivers/mfd/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_MFD_ATMEL_SMC) += atmel-smc.o
diff --git a/drivers/mfd/atmel-smc.c b/drivers/mfd/atmel-smc.c
new file mode 100644
index 00..15296f71a1
--- /dev/null
+++ b/drivers/mfd/atmel-smc.c
@@ -0,0 +1,364 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Atmel SMC (Static Memory Controller) helper functions.
+ *
+ * Copyright (C) 2022 Microchip Technology Inc.
+ * Copyright (C) 2017 Free Electrons
+ *
+ * Author: Boris Brezillon 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * atmel_smc_cs_conf_init - initialize a SMC CS conf
+ * @conf: the SMC CS conf to initialize
+ *
+ * Set all fields to 0 so that one can start defining a new config.
+ */
+void atmel_smc_cs_conf_init(struct atmel_smc_cs_conf *conf)
+{
+   memset(conf, 0, sizeof(*conf));
+}
+EXPORT_SYMBOL_GPL(atmel_smc_cs_conf_init);
+
+/**
+ * atmel_smc_cs_encode_ncycles - encode a number of MCK clk cycles in the
+ *  format expected by the SMC engine
+ * @ncycles: number of MCK clk cycles
+ * @msbpos: position of the MSB part of the timing field
+ * @msbwidth: width of the MSB part of the timing field
+ * @msbfactor: factor applied to the MSB
+ * @encodedval: param used to store the encoding result
+ *
+ * This function encodes the @ncycles value as described in the datasheet
+ * (section "SMC Setup/Pulse/Cycle/Timings Register"). This is a generic
+ * helper which called with different parameter depending on the encoding
+ * scheme.
+ *
+ * If the @ncycles value is too big to be encoded, -ERANGE is returned and
+ * the encodedval is contains the maximum val. Otherwise, 0 is returned.
+ */
+static int atmel_smc_cs_encode_ncycles(unsigned int ncycles,
+  unsigned int msbpos,
+  unsigned int msbwidth,
+  unsigned int msbfactor,
+  unsigned int *encodedval)
+{
+   unsigned int lsbmask = GENMASK(msbpos - 1, 0);
+   unsigned int msbmask = GENMASK(msbwidth - 1, 0);
+   unsigned int msb, lsb;
+   int ret = 0;
+
+   msb = ncycles / msbfactor;
+   lsb = ncycles % msbfactor;
+
+   if (lsb > lsbmask) {
+   lsb = 0;
+   msb++;
+   }
+
+   /*
+* Let's just put the maximum we can if the requested setting does
+* not fit in the register field.
+* We still return -ERANGE in case the caller cares.
+*/
+   if (msb > msbmask) {
+   msb = msbmask;
+   lsb = lsbmask;
+   ret = -ERANGE;
+   }
+
+   *encodedval = (msb << msbpos) | lsb;
+
+   return ret;
+}
+
+/**
+ * atmel_smc_cs_conf_set_timing - set the SMC CS conf Txx parameter to a
+ *   specific value
+ * @conf: SMC CS conf descriptor
+ * @shift: the position of the Txx field in the TIMINGS register
+ * @ncycles: value (expressed in MCK clk cycles) to assign to this Txx
+ *  parameter
+ *
+ * This function encodes the @ncycles value as described in the datasheet
+ * (section "SMC Timings Register"), and then stores the result in 

[PATCH v2 4/9] memory: atmel-ebi: add Atmel EBI (External Bus Interface) driver

2022-08-28 Thread Balamanikandan Gunasundar
The EBI is used to access peripherals like NAND, SRAM, NOR etc. Add
this driver to probe the nand flash controller. This is a dummy driver
and not yet a complete device driver for EBI.

Signed-off-by: Balamanikandan Gunasundar 

---
 MAINTAINERS|  1 +
 drivers/memory/Kconfig |  7 +++
 drivers/memory/Makefile|  1 +
 drivers/memory/atmel_ebi.c | 37 +
 4 files changed, 46 insertions(+)
 create mode 100644 drivers/memory/atmel_ebi.c

diff --git a/MAINTAINERS b/MAINTAINERS
index fa8c13fc7d..6d3f4c58a0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -386,6 +386,7 @@ T:  git 
https://source.denx.de/u-boot/custodians/u-boot-atmel.git
 F: arch/arm/mach-at91/
 F: board/atmel/
 F: drivers/cpu/at91_cpu.c
+F: drivers/memory/atmel-ebi.c
 F: drivers/misc/microchip_flexcom.c
 F: drivers/timer/atmel_tcb_timer.c
 F: include/dt-bindings/mfd/atmel-flexcom.h
diff --git a/drivers/memory/Kconfig b/drivers/memory/Kconfig
index 7271892763..759151a452 100644
--- a/drivers/memory/Kconfig
+++ b/drivers/memory/Kconfig
@@ -24,4 +24,11 @@ config TI_AEMIF
  of 256M bytes of any of these memories can be accessed at a given
  time via four chip selects with 64M byte access per chip select.
 
+config ATMEL_EBI
+   bool "Support for Atmel EBI"
+   help
+ Driver for Atmel EBI controller. This is a dummy
+ driver. Doesn't provide an access to EBI controller. Select
+ this option to enable the NAND flash controller driver
+
 endmenu
diff --git a/drivers/memory/Makefile b/drivers/memory/Makefile
index fec52efb60..1d24009e86 100644
--- a/drivers/memory/Makefile
+++ b/drivers/memory/Makefile
@@ -1,3 +1,4 @@
 
 obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o
+obj-$(CONFIG_ATMEL_EBI) += atmel_ebi.o
 obj-$(CONFIG_TI_AEMIF) += ti-aemif.o
diff --git a/drivers/memory/atmel_ebi.c b/drivers/memory/atmel_ebi.c
new file mode 100644
index 00..4739eef1b7
--- /dev/null
+++ b/drivers/memory/atmel_ebi.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022 Microchip Technology Inc. and its subsidiaries
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+static int atmel_ebi_probe(struct udevice *dev)
+{
+   int ret;
+   struct udevice *ndev;
+
+   ret = uclass_get_device_by_driver(UCLASS_MTD,
+ DM_DRIVER_GET(atmel_nand_controller),
+ &ndev);
+   if (ret)
+   printf("Failed to probe nand driver (err = %d)\n", ret);
+
+   return ret;
+}
+
+static const struct udevice_id atmel_ebi_match[] = {
+   {.compatible = "microchip,sam9x60-ebi"},
+   {.compatible = "atmel,sama5d3-ebi"},
+   { /* Sentinel */ }
+};
+
+U_BOOT_DRIVER(atmel_ebi) = {
+   .name = "atmel_ebi",
+   .id = UCLASS_NOP,
+   .of_match = atmel_ebi_match,
+   .probe = atmel_ebi_probe,
+   .bind = dm_scan_fdt_dev,
+};
-- 
2.34.1



[PATCH v2 3/9] mfd: syscon: Add atmel-matrix registers definition

2022-08-28 Thread Balamanikandan Gunasundar
This file is copied from Linux. AT91 SoCs have a memory range reserved
for internal bus configuration. Expose those registers so that drivers
can make use of the matrix syscon declared in at91 DTs.

Signed-off-by: Balamanikandan Gunasundar 

---
 include/linux/mfd/syscon/atmel-matrix.h | 112 
 1 file changed, 112 insertions(+)
 create mode 100644 include/linux/mfd/syscon/atmel-matrix.h

diff --git a/include/linux/mfd/syscon/atmel-matrix.h 
b/include/linux/mfd/syscon/atmel-matrix.h
new file mode 100644
index 00..dd228cab67
--- /dev/null
+++ b/include/linux/mfd/syscon/atmel-matrix.h
@@ -0,0 +1,112 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ *  Copyright (C) 2014 Atmel Corporation.
+ *
+ * Memory Controllers (MATRIX, EBI) - System peripherals registers.
+ */
+
+#ifndef _LINUX_MFD_SYSCON_ATMEL_MATRIX_H
+#define _LINUX_MFD_SYSCON_ATMEL_MATRIX_H
+
+#define AT91SAM9260_MATRIX_MCFG0x00
+#define AT91SAM9260_MATRIX_SCFG0x40
+#define AT91SAM9260_MATRIX_PRS 0x80
+#define AT91SAM9260_MATRIX_MRCR0x100
+#define AT91SAM9260_MATRIX_EBICSA  0x11c
+
+#define AT91SAM9261_MATRIX_MRCR0x0
+#define AT91SAM9261_MATRIX_SCFG0x4
+#define AT91SAM9261_MATRIX_TCR 0x24
+#define AT91SAM9261_MATRIX_EBICSA  0x30
+#define AT91SAM9261_MATRIX_USBPUCR 0x34
+
+#define AT91SAM9263_MATRIX_MCFG0x00
+#define AT91SAM9263_MATRIX_SCFG0x40
+#define AT91SAM9263_MATRIX_PRS 0x80
+#define AT91SAM9263_MATRIX_MRCR0x100
+#define AT91SAM9263_MATRIX_TCR 0x114
+#define AT91SAM9263_MATRIX_EBI0CSA 0x120
+#define AT91SAM9263_MATRIX_EBI1CSA 0x124
+
+#define AT91SAM9RL_MATRIX_MCFG 0x00
+#define AT91SAM9RL_MATRIX_SCFG 0x40
+#define AT91SAM9RL_MATRIX_PRS  0x80
+#define AT91SAM9RL_MATRIX_MRCR 0x100
+#define AT91SAM9RL_MATRIX_TCR  0x114
+#define AT91SAM9RL_MATRIX_EBICSA   0x120
+
+#define AT91SAM9G45_MATRIX_MCFG0x00
+#define AT91SAM9G45_MATRIX_SCFG0x40
+#define AT91SAM9G45_MATRIX_PRS 0x80
+#define AT91SAM9G45_MATRIX_MRCR0x100
+#define AT91SAM9G45_MATRIX_TCR 0x110
+#define AT91SAM9G45_MATRIX_DDRMPR  0x118
+#define AT91SAM9G45_MATRIX_EBICSA  0x128
+
+#define AT91SAM9N12_MATRIX_MCFG0x00
+#define AT91SAM9N12_MATRIX_SCFG0x40
+#define AT91SAM9N12_MATRIX_PRS 0x80
+#define AT91SAM9N12_MATRIX_MRCR0x100
+#define AT91SAM9N12_MATRIX_EBICSA  0x118
+
+#define AT91SAM9X5_MATRIX_MCFG 0x00
+#define AT91SAM9X5_MATRIX_SCFG 0x40
+#define AT91SAM9X5_MATRIX_PRS  0x80
+#define AT91SAM9X5_MATRIX_MRCR 0x100
+#define AT91SAM9X5_MATRIX_EBICSA   0x120
+
+#define SAMA5D3_MATRIX_MCFG0x00
+#define SAMA5D3_MATRIX_SCFG0x40
+#define SAMA5D3_MATRIX_PRS 0x80
+#define SAMA5D3_MATRIX_MRCR0x100
+
+#define AT91_MATRIX_MCFG(o, x) ((o) + ((x) * 0x4))
+#define AT91_MATRIX_ULBT   GENMASK(2, 0)
+#define AT91_MATRIX_ULBT_INFINITE  (0 << 0)
+#define AT91_MATRIX_ULBT_SINGLE(1 << 0)
+#define AT91_MATRIX_ULBT_FOUR  (2 << 0)
+#define AT91_MATRIX_ULBT_EIGHT (3 << 0)
+#define AT91_MATRIX_ULBT_SIXTEEN   (4 << 0)
+
+#define AT91_MATRIX_SCFG(o, x) ((o) + ((x) * 0x4))
+#define AT91_MATRIX_SLOT_CYCLE GENMASK(7,  0)
+#define AT91_MATRIX_DEFMSTR_TYPE   GENMASK(17, 16)
+#define AT91_MATRIX_DEFMSTR_TYPE_NONE  (0 << 16)
+#define AT91_MATRIX_DEFMSTR_TYPE_LAST  (1 << 16)
+#define AT91_MATRIX_DEFMSTR_TYPE_FIXED (2 << 16)
+#define AT91_MATRIX_FIXED_DEFMSTR  GENMASK(20, 18)
+#define AT91_MATRIX_ARBT   GENMASK(25, 24)
+#define AT91_MATRIX_ARBT_ROUND_ROBIN   (0 << 24)
+#define AT91_MATRIX_ARBT_FIXED_PRIORITY(1 << 24)
+
+#define AT91_MATRIX_ITCM_SIZE  GENMASK(3, 0)
+#define AT91_MATRIX_ITCM_0 (0 << 0)
+#define AT91_MATRIX_ITCM_16(5 << 0)
+#define AT91_MATRIX_ITCM_32(6 << 0)
+#define AT91_MATRIX_ITCM_64(7 << 0)
+#defineAT91_MATRIX_DTCM_SIZE   GENMASK(7, 4)
+#defineAT91_MATRIX_DTCM_0  (0 << 4)
+#defineAT91_MATRIX_DTCM_16 (5 << 4)
+#define AT91_MATRIX_DTCM_32(6 << 4)
+#define AT91_MATRIX_DTCM_64

[PATCH v2 2/9] nand: atmel: Add pmecc driver

2022-08-28 Thread Balamanikandan Gunasundar
Add driver for atmel pmecc. This implementation is ported from
Linux. The reference taken is linux-5.4-at91.

Signed-off-by: Balamanikandan Gunasundar 

---
 drivers/mtd/nand/raw/atmel/Makefile |   3 +-
 drivers/mtd/nand/raw/atmel/pmecc.c  | 965 
 drivers/mtd/nand/raw/atmel/pmecc.h  |  94 +++
 3 files changed, 1061 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/nand/raw/atmel/pmecc.c
 create mode 100644 drivers/mtd/nand/raw/atmel/pmecc.h

diff --git a/drivers/mtd/nand/raw/atmel/Makefile 
b/drivers/mtd/nand/raw/atmel/Makefile
index 6708416983..e044ff55ba 100644
--- a/drivers/mtd/nand/raw/atmel/Makefile
+++ b/drivers/mtd/nand/raw/atmel/Makefile
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
-obj-$(CONFIG_DM_NAND_ATMEL)+= atmel-nand-controller.o
+obj-$(CONFIG_DM_NAND_ATMEL)+= atmel-nand-controller.o atmel-pmecc.o
 
 atmel-nand-controller-objs := nand-controller.o
+atmel-pmecc-objs   := pmecc.o
diff --git a/drivers/mtd/nand/raw/atmel/pmecc.c 
b/drivers/mtd/nand/raw/atmel/pmecc.c
new file mode 100644
index 00..e2e3f1ee6b
--- /dev/null
+++ b/drivers/mtd/nand/raw/atmel/pmecc.c
@@ -0,0 +1,965 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2017 ATMEL
+ * Copyright 2017 Free Electrons
+ *
+ * Author: Boris Brezillon 
+ *
+ * Derived from the atmel_nand.c driver which contained the following
+ * copyrights:
+ *
+ *   Copyright 2003 Rick Bronson
+ *
+ *   Derived from drivers/mtd/nand/autcpu12.c (removed in v3.8)
+ * Copyright 2001 Thomas Gleixner (gleix...@autronix.de)
+ *
+ *   Derived from drivers/mtd/spia.c (removed in v3.8)
+ * Copyright 2000 Steven J. Hill (sjh...@cotw.com)
+ *
+ *   Add Hardware ECC support for AT91SAM9260 / AT91SAM9263
+ * Richard Genoud (richard.gen...@gmail.com), Adeneo Copyright 2007
+ *
+ *   Derived from Das U-Boot source code
+ * (u-boot-1.1.5/board/atmel/at91sam9263ek/nand.c)
+ *  Copyright 2006 ATMEL Rousset, Lacressonniere Nicolas
+ *
+ *   Add Programmable Multibit ECC support for various AT91 SoC
+ * Copyright 2012 ATMEL, Hong Xu
+ *
+ *   Add Nand Flash Controller support for SAMA5 SoC
+ * Copyright 2013 ATMEL, Josh Wu (josh...@atmel.com)
+ *
+ * The PMECC is an hardware assisted BCH engine, which means part of the
+ * ECC algorithm is left to the software. The hardware/software repartition
+ * is explained in the "PMECC Controller Functional Description" chapter in
+ * Atmel datasheets, and some of the functions in this file are directly
+ * implementing the algorithms described in the "Software Implementation"
+ * sub-section.
+ *
+ * TODO: it seems that the software BCH implementation in lib/bch.c is already
+ * providing some of the logic we are implementing here. It would be smart
+ * to expose the needed lib/bch.c helpers/functions and re-use them here.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "pmecc.h"
+#include 
+#include 
+#include 
+#include 
+
+/* Galois field dimension */
+#define PMECC_GF_DIMENSION_13  13
+#define PMECC_GF_DIMENSION_14  14
+
+/* Primitive Polynomial used by PMECC */
+#define PMECC_GF_13_PRIMITIVE_POLY 0x201b
+#define PMECC_GF_14_PRIMITIVE_POLY 0x4443
+
+#define PMECC_LOOKUP_TABLE_SIZE_5120x2000
+#define PMECC_LOOKUP_TABLE_SIZE_1024   0x4000
+
+/* Time out value for reading PMECC status register */
+#define PMECC_MAX_TIMEOUT_MS   100
+
+/* PMECC Register Definitions */
+#define ATMEL_PMECC_CFG0x0
+#define PMECC_CFG_BCH_STRENGTH(x)  (x)
+#define PMECC_CFG_BCH_STRENGTH_MASKGENMASK(2, 0)
+#define PMECC_CFG_SECTOR512(0 << 4)
+#define PMECC_CFG_SECTOR1024   BIT(4)
+#define PMECC_CFG_NSECTORS(x)  ((fls(x) - 1) << 8)
+#define PMECC_CFG_READ_OP  (0 << 12)
+#define PMECC_CFG_WRITE_OP BIT(12)
+#define PMECC_CFG_SPARE_ENABLE BIT(16)
+#define PMECC_CFG_AUTO_ENABLE  BIT(20)
+
+#define ATMEL_PMECC_SAREA  0x4
+#define ATMEL_PMECC_SADDR  0x8
+#define ATMEL_PMECC_EADDR  0xc
+
+#define ATMEL_PMECC_CLK0x10
+#define PMECC_CLK_133MHZ   (2 << 0)
+
+#define ATMEL_PMECC_CTRL   0x14
+#define PMECC_CTRL_RST BIT(0)
+#define PMECC_CTRL_DATABIT(1)
+#define PMECC_CTRL_USERBIT(2)
+#define PMECC_CTRL_ENABLE  BIT(4)
+#define PMECC_CTRL_DISABLE BIT(5)
+
+#define ATMEL_PMECC_SR 0x18
+#define PMECC_SR_BUSY  BIT(0)
+#define PMECC_SR_ENABLEBIT(4)
+
+#define ATMEL_PMECC_IER0x1c
+#define ATMEL_PMECC_IDR 

[PATCH v2 1/9] nand: atmel: Add DM based NAND driver

2022-08-28 Thread Balamanikandan Gunasundar
This implementation is ported from the rework done by Boris Brezillon
in Linux. This porting is done based on linux-5.4-at91. The driver is
tested in sam9x60ek, sama5d3_xplained, sam9x75eb and sama7g54-ddr3-eb.

Changes done includes

- Adapt GPIO descriptor apis for U-Boot. Use
  gpio_request_by_name_nodev, dm_gpio_get_value etc.
- Use U_BOOT_DRIVER instead of platform_driver.
- Replace struct platform_device with struct udevice
- Check the status of nfc exec operation by polling the status
  register instead of interrupt based handling
- DMA operations not supported. Remove it
- Adapt DT parsing to U-Boot APIs

Signed-off-by: Balamanikandan Gunasundar 

---
 drivers/mtd/nand/raw/Kconfig |8 +
 drivers/mtd/nand/raw/Makefile|1 +
 drivers/mtd/nand/raw/atmel/Makefile  |4 +
 drivers/mtd/nand/raw/atmel/nand-controller.c | 2293 ++
 4 files changed, 2306 insertions(+)
 create mode 100644 drivers/mtd/nand/raw/atmel/Makefile
 create mode 100644 drivers/mtd/nand/raw/atmel/nand-controller.c

diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig
index ce67d1abde..4d023e2893 100644
--- a/drivers/mtd/nand/raw/Kconfig
+++ b/drivers/mtd/nand/raw/Kconfig
@@ -37,6 +37,14 @@ config SYS_NAND_USE_FLASH_BBT
help
  Enable the BBT (Bad Block Table) usage.
 
+config DM_NAND_ATMEL
+   bool "Support Atmel NAND controller with DM support"
+   select SYS_NAND_SELF_INIT
+   imply SYS_NAND_USE_FLASH_BBT
+   help
+ Enable this driver for NAND flash platforms using an Atmel NAND
+ controller.
+
 config NAND_ATMEL
bool "Support Atmel NAND controller"
select SYS_NAND_SELF_INIT
diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile
index a398aa9d88..42c1fb25b4 100644
--- a/drivers/mtd/nand/raw/Makefile
+++ b/drivers/mtd/nand/raw/Makefile
@@ -48,6 +48,7 @@ ifdef NORMAL_DRIVERS
 obj-$(CONFIG_NAND_ECC_BCH) += nand_bch.o
 
 obj-$(CONFIG_NAND_ATMEL) += atmel_nand.o
+obj-$(CONFIG_DM_NAND_ATMEL) += atmel/
 obj-$(CONFIG_NAND_ARASAN) += arasan_nfc.o
 obj-$(CONFIG_NAND_BRCMNAND) += brcmnand/
 obj-$(CONFIG_NAND_DAVINCI) += davinci_nand.o
diff --git a/drivers/mtd/nand/raw/atmel/Makefile 
b/drivers/mtd/nand/raw/atmel/Makefile
new file mode 100644
index 00..6708416983
--- /dev/null
+++ b/drivers/mtd/nand/raw/atmel/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_DM_NAND_ATMEL)+= atmel-nand-controller.o
+
+atmel-nand-controller-objs := nand-controller.o
diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c 
b/drivers/mtd/nand/raw/atmel/nand-controller.c
new file mode 100644
index 00..29365c7db0
--- /dev/null
+++ b/drivers/mtd/nand/raw/atmel/nand-controller.c
@@ -0,0 +1,2293 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2022 ATMEL
+ * Copyright 2017 Free Electrons
+ *
+ * Author: Boris Brezillon 
+ *
+ * Derived from the atmel_nand.c driver which contained the following
+ * copyrights:
+ *
+ *   Copyright 2003 Rick Bronson
+ *
+ *   Derived from drivers/mtd/nand/autcpu12.c (removed in v3.8)
+ * Copyright 2001 Thomas Gleixner (gleix...@autronix.de)
+ *
+ *   Derived from drivers/mtd/spia.c (removed in v3.8)
+ * Copyright 2000 Steven J. Hill (sjh...@cotw.com)
+ *
+ *
+ *   Add Hardware ECC support for AT91SAM9260 / AT91SAM9263
+ * Richard Genoud (richard.gen...@gmail.com), Adeneo Copyright 2007
+ *
+ *   Derived from Das U-Boot source code
+ * (u-boot-1.1.5/board/atmel/at91sam9263ek/nand.c)
+ * Copyright 2006 ATMEL Rousset, Lacressonniere Nicolas
+ *
+ *   Add Programmable Multibit ECC support for various AT91 SoC
+ * Copyright 2012 ATMEL, Hong Xu
+ *
+ *   Add Nand Flash Controller support for SAMA5 SoC
+ * Copyright 2013 ATMEL, Josh Wu (josh...@atmel.com)
+ *
+ *   Port from Linux
+ * Balamanikandan Gunasundar(balamanikandan.gunasun...@microchip.com)
+ * Copyright (C) 2022 Microchip Technology Inc.
+ *
+ * A few words about the naming convention in this file. This convention
+ * applies to structure and function names.
+ *
+ * Prefixes:
+ *
+ * - atmel_nand_: all generic structures/functions
+ * - atmel_smc_nand_: all structures/functions specific to the SMC interface
+ *   (at91sam9 and avr32 SoCs)
+ * - atmel_hsmc_nand_: all structures/functions specific to the HSMC interface
+ *(sama5 SoCs and later)
+ * - atmel_nfc_: all structures/functions used to manipulate the NFC sub-block
+ *  that is available in the HSMC block
+ * - _nand_: all SoC specific structures/functions
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "pmecc.h"
+
+#define NSEC_PER_SEC10L
+
+#define ATMEL_HSMC_NFC_CFG 0x0
+#define ATMEL_HSMC_NFC_CFG_SPARESIZE(x)

[PATCH v2 0/9] Add DM support for atmel NAND driver

2022-08-28 Thread Balamanikandan Gunasundar
Change include:

- Adapt GPIO descriptor apis for U-Boot. Use
  gpio_request_by_name_nodev, dm_gpio_get_value etc.
- Use U_BOOT_DRIVER instead of platform_driver.
- Replace struct platform_device with struct udevice
- Check the status of nfc exec operation by polling the status
  register instead of interrupt based handling
- DMA operations not supported. Remove it
- Adapt DT parsing to U-Boot APIs

v2:

- Add linux reference version in the commit message from which the
  driver is ported from
- Reword the commit message to describe the changes clearly

Balamanikandan Gunasundar (9):
  nand: atmel: Add DM based NAND driver
  nand: atmel: Add pmecc driver
  mfd: syscon: Add atmel-matrix registers definition
  memory: atmel-ebi: add Atmel EBI (External Bus Interface) driver
  mfd: syscon: atmel-smc: Add driver for atmel SMC
  configs: at91: sam9x60ek: Enable DM based nand driver
  ARM: dts: at91: sam9x60: Add nodes for EBI and NAND
  ARM: dts: at91: sam9x60ek: Enable NAND support
  board: sam9x60ek: remove nand init from board file

 MAINTAINERS  |1 +
 arch/arm/dts/sam9x60.dtsi|   42 +
 arch/arm/dts/sam9x60ek.dts   |  103 +
 board/atmel/sam9x60ek/sam9x60ek.c|   59 -
 configs/sam9x60ek_mmc_defconfig  |9 +-
 configs/sam9x60ek_nandflash_defconfig|9 +-
 configs/sam9x60ek_qspiflash_defconfig|8 +-
 drivers/Kconfig  |2 +
 drivers/Makefile |1 +
 drivers/memory/Kconfig   |7 +
 drivers/memory/Makefile  |1 +
 drivers/memory/atmel_ebi.c   |   37 +
 drivers/mfd/Kconfig  |4 +
 drivers/mfd/Makefile |1 +
 drivers/mfd/atmel-smc.c  |  364 +++
 drivers/mtd/nand/raw/Kconfig |8 +
 drivers/mtd/nand/raw/Makefile|1 +
 drivers/mtd/nand/raw/atmel/Makefile  |5 +
 drivers/mtd/nand/raw/atmel/nand-controller.c | 2293 ++
 drivers/mtd/nand/raw/atmel/pmecc.c   |  965 
 drivers/mtd/nand/raw/atmel/pmecc.h   |   94 +
 include/configs/sam9x60ek.h  |5 -
 include/linux/mfd/syscon/atmel-matrix.h  |  112 +
 include/linux/mfd/syscon/atmel-smc.h |  119 +
 24 files changed, 4177 insertions(+), 73 deletions(-)
 create mode 100644 drivers/memory/atmel_ebi.c
 create mode 100644 drivers/mfd/Kconfig
 create mode 100644 drivers/mfd/Makefile
 create mode 100644 drivers/mfd/atmel-smc.c
 create mode 100644 drivers/mtd/nand/raw/atmel/Makefile
 create mode 100644 drivers/mtd/nand/raw/atmel/nand-controller.c
 create mode 100644 drivers/mtd/nand/raw/atmel/pmecc.c
 create mode 100644 drivers/mtd/nand/raw/atmel/pmecc.h
 create mode 100644 include/linux/mfd/syscon/atmel-matrix.h
 create mode 100644 include/linux/mfd/syscon/atmel-smc.h

-- 
2.34.1



Re: Question about uboot initialisation

2022-08-28 Thread momo aubin
Hi Simon,

Thanks for your answer.

The script that you are telling it is Env.txt right ?

What is a 'dm tree' ? Please could you provide me more infos about this ?

Thanks for your answer in advance.

On Sat, 27 Aug 2022 at 02:21, Simon Glass  wrote:

> Hi Aubin,
>
> On Fri, 26 Aug 2022 at 06:41, momo aubin  wrote:
> >
> > Dear all,
> >
> >
> > Is there any way that allows us to know that uboot has initialised all
> his
> > peripherals before starting loading kernel ?
> >
> > The goal of this check is to reset the board in case of bad
> initialisation
> > and choose a different uboot .
> >
> > Thanks for your answer in advance.
> > Aubin
>
> If there is a failure then it likely results in an error-return code
> from board_init_f() or board_init_r(). These generally halt U-Boot /
> cause a reboot. But this only covers the peripherals that U-Boot sets
> up early, like serial, clocks, pinctrl, MMC, PCI, etc.
>
> U-Boot typically does not init a peripheral unless it is needed for U-Boot.
>
> While U-Boot is running (e.g. a script) it may start up other
> peripherals (e.g. to read a kernel from USB) and in those cases errors
> can be handled by the script.
>
> You can use 'dm tree' to see what devices have been probed successfully.
>
> Regards,
> Simon
>


[PATCH] virtio: pci: fix bug of virtio_pci_map_capability

2022-08-28 Thread Xiang W
The bar of the structure virtio_pci_cap is the index, and each base
address occupies 4 bytes, so it needs to be multiplied by 4.

This patch fixes a bug reported by Felix Yan
https://lists.denx.de/pipermail/u-boot/2022-August/492779.html

Signed-off-by: Xiang W 
Tested-by: Felix Yan 
---
 drivers/virtio/virtio_pci_modern.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 880a12cc28..cfde4007f5 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -466,7 +466,7 @@ static void __iomem *virtio_pci_map_capability(struct 
udevice *udev,
unsigned long mask =
PCI_REGION_TYPE | PCI_REGION_SYS_MEMORY | PCI_REGION_RO;
unsigned long flags = PCI_REGION_MEM;
-   u8 *p = dm_pci_map_bar(udev, PCI_BASE_ADDRESS_0 + cap->bar, cap->offset,
+   u8 *p = dm_pci_map_bar(udev, PCI_BASE_ADDRESS_0 + 4 * cap->bar, 
cap->offset,
   cap->length, mask, flags);
 
return (void __iomem *)p;
-- 
2.30.2



Re: [PATCH] Makefile: Use relative paths for debugging symbols.

2022-08-28 Thread Vagrant Cascadian
On 2022-08-28, Vagrant Cascadian wrote:
> On 2022-08-28, Rasmus Villemoes wrote:
>> On 26/08/2022 22.59, Tom Rini wrote:
>>> On Thu, Aug 18, 2022 at 10:31:34AM -0700, Vagrant Cascadian wrote:
 From: Vagrant Cascadian 

 The KBUILD_CFLAGS and KBUILD_AFLAGS variables are adjusted to use
 -ffile-prefix-map and --debug-prefix-map, respectively, to use
 relative paths for occurrences of __FILE__ and debug paths.

 This enables reproducible builds regardless of the absolute path to
 the build directory:

   https://reproducible-builds.org/docs/build-path/

 Signed-off-by: Vagrant Cascadian 
 Acked-by: Rasmus Villemoes 
>>> 
>>> This needs some sort of clang check and then perhaps different flag
>>> used? How does the linux kernel handle this?
>>
>> Well, interestingly it seems that the kernel doesn't do anything like
>> this for debug info, they only apply the -fmacro-prefix-map. Which one
>> should probably raise with them at some point.
>>
>> It seems we're not actually calling gas directly, but always invokes
>> $(CC) whatever that may be to compile assembler files. So I think the
>> right fix is to simply pass the same -ffile-prefix-map in both
>> KBUILD_CFLAGS as in KBUILD_AFLAGS - and if there's some variable that
>> ends up being included in both automatically, then just adding it there
>> should do the trick.
>
> I tried just adding -ffile-prefix-map and that helped, but was not
> sufficient to solve the reproducibility issues. It also needs the
> --debug-prefix-map to make it the assembly code build reproducibly.
>
> Though I guess I didn't try adding -ffile-prefix-map to KBUILD_AFLAGS,
> now that I think about it... will test that too, thanks!

Nope, that built, but not reproducibly...

I was able to guard it with "as-option":

  +KBUILD_AFLAGS   += $(call as-option,--debug-prefix-map=$(srctree)/=)

And it builds reproducibly for me.

That should be sufficient to fix build failures with clang... or is
there a more appropriate guard to use? I am not familiar with clang and
it's relevent tools to know if there is a relevent comprable option to
--debug-prefix-map.


live well,
  vagrant


signature.asc
Description: PGP signature


Re: [PATCH] usb: Add delay for control messages to reach usb stick

2022-08-28 Thread Marek Vasut

On 8/26/22 07:35, Ashok Reddy Soma wrote:

We are seeing timing issues with transcend usb sticks. These devices
seems to require more time than regular devices for the control messages
to reach device. Add 1ms delay before sending control message to fix
trancend device detection issue.


In case you set 'usb_pgood_delay=2000' in U-Boot environment and re-test 
the USB stick, does the issue go away too ? This would increase the time 
from power Vbus enable to USB enumeration, it usually tends to fix such 
odd hardware too.


[PATCH 7/8] image: Correct indentation in select_ramdisk()

2022-08-28 Thread Simon Glass
Finish off the refactoring by correcting the indent levels. Note that this
does not include any functional changes.

Signed-off-by: Simon Glass 
---

 boot/image-board.c | 140 ++---
 1 file changed, 69 insertions(+), 71 deletions(-)

diff --git a/boot/image-board.c b/boot/image-board.c
index 7c0948b592a..7a17ffb7f7f 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -347,8 +347,8 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
else
default_addr = image_load_addr;
 
-   if (fit_parse_conf(select, default_addr,
-  &rd_addr, &fit_uname_config)) {
+   if (fit_parse_conf(select, default_addr, &rd_addr,
+  &fit_uname_config)) {
debug("*  ramdisk: config '%s' from image at 
0x%08lx\n",
  fit_uname_config, rd_addr);
done_select = true;
@@ -362,82 +362,80 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
}
}
if (!done_select) {
-   rd_addr = hextoul(select, NULL);
-   debug("*  ramdisk: cmdline image address = 
0x%08lx\n",
- rd_addr);
+   rd_addr = hextoul(select, NULL);
+   debug("*  ramdisk: cmdline image address = 0x%08lx\n", rd_addr);
}
-   if (CONFIG_IS_ENABLED(FIT) && !select) {
-   /* use FIT configuration provided in first bootm
-* command argument. If the property is not defined,
-* quit silently (with -ENOPKG)
-*/
-   rd_addr = map_to_sysmem(images->fit_hdr_os);
-   rd_noffset = fit_get_node_from_config(images,
- FIT_RAMDISK_PROP,
- rd_addr);
-   if (rd_noffset == -ENOENT)
-   return -ENOPKG;
-   else if (rd_noffset < 0)
-   return rd_noffset;
-   }
-
-   /*
-* Check if there is an initrd image at the
-* address provided in the second bootm argument
-* check image type, for FIT images get FIT node.
+   if (CONFIG_IS_ENABLED(FIT) && !select) {
+   /* use FIT configuration provided in first bootm
+* command argument. If the property is not defined,
+* quit silently (with -ENOPKG)
 */
-   buf = map_sysmem(rd_addr, 0);
-   switch (genimg_get_format(buf)) {
-   case IMAGE_FORMAT_LEGACY:
-   if (CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)) {
-   const image_header_t *rd_hdr;
+   rd_addr = map_to_sysmem(images->fit_hdr_os);
+   rd_noffset = fit_get_node_from_config(images, FIT_RAMDISK_PROP,
+ rd_addr);
+   if (rd_noffset == -ENOENT)
+   return -ENOPKG;
+   else if (rd_noffset < 0)
+   return rd_noffset;
+   }
 
-   printf("## Loading init Ramdisk from Legacy 
Image at %08lx ...\n",
-  rd_addr);
+   /*
+* Check if there is an initrd image at the
+* address provided in the second bootm argument
+* check image type, for FIT images get FIT node.
+*/
+   buf = map_sysmem(rd_addr, 0);
+   switch (genimg_get_format(buf)) {
+   case IMAGE_FORMAT_LEGACY:
+   if (CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)) {
+   const image_header_t *rd_hdr;
 
-   bootstage_mark(BOOTSTAGE_ID_CHECK_RAMDISK);
-   rd_hdr = image_get_ramdisk(rd_addr, arch,
-  images->verify);
+   printf("## Loading init Ramdisk from Legacy Image at 
%08lx ...\n",
+  rd_addr);
 
-   if (!rd_hdr)
-   return -ENOENT;
+   bootstage_mark(BOOTSTAGE_ID_CHECK_RAMDISK);
+   rd_hdr = image_get_ramdisk(rd_addr, arch,
+  images->verify);
 
-   *rd_datap = image_get_data(rd_hdr);
-   *rd_lenp = image_get_data_size(rd_hdr);
-   done = true;
-   }
-   break;
-

[PATCH 3/8] image: Drop #ifdefs for LEGACY_IMAGE_FORMAT

2022-08-28 Thread Simon Glass
Use if() instead of the #ifdef in select_ramdisk().

Signed-off-by: Simon Glass 
---

 boot/image-board.c | 31 ++-
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/boot/image-board.c b/boot/image-board.c
index 2d5e5b6e6f0..a80ad08b15f 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -24,7 +24,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
 /**
  * image_get_ramdisk - get and verify ramdisk image
  * @rd_addr: ramdisk image start address
@@ -83,7 +82,6 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, 
u8 arch,
 
return rd_hdr;
 }
-#endif
 
 /*/
 /* Shared dual-format routines */
@@ -386,26 +384,25 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
 */
buf = map_sysmem(rd_addr, 0);
switch (genimg_get_format(buf)) {
-#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
-   case IMAGE_FORMAT_LEGACY: {
-   const image_header_t *rd_hdr;
+   case IMAGE_FORMAT_LEGACY:
+   if (CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)) {
+   const image_header_t *rd_hdr;
 
-   printf("## Loading init Ramdisk from Legacy Image at 
%08lx ...\n",
-  rd_addr);
+   printf("## Loading init Ramdisk from Legacy 
Image at %08lx ...\n",
+  rd_addr);
 
-   bootstage_mark(BOOTSTAGE_ID_CHECK_RAMDISK);
-   rd_hdr = image_get_ramdisk(rd_addr, arch,
-  images->verify);
+   bootstage_mark(BOOTSTAGE_ID_CHECK_RAMDISK);
+   rd_hdr = image_get_ramdisk(rd_addr, arch,
+  images->verify);
 
-   if (!rd_hdr)
-   return -ENOENT;
+   if (!rd_hdr)
+   return -ENOENT;
 
-   *rd_datap = image_get_data(rd_hdr);
-   *rd_lenp = image_get_data_size(rd_hdr);
-   done = true;
+   *rd_datap = image_get_data(rd_hdr);
+   *rd_lenp = image_get_data_size(rd_hdr);
+   done = true;
+   }
break;
-   }
-#endif
 #if CONFIG_IS_ENABLED(FIT)
case IMAGE_FORMAT_FIT:
rd_noffset = fit_image_load(images,
-- 
2.37.2.672.g94769d06f0-goog



[PATCH 8/8] image: Drop some other #ifdefs in image-board.c

2022-08-28 Thread Simon Glass
Remove all but a few that are difficult, relying on legacy CONFIG options
or optional global_data fields.

Drop the duplicate function name in the comment for boot_get_cmdline().

Signed-off-by: Simon Glass 
---

 boot/image-board.c | 67 +-
 include/image.h|  6 +
 2 files changed, 42 insertions(+), 31 deletions(-)

diff --git a/boot/image-board.c b/boot/image-board.c
index 7a17ffb7f7f..1be0a359aba 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -172,29 +173,29 @@ void memmove_wd(void *to, void *from, size_t len, ulong 
chunksz)
if (to == from)
return;
 
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-   if (to > from) {
-   from += len;
-   to += len;
-   }
-   while (len > 0) {
-   size_t tail = (len > chunksz) ? chunksz : len;
-
-   WATCHDOG_RESET();
+   if (IS_ENABLED(CONFIG_HW_WATCHDOG) || IS_ENABLED(CONFIG_WATCHDOG)) {
if (to > from) {
-   to -= tail;
-   from -= tail;
+   from += len;
+   to += len;
}
-   memmove(to, from, tail);
-   if (to < from) {
-   to += tail;
-   from += tail;
+   while (len > 0) {
+   size_t tail = (len > chunksz) ? chunksz : len;
+
+   WATCHDOG_RESET();
+   if (to > from) {
+   to -= tail;
+   from -= tail;
+   }
+   memmove(to, from, tail);
+   if (to < from) {
+   to += tail;
+   from += tail;
+   }
+   len -= tail;
}
-   len -= tail;
+   } else {
+   memmove(to, from, len);
}
-#else  /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
-   memmove(to, from, len);
-#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
 }
 
 /**
@@ -551,7 +552,6 @@ int boot_get_ramdisk(int argc, char *const argv[], 
bootm_headers_t *images,
return 0;
 }
 
-#if defined(CONFIG_LMB)
 /**
  * boot_ramdisk_high - relocate init ramdisk
  * @lmb: pointer to lmb handle, will be used for memory mgmt
@@ -645,7 +645,6 @@ int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong 
rd_len,
 error:
return -1;
 }
-#endif
 
 int boot_get_setup(bootm_headers_t *images, u8 arch,
   ulong *setup_start, ulong *setup_len)
@@ -839,15 +838,13 @@ int boot_get_loadable(int argc, char *const argv[], 
bootm_headers_t *images,
return 0;
 }
 
-#if defined(CONFIG_LMB)
-#ifdef CONFIG_SYS_BOOT_GET_CMDLINE
 /**
  * boot_get_cmdline - allocate and initialize kernel cmdline
  * @lmb: pointer to lmb handle, will be used for memory mgmt
  * @cmd_start: pointer to a ulong variable, will hold cmdline start
  * @cmd_end: pointer to a ulong variable, will hold cmdline end
  *
- * boot_get_cmdline() allocates space for kernel command line below
+ * This allocates space for kernel command line below
  * BOOTMAPSZ + env_get_bootm_low() address. If "bootargs" U-Boot environment
  * variable is present its contents is copied to allocated kernel
  * command line.
@@ -858,10 +855,19 @@ int boot_get_loadable(int argc, char *const argv[], 
bootm_headers_t *images,
  */
 int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
 {
+   int barg;
char *cmdline;
char *s;
 
-   cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
+   /*
+* Help the compiler detect that this function is only called when
+* CONFIG_SYS_BOOT_GET_CMDLINE is enabled
+*/
+   if (!IS_ENABLED(CONFIG_SYS_BOOT_GET_CMDLINE))
+   return 0;
+
+   barg = IF_ENABLED_INT(CONFIG_SYS_BOOT_GET_CMDLINE, CONFIG_SYS_BARGSIZE);
+   cmdline = (char *)(ulong)lmb_alloc_base(lmb, barg, 0xf,
env_get_bootm_mapsize() + env_get_bootm_low());
if (!cmdline)
return -1;
@@ -907,22 +913,22 @@ int boot_get_kbd(struct lmb *lmb, struct bd_info **kbd)
 
debug("## kernel board info at 0x%08lx\n", (ulong)*kbd);
 
-#if defined(DEBUG)
-   if (IS_ENABLED(CONFIG_CMD_BDI))
+   if (_DEBUG && IS_ENABLED(CONFIG_CMD_BDI))
do_bdinfo(NULL, 0, 0, NULL);
-#endif
 
return 0;
 }
-#endif
 
 int image_setup_linux(bootm_headers_t *images)
 {
ulong of_size = images->ft_len;
char **of_flat_tree = &images->ft_addr;
-   struct lmb *lmb = &images->lmb;
+   struct lmb *lmb = images_lmb(images);
int ret;
 
+   /* This function cannot be called without lmb support */
+   if (!CONFIG_IS_ENABLED(LM

[PATCH 6/8] image: Drop remaining FIT #ifdef

2022-08-28 Thread Simon Glass
Drop the last one of these, by using a done_select variable to control
whether to fall back to using 'select' as a hex value.

Note that the indentation is not adjusted, to make this easier to review.

Signed-off-by: Simon Glass 
---

 boot/image-board.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/boot/image-board.c b/boot/image-board.c
index 8858a2fe126..7c0948b592a 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -324,12 +324,13 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
 {
const char *fit_uname_config;
const char *fit_uname_ramdisk;
+   bool done_select = !select;
bool done = false;
int rd_noffset;
ulong rd_addr;
char *buf;
 
-#if CONFIG_IS_ENABLED(FIT)
+   if (CONFIG_IS_ENABLED(FIT)) {
fit_uname_config = images->fit_uname_cfg;
fit_uname_ramdisk = NULL;
 
@@ -350,21 +351,21 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
   &rd_addr, &fit_uname_config)) {
debug("*  ramdisk: config '%s' from image at 
0x%08lx\n",
  fit_uname_config, rd_addr);
+   done_select = true;
} else if (fit_parse_subimage(select, default_addr,
  &rd_addr,
  &fit_uname_ramdisk)) {
debug("*  ramdisk: subimage '%s' from image at 
0x%08lx\n",
  fit_uname_ramdisk, rd_addr);
-   } else
-#endif
-   {
+   done_select = true;
+   }
+   }
+   }
+   if (!done_select) {
rd_addr = hextoul(select, NULL);
debug("*  ramdisk: cmdline image address = 
0x%08lx\n",
  rd_addr);
-   }
-#if CONFIG_IS_ENABLED(FIT)
-   }
-#endif
+   }
if (CONFIG_IS_ENABLED(FIT) && !select) {
/* use FIT configuration provided in first bootm
 * command argument. If the property is not defined,
-- 
2.37.2.672.g94769d06f0-goog



[PATCH 5/8] image: Drop another #ifdef for FIT

2022-08-28 Thread Simon Glass
Drop the prenultimate one of these from select_ramdisk().

Signed-off-by: Simon Glass 
---

 boot/image-board.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/boot/image-board.c b/boot/image-board.c
index 07b7e467cc4..8858a2fe126 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -363,7 +363,9 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
  rd_addr);
}
 #if CONFIG_IS_ENABLED(FIT)
-   } else {
+   }
+#endif
+   if (CONFIG_IS_ENABLED(FIT) && !select) {
/* use FIT configuration provided in first bootm
 * command argument. If the property is not defined,
 * quit silently (with -ENOPKG)
@@ -377,7 +379,6 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
else if (rd_noffset < 0)
return rd_noffset;
}
-#endif
 
/*
 * Check if there is an initrd image at the
-- 
2.37.2.672.g94769d06f0-goog



[PATCH 4/8] image: Drop one #ifdef for FIT

2022-08-28 Thread Simon Glass
Drop the #ifdef from near the end of select_ramdisk(). Move some variables
to the top of the function to make this work.

Signed-off-by: Simon Glass 
---

 boot/image-board.c | 39 ---
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/boot/image-board.c b/boot/image-board.c
index a80ad08b15f..07b7e467cc4 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -322,14 +322,16 @@ int genimg_has_config(bootm_headers_t *images)
 static int select_ramdisk(bootm_headers_t *images, const char *select, u8 arch,
  ulong *rd_datap, ulong *rd_lenp)
 {
+   const char *fit_uname_config;
+   const char *fit_uname_ramdisk;
bool done = false;
+   int rd_noffset;
ulong rd_addr;
char *buf;
 
 #if CONFIG_IS_ENABLED(FIT)
-   const char *fit_uname_config = images->fit_uname_cfg;
-   const char *fit_uname_ramdisk = NULL;
-   int rd_noffset;
+   fit_uname_config = images->fit_uname_cfg;
+   fit_uname_ramdisk = NULL;
 
if (select) {
ulong default_addr;
@@ -403,24 +405,23 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
done = true;
}
break;
-#if CONFIG_IS_ENABLED(FIT)
case IMAGE_FORMAT_FIT:
-   rd_noffset = fit_image_load(images,
-   rd_addr, &fit_uname_ramdisk,
-   &fit_uname_config, arch,
-   IH_TYPE_RAMDISK,
-   BOOTSTAGE_ID_FIT_RD_START,
-   FIT_LOAD_OPTIONAL_NON_ZERO,
-   rd_datap, rd_lenp);
-   if (rd_noffset < 0)
-   return rd_noffset;
-
-   images->fit_hdr_rd = map_sysmem(rd_addr, 0);
-   images->fit_uname_rd = fit_uname_ramdisk;
-   images->fit_noffset_rd = rd_noffset;
-   done = true;
+   if (CONFIG_IS_ENABLED(FIT)) {
+   rd_noffset = fit_image_load(images, rd_addr,
+   &fit_uname_ramdisk, &fit_uname_config,
+   arch, IH_TYPE_RAMDISK,
+   BOOTSTAGE_ID_FIT_RD_START,
+   FIT_LOAD_OPTIONAL_NON_ZERO,
+   rd_datap, rd_lenp);
+   if (rd_noffset < 0)
+   return rd_noffset;
+
+   images->fit_hdr_rd = map_sysmem(rd_addr, 0);
+   images->fit_uname_rd = fit_uname_ramdisk;
+   images->fit_noffset_rd = rd_noffset;
+   done = true;
+   }
break;
-#endif
case IMAGE_FORMAT_ANDROID:
if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) {
void *ptr = map_sysmem(images->os.start, 0);
-- 
2.37.2.672.g94769d06f0-goog



[PATCH 2/8] image: Track when ramdisk processing is completed

2022-08-28 Thread Simon Glass
The current switch default is tricky since it relies on #ifdefs to work.
Use a bool instead.

Also fix the comment on @select, since it has a dual purpose.

Signed-off-by: Simon Glass 
---

 boot/image-board.c | 36 ++--
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/boot/image-board.c b/boot/image-board.c
index 14b595977e1..2d5e5b6e6f0 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -314,7 +314,7 @@ int genimg_has_config(bootm_headers_t *images)
  * select_ramdisk() - Select and locate the ramdisk to use
  *
  * @images: pointer to the bootm images structure
- * @select: name of ramdisk to select, or NULL for any
+ * @select: name of ramdisk to select, or hex address, NULL for any
  * @arch: expected ramdisk architecture
  * @rd_datap: pointer to a ulong variable, will hold ramdisk pointer
  * @rd_lenp: pointer to a ulong variable, will hold ramdisk length
@@ -324,6 +324,7 @@ int genimg_has_config(bootm_headers_t *images)
 static int select_ramdisk(bootm_headers_t *images, const char *select, u8 arch,
  ulong *rd_datap, ulong *rd_lenp)
 {
+   bool done = false;
ulong rd_addr;
char *buf;
 
@@ -401,6 +402,7 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
 
*rd_datap = image_get_data(rd_hdr);
*rd_lenp = image_get_data_size(rd_hdr);
+   done = true;
break;
}
 #endif
@@ -419,6 +421,7 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
images->fit_hdr_rd = map_sysmem(rd_addr, 0);
images->fit_uname_rd = fit_uname_ramdisk;
images->fit_noffset_rd = rd_noffset;
+   done = true;
break;
 #endif
case IMAGE_FORMAT_ANDROID:
@@ -431,24 +434,29 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
unmap_sysmem(ptr);
if (ret)
return ret;
-   break;
+   done = true;
}
-   fallthrough;
-   default:
-   if (IS_ENABLED(CONFIG_SUPPORT_RAW_INITRD)) {
-   char *end = NULL;
-
-   if (select)
-   end = strchr(select, ':');
-   if (end) {
-   *rd_lenp = hextoul(++end, NULL);
-   *rd_datap = rd_addr;
-   break;
-   }
+   break;
+   }
+
+   if (!done) {
+   if (IS_ENABLED(CONFIG_SUPPORT_RAW_INITRD)) {
+   char *end = NULL;
+
+   if (select)
+   end = strchr(select, ':');
+   if (end) {
+   *rd_lenp = hextoul(++end, NULL);
+   *rd_datap = rd_addr;
+   done = true;
}
+   }
+
+   if (!done) {
puts("Wrong Ramdisk Image Format\n");
return -EINVAL;
}
+   }
 
return 0;
 }
-- 
2.37.2.672.g94769d06f0-goog



[PATCH 1/8] image: Fix up ANDROID_BOOT_IMAGE ramdisk code

2022-08-28 Thread Simon Glass
Convert this to an if(), fix the cast from an address to a pointer and
make sure that any error is returned correctly.

Signed-off-by: Simon Glass 
---

 boot/image-board.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/boot/image-board.c b/boot/image-board.c
index 4e4d1c157d7..14b595977e1 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -421,12 +421,19 @@ static int select_ramdisk(bootm_headers_t *images, const 
char *select, u8 arch,
images->fit_noffset_rd = rd_noffset;
break;
 #endif
-#ifdef CONFIG_ANDROID_BOOT_IMAGE
case IMAGE_FORMAT_ANDROID:
-   android_image_get_ramdisk((void *)images->os.start,
- rd_datap, rd_lenp);
-   break;
-#endif
+   if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) {
+   void *ptr = map_sysmem(images->os.start, 0);
+   int ret;
+
+   ret = android_image_get_ramdisk(ptr, rd_datap,
+   rd_lenp);
+   unmap_sysmem(ptr);
+   if (ret)
+   return ret;
+   break;
+   }
+   fallthrough;
default:
if (IS_ENABLED(CONFIG_SUPPORT_RAW_INITRD)) {
char *end = NULL;
-- 
2.37.2.672.g94769d06f0-goog



[PATCH 0/8] image: Refactor ramdisk code to avoid #ifdef

2022-08-28 Thread Simon Glass
The previous attempt at this[1] broke a board and was reverted in [2].
This series adopts a slightly different approach, splitting the changes
into many commits.

[1] f33a2c1bd0f ("image: Remove #ifdefs from select_ramdisk()")
[2] 621158d106f ("Revert "image: Remove #ifdefs from select_ramdisk()"")


Simon Glass (8):
  image: Fix up ANDROID_BOOT_IMAGE ramdisk code
  image: Track when ramdisk processing is completed
  image: Drop #ifdefs for LEGACY_IMAGE_FORMAT
  image: Drop one #ifdef for FIT
  image: Drop another #ifdef for FIT
  image: Drop remaining FIT #ifdef
  image: Correct indentation in select_ramdisk()
  image: Drop some other #ifdefs in image-board.c

 boot/image-board.c | 212 -
 include/image.h|   6 ++
 2 files changed, 121 insertions(+), 97 deletions(-)

-- 
2.37.2.672.g94769d06f0-goog



Re: [PATCH] Makefile: Use relative paths for debugging symbols.

2022-08-28 Thread Vagrant Cascadian
On 2022-08-28, Rasmus Villemoes wrote:
> On 26/08/2022 22.59, Tom Rini wrote:
>> On Thu, Aug 18, 2022 at 10:31:34AM -0700, Vagrant Cascadian wrote:
>> 
>>> From: Vagrant Cascadian 
>>>
>>> The KBUILD_CFLAGS and KBUILD_AFLAGS variables are adjusted to use
>>> -ffile-prefix-map and --debug-prefix-map, respectively, to use
>>> relative paths for occurrences of __FILE__ and debug paths.
>>>
>>> This enables reproducible builds regardless of the absolute path to
>>> the build directory:
>>>
>>>   https://reproducible-builds.org/docs/build-path/
>>>
>>> Signed-off-by: Vagrant Cascadian 
>>> Acked-by: Rasmus Villemoes 
>> 
>> This needs some sort of clang check and then perhaps different flag
>> used? How does the linux kernel handle this?
>
> Well, interestingly it seems that the kernel doesn't do anything like
> this for debug info, they only apply the -fmacro-prefix-map. Which one
> should probably raise with them at some point.
>
> It seems we're not actually calling gas directly, but always invokes
> $(CC) whatever that may be to compile assembler files. So I think the
> right fix is to simply pass the same -ffile-prefix-map in both
> KBUILD_CFLAGS as in KBUILD_AFLAGS - and if there's some variable that
> ends up being included in both automatically, then just adding it there
> should do the trick.

I tried just adding -ffile-prefix-map and that helped, but was not
sufficient to solve the reproducibility issues. It also needs the
--debug-prefix-map to make it the assembly code build reproducibly.

Though I guess I didn't try adding -ffile-prefix-map to KBUILD_AFLAGS,
now that I think about it... will test that too, thanks!


live well,
  vagrant


signature.asc
Description: PGP signature


Re: [PATCH v2 18/18] virtio: pci: Make use of dm_pci_map_bar()

2022-08-28 Thread Xiang W
在 2022-08-25星期四的 11:01 +0300,Felix Yan写道:
> Hi,
> 
> Today I discovered a failure which bisected to this commit.
> 
> When running QEMU with libvirt, which created some pcie devices, U-boot 
> fails on autoboot with:
> 
> Unhandled exception: Load access fault
> EPC: bff7c46e RA: bff7c46c TVAL: 40200014
> EPC: 8002446e RA: 8002446c reloc adjusted
> 
> Code: 8082 1141 e022 e406 842e 40ef dc5f 611c (c783 0147)
> 
> I have tried to minimize the command line that makes the difference.
> 
> This works:
> 
> -device 
> '{"driver":"virtio-blk-pci","drive":"libvirt-2-format","id":"virtio-disk0","bootindex":1}'
> 
> This doesn't work:
> 
> -device 
> '{"driver":"virtio-blk-pci","bus":"pci.2","addr":"0x0","drive":"libvirt-2-format","id":"virtio-disk0","bootindex":1}'
> 
> I have tried this on multiple machines, different U-boot tags, mmode or 
> smode with OpenSBI, all with the same behavior. Latest U-boot master 
> with this commit reverted works fine on both cases.
> 
> I am very new to U-boot, please do let me know if more info are to be 
> provided.
> 
> Attached the full command line, for reference:
> 
> /usr/bin/qemu-system-riscv64  \
> -machine virt  \
> -bios u-boot/u-boot.bin  \
> -m 1024  \
> -device 
> '{"driver":"pcie-root-port","port":8,"chassis":1,"id":"pci.1","bus":"pcie.0","multifunction":true,"addr":"0x1"}'
>  
>   \
> -device 
> '{"driver":"pcie-root-port","port":9,"chassis":2,"id":"pci.2","bus":"pcie.0","addr":"0x1.0x1"}'
>  
>   \
> -blockdev 
> '{"driver":"file","filename":"archriscv-2022-08-24.qcow2","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}'
>  
>   \
> -blockdev 
> '{"node-name":"libvirt-2-format","read-only":false,"driver":"qcow2","file":"libvirt-2-storage","backing":null}'
>  
>   \
> -device 
> '{"driver":"virtio-blk-pci","bus":"pci.2","addr":"0x0","drive":"libvirt-2-format","id":"virtio-disk0","bootindex":1}'
>  
>   \
> -nographic
> 
> -- 
> Regards,
> Felix Yan

Please try my patch and let me know the test results

diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
index 880a12cc28..cfde4007f5 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -466,7 +466,7 @@ static void __iomem *virtio_pci_map_capability(struct 
udevice *udev,
unsigned long mask =
PCI_REGION_TYPE | PCI_REGION_SYS_MEMORY | PCI_REGION_RO;
unsigned long flags = PCI_REGION_MEM;
-   u8 *p = dm_pci_map_bar(udev, PCI_BASE_ADDRESS_0 + cap->bar, cap->offset,
+   u8 *p = dm_pci_map_bar(udev, PCI_BASE_ADDRESS_0 + 4 * cap->bar, 
cap->offset,
   cap->length, mask, flags);
 
return (void __iomem *)p;

Regards,
Xiang W



[PATCH v2] board_f: Add support for CONFIG_OF_BOARD_FIXUP for XIP images

2022-08-28 Thread Marek Behún
From: Pali Rohár 

When U-Boot is running from flash memory (execute in place) then
gd->fdt_blob before relocation points to read-only flash memory.

So U-Boot calls board_fix_fdt() with read-only gd->fdt_blob pointer which
cause immediate CPU crash when callback is trying to modify gd->fdt_blob.

Fix this issue by introducing a new config option
OF_DTB_READONLY_BEFORE_RELOC which moves fix_fdt callback after the
reloc_fdt callback. This makes CONFIG_OF_BOARD_FIXUP working also if
U-Boot before relocation is not running from read/write (S)RAM memory.

This is required for mpc85xx boards when booting from flash NOR.

Signed-off-by: Pali Rohár 
Signed-off-by: Marek Behún 
---
Changes since v1:
- just changed the new Kconfig option name and associated help string
---
 common/board_f.c | 8 +++-
 dts/Kconfig  | 6 ++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/common/board_f.c b/common/board_f.c
index 18e2246733..35fb4a0753 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -911,7 +911,7 @@ static const init_fnc_t init_sequence_f[] = {
 *  - board info struct
 */
setup_dest_addr,
-#ifdef CONFIG_OF_BOARD_FIXUP
+#if defined(CONFIG_OF_BOARD_FIXUP) && 
!defined(CONFIG_OF_DTB_READONLY_BEFORE_RELOC)
fix_fdt,
 #endif
 #ifdef CONFIG_PRAM
@@ -926,6 +926,10 @@ static const init_fnc_t init_sequence_f[] = {
reserve_board,
reserve_global_data,
reserve_fdt,
+#if defined(CONFIG_OF_BOARD_FIXUP) && 
defined(CONFIG_OF_DTB_READONLY_BEFORE_RELOC)
+   reloc_fdt,
+   fix_fdt,
+#endif
reserve_bootstage,
reserve_bloblist,
reserve_arch,
@@ -936,7 +940,9 @@ static const init_fnc_t init_sequence_f[] = {
setup_bdinfo,
display_new_sp,
INIT_FUNC_WATCHDOG_RESET
+#if !defined(CONFIG_OF_BOARD_FIXUP) || 
!defined(CONFIG_OF_DTB_READONLY_BEFORE_RELOC)
reloc_fdt,
+#endif
reloc_bootstage,
reloc_bloblist,
setup_reloc,
diff --git a/dts/Kconfig b/dts/Kconfig
index bc5f22029f..29e5248b15 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -105,6 +105,12 @@ config OF_EMBED
 
 endchoice
 
+config OF_DTB_READONLY_BEFORE_RELOC
+   bool "Initial DTB (before relocation) for DT control is read-only"
+   help
+ If initial (before relocation) DTB for DT control is read-only,
+ (e.g. points to memory-mapped flash memory), set this option.
+
 config OF_BOARD
bool "Provided by the board (e.g a previous loader) at runtime"
default y if SANDBOX || OF_HAS_PRIOR_STAGE
-- 
2.35.1



Re: [PATCH] tools: mkimage: fix build with recent LibreSSL

2022-08-28 Thread Jonathan Gray
On Sat, Aug 27, 2022 at 07:23:44PM +0200, Mark Kettenis wrote:
> Recent versions of LibreSSL, such as those shipped as part of
> OpenBSD 7.1 and later have an opaque RSA object and do provide the
> RSA_get0_* functions that OpenSSL provides.

part of 3.5.0 / 0x305fL as well
https://lists.denx.de/pipermail/u-boot/2022-July/489768.html
https://marc.info/?l=libressl&m=164572407401570&w=2

> 
> Fixes: 2ecc354b8e46 ("tools: mkimage: fix build with LibreSSL")
> Signed-off-by: Mark Kettenis 
> ---
>  tools/sunxi_toc0.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/sunxi_toc0.c b/tools/sunxi_toc0.c
> index 56200bd927..eb5626411c 100644
> --- a/tools/sunxi_toc0.c
> +++ b/tools/sunxi_toc0.c
> @@ -34,7 +34,7 @@
>  #define pr_warn(fmt, args...)fprintf(stderr, pr_fmt(fmt), "warning", 
> ##args)
>  #define pr_info(fmt, args...)fprintf(stderr, pr_fmt(fmt), "info", 
> ##args)
>  
> -#if defined(LIBRESSL_VERSION_NUMBER)
> +#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x3050100fL
>  #define RSA_get0_n(key) (key)->n
>  #define RSA_get0_e(key) (key)->e
>  #define RSA_get0_d(key) (key)->d
> -- 
> 2.37.2
> 
> 


Re: [PATCH] Makefile: Use relative paths for debugging symbols.

2022-08-28 Thread Rasmus Villemoes
On 26/08/2022 22.59, Tom Rini wrote:
> On Thu, Aug 18, 2022 at 10:31:34AM -0700, Vagrant Cascadian wrote:
> 
>> From: Vagrant Cascadian 
>>
>> The KBUILD_CFLAGS and KBUILD_AFLAGS variables are adjusted to use
>> -ffile-prefix-map and --debug-prefix-map, respectively, to use
>> relative paths for occurrences of __FILE__ and debug paths.
>>
>> This enables reproducible builds regardless of the absolute path to
>> the build directory:
>>
>>   https://reproducible-builds.org/docs/build-path/
>>
>> Signed-off-by: Vagrant Cascadian 
>> Acked-by: Rasmus Villemoes 
> 
> This needs some sort of clang check and then perhaps different flag
> used? How does the linux kernel handle this?

Well, interestingly it seems that the kernel doesn't do anything like
this for debug info, they only apply the -fmacro-prefix-map. Which one
should probably raise with them at some point.

It seems we're not actually calling gas directly, but always invokes
$(CC) whatever that may be to compile assembler files. So I think the
right fix is to simply pass the same -ffile-prefix-map in both
KBUILD_CFLAGS as in KBUILD_AFLAGS - and if there's some variable that
ends up being included in both automatically, then just adding it there
should do the trick.

Rasmus


Re: [PATCH v2] fs: fix comment typo

2022-08-28 Thread Roger Knecht
--- Original Message ---
On Thursday, August 25th, 2022 at 15:01, Simon Glass  wrote:
> 
> 
> Hi Roger,
> 
> On Thu, 25 Aug 2022 at 05:12, Roger Knecht rkne...@pm.me wrote:
> 
> > Fix typo in include/fs.h
> > 
> > Reviewed-by: Simon Glass s...@chromium.org
> > Signed-off-by: Roger Knecht rkne...@pm.me
> > ---
> > v2:
> > - Added Reviewed-by Simon
> 
> 
> Just a note that patchwork collects these tags for you so there is no
> need to resend the patch if that is all that has changed:
> 
> https://patchwork.ozlabs.org/project/uboot/patch/20220821152526.367-1-rkne...@pm.me/
> 
Good to know, thanks Simon.

Regards,
Roger



Re: [PATCH] board_f: Add support for CONFIG_OF_BOARD_FIXUP for XIP images

2022-08-28 Thread Pali Rohár
On Sunday 28 August 2022 05:47:51 Marek Behún wrote:
> Can you rename the option to
>   OF_FDT_READONLY_BEFORE_RELOC
> ?

I do not care what is the name of this option. All other options for
this configuration have OF and DTB in its name, not FDT, and that is why
I chose the current name.

> The INITIAL in the name may confuse people.
> 
> The functions are called *_fdt (reloc_fdt, fix_fdt), so maybe put FDT
> instead of DTB in the config option name.
> 
> Marek