From uwe at kleine-koenig.org  Sat Mar  1 08:36:17 2025
From: uwe at kleine-koenig.org (=?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?=)
Date: Sat,  1 Mar 2025 17:36:17 +0100
Subject: [PATCH 0/4] Add support for QNAP's ts-433 4bay NAS
Message-ID: <cover.1740846737.git.uwe@kleine-koenig.org>

Hello,

this is the result of my quick effort to make barebox run on QNAP's
ts-433 4bay NAS. The first 3 patches are IMHO fine to go in. The last
one adds the new machine. As writting in the commit log the NAS boots
with the resulting image, but neither network nor eMMC work.

I also tried adding

	writel(RK_SETBITS(0x50), 0xfdc20140)

in lowlevel.c, but that didn't make a difference. I'm open for other
ideas about what bit is missing.

Best regards
Uwe

Uwe Kleine-K?nig (4):
  Documentation: rockchip: Update versions of DDR init blobs
  arm64: rockchip: Refresh rockchip_v8_defconfig
  arm64: rockchip: Enable rk-usb-loader in rockchip_v8_defconfig
  WIP: arm64: rockchip: Add support for QNAP's ts-433 4bay NAS

 Documentation/boards/rockchip.rst      |  7 ++++---
 arch/arm/boards/Makefile               |  1 +
 arch/arm/boards/qnap-tsx33/.gitignore  |  1 +
 arch/arm/boards/qnap-tsx33/Makefile    |  2 ++
 arch/arm/boards/qnap-tsx33/lowlevel.c  | 27 ++++++++++++++++++++++++++
 arch/arm/configs/rockchip_v8_defconfig |  6 ++----
 arch/arm/dts/Makefile                  |  1 +
 arch/arm/dts/rk3568-qnap-ts433.dts     | 27 ++++++++++++++++++++++++++
 arch/arm/mach-rockchip/Kconfig         |  7 +++++++
 images/Makefile.rockchip               |  1 +
 10 files changed, 73 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm/boards/qnap-tsx33/.gitignore
 create mode 100644 arch/arm/boards/qnap-tsx33/Makefile
 create mode 100644 arch/arm/boards/qnap-tsx33/lowlevel.c
 create mode 100644 arch/arm/dts/rk3568-qnap-ts433.dts


base-commit: 2afd1a809f1a41f1dd42b95c2bc0ae74853b475b
-- 
2.47.1



From uwe at kleine-koenig.org  Sat Mar  1 08:36:19 2025
From: uwe at kleine-koenig.org (=?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?=)
Date: Sat,  1 Mar 2025 17:36:19 +0100
Subject: [PATCH 2/4] arm64: rockchip: Refresh rockchip_v8_defconfig
In-Reply-To: <cover.1740846737.git.uwe@kleine-koenig.org>
References: <cover.1740846737.git.uwe@kleine-koenig.org>
Message-ID: <7877998d2d34d00913ece6ef21d1fed8a6ea4771.1740846737.git.uwe@kleine-koenig.org>

This is just the result of

	make rockchip_v8_defconfig
	make savedefconfig
	cp defconfig arch/arm/configs/rockchip_v8_defconfig

Signed-off-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
---
 arch/arm/configs/rockchip_v8_defconfig | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/arch/arm/configs/rockchip_v8_defconfig b/arch/arm/configs/rockchip_v8_defconfig
index 83799ac492e7..941625394ccf 100644
--- a/arch/arm/configs/rockchip_v8_defconfig
+++ b/arch/arm/configs/rockchip_v8_defconfig
@@ -7,8 +7,6 @@ CONFIG_MACH_PROTONIC_MECSBC=y
 CONFIG_MACH_RADXA_ROCK3=y
 CONFIG_MACH_RADXA_ROCK5=y
 CONFIG_MACH_RADXA_CM3=y
-CONFIG_BOARD_GENERIC_DT=y
-CONFIG_64BIT=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_PSCI_CLIENT=y
 CONFIG_MMU=y
@@ -91,7 +89,6 @@ CONFIG_CMD_TIME=y
 CONFIG_NET=y
 CONFIG_NET_NFS=y
 CONFIG_NET_NETCONSOLE=y
-CONFIG_OFDEVICE=y
 CONFIG_OF_BAREBOX_DRIVERS=y
 CONFIG_AIODEV=y
 CONFIG_ROCKCHIP_SARADC=y
@@ -156,7 +153,6 @@ CONFIG_FS_TFTP=y
 CONFIG_FS_NFS=y
 CONFIG_FS_FAT=y
 CONFIG_FS_FAT_WRITE=y
-CONFIG_FS_FAT_LFN=y
 CONFIG_FS_BPKFS=y
 CONFIG_FS_UIMAGEFS=y
 CONFIG_LZO_DECOMPRESS=y
-- 
2.47.1



From uwe at kleine-koenig.org  Sat Mar  1 08:36:20 2025
From: uwe at kleine-koenig.org (=?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?=)
Date: Sat,  1 Mar 2025 17:36:20 +0100
Subject: [PATCH 3/4] arm64: rockchip: Enable rk-usb-loader in rockchip_v8_defconfig
In-Reply-To: <cover.1740846737.git.uwe@kleine-koenig.org>
References: <cover.1740846737.git.uwe@kleine-koenig.org>
Message-ID: <9be5d6592f1b13446808b9cf17a699a048db1069.1740846737.git.uwe@kleine-koenig.org>

rk-usb-loader is the tool advertised in the rockchip documentation to
bootstrap a machine. So enable it in the defconfig.

Signed-off-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
---
 arch/arm/configs/rockchip_v8_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/rockchip_v8_defconfig b/arch/arm/configs/rockchip_v8_defconfig
index 941625394ccf..f1f418872385 100644
--- a/arch/arm/configs/rockchip_v8_defconfig
+++ b/arch/arm/configs/rockchip_v8_defconfig
@@ -157,3 +157,4 @@ CONFIG_FS_BPKFS=y
 CONFIG_FS_UIMAGEFS=y
 CONFIG_LZO_DECOMPRESS=y
 # CONFIG_MISSING_FIRMWARE_ERROR is not set
+CONFIG_RK_USB_LOADER=y
-- 
2.47.1



From uwe at kleine-koenig.org  Sat Mar  1 08:36:21 2025
From: uwe at kleine-koenig.org (=?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?=)
Date: Sat,  1 Mar 2025 17:36:21 +0100
Subject: [PATCH 4/4] WIP: arm64: rockchip: Add support for QNAP's ts-433 4bay NAS
In-Reply-To: <cover.1740846737.git.uwe@kleine-koenig.org>
References: <cover.1740846737.git.uwe@kleine-koenig.org>
Message-ID: <1ec0faa7cbbbe074c328bb8be3dbb571fa4587b2.1740846737.git.uwe@kleine-koenig.org>

The resulting image boots to a prompt using usb booting. But neither
network nor eMMC work :-\

Signed-off-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
---
 Documentation/boards/rockchip.rst      |  1 +
 arch/arm/boards/Makefile               |  1 +
 arch/arm/boards/qnap-tsx33/.gitignore  |  1 +
 arch/arm/boards/qnap-tsx33/Makefile    |  2 ++
 arch/arm/boards/qnap-tsx33/lowlevel.c  | 27 ++++++++++++++++++++++++++
 arch/arm/configs/rockchip_v8_defconfig |  1 +
 arch/arm/dts/Makefile                  |  1 +
 arch/arm/dts/rk3568-qnap-ts433.dts     | 27 ++++++++++++++++++++++++++
 arch/arm/mach-rockchip/Kconfig         |  7 +++++++
 images/Makefile.rockchip               |  1 +
 10 files changed, 69 insertions(+)
 create mode 100644 arch/arm/boards/qnap-tsx33/.gitignore
 create mode 100644 arch/arm/boards/qnap-tsx33/Makefile
 create mode 100644 arch/arm/boards/qnap-tsx33/lowlevel.c
 create mode 100644 arch/arm/dts/rk3568-qnap-ts433.dts

diff --git a/Documentation/boards/rockchip.rst b/Documentation/boards/rockchip.rst
index b2b04abb03cd..a9499e3560dd 100644
--- a/Documentation/boards/rockchip.rst
+++ b/Documentation/boards/rockchip.rst
@@ -61,6 +61,7 @@ Supported Boards
 - Pine64 Quartz64 Model A
 - Radxa ROCK3 Model A
 - Radxa CM3 (RK3566) IO Board
+- QNAP TS-433 NAS
 - Protonic MECSBC
 
 The steps described in the following target the RK3568 and the RK3568 EVB but
diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
index c6104d043297..747676056a45 100644
--- a/arch/arm/boards/Makefile
+++ b/arch/arm/boards/Makefile
@@ -94,6 +94,7 @@ obj-$(CONFIG_MACH_PROTONIC_STM32MP1)		+= protonic-stm32mp1/
 obj-$(CONFIG_MACH_PROTONIC_STM32MP13)		+= protonic-stm32mp13/
 obj-$(CONFIG_MACH_QIL_A9260)			+= qil-a926x/
 obj-$(CONFIG_MACH_QIL_A9G20)			+= qil-a926x/
+obj-$(CONFIG_MACH_QNAP_TSX33)			+= qnap-tsx33/
 obj-$(CONFIG_MACH_RADXA_ROCK)			+= radxa-rock/
 obj-$(CONFIG_MACH_PHYTEC_SOM_RK3288)		+= phytec-som-rk3288/
 obj-$(CONFIG_MACH_REALQ7)			+= datamodul-edm-qmx6/
diff --git a/arch/arm/boards/qnap-tsx33/.gitignore b/arch/arm/boards/qnap-tsx33/.gitignore
new file mode 100644
index 000000000000..f458f794b54c
--- /dev/null
+++ b/arch/arm/boards/qnap-tsx33/.gitignore
@@ -0,0 +1 @@
+sdram-init.bin
diff --git a/arch/arm/boards/qnap-tsx33/Makefile b/arch/arm/boards/qnap-tsx33/Makefile
new file mode 100644
index 000000000000..9961af02a3ea
--- /dev/null
+++ b/arch/arm/boards/qnap-tsx33/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+lwl-y += lowlevel.o
diff --git a/arch/arm/boards/qnap-tsx33/lowlevel.c b/arch/arm/boards/qnap-tsx33/lowlevel.c
new file mode 100644
index 000000000000..f852e8d00a2b
--- /dev/null
+++ b/arch/arm/boards/qnap-tsx33/lowlevel.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <common.h>
+#include <linux/sizes.h>
+#include <asm/barebox-arm-head.h>
+#include <asm/barebox-arm.h>
+#include <mach/rockchip/hardware.h>
+#include <mach/rockchip/atf.h>
+#include <debug_ll.h>
+#include <mach/rockchip/rockchip.h>
+
+extern char __dtb_rk3568_qnap_ts433_start[];
+
+ENTRY_FUNCTION(start_rk3568_qnap_ts433, r0, r1, r2)
+{
+	/*
+	 * Image execution starts at 0x0, but this is used for ATF and
+	 * OP-TEE later, so move away from here.
+	 */
+	if (current_el() == 3)
+		relocate_to_adr_full(RK3568_BAREBOX_LOAD_ADDRESS);
+	else
+		relocate_to_current_adr();
+
+	setup_c();
+
+	rk3568_barebox_entry(__dtb_rk3568_qnap_ts433_start);
+}
diff --git a/arch/arm/configs/rockchip_v8_defconfig b/arch/arm/configs/rockchip_v8_defconfig
index f1f418872385..86f31affa901 100644
--- a/arch/arm/configs/rockchip_v8_defconfig
+++ b/arch/arm/configs/rockchip_v8_defconfig
@@ -4,6 +4,7 @@ CONFIG_MACH_RK3568_BPI_R2PRO=y
 CONFIG_MACH_PINE64_PINETAB2=y
 CONFIG_MACH_PINE64_QUARTZ64=y
 CONFIG_MACH_PROTONIC_MECSBC=y
+CONFIG_MACH_QNAP_TSX33=y
 CONFIG_MACH_RADXA_ROCK3=y
 CONFIG_MACH_RADXA_ROCK5=y
 CONFIG_MACH_RADXA_CM3=y
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index d2de01927824..b4875cc00c91 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -117,6 +117,7 @@ lwl-$(CONFIG_MACH_PROTONIC_STM32MP1) += \
 	stm32mp151-mecio1.dtb.o \
 	stm32mp151-mect1s.dtb.o
 lwl-$(CONFIG_MACH_PROTONIC_STM32MP13) += stm32mp133c-prihmb.dtb.o
+lwl-$(CONFIG_MACH_QNAP_TSX33) += rk3568-qnap-ts433.dtb.o
 lwl-$(CONFIG_MACH_RADXA_ROCK) += rk3188-radxarock.dtb.o
 lwl-$(CONFIG_MACH_RADXA_ROCK3) += rk3568-rock-3a.dtb.o
 lwl-$(CONFIG_MACH_RADXA_ROCK5) += rk3588-rock-5b.dtb.o
diff --git a/arch/arm/dts/rk3568-qnap-ts433.dts b/arch/arm/dts/rk3568-qnap-ts433.dts
new file mode 100644
index 000000000000..05876656b4e2
--- /dev/null
+++ b/arch/arm/dts/rk3568-qnap-ts433.dts
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR MIT)
+
+/dts-v1/;
+#include <arm64/rockchip/rk3568-qnap-ts433.dts>
+#include "rk356x.dtsi"
+
+/ {
+	chosen: chosen {
+		environment-emmc {
+			compatible = "barebox,environment";
+			device-path = &environment_emmc;
+		};
+	};
+};
+
+&sdmmc0 {
+	partitions {
+		compatible = "fixed-partitions";
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		environment_emmc: partition at 408000 {
+			label = "barebox-environment";
+			reg = <0x0 0x408000 0x0 0x8000>;
+		};
+	};
+};
diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index bfbfa7367a3e..f8b0d5e4ec54 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -106,6 +106,13 @@ config MACH_PROTONIC_MECSBC
 	help
 	  Say Y here if you are using a Protonic MECSBC
 
+config MACH_QNAP_TSX33
+	select ARCH_RK3568
+	bool "QNAP TS-433 NAS"
+	help
+	  Select this if you are using a QNAP TS-433 NAS.
+	  <https://www.qnap.com/en-us/product/ts-433>
+
 config MACH_RADXA_ROCK3
 	select ARCH_RK3568
 	bool "Radxa ROCK3"
diff --git a/images/Makefile.rockchip b/images/Makefile.rockchip
index 761c6b814989..2e63e554edce 100644
--- a/images/Makefile.rockchip
+++ b/images/Makefile.rockchip
@@ -35,6 +35,7 @@ $(call build_rockchip_image, CONFIG_MACH_PINE64_PINETAB2, start_pinetab2_v0, pin
 $(call build_rockchip_image, CONFIG_MACH_PINE64_PINETAB2, start_pinetab2_v2, pine64-pinetab2/sdram-init.bin, pinetab2-v2)
 $(call build_rockchip_image, CONFIG_MACH_PINE64_QUARTZ64, start_quartz64a, pine64-quartz64/sdram-init.bin, quartz64a)
 $(call build_rockchip_image, CONFIG_MACH_PROTONIC_MECSBC, start_mecsbc, protonic-mecsbc/sdram-init.bin, mecsbc)
+$(call build_rockchip_image, CONFIG_MACH_QNAP_TSX33, start_rk3568_qnap_ts433, qnap-tsx33/sdram-init.bin, qnap-ts433)
 $(call build_rockchip_image, CONFIG_MACH_RADXA_ROCK3, start_rock3a, radxa-rock3/sdram-init.bin, rock3a)
 $(call build_rockchip_image, CONFIG_MACH_RADXA_ROCK5, start_rock5b, radxa-rock5/sdram-init.bin, rock5b)
 $(call build_rockchip_image, CONFIG_MACH_RADXA_CM3, start_radxa_cm3_io, radxa-cm3/sdram-init.bin, radxa-cm3-io)
-- 
2.47.1



From uwe at kleine-koenig.org  Sat Mar  1 08:36:18 2025
From: uwe at kleine-koenig.org (=?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?=)
Date: Sat,  1 Mar 2025 17:36:18 +0100
Subject: [PATCH 1/4] Documentation: rockchip: Update versions of DDR init blobs
In-Reply-To: <cover.1740846737.git.uwe@kleine-koenig.org>
References: <cover.1740846737.git.uwe@kleine-koenig.org>
Message-ID: <173fcf6bbf3536d13242d4bcb06cea9ef94f1cf9.1740846737.git.uwe@kleine-koenig.org>

Update file names as they are currently available
https://github.com/rockchip-linux/rkbin as of today.

Signed-off-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
---
 Documentation/boards/rockchip.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/boards/rockchip.rst b/Documentation/boards/rockchip.rst
index b94c7a78e115..b2b04abb03cd 100644
--- a/Documentation/boards/rockchip.rst
+++ b/Documentation/boards/rockchip.rst
@@ -75,9 +75,9 @@ The build process needs three binary files which have to be copied from the
 
 .. code-block:: sh
 
-  cp $RKBIN/bin/rk35/rk3568_bl31_v1.34.elf firmware/rk3568-bl31.bin
-  cp $RKBIN/bin/rk35/rk3568_bl32_v2.08.bin firmware/rk3568-bl32.bin
-  cp $RKBIN/bin/rk35/rk3568_ddr_1560MHz_v1.13.bin arch/arm/boards/rockchip-rk3568-evb/sdram-init.bin
+  cp $RKBIN/bin/rk35/rk3568_bl31_v1.44.elf firmware/rk3568-bl31.bin
+  cp $RKBIN/bin/rk35/rk3568_bl32_v2.15.bin firmware/rk3568-bl32.bin
+  cp $RKBIN/bin/rk35/rk3568_ddr_1560MHz_v1.23.bin arch/arm/boards/rockchip-rk3568-evb/sdram-init.bin
 
 With these barebox can be compiled as:
 
-- 
2.47.1



From s.hauer at pengutronix.de  Sun Mar  2 23:28:16 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon,  3 Mar 2025 08:28:16 +0100
Subject: [PATCH] fip: fix missing close() in error path
Message-ID: <20250303072816.3789920-1-s.hauer@pengutronix.de>

The file opened in fip_read_image_from_file() is never closed in the
error paths. Add the missing close() and while at it free the allocated
pointer as well.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 lib/fip.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/fip.c b/lib/fip.c
index 23e82098da..99d6c5c383 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -284,7 +284,7 @@ int fip_parse(struct fip_state *fip,
 static struct fip_image *fip_read_image_from_file(const uuid_t *uuid, const char *filename)
 {
 	struct stat st;
-	struct fip_image *image;
+	struct fip_image *image = NULL;
 	int fd;
 
 	ASSERT(uuid != NULL);
@@ -298,7 +298,7 @@ static struct fip_image *fip_read_image_from_file(const uuid_t *uuid, const char
 
 	if (fstat(fd, &st) == -1) {
 		pr_err("fstat %s: %m\n", filename);
-		return NULL;
+		goto err;
 	}
 
 	image = xzalloc(sizeof(*image));
@@ -306,12 +306,18 @@ static struct fip_image *fip_read_image_from_file(const uuid_t *uuid, const char
 	image->buffer = xmalloc(st.st_size);
 	if (read_full(fd, image->buffer, st.st_size) != st.st_size) {
 		pr_err("Failed to read %s: %m\n", filename);
-		return NULL;
+		goto err;
 	}
 	image->toc_e.size = st.st_size;
 
 	close(fd);
 	return image;
+
+err:
+	close(fd);
+	free(image);
+
+	return NULL;
 }
 
 int fip_pack_images(struct fip_state *fip,
-- 
2.39.5



From a.fatoum at pengutronix.de  Mon Mar  3 00:40:48 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 3 Mar 2025 09:40:48 +0100
Subject: Mount NFSv4.2 filesystem in barebox?
In-Reply-To: <Z8GWfv4oIhB7CDSU@pengutronix.de>
References: <CANH4o6Njc3uHE=NbasRJrRr0W5B89R8MTM_BwGwab7t5fNWuaA@mail.gmail.com>
 <Z6yxUVTp0vGWqs7Q@pengutronix.de>
 <CANH4o6NRK2+ekNe_LrUaoAi8PVbi-MC3hWerv4g6F-WmXmyK5w@mail.gmail.com>
 <Z8GWfv4oIhB7CDSU@pengutronix.de>
Message-ID: <3ba4d5f3-9679-4a32-a3e7-a8c958107df9@pengutronix.de>

Hi,

On 28.02.25 11:57, Sascha Hauer wrote:
> On Fri, Feb 21, 2025 at 12:54:00PM +0100, Martin Wege wrote:
>> On Wed, Feb 12, 2025 at 3:33?PM Sascha Hauer <s.hauer at pengutronix.de> wrote:
>>>
>>> Hi Martin,
>>>
>>> On Tue, Feb 11, 2025 at 01:56:58PM +0100, Martin Wege wrote:
>>>> Hello!
>>>>
>>>> Does barebox have support to mount a NFSv.2 filesystem?
>>>
>>> No, not yet. For NFSv4 we would first need TCP support. While we started
>>> to integrate a TCP stack we are not there yet unfortunately.
>>
>> How long is this going to take?
> 
> I don't think this will happen anytime soon. It's quite some work and
> our bandwidth for adding such a feature without (paying) customer
> demand is limited.
> 
> That said, the lack of NFSv4 support is nagging me personally as well.

We had a discussion about this last year, but it didn't result in any
upstream code yet:
https://lore.barebox.org/barebox/CAAvCNcCZhS8mkvdgcJ2L-eiur+OxgWEXRLnadO_HFyHfSi7WFA at mail.gmail.com/

One question that I still have, is what do you use NFSv4 for?
Is it just for development and your IT is disabling NFSv3?

Do you use it in the field?

Knowing about the use case helps with prioritizing future work.
As it stands, NFS is mostly understood as development feature and
it's expected so far that interested users will be able to provide
a NFSv3 UDP server in their development network.

Thanks,
Ahmad



> 
> Sascha
> 


-- 
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-5555 |


From a.fatoum at pengutronix.de  Mon Mar  3 00:41:53 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 3 Mar 2025 09:41:53 +0100
Subject: [PATCH 1/2] imx-bbu-nand-fcb: do not use hardcoded devicefile
In-Reply-To: <6N27SS.D8B9D3CEGOUH3@gmail.com>
References: <20250221180109.14129-1-stefano.manni@gmail.com>
 <06d40295-264c-4119-a201-f6e045def59d@pengutronix.de>
 <6N27SS.D8B9D3CEGOUH3@gmail.com>
Message-ID: <3a8afe4a-f7e7-4158-b302-09f67dc11d8f@pengutronix.de>

On 24.02.25 16:49, Stefano Manni wrote:
> Hello Ahmad,
> 
> On ven, feb 21 2025 at 18:33:04 +01:00:00, Ahmad Fatoum <a.fatoum at pengutronix.de> wrote:
>> Hello Stefano,
>>
>> On 21.02.25 19:01, Stefano Manni wrote:
>>> ?Device file was hardcoded to "nand0.barebox".
>>> ?This patch harmonize the signature of
>>>
>>> ?imx6_bbu_nand_register_handler()
>>> ?imx7_bbu_nand_register_handler()
>>> ?imx28_bbu_nand_register_handler()
>>>
>>> ?with the other bbu register functions in order to take
>>> ?the devicefile as parameter.
>>
>> Is this this the sole motivation behind the patch or do you
>> intend to actually make use of the ability of varying
>> the devicefile?
> 
> my purpose is to let people use a device/partition different from the hardcoded one.

Can you have multiple NANDs? But yes, customizing partition name can
be useful.

Thanks,
Ahmad

> 
>>
>> Thanks,
>> 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-5555 |


From a.fatoum at pengutronix.de  Mon Mar  3 00:51:12 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 3 Mar 2025 09:51:12 +0100
Subject: [PATCH 0/5] Filesystem memory corruption fixes
In-Reply-To: <Z8AyD_cHzW_Wxcqz@pengutronix.de>
References: <20250219141844.1912413-1-s.hauer@pengutronix.de>
 <174012323334.2354255.16758545638294107895.b4-ty@pengutronix.de>
 <CABMsoEGDcxSCSfdnV0B1dKvvJaQYBYhpAu2R_t31j5g_Q8fVBg@mail.gmail.com>
 <Z8AyD_cHzW_Wxcqz@pengutronix.de>
Message-ID: <0febcf92-f6b9-4717-a374-da93c1b4c205@pengutronix.de>

Hi,

On 27.02.25 10:36, Sascha Hauer wrote:
> On Sat, Feb 22, 2025 at 12:46:18PM -0800, Jonathan Bar Or wrote:
>> Those are awesome, thank you.
>> We intend to publicly disclose March 19th, is that okay?
> 
> Well, this is a public list, so they are already disclosed...

In a way, yes, but most users will probably only find out about this
once their CVE tooling reports that they are using a barebox version
that doesn't fix e.g. CVE-2025-26722.

CVE-2025-26722 (and I assume the others) are reserved right now, but
lack a description of the issue and its possible security implications.

We should probably write down some extra policy here:

  - Should CVE numbers even be mentioned for yet-undisclosed issues?

  - An explicit policy about disclosure timeline. Bugs are fixed all the
    time and I think, it's desirable that disclosure is postponed until
    after a release, so users informed of the issue directly know
    what to do about it. For critical security issues, a point release
    can be done on short notice

@Jonathan, March 19th is ok for us, but we don't object to any earlier
date.

Cheers,
Ahmad

> Sascha
> 
>>
>> Jonathan
>>
>> On Thu, Feb 20, 2025 at 11:33?PM Sascha Hauer <s.hauer at pengutronix.de> wrote:
>>>
>>>
>>> On Wed, 19 Feb 2025 15:18:39 +0100, Sascha Hauer wrote:
>>>> These are some fixes for memory corruptions that can occur on corrupted
>>>> or manipulated filesystems.
>>>>
>>>> In case you use one of the affected filesystems in a secure boot chain
>>>> you should apply these patches.
>>>>
>>>> Normally you shouldn't use a barebox filesystem in a secure boot chain,
>>>> but instead use FIT images on a raw partition. We never made this explicit
>>>> though. Ahmad has done this recently:
>>>>
>>>> [...]
>>>
>>> Applied, thanks!
>>>
>>> [1/5] CVE-2025-26722: fs: squashfs: Ensure positive inode length
>>>       https://git.pengutronix.de/cgit/barebox/commit/?id=6281a871e2c6 (link may not be stable)
>>> [2/5] CVE-2025-26724: fs: cramfs: fix malloc(size + constant) buffer overflow issues
>>>       https://git.pengutronix.de/cgit/barebox/commit/?id=f86e528c8fba (link may not be stable)
>>> [3/5] CVE-2025-26723: fs: ext4: fix malloc(size + constant) buffer overflow issues
>>>       https://git.pengutronix.de/cgit/barebox/commit/?id=51eea5c16fd2 (link may not be stable)
>>> [4/5] CVE-2025-26725: fs: jffs2: fix malloc(size + constant) buffer overflow issues
>>>       https://git.pengutronix.de/cgit/barebox/commit/?id=e7397340359d (link may not be stable)
>>> [5/5] CVE-2025-26721: fs: pstore: fix malloc(size + constant) buffer overflow issues
>>>       https://git.pengutronix.de/cgit/barebox/commit/?id=7563f5722dfd (link may not be stable)
>>>
>>> Best regards,
>>> --
>>> Sascha Hauer <s.hauer at pengutronix.de>
>>>
>>
> 


-- 
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-5555 |


From s.trumtrar at pengutronix.de  Mon Mar  3 00:59:16 2025
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Mon, 03 Mar 2025 09:59:16 +0100
Subject: [PATCH 0/5] SoCFPGA: Arria10: sdram: cleanup and fix DDR driver
Message-ID: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>

When the L4WD0 is left enabled on startup, depending on handoff files
and its PLL settings, the DDR code might hang while waiting for the
calibration to be successful. Rework this code and cleanup the rest of
the driver a little bit while we are at it.

Tested on an Enclustra PE1 board.

Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
---
Steffen Trumtrar (5):
      ARM: SoCFPGA: move wait_on_timeout to generic
      ARM: SoCFPGA: arria10-sdram: cleanup emif_clear
      ARM: SoCFPGA: arria10-sdram: cleanup emif_reset
      ARM: SoCFPGA: arria10-sdram: remove workaround
      ARM: SoCFPGA: arria10-sdram: cleanup ddr_setup

 arch/arm/mach-socfpga/arria10-sdram.c | 196 ++++++----------------------------
 arch/arm/mach-socfpga/arria10-xload.c |  16 ---
 include/mach/socfpga/generic.h        |  16 +++
 3 files changed, 46 insertions(+), 182 deletions(-)
---
base-commit: 2afd1a809f1a41f1dd42b95c2bc0ae74853b475b
change-id: 20250303-v2025-02-0-topic-socfpga-arria10-bf2ce013ebcb

Best regards,
-- 
Steffen Trumtrar <s.trumtrar at pengutronix.de>



From s.trumtrar at pengutronix.de  Mon Mar  3 00:59:17 2025
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Mon, 03 Mar 2025 09:59:17 +0100
Subject: [PATCH 1/5] ARM: SoCFPGA: move wait_on_timeout to generic
In-Reply-To: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
References: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
Message-ID: <20250303-v2025-02-0-topic-socfpga-arria10-v1-1-d66021246a66@pengutronix.de>

To be able to use the __wait_on_timeout macro in more places, move it to
the generic socfpga header.

Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
---
 arch/arm/mach-socfpga/arria10-xload.c | 16 ----------------
 include/mach/socfpga/generic.h        | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/arch/arm/mach-socfpga/arria10-xload.c b/arch/arm/mach-socfpga/arria10-xload.c
index afec55c33a278f7aa7c13d16557881a5e13f38f9..fb87135ca94a1fd12992bc8e7fb9d1725831aad6 100644
--- a/arch/arm/mach-socfpga/arria10-xload.c
+++ b/arch/arm/mach-socfpga/arria10-xload.c
@@ -16,22 +16,6 @@
 #include <mach/socfpga/generic.h>
 #include <linux/sizes.h>
 
-#define __wait_on_timeout(timeout, condition) \
-({								\
-	int __ret = 0;						\
-	int __timeout = timeout;				\
-								\
-	while ((condition)) {					\
-		if (__timeout-- < 0) {				\
-			__ret = -ETIMEDOUT;			\
-			break;					\
-		}						\
-		arria10_kick_l4wd0();                           \
-                __udelay(1);                                    \
-	}							\
-	__ret;							\
-})
-
 int a10_update_bits(unsigned int reg, unsigned int mask,
 		    unsigned int val)
 {
diff --git a/include/mach/socfpga/generic.h b/include/mach/socfpga/generic.h
index 40224897c1d2e05b934cd49963ac4ddeaeb28a25..9891dbe4fe1016ce0732d635fdd06ae7add16ac3 100644
--- a/include/mach/socfpga/generic.h
+++ b/include/mach/socfpga/generic.h
@@ -106,6 +106,22 @@ static inline void __udelay(unsigned us)
 	for (i = 0; i < us * 3; i++);
 }
 
+#define __wait_on_timeout(timeout, condition) \
+({								\
+	int __ret = 0;						\
+	int __timeout = timeout;				\
+								\
+	while ((condition)) {					\
+		if (__timeout-- < 0) {				\
+			__ret = -ETIMEDOUT;			\
+			break;					\
+		}						\
+		arria10_kick_l4wd0();                           \
+		__udelay(1);                                    \
+	}							\
+	__ret;							\
+})
+
 struct socfpga_barebox_part {
 	unsigned int nor_offset;
 	unsigned int nor_size;

-- 
2.45.2



From s.trumtrar at pengutronix.de  Mon Mar  3 00:59:18 2025
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Mon, 03 Mar 2025 09:59:18 +0100
Subject: [PATCH 2/5] ARM: SoCFPGA: arria10-sdram: cleanup emif_clear
In-Reply-To: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
References: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
Message-ID: <20250303-v2025-02-0-topic-socfpga-arria10-v1-2-d66021246a66@pengutronix.de>

Cleanup the emif_clear() function.

Use __wait_on_timeout to kick the watchdog and make the code more readable.

Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
---
 arch/arm/mach-socfpga/arria10-sdram.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/arch/arm/mach-socfpga/arria10-sdram.c b/arch/arm/mach-socfpga/arria10-sdram.c
index 70d4edd9736c786729ba59e7ecad7eb7cfe7f77e..da7d3ea685e238c8c9abda84976a1161edfc4b03 100644
--- a/arch/arm/mach-socfpga/arria10-sdram.c
+++ b/arch/arm/mach-socfpga/arria10-sdram.c
@@ -216,20 +216,14 @@ static int ddr_calibration_es_workaround(void)
 
 static int emif_clear(void)
 {
-	uint32_t s2c;
-	uint32_t i = DDR_MAX_TRIES;
-
 	writel(0, DDR_REG_CORE2SEQ);
-	do {
-		ddr_delay(50);
-		s2c = readl(DDR_REG_SEQ2CORE);
-	} while ((s2c & SEQ2CORE_MASK) && (--i > 0));
 
-	return !i;
+	return __wait_on_timeout(1000, readl(DDR_REG_SEQ2CORE) & SEQ2CORE_MASK);
 }
 static int emif_reset(void)
 {
 	uint32_t c2s, s2c;
+	int ret;
 
 	c2s = readl(DDR_REG_CORE2SEQ);
 	s2c = readl(DDR_REG_SEQ2CORE);
@@ -240,9 +234,12 @@ static int emif_reset(void)
 		readl(IO48_MMR_NIOS2_RESERVE2),
 		readl(IO48_MMR_DRAMSTS));
 
-	if ((s2c & SEQ2CORE_MASK) && emif_clear()) {
-		printf("failed emif_clear()\n");
-		return -1;
+	if (s2c & SEQ2CORE_MASK) {
+		ret = emif_clear();
+		if (ret) {
+			printf("failed emif_clear()\n");
+			return -1;
+		}
 	}
 
 	writel(CORE2SEQ_INT_REQ, DDR_REG_CORE2SEQ);
@@ -254,7 +251,8 @@ static int emif_reset(void)
 		printf("emif_reset interrupt acknowledged\n");
 	}
 
-	if (emif_clear()) {
+	ret = emif_clear();
+	if (ret) {
 		printf("emif_clear() failed\n");
 		return -3;
 	}

-- 
2.45.2



From s.trumtrar at pengutronix.de  Mon Mar  3 00:59:20 2025
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Mon, 03 Mar 2025 09:59:20 +0100
Subject: [PATCH 4/5] ARM: SoCFPGA: arria10-sdram: remove workaround
In-Reply-To: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
References: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
Message-ID: <20250303-v2025-02-0-topic-socfpga-arria10-v1-4-d66021246a66@pengutronix.de>

Early engineering sample silicon needed a workaround for DDR setup. No
supported board has this early silicion, Altera doesn't have this
workaround in their u-boot. Just get rid of this old code.

Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
---
 arch/arm/mach-socfpga/arria10-sdram.c | 125 +---------------------------------
 1 file changed, 2 insertions(+), 123 deletions(-)

diff --git a/arch/arm/mach-socfpga/arria10-sdram.c b/arch/arm/mach-socfpga/arria10-sdram.c
index c28cf50eb55fb97c2dfe52acfbc360784ca3e36b..c6a86f821473c9990f88906bbe4d52ff8987207c 100644
--- a/arch/arm/mach-socfpga/arria10-sdram.c
+++ b/arch/arm/mach-socfpga/arria10-sdram.c
@@ -23,9 +23,6 @@
 #define ARRIA10_NIOS_OCT_DONE	BIT(7)
 #define ARRIA10_NIOS_OCT_ACK	7
 
-/* Engineering sample silicon */
-#define ARRIA10_ES_SILICON_VER	0x00010001
-
 #define DDR_REG_SEQ2CORE        0xFFD0507C
 #define DDR_REG_CORE2SEQ        0xFFD05078
 #define DDR_REG_GPOUT           0xFFD03010
@@ -100,27 +97,6 @@ static int is_sdram_cal_success(void)
 	return readl(ARRIA10_ECC_HMC_OCP_DDRCALSTAT);
 }
 
-static unsigned char ddr_get_bit(uint32_t ereg, unsigned char bit)
-{
-	unsigned int reg = readl(ereg);
-
-	return (reg & (1 << bit)) ? 1 : 0;
-}
-
-static unsigned char ddr_wait_bit(uint32_t ereg, uint32_t bit,
-				  uint32_t expected, uint32_t timeout_usec)
-{
-	unsigned int tmr;
-
-	for (tmr = 0; tmr < timeout_usec; tmr += 100) {
-		__udelay(100);
-		if (ddr_get_bit(ereg, bit) == expected)
-			return 0;
-	}
-
-	return 1;
-}
-
 static void ddr_delay(uint32_t delay)
 {
 	int tmr;
@@ -129,91 +105,6 @@ static void ddr_delay(uint32_t delay)
 		__udelay(1000);
 }
 
-/*
- * Diagram of OCT Workaround:
- *
- * EMIF Core                     HPS Processor              OCT FSM
- * =================================================================
- *
- * seq2core      ==============>
- * [0x?????????]   OCT Request   [0xFFD0507C]
- *
- * core2seq
- * [0x?????????] <==============
- *                 OCT Ready     [0xFFD05078]
- *
- *                               [0xFFD03010] ============> Request
- *                                             OCT Request
- *
- *                               [0xFFD03014] <============ Ready
- *                                              OCT Ready
- * Signal definitions:
- *
- * seq2core[7] - OCT calibration request (act-high)
- * core2seq[7] - Signals OCT FSM is ready (active high)
- * gpout[31]   - EMIF Reset override (active low)
- * gpout[30]   - OCT calibration request (act-high)
- * gpin[31]    - OCT calibration ready (act-high)
- */
-
-static int ddr_calibration_es_workaround(void)
-{
-	ddr_delay(500);
-	/* Step 1 - Initiating Reset Sequence */
-	clrbits_le32(DDR_REG_GPOUT, ARRIA10_EMIF_RST);
-	ddr_delay(10);
-
-	/* Step 2 - Clearing registers to EMIF core */
-	writel(0, DDR_REG_CORE2SEQ);	/*Clear the HPS->NIOS COM reg.*/
-
-	/* Step 3 - Clearing registers to OCT core */
-	clrbits_le32(DDR_REG_GPOUT, ARRIA10_OCT_CAL_REQ);
-	ddr_delay(5);
-
-	/* Step 4 - Taking EMIF out of reset */
-	setbits_le32(DDR_REG_GPOUT, ARRIA10_EMIF_RST);
-	ddr_delay(10);
-
-	/* Step 5 - Waiting for OCT circuitry to come out of reset */
-	if (ddr_wait_bit(DDR_REG_GPIN, ARRIA10_OCT_CAL_ACK, 1, 1000000))
-		return -1;
-
-	/* Step 6 - Allowing EMIF to proceed with OCT calibration */
-	setbits_le32(DDR_REG_CORE2SEQ, ARRIA10_NIOS_OCT_DONE);
-
-	/* Step 7 - Waiting for EMIF request */
-	if (ddr_wait_bit(DDR_REG_SEQ2CORE, ARRIA10_NIOS_OCT_ACK, 1, 2000000))
-		return -2;
-
-	/* Step 8 - Acknowledging EMIF OCT request */
-	clrbits_le32(DDR_REG_CORE2SEQ, ARRIA10_NIOS_OCT_DONE);
-
-	/* Step 9 - Waiting for EMIF response */
-	if (ddr_wait_bit(DDR_REG_SEQ2CORE, ARRIA10_NIOS_OCT_ACK, 0, 2000000))
-		return -3;
-
-	/* Step 10 - Triggering OCT Calibration */
-	setbits_le32(DDR_REG_GPOUT, ARRIA10_OCT_CAL_REQ);
-
-	/* Step 11 - Waiting for OCT response */
-	if (ddr_wait_bit(DDR_REG_GPIN, ARRIA10_OCT_CAL_ACK, 0, 1000))
-		return -4;
-
-	/* Step 12 - Clearing OCT Request bit */
-	clrbits_le32(DDR_REG_GPOUT, ARRIA10_OCT_CAL_REQ);
-
-	/* Step 13 - Waiting for OCT Engine */
-	if (ddr_wait_bit(DDR_REG_GPIN, ARRIA10_OCT_CAL_ACK, 1, 200000))
-		return -5;
-
-	/* Step 14 - Proceeding with EMIF calibration */
-	setbits_le32(DDR_REG_CORE2SEQ, ARRIA10_NIOS_OCT_DONE);
-
-	ddr_delay(100);
-
-	return 0;
-}
-
 static int emif_clear(void)
 {
 	writel(0, DDR_REG_CORE2SEQ);
@@ -271,30 +162,18 @@ static int emif_reset(void)
 
 static int arria10_ddr_setup(void)
 {
-	int i, j, retcode, ddr_setup_complete = 0;
-	int chip_version = readl(ARRIA10_SYSMGR_SILICONID1);
+	int i, j, ddr_setup_complete = 0;
 
 	/* Try 3 times to do a calibration */
 	for (i = 0; (i < 3) && !ddr_setup_complete; i++) {
-		/* Only engineering sample needs calibration workaround */
-		if (ARRIA10_ES_SILICON_VER == chip_version) {
-			retcode = ddr_calibration_es_workaround();
-			if (retcode) {
-				printf("DDRCAL: Failure: %d\n", retcode);
-				continue;
-			}
-		}
-
 		/* A delay to wait for calibration bit to set */
 		for (j = 0; (j < 10) && !ddr_setup_complete; j++) {
 			ddr_delay(500);
 			ddr_setup_complete = is_sdram_cal_success();
 		}
 
-		if (!ddr_setup_complete &&
-			(ARRIA10_ES_SILICON_VER != chip_version)) {
+		if (!ddr_setup_complete)
 			emif_reset();
-		}
 	}
 
 	if (!ddr_setup_complete) {

-- 
2.45.2



From s.trumtrar at pengutronix.de  Mon Mar  3 00:59:21 2025
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Mon, 03 Mar 2025 09:59:21 +0100
Subject: [PATCH 5/5] ARM: SoCFPGA: arria10-sdram: cleanup ddr_setup
In-Reply-To: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
References: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
Message-ID: <20250303-v2025-02-0-topic-socfpga-arria10-v1-5-d66021246a66@pengutronix.de>

Replace the convoluted loop-in-loop code with ad-hoc polling with
__wait_on_timeout. This makes the code more readable and ensures, that
the L4WD0 is kicked as necessary.

If a calibration fails, restart the EMIF, wait for 500ms for the
calibration to complete and check again. Try this for 32 times.

Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
---
 arch/arm/mach-socfpga/arria10-sdram.c | 44 +++++++++++------------------------
 1 file changed, 14 insertions(+), 30 deletions(-)

diff --git a/arch/arm/mach-socfpga/arria10-sdram.c b/arch/arm/mach-socfpga/arria10-sdram.c
index c6a86f821473c9990f88906bbe4d52ff8987207c..eeb94277039dae0394aed180f970a9baa1098229 100644
--- a/arch/arm/mach-socfpga/arria10-sdram.c
+++ b/arch/arm/mach-socfpga/arria10-sdram.c
@@ -91,20 +91,6 @@ static int match_ddr_conf(uint32_t ddr_conf)
 	return 0;
 }
 
-/* Check whether SDRAM is successfully Calibrated */
-static int is_sdram_cal_success(void)
-{
-	return readl(ARRIA10_ECC_HMC_OCP_DDRCALSTAT);
-}
-
-static void ddr_delay(uint32_t delay)
-{
-	int tmr;
-
-	for (tmr = 0; tmr < delay; tmr++)
-		__udelay(1000);
-}
-
 static int emif_clear(void)
 {
 	writel(0, DDR_REG_CORE2SEQ);
@@ -162,26 +148,24 @@ static int emif_reset(void)
 
 static int arria10_ddr_setup(void)
 {
-	int i, j, ddr_setup_complete = 0;
-
-	/* Try 3 times to do a calibration */
-	for (i = 0; (i < 3) && !ddr_setup_complete; i++) {
-		/* A delay to wait for calibration bit to set */
-		for (j = 0; (j < 10) && !ddr_setup_complete; j++) {
-			ddr_delay(500);
-			ddr_setup_complete = is_sdram_cal_success();
-		}
+	int i, ret = 0;
 
-		if (!ddr_setup_complete)
-			emif_reset();
-	}
+	/* Try 32 times to do a calibration */
+	for (i = 0; i < 32; i++) {
+		ret = __wait_on_timeout(1000,
+				!(readl(ARRIA10_ECC_HMC_OCP_DDRCALSTAT)	&
+					BIT(0)));
+		if (!ret)
+			return 0;
 
-	if (!ddr_setup_complete) {
-		puts_ll("Error: Could Not Calibrate SDRAM\n");
-		return -1;
+		ret = emif_reset();
+		if (ret)
+			puts_ll("Error: arria10_ddr_setup: Failed to reset EMIF\n");
+
+		__udelay(500000);
 	}
 
-	return 0;
+	return -ETIMEDOUT;
 }
 
 /* Function to startup the SDRAM*/

-- 
2.45.2



From s.trumtrar at pengutronix.de  Mon Mar  3 00:59:19 2025
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Mon, 03 Mar 2025 09:59:19 +0100
Subject: [PATCH 3/5] ARM: SoCFPGA: arria10-sdram: cleanup emif_reset
In-Reply-To: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
References: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
Message-ID: <20250303-v2025-02-0-topic-socfpga-arria10-v1-3-d66021246a66@pengutronix.de>

Use the __wait_on_timeout code to poll for EMIF reset.

Be sure to clear EMIF if reset fails before trying again.

Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
---
 arch/arm/mach-socfpga/arria10-sdram.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-socfpga/arria10-sdram.c b/arch/arm/mach-socfpga/arria10-sdram.c
index da7d3ea685e238c8c9abda84976a1161edfc4b03..c28cf50eb55fb97c2dfe52acfbc360784ca3e36b 100644
--- a/arch/arm/mach-socfpga/arria10-sdram.c
+++ b/arch/arm/mach-socfpga/arria10-sdram.c
@@ -244,13 +244,16 @@ static int emif_reset(void)
 
 	writel(CORE2SEQ_INT_REQ, DDR_REG_CORE2SEQ);
 
-	if (ddr_wait_bit(DDR_REG_SEQ2CORE, SEQ2CORE_INT_RESP_BIT, 0, 1000000)) {
+	ret = __wait_on_timeout(1000000, readl(DDR_REG_SEQ2CORE) &
+				SEQ2CORE_INT_RESP_BIT);
+	if (ret) {
 		printf("emif_reset failed to see interrupt acknowledge\n");
+		emif_clear();
 		return -2;
-	} else {
-		printf("emif_reset interrupt acknowledged\n");
 	}
 
+	__udelay(1000);
+
 	ret = emif_clear();
 	if (ret) {
 		printf("emif_clear() failed\n");

-- 
2.45.2



From a.fatoum at pengutronix.de  Mon Mar  3 01:12:04 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 3 Mar 2025 10:12:04 +0100
Subject: [PATCH 1/5] ARM: SoCFPGA: move wait_on_timeout to generic
In-Reply-To: <20250303-v2025-02-0-topic-socfpga-arria10-v1-1-d66021246a66@pengutronix.de>
References: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
 <20250303-v2025-02-0-topic-socfpga-arria10-v1-1-d66021246a66@pengutronix.de>
Message-ID: <f8f5ceab-65d0-44a3-bf19-8fce40f56bc3@pengutronix.de>

Hello Steffen,

On 03.03.25 09:59, Steffen Trumtrar wrote:
> To be able to use the __wait_on_timeout macro in more places, move it to
> the generic socfpga header.
> 
> Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
> ---
>  arch/arm/mach-socfpga/arria10-xload.c | 16 ----------------
>  include/mach/socfpga/generic.h        | 16 ++++++++++++++++
>  2 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/arch/arm/mach-socfpga/arria10-xload.c b/arch/arm/mach-socfpga/arria10-xload.c
> index afec55c33a278f7aa7c13d16557881a5e13f38f9..fb87135ca94a1fd12992bc8e7fb9d1725831aad6 100644
> --- a/arch/arm/mach-socfpga/arria10-xload.c
> +++ b/arch/arm/mach-socfpga/arria10-xload.c
> @@ -16,22 +16,6 @@
>  #include <mach/socfpga/generic.h>
>  #include <linux/sizes.h>
>  
> -#define __wait_on_timeout(timeout, condition) \
> -({								\
> -	int __ret = 0;						\
> -	int __timeout = timeout;				\
> -								\
> -	while ((condition)) {					\
> -		if (__timeout-- < 0) {				\
> -			__ret = -ETIMEDOUT;			\
> -			break;					\
> -		}						\
> -		arria10_kick_l4wd0();                           \
> -                __udelay(1);                                    \

Unrelated to your patch. But feeding the watchdog every 1us is
a bit excessive, isn't it?

Cheers,
Ahmad

> -	}							\
> -	__ret;							\
> -})
> -
>  int a10_update_bits(unsigned int reg, unsigned int mask,
>  		    unsigned int val)
>  {
> diff --git a/include/mach/socfpga/generic.h b/include/mach/socfpga/generic.h
> index 40224897c1d2e05b934cd49963ac4ddeaeb28a25..9891dbe4fe1016ce0732d635fdd06ae7add16ac3 100644
> --- a/include/mach/socfpga/generic.h
> +++ b/include/mach/socfpga/generic.h
> @@ -106,6 +106,22 @@ static inline void __udelay(unsigned us)
>  	for (i = 0; i < us * 3; i++);
>  }
>  
> +#define __wait_on_timeout(timeout, condition) \
> +({								\
> +	int __ret = 0;						\
> +	int __timeout = timeout;				\
> +								\
> +	while ((condition)) {					\
> +		if (__timeout-- < 0) {				\
> +			__ret = -ETIMEDOUT;			\
> +			break;					\
> +		}						\
> +		arria10_kick_l4wd0();                           \
> +		__udelay(1);                                    \
> +	}							\
> +	__ret;							\
> +})
> +
>  struct socfpga_barebox_part {
>  	unsigned int nor_offset;
>  	unsigned int nor_size;
> 


-- 
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-5555 |


From s.trumtrar at pengutronix.de  Mon Mar  3 03:11:29 2025
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Mon, 03 Mar 2025 12:11:29 +0100
Subject: [PATCH 1/5] ARM: SoCFPGA: move wait_on_timeout to generic
In-Reply-To: <f8f5ceab-65d0-44a3-bf19-8fce40f56bc3@pengutronix.de> (Ahmad
	Fatoum's message of "Mon, 3 Mar 2025 10:12:04 +0100")
References: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
	<20250303-v2025-02-0-topic-socfpga-arria10-v1-1-d66021246a66@pengutronix.de>
	<f8f5ceab-65d0-44a3-bf19-8fce40f56bc3@pengutronix.de>
Message-ID: <8734fu2wta.fsf@pengutronix.de>


Hi Ahmad,

On 2025-03-03 at 10:12 +01, Ahmad Fatoum <a.fatoum at pengutronix.de> wrote:

> Hello Steffen,
>
> On 03.03.25 09:59, Steffen Trumtrar wrote:
> > To be able to use the __wait_on_timeout macro in more places, move it to
> > the generic socfpga header.
> >
> > Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
> > ---
> >  arch/arm/mach-socfpga/arria10-xload.c | 16 ----------------
> >  include/mach/socfpga/generic.h        | 16 ++++++++++++++++
> >  2 files changed, 16 insertions(+), 16 deletions(-)
> >
> > diff --git a/arch/arm/mach-socfpga/arria10-xload.c b/arch/arm/mach-socfpga/arria10-xload.c
> > index afec55c33a278f7aa7c13d16557881a5e13f38f9..fb87135ca94a1fd12992bc8e7fb9d1725831aad6 100644
> > --- a/arch/arm/mach-socfpga/arria10-xload.c
> > +++ b/arch/arm/mach-socfpga/arria10-xload.c
> > @@ -16,22 +16,6 @@
> >  #include <mach/socfpga/generic.h>
> >  #include <linux/sizes.h>
> >
> > -#define __wait_on_timeout(timeout, condition) \
> > -({								\
> > -	int __ret = 0;						\
> > -	int __timeout = timeout;				\
> > -								\
> > -	while ((condition)) {					\
> > -		if (__timeout-- < 0) {				\
> > -			__ret = -ETIMEDOUT;			\
> > -			break;					\
> > -		}						\
> > -		arria10_kick_l4wd0();                           \
> > -                __udelay(1);                                    \
>
> Unrelated to your patch. But feeding the watchdog every 1us is
> a bit excessive, isn't it?
>

uuh, yes. That should not be necessary.


Thanks,
Steffen


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


From a.fatoum at pengutronix.de  Mon Mar  3 05:28:00 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon,  3 Mar 2025 14:28:00 +0100
Subject: [PATCH master] sandbox: libc_malloc: multiply, not add, args in calloc overflow check
Message-ID: <20250303132800.3164782-1-a.fatoum@pengutronix.de>

libc_malloc is built without access to barebox headers, so instead of
size_mul it's using GCC builtins directly.

The check against BAREBOX_MALLOC_MAX_SIZE should've been done using the
product as indicated by the variable name, but erroneously
__builtin_add_overflow was used instead of __builtin_mul_overflow.

Fixes: 8839004152f7 ("sandbox: libc_malloc: fail allocations exceeding MALLOC_MAX_SIZE")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/os/libc_malloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/os/libc_malloc.c b/arch/sandbox/os/libc_malloc.c
index ac97fc37eee5..dd0f8670ff71 100644
--- a/arch/sandbox/os/libc_malloc.c
+++ b/arch/sandbox/os/libc_malloc.c
@@ -67,7 +67,7 @@ void *barebox_calloc(size_t n, size_t elem_size)
 	size_t product;
 	void *mem = NULL;
 
-	if (!__builtin_add_overflow(n, elem_size, &product) &&
+	if (!__builtin_mul_overflow(n, elem_size, &product) &&
 	    product <= BAREBOX_MALLOC_MAX_SIZE)
 		mem = calloc(n, elem_size);
 	if (!mem)
-- 
2.39.5



From bst at pengutronix.de  Mon Mar  3 06:31:44 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Mon,  3 Mar 2025 15:31:44 +0100
Subject: [PATCH] mfd: rn5t568: add priority to reset_source_set_device()
Message-ID: <20250303143144.2953662-1-bst@pengutronix.de>

30322f4b565 ("reset_source: give reset_source_set_device a priority
parameter") introduced a reset source priority parameter, but forgot
applying a priority the Ricoh RN5T568 PMIC driver's
reset_source_set_device() call.

So apply the default priority 200 here, too.

Fixes this build error:

  drivers/mfd/rn5t568.c: In function 'rn5t568_reset_reason_detect':
  drivers/mfd/rn5t568.c:82:9: error: too few arguments to function 'reset_source_set_device'
     82 |         reset_source_set_device(dev, type);
        |         ^~~~~~~~~~~~~~~~~~~~~~~
  In file included from drivers/mfd/rn5t568.c:17:
  include/reset_source.h:31:6: note: declared here
     31 | void reset_source_set_device(struct device *dev, enum reset_src_type st,
        |      ^~~~~~~~~~~~~~~~~~~~~~~

Fixes: 30322f4b565 ("reset_source: give reset_source_set_device a priority parameter")
Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 drivers/mfd/rn5t568.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/rn5t568.c b/drivers/mfd/rn5t568.c
index 7468338a2d5..e140cea03b0 100644
--- a/drivers/mfd/rn5t568.c
+++ b/drivers/mfd/rn5t568.c
@@ -79,7 +79,7 @@ static int rn5t568_reset_reason_detect(struct device *dev,
 			return -EINVAL;
 	}
 
-	reset_source_set_device(dev, type);
+	reset_source_set_device(dev, type, 200);
 	return 0;
 }
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Mon Mar  3 06:44:17 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 3 Mar 2025 15:44:17 +0100
Subject: [PATCH] mfd: rn5t568: add priority to reset_source_set_device()
In-Reply-To: <20250303143144.2953662-1-bst@pengutronix.de>
References: <20250303143144.2953662-1-bst@pengutronix.de>
Message-ID: <3bb01f7d-f379-49b3-9a1a-250fc9df7ec2@pengutronix.de>

Hello Bastian,

On 03.03.25 15:31, Bastian Krause wrote:
> 30322f4b565 ("reset_source: give reset_source_set_device a priority
> parameter") introduced a reset source priority parameter, but forgot
> applying a priority the Ricoh RN5T568 PMIC driver's
> reset_source_set_device() call.
> 
> So apply the default priority 200 here, too.
> 
> Fixes this build error:
> 
>   drivers/mfd/rn5t568.c: In function 'rn5t568_reset_reason_detect':
>   drivers/mfd/rn5t568.c:82:9: error: too few arguments to function 'reset_source_set_device'
>      82 |         reset_source_set_device(dev, type);
>         |         ^~~~~~~~~~~~~~~~~~~~~~~
>   In file included from drivers/mfd/rn5t568.c:17:
>   include/reset_source.h:31:6: note: declared here
>      31 | void reset_source_set_device(struct device *dev, enum reset_src_type st,
>         |      ^~~~~~~~~~~~~~~~~~~~~~~
> 
> Fixes: 30322f4b565 ("reset_source: give reset_source_set_device a priority parameter")
> Signed-off-by: Bastian Krause <bst at pengutronix.de>

Ouch, sorry for missing the follow-up commit fixing this.

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

We should probably add an allyes build to CI.

Cheers,
Ahmad

> ---
>  drivers/mfd/rn5t568.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mfd/rn5t568.c b/drivers/mfd/rn5t568.c
> index 7468338a2d5..e140cea03b0 100644
> --- a/drivers/mfd/rn5t568.c
> +++ b/drivers/mfd/rn5t568.c
> @@ -79,7 +79,7 @@ static int rn5t568_reset_reason_detect(struct device *dev,
>  			return -EINVAL;
>  	}
>  
> -	reset_source_set_device(dev, type);
> +	reset_source_set_device(dev, type, 200);
>  	return 0;
>  }
>  


-- 
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-5555 |


From s.hauer at pengutronix.de  Tue Mar  4 00:15:25 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 04 Mar 2025 09:15:25 +0100
Subject: [PATCH] mfd: rn5t568: add priority to
 reset_source_set_device()
In-Reply-To: <20250303143144.2953662-1-bst@pengutronix.de>
References: <20250303143144.2953662-1-bst@pengutronix.de>
Message-ID: <174107612558.753249.11909429512529384121.b4-ty@pengutronix.de>


On Mon, 03 Mar 2025 15:31:44 +0100, Bastian Krause wrote:
> 30322f4b565 ("reset_source: give reset_source_set_device a priority
> parameter") introduced a reset source priority parameter, but forgot
> applying a priority the Ricoh RN5T568 PMIC driver's
> reset_source_set_device() call.
> 
> So apply the default priority 200 here, too.
> 
> [...]

Applied, thanks!

[1/1] mfd: rn5t568: add priority to reset_source_set_device()
      https://git.pengutronix.de/cgit/barebox/commit/?id=af8e7ff8a5c5 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar  4 00:16:03 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 04 Mar 2025 09:16:03 +0100
Subject: [PATCH master] sandbox: libc_malloc: multiply, not add, args
 in calloc overflow check
In-Reply-To: <20250303132800.3164782-1-a.fatoum@pengutronix.de>
References: <20250303132800.3164782-1-a.fatoum@pengutronix.de>
Message-ID: <174107616336.753345.12402535592277524479.b4-ty@pengutronix.de>


On Mon, 03 Mar 2025 14:28:00 +0100, Ahmad Fatoum wrote:
> libc_malloc is built without access to barebox headers, so instead of
> size_mul it's using GCC builtins directly.
> 
> The check against BAREBOX_MALLOC_MAX_SIZE should've been done using the
> product as indicated by the variable name, but erroneously
> __builtin_add_overflow was used instead of __builtin_mul_overflow.
> 
> [...]

Applied, thanks!

[1/1] sandbox: libc_malloc: multiply, not add, args in calloc overflow check
      https://git.pengutronix.de/cgit/barebox/commit/?id=75296e2aa356 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar  4 01:15:13 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 4 Mar 2025 10:15:13 +0100
Subject: [PATCH 0/4] Add support for QNAP's ts-433 4bay NAS
In-Reply-To: <cover.1740846737.git.uwe@kleine-koenig.org>
References: <cover.1740846737.git.uwe@kleine-koenig.org>
Message-ID: <Z8bEobxWH6sNRt6B@pengutronix.de>

Hi Uwe,

On Sat, Mar 01, 2025 at 05:36:17PM +0100, Uwe Kleine-K?nig wrote:
> Hello,
> 
> this is the result of my quick effort to make barebox run on QNAP's
> ts-433 4bay NAS. The first 3 patches are IMHO fine to go in. The last
> one adds the new machine. As writting in the commit log the NAS boots
> with the resulting image, but neither network nor eMMC work.
> 
> I also tried adding
> 
> 	writel(RK_SETBITS(0x50), 0xfdc20140)
> 
> in lowlevel.c, but that didn't make a difference. I'm open for other
> ideas about what bit is missing.

dts/src/arm64/rockchip/rk3568-qnap-ts433.dts lacks the pinctrl nodes for
the sdhci controller. It might be that it works when booting from eMMC,
but not when booting from USB.

No idea for networking though.

Regards,
 Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Tue Mar  4 01:15:52 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 04 Mar 2025 10:15:52 +0100
Subject: (subset) [PATCH 0/4] Add support for QNAP's ts-433 4bay NAS
In-Reply-To: <cover.1740846737.git.uwe@kleine-koenig.org>
References: <cover.1740846737.git.uwe@kleine-koenig.org>
Message-ID: <174107975299.815779.7341360670504446778.b4-ty@pengutronix.de>


On Sat, 01 Mar 2025 17:36:17 +0100, Uwe Kleine-K?nig wrote:
> this is the result of my quick effort to make barebox run on QNAP's
> ts-433 4bay NAS. The first 3 patches are IMHO fine to go in. The last
> one adds the new machine. As writting in the commit log the NAS boots
> with the resulting image, but neither network nor eMMC work.
> 
> I also tried adding
> 
> [...]

Applied, thanks!

[1/4] Documentation: rockchip: Update versions of DDR init blobs
      https://git.pengutronix.de/cgit/barebox/commit/?id=4c0953db0f2d (link may not be stable)
[2/4] arm64: rockchip: Refresh rockchip_v8_defconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=7a94e43d0862 (link may not be stable)
[3/4] arm64: rockchip: Enable rk-usb-loader in rockchip_v8_defconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=12ba84b2a475 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From jre at pengutronix.de  Tue Mar  4 08:24:15 2025
From: jre at pengutronix.de (Jonas Rebmann)
Date: Tue, 04 Mar 2025 17:24:15 +0100
Subject: [PATCH] ARM: boards: Add support for phyBOARD-Segin i.MX 93
Message-ID: <20250304-phyboard-segin-imx93-v1-1-8677740a79de@pengutronix.de>

This patch adds support for the phyBOARD-Segin i.MX 93 and the phyCORE
i.MX 93 SoM it is based upon.

Note that support is only provided for the standard configuration
featuring 1GB RAM as testing was only possible on that variant and only
the single-configuration lpddr4_timing.c as initially committed to
u-boot in 7c1f8ce3956 worked.

The 1GB configuration from later revisions results in a freeze during
dram setup.

The following functionality has been tested:
 - barebox starts via imxusbloader, tftp and emmc
 - both ethertnet interfaces work
 - barebox_update to emmc
 - boot kernel via network
 - USB OTG
 - USB mass storage on USB Host Port
 - reset

Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
---
 arch/arm/boards/Makefile                           |    1 +
 arch/arm/boards/phytec-phycore-imx93/Makefile      |    2 +
 arch/arm/boards/phytec-phycore-imx93/board.c       |   56 +
 arch/arm/boards/phytec-phycore-imx93/lowlevel.c    |   60 +
 .../boards/phytec-phycore-imx93/lpddr4_timing.c    | 1546 ++++++++++++++++++++
 arch/arm/configs/imx_v8_defconfig                  |    1 +
 arch/arm/configs/multi_v8_defconfig                |    1 +
 arch/arm/dts/Makefile                              |    1 +
 arch/arm/dts/imx93-phyboard-segin-downstream.dtsi  |  269 ++++
 arch/arm/dts/imx93-phyboard-segin.dts              |   28 +
 arch/arm/mach-imx/Kconfig                          |    9 +
 images/Makefile.imx                                |    4 +
 12 files changed, 1978 insertions(+)

diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
index c6104d04329774655712db5aaf6df671fd74142e..1e67b304f1855df2c32305638c3d9029ed0994c6 100644
--- a/arch/arm/boards/Makefile
+++ b/arch/arm/boards/Makefile
@@ -78,6 +78,7 @@ obj-$(CONFIG_MACH_PCM038)			+= phytec-phycore-imx27/
 obj-$(CONFIG_MACH_PHYTEC_SOM_AM335X)		+= phytec-som-am335x/
 obj-$(CONFIG_MACH_PHYTEC_SOM_IMX6)		+= phytec-som-imx6/
 obj-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX7)		+= phytec-phycore-imx7/
+obj-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX93)		+= phytec-phycore-imx93/
 obj-$(CONFIG_MACH_PHYTEC_PHYCORE_STM32MP1)	+= phytec-phycore-stm32mp1/
 obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MM)		+= phytec-som-imx8mm/
 obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MQ)		+= phytec-som-imx8mq/
diff --git a/arch/arm/boards/phytec-phycore-imx93/Makefile b/arch/arm/boards/phytec-phycore-imx93/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..ae29bb9249e62cb649e21e580559383fa9d18386
--- /dev/null
+++ b/arch/arm/boards/phytec-phycore-imx93/Makefile
@@ -0,0 +1,2 @@
+lwl-y += lowlevel.o lpddr4_timing.o
+obj-y += board.o
diff --git a/arch/arm/boards/phytec-phycore-imx93/board.c b/arch/arm/boards/phytec-phycore-imx93/board.c
new file mode 100644
index 0000000000000000000000000000000000000000..149248ca654624826d0e8f6fe0f1f42c2747e248
--- /dev/null
+++ b/arch/arm/boards/phytec-phycore-imx93/board.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#define pr_fmt(fmt) "phyCORE imx93: " fmt
+
+#include <common.h>
+#include <init.h>
+#include <linux/kernel.h>
+#include <environment.h>
+#include <mfd/pca9450.h>
+#include <deep-probe.h>
+#include <mach/imx/bbu.h>
+#include <linux/pinctrl/consumer.h>
+
+static void phycore_imx93_init_pmic(struct regmap *map)
+{
+	/* set WDOG_B_CFG to cold reset */
+	regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
+}
+
+static int phycore_imx93_probe(struct device *dev)
+{
+	struct device_node *np;
+
+	pca9450_register_init_callback(phycore_imx93_init_pmic);
+
+	/*
+	 * The phy on the EQOS has its MDIO lines connected to the FEC. The phy
+	 * registers can only be successfully read when the EQOS pinctrl setup
+	 * has been done. The phys on the FEC MDIO bus are probed during the
+	 * FEC driver probe, so do the EQOS pinctrl setup here to make sure it's
+	 * done before the FEC probes.
+	 */
+	np = of_find_compatible_node(dev->of_node, NULL, "nxp,imx93-dwmac-eqos");
+	BUG_ON(!np);
+	of_pinctrl_select_state_default(np);
+
+	imx9_bbu_internal_mmcboot_register_handler("eMMC", "/dev/mmc0", 0);
+
+	return 0;
+}
+
+static const struct of_device_id phycore_imx93_of_match[] = {
+	{
+		.compatible = "phytec,imx93-phyboard-segin",
+	},
+	{ /* sentinel */ },
+};
+
+static struct driver phycore_imx93_board_driver = {
+	.name = "board-phycore_imx93",
+	.probe = phycore_imx93_probe,
+	.of_compatible = phycore_imx93_of_match,
+};
+coredevice_platform_driver(phycore_imx93_board_driver);
+
+BAREBOX_DEEP_PROBE_ENABLE(phycore_imx93_of_match);
diff --git a/arch/arm/boards/phytec-phycore-imx93/lowlevel.c b/arch/arm/boards/phytec-phycore-imx93/lowlevel.c
new file mode 100644
index 0000000000000000000000000000000000000000..7678d2f2633ea07e532684f999b62ddecc2b79dc
--- /dev/null
+++ b/arch/arm/boards/phytec-phycore-imx93/lowlevel.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <common.h>
+#include <debug_ll.h>
+#include <mach/imx/debug_ll.h>
+#include <mach/imx/generic.h>
+#include <mach/imx/xload.h>
+#include <asm/barebox-arm.h>
+#include <soc/imx9/ddr.h>
+#include <mach/imx/atf.h>
+#include <mach/imx/xload.h>
+#include <mach/imx/romapi.h>
+#include <mach/imx/esdctl.h>
+#include <pbl/i2c.h>
+
+extern char __dtb_z_imx93_phyboard_segin_start[];
+extern struct dram_timing_info dram_timing;
+
+static noinline void phycore_imx93_continue(void)
+{
+	void *base = IOMEM(MX9_UART1_BASE_ADDR);
+	void *muxbase = IOMEM(MX9_IOMUXC_BASE_ADDR);
+	void *fdt;
+
+	/* uart iomux-setup */
+	writel(0x0, muxbase + 0x0184); /* TX */
+	writel(0x0, muxbase + 0x0180); /* RX */
+
+	imx9_uart_setup(IOMEM(base));
+	pbl_set_putc(lpuart32_putc, base + 0x10);
+
+	if (current_el() == 3) {
+
+		/*
+		 * Current u-boot master has two dram variants but neither
+		 * where found to work here. As a workaround, lpddr4_timing.c
+		 * is based on the initial single config version
+		 */
+
+		imx93_ddr_init(&dram_timing, DRAM_TYPE_LPDDR4);
+		imx93_load_and_start_image_via_tfa();
+	}
+
+	fdt = __dtb_z_imx93_phyboard_segin_start;
+
+	imx93_barebox_entry(fdt);
+
+	__builtin_unreachable();
+}
+
+ENTRY_FUNCTION(start_imx93_phyboard_segin, r0, r1, r2)
+{
+	if (current_el() == 3)
+		imx93_cpu_lowlevel_init();
+
+	relocate_to_current_adr();
+	setup_c();
+
+	phycore_imx93_continue();
+}
diff --git a/arch/arm/boards/phytec-phycore-imx93/lpddr4_timing.c b/arch/arm/boards/phytec-phycore-imx93/lpddr4_timing.c
new file mode 100644
index 0000000000000000000000000000000000000000..6ff5dc158ee1135d8024223f7c672ecde6cfc6c1
--- /dev/null
+++ b/arch/arm/boards/phytec-phycore-imx93/lpddr4_timing.c
@@ -0,0 +1,1546 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2023 NXP
+ * Copyright (C) 2023 PHYTEC Messtechnik GmbH
+ * Christoph Stoidner <c.stoidner at phytec.de>
+ *
+ * Code generated with DDR Tool v1.0.0.
+ */
+
+#include <linux/kernel.h>
+#include <soc/imx9/ddr.h>
+
+static struct dram_cfg_param ddr_ddrc_cfg[] = {
+	/** Initialize DDRC registers **/
+	{0x4e300110, 0x44100001},
+	{0x4e300000, 0x8000bf},
+	{0x4e300008, 0x0},
+	{0x4e300080, 0x80000412},
+	{0x4e300084, 0x0},
+	{0x4e300114, 0x1002},
+	{0x4e300260, 0x4080},
+	{0x4e300f04, 0x80},
+	{0x4e300800, 0x43b30002},
+	{0x4e300804, 0x1f1f1f1f},
+	{0x4e301000, 0x0},
+	{0x4e301240, 0x0},
+	{0x4e301244, 0x0},
+	{0x4e301248, 0x0},
+	{0x4e30124c, 0x0},
+	{0x4e301250, 0x0},
+	{0x4e301254, 0x0},
+	{0x4e301258, 0x0},
+	{0x4e30125c, 0x0},
+
+};
+
+/* dram fsp cfg */
+static struct dram_fsp_cfg ddr_dram_fsp_cfg[] = {
+	{
+		{
+			{0x4e300100, 0x24A0421B},
+			{0x4e300104, 0xF8EE001B},
+			{0x4e300108, 0x2F263233},
+			{0x4e30010C, 0x0005E18B},
+			{0x4e300124, 0x1C770000},
+			{0x4e300160, 0x00009102},
+			{0x4e30016C, 0x35F00000},
+			{0x4e300170, 0x8B0B0608},
+			{0x4e300250, 0x00000028},
+			{0x4e300254, 0x00FE00FE},
+			{0x4e300258, 0x00000008},
+			{0x4e30025C, 0x00000400},
+			{0x4e300300, 0x224F2215},
+			{0x4e300304, 0x00FE2213},
+			{0x4e300308, 0x0A3C0E3C},
+		},
+		{
+			{0x01, 0xE4},
+			{0x02, 0x36},
+			{0x03, 0xF2},
+			{0x0b, 0x46},
+			{0x0c, 0x11},
+			{0x0e, 0x11},
+			{0x16, 0x04},
+		},
+		0,
+	},
+
+};
+
+/* PHY Initialize Configuration */
+static struct dram_cfg_param ddr_ddrphy_cfg[] = {
+	{0x100a0, 0x0},
+	{0x100a1, 0x1},
+	{0x100a2, 0x2},
+	{0x100a3, 0x3},
+	{0x100a4, 0x4},
+	{0x100a5, 0x5},
+	{0x100a6, 0x6},
+	{0x100a7, 0x7},
+	{0x110a0, 0x0},
+	{0x110a1, 0x1},
+	{0x110a2, 0x2},
+	{0x110a3, 0x3},
+	{0x110a4, 0x4},
+	{0x110a5, 0x5},
+	{0x110a6, 0x6},
+	{0x110a7, 0x7},
+	{0x1005f, 0x5ff},
+	{0x1015f, 0x5ff},
+	{0x1105f, 0x5ff},
+	{0x1115f, 0x5ff},
+	{0x55, 0x1ff},
+	{0x1055, 0x1ff},
+	{0x2055, 0x1ff},
+	{0x200c5, 0x19},
+	{0x2002e, 0x2},
+	{0x90204, 0x0},
+	{0x20024, 0x1e3},
+	{0x2003a, 0x2},
+	{0x2007d, 0x212},
+	{0x2007c, 0x61},
+	{0x20056, 0x3},
+	{0x1004d, 0x600},
+	{0x1014d, 0x600},
+	{0x1104d, 0x600},
+	{0x1114d, 0x600},
+	{0x10049, 0xe00},
+	{0x10149, 0xe00},
+	{0x11049, 0xe00},
+	{0x11149, 0xe00},
+	{0x43, 0x60},
+	{0x1043, 0x60},
+	{0x2043, 0x60},
+	{0x20018, 0x1},
+	{0x20075, 0x4},
+	{0x20050, 0x0},
+	{0x2009b, 0x2},
+	{0x20008, 0x3a5},
+	{0x20088, 0x9},
+	{0x200b2, 0x10c},
+	{0x10043, 0x5a1},
+	{0x10143, 0x5a1},
+	{0x11043, 0x5a1},
+	{0x11143, 0x5a1},
+	{0x200fa, 0x2},
+	{0x20019, 0x1},
+	{0x200f0, 0x600},
+	{0x200f1, 0x0},
+	{0x200f2, 0x4444},
+	{0x200f3, 0x8888},
+	{0x200f4, 0x5655},
+	{0x200f5, 0x0},
+	{0x200f6, 0x0},
+	{0x200f7, 0xf000},
+	{0x20025, 0x0},
+	{0x2002d, 0x1},
+	{0x2002c, 0x0},
+	{0x20021, 0x0},
+	{0x200c7, 0x21},
+	{0x1200c7, 0x21},
+	{0x200ca, 0x24},
+	{0x1200ca, 0x24},
+
+};
+
+/* ddr phy trained csr */
+static struct dram_cfg_param ddr_ddrphy_trained_csr[] = {
+	{0x1005f, 0x0},
+	{0x1015f, 0x0},
+	{0x1105f, 0x0},
+	{0x1115f, 0x0},
+	{0x55, 0x0},
+	{0x1055, 0x0},
+	{0x2055, 0x0},
+	{0x200c5, 0x0},
+	{0x2002e, 0x0},
+	{0x90204, 0x0},
+	{0x20024, 0x0},
+	{0x2003a, 0x0},
+	{0x2007d, 0x0},
+	{0x2007c, 0x0},
+	{0x20056, 0x0},
+	{0x1004d, 0x0},
+	{0x1014d, 0x0},
+	{0x1104d, 0x0},
+	{0x1114d, 0x0},
+	{0x10049, 0x0},
+	{0x10149, 0x0},
+	{0x11049, 0x0},
+	{0x11149, 0x0},
+	{0x43, 0x0},
+	{0x1043, 0x0},
+	{0x2043, 0x0},
+	{0x20018, 0x0},
+	{0x20075, 0x0},
+	{0x20050, 0x0},
+	{0x2009b, 0x0},
+	{0x20008, 0x0},
+	{0x20088, 0x0},
+	{0x200b2, 0x0},
+	{0x10043, 0x0},
+	{0x10143, 0x0},
+	{0x11043, 0x0},
+	{0x11143, 0x0},
+	{0x200fa, 0x0},
+	{0x20019, 0x0},
+	{0x200f0, 0x0},
+	{0x200f1, 0x0},
+	{0x200f2, 0x0},
+	{0x200f3, 0x0},
+	{0x200f4, 0x0},
+	{0x200f5, 0x0},
+	{0x200f6, 0x0},
+	{0x200f7, 0x0},
+	{0x20025, 0x0},
+	{0x2002d, 0x0},
+	{0x2002c, 0x0},
+	{0xd0000, 0x0},
+	{0x90000, 0x0},
+	{0x90001, 0x0},
+	{0x90002, 0x0},
+	{0x90003, 0x0},
+	{0x90004, 0x0},
+	{0x90005, 0x0},
+	{0x90029, 0x0},
+	{0x9002a, 0x0},
+	{0x9002b, 0x0},
+	{0x9002c, 0x0},
+	{0x9002d, 0x0},
+	{0x9002e, 0x0},
+	{0x9002f, 0x0},
+	{0x90030, 0x0},
+	{0x90031, 0x0},
+	{0x90032, 0x0},
+	{0x90033, 0x0},
+	{0x90034, 0x0},
+	{0x90035, 0x0},
+	{0x90036, 0x0},
+	{0x90037, 0x0},
+	{0x90038, 0x0},
+	{0x90039, 0x0},
+	{0x9003a, 0x0},
+	{0x9003b, 0x0},
+	{0x9003c, 0x0},
+	{0x9003d, 0x0},
+	{0x9003e, 0x0},
+	{0x9003f, 0x0},
+	{0x90040, 0x0},
+	{0x90041, 0x0},
+	{0x90042, 0x0},
+	{0x90043, 0x0},
+	{0x90044, 0x0},
+	{0x90045, 0x0},
+	{0x90046, 0x0},
+	{0x90047, 0x0},
+	{0x90048, 0x0},
+	{0x90049, 0x0},
+	{0x9004a, 0x0},
+	{0x9004b, 0x0},
+	{0x9004c, 0x0},
+	{0x9004d, 0x0},
+	{0x9004e, 0x0},
+	{0x9004f, 0x0},
+	{0x90050, 0x0},
+	{0x90051, 0x0},
+	{0x90052, 0x0},
+	{0x90053, 0x0},
+	{0x90054, 0x0},
+	{0x90055, 0x0},
+	{0x90056, 0x0},
+	{0x90057, 0x0},
+	{0x90058, 0x0},
+	{0x90059, 0x0},
+	{0x9005a, 0x0},
+	{0x9005b, 0x0},
+	{0x9005c, 0x0},
+	{0x9005d, 0x0},
+	{0x9005e, 0x0},
+	{0x9005f, 0x0},
+	{0x90060, 0x0},
+	{0x90061, 0x0},
+	{0x90062, 0x0},
+	{0x90063, 0x0},
+	{0x90064, 0x0},
+	{0x90065, 0x0},
+	{0x90066, 0x0},
+	{0x90067, 0x0},
+	{0x90068, 0x0},
+	{0x90069, 0x0},
+	{0x9006a, 0x0},
+	{0x9006b, 0x0},
+	{0x9006c, 0x0},
+	{0x9006d, 0x0},
+	{0x9006e, 0x0},
+	{0x9006f, 0x0},
+	{0x90070, 0x0},
+	{0x90071, 0x0},
+	{0x90072, 0x0},
+	{0x90073, 0x0},
+	{0x90074, 0x0},
+	{0x90075, 0x0},
+	{0x90076, 0x0},
+	{0x90077, 0x0},
+	{0x90078, 0x0},
+	{0x90079, 0x0},
+	{0x9007a, 0x0},
+	{0x9007b, 0x0},
+	{0x9007c, 0x0},
+	{0x9007d, 0x0},
+	{0x9007e, 0x0},
+	{0x9007f, 0x0},
+	{0x90080, 0x0},
+	{0x90081, 0x0},
+	{0x90082, 0x0},
+	{0x90083, 0x0},
+	{0x90084, 0x0},
+	{0x90085, 0x0},
+	{0x90086, 0x0},
+	{0x90087, 0x0},
+	{0x90088, 0x0},
+	{0x90089, 0x0},
+	{0x9008a, 0x0},
+	{0x9008b, 0x0},
+	{0x9008c, 0x0},
+	{0x9008d, 0x0},
+	{0x9008e, 0x0},
+	{0x9008f, 0x0},
+	{0x90090, 0x0},
+	{0x90091, 0x0},
+	{0x90092, 0x0},
+	{0x90093, 0x0},
+	{0x90094, 0x0},
+	{0x90095, 0x0},
+	{0x90096, 0x0},
+	{0x90097, 0x0},
+	{0x90098, 0x0},
+	{0x90099, 0x0},
+	{0x9009a, 0x0},
+	{0x9009b, 0x0},
+	{0x9009c, 0x0},
+	{0x9009d, 0x0},
+	{0x9009e, 0x0},
+	{0x9009f, 0x0},
+	{0x900a0, 0x0},
+	{0x900a1, 0x0},
+	{0x900a2, 0x0},
+	{0x900a3, 0x0},
+	{0x900a4, 0x0},
+	{0x900a5, 0x0},
+	{0x900a6, 0x0},
+	{0x900a7, 0x0},
+	{0x900a8, 0x0},
+	{0x900a9, 0x0},
+	{0x40000, 0x0},
+	{0x40020, 0x0},
+	{0x40040, 0x0},
+	{0x40060, 0x0},
+	{0x40001, 0x0},
+	{0x40021, 0x0},
+	{0x40041, 0x0},
+	{0x40061, 0x0},
+	{0x40002, 0x0},
+	{0x40022, 0x0},
+	{0x40042, 0x0},
+	{0x40062, 0x0},
+	{0x40003, 0x0},
+	{0x40023, 0x0},
+	{0x40043, 0x0},
+	{0x40063, 0x0},
+	{0x40004, 0x0},
+	{0x40024, 0x0},
+	{0x40044, 0x0},
+	{0x40064, 0x0},
+	{0x40005, 0x0},
+	{0x40025, 0x0},
+	{0x40045, 0x0},
+	{0x40065, 0x0},
+	{0x40006, 0x0},
+	{0x40026, 0x0},
+	{0x40046, 0x0},
+	{0x40066, 0x0},
+	{0x40007, 0x0},
+	{0x40027, 0x0},
+	{0x40047, 0x0},
+	{0x40067, 0x0},
+	{0x40008, 0x0},
+	{0x40028, 0x0},
+	{0x40048, 0x0},
+	{0x40068, 0x0},
+	{0x40009, 0x0},
+	{0x40029, 0x0},
+	{0x40049, 0x0},
+	{0x40069, 0x0},
+	{0x4000a, 0x0},
+	{0x4002a, 0x0},
+	{0x4004a, 0x0},
+	{0x4006a, 0x0},
+	{0x4000b, 0x0},
+	{0x4002b, 0x0},
+	{0x4004b, 0x0},
+	{0x4006b, 0x0},
+	{0x4000c, 0x0},
+	{0x4002c, 0x0},
+	{0x4004c, 0x0},
+	{0x4006c, 0x0},
+	{0x4000d, 0x0},
+	{0x4002d, 0x0},
+	{0x4004d, 0x0},
+	{0x4006d, 0x0},
+	{0x4000e, 0x0},
+	{0x4002e, 0x0},
+	{0x4004e, 0x0},
+	{0x4006e, 0x0},
+	{0x4000f, 0x0},
+	{0x4002f, 0x0},
+	{0x4004f, 0x0},
+	{0x4006f, 0x0},
+	{0x40010, 0x0},
+	{0x40030, 0x0},
+	{0x40050, 0x0},
+	{0x40070, 0x0},
+	{0x40011, 0x0},
+	{0x40031, 0x0},
+	{0x40051, 0x0},
+	{0x40071, 0x0},
+	{0x40012, 0x0},
+	{0x40032, 0x0},
+	{0x40052, 0x0},
+	{0x40072, 0x0},
+	{0x40013, 0x0},
+	{0x40033, 0x0},
+	{0x40053, 0x0},
+	{0x40073, 0x0},
+	{0x40014, 0x0},
+	{0x40034, 0x0},
+	{0x40054, 0x0},
+	{0x40074, 0x0},
+	{0x40015, 0x0},
+	{0x40035, 0x0},
+	{0x40055, 0x0},
+	{0x40075, 0x0},
+	{0x40016, 0x0},
+	{0x40036, 0x0},
+	{0x40056, 0x0},
+	{0x40076, 0x0},
+	{0x40017, 0x0},
+	{0x40037, 0x0},
+	{0x40057, 0x0},
+	{0x40077, 0x0},
+	{0x40018, 0x0},
+	{0x40038, 0x0},
+	{0x40058, 0x0},
+	{0x40078, 0x0},
+	{0x40019, 0x0},
+	{0x40039, 0x0},
+	{0x40059, 0x0},
+	{0x40079, 0x0},
+	{0x4001a, 0x0},
+	{0x4003a, 0x0},
+	{0x4005a, 0x0},
+	{0x4007a, 0x0},
+	{0x900aa, 0x0},
+	{0x900ab, 0x0},
+	{0x900ac, 0x0},
+	{0x900ad, 0x0},
+	{0x900ae, 0x0},
+	{0x900af, 0x0},
+	{0x900b0, 0x0},
+	{0x900b1, 0x0},
+	{0x900b2, 0x0},
+	{0x900b3, 0x0},
+	{0x900b4, 0x0},
+	{0x900b5, 0x0},
+	{0x900b6, 0x0},
+	{0x900b7, 0x0},
+	{0x900b8, 0x0},
+	{0x900b9, 0x0},
+	{0x900ba, 0x0},
+	{0x900bb, 0x0},
+	{0x900bc, 0x0},
+	{0x900bd, 0x0},
+	{0x900be, 0x0},
+	{0x900bf, 0x0},
+	{0x900c0, 0x0},
+	{0x900c1, 0x0},
+	{0x900c2, 0x0},
+	{0x900c3, 0x0},
+	{0x900c4, 0x0},
+	{0x900c5, 0x0},
+	{0x900c6, 0x0},
+	{0x900c7, 0x0},
+	{0x900c8, 0x0},
+	{0x900c9, 0x0},
+	{0x900ca, 0x0},
+	{0x900cb, 0x0},
+	{0x900cc, 0x0},
+	{0x900cd, 0x0},
+	{0x900ce, 0x0},
+	{0x900cf, 0x0},
+	{0x900d0, 0x0},
+	{0x900d1, 0x0},
+	{0x900d2, 0x0},
+	{0x900d3, 0x0},
+	{0x900d4, 0x0},
+	{0x900d5, 0x0},
+	{0x900d6, 0x0},
+	{0x900d7, 0x0},
+	{0x900d8, 0x0},
+	{0x900d9, 0x0},
+	{0x900da, 0x0},
+	{0x900db, 0x0},
+	{0x900dc, 0x0},
+	{0x900dd, 0x0},
+	{0x900de, 0x0},
+	{0x900df, 0x0},
+	{0x900e0, 0x0},
+	{0x900e1, 0x0},
+	{0x900e2, 0x0},
+	{0x900e3, 0x0},
+	{0x900e4, 0x0},
+	{0x900e5, 0x0},
+	{0x900e6, 0x0},
+	{0x900e7, 0x0},
+	{0x900e8, 0x0},
+	{0x900e9, 0x0},
+	{0x900ea, 0x0},
+	{0x900eb, 0x0},
+	{0x900ec, 0x0},
+	{0x900ed, 0x0},
+	{0x900ee, 0x0},
+	{0x900ef, 0x0},
+	{0x900f0, 0x0},
+	{0x900f1, 0x0},
+	{0x900f2, 0x0},
+	{0x900f3, 0x0},
+	{0x900f4, 0x0},
+	{0x900f5, 0x0},
+	{0x900f6, 0x0},
+	{0x900f7, 0x0},
+	{0x900f8, 0x0},
+	{0x900f9, 0x0},
+	{0x900fa, 0x0},
+	{0x900fb, 0x0},
+	{0x900fc, 0x0},
+	{0x900fd, 0x0},
+	{0x900fe, 0x0},
+	{0x900ff, 0x0},
+	{0x90100, 0x0},
+	{0x90101, 0x0},
+	{0x90102, 0x0},
+	{0x90103, 0x0},
+	{0x90104, 0x0},
+	{0x90105, 0x0},
+	{0x90106, 0x0},
+	{0x90107, 0x0},
+	{0x90108, 0x0},
+	{0x90109, 0x0},
+	{0x9010a, 0x0},
+	{0x9010b, 0x0},
+	{0x9010c, 0x0},
+	{0x9010d, 0x0},
+	{0x9010e, 0x0},
+	{0x9010f, 0x0},
+	{0x90110, 0x0},
+	{0x90111, 0x0},
+	{0x90112, 0x0},
+	{0x90113, 0x0},
+	{0x90114, 0x0},
+	{0x90115, 0x0},
+	{0x90116, 0x0},
+	{0x90117, 0x0},
+	{0x90118, 0x0},
+	{0x90119, 0x0},
+	{0x9011a, 0x0},
+	{0x9011b, 0x0},
+	{0x9011c, 0x0},
+	{0x9011d, 0x0},
+	{0x9011e, 0x0},
+	{0x9011f, 0x0},
+	{0x90120, 0x0},
+	{0x90121, 0x0},
+	{0x90122, 0x0},
+	{0x90123, 0x0},
+	{0x90124, 0x0},
+	{0x90125, 0x0},
+	{0x90126, 0x0},
+	{0x90127, 0x0},
+	{0x90128, 0x0},
+	{0x90129, 0x0},
+	{0x9012a, 0x0},
+	{0x9012b, 0x0},
+	{0x9012c, 0x0},
+	{0x9012d, 0x0},
+	{0x9012e, 0x0},
+	{0x9012f, 0x0},
+	{0x90130, 0x0},
+	{0x90131, 0x0},
+	{0x90132, 0x0},
+	{0x90133, 0x0},
+	{0x90134, 0x0},
+	{0x90135, 0x0},
+	{0x90136, 0x0},
+	{0x90137, 0x0},
+	{0x90138, 0x0},
+	{0x90139, 0x0},
+	{0x9013a, 0x0},
+	{0x9013b, 0x0},
+	{0x9013c, 0x0},
+	{0x9013d, 0x0},
+	{0x9013e, 0x0},
+	{0x9013f, 0x0},
+	{0x90140, 0x0},
+	{0x90141, 0x0},
+	{0x90142, 0x0},
+	{0x90143, 0x0},
+	{0x90144, 0x0},
+	{0x90145, 0x0},
+	{0x90146, 0x0},
+	{0x90147, 0x0},
+	{0x90148, 0x0},
+	{0x90149, 0x0},
+	{0x9014a, 0x0},
+	{0x9014b, 0x0},
+	{0x9014c, 0x0},
+	{0x9014d, 0x0},
+	{0x9014e, 0x0},
+	{0x9014f, 0x0},
+	{0x90150, 0x0},
+	{0x90151, 0x0},
+	{0x90152, 0x0},
+	{0x90153, 0x0},
+	{0x90154, 0x0},
+	{0x90155, 0x0},
+	{0x90156, 0x0},
+	{0x90157, 0x0},
+	{0x90158, 0x0},
+	{0x90159, 0x0},
+	{0x9015a, 0x0},
+	{0x9015b, 0x0},
+	{0x9015c, 0x0},
+	{0x9015d, 0x0},
+	{0x9015e, 0x0},
+	{0x9015f, 0x0},
+	{0x90160, 0x0},
+	{0x90161, 0x0},
+	{0x90162, 0x0},
+	{0x90163, 0x0},
+	{0x90164, 0x0},
+	{0x90165, 0x0},
+	{0x90166, 0x0},
+	{0x90167, 0x0},
+	{0x90168, 0x0},
+	{0x90169, 0x0},
+	{0x9016a, 0x0},
+	{0x9016b, 0x0},
+	{0x9016c, 0x0},
+	{0x9016d, 0x0},
+	{0x9016e, 0x0},
+	{0x9016f, 0x0},
+	{0x90170, 0x0},
+	{0x90171, 0x0},
+	{0x90172, 0x0},
+	{0x90173, 0x0},
+	{0x90174, 0x0},
+	{0x90175, 0x0},
+	{0x90176, 0x0},
+	{0x90177, 0x0},
+	{0x90178, 0x0},
+	{0x90179, 0x0},
+	{0x9017a, 0x0},
+	{0x9017b, 0x0},
+	{0x9017c, 0x0},
+	{0x9017d, 0x0},
+	{0x9017e, 0x0},
+	{0x9017f, 0x0},
+	{0x90180, 0x0},
+	{0x90181, 0x0},
+	{0x90182, 0x0},
+	{0x90183, 0x0},
+	{0x90184, 0x0},
+	{0x90006, 0x0},
+	{0x90007, 0x0},
+	{0x90008, 0x0},
+	{0x90009, 0x0},
+	{0x9000a, 0x0},
+	{0x9000b, 0x0},
+	{0xd00e7, 0x0},
+	{0x90017, 0x0},
+	{0x9001f, 0x0},
+	{0x90026, 0x0},
+	{0x400d0, 0x0},
+	{0x400d1, 0x0},
+	{0x400d2, 0x0},
+	{0x400d3, 0x0},
+	{0x400d4, 0x0},
+	{0x400d5, 0x0},
+	{0x400d6, 0x0},
+	{0x400d7, 0x0},
+	{0x200be, 0x0},
+	{0x2000b, 0x0},
+	{0x2000c, 0x0},
+	{0x2000d, 0x0},
+	{0x2000e, 0x0},
+	{0x9000c, 0x0},
+	{0x9000d, 0x0},
+	{0x9000e, 0x0},
+	{0x9000f, 0x0},
+	{0x90010, 0x0},
+	{0x90011, 0x0},
+	{0x90012, 0x0},
+	{0x90013, 0x0},
+	{0x20010, 0x0},
+	{0x20011, 0x0},
+	{0x40080, 0x0},
+	{0x40081, 0x0},
+	{0x40082, 0x0},
+	{0x40083, 0x0},
+	{0x40084, 0x0},
+	{0x40085, 0x0},
+	{0x400fd, 0x0},
+	{0x400f1, 0x0},
+	{0x10011, 0x0},
+	{0x10012, 0x0},
+	{0x10013, 0x0},
+	{0x10018, 0x0},
+	{0x10002, 0x0},
+	{0x100b2, 0x0},
+	{0x101b4, 0x0},
+	{0x102b4, 0x0},
+	{0x103b4, 0x0},
+	{0x104b4, 0x0},
+	{0x105b4, 0x0},
+	{0x106b4, 0x0},
+	{0x107b4, 0x0},
+	{0x108b4, 0x0},
+	{0x11011, 0x0},
+	{0x11012, 0x0},
+	{0x11013, 0x0},
+	{0x11018, 0x0},
+	{0x11002, 0x0},
+	{0x110b2, 0x0},
+	{0x111b4, 0x0},
+	{0x112b4, 0x0},
+	{0x113b4, 0x0},
+	{0x114b4, 0x0},
+	{0x115b4, 0x0},
+	{0x116b4, 0x0},
+	{0x117b4, 0x0},
+	{0x118b4, 0x0},
+	{0x20089, 0x0},
+	{0xc0080, 0x0},
+	{0x200cb, 0x0},
+	{0x10068, 0x0},
+	{0x10069, 0x0},
+	{0x10168, 0x0},
+	{0x10169, 0x0},
+	{0x10268, 0x0},
+	{0x10269, 0x0},
+	{0x10368, 0x0},
+	{0x10369, 0x0},
+	{0x10468, 0x0},
+	{0x10469, 0x0},
+	{0x10568, 0x0},
+	{0x10569, 0x0},
+	{0x10668, 0x0},
+	{0x10669, 0x0},
+	{0x10768, 0x0},
+	{0x10769, 0x0},
+	{0x10868, 0x0},
+	{0x10869, 0x0},
+	{0x100aa, 0x0},
+	{0x10062, 0x0},
+	{0x10001, 0x0},
+	{0x100a0, 0x0},
+	{0x100a1, 0x0},
+	{0x100a2, 0x0},
+	{0x100a3, 0x0},
+	{0x100a4, 0x0},
+	{0x100a5, 0x0},
+	{0x100a6, 0x0},
+	{0x100a7, 0x0},
+	{0x11068, 0x0},
+	{0x11069, 0x0},
+	{0x11168, 0x0},
+	{0x11169, 0x0},
+	{0x11268, 0x0},
+	{0x11269, 0x0},
+	{0x11368, 0x0},
+	{0x11369, 0x0},
+	{0x11468, 0x0},
+	{0x11469, 0x0},
+	{0x11568, 0x0},
+	{0x11569, 0x0},
+	{0x11668, 0x0},
+	{0x11669, 0x0},
+	{0x11768, 0x0},
+	{0x11769, 0x0},
+	{0x11868, 0x0},
+	{0x11869, 0x0},
+	{0x110aa, 0x0},
+	{0x11062, 0x0},
+	{0x11001, 0x0},
+	{0x110a0, 0x0},
+	{0x110a1, 0x0},
+	{0x110a2, 0x0},
+	{0x110a3, 0x0},
+	{0x110a4, 0x0},
+	{0x110a5, 0x0},
+	{0x110a6, 0x0},
+	{0x110a7, 0x0},
+	{0x80, 0x0},
+	{0x1080, 0x0},
+	{0x2080, 0x0},
+	{0x10020, 0x0},
+	{0x10080, 0x0},
+	{0x10081, 0x0},
+	{0x100d0, 0x0},
+	{0x100d1, 0x0},
+	{0x1008c, 0x0},
+	{0x1008d, 0x0},
+	{0x10180, 0x0},
+	{0x10181, 0x0},
+	{0x101d0, 0x0},
+	{0x101d1, 0x0},
+	{0x1018c, 0x0},
+	{0x1018d, 0x0},
+	{0x100c0, 0x0},
+	{0x100c1, 0x0},
+	{0x101c0, 0x0},
+	{0x101c1, 0x0},
+	{0x102c0, 0x0},
+	{0x102c1, 0x0},
+	{0x103c0, 0x0},
+	{0x103c1, 0x0},
+	{0x104c0, 0x0},
+	{0x104c1, 0x0},
+	{0x105c0, 0x0},
+	{0x105c1, 0x0},
+	{0x106c0, 0x0},
+	{0x106c1, 0x0},
+	{0x107c0, 0x0},
+	{0x107c1, 0x0},
+	{0x108c0, 0x0},
+	{0x108c1, 0x0},
+	{0x100ae, 0x0},
+	{0x100af, 0x0},
+	{0x11020, 0x0},
+	{0x11080, 0x0},
+	{0x11081, 0x0},
+	{0x110d0, 0x0},
+	{0x110d1, 0x0},
+	{0x1108c, 0x0},
+	{0x1108d, 0x0},
+	{0x11180, 0x0},
+	{0x11181, 0x0},
+	{0x111d0, 0x0},
+	{0x111d1, 0x0},
+	{0x1118c, 0x0},
+	{0x1118d, 0x0},
+	{0x110c0, 0x0},
+	{0x110c1, 0x0},
+	{0x111c0, 0x0},
+	{0x111c1, 0x0},
+	{0x112c0, 0x0},
+	{0x112c1, 0x0},
+	{0x113c0, 0x0},
+	{0x113c1, 0x0},
+	{0x114c0, 0x0},
+	{0x114c1, 0x0},
+	{0x115c0, 0x0},
+	{0x115c1, 0x0},
+	{0x116c0, 0x0},
+	{0x116c1, 0x0},
+	{0x117c0, 0x0},
+	{0x117c1, 0x0},
+	{0x118c0, 0x0},
+	{0x118c1, 0x0},
+	{0x110ae, 0x0},
+	{0x110af, 0x0},
+	{0x90201, 0x0},
+	{0x90202, 0x0},
+	{0x90203, 0x0},
+	{0x90205, 0x0},
+	{0x90206, 0x0},
+	{0x90207, 0x0},
+	{0x90208, 0x0},
+	{0x20020, 0x0},
+	{0x20077, 0x0},
+	{0x20072, 0x0},
+	{0x20073, 0x0},
+	{0x400c0, 0x0},
+	{0x10040, 0x0},
+	{0x10140, 0x0},
+	{0x10240, 0x0},
+	{0x10340, 0x0},
+	{0x10440, 0x0},
+	{0x10540, 0x0},
+	{0x10640, 0x0},
+	{0x10740, 0x0},
+	{0x10840, 0x0},
+	{0x11040, 0x0},
+	{0x11140, 0x0},
+	{0x11240, 0x0},
+	{0x11340, 0x0},
+	{0x11440, 0x0},
+	{0x11540, 0x0},
+	{0x11640, 0x0},
+	{0x11740, 0x0},
+	{0x11840, 0x0},
+
+};
+
+/* P0 message block parameter for training firmware */
+static struct dram_cfg_param ddr_fsp0_cfg[] = {
+	{0xd0000, 0x0},
+	{0x54003, 0xe94},
+	{0x54004, 0x4},
+	{0x54006, 0x15},
+	{0x54008, 0x131f},
+	{0x54009, 0xc8},
+	{0x5400b, 0x4},
+	{0x5400d, 0x100},
+	{0x5400f, 0x100},
+	{0x54012, 0x110},
+	{0x54019, 0x36e4},
+	{0x5401a, 0xf2},
+	{0x5401b, 0x1146},
+	{0x5401c, 0x1108},
+	{0x5401e, 0x4},
+	{0x5401f, 0x36e4},
+	{0x54020, 0xf2},
+	{0x54021, 0x1146},
+	{0x54022, 0x1108},
+	{0x54024, 0x4},
+	{0x54032, 0xe400},
+	{0x54033, 0xf236},
+	{0x54034, 0x4600},
+	{0x54035, 0x811},
+	{0x54036, 0x11},
+	{0x54037, 0x400},
+	{0x54038, 0xe400},
+	{0x54039, 0xf236},
+	{0x5403a, 0x4600},
+	{0x5403b, 0x811},
+	{0x5403c, 0x11},
+	{0x5403d, 0x400},
+	{0xd0000, 0x1}
+};
+
+/* P0 2D message block parameter for training firmware */
+static struct dram_cfg_param ddr_fsp0_2d_cfg[] = {
+	{0xd0000, 0x0},
+	{0x54003, 0xe94},
+	{0x54004, 0x4},
+	{0x54006, 0x15},
+	{0x54008, 0x61},
+	{0x54009, 0xc8},
+	{0x5400b, 0x4},
+	{0x5400d, 0x100},
+	{0x5400f, 0x100},
+	{0x54010, 0x2080},
+	{0x54012, 0x110},
+	{0x54019, 0x36e4},
+	{0x5401a, 0xf2},
+	{0x5401b, 0x1146},
+	{0x5401c, 0x1108},
+	{0x5401e, 0x4},
+	{0x5401f, 0x36e4},
+	{0x54020, 0xf2},
+	{0x54021, 0x1146},
+	{0x54022, 0x1108},
+	{0x54024, 0x4},
+	{0x54032, 0xe400},
+	{0x54033, 0xf236},
+	{0x54034, 0x4600},
+	{0x54035, 0x811},
+	{0x54036, 0x11},
+	{0x54037, 0x400},
+	{0x54038, 0xe400},
+	{0x54039, 0xf236},
+	{0x5403a, 0x4600},
+	{0x5403b, 0x811},
+	{0x5403c, 0x11},
+	{0x5403d, 0x400},
+	{0xd0000, 0x1}
+};
+
+/* DRAM PHY init engine image */
+static struct dram_cfg_param ddr_phy_pie[] = {
+	{0xd0000, 0x0},
+	{0x90000, 0x10},
+	{0x90001, 0x400},
+	{0x90002, 0x10e},
+	{0x90003, 0x0},
+	{0x90004, 0x0},
+	{0x90005, 0x8},
+	{0x90029, 0xb},
+	{0x9002a, 0x480},
+	{0x9002b, 0x109},
+	{0x9002c, 0x8},
+	{0x9002d, 0x448},
+	{0x9002e, 0x139},
+	{0x9002f, 0x8},
+	{0x90030, 0x478},
+	{0x90031, 0x109},
+	{0x90032, 0x0},
+	{0x90033, 0xe8},
+	{0x90034, 0x109},
+	{0x90035, 0x2},
+	{0x90036, 0x10},
+	{0x90037, 0x139},
+	{0x90038, 0xb},
+	{0x90039, 0x7c0},
+	{0x9003a, 0x139},
+	{0x9003b, 0x44},
+	{0x9003c, 0x633},
+	{0x9003d, 0x159},
+	{0x9003e, 0x14f},
+	{0x9003f, 0x630},
+	{0x90040, 0x159},
+	{0x90041, 0x47},
+	{0x90042, 0x633},
+	{0x90043, 0x149},
+	{0x90044, 0x4f},
+	{0x90045, 0x633},
+	{0x90046, 0x179},
+	{0x90047, 0x8},
+	{0x90048, 0xe0},
+	{0x90049, 0x109},
+	{0x9004a, 0x0},
+	{0x9004b, 0x7c8},
+	{0x9004c, 0x109},
+	{0x9004d, 0x0},
+	{0x9004e, 0x1},
+	{0x9004f, 0x8},
+	{0x90050, 0x30},
+	{0x90051, 0x65a},
+	{0x90052, 0x9},
+	{0x90053, 0x0},
+	{0x90054, 0x45a},
+	{0x90055, 0x9},
+	{0x90056, 0x0},
+	{0x90057, 0x448},
+	{0x90058, 0x109},
+	{0x90059, 0x40},
+	{0x9005a, 0x633},
+	{0x9005b, 0x179},
+	{0x9005c, 0x1},
+	{0x9005d, 0x618},
+	{0x9005e, 0x109},
+	{0x9005f, 0x40c0},
+	{0x90060, 0x633},
+	{0x90061, 0x149},
+	{0x90062, 0x8},
+	{0x90063, 0x4},
+	{0x90064, 0x48},
+	{0x90065, 0x4040},
+	{0x90066, 0x633},
+	{0x90067, 0x149},
+	{0x90068, 0x0},
+	{0x90069, 0x4},
+	{0x9006a, 0x48},
+	{0x9006b, 0x40},
+	{0x9006c, 0x633},
+	{0x9006d, 0x149},
+	{0x9006e, 0x0},
+	{0x9006f, 0x658},
+	{0x90070, 0x109},
+	{0x90071, 0x10},
+	{0x90072, 0x4},
+	{0x90073, 0x18},
+	{0x90074, 0x0},
+	{0x90075, 0x4},
+	{0x90076, 0x78},
+	{0x90077, 0x549},
+	{0x90078, 0x633},
+	{0x90079, 0x159},
+	{0x9007a, 0xd49},
+	{0x9007b, 0x633},
+	{0x9007c, 0x159},
+	{0x9007d, 0x94a},
+	{0x9007e, 0x633},
+	{0x9007f, 0x159},
+	{0x90080, 0x441},
+	{0x90081, 0x633},
+	{0x90082, 0x149},
+	{0x90083, 0x42},
+	{0x90084, 0x633},
+	{0x90085, 0x149},
+	{0x90086, 0x1},
+	{0x90087, 0x633},
+	{0x90088, 0x149},
+	{0x90089, 0x0},
+	{0x9008a, 0xe0},
+	{0x9008b, 0x109},
+	{0x9008c, 0xa},
+	{0x9008d, 0x10},
+	{0x9008e, 0x109},
+	{0x9008f, 0x9},
+	{0x90090, 0x3c0},
+	{0x90091, 0x149},
+	{0x90092, 0x9},
+	{0x90093, 0x3c0},
+	{0x90094, 0x159},
+	{0x90095, 0x18},
+	{0x90096, 0x10},
+	{0x90097, 0x109},
+	{0x90098, 0x0},
+	{0x90099, 0x3c0},
+	{0x9009a, 0x109},
+	{0x9009b, 0x18},
+	{0x9009c, 0x4},
+	{0x9009d, 0x48},
+	{0x9009e, 0x18},
+	{0x9009f, 0x4},
+	{0x900a0, 0x58},
+	{0x900a1, 0xb},
+	{0x900a2, 0x10},
+	{0x900a3, 0x109},
+	{0x900a4, 0x1},
+	{0x900a5, 0x10},
+	{0x900a6, 0x109},
+	{0x900a7, 0x5},
+	{0x900a8, 0x7c0},
+	{0x900a9, 0x109},
+	{0x40000, 0x811},
+	{0x40020, 0x880},
+	{0x40040, 0x0},
+	{0x40060, 0x0},
+	{0x40001, 0x4008},
+	{0x40021, 0x83},
+	{0x40041, 0x4f},
+	{0x40061, 0x0},
+	{0x40002, 0x4040},
+	{0x40022, 0x83},
+	{0x40042, 0x51},
+	{0x40062, 0x0},
+	{0x40003, 0x811},
+	{0x40023, 0x880},
+	{0x40043, 0x0},
+	{0x40063, 0x0},
+	{0x40004, 0x720},
+	{0x40024, 0xf},
+	{0x40044, 0x1740},
+	{0x40064, 0x0},
+	{0x40005, 0x16},
+	{0x40025, 0x83},
+	{0x40045, 0x4b},
+	{0x40065, 0x0},
+	{0x40006, 0x716},
+	{0x40026, 0xf},
+	{0x40046, 0x2001},
+	{0x40066, 0x0},
+	{0x40007, 0x716},
+	{0x40027, 0xf},
+	{0x40047, 0x2800},
+	{0x40067, 0x0},
+	{0x40008, 0x716},
+	{0x40028, 0xf},
+	{0x40048, 0xf00},
+	{0x40068, 0x0},
+	{0x40009, 0x720},
+	{0x40029, 0xf},
+	{0x40049, 0x1400},
+	{0x40069, 0x0},
+	{0x4000a, 0xe08},
+	{0x4002a, 0xc15},
+	{0x4004a, 0x0},
+	{0x4006a, 0x0},
+	{0x4000b, 0x625},
+	{0x4002b, 0x15},
+	{0x4004b, 0x0},
+	{0x4006b, 0x0},
+	{0x4000c, 0x4028},
+	{0x4002c, 0x80},
+	{0x4004c, 0x0},
+	{0x4006c, 0x0},
+	{0x4000d, 0xe08},
+	{0x4002d, 0xc1a},
+	{0x4004d, 0x0},
+	{0x4006d, 0x0},
+	{0x4000e, 0x625},
+	{0x4002e, 0x1a},
+	{0x4004e, 0x0},
+	{0x4006e, 0x0},
+	{0x4000f, 0x4040},
+	{0x4002f, 0x80},
+	{0x4004f, 0x0},
+	{0x4006f, 0x0},
+	{0x40010, 0x2604},
+	{0x40030, 0x15},
+	{0x40050, 0x0},
+	{0x40070, 0x0},
+	{0x40011, 0x708},
+	{0x40031, 0x5},
+	{0x40051, 0x0},
+	{0x40071, 0x2002},
+	{0x40012, 0x8},
+	{0x40032, 0x80},
+	{0x40052, 0x0},
+	{0x40072, 0x0},
+	{0x40013, 0x2604},
+	{0x40033, 0x1a},
+	{0x40053, 0x0},
+	{0x40073, 0x0},
+	{0x40014, 0x708},
+	{0x40034, 0xa},
+	{0x40054, 0x0},
+	{0x40074, 0x2002},
+	{0x40015, 0x4040},
+	{0x40035, 0x80},
+	{0x40055, 0x0},
+	{0x40075, 0x0},
+	{0x40016, 0x60a},
+	{0x40036, 0x15},
+	{0x40056, 0x1200},
+	{0x40076, 0x0},
+	{0x40017, 0x61a},
+	{0x40037, 0x15},
+	{0x40057, 0x1300},
+	{0x40077, 0x0},
+	{0x40018, 0x60a},
+	{0x40038, 0x1a},
+	{0x40058, 0x1200},
+	{0x40078, 0x0},
+	{0x40019, 0x642},
+	{0x40039, 0x1a},
+	{0x40059, 0x1300},
+	{0x40079, 0x0},
+	{0x4001a, 0x4808},
+	{0x4003a, 0x880},
+	{0x4005a, 0x0},
+	{0x4007a, 0x0},
+	{0x900aa, 0x0},
+	{0x900ab, 0x790},
+	{0x900ac, 0x11a},
+	{0x900ad, 0x8},
+	{0x900ae, 0x7aa},
+	{0x900af, 0x2a},
+	{0x900b0, 0x10},
+	{0x900b1, 0x7b2},
+	{0x900b2, 0x2a},
+	{0x900b3, 0x0},
+	{0x900b4, 0x7c8},
+	{0x900b5, 0x109},
+	{0x900b6, 0x10},
+	{0x900b7, 0x10},
+	{0x900b8, 0x109},
+	{0x900b9, 0x10},
+	{0x900ba, 0x2a8},
+	{0x900bb, 0x129},
+	{0x900bc, 0x8},
+	{0x900bd, 0x370},
+	{0x900be, 0x129},
+	{0x900bf, 0xa},
+	{0x900c0, 0x3c8},
+	{0x900c1, 0x1a9},
+	{0x900c2, 0xc},
+	{0x900c3, 0x408},
+	{0x900c4, 0x199},
+	{0x900c5, 0x14},
+	{0x900c6, 0x790},
+	{0x900c7, 0x11a},
+	{0x900c8, 0x8},
+	{0x900c9, 0x4},
+	{0x900ca, 0x18},
+	{0x900cb, 0xe},
+	{0x900cc, 0x408},
+	{0x900cd, 0x199},
+	{0x900ce, 0x8},
+	{0x900cf, 0x8568},
+	{0x900d0, 0x108},
+	{0x900d1, 0x18},
+	{0x900d2, 0x790},
+	{0x900d3, 0x16a},
+	{0x900d4, 0x8},
+	{0x900d5, 0x1d8},
+	{0x900d6, 0x169},
+	{0x900d7, 0x10},
+	{0x900d8, 0x8558},
+	{0x900d9, 0x168},
+	{0x900da, 0x1ff8},
+	{0x900db, 0x85a8},
+	{0x900dc, 0x1e8},
+	{0x900dd, 0x50},
+	{0x900de, 0x798},
+	{0x900df, 0x16a},
+	{0x900e0, 0x60},
+	{0x900e1, 0x7a0},
+	{0x900e2, 0x16a},
+	{0x900e3, 0x8},
+	{0x900e4, 0x8310},
+	{0x900e5, 0x168},
+	{0x900e6, 0x8},
+	{0x900e7, 0xa310},
+	{0x900e8, 0x168},
+	{0x900e9, 0xa},
+	{0x900ea, 0x408},
+	{0x900eb, 0x169},
+	{0x900ec, 0x6e},
+	{0x900ed, 0x0},
+	{0x900ee, 0x68},
+	{0x900ef, 0x0},
+	{0x900f0, 0x408},
+	{0x900f1, 0x169},
+	{0x900f2, 0x0},
+	{0x900f3, 0x8310},
+	{0x900f4, 0x168},
+	{0x900f5, 0x0},
+	{0x900f6, 0xa310},
+	{0x900f7, 0x168},
+	{0x900f8, 0x1ff8},
+	{0x900f9, 0x85a8},
+	{0x900fa, 0x1e8},
+	{0x900fb, 0x68},
+	{0x900fc, 0x798},
+	{0x900fd, 0x16a},
+	{0x900fe, 0x78},
+	{0x900ff, 0x7a0},
+	{0x90100, 0x16a},
+	{0x90101, 0x68},
+	{0x90102, 0x790},
+	{0x90103, 0x16a},
+	{0x90104, 0x8},
+	{0x90105, 0x8b10},
+	{0x90106, 0x168},
+	{0x90107, 0x8},
+	{0x90108, 0xab10},
+	{0x90109, 0x168},
+	{0x9010a, 0xa},
+	{0x9010b, 0x408},
+	{0x9010c, 0x169},
+	{0x9010d, 0x58},
+	{0x9010e, 0x0},
+	{0x9010f, 0x68},
+	{0x90110, 0x0},
+	{0x90111, 0x408},
+	{0x90112, 0x169},
+	{0x90113, 0x0},
+	{0x90114, 0x8b10},
+	{0x90115, 0x168},
+	{0x90116, 0x1},
+	{0x90117, 0xab10},
+	{0x90118, 0x168},
+	{0x90119, 0x0},
+	{0x9011a, 0x1d8},
+	{0x9011b, 0x169},
+	{0x9011c, 0x80},
+	{0x9011d, 0x790},
+	{0x9011e, 0x16a},
+	{0x9011f, 0x18},
+	{0x90120, 0x7aa},
+	{0x90121, 0x6a},
+	{0x90122, 0xa},
+	{0x90123, 0x0},
+	{0x90124, 0x1e9},
+	{0x90125, 0x8},
+	{0x90126, 0x8080},
+	{0x90127, 0x108},
+	{0x90128, 0xf},
+	{0x90129, 0x408},
+	{0x9012a, 0x169},
+	{0x9012b, 0xc},
+	{0x9012c, 0x0},
+	{0x9012d, 0x68},
+	{0x9012e, 0x9},
+	{0x9012f, 0x0},
+	{0x90130, 0x1a9},
+	{0x90131, 0x0},
+	{0x90132, 0x408},
+	{0x90133, 0x169},
+	{0x90134, 0x0},
+	{0x90135, 0x8080},
+	{0x90136, 0x108},
+	{0x90137, 0x8},
+	{0x90138, 0x7aa},
+	{0x90139, 0x6a},
+	{0x9013a, 0x0},
+	{0x9013b, 0x8568},
+	{0x9013c, 0x108},
+	{0x9013d, 0xb7},
+	{0x9013e, 0x790},
+	{0x9013f, 0x16a},
+	{0x90140, 0x1f},
+	{0x90141, 0x0},
+	{0x90142, 0x68},
+	{0x90143, 0x8},
+	{0x90144, 0x8558},
+	{0x90145, 0x168},
+	{0x90146, 0xf},
+	{0x90147, 0x408},
+	{0x90148, 0x169},
+	{0x90149, 0xd},
+	{0x9014a, 0x0},
+	{0x9014b, 0x68},
+	{0x9014c, 0x0},
+	{0x9014d, 0x408},
+	{0x9014e, 0x169},
+	{0x9014f, 0x0},
+	{0x90150, 0x8558},
+	{0x90151, 0x168},
+	{0x90152, 0x8},
+	{0x90153, 0x3c8},
+	{0x90154, 0x1a9},
+	{0x90155, 0x3},
+	{0x90156, 0x370},
+	{0x90157, 0x129},
+	{0x90158, 0x20},
+	{0x90159, 0x2aa},
+	{0x9015a, 0x9},
+	{0x9015b, 0x8},
+	{0x9015c, 0xe8},
+	{0x9015d, 0x109},
+	{0x9015e, 0x0},
+	{0x9015f, 0x8140},
+	{0x90160, 0x10c},
+	{0x90161, 0x10},
+	{0x90162, 0x8138},
+	{0x90163, 0x104},
+	{0x90164, 0x8},
+	{0x90165, 0x448},
+	{0x90166, 0x109},
+	{0x90167, 0xf},
+	{0x90168, 0x7c0},
+	{0x90169, 0x109},
+	{0x9016a, 0x0},
+	{0x9016b, 0xe8},
+	{0x9016c, 0x109},
+	{0x9016d, 0x47},
+	{0x9016e, 0x630},
+	{0x9016f, 0x109},
+	{0x90170, 0x8},
+	{0x90171, 0x618},
+	{0x90172, 0x109},
+	{0x90173, 0x8},
+	{0x90174, 0xe0},
+	{0x90175, 0x109},
+	{0x90176, 0x0},
+	{0x90177, 0x7c8},
+	{0x90178, 0x109},
+	{0x90179, 0x8},
+	{0x9017a, 0x8140},
+	{0x9017b, 0x10c},
+	{0x9017c, 0x0},
+	{0x9017d, 0x478},
+	{0x9017e, 0x109},
+	{0x9017f, 0x0},
+	{0x90180, 0x1},
+	{0x90181, 0x8},
+	{0x90182, 0x8},
+	{0x90183, 0x4},
+	{0x90184, 0x0},
+	{0x90006, 0x8},
+	{0x90007, 0x7c8},
+	{0x90008, 0x109},
+	{0x90009, 0x0},
+	{0x9000a, 0x400},
+	{0x9000b, 0x106},
+	{0xd00e7, 0x400},
+	{0x90017, 0x0},
+	{0x9001f, 0x2b},
+	{0x90026, 0x69},
+	{0x400d0, 0x0},
+	{0x400d1, 0x101},
+	{0x400d2, 0x105},
+	{0x400d3, 0x107},
+	{0x400d4, 0x10f},
+	{0x400d5, 0x202},
+	{0x400d6, 0x20a},
+	{0x400d7, 0x20b},
+	{0x2003a, 0x2},
+	{0x200be, 0x3},
+	{0x2000b, 0x75},
+	{0x2000c, 0xe9},
+	{0x2000d, 0x91c},
+	{0x2000e, 0x2c},
+	{0x9000c, 0x0},
+	{0x9000d, 0x173},
+	{0x9000e, 0x60},
+	{0x9000f, 0x6110},
+	{0x90010, 0x2152},
+	{0x90011, 0xdfbd},
+	{0x90012, 0x2060},
+	{0x90013, 0x6152},
+	{0x20010, 0x5a},
+	{0x20011, 0x3},
+	{0x40080, 0xe0},
+	{0x40081, 0x12},
+	{0x40082, 0xe0},
+	{0x40083, 0x12},
+	{0x40084, 0xe0},
+	{0x40085, 0x12},
+	{0x400fd, 0xf},
+	{0x400f1, 0xe},
+	{0x10011, 0x1},
+	{0x10012, 0x1},
+	{0x10013, 0x180},
+	{0x10018, 0x1},
+	{0x10002, 0x6209},
+	{0x100b2, 0x1},
+	{0x101b4, 0x1},
+	{0x102b4, 0x1},
+	{0x103b4, 0x1},
+	{0x104b4, 0x1},
+	{0x105b4, 0x1},
+	{0x106b4, 0x1},
+	{0x107b4, 0x1},
+	{0x108b4, 0x1},
+	{0x11011, 0x1},
+	{0x11012, 0x1},
+	{0x11013, 0x180},
+	{0x11018, 0x1},
+	{0x11002, 0x6209},
+	{0x110b2, 0x1},
+	{0x111b4, 0x1},
+	{0x112b4, 0x1},
+	{0x113b4, 0x1},
+	{0x114b4, 0x1},
+	{0x115b4, 0x1},
+	{0x116b4, 0x1},
+	{0x117b4, 0x1},
+	{0x118b4, 0x1},
+	{0x20089, 0x1},
+	{0x20088, 0x19},
+	{0xc0080, 0x0},
+	{0xd0000, 0x1},
+
+};
+
+static struct dram_fsp_msg ddr_dram_fsp_msg[] = {
+	{
+		/* P0 3733mts 1D */
+		.drate = 3733,
+		.fw_type = FW_1D_IMAGE,
+		.fsp_cfg = ddr_fsp0_cfg,
+		.fsp_cfg_num = ARRAY_SIZE(ddr_fsp0_cfg),
+
+	},
+
+	{
+		/* P0 3733mts 2D */
+		.drate = 3733,
+		.fw_type = FW_2D_IMAGE,
+		.fsp_cfg = ddr_fsp0_2d_cfg,
+		.fsp_cfg_num = ARRAY_SIZE(ddr_fsp0_2d_cfg),
+	},
+
+};
+
+/* ddr timing config params */
+struct dram_timing_info dram_timing = {
+	.ddrc_cfg = ddr_ddrc_cfg,
+	.ddrc_cfg_num = ARRAY_SIZE(ddr_ddrc_cfg),
+	.ddrphy_cfg = ddr_ddrphy_cfg,
+	.ddrphy_cfg_num = ARRAY_SIZE(ddr_ddrphy_cfg),
+	.fsp_msg = ddr_dram_fsp_msg,
+	.fsp_msg_num = ARRAY_SIZE(ddr_dram_fsp_msg),
+	.ddrphy_trained_csr = ddr_ddrphy_trained_csr,
+	.ddrphy_trained_csr_num = ARRAY_SIZE(ddr_ddrphy_trained_csr),
+	.ddrphy_pie = ddr_phy_pie,
+	.ddrphy_pie_num = ARRAY_SIZE(ddr_phy_pie),
+	.fsp_table = { 3733, },
+	.fsp_cfg = ddr_dram_fsp_cfg,
+	.fsp_cfg_num = ARRAY_SIZE(ddr_dram_fsp_cfg),
+};
diff --git a/arch/arm/configs/imx_v8_defconfig b/arch/arm/configs/imx_v8_defconfig
index e58a2ca13d7a7f4767b680cceefed27fb6950f9b..445f20a303cc7f31f574125d38b34b9bdffd74da 100644
--- a/arch/arm/configs/imx_v8_defconfig
+++ b/arch/arm/configs/imx_v8_defconfig
@@ -16,6 +16,7 @@ CONFIG_MACH_VARISCITE_DT8MCUSTOMBOARD_IMX8MP=y
 CONFIG_MACH_ZII_IMX8MQ_DEV=y
 CONFIG_64BIT=y
 CONFIG_MACH_TQMA93XX=y
+CONFIG_MACH_PHYTEC_PHYCORE_IMX93=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_MALLOC_SIZE=0x0
diff --git a/arch/arm/configs/multi_v8_defconfig b/arch/arm/configs/multi_v8_defconfig
index b1e66e85f4607752efd79bdda6648b750bf872a1..c66b8a0be803a1f3c243e7ec3da5169e3d5451a1 100644
--- a/arch/arm/configs/multi_v8_defconfig
+++ b/arch/arm/configs/multi_v8_defconfig
@@ -22,6 +22,7 @@ CONFIG_MACH_TQ_MBA8MPXL=y
 CONFIG_MACH_VARISCITE_DT8MCUSTOMBOARD_IMX8MP=y
 CONFIG_MACH_ZII_IMX8MQ_DEV=y
 CONFIG_MACH_TQMA93XX=y
+CONFIG_MACH_PHYTEC_PHYCORE_IMX93=y
 CONFIG_IMX_IIM=y
 CONFIG_ARCH_LAYERSCAPE_PPA=y
 CONFIG_MACH_LS1028ARDB=y
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index d3462858523067d68cd41112daaa81d72a072957..3423115b4b447a14d9755ecd63c05a36328c158a 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -81,6 +81,7 @@ lwl-$(CONFIG_MACH_PHYTEC_SOM_IMX6) += imx6q-phytec-phycard.dtb.o \
 				imx6ull-phytec-phycore-som-nand.dtb.o \
 				imx6ull-phytec-phycore-som-emmc.dtb.o
 lwl-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX7) += imx7d-phyboard-zeta.dtb.o
+lwl-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX93) += imx93-phyboard-segin.dtb.o
 lwl-$(CONFIG_MACH_PHYTEC_PHYCORE_STM32MP1) += stm32mp157c-phycore-stm32mp1-3.dtb.o
 lwl-$(CONFIG_MACH_PHYTEC_SOM_IMX8MM) += imx8mm-phyboard-polis-rdk.dtb.o
 lwl-$(CONFIG_MACH_PHYTEC_SOM_IMX8MQ) += imx8mq-phytec-phycore-som.dtb.o
diff --git a/arch/arm/dts/imx93-phyboard-segin-downstream.dtsi b/arch/arm/dts/imx93-phyboard-segin-downstream.dtsi
new file mode 100644
index 0000000000000000000000000000000000000000..d2a81069e335c12933cdf48bbc1b7c13e937a6c3
--- /dev/null
+++ b/arch/arm/dts/imx93-phyboard-segin-downstream.dtsi
@@ -0,0 +1,269 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (C) 2023 PHYTEC Messtechnik GmbH
+ * Author: Wadim Egorov <w.egorov at phytec.de>, Christoph Stoidner <c.stoidner at phytec.de>
+ */
+
+/*
+ * Contents of this file are copied from the linux-phytec-imx downstream and
+ * can be removed once mainlined.
+ */
+
+/ {
+	reg_vcc_1v8_audio: regulator-vcc1v8-audio {
+		compatible = "regulator-fixed";
+		regulator-max-microvolt = <1800000>;
+		regulator-min-microvolt = <1800000>;
+		regulator-name = "VCC1V8_AUDIO";
+	};
+	reg_vcc_3v3: regulator-vcc-3v3 {
+		compatible = "regulator-fixed";
+		regulator-max-microvolt = <3300000>;
+		regulator-min-microvolt = <3300000>;
+		regulator-name = "VCC3V3";
+	};
+};
+
+&reg_usdhc2_vmmc {
+	compatible = "regulator-fixed";
+	gpio = <&gpio3 7 GPIO_ACTIVE_HIGH>;
+	enable-active-high;
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_reg_usdhc2_vmmc>;
+	regulator-max-microvolt = <3300000>;
+	regulator-min-microvolt = <3300000>;
+	regulator-name = "VCC_SD";
+};
+
+/* I2C3 */
+&lpi2c3 {
+	clock-frequency = <400000>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_lpi2c3>;
+	#address-cells = <1>;
+	#size-cells = <0>;
+	status = "okay";
+
+	pmic at 25 {
+		compatible = "nxp,pca9451a";
+		reg = <0x25>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_pmic>;
+		interrupt-parent = <&gpio4>;
+		interrupts = <27 IRQ_TYPE_LEVEL_LOW>;
+
+		regulators {
+			buck1: BUCK1 {
+				regulator-name = "VDD_SOC";
+				regulator-min-microvolt = <610000>;
+				regulator-max-microvolt = <950000>;
+				regulator-boot-on;
+				regulator-always-on;
+				regulator-ramp-delay = <3125>;
+			};
+
+			buck2: BUCK2 {
+				regulator-name = "VDDQ_0V6";
+				regulator-min-microvolt = <600000>;
+				regulator-max-microvolt = <600000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			buck4: BUCK4 {
+				regulator-name = "VDD_3V3_BUCK";
+				regulator-min-microvolt = <3300000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			buck5: BUCK5 {
+				regulator-name = "VDD_1V8";
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			buck6: BUCK6 {
+				regulator-name = "VDD_1V1";
+				regulator-min-microvolt = <1100000>;
+				regulator-max-microvolt = <1100000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			ldo1: LDO1 {
+				regulator-name = "PMIC_SNVS_1V8";
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			ldo4: LDO4 {
+				regulator-name = "VDD_0V8";
+				regulator-min-microvolt = <800000>;
+				regulator-max-microvolt = <800000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			ldo5: LDO5 {
+				regulator-name = "NVCC_SD2";
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+		};
+	};
+
+	eeprom at 50 {
+		compatible = "atmel,24c32";
+		reg = <0x50>;
+		pagesize = <32>;
+		vcc-supply = <&buck4>;
+	};
+
+	eepromid at 58 {
+		compatible = "atmel,24c32";
+		pagesize = <32>;
+		reg = <0x58>;
+		size = <32>;
+		vcc-supply = <&buck4>;
+	};
+};
+
+/* Ethernet */
+&eqos {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_eqos>;
+	phy-mode = "rmii";
+	phy-handle = <&ethphy2>;
+	assigned-clocks = <&clk IMX93_CLK_ENET_TIMER2>,
+			  <&clk IMX93_CLK_ENET>;
+	assigned-clock-parents = <&clk IMX93_CLK_SYS_PLL_PFD1_DIV2>,
+				 <&clk IMX93_CLK_SYS_PLL_PFD1_DIV2>;
+	assigned-clock-rates = <100000000>, <50000000>;
+	status = "okay";
+};
+
+/* ENET2 MDIO */
+&mdio {
+	ethphy2: ethernet-phy at 2 {
+		reg = <2>;
+		micrel,led-mode = <1>;
+		compatible = "ethernet-phy-id0022.1561";
+
+		/*
+		 * HACK:
+		 * IMX93_CLK_ENET is the ref clock and should be running at 50Mhz.
+		 * Using it here to tell the PHY we are running at 50MHz is not working.
+		 * Let us simply use another clock here.
+		 */
+		/* clocks = <&clk IMX93_CLK_ENET>; */
+		clocks = <&clk IMX93_CLK_ENET_REF_PHY>;
+		clock-names = "rmii-ref";
+	};
+};
+
+/* USB  */
+&usbotg1 {
+	disable-over-current;
+	dr_mode = "otg";
+	status = "okay";
+};
+
+&usbotg2 {
+	disable-over-current;
+	dr_mode = "host";
+	status = "okay";
+};
+
+/* SD-Card */
+&usdhc2 {
+	pinctrl-names = "default", "state_100mhz", "state_200mhz";
+	pinctrl-0 = <&pinctrl_usdhc2_default>, <&pinctrl_usdhc2_cd>;
+	pinctrl-1 = <&pinctrl_usdhc2_100mhz>, <&pinctrl_usdhc2_cd>;
+	pinctrl-2 = <&pinctrl_usdhc2_200mhz>, <&pinctrl_usdhc2_cd>;
+	cd-gpios = <&gpio3 00 GPIO_ACTIVE_LOW>;
+	vmmc-supply = <&reg_usdhc2_vmmc>;
+	bus-width = <4>;
+	disable-wp;
+	no-sdio;
+	no-mmc;
+	status = "okay";
+};
+
+/* need to config the SION for data and cmd pad, refer to ERR052021 */
+&pinctrl_usdhc2_default {
+	fsl,pins = <
+		MX93_PAD_SD2_CLK__USDHC2_CLK		0x159e
+		MX93_PAD_SD2_CMD__USDHC2_CMD		0x4000139e
+		MX93_PAD_SD2_DATA0__USDHC2_DATA0	0x4000138e
+		MX93_PAD_SD2_DATA1__USDHC2_DATA1	0x4000138e
+		MX93_PAD_SD2_DATA2__USDHC2_DATA2	0x4000138e
+		MX93_PAD_SD2_DATA3__USDHC2_DATA3	0x4000139e
+		MX93_PAD_SD2_VSELECT__USDHC2_VSELECT	0x51e
+	>;
+};
+
+/* need to config the SION for data and cmd pad, refer to ERR052021 */
+&pinctrl_usdhc2_100mhz {
+	fsl,pins = <
+		MX93_PAD_SD2_CLK__USDHC2_CLK            0x159e
+		MX93_PAD_SD2_CMD__USDHC2_CMD            0x4000139e
+		MX93_PAD_SD2_DATA0__USDHC2_DATA0        0x4000138e
+		MX93_PAD_SD2_DATA1__USDHC2_DATA1        0x4000138e
+		MX93_PAD_SD2_DATA2__USDHC2_DATA2        0x4000139e
+		MX93_PAD_SD2_DATA3__USDHC2_DATA3        0x4000139e
+		MX93_PAD_SD2_VSELECT__USDHC2_VSELECT    0x51e
+	>;
+};
+
+/* need to config the SION for data and cmd pad, refer to ERR052021 */
+&pinctrl_usdhc2_200mhz {
+	fsl,pins = <
+		MX93_PAD_SD2_CLK__USDHC2_CLK            0x158e
+		MX93_PAD_SD2_CMD__USDHC2_CMD            0x4000139e
+		MX93_PAD_SD2_DATA0__USDHC2_DATA0        0x4000139e
+		MX93_PAD_SD2_DATA1__USDHC2_DATA1        0x4000139e
+		MX93_PAD_SD2_DATA2__USDHC2_DATA2        0x4000139e
+		MX93_PAD_SD2_DATA3__USDHC2_DATA3        0x4000139e
+		MX93_PAD_SD2_VSELECT__USDHC2_VSELECT    0x51e
+	>;
+};
+
+
+&iomuxc {
+	pinctrl_eqos: eqosgrp {
+		fsl,pins = <
+			MX93_PAD_ENET1_TD2__CCM_ENET_QOS_CLOCK_GENERATE_REF_CLK 0x4000050e
+			MX93_PAD_ENET1_RD0__ENET_QOS_RGMII_RD0			0x57e
+			MX93_PAD_ENET1_RD1__ENET_QOS_RGMII_RD1			0x57e
+			MX93_PAD_ENET1_TD0__ENET_QOS_RGMII_TD0			0x50e
+			MX93_PAD_ENET1_TD1__ENET_QOS_RGMII_TD1			0x50e
+			MX93_PAD_ENET1_RX_CTL__ENET_QOS_RGMII_RX_CTL		0x57e
+			MX93_PAD_ENET1_TX_CTL__ENET_QOS_RGMII_TX_CTL		0x50e
+			MX93_PAD_ENET1_RXC__ENET_QOS_RX_ER			0x57e
+		>;
+	};
+	pinctrl_lpi2c3: lpi2c3grp {
+		fsl,pins = <
+			MX93_PAD_GPIO_IO28__LPI2C3_SDA			0x40000b9e
+			MX93_PAD_GPIO_IO29__LPI2C3_SCL			0x40000b9e
+		>;
+	};
+	pinctrl_pmic: pmicgrp {
+		fsl,pins = <
+			MX93_PAD_ENET2_RD3__GPIO4_IO27			0x31e
+		>;
+	};
+	pinctrl_rtc: rtcgrp {
+		fsl,pins = <
+			MX93_PAD_ENET2_RD2__GPIO4_IO26		0x31e
+		>;
+	};
+};
diff --git a/arch/arm/dts/imx93-phyboard-segin.dts b/arch/arm/dts/imx93-phyboard-segin.dts
new file mode 100644
index 0000000000000000000000000000000000000000..0fc69b8789661eaa3c904efbe3e439170a83adb6
--- /dev/null
+++ b/arch/arm/dts/imx93-phyboard-segin.dts
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR MIT)
+
+#include <arm64/freescale/imx93-phyboard-segin.dts>
+#include "imx93.dtsi"
+#include "imx93-phyboard-segin-downstream.dtsi"
+
+/ {
+	chosen {
+		environment-emmc {
+			compatible = "barebox,environment";
+			device-path = &environment_emmc;
+		};
+	};
+};
+
+&usdhc1 {
+	partitions {
+		compatible = "fixed-partitions";
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		environment_emmc: partition at 80000 {
+			label = "barebox-environment";
+			reg = <0x0 0x80000 0x0 0x80000>;
+		};
+	};
+
+};
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 5ae7ab12ee94f4fab3fe446904ea785c5cd51193..552e7227a0221fee8232dfba5dcdd60de923ff0c 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -746,6 +746,15 @@ config MACH_ZII_IMX8MQ_DEV
 
 comment "i.MX93 boards"
 
+config MACH_PHYTEC_PHYCORE_IMX93
+	bool "phyCORE i.MX93 SoM based devices"
+	select ARCH_IMX93
+	select IMX9_DRAM
+	select I2C
+	select I2C_IMX_LPI2C
+	select FIRMWARE_IMX93_ATF
+	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+
 config MACH_TQMA93XX
 	bool "TQ i.MX93 on TQMA93XX Board"
 	select ARCH_IMX93
diff --git a/images/Makefile.imx b/images/Makefile.imx
index c3f1bd5f05a008321944cf68659c146f8cd25ce1..93264254e9e4cda3969bf7bf4812f2d1c5b59c09 100644
--- a/images/Makefile.imx
+++ b/images/Makefile.imx
@@ -521,3 +521,7 @@ $(obj)/%.imx9img: $(obj)/% FORCE
 pblb-$(CONFIG_MACH_TQMA93XX) += start_imx93_tqma93xx
 FILE_barebox-tqma93xx.img = start_imx93_tqma93xx.pblb.imx9img
 image-$(CONFIG_MACH_TQMA93XX) += barebox-tqma93xx.img
+
+pblb-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX93) += start_imx93_phyboard_segin
+FILE_barebox-phyboard_segin.img = start_imx93_phyboard_segin.pblb.imx9img
+image-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX93) += barebox-phyboard_segin.img

---
base-commit: 75296e2aa356f6fbd680aa2204545732ac49e37d
change-id: 20250304-phyboard-segin-imx93-257c1809d4f8

Best regards,
-- 
Jonas Rebmann <jre at pengutronix.de>



From stefano.manni at gmail.com  Tue Mar  4 09:49:02 2025
From: stefano.manni at gmail.com (Stefano Manni)
Date: Tue, 04 Mar 2025 18:49:02 +0100
Subject: [PATCH 1/2] imx-bbu-nand-fcb: do not use hardcoded devicefile
In-Reply-To: <3a8afe4a-f7e7-4158-b302-09f67dc11d8f@pengutronix.de>
References: <20250221180109.14129-1-stefano.manni@gmail.com>
	<06d40295-264c-4119-a201-f6e045def59d@pengutronix.de>
	<6N27SS.D8B9D3CEGOUH3@gmail.com>
	<3a8afe4a-f7e7-4158-b302-09f67dc11d8f@pengutronix.de>
Message-ID: <QH1MSS.NEOFAGTU4XUA1@gmail.com>



Hello Ahmad,

On lun, mar 3 2025 at 09:41:53 +01:00:00, Ahmad Fatoum 
<a.fatoum at pengutronix.de> wrote:
> On 24.02.25 16:49, Stefano Manni wrote:
>>  Hello Ahmad,
>> 
>>  On ven, feb 21 2025 at 18:33:04 +01:00:00, Ahmad Fatoum 
>> <a.fatoum at pengutronix.de> wrote:
>>>  Hello Stefano,
>>> 
>>>  On 21.02.25 19:01, Stefano Manni wrote:
>>>>   Device file was hardcoded to "nand0.barebox".
>>>>   This patch harmonize the signature of
>>>> 
>>>>   imx6_bbu_nand_register_handler()
>>>>   imx7_bbu_nand_register_handler()
>>>>   imx28_bbu_nand_register_handler()
>>>> 
>>>>   with the other bbu register functions in order to take
>>>>   the devicefile as parameter.
>>> 
>>>  Is this this the sole motivation behind the patch or do you
>>>  intend to actually make use of the ability of varying
>>>  the devicefile?
>> 
>>  my purpose is to let people use a device/partition different from 
>> the hardcoded one.
> 
> Can you have multiple NANDs? But yes, customizing partition name can
> be useful.
> 

for sure I cannot have multiple NANDs but I can have a different 
partition name.

Anyway drop the patch if you consider it not necessary.

Best,
Stefano

> Thanks,
> Ahmad




From a.fatoum at pengutronix.de  Tue Mar  4 09:39:56 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 4 Mar 2025 18:39:56 +0100
Subject: [PATCH 1/2] imx-bbu-nand-fcb: do not use hardcoded devicefile
In-Reply-To: <QH1MSS.NEOFAGTU4XUA1@gmail.com>
References: <20250221180109.14129-1-stefano.manni@gmail.com>
 <06d40295-264c-4119-a201-f6e045def59d@pengutronix.de>
 <6N27SS.D8B9D3CEGOUH3@gmail.com>
 <3a8afe4a-f7e7-4158-b302-09f67dc11d8f@pengutronix.de>
 <QH1MSS.NEOFAGTU4XUA1@gmail.com>
Message-ID: <9f921a53-df29-4e7c-93e1-444b1068dd35@pengutronix.de>

On 04.03.25 18:49, Stefano Manni wrote:
> 
> 
> Hello Ahmad,
> 
> On lun, mar 3 2025 at 09:41:53 +01:00:00, Ahmad Fatoum <a.fatoum at pengutronix.de> wrote:
>> On 24.02.25 16:49, Stefano Manni wrote:
>>> ?Hello Ahmad,
>>>
>>> ?On ven, feb 21 2025 at 18:33:04 +01:00:00, Ahmad Fatoum <a.fatoum at pengutronix.de> wrote:
>>>> ?Hello Stefano,
>>>>
>>>> ?On 21.02.25 19:01, Stefano Manni wrote:
>>>>> ? Device file was hardcoded to "nand0.barebox".
>>>>> ? This patch harmonize the signature of
>>>>>
>>>>> ? imx6_bbu_nand_register_handler()
>>>>> ? imx7_bbu_nand_register_handler()
>>>>> ? imx28_bbu_nand_register_handler()
>>>>>
>>>>> ? with the other bbu register functions in order to take
>>>>> ? the devicefile as parameter.
>>>>
>>>> ?Is this this the sole motivation behind the patch or do you
>>>> ?intend to actually make use of the ability of varying
>>>> ?the devicefile?
>>>
>>> ?my purpose is to let people use a device/partition different from the hardcoded one.
>>
>> Can you have multiple NANDs? But yes, customizing partition name can
>> be useful.
>>
> 
> for sure I cannot have multiple NANDs but I can have a different partition name.
> 
> Anyway drop the patch if you consider it not necessary.

I think the patch is ok.

Cheers,
Ahmad

> 
> Best,
> Stefano
> 
>> Thanks,
>> 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-5555 |


From martin.l.wege at gmail.com  Tue Mar  4 13:50:00 2025
From: martin.l.wege at gmail.com (Martin Wege)
Date: Tue, 4 Mar 2025 22:50:00 +0100
Subject: Mount NFSv4.2 filesystem in barebox?
In-Reply-To: <3ba4d5f3-9679-4a32-a3e7-a8c958107df9@pengutronix.de>
References: <CANH4o6Njc3uHE=NbasRJrRr0W5B89R8MTM_BwGwab7t5fNWuaA@mail.gmail.com>
 <Z6yxUVTp0vGWqs7Q@pengutronix.de> <CANH4o6NRK2+ekNe_LrUaoAi8PVbi-MC3hWerv4g6F-WmXmyK5w@mail.gmail.com>
 <Z8GWfv4oIhB7CDSU@pengutronix.de> <3ba4d5f3-9679-4a32-a3e7-a8c958107df9@pengutronix.de>
Message-ID: <CANH4o6PN3tJC+zLt_eLeKzJ6BVFnGo+vYFDF+9Hjp9x6oz626g@mail.gmail.com>

On Mon, Mar 3, 2025 at 9:40?AM Ahmad Fatoum <a.fatoum at pengutronix.de> wrote:
>
> Hi,
>
> On 28.02.25 11:57, Sascha Hauer wrote:
> > On Fri, Feb 21, 2025 at 12:54:00PM +0100, Martin Wege wrote:
> >> On Wed, Feb 12, 2025 at 3:33?PM Sascha Hauer <s.hauer at pengutronix.de> wrote:
> >>>
> >>> Hi Martin,
> >>>
> >>> On Tue, Feb 11, 2025 at 01:56:58PM +0100, Martin Wege wrote:
> >>>> Hello!
> >>>>
> >>>> Does barebox have support to mount a NFSv.2 filesystem?
> >>>
> >>> No, not yet. For NFSv4 we would first need TCP support. While we started
> >>> to integrate a TCP stack we are not there yet unfortunately.
> >>
> >> How long is this going to take?
> >
> > I don't think this will happen anytime soon. It's quite some work and
> > our bandwidth for adding such a feature without (paying) customer
> > demand is limited.
> >
> > That said, the lack of NFSv4 support is nagging me personally as well.
>
> We had a discussion about this last year, but it didn't result in any
> upstream code yet:
> https://lore.barebox.org/barebox/CAAvCNcCZhS8mkvdgcJ2L-eiur+OxgWEXRLnadO_HFyHfSi7WFA at mail.gmail.com/
>
> One question that I still have, is what do you use NFSv4 for?
> Is it just for development and your IT is disabling NFSv3?

No, NFSv4.1 (NFSv4.0 is obsolete due to bugs) offers better
performance, more flexibility, smaller footprint, better caching
(delegations), ACLs, SELinux support, and can be tunneled through
firewalls because it only uses TCP port 2049 and nothing else.

>
> Do you use it in the field?

Yes, we do

>
> Knowing about the use case helps with prioritizing future work.
> As it stands, NFS is mostly understood as development feature and
> it's expected so far that interested users will be able to provide
> a NFSv3 UDP server in their development network.

No, NFS is not only a development feature. For example CERN uses NFS
boot (with patched NFSv4.1 stack) in radiation environments - that
saves a SSD per embedded machine, which is typically one of the most
affected pieces from radiation. AIRBUS also uses nfsboot in their
equipment and flight deck systems.

So yes, you would have customers for NFSv4.1 support in barebox.

Thanks,
Martin


From eagle.alexander923 at gmail.com  Tue Mar  4 22:20:58 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Wed,  5 Mar 2025 09:20:58 +0300
Subject: [PATCH 1/4] at91:: Remove dead definition of atmel_nand_load_image()
Message-ID: <20250305062101.25588-1-eagle.alexander923@gmail.com>

atmel_nand_load_image() is not defined anywhere.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 include/mach/at91/board.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/mach/at91/board.h b/include/mach/at91/board.h
index 5f04f9c849..7edadeafba 100644
--- a/include/mach/at91/board.h
+++ b/include/mach/at91/board.h
@@ -31,8 +31,6 @@ struct at91_usbh_data {
 extern void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data);
 extern void __init at91_add_device_usbh_ehci(struct at91_usbh_data *data);
 
-void atmel_nand_load_image(void *dest, int size, int pagesize, int blocksize);
-
  /* USB Device */
 struct at91_udc_data {
 	int	vbus_pin;		/* high == host powering us */
-- 
2.39.1



From eagle.alexander923 at gmail.com  Tue Mar  4 22:20:59 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Wed,  5 Mar 2025 09:20:59 +0300
Subject: [PATCH 2/4] at91: Use the ddramc driver for all boards whose architecture uses it
In-Reply-To: <20250305062101.25588-1-eagle.alexander923@gmail.com>
References: <20250305062101.25588-1-eagle.alexander923@gmail.com>
Message-ID: <20250305062101.25588-2-eagle.alexander923@gmail.com>

Reuse ddramc driver for all SAMA5D2/3/4 boards.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/boards/sama5d4_xplained/lowlevel.c |  4 ++--
 arch/arm/mach-at91/ddramc.c                 |  4 ++--
 arch/arm/mach-at91/sama5d3_devices.c        |  7 +++----
 arch/arm/mach-at91/sama5d4_devices.c        |  7 +++----
 include/mach/at91/at91_ddrsdrc.h            | 11 -----------
 5 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/arch/arm/boards/sama5d4_xplained/lowlevel.c b/arch/arm/boards/sama5d4_xplained/lowlevel.c
index 183bd9c5a9..5763333f39 100644
--- a/arch/arm/boards/sama5d4_xplained/lowlevel.c
+++ b/arch/arm/boards/sama5d4_xplained/lowlevel.c
@@ -10,7 +10,7 @@
 #include <asm/barebox-arm-head.h>
 #include <asm/barebox-arm.h>
 
-#include <mach/at91/at91_ddrsdrc.h>
+#include <mach/at91/ddramc.h>
 #include <mach/at91/hardware.h>
 
 void __naked __bare_init barebox_arm_reset_vector(uint32_t r0, uint32_t r1, uint32_t r2)
@@ -19,5 +19,5 @@ void __naked __bare_init barebox_arm_reset_vector(uint32_t r0, uint32_t r1, uint
 
 	arm_setup_stack(SAMA5D4_SRAM_BASE + SAMA5D4_SRAM_SIZE);
 
-	barebox_arm_entry(SAMA5_DDRCS, at91sama5d4_get_ddram_size(), NULL);
+	sama5d4_barebox_entry(0, NULL);
 }
diff --git a/arch/arm/mach-at91/ddramc.c b/arch/arm/mach-at91/ddramc.c
index 4d0637b487..ca77889ecc 100644
--- a/arch/arm/mach-at91/ddramc.c
+++ b/arch/arm/mach-at91/ddramc.c
@@ -30,14 +30,14 @@ void __noreturn sama5d3_barebox_entry(unsigned int r4, void *boarddata)
 {
 	__sama5d3_stashed_bootrom_r4 = r4;
 
-	barebox_arm_entry(SAMA5_DDRCS, at91sama5d3_get_ddram_size(),
+	barebox_arm_entry(SAMA5_DDRCS, sama5_ramsize(IOMEM(SAMA5D3_BASE_MPDDRC)),
 			  boarddata);
 }
 void __noreturn sama5d4_barebox_entry(unsigned int r4, void *boarddata)
 {
 	__sama5d4_stashed_bootrom_r4 = r4;
 
-	barebox_arm_entry(SAMA5_DDRCS, at91sama5d4_get_ddram_size(),
+	barebox_arm_entry(SAMA5_DDRCS, sama5_ramsize(IOMEM(SAMA5D4_BASE_MPDDRC)),
 			  boarddata);
 }
 
diff --git a/arch/arm/mach-at91/sama5d3_devices.c b/arch/arm/mach-at91/sama5d3_devices.c
index f6d5617e5f..4871c2bd69 100644
--- a/arch/arm/mach-at91/sama5d3_devices.c
+++ b/arch/arm/mach-at91/sama5d3_devices.c
@@ -21,10 +21,9 @@
 
 void at91_add_device_sdram(u32 size)
 {
-	if (!size)
-		size = at91sama5d3_get_ddram_size();
-
-	arm_add_mem_device("ram0", SAMA5_DDRCS, size);
+	add_generic_device("sama5-ddramc", DEVICE_ID_SINGLE, NULL,
+			   SAMA5D3_BASE_MPDDRC, SZ_512,
+			   IORESOURCE_MEM, NULL);
 	add_mem_device("sram0", SAMA5D3_SRAM_BASE,
 			SAMA5D3_SRAM_SIZE, IORESOURCE_MEM_WRITEABLE);
 }
diff --git a/arch/arm/mach-at91/sama5d4_devices.c b/arch/arm/mach-at91/sama5d4_devices.c
index e438bd0d10..4a81e7cd40 100644
--- a/arch/arm/mach-at91/sama5d4_devices.c
+++ b/arch/arm/mach-at91/sama5d4_devices.c
@@ -21,10 +21,9 @@
 
 void at91_add_device_sdram(u32 size)
 {
-	if (!size)
-		size = at91sama5d4_get_ddram_size();
-
-	arm_add_mem_device("ram0", SAMA5_DDRCS, size);
+	add_generic_device("sama5-ddramc", DEVICE_ID_SINGLE, NULL,
+			   SAMA5D4_BASE_MPDDRC, SZ_512,
+			   IORESOURCE_MEM, NULL);
 	add_mem_device("sram0", SAMA5D4_SRAM_BASE,
 		       SAMA5D4_SRAM_SIZE, IORESOURCE_MEM_WRITEABLE);
 }
diff --git a/include/mach/at91/at91_ddrsdrc.h b/include/mach/at91/at91_ddrsdrc.h
index b9b0eb20b3..d511e157b2 100644
--- a/include/mach/at91/at91_ddrsdrc.h
+++ b/include/mach/at91/at91_ddrsdrc.h
@@ -357,17 +357,6 @@ static inline u32 at91sam9n12_get_ddram_size(void)
 	return at91_get_ddram_size(IOMEM(AT91SAM9N12_BASE_DDRSDRC0), true);
 }
 
-static inline u32 at91sama5d3_get_ddram_size(void)
-{
-	return at91_get_ddram_size(IOMEM(SAMA5D3_BASE_MPDDRC), true);
-}
-
-static inline u32 at91sama5d4_get_ddram_size(void)
-{
-	return at91_get_ddram_size(IOMEM(SAMA5D4_BASE_MPDDRC), true);
-}
-
-
 #endif /* __ASSEMBLY__ */
 
 #endif	/* #ifndef __AT91_DDRSDRC_H__ */
-- 
2.39.1



From eagle.alexander923 at gmail.com  Tue Mar  4 22:21:00 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Wed,  5 Mar 2025 09:21:00 +0300
Subject: [PATCH 3/4] at91: ddramc: Trivial code cleanup
In-Reply-To: <20250305062101.25588-1-eagle.alexander923@gmail.com>
References: <20250305062101.25588-1-eagle.alexander923@gmail.com>
Message-ID: <20250305062101.25588-3-eagle.alexander923@gmail.com>

Trivial code cleanup, which includes:
- Adding/removing blank lines for better code readability.
- Wrapping the of_compatible driver property in DRV_OF_COMPAT().

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/ddramc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-at91/ddramc.c b/arch/arm/mach-at91/ddramc.c
index ca77889ecc..ffedd39d6b 100644
--- a/arch/arm/mach-at91/ddramc.c
+++ b/arch/arm/mach-at91/ddramc.c
@@ -22,6 +22,7 @@ static unsigned sama5_ramsize(void __iomem *base)
 void __noreturn sama5d2_barebox_entry(unsigned int r4, void *boarddata)
 {
 	__sama5d2_stashed_bootrom_r4 = r4;
+
 	barebox_arm_entry(SAMA5_DDRCS, sama5_ramsize(SAMA5D2_BASE_MPDDRC),
 			  boarddata);
 }
@@ -33,6 +34,7 @@ void __noreturn sama5d3_barebox_entry(unsigned int r4, void *boarddata)
 	barebox_arm_entry(SAMA5_DDRCS, sama5_ramsize(IOMEM(SAMA5D3_BASE_MPDDRC)),
 			  boarddata);
 }
+
 void __noreturn sama5d4_barebox_entry(unsigned int r4, void *boarddata)
 {
 	__sama5d4_stashed_bootrom_r4 = r4;
@@ -54,7 +56,7 @@ static int sama5_ddr_probe(struct device *dev)
 	return arm_add_mem_device("ram0", SAMA5_DDRCS, sama5_ramsize(base));
 }
 
-static struct of_device_id sama5_ddr_dt_ids[] = {
+static __maybe_unused struct of_device_id sama5_ddr_dt_ids[] = {
 	{ .compatible = "atmel,sama5d3-ddramc" },
 	{ /* sentinel */ }
 };
@@ -63,7 +65,6 @@ MODULE_DEVICE_TABLE(of, sama5_ddr_dt_ids);
 static struct driver sama5_ddr_driver = {
 	.name   = "sama5-ddramc",
 	.probe  = sama5_ddr_probe,
-	.of_compatible = sama5_ddr_dt_ids,
+	.of_compatible = DRV_OF_COMPAT(sama5_ddr_dt_ids),
 };
-
 mem_platform_driver(sama5_ddr_driver);
-- 
2.39.1



From eagle.alexander923 at gmail.com  Tue Mar  4 22:21:01 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Wed,  5 Mar 2025 09:21:01 +0300
Subject: [PATCH 4/4] at91: Use proper values of stashed SAMA5D2/3/4 bootsource
In-Reply-To: <20250305062101.25588-1-eagle.alexander923@gmail.com>
References: <20250305062101.25588-1-eagle.alexander923@gmail.com>
Message-ID: <20250305062101.25588-4-eagle.alexander923@gmail.com>

Since the SRAM area varies across different processor variants,
let's make a distinction for stashed bootsource recovery.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/sama5_bootsource.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-at91/sama5_bootsource.c b/arch/arm/mach-at91/sama5_bootsource.c
index 4ede256e8f..0d91f5fb5a 100644
--- a/arch/arm/mach-at91/sama5_bootsource.c
+++ b/arch/arm/mach-at91/sama5_bootsource.c
@@ -19,11 +19,15 @@
  */
 static int sama5_bootsource_init(void)
 {
-	if (!of_machine_is_compatible("atmel,sama5"))
+	if (of_machine_is_compatible("atmel,sama5d2"))
+		at91_bootsource = __sama5d2_stashed_bootrom_r4;
+	else if (of_machine_is_compatible("atmel,sama5d3"))
+		at91_bootsource = __sama5d3_stashed_bootrom_r4;
+	else if (of_machine_is_compatible("atmel,sama5d4"))
+		at91_bootsource = __sama5d4_stashed_bootrom_r4;
+	else
 		return 0;
 
-	at91_bootsource = __sama5d2_stashed_bootrom_r4;
-
 	if (at91_bootsource)
 		bootsource_set_raw(sama5_bootsource(at91_bootsource),
 				   sama5_bootsource_instance(at91_bootsource));
-- 
2.39.1



From eagle.alexander923 at gmail.com  Tue Mar  4 23:48:35 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Wed,  5 Mar 2025 10:48:35 +0300
Subject: [PATCH] at91: sama5d2: Do not use the contents of BSC_CR if the DISABLE_BSCR bit is set in the fuse
Message-ID: <20250305074835.34782-1-eagle.alexander923@gmail.com>

The DISABLE_BSCR bit in Fuse means "Does not read BSC_CR content,
so the Boot settings are those from the Fuse".
Let's ignore BSC_CR it this case.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 include/mach/at91/sama5d2.h | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/include/mach/at91/sama5d2.h b/include/mach/at91/sama5d2.h
index 90b566ffc4..d8a450255f 100644
--- a/include/mach/at91/sama5d2.h
+++ b/include/mach/at91/sama5d2.h
@@ -305,16 +305,18 @@ static inline void __iomem *sama5d2_pio_map_bank(int bank, unsigned *id)
 
 static inline u32 sama5d2_bootcfg(void)
 {
-	u32 __iomem *bureg = SAMA5D2_BASE_SECURAM + 0x1400;
-	u32 bsc_cr = readl(SAMA5D2_BASE_SYSC + 0x54);
-	u32 __iomem *bootcfg;
+	u32 bsc_cr, bootcfg = readl(SAMA5D2_SFC_DR(16));
 
-	if (bsc_cr & SAMA5D2_BUREG_VALID)
-		bootcfg = &bureg[FIELD_GET(SAMA5D2_BUREG_INDEX, bsc_cr)];
-	else
-		bootcfg = SAMA5D2_SFC_DR(512 / 32);
+	if (bootcfg & SAMA5D2_DISABLE_BSC_CR)
+		return bootcfg;
 
-	return readl(bootcfg);
+	bsc_cr = readl(SAMA5D2_BASE_SYSC + 0x54);
+	if (bsc_cr & SAMA5D2_BUREG_VALID) {
+		u32 __iomem *bureg = SAMA5D2_BASE_SECURAM + 0x1400;
+		bootcfg = readl(&bureg[FIELD_GET(SAMA5D2_BUREG_INDEX, bsc_cr)]);
+	}
+
+	return bootcfg;
 }
 
 #endif
-- 
2.39.1



From s.hauer at pengutronix.de  Wed Mar  5 03:17:58 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 05 Mar 2025 12:17:58 +0100
Subject: [PATCH 0/5] SoCFPGA: Arria10: sdram: cleanup and fix DDR
 driver
In-Reply-To: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
References: <20250303-v2025-02-0-topic-socfpga-arria10-v1-0-d66021246a66@pengutronix.de>
Message-ID: <174117347816.1911229.14146792947451830485.b4-ty@pengutronix.de>


On Mon, 03 Mar 2025 09:59:16 +0100, Steffen Trumtrar wrote:
> When the L4WD0 is left enabled on startup, depending on handoff files
> and its PLL settings, the DDR code might hang while waiting for the
> calibration to be successful. Rework this code and cleanup the rest of
> the driver a little bit while we are at it.
> 
> Tested on an Enclustra PE1 board.
> 
> [...]

Applied, thanks!

[1/5] ARM: SoCFPGA: move wait_on_timeout to generic
      https://git.pengutronix.de/cgit/barebox/commit/?id=5080f1eae33d (link may not be stable)
[2/5] ARM: SoCFPGA: arria10-sdram: cleanup emif_clear
      https://git.pengutronix.de/cgit/barebox/commit/?id=7d639315b48c (link may not be stable)
[3/5] ARM: SoCFPGA: arria10-sdram: cleanup emif_reset
      https://git.pengutronix.de/cgit/barebox/commit/?id=41ec8cbd8bfb (link may not be stable)
[4/5] ARM: SoCFPGA: arria10-sdram: remove workaround
      https://git.pengutronix.de/cgit/barebox/commit/?id=da158a7fd07b (link may not be stable)
[5/5] ARM: SoCFPGA: arria10-sdram: cleanup ddr_setup
      https://git.pengutronix.de/cgit/barebox/commit/?id=c97ef53a7eae (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Wed Mar  5 03:14:47 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Mar 2025 12:14:47 +0100
Subject: [PATCH 1/2] imx-bbu-nand-fcb: do not use hardcoded devicefile
In-Reply-To: <20250221180109.14129-1-stefano.manni@gmail.com>
References: <20250221180109.14129-1-stefano.manni@gmail.com>
Message-ID: <Z8gyJ2_jXp12dhz1@pengutronix.de>

Hi Stefano,

I merged both patches into one to avoid intermediate breakage.

On Fri, Feb 21, 2025 at 07:01:08PM +0100, Stefano Manni wrote:
> @@ -1599,7 +1607,8 @@ static int imx7_fcb_write(struct mtd_info *mtd, int block, struct fcb_block *fcb
>  	return mxs_nand_write_fcb_bch62(block, fcb, sizeof(*fcb));
>  }
>  
> -int imx7_bbu_nand_register_handler(const char *name, unsigned long flags)
> +int imx7_bbu_nand_register_handler(const char *name
> +	   const char *devicefile, unsigned long flags)
>  {

Also added the missing comma after *name

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Wed Mar  5 03:13:06 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 05 Mar 2025 12:13:06 +0100
Subject: [PATCH 1/2] imx-bbu-nand-fcb: do not use hardcoded devicefile
In-Reply-To: <20250221180109.14129-1-stefano.manni@gmail.com>
References: <20250221180109.14129-1-stefano.manni@gmail.com>
Message-ID: <174117318683.1834643.2938189549054116629.b4-ty@pengutronix.de>


On Fri, 21 Feb 2025 19:01:08 +0100, Stefano Manni wrote:
> Device file was hardcoded to "nand0.barebox".
> This patch harmonize the signature of
> 
> imx6_bbu_nand_register_handler()
> imx7_bbu_nand_register_handler()
> imx28_bbu_nand_register_handler()
> 
> [...]

Applied, thanks!

[1/2] imx-bbu-nand-fcb: do not use hardcoded devicefile
      https://git.pengutronix.de/cgit/barebox/commit/?id=e377e1a068db (link may not be stable)
[2/2] ARM: boards: fix nand bbu_handler device paths
      (no commit info)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From david at protonic.nl  Wed Mar  5 03:30:32 2025
From: david at protonic.nl (David Jander)
Date: Wed, 5 Mar 2025 12:30:32 +0100
Subject: Mount NFSv4.2 filesystem in barebox?
In-Reply-To: <CANH4o6PN3tJC+zLt_eLeKzJ6BVFnGo+vYFDF+9Hjp9x6oz626g@mail.gmail.com>
References: <CANH4o6Njc3uHE=NbasRJrRr0W5B89R8MTM_BwGwab7t5fNWuaA@mail.gmail.com>
	<Z6yxUVTp0vGWqs7Q@pengutronix.de>
	<CANH4o6NRK2+ekNe_LrUaoAi8PVbi-MC3hWerv4g6F-WmXmyK5w@mail.gmail.com>
	<Z8GWfv4oIhB7CDSU@pengutronix.de>
	<3ba4d5f3-9679-4a32-a3e7-a8c958107df9@pengutronix.de>
	<CANH4o6PN3tJC+zLt_eLeKzJ6BVFnGo+vYFDF+9Hjp9x6oz626g@mail.gmail.com>
Message-ID: <20250305123032.2b2c7768@erd003.prtnl>


Dear Martin,

On Tue, 4 Mar 2025 22:50:00 +0100
Martin Wege <martin.l.wege at gmail.com> wrote:

> On Mon, Mar 3, 2025 at 9:40?AM Ahmad Fatoum <a.fatoum at pengutronix.de> wrote:
> >
> > Hi,
> >
> > On 28.02.25 11:57, Sascha Hauer wrote:  
> > > On Fri, Feb 21, 2025 at 12:54:00PM +0100, Martin Wege wrote:  
> > >> On Wed, Feb 12, 2025 at 3:33?PM Sascha Hauer <s.hauer at pengutronix.de> wrote:  
> > >>>
> > >>> Hi Martin,
> > >>>
> > >>> On Tue, Feb 11, 2025 at 01:56:58PM +0100, Martin Wege wrote:  
> > >>>> Hello!
> > >>>>
> > >>>> Does barebox have support to mount a NFSv.2 filesystem?  
> > >>>
> > >>> No, not yet. For NFSv4 we would first need TCP support. While we started
> > >>> to integrate a TCP stack we are not there yet unfortunately.  
> > >>
> > >> How long is this going to take?  
> > >
> > > I don't think this will happen anytime soon. It's quite some work and
> > > our bandwidth for adding such a feature without (paying) customer
> > > demand is limited.
> > >
> > > That said, the lack of NFSv4 support is nagging me personally as well.  
> >
> > We had a discussion about this last year, but it didn't result in any
> > upstream code yet:
> > https://lore.barebox.org/barebox/CAAvCNcCZhS8mkvdgcJ2L-eiur+OxgWEXRLnadO_HFyHfSi7WFA at mail.gmail.com/
> >
> > One question that I still have, is what do you use NFSv4 for?
> > Is it just for development and your IT is disabling NFSv3?  
> 
> No, NFSv4.1 (NFSv4.0 is obsolete due to bugs) offers better
> performance, more flexibility, smaller footprint, better caching
> (delegations), ACLs, SELinux support, and can be tunneled through
> firewalls because it only uses TCP port 2049 and nothing else.
> 
> >
> > Do you use it in the field?  
> 
> Yes, we do
> 
> >
> > Knowing about the use case helps with prioritizing future work.
> > As it stands, NFS is mostly understood as development feature and
> > it's expected so far that interested users will be able to provide
> > a NFSv3 UDP server in their development network.  
> 
> No, NFS is not only a development feature. For example CERN uses NFS
> boot (with patched NFSv4.1 stack) in radiation environments - that
> saves a SSD per embedded machine, which is typically one of the most
> affected pieces from radiation. AIRBUS also uses nfsboot in their
> equipment and flight deck systems.
> 
> So yes, you would have customers for NFSv4.1 support in barebox.

Just wanted to chime in to amplify this a bit, since we are also using NFSv4.2
netboot (though only TFTP in barebox for now):

Your arguments are solid, and make a lot of sense. If you are going to replace
more and more microcontroller based nodes with Linux capable SoCs, because it
makes a lot of economical sense (hardware costs are very similar nowadays, and
software development is 10x easier and cheaper on Linux than on a uC), you
will end up inevitably with a lot of Linux nodes inside of a machine or
industrial plant, where you previously had uC's. So, do you want to continue
using 1970's tech (RS485/modbus) or 1980's tech (CAN) to communicate between all
those nodes, or will you use Linux's native language (TCP/IP) which also
immediately means another 10x reduction in software development costs of the
networking part? If you choose the latter, you will also get significant HW
cost savings basically for free if you also net-boot (via NFS and/or TFTP).

In other words, why are we not already doing this?

At least we are. We are starting to use Single Pair Ethernet almost everywhere
where there were other field-busses involved traditionally. So we noticed that
we end up with a lot of boards running Linux connected together via anything
from 10Base-T1L to 1000Base-T1. Replace the eMMC chip on all but one of them
with a cheap 2MiB SPI-NOR flash to load barebox and netboot from one single
board running an NFSv4.2 (and TFTP) server serving the kernel and rootfs for
all the others from a single eMMC, that can be updated with a single RAUC
bundle guaranteeing consistent software and trivially easy updates on all
nodes at once. Not to mention the benefit of trivial repairs because all
boards are basically dumb and don't need to be flashed with software that
matches the machine they are being replaced in, etc...

To be fair though, it isn't strictly needed for barebox to have NFS support
for our use-case, since it suffices to load the kernel (and possibly an
initramfs) via TFTP and mount the nfsroot from the kernel, but IMHO it is
certainly valuable to have basic NFSv4.2 support in barebox. It would
facilitate the use of just 1 protocol instead of 2. I also agree that NFSv3
support in that regard offers little value since you really don't want to base
everything on this obsolete version with all of its limitations.

But also a bit of caution to be mindful of: Cybersecurity. Of course barebox
can be made to only boot signed fit images, but are there other potential
attack vectors? What if the NFS server needs to be secured with with GSS and
kerberos? Barebox possibly won't be able to access it unless it also supports
that.

P.S.: I am currently not subscribed to the barebox mailing list, so I don't
know if this email will get forwarded by the list server.

Best regards,

-- 
David Jander


From a.fatoum at pengutronix.de  Wed Mar  5 04:03:09 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 5 Mar 2025 13:03:09 +0100
Subject: Mount NFSv4.2 filesystem in barebox?
In-Reply-To: <CANH4o6PN3tJC+zLt_eLeKzJ6BVFnGo+vYFDF+9Hjp9x6oz626g@mail.gmail.com>
References: <CANH4o6Njc3uHE=NbasRJrRr0W5B89R8MTM_BwGwab7t5fNWuaA@mail.gmail.com>
 <Z6yxUVTp0vGWqs7Q@pengutronix.de>
 <CANH4o6NRK2+ekNe_LrUaoAi8PVbi-MC3hWerv4g6F-WmXmyK5w@mail.gmail.com>
 <Z8GWfv4oIhB7CDSU@pengutronix.de>
 <3ba4d5f3-9679-4a32-a3e7-a8c958107df9@pengutronix.de>
 <CANH4o6PN3tJC+zLt_eLeKzJ6BVFnGo+vYFDF+9Hjp9x6oz626g@mail.gmail.com>
Message-ID: <19b1fcef-836e-450b-9cf7-e1d5ccd4e416@pengutronix.de>

Hello Martin,

On 04.03.25 22:50, Martin Wege wrote:
> On Mon, Mar 3, 2025 at 9:40?AM Ahmad Fatoum <a.fatoum at pengutronix.de> wrote:
>> We had a discussion about this last year, but it didn't result in any
>> upstream code yet:
>> https://lore.barebox.org/barebox/CAAvCNcCZhS8mkvdgcJ2L-eiur+OxgWEXRLnadO_HFyHfSi7WFA at mail.gmail.com/
>>
>> One question that I still have, is what do you use NFSv4 for?
>> Is it just for development and your IT is disabling NFSv3?
> 
> No, NFSv4.1 (NFSv4.0 is obsolete due to bugs) offers better
> performance, more flexibility, smaller footprint, better caching
> (delegations), ACLs, SELinux support, and can be tunneled through
> firewalls because it only uses TCP port 2049 and nothing else.

I am speaking in particular about NFS use in barebox itself,
where you'll likely to not benefit from better caching, ACLs, SELinux
support and so on. The kernel NFS server can provide both v3 and v4
in parallel and you can already set in barebox

  global.linux.rootnfsopts="v4,tcp"

So the booted kernel need not have any NFSv3 UDP support at all.

As David mentioned using TFTP in barebox instead of NFS is an option
as well for as long there is no NFSv4 support if NFSv3 is a no-go.

>> Do you use it in the field?
> 
> Yes, we do

So, you use barebox to load a kernel from NFS and then use the same
NFS as rootfs in production and currently you are using NFSv3
for both?

>> Knowing about the use case helps with prioritizing future work.
>> As it stands, NFS is mostly understood as development feature and
>> it's expected so far that interested users will be able to provide
>> a NFSv3 UDP server in their development network.
> 
> No, NFS is not only a development feature. For example CERN uses NFS
> boot (with patched NFSv4.1 stack) in radiation environments - that
> saves a SSD per embedded machine, which is typically one of the most
> affected pieces from radiation. AIRBUS also uses nfsboot in their
> equipment and flight deck systems.

We also use NFS at work for the developer workstations. My question
is strictly about _your_ NFS usage in barebox.

> So yes, you would have customers for NFSv4.1 support in barebox.

Just to clarify: I would love to see barebox support TCP and newer NFS
versions and if someone were to contribute that, I'd be happy to help with
testing and review to see it merged upstream.

So far, we had three threads on the mailing list, where users asked about
our plans. However, I haven't managed to find out how in particular they
currently use the NFS support in barebox.

We (as in the barebox maintainers) haven't been approached by a paying
customer interested in adding that support. That means, the topic has
to compete against other features we are interested in adding to barebox.

So far, NFSv4 has been low priority for us (TCP itself is not though and
I hope we might get there this year). So the way forward is either:

  - A user contributes support
  - A customer pays for the support
  - Users describe their use cases, so we as maintainers can better
    assess how useful NFSv4 support would be for barebox as a project

Thanks,
Ahmad


> 
> Thanks,
> Martin
> 


-- 
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-5555 |


From a.fatoum at pengutronix.de  Wed Mar  5 04:51:51 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 5 Mar 2025 13:51:51 +0100
Subject: Mount NFSv4.2 filesystem in barebox?
In-Reply-To: <20250305123032.2b2c7768@erd003.prtnl>
References: <CANH4o6Njc3uHE=NbasRJrRr0W5B89R8MTM_BwGwab7t5fNWuaA@mail.gmail.com>
 <Z6yxUVTp0vGWqs7Q@pengutronix.de>
 <CANH4o6NRK2+ekNe_LrUaoAi8PVbi-MC3hWerv4g6F-WmXmyK5w@mail.gmail.com>
 <Z8GWfv4oIhB7CDSU@pengutronix.de>
 <3ba4d5f3-9679-4a32-a3e7-a8c958107df9@pengutronix.de>
 <CANH4o6PN3tJC+zLt_eLeKzJ6BVFnGo+vYFDF+9Hjp9x6oz626g@mail.gmail.com>
 <20250305123032.2b2c7768@erd003.prtnl>
Message-ID: <7b73bca5-c1a2-4260-9c8a-510887ba4be8@pengutronix.de>

Hi David,

On 05.03.25 12:30, David Jander wrote:
> On Tue, 4 Mar 2025 22:50:00 +0100
> Martin Wege <martin.l.wege at gmail.com> wrote:
>> So yes, you would have customers for NFSv4.1 support in barebox.
> 
> Just wanted to chime in to amplify this a bit, since we are also using NFSv4.2
> netboot (though only TFTP in barebox for now):
> 
> Your arguments are solid, and make a lot of sense. If you are going to replace
> more and more microcontroller based nodes with Linux capable SoCs, because it
> makes a lot of economical sense (hardware costs are very similar nowadays, and
> software development is 10x easier and cheaper on Linux than on a uC), you
> will end up inevitably with a lot of Linux nodes inside of a machine or
> industrial plant, where you previously had uC's. So, do you want to continue
> using 1970's tech (RS485/modbus) or 1980's tech (CAN) to communicate between all
> those nodes, or will you use Linux's native language (TCP/IP) which also
> immediately means another 10x reduction in software development costs of the
> networking part? If you choose the latter, you will also get significant HW
> cost savings basically for free if you also net-boot (via NFS and/or TFTP).
> 
> In other words, why are we not already doing this?
> 
> At least we are. We are starting to use Single Pair Ethernet almost everywhere
> where there were other field-busses involved traditionally. So we noticed that
> we end up with a lot of boards running Linux connected together via anything
> from 10Base-T1L to 1000Base-T1. Replace the eMMC chip on all but one of them
> with a cheap 2MiB SPI-NOR flash to load barebox and netboot from one single
> board running an NFSv4.2 (and TFTP) server serving the kernel and rootfs for
> all the others from a single eMMC, that can be updated with a single RAUC
> bundle guaranteeing consistent software and trivially easy updates on all
> nodes at once. Not to mention the benefit of trivial repairs because all
> boards are basically dumb and don't need to be flashed with software that
> matches the machine they are being replaced in, etc...

Which I think is very cool. :-)

> To be fair though, it isn't strictly needed for barebox to have NFS support
> for our use-case, since it suffices to load the kernel (and possibly an
> initramfs) via TFTP and mount the nfsroot from the kernel, but IMHO it is
> certainly valuable to have basic NFSv4.2 support in barebox. It would
> facilitate the use of just 1 protocol instead of 2.

Ack.

> I also agree that NFSv3
> support in that regard offers little value since you really don't want to base
> everything on this obsolete version with all of its limitations.
> 
> But also a bit of caution to be mindful of: Cybersecurity. Of course barebox
> can be made to only boot signed fit images, but are there other potential
> attack vectors?

We have been fuzzing the security critical boot path and issues were found
and fixed. Our network stack and NFS implementation are not currently part
of that. The documentation now spells that out and explicitly advises
against using any unsigned file system at all (whether networked or not)
to contain a signed FIT image:

https://www.barebox.org/doc/latest/user/security.html#avoiding-use-of-file-systems

As we gain more confidence in the implementation (or rather import mptcp and focus
on fuzzing that), this will change, but as things stand now, it's is not advisable
to do network boot of signed images.

> What if the NFS server needs to be secured with with GSS and
> kerberos? Barebox possibly won't be able to access it unless it also supports
> that.

Yes. I think HTTP(S) support may be a better investment of time, even
if it means having to use two protocols still.

> P.S.: I am currently not subscribed to the barebox mailing list, so I don't
> know if this email will get forwarded by the list server.

The ML accepts mails from non-subscribers. Infradead is currently slow on
delivering mail, though, but I hope it will soon show up on both
lore.barebox.org/barebox and lore.kernel.org/barebox.

Cheers,
Ahmad

> 
> Best regards,
> 


-- 
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-5555 |


From a.fatoum at pengutronix.de  Wed Mar  5 05:11:21 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed,  5 Mar 2025 14:11:21 +0100
Subject: [PATCH master] nfs: rename global.net.nfsport to global.nfs.port
Message-ID: <20250305131121.3985854-1-a.fatoum@pengutronix.de>

There's already precedence in global.tftp.windowsize, so global.nfs.port
is probably a better name than squeezing it into global.net.

This parameter is not yet in any release, so the fallout is fairly
limited.

While at it, mention it in the documentation.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Documentation/user/booting-linux.rst | 15 ++++++++++++---
 Documentation/user/networking.rst    | 23 ++++++++++++++++++++---
 fs/nfs.c                             |  4 ++--
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/Documentation/user/booting-linux.rst b/Documentation/user/booting-linux.rst
index b49b2c93b1f3..6c8d25a96c1e 100644
--- a/Documentation/user/booting-linux.rst
+++ b/Documentation/user/booting-linux.rst
@@ -231,9 +231,18 @@ The entry can be listed with the ``-l`` option:
 When the SD card shows up as ``mmc1`` in barebox, this entry can be booted with
 ``boot mmc1`` or by setting ``global.boot.default`` to ``mmc1``.
 
-A bootloader spec entry can also reside on an NFS server, in which case an
-`RFC 2224 <https://datatracker.ietf.org/doc/html/rfc2224>`__-compatible NFS URI
-must be passed to the boot command:
+A bootloader spec entry can also reside on an NFS server by pointing the boot
+command at the mount point
+(here the default :ref:`automount <network_filesystems_automounts>`):
+
+.. code-block:: sh
+
+  global.user=myself
+  boot /mnt/nfs
+
+Alternatively, the bootloader spec support also understands
+`RFC 2224 <https://datatracker.ietf.org/doc/html/rfc2224>`__-compatible
+NFS URIs, when passed to the :ref:`boot command <command_boot>`:
 
 .. code-block:: sh
 
diff --git a/Documentation/user/networking.rst b/Documentation/user/networking.rst
index 2306cb6a60d1..0adcff6954dc 100644
--- a/Documentation/user/networking.rst
+++ b/Documentation/user/networking.rst
@@ -150,9 +150,26 @@ or
 
   mount -t nfs 192.168.2.1:/export none /mnt
 
-**NOTE:** The execution of the mount command can often be hidden behind the
-:ref:`automount command <command_automount>`, to make mounting transparent to
-the user.
+.. _network_filesystems_automounts:
+
+Automounts
+^^^^^^^^^^
+
+For user convenience, the default ``automount`` init script runs
+the :ref:`automount command <command_automount>` to create automounts for
+both TFTP and NFS. On first access, an Ethernet interface will be brought
+up and file operations will be forwarded to a host specified by global
+variables:
+
+- ``/mnt/tftp``: will use ``$global.net.server`` as TFTP server
+
+- ``/mnt/nfs``: will use ``$global.net.server`` as NFS server
+  and ``/home/${global.user}/nfsroot/${global.hostname}`` as nfsroot.
+  By default, a RPC lookup will be conducted to determine mount and
+  NFS ports, but these can be overridden together using a user-specified
+  by means of ``global.nfs.port``. The latter is equivalent to specifying
+  ``-o port=$global.nfs.port,mountport=$global.nfs.port`` as argument
+  to the :ref:`mount command <command_mount>`.
 
 Network console
 ---------------
diff --git a/fs/nfs.c b/fs/nfs.c
index 530d9c6672d8..bc3ab3aa8e87 100644
--- a/fs/nfs.c
+++ b/fs/nfs.c
@@ -1567,11 +1567,11 @@ static int nfs_init(void)
 	rootnfsopts = xstrdup("v3,tcp");
 
 	globalvar_add_simple_string("linux.rootnfsopts", &rootnfsopts);
-	globalvar_add_simple_int("net.nfsport", &nfsport_default, "%d");
+	globalvar_add_simple_int("nfs.port", &nfsport_default, "%d");
 
 	return register_fs_driver(&nfs_driver);
 }
 coredevice_initcall(nfs_init);
 
-BAREBOX_MAGICVAR(global.net.nfsport,
+BAREBOX_MAGICVAR(global.nfs.port,
 		 "Sets both NFS -o {port.mountport}= to the specified non-zero value");
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar  5 05:12:21 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed,  5 Mar 2025 14:12:21 +0100
Subject: [PATCH] Documentation: user: networking: fix trivial typo
Message-ID: <20250305131221.3986986-1-a.fatoum@pengutronix.de>

s/varariables/variables/

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Documentation/user/networking.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/user/networking.rst b/Documentation/user/networking.rst
index 0adcff6954dc..1be2a15ac5f4 100644
--- a/Documentation/user/networking.rst
+++ b/Documentation/user/networking.rst
@@ -81,7 +81,7 @@ The :ref:`dhcp command <command_dhcp>` will change the settings based on the ans
 from the DHCP server.
 
 To make the network device settings persistent across reboots there is a nonvolatile
-variable (nvvar) for each of the varariables above. The network device specific variables
+variable (nvvar) for each of the variables above. The network device specific variables
 are:
 
 .. code-block:: sh
-- 
2.39.5



From david at protonic.nl  Wed Mar  5 05:55:43 2025
From: david at protonic.nl (David Jander)
Date: Wed, 5 Mar 2025 14:55:43 +0100
Subject: Mount NFSv4.2 filesystem in barebox?
In-Reply-To: <7b73bca5-c1a2-4260-9c8a-510887ba4be8@pengutronix.de>
References: <CANH4o6Njc3uHE=NbasRJrRr0W5B89R8MTM_BwGwab7t5fNWuaA@mail.gmail.com>
	<Z6yxUVTp0vGWqs7Q@pengutronix.de>
	<CANH4o6NRK2+ekNe_LrUaoAi8PVbi-MC3hWerv4g6F-WmXmyK5w@mail.gmail.com>
	<Z8GWfv4oIhB7CDSU@pengutronix.de>
	<3ba4d5f3-9679-4a32-a3e7-a8c958107df9@pengutronix.de>
	<CANH4o6PN3tJC+zLt_eLeKzJ6BVFnGo+vYFDF+9Hjp9x6oz626g@mail.gmail.com>
	<20250305123032.2b2c7768@erd003.prtnl>
	<7b73bca5-c1a2-4260-9c8a-510887ba4be8@pengutronix.de>
Message-ID: <20250305145543.30c3c8fa@erd003.prtnl>


Hi Ahmad,

On Wed, 5 Mar 2025 13:51:51 +0100
Ahmad Fatoum <a.fatoum at pengutronix.de> wrote:

> Hi David,
> 
> On 05.03.25 12:30, David Jander wrote:
> > On Tue, 4 Mar 2025 22:50:00 +0100
> > Martin Wege <martin.l.wege at gmail.com> wrote:  
> >> So yes, you would have customers for NFSv4.1 support in barebox.  
> > 
> > Just wanted to chime in to amplify this a bit, since we are also using NFSv4.2
> > netboot (though only TFTP in barebox for now):
> > 
> > Your arguments are solid, and make a lot of sense. If you are going to replace
> > more and more microcontroller based nodes with Linux capable SoCs, because it
> > makes a lot of economical sense (hardware costs are very similar nowadays, and
> > software development is 10x easier and cheaper on Linux than on a uC), you
> > will end up inevitably with a lot of Linux nodes inside of a machine or
> > industrial plant, where you previously had uC's. So, do you want to continue
> > using 1970's tech (RS485/modbus) or 1980's tech (CAN) to communicate between all
> > those nodes, or will you use Linux's native language (TCP/IP) which also
> > immediately means another 10x reduction in software development costs of the
> > networking part? If you choose the latter, you will also get significant HW
> > cost savings basically for free if you also net-boot (via NFS and/or TFTP).
> > 
> > In other words, why are we not already doing this?
> > 
> > At least we are. We are starting to use Single Pair Ethernet almost everywhere
> > where there were other field-busses involved traditionally. So we noticed that
> > we end up with a lot of boards running Linux connected together via anything
> > from 10Base-T1L to 1000Base-T1. Replace the eMMC chip on all but one of them
> > with a cheap 2MiB SPI-NOR flash to load barebox and netboot from one single
> > board running an NFSv4.2 (and TFTP) server serving the kernel and rootfs for
> > all the others from a single eMMC, that can be updated with a single RAUC
> > bundle guaranteeing consistent software and trivially easy updates on all
> > nodes at once. Not to mention the benefit of trivial repairs because all
> > boards are basically dumb and don't need to be flashed with software that
> > matches the machine they are being replaced in, etc...  
> 
> Which I think is very cool. :-)

Thanks :-)

> > To be fair though, it isn't strictly needed for barebox to have NFS support
> > for our use-case, since it suffices to load the kernel (and possibly an
> > initramfs) via TFTP and mount the nfsroot from the kernel, but IMHO it is
> > certainly valuable to have basic NFSv4.2 support in barebox. It would
> > facilitate the use of just 1 protocol instead of 2.  
> 
> Ack.
> 
> > I also agree that NFSv3
> > support in that regard offers little value since you really don't want to base
> > everything on this obsolete version with all of its limitations.
> > 
> > But also a bit of caution to be mindful of: Cybersecurity. Of course barebox
> > can be made to only boot signed fit images, but are there other potential
> > attack vectors?  
> 
> We have been fuzzing the security critical boot path and issues were found
> and fixed. Our network stack and NFS implementation are not currently part
> of that. The documentation now spells that out and explicitly advises
> against using any unsigned file system at all (whether networked or not)
> to contain a signed FIT image:
> 
> https://www.barebox.org/doc/latest/user/security.html#avoiding-use-of-file-systems
> 
> As we gain more confidence in the implementation (or rather import mptcp and focus
> on fuzzing that), this will change, but as things stand now, it's is not advisable
> to do network boot of signed images.

Aha. Interesting. I suppose you mean network boot of signed images from
something like NFS (a complex filesystem) as opposed to TFTP (which is more
akin to a raw partition in terms of simplicity of the protocol)? Or is TFTP
already outside of the security comfort zone of barebox?

> > What if the NFS server needs to be secured with with GSS and
> > kerberos? Barebox possibly won't be able to access it unless it also supports
> > that.  
> 
> Yes. I think HTTP(S) support may be a better investment of time, even
> if it means having to use two protocols still.

I agree that if secure-boot is involved, the net-boot solution for barebox
should be the most simple protocol possible so that we always have some
transport implementation that can be hardened with the lowest effort, whether
that is TFTP or HTTP(S). It surely won't be NFSv4.2+kerberos or anything like
that. Still, there are likely a lot of cases, where a physical access barrier
is secure enough, and bare NFS can be used, so let's not immediately shoot
down the idea of having an NFSv4 client in barebox ;-)

A basic HTTP get-only client implementation is probably simple enough
without the (S) part if the sole purpose is to download a signed fit image?

Of course, the server part for boot purposes should probably also be a small,
trusted code-base and not something like a full-blown webserver, full of
enormous attack surfaces due to the lack of TLS.

> > P.S.: I am currently not subscribed to the barebox mailing list, so I don't
> > know if this email will get forwarded by the list server.  
> 
> The ML accepts mails from non-subscribers. Infradead is currently slow on
> delivering mail, though, but I hope it will soon show up on both
> lore.barebox.org/barebox and lore.kernel.org/barebox.

It already arrived :-)
Thanks.

Best regards,

-- 
David Jander


From bst at pengutronix.de  Wed Mar  5 06:00:00 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Wed,  5 Mar 2025 15:00:00 +0100
Subject: [PATCH] ARM: i.MX9: tqma93xx: remove mach/imx/romapi.h include
Message-ID: <20250305140000.1539572-1-bst@pengutronix.de>

dd26bc1d5a0 ("ARM: i.MX93: add destination argument to
imx93_romapi_load_image()") added the imx93_romapi_load_image call to
imx93_load_and_start_image_via_tfa and removed the call from
board-specific lowlevel code. So drop the corresponding include as well.

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 arch/arm/boards/tqma93xx/lowlevel.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/arm/boards/tqma93xx/lowlevel.c b/arch/arm/boards/tqma93xx/lowlevel.c
index cc5101a1a3c..fb61ae5c70b 100644
--- a/arch/arm/boards/tqma93xx/lowlevel.c
+++ b/arch/arm/boards/tqma93xx/lowlevel.c
@@ -9,7 +9,6 @@
 #include <soc/imx9/ddr.h>
 #include <mach/imx/atf.h>
 #include <mach/imx/xload.h>
-#include <mach/imx/romapi.h>
 #include <mach/imx/esdctl.h>
 #include <pbl/i2c.h>
 #include <boards/tq/tq_eeprom.h>
-- 
2.39.5



From bst at pengutronix.de  Wed Mar  5 06:02:25 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Wed, 5 Mar 2025 15:02:25 +0100
Subject: [PATCH] ARM: boards: Add support for phyBOARD-Segin i.MX 93
In-Reply-To: <20250304-phyboard-segin-imx93-v1-1-8677740a79de@pengutronix.de>
References: <20250304-phyboard-segin-imx93-v1-1-8677740a79de@pengutronix.de>
Message-ID: <93d21a21-02f8-45c1-91bf-034c4ed08d30@pengutronix.de>

Hi Jonas,

On 3/4/25 5:24 PM, Jonas Rebmann wrote:
> This patch adds support for the phyBOARD-Segin i.MX 93 and the phyCORE
> i.MX 93 SoM it is based upon.
> 
> Note that support is only provided for the standard configuration
> featuring 1GB RAM as testing was only possible on that variant and only
> the single-configuration lpddr4_timing.c as initially committed to
> u-boot in 7c1f8ce3956 worked.
> 
> The 1GB configuration from later revisions results in a freeze during
> dram setup.
> 
> The following functionality has been tested:
>   - barebox starts via imxusbloader, tftp and emmc
>   - both ethertnet interfaces work
>   - barebox_update to emmc
>   - boot kernel via network
>   - USB OTG
>   - USB mass storage on USB Host Port
>   - reset
> 
> Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
> ---
>   arch/arm/boards/Makefile                           |    1 +
>   arch/arm/boards/phytec-phycore-imx93/Makefile      |    2 +
>   arch/arm/boards/phytec-phycore-imx93/board.c       |   56 +
>   arch/arm/boards/phytec-phycore-imx93/lowlevel.c    |   60 +
>   .../boards/phytec-phycore-imx93/lpddr4_timing.c    | 1546 ++++++++++++++++++++
>   arch/arm/configs/imx_v8_defconfig                  |    1 +
>   arch/arm/configs/multi_v8_defconfig                |    1 +
>   arch/arm/dts/Makefile                              |    1 +
>   arch/arm/dts/imx93-phyboard-segin-downstream.dtsi  |  269 ++++
>   arch/arm/dts/imx93-phyboard-segin.dts              |   28 +
>   arch/arm/mach-imx/Kconfig                          |    9 +
>   images/Makefile.imx                                |    4 +
>   12 files changed, 1978 insertions(+)
> 
> diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
> index c6104d04329774655712db5aaf6df671fd74142e..1e67b304f1855df2c32305638c3d9029ed0994c6 100644
> --- a/arch/arm/boards/Makefile
> +++ b/arch/arm/boards/Makefile
> @@ -78,6 +78,7 @@ obj-$(CONFIG_MACH_PCM038)			+= phytec-phycore-imx27/
>   obj-$(CONFIG_MACH_PHYTEC_SOM_AM335X)		+= phytec-som-am335x/
>   obj-$(CONFIG_MACH_PHYTEC_SOM_IMX6)		+= phytec-som-imx6/
>   obj-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX7)		+= phytec-phycore-imx7/
> +obj-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX93)		+= phytec-phycore-imx93/
>   obj-$(CONFIG_MACH_PHYTEC_PHYCORE_STM32MP1)	+= phytec-phycore-stm32mp1/
>   obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MM)		+= phytec-som-imx8mm/
>   obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MQ)		+= phytec-som-imx8mq/
> diff --git a/arch/arm/boards/phytec-phycore-imx93/Makefile b/arch/arm/boards/phytec-phycore-imx93/Makefile
> new file mode 100644
> index 0000000000000000000000000000000000000000..ae29bb9249e62cb649e21e580559383fa9d18386
> --- /dev/null
> +++ b/arch/arm/boards/phytec-phycore-imx93/Makefile
> @@ -0,0 +1,2 @@
> +lwl-y += lowlevel.o lpddr4_timing.o
> +obj-y += board.o
> diff --git a/arch/arm/boards/phytec-phycore-imx93/board.c b/arch/arm/boards/phytec-phycore-imx93/board.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..149248ca654624826d0e8f6fe0f1f42c2747e248
> --- /dev/null
> +++ b/arch/arm/boards/phytec-phycore-imx93/board.c
> @@ -0,0 +1,56 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#define pr_fmt(fmt) "phyCORE imx93: " fmt
> +
> +#include <common.h>
> +#include <init.h>
> +#include <linux/kernel.h>
> +#include <environment.h>
> +#include <mfd/pca9450.h>
> +#include <deep-probe.h>
> +#include <mach/imx/bbu.h>
> +#include <linux/pinctrl/consumer.h>
> +
> +static void phycore_imx93_init_pmic(struct regmap *map)
> +{
> +	/* set WDOG_B_CFG to cold reset */
> +	regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
> +}
> +
> +static int phycore_imx93_probe(struct device *dev)
> +{
> +	struct device_node *np;
> +
> +	pca9450_register_init_callback(phycore_imx93_init_pmic);
> +
> +	/*
> +	 * The phy on the EQOS has its MDIO lines connected to the FEC. The phy
> +	 * registers can only be successfully read when the EQOS pinctrl setup
> +	 * has been done. The phys on the FEC MDIO bus are probed during the
> +	 * FEC driver probe, so do the EQOS pinctrl setup here to make sure it's
> +	 * done before the FEC probes.
> +	 */
> +	np = of_find_compatible_node(dev->of_node, NULL, "nxp,imx93-dwmac-eqos");
> +	BUG_ON(!np);
> +	of_pinctrl_select_state_default(np);
> +
> +	imx9_bbu_internal_mmcboot_register_handler("eMMC", "/dev/mmc0", 0);
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id phycore_imx93_of_match[] = {
> +	{
> +		.compatible = "phytec,imx93-phyboard-segin",
> +	},
> +	{ /* sentinel */ },
> +};
> +
> +static struct driver phycore_imx93_board_driver = {
> +	.name = "board-phycore_imx93",
> +	.probe = phycore_imx93_probe,
> +	.of_compatible = phycore_imx93_of_match,
> +};
> +coredevice_platform_driver(phycore_imx93_board_driver);
> +
> +BAREBOX_DEEP_PROBE_ENABLE(phycore_imx93_of_match);
> diff --git a/arch/arm/boards/phytec-phycore-imx93/lowlevel.c b/arch/arm/boards/phytec-phycore-imx93/lowlevel.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..7678d2f2633ea07e532684f999b62ddecc2b79dc
> --- /dev/null
> +++ b/arch/arm/boards/phytec-phycore-imx93/lowlevel.c
> @@ -0,0 +1,60 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <common.h>
> +#include <debug_ll.h>
> +#include <mach/imx/debug_ll.h>
> +#include <mach/imx/generic.h>
> +#include <mach/imx/xload.h>
> +#include <asm/barebox-arm.h>
> +#include <soc/imx9/ddr.h>
> +#include <mach/imx/atf.h>
> +#include <mach/imx/xload.h>
> +#include <mach/imx/romapi.h>

This shouldn't be needed.

Regards,
Bastian

> +#include <mach/imx/esdctl.h>
> +#include <pbl/i2c.h>
> +
> +extern char __dtb_z_imx93_phyboard_segin_start[];
> +extern struct dram_timing_info dram_timing;
> +
> +static noinline void phycore_imx93_continue(void)
> +{
> +	void *base = IOMEM(MX9_UART1_BASE_ADDR);
> +	void *muxbase = IOMEM(MX9_IOMUXC_BASE_ADDR);
> +	void *fdt;
> +
> +	/* uart iomux-setup */
> +	writel(0x0, muxbase + 0x0184); /* TX */
> +	writel(0x0, muxbase + 0x0180); /* RX */
> +
> +	imx9_uart_setup(IOMEM(base));
> +	pbl_set_putc(lpuart32_putc, base + 0x10);
> +
> +	if (current_el() == 3) {
> +
> +		/*
> +		 * Current u-boot master has two dram variants but neither
> +		 * where found to work here. As a workaround, lpddr4_timing.c
> +		 * is based on the initial single config version
> +		 */
> +
> +		imx93_ddr_init(&dram_timing, DRAM_TYPE_LPDDR4);
> +		imx93_load_and_start_image_via_tfa();
> +	}
> +
> +	fdt = __dtb_z_imx93_phyboard_segin_start;
> +
> +	imx93_barebox_entry(fdt);
> +
> +	__builtin_unreachable();
> +}
> +
> +ENTRY_FUNCTION(start_imx93_phyboard_segin, r0, r1, r2)
> +{
> +	if (current_el() == 3)
> +		imx93_cpu_lowlevel_init();
> +
> +	relocate_to_current_adr();
> +	setup_c();
> +
> +	phycore_imx93_continue();
> +}
> diff --git a/arch/arm/boards/phytec-phycore-imx93/lpddr4_timing.c b/arch/arm/boards/phytec-phycore-imx93/lpddr4_timing.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..6ff5dc158ee1135d8024223f7c672ecde6cfc6c1
> --- /dev/null
> +++ b/arch/arm/boards/phytec-phycore-imx93/lpddr4_timing.c
> @@ -0,0 +1,1546 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright 2023 NXP
> + * Copyright (C) 2023 PHYTEC Messtechnik GmbH
> + * Christoph Stoidner <c.stoidner at phytec.de>
> + *
> + * Code generated with DDR Tool v1.0.0.
> + */
> +
> +#include <linux/kernel.h>
> +#include <soc/imx9/ddr.h>
> +
> +static struct dram_cfg_param ddr_ddrc_cfg[] = {
> +	/** Initialize DDRC registers **/
> +	{0x4e300110, 0x44100001},
> +	{0x4e300000, 0x8000bf},
> +	{0x4e300008, 0x0},
> +	{0x4e300080, 0x80000412},
> +	{0x4e300084, 0x0},
> +	{0x4e300114, 0x1002},
> +	{0x4e300260, 0x4080},
> +	{0x4e300f04, 0x80},
> +	{0x4e300800, 0x43b30002},
> +	{0x4e300804, 0x1f1f1f1f},
> +	{0x4e301000, 0x0},
> +	{0x4e301240, 0x0},
> +	{0x4e301244, 0x0},
> +	{0x4e301248, 0x0},
> +	{0x4e30124c, 0x0},
> +	{0x4e301250, 0x0},
> +	{0x4e301254, 0x0},
> +	{0x4e301258, 0x0},
> +	{0x4e30125c, 0x0},
> +
> +};
> +
> +/* dram fsp cfg */
> +static struct dram_fsp_cfg ddr_dram_fsp_cfg[] = {
> +	{
> +		{
> +			{0x4e300100, 0x24A0421B},
> +			{0x4e300104, 0xF8EE001B},
> +			{0x4e300108, 0x2F263233},
> +			{0x4e30010C, 0x0005E18B},
> +			{0x4e300124, 0x1C770000},
> +			{0x4e300160, 0x00009102},
> +			{0x4e30016C, 0x35F00000},
> +			{0x4e300170, 0x8B0B0608},
> +			{0x4e300250, 0x00000028},
> +			{0x4e300254, 0x00FE00FE},
> +			{0x4e300258, 0x00000008},
> +			{0x4e30025C, 0x00000400},
> +			{0x4e300300, 0x224F2215},
> +			{0x4e300304, 0x00FE2213},
> +			{0x4e300308, 0x0A3C0E3C},
> +		},
> +		{
> +			{0x01, 0xE4},
> +			{0x02, 0x36},
> +			{0x03, 0xF2},
> +			{0x0b, 0x46},
> +			{0x0c, 0x11},
> +			{0x0e, 0x11},
> +			{0x16, 0x04},
> +		},
> +		0,
> +	},
> +
> +};
> +
> +/* PHY Initialize Configuration */
> +static struct dram_cfg_param ddr_ddrphy_cfg[] = {
> +	{0x100a0, 0x0},
> +	{0x100a1, 0x1},
> +	{0x100a2, 0x2},
> +	{0x100a3, 0x3},
> +	{0x100a4, 0x4},
> +	{0x100a5, 0x5},
> +	{0x100a6, 0x6},
> +	{0x100a7, 0x7},
> +	{0x110a0, 0x0},
> +	{0x110a1, 0x1},
> +	{0x110a2, 0x2},
> +	{0x110a3, 0x3},
> +	{0x110a4, 0x4},
> +	{0x110a5, 0x5},
> +	{0x110a6, 0x6},
> +	{0x110a7, 0x7},
> +	{0x1005f, 0x5ff},
> +	{0x1015f, 0x5ff},
> +	{0x1105f, 0x5ff},
> +	{0x1115f, 0x5ff},
> +	{0x55, 0x1ff},
> +	{0x1055, 0x1ff},
> +	{0x2055, 0x1ff},
> +	{0x200c5, 0x19},
> +	{0x2002e, 0x2},
> +	{0x90204, 0x0},
> +	{0x20024, 0x1e3},
> +	{0x2003a, 0x2},
> +	{0x2007d, 0x212},
> +	{0x2007c, 0x61},
> +	{0x20056, 0x3},
> +	{0x1004d, 0x600},
> +	{0x1014d, 0x600},
> +	{0x1104d, 0x600},
> +	{0x1114d, 0x600},
> +	{0x10049, 0xe00},
> +	{0x10149, 0xe00},
> +	{0x11049, 0xe00},
> +	{0x11149, 0xe00},
> +	{0x43, 0x60},
> +	{0x1043, 0x60},
> +	{0x2043, 0x60},
> +	{0x20018, 0x1},
> +	{0x20075, 0x4},
> +	{0x20050, 0x0},
> +	{0x2009b, 0x2},
> +	{0x20008, 0x3a5},
> +	{0x20088, 0x9},
> +	{0x200b2, 0x10c},
> +	{0x10043, 0x5a1},
> +	{0x10143, 0x5a1},
> +	{0x11043, 0x5a1},
> +	{0x11143, 0x5a1},
> +	{0x200fa, 0x2},
> +	{0x20019, 0x1},
> +	{0x200f0, 0x600},
> +	{0x200f1, 0x0},
> +	{0x200f2, 0x4444},
> +	{0x200f3, 0x8888},
> +	{0x200f4, 0x5655},
> +	{0x200f5, 0x0},
> +	{0x200f6, 0x0},
> +	{0x200f7, 0xf000},
> +	{0x20025, 0x0},
> +	{0x2002d, 0x1},
> +	{0x2002c, 0x0},
> +	{0x20021, 0x0},
> +	{0x200c7, 0x21},
> +	{0x1200c7, 0x21},
> +	{0x200ca, 0x24},
> +	{0x1200ca, 0x24},
> +
> +};
> +
> +/* ddr phy trained csr */
> +static struct dram_cfg_param ddr_ddrphy_trained_csr[] = {
> +	{0x1005f, 0x0},
> +	{0x1015f, 0x0},
> +	{0x1105f, 0x0},
> +	{0x1115f, 0x0},
> +	{0x55, 0x0},
> +	{0x1055, 0x0},
> +	{0x2055, 0x0},
> +	{0x200c5, 0x0},
> +	{0x2002e, 0x0},
> +	{0x90204, 0x0},
> +	{0x20024, 0x0},
> +	{0x2003a, 0x0},
> +	{0x2007d, 0x0},
> +	{0x2007c, 0x0},
> +	{0x20056, 0x0},
> +	{0x1004d, 0x0},
> +	{0x1014d, 0x0},
> +	{0x1104d, 0x0},
> +	{0x1114d, 0x0},
> +	{0x10049, 0x0},
> +	{0x10149, 0x0},
> +	{0x11049, 0x0},
> +	{0x11149, 0x0},
> +	{0x43, 0x0},
> +	{0x1043, 0x0},
> +	{0x2043, 0x0},
> +	{0x20018, 0x0},
> +	{0x20075, 0x0},
> +	{0x20050, 0x0},
> +	{0x2009b, 0x0},
> +	{0x20008, 0x0},
> +	{0x20088, 0x0},
> +	{0x200b2, 0x0},
> +	{0x10043, 0x0},
> +	{0x10143, 0x0},
> +	{0x11043, 0x0},
> +	{0x11143, 0x0},
> +	{0x200fa, 0x0},
> +	{0x20019, 0x0},
> +	{0x200f0, 0x0},
> +	{0x200f1, 0x0},
> +	{0x200f2, 0x0},
> +	{0x200f3, 0x0},
> +	{0x200f4, 0x0},
> +	{0x200f5, 0x0},
> +	{0x200f6, 0x0},
> +	{0x200f7, 0x0},
> +	{0x20025, 0x0},
> +	{0x2002d, 0x0},
> +	{0x2002c, 0x0},
> +	{0xd0000, 0x0},
> +	{0x90000, 0x0},
> +	{0x90001, 0x0},
> +	{0x90002, 0x0},
> +	{0x90003, 0x0},
> +	{0x90004, 0x0},
> +	{0x90005, 0x0},
> +	{0x90029, 0x0},
> +	{0x9002a, 0x0},
> +	{0x9002b, 0x0},
> +	{0x9002c, 0x0},
> +	{0x9002d, 0x0},
> +	{0x9002e, 0x0},
> +	{0x9002f, 0x0},
> +	{0x90030, 0x0},
> +	{0x90031, 0x0},
> +	{0x90032, 0x0},
> +	{0x90033, 0x0},
> +	{0x90034, 0x0},
> +	{0x90035, 0x0},
> +	{0x90036, 0x0},
> +	{0x90037, 0x0},
> +	{0x90038, 0x0},
> +	{0x90039, 0x0},
> +	{0x9003a, 0x0},
> +	{0x9003b, 0x0},
> +	{0x9003c, 0x0},
> +	{0x9003d, 0x0},
> +	{0x9003e, 0x0},
> +	{0x9003f, 0x0},
> +	{0x90040, 0x0},
> +	{0x90041, 0x0},
> +	{0x90042, 0x0},
> +	{0x90043, 0x0},
> +	{0x90044, 0x0},
> +	{0x90045, 0x0},
> +	{0x90046, 0x0},
> +	{0x90047, 0x0},
> +	{0x90048, 0x0},
> +	{0x90049, 0x0},
> +	{0x9004a, 0x0},
> +	{0x9004b, 0x0},
> +	{0x9004c, 0x0},
> +	{0x9004d, 0x0},
> +	{0x9004e, 0x0},
> +	{0x9004f, 0x0},
> +	{0x90050, 0x0},
> +	{0x90051, 0x0},
> +	{0x90052, 0x0},
> +	{0x90053, 0x0},
> +	{0x90054, 0x0},
> +	{0x90055, 0x0},
> +	{0x90056, 0x0},
> +	{0x90057, 0x0},
> +	{0x90058, 0x0},
> +	{0x90059, 0x0},
> +	{0x9005a, 0x0},
> +	{0x9005b, 0x0},
> +	{0x9005c, 0x0},
> +	{0x9005d, 0x0},
> +	{0x9005e, 0x0},
> +	{0x9005f, 0x0},
> +	{0x90060, 0x0},
> +	{0x90061, 0x0},
> +	{0x90062, 0x0},
> +	{0x90063, 0x0},
> +	{0x90064, 0x0},
> +	{0x90065, 0x0},
> +	{0x90066, 0x0},
> +	{0x90067, 0x0},
> +	{0x90068, 0x0},
> +	{0x90069, 0x0},
> +	{0x9006a, 0x0},
> +	{0x9006b, 0x0},
> +	{0x9006c, 0x0},
> +	{0x9006d, 0x0},
> +	{0x9006e, 0x0},
> +	{0x9006f, 0x0},
> +	{0x90070, 0x0},
> +	{0x90071, 0x0},
> +	{0x90072, 0x0},
> +	{0x90073, 0x0},
> +	{0x90074, 0x0},
> +	{0x90075, 0x0},
> +	{0x90076, 0x0},
> +	{0x90077, 0x0},
> +	{0x90078, 0x0},
> +	{0x90079, 0x0},
> +	{0x9007a, 0x0},
> +	{0x9007b, 0x0},
> +	{0x9007c, 0x0},
> +	{0x9007d, 0x0},
> +	{0x9007e, 0x0},
> +	{0x9007f, 0x0},
> +	{0x90080, 0x0},
> +	{0x90081, 0x0},
> +	{0x90082, 0x0},
> +	{0x90083, 0x0},
> +	{0x90084, 0x0},
> +	{0x90085, 0x0},
> +	{0x90086, 0x0},
> +	{0x90087, 0x0},
> +	{0x90088, 0x0},
> +	{0x90089, 0x0},
> +	{0x9008a, 0x0},
> +	{0x9008b, 0x0},
> +	{0x9008c, 0x0},
> +	{0x9008d, 0x0},
> +	{0x9008e, 0x0},
> +	{0x9008f, 0x0},
> +	{0x90090, 0x0},
> +	{0x90091, 0x0},
> +	{0x90092, 0x0},
> +	{0x90093, 0x0},
> +	{0x90094, 0x0},
> +	{0x90095, 0x0},
> +	{0x90096, 0x0},
> +	{0x90097, 0x0},
> +	{0x90098, 0x0},
> +	{0x90099, 0x0},
> +	{0x9009a, 0x0},
> +	{0x9009b, 0x0},
> +	{0x9009c, 0x0},
> +	{0x9009d, 0x0},
> +	{0x9009e, 0x0},
> +	{0x9009f, 0x0},
> +	{0x900a0, 0x0},
> +	{0x900a1, 0x0},
> +	{0x900a2, 0x0},
> +	{0x900a3, 0x0},
> +	{0x900a4, 0x0},
> +	{0x900a5, 0x0},
> +	{0x900a6, 0x0},
> +	{0x900a7, 0x0},
> +	{0x900a8, 0x0},
> +	{0x900a9, 0x0},
> +	{0x40000, 0x0},
> +	{0x40020, 0x0},
> +	{0x40040, 0x0},
> +	{0x40060, 0x0},
> +	{0x40001, 0x0},
> +	{0x40021, 0x0},
> +	{0x40041, 0x0},
> +	{0x40061, 0x0},
> +	{0x40002, 0x0},
> +	{0x40022, 0x0},
> +	{0x40042, 0x0},
> +	{0x40062, 0x0},
> +	{0x40003, 0x0},
> +	{0x40023, 0x0},
> +	{0x40043, 0x0},
> +	{0x40063, 0x0},
> +	{0x40004, 0x0},
> +	{0x40024, 0x0},
> +	{0x40044, 0x0},
> +	{0x40064, 0x0},
> +	{0x40005, 0x0},
> +	{0x40025, 0x0},
> +	{0x40045, 0x0},
> +	{0x40065, 0x0},
> +	{0x40006, 0x0},
> +	{0x40026, 0x0},
> +	{0x40046, 0x0},
> +	{0x40066, 0x0},
> +	{0x40007, 0x0},
> +	{0x40027, 0x0},
> +	{0x40047, 0x0},
> +	{0x40067, 0x0},
> +	{0x40008, 0x0},
> +	{0x40028, 0x0},
> +	{0x40048, 0x0},
> +	{0x40068, 0x0},
> +	{0x40009, 0x0},
> +	{0x40029, 0x0},
> +	{0x40049, 0x0},
> +	{0x40069, 0x0},
> +	{0x4000a, 0x0},
> +	{0x4002a, 0x0},
> +	{0x4004a, 0x0},
> +	{0x4006a, 0x0},
> +	{0x4000b, 0x0},
> +	{0x4002b, 0x0},
> +	{0x4004b, 0x0},
> +	{0x4006b, 0x0},
> +	{0x4000c, 0x0},
> +	{0x4002c, 0x0},
> +	{0x4004c, 0x0},
> +	{0x4006c, 0x0},
> +	{0x4000d, 0x0},
> +	{0x4002d, 0x0},
> +	{0x4004d, 0x0},
> +	{0x4006d, 0x0},
> +	{0x4000e, 0x0},
> +	{0x4002e, 0x0},
> +	{0x4004e, 0x0},
> +	{0x4006e, 0x0},
> +	{0x4000f, 0x0},
> +	{0x4002f, 0x0},
> +	{0x4004f, 0x0},
> +	{0x4006f, 0x0},
> +	{0x40010, 0x0},
> +	{0x40030, 0x0},
> +	{0x40050, 0x0},
> +	{0x40070, 0x0},
> +	{0x40011, 0x0},
> +	{0x40031, 0x0},
> +	{0x40051, 0x0},
> +	{0x40071, 0x0},
> +	{0x40012, 0x0},
> +	{0x40032, 0x0},
> +	{0x40052, 0x0},
> +	{0x40072, 0x0},
> +	{0x40013, 0x0},
> +	{0x40033, 0x0},
> +	{0x40053, 0x0},
> +	{0x40073, 0x0},
> +	{0x40014, 0x0},
> +	{0x40034, 0x0},
> +	{0x40054, 0x0},
> +	{0x40074, 0x0},
> +	{0x40015, 0x0},
> +	{0x40035, 0x0},
> +	{0x40055, 0x0},
> +	{0x40075, 0x0},
> +	{0x40016, 0x0},
> +	{0x40036, 0x0},
> +	{0x40056, 0x0},
> +	{0x40076, 0x0},
> +	{0x40017, 0x0},
> +	{0x40037, 0x0},
> +	{0x40057, 0x0},
> +	{0x40077, 0x0},
> +	{0x40018, 0x0},
> +	{0x40038, 0x0},
> +	{0x40058, 0x0},
> +	{0x40078, 0x0},
> +	{0x40019, 0x0},
> +	{0x40039, 0x0},
> +	{0x40059, 0x0},
> +	{0x40079, 0x0},
> +	{0x4001a, 0x0},
> +	{0x4003a, 0x0},
> +	{0x4005a, 0x0},
> +	{0x4007a, 0x0},
> +	{0x900aa, 0x0},
> +	{0x900ab, 0x0},
> +	{0x900ac, 0x0},
> +	{0x900ad, 0x0},
> +	{0x900ae, 0x0},
> +	{0x900af, 0x0},
> +	{0x900b0, 0x0},
> +	{0x900b1, 0x0},
> +	{0x900b2, 0x0},
> +	{0x900b3, 0x0},
> +	{0x900b4, 0x0},
> +	{0x900b5, 0x0},
> +	{0x900b6, 0x0},
> +	{0x900b7, 0x0},
> +	{0x900b8, 0x0},
> +	{0x900b9, 0x0},
> +	{0x900ba, 0x0},
> +	{0x900bb, 0x0},
> +	{0x900bc, 0x0},
> +	{0x900bd, 0x0},
> +	{0x900be, 0x0},
> +	{0x900bf, 0x0},
> +	{0x900c0, 0x0},
> +	{0x900c1, 0x0},
> +	{0x900c2, 0x0},
> +	{0x900c3, 0x0},
> +	{0x900c4, 0x0},
> +	{0x900c5, 0x0},
> +	{0x900c6, 0x0},
> +	{0x900c7, 0x0},
> +	{0x900c8, 0x0},
> +	{0x900c9, 0x0},
> +	{0x900ca, 0x0},
> +	{0x900cb, 0x0},
> +	{0x900cc, 0x0},
> +	{0x900cd, 0x0},
> +	{0x900ce, 0x0},
> +	{0x900cf, 0x0},
> +	{0x900d0, 0x0},
> +	{0x900d1, 0x0},
> +	{0x900d2, 0x0},
> +	{0x900d3, 0x0},
> +	{0x900d4, 0x0},
> +	{0x900d5, 0x0},
> +	{0x900d6, 0x0},
> +	{0x900d7, 0x0},
> +	{0x900d8, 0x0},
> +	{0x900d9, 0x0},
> +	{0x900da, 0x0},
> +	{0x900db, 0x0},
> +	{0x900dc, 0x0},
> +	{0x900dd, 0x0},
> +	{0x900de, 0x0},
> +	{0x900df, 0x0},
> +	{0x900e0, 0x0},
> +	{0x900e1, 0x0},
> +	{0x900e2, 0x0},
> +	{0x900e3, 0x0},
> +	{0x900e4, 0x0},
> +	{0x900e5, 0x0},
> +	{0x900e6, 0x0},
> +	{0x900e7, 0x0},
> +	{0x900e8, 0x0},
> +	{0x900e9, 0x0},
> +	{0x900ea, 0x0},
> +	{0x900eb, 0x0},
> +	{0x900ec, 0x0},
> +	{0x900ed, 0x0},
> +	{0x900ee, 0x0},
> +	{0x900ef, 0x0},
> +	{0x900f0, 0x0},
> +	{0x900f1, 0x0},
> +	{0x900f2, 0x0},
> +	{0x900f3, 0x0},
> +	{0x900f4, 0x0},
> +	{0x900f5, 0x0},
> +	{0x900f6, 0x0},
> +	{0x900f7, 0x0},
> +	{0x900f8, 0x0},
> +	{0x900f9, 0x0},
> +	{0x900fa, 0x0},
> +	{0x900fb, 0x0},
> +	{0x900fc, 0x0},
> +	{0x900fd, 0x0},
> +	{0x900fe, 0x0},
> +	{0x900ff, 0x0},
> +	{0x90100, 0x0},
> +	{0x90101, 0x0},
> +	{0x90102, 0x0},
> +	{0x90103, 0x0},
> +	{0x90104, 0x0},
> +	{0x90105, 0x0},
> +	{0x90106, 0x0},
> +	{0x90107, 0x0},
> +	{0x90108, 0x0},
> +	{0x90109, 0x0},
> +	{0x9010a, 0x0},
> +	{0x9010b, 0x0},
> +	{0x9010c, 0x0},
> +	{0x9010d, 0x0},
> +	{0x9010e, 0x0},
> +	{0x9010f, 0x0},
> +	{0x90110, 0x0},
> +	{0x90111, 0x0},
> +	{0x90112, 0x0},
> +	{0x90113, 0x0},
> +	{0x90114, 0x0},
> +	{0x90115, 0x0},
> +	{0x90116, 0x0},
> +	{0x90117, 0x0},
> +	{0x90118, 0x0},
> +	{0x90119, 0x0},
> +	{0x9011a, 0x0},
> +	{0x9011b, 0x0},
> +	{0x9011c, 0x0},
> +	{0x9011d, 0x0},
> +	{0x9011e, 0x0},
> +	{0x9011f, 0x0},
> +	{0x90120, 0x0},
> +	{0x90121, 0x0},
> +	{0x90122, 0x0},
> +	{0x90123, 0x0},
> +	{0x90124, 0x0},
> +	{0x90125, 0x0},
> +	{0x90126, 0x0},
> +	{0x90127, 0x0},
> +	{0x90128, 0x0},
> +	{0x90129, 0x0},
> +	{0x9012a, 0x0},
> +	{0x9012b, 0x0},
> +	{0x9012c, 0x0},
> +	{0x9012d, 0x0},
> +	{0x9012e, 0x0},
> +	{0x9012f, 0x0},
> +	{0x90130, 0x0},
> +	{0x90131, 0x0},
> +	{0x90132, 0x0},
> +	{0x90133, 0x0},
> +	{0x90134, 0x0},
> +	{0x90135, 0x0},
> +	{0x90136, 0x0},
> +	{0x90137, 0x0},
> +	{0x90138, 0x0},
> +	{0x90139, 0x0},
> +	{0x9013a, 0x0},
> +	{0x9013b, 0x0},
> +	{0x9013c, 0x0},
> +	{0x9013d, 0x0},
> +	{0x9013e, 0x0},
> +	{0x9013f, 0x0},
> +	{0x90140, 0x0},
> +	{0x90141, 0x0},
> +	{0x90142, 0x0},
> +	{0x90143, 0x0},
> +	{0x90144, 0x0},
> +	{0x90145, 0x0},
> +	{0x90146, 0x0},
> +	{0x90147, 0x0},
> +	{0x90148, 0x0},
> +	{0x90149, 0x0},
> +	{0x9014a, 0x0},
> +	{0x9014b, 0x0},
> +	{0x9014c, 0x0},
> +	{0x9014d, 0x0},
> +	{0x9014e, 0x0},
> +	{0x9014f, 0x0},
> +	{0x90150, 0x0},
> +	{0x90151, 0x0},
> +	{0x90152, 0x0},
> +	{0x90153, 0x0},
> +	{0x90154, 0x0},
> +	{0x90155, 0x0},
> +	{0x90156, 0x0},
> +	{0x90157, 0x0},
> +	{0x90158, 0x0},
> +	{0x90159, 0x0},
> +	{0x9015a, 0x0},
> +	{0x9015b, 0x0},
> +	{0x9015c, 0x0},
> +	{0x9015d, 0x0},
> +	{0x9015e, 0x0},
> +	{0x9015f, 0x0},
> +	{0x90160, 0x0},
> +	{0x90161, 0x0},
> +	{0x90162, 0x0},
> +	{0x90163, 0x0},
> +	{0x90164, 0x0},
> +	{0x90165, 0x0},
> +	{0x90166, 0x0},
> +	{0x90167, 0x0},
> +	{0x90168, 0x0},
> +	{0x90169, 0x0},
> +	{0x9016a, 0x0},
> +	{0x9016b, 0x0},
> +	{0x9016c, 0x0},
> +	{0x9016d, 0x0},
> +	{0x9016e, 0x0},
> +	{0x9016f, 0x0},
> +	{0x90170, 0x0},
> +	{0x90171, 0x0},
> +	{0x90172, 0x0},
> +	{0x90173, 0x0},
> +	{0x90174, 0x0},
> +	{0x90175, 0x0},
> +	{0x90176, 0x0},
> +	{0x90177, 0x0},
> +	{0x90178, 0x0},
> +	{0x90179, 0x0},
> +	{0x9017a, 0x0},
> +	{0x9017b, 0x0},
> +	{0x9017c, 0x0},
> +	{0x9017d, 0x0},
> +	{0x9017e, 0x0},
> +	{0x9017f, 0x0},
> +	{0x90180, 0x0},
> +	{0x90181, 0x0},
> +	{0x90182, 0x0},
> +	{0x90183, 0x0},
> +	{0x90184, 0x0},
> +	{0x90006, 0x0},
> +	{0x90007, 0x0},
> +	{0x90008, 0x0},
> +	{0x90009, 0x0},
> +	{0x9000a, 0x0},
> +	{0x9000b, 0x0},
> +	{0xd00e7, 0x0},
> +	{0x90017, 0x0},
> +	{0x9001f, 0x0},
> +	{0x90026, 0x0},
> +	{0x400d0, 0x0},
> +	{0x400d1, 0x0},
> +	{0x400d2, 0x0},
> +	{0x400d3, 0x0},
> +	{0x400d4, 0x0},
> +	{0x400d5, 0x0},
> +	{0x400d6, 0x0},
> +	{0x400d7, 0x0},
> +	{0x200be, 0x0},
> +	{0x2000b, 0x0},
> +	{0x2000c, 0x0},
> +	{0x2000d, 0x0},
> +	{0x2000e, 0x0},
> +	{0x9000c, 0x0},
> +	{0x9000d, 0x0},
> +	{0x9000e, 0x0},
> +	{0x9000f, 0x0},
> +	{0x90010, 0x0},
> +	{0x90011, 0x0},
> +	{0x90012, 0x0},
> +	{0x90013, 0x0},
> +	{0x20010, 0x0},
> +	{0x20011, 0x0},
> +	{0x40080, 0x0},
> +	{0x40081, 0x0},
> +	{0x40082, 0x0},
> +	{0x40083, 0x0},
> +	{0x40084, 0x0},
> +	{0x40085, 0x0},
> +	{0x400fd, 0x0},
> +	{0x400f1, 0x0},
> +	{0x10011, 0x0},
> +	{0x10012, 0x0},
> +	{0x10013, 0x0},
> +	{0x10018, 0x0},
> +	{0x10002, 0x0},
> +	{0x100b2, 0x0},
> +	{0x101b4, 0x0},
> +	{0x102b4, 0x0},
> +	{0x103b4, 0x0},
> +	{0x104b4, 0x0},
> +	{0x105b4, 0x0},
> +	{0x106b4, 0x0},
> +	{0x107b4, 0x0},
> +	{0x108b4, 0x0},
> +	{0x11011, 0x0},
> +	{0x11012, 0x0},
> +	{0x11013, 0x0},
> +	{0x11018, 0x0},
> +	{0x11002, 0x0},
> +	{0x110b2, 0x0},
> +	{0x111b4, 0x0},
> +	{0x112b4, 0x0},
> +	{0x113b4, 0x0},
> +	{0x114b4, 0x0},
> +	{0x115b4, 0x0},
> +	{0x116b4, 0x0},
> +	{0x117b4, 0x0},
> +	{0x118b4, 0x0},
> +	{0x20089, 0x0},
> +	{0xc0080, 0x0},
> +	{0x200cb, 0x0},
> +	{0x10068, 0x0},
> +	{0x10069, 0x0},
> +	{0x10168, 0x0},
> +	{0x10169, 0x0},
> +	{0x10268, 0x0},
> +	{0x10269, 0x0},
> +	{0x10368, 0x0},
> +	{0x10369, 0x0},
> +	{0x10468, 0x0},
> +	{0x10469, 0x0},
> +	{0x10568, 0x0},
> +	{0x10569, 0x0},
> +	{0x10668, 0x0},
> +	{0x10669, 0x0},
> +	{0x10768, 0x0},
> +	{0x10769, 0x0},
> +	{0x10868, 0x0},
> +	{0x10869, 0x0},
> +	{0x100aa, 0x0},
> +	{0x10062, 0x0},
> +	{0x10001, 0x0},
> +	{0x100a0, 0x0},
> +	{0x100a1, 0x0},
> +	{0x100a2, 0x0},
> +	{0x100a3, 0x0},
> +	{0x100a4, 0x0},
> +	{0x100a5, 0x0},
> +	{0x100a6, 0x0},
> +	{0x100a7, 0x0},
> +	{0x11068, 0x0},
> +	{0x11069, 0x0},
> +	{0x11168, 0x0},
> +	{0x11169, 0x0},
> +	{0x11268, 0x0},
> +	{0x11269, 0x0},
> +	{0x11368, 0x0},
> +	{0x11369, 0x0},
> +	{0x11468, 0x0},
> +	{0x11469, 0x0},
> +	{0x11568, 0x0},
> +	{0x11569, 0x0},
> +	{0x11668, 0x0},
> +	{0x11669, 0x0},
> +	{0x11768, 0x0},
> +	{0x11769, 0x0},
> +	{0x11868, 0x0},
> +	{0x11869, 0x0},
> +	{0x110aa, 0x0},
> +	{0x11062, 0x0},
> +	{0x11001, 0x0},
> +	{0x110a0, 0x0},
> +	{0x110a1, 0x0},
> +	{0x110a2, 0x0},
> +	{0x110a3, 0x0},
> +	{0x110a4, 0x0},
> +	{0x110a5, 0x0},
> +	{0x110a6, 0x0},
> +	{0x110a7, 0x0},
> +	{0x80, 0x0},
> +	{0x1080, 0x0},
> +	{0x2080, 0x0},
> +	{0x10020, 0x0},
> +	{0x10080, 0x0},
> +	{0x10081, 0x0},
> +	{0x100d0, 0x0},
> +	{0x100d1, 0x0},
> +	{0x1008c, 0x0},
> +	{0x1008d, 0x0},
> +	{0x10180, 0x0},
> +	{0x10181, 0x0},
> +	{0x101d0, 0x0},
> +	{0x101d1, 0x0},
> +	{0x1018c, 0x0},
> +	{0x1018d, 0x0},
> +	{0x100c0, 0x0},
> +	{0x100c1, 0x0},
> +	{0x101c0, 0x0},
> +	{0x101c1, 0x0},
> +	{0x102c0, 0x0},
> +	{0x102c1, 0x0},
> +	{0x103c0, 0x0},
> +	{0x103c1, 0x0},
> +	{0x104c0, 0x0},
> +	{0x104c1, 0x0},
> +	{0x105c0, 0x0},
> +	{0x105c1, 0x0},
> +	{0x106c0, 0x0},
> +	{0x106c1, 0x0},
> +	{0x107c0, 0x0},
> +	{0x107c1, 0x0},
> +	{0x108c0, 0x0},
> +	{0x108c1, 0x0},
> +	{0x100ae, 0x0},
> +	{0x100af, 0x0},
> +	{0x11020, 0x0},
> +	{0x11080, 0x0},
> +	{0x11081, 0x0},
> +	{0x110d0, 0x0},
> +	{0x110d1, 0x0},
> +	{0x1108c, 0x0},
> +	{0x1108d, 0x0},
> +	{0x11180, 0x0},
> +	{0x11181, 0x0},
> +	{0x111d0, 0x0},
> +	{0x111d1, 0x0},
> +	{0x1118c, 0x0},
> +	{0x1118d, 0x0},
> +	{0x110c0, 0x0},
> +	{0x110c1, 0x0},
> +	{0x111c0, 0x0},
> +	{0x111c1, 0x0},
> +	{0x112c0, 0x0},
> +	{0x112c1, 0x0},
> +	{0x113c0, 0x0},
> +	{0x113c1, 0x0},
> +	{0x114c0, 0x0},
> +	{0x114c1, 0x0},
> +	{0x115c0, 0x0},
> +	{0x115c1, 0x0},
> +	{0x116c0, 0x0},
> +	{0x116c1, 0x0},
> +	{0x117c0, 0x0},
> +	{0x117c1, 0x0},
> +	{0x118c0, 0x0},
> +	{0x118c1, 0x0},
> +	{0x110ae, 0x0},
> +	{0x110af, 0x0},
> +	{0x90201, 0x0},
> +	{0x90202, 0x0},
> +	{0x90203, 0x0},
> +	{0x90205, 0x0},
> +	{0x90206, 0x0},
> +	{0x90207, 0x0},
> +	{0x90208, 0x0},
> +	{0x20020, 0x0},
> +	{0x20077, 0x0},
> +	{0x20072, 0x0},
> +	{0x20073, 0x0},
> +	{0x400c0, 0x0},
> +	{0x10040, 0x0},
> +	{0x10140, 0x0},
> +	{0x10240, 0x0},
> +	{0x10340, 0x0},
> +	{0x10440, 0x0},
> +	{0x10540, 0x0},
> +	{0x10640, 0x0},
> +	{0x10740, 0x0},
> +	{0x10840, 0x0},
> +	{0x11040, 0x0},
> +	{0x11140, 0x0},
> +	{0x11240, 0x0},
> +	{0x11340, 0x0},
> +	{0x11440, 0x0},
> +	{0x11540, 0x0},
> +	{0x11640, 0x0},
> +	{0x11740, 0x0},
> +	{0x11840, 0x0},
> +
> +};
> +
> +/* P0 message block parameter for training firmware */
> +static struct dram_cfg_param ddr_fsp0_cfg[] = {
> +	{0xd0000, 0x0},
> +	{0x54003, 0xe94},
> +	{0x54004, 0x4},
> +	{0x54006, 0x15},
> +	{0x54008, 0x131f},
> +	{0x54009, 0xc8},
> +	{0x5400b, 0x4},
> +	{0x5400d, 0x100},
> +	{0x5400f, 0x100},
> +	{0x54012, 0x110},
> +	{0x54019, 0x36e4},
> +	{0x5401a, 0xf2},
> +	{0x5401b, 0x1146},
> +	{0x5401c, 0x1108},
> +	{0x5401e, 0x4},
> +	{0x5401f, 0x36e4},
> +	{0x54020, 0xf2},
> +	{0x54021, 0x1146},
> +	{0x54022, 0x1108},
> +	{0x54024, 0x4},
> +	{0x54032, 0xe400},
> +	{0x54033, 0xf236},
> +	{0x54034, 0x4600},
> +	{0x54035, 0x811},
> +	{0x54036, 0x11},
> +	{0x54037, 0x400},
> +	{0x54038, 0xe400},
> +	{0x54039, 0xf236},
> +	{0x5403a, 0x4600},
> +	{0x5403b, 0x811},
> +	{0x5403c, 0x11},
> +	{0x5403d, 0x400},
> +	{0xd0000, 0x1}
> +};
> +
> +/* P0 2D message block parameter for training firmware */
> +static struct dram_cfg_param ddr_fsp0_2d_cfg[] = {
> +	{0xd0000, 0x0},
> +	{0x54003, 0xe94},
> +	{0x54004, 0x4},
> +	{0x54006, 0x15},
> +	{0x54008, 0x61},
> +	{0x54009, 0xc8},
> +	{0x5400b, 0x4},
> +	{0x5400d, 0x100},
> +	{0x5400f, 0x100},
> +	{0x54010, 0x2080},
> +	{0x54012, 0x110},
> +	{0x54019, 0x36e4},
> +	{0x5401a, 0xf2},
> +	{0x5401b, 0x1146},
> +	{0x5401c, 0x1108},
> +	{0x5401e, 0x4},
> +	{0x5401f, 0x36e4},
> +	{0x54020, 0xf2},
> +	{0x54021, 0x1146},
> +	{0x54022, 0x1108},
> +	{0x54024, 0x4},
> +	{0x54032, 0xe400},
> +	{0x54033, 0xf236},
> +	{0x54034, 0x4600},
> +	{0x54035, 0x811},
> +	{0x54036, 0x11},
> +	{0x54037, 0x400},
> +	{0x54038, 0xe400},
> +	{0x54039, 0xf236},
> +	{0x5403a, 0x4600},
> +	{0x5403b, 0x811},
> +	{0x5403c, 0x11},
> +	{0x5403d, 0x400},
> +	{0xd0000, 0x1}
> +};
> +
> +/* DRAM PHY init engine image */
> +static struct dram_cfg_param ddr_phy_pie[] = {
> +	{0xd0000, 0x0},
> +	{0x90000, 0x10},
> +	{0x90001, 0x400},
> +	{0x90002, 0x10e},
> +	{0x90003, 0x0},
> +	{0x90004, 0x0},
> +	{0x90005, 0x8},
> +	{0x90029, 0xb},
> +	{0x9002a, 0x480},
> +	{0x9002b, 0x109},
> +	{0x9002c, 0x8},
> +	{0x9002d, 0x448},
> +	{0x9002e, 0x139},
> +	{0x9002f, 0x8},
> +	{0x90030, 0x478},
> +	{0x90031, 0x109},
> +	{0x90032, 0x0},
> +	{0x90033, 0xe8},
> +	{0x90034, 0x109},
> +	{0x90035, 0x2},
> +	{0x90036, 0x10},
> +	{0x90037, 0x139},
> +	{0x90038, 0xb},
> +	{0x90039, 0x7c0},
> +	{0x9003a, 0x139},
> +	{0x9003b, 0x44},
> +	{0x9003c, 0x633},
> +	{0x9003d, 0x159},
> +	{0x9003e, 0x14f},
> +	{0x9003f, 0x630},
> +	{0x90040, 0x159},
> +	{0x90041, 0x47},
> +	{0x90042, 0x633},
> +	{0x90043, 0x149},
> +	{0x90044, 0x4f},
> +	{0x90045, 0x633},
> +	{0x90046, 0x179},
> +	{0x90047, 0x8},
> +	{0x90048, 0xe0},
> +	{0x90049, 0x109},
> +	{0x9004a, 0x0},
> +	{0x9004b, 0x7c8},
> +	{0x9004c, 0x109},
> +	{0x9004d, 0x0},
> +	{0x9004e, 0x1},
> +	{0x9004f, 0x8},
> +	{0x90050, 0x30},
> +	{0x90051, 0x65a},
> +	{0x90052, 0x9},
> +	{0x90053, 0x0},
> +	{0x90054, 0x45a},
> +	{0x90055, 0x9},
> +	{0x90056, 0x0},
> +	{0x90057, 0x448},
> +	{0x90058, 0x109},
> +	{0x90059, 0x40},
> +	{0x9005a, 0x633},
> +	{0x9005b, 0x179},
> +	{0x9005c, 0x1},
> +	{0x9005d, 0x618},
> +	{0x9005e, 0x109},
> +	{0x9005f, 0x40c0},
> +	{0x90060, 0x633},
> +	{0x90061, 0x149},
> +	{0x90062, 0x8},
> +	{0x90063, 0x4},
> +	{0x90064, 0x48},
> +	{0x90065, 0x4040},
> +	{0x90066, 0x633},
> +	{0x90067, 0x149},
> +	{0x90068, 0x0},
> +	{0x90069, 0x4},
> +	{0x9006a, 0x48},
> +	{0x9006b, 0x40},
> +	{0x9006c, 0x633},
> +	{0x9006d, 0x149},
> +	{0x9006e, 0x0},
> +	{0x9006f, 0x658},
> +	{0x90070, 0x109},
> +	{0x90071, 0x10},
> +	{0x90072, 0x4},
> +	{0x90073, 0x18},
> +	{0x90074, 0x0},
> +	{0x90075, 0x4},
> +	{0x90076, 0x78},
> +	{0x90077, 0x549},
> +	{0x90078, 0x633},
> +	{0x90079, 0x159},
> +	{0x9007a, 0xd49},
> +	{0x9007b, 0x633},
> +	{0x9007c, 0x159},
> +	{0x9007d, 0x94a},
> +	{0x9007e, 0x633},
> +	{0x9007f, 0x159},
> +	{0x90080, 0x441},
> +	{0x90081, 0x633},
> +	{0x90082, 0x149},
> +	{0x90083, 0x42},
> +	{0x90084, 0x633},
> +	{0x90085, 0x149},
> +	{0x90086, 0x1},
> +	{0x90087, 0x633},
> +	{0x90088, 0x149},
> +	{0x90089, 0x0},
> +	{0x9008a, 0xe0},
> +	{0x9008b, 0x109},
> +	{0x9008c, 0xa},
> +	{0x9008d, 0x10},
> +	{0x9008e, 0x109},
> +	{0x9008f, 0x9},
> +	{0x90090, 0x3c0},
> +	{0x90091, 0x149},
> +	{0x90092, 0x9},
> +	{0x90093, 0x3c0},
> +	{0x90094, 0x159},
> +	{0x90095, 0x18},
> +	{0x90096, 0x10},
> +	{0x90097, 0x109},
> +	{0x90098, 0x0},
> +	{0x90099, 0x3c0},
> +	{0x9009a, 0x109},
> +	{0x9009b, 0x18},
> +	{0x9009c, 0x4},
> +	{0x9009d, 0x48},
> +	{0x9009e, 0x18},
> +	{0x9009f, 0x4},
> +	{0x900a0, 0x58},
> +	{0x900a1, 0xb},
> +	{0x900a2, 0x10},
> +	{0x900a3, 0x109},
> +	{0x900a4, 0x1},
> +	{0x900a5, 0x10},
> +	{0x900a6, 0x109},
> +	{0x900a7, 0x5},
> +	{0x900a8, 0x7c0},
> +	{0x900a9, 0x109},
> +	{0x40000, 0x811},
> +	{0x40020, 0x880},
> +	{0x40040, 0x0},
> +	{0x40060, 0x0},
> +	{0x40001, 0x4008},
> +	{0x40021, 0x83},
> +	{0x40041, 0x4f},
> +	{0x40061, 0x0},
> +	{0x40002, 0x4040},
> +	{0x40022, 0x83},
> +	{0x40042, 0x51},
> +	{0x40062, 0x0},
> +	{0x40003, 0x811},
> +	{0x40023, 0x880},
> +	{0x40043, 0x0},
> +	{0x40063, 0x0},
> +	{0x40004, 0x720},
> +	{0x40024, 0xf},
> +	{0x40044, 0x1740},
> +	{0x40064, 0x0},
> +	{0x40005, 0x16},
> +	{0x40025, 0x83},
> +	{0x40045, 0x4b},
> +	{0x40065, 0x0},
> +	{0x40006, 0x716},
> +	{0x40026, 0xf},
> +	{0x40046, 0x2001},
> +	{0x40066, 0x0},
> +	{0x40007, 0x716},
> +	{0x40027, 0xf},
> +	{0x40047, 0x2800},
> +	{0x40067, 0x0},
> +	{0x40008, 0x716},
> +	{0x40028, 0xf},
> +	{0x40048, 0xf00},
> +	{0x40068, 0x0},
> +	{0x40009, 0x720},
> +	{0x40029, 0xf},
> +	{0x40049, 0x1400},
> +	{0x40069, 0x0},
> +	{0x4000a, 0xe08},
> +	{0x4002a, 0xc15},
> +	{0x4004a, 0x0},
> +	{0x4006a, 0x0},
> +	{0x4000b, 0x625},
> +	{0x4002b, 0x15},
> +	{0x4004b, 0x0},
> +	{0x4006b, 0x0},
> +	{0x4000c, 0x4028},
> +	{0x4002c, 0x80},
> +	{0x4004c, 0x0},
> +	{0x4006c, 0x0},
> +	{0x4000d, 0xe08},
> +	{0x4002d, 0xc1a},
> +	{0x4004d, 0x0},
> +	{0x4006d, 0x0},
> +	{0x4000e, 0x625},
> +	{0x4002e, 0x1a},
> +	{0x4004e, 0x0},
> +	{0x4006e, 0x0},
> +	{0x4000f, 0x4040},
> +	{0x4002f, 0x80},
> +	{0x4004f, 0x0},
> +	{0x4006f, 0x0},
> +	{0x40010, 0x2604},
> +	{0x40030, 0x15},
> +	{0x40050, 0x0},
> +	{0x40070, 0x0},
> +	{0x40011, 0x708},
> +	{0x40031, 0x5},
> +	{0x40051, 0x0},
> +	{0x40071, 0x2002},
> +	{0x40012, 0x8},
> +	{0x40032, 0x80},
> +	{0x40052, 0x0},
> +	{0x40072, 0x0},
> +	{0x40013, 0x2604},
> +	{0x40033, 0x1a},
> +	{0x40053, 0x0},
> +	{0x40073, 0x0},
> +	{0x40014, 0x708},
> +	{0x40034, 0xa},
> +	{0x40054, 0x0},
> +	{0x40074, 0x2002},
> +	{0x40015, 0x4040},
> +	{0x40035, 0x80},
> +	{0x40055, 0x0},
> +	{0x40075, 0x0},
> +	{0x40016, 0x60a},
> +	{0x40036, 0x15},
> +	{0x40056, 0x1200},
> +	{0x40076, 0x0},
> +	{0x40017, 0x61a},
> +	{0x40037, 0x15},
> +	{0x40057, 0x1300},
> +	{0x40077, 0x0},
> +	{0x40018, 0x60a},
> +	{0x40038, 0x1a},
> +	{0x40058, 0x1200},
> +	{0x40078, 0x0},
> +	{0x40019, 0x642},
> +	{0x40039, 0x1a},
> +	{0x40059, 0x1300},
> +	{0x40079, 0x0},
> +	{0x4001a, 0x4808},
> +	{0x4003a, 0x880},
> +	{0x4005a, 0x0},
> +	{0x4007a, 0x0},
> +	{0x900aa, 0x0},
> +	{0x900ab, 0x790},
> +	{0x900ac, 0x11a},
> +	{0x900ad, 0x8},
> +	{0x900ae, 0x7aa},
> +	{0x900af, 0x2a},
> +	{0x900b0, 0x10},
> +	{0x900b1, 0x7b2},
> +	{0x900b2, 0x2a},
> +	{0x900b3, 0x0},
> +	{0x900b4, 0x7c8},
> +	{0x900b5, 0x109},
> +	{0x900b6, 0x10},
> +	{0x900b7, 0x10},
> +	{0x900b8, 0x109},
> +	{0x900b9, 0x10},
> +	{0x900ba, 0x2a8},
> +	{0x900bb, 0x129},
> +	{0x900bc, 0x8},
> +	{0x900bd, 0x370},
> +	{0x900be, 0x129},
> +	{0x900bf, 0xa},
> +	{0x900c0, 0x3c8},
> +	{0x900c1, 0x1a9},
> +	{0x900c2, 0xc},
> +	{0x900c3, 0x408},
> +	{0x900c4, 0x199},
> +	{0x900c5, 0x14},
> +	{0x900c6, 0x790},
> +	{0x900c7, 0x11a},
> +	{0x900c8, 0x8},
> +	{0x900c9, 0x4},
> +	{0x900ca, 0x18},
> +	{0x900cb, 0xe},
> +	{0x900cc, 0x408},
> +	{0x900cd, 0x199},
> +	{0x900ce, 0x8},
> +	{0x900cf, 0x8568},
> +	{0x900d0, 0x108},
> +	{0x900d1, 0x18},
> +	{0x900d2, 0x790},
> +	{0x900d3, 0x16a},
> +	{0x900d4, 0x8},
> +	{0x900d5, 0x1d8},
> +	{0x900d6, 0x169},
> +	{0x900d7, 0x10},
> +	{0x900d8, 0x8558},
> +	{0x900d9, 0x168},
> +	{0x900da, 0x1ff8},
> +	{0x900db, 0x85a8},
> +	{0x900dc, 0x1e8},
> +	{0x900dd, 0x50},
> +	{0x900de, 0x798},
> +	{0x900df, 0x16a},
> +	{0x900e0, 0x60},
> +	{0x900e1, 0x7a0},
> +	{0x900e2, 0x16a},
> +	{0x900e3, 0x8},
> +	{0x900e4, 0x8310},
> +	{0x900e5, 0x168},
> +	{0x900e6, 0x8},
> +	{0x900e7, 0xa310},
> +	{0x900e8, 0x168},
> +	{0x900e9, 0xa},
> +	{0x900ea, 0x408},
> +	{0x900eb, 0x169},
> +	{0x900ec, 0x6e},
> +	{0x900ed, 0x0},
> +	{0x900ee, 0x68},
> +	{0x900ef, 0x0},
> +	{0x900f0, 0x408},
> +	{0x900f1, 0x169},
> +	{0x900f2, 0x0},
> +	{0x900f3, 0x8310},
> +	{0x900f4, 0x168},
> +	{0x900f5, 0x0},
> +	{0x900f6, 0xa310},
> +	{0x900f7, 0x168},
> +	{0x900f8, 0x1ff8},
> +	{0x900f9, 0x85a8},
> +	{0x900fa, 0x1e8},
> +	{0x900fb, 0x68},
> +	{0x900fc, 0x798},
> +	{0x900fd, 0x16a},
> +	{0x900fe, 0x78},
> +	{0x900ff, 0x7a0},
> +	{0x90100, 0x16a},
> +	{0x90101, 0x68},
> +	{0x90102, 0x790},
> +	{0x90103, 0x16a},
> +	{0x90104, 0x8},
> +	{0x90105, 0x8b10},
> +	{0x90106, 0x168},
> +	{0x90107, 0x8},
> +	{0x90108, 0xab10},
> +	{0x90109, 0x168},
> +	{0x9010a, 0xa},
> +	{0x9010b, 0x408},
> +	{0x9010c, 0x169},
> +	{0x9010d, 0x58},
> +	{0x9010e, 0x0},
> +	{0x9010f, 0x68},
> +	{0x90110, 0x0},
> +	{0x90111, 0x408},
> +	{0x90112, 0x169},
> +	{0x90113, 0x0},
> +	{0x90114, 0x8b10},
> +	{0x90115, 0x168},
> +	{0x90116, 0x1},
> +	{0x90117, 0xab10},
> +	{0x90118, 0x168},
> +	{0x90119, 0x0},
> +	{0x9011a, 0x1d8},
> +	{0x9011b, 0x169},
> +	{0x9011c, 0x80},
> +	{0x9011d, 0x790},
> +	{0x9011e, 0x16a},
> +	{0x9011f, 0x18},
> +	{0x90120, 0x7aa},
> +	{0x90121, 0x6a},
> +	{0x90122, 0xa},
> +	{0x90123, 0x0},
> +	{0x90124, 0x1e9},
> +	{0x90125, 0x8},
> +	{0x90126, 0x8080},
> +	{0x90127, 0x108},
> +	{0x90128, 0xf},
> +	{0x90129, 0x408},
> +	{0x9012a, 0x169},
> +	{0x9012b, 0xc},
> +	{0x9012c, 0x0},
> +	{0x9012d, 0x68},
> +	{0x9012e, 0x9},
> +	{0x9012f, 0x0},
> +	{0x90130, 0x1a9},
> +	{0x90131, 0x0},
> +	{0x90132, 0x408},
> +	{0x90133, 0x169},
> +	{0x90134, 0x0},
> +	{0x90135, 0x8080},
> +	{0x90136, 0x108},
> +	{0x90137, 0x8},
> +	{0x90138, 0x7aa},
> +	{0x90139, 0x6a},
> +	{0x9013a, 0x0},
> +	{0x9013b, 0x8568},
> +	{0x9013c, 0x108},
> +	{0x9013d, 0xb7},
> +	{0x9013e, 0x790},
> +	{0x9013f, 0x16a},
> +	{0x90140, 0x1f},
> +	{0x90141, 0x0},
> +	{0x90142, 0x68},
> +	{0x90143, 0x8},
> +	{0x90144, 0x8558},
> +	{0x90145, 0x168},
> +	{0x90146, 0xf},
> +	{0x90147, 0x408},
> +	{0x90148, 0x169},
> +	{0x90149, 0xd},
> +	{0x9014a, 0x0},
> +	{0x9014b, 0x68},
> +	{0x9014c, 0x0},
> +	{0x9014d, 0x408},
> +	{0x9014e, 0x169},
> +	{0x9014f, 0x0},
> +	{0x90150, 0x8558},
> +	{0x90151, 0x168},
> +	{0x90152, 0x8},
> +	{0x90153, 0x3c8},
> +	{0x90154, 0x1a9},
> +	{0x90155, 0x3},
> +	{0x90156, 0x370},
> +	{0x90157, 0x129},
> +	{0x90158, 0x20},
> +	{0x90159, 0x2aa},
> +	{0x9015a, 0x9},
> +	{0x9015b, 0x8},
> +	{0x9015c, 0xe8},
> +	{0x9015d, 0x109},
> +	{0x9015e, 0x0},
> +	{0x9015f, 0x8140},
> +	{0x90160, 0x10c},
> +	{0x90161, 0x10},
> +	{0x90162, 0x8138},
> +	{0x90163, 0x104},
> +	{0x90164, 0x8},
> +	{0x90165, 0x448},
> +	{0x90166, 0x109},
> +	{0x90167, 0xf},
> +	{0x90168, 0x7c0},
> +	{0x90169, 0x109},
> +	{0x9016a, 0x0},
> +	{0x9016b, 0xe8},
> +	{0x9016c, 0x109},
> +	{0x9016d, 0x47},
> +	{0x9016e, 0x630},
> +	{0x9016f, 0x109},
> +	{0x90170, 0x8},
> +	{0x90171, 0x618},
> +	{0x90172, 0x109},
> +	{0x90173, 0x8},
> +	{0x90174, 0xe0},
> +	{0x90175, 0x109},
> +	{0x90176, 0x0},
> +	{0x90177, 0x7c8},
> +	{0x90178, 0x109},
> +	{0x90179, 0x8},
> +	{0x9017a, 0x8140},
> +	{0x9017b, 0x10c},
> +	{0x9017c, 0x0},
> +	{0x9017d, 0x478},
> +	{0x9017e, 0x109},
> +	{0x9017f, 0x0},
> +	{0x90180, 0x1},
> +	{0x90181, 0x8},
> +	{0x90182, 0x8},
> +	{0x90183, 0x4},
> +	{0x90184, 0x0},
> +	{0x90006, 0x8},
> +	{0x90007, 0x7c8},
> +	{0x90008, 0x109},
> +	{0x90009, 0x0},
> +	{0x9000a, 0x400},
> +	{0x9000b, 0x106},
> +	{0xd00e7, 0x400},
> +	{0x90017, 0x0},
> +	{0x9001f, 0x2b},
> +	{0x90026, 0x69},
> +	{0x400d0, 0x0},
> +	{0x400d1, 0x101},
> +	{0x400d2, 0x105},
> +	{0x400d3, 0x107},
> +	{0x400d4, 0x10f},
> +	{0x400d5, 0x202},
> +	{0x400d6, 0x20a},
> +	{0x400d7, 0x20b},
> +	{0x2003a, 0x2},
> +	{0x200be, 0x3},
> +	{0x2000b, 0x75},
> +	{0x2000c, 0xe9},
> +	{0x2000d, 0x91c},
> +	{0x2000e, 0x2c},
> +	{0x9000c, 0x0},
> +	{0x9000d, 0x173},
> +	{0x9000e, 0x60},
> +	{0x9000f, 0x6110},
> +	{0x90010, 0x2152},
> +	{0x90011, 0xdfbd},
> +	{0x90012, 0x2060},
> +	{0x90013, 0x6152},
> +	{0x20010, 0x5a},
> +	{0x20011, 0x3},
> +	{0x40080, 0xe0},
> +	{0x40081, 0x12},
> +	{0x40082, 0xe0},
> +	{0x40083, 0x12},
> +	{0x40084, 0xe0},
> +	{0x40085, 0x12},
> +	{0x400fd, 0xf},
> +	{0x400f1, 0xe},
> +	{0x10011, 0x1},
> +	{0x10012, 0x1},
> +	{0x10013, 0x180},
> +	{0x10018, 0x1},
> +	{0x10002, 0x6209},
> +	{0x100b2, 0x1},
> +	{0x101b4, 0x1},
> +	{0x102b4, 0x1},
> +	{0x103b4, 0x1},
> +	{0x104b4, 0x1},
> +	{0x105b4, 0x1},
> +	{0x106b4, 0x1},
> +	{0x107b4, 0x1},
> +	{0x108b4, 0x1},
> +	{0x11011, 0x1},
> +	{0x11012, 0x1},
> +	{0x11013, 0x180},
> +	{0x11018, 0x1},
> +	{0x11002, 0x6209},
> +	{0x110b2, 0x1},
> +	{0x111b4, 0x1},
> +	{0x112b4, 0x1},
> +	{0x113b4, 0x1},
> +	{0x114b4, 0x1},
> +	{0x115b4, 0x1},
> +	{0x116b4, 0x1},
> +	{0x117b4, 0x1},
> +	{0x118b4, 0x1},
> +	{0x20089, 0x1},
> +	{0x20088, 0x19},
> +	{0xc0080, 0x0},
> +	{0xd0000, 0x1},
> +
> +};
> +
> +static struct dram_fsp_msg ddr_dram_fsp_msg[] = {
> +	{
> +		/* P0 3733mts 1D */
> +		.drate = 3733,
> +		.fw_type = FW_1D_IMAGE,
> +		.fsp_cfg = ddr_fsp0_cfg,
> +		.fsp_cfg_num = ARRAY_SIZE(ddr_fsp0_cfg),
> +
> +	},
> +
> +	{
> +		/* P0 3733mts 2D */
> +		.drate = 3733,
> +		.fw_type = FW_2D_IMAGE,
> +		.fsp_cfg = ddr_fsp0_2d_cfg,
> +		.fsp_cfg_num = ARRAY_SIZE(ddr_fsp0_2d_cfg),
> +	},
> +
> +};
> +
> +/* ddr timing config params */
> +struct dram_timing_info dram_timing = {
> +	.ddrc_cfg = ddr_ddrc_cfg,
> +	.ddrc_cfg_num = ARRAY_SIZE(ddr_ddrc_cfg),
> +	.ddrphy_cfg = ddr_ddrphy_cfg,
> +	.ddrphy_cfg_num = ARRAY_SIZE(ddr_ddrphy_cfg),
> +	.fsp_msg = ddr_dram_fsp_msg,
> +	.fsp_msg_num = ARRAY_SIZE(ddr_dram_fsp_msg),
> +	.ddrphy_trained_csr = ddr_ddrphy_trained_csr,
> +	.ddrphy_trained_csr_num = ARRAY_SIZE(ddr_ddrphy_trained_csr),
> +	.ddrphy_pie = ddr_phy_pie,
> +	.ddrphy_pie_num = ARRAY_SIZE(ddr_phy_pie),
> +	.fsp_table = { 3733, },
> +	.fsp_cfg = ddr_dram_fsp_cfg,
> +	.fsp_cfg_num = ARRAY_SIZE(ddr_dram_fsp_cfg),
> +};
> diff --git a/arch/arm/configs/imx_v8_defconfig b/arch/arm/configs/imx_v8_defconfig
> index e58a2ca13d7a7f4767b680cceefed27fb6950f9b..445f20a303cc7f31f574125d38b34b9bdffd74da 100644
> --- a/arch/arm/configs/imx_v8_defconfig
> +++ b/arch/arm/configs/imx_v8_defconfig
> @@ -16,6 +16,7 @@ CONFIG_MACH_VARISCITE_DT8MCUSTOMBOARD_IMX8MP=y
>   CONFIG_MACH_ZII_IMX8MQ_DEV=y
>   CONFIG_64BIT=y
>   CONFIG_MACH_TQMA93XX=y
> +CONFIG_MACH_PHYTEC_PHYCORE_IMX93=y
>   CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
>   CONFIG_MMU=y
>   CONFIG_MALLOC_SIZE=0x0
> diff --git a/arch/arm/configs/multi_v8_defconfig b/arch/arm/configs/multi_v8_defconfig
> index b1e66e85f4607752efd79bdda6648b750bf872a1..c66b8a0be803a1f3c243e7ec3da5169e3d5451a1 100644
> --- a/arch/arm/configs/multi_v8_defconfig
> +++ b/arch/arm/configs/multi_v8_defconfig
> @@ -22,6 +22,7 @@ CONFIG_MACH_TQ_MBA8MPXL=y
>   CONFIG_MACH_VARISCITE_DT8MCUSTOMBOARD_IMX8MP=y
>   CONFIG_MACH_ZII_IMX8MQ_DEV=y
>   CONFIG_MACH_TQMA93XX=y
> +CONFIG_MACH_PHYTEC_PHYCORE_IMX93=y
>   CONFIG_IMX_IIM=y
>   CONFIG_ARCH_LAYERSCAPE_PPA=y
>   CONFIG_MACH_LS1028ARDB=y
> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> index d3462858523067d68cd41112daaa81d72a072957..3423115b4b447a14d9755ecd63c05a36328c158a 100644
> --- a/arch/arm/dts/Makefile
> +++ b/arch/arm/dts/Makefile
> @@ -81,6 +81,7 @@ lwl-$(CONFIG_MACH_PHYTEC_SOM_IMX6) += imx6q-phytec-phycard.dtb.o \
>   				imx6ull-phytec-phycore-som-nand.dtb.o \
>   				imx6ull-phytec-phycore-som-emmc.dtb.o
>   lwl-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX7) += imx7d-phyboard-zeta.dtb.o
> +lwl-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX93) += imx93-phyboard-segin.dtb.o
>   lwl-$(CONFIG_MACH_PHYTEC_PHYCORE_STM32MP1) += stm32mp157c-phycore-stm32mp1-3.dtb.o
>   lwl-$(CONFIG_MACH_PHYTEC_SOM_IMX8MM) += imx8mm-phyboard-polis-rdk.dtb.o
>   lwl-$(CONFIG_MACH_PHYTEC_SOM_IMX8MQ) += imx8mq-phytec-phycore-som.dtb.o
> diff --git a/arch/arm/dts/imx93-phyboard-segin-downstream.dtsi b/arch/arm/dts/imx93-phyboard-segin-downstream.dtsi
> new file mode 100644
> index 0000000000000000000000000000000000000000..d2a81069e335c12933cdf48bbc1b7c13e937a6c3
> --- /dev/null
> +++ b/arch/arm/dts/imx93-phyboard-segin-downstream.dtsi
> @@ -0,0 +1,269 @@
> +// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
> +/*
> + * Copyright (C) 2023 PHYTEC Messtechnik GmbH
> + * Author: Wadim Egorov <w.egorov at phytec.de>, Christoph Stoidner <c.stoidner at phytec.de>
> + */
> +
> +/*
> + * Contents of this file are copied from the linux-phytec-imx downstream and
> + * can be removed once mainlined.
> + */
> +
> +/ {
> +	reg_vcc_1v8_audio: regulator-vcc1v8-audio {
> +		compatible = "regulator-fixed";
> +		regulator-max-microvolt = <1800000>;
> +		regulator-min-microvolt = <1800000>;
> +		regulator-name = "VCC1V8_AUDIO";
> +	};
> +	reg_vcc_3v3: regulator-vcc-3v3 {
> +		compatible = "regulator-fixed";
> +		regulator-max-microvolt = <3300000>;
> +		regulator-min-microvolt = <3300000>;
> +		regulator-name = "VCC3V3";
> +	};
> +};
> +
> +&reg_usdhc2_vmmc {
> +	compatible = "regulator-fixed";
> +	gpio = <&gpio3 7 GPIO_ACTIVE_HIGH>;
> +	enable-active-high;
> +	pinctrl-names = "default";
> +	pinctrl-0 = <&pinctrl_reg_usdhc2_vmmc>;
> +	regulator-max-microvolt = <3300000>;
> +	regulator-min-microvolt = <3300000>;
> +	regulator-name = "VCC_SD";
> +};
> +
> +/* I2C3 */
> +&lpi2c3 {
> +	clock-frequency = <400000>;
> +	pinctrl-names = "default";
> +	pinctrl-0 = <&pinctrl_lpi2c3>;
> +	#address-cells = <1>;
> +	#size-cells = <0>;
> +	status = "okay";
> +
> +	pmic at 25 {
> +		compatible = "nxp,pca9451a";
> +		reg = <0x25>;
> +		pinctrl-names = "default";
> +		pinctrl-0 = <&pinctrl_pmic>;
> +		interrupt-parent = <&gpio4>;
> +		interrupts = <27 IRQ_TYPE_LEVEL_LOW>;
> +
> +		regulators {
> +			buck1: BUCK1 {
> +				regulator-name = "VDD_SOC";
> +				regulator-min-microvolt = <610000>;
> +				regulator-max-microvolt = <950000>;
> +				regulator-boot-on;
> +				regulator-always-on;
> +				regulator-ramp-delay = <3125>;
> +			};
> +
> +			buck2: BUCK2 {
> +				regulator-name = "VDDQ_0V6";
> +				regulator-min-microvolt = <600000>;
> +				regulator-max-microvolt = <600000>;
> +				regulator-boot-on;
> +				regulator-always-on;
> +			};
> +
> +			buck4: BUCK4 {
> +				regulator-name = "VDD_3V3_BUCK";
> +				regulator-min-microvolt = <3300000>;
> +				regulator-max-microvolt = <3300000>;
> +				regulator-boot-on;
> +				regulator-always-on;
> +			};
> +
> +			buck5: BUCK5 {
> +				regulator-name = "VDD_1V8";
> +				regulator-min-microvolt = <1800000>;
> +				regulator-max-microvolt = <1800000>;
> +				regulator-boot-on;
> +				regulator-always-on;
> +			};
> +
> +			buck6: BUCK6 {
> +				regulator-name = "VDD_1V1";
> +				regulator-min-microvolt = <1100000>;
> +				regulator-max-microvolt = <1100000>;
> +				regulator-boot-on;
> +				regulator-always-on;
> +			};
> +
> +			ldo1: LDO1 {
> +				regulator-name = "PMIC_SNVS_1V8";
> +				regulator-min-microvolt = <1800000>;
> +				regulator-max-microvolt = <1800000>;
> +				regulator-boot-on;
> +				regulator-always-on;
> +			};
> +
> +			ldo4: LDO4 {
> +				regulator-name = "VDD_0V8";
> +				regulator-min-microvolt = <800000>;
> +				regulator-max-microvolt = <800000>;
> +				regulator-boot-on;
> +				regulator-always-on;
> +			};
> +
> +			ldo5: LDO5 {
> +				regulator-name = "NVCC_SD2";
> +				regulator-min-microvolt = <1800000>;
> +				regulator-max-microvolt = <3300000>;
> +				regulator-boot-on;
> +				regulator-always-on;
> +			};
> +		};
> +	};
> +
> +	eeprom at 50 {
> +		compatible = "atmel,24c32";
> +		reg = <0x50>;
> +		pagesize = <32>;
> +		vcc-supply = <&buck4>;
> +	};
> +
> +	eepromid at 58 {
> +		compatible = "atmel,24c32";
> +		pagesize = <32>;
> +		reg = <0x58>;
> +		size = <32>;
> +		vcc-supply = <&buck4>;
> +	};
> +};
> +
> +/* Ethernet */
> +&eqos {
> +	pinctrl-names = "default";
> +	pinctrl-0 = <&pinctrl_eqos>;
> +	phy-mode = "rmii";
> +	phy-handle = <&ethphy2>;
> +	assigned-clocks = <&clk IMX93_CLK_ENET_TIMER2>,
> +			  <&clk IMX93_CLK_ENET>;
> +	assigned-clock-parents = <&clk IMX93_CLK_SYS_PLL_PFD1_DIV2>,
> +				 <&clk IMX93_CLK_SYS_PLL_PFD1_DIV2>;
> +	assigned-clock-rates = <100000000>, <50000000>;
> +	status = "okay";
> +};
> +
> +/* ENET2 MDIO */
> +&mdio {
> +	ethphy2: ethernet-phy at 2 {
> +		reg = <2>;
> +		micrel,led-mode = <1>;
> +		compatible = "ethernet-phy-id0022.1561";
> +
> +		/*
> +		 * HACK:
> +		 * IMX93_CLK_ENET is the ref clock and should be running at 50Mhz.
> +		 * Using it here to tell the PHY we are running at 50MHz is not working.
> +		 * Let us simply use another clock here.
> +		 */
> +		/* clocks = <&clk IMX93_CLK_ENET>; */
> +		clocks = <&clk IMX93_CLK_ENET_REF_PHY>;
> +		clock-names = "rmii-ref";
> +	};
> +};
> +
> +/* USB  */
> +&usbotg1 {
> +	disable-over-current;
> +	dr_mode = "otg";
> +	status = "okay";
> +};
> +
> +&usbotg2 {
> +	disable-over-current;
> +	dr_mode = "host";
> +	status = "okay";
> +};
> +
> +/* SD-Card */
> +&usdhc2 {
> +	pinctrl-names = "default", "state_100mhz", "state_200mhz";
> +	pinctrl-0 = <&pinctrl_usdhc2_default>, <&pinctrl_usdhc2_cd>;
> +	pinctrl-1 = <&pinctrl_usdhc2_100mhz>, <&pinctrl_usdhc2_cd>;
> +	pinctrl-2 = <&pinctrl_usdhc2_200mhz>, <&pinctrl_usdhc2_cd>;
> +	cd-gpios = <&gpio3 00 GPIO_ACTIVE_LOW>;
> +	vmmc-supply = <&reg_usdhc2_vmmc>;
> +	bus-width = <4>;
> +	disable-wp;
> +	no-sdio;
> +	no-mmc;
> +	status = "okay";
> +};
> +
> +/* need to config the SION for data and cmd pad, refer to ERR052021 */
> +&pinctrl_usdhc2_default {
> +	fsl,pins = <
> +		MX93_PAD_SD2_CLK__USDHC2_CLK		0x159e
> +		MX93_PAD_SD2_CMD__USDHC2_CMD		0x4000139e
> +		MX93_PAD_SD2_DATA0__USDHC2_DATA0	0x4000138e
> +		MX93_PAD_SD2_DATA1__USDHC2_DATA1	0x4000138e
> +		MX93_PAD_SD2_DATA2__USDHC2_DATA2	0x4000138e
> +		MX93_PAD_SD2_DATA3__USDHC2_DATA3	0x4000139e
> +		MX93_PAD_SD2_VSELECT__USDHC2_VSELECT	0x51e
> +	>;
> +};
> +
> +/* need to config the SION for data and cmd pad, refer to ERR052021 */
> +&pinctrl_usdhc2_100mhz {
> +	fsl,pins = <
> +		MX93_PAD_SD2_CLK__USDHC2_CLK            0x159e
> +		MX93_PAD_SD2_CMD__USDHC2_CMD            0x4000139e
> +		MX93_PAD_SD2_DATA0__USDHC2_DATA0        0x4000138e
> +		MX93_PAD_SD2_DATA1__USDHC2_DATA1        0x4000138e
> +		MX93_PAD_SD2_DATA2__USDHC2_DATA2        0x4000139e
> +		MX93_PAD_SD2_DATA3__USDHC2_DATA3        0x4000139e
> +		MX93_PAD_SD2_VSELECT__USDHC2_VSELECT    0x51e
> +	>;
> +};
> +
> +/* need to config the SION for data and cmd pad, refer to ERR052021 */
> +&pinctrl_usdhc2_200mhz {
> +	fsl,pins = <
> +		MX93_PAD_SD2_CLK__USDHC2_CLK            0x158e
> +		MX93_PAD_SD2_CMD__USDHC2_CMD            0x4000139e
> +		MX93_PAD_SD2_DATA0__USDHC2_DATA0        0x4000139e
> +		MX93_PAD_SD2_DATA1__USDHC2_DATA1        0x4000139e
> +		MX93_PAD_SD2_DATA2__USDHC2_DATA2        0x4000139e
> +		MX93_PAD_SD2_DATA3__USDHC2_DATA3        0x4000139e
> +		MX93_PAD_SD2_VSELECT__USDHC2_VSELECT    0x51e
> +	>;
> +};
> +
> +
> +&iomuxc {
> +	pinctrl_eqos: eqosgrp {
> +		fsl,pins = <
> +			MX93_PAD_ENET1_TD2__CCM_ENET_QOS_CLOCK_GENERATE_REF_CLK 0x4000050e
> +			MX93_PAD_ENET1_RD0__ENET_QOS_RGMII_RD0			0x57e
> +			MX93_PAD_ENET1_RD1__ENET_QOS_RGMII_RD1			0x57e
> +			MX93_PAD_ENET1_TD0__ENET_QOS_RGMII_TD0			0x50e
> +			MX93_PAD_ENET1_TD1__ENET_QOS_RGMII_TD1			0x50e
> +			MX93_PAD_ENET1_RX_CTL__ENET_QOS_RGMII_RX_CTL		0x57e
> +			MX93_PAD_ENET1_TX_CTL__ENET_QOS_RGMII_TX_CTL		0x50e
> +			MX93_PAD_ENET1_RXC__ENET_QOS_RX_ER			0x57e
> +		>;
> +	};
> +	pinctrl_lpi2c3: lpi2c3grp {
> +		fsl,pins = <
> +			MX93_PAD_GPIO_IO28__LPI2C3_SDA			0x40000b9e
> +			MX93_PAD_GPIO_IO29__LPI2C3_SCL			0x40000b9e
> +		>;
> +	};
> +	pinctrl_pmic: pmicgrp {
> +		fsl,pins = <
> +			MX93_PAD_ENET2_RD3__GPIO4_IO27			0x31e
> +		>;
> +	};
> +	pinctrl_rtc: rtcgrp {
> +		fsl,pins = <
> +			MX93_PAD_ENET2_RD2__GPIO4_IO26		0x31e
> +		>;
> +	};
> +};
> diff --git a/arch/arm/dts/imx93-phyboard-segin.dts b/arch/arm/dts/imx93-phyboard-segin.dts
> new file mode 100644
> index 0000000000000000000000000000000000000000..0fc69b8789661eaa3c904efbe3e439170a83adb6
> --- /dev/null
> +++ b/arch/arm/dts/imx93-phyboard-segin.dts
> @@ -0,0 +1,28 @@
> +// SPDX-License-Identifier: (GPL-2.0-or-later OR MIT)
> +
> +#include <arm64/freescale/imx93-phyboard-segin.dts>
> +#include "imx93.dtsi"
> +#include "imx93-phyboard-segin-downstream.dtsi"
> +
> +/ {
> +	chosen {
> +		environment-emmc {
> +			compatible = "barebox,environment";
> +			device-path = &environment_emmc;
> +		};
> +	};
> +};
> +
> +&usdhc1 {
> +	partitions {
> +		compatible = "fixed-partitions";
> +		#address-cells = <2>;
> +		#size-cells = <2>;
> +
> +		environment_emmc: partition at 80000 {
> +			label = "barebox-environment";
> +			reg = <0x0 0x80000 0x0 0x80000>;
> +		};
> +	};
> +
> +};
> diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
> index 5ae7ab12ee94f4fab3fe446904ea785c5cd51193..552e7227a0221fee8232dfba5dcdd60de923ff0c 100644
> --- a/arch/arm/mach-imx/Kconfig
> +++ b/arch/arm/mach-imx/Kconfig
> @@ -746,6 +746,15 @@ config MACH_ZII_IMX8MQ_DEV
>   
>   comment "i.MX93 boards"
>   
> +config MACH_PHYTEC_PHYCORE_IMX93
> +	bool "phyCORE i.MX93 SoM based devices"
> +	select ARCH_IMX93
> +	select IMX9_DRAM
> +	select I2C
> +	select I2C_IMX_LPI2C
> +	select FIRMWARE_IMX93_ATF
> +	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
> +
>   config MACH_TQMA93XX
>   	bool "TQ i.MX93 on TQMA93XX Board"
>   	select ARCH_IMX93
> diff --git a/images/Makefile.imx b/images/Makefile.imx
> index c3f1bd5f05a008321944cf68659c146f8cd25ce1..93264254e9e4cda3969bf7bf4812f2d1c5b59c09 100644
> --- a/images/Makefile.imx
> +++ b/images/Makefile.imx
> @@ -521,3 +521,7 @@ $(obj)/%.imx9img: $(obj)/% FORCE
>   pblb-$(CONFIG_MACH_TQMA93XX) += start_imx93_tqma93xx
>   FILE_barebox-tqma93xx.img = start_imx93_tqma93xx.pblb.imx9img
>   image-$(CONFIG_MACH_TQMA93XX) += barebox-tqma93xx.img
> +
> +pblb-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX93) += start_imx93_phyboard_segin
> +FILE_barebox-phyboard_segin.img = start_imx93_phyboard_segin.pblb.imx9img
> +image-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX93) += barebox-phyboard_segin.img
> 
> ---
> base-commit: 75296e2aa356f6fbd680aa2204545732ac49e37d
> change-id: 20250304-phyboard-segin-imx93-257c1809d4f8
> 
> Best regards,


-- 
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-5555 |


From eagle.alexander923 at gmail.com  Wed Mar  5 21:39:20 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Thu,  6 Mar 2025 08:39:20 +0300
Subject: [PATCH RFC] at91: Remove AT91_LOAD_BAREBOX_SRAM option
Message-ID: <20250306053920.7544-1-eagle.alexander923@gmail.com>

This patch removes the AT91_LOAD_BAREBOX_SRAM option.
The option was introduced over 12 years ago and is now misleading.
The functionality of loading a stage into SRAM can now be implemented
via PBL in a low-level board-specific call.
For boot sources (other than MMC), BOOTRom expects the size of the
image to boot into SRAM in exception vector 6, so let's fix
barebox-arm-head to always use the correct value here.

This partially reverts commits:
41d3371741: at91: introduce AT91_LOAD_BAREBOX_SRAM to specifcy which size load for external boot
4bd5ceee72: at91sam9261ek: add first stage support

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 .../boards/at91/microchip-at91sam9263-ek.rst  |  7 --
 .../defaultenv-at91sam9261ek/config           | 10 +--
 arch/arm/boards/at91sam9261ek/init.c          | 16 +----
 .../at91sam9261ek_first_stage_defconfig       | 65 -------------------
 arch/arm/mach-at91/Kconfig                    | 10 ---
 include/mach/at91/barebox-arm.h               | 11 +---
 6 files changed, 6 insertions(+), 113 deletions(-)
 delete mode 100644 arch/arm/configs/at91sam9261ek_first_stage_defconfig

diff --git a/Documentation/boards/at91/microchip-at91sam9263-ek.rst b/Documentation/boards/at91/microchip-at91sam9263-ek.rst
index 8022cdd678..557e2040cb 100644
--- a/Documentation/boards/at91/microchip-at91sam9263-ek.rst
+++ b/Documentation/boards/at91/microchip-at91sam9263-ek.rst
@@ -123,10 +123,3 @@ This is the reset vector and exception vectors. Must be the very first in the fi
 ``.text_bare_init*:``
 Everything in this section, and , is checked at link time.
 Size most be less than BAREBOX_MAX_BARE_INIT_SIZE / ARCH_BAREBOX_MAX_BARE_INIT_SIZE
-
-at91 specify the size of the two sections in exception vector 6 (see above),
-if CONFIG_AT91_LOAD_BAREBOX_SRAM is defined.
-I think this is because some at91 variants have only very limited SRAM size,
-and we copy only a minimal part to the SRAM. The remaining part is then
-executed in-place.
-For at91sam9263 we have a large SRAM so there is room for the full bootstrap binary.
diff --git a/arch/arm/boards/at91sam9261ek/defaultenv-at91sam9261ek/config b/arch/arm/boards/at91sam9261ek/defaultenv-at91sam9261ek/config
index cb3e847f54..7d855779ca 100644
--- a/arch/arm/boards/at91sam9261ek/defaultenv-at91sam9261ek/config
+++ b/arch/arm/boards/at91sam9261ek/defaultenv-at91sam9261ek/config
@@ -34,14 +34,8 @@ kernelimage=zImage
 #kernelimage=Image.lzo
 
 nand_device=atmel_nand
-if [ x$borebox_first_stage = x1 ]
-then
-	nand_parts="384k(barebox)ro,128k(bareboxenv),128k(bareboxenv2),128k(oftree),4M(kernel),120M(rootfs),-(data)"
-	rootfs_mtdblock_nand=5
-else
-	nand_parts="128k(at91bootstrap),256k(barebox)ro,128k(bareboxenv),128k(bareboxenv2),128k(oftree),4M(kernel),120M(rootfs),-(data)"
-	rootfs_mtdblock_nand=6
-fi
+nand_parts="128k(at91bootstrap),256k(barebox)ro,128k(bareboxenv),128k(bareboxenv2),128k(oftree),4M(kernel),120M(rootfs),-(data)"
+rootfs_mtdblock_nand=6
 
 autoboot_timeout=3
 
diff --git a/arch/arm/boards/at91sam9261ek/init.c b/arch/arm/boards/at91sam9261ek/init.c
index da305fe9ed..799466d655 100644
--- a/arch/arm/boards/at91sam9261ek/init.c
+++ b/arch/arm/boards/at91sam9261ek/init.c
@@ -319,9 +319,6 @@ mem_initcall(at91sam9261ek_mem_init);
 
 static int at91sam9261ek_devices_init(void)
 {
-	u32 barebox_part_start;
-	u32 barebox_part_size;
-
 	ek_add_device_nand();
 	ek_add_device_dm9000();
 	ek_add_device_udc();
@@ -330,17 +327,8 @@ static int at91sam9261ek_devices_init(void)
 	ek_add_device_lcdc();
 	ek_add_device_spi();
 
-	if (IS_ENABLED(CONFIG_AT91_LOAD_BAREBOX_SRAM)) {
-		barebox_part_start = 0;
-		barebox_part_size = SZ_256K + SZ_128K;
-		export_env_ull("borebox_first_stage", 1);
-	} else {
-		devfs_add_partition("nand0", 0x00000, SZ_128K, DEVFS_PARTITION_FIXED, "at91bootstrap_raw");
-		barebox_part_start = SZ_128K;
-		barebox_part_size = SZ_256K;
-	}
-	devfs_add_partition("nand0", barebox_part_start, barebox_part_size,
-			    DEVFS_PARTITION_FIXED, "self_raw");
+	devfs_add_partition("nand0", 0x00000, SZ_128K, DEVFS_PARTITION_FIXED, "at91bootstrap_raw");
+	devfs_add_partition("nand0", SZ_128K, SZ_256K, DEVFS_PARTITION_FIXED, "self_raw");
 	dev_add_bb_dev("self_raw", "self0");
 	devfs_add_partition("nand0", SZ_256K + SZ_128K, SZ_128K, DEVFS_PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
diff --git a/arch/arm/configs/at91sam9261ek_first_stage_defconfig b/arch/arm/configs/at91sam9261ek_first_stage_defconfig
deleted file mode 100644
index 8e6065de34..0000000000
--- a/arch/arm/configs/at91sam9261ek_first_stage_defconfig
+++ /dev/null
@@ -1,65 +0,0 @@
-CONFIG_ARCH_AT91=y
-CONFIG_ARCH_AT91SAM9261=y
-CONFIG_AT91_LOAD_BAREBOX_SRAM=y
-CONFIG_AEABI=y
-CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
-CONFIG_MMU=y
-CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x27000
-CONFIG_EXPERIMENTAL=y
-CONFIG_MALLOC_TLSF=y
-CONFIG_PROMPT="9261-EK:"
-CONFIG_HUSH_FANCY_PROMPT=y
-CONFIG_CMDLINE_EDITING=y
-CONFIG_AUTO_COMPLETE=y
-CONFIG_MENU=y
-CONFIG_BOOTM_SHOW_TYPE=y
-CONFIG_BOOTM_INITRD=y
-CONFIG_CONSOLE_ACTIVATE_ALL=y
-CONFIG_DEFAULT_ENVIRONMENT_GENERIC=y
-# CONFIG_CMD_ARM_CPUINFO is not set
-CONFIG_LONGHELP=y
-CONFIG_CMD_MEMINFO=y
-CONFIG_CMD_AT91_BOOT_TEST=y
-# CONFIG_CMD_BOOTU is not set
-CONFIG_CMD_GO=y
-CONFIG_CMD_LOADB=y
-CONFIG_CMD_RESET=y
-CONFIG_CMD_UIMAGE=y
-CONFIG_CMD_PARTITION=y
-CONFIG_CMD_EXPORT=y
-CONFIG_CMD_PRINTENV=y
-CONFIG_CMD_SAVEENV=y
-CONFIG_CMD_SLEEP=y
-CONFIG_CMD_DHCP=y
-CONFIG_CMD_PING=y
-CONFIG_CMD_TFTP=y
-CONFIG_CMD_ECHO_E=y
-CONFIG_CMD_EDIT=y
-CONFIG_CMD_LOGIN=y
-CONFIG_CMD_MENU=y
-CONFIG_CMD_MENU_MANAGEMENT=y
-CONFIG_CMD_PASSWD=y
-CONFIG_CMD_READLINE=y
-CONFIG_CMD_TIMEOUT=y
-CONFIG_CMD_FLASH=y
-CONFIG_CMD_GPIO=y
-CONFIG_CMD_LED=y
-CONFIG_CMD_LED_TRIGGER=y
-CONFIG_NET=y
-CONFIG_NET_NFS=y
-CONFIG_NET_RESOLV=y
-CONFIG_DRIVER_NET_DM9K=y
-CONFIG_DRIVER_SPI_ATMEL=y
-CONFIG_MTD=y
-# CONFIG_MTD_OOB_DEVICE is not set
-CONFIG_MTD_DATAFLASH=y
-CONFIG_NAND=y
-CONFIG_NAND_ATMEL=y
-CONFIG_USB_GADGET=y
-CONFIG_USB_GADGET_DFU=y
-CONFIG_USB_GADGET_SERIAL=y
-CONFIG_LED=y
-CONFIG_LED_GPIO=y
-CONFIG_LED_TRIGGERS=y
-CONFIG_KEYBOARD_GPIO=y
-CONFIG_FS_TFTP=y
diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig
index 0b3a4ac44c..5bc5cacb7c 100644
--- a/arch/arm/mach-at91/Kconfig
+++ b/arch/arm/mach-at91/Kconfig
@@ -152,9 +152,6 @@ config HAVE_NAND_ATMEL_BUSWIDTH_16
 config HAVE_AT91_DATAFLASH_CARD
 	bool
 
-config HAVE_AT91_LOAD_BAREBOX_SRAM
-	bool
-
 comment "Atmel AT91 System-on-Chip"
 
 config SOC_AT91RM9200
@@ -177,7 +174,6 @@ config SOC_AT91SAM9261
 	bool
 	select SOC_AT91SAM9
 	select PINCTRL_AT91
-	select HAVE_AT91_LOAD_BAREBOX_SRAM
 	help
 	  Select this if you are using one of Atmel's AT91SAM9261 or AT91SAM9G10 SoC.
 
@@ -185,7 +181,6 @@ config SOC_AT91SAM9263
 	bool
 	select SOC_AT91SAM9
 	select HAS_MACB
-	select HAVE_AT91_LOAD_BAREBOX_SRAM
 	select PINCTRL_AT91
 
 config SOC_AT91SAM9G45
@@ -707,9 +702,4 @@ config AT91_BOOTSTRAP
 	depends on HAVE_AT91_BOOTSTRAP
 	select BOOTSTRAP
 
-config AT91_LOAD_BAREBOX_SRAM
-	bool "at91 load barebox in sram"
-	depends on SHELL_NONE || HAVE_AT91_LOAD_BAREBOX_SRAM
-	default y if SHELL_NONE
-
 endif
diff --git a/include/mach/at91/barebox-arm.h b/include/mach/at91/barebox-arm.h
index 652fd283a0..3a041b4557 100644
--- a/include/mach/at91/barebox-arm.h
+++ b/include/mach/at91/barebox-arm.h
@@ -4,18 +4,11 @@
 
 #include <asm/barebox-arm.h>
 #include <asm/common.h>
+#include <linux/compiler.h>
 #include <mach/at91/sama5d3.h>
 #include <mach/at91/sama5d4.h>
 #include <mach/at91/at91sam9261.h>
 
-#ifdef CONFIG_AT91_LOAD_BAREBOX_SRAM
-#define AT91_EXV6	".word _barebox_image_size\n"
-#else
-#define AT91_EXV6	".word _barebox_bare_init_size\n"
-#endif
-
-#include <linux/compiler.h>
-
 static __always_inline void __barebox_at91_head(void)
 {
 	__asm__ __volatile__ (
@@ -27,7 +20,7 @@ static __always_inline void __barebox_at91_head(void)
 		"1: b 1b\n"
 		"1: b 1b\n"
 		"1: b 1b\n"
-		AT91_EXV6				/* image size to load by the bootrom */
+		".word _barebox_image_size\n"		/* image size to load by the bootrom */
 		"1: b 1b\n"
 		"1: b 1b\n"
 #endif
-- 
2.39.1



From bst at pengutronix.de  Thu Mar  6 07:24:43 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Thu,  6 Mar 2025 16:24:43 +0100
Subject: [PATCH] commands: fix typo in CMD_AUTOMOUNT
Message-ID: <20250306152443.2519665-1-bst@pengutronix.de>

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 commands/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index e41625e294c..fe459fa862f 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -638,7 +638,7 @@ config CMD_AUTOMOUNT
 	select FS_AUTOMOUNT
 	prompt "automount"
 	help
-	  Automount allows o automatically execute a script when a certain
+	  Automount allows to automatically execute a script when a certain
 	  directory is accessed for the first time. The script should then make
 	  this directory available (discover USB devices, bring network interface
 	  up and finally mount the filesystem).
-- 
2.39.5



From eagle.alexander923 at gmail.com  Thu Mar  6 21:51:35 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Fri,  7 Mar 2025 08:51:35 +0300
Subject: [PATCH] at91: Remove non-devicetree board support for SAMA5D3 SOC
Message-ID: <20250307055135.26298-1-eagle.alexander923@gmail.com>

Since all SAMA5D3 boards now do not use the devicetree,
we can safely remove the board support files for this SOC.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/Kconfig           |   5 -
 arch/arm/mach-at91/Makefile          |   1 -
 arch/arm/mach-at91/sama5d3.c         | 410 ----------------------
 arch/arm/mach-at91/sama5d3_devices.c | 491 ---------------------------
 4 files changed, 907 deletions(-)
 delete mode 100644 arch/arm/mach-at91/sama5d3.c
 delete mode 100644 arch/arm/mach-at91/sama5d3_devices.c

diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig
index 0b3a4ac44c..d63845437d 100644
--- a/arch/arm/mach-at91/Kconfig
+++ b/arch/arm/mach-at91/Kconfig
@@ -269,10 +269,6 @@ config ARCH_AT91SAM9N12
 	bool "AT91SAM9N12"
 	select SOC_AT91SAM9N12
 
-config ARCH_SAMA5D3
-	bool "SAMA5D3x"
-	select SOC_SAMA5D3
-
 config ARCH_SAMA5D4
 	bool "SAMA5D4"
 	select SOC_SAMA5D4
@@ -289,7 +285,6 @@ config ARCH_BAREBOX_MAX_BARE_INIT_SIZE
 	default 0xF000 if ARCH_AT91SAM9G45
 	default 0x6000 if ARCH_AT91SAM9X5
 	default 0x6000 if ARCH_AT91SAM9N12
-	default 0x6000 if ARCH_SAMA5D3
 	default 0xffffffff
 
 if ARCH_AT91RM9200
diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
index 857f77ab49..556e46f181 100644
--- a/arch/arm/mach-at91/Makefile
+++ b/arch/arm/mach-at91/Makefile
@@ -27,7 +27,6 @@ obj-$(CONFIG_SOC_AT91SAM9G10) += at91sam9261.o at91sam9261_devices.o
 ifeq ($(CONFIG_AT91_MULTI_BOARDS),)
 obj-$(CONFIG_SOC_AT91SAM9260) += at91sam9260.o at91sam9260_devices.o
 obj-$(CONFIG_SOC_AT91SAM9263) += at91sam9263.o at91sam9263_devices.o
-obj-$(CONFIG_SOC_SAMA5D3)	+= sama5d3.o sama5d3_devices.o
 obj-$(CONFIG_SOC_SAMA5D4)	+= sama5d4.o sama5d4_devices.o
 endif
 lwl-$(CONFIG_SOC_AT91SAM9263)	+= sam9263_ll.o
diff --git a/arch/arm/mach-at91/sama5d3.c b/arch/arm/mach-at91/sama5d3.c
deleted file mode 100644
index 447ac711b4..0000000000
diff --git a/arch/arm/mach-at91/sama5d3_devices.c b/arch/arm/mach-at91/sama5d3_devices.c
deleted file mode 100644
index f6d5617e5f..0000000000
-- 
2.39.1



From s.hauer at pengutronix.de  Thu Mar  6 23:43:50 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 07 Mar 2025 08:43:50 +0100
Subject: [PATCH] commands: fix typo in CMD_AUTOMOUNT
In-Reply-To: <20250306152443.2519665-1-bst@pengutronix.de>
References: <20250306152443.2519665-1-bst@pengutronix.de>
Message-ID: <174133343001.958871.11612609785653961247.b4-ty@pengutronix.de>


On Thu, 06 Mar 2025 16:24:43 +0100, Bastian Krause wrote:
> 


Applied, thanks!

[1/1] commands: fix typo in CMD_AUTOMOUNT
      https://git.pengutronix.de/cgit/barebox/commit/?id=42b945310066 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar  6 23:50:45 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 07 Mar 2025 08:50:45 +0100
Subject: [PATCH] at91: Remove non-devicetree board support for SAMA5D3
 SOC
In-Reply-To: <20250307055135.26298-1-eagle.alexander923@gmail.com>
References: <20250307055135.26298-1-eagle.alexander923@gmail.com>
Message-ID: <174133384594.969665.14507034128959480599.b4-ty@pengutronix.de>


On Fri, 07 Mar 2025 08:51:35 +0300, Alexander Shiyan wrote:
> Since all SAMA5D3 boards now do not use the devicetree,
> we can safely remove the board support files for this SOC.
> 
> 

Applied, thanks!

[1/1] at91: Remove non-devicetree board support for SAMA5D3 SOC
      https://git.pengutronix.de/cgit/barebox/commit/?id=90738596b7d4 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar  6 23:51:56 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 7 Mar 2025 08:51:56 +0100
Subject: [PATCH] at91: Remove non-devicetree board support for SAMA5D3 SOC
In-Reply-To: <20250307055135.26298-1-eagle.alexander923@gmail.com>
References: <20250307055135.26298-1-eagle.alexander923@gmail.com>
Message-ID: <Z8qlnE2kk64HdkDy@pengutronix.de>

On Fri, Mar 07, 2025 at 08:51:35AM +0300, Alexander Shiyan wrote:
> Since all SAMA5D3 boards now do not use the devicetree,
> we can safely remove the board support files for this SOC.

s/do not//

I fixed that while applying.

Sascha

> 
> Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
> ---
>  arch/arm/mach-at91/Kconfig           |   5 -
>  arch/arm/mach-at91/Makefile          |   1 -
>  arch/arm/mach-at91/sama5d3.c         | 410 ----------------------
>  arch/arm/mach-at91/sama5d3_devices.c | 491 ---------------------------
>  4 files changed, 907 deletions(-)
>  delete mode 100644 arch/arm/mach-at91/sama5d3.c
>  delete mode 100644 arch/arm/mach-at91/sama5d3_devices.c
> 
> diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig
> index 0b3a4ac44c..d63845437d 100644
> --- a/arch/arm/mach-at91/Kconfig
> +++ b/arch/arm/mach-at91/Kconfig
> @@ -269,10 +269,6 @@ config ARCH_AT91SAM9N12
>  	bool "AT91SAM9N12"
>  	select SOC_AT91SAM9N12
>  
> -config ARCH_SAMA5D3
> -	bool "SAMA5D3x"
> -	select SOC_SAMA5D3
> -
>  config ARCH_SAMA5D4
>  	bool "SAMA5D4"
>  	select SOC_SAMA5D4
> @@ -289,7 +285,6 @@ config ARCH_BAREBOX_MAX_BARE_INIT_SIZE
>  	default 0xF000 if ARCH_AT91SAM9G45
>  	default 0x6000 if ARCH_AT91SAM9X5
>  	default 0x6000 if ARCH_AT91SAM9N12
> -	default 0x6000 if ARCH_SAMA5D3
>  	default 0xffffffff
>  
>  if ARCH_AT91RM9200
> diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
> index 857f77ab49..556e46f181 100644
> --- a/arch/arm/mach-at91/Makefile
> +++ b/arch/arm/mach-at91/Makefile
> @@ -27,7 +27,6 @@ obj-$(CONFIG_SOC_AT91SAM9G10) += at91sam9261.o at91sam9261_devices.o
>  ifeq ($(CONFIG_AT91_MULTI_BOARDS),)
>  obj-$(CONFIG_SOC_AT91SAM9260) += at91sam9260.o at91sam9260_devices.o
>  obj-$(CONFIG_SOC_AT91SAM9263) += at91sam9263.o at91sam9263_devices.o
> -obj-$(CONFIG_SOC_SAMA5D3)	+= sama5d3.o sama5d3_devices.o
>  obj-$(CONFIG_SOC_SAMA5D4)	+= sama5d4.o sama5d4_devices.o
>  endif
>  lwl-$(CONFIG_SOC_AT91SAM9263)	+= sam9263_ll.o
> diff --git a/arch/arm/mach-at91/sama5d3.c b/arch/arm/mach-at91/sama5d3.c
> deleted file mode 100644
> index 447ac711b4..0000000000
> diff --git a/arch/arm/mach-at91/sama5d3_devices.c b/arch/arm/mach-at91/sama5d3_devices.c
> deleted file mode 100644
> index f6d5617e5f..0000000000
> -- 
> 2.39.1
> 
> 
> 

-- 
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-5555 |


From s.hauer at pengutronix.de  Thu Mar  6 23:59:27 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri,  7 Mar 2025 08:59:27 +0100
Subject: [PATCH] ARM: at91: remove obsolete defconfig
Message-ID: <20250307075927.973504-1-s.hauer@pengutronix.de>

sama5d3xek_defconfig is obsolete. The sama5d3xek is now covered by
at91_multi_defconfig. It currently falls back for building for
the AT91RM9200-EK instead of the sama5d3xek, so just drop it.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/sama5d3xek_defconfig | 87 ---------------------------
 1 file changed, 87 deletions(-)
 delete mode 100644 arch/arm/configs/sama5d3xek_defconfig

diff --git a/arch/arm/configs/sama5d3xek_defconfig b/arch/arm/configs/sama5d3xek_defconfig
deleted file mode 100644
index c868bd0daf..0000000000
--- a/arch/arm/configs/sama5d3xek_defconfig
+++ /dev/null
@@ -1,87 +0,0 @@
-CONFIG_TEXT_BASE=0x26f00000
-CONFIG_ARCH_AT91=y
-CONFIG_ARCH_SAMA5D3=y
-CONFIG_AEABI=y
-CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
-CONFIG_MMU=y
-CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x60000
-CONFIG_MALLOC_SIZE=0xA00000
-CONFIG_EXPERIMENTAL=y
-CONFIG_MALLOC_TLSF=y
-CONFIG_PROMPT="A5D3X-EK:"
-CONFIG_PROMPT_HUSH_PS2="y"
-CONFIG_HUSH_FANCY_PROMPT=y
-CONFIG_CMDLINE_EDITING=y
-CONFIG_AUTO_COMPLETE=y
-CONFIG_BOOTM_SHOW_TYPE=y
-CONFIG_BOOTM_VERBOSE=y
-CONFIG_BOOTM_INITRD=y
-CONFIG_BOOTM_OFTREE=y
-CONFIG_BOOTM_OFTREE_UIMAGE=y
-CONFIG_CONSOLE_ACTIVATE_ALL=y
-CONFIG_DEFAULT_ENVIRONMENT_GENERIC=y
-# CONFIG_CMD_ARM_CPUINFO is not set
-CONFIG_LONGHELP=y
-CONFIG_CMD_MEMINFO=y
-# CONFIG_CMD_BOOTU is not set
-CONFIG_CMD_GO=y
-CONFIG_CMD_LOADB=y
-CONFIG_CMD_RESET=y
-CONFIG_CMD_UIMAGE=y
-CONFIG_CMD_PARTITION=y
-CONFIG_CMD_EXPORT=y
-CONFIG_CMD_PRINTENV=y
-CONFIG_CMD_SAVEENV=y
-CONFIG_CMD_FILETYPE=y
-CONFIG_CMD_SLEEP=y
-CONFIG_CMD_DHCP=y
-CONFIG_CMD_MIITOOL=y
-CONFIG_CMD_PING=y
-CONFIG_CMD_TFTP=y
-CONFIG_CMD_ECHO_E=y
-CONFIG_CMD_EDIT=y
-CONFIG_CMD_SPLASH=y
-CONFIG_CMD_READLINE=y
-CONFIG_CMD_TIMEOUT=y
-CONFIG_CMD_FLASH=y
-CONFIG_CMD_GPIO=y
-CONFIG_CMD_I2C=y
-CONFIG_CMD_LED=y
-CONFIG_CMD_SPI=y
-CONFIG_CMD_LED_TRIGGER=y
-CONFIG_CMD_OFTREE=y
-CONFIG_NET=y
-CONFIG_NET_NFS=y
-CONFIG_NET_NETCONSOLE=y
-CONFIG_DRIVER_NET_MACB=y
-CONFIG_MICREL_PHY=y
-CONFIG_DRIVER_SPI_ATMEL=y
-CONFIG_I2C=y
-CONFIG_I2C_GPIO=y
-CONFIG_MTD=y
-# CONFIG_MTD_OOB_DEVICE is not set
-CONFIG_MTD_M25P80=y
-CONFIG_NAND=y
-CONFIG_NAND_ATMEL=y
-CONFIG_NAND_ATMEL_PMECC=y
-CONFIG_VIDEO=y
-CONFIG_DRIVER_VIDEO_ATMEL_HLCD=y
-CONFIG_MCI=y
-CONFIG_MCI_STARTUP=y
-CONFIG_MCI_ATMEL=y
-CONFIG_LED=y
-CONFIG_LED_GPIO=y
-CONFIG_LED_TRIGGERS=y
-CONFIG_KEYBOARD_GPIO=y
-CONFIG_KEYBOARD_QT1070=y
-CONFIG_W1=y
-CONFIG_W1_MASTER_GPIO=y
-CONFIG_W1_SLAVE_DS2431=y
-CONFIG_W1_SLAVE_DS2433=y
-CONFIG_W1_DUAL_SEARCH=y
-CONFIG_FS_EXT4=y
-CONFIG_FS_TFTP=y
-CONFIG_FS_FAT=y
-CONFIG_FS_FAT_WRITE=y
-CONFIG_FS_FAT_LFN=y
-CONFIG_PNG=y
-- 
2.39.5



From s.hauer at pengutronix.de  Fri Mar  7 00:00:07 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 07 Mar 2025 09:00:07 +0100
Subject: [PATCH master] nfs: rename global.net.nfsport to
 global.nfs.port
In-Reply-To: <20250305131121.3985854-1-a.fatoum@pengutronix.de>
References: <20250305131121.3985854-1-a.fatoum@pengutronix.de>
Message-ID: <174133440764.973644.18378279852503854528.b4-ty@pengutronix.de>


On Wed, 05 Mar 2025 14:11:21 +0100, Ahmad Fatoum wrote:
> There's already precedence in global.tftp.windowsize, so global.nfs.port
> is probably a better name than squeezing it into global.net.
> 
> This parameter is not yet in any release, so the fallout is fairly
> limited.
> 
> While at it, mention it in the documentation.
> 
> [...]

Applied, thanks!

[1/1] nfs: rename global.net.nfsport to global.nfs.port
      https://git.pengutronix.de/cgit/barebox/commit/?id=1b2126866258 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar  7 00:00:19 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 07 Mar 2025 09:00:19 +0100
Subject: [PATCH] Documentation: user: networking: fix trivial typo
In-Reply-To: <20250305131221.3986986-1-a.fatoum@pengutronix.de>
References: <20250305131221.3986986-1-a.fatoum@pengutronix.de>
Message-ID: <174133441928.973743.7534309935178488960.b4-ty@pengutronix.de>


On Wed, 05 Mar 2025 14:12:21 +0100, Ahmad Fatoum wrote:
> s/varariables/variables/
> 
> 

Applied, thanks!

[1/1] Documentation: user: networking: fix trivial typo
      https://git.pengutronix.de/cgit/barebox/commit/?id=0838b328ae48 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar  7 00:01:07 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 07 Mar 2025 09:01:07 +0100
Subject: [PATCH] ARM: i.MX9: tqma93xx: remove mach/imx/romapi.h include
In-Reply-To: <20250305140000.1539572-1-bst@pengutronix.de>
References: <20250305140000.1539572-1-bst@pengutronix.de>
Message-ID: <174133446733.973881.10754802296815043103.b4-ty@pengutronix.de>


On Wed, 05 Mar 2025 15:00:00 +0100, Bastian Krause wrote:
> dd26bc1d5a0 ("ARM: i.MX93: add destination argument to
> imx93_romapi_load_image()") added the imx93_romapi_load_image call to
> imx93_load_and_start_image_via_tfa and removed the call from
> board-specific lowlevel code. So drop the corresponding include as well.
> 
> 

Applied, thanks!

[1/1] ARM: i.MX9: tqma93xx: remove mach/imx/romapi.h include
      https://git.pengutronix.de/cgit/barebox/commit/?id=66b293c91527 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar  7 00:03:19 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 07 Mar 2025 09:03:19 +0100
Subject: [PATCH] at91: sama5d2: Do not use the contents of BSC_CR if
 the DISABLE_BSCR bit is set in the fuse
In-Reply-To: <20250305074835.34782-1-eagle.alexander923@gmail.com>
References: <20250305074835.34782-1-eagle.alexander923@gmail.com>
Message-ID: <174133459926.974669.5364324896110381958.b4-ty@pengutronix.de>


On Wed, 05 Mar 2025 10:48:35 +0300, Alexander Shiyan wrote:
> The DISABLE_BSCR bit in Fuse means "Does not read BSC_CR content,
> so the Boot settings are those from the Fuse".
> Let's ignore BSC_CR it this case.
> 
> 

Applied, thanks!

[1/1] at91: sama5d2: Do not use the contents of BSC_CR if the DISABLE_BSCR bit is set in the fuse
      https://git.pengutronix.de/cgit/barebox/commit/?id=1d0c9343b7f4 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar  7 00:18:14 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 7 Mar 2025 09:18:14 +0100
Subject: [PATCH 2/4] at91: Use the ddramc driver for all boards whose
 architecture uses it
In-Reply-To: <20250305062101.25588-2-eagle.alexander923@gmail.com>
References: <20250305062101.25588-1-eagle.alexander923@gmail.com>
 <20250305062101.25588-2-eagle.alexander923@gmail.com>
Message-ID: <Z8qrxskIpfyBO74o@pengutronix.de>

On Wed, Mar 05, 2025 at 09:20:59AM +0300, Alexander Shiyan wrote:
> Reuse ddramc driver for all SAMA5D2/3/4 boards.
> 
> Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
> ---
>  arch/arm/boards/sama5d4_xplained/lowlevel.c |  4 ++--
>  arch/arm/mach-at91/ddramc.c                 |  4 ++--
>  arch/arm/mach-at91/sama5d3_devices.c        |  7 +++----
>  arch/arm/mach-at91/sama5d4_devices.c        |  7 +++----
>  include/mach/at91/at91_ddrsdrc.h            | 11 -----------
>  5 files changed, 10 insertions(+), 23 deletions(-)
> 
> diff --git a/arch/arm/boards/sama5d4_xplained/lowlevel.c b/arch/arm/boards/sama5d4_xplained/lowlevel.c
> index 183bd9c5a9..5763333f39 100644
> --- a/arch/arm/boards/sama5d4_xplained/lowlevel.c
> +++ b/arch/arm/boards/sama5d4_xplained/lowlevel.c
> @@ -10,7 +10,7 @@
>  #include <asm/barebox-arm-head.h>
>  #include <asm/barebox-arm.h>
>  
> -#include <mach/at91/at91_ddrsdrc.h>
> +#include <mach/at91/ddramc.h>
>  #include <mach/at91/hardware.h>
>  
>  void __naked __bare_init barebox_arm_reset_vector(uint32_t r0, uint32_t r1, uint32_t r2)
> @@ -19,5 +19,5 @@ void __naked __bare_init barebox_arm_reset_vector(uint32_t r0, uint32_t r1, uint
>  
>  	arm_setup_stack(SAMA5D4_SRAM_BASE + SAMA5D4_SRAM_SIZE);
>  
> -	barebox_arm_entry(SAMA5_DDRCS, at91sama5d4_get_ddram_size(), NULL);
> +	sama5d4_barebox_entry(0, NULL);
>  }
> diff --git a/arch/arm/mach-at91/ddramc.c b/arch/arm/mach-at91/ddramc.c
> index 4d0637b487..ca77889ecc 100644
> --- a/arch/arm/mach-at91/ddramc.c
> +++ b/arch/arm/mach-at91/ddramc.c
> @@ -30,14 +30,14 @@ void __noreturn sama5d3_barebox_entry(unsigned int r4, void *boarddata)
>  {
>  	__sama5d3_stashed_bootrom_r4 = r4;
>  
> -	barebox_arm_entry(SAMA5_DDRCS, at91sama5d3_get_ddram_size(),
> +	barebox_arm_entry(SAMA5_DDRCS, sama5_ramsize(IOMEM(SAMA5D3_BASE_MPDDRC)),
>  			  boarddata);

I like it better to have a at91sama5d3_get_ddram_size() because with
that you don't have to worry about the base address, but only need to
call for the correct SoC.

>  }
>  void __noreturn sama5d4_barebox_entry(unsigned int r4, void *boarddata)
>  {
>  	__sama5d4_stashed_bootrom_r4 = r4;
>  
> -	barebox_arm_entry(SAMA5_DDRCS, at91sama5d4_get_ddram_size(),
> +	barebox_arm_entry(SAMA5_DDRCS, sama5_ramsize(IOMEM(SAMA5D4_BASE_MPDDRC)),
>  			  boarddata);
>  }
>  
> diff --git a/arch/arm/mach-at91/sama5d3_devices.c b/arch/arm/mach-at91/sama5d3_devices.c
> index f6d5617e5f..4871c2bd69 100644
> --- a/arch/arm/mach-at91/sama5d3_devices.c
> +++ b/arch/arm/mach-at91/sama5d3_devices.c
> @@ -21,10 +21,9 @@
>  
>  void at91_add_device_sdram(u32 size)
>  {
> -	if (!size)
> -		size = at91sama5d3_get_ddram_size();
> -
> -	arm_add_mem_device("ram0", SAMA5_DDRCS, size);
> +	add_generic_device("sama5-ddramc", DEVICE_ID_SINGLE, NULL,
> +			   SAMA5D3_BASE_MPDDRC, SZ_512,
> +			   IORESOURCE_MEM, NULL);

Is this necessary? I just merged your patch that says that all SAMA5D3
boards are merged to device tree. The device tree already has a
"atmel,sama5d3-ddramc" node, so there shouldn't be a need to create the
device here again.

Sascha

>  	add_mem_device("sram0", SAMA5D3_SRAM_BASE,
>  			SAMA5D3_SRAM_SIZE, IORESOURCE_MEM_WRITEABLE);
>  }
> diff --git a/arch/arm/mach-at91/sama5d4_devices.c b/arch/arm/mach-at91/sama5d4_devices.c
> index e438bd0d10..4a81e7cd40 100644
> --- a/arch/arm/mach-at91/sama5d4_devices.c
> +++ b/arch/arm/mach-at91/sama5d4_devices.c
> @@ -21,10 +21,9 @@
>  
>  void at91_add_device_sdram(u32 size)
>  {
> -	if (!size)
> -		size = at91sama5d4_get_ddram_size();
> -
> -	arm_add_mem_device("ram0", SAMA5_DDRCS, size);
> +	add_generic_device("sama5-ddramc", DEVICE_ID_SINGLE, NULL,
> +			   SAMA5D4_BASE_MPDDRC, SZ_512,
> +			   IORESOURCE_MEM, NULL);
>  	add_mem_device("sram0", SAMA5D4_SRAM_BASE,
>  		       SAMA5D4_SRAM_SIZE, IORESOURCE_MEM_WRITEABLE);
>  }
> diff --git a/include/mach/at91/at91_ddrsdrc.h b/include/mach/at91/at91_ddrsdrc.h
> index b9b0eb20b3..d511e157b2 100644
> --- a/include/mach/at91/at91_ddrsdrc.h
> +++ b/include/mach/at91/at91_ddrsdrc.h
> @@ -357,17 +357,6 @@ static inline u32 at91sam9n12_get_ddram_size(void)
>  	return at91_get_ddram_size(IOMEM(AT91SAM9N12_BASE_DDRSDRC0), true);
>  }
>  
> -static inline u32 at91sama5d3_get_ddram_size(void)
> -{
> -	return at91_get_ddram_size(IOMEM(SAMA5D3_BASE_MPDDRC), true);
> -}
> -
> -static inline u32 at91sama5d4_get_ddram_size(void)
> -{
> -	return at91_get_ddram_size(IOMEM(SAMA5D4_BASE_MPDDRC), true);
> -}
> -
> -
>  #endif /* __ASSEMBLY__ */
>  
>  #endif	/* #ifndef __AT91_DDRSDRC_H__ */
> -- 
> 2.39.1
> 
> 
> 

-- 
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-5555 |


From s.hauer at pengutronix.de  Fri Mar  7 00:20:09 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 07 Mar 2025 09:20:09 +0100
Subject: (subset) [PATCH 1/4] at91:: Remove dead definition of
 atmel_nand_load_image()
In-Reply-To: <20250305062101.25588-1-eagle.alexander923@gmail.com>
References: <20250305062101.25588-1-eagle.alexander923@gmail.com>
Message-ID: <174133560930.978587.2705746813753385202.b4-ty@pengutronix.de>


On Wed, 05 Mar 2025 09:20:58 +0300, Alexander Shiyan wrote:
> atmel_nand_load_image() is not defined anywhere.
> 
> 

Applied, thanks!

[1/4] at91:: Remove dead definition of atmel_nand_load_image()
      https://git.pengutronix.de/cgit/barebox/commit/?id=b4f53ca046e0 (link may not be stable)
[3/4] at91: ddramc: Trivial code cleanup
      https://git.pengutronix.de/cgit/barebox/commit/?id=94bb3615d786 (link may not be stable)
[4/4] at91: Use proper values of stashed SAMA5D2/3/4 bootsource
      https://git.pengutronix.de/cgit/barebox/commit/?id=b70ae92dda7a (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From eagle.alexander923 at gmail.com  Fri Mar  7 00:24:00 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Fri, 7 Mar 2025 11:24:00 +0300
Subject: [PATCH 2/4] at91: Use the ddramc driver for all boards whose
 architecture uses it
In-Reply-To: <Z8qrxskIpfyBO74o@pengutronix.de>
References: <20250305062101.25588-1-eagle.alexander923@gmail.com>
 <20250305062101.25588-2-eagle.alexander923@gmail.com> <Z8qrxskIpfyBO74o@pengutronix.de>
Message-ID: <CAP1tNvRyshvEEEumXZEfOQr475vDsaSovYtE2xLyLJL-AirToQ@mail.gmail.com>

Hello.

> > diff --git a/arch/arm/mach-at91/sama5d3_devices.c b/arch/arm/mach-at91/sama5d3_devices.c
> > index f6d5617e5f..4871c2bd69 100644
> > --- a/arch/arm/mach-at91/sama5d3_devices.c
> > +++ b/arch/arm/mach-at91/sama5d3_devices.c
> > @@ -21,10 +21,9 @@
> >
> >  void at91_add_device_sdram(u32 size)
> >  {
> > -     if (!size)
> > -             size = at91sama5d3_get_ddram_size();
> > -
> > -     arm_add_mem_device("ram0", SAMA5_DDRCS, size);
> > +     add_generic_device("sama5-ddramc", DEVICE_ID_SINGLE, NULL,
> > +                        SAMA5D3_BASE_MPDDRC, SZ_512,
> > +                        IORESOURCE_MEM, NULL);
>
> Is this necessary? I just merged your patch that says that all SAMA5D3
> boards are merged to device tree. The device tree already has a
> "atmel,sama5d3-ddramc" node, so there shouldn't be a need to create the
> device here again.

This series was created before I realized that board files for SAMA5D3 can
be deleted completely. In general, in this case it is a patch race :)

Thanks!


From s.hauer at pengutronix.de  Fri Mar  7 00:43:25 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 7 Mar 2025 09:43:25 +0100
Subject: [PATCH RFC] at91: Remove AT91_LOAD_BAREBOX_SRAM option
In-Reply-To: <20250306053920.7544-1-eagle.alexander923@gmail.com>
References: <20250306053920.7544-1-eagle.alexander923@gmail.com>
Message-ID: <Z8qxrYX0QOWkhO8J@pengutronix.de>

On Thu, Mar 06, 2025 at 08:39:20AM +0300, Alexander Shiyan wrote:
> This patch removes the AT91_LOAD_BAREBOX_SRAM option.
> The option was introduced over 12 years ago and is now misleading.
> The functionality of loading a stage into SRAM can now be implemented
> via PBL in a low-level board-specific call.
> For boot sources (other than MMC), BOOTRom expects the size of the
> image to boot into SRAM in exception vector 6, so let's fix
> barebox-arm-head to always use the correct value here.
> 
> This partially reverts commits:
> 41d3371741: at91: introduce AT91_LOAD_BAREBOX_SRAM to specifcy which size load for external boot
> 4bd5ceee72: at91sam9261ek: add first stage support

Building at91sam9261ek_first_stage_defconfig currently fails with:

images/start_at91sam9261ek.pblb size 250172 > maximum size 159744

So this is unusable anyway. Trying to bring the binary size down by 40%
is likely more work than implementing a xload mechanism for NAND.

I think this patch is fine.

Sascha

> 
> Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
> ---
>  .../boards/at91/microchip-at91sam9263-ek.rst  |  7 --
>  .../defaultenv-at91sam9261ek/config           | 10 +--
>  arch/arm/boards/at91sam9261ek/init.c          | 16 +----
>  .../at91sam9261ek_first_stage_defconfig       | 65 -------------------
>  arch/arm/mach-at91/Kconfig                    | 10 ---
>  include/mach/at91/barebox-arm.h               | 11 +---
>  6 files changed, 6 insertions(+), 113 deletions(-)
>  delete mode 100644 arch/arm/configs/at91sam9261ek_first_stage_defconfig
> 
> diff --git a/Documentation/boards/at91/microchip-at91sam9263-ek.rst b/Documentation/boards/at91/microchip-at91sam9263-ek.rst
> index 8022cdd678..557e2040cb 100644
> --- a/Documentation/boards/at91/microchip-at91sam9263-ek.rst
> +++ b/Documentation/boards/at91/microchip-at91sam9263-ek.rst
> @@ -123,10 +123,3 @@ This is the reset vector and exception vectors. Must be the very first in the fi
>  ``.text_bare_init*:``
>  Everything in this section, and , is checked at link time.
>  Size most be less than BAREBOX_MAX_BARE_INIT_SIZE / ARCH_BAREBOX_MAX_BARE_INIT_SIZE
> -
> -at91 specify the size of the two sections in exception vector 6 (see above),
> -if CONFIG_AT91_LOAD_BAREBOX_SRAM is defined.
> -I think this is because some at91 variants have only very limited SRAM size,
> -and we copy only a minimal part to the SRAM. The remaining part is then
> -executed in-place.
> -For at91sam9263 we have a large SRAM so there is room for the full bootstrap binary.
> diff --git a/arch/arm/boards/at91sam9261ek/defaultenv-at91sam9261ek/config b/arch/arm/boards/at91sam9261ek/defaultenv-at91sam9261ek/config
> index cb3e847f54..7d855779ca 100644
> --- a/arch/arm/boards/at91sam9261ek/defaultenv-at91sam9261ek/config
> +++ b/arch/arm/boards/at91sam9261ek/defaultenv-at91sam9261ek/config
> @@ -34,14 +34,8 @@ kernelimage=zImage
>  #kernelimage=Image.lzo
>  
>  nand_device=atmel_nand
> -if [ x$borebox_first_stage = x1 ]
> -then
> -	nand_parts="384k(barebox)ro,128k(bareboxenv),128k(bareboxenv2),128k(oftree),4M(kernel),120M(rootfs),-(data)"
> -	rootfs_mtdblock_nand=5
> -else
> -	nand_parts="128k(at91bootstrap),256k(barebox)ro,128k(bareboxenv),128k(bareboxenv2),128k(oftree),4M(kernel),120M(rootfs),-(data)"
> -	rootfs_mtdblock_nand=6
> -fi
> +nand_parts="128k(at91bootstrap),256k(barebox)ro,128k(bareboxenv),128k(bareboxenv2),128k(oftree),4M(kernel),120M(rootfs),-(data)"
> +rootfs_mtdblock_nand=6
>  
>  autoboot_timeout=3
>  
> diff --git a/arch/arm/boards/at91sam9261ek/init.c b/arch/arm/boards/at91sam9261ek/init.c
> index da305fe9ed..799466d655 100644
> --- a/arch/arm/boards/at91sam9261ek/init.c
> +++ b/arch/arm/boards/at91sam9261ek/init.c
> @@ -319,9 +319,6 @@ mem_initcall(at91sam9261ek_mem_init);
>  
>  static int at91sam9261ek_devices_init(void)
>  {
> -	u32 barebox_part_start;
> -	u32 barebox_part_size;
> -
>  	ek_add_device_nand();
>  	ek_add_device_dm9000();
>  	ek_add_device_udc();
> @@ -330,17 +327,8 @@ static int at91sam9261ek_devices_init(void)
>  	ek_add_device_lcdc();
>  	ek_add_device_spi();
>  
> -	if (IS_ENABLED(CONFIG_AT91_LOAD_BAREBOX_SRAM)) {
> -		barebox_part_start = 0;
> -		barebox_part_size = SZ_256K + SZ_128K;
> -		export_env_ull("borebox_first_stage", 1);
> -	} else {
> -		devfs_add_partition("nand0", 0x00000, SZ_128K, DEVFS_PARTITION_FIXED, "at91bootstrap_raw");
> -		barebox_part_start = SZ_128K;
> -		barebox_part_size = SZ_256K;
> -	}
> -	devfs_add_partition("nand0", barebox_part_start, barebox_part_size,
> -			    DEVFS_PARTITION_FIXED, "self_raw");
> +	devfs_add_partition("nand0", 0x00000, SZ_128K, DEVFS_PARTITION_FIXED, "at91bootstrap_raw");
> +	devfs_add_partition("nand0", SZ_128K, SZ_256K, DEVFS_PARTITION_FIXED, "self_raw");
>  	dev_add_bb_dev("self_raw", "self0");
>  	devfs_add_partition("nand0", SZ_256K + SZ_128K, SZ_128K, DEVFS_PARTITION_FIXED, "env_raw");
>  	dev_add_bb_dev("env_raw", "env0");
> diff --git a/arch/arm/configs/at91sam9261ek_first_stage_defconfig b/arch/arm/configs/at91sam9261ek_first_stage_defconfig
> deleted file mode 100644
> index 8e6065de34..0000000000
> --- a/arch/arm/configs/at91sam9261ek_first_stage_defconfig
> +++ /dev/null
> @@ -1,65 +0,0 @@
> -CONFIG_ARCH_AT91=y
> -CONFIG_ARCH_AT91SAM9261=y
> -CONFIG_AT91_LOAD_BAREBOX_SRAM=y
> -CONFIG_AEABI=y
> -CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
> -CONFIG_MMU=y
> -CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x27000
> -CONFIG_EXPERIMENTAL=y
> -CONFIG_MALLOC_TLSF=y
> -CONFIG_PROMPT="9261-EK:"
> -CONFIG_HUSH_FANCY_PROMPT=y
> -CONFIG_CMDLINE_EDITING=y
> -CONFIG_AUTO_COMPLETE=y
> -CONFIG_MENU=y
> -CONFIG_BOOTM_SHOW_TYPE=y
> -CONFIG_BOOTM_INITRD=y
> -CONFIG_CONSOLE_ACTIVATE_ALL=y
> -CONFIG_DEFAULT_ENVIRONMENT_GENERIC=y
> -# CONFIG_CMD_ARM_CPUINFO is not set
> -CONFIG_LONGHELP=y
> -CONFIG_CMD_MEMINFO=y
> -CONFIG_CMD_AT91_BOOT_TEST=y
> -# CONFIG_CMD_BOOTU is not set
> -CONFIG_CMD_GO=y
> -CONFIG_CMD_LOADB=y
> -CONFIG_CMD_RESET=y
> -CONFIG_CMD_UIMAGE=y
> -CONFIG_CMD_PARTITION=y
> -CONFIG_CMD_EXPORT=y
> -CONFIG_CMD_PRINTENV=y
> -CONFIG_CMD_SAVEENV=y
> -CONFIG_CMD_SLEEP=y
> -CONFIG_CMD_DHCP=y
> -CONFIG_CMD_PING=y
> -CONFIG_CMD_TFTP=y
> -CONFIG_CMD_ECHO_E=y
> -CONFIG_CMD_EDIT=y
> -CONFIG_CMD_LOGIN=y
> -CONFIG_CMD_MENU=y
> -CONFIG_CMD_MENU_MANAGEMENT=y
> -CONFIG_CMD_PASSWD=y
> -CONFIG_CMD_READLINE=y
> -CONFIG_CMD_TIMEOUT=y
> -CONFIG_CMD_FLASH=y
> -CONFIG_CMD_GPIO=y
> -CONFIG_CMD_LED=y
> -CONFIG_CMD_LED_TRIGGER=y
> -CONFIG_NET=y
> -CONFIG_NET_NFS=y
> -CONFIG_NET_RESOLV=y
> -CONFIG_DRIVER_NET_DM9K=y
> -CONFIG_DRIVER_SPI_ATMEL=y
> -CONFIG_MTD=y
> -# CONFIG_MTD_OOB_DEVICE is not set
> -CONFIG_MTD_DATAFLASH=y
> -CONFIG_NAND=y
> -CONFIG_NAND_ATMEL=y
> -CONFIG_USB_GADGET=y
> -CONFIG_USB_GADGET_DFU=y
> -CONFIG_USB_GADGET_SERIAL=y
> -CONFIG_LED=y
> -CONFIG_LED_GPIO=y
> -CONFIG_LED_TRIGGERS=y
> -CONFIG_KEYBOARD_GPIO=y
> -CONFIG_FS_TFTP=y
> diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig
> index 0b3a4ac44c..5bc5cacb7c 100644
> --- a/arch/arm/mach-at91/Kconfig
> +++ b/arch/arm/mach-at91/Kconfig
> @@ -152,9 +152,6 @@ config HAVE_NAND_ATMEL_BUSWIDTH_16
>  config HAVE_AT91_DATAFLASH_CARD
>  	bool
>  
> -config HAVE_AT91_LOAD_BAREBOX_SRAM
> -	bool
> -
>  comment "Atmel AT91 System-on-Chip"
>  
>  config SOC_AT91RM9200
> @@ -177,7 +174,6 @@ config SOC_AT91SAM9261
>  	bool
>  	select SOC_AT91SAM9
>  	select PINCTRL_AT91
> -	select HAVE_AT91_LOAD_BAREBOX_SRAM
>  	help
>  	  Select this if you are using one of Atmel's AT91SAM9261 or AT91SAM9G10 SoC.
>  
> @@ -185,7 +181,6 @@ config SOC_AT91SAM9263
>  	bool
>  	select SOC_AT91SAM9
>  	select HAS_MACB
> -	select HAVE_AT91_LOAD_BAREBOX_SRAM
>  	select PINCTRL_AT91
>  
>  config SOC_AT91SAM9G45
> @@ -707,9 +702,4 @@ config AT91_BOOTSTRAP
>  	depends on HAVE_AT91_BOOTSTRAP
>  	select BOOTSTRAP
>  
> -config AT91_LOAD_BAREBOX_SRAM
> -	bool "at91 load barebox in sram"
> -	depends on SHELL_NONE || HAVE_AT91_LOAD_BAREBOX_SRAM
> -	default y if SHELL_NONE
> -
>  endif
> diff --git a/include/mach/at91/barebox-arm.h b/include/mach/at91/barebox-arm.h
> index 652fd283a0..3a041b4557 100644
> --- a/include/mach/at91/barebox-arm.h
> +++ b/include/mach/at91/barebox-arm.h
> @@ -4,18 +4,11 @@
>  
>  #include <asm/barebox-arm.h>
>  #include <asm/common.h>
> +#include <linux/compiler.h>
>  #include <mach/at91/sama5d3.h>
>  #include <mach/at91/sama5d4.h>
>  #include <mach/at91/at91sam9261.h>
>  
> -#ifdef CONFIG_AT91_LOAD_BAREBOX_SRAM
> -#define AT91_EXV6	".word _barebox_image_size\n"
> -#else
> -#define AT91_EXV6	".word _barebox_bare_init_size\n"
> -#endif
> -
> -#include <linux/compiler.h>
> -
>  static __always_inline void __barebox_at91_head(void)
>  {
>  	__asm__ __volatile__ (
> @@ -27,7 +20,7 @@ static __always_inline void __barebox_at91_head(void)
>  		"1: b 1b\n"
>  		"1: b 1b\n"
>  		"1: b 1b\n"
> -		AT91_EXV6				/* image size to load by the bootrom */
> +		".word _barebox_image_size\n"		/* image size to load by the bootrom */
>  		"1: b 1b\n"
>  		"1: b 1b\n"
>  #endif
> -- 
> 2.39.1
> 
> 
> 

-- 
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-5555 |


From eagle.alexander923 at gmail.com  Fri Mar  7 03:21:45 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Fri,  7 Mar 2025 14:21:45 +0300
Subject: [PATCH] images: at91: Fix MAX_PBL_IMAGE_SIZE value for xload
Message-ID: <20250307112145.3679965-1-eagle.alexander923@gmail.com>

he maximum allowed code size read from external boot source
by SAMA5Dx bootrom is 64KB.
It seems that the last allowed address is currently used,
let's fix this value for the verification script.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 images/Makefile.at91 | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/images/Makefile.at91 b/images/Makefile.at91
index 06f8936893..81e7c22e8b 100644
--- a/images/Makefile.at91
+++ b/images/Makefile.at91
@@ -16,7 +16,7 @@ FILE_barebox-microchip-ksz9477-evb.img = start_sama5d3_xplained_ung8071.pblb
 image-$(CONFIG_MACH_MICROCHIP_KSZ9477_EVB) += barebox-microchip-ksz9477-evb.img
 
 pblb-$(CONFIG_MACH_MICROCHIP_KSZ9477_EVB) += start_sama5d3_xplained_ung8071_xload_mmc
-MAX_PBL_IMAGE_SIZE_start_sama5d3_xplained_ung8071_xload_mmc = 0xffff
+MAX_PBL_IMAGE_SIZE_start_sama5d3_xplained_ung8071_xload_mmc = 0x10000
 FILE_barebox-microchip-ksz9477-evb-xload-mmc.img = start_sama5d3_xplained_ung8071_xload_mmc.pblb
 image-$(CONFIG_MACH_MICROCHIP_KSZ9477_EVB) += barebox-microchip-ksz9477-evb-xload-mmc.img
 
@@ -25,7 +25,7 @@ FILE_barebox-microchip-sama5d3-eds.img = start_microchip_sama5d3_eds.pblb
 image-$(CONFIG_MACH_MICROCHIP_SAMA5D3_EDS) += barebox-microchip-sama5d3-eds.img
 
 pblb-$(CONFIG_MACH_MICROCHIP_SAMA5D3_EDS) += start_microchip_sama5d3_eds_xload_mmc
-MAX_PBL_IMAGE_SIZE_start_microchip_sama5d3_eds_xload_mmc = 0xffff
+MAX_PBL_IMAGE_SIZE_start_microchip_sama5d3_eds_xload_mmc = 0x10000
 FILE_barebox-microchip-sama5d3-eds-xload-mmc.img = start_microchip_sama5d3_eds_xload_mmc.pblb
 image-$(CONFIG_MACH_MICROCHIP_SAMA5D3_EDS) += barebox-microchip-sama5d3-eds-xload-mmc.img
 
@@ -34,7 +34,7 @@ FILE_barebox-sama5d3-xplained.img = start_sama5d3_xplained.pblb
 image-$(CONFIG_MACH_SAMA5D3_XPLAINED) += barebox-sama5d3-xplained.img
 
 pblb-$(CONFIG_MACH_SAMA5D3_XPLAINED) += start_sama5d3_xplained_xload_mmc
-MAX_PBL_IMAGE_SIZE_start_sama5d3_xplained_xload_mmc = 0xffff
+MAX_PBL_IMAGE_SIZE_start_sama5d3_xplained_xload_mmc = 0x10000
 FILE_barebox-sama5d3-xplained-xload-mmc.img = start_sama5d3_xplained_xload_mmc.pblb
 image-$(CONFIG_MACH_SAMA5D3_XPLAINED) += barebox-sama5d3-xplained-xload-mmc.img
 
@@ -43,7 +43,7 @@ FILE_barebox-sama5d27-som1-ek.img = start_sama5d27_som1_ek.pblb
 image-$(CONFIG_MACH_SAMA5D27_SOM1) += barebox-sama5d27-som1-ek.img
 
 pblb-$(CONFIG_MACH_SAMA5D27_SOM1) += start_sama5d27_som1_ek_xload_mmc
-MAX_PBL_IMAGE_SIZE_start_sama5d27_som1_ek_xload_mmc = 0xffff
+MAX_PBL_IMAGE_SIZE_start_sama5d27_som1_ek_xload_mmc = 0x10000
 FILE_barebox-sama5d27-som1-ek-xload-mmc.img = start_sama5d27_som1_ek_xload_mmc.pblb
 image-$(CONFIG_MACH_SAMA5D27_SOM1) += barebox-sama5d27-som1-ek-xload-mmc.img
 
-- 
2.38.2



From eagle.alexander923 at gmail.com  Fri Mar  7 03:47:39 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Fri,  7 Mar 2025 14:47:39 +0300
Subject: [PATCH] ARM: at91: Remove SAMA5D2 handling from sam9_smc driver
Message-ID: <20250307114739.3680956-1-eagle.alexander923@gmail.com>

SAMA5D2 SOC does not use sam9_smc driver.
Let's remove handling of this SOC from driver code.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/sam9_smc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/arm/mach-at91/sam9_smc.c b/arch/arm/mach-at91/sam9_smc.c
index ef58a0153a..257d7a07c3 100644
--- a/arch/arm/mach-at91/sam9_smc.c
+++ b/arch/arm/mach-at91/sam9_smc.c
@@ -14,8 +14,7 @@
 
 #define AT91_SAM9_SMC_CS_STRIDE		0x10
 #define AT91_SAMA5_SMC_CS_STRIDE	0x14
-#define AT91_SMC_CS_STRIDE	((at91_soc_initdata.type == AT91_SOC_SAMA5D2 \
-				 || at91_soc_initdata.type == AT91_SOC_SAMA5D3 \
+#define AT91_SMC_CS_STRIDE	((at91_soc_initdata.type == AT91_SOC_SAMA5D3 \
 				 || at91_soc_initdata.type == AT91_SOC_SAMA5D4) \
 				 ? AT91_SAMA5_SMC_CS_STRIDE : AT91_SAM9_SMC_CS_STRIDE)
 #define AT91_SMC_CS(id, n)	(smc_base_addr[id] + ((n) * AT91_SMC_CS_STRIDE))
@@ -28,7 +27,6 @@ static void sam9_smc_cs_write_mode(void __iomem *base,
 	void __iomem *mode_reg;
 
 	switch (at91_soc_initdata.type) {
-	case AT91_SOC_SAMA5D2:
 	case AT91_SOC_SAMA5D3:
 	case AT91_SOC_SAMA5D4:
 		mode_reg = base + AT91_SAMA5_SMC_MODE;
-- 
2.38.2



From dan.f.shelton at gmail.com  Fri Mar  7 06:40:00 2025
From: dan.f.shelton at gmail.com (Dan Shelton)
Date: Fri, 7 Mar 2025 15:40:00 +0100
Subject: Mount NFSv4.2 filesystem in barebox?
In-Reply-To: <20250305145543.30c3c8fa@erd003.prtnl>
References: <CANH4o6Njc3uHE=NbasRJrRr0W5B89R8MTM_BwGwab7t5fNWuaA@mail.gmail.com>
 <Z6yxUVTp0vGWqs7Q@pengutronix.de> <CANH4o6NRK2+ekNe_LrUaoAi8PVbi-MC3hWerv4g6F-WmXmyK5w@mail.gmail.com>
 <Z8GWfv4oIhB7CDSU@pengutronix.de> <3ba4d5f3-9679-4a32-a3e7-a8c958107df9@pengutronix.de>
 <CANH4o6PN3tJC+zLt_eLeKzJ6BVFnGo+vYFDF+9Hjp9x6oz626g@mail.gmail.com>
 <20250305123032.2b2c7768@erd003.prtnl> <7b73bca5-c1a2-4260-9c8a-510887ba4be8@pengutronix.de>
 <20250305145543.30c3c8fa@erd003.prtnl>
Message-ID: <CAAvCNcAYO7TK-i=vMLuJkhD0Ze0YpyXXfhvH94h+o0ssn_DXJg@mail.gmail.com>

On Wed, 5 Mar 2025 at 14:55, David Jander <david at protonic.nl> wrote:
>
>
> Hi Ahmad,
>
> On Wed, 5 Mar 2025 13:51:51 +0100
> Ahmad Fatoum <a.fatoum at pengutronix.de> wrote:
>
> > Hi David,
> >
> > On 05.03.25 12:30, David Jander wrote:
> > > On Tue, 4 Mar 2025 22:50:00 +0100
> > > Martin Wege <martin.l.wege at gmail.com> wrote:
> > >> So yes, you would have customers for NFSv4.1 support in barebox.
> > >
> > > Just wanted to chime in to amplify this a bit, since we are also using NFSv4.2
> > > netboot (though only TFTP in barebox for now):
> > >
> > > Your arguments are solid, and make a lot of sense. If you are going to replace
> > > more and more microcontroller based nodes with Linux capable SoCs, because it
> > > makes a lot of economical sense (hardware costs are very similar nowadays, and
> > > software development is 10x easier and cheaper on Linux than on a uC), you
> > > will end up inevitably with a lot of Linux nodes inside of a machine or
> > > industrial plant, where you previously had uC's. So, do you want to continue
> > > using 1970's tech (RS485/modbus) or 1980's tech (CAN) to communicate between all
> > > those nodes, or will you use Linux's native language (TCP/IP) which also
> > > immediately means another 10x reduction in software development costs of the
> > > networking part? If you choose the latter, you will also get significant HW
> > > cost savings basically for free if you also net-boot (via NFS and/or TFTP).
> > >
> > > In other words, why are we not already doing this?
> > >
> > > At least we are. We are starting to use Single Pair Ethernet almost everywhere
> > > where there were other field-busses involved traditionally. So we noticed that
> > > we end up with a lot of boards running Linux connected together via anything
> > > from 10Base-T1L to 1000Base-T1. Replace the eMMC chip on all but one of them
> > > with a cheap 2MiB SPI-NOR flash to load barebox and netboot from one single
> > > board running an NFSv4.2 (and TFTP) server serving the kernel and rootfs for
> > > all the others from a single eMMC, that can be updated with a single RAUC
> > > bundle guaranteeing consistent software and trivially easy updates on all
> > > nodes at once. Not to mention the benefit of trivial repairs because all
> > > boards are basically dumb and don't need to be flashed with software that
> > > matches the machine they are being replaced in, etc...
> >
> > Which I think is very cool. :-)
>
> Thanks :-)
>
> > > To be fair though, it isn't strictly needed for barebox to have NFS support
> > > for our use-case, since it suffices to load the kernel (and possibly an
> > > initramfs) via TFTP and mount the nfsroot from the kernel, but IMHO it is
> > > certainly valuable to have basic NFSv4.2 support in barebox. It would
> > > facilitate the use of just 1 protocol instead of 2.
> >
> > Ack.
> >
> > > I also agree that NFSv3
> > > support in that regard offers little value since you really don't want to base
> > > everything on this obsolete version with all of its limitations.
> > >
> > > But also a bit of caution to be mindful of: Cybersecurity. Of course barebox
> > > can be made to only boot signed fit images, but are there other potential
> > > attack vectors?
> >
> > We have been fuzzing the security critical boot path and issues were found
> > and fixed. Our network stack and NFS implementation are not currently part
> > of that. The documentation now spells that out and explicitly advises
> > against using any unsigned file system at all (whether networked or not)
> > to contain a signed FIT image:
> >
> > https://www.barebox.org/doc/latest/user/security.html#avoiding-use-of-file-systems
> >
> > As we gain more confidence in the implementation (or rather import mptcp and focus
> > on fuzzing that), this will change, but as things stand now, it's is not advisable
> > to do network boot of signed images.
>
> Aha. Interesting. I suppose you mean network boot of signed images from
> something like NFS (a complex filesystem) as opposed to TFTP (which is more
> akin to a raw partition in terms of simplicity of the protocol)? Or is TFTP
> already outside of the security comfort zone of barebox?

TFTP is outside the comfort zone of almost every enterprise IT. Most
of Intel&Win&co label it as "legacy" for a reason

>
> > > What if the NFS server needs to be secured with with GSS and
> > > kerberos? Barebox possibly won't be able to access it unless it also supports
> > > that.
> >
> > Yes. I think HTTP(S) support may be a better investment of time, even
> > if it means having to use two protocols still.
>
> I agree that if secure-boot is involved, the net-boot solution for barebox
> should be the most simple protocol possible so that we always have some
> transport implementation that can be hardened with the lowest effort, whether
> that is TFTP or HTTP(S).

1. HTTPS is not always viable, in case of firewalls which unpack, add
headers or content, and then repack HTTPS traffic. Given that kind of
problem HTTPS is often unuseable. Plus, many managements no longer
trusts HTTPS, because it has become a jack of all trades, and a gaping
security hole for all trades.
2. Booting or getting a boot image via HTTPS is basically not a
standard, NFSv4 is at least IETF+RFC+already in use. barebox is just
late in that game

> It surely won't be NFSv4.2+kerberos or anything like
> that. Still, there are likely a lot of cases, where a physical access barrier
> is secure enough, and bare NFS can be used, so let's not immediately shoot
> down the idea of having an NFSv4 client in barebox ;-)

There is NFSv4+TLS, which should be pretty easy to implement, because
it is just sticking TLS in front of libtirpc

Dan
-- 
Dan Shelton - Cluster Specialist Win/Lin/Bsd


From m.felsch at pengutronix.de  Mon Mar 10 04:36:26 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Mon, 10 Mar 2025 12:36:26 +0100
Subject: [PATCH master] i.MX: HAB: fix i.MX8MP field-return fuse
Message-ID: <20250310113626.2241630-1-m.felsch@pengutronix.de>

Current tests showed that fusing just the single field-return bit(0) on
i.MX8MP SoCs brick the device.

All i.MX8M SoCs have a single field-return bit except for the i.MX8MP
which requires a pattern. The pattern is not documented but was
discussed here [1] and the final u-boot commit [2] added the support
accordingly.

This commit is based on the outcome of [1, 2].

[1] https://lore.kernel.org/all/20240621130626.729666-1-paul.geurts at prodrive-technologies.com/
[2] https://github.com/u-boot/u-boot/blob/v2025.01/arch/arm/mach-imx/hab.c#L35

Tested-by: Johannes Schneider <johannes.schneider at leica-geosystems.com>
Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
 drivers/hab/hab.c                | 12 +++++++++++-
 include/mach/imx/ocotp-fusemap.h |  1 +
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/hab/hab.c b/drivers/hab/hab.c
index 73d470be131e..74ba4a48557c 100644
--- a/drivers/hab/hab.c
+++ b/drivers/hab/hab.c
@@ -252,6 +252,12 @@ static int imx8m_hab_revoke_key_ocotp(unsigned key_idx)
 	return ret;
 }
 
+/*
+ * The fuse pattern for i.MX8M Plus is 0x28001401, but bit 2 is already set from factory.
+ * This means when field return is set, the fuse word value reads 0x28001405
+ */
+#define MX8MP_FIELD_RETURN_PATTERN	0x28001401
+
 static int imx8m_hab_field_return_ocotp(void)
 {
 	int ret;
@@ -264,7 +270,11 @@ static int imx8m_hab_field_return_ocotp(void)
 	if (ret == 1)
 		return -EINVAL;
 
-	ret = imx_ocotp_write_field(MX8M_OCOTP_FIELD_RETURN, 1);
+	if (cpu_is_mx8mp())
+		ret = imx_ocotp_write_field(MX8MP_OCOTP_FIELD_RETURN,
+					    MX8MP_FIELD_RETURN_PATTERN);
+	else
+		ret = imx_ocotp_write_field(MX8M_OCOTP_FIELD_RETURN, 1);
 
 	return ret;
 }
diff --git a/include/mach/imx/ocotp-fusemap.h b/include/mach/imx/ocotp-fusemap.h
index 37f1ee8298c2..587fe8b15eab 100644
--- a/include/mach/imx/ocotp-fusemap.h
+++ b/include/mach/imx/ocotp-fusemap.h
@@ -68,6 +68,7 @@
 #define MX8MP_OCOTP_ROM_NO_LOG		(OCOTP_WORD(0x480) | OCOTP_BIT(22) | OCOTP_WIDTH(1))
 #define MX8M_OCOTP_RECOVERY_SDMMC_BOOT_DIS	(OCOTP_WORD(0x490) | OCOTP_BIT(23) | OCOTP_WIDTH(1))
 #define MX8M_OCOTP_FIELD_RETURN		(OCOTP_WORD(0x630) | OCOTP_BIT(0) | OCOTP_WIDTH(1))
+#define MX8MP_OCOTP_FIELD_RETURN	(OCOTP_WORD(0x630) | OCOTP_BIT(0) | OCOTP_WIDTH(32))
 #define MX8M_OCOTP_SRK_REVOKE		(OCOTP_WORD(0x670) | OCOTP_BIT(0) | OCOTP_WIDTH(4))
 
 #endif /* __MACH_IMX_OCOTP_FUSEMAP_H */
-- 
2.39.5



From a.fatoum at pengutronix.de  Mon Mar 10 06:31:40 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 10 Mar 2025 14:31:40 +0100
Subject: [PATCH master] i.MX: HAB: fix i.MX8MP field-return fuse
In-Reply-To: <20250310113626.2241630-1-m.felsch@pengutronix.de>
References: <20250310113626.2241630-1-m.felsch@pengutronix.de>
Message-ID: <2770e761-a192-437f-bc82-128519c04d18@pengutronix.de>

Hello Marco,

On 3/10/25 12:36, Marco Felsch wrote:
> Current tests showed that fusing just the single field-return bit(0) on
> i.MX8MP SoCs brick the device.

So such a device is bricked permanently with no way to upload
a bootloader again to fuse the remainder of the bits?

Interesting thing to not document :/

Cheers,
Ahmad

> 
> All i.MX8M SoCs have a single field-return bit except for the i.MX8MP
> which requires a pattern. The pattern is not documented but was
> discussed here [1] and the final u-boot commit [2] added the support
> accordingly.
> 
> This commit is based on the outcome of [1, 2].
> 
> [1] https://lore.kernel.org/all/20240621130626.729666-1-paul.geurts at prodrive-technologies.com/
> [2] https://github.com/u-boot/u-boot/blob/v2025.01/arch/arm/mach-imx/hab.c#L35
> 
> Tested-by: Johannes Schneider <johannes.schneider at leica-geosystems.com>
> Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> ---
>  drivers/hab/hab.c                | 12 +++++++++++-
>  include/mach/imx/ocotp-fusemap.h |  1 +
>  2 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hab/hab.c b/drivers/hab/hab.c
> index 73d470be131e..74ba4a48557c 100644
> --- a/drivers/hab/hab.c
> +++ b/drivers/hab/hab.c
> @@ -252,6 +252,12 @@ static int imx8m_hab_revoke_key_ocotp(unsigned key_idx)
>  	return ret;
>  }
>  
> +/*
> + * The fuse pattern for i.MX8M Plus is 0x28001401, but bit 2 is already set from factory.
> + * This means when field return is set, the fuse word value reads 0x28001405
> + */
> +#define MX8MP_FIELD_RETURN_PATTERN	0x28001401
> +
>  static int imx8m_hab_field_return_ocotp(void)
>  {
>  	int ret;
> @@ -264,7 +270,11 @@ static int imx8m_hab_field_return_ocotp(void)
>  	if (ret == 1)
>  		return -EINVAL;
>  
> -	ret = imx_ocotp_write_field(MX8M_OCOTP_FIELD_RETURN, 1);
> +	if (cpu_is_mx8mp())
> +		ret = imx_ocotp_write_field(MX8MP_OCOTP_FIELD_RETURN,
> +					    MX8MP_FIELD_RETURN_PATTERN);
> +	else
> +		ret = imx_ocotp_write_field(MX8M_OCOTP_FIELD_RETURN, 1);
>  
>  	return ret;
>  }
> diff --git a/include/mach/imx/ocotp-fusemap.h b/include/mach/imx/ocotp-fusemap.h
> index 37f1ee8298c2..587fe8b15eab 100644
> --- a/include/mach/imx/ocotp-fusemap.h
> +++ b/include/mach/imx/ocotp-fusemap.h
> @@ -68,6 +68,7 @@
>  #define MX8MP_OCOTP_ROM_NO_LOG		(OCOTP_WORD(0x480) | OCOTP_BIT(22) | OCOTP_WIDTH(1))
>  #define MX8M_OCOTP_RECOVERY_SDMMC_BOOT_DIS	(OCOTP_WORD(0x490) | OCOTP_BIT(23) | OCOTP_WIDTH(1))
>  #define MX8M_OCOTP_FIELD_RETURN		(OCOTP_WORD(0x630) | OCOTP_BIT(0) | OCOTP_WIDTH(1))
> +#define MX8MP_OCOTP_FIELD_RETURN	(OCOTP_WORD(0x630) | OCOTP_BIT(0) | OCOTP_WIDTH(32))
>  #define MX8M_OCOTP_SRK_REVOKE		(OCOTP_WORD(0x670) | OCOTP_BIT(0) | OCOTP_WIDTH(4))
>  
>  #endif /* __MACH_IMX_OCOTP_FUSEMAP_H */



From m.felsch at pengutronix.de  Mon Mar 10 06:51:54 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Mon, 10 Mar 2025 14:51:54 +0100
Subject: [PATCH master] i.MX: HAB: fix i.MX8MP field-return fuse
In-Reply-To: <2770e761-a192-437f-bc82-128519c04d18@pengutronix.de>
References: <20250310113626.2241630-1-m.felsch@pengutronix.de>
 <2770e761-a192-437f-bc82-128519c04d18@pengutronix.de>
Message-ID: <20250310135154.bw6awpkjydcf32zp@pengutronix.de>

On 25-03-10, Ahmad Fatoum wrote:
> Hello Marco,
> 
> On 3/10/25 12:36, Marco Felsch wrote:
> > Current tests showed that fusing just the single field-return bit(0) on
> > i.MX8MP SoCs brick the device.
> 
> So such a device is bricked permanently with no way to upload
> a bootloader again to fuse the remainder of the bits?

Yes, as written here [3], the device isnow in "device asserts security
violation" state, what ever this means but maybe: "I refuse to power
up".

[3] https://lore.kernel.org/all/a9ebece9-4ab6-4bca-bebe-985e0bf95278 at oss.nxp.com/

> Interesting thing to not document :/

Took us 2 devices to figure it out :/ We also don't know why NXP doesn't
care and don't update the (S)TRM since the v1 of [3] is 9months old.

Regards,
  Marco


From johannes.schneider at leica-geosystems.com  Mon Mar 10 09:36:37 2025
From: johannes.schneider at leica-geosystems.com (SCHNEIDER Johannes)
Date: Mon, 10 Mar 2025 16:36:37 +0000
Subject: [PATCH master] i.MX: HAB: fix i.MX8MP field-return fuse
In-Reply-To: <20250310135154.bw6awpkjydcf32zp@pengutronix.de>
References: <20250310113626.2241630-1-m.felsch@pengutronix.de>
 <2770e761-a192-437f-bc82-128519c04d18@pengutronix.de>
 <20250310135154.bw6awpkjydcf32zp@pengutronix.de>
Message-ID: <AM8PR06MB7521AE5766581B704671ECB8BCD62@AM8PR06MB7521.eurprd06.prod.outlook.com>

Hoi,

>
> On 25-03-10, Ahmad Fatoum wrote:
> > Hello Marco,
> >
> > On 3/10/25 12:36, Marco Felsch wrote:
> > > Current tests showed that fusing just the single field-return bit(0) on
> > > i.MX8MP SoCs brick the device.
> >
> > So such a device is bricked permanently with no way to upload
> > a bootloader again to fuse the remainder of the bits?
>
> Yes, as written here [3], the device isnow in "device asserts security
> violation" state, what ever this means but maybe: "I refuse to power
> up".

The imx does consume power, but does "nothing", e.g. does not boot from emmc,
say anything on the hardware serial or even enumerate the usb side.
And pulling the boot-mode pins to serial-download mode does also nothing,
even though the serial-dl is usually the one last and common fallback.

>
> [3] https://lore.kernel.org/all/a9ebece9-4ab6-4bca-bebe-985e0bf95278 at oss.nxp.com/
>
> > Interesting thing to not document :/
>
> Took us 2 devices to figure it out :/ We also don't know why NXP doesn't
> care and don't update the (S)TRM since the v1 of [3] is 9months old.
>
> Regards,
>   Marco
>

gru?
Johannes


From m.felsch at pengutronix.de  Mon Mar 10 10:40:58 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Mon, 10 Mar 2025 18:40:58 +0100
Subject: [PATCH 00/13] am625: support secure loading of full barebox
In-Reply-To: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
Message-ID: <20250310174058.t3rsxws6syxz2rqp@pengutronix.de>

Hi Sascha,

On 25-02-28, Sascha Hauer wrote:
> On K3 SoCs only a small barebox is loaded by the ROM into SRAM. This
> barebox then loads the full barebox from SD/eMMC or USB DFU. In a secure
> boot environment the full barebox must be authenticated. This series
> implements two ways for accomplishing this.
> 
> First way is to utilize the ROM API to authenticate images. The other
> way is to compile a secure hash into the first stage binary and check
> if the full barebox image matches the hash. Using the ROM API means
> different first stage and second stage images can be combined whereas
> hashing binds specific builds together avoiding mix and match attacks.

before having a closer look on your patchset, do we really want to have
the 2nd case to be available? If we really want the 2nd case to be
available we should bound it to CONFIG_INSECURE (if not already done).

Regards,
  Marco

> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
> Sascha Hauer (13):
>       firmware: always generate sha256sum
>       firmware: add function to verify next image
>       ARM: k3: r5: drop loading of separate binaries
>       ARM: k3: r5: add proper error handling
>       fip: rework fip_image_open()
>       fip: fix wrong function call
>       fip: add function to calculate a sha256 over FIP image
>       ARM: am625: support hash verification of full barebox
>       ARM: k3: add support for authenticating images against the ROM API
>       ARM: k3: r5: delete fip image when it can't be opened
>       ARM: k3: r5: Allow to authenticate next image by ROM API
>       scripts/k3img: remove temporary files
>       scripts: add k3sign
> 
>  arch/arm/mach-k3/Kconfig  |  15 ++++
>  arch/arm/mach-k3/common.c |  99 ++++++++++++++++++++++
>  arch/arm/mach-k3/r5.c     | 206 +++++++++++++++++++++++++---------------------
>  firmware/Kconfig          |  23 ++++++
>  firmware/Makefile         |   8 +-
>  include/fiptool.h         |   3 +
>  include/firmware.h        |  28 +++++++
>  include/mach/k3/common.h  |   1 +
>  lib/fip.c                 | 101 ++++++++++++++---------
>  scripts/k3img             |   9 +-
>  scripts/k3sign            | 126 ++++++++++++++++++++++++++++
>  11 files changed, 478 insertions(+), 141 deletions(-)
> ---
> base-commit: 748ba0627681797b01a94be1b3f879ed2e52a361
> change-id: 20250228-am625-secure-49301f641738
> 
> Best regards,
> -- 
> Sascha Hauer <s.hauer at pengutronix.de>
> 
> 
> 


From m.felsch at pengutronix.de  Mon Mar 10 11:37:33 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Mon, 10 Mar 2025 19:37:33 +0100
Subject: [PATCH 02/13] firmware: add function to verify next image
In-Reply-To: <20250228-am625-secure-v1-2-4002488ff5ed@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250228-am625-secure-v1-2-4002488ff5ed@pengutronix.de>
Message-ID: <20250310183733.gykbqq25cznu72it@pengutronix.de>

On 25-02-28, Sascha Hauer wrote:
> Some SoCs use a startup sequence that includes multiple stages where a
> full barebox is loaded by an early small barebox that fits into the
> SoC's SRAM. This is commonly referred to as xload. In a secure boot
> environment it's necessary to load only trusted barebox images. One
> way to accomplish this is to compile a sha256 into the first stage
> barebox and to verify the full barebox against this hash.
> 
> This patch adds the generic parts for this. The full barebox binary
> can be put into the first stage build as a firmware file. The firmware
> itself won't be used, only the hash is compiled into the image. SoC
> code can then check the full barebox image against the hash. As this
> requires SoC code to check the hash, the option is hidden behind
> CONFIG_HAVE_FIRMWARE_VERIFY_NEXT_IMAGE. SoC code can select this option
> when it implements the required hash checking.
> 
> It's worth noting that using a hash for verification has one advantage
> over cryptographicaly signing followup images: It ties first stage
> and full barebox stages together effectively avoiding mix-and-match
> attacks.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  firmware/Kconfig   | 23 +++++++++++++++++++++++
>  firmware/Makefile  |  2 ++
>  include/firmware.h | 28 ++++++++++++++++++++++++++++
>  3 files changed, 53 insertions(+)
> 
> diff --git a/firmware/Kconfig b/firmware/Kconfig
> index ba005976c5..bdb71321bc 100644
> --- a/firmware/Kconfig
> +++ b/firmware/Kconfig
> @@ -108,4 +108,27 @@ config FIRMWARE_LS1028A_ATF
>  config FIRMWARE_LS1046A_ATF
>  	bool
>  
> +config HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
> +	bool
> +
> +config FIRMWARE_VERIFY_NEXT_IMAGE
> +	depends on HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
> +	bool "verify next image to load"
> +	help
> +	  The boot process of some SoCs uses multiple stages where the first stage is
> +	  a stripped down barebox loaded by the SoC's ROM and the next state is a full
> +	  barebox loaded by the first stage. In a trusted boot scenario the next stage
> +	  has to be verified by the first stage,
> +
> +	  This option allows to specify the next image to be loaded. Put the next stage
> +	  image to firmware/next-image.bin. The image itself is not used, but a sha256
> +	  hash of the image will be generated and compiled into the first stage which
> +	  can be used to verify the next stage.
> +
> +	  Note that this option only enabled generation of the sha256 hash. Loading and
> +	  starting the next stage is highly SoC dependent and it's the SoC code's
> +	  responsibility to actually verify the hash and to only start successfully
> +	  verified images. The function to check the next stage image hash is
> +	  firmware_next_image_verify(), make sure your SoC code uses it.
> +
>  endmenu
> diff --git a/firmware/Makefile b/firmware/Makefile
> index 095d6f0e31..67fd898890 100644
> --- a/firmware/Makefile
> +++ b/firmware/Makefile
> @@ -34,6 +34,8 @@ pbl-firmware-$(CONFIG_ARCH_RK3588) += rk3588-bl32.bin
>  pbl-firmware-$(CONFIG_ARCH_RK3399) += rk3399-bl32.bin
>  endif
>  
> +firmware-$(CONFIG_FIRMWARE_NEXT_IMAGE) += next-image.bin

Why can't we use the fw-external here?

> +
>  firmware-$(CONFIG_DRIVER_NET_FSL_FMAN) += fsl_fman_ucode_ls1046_r1.0_106_4_18.bin
>  
>  fw-external-$(CONFIG_FIRMWARE_LS1028A_ATF) += ls1028a-bl31.bin
> diff --git a/include/firmware.h b/include/firmware.h
> index d7feae1371..7225b55e4f 100644
> --- a/include/firmware.h
> +++ b/include/firmware.h
> @@ -13,6 +13,8 @@
>  #include <debug_ll.h>
>  #include <linux/kernel.h>
>  #include <asm/sections.h>
> +#include <crypto/sha.h>
> +#include <crypto.h>
>  
>  struct firmware {
>  	size_t size;
> @@ -113,4 +115,30 @@ static inline void firmware_ext_verify(const void *data_start, size_t data_size,
>  #define get_builtin_firmware_ext(name, base, start, size)		\
>  	__get_builtin_firmware(name, (long)base - (long)_text, start, size)
>  
> +static inline int firmware_next_image_verify(const void *hash_start, size_t hash_size, bool verbose)
> +{
> +	extern char _fw_next_image_bin_sha_start[];
> +	int ret;
> +
> +	if (!IS_ENABLED(CONFIG_FIRMWARE_NEXT_IMAGE))
> +		return -EINVAL;
> +
> +	if (hash_size != SHA256_DIGEST_SIZE)
> +		return -EINVAL;
> +
> +	ret = crypto_memneq(hash_start, _fw_next_image_bin_sha_start, hash_size);

If we don't check the runtime sha256 of next_image an attacker could
replace next_image and keep the builtin sha256sum and we wouldn't
recognize it, or do I miss something?

Regards,
  Marco

> +
> +	if (verbose) {
> +		if (ret) {
> +			pr_err("next image hash mismatch!\n");
> +			pr_err("expected: sha256=%*phN\n", hash_size, _fw_next_image_bin_sha_start);
> +			pr_err("found:    sha256=%*phN\n", hash_size, hash_start);
> +		} else {
> +			pr_info("hash sha256=%*phN OK\n", hash_size, _fw_next_image_bin_sha_start);
> +		}
> +	}
> +
> +	return ret;
> +}
> +
>  #endif /* FIRMWARE_H */
> 
> -- 
> 2.39.5
> 
> 
> 


From m.felsch at pengutronix.de  Mon Mar 10 11:44:56 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Mon, 10 Mar 2025 19:44:56 +0100
Subject: [PATCH 03/13] ARM: k3: r5: drop loading of separate binaries
In-Reply-To: <20250228-am625-secure-v1-3-4002488ff5ed@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250228-am625-secure-v1-3-4002488ff5ed@pengutronix.de>
Message-ID: <20250310184456.i4tpauvbwb6uqwuk@pengutronix.de>

On 25-02-28, Sascha Hauer wrote:
> For starting the A52 cores we need TFA, OP-TEE, barebox and ti-dm
	             ^
		     3
> binaries. These can be loaded as separate files from SD/eMMC/DFU or
> alternatively combined into a single FIP image.
> FIP images are convenient to handle, they can easily be generated on the
> command line and fiptool also has support for replacing blobs in images.
> This makes handling of separate binaries rather unnecessary and support
> for it only makes the loading code more complex. Drop it and make FIP
> images the only option which also faciliates integrating of secure boot.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  arch/arm/mach-k3/r5.c | 70 +--------------------------------------------------
>  1 file changed, 1 insertion(+), 69 deletions(-)
> 
> diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
> index ced1eb2856..2418e9ae73 100644
> --- a/arch/arm/mach-k3/r5.c
> +++ b/arch/arm/mach-k3/r5.c
> @@ -288,50 +288,15 @@ static void do_dfu(void)
>  	struct usbgadget_funcs funcs = {};
>  	int ret;
>  	struct stat s;
> -	ssize_t size;
>  
>  	funcs.flags |= USBGADGET_DFU;
> -	funcs.dfu_opts = "/optee.bin(optee)c,"
> -			 "/bl31.bin(tfa)c,"
> -			 "/ti-dm.bin(ti-dm)c,"
> -			 "/barebox.bin(barebox)cs,"
> -			 "/fip.img(fip)cs";
> +	funcs.dfu_opts = "/fip.img(fip)cs";
>  
>  	ret = usbgadget_prepare_register(&funcs);
>  	if (ret)
>  		goto err;
>  
>  	while (1) {
> -		if (!have_bl32) {
> -			size = read_file_into_buf("/optee.bin", BL32_ADDRESS, SZ_32M);
> -			if (size > 0) {
> -				printf("Downloaded OP-TEE\n");
> -				have_bl32 = true;
> -			}
> -		}
> -
> -		if (!have_bl31) {
> -			size = read_file_into_buf("/bl31.bin", BL31_ADDRESS, SZ_32M);
> -			if (size > 0) {
> -				printf("Downloaded TF-A\n");
> -				have_bl31 = true;
> -			}
> -		}
> -
> -		if (!k3_ti_dm) {
> -			ret = read_file_2("/ti-dm.bin", &size, &k3_ti_dm, FILESIZE_MAX);
> -			if (!ret) {
> -				printf("Downloaded TI-DM\n");
> -			}
> -		}
> -
> -		size = read_file_into_buf("/barebox.bin", BAREBOX_ADDRESS, SZ_32M);
> -		if (size > 0) {
> -			have_bl33 = true;
> -			printf("Downloaded barebox image, DFU done\n");
> -			break;
> -		}
> -
>  		ret = stat("/fip.img", &s);
>  		if (!ret) {
>  			printf("Downloaded FIP image, DFU done\n");
> @@ -352,45 +317,12 @@ static void do_dfu(void)
>  
>  static int load_images(void)
>  {
> -	ssize_t size;
>  	int err;
>  
>  	err = load_fip("/boot/k3.fip", 0);

Since load_fip() is the only call we could remove the entire function
and call load_fip() directly from k3_r5_start_image().

Regards,
  Marco

>  	if (!err)
>  		return 0;
>  
> -	size = read_file_into_buf("/boot/optee.bin", BL32_ADDRESS, SZ_32M);
> -	if (size < 0) {
> -		if (size != -ENOENT) {
> -			pr_err("Cannot load optee.bin: %pe\n", ERR_PTR(size));
> -			return size;
> -		}
> -		pr_info("optee.bin not found, continue without\n");
> -	} else {
> -		pr_debug("Loaded optee.bin (size %u) to 0x%p\n", size, BL32_ADDRESS);
> -	}
> -
> -	size = read_file_into_buf("/boot/barebox.bin", BAREBOX_ADDRESS, SZ_32M);
> -	if (size < 0) {
> -		pr_err("Cannot load barebox.bin: %pe\n", ERR_PTR(size));
> -		return size;
> -	}
> -	pr_debug("Loaded barebox.bin (size %u) to 0x%p\n", size, BAREBOX_ADDRESS);
> -
> -	size = read_file_into_buf("/boot/bl31.bin", BL31_ADDRESS, SZ_32M);
> -	if (size < 0) {
> -		pr_err("Cannot load bl31.bin: %pe\n", ERR_PTR(size));
> -		return size;
> -	}
> -	pr_debug("Loaded bl31.bin (size %u) to 0x%p\n", size, BL31_ADDRESS);
> -
> -	err = read_file_2("/boot/ti-dm.bin", &size, &k3_ti_dm, FILESIZE_MAX);
> -	if (err) {
> -		pr_err("Cannot load ti-dm.bin: %pe\n", ERR_PTR(err));
> -		return err;
> -	}
> -	pr_debug("Loaded ti-dm.bin (size %u)\n", size);
> -
>  	return 0;
>  }
>  
> 
> -- 
> 2.39.5
> 
> 
> 


From m.felsch at pengutronix.de  Mon Mar 10 11:52:17 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Mon, 10 Mar 2025 19:52:17 +0100
Subject: [PATCH 04/13] ARM: k3: r5: add proper error handling
In-Reply-To: <20250228-am625-secure-v1-4-4002488ff5ed@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250228-am625-secure-v1-4-4002488ff5ed@pengutronix.de>
Message-ID: <20250310185217.4bmple2ygkrcl3gp@pengutronix.de>

On 25-02-28, Sascha Hauer wrote:
> Add missing error handling in the image loading code. Properly check for
> errors and panic when mandatory binaries are missing instead of blindly
> continuing.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  arch/arm/mach-k3/r5.c | 57 ++++++++++++++++++++++++++++-----------------------
>  1 file changed, 31 insertions(+), 26 deletions(-)
> 
> diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
> index 2418e9ae73..e12c888afa 100644
> --- a/arch/arm/mach-k3/r5.c
> +++ b/arch/arm/mach-k3/r5.c
> @@ -283,7 +283,7 @@ static int load_fip(const char *filename, off_t offset)
>  	return 0;
>  }
>  
> -static void do_dfu(void)
> +static int do_dfu(void)
>  {
>  	struct usbgadget_funcs funcs = {};
>  	int ret;
> @@ -293,37 +293,24 @@ static void do_dfu(void)
>  	funcs.dfu_opts = "/fip.img(fip)cs";
>  
>  	ret = usbgadget_prepare_register(&funcs);
> -	if (ret)
> -		goto err;
> +	if (ret) {
> +		pr_err("DFU failed with: %pe\n", ERR_PTR(ret));
> +		return ret;
> +	}
>  
>  	while (1) {
>  		ret = stat("/fip.img", &s);
>  		if (!ret) {
>  			printf("Downloaded FIP image, DFU done\n");
> -			load_fip("/fip.img", 0);
> -			break;
> +			ret = load_fip("/fip.img", 0);
> +			if (!ret)
> +				return 0;
>  		}
>  
>  		command_slice_release();
>  		mdelay(50);
>  		command_slice_acquire();
>  	};
> -
> -	return;
> -
> -err:
> -	pr_err("DFU failed with: %pe\n", ERR_PTR(ret));
> -}
> -
> -static int load_images(void)
> -{
> -	int err;
> -
> -	err = load_fip("/boot/k3.fip", 0);
> -	if (!err)
> -		return 0;
> -
> -	return 0;
>  }

Removing load_images should go into patch-3.

>  
>  static int load_fip_emmc(void)
> @@ -332,6 +319,7 @@ static int load_fip_emmc(void)
>  	struct mci *mci;
>  	char *fname;
>  	const char *mmcdev = "mmc0";
> +	int ret;

Nit: Sometimes you do use ret, sometimes err. I would like to align it
if possible.

Rest LGTM.

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>

Regards,
  Marco

>  
>  	device_detect_by_name(mmcdev);
>  
> @@ -348,11 +336,11 @@ static int load_fip_emmc(void)
>  
>  	fname = xasprintf("/dev/%s.boot%d", mmcdev, bootpart - 1);
>  
> -	load_fip(fname, K3_EMMC_BOOTPART_TIBOOT3_BIN_SIZE);
> +	ret = load_fip(fname, K3_EMMC_BOOTPART_TIBOOT3_BIN_SIZE);
>  
>  	free(fname);
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static int k3_r5_start_image(void)
> @@ -365,11 +353,28 @@ static int k3_r5_start_image(void)
>  	struct rproc *arm64_rproc;
>  
>  	if (IS_ENABLED(CONFIG_USB_GADGET_DFU) && bootsource_get() == BOOTSOURCE_SERIAL)
> -		do_dfu();
> +		err = do_dfu();
>  	else if (k3_boot_is_emmc())
> -		load_fip_emmc();
> +		err = load_fip_emmc();
>  	else
> -		load_images();
> +		err = load_fip("/boot/k3.fip", 0);
> +
> +	if (err) {
> +		pr_crit("Unable to load FIP image\n");
> +		panic("Stop booting\n");
> +	}
> +
> +	if (!have_bl31)
> +		panic("No TFA found in FIP image\n");
> +
> +	if (!have_bl32)
> +		pr_info("No OP-TEE found. Continuing without\n");
> +
> +	if (!have_bl33)
> +		panic("No bl33 found in FIP image\n");
> +
> +	if (!k3_ti_dm)
> +		panic("No ti-dm binary found\n");
>  
>  	ti_sci = ti_sci_get_handle(NULL);
>  	if (IS_ERR(ti_sci))
> 
> -- 
> 2.39.5
> 
> 
> 


From m.felsch at pengutronix.de  Mon Mar 10 12:22:26 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Mon, 10 Mar 2025 20:22:26 +0100
Subject: [PATCH 08/13] ARM: am625: support hash verification of full
 barebox
In-Reply-To: <20250228-am625-secure-v1-8-4002488ff5ed@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250228-am625-secure-v1-8-4002488ff5ed@pengutronix.de>
Message-ID: <20250310192226.x7g2jq6vf5rx4c7c@pengutronix.de>

On 25-02-28, Sascha Hauer wrote:
> This implements the necessary SoC code to check the full barebox against
> a sha256 compiled into the first stage barebox.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  arch/arm/mach-k3/Kconfig |  1 +
>  arch/arm/mach-k3/r5.c    | 14 ++++++++++++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
> index 50919dc7e3..561ad1dac4 100644
> --- a/arch/arm/mach-k3/Kconfig
> +++ b/arch/arm/mach-k3/Kconfig
> @@ -16,6 +16,7 @@ config MACH_K3_CORTEX_R5
>  	select ELF
>  	select K3_DDRSS
>  	select FIP
> +	select HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
>  	depends on 32BIT
>  	select ARM_USE_COMPRESSED_DTB
>  	default y
> diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
> index e12c888afa..cb52ff364d 100644
> --- a/arch/arm/mach-k3/r5.c
> +++ b/arch/arm/mach-k3/r5.c
> @@ -248,6 +248,8 @@ static int load_fip(const char *filename, off_t offset)
>  {
>  	struct fip_state *fip;
>  	struct fip_image_desc *desc;
> +	unsigned char shasum[SHA256_DIGEST_SIZE];
> +	int ret;
>  
>  	fip = fip_image_open(filename, offset);
>  	if (IS_ERR(fip)) {
> @@ -255,6 +257,18 @@ static int load_fip(const char *filename, off_t offset)
>  		return PTR_ERR(fip);
>  	}
>  
> +	if (IS_ENABLED(CONFIG_FIRMWARE_VERIFY_NEXT_IMAGE)) {
> +		ret = fip_sha256(fip, shasum);
> +		if (ret) {
> +			pr_err("Cannot calc fip sha256: %pe\n", ERR_PTR(ret));
> +			return ret;
> +		}
> +
> +		ret = firmware_next_image_verify(shasum, SHA256_DIGEST_SIZE, true);
> +		if (ret)
> +			return ret;

Albeit it would involve way more effort, I would like to see that the
FIP image format does have support for signatures within their "struct
image_desc" for each image.
This way it would be far easier for us to verify each image separately
and in a common way. Also it wouldn't require to rebuild the "r5"
tiboot3.bin to include the the updated sha256sum each time.

I do see why we can't use the externa-firmware mechanism now but I
wouldn't call it firmware_next_image_verify(). Maybe limit the scope to
fip and extent it later or remove/deprecate it once we managed to add
signatures to the FIP format.
Also the shasum size seems like the user would have a choice to choose
other sha-sums which he hasn't, therefore I would drop it.

Regards,
  Marco

> +	}
> +
>  	fip_for_each_desc(fip, desc) {
>  		struct fip_toc_entry *toc_entry = &desc->image->toc_e;
>  
> 
> -- 
> 2.39.5
> 
> 
> 


From m.felsch at pengutronix.de  Mon Mar 10 12:26:01 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Mon, 10 Mar 2025 20:26:01 +0100
Subject: [PATCH 11/13] ARM: k3: r5: Allow to authenticate next image by
 ROM API
In-Reply-To: <20250228-am625-secure-v1-11-4002488ff5ed@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250228-am625-secure-v1-11-4002488ff5ed@pengutronix.de>
Message-ID: <20250310192601.7nzsencbk3borvqm@pengutronix.de>

On 25-02-28, Sascha Hauer wrote:
> This adds the Kconfig option CONFIG_ARCH_K3_AUTHENTICATE_IMAGE. When
> enabled, the full barebox image will only be started when it can be
> authenticated using the ROM API.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  arch/arm/mach-k3/Kconfig |  7 ++++++
>  arch/arm/mach-k3/r5.c    | 64 +++++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 70 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
> index 37d5155577..e93e3154c8 100644
> --- a/arch/arm/mach-k3/Kconfig
> +++ b/arch/arm/mach-k3/Kconfig
> @@ -37,6 +37,13 @@ config MACH_BEAGLEPLAY
>  	help
>  	  Say Y here if you are using a TI AM62x based BeaglePlay board
>  
> +config ARCH_K3_AUTHENTICATE_IMAGE
> +	bool "Force authentication of FIP image against ROM API"
> +	help
> +	  By enabling this option the FIP image loaded by the first stage
> +	  will be authenticated against the K3 ROM API. Images which fail
> +	  to authenticate will not be started.

The ROM is checking only the sha sum or does the ROM also have some kind
of signature-checking (pub/priv keys requried)?

Regards,
  Marco


> +
>  config ARCH_K3_COMMAND_AUTHENTICATE
>  	bool "k3_authenticate_image command"
>  	depends on COMMAND_SUPPORT
> diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
> index c8a91e2597..d0093a3be7 100644
> --- a/arch/arm/mach-k3/r5.c
> +++ b/arch/arm/mach-k3/r5.c
> @@ -244,6 +244,64 @@ static uuid_t uuid_ti_dm_fw = UUID_TI_DM_FW;
>  static uuid_t uuid_bl33 = UUID_NON_TRUSTED_FIRMWARE_BL33;
>  static uuid_t uuid_bl32 = UUID_SECURE_PAYLOAD_BL32;
>  
> +static struct fip_state *fip_image_load_auth(const char *filename, size_t offset)
> +{
> +	struct fip_state *fip = NULL;
> +	int fd;
> +	unsigned int maxsize = SZ_4M;
> +	size_t size;
> +	void *buf = NULL;
> +	int ret;
> +
> +	fd = open(filename, O_RDONLY);
> +	if (fd < 0)
> +		return ERR_PTR(-errno);
> +
> +	if (offset) {
> +		loff_t pos;
> +		pos = lseek(fd, offset, SEEK_SET);
> +		if (pos < 0) {
> +			ret = -errno;
> +			goto err;
> +		}
> +	}
> +
> +	buf = xzalloc(maxsize);
> +
> +	/*
> +	 * There is no easy way to determine the size of the certificates the ROM
> +	 * takes as images, so the best we can do here is to assume a maximum size
> +	 * and load this.
> +	 */
> +	ret = read_full(fd, buf, maxsize);
> +	if (ret < 0)
> +		goto err;
> +
> +	size = maxsize;
> +
> +	ret = k3_authenticate_image(&buf, &size);
> +	if (ret) {
> +		pr_err("Failed to authenticate %s\n", filename);
> +		goto err;
> +	}
> +
> +	fip = fip_new();
> +	ret = fip_parse_buf(fip, buf, size, NULL);
> +	if (ret)
> +		goto err;
> +
> +	close(fd);
> +
> +	return fip;
> +err:
> +	if (fip)
> +		fip_free(fip);
> +	close(fd);
> +	free(buf);
> +
> +	return ERR_PTR(ret);
> +}
> +
>  static int load_fip(const char *filename, off_t offset)
>  {
>  	struct fip_state *fip;
> @@ -251,7 +309,11 @@ static int load_fip(const char *filename, off_t offset)
>  	unsigned char shasum[SHA256_DIGEST_SIZE];
>  	int ret;
>  
> -	fip = fip_image_open(filename, offset);
> +	if (IS_ENABLED(CONFIG_ARCH_K3_AUTHENTICATE_IMAGE))
> +		fip = fip_image_load_auth(filename, offset);
> +	else
> +		fip = fip_image_open(filename, offset);
> +
>  	if (IS_ERR(fip)) {
>  		pr_err("Cannot open FIP image: %pe\n", fip);
>  		return PTR_ERR(fip);
> 
> -- 
> 2.39.5
> 
> 
> 


From s.hauer at pengutronix.de  Tue Mar 11 00:35:03 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 08:35:03 +0100
Subject: [PATCH 02/13] firmware: add function to verify next image
In-Reply-To: <20250310183733.gykbqq25cznu72it@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250228-am625-secure-v1-2-4002488ff5ed@pengutronix.de>
 <20250310183733.gykbqq25cznu72it@pengutronix.de>
Message-ID: <Z8_npyCenE9m3oli@pengutronix.de>

On Mon, Mar 10, 2025 at 07:37:33PM +0100, Marco Felsch wrote:
> On 25-02-28, Sascha Hauer wrote:
> > Some SoCs use a startup sequence that includes multiple stages where a
> > full barebox is loaded by an early small barebox that fits into the
> > SoC's SRAM. This is commonly referred to as xload. In a secure boot
> > environment it's necessary to load only trusted barebox images. One
> > way to accomplish this is to compile a sha256 into the first stage
> > barebox and to verify the full barebox against this hash.
> > 
> > This patch adds the generic parts for this. The full barebox binary
> > can be put into the first stage build as a firmware file. The firmware
> > itself won't be used, only the hash is compiled into the image. SoC
> > code can then check the full barebox image against the hash. As this
> > requires SoC code to check the hash, the option is hidden behind
> > CONFIG_HAVE_FIRMWARE_VERIFY_NEXT_IMAGE. SoC code can select this option
> > when it implements the required hash checking.
> > 
> > It's worth noting that using a hash for verification has one advantage
> > over cryptographicaly signing followup images: It ties first stage
> > and full barebox stages together effectively avoiding mix-and-match
> > attacks.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  firmware/Kconfig   | 23 +++++++++++++++++++++++
> >  firmware/Makefile  |  2 ++
> >  include/firmware.h | 28 ++++++++++++++++++++++++++++
> >  3 files changed, 53 insertions(+)
> > 
> > diff --git a/firmware/Kconfig b/firmware/Kconfig
> > index ba005976c5..bdb71321bc 100644
> > --- a/firmware/Kconfig
> > +++ b/firmware/Kconfig
> > @@ -108,4 +108,27 @@ config FIRMWARE_LS1028A_ATF
> >  config FIRMWARE_LS1046A_ATF
> >  	bool
> >  
> > +config HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
> > +	bool
> > +
> > +config FIRMWARE_VERIFY_NEXT_IMAGE
> > +	depends on HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
> > +	bool "verify next image to load"
> > +	help
> > +	  The boot process of some SoCs uses multiple stages where the first stage is
> > +	  a stripped down barebox loaded by the SoC's ROM and the next state is a full
> > +	  barebox loaded by the first stage. In a trusted boot scenario the next stage
> > +	  has to be verified by the first stage,
> > +
> > +	  This option allows to specify the next image to be loaded. Put the next stage
> > +	  image to firmware/next-image.bin. The image itself is not used, but a sha256
> > +	  hash of the image will be generated and compiled into the first stage which
> > +	  can be used to verify the next stage.
> > +
> > +	  Note that this option only enabled generation of the sha256 hash. Loading and
> > +	  starting the next stage is highly SoC dependent and it's the SoC code's
> > +	  responsibility to actually verify the hash and to only start successfully
> > +	  verified images. The function to check the next stage image hash is
> > +	  firmware_next_image_verify(), make sure your SoC code uses it.
> > +
> >  endmenu
> > diff --git a/firmware/Makefile b/firmware/Makefile
> > index 095d6f0e31..67fd898890 100644
> > --- a/firmware/Makefile
> > +++ b/firmware/Makefile
> > @@ -34,6 +34,8 @@ pbl-firmware-$(CONFIG_ARCH_RK3588) += rk3588-bl32.bin
> >  pbl-firmware-$(CONFIG_ARCH_RK3399) += rk3399-bl32.bin
> >  endif
> >  
> > +firmware-$(CONFIG_FIRMWARE_NEXT_IMAGE) += next-image.bin
> 
> Why can't we use the fw-external here?

With fw-external the hash will end up in the PBL. I need it in barebox
proper.

> 
> > +
> >  firmware-$(CONFIG_DRIVER_NET_FSL_FMAN) += fsl_fman_ucode_ls1046_r1.0_106_4_18.bin
> >  
> >  fw-external-$(CONFIG_FIRMWARE_LS1028A_ATF) += ls1028a-bl31.bin
> > diff --git a/include/firmware.h b/include/firmware.h
> > index d7feae1371..7225b55e4f 100644
> > --- a/include/firmware.h
> > +++ b/include/firmware.h
> > @@ -13,6 +13,8 @@
> >  #include <debug_ll.h>
> >  #include <linux/kernel.h>
> >  #include <asm/sections.h>
> > +#include <crypto/sha.h>
> > +#include <crypto.h>
> >  
> >  struct firmware {
> >  	size_t size;
> > @@ -113,4 +115,30 @@ static inline void firmware_ext_verify(const void *data_start, size_t data_size,
> >  #define get_builtin_firmware_ext(name, base, start, size)		\
> >  	__get_builtin_firmware(name, (long)base - (long)_text, start, size)
> >  
> > +static inline int firmware_next_image_verify(const void *hash_start, size_t hash_size, bool verbose)
> > +{
> > +	extern char _fw_next_image_bin_sha_start[];
> > +	int ret;
> > +
> > +	if (!IS_ENABLED(CONFIG_FIRMWARE_NEXT_IMAGE))
> > +		return -EINVAL;
> > +
> > +	if (hash_size != SHA256_DIGEST_SIZE)
> > +		return -EINVAL;
> > +
> > +	ret = crypto_memneq(hash_start, _fw_next_image_bin_sha_start, hash_size);
> 
> If we don't check the runtime sha256 of next_image an attacker could
> replace next_image and keep the builtin sha256sum and we wouldn't
> recognize it, or do I miss something?

Not sure I can follow you. The sha256 of the next image is passed to
this function as argument and compared against the compiled in hash.

If you miss the call to actually calculate the hash: The caller of this
function calls it as I consider this being board dependent. Background
it that at least in a previous version I calculated the hash while
reading in the image, I never had a contiguous buffer where I could
calculate the hash over.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Tue Mar 11 00:53:54 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 08:53:54 +0100
Subject: [PATCH 08/13] ARM: am625: support hash verification of full
 barebox
In-Reply-To: <20250310192226.x7g2jq6vf5rx4c7c@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250228-am625-secure-v1-8-4002488ff5ed@pengutronix.de>
 <20250310192226.x7g2jq6vf5rx4c7c@pengutronix.de>
Message-ID: <Z8_sEu7Ta1RuJwk4@pengutronix.de>

On Mon, Mar 10, 2025 at 08:22:26PM +0100, Marco Felsch wrote:
> On 25-02-28, Sascha Hauer wrote:
> > This implements the necessary SoC code to check the full barebox against
> > a sha256 compiled into the first stage barebox.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  arch/arm/mach-k3/Kconfig |  1 +
> >  arch/arm/mach-k3/r5.c    | 14 ++++++++++++++
> >  2 files changed, 15 insertions(+)
> > 
> > diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
> > index 50919dc7e3..561ad1dac4 100644
> > --- a/arch/arm/mach-k3/Kconfig
> > +++ b/arch/arm/mach-k3/Kconfig
> > @@ -16,6 +16,7 @@ config MACH_K3_CORTEX_R5
> >  	select ELF
> >  	select K3_DDRSS
> >  	select FIP
> > +	select HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
> >  	depends on 32BIT
> >  	select ARM_USE_COMPRESSED_DTB
> >  	default y
> > diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
> > index e12c888afa..cb52ff364d 100644
> > --- a/arch/arm/mach-k3/r5.c
> > +++ b/arch/arm/mach-k3/r5.c
> > @@ -248,6 +248,8 @@ static int load_fip(const char *filename, off_t offset)
> >  {
> >  	struct fip_state *fip;
> >  	struct fip_image_desc *desc;
> > +	unsigned char shasum[SHA256_DIGEST_SIZE];
> > +	int ret;
> >  
> >  	fip = fip_image_open(filename, offset);
> >  	if (IS_ERR(fip)) {
> > @@ -255,6 +257,18 @@ static int load_fip(const char *filename, off_t offset)
> >  		return PTR_ERR(fip);
> >  	}
> >  
> > +	if (IS_ENABLED(CONFIG_FIRMWARE_VERIFY_NEXT_IMAGE)) {
> > +		ret = fip_sha256(fip, shasum);
> > +		if (ret) {
> > +			pr_err("Cannot calc fip sha256: %pe\n", ERR_PTR(ret));
> > +			return ret;
> > +		}
> > +
> > +		ret = firmware_next_image_verify(shasum, SHA256_DIGEST_SIZE, true);
> > +		if (ret)
> > +			return ret;
> 
> Albeit it would involve way more effort, I would like to see that the
> FIP image format does have support for signatures within their "struct
> image_desc" for each image.
> This way it would be far easier for us to verify each image separately
> and in a common way. Also it wouldn't require to rebuild the "r5"
> tiboot3.bin to include the the updated sha256sum each time.

Having to rebuild the tiboot3.bin for the updated sha256sum is not a
downside in this case, but actually the feature I wanted to implement.

Using a hash avoids mix-and-match attacks between different 1st stage
images combined with different 2nd stage images.

So yes, using the FIP image signing mechanisms would be nice to have,
but doesn't meet my goal.

> Also the shasum size seems like the user would have a choice to choose
> other sha-sums which he hasn't, therefore I would drop it.

ok.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Tue Mar 11 00:54:58 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 08:54:58 +0100
Subject: [PATCH 11/13] ARM: k3: r5: Allow to authenticate next image by
 ROM API
In-Reply-To: <20250310192601.7nzsencbk3borvqm@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250228-am625-secure-v1-11-4002488ff5ed@pengutronix.de>
 <20250310192601.7nzsencbk3borvqm@pengutronix.de>
Message-ID: <Z8_sUo3vWUp8YtA8@pengutronix.de>

On Mon, Mar 10, 2025 at 08:26:01PM +0100, Marco Felsch wrote:
> On 25-02-28, Sascha Hauer wrote:
> > This adds the Kconfig option CONFIG_ARCH_K3_AUTHENTICATE_IMAGE. When
> > enabled, the full barebox image will only be started when it can be
> > authenticated using the ROM API.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  arch/arm/mach-k3/Kconfig |  7 ++++++
> >  arch/arm/mach-k3/r5.c    | 64 +++++++++++++++++++++++++++++++++++++++++++++++-
> >  2 files changed, 70 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
> > index 37d5155577..e93e3154c8 100644
> > --- a/arch/arm/mach-k3/Kconfig
> > +++ b/arch/arm/mach-k3/Kconfig
> > @@ -37,6 +37,13 @@ config MACH_BEAGLEPLAY
> >  	help
> >  	  Say Y here if you are using a TI AM62x based BeaglePlay board
> >  
> > +config ARCH_K3_AUTHENTICATE_IMAGE
> > +	bool "Force authentication of FIP image against ROM API"
> > +	help
> > +	  By enabling this option the FIP image loaded by the first stage
> > +	  will be authenticated against the K3 ROM API. Images which fail
> > +	  to authenticate will not be started.
> 
> The ROM is checking only the sha sum or does the ROM also have some kind
> of signature-checking (pub/priv keys requried)?

The ROM cheks against signatures

Sascha


-- 
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-5555 |


From s.hauer at pengutronix.de  Tue Mar 11 01:09:25 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 09:09:25 +0100
Subject: [PATCH] bootm: let BOOTM_OPTIONAL_SIGNED_IMAGES depend on BOOTM
Message-ID: <20250311080925.1439519-1-s.hauer@pengutronix.de>

The purpose of BOOTM_OPTIONAL_SIGNED_IMAGES is to select
HAS_INSECURE_DEFAULTS, but it should only do so when BOOTM
support is actually compiled in.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/Kconfig b/common/Kconfig
index 8a051a29e7..12026b8232 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -768,6 +768,7 @@ config BOOTM_FORCE_SIGNED_IMAGES
 config BOOTM_OPTIONAL_SIGNED_IMAGES
 	def_bool !BOOTM_FORCE_SIGNED_IMAGES
 	select HAS_INSECURE_DEFAULTS
+	depends on BOOTM
 	help
 	  With this option enabled, barebox can be reconfigured to not verify signed
 	  images. It's the board code's responsibility to call the function
-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 01:12:51 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 09:12:51 +0100
Subject: [PATCH 00/13] am625: support secure loading of full barebox
In-Reply-To: <20250310174058.t3rsxws6syxz2rqp@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250310174058.t3rsxws6syxz2rqp@pengutronix.de>
Message-ID: <Z8_wg9fWKN4s0vrd@pengutronix.de>

On Mon, Mar 10, 2025 at 06:40:58PM +0100, Marco Felsch wrote:
> Hi Sascha,
> 
> On 25-02-28, Sascha Hauer wrote:
> > On K3 SoCs only a small barebox is loaded by the ROM into SRAM. This
> > barebox then loads the full barebox from SD/eMMC or USB DFU. In a secure
> > boot environment the full barebox must be authenticated. This series
> > implements two ways for accomplishing this.
> > 
> > First way is to utilize the ROM API to authenticate images. The other
> > way is to compile a secure hash into the first stage binary and check
> > if the full barebox image matches the hash. Using the ROM API means
> > different first stage and second stage images can be combined whereas
> > hashing binds specific builds together avoiding mix and match attacks.
> 
> before having a closer look on your patchset, do we really want to have
> the 2nd case to be available?

Yes, as explained to avoid mix-and-match attacks.

> If we really want the 2nd case to be
> available we should bound it to CONFIG_INSECURE (if not already done).

Ok, will do.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Tue Mar 11 01:24:00 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 09:24:00 +0100
Subject: [PATCH 04/13] ARM: k3: r5: add proper error handling
In-Reply-To: <20250310185217.4bmple2ygkrcl3gp@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250228-am625-secure-v1-4-4002488ff5ed@pengutronix.de>
 <20250310185217.4bmple2ygkrcl3gp@pengutronix.de>
Message-ID: <Z8_zIC2f7n3-_sVn@pengutronix.de>

On Mon, Mar 10, 2025 at 07:52:17PM +0100, Marco Felsch wrote:
> On 25-02-28, Sascha Hauer wrote:
> > Add missing error handling in the image loading code. Properly check for
> > errors and panic when mandatory binaries are missing instead of blindly
> > continuing.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  arch/arm/mach-k3/r5.c | 57 ++++++++++++++++++++++++++++-----------------------
> >  1 file changed, 31 insertions(+), 26 deletions(-)
> > 
> > diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
> > index 2418e9ae73..e12c888afa 100644
> > --- a/arch/arm/mach-k3/r5.c
> > +++ b/arch/arm/mach-k3/r5.c
> > @@ -283,7 +283,7 @@ static int load_fip(const char *filename, off_t offset)
> >  	return 0;
> >  }
> >  
> > -static void do_dfu(void)
> > +static int do_dfu(void)
> >  {
> >  	struct usbgadget_funcs funcs = {};
> >  	int ret;
> > @@ -293,37 +293,24 @@ static void do_dfu(void)
> >  	funcs.dfu_opts = "/fip.img(fip)cs";
> >  
> >  	ret = usbgadget_prepare_register(&funcs);
> > -	if (ret)
> > -		goto err;
> > +	if (ret) {
> > +		pr_err("DFU failed with: %pe\n", ERR_PTR(ret));
> > +		return ret;
> > +	}
> >  
> >  	while (1) {
> >  		ret = stat("/fip.img", &s);
> >  		if (!ret) {
> >  			printf("Downloaded FIP image, DFU done\n");
> > -			load_fip("/fip.img", 0);
> > -			break;
> > +			ret = load_fip("/fip.img", 0);
> > +			if (!ret)
> > +				return 0;
> >  		}
> >  
> >  		command_slice_release();
> >  		mdelay(50);
> >  		command_slice_acquire();
> >  	};
> > -
> > -	return;
> > -
> > -err:
> > -	pr_err("DFU failed with: %pe\n", ERR_PTR(ret));
> > -}
> > -
> > -static int load_images(void)
> > -{
> > -	int err;
> > -
> > -	err = load_fip("/boot/k3.fip", 0);
> > -	if (!err)
> > -		return 0;
> > -
> > -	return 0;
> >  }
> 
> Removing load_images should go into patch-3.

I deliberately did it in this patch because load_images already does
error checking, but up to now the return value of load_images() wasn't
checked. By doing it like you suggest I would either end up calling
load_fip() without checking the error, or I would introduce an
incomplete error checking in k3_r5_start_image() where the return value
of load_fip() is checked, but not the return values of do_dfu and
load_fip_emmc().

> >  static int load_fip_emmc(void)
> > @@ -332,6 +319,7 @@ static int load_fip_emmc(void)
> >  	struct mci *mci;
> >  	char *fname;
> >  	const char *mmcdev = "mmc0";
> > +	int ret;
> 
> Nit: Sometimes you do use ret, sometimes err. I would like to align it
> if possible.

Changed to 'ret' consistently.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Tue Mar 11 01:31:54 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 09:31:54 +0100
Subject: [PATCH] ARM: at91: remove obsolete defconfig
In-Reply-To: <20250307075927.973504-1-s.hauer@pengutronix.de>
References: <20250307075927.973504-1-s.hauer@pengutronix.de>
Message-ID: <174168191451.1446554.5728074660413908810.b4-ty@pengutronix.de>


On Fri, 07 Mar 2025 08:59:27 +0100, Sascha Hauer wrote:
> sama5d3xek_defconfig is obsolete. The sama5d3xek is now covered by
> at91_multi_defconfig. It currently falls back for building for
> the AT91RM9200-EK instead of the sama5d3xek, so just drop it.
> 
> 

Applied, thanks!

[1/1] ARM: at91: remove obsolete defconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=2341f810eab6 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar 11 01:32:34 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 09:32:34 +0100
Subject: [PATCH RFC] at91: Remove AT91_LOAD_BAREBOX_SRAM option
In-Reply-To: <20250306053920.7544-1-eagle.alexander923@gmail.com>
References: <20250306053920.7544-1-eagle.alexander923@gmail.com>
Message-ID: <174168195400.1447026.10008747582568559829.b4-ty@pengutronix.de>


On Thu, 06 Mar 2025 08:39:20 +0300, Alexander Shiyan wrote:
> This patch removes the AT91_LOAD_BAREBOX_SRAM option.
> The option was introduced over 12 years ago and is now misleading.
> The functionality of loading a stage into SRAM can now be implemented
> via PBL in a low-level board-specific call.
> For boot sources (other than MMC), BOOTRom expects the size of the
> image to boot into SRAM in exception vector 6, so let's fix
> barebox-arm-head to always use the correct value here.
> 
> [...]

Applied, thanks!

[1/1] at91: Remove AT91_LOAD_BAREBOX_SRAM option
      https://git.pengutronix.de/cgit/barebox/commit/?id=e9a01d3498f5 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar 11 01:33:15 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 09:33:15 +0100
Subject: [PATCH] images: at91: Fix MAX_PBL_IMAGE_SIZE value for xload
In-Reply-To: <20250307112145.3679965-1-eagle.alexander923@gmail.com>
References: <20250307112145.3679965-1-eagle.alexander923@gmail.com>
Message-ID: <174168199552.1447139.9217676884843884297.b4-ty@pengutronix.de>


On Fri, 07 Mar 2025 14:21:45 +0300, Alexander Shiyan wrote:
> he maximum allowed code size read from external boot source
> by SAMA5Dx bootrom is 64KB.
> It seems that the last allowed address is currently used,
> let's fix this value for the verification script.
> 
> 

Applied, thanks!

[1/1] images: at91: Fix MAX_PBL_IMAGE_SIZE value for xload
      https://git.pengutronix.de/cgit/barebox/commit/?id=2d8bf1e1a678 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From m.felsch at pengutronix.de  Tue Mar 11 01:48:33 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 11 Mar 2025 09:48:33 +0100
Subject: [PATCH 00/13] am625: support secure loading of full barebox
In-Reply-To: <Z8_wg9fWKN4s0vrd@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250310174058.t3rsxws6syxz2rqp@pengutronix.de>
 <Z8_wg9fWKN4s0vrd@pengutronix.de>
Message-ID: <20250311084833.5h32rntkvk6ggi5i@pengutronix.de>

On 25-03-11, Sascha Hauer wrote:
> On Mon, Mar 10, 2025 at 06:40:58PM +0100, Marco Felsch wrote:
> > Hi Sascha,
> > 
> > On 25-02-28, Sascha Hauer wrote:
> > > On K3 SoCs only a small barebox is loaded by the ROM into SRAM. This
> > > barebox then loads the full barebox from SD/eMMC or USB DFU. In a secure
> > > boot environment the full barebox must be authenticated. This series
> > > implements two ways for accomplishing this.
> > > 
> > > First way is to utilize the ROM API to authenticate images. The other
> > > way is to compile a secure hash into the first stage binary and check
> > > if the full barebox image matches the hash. Using the ROM API means
> > > different first stage and second stage images can be combined whereas
> > > hashing binds specific builds together avoiding mix and match attacks.
> > 
> > before having a closer look on your patchset, do we really want to have
> > the 2nd case to be available?
> 
> Yes, as explained to avoid mix-and-match attacks.

Argh.. sorry, I meant the first case, the ROM API one. If the ROM API
allows mix-and-match attacks, we need to mark it as INSECURE. Sorry for
the confusion.

Regards,
  Marco

> > If we really want the 2nd case to be
> > available we should bound it to CONFIG_INSECURE (if not already done).
> 
> Ok, will do.
> 
> Sascha
> 
> -- 
> 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-5555 |
> 


From s.hauer at pengutronix.de  Tue Mar 11 01:49:09 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 09:49:09 +0100
Subject: [PATCH] ARM: boards: Add support for phyBOARD-Segin i.MX 93
In-Reply-To: <20250304-phyboard-segin-imx93-v1-1-8677740a79de@pengutronix.de>
References: <20250304-phyboard-segin-imx93-v1-1-8677740a79de@pengutronix.de>
Message-ID: <174168294990.1453253.10483274415863259109.b4-ty@pengutronix.de>


On Tue, 04 Mar 2025 17:24:15 +0100, Jonas Rebmann wrote:
> This patch adds support for the phyBOARD-Segin i.MX 93 and the phyCORE
> i.MX 93 SoM it is based upon.
> 
> Note that support is only provided for the standard configuration
> featuring 1GB RAM as testing was only possible on that variant and only
> the single-configuration lpddr4_timing.c as initially committed to
> u-boot in 7c1f8ce3956 worked.
> 
> [...]

Applied, thanks!

[1/1] ARM: boards: Add support for phyBOARD-Segin i.MX 93
      https://git.pengutronix.de/cgit/barebox/commit/?id=41c53621ac0b (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar 11 01:49:50 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 09:49:50 +0100
Subject: [PATCH] ARM: boards: Add support for phyBOARD-Segin i.MX 93
In-Reply-To: <93d21a21-02f8-45c1-91bf-034c4ed08d30@pengutronix.de>
References: <20250304-phyboard-segin-imx93-v1-1-8677740a79de@pengutronix.de>
 <93d21a21-02f8-45c1-91bf-034c4ed08d30@pengutronix.de>
Message-ID: <Z8_5LlB26xDUjSr4@pengutronix.de>

On Wed, Mar 05, 2025 at 03:02:25PM +0100, Bastian Krause wrote:
> Hi Jonas,
> 
> On 3/4/25 5:24 PM, Jonas Rebmann wrote:
> > This patch adds support for the phyBOARD-Segin i.MX 93 and the phyCORE
> > i.MX 93 SoM it is based upon.
> > 
> > Note that support is only provided for the standard configuration
> > featuring 1GB RAM as testing was only possible on that variant and only
> > the single-configuration lpddr4_timing.c as initially committed to
> > u-boot in 7c1f8ce3956 worked.
> > 
> > The 1GB configuration from later revisions results in a freeze during
> > dram setup.
> > 
> > The following functionality has been tested:
> >   - barebox starts via imxusbloader, tftp and emmc
> >   - both ethertnet interfaces work
> >   - barebox_update to emmc
> >   - boot kernel via network
> >   - USB OTG
> >   - USB mass storage on USB Host Port
> >   - reset
> > 
> > Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
> > ---
> >   arch/arm/boards/Makefile                           |    1 +
> >   arch/arm/boards/phytec-phycore-imx93/Makefile      |    2 +
> >   arch/arm/boards/phytec-phycore-imx93/board.c       |   56 +
> >   arch/arm/boards/phytec-phycore-imx93/lowlevel.c    |   60 +
> >   .../boards/phytec-phycore-imx93/lpddr4_timing.c    | 1546 ++++++++++++++++++++
> >   arch/arm/configs/imx_v8_defconfig                  |    1 +
> >   arch/arm/configs/multi_v8_defconfig                |    1 +
> >   arch/arm/dts/Makefile                              |    1 +
> >   arch/arm/dts/imx93-phyboard-segin-downstream.dtsi  |  269 ++++
> >   arch/arm/dts/imx93-phyboard-segin.dts              |   28 +
> >   arch/arm/mach-imx/Kconfig                          |    9 +
> >   images/Makefile.imx                                |    4 +
> >   12 files changed, 1978 insertions(+)
> > 
> > diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
> > index c6104d04329774655712db5aaf6df671fd74142e..1e67b304f1855df2c32305638c3d9029ed0994c6 100644
> > --- a/arch/arm/boards/Makefile
> > +++ b/arch/arm/boards/Makefile
> > @@ -78,6 +78,7 @@ obj-$(CONFIG_MACH_PCM038)			+= phytec-phycore-imx27/
> >   obj-$(CONFIG_MACH_PHYTEC_SOM_AM335X)		+= phytec-som-am335x/
> >   obj-$(CONFIG_MACH_PHYTEC_SOM_IMX6)		+= phytec-som-imx6/
> >   obj-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX7)		+= phytec-phycore-imx7/
> > +obj-$(CONFIG_MACH_PHYTEC_PHYCORE_IMX93)		+= phytec-phycore-imx93/
> >   obj-$(CONFIG_MACH_PHYTEC_PHYCORE_STM32MP1)	+= phytec-phycore-stm32mp1/
> >   obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MM)		+= phytec-som-imx8mm/
> >   obj-$(CONFIG_MACH_PHYTEC_SOM_IMX8MQ)		+= phytec-som-imx8mq/
> > diff --git a/arch/arm/boards/phytec-phycore-imx93/Makefile b/arch/arm/boards/phytec-phycore-imx93/Makefile
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..ae29bb9249e62cb649e21e580559383fa9d18386
> > --- /dev/null
> > +++ b/arch/arm/boards/phytec-phycore-imx93/Makefile
> > @@ -0,0 +1,2 @@
> > +lwl-y += lowlevel.o lpddr4_timing.o
> > +obj-y += board.o
> > diff --git a/arch/arm/boards/phytec-phycore-imx93/board.c b/arch/arm/boards/phytec-phycore-imx93/board.c
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..149248ca654624826d0e8f6fe0f1f42c2747e248
> > --- /dev/null
> > +++ b/arch/arm/boards/phytec-phycore-imx93/board.c
> > @@ -0,0 +1,56 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +#define pr_fmt(fmt) "phyCORE imx93: " fmt
> > +
> > +#include <common.h>
> > +#include <init.h>
> > +#include <linux/kernel.h>
> > +#include <environment.h>
> > +#include <mfd/pca9450.h>
> > +#include <deep-probe.h>
> > +#include <mach/imx/bbu.h>
> > +#include <linux/pinctrl/consumer.h>
> > +
> > +static void phycore_imx93_init_pmic(struct regmap *map)
> > +{
> > +	/* set WDOG_B_CFG to cold reset */
> > +	regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
> > +}
> > +
> > +static int phycore_imx93_probe(struct device *dev)
> > +{
> > +	struct device_node *np;
> > +
> > +	pca9450_register_init_callback(phycore_imx93_init_pmic);
> > +
> > +	/*
> > +	 * The phy on the EQOS has its MDIO lines connected to the FEC. The phy
> > +	 * registers can only be successfully read when the EQOS pinctrl setup
> > +	 * has been done. The phys on the FEC MDIO bus are probed during the
> > +	 * FEC driver probe, so do the EQOS pinctrl setup here to make sure it's
> > +	 * done before the FEC probes.
> > +	 */
> > +	np = of_find_compatible_node(dev->of_node, NULL, "nxp,imx93-dwmac-eqos");
> > +	BUG_ON(!np);
> > +	of_pinctrl_select_state_default(np);
> > +
> > +	imx9_bbu_internal_mmcboot_register_handler("eMMC", "/dev/mmc0", 0);
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct of_device_id phycore_imx93_of_match[] = {
> > +	{
> > +		.compatible = "phytec,imx93-phyboard-segin",
> > +	},
> > +	{ /* sentinel */ },
> > +};
> > +
> > +static struct driver phycore_imx93_board_driver = {
> > +	.name = "board-phycore_imx93",
> > +	.probe = phycore_imx93_probe,
> > +	.of_compatible = phycore_imx93_of_match,
> > +};
> > +coredevice_platform_driver(phycore_imx93_board_driver);
> > +
> > +BAREBOX_DEEP_PROBE_ENABLE(phycore_imx93_of_match);
> > diff --git a/arch/arm/boards/phytec-phycore-imx93/lowlevel.c b/arch/arm/boards/phytec-phycore-imx93/lowlevel.c
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..7678d2f2633ea07e532684f999b62ddecc2b79dc
> > --- /dev/null
> > +++ b/arch/arm/boards/phytec-phycore-imx93/lowlevel.c
> > @@ -0,0 +1,60 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +#include <common.h>
> > +#include <debug_ll.h>
> > +#include <mach/imx/debug_ll.h>
> > +#include <mach/imx/generic.h>
> > +#include <mach/imx/xload.h>
> > +#include <asm/barebox-arm.h>
> > +#include <soc/imx9/ddr.h>
> > +#include <mach/imx/atf.h>
> > +#include <mach/imx/xload.h>
> > +#include <mach/imx/romapi.h>
> 
> This shouldn't be needed.

Dropped a few includes while applying.

Sascha


-- 
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-5555 |


From m.felsch at pengutronix.de  Tue Mar 11 01:50:19 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 11 Mar 2025 09:50:19 +0100
Subject: [PATCH 04/13] ARM: k3: r5: add proper error handling
In-Reply-To: <Z8_zIC2f7n3-_sVn@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250228-am625-secure-v1-4-4002488ff5ed@pengutronix.de>
 <20250310185217.4bmple2ygkrcl3gp@pengutronix.de>
 <Z8_zIC2f7n3-_sVn@pengutronix.de>
Message-ID: <20250311085019.rfmfsckfwwxh5hxn@pengutronix.de>

On 25-03-11, Sascha Hauer wrote:
> On Mon, Mar 10, 2025 at 07:52:17PM +0100, Marco Felsch wrote:
> > On 25-02-28, Sascha Hauer wrote:
> > > Add missing error handling in the image loading code. Properly check for
> > > errors and panic when mandatory binaries are missing instead of blindly
> > > continuing.
> > > 
> > > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > > ---
> > >  arch/arm/mach-k3/r5.c | 57 ++++++++++++++++++++++++++++-----------------------
> > >  1 file changed, 31 insertions(+), 26 deletions(-)
> > > 
> > > diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
> > > index 2418e9ae73..e12c888afa 100644
> > > --- a/arch/arm/mach-k3/r5.c
> > > +++ b/arch/arm/mach-k3/r5.c
> > > @@ -283,7 +283,7 @@ static int load_fip(const char *filename, off_t offset)
> > >  	return 0;
> > >  }
> > >  
> > > -static void do_dfu(void)
> > > +static int do_dfu(void)
> > >  {
> > >  	struct usbgadget_funcs funcs = {};
> > >  	int ret;
> > > @@ -293,37 +293,24 @@ static void do_dfu(void)
> > >  	funcs.dfu_opts = "/fip.img(fip)cs";
> > >  
> > >  	ret = usbgadget_prepare_register(&funcs);
> > > -	if (ret)
> > > -		goto err;
> > > +	if (ret) {
> > > +		pr_err("DFU failed with: %pe\n", ERR_PTR(ret));
> > > +		return ret;
> > > +	}
> > >  
> > >  	while (1) {
> > >  		ret = stat("/fip.img", &s);
> > >  		if (!ret) {
> > >  			printf("Downloaded FIP image, DFU done\n");
> > > -			load_fip("/fip.img", 0);
> > > -			break;
> > > +			ret = load_fip("/fip.img", 0);
> > > +			if (!ret)
> > > +				return 0;
> > >  		}
> > >  
> > >  		command_slice_release();
> > >  		mdelay(50);
> > >  		command_slice_acquire();
> > >  	};
> > > -
> > > -	return;
> > > -
> > > -err:
> > > -	pr_err("DFU failed with: %pe\n", ERR_PTR(ret));
> > > -}
> > > -
> > > -static int load_images(void)
> > > -{
> > > -	int err;
> > > -
> > > -	err = load_fip("/boot/k3.fip", 0);
> > > -	if (!err)
> > > -		return 0;
> > > -
> > > -	return 0;
> > >  }
> > 
> > Removing load_images should go into patch-3.
> 
> I deliberately did it in this patch because load_images already does
> error checking, but up to now the return value of load_images() wasn't
> checked. By doing it like you suggest I would either end up calling
> load_fip() without checking the error, or I would introduce an
> incomplete error checking in k3_r5_start_image() where the return value
> of load_fip() is checked, but not the return values of do_dfu and
> load_fip_emmc().

Ah okay, good point. In that case I'm fine with it.

Regards,
  Marco


> 
> > >  static int load_fip_emmc(void)
> > > @@ -332,6 +319,7 @@ static int load_fip_emmc(void)
> > >  	struct mci *mci;
> > >  	char *fname;
> > >  	const char *mmcdev = "mmc0";
> > > +	int ret;
> > 
> > Nit: Sometimes you do use ret, sometimes err. I would like to align it
> > if possible.
> 
> Changed to 'ret' consistently.
> 
> Sascha
> 
> -- 
> 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-5555 |
> 


From s.hauer at pengutronix.de  Tue Mar 11 01:50:35 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 09:50:35 +0100
Subject: [PATCH] barebox-environment: Use default mount path
In-Reply-To: <20250228080214.1319495-1-s.hauer@pengutronix.de>
References: <20250228080214.1319495-1-s.hauer@pengutronix.de>
Message-ID: <174168303567.1453535.11863895677732790464.b4-ty@pengutronix.de>


On Fri, 28 Feb 2025 09:02:14 +0100, Sascha Hauer wrote:
> When using a file inside a partition for the barebox environment we
> mount the partition to a non standard path ("/boot") which can cause
> problems with autmounting. Mount the partition to the standard location
> and create a symlink from /boot to the mounted path.
> 
> 

Applied, thanks!

[1/1] barebox-environment: Use default mount path
      https://git.pengutronix.de/cgit/barebox/commit/?id=4042480fc709 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar 11 02:13:36 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 10:13:36 +0100
Subject: [PATCH 00/13] am625: support secure loading of full barebox
In-Reply-To: <20250311084833.5h32rntkvk6ggi5i@pengutronix.de>
References: <20250228-am625-secure-v1-0-4002488ff5ed@pengutronix.de>
 <20250310174058.t3rsxws6syxz2rqp@pengutronix.de>
 <Z8_wg9fWKN4s0vrd@pengutronix.de>
 <20250311084833.5h32rntkvk6ggi5i@pengutronix.de>
Message-ID: <Z8_-wNpIL60GWv6N@pengutronix.de>

On Tue, Mar 11, 2025 at 09:48:33AM +0100, Marco Felsch wrote:
> On 25-03-11, Sascha Hauer wrote:
> > On Mon, Mar 10, 2025 at 06:40:58PM +0100, Marco Felsch wrote:
> > > Hi Sascha,
> > > 
> > > On 25-02-28, Sascha Hauer wrote:
> > > > On K3 SoCs only a small barebox is loaded by the ROM into SRAM. This
> > > > barebox then loads the full barebox from SD/eMMC or USB DFU. In a secure
> > > > boot environment the full barebox must be authenticated. This series
> > > > implements two ways for accomplishing this.
> > > > 
> > > > First way is to utilize the ROM API to authenticate images. The other
> > > > way is to compile a secure hash into the first stage binary and check
> > > > if the full barebox image matches the hash. Using the ROM API means
> > > > different first stage and second stage images can be combined whereas
> > > > hashing binds specific builds together avoiding mix and match attacks.
> > > 
> > > before having a closer look on your patchset, do we really want to have
> > > the 2nd case to be available?
> > 
> > Yes, as explained to avoid mix-and-match attacks.
> 
> Argh.. sorry, I meant the first case, the ROM API one. If the ROM API
> allows mix-and-match attacks, we need to mark it as INSECURE. Sorry for
> the confusion.

I wouldn't call using the ROM API insecure. In the end with the ROM API
the images are still signed and different people likely come to
different conclusions whether they want to sign or rather hash the
images.

Sascha

-- 
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-5555 |


From jre at pengutronix.de  Tue Mar 11 03:50:18 2025
From: jre at pengutronix.de (Jonas Rebmann)
Date: Tue, 11 Mar 2025 11:50:18 +0100
Subject: [PATCH 2/2] ARM: boards: remove obsolete PCA9450_RESET_CTRL setup
In-Reply-To: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
References: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
Message-ID: <20250311-pca9450-wdog-v1-2-45120abeae00@pengutronix.de>

Since a previous commit, PCA9450_RESET_CTRL is initialized to 0xA1 in
pca9450_probe; explicitly setting this in board.c has no effect anymore.

Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
---
 arch/arm/boards/phytec-phycore-imx93/board.c | 9 ---------
 arch/arm/boards/tqma93xx/board.c             | 3 ---
 2 files changed, 12 deletions(-)

diff --git a/arch/arm/boards/phytec-phycore-imx93/board.c b/arch/arm/boards/phytec-phycore-imx93/board.c
index 149248ca654624826d0e8f6fe0f1f42c2747e248..03ba8cb5026d2a9eaa054fcfc69e18872fcd658e 100644
--- a/arch/arm/boards/phytec-phycore-imx93/board.c
+++ b/arch/arm/boards/phytec-phycore-imx93/board.c
@@ -6,23 +6,14 @@
 #include <init.h>
 #include <linux/kernel.h>
 #include <environment.h>
-#include <mfd/pca9450.h>
 #include <deep-probe.h>
 #include <mach/imx/bbu.h>
 #include <linux/pinctrl/consumer.h>
 
-static void phycore_imx93_init_pmic(struct regmap *map)
-{
-	/* set WDOG_B_CFG to cold reset */
-	regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
-}
-
 static int phycore_imx93_probe(struct device *dev)
 {
 	struct device_node *np;
 
-	pca9450_register_init_callback(phycore_imx93_init_pmic);
-
 	/*
 	 * The phy on the EQOS has its MDIO lines connected to the FEC. The phy
 	 * registers can only be successfully read when the EQOS pinctrl setup
diff --git a/arch/arm/boards/tqma93xx/board.c b/arch/arm/boards/tqma93xx/board.c
index b181784079cf12e5a112d13f95c87c2cf5ebeba6..b4de6c2f6c347cb255537a3784a667a9c2607de3 100644
--- a/arch/arm/boards/tqma93xx/board.c
+++ b/arch/arm/boards/tqma93xx/board.c
@@ -27,9 +27,6 @@ static void tqma93xx_init_pmic(struct regmap *map)
 
 	/* I2C_LT_EN*/
 	regmap_write(map, 0xa, 0x3);
-
-	/* set WDOG_B_CFG to cold reset */
-	regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
 }
 
 static int tqma93xx_probe(struct device *dev)

-- 
2.39.5



From jre at pengutronix.de  Tue Mar 11 03:50:16 2025
From: jre at pengutronix.de (Jonas Rebmann)
Date: Tue, 11 Mar 2025 11:50:16 +0100
Subject: [PATCH 0/2] Move pca9450 RESET_CTRL configuration to driver
Message-ID: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>

Configure the RESET_CTRL register of the pca9450 pmic in the driver,
like u-boot and kernel do. Subsequently, remove the setup of this
register from the pca9450_register_init_callback of the two imx93 boards
we currently have.

Configuration of this register in lowlevel.c of the imx8 boards remains
untouched for now as they use a larger array of pmic register setups
which I haven't given a closer look as to which is actually needed given
the defaults and what's done in the driver already.

Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
---
Jonas Rebmann (2):
      mfd: pca9450: configure pmic reset behavior
      ARM: boards: remove obsolete PCA9450_RESET_CTRL setup

 arch/arm/boards/phytec-phycore-imx93/board.c |  9 ---------
 arch/arm/boards/tqma93xx/board.c             |  3 ---
 drivers/mfd/pca9450.c                        | 11 +++++++++++
 include/mfd/pca9450.h                        |  4 ++++
 4 files changed, 15 insertions(+), 12 deletions(-)
---
base-commit: d004da6e3710cc01b645a57c8dd1a986eced1c80
change-id: 20250311-pca9450-wdog-b9458f1a26ff

Best regards,
-- 
Jonas Rebmann <jre at pengutronix.de>



From jre at pengutronix.de  Tue Mar 11 03:50:17 2025
From: jre at pengutronix.de (Jonas Rebmann)
Date: Tue, 11 Mar 2025 11:50:17 +0100
Subject: [PATCH 1/2] mfd: pca9450: configure pmic reset behavior
In-Reply-To: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
References: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
Message-ID: <20250311-pca9450-wdog-v1-1-45120abeae00@pengutronix.de>

Currently, boards using the pca9450 pmic driver initialize the
RESET_CTRL register either in lowlevel.c or board.c explicitly to 0xA1
to enable the watchdog for Cold Reset with all voltage regulators
recycled except LDO1/ LDO2 in addition to the default configuration of
0x11 where the WDOG_B watchdog input is disabled.

Instead, enable the watchdog in the driver for Cold Reset with all
voltage regulators recycled except LDO1/ LDO2. When
nxp,wdog_b-warm-reset is set, the watchdog is instead enabled for Warm
Reset.

This is identical to U-Boot's behaviour since commit 910c7a881f5 and
Linux's since commit 2364a64d0673f.

Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
---
 drivers/mfd/pca9450.c | 11 +++++++++++
 include/mfd/pca9450.h |  4 ++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/mfd/pca9450.c b/drivers/mfd/pca9450.c
index 2511e662c3dfb5dfedbc461357ffa82d1812166f..6d6fb32c36569689b901455b3376c92977eabc37 100644
--- a/drivers/mfd/pca9450.c
+++ b/drivers/mfd/pca9450.c
@@ -3,6 +3,7 @@
  * Copyright (C) 2023 Holger Assmann, Pengutronix
  */
 
+#include "linux/regmap.h"
 #include <common.h>
 #include <driver.h>
 #include <errno.h>
@@ -103,6 +104,16 @@ static int __init pca9450_probe(struct device *dev)
 	/* Chip ID defined in bits [7:4] */
 	dev_info(dev, "PMIC Chip ID: 0x%x\n", (reg >> 4));
 
+	/* Enable WDOG_B, for cold reset by default */
+	if (of_property_read_bool(dev->of_node, "nxp,wdog_b-warm-reset"))
+		regmap_update_bits(regmap, PCA9450_RESET_CTRL,
+				   PCA9450_PMIC_RESET_WDOG_B_CFG_MASK,
+				   PCA9450_PMIC_RESET_WDOG_B_CFG_WARM);
+	else
+		regmap_update_bits(regmap, PCA9450_RESET_CTRL,
+				   PCA9450_PMIC_RESET_WDOG_B_CFG_MASK,
+				   PCA9450_PMIC_RESET_WDOG_B_CFG_COLD_LDO12);
+
 	if (pca9450_init_callback)
 		pca9450_init_callback(regmap);
 	pca9450_map = regmap;
diff --git a/include/mfd/pca9450.h b/include/mfd/pca9450.h
index 7071c3a9da6c5adc26dbd6149fec5fa96f3365bf..af10e409855ff6c3585c7f63098a16e8ec33dee2 100644
--- a/include/mfd/pca9450.h
+++ b/include/mfd/pca9450.h
@@ -66,4 +66,8 @@ static inline int pca9450_register_init_callback(void(*callback)(struct regmap *
 }
 #endif
 
+#define PCA9450_PMIC_RESET_WDOG_B_CFG_MASK		0xc0
+#define PCA9450_PMIC_RESET_WDOG_B_CFG_WARM		0x40
+#define PCA9450_PMIC_RESET_WDOG_B_CFG_COLD_LDO12	0x80
+
 #endif

-- 
2.39.5



From a.fatoum at pengutronix.de  Tue Mar 11 04:03:07 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Mar 2025 12:03:07 +0100
Subject: [PATCH 2/2] ARM: boards: remove obsolete PCA9450_RESET_CTRL setup
In-Reply-To: <20250311-pca9450-wdog-v1-2-45120abeae00@pengutronix.de>
References: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
 <20250311-pca9450-wdog-v1-2-45120abeae00@pengutronix.de>
Message-ID: <f6277af8-56a9-4327-a299-d2e2d39cbc1a@pengutronix.de>

Hi,

On 3/11/25 11:50, Jonas Rebmann wrote:
> Since a previous commit, PCA9450_RESET_CTRL is initialized to 0xA1 in
> pca9450_probe; explicitly setting this in board.c has no effect anymore.

Note that there is a number of i.MX8M boards that also use the PCA9450
and configure 0xA1 into PCA9450_RESET_CTRL in their lowlevel.c.

Any particular reason against or for dropping the configuration there?

Thanks,
Ahmad

> Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
> ---
>  arch/arm/boards/phytec-phycore-imx93/board.c | 9 ---------
>  arch/arm/boards/tqma93xx/board.c             | 3 ---
>  2 files changed, 12 deletions(-)
> 
> diff --git a/arch/arm/boards/phytec-phycore-imx93/board.c b/arch/arm/boards/phytec-phycore-imx93/board.c
> index 149248ca654624826d0e8f6fe0f1f42c2747e248..03ba8cb5026d2a9eaa054fcfc69e18872fcd658e 100644
> --- a/arch/arm/boards/phytec-phycore-imx93/board.c
> +++ b/arch/arm/boards/phytec-phycore-imx93/board.c
> @@ -6,23 +6,14 @@
>  #include <init.h>
>  #include <linux/kernel.h>
>  #include <environment.h>
> -#include <mfd/pca9450.h>
>  #include <deep-probe.h>
>  #include <mach/imx/bbu.h>
>  #include <linux/pinctrl/consumer.h>
>  
> -static void phycore_imx93_init_pmic(struct regmap *map)
> -{
> -	/* set WDOG_B_CFG to cold reset */
> -	regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
> -}
> -
>  static int phycore_imx93_probe(struct device *dev)
>  {
>  	struct device_node *np;
>  
> -	pca9450_register_init_callback(phycore_imx93_init_pmic);
> -
>  	/*
>  	 * The phy on the EQOS has its MDIO lines connected to the FEC. The phy
>  	 * registers can only be successfully read when the EQOS pinctrl setup
> diff --git a/arch/arm/boards/tqma93xx/board.c b/arch/arm/boards/tqma93xx/board.c
> index b181784079cf12e5a112d13f95c87c2cf5ebeba6..b4de6c2f6c347cb255537a3784a667a9c2607de3 100644
> --- a/arch/arm/boards/tqma93xx/board.c
> +++ b/arch/arm/boards/tqma93xx/board.c
> @@ -27,9 +27,6 @@ static void tqma93xx_init_pmic(struct regmap *map)
>  
>  	/* I2C_LT_EN*/
>  	regmap_write(map, 0xa, 0x3);
> -
> -	/* set WDOG_B_CFG to cold reset */
> -	regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
>  }
>  
>  static int tqma93xx_probe(struct device *dev)
> 



From r.czerwinski at pengutronix.de  Tue Mar 11 04:05:22 2025
From: r.czerwinski at pengutronix.de (Rouven Czerwinski)
Date: Tue, 11 Mar 2025 12:05:22 +0100
Subject: [PATCH 0/2] Move pca9450 RESET_CTRL configuration to driver
In-Reply-To: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
References: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
Message-ID: <a2b2fd98bb4d5f5597b55587ddc9f6b6e4da8fcb.camel@pengutronix.de>

Hi,

On Tue, 2025-03-11 at 11:50 +0100, Jonas Rebmann wrote:
> Configure the RESET_CTRL register of the pca9450 pmic in the driver,
> like u-boot and kernel do. Subsequently, remove the setup of this
> register from the pca9450_register_init_callback of the two imx93 boards
> we currently have.

Does it make sense to select the pcs9450 in the board kconfig symbols?
This way users retain the behaviour after an update even if the pca9450
driver was not selected before.

> Configuration of this register in lowlevel.c of the imx8 boards remains
> untouched for now as they use a larger array of pmic register setups
> which I haven't given a closer look as to which is actually needed given
> the defaults and what's done in the driver already.
> 
> Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
> ---
> Jonas Rebmann (2):
> ????? mfd: pca9450: configure pmic reset behavior
> ????? ARM: boards: remove obsolete PCA9450_RESET_CTRL setup
> 
> ?arch/arm/boards/phytec-phycore-imx93/board.c |? 9 ---------
> ?arch/arm/boards/tqma93xx/board.c???????????? |? 3 ---
> ?drivers/mfd/pca9450.c??????????????????????? | 11 +++++++++++
> ?include/mfd/pca9450.h??????????????????????? |? 4 ++++
> ?4 files changed, 15 insertions(+), 12 deletions(-)
> ---
> base-commit: d004da6e3710cc01b645a57c8dd1a986eced1c80
> change-id: 20250311-pca9450-wdog-b9458f1a26ff
> 
> Best regards,

Best regards,
Rouven


From jre at pengutronix.de  Tue Mar 11 04:21:52 2025
From: jre at pengutronix.de (Jonas Rebmann)
Date: Tue, 11 Mar 2025 12:21:52 +0100
Subject: [PATCH 2/2] ARM: boards: remove obsolete PCA9450_RESET_CTRL setup
In-Reply-To: <f6277af8-56a9-4327-a299-d2e2d39cbc1a@pengutronix.de>
References: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
 <20250311-pca9450-wdog-v1-2-45120abeae00@pengutronix.de>
 <f6277af8-56a9-4327-a299-d2e2d39cbc1a@pengutronix.de>
Message-ID: <2a97c0f8-f9fd-47f0-8ac6-a0c5b7499dc1@pengutronix.de>

Hi Ahmad,

Not so much. As mentioned in the cover, the imx8 boards routinely 
configure a larger array of pca9450 registers. As I didn't give the rest 
of that setup a closer look, I did not change the code.

I have only tested this series on the phyboard segin imx93.

Just like with the imx93 boards, after application of the driver patch, 
the { PCA9450_RESET_CTRL, 0xA1 } lines in lowlevel.c should no more have 
an effect (as no board currently uses nxp,wdog_b-warm-reset).

Should I remove all { PCA9450_RESET_CTRL, 0xA1 } configuration in v2?

  - Jonas

On 2025-03-11 12:03, Ahmad Fatoum wrote:
> Hi,
> 
> On 3/11/25 11:50, Jonas Rebmann wrote:
>> Since a previous commit, PCA9450_RESET_CTRL is initialized to 0xA1 in
>> pca9450_probe; explicitly setting this in board.c has no effect anymore.
> 
> Note that there is a number of i.MX8M boards that also use the PCA9450
> and configure 0xA1 into PCA9450_RESET_CTRL in their lowlevel.c.
> 
> Any particular reason against or for dropping the configuration there?
> 
> Thanks,
> Ahmad
> 
>> Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
>> ---
>>   arch/arm/boards/phytec-phycore-imx93/board.c | 9 ---------
>>   arch/arm/boards/tqma93xx/board.c             | 3 ---
>>   2 files changed, 12 deletions(-)
>>
>> diff --git a/arch/arm/boards/phytec-phycore-imx93/board.c b/arch/arm/boards/phytec-phycore-imx93/board.c
>> index 149248ca654624826d0e8f6fe0f1f42c2747e248..03ba8cb5026d2a9eaa054fcfc69e18872fcd658e 100644
>> --- a/arch/arm/boards/phytec-phycore-imx93/board.c
>> +++ b/arch/arm/boards/phytec-phycore-imx93/board.c
>> @@ -6,23 +6,14 @@
>>   #include <init.h>
>>   #include <linux/kernel.h>
>>   #include <environment.h>
>> -#include <mfd/pca9450.h>
>>   #include <deep-probe.h>
>>   #include <mach/imx/bbu.h>
>>   #include <linux/pinctrl/consumer.h>
>>   
>> -static void phycore_imx93_init_pmic(struct regmap *map)
>> -{
>> -	/* set WDOG_B_CFG to cold reset */
>> -	regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
>> -}
>> -
>>   static int phycore_imx93_probe(struct device *dev)
>>   {
>>   	struct device_node *np;
>>   
>> -	pca9450_register_init_callback(phycore_imx93_init_pmic);
>> -
>>   	/*
>>   	 * The phy on the EQOS has its MDIO lines connected to the FEC. The phy
>>   	 * registers can only be successfully read when the EQOS pinctrl setup
>> diff --git a/arch/arm/boards/tqma93xx/board.c b/arch/arm/boards/tqma93xx/board.c
>> index b181784079cf12e5a112d13f95c87c2cf5ebeba6..b4de6c2f6c347cb255537a3784a667a9c2607de3 100644
>> --- a/arch/arm/boards/tqma93xx/board.c
>> +++ b/arch/arm/boards/tqma93xx/board.c
>> @@ -27,9 +27,6 @@ static void tqma93xx_init_pmic(struct regmap *map)
>>   
>>   	/* I2C_LT_EN*/
>>   	regmap_write(map, 0xa, 0x3);
>> -
>> -	/* set WDOG_B_CFG to cold reset */
>> -	regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
>>   }
>>   
>>   static int tqma93xx_probe(struct device *dev)
>>
> 
> 
> 



From jre at pengutronix.de  Tue Mar 11 04:40:03 2025
From: jre at pengutronix.de (Jonas Rebmann)
Date: Tue, 11 Mar 2025 12:40:03 +0100
Subject: [PATCH 0/2] Move pca9450 RESET_CTRL configuration to driver
In-Reply-To: <a2b2fd98bb4d5f5597b55587ddc9f6b6e4da8fcb.camel@pengutronix.de>
References: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
 <a2b2fd98bb4d5f5597b55587ddc9f6b6e4da8fcb.camel@pengutronix.de>
Message-ID: <cbb86516-6337-44ba-a957-5620e5eb5015@pengutronix.de>

Hi Rouven,

On 2025-03-11 12:05, Rouven Czerwinski wrote:
> Does it make sense to select the pcs9450 in the board kconfig symbols?
> This way users retain the behaviour after an update even if the pca9450
> driver was not selected before.

Are you referring to a scenario where removal of an explicit 
initialization of PCA9450_RESET_CTRL in favor of the setup in the driver 
would lead to an unitialized PCA9450_RESET_CTRL if the driver is not 
enabled?

For the imx93 boards, behaviour remains unchanged same as those two 
boards configure PCA9450_RESET_CTRL in pca9450_register_init_callback, 
which is called by the driver. So change in behavior with those.

Not so on the imx8 boards where pmic_configure is called unconditionally 
in the power-on routine.

Given this, I'm not sure if we should remove the explicit register 
config for the imx8 boards as Ahmad mentioned. I think I remember Sasha 
mentioning a reason why board kconfig doesn't select the pmic driver?..

  - Jonas


From jre at pengutronix.de  Tue Mar 11 04:42:41 2025
From: jre at pengutronix.de (Jonas Rebmann)
Date: Tue, 11 Mar 2025 12:42:41 +0100
Subject: [PATCH 0/2] Move pca9450 RESET_CTRL configuration to driver
In-Reply-To: <cbb86516-6337-44ba-a957-5620e5eb5015@pengutronix.de>
References: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
 <a2b2fd98bb4d5f5597b55587ddc9f6b6e4da8fcb.camel@pengutronix.de>
 <cbb86516-6337-44ba-a957-5620e5eb5015@pengutronix.de>
Message-ID: <f385ff79-b560-4497-aba2-4d8a2ed54c2f@pengutronix.de>

On 2025-03-11 12:40, Jonas Rebmann wrote:
> For the imx93 boards, behaviour remains unchanged same as those two
> boards configure PCA9450_RESET_CTRL in pca9450_register_init_callback,
> which is called by the driver. So change in behavior with those.

This was supposed to say:

For the imx93 boards, behaviour remains **unchanged** as those two
boards configure PCA9450_RESET_CTRL in pca9450_register_init_callback,
which is called by the driver. So **no** change in behavior with those.


From a.fatoum at pengutronix.de  Tue Mar 11 04:42:40 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Mar 2025 12:42:40 +0100
Subject: [PATCH 2/2] ARM: boards: remove obsolete PCA9450_RESET_CTRL setup
In-Reply-To: <2a97c0f8-f9fd-47f0-8ac6-a0c5b7499dc1@pengutronix.de>
References: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
 <20250311-pca9450-wdog-v1-2-45120abeae00@pengutronix.de>
 <f6277af8-56a9-4327-a299-d2e2d39cbc1a@pengutronix.de>
 <2a97c0f8-f9fd-47f0-8ac6-a0c5b7499dc1@pengutronix.de>
Message-ID: <7e01458c-d25f-4f74-a864-a85fe86c02f3@pengutronix.de>

Hello Jonas,

On 3/11/25 12:21, Jonas Rebmann wrote:
> Hi Ahmad,
> 
> Not so much. As mentioned in the cover, the imx8 boards routinely
> configure a larger array of pca9450 registers. As I didn't give the rest
> of that setup a closer look, I did not change the code.

Ah, should've read the cover letter, my bad.

Please add that information into the commit messages, so it becomes
part of the git history.

> I have only tested this series on the phyboard segin imx93.
> 
> Just like with the imx93 boards, after application of the driver patch,
> the { PCA9450_RESET_CTRL, 0xA1 } lines in lowlevel.c should no more have
> an effect (as no board currently uses nxp,wdog_b-warm-reset).
> 
> Should I remove all { PCA9450_RESET_CTRL, 0xA1 } configuration in v2?

An explanation in the commit message why this wasn't done is enough.

Cheers,
Ahmad

> 
> ?- Jonas
> 
> On 2025-03-11 12:03, Ahmad Fatoum wrote:
>> Hi,
>>
>> On 3/11/25 11:50, Jonas Rebmann wrote:
>>> Since a previous commit, PCA9450_RESET_CTRL is initialized to 0xA1 in
>>> pca9450_probe; explicitly setting this in board.c has no effect anymore.
>>
>> Note that there is a number of i.MX8M boards that also use the PCA9450
>> and configure 0xA1 into PCA9450_RESET_CTRL in their lowlevel.c.
>>
>> Any particular reason against or for dropping the configuration there?
>>
>> Thanks,
>> Ahmad
>>
>>> Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
>>> ---
>>> ? arch/arm/boards/phytec-phycore-imx93/board.c | 9 ---------
>>> ? arch/arm/boards/tqma93xx/board.c???????????? | 3 ---
>>> ? 2 files changed, 12 deletions(-)
>>>
>>> diff --git a/arch/arm/boards/phytec-phycore-imx93/board.c b/arch/arm/
>>> boards/phytec-phycore-imx93/board.c
>>> index
>>> 149248ca654624826d0e8f6fe0f1f42c2747e248..03ba8cb5026d2a9eaa054fcfc69e18872fcd658e 100644
>>> --- a/arch/arm/boards/phytec-phycore-imx93/board.c
>>> +++ b/arch/arm/boards/phytec-phycore-imx93/board.c
>>> @@ -6,23 +6,14 @@
>>> ? #include <init.h>
>>> ? #include <linux/kernel.h>
>>> ? #include <environment.h>
>>> -#include <mfd/pca9450.h>
>>> ? #include <deep-probe.h>
>>> ? #include <mach/imx/bbu.h>
>>> ? #include <linux/pinctrl/consumer.h>
>>> ? -static void phycore_imx93_init_pmic(struct regmap *map)
>>> -{
>>> -??? /* set WDOG_B_CFG to cold reset */
>>> -??? regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
>>> -}
>>> -
>>> ? static int phycore_imx93_probe(struct device *dev)
>>> ? {
>>> ????? struct device_node *np;
>>> ? -??? pca9450_register_init_callback(phycore_imx93_init_pmic);
>>> -
>>> ????? /*
>>> ?????? * The phy on the EQOS has its MDIO lines connected to the FEC.
>>> The phy
>>> ?????? * registers can only be successfully read when the EQOS
>>> pinctrl setup
>>> diff --git a/arch/arm/boards/tqma93xx/board.c b/arch/arm/boards/
>>> tqma93xx/board.c
>>> index
>>> b181784079cf12e5a112d13f95c87c2cf5ebeba6..b4de6c2f6c347cb255537a3784a667a9c2607de3 100644
>>> --- a/arch/arm/boards/tqma93xx/board.c
>>> +++ b/arch/arm/boards/tqma93xx/board.c
>>> @@ -27,9 +27,6 @@ static void tqma93xx_init_pmic(struct regmap *map)
>>> ? ????? /* I2C_LT_EN*/
>>> ????? regmap_write(map, 0xa, 0x3);
>>> -
>>> -??? /* set WDOG_B_CFG to cold reset */
>>> -??? regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
>>> ? }
>>> ? ? static int tqma93xx_probe(struct device *dev)
>>>
>>
>>
>>
> 
> 



From s.hauer at pengutronix.de  Tue Mar 11 05:25:16 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:16 +0100
Subject: [PATCH v2 03/14] ARM: k3: r5: drop loading of separate binaries
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-3-3cbbfa092346@pengutronix.de>

For starting the A52 cores we need TFA, OP-TEE, barebox and ti-dm
binaries. These can be loaded as separate files from SD/eMMC/DFU or
alternatively combined into a single FIP image.
FIP images are convenient to handle, they can easily be generated on the
command line and fiptool also has support for replacing blobs in images.
This makes handling of separate binaries rather unnecessary and support
for it only makes the loading code more complex. Drop it and make FIP
images the only option which also faciliates integrating of secure boot.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-k3/r5.c | 70 +--------------------------------------------------
 1 file changed, 1 insertion(+), 69 deletions(-)

diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
index ced1eb2856..2418e9ae73 100644
--- a/arch/arm/mach-k3/r5.c
+++ b/arch/arm/mach-k3/r5.c
@@ -288,50 +288,15 @@ static void do_dfu(void)
 	struct usbgadget_funcs funcs = {};
 	int ret;
 	struct stat s;
-	ssize_t size;
 
 	funcs.flags |= USBGADGET_DFU;
-	funcs.dfu_opts = "/optee.bin(optee)c,"
-			 "/bl31.bin(tfa)c,"
-			 "/ti-dm.bin(ti-dm)c,"
-			 "/barebox.bin(barebox)cs,"
-			 "/fip.img(fip)cs";
+	funcs.dfu_opts = "/fip.img(fip)cs";
 
 	ret = usbgadget_prepare_register(&funcs);
 	if (ret)
 		goto err;
 
 	while (1) {
-		if (!have_bl32) {
-			size = read_file_into_buf("/optee.bin", BL32_ADDRESS, SZ_32M);
-			if (size > 0) {
-				printf("Downloaded OP-TEE\n");
-				have_bl32 = true;
-			}
-		}
-
-		if (!have_bl31) {
-			size = read_file_into_buf("/bl31.bin", BL31_ADDRESS, SZ_32M);
-			if (size > 0) {
-				printf("Downloaded TF-A\n");
-				have_bl31 = true;
-			}
-		}
-
-		if (!k3_ti_dm) {
-			ret = read_file_2("/ti-dm.bin", &size, &k3_ti_dm, FILESIZE_MAX);
-			if (!ret) {
-				printf("Downloaded TI-DM\n");
-			}
-		}
-
-		size = read_file_into_buf("/barebox.bin", BAREBOX_ADDRESS, SZ_32M);
-		if (size > 0) {
-			have_bl33 = true;
-			printf("Downloaded barebox image, DFU done\n");
-			break;
-		}
-
 		ret = stat("/fip.img", &s);
 		if (!ret) {
 			printf("Downloaded FIP image, DFU done\n");
@@ -352,45 +317,12 @@ static void do_dfu(void)
 
 static int load_images(void)
 {
-	ssize_t size;
 	int err;
 
 	err = load_fip("/boot/k3.fip", 0);
 	if (!err)
 		return 0;
 
-	size = read_file_into_buf("/boot/optee.bin", BL32_ADDRESS, SZ_32M);
-	if (size < 0) {
-		if (size != -ENOENT) {
-			pr_err("Cannot load optee.bin: %pe\n", ERR_PTR(size));
-			return size;
-		}
-		pr_info("optee.bin not found, continue without\n");
-	} else {
-		pr_debug("Loaded optee.bin (size %u) to 0x%p\n", size, BL32_ADDRESS);
-	}
-
-	size = read_file_into_buf("/boot/barebox.bin", BAREBOX_ADDRESS, SZ_32M);
-	if (size < 0) {
-		pr_err("Cannot load barebox.bin: %pe\n", ERR_PTR(size));
-		return size;
-	}
-	pr_debug("Loaded barebox.bin (size %u) to 0x%p\n", size, BAREBOX_ADDRESS);
-
-	size = read_file_into_buf("/boot/bl31.bin", BL31_ADDRESS, SZ_32M);
-	if (size < 0) {
-		pr_err("Cannot load bl31.bin: %pe\n", ERR_PTR(size));
-		return size;
-	}
-	pr_debug("Loaded bl31.bin (size %u) to 0x%p\n", size, BL31_ADDRESS);
-
-	err = read_file_2("/boot/ti-dm.bin", &size, &k3_ti_dm, FILESIZE_MAX);
-	if (err) {
-		pr_err("Cannot load ti-dm.bin: %pe\n", ERR_PTR(err));
-		return err;
-	}
-	pr_debug("Loaded ti-dm.bin (size %u)\n", size);
-
 	return 0;
 }
 

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:14 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:14 +0100
Subject: [PATCH v2 01/14] firmware: always generate sha256sum
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-1-3cbbfa092346@pengutronix.de>

Right now we only generate the sha256 for firmware files that are
loaded from an external binary. Instead, always generate the sha256
which helps with upcoming support for checking the next image hash.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 firmware/Makefile | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/firmware/Makefile b/firmware/Makefile
index 4cf61587d6..095d6f0e31 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -76,9 +76,6 @@ filechk_fwbin = { \
 	echo "_fwname_$(FWSTR):"				;\
 	printf '.ascii "%s"\n' 'firmware/$(FWNAME)\n'		;\
 	echo "\#endif" 						;\
-}
-
-__fwbin_sha = { \
 	echo "    .section .rodata.$(FWSTR).sha"		;\
 	echo "    .p2align ASM_LGPTR"				;\
 	echo ".global _fw_$(FWSTR)_sha_start"			;\
@@ -90,10 +87,9 @@ __fwbin_sha = { \
 
 filechk_fwbin_ext = { \
 	$(filechk_fwbin)					;\
-	$(__fwbin_sha)						;\
 }
 
-$(obj)/%.gen.S: FORCE
+$(obj)/%.gen.S: $(obj)/%.sha.bin FORCE
 	$(call filechk,fwbin,.rodata.$(FWSTR),)
 
 $(obj)/%.extgen.S: $(obj)/%.sha.bin FORCE

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:15 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:15 +0100
Subject: [PATCH v2 02/14] firmware: add function to verify next image
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-2-3cbbfa092346@pengutronix.de>

Some SoCs use a startup sequence that includes multiple stages where a
full barebox is loaded by an early small barebox that fits into the
SoC's SRAM. This is commonly referred to as xload. In a secure boot
environment it's necessary to load only trusted barebox images. One
way to accomplish this is to compile a sha256 into the first stage
barebox and to verify the full barebox against this hash.

This patch adds the generic parts for this. The full barebox binary
can be put into the first stage build as a firmware file. The firmware
itself won't be used, only the hash is compiled into the image. SoC
code can then check the full barebox image against the hash. As this
requires SoC code to check the hash, the option is hidden behind
CONFIG_HAVE_FIRMWARE_VERIFY_NEXT_IMAGE. SoC code can select this option
when it implements the required hash checking.

It's worth noting that using a hash for verification has one advantage
over cryptographicaly signing followup images: It ties first stage
and full barebox stages together effectively avoiding mix-and-match
attacks.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 firmware/Kconfig   | 23 +++++++++++++++++++++++
 firmware/Makefile  |  2 ++
 include/firmware.h | 26 ++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)

diff --git a/firmware/Kconfig b/firmware/Kconfig
index ba005976c5..bdb71321bc 100644
--- a/firmware/Kconfig
+++ b/firmware/Kconfig
@@ -108,4 +108,27 @@ config FIRMWARE_LS1028A_ATF
 config FIRMWARE_LS1046A_ATF
 	bool
 
+config HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
+	bool
+
+config FIRMWARE_VERIFY_NEXT_IMAGE
+	depends on HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
+	bool "verify next image to load"
+	help
+	  The boot process of some SoCs uses multiple stages where the first stage is
+	  a stripped down barebox loaded by the SoC's ROM and the next state is a full
+	  barebox loaded by the first stage. In a trusted boot scenario the next stage
+	  has to be verified by the first stage,
+
+	  This option allows to specify the next image to be loaded. Put the next stage
+	  image to firmware/next-image.bin. The image itself is not used, but a sha256
+	  hash of the image will be generated and compiled into the first stage which
+	  can be used to verify the next stage.
+
+	  Note that this option only enabled generation of the sha256 hash. Loading and
+	  starting the next stage is highly SoC dependent and it's the SoC code's
+	  responsibility to actually verify the hash and to only start successfully
+	  verified images. The function to check the next stage image hash is
+	  firmware_next_image_verify(), make sure your SoC code uses it.
+
 endmenu
diff --git a/firmware/Makefile b/firmware/Makefile
index 095d6f0e31..67fd898890 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -34,6 +34,8 @@ pbl-firmware-$(CONFIG_ARCH_RK3588) += rk3588-bl32.bin
 pbl-firmware-$(CONFIG_ARCH_RK3399) += rk3399-bl32.bin
 endif
 
+firmware-$(CONFIG_FIRMWARE_NEXT_IMAGE) += next-image.bin
+
 firmware-$(CONFIG_DRIVER_NET_FSL_FMAN) += fsl_fman_ucode_ls1046_r1.0_106_4_18.bin
 
 fw-external-$(CONFIG_FIRMWARE_LS1028A_ATF) += ls1028a-bl31.bin
diff --git a/include/firmware.h b/include/firmware.h
index d7feae1371..ab518cb432 100644
--- a/include/firmware.h
+++ b/include/firmware.h
@@ -13,6 +13,8 @@
 #include <debug_ll.h>
 #include <linux/kernel.h>
 #include <asm/sections.h>
+#include <crypto/sha.h>
+#include <crypto.h>
 
 struct firmware {
 	size_t size;
@@ -113,4 +115,28 @@ static inline void firmware_ext_verify(const void *data_start, size_t data_size,
 #define get_builtin_firmware_ext(name, base, start, size)		\
 	__get_builtin_firmware(name, (long)base - (long)_text, start, size)
 
+static inline int firmware_next_image_check_sha256(const void *hash, bool verbose)
+{
+	extern char _fw_next_image_bin_sha_start[];
+	int hsize = SHA256_DIGEST_SIZE;
+	int ret;
+
+	if (!IS_ENABLED(CONFIG_FIRMWARE_NEXT_IMAGE))
+		return -EINVAL;
+
+	ret = crypto_memneq(hash, _fw_next_image_bin_sha_start, hsize);
+
+	if (verbose) {
+		if (ret) {
+			pr_err("next image hash mismatch!\n");
+			pr_err("expected: sha256=%*phN\n", hsize, _fw_next_image_bin_sha_start);
+			pr_err("found:    sha256=%*phN\n", hsize, hash);
+		} else {
+			pr_info("hash sha256=%*phN OK\n", hsize, _fw_next_image_bin_sha_start);
+		}
+	}
+
+	return ret;
+}
+
 #endif /* FIRMWARE_H */

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:20 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:20 +0100
Subject: [PATCH v2 07/14] fip: add function to calculate a sha256 over FIP
 image
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-7-3cbbfa092346@pengutronix.de>

This adds fip_sha256() to calculate a sha256 over a FIP image.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/fiptool.h |  3 +++
 lib/fip.c         | 23 ++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/include/fiptool.h b/include/fiptool.h
index bb63a79c16..73b0fbe398 100644
--- a/include/fiptool.h
+++ b/include/fiptool.h
@@ -38,6 +38,7 @@ struct fip_state {
 	size_t nr_image_descs;
 	int verbose;
 	void *buffer;
+	size_t bufsize;
 	bool buf_no_free;
 };
 
@@ -100,4 +101,6 @@ extern toc_entry_t plat_def_toc_entries[];
 
 struct fip_state *fip_image_open(const char *filename, size_t offset);
 
+int fip_sha256(struct fip_state *fip, char *hash);
+
 #endif /* FIPTOOL_H */
diff --git a/lib/fip.c b/lib/fip.c
index 8086b43412..7a5e3dc844 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -24,6 +24,7 @@
 #include <libfile.h>
 #include <fs.h>
 #include <linux/kernel.h>
+#include <digest.h>
 
 #include <fip.h>
 #include <fiptool.h>
@@ -168,6 +169,7 @@ static int fip_do_parse_buf(struct fip_state *fip, void *buf, size_t size,
 	int terminated = 0;
 
 	fip->buffer = buf;
+	fip->bufsize = size;
 
 	bufend = fip->buffer + size;
 
@@ -570,10 +572,29 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
 	close(fd);
 
 	return fip_state;
-
 err:
 	close(fd);
 	fip_free(fip_state);
 
 	return ERR_PTR(ret);
 }
+
+int fip_sha256(struct fip_state *fip, char *hash)
+{
+	struct digest *d;
+	int ret;
+
+	d = digest_alloc_by_algo(HASH_ALGO_SHA256);
+	if (!d)
+		return -ENOSYS;
+
+	digest_init(d);
+
+	digest_update(d, fip->buffer, fip->bufsize);
+
+	ret = digest_final(d, hash);
+
+	digest_free(d);
+
+	return ret;
+}

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:19 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:19 +0100
Subject: [PATCH v2 06/14] fip: fix wrong function call
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-6-3cbbfa092346@pengutronix.de>

fip_parse_buf() is to be called when a buffer shall be parsed that is
allocated externally and thus shall not be freed in fip_free(). This
is not what we want in fip_parse(), we want exactly the buffer to be
freed, so call fip_do_parse_buf() instead.

Fixes: 748ba06276 ("fip: add function to parse FIP from a buffer")
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 lib/fip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/fip.c b/lib/fip.c
index aab2795476..8086b43412 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -274,7 +274,7 @@ int fip_parse(struct fip_state *fip,
 		return ret;
 	}
 
-	ret = fip_parse_buf(fip, buf, size, toc_header_out);
+	ret = fip_do_parse_buf(fip, buf, size, toc_header_out);
 
 	if (ret)
 		free(buf);

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:13 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:13 +0100
Subject: [PATCH v2 00/14] am625: support secure loading of full barebox
Message-ID: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>

On K3 SoCs only a small barebox is loaded by the ROM into SRAM. This
barebox then loads the full barebox from SD/eMMC or USB DFU. In a secure
boot environment the full barebox must be authenticated. This series
implements two ways for accomplishing this.

First way is to utilize the ROM API to authenticate images. The other
way is to compile a secure hash into the first stage binary and check
if the full barebox image matches the hash. Using the ROM API means
different first stage and second stage images can be combined whereas
hashing binds specific builds together avoiding mix and match attacks.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
Changes in v2:
- select HAS_INSECURE_DEFAULTS when necessary
- use 'ret' as error value variable rather than mixing 'err' and 'ret'
  in a single file
- rename firmware_next_image_verify() to
  firmware_next_image_check_sha256() and drop unnecessary hash_size argument
- Link to v1: https://lore.kernel.org/r/20250228-am625-secure-v1-0-4002488ff5ed at pengutronix.de

---
Sascha Hauer (14):
      firmware: always generate sha256sum
      firmware: add function to verify next image
      ARM: k3: r5: drop loading of separate binaries
      ARM: k3: r5: add proper error handling
      fip: rework fip_image_open()
      fip: fix wrong function call
      fip: add function to calculate a sha256 over FIP image
      ARM: am625: support hash verification of full barebox
      ARM: k3: add support for authenticating images against the ROM API
      ARM: k3: r5: delete fip image when it can't be opened
      ARM: k3: r5: Allow to authenticate next image by ROM API
      scripts/k3img: remove temporary files
      scripts: add k3sign
      ARM: k3: r5: select HAS_INSECURE_DEFAULTS when necessary

 arch/arm/mach-k3/Kconfig  |  16 ++++
 arch/arm/mach-k3/common.c |  99 +++++++++++++++++++++
 arch/arm/mach-k3/r5.c     | 214 ++++++++++++++++++++++++----------------------
 firmware/Kconfig          |  23 +++++
 firmware/Makefile         |   8 +-
 include/fiptool.h         |   3 +
 include/firmware.h        |  26 ++++++
 include/mach/k3/common.h  |   1 +
 lib/fip.c                 | 101 ++++++++++++++--------
 scripts/k3img             |   9 +-
 scripts/k3sign            | 126 +++++++++++++++++++++++++++
 11 files changed, 481 insertions(+), 145 deletions(-)
---
base-commit: 66b293c915276c3926cfda068f3f7a4b39b19f4a
change-id: 20250228-am625-secure-49301f641738

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar 11 05:25:22 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:22 +0100
Subject: [PATCH v2 09/14] ARM: k3: add support for authenticating images
 against the ROM API
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-9-3cbbfa092346@pengutronix.de>

This adds support for authenticating an image against the K3 ROM API.
Also included in this patch is a new command for testing the
authentication.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-k3/Kconfig  |  7 ++++
 arch/arm/mach-k3/common.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++
 include/mach/k3/common.h  |  1 +
 3 files changed, 107 insertions(+)

diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
index 561ad1dac4..37d5155577 100644
--- a/arch/arm/mach-k3/Kconfig
+++ b/arch/arm/mach-k3/Kconfig
@@ -37,4 +37,11 @@ config MACH_BEAGLEPLAY
 	help
 	  Say Y here if you are using a TI AM62x based BeaglePlay board
 
+config ARCH_K3_COMMAND_AUTHENTICATE
+	bool "k3_authenticate_image command"
+	depends on COMMAND_SUPPORT
+	help
+	  Add k3_authenticate_image command to test authenticating images
+	  against the K3 ROM API.
+
 endmenu
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 8dc9d3bc9e..a324e2d5f6 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 #include <of.h>
 #include <io.h>
+#include <dma.h>
 #include <deep-probe.h>
 #include <init.h>
 #include <envfs.h>
@@ -8,11 +9,15 @@
 #include <stdio.h>
 #include <xfuncs.h>
 #include <malloc.h>
+#include <command.h>
+#include <getopt.h>
+#include <libfile.h>
 #include <pm_domain.h>
 #include <bootsource.h>
 #include <linux/bits.h>
 #include <linux/bitfield.h>
 #include <mach/k3/common.h>
+#include <soc/ti/ti_sci_protocol.h>
 
 static const struct of_device_id k3_of_match[] = {
 	{
@@ -334,3 +339,97 @@ static int omap_env_init(void)
 	return 0;
 }
 late_initcall(omap_env_init);
+
+int k3_authenticate_image(void **buf, size_t *size)
+{
+	const struct ti_sci_handle *ti_sci;
+	u64 image_addr;
+	int ret;
+	unsigned int s = *size;
+
+	ti_sci = ti_sci_get_handle(NULL);
+	if (IS_ERR(ti_sci))
+		return -EINVAL;
+
+	image_addr = dma_map_single(NULL, *buf, *size, DMA_BIDIRECTIONAL);
+
+	ret = ti_sci->ops.proc_ops.proc_auth_boot_image(ti_sci, &image_addr, &s);
+
+	dma_unmap_single(NULL, image_addr, *size, DMA_BIDIRECTIONAL);
+
+	if (ret)
+		*size = 0;
+	else
+		*size = s;
+
+	return ret;
+}
+
+#ifdef CONFIG_ARCH_K3_COMMAND_AUTHENTICATE
+static int do_k3_authenticate_image(int argc, char *argv[])
+{
+	void *buf;
+	size_t size;
+	int ret;
+	int opt;
+	const char *outfile = NULL;
+	const char *filename;
+
+	while ((opt = getopt(argc, argv, "o:")) > 0) {
+		switch (opt) {
+		case 'o':
+			outfile = optarg;
+			break;
+		}
+	}
+
+	argc -= optind;
+
+	if (argc == 0)
+		return COMMAND_ERROR_USAGE;
+
+	filename = argv[0];
+
+	ret = read_file_2(filename, &size, &buf, FILESIZE_MAX);
+	if (ret)
+		return ret;
+
+	ret = k3_authenticate_image(&buf, &size);
+	if (ret) {
+		printf("authenticating %s failed: %pe\n", filename, ERR_PTR(ret));
+		ret = COMMAND_ERROR;
+		goto err;
+	}
+
+	printf("%s successfully authenticated\n", filename);
+
+	if (outfile) {
+		ret = write_file(outfile, buf, size);
+		if (ret) {
+			printf("Failed to write output file: %pe\n", ERR_PTR(ret));
+			goto err;
+		}
+	}
+
+	ret = 0;
+err:
+	free(buf);
+
+	return ret;
+}
+
+BAREBOX_CMD_HELP_START(k3_authenticate_image)
+BAREBOX_CMD_HELP_TEXT("Authenticate image with K3 ROM API")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-o <out>",  "store unpacked authenticated image in <out>")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(k3_authenticate_image)
+	.cmd = do_k3_authenticate_image,
+	BAREBOX_CMD_DESC("authenticate file with K3 ROM API")
+	BAREBOX_CMD_OPTS("[-o <out>] file")
+	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+	BAREBOX_CMD_HELP(k3_authenticate_image)
+BAREBOX_CMD_END
+#endif
diff --git a/include/mach/k3/common.h b/include/mach/k3/common.h
index 871e9f39e3..94c5fba19d 100644
--- a/include/mach/k3/common.h
+++ b/include/mach/k3/common.h
@@ -13,6 +13,7 @@ bool k3_boot_is_emmc(void);
 u64 am625_sdram_size(void);
 void am625_register_dram(void);
 void am625_enable_32k_crystal(void);
+int k3_authenticate_image(void **buf, size_t *size);
 
 #define K3_EMMC_BOOTPART_TIBOOT3_BIN_SIZE	SZ_1M
 

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:21 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:21 +0100
Subject: [PATCH v2 08/14] ARM: am625: support hash verification of full
 barebox
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-8-3cbbfa092346@pengutronix.de>

This implements the necessary SoC code to check the full barebox against
a sha256 compiled into the first stage barebox.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-k3/Kconfig |  1 +
 arch/arm/mach-k3/r5.c    | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
index 50919dc7e3..561ad1dac4 100644
--- a/arch/arm/mach-k3/Kconfig
+++ b/arch/arm/mach-k3/Kconfig
@@ -16,6 +16,7 @@ config MACH_K3_CORTEX_R5
 	select ELF
 	select K3_DDRSS
 	select FIP
+	select HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
 	depends on 32BIT
 	select ARM_USE_COMPRESSED_DTB
 	default y
diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
index 4eaf8658da..79bdb7aac7 100644
--- a/arch/arm/mach-k3/r5.c
+++ b/arch/arm/mach-k3/r5.c
@@ -248,6 +248,8 @@ static int load_fip(const char *filename, off_t offset)
 {
 	struct fip_state *fip;
 	struct fip_image_desc *desc;
+	unsigned char shasum[SHA256_DIGEST_SIZE];
+	int ret;
 
 	fip = fip_image_open(filename, offset);
 	if (IS_ERR(fip)) {
@@ -255,6 +257,18 @@ static int load_fip(const char *filename, off_t offset)
 		return PTR_ERR(fip);
 	}
 
+	if (IS_ENABLED(CONFIG_FIRMWARE_VERIFY_NEXT_IMAGE)) {
+		ret = fip_sha256(fip, shasum);
+		if (ret) {
+			pr_err("Cannot calc fip sha256: %pe\n", ERR_PTR(ret));
+			return ret;
+		}
+
+		ret = firmware_next_image_check_sha256(shasum, true);
+		if (ret)
+			return ret;
+	}
+
 	fip_for_each_desc(fip, desc) {
 		struct fip_toc_entry *toc_entry = &desc->image->toc_e;
 

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:18 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:18 +0100
Subject: [PATCH v2 05/14] fip: rework fip_image_open()
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-5-3cbbfa092346@pengutronix.de>

fip_image_open() used to do all the parsing into a struct fip_state
itself. Instead, only load the FIP image into a buffer and call
fip_do_parse_buf() with this buffer. This has the advantage that we
have all parsing of the FIP image in a single place. Also this helps
with a followup patch which calculates a sha256 over a FIP image
which can easily done when we have the whole FIP image in a contiguous
buffer.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 lib/fip.c | 78 +++++++++++++++++++++++++++++++++------------------------------
 1 file changed, 41 insertions(+), 37 deletions(-)

diff --git a/lib/fip.c b/lib/fip.c
index 23e82098da..aab2795476 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <libfile.h>
 #include <fs.h>
+#include <linux/kernel.h>
 
 #include <fip.h>
 #include <fiptool.h>
@@ -447,22 +448,17 @@ int fip_update(struct fip_state *fip)
 }
 
 /*
- * fip_image_open - open a FIP image for readonly access
+ * fip_image_open - open a FIP image
  * @filename: The filename of the FIP image
  * @offset: The offset of the FIP image in the file
  *
- * This opens a FIP image for readonly access. This is an alternative
- * implementation for fip_parse() with these differences:
+ * This opens a FIP image. This is an alternative implementation for
+ * fip_parse() with these differences:
  * - suitable for reading FIP images from raw partitions. This function
  *   only reads the FIP image, even when the partition is bigger than the
  *   image
  * - Allows to specify an offset within the partition where the FIP image
  *   starts
- * - Do not memdup the images from the full FIP image
- *
- * This function is for easy readonly access to the images within the FIP
- * image. Do not call any of the above FIP manipulation functions other than
- * fip_free() on an image opened with this function.
  */
 struct fip_state *fip_image_open(const char *filename, size_t offset)
 {
@@ -470,11 +466,13 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
 	int ret;
 	int fd;
 	struct fip_state *fip_state;
-	LIST_HEAD(entries);
 	size_t fip_headers_size, total = 0;
-	struct fip_image_desc *desc;
 	off_t pos;
 	int n_entries = 0;
+	struct fip_toc_entry toc_entries[16];
+	void *buf, *ptr;
+	int i;
+	struct fip_toc_entry *toc_entry;
 
 	fd = open(filename, O_RDONLY);
 	if (fd < 0)
@@ -506,11 +504,9 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
 
 	/* read all toc entries */
 	while (1) {
-		struct fip_image_desc *desc = xzalloc(sizeof(*desc));
-		struct fip_image *image = xzalloc(sizeof(*image));
-		struct fip_toc_entry *toc_entry = &image->toc_e;
+		uint64_t this_end;
 
-		desc->image = image;
+		toc_entry = &toc_entries[n_entries];
 
 		ret = read_full(fd, toc_entry, sizeof(*toc_entry));
 		if (ret < 0)
@@ -520,53 +516,61 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
 			goto err;
 		}
 
-		list_add_tail(&desc->list, &fip_state->descs);
-
 		pr_debug("Read TOC entry %pU %llu %llu\n", &toc_entry->uuid,
 			 toc_entry->offset_address, toc_entry->size);
 
-		/* Found the ToC terminator, we are done. */
-		if (uuid_is_null(&toc_entry->uuid))
-			break;
-	}
-
-	/* determine buffer size */
-	fip_for_each_desc(fip_state, desc) {
-		uint64_t this_end = desc->image->toc_e.offset_address + desc->image->toc_e.size;
+		this_end = toc_entry->offset_address + toc_entry->size;
 
 		if (this_end > total)
 			total = this_end;
+
 		n_entries++;
-	}
 
-	fip_headers_size = n_entries * sizeof(struct fip_toc_entry) + sizeof(fip_toc_header_t);
+		if (n_entries >= ARRAY_SIZE(toc_entries)) {
+			ret = -ENOSPC;
+			goto err;
+		}
 
-	total -= fip_headers_size;
+		/* Found the ToC terminator, we are done. */
+		if (uuid_is_null(&toc_entry->uuid))
+			break;
+	}
 
-	fip_state->buffer = malloc(total);
-	if (!fip_state->buffer) {
+	buf = malloc(total);
+	if (!buf) {
 		ret = -ENOMEM;
 		goto err;
 	}
 
-	ret = read_full(fd, fip_state->buffer, total);
+	ptr = buf;
+
+	memcpy(ptr, &toc_header, sizeof(toc_header));
+	ptr += sizeof(toc_header);
+
+	for (i = 0; i < n_entries; i++) {
+		memcpy(ptr, &toc_entries[i], sizeof(*toc_entry));
+		ptr += sizeof(*toc_entry);
+	}
+
+	fip_headers_size = n_entries * sizeof(struct fip_toc_entry) + sizeof(fip_toc_header_t);
+
+	ret = read_full(fd, ptr, total - fip_headers_size);
 	if (ret < 0)
 		goto err;
 
-	if (ret < total) {
+	if (ret < total - fip_headers_size) {
 		ret = -ENODATA;
 		goto err;
 	}
 
-	close(fd);
+	ret = fip_do_parse_buf(fip_state, buf, total, NULL);
+	if (ret)
+		goto err;
 
-	fip_for_each_desc(fip_state, desc) {
-		desc->image->buffer = fip_state->buffer +
-			desc->image->toc_e.offset_address - fip_headers_size;
-		desc->image->buf_no_free = true;
-	}
+	close(fd);
 
 	return fip_state;
+
 err:
 	close(fd);
 	fip_free(fip_state);

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:17 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:17 +0100
Subject: [PATCH v2 04/14] ARM: k3: r5: add proper error handling
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-4-3cbbfa092346@pengutronix.de>

Add missing error handling in the image loading code. Properly check for
errors and panic when mandatory binaries are missing instead of blindly
continuing.

While at it change the return value variable from 'err' to 'ret' to stay
consistent with the rest of the code in r5.c.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-k3/r5.c | 65 +++++++++++++++++++++++++++------------------------
 1 file changed, 35 insertions(+), 30 deletions(-)

diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
index 2418e9ae73..4eaf8658da 100644
--- a/arch/arm/mach-k3/r5.c
+++ b/arch/arm/mach-k3/r5.c
@@ -283,7 +283,7 @@ static int load_fip(const char *filename, off_t offset)
 	return 0;
 }
 
-static void do_dfu(void)
+static int do_dfu(void)
 {
 	struct usbgadget_funcs funcs = {};
 	int ret;
@@ -293,37 +293,24 @@ static void do_dfu(void)
 	funcs.dfu_opts = "/fip.img(fip)cs";
 
 	ret = usbgadget_prepare_register(&funcs);
-	if (ret)
-		goto err;
+	if (ret) {
+		pr_err("DFU failed with: %pe\n", ERR_PTR(ret));
+		return ret;
+	}
 
 	while (1) {
 		ret = stat("/fip.img", &s);
 		if (!ret) {
 			printf("Downloaded FIP image, DFU done\n");
-			load_fip("/fip.img", 0);
-			break;
+			ret = load_fip("/fip.img", 0);
+			if (!ret)
+				return 0;
 		}
 
 		command_slice_release();
 		mdelay(50);
 		command_slice_acquire();
 	};
-
-	return;
-
-err:
-	pr_err("DFU failed with: %pe\n", ERR_PTR(ret));
-}
-
-static int load_images(void)
-{
-	int err;
-
-	err = load_fip("/boot/k3.fip", 0);
-	if (!err)
-		return 0;
-
-	return 0;
 }
 
 static int load_fip_emmc(void)
@@ -332,6 +319,7 @@ static int load_fip_emmc(void)
 	struct mci *mci;
 	char *fname;
 	const char *mmcdev = "mmc0";
+	int ret;
 
 	device_detect_by_name(mmcdev);
 
@@ -348,16 +336,16 @@ static int load_fip_emmc(void)
 
 	fname = xasprintf("/dev/%s.boot%d", mmcdev, bootpart - 1);
 
-	load_fip(fname, K3_EMMC_BOOTPART_TIBOOT3_BIN_SIZE);
+	ret = load_fip(fname, K3_EMMC_BOOTPART_TIBOOT3_BIN_SIZE);
 
 	free(fname);
 
-	return 0;
+	return ret;
 }
 
 static int k3_r5_start_image(void)
 {
-	int err;
+	int ret;
 	struct firmware fw;
 	const struct ti_sci_handle *ti_sci;
 	struct elf_image *elf;
@@ -365,11 +353,28 @@ static int k3_r5_start_image(void)
 	struct rproc *arm64_rproc;
 
 	if (IS_ENABLED(CONFIG_USB_GADGET_DFU) && bootsource_get() == BOOTSOURCE_SERIAL)
-		do_dfu();
+		ret = do_dfu();
 	else if (k3_boot_is_emmc())
-		load_fip_emmc();
+		ret = load_fip_emmc();
 	else
-		load_images();
+		ret = load_fip("/boot/k3.fip", 0);
+
+	if (ret) {
+		pr_crit("Unable to load FIP image\n");
+		panic("Stop booting\n");
+	}
+
+	if (!have_bl31)
+		panic("No TFA found in FIP image\n");
+
+	if (!have_bl32)
+		pr_info("No OP-TEE found. Continuing without\n");
+
+	if (!have_bl33)
+		panic("No bl33 found in FIP image\n");
+
+	if (!k3_ti_dm)
+		panic("No ti-dm binary found\n");
 
 	ti_sci = ti_sci_get_handle(NULL);
 	if (IS_ERR(ti_sci))
@@ -387,9 +392,9 @@ static int k3_r5_start_image(void)
 		return PTR_ERR(elf);
 	}
 
-	err = elf_load(elf);
-	if (err) {
-		pr_err("Cannot load ELF image %pe\n", ERR_PTR(err));
+	ret = elf_load(elf);
+	if (ret) {
+		pr_err("Cannot load ELF image %pe\n", ERR_PTR(ret));
 		elf_close(elf);
 	}
 

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:27 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:27 +0100
Subject: [PATCH v2 14/14] ARM: k3: r5: select HAS_INSECURE_DEFAULTS when
 necessary
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-14-3cbbfa092346@pengutronix.de>

The R5 code will load the full barebox binary which needs to be
authenticated in order to get a secure boot flow. Select
HAS_INSECURE_DEFAULTS when no authentication method is compiled in.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-k3/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
index e93e3154c8..3dcdb20186 100644
--- a/arch/arm/mach-k3/Kconfig
+++ b/arch/arm/mach-k3/Kconfig
@@ -19,6 +19,7 @@ config MACH_K3_CORTEX_R5
 	select HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
 	depends on 32BIT
 	select ARM_USE_COMPRESSED_DTB
+	select HAS_INSECURE_DEFAULTS if (!FIRMWARE_VERIFY_NEXT_IMAGE && !ARCH_K3_AUTHENTICATE_IMAGE)
 	default y
 
 config MACH_K3_CORTEX_A

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:26 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:26 +0100
Subject: [PATCH v2 13/14] scripts: add k3sign
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-13-3cbbfa092346@pengutronix.de>

This adds k3sign which is a small example script to generate a
certificate from an input file suitable for verification against the K3
ROM API.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 scripts/k3sign | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 126 insertions(+)

diff --git a/scripts/k3sign b/scripts/k3sign
new file mode 100755
index 0000000000..df66501eee
--- /dev/null
+++ b/scripts/k3sign
@@ -0,0 +1,126 @@
+#!/bin/bash
+
+set -e
+
+myname=${0##*/}
+
+usage() {
+	cat >&2 << EOL
+
+Sign an image suitable for authenticating with the K3 ROM API
+Usage:
+$myname options <INFILE>
+options:
+	--key <KEYFILE>	The key to sign the image with
+	--out <OUTFILE>	Write output to OUTFILE
+	--help		This help
+EOL
+	exit 1
+}
+
+TEMP=$(getopt -o '' --long 'out:,key:,help' -n 'k3img' -- "$@")
+
+if [ $? -ne 0 ]; then
+	echo 'Terminating...' >&2
+	exit 1
+fi
+
+# Note the quotes around "$TEMP": they are essential!
+eval set -- "$TEMP"
+unset TEMP
+
+while true; do
+        case "$1" in
+	'--out')
+		out="$2"
+		shift 2
+		continue
+	;;
+	'--key')
+		key="$2"
+		shift 2
+		continue
+	;;
+	'--help')
+		usage
+		continue
+	;;
+	'--')
+		shift
+		break
+	;;
+	*)
+		echo 'Internal error!' >&2
+		exit 1
+	;;
+	esac
+done
+
+if [ $# = 0 ]; then
+	echo "No input file given"
+	usage
+fi
+
+in=$1
+
+if [ -z "$out" ]; then
+	out=$in.cert
+fi
+
+if [ -z "$key" ]; then
+	echo "No key given (--key)"
+	exit 1
+fi
+
+filesha=$(sha512sum $in | sed 's/ .*//')
+filesize=$(stat -c%s $in)
+
+TMPDIR="$(mktemp -d)"
+trap 'rm -rf -- "$TMPDIR"' EXIT
+
+certcfg=${TMPDIR}/certcfg
+cert=${TMPDIR}/cert
+
+cat > $certcfg <<EndOfHereDocument
+[ req ]
+distinguished_name     = req_distinguished_name
+x509_extensions        = v3_ca
+prompt                 = no
+dirstring_type         = nobmp
+
+[ req_distinguished_name ]
+C                      = US
+ST                     = TX
+L                      = Dallas
+O                      = Texas Instruments Incorporated
+OU                     = Processors
+CN                     = TI Support
+emailAddress           = support at ti.com
+
+[ v3_ca ]
+basicConstraints       = CA:true
+1.3.6.1.4.1.294.1.3    = ASN1:SEQUENCE:swrv
+1.3.6.1.4.1.294.1.34   = ASN1:SEQUENCE:sysfw_image_integrity
+1.3.6.1.4.1.294.1.35   = ASN1:SEQUENCE:sysfw_image_load
+1.3.6.1.4.1.294.1.37   = ASN1:SEQUENCE:firewall
+
+[ swrv ]
+swrv = INTEGER:1
+
+[ sysfw_image_integrity ]
+shaType                = OID:2.16.840.1.101.3.4.2.3
+shaValue               = FORMAT:HEX,OCT:$filesha
+imageSize              = INTEGER:$filesize
+
+[ sysfw_image_load ]
+destAddr = FORMAT:HEX,OCT:00000000
+authInPlace = INTEGER:0x2
+
+[ firewall ]
+numFirewallRegions = INTEGER:0
+
+EndOfHereDocument
+
+openssl req -new -x509 -key $key -nodes -outform DER -out $cert -config $certcfg -sha512
+
+cat $cert $in > $out

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:25 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:25 +0100
Subject: [PATCH v2 12/14] scripts/k3img: remove temporary files
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-12-3cbbfa092346@pengutronix.de>

Remove temporary files when exiting the script. While at it add a "set
-e" to exit the script when a command fails.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 scripts/k3img | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/scripts/k3img b/scripts/k3img
index 048da82b92..a514852fcd 100755
--- a/scripts/k3img
+++ b/scripts/k3img
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+set -e
+
 TEMP=$(getopt -o '' --long 'sysfw:,sysfwdata:,dmdata:,out:,sbl:,key:,innerdata:' -n 'k3img' -- "$@")
 
 if [ $? -ne 0 ]; then
@@ -76,8 +78,11 @@ dmdatasize=$(stat -c%s $dmdata)
 
 total=$(($sblsize + $sysfwsize + $sysfwdatasize + $dmdatasize))
 
-certcfg=$(mktemp k3img.XXXXXXX)
-cert=$(mktemp k3img.XXXXXXX)
+TMPDIR="$(mktemp -d)"
+trap 'rm -rf -- "$TMPDIR"' EXIT
+
+certcfg=${TMPDIR}/certcfg
+cert=${TMPDIR}/cert
 
 num_comp=4
 

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:23 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:23 +0100
Subject: [PATCH v2 10/14] ARM: k3: r5: delete fip image when it can't be
 opened
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-10-3cbbfa092346@pengutronix.de>

In case the uploaded FIP image can't be opened due to corruption of
the image we end up in an endless loop trying to open the same image
again and again. Delete the uploaded image in this case to give the
user a chance to upload another image.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-k3/r5.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
index 79bdb7aac7..e7133ff4ab 100644
--- a/arch/arm/mach-k3/r5.c
+++ b/arch/arm/mach-k3/r5.c
@@ -319,6 +319,7 @@ static int do_dfu(void)
 			ret = load_fip("/fip.img", 0);
 			if (!ret)
 				return 0;
+			unlink("/fip.img");
 		}
 
 		command_slice_release();

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 11 05:25:24 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Mar 2025 13:25:24 +0100
Subject: [PATCH v2 11/14] ARM: k3: r5: Allow to authenticate next image by
 ROM API
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <20250311-am625-secure-v2-11-3cbbfa092346@pengutronix.de>

This adds the Kconfig option CONFIG_ARCH_K3_AUTHENTICATE_IMAGE. When
enabled, the full barebox image will only be started when it can be
authenticated using the ROM API.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-k3/Kconfig |  7 ++++++
 arch/arm/mach-k3/r5.c    | 64 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
index 37d5155577..e93e3154c8 100644
--- a/arch/arm/mach-k3/Kconfig
+++ b/arch/arm/mach-k3/Kconfig
@@ -37,6 +37,13 @@ config MACH_BEAGLEPLAY
 	help
 	  Say Y here if you are using a TI AM62x based BeaglePlay board
 
+config ARCH_K3_AUTHENTICATE_IMAGE
+	bool "Force authentication of FIP image against ROM API"
+	help
+	  By enabling this option the FIP image loaded by the first stage
+	  will be authenticated against the K3 ROM API. Images which fail
+	  to authenticate will not be started.
+
 config ARCH_K3_COMMAND_AUTHENTICATE
 	bool "k3_authenticate_image command"
 	depends on COMMAND_SUPPORT
diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
index e7133ff4ab..83089b8444 100644
--- a/arch/arm/mach-k3/r5.c
+++ b/arch/arm/mach-k3/r5.c
@@ -244,6 +244,64 @@ static uuid_t uuid_ti_dm_fw = UUID_TI_DM_FW;
 static uuid_t uuid_bl33 = UUID_NON_TRUSTED_FIRMWARE_BL33;
 static uuid_t uuid_bl32 = UUID_SECURE_PAYLOAD_BL32;
 
+static struct fip_state *fip_image_load_auth(const char *filename, size_t offset)
+{
+	struct fip_state *fip = NULL;
+	int fd;
+	unsigned int maxsize = SZ_4M;
+	size_t size;
+	void *buf = NULL;
+	int ret;
+
+	fd = open(filename, O_RDONLY);
+	if (fd < 0)
+		return ERR_PTR(-errno);
+
+	if (offset) {
+		loff_t pos;
+		pos = lseek(fd, offset, SEEK_SET);
+		if (pos < 0) {
+			ret = -errno;
+			goto err;
+		}
+	}
+
+	buf = xzalloc(maxsize);
+
+	/*
+	 * There is no easy way to determine the size of the certificates the ROM
+	 * takes as images, so the best we can do here is to assume a maximum size
+	 * and load this.
+	 */
+	ret = read_full(fd, buf, maxsize);
+	if (ret < 0)
+		goto err;
+
+	size = maxsize;
+
+	ret = k3_authenticate_image(&buf, &size);
+	if (ret) {
+		pr_err("Failed to authenticate %s\n", filename);
+		goto err;
+	}
+
+	fip = fip_new();
+	ret = fip_parse_buf(fip, buf, size, NULL);
+	if (ret)
+		goto err;
+
+	close(fd);
+
+	return fip;
+err:
+	if (fip)
+		fip_free(fip);
+	close(fd);
+	free(buf);
+
+	return ERR_PTR(ret);
+}
+
 static int load_fip(const char *filename, off_t offset)
 {
 	struct fip_state *fip;
@@ -251,7 +309,11 @@ static int load_fip(const char *filename, off_t offset)
 	unsigned char shasum[SHA256_DIGEST_SIZE];
 	int ret;
 
-	fip = fip_image_open(filename, offset);
+	if (IS_ENABLED(CONFIG_ARCH_K3_AUTHENTICATE_IMAGE))
+		fip = fip_image_load_auth(filename, offset);
+	else
+		fip = fip_image_open(filename, offset);
+
 	if (IS_ERR(fip)) {
 		pr_err("Cannot open FIP image: %pe\n", fip);
 		return PTR_ERR(fip);

-- 
2.39.5



From m.felsch at pengutronix.de  Tue Mar 11 06:13:05 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 11 Mar 2025 14:13:05 +0100
Subject: [PATCH v2 01/14] firmware: always generate sha256sum
In-Reply-To: <20250311-am625-secure-v2-1-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
 <20250311-am625-secure-v2-1-3cbbfa092346@pengutronix.de>
Message-ID: <20250311131305.acet5bh6g6etggm4@pengutronix.de>

On 25-03-11, Sascha Hauer wrote:
> Right now we only generate the sha256 for firmware files that are
> loaded from an external binary. Instead, always generate the sha256
> which helps with upcoming support for checking the next image hash.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>


From m.felsch at pengutronix.de  Tue Mar 11 06:19:21 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 11 Mar 2025 14:19:21 +0100
Subject: [PATCH v2 02/14] firmware: add function to verify next image
In-Reply-To: <20250311-am625-secure-v2-2-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
 <20250311-am625-secure-v2-2-3cbbfa092346@pengutronix.de>
Message-ID: <20250311131921.qk256ikyiksqmomf@pengutronix.de>

On 25-03-11, Sascha Hauer wrote:
> Some SoCs use a startup sequence that includes multiple stages where a
> full barebox is loaded by an early small barebox that fits into the
> SoC's SRAM. This is commonly referred to as xload. In a secure boot
> environment it's necessary to load only trusted barebox images. One
> way to accomplish this is to compile a sha256 into the first stage
> barebox and to verify the full barebox against this hash.
> 
> This patch adds the generic parts for this. The full barebox binary
> can be put into the first stage build as a firmware file. The firmware
> itself won't be used, only the hash is compiled into the image. SoC
> code can then check the full barebox image against the hash. As this
> requires SoC code to check the hash, the option is hidden behind
> CONFIG_HAVE_FIRMWARE_VERIFY_NEXT_IMAGE. SoC code can select this option
> when it implements the required hash checking.
> 
> It's worth noting that using a hash for verification has one advantage
> over cryptographicaly signing followup images: It ties first stage
> and full barebox stages together effectively avoiding mix-and-match
> attacks.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  firmware/Kconfig   | 23 +++++++++++++++++++++++
>  firmware/Makefile  |  2 ++
>  include/firmware.h | 26 ++++++++++++++++++++++++++
>  3 files changed, 51 insertions(+)
> 
> diff --git a/firmware/Kconfig b/firmware/Kconfig
> index ba005976c5..bdb71321bc 100644
> --- a/firmware/Kconfig
> +++ b/firmware/Kconfig
> @@ -108,4 +108,27 @@ config FIRMWARE_LS1028A_ATF
>  config FIRMWARE_LS1046A_ATF
>  	bool
>  
> +config HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
> +	bool
> +
> +config FIRMWARE_VERIFY_NEXT_IMAGE
> +	depends on HAVE_FIRMWARE_VERIFY_NEXT_IMAGE
> +	bool "verify next image to load"
> +	help
> +	  The boot process of some SoCs uses multiple stages where the first stage is
> +	  a stripped down barebox loaded by the SoC's ROM and the next state is a full
> +	  barebox loaded by the first stage. In a trusted boot scenario the next stage
> +	  has to be verified by the first stage,
> +
> +	  This option allows to specify the next image to be loaded. Put the next stage
> +	  image to firmware/next-image.bin. The image itself is not used, but a sha256
> +	  hash of the image will be generated and compiled into the first stage which
> +	  can be used to verify the next stage.

Nit I would mention that the next-image.bin won't be part of the final
binary if not referenced, e.g: 

  The next-image.bin won't be added to final barebox binary if not referenced.

Apart of this, feel free to add my

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>

Regards,
  Marco

> +
> +	  Note that this option only enabled generation of the sha256 hash. Loading and
> +	  starting the next stage is highly SoC dependent and it's the SoC code's
> +	  responsibility to actually verify the hash and to only start successfully
> +	  verified images. The function to check the next stage image hash is
> +	  firmware_next_image_verify(), make sure your SoC code uses it.
> +
>  endmenu
> diff --git a/firmware/Makefile b/firmware/Makefile
> index 095d6f0e31..67fd898890 100644
> --- a/firmware/Makefile
> +++ b/firmware/Makefile
> @@ -34,6 +34,8 @@ pbl-firmware-$(CONFIG_ARCH_RK3588) += rk3588-bl32.bin
>  pbl-firmware-$(CONFIG_ARCH_RK3399) += rk3399-bl32.bin
>  endif
>  
> +firmware-$(CONFIG_FIRMWARE_NEXT_IMAGE) += next-image.bin
> +
>  firmware-$(CONFIG_DRIVER_NET_FSL_FMAN) += fsl_fman_ucode_ls1046_r1.0_106_4_18.bin
>  
>  fw-external-$(CONFIG_FIRMWARE_LS1028A_ATF) += ls1028a-bl31.bin
> diff --git a/include/firmware.h b/include/firmware.h
> index d7feae1371..ab518cb432 100644
> --- a/include/firmware.h
> +++ b/include/firmware.h
> @@ -13,6 +13,8 @@
>  #include <debug_ll.h>
>  #include <linux/kernel.h>
>  #include <asm/sections.h>
> +#include <crypto/sha.h>
> +#include <crypto.h>
>  
>  struct firmware {
>  	size_t size;
> @@ -113,4 +115,28 @@ static inline void firmware_ext_verify(const void *data_start, size_t data_size,
>  #define get_builtin_firmware_ext(name, base, start, size)		\
>  	__get_builtin_firmware(name, (long)base - (long)_text, start, size)
>  
> +static inline int firmware_next_image_check_sha256(const void *hash, bool verbose)
> +{
> +	extern char _fw_next_image_bin_sha_start[];
> +	int hsize = SHA256_DIGEST_SIZE;
> +	int ret;
> +
> +	if (!IS_ENABLED(CONFIG_FIRMWARE_NEXT_IMAGE))
> +		return -EINVAL;
> +
> +	ret = crypto_memneq(hash, _fw_next_image_bin_sha_start, hsize);
> +
> +	if (verbose) {
> +		if (ret) {
> +			pr_err("next image hash mismatch!\n");
> +			pr_err("expected: sha256=%*phN\n", hsize, _fw_next_image_bin_sha_start);
> +			pr_err("found:    sha256=%*phN\n", hsize, hash);
> +		} else {
> +			pr_info("hash sha256=%*phN OK\n", hsize, _fw_next_image_bin_sha_start);
> +		}
> +	}
> +
> +	return ret;
> +}
> +
>  #endif /* FIRMWARE_H */
> 
> -- 
> 2.39.5
> 
> 
> 


From m.felsch at pengutronix.de  Tue Mar 11 06:20:36 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 11 Mar 2025 14:20:36 +0100
Subject: [PATCH v2 03/14] ARM: k3: r5: drop loading of separate binaries
In-Reply-To: <20250311-am625-secure-v2-3-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
 <20250311-am625-secure-v2-3-3cbbfa092346@pengutronix.de>
Message-ID: <20250311132036.45dqfeeeq3xepxfs@pengutronix.de>

On 25-03-11, Sascha Hauer wrote:
> For starting the A52 cores we need TFA, OP-TEE, barebox and ti-dm
		     ^
		     3?

> binaries. These can be loaded as separate files from SD/eMMC/DFU or
> alternatively combined into a single FIP image.
> FIP images are convenient to handle, they can easily be generated on the
> command line and fiptool also has support for replacing blobs in images.
> This makes handling of separate binaries rather unnecessary and support
> for it only makes the loading code more complex. Drop it and make FIP
> images the only option which also faciliates integrating of secure boot.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>


From m.felsch at pengutronix.de  Tue Mar 11 06:21:31 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 11 Mar 2025 14:21:31 +0100
Subject: [PATCH v2 04/14] ARM: k3: r5: add proper error handling
In-Reply-To: <20250311-am625-secure-v2-4-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
 <20250311-am625-secure-v2-4-3cbbfa092346@pengutronix.de>
Message-ID: <20250311132131.fpkqincgdmxo3duv@pengutronix.de>

On 25-03-11, Sascha Hauer wrote:
> Add missing error handling in the image loading code. Properly check for
> errors and panic when mandatory binaries are missing instead of blindly
> continuing.
> 
> While at it change the return value variable from 'err' to 'ret' to stay
> consistent with the rest of the code in r5.c.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>


From m.felsch at pengutronix.de  Tue Mar 11 06:42:07 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 11 Mar 2025 14:42:07 +0100
Subject: [PATCH v2 05/14] fip: rework fip_image_open()
In-Reply-To: <20250311-am625-secure-v2-5-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
 <20250311-am625-secure-v2-5-3cbbfa092346@pengutronix.de>
Message-ID: <20250311134207.x4o2ccin3jx6pdpj@pengutronix.de>

On 25-03-11, Sascha Hauer wrote:
> fip_image_open() used to do all the parsing into a struct fip_state
> itself. Instead, only load the FIP image into a buffer and call
> fip_do_parse_buf() with this buffer. This has the advantage that we
> have all parsing of the FIP image in a single place. Also this helps
> with a followup patch which calculates a sha256 over a FIP image
> which can easily done when we have the whole FIP image in a contiguous
> buffer.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  lib/fip.c | 78 +++++++++++++++++++++++++++++++++------------------------------
>  1 file changed, 41 insertions(+), 37 deletions(-)
> 
> diff --git a/lib/fip.c b/lib/fip.c
> index 23e82098da..aab2795476 100644
> --- a/lib/fip.c
> +++ b/lib/fip.c
> @@ -23,6 +23,7 @@
>  #include <string.h>
>  #include <libfile.h>
>  #include <fs.h>
> +#include <linux/kernel.h>
>  
>  #include <fip.h>
>  #include <fiptool.h>
> @@ -447,22 +448,17 @@ int fip_update(struct fip_state *fip)
>  }
>  
>  /*
> - * fip_image_open - open a FIP image for readonly access
> + * fip_image_open - open a FIP image
>   * @filename: The filename of the FIP image
>   * @offset: The offset of the FIP image in the file
>   *
> - * This opens a FIP image for readonly access. This is an alternative
> - * implementation for fip_parse() with these differences:
> + * This opens a FIP image. This is an alternative implementation for
> + * fip_parse() with these differences:
>   * - suitable for reading FIP images from raw partitions. This function
>   *   only reads the FIP image, even when the partition is bigger than the
>   *   image
>   * - Allows to specify an offset within the partition where the FIP image
>   *   starts
> - * - Do not memdup the images from the full FIP image
> - *
> - * This function is for easy readonly access to the images within the FIP
> - * image. Do not call any of the above FIP manipulation functions other than
> - * fip_free() on an image opened with this function.
>   */
>  struct fip_state *fip_image_open(const char *filename, size_t offset)
>  {
> @@ -470,11 +466,13 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
>  	int ret;
>  	int fd;
>  	struct fip_state *fip_state;
> -	LIST_HEAD(entries);
>  	size_t fip_headers_size, total = 0;
> -	struct fip_image_desc *desc;
>  	off_t pos;
>  	int n_entries = 0;
> +	struct fip_toc_entry toc_entries[16];
				 	 ^
Why did you used 16?

> +	void *buf, *ptr;
> +	int i;
> +	struct fip_toc_entry *toc_entry;
>  
>  	fd = open(filename, O_RDONLY);
>  	if (fd < 0)
> @@ -506,11 +504,9 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
>  
>  	/* read all toc entries */
>  	while (1) {
> -		struct fip_image_desc *desc = xzalloc(sizeof(*desc));
> -		struct fip_image *image = xzalloc(sizeof(*image));
> -		struct fip_toc_entry *toc_entry = &image->toc_e;
> +		uint64_t this_end;
>  
> -		desc->image = image;
> +		toc_entry = &toc_entries[n_entries];
>  
>  		ret = read_full(fd, toc_entry, sizeof(*toc_entry));
>  		if (ret < 0)
> @@ -520,53 +516,61 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
>  			goto err;
>  		}
>  
> -		list_add_tail(&desc->list, &fip_state->descs);
> -
>  		pr_debug("Read TOC entry %pU %llu %llu\n", &toc_entry->uuid,
>  			 toc_entry->offset_address, toc_entry->size);
>  
> -		/* Found the ToC terminator, we are done. */
> -		if (uuid_is_null(&toc_entry->uuid))
> -			break;
> -	}
> -
> -	/* determine buffer size */
> -	fip_for_each_desc(fip_state, desc) {
> -		uint64_t this_end = desc->image->toc_e.offset_address + desc->image->toc_e.size;
> +		this_end = toc_entry->offset_address + toc_entry->size;
>  
>  		if (this_end > total)
>  			total = this_end;
> +
>  		n_entries++;
> -	}
>  
> -	fip_headers_size = n_entries * sizeof(struct fip_toc_entry) + sizeof(fip_toc_header_t);
> +		if (n_entries >= ARRAY_SIZE(toc_entries)) {

			pr_err("Error: Only 16 toc-entries are supported at the moment\n");

> +			ret = -ENOSPC;
> +			goto err;
> +		}
>  
> -	total -= fip_headers_size;
> +		/* Found the ToC terminator, we are done. */
> +		if (uuid_is_null(&toc_entry->uuid))
> +			break;

If this check is happening after the n_entries check, we trigger a
false-positive in case of a 16-entries FIP.

Regards,
  Marco

> +	}
>  
> -	fip_state->buffer = malloc(total);
> -	if (!fip_state->buffer) {
> +	buf = malloc(total);
> +	if (!buf) {
>  		ret = -ENOMEM;
>  		goto err;
>  	}
>  
> -	ret = read_full(fd, fip_state->buffer, total);
> +	ptr = buf;
> +
> +	memcpy(ptr, &toc_header, sizeof(toc_header));
> +	ptr += sizeof(toc_header);
> +
> +	for (i = 0; i < n_entries; i++) {
> +		memcpy(ptr, &toc_entries[i], sizeof(*toc_entry));
> +		ptr += sizeof(*toc_entry);
> +	}
> +
> +	fip_headers_size = n_entries * sizeof(struct fip_toc_entry) + sizeof(fip_toc_header_t);
> +
> +	ret = read_full(fd, ptr, total - fip_headers_size);
>  	if (ret < 0)
>  		goto err;
>  
> -	if (ret < total) {
> +	if (ret < total - fip_headers_size) {
>  		ret = -ENODATA;
>  		goto err;
>  	}
>  
> -	close(fd);
> +	ret = fip_do_parse_buf(fip_state, buf, total, NULL);
> +	if (ret)
> +		goto err;
>  
> -	fip_for_each_desc(fip_state, desc) {
> -		desc->image->buffer = fip_state->buffer +
> -			desc->image->toc_e.offset_address - fip_headers_size;
> -		desc->image->buf_no_free = true;
> -	}
> +	close(fd);
>  
>  	return fip_state;
> +
>  err:
>  	close(fd);
>  	fip_free(fip_state);
> 
> -- 
> 2.39.5
> 
> 
> 


From m.felsch at pengutronix.de  Tue Mar 11 06:43:49 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 11 Mar 2025 14:43:49 +0100
Subject: [PATCH v2 07/14] fip: add function to calculate a sha256 over
 FIP image
In-Reply-To: <20250311-am625-secure-v2-7-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
 <20250311-am625-secure-v2-7-3cbbfa092346@pengutronix.de>
Message-ID: <20250311134349.kresmi7nbwffa2pn@pengutronix.de>

On 25-03-11, Sascha Hauer wrote:
> This adds fip_sha256() to calculate a sha256 over a FIP image.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>

> ---
>  include/fiptool.h |  3 +++
>  lib/fip.c         | 23 ++++++++++++++++++++++-
>  2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/include/fiptool.h b/include/fiptool.h
> index bb63a79c16..73b0fbe398 100644
> --- a/include/fiptool.h
> +++ b/include/fiptool.h
> @@ -38,6 +38,7 @@ struct fip_state {
>  	size_t nr_image_descs;
>  	int verbose;
>  	void *buffer;
> +	size_t bufsize;
>  	bool buf_no_free;
>  };
>  
> @@ -100,4 +101,6 @@ extern toc_entry_t plat_def_toc_entries[];
>  
>  struct fip_state *fip_image_open(const char *filename, size_t offset);
>  
> +int fip_sha256(struct fip_state *fip, char *hash);
> +
>  #endif /* FIPTOOL_H */
> diff --git a/lib/fip.c b/lib/fip.c
> index 8086b43412..7a5e3dc844 100644
> --- a/lib/fip.c
> +++ b/lib/fip.c
> @@ -24,6 +24,7 @@
>  #include <libfile.h>
>  #include <fs.h>
>  #include <linux/kernel.h>
> +#include <digest.h>
>  
>  #include <fip.h>
>  #include <fiptool.h>
> @@ -168,6 +169,7 @@ static int fip_do_parse_buf(struct fip_state *fip, void *buf, size_t size,
>  	int terminated = 0;
>  
>  	fip->buffer = buf;
> +	fip->bufsize = size;
>  
>  	bufend = fip->buffer + size;
>  
> @@ -570,10 +572,29 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
>  	close(fd);
>  
>  	return fip_state;
> -
>  err:
>  	close(fd);
>  	fip_free(fip_state);
>  
>  	return ERR_PTR(ret);
>  }
> +
> +int fip_sha256(struct fip_state *fip, char *hash)
> +{
> +	struct digest *d;
> +	int ret;
> +
> +	d = digest_alloc_by_algo(HASH_ALGO_SHA256);
> +	if (!d)
> +		return -ENOSYS;
> +
> +	digest_init(d);
> +
> +	digest_update(d, fip->buffer, fip->bufsize);
> +
> +	ret = digest_final(d, hash);
> +
> +	digest_free(d);
> +
> +	return ret;
> +}
> 
> -- 
> 2.39.5
> 
> 
> 


From m.felsch at pengutronix.de  Tue Mar 11 06:44:28 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 11 Mar 2025 14:44:28 +0100
Subject: [PATCH v2 08/14] ARM: am625: support hash verification of full
 barebox
In-Reply-To: <20250311-am625-secure-v2-8-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
 <20250311-am625-secure-v2-8-3cbbfa092346@pengutronix.de>
Message-ID: <20250311134428.4xildaqnt4f5bwhi@pengutronix.de>

On 25-03-11, Sascha Hauer wrote:
> This implements the necessary SoC code to check the full barebox against
> a sha256 compiled into the first stage barebox.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>


From m.felsch at pengutronix.de  Tue Mar 11 06:46:44 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 11 Mar 2025 14:46:44 +0100
Subject: [PATCH v2 14/14] ARM: k3: r5: select HAS_INSECURE_DEFAULTS when
 necessary
In-Reply-To: <20250311-am625-secure-v2-14-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
 <20250311-am625-secure-v2-14-3cbbfa092346@pengutronix.de>
Message-ID: <20250311134644.6gt4fdw4gqpr5mvg@pengutronix.de>

On 25-03-11, Sascha Hauer wrote:
> The R5 code will load the full barebox binary which needs to be
> authenticated in order to get a secure boot flow. Select
> HAS_INSECURE_DEFAULTS when no authentication method is compiled in.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>


From jonas.licht at gmail.com  Tue Mar 11 07:17:13 2025
From: jonas.licht at gmail.com (Jonas Licht)
Date: Tue, 11 Mar 2025 15:17:13 +0100
Subject: [PATCH] environment: support reading and writing of efivar
Message-ID: <20250311141713.30947-1-jonas.licht@gmail.com>

scripts/bareboxenv: skip file creation to allow reading the destination
file, when existing.

Signed-off-by: Jonas Licht <jonas.licht at gmail.com>
Fixes #29
---
 common/environment.c | 62 +++++++++++++++++++++++++++++++++++++++-----
 scripts/bareboxenv.c | 11 +-------
 2 files changed, 57 insertions(+), 16 deletions(-)

diff --git a/common/environment.c b/common/environment.c
index 37adb5d678..dee746a6b2 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -305,9 +305,10 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 	struct envfs_super *super;
 	int envfd, size, ret;
 	struct action_data data = {};
-	void *buf = NULL, *wbuf;
+	void *buf = NULL, *wbuf, *bufWithEfi;
 	struct envfs_entry *env;
 	const char *defenv_path = default_environment_path_get();
+	uint32_t magic;
 
 	if (!filename)
 		filename = defenv_path;
@@ -342,7 +343,9 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 		}
 	}
 
-	buf = xzalloc(size + sizeof(struct envfs_super));
+	bufWithEfi = xzalloc(size + sizeof(struct envfs_super) +
+			     4); // four byte efi attributes
+	buf = bufWithEfi + 4;
 	data.writep = buf + sizeof(struct envfs_super);
 
 	super = buf;
@@ -370,7 +373,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 	super->crc = ENVFS_32(crc32(0, buf + sizeof(struct envfs_super), size));
 	super->sb_crc = ENVFS_32(crc32(0, buf, sizeof(struct envfs_super) - 4));
 
-	envfd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
+	envfd = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
 	if (envfd < 0) {
 		printf("could not open %s: %m\n", filename);
 		ret = -errno;
@@ -385,6 +388,34 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 		goto out;
 	}
 
+	wbuf = buf;
+
+	/* check if we writing efi vars */
+	ret = pread(envfd, &magic, sizeof(uint32_t),
+		    4); // four byte efi var attributes
+	if (ret == -1 && errno == ENOENT) {
+		// skip as file don't exist
+		goto skip_efi_read;
+	}
+	if (ret < sizeof(u_int32_t)) {
+		perror("read of destination file failed");
+		ret = -errno;
+		goto skip_efi_read;
+	}
+
+	if (ENVFS_32(magic) == ENVFS_MAGIC) {
+		pr_info("looks like we writing efi vars, keep attributes\n");
+		ret = pread(envfd, bufWithEfi, sizeof(uint32_t), 0);
+		if (ret < sizeof(uint32_t)) {
+			perror("read of efi attributes failed");
+			ret = -errno;
+			goto out;
+		}
+		size += sizeof(uint32_t);
+		wbuf = bufWithEfi;
+	}
+
+skip_efi_read:
 	ret = erase(envfd, ERASE_SIZE_ALL, 0, ERASE_TO_WRITE);
 
 	/* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */
@@ -395,8 +426,6 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 
 	size += sizeof(struct envfs_super);
 
-	wbuf = buf;
-
 	while (size) {
 		ssize_t now = write(envfd, wbuf, size);
 		if (now < 0) {
@@ -425,7 +454,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 out:
 	close(envfd);
 out1:
-	free(buf);
+	free(bufWithEfi);
 #ifdef __BAREBOX__
 	unlink_recursive(TMPDIR, NULL);
 #endif
@@ -449,6 +478,7 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
 	int envfd;
 	int ret = 0;
 	size_t size, rsize;
+	uint32_t magic;
 
 	if (!filename)
 		filename = default_environment_path_get();
@@ -466,6 +496,26 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
 		return -1;
 	}
 
+	/* check if we reading efi vars */
+	ret = pread(envfd, &magic, sizeof(uint32_t),
+		    4); // four byte efi var attributes
+	if (ret < sizeof(u_int32_t)) {
+		perror("read");
+		ret = -errno;
+		goto out;
+	}
+
+	if (ENVFS_32(magic) == ENVFS_MAGIC) {
+		pr_info("looks like we reading efi vars, skip attributes\n");
+		ret = read(envfd, &magic,
+			   sizeof(uint32_t)); // simply reuse the memory
+		if (ret < sizeof(uint32_t)) {
+			perror("read");
+			ret = -errno;
+			goto out;
+		}
+	}
+
 	/* read superblock */
 	ret = read(envfd, &super, sizeof(struct envfs_super));
 	if ( ret < sizeof(struct envfs_super)) {
diff --git a/scripts/bareboxenv.c b/scripts/bareboxenv.c
index e954447015..6b9b8d90c4 100644
--- a/scripts/bareboxenv.c
+++ b/scripts/bareboxenv.c
@@ -117,7 +117,7 @@ static void usage(char *prgname)
 int main(int argc, char *argv[])
 {
 	int opt;
-	int save = 0, load = 0, pad = 0, err = 0, fd;
+	int save = 0, load = 0, pad = 0, err = 0;
 	char *filename = NULL, *dirname = NULL;
 	unsigned envfs_flags = 0;
 	int verbose = 0;
@@ -156,15 +156,6 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	if (save) {
-		fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0644);
-		if (fd < 0) {
-			perror("open");
-			exit(1);
-		}
-		close(fd);
-	}
-
 	if (save && pad) {
 		if (truncate(filename, pad)) {
 			perror("truncate");
-- 
2.45.3



From s.hauer at pengutronix.de  Wed Mar 12 03:22:30 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 11:22:30 +0100
Subject: [PATCH master] i.MX: HAB: fix i.MX8MP field-return fuse
In-Reply-To: <20250310113626.2241630-1-m.felsch@pengutronix.de>
References: <20250310113626.2241630-1-m.felsch@pengutronix.de>
Message-ID: <174177495024.893398.9248321381901871386.b4-ty@pengutronix.de>


On Mon, 10 Mar 2025 12:36:26 +0100, Marco Felsch wrote:
> Current tests showed that fusing just the single field-return bit(0) on
> i.MX8MP SoCs brick the device.
> 
> All i.MX8M SoCs have a single field-return bit except for the i.MX8MP
> which requires a pattern. The pattern is not documented but was
> discussed here [1] and the final u-boot commit [2] added the support
> accordingly.
> 
> [...]

Applied, thanks!

[1/1] i.MX: HAB: fix i.MX8MP field-return fuse
      https://git.pengutronix.de/cgit/barebox/commit/?id=51a10d4fd531 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Wed Mar 12 03:22:30 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 11:22:30 +0100
Subject: [PATCH v2 00/14] am625: support secure loading of full barebox
In-Reply-To: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
Message-ID: <174177495026.893398.8971903707546072946.b4-ty@pengutronix.de>


On Tue, 11 Mar 2025 13:25:13 +0100, Sascha Hauer wrote:
> On K3 SoCs only a small barebox is loaded by the ROM into SRAM. This
> barebox then loads the full barebox from SD/eMMC or USB DFU. In a secure
> boot environment the full barebox must be authenticated. This series
> implements two ways for accomplishing this.
> 
> First way is to utilize the ROM API to authenticate images. The other
> way is to compile a secure hash into the first stage binary and check
> if the full barebox image matches the hash. Using the ROM API means
> different first stage and second stage images can be combined whereas
> hashing binds specific builds together avoiding mix and match attacks.
> 
> [...]

Applied, thanks!

[01/14] firmware: always generate sha256sum
        https://git.pengutronix.de/cgit/barebox/commit/?id=4fa921792285 (link may not be stable)
[02/14] firmware: add function to verify next image
        https://git.pengutronix.de/cgit/barebox/commit/?id=8c711a697ce5 (link may not be stable)
[03/14] ARM: k3: r5: drop loading of separate binaries
        https://git.pengutronix.de/cgit/barebox/commit/?id=1bc97b7995e1 (link may not be stable)
[04/14] ARM: k3: r5: add proper error handling
        https://git.pengutronix.de/cgit/barebox/commit/?id=f382d0e799bc (link may not be stable)
[05/14] fip: rework fip_image_open()
        https://git.pengutronix.de/cgit/barebox/commit/?id=a7e5e42a2dc5 (link may not be stable)
[06/14] fip: fix wrong function call
        https://git.pengutronix.de/cgit/barebox/commit/?id=14308afd22ac (link may not be stable)
[07/14] fip: add function to calculate a sha256 over FIP image
        https://git.pengutronix.de/cgit/barebox/commit/?id=096dc30fcfd4 (link may not be stable)
[08/14] ARM: am625: support hash verification of full barebox
        https://git.pengutronix.de/cgit/barebox/commit/?id=0e0b9a236be4 (link may not be stable)
[09/14] ARM: k3: add support for authenticating images against the ROM API
        https://git.pengutronix.de/cgit/barebox/commit/?id=c2bde368cf28 (link may not be stable)
[10/14] ARM: k3: r5: delete fip image when it can't be opened
        https://git.pengutronix.de/cgit/barebox/commit/?id=c2a3a4dbc2c5 (link may not be stable)
[11/14] ARM: k3: r5: Allow to authenticate next image by ROM API
        https://git.pengutronix.de/cgit/barebox/commit/?id=eddc4c708d5f (link may not be stable)
[12/14] scripts/k3img: remove temporary files
        https://git.pengutronix.de/cgit/barebox/commit/?id=2665beee87cf (link may not be stable)
[13/14] scripts: add k3sign
        https://git.pengutronix.de/cgit/barebox/commit/?id=f450ef453e88 (link may not be stable)
[14/14] ARM: k3: r5: select HAS_INSECURE_DEFAULTS when necessary
        https://git.pengutronix.de/cgit/barebox/commit/?id=d4444f3cb892 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Wed Mar 12 04:02:36 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 12:02:36 +0100
Subject: [PATCH v2 05/14] fip: rework fip_image_open()
In-Reply-To: <20250311134207.x4o2ccin3jx6pdpj@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
 <20250311-am625-secure-v2-5-3cbbfa092346@pengutronix.de>
 <20250311134207.x4o2ccin3jx6pdpj@pengutronix.de>
Message-ID: <Z9FpzJGBShGoi0Ji@pengutronix.de>

On Tue, Mar 11, 2025 at 02:42:07PM +0100, Marco Felsch wrote:
> >  struct fip_state *fip_image_open(const char *filename, size_t offset)
> >  {
> > @@ -470,11 +466,13 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
> >  	int ret;
> >  	int fd;
> >  	struct fip_state *fip_state;
> > -	LIST_HEAD(entries);
> >  	size_t fip_headers_size, total = 0;
> > -	struct fip_image_desc *desc;
> >  	off_t pos;
> >  	int n_entries = 0;
> > +	struct fip_toc_entry toc_entries[16];
> 				 	 ^
> Why did you used 16?

Okay okay, I allocated the entries dynamically now to support an
arbitrary number of toc entries.

Sascha

-------------------------------8<------------------------------

>From 87bc7468e698e3404345ee601885ec186de7f4fa Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer at pengutronix.de>
Date: Tue, 11 Mar 2025 13:25:18 +0100
Subject: [PATCH] fip: rework fip_image_open()

fip_image_open() used to do all the parsing into a struct fip_state
itself. Instead, only load the FIP image into a buffer and call
fip_do_parse_buf() with this buffer. This has the advantage that we
have all parsing of the FIP image in a single place. Also this helps
with a followup patch which calculates a sha256 over a FIP image
which can easily done when we have the whole FIP image in a contiguous
buffer.

Link: https://lore.kernel.org/r/20250311-am625-secure-v2-5-3cbbfa092346 at pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 lib/fip.c | 90 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 53 insertions(+), 37 deletions(-)

diff --git a/lib/fip.c b/lib/fip.c
index 23e82098da..0d4ea54605 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -23,6 +23,8 @@
 #include <string.h>
 #include <libfile.h>
 #include <fs.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
 
 #include <fip.h>
 #include <fiptool.h>
@@ -446,23 +448,23 @@ int fip_update(struct fip_state *fip)
 	return 0;
 }
 
+struct toc_entry_list {
+	struct fip_toc_entry toc;
+	struct list_head list;
+};
+
 /*
- * fip_image_open - open a FIP image for readonly access
+ * fip_image_open - open a FIP image
  * @filename: The filename of the FIP image
  * @offset: The offset of the FIP image in the file
  *
- * This opens a FIP image for readonly access. This is an alternative
- * implementation for fip_parse() with these differences:
+ * This opens a FIP image. This is an alternative implementation for
+ * fip_parse() with these differences:
  * - suitable for reading FIP images from raw partitions. This function
  *   only reads the FIP image, even when the partition is bigger than the
  *   image
  * - Allows to specify an offset within the partition where the FIP image
  *   starts
- * - Do not memdup the images from the full FIP image
- *
- * This function is for easy readonly access to the images within the FIP
- * image. Do not call any of the above FIP manipulation functions other than
- * fip_free() on an image opened with this function.
  */
 struct fip_state *fip_image_open(const char *filename, size_t offset)
 {
@@ -470,11 +472,13 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
 	int ret;
 	int fd;
 	struct fip_state *fip_state;
-	LIST_HEAD(entries);
 	size_t fip_headers_size, total = 0;
-	struct fip_image_desc *desc;
 	off_t pos;
 	int n_entries = 0;
+	void *buf, *ptr;
+	struct fip_toc_entry *toc_entry;
+	struct toc_entry_list *toc_entry_list, *tmp;
+	LIST_HEAD(toc_entries);
 
 	fd = open(filename, O_RDONLY);
 	if (fd < 0)
@@ -506,11 +510,10 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
 
 	/* read all toc entries */
 	while (1) {
-		struct fip_image_desc *desc = xzalloc(sizeof(*desc));
-		struct fip_image *image = xzalloc(sizeof(*image));
-		struct fip_toc_entry *toc_entry = &image->toc_e;
+		uint64_t this_end;
 
-		desc->image = image;
+		toc_entry_list = xzalloc(sizeof(*toc_entry_list));
+		toc_entry = &toc_entry_list->toc;
 
 		ret = read_full(fd, toc_entry, sizeof(*toc_entry));
 		if (ret < 0)
@@ -520,54 +523,67 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
 			goto err;
 		}
 
-		list_add_tail(&desc->list, &fip_state->descs);
-
 		pr_debug("Read TOC entry %pU %llu %llu\n", &toc_entry->uuid,
 			 toc_entry->offset_address, toc_entry->size);
 
-		/* Found the ToC terminator, we are done. */
-		if (uuid_is_null(&toc_entry->uuid))
-			break;
-	}
-
-	/* determine buffer size */
-	fip_for_each_desc(fip_state, desc) {
-		uint64_t this_end = desc->image->toc_e.offset_address + desc->image->toc_e.size;
+		this_end = toc_entry->offset_address + toc_entry->size;
 
 		if (this_end > total)
 			total = this_end;
+
 		n_entries++;
-	}
 
-	fip_headers_size = n_entries * sizeof(struct fip_toc_entry) + sizeof(fip_toc_header_t);
+		list_add_tail(&toc_entry_list->list, &toc_entries);
 
-	total -= fip_headers_size;
+		/* Found the ToC terminator, we are done. */
+		if (uuid_is_null(&toc_entry->uuid))
+			break;
+	}
 
-	fip_state->buffer = malloc(total);
-	if (!fip_state->buffer) {
+	buf = malloc(total);
+	if (!buf) {
 		ret = -ENOMEM;
 		goto err;
 	}
 
-	ret = read_full(fd, fip_state->buffer, total);
+	ptr = buf;
+	fip_state->buffer = buf;
+
+	memcpy(ptr, &toc_header, sizeof(toc_header));
+	ptr += sizeof(toc_header);
+
+	list_for_each_entry_safe(toc_entry_list, tmp, &toc_entries, list) {
+		memcpy(ptr, &toc_entry_list->toc, sizeof(*toc_entry));
+		ptr += sizeof(*toc_entry);
+
+		list_del(&toc_entry_list->list);
+		free(toc_entry_list);
+	}
+
+	fip_headers_size = n_entries * sizeof(struct fip_toc_entry) + sizeof(fip_toc_header_t);
+
+	ret = read_full(fd, ptr, total - fip_headers_size);
+	ret = -EINVAL;
 	if (ret < 0)
 		goto err;
 
-	if (ret < total) {
+	if (ret < total - fip_headers_size) {
 		ret = -ENODATA;
 		goto err;
 	}
 
-	close(fd);
+	ret = fip_do_parse_buf(fip_state, buf, total, NULL);
+	if (ret)
+		goto err;
 
-	fip_for_each_desc(fip_state, desc) {
-		desc->image->buffer = fip_state->buffer +
-			desc->image->toc_e.offset_address - fip_headers_size;
-		desc->image->buf_no_free = true;
-	}
+	close(fd);
 
 	return fip_state;
+
 err:
+	list_for_each_entry_safe(toc_entry_list, tmp, &toc_entries, list)
+		free(toc_entry_list);
+
 	close(fd);
 	fip_free(fip_state);
 
-- 
2.39.5



-- 
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-5555 |


From o.rempel at pengutronix.de  Wed Mar 12 04:20:56 2025
From: o.rempel at pengutronix.de (Oleksij Rempel)
Date: Wed, 12 Mar 2025 12:20:56 +0100
Subject: [PATCH v1 2/3] Documentation: networking: Add DSA switch support documentation
In-Reply-To: <20250312112057.570001-1-o.rempel@pengutronix.de>
References: <20250312112057.570001-1-o.rempel@pengutronix.de>
Message-ID: <20250312112057.570001-2-o.rempel@pengutronix.de>

Add documentation for Distributed Switch Architecture (DSA) support in
Barebox. It introduces the `forwarding` parameter, which allows
configuring a DSA switch to operate in either isolated mode (default) or
forwarding mode.

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 Documentation/user/networking.rst | 74 +++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/Documentation/user/networking.rst b/Documentation/user/networking.rst
index 2306cb6a60d1..71703f064bee 100644
--- a/Documentation/user/networking.rst
+++ b/Documentation/user/networking.rst
@@ -186,3 +186,77 @@ barebox:
 The netconsole can be used just like any other console. Note, however, that the
 simple console protocol is UDP based, so there is no guarantee about packet
 loss.
+
+DSA (Distributed Switch Architecture) Support in Barebox
+--------------------------------------------------------
+
+Barebox includes support for DSA (Distributed Switch Architecture), allowing
+for basic configuration and management of network switches within the
+bootloader.
+
+DSA enables network devices to use a switch framework where each port of the
+switch is treated as a separate network interface, while still allowing packet
+forwarding between ports when enabled.
+
+DSA Configuration
+^^^^^^^^^^^^^^^^^
+
+DSA switches are managed through device parameters, similar to network
+interfaces. Each switch is identified as a separate device, typically named
+``switch0`` or ``switch at 00`` depending on the bus address.
+
+Global Forwarding Control
+"""""""""""""""""""""""""
+
+A parameter, ``forwarding``, allows configuring whether a switch operates
+in **isolated mode** (default) or **forwarding mode**:
+
+- **Isolated Mode** (default): Each port is treated as an independent interface,
+  with no forwarding between ports.
+
+- **Forwarding Mode**: The switch allows forwarding of packets between ports,
+  acting as a traditional non-managed switch.
+
+To check the current DSA switch settings, use:
+
+.. code-block:: sh
+
+  barebox:/ devinfo switch0
+  Parameters:
+    forwarding: 0 (type: bool)
+
+To enable forwarding mode:
+
+.. code-block:: sh
+
+  dev.switch0.forwarding=1
+
+To disable forwarding and revert to isolated mode:
+
+.. code-block:: sh
+
+  dev.switch0.forwarding=0
+
+Persisting Configuration
+""""""""""""""""""""""""
+
+To ensure that the forwarding mode setting persists across reboots,
+it can be stored as a nonvolatile (nv) variable:
+
+.. code-block:: sh
+
+  nv dev.switch0.forwarding=1
+
+This will configure the switch to always boot in forwarding mode.
+
+Integration with Network Interfaces
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Each port of the DSA switch is exposed as an independent network interface in
+Barebox. However, when forwarding is enabled, packets can be forwarded between
+these interfaces without requiring intervention from the CPU.
+
+To configure network settings for individual ports, use standard network
+configuration variables (e.g., ``eth0.ipaddr``, ``eth0.mode``, etc.). These
+settings are applied per port and are independent of the global switch
+forwarding configuration.
-- 
2.39.5



From o.rempel at pengutronix.de  Wed Mar 12 04:20:55 2025
From: o.rempel at pengutronix.de (Oleksij Rempel)
Date: Wed, 12 Mar 2025 12:20:55 +0100
Subject: [PATCH v1 1/3] net: dsa: Add global forwarding mode support
Message-ID: <20250312112057.570001-1-o.rempel@pengutronix.de>

This patch introduces a global forwarding mode control for DSA switches
in Barebox.  It adds a new `forwarding` parameter that allows enabling
or disabling forwarding  between all ports on a DSA switch.

This enables users to configure global forwarding dynamically via:
dev.switch0.forwarding=1  # Enable forwarding
dev.switch0.forwarding=0  # Disable forwarding (isolated mode)

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 drivers/net/dsa.c | 12 ++++++++++++
 include/dsa.h     |  4 ++++
 2 files changed, 16 insertions(+)

diff --git a/drivers/net/dsa.c b/drivers/net/dsa.c
index a451a1a35e8b..537e9dd72ac6 100644
--- a/drivers/net/dsa.c
+++ b/drivers/net/dsa.c
@@ -4,6 +4,7 @@
 #include <dma.h>
 #include <dsa.h>
 #include <of_net.h>
+#include <param.h>
 
 u32 dsa_user_ports(struct dsa_switch *ds)
 {
@@ -431,6 +432,13 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds,
 	return ret;
 }
 
+static int dsa_set_forwarding(struct param_d *p, void *priv)
+{
+	struct dsa_switch *ds = priv;
+
+	return ds->ops->set_forwarding(ds, ds->forwarding_enable);
+}
+
 int dsa_register_switch(struct dsa_switch *ds)
 {
 	int ret;
@@ -448,6 +456,10 @@ int dsa_register_switch(struct dsa_switch *ds)
 		return -EINVAL;
 	}
 
+	if (ds->ops->set_forwarding)
+		dev_add_param_bool(ds->dev, "forwarding", dsa_set_forwarding,
+				   NULL, &ds->forwarding_enable, ds);
+
 	ret = dsa_switch_parse_ports_of(ds, ds->dev->of_node);
 	if (ret)
 		return ret;
diff --git a/include/dsa.h b/include/dsa.h
index 527941c26949..ecf7c4f429f3 100644
--- a/include/dsa.h
+++ b/include/dsa.h
@@ -56,6 +56,9 @@ struct dsa_switch_ops {
 	int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
 	int (*phy_write)(struct dsa_switch *ds, int port, int regnum, u16 val);
 	void (*adjust_link)(struct eth_device *dev);
+
+	/* enable/disable forwarding between all ports on the switch */
+	int (*set_forwarding)(struct dsa_switch *ds, bool enable);
 };
 
 struct dsa_port {
@@ -84,6 +87,7 @@ struct dsa_switch {
 	struct mii_bus *slave_mii_bus;
 	u32 phys_mii_mask;
 	void *priv;
+	u32 forwarding_enable;
 };
 
 static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
-- 
2.39.5



From o.rempel at pengutronix.de  Wed Mar 12 04:20:57 2025
From: o.rempel at pengutronix.de (Oleksij Rempel)
Date: Wed, 12 Mar 2025 12:20:57 +0100
Subject: [PATCH v1 3/3] net: dsa: sja1105: Add support for global forwarding mode
In-Reply-To: <20250312112057.570001-1-o.rempel@pengutronix.de>
References: <20250312112057.570001-1-o.rempel@pengutronix.de>
Message-ID: <20250312112057.570001-3-o.rempel@pengutronix.de>

Add support for global forwarding mode in the SJA1105 DSA driver,
allowing dynamic control over whether the switch forwards traffic
between all ports or restricts communication to only CPU-port
connections.

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 drivers/net/sja1105.c | 77 +++++++++++++++++++++++++++++++++----------
 1 file changed, 59 insertions(+), 18 deletions(-)

diff --git a/drivers/net/sja1105.c b/drivers/net/sja1105.c
index 4ef30b8c81f1..aaf9237dc19d 100644
--- a/drivers/net/sja1105.c
+++ b/drivers/net/sja1105.c
@@ -1230,11 +1230,13 @@ static int sja1105_init_mii_settings(struct sja1105_private *priv)
 	return 0;
 }
 
-static void sja1105_setup_tagging(struct sja1105_private *priv, int port)
+static void sja1105_setup_tagging(struct sja1105_private *priv, int port,
+				  bool forward_all)
 {
 	struct sja1105_vlan_lookup_entry *vlan;
 	struct dsa_switch *ds = &priv->ds;
 	int cpu = ds->cpu_port;
+	u8 vlan_mask;
 
 	/* The CPU port is implicitly configured by
 	 * configuring the front-panel ports
@@ -1246,8 +1248,16 @@ static void sja1105_setup_tagging(struct sja1105_private *priv, int port)
 
 	priv->pvid[port] = DSA_8021Q_DIR_TX | DSA_8021Q_PORT(port);
 
-	vlan[port].vmemb_port	= BIT(port) | BIT(cpu);
-	vlan[port].vlan_bc	= BIT(port) | BIT(cpu);
+	if (forward_all) {
+		/* All ports in the same VLAN */
+		vlan_mask = (1 << ds->num_ports) - 1;
+	} else {
+		/* Only allow port ? CPU communication */
+		vlan_mask = BIT(port) | BIT(cpu);
+	}
+
+	vlan[port].vmemb_port	= vlan_mask;
+	vlan[port].vlan_bc	= vlan_mask;
 	vlan[port].tag_port	= BIT(cpu);
 	vlan[port].vlanid	= priv->pvid[port];
 	vlan[port].type_entry	= SJA1110_VLAN_D_TAG;
@@ -1269,7 +1279,7 @@ static int sja1105_init_vlan(struct sja1105_private *priv)
 	table->entry_count = ds->num_ports;
 
 	for (port = 0; port < ds->num_ports; port++)
-		sja1105_setup_tagging(priv, port);
+		sja1105_setup_tagging(priv, port, false);
 
 	return 0;
 }
@@ -1283,33 +1293,47 @@ sja1105_port_allow_traffic(struct sja1105_l2_forwarding_entry *l2_fwd,
 	l2_fwd[from].fl_domain  |= BIT(to);
 }
 
-static int sja1105_init_l2_forwarding(struct sja1105_private *priv)
+static int sja1105_init_l2_forwarding(struct sja1105_private *priv,
+				      bool forward_all)
 {
 	struct sja1105_l2_forwarding_entry *l2fwd;
 	struct dsa_switch *ds = &priv->ds;
 	struct sja1105_table *table;
 	int cpu = ds->cpu_port;
-	int i;
+	int i, j;
 
 	table = &priv->static_config.tables[BLK_IDX_L2_FORWARDING];
 
-	table->entries = calloc(SJA1105_MAX_L2_FORWARDING_COUNT,
-				table->ops->unpacked_entry_size);
-	if (!table->entries)
-		return -ENOMEM;
+	if (!table->entries) {
+		table->entries = calloc(SJA1105_MAX_L2_FORWARDING_COUNT,
+					table->ops->unpacked_entry_size);
+		if (!table->entries)
+			return -ENOMEM;
+	}
 
 	table->entry_count = SJA1105_MAX_L2_FORWARDING_COUNT;
 
 	l2fwd = table->entries;
 
-	/* First 5 entries define the forwarding rules */
-	for (i = 0; i < ds->num_ports; i++) {
-		if (i == cpu)
-			continue;
-
-		sja1105_port_allow_traffic(l2fwd, i, cpu);
-		sja1105_port_allow_traffic(l2fwd, cpu, i);
+	if (forward_all) {
+		/* Forwarding mode: All ports can talk to each other */
+		for (i = 0; i < ds->num_ports; i++) {
+			for (j = 0; j < ds->num_ports; j++) {
+				if (i == j)
+					continue;
+				sja1105_port_allow_traffic(l2fwd, i, j);
+			}
+		}
+	} else {
+		/* Default mode: Each port only forwards to/from the CPU */
+		for (i = 0; i < ds->num_ports; i++) {
+			if (i == cpu)
+				continue;
+			sja1105_port_allow_traffic(l2fwd, i, cpu);
+			sja1105_port_allow_traffic(l2fwd, cpu, i);
+		}
 	}
+
 	/* Next 8 entries define VLAN PCP mapping from ingress to egress.
 	 * Leave them unpopulated (implicitly 0) but present.
 	 */
@@ -1490,7 +1514,7 @@ static int sja1105_static_config_init(struct sja1105_private *priv)
 	rc = sja1105_init_mii_settings(priv);
 	if (rc < 0)
 		return rc;
-	rc = sja1105_init_l2_forwarding(priv);
+	rc = sja1105_init_l2_forwarding(priv, false);
 	if (rc < 0)
 		return rc;
 	rc = sja1105_init_l2_forwarding_params(priv);
@@ -2866,12 +2890,29 @@ static int sja1105_cpu_port_enable(struct dsa_port *dp, int port,
 	return sja1105_static_config_reload(priv);
 }
 
+static int sja1105_set_forwarding(struct dsa_switch *ds, bool enable)
+{
+	struct device *dev = ds->dev;
+	struct sja1105_private *priv = dev_get_priv(dev);
+	int port, ret;
+
+	for (port = 0; port < ds->num_ports; port++)
+		sja1105_setup_tagging(priv, port, enable);
+
+	ret = sja1105_init_l2_forwarding(priv, enable);
+	if (ret)
+		return ret;
+
+	return sja1105_static_config_reload(priv);
+}
+
 static const struct dsa_switch_ops sja1105_dsa_ops = {
 	.port_pre_enable	= sja1105_port_pre_enable,
 	.port_enable		= sja1105_cpu_port_enable,
 	.adjust_link		= sja1105_adjust_link,
 	.xmit			= sja1105_xmit,
 	.rcv			= sja1105_rcv,
+	.set_forwarding		= sja1105_set_forwarding,
 };
 
 static int sja1105_init(struct sja1105_private *priv)
-- 
2.39.5



From m.felsch at pengutronix.de  Wed Mar 12 04:45:10 2025
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Wed, 12 Mar 2025 12:45:10 +0100
Subject: [PATCH v2 05/14] fip: rework fip_image_open()
In-Reply-To: <Z9FpzJGBShGoi0Ji@pengutronix.de>
References: <20250311-am625-secure-v2-0-3cbbfa092346@pengutronix.de>
 <20250311-am625-secure-v2-5-3cbbfa092346@pengutronix.de>
 <20250311134207.x4o2ccin3jx6pdpj@pengutronix.de>
 <Z9FpzJGBShGoi0Ji@pengutronix.de>
Message-ID: <20250312114510.itqbgxwxd66ynumy@pengutronix.de>

On 25-03-12, Sascha Hauer wrote:
> On Tue, Mar 11, 2025 at 02:42:07PM +0100, Marco Felsch wrote:
> > >  struct fip_state *fip_image_open(const char *filename, size_t offset)
> > >  {
> > > @@ -470,11 +466,13 @@ struct fip_state *fip_image_open(const char *filename, size_t offset)
> > >  	int ret;
> > >  	int fd;
> > >  	struct fip_state *fip_state;
> > > -	LIST_HEAD(entries);
> > >  	size_t fip_headers_size, total = 0;
> > > -	struct fip_image_desc *desc;
> > >  	off_t pos;
> > >  	int n_entries = 0;
> > > +	struct fip_toc_entry toc_entries[16];
> > 				 	 ^
> > Why did you used 16?
> 
> Okay okay, I allocated the entries dynamically now to support an
> arbitrary number of toc entries.

Nice, thanks :)

> 
> Sascha
> 
> -------------------------------8<------------------------------
> 
> From 87bc7468e698e3404345ee601885ec186de7f4fa Mon Sep 17 00:00:00 2001
> From: Sascha Hauer <s.hauer at pengutronix.de>
> Date: Tue, 11 Mar 2025 13:25:18 +0100
> Subject: [PATCH] fip: rework fip_image_open()
> 
> fip_image_open() used to do all the parsing into a struct fip_state
> itself. Instead, only load the FIP image into a buffer and call
> fip_do_parse_buf() with this buffer. This has the advantage that we
> have all parsing of the FIP image in a single place. Also this helps
> with a followup patch which calculates a sha256 over a FIP image
> which can easily done when we have the whole FIP image in a contiguous
> buffer.
> 
> Link: https://lore.kernel.org/r/20250311-am625-secure-v2-5-3cbbfa092346 at pengutronix.de
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>

if not already to late.


From s.hauer at pengutronix.de  Wed Mar 12 05:16:17 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:16:17 +0100
Subject: [PATCH 2/9] mci: export some functions for RPMB support
In-Reply-To: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
Message-ID: <20250312-rpmb-v1-2-0f213382a3f3@pengutronix.de>

Export mci_send_cmd() and mci_blk_part_switch() in preparation for
adding RPMB support.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 4 ++--
 include/mci.h          | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 6d8140f7b0..b7ea0df3cb 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -68,7 +68,7 @@ static inline unsigned mci_caps(struct mci *mci)
  * @param data The data according to the command (can be NULL)
  * @return Driver's answer (0 on success)
  */
-static int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data)
+int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data)
 {
 	struct mci_host *host = mci->host;
 
@@ -2030,7 +2030,7 @@ static int sd_send_if_cond(struct mci *mci)
 /**
  * Switch between hardware MMC partitions on demand
  */
-static int mci_blk_part_switch(struct mci_part *part)
+int mci_blk_part_switch(struct mci_part *part)
 {
 	struct mci *mci = part->mci;
 	int ret;
diff --git a/include/mci.h b/include/mci.h
index c6ee6ea50f..8084df813a 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -729,6 +729,8 @@ int mci_execute_tuning(struct mci *mci);
 int mci_send_abort_tuning(struct mci *mci, u32 opcode);
 int mmc_select_timing(struct mci *mci);
 int mci_set_blockcount(struct mci *mci, unsigned int cmdarg);
+int mci_blk_part_switch(struct mci_part *part);
+int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data);
 
 static inline bool mmc_card_hs200(struct mci *mci)
 {

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 12 05:16:15 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:16:15 +0100
Subject: [PATCH 0/9] Add RPMB support
Message-ID: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>

This series adds the necessary pieces to provide OP-TEE access to RPMB
partitions under barebox.

With this OP-TEE can issue RPMB requests to barebox and barebox will
answer them accordingly.

OP-TEE will only access the RPMB when triggered by barebox. For this
purpose I implemented access to the Android Verified Boot (AVB) variable
store. This is implemented in U-Boot as well and the code is loosely
based on it. The variables can be read/written using the newly
introduced avb_pvalue command.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
Sascha Hauer (9):
      mci: implement mci_set_blockcount()
      mci: export some functions for RPMB support
      mci: detect RPMB partitions
      mci: add RPMB support
      tee: optee: probe successfully even when no devices are found
      tee: optee: implement shared mem alloc/free RPC commands
      tee: optee: implement RPMB support
      tee: optee: implement AVB named persistent values support
      commands: add avb_pvalue command

 commands/Kconfig                  |  13 +++
 commands/Makefile                 |   1 +
 commands/avb_pvalue.c             | 138 +++++++++++++++++++++++++
 drivers/mci/Kconfig               |   3 +
 drivers/mci/Makefile              |   1 +
 drivers/mci/mci-core.c            |  73 +++++++++++++-
 drivers/mci/rpmb.c                | 206 ++++++++++++++++++++++++++++++++++++++
 drivers/tee/optee/Kconfig         |   9 ++
 drivers/tee/optee/Makefile        |   2 +
 drivers/tee/optee/avb.c           | 189 ++++++++++++++++++++++++++++++++++
 drivers/tee/optee/device.c        |   1 +
 drivers/tee/optee/optee_private.h |  13 +++
 drivers/tee/optee/optee_rpc_cmd.h | 144 ++++++++++++++++++++++++++
 drivers/tee/optee/rpc.c           |  63 +++++++++++-
 drivers/tee/optee/rpmb.c          | 128 +++++++++++++++++++++++
 drivers/tee/optee/smc_abi.c       |  26 +++--
 drivers/tee/tee_shm.c             |   1 +
 include/linux/tee_drv.h           |   1 +
 include/mci.h                     |  17 +++-
 include/tee/avb.h                 |   9 ++
 20 files changed, 1021 insertions(+), 17 deletions(-)
---
base-commit: a9a50228674d01adc8d7a49d1ab0e7e894c25fe8
change-id: 20250312-rpmb-c6f330f29cb1

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Wed Mar 12 05:16:24 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:16:24 +0100
Subject: [PATCH 9/9] commands: add avb_pvalue command
In-Reply-To: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
Message-ID: <20250312-rpmb-v1-9-0f213382a3f3@pengutronix.de>

Android Verified Boot (AVB( 2.0 spec. revision 1.1 introduces support
for named persistent values that must be tamper evident and allows AVB
to store arbitrary key-value pairs.

This patch introduces a command to access this variable store. Variables
can be read into a file or an environment variable or printed as
hexdump. Variables can be written from file content or a string from the
command line.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/Kconfig      |  13 +++++
 commands/Makefile     |   1 +
 commands/avb_pvalue.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 152 insertions(+)

diff --git a/commands/Kconfig b/commands/Kconfig
index e41625e294..3d87ba5e09 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2254,6 +2254,19 @@ config CMD_2048
 	help
 	  Console version of the game "2048" for GNU/Linux
 
+config CMD_AVB_PVALUE
+	depends on OPTEE_AVB_PERSISTENT_VALUES
+	tristate
+	prompt "avb_pvalue"
+	help
+	  The avb_pvalue command provides access to the Android Verified Boot (AVB)
+	  persistent value store.
+
+	  AVB 2.0 spec. revision 1.1 introduces support for named persistent values
+	  that must be tamper evident and allows AVB to store arbitrary key-value
+	  pairs.
+
+
 config CMD_BAREBOX_UPDATE
 	tristate
 	select BAREBOX_UPDATE
diff --git a/commands/Makefile b/commands/Makefile
index e152e4148b..7a635e8791 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -3,6 +3,7 @@
 obj-$(CONFIG_STDDEV)		+= stddev.o
 obj-$(CONFIG_CMD_DIGEST)	+= digest.o
 obj-$(CONFIG_COMPILE_HASH)	+= hashsum.o
+obj-$(CONFIG_CMD_AVB_PVALUE)	+= avb_pvalue.o
 obj-$(CONFIG_CMD_BOOTM)		+= bootm.o
 obj-$(CONFIG_CMD_UIMAGE)	+= uimage.o
 obj-$(CONFIG_CMD_LOADB)		+= loadb.o
diff --git a/commands/avb_pvalue.c b/commands/avb_pvalue.c
new file mode 100644
index 0000000000..adc44321fb
--- /dev/null
+++ b/commands/avb_pvalue.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <command.h>
+#include <getopt.h>
+#include <libfile.h>
+#include <fs.h>
+#include <xfuncs.h>
+#include <linux/sizes.h>
+#include <tee/avb.h>
+#include <linux/ctype.h>
+#include <environment.h>
+
+static int do_avb_pvalue(int argc, char *argv[])
+{
+	size_t out = 0x13;
+	void *buf = NULL;
+	int ret = 0, rc = COMMAND_ERROR;
+	int opt;
+	const char *write_varname = NULL, *read_varname = NULL;
+	void *val = NULL;
+	size_t size;
+	const char *filename = NULL;
+	const char *varname = NULL;
+	const int bufsize = SZ_8K;
+
+	while ((opt = getopt(argc, argv, "r:w:f:")) > 0) {
+		switch(opt) {
+		case 'r':
+			read_varname = optarg;
+			break;
+		case 'w':
+			write_varname = optarg;
+			break;
+		case 'f':
+			filename = optarg;
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	argc -= optind;
+	argv += optind;
+
+	if (!read_varname && !write_varname)
+		return COMMAND_ERROR_USAGE;
+
+	if (read_varname && write_varname)
+		return COMMAND_ERROR_USAGE;
+
+	if (write_varname) {
+		if (argc >= 1)
+			val = argv[0];
+
+		if (filename) {
+			ret = read_file_2(filename, &size, &buf, FILESIZE_MAX);
+			if (ret) {
+				printf("Cannot read %s: %pe\n", read_varname, ERR_PTR(ret));
+				return COMMAND_ERROR;
+			}
+		} else {
+			if (!val)
+				return COMMAND_ERROR_USAGE;
+			size = strlen(val) + 1;
+			buf = xstrdup(val);
+
+		}
+		ret = avb_write_persistent_value(write_varname, size, buf);
+		if (ret) {
+			printf("Cannot write variable %s: %pe\n", read_varname, ERR_PTR(ret));
+			goto err;
+		}
+	}
+
+	if (read_varname) {
+		if (argc >= 1)
+			varname = argv[0];
+
+		buf = xzalloc(bufsize);
+
+		ret = avb_read_persistent_value(read_varname, SZ_8K, buf, &out);
+		if (ret) {
+			printf("Cannot read variable %s: %pe\n", read_varname, ERR_PTR(ret));
+			rc = COMMAND_ERROR;
+			goto err;
+		}
+
+		if (filename) {
+			ret = write_file(filename, buf, out);
+			if (ret) {
+				printf("Cannot write %s: %pe\n", filename, ERR_PTR(ret));
+				rc = COMMAND_ERROR;
+				goto err;
+			}
+		} else if (varname) {
+			unsigned char *str = buf;
+			int i;
+
+			str[bufsize - 1] = 0;
+	
+			for (i = 0; i < out; i++)
+				if (!isprint(str[i]))
+					break;
+
+			str[i] = 0;
+
+			setenv(varname, buf);
+		} else {
+			memory_display(buf, 0, out, 1, 0);
+		}
+	}
+
+	rc = 0;
+
+err:
+	free(buf);
+
+	return rc;
+}
+
+BAREBOX_CMD_HELP_START(avb_pvalue)
+BAREBOX_CMD_HELP_TEXT("This command provides access to the AVB persistent variable store.")
+BAREBOX_CMD_HELP_TEXT("usage:")
+BAREBOX_CMD_HELP_TEXT("avb_pvalue [OPTION]... [VARNAME/VALUE]")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-r <varname>",  "read variable <varname>. read value into [VARNAME] if given")
+BAREBOX_CMD_HELP_OPT ("-w <varname>",  "write variable <varname>. Set to [VALUE] if given")
+BAREBOX_CMD_HELP_OPT ("-f <file>",  "read/write value from/to file")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(avb_pvalue)
+	.cmd            = do_avb_pvalue,
+	BAREBOX_CMD_DESC("AVB persistent variable store")
+	BAREBOX_CMD_OPTS("[-rwf] [VARNAME/VALUE]")
+	BAREBOX_CMD_HELP(cmd_avb_pvalue_help)
+	BAREBOX_CMD_GROUP(CMD_GRP_CONSOLE)
+BAREBOX_CMD_END

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 12 05:16:19 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:16:19 +0100
Subject: [PATCH 4/9] mci: add RPMB support
In-Reply-To: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
Message-ID: <20250312-rpmb-v1-4-0f213382a3f3@pengutronix.de>

This implements the MMC specific part to access RPMB partitions:

- Provide a function to find a RPMB capable eMMC
- partition switching to the RPMB partition
- Dissecting the OP-TEE requests into the correspnding MMC read/write
  multiblock commands

For now we only support a single eMMC RPMB partition per board. This is
the 99% case, but there might be systems with multiple eMMCs. The OP-TEE
protocol has a dev_id field to support multiple eMMCs, but OP-TEE itself
currently only supports a single RPMB. This means we really only need to
support one eMMC, but should there be multiple eMMCs on a system we will
need a way for the user to specify which one shall be used. As of now
the first one found will be used.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/Kconfig    |   3 +
 drivers/mci/Makefile   |   1 +
 drivers/mci/mci-core.c |  24 +++++-
 drivers/mci/rpmb.c     | 206 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/mci.h          |   3 +
 5 files changed, 236 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/Kconfig b/drivers/mci/Kconfig
index 4641e9cdcd..09648aa771 100644
--- a/drivers/mci/Kconfig
+++ b/drivers/mci/Kconfig
@@ -68,6 +68,9 @@ config MCI_MMC_GPP_PARTITIONS
 	  Note: by default, 'MMC' devices have no 'general purpose partitions',
 	  it requires a special one-time configuration step to enable them.
 
+config MCI_MMC_RPMB
+	bool "Support eMMC replay protected memory block (RPMB)"
+
 comment "--- MCI host drivers ---"
 
 config MCI_DWC_MSHC
diff --git a/drivers/mci/Makefile b/drivers/mci/Makefile
index 5e951d695f..d3df4c1bb6 100644
--- a/drivers/mci/Makefile
+++ b/drivers/mci/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_MCI)		+= mci-core.o
+obj-$(CONFIG_MCI_MMC_RPMB)	+= rpmb.o
 obj-$(CONFIG_MCI_AM654)		+= am654-sdhci.o
 obj-$(CONFIG_MCI_ARASAN)	+= arasan-sdhci.o
 obj-$(CONFIG_MCI_ATMEL)		+= atmel_mci.o atmel_mci_common.o
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 18c910c4c3..9c3b35c23f 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -2068,7 +2068,9 @@ int mci_blk_part_switch(struct mci_part *part)
 	struct mci *mci = part->mci;
 	int ret;
 
-	if (!IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) && !IS_ENABLED(CONFIG_MCI_MMC_GPP_PARTITIONS))
+	if (!IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) &&
+	    !IS_ENABLED(CONFIG_MCI_MMC_GPP_PARTITIONS) &&
+	    !IS_ENABLED(CONFIG_MCI_MMC_RPMB))
 		return 0; /* no need */
 
 	if (mci->part_curr == part)
@@ -3067,3 +3069,23 @@ struct mci *mci_get_device_by_name(const char *name)
 
 	return NULL;
 }
+
+struct mci *mci_get_rpmb_dev(void)
+{
+	struct mci *mci;
+
+	if (rpmb_partition)
+		return rpmb_partition->mci;
+
+	list_for_each_entry(mci, &mci_list, list) {
+		if (mci->host->caps2 & MMC_CAP2_NO_MMC)
+			continue;
+
+		mci_detect_card(mci->host);
+
+		if (rpmb_partition)
+			return rpmb_partition->mci;
+	}
+
+	return NULL;
+}
diff --git a/drivers/mci/rpmb.c b/drivers/mci/rpmb.c
new file mode 100644
index 0000000000..5c98222bad
--- /dev/null
+++ b/drivers/mci/rpmb.c
@@ -0,0 +1,206 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2014, Staubli Faverges
+ * Pierre Aubert
+ *
+ * eMMC- Replay Protected Memory Block
+ * According to JEDEC Standard No. 84-A441
+ */
+
+#include <mci.h>
+#include <malloc.h>
+#include <dma.h>
+
+int mmc_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
+			  void *rsp, unsigned long rsplen);
+
+/**
+ * struct rpmb_frame - rpmb frame as defined by eMMC 5.1 (JESD84-B51)
+ *
+ * @stuff        : stuff bytes
+ * @key_mac      : The authentication key or the message authentication
+ *                 code (MAC) depending on the request/response type.
+ *                 The MAC will be delivered in the last (or the only)
+ *                 block of data.
+ * @data         : Data to be written or read by signed access.
+ * @nonce        : Random number generated by the host for the requests
+ *                 and copied to the response by the RPMB engine.
+ * @write_counter: Counter value for the total amount of the successful
+ *                 authenticated data write requests made by the host.
+ * @addr         : Address of the data to be programmed to or read
+ *                 from the RPMB. Address is the serial number of
+ *                 the accessed block (half sector 256B).
+ * @block_count  : Number of blocks (half sectors, 256B) requested to be
+ *                 read/programmed.
+ * @result       : Includes information about the status of the write counter
+ *                 (valid, expired) and result of the access made to the RPMB.
+ * @req_resp     : Defines the type of request and response to/from the memory.
+ *
+ * The stuff bytes and big-endian properties are modeled to fit to the spec.
+ */
+struct rpmb_frame {
+	u8 stuff[196];
+	u8 key_mac[32];
+	u8 data[256];
+	u8 nonce[16];
+	__be32 write_counter;
+	__be16 addr;
+	__be16 block_count;
+	__be16 result;
+	__be16 req_resp;
+} __packed;
+
+#define RPMB_PROGRAM_KEY	0x1	/* Program RPMB Authentication Key */
+#define RPMB_GET_WRITE_COUNTER	0x2	/* Read RPMB write counter */
+#define RPMB_WRITE_DATA		0x3	/* Write data to RPMB partition */
+#define RPMB_READ_DATA		0x4	/* Read data from RPMB partition */
+#define RPMB_RESULT_READ	0x5	/* Read result request  (Internal) */
+
+static int mci_read_write_blocks(struct mci *mci, u32 opcode, int write_flag, void *buf,
+				 unsigned int buf_bytes)
+{
+	int blocks = buf_bytes / 512;
+	struct mci_cmd cmd = {
+		.cmdidx = opcode,
+		.resp_type = MMC_RSP_R1,
+	};
+	struct mci_data data = {
+		.blocks = blocks,
+		.blocksize = sizeof(struct rpmb_frame),
+	};
+	int ret;
+
+	if (write_flag) {
+		data.src = buf;
+		data.flags = MMC_DATA_WRITE;
+	} else {
+		data.dest = buf;
+		data.flags = MMC_DATA_READ;
+	}
+
+	ret = mci_set_blockcount(mci, blocks | (write_flag & MMC_CMD23_ARG_REL_WR));
+	if (ret)
+		return ret;
+
+	return mci_send_cmd(mci, &cmd, &data);
+}
+
+static int rpmb_route_frames(struct mci *mci, void *req,
+			     unsigned int req_len, void *resp,
+			     unsigned int resp_len)
+{
+	struct rpmb_frame *frm = req;
+	unsigned int cmd_count;
+	u16 req_type;
+	bool write;
+	int ret;
+
+	if (req_len < sizeof(*frm))
+		return -EINVAL;
+
+	req_type = be16_to_cpu(frm->req_resp);
+	switch (req_type) {
+	case RPMB_PROGRAM_KEY:
+		if (req_len != sizeof(struct rpmb_frame) ||
+		    resp_len != sizeof(struct rpmb_frame))
+			return -EINVAL;
+		write = true;
+		break;
+	case RPMB_GET_WRITE_COUNTER:
+		if (req_len != sizeof(struct rpmb_frame) ||
+		    resp_len != sizeof(struct rpmb_frame))
+			return -EINVAL;
+		write = false;
+		break;
+	case RPMB_WRITE_DATA:
+		if (req_len % sizeof(struct rpmb_frame) ||
+		    resp_len != sizeof(struct rpmb_frame))
+			return -EINVAL;
+		write = true;
+		break;
+	case RPMB_READ_DATA:
+		if (req_len != sizeof(struct rpmb_frame) ||
+		    resp_len % sizeof(struct rpmb_frame))
+			return -EINVAL;
+		write = false;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (write)
+		cmd_count = 3;
+	else
+		cmd_count = 2;
+
+	if (write) {
+		struct rpmb_frame *frm = resp;
+
+		/* Send write request frame(s) */
+		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK,
+			  1 | MMC_CMD23_ARG_REL_WR, req, req_len);
+		if (ret)
+			goto out;
+
+		/* Send result request frame */
+		memset(frm, 0, sizeof(*frm));
+		frm->req_resp = cpu_to_be16(RPMB_RESULT_READ);
+		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK, 1,
+					    resp, resp_len);
+		if (ret)
+			goto out;
+
+		/* Read response frame */
+		ret = mci_read_write_blocks(mci, MMC_CMD_READ_MULTIPLE_BLOCK, 0,
+					    resp, resp_len);
+		if (ret)
+			goto out;
+	} else {
+		/* Send write request frame(s) */
+		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK, 1,
+					    req, req_len);
+		if (ret)
+			goto out;
+
+		/* Read response frame */
+		ret = mci_read_write_blocks(mci, MMC_CMD_READ_MULTIPLE_BLOCK, 0,
+					    resp, resp_len);
+		if (ret)
+			goto out;
+	}
+out:
+	return ret;
+}
+
+int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
+			  void *rsp, unsigned long rsplen)
+{
+	/*
+	 * Whoever crafted the data supplied to this function knows how to
+	 * format the PRMB frames and which response is expected. If
+	 * there's some unexpected mismatch it's more helpful to report an
+	 * error immediately than trying to guess what was the intention
+	 * and possibly just delay an eventual error which will be harder
+	 * to track down.
+	 */
+	void *rpmb_data = NULL;
+	int ret;
+
+	mci_blk_part_switch(mci->rpmb_part);
+
+	if (!IS_ALIGNED((uintptr_t)req, ARCH_DMA_MINALIGN)) {
+		/* Memory alignment is required by MMC driver */
+		rpmb_data = dma_alloc(reqlen);
+		if (!rpmb_data)
+			return -ENOMEM;
+
+		memcpy(rpmb_data, req, reqlen);
+		req = rpmb_data;
+	}
+
+	ret = rpmb_route_frames(mci, req, reqlen, rsp, rsplen);
+
+	free(rpmb_data);
+
+	return ret;
+}
diff --git a/include/mci.h b/include/mci.h
index 08a3e46f7d..ec0390eedf 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -736,6 +736,9 @@ int mmc_select_timing(struct mci *mci);
 int mci_set_blockcount(struct mci *mci, unsigned int cmdarg);
 int mci_blk_part_switch(struct mci_part *part);
 int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data);
+struct mci *mci_get_rpmb_dev(void);
+int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
+			  void *rsp, unsigned long rsplen);
 
 static inline bool mmc_card_hs200(struct mci *mci)
 {

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 12 05:16:16 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:16:16 +0100
Subject: [PATCH 1/9] mci: implement mci_set_blockcount()
In-Reply-To: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
Message-ID: <20250312-rpmb-v1-1-0f213382a3f3@pengutronix.de>

This adds a function to send a MMC_CMD_SET_BLOCK_COUNT command. This
is not yet needed by barebox as we use open end multiblock transfers,
but will be needed by upcoming RPMB support.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 9 +++++++++
 include/mci.h          | 5 +++++
 2 files changed, 14 insertions(+)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 27a10df9ce..6d8140f7b0 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -311,6 +311,15 @@ static int mci_block_erase(struct mci *card, unsigned int from,
 	return -EIO;
 }
 
+int mci_set_blockcount(struct mci *mci, unsigned int cmdarg)
+{
+	struct mci_cmd cmd = {};
+
+	mci_setup_cmd(&cmd, MMC_CMD_SET_BLOCK_COUNT, cmdarg, MMC_RSP_R1);
+
+	return mci_send_cmd(mci, &cmd, NULL);
+}
+
 static int mci_do_block_op(struct mci *mci, const void *src, void *dst, int blocknum,
 		int blocks)
 {
diff --git a/include/mci.h b/include/mci.h
index f0db1f9ea0..c6ee6ea50f 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -87,12 +87,16 @@
 #define MMC_CMD_READ_MULTIPLE_BLOCK	18
 #define MMC_SEND_TUNING_BLOCK		19   /* adtc R1  */
 #define MMC_SEND_TUNING_BLOCK_HS200	21   /* adtc R1  */
+#define MMC_CMD_SET_BLOCK_COUNT		23
 #define MMC_CMD_WRITE_SINGLE_BLOCK	24
 #define MMC_CMD_WRITE_MULTIPLE_BLOCK	25
 #define MMC_CMD_APP_CMD			55
 #define MMC_CMD_SPI_READ_OCR		58
 #define MMC_CMD_SPI_CRC_ON_OFF		59
 
+#define MMC_CMD23_ARG_BLOCKS	GENMASK(15, 0)
+#define MMC_CMD23_ARG_REL_WR	BIT(31)
+
   /* class 5 */
 #define MMC_ERASE_GROUP_START    35   /* ac   [31:0] data addr   R1  */
 #define MMC_ERASE_GROUP_END      36   /* ac   [31:0] data addr   R1  */
@@ -724,6 +728,7 @@ int mmc_hs200_tuning(struct mci *mci);
 int mci_execute_tuning(struct mci *mci);
 int mci_send_abort_tuning(struct mci *mci, u32 opcode);
 int mmc_select_timing(struct mci *mci);
+int mci_set_blockcount(struct mci *mci, unsigned int cmdarg);
 
 static inline bool mmc_card_hs200(struct mci *mci)
 {

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 12 05:16:20 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:16:20 +0100
Subject: [PATCH 5/9] tee: optee: probe successfully even when no devices
 are found
In-Reply-To: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
Message-ID: <20250312-rpmb-v1-5-0f213382a3f3@pengutronix.de>

OP-TEE iterates over the devices and when none are found the OP-TEE
driver returns with an error. Return successfully instead because
for example RPMB support doesn't require any devices exported from
OP-TEE.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/tee/optee/device.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c
index 100a877395..5176989a50 100644
--- a/drivers/tee/optee/device.c
+++ b/drivers/tee/optee/device.c
@@ -115,6 +115,7 @@ static int __optee_enumerate_devices(u32 func)
 		goto out_sess;
 	if (!shm_size) {
 		pr_debug("device enumeration PTA found, but no devices!\n");
+		rc = 0;
 		goto out_sess;
 	}
 

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 12 05:16:18 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:16:18 +0100
Subject: [PATCH 3/9] mci: detect RPMB partitions
In-Reply-To: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
Message-ID: <20250312-rpmb-v1-3-0f213382a3f3@pengutronix.de>

Detect RPMB partitions and initialize a struct mci_part for them. We do
not actually register the RPMB partitions as we can't access them with
regular mci_do_block_op() and we would only access encrypted data anyway.

Right now we assume that only one RPMB is present in a system which
covers the 99% case. Should there be multiple RPMBs found we issue a
warning message as there is no way to specify which one shall be used,
the first one found will be used which may vary depending on probe
order.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 36 ++++++++++++++++++++++++++++++++++++
 include/mci.h          |  7 ++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index b7ea0df3cb..18c910c4c3 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -647,6 +647,15 @@ static blkcnt_t mci_calc_blk_cnt(blkcnt_t cap, unsigned shift)
 	return ret;
 }
 
+/*
+ * We currently only support a single RPMB partition. Most systems only have a
+ * single eMMC and thus only one RPMB partition, so we are fine on most systems.
+ * When multiple RPMB partitions are found we issue a warning message as the
+ * first RPMB found will be used. There currently is no way to specify which one
+ * shall be used.
+ */
+static struct mci_part *rpmb_partition;
+
 static void mci_part_add(struct mci *mci, uint64_t size,
                         unsigned int part_cfg, char *name, char *partname, int idx, bool ro,
                         int area_type)
@@ -671,6 +680,16 @@ static void mci_part_add(struct mci *mci, uint64_t size,
 	part->part_cfg = part_cfg;
 	part->idx = idx;
 
+	if (area_type == MMC_BLK_DATA_AREA_RPMB) {
+		mci->rpmb_part = part;
+		if (rpmb_partition) {
+			dev_warn(&mci->dev, "Multiple RPMB partitions found. Only %s will be used\n",
+				 rpmb_partition->mci->host->devname);
+		} else {
+			rpmb_partition = mci->rpmb_part;
+		}
+	}
+
 	if (area_type == MMC_BLK_DATA_AREA_MAIN) {
 		cdev_set_of_node(&part->blk.cdev, mci->host->hw_dev->of_node);
 		part->blk.cdev.flags |= DEVFS_IS_MCI_MAIN_PART_DEV;
@@ -822,6 +841,20 @@ static int mmc_change_freq(struct mci *mci)
 		mci->boot_ack_enable = (mci->ext_csd_part_config >> 6) & 0x1;
 	}
 
+	if (mci->ext_csd[EXT_CSD_REV] >= 5) {
+		if (mci->ext_csd[EXT_CSD_RPMB_SIZE_MULT]) {
+			char *name, *partname;
+
+			partname = basprintf("rpmb");
+			name = basprintf("%s.%s", mci->cdevname, partname);
+
+			mci_part_add(mci, mci->ext_csd[EXT_CSD_RPMB_SIZE_MULT] << 17,
+				EXT_CSD_PART_CONFIG_ACC_RPMB,
+				name, partname, 0, false,
+				MMC_BLK_DATA_AREA_RPMB);
+		}
+	}
+
 	if (IS_ENABLED(CONFIG_MCI_MMC_GPP_PARTITIONS))
 		mmc_extract_gpp_partitions(mci);
 
@@ -2601,6 +2634,9 @@ static int mci_register_partition(struct mci_part *part)
 	part->blk.ops = &mci_ops;
 	part->blk.type = IS_SD(mci) ? BLK_TYPE_SD : BLK_TYPE_MMC;
 
+	if (part->area_type == MMC_BLK_DATA_AREA_RPMB)
+		return 0;
+
 	rc = blockdevice_register(&part->blk);
 	if (rc != 0) {
 		dev_err(&mci->dev, "Failed to register MCI/SD blockdevice\n");
diff --git a/include/mci.h b/include/mci.h
index 8084df813a..08a3e46f7d 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -347,6 +347,7 @@
  */
 #define EXT_CSD_PART_CONFIG_ACC_MASK	(0x7)
 #define EXT_CSD_PART_CONFIG_ACC_BOOT0	(0x1)
+#define EXT_CSD_PART_CONFIG_ACC_RPMB	(0x3)
 #define EXT_CSD_PART_CONFIG_ACC_GPP0	(0x4)
 
 #define EXT_CSD_CMD_SET_NORMAL		(1<<0)
@@ -606,9 +607,11 @@ struct mci_host {
 #define MMC_NUM_BOOT_PARTITION	2
 #define MMC_NUM_GP_PARTITION	4
 #define MMC_NUM_USER_PARTITION	1
+#define MMC_NUM_RPMB_PARTITION	1
 #define MMC_NUM_PHY_PARTITION	(MMC_NUM_BOOT_PARTITION + \
                                  MMC_NUM_GP_PARTITION + \
-                                 MMC_NUM_USER_PARTITION)
+                                 MMC_NUM_USER_PARTITION + \
+                                 MMC_NUM_RPMB_PARTITION)
 
 struct mci_part {
 	struct block_device	blk;		/**< the blockdevice for the card */
@@ -674,6 +677,8 @@ struct mci {
 	int boot_ack_enable;
 
 	struct mci_part part[MMC_NUM_PHY_PARTITION];
+	struct mci_part *rpmb_part;
+
 	int nr_parts;
 	char *cdevname;
 

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 12 05:16:22 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:16:22 +0100
Subject: [PATCH 7/9] tee: optee: implement RPMB support
In-Reply-To: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
Message-ID: <20250312-rpmb-v1-7-0f213382a3f3@pengutronix.de>

This implements the OPTEE_RPC_CMD_RPMB RPC call. For data requests we
call into the MMC specific RPMB implementation.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/tee/optee/Makefile        |   1 +
 drivers/tee/optee/optee_private.h |  10 +++
 drivers/tee/optee/rpc.c           |   3 +
 drivers/tee/optee/rpmb.c          | 128 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 142 insertions(+)

diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile
index 5e71af77ee..f68352aa4e 100644
--- a/drivers/tee/optee/Makefile
+++ b/drivers/tee/optee/Makefile
@@ -6,3 +6,4 @@ optee-objs += call.o
 optee-objs += rpc.o
 optee-objs += device.o
 optee-objs += smc_abi.o
+obj-$(CONFIG_MCI_MMC_RPMB) += rpmb.o
diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h
index d739a6c609..bb9ac1b068 100644
--- a/drivers/tee/optee/optee_private.h
+++ b/drivers/tee/optee/optee_private.h
@@ -179,4 +179,14 @@ static inline void reg_pair_from_64(u32 *reg0, u32 *reg1, u64 val)
 /* Registration of the ABIs */
 int optee_smc_abi_register(void);
 
+#ifdef CONFIG_MCI_MMC_RPMB
+void optee_suppl_cmd_rpmb(struct tee_context *ctx, struct optee_msg_arg *arg);
+#else
+static inline void optee_suppl_cmd_rpmb(struct tee_context *ctx, struct optee_msg_arg *arg)
+{
+	pr_debug("OPTEE_MSG_RPC_CMD_RPMB not implemented\n");
+	arg->ret = TEEC_ERROR_NOT_IMPLEMENTED;
+}
+#endif
+
 #endif /*OPTEE_PRIVATE_H*/
diff --git a/drivers/tee/optee/rpc.c b/drivers/tee/optee/rpc.c
index bdb2a9da74..182a06ec91 100644
--- a/drivers/tee/optee/rpc.c
+++ b/drivers/tee/optee/rpc.c
@@ -64,6 +64,9 @@ void optee_rpc_cmd(struct tee_context *ctx, struct optee *optee,
 	case OPTEE_RPC_CMD_SHM_FREE:
 		cmd_shm_free(arg);
 		break;
+	case OPTEE_RPC_CMD_RPMB:
+		optee_suppl_cmd_rpmb(ctx, arg);
+		break;
 	default:
 		arg->ret = TEEC_ERROR_NOT_IMPLEMENTED;
 	}
diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c
new file mode 100644
index 0000000000..da115796f4
--- /dev/null
+++ b/drivers/tee/optee/rpmb.c
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2018 Linaro Limited
+ */
+
+#define pr_fmt(fmt)     "optee-rpmb: " fmt
+
+#include <mci.h>
+
+#include "optee_msg.h"
+#include "optee_private.h"
+
+/*
+ * Request and response definitions must be in sync with the secure side of
+ * OP-TEE.
+ */
+
+/* Request */
+struct rpmb_req {
+	u16 cmd;
+#define RPMB_CMD_DATA_REQ      0x00
+#define RPMB_CMD_GET_DEV_INFO  0x01
+	u16 dev_id;
+	u16 block_count;
+	/* Optional data frames (rpmb_data_frame) follow */
+};
+
+#define RPMB_REQ_DATA(req) ((void *)((struct rpmb_req *)(req) + 1))
+
+/* Response to device info request */
+struct rpmb_dev_info {
+	u8 cid[16];
+	u8 rpmb_size_mult;	/* EXT CSD-slice 168: RPMB Size */
+	u8 rel_wr_sec_c;	/* EXT CSD-slice 222: Reliable Write Sector */
+				/*                    Count */
+	u8 ret_code;
+#define RPMB_CMD_GET_DEV_INFO_RET_OK     0x00
+#define RPMB_CMD_GET_DEV_INFO_RET_ERROR  0x01
+};
+
+static u32 rpmb_get_dev_info(struct mci *mci, struct rpmb_dev_info *info)
+{
+	int i;
+
+	if (!mci->ext_csd)
+		return TEEC_ERROR_GENERIC;
+
+	for (i = 0; i < ARRAY_SIZE(mci->raw_cid); i++)
+		((u32 *) info->cid)[i] = cpu_to_be32(mci->raw_cid[i]);
+
+	info->rel_wr_sec_c = mci->ext_csd[222];
+	info->rpmb_size_mult = mci->ext_csd[168];
+	info->ret_code = RPMB_CMD_GET_DEV_INFO_RET_OK;
+
+	return TEEC_SUCCESS;
+}
+
+static u32 rpmb_process_request(struct tee_context *ctx, void *req,
+				ulong req_size, void *rsp, ulong rsp_size)
+{
+	struct rpmb_req *sreq = req;
+	struct mci *mci = mci_get_rpmb_dev();
+
+	if (req_size < sizeof(*sreq))
+		return TEEC_ERROR_BAD_PARAMETERS;
+
+	if (!mci)
+		return TEEC_ERROR_ITEM_NOT_FOUND;
+
+	switch (sreq->cmd) {
+	case RPMB_CMD_DATA_REQ:
+		if (mci_rpmb_route_frames(mci, RPMB_REQ_DATA(req),
+					  req_size - sizeof(struct rpmb_req),
+					  rsp, rsp_size))
+			return TEEC_ERROR_BAD_PARAMETERS;
+		return TEEC_SUCCESS;
+
+	case RPMB_CMD_GET_DEV_INFO:
+		if (rsp_size != sizeof(struct rpmb_dev_info)) {
+			pr_debug("Invalid req/rsp size\n");
+			return TEEC_ERROR_BAD_PARAMETERS;
+		}
+
+		/*
+		 * We do not have any way in barebox to associate a dev_id with a
+		 * corresponding eMMC device. For now we assume that only a single
+		 * eMMC is present in the system which is assumed to have dev_id 0.
+		 */
+		if (sreq->dev_id != 0) {
+			pr_err("Unexpected RPMB dev_id %u\n", sreq->dev_id);
+			return TEEC_ERROR_ITEM_NOT_FOUND;
+		}
+
+		return rpmb_get_dev_info(mci, rsp);
+
+	default:
+		pr_debug("Unsupported RPMB command: %d\n", sreq->cmd);
+		return TEEC_ERROR_BAD_PARAMETERS;
+	}
+}
+
+void optee_suppl_cmd_rpmb(struct tee_context *ctx, struct optee_msg_arg *arg)
+{
+	struct tee_shm *req_shm;
+	struct tee_shm *rsp_shm;
+	void *req_buf;
+	void *rsp_buf;
+	ulong req_size;
+	ulong rsp_size;
+
+	if (arg->num_params != 2 ||
+	    arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_RMEM_INPUT ||
+	    arg->params[1].attr != OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT) {
+		arg->ret = TEEC_ERROR_BAD_PARAMETERS;
+		return;
+	}
+
+	req_shm = (struct tee_shm *)(ulong)arg->params[0].u.rmem.shm_ref;
+	req_buf = (u8 *)req_shm->kaddr + arg->params[0].u.rmem.offs;
+	req_size = arg->params[0].u.rmem.size;
+
+	rsp_shm = (struct tee_shm *)(ulong)arg->params[1].u.rmem.shm_ref;
+	rsp_buf = (u8 *)rsp_shm->kaddr + arg->params[1].u.rmem.offs;
+	rsp_size = arg->params[1].u.rmem.size;
+
+	arg->ret = rpmb_process_request(ctx, req_buf, req_size,
+					rsp_buf, rsp_size);
+}

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 12 05:16:23 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:16:23 +0100
Subject: [PATCH 8/9] tee: optee: implement AVB named persistent values
 support
In-Reply-To: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
Message-ID: <20250312-rpmb-v1-8-0f213382a3f3@pengutronix.de>

Android Verified Boot (AVB) 2.0 spec. revision 1.1 introduces support
for named persistent values that must be tamper evident and allows AVB
to store arbitrary key-value pairs.

While AVB itself is not implemented in barebox. this patch allows
barebox to access the persistent value store. This is useful on its
own and can also be used to test the RPMB access in barebox.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/tee/optee/Kconfig  |   9 +++
 drivers/tee/optee/Makefile |   1 +
 drivers/tee/optee/avb.c    | 189 +++++++++++++++++++++++++++++++++++++++++++++
 include/tee/avb.h          |   9 +++
 4 files changed, 208 insertions(+)

diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig
index 045be3cca4..805aba65ed 100644
--- a/drivers/tee/optee/Kconfig
+++ b/drivers/tee/optee/Kconfig
@@ -31,6 +31,15 @@ config OPTEE_DEVFS
 	  but it's useful for compiling libteeclient + optee_tests for
 	  use inside barebox to verify proper operation of CONFIG_OPTEE.
 
+config OPTEE_AVB_PERSISTENT_VALUES
+	bool "Android Verified Boot (AVB) persistent values support"
+	depends on OPTEE
+	help
+	  AVB 2.0 spec. revision 1.1 introduces support for named persistent values
+	  that must be tamper evident and allows AVB to store arbitrary key-value
+	  pairs. AVB itself is not implemented in barebox, but enabling this option
+	  allows barebox to use the AVB persistent value store.
+
 endif
 
 config OF_FIXUP_OPTEE
diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile
index f68352aa4e..1fbeb39fb8 100644
--- a/drivers/tee/optee/Makefile
+++ b/drivers/tee/optee/Makefile
@@ -7,3 +7,4 @@ optee-objs += rpc.o
 optee-objs += device.o
 optee-objs += smc_abi.o
 obj-$(CONFIG_MCI_MMC_RPMB) += rpmb.o
+obj-$(CONFIG_OPTEE_AVB_PERSISTENT_VALUES) += avb.o
diff --git a/drivers/tee/optee/avb.c b/drivers/tee/optee/avb.c
new file mode 100644
index 0000000000..0adbee6258
--- /dev/null
+++ b/drivers/tee/optee/avb.c
@@ -0,0 +1,189 @@
+#include <linux/types.h>
+#include <tee/avb.h>
+#include <linux/tee_drv.h>
+
+#include "optee_private.h"
+
+#define TA_AVB_UUID UUID_INIT(0x023f8f1a, 0x292a, 0x432b, \
+                      0x8f, 0xc4, 0xde, 0x84, 0x71, 0x35, 0x80, 0x67)
+#define TEE_PARAM_ATTR_TYPE_MEMREF_INOUT       7       /* input and output */
+#define TA_AVB_CMD_READ_PERSIST_VALUE     4
+#define TEE_PARAM_ATTR_TYPE_MEMREF_INPUT       5
+#define TA_AVB_CMD_WRITE_PERSIST_VALUE    5
+
+static int optee_ctx_match(struct tee_ioctl_version_data *ver, const void *data)
+{
+	if (ver->impl_id == TEE_IMPL_ID_OPTEE)
+		return 1;
+	else
+		return 0;
+}
+
+int avb_read_persistent_value(const char *name, size_t buffer_size,
+			      u8 *out_buffer, size_t *out_num_bytes_read)
+{
+	const uuid_t avb_uuid = TA_AVB_UUID;
+	int rc = 0;
+	struct tee_shm *shm_name;
+	struct tee_shm *shm_buf;
+	struct tee_param param[2];
+	size_t name_size = strlen(name) + 1;
+	struct tee_ioctl_open_session_arg sess_arg = {};
+	struct tee_context *ctx = NULL;
+	struct tee_ioctl_invoke_arg arg;
+
+	ctx = tee_client_open_context(NULL, optee_ctx_match, NULL, NULL);
+	if (IS_ERR(ctx))
+		return -ENODEV;
+
+	export_uuid(sess_arg.uuid, &avb_uuid);
+	sess_arg.clnt_login = TEE_IOCTL_LOGIN_PUBLIC;
+	sess_arg.num_params = 0;
+
+	rc = tee_client_open_session(ctx, &sess_arg, NULL);
+	if ((rc < 0) || (sess_arg.ret != TEEC_SUCCESS)) {
+		pr_debug("%s device enumeration pseudo TA not found\n", __func__);
+		rc = 0;
+		goto out_ctx;
+	}
+
+	shm_name = tee_shm_alloc_kernel_buf(ctx, name_size);
+	if (IS_ERR(shm_name)) {
+		rc = -ENOMEM;
+		goto close_session;
+	}
+
+	shm_buf = tee_shm_alloc_kernel_buf(ctx, buffer_size);
+	if (IS_ERR(shm_buf)) {
+		rc = -ENOMEM;
+		goto free_name;
+	}
+
+	memcpy(shm_name->kaddr, name, name_size);
+
+	memset(param, 0, sizeof(param));
+	param[0].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INPUT;
+	param[0].u.memref.shm = shm_name;
+	param[0].u.memref.size = name_size;
+	param[1].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INOUT;
+	param[1].u.memref.shm = shm_buf;
+	param[1].u.memref.size = buffer_size;
+
+	arg.func = TA_AVB_CMD_READ_PERSIST_VALUE;
+	arg.session = sess_arg.session;
+	arg.num_params = 2;
+
+	rc = tee_client_invoke_func(ctx, &arg, param);
+	if (rc)
+		goto out;
+	switch (arg.ret) {
+	case TEEC_SUCCESS:
+		rc = 0;
+		break;
+	case TEEC_ERROR_ITEM_NOT_FOUND:
+		rc = -ENOENT;
+		break;
+	default:
+		rc = -EINVAL;
+		break;
+	}
+	if (rc)
+		goto out;
+
+	if (param[1].u.memref.size > buffer_size) {
+		rc = -EINVAL;
+		goto out;
+	}
+
+	*out_num_bytes_read = param[1].u.memref.size;
+
+	memcpy(out_buffer, shm_buf->kaddr, *out_num_bytes_read);
+
+out:
+	tee_shm_free(shm_buf);
+free_name:
+	tee_shm_free(shm_name);
+close_session:
+	tee_client_close_session(ctx, sess_arg.session);
+out_ctx:
+	tee_client_close_context(ctx);
+
+	return rc;
+}
+
+int avb_write_persistent_value(const char *name, size_t value_size,
+			       const u8 *value)
+{
+	const uuid_t avb_uuid = TA_AVB_UUID;
+	int rc = 0;
+	struct tee_shm *shm_name;
+	struct tee_shm *shm_buf;
+	struct tee_param param[2];
+	struct tee_ioctl_open_session_arg sess_arg = {};
+	struct tee_context *ctx = NULL;
+	size_t name_size = strlen(name) + 1;
+	struct tee_ioctl_invoke_arg inv_arg;
+
+	if (!value_size)
+		return -EINVAL;
+
+	ctx = tee_client_open_context(NULL, optee_ctx_match, NULL, NULL);
+	if (IS_ERR(ctx))
+		return -ENODEV;
+
+	export_uuid(sess_arg.uuid, &avb_uuid);
+	sess_arg.clnt_login = TEE_IOCTL_LOGIN_PUBLIC;
+	sess_arg.num_params = 0;
+
+	rc = tee_client_open_session(ctx, &sess_arg, NULL);
+	if ((rc < 0) || (sess_arg.ret != TEEC_SUCCESS)) {
+		pr_err("%s AVB TA not found\n", __func__);
+		goto out_ctx;
+	}
+
+	shm_name = tee_shm_alloc_kernel_buf(ctx, name_size);
+	if (IS_ERR(shm_name)) {
+		rc = -ENOMEM;
+		goto close_session;
+	}
+
+	shm_buf = tee_shm_alloc_kernel_buf(ctx, value_size);
+	if (IS_ERR(shm_buf)) {
+		rc = -ENOMEM;
+		goto free_name;
+	}
+
+	memcpy(shm_name->kaddr, name, name_size);
+	memcpy(shm_buf->kaddr, value, value_size);
+
+	memset(param, 0, sizeof(param));
+	param[0].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INPUT;
+	param[0].u.memref.shm = shm_name;
+	param[0].u.memref.size = name_size;
+	param[1].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INPUT;
+	param[1].u.memref.shm = shm_buf;
+	param[1].u.memref.size = value_size;
+
+	inv_arg.func = TA_AVB_CMD_WRITE_PERSIST_VALUE;
+	inv_arg.session = sess_arg.session;
+	inv_arg.num_params = 2;
+
+	rc = tee_client_invoke_func(ctx, &inv_arg, param);
+	if (rc)
+		goto out;
+	if (inv_arg.ret) {
+		pr_err("invoke func failed with 0x%08x\n", inv_arg.ret);
+		rc = -EIO;
+	}
+
+out:
+	tee_shm_free(shm_buf);
+free_name:
+	tee_shm_free(shm_name);
+close_session:
+	tee_client_close_session(ctx, sess_arg.session);
+out_ctx:
+	tee_client_close_context(ctx);
+
+	return rc;
+}
diff --git a/include/tee/avb.h b/include/tee/avb.h
new file mode 100644
index 0000000000..3873b5c59b
--- /dev/null
+++ b/include/tee/avb.h
@@ -0,0 +1,9 @@
+#ifndef TEE_AVB_H
+#define TEE_AVB_H
+
+int avb_write_persistent_value(const char *name, size_t value_size,
+			       const u8 *value);
+int avb_read_persistent_value(const char *name, size_t buffer_size,
+			      u8 *out_buffer, size_t *out_num_bytes_read);
+
+#endif /* TEE_AVB_H */

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 12 05:16:21 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:16:21 +0100
Subject: [PATCH 6/9] tee: optee: implement shared mem alloc/free RPC
 commands
In-Reply-To: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
Message-ID: <20250312-rpmb-v1-6-0f213382a3f3@pengutronix.de>

This implements the OPTEE_RPC_CMD_SHM_ALLOC and OPTEE_RPC_CMD_SHM_FREE
commands to let the secure world allocate and free shared memory.

When OP-TEE calls into the nonsecure world in order to allocate shared
memory we'll need a list of pages returned to the secure world. This
is needed in two cases: once when we call into OP-TEE to register the
shared memory with OP-TEE and once in the return parameters of the
OPTEE_RPC_CMD_SHM_ALLOC RPC call. The U-Boot code this code is based on
allocates two separate page lists. In barebox we attach the page list
to the shared memory object instead so that we have to allocate and
initialize it only once.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/tee/optee/optee_private.h |   3 +
 drivers/tee/optee/optee_rpc_cmd.h | 144 ++++++++++++++++++++++++++++++++++++++
 drivers/tee/optee/rpc.c           |  60 +++++++++++++++-
 drivers/tee/optee/smc_abi.c       |  26 ++++---
 drivers/tee/tee_shm.c             |   1 +
 include/linux/tee_drv.h           |   1 +
 6 files changed, 222 insertions(+), 13 deletions(-)

diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h
index 637d3195be..d739a6c609 100644
--- a/drivers/tee/optee/optee_private.h
+++ b/drivers/tee/optee/optee_private.h
@@ -17,7 +17,10 @@
 
 /* Some Global Platform error codes used in this driver */
 #define TEEC_SUCCESS			0x00000000
+#define TEEC_ERROR_GENERIC		0xffff0000
 #define TEEC_ERROR_BAD_PARAMETERS	0xFFFF0006
+#define TEEC_ERROR_ITEM_NOT_FOUND	0xffff0008
+#define TEEC_ERROR_NOT_IMPLEMENTED	0xFFFF0009
 #define TEEC_ERROR_NOT_SUPPORTED	0xFFFF000A
 #define TEEC_ERROR_COMMUNICATION	0xFFFF000E
 #define TEEC_ERROR_OUT_OF_MEMORY	0xFFFF000C
diff --git a/drivers/tee/optee/optee_rpc_cmd.h b/drivers/tee/optee/optee_rpc_cmd.h
new file mode 100644
index 0000000000..3ef5672be7
--- /dev/null
+++ b/drivers/tee/optee/optee_rpc_cmd.h
@@ -0,0 +1,144 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Copyright (c) 2016-2021, Linaro Limited
+ */
+
+#ifndef __OPTEE_RPC_CMD_H
+#define __OPTEE_RPC_CMD_H
+
+/*
+ * All RPC is done with a struct optee_msg_arg as bearer of information,
+ * struct optee_msg_arg::arg holds values defined by OPTEE_RPC_CMD_* below.
+ * Only the commands handled by the kernel driver are defined here.
+ *
+ * RPC communication with tee-supplicant is reversed compared to normal
+ * client communication described above. The supplicant receives requests
+ * and sends responses.
+ */
+
+#define OPTEE_RPC_CMD_RPMB		1
+
+/*
+ * Get time
+ *
+ * Returns number of seconds and nano seconds since the Epoch,
+ * 1970-01-01 00:00:00 +0000 (UTC).
+ *
+ * [out]    value[0].a	    Number of seconds
+ * [out]    value[0].b	    Number of nano seconds.
+ */
+#define OPTEE_RPC_CMD_GET_TIME		3
+
+/*
+ * Notification from/to secure world.
+ *
+ * If secure world needs to wait for something, for instance a mutex, it
+ * does a notification wait request instead of spinning in secure world.
+ * Conversely can a synchronous notification can be sent when a secure
+ * world mutex with a thread waiting thread is unlocked.
+ *
+ * This interface can also be used to wait for a asynchronous notification
+ * which instead is sent via a non-secure interrupt.
+ *
+ * Waiting on notification
+ * [in]    value[0].a	    OPTEE_RPC_NOTIFICATION_WAIT
+ * [in]    value[0].b	    notification value
+ * [in]    value[0].c	    timeout in milliseconds or 0 if no timeout
+ *
+ * Sending a synchronous notification
+ * [in]    value[0].a	    OPTEE_RPC_NOTIFICATION_SEND
+ * [in]    value[0].b	    notification value
+ */
+#define OPTEE_RPC_CMD_NOTIFICATION	4
+#define OPTEE_RPC_NOTIFICATION_WAIT	0
+#define OPTEE_RPC_NOTIFICATION_SEND	1
+
+/*
+ * Suspend execution
+ *
+ * [in]    value[0].a	Number of milliseconds to suspend
+ */
+#define OPTEE_RPC_CMD_SUSPEND		5
+
+/*
+ * Allocate a piece of shared memory
+ *
+ * [in]    value[0].a	    Type of memory one of
+ *			    OPTEE_RPC_SHM_TYPE_* below
+ * [in]    value[0].b	    Requested size
+ * [in]    value[0].c	    Required alignment
+ * [out]   memref[0]	    Buffer
+ */
+#define OPTEE_RPC_CMD_SHM_ALLOC		6
+/* Memory that can be shared with a non-secure user space application */
+#define OPTEE_RPC_SHM_TYPE_APPL		0
+/* Memory only shared with non-secure kernel */
+#define OPTEE_RPC_SHM_TYPE_KERNEL	1
+
+/*
+ * Free shared memory previously allocated with OPTEE_RPC_CMD_SHM_ALLOC
+ *
+ * [in]     value[0].a	    Type of memory one of
+ *			    OPTEE_RPC_SHM_TYPE_* above
+ * [in]     value[0].b	    Value of shared memory reference or cookie
+ */
+#define OPTEE_RPC_CMD_SHM_FREE		7
+
+/*
+ * Issue master requests (read and write operations) to an I2C chip.
+ *
+ * [in]     value[0].a	    Transfer mode (OPTEE_RPC_I2C_TRANSFER_*)
+ * [in]     value[0].b	    The I2C bus (a.k.a adapter).
+ *				16 bit field.
+ * [in]     value[0].c	    The I2C chip (a.k.a address).
+ *				16 bit field (either 7 or 10 bit effective).
+ * [in]     value[1].a	    The I2C master control flags (ie, 10 bit address).
+ *				16 bit field.
+ * [in/out] memref[2]	    Buffer used for data transfers.
+ * [out]    value[3].a	    Number of bytes transferred by the REE.
+ */
+#define OPTEE_RPC_CMD_I2C_TRANSFER	21
+
+/* I2C master transfer modes */
+#define OPTEE_RPC_I2C_TRANSFER_RD	0
+#define OPTEE_RPC_I2C_TRANSFER_WR	1
+
+/* I2C master control flags */
+#define OPTEE_RPC_I2C_FLAGS_TEN_BIT	BIT(0)
+
+/*
+ * Reset RPMB probing
+ *
+ * Releases an eventually already used RPMB devices and starts over searching
+ * for RPMB devices. Returns the kind of shared memory to use in subsequent
+ * OPTEE_RPC_CMD_RPMB_PROBE_NEXT and OPTEE_RPC_CMD_RPMB calls.
+ *
+ * [out]    value[0].a	    OPTEE_RPC_SHM_TYPE_*, the parameter for
+ *			    OPTEE_RPC_CMD_SHM_ALLOC
+ */
+#define OPTEE_RPC_CMD_RPMB_PROBE_RESET	22
+
+/*
+ * Probe next RPMB device
+ *
+ * [out]    value[0].a	    Type of RPMB device, OPTEE_RPC_RPMB_*
+ * [out]    value[0].b	    EXT CSD-slice 168 "RPMB Size"
+ * [out]    value[0].c	    EXT CSD-slice 222 "Reliable Write Sector Count"
+ * [out]    memref[1]       Buffer with the raw CID
+ */
+#define OPTEE_RPC_CMD_RPMB_PROBE_NEXT	23
+
+/* Type of RPMB device */
+#define OPTEE_RPC_RPMB_EMMC		0
+#define OPTEE_RPC_RPMB_UFS		1
+#define OPTEE_RPC_RPMB_NVME		2
+
+/*
+ * Replay Protected Memory Block access
+ *
+ * [in]     memref[0]	    Frames to device
+ * [out]    memref[1]	    Frames from device
+ */
+#define OPTEE_RPC_CMD_RPMB_FRAMES	24
+
+#endif /*__OPTEE_RPC_CMD_H*/
diff --git a/drivers/tee/optee/rpc.c b/drivers/tee/optee/rpc.c
index 3d0a7f2980..bdb2a9da74 100644
--- a/drivers/tee/optee/rpc.c
+++ b/drivers/tee/optee/rpc.c
@@ -7,10 +7,66 @@
 
 #include <linux/tee_drv.h>
 #include "optee_private.h"
+#include "optee_rpc_cmd.h"
+
+static void cmd_shm_alloc(struct tee_context *ctx, struct optee_msg_arg *arg)
+{
+	struct tee_shm *shm;
+
+	arg->ret_origin = TEEC_ORIGIN_COMMS;
+
+	if (arg->num_params != 1 ||
+	    arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_INPUT) {
+		arg->ret = TEEC_ERROR_BAD_PARAMETERS;
+		return;
+	}
+
+	shm = tee_shm_alloc_kernel_buf(ctx, arg->params[0].u.value.b);
+	if (IS_ERR(shm)) {
+		if (PTR_ERR(shm) == -ENOMEM)
+			arg->ret = TEEC_ERROR_OUT_OF_MEMORY;
+		else
+			arg->ret = TEEC_ERROR_GENERIC;
+		return;
+	}
+
+	arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT |
+			      OPTEE_MSG_ATTR_NONCONTIG;
+	arg->params[0].u.tmem.buf_ptr = virt_to_phys(shm->pages_list);
+	arg->params[0].u.tmem.size = shm->size;
+	arg->params[0].u.tmem.shm_ref = (ulong)shm;
+	arg->ret = TEEC_SUCCESS;
+}
+
+static void cmd_shm_free(struct optee_msg_arg *arg)
+{
+	arg->ret_origin = TEEC_ORIGIN_COMMS;
+
+	if (arg->num_params != 1 ||
+	    arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_INPUT) {
+		arg->ret = TEEC_ERROR_BAD_PARAMETERS;
+		return;
+	}
+
+	tee_shm_free((struct tee_shm *)(ulong)arg->params[0].u.value.b);
+	arg->ret = TEEC_SUCCESS;
+}
 
 void optee_rpc_cmd(struct tee_context *ctx, struct optee *optee,
 		   struct optee_msg_arg *arg)
 {
-	pr_notice_once("optee: No supplicant or RPC handler for command 0x%x\n", arg->cmd);
-	arg->ret = TEEC_ERROR_NOT_SUPPORTED;
+	pr_debug("%s: receive RPC CMD: %d\n", __func__, arg->cmd);
+
+	switch (arg->cmd) {
+	case OPTEE_RPC_CMD_SHM_ALLOC:
+		cmd_shm_alloc(ctx, arg);
+		break;
+	case OPTEE_RPC_CMD_SHM_FREE:
+		cmd_shm_free(arg);
+		break;
+	default:
+		arg->ret = TEEC_ERROR_NOT_IMPLEMENTED;
+	}
+
+	arg->ret_origin = TEEC_ORIGIN_COMMS;
 }
diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c
index 354a94a2f2..aab8ebb186 100644
--- a/drivers/tee/optee/smc_abi.c
+++ b/drivers/tee/optee/smc_abi.c
@@ -301,7 +301,7 @@ static int optee_shm_register(struct tee_context *ctx, struct tee_shm *shm)
 	struct tee_shm *shm_arg;
 	u64 *pages_list;
 	u64 ph_ptr;
-	int rc = 0;
+	int rc;
 
 	pages_list = optee_alloc_and_init_page_list(shm->kaddr, shm->size, &ph_ptr);
 	if (!pages_list)
@@ -314,7 +314,7 @@ static int optee_shm_register(struct tee_context *ctx, struct tee_shm *shm)
 	msg_arg = optee_get_msg_arg(ctx, 1, &shm_arg);
 	if (IS_ERR(msg_arg)) {
 		rc = PTR_ERR(msg_arg);
-		goto free_pages_list;
+		goto err_free;
 	}
 
 	msg_arg->num_params = 1;
@@ -326,11 +326,20 @@ static int optee_shm_register(struct tee_context *ctx, struct tee_shm *shm)
 	msg_arg->params->u.tmem.size = tee_shm_get_size(shm);
 
 	if (optee->ops->do_call_with_arg(ctx, msg_arg) ||
-	    msg_arg->ret != TEEC_SUCCESS)
+	    msg_arg->ret != TEEC_SUCCESS) {
 		rc = -EINVAL;
+		goto err_free_msg_arg;
+	}
+
+	optee_free_msg_arg(ctx, shm_arg);
+
+	shm->pages_list = pages_list;
 
+	return 0;
+
+err_free_msg_arg:
 	optee_free_msg_arg(ctx, shm_arg);
-free_pages_list:
+err_free:
 	free(pages_list);
 
 	return rc;
@@ -383,8 +392,7 @@ static int optee_shm_unregister(struct tee_context *ctx, struct tee_shm *shm)
  *
  * Result of RPC is written back into @param.
  */
-static void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param,
-			     void *page_list)
+static void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param)
 {
 	struct tee_device *teedev = ctx->teedev;
 	struct optee *optee = tee_get_drvdata(teedev);
@@ -448,7 +456,6 @@ static int optee_smc_do_call_with_arg(struct tee_context *ctx,
 {
 	struct optee *optee = tee_get_drvdata(ctx->teedev);
 	struct optee_rpc_param param = { .a0 = OPTEE_SMC_CALL_WITH_ARG };
-	void *page_list = NULL;
 
 	reg_pair_from_64(&param.a1, &param.a2, virt_to_phys(arg));
 	while (true) {
@@ -461,15 +468,12 @@ static int optee_smc_do_call_with_arg(struct tee_context *ctx,
 		optee->smc.invoke_fn(param.a0, param.a1, param.a2, param.a3,
 				     param.a4, param.a5, param.a6, param.a7, &res);
 
-		free(page_list);
-		page_list = NULL;
-
 		if (OPTEE_SMC_RETURN_IS_RPC(res.a0)) {
 			param.a0 = res.a0;
 			param.a1 = res.a1;
 			param.a2 = res.a2;
 			param.a3 = res.a3;
-			optee_handle_rpc(ctx, &param, &page_list);
+			optee_handle_rpc(ctx, &param);
 		} else {
 			return res.a0;
 		}
diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
index 9952608435..50ed086d0e 100644
--- a/drivers/tee/tee_shm.c
+++ b/drivers/tee/tee_shm.c
@@ -32,6 +32,7 @@ static void tee_shm_release(struct tee_device *teedev, struct tee_shm *shm)
 
 	teedev_ctx_put(shm->ctx);
 
+	kfree(shm->pages_list);
 	kfree(shm);
 
 	tee_device_put(teedev);
diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h
index 7289c3057a..e2c1042deb 100644
--- a/include/linux/tee_drv.h
+++ b/include/linux/tee_drv.h
@@ -194,6 +194,7 @@ struct tee_shm {
 	struct tee_context *ctx;
 	phys_addr_t paddr;
 	void *kaddr;
+	u64 *pages_list;
 	size_t size;
 	refcount_t refcount;
 	u32 flags;

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 12 05:31:32 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:31:32 +0100
Subject: [PATCH 0/2] Move pca9450 RESET_CTRL configuration to driver
In-Reply-To: <cbb86516-6337-44ba-a957-5620e5eb5015@pengutronix.de>
References: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
 <a2b2fd98bb4d5f5597b55587ddc9f6b6e4da8fcb.camel@pengutronix.de>
 <cbb86516-6337-44ba-a957-5620e5eb5015@pengutronix.de>
Message-ID: <Z9F-pB6dHxuzvkb6@pengutronix.de>

On Tue, Mar 11, 2025 at 12:40:03PM +0100, Jonas Rebmann wrote:
> Hi Rouven,
> 
> On 2025-03-11 12:05, Rouven Czerwinski wrote:
> > Does it make sense to select the pcs9450 in the board kconfig symbols?
> > This way users retain the behaviour after an update even if the pca9450
> > driver was not selected before.
> 
> Are you referring to a scenario where removal of an explicit initialization
> of PCA9450_RESET_CTRL in favor of the setup in the driver would lead to an
> unitialized PCA9450_RESET_CTRL if the driver is not enabled?
> 
> For the imx93 boards, behaviour remains unchanged same as those two boards
> configure PCA9450_RESET_CTRL in pca9450_register_init_callback, which is
> called by the driver. So change in behavior with those.
> 
> Not so on the imx8 boards where pmic_configure is called unconditionally in
> the power-on routine.
> 
> Given this, I'm not sure if we should remove the explicit register config
> for the imx8 boards as Ahmad mentioned. I think I remember Sasha mentioning
> a reason why board kconfig doesn't select the pmic driver?..

Yes. We can't select the PMIC driver from the board Kconfig because we
would also have to select all direct dependencies like I2C. Although not
a direct dependency we would also have to select the I2C hardware bus
driver, because without it we also could not access the PMIC. All this
is cumbersome to do, so better avoided. If necessary we could issue a
warning message at runtime and leave it up to the user to select the
missing pieces.

Sascha


-- 
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-5555 |


From s.hauer at pengutronix.de  Wed Mar 12 05:38:56 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:38:56 +0100
Subject: [PATCH 1/2] mfd: pca9450: configure pmic reset behavior
In-Reply-To: <20250311-pca9450-wdog-v1-1-45120abeae00@pengutronix.de>
References: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
 <20250311-pca9450-wdog-v1-1-45120abeae00@pengutronix.de>
Message-ID: <Z9GAYICcORX5RQgU@pengutronix.de>

On Tue, Mar 11, 2025 at 11:50:17AM +0100, Jonas Rebmann wrote:
> Currently, boards using the pca9450 pmic driver initialize the
> RESET_CTRL register either in lowlevel.c or board.c explicitly to 0xA1
> to enable the watchdog for Cold Reset with all voltage regulators
> recycled except LDO1/ LDO2 in addition to the default configuration of
> 0x11 where the WDOG_B watchdog input is disabled.
> 
> Instead, enable the watchdog in the driver for Cold Reset with all
> voltage regulators recycled except LDO1/ LDO2. When
> nxp,wdog_b-warm-reset is set, the watchdog is instead enabled for Warm
> Reset.
> 
> This is identical to U-Boot's behaviour since commit 910c7a881f5 and
> Linux's since commit 2364a64d0673f.

Please add the commit description like

910c7a881f5 ("pmic: pca9450: Make warm reset on WDOG_B assertion") and
2364a64d0673f ("regulator: pca9450: Make warm reset on WDOG_B assertion")

> 
> Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
> ---
>  drivers/mfd/pca9450.c | 11 +++++++++++
>  include/mfd/pca9450.h |  4 ++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/drivers/mfd/pca9450.c b/drivers/mfd/pca9450.c
> index 2511e662c3dfb5dfedbc461357ffa82d1812166f..6d6fb32c36569689b901455b3376c92977eabc37 100644
> --- a/drivers/mfd/pca9450.c
> +++ b/drivers/mfd/pca9450.c
> @@ -3,6 +3,7 @@
>   * Copyright (C) 2023 Holger Assmann, Pengutronix
>   */
>  
> +#include "linux/regmap.h"

Please include files from the include paths with <> rather than "".

In this case you can drop it entirely, because linux/regmap.h is already
included by regmap.h

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Wed Mar 12 05:43:26 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Mar 2025 13:43:26 +0100
Subject: [PATCH 2/2] ARM: boards: remove obsolete PCA9450_RESET_CTRL setup
In-Reply-To: <2a97c0f8-f9fd-47f0-8ac6-a0c5b7499dc1@pengutronix.de>
References: <20250311-pca9450-wdog-v1-0-45120abeae00@pengutronix.de>
 <20250311-pca9450-wdog-v1-2-45120abeae00@pengutronix.de>
 <f6277af8-56a9-4327-a299-d2e2d39cbc1a@pengutronix.de>
 <2a97c0f8-f9fd-47f0-8ac6-a0c5b7499dc1@pengutronix.de>
Message-ID: <Z9GBboek1bS-u1rb@pengutronix.de>

On Tue, Mar 11, 2025 at 12:21:52PM +0100, Jonas Rebmann wrote:
> Hi Ahmad,
> 
> Not so much. As mentioned in the cover, the imx8 boards routinely configure
> a larger array of pca9450 registers. As I didn't give the rest of that setup
> a closer look, I did not change the code.
> 
> I have only tested this series on the phyboard segin imx93.
> 
> Just like with the imx93 boards, after application of the driver patch, the
> { PCA9450_RESET_CTRL, 0xA1 } lines in lowlevel.c should no more have an
> effect (as no board currently uses nxp,wdog_b-warm-reset).
> 
> Should I remove all { PCA9450_RESET_CTRL, 0xA1 } configuration in v2?

Better not. We have other PMIC register accesses in the lowlevel.c
anyway, so having one more doesn't hurt. The positive effect is that
these boards work better in case the PMIC driver is disabled.

Sascha

-- 
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-5555 |


From o.rempel at pengutronix.de  Wed Mar 12 06:45:36 2025
From: o.rempel at pengutronix.de (Oleksij Rempel)
Date: Wed, 12 Mar 2025 14:45:36 +0100
Subject: [PATCH v1] commands: Add `ip` command for listing interfaces, addresses, and routes
Message-ID: <20250312134536.3232324-1-o.rempel@pengutronix.de>

This patch introduces the `ip` command, providing functionality similar
to Linux?s `ip` tool, catering to users with strong Linux muscle memory.
It supports:

- `ip l` / `ip link`   - Show network interfaces (state, MAC address)
- `ip a` / `ip addr`   - Show assigned IP addresses and netmasks
- `ip r` / `ip route`  - Show routing table, including default gateway,
                         interface-specific routes, DNS, and server IP.

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 commands/Kconfig  |   9 +++
 commands/Makefile |   1 +
 commands/ip.c     | 157 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 167 insertions(+)
 create mode 100644 commands/ip.c

diff --git a/commands/Kconfig b/commands/Kconfig
index e41625e294c9..528b30b8fc90 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1397,6 +1397,15 @@ config CMD_TFTP
 	  Options:
 		  -p	push to TFTP server
 
+config CMD_IP
+	tristate
+	prompt "ip"
+	default y
+	help
+          This command provides information about network interfaces, similar
+	  to the Linux `ip addr show` command. It lists interface names, states
+	  (UP/DOWN), MAC addresses, and assigned IP addresses.
+
 config CMD_IP_ROUTE_GET
 	tristate
 	prompt "ip-route-get"
diff --git a/commands/Makefile b/commands/Makefile
index e152e4148b04..c202cdef5703 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -146,6 +146,7 @@ obj-$(CONFIG_CMD_MMC)		+= mmc.o
 obj-$(CONFIG_CMD_MMC_EXTCSD)	+= mmc_extcsd.o
 obj-$(CONFIG_CMD_NAND_BITFLIP)	+= nand-bitflip.o
 obj-$(CONFIG_CMD_SEED)		+= seed.o
+obj-$(CONFIG_CMD_IP)		+= ip.o
 obj-$(CONFIG_CMD_IP_ROUTE_GET)  += ip-route-get.o
 obj-$(CONFIG_CMD_BTHREAD)	+= bthread.o
 obj-$(CONFIG_CMD_UBSAN)		+= ubsan.o
diff --git a/commands/ip.c b/commands/ip.c
new file mode 100644
index 000000000000..35fc5f4d300f
--- /dev/null
+++ b/commands/ip.c
@@ -0,0 +1,157 @@
+#include <common.h>
+#include <command.h>
+#include <net.h>
+#include <linux/list.h>
+#include <complete.h>
+
+/* Function to calculate CIDR prefix from netmask */
+static int netmask_to_prefix(IPaddr_t netmask)
+{
+	int prefix = 0;
+
+	while (netmask) {
+		prefix += netmask & 1;
+		netmask >>= 1;
+	}
+
+	return prefix;
+}
+
+/* Function to display network links (`ip l`) */
+static int do_ip_link(int argc, char *argv[])
+{
+	struct eth_device *edev;
+
+	for_each_netdev(edev) {
+		const char *phy_status = edev->phydev ?
+			(edev->phydev->link ? ",LOWER_UP" : ",NO-CARRIER") : "";
+
+		printf("%s: <%s%s>\n",
+			   eth_name(edev),
+			   edev->active ? "UP" : "DOWN",
+			   phy_status);
+
+		printf("	link/ether %pM brd ff:ff:ff:ff:ff:ff\n",
+		       edev->ethaddr);
+	}
+
+	return 0;
+}
+
+/* Function to display network addresses (`ip a`) */
+static int do_ip_addr(int argc, char *argv[])
+{
+	struct eth_device *edev;
+
+	for_each_netdev(edev) {
+		IPaddr_t ipaddr = net_get_ip(edev);
+		int prefix_length = netmask_to_prefix(edev->netmask);
+		const char *phy_status = edev->phydev ?
+			(edev->phydev->link ? ",LOWER_UP" : ",NO-CARRIER") : "";
+
+		printf("%s: <%s%s>\n", eth_name(edev),
+		       edev->active ? "UP" : "DOWN", phy_status);
+
+		printf("	link/ether %pM brd ff:ff:ff:ff:ff:ff\n",
+		       edev->ethaddr);
+
+		if (ipaddr) {
+			printf("	inet %pI4/%d scope global src %pI4\n",
+				   &ipaddr, prefix_length, &ipaddr);
+		}
+	}
+
+	return 0;
+}
+
+/* Function to display network routes (`ip r`) */
+static int do_ip_route(int argc, char *argv[])
+{
+	const char *domainname = net_get_domainname();
+	IPaddr_t nameserver = net_get_nameserver();
+	const char *serverip = net_get_server();
+	IPaddr_t gateway = net_get_gateway();
+	struct eth_device *edev;
+
+	for_each_netdev(edev) {
+		int prefix_length = netmask_to_prefix(edev->netmask);
+		IPaddr_t ipaddr = net_get_ip(edev);
+		const char *proto;
+
+		/* Skip interfaces without an IP address */
+		if (!ipaddr)
+			continue;
+
+		/* Determine protocol: DHCP or Static */
+		if (edev->global_mode == ETH_MODE_DHCP)
+			proto = "dhcp";
+		else
+			proto = "static";
+
+		/* Show default gateway */
+		if (gateway) {
+			printf("default via %pI4 dev %s proto %s src %pI4\n",
+				   &gateway, eth_name(edev), proto, &ipaddr);
+		}
+
+		/* Show per-interface network route */
+		if (prefix_length > 0) {
+			printf("%pI4/%d dev %s proto kernel scope link src %pI4\n",
+				   &ipaddr, prefix_length, eth_name(edev),
+				   &ipaddr);
+		}
+	}
+
+	/* Show boot server */
+	if (serverip && *serverip) {
+		printf("serverip %s\n", serverip);
+	}
+
+	/* Show DNS server */
+	if (nameserver) {
+		printf("nameserver %pI4\n", &nameserver);
+	}
+
+	/* Show search domain */
+	if (domainname && *domainname) {
+		printf("search %s\n", domainname);
+	}
+
+	return 0;
+}
+
+/* Main IP command dispatcher */
+static int do_ip(int argc, char *argv[])
+{
+	if (argc < 2) {
+		return do_ip_addr(argc, argv); /* Default: `ip a` */
+	}
+
+	if (!strcmp(argv[1], "l") || !strcmp(argv[1], "link"))
+		return do_ip_link(argc, argv);
+	else if (!strcmp(argv[1], "a") || !strcmp(argv[1], "addr"))
+		return do_ip_addr(argc, argv);
+	else if (!strcmp(argv[1], "r") || !strcmp(argv[1], "route"))
+		return do_ip_route(argc, argv);
+
+	printf("Usage: ip [l|link] | [a|addr] | [r|route]\n");
+	return 1;
+}
+
+BAREBOX_CMD_HELP_START(ip)
+BAREBOX_CMD_HELP_TEXT("Show network interfaces, addresses, and routes")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("l, link", "Show only network links (interface state and MAC)")
+BAREBOX_CMD_HELP_OPT("a, addr", "Show only network addresses (default behavior)")
+BAREBOX_CMD_HELP_OPT("r, route", "Show routing information (default gateway, network routes, server IP, DNS)")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(ip)
+	.cmd		= do_ip,
+	BAREBOX_CMD_DESC("Show network interfaces, addresses, and routes")
+	BAREBOX_CMD_OPTS("[l|link] | [a|addr] | [r|route]")
+	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+	BAREBOX_CMD_COMPLETE(empty_complete)
+	BAREBOX_CMD_HELP(cmd_ip_help)
+BAREBOX_CMD_END
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 12 23:37:26 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 07:37:26 +0100
Subject: [PATCH 1/2] kbuild: export whether we are cross compiling
Message-ID: <20250313063727.70946-1-a.fatoum@pengutronix.de>

scripts/kconfig makes use of this variable to inform whether the local
system's config should be used when no config exists.

Set it in barebox like Linux does.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Makefile | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Makefile b/Makefile
index 9ef07ba34457..760fd7381ece 100644
--- a/Makefile
+++ b/Makefile
@@ -368,6 +368,11 @@ ifeq ($(ARCH),um)
        SRCARCH := sandbox
 endif
 
+export cross_compiling :=
+ifneq ($(SRCARCH),$(SUBARCH))
+cross_compiling := 1
+endif
+
 KCONFIG_CONFIG	?= .config
 
 PKG_CONFIG ?= pkg-config
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 12 23:37:27 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 07:37:27 +0100
Subject: [PATCH 2/2] kbuild: override host system KCONFIG_DEFCONFIG_LIST
In-Reply-To: <20250313063727.70946-1-a.fatoum@pengutronix.de>
References: <20250313063727.70946-1-a.fatoum@pengutronix.de>
Message-ID: <20250313063727.70946-2-a.fatoum@pengutronix.de>

KCONFIG_DEFCONFIG_LIST contains some default locations where a Kernel
config can be found (e.g. /boot/config-$(uname -r)).

Currently, if a config is found in these default locations, it's used as
initial config for barebox as well, which doesn't work well, because
barebox architecture symbols defer quite a bit from the Linux ones.

Let's therefore set the make variable to an empty string to avoid this
issue.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 760fd7381ece..5433927ed197 100644
--- a/Makefile
+++ b/Makefile
@@ -602,10 +602,10 @@ include $(srctree)/arch/$(SRCARCH)/Makefile
 export KBUILD_DEFCONFIG CC_VERSION_TEXT
 
 config: outputmakefile scripts_basic FORCE
-	$(Q)$(MAKE) $(build)=scripts/kconfig $@
+	$(Q)$(MAKE) $(build)=scripts/kconfig KCONFIG_DEFCONFIG_LIST= $@
 
 %config: outputmakefile scripts_basic FORCE
-	$(Q)$(MAKE) $(build)=scripts/kconfig $@
+	$(Q)$(MAKE) $(build)=scripts/kconfig KCONFIG_DEFCONFIG_LIST= $@
 
 else #!config-build
 # ===========================================================================
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 12 23:42:09 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 07:42:09 +0100
Subject: [PATCH 1/2] vsprintf: make basprintf an alias of xasprintf
Message-ID: <20250313064210.74011-1-a.fatoum@pengutronix.de>

Less than 12% of all our basprintf callsites actually bother to check
for allocation failure. It's highly unlikely that barebox will be able
to function when the heap is so full that the usually small basprintf
requests fail.

Therefore, make basprintf an alias for xasprintf, so barebox panics on
OOM instead of possibly triggering undefined behavior.

Users doing big allocations with basprintf and wishing to handle their
failure should switch over to asprintf instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/stdio.h |  8 +++-----
 lib/vsprintf.c  | 17 -----------------
 2 files changed, 3 insertions(+), 22 deletions(-)

diff --git a/include/stdio.h b/include/stdio.h
index c02d383d6bad..0e01a0e63a46 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -5,6 +5,7 @@
 #include <stdarg.h>
 #include <console.h>
 #include <printf.h>
+#include <xfuncs.h>
 
 /*
  * STDIO based functions (can always be used)
@@ -21,15 +22,10 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 
 #if IN_PROPER || defined(CONFIG_PBL_CONSOLE)
-char *basprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
 int asprintf(char **strp, const char *fmt, ...)  __attribute__ ((format(__printf__, 2, 3)));
 char *bvasprintf(const char *fmt, va_list ap);
 int vasprintf(char **strp, const char *fmt, va_list ap);
 #else
-static inline char *basprintf(const char *fmt, ...)
-{
-	return NULL;
-}
 static inline int asprintf(char **strp, const char *fmt, ...)
 {
 	return -1;
@@ -44,6 +40,8 @@ static inline int vasprintf(char **strp, const char *fmt, va_list ap)
 }
 #endif
 
+#define basprintf xasprintf
+
 #ifdef CONFIG_ARCH_HAS_CTRLC
 int arch_ctrlc(void);
 #endif
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index cb42caebca16..9d3c7e09f08a 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -978,20 +978,3 @@ int asprintf(char **strp, const char *fmt, ...)
 	return len;
 }
 EXPORT_SYMBOL(asprintf);
-
-char *basprintf(const char *fmt, ...)
-{
-	va_list ap;
-	char *p;
-	int len;
-
-	va_start(ap, fmt);
-	len = vasprintf(&p, fmt, ap);
-	va_end(ap);
-
-	if (len < 0)
-		return NULL;
-
-	return p;
-}
-EXPORT_SYMBOL(basprintf);
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 12 23:42:10 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 07:42:10 +0100
Subject: [PATCH 2/2] treewide: remove NULL checks for revised basprintf
In-Reply-To: <20250313064210.74011-1-a.fatoum@pengutronix.de>
References: <20250313064210.74011-1-a.fatoum@pengutronix.de>
Message-ID: <20250313064210.74011-2-a.fatoum@pengutronix.de>

Of all >200 instances of basprintf in barebox, only 25 actually checked
for NULL. A previous commit made basprintf an alias for xasprintf, so
let's drop these 25 unneeded NULL checks and while at it, change the
code to use xasprintf to make it clearer that this operation panics on
OOM.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/boards/protonic-imx6/board.c        | 24 ++++----------------
 arch/arm/mach-stm32mp/bbu.c                  |  4 +---
 commands/tftp.c                              |  7 ++----
 common/memory.c                              |  7 +-----
 common/oftree.c                              | 11 +++------
 common/partitions.c                          |  4 +---
 drivers/clk/ti-sci-clk.c                     | 10 ++------
 drivers/mtd/nand/raw/atmel/nand-controller.c |  6 +----
 drivers/pmdomain/ti/ti-k3.c                  |  2 +-
 drivers/pmdomain/ti/ti_sci_pm_domains.c      |  4 +---
 drivers/regulator/scmi-regulator.c           |  4 +---
 drivers/spi/spi-fsl-qspi.c                   | 10 +-------
 drivers/spi/spi-nxp-fspi.c                   | 10 +-------
 drivers/spi/spi.c                            |  4 +---
 drivers/tee/tee_shm.c                        |  4 +---
 drivers/video/imx-ipu-v3/ipu-di.c            |  4 +---
 drivers/w1/slaves/w1_ds2431.c                |  4 +---
 drivers/w1/slaves/w1_ds2433.c                |  4 +---
 fs/devfs-core.c                              |  4 +---
 include/w1_mac_address.h                     |  4 +---
 20 files changed, 27 insertions(+), 104 deletions(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 9e62dc154409..db1d88943c27 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -527,21 +527,13 @@ static int prt_imx6_bbu(struct prt_imx6_priv *priv)
 		emmc_flags = BBU_HANDLER_FLAG_DEFAULT;
 	}
 
-	devicefile = basprintf("/dev/mmc%d", dcfg->emmc_usdhc);
-	if (!devicefile) {
-		ret = -ENOMEM;
-		goto exit_bbu;
-	}
+	devicefile = xasprintf("/dev/mmc%d", dcfg->emmc_usdhc);
 	ret = imx6_bbu_internal_mmcboot_register_handler("eMMC", devicefile,
 						   emmc_flags);
 	if (ret)
 		goto exit_bbu;
 
-	devicefile = basprintf("/dev/mmc%d", dcfg->sd_usdhc);
-	if (!devicefile) {
-		ret = -ENOMEM;
-		goto exit_bbu;
-	}
+	devicefile = xasprintf("/dev/mmc%d", dcfg->sd_usdhc);
 
 	ret = imx6_bbu_internal_mmc_register_handler("SD", devicefile, 0);
 	if (ret)
@@ -778,11 +770,7 @@ static int prt_imx6_rfid_fixup(struct prt_imx6_priv *priv,
 	int ret;
 	u8 *tmp;
 
-	alias = basprintf("i2c%d", dcfg->i2c_adapter);
-	if (!alias) {
-		ret = -ENOMEM;
-		goto exit_error;
-	}
+	alias = xasprintf("i2c%d", dcfg->i2c_adapter);
 
 	i2c_node = of_find_node_by_alias(root, alias);
 	kfree(alias);
@@ -791,10 +779,7 @@ static int prt_imx6_rfid_fixup(struct prt_imx6_priv *priv,
 		return -ENODEV;
 	}
 
-	eeprom_node_name = basprintf("/eeprom@%x", dcfg->i2c_addr);
-	if (!eeprom_node_name) {
-		return -ENOMEM;
-	}
+	eeprom_node_name = xasprintf("/eeprom@%x", dcfg->i2c_addr);
 
 	node = of_create_node(i2c_node, eeprom_node_name);
 	if (!node) {
@@ -824,7 +809,6 @@ static int prt_imx6_rfid_fixup(struct prt_imx6_priv *priv,
 	return 0;
 free_eeprom:
 	kfree(eeprom_node_name);
-exit_error:
 	dev_err(priv->dev, "Failed to apply fixup: %pe\n", ERR_PTR(ret));
 	return ret;
 }
diff --git a/arch/arm/mach-stm32mp/bbu.c b/arch/arm/mach-stm32mp/bbu.c
index 5d6d61db7d49..07b511134124 100644
--- a/arch/arm/mach-stm32mp/bbu.c
+++ b/arch/arm/mach-stm32mp/bbu.c
@@ -33,9 +33,7 @@ static int stm32mp_bbu_gpt_part_update(struct bbu_handler *handler,
 	struct stat st;
 	int ret;
 
-	gpt_data.devicefile = basprintf("%s.%s", gpt_data.devicefile, part);
-	if (!gpt_data.devicefile)
-		return -ENOMEM;
+	gpt_data.devicefile = xasprintf("%s.%s", gpt_data.devicefile, part);
 
 	pr_debug("Attempting %s update\n", gpt_data.devicefile);
 
diff --git a/commands/tftp.c b/commands/tftp.c
index 5e8d8d17761d..4356792ce51f 100644
--- a/commands/tftp.c
+++ b/commands/tftp.c
@@ -56,12 +56,9 @@ static int do_tftpb(int argc, char *argv[])
 		dest = argv[optind];
 
 	if (tftp_push)
-		dest = freep = basprintf("%s/%s", TFTP_MOUNT_PATH, dest);
+		dest = freep = xasprintf("%s/%s", TFTP_MOUNT_PATH, dest);
 	else
-		source = freep = basprintf("%s/%s", TFTP_MOUNT_PATH, source);
-
-	if (!freep)
-		return -ENOMEM;
+		source = freep = xasprintf("%s/%s", TFTP_MOUNT_PATH, source);
 
 	ret = make_directory(TFTP_MOUNT_PATH);
 	if (ret)
diff --git a/common/memory.c b/common/memory.c
index c155cb317f25..36aa4bcb8800 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -367,11 +367,7 @@ static int of_memory_fixup(struct device_node *root, void *unused)
 		int len = 0;
 
 		/* Create a /memory node for each bank */
-		memnode_name = basprintf("/memory@%lx", bank->start);
-		if (!memnode_name) {
-			err = -ENOMEM;
-			goto err_out;
-		}
+		memnode_name = xasprintf("/memory@%lx", bank->start);
 
 		memnode = of_create_node(root, memnode_name);
 		if (!memnode) {
@@ -402,7 +398,6 @@ static int of_memory_fixup(struct device_node *root, void *unused)
 
 err_free:
 	free(memnode_name);
-err_out:
 	return err;
 }
 
diff --git a/common/oftree.c b/common/oftree.c
index 2ebde791c708..001f5a19c298 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -172,9 +172,7 @@ static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_nod
 	if (alias_id < 0)
 		return;
 
-	buf = basprintf("systemd.watchdog_device=/dev/watchdog%d", alias_id);
-	if (!buf)
-		return;
+	buf = xasprintf("systemd.watchdog_device=/dev/watchdog%d", alias_id);
 
 	globalvar_add_simple("linux.bootargs.dyn.watchdog", buf);
 	free(buf);
@@ -204,11 +202,8 @@ static int of_write_bootargs(struct device_node *node)
 		const char *oldstr;
 
 		ret = of_property_read_string(node, "bootargs", &oldstr);
-		if (!ret) {
-			str = buf = basprintf("%s %s", oldstr, str);
-			if (!buf)
-				return -ENOMEM;
-		}
+		if (!ret)
+			str = buf = xasprintf("%s %s", oldstr, str);
 	}
 
 	ret = of_property_write_string(node, "bootargs", str);
diff --git a/common/partitions.c b/common/partitions.c
index 8e6bf16e73f1..7562536cf9b8 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -37,9 +37,7 @@ static int register_one_partition(struct block_device *blk, struct partition *pa
 		.size = part->size * SECTOR_SIZE,
 	};
 
-	partition_name = basprintf("%s.%d", blk->cdev.name, part->num);
-	if (!partition_name)
-		return -ENOMEM;
+	partition_name = xasprintf("%s.%d", blk->cdev.name, part->num);
 
 	partinfo.name = partition_name;
 
diff --git a/drivers/clk/ti-sci-clk.c b/drivers/clk/ti-sci-clk.c
index 57e0406553d7..fa1bee5d4ea7 100644
--- a/drivers/clk/ti-sci-clk.c
+++ b/drivers/clk/ti-sci-clk.c
@@ -247,9 +247,7 @@ static int _sci_clk_build(struct sci_clk_provider *provider,
 	int i;
 	int ret = 0;
 
-	name = basprintf("clk:%d:%d", sci_clk->dev_id, sci_clk->clk_id);
-	if (!name)
-		return -ENOMEM;
+	name = xasprintf("clk:%d:%d", sci_clk->dev_id, sci_clk->clk_id);
 
 	init.name = name;
 
@@ -274,13 +272,9 @@ static int _sci_clk_build(struct sci_clk_provider *provider,
 		for (i = 0; i < sci_clk->num_parents; i++) {
 			char *parent_name;
 
-			parent_name = basprintf("clk:%d:%d",
+			parent_name = xasprintf("clk:%d:%d",
 						sci_clk->dev_id,
 						sci_clk->clk_id + 1 + i);
-			if (!parent_name) {
-				ret = -ENOMEM;
-				goto err;
-			}
 			parent_names[i] = parent_name;
 		}
 		init.parent_names = (void *)parent_names;
diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c
index 5188a11cbef6..8add4109b7ae 100644
--- a/drivers/mtd/nand/raw/atmel/nand-controller.c
+++ b/drivers/mtd/nand/raw/atmel/nand-controller.c
@@ -1694,12 +1694,8 @@ static int atmel_nand_attach_chip(struct nand_chip *chip)
 		 * This way, mtd->name will be set by the core when
 		 * nand_set_flash_node() is called.
 		 */
-		mtd->name = basprintf("%s:nand.%d", dev_name(nc->dev),
+		mtd->name = xasprintf("%s:nand.%d", dev_name(nc->dev),
 				      nand->cs[0].id);
-		if (!mtd->name) {
-			dev_err(nc->dev, "Failed to allocate mtd->name\n");
-			return -ENOMEM;
-		}
 	}
 
 	return 0;
diff --git a/drivers/pmdomain/ti/ti-k3.c b/drivers/pmdomain/ti/ti-k3.c
index 1616e90b6230..429de3fa0db2 100644
--- a/drivers/pmdomain/ti/ti-k3.c
+++ b/drivers/pmdomain/ti/ti-k3.c
@@ -448,7 +448,7 @@ static int ti_k3_pm_domain_probe(struct device *dev)
 	priv->pd = pd;
 
 	for (i = 0; i < num_domains; i++, pd++) {
-		pd->genpd.name = basprintf("pd:%d", i);
+		pd->genpd.name = xasprintf("pd:%d", i);
 		pd->lpsc = &data->lpsc[i];
 		pd->genpd.power_off = ti_k3_pm_domain_off;
 		pd->genpd.power_on = ti_k3_pm_domain_on;
diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c
index ab0a4d3829cd..e712121bf5d8 100644
--- a/drivers/pmdomain/ti/ti_sci_pm_domains.c
+++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c
@@ -156,9 +156,7 @@ static int ti_sci_pm_domain_probe(struct device *dev)
 
 				pd = xzalloc(sizeof(*pd));
 
-				pd->pd.name = basprintf("pd:%d", args.args[0]);
-				if (!pd->pd.name)
-					return -ENOMEM;
+				pd->pd.name = xasprintf("pd:%d", args.args[0]);
 
 				pd->pd.power_off = ti_sci_pd_power_off;
 				pd->pd.power_on = ti_sci_pd_power_on;
diff --git a/drivers/regulator/scmi-regulator.c b/drivers/regulator/scmi-regulator.c
index 6f22fa642039..fd42ae35ee7b 100644
--- a/drivers/regulator/scmi-regulator.c
+++ b/drivers/regulator/scmi-regulator.c
@@ -236,9 +236,7 @@ static int scmi_regulator_common_init(struct scmi_regulator *sreg)
 		return -EOPNOTSUPP;
 	}
 
-	sdesc->name = basprintf("%s", vinfo->name);
-	if (!sdesc->name)
-		return -ENOMEM;
+	sdesc->name = xasprintf("%s", vinfo->name);
 
 	if (vinfo->segmented)
 		ret = scmi_config_linear_regulator_mappings(sreg, vinfo);
diff --git a/drivers/spi/spi-fsl-qspi.c b/drivers/spi/spi-fsl-qspi.c
index d242035ee00a..599e5fe96a08 100644
--- a/drivers/spi/spi-fsl-qspi.c
+++ b/drivers/spi/spi-fsl-qspi.c
@@ -743,8 +743,6 @@ static int fsl_qspi_setup(struct spi_device *spi)
 static const char *fsl_qspi_get_name(struct spi_mem *mem)
 {
 	struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->controller);
-	struct device *dev = &mem->spi->dev;
-	const char *name;
 
 	/*
 	 * In order to keep mtdparts compatible with the old MTD driver at
@@ -754,13 +752,7 @@ static const char *fsl_qspi_get_name(struct spi_mem *mem)
 	if (of_get_available_child_count(q->dev->of_node) == 1)
 		return dev_name(q->dev);
 
-	name = basprintf("%s-%d", dev_name(q->dev), mem->spi->chip_select);
-	if (!name) {
-		dev_err(dev, "failed to get memory for custom flash name\n");
-		return ERR_PTR(-ENOMEM);
-	}
-
-	return name;
+	return xasprintf("%s-%d", dev_name(q->dev), mem->spi->chip_select);
 }
 
 static const struct spi_controller_mem_ops fsl_qspi_mem_ops = {
diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
index d8675779dab5..cfef5795a7c8 100644
--- a/drivers/spi/spi-nxp-fspi.c
+++ b/drivers/spi/spi-nxp-fspi.c
@@ -938,21 +938,13 @@ static int nxp_fspi_setup(struct spi_device *spi)
 static const char *nxp_fspi_get_name(struct spi_mem *mem)
 {
 	struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master);
-	struct device *dev = (struct device *)&mem->spi->dev;
-	const char *name;
 
 	/* Set custom name derived from the platform_device of the controller.
 	 */
 	if (of_get_available_child_count(f->dev->of_node) == 1)
 		return dev_name(f->dev);
 
-	name = basprintf("%s-%d", dev_name(f->dev), mem->spi->chip_select);
-	if (!name) {
-		dev_err(dev, "failed to get memory for custom flash name\n");
-		return ERR_PTR(-ENOMEM);
-	}
-
-	return name;
+	return xasprintf("%s-%d", dev_name(f->dev), mem->spi->chip_select);
 }
 
 static const struct spi_controller_mem_ops nxp_fspi_mem_ops = {
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 939164a4817c..c70b22fc0c1b 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -309,9 +309,7 @@ static int spi_get_gpio_descs(struct spi_controller *ctlr)
 			 */
 			char *gpioname;
 
-			gpioname = basprintf("%s CS%d", dev_name(dev), i);
-			if (!gpioname)
-				return -ENOMEM;
+			gpioname = xasprintf("%s CS%d", dev_name(dev), i);
 			gpiod_set_consumer_name(cs[i], gpioname);
 			free(gpioname);
 		}
diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
index 9952608435f6..4cc7911f7695 100644
--- a/drivers/tee/tee_shm.c
+++ b/drivers/tee/tee_shm.c
@@ -242,9 +242,7 @@ int tee_shm_get_fd(struct tee_shm *shm)
 	if (shm->fd < 0) {
 		char *tmp;
 
-		tmp = basprintf("/dev/%s", shm->cdev.name);
-		if (!tmp)
-			return -ENOMEM;
+		tmp = xasprintf("/dev/%s", shm->cdev.name);
 
 		shm->fd = open(tmp, O_RDONLY);
 		free(tmp);
diff --git a/drivers/video/imx-ipu-v3/ipu-di.c b/drivers/video/imx-ipu-v3/ipu-di.c
index 6156911bfc9c..7653d512969f 100644
--- a/drivers/video/imx-ipu-v3/ipu-di.c
+++ b/drivers/video/imx-ipu-v3/ipu-di.c
@@ -729,9 +729,7 @@ int ipu_di_init(struct ipu_soc *ipu, struct device *dev, int id,
 	ipu_di_write(di, 0x10, DI_BS_CLKGEN0);
 
 	di->clk_di_pixel.parent_names = di->di_parent_names;
-	di->clk_name = basprintf("%s_di%d_pixel", dev_name(dev), id);
-	if (!di->clk_name)
-		return -ENOMEM;
+	di->clk_name = xasprintf("%s_di%d_pixel", dev_name(dev), id);
 
 	di->clk_di_pixel.ops = &clk_di_ops;
 	di->clk_di_pixel.num_parents = 2;
diff --git a/drivers/w1/slaves/w1_ds2431.c b/drivers/w1/slaves/w1_ds2431.c
index 9a5f6b5dae62..87640640f133 100644
--- a/drivers/w1/slaves/w1_ds2431.c
+++ b/drivers/w1/slaves/w1_ds2431.c
@@ -269,9 +269,7 @@ static int ds2431_probe(struct w1_device *dev)
 	cdev->priv	= dev;
 	cdev->ops	= &ds2431_ops;
 	cdev->size	= W1_F2D_EEPROM_SIZE;
-	cdev->name	= basprintf(DRIVERNAME"%d", ds2431_count++);
-	if (cdev->name == NULL)
-		return -ENOMEM;
+	cdev->name	= xasprintf(DRIVERNAME"%d", ds2431_count++);
 
 	return devfs_create(cdev);
 }
diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c
index 0e626530db2d..acab7d6dc44e 100644
--- a/drivers/w1/slaves/w1_ds2433.c
+++ b/drivers/w1/slaves/w1_ds2433.c
@@ -166,9 +166,7 @@ static int ds2433_cdev_create(struct w1_device *dev, int size, int id)
 	cdev->priv	= dev;
 	cdev->ops	= &ds2433_ops;
 	cdev->size	= size;
-	cdev->name	= basprintf("%s%d", dev->dev.driver->name, id);
-	if (cdev->name == NULL)
-		return -ENOMEM;
+	cdev->name	= xasprintf("%s%d", dev->dev.driver->name, id);
 
 	return devfs_create(cdev);
 }
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index c9313ed73167..2617eeea0706 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -199,9 +199,7 @@ int cdev_fdopen(struct cdev *cdev, unsigned long flags)
 	if (IS_ERR(cdev))
 		return PTR_ERR(cdev);
 
-	path = basprintf("/dev/%s", cdev->name);
-	if (!path)
-		return -ENOMEM;
+	path = xasprintf("/dev/%s", cdev->name);
 
 	fd = open(path, flags);
 
diff --git a/include/w1_mac_address.h b/include/w1_mac_address.h
index 1ee0ad27c99d..3ec0e7fffdd9 100644
--- a/include/w1_mac_address.h
+++ b/include/w1_mac_address.h
@@ -32,9 +32,7 @@ static inline int w1_local_mac_address_register(int ethid, char * oui, char *w1_
 			addr[i] = oui[i];
 	}
 
-	tmp = basprintf("%s.id", w1_dev);
-	if (!tmp)
-		return -ENOMEM;
+	tmp = xasprintf("%s.id", w1_dev);
 
 	val = getenv(tmp);
 	if (!val) {
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 12 23:45:40 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 07:45:40 +0100
Subject: [PATCH] fs: combine __d_alloc's allocations into one
Message-ID: <20250313064540.76961-1-a.fatoum@pengutronix.de>

Instead of doing two allocations, one for the struct dentry and one for
the full name, just do one allocation and place them after each other.

This has the extra benefit of fixing a leak of the dentry allocation
when the second allocation for the file name fails.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 fs/fs.c                | 13 ++++---------
 include/linux/dcache.h |  2 +-
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 96ca60341ea4..f8b7340d809d 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -795,7 +795,6 @@ static void dentry_kill(struct dentry *dentry)
 		dput(dentry->d_parent);
 
 	list_del(&dentry->d_child);
-	free(dentry->name);
 	free(dentry);
 }
 
@@ -1427,15 +1426,11 @@ static struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
 {
 	struct dentry *dentry;
 
-	dentry = xzalloc(sizeof(*dentry));
-	if (!dentry)
-		return NULL;
-
 	if (!name)
 		name = &slash_name;
 
-	dentry->name = malloc(name->len + 1);
-	if (!dentry->name)
+	dentry = xzalloc(struct_size(dentry, name, name->len + 1));
+	if (!dentry)
 		return NULL;
 
 	memcpy(dentry->name, name->name, name->len);
@@ -3006,9 +3001,9 @@ static char *__dpath(struct dentry *dentry, struct dentry *root)
 
 	ppath = __dpath(dentry->d_parent, root);
 	if (ppath)
-		res = basprintf("%s/%s", ppath, dentry->name);
+		res = basprintf("%s/%s", ppath, dentry->d_name.name);
 	else
-		res = basprintf("/%s", dentry->name);
+		res = basprintf("/%s", dentry->d_name.name);
 	free(ppath);
 
 	return res;
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index ed7e5c2cbcff..1b51a5656703 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -80,7 +80,7 @@ struct dentry {
 	struct dcookie_struct *d_cookie; /* cookie, if any */
 #endif
 	int d_mounted;
-	unsigned char *name;		/* all names */
+	unsigned char name[];		/* all names */
 };
 
 struct dentry_operations {
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 12 23:45:53 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 07:45:53 +0100
Subject: [PATCH 2/6] RISC-V: rename HAS_CACHE to RISCV_ICACHE
In-Reply-To: <20250313064557.77398-1-a.fatoum@pengutronix.de>
References: <20250313064557.77398-1-a.fatoum@pengutronix.de>
Message-ID: <20250313064557.77398-2-a.fatoum@pengutronix.de>

CONFIG_HAS_CACHE only serves a purpose on RISC-V to allow barebox to run
on softcores without fence.i instruction. Rename the symbol to reflect
that in preparation for removing HAS_CACHE altogether.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/riscv/Kconfig.socs        | 9 ++++++---
 arch/riscv/include/asm/cache.h | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs
index ccda688faf6d..4a3b56b5fff4 100644
--- a/arch/riscv/Kconfig.socs
+++ b/arch/riscv/Kconfig.socs
@@ -19,7 +19,7 @@ config SOC_VIRT
 	bool "QEMU Virt Machine"
 	select RISCV_S_MODE
 	select BOARD_GENERIC_DT
-	select HAS_CACHE
+	select RISCV_ICACHE
 	select HAS_DEBUG_LL
 	help
 	  Generates an image tht can be be booted by QEMU. The image is called
@@ -46,7 +46,7 @@ config BOARD_RISCVEMU
 
 config CPU_SIFIVE
 	bool
-	select HAS_CACHE
+	select RISCV_ICACHE
 
 config SOC_SIFIVE
 	bool "SiFive SoCs"
@@ -116,7 +116,7 @@ config SOC_ALLWINNER_SUN20I
 	bool "Allwinner Sun20i SoCs"
 	depends on ARCH_RV64I
 	select HAS_DEBUG_LL
-	select HAS_CACHE
+	select RISCV_ICACHE
 
 if SOC_ALLWINNER_SUN20I
 
@@ -130,6 +130,9 @@ endif
 
 comment "CPU features"
 
+config RISCV_ICACHE
+	bool
+
 config SIFIVE_L2
 	bool "SiFive L2 cache controller"
 	depends on CPU_SIFIVE
diff --git a/arch/riscv/include/asm/cache.h b/arch/riscv/include/asm/cache.h
index c787f890017e..8c3cde669c30 100644
--- a/arch/riscv/include/asm/cache.h
+++ b/arch/riscv/include/asm/cache.h
@@ -21,7 +21,7 @@ static inline void thead_local_flush_icache_all(void)
 
 static inline void local_flush_icache_all(void)
 {
-#ifdef CONFIG_HAS_CACHE
+#ifdef CONFIG_RISCV_ICACHE
 	switch(riscv_vendor_id()) {
 	case THEAD_VENDOR_ID:
 		thead_local_flush_icache_all();
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 12 23:45:52 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 07:45:52 +0100
Subject: [PATCH 1/6] arch: move promptless options to end of Kconfig file
Message-ID: <20250313064557.77398-1-a.fatoum@pengutronix.de>

Later commits will move many more promptless arch symbols into the file,
so prepare for that by moving the current ones to the end and leave the
options, which either have a prompt or are not boolean at the start.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/Kconfig | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index aee5375dc70c..21175b90a076 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -9,19 +9,6 @@
 #
 source "arch/$(SRCARCH)/Kconfig"
 
-config ARCH_HAS_CTRLC
-	bool
-
-#
-# Select this option if the architecture assumes DMA devices are coherent
-# by default.
-#
-config ARCH_DMA_DEFAULT_COHERENT
-	bool
-
-config ARCH_HAS_ASAN_FIBER_API
-	bool
-
 config ARCH_LINUX_NAME
 	string
 	default "$(SRCARCH)"
@@ -30,9 +17,6 @@ config ARCH_MKIMAGE_NAME
 	string
 	default "invalid"
 
-config HAVE_ARCH_BOARD_GENERIC_DT
-	bool
-
 menu "General architecture-dependent options"
 
 config BOARD_GENERIC_DT
@@ -64,3 +48,19 @@ config BOARD_GENERIC_FIT
 	  installed on the build host.
 
 endmenu
+
+config ARCH_HAS_CTRLC
+	bool
+
+#
+# Select this option if the architecture assumes DMA devices are coherent
+# by default.
+#
+config ARCH_DMA_DEFAULT_COHERENT
+	bool
+
+config ARCH_HAS_ASAN_FIBER_API
+	bool
+
+config HAVE_ARCH_BOARD_GENERIC_DT
+	bool
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 12 23:45:54 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 07:45:54 +0100
Subject: [PATCH 3/6] treewide: retire CONFIG_HAS_CACHE
In-Reply-To: <20250313064557.77398-1-a.fatoum@pengutronix.de>
References: <20250313064557.77398-1-a.fatoum@pengutronix.de>
Message-ID: <20250313064557.77398-3-a.fatoum@pengutronix.de>

The option serves no purpose any longer as all cache maintenance is
hidden behind generic APIs like the DMA streaming API.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/Kconfig      | 1 -
 arch/kvx/Kconfig      | 1 -
 arch/openrisc/Kconfig | 1 -
 arch/powerpc/Kconfig  | 1 -
 common/Kconfig        | 8 --------
 drivers/net/Kconfig   | 1 -
 6 files changed, 13 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 3d8f2eeca713..f5f9f3828782 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -3,7 +3,6 @@
 config ARM
 	bool
 	select HAS_KALLSYMS
-	select HAS_CACHE
 	select HAVE_IMAGE_COMPRESSION
 	select HAVE_ARCH_KASAN
 	select ARCH_HAS_SJLJ
diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
index 2e6432f897d8..5f325ca28358 100644
--- a/arch/kvx/Kconfig
+++ b/arch/kvx/Kconfig
@@ -14,7 +14,6 @@ config KVX
 	select FITIMAGE
 	select GENERIC_FIND_NEXT_BIT
 	select ARCH_HAS_SJLJ
-	select HAS_CACHE
 	select HAS_DMA
 	select LIBFDT
 	select MFD_SYSCON
diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig
index 6b64b299b391..d79743962a42 100644
--- a/arch/openrisc/Kconfig
+++ b/arch/openrisc/Kconfig
@@ -3,7 +3,6 @@
 config OPENRISC
 	bool
 	select OFTREE
-	select HAS_CACHE
 	select HAVE_CONFIGURABLE_MEMORY_LAYOUT
 	select GENERIC_FIND_NEXT_BIT
 	select ARCH_HAS_SJLJ
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 6346594173ac..4e282bc3ac80 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -5,7 +5,6 @@ config PPC
 	select HAVE_CONFIGURABLE_TEXT_BASE
 	select HAS_KALLSYMS
 	select HAS_MODULES
-	select HAS_CACHE
 	select GENERIC_FIND_NEXT_BIT
 	select OFTREE
 	select ARCH_HAS_SJLJ
diff --git a/common/Kconfig b/common/Kconfig
index 8a051a29e76c..6e5fba33ea4a 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -27,14 +27,6 @@ config HAS_KALLSYMS
 config HAS_MODULES
 	bool
 
-config HAS_CACHE
-	bool
-	help
-	  This allows you to run "make ARCH=sandbox allyesconfig".
-
-	  Drivers that depend on a cache implementation can depend on this
-	  config, so that you don't get a compilation error.
-
 config HAS_DMA
 	bool
 	help
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 5c436a05ccc5..7cad80c0a4b6 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -188,7 +188,6 @@ config DRIVER_NET_ENC28J60_WRITEVERIFY
 config DRIVER_NET_ETHOC
 	bool "OpenCores ethernet MAC driver"
 	depends on OPENRISC
-	depends on HAS_CACHE
 	select PHYLIB
 	help
 	  This option enables support for the OpenCores 10/100 Mbps
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 12 23:45:57 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 07:45:57 +0100
Subject: [PATCH 6/6] x86: make phys_addr_t 64-bit on x86_64
In-Reply-To: <20250313064557.77398-1-a.fatoum@pengutronix.de>
References: <20250313064557.77398-1-a.fatoum@pengutronix.de>
Message-ID: <20250313064557.77398-6-a.fatoum@pengutronix.de>

sizeof(phys_addr_t) depends on whether CONFIG_PHYS_ADDR_T_64BIT is
enabled, which so far was selected for all 64-bit platforms except
x86_64.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/x86/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index cea8e25b81f0..b453890f022b 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -28,6 +28,7 @@ menu "ARCH specific settings"
 config 64BIT
 	def_bool y if X86_EFI
 	select ARCH_DMA_ADDR_T_64BIT
+	select PHYS_ADDR_T_64BIT
 	help
 	  Say yes to build a 64-bit binary - formerly known as x86_64
 	  Say no to build a 32-bit binary - formerly known as i386.
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 12 23:45:55 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 07:45:55 +0100
Subject: [PATCH 4/6] arch: move hidden arch options to arch/Kconfig
In-Reply-To: <20250313064557.77398-1-a.fatoum@pengutronix.de>
References: <20250313064557.77398-1-a.fatoum@pengutronix.de>
Message-ID: <20250313064557.77398-4-a.fatoum@pengutronix.de>

We have a number of Kconfig symbols that are exclusively selected from
architecture Kconfig files, but are defined all over.

Move the definition of these symbols into arch/Kconfig, where they
are supposed to be.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/Kconfig            | 42 +++++++++++++++++++++++++++++++++++++++++
 common/Kconfig          | 21 ---------------------
 common/Kconfig.debug_ll |  3 ---
 lib/Kconfig             | 12 ------------
 lib/Kconfig.ubsan       |  2 --
 lib/kasan/Kconfig       |  3 ---
 6 files changed, 42 insertions(+), 41 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 21175b90a076..b1200184678f 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -62,5 +62,47 @@ config ARCH_DMA_DEFAULT_COHERENT
 config ARCH_HAS_ASAN_FIBER_API
 	bool
 
+config ARCH_HAS_STACK_DUMP
+	bool
+
+config ARCH_HAS_DATA_ABORT_MASK
+	bool
+
+config ARCH_HAS_ZERO_PAGE
+	bool
+
+config HAVE_EFFICIENT_UNALIGNED_ACCESS
+	bool
+
 config HAVE_ARCH_BOARD_GENERIC_DT
 	bool
+
+config HAVE_MOD_ARCH_SPECIFIC
+	bool
+	help
+	  The arch uses struct mod_arch_specific to store data.  Many arches
+	  just need a simple module loader without arch specific data - those
+	  should not enable this.
+
+config ARCH_HAS_SJLJ
+	bool
+	help
+	  Architecture has support implemented for setjmp()/longjmp()/initjmp()
+
+config ARCH_DMA_ADDR_T_64BIT
+	bool
+
+config ARCH_USE_SYM_ANNOTATIONS
+	bool
+	help
+	  This is selected by architectures that exclusively use the new SYM_
+	  macros in their assembly code and not the deprecated ENTRY/PROC.
+
+config HAS_DEBUG_LL
+	bool
+
+config HAVE_ARCH_KASAN
+	bool
+
+config ARCH_HAS_UBSAN_SANITIZE_ALL
+	bool
diff --git a/common/Kconfig b/common/Kconfig
index 6e5fba33ea4a..de66f0461cf1 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -35,11 +35,6 @@ config HAS_DMA
 	  Drivers that depend on a DMA implementation can depend on this
 	  config, so that you don't get a compilation error.
 
-config ARCH_HAS_SJLJ
-	bool
-	help
-	  Architecture has support implemented for setjmp()/longjmp()/initjmp()
-
 config GENERIC_GPIO
 	bool
 
@@ -84,9 +79,6 @@ config MENUTREE
 	select GLOB
 	select GLOB_SORT
 
-config ARCH_DMA_ADDR_T_64BIT
-	bool
-
 config BAREBOX_UPDATE_IMX_NAND_FCB
 	bool
 	depends on ARCH_IMX7 || ARCH_IMX6 || ARCH_IMX28
@@ -359,13 +351,6 @@ config MODULES
 	  As modules can't be signed, loading external modules is not
 	  recommended for secure systems.
 
-config HAVE_MOD_ARCH_SPECIFIC
-	bool
-	help
-	  The arch uses struct mod_arch_specific to store data.  Many arches
-	  just need a simple module loader without arch specific data - those
-	  should not enable this.
-
 config KALLSYMS
 	depends on HAS_KALLSYMS
 	bool "kallsyms"
@@ -1359,9 +1344,3 @@ source "common/boards/Kconfig"
 config DDR_SPD
 	bool
 	select CRC_ITU_T
-
-config ARCH_USE_SYM_ANNOTATIONS
-	bool
-	help
-	  This is selected by architectures that exclusively use the new SYM_
-	  macros in their assembly code and not the deprecated ENTRY/PROC.
diff --git a/common/Kconfig.debug_ll b/common/Kconfig.debug_ll
index 1f9255b1a45b..8c49f5b72882 100644
--- a/common/Kconfig.debug_ll
+++ b/common/Kconfig.debug_ll
@@ -1,8 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-config HAS_DEBUG_LL
-	bool
-
 config DEBUG_LL
 	bool
 	depends on HAS_DEBUG_LL
diff --git a/lib/Kconfig b/lib/Kconfig
index 40c7b2cb5d65..8e1d8086fbb6 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -213,18 +213,6 @@ config BLOBGEN
 	select BASE64
 	bool "include blob encode/decode support"
 
-config ARCH_HAS_STACK_DUMP
-	bool
-
-config ARCH_HAS_DATA_ABORT_MASK
-	bool
-
-config ARCH_HAS_ZERO_PAGE
-	bool
-
-config HAVE_EFFICIENT_UNALIGNED_ACCESS
-	bool
-
 config GENERIC_ALLOCATOR
 	bool
 	help
diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan
index c04ff3cbb6fd..063563536be1 100644
--- a/lib/Kconfig.ubsan
+++ b/lib/Kconfig.ubsan
@@ -1,6 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
-config ARCH_HAS_UBSAN_SANITIZE_ALL
-	bool
 
 config UBSAN
 	bool "Undefined behaviour sanity checker"
diff --git a/lib/kasan/Kconfig b/lib/kasan/Kconfig
index 895a62d88439..532412953ba5 100644
--- a/lib/kasan/Kconfig
+++ b/lib/kasan/Kconfig
@@ -1,8 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-config HAVE_ARCH_KASAN
-	bool
-
 config CC_HAS_KASAN_GENERIC
 	def_bool $(cc-option, -fsanitize=kernel-address)
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 12 23:45:56 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 07:45:56 +0100
Subject: [PATCH 5/6] arch: move PHYS_ADDR_T_64BIT definition to arch/Kconfig
In-Reply-To: <20250313064557.77398-1-a.fatoum@pengutronix.de>
References: <20250313064557.77398-1-a.fatoum@pengutronix.de>
Message-ID: <20250313064557.77398-5-a.fatoum@pengutronix.de>

Currently, every architecture with 64-bit support defines its own
PHYS_ADDR_T_64BIT symbol, except for x86.

Sync with what's done for ARCH_DMA_ADDR_T_64BIT and move
PHYS_ADDR_T_64BIT into arch/Kconfig as well.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/Kconfig         | 4 ++++
 arch/arm/cpu/Kconfig | 3 ---
 arch/kvx/Kconfig     | 3 ---
 arch/mips/Kconfig    | 3 ---
 arch/riscv/Kconfig   | 3 ---
 arch/sandbox/Kconfig | 3 ---
 6 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index b1200184678f..dc5d1e454df5 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -89,6 +89,10 @@ config ARCH_HAS_SJLJ
 	help
 	  Architecture has support implemented for setjmp()/longjmp()/initjmp()
 
+
+config PHYS_ADDR_T_64BIT
+	bool
+
 config ARCH_DMA_ADDR_T_64BIT
 	bool
 
diff --git a/arch/arm/cpu/Kconfig b/arch/arm/cpu/Kconfig
index 84fe770b6da8..e61bcadc8c35 100644
--- a/arch/arm/cpu/Kconfig
+++ b/arch/arm/cpu/Kconfig
@@ -2,9 +2,6 @@
 
 comment "Processor Type"
 
-config PHYS_ADDR_T_64BIT
-	bool
-
 config CPU_32
 	bool
 	select HAS_MODULES
diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
index 5f325ca28358..9b733cd79201 100644
--- a/arch/kvx/Kconfig
+++ b/arch/kvx/Kconfig
@@ -23,9 +23,6 @@ config KVX
 	select RESET_SOURCE
 	default y
 
-config PHYS_ADDR_T_64BIT
-	bool
-
 config 64BIT
 	bool
 	select ARCH_DMA_ADDR_T_64BIT
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 769949a91085..43c493978c8f 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -36,9 +36,6 @@ config GENERIC_LINKER_SCRIPT
 	bool
 	default y
 
-config PHYS_ADDR_T_64BIT
-	bool
-
 config ARCH_TEXT_BASE
 	hex
 	default 0xa0800000
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index be2146b3facb..4d56e55b533f 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -59,9 +59,6 @@ config CPU_SUPPORTS_32BIT_KERNEL
 config CPU_SUPPORTS_64BIT_KERNEL
 	bool
 
-config PHYS_ADDR_T_64BIT
-	bool
-
 config 32BIT
 	bool
 	depends on CPU_SUPPORTS_32BIT_KERNEL
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index c1a51d4f021d..7c86511a2c61 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -32,9 +32,6 @@ config ARCH_TEXT_BASE
 
 menu "Sandbox specific settings"
 
-config PHYS_ADDR_T_64BIT
-	bool
-
 config CC_IS_64BIT
 	def_bool $(success,$(srctree)/scripts/gcc-64bitptr.sh $(CC))
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:23:09 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:23:09 +0100
Subject: [PATCH master] FIT: early exit if digest fails
Message-ID: <20250313072309.141338-1-a.fatoum@pengutronix.de>

fit_digest will hash the list of images in the configuration, so
fit_check_signature() can compare it against the signed hash.

So far, parse errors while computing the hash were ignored. This is not
directly exploitable as the hash would be incomplete and fail the
signature verification, but it makes the code more difficult to reason
about.

This unused assignment to ret was detected by clang-analyzer-19.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/image-fit.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/common/image-fit.c b/common/image-fit.c
index 959384abd275..6eda041935be 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -338,6 +338,9 @@ static int fit_verify_signature(struct device_node *sig_node, const void *fit)
 
 	ret = fit_digest(fit, digest, &inc_nodes, &exc_props, hashed_strings_start,
 			 hashed_strings_size);
+	if (ret)
+		goto out_sl;
+
 	hash = xzalloc(digest_length(digest));
 	digest_final(digest, hash);
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:23 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:23 +0100
Subject: [PATCH 00/22] add support for clang-analyzer with scan-build
Message-ID: <20250313073445.764875-1-a.fatoum@pengutronix.de>

With the changes, it's now possible to build barebox for sandbox
with allyesconfig with clang under scan-build with:

  export LLVM=-19 # or whatever your clang suffix is if you've one
  scan-build${LLVM} --use-cc=clang${LLVM} make

For this build to run to completion, a number of things that clang
treats as errors need to be resolved as well, which is included
in this series.

Ahmad Fatoum (22):
  kbuild: add support for clang-analyzer with scan-build
  soc: ti: k3-navss-ringacc: fix COMPILE_TEST link error
  treewide: fix missing headers in sandbox allyesconfig
  drivers: don't cast pointer directly to enum
  firmware: arm_scmi: smc: compile only for ARM
  video: stm32-ltdc: fix printing uninitialized variable
  usb: core: remove unnecessary comparison
  ddr_spd: fix always true sub-condition
  hush: fix make_string behavior on empty strings
  nvmem: fix clang-analyzer false-positive use of uninitialized value
  string: initialize string array in string selftest
  commands: ubsan: hide zero division in test
  crypto: ecc: fix clang-analyzer warning about NULL dereference
  mci_spi: fix possible use of uninitialized variable
  mtd: have mtd_read populate retlen always
  of: fdt: silence possible static analyzer false positive
  ubi: workaround zero division on malformed input in ubi_assert
  video: Rockchip: fix zero division in rk3588_calc_cru_cfg
  lib: scatterlist: don't assert last element for empty sglist
  scripts: omap3-usb-loader: fix clang-analyzer false-positive
  clk: analogbits: wrpll-cln28hpc: bail out before zero division
  watchdog: stm32_iwdg: bail out before zero division

 Makefile                                   |  9 +++++++++
 commands/ubsan.c                           |  2 ++
 common/ddr_spd.c                           |  6 ++----
 common/hush.c                              |  4 ++++
 crypto/ecc.c                               |  2 ++
 drivers/aiodev/lm75.c                      |  2 +-
 drivers/clk/analogbits/wrpll-cln28hpc.c    |  3 +++
 drivers/dma/ti/Kconfig                     |  6 ++++++
 drivers/dma/ti/k3-udma.c                   |  2 +-
 drivers/firmware/arm_scmi/Kconfig          |  1 +
 drivers/mci/mci_spi.c                      |  2 +-
 drivers/mfd/tps65219.c                     |  1 +
 drivers/mtd/core.c                         |  9 ++++-----
 drivers/mtd/ubi/build.c                    |  3 ++-
 drivers/net/ksz8864rmn.c                   |  2 +-
 drivers/nvmem/core.c                       |  2 +-
 drivers/of/fdt.c                           |  3 +++
 drivers/pmdomain/ti/ti-k3.c                |  1 +
 drivers/regulator/fan53555.c               |  2 +-
 drivers/regulator/tps65219-regulator.c     |  1 +
 drivers/soc/Makefile                       |  2 +-
 drivers/soc/ti/Kconfig                     | 11 +++++++++++
 drivers/soc/ti/Makefile                    |  4 +++-
 drivers/soc/ti/k3-navss-ringacc.c          |  1 +
 drivers/usb/core/common.c                  |  2 +-
 drivers/video/rockchip/rockchip_drm_vop2.c |  6 +++---
 drivers/video/stm32_ltdc.c                 |  6 ++----
 drivers/watchdog/stm32_iwdg.c              |  3 +++
 lib/scatterlist.c                          |  2 +-
 scripts/omap3-usb-loader.c                 |  9 ++++++---
 test/self/string.c                         |  2 +-
 31 files changed, 80 insertions(+), 31 deletions(-)

-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:26 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:26 +0100
Subject: [PATCH 03/22] treewide: fix missing headers in sandbox allyesconfig
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-4-a.fatoum@pengutronix.de>

Building these drivers fails because of missing includes that are
transitively included on ARM, but no on sandbox.

Add the relevant includes directly to address this.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/dma/ti/k3-udma.c               | 2 +-
 drivers/mfd/tps65219.c                 | 1 +
 drivers/pmdomain/ti/ti-k3.c            | 1 +
 drivers/regulator/tps65219-regulator.c | 1 +
 drivers/soc/ti/k3-navss-ringacc.c      | 1 +
 5 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
index 761898867d4e..e17b99de47c4 100644
--- a/drivers/dma/ti/k3-udma.c
+++ b/drivers/dma/ti/k3-udma.c
@@ -5,9 +5,9 @@
  */
 #define pr_fmt(fmt) "udma: " fmt
 
-#include <asm/cache.h>
 #include <io.h>
 #include <malloc.h>
+#include <stdio.h>
 #include <linux/bitops.h>
 #include <linux/sizes.h>
 #include <linux/printk.h>
diff --git a/drivers/mfd/tps65219.c b/drivers/mfd/tps65219.c
index 854210537fa3..132dab7cdeec 100644
--- a/drivers/mfd/tps65219.c
+++ b/drivers/mfd/tps65219.c
@@ -12,6 +12,7 @@
 #include <linux/regmap.h>
 #include <linux/mfd/tps65219.h>
 #include <linux/device.h>
+#include <linux/kernel.h>
 
 static const struct mfd_cell tps65219_cells[] = {
 	{ .name = "tps65219-regulator", },
diff --git a/drivers/pmdomain/ti/ti-k3.c b/drivers/pmdomain/ti/ti-k3.c
index 33bffeaca001..1616e90b6230 100644
--- a/drivers/pmdomain/ti/ti-k3.c
+++ b/drivers/pmdomain/ti/ti-k3.c
@@ -9,6 +9,7 @@
 #define pr_fmt(fmt)     "ti-k3-pm-domain: " fmt
 
 #include <io.h>
+#include <stdio.h>
 #include <of_device.h>
 #include <malloc.h>
 #include <init.h>
diff --git a/drivers/regulator/tps65219-regulator.c b/drivers/regulator/tps65219-regulator.c
index da329660d688..9ec54ed77908 100644
--- a/drivers/regulator/tps65219-regulator.c
+++ b/drivers/regulator/tps65219-regulator.c
@@ -10,6 +10,7 @@
 // "J Keerthy <j-keerthy at ti.com>"
 //
 
+#include <linux/kernel.h>
 #include <linux/mfd/tps65219.h>
 #include <of_device.h>
 #include <linux/regmap.h>
diff --git a/drivers/soc/ti/k3-navss-ringacc.c b/drivers/soc/ti/k3-navss-ringacc.c
index 933e03018398..f19a37dde064 100644
--- a/drivers/soc/ti/k3-navss-ringacc.c
+++ b/drivers/soc/ti/k3-navss-ringacc.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com
  */
 
+#include <linux/kernel.h>
 #include <driver.h>
 #include <xfuncs.h>
 #include <soc/ti/k3-navss-ringacc.h>
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:29 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:29 +0100
Subject: [PATCH 06/22] video: stm32-ltdc: fix printing uninitialized variable
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-7-a.fatoum@pengutronix.de>

ret is not initialized on failure to get the clock.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/video/stm32_ltdc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/video/stm32_ltdc.c b/drivers/video/stm32_ltdc.c
index 6b91ee18b962..7ebd24d6d908 100644
--- a/drivers/video/stm32_ltdc.c
+++ b/drivers/video/stm32_ltdc.c
@@ -269,10 +269,8 @@ static int ltdc_probe(struct device *dev)
 	hw->regs = IOMEM(iores->start);
 
 	hw->pclk = clk_get(dev, NULL);
-	if (IS_ERR(hw->pclk)) {
-		dev_err(dev, "peripheral clock get error %d\n", ret);
-		return PTR_ERR(hw->pclk);
-	}
+	if (IS_ERR(hw->pclk))
+		return dev_errp_probe(dev, hw->pclk, "peripheral clock get\n");
 
 	for_each_available_child_of_node(dev->of_node, np) {
 		struct ltdc_fb *priv;
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:27 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:27 +0100
Subject: [PATCH 04/22] drivers: don't cast pointer directly to enum
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-5-a.fatoum@pengutronix.de>

64-bit Sandbox builds with clang don't like the direct cast of
a 64-bit pointer to a 32-bit enum value. Add an uintptr_t in between
to loosen up the atmosphere.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/aiodev/lm75.c        | 2 +-
 drivers/net/ksz8864rmn.c     | 2 +-
 drivers/regulator/fan53555.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/aiodev/lm75.c b/drivers/aiodev/lm75.c
index 13b7ac4710c2..86eac091d8d3 100644
--- a/drivers/aiodev/lm75.c
+++ b/drivers/aiodev/lm75.c
@@ -110,7 +110,7 @@ static int lm75_probe(struct device *dev)
 	int new, ret;
 	enum lm75_type kind;
 
-	kind = (enum lm75_type)device_get_match_data(dev);
+	kind = (enum lm75_type)(uintptr_t)device_get_match_data(dev);
 	if (kind == unknown)
 		return -ENODEV;
 
diff --git a/drivers/net/ksz8864rmn.c b/drivers/net/ksz8864rmn.c
index c4c30377af83..8cec0bb02678 100644
--- a/drivers/net/ksz8864rmn.c
+++ b/drivers/net/ksz8864rmn.c
@@ -126,7 +126,7 @@ static int micrel_switch_probe(struct device *dev)
 {
 	struct micrel_switch_priv *priv;
 	int ret = 0;
-	enum ksz_type kind = (enum ksz_type)device_get_match_data(dev);
+	enum ksz_type kind = (enum ksz_type)(uintptr_t)device_get_match_data(dev);
 	uint8_t id;
 
 	if (kind == unknown)
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index f73511b36b20..2df0d2410a03 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -384,7 +384,7 @@ static int fan53555_regulator_probe(struct device *dev)
 
 	di = xzalloc(sizeof(*di));
 
-	di->vendor = (enum fan53555_vendor)device_get_match_data(dev);
+	di->vendor = (enum fan53555_vendor)(uintptr_t)device_get_match_data(dev);
 
 	di->rdev.desc = &di->rdesc;
 	di->rdev.dev = dev;
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:25 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:25 +0100
Subject: [PATCH 02/22] soc: ti: k3-navss-ringacc: fix COMPILE_TEST link error
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-3-a.fatoum@pengutronix.de>

The TI UDMA driver has a fixed dependency on the K3 RINGACC driver,
which is not necessarily satisfied during COMPILE_TEST as the latter
depends on ARCH_K3 being enabled, which is an ARM-only symbol
unavailable when compile testing on other architectures.

Fix this by selecting the code as needed.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/dma/ti/Kconfig  |  6 ++++++
 drivers/soc/Makefile    |  2 +-
 drivers/soc/ti/Kconfig  | 11 +++++++++++
 drivers/soc/ti/Makefile |  4 +++-
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/ti/Kconfig b/drivers/dma/ti/Kconfig
index 78755bb33a45..df705a23bff7 100644
--- a/drivers/dma/ti/Kconfig
+++ b/drivers/dma/ti/Kconfig
@@ -1,6 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Texas Instruments DMA drivers
+#
+
 config TI_K3_UDMA
         tristate "Texas Instruments UDMA support"
         depends on ARCH_K3 || COMPILE_TEST
+        select TI_K3_RINGACC
         help
           Enable support for the TI UDMA (Unified DMA) controller. This
           DMA engine is used in AM65x and j721e.
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 5b6ebe53c39d..975304cd50b4 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -5,4 +5,4 @@ obj-$(CONFIG_KVX)		+= kvx/
 obj-$(CONFIG_ARCH_ROCKCHIP)	+= rockchip/
 obj-$(CONFIG_CPU_SIFIVE)	+= sifive/
 obj-$(CONFIG_SOC_STARFIVE)	+= starfive/
-obj-$(CONFIG_ARCH_K3)		+= ti/
+obj-y				+= ti/
diff --git a/drivers/soc/ti/Kconfig b/drivers/soc/ti/Kconfig
index 8d2dd86f3fe6..d0aadbce10c3 100644
--- a/drivers/soc/ti/Kconfig
+++ b/drivers/soc/ti/Kconfig
@@ -2,3 +2,14 @@ config K3_ESM
 	bool
 	depends on ARCH_K3 && MACH_K3_CORTEX_R5
 	default y
+
+config TI_K3_RINGACC
+	tristate "K3 Ring accelerator Sub System"
+	depends on ARCH_K3 || COMPILE_TEST
+	help
+	  Say y here to support the K3 Ring accelerator module.
+	  The Ring Accelerator (RINGACC or RA)  provides hardware acceleration
+	  to enable straightforward passing of work between a producer
+	  and a consumer. There is one RINGACC module per NAVSS on TI AM65x SoCs
+	  If unsure, say N.
+
diff --git a/drivers/soc/ti/Makefile b/drivers/soc/ti/Makefile
index 3109a4e9675c..6d6ff4dd2aaf 100644
--- a/drivers/soc/ti/Makefile
+++ b/drivers/soc/ti/Makefile
@@ -1,2 +1,4 @@
-obj-y += k3-navss-ringacc.o
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_TI_K3_RINGACC) += k3-navss-ringacc.o
 obj-$(CONFIG_K3_ESM) += k3-esm.o
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:30 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:30 +0100
Subject: [PATCH 07/22] usb: core: remove unnecessary comparison
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-8-a.fatoum@pengutronix.de>

The GCC default is to treat enums without negative values in the
enumerations as an unsigned int. clang seems to follow suit and
clang-analyzer warns that speed < 0 can never happen.

Therefore, drop this superfluous check.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/usb/core/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/core/common.c b/drivers/usb/core/common.c
index 61ccc130244b..f255f97cdd4d 100644
--- a/drivers/usb/core/common.c
+++ b/drivers/usb/core/common.c
@@ -13,7 +13,7 @@ static const char *const speed_names[] = {
 
 const char *usb_speed_string(enum usb_device_speed speed)
 {
-	if (speed < 0 || speed >= ARRAY_SIZE(speed_names))
+	if (speed >= ARRAY_SIZE(speed_names))
 		speed = USB_SPEED_UNKNOWN;
 	return speed_names[speed];
 }
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:32 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:32 +0100
Subject: [PATCH 09/22] hush: fix make_string behavior on empty strings
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-10-a.fatoum@pengutronix.de>

clang-analyzer believes that an empty string could be passed here,
leading to a NULL dereference.

Avoid this situation by allocating a len (2 byte) string instead
to hold "\n" as value in that case.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/hush.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/common/hush.c b/common/hush.c
index 608c0e4937c1..3a213fc54591 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -1885,6 +1885,10 @@ static char * make_string(char ** inp)
 		if (p != inp[n])
 			free(p);
 	}
+
+	if (!str)
+		str = xzalloc(len);
+
 	len = strlen(str);
 	*(str + len) = '\n';
 	*(str + len + 1) = '\0';
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:31 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:31 +0100
Subject: [PATCH 08/22] ddr_spd: fix always true sub-condition
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-9-a.fatoum@pengutronix.de>

The last subcondition is always true, because it compares the left-hand
side against two different values and ORs the result.

I think the intention of the code is to avoid printing bogus serial
numbers that are either all zeroes or all ones, so let's check for that.

This is a debug print, so there is no fallout expected if the guess
turns out wrong..

Cc: Denis Orlov <denorl2009 at gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/ddr_spd.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/common/ddr_spd.c b/common/ddr_spd.c
index b7693f3fd25c..7ca8e9887a55 100644
--- a/common/ddr_spd.c
+++ b/common/ddr_spd.c
@@ -927,10 +927,8 @@ static void ddr3_spd_print(uint8_t *record)
 	    && !((s->mdate[0] == 0x0) && (s->mdate[1] == 0x0)))
 		spd_print_manufacturing_date(s->mdate[0], s->mdate[1]);
 
-	if ((s->sernum[0] != s->sernum[1])
-	    && (s->sernum[0] != s->sernum[2])
-	    && (s->sernum[1] != s->sernum[3])
-	    && ((s->sernum[0] != 0xff) || (s->sernum[0] != 0x0)))
+	if (memcmp(s->sernum, "\xFF\xFF\xFF\xFF", 4) &&
+	    memcmp(s->sernum, "\x00\x00\x00\x00", 4))
 		printf("%-48s 0x%02X%02X%02X%02X\n", "Assembly Serial Number",
 		       s->sernum[0], s->sernum[1], s->sernum[2], s->sernum[3]);
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:24 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:24 +0100
Subject: [PATCH 01/22] kbuild: add support for clang-analyzer with scan-build
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-2-a.fatoum@pengutronix.de>

scan-build will set a number of environment variables, including CC and
CCC_ANALYZER_HTML and the build command passed as its argument.

When that build system uses CC as a compiler, scan-build will capture
the arguments used and run clang-analyzer on all these files in addition
to the normal compiler.

This doesn't current work with barebox as barebox' Kbuild ignores the CC
variable in the environment. Fix this by collecting into ENVCC the CC
environment variable and using it to override CC whenever it is set in
addition to CCC_ANALYZER_HTML.

Example usage:

  export LLVM=-19
  scan-build${LLVM} --use-cc=clang${LLVM} make

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Makefile b/Makefile
index f3e5b44d5566..9ef07ba34457 100644
--- a/Makefile
+++ b/Makefile
@@ -410,6 +410,8 @@ KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
 KBUILD_HOSTLDFLAGS  := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
 KBUILD_HOSTLDLIBS   := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
 
+ENVCC		:= $(CC)
+
 # Make variables (CC, etc...)
 CPP		= $(CC) -E
 ifneq ($(LLVM),)
@@ -574,6 +576,13 @@ ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
 include $(srctree)/scripts/Makefile.clang
 endif
 
+# allow scan-build to override the used compiler
+ifneq ($(CCC_ANALYZER_HTML),)
+ifneq ($(ENVCC),)
+CC = $(ENVCC)
+endif
+endif
+
 ifdef config-build
 # ===========================================================================
 # *config targets only - make sure prerequisites are updated, and descend
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:28 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:28 +0100
Subject: [PATCH 05/22] firmware: arm_scmi: smc: compile only for ARM
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-6-a.fatoum@pengutronix.de>

The SMC transport driver references ARM register names in C code via the
register asm syntax and thus fails to build on other architectures.

Mark it ARM-only to reflect this. The remainder of the ARM SCMI support
can built with COMPILE_TEST normally.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/firmware/arm_scmi/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
index 29b0152901ad..3405c6b3e9e3 100644
--- a/drivers/firmware/arm_scmi/Kconfig
+++ b/drivers/firmware/arm_scmi/Kconfig
@@ -58,6 +58,7 @@ config ARM_SCMI_TRANSPORT_OPTEE
 
 config ARM_SCMI_TRANSPORT_SMC
 	bool "SCMI transport based on SMC"
+	depends on ARM
 	select ARM_SMCCC
 	select ARM_SCMI_HAVE_TRANSPORT
 	select ARM_SCMI_HAVE_SHMEM
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:35 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:35 +0100
Subject: [PATCH 12/22] commands: ubsan: hide zero division in test
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-13-a.fatoum@pengutronix.de>

clang-analyzer pierces the volatile veil and complains that
test_ubsan_divrem_overflow() does a division by zero.

The division is intentional to exercise UBSAN runtime detection of the
condition, so let's hide the fact that val2 is zero using
OPTIMIZER_HIDE_VAR.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 commands/ubsan.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/commands/ubsan.c b/commands/ubsan.c
index 4a9716139c4b..634ab2bc60b2 100644
--- a/commands/ubsan.c
+++ b/commands/ubsan.c
@@ -43,6 +43,8 @@ static void test_ubsan_divrem_overflow(void)
 	volatile int val = 16;
 	volatile int val2 = 0;
 
+	OPTIMIZER_HIDE_VAR(&val2);
+
 	val /= val2;
 }
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:43 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:43 +0100
Subject: [PATCH 20/22] scripts: omap3-usb-loader: fix clang-analyzer false-positive
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-21-a.fatoum@pengutronix.de>

clang-analyzer has a heuristic to determine mismatched allocations.
It flags allocating bufsize of chars and assigned it to a pointer
to uint32, although it's ultimately correct.

Let's silence the warning by using the pointee type instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 scripts/omap3-usb-loader.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/scripts/omap3-usb-loader.c b/scripts/omap3-usb-loader.c
index 38cdbfac939e..192e42689bb2 100644
--- a/scripts/omap3-usb-loader.c
+++ b/scripts/omap3-usb-loader.c
@@ -424,15 +424,18 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state
 
 static int transfer_other_files(libusb_device_handle *handle, struct arg_state *args)
 {
-	uint32_t *buffer = NULL;
-	int bufsize = 128 * sizeof (*buffer);
+	uint32_t *buffer;
+	int bufsize;
 	int numfailures = 0;	/* build in some reliablity */
 	int maxfailures = 3;
 	int transLen = 0;
 	int curfile = 1;	/* skip the first file */
 	size_t len;
 
-	buffer = calloc(bufsize, sizeof(unsigned char));
+	buffer = calloc(128, sizeof(*buffer));
+	if (!buffer)
+		goto fail;
+	bufsize = 128 * sizeof (*buffer);
 
 	/* handle the state machine for the X-Loader */
 	while (curfile < args->numfiles) {
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:44 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:44 +0100
Subject: [PATCH 21/22] clk: analogbits: wrpll-cln28hpc: bail out before zero division
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-22-a.fatoum@pengutronix.de>

clang-analyzer reports that a zero division may be possible while
computing post_divr_freq. Bail out early instead by returning
-ERANGE.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/clk/analogbits/wrpll-cln28hpc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/clk/analogbits/wrpll-cln28hpc.c b/drivers/clk/analogbits/wrpll-cln28hpc.c
index 1aafaf2e6502..a9231fbf8188 100644
--- a/drivers/clk/analogbits/wrpll-cln28hpc.c
+++ b/drivers/clk/analogbits/wrpll-cln28hpc.c
@@ -301,6 +301,9 @@ int wrpll_configure_for_rate(struct wrpll_cfg *c, u32 target_rate,
 	c->divr = best_r - 1;
 	c->divf = best_f - 1;
 
+	if (!best_r)
+		return -ERANGE;
+
 	post_divr_freq = div_u64(parent_rate, best_r);
 
 	/* Pick the best PLL jitter filter */
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:40 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:40 +0100
Subject: [PATCH 17/22] ubi: workaround zero division on malformed input in ubi_assert
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-18-a.fatoum@pengutronix.de>

A zero hdrs_min_io_size is a bug and will trigger a ubi_assert.
These are critical events, but don't panic the system.

The last ubi_assert will trigger a division by zero. Add a zero check
into it, so it doesn't overlap with the first assert.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/mtd/ubi/build.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 94b4231aadc4..8bb1f0cbb901 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -320,7 +320,8 @@ static int io_init(struct ubi_device *ubi, int max_beb_per1024)
 
 	ubi_assert(ubi->hdrs_min_io_size > 0);
 	ubi_assert(ubi->hdrs_min_io_size <= ubi->min_io_size);
-	ubi_assert(ubi->min_io_size % ubi->hdrs_min_io_size == 0);
+	ubi_assert(ubi->hdrs_min_io_size &&
+		   ubi->min_io_size % ubi->hdrs_min_io_size == 0);
 
 	ubi->max_write_size = ubi->mtd->writebufsize;
 	/*
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:41 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:41 +0100
Subject: [PATCH 18/22] video: Rockchip: fix zero division in rk3588_calc_cru_cfg
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-19-a.fatoum@pengutronix.de>

This was detected by clang-analyzer and I don't understand how that
function could have ever worked, because it's running into the zero
division in the "successful" code path.

Peeking at rk3568_set_intf_mux, the CRTC clock is passed by the caller
in barebox, so let's do the same for rk3588_calc_cru_cfg.

Fixes: c8c0833beb77 ("video: Rockchip: Add VOP2 driver")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/video/rockchip/rockchip_drm_vop2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/video/rockchip/rockchip_drm_vop2.c b/drivers/video/rockchip/rockchip_drm_vop2.c
index 3a1c951ec7e4..f15ef1b57bf5 100644
--- a/drivers/video/rockchip/rockchip_drm_vop2.c
+++ b/drivers/video/rockchip/rockchip_drm_vop2.c
@@ -743,10 +743,10 @@ static unsigned long rk3588_calc_dclk(unsigned long child_clk, unsigned long max
  */
 static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int id,
 					 int *dclk_core_div, int *dclk_out_div,
-					 int *if_pixclk_div, int *if_dclk_div)
+					 int *if_pixclk_div, int *if_dclk_div,
+					 u32 crtc_clock)
 {
 	struct vop2 *vop2 = vp->vop2;
-	u32 crtc_clock = 0;
 	unsigned long v_pixclk = crtc_clock * 1000LL; /* video timing pixclk */
 	unsigned long dclk_core_rate = v_pixclk >> 2;
 	unsigned long dclk_rate = v_pixclk;
@@ -856,7 +856,7 @@ static unsigned long rk3588_set_intf_mux(struct vop2_video_port *vp, int id, u32
 	u32 die, dip, div, vp_clk_div, val;
 
 	clock = rk3588_calc_cru_cfg(vp, id, &dclk_core_div, &dclk_out_div,
-				    &if_pixclk_div, &if_dclk_div);
+				    &if_pixclk_div, &if_dclk_div, clock);
 	if (!clock)
 		return 0;
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:34 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:34 +0100
Subject: [PATCH 11/22] string: initialize string array in string selftest
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-12-a.fatoum@pengutronix.de>

The array members in tokens are passed to strverscmp, which doesn't do a
NULL-check, which is prone to happen with malformed test input.

Static analysis warns about this, so initialize it to empty strings.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/self/string.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/self/string.c b/test/self/string.c
index d33e2d7918ca..542277a09797 100644
--- a/test/self/string.c
+++ b/test/self/string.c
@@ -37,7 +37,7 @@ static int strverscmp_assert_one(const char *lhs, const char *rhs, int expect)
 
 static int __strverscmp_assert(char *expr)
 {
-	const char *token, *tokens[3];
+	const char *token, *tokens[3] = { "", "", "" };
 	int expect = -42;
 	int i = 0;
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:36 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:36 +0100
Subject: [PATCH 13/22] crypto: ecc: fix clang-analyzer warning about NULL dereference
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-14-a.fatoum@pengutronix.de>

clang-analyzer believes that point->x can dereference a NULL pointer.
I suspect that's not possible, because of the arguments the function is
called with, but let's play it safe and assert that point is non-NULL
before dereferencing.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 crypto/ecc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/crypto/ecc.c b/crypto/ecc.c
index a0ab962262ca..d91948bddbde 100644
--- a/crypto/ecc.c
+++ b/crypto/ecc.c
@@ -1434,6 +1434,8 @@ void ecc_point_mult_shamir(const struct ecc_point *result,
 	idx |= (!!vli_test_bit(u2, i)) << 1;
 	point = points[idx];
 
+	BUG_ON(!point);
+
 	vli_set(rx, point->x, ndigits);
 	vli_set(ry, point->y, ndigits);
 	vli_clear(z + 1, ndigits - 1);
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:37 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:37 +0100
Subject: [PATCH 14/22] mci_spi: fix possible use of uninitialized variable
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-15-a.fatoum@pengutronix.de>

When called with a zero bcnt, r1 is used uninitialized.
Initialize it to an error in that case.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/mci/mci_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mci/mci_spi.c b/drivers/mci/mci_spi.c
index 41d8c25e2736..657ce9e42ee0 100644
--- a/drivers/mci/mci_spi.c
+++ b/drivers/mci/mci_spi.c
@@ -137,7 +137,7 @@ static uint mmc_spi_readdata(struct mmc_spi_host *host, void *xbuf,
 				uint32_t bcnt, uint32_t bsize)
 {
 	uint8_t *buf = xbuf;
-	uint8_t r1;
+	uint8_t r1 = R1_SPI_ERROR;
 	uint16_t crc;
 	int i;
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:42 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:42 +0100
Subject: [PATCH 19/22] lib: scatterlist: don't assert last element for empty sglist
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-20-a.fatoum@pengutronix.de>

A BUG_ON in sg_last tries to verify that the last element in a scatter
gather list is indeed marked as such in its flags.

clang-analyzer warns that this would make the function fail for an empty
list, so let's add a NULL-check into the BUG_ON.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 lib/scatterlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index f7b06013a552..6a4e1e91f8f1 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -105,7 +105,7 @@ struct scatterlist *sg_last(struct scatterlist *sgl, unsigned int nents)
 	for_each_sg(sgl, sg, nents, i)
 		ret = sg;
 
-	BUG_ON(!sg_is_last(ret));
+	BUG_ON(ret && !sg_is_last(ret));
 	return ret;
 }
 EXPORT_SYMBOL(sg_last);
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:39 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:39 +0100
Subject: [PATCH 16/22] of: fdt: silence possible static analyzer false positive
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-17-a.fatoum@pengutronix.de>

clang-analyzer warns that aligning up newsize may end up causing an
overflow. Let's stop well before that by bailing out if the unaligned
size itself wouldn't fit into a malloc allocation anyway.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/of/fdt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 6c554af61f6f..43bb73b7a2df 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -378,6 +378,9 @@ static void *memalign_realloc(void *orig, size_t oldsize, size_t newsize)
 	int align;
 	void *newbuf;
 
+	if (newsize > MALLOC_MAX_SIZE)
+		return NULL;
+
 	/*
 	 * ARM Linux uses a single 1MiB section (with 1MiB alignment)
 	 * for mapping the devicetree, so we are not allowed to cross
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:38 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:38 +0100
Subject: [PATCH 15/22] mtd: have mtd_read populate retlen always
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-16-a.fatoum@pengutronix.de>

We currently populate retlen only on successful reads of more than zero
bytes, while Linux function with the same name populates it
unconditionally.

Mimic the Linux API for compatibility.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/mtd/core.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 562443275fe6..c75c52dcb3a5 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -375,16 +375,15 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
 		.len = len,
 		.datbuf = buf,
 	};
-	int ret;
+	int ret = 0;
 
 	if (from < 0 || from >= mtd->size || len > mtd->size - from)
 		return -EINVAL;
-	if (!len)
-		return 0;
 
-	ret = mtd_read_oob(mtd, from, &ops);
+	if (len)
+		ret = mtd_read_oob(mtd, from, &ops);
+
 	*retlen = ops.retlen;
-
 	return ret;
 }
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:45 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:45 +0100
Subject: [PATCH 22/22] watchdog: stm32_iwdg: bail out before zero division
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-23-a.fatoum@pengutronix.de>

clang-analyzer reports that a zero division may be possible while
computing presc. This can only happen if the watchdog is driven by a
non-zero clock rate under 4096Hz. This won't happen in practice, but
clang-analyzer doesn't know that, so just add a check to silence it.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/watchdog/stm32_iwdg.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c
index 6ac9e7d56e9e..c47a8cac15ec 100644
--- a/drivers/watchdog/stm32_iwdg.c
+++ b/drivers/watchdog/stm32_iwdg.c
@@ -62,6 +62,9 @@ static int stm32_iwdg_start(struct stm32_iwdg *wd, unsigned int timeout)
 
 	/* The prescaler is align on power of 2 and start at 2 ^ PR_SHIFT. */
 	presc = roundup_pow_of_two(presc);
+	if (!presc)
+		return -ERANGE;
+
 	iwdg_pr = presc <= 1 << PR_SHIFT ? 0 : ilog2(presc) - PR_SHIFT;
 	iwdg_rlr = ((timeout * wd->rate) / presc) - 1;
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:34:33 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:34:33 +0100
Subject: [PATCH 10/22] nvmem: fix clang-analyzer false-positive use of uninitialized value
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <20250313073445.764875-11-a.fatoum@pengutronix.de>

clang-analyzer believes len can be returned uninitialized, but reading
the code this seems impossible. Anyways, let's initialize it by zero to
be able to focus on the more reports.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 4e69b3fa582b..38dfb2cf2d1f 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -692,7 +692,7 @@ ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
 {
 	struct nvmem_cell cell;
 	int rc;
-	ssize_t len;
+	ssize_t len = 0;
 
 	if (!nvmem)
 		return -EINVAL;
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:54:11 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:54:11 +0100
Subject: [PATCH v2 1/6] arch: move promptless options to end of Kconfig file
Message-ID: <20250313075416.3202194-1-a.fatoum@pengutronix.de>

Later commits will move many more promptless arch symbols into the file,
so prepare for that by moving the current ones to the end and leave the
options, which either have a prompt or are not boolean at the start.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - no change
---
 arch/Kconfig | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index aee5375dc70c..21175b90a076 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -9,19 +9,6 @@
 #
 source "arch/$(SRCARCH)/Kconfig"
 
-config ARCH_HAS_CTRLC
-	bool
-
-#
-# Select this option if the architecture assumes DMA devices are coherent
-# by default.
-#
-config ARCH_DMA_DEFAULT_COHERENT
-	bool
-
-config ARCH_HAS_ASAN_FIBER_API
-	bool
-
 config ARCH_LINUX_NAME
 	string
 	default "$(SRCARCH)"
@@ -30,9 +17,6 @@ config ARCH_MKIMAGE_NAME
 	string
 	default "invalid"
 
-config HAVE_ARCH_BOARD_GENERIC_DT
-	bool
-
 menu "General architecture-dependent options"
 
 config BOARD_GENERIC_DT
@@ -64,3 +48,19 @@ config BOARD_GENERIC_FIT
 	  installed on the build host.
 
 endmenu
+
+config ARCH_HAS_CTRLC
+	bool
+
+#
+# Select this option if the architecture assumes DMA devices are coherent
+# by default.
+#
+config ARCH_DMA_DEFAULT_COHERENT
+	bool
+
+config ARCH_HAS_ASAN_FIBER_API
+	bool
+
+config HAVE_ARCH_BOARD_GENERIC_DT
+	bool
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:54:13 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:54:13 +0100
Subject: [PATCH v2 3/6] treewide: retire CONFIG_HAS_CACHE
In-Reply-To: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
References: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
Message-ID: <20250313075416.3202194-3-a.fatoum@pengutronix.de>

The option serves no purpose any longer as all cache maintenance is
hidden behind generic APIs like the DMA streaming API.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - no change
---
 arch/arm/Kconfig      | 1 -
 arch/kvx/Kconfig      | 1 -
 arch/openrisc/Kconfig | 1 -
 arch/powerpc/Kconfig  | 1 -
 common/Kconfig        | 8 --------
 drivers/net/Kconfig   | 1 -
 6 files changed, 13 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 3d8f2eeca713..f5f9f3828782 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -3,7 +3,6 @@
 config ARM
 	bool
 	select HAS_KALLSYMS
-	select HAS_CACHE
 	select HAVE_IMAGE_COMPRESSION
 	select HAVE_ARCH_KASAN
 	select ARCH_HAS_SJLJ
diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
index 2e6432f897d8..5f325ca28358 100644
--- a/arch/kvx/Kconfig
+++ b/arch/kvx/Kconfig
@@ -14,7 +14,6 @@ config KVX
 	select FITIMAGE
 	select GENERIC_FIND_NEXT_BIT
 	select ARCH_HAS_SJLJ
-	select HAS_CACHE
 	select HAS_DMA
 	select LIBFDT
 	select MFD_SYSCON
diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig
index 6b64b299b391..d79743962a42 100644
--- a/arch/openrisc/Kconfig
+++ b/arch/openrisc/Kconfig
@@ -3,7 +3,6 @@
 config OPENRISC
 	bool
 	select OFTREE
-	select HAS_CACHE
 	select HAVE_CONFIGURABLE_MEMORY_LAYOUT
 	select GENERIC_FIND_NEXT_BIT
 	select ARCH_HAS_SJLJ
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 6346594173ac..4e282bc3ac80 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -5,7 +5,6 @@ config PPC
 	select HAVE_CONFIGURABLE_TEXT_BASE
 	select HAS_KALLSYMS
 	select HAS_MODULES
-	select HAS_CACHE
 	select GENERIC_FIND_NEXT_BIT
 	select OFTREE
 	select ARCH_HAS_SJLJ
diff --git a/common/Kconfig b/common/Kconfig
index 8a051a29e76c..6e5fba33ea4a 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -27,14 +27,6 @@ config HAS_KALLSYMS
 config HAS_MODULES
 	bool
 
-config HAS_CACHE
-	bool
-	help
-	  This allows you to run "make ARCH=sandbox allyesconfig".
-
-	  Drivers that depend on a cache implementation can depend on this
-	  config, so that you don't get a compilation error.
-
 config HAS_DMA
 	bool
 	help
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 5c436a05ccc5..7cad80c0a4b6 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -188,7 +188,6 @@ config DRIVER_NET_ENC28J60_WRITEVERIFY
 config DRIVER_NET_ETHOC
 	bool "OpenCores ethernet MAC driver"
 	depends on OPENRISC
-	depends on HAS_CACHE
 	select PHYLIB
 	help
 	  This option enables support for the OpenCores 10/100 Mbps
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:54:14 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:54:14 +0100
Subject: [PATCH v2 4/6] arch: move hidden arch options to arch/Kconfig
In-Reply-To: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
References: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
Message-ID: <20250313075416.3202194-4-a.fatoum@pengutronix.de>

We have a number of Kconfig symbols that are exclusively selected from
architecture Kconfig files, but are defined all over.

Move the definition of these symbols into arch/Kconfig, where they
are supposed to be.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - no change
---
 arch/Kconfig            | 42 +++++++++++++++++++++++++++++++++++++++++
 common/Kconfig          | 21 ---------------------
 common/Kconfig.debug_ll |  3 ---
 lib/Kconfig             | 12 ------------
 lib/Kconfig.ubsan       |  2 --
 lib/kasan/Kconfig       |  3 ---
 6 files changed, 42 insertions(+), 41 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 21175b90a076..b1200184678f 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -62,5 +62,47 @@ config ARCH_DMA_DEFAULT_COHERENT
 config ARCH_HAS_ASAN_FIBER_API
 	bool
 
+config ARCH_HAS_STACK_DUMP
+	bool
+
+config ARCH_HAS_DATA_ABORT_MASK
+	bool
+
+config ARCH_HAS_ZERO_PAGE
+	bool
+
+config HAVE_EFFICIENT_UNALIGNED_ACCESS
+	bool
+
 config HAVE_ARCH_BOARD_GENERIC_DT
 	bool
+
+config HAVE_MOD_ARCH_SPECIFIC
+	bool
+	help
+	  The arch uses struct mod_arch_specific to store data.  Many arches
+	  just need a simple module loader without arch specific data - those
+	  should not enable this.
+
+config ARCH_HAS_SJLJ
+	bool
+	help
+	  Architecture has support implemented for setjmp()/longjmp()/initjmp()
+
+config ARCH_DMA_ADDR_T_64BIT
+	bool
+
+config ARCH_USE_SYM_ANNOTATIONS
+	bool
+	help
+	  This is selected by architectures that exclusively use the new SYM_
+	  macros in their assembly code and not the deprecated ENTRY/PROC.
+
+config HAS_DEBUG_LL
+	bool
+
+config HAVE_ARCH_KASAN
+	bool
+
+config ARCH_HAS_UBSAN_SANITIZE_ALL
+	bool
diff --git a/common/Kconfig b/common/Kconfig
index 6e5fba33ea4a..de66f0461cf1 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -35,11 +35,6 @@ config HAS_DMA
 	  Drivers that depend on a DMA implementation can depend on this
 	  config, so that you don't get a compilation error.
 
-config ARCH_HAS_SJLJ
-	bool
-	help
-	  Architecture has support implemented for setjmp()/longjmp()/initjmp()
-
 config GENERIC_GPIO
 	bool
 
@@ -84,9 +79,6 @@ config MENUTREE
 	select GLOB
 	select GLOB_SORT
 
-config ARCH_DMA_ADDR_T_64BIT
-	bool
-
 config BAREBOX_UPDATE_IMX_NAND_FCB
 	bool
 	depends on ARCH_IMX7 || ARCH_IMX6 || ARCH_IMX28
@@ -359,13 +351,6 @@ config MODULES
 	  As modules can't be signed, loading external modules is not
 	  recommended for secure systems.
 
-config HAVE_MOD_ARCH_SPECIFIC
-	bool
-	help
-	  The arch uses struct mod_arch_specific to store data.  Many arches
-	  just need a simple module loader without arch specific data - those
-	  should not enable this.
-
 config KALLSYMS
 	depends on HAS_KALLSYMS
 	bool "kallsyms"
@@ -1359,9 +1344,3 @@ source "common/boards/Kconfig"
 config DDR_SPD
 	bool
 	select CRC_ITU_T
-
-config ARCH_USE_SYM_ANNOTATIONS
-	bool
-	help
-	  This is selected by architectures that exclusively use the new SYM_
-	  macros in their assembly code and not the deprecated ENTRY/PROC.
diff --git a/common/Kconfig.debug_ll b/common/Kconfig.debug_ll
index 1f9255b1a45b..8c49f5b72882 100644
--- a/common/Kconfig.debug_ll
+++ b/common/Kconfig.debug_ll
@@ -1,8 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-config HAS_DEBUG_LL
-	bool
-
 config DEBUG_LL
 	bool
 	depends on HAS_DEBUG_LL
diff --git a/lib/Kconfig b/lib/Kconfig
index 40c7b2cb5d65..8e1d8086fbb6 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -213,18 +213,6 @@ config BLOBGEN
 	select BASE64
 	bool "include blob encode/decode support"
 
-config ARCH_HAS_STACK_DUMP
-	bool
-
-config ARCH_HAS_DATA_ABORT_MASK
-	bool
-
-config ARCH_HAS_ZERO_PAGE
-	bool
-
-config HAVE_EFFICIENT_UNALIGNED_ACCESS
-	bool
-
 config GENERIC_ALLOCATOR
 	bool
 	help
diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan
index c04ff3cbb6fd..063563536be1 100644
--- a/lib/Kconfig.ubsan
+++ b/lib/Kconfig.ubsan
@@ -1,6 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
-config ARCH_HAS_UBSAN_SANITIZE_ALL
-	bool
 
 config UBSAN
 	bool "Undefined behaviour sanity checker"
diff --git a/lib/kasan/Kconfig b/lib/kasan/Kconfig
index 895a62d88439..532412953ba5 100644
--- a/lib/kasan/Kconfig
+++ b/lib/kasan/Kconfig
@@ -1,8 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-config HAVE_ARCH_KASAN
-	bool
-
 config CC_HAS_KASAN_GENERIC
 	def_bool $(cc-option, -fsanitize=kernel-address)
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:54:15 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:54:15 +0100
Subject: [PATCH v2 5/6] arch: move PHYS_ADDR_T_64BIT definition to arch/Kconfig
In-Reply-To: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
References: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
Message-ID: <20250313075416.3202194-5-a.fatoum@pengutronix.de>

Currently, every architecture with 64-bit support defines its own
PHYS_ADDR_T_64BIT symbol, except for x86.

Sync with what's done for ARCH_DMA_ADDR_T_64BIT and move
PHYS_ADDR_T_64BIT into arch/Kconfig as well.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - no change
---
 arch/Kconfig         | 4 ++++
 arch/arm/cpu/Kconfig | 3 ---
 arch/kvx/Kconfig     | 3 ---
 arch/mips/Kconfig    | 3 ---
 arch/riscv/Kconfig   | 3 ---
 arch/sandbox/Kconfig | 3 ---
 6 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index b1200184678f..dc5d1e454df5 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -89,6 +89,10 @@ config ARCH_HAS_SJLJ
 	help
 	  Architecture has support implemented for setjmp()/longjmp()/initjmp()
 
+
+config PHYS_ADDR_T_64BIT
+	bool
+
 config ARCH_DMA_ADDR_T_64BIT
 	bool
 
diff --git a/arch/arm/cpu/Kconfig b/arch/arm/cpu/Kconfig
index 84fe770b6da8..e61bcadc8c35 100644
--- a/arch/arm/cpu/Kconfig
+++ b/arch/arm/cpu/Kconfig
@@ -2,9 +2,6 @@
 
 comment "Processor Type"
 
-config PHYS_ADDR_T_64BIT
-	bool
-
 config CPU_32
 	bool
 	select HAS_MODULES
diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
index 5f325ca28358..9b733cd79201 100644
--- a/arch/kvx/Kconfig
+++ b/arch/kvx/Kconfig
@@ -23,9 +23,6 @@ config KVX
 	select RESET_SOURCE
 	default y
 
-config PHYS_ADDR_T_64BIT
-	bool
-
 config 64BIT
 	bool
 	select ARCH_DMA_ADDR_T_64BIT
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 769949a91085..43c493978c8f 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -36,9 +36,6 @@ config GENERIC_LINKER_SCRIPT
 	bool
 	default y
 
-config PHYS_ADDR_T_64BIT
-	bool
-
 config ARCH_TEXT_BASE
 	hex
 	default 0xa0800000
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index be2146b3facb..4d56e55b533f 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -59,9 +59,6 @@ config CPU_SUPPORTS_32BIT_KERNEL
 config CPU_SUPPORTS_64BIT_KERNEL
 	bool
 
-config PHYS_ADDR_T_64BIT
-	bool
-
 config 32BIT
 	bool
 	depends on CPU_SUPPORTS_32BIT_KERNEL
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index c1a51d4f021d..7c86511a2c61 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -32,9 +32,6 @@ config ARCH_TEXT_BASE
 
 menu "Sandbox specific settings"
 
-config PHYS_ADDR_T_64BIT
-	bool
-
 config CC_IS_64BIT
 	def_bool $(success,$(srctree)/scripts/gcc-64bitptr.sh $(CC))
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:54:16 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:54:16 +0100
Subject: [PATCH v2 6/6] x86: move CONFIG_PHYS_ADDR_T_64BIT setting into Kconfig
In-Reply-To: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
References: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
Message-ID: <20250313075416.3202194-6-a.fatoum@pengutronix.de>

sizeof(phys_addr_t) depends on whether CONFIG_PHYS_ADDR_T_64BIT is
enabled, which we so far defined depending on __x86_64__ in a header
file.

Given that we have a 64BIT symbol already in Kconfig that's selected
when building for 64-bit, let's have it select PHYS_ADDR_T_64BIT.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - drop CONFIG_PHYS_ADDR_T_64BIT assignment in header file
  - reword commit message accordingly
---
 arch/x86/Kconfig             | 1 +
 arch/x86/include/asm/types.h | 6 ------
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index cea8e25b81f0..b453890f022b 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -28,6 +28,7 @@ menu "ARCH specific settings"
 config 64BIT
 	def_bool y if X86_EFI
 	select ARCH_DMA_ADDR_T_64BIT
+	select PHYS_ADDR_T_64BIT
 	help
 	  Say yes to build a 64-bit binary - formerly known as x86_64
 	  Say no to build a 32-bit binary - formerly known as i386.
diff --git a/arch/x86/include/asm/types.h b/arch/x86/include/asm/types.h
index 52a6e51fd4b1..feb5843b9c92 100644
--- a/arch/x86/include/asm/types.h
+++ b/arch/x86/include/asm/types.h
@@ -14,12 +14,6 @@
  */
 #define INTERNAL_SIZE_T unsigned long
 
-/*
- * This is a Kconfig variable in the Kernel, but we want to detect
- * this during compile time, so we set it here.
- */
-#define CONFIG_PHYS_ADDR_T_64BIT
-
 #endif
 
 #endif
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 00:54:12 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 08:54:12 +0100
Subject: [PATCH v2 2/6] RISC-V: rename HAS_CACHE to RISCV_ICACHE
In-Reply-To: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
References: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
Message-ID: <20250313075416.3202194-2-a.fatoum@pengutronix.de>

CONFIG_HAS_CACHE only serves a purpose on RISC-V to allow barebox to run
on softcores without fence.i instruction. Rename the symbol to reflect
that in preparation for removing HAS_CACHE altogether.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - no change
---
 arch/riscv/Kconfig.socs        | 9 ++++++---
 arch/riscv/include/asm/cache.h | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs
index ccda688faf6d..4a3b56b5fff4 100644
--- a/arch/riscv/Kconfig.socs
+++ b/arch/riscv/Kconfig.socs
@@ -19,7 +19,7 @@ config SOC_VIRT
 	bool "QEMU Virt Machine"
 	select RISCV_S_MODE
 	select BOARD_GENERIC_DT
-	select HAS_CACHE
+	select RISCV_ICACHE
 	select HAS_DEBUG_LL
 	help
 	  Generates an image tht can be be booted by QEMU. The image is called
@@ -46,7 +46,7 @@ config BOARD_RISCVEMU
 
 config CPU_SIFIVE
 	bool
-	select HAS_CACHE
+	select RISCV_ICACHE
 
 config SOC_SIFIVE
 	bool "SiFive SoCs"
@@ -116,7 +116,7 @@ config SOC_ALLWINNER_SUN20I
 	bool "Allwinner Sun20i SoCs"
 	depends on ARCH_RV64I
 	select HAS_DEBUG_LL
-	select HAS_CACHE
+	select RISCV_ICACHE
 
 if SOC_ALLWINNER_SUN20I
 
@@ -130,6 +130,9 @@ endif
 
 comment "CPU features"
 
+config RISCV_ICACHE
+	bool
+
 config SIFIVE_L2
 	bool "SiFive L2 cache controller"
 	depends on CPU_SIFIVE
diff --git a/arch/riscv/include/asm/cache.h b/arch/riscv/include/asm/cache.h
index c787f890017e..8c3cde669c30 100644
--- a/arch/riscv/include/asm/cache.h
+++ b/arch/riscv/include/asm/cache.h
@@ -21,7 +21,7 @@ static inline void thead_local_flush_icache_all(void)
 
 static inline void local_flush_icache_all(void)
 {
-#ifdef CONFIG_HAS_CACHE
+#ifdef CONFIG_RISCV_ICACHE
 	switch(riscv_vendor_id()) {
 	case THEAD_VENDOR_ID:
 		thead_local_flush_icache_all();
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 01:09:50 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 09:09:50 +0100
Subject: [PATCH] fixup! video: Rockchip: fix zero division in rk3588_calc_cru_cfg
In-Reply-To: <20250313073445.764875-19-a.fatoum@pengutronix.de>
References: <20250313073445.764875-19-a.fatoum@pengutronix.de>
Message-ID: <20250313080950.3222757-1-a.fatoum@pengutronix.de>

GCC in CI detects that a number of arguments to rk3588_calc_cru_cfg()
may be passed to ilog2() uninitialized. This issue also exists in the
kernel:

 - if_pixclk_div, if_dclk_div are seemingly unused by rk3588_set_intf_mux
   in cases where an uninitialized value is passed to ilog2

 - dclk_out_div is used unconditionally, but is uninitialized in the
   case of eDP and HDMI.

This will be reported upstream, but until it's resolved, initialize the
values to zero (ilog2(0) == 0 in Linux/barebox).

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/video/rockchip/rockchip_drm_vop2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/rockchip/rockchip_drm_vop2.c b/drivers/video/rockchip/rockchip_drm_vop2.c
index f15ef1b57bf5..e45492360d6f 100644
--- a/drivers/video/rockchip/rockchip_drm_vop2.c
+++ b/drivers/video/rockchip/rockchip_drm_vop2.c
@@ -852,7 +852,7 @@ static unsigned long rk3588_set_intf_mux(struct vop2_video_port *vp, int id, u32
 					 unsigned int clock)
 {
 	struct vop2 *vop2 = vp->vop2;
-	int dclk_core_div, dclk_out_div, if_pixclk_div, if_dclk_div;
+	int dclk_core_div, dclk_out_div = 0, if_pixclk_div = 0, if_dclk_div = 0;
 	u32 die, dip, div, vp_clk_div, val;
 
 	clock = rk3588_calc_cru_cfg(vp, id, &dclk_core_div, &dclk_out_div,
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 01:33:12 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 09:33:12 +0100
Subject: [BUG] drm/rockchip: vop2: uninitialized variables passed to ilog2 and
 writel
Message-ID: <7ba2e429-113d-4e1c-968b-ffbe65bcf9f4@pengutronix.de>

Hi,

Running clang-analyzer[1] on the VOP2 driver in barebox[2], which was ported
from Linux reports that following variables:

  dclk_out_div, if_pixclk_div, if_dclk_div

defined in rk3588_set_intf_mux() and passed to rk3588_calc_cru_cfg()
are given as uninitialized arguments to ilog2() and in some cases even
used afterwards unconditionally (outside of error cases):

  - dclk_out_div: is not initialized in the HDMI, eDP and DPI cases,
    but is passed to ilog2 unconditionally and the result is written
    into the RK3588_VP_CLK_CTRL register

  - if_pixclk_div: is not initialized in the DP and DPI cases,
    but is passed to ilog2 unconditionally.
    However, the result seems unused.

  - if_clk_div: is not initialized in the DP, MIPI and DPI cases,
    but is passed to ilog2 unconditionally.
    However, the result seems unused.

I checked against Linux v6.14-rc6.

I am not fully sure what a suitable default value would be for the first
case, which is why I report this without a patch.

[1]: https://lore.kernel.org/barebox/20250313080950.3222757-1-a.fatoum at pengutronix.de/T/#m78ca98c01b73ef7fe3316e73ce62cfe4b2c111d0
[2]: https://github.com/barebox/barebox/blob/v2025.02.0/drivers/video/rockchip/rockchip_drm_vop2.c

Thanks,
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-5555 |



From a.fatoum at pengutronix.de  Thu Mar 13 01:56:58 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 09:56:58 +0100
Subject: [PATCH] malloc: return ZERO_SIZE_PTR for 0-byte allocations
Message-ID: <20250313085658.13255-1-a.fatoum@pengutronix.de>

Linux kmalloc doesn't return NULL on 0-byte allocations, but returns a
fixed ZERO_PSIZE_PTR constant, which triggers a NULL page exception when
dereferenced.

However, in barebox, allocator behavior differs:

 - glibc returns an unique pointer, but the standard also allows
   libc implementations to return NULL
 - tlsf returns NULL
 - dlmalloc returns a unique pointer
 - dummy malloc returns a unique pointer

Let's unify this discrepancy by doing something completely else and
returning a non-NULL non-unique pointer constant like Linux does.

The benefit of that is:

  - NULL return value always means out-of-memory
  - Accessing a zero sized allocation triggers a NULL page exception

This was noticed during porting of 9p2000 file system from Linux, which
does variable sized allocations and can end up allocating 0 bytes, but
expects that the allocation does not return NULL.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/os/libc_malloc.c | 25 ++++++++++++++++++++++++-
 common/calloc.c               |  2 +-
 common/dlmalloc.c             | 16 +++++++++-------
 common/dummy_malloc.c         |  3 +++
 common/tlsf.c                 | 15 ++++++++++-----
 common/tlsf_malloc.c          |  9 ---------
 include/malloc.h              | 13 +++++++++++++
 test/self/malloc.c            |  3 ++-
 8 files changed, 62 insertions(+), 24 deletions(-)

diff --git a/arch/sandbox/os/libc_malloc.c b/arch/sandbox/os/libc_malloc.c
index dd0f8670ff71..bb4fb1c9ead4 100644
--- a/arch/sandbox/os/libc_malloc.c
+++ b/arch/sandbox/os/libc_malloc.c
@@ -6,6 +6,10 @@
 #include <stdlib.h>
 #include <malloc.h>
 
+#define ZERO_SIZE_PTR ((void *)16)
+
+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
+				(unsigned long)ZERO_SIZE_PTR)
 #define BAREBOX_ENOMEM 12
 #define BAREBOX_MALLOC_MAX_SIZE 0x40000000
 
@@ -19,6 +23,9 @@ void *barebox_memalign(size_t alignment, size_t bytes)
 {
 	void *mem = NULL;
 
+	if (!bytes)
+		return ZERO_SIZE_PTR;
+
 	if (alignment <= BAREBOX_MALLOC_MAX_SIZE && bytes <= BAREBOX_MALLOC_MAX_SIZE)
 		mem = memalign(alignment, bytes);
 	if (!mem)
@@ -29,9 +36,11 @@ void *barebox_memalign(size_t alignment, size_t bytes)
 
 void *barebox_malloc(size_t size)
 {
-
 	void *mem = NULL;
 
+	if (!size)
+		return ZERO_SIZE_PTR;
+
 	if (size <= BAREBOX_MALLOC_MAX_SIZE)
 		mem = malloc(size);
 	if (!mem)
@@ -42,11 +51,15 @@ void *barebox_malloc(size_t size)
 
 size_t barebox_malloc_usable_size(void *mem)
 {
+	if (ZERO_OR_NULL_PTR(mem))
+		return 0;
 	return malloc_usable_size(mem);
 }
 
 void barebox_free(void *ptr)
 {
+	if (ZERO_OR_NULL_PTR(ptr))
+		return;
 	free(ptr);
 }
 
@@ -54,6 +67,13 @@ void *barebox_realloc(void *ptr, size_t size)
 {
 	void *mem = NULL;
 
+	if (!size) {
+		barebox_free(ptr);
+		return ZERO_SIZE_PTR;
+	}
+	if (ZERO_OR_NULL_PTR(ptr))
+		ptr = NULL;
+
 	if (size <= BAREBOX_MALLOC_MAX_SIZE)
 		mem = realloc(ptr, size);
 	if (!mem)
@@ -67,6 +87,9 @@ void *barebox_calloc(size_t n, size_t elem_size)
 	size_t product;
 	void *mem = NULL;
 
+	if (!n || !elem_size)
+		return ZERO_SIZE_PTR;
+
 	if (!__builtin_mul_overflow(n, elem_size, &product) &&
 	    product <= BAREBOX_MALLOC_MAX_SIZE)
 		mem = calloc(n, elem_size);
diff --git a/common/calloc.c b/common/calloc.c
index 17cbd9beefee..ee9322509751 100644
--- a/common/calloc.c
+++ b/common/calloc.c
@@ -13,7 +13,7 @@ void *calloc(size_t n, size_t elem_size)
 	size_t size = size_mul(elem_size, n);
 	void *r = malloc(size);
 
-	if (r && !want_init_on_alloc())
+	if (!ZERO_OR_NULL_PTR(r) && !want_init_on_alloc())
 		memset(r, 0x0, size);
 
 	return r;
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 2b5723e127c4..c8e05ac68f2a 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -389,7 +389,7 @@
   returns a unique pointer for malloc(0), so does realloc(p, 0).
 */
 
-/*   #define REALLOC_ZERO_BYTES_FREES */
+#define REALLOC_ZERO_BYTES_FREES
 
 /*
   Define HAVE_MMAP to optionally make malloc() use mmap() to
@@ -1165,6 +1165,8 @@ void *dlmalloc(size_t bytes)
 	if (bytes > MALLOC_MAX_SIZE) {
 		errno = ENOMEM;
 		return NULL;
+	} else if (bytes == 0) {
+		return ZERO_SIZE_PTR;
 	}
 
 	nb = request2size(bytes); /* padded request size; */
@@ -1363,7 +1365,7 @@ void dlfree(void *mem)
 	mchunkptr fwd;		/* misc temp for linking */
 	int islr;		/* track whether merging with last_remainder */
 
-	if (!mem)		/* free(0) has no effect */
+	if (ZERO_OR_NULL_PTR(mem))		/* free(0) has no effect */
 		return;
 
 	p = mem2chunk(mem);
@@ -1431,7 +1433,7 @@ size_t dlmalloc_usable_size(void *mem)
 {
 	mchunkptr p;
 
-	if (!mem)
+	if (ZERO_OR_NULL_PTR(mem))
 		return 0;
 
 	p = mem2chunk(mem);
@@ -1495,7 +1497,7 @@ void *dlrealloc(void *oldmem, size_t bytes)
 #ifdef REALLOC_ZERO_BYTES_FREES
 	if (bytes == 0) {
 		dlfree(oldmem);
-		return NULL;
+		return ZERO_SIZE_PTR;
 	}
 #endif
 
@@ -1505,7 +1507,7 @@ void *dlrealloc(void *oldmem, size_t bytes)
 	}
 
 	/* realloc of null is supposed to be same as malloc */
-	if (!oldmem)
+	if (ZERO_OR_NULL_PTR(oldmem))
 		return dlmalloc(bytes);
 
 	newp = oldp = mem2chunk(oldmem);
@@ -1760,8 +1762,8 @@ void *dlcalloc(size_t n, size_t elem_size)
 
 	mem = dlmalloc(sz);
 
-	if (!mem)
-		return NULL;
+	if (ZERO_OR_NULL_PTR(mem))
+		return mem;
 	else {
 		p = mem2chunk(mem);
 
diff --git a/common/dummy_malloc.c b/common/dummy_malloc.c
index 4973f35650ab..956a54da0396 100644
--- a/common/dummy_malloc.c
+++ b/common/dummy_malloc.c
@@ -13,6 +13,9 @@ void *memalign(size_t alignment, size_t bytes)
 {
 	void *mem = NULL;
 
+	if (!bytes)
+		return ZERO_SIZE_PTR;
+
 	if (alignment <= MALLOC_MAX_SIZE && bytes <= MALLOC_MAX_SIZE)
 		mem = sbrk(bytes + alignment);
 	if (!mem) {
diff --git a/common/tlsf.c b/common/tlsf.c
index 146f1b7ebe81..5504453a9453 100644
--- a/common/tlsf.c
+++ b/common/tlsf.c
@@ -743,7 +743,7 @@ void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user)
 size_t tlsf_block_size(void* ptr)
 {
 	size_t size = 0;
-	if (ptr)
+	if (likely(!ZERO_OR_NULL_PTR(ptr)))
 	{
 		const block_header_t* block = block_from_ptr(ptr);
 		size = block_size(block);
@@ -935,6 +935,8 @@ void* tlsf_malloc(tlsf_t tlsf, size_t size)
 	const size_t adjust = adjust_request_size(size, ALIGN_SIZE);
 	block_header_t* block;
 
+	if (!size)
+		return ZERO_SIZE_PTR;
 	if (!adjust)
 		return NULL;
 
@@ -961,12 +963,14 @@ void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size)
 
 	/*
 	** If alignment is less than or equals base alignment, we're done.
-	** If we requested 0 bytes, return null, as tlsf_malloc(0) does.
+	** If we requested 0 bytes, return ZERO_SIZE_PTR, as tlsf_malloc(0) does.
 	*/
 	const size_t aligned_size = (adjust && align > ALIGN_SIZE) ? size_with_gap : adjust;
 
 	block_header_t* block;
 
+	if (!size)
+		return ZERO_SIZE_PTR;
 	if (!adjust || !size_with_gap)
 		return NULL;
 
@@ -1008,7 +1012,7 @@ void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size)
 void tlsf_free(tlsf_t tlsf, void* ptr)
 {
 	/* Don't attempt to free a NULL pointer. */
-	if (ptr)
+	if (!ZERO_OR_NULL_PTR(ptr))
 	{
 		control_t* control = tlsf_cast(control_t*, tlsf);
 		block_header_t* block = block_from_ptr(ptr);
@@ -1042,12 +1046,13 @@ void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
 	void* p = 0;
 
 	/* Zero-size requests are treated as free. */
-	if (ptr && size == 0)
+	if (size == 0)
 	{
 		tlsf_free(tlsf, ptr);
+		return ZERO_SIZE_PTR;
 	}
 	/* Requests with NULL pointers are treated as malloc. */
-	else if (!ptr)
+	else if (ZERO_OR_NULL_PTR(ptr))
 	{
 		p = tlsf_malloc(tlsf, size);
 	}
diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
index 1b9d9c7702c2..6a90ee47199f 100644
--- a/common/tlsf_malloc.c
+++ b/common/tlsf_malloc.c
@@ -17,12 +17,6 @@ extern tlsf_t tlsf_mem_pool;
 void *malloc(size_t bytes)
 {
 	void *mem;
-	/*
-	 * tlsf_malloc returns NULL for zero bytes, we instead want
-	 * to have a valid pointer.
-	 */
-	if (!bytes)
-		bytes = 1;
 
 	mem = tlsf_malloc(tlsf_mem_pool, bytes);
 	if (!mem)
@@ -40,9 +34,6 @@ EXPORT_SYMBOL(free);
 
 size_t malloc_usable_size(void *mem)
 {
-	if (!mem)
-		return 0;
-
 	return tlsf_block_size(mem);
 }
 EXPORT_SYMBOL(malloc_usable_size);
diff --git a/include/malloc.h b/include/malloc.h
index c38726342c08..0b74746360c0 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -8,6 +8,19 @@
 #define MALLOC_SHIFT_MAX	30
 #define MALLOC_MAX_SIZE		(1UL << MALLOC_SHIFT_MAX)
 
+/*
+ * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests.
+ *
+ * Dereferencing ZERO_SIZE_PTR will lead to a distinct access fault.
+ *
+ * ZERO_SIZE_PTR can be passed to free though in the same way that NULL can.
+ * Both make free a no-op.
+ */
+#define ZERO_SIZE_PTR ((void *)16)
+
+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
+				(unsigned long)ZERO_SIZE_PTR)
+
 #if IN_PROPER
 void *malloc(size_t) __alloc_size(1);
 size_t malloc_usable_size(void *);
diff --git a/test/self/malloc.c b/test/self/malloc.c
index 79a32b5d97c7..52f9fc344c1a 100644
--- a/test/self/malloc.c
+++ b/test/self/malloc.c
@@ -122,7 +122,8 @@ static void test_malloc(void)
 	p = expect_alloc_ok(malloc(0));
 	tmp = expect_alloc_ok(malloc(0));
 
-	__expect_cond(p != tmp, true, "allocate distinct 0-size buffers", __func__, __LINE__);
+	__expect_cond(p == tmp, true, "allocate equal 0-size buffers", __func__, __LINE__);
+	__expect_cond(p == ZERO_SIZE_PTR, true, "get ZERO_SIZE_PTR for 0-size buffers", __func__, __LINE__);
 
 	free(p);
 	free(tmp);
-- 
2.39.5



From jre at pengutronix.de  Thu Mar 13 02:21:19 2025
From: jre at pengutronix.de (Jonas Rebmann)
Date: Thu, 13 Mar 2025 10:21:19 +0100
Subject: [PATCH v2 2/2] ARM: boards: remove obsolete PCA9450_RESET_CTRL
 setup
In-Reply-To: <20250313-pca9450-wdog-v2-0-28e97e7da480@pengutronix.de>
References: <20250313-pca9450-wdog-v2-0-28e97e7da480@pengutronix.de>
Message-ID: <20250313-pca9450-wdog-v2-2-28e97e7da480@pengutronix.de>

Since a previous commit, PCA9450_RESET_CTRL is initialized to 0xA1 in
pca9450_probe; explicitly setting this in board.c has no effect anymore.

Remove the setup of this register from the
pca9450_register_init_callback of the two imx93 boards we currently
have.

Configuration of this register in power_init_board() in lowlevel.c of
the imx8 boards remains untouched for now. This is because there, the
register is configured even if the pca9450 driver is not enabled.
Furthermore, the power_init_board() functions initialize a larger array
of pmic registers which I haven't compared against other pmic and
-driver defaults.

Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
---
 arch/arm/boards/phytec-phycore-imx93/board.c | 9 ---------
 arch/arm/boards/tqma93xx/board.c             | 3 ---
 2 files changed, 12 deletions(-)

diff --git a/arch/arm/boards/phytec-phycore-imx93/board.c b/arch/arm/boards/phytec-phycore-imx93/board.c
index 149248ca654624826d0e8f6fe0f1f42c2747e248..03ba8cb5026d2a9eaa054fcfc69e18872fcd658e 100644
--- a/arch/arm/boards/phytec-phycore-imx93/board.c
+++ b/arch/arm/boards/phytec-phycore-imx93/board.c
@@ -6,23 +6,14 @@
 #include <init.h>
 #include <linux/kernel.h>
 #include <environment.h>
-#include <mfd/pca9450.h>
 #include <deep-probe.h>
 #include <mach/imx/bbu.h>
 #include <linux/pinctrl/consumer.h>
 
-static void phycore_imx93_init_pmic(struct regmap *map)
-{
-	/* set WDOG_B_CFG to cold reset */
-	regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
-}
-
 static int phycore_imx93_probe(struct device *dev)
 {
 	struct device_node *np;
 
-	pca9450_register_init_callback(phycore_imx93_init_pmic);
-
 	/*
 	 * The phy on the EQOS has its MDIO lines connected to the FEC. The phy
 	 * registers can only be successfully read when the EQOS pinctrl setup
diff --git a/arch/arm/boards/tqma93xx/board.c b/arch/arm/boards/tqma93xx/board.c
index b181784079cf12e5a112d13f95c87c2cf5ebeba6..b4de6c2f6c347cb255537a3784a667a9c2607de3 100644
--- a/arch/arm/boards/tqma93xx/board.c
+++ b/arch/arm/boards/tqma93xx/board.c
@@ -27,9 +27,6 @@ static void tqma93xx_init_pmic(struct regmap *map)
 
 	/* I2C_LT_EN*/
 	regmap_write(map, 0xa, 0x3);
-
-	/* set WDOG_B_CFG to cold reset */
-	regmap_write(map, PCA9450_RESET_CTRL, 0xA1);
 }
 
 static int tqma93xx_probe(struct device *dev)

-- 
2.39.5



From jre at pengutronix.de  Thu Mar 13 02:21:17 2025
From: jre at pengutronix.de (Jonas Rebmann)
Date: Thu, 13 Mar 2025 10:21:17 +0100
Subject: [PATCH v2 0/2] Move pca9450 RESET_CTRL configuration to driver
Message-ID: <20250313-pca9450-wdog-v2-0-28e97e7da480@pengutronix.de>

Configure the RESET_CTRL register of the pca9450 pmic in the driver,
like u-boot and kernel do. Subsequently, remove the setup of this
register from the pca9450_register_init_callback of the two imx93 boards
we currently have.

Configuration of this register in lowlevel.c of the imx8 boards remains
untouched for now.

Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
---
Changes in v2:
- Move to commit message the reasoning for keeping mx8 boards explicit register initialization
- When mentioning other commits in a commit message, include their subject line 
- Remove superfluous include
- Link to v1: https://lore.kernel.org/r/20250311-pca9450-wdog-v1-0-45120abeae00 at pengutronix.de

---
Jonas Rebmann (2):
      mfd: pca9450: configure pmic reset behavior
      ARM: boards: remove obsolete PCA9450_RESET_CTRL setup

 arch/arm/boards/phytec-phycore-imx93/board.c |  9 ---------
 arch/arm/boards/tqma93xx/board.c             |  3 ---
 drivers/mfd/pca9450.c                        | 10 ++++++++++
 include/mfd/pca9450.h                        |  4 ++++
 4 files changed, 14 insertions(+), 12 deletions(-)
---
base-commit: d004da6e3710cc01b645a57c8dd1a986eced1c80
change-id: 20250311-pca9450-wdog-b9458f1a26ff

Best regards,
-- 
Jonas Rebmann <jre at pengutronix.de>



From jre at pengutronix.de  Thu Mar 13 02:21:18 2025
From: jre at pengutronix.de (Jonas Rebmann)
Date: Thu, 13 Mar 2025 10:21:18 +0100
Subject: [PATCH v2 1/2] mfd: pca9450: configure pmic reset behavior
In-Reply-To: <20250313-pca9450-wdog-v2-0-28e97e7da480@pengutronix.de>
References: <20250313-pca9450-wdog-v2-0-28e97e7da480@pengutronix.de>
Message-ID: <20250313-pca9450-wdog-v2-1-28e97e7da480@pengutronix.de>

Currently, boards using the pca9450 pmic driver initialize the
RESET_CTRL register either in lowlevel.c or board.c explicitly to 0xA1
to enable the watchdog for Cold Reset with all voltage regulators
recycled except LDO1/ LDO2 in addition to the default configuration of
0x11 where the WDOG_B watchdog input is disabled.

Instead, enable the watchdog in the driver for Cold Reset with all
voltage regulators recycled except LDO1/ LDO2. When
nxp,wdog_b-warm-reset is set, the watchdog is instead enabled for Warm
Reset.

This is identical to U-Boot's behaviour since commit 910c7a881f5 ("pmic:
pca9450: Make warm reset on WDOG_B assertion") and Linux's since commit
2364a64d0673f ("regulator: pca9450: Make warm reset on WDOG_B
assertion").

Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
---
 drivers/mfd/pca9450.c | 10 ++++++++++
 include/mfd/pca9450.h |  4 ++++
 2 files changed, 14 insertions(+)

diff --git a/drivers/mfd/pca9450.c b/drivers/mfd/pca9450.c
index 2511e662c3dfb5dfedbc461357ffa82d1812166f..5d5d3d8e017232a45676efad390a503500dd2156 100644
--- a/drivers/mfd/pca9450.c
+++ b/drivers/mfd/pca9450.c
@@ -103,6 +103,16 @@ static int __init pca9450_probe(struct device *dev)
 	/* Chip ID defined in bits [7:4] */
 	dev_info(dev, "PMIC Chip ID: 0x%x\n", (reg >> 4));
 
+	/* Enable WDOG_B, for cold reset by default */
+	if (of_property_read_bool(dev->of_node, "nxp,wdog_b-warm-reset"))
+		regmap_update_bits(regmap, PCA9450_RESET_CTRL,
+				   PCA9450_PMIC_RESET_WDOG_B_CFG_MASK,
+				   PCA9450_PMIC_RESET_WDOG_B_CFG_WARM);
+	else
+		regmap_update_bits(regmap, PCA9450_RESET_CTRL,
+				   PCA9450_PMIC_RESET_WDOG_B_CFG_MASK,
+				   PCA9450_PMIC_RESET_WDOG_B_CFG_COLD_LDO12);
+
 	if (pca9450_init_callback)
 		pca9450_init_callback(regmap);
 	pca9450_map = regmap;
diff --git a/include/mfd/pca9450.h b/include/mfd/pca9450.h
index 7071c3a9da6c5adc26dbd6149fec5fa96f3365bf..af10e409855ff6c3585c7f63098a16e8ec33dee2 100644
--- a/include/mfd/pca9450.h
+++ b/include/mfd/pca9450.h
@@ -66,4 +66,8 @@ static inline int pca9450_register_init_callback(void(*callback)(struct regmap *
 }
 #endif
 
+#define PCA9450_PMIC_RESET_WDOG_B_CFG_MASK		0xc0
+#define PCA9450_PMIC_RESET_WDOG_B_CFG_WARM		0x40
+#define PCA9450_PMIC_RESET_WDOG_B_CFG_COLD_LDO12	0x80
+
 #endif

-- 
2.39.5



From s.hauer at pengutronix.de  Thu Mar 13 02:54:41 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 13 Mar 2025 10:54:41 +0100
Subject: [PATCH 1/2] net: am65-cpsw-nuss: depends on DMA support
Message-ID: <20250313095442.2812937-1-s.hauer@pengutronix.de>

The am65-cpsw-nuss needs DMA functions provided by CONFIG_DMADEVICES, so
we must depend on this option to avoid linker errors. As the am65-cpsw-nuss
is useless without the DMA hardware driver depend on CONFIG_TI_K3_UDMA
instead which implies CONFIG_DMADEVICES.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/net/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 5c436a05cc..0099845096 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -68,6 +68,7 @@ config DRIVER_NET_DAVINCI_EMAC
 config DRIVER_NET_TI_K3_AM65_CPSW_NUSS
 	bool "TI K3 AM654x/J721E CPSW Ethernet driver"
 	depends on ARCH_K3 || COMPILE_TEST
+	depends on TI_K3_UDMA
 	select DRIVER_NET_TI_DAVINCI_MDIO
 	select PHYLIB
 	help
-- 
2.39.5



From s.hauer at pengutronix.de  Thu Mar 13 02:54:42 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 13 Mar 2025 10:54:42 +0100
Subject: [PATCH 2/2] ARM: multi_v8_defconfig: enable k3 drivers
In-Reply-To: <20250313095442.2812937-1-s.hauer@pengutronix.de>
References: <20250313095442.2812937-1-s.hauer@pengutronix.de>
Message-ID: <20250313095442.2812937-2-s.hauer@pengutronix.de>

The K3 architecture is enabled in multi_v8_defconfig. Enable the K3
specific drivers to make it more usable.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/multi_v8_defconfig | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm/configs/multi_v8_defconfig b/arch/arm/configs/multi_v8_defconfig
index b1e66e85f4..78964990a9 100644
--- a/arch/arm/configs/multi_v8_defconfig
+++ b/arch/arm/configs/multi_v8_defconfig
@@ -155,6 +155,7 @@ CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SERIAL_CADENCE=y
 CONFIG_DRIVER_SERIAL_LPUART32=y
 CONFIG_VIRTIO_CONSOLE=y
+CONFIG_DRIVER_NET_TI_K3_AM65_CPSW_NUSS=y
 CONFIG_DRIVER_NET_DESIGNWARE_IMX8=y
 CONFIG_DRIVER_NET_DESIGNWARE_ROCKCHIP=y
 CONFIG_DRIVER_NET_FEC_IMX=y
@@ -180,6 +181,7 @@ CONFIG_DRIVER_SPI_IMX=y
 CONFIG_SPI_NXP_FLEXSPI=y
 CONFIG_I2C_GPIO=y
 CONFIG_I2C_IMX=y
+CONFIG_I2C_OMAP=y
 CONFIG_I2C_RK3X=y
 CONFIG_I2C_MUX=y
 CONFIG_I2C_MUX_PCA954x=y
@@ -207,10 +209,11 @@ CONFIG_SOUND=y
 CONFIG_MCI=y
 CONFIG_MCI_MMC_BOOT_PARTITIONS=y
 CONFIG_MCI_DW=y
-CONFIG_MCI_ROCKCHIP_DWCMSHC=y
 CONFIG_MCI_SUNXI_SMHC=y
+CONFIG_MCI_ROCKCHIP_DWCMSHC=y
 CONFIG_MCI_IMX_ESDHC=y
 CONFIG_MCI_ARASAN=y
+CONFIG_MCI_AM654=y
 CONFIG_COMMON_CLK_SCMI=y
 CONFIG_MFD_ACT8846=y
 CONFIG_RAVE_SP_CORE=y
@@ -230,8 +233,11 @@ CONFIG_WATCHDOG_DW=y
 CONFIG_WATCHDOG_IMX=y
 CONFIG_WATCHDOG_IMXULP=y
 CONFIG_RAVE_SP_WATCHDOG=y
+CONFIG_K3_RTI_WDT=y
 CONFIG_HWRNG=y
 CONFIG_HW_RANDOM_VIRTIO=y
+CONFIG_DMADEVICES=y
+CONFIG_TI_K3_UDMA=y
 CONFIG_GPIO_PCA953X=y
 CONFIG_GPIO_ZYNQ=y
 CONFIG_PINCTRL_SINGLE=y
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:17 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:17 +0100
Subject: [PATCH 00/11] firmware: qemu_fw_cfg: implement file system
Message-ID: <20250313101728.3546902-1-a.fatoum@pengutronix.de>

The character device we currently have is cumbersome to use.
The Linux way to access it at /sys/firmware/qemu_fw_cfg
is much nicer to use, so this series adds support for a similar
FS to barebox.

A very nice result of having file system access to the QEMU variables
in barebox is that we get a trivial way to pass data to barebox.
To make it even more convenient to use, this series enables overriding
individual files in the environment via the new mechanism, e.g.:

  pytest --env nv/boot.default=fit --env boot/fit=@boot.sh

Ahmad Fatoum (11):
  video: ramfb: fix frame buffer screen size
  firmware: qemu_fw_cfg: drop duplicate definitions
  firmware: qemu_fw_cfg: add support for seeking
  firmware: qemu_fw_cfg: rename from /dev/fw_cfg0 to /dev/fw_cfg
  fs: add qemu_fw_cfg file system
  firmware: qemu_fw_cfg: register at device initcall level
  video: ramfb: use new qemu fw_cfg FS
  libfile: give copy_file a flags parameter
  libfile: pass copy_file flags through copy_recursive
  libfile: add support for not clobbering files in copy_file
  fs: qemu_fw_cfg: support populating environment via QEMU fw_cfg

 commands/Kconfig               |   4 +-
 commands/cp.c                  |  18 +-
 commands/defaultenv.c          |   2 +-
 commands/tftp.c                |   2 +-
 common/fastboot.c              |   2 +-
 conftest.py                    |  22 ++
 defaultenv/defaultenv.c        |  22 ++
 drivers/firmware/qemu_fw_cfg.c |  63 +++--
 drivers/video/Kconfig          |   2 +-
 drivers/video/ramfb.c          | 116 ++++------
 fs/Kconfig                     |   7 +
 fs/Makefile                    |   1 +
 fs/qemu_fw_cfg.c               | 404 +++++++++++++++++++++++++++++++++
 include/envfs.h                |   5 +
 include/libfile.h              |   8 +-
 include/string.h               |   5 +
 lib/libfile.c                  |  43 +++-
 17 files changed, 592 insertions(+), 134 deletions(-)
 create mode 100644 fs/qemu_fw_cfg.c

-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:21 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:21 +0100
Subject: [PATCH 04/11] firmware: qemu_fw_cfg: rename from /dev/fw_cfg0 to /dev/fw_cfg
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Message-ID: <20250313101728.3546902-5-a.fatoum@pengutronix.de>

There's only a single fw_cfg device, so the 0 suffix doesn't serve any
value. Remove it.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/firmware/qemu_fw_cfg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
index 33c1617a61e4..8928cc5bf2aa 100644
--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -263,7 +263,7 @@ static int fw_cfg_probe(struct device *dev)
 	fw_cfg->acc_virt = dma_alloc_coherent(DMA_DEVICE_BROKEN,
 					      sizeof(*fw_cfg->acc_virt), &fw_cfg->acc_dma);
 
-	fw_cfg->cdev.name = basprintf("fw_cfg%d", cdev_find_free_index("fw_cfg"));
+	fw_cfg->cdev.name = "fw_cfg";
 	fw_cfg->cdev.flags = DEVFS_IS_CHARACTER_DEV;
 	fw_cfg->cdev.size = 0;
 	fw_cfg->cdev.ops = &fw_cfg_ops;
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:23 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:23 +0100
Subject: [PATCH 06/11] firmware: qemu_fw_cfg: register at device initcall level
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Message-ID: <20250313101728.3546902-7-a.fatoum@pengutronix.de>

Registration at postmmu_initcall is too early for automounts to be
created.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/firmware/qemu_fw_cfg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
index 8928cc5bf2aa..ab34f999ceaa 100644
--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -313,4 +313,4 @@ static int qemu_fw_cfg_init(void)
 
 	return of_devices_ensure_probed_by_dev_id(qemu_fw_cfg_of_match);
 }
-postmmu_initcall(qemu_fw_cfg_init);
+device_initcall(qemu_fw_cfg_init);
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:24 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:24 +0100
Subject: [PATCH 07/11] video: ramfb: use new qemu fw_cfg FS
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Message-ID: <20250313101728.3546902-8-a.fatoum@pengutronix.de>

The new qemu_fw_cfg file system can simplify the ramfb driver a great
deal as it's then no longer necessary to enumerate the files in the
driver.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/video/Kconfig |   2 +-
 drivers/video/ramfb.c | 114 +++++++++++++++---------------------------
 2 files changed, 42 insertions(+), 74 deletions(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 0539e2d453da..437b6a3ba0f6 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -106,7 +106,7 @@ config DRIVER_VIDEO_SIMPLEFB
 
 config DRIVER_VIDEO_RAMFB
 	bool "QEMU RamFB support"
-	select QEMU_FW_CFG
+	select FS_QEMU_FW_CFG
 	help
 	  Add support for setting up a QEMU RamFB driver.
 
diff --git a/drivers/video/ramfb.c b/drivers/video/ramfb.c
index 5b03d8a9c821..0a0888fcfbcb 100644
--- a/drivers/video/ramfb.c
+++ b/drivers/video/ramfb.c
@@ -19,7 +19,6 @@ struct ramfb {
 	struct fb_info info;
 	dma_addr_t screen_dma;
 	struct fb_videomode mode;
-	u16 etcfb_select;
 };
 
 struct fw_cfg_etc_ramfb {
@@ -31,37 +30,6 @@ struct fw_cfg_etc_ramfb {
 	u32 stride;
 } __packed;
 
-static int fw_cfg_find_file(struct device *dev, int fd, const char *filename)
-{
-	size_t filename_len = strlen(filename);
-	ssize_t ret;
-	__be32 count;
-	int i;
-
-	ioctl(fd, FW_CFG_SELECT, &(u16) { FW_CFG_FILE_DIR });
-
-	lseek(fd, 0, SEEK_SET);
-
-	ret = read(fd, &count, sizeof(count));
-	if (ret < 0)
-		return ret;
-
-	for (i = 0; i < be32_to_cpu(count); i++) {
-		struct fw_cfg_file qfile;
-
-		read(fd, &qfile, sizeof(qfile));
-
-		dev_dbg(dev, "enumerating file %s\n", qfile.name);
-
-		if (memcmp(qfile.name, filename, filename_len))
-			continue;
-
-		return be16_to_cpu(qfile.select);
-	}
-
-	return -ENOENT;
-}
-
 static void ramfb_populate_modes(struct ramfb *ramfb)
 {
 	struct fb_info *info = &ramfb->info;
@@ -81,14 +49,15 @@ static void ramfb_populate_modes(struct ramfb *ramfb)
 static int ramfb_activate_var(struct fb_info *fbi)
 {
 	struct ramfb *ramfb = fbi->priv;
+	struct device *hwdev = fbi->dev.parent->parent;
 
 	if (fbi->screen_base)
-		dma_free_coherent(DMA_DEVICE_BROKEN,
-				  fbi->screen_base, ramfb->screen_dma, fbi->screen_size);
+		dma_free_coherent(hwdev, fbi->screen_base, ramfb->screen_dma,
+				  fbi->screen_size);
 
 	fbi->screen_size = fbi->xres * fbi->yres * fbi->bits_per_pixel / BITS_PER_BYTE;
-	fbi->screen_base = dma_alloc_coherent(DMA_DEVICE_BROKEN,
-					      fbi->screen_size, &ramfb->screen_dma);
+	fbi->screen_base = dma_alloc_coherent(hwdev, fbi->screen_size,
+					      &ramfb->screen_dma);
 
 	return 0;
 }
@@ -107,8 +76,6 @@ static void ramfb_enable(struct fb_info *fbi)
 	etc_ramfb->height = cpu_to_be32(fbi->yres);
 	etc_ramfb->stride = cpu_to_be32(fbi->line_length);
 
-	ioctl(ramfb->fd, FW_CFG_SELECT, &ramfb->etcfb_select);
-
 	pwrite(ramfb->fd, etc_ramfb, sizeof(*etc_ramfb), 0);
 
 	dma_free(etc_ramfb);
@@ -119,74 +86,75 @@ static struct fb_ops ramfb_ops = {
 	.fb_enable = ramfb_enable,
 };
 
-static int ramfb_probe(struct device *parent_dev, int fd)
+static int ramfb_probe(struct device *dev)
 {
 	int ret;
 	struct ramfb *ramfb;
 	struct fb_info *fbi;
 
-	ret = -ENODEV;
-
 	ramfb = xzalloc(sizeof(*ramfb));
 
-	ramfb->fd = fd;
-
-	ret = fw_cfg_find_file(parent_dev, fd, "etc/ramfb");
-	if (ret < 0) {
-		dev_dbg(parent_dev, "ramfb: fw_cfg (etc/ramfb) file not found\n");
-		return -ENODEV;
-	}
-
-	ramfb->etcfb_select = ret;
-	dev_dbg(parent_dev, "etc/ramfb file at slot 0x%x\n", ramfb->etcfb_select);
+	ramfb->fd = (int)(uintptr_t)dev->platform_data;
 
 	fbi = &ramfb->info;
 	fbi->priv = ramfb;
 	fbi->fbops = &ramfb_ops;
-	fbi->dev.parent = parent_dev;
+	fbi->dev.parent = dev;
 
 	ramfb_populate_modes(ramfb);
 
 	ret = register_framebuffer(fbi);
 	if (ret < 0) {
-		dev_err(parent_dev, "Unable to register ramfb: %d\n", ret);
+		dev_err(dev, "Unable to register ramfb: %d\n", ret);
 		return ret;
 	}
 
-	dev_info(parent_dev, "ramfb registered\n");
+	dev_info(dev, "ramfb registered\n");
 
 	return 0;
 }
 
+static struct driver ramfb_driver = {
+	.probe = ramfb_probe,
+	.name = "qemu-ramfb",
+};
+
 static int ramfb_driver_init(void)
 {
 	struct cdev *cdev;
-	int err = 0;
+	struct device *dev;
+	const char *mntpath;
+	int dirfd, fd;
 
-	for_each_cdev(cdev) {
-		int fd, ret;
+	platform_driver_register(&ramfb_driver);
 
-		if (!strstarts(cdev->name, "fw_cfg"))
-			continue;
+	cdev = cdev_by_name("fw_cfg");
+	if (!cdev)
+		return 0;
 
-		fd = cdev_fdopen(cdev, O_RDWR);
-		if (fd < 0) {
-			err = fd;
-			continue;
-		}
+	mntpath = cdev_mount(cdev);
+	if (IS_ERR(mntpath))
+		return PTR_ERR(mntpath);
 
-		ret = ramfb_probe(cdev->dev, fd);
-		if (ret == 0)
-			continue;
-		if (ret != -ENODEV && ret != -ENXIO)
-			err = ret;
+	dirfd = open(mntpath, O_PATH);
+	if (dirfd < 0)
+		return dirfd;
 
-		close(fd);
-	}
+	fd = openat(dirfd, "by_name/etc/ramfb", O_WRONLY);
+	close(dirfd);
+	if (fd == -ENOENT)
+		return 0;
+	if (fd < 0)
+		return fd;
 
-	return err;
+	dev = device_alloc("qemu-ramfb", DEVICE_ID_SINGLE);
+	dev->parent = cdev->dev;
+	dev->platform_data = (void *)(uintptr_t)fd;
+	platform_device_register(dev);
+
+	return 0;
 }
-device_initcall(ramfb_driver_init);
+late_initcall(ramfb_driver_init);
 
 MODULE_AUTHOR("Adrian Negreanu <adrian.negreanu at nxp.com>");
 MODULE_DESCRIPTION("QEMU RamFB driver");
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:19 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:19 +0100
Subject: [PATCH 02/11] firmware: qemu_fw_cfg: drop duplicate definitions
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Message-ID: <20250313101728.3546902-3-a.fatoum@pengutronix.de>

These same defines are already in <uapi/linux/qemu_fw_cfg.h>, so let's
not duplicate them in the driver.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/firmware/qemu_fw_cfg.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
index 4a48ad91520b..26770da908ce 100644
--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -28,19 +28,6 @@
 # define FW_CFG_DMA_OFF 0x10
 #endif
 
-/* fw_cfg DMA commands */
-#define FW_CFG_DMA_CTL_ERROR   0x01
-#define FW_CFG_DMA_CTL_READ    0x02
-#define FW_CFG_DMA_CTL_SKIP    0x04
-#define FW_CFG_DMA_CTL_SELECT  0x08
-#define FW_CFG_DMA_CTL_WRITE   0x10
-
-struct fw_cfg_dma {
-	__be32 control;
-	__be32 length;
-	__be64 address;
-} __packed;
-
 /* fw_cfg device i/o register addresses */
 struct fw_cfg {
 	struct resource *iores;
@@ -51,7 +38,7 @@ struct fw_cfg {
 	loff_t next_read_offset;
 	u32 sel;
 	bool is_mmio;
-	struct fw_cfg_dma __iomem *acc_virt;
+	struct fw_cfg_dma_access __iomem *acc_virt;
 	dma_addr_t acc_dma;
 };
 
@@ -172,7 +159,7 @@ static ssize_t fw_cfg_write(struct cdev *cdev, const void *buf, size_t count,
 {
 	struct fw_cfg *fw_cfg = to_fw_cfg(cdev);
 	struct device *dev = cdev->dev;
-	struct fw_cfg_dma __iomem *acc = fw_cfg->acc_virt;
+	struct fw_cfg_dma_access __iomem *acc = fw_cfg->acc_virt;
 	void *dma_buf;
 	dma_addr_t mapping;
 	int ret = 0;
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:25 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:25 +0100
Subject: [PATCH 08/11] libfile: give copy_file a flags parameter
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Message-ID: <20250313101728.3546902-9-a.fatoum@pengutronix.de>

In preparation for adding an additional flag input to copy_file, let's
turn the current copy_file verbose parameter in a bitmask.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 commands/cp.c     |  8 ++++----
 commands/tftp.c   |  2 +-
 common/fastboot.c |  2 +-
 include/libfile.h |  5 ++++-
 lib/libfile.c     | 12 +++++++-----
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/commands/cp.c b/commands/cp.c
index 71448f9aff6f..e2f91123ca92 100644
--- a/commands/cp.c
+++ b/commands/cp.c
@@ -25,13 +25,13 @@ static int do_cp(int argc, char *argv[])
 	int last_is_dir = 0;
 	int i;
 	int opt;
-	int verbose = 0, recursive = 0;
+	int flags = 0, recursive = 0;
 	int argc_min;
 
 	while ((opt = getopt(argc, argv, "vr")) > 0) {
 		switch (opt) {
 		case 'v':
-			verbose = 1;
+			flags |= COPY_FILE_VERBOSE;
 			break;
 		case 'r':
 			recursive = 1;
@@ -68,9 +68,9 @@ static int do_cp(int argc, char *argv[])
 		if (recursive)
 			ret = copy_recursive(argv[i], dst);
 		else if (last_is_dir)
-			ret = copy_file(argv[i], dst, verbose);
+			ret = copy_file(argv[i], dst, flags);
 		else
-			ret = copy_file(argv[i], argv[argc - 1], verbose);
+			ret = copy_file(argv[i], argv[argc - 1], flags);
 
 		free(dst);
 		if (ret)
diff --git a/commands/tftp.c b/commands/tftp.c
index 5e8d8d17761d..f17b589ee62d 100644
--- a/commands/tftp.c
+++ b/commands/tftp.c
@@ -81,7 +81,7 @@ static int do_tftpb(int argc, char *argv[])
 
 	debug("%s: %s -> %s\n", __func__, source, dest);
 
-	ret = copy_file(source, dest, 1);
+	ret = copy_file(source, dest, COPY_FILE_VERBOSE);
 
 	umount(TFTP_MOUNT_PATH);
 
diff --git a/common/fastboot.c b/common/fastboot.c
index 60bef0ec776b..9088b988cb6c 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -741,7 +741,7 @@ static void cb_flash(struct fastboot *fb, const char *cmd)
 	}
 
 copy:
-	ret = copy_file(fb->tempname, filename, 1);
+	ret = copy_file(fb->tempname, filename, COPY_FILE_VERBOSE);
 	if (ret)
 		fastboot_tx_print(fb, FASTBOOT_MSG_FAIL,
 				  "write partition: %s", strerror(-ret));
diff --git a/include/libfile.h b/include/libfile.h
index bf775b022dc4..a9bef5065d08 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -3,6 +3,7 @@
 #define __LIBFILE_H
 
 #include <linux/types.h>
+#include <linux/bits.h>
 
 struct resource;
 
@@ -26,7 +27,9 @@ int read_file_2(const char *filename, size_t *size, void **outbuf,
 int write_file(const char *filename, const void *buf, size_t size);
 int write_file_flash(const char *filename, const void *buf, size_t size);
 
-int copy_file(const char *src, const char *dst, int verbose);
+#define COPY_FILE_VERBOSE	BIT(0)
+
+int copy_file(const char *src, const char *dst, unsigned flags);
 
 int copy_recursive(const char *src, const char *dst);
 
diff --git a/lib/libfile.c b/lib/libfile.c
index 80d4591dd6e5..76a091878ebb 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -432,11 +432,13 @@ EXPORT_SYMBOL(write_file_flash);
  * copy_file - Copy a file
  * @src:	The source filename
  * @dst:	The destination filename
- * @verbose:	if true, show a progression bar
+ * @flags:	A bitmask of COPY_FILE_* flags. Possible values:
+ *
+ *                COPY_FILE_VERBOSE: show a progression bar
  *
  * Return: 0 for success or negative error code
  */
-int copy_file(const char *src, const char *dst, int verbose)
+int copy_file(const char *src, const char *dst, unsigned flags)
 {
 	char *rw_buf = NULL;
 	int srcfd = 0, dstfd = 0;
@@ -488,7 +490,7 @@ int copy_file(const char *src, const char *dst, int verbose)
 		}
 	}
 
-	if (verbose)
+	if (flags & COPY_FILE_VERBOSE)
 		init_progression_bar(srcstat.st_size);
 
 	while (1) {
@@ -509,7 +511,7 @@ int copy_file(const char *src, const char *dst, int verbose)
 
 		total += r;
 
-		if (verbose) {
+		if (flags & COPY_FILE_VERBOSE) {
 			if (srcstat.st_size && srcstat.st_size != FILESIZE_MAX)
 				show_progress(total);
 			else
@@ -519,7 +521,7 @@ int copy_file(const char *src, const char *dst, int verbose)
 
 	ret = 0;
 out:
-	if (verbose)
+	if (flags & COPY_FILE_VERBOSE)
 		putchar('\n');
 
 	free(rw_buf);
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:18 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:18 +0100
Subject: [PATCH 01/11] video: ramfb: fix frame buffer screen size
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Message-ID: <20250313101728.3546902-2-a.fatoum@pengutronix.de>

struct fb_info::screen_size is in units of bytes, but we allocated 8
times as much so far, because of bits vs bytes confusion.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/video/ramfb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/ramfb.c b/drivers/video/ramfb.c
index 45b75e890c59..5b03d8a9c821 100644
--- a/drivers/video/ramfb.c
+++ b/drivers/video/ramfb.c
@@ -86,7 +86,7 @@ static int ramfb_activate_var(struct fb_info *fbi)
 		dma_free_coherent(DMA_DEVICE_BROKEN,
 				  fbi->screen_base, ramfb->screen_dma, fbi->screen_size);
 
-	fbi->screen_size = fbi->xres * fbi->yres * fbi->bits_per_pixel;
+	fbi->screen_size = fbi->xres * fbi->yres * fbi->bits_per_pixel / BITS_PER_BYTE;
 	fbi->screen_base = dma_alloc_coherent(DMA_DEVICE_BROKEN,
 					      fbi->screen_size, &ramfb->screen_dma);
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:20 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:20 +0100
Subject: [PATCH 03/11] firmware: qemu_fw_cfg: add support for seeking
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Message-ID: <20250313101728.3546902-4-a.fatoum@pengutronix.de>

Seeks were so far not possible and resulted in an -EINVAL if the accesses
weren't consecutive.

Implement it properly using FW_CFG_DMA_CTL_SKIP.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/firmware/qemu_fw_cfg.c | 44 ++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
index 26770da908ce..33c1617a61e4 100644
--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -70,6 +70,7 @@ static int fw_cfg_ioctl(struct cdev *cdev, unsigned int request, void *buf)
 	switch (request) {
 	case FW_CFG_SELECT:
 		fw_cfg->sel = *(u16 *)buf;
+		fw_cfg->next_read_offset = 0;
 		break;
 	default:
 		ret = -ENOTTY;
@@ -87,10 +88,8 @@ static int fw_cfg_ioctl(struct cdev *cdev, unsigned int request, void *buf)
 	while (*remaining >= sizeof(type)) {				\
 		val = __raw_read##type((fw_cfg)->reg_data);		\
 		*remaining -= sizeof(type);				\
-		if (*address) {						\
-			put_unaligned(val, (type *)*address);		\
-			*address += sizeof(type);			\
-		}							\
+		put_unaligned(val, (type *)*address);		\
+		*address += sizeof(type);			\
 	}								\
 } while(0)
 
@@ -123,11 +122,27 @@ static void fw_cfg_data_read(struct fw_cfg *fw_cfg, void *address, size_t remain
 	fw_cfg_data_read_sized(fw_cfg, &remaining, &address, u8);
 }
 
+static void fw_cfg_do_dma(struct fw_cfg *fw_cfg, dma_addr_t address,
+			  u32 count, u32 control)
+{
+	struct fw_cfg_dma_access __iomem *acc = fw_cfg->acc_virt;
+
+	acc->address = cpu_to_be64(address);
+	acc->length = cpu_to_be32(count);
+	acc->control = cpu_to_be32(control);
+
+	iowrite64be(fw_cfg->acc_dma, fw_cfg->reg_dma);
+
+	while (ioread32be(&acc->control) & ~FW_CFG_DMA_CTL_ERROR)
+		;
+}
+
 static ssize_t fw_cfg_read(struct cdev *cdev, void *buf, size_t count,
 			   loff_t pos, unsigned long flags)
 {
 	struct fw_cfg *fw_cfg = to_fw_cfg(cdev);
 	unsigned rdsize = FIELD_GET(O_RWSIZE_MASK, flags);
+	u32 selector = FW_CFG_DMA_CTL_SELECT | fw_cfg->sel << 16;
 
 	if (!pos || pos != fw_cfg->next_read_offset) {
 		fw_cfg_select(fw_cfg);
@@ -145,8 +160,9 @@ static ssize_t fw_cfg_read(struct cdev *cdev, void *buf, size_t count,
 			rdsize = 1;
 	}
 
-	while (pos-- > fw_cfg->next_read_offset)
-		fw_cfg_data_read(fw_cfg, NULL, count, rdsize);
+	if (pos != fw_cfg->next_read_offset)
+		fw_cfg_do_dma(fw_cfg, DMA_ERROR_CODE, pos,
+			      FW_CFG_DMA_CTL_SKIP | selector);
 
 	fw_cfg_data_read(fw_cfg, buf, count, rdsize);
 
@@ -159,14 +175,10 @@ static ssize_t fw_cfg_write(struct cdev *cdev, const void *buf, size_t count,
 {
 	struct fw_cfg *fw_cfg = to_fw_cfg(cdev);
 	struct device *dev = cdev->dev;
-	struct fw_cfg_dma_access __iomem *acc = fw_cfg->acc_virt;
 	void *dma_buf;
 	dma_addr_t mapping;
 	int ret = 0;
 
-	if (pos != 0)
-		return -EINVAL;
-
 	dma_buf = dma_alloc(count);
 	if (!dma_buf)
 		return -ENOMEM;
@@ -181,15 +193,11 @@ static ssize_t fw_cfg_write(struct cdev *cdev, const void *buf, size_t count,
 
 	fw_cfg->next_read_offset = 0;
 
-	acc->address = cpu_to_be64(mapping);
-	acc->length = cpu_to_be32(count);
-	acc->control = cpu_to_be32(FW_CFG_DMA_CTL_WRITE |
-				   FW_CFG_DMA_CTL_SELECT | fw_cfg->sel << 16);
+	fw_cfg_do_dma(fw_cfg, DMA_ERROR_CODE, pos, FW_CFG_DMA_CTL_SKIP |
+		      FW_CFG_DMA_CTL_SELECT | fw_cfg->sel << 16);
 
-	iowrite64be(fw_cfg->acc_dma, fw_cfg->reg_dma);
-
-	while (ioread32be(&acc->control) & ~FW_CFG_DMA_CTL_ERROR)
-		;
+	fw_cfg_do_dma(fw_cfg, mapping, count, FW_CFG_DMA_CTL_WRITE |
+		      FW_CFG_DMA_CTL_SELECT | fw_cfg->sel << 16);
 
 	dma_unmap_single(dev, mapping, count, DMA_FROM_DEVICE);
 free_buf:
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:26 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:26 +0100
Subject: [PATCH 09/11] libfile: pass copy_file flags through copy_recursive
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Message-ID: <20250313101728.3546902-10-a.fatoum@pengutronix.de>

copy_recursive calls copy_file internally, so it makes sense that it
should take the same flags that copy_file already takes.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 commands/cp.c         |  2 +-
 commands/defaultenv.c |  2 +-
 include/libfile.h     |  2 +-
 lib/libfile.c         | 14 ++++++++++++--
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/commands/cp.c b/commands/cp.c
index e2f91123ca92..5b8d976c3cfe 100644
--- a/commands/cp.c
+++ b/commands/cp.c
@@ -66,7 +66,7 @@ static int do_cp(int argc, char *argv[])
 		dst = concat_path_file(argv[argc - 1], posix_basename(argv[i]));
 
 		if (recursive)
-			ret = copy_recursive(argv[i], dst);
+			ret = copy_recursive(argv[i], dst, flags);
 		else if (last_is_dir)
 			ret = copy_file(argv[i], dst, flags);
 		else
diff --git a/commands/defaultenv.c b/commands/defaultenv.c
index c13d9aaac7c0..3d118f20a650 100644
--- a/commands/defaultenv.c
+++ b/commands/defaultenv.c
@@ -54,7 +54,7 @@ static int do_defaultenv(int argc, char *argv[])
 	if (scrub)
 		unlink_recursive(to, NULL);
 
-	ret = copy_recursive(from, to);
+	ret = copy_recursive(from, to, 0);
 	free(from);
 	free(to);
 
diff --git a/include/libfile.h b/include/libfile.h
index a9bef5065d08..00a7f86a1477 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -31,7 +31,7 @@ int write_file_flash(const char *filename, const void *buf, size_t size);
 
 int copy_file(const char *src, const char *dst, unsigned flags);
 
-int copy_recursive(const char *src, const char *dst);
+int copy_recursive(const char *src, const char *dst, unsigned flags);
 
 int compare_file(const char *f1, const char *f2);
 
diff --git a/lib/libfile.c b/lib/libfile.c
index 76a091878ebb..aaade34a4c34 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -534,7 +534,17 @@ int copy_file(const char *src, const char *dst, unsigned flags)
 }
 EXPORT_SYMBOL(copy_file);
 
-int copy_recursive(const char *src, const char *dst)
+/**
+ * copy_recursive - Copy files recursively
+ * @src:	The source filename or directory
+ * @dst:	The destination filename or directory
+ * @flags:	A bitmask of COPY_FILE_* flags. Possible values:
+ *
+ *                COPY_FILE_VERBOSE: show a progression bar
+ *
+ * Return: 0 for success or negative error code
+ */
+int copy_recursive(const char *src, const char *dst, unsigned flags)
 {
 	struct stat s;
 	DIR *dir;
@@ -563,7 +573,7 @@ int copy_recursive(const char *src, const char *dst)
 
 		from = basprintf("%s/%s", src, d->d_name);
 		to = basprintf("%s/%s", dst, d->d_name);
-		ret = copy_recursive(from, to);
+		ret = copy_recursive(from, to, flags);
 		if (ret)
 			break;
 		free(from);
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:22 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:22 +0100
Subject: [PATCH 05/11] fs: add qemu_fw_cfg file system
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Message-ID: <20250313101728.3546902-6-a.fatoum@pengutronix.de>

The character device we currently have is cumbersome to use.
The Linux way to access it at /sys/firmware/qemu_fw_cfg
is much nicer to use, so add support for a similar FS to barebox.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 fs/Kconfig       |   7 +
 fs/Makefile      |   1 +
 fs/qemu_fw_cfg.c | 397 +++++++++++++++++++++++++++++++++++++++++++++++
 include/string.h |   5 +
 4 files changed, 410 insertions(+)
 create mode 100644 fs/qemu_fw_cfg.c

diff --git a/fs/Kconfig b/fs/Kconfig
index 9118d1114daa..01ac3040438d 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -156,4 +156,11 @@ config FS_UBOOTVARFS
 	  This filesystem driver provides access to U-Boot environment
 	  variables.
 
+config FS_QEMU_FW_CFG
+	bool "QEMU FW CFG interface"
+	select QEMU_FW_CFG
+	help
+	  This filesystem driver provides access to the QEMU FW CFG conduit
+	  as a file system.
+
 endmenu
diff --git a/fs/Makefile b/fs/Makefile
index 6160ef4e1a0b..20a26a16c5ab 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_FS_PSTORE) += pstore/
 obj-$(CONFIG_FS_SQUASHFS) += squashfs/
 obj-$(CONFIG_FS_RATP)	+= ratpfs.o
 obj-$(CONFIG_FS_UBOOTVARFS) += ubootvarfs.o
+obj-$(CONFIG_FS_QEMU_FW_CFG) += qemu_fw_cfg.o
diff --git a/fs/qemu_fw_cfg.c b/fs/qemu_fw_cfg.c
new file mode 100644
index 000000000000..7f7350e67e64
--- /dev/null
+++ b/fs/qemu_fw_cfg.c
@@ -0,0 +1,397 @@
+// SPDX-License-Identifier: GPL-2.0+
+// SPDX-FileCopyrightText: 2024 Ahmad Fatoum
+
+#define pr_fmt(fmt) "qemu_fw_cfg-fs: " fmt
+
+#include <common.h>
+#include <driver.h>
+#include <init.h>
+#include <malloc.h>
+#include <fs.h>
+#include <string.h>
+#include <libfile.h>
+#include <errno.h>
+#include <linux/stat.h>
+#include <xfuncs.h>
+#include <fcntl.h>
+#include <linux/qemu_fw_cfg.h>
+#include <wchar.h>
+#include <linux/err.h>
+#include <linux/ctype.h>
+
+struct fw_cfg_fs_inode {
+	struct inode inode;
+	const char *name;
+	struct list_head sibling;
+	struct list_head children;
+	char *buf;
+};
+
+struct fw_cfg_fs_data {
+	int fd;
+	int next_ino;
+};
+
+static struct fw_cfg_fs_inode *inode_to_node(struct inode *inode)
+{
+	return container_of(inode, struct fw_cfg_fs_inode, inode);
+}
+
+static const char *fw_cfg_fs_get_link(struct dentry *dentry, struct inode *inode)
+{
+	return inode->i_link;
+}
+
+static const struct inode_operations fw_cfg_fs_file_inode_operations;
+static const struct inode_operations fw_cfg_fs_dir_inode_operations;
+static const struct inode_operations fw_cfg_fs_symlink_inode_operations = {
+	.get_link = fw_cfg_fs_get_link,
+};
+static const struct file_operations fw_cfg_fs_file_operations;
+static const struct file_operations fw_cfg_fs_dir_operations;
+
+static struct inode *fw_cfg_fs_get_inode(struct inode *iparent,
+					 const char *name)
+{
+	struct fw_cfg_fs_inode *parent = inode_to_node(iparent);
+
+	while (true) {
+		struct fw_cfg_fs_inode *node;
+		char *slash;
+
+		slash = strchrnul(name, '/');
+
+		list_for_each_entry(node, &parent->children, sibling) {
+			size_t namelen = slash - name;
+			if (!strncmp_ptr(name, node->name, namelen) &&
+			    !node->name[namelen]) {
+				if (*slash == '\0')
+					return &node->inode;
+				parent = node;
+				goto next;
+			}
+		}
+
+		return NULL;
+
+next:
+		name = slash + 1;
+	}
+}
+
+static struct dentry *fw_cfg_fs_lookup(struct inode *dir,
+				       struct dentry *dentry,
+				       unsigned int flags)
+{
+	struct inode *inode;
+
+	inode = fw_cfg_fs_get_inode(dir, dentry->name);
+	if (IS_ERR_OR_NULL(inode))
+		return ERR_CAST(inode);
+
+	d_add(dentry, inode);
+
+	return NULL;
+}
+
+static const struct inode_operations fw_cfg_fs_dir_inode_operations = {
+	.lookup = fw_cfg_fs_lookup,
+};
+
+static struct fw_cfg_fs_inode *fw_cfg_fs_node_new(struct super_block *sb,
+						  struct fw_cfg_fs_inode *parent,
+						  const char *name,
+						  ulong select,
+						  umode_t mode)
+{
+	struct fw_cfg_fs_inode *node;
+	struct inode *inode;
+
+
+	inode = new_inode(sb);
+	if (!inode)
+		return NULL;
+
+	inode->i_ino = select;
+	inode->i_mode = 0777 | mode;
+	node = inode_to_node(inode);
+	node->name = strdup(name);
+
+	switch (inode->i_mode & S_IFMT) {
+	default:
+		return ERR_PTR(-EINVAL);
+	case S_IFREG:
+		inode->i_op = &fw_cfg_fs_file_inode_operations;
+		inode->i_fop = &fw_cfg_fs_file_operations;
+		break;
+	case S_IFDIR:
+		inode->i_op = &fw_cfg_fs_dir_inode_operations;
+		inode->i_fop = &fw_cfg_fs_dir_operations;
+		inc_nlink(inode);
+		break;
+	case S_IFLNK:
+		inode->i_op = &fw_cfg_fs_symlink_inode_operations;
+		break;
+	}
+
+	if (parent)
+		list_add_tail(&node->sibling, &parent->children);
+
+	return node;
+}
+
+#define fw_cfg_fs_node_sprintf(node, args...)		\
+do {							\
+	node->inode.i_size = asprintf(&node->buf, args);\
+} while (0)
+
+static int fw_cfg_fs_parse(struct super_block *sb)
+{
+	struct fw_cfg_fs_data *data = sb->s_fs_info;
+	struct fw_cfg_fs_inode *root, *by_key, *by_name;
+	__be32 count;
+	int i, ret;
+
+	ioctl(data->fd, FW_CFG_SELECT, &(u16) { FW_CFG_FILE_DIR });
+
+	lseek(data->fd, 0, SEEK_SET);
+
+	ret = read(data->fd, &count, sizeof(count));
+	if (ret < 0)
+		return ret;
+
+	root = inode_to_node(d_inode(sb->s_root));
+
+	by_key = fw_cfg_fs_node_new(sb, root, "by_key", data->next_ino++, S_IFDIR);
+	if (IS_ERR(by_key))
+		return PTR_ERR(by_key);
+
+	by_name = fw_cfg_fs_node_new(sb, root, "by_name", data->next_ino++, S_IFDIR);
+	if (IS_ERR(by_name))
+		return PTR_ERR(by_name);
+
+	for (i = 0; i < be32_to_cpu(count); i++) {
+		struct fw_cfg_fs_inode *parent, *dir, *node;
+		struct fw_cfg_file qfile;
+		char buf[sizeof("65536")];
+		char *context, *name;
+		int ndirs = 0;
+
+		ret = read(data->fd, &qfile, sizeof(qfile));
+		if (ret < 0)
+			break;
+
+		snprintf(buf, sizeof(buf), "%u", be16_to_cpu(qfile.select));
+
+		dir = fw_cfg_fs_node_new(sb, by_key, buf, data->next_ino++, S_IFDIR);
+		if (IS_ERR(dir))
+			return PTR_ERR(dir);
+
+		node = fw_cfg_fs_node_new(sb, dir, "name", data->next_ino++, S_IFREG);
+		fw_cfg_fs_node_sprintf(node, "%s", qfile.name);
+
+		node = fw_cfg_fs_node_new(sb, dir, "size", data->next_ino++, S_IFREG);
+		fw_cfg_fs_node_sprintf(node, "%u", be32_to_cpu(qfile.size));
+
+		node = fw_cfg_fs_node_new(sb, dir, "key", data->next_ino++, S_IFREG);
+		fw_cfg_fs_node_sprintf(node, "%u", be16_to_cpu(qfile.select));
+
+		node = fw_cfg_fs_node_new(sb, dir, "raw", be16_to_cpu(qfile.select), S_IFREG);
+		node->inode.i_size = be32_to_cpu(qfile.size);
+
+		for (const char *s = qfile.name; *s; s++) {
+			if (*s == '/')
+				ndirs++;
+		}
+
+		context = qfile.name;
+		parent = by_name;
+
+		while ((name = strsep(&context, "/"))) {
+			struct fw_cfg_fs_inode *node;
+			mode_t mode;
+
+			list_for_each_entry(node, &parent->children, sibling) {
+				if (streq_ptr(name, node->name)) {
+					parent = node;
+					goto next;
+				}
+			}
+
+			mode = context && *context ? S_IFDIR : S_IFLNK;
+			parent = fw_cfg_fs_node_new(sb, parent, name, data->next_ino++,
+						    mode);
+			if (IS_ERR(parent))
+				break;
+			if (mode == S_IFLNK) {
+				char *s	= basprintf("%*sby_key/%s/raw",
+						    (ndirs + 1) * 3, "", buf);
+
+				parent->inode.i_link = s;
+				while (*s == ' ')
+					s = mempcpy(s, "../", 3);
+			}
+next:
+			;
+		}
+	}
+
+	return ret >= 0 ? 0 : ret;
+}
+
+static inline unsigned char dt_type(struct inode *inode)
+{
+	return (inode->i_mode >> 12) & 15;
+}
+
+static int fw_cfg_fs_dcache_readdir(struct file *file, struct dir_context *ctx)
+{
+	struct dentry *dentry = file->f_path.dentry;
+	struct inode *iparent = d_inode(dentry);
+	struct fw_cfg_fs_inode *node, *parent = inode_to_node(iparent);
+
+	dir_emit_dots(file, ctx);
+
+	list_for_each_entry(node, &parent->children, sibling) {
+		dir_emit(ctx, node->name, strlen(node->name),
+			 node->inode.i_ino, dt_type(&node->inode));
+	}
+
+	return 0;
+}
+
+static const struct file_operations fw_cfg_fs_dir_operations = {
+	.iterate = fw_cfg_fs_dcache_readdir,
+};
+
+static struct inode *fw_cfg_fs_alloc_inode(struct super_block *sb)
+{
+	struct fw_cfg_fs_inode *node;
+
+	node = xzalloc(sizeof(*node));
+
+	INIT_LIST_HEAD(&node->children);
+	INIT_LIST_HEAD(&node->sibling);
+
+	return &node->inode;
+}
+
+static void fw_cfg_fs_destroy_inode(struct inode *inode)
+{
+	struct fw_cfg_fs_inode *node = inode_to_node(inode);
+
+	list_del(&node->children);
+	list_del(&node->sibling);
+	free(node->buf);
+	free(node);
+}
+
+static const struct super_operations fw_cfg_fs_ops = {
+	.alloc_inode = fw_cfg_fs_alloc_inode,
+	.destroy_inode = fw_cfg_fs_destroy_inode,
+};
+
+static int fw_cfg_fs_io(struct device *dev, struct file *f, void *buf,
+			 size_t insize, bool read)
+{
+	struct inode *inode = f->f_inode;
+	struct fw_cfg_fs_inode *node = inode_to_node(inode);
+	struct fw_cfg_fs_data *data = dev->priv;
+	int fd = data->fd;
+
+	if (node->buf) {
+		if (read)
+			memcpy(buf, node->buf + f->f_pos, insize);
+		else
+			memcpy(node->buf + f->f_pos, buf, insize);
+		return insize;
+	}
+
+	ioctl(fd, FW_CFG_SELECT, &(u16) { inode->i_ino });
+
+	if (read)
+		return pread(fd, buf, insize, f->f_pos);
+	else
+		return pwrite(fd, buf, insize, f->f_pos);
+}
+
+static int fw_cfg_fs_read(struct device *dev, struct file *f, void *buf,
+			   size_t insize)
+{
+	return fw_cfg_fs_io(dev, f, buf, insize, true);
+}
+
+static int fw_cfg_fs_write(struct device *dev, struct file *f, const void *buf,
+			    size_t insize)
+{
+	return fw_cfg_fs_io(dev, f, (void *)buf, insize, false);
+}
+
+static int fw_cfg_fw_truncate(struct device *dev, struct file *f, loff_t size)
+{
+	return 0;
+}
+
+static int fw_cfg_fs_probe(struct device *dev)
+{
+	struct fw_cfg_fs_inode *node;
+	struct fw_cfg_fs_data *data = xzalloc(sizeof(*data));
+	struct fs_device *fsdev = dev_to_fs_device(dev);
+	struct super_block *sb = &fsdev->sb;
+	int ret;
+
+	dev->priv = data;
+
+	data->next_ino = U16_MAX + 1;
+	data->fd = open(fsdev->backingstore, O_RDWR);
+	if (data->fd < 0) {
+		ret = -errno;
+		goto free_data;
+	}
+
+	sb->s_op = &fw_cfg_fs_ops;
+	node = fw_cfg_fs_node_new(sb, NULL, NULL, data->next_ino++, S_IFDIR);
+	if (IS_ERR(node))
+		return PTR_ERR(node);
+	sb->s_root = d_make_root(&node->inode);
+	sb->s_fs_info = data;
+
+
+	/*
+	 * We don't use cdev * directly, but this is needed for
+	 * cdev_get_mount_path() to work right
+	 */
+	fsdev->cdev = cdev_by_name(devpath_to_name(fsdev->backingstore));
+
+	return fw_cfg_fs_parse(sb);
+free_data:
+	free(data);
+	return ret;
+}
+
+static void fw_cfg_fs_remove(struct device *dev)
+{
+	struct fw_cfg_fs_data *data = dev->priv;
+
+	flush(data->fd);
+	close(data->fd);
+	free(data);
+}
+
+static struct fs_driver fw_cfg_fs_driver = {
+	.read = fw_cfg_fs_read,
+	.write = fw_cfg_fs_write,
+	.truncate = fw_cfg_fw_truncate,
+	.type = filetype_qemu_fw_cfg,
+	.drv = {
+		.probe = fw_cfg_fs_probe,
+		.remove = fw_cfg_fs_remove,
+		.name = "qemu_fw_cfg-fs",
+	}
+};
+
+static int qemu_fw_cfg_fs_init(void)
+{
+	return register_fs_driver(&fw_cfg_fs_driver);
+}
+coredevice_initcall(qemu_fw_cfg_fs_init);
diff --git a/include/string.h b/include/string.h
index 986ccd83dd73..782fb9425a95 100644
--- a/include/string.h
+++ b/include/string.h
@@ -30,6 +30,11 @@ static inline int strcmp_ptr(const char *a, const char *b)
 	return a && b ? strcmp(a, b) : compare3(a, b);
 }
 
+static inline int strncmp_ptr(const char *a, const char *b, size_t n)
+{
+	return a && b ? strncmp(a, b, n) : compare3(a, b);
+}
+
 static inline bool streq_ptr(const char *a, const char *b)
 {
 	return strcmp_ptr(a, b) == 0;
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:28 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:28 +0100
Subject: [PATCH 11/11] fs: qemu_fw_cfg: support populating environment via QEMU fw_cfg
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Message-ID: <20250313101728.3546902-12-a.fatoum@pengutronix.de>

QEMU fw_cfg allows passing through user defined key/values, which is
more powerful than what we currently have with sandbox as it allows
passing arbitrary files without having to mess with block devices and
their alignment.

All the added files are already available in the QEMU fw_cfg file system,
but for added convenience, let's map all files under a opt/org.barebox.env
directory to the environment of the running barebox image, thereby
allowing configuring barebox easily from the outside, e.g.

pytest --env nv/boot.default=fit --env boot/fit=@boot.sh

Will boot, after coundown, whatever is in the boot.sh script in the
working directory of QEMU.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 conftest.py             | 22 ++++++++++++++++++++++
 defaultenv/defaultenv.c | 22 ++++++++++++++++++++++
 fs/qemu_fw_cfg.c        |  9 ++++++++-
 include/envfs.h         |  5 +++++
 4 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/conftest.py b/conftest.py
index 941eddcb72dd..5dfefef24638 100644
--- a/conftest.py
+++ b/conftest.py
@@ -39,6 +39,9 @@ def pytest_configure(config):
         os.environ['LG_BUILDDIR'] = os.path.realpath(os.environ['LG_BUILDDIR'])
 
 def pytest_addoption(parser):
+    def assignment(arg):
+            return arg.split('=', 1)
+
     parser.addoption('--interactive', action='store_const', const='qemu_interactive',
         dest='lg_initial_state',
         help=('(for debugging) skip tests and just start Qemu interactively'))
@@ -55,6 +58,9 @@ def pytest_addoption(parser):
     parser.addoption('--blk', action='append', dest='qemu_block',
         default=[], metavar="FILE",
         help=('Pass block device to emulated barebox. Can be specified more than once'))
+    parser.addoption('--env', action='append', dest='qemu_fw_cfg',
+        default=[], metavar="[envpath=]content | [envpath=]@filepath", type=assignment,
+        help=('Pass barebox environment files to barebox. Can be specified more than once'))
     parser.addoption('--qemu', dest='qemu_arg', nargs=argparse.REMAINDER, default=[],
         help=('Pass all remaining options to QEMU as is'))
 
@@ -109,6 +115,22 @@ def strategy(request, target, pytestconfig):
         else:
             pytest.exit("--blk unsupported for target\n", 1)
 
+    for i, fw_cfg in enumerate(pytestconfig.option.qemu_fw_cfg):
+        if virtio:
+            value = fw_cfg.pop()
+            envpath = fw_cfg.pop() if fw_cfg else f"data/fw_cfg{i}"
+
+            if value.startswith('@'):
+                source = f"file='{value[1:]}'"
+            else:
+                source = f"string='{value}'"
+
+            strategy.append_qemu_args(
+                '-fw_cfg', f'name=opt/org.barebox.env/{envpath},{source}'
+            )
+        else:
+            pytest.exit("--env unsupported for target\n", 1)
+
     for arg in pytestconfig.option.qemu_arg:
         strategy.append_qemu_args(arg)
 
diff --git a/defaultenv/defaultenv.c b/defaultenv/defaultenv.c
index 055475eb4756..3585660fbc09 100644
--- a/defaultenv/defaultenv.c
+++ b/defaultenv/defaultenv.c
@@ -18,6 +18,7 @@
 #include <uncompress.h>
 #include <malloc.h>
 #include <init.h>
+#include <libfile.h>
 #include <asm/unaligned.h>
 #include "barebox_default_env.h"
 
@@ -25,6 +26,7 @@ static LIST_HEAD(defaultenv_list);
 
 struct defaultenv {
 	struct list_head list;
+	const char *srcdir;
 	const char *name;
 	void *buf;
 	size_t size;
@@ -93,6 +95,19 @@ void defaultenv_append(void *buf, unsigned int size, const char *name)
 	list_add_tail(&df->list, &defaultenv_list);
 }
 
+void defaultenv_append_runtime_directory(const char *srcdir)
+{
+	struct defaultenv *df;
+
+	defaultenv_add_base();
+
+	df = xzalloc(sizeof(*df));
+	df->srcdir = srcdir;
+	df->name = srcdir;
+
+	list_add_tail(&df->list, &defaultenv_list);
+}
+
 static int defaultenv_load_one(struct defaultenv *df, const char *dir,
 		unsigned flags)
 {
@@ -104,6 +119,13 @@ static int defaultenv_load_one(struct defaultenv *df, const char *dir,
 
 	pr_debug("loading %s\n", df->name);
 
+	if (df->srcdir) {
+		int cpflags = 0;
+		if (flags & ENV_FLAG_NO_OVERWRITE)
+			cpflags |= COPY_FILE_NO_OVERWRITE;
+		return copy_recursive(df->srcdir, dir, cpflags);
+	}
+
 	if (!IS_ENABLED(CONFIG_DEFAULT_COMPRESSION_NONE) &&
 			ft != filetype_barebox_env) {
 		size = get_unaligned_le32(df->buf + df->size - 4);
diff --git a/fs/qemu_fw_cfg.c b/fs/qemu_fw_cfg.c
index 7f7350e67e64..ef2a1008ee5d 100644
--- a/fs/qemu_fw_cfg.c
+++ b/fs/qemu_fw_cfg.c
@@ -13,6 +13,7 @@
 #include <errno.h>
 #include <linux/stat.h>
 #include <xfuncs.h>
+#include <envfs.h>
 #include <fcntl.h>
 #include <linux/qemu_fw_cfg.h>
 #include <wchar.h>
@@ -363,7 +364,13 @@ static int fw_cfg_fs_probe(struct device *dev)
 	 */
 	fsdev->cdev = cdev_by_name(devpath_to_name(fsdev->backingstore));
 
-	return fw_cfg_fs_parse(sb);
+	ret = fw_cfg_fs_parse(sb);
+	if (ret)
+		goto free_data;
+
+	defaultenv_append_runtime_directory("/mnt/fw_cfg/by_name/opt/org.barebox.env");
+
+	return 0;
 free_data:
 	free(data);
 	return ret;
diff --git a/include/envfs.h b/include/envfs.h
index a6614c0a15ee..1a194c8bff2f 100644
--- a/include/envfs.h
+++ b/include/envfs.h
@@ -130,12 +130,17 @@ static inline const char *of_env_get_device_alias_by_path(const char *of_path)
 
 #ifdef CONFIG_DEFAULT_ENVIRONMENT
 void defaultenv_append(void *buf, unsigned int size, const char *name);
+void defaultenv_append_runtime_directory(const char *srcdir);
 int defaultenv_load(const char *dir, unsigned flags);
 #else
 static inline void defaultenv_append(void *buf, unsigned int size, const char *name)
 {
 }
 
+static inline void defaultenv_append_runtime_directory(const char *srcdir)
+{
+}
+
 static inline int defaultenv_load(const char *dir, unsigned flags)
 {
 	return -ENOSYS;
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 03:17:27 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 11:17:27 +0100
Subject: [PATCH 10/11] libfile: add support for not clobbering files in copy_file
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Message-ID: <20250313101728.3546902-11-a.fatoum@pengutronix.de>

copy_file will always overwrite overwrite an existing file and so will
copy_recursive. This is not always the intended behavior, so add a flag
to control this.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 commands/Kconfig  |  4 +++-
 commands/cp.c     |  8 ++++++--
 include/libfile.h |  1 +
 lib/libfile.c     | 17 ++++++++++++-----
 4 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index fe459fa862f5..0d60566ba9c6 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -921,11 +921,13 @@ config CMD_CP
 	help
 	  Copy files
 
-	  Usage: cp [-v] SRC DEST
+	  Usage: cp [-rnv] SRC DEST
 
 	  Copy file from SRC to DEST.
 
 	  Options:
+		  -r    recursive
+		  -n    do not overwrite an existing file
 		  -v	verbose
 
 config CMD_CMP
diff --git a/commands/cp.c b/commands/cp.c
index 5b8d976c3cfe..dc38cbab889d 100644
--- a/commands/cp.c
+++ b/commands/cp.c
@@ -28,11 +28,14 @@ static int do_cp(int argc, char *argv[])
 	int flags = 0, recursive = 0;
 	int argc_min;
 
-	while ((opt = getopt(argc, argv, "vr")) > 0) {
+	while ((opt = getopt(argc, argv, "vnr")) > 0) {
 		switch (opt) {
 		case 'v':
 			flags |= COPY_FILE_VERBOSE;
 			break;
+		case 'n':
+			flags |= COPY_FILE_NO_OVERWRITE;
+			break;
 		case 'r':
 			recursive = 1;
 			break;
@@ -87,13 +90,14 @@ BAREBOX_CMD_HELP_TEXT("Copy file from SRC to DEST.")
 BAREBOX_CMD_HELP_TEXT("")
 BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT ("-r", "recursive")
+BAREBOX_CMD_HELP_OPT ("-n", "do not overwrite an existing file")
 BAREBOX_CMD_HELP_OPT ("-v", "verbose")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(cp)
 	.cmd		= do_cp,
 	BAREBOX_CMD_DESC("copy files")
-	BAREBOX_CMD_OPTS("[-rv] SRC DEST")
+	BAREBOX_CMD_OPTS("[-rnv] SRC DEST")
 	BAREBOX_CMD_GROUP(CMD_GRP_FILE)
 	BAREBOX_CMD_HELP(cmd_cp_help)
 BAREBOX_CMD_END
diff --git a/include/libfile.h b/include/libfile.h
index 00a7f86a1477..74333a2648f8 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -28,6 +28,7 @@ int write_file(const char *filename, const void *buf, size_t size);
 int write_file_flash(const char *filename, const void *buf, size_t size);
 
 #define COPY_FILE_VERBOSE	BIT(0)
+#define COPY_FILE_NO_OVERWRITE	BIT(1)
 
 int copy_file(const char *src, const char *dst, unsigned flags);
 
diff --git a/lib/libfile.c b/lib/libfile.c
index aaade34a4c34..995531248ea4 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -435,6 +435,7 @@ EXPORT_SYMBOL(write_file_flash);
  * @flags:	A bitmask of COPY_FILE_* flags. Possible values:
  *
  *                COPY_FILE_VERBOSE: show a progression bar
+ *                COPY_FILE_NO_OVERWRITE: don't clobber existing files
  *
  * Return: 0 for success or negative error code
  */
@@ -467,8 +468,13 @@ int copy_file(const char *src, const char *dst, unsigned flags)
 	}
 
 	/* Set O_TRUNC only if file exists and is a regular file */
-	if (!s && S_ISREG(dststat.st_mode))
+	if (!s && S_ISREG(dststat.st_mode)) {
+		if (flags & COPY_FILE_NO_OVERWRITE) {
+			ret = 0;
+			goto out;
+		}
 		mode |= O_TRUNC;
+	}
 
 	dstfd = open(dst, mode);
 	if (dstfd < 0) {
@@ -498,7 +504,7 @@ int copy_file(const char *src, const char *dst, unsigned flags)
 		if (r < 0) {
 			perror("read");
 			ret = r;
-			goto out;
+			goto out_newline;
 		}
 		if (!r)
 			break;
@@ -506,7 +512,7 @@ int copy_file(const char *src, const char *dst, unsigned flags)
 		ret = write_full(dstfd, rw_buf, r);
 		if (ret < 0) {
 			perror("write");
-			goto out;
+			goto out_newline;
 		}
 
 		total += r;
@@ -520,10 +526,10 @@ int copy_file(const char *src, const char *dst, unsigned flags)
 	}
 
 	ret = 0;
-out:
+out_newline:
 	if (flags & COPY_FILE_VERBOSE)
 		putchar('\n');
-
+out:
 	free(rw_buf);
 	if (srcfd > 0)
 		close(srcfd);
@@ -541,6 +547,7 @@ EXPORT_SYMBOL(copy_file);
  * @flags:	A bitmask of COPY_FILE_* flags. Possible values:
  *
  *                COPY_FILE_VERBOSE: show a progression bar
+ *                COPY_FILE_NO_OVERWRITE: don't clobber existing files
  *
  * Return: 0 for success or negative error code
  */
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 04:36:03 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 12:36:03 +0100
Subject: [PATCH 1/2] MAKEALL: support direct options for KCONFIG_ADD
Message-ID: <20250313113604.915474-1-a.fatoum@pengutronix.de>

KCONFIG_ADD currently expects a list of files to be merged.
As MAKEALL is a bash script, let's make use of process substitution
to create temporary files out of -k CONFIG_foo=bar options.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 MAKEALL | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/MAKEALL b/MAKEALL
index 1966eedb4673..b0967b8ae340 100755
--- a/MAKEALL
+++ b/MAKEALL
@@ -56,7 +56,7 @@ usage() {
 	echo "BUILDDIR    -O      build dir"
 	echo "LOGDIR      -l      log dir"
 	echo "REGEX       -e      regex"
-	echo "KCONFIG_ADD -k      kconfig fragment"
+	echo "KCONFIG_ADD -k      kconfig fragment or option"
 	echo "TARGET      -t      Makefile target"
 	echo "V           -v      verbosity"
 	echo "INCREMENTAL -i"
@@ -116,6 +116,11 @@ report() {
 	fi
 }
 
+merge_config() {
+	with_logs_collected ./scripts/kconfig/merge_config.sh -m -O \
+		${BUILDDIR} "$@"
+}
+
 do_build_defconfig() {
 	local arch=$1
 	local defconfig=$2
@@ -156,8 +161,11 @@ do_build_defconfig() {
 	MAKE="${MAKE} $silent_flag CROSS_COMPILE=${cross_compile}"
 	with_logs_collected ${MAKE} ${defconfig}
 	for i in ${KCONFIG_ADD}; do
-		with_logs_collected ./scripts/kconfig/merge_config.sh -m -O \
-			${BUILDDIR} ${BUILDDIR}/.config $i
+		if [[ $i =~ ^CONFIG_* ]]; then
+			merge_config ${BUILDDIR}/.config <(echo $i)
+		else
+			merge_config ${BUILDDIR}/.config $i
+		fi
 	done
 	with_logs_collected ${MAKE} $silent_flag olddefconfig
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 13 04:36:04 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Mar 2025 12:36:04 +0100
Subject: [PATCH 2/2] MAKEALL: parse kconfig_add out of YAML files
In-Reply-To: <20250313113604.915474-1-a.fatoum@pengutronix.de>
References: <20250313113604.915474-1-a.fatoum@pengutronix.de>
Message-ID: <20250313113604.915474-2-a.fatoum@pengutronix.de>

Now that MAKEALL supports direct options in KCONFIG_ADD, teach it to
read runner kconfig_add keys out of the labgrid environment YAML files.

This is a further step towards removal of test/emulate.pl.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 MAKEALL            | 13 +++++++++++++
 test/Containerfile |  1 +
 2 files changed, 14 insertions(+)

diff --git a/MAKEALL b/MAKEALL
index b0967b8ae340..636621d9faec 100755
--- a/MAKEALL
+++ b/MAKEALL
@@ -422,6 +422,19 @@ else
 		if [[ $i =~ ^.*/([^/]+)/([^@]*@|)([^.]+).yaml$ ]]; then
 			arch=${BASH_REMATCH[1]}
 			defconfig=${BASH_REMATCH[3]}
+
+			if grep -q "^\s\+kconfig_add:" $i; then
+				if command -v yq 2>&1 >/dev/null; then
+					KCONFIG_ADD="${KCONFIG_ADD} $(yq -M -r \
+					'.targets.main.runner.kconfig_add |
+					keys[] as $k | .[$k]' < $i)"
+				else
+					echo "WARNING: yq command not found in path" >&2
+					echo "WARNING: ignoring kconfig_add in $i" >&2
+					echo
+				fi
+			fi
+
 			do_build_defconfig $arch $defconfig
 			if [ $? -eq 0 ]; then
 				do_test_defconfig $config $defconfig "${pytest_opts[@]}"
diff --git a/test/Containerfile b/test/Containerfile
index db43d039b922..53a5443e48fe 100644
--- a/test/Containerfile
+++ b/test/Containerfile
@@ -51,6 +51,7 @@ RUN apt-get update && apt-get install -y \
 	sudo \
 	u-boot-tools \
 	yamllint \
+	yq \
 	&& rm -rf /var/lib/apt/lists/*
 
 ENV GCC_VERSION=14.2.0
-- 
2.39.5



From s.hauer at pengutronix.de  Thu Mar 13 04:38:33 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 13 Mar 2025 12:38:33 +0100
Subject: [PATCH v1] commands: Add `ip` command for listing interfaces,
 addresses, and routes
In-Reply-To: <20250312134536.3232324-1-o.rempel@pengutronix.de>
References: <20250312134536.3232324-1-o.rempel@pengutronix.de>
Message-ID: <Z9LDufA4tvr8r_Zf@pengutronix.de>

On Wed, Mar 12, 2025 at 02:45:36PM +0100, Oleksij Rempel wrote:
> This patch introduces the `ip` command, providing functionality similar
> to Linux?s `ip` tool, catering to users with strong Linux muscle memory.
> It supports:
> 
> - `ip l` / `ip link`   - Show network interfaces (state, MAC address)
> - `ip a` / `ip addr`   - Show assigned IP addresses and netmasks
> - `ip r` / `ip route`  - Show routing table, including default gateway,
>                          interface-specific routes, DNS, and server IP.
> 
> Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
> ---
>  commands/Kconfig  |   9 +++
>  commands/Makefile |   1 +
>  commands/ip.c     | 157 ++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 167 insertions(+)
>  create mode 100644 commands/ip.c
> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index e41625e294c9..528b30b8fc90 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -1397,6 +1397,15 @@ config CMD_TFTP
>  	  Options:
>  		  -p	push to TFTP server
>  
> +config CMD_IP
> +	tristate
> +	prompt "ip"
> +	default y
> +	help
> +          This command provides information about network interfaces, similar
> +	  to the Linux `ip addr show` command. It lists interface names, states
> +	  (UP/DOWN), MAC addresses, and assigned IP addresses.

Whitespace damage before "This..."

> +
>  config CMD_IP_ROUTE_GET
>  	tristate
>  	prompt "ip-route-get"
> diff --git a/commands/Makefile b/commands/Makefile
> index e152e4148b04..c202cdef5703 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -146,6 +146,7 @@ obj-$(CONFIG_CMD_MMC)		+= mmc.o
>  obj-$(CONFIG_CMD_MMC_EXTCSD)	+= mmc_extcsd.o
>  obj-$(CONFIG_CMD_NAND_BITFLIP)	+= nand-bitflip.o
>  obj-$(CONFIG_CMD_SEED)		+= seed.o
> +obj-$(CONFIG_CMD_IP)		+= ip.o
>  obj-$(CONFIG_CMD_IP_ROUTE_GET)  += ip-route-get.o
>  obj-$(CONFIG_CMD_BTHREAD)	+= bthread.o
>  obj-$(CONFIG_CMD_UBSAN)		+= ubsan.o
> diff --git a/commands/ip.c b/commands/ip.c
> new file mode 100644
> index 000000000000..35fc5f4d300f
> --- /dev/null
> +++ b/commands/ip.c
> @@ -0,0 +1,157 @@

SPDX?

> +#include <common.h>
> +#include <command.h>
> +#include <net.h>
> +#include <linux/list.h>
> +#include <complete.h>
> +
> +/* Function to calculate CIDR prefix from netmask */
> +static int netmask_to_prefix(IPaddr_t netmask)
> +{
> +	int prefix = 0;
> +
> +	while (netmask) {
> +		prefix += netmask & 1;
> +		netmask >>= 1;
> +	}
> +
> +	return prefix;
> +}
> +
> +/* Function to display network links (`ip l`) */
> +static int do_ip_link(int argc, char *argv[])
> +{
> +	struct eth_device *edev;
> +
> +	for_each_netdev(edev) {
> +		const char *phy_status = edev->phydev ?
> +			(edev->phydev->link ? ",LOWER_UP" : ",NO-CARRIER") : "";
> +
> +		printf("%s: <%s%s>\n",
> +			   eth_name(edev),
> +			   edev->active ? "UP" : "DOWN",
> +			   phy_status);
> +
> +		printf("	link/ether %pM brd ff:ff:ff:ff:ff:ff\n",
> +		       edev->ethaddr);
> +	}
> +
> +	return 0;
> +}
> +
> +/* Function to display network addresses (`ip a`) */
> +static int do_ip_addr(int argc, char *argv[])
> +{
> +	struct eth_device *edev;
> +
> +	for_each_netdev(edev) {
> +		IPaddr_t ipaddr = net_get_ip(edev);
> +		int prefix_length = netmask_to_prefix(edev->netmask);
> +		const char *phy_status = edev->phydev ?
> +			(edev->phydev->link ? ",LOWER_UP" : ",NO-CARRIER") : "";
> +
> +		printf("%s: <%s%s>\n", eth_name(edev),
> +		       edev->active ? "UP" : "DOWN", phy_status);
> +
> +		printf("	link/ether %pM brd ff:ff:ff:ff:ff:ff\n",
> +		       edev->ethaddr);
> +
> +		if (ipaddr) {
> +			printf("	inet %pI4/%d scope global src %pI4\n",
> +				   &ipaddr, prefix_length, &ipaddr);
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +/* Function to display network routes (`ip r`) */
> +static int do_ip_route(int argc, char *argv[])
> +{
> +	const char *domainname = net_get_domainname();
> +	IPaddr_t nameserver = net_get_nameserver();
> +	const char *serverip = net_get_server();
> +	IPaddr_t gateway = net_get_gateway();
> +	struct eth_device *edev;
> +
> +	for_each_netdev(edev) {
> +		int prefix_length = netmask_to_prefix(edev->netmask);
> +		IPaddr_t ipaddr = net_get_ip(edev);
> +		const char *proto;
> +
> +		/* Skip interfaces without an IP address */
> +		if (!ipaddr)
> +			continue;
> +
> +		/* Determine protocol: DHCP or Static */
> +		if (edev->global_mode == ETH_MODE_DHCP)
> +			proto = "dhcp";
> +		else
> +			proto = "static";
> +
> +		/* Show default gateway */
> +		if (gateway) {
> +			printf("default via %pI4 dev %s proto %s src %pI4\n",
> +				   &gateway, eth_name(edev), proto, &ipaddr);
> +		}
> +
> +		/* Show per-interface network route */
> +		if (prefix_length > 0) {
> +			printf("%pI4/%d dev %s proto kernel scope link src %pI4\n",
> +				   &ipaddr, prefix_length, eth_name(edev),
> +				   &ipaddr);
> +		}
> +	}
> +
> +	/* Show boot server */
> +	if (serverip && *serverip) {
> +		printf("serverip %s\n", serverip);
> +	}
> +
> +	/* Show DNS server */
> +	if (nameserver) {
> +		printf("nameserver %pI4\n", &nameserver);
> +	}
> +
> +	/* Show search domain */
> +	if (domainname && *domainname) {
> +		printf("search %s\n", domainname);
> +	}
> +
> +	return 0;
> +}
> +
> +/* Main IP command dispatcher */
> +static int do_ip(int argc, char *argv[])
> +{
> +	if (argc < 2) {
> +		return do_ip_addr(argc, argv); /* Default: `ip a` */
> +	}
> +
> +	if (!strcmp(argv[1], "l") || !strcmp(argv[1], "link"))
> +		return do_ip_link(argc, argv);
> +	else if (!strcmp(argv[1], "a") || !strcmp(argv[1], "addr"))
> +		return do_ip_addr(argc, argv);
> +	else if (!strcmp(argv[1], "r") || !strcmp(argv[1], "route"))
> +		return do_ip_route(argc, argv);

The Linux ip tool not only accepts "l" and "link", but also "li" and "lin",
so maybe something like strncmp(argv[1], "link", strlen(argv[1]))?

> +
> +	printf("Usage: ip [l|link] | [a|addr] | [r|route]\n");
> +	return 1;

return COMMAND_ERROR_USAGE instead?

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Thu Mar 13 04:41:07 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 13 Mar 2025 12:41:07 +0100
Subject: [PATCH 1/2] kbuild: export whether we are cross compiling
In-Reply-To: <20250313063727.70946-1-a.fatoum@pengutronix.de>
References: <20250313063727.70946-1-a.fatoum@pengutronix.de>
Message-ID: <174186606754.1192064.15022203904023825634.b4-ty@pengutronix.de>


On Thu, 13 Mar 2025 07:37:26 +0100, Ahmad Fatoum wrote:
> scripts/kconfig makes use of this variable to inform whether the local
> system's config should be used when no config exists.
> 
> Set it in barebox like Linux does.
> 
> 

Applied, thanks!

[1/2] kbuild: export whether we are cross compiling
      https://git.pengutronix.de/cgit/barebox/commit/?id=c42de0901bd7 (link may not be stable)
[2/2] kbuild: override host system KCONFIG_DEFCONFIG_LIST
      https://git.pengutronix.de/cgit/barebox/commit/?id=2b32c64a9f08 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 13 04:54:53 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 13 Mar 2025 12:54:53 +0100
Subject: [PATCH master] FIT: early exit if digest fails
In-Reply-To: <20250313072309.141338-1-a.fatoum@pengutronix.de>
References: <20250313072309.141338-1-a.fatoum@pengutronix.de>
Message-ID: <174186689300.1709307.16238066312382038254.b4-ty@pengutronix.de>


On Thu, 13 Mar 2025 08:23:09 +0100, Ahmad Fatoum wrote:
> fit_digest will hash the list of images in the configuration, so
> fit_check_signature() can compare it against the signed hash.
> 
> So far, parse errors while computing the hash were ignored. This is not
> directly exploitable as the hash would be incomplete and fail the
> signature verification, but it makes the code more difficult to reason
> about.
> 
> [...]

Applied, thanks!

[1/1] FIT: early exit if digest fails
      https://git.pengutronix.de/cgit/barebox/commit/?id=a676705feac6 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar 14 02:45:58 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 10:45:58 +0100
Subject: [PATCH 1/2] firmware: export firmware directory
Message-ID: <20250314094559.3631184-1-s.hauer@pengutronix.de>

The recently added k3r5 code needs firmware blobs as part of the image
generation. It hardcodes the firmware path to $(srctree)/firmware which
is the default, but could changed with CONFIG_EXTRA_FIRMWARE_DIR.

Move setting of $(fwdir) to the toplevel Makefile and export it to make
it available to images/Makefile.k3. As fwdir is a bad name for an
exported variable rename it to FIRMWARE_DIR.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 Makefile          |  6 ++++++
 firmware/Makefile | 14 +++++---------
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index 40d7553dfc..2341625d64 100644
--- a/Makefile
+++ b/Makefile
@@ -515,6 +515,12 @@ export LDFLAGS_barebox LDFLAGS_pbl LDFLAGS_elf
 export CFLAGS_UBSAN
 export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE
 
+# Create $(FIRMWARE_DIR) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a
+# leading /, it's relative to $(srctree).
+FIRMWARE_DIR := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE_DIR))
+FIRMWARE_DIR := $(addprefix $(srctree)/,$(filter-out /%,$(FIRMWARE_DIR)))$(filter /%,$(FIRMWARE_DIR))
+export FIRMWARE_DIR
+
 # Files to ignore in find ... statements
 
 export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o    \
diff --git a/firmware/Makefile b/firmware/Makefile
index 2f47e04bee..a3fdaa0f7c 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -42,10 +42,6 @@ fw-external-$(CONFIG_FIRMWARE_LS1046A_ATF) += ls1046a-bl31.bin
 pbl-firmware-$(CONFIG_FIRMWARE_CCBV2_OPTEE) += ccbv2_optee.bin
 pbl-firmware-$(CONFIG_FIRMWARE_TQMA6UL_OPTEE) += mba6ul_optee.bin
 
-# Create $(fwdir) from $(CONFIG_EXTRA_FIRMWARE_DIR) -- if it doesn't have a
-# leading /, it's relative to $(srctree).
-fwdir := $(subst $(quote),,$(CONFIG_EXTRA_FIRMWARE_DIR))
-fwdir := $(addprefix $(srctree)/,$(filter-out /%,$(fwdir)))$(filter /%,$(fwdir))
 fwobjdir := $(objtree)/firmware
 
 pbl-y     := $(addsuffix .gen.o, $(pbl-firmware-y))
@@ -54,7 +50,7 @@ pbl-fwext-y := $(addsuffix .extgen.o, $(fw-external-y))
 
 FWNAME    = $(patsubst $(obj)/%.extgen.S,%,$(patsubst $(obj)/%.gen.S,%,$@))
 FWSTR     = $(subst /,_,$(subst .,_,$(subst -,_,$(FWNAME))))
-FWNAME_EXISTS = $(if $(wildcard $(fwdir)/$(FWNAME)),1,0)
+FWNAME_EXISTS = $(if $(wildcard $(FIRMWARE_DIR)/$(FWNAME)),1,0)
 
 filechk_fwbin = { \
 	echo "/* Generated by $(src)/Makefile */"		;\
@@ -65,7 +61,7 @@ filechk_fwbin = { \
 	echo ".global _fw_$(FWSTR)_start"			;\
 	echo "_fw_$(FWSTR)_start:"				;\
 	echo "\#if $(FWNAME_EXISTS)"				;\
-	echo "    .incbin \"$(fwdir)/$(FWNAME)\""		;\
+	echo "    .incbin \"$(FIRMWARE_DIR)/$(FWNAME)\""		;\
 	echo "\#elif defined(__PBL__)"				;\
 	echo "ASM_PTR _fwname_$(FWSTR)"				;\
 	echo "\#endif"						;\
@@ -103,12 +99,12 @@ $(obj)/%.sha.bin: $(obj)/%.sum FORCE
 	$(call if_changed,sha256bin)
 
 $(obj)/%.sum: FORCE
-	$(if $(wildcard $(fwdir)/$*), $(call if_changed,sha256sum,$(fwdir)/$*), @touch $@)
+	$(if $(wildcard $(FIRMWARE_DIR)/$*), $(call if_changed,sha256sum,$(FIRMWARE_DIR)/$*), @touch $@)
 
 clean-files += *.sha.bin *.sum
 
 # This dependency is used if missing firmware should fail the build immediately
-fwdep-required-y = $(fwdir)/%
+fwdep-required-y = $(FIRMWARE_DIR)/%
 # This dependency expands to nothing if the file doesn't exist. This allows
 # delaying the firmware check:
 #
@@ -117,7 +113,7 @@ fwdep-required-y = $(fwdir)/%
 #
 # This way, we allow users to build defconfigs with multiple images without requiring
 # them to install all firmware for all platforms if only few are of interest.
-fwdep-required-n = $$(wildcard $(fwdir)/%)
+fwdep-required-n = $$(wildcard $(FIRMWARE_DIR)/%)
 
 .SECONDEXPANSION:
 # The .o files depend on the binaries directly if available; the .S files don't.
-- 
2.39.5



From s.hauer at pengutronix.de  Fri Mar 14 02:45:59 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 10:45:59 +0100
Subject: [PATCH 2/2] ARM: k3r5: Honour CONFIG_EXTRA_FIRMWARE_DIR
In-Reply-To: <20250314094559.3631184-1-s.hauer@pengutronix.de>
References: <20250314094559.3631184-1-s.hauer@pengutronix.de>
Message-ID: <20250314094559.3631184-2-s.hauer@pengutronix.de>

barebox expects the firmware blobs in CONFIG_EXTRA_FIRMWARE_DIR, but the
ti-fs-firmware is searched for in $(srctree)/firmware/ instead. Use
$(FIRMWARE_DIR) instead to use the correct directory when changed from
the default.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 images/Makefile.k3 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/images/Makefile.k3 b/images/Makefile.k3
index 466a84af99..fd42877837 100644
--- a/images/Makefile.k3
+++ b/images/Makefile.k3
@@ -25,9 +25,9 @@ ifdef CONFIG_MACH_K3_CORTEX_R5
 
 SYSFWDATA_am625=$(objtree)/arch/arm/mach-k3/combined-sysfw-cfg-am625.k3cfg
 DMDATA_am625=$(objtree)/arch/arm/mach-k3/combined-dm-cfg-am625.k3cfg
-SYSFW_am625_hs_fs=$(srctree)/firmware/ti-fs-firmware-am62x-hs-fs-enc.bin
-SYSFW_am625_gp=$(srctree)/firmware/ti-fs-firmware-am62x-gp.bin
-INNERDATA_am625=$(srctree)/firmware/ti-fs-firmware-am62x-hs-fs-cert.bin
+SYSFW_am625_hs_fs=$(FIRMWARE_DIR)/ti-fs-firmware-am62x-hs-fs-enc.bin
+SYSFW_am625_gp=$(FIRMWARE_DIR)/ti-fs-firmware-am62x-gp.bin
+INNERDATA_am625=$(FIRMWARE_DIR)/ti-fs-firmware-am62x-hs-fs-cert.bin
 KEY_custmpk=$(srctree)/arch/arm/mach-k3/custMpk.pem
 KEY_degenerate=$(srctree)/arch/arm/mach-k3/ti-degenerate-key.pem
 
-- 
2.39.5



From jmaselbas at zdiv.net  Fri Mar 14 03:40:28 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 11:40:28 +0100
Subject: [PATCH 0/6] compile test fixes
Message-ID: <20250314104034.13637-1-jmaselbas@zdiv.net>

Small patches series of fixes discovered with a compile test on sandbox (x86_64)
The compile test has been against the next branch but all the patches applies on
commits that are already in the master branch.

Jules Maselbas (6):
  dma-devices: k3-udma: cleanup headers
  dma-devices: k3-udma: use snprintf instead of sprintf
  mfd: tps65219: add missing include
  pmdomain: ti-k3: add missing include
  pmdomain: ti-k3: remove trailing whitespace
  regulator: tps65219: add missing include

 drivers/dma/ti/k3-udma.c               | 5 ++---
 drivers/mfd/tps65219.c                 | 1 +
 drivers/pmdomain/ti/ti-k3.c            | 9 +++++----
 drivers/regulator/tps65219-regulator.c | 1 +
 4 files changed, 9 insertions(+), 7 deletions(-)

-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 03:40:29 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 11:40:29 +0100
Subject: [PATCH 1/6] dma-devices: k3-udma: cleanup headers
In-Reply-To: <20250314104034.13637-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
Message-ID: <20250314104034.13637-2-jmaselbas@zdiv.net>

Remove include of `asm/cache.h` as it is not used.
Also remove the duplicated include `soc/ti/ti_sci_protocol.h`.
Add the include `common.h` for the missing declaration of sprintf.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/dma/ti/k3-udma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
index 761898867d..8f46364145 100644
--- a/drivers/dma/ti/k3-udma.c
+++ b/drivers/dma/ti/k3-udma.c
@@ -5,8 +5,8 @@
  */
 #define pr_fmt(fmt) "udma: " fmt
 
-#include <asm/cache.h>
 #include <io.h>
+#include <common.h>
 #include <malloc.h>
 #include <linux/bitops.h>
 #include <linux/sizes.h>
@@ -21,7 +21,6 @@
 #include <linux/bitmap.h>
 #include <driver.h>
 #include <linux/device.h>
-#include <soc/ti/ti_sci_protocol.h>
 
 #include "k3-udma-hwdef.h"
 #include "k3-psil-priv.h"
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 03:40:30 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 11:40:30 +0100
Subject: [PATCH 2/6] dma-devices: k3-udma: use snprintf instead of sprintf
In-Reply-To: <20250314104034.13637-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
Message-ID: <20250314104034.13637-3-jmaselbas@zdiv.net>

Replace the use of sprintf by snprintf, in this case sprintf could not
overflow because the size of uc::name is well chosen to be able to fit
the largest u32 integer.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/dma/ti/k3-udma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
index 8f46364145..d32ed46b0f 100644
--- a/drivers/dma/ti/k3-udma.c
+++ b/drivers/dma/ti/k3-udma.c
@@ -2678,7 +2678,7 @@ static int k3_udma_probe(struct device *dev)
 		uc->config.mapped_channel_id = -1;
 		uc->config.default_flow_id = -1;
 		uc->config.dir = DMA_MEM_TO_MEM;
-		sprintf(uc->name, "UDMA chan%d\n", i);
+		snprintf(uc->name, sizeof(uc->name), "UDMA chan%d\n", i);
 		if (!i)
 			uc->in_use = true;
 	}
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 03:40:31 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 11:40:31 +0100
Subject: [PATCH 3/6] mfd: tps65219: add missing include
In-Reply-To: <20250314104034.13637-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
Message-ID: <20250314104034.13637-4-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/mfd/tps65219.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mfd/tps65219.c b/drivers/mfd/tps65219.c
index 854210537f..62280f2aa2 100644
--- a/drivers/mfd/tps65219.c
+++ b/drivers/mfd/tps65219.c
@@ -12,6 +12,7 @@
 #include <linux/regmap.h>
 #include <linux/mfd/tps65219.h>
 #include <linux/device.h>
+#include <linux/array_size.h>
 
 static const struct mfd_cell tps65219_cells[] = {
 	{ .name = "tps65219-regulator", },
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 03:40:32 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 11:40:32 +0100
Subject: [PATCH 4/6] pmdomain: ti-k3: add missing include
In-Reply-To: <20250314104034.13637-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
Message-ID: <20250314104034.13637-5-jmaselbas@zdiv.net>

The function basprintf was not defined, include common.h which includes
stdio.h and defines basprintf

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/pmdomain/ti/ti-k3.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pmdomain/ti/ti-k3.c b/drivers/pmdomain/ti/ti-k3.c
index 33bffeaca0..f53e907386 100644
--- a/drivers/pmdomain/ti/ti-k3.c
+++ b/drivers/pmdomain/ti/ti-k3.c
@@ -8,6 +8,7 @@
 
 #define pr_fmt(fmt)     "ti-k3-pm-domain: " fmt
 
+#include <common.h>
 #include <io.h>
 #include <of_device.h>
 #include <malloc.h>
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 03:40:33 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 11:40:33 +0100
Subject: [PATCH 5/6] pmdomain: ti-k3: remove trailing whitespace
In-Reply-To: <20250314104034.13637-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
Message-ID: <20250314104034.13637-6-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/pmdomain/ti/ti-k3.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pmdomain/ti/ti-k3.c b/drivers/pmdomain/ti/ti-k3.c
index f53e907386..a2667a9847 100644
--- a/drivers/pmdomain/ti/ti-k3.c
+++ b/drivers/pmdomain/ti/ti-k3.c
@@ -321,14 +321,14 @@ static int ti_k3_pm_domain_on(struct generic_pm_domain *domain)
 	struct ti_k3_pm_domain *pd = to_ti_k3_pd(domain);
 
 	return ti_lpsc_transition(pd->lpsc, MDSTAT_STATE_ENABLE);
-}       
-        
+}
+
 static int ti_k3_pm_domain_off(struct generic_pm_domain *domain)
-{       
+{
 	struct ti_k3_pm_domain *pd = to_ti_k3_pd(domain);
 
 	return ti_lpsc_transition(pd->lpsc, MDSTAT_STATE_SWRSTDISABLE);
-}       
+}
 
 static struct ti_psc am625_psc[] = {
 	[0] = { .id = 0, .base = (void *)0x04000000 },
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 03:40:34 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 11:40:34 +0100
Subject: [PATCH 6/6] regulator: tps65219: add missing include
In-Reply-To: <20250314104034.13637-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
Message-ID: <20250314104034.13637-7-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/regulator/tps65219-regulator.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/regulator/tps65219-regulator.c b/drivers/regulator/tps65219-regulator.c
index da329660d6..9961638595 100644
--- a/drivers/regulator/tps65219-regulator.c
+++ b/drivers/regulator/tps65219-regulator.c
@@ -16,6 +16,7 @@
 #include <linux/regulator/of_regulator.h>
 #include <regulator.h>
 #include <linux/device.h>
+#include <linux/array_size.h>
 
 struct tps65219_regulator_irq_type {
 	const char *irq_name;
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 03:45:01 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 11:45:01 +0100
Subject: [PATCH 1/2] eeprom: at25: replace strncpy with strlcpy
Message-ID: <20250314104502.14851-1-jmaselbas@zdiv.net>

strncpy will not nul terminate the dst string in case the src is longer
than the the dst size, strlcpy will truncate and nul terminate the string.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/eeprom/at25.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/eeprom/at25.c b/drivers/eeprom/at25.c
index ca1df82122..43e72677c9 100644
--- a/drivers/eeprom/at25.c
+++ b/drivers/eeprom/at25.c
@@ -243,7 +243,7 @@ static int at25_np_to_chip(struct device *dev,
 		return -ENODEV;
 
 	memset(chip, 0, sizeof(*chip));
-	strncpy(chip->name, np->name, sizeof(chip->name));
+	strlcpy(chip->name, np->name, sizeof(chip->name));
 
 	if (of_property_read_u32(np, "size", &val) == 0 ||
 	    of_property_read_u32(np, "at25,byte-len", &val) == 0) {
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 03:45:02 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 11:45:02 +0100
Subject: [PATCH 2/2] eeprom: at25: add explicit fallthrough
In-Reply-To: <20250314104502.14851-1-jmaselbas@zdiv.net>
References: <20250314104502.14851-1-jmaselbas@zdiv.net>
Message-ID: <20250314104502.14851-2-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/eeprom/at25.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/eeprom/at25.c b/drivers/eeprom/at25.c
index 43e72677c9..f58e554616 100644
--- a/drivers/eeprom/at25.c
+++ b/drivers/eeprom/at25.c
@@ -87,8 +87,10 @@ static ssize_t at25_ee_read(struct cdev *cdev,
 	switch (at25->addrlen) {
 	default:	/* case 3 */
 		*cp++ = offset >> 16;
+		fallthrough;
 	case 2:
 		*cp++ = offset >> 8;
+		fallthrough;
 	case 1:
 	case 0:	/* can't happen: for better codegen */
 		*cp++ = offset >> 0;
@@ -168,8 +170,10 @@ static ssize_t at25_ee_write(struct cdev *cdev,
 		switch (at25->addrlen) {
 		default:	/* case 3 */
 			*cp++ = offset >> 16;
+			fallthrough;
 		case 2:
 			*cp++ = offset >> 8;
+			fallthrough;
 		case 1:
 		case 0:	/* can't happen: for better codegen */
 			*cp++ = offset >> 0;
-- 
2.48.1



From a.fatoum at pengutronix.de  Fri Mar 14 06:08:58 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Mar 2025 14:08:58 +0100
Subject: [PATCH 0/6] compile test fixes
In-Reply-To: <20250314104034.13637-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
Message-ID: <a87dbd9c-10fb-4451-abd3-f3d9d49c13e2@pengutronix.de>

Hi Jules,

On 3/14/25 11:40, Jules Maselbas wrote:
> Small patches series of fixes discovered with a compile test on sandbox (x86_64)
> The compile test has been against the next branch but all the patches applies on
> commits that are already in the master branch.

This partially duplicates fixes in my clang-analyzer series here:
https://lore.barebox.org/barebox/20250313073445.764875-1-a.fatoum at pengutronix.de/T/#t

Can you rebase?

Thanks,
Ahmad

> 
> Jules Maselbas (6):
>   dma-devices: k3-udma: cleanup headers
>   dma-devices: k3-udma: use snprintf instead of sprintf
>   mfd: tps65219: add missing include
>   pmdomain: ti-k3: add missing include
>   pmdomain: ti-k3: remove trailing whitespace
>   regulator: tps65219: add missing include
> 
>  drivers/dma/ti/k3-udma.c               | 5 ++---
>  drivers/mfd/tps65219.c                 | 1 +
>  drivers/pmdomain/ti/ti-k3.c            | 9 +++++----
>  drivers/regulator/tps65219-regulator.c | 1 +
>  4 files changed, 9 insertions(+), 7 deletions(-)
> 



From jmaselbas at zdiv.net  Fri Mar 14 07:32:54 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 15:32:54 +0100
Subject: [PATCH] common: deep-probe: make __barebox_deep_probe_{start,end} of array type
Message-ID: <20250314143254.21753-1-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 common/deep-probe.c  | 4 ++--
 include/deep-probe.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/deep-probe.c b/common/deep-probe.c
index b270a10f7f..69beaf2d80 100644
--- a/common/deep-probe.c
+++ b/common/deep-probe.c
@@ -22,8 +22,8 @@ bool deep_probe_is_supported(void)
 		return boardstate;
 
 	/* determine boardstate */
-	for (board = &__barebox_deep_probe_start;
-	     board != &__barebox_deep_probe_end; board++) {
+	for (board = __barebox_deep_probe_start;
+	     board != __barebox_deep_probe_end; board++) {
 		const struct of_device_id *matches = board->device_id;
 
 		for (; matches->compatible; matches++) {
diff --git a/include/deep-probe.h b/include/deep-probe.h
index e3770fcf0d..9ba9d09ec3 100644
--- a/include/deep-probe.h
+++ b/include/deep-probe.h
@@ -19,8 +19,8 @@ static inline bool deep_probe_is_supported(void)
 }
 #endif
 
-extern struct deep_probe_entry __barebox_deep_probe_start;
-extern struct deep_probe_entry __barebox_deep_probe_end;
+extern struct deep_probe_entry __barebox_deep_probe_start[];
+extern struct deep_probe_entry __barebox_deep_probe_end[];
 
 #define __BAREBOX_DEEP_PROBE_ENABLE(_entry,_device_id)			\
 	static const struct deep_probe_entry _entry			\
-- 
2.48.1



From s.hauer at pengutronix.de  Fri Mar 14 07:42:47 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 15:42:47 +0100
Subject: [PATCH] ARM: k3-r5_defconfig: enable eMMC boot partitions
Message-ID: <20250314144247.4074473-1-s.hauer@pengutronix.de>

Support for eMMC boot partition is needed to boot from eMMCs, enable
it.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/k3-r5_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/k3-r5_defconfig b/arch/arm/configs/k3-r5_defconfig
index 59b3aa5a6e..df66bdef5a 100644
--- a/arch/arm/configs/k3-r5_defconfig
+++ b/arch/arm/configs/k3-r5_defconfig
@@ -30,6 +30,7 @@ CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_DFU=y
 CONFIG_MCI=y
 # CONFIG_MCI_WRITE is not set
+CONFIG_MCI_MMC_BOOT_PARTITIONS=y
 CONFIG_MCI_AM654=y
 # CONFIG_TI_SCI_CLK is not set
 CONFIG_MFD_SYSCON=y
-- 
2.39.5



From jmaselbas at zdiv.net  Fri Mar 14 07:43:24 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 15:43:24 +0100
Subject: [PATCH 0/6] compile test fixes
In-Reply-To: <a87dbd9c-10fb-4451-abd3-f3d9d49c13e2@pengutronix.de>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
 <a87dbd9c-10fb-4451-abd3-f3d9d49c13e2@pengutronix.de>
Message-ID: <D8G2HOCHLZHE.3FCQMJ924J7NR@zdiv.net>

On Fri Mar 14, 2025 at 2:08 PM CET, Ahmad Fatoum wrote:
> Hi Jules,
>
> On 3/14/25 11:40, Jules Maselbas wrote:
>> Small patches series of fixes discovered with a compile test on sandbox (x86_64)
>> The compile test has been against the next branch but all the patches applies on
>> commits that are already in the master branch.
>
> This partially duplicates fixes in my clang-analyzer series here:
> https://lore.barebox.org/barebox/20250313073445.764875-1-a.fatoum at pengutronix.de/T/#t
>
> Can you rebase?

Only patch 6 is conflicting and can be dropped because it is already fixed by
9b815da01ff4b88c6634c4a7541c581a35ad96d8 ("treewide: fix missing headers in sandbox allyesconfig")

>
> Thanks,
> Ahmad
>
>> 
>> Jules Maselbas (6):
>>   dma-devices: k3-udma: cleanup headers
>>   dma-devices: k3-udma: use snprintf instead of sprintf
>>   mfd: tps65219: add missing include
>>   pmdomain: ti-k3: add missing include
>>   pmdomain: ti-k3: remove trailing whitespace
>>   regulator: tps65219: add missing include
>> 
>>  drivers/dma/ti/k3-udma.c               | 5 ++---
>>  drivers/mfd/tps65219.c                 | 1 +
>>  drivers/pmdomain/ti/ti-k3.c            | 9 +++++----
>>  drivers/regulator/tps65219-regulator.c | 1 +
>>  4 files changed, 9 insertions(+), 7 deletions(-)
>> 



From a.fatoum at pengutronix.de  Fri Mar 14 07:49:10 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Mar 2025 15:49:10 +0100
Subject: [PATCH 0/6] compile test fixes
In-Reply-To: <D8G2HOCHLZHE.3FCQMJ924J7NR@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
 <a87dbd9c-10fb-4451-abd3-f3d9d49c13e2@pengutronix.de>
 <D8G2HOCHLZHE.3FCQMJ924J7NR@zdiv.net>
Message-ID: <70cf43af-954d-4cbd-bb2d-0e2be2d8c6f5@pengutronix.de>

Hello Jules,

On 3/14/25 15:43, Jules Maselbas wrote:
> On Fri Mar 14, 2025 at 2:08 PM CET, Ahmad Fatoum wrote:
>> Hi Jules,
>>
>> On 3/14/25 11:40, Jules Maselbas wrote:
>>> Small patches series of fixes discovered with a compile test on sandbox (x86_64)
>>> The compile test has been against the next branch but all the patches applies on
>>> commits that are already in the master branch.
>>
>> This partially duplicates fixes in my clang-analyzer series here:
>> https://lore.barebox.org/barebox/20250313073445.764875-1-a.fatoum at pengutronix.de/T/#t
>>
>> Can you rebase?
> 
> Only patch 6 is conflicting and can be dropped because it is already fixed by
> 9b815da01ff4b88c6634c4a7541c581a35ad96d8 ("treewide: fix missing headers in sandbox allyesconfig")

Patch 3/6 and 4/6 as well as partially (?) 1/6 are also addressed by my
series. So even without conflict, applying this on top would lead to
addition of a now superfluous include.

Thanks,
Ahmad

> 
>>
>> Thanks,
>> Ahmad
>>
>>>
>>> Jules Maselbas (6):
>>>   dma-devices: k3-udma: cleanup headers
>>>   dma-devices: k3-udma: use snprintf instead of sprintf
>>>   mfd: tps65219: add missing include
>>>   pmdomain: ti-k3: add missing include
>>>   pmdomain: ti-k3: remove trailing whitespace
>>>   regulator: tps65219: add missing include
>>>
>>>  drivers/dma/ti/k3-udma.c               | 5 ++---
>>>  drivers/mfd/tps65219.c                 | 1 +
>>>  drivers/pmdomain/ti/ti-k3.c            | 9 +++++----
>>>  drivers/regulator/tps65219-regulator.c | 1 +
>>>  4 files changed, 9 insertions(+), 7 deletions(-)
>>>
> 
> 



From jmaselbas at zdiv.net  Fri Mar 14 08:00:02 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 16:00:02 +0100
Subject: [PATCH 0/6] compile test fixes
In-Reply-To: <70cf43af-954d-4cbd-bb2d-0e2be2d8c6f5@pengutronix.de>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
 <a87dbd9c-10fb-4451-abd3-f3d9d49c13e2@pengutronix.de>
 <D8G2HOCHLZHE.3FCQMJ924J7NR@zdiv.net>
 <70cf43af-954d-4cbd-bb2d-0e2be2d8c6f5@pengutronix.de>
Message-ID: <D8G2UF0EAAFW.35UKIQ5U4FFPI@zdiv.net>

Hi Ahmad,

On Fri Mar 14, 2025 at 3:49 PM CET, Ahmad Fatoum wrote:
> Hello Jules,
>
> On 3/14/25 15:43, Jules Maselbas wrote:
>> On Fri Mar 14, 2025 at 2:08 PM CET, Ahmad Fatoum wrote:
>>> Hi Jules,
>>>
>>> On 3/14/25 11:40, Jules Maselbas wrote:
>>>> Small patches series of fixes discovered with a compile test on sandbox (x86_64)
>>>> The compile test has been against the next branch but all the patches applies on
>>>> commits that are already in the master branch.
>>>
>>> This partially duplicates fixes in my clang-analyzer series here:
>>> https://lore.barebox.org/barebox/20250313073445.764875-1-a.fatoum at pengutronix.de/T/#t
>>>
>>> Can you rebase?
>> 
>> Only patch 6 is conflicting and can be dropped because it is already fixed by
>> 9b815da01ff4b88c6634c4a7541c581a35ad96d8 ("treewide: fix missing headers in sandbox allyesconfig")
>
> Patch 3/6 and 4/6 as well as partially (?) 1/6 are also addressed by my
> series. So even without conflict, applying this on top would lead to
> addition of a now superfluous include.

Good point

I will send a v2, and drop unneeded patches



From jmaselbas at zdiv.net  Fri Mar 14 08:09:49 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 16:09:49 +0100
Subject: [PATCH v2 0/3] compile test cleanups
In-Reply-To: <20250314104034.13637-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
Message-ID: <20250314150953.21686-1-jmaselbas@zdiv.net>

Small cleanups patches

v2:
 - rebased on Ahmad clang-analyzer series, and dropped spurious changes

Jules Maselbas (3):
  dma-devices: k3-udma: remove duplicated include
  dma-devices: k3-udma: use snprintf instead of sprintf
  pmdomain: ti-k3: remove trailing whitespace

 drivers/dma/ti/k3-udma.c    | 3 +--
 drivers/pmdomain/ti/ti-k3.c | 8 ++++----
 2 files changed, 5 insertions(+), 6 deletions(-)

-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 08:09:50 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 16:09:50 +0100
Subject: [PATCH v2 1/3] dma-devices: k3-udma: remove duplicated include
In-Reply-To: <20250314150953.21686-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
 <20250314150953.21686-1-jmaselbas@zdiv.net>
Message-ID: <20250314150953.21686-2-jmaselbas@zdiv.net>

Remove the duplicated include `soc/ti/ti_sci_protocol.h`.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/dma/ti/k3-udma.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
index e17b99de47..06f81431be 100644
--- a/drivers/dma/ti/k3-udma.c
+++ b/drivers/dma/ti/k3-udma.c
@@ -21,7 +21,6 @@
 #include <linux/bitmap.h>
 #include <driver.h>
 #include <linux/device.h>
-#include <soc/ti/ti_sci_protocol.h>
 
 #include "k3-udma-hwdef.h"
 #include "k3-psil-priv.h"
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 08:09:51 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 16:09:51 +0100
Subject: [PATCH v2 2/3] dma-devices: k3-udma: use snprintf instead of sprintf
In-Reply-To: <20250314150953.21686-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
 <20250314150953.21686-1-jmaselbas@zdiv.net>
Message-ID: <20250314150953.21686-3-jmaselbas@zdiv.net>

Replace the use of sprintf by snprintf, in this case sprintf could not
overflow because the size of uc::name is well chosen to be able to fit
the largest u32 integer.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/dma/ti/k3-udma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
index 06f81431be..7e6a08348a 100644
--- a/drivers/dma/ti/k3-udma.c
+++ b/drivers/dma/ti/k3-udma.c
@@ -2678,7 +2678,7 @@ static int k3_udma_probe(struct device *dev)
 		uc->config.mapped_channel_id = -1;
 		uc->config.default_flow_id = -1;
 		uc->config.dir = DMA_MEM_TO_MEM;
-		sprintf(uc->name, "UDMA chan%d\n", i);
+		snprintf(uc->name, sizeof(uc->name), "UDMA chan%d\n", i);
 		if (!i)
 			uc->in_use = true;
 	}
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 08:09:52 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 16:09:52 +0100
Subject: [PATCH v2 3/3] pmdomain: ti-k3: remove trailing whitespace
In-Reply-To: <20250314150953.21686-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
 <20250314150953.21686-1-jmaselbas@zdiv.net>
Message-ID: <20250314150953.21686-4-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/pmdomain/ti/ti-k3.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pmdomain/ti/ti-k3.c b/drivers/pmdomain/ti/ti-k3.c
index 1616e90b62..39fd9f329b 100644
--- a/drivers/pmdomain/ti/ti-k3.c
+++ b/drivers/pmdomain/ti/ti-k3.c
@@ -321,14 +321,14 @@ static int ti_k3_pm_domain_on(struct generic_pm_domain *domain)
 	struct ti_k3_pm_domain *pd = to_ti_k3_pd(domain);
 
 	return ti_lpsc_transition(pd->lpsc, MDSTAT_STATE_ENABLE);
-}       
-        
+}
+
 static int ti_k3_pm_domain_off(struct generic_pm_domain *domain)
-{       
+{
 	struct ti_k3_pm_domain *pd = to_ti_k3_pd(domain);
 
 	return ti_lpsc_transition(pd->lpsc, MDSTAT_STATE_SWRSTDISABLE);
-}       
+}
 
 static struct ti_psc am625_psc[] = {
 	[0] = { .id = 0, .base = (void *)0x04000000 },
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 08:14:40 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 16:14:40 +0100
Subject: [PATCH 1/2] sandbox: sdl: fix compilation on musl-libc
Message-ID: <20250314151441.23223-1-jmaselbas@zdiv.net>

fails to compile with "unknown type name 'loff_t'; did you mean 'off_t'"
error, add missing include and also define _GNU_SOURCE

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 arch/sandbox/os/sdl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/sandbox/os/sdl.c b/arch/sandbox/os/sdl.c
index 87c8265ea9..0c31b6ce87 100644
--- a/arch/sandbox/os/sdl.c
+++ b/arch/sandbox/os/sdl.c
@@ -3,8 +3,11 @@
  * Copyright (c) 2021 Ahmad Fatoum
  */
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdbool.h>
+#include <stdint.h>
+#include <fcntl.h>
 #include <SDL.h>
 #include <mach/linux.h>
 
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 08:14:41 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 16:14:41 +0100
Subject: [PATCH 2/2] sandbox: sdl: make window variable static
In-Reply-To: <20250314151441.23223-1-jmaselbas@zdiv.net>
References: <20250314151441.23223-1-jmaselbas@zdiv.net>
Message-ID: <20250314151441.23223-2-jmaselbas@zdiv.net>

the `window` variable doesn't seems to be used outside of this file,
thus doesn't need to be exported and can be made static.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 arch/sandbox/os/sdl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/os/sdl.c b/arch/sandbox/os/sdl.c
index 0c31b6ce87..e4c6f1a587 100644
--- a/arch/sandbox/os/sdl.c
+++ b/arch/sandbox/os/sdl.c
@@ -18,7 +18,7 @@ static void sdl_perror(const char *what)
 
 static struct sdl_fb_info info;
 static SDL_atomic_t shutdown;
-SDL_Window *window;
+static SDL_Window *window;
 
 static void handle_sdl_events(void)
 {
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 08:24:37 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 16:24:37 +0100
Subject: [PATCH] regulator: fan53555: suppress warning about uninitialized variable
Message-ID: <20250314152437.25675-1-jmaselbas@zdiv.net>

In function 'fan53555_device_setup', a call to 'regmap_update_bits' is
made with the mode_mask variable potentially uninitialized.

This can be the case if di->vendor is FAN53526_VENDOR_FAIRCHILD and
di->sleep_vsel_id is not handled by the case (neither FAN53555_VSEL_ID_0 nor FAN53555_VSEL_ID_1).
I am not sure how likely it is to happen.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/regulator/fan53555.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index 2df0d2410a..2dcc6f5394 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -238,7 +238,7 @@ static const struct regulator_ops fan53555_regulator_ops = {
 
 static int fan53555_device_setup(struct fan53555_device_info *di)
 {
-	unsigned int mode_reg, mode_mask;
+	unsigned int mode_reg, mode_mask = 0;
 	int ret = 0;
 
 	/* Setup voltage control register */
-- 
2.48.1



From s.hauer at pengutronix.de  Fri Mar 14 08:53:31 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 16:53:31 +0100
Subject: [PATCH] bootm: let BOOTM_OPTIONAL_SIGNED_IMAGES depend on
 BOOTM
In-Reply-To: <20250311080925.1439519-1-s.hauer@pengutronix.de>
References: <20250311080925.1439519-1-s.hauer@pengutronix.de>
Message-ID: <174196761162.4115641.614461956565019407.b4-ty@pengutronix.de>


On Tue, 11 Mar 2025 09:09:25 +0100, Sascha Hauer wrote:
> The purpose of BOOTM_OPTIONAL_SIGNED_IMAGES is to select
> HAS_INSECURE_DEFAULTS, but it should only do so when BOOTM
> support is actually compiled in.
> 
> 

Applied, thanks!

[1/1] bootm: let BOOTM_OPTIONAL_SIGNED_IMAGES depend on BOOTM
      https://git.pengutronix.de/cgit/barebox/commit/?id=f9a7b77e8509 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar 14 08:54:31 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 16:54:31 +0100
Subject: [PATCH] fs: combine __d_alloc's allocations into one
In-Reply-To: <20250313064540.76961-1-a.fatoum@pengutronix.de>
References: <20250313064540.76961-1-a.fatoum@pengutronix.de>
Message-ID: <174196767114.4115826.116033472155325437.b4-ty@pengutronix.de>


On Thu, 13 Mar 2025 07:45:40 +0100, Ahmad Fatoum wrote:
> Instead of doing two allocations, one for the struct dentry and one for
> the full name, just do one allocation and place them after each other.
> 
> This has the extra benefit of fixing a leak of the dentry allocation
> when the second allocation for the file name fails.
> 
> 
> [...]

Applied, thanks!

[1/1] fs: combine __d_alloc's allocations into one
      https://git.pengutronix.de/cgit/barebox/commit/?id=9b21612c3bc0 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar 14 09:03:08 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 17:03:08 +0100
Subject: [PATCH 18/22] video: Rockchip: fix zero division in
 rk3588_calc_cru_cfg
In-Reply-To: <20250313073445.764875-19-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
 <20250313073445.764875-19-a.fatoum@pengutronix.de>
Message-ID: <Z9RTPKnmYeif2qKx@pengutronix.de>

On Thu, Mar 13, 2025 at 08:34:41AM +0100, Ahmad Fatoum wrote:
> This was detected by clang-analyzer and I don't understand how that
> function could have ever worked, because it's running into the zero
> division in the "successful" code path.

The driver is only tested on rk3568, so this code path likely never
executed.

sascha

> 
> Peeking at rk3568_set_intf_mux, the CRTC clock is passed by the caller
> in barebox, so let's do the same for rk3588_calc_cru_cfg.
> 
> Fixes: c8c0833beb77 ("video: Rockchip: Add VOP2 driver")
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  drivers/video/rockchip/rockchip_drm_vop2.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/rockchip/rockchip_drm_vop2.c b/drivers/video/rockchip/rockchip_drm_vop2.c
> index 3a1c951ec7e4..f15ef1b57bf5 100644
> --- a/drivers/video/rockchip/rockchip_drm_vop2.c
> +++ b/drivers/video/rockchip/rockchip_drm_vop2.c
> @@ -743,10 +743,10 @@ static unsigned long rk3588_calc_dclk(unsigned long child_clk, unsigned long max
>   */
>  static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int id,
>  					 int *dclk_core_div, int *dclk_out_div,
> -					 int *if_pixclk_div, int *if_dclk_div)
> +					 int *if_pixclk_div, int *if_dclk_div,
> +					 u32 crtc_clock)
>  {
>  	struct vop2 *vop2 = vp->vop2;
> -	u32 crtc_clock = 0;
>  	unsigned long v_pixclk = crtc_clock * 1000LL; /* video timing pixclk */
>  	unsigned long dclk_core_rate = v_pixclk >> 2;
>  	unsigned long dclk_rate = v_pixclk;
> @@ -856,7 +856,7 @@ static unsigned long rk3588_set_intf_mux(struct vop2_video_port *vp, int id, u32
>  	u32 die, dip, div, vp_clk_div, val;
>  
>  	clock = rk3588_calc_cru_cfg(vp, id, &dclk_core_div, &dclk_out_div,
> -				    &if_pixclk_div, &if_dclk_div);
> +				    &if_pixclk_div, &if_dclk_div, clock);
>  	if (!clock)
>  		return 0;
>  
> -- 
> 2.39.5
> 
> 
> 

-- 
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-5555 |


From s.hauer at pengutronix.de  Fri Mar 14 09:04:44 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 17:04:44 +0100
Subject: [PATCH 00/22] add support for clang-analyzer with scan-build
In-Reply-To: <20250313073445.764875-1-a.fatoum@pengutronix.de>
References: <20250313073445.764875-1-a.fatoum@pengutronix.de>
Message-ID: <174196828407.4118485.17440201820843364791.b4-ty@pengutronix.de>


On Thu, 13 Mar 2025 08:34:23 +0100, Ahmad Fatoum wrote:
> With the changes, it's now possible to build barebox for sandbox
> with allyesconfig with clang under scan-build with:
> 
>   export LLVM=-19 # or whatever your clang suffix is if you've one
>   scan-build${LLVM} --use-cc=clang${LLVM} make
> 
> For this build to run to completion, a number of things that clang
> treats as errors need to be resolved as well, which is included
> in this series.
> 
> [...]

Applied, thanks!

[01/22] kbuild: add support for clang-analyzer with scan-build
        https://git.pengutronix.de/cgit/barebox/commit/?id=da3ab7931a95 (link may not be stable)
[02/22] soc: ti: k3-navss-ringacc: fix COMPILE_TEST link error
        https://git.pengutronix.de/cgit/barebox/commit/?id=8644f442f72e (link may not be stable)
[03/22] treewide: fix missing headers in sandbox allyesconfig
        https://git.pengutronix.de/cgit/barebox/commit/?id=38a389121b87 (link may not be stable)
[04/22] drivers: don't cast pointer directly to enum
        https://git.pengutronix.de/cgit/barebox/commit/?id=31fb717b4e27 (link may not be stable)
[05/22] firmware: arm_scmi: smc: compile only for ARM
        https://git.pengutronix.de/cgit/barebox/commit/?id=faf4a5da3f86 (link may not be stable)
[06/22] video: stm32-ltdc: fix printing uninitialized variable
        https://git.pengutronix.de/cgit/barebox/commit/?id=9c0ff56016a2 (link may not be stable)
[07/22] usb: core: remove unnecessary comparison
        https://git.pengutronix.de/cgit/barebox/commit/?id=049e56755631 (link may not be stable)
[08/22] ddr_spd: fix always true sub-condition
        https://git.pengutronix.de/cgit/barebox/commit/?id=2ad7e02e24c9 (link may not be stable)
[09/22] hush: fix make_string behavior on empty strings
        https://git.pengutronix.de/cgit/barebox/commit/?id=c884ea565a51 (link may not be stable)
[10/22] nvmem: fix clang-analyzer false-positive use of uninitialized value
        https://git.pengutronix.de/cgit/barebox/commit/?id=2e02e583f7c7 (link may not be stable)
[11/22] string: initialize string array in string selftest
        https://git.pengutronix.de/cgit/barebox/commit/?id=c807c954e141 (link may not be stable)
[12/22] commands: ubsan: hide zero division in test
        https://git.pengutronix.de/cgit/barebox/commit/?id=cb7953532da2 (link may not be stable)
[13/22] crypto: ecc: fix clang-analyzer warning about NULL dereference
        https://git.pengutronix.de/cgit/barebox/commit/?id=c7a1df25a191 (link may not be stable)
[14/22] mci_spi: fix possible use of uninitialized variable
        https://git.pengutronix.de/cgit/barebox/commit/?id=8a8f51a2f8a4 (link may not be stable)
[15/22] mtd: have mtd_read populate retlen always
        https://git.pengutronix.de/cgit/barebox/commit/?id=9d7580eb87bc (link may not be stable)
[16/22] of: fdt: silence possible static analyzer false positive
        https://git.pengutronix.de/cgit/barebox/commit/?id=44377ec41732 (link may not be stable)
[17/22] ubi: workaround zero division on malformed input in ubi_assert
        https://git.pengutronix.de/cgit/barebox/commit/?id=9e52dd5668eb (link may not be stable)
[18/22] video: Rockchip: fix zero division in rk3588_calc_cru_cfg
        https://git.pengutronix.de/cgit/barebox/commit/?id=fdd1c5bac55f (link may not be stable)
[19/22] lib: scatterlist: don't assert last element for empty sglist
        https://git.pengutronix.de/cgit/barebox/commit/?id=5a7f10a4b865 (link may not be stable)
[20/22] scripts: omap3-usb-loader: fix clang-analyzer false-positive
        https://git.pengutronix.de/cgit/barebox/commit/?id=06e3e7f29b98 (link may not be stable)
[21/22] clk: analogbits: wrpll-cln28hpc: bail out before zero division
        https://git.pengutronix.de/cgit/barebox/commit/?id=66daf4f16210 (link may not be stable)
[22/22] watchdog: stm32_iwdg: bail out before zero division
        https://git.pengutronix.de/cgit/barebox/commit/?id=8a4768c4ed82 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar 14 09:08:52 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 17:08:52 +0100
Subject: [PATCH v2 1/6] arch: move promptless options to end of Kconfig
 file
In-Reply-To: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
References: <20250313075416.3202194-1-a.fatoum@pengutronix.de>
Message-ID: <174196853230.4120026.15168346488074160951.b4-ty@pengutronix.de>


On Thu, 13 Mar 2025 08:54:11 +0100, Ahmad Fatoum wrote:
> Later commits will move many more promptless arch symbols into the file,
> so prepare for that by moving the current ones to the end and leave the
> options, which either have a prompt or are not boolean at the start.
> 
> 

Applied, thanks!

[1/6] arch: move promptless options to end of Kconfig file
      https://git.pengutronix.de/cgit/barebox/commit/?id=8b39ba47c150 (link may not be stable)
[2/6] RISC-V: rename HAS_CACHE to RISCV_ICACHE
      https://git.pengutronix.de/cgit/barebox/commit/?id=f1d533dda182 (link may not be stable)
[3/6] treewide: retire CONFIG_HAS_CACHE
      https://git.pengutronix.de/cgit/barebox/commit/?id=e341ed5e491a (link may not be stable)
[4/6] arch: move hidden arch options to arch/Kconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=31bcf8f64530 (link may not be stable)
[5/6] arch: move PHYS_ADDR_T_64BIT definition to arch/Kconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=d5ae6d2e03f0 (link may not be stable)
[6/6] x86: move CONFIG_PHYS_ADDR_T_64BIT setting into Kconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=decf1d12a597 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar 14 09:11:33 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 17:11:33 +0100
Subject: [PATCH] malloc: return ZERO_SIZE_PTR for 0-byte allocations
In-Reply-To: <20250313085658.13255-1-a.fatoum@pengutronix.de>
References: <20250313085658.13255-1-a.fatoum@pengutronix.de>
Message-ID: <174196869365.4120263.12791985060424280026.b4-ty@pengutronix.de>


On Thu, 13 Mar 2025 09:56:58 +0100, Ahmad Fatoum wrote:
> Linux kmalloc doesn't return NULL on 0-byte allocations, but returns a
> fixed ZERO_PSIZE_PTR constant, which triggers a NULL page exception when
> dereferenced.
> 
> However, in barebox, allocator behavior differs:
> 
>  - glibc returns an unique pointer, but the standard also allows
>    libc implementations to return NULL
>  - tlsf returns NULL
>  - dlmalloc returns a unique pointer
>  - dummy malloc returns a unique pointer
> 
> [...]

Applied, thanks!

[1/1] malloc: return ZERO_SIZE_PTR for 0-byte allocations
      https://git.pengutronix.de/cgit/barebox/commit/?id=3f5b270289be (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar 14 09:12:22 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 17:12:22 +0100
Subject: [PATCH v2 0/2] Move pca9450 RESET_CTRL configuration to driver
In-Reply-To: <20250313-pca9450-wdog-v2-0-28e97e7da480@pengutronix.de>
References: <20250313-pca9450-wdog-v2-0-28e97e7da480@pengutronix.de>
Message-ID: <174196874239.4122146.6496417535820786556.b4-ty@pengutronix.de>


On Thu, 13 Mar 2025 10:21:17 +0100, Jonas Rebmann wrote:
> Configure the RESET_CTRL register of the pca9450 pmic in the driver,
> like u-boot and kernel do. Subsequently, remove the setup of this
> register from the pca9450_register_init_callback of the two imx93 boards
> we currently have.
> 
> Configuration of this register in lowlevel.c of the imx8 boards remains
> untouched for now.
> 
> [...]

Applied, thanks!

[1/2] mfd: pca9450: configure pmic reset behavior
      https://git.pengutronix.de/cgit/barebox/commit/?id=36fc07dcd418 (link may not be stable)
[2/2] ARM: boards: remove obsolete PCA9450_RESET_CTRL setup
      https://git.pengutronix.de/cgit/barebox/commit/?id=86612dd9568d (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar 14 09:13:00 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 17:13:00 +0100
Subject: [PATCH v1 1/3] net: dsa: Add global forwarding mode support
In-Reply-To: <20250312112057.570001-1-o.rempel@pengutronix.de>
References: <20250312112057.570001-1-o.rempel@pengutronix.de>
Message-ID: <174196878072.4122330.5724496373208605972.b4-ty@pengutronix.de>


On Wed, 12 Mar 2025 12:20:55 +0100, Oleksij Rempel wrote:
> This patch introduces a global forwarding mode control for DSA switches
> in Barebox.  It adds a new `forwarding` parameter that allows enabling
> or disabling forwarding  between all ports on a DSA switch.
> 
> This enables users to configure global forwarding dynamically via:
> dev.switch0.forwarding=1  # Enable forwarding
> dev.switch0.forwarding=0  # Disable forwarding (isolated mode)
> 
> [...]

Applied, thanks!

[1/3] net: dsa: Add global forwarding mode support
      https://git.pengutronix.de/cgit/barebox/commit/?id=e49028e88017 (link may not be stable)
[2/3] Documentation: networking: Add DSA switch support documentation
      https://git.pengutronix.de/cgit/barebox/commit/?id=861b6fcd7943 (link may not be stable)
[3/3] net: dsa: sja1105: Add support for global forwarding mode
      https://git.pengutronix.de/cgit/barebox/commit/?id=816fb00dbf28 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar 14 09:13:41 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 17:13:41 +0100
Subject: [PATCH 1/2] net: am65-cpsw-nuss: depends on DMA support
In-Reply-To: <20250313095442.2812937-1-s.hauer@pengutronix.de>
References: <20250313095442.2812937-1-s.hauer@pengutronix.de>
Message-ID: <174196882144.4122563.6821951776974479558.b4-ty@pengutronix.de>


On Thu, 13 Mar 2025 10:54:41 +0100, Sascha Hauer wrote:
> The am65-cpsw-nuss needs DMA functions provided by CONFIG_DMADEVICES, so
> we must depend on this option to avoid linker errors. As the am65-cpsw-nuss
> is useless without the DMA hardware driver depend on CONFIG_TI_K3_UDMA
> instead which implies CONFIG_DMADEVICES.
> 
> 

Applied, thanks!

[1/2] net: am65-cpsw-nuss: depends on DMA support
      https://git.pengutronix.de/cgit/barebox/commit/?id=3c8f3959650e (link may not be stable)
[2/2] ARM: multi_v8_defconfig: enable k3 drivers
      https://git.pengutronix.de/cgit/barebox/commit/?id=a7d2d53f3e2f (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar 14 09:15:28 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 17:15:28 +0100
Subject: [PATCH] ARM: at91: Remove SAMA5D2 handling from sam9_smc
 driver
In-Reply-To: <20250307114739.3680956-1-eagle.alexander923@gmail.com>
References: <20250307114739.3680956-1-eagle.alexander923@gmail.com>
Message-ID: <174196892800.4122820.6862295502856355866.b4-ty@pengutronix.de>


On Fri, 07 Mar 2025 14:47:39 +0300, Alexander Shiyan wrote:
> SAMA5D2 SOC does not use sam9_smc driver.
> Let's remove handling of this SOC from driver code.
> 
> 

Applied, thanks!

[1/1] ARM: at91: Remove SAMA5D2 handling from sam9_smc driver
      https://git.pengutronix.de/cgit/barebox/commit/?id=6a825b7cfb7a (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Fri Mar 14 09:16:26 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Mar 2025 17:16:26 +0100
Subject: [PATCH] ARM: k3-r5_defconfig: enable eMMC boot partitions
In-Reply-To: <20250314144247.4074473-1-s.hauer@pengutronix.de>
References: <20250314144247.4074473-1-s.hauer@pengutronix.de>
Message-ID: <174196898617.4123020.3348261402469330658.b4-ty@pengutronix.de>


On Fri, 14 Mar 2025 15:42:47 +0100, Sascha Hauer wrote:
> Support for eMMC boot partition is needed to boot from eMMCs, enable
> it.
> 
> 

Applied, thanks!

[1/1] ARM: k3-r5_defconfig: enable eMMC boot partitions
      https://git.pengutronix.de/cgit/barebox/commit/?id=45b4345cdfc9 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From jmaselbas at zdiv.net  Fri Mar 14 13:53:21 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 21:53:21 +0100
Subject: [PATCH] treewide: use fallthrough pseudo keyword in switches
Message-ID: <20250314205321.16898-1-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 arch/arm/lib32/bootm.c           |  2 +-
 arch/arm/lib32/bootz.c           |  2 +-
 arch/arm/mach-mxs/imx.c          |  4 ++--
 commands/bthread.c               |  2 +-
 commands/edit.c                  | 14 +++++++-------
 commands/pwm.c                   |  2 +-
 common/console.c                 |  3 +--
 drivers/aiodev/lm75.c            |  2 +-
 drivers/mci/mci-core.c           |  4 +++-
 drivers/net/am65-cpsw-nuss.c     |  2 +-
 drivers/net/phy/mv88e6xxx/port.c |  1 +
 drivers/of/address.c             |  2 +-
 drivers/pci/pci-efi.c            |  2 +-
 drivers/reset/reset-imx7.c       | 14 +++++++-------
 drivers/usb/gadget/udc/fsl_udc.c |  2 +-
 drivers/usb/host/xhci-ring.c     |  2 +-
 drivers/video/atmel_lcdfb_core.c |  2 +-
 lib/vsprintf.c                   |  3 ++-
 18 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/arch/arm/lib32/bootm.c b/arch/arm/lib32/bootm.c
index d3a4d99a58..5be98b920b 100644
--- a/arch/arm/lib32/bootm.c
+++ b/arch/arm/lib32/bootm.c
@@ -479,7 +479,7 @@ static int do_bootz_linux(struct image_data *data)
 	switch (header->magic) {
 	case swab32(ZIMAGE_MAGIC):
 		swap = 1;
-		/* fall through */
+		fallthrough;
 	case ZIMAGE_MAGIC:
 		break;
 	default:
diff --git a/arch/arm/lib32/bootz.c b/arch/arm/lib32/bootz.c
index 7b3b32d418..8e8b0d225e 100644
--- a/arch/arm/lib32/bootz.c
+++ b/arch/arm/lib32/bootz.c
@@ -67,7 +67,7 @@ static int do_bootz(int argc, char *argv[])
 #ifdef CONFIG_BOOT_ENDIANNESS_SWITCH
 	case swab32(ZIMAGE_MAGIC):
 		swap = 1;
-		/* fall through */
+		fallthrough;
 #endif
 	case ZIMAGE_MAGIC:
 		break;
diff --git a/arch/arm/mach-mxs/imx.c b/arch/arm/mach-mxs/imx.c
index 2b4e682281..8abfa8e809 100644
--- a/arch/arm/mach-mxs/imx.c
+++ b/arch/arm/mach-mxs/imx.c
@@ -150,11 +150,11 @@ static void mxs_boot_save_loc(void)
 	switch (mode & 0xf) {
 	case 0x0: src = BOOTSOURCE_USB; break;		/* "USB" */
 	case 0x1: src = BOOTSOURCE_I2C_EEPROM; break;	/* "I2C, master" */
-	case 0x3: instance = 1;	/* fallthrough */	/* "SSP SPI #2, master, NOR" */
+	case 0x3: instance = 1;	fallthrough;		/* "SSP SPI #2, master, NOR" */
 	case 0x2: src = BOOTSOURCE_SPI_NOR; break;	/* "SSP SPI #1, master, NOR" */
 	case 0x4: src = BOOTSOURCE_NAND; break;		/* "NAND" */
 	case 0x8: src = BOOTSOURCE_SPI_EEPROM; break;	/* "SSP SPI #3, master, EEPROM" */
-	case 0xa: instance = 1;	/* fallthrough */	/* "SSP SD/MMC #1" */
+	case 0xa: instance = 1;	fallthrough;		/* "SSP SD/MMC #1" */
 	case 0x9: src = BOOTSOURCE_MMC; break;		/* "SSP SD/MMC #0" */
 	}
 
diff --git a/commands/bthread.c b/commands/bthread.c
index 00ff1837cc..7a16c6713d 100644
--- a/commands/bthread.c
+++ b/commands/bthread.c
@@ -191,7 +191,7 @@ static int do_bthread(int argc, char *argv[])
 			 */
 			list_add(&spawner->list, &spawners);
 
-			/* fallthrough */
+			fallthrough;
 		case 't':
 			time = true;
 		}
diff --git a/commands/edit.c b/commands/edit.c
index 893fa0271d..eda277d218 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -389,17 +389,17 @@ static int read_modal_key(bool is_modal)
 	case 'a':
 		statusbar("-- INSERT --");
 		mode = MODE_INSERT;
-		/* fall through */
+		fallthrough;
 	case 'l':
 		return BB_KEY_RIGHT;
 	case 'O':
 		backlog[0] = '\n';
 		backlog[1] = BB_KEY_UP;
-		/* fall through */
+		fallthrough;
 	case 'I':
 		statusbar("-- INSERT --");
 		mode = MODE_INSERT;
-		/* fall through */
+		fallthrough;
 	case '^':
 	case '0':
 		return BB_KEY_HOME;
@@ -409,22 +409,22 @@ static int read_modal_key(bool is_modal)
 			break;
 		backlog[0] = CTL_CH('u');
 		backlog[1] = CTL_CH('u');
-		/* fall through */
+		fallthrough;
 	case CTL_CH('u'):
 		return BB_KEY_PAGEUP;
 	case 'G':
 		backlog[0] = CTL_CH('d');
 		backlog[1] = CTL_CH('d');
-		/* fall through */
+		fallthrough;
 	case CTL_CH('d'):
 		return BB_KEY_PAGEDOWN;
 	case 'o':
 		backlog[0] = '\n';
-		/* fall through */
+		fallthrough;
 	case 'A':
 		statusbar("-- INSERT --");
 		mode = MODE_INSERT;
-		/* fall through */
+		fallthrough;
 	case '$':
 		return BB_KEY_END;
 	case CTL_CH('c'):
diff --git a/commands/pwm.c b/commands/pwm.c
index b86f865d55..fec6abe825 100644
--- a/commands/pwm.c
+++ b/commands/pwm.c
@@ -52,7 +52,7 @@ static int do_pwm_cmd(int argc, char *argv[])
 			/* convenience option for changing frequency without
 			 * having to specify duty width */
 			use_default_width = true;
-			/* fallthrough */
+			fallthrough;
 		case 'f':
 			freq = simple_strtol(optarg, NULL, 0);
 			break;
diff --git a/common/console.c b/common/console.c
index 136ed3b598..d5e4a96661 100644
--- a/common/console.c
+++ b/common/console.c
@@ -576,8 +576,7 @@ void console_putc(unsigned int ch, char c)
 	switch (init) {
 	case CONSOLE_UNINITIALIZED:
 		console_init_early();
-		/* fall through */
-
+		fallthrough;
 	case CONSOLE_INITIALIZED_BUFFER:
 		kfifo_putc(console_output_fifo, c);
 		if (c == '\n')
diff --git a/drivers/aiodev/lm75.c b/drivers/aiodev/lm75.c
index 86eac091d8..4685b41903 100644
--- a/drivers/aiodev/lm75.c
+++ b/drivers/aiodev/lm75.c
@@ -158,7 +158,7 @@ static int lm75_probe(struct device *dev)
 		data->resolution = 9;
 		break;
 	case mcp980x:
-		/* fall through */
+		fallthrough;
 	case tmp100:
 	case tmp101:
 		set_mask |= 3 << 5;		/* 12-bit mode */
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 8113b523cb..2049645ef6 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -3045,8 +3045,10 @@ void mci_of_parse_node(struct mci_host *host,
 		switch (bus_width) {
 		case 8:
 			host->host_caps |= MMC_CAP_8_BIT_DATA;
-		case 4: /* note fall through from above */
+			fallthrough;
+		case 4:
 			host->host_caps |= MMC_CAP_4_BIT_DATA;
+			fallthrough;
 		case 1:
 			break;
 		default:
diff --git a/drivers/net/am65-cpsw-nuss.c b/drivers/net/am65-cpsw-nuss.c
index f6dc811bd9..6add502902 100644
--- a/drivers/net/am65-cpsw-nuss.c
+++ b/drivers/net/am65-cpsw-nuss.c
@@ -245,7 +245,7 @@ static int am65_cpsw_gmii_sel_k3(struct am65_cpsw_port *port,
 		dev_warn(dev,
 			 "Unsupported PHY mode: %u. Defaulting to MII.\n",
 			 phy_mode);
-		/* fallthrough */
+		fallthrough;
 	case PHY_INTERFACE_MODE_MII:
 		mode = AM65_GMII_SEL_MODE_MII;
 		break;
diff --git a/drivers/net/phy/mv88e6xxx/port.c b/drivers/net/phy/mv88e6xxx/port.c
index 29ea4ec882..2b3d86ddda 100644
--- a/drivers/net/phy/mv88e6xxx/port.c
+++ b/drivers/net/phy/mv88e6xxx/port.c
@@ -219,6 +219,7 @@ static int mv88e6xxx_port_set_speed(struct mv88e6xxx_chip *chip, int port,
 		break;
 	case 10000:
 		/* all bits set, fall through... */
+		fallthrough;
 	case SPEED_UNFORCED:
 		ctrl = MV88E6XXX_PORT_MAC_CTL_SPEED_UNFORCED;
 		break;
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 03868406e2..c9b801e3fe 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -127,7 +127,7 @@ static unsigned int of_bus_pci_get_flags(const __be32 *addr)
 		break;
 	case 0x03: /* 64 bits */
 		flags |= IORESOURCE_MEM_64;
-		/* fallthrough */
+		fallthrough;
 	case 0x02: /* 32 bits */
 		flags |= IORESOURCE_MEM;
 		break;
diff --git a/drivers/pci/pci-efi.c b/drivers/pci/pci-efi.c
index b8cd663161..339a7ef673 100644
--- a/drivers/pci/pci-efi.c
+++ b/drivers/pci/pci-efi.c
@@ -176,7 +176,7 @@ static u8 *acpi_parse_resource(u8 *next, struct resource *out)
 		case ACPI_RESOURCE_TYPFLAG_MEM_PREF:
 			name = "P-MEM";
 			flags |= IORESOURCE_PREFETCH;
-			/* fallthrough */
+			fallthrough;
 		case ACPI_RESOURCE_TYPFLAG_MEM_WC:
 		case ACPI_RESOURCE_TYPFLAG_MEM_CACHEABLE:
 			flags |= IORESOURCE_CACHEABLE;
diff --git a/drivers/reset/reset-imx7.c b/drivers/reset/reset-imx7.c
index c6c38f48a8..4fea048199 100644
--- a/drivers/reset/reset-imx7.c
+++ b/drivers/reset/reset-imx7.c
@@ -209,7 +209,7 @@ static int imx8mq_reset_set(struct reset_controller_dev *rcdev,
 
 	switch (id) {
 	case IMX8MQ_RESET_PCIEPHY:
-	case IMX8MQ_RESET_PCIEPHY2: /* fallthrough */
+	case IMX8MQ_RESET_PCIEPHY2:
 		/*
 		 * wait for more than 10us to release phy g_rst and
 		 * btnrst
@@ -219,12 +219,12 @@ static int imx8mq_reset_set(struct reset_controller_dev *rcdev,
 		break;
 
 	case IMX8MQ_RESET_PCIE_CTRL_APPS_EN:
-	case IMX8MQ_RESET_PCIE2_CTRL_APPS_EN:	/* fallthrough */
-	case IMX8MQ_RESET_MIPI_DSI_PCLK_RESET_N:	/* fallthrough */
-	case IMX8MQ_RESET_MIPI_DSI_ESC_RESET_N:	/* fallthrough */
-	case IMX8MQ_RESET_MIPI_DSI_DPI_RESET_N:	/* fallthrough */
-	case IMX8MQ_RESET_MIPI_DSI_RESET_N:	/* fallthrough */
-	case IMX8MQ_RESET_MIPI_DSI_RESET_BYTE_N:	/* fallthrough */
+	case IMX8MQ_RESET_PCIE2_CTRL_APPS_EN:
+	case IMX8MQ_RESET_MIPI_DSI_PCLK_RESET_N:
+	case IMX8MQ_RESET_MIPI_DSI_ESC_RESET_N:
+	case IMX8MQ_RESET_MIPI_DSI_DPI_RESET_N:
+	case IMX8MQ_RESET_MIPI_DSI_RESET_N:
+	case IMX8MQ_RESET_MIPI_DSI_RESET_BYTE_N:
 		value = assert ? 0 : bit;
 		break;
 	}
diff --git a/drivers/usb/gadget/udc/fsl_udc.c b/drivers/usb/gadget/udc/fsl_udc.c
index 61861883ef..54fc0df655 100644
--- a/drivers/usb/gadget/udc/fsl_udc.c
+++ b/drivers/usb/gadget/udc/fsl_udc.c
@@ -250,7 +250,7 @@ static int dr_controller_setup(struct fsl_udc *udc)
 		break;
 	case FSL_USB2_PHY_UTMI_WIDE:
 		portctrl |= PORTSCX_PTW_16BIT;
-		/* fall through */
+		fallthrough;
 	case FSL_USB2_PHY_UTMI:
 		portctrl |= PORTSCX_PTS_UTMI;
 		break;
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 691d9c7463..00344e8074 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -609,7 +609,7 @@ static void record_transfer_result(struct usb_device *udev,
 	switch (GET_COMP_CODE(le32_to_cpu(event->trans_event.transfer_len))) {
 	case COMP_SUCCESS:
 		BUG_ON(udev->act_len != length);
-		/* fallthrough */
+		fallthrough;
 	case COMP_SHORT_TX:
 		udev->status = 0;
 		break;
diff --git a/drivers/video/atmel_lcdfb_core.c b/drivers/video/atmel_lcdfb_core.c
index 964b69867f..f2d7387b10 100644
--- a/drivers/video/atmel_lcdfb_core.c
+++ b/drivers/video/atmel_lcdfb_core.c
@@ -139,7 +139,7 @@ static int atmel_lcdfb_check_var(struct fb_info *info)
 	case 32:
 		info->transp.offset = 24;
 		info->transp.length = 8;
-		/* fall through */
+		fallthrough;
 	case 24:
 		if (sinfo->lcd_wiring_mode == ATMEL_LCDC_WIRING_RGB) {
 			/* RGB:888 mode */
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index cb42caebca..5f7c097dcd 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -336,7 +336,8 @@ char *uuid_string(char *buf, const char *end, const u8 *addr, int field_width,
 
 	switch (*(++fmt)) {
 	case 'L':
-		uc = true;		/* fall-through */
+		uc = true;
+		fallthrough;
 	case 'l':
 		index = le;
 		break;
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 14:18:30 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 22:18:30 +0100
Subject: [PATCH] fixup! treewide: use fallthrough pseudo keyword in switches
In-Reply-To: <20250314205321.16898-1-jmaselbas@zdiv.net>
References: <20250314205321.16898-1-jmaselbas@zdiv.net>
Message-ID: <20250314211830.24629-1-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 commands/edit.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/commands/edit.c b/commands/edit.c
index eda277d218..fcf8ad90f5 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -453,6 +453,7 @@ static int read_modal_key(bool is_modal)
 			return CTL_CH('d');
 		if (c == 'Q')
 			return CTL_CH('c');
+		fallthrough;
 	default:
 		statusbar("ERROR: not implemented");
 		break;
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 14:33:44 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 22:33:44 +0100
Subject: [PATCH] commands: hwclock: replace strncpy with strlcpy
Message-ID: <20250314213344.12335-1-jmaselbas@zdiv.net>

strncpy could leave the rtc_name buffer not nul-terminated, strlcpy will
always nul-terminate the dst buffer.
Also replace the hardcoded size with sizeof(rtc_name)

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 commands/hwclock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/hwclock.c b/commands/hwclock.c
index c594e070ac..33829e4118 100644
--- a/commands/hwclock.c
+++ b/commands/hwclock.c
@@ -95,7 +95,7 @@ static int do_hwclock(int argc, char *argv[])
 
 		switch (opt) {
 		case 'f':
-			strncpy(rtc_name, optarg, 16);
+			strlcpy(rtc_name, optarg, sizeof(rtc_name));
 			break;
 		case 's':
 			memset(&stm, 0, sizeof(stm));
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 15:30:07 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 23:30:07 +0100
Subject: [PATCH] commands: of_display_timings: prevent memory leak
Message-ID: <20250314223007.26457-1-jmaselbas@zdiv.net>

memory could be leaked if the S option is passed several time.
Also replace the xzalloc + strcpy call with a call to xstrdup.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 commands/of_display_timings.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/commands/of_display_timings.c b/commands/of_display_timings.c
index 232074fce7..5998d42ffe 100644
--- a/commands/of_display_timings.c
+++ b/commands/of_display_timings.c
@@ -42,7 +42,7 @@ static int do_of_display_timings(int argc, char *argv[])
 	struct device_node *root = NULL;
 	struct device_node *display = NULL;
 	struct device_node *timings = NULL;
-	char *timingpath = NULL;
+	const char *timingpath = NULL;
 	char *dtbfile = NULL;
 
 	while ((opt = getopt(argc, argv, "sS:lf:")) > 0) {
@@ -57,8 +57,7 @@ static int do_of_display_timings(int argc, char *argv[])
 			selected = 1;
 			break;
 		case 'S':
-			timingpath = xzalloc(strlen(optarg) + 1);
-			strcpy(timingpath, optarg);
+			timingpath = optarg;
 			break;
 		default:
 			return COMMAND_ERROR_USAGE;
@@ -108,7 +107,7 @@ static int do_of_display_timings(int argc, char *argv[])
 	}
 
 	if (timingpath)
-		of_register_fixup(of_display_timing, timingpath);
+		of_register_fixup(of_display_timing, xstrdup(timingpath));
 
 	return 0;
 }
-- 
2.48.1



From jmaselbas at zdiv.net  Fri Mar 14 15:44:39 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Fri, 14 Mar 2025 23:44:39 +0100
Subject: [PATCH] mci: sunxi-mmc: do not log error message on EINVAL error
Message-ID: <20250314224439.30069-1-jmaselbas@zdiv.net>

In the function sdxc_send_cmd: logging the error could use the
uninitialized variable `why`, this can be the case when the
sunxi_mmc_send_cmd function returns very early with the -EINVAL
error code. This doesnt needs to be logged.
Also add a default value for the variable.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/mci/sunxi-mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mci/sunxi-mmc.c b/drivers/mci/sunxi-mmc.c
index a19abbe55d..376ef2c0a9 100644
--- a/drivers/mci/sunxi-mmc.c
+++ b/drivers/mci/sunxi-mmc.c
@@ -24,11 +24,11 @@ static int sdxc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd, struct mci_d
 {
 	struct sunxi_mmc_host *host = to_sunxi_mmc_host(mci);
 	struct device *dev = mci->hw_dev;
-	const char *why;
+	const char *why = "";
 	int ret;
 
 	ret = sunxi_mmc_send_cmd(host, cmd, data, &why);
-	if (ret && ret != -ETIMEDOUT)
+	if (ret && ret != -ETIMEDOUT && ret != -EINVAL)
 		dev_err(dev, "error %s CMD%d (%d)\n", why, cmd->cmdidx, ret);
 	if (ret == -ETIMEDOUT)
 		mdelay(1);
-- 
2.48.1



From o.rempel at pengutronix.de  Sat Mar 15 06:52:45 2025
From: o.rempel at pengutronix.de (Oleksij Rempel)
Date: Sat, 15 Mar 2025 14:52:45 +0100
Subject: [PATCH v2] commands: Add `ip` command for listing interfaces, addresses, and routes
Message-ID: <20250315135245.2729171-1-o.rempel@pengutronix.de>

This patch introduces the `ip` command, providing functionality similar
to Linux?s `ip` tool, catering to users with strong Linux muscle memory.
It supports:

- `ip l` / `ip link`   - Show network interfaces (state, MAC address)
- `ip a` / `ip addr`   - Show assigned IP addresses and netmasks
- `ip r` / `ip route`  - Show routing table, including default gateway,
                         interface-specific routes, DNS, and server IP.

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
changes v2:
- add SPDX
- fix help in Kconfig
- add support for range of commands
- use COMMAND_ERROR_USAGE
---
 commands/Kconfig  |   9 +++
 commands/Makefile |   1 +
 commands/ip.c     | 159 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 169 insertions(+)
 create mode 100644 commands/ip.c

diff --git a/commands/Kconfig b/commands/Kconfig
index fe459fa862f5..466afa7fa479 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1397,6 +1397,15 @@ config CMD_TFTP
 	  Options:
 		  -p	push to TFTP server
 
+config CMD_IP
+	tristate
+	prompt "ip"
+	default y
+	help
+	  This command provides information about network interfaces, similar
+	  to the Linux `ip addr show` command. It lists interface names, states
+	  (UP/DOWN), MAC addresses, and assigned IP addresses.
+
 config CMD_IP_ROUTE_GET
 	tristate
 	prompt "ip-route-get"
diff --git a/commands/Makefile b/commands/Makefile
index e152e4148b04..c202cdef5703 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -146,6 +146,7 @@ obj-$(CONFIG_CMD_MMC)		+= mmc.o
 obj-$(CONFIG_CMD_MMC_EXTCSD)	+= mmc_extcsd.o
 obj-$(CONFIG_CMD_NAND_BITFLIP)	+= nand-bitflip.o
 obj-$(CONFIG_CMD_SEED)		+= seed.o
+obj-$(CONFIG_CMD_IP)		+= ip.o
 obj-$(CONFIG_CMD_IP_ROUTE_GET)  += ip-route-get.o
 obj-$(CONFIG_CMD_BTHREAD)	+= bthread.o
 obj-$(CONFIG_CMD_UBSAN)		+= ubsan.o
diff --git a/commands/ip.c b/commands/ip.c
new file mode 100644
index 000000000000..76a84804c002
--- /dev/null
+++ b/commands/ip.c
@@ -0,0 +1,159 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: ? 2025 Oleksij Rempel <o.rempel at pengutronix.de>
+
+#include <common.h>
+#include <command.h>
+#include <net.h>
+#include <linux/list.h>
+#include <complete.h>
+
+/* Function to calculate CIDR prefix from netmask */
+static int netmask_to_prefix(IPaddr_t netmask)
+{
+	int prefix = 0;
+
+	while (netmask) {
+		prefix += netmask & 1;
+		netmask >>= 1;
+	}
+
+	return prefix;
+}
+
+/* Function to display network links (`ip l`) */
+static int do_ip_link(int argc, char *argv[])
+{
+	struct eth_device *edev;
+
+	for_each_netdev(edev) {
+		const char *phy_status = edev->phydev ?
+			(edev->phydev->link ? ",LOWER_UP" : ",NO-CARRIER") : "";
+
+		printf("%s: <%s%s>\n",
+			   eth_name(edev),
+			   edev->active ? "UP" : "DOWN",
+			   phy_status);
+
+		printf("	link/ether %pM brd ff:ff:ff:ff:ff:ff\n",
+		       edev->ethaddr);
+	}
+
+	return 0;
+}
+
+/* Function to display network addresses (`ip a`) */
+static int do_ip_addr(int argc, char *argv[])
+{
+	struct eth_device *edev;
+
+	for_each_netdev(edev) {
+		IPaddr_t ipaddr = net_get_ip(edev);
+		int prefix_length = netmask_to_prefix(edev->netmask);
+		const char *phy_status = edev->phydev ?
+			(edev->phydev->link ? ",LOWER_UP" : ",NO-CARRIER") : "";
+
+		printf("%s: <%s%s>\n", eth_name(edev),
+		       edev->active ? "UP" : "DOWN", phy_status);
+
+		printf("	link/ether %pM brd ff:ff:ff:ff:ff:ff\n",
+		       edev->ethaddr);
+
+		if (ipaddr) {
+			printf("	inet %pI4/%d scope global src %pI4\n",
+				   &ipaddr, prefix_length, &ipaddr);
+		}
+	}
+
+	return 0;
+}
+
+/* Function to display network routes (`ip r`) */
+static int do_ip_route(int argc, char *argv[])
+{
+	const char *domainname = net_get_domainname();
+	IPaddr_t nameserver = net_get_nameserver();
+	const char *serverip = net_get_server();
+	IPaddr_t gateway = net_get_gateway();
+	struct eth_device *edev;
+
+	for_each_netdev(edev) {
+		int prefix_length = netmask_to_prefix(edev->netmask);
+		IPaddr_t ipaddr = net_get_ip(edev);
+		const char *proto;
+
+		/* Skip interfaces without an IP address */
+		if (!ipaddr)
+			continue;
+
+		/* Determine protocol: DHCP or Static */
+		if (edev->global_mode == ETH_MODE_DHCP)
+			proto = "dhcp";
+		else
+			proto = "static";
+
+		/* Show default gateway */
+		if (gateway) {
+			printf("default via %pI4 dev %s proto %s src %pI4\n",
+				   &gateway, eth_name(edev), proto, &ipaddr);
+		}
+
+		/* Show per-interface network route */
+		if (prefix_length > 0) {
+			printf("%pI4/%d dev %s proto kernel scope link src %pI4\n",
+				   &ipaddr, prefix_length, eth_name(edev),
+				   &ipaddr);
+		}
+	}
+
+	/* Show boot server */
+	if (serverip && *serverip)
+		printf("serverip %s\n", serverip);
+
+	/* Show DNS server */
+	if (nameserver)
+		printf("nameserver %pI4\n", &nameserver);
+
+	/* Show search domain */
+	if (domainname && *domainname)
+		printf("search %s\n", domainname);
+
+	return 0;
+}
+
+/* Main IP command dispatcher */
+static int do_ip(int argc, char *argv[])
+{
+	size_t arglen;
+
+	if (argc < 2)
+		return do_ip_addr(argc, argv); /* Default: `ip a` */
+
+	arglen = strlen(argv[1]);
+
+	if ((arglen <= strlen("link")) && !strncmp(argv[1], "link", arglen))
+		return do_ip_link(argc, argv);
+	else if ((arglen <= strlen("addr")) && !strncmp(argv[1], "addr", arglen))
+		return do_ip_addr(argc, argv);
+	else if ((arglen <= strlen("route")) && !strncmp(argv[1], "route", arglen))
+		return do_ip_route(argc, argv);
+
+	return COMMAND_ERROR_USAGE;
+}
+
+BAREBOX_CMD_HELP_START(ip)
+BAREBOX_CMD_HELP_TEXT("Show network interfaces, addresses, and routes")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("l, link", "Show only network links (interface state and MAC)")
+BAREBOX_CMD_HELP_OPT("a, addr", "Show only network addresses (default behavior)")
+BAREBOX_CMD_HELP_OPT("r, route", "Show routing information (default gateway, network routes, server IP, DNS)")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(ip)
+	.cmd		= do_ip,
+	BAREBOX_CMD_DESC("Show network interfaces, addresses, and routes")
+	BAREBOX_CMD_OPTS("[l|link] | [a|addr] | [r|route]")
+	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+	BAREBOX_CMD_COMPLETE(empty_complete)
+	BAREBOX_CMD_HELP(cmd_ip_help)
+BAREBOX_CMD_END
-- 
2.39.5



From s.hauer at pengutronix.de  Mon Mar 17 00:44:37 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 08:44:37 +0100
Subject: [PATCH 11/11] fs: qemu_fw_cfg: support populating environment
 via QEMU fw_cfg
In-Reply-To: <20250313101728.3546902-12-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
 <20250313101728.3546902-12-a.fatoum@pengutronix.de>
Message-ID: <Z9fS5ZZzEDheZMJh@pengutronix.de>

Hi Ahmad,

On Thu, Mar 13, 2025 at 11:17:28AM +0100, Ahmad Fatoum wrote:
> diff --git a/fs/qemu_fw_cfg.c b/fs/qemu_fw_cfg.c
> index 7f7350e67e64..ef2a1008ee5d 100644
> --- a/fs/qemu_fw_cfg.c
> +++ b/fs/qemu_fw_cfg.c
> @@ -13,6 +13,7 @@
>  #include <errno.h>
>  #include <linux/stat.h>
>  #include <xfuncs.h>
> +#include <envfs.h>
>  #include <fcntl.h>
>  #include <linux/qemu_fw_cfg.h>
>  #include <wchar.h>
> @@ -363,7 +364,13 @@ static int fw_cfg_fs_probe(struct device *dev)
>  	 */
>  	fsdev->cdev = cdev_by_name(devpath_to_name(fsdev->backingstore));
>  
> -	return fw_cfg_fs_parse(sb);
> +	ret = fw_cfg_fs_parse(sb);
> +	if (ret)
> +		goto free_data;
> +
> +	defaultenv_append_runtime_directory("/mnt/fw_cfg/by_name/opt/org.barebox.env");

I see the variables show up in /mnt/fw_cfg/by_name/opt/org.barebox.env/,
but not in the environment.

I wonder how this is supposed to work. The fw_cfg fs is mounted when I
first access /mnt/fw_cfg on the barebox command line, but at that time
defaultenv_append_runtime_directory() has no effect anymore as
defaultenv_load() is executed during startup.

Should defaultenv_append_runtime_directory() be called in
qemu_fw_cfg_fs_init() instead?

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Mon Mar 17 01:21:16 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 09:21:16 +0100
Subject: [PATCH 05/11] fs: add qemu_fw_cfg file system
In-Reply-To: <20250313101728.3546902-6-a.fatoum@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
 <20250313101728.3546902-6-a.fatoum@pengutronix.de>
Message-ID: <Z9fbfE-1IZr44IUs@pengutronix.de>

Hi Ahmad,

On Thu, Mar 13, 2025 at 11:17:22AM +0100, Ahmad Fatoum wrote:
> +static int fw_cfg_fs_io(struct device *dev, struct file *f, void *buf,
> +			 size_t insize, bool read)
> +{
> +	struct inode *inode = f->f_inode;
> +	struct fw_cfg_fs_inode *node = inode_to_node(inode);
> +	struct fw_cfg_fs_data *data = dev->priv;
> +	int fd = data->fd;
> +
> +	if (node->buf) {
> +		if (read)
> +			memcpy(buf, node->buf + f->f_pos, insize);
> +		else
> +			memcpy(node->buf + f->f_pos, buf, insize);
> +		return insize;
> +	}
> +
> +	ioctl(fd, FW_CFG_SELECT, &(u16) { inode->i_ino });
> +
> +	if (read)
> +		return pread(fd, buf, insize, f->f_pos);
> +	else
> +		return pwrite(fd, buf, insize, f->f_pos);
> +}
> +
> +static int fw_cfg_fs_read(struct device *dev, struct file *f, void *buf,
> +			   size_t insize)
> +{
> +	return fw_cfg_fs_io(dev, f, buf, insize, true);
> +}
> +
> +static int fw_cfg_fs_write(struct device *dev, struct file *f, const void *buf,
> +			    size_t insize)
> +{
> +	return fw_cfg_fs_io(dev, f, (void *)buf, insize, false);
> +}
> +
> +static int fw_cfg_fw_truncate(struct device *dev, struct file *f, loff_t size)
> +{
> +	return 0;
> +}

By returning 0 here you claim that the file can get an arbitrary size.

node->buf is a fixed size buffer. If I understand correctly then
node->buf is only used for special files like "name", "raw".

However, writing to these files is not prohibited, consequently a
cp /dev/ram0 /mnt/fw_cfg//by_key/37/key results in memory corrupions.

Writing data to a file I passed via --env truncates the file to the
written data size, but the actual content of the file is unchanged. I
still read back the original data. Is writing data supported?

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Mon Mar 17 01:31:08 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 09:31:08 +0100
Subject: [PATCH 1/2] eeprom: at25: replace strncpy with strlcpy
In-Reply-To: <20250314104502.14851-1-jmaselbas@zdiv.net>
References: <20250314104502.14851-1-jmaselbas@zdiv.net>
Message-ID: <174220026891.4058046.4189677646354482989.b4-ty@pengutronix.de>


On Fri, 14 Mar 2025 11:45:01 +0100, Jules Maselbas wrote:
> strncpy will not nul terminate the dst string in case the src is longer
> than the the dst size, strlcpy will truncate and nul terminate the string.
> 
> 

Applied, thanks!

[1/2] eeprom: at25: replace strncpy with strlcpy
      https://git.pengutronix.de/cgit/barebox/commit/?id=8265cfe43587 (link may not be stable)
[2/2] eeprom: at25: add explicit fallthrough
      https://git.pengutronix.de/cgit/barebox/commit/?id=6a2c56c934d1 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 01:32:20 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 09:32:20 +0100
Subject: [PATCH] common: deep-probe: make
 __barebox_deep_probe_{start,end} of array type
In-Reply-To: <20250314143254.21753-1-jmaselbas@zdiv.net>
References: <20250314143254.21753-1-jmaselbas@zdiv.net>
Message-ID: <174220034098.4058539.3704906446314246480.b4-ty@pengutronix.de>


On Fri, 14 Mar 2025 15:32:54 +0100, Jules Maselbas wrote:
> 


Applied, thanks!

[1/1] common: deep-probe: make __barebox_deep_probe_{start,end} of array type
      https://git.pengutronix.de/cgit/barebox/commit/?id=103efa5dbce1 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 01:33:50 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 09:33:50 +0100
Subject: [PATCH v2 0/3] compile test cleanups
In-Reply-To: <20250314150953.21686-1-jmaselbas@zdiv.net>
References: <20250314104034.13637-1-jmaselbas@zdiv.net>
 <20250314150953.21686-1-jmaselbas@zdiv.net>
Message-ID: <174220043080.4058802.12375043418375087659.b4-ty@pengutronix.de>


On Fri, 14 Mar 2025 16:09:49 +0100, Jules Maselbas wrote:
> Small cleanups patches
> 
> v2:
>  - rebased on Ahmad clang-analyzer series, and dropped spurious changes
> 
> Jules Maselbas (3):
>   dma-devices: k3-udma: remove duplicated include
>   dma-devices: k3-udma: use snprintf instead of sprintf
>   pmdomain: ti-k3: remove trailing whitespace
> 
> [...]

Applied, thanks!

[1/3] dma-devices: k3-udma: remove duplicated include
      https://git.pengutronix.de/cgit/barebox/commit/?id=277212d7458b (link may not be stable)
[2/3] dma-devices: k3-udma: use snprintf instead of sprintf
      https://git.pengutronix.de/cgit/barebox/commit/?id=4674d4c8044f (link may not be stable)
[3/3] pmdomain: ti-k3: remove trailing whitespace
      https://git.pengutronix.de/cgit/barebox/commit/?id=2ecff68dabdd (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 01:37:05 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 09:37:05 +0100
Subject: [PATCH] mci: sunxi-mmc: do not log error message on EINVAL
 error
In-Reply-To: <20250314224439.30069-1-jmaselbas@zdiv.net>
References: <20250314224439.30069-1-jmaselbas@zdiv.net>
Message-ID: <174220062501.4059183.4020811691451908069.b4-ty@pengutronix.de>


On Fri, 14 Mar 2025 23:44:39 +0100, Jules Maselbas wrote:
> In the function sdxc_send_cmd: logging the error could use the
> uninitialized variable `why`, this can be the case when the
> sunxi_mmc_send_cmd function returns very early with the -EINVAL
> error code. This doesnt needs to be logged.
> Also add a default value for the variable.
> 
> 
> [...]

Applied, thanks!

[1/1] mci: sunxi-mmc: do not log error message on EINVAL error
      https://git.pengutronix.de/cgit/barebox/commit/?id=6a98ccdcf5ca (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 01:38:22 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 09:38:22 +0100
Subject: [PATCH] commands: of_display_timings: prevent memory leak
In-Reply-To: <20250314223007.26457-1-jmaselbas@zdiv.net>
References: <20250314223007.26457-1-jmaselbas@zdiv.net>
Message-ID: <174220070282.4061036.12798849830895781197.b4-ty@pengutronix.de>


On Fri, 14 Mar 2025 23:30:07 +0100, Jules Maselbas wrote:
> memory could be leaked if the S option is passed several time.
> Also replace the xzalloc + strcpy call with a call to xstrdup.
> 
> 

Applied, thanks!

[1/1] commands: of_display_timings: prevent memory leak
      https://git.pengutronix.de/cgit/barebox/commit/?id=5b43643625b2 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 01:42:19 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 09:42:19 +0100
Subject: [PATCH] commands: hwclock: replace strncpy with strlcpy
In-Reply-To: <20250314213344.12335-1-jmaselbas@zdiv.net>
References: <20250314213344.12335-1-jmaselbas@zdiv.net>
Message-ID: <Z9fga36NGkFsrZ82@pengutronix.de>

Hi Jules,

On Fri, Mar 14, 2025 at 10:33:44PM +0100, Jules Maselbas wrote:
> strncpy could leave the rtc_name buffer not nul-terminated, strlcpy will
> always nul-terminate the dst buffer.
> Also replace the hardcoded size with sizeof(rtc_name)
> 
> Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
> ---
>  commands/hwclock.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/commands/hwclock.c b/commands/hwclock.c
> index c594e070ac..33829e4118 100644
> --- a/commands/hwclock.c
> +++ b/commands/hwclock.c
> @@ -95,7 +95,7 @@ static int do_hwclock(int argc, char *argv[])
>  
>  		switch (opt) {
>  		case 'f':
> -			strncpy(rtc_name, optarg, 16);
> +			strlcpy(rtc_name, optarg, sizeof(rtc_name));
>  			break;

rtc_name is an array for no good reason. Can we just do a

const char *rtc_name = "rtc0";

		case 'f':
			rtc_name = optarg;

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Mon Mar 17 01:43:14 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 09:43:14 +0100
Subject: [PATCH] regulator: fan53555: suppress warning about
 uninitialized variable
In-Reply-To: <20250314152437.25675-1-jmaselbas@zdiv.net>
References: <20250314152437.25675-1-jmaselbas@zdiv.net>
Message-ID: <174220099476.4061406.12703222009405718514.b4-ty@pengutronix.de>


On Fri, 14 Mar 2025 16:24:37 +0100, Jules Maselbas wrote:
> In function 'fan53555_device_setup', a call to 'regmap_update_bits' is
> made with the mode_mask variable potentially uninitialized.
> 
> This can be the case if di->vendor is FAN53526_VENDOR_FAIRCHILD and
> di->sleep_vsel_id is not handled by the case (neither FAN53555_VSEL_ID_0 nor FAN53555_VSEL_ID_1).
> I am not sure how likely it is to happen.
> 
> [...]

Applied, thanks!

[1/1] regulator: fan53555: suppress warning about uninitialized variable
      https://git.pengutronix.de/cgit/barebox/commit/?id=55d10d7aa06f (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 01:51:10 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 09:51:10 +0100
Subject: (subset) [PATCH] treewide: use fallthrough pseudo keyword in
 switches
In-Reply-To: <20250314205321.16898-1-jmaselbas@zdiv.net>
References: <20250314205321.16898-1-jmaselbas@zdiv.net>
Message-ID: <174220147012.4062446.2175121099935247908.b4-ty@pengutronix.de>


On Fri, 14 Mar 2025 21:53:21 +0100, Jules Maselbas wrote:
> 


Applied, thanks!

[1/1] treewide: use fallthrough pseudo keyword in switches
      https://git.pengutronix.de/cgit/barebox/commit/?id=9f644e676574 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 01:51:59 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 09:51:59 +0100
Subject: [PATCH 1/2] sandbox: sdl: fix compilation on musl-libc
In-Reply-To: <20250314151441.23223-1-jmaselbas@zdiv.net>
References: <20250314151441.23223-1-jmaselbas@zdiv.net>
Message-ID: <174220151954.4062626.12314255702218142979.b4-ty@pengutronix.de>


On Fri, 14 Mar 2025 16:14:40 +0100, Jules Maselbas wrote:
> fails to compile with "unknown type name 'loff_t'; did you mean 'off_t'"
> error, add missing include and also define _GNU_SOURCE
> 
> 

Applied, thanks!

[1/2] sandbox: sdl: fix compilation on musl-libc
      https://git.pengutronix.de/cgit/barebox/commit/?id=27e3970894ae (link may not be stable)
[2/2] sandbox: sdl: make window variable static
      https://git.pengutronix.de/cgit/barebox/commit/?id=a9d38c42fe4a (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 01:56:02 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 09:56:02 +0100
Subject: [PATCH 1/2] firmware: export firmware directory
In-Reply-To: <20250314094559.3631184-1-s.hauer@pengutronix.de>
References: <20250314094559.3631184-1-s.hauer@pengutronix.de>
Message-ID: <174220176292.4064829.27224376056409189.b4-ty@pengutronix.de>


On Fri, 14 Mar 2025 10:45:58 +0100, Sascha Hauer wrote:
> The recently added k3r5 code needs firmware blobs as part of the image
> generation. It hardcodes the firmware path to $(srctree)/firmware which
> is the default, but could changed with CONFIG_EXTRA_FIRMWARE_DIR.
> 
> Move setting of $(fwdir) to the toplevel Makefile and export it to make
> it available to images/Makefile.k3. As fwdir is a bad name for an
> exported variable rename it to FIRMWARE_DIR.
> 
> [...]

Applied, thanks!

[1/2] firmware: export firmware directory
      https://git.pengutronix.de/cgit/barebox/commit/?id=906ecf8c9c37 (link may not be stable)
[2/2] ARM: k3r5: Honour CONFIG_EXTRA_FIRMWARE_DIR
      https://git.pengutronix.de/cgit/barebox/commit/?id=78ebaea8ebd0 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 02:05:54 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 10:05:54 +0100
Subject: [PATCH v2] commands: Add `ip` command for listing interfaces,
 addresses, and routes
In-Reply-To: <20250315135245.2729171-1-o.rempel@pengutronix.de>
References: <20250315135245.2729171-1-o.rempel@pengutronix.de>
Message-ID: <174220235474.4066001.6991372267478942347.b4-ty@pengutronix.de>


On Sat, 15 Mar 2025 14:52:45 +0100, Oleksij Rempel wrote:
> This patch introduces the `ip` command, providing functionality similar
> to Linux?s `ip` tool, catering to users with strong Linux muscle memory.
> It supports:
> 
> - `ip l` / `ip link`   - Show network interfaces (state, MAC address)
> - `ip a` / `ip addr`   - Show assigned IP addresses and netmasks
> - `ip r` / `ip route`  - Show routing table, including default gateway,
>                          interface-specific routes, DNS, and server IP.
> 
> [...]

Applied, thanks!

[1/1] commands: Add `ip` command for listing interfaces, addresses, and routes
      https://git.pengutronix.de/cgit/barebox/commit/?id=35e565ec63ab (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 02:07:17 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 10:07:17 +0100
Subject: [PATCH v2] commands: Add `ip` command for listing interfaces,
 addresses, and routes
In-Reply-To: <20250315135245.2729171-1-o.rempel@pengutronix.de>
References: <20250315135245.2729171-1-o.rempel@pengutronix.de>
Message-ID: <Z9fmReMijNznh7FK@pengutronix.de>

On Sat, Mar 15, 2025 at 02:52:45PM +0100, Oleksij Rempel wrote:
> This patch introduces the `ip` command, providing functionality similar
> to Linux?s `ip` tool, catering to users with strong Linux muscle memory.
> It supports:
> 
> - `ip l` / `ip link`   - Show network interfaces (state, MAC address)
> - `ip a` / `ip addr`   - Show assigned IP addresses and netmasks
> - `ip r` / `ip route`  - Show routing table, including default gateway,
>                          interface-specific routes, DNS, and server IP.
> 
> Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
> ---
> changes v2:
> - add SPDX
> - fix help in Kconfig
> - add support for range of commands
> - use COMMAND_ERROR_USAGE
> ---
>  commands/Kconfig  |   9 +++
>  commands/Makefile |   1 +
>  commands/ip.c     | 159 ++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 169 insertions(+)
>  create mode 100644 commands/ip.c
> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index fe459fa862f5..466afa7fa479 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -1397,6 +1397,15 @@ config CMD_TFTP
>  	  Options:
>  		  -p	push to TFTP server
>  
> +config CMD_IP
> +	tristate
> +	prompt "ip"
> +	default y

Dropped the default y while applying.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Mon Mar 17 02:21:28 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 10:21:28 +0100
Subject: [PATCH 1/2] MAKEALL: support direct options for KCONFIG_ADD
In-Reply-To: <20250313113604.915474-1-a.fatoum@pengutronix.de>
References: <20250313113604.915474-1-a.fatoum@pengutronix.de>
Message-ID: <Z9fpmOzuQh7G4WW_@pengutronix.de>

On Thu, Mar 13, 2025 at 12:36:03PM +0100, Ahmad Fatoum wrote:
> KCONFIG_ADD currently expects a list of files to be merged.
> As MAKEALL is a bash script, let's make use of process substitution
> to create temporary files out of -k CONFIG_foo=bar options.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  MAKEALL | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/MAKEALL b/MAKEALL
> index 1966eedb4673..b0967b8ae340 100755
> --- a/MAKEALL
> +++ b/MAKEALL
> @@ -56,7 +56,7 @@ usage() {
>  	echo "BUILDDIR    -O      build dir"
>  	echo "LOGDIR      -l      log dir"
>  	echo "REGEX       -e      regex"
> -	echo "KCONFIG_ADD -k      kconfig fragment"
> +	echo "KCONFIG_ADD -k      kconfig fragment or option"
>  	echo "TARGET      -t      Makefile target"
>  	echo "V           -v      verbosity"
>  	echo "INCREMENTAL -i"
> @@ -116,6 +116,11 @@ report() {
>  	fi
>  }
>  
> +merge_config() {
> +	with_logs_collected ./scripts/kconfig/merge_config.sh -m -O \
> +		${BUILDDIR} "$@"
> +}
> +
>  do_build_defconfig() {
>  	local arch=$1
>  	local defconfig=$2
> @@ -156,8 +161,11 @@ do_build_defconfig() {
>  	MAKE="${MAKE} $silent_flag CROSS_COMPILE=${cross_compile}"
>  	with_logs_collected ${MAKE} ${defconfig}
>  	for i in ${KCONFIG_ADD}; do
> -		with_logs_collected ./scripts/kconfig/merge_config.sh -m -O \
> -			${BUILDDIR} ${BUILDDIR}/.config $i
> +		if [[ $i =~ ^CONFIG_* ]]; then

'_*' matches zero or more underscores which is likely not what you mean
here.

How about ^CONFIG_.*=.* which also tests for the equal sign.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Mon Mar 17 02:34:37 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 10:34:37 +0100
Subject: [PATCH 5/6] mci: mci_spi: fix warning message
In-Reply-To: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
References: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
Message-ID: <20250317-mci-misc-cleanup-v1-5-24b4d6f5d31a@pengutronix.de>

The driver warns about a missing reset GPIO, but it is the card detect
GPIO that is searched for. Fix the warning message.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mci/mci_spi.c b/drivers/mci/mci_spi.c
index 41d788704f..864e15a416 100644
--- a/drivers/mci/mci_spi.c
+++ b/drivers/mci/mci_spi.c
@@ -440,7 +440,7 @@ static int spi_mci_probe(struct device *dev)
 		host->mci.devname = xstrdup(of_alias_get(np));
 		host->detect_pin = gpiod_get_optional(dev, NULL, GPIOD_IN);
 		if (IS_ERR(host->detect_pin))
-			dev_warn(dev, "Failed to get 'reset' GPIO (ignored)\n");
+			dev_warn(dev, "Failed to get card detect GPIO (ignored)\n");
 	}
 
 	mci_register(&host->mci);

-- 
2.39.5



From s.hauer at pengutronix.de  Mon Mar 17 02:34:36 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 10:34:36 +0100
Subject: [PATCH 4/6] mci: mci_spi: remove stray return 0
In-Reply-To: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
References: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
Message-ID: <20250317-mci-misc-cleanup-v1-4-24b4d6f5d31a@pengutronix.de>

The return 0 in mmc_spi_request() cannot be reached. Remove it.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci_spi.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/mci/mci_spi.c b/drivers/mci/mci_spi.c
index 41d8c25e27..41d788704f 100644
--- a/drivers/mci/mci_spi.c
+++ b/drivers/mci/mci_spi.c
@@ -294,9 +294,6 @@ static int mmc_spi_request(struct mci_host *mci, struct mci_cmd *cmd, struct mci
 done:
 	mmc_cs_off(host);
 	return ret;
-
-return  0;
-
 }
 
 static void mmc_spi_set_ios(struct mci_host *mci, struct mci_ios *ios)

-- 
2.39.5



From s.hauer at pengutronix.de  Mon Mar 17 02:34:32 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 10:34:32 +0100
Subject: [PATCH 0/6] mci: some cleanups
Message-ID: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>

This cleans up some stuff in the mci layer and its drivers.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
Sascha Hauer (6):
      mci: use struct cid
      mmc: merge block read/write functions
      mci: cleanup code around ready_for_use flag
      mci: mci_spi: remove stray return 0
      mci: mci_spi: fix warning message
      mci: mci_spi: use mci_of_parse()

 drivers/mci/mci-core.c | 488 ++++++++++++++++++++-----------------------------
 drivers/mci/mci_spi.c  |   7 +-
 include/mci.h          |  18 +-
 3 files changed, 216 insertions(+), 297 deletions(-)
---
base-commit: 2afd1a809f1a41f1dd42b95c2bc0ae74853b475b
change-id: 20250317-mci-misc-cleanup-2362d1efd1ea

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 02:34:34 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 10:34:34 +0100
Subject: [PATCH 2/6] mmc: merge block read/write functions
In-Reply-To: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
References: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
Message-ID: <20250317-mci-misc-cleanup-v1-2-24b4d6f5d31a@pengutronix.de>

mci_block_write() and mci_read_block() both have very similar
implementations. Merge them into a mci_do_block_op() function
and call it from the actual block read/write functions.

While at it rename mci_read_block() to mci_block_read() to get a
naming consistent to mci_block_write().

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 123 +++++++++++++++++++++++--------------------------
 1 file changed, 57 insertions(+), 66 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 34ea775813..975896d2d8 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -260,59 +260,6 @@ static int mci_poll_until_ready(struct mci *mci, int timeout_ms)
 	return 0;
 }
 
-
-/**
- * Write one or several blocks of data to the card
- * @param mci_dev MCI instance
- * @param src Where to read from to write to the card
- * @param blocknum Block number to write
- * @param blocks Block count to write
- * @return Transaction status (0 on success)
- */
-static int mci_block_write(struct mci *mci, const void *src, int blocknum,
-	int blocks)
-{
-	struct mci_cmd cmd = {};
-	struct mci_data data;
-	unsigned mmccmd;
-	int ret;
-
-	/*
-	 * Quoting eMMC Spec v5.1 (JEDEC Standard No. 84-B51):
-	 * Due to legacy reasons, a Device may still treat CMD24/25 during
-	 * prg-state (while busy is active) as a legal or illegal command.
-	 * A host should not send CMD24/25 while the Device is in the prg
-	 * state and busy is active.
-	 */
-	ret = mci_poll_until_ready(mci, 1000 /* ms */);
-	if (ret && ret != -ENOSYS)
-		return ret;
-
-	if (blocks > 1)
-		mmccmd = MMC_CMD_WRITE_MULTIPLE_BLOCK;
-	else
-		mmccmd = MMC_CMD_WRITE_SINGLE_BLOCK;
-
-	mci_setup_cmd(&cmd,
-		mmccmd,
-		mci->high_capacity != 0 ? blocknum : blocknum * mci->write_bl_len,
-		MMC_RSP_R1);
-
-	data.src = src;
-	data.blocks = blocks;
-	data.blocksize = mci->write_bl_len;
-	data.flags = MMC_DATA_WRITE;
-
-	ret = mci_send_cmd(mci, &cmd, &data);
-
-	if (ret || blocks > 1) {
-		mci_setup_cmd(&cmd, MMC_CMD_STOP_TRANSMISSION, 0, MMC_RSP_R1b);
-		mci_send_cmd(mci, &cmd, NULL);
-        }
-
-	return ret;
-}
-
 /**
  * Erase one or several blocks of data to the card
  * @param mci_dev MCI instance
@@ -364,35 +311,51 @@ static int mci_block_erase(struct mci *card, unsigned int from,
 	return -EIO;
 }
 
-/**
- * Read one or several block(s) of data from the card
- * @param mci MCI instance
- * @param dst Where to store the data read from the card
- * @param blocknum Block number to read
- * @param blocks number of blocks to read
- */
-static int mci_read_block(struct mci *mci, void *dst, int blocknum,
+static int mci_do_block_op(struct mci *mci, const void *src, void *dst, int blocknum,
 		int blocks)
 {
 	struct mci_cmd cmd = {};
 	struct mci_data data;
 	int ret;
-	unsigned mmccmd;
+	unsigned mmccmd_multi_block, mmccmd_single_block, mmccmd;
+	unsigned int flags;
+
+	if (dst) {
+		mmccmd_multi_block = MMC_CMD_READ_MULTIPLE_BLOCK;
+		mmccmd_single_block = MMC_CMD_READ_SINGLE_BLOCK;
+		flags = MMC_DATA_READ;
+	} else {
+		/*
+		 * Quoting eMMC Spec v5.1 (JEDEC Standard No. 84-B51):
+		 * Due to legacy reasons, a Device may still treat CMD24/25 during
+		 * prg-state (while busy is active) as a legal or illegal command.
+		 * A host should not send CMD24/25 while the Device is in the prg
+		 * state and busy is active.
+		 */
+		ret = mci_poll_until_ready(mci, 1000 /* ms */);
+		if (ret && ret != -ENOSYS)
+			return ret;
+
+		mmccmd_multi_block = MMC_CMD_WRITE_MULTIPLE_BLOCK;
+		mmccmd_single_block = MMC_CMD_WRITE_SINGLE_BLOCK;
+		flags = MMC_DATA_WRITE;
+	}
 
 	if (blocks > 1)
-		mmccmd = MMC_CMD_READ_MULTIPLE_BLOCK;
+		mmccmd = mmccmd_multi_block;
 	else
-		mmccmd = MMC_CMD_READ_SINGLE_BLOCK;
+		mmccmd = mmccmd_single_block;
 
 	mci_setup_cmd(&cmd,
 		mmccmd,
 		mci->high_capacity != 0 ? blocknum : blocknum * mci->read_bl_len,
 		MMC_RSP_R1);
 
+	data.src = src;
 	data.dest = dst;
 	data.blocks = blocks;
 	data.blocksize = mci->read_bl_len;
-	data.flags = MMC_DATA_READ;
+	data.flags = flags;
 
 	ret = mci_send_cmd(mci, &cmd, &data);
 
@@ -401,9 +364,37 @@ static int mci_read_block(struct mci *mci, void *dst, int blocknum,
 			      IS_SD(mci) ? MMC_RSP_R1b : MMC_RSP_R1);
 		mci_send_cmd(mci, &cmd, NULL);
 	}
+
 	return ret;
 }
 
+/**
+ * Read one or several block(s) of data from the card
+ * @param mci MCI instance
+ * @param dst Where to store the data read from the card
+ * @param blocknum Block number to read
+ * @param blocks number of blocks to read
+ */
+static int mci_block_read(struct mci *mci, void *dst, int blocknum,
+		int blocks)
+{
+	return mci_do_block_op(mci, NULL, dst, blocknum, blocks);
+}
+
+/**
+ * Write one or several blocks of data to the card
+ * @param mci_dev MCI instance
+ * @param src Where to read from to write to the card
+ * @param blocknum Block number to write
+ * @param blocks Block count to write
+ * @return Transaction status (0 on success)
+ */
+static int mci_block_write(struct mci *mci, const void *src, int blocknum,
+	int blocks)
+{
+	return mci_do_block_op(mci, src, NULL, blocknum, blocks);
+}
+
 /**
  * Reset the attached MMC/SD card
  * @param mci MCI instance
@@ -2244,7 +2235,7 @@ static int mci_sd_read(struct block_device *blk, void *buffer, sector_t block,
 
 	while (num_blocks) {
 		read_block = min(num_blocks, max_req_block);
-		rc = mci_read_block(mci, buffer, block, read_block);
+		rc = mci_block_read(mci, buffer, block, read_block);
 		if (rc != 0) {
 			dev_dbg(&mci->dev, "Reading block %llu failed with %d\n", block, rc);
 			return rc;

-- 
2.39.5



From s.hauer at pengutronix.de  Mon Mar 17 02:34:38 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 10:34:38 +0100
Subject: [PATCH 6/6] mci: mci_spi: use mci_of_parse()
In-Reply-To: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
References: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
Message-ID: <20250317-mci-misc-cleanup-v1-6-24b4d6f5d31a@pengutronix.de>

The mci_spi driver parses the device tree alias itself. Instead call
mci_of_parse() which does the same and also parses other generic mmc
properties.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mci/mci_spi.c b/drivers/mci/mci_spi.c
index 864e15a416..dd4c9333ee 100644
--- a/drivers/mci/mci_spi.c
+++ b/drivers/mci/mci_spi.c
@@ -437,7 +437,7 @@ static int spi_mci_probe(struct device *dev)
 	host->mci.host_caps = MMC_CAP_SPI;
 
 	if (np) {
-		host->mci.devname = xstrdup(of_alias_get(np));
+		mci_of_parse(&host->mci);
 		host->detect_pin = gpiod_get_optional(dev, NULL, GPIOD_IN);
 		if (IS_ERR(host->detect_pin))
 			dev_warn(dev, "Failed to get card detect GPIO (ignored)\n");

-- 
2.39.5



From s.hauer at pengutronix.de  Mon Mar 17 02:34:33 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 10:34:33 +0100
Subject: [PATCH 1/6] mci: use struct cid
In-Reply-To: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
References: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
Message-ID: <20250317-mci-misc-cleanup-v1-1-24b4d6f5d31a@pengutronix.de>

Linux has a struct mmc_cid where the CID data is parsed into whereas
in barebox we call the UNSTUFF_BITS macro whenever we need a field
from the CID data. Do it like Linux and parse the CID data into the
same struct. While at it convert the UNSTUFF_BITS macro into a
unstuff_bits static inline function.

This also changes some names of the mci device parameters:

- cid_mdt is now split up into year and month and becomes cid_year and
  cid_month
- cid_prv is now split up into hardware revision and firmware revision
  and becomes cid_hwrev and cid_fwrev

This is done as Linux has this as well. It is assumed that these
variables are informational only and thus no scripts depend on the
exact names.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 340 ++++++++++++++++++++-----------------------------
 include/mci.h          |  16 ++-
 2 files changed, 154 insertions(+), 202 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 7ec2643b8d..34ea775813 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -26,19 +26,19 @@
 
 #define MAX_BUFFER_NUMBER 0xffffffff
 
-#define UNSTUFF_BITS(resp,start,size)					\
-	({								\
-		const int __size = size;				\
-		const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1;	\
-		const int __off = 3 - ((start) / 32);			\
-		const int __shft = (start) & 31;			\
-		u32 __res;						\
-									\
-		__res = resp[__off] >> __shft;				\
-		if (__size + __shft > 32)				\
-			__res |= resp[__off-1] << ((32 - __shft) % 32);	\
-		__res & __mask;						\
-	})
+static inline u32 unstuff_bits(const u32 *resp, int start, int size)
+{
+	const int __size = size;
+	const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1;
+	const int __off = 3 - (start / 32);
+	const int __shft = start & 31;
+	u32 __res = resp[__off] >> __shft;
+
+	if (__size + __shft > 32)
+		__res |= resp[__off - 1] << ((32 - __shft) % 32);
+
+	return __res & __mask;
+}
 
 LIST_HEAD(mci_list);
 
@@ -1202,7 +1202,7 @@ static void mci_extract_max_tran_speed_from_csd(struct mci *mci)
  */
 static void mci_extract_block_lengths_from_csd(struct mci *mci)
 {
-	mci->read_bl_len = 1 << UNSTUFF_BITS(mci->csd, 80, 4);
+	mci->read_bl_len = 1 << unstuff_bits(mci->csd, 80, 4);
 
 	/* Quoting Physical Layer Simplified Specification Version 9.10:
 	 * Note that in an SD Memory Card the WRITE_BL_LEN is always
@@ -1224,18 +1224,18 @@ static void mci_extract_block_lengths_from_csd(struct mci *mci)
 static void mci_extract_erase_group_size(struct mci *mci)
 {
 	if (!IS_ENABLED(CONFIG_MCI_ERASE) ||
-	    !(UNSTUFF_BITS(mci->csd, 84, 12) & CCC_ERASE))
+	    !(unstuff_bits(mci->csd, 84, 12) & CCC_ERASE))
 		return;
 
 
 	if (IS_SD(mci)) {
-		if (UNSTUFF_BITS(mci->csd, 126, 2) == 0) {
-			unsigned int write_blkbits = UNSTUFF_BITS(mci->csd, 22, 4);
+		if (unstuff_bits(mci->csd, 126, 2) == 0) {
+			unsigned int write_blkbits = unstuff_bits(mci->csd, 22, 4);
 
-			if (UNSTUFF_BITS(mci->csd, 46, 1)) {
+			if (unstuff_bits(mci->csd, 46, 1)) {
 				mci->erase_grp_size = 1;
 			} else if (write_blkbits >= 9) {
-				mci->erase_grp_size = UNSTUFF_BITS(mci->csd, 39, 7) + 1;
+				mci->erase_grp_size = unstuff_bits(mci->csd, 39, 7) + 1;
 				mci->erase_grp_size <<= write_blkbits - 9;
 			}
 		} else {
@@ -1279,7 +1279,7 @@ static void mci_extract_card_capacity_from_csd(struct mci *mci)
 
 	if (mci->high_capacity) {
 		if (IS_SD(mci)) {
-			csize = UNSTUFF_BITS(mci->csd, 48, 22);
+			csize = unstuff_bits(mci->csd, 48, 22);
 			mci->capacity = (1 + csize) << 10;
 		} else {
 			mci->capacity = mci->ext_csd[EXT_CSD_SEC_COUNT] << 0 |
@@ -1288,12 +1288,12 @@ static void mci_extract_card_capacity_from_csd(struct mci *mci)
 				mci->ext_csd[EXT_CSD_SEC_COUNT + 3] << 24;
 		}
 	} else {
-		cmult = UNSTUFF_BITS(mci->csd, 47, 3);
-		csize = UNSTUFF_BITS(mci->csd, 62, 12);
+		cmult = unstuff_bits(mci->csd, 47, 3);
+		csize = unstuff_bits(mci->csd, 62, 12);
 		mci->capacity = (csize + 1) << (cmult + 2);
 	}
 
-	mci->capacity *= 1 << UNSTUFF_BITS(mci->csd, 80, 4);
+	mci->capacity *= 1 << unstuff_bits(mci->csd, 80, 4);
 	dev_dbg(&mci->dev, "Capacity: %u MiB\n", (unsigned)(mci->capacity >> 20));
 }
 
@@ -1303,7 +1303,7 @@ static void mci_extract_card_capacity_from_csd(struct mci *mci)
  */
 static void mci_extract_card_dsr_imp_from_csd(struct mci *mci)
 {
-	mci->dsr_imp = UNSTUFF_BITS(mci->csd, 76, 1);
+	mci->dsr_imp = unstuff_bits(mci->csd, 76, 1);
 }
 
 static int mmc_compare_ext_csds(struct mci *mci, enum mci_bus_width bus_width)
@@ -1806,10 +1806,10 @@ static int mci_startup(struct mci *mci)
 		return err;
 	}
 
-	memcpy(mci->cid, cmd.response, 16);
+	memcpy(mci->raw_cid, cmd.response, 16);
 
 	dev_dbg(&mci->dev, "Card's identification data is: %08X-%08X-%08X-%08X\n",
-		mci->cid[0], mci->cid[1], mci->cid[2], mci->cid[3]);
+		mci->raw_cid[0], mci->raw_cid[1], mci->raw_cid[2], mci->raw_cid[3]);
 
 	/*
 	 * For MMC cards, set the Relative Address.
@@ -2259,156 +2259,6 @@ static int mci_sd_read(struct block_device *blk, void *buffer, sector_t block,
 
 /* ------------------ attach to the device API --------------------------- */
 
-/**
- * Extract the Manufacturer ID from the CID
- * @param mci Instance data
- *
- * The 'MID' is encoded in bit 127:120 in the CID
- */
-static unsigned extract_mid(struct mci *mci)
-{
-	if (!IS_SD(mci) && mci->version <= MMC_VERSION_1_4)
-		return UNSTUFF_BITS(mci->cid, 104, 24);
-	else
-		return UNSTUFF_BITS(mci->cid, 120, 8);
-}
-
-/**
- * Extract the CBX from the CID
- * @param mci Instance data
- *
- * The 'CBX' is encoded in bit 113:112 in the CID and only present in MMC cards
- */
-static unsigned extract_cbx(struct mci *mci)
-{
-	return UNSTUFF_BITS(mci->cid, 112, 2);
-}
-
-/**
- * Extract the OEM/Application ID from the CID
- * @param mci Instance data
- *
- * The 'OID' is encoded in bit 119:104 in the CID for SD cards and 111:104 for
- * MMC cards
- */
-static void extract_oid(struct mci *mci, char oid[static 5])
-{
-	if (IS_SD(mci)) {
-		// SD cards have a 2 character long OEM ID
-		snprintf(oid, 5, "%c%c", UNSTUFF_BITS(mci->cid, 112, 8), UNSTUFF_BITS(mci->cid, 104, 8));
-	} else {
-		// MMC cards have a 8-bit binary number as OEM ID
-		snprintf(oid, 5, "0x%02X", UNSTUFF_BITS(mci->cid, 104, 8));
-	}
-}
-
-/**
- * Extract the product name from the CID
- * @param mci Instance data
- *
- * The 'PNM' is encoded in bit 103:64 in the CID for SD cards and 103:56 for
- * MMC cards
- */
-static void extract_pnm(struct mci *mci, char pnm[static 7])
-{
-	pnm[0] = UNSTUFF_BITS(mci->cid, 96, 8);
-	pnm[1] = UNSTUFF_BITS(mci->cid, 88, 8);
-	pnm[2] = UNSTUFF_BITS(mci->cid, 80, 8);
-	pnm[3] = UNSTUFF_BITS(mci->cid, 72, 8);
-	pnm[4] = UNSTUFF_BITS(mci->cid, 64, 8);
-
-	if (IS_SD(mci)) {
-		// SD cards have a 5 character long product name
-		pnm[5] = '\0';
-	} else {
-		// MMC cards have a 6 character long product name
-		pnm[5] = UNSTUFF_BITS(mci->cid, 56, 8);
-		pnm[6] = '\0';
-	}
-}
-
-/**
- * Extract the product revision from the CID
- * @param mci Instance data
- *
- * The 'PRV' is encoded in bit 63:56 in the CID for SD cards and 55:48 for MMC cards
- */
-static void extract_prv(struct mci *mci, char prv[static 8])
-{
-	unsigned prv_bcd = IS_SD(mci) ? UNSTUFF_BITS(mci->cid, 56, 8) : UNSTUFF_BITS(mci->cid, 48, 8);
-
-	snprintf(prv, 8,"%u.%u", prv_bcd >> 4, prv_bcd & 0xf);
-}
-
-/**
- * Extract the product serial number from the CID
- * @param mci Instance data
- *
- * The 'PSN' is encoded in bit 55:24 in the CID for SD cards and 47:16 for MMC cards
- */
-static unsigned extract_psn(struct mci *mci)
-{
-	if (IS_SD(mci)) {
-		return UNSTUFF_BITS(mci->csd, 24, 32);
-	} else {
-		if (mci->version > MMC_VERSION_1_4)
-			return UNSTUFF_BITS(mci->cid, 16, 32);
-		else
-			return UNSTUFF_BITS(mci->cid, 16, 24);
-	}
-
-}
-
-/**
- * Extract the month of the manufacturing date from the CID
- * @param mci Instance data
- *
- * The 'MDT' is encoded in bit 19:8 in the CID, month in 11:8
- */
-static unsigned extract_mdt_month(struct mci *mci)
-{
-	if (IS_SD(mci))
-		return UNSTUFF_BITS(mci->cid, 8, 4);
-	else
-		return UNSTUFF_BITS(mci->cid, 12, 4);
-}
-
-/**
- * Extract the year of the manufacturing date from the CID
- * @param mci Instance data
- *
- * The 'MDT' is encoded in bit 19:8 in the CID, year in 19:12
- * An encoded 0 means the year 2000
- */
-static unsigned extract_mdt_year(struct mci *mci)
-{
-	unsigned year;
-	if (IS_SD(mci))
-		year = UNSTUFF_BITS(mci->cid, 12, 8) + 2000;
-	else if (mci->version < MMC_VERSION_4_41)
-		return UNSTUFF_BITS(mci->cid, 8, 4) + 1997;
-	else {
-		year = UNSTUFF_BITS(mci->cid, 8, 4) + 1997;
-		if (year < 2010)
-			year += 16;
-	}
-	return year;
-}
-
-/**
- * Extract the manufacturing date from the CID
- * @param mci Instance data
- *
- * The 'MDT' is encoded in bit 19:8 in the CID
- */
-static void extract_mdt(struct mci *mci, char mdt[static 8])
-{
-	unsigned month = extract_mdt_month(mci);
-	unsigned year = extract_mdt_year(mci);
-
-	snprintf(mdt, 8, "%u.%u", year, month);
-}
-
 static const char *mci_timing_tostr(unsigned timing)
 {
 	switch (timing) {
@@ -2440,6 +2290,88 @@ static void mci_print_caps(unsigned caps)
 		caps & MMC_CAP_MMC_1_2V_DDR ? "ddr-1.2v " : "");
 }
 
+/*
+ * Given the decoded CSD structure, decode the raw CID to our CID structure.
+ */
+static int mci_mmc_decode_cid(struct mci *card)
+{
+	u32 *resp = card->raw_cid;
+	u32 mmca_vsn = unstuff_bits(card->csd, 122, 4);
+
+	/*
+	 * The selection of the format here is based upon published
+	 * specs from sandisk and from what people have reported.
+	 */
+	switch (mmca_vsn) {
+	case 0: /* MMC v1.0 - v1.2 */
+	case 1: /* MMC v1.4 */
+		card->cid.manfid	= unstuff_bits(resp, 104, 24);
+		card->cid.prod_name[0]	= unstuff_bits(resp, 96, 8);
+		card->cid.prod_name[1]	= unstuff_bits(resp, 88, 8);
+		card->cid.prod_name[2]	= unstuff_bits(resp, 80, 8);
+		card->cid.prod_name[3]	= unstuff_bits(resp, 72, 8);
+		card->cid.prod_name[4]	= unstuff_bits(resp, 64, 8);
+		card->cid.prod_name[5]	= unstuff_bits(resp, 56, 8);
+		card->cid.prod_name[6]	= unstuff_bits(resp, 48, 8);
+		card->cid.hwrev		= unstuff_bits(resp, 44, 4);
+		card->cid.fwrev		= unstuff_bits(resp, 40, 4);
+		card->cid.serial	= unstuff_bits(resp, 16, 24);
+		card->cid.month		= unstuff_bits(resp, 12, 4);
+		card->cid.year		= unstuff_bits(resp, 8, 4) + 1997;
+		break;
+
+	case 2: /* MMC v2.0 - v2.2 */
+	case 3: /* MMC v3.1 - v3.3 */
+	case 4: /* MMC v4 */
+		card->cid.manfid	= unstuff_bits(resp, 120, 8);
+		card->cid.oemid		= unstuff_bits(resp, 104, 16);
+		card->cid.prod_name[0]	= unstuff_bits(resp, 96, 8);
+		card->cid.prod_name[1]	= unstuff_bits(resp, 88, 8);
+		card->cid.prod_name[2]	= unstuff_bits(resp, 80, 8);
+		card->cid.prod_name[3]	= unstuff_bits(resp, 72, 8);
+		card->cid.prod_name[4]	= unstuff_bits(resp, 64, 8);
+		card->cid.prod_name[5]	= unstuff_bits(resp, 56, 8);
+		card->cid.prv		= unstuff_bits(resp, 48, 8);
+		card->cid.serial	= unstuff_bits(resp, 16, 32);
+		card->cid.month		= unstuff_bits(resp, 12, 4);
+		card->cid.year		= unstuff_bits(resp, 8, 4) + 1997;
+		break;
+
+	default:
+		dev_err(&card->dev, "card has unknown MMCA version %d\n", mmca_vsn);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/*
+ * Given the decoded CSD structure, decode the raw CID to our CID structure.
+ */
+static void mci_sd_decode_cid(struct mci *card)
+{
+	u32 *resp = card->raw_cid;
+
+	/*
+	 * SD doesn't currently have a version field so we will
+	 * have to assume we can parse this.
+	 */
+	card->cid.manfid		= unstuff_bits(resp, 120, 8);
+	card->cid.oemid			= unstuff_bits(resp, 104, 16);
+	card->cid.prod_name[0]		= unstuff_bits(resp, 96, 8);
+	card->cid.prod_name[1]		= unstuff_bits(resp, 88, 8);
+	card->cid.prod_name[2]		= unstuff_bits(resp, 80, 8);
+	card->cid.prod_name[3]		= unstuff_bits(resp, 72, 8);
+	card->cid.prod_name[4]		= unstuff_bits(resp, 64, 8);
+	card->cid.hwrev			= unstuff_bits(resp, 60, 4);
+	card->cid.fwrev			= unstuff_bits(resp, 56, 4);
+	card->cid.serial		= unstuff_bits(resp, 24, 32);
+	card->cid.year			= unstuff_bits(resp, 12, 8);
+	card->cid.month			= unstuff_bits(resp, 8, 4);
+
+	card->cid.year += 2000; /* SD cards year offset */
+}
+
 /**
  * Output some valuable information when the user runs 'devinfo' on an MCI device
  * @param mci MCI device instance
@@ -2492,38 +2424,44 @@ static void mci_info(struct device *dev)
 
 	if (mci->high_capacity)
 		printf("  High capacity card\n");
-	printf("   CID: %08X-%08X-%08X-%08X\n", mci->cid[0], mci->cid[1],
-		mci->cid[2], mci->cid[3]);
+	printf("   CID: %08X-%08X-%08X-%08X\n", mci->raw_cid[0], mci->raw_cid[1],
+		mci->raw_cid[2], mci->raw_cid[3]);
 	printf("   CSD: %08X-%08X-%08X-%08X\n", mci->csd[0], mci->csd[1],
 		mci->csd[2], mci->csd[3]);
 	printf("  Max. transfer speed: %u Hz\n", mci->tran_speed);
 	mci_print_caps(mci->card_caps);
-	printf("  Manufacturer ID: %s\n", dev_get_param(dev, "cid_mid"));
-	printf("  OEM/Application ID: %s\n", dev_get_param(dev, "cid_oid"));
-	if (!IS_SD(mci))
-		printf("  CBX: %s\n", dev_get_param(dev, "cid_cbx"));
-	printf("  Product name: '%s'\n", dev_get_param(dev, "cid_pnm"));
-	printf("  Product revision: %s\n", dev_get_param(dev, "cid_prv"));
-	printf("  Serial no: %s\n", dev_get_param(dev, "cid_psn"));
-	printf("  Manufacturing date: %s\n", dev_get_param(dev, "cid_mdt"));
+	printf("  Manufacturer ID: 0x%02x\n", mci->cid.manfid);
+	printf("  OEM/Application ID: 0x%04x\n", mci->cid.oemid);
+	printf("  Product name: '%s'\n", mci->cid.prod_name);
+	printf("  Hardware revision: 0x%02x\n", mci->cid.hwrev);
+	printf("  Firmware revision: 0x%02x\n", mci->cid.fwrev);
+	printf("  Serial no: %u\n", mci->cid.serial);
+	printf("  Manufacturing date: %u.%u\n", mci->cid.year, mci->cid.month);
 }
 
-static void mci_parse_cid(struct mci *mci) {
+static void mci_parse_cid(struct mci *mci)
+{
 	struct device *dev = &mci->dev;
-	char buffer[8];
-
-	dev_add_param_uint32_fixed(dev, "cid_mid", extract_mid(mci), "0x%02X");
-	extract_oid(mci, buffer);
-	dev_add_param_string_fixed(dev, "cid_oid", buffer);
-	if (!IS_SD(mci))
-		dev_add_param_uint32_fixed(dev, "cid_cbx", extract_cbx(mci), "%u");
-	extract_pnm(mci, buffer);
-	dev_add_param_string_fixed(dev, "cid_pnm", buffer);
-	extract_prv(mci, buffer);
-	dev_add_param_string_fixed(dev, "cid_prv", buffer);
-	dev_add_param_uint32_fixed(dev, "cid_psn", extract_psn(mci), "%0u");
-	extract_mdt(mci, buffer);
-	dev_add_param_string_fixed(dev, "cid_mdt", buffer);
+
+	if (IS_SD(mci))
+		mci_sd_decode_cid(mci);
+	else
+		mci_mmc_decode_cid(mci);
+
+	if (mci->ext_csd[EXT_CSD_REV] >= 5) {
+		/* Adjust production date as per JEDEC JESD84-B451 */
+		if (mci->cid.year < 2010)
+			mci->cid.year += 16;
+	}
+
+	dev_add_param_uint32_fixed(dev, "cid_mid", mci->cid.manfid, "0x%02X");
+	dev_add_param_uint32_fixed(dev, "cid_oid", mci->cid.oemid, "0x%04X");
+	dev_add_param_string_fixed(dev, "cid_pnm", mci->cid.prod_name);
+	dev_add_param_uint32_fixed(dev, "cid_hwrev", mci->cid.hwrev, "0x%02X");
+	dev_add_param_uint32_fixed(dev, "cid_fwrev", mci->cid.fwrev, "0x%02X");
+	dev_add_param_uint32_fixed(dev, "cid_psn", mci->cid.serial, "%0u");
+	dev_add_param_uint32_fixed(dev, "cid_year", mci->cid.year, "%0u");
+	dev_add_param_uint32_fixed(dev, "cid_month", mci->cid.month, "%0u");
 }
 
 /**
diff --git a/include/mci.h b/include/mci.h
index 1e37570274..689ca7167f 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -626,6 +626,18 @@ struct sd_ssr {
 	unsigned int erase_offset;      /* In milliseconds */
 };
 
+struct mmc_cid {
+	unsigned int		manfid;
+	char			prod_name[8];
+	unsigned char		prv;
+	unsigned int		serial;
+	unsigned short		oemid;
+	unsigned short		year;
+	unsigned char		hwrev;
+	unsigned char		fwrev;
+	unsigned char		month;
+};
+
 /** MMC/SD and interface instance information */
 struct mci {
 	struct mci_host *host;		/**< the host for this card */
@@ -635,7 +647,7 @@ struct mci {
 	unsigned ocr;		/**< card's "operation condition register" */
 	unsigned scr[2];
 	unsigned csd[4];	/**< card's "card specific data register" */
-	unsigned cid[4];	/**< card's "card identification register" */
+	unsigned raw_cid[4];	/**< card's "card identification register" */
 	unsigned short rca;	/**< relative card address */
 	u8 sdio:1;              /**< card is a SDIO card */
 	u8 high_capacity:1;	/**< high capacity card is connected (OCR -> OCR_HCS) */
@@ -663,6 +675,8 @@ struct mci {
 	struct mci_part *part_curr;
 	u8 ext_csd_part_config;
 
+	struct mmc_cid cid;
+
 	struct list_head list;     /* The list of all mci devices */
 };
 

-- 
2.39.5



From s.hauer at pengutronix.de  Mon Mar 17 02:34:35 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 10:34:35 +0100
Subject: [PATCH 3/6] mci: cleanup code around ready_for_use flag
In-Reply-To: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
References: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
Message-ID: <20250317-mci-misc-cleanup-v1-3-24b4d6f5d31a@pengutronix.de>

struct mci::ready_for_use is a flag, thus should be boolean. Also
no need to have an extra function which returns a negative error
code when the flag is set. Just check for the flag where needed.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 29 ++++-------------------------
 include/mci.h          |  2 +-
 2 files changed, 5 insertions(+), 26 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 975896d2d8..f29dc84f93 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -2373,7 +2373,7 @@ static void mci_info(struct device *dev)
 	struct mci_host *host = mci->host;
 	int bw;
 
-	if (mci->ready_for_use == 0) {
+	if (!mci->ready_for_use) {
 		printf(" No information available:\n  MCI card not probed yet\n");
 		return;
 	}
@@ -2455,23 +2455,6 @@ static void mci_parse_cid(struct mci *mci)
 	dev_add_param_uint32_fixed(dev, "cid_month", mci->cid.month, "%0u");
 }
 
-/**
- * Check if the MCI card is already probed
- * @param mci MCI device instance
- * @return 0 when not probed yet, -EPERM if already probed
- *
- * @a barebox cannot really cope with hot plugging. So, probing an attached
- * MCI card is a one time only job. If its already done, there is no way to
- * return.
- */
-static int mci_check_if_already_initialized(struct mci *mci)
-{
-	if (mci->ready_for_use != 0)
-		return -EPERM;
-
-	return 0;
-}
-
 static struct block_device_ops mci_ops = {
 	.read = mci_sd_read,
 	.write = IS_ENABLED(CONFIG_MCI_WRITE) ? mci_sd_write : NULL,
@@ -2716,7 +2699,7 @@ static int mci_card_probe(struct mci *mci)
 	}
 
 	dev_dbg(&mci->dev, "Card is up and running now, registering as a disk\n");
-	mci->ready_for_use = 1;	/* TODO now or later? */
+	mci->ready_for_use = true; /* TODO now or later? */
 
 	for (i = 0; i < mci->nr_parts; i++) {
 		struct mci_part *part = &mci->part[i];
@@ -2775,8 +2758,7 @@ static int mci_set_probe(struct param_d *param, void *priv)
 	if (!mci->probe)
 		return 0;
 
-	rc = mci_check_if_already_initialized(mci);
-	if (rc != 0)
+	if (mci->ready_for_use)
 		return 0;
 
 	rc = mci_card_probe(mci);
@@ -2788,10 +2770,7 @@ static int mci_set_probe(struct param_d *param, void *priv)
 
 int mci_detect_card(struct mci_host *host)
 {
-	int rc;
-
-	rc = mci_check_if_already_initialized(host->mci);
-	if (rc != 0)
+	if (host->mci->ready_for_use)
 		return 0;
 
 	return mci_card_probe(host->mci);
diff --git a/include/mci.h b/include/mci.h
index 689ca7167f..db1333999a 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -660,7 +660,7 @@ struct mci {
 	unsigned write_bl_len;
 	unsigned erase_grp_size;
 	uint64_t capacity;	/**< Card's data capacity in bytes */
-	int ready_for_use;	/** true if already probed */
+	bool ready_for_use;	/** true if already probed */
 	int dsr_imp;		/**< DSR implementation state from CSD */
 	u8 *ext_csd;
 	int probe;

-- 
2.39.5



From eagle.alexander923 at gmail.com  Mon Mar 17 02:41:22 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Mon, 17 Mar 2025 12:41:22 +0300
Subject: [PATCH 1/6] mci: use struct cid
In-Reply-To: <20250317-mci-misc-cleanup-v1-1-24b4d6f5d31a@pengutronix.de>
References: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de> <20250317-mci-misc-cleanup-v1-1-24b4d6f5d31a@pengutronix.de>
Message-ID: <CAP1tNvTCxfq7wnfwhmvMhKga67h4YUw4RebJYGxcb4o2Yw2btQ@mail.gmail.com>

Hello.

> Linux has a struct mmc_cid where the CID data is parsed into whereas
> in barebox we call the UNSTUFF_BITS macro whenever we need a field
> from the CID data. Do it like Linux and parse the CID data into the
> same struct. While at it convert the UNSTUFF_BITS macro into a
> unstuff_bits static inline function.
...
> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> index 7ec2643b8d..34ea775813 100644
> --- a/drivers/mci/mci-core.c
> +++ b/drivers/mci/mci-core.c
> @@ -26,19 +26,19 @@
>
>  #define MAX_BUFFER_NUMBER 0xffffffff
>
> -#define UNSTUFF_BITS(resp,start,size)                                  \
> -       ({                                                              \
> -               const int __size = size;                                \
> -               const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \
> -               const int __off = 3 - ((start) / 32);                   \
> -               const int __shft = (start) & 31;                        \
> -               u32 __res;                                              \
> -                                                                       \
> -               __res = resp[__off] >> __shft;                          \
> -               if (__size + __shft > 32)                               \
> -                       __res |= resp[__off-1] << ((32 - __shft) % 32); \
> -               __res & __mask;                                         \
> -       })
> +static inline u32 unstuff_bits(const u32 *resp, int start, int size)
> +{
> +       const int __size = size;
> +       const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1;
> +       const int __off = 3 - (start / 32);
> +       const int __shft = start & 31;
> +       u32 __res = resp[__off] >> __shft;
> +
> +       if (__size + __shft > 32)
> +               __res |= resp[__off - 1] << ((32 - __shft) % 32);
> +
> +       return __res & __mask;
> +}

For board specific code where the eMMC ID is used as a unique identifier,
it would be useful to have this function in the header.


From s.hauer at pengutronix.de  Mon Mar 17 03:40:22 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 11:40:22 +0100
Subject: [PATCH] watchdog: rti_wdt: return 0 even when not ready for ping
Message-ID: <20250317104022.1046085-1-s.hauer@pengutronix.de>

The rti_wdt is a windowed watchdog which means we are not allowed to
ping the watchdog outside a certain timing window. When pinging the
watchdog too early the watchdog will trigger.

We used to return -EBUSY from the watchdogs ping callback when
pinging outside the timing window. We may ping the watchdog multiple
times in boot_entry() which then results in

Failed to enable watchdog: Device or resource busy

Avoid these messages by returning successfully even when pinged too
early.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/watchdog/rti_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c
index f5ca6683db..ffc4427059 100644
--- a/drivers/watchdog/rti_wdt.c
+++ b/drivers/watchdog/rti_wdt.c
@@ -56,7 +56,7 @@ static int rti_wdt_ping(struct watchdog *wdt)
 	halftime = wdt->timeout_cur / 2 + 1;
 
 	if (!is_timeout_non_interruptible(wdt->last_ping, halftime * SECOND))
-		return -EBUSY;
+		return 0;
 
 	writel(WDKEY_SEQ0, priv->regs + RTIWDKEY);
 	writel(WDKEY_SEQ1, priv->regs + RTIWDKEY);
-- 
2.39.5



From a.fatoum at pengutronix.de  Mon Mar 17 03:42:12 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 17 Mar 2025 11:42:12 +0100
Subject: [PATCH] environment: support reading and writing of efivar
In-Reply-To: <20250311141713.30947-1-jonas.licht@gmail.com>
References: <20250311141713.30947-1-jonas.licht@gmail.com>
Message-ID: <6d6d7a57-e716-48c0-86a6-9a91b337db3f@pengutronix.de>

Hi,

Thanks for your patch. Please see the comments inline.

On 3/11/25 15:17, Jonas Licht wrote:
> scripts/bareboxenv: skip file creation to allow reading the destination
> file, when existing.

Can you elaborate a bit on what's done here? e.g. On EFI, barebox
environment can be stored into an EFI variable. An EFI variable's value
as read from Linux efivarfs is preceded by four bytes of metadata, which
we need to maintain when rewriting the variable.

> Signed-off-by: Jonas Licht <jonas.licht at gmail.com>
> Fixes #29

Link: https://github.com/barebox/barebox/issues/29

> ---
>  common/environment.c | 62 +++++++++++++++++++++++++++++++++++++++-----
>  scripts/bareboxenv.c | 11 +-------
>  2 files changed, 57 insertions(+), 16 deletions(-)
> 
> diff --git a/common/environment.c b/common/environment.c
> index 37adb5d678..dee746a6b2 100644
> --- a/common/environment.c
> +++ b/common/environment.c
> @@ -305,9 +305,10 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
>  	struct envfs_super *super;
>  	int envfd, size, ret;
>  	struct action_data data = {};
> -	void *buf = NULL, *wbuf;
> +	void *buf = NULL, *wbuf, *bufWithEfi;

barebox is written in kernel coding style, so please use snake case
for variables.

>  	struct envfs_entry *env;
>  	const char *defenv_path = default_environment_path_get();
> +	uint32_t magic;
>  
>  	if (!filename)
>  		filename = defenv_path;
> @@ -342,7 +343,9 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
>  		}
>  	}
>  
> -	buf = xzalloc(size + sizeof(struct envfs_super));
> +	bufWithEfi = xzalloc(size + sizeof(struct envfs_super) +
> +			     4); // four byte efi attributes

Nit: #define EFIVAR_ATTR_SIZE 4 at the top of the file and use it here
instead of the comment.

> +	buf = bufWithEfi + 4;
>  	data.writep = buf + sizeof(struct envfs_super);
>  
>  	super = buf;
> @@ -370,7 +373,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
>  	super->crc = ENVFS_32(crc32(0, buf + sizeof(struct envfs_super), size));
>  	super->sb_crc = ENVFS_32(crc32(0, buf, sizeof(struct envfs_super) - 4));
>  
> -	envfd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
> +	envfd = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
>  	if (envfd < 0) {
>  		printf("could not open %s: %m\n", filename);
>  		ret = -errno;
> @@ -385,6 +388,34 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
>  		goto out;
>  	}
>  
> +	wbuf = buf;
> +
> +	/* check if we writing efi vars */

I think it will be more readable to factor this out into a helper
function. That function should also have an early exit with:

	if (!IS_ENABLED(CONFIG_EFI))
		return buf;

So, non-EFI platforms can skip this code altogether.

> +	ret = pread(envfd, &magic, sizeof(uint32_t),
> +		    4); // four byte efi var attributes
> +	if (ret == -1 && errno == ENOENT) {
> +		// skip as file don't exist
> +		goto skip_efi_read;
> +	}
> +	if (ret < sizeof(u_int32_t)) {
> +		perror("read of destination file failed");

perror("pread") is enough given that there are no instances of perror.

> +		ret = -errno;
> +		goto skip_efi_read;
> +	}
> +
> +	if (ENVFS_32(magic) == ENVFS_MAGIC) {
> +		pr_info("looks like we writing efi vars, keep attributes\n");

"Assuming EFI variable. Keeping attributes\n"

> +		ret = pread(envfd, bufWithEfi, sizeof(uint32_t), 0);
> +		if (ret < sizeof(uint32_t)) {
> +			perror("read of efi attributes failed");
> +			ret = -errno;

errno could be clobbered by perror before, so you need to record it
before doing anything else (including calling perror).


> +			goto out;
> +		}
> +		size += sizeof(uint32_t);
> +		wbuf = bufWithEfi;
> +	}
> +
> +skip_efi_read:
>  	ret = erase(envfd, ERASE_SIZE_ALL, 0, ERASE_TO_WRITE);
>  
>  	/* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */
> @@ -395,8 +426,6 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
>  
>  	size += sizeof(struct envfs_super);
>  
> -	wbuf = buf;
> -
>  	while (size) {
>  		ssize_t now = write(envfd, wbuf, size);
>  		if (now < 0) {
> @@ -425,7 +454,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
>  out:
>  	close(envfd);
>  out1:
> -	free(buf);
> +	free(bufWithEfi);
>  #ifdef __BAREBOX__
>  	unlink_recursive(TMPDIR, NULL);
>  #endif
> @@ -449,6 +478,7 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
>  	int envfd;
>  	int ret = 0;
>  	size_t size, rsize;
> +	uint32_t magic;
>  
>  	if (!filename)
>  		filename = default_environment_path_get();
> @@ -466,6 +496,26 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
>  		return -1;
>  	}
>  
> +	/* check if we reading efi vars */
> +	ret = pread(envfd, &magic, sizeof(uint32_t),
> +		    4); // four byte efi var attributes
> +	if (ret < sizeof(u_int32_t)) {
> +		perror("read");
> +		ret = -errno;
> +		goto out;
> +	}
> +
> +	if (ENVFS_32(magic) == ENVFS_MAGIC) {
> +		pr_info("looks like we reading efi vars, skip attributes\n");
> +		ret = read(envfd, &magic,
> +			   sizeof(uint32_t)); // simply reuse the memory
> +		if (ret < sizeof(uint32_t)) {
> +			perror("read");
> +			ret = -errno;
> +			goto out;
> +		}
> +	}
> +
>  	/* read superblock */
>  	ret = read(envfd, &super, sizeof(struct envfs_super));
>  	if ( ret < sizeof(struct envfs_super)) {
> diff --git a/scripts/bareboxenv.c b/scripts/bareboxenv.c
> index e954447015..6b9b8d90c4 100644
> --- a/scripts/bareboxenv.c
> +++ b/scripts/bareboxenv.c
> @@ -117,7 +117,7 @@ static void usage(char *prgname)
>  int main(int argc, char *argv[])
>  {
>  	int opt;
> -	int save = 0, load = 0, pad = 0, err = 0, fd;
> +	int save = 0, load = 0, pad = 0, err = 0;
>  	char *filename = NULL, *dirname = NULL;
>  	unsigned envfs_flags = 0;
>  	int verbose = 0;
> @@ -156,15 +156,6 @@ int main(int argc, char *argv[])
>  		exit(1);
>  	}
>  
> -	if (save) {
> -		fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0644);
> -		if (fd < 0) {
> -			perror("open");
> -			exit(1);
> -		}
> -		close(fd);
> -	}

Did you verify proper operation in the non-EFI case?

Thanks,
Ahmad

> -
>  	if (save && pad) {
>  		if (truncate(filename, pad)) {
>  			perror("truncate");



From s.hauer at pengutronix.de  Mon Mar 17 03:53:00 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 11:53:00 +0100
Subject: [PATCH 1/6] mci: use struct cid
In-Reply-To: <CAP1tNvTCxfq7wnfwhmvMhKga67h4YUw4RebJYGxcb4o2Yw2btQ@mail.gmail.com>
References: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
 <20250317-mci-misc-cleanup-v1-1-24b4d6f5d31a@pengutronix.de>
 <CAP1tNvTCxfq7wnfwhmvMhKga67h4YUw4RebJYGxcb4o2Yw2btQ@mail.gmail.com>
Message-ID: <Z9f_DK_AlkhH3jOO@pengutronix.de>

On Mon, Mar 17, 2025 at 12:41:22PM +0300, Alexander Shiyan wrote:
> Hello.
> 
> > Linux has a struct mmc_cid where the CID data is parsed into whereas
> > in barebox we call the UNSTUFF_BITS macro whenever we need a field
> > from the CID data. Do it like Linux and parse the CID data into the
> > same struct. While at it convert the UNSTUFF_BITS macro into a
> > unstuff_bits static inline function.
> ...
> > diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> > index 7ec2643b8d..34ea775813 100644
> > --- a/drivers/mci/mci-core.c
> > +++ b/drivers/mci/mci-core.c
> > @@ -26,19 +26,19 @@
> >
> >  #define MAX_BUFFER_NUMBER 0xffffffff
> >
> > -#define UNSTUFF_BITS(resp,start,size)                                  \
> > -       ({                                                              \
> > -               const int __size = size;                                \
> > -               const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \
> > -               const int __off = 3 - ((start) / 32);                   \
> > -               const int __shft = (start) & 31;                        \
> > -               u32 __res;                                              \
> > -                                                                       \
> > -               __res = resp[__off] >> __shft;                          \
> > -               if (__size + __shft > 32)                               \
> > -                       __res |= resp[__off-1] << ((32 - __shft) % 32); \
> > -               __res & __mask;                                         \
> > -       })
> > +static inline u32 unstuff_bits(const u32 *resp, int start, int size)
> > +{
> > +       const int __size = size;
> > +       const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1;
> > +       const int __off = 3 - (start / 32);
> > +       const int __shft = start & 31;
> > +       u32 __res = resp[__off] >> __shft;
> > +
> > +       if (__size + __shft > 32)
> > +               __res |= resp[__off - 1] << ((32 - __shft) % 32);
> > +
> > +       return __res & __mask;
> > +}
> 
> For board specific code where the eMMC ID is used as a unique identifier,
> it would be useful to have this function in the header.

Wouldn't you rather use something like getenv("mmc0.cid_psn") then?

We could also introduce some mmc helper function for convenience.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Mon Mar 17 03:54:06 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 11:54:06 +0100
Subject: [PATCH 1/2] vsprintf: make basprintf an alias of xasprintf
In-Reply-To: <20250313064210.74011-1-a.fatoum@pengutronix.de>
References: <20250313064210.74011-1-a.fatoum@pengutronix.de>
Message-ID: <174220884698.1334182.4751128920348280614.b4-ty@pengutronix.de>


On Thu, 13 Mar 2025 07:42:09 +0100, Ahmad Fatoum wrote:
> Less than 12% of all our basprintf callsites actually bother to check
> for allocation failure. It's highly unlikely that barebox will be able
> to function when the heap is so full that the usually small basprintf
> requests fail.
> 
> Therefore, make basprintf an alias for xasprintf, so barebox panics on
> OOM instead of possibly triggering undefined behavior.
> 
> [...]

Applied, thanks!

[1/2] vsprintf: make basprintf an alias of xasprintf
      https://git.pengutronix.de/cgit/barebox/commit/?id=12528e292f04 (link may not be stable)
[2/2] treewide: remove NULL checks for revised basprintf
      https://git.pengutronix.de/cgit/barebox/commit/?id=c574a452bd49 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From a.fatoum at pengutronix.de  Mon Mar 17 04:31:42 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 17 Mar 2025 12:31:42 +0100
Subject: [PATCH] net: am65-cpsw-nuss: fix out-of-bounds access
Message-ID: <20250317113142.1862481-1-a.fatoum@pengutronix.de>

GCC 12.2.0 complains about am65_cpsw_recv:

drivers/net/am65-cpsw-nuss.c: In function ?am65_cpsw_recv?:
drivers/net/am65-cpsw-nuss.c:495:30: warning: array subscript 9 is
  above array bounds of ?struct am65_cpsw_port[9]? [-Warray-bounds]
  495 |         port = &common->ports[port_id];
      |                 ~~~~~~~~~~~~~^~~~~~~~~
drivers/net/am65-cpsw-nuss.c:115:33: note: while referencing ?ports?
  115 |         struct am65_cpsw_port  ports[AM65_CPSW_CPSWNU_MAX_PORTS];
      |                                 ^~~~~

port_id is read from the hardware and used unsanitized to index into an
array. Rework the code, so out-of-bound access leads to an error, but
no out of bound access.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/net/am65-cpsw-nuss.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/am65-cpsw-nuss.c b/drivers/net/am65-cpsw-nuss.c
index f6dc811bd982..6b9432e2d4e7 100644
--- a/drivers/net/am65-cpsw-nuss.c
+++ b/drivers/net/am65-cpsw-nuss.c
@@ -466,7 +466,6 @@ static void am65_cpsw_recv(struct eth_device *edev)
 	dma_addr_t pkt;
 	int ret;
 	u32 num, port_id;
-	bool valid = true;
 
 	if (!common->started)
 		return;
@@ -489,18 +488,17 @@ static void am65_cpsw_recv(struct eth_device *edev)
 	port_id = packet_data.src_tag;
 	if (port_id >= AM65_CPSW_CPSWNU_MAX_PORTS) {
 		dev_err(common->dev, "received pkt on invalid port_id %d\n", port_id);
-		valid = false;
+		goto out;
 	}
 
 	port = &common->ports[port_id];
 	if (!port->enabled) {
 		dev_err(common->dev, "received pkt on disabled port_id %d\n", port_id);
-		valid = false;
+		goto out;
 	}
 
-	if (valid)
-		net_receive(&port->edev, (void *)pkt, ret);
-
+	net_receive(&port->edev, (void *)pkt, ret);
+out:
 	num = common->rx_next % UDMA_RX_DESC_NUM;
 
 	dma_sync_single_for_device(common->dev, pkt, ret, DMA_FROM_DEVICE);
-- 
2.39.5



From a.fatoum at pengutronix.de  Mon Mar 17 04:32:07 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 17 Mar 2025 12:32:07 +0100
Subject: [PATCH v2 1/2] MAKEALL: support direct options for KCONFIG_ADD
Message-ID: <20250317113208.1863258-1-a.fatoum@pengutronix.de>

KCONFIG_ADD currently expects a list of files to be merged.
As MAKEALL is a bash script, let's make use of process substitution
to create temporary files out of -k CONFIG_foo=bar options.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - fix Regex (Sascha)
---
 MAKEALL | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/MAKEALL b/MAKEALL
index 1966eedb4673..bc612b45561f 100755
--- a/MAKEALL
+++ b/MAKEALL
@@ -56,7 +56,7 @@ usage() {
 	echo "BUILDDIR    -O      build dir"
 	echo "LOGDIR      -l      log dir"
 	echo "REGEX       -e      regex"
-	echo "KCONFIG_ADD -k      kconfig fragment"
+	echo "KCONFIG_ADD -k      kconfig fragment or option"
 	echo "TARGET      -t      Makefile target"
 	echo "V           -v      verbosity"
 	echo "INCREMENTAL -i"
@@ -116,6 +116,11 @@ report() {
 	fi
 }
 
+merge_config() {
+	with_logs_collected ./scripts/kconfig/merge_config.sh -m -O \
+		${BUILDDIR} "$@"
+}
+
 do_build_defconfig() {
 	local arch=$1
 	local defconfig=$2
@@ -156,8 +161,11 @@ do_build_defconfig() {
 	MAKE="${MAKE} $silent_flag CROSS_COMPILE=${cross_compile}"
 	with_logs_collected ${MAKE} ${defconfig}
 	for i in ${KCONFIG_ADD}; do
-		with_logs_collected ./scripts/kconfig/merge_config.sh -m -O \
-			${BUILDDIR} ${BUILDDIR}/.config $i
+		if [[ $i =~ ^CONFIG_.*=.* ]]; then
+			merge_config ${BUILDDIR}/.config <(echo $i)
+		else
+			merge_config ${BUILDDIR}/.config $i
+		fi
 	done
 	with_logs_collected ${MAKE} $silent_flag olddefconfig
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Mon Mar 17 04:32:08 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 17 Mar 2025 12:32:08 +0100
Subject: [PATCH v2 2/2] MAKEALL: parse kconfig_add out of YAML files
In-Reply-To: <20250317113208.1863258-1-a.fatoum@pengutronix.de>
References: <20250317113208.1863258-1-a.fatoum@pengutronix.de>
Message-ID: <20250317113208.1863258-2-a.fatoum@pengutronix.de>

Now that MAKEALL supports direct options in KCONFIG_ADD, teach it to
read runner kconfig_add keys out of the labgrid environment YAML files.

This is a further step towards removal of test/emulate.pl.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - no change
---
 MAKEALL            | 13 +++++++++++++
 test/Containerfile |  1 +
 2 files changed, 14 insertions(+)

diff --git a/MAKEALL b/MAKEALL
index bc612b45561f..a9409fbf7b07 100755
--- a/MAKEALL
+++ b/MAKEALL
@@ -422,6 +422,19 @@ else
 		if [[ $i =~ ^.*/([^/]+)/([^@]*@|)([^.]+).yaml$ ]]; then
 			arch=${BASH_REMATCH[1]}
 			defconfig=${BASH_REMATCH[3]}
+
+			if grep -q "^\s\+kconfig_add:" $i; then
+				if command -v yq 2>&1 >/dev/null; then
+					KCONFIG_ADD="${KCONFIG_ADD} $(yq -M -r \
+					'.targets.main.runner.kconfig_add |
+					keys[] as $k | .[$k]' < $i)"
+				else
+					echo "WARNING: yq command not found in path" >&2
+					echo "WARNING: ignoring kconfig_add in $i" >&2
+					echo
+				fi
+			fi
+
 			do_build_defconfig $arch $defconfig
 			if [ $? -eq 0 ]; then
 				do_test_defconfig $config $defconfig "${pytest_opts[@]}"
diff --git a/test/Containerfile b/test/Containerfile
index db43d039b922..53a5443e48fe 100644
--- a/test/Containerfile
+++ b/test/Containerfile
@@ -51,6 +51,7 @@ RUN apt-get update && apt-get install -y \
 	sudo \
 	u-boot-tools \
 	yamllint \
+	yq \
 	&& rm -rf /var/lib/apt/lists/*
 
 ENV GCC_VERSION=14.2.0
-- 
2.39.5



From a.fatoum at pengutronix.de  Mon Mar 17 04:32:40 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 17 Mar 2025 12:32:40 +0100
Subject: [PATCH 1/2] MAKEALL: support direct options for KCONFIG_ADD
In-Reply-To: <Z9fpmOzuQh7G4WW_@pengutronix.de>
References: <20250313113604.915474-1-a.fatoum@pengutronix.de>
 <Z9fpmOzuQh7G4WW_@pengutronix.de>
Message-ID: <bd45abc4-afef-4f80-ab3b-edd501eb7180@pengutronix.de>



On 3/17/25 10:21, Sascha Hauer wrote:
> On Thu, Mar 13, 2025 at 12:36:03PM +0100, Ahmad Fatoum wrote:
>> KCONFIG_ADD currently expects a list of files to be merged.
>> As MAKEALL is a bash script, let's make use of process substitution
>> to create temporary files out of -k CONFIG_foo=bar options.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
>> ---
>>  MAKEALL | 14 +++++++++++---
>>  1 file changed, 11 insertions(+), 3 deletions(-)
>>
>> diff --git a/MAKEALL b/MAKEALL
>> index 1966eedb4673..b0967b8ae340 100755
>> --- a/MAKEALL
>> +++ b/MAKEALL
>> @@ -56,7 +56,7 @@ usage() {
>>  	echo "BUILDDIR    -O      build dir"
>>  	echo "LOGDIR      -l      log dir"
>>  	echo "REGEX       -e      regex"
>> -	echo "KCONFIG_ADD -k      kconfig fragment"
>> +	echo "KCONFIG_ADD -k      kconfig fragment or option"
>>  	echo "TARGET      -t      Makefile target"
>>  	echo "V           -v      verbosity"
>>  	echo "INCREMENTAL -i"
>> @@ -116,6 +116,11 @@ report() {
>>  	fi
>>  }
>>  
>> +merge_config() {
>> +	with_logs_collected ./scripts/kconfig/merge_config.sh -m -O \
>> +		${BUILDDIR} "$@"
>> +}
>> +
>>  do_build_defconfig() {
>>  	local arch=$1
>>  	local defconfig=$2
>> @@ -156,8 +161,11 @@ do_build_defconfig() {
>>  	MAKE="${MAKE} $silent_flag CROSS_COMPILE=${cross_compile}"
>>  	with_logs_collected ${MAKE} ${defconfig}
>>  	for i in ${KCONFIG_ADD}; do
>> -		with_logs_collected ./scripts/kconfig/merge_config.sh -m -O \
>> -			${BUILDDIR} ${BUILDDIR}/.config $i
>> +		if [[ $i =~ ^CONFIG_* ]]; then
> 
> '_*' matches zero or more underscores which is likely not what you mean
> here.
> 
> How about ^CONFIG_.*=.* which also tests for the equal sign.

Sounds good. Please see v2 that I just sent out.

> 
> Sascha
> 



From a.fatoum at pengutronix.de  Mon Mar 17 04:34:21 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 17 Mar 2025 12:34:21 +0100
Subject: [PATCH 05/11] fs: add qemu_fw_cfg file system
In-Reply-To: <Z9fbfE-1IZr44IUs@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
 <20250313101728.3546902-6-a.fatoum@pengutronix.de>
 <Z9fbfE-1IZr44IUs@pengutronix.de>
Message-ID: <66db8ce1-0791-43ed-8ef8-b28630c87500@pengutronix.de>

Hello Sascha,

On 3/17/25 09:21, Sascha Hauer wrote:
> Hi Ahmad,
> 
> On Thu, Mar 13, 2025 at 11:17:22AM +0100, Ahmad Fatoum wrote:
>> +static int fw_cfg_fs_io(struct device *dev, struct file *f, void *buf,
>> +			 size_t insize, bool read)
>> +{
>> +	struct inode *inode = f->f_inode;
>> +	struct fw_cfg_fs_inode *node = inode_to_node(inode);
>> +	struct fw_cfg_fs_data *data = dev->priv;
>> +	int fd = data->fd;
>> +
>> +	if (node->buf) {
>> +		if (read)
>> +			memcpy(buf, node->buf + f->f_pos, insize);
>> +		else
>> +			memcpy(node->buf + f->f_pos, buf, insize);
>> +		return insize;
>> +	}
>> +
>> +	ioctl(fd, FW_CFG_SELECT, &(u16) { inode->i_ino });
>> +
>> +	if (read)
>> +		return pread(fd, buf, insize, f->f_pos);
>> +	else
>> +		return pwrite(fd, buf, insize, f->f_pos);
>> +}
>> +
>> +static int fw_cfg_fs_read(struct device *dev, struct file *f, void *buf,
>> +			   size_t insize)
>> +{
>> +	return fw_cfg_fs_io(dev, f, buf, insize, true);
>> +}
>> +
>> +static int fw_cfg_fs_write(struct device *dev, struct file *f, const void *buf,
>> +			    size_t insize)
>> +{
>> +	return fw_cfg_fs_io(dev, f, (void *)buf, insize, false);
>> +}
>> +
>> +static int fw_cfg_fw_truncate(struct device *dev, struct file *f, loff_t size)
>> +{
>> +	return 0;
>> +}
> 
> By returning 0 here you claim that the file can get an arbitrary size.
> 
> node->buf is a fixed size buffer. If I understand correctly then
> node->buf is only used for special files like "name", "raw".

Yes.

> However, writing to these files is not prohibited, consequently a
> cp /dev/ram0 /mnt/fw_cfg//by_key/37/key results in memory corrupions.

Ouch, I will revisit this.

> Writing data to a file I passed via --env truncates the file to the
> written data size, but the actual content of the file is unchanged. I
> still read back the original data. Is writing data supported?

I am not sure. I only wrote the special framebuffer file so far.
I will look into it.

Cheers,
Ahmad

> 
> Sascha
> 



From a.fatoum at pengutronix.de  Mon Mar 17 04:36:48 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 17 Mar 2025 12:36:48 +0100
Subject: [PATCH 11/11] fs: qemu_fw_cfg: support populating environment via
 QEMU fw_cfg
In-Reply-To: <Z9fS5ZZzEDheZMJh@pengutronix.de>
References: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
 <20250313101728.3546902-12-a.fatoum@pengutronix.de>
 <Z9fS5ZZzEDheZMJh@pengutronix.de>
Message-ID: <710a2e83-3027-49dc-8035-a374075eb2e9@pengutronix.de>

Hi Sascha,

On 3/17/25 08:44, Sascha Hauer wrote:
> Hi Ahmad,
> 
> On Thu, Mar 13, 2025 at 11:17:28AM +0100, Ahmad Fatoum wrote:
>> diff --git a/fs/qemu_fw_cfg.c b/fs/qemu_fw_cfg.c
>> index 7f7350e67e64..ef2a1008ee5d 100644
>> --- a/fs/qemu_fw_cfg.c
>> +++ b/fs/qemu_fw_cfg.c
>> @@ -13,6 +13,7 @@
>>  #include <errno.h>
>>  #include <linux/stat.h>
>>  #include <xfuncs.h>
>> +#include <envfs.h>
>>  #include <fcntl.h>
>>  #include <linux/qemu_fw_cfg.h>
>>  #include <wchar.h>
>> @@ -363,7 +364,13 @@ static int fw_cfg_fs_probe(struct device *dev)
>>  	 */
>>  	fsdev->cdev = cdev_by_name(devpath_to_name(fsdev->backingstore));
>>  
>> -	return fw_cfg_fs_parse(sb);
>> +	ret = fw_cfg_fs_parse(sb);
>> +	if (ret)
>> +		goto free_data;
>> +
>> +	defaultenv_append_runtime_directory("/mnt/fw_cfg/by_name/opt/org.barebox.env");
> 
> I see the variables show up in /mnt/fw_cfg/by_name/opt/org.barebox.env/,
> but not in the environment.
> 
> I wonder how this is supposed to work. The fw_cfg fs is mounted when I
> first access /mnt/fw_cfg on the barebox command line, but at that time
> defaultenv_append_runtime_directory() has no effect anymore as
> defaultenv_load() is executed during startup.

I had the ramfb driver enabled and that mounted the FS for me...

> Should defaultenv_append_runtime_directory() be called in
> qemu_fw_cfg_fs_init() instead?

Possibly. I will check for v2.

Thanks for your feedback and testing,
Ahmad

> 
> Sascha
> 



From s.hauer at pengutronix.de  Mon Mar 17 05:27:04 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 13:27:04 +0100
Subject: [PATCH] net: am65-cpsw-nuss: fix out-of-bounds access
In-Reply-To: <20250317113142.1862481-1-a.fatoum@pengutronix.de>
References: <20250317113142.1862481-1-a.fatoum@pengutronix.de>
Message-ID: <174221442479.3180549.5387539647769916844.b4-ty@pengutronix.de>


On Mon, 17 Mar 2025 12:31:42 +0100, Ahmad Fatoum wrote:
> GCC 12.2.0 complains about am65_cpsw_recv:
> 
> drivers/net/am65-cpsw-nuss.c: In function ?am65_cpsw_recv?:
> drivers/net/am65-cpsw-nuss.c:495:30: warning: array subscript 9 is
>   above array bounds of ?struct am65_cpsw_port[9]? [-Warray-bounds]
>   495 |         port = &common->ports[port_id];
>       |                 ~~~~~~~~~~~~~^~~~~~~~~
> drivers/net/am65-cpsw-nuss.c:115:33: note: while referencing ?ports?
>   115 |         struct am65_cpsw_port  ports[AM65_CPSW_CPSWNU_MAX_PORTS];
>       |                                 ^~~~~
> 
> [...]

Applied, thanks!

[1/1] net: am65-cpsw-nuss: fix out-of-bounds access
      https://git.pengutronix.de/cgit/barebox/commit/?id=9c9f95c45431 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 17 05:28:31 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 13:28:31 +0100
Subject: [PATCH] net: am65-cpsw-nuss: remove unused variables
Message-ID: <20250317122831.3207605-1-s.hauer@pengutronix.de>

In struct am65_cpsw_common the fields rx_next and rx_pend are set but
not used. Remove them.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/net/am65-cpsw-nuss.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/net/am65-cpsw-nuss.c b/drivers/net/am65-cpsw-nuss.c
index 6b9432e2d4..1b90669fec 100644
--- a/drivers/net/am65-cpsw-nuss.c
+++ b/drivers/net/am65-cpsw-nuss.c
@@ -118,8 +118,6 @@ struct am65_cpsw_common {
 
 	struct dma		*dma_tx;
 	struct dma		*dma_rx;
-	u32			rx_next;
-	u32			rx_pend;
 	int			started;
 };
 
@@ -285,8 +283,6 @@ static int am65_cpsw_common_start(struct am65_cpsw_common *common)
 		goto err_off_pwrdm;
 	}
 
-	common->rx_next = 0;
-	common->rx_pend = 0;
 	common->dma_tx = dma_get_by_name(common->dev, "tx0");
 	if (IS_ERR(common->dma_tx)) {
 		ret = PTR_ERR(common->dma_tx);
@@ -465,7 +461,7 @@ static void am65_cpsw_recv(struct eth_device *edev)
 	struct ti_udma_drv_packet_data packet_data;
 	dma_addr_t pkt;
 	int ret;
-	u32 num, port_id;
+	u32 port_id;
 
 	if (!common->started)
 		return;
@@ -499,15 +495,11 @@ static void am65_cpsw_recv(struct eth_device *edev)
 
 	net_receive(&port->edev, (void *)pkt, ret);
 out:
-	num = common->rx_next % UDMA_RX_DESC_NUM;
-
 	dma_sync_single_for_device(common->dev, pkt, ret, DMA_FROM_DEVICE);
 
 	ret = dma_prepare_rcv_buf(common->dma_rx, pkt, PKTSIZE);
 	if (ret)
 		dev_err(common->dev, "RX dma free_pkt failed %d\n", ret);
-
-	common->rx_next++;
 }
 
 static void am65_cpsw_common_stop(struct am65_cpsw_common *common)
-- 
2.39.5



From s.hauer at pengutronix.de  Mon Mar 17 05:28:52 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Mar 2025 13:28:52 +0100
Subject: [PATCH v2 1/2] MAKEALL: support direct options for KCONFIG_ADD
In-Reply-To: <20250317113208.1863258-1-a.fatoum@pengutronix.de>
References: <20250317113208.1863258-1-a.fatoum@pengutronix.de>
Message-ID: <174221453273.3211264.6864612304810272816.b4-ty@pengutronix.de>


On Mon, 17 Mar 2025 12:32:07 +0100, Ahmad Fatoum wrote:
> KCONFIG_ADD currently expects a list of files to be merged.
> As MAKEALL is a bash script, let's make use of process substitution
> to create temporary files out of -k CONFIG_foo=bar options.
> 
> 

Applied, thanks!

[1/2] MAKEALL: support direct options for KCONFIG_ADD
      https://git.pengutronix.de/cgit/barebox/commit/?id=b39351c0036f (link may not be stable)
[2/2] MAKEALL: parse kconfig_add out of YAML files
      https://git.pengutronix.de/cgit/barebox/commit/?id=3b288224cc6c (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From a.fatoum at pengutronix.de  Mon Mar 17 08:18:32 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 17 Mar 2025 16:18:32 +0100
Subject: [PATCH 4/9] mci: add RPMB support
In-Reply-To: <20250312-rpmb-v1-4-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
 <20250312-rpmb-v1-4-0f213382a3f3@pengutronix.de>
Message-ID: <9c66b31b-a79c-4a07-a03f-119c7c3dadc7@pengutronix.de>

Hello Sascha,

On 3/12/25 13:16, Sascha Hauer wrote:
> +
> +int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
> +			  void *rsp, unsigned long rsplen)
> +{
> +	/*
> +	 * Whoever crafted the data supplied to this function knows how to
> +	 * format the PRMB frames and which response is expected. If
> +	 * there's some unexpected mismatch it's more helpful to report an
> +	 * error immediately than trying to guess what was the intention
> +	 * and possibly just delay an eventual error which will be harder
> +	 * to track down.
> +	 */
> +	void *rpmb_data = NULL;
> +	int ret;
> +
> +	mci_blk_part_switch(mci->rpmb_part);
> +
> +	if (!IS_ALIGNED((uintptr_t)req, ARCH_DMA_MINALIGN)) {

Even if alignment happens to be correct, there is no guarantee that
there is no other data sharing a cache line.

Let's just return an error for the unaligned case instead and expect
users to align the request.

Thanks,
Ahmad

> +		/* Memory alignment is required by MMC driver */
> +		rpmb_data = dma_alloc(reqlen);
> +		if (!rpmb_data)
> +			return -ENOMEM;
> +
> +		memcpy(rpmb_data, req, reqlen);
> +		req = rpmb_data;
> +	}
> +
> +	ret = rpmb_route_frames(mci, req, reqlen, rsp, rsplen);
> +
> +	free(rpmb_data);
> +
> +	return ret;
> +}
> diff --git a/include/mci.h b/include/mci.h
> index 08a3e46f7d..ec0390eedf 100644
> --- a/include/mci.h
> +++ b/include/mci.h
> @@ -736,6 +736,9 @@ int mmc_select_timing(struct mci *mci);
>  int mci_set_blockcount(struct mci *mci, unsigned int cmdarg);
>  int mci_blk_part_switch(struct mci_part *part);
>  int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data);
> +struct mci *mci_get_rpmb_dev(void);
> +int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
> +			  void *rsp, unsigned long rsplen);
>  
>  static inline bool mmc_card_hs200(struct mci *mci)
>  {
> 



From uwe at kleine-koenig.org  Mon Mar 17 09:38:28 2025
From: uwe at kleine-koenig.org (Uwe =?utf-8?Q?Kleine-K=C3=B6nig?=)
Date: Mon, 17 Mar 2025 17:38:28 +0100
Subject: [PATCH 0/4] Add support for QNAP's ts-433 4bay NAS
In-Reply-To: <Z8bEobxWH6sNRt6B@pengutronix.de>
References: <cover.1740846737.git.uwe@kleine-koenig.org>
 <Z8bEobxWH6sNRt6B@pengutronix.de>
Message-ID: <ft7kujxf2r52nbvndmel5qxxf5ddeugp45gvuhsyqaatsjjniz@g4jbaeh4n6sa>

Hello Sascha,

thanks for picking up the first three patches
On Tue, Mar 04, 2025 at 10:15:13AM +0100, Sascha Hauer wrote:
> On Sat, Mar 01, 2025 at 05:36:17PM +0100, Uwe Kleine-K?nig wrote:
> > this is the result of my quick effort to make barebox run on QNAP's
> > ts-433 4bay NAS. The first 3 patches are IMHO fine to go in. The last
> > one adds the new machine. As writting in the commit log the NAS boots
> > with the resulting image, but neither network nor eMMC work.
> > 
> > I also tried adding
> > 
> > 	writel(RK_SETBITS(0x50), 0xfdc20140)
> > 
> > in lowlevel.c, but that didn't make a difference. I'm open for other
> > ideas about what bit is missing.
> 
> dts/src/arm64/rockchip/rk3568-qnap-ts433.dts lacks the pinctrl nodes for
> the sdhci controller. It might be that it works when booting from eMMC,
> but not when booting from USB.

When I add pinctrl info like that:

diff --git a/dts/src/arm64/rockchip/rk3568-qnap-ts433.dts b/dts/src/arm64/rockchip/rk3568-qnap-ts433.dts
index e601d9271ba8..b65f2412023a 100644
--- a/dts/src/arm64/rockchip/rk3568-qnap-ts433.dts
+++ b/dts/src/arm64/rockchip/rk3568-qnap-ts433.dts
@@ -567,6 +567,8 @@ &sdhci {
 	bus-width = <8>;
 	max-frequency = <200000000>;
 	non-removable;
+	pinctrl-names = "default";
+	pinctrl-0 = <&emmc_bus8 &emmc_clk &emmc_cmd &emmc_datastrobe>;
 	status = "okay";
 };

I get an error message when the driver probes (see below).

Enabling deep probe (which was an idea from #barebox) didn't change
anything here.

> No idea for networking though.

With rtl8169 driver disabled the internal eth driver probes successfully
(didn't work out the details, with both enabled I get 
	ERROR: register_device: already registered eth
	ERROR: eqos-rockchip fe2a0000.ethernet at fe2a0000.of: probe failed: Invalid argument
) the full boot log is:

	barebox 2025.02.0-00004-g1ec0faa7cbbb-dirty #9 Mon Mar 17 17:29:30 CET 2025


	Board: Qnap TS-433-4G NAS System 4-Bay
	deep-probe: supported due to qnap,ts433
	rockchip-dmc memory-controller.of: Detected memory size: 0x100000000
	netconsole: registered as netconsole-1
	arm-scmi firmware:scmi.of: SCMI Protocol v2.0 'rockchip:' Firmware version 0x0
	psci psci.of: detected version 1.1
	xHCI xHCI0: USB XHCI 1.10
	ehci fd800000.usb at fd800000.of: USB EHCI 1.00
	ehci fd880000.usb at fd880000.of: USB EHCI 1.00
	rk808 rk8090: chip id: 0x8090
	rk3568-dwcmshc-sdhci fe310000.mmc at fe310000.of: registered as mmc0
	ERROR: rk3568-dwcmshc-sdhci fe310000.mmc at fe310000.of: SDHCI timeout while waiting for idle
	WARNING: mmc0: Card's startup fails with -16
	phy6: lane number 0, val 1
	phy6: lane number 1, val 2
	phy6: bifurcation enabled
	mdio_bus: miibus0: probed
	malloc space: 0xafd00000 -> 0xefcfffff (size 1 GiB)
	environment load /dev/env0: No such file or directory
	Maybe you have to create the partition.

	Hit any to stop autoboot:    3
	eth0: 1000Mbps full duplex link detected
	barebox at QNAP TS-433:/ ifup eth0
	WARNING: eth0: No MAC address set. Using random address 22:e8:c9:ad:3e:45
	T T T T T T T T T T T T T T T T T T T T ifup: Connection timed out

I guess the next step is to try 2nd stage booting with U-Boot.

Best regards
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20250317/71eca9ff/attachment.sig>

From eagle.alexander923 at gmail.com  Tue Mar 18 00:43:23 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Tue, 18 Mar 2025 10:43:23 +0300
Subject: [PATCH 1/5] ARM: at91: Add PBL_BREAK support
Message-ID: <20250318074327.37730-1-eagle.alexander923@gmail.com>

This adds PBL_BREAK support to the barebox at91 header.
Since we're here, let's set the header parameters to the defaults
for the barebox and do some code formatting to improve readability.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 include/mach/at91/barebox-arm.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/mach/at91/barebox-arm.h b/include/mach/at91/barebox-arm.h
index 3a041b4557..ef4bb185bc 100644
--- a/include/mach/at91/barebox-arm.h
+++ b/include/mach/at91/barebox-arm.h
@@ -34,15 +34,16 @@ static __always_inline void __barebox_at91_head(void)
 		".endr\n"
 		"2:\n"
 	);
+	pbl_barebox_break();
 }
 
 #define SAMA5_ENTRY_FUNCTION(name, stack_top, r4)				\
-	void name (u32 r0, u32 r1, u32 r2, u32 r3);				\
+	void name (u32 r0, u32 r1, u32 r2);					\
 										\
 	static void __##name(u32);						\
 										\
 	void __naked __section(.text_head_entry_##name)	name			\
-				(u32 r0, u32 r1, u32 r2, u32 r3)		\
+				(u32 r0, u32 r1, u32 r2)			\
 		{								\
 			register u32 r4 asm("r4");				\
 			__barebox_at91_head();					\
@@ -50,7 +51,7 @@ static __always_inline void __barebox_at91_head(void)
 				arm_setup_stack(stack_top);			\
 			__##name(r4);						\
 		}								\
-		static void noinline __##name(u32 r4)
+	static void noinline __##name(u32 r4)
 
 /* BootROM already initialized usable stack top */
 #define SAMA5D2_ENTRY_FUNCTION(name, r4)					\
@@ -62,7 +63,7 @@ static __always_inline void __barebox_at91_head(void)
 #define SAMA5D4_ENTRY_FUNCTION(name, r4)					\
 	SAMA5_ENTRY_FUNCTION(name, SAMA5D4_SRAM_BASE + SAMA5D4_SRAM_SIZE, r4)
 
-#define SAM9_ENTRY_FUNCTION(name)	\
+#define SAM9_ENTRY_FUNCTION(name)						\
 	ENTRY_FUNCTION_WITHSTACK_HEAD(name, AT91SAM9261_SRAM_BASE + AT91SAM9261_SRAM_SIZE, \
 				      __barebox_at91_head, r0, r1, r2)
 
-- 
2.39.1



From eagle.alexander923 at gmail.com  Tue Mar 18 00:43:24 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Tue, 18 Mar 2025 10:43:24 +0300
Subject: [PATCH 2/5] ARM: at91: Merge sama5_boot_xload() asm code
In-Reply-To: <20250318074327.37730-1-eagle.alexander923@gmail.com>
References: <20250318074327.37730-1-eagle.alexander923@gmail.com>
Message-ID: <20250318074327.37730-2-eagle.alexander923@gmail.com>

This merges the sama5_boot_xload() assembler code to prevent
the r4 register from being used in the second line of asm volatile().

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 include/mach/at91/sama5_bootsource.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/mach/at91/sama5_bootsource.h b/include/mach/at91/sama5_bootsource.h
index 2fb65ce10f..aeda1b4114 100644
--- a/include/mach/at91/sama5_bootsource.h
+++ b/include/mach/at91/sama5_bootsource.h
@@ -56,8 +56,13 @@ extern unsigned long at91_bootsource;
 
 static inline void __noreturn sama5_boot_xload(void __noreturn (*bb)(void), u32 r4)
 {
-	asm volatile("mov r4, %0" : : "r"(r4) : );
-	asm volatile("bx  %0"     : : "r"(bb) : );
+	asm volatile (
+		"mov r4, %0\n"
+		"bx  %1\n"
+		:
+		: "r"(r4), "r"(bb)
+		: "r4"
+	);
 	__builtin_unreachable();
 }
 
-- 
2.39.1



From eagle.alexander923 at gmail.com  Tue Mar 18 00:43:25 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Tue, 18 Mar 2025 10:43:25 +0300
Subject: [PATCH 3/5] ARM: at91: Rename xload-mmc.c
In-Reply-To: <20250318074327.37730-1-eagle.alexander923@gmail.com>
References: <20250318074327.37730-1-eagle.alexander923@gmail.com>
Message-ID: <20250318074327.37730-3-eagle.alexander923@gmail.com>

This will rename xload-mmc.c to the simpler name xload.c indicating
support for booting from more than just MMC for the first stage of
the bootloader.
Also rename the hidden helper configuration option for this.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/Kconfig                  | 2 +-
 arch/arm/mach-at91/Makefile                 | 3 +--
 arch/arm/mach-at91/{xload-mmc.c => xload.c} | 0
 3 files changed, 2 insertions(+), 3 deletions(-)
 rename arch/arm/mach-at91/{xload-mmc.c => xload.c} (100%)

diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig
index 2f70e4aac3..bb04c1267e 100644
--- a/arch/arm/mach-at91/Kconfig
+++ b/arch/arm/mach-at91/Kconfig
@@ -52,7 +52,7 @@ config HAVE_AT91_SDRAMC
 config HAVE_AT91_DDRAMC
 	bool
 
-config AT91_MCI_PBL
+config AT91_PBL
 	def_bool MCI_ATMEL_PBL || MCI_ATMEL_SDHCI_PBL
 
 # Select if board uses the common at91sam926x_board_init
diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
index 556e46f181..1c87cab5bb 100644
--- a/arch/arm/mach-at91/Makefile
+++ b/arch/arm/mach-at91/Makefile
@@ -14,8 +14,7 @@ obj-$(CONFIG_BOOTM) += bootm-barebox.o
 obj-y += at91sam9_reset.o
 obj-pbl-$(CONFIG_HAVE_AT91_DDRAMC) += ddramc.o
 obj-pbl-$(CONFIG_HAVE_AT91_SDRAMC) += sdramc.o
-pbl-$(CONFIG_AT91_MCI_PBL) +=  xload-mmc.o
-pbl-$(CONFIG_AT91_MCI_PBL) +=  at91sam9_xload_mmc.o
+pbl-$(CONFIG_AT91_PBL) += at91sam9_xload_mmc.o xload.o
 
 obj-$(CONFIG_AT91SAM9_SMC) += sam9_smc.o
 obj-$(CONFIG_HAVE_AT91SAM9_RST) += at91sam9_rst.o
diff --git a/arch/arm/mach-at91/xload-mmc.c b/arch/arm/mach-at91/xload.c
similarity index 100%
rename from arch/arm/mach-at91/xload-mmc.c
rename to arch/arm/mach-at91/xload.c
-- 
2.39.1



From eagle.alexander923 at gmail.com  Tue Mar 18 00:43:26 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Tue, 18 Mar 2025 10:43:26 +0300
Subject: [PATCH 4/5] ARM: at91: sama5: Unify xx_start_image() calls
In-Reply-To: <20250318074327.37730-1-eagle.alexander923@gmail.com>
References: <20250318074327.37730-1-eagle.alexander923@gmail.com>
Message-ID: <20250318074327.37730-4-eagle.alexander923@gmail.com>

This unifies the xload.c start_image() code for both sama5d2() and
sama5d3() CPU variants.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 .../arm/boards/sama5d27-giantboard/lowlevel.c |   2 +-
 arch/arm/boards/sama5d27-som1/lowlevel.c      |   2 +-
 arch/arm/mach-at91/xload.c                    | 102 ++++++++++--------
 include/mach/at91/xload.h                     |   2 +-
 4 files changed, 62 insertions(+), 46 deletions(-)

diff --git a/arch/arm/boards/sama5d27-giantboard/lowlevel.c b/arch/arm/boards/sama5d27-giantboard/lowlevel.c
index 49540bede0..c266af6357 100644
--- a/arch/arm/boards/sama5d27-giantboard/lowlevel.c
+++ b/arch/arm/boards/sama5d27-giantboard/lowlevel.c
@@ -31,7 +31,7 @@ SAMA5D2_ENTRY_FUNCTION(start_sama5d27_giantboard_xload_mmc, r4)
 
 	sama5d2_udelay_init(MASTER_CLOCK);
 	sama5d2_d1g_ddrconf();
-	sama5d2_sdhci_start_image(r4);
+	sama5d2_start_image(r4);
 }
 
 extern char __dtb_z_at91_sama5d27_giantboard_start[];
diff --git a/arch/arm/boards/sama5d27-som1/lowlevel.c b/arch/arm/boards/sama5d27-som1/lowlevel.c
index 67300587fe..e74502244b 100644
--- a/arch/arm/boards/sama5d27-som1/lowlevel.c
+++ b/arch/arm/boards/sama5d27-som1/lowlevel.c
@@ -55,7 +55,7 @@ SAMA5D2_ENTRY_FUNCTION(start_sama5d27_som1_ek_xload_mmc, r4)
 	ek_turn_led(RGB_LED_RED | RGB_LED_GREEN); /* Yellow */
 	sama5d2_udelay_init(MASTER_CLOCK);
 	sama5d2_d1g_ddrconf();
-	sama5d2_sdhci_start_image(r4);
+	sama5d2_start_image(r4);
 }
 
 extern char __dtb_z_at91_sama5d27_som1_ek_start[];
diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 9c03d2119c..e417223b31 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -11,39 +11,50 @@
 #include <asm/cache.h>
 #include <pbl/bio.h>
 
-static void at91_fat_start_image(struct pbl_bio *bio,
-				 void *buf, unsigned int len,
-				 u32 r4)
+struct xload_instance {
+	void __iomem *base;
+	unsigned id;
+	u8 periph;
+	s8 pins[15];
+};
+
+static void at91_fat_start_image(struct pbl_bio *bio, u32 r4)
 {
-	void __noreturn (*bb)(void);
+	void *buf = (void *)SAMA5_DDRCS;
 	int ret;
 
-	ret = pbl_fat_load(bio, "barebox.bin", buf, len);
+	ret = pbl_fat_load(bio, "barebox.bin", buf, SZ_2M);
 	if (ret < 0) {
 		pr_err("pbl_fat_load: error %d\n", ret);
 		return;
 	}
 
-	bb = buf;
-
 	sync_caches_for_execution();
 
-	sama5_boot_xload(bb, r4);
+	sama5_boot_xload(buf, r4);
 }
 
-static const struct sdhci_instance {
-	void __iomem *base;
-	unsigned id;
-	u8 periph;
-	s8 pins[15];
-} sdhci_instances[] = {
+static const struct xload_instance sama5d2_mci_instances[] = {
 	[0] = {
-		.base = SAMA5D2_BASE_SDHC0, .id = SAMA5D2_ID_SDMMC0, .periph = AT91_MUX_PERIPH_A,
-		.pins = { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 13, 10, 11, 12, -1 }
+		.base = SAMA5D2_BASE_SDHC0,
+		.id = SAMA5D2_ID_SDMMC0,
+		.periph = AT91_MUX_PERIPH_A,
+		.pins = {
+			AT91_PIN_PA2, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5,
+			AT91_PIN_PA6, AT91_PIN_PA7, AT91_PIN_PA8, AT91_PIN_PA9,
+			AT91_PIN_PA0, AT91_PIN_PA1, AT91_PIN_PA13, AT91_PIN_PA10,
+			AT91_PIN_PA11, AT91_PIN_PA12, -1
+		}
 	},
 	[1] = {
-		.base = SAMA5D2_BASE_SDHC1, .id = SAMA5D2_ID_SDMMC1, .periph = AT91_MUX_PERIPH_E,
-		.pins = { 18, 19, 20, 21, 22, 28, 30, -1 }
+		.base = SAMA5D2_BASE_SDHC1,
+		.id = SAMA5D2_ID_SDMMC1,
+		.periph = AT91_MUX_PERIPH_E,
+		.pins = {
+			AT91_PIN_PA18, AT91_PIN_PA19, AT91_PIN_PA20,
+			AT91_PIN_PA21, AT91_PIN_PA22, AT91_PIN_PA28,
+			AT91_PIN_PA30, -1
+		}
 	},
 };
 
@@ -51,25 +62,23 @@ static const struct sdhci_instance {
  * sama5d2_sdhci_start_image - Load and start an image from FAT-formatted SDHCI
  * @r4: value of r4 passed by BootROM
  */
-void __noreturn sama5d2_sdhci_start_image(u32 r4)
+static void __noreturn sama5d2_sdhci_start_image(u32 r4)
 {
-	void *buf = (void *)SAMA5_DDRCS;
-	const struct sdhci_instance *instance;
+	const struct xload_instance *instance;
 	struct pbl_bio bio;
 	const s8 *pin;
 	int ret;
 
 	ret = sama5_bootsource_instance(r4);
-	if (ret > 1)
+	if (ret > ARRAY_SIZE(sama5d2_mci_instances) - 1)
 		panic("Couldn't determine boot MCI instance\n");
 
-	instance = &sdhci_instances[ret];
+	instance = &sama5d2_mci_instances[ret];
 
 	sama5d2_pmc_enable_periph_clock(SAMA5D2_ID_PIOA);
-	for (pin = instance->pins; *pin >= 0; pin++) {
+	for (pin = instance->pins; *pin >= 0; pin++)
 		at91_mux_pio4_set_periph(SAMA5D2_BASE_PIOA,
 					 BIT(*pin), instance->periph);
-	}
 
 	sama5d2_pmc_enable_periph_clock(instance->id);
 	sama5d2_pmc_enable_generic_clock(instance->id, AT91_PMC_GCKCSS_UPLL_CLK, 1);
@@ -80,18 +89,26 @@ void __noreturn sama5d2_sdhci_start_image(u32 r4)
 
 	/* TODO: eMMC boot partition handling: they are not FAT-formatted */
 
-	at91_fat_start_image(&bio, buf, SZ_16M, r4);
+	at91_fat_start_image(&bio, r4);
 
 out_panic:
 	panic("FAT chainloading failed\n");
 }
 
-static const struct atmci_instance {
-	void __iomem *base;
-	unsigned id;
-	u8 periph;
-	s8 pins[15];
-} sama5d3_atmci_instances[] = {
+void __noreturn sama5d2_start_image(u32 r4)
+{
+	switch (sama5_bootsource(r4)) {
+	case BOOTSOURCE_MMC:
+		sama5d2_sdhci_start_image(r4);
+		break;
+	default:
+		break;
+	}
+
+	panic("Unsupported boot configuration!\n");
+}
+
+static const struct xload_instance sama5d3_mci_instances[] = {
 	[0] = {
 		.base = IOMEM(SAMA5D3_BASE_HSMCI0),
 		.id = SAMA5D3_ID_HSMCI0,
@@ -99,30 +116,29 @@ static const struct atmci_instance {
 		.pins = {
 			AT91_PIN_PD0, AT91_PIN_PD1, AT91_PIN_PD2, AT91_PIN_PD3,
 			AT91_PIN_PD4, AT91_PIN_PD5, AT91_PIN_PD6, AT91_PIN_PD7,
-			AT91_PIN_PD8, AT91_PIN_PD9, -1 }
+			AT91_PIN_PD8, AT91_PIN_PD9, -1
+		}
 	},
 };
 
-void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
+void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
 					  unsigned int slot)
 {
-	void *buf = (void *)SAMA5_DDRCS;
-	const struct atmci_instance *instance;
+	const struct xload_instance *instance;
 	struct pbl_bio bio;
 	const s8 *pin;
 	int ret;
 
-	ret = sama5_bootsource_instance(boot_src);
-	if (ret > ARRAY_SIZE(sama5d3_atmci_instances) - 1)
+	ret = sama5_bootsource_instance(r4);
+	if (ret > ARRAY_SIZE(sama5d3_mci_instances) - 1)
 		panic("Couldn't determine boot MCI instance\n");
 
-	instance = &sama5d3_atmci_instances[boot_src];
+	instance = &sama5d3_mci_instances[r4];
 
 	sama5d3_pmc_enable_periph_clock(SAMA5D3_ID_PIOD);
-	for (pin = instance->pins; *pin >= 0; pin++) {
+	for (pin = instance->pins; *pin >= 0; pin++)
 		at91_mux_pio3_pin(IOMEM(SAMA5D3_BASE_PIOD),
-					 pin_to_mask(*pin), instance->periph, 0);
-	}
+				  pin_to_mask(*pin), instance->periph, 0);
 
 	sama5d3_pmc_enable_periph_clock(instance->id);
 
@@ -130,7 +146,7 @@ void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
 	if (ret)
 		goto out_panic;
 
-	at91_fat_start_image(&bio, buf, SZ_16M, boot_src);
+	at91_fat_start_image(&bio, r4);
 
 out_panic:
 	panic("FAT chainloading failed\n");
diff --git a/include/mach/at91/xload.h b/include/mach/at91/xload.h
index 2886490246..d5fc7596fd 100644
--- a/include/mach/at91/xload.h
+++ b/include/mach/at91/xload.h
@@ -6,7 +6,7 @@
 #include <linux/compiler.h>
 #include <pbl/bio.h>
 
-void __noreturn sama5d2_sdhci_start_image(u32 r4);
+void __noreturn sama5d2_start_image(u32 r4);
 void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
 					  unsigned int slot);
 
-- 
2.39.1



From eagle.alexander923 at gmail.com  Tue Mar 18 00:43:27 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Tue, 18 Mar 2025 10:43:27 +0300
Subject: [PATCH 5/5] ARM: at91: sama5d2: Add QSPI boot support
In-Reply-To: <20250318074327.37730-1-eagle.alexander923@gmail.com>
References: <20250318074327.37730-1-eagle.alexander923@gmail.com>
Message-ID: <20250318074327.37730-5-eagle.alexander923@gmail.com>

This adds QSPI NOR boot support for sama5d2 CPUs.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/xload.c | 84 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index e417223b31..9f9945e96d 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <common.h>
+#include <filetype.h>
 #include <mach/at91/xload.h>
 #include <mach/at91/sama5_bootsource.h>
 #include <mach/at91/hardware.h>
@@ -95,12 +96,95 @@ static void __noreturn sama5d2_sdhci_start_image(u32 r4)
 	panic("FAT chainloading failed\n");
 }
 
+static const struct xload_instance sama5d2_qspi_ioset1_instances[] = {
+	[0] = {
+		.base = SAMA5D2_BASE_QSPI0,
+		.id = SAMA5D2_ID_QSPI0,
+		.periph = AT91_MUX_PERIPH_B,
+		.pins = {
+			AT91_PIN_PA0, AT91_PIN_PA1, AT91_PIN_PA2,
+			AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, -1
+		}
+	},
+	[1] = {
+		.base = SAMA5D2_BASE_QSPI1,
+		.id = SAMA5D2_ID_QSPI1,
+		.periph = AT91_MUX_PERIPH_B,
+		.pins = {
+			AT91_PIN_PA6, AT91_PIN_PA7, AT91_PIN_PA8,
+			AT91_PIN_PA9, AT91_PIN_PA10, AT91_PIN_PA11, -1
+		}
+	},
+};
+
+/**
+ * sama5d2_qspi_start_image - Start an image from QSPI NOR flash
+ * @r4: value of r4 passed by BootROM
+ */
+static void __noreturn sama5d2_qspi_start_image(u32 r4)
+{
+	void __iomem *mem, *dest = IOMEM(SAMA5_DDRCS);
+	const struct xload_instance *instance;
+	const s8 *pin;
+	u32 offs;
+	int ret;
+
+	ret = sama5_bootsource_instance(r4);
+	if (ret == 0)
+		mem = SAMA5D2_BASE_QSPI0_MEM;
+	else if (ret == 1)
+		mem = SAMA5D2_BASE_QSPI1_MEM;
+	else
+		panic("Couldn't determine boot QSPI instance\n");
+
+	instance = &sama5d2_qspi_ioset1_instances[ret];
+
+	sama5d2_pmc_enable_periph_clock(SAMA5D2_ID_PIOA);
+	for (pin = instance->pins; *pin >= 0; pin++)
+		at91_mux_pio4_set_periph(SAMA5D2_BASE_PIOA,
+					 BIT(*pin), instance->periph);
+
+	sama5d2_pmc_enable_periph_clock(instance->id);
+
+	/*
+	 * Since we booted from QSPI, we expect the QSPI registers to be
+	 * properly initialized already.
+	 * Let's just read the memory-mapped data.
+	 */
+
+	/* Find barebox pattern first */
+	for (offs = SZ_128K; offs <= SZ_1M; offs += SZ_128K) {
+		/* Fix cache coherency issue by reading each sector only once */
+		memcpy(dest, mem + offs, SZ_128K);
+
+		if (is_barebox_arm_head(dest)) {
+			u32 size = readl(dest + ARM_HEAD_SIZE_OFFSET);
+
+			pr_info("Image found at 0x%08x, size %u\n", offs, size);
+
+			/* Copy remaining barebox code */
+			if (size > SZ_128K)
+				memcpy(dest + SZ_128K, mem + offs + SZ_128K,
+				       size - SZ_128K);
+
+			sync_caches_for_execution();
+
+			sama5_boot_xload(dest, r4);
+		}
+	}
+
+	panic("No barebox image found!\n");
+}
+
 void __noreturn sama5d2_start_image(u32 r4)
 {
 	switch (sama5_bootsource(r4)) {
 	case BOOTSOURCE_MMC:
 		sama5d2_sdhci_start_image(r4);
 		break;
+	case BOOTSOURCE_SPI:
+		sama5d2_qspi_start_image(r4);
+		break;
 	default:
 		break;
 	}
-- 
2.39.1



From a.fatoum at pengutronix.de  Tue Mar 18 01:24:35 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Mar 2025 09:24:35 +0100
Subject: [PATCH master] partition: fix reference to wrong cdev in warning message
Message-ID: <20250318082435.419053-1-a.fatoum@pengutronix.de>

For MBR and GPT, barebox creates links to the partitions, so they can be
referenced both by index and partition label.

Failing to create a link is not an error, but results in a warning
message. The current message claims that the link was pointing at the
parent block device's cdev, but it actually was pointing at the child
partition. Fix that.

Reported-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/partitions.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/partitions.c b/common/partitions.c
index 7562536cf9b8..bc90f51f6112 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -63,7 +63,7 @@ static int register_one_partition(struct block_device *blk, struct partition *pa
 	ret = devfs_create_link(cdev, partition_name);
 	if (ret)
 		dev_warn(blk->dev, "Failed to create link from %s to %s\n",
-			 partition_name, blk->cdev.name);
+			 partition_name, cdev->name);
 	free(partition_name);
 
 	return 0;
-- 
2.39.5



From a.fatoum at pengutronix.de  Tue Mar 18 01:25:04 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Mar 2025 09:25:04 +0100
Subject: [PATCH 1/4] scripts/make_fit: factor dtb file name into configuration name
Message-ID: <20250318082507.419785-1-a.fatoum@pengutronix.de>

Bootloaders often support booting a specific FIT configuration by name.
This is useful when the automatic boot fails, because the bootloader's
DT compatible differs from the upstream one included with the Linux
device trees.

Currently, configuration are numbered sequentially requiring the user to
dump the FIT image to determine what number the configuration has.

Improve upon this by naming configurations after the dtb name instead.
This is what OE-core kernel-fitimage.bbclass does for example.

Cc: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 scripts/make_fit.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/scripts/make_fit.py b/scripts/make_fit.py
index 075b7c258ff2..2190da4c003c 100755
--- a/scripts/make_fit.py
+++ b/scripts/make_fit.py
@@ -145,11 +145,9 @@ def finish_fit(fsw, entries):
             str: Compatible stringlist
     """
     fsw.end_node()
-    seq = 0
     with fsw.add_node('configurations'):
-        for model, compat, files in entries:
-            seq += 1
-            with fsw.add_node(f'conf-{seq}'):
+        for dtbname, model, compat, files in entries:
+            with fsw.add_node(f'conf-{dtbname}'):
                 fsw.property('compatible', bytes(compat))
                 fsw.property_string('description', model)
                 fsw.property('fdt', bytes(''.join(f'fdt-{x}\x00' for x in files), "ascii"))
@@ -266,6 +264,7 @@ def build_fit(args):
     fsw = libfdt.FdtSw()
     setup_fit(fsw, args.name)
     entries = []
+    dtbs_seen = set()
     fdts = {}
 
     # Handle the kernel
@@ -290,7 +289,13 @@ def build_fit(args):
 
         files_seq = [fdts[fn] for fn in files]
 
-        entries.append([model, compat, files_seq])
+        dtbname = os.path.basename(fname)
+        ndtbs_seen = len(dtbs_seen)
+        dtbs_seen.add(dtbname)
+        if len(dtbs_seen) == ndtbs_seen:
+            raise RuntimeError(f"Duplicate file name '{dtbname}' during FIT creation")
+
+        entries.append([dtbname, model, compat, files_seq])
 
     finish_fit(fsw, entries)
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Tue Mar 18 01:25:07 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Mar 2025 09:25:07 +0100
Subject: [PATCH 4/4] ARM: qemu: mask data aborts during AMBA identification
In-Reply-To: <20250318082507.419785-1-a.fatoum@pengutronix.de>
References: <20250318082507.419785-1-a.fatoum@pengutronix.de>
Message-ID: <20250318082507.419785-4-a.fatoum@pengutronix.de>

The barebox FIT image target is meant as an easy way to load barebox
second stage from other bootloaders.

Doing so with U-Boot 2025.01 compiled for qemu_arm64_defconfig
currently leads to a crash when accessing the PL061 GPIO controller
device for identification.

It seems that U-Boot (or TF-A, which wasn't included in my setup)
should have done some initial setup to allow access to the PL061.

barebox doesn't even have a driver for the peripheral and loading
barebox directly with -kernel works. In both cases, barebox runs in EL1.

Let's thus workaround the issue on the barebox side by using the new
CONFIG_ARM_AMBA_DABT_MASK option to turn the crash into an error
message.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index f5f9f3828782..7d46dcfb63dc 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -282,6 +282,7 @@ config BOARD_ARM_VIRT
 	select BOARD_GENERIC_DT
 	select BOARD_QEMU_VIRT
 	select OF_OVERLAY
+	select ARM_AMBA_DABT_MASK
 
 config BOARD_ARM_GENERIC_DT
 	def_bool BOARD_GENERIC_DT
-- 
2.39.5



From a.fatoum at pengutronix.de  Tue Mar 18 01:25:06 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Mar 2025 09:25:06 +0100
Subject: [PATCH 3/4] amba: support masking data abort during identification
In-Reply-To: <20250318082507.419785-1-a.fatoum@pengutronix.de>
References: <20250318082507.419785-1-a.fatoum@pengutronix.de>
Message-ID: <20250318082507.419785-3-a.fatoum@pengutronix.de>

Registration of an AMBA device requires reading its pid and cid
registers after turning on the device. This is the first I/O done to the
device and may end up crashing if the device tree doesn't describe
the correct clock and power domains or if a previous boot stage
should've enabled them, but didn't.

This is not a likely issue, but when it happens it crashes the system
annoyingly early during device tree populating.

Add a symbol that masks the data abort exception around the
identification code to turn the crash into an error message instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/amba/Kconfig | 19 +++++++++++++++++++
 drivers/amba/bus.c   | 12 +++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/amba/Kconfig b/drivers/amba/Kconfig
index 444d4ce7435c..be5e053f4b84 100644
--- a/drivers/amba/Kconfig
+++ b/drivers/amba/Kconfig
@@ -1,3 +1,22 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config ARM_AMBA
 	bool
+
+config ARM_AMBA_DABT_MASK
+	bool
+	prompt "Mask data abort while identifying AMBA devices" if COMPILE_TEST
+	depends on ARM_AMBA && ARCH_HAS_DATA_ABORT_MASK
+	help
+	  Registration of an AMBA device requires reading its pid and cid
+	  registers after turning on the device, which can involve enabling
+	  clocks, deasserting resets and powering on power domains.
+	  In some cases, these resources are not available to barebox running
+	  in the normal world and thus need to be setup by a previous
+	  stage bootloader running in the secure world.
+	  If such setup doesn't happen, accessing devices may lead to
+	  a data abort or complete system hang.
+
+	  As a workaround for the former case, this option can be enabled
+	  to gracefully handle data aborts during readout of the PID/CID
+	  registers. The proper solution is fixing your first stage
+	  bootloader or allow barebox access to the missing resources.
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 6463366fafc5..5ed8336e6124 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -10,6 +10,7 @@
 #include <linux/amba/bus.h>
 #include <io.h>
 #include <init.h>
+#include <abort.h>
 
 #define to_amba_driver(d)	container_of(d, struct amba_driver, drv)
 
@@ -132,6 +133,9 @@ int amba_device_add(struct amba_device *dev)
 	if (ret == 0) {
 		u32 pid, cid;
 
+		if (IS_ENABLED(CONFIG_ARM_AMBA_DABT_MASK))
+			data_abort_mask();
+
 		/*
 		 * Read pid and cid based on size of resource
 		 * they are located at end of region
@@ -139,8 +143,14 @@ int amba_device_add(struct amba_device *dev)
 		pid = amba_device_get_pid(tmp, size);
 		cid = amba_device_get_cid(tmp, size);
 
-		if (cid == AMBA_CID)
+		if (IS_ENABLED(CONFIG_ARM_AMBA_DABT_MASK) && data_abort_unmask()) {
+			dev_err(amba_bustype.dev,
+				"data abort during MMIO read of PID/CID for %pOF\n",
+				dev->dev.of_node);
+			ret = -EFAULT;
+		} else if (cid == AMBA_CID) {
 			dev->periphid = pid;
+		}
 
 		if (!dev->periphid)
 			ret = -ENODEV;
-- 
2.39.5



From a.fatoum at pengutronix.de  Tue Mar 18 01:25:05 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Mar 2025 09:25:05 +0100
Subject: [PATCH 2/4] amba: drop unused hepers for creating AMBA devices outside OF
In-Reply-To: <20250318082507.419785-1-a.fatoum@pengutronix.de>
References: <20250318082507.419785-1-a.fatoum@pengutronix.de>
Message-ID: <20250318082507.419785-2-a.fatoum@pengutronix.de>

All amba devices created for upstream boards are instantiated from
device tree. The headers have functions that can be used from board
code, but are unused, so let's drop them and make AMBA OF-only.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/amba/bus.c       | 21 ---------------------
 include/linux/amba/bus.h | 23 -----------------------
 2 files changed, 44 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index cf43aaa76ea1..6463366fafc5 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -162,27 +162,6 @@ int amba_device_add(struct amba_device *dev)
 	return ret;
 }
 
-struct amba_device *
-amba_aphb_device_add(struct device *parent, const char *name, int id,
-		     resource_size_t base, size_t size,
-		     void *pdata, unsigned int periphid)
-{
-	struct amba_device *dev;
-	int ret;
-
-	dev = amba_device_alloc(name, id, base, size);
-
-	dev->periphid = periphid;
-	dev->dev.platform_data = pdata;
-	dev->dev.parent = parent;
-
-	ret = amba_device_add(dev);
-	if (ret)
-		return ERR_PTR(ret);
-
-	return dev;
-}
-
 /**
  *	amba_device_alloc - allocate an AMBA device
  *	@name: sysfs name of the AMBA device
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index cc24b38e8300..7cbc4e653eac 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -74,29 +74,6 @@ void amba_device_put(struct amba_device *);
 int amba_device_add(struct amba_device *);
 int amba_device_register(struct amba_device *, struct resource *);
 
-struct amba_device *
-amba_aphb_device_add(struct device *parent, const char *name, int id,
-		     resource_size_t base, size_t size,
-		     void *pdata, unsigned int periphid);
-
-static inline struct amba_device *
-amba_apb_device_add(struct device *parent, const char *name, int id,
-		    resource_size_t base, size_t size,
-		    void *pdata, unsigned int periphid)
-{
-	return amba_aphb_device_add(parent, name, id, base, size, pdata,
-				    periphid);
-}
-
-static inline struct amba_device *
-amba_ahb_device_add(struct device *parent, const char *name, int id,
-		    resource_size_t base, size_t size,
-		    void *pdata, unsigned int periphid)
-{
-	return amba_aphb_device_add(parent, name, id, base, size, pdata,
-				    periphid);
-}
-
 static inline void __iomem *amba_get_mem_region(struct amba_device *dev)
 {
 	return dev->base;
-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 18 03:21:27 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 11:21:27 +0100
Subject: [PATCH] watchdog: rti_wdt: return 0 even when not ready for
 ping
In-Reply-To: <20250317104022.1046085-1-s.hauer@pengutronix.de>
References: <20250317104022.1046085-1-s.hauer@pengutronix.de>
Message-ID: <174229328774.3839599.4843202908065121251.b4-ty@pengutronix.de>


On Mon, 17 Mar 2025 11:40:22 +0100, Sascha Hauer wrote:
> The rti_wdt is a windowed watchdog which means we are not allowed to
> ping the watchdog outside a certain timing window. When pinging the
> watchdog too early the watchdog will trigger.
> 
> We used to return -EBUSY from the watchdogs ping callback when
> pinging outside the timing window. We may ping the watchdog multiple
> times in boot_entry() which then results in
> 
> [...]

Applied, thanks!

[1/1] watchdog: rti_wdt: return 0 even when not ready for ping
      https://git.pengutronix.de/cgit/barebox/commit/?id=85654b653d7c (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar 18 03:21:40 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 11:21:40 +0100
Subject: [PATCH] net: am65-cpsw-nuss: remove unused variables
In-Reply-To: <20250317122831.3207605-1-s.hauer@pengutronix.de>
References: <20250317122831.3207605-1-s.hauer@pengutronix.de>
Message-ID: <174229330032.3839698.14017843546247934885.b4-ty@pengutronix.de>


On Mon, 17 Mar 2025 13:28:31 +0100, Sascha Hauer wrote:
> In struct am65_cpsw_common the fields rx_next and rx_pend are set but
> not used. Remove them.
> 
> 

Applied, thanks!

[1/1] net: am65-cpsw-nuss: remove unused variables
      https://git.pengutronix.de/cgit/barebox/commit/?id=72b221652b86 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar 18 03:22:58 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 11:22:58 +0100
Subject: [PATCH master] partition: fix reference to wrong cdev in
 warning message
In-Reply-To: <20250318082435.419053-1-a.fatoum@pengutronix.de>
References: <20250318082435.419053-1-a.fatoum@pengutronix.de>
Message-ID: <174229337835.3839813.3617173015969684887.b4-ty@pengutronix.de>


On Tue, 18 Mar 2025 09:24:35 +0100, Ahmad Fatoum wrote:
> For MBR and GPT, barebox creates links to the partitions, so they can be
> referenced both by index and partition label.
> 
> Failing to create a link is not an error, but results in a warning
> message. The current message claims that the link was pointing at the
> parent block device's cdev, but it actually was pointing at the child
> partition. Fix that.
> 
> [...]

Applied, thanks!

[1/1] partition: fix reference to wrong cdev in warning message
      https://git.pengutronix.de/cgit/barebox/commit/?id=a0ba27e06535 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From uwe at kleine-koenig.org  Tue Mar 18 03:53:18 2025
From: uwe at kleine-koenig.org (Uwe =?utf-8?Q?Kleine-K=C3=B6nig?=)
Date: Tue, 18 Mar 2025 11:53:18 +0100
Subject: [PATCH 2/4] amba: drop unused hepers for creating AMBA devices
 outside OF
In-Reply-To: <20250318082507.419785-2-a.fatoum@pengutronix.de>
References: <20250318082507.419785-1-a.fatoum@pengutronix.de>
 <20250318082507.419785-2-a.fatoum@pengutronix.de>
Message-ID: <vh6zygee2p4sc7karvch2n7mxqeo2e2253fjvtegtrbrv4vxvs@ujnozm5kxxbn>

Hello Ahmad,

$Subject ~= s/hepers/helpers/

Best regards
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20250318/df61d573/attachment-0001.sig>

From s.hauer at pengutronix.de  Tue Mar 18 03:55:27 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 11:55:27 +0100
Subject: [PATCH 4/5] ARM: at91: sama5: Unify xx_start_image() calls
In-Reply-To: <20250318074327.37730-4-eagle.alexander923@gmail.com>
References: <20250318074327.37730-1-eagle.alexander923@gmail.com>
 <20250318074327.37730-4-eagle.alexander923@gmail.com>
Message-ID: <Z9lRH065pPDbir9z@pengutronix.de>

Hi Alexander,

On Tue, Mar 18, 2025 at 10:43:26AM +0300, Alexander Shiyan wrote:
> This unifies the xload.c start_image() code for both sama5d2() and
> sama5d3() CPU variants.

I have trouble bringing the description together with what the patch
acutally does.

> 
> Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
> ---
>  .../arm/boards/sama5d27-giantboard/lowlevel.c |   2 +-
>  arch/arm/boards/sama5d27-som1/lowlevel.c      |   2 +-
>  arch/arm/mach-at91/xload.c                    | 102 ++++++++++--------
>  include/mach/at91/xload.h                     |   2 +-
>  4 files changed, 62 insertions(+), 46 deletions(-)
> 
> diff --git a/arch/arm/boards/sama5d27-giantboard/lowlevel.c b/arch/arm/boards/sama5d27-giantboard/lowlevel.c
> index 49540bede0..c266af6357 100644
> --- a/arch/arm/boards/sama5d27-giantboard/lowlevel.c
> +++ b/arch/arm/boards/sama5d27-giantboard/lowlevel.c
> @@ -31,7 +31,7 @@ SAMA5D2_ENTRY_FUNCTION(start_sama5d27_giantboard_xload_mmc, r4)
>  
>  	sama5d2_udelay_init(MASTER_CLOCK);
>  	sama5d2_d1g_ddrconf();
> -	sama5d2_sdhci_start_image(r4);
> +	sama5d2_start_image(r4);
>  }
>  
>  extern char __dtb_z_at91_sama5d27_giantboard_start[];
> diff --git a/arch/arm/boards/sama5d27-som1/lowlevel.c b/arch/arm/boards/sama5d27-som1/lowlevel.c
> index 67300587fe..e74502244b 100644
> --- a/arch/arm/boards/sama5d27-som1/lowlevel.c
> +++ b/arch/arm/boards/sama5d27-som1/lowlevel.c
> @@ -55,7 +55,7 @@ SAMA5D2_ENTRY_FUNCTION(start_sama5d27_som1_ek_xload_mmc, r4)
>  	ek_turn_led(RGB_LED_RED | RGB_LED_GREEN); /* Yellow */
>  	sama5d2_udelay_init(MASTER_CLOCK);
>  	sama5d2_d1g_ddrconf();
> -	sama5d2_sdhci_start_image(r4);
> +	sama5d2_start_image(r4);
>  }
>  
>  extern char __dtb_z_at91_sama5d27_som1_ek_start[];
> diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
> index 9c03d2119c..e417223b31 100644
> --- a/arch/arm/mach-at91/xload.c
> +++ b/arch/arm/mach-at91/xload.c
> @@ -11,39 +11,50 @@
>  #include <asm/cache.h>
>  #include <pbl/bio.h>
>  
> -static void at91_fat_start_image(struct pbl_bio *bio,
> -				 void *buf, unsigned int len,
> -				 u32 r4)
> +struct xload_instance {
> +	void __iomem *base;
> +	unsigned id;
> +	u8 periph;
> +	s8 pins[15];
> +};

Original code has struct sdhci_instance and struct atmci_instance which
both have the same members. You unify this to struct xload_instance
which is a good step. I think this should be a separate patch along with
the rename from sdhci_instance[] to sama5d2_mci_instances[] and
sama5d3_atmci_instances[] to sama5d3_mci_instances[].

This will help to better see what the rest of this patch is about.

> +
> +static void at91_fat_start_image(struct pbl_bio *bio, u32 r4)

You remove the *buf and len arguments from at91_fat_start_image()
because both arguments are common for all callers. Again, should be a
separate patch.

>  {
> -	void __noreturn (*bb)(void);
> +	void *buf = (void *)SAMA5_DDRCS;
>  	int ret;
>  
> -	ret = pbl_fat_load(bio, "barebox.bin", buf, len);
> +	ret = pbl_fat_load(bio, "barebox.bin", buf, SZ_2M);
>  	if (ret < 0) {
>  		pr_err("pbl_fat_load: error %d\n", ret);
>  		return;
>  	}
>  
> -	bb = buf;
> -
>  	sync_caches_for_execution();
>  
> -	sama5_boot_xload(bb, r4);
> +	sama5_boot_xload(buf, r4);
>  }
>  
> -static const struct sdhci_instance {
> -	void __iomem *base;
> -	unsigned id;
> -	u8 periph;
> -	s8 pins[15];
> -} sdhci_instances[] = {
> +static const struct xload_instance sama5d2_mci_instances[] = {
>  	[0] = {
> -		.base = SAMA5D2_BASE_SDHC0, .id = SAMA5D2_ID_SDMMC0, .periph = AT91_MUX_PERIPH_A,
> -		.pins = { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 13, 10, 11, 12, -1 }
> +		.base = SAMA5D2_BASE_SDHC0,
> +		.id = SAMA5D2_ID_SDMMC0,
> +		.periph = AT91_MUX_PERIPH_A,
> +		.pins = {
> +			AT91_PIN_PA2, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5,
> +			AT91_PIN_PA6, AT91_PIN_PA7, AT91_PIN_PA8, AT91_PIN_PA9,
> +			AT91_PIN_PA0, AT91_PIN_PA1, AT91_PIN_PA13, AT91_PIN_PA10,
> +			AT91_PIN_PA11, AT91_PIN_PA12, -1
> +		}

Here the hardcoded values are replaced with defines which is also a good
step but could be a separate patch.

>  	},
>  	[1] = {
> -		.base = SAMA5D2_BASE_SDHC1, .id = SAMA5D2_ID_SDMMC1, .periph = AT91_MUX_PERIPH_E,
> -		.pins = { 18, 19, 20, 21, 22, 28, 30, -1 }
> +		.base = SAMA5D2_BASE_SDHC1,
> +		.id = SAMA5D2_ID_SDMMC1,
> +		.periph = AT91_MUX_PERIPH_E,
> +		.pins = {
> +			AT91_PIN_PA18, AT91_PIN_PA19, AT91_PIN_PA20,
> +			AT91_PIN_PA21, AT91_PIN_PA22, AT91_PIN_PA28,
> +			AT91_PIN_PA30, -1
> +		}
>  	},
>  };
>  
> @@ -51,25 +62,23 @@ static const struct sdhci_instance {
>   * sama5d2_sdhci_start_image - Load and start an image from FAT-formatted SDHCI
>   * @r4: value of r4 passed by BootROM
>   */
> -void __noreturn sama5d2_sdhci_start_image(u32 r4)
> +static void __noreturn sama5d2_sdhci_start_image(u32 r4)
>  {
> -	void *buf = (void *)SAMA5_DDRCS;
> -	const struct sdhci_instance *instance;
> +	const struct xload_instance *instance;
>  	struct pbl_bio bio;
>  	const s8 *pin;
>  	int ret;
>  
>  	ret = sama5_bootsource_instance(r4);
> -	if (ret > 1)
> +	if (ret > ARRAY_SIZE(sama5d2_mci_instances) - 1)
>  		panic("Couldn't determine boot MCI instance\n");
>  
> -	instance = &sdhci_instances[ret];
> +	instance = &sama5d2_mci_instances[ret];
>  
>  	sama5d2_pmc_enable_periph_clock(SAMA5D2_ID_PIOA);
> -	for (pin = instance->pins; *pin >= 0; pin++) {
> +	for (pin = instance->pins; *pin >= 0; pin++)
>  		at91_mux_pio4_set_periph(SAMA5D2_BASE_PIOA,
>  					 BIT(*pin), instance->periph);
> -	}
>  
>  	sama5d2_pmc_enable_periph_clock(instance->id);
>  	sama5d2_pmc_enable_generic_clock(instance->id, AT91_PMC_GCKCSS_UPLL_CLK, 1);
> @@ -80,18 +89,26 @@ void __noreturn sama5d2_sdhci_start_image(u32 r4)
>  
>  	/* TODO: eMMC boot partition handling: they are not FAT-formatted */
>  
> -	at91_fat_start_image(&bio, buf, SZ_16M, r4);
> +	at91_fat_start_image(&bio, r4);
>  
>  out_panic:
>  	panic("FAT chainloading failed\n");
>  }
>  
> -static const struct atmci_instance {
> -	void __iomem *base;
> -	unsigned id;
> -	u8 periph;
> -	s8 pins[15];
> -} sama5d3_atmci_instances[] = {
> +void __noreturn sama5d2_start_image(u32 r4)
> +{
> +	switch (sama5_bootsource(r4)) {
> +	case BOOTSOURCE_MMC:
> +		sama5d2_sdhci_start_image(r4);
> +		break;
> +	default:
> +		break;
> +	}
> +
> +	panic("Unsupported boot configuration!\n");
> +}

And this is what the patch really is about: You want to have a function
which is no longer MMC specific, but boots from MMC/QSPI depending on
the bootsource. Please make this a separate patch as well.

Sascha

-- 
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-5555 |


From uwe at kleine-koenig.org  Tue Mar 18 04:03:18 2025
From: uwe at kleine-koenig.org (Uwe =?utf-8?Q?Kleine-K=C3=B6nig?=)
Date: Tue, 18 Mar 2025 12:03:18 +0100
Subject: [PATCH 1/4] scripts/make_fit: factor dtb file name into
 configuration name
In-Reply-To: <20250318082507.419785-1-a.fatoum@pengutronix.de>
References: <20250318082507.419785-1-a.fatoum@pengutronix.de>
Message-ID: <v4s2tw2pg3o7ougore4dvhuzpfqz4lgehiskaopfw5gllpyptb@2fjhiqk36mqo>

Hello Ahmad,

On Tue, Mar 18, 2025 at 09:25:04AM +0100, Ahmad Fatoum wrote:
> Bootloaders often support booting a specific FIT configuration by name.
> This is useful when the automatic boot fails, because the bootloader's
> DT compatible differs from the upstream one included with the Linux
> device trees.
> 
> Currently, configuration are numbered sequentially requiring the user to
> dump the FIT image to determine what number the configuration has.
> 
> Improve upon this by naming configurations after the dtb name instead.
> This is what OE-core kernel-fitimage.bbclass does for example.
> 
> Cc: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  scripts/make_fit.py | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/scripts/make_fit.py b/scripts/make_fit.py
> index 075b7c258ff2..2190da4c003c 100755
> --- a/scripts/make_fit.py
> +++ b/scripts/make_fit.py
> @@ -145,11 +145,9 @@ def finish_fit(fsw, entries):
>              str: Compatible stringlist
>      """
>      fsw.end_node()
> -    seq = 0
>      with fsw.add_node('configurations'):
> -        for model, compat, files in entries:
> -            seq += 1
> -            with fsw.add_node(f'conf-{seq}'):
> +        for dtbname, model, compat, files in entries:
> +            with fsw.add_node(f'conf-{dtbname}'):

Funny/surprising semantic of fsw.add_node (i.e. fsw refers to the new
node in the with-body?)

>                  fsw.property('compatible', bytes(compat))
>                  fsw.property_string('description', model)
>                  fsw.property('fdt', bytes(''.join(f'fdt-{x}\x00' for x in files), "ascii"))
> @@ -266,6 +264,7 @@ def build_fit(args):
>      fsw = libfdt.FdtSw()
>      setup_fit(fsw, args.name)
>      entries = []
> +    dtbs_seen = set()
>      fdts = {}
>  
>      # Handle the kernel
> @@ -290,7 +289,13 @@ def build_fit(args):
>  
>          files_seq = [fdts[fn] for fn in files]
>  
> -        entries.append([model, compat, files_seq])
> +        dtbname = os.path.basename(fname)
> +        ndtbs_seen = len(dtbs_seen)
> +        dtbs_seen.add(dtbname)
> +        if len(dtbs_seen) == ndtbs_seen:
> +            raise RuntimeError(f"Duplicate file name '{dtbname}' during FIT creation")
> +
> +        entries.append([dtbname, model, compat, files_seq])

	dtbname = os.path.basename(fname)
	if dtbname in dtbs_seen:
	    raise RuntimeError(...)
	dtbs_seen.add(dtbname)
	entries.append(...)

looks more pythonic (to me).

Acked-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>

for the idea of this patch.

Best regards
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20250318/e268c9c9/attachment.sig>

From s.hauer at pengutronix.de  Tue Mar 18 04:04:34 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 12:04:34 +0100
Subject: [PATCH 3/4] amba: support masking data abort during
 identification
In-Reply-To: <20250318082507.419785-3-a.fatoum@pengutronix.de>
References: <20250318082507.419785-1-a.fatoum@pengutronix.de>
 <20250318082507.419785-3-a.fatoum@pengutronix.de>
Message-ID: <Z9lTQlVUBnZUPm9q@pengutronix.de>

On Tue, Mar 18, 2025 at 09:25:06AM +0100, Ahmad Fatoum wrote:
> Registration of an AMBA device requires reading its pid and cid
> registers after turning on the device. This is the first I/O done to the
> device and may end up crashing if the device tree doesn't describe
> the correct clock and power domains or if a previous boot stage
> should've enabled them, but didn't.
> 
> This is not a likely issue, but when it happens it crashes the system
> annoyingly early during device tree populating.
> 
> Add a symbol that masks the data abort exception around the
> identification code to turn the crash into an error message instead.

Do we need to make this optional? I could imagine I find out about the
existence of this option only after having traced the issue down to the
exact lines of code in which case I won't need the option anymore.

Sascha

> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  drivers/amba/Kconfig | 19 +++++++++++++++++++
>  drivers/amba/bus.c   | 12 +++++++++++-
>  2 files changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/amba/Kconfig b/drivers/amba/Kconfig
> index 444d4ce7435c..be5e053f4b84 100644
> --- a/drivers/amba/Kconfig
> +++ b/drivers/amba/Kconfig
> @@ -1,3 +1,22 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  config ARM_AMBA
>  	bool
> +
> +config ARM_AMBA_DABT_MASK
> +	bool
> +	prompt "Mask data abort while identifying AMBA devices" if COMPILE_TEST
> +	depends on ARM_AMBA && ARCH_HAS_DATA_ABORT_MASK
> +	help
> +	  Registration of an AMBA device requires reading its pid and cid
> +	  registers after turning on the device, which can involve enabling
> +	  clocks, deasserting resets and powering on power domains.
> +	  In some cases, these resources are not available to barebox running
> +	  in the normal world and thus need to be setup by a previous
> +	  stage bootloader running in the secure world.
> +	  If such setup doesn't happen, accessing devices may lead to
> +	  a data abort or complete system hang.
> +
> +	  As a workaround for the former case, this option can be enabled
> +	  to gracefully handle data aborts during readout of the PID/CID
> +	  registers. The proper solution is fixing your first stage
> +	  bootloader or allow barebox access to the missing resources.
> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
> index 6463366fafc5..5ed8336e6124 100644
> --- a/drivers/amba/bus.c
> +++ b/drivers/amba/bus.c
> @@ -10,6 +10,7 @@
>  #include <linux/amba/bus.h>
>  #include <io.h>
>  #include <init.h>
> +#include <abort.h>
>  
>  #define to_amba_driver(d)	container_of(d, struct amba_driver, drv)
>  
> @@ -132,6 +133,9 @@ int amba_device_add(struct amba_device *dev)
>  	if (ret == 0) {
>  		u32 pid, cid;
>  
> +		if (IS_ENABLED(CONFIG_ARM_AMBA_DABT_MASK))
> +			data_abort_mask();
> +
>  		/*
>  		 * Read pid and cid based on size of resource
>  		 * they are located at end of region
> @@ -139,8 +143,14 @@ int amba_device_add(struct amba_device *dev)
>  		pid = amba_device_get_pid(tmp, size);
>  		cid = amba_device_get_cid(tmp, size);
>  
> -		if (cid == AMBA_CID)
> +		if (IS_ENABLED(CONFIG_ARM_AMBA_DABT_MASK) && data_abort_unmask()) {
> +			dev_err(amba_bustype.dev,
> +				"data abort during MMIO read of PID/CID for %pOF\n",
> +				dev->dev.of_node);
> +			ret = -EFAULT;
> +		} else if (cid == AMBA_CID) {
>  			dev->periphid = pid;
> +		}
>  
>  		if (!dev->periphid)
>  			ret = -ENODEV;
> -- 
> 2.39.5
> 
> 
> 

-- 
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-5555 |


From s.hauer at pengutronix.de  Tue Mar 18 04:07:07 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 12:07:07 +0100
Subject: [PATCH 4/4] ARM: qemu: mask data aborts during AMBA
 identification
In-Reply-To: <20250318082507.419785-4-a.fatoum@pengutronix.de>
References: <20250318082507.419785-1-a.fatoum@pengutronix.de>
 <20250318082507.419785-4-a.fatoum@pengutronix.de>
Message-ID: <Z9lT26AVZGa65OWT@pengutronix.de>

On Tue, Mar 18, 2025 at 09:25:07AM +0100, Ahmad Fatoum wrote:
> The barebox FIT image target is meant as an easy way to load barebox
> second stage from other bootloaders.
> 
> Doing so with U-Boot 2025.01 compiled for qemu_arm64_defconfig
> currently leads to a crash when accessing the PL061 GPIO controller
> device for identification.
> 
> It seems that U-Boot (or TF-A, which wasn't included in my setup)
> should have done some initial setup to allow access to the PL061.
> 
> barebox doesn't even have a driver for the peripheral and loading
> barebox directly with -kernel works. In both cases, barebox runs in EL1.
> 
> Let's thus workaround the issue on the barebox side by using the new
> CONFIG_ARM_AMBA_DABT_MASK option to turn the crash into an error
> message.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  arch/arm/Kconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index f5f9f3828782..7d46dcfb63dc 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -282,6 +282,7 @@ config BOARD_ARM_VIRT
>  	select BOARD_GENERIC_DT
>  	select BOARD_QEMU_VIRT
>  	select OF_OVERLAY
> +	select ARM_AMBA_DABT_MASK

Ah, ok. You select the option where you anticipate that it's useful.
Should have read this patch before commenting on #3.

Fine with me then.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Tue Mar 18 04:07:39 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 12:07:39 +0100
Subject: [PATCH 1/4] scripts/make_fit: factor dtb file name into
 configuration name
In-Reply-To: <20250318082507.419785-1-a.fatoum@pengutronix.de>
References: <20250318082507.419785-1-a.fatoum@pengutronix.de>
Message-ID: <174229605902.3848130.2566513281542426179.b4-ty@pengutronix.de>


On Tue, 18 Mar 2025 09:25:04 +0100, Ahmad Fatoum wrote:
> Bootloaders often support booting a specific FIT configuration by name.
> This is useful when the automatic boot fails, because the bootloader's
> DT compatible differs from the upstream one included with the Linux
> device trees.
> 
> Currently, configuration are numbered sequentially requiring the user to
> dump the FIT image to determine what number the configuration has.
> 
> [...]

Applied, thanks!

[1/4] scripts/make_fit: factor dtb file name into configuration name
      https://git.pengutronix.de/cgit/barebox/commit/?id=852e75a48dc7 (link may not be stable)
[2/4] amba: drop unused hepers for creating AMBA devices outside OF
      https://git.pengutronix.de/cgit/barebox/commit/?id=b12430033d05 (link may not be stable)
[3/4] amba: support masking data abort during identification
      https://git.pengutronix.de/cgit/barebox/commit/?id=c1395964b07f (link may not be stable)
[4/4] ARM: qemu: mask data aborts during AMBA identification
      https://git.pengutronix.de/cgit/barebox/commit/?id=2db7c84a8d0b (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From uwe at kleine-koenig.org  Tue Mar 18 04:16:10 2025
From: uwe at kleine-koenig.org (Uwe =?utf-8?Q?Kleine-K=C3=B6nig?=)
Date: Tue, 18 Mar 2025 12:16:10 +0100
Subject: [PATCH master] partition: fix reference to wrong cdev in warning
 message
In-Reply-To: <20250318082435.419053-1-a.fatoum@pengutronix.de>
References: <20250318082435.419053-1-a.fatoum@pengutronix.de>
Message-ID: <p6sahp32nei5iesre27rbtdbsatui24ce53f3fx6sovbe2mis7@lkei2stdndjo>

On Tue, Mar 18, 2025 at 09:24:35AM +0100, Ahmad Fatoum wrote:
> For MBR and GPT, barebox creates links to the partitions, so they can be
> referenced both by index and partition label.
> 
> Failing to create a link is not an error, but results in a warning
> message. The current message claims that the link was pointing at the
> parent block device's cdev, but it actually was pointing at the child
> partition. Fix that.
> 
> Reported-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  common/partitions.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/partitions.c b/common/partitions.c
> index 7562536cf9b8..bc90f51f6112 100644
> --- a/common/partitions.c
> +++ b/common/partitions.c
> @@ -63,7 +63,7 @@ static int register_one_partition(struct block_device *blk, struct partition *pa
>  	ret = devfs_create_link(cdev, partition_name);
>  	if (ret)
>  		dev_warn(blk->dev, "Failed to create link from %s to %s\n",
> -			 partition_name, blk->cdev.name);
> +			 partition_name, cdev->name);

This improves the error messages on my ts433 from

	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0

to 

	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.2
	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.3
	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.4
	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.5
	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.6

I still don't understand why barebox intends to create mmc0.primary for
all these partitions, but still it's an obviously right improvement.

Acked-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>

Best regards and thanks
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20250318/49e40d68/attachment-0001.sig>

From a.fatoum at pengutronix.de  Tue Mar 18 04:23:19 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Mar 2025 12:23:19 +0100
Subject: [PATCH master] partition: fix reference to wrong cdev in warning
 message
In-Reply-To: <p6sahp32nei5iesre27rbtdbsatui24ce53f3fx6sovbe2mis7@lkei2stdndjo>
References: <20250318082435.419053-1-a.fatoum@pengutronix.de>
 <p6sahp32nei5iesre27rbtdbsatui24ce53f3fx6sovbe2mis7@lkei2stdndjo>
Message-ID: <f66973ec-4516-4dd3-92d3-214fab6c035e@pengutronix.de>

Hello Uwe,

On 3/18/25 12:16, Uwe Kleine-K?nig wrote:
> This improves the error messages on my ts433 from
> 
> 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
> 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
> 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
> 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
> 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
> 
> to 
> 
> 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.2
> 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.3
> 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.4
> 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.5
> 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.6
> 
> I still don't understand why barebox intends to create mmc0.primary for
> all these partitions, but still it's an obviously right improvement.

Thanks for testing. I still suspect that you have multiple on-disk
partitions with the same label. What does lsblk -o name,label,partlabel
say?

Cheers,
Ahmad

> 
> Acked-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
> 
> Best regards and thanks
> Uwe



From a.fatoum at pengutronix.de  Tue Mar 18 04:24:35 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Mar 2025 12:24:35 +0100
Subject: [PATCH 3/4] amba: support masking data abort during
 identification
In-Reply-To: <Z9lTQlVUBnZUPm9q@pengutronix.de>
References: <20250318082507.419785-1-a.fatoum@pengutronix.de>
 <20250318082507.419785-3-a.fatoum@pengutronix.de>
 <Z9lTQlVUBnZUPm9q@pengutronix.de>
Message-ID: <ab47dbb5-bc30-43bc-933c-f078c09196b7@pengutronix.de>

Hello Sascha,

On 3/18/25 12:04, Sascha Hauer wrote:
> On Tue, Mar 18, 2025 at 09:25:06AM +0100, Ahmad Fatoum wrote:
>> Registration of an AMBA device requires reading its pid and cid
>> registers after turning on the device. This is the first I/O done to the
>> device and may end up crashing if the device tree doesn't describe
>> the correct clock and power domains or if a previous boot stage
>> should've enabled them, but didn't.
>>
>> This is not a likely issue, but when it happens it crashes the system
>> annoyingly early during device tree populating.
>>
>> Add a symbol that masks the data abort exception around the
>> identification code to turn the crash into an error message instead.
> 
> Do we need to make this optional? I could imagine I find out about the
> existence of this option only after having traced the issue down to the
> exact lines of code in which case I won't need the option anymore.

If it turns out to be needed for more platforms, we can consider
making it visible by default, but currently I think its of
rather limited use case.

Another way would be disabling the node in the barebox DT,
but I don't want to the Qemu virt DTs to diverge.

Cheers,
Ahmad

> 
> Sascha
> 
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
>> ---
>>  drivers/amba/Kconfig | 19 +++++++++++++++++++
>>  drivers/amba/bus.c   | 12 +++++++++++-
>>  2 files changed, 30 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/amba/Kconfig b/drivers/amba/Kconfig
>> index 444d4ce7435c..be5e053f4b84 100644
>> --- a/drivers/amba/Kconfig
>> +++ b/drivers/amba/Kconfig
>> @@ -1,3 +1,22 @@
>>  # SPDX-License-Identifier: GPL-2.0-only
>>  config ARM_AMBA
>>  	bool
>> +
>> +config ARM_AMBA_DABT_MASK
>> +	bool
>> +	prompt "Mask data abort while identifying AMBA devices" if COMPILE_TEST
>> +	depends on ARM_AMBA && ARCH_HAS_DATA_ABORT_MASK
>> +	help
>> +	  Registration of an AMBA device requires reading its pid and cid
>> +	  registers after turning on the device, which can involve enabling
>> +	  clocks, deasserting resets and powering on power domains.
>> +	  In some cases, these resources are not available to barebox running
>> +	  in the normal world and thus need to be setup by a previous
>> +	  stage bootloader running in the secure world.
>> +	  If such setup doesn't happen, accessing devices may lead to
>> +	  a data abort or complete system hang.
>> +
>> +	  As a workaround for the former case, this option can be enabled
>> +	  to gracefully handle data aborts during readout of the PID/CID
>> +	  registers. The proper solution is fixing your first stage
>> +	  bootloader or allow barebox access to the missing resources.
>> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
>> index 6463366fafc5..5ed8336e6124 100644
>> --- a/drivers/amba/bus.c
>> +++ b/drivers/amba/bus.c
>> @@ -10,6 +10,7 @@
>>  #include <linux/amba/bus.h>
>>  #include <io.h>
>>  #include <init.h>
>> +#include <abort.h>
>>  
>>  #define to_amba_driver(d)	container_of(d, struct amba_driver, drv)
>>  
>> @@ -132,6 +133,9 @@ int amba_device_add(struct amba_device *dev)
>>  	if (ret == 0) {
>>  		u32 pid, cid;
>>  
>> +		if (IS_ENABLED(CONFIG_ARM_AMBA_DABT_MASK))
>> +			data_abort_mask();
>> +
>>  		/*
>>  		 * Read pid and cid based on size of resource
>>  		 * they are located at end of region
>> @@ -139,8 +143,14 @@ int amba_device_add(struct amba_device *dev)
>>  		pid = amba_device_get_pid(tmp, size);
>>  		cid = amba_device_get_cid(tmp, size);
>>  
>> -		if (cid == AMBA_CID)
>> +		if (IS_ENABLED(CONFIG_ARM_AMBA_DABT_MASK) && data_abort_unmask()) {
>> +			dev_err(amba_bustype.dev,
>> +				"data abort during MMIO read of PID/CID for %pOF\n",
>> +				dev->dev.of_node);
>> +			ret = -EFAULT;
>> +		} else if (cid == AMBA_CID) {
>>  			dev->periphid = pid;
>> +		}
>>  
>>  		if (!dev->periphid)
>>  			ret = -ENODEV;
>> -- 
>> 2.39.5
>>
>>
>>
> 



From a.fatoum at pengutronix.de  Tue Mar 18 04:27:26 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Mar 2025 12:27:26 +0100
Subject: [PATCH 1/4] scripts/make_fit: factor dtb file name into
 configuration name
In-Reply-To: <v4s2tw2pg3o7ougore4dvhuzpfqz4lgehiskaopfw5gllpyptb@2fjhiqk36mqo>
References: <20250318082507.419785-1-a.fatoum@pengutronix.de>
 <v4s2tw2pg3o7ougore4dvhuzpfqz4lgehiskaopfw5gllpyptb@2fjhiqk36mqo>
Message-ID: <a3235700-b02b-4870-ba19-b401d6e36600@pengutronix.de>

Hello Uwe,

On 3/18/25 12:03, Uwe Kleine-K?nig wrote:
> On Tue, Mar 18, 2025 at 09:25:04AM +0100, Ahmad Fatoum wrote:
>>      fsw.end_node()
>> -    seq = 0
>>      with fsw.add_node('configurations'):
>> -        for model, compat, files in entries:
>> -            seq += 1
>> -            with fsw.add_node(f'conf-{seq}'):
>> +        for dtbname, model, compat, files in entries:
>> +            with fsw.add_node(f'conf-{dtbname}'):
> 
> Funny/surprising semantic of fsw.add_node (i.e. fsw refers to the new
> node in the with-body?)

Yes. I suspect it's to ensure that a node end tag is inserted
after the properties.

>> -        entries.append([model, compat, files_seq])
>> +        dtbname = os.path.basename(fname)
>> +        ndtbs_seen = len(dtbs_seen)
>> +        dtbs_seen.add(dtbname)
>> +        if len(dtbs_seen) == ndtbs_seen:
>> +            raise RuntimeError(f"Duplicate file name '{dtbname}' during FIT creation")
>> +
>> +        entries.append([dtbname, model, compat, files_seq])
> 
> 	dtbname = os.path.basename(fname)
> 	if dtbname in dtbs_seen:
> 	    raise RuntimeError(...)
> 	dtbs_seen.add(dtbname)
> 	entries.append(...)
> 
> looks more pythonic (to me).

I dislike iterating twice over the dtbs. I wrote it this way,
because I assumed calling len on the set is O(1).

> Acked-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
> 
> for the idea of this patch.

Thanks,
Ahmad

> 
> Best regards
> Uwe



From uwe at kleine-koenig.org  Tue Mar 18 04:31:10 2025
From: uwe at kleine-koenig.org (Uwe =?utf-8?Q?Kleine-K=C3=B6nig?=)
Date: Tue, 18 Mar 2025 12:31:10 +0100
Subject: [PATCH master] partition: fix reference to wrong cdev in warning
 message
In-Reply-To: <f66973ec-4516-4dd3-92d3-214fab6c035e@pengutronix.de>
References: <20250318082435.419053-1-a.fatoum@pengutronix.de>
 <p6sahp32nei5iesre27rbtdbsatui24ce53f3fx6sovbe2mis7@lkei2stdndjo>
 <f66973ec-4516-4dd3-92d3-214fab6c035e@pengutronix.de>
Message-ID: <ulltkotowmwcbpxito2puglexqq3diyjc23mmjp3ylputzy74c@6hsepfjsalpr>

Hello Ahmad,

On Tue, Mar 18, 2025 at 12:23:19PM +0100, Ahmad Fatoum wrote:
> On 3/18/25 12:16, Uwe Kleine-K?nig wrote:
> > This improves the error messages on my ts433 from
> > 
> > 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
> > 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
> > 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
> > 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
> > 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0
> > 
> > to 
> > 
> > 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.2
> > 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.3
> > 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.4
> > 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.5
> > 	WARNING: mmc0: Failed to create link from mmc0.primary to mmc0.6
> > 
> > I still don't understand why barebox intends to create mmc0.primary for
> > all these partitions, but still it's an obviously right improvement.
> 
> Thanks for testing. I still suspect that you have multiple on-disk
> partitions with the same label. What does lsblk -o name,label,partlabel
> say?

indeed:

	# lsblk -o name,label,partlabel /dev/mmcblk0
	NAME        LABEL          PARTLABEL
	mmcblk0
	??mmcblk0p1                uboot
	??mmcblk0p2 QTS_BOOT_PART2 primary
	??mmcblk0p3 QTS_BOOT_PART3 primary
	??mmcblk0p4                primary
	??mmcblk0p5                primary
	??mmcblk0p6                primary
	??mmcblk0p7                primary

Best regards
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20250318/cdce4e7c/attachment.sig>

From s.hauer at pengutronix.de  Tue Mar 18 04:33:05 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 12:33:05 +0100
Subject: [PATCH 4/9] mci: add RPMB support
In-Reply-To: <9c66b31b-a79c-4a07-a03f-119c7c3dadc7@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
 <20250312-rpmb-v1-4-0f213382a3f3@pengutronix.de>
 <9c66b31b-a79c-4a07-a03f-119c7c3dadc7@pengutronix.de>
Message-ID: <Z9lZ8Q4bhUnuur1X@pengutronix.de>

On Mon, Mar 17, 2025 at 04:18:32PM +0100, Ahmad Fatoum wrote:
> Hello Sascha,
> 
> On 3/12/25 13:16, Sascha Hauer wrote:
> > +
> > +int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
> > +			  void *rsp, unsigned long rsplen)
> > +{
> > +	/*
> > +	 * Whoever crafted the data supplied to this function knows how to
> > +	 * format the PRMB frames and which response is expected. If
> > +	 * there's some unexpected mismatch it's more helpful to report an
> > +	 * error immediately than trying to guess what was the intention
> > +	 * and possibly just delay an eventual error which will be harder
> > +	 * to track down.
> > +	 */
> > +	void *rpmb_data = NULL;
> > +	int ret;
> > +
> > +	mci_blk_part_switch(mci->rpmb_part);
> > +
> > +	if (!IS_ALIGNED((uintptr_t)req, ARCH_DMA_MINALIGN)) {
> 
> Even if alignment happens to be correct, there is no guarantee that
> there is no other data sharing a cache line.

reqlen is expected to be a single block of 512 bytes, so indeed when req
is aligned then the end is cacheline aligned as well. We could check
reqlen as well, but I actually never ran into this case, so we can just
return an error for now as you suggested.

Sascha

-- 
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-5555 |


From uwe at kleine-koenig.org  Tue Mar 18 04:33:30 2025
From: uwe at kleine-koenig.org (Uwe =?utf-8?Q?Kleine-K=C3=B6nig?=)
Date: Tue, 18 Mar 2025 12:33:30 +0100
Subject: [PATCH 1/4] scripts/make_fit: factor dtb file name into
 configuration name
In-Reply-To: <a3235700-b02b-4870-ba19-b401d6e36600@pengutronix.de>
References: <20250318082507.419785-1-a.fatoum@pengutronix.de>
 <v4s2tw2pg3o7ougore4dvhuzpfqz4lgehiskaopfw5gllpyptb@2fjhiqk36mqo>
 <a3235700-b02b-4870-ba19-b401d6e36600@pengutronix.de>
Message-ID: <7gm47as3wubmlxwg3o64zh2w4sgi3zwzpog5z6vuxdhctykks4@nrpltcjzdcsk>

Hello,

On Tue, Mar 18, 2025 at 12:27:26PM +0100, Ahmad Fatoum wrote:
> Hello Uwe,
> 
> On 3/18/25 12:03, Uwe Kleine-K?nig wrote:
> > On Tue, Mar 18, 2025 at 09:25:04AM +0100, Ahmad Fatoum wrote:
> >>      fsw.end_node()
> >> -    seq = 0
> >>      with fsw.add_node('configurations'):
> >> -        for model, compat, files in entries:
> >> -            seq += 1
> >> -            with fsw.add_node(f'conf-{seq}'):
> >> +        for dtbname, model, compat, files in entries:
> >> +            with fsw.add_node(f'conf-{dtbname}'):
> > 
> > Funny/surprising semantic of fsw.add_node (i.e. fsw refers to the new
> > node in the with-body?)
> 
> Yes. I suspect it's to ensure that a node end tag is inserted
> after the properties.
> 
> >> -        entries.append([model, compat, files_seq])
> >> +        dtbname = os.path.basename(fname)
> >> +        ndtbs_seen = len(dtbs_seen)
> >> +        dtbs_seen.add(dtbname)
> >> +        if len(dtbs_seen) == ndtbs_seen:
> >> +            raise RuntimeError(f"Duplicate file name '{dtbname}' during FIT creation")
> >> +
> >> +        entries.append([dtbname, model, compat, files_seq])
> > 
> > 	dtbname = os.path.basename(fname)
> > 	if dtbname in dtbs_seen:
> > 	    raise RuntimeError(...)
> > 	dtbs_seen.add(dtbname)
> > 	entries.append(...)
> > 
> > looks more pythonic (to me).
> 
> I dislike iterating twice over the dtbs. I wrote it this way,
> because I assumed calling len on the set is O(1).

I would expect that both `dtbname in dtbs_seen` and
`dtbs_seen.add(dtbname)` is O(1) (in the absense of hash collisions).

Best regards
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20250318/aa22902b/attachment-0001.sig>

From a.fatoum at pengutronix.de  Tue Mar 18 04:42:48 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Mar 2025 12:42:48 +0100
Subject: [PATCH 6/9] tee: optee: implement shared mem alloc/free RPC
 commands
In-Reply-To: <20250312-rpmb-v1-6-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
 <20250312-rpmb-v1-6-0f213382a3f3@pengutronix.de>
Message-ID: <ec54f22b-3751-4891-948a-b9a79272acdd@pengutronix.de>

Hello Sascha,

On 3/12/25 13:16, Sascha Hauer wrote:
>  void optee_rpc_cmd(struct tee_context *ctx, struct optee *optee,
>  		   struct optee_msg_arg *arg)
>  {
> -	pr_notice_once("optee: No supplicant or RPC handler for command 0x%x\n", arg->cmd);
> -	arg->ret = TEEC_ERROR_NOT_SUPPORTED;
> +	pr_debug("%s: receive RPC CMD: %d\n", __func__, arg->cmd);
> +
> +	switch (arg->cmd) {
> +	case OPTEE_RPC_CMD_SHM_ALLOC:
> +		cmd_shm_alloc(ctx, arg);
> +		break;
> +	case OPTEE_RPC_CMD_SHM_FREE:
> +		cmd_shm_free(arg);
> +		break;
> +	default:
> +		arg->ret = TEEC_ERROR_NOT_IMPLEMENTED;

Please move the pr_notice_once here, so barebox users know that
OP-TEE tried to do something not supported yet.

Thanks,
Ahmad

> +	}
> +
> +	arg->ret_origin = TEEC_ORIGIN_COMMS;




From eagle.alexander923 at gmail.com  Tue Mar 18 04:49:12 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Tue, 18 Mar 2025 14:49:12 +0300
Subject: [PATCH 4/5] ARM: at91: sama5: Unify xx_start_image() calls
In-Reply-To: <Z9lRH065pPDbir9z@pengutronix.de>
References: <20250318074327.37730-1-eagle.alexander923@gmail.com>
 <20250318074327.37730-4-eagle.alexander923@gmail.com> <Z9lRH065pPDbir9z@pengutronix.de>
Message-ID: <CAP1tNvSRjG21_EPcS0Hi_Sd3FzfQZVOy8CSaMSpp4nxgLKVnwQ@mail.gmail.com>

Hello.

Ok. Can You apply the first patches to reduce the v2 series?
I also want to add another one to rename the sama5d2-related output
images to reflect that one image can now be used to boot from
both MMC and QSPI.

Thanks!

> On Tue, Mar 18, 2025 at 10:43:26AM +0300, Alexander Shiyan wrote:
> > This unifies the xload.c start_image() code for both sama5d2() and
> > sama5d3() CPU variants.
...
> Original code has struct sdhci_instance and struct atmci_instance which
> both have the same members. You unify this to struct xload_instance
> which is a good step. I think this should be a separate patch along with
> the rename from sdhci_instance[] to sama5d2_mci_instances[] and
> sama5d3_atmci_instances[] to sama5d3_mci_instances[].
>
> This will help to better see what the rest of this patch is about.


From s.hauer at pengutronix.de  Tue Mar 18 07:41:41 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 15:41:41 +0100
Subject: [PATCH 0/7] filetype: Some size reduction patches
Message-ID: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>

The am335x_mlo_defconfig is very size constrained and doesn't build
within these constraint anymore for some time. The filetype detection
code has become quite big and offers some opportunities for size
reduction. Specifically file_detect_type() is quite big, but many
callers are only interested in some specific file types like supported
file systems or supported compressed binary formats. This series
introduces some more specific smaller file detection functions so that
we can get rid of the big file_detect_type() in the binary.

Also included some patches for the myirtech-mid board to use a stripped
down device tree for the MLO. The same is already done for the other
boards supported in am335x_mlo_defconfig

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
Sascha Hauer (7):
      filetype: add file_detect_compression_type()
      filetype: add file_detect_fs_type()
      filetype: add function pointer to file_name_detect_type_offset()
      filetype: let cdev_detect_type() only detect filesystems
      filetype: make file type strings optional
      ARM: am33xx: myirtech-myd: add MLO specific device tree
      ARM: am335x_mlo_defconfig: disable file type strings

 arch/arm/boards/myirtech-x335x/lowlevel.c |   6 +-
 arch/arm/configs/am335x_mlo_defconfig     |   1 +
 arch/arm/dts/Makefile                     |   2 +-
 arch/arm/dts/am335x-myirtech-myd-mlo.dts  |  10 +++
 common/Kconfig                            |   8 ++
 common/filetype.c                         | 132 +++++++++++++++++++++---------
 fs/fs.c                                   |   3 +-
 include/filetype.h                        |   5 +-
 lib/uncompress.c                          |   4 +-
 9 files changed, 125 insertions(+), 46 deletions(-)
---
base-commit: a0ba27e06535570e8e4653f5f92a607f8b99022e
change-id: 20250318-filetype-size-reduction-0cbf74281e2e

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar 18 07:41:48 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 15:41:48 +0100
Subject: [PATCH 7/7] ARM: am335x_mlo_defconfig: disable file type strings
In-Reply-To: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
Message-ID: <20250318-filetype-size-reduction-v1-7-4f463ffae7d0@pengutronix.de>

The am335x_mlo_defconfig is very size constrained. Remove support for
printing file types as strings to reduce the binary size a bit.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/am335x_mlo_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/am335x_mlo_defconfig b/arch/arm/configs/am335x_mlo_defconfig
index 91d0eb4a8d..4a9ce6cfb7 100644
--- a/arch/arm/configs/am335x_mlo_defconfig
+++ b/arch/arm/configs/am335x_mlo_defconfig
@@ -19,6 +19,7 @@ CONFIG_SHELL_NONE=y
 # CONFIG_TIMESTAMP is not set
 CONFIG_CONSOLE_ACTIVATE_NONE=y
 CONFIG_OFDEVICE=y
+# CONFIG_FILETYPE_STRING is not set
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SPI_OMAP3=y
 CONFIG_MTD=y

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 18 07:41:43 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 15:41:43 +0100
Subject: [PATCH 2/7] filetype: add file_detect_fs_type()
In-Reply-To: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
Message-ID: <20250318-filetype-size-reduction-v1-2-4f463ffae7d0@pengutronix.de>

add file_detect_fs_type() which only tests if the buffer contains one of
the supported filesystems without testing for other binary formats.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/filetype.c  | 59 ++++++++++++++++++++++++++++++++++++------------------
 include/filetype.h |  1 +
 2 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index 9916b63b80..2a55d5f4ea 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -198,29 +198,39 @@ int is_fat_boot_sector(const void *sect)
 	return 0;
 }
 
-enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec)
+static enum filetype file_detect_fs_fat(const void *_buf, size_t bufsize)
 {
-	/*
-	 * bootsec can be used to return index of the first sector in the
-	 * first partition
-	 */
-	if (bootsec)
-		*bootsec = 0;
+	const u8 *buf8 = _buf;
 
 	/*
 	 * Check record signature (always placed at offset 510 even if the
 	 * sector size is > 512)
 	 */
-	if (get_unaligned_le16(&sector[BS_55AA]) != 0xAA55)
+	if (get_unaligned_le16(&buf8[BS_55AA]) != 0xAA55)
 		return filetype_unknown;
 
 	/* Check "FAT" string */
-	if ((get_unaligned_le32(&sector[BS_FilSysType]) & 0xFFFFFF) == 0x544146)
+	if ((get_unaligned_le32(&buf8[BS_FilSysType]) & 0xFFFFFF) == 0x544146)
 		return filetype_fat;
 
-	if ((get_unaligned_le32(&sector[BS_FilSysType32]) & 0xFFFFFF) == 0x544146)
+	if ((get_unaligned_le32(&buf8[BS_FilSysType32]) & 0xFFFFFF) == 0x544146)
 		return filetype_fat;
 
+	return filetype_unknown;
+}
+
+enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec)
+{
+	/*
+	 * bootsec can be used to return index of the first sector in the
+	 * first partition
+	 */
+	if (bootsec)
+		*bootsec = 0;
+
+	if (file_detect_fs_fat(sector, 512) != filetype_fat)
+		return filetype_unknown;
+
 	if (bootsec)
 		/*
 		 * This must be an MBR, so return the starting sector of the
@@ -289,12 +299,31 @@ enum filetype file_detect_compression_type(const void *_buf, size_t bufsize)
 	return filetype_unknown;
 }
 
+enum filetype file_detect_fs_type(const void *_buf, size_t bufsize)
+{
+	const u32 *buf = _buf;
+	const u16 *buf16 = _buf;
+	const u8 *buf8 = _buf;
+
+	if (bufsize < 16)
+		return filetype_unknown;
+
+	if (buf8[0] == 'h' && buf8[1] == 's' && buf8[2] == 'q' &&
+			buf8[3] == 's')
+		return filetype_squashfs;
+	if (bufsize >= 1536 && buf16[512 + 28] == le16_to_cpu(0xef53))
+		return filetype_ext;
+	if (buf[0] == le32_to_cpu(0x06101831))
+		return filetype_ubifs;
+
+	return file_detect_fs_fat(_buf, bufsize);
+}
+
 enum filetype file_detect_type(const void *_buf, size_t bufsize)
 {
 	const u32 *buf = _buf;
 	const u64 *buf64 = _buf;
 	const u8 *buf8 = _buf;
-	const u16 *buf16 = _buf;
 	const struct imx_flash_header *imx_flash_header = _buf;
 	enum filetype type;
 
@@ -319,13 +348,8 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 		return filetype_uimage;
 	if (buf[0] == 0x23494255)
 		return filetype_ubi;
-	if (buf[0] == le32_to_cpu(0x06101831))
-		return filetype_ubifs;
 	if (buf[0] == 0x20031985)
 		return filetype_jffs2;
-	if (buf8[0] == 'h' && buf8[1] == 's' && buf8[2] == 'q' &&
-			buf8[3] == 's')
-		return filetype_squashfs;
 	if (buf[0] == be32_to_cpu(0xd00dfeed))
 		return filetype_oftree;
 	if (strncmp(buf8, "ANDROID!", 8) == 0)
@@ -423,9 +447,6 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (type != filetype_unknown)
 		return type;
 
-	if (bufsize >= 1536 && buf16[512 + 28] == le16_to_cpu(0xef53))
-		return filetype_ext;
-
 	if (strncmp(buf8 + CH_TOC_section_name, "CHSETTINGS", 10) == 0)
 		return filetype_ch_image;
 
diff --git a/include/filetype.h b/include/filetype.h
index b8c0105bf2..329ebc9e8b 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -75,6 +75,7 @@ const char *file_type_to_string(enum filetype f);
 const char *file_type_to_short_string(enum filetype f);
 enum filetype file_detect_partition_table(const void *_buf, size_t bufsize);
 enum filetype file_detect_compression_type(const void *_buf, size_t bufsize);
+enum filetype file_detect_fs_type(const void *_buf, size_t bufsize);
 enum filetype file_detect_type(const void *_buf, size_t bufsize);
 int file_name_detect_type(const char *filename, enum filetype *type);
 int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type);

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 18 07:41:45 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 15:41:45 +0100
Subject: [PATCH 4/7] filetype: let cdev_detect_type() only detect
 filesystems
In-Reply-To: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
Message-ID: <20250318-filetype-size-reduction-v1-4-4f463ffae7d0@pengutronix.de>

cdev_detect_type() is only used by the fs code to determine the
filesystem type on a cdev, so it only needs to be able to detect
filesystems and no other types. Call file_detect_fs_type() instead
for smaller binary size.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/filetype.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/filetype.c b/common/filetype.c
index 1e2d4ed0e3..b8d65dfb9f 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -523,7 +523,7 @@ int cdev_detect_type(struct cdev *cdev, enum filetype *type)
 	if (ret < 0)
 		goto err_out;
 
-	*type = file_detect_type(buf, ret);
+	*type = file_detect_fs_type(buf, ret);
 	ret = 0;
 
 err_out:

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 18 07:41:47 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 15:41:47 +0100
Subject: [PATCH 6/7] ARM: am33xx: myirtech-myd: add MLO specific device
 tree
In-Reply-To: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
Message-ID: <20250318-filetype-size-reduction-v1-6-4f463ffae7d0@pengutronix.de>

Use a stripped down device tree for the MLO to decrease the binary size.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/myirtech-x335x/lowlevel.c |  6 ++++--
 arch/arm/dts/Makefile                     |  2 +-
 arch/arm/dts/am335x-myirtech-myd-mlo.dts  | 10 ++++++++++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boards/myirtech-x335x/lowlevel.c b/arch/arm/boards/myirtech-x335x/lowlevel.c
index c7b36b0173..05c858ad86 100644
--- a/arch/arm/boards/myirtech-x335x/lowlevel.c
+++ b/arch/arm/boards/myirtech-x335x/lowlevel.c
@@ -54,7 +54,7 @@ static struct am33xx_emif_regs ddr3_regs = {
 	.sdram_ref_ctrl		= 0xc30,
 };
 
-extern char __dtb_z_am335x_myirtech_myd_start[];
+extern char __dtb_z_am335x_myirtech_myd_mlo_start[];
 
 ENTRY_FUNCTION(start_am33xx_myirtech_sram, bootinfo, r1, r2)
 {
@@ -68,7 +68,7 @@ ENTRY_FUNCTION(start_am33xx_myirtech_sram, bootinfo, r1, r2)
 	relocate_to_current_adr();
 	setup_c();
 
-	fdt = __dtb_z_am335x_myirtech_myd_start;
+	fdt = __dtb_z_am335x_myirtech_myd_mlo_start;
 
 	omap_watchdog_disable(IOMEM(AM33XX_WDT_BASE));
 
@@ -99,6 +99,8 @@ ENTRY_FUNCTION(start_am33xx_myirtech_sram, bootinfo, r1, r2)
 	am335x_barebox_entry(fdt);
 }
 
+extern char __dtb_z_am335x_myirtech_myd_start[];
+
 ENTRY_FUNCTION(start_am33xx_myirtech_sdram, r0, r1, r2)
 {
 	void *fdt;
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index d346285852..2d90738748 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -44,7 +44,7 @@ lwl-$(CONFIG_MACH_LENOVO_IX4_300D) += armada-xp-lenovo-ix4-300d-bb.dtb.o
 lwl-$(CONFIG_MACH_MARVELL_ARMADA_XP_GP) += armada-xp-gp-bb.dtb.o
 lwl-$(CONFIG_MACH_MARVELL_ARMADA_XP_DB) += armada-xp-db-bb.dtb.o
 lwl-$(CONFIG_MACH_MX28EVK) += imx28-evk.dtb.o
-lwl-$(CONFIG_MACH_MYIRTECH_X335X) += am335x-myirtech-myd.dtb.o
+lwl-$(CONFIG_MACH_MYIRTECH_X335X) += am335x-myirtech-myd.dtb.o am335x-myirtech-myd-mlo.dtb.o
 lwl-$(CONFIG_MACH_NETGEAR_RN104) += armada-370-rn104-bb.dtb.o
 lwl-$(CONFIG_MACH_NETGEAR_RN2120) += armada-xp-rn2120-bb.dtb.o
 lwl-$(CONFIG_MACH_NITROGEN6) += imx6q-nitrogen6x.dtb.o imx6dl-nitrogen6x.dtb.o imx6qp-nitrogen6_max.dtb.o
diff --git a/arch/arm/dts/am335x-myirtech-myd-mlo.dts b/arch/arm/dts/am335x-myirtech-myd-mlo.dts
new file mode 100644
index 0000000000..20c3298073
--- /dev/null
+++ b/arch/arm/dts/am335x-myirtech-myd-mlo.dts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* SPDX-FileCopyrightText: Alexander Shiyan, <shc_work at mail.ru> */
+
+/dts-v1/;
+
+#include "am335x-myirtech-myd.dts"
+#include "am33xx-strip.dtsi"
+#include "am33xx-clocks-strip.dtsi"
+
+/delete-node/ &{/sound};

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 18 07:41:46 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 15:41:46 +0100
Subject: [PATCH 5/7] filetype: make file type strings optional
In-Reply-To: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
Message-ID: <20250318-filetype-size-reduction-v1-5-4f463ffae7d0@pengutronix.de>

This adds a new Kconfig option FILETYPE_STRING which makes
printing file types as strings optional. The filetype_str[]
array has become quite big and with this we can get rid of
it in size constraint barebox images. Make it default y to
keep the existing default.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/Kconfig    |  8 ++++++++
 common/filetype.c | 15 +++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/common/Kconfig b/common/Kconfig
index 12026b8232..c57669bb61 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1332,6 +1332,14 @@ config PBL_OPTEE
 	  Allows starting OP-TEE during lowlevel initialization of the PBL.
 	  Requires explicit support in the board's lowlevel file.
 
+config FILETYPE_STRING
+	bool "Print file types as strings"
+	default y
+	depends on FILETYPE
+	help
+	  Say yes here to include strings for filetypes in barebox. If disabled file
+	  types will be printed as numbers only.
+
 endmenu
 
 if FASTBOOT_BASE
diff --git a/common/filetype.c b/common/filetype.c
index b8d65dfb9f..ce868223d5 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -85,8 +85,20 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_zstd_compressed] = { "ZSTD compressed", "zstd" },
 };
 
+static const char *file_type_to_nr_string(enum filetype f)
+{
+	static char str[sizeof("4294967295")];
+
+	sprintf(str, "%u", (unsigned int)f);
+
+	return str;
+}
+
 const char *file_type_to_string(enum filetype f)
 {
+	if (!IS_ENABLED(CONFIG_FILETYPE_STRINGS))
+		return file_type_to_nr_string(f);
+
 	if (f < ARRAY_SIZE(filetype_str))
 		return filetype_str[f].name;
 
@@ -95,6 +107,9 @@ const char *file_type_to_string(enum filetype f)
 
 const char *file_type_to_short_string(enum filetype f)
 {
+	if (!IS_ENABLED(CONFIG_FILETYPE_STRINGS))
+		return file_type_to_nr_string(f);
+
 	if (f < ARRAY_SIZE(filetype_str))
 		return filetype_str[f].shortname;
 

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 18 07:41:42 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 15:41:42 +0100
Subject: [PATCH 1/7] filetype: add file_detect_compression_type()
In-Reply-To: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
Message-ID: <20250318-filetype-size-reduction-v1-1-4f463ffae7d0@pengutronix.de>

Add file_detect_compression_type() and use that in the uncompression
code which is only interested if the file is one of the supported
compression formats.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/filetype.c  | 48 ++++++++++++++++++++++++++++++++----------------
 include/filetype.h |  1 +
 lib/uncompress.c   |  4 ++--
 3 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index 73ea17e19b..9916b63b80 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -261,6 +261,34 @@ static bool is_dos_exe(const u8 *buf8)
 
 #define CH_TOC_section_name     0x14
 
+enum filetype file_detect_compression_type(const void *_buf, size_t bufsize)
+{
+	const u32 *buf = _buf;
+	const u8 *buf8 = _buf;
+
+	if (bufsize < 16)
+		return filetype_unknown;
+
+	if (buf8[0] == 0x89 && buf8[1] == 0x4c && buf8[2] == 0x5a &&
+			buf8[3] == 0x4f)
+		return filetype_lzo_compressed;
+	if (buf8[0] == 0x02 && buf8[1] == 0x21 && buf8[2] == 0x4c &&
+			buf8[3] == 0x18)
+		return filetype_lz4_compressed;
+	if (buf8[0] == 0x1f && buf8[1] == 0x8b && buf8[2] == 0x08)
+		return filetype_gzip;
+	if (buf8[0] == 'B' && buf8[1] == 'Z' && buf8[2] == 'h' &&
+			buf8[3] > '0' && buf8[3] <= '9')
+                return filetype_bzip2;
+	if (buf8[0] == 0xfd && buf8[1] == 0x37 && buf8[2] == 0x7a &&
+			buf8[3] == 0x58 && buf8[4] == 0x5a && buf8[5] == 0x00)
+		return filetype_xz_compressed;
+	if (le32_to_cpu(buf[0]) == le32_to_cpu(ZSTD_MAGICNUMBER))
+		return filetype_zstd_compressed;
+
+	return filetype_unknown;
+}
+
 enum filetype file_detect_type(const void *_buf, size_t bufsize)
 {
 	const u32 *buf = _buf;
@@ -278,17 +306,15 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (buf[0] == ENVFS_32(ENVFS_MAGIC))
 		return filetype_barebox_env;
 
+	type = file_detect_compression_type(_buf, bufsize);
+	if (type != filetype_unknown)
+		return type;
+
 	if (bufsize < 32)
 		return filetype_unknown;
 
 	if (strncmp(buf8, "BM", 2) == 0)
 		return filetype_bmp;
-	if (buf8[0] == 0x89 && buf8[1] == 0x4c && buf8[2] == 0x5a &&
-			buf8[3] == 0x4f)
-		return filetype_lzo_compressed;
-	if (buf8[0] == 0x02 && buf8[1] == 0x21 && buf8[2] == 0x4c &&
-			buf8[3] == 0x18)
-		return filetype_lz4_compressed;
 	if (buf[0] == be32_to_cpu(0x27051956))
 		return filetype_uimage;
 	if (buf[0] == 0x23494255)
@@ -297,14 +323,6 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 		return filetype_ubifs;
 	if (buf[0] == 0x20031985)
 		return filetype_jffs2;
-	if (buf8[0] == 0x1f && buf8[1] == 0x8b && buf8[2] == 0x08)
-		return filetype_gzip;
-	if (buf8[0] == 'B' && buf8[1] == 'Z' && buf8[2] == 'h' &&
-			buf8[3] > '0' && buf8[3] <= '9')
-                return filetype_bzip2;
-	if (buf8[0] == 0xfd && buf8[1] == 0x37 && buf8[2] == 0x7a &&
-			buf8[3] == 0x58 && buf8[4] == 0x5a && buf8[5] == 0x00)
-		return filetype_xz_compressed;
 	if (buf8[0] == 'h' && buf8[1] == 's' && buf8[2] == 'q' &&
 			buf8[3] == 's')
 		return filetype_squashfs;
@@ -325,8 +343,6 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 		return filetype_rockchip_rkns_image;
 	if (le32_to_cpu(buf[0]) == le32_to_cpu(0xaa640001))
 		return filetype_fip;
-	if (le32_to_cpu(buf[0]) == le32_to_cpu(ZSTD_MAGICNUMBER))
-		return filetype_zstd_compressed;
 
 	if ((buf8[0] == 0x5a || buf8[0] == 0x69 || buf8[0] == 0x78 ||
 	     buf8[0] == 0x8b || buf8[0] == 0x9c) &&
diff --git a/include/filetype.h b/include/filetype.h
index c24d061e8f..b8c0105bf2 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -74,6 +74,7 @@ struct cdev;
 const char *file_type_to_string(enum filetype f);
 const char *file_type_to_short_string(enum filetype f);
 enum filetype file_detect_partition_table(const void *_buf, size_t bufsize);
+enum filetype file_detect_compression_type(const void *_buf, size_t bufsize);
 enum filetype file_detect_type(const void *_buf, size_t bufsize);
 int file_name_detect_type(const char *filename, enum filetype *type);
 int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type);
diff --git a/lib/uncompress.c b/lib/uncompress.c
index 0aaeb066b6..c284bcc6ba 100644
--- a/lib/uncompress.c
+++ b/lib/uncompress.c
@@ -79,7 +79,7 @@ int uncompress(unsigned char *inbuf, long len,
 	char *err;
 
 	if (inbuf) {
-		ft = file_detect_type(inbuf, len);
+		ft = file_detect_compression_type(inbuf, len);
 		uncompress_buf = NULL;
 		uncompress_size = 0;
 	} else {
@@ -94,7 +94,7 @@ int uncompress(unsigned char *inbuf, long len,
 		if (ret < 0)
 			goto err;
 
-		ft = file_detect_type(uncompress_buf, 32);
+		ft = file_detect_compression_type(uncompress_buf, 32);
 	}
 
 	pr_debug("Filetype detected: %s\n", file_type_to_string(ft));

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 18 07:41:44 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 15:41:44 +0100
Subject: [PATCH 3/7] filetype: add function pointer to
 file_name_detect_type_offset()
In-Reply-To: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
Message-ID: <20250318-filetype-size-reduction-v1-3-4f463ffae7d0@pengutronix.de>

file_name_detect_type_offset() calls file_detect_type() which is quite
a big function. Add a function pointer argument so the caller can
decide which file detection function shall be called. This allows
callers to depend on a function with a smaller binary size impact.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/filetype.c  | 8 +++++---
 fs/fs.c            | 3 ++-
 include/filetype.h | 3 ++-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index 2a55d5f4ea..1e2d4ed0e3 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -476,7 +476,8 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	return filetype_unknown;
 }
 
-int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type)
+int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type,
+				 enum filetype (*detect)(const void *buf, size_t bufsize))
 {
 	int fd, ret;
 	void *buf;
@@ -491,7 +492,7 @@ int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype
 	if (ret < 0)
 		goto err_out;
 
-	*type = file_detect_type(buf, ret);
+	*type = detect(buf, ret);
 
 	ret = 0;
 err_out:
@@ -503,7 +504,8 @@ int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype
 
 int file_name_detect_type(const char *filename, enum filetype *type)
 {
-	return file_name_detect_type_offset(filename, 0, type);
+	return file_name_detect_type_offset(filename, 0, type,
+					    file_detect_type);
 }
 
 int cdev_detect_type(struct cdev *cdev, enum filetype *type)
diff --git a/fs/fs.c b/fs/fs.c
index 96ca60341e..9924709424 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -903,7 +903,8 @@ const char *fs_detect(const char *filename, const char *fsoptions)
 	parseopt_llu_suffix(fsoptions, "offset", &offset);
 
 	if (loop) {
-		ret = file_name_detect_type_offset(filename, offset, &type);
+		ret = file_name_detect_type_offset(filename, offset, &type,
+						   file_detect_fs_type);
 	} else {
 		struct cdev *cdev = cdev_open_by_name(filename, O_RDONLY);
 		if (cdev) {
diff --git a/include/filetype.h b/include/filetype.h
index 329ebc9e8b..03d1f1595d 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -78,7 +78,8 @@ enum filetype file_detect_compression_type(const void *_buf, size_t bufsize);
 enum filetype file_detect_fs_type(const void *_buf, size_t bufsize);
 enum filetype file_detect_type(const void *_buf, size_t bufsize);
 int file_name_detect_type(const char *filename, enum filetype *type);
-int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type);
+int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype *type,
+				 enum filetype (*detect)(const void *buf, size_t bufsize));
 int cdev_detect_type(struct cdev *cdev, enum filetype *type);
 enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec);
 int is_fat_boot_sector(const void *_buf);

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 18 07:49:25 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 15:49:25 +0100
Subject: (subset) [PATCH 1/5] ARM: at91: Add PBL_BREAK support
In-Reply-To: <20250318074327.37730-1-eagle.alexander923@gmail.com>
References: <20250318074327.37730-1-eagle.alexander923@gmail.com>
Message-ID: <174230936500.3750975.4594139840692961507.b4-ty@pengutronix.de>


On Tue, 18 Mar 2025 10:43:23 +0300, Alexander Shiyan wrote:
> This adds PBL_BREAK support to the barebox at91 header.
> Since we're here, let's set the header parameters to the defaults
> for the barebox and do some code formatting to improve readability.
> 
> 

Applied, thanks!

[1/5] ARM: at91: Add PBL_BREAK support
      https://git.pengutronix.de/cgit/barebox/commit/?id=3644b3362686 (link may not be stable)
[2/5] ARM: at91: Merge sama5_boot_xload() asm code
      https://git.pengutronix.de/cgit/barebox/commit/?id=1d0cc726f94c (link may not be stable)
[3/5] ARM: at91: Rename xload-mmc.c
      https://git.pengutronix.de/cgit/barebox/commit/?id=5c59dd719417 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From a.fatoum at pengutronix.de  Tue Mar 18 07:51:44 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Mar 2025 15:51:44 +0100
Subject: [PATCH 2/7] filetype: add file_detect_fs_type()
In-Reply-To: <20250318-filetype-size-reduction-v1-2-4f463ffae7d0@pengutronix.de>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
 <20250318-filetype-size-reduction-v1-2-4f463ffae7d0@pengutronix.de>
Message-ID: <f7975f67-d659-48c3-bf1b-498331fc5401@pengutronix.de>

Hi,

On 3/18/25 15:41, Sascha Hauer wrote:
> add file_detect_fs_type() which only tests if the buffer contains one of
> the supported filesystems without testing for other binary formats.


> +enum filetype file_detect_fs_type(const void *_buf, size_t bufsize)

[snip]

>  enum filetype file_detect_type(const void *_buf, size_t bufsize)
> -	if (bufsize >= 1536 && buf16[512 + 28] == le16_to_cpu(0xef53))
> -		return filetype_ext;
> -
>  	if (strncmp(buf8 + CH_TOC_section_name, "CHSETTINGS", 10) == 0)
>  		return filetype_ch_image

Shouldn't file_detec_type() still call file_detect_fs_type()?

Thanks,
Ahmad


From eagle.alexander923 at gmail.com  Tue Mar 18 08:01:19 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Tue, 18 Mar 2025 18:01:19 +0300
Subject: [PATCH 0/7] filetype: Some size reduction patches
In-Reply-To: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
Message-ID: <CAP1tNvQokH9TTSANKNADzo5Nie2SzjAyM08ix0D8gbL6TPxBuw@mail.gmail.com>

Hello Sascha!

I've been using a separate config for this board for a long time :)
Maybe you can take something from my working configuration that
has been working for several years:
https://github.com/shcgit/barebox/blob/milas/arch/arm/configs/mm_am335x_mlo_defconfig

Thanks!

??, 18 ???. 2025??. ? 17:46, Sascha Hauer <s.hauer at pengutronix.de>:
>
> The am335x_mlo_defconfig is very size constrained and doesn't build
> within these constraint anymore for some time. The filetype detection
> code has become quite big and offers some opportunities for size
> reduction. Specifically file_detect_type() is quite big, but many
> callers are only interested in some specific file types like supported
> file systems or supported compressed binary formats. This series
> introduces some more specific smaller file detection functions so that
> we can get rid of the big file_detect_type() in the binary.
>
> Also included some patches for the myirtech-mid board to use a stripped
> down device tree for the MLO. The same is already done for the other
> boards supported in am335x_mlo_defconfig
>
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
> Sascha Hauer (7):
>       filetype: add file_detect_compression_type()
>       filetype: add file_detect_fs_type()
>       filetype: add function pointer to file_name_detect_type_offset()
>       filetype: let cdev_detect_type() only detect filesystems
>       filetype: make file type strings optional
>       ARM: am33xx: myirtech-myd: add MLO specific device tree
>       ARM: am335x_mlo_defconfig: disable file type strings
>
>  arch/arm/boards/myirtech-x335x/lowlevel.c |   6 +-
>  arch/arm/configs/am335x_mlo_defconfig     |   1 +
>  arch/arm/dts/Makefile                     |   2 +-
>  arch/arm/dts/am335x-myirtech-myd-mlo.dts  |  10 +++
>  common/Kconfig                            |   8 ++
>  common/filetype.c                         | 132 +++++++++++++++++++++---------
>  fs/fs.c                                   |   3 +-
>  include/filetype.h                        |   5 +-
>  lib/uncompress.c                          |   4 +-
>  9 files changed, 125 insertions(+), 46 deletions(-)
> ---
> base-commit: a0ba27e06535570e8e4653f5f92a607f8b99022e
> change-id: 20250318-filetype-size-reduction-0cbf74281e2e
>
> Best regards,
> --
> Sascha Hauer <s.hauer at pengutronix.de>
>
>


From s.hauer at pengutronix.de  Tue Mar 18 08:06:47 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Mar 2025 16:06:47 +0100
Subject: [PATCH 2/7] filetype: add file_detect_fs_type()
In-Reply-To: <f7975f67-d659-48c3-bf1b-498331fc5401@pengutronix.de>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
 <20250318-filetype-size-reduction-v1-2-4f463ffae7d0@pengutronix.de>
 <f7975f67-d659-48c3-bf1b-498331fc5401@pengutronix.de>
Message-ID: <Z9mMB8_1LV_YmcxN@pengutronix.de>

On Tue, Mar 18, 2025 at 03:51:44PM +0100, Ahmad Fatoum wrote:
> Hi,
> 
> On 3/18/25 15:41, Sascha Hauer wrote:
> > add file_detect_fs_type() which only tests if the buffer contains one of
> > the supported filesystems without testing for other binary formats.
> 
> 
> > +enum filetype file_detect_fs_type(const void *_buf, size_t bufsize)
> 
> [snip]
> 
> >  enum filetype file_detect_type(const void *_buf, size_t bufsize)
> > -	if (bufsize >= 1536 && buf16[512 + 28] == le16_to_cpu(0xef53))
> > -		return filetype_ext;
> > -
> >  	if (strncmp(buf8 + CH_TOC_section_name, "CHSETTINGS", 10) == 0)
> >  		return filetype_ch_image
> 
> Shouldn't file_detec_type() still call file_detect_fs_type()?

Sure, that was the intention at least.

Thanks for catching, fixed this.

Sascha

-- 
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-5555 |


From jonas.licht at gmail.com  Tue Mar 18 09:32:51 2025
From: jonas.licht at gmail.com (Jonas Licht)
Date: Tue, 18 Mar 2025 17:32:51 +0100
Subject: [PATCH v2] environment: support reading and writing of efivar
In-Reply-To: <20250311141713.30947-1-jonas.licht@gmail.com>
References: <20250311141713.30947-1-jonas.licht@gmail.com>
Message-ID: <20250318163251.352-1-jonas.licht@gmail.com>

scripts/bareboxenv: skip file creation to allow reading the destination
file, when existing.

In envfs_load before reading the superblock, we check if our superblock
magic exists after an EFIVAR_ATTR_SIZE offset. This is necessary because
linux kernel adds four byte variable attributes in front of each efi
variable in sysfs. When the magic is found after EFIVAR_ATTR_SIZE, we
skip reading the four bytes variable attributes.
For envfs_save detection of an efi var is done the same way. But we need
to keep the attributes, as they are required for writing as well.

In order to write to efivars, you still need to remove immutable flag
from the file with 'chattr -i' .

Signed-off-by: Jonas Licht <jonas.licht at gmail.com>
Fixes: #29
Link: https://github.com/barebox/barebox/issues/29
---
 common/environment.c | 80 ++++++++++++++++++++++++++++++++++++++++----
 scripts/Makefile     |  2 ++
 scripts/bareboxenv.c | 11 +-----
 3 files changed, 76 insertions(+), 17 deletions(-)

diff --git a/common/environment.c b/common/environment.c
index 37adb5d678..b91c3e0afa 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -32,8 +32,11 @@
 #include <magicvar.h>
 #else
 #define EXPORT_SYMBOL(x)
+#include <autoconf.h>
 #endif
 
+#define EFIVAR_ATTR_SIZE 4
+
 struct envfs_entry {
 	char *name;
 	void *buf;
@@ -290,6 +293,41 @@ static int file_remove_action(const char *filename, struct stat *statbuf,
 }
 #endif
 
+static int detect_efi_vars(int fd, void* buf_with_efi, void** wbuf, int *size) {
+	uint32_t magic;
+	int ret;
+
+	*wbuf = buf_with_efi + EFIVAR_ATTR_SIZE;
+#ifndef CONFIG_EFI
+		return 0;
+#endif
+
+	ret = pread(fd, &magic, sizeof(uint32_t),
+		EFIVAR_ATTR_SIZE);
+	if (ret == -1 && errno == ENOENT) {
+		perror("pread");
+		// skip as file don't exist
+		return 0;
+	}
+	if (ret < sizeof(u_int32_t)) {
+		perror("pread");
+		return 0;
+	}
+
+	if (ENVFS_32(magic) == ENVFS_MAGIC) {
+		pr_info("Assuming EFI variable. Keeping attributes\n");
+		ret = pread(fd, buf_with_efi, EFIVAR_ATTR_SIZE, 0);
+		if (ret < EFIVAR_ATTR_SIZE) {
+			ret = -errno;
+			perror("read of efi attributes failed");
+			return ret;
+		}
+		*size += EFIVAR_ATTR_SIZE;
+		*wbuf = buf_with_efi;
+	}
+	return 0;
+}
+
 /**
  * Make the current environment persistent
  * @param[in] filename where to store
@@ -305,7 +343,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 	struct envfs_super *super;
 	int envfd, size, ret;
 	struct action_data data = {};
-	void *buf = NULL, *wbuf;
+	void *buf = NULL, *wbuf = NULL, *buf_with_efi;
 	struct envfs_entry *env;
 	const char *defenv_path = default_environment_path_get();
 
@@ -342,7 +380,9 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 		}
 	}
 
-	buf = xzalloc(size + sizeof(struct envfs_super));
+	buf_with_efi = xzalloc(size + sizeof(struct envfs_super) +
+	EFIVAR_ATTR_SIZE);
+	buf = buf_with_efi + EFIVAR_ATTR_SIZE;
 	data.writep = buf + sizeof(struct envfs_super);
 
 	super = buf;
@@ -370,7 +410,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 	super->crc = ENVFS_32(crc32(0, buf + sizeof(struct envfs_super), size));
 	super->sb_crc = ENVFS_32(crc32(0, buf, sizeof(struct envfs_super) - 4));
 
-	envfd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
+	envfd = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
 	if (envfd < 0) {
 		printf("could not open %s: %m\n", filename);
 		ret = -errno;
@@ -385,6 +425,12 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 		goto out;
 	}
 
+	/* check if we writing efi vars */
+	ret = detect_efi_vars(envfd, buf_with_efi, &wbuf, &size);
+	if (ret != 0) {
+		goto out;
+	}
+
 	ret = erase(envfd, ERASE_SIZE_ALL, 0, ERASE_TO_WRITE);
 
 	/* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */
@@ -395,12 +441,11 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 
 	size += sizeof(struct envfs_super);
 
-	wbuf = buf;
-
 	while (size) {
 		ssize_t now = write(envfd, wbuf, size);
 		if (now < 0) {
 			ret = -errno;
+			perror("write");
 			goto out;
 		}
 
@@ -418,14 +463,14 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 
 	ret = 0;
 
-#ifdef CONFIG_NVVAR
+#if defined CONFIG_NVVAR && defined __BAREBOX__
 	if (defenv_path && !strcmp(filename, defenv_path))
 	    nv_var_set_clean();
 #endif
 out:
 	close(envfd);
 out1:
-	free(buf);
+	free(buf_with_efi);
 #ifdef __BAREBOX__
 	unlink_recursive(TMPDIR, NULL);
 #endif
@@ -449,6 +494,7 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
 	int envfd;
 	int ret = 0;
 	size_t size, rsize;
+	uint32_t magic;
 
 	if (!filename)
 		filename = default_environment_path_get();
@@ -466,6 +512,26 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
 		return -1;
 	}
 
+	/* check if we reading efi vars */
+	ret = pread(envfd, &magic, sizeof(uint32_t),
+		    EFIVAR_ATTR_SIZE);
+	if (ret < sizeof(u_int32_t)) {
+		perror("read");
+		ret = -errno;
+		goto out;
+	}
+
+	if (ENVFS_32(magic) == ENVFS_MAGIC) {
+		pr_info("Assuming EFI variable. Skip attributes\n");
+		ret = read(envfd, &magic,
+			   sizeof(uint32_t)); // simply reuse the memory
+		if (ret < sizeof(uint32_t)) {
+			perror("read");
+			ret = -errno;
+			goto out;
+		}
+	}
+
 	/* read superblock */
 	ret = read(envfd, &super, sizeof(struct envfs_super));
 	if ( ret < sizeof(struct envfs_super)) {
diff --git a/scripts/Makefile b/scripts/Makefile
index 6d89af7d4f..57d8ddb54d 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -30,6 +30,7 @@ hostprogs-always-$(CONFIG_RK_IMAGE)			+= rkimage
 HOSTCFLAGS_rkimage.o = `$(PKG_CONFIG) --cflags openssl`
 HOSTLDLIBS_rkimage = `$(PKG_CONFIG) --libs openssl`
 KBUILD_HOSTCFLAGS += -I$(srctree)/scripts/include/
+KBUILD_HOSTCFLAGS += -I$(objtree)/include/generated/
 HOSTCFLAGS_mxsimage.o = `$(PKG_CONFIG) --cflags openssl`
 HOSTLDLIBS_mxsimage  = `$(PKG_CONFIG) --libs openssl`
 HOSTCFLAGS_omap3-usb-loader.o = `$(PKG_CONFIG) --cflags libusb-1.0`
@@ -57,6 +58,7 @@ omap4_usbboot-target-userccflags += `$(CROSS_PKG_CONFIG) --cflags libusb-1.0`
 omap4_usbboot-target-userldlibs += -lpthread `$(CROSS_PKG_CONFIG) --libs libusb-1.0`
 rk-usb-loader-target-userccflags += `$(CROSS_PKG_CONFIG) --cflags libusb-1.0`
 rk-usb-loader-target-userldlibs += `$(CROSS_PKG_CONFIG) --libs libusb-1.0`
+bareboxenv-target-userccflags += -I$(objtree)/include/generated/
 
 userccflags += -I $(srctree)/$(src)/include -isystem $(srctree)/scripts/include
 
diff --git a/scripts/bareboxenv.c b/scripts/bareboxenv.c
index e954447015..6b9b8d90c4 100644
--- a/scripts/bareboxenv.c
+++ b/scripts/bareboxenv.c
@@ -117,7 +117,7 @@ static void usage(char *prgname)
 int main(int argc, char *argv[])
 {
 	int opt;
-	int save = 0, load = 0, pad = 0, err = 0, fd;
+	int save = 0, load = 0, pad = 0, err = 0;
 	char *filename = NULL, *dirname = NULL;
 	unsigned envfs_flags = 0;
 	int verbose = 0;
@@ -156,15 +156,6 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	if (save) {
-		fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0644);
-		if (fd < 0) {
-			perror("open");
-			exit(1);
-		}
-		close(fd);
-	}
-
 	if (save && pad) {
 		if (truncate(filename, pad)) {
 			perror("truncate");
-- 
2.45.3



From s.hauer at pengutronix.de  Wed Mar 19 01:36:23 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 09:36:23 +0100
Subject: [PATCH] ARM: am335x_mlo_defconfig: disable unnecessary options
Message-ID: <20250319083623.2203370-1-s.hauer@pengutronix.de>

- disable CONFIG_BOARD_GENERIC_DT which is not needed for the MLO
  defconfig
- disable CONFIG_MTD_NAND_ECC_SW_HAMMING. AM335x uses hardware ECC
- disable CONFIG_BANNER. Saves another few bytes

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/am335x_mlo_defconfig | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/arm/configs/am335x_mlo_defconfig b/arch/arm/configs/am335x_mlo_defconfig
index 4a9ce6cfb7..e9d9f93edf 100644
--- a/arch/arm/configs/am335x_mlo_defconfig
+++ b/arch/arm/configs/am335x_mlo_defconfig
@@ -6,19 +6,18 @@ CONFIG_MACH_BEAGLEBONE=y
 CONFIG_MACH_MYIRTECH_X335X=y
 CONFIG_MACH_PHYTEC_SOM_AM335X=y
 CONFIG_THUMB2_BAREBOX=y
+# CONFIG_BOARD_GENERIC_DT is not set
+# CONFIG_BANNER is not set
 # CONFIG_MEMINFO is not set
 CONFIG_IMAGE_COMPRESSION_XZKERN=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x1b400
 CONFIG_MALLOC_SIZE=0x0
 CONFIG_MALLOC_TLSF=y
-CONFIG_RELOCATABLE=y
 CONFIG_PROMPT="MLO>"
 CONFIG_SHELL_NONE=y
 # CONFIG_ERRNO_MESSAGES is not set
-# CONFIG_TIMESTAMP is not set
 CONFIG_CONSOLE_ACTIVATE_NONE=y
-CONFIG_OFDEVICE=y
 # CONFIG_FILETYPE_STRING is not set
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SPI_OMAP3=y
@@ -28,10 +27,12 @@ CONFIG_MTD=y
 CONFIG_MTD_M25P80=y
 CONFIG_NAND=y
 CONFIG_NAND_OMAP_GPMC=y
+# CONFIG_MTD_NAND_ECC_SW_HAMMING is not set
 CONFIG_MCI=y
 # CONFIG_MCI_WRITE is not set
 CONFIG_MCI_OMAP_HSMMC=y
 CONFIG_PINCTRL_SINGLE=y
 CONFIG_BUS_OMAP_GPMC=y
+# CONFIG_VIRTIO_MENU is not set
 # CONFIG_FS_DEVFS is not set
 CONFIG_FS_FAT=y
-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 19 01:41:50 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 09:41:50 +0100
Subject: [PATCH 0/7] filetype: Some size reduction patches
In-Reply-To: <CAP1tNvQokH9TTSANKNADzo5Nie2SzjAyM08ix0D8gbL6TPxBuw@mail.gmail.com>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
 <CAP1tNvQokH9TTSANKNADzo5Nie2SzjAyM08ix0D8gbL6TPxBuw@mail.gmail.com>
Message-ID: <Z9qDTuzVEeRNHRqn@pengutronix.de>

Hi Alexander,

On Tue, Mar 18, 2025 at 06:01:19PM +0300, Alexander Shiyan wrote:
> Hello Sascha!
> 
> I've been using a separate config for this board for a long time :)
> Maybe you can take something from my working configuration that
> has been working for several years:
> https://github.com/shcgit/barebox/blob/milas/arch/arm/configs/mm_am335x_mlo_defconfig

Thanks, I extracted some more unneeded options from that. You disabled
the board support which we want to keep. Also you disabled SPI boot
which I think we'll need for some boards. However, these are indeed
not needed:

- CONFIG_BOARD_GENERIC_DT
- CONFIG_MTD_NAND_ECC_SW_HAMMING.
- CONFIG_BANNER

With my series and these options disabled the beaglebone MLO is now down
to 108836 bytes from originally 111956 bytes. The maximim size is 111616
bytes so we now have another 2780 bytes for future bloat before we are
in the same situation again ;)

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Wed Mar 19 02:13:22 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 10:13:22 +0100
Subject: [PATCH 0/6] mci: some cleanups
In-Reply-To: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
References: <20250317-mci-misc-cleanup-v1-0-24b4d6f5d31a@pengutronix.de>
Message-ID: <174237560298.2355103.5957017931407817475.b4-ty@pengutronix.de>


On Mon, 17 Mar 2025 10:34:32 +0100, Sascha Hauer wrote:
> This cleans up some stuff in the mci layer and its drivers.
> 
> 

Applied, thanks!

[1/6] mci: use struct cid
      https://git.pengutronix.de/cgit/barebox/commit/?id=a4a78c4f321a (link may not be stable)
[2/6] mmc: merge block read/write functions
      https://git.pengutronix.de/cgit/barebox/commit/?id=38543119546f (link may not be stable)
[3/6] mci: cleanup code around ready_for_use flag
      https://git.pengutronix.de/cgit/barebox/commit/?id=8c7710fdf1c0 (link may not be stable)
[4/6] mci: mci_spi: remove stray return 0
      https://git.pengutronix.de/cgit/barebox/commit/?id=52ea3c5986cf (link may not be stable)
[5/6] mci: mci_spi: fix warning message
      https://git.pengutronix.de/cgit/barebox/commit/?id=6c0dcb67f65a (link may not be stable)
[6/6] mci: mci_spi: use mci_of_parse()
      https://git.pengutronix.de/cgit/barebox/commit/?id=82a681eb1889 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Wed Mar 19 02:19:36 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 10:19:36 +0100
Subject: [PATCH] ARM: am335x_mlo_defconfig: disable unnecessary options
In-Reply-To: <20250319083623.2203370-1-s.hauer@pengutronix.de>
References: <20250319083623.2203370-1-s.hauer@pengutronix.de>
Message-ID: <174237597692.2358998.2140175256944818188.b4-ty@pengutronix.de>


On Wed, 19 Mar 2025 09:36:23 +0100, Sascha Hauer wrote:
> - disable CONFIG_BOARD_GENERIC_DT which is not needed for the MLO
>   defconfig
> - disable CONFIG_MTD_NAND_ECC_SW_HAMMING. AM335x uses hardware ECC
> - disable CONFIG_BANNER. Saves another few bytes
> 
> 

Applied, thanks!

[1/1] ARM: am335x_mlo_defconfig: disable unnecessary options
      https://git.pengutronix.de/cgit/barebox/commit/?id=2e62b722f190 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Wed Mar 19 03:22:28 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 11:22:28 +0100
Subject: [PATCH] serial: omap: make Linux console name configurable
Message-ID: <20250319102228.2401563-1-s.hauer@pengutronix.de>

Depending on the configuration Linux on OMAP SoCs either needs ttyO or
ttyS as console name. We used to pass ttyO, but c1c0d18973
("serial: omap: Use ttyS as Linux console name") recently changed this
to ttyS which breaks setups that used to work earlier. Make the
name configurable to allow for setups requiring ttyS and use ttyO
as default to keep existing setups working.

Note that with ti,am4372-uart we used to pass ttyO as well, but this
specific compatible is only supported by the 8250 based driver which
needs ttyS as console name. With this patch we always pass ttyS
regardless of CONFIG_DRIVER_SERIAL_NS16550_OMAP_TTYS.

All new SoCs like the K3 SoCs are only supported by the 8250 based
driver which needs ttyS. On these SoCs CONFIG_DRIVER_SERIAL_NS16550_OMAP_TTYS
will also have no effect.

Fixes: c1c0d18973 ("serial: omap: Use ttyS as Linux console name")
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/serial/Kconfig          | 12 ++++++++++++
 drivers/serial/serial_ns16550.c |  4 ++++
 2 files changed, 16 insertions(+)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index b7312ca796..6ac1d94526 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -77,6 +77,18 @@ config DRIVER_SERIAL_NS16550
 	help
 	  Enable this to get support for NS16550 based serial devices
 
+config DRIVER_SERIAL_NS16550_OMAP_TTYS
+	depends on ARCH_OMAP
+	bool "Use ttyS as console name for TI OMAP/AMxxx SoCs"
+	help
+	  Linux has two different drivers for the TI OMAP/AMxxx serial ports. One is
+	  based on the generic 8250 driver and activated with CONFIG_SERIAL_8250_OMAP.
+	  This one uses ttyS as console name. When CONFIG_SERIAL_8250_OMAP_TTYO_FIXUP
+	  is enabled, this driver takes ttyO as console name as well, but issues a warning
+	  during boot. The other driver is activated with CONFIG_SERIAL_OMAP and takes ttyO
+	  as console name. Say yes here to pass ttyS as console, otherwise ttyO will be
+	  used.
+
 config DRIVER_SERIAL_ATMEL
 	depends on ARCH_AT91
 	default y
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index 56a1c6c6b9..6d4a4e8c7c 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -402,7 +402,11 @@ static struct ns16550_drvdata ns16550_drvdata = {
 
 static __maybe_unused struct ns16550_drvdata omap_drvdata = {
 	.init_port = ns16550_omap_init_port,
+#ifdef CONFIG_DRIVER_SERIAL_NS16550_OMAP_TTYS
 	.linux_console_name = "ttyS",
+#else
+	.linux_console_name = "ttyO",
+#endif
 	.linux_earlycon_name = "omap8250",
 };
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 03:55:53 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 19 Mar 2025 11:55:53 +0100
Subject: [PATCH] serial: omap: make Linux console name configurable
In-Reply-To: <20250319102228.2401563-1-s.hauer@pengutronix.de>
References: <20250319102228.2401563-1-s.hauer@pengutronix.de>
Message-ID: <50522640-eedf-4c34-81ad-9238aa6d39b9@pengutronix.de>

Hello Sascha,

On 3/19/25 11:22, Sascha Hauer wrote:
> Depending on the configuration Linux on OMAP SoCs either needs ttyO or
> ttyS as console name. We used to pass ttyO, but c1c0d18973
> ("serial: omap: Use ttyS as Linux console name") recently changed this
> to ttyS which breaks setups that used to work earlier. Make the
> name configurable to allow for setups requiring ttyS and use ttyO
> as default to keep existing setups working.
> 
> Note that with ti,am4372-uart we used to pass ttyO as well, but this
> specific compatible is only supported by the 8250 based driver which
> needs ttyS as console name. 

This reads as if 8250_omap supports only ttyS, but it has logic to
support ttyO as well.

> With this patch we always pass ttyS
> regardless of CONFIG_DRIVER_SERIAL_NS16550_OMAP_TTYS.
> 
> All new SoCs like the K3 SoCs are only supported by the 8250 based
> driver which needs ttyS. On these SoCs CONFIG_DRIVER_SERIAL_NS16550_OMAP_TTYS
> will also have no effect.
> 
> Fixes: c1c0d18973 ("serial: omap: Use ttyS as Linux console name")
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

See also the comment below.


> ---
>  drivers/serial/Kconfig          | 12 ++++++++++++
>  drivers/serial/serial_ns16550.c |  4 ++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
> index b7312ca796..6ac1d94526 100644
> --- a/drivers/serial/Kconfig
> +++ b/drivers/serial/Kconfig
> @@ -77,6 +77,18 @@ config DRIVER_SERIAL_NS16550
>  	help
>  	  Enable this to get support for NS16550 based serial devices
>  
> +config DRIVER_SERIAL_NS16550_OMAP_TTYS

default ARCH_K3 ?

> +	depends on ARCH_OMAP
> +	bool "Use ttyS as console name for TI OMAP/AMxxx SoCs"
> +	help
> +	  Linux has two different drivers for the TI OMAP/AMxxx serial ports. One is
> +	  based on the generic 8250 driver and activated with CONFIG_SERIAL_8250_OMAP.
> +	  This one uses ttyS as console name. When CONFIG_SERIAL_8250_OMAP_TTYO_FIXUP
> +	  is enabled, this driver takes ttyO as console name as well, but issues a warning
> +	  during boot. The other driver is activated with CONFIG_SERIAL_OMAP and takes ttyO
> +	  as console name. Say yes here to pass ttyS as console, otherwise ttyO will be
> +	  used.
> +
>  config DRIVER_SERIAL_ATMEL
>  	depends on ARCH_AT91
>  	default y
> diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
> index 56a1c6c6b9..6d4a4e8c7c 100644
> --- a/drivers/serial/serial_ns16550.c
> +++ b/drivers/serial/serial_ns16550.c
> @@ -402,7 +402,11 @@ static struct ns16550_drvdata ns16550_drvdata = {
>  
>  static __maybe_unused struct ns16550_drvdata omap_drvdata = {
>  	.init_port = ns16550_omap_init_port,
> +#ifdef CONFIG_DRIVER_SERIAL_NS16550_OMAP_TTYS
>  	.linux_console_name = "ttyS",
> +#else
> +	.linux_console_name = "ttyO",
> +#endif
>  	.linux_earlycon_name = "omap8250",
>  };
>  



From s.hauer at pengutronix.de  Wed Mar 19 04:01:30 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 12:01:30 +0100
Subject: [PATCH] serial: omap: make Linux console name configurable
In-Reply-To: <50522640-eedf-4c34-81ad-9238aa6d39b9@pengutronix.de>
References: <20250319102228.2401563-1-s.hauer@pengutronix.de>
 <50522640-eedf-4c34-81ad-9238aa6d39b9@pengutronix.de>
Message-ID: <Z9qkCsnzeOjtnJkh@pengutronix.de>

On Wed, Mar 19, 2025 at 11:55:53AM +0100, Ahmad Fatoum wrote:
> Hello Sascha,
> 
> On 3/19/25 11:22, Sascha Hauer wrote:
> > Depending on the configuration Linux on OMAP SoCs either needs ttyO or
> > ttyS as console name. We used to pass ttyO, but c1c0d18973
> > ("serial: omap: Use ttyS as Linux console name") recently changed this
> > to ttyS which breaks setups that used to work earlier. Make the
> > name configurable to allow for setups requiring ttyS and use ttyO
> > as default to keep existing setups working.
> > 
> > Note that with ti,am4372-uart we used to pass ttyO as well, but this
> > specific compatible is only supported by the 8250 based driver which
> > needs ttyS as console name. 
> 
> This reads as if 8250_omap supports only ttyS, but it has logic to
> support ttyO as well.

s/needs/prefers/ maybe

Sascha

-- 
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-5555 |


From a.fatoum at pengutronix.de  Wed Mar 19 04:03:31 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 19 Mar 2025 12:03:31 +0100
Subject: [PATCH] serial: omap: make Linux console name configurable
In-Reply-To: <Z9qkCsnzeOjtnJkh@pengutronix.de>
References: <20250319102228.2401563-1-s.hauer@pengutronix.de>
 <50522640-eedf-4c34-81ad-9238aa6d39b9@pengutronix.de>
 <Z9qkCsnzeOjtnJkh@pengutronix.de>
Message-ID: <92d6e357-4620-4c3e-ac28-48804d74d192@pengutronix.de>



On 3/19/25 12:01, Sascha Hauer wrote:
> On Wed, Mar 19, 2025 at 11:55:53AM +0100, Ahmad Fatoum wrote:
>> Hello Sascha,
>>
>> On 3/19/25 11:22, Sascha Hauer wrote:
>>> Depending on the configuration Linux on OMAP SoCs either needs ttyO or
>>> ttyS as console name. We used to pass ttyO, but c1c0d18973
>>> ("serial: omap: Use ttyS as Linux console name") recently changed this
>>> to ttyS which breaks setups that used to work earlier. Make the
>>> name configurable to allow for setups requiring ttyS and use ttyO
>>> as default to keep existing setups working.
>>>
>>> Note that with ti,am4372-uart we used to pass ttyO as well, but this
>>> specific compatible is only supported by the 8250 based driver which
>>> needs ttyS as console name. 
>>
>> This reads as if 8250_omap supports only ttyS, but it has logic to
>> support ttyO as well.
> 
> s/needs/prefers/ maybe

Ye, further below there is also 'will also have no effect', which is not
true as it hides an ugly error message.

Can you reword these two parts and make the option default ARCH_K3?

Thanks,
Ahmad

> 
> Sascha
> 



From s.hauer at pengutronix.de  Wed Mar 19 04:16:13 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 12:16:13 +0100
Subject: [PATCH] serial: omap: make Linux console name configurable
In-Reply-To: <92d6e357-4620-4c3e-ac28-48804d74d192@pengutronix.de>
References: <20250319102228.2401563-1-s.hauer@pengutronix.de>
 <50522640-eedf-4c34-81ad-9238aa6d39b9@pengutronix.de>
 <Z9qkCsnzeOjtnJkh@pengutronix.de>
 <92d6e357-4620-4c3e-ac28-48804d74d192@pengutronix.de>
Message-ID: <Z9qnfYtxQ_LZtRYw@pengutronix.de>

On Wed, Mar 19, 2025 at 12:03:31PM +0100, Ahmad Fatoum wrote:
> 
> 
> On 3/19/25 12:01, Sascha Hauer wrote:
> > On Wed, Mar 19, 2025 at 11:55:53AM +0100, Ahmad Fatoum wrote:
> >> Hello Sascha,
> >>
> >> On 3/19/25 11:22, Sascha Hauer wrote:
> >>> Depending on the configuration Linux on OMAP SoCs either needs ttyO or
> >>> ttyS as console name. We used to pass ttyO, but c1c0d18973
> >>> ("serial: omap: Use ttyS as Linux console name") recently changed this
> >>> to ttyS which breaks setups that used to work earlier. Make the
> >>> name configurable to allow for setups requiring ttyS and use ttyO
> >>> as default to keep existing setups working.
> >>>
> >>> Note that with ti,am4372-uart we used to pass ttyO as well, but this
> >>> specific compatible is only supported by the 8250 based driver which
> >>> needs ttyS as console name. 
> >>
> >> This reads as if 8250_omap supports only ttyS, but it has logic to
> >> support ttyO as well.
> > 
> > s/needs/prefers/ maybe
> 
> Ye, further below there is also 'will also have no effect', which is not
> true as it hides an ugly error message.
> 
> Can you reword these two parts and make the option default ARCH_K3?

ARCH_K3 doesn't need this option.

Sascha

-- 
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-5555 |


From a.fatoum at pengutronix.de  Wed Mar 19 04:30:30 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 19 Mar 2025 12:30:30 +0100
Subject: [PATCH] serial: omap: make Linux console name configurable
In-Reply-To: <Z9qnfYtxQ_LZtRYw@pengutronix.de>
References: <20250319102228.2401563-1-s.hauer@pengutronix.de>
 <50522640-eedf-4c34-81ad-9238aa6d39b9@pengutronix.de>
 <Z9qkCsnzeOjtnJkh@pengutronix.de>
 <92d6e357-4620-4c3e-ac28-48804d74d192@pengutronix.de>
 <Z9qnfYtxQ_LZtRYw@pengutronix.de>
Message-ID: <7b564a3c-2f28-4d0f-86b4-fd3da47e94c3@pengutronix.de>

Hi,

On 3/19/25 12:16, Sascha Hauer wrote:
> On Wed, Mar 19, 2025 at 12:03:31PM +0100, Ahmad Fatoum wrote:
>>
>>
>> On 3/19/25 12:01, Sascha Hauer wrote:
>>> On Wed, Mar 19, 2025 at 11:55:53AM +0100, Ahmad Fatoum wrote:
>>>> Hello Sascha,
>>>>
>>>> On 3/19/25 11:22, Sascha Hauer wrote:
>>>>> Depending on the configuration Linux on OMAP SoCs either needs ttyO or
>>>>> ttyS as console name. We used to pass ttyO, but c1c0d18973
>>>>> ("serial: omap: Use ttyS as Linux console name") recently changed this
>>>>> to ttyS which breaks setups that used to work earlier. Make the
>>>>> name configurable to allow for setups requiring ttyS and use ttyO
>>>>> as default to keep existing setups working.
>>>>>
>>>>> Note that with ti,am4372-uart we used to pass ttyO as well, but this
>>>>> specific compatible is only supported by the 8250 based driver which
>>>>> needs ttyS as console name. 
>>>>
>>>> This reads as if 8250_omap supports only ttyS, but it has logic to
>>>> support ttyO as well.
>>>
>>> s/needs/prefers/ maybe
>>
>> Ye, further below there is also 'will also have no effect', which is not
>> true as it hides an ugly error message.
>>
>> Can you reword these two parts and make the option default ARCH_K3?
> 
> ARCH_K3 doesn't need this option.

Ah, ok. Then feel free to add my:

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

Cheers,
Ahmad

> 
> Sascha
> 



From s.hauer at pengutronix.de  Wed Mar 19 05:32:32 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 13:32:32 +0100
Subject: [PATCH 0/7] filetype: Some size reduction patches
In-Reply-To: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
References: <20250318-filetype-size-reduction-v1-0-4f463ffae7d0@pengutronix.de>
Message-ID: <174238755239.2481153.12007766666223606397.b4-ty@pengutronix.de>


On Tue, 18 Mar 2025 15:41:41 +0100, Sascha Hauer wrote:
> The am335x_mlo_defconfig is very size constrained and doesn't build
> within these constraint anymore for some time. The filetype detection
> code has become quite big and offers some opportunities for size
> reduction. Specifically file_detect_type() is quite big, but many
> callers are only interested in some specific file types like supported
> file systems or supported compressed binary formats. This series
> introduces some more specific smaller file detection functions so that
> we can get rid of the big file_detect_type() in the binary.
> 
> [...]

Applied, thanks!

[1/7] filetype: add file_detect_compression_type()
      https://git.pengutronix.de/cgit/barebox/commit/?id=519153fd74cb (link may not be stable)
[2/7] filetype: add file_detect_fs_type()
      https://git.pengutronix.de/cgit/barebox/commit/?id=b25680a9c995 (link may not be stable)
[3/7] filetype: add function pointer to file_name_detect_type_offset()
      https://git.pengutronix.de/cgit/barebox/commit/?id=834d9b644638 (link may not be stable)
[4/7] filetype: let cdev_detect_type() only detect filesystems
      https://git.pengutronix.de/cgit/barebox/commit/?id=dcf835a983c9 (link may not be stable)
[5/7] filetype: make file type strings optional
      https://git.pengutronix.de/cgit/barebox/commit/?id=09702e4a00ec (link may not be stable)
[6/7] ARM: am33xx: myirtech-myd: add MLO specific device tree
      https://git.pengutronix.de/cgit/barebox/commit/?id=75914e1c1983 (link may not be stable)
[7/7] ARM: am335x_mlo_defconfig: disable file type strings
      https://git.pengutronix.de/cgit/barebox/commit/?id=285d88922cad (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Wed Mar 19 05:34:13 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 13:34:13 +0100
Subject: [PATCH] serial: omap: make Linux console name configurable
In-Reply-To: <20250319102228.2401563-1-s.hauer@pengutronix.de>
References: <20250319102228.2401563-1-s.hauer@pengutronix.de>
Message-ID: <174238765331.2494090.3855475189846366550.b4-ty@pengutronix.de>


On Wed, 19 Mar 2025 11:22:28 +0100, Sascha Hauer wrote:
> Depending on the configuration Linux on OMAP SoCs either needs ttyO or
> ttyS as console name. We used to pass ttyO, but c1c0d18973
> ("serial: omap: Use ttyS as Linux console name") recently changed this
> to ttyS which breaks setups that used to work earlier. Make the
> name configurable to allow for setups requiring ttyS and use ttyO
> as default to keep existing setups working.
> 
> [...]

Applied, thanks!

[1/1] serial: omap: make Linux console name configurable
      https://git.pengutronix.de/cgit/barebox/commit/?id=13557d1ab024 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Wed Mar 19 08:29:15 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:29:15 +0100
Subject: [PATCH 4/9] mci: add RPMB support
In-Reply-To: <Z9lZ8Q4bhUnuur1X@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
 <20250312-rpmb-v1-4-0f213382a3f3@pengutronix.de>
 <9c66b31b-a79c-4a07-a03f-119c7c3dadc7@pengutronix.de>
 <Z9lZ8Q4bhUnuur1X@pengutronix.de>
Message-ID: <Z9riy3YWmESSdii7@pengutronix.de>

On Tue, Mar 18, 2025 at 12:33:05PM +0100, Sascha Hauer wrote:
> On Mon, Mar 17, 2025 at 04:18:32PM +0100, Ahmad Fatoum wrote:
> > Hello Sascha,
> > 
> > On 3/12/25 13:16, Sascha Hauer wrote:
> > > +
> > > +int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
> > > +			  void *rsp, unsigned long rsplen)
> > > +{
> > > +	/*
> > > +	 * Whoever crafted the data supplied to this function knows how to
> > > +	 * format the PRMB frames and which response is expected. If
> > > +	 * there's some unexpected mismatch it's more helpful to report an
> > > +	 * error immediately than trying to guess what was the intention
> > > +	 * and possibly just delay an eventual error which will be harder
> > > +	 * to track down.
> > > +	 */
> > > +	void *rpmb_data = NULL;
> > > +	int ret;
> > > +
> > > +	mci_blk_part_switch(mci->rpmb_part);
> > > +
> > > +	if (!IS_ALIGNED((uintptr_t)req, ARCH_DMA_MINALIGN)) {
> > 
> > Even if alignment happens to be correct, there is no guarantee that
> > there is no other data sharing a cache line.
> 
> reqlen is expected to be a single block of 512 bytes, so indeed when req
> is aligned then the end is cacheline aligned as well. We could check
> reqlen as well, but I actually never ran into this case, so we can just
> return an error for now as you suggested.

I was wrong here. the request is placed directly behind a 6 byte struct,
so it's guaranteed to be unaligned. We always have to copy it.

The response might be unaligned as well, but must be aligned to pass it
to the mmc layer. In my tests the response was always aligned, but
better safe than sorry, so I'll add an alignment check here as well,
this time including a check for the length.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Wed Mar 19 08:30:51 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:30:51 +0100
Subject: [PATCH v2 00/10] Add RPMB support
Message-ID: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>

This series adds the necessary pieces to provide OP-TEE access to RPMB
partitions under barebox.

With this OP-TEE can issue RPMB requests to barebox and barebox will
answer them accordingly.

OP-TEE will only access the RPMB when triggered by barebox. For this
purpose I implemented access to the Android Verified Boot (AVB) variable
store. This is implemented in U-Boot as well and the code is loosely
based on it. The variables can be read/written using the newly
introduced avb_pvalue command.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
Changes in v2:
- Use mmc of alias to translate OP-TEE dev_id into barebox mmc device
- Always copy mmc request to aligned address
- check mmc response for proper alignment
- Warn when we encounter an unimplemented OP-TEE RPC request
- Link to v1: https://lore.kernel.org/r/20250312-rpmb-v1-0-0f213382a3f3 at pengutronix.de

---
Sascha Hauer (10):
      mci: implement mci_set_blockcount()
      mci: export some functions for RPMB support
      mci: detect RPMB partitions
      mci: add RPMB support
      tee: optee: probe successfully even when no devices are found
      tee: optee: implement shared mem alloc/free RPC commands
      tee: optee: implement RPMB support
      tee: optee: implement AVB named persistent values support
      commands: add avb_pvalue command
      ARM: omap: remove unused file

 commands/Kconfig                  |  13 +++
 commands/Makefile                 |   1 +
 commands/avb_pvalue.c             | 138 +++++++++++++++++++++++++
 drivers/mci/Kconfig               |   3 +
 drivers/mci/Makefile              |   1 +
 drivers/mci/mci-core.c            |  70 +++++++++++--
 drivers/mci/rpmb.c                | 210 ++++++++++++++++++++++++++++++++++++++
 drivers/tee/optee/Kconfig         |   9 ++
 drivers/tee/optee/Makefile        |   2 +
 drivers/tee/optee/avb.c           | 189 ++++++++++++++++++++++++++++++++++
 drivers/tee/optee/device.c        |   1 +
 drivers/tee/optee/optee_private.h |  13 +++
 drivers/tee/optee/optee_rpc_cmd.h | 144 ++++++++++++++++++++++++++
 drivers/tee/optee/rpc.c           |  64 +++++++++++-
 drivers/tee/optee/rpmb.c          | 121 ++++++++++++++++++++++
 drivers/tee/optee/smc_abi.c       |  26 +++--
 drivers/tee/tee_shm.c             |   1 +
 include/linux/tee_drv.h           |   1 +
 include/mach/omap/omap4-devices.h |  93 -----------------
 include/mci.h                     |  19 +++-
 include/tee/avb.h                 |   9 ++
 21 files changed, 1014 insertions(+), 114 deletions(-)
---
base-commit: ca25df4baad4569efabbebcd79ab4aee7ed226ff
change-id: 20250312-rpmb-c6f330f29cb1

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Wed Mar 19 08:30:56 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:30:56 +0100
Subject: [PATCH v2 05/10] tee: optee: probe successfully even when no
 devices are found
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
Message-ID: <20250319-rpmb-v2-5-a8801fb35cd4@pengutronix.de>

OP-TEE iterates over the devices and when none are found the OP-TEE
driver returns with an error. Return successfully instead because
for example RPMB support doesn't require any devices exported from
OP-TEE.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/tee/optee/device.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c
index 100a877395..5176989a50 100644
--- a/drivers/tee/optee/device.c
+++ b/drivers/tee/optee/device.c
@@ -115,6 +115,7 @@ static int __optee_enumerate_devices(u32 func)
 		goto out_sess;
 	if (!shm_size) {
 		pr_debug("device enumeration PTA found, but no devices!\n");
+		rc = 0;
 		goto out_sess;
 	}
 

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 19 08:30:54 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:30:54 +0100
Subject: [PATCH v2 03/10] mci: detect RPMB partitions
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
Message-ID: <20250319-rpmb-v2-3-a8801fb35cd4@pengutronix.de>

Detect RPMB partitions and initialize a struct mci_part for them. We do
not actually register the RPMB partitions as we can't access them with
regular mci_do_block_op() and we would only access encrypted data anyway.

Right now we assume that only one RPMB is present in a system which
covers the 99% case. Should there be multiple RPMBs found we issue a
warning message as there is no way to specify which one shall be used,
the first one found will be used which may vary depending on probe
order.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 20 ++++++++++++++++++++
 include/mci.h          |  7 ++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index b7ea0df3cb..3bf0f15def 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -671,6 +671,9 @@ static void mci_part_add(struct mci *mci, uint64_t size,
 	part->part_cfg = part_cfg;
 	part->idx = idx;
 
+	if (area_type == MMC_BLK_DATA_AREA_RPMB)
+		mci->rpmb_part = part;
+
 	if (area_type == MMC_BLK_DATA_AREA_MAIN) {
 		cdev_set_of_node(&part->blk.cdev, mci->host->hw_dev->of_node);
 		part->blk.cdev.flags |= DEVFS_IS_MCI_MAIN_PART_DEV;
@@ -822,6 +825,20 @@ static int mmc_change_freq(struct mci *mci)
 		mci->boot_ack_enable = (mci->ext_csd_part_config >> 6) & 0x1;
 	}
 
+	if (mci->ext_csd[EXT_CSD_REV] >= 5) {
+		if (mci->ext_csd[EXT_CSD_RPMB_SIZE_MULT]) {
+			char *name, *partname;
+
+			partname = basprintf("rpmb");
+			name = basprintf("%s.%s", mci->cdevname, partname);
+
+			mci_part_add(mci, mci->ext_csd[EXT_CSD_RPMB_SIZE_MULT] << 17,
+				EXT_CSD_PART_CONFIG_ACC_RPMB,
+				name, partname, 0, false,
+				MMC_BLK_DATA_AREA_RPMB);
+		}
+	}
+
 	if (IS_ENABLED(CONFIG_MCI_MMC_GPP_PARTITIONS))
 		mmc_extract_gpp_partitions(mci);
 
@@ -2601,6 +2618,9 @@ static int mci_register_partition(struct mci_part *part)
 	part->blk.ops = &mci_ops;
 	part->blk.type = IS_SD(mci) ? BLK_TYPE_SD : BLK_TYPE_MMC;
 
+	if (part->area_type == MMC_BLK_DATA_AREA_RPMB)
+		return 0;
+
 	rc = blockdevice_register(&part->blk);
 	if (rc != 0) {
 		dev_err(&mci->dev, "Failed to register MCI/SD blockdevice\n");
diff --git a/include/mci.h b/include/mci.h
index 8084df813a..08a3e46f7d 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -347,6 +347,7 @@
  */
 #define EXT_CSD_PART_CONFIG_ACC_MASK	(0x7)
 #define EXT_CSD_PART_CONFIG_ACC_BOOT0	(0x1)
+#define EXT_CSD_PART_CONFIG_ACC_RPMB	(0x3)
 #define EXT_CSD_PART_CONFIG_ACC_GPP0	(0x4)
 
 #define EXT_CSD_CMD_SET_NORMAL		(1<<0)
@@ -606,9 +607,11 @@ struct mci_host {
 #define MMC_NUM_BOOT_PARTITION	2
 #define MMC_NUM_GP_PARTITION	4
 #define MMC_NUM_USER_PARTITION	1
+#define MMC_NUM_RPMB_PARTITION	1
 #define MMC_NUM_PHY_PARTITION	(MMC_NUM_BOOT_PARTITION + \
                                  MMC_NUM_GP_PARTITION + \
-                                 MMC_NUM_USER_PARTITION)
+                                 MMC_NUM_USER_PARTITION + \
+                                 MMC_NUM_RPMB_PARTITION)
 
 struct mci_part {
 	struct block_device	blk;		/**< the blockdevice for the card */
@@ -674,6 +677,8 @@ struct mci {
 	int boot_ack_enable;
 
 	struct mci_part part[MMC_NUM_PHY_PARTITION];
+	struct mci_part *rpmb_part;
+
 	int nr_parts;
 	char *cdevname;
 

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 19 08:30:58 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:30:58 +0100
Subject: [PATCH v2 07/10] tee: optee: implement RPMB support
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
Message-ID: <20250319-rpmb-v2-7-a8801fb35cd4@pengutronix.de>

This implements the OPTEE_RPC_CMD_RPMB RPC call. For data requests we
call into the MMC specific RPMB implementation.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/tee/optee/Makefile        |   1 +
 drivers/tee/optee/optee_private.h |  10 ++++
 drivers/tee/optee/rpc.c           |   4 ++
 drivers/tee/optee/rpmb.c          | 121 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 136 insertions(+)

diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile
index 5e71af77ee..f68352aa4e 100644
--- a/drivers/tee/optee/Makefile
+++ b/drivers/tee/optee/Makefile
@@ -6,3 +6,4 @@ optee-objs += call.o
 optee-objs += rpc.o
 optee-objs += device.o
 optee-objs += smc_abi.o
+obj-$(CONFIG_MCI_MMC_RPMB) += rpmb.o
diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h
index d739a6c609..bb9ac1b068 100644
--- a/drivers/tee/optee/optee_private.h
+++ b/drivers/tee/optee/optee_private.h
@@ -179,4 +179,14 @@ static inline void reg_pair_from_64(u32 *reg0, u32 *reg1, u64 val)
 /* Registration of the ABIs */
 int optee_smc_abi_register(void);
 
+#ifdef CONFIG_MCI_MMC_RPMB
+void optee_suppl_cmd_rpmb(struct tee_context *ctx, struct optee_msg_arg *arg);
+#else
+static inline void optee_suppl_cmd_rpmb(struct tee_context *ctx, struct optee_msg_arg *arg)
+{
+	pr_debug("OPTEE_MSG_RPC_CMD_RPMB not implemented\n");
+	arg->ret = TEEC_ERROR_NOT_IMPLEMENTED;
+}
+#endif
+
 #endif /*OPTEE_PRIVATE_H*/
diff --git a/drivers/tee/optee/rpc.c b/drivers/tee/optee/rpc.c
index bdb2a9da74..bc398a625b 100644
--- a/drivers/tee/optee/rpc.c
+++ b/drivers/tee/optee/rpc.c
@@ -64,7 +64,11 @@ void optee_rpc_cmd(struct tee_context *ctx, struct optee *optee,
 	case OPTEE_RPC_CMD_SHM_FREE:
 		cmd_shm_free(arg);
 		break;
+	case OPTEE_RPC_CMD_RPMB:
+		optee_suppl_cmd_rpmb(ctx, arg);
+		break;
 	default:
+		pr_notice_once("optee: No supplicant or RPC handler for command 0x%x\n", arg->cmd);
 		arg->ret = TEEC_ERROR_NOT_IMPLEMENTED;
 	}
 
diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c
new file mode 100644
index 0000000000..cdc8afc1a4
--- /dev/null
+++ b/drivers/tee/optee/rpmb.c
@@ -0,0 +1,121 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2018 Linaro Limited
+ */
+
+#define pr_fmt(fmt)     "optee-rpmb: " fmt
+
+#include <mci.h>
+
+#include "optee_msg.h"
+#include "optee_private.h"
+
+/*
+ * Request and response definitions must be in sync with the secure side of
+ * OP-TEE.
+ */
+
+/* Request */
+struct rpmb_req {
+	u16 cmd;
+#define RPMB_CMD_DATA_REQ      0x00
+#define RPMB_CMD_GET_DEV_INFO  0x01
+	u16 dev_id;
+	u16 block_count;
+	/* Optional data frames (rpmb_data_frame) follow */
+};
+
+#define RPMB_REQ_DATA(req) ((void *)((struct rpmb_req *)(req) + 1))
+
+/* Response to device info request */
+struct rpmb_dev_info {
+	u8 cid[16];
+	u8 rpmb_size_mult;	/* EXT CSD-slice 168: RPMB Size */
+	u8 rel_wr_sec_c;	/* EXT CSD-slice 222: Reliable Write Sector */
+				/*                    Count */
+	u8 ret_code;
+#define RPMB_CMD_GET_DEV_INFO_RET_OK     0x00
+#define RPMB_CMD_GET_DEV_INFO_RET_ERROR  0x01
+};
+
+static u32 rpmb_get_dev_info(struct mci *mci, struct rpmb_dev_info *info)
+{
+	int i;
+
+	if (!mci->ext_csd)
+		return TEEC_ERROR_GENERIC;
+
+	for (i = 0; i < ARRAY_SIZE(mci->raw_cid); i++)
+		((u32 *) info->cid)[i] = cpu_to_be32(mci->raw_cid[i]);
+
+	info->rel_wr_sec_c = mci->ext_csd[222];
+	info->rpmb_size_mult = mci->ext_csd[168];
+	info->ret_code = RPMB_CMD_GET_DEV_INFO_RET_OK;
+
+	return TEEC_SUCCESS;
+}
+
+static u32 rpmb_process_request(struct tee_context *ctx, void *req,
+				ulong req_size, void *rsp, ulong rsp_size)
+{
+	struct rpmb_req *sreq = req;
+	struct mci *mci;
+
+	if (req_size < sizeof(*sreq))
+		return TEEC_ERROR_BAD_PARAMETERS;
+
+	mci = mci_get_rpmb_dev(sreq->dev_id);
+	if (!mci) {
+		pr_err_once("Cannot find RPMB MMC with id %u\n", sreq->dev_id);
+		return TEEC_ERROR_ITEM_NOT_FOUND;
+	}
+
+	switch (sreq->cmd) {
+	case RPMB_CMD_DATA_REQ:
+		if (mci_rpmb_route_frames(mci, RPMB_REQ_DATA(req),
+					  req_size - sizeof(struct rpmb_req),
+					  rsp, rsp_size))
+			return TEEC_ERROR_BAD_PARAMETERS;
+		return TEEC_SUCCESS;
+
+	case RPMB_CMD_GET_DEV_INFO:
+		if (rsp_size != sizeof(struct rpmb_dev_info)) {
+			pr_debug("Invalid req/rsp size\n");
+			return TEEC_ERROR_BAD_PARAMETERS;
+		}
+
+		return rpmb_get_dev_info(mci, rsp);
+
+	default:
+		pr_debug("Unsupported RPMB command: %d\n", sreq->cmd);
+		return TEEC_ERROR_BAD_PARAMETERS;
+	}
+}
+
+void optee_suppl_cmd_rpmb(struct tee_context *ctx, struct optee_msg_arg *arg)
+{
+	struct tee_shm *req_shm;
+	struct tee_shm *rsp_shm;
+	void *req_buf;
+	void *rsp_buf;
+	ulong req_size;
+	ulong rsp_size;
+
+	if (arg->num_params != 2 ||
+	    arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_RMEM_INPUT ||
+	    arg->params[1].attr != OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT) {
+		arg->ret = TEEC_ERROR_BAD_PARAMETERS;
+		return;
+	}
+
+	req_shm = (struct tee_shm *)(ulong)arg->params[0].u.rmem.shm_ref;
+	req_buf = (u8 *)req_shm->kaddr + arg->params[0].u.rmem.offs;
+	req_size = arg->params[0].u.rmem.size;
+
+	rsp_shm = (struct tee_shm *)(ulong)arg->params[1].u.rmem.shm_ref;
+	rsp_buf = (u8 *)rsp_shm->kaddr + arg->params[1].u.rmem.offs;
+	rsp_size = arg->params[1].u.rmem.size;
+
+	arg->ret = rpmb_process_request(ctx, req_buf, req_size,
+					rsp_buf, rsp_size);
+}

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 19 08:31:00 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:31:00 +0100
Subject: [PATCH v2 09/10] commands: add avb_pvalue command
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
Message-ID: <20250319-rpmb-v2-9-a8801fb35cd4@pengutronix.de>

Android Verified Boot (AVB( 2.0 spec. revision 1.1 introduces support
for named persistent values that must be tamper evident and allows AVB
to store arbitrary key-value pairs.

This patch introduces a command to access this variable store. Variables
can be read into a file or an environment variable or printed as
hexdump. Variables can be written from file content or a string from the
command line.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/Kconfig      |  13 +++++
 commands/Makefile     |   1 +
 commands/avb_pvalue.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 152 insertions(+)

diff --git a/commands/Kconfig b/commands/Kconfig
index fe459fa862..48fe4f02c2 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2254,6 +2254,19 @@ config CMD_2048
 	help
 	  Console version of the game "2048" for GNU/Linux
 
+config CMD_AVB_PVALUE
+	depends on OPTEE_AVB_PERSISTENT_VALUES
+	tristate
+	prompt "avb_pvalue"
+	help
+	  The avb_pvalue command provides access to the Android Verified Boot (AVB)
+	  persistent value store.
+
+	  AVB 2.0 spec. revision 1.1 introduces support for named persistent values
+	  that must be tamper evident and allows AVB to store arbitrary key-value
+	  pairs.
+
+
 config CMD_BAREBOX_UPDATE
 	tristate
 	select BAREBOX_UPDATE
diff --git a/commands/Makefile b/commands/Makefile
index e152e4148b..7a635e8791 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -3,6 +3,7 @@
 obj-$(CONFIG_STDDEV)		+= stddev.o
 obj-$(CONFIG_CMD_DIGEST)	+= digest.o
 obj-$(CONFIG_COMPILE_HASH)	+= hashsum.o
+obj-$(CONFIG_CMD_AVB_PVALUE)	+= avb_pvalue.o
 obj-$(CONFIG_CMD_BOOTM)		+= bootm.o
 obj-$(CONFIG_CMD_UIMAGE)	+= uimage.o
 obj-$(CONFIG_CMD_LOADB)		+= loadb.o
diff --git a/commands/avb_pvalue.c b/commands/avb_pvalue.c
new file mode 100644
index 0000000000..adc44321fb
--- /dev/null
+++ b/commands/avb_pvalue.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <command.h>
+#include <getopt.h>
+#include <libfile.h>
+#include <fs.h>
+#include <xfuncs.h>
+#include <linux/sizes.h>
+#include <tee/avb.h>
+#include <linux/ctype.h>
+#include <environment.h>
+
+static int do_avb_pvalue(int argc, char *argv[])
+{
+	size_t out = 0x13;
+	void *buf = NULL;
+	int ret = 0, rc = COMMAND_ERROR;
+	int opt;
+	const char *write_varname = NULL, *read_varname = NULL;
+	void *val = NULL;
+	size_t size;
+	const char *filename = NULL;
+	const char *varname = NULL;
+	const int bufsize = SZ_8K;
+
+	while ((opt = getopt(argc, argv, "r:w:f:")) > 0) {
+		switch(opt) {
+		case 'r':
+			read_varname = optarg;
+			break;
+		case 'w':
+			write_varname = optarg;
+			break;
+		case 'f':
+			filename = optarg;
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	argc -= optind;
+	argv += optind;
+
+	if (!read_varname && !write_varname)
+		return COMMAND_ERROR_USAGE;
+
+	if (read_varname && write_varname)
+		return COMMAND_ERROR_USAGE;
+
+	if (write_varname) {
+		if (argc >= 1)
+			val = argv[0];
+
+		if (filename) {
+			ret = read_file_2(filename, &size, &buf, FILESIZE_MAX);
+			if (ret) {
+				printf("Cannot read %s: %pe\n", read_varname, ERR_PTR(ret));
+				return COMMAND_ERROR;
+			}
+		} else {
+			if (!val)
+				return COMMAND_ERROR_USAGE;
+			size = strlen(val) + 1;
+			buf = xstrdup(val);
+
+		}
+		ret = avb_write_persistent_value(write_varname, size, buf);
+		if (ret) {
+			printf("Cannot write variable %s: %pe\n", read_varname, ERR_PTR(ret));
+			goto err;
+		}
+	}
+
+	if (read_varname) {
+		if (argc >= 1)
+			varname = argv[0];
+
+		buf = xzalloc(bufsize);
+
+		ret = avb_read_persistent_value(read_varname, SZ_8K, buf, &out);
+		if (ret) {
+			printf("Cannot read variable %s: %pe\n", read_varname, ERR_PTR(ret));
+			rc = COMMAND_ERROR;
+			goto err;
+		}
+
+		if (filename) {
+			ret = write_file(filename, buf, out);
+			if (ret) {
+				printf("Cannot write %s: %pe\n", filename, ERR_PTR(ret));
+				rc = COMMAND_ERROR;
+				goto err;
+			}
+		} else if (varname) {
+			unsigned char *str = buf;
+			int i;
+
+			str[bufsize - 1] = 0;
+	
+			for (i = 0; i < out; i++)
+				if (!isprint(str[i]))
+					break;
+
+			str[i] = 0;
+
+			setenv(varname, buf);
+		} else {
+			memory_display(buf, 0, out, 1, 0);
+		}
+	}
+
+	rc = 0;
+
+err:
+	free(buf);
+
+	return rc;
+}
+
+BAREBOX_CMD_HELP_START(avb_pvalue)
+BAREBOX_CMD_HELP_TEXT("This command provides access to the AVB persistent variable store.")
+BAREBOX_CMD_HELP_TEXT("usage:")
+BAREBOX_CMD_HELP_TEXT("avb_pvalue [OPTION]... [VARNAME/VALUE]")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-r <varname>",  "read variable <varname>. read value into [VARNAME] if given")
+BAREBOX_CMD_HELP_OPT ("-w <varname>",  "write variable <varname>. Set to [VALUE] if given")
+BAREBOX_CMD_HELP_OPT ("-f <file>",  "read/write value from/to file")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(avb_pvalue)
+	.cmd            = do_avb_pvalue,
+	BAREBOX_CMD_DESC("AVB persistent variable store")
+	BAREBOX_CMD_OPTS("[-rwf] [VARNAME/VALUE]")
+	BAREBOX_CMD_HELP(cmd_avb_pvalue_help)
+	BAREBOX_CMD_GROUP(CMD_GRP_CONSOLE)
+BAREBOX_CMD_END

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 19 08:30:57 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:30:57 +0100
Subject: [PATCH v2 06/10] tee: optee: implement shared mem alloc/free RPC
 commands
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
Message-ID: <20250319-rpmb-v2-6-a8801fb35cd4@pengutronix.de>

This implements the OPTEE_RPC_CMD_SHM_ALLOC and OPTEE_RPC_CMD_SHM_FREE
commands to let the secure world allocate and free shared memory.

When OP-TEE calls into the nonsecure world in order to allocate shared
memory we'll need a list of pages returned to the secure world. This
is needed in two cases: once when we call into OP-TEE to register the
shared memory with OP-TEE and once in the return parameters of the
OPTEE_RPC_CMD_SHM_ALLOC RPC call. The U-Boot code this code is based on
allocates two separate page lists. In barebox we attach the page list
to the shared memory object instead so that we have to allocate and
initialize it only once.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/tee/optee/optee_private.h |   3 +
 drivers/tee/optee/optee_rpc_cmd.h | 144 ++++++++++++++++++++++++++++++++++++++
 drivers/tee/optee/rpc.c           |  60 +++++++++++++++-
 drivers/tee/optee/smc_abi.c       |  26 ++++---
 drivers/tee/tee_shm.c             |   1 +
 include/linux/tee_drv.h           |   1 +
 6 files changed, 222 insertions(+), 13 deletions(-)

diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h
index 637d3195be..d739a6c609 100644
--- a/drivers/tee/optee/optee_private.h
+++ b/drivers/tee/optee/optee_private.h
@@ -17,7 +17,10 @@
 
 /* Some Global Platform error codes used in this driver */
 #define TEEC_SUCCESS			0x00000000
+#define TEEC_ERROR_GENERIC		0xffff0000
 #define TEEC_ERROR_BAD_PARAMETERS	0xFFFF0006
+#define TEEC_ERROR_ITEM_NOT_FOUND	0xffff0008
+#define TEEC_ERROR_NOT_IMPLEMENTED	0xFFFF0009
 #define TEEC_ERROR_NOT_SUPPORTED	0xFFFF000A
 #define TEEC_ERROR_COMMUNICATION	0xFFFF000E
 #define TEEC_ERROR_OUT_OF_MEMORY	0xFFFF000C
diff --git a/drivers/tee/optee/optee_rpc_cmd.h b/drivers/tee/optee/optee_rpc_cmd.h
new file mode 100644
index 0000000000..3ef5672be7
--- /dev/null
+++ b/drivers/tee/optee/optee_rpc_cmd.h
@@ -0,0 +1,144 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Copyright (c) 2016-2021, Linaro Limited
+ */
+
+#ifndef __OPTEE_RPC_CMD_H
+#define __OPTEE_RPC_CMD_H
+
+/*
+ * All RPC is done with a struct optee_msg_arg as bearer of information,
+ * struct optee_msg_arg::arg holds values defined by OPTEE_RPC_CMD_* below.
+ * Only the commands handled by the kernel driver are defined here.
+ *
+ * RPC communication with tee-supplicant is reversed compared to normal
+ * client communication described above. The supplicant receives requests
+ * and sends responses.
+ */
+
+#define OPTEE_RPC_CMD_RPMB		1
+
+/*
+ * Get time
+ *
+ * Returns number of seconds and nano seconds since the Epoch,
+ * 1970-01-01 00:00:00 +0000 (UTC).
+ *
+ * [out]    value[0].a	    Number of seconds
+ * [out]    value[0].b	    Number of nano seconds.
+ */
+#define OPTEE_RPC_CMD_GET_TIME		3
+
+/*
+ * Notification from/to secure world.
+ *
+ * If secure world needs to wait for something, for instance a mutex, it
+ * does a notification wait request instead of spinning in secure world.
+ * Conversely can a synchronous notification can be sent when a secure
+ * world mutex with a thread waiting thread is unlocked.
+ *
+ * This interface can also be used to wait for a asynchronous notification
+ * which instead is sent via a non-secure interrupt.
+ *
+ * Waiting on notification
+ * [in]    value[0].a	    OPTEE_RPC_NOTIFICATION_WAIT
+ * [in]    value[0].b	    notification value
+ * [in]    value[0].c	    timeout in milliseconds or 0 if no timeout
+ *
+ * Sending a synchronous notification
+ * [in]    value[0].a	    OPTEE_RPC_NOTIFICATION_SEND
+ * [in]    value[0].b	    notification value
+ */
+#define OPTEE_RPC_CMD_NOTIFICATION	4
+#define OPTEE_RPC_NOTIFICATION_WAIT	0
+#define OPTEE_RPC_NOTIFICATION_SEND	1
+
+/*
+ * Suspend execution
+ *
+ * [in]    value[0].a	Number of milliseconds to suspend
+ */
+#define OPTEE_RPC_CMD_SUSPEND		5
+
+/*
+ * Allocate a piece of shared memory
+ *
+ * [in]    value[0].a	    Type of memory one of
+ *			    OPTEE_RPC_SHM_TYPE_* below
+ * [in]    value[0].b	    Requested size
+ * [in]    value[0].c	    Required alignment
+ * [out]   memref[0]	    Buffer
+ */
+#define OPTEE_RPC_CMD_SHM_ALLOC		6
+/* Memory that can be shared with a non-secure user space application */
+#define OPTEE_RPC_SHM_TYPE_APPL		0
+/* Memory only shared with non-secure kernel */
+#define OPTEE_RPC_SHM_TYPE_KERNEL	1
+
+/*
+ * Free shared memory previously allocated with OPTEE_RPC_CMD_SHM_ALLOC
+ *
+ * [in]     value[0].a	    Type of memory one of
+ *			    OPTEE_RPC_SHM_TYPE_* above
+ * [in]     value[0].b	    Value of shared memory reference or cookie
+ */
+#define OPTEE_RPC_CMD_SHM_FREE		7
+
+/*
+ * Issue master requests (read and write operations) to an I2C chip.
+ *
+ * [in]     value[0].a	    Transfer mode (OPTEE_RPC_I2C_TRANSFER_*)
+ * [in]     value[0].b	    The I2C bus (a.k.a adapter).
+ *				16 bit field.
+ * [in]     value[0].c	    The I2C chip (a.k.a address).
+ *				16 bit field (either 7 or 10 bit effective).
+ * [in]     value[1].a	    The I2C master control flags (ie, 10 bit address).
+ *				16 bit field.
+ * [in/out] memref[2]	    Buffer used for data transfers.
+ * [out]    value[3].a	    Number of bytes transferred by the REE.
+ */
+#define OPTEE_RPC_CMD_I2C_TRANSFER	21
+
+/* I2C master transfer modes */
+#define OPTEE_RPC_I2C_TRANSFER_RD	0
+#define OPTEE_RPC_I2C_TRANSFER_WR	1
+
+/* I2C master control flags */
+#define OPTEE_RPC_I2C_FLAGS_TEN_BIT	BIT(0)
+
+/*
+ * Reset RPMB probing
+ *
+ * Releases an eventually already used RPMB devices and starts over searching
+ * for RPMB devices. Returns the kind of shared memory to use in subsequent
+ * OPTEE_RPC_CMD_RPMB_PROBE_NEXT and OPTEE_RPC_CMD_RPMB calls.
+ *
+ * [out]    value[0].a	    OPTEE_RPC_SHM_TYPE_*, the parameter for
+ *			    OPTEE_RPC_CMD_SHM_ALLOC
+ */
+#define OPTEE_RPC_CMD_RPMB_PROBE_RESET	22
+
+/*
+ * Probe next RPMB device
+ *
+ * [out]    value[0].a	    Type of RPMB device, OPTEE_RPC_RPMB_*
+ * [out]    value[0].b	    EXT CSD-slice 168 "RPMB Size"
+ * [out]    value[0].c	    EXT CSD-slice 222 "Reliable Write Sector Count"
+ * [out]    memref[1]       Buffer with the raw CID
+ */
+#define OPTEE_RPC_CMD_RPMB_PROBE_NEXT	23
+
+/* Type of RPMB device */
+#define OPTEE_RPC_RPMB_EMMC		0
+#define OPTEE_RPC_RPMB_UFS		1
+#define OPTEE_RPC_RPMB_NVME		2
+
+/*
+ * Replay Protected Memory Block access
+ *
+ * [in]     memref[0]	    Frames to device
+ * [out]    memref[1]	    Frames from device
+ */
+#define OPTEE_RPC_CMD_RPMB_FRAMES	24
+
+#endif /*__OPTEE_RPC_CMD_H*/
diff --git a/drivers/tee/optee/rpc.c b/drivers/tee/optee/rpc.c
index 3d0a7f2980..bdb2a9da74 100644
--- a/drivers/tee/optee/rpc.c
+++ b/drivers/tee/optee/rpc.c
@@ -7,10 +7,66 @@
 
 #include <linux/tee_drv.h>
 #include "optee_private.h"
+#include "optee_rpc_cmd.h"
+
+static void cmd_shm_alloc(struct tee_context *ctx, struct optee_msg_arg *arg)
+{
+	struct tee_shm *shm;
+
+	arg->ret_origin = TEEC_ORIGIN_COMMS;
+
+	if (arg->num_params != 1 ||
+	    arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_INPUT) {
+		arg->ret = TEEC_ERROR_BAD_PARAMETERS;
+		return;
+	}
+
+	shm = tee_shm_alloc_kernel_buf(ctx, arg->params[0].u.value.b);
+	if (IS_ERR(shm)) {
+		if (PTR_ERR(shm) == -ENOMEM)
+			arg->ret = TEEC_ERROR_OUT_OF_MEMORY;
+		else
+			arg->ret = TEEC_ERROR_GENERIC;
+		return;
+	}
+
+	arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT |
+			      OPTEE_MSG_ATTR_NONCONTIG;
+	arg->params[0].u.tmem.buf_ptr = virt_to_phys(shm->pages_list);
+	arg->params[0].u.tmem.size = shm->size;
+	arg->params[0].u.tmem.shm_ref = (ulong)shm;
+	arg->ret = TEEC_SUCCESS;
+}
+
+static void cmd_shm_free(struct optee_msg_arg *arg)
+{
+	arg->ret_origin = TEEC_ORIGIN_COMMS;
+
+	if (arg->num_params != 1 ||
+	    arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_INPUT) {
+		arg->ret = TEEC_ERROR_BAD_PARAMETERS;
+		return;
+	}
+
+	tee_shm_free((struct tee_shm *)(ulong)arg->params[0].u.value.b);
+	arg->ret = TEEC_SUCCESS;
+}
 
 void optee_rpc_cmd(struct tee_context *ctx, struct optee *optee,
 		   struct optee_msg_arg *arg)
 {
-	pr_notice_once("optee: No supplicant or RPC handler for command 0x%x\n", arg->cmd);
-	arg->ret = TEEC_ERROR_NOT_SUPPORTED;
+	pr_debug("%s: receive RPC CMD: %d\n", __func__, arg->cmd);
+
+	switch (arg->cmd) {
+	case OPTEE_RPC_CMD_SHM_ALLOC:
+		cmd_shm_alloc(ctx, arg);
+		break;
+	case OPTEE_RPC_CMD_SHM_FREE:
+		cmd_shm_free(arg);
+		break;
+	default:
+		arg->ret = TEEC_ERROR_NOT_IMPLEMENTED;
+	}
+
+	arg->ret_origin = TEEC_ORIGIN_COMMS;
 }
diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c
index 354a94a2f2..aab8ebb186 100644
--- a/drivers/tee/optee/smc_abi.c
+++ b/drivers/tee/optee/smc_abi.c
@@ -301,7 +301,7 @@ static int optee_shm_register(struct tee_context *ctx, struct tee_shm *shm)
 	struct tee_shm *shm_arg;
 	u64 *pages_list;
 	u64 ph_ptr;
-	int rc = 0;
+	int rc;
 
 	pages_list = optee_alloc_and_init_page_list(shm->kaddr, shm->size, &ph_ptr);
 	if (!pages_list)
@@ -314,7 +314,7 @@ static int optee_shm_register(struct tee_context *ctx, struct tee_shm *shm)
 	msg_arg = optee_get_msg_arg(ctx, 1, &shm_arg);
 	if (IS_ERR(msg_arg)) {
 		rc = PTR_ERR(msg_arg);
-		goto free_pages_list;
+		goto err_free;
 	}
 
 	msg_arg->num_params = 1;
@@ -326,11 +326,20 @@ static int optee_shm_register(struct tee_context *ctx, struct tee_shm *shm)
 	msg_arg->params->u.tmem.size = tee_shm_get_size(shm);
 
 	if (optee->ops->do_call_with_arg(ctx, msg_arg) ||
-	    msg_arg->ret != TEEC_SUCCESS)
+	    msg_arg->ret != TEEC_SUCCESS) {
 		rc = -EINVAL;
+		goto err_free_msg_arg;
+	}
+
+	optee_free_msg_arg(ctx, shm_arg);
+
+	shm->pages_list = pages_list;
 
+	return 0;
+
+err_free_msg_arg:
 	optee_free_msg_arg(ctx, shm_arg);
-free_pages_list:
+err_free:
 	free(pages_list);
 
 	return rc;
@@ -383,8 +392,7 @@ static int optee_shm_unregister(struct tee_context *ctx, struct tee_shm *shm)
  *
  * Result of RPC is written back into @param.
  */
-static void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param,
-			     void *page_list)
+static void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param)
 {
 	struct tee_device *teedev = ctx->teedev;
 	struct optee *optee = tee_get_drvdata(teedev);
@@ -448,7 +456,6 @@ static int optee_smc_do_call_with_arg(struct tee_context *ctx,
 {
 	struct optee *optee = tee_get_drvdata(ctx->teedev);
 	struct optee_rpc_param param = { .a0 = OPTEE_SMC_CALL_WITH_ARG };
-	void *page_list = NULL;
 
 	reg_pair_from_64(&param.a1, &param.a2, virt_to_phys(arg));
 	while (true) {
@@ -461,15 +468,12 @@ static int optee_smc_do_call_with_arg(struct tee_context *ctx,
 		optee->smc.invoke_fn(param.a0, param.a1, param.a2, param.a3,
 				     param.a4, param.a5, param.a6, param.a7, &res);
 
-		free(page_list);
-		page_list = NULL;
-
 		if (OPTEE_SMC_RETURN_IS_RPC(res.a0)) {
 			param.a0 = res.a0;
 			param.a1 = res.a1;
 			param.a2 = res.a2;
 			param.a3 = res.a3;
-			optee_handle_rpc(ctx, &param, &page_list);
+			optee_handle_rpc(ctx, &param);
 		} else {
 			return res.a0;
 		}
diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
index 9952608435..50ed086d0e 100644
--- a/drivers/tee/tee_shm.c
+++ b/drivers/tee/tee_shm.c
@@ -32,6 +32,7 @@ static void tee_shm_release(struct tee_device *teedev, struct tee_shm *shm)
 
 	teedev_ctx_put(shm->ctx);
 
+	kfree(shm->pages_list);
 	kfree(shm);
 
 	tee_device_put(teedev);
diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h
index 7289c3057a..e2c1042deb 100644
--- a/include/linux/tee_drv.h
+++ b/include/linux/tee_drv.h
@@ -194,6 +194,7 @@ struct tee_shm {
 	struct tee_context *ctx;
 	phys_addr_t paddr;
 	void *kaddr;
+	u64 *pages_list;
 	size_t size;
 	refcount_t refcount;
 	u32 flags;

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 19 08:30:53 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:30:53 +0100
Subject: [PATCH v2 02/10] mci: export some functions for RPMB support
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
Message-ID: <20250319-rpmb-v2-2-a8801fb35cd4@pengutronix.de>

Export mci_send_cmd() and mci_blk_part_switch() in preparation for
adding RPMB support.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 4 ++--
 include/mci.h          | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 6d8140f7b0..b7ea0df3cb 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -68,7 +68,7 @@ static inline unsigned mci_caps(struct mci *mci)
  * @param data The data according to the command (can be NULL)
  * @return Driver's answer (0 on success)
  */
-static int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data)
+int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data)
 {
 	struct mci_host *host = mci->host;
 
@@ -2030,7 +2030,7 @@ static int sd_send_if_cond(struct mci *mci)
 /**
  * Switch between hardware MMC partitions on demand
  */
-static int mci_blk_part_switch(struct mci_part *part)
+int mci_blk_part_switch(struct mci_part *part)
 {
 	struct mci *mci = part->mci;
 	int ret;
diff --git a/include/mci.h b/include/mci.h
index c6ee6ea50f..8084df813a 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -729,6 +729,8 @@ int mci_execute_tuning(struct mci *mci);
 int mci_send_abort_tuning(struct mci *mci, u32 opcode);
 int mmc_select_timing(struct mci *mci);
 int mci_set_blockcount(struct mci *mci, unsigned int cmdarg);
+int mci_blk_part_switch(struct mci_part *part);
+int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data);
 
 static inline bool mmc_card_hs200(struct mci *mci)
 {

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 19 08:30:59 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:30:59 +0100
Subject: [PATCH v2 08/10] tee: optee: implement AVB named persistent values
 support
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
Message-ID: <20250319-rpmb-v2-8-a8801fb35cd4@pengutronix.de>

Android Verified Boot (AVB) 2.0 spec. revision 1.1 introduces support
for named persistent values that must be tamper evident and allows AVB
to store arbitrary key-value pairs.

While AVB itself is not implemented in barebox. this patch allows
barebox to access the persistent value store. This is useful on its
own and can also be used to test the RPMB access in barebox.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/tee/optee/Kconfig  |   9 +++
 drivers/tee/optee/Makefile |   1 +
 drivers/tee/optee/avb.c    | 189 +++++++++++++++++++++++++++++++++++++++++++++
 include/tee/avb.h          |   9 +++
 4 files changed, 208 insertions(+)

diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig
index 045be3cca4..805aba65ed 100644
--- a/drivers/tee/optee/Kconfig
+++ b/drivers/tee/optee/Kconfig
@@ -31,6 +31,15 @@ config OPTEE_DEVFS
 	  but it's useful for compiling libteeclient + optee_tests for
 	  use inside barebox to verify proper operation of CONFIG_OPTEE.
 
+config OPTEE_AVB_PERSISTENT_VALUES
+	bool "Android Verified Boot (AVB) persistent values support"
+	depends on OPTEE
+	help
+	  AVB 2.0 spec. revision 1.1 introduces support for named persistent values
+	  that must be tamper evident and allows AVB to store arbitrary key-value
+	  pairs. AVB itself is not implemented in barebox, but enabling this option
+	  allows barebox to use the AVB persistent value store.
+
 endif
 
 config OF_FIXUP_OPTEE
diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile
index f68352aa4e..1fbeb39fb8 100644
--- a/drivers/tee/optee/Makefile
+++ b/drivers/tee/optee/Makefile
@@ -7,3 +7,4 @@ optee-objs += rpc.o
 optee-objs += device.o
 optee-objs += smc_abi.o
 obj-$(CONFIG_MCI_MMC_RPMB) += rpmb.o
+obj-$(CONFIG_OPTEE_AVB_PERSISTENT_VALUES) += avb.o
diff --git a/drivers/tee/optee/avb.c b/drivers/tee/optee/avb.c
new file mode 100644
index 0000000000..0adbee6258
--- /dev/null
+++ b/drivers/tee/optee/avb.c
@@ -0,0 +1,189 @@
+#include <linux/types.h>
+#include <tee/avb.h>
+#include <linux/tee_drv.h>
+
+#include "optee_private.h"
+
+#define TA_AVB_UUID UUID_INIT(0x023f8f1a, 0x292a, 0x432b, \
+                      0x8f, 0xc4, 0xde, 0x84, 0x71, 0x35, 0x80, 0x67)
+#define TEE_PARAM_ATTR_TYPE_MEMREF_INOUT       7       /* input and output */
+#define TA_AVB_CMD_READ_PERSIST_VALUE     4
+#define TEE_PARAM_ATTR_TYPE_MEMREF_INPUT       5
+#define TA_AVB_CMD_WRITE_PERSIST_VALUE    5
+
+static int optee_ctx_match(struct tee_ioctl_version_data *ver, const void *data)
+{
+	if (ver->impl_id == TEE_IMPL_ID_OPTEE)
+		return 1;
+	else
+		return 0;
+}
+
+int avb_read_persistent_value(const char *name, size_t buffer_size,
+			      u8 *out_buffer, size_t *out_num_bytes_read)
+{
+	const uuid_t avb_uuid = TA_AVB_UUID;
+	int rc = 0;
+	struct tee_shm *shm_name;
+	struct tee_shm *shm_buf;
+	struct tee_param param[2];
+	size_t name_size = strlen(name) + 1;
+	struct tee_ioctl_open_session_arg sess_arg = {};
+	struct tee_context *ctx = NULL;
+	struct tee_ioctl_invoke_arg arg;
+
+	ctx = tee_client_open_context(NULL, optee_ctx_match, NULL, NULL);
+	if (IS_ERR(ctx))
+		return -ENODEV;
+
+	export_uuid(sess_arg.uuid, &avb_uuid);
+	sess_arg.clnt_login = TEE_IOCTL_LOGIN_PUBLIC;
+	sess_arg.num_params = 0;
+
+	rc = tee_client_open_session(ctx, &sess_arg, NULL);
+	if ((rc < 0) || (sess_arg.ret != TEEC_SUCCESS)) {
+		pr_debug("%s device enumeration pseudo TA not found\n", __func__);
+		rc = 0;
+		goto out_ctx;
+	}
+
+	shm_name = tee_shm_alloc_kernel_buf(ctx, name_size);
+	if (IS_ERR(shm_name)) {
+		rc = -ENOMEM;
+		goto close_session;
+	}
+
+	shm_buf = tee_shm_alloc_kernel_buf(ctx, buffer_size);
+	if (IS_ERR(shm_buf)) {
+		rc = -ENOMEM;
+		goto free_name;
+	}
+
+	memcpy(shm_name->kaddr, name, name_size);
+
+	memset(param, 0, sizeof(param));
+	param[0].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INPUT;
+	param[0].u.memref.shm = shm_name;
+	param[0].u.memref.size = name_size;
+	param[1].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INOUT;
+	param[1].u.memref.shm = shm_buf;
+	param[1].u.memref.size = buffer_size;
+
+	arg.func = TA_AVB_CMD_READ_PERSIST_VALUE;
+	arg.session = sess_arg.session;
+	arg.num_params = 2;
+
+	rc = tee_client_invoke_func(ctx, &arg, param);
+	if (rc)
+		goto out;
+	switch (arg.ret) {
+	case TEEC_SUCCESS:
+		rc = 0;
+		break;
+	case TEEC_ERROR_ITEM_NOT_FOUND:
+		rc = -ENOENT;
+		break;
+	default:
+		rc = -EINVAL;
+		break;
+	}
+	if (rc)
+		goto out;
+
+	if (param[1].u.memref.size > buffer_size) {
+		rc = -EINVAL;
+		goto out;
+	}
+
+	*out_num_bytes_read = param[1].u.memref.size;
+
+	memcpy(out_buffer, shm_buf->kaddr, *out_num_bytes_read);
+
+out:
+	tee_shm_free(shm_buf);
+free_name:
+	tee_shm_free(shm_name);
+close_session:
+	tee_client_close_session(ctx, sess_arg.session);
+out_ctx:
+	tee_client_close_context(ctx);
+
+	return rc;
+}
+
+int avb_write_persistent_value(const char *name, size_t value_size,
+			       const u8 *value)
+{
+	const uuid_t avb_uuid = TA_AVB_UUID;
+	int rc = 0;
+	struct tee_shm *shm_name;
+	struct tee_shm *shm_buf;
+	struct tee_param param[2];
+	struct tee_ioctl_open_session_arg sess_arg = {};
+	struct tee_context *ctx = NULL;
+	size_t name_size = strlen(name) + 1;
+	struct tee_ioctl_invoke_arg inv_arg;
+
+	if (!value_size)
+		return -EINVAL;
+
+	ctx = tee_client_open_context(NULL, optee_ctx_match, NULL, NULL);
+	if (IS_ERR(ctx))
+		return -ENODEV;
+
+	export_uuid(sess_arg.uuid, &avb_uuid);
+	sess_arg.clnt_login = TEE_IOCTL_LOGIN_PUBLIC;
+	sess_arg.num_params = 0;
+
+	rc = tee_client_open_session(ctx, &sess_arg, NULL);
+	if ((rc < 0) || (sess_arg.ret != TEEC_SUCCESS)) {
+		pr_err("%s AVB TA not found\n", __func__);
+		goto out_ctx;
+	}
+
+	shm_name = tee_shm_alloc_kernel_buf(ctx, name_size);
+	if (IS_ERR(shm_name)) {
+		rc = -ENOMEM;
+		goto close_session;
+	}
+
+	shm_buf = tee_shm_alloc_kernel_buf(ctx, value_size);
+	if (IS_ERR(shm_buf)) {
+		rc = -ENOMEM;
+		goto free_name;
+	}
+
+	memcpy(shm_name->kaddr, name, name_size);
+	memcpy(shm_buf->kaddr, value, value_size);
+
+	memset(param, 0, sizeof(param));
+	param[0].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INPUT;
+	param[0].u.memref.shm = shm_name;
+	param[0].u.memref.size = name_size;
+	param[1].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INPUT;
+	param[1].u.memref.shm = shm_buf;
+	param[1].u.memref.size = value_size;
+
+	inv_arg.func = TA_AVB_CMD_WRITE_PERSIST_VALUE;
+	inv_arg.session = sess_arg.session;
+	inv_arg.num_params = 2;
+
+	rc = tee_client_invoke_func(ctx, &inv_arg, param);
+	if (rc)
+		goto out;
+	if (inv_arg.ret) {
+		pr_err("invoke func failed with 0x%08x\n", inv_arg.ret);
+		rc = -EIO;
+	}
+
+out:
+	tee_shm_free(shm_buf);
+free_name:
+	tee_shm_free(shm_name);
+close_session:
+	tee_client_close_session(ctx, sess_arg.session);
+out_ctx:
+	tee_client_close_context(ctx);
+
+	return rc;
+}
diff --git a/include/tee/avb.h b/include/tee/avb.h
new file mode 100644
index 0000000000..3873b5c59b
--- /dev/null
+++ b/include/tee/avb.h
@@ -0,0 +1,9 @@
+#ifndef TEE_AVB_H
+#define TEE_AVB_H
+
+int avb_write_persistent_value(const char *name, size_t value_size,
+			       const u8 *value);
+int avb_read_persistent_value(const char *name, size_t buffer_size,
+			      u8 *out_buffer, size_t *out_num_bytes_read);
+
+#endif /* TEE_AVB_H */

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 19 08:30:55 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:30:55 +0100
Subject: [PATCH v2 04/10] mci: add RPMB support
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
Message-ID: <20250319-rpmb-v2-4-a8801fb35cd4@pengutronix.de>

This implements the MMC specific part to access RPMB partitions:

- Provide a function to find a RPMB capable eMMC
- partition switching to the RPMB partition
- Dissecting the OP-TEE requests into the correspnding MMC read/write
  multiblock commands

For now we only support a single eMMC RPMB partition per board. This is
the 99% case, but there might be systems with multiple eMMCs. The OP-TEE
protocol has a dev_id field to support multiple eMMCs, but OP-TEE itself
currently only supports a single RPMB. This means we really only need to
support one eMMC, but should there be multiple eMMCs on a system we will
need a way for the user to specify which one shall be used. As of now
the first one found will be used.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/Kconfig    |   3 +
 drivers/mci/Makefile   |   1 +
 drivers/mci/mci-core.c |  37 +++++++--
 drivers/mci/rpmb.c     | 210 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/mci.h          |   5 ++
 5 files changed, 251 insertions(+), 5 deletions(-)

diff --git a/drivers/mci/Kconfig b/drivers/mci/Kconfig
index 4641e9cdcd..09648aa771 100644
--- a/drivers/mci/Kconfig
+++ b/drivers/mci/Kconfig
@@ -68,6 +68,9 @@ config MCI_MMC_GPP_PARTITIONS
 	  Note: by default, 'MMC' devices have no 'general purpose partitions',
 	  it requires a special one-time configuration step to enable them.
 
+config MCI_MMC_RPMB
+	bool "Support eMMC replay protected memory block (RPMB)"
+
 comment "--- MCI host drivers ---"
 
 config MCI_DWC_MSHC
diff --git a/drivers/mci/Makefile b/drivers/mci/Makefile
index 5e951d695f..d3df4c1bb6 100644
--- a/drivers/mci/Makefile
+++ b/drivers/mci/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_MCI)		+= mci-core.o
+obj-$(CONFIG_MCI_MMC_RPMB)	+= rpmb.o
 obj-$(CONFIG_MCI_AM654)		+= am654-sdhci.o
 obj-$(CONFIG_MCI_ARASAN)	+= arasan-sdhci.o
 obj-$(CONFIG_MCI_ATMEL)		+= atmel_mci.o atmel_mci_common.o
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 3bf0f15def..48bdd1a0c7 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -2052,7 +2052,9 @@ int mci_blk_part_switch(struct mci_part *part)
 	struct mci *mci = part->mci;
 	int ret;
 
-	if (!IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) && !IS_ENABLED(CONFIG_MCI_MMC_GPP_PARTITIONS))
+	if (!IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) &&
+	    !IS_ENABLED(CONFIG_MCI_MMC_GPP_PARTITIONS) &&
+	    !IS_ENABLED(CONFIG_MCI_MMC_RPMB))
 		return 0; /* no need */
 
 	if (mci->part_curr == part)
@@ -2953,7 +2955,6 @@ void mci_of_parse_node(struct mci_host *host,
 {
 	u32 bus_width;
 	u32 dsr_val;
-	const char *alias;
 
 	if (!IS_ENABLED(CONFIG_OFDEVICE))
 		return;
@@ -2961,9 +2962,14 @@ void mci_of_parse_node(struct mci_host *host,
 	if (!host->hw_dev || !np)
 		return;
 
-	alias = of_alias_get(np);
-	if (alias)
-		host->devname = xstrdup(alias);
+	host->of_id = of_alias_get_id(np, "mmc");
+	if (host->of_id < 0)
+		host->of_id = of_alias_get_id(np->parent, "mmc");
+
+	if (host->of_id >= 0) {
+		host->devname = xasprintf("mmc%u", host->of_id);
+		host->of_id_valid = true;
+	}
 
 	/* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */
 	if (of_property_read_u32(np, "bus-width", &bus_width) < 0) {
@@ -3051,3 +3057,24 @@ struct mci *mci_get_device_by_name(const char *name)
 
 	return NULL;
 }
+
+struct mci *mci_get_rpmb_dev(unsigned int id)
+{
+	struct mci *mci;
+
+	list_for_each_entry(mci, &mci_list, list) {
+		if (mci->host->of_id != id)
+			continue;
+
+		mci_detect_card(mci->host);
+
+		if (!mci->rpmb_part) {
+			dev_err(&mci->dev, "requested MMC does not have a RPMB partition\n");
+			return NULL;
+		}
+
+		return mci;
+	}
+
+	return NULL;
+}
diff --git a/drivers/mci/rpmb.c b/drivers/mci/rpmb.c
new file mode 100644
index 0000000000..6c693aa1ea
--- /dev/null
+++ b/drivers/mci/rpmb.c
@@ -0,0 +1,210 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2014, Staubli Faverges
+ * Pierre Aubert
+ *
+ * eMMC- Replay Protected Memory Block
+ * According to JEDEC Standard No. 84-A441
+ */
+#define pr_fmt(fmt) "mmc-rpmb: " fmt
+
+#include <mci.h>
+#include <malloc.h>
+#include <dma.h>
+
+int mmc_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
+			  void *rsp, unsigned long rsplen);
+
+/**
+ * struct rpmb_frame - rpmb frame as defined by eMMC 5.1 (JESD84-B51)
+ *
+ * @stuff        : stuff bytes
+ * @key_mac      : The authentication key or the message authentication
+ *                 code (MAC) depending on the request/response type.
+ *                 The MAC will be delivered in the last (or the only)
+ *                 block of data.
+ * @data         : Data to be written or read by signed access.
+ * @nonce        : Random number generated by the host for the requests
+ *                 and copied to the response by the RPMB engine.
+ * @write_counter: Counter value for the total amount of the successful
+ *                 authenticated data write requests made by the host.
+ * @addr         : Address of the data to be programmed to or read
+ *                 from the RPMB. Address is the serial number of
+ *                 the accessed block (half sector 256B).
+ * @block_count  : Number of blocks (half sectors, 256B) requested to be
+ *                 read/programmed.
+ * @result       : Includes information about the status of the write counter
+ *                 (valid, expired) and result of the access made to the RPMB.
+ * @req_resp     : Defines the type of request and response to/from the memory.
+ *
+ * The stuff bytes and big-endian properties are modeled to fit to the spec.
+ */
+struct rpmb_frame {
+	u8 stuff[196];
+	u8 key_mac[32];
+	u8 data[256];
+	u8 nonce[16];
+	__be32 write_counter;
+	__be16 addr;
+	__be16 block_count;
+	__be16 result;
+	__be16 req_resp;
+} __packed;
+
+#define RPMB_PROGRAM_KEY	0x1	/* Program RPMB Authentication Key */
+#define RPMB_GET_WRITE_COUNTER	0x2	/* Read RPMB write counter */
+#define RPMB_WRITE_DATA		0x3	/* Write data to RPMB partition */
+#define RPMB_READ_DATA		0x4	/* Read data from RPMB partition */
+#define RPMB_RESULT_READ	0x5	/* Read result request  (Internal) */
+
+static int mci_read_write_blocks(struct mci *mci, u32 opcode, int write_flag, void *buf,
+				 unsigned int buf_bytes)
+{
+	int blocks = buf_bytes / 512;
+	struct mci_cmd cmd = {
+		.cmdidx = opcode,
+		.resp_type = MMC_RSP_R1,
+	};
+	struct mci_data data = {
+		.blocks = blocks,
+		.blocksize = sizeof(struct rpmb_frame),
+	};
+	int ret;
+
+	if (write_flag) {
+		data.src = buf;
+		data.flags = MMC_DATA_WRITE;
+	} else {
+		data.dest = buf;
+		data.flags = MMC_DATA_READ;
+	}
+
+	ret = mci_set_blockcount(mci, blocks | (write_flag & MMC_CMD23_ARG_REL_WR));
+	if (ret)
+		return ret;
+
+	return mci_send_cmd(mci, &cmd, &data);
+}
+
+static int rpmb_route_frames(struct mci *mci, void *req,
+			     unsigned int req_len, void *resp,
+			     unsigned int resp_len)
+{
+	struct rpmb_frame *frm = req;
+	unsigned int cmd_count;
+	u16 req_type;
+	bool write;
+	int ret;
+
+	if (req_len < sizeof(*frm))
+		return -EINVAL;
+
+	req_type = be16_to_cpu(frm->req_resp);
+	switch (req_type) {
+	case RPMB_PROGRAM_KEY:
+		if (req_len != sizeof(struct rpmb_frame) ||
+		    resp_len != sizeof(struct rpmb_frame))
+			return -EINVAL;
+		write = true;
+		break;
+	case RPMB_GET_WRITE_COUNTER:
+		if (req_len != sizeof(struct rpmb_frame) ||
+		    resp_len != sizeof(struct rpmb_frame))
+			return -EINVAL;
+		write = false;
+		break;
+	case RPMB_WRITE_DATA:
+		if (req_len % sizeof(struct rpmb_frame) ||
+		    resp_len != sizeof(struct rpmb_frame))
+			return -EINVAL;
+		write = true;
+		break;
+	case RPMB_READ_DATA:
+		if (req_len != sizeof(struct rpmb_frame) ||
+		    resp_len % sizeof(struct rpmb_frame))
+			return -EINVAL;
+		write = false;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (write)
+		cmd_count = 3;
+	else
+		cmd_count = 2;
+
+	if (write) {
+		struct rpmb_frame *frm = resp;
+
+		/* Send write request frame(s) */
+		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK,
+			  1 | MMC_CMD23_ARG_REL_WR, req, req_len);
+		if (ret)
+			goto out;
+
+		/* Send result request frame */
+		memset(frm, 0, sizeof(*frm));
+		frm->req_resp = cpu_to_be16(RPMB_RESULT_READ);
+		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK, 1,
+					    resp, resp_len);
+		if (ret)
+			goto out;
+
+		/* Read response frame */
+		ret = mci_read_write_blocks(mci, MMC_CMD_READ_MULTIPLE_BLOCK, 0,
+					    resp, resp_len);
+		if (ret)
+			goto out;
+	} else {
+		/* Send write request frame(s) */
+		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK, 1,
+					    req, req_len);
+		if (ret)
+			goto out;
+
+		/* Read response frame */
+		ret = mci_read_write_blocks(mci, MMC_CMD_READ_MULTIPLE_BLOCK, 0,
+					    resp, resp_len);
+		if (ret)
+			goto out;
+	}
+out:
+	return ret;
+}
+
+int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
+			  void *rsp, unsigned long rsplen)
+{
+	/*
+	 * Whoever crafted the data supplied to this function knows how to
+	 * format the PRMB frames and which response is expected. If
+	 * there's some unexpected mismatch it's more helpful to report an
+	 * error immediately than trying to guess what was the intention
+	 * and possibly just delay an eventual error which will be harder
+	 * to track down.
+	 */
+	void *rpmb_data;
+	int ret;
+
+	if (!IS_ALIGNED((uintptr_t)rsp, ARCH_DMA_MINALIGN) ||
+	    !IS_ALIGNED(rsplen, ARCH_DMA_MINALIGN)) {
+		pr_err_once("response or length not DMA aligned\n");
+		return -EINVAL;
+	}
+
+	mci_blk_part_switch(mci->rpmb_part);
+
+	/* Memory alignment is required by MMC driver */
+	rpmb_data = dma_alloc(reqlen);
+	if (!rpmb_data)
+		return -ENOMEM;
+
+	memcpy(rpmb_data, req, reqlen);
+
+	ret = rpmb_route_frames(mci, rpmb_data, reqlen, rsp, rsplen);
+
+	free(rpmb_data);
+
+	return ret;
+}
diff --git a/include/mci.h b/include/mci.h
index 08a3e46f7d..43a0b01315 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -554,6 +554,8 @@ struct mci_host {
 	struct device *hw_dev;	/**< the host MCI hardware device */
 	struct mci *mci;
 	const char *devname;		/**< the devicename for the card, defaults to disk%d */
+	int of_id;
+	bool of_id_valid;
 	unsigned voltages;
 	unsigned host_caps;	/**< Host's interface capabilities, refer MMC_VDD_* */
 	unsigned caps2;		/* More host capabilities */
@@ -736,6 +738,9 @@ int mmc_select_timing(struct mci *mci);
 int mci_set_blockcount(struct mci *mci, unsigned int cmdarg);
 int mci_blk_part_switch(struct mci_part *part);
 int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data);
+struct mci *mci_get_rpmb_dev(unsigned int id);
+int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
+			  void *rsp, unsigned long rsplen);
 
 static inline bool mmc_card_hs200(struct mci *mci)
 {

-- 
2.39.5



From s.hauer at pengutronix.de  Wed Mar 19 08:30:52 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:30:52 +0100
Subject: [PATCH v2 01/10] mci: implement mci_set_blockcount()
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
Message-ID: <20250319-rpmb-v2-1-a8801fb35cd4@pengutronix.de>

This adds a function to send a MMC_CMD_SET_BLOCK_COUNT command. This
is not yet needed by barebox as we use open end multiblock transfers,
but will be needed by upcoming RPMB support.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 9 +++++++++
 include/mci.h          | 5 +++++
 2 files changed, 14 insertions(+)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 27a10df9ce..6d8140f7b0 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -311,6 +311,15 @@ static int mci_block_erase(struct mci *card, unsigned int from,
 	return -EIO;
 }
 
+int mci_set_blockcount(struct mci *mci, unsigned int cmdarg)
+{
+	struct mci_cmd cmd = {};
+
+	mci_setup_cmd(&cmd, MMC_CMD_SET_BLOCK_COUNT, cmdarg, MMC_RSP_R1);
+
+	return mci_send_cmd(mci, &cmd, NULL);
+}
+
 static int mci_do_block_op(struct mci *mci, const void *src, void *dst, int blocknum,
 		int blocks)
 {
diff --git a/include/mci.h b/include/mci.h
index f0db1f9ea0..c6ee6ea50f 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -87,12 +87,16 @@
 #define MMC_CMD_READ_MULTIPLE_BLOCK	18
 #define MMC_SEND_TUNING_BLOCK		19   /* adtc R1  */
 #define MMC_SEND_TUNING_BLOCK_HS200	21   /* adtc R1  */
+#define MMC_CMD_SET_BLOCK_COUNT		23
 #define MMC_CMD_WRITE_SINGLE_BLOCK	24
 #define MMC_CMD_WRITE_MULTIPLE_BLOCK	25
 #define MMC_CMD_APP_CMD			55
 #define MMC_CMD_SPI_READ_OCR		58
 #define MMC_CMD_SPI_CRC_ON_OFF		59
 
+#define MMC_CMD23_ARG_BLOCKS	GENMASK(15, 0)
+#define MMC_CMD23_ARG_REL_WR	BIT(31)
+
   /* class 5 */
 #define MMC_ERASE_GROUP_START    35   /* ac   [31:0] data addr   R1  */
 #define MMC_ERASE_GROUP_END      36   /* ac   [31:0] data addr   R1  */
@@ -724,6 +728,7 @@ int mmc_hs200_tuning(struct mci *mci);
 int mci_execute_tuning(struct mci *mci);
 int mci_send_abort_tuning(struct mci *mci, u32 opcode);
 int mmc_select_timing(struct mci *mci);
+int mci_set_blockcount(struct mci *mci, unsigned int cmdarg);
 
 static inline bool mmc_card_hs200(struct mci *mci)
 {

-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 08:34:09 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 19 Mar 2025 16:34:09 +0100
Subject: [PATCH 4/9] mci: add RPMB support
In-Reply-To: <Z9riy3YWmESSdii7@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
 <20250312-rpmb-v1-4-0f213382a3f3@pengutronix.de>
 <9c66b31b-a79c-4a07-a03f-119c7c3dadc7@pengutronix.de>
 <Z9lZ8Q4bhUnuur1X@pengutronix.de> <Z9riy3YWmESSdii7@pengutronix.de>
Message-ID: <29edc564-8919-40d3-b4ac-d0e622a92bcd@pengutronix.de>



On 3/19/25 16:29, Sascha Hauer wrote:
> On Tue, Mar 18, 2025 at 12:33:05PM +0100, Sascha Hauer wrote:
>> On Mon, Mar 17, 2025 at 04:18:32PM +0100, Ahmad Fatoum wrote:
>>> Hello Sascha,
>>>
>>> On 3/12/25 13:16, Sascha Hauer wrote:
>>>> +
>>>> +int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
>>>> +			  void *rsp, unsigned long rsplen)
>>>> +{
>>>> +	/*
>>>> +	 * Whoever crafted the data supplied to this function knows how to
>>>> +	 * format the PRMB frames and which response is expected. If
>>>> +	 * there's some unexpected mismatch it's more helpful to report an
>>>> +	 * error immediately than trying to guess what was the intention
>>>> +	 * and possibly just delay an eventual error which will be harder
>>>> +	 * to track down.
>>>> +	 */
>>>> +	void *rpmb_data = NULL;
>>>> +	int ret;
>>>> +
>>>> +	mci_blk_part_switch(mci->rpmb_part);
>>>> +
>>>> +	if (!IS_ALIGNED((uintptr_t)req, ARCH_DMA_MINALIGN)) {
>>>
>>> Even if alignment happens to be correct, there is no guarantee that
>>> there is no other data sharing a cache line.
>>
>> reqlen is expected to be a single block of 512 bytes, so indeed when req
>> is aligned then the end is cacheline aligned as well. We could check
>> reqlen as well, but I actually never ran into this case, so we can just
>> return an error for now as you suggested.
> 
> I was wrong here. the request is placed directly behind a 6 byte struct,
> so it's guaranteed to be unaligned. We always have to copy it.
> 
> The response might be unaligned as well, but must be aligned to pass it
> to the mmc layer. In my tests the response was always aligned, but
> better safe than sorry, so I'll add an alignment check here as well,
> this time including a check for the length.



> 
> Sascha
> 



From s.hauer at pengutronix.de  Wed Mar 19 08:31:01 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Mar 2025 16:31:01 +0100
Subject: [PATCH v2 10/10] ARM: omap: remove unused file
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
Message-ID: <20250319-rpmb-v2-10-a8801fb35cd4@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/mach/omap/omap4-devices.h | 93 ---------------------------------------
 1 file changed, 93 deletions(-)

diff --git a/include/mach/omap/omap4-devices.h b/include/mach/omap/omap4-devices.h
deleted file mode 100644
index de73062bc5..0000000000
--- a/include/mach/omap/omap4-devices.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#ifndef __MACH_OMAP4_DEVICES_H
-#define __MACH_OMAP4_DEVICES_H
-
-#include <driver.h>
-#include <linux/sizes.h>
-#include <mach/omap/devices.h>
-#include <mach/omap/omap4-silicon.h>
-#include <mach/omap/mcspi.h>
-#include <mach/omap/omap_hsmmc.h>
-
-static inline void omap44xx_add_sram0(void)
-{
-	return omap_add_sram0(OMAP44XX_SRAM_BASE, 48 * SZ_1K);
-}
-
-static inline struct device *omap44xx_add_uart1(void)
-{
-	return omap_add_uart(0, OMAP44XX_UART1_BASE);
-}
-
-static inline struct device *omap44xx_add_uart2(void)
-{
-	return omap_add_uart(1, OMAP44XX_UART2_BASE);
-}
-
-static inline struct device *omap44xx_add_uart3(void)
-{
-	return omap_add_uart(2, OMAP44XX_UART3_BASE);
-}
-
-static inline struct device *omap44xx_add_mmc1(struct omap_hsmmc_platform_data *pdata)
-{
-	return add_generic_device("omap4-hsmmc", 0, NULL,
-			OMAP44XX_MMC1_BASE, SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_mmc2(struct omap_hsmmc_platform_data *pdata)
-{
-	return add_generic_device("omap4-hsmmc", 1, NULL,
-			OMAP44XX_MMC2_BASE, SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_mmc3(struct omap_hsmmc_platform_data *pdata)
-{
-	return add_generic_device("omap4-hsmmc", 2, NULL,
-			OMAP44XX_MMC3_BASE, SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_mmc4(struct omap_hsmmc_platform_data *pdata)
-{
-	return add_generic_device("omap4-hsmmc", 3, NULL,
-			OMAP44XX_MMC4_BASE, SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_mmc5(struct omap_hsmmc_platform_data *pdata)
-{
-	return add_generic_device("omap4-hsmmc", 4, NULL,
-			OMAP44XX_MMC5_BASE, SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_i2c1(void *pdata)
-{
-	return add_generic_device("i2c-omap4", 0, NULL, OMAP44XX_I2C1_BASE,
-			SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_i2c2(void *pdata)
-{
-	return add_generic_device("i2c-omap4", 1, NULL, OMAP44XX_I2C2_BASE,
-			SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_i2c3(void *pdata)
-{
-	return add_generic_device("i2c-omap4", 2, NULL, OMAP44XX_I2C3_BASE,
-			SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_i2c4(void *pdata)
-{
-	return add_generic_device("i2c-omap4", 3, NULL, OMAP44XX_I2C4_BASE,
-			SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_ehci(void *pdata)
-{
-	return add_usb_ehci_device(DEVICE_ID_DYNAMIC, OMAP44XX_EHCI_BASE,
-				OMAP44XX_EHCI_BASE + 0x10, pdata);
-}
-
-#endif /* __MACH_OMAP4_DEVICES_H */

-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 08:41:10 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 19 Mar 2025 16:41:10 +0100
Subject: [PATCH 4/9] mci: add RPMB support
In-Reply-To: <29edc564-8919-40d3-b4ac-d0e622a92bcd@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
 <20250312-rpmb-v1-4-0f213382a3f3@pengutronix.de>
 <9c66b31b-a79c-4a07-a03f-119c7c3dadc7@pengutronix.de>
 <Z9lZ8Q4bhUnuur1X@pengutronix.de> <Z9riy3YWmESSdii7@pengutronix.de>
 <29edc564-8919-40d3-b4ac-d0e622a92bcd@pengutronix.de>
Message-ID: <d8abf87b-2cda-4b21-ad76-f51ac888e300@pengutronix.de>



On 3/19/25 16:34, Ahmad Fatoum wrote:
> 
> 
> On 3/19/25 16:29, Sascha Hauer wrote:
>> On Tue, Mar 18, 2025 at 12:33:05PM +0100, Sascha Hauer wrote:
>>> On Mon, Mar 17, 2025 at 04:18:32PM +0100, Ahmad Fatoum wrote:
>>>> Hello Sascha,
>>>>
>>>> On 3/12/25 13:16, Sascha Hauer wrote:
>>>>> +
>>>>> +int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
>>>>> +			  void *rsp, unsigned long rsplen)
>>>>> +{
>>>>> +	/*
>>>>> +	 * Whoever crafted the data supplied to this function knows how to
>>>>> +	 * format the PRMB frames and which response is expected. If
>>>>> +	 * there's some unexpected mismatch it's more helpful to report an
>>>>> +	 * error immediately than trying to guess what was the intention
>>>>> +	 * and possibly just delay an eventual error which will be harder
>>>>> +	 * to track down.
>>>>> +	 */
>>>>> +	void *rpmb_data = NULL;
>>>>> +	int ret;
>>>>> +
>>>>> +	mci_blk_part_switch(mci->rpmb_part);
>>>>> +
>>>>> +	if (!IS_ALIGNED((uintptr_t)req, ARCH_DMA_MINALIGN)) {
>>>>
>>>> Even if alignment happens to be correct, there is no guarantee that
>>>> there is no other data sharing a cache line.
>>>
>>> reqlen is expected to be a single block of 512 bytes, so indeed when req
>>> is aligned then the end is cacheline aligned as well. We could check
>>> reqlen as well, but I actually never ran into this case, so we can just
>>> return an error for now as you suggested.
>>
>> I was wrong here. the request is placed directly behind a 6 byte struct,
>> so it's guaranteed to be unaligned. We always have to copy it.
>>
>> The response might be unaligned as well, but must be aligned to pass it
>> to the mmc layer. In my tests the response was always aligned, but
>> better safe than sorry, so I'll add an alignment check here as well,
>> this time including a check for the length.

Sorry about the empty mail. Can we have a generic helper for this?

Maybe dma_map_buf_is_aligned or something like that, preferably with a
device argument from the outset.

Cheers,
Ahmad

> 
> 
> 
>>
>> Sascha
>>
> 



From a.fatoum at pengutronix.de  Wed Mar 19 08:53:02 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 19 Mar 2025 16:53:02 +0100
Subject: [PATCH v2 04/10] mci: add RPMB support
In-Reply-To: <20250319-rpmb-v2-4-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
 <20250319-rpmb-v2-4-a8801fb35cd4@pengutronix.de>
Message-ID: <63082337-c9aa-467b-9a6b-5c98e5614c88@pengutronix.de>



On 3/19/25 16:30, Sascha Hauer wrote:
> This implements the MMC specific part to access RPMB partitions:
> 
> - Provide a function to find a RPMB capable eMMC
> - partition switching to the RPMB partition
> - Dissecting the OP-TEE requests into the correspnding MMC read/write
>   multiblock commands
> 
> For now we only support a single eMMC RPMB partition per board. This is
> the 99% case, but there might be systems with multiple eMMCs. The OP-TEE
> protocol has a dev_id field to support multiple eMMCs, but OP-TEE itself
> currently only supports a single RPMB. This means we really only need to
> support one eMMC, but should there be multiple eMMCs on a system we will
> need a way for the user to specify which one shall be used. As of now
> the first one found will be used.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  drivers/mci/Kconfig    |   3 +
>  drivers/mci/Makefile   |   1 +
>  drivers/mci/mci-core.c |  37 +++++++--
>  drivers/mci/rpmb.c     | 210 +++++++++++++++++++++++++++++++++++++++++++++++++
>  include/mci.h          |   5 ++
>  5 files changed, 251 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mci/Kconfig b/drivers/mci/Kconfig
> index 4641e9cdcd..09648aa771 100644
> --- a/drivers/mci/Kconfig
> +++ b/drivers/mci/Kconfig
> @@ -68,6 +68,9 @@ config MCI_MMC_GPP_PARTITIONS
>  	  Note: by default, 'MMC' devices have no 'general purpose partitions',
>  	  it requires a special one-time configuration step to enable them.
>  
> +config MCI_MMC_RPMB
> +	bool "Support eMMC replay protected memory block (RPMB)"
> +
>  comment "--- MCI host drivers ---"
>  
>  config MCI_DWC_MSHC
> diff --git a/drivers/mci/Makefile b/drivers/mci/Makefile
> index 5e951d695f..d3df4c1bb6 100644
> --- a/drivers/mci/Makefile
> +++ b/drivers/mci/Makefile
> @@ -1,5 +1,6 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  obj-$(CONFIG_MCI)		+= mci-core.o
> +obj-$(CONFIG_MCI_MMC_RPMB)	+= rpmb.o
>  obj-$(CONFIG_MCI_AM654)		+= am654-sdhci.o
>  obj-$(CONFIG_MCI_ARASAN)	+= arasan-sdhci.o
>  obj-$(CONFIG_MCI_ATMEL)		+= atmel_mci.o atmel_mci_common.o
> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> index 3bf0f15def..48bdd1a0c7 100644
> --- a/drivers/mci/mci-core.c
> +++ b/drivers/mci/mci-core.c
> @@ -2052,7 +2052,9 @@ int mci_blk_part_switch(struct mci_part *part)
>  	struct mci *mci = part->mci;
>  	int ret;
>  
> -	if (!IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) && !IS_ENABLED(CONFIG_MCI_MMC_GPP_PARTITIONS))
> +	if (!IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) &&
> +	    !IS_ENABLED(CONFIG_MCI_MMC_GPP_PARTITIONS) &&
> +	    !IS_ENABLED(CONFIG_MCI_MMC_RPMB))
>  		return 0; /* no need */
>  
>  	if (mci->part_curr == part)
> @@ -2953,7 +2955,6 @@ void mci_of_parse_node(struct mci_host *host,
>  {
>  	u32 bus_width;
>  	u32 dsr_val;
> -	const char *alias;
>  
>  	if (!IS_ENABLED(CONFIG_OFDEVICE))
>  		return;
> @@ -2961,9 +2962,14 @@ void mci_of_parse_node(struct mci_host *host,
>  	if (!host->hw_dev || !np)
>  		return;
>  
> -	alias = of_alias_get(np);
> -	if (alias)
> -		host->devname = xstrdup(alias);
> +	host->of_id = of_alias_get_id(np, "mmc");
> +	if (host->of_id < 0)
> +		host->of_id = of_alias_get_id(np->parent, "mmc");
> +
> +	if (host->of_id >= 0) {
> +		host->devname = xasprintf("mmc%u", host->of_id);
> +		host->of_id_valid = true;
> +	}
>  
>  	/* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */
>  	if (of_property_read_u32(np, "bus-width", &bus_width) < 0) {
> @@ -3051,3 +3057,24 @@ struct mci *mci_get_device_by_name(const char *name)
>  
>  	return NULL;
>  }
> +
> +struct mci *mci_get_rpmb_dev(unsigned int id)
> +{
> +	struct mci *mci;
> +
> +	list_for_each_entry(mci, &mci_list, list) {
> +		if (mci->host->of_id != id)
> +			continue;
> +
> +		mci_detect_card(mci->host);
> +
> +		if (!mci->rpmb_part) {
> +			dev_err(&mci->dev, "requested MMC does not have a RPMB partition\n");
> +			return NULL;
> +		}
> +
> +		return mci;
> +	}
> +
> +	return NULL;
> +}
> diff --git a/drivers/mci/rpmb.c b/drivers/mci/rpmb.c
> new file mode 100644
> index 0000000000..6c693aa1ea
> --- /dev/null
> +++ b/drivers/mci/rpmb.c
> @@ -0,0 +1,210 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright 2014, Staubli Faverges
> + * Pierre Aubert
> + *
> + * eMMC- Replay Protected Memory Block
> + * According to JEDEC Standard No. 84-A441
> + */
> +#define pr_fmt(fmt) "mmc-rpmb: " fmt
> +
> +#include <mci.h>
> +#include <malloc.h>
> +#include <dma.h>
> +
> +int mmc_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
> +			  void *rsp, unsigned long rsplen);
> +
> +/**
> + * struct rpmb_frame - rpmb frame as defined by eMMC 5.1 (JESD84-B51)
> + *
> + * @stuff        : stuff bytes
> + * @key_mac      : The authentication key or the message authentication
> + *                 code (MAC) depending on the request/response type.
> + *                 The MAC will be delivered in the last (or the only)
> + *                 block of data.
> + * @data         : Data to be written or read by signed access.
> + * @nonce        : Random number generated by the host for the requests
> + *                 and copied to the response by the RPMB engine.
> + * @write_counter: Counter value for the total amount of the successful
> + *                 authenticated data write requests made by the host.
> + * @addr         : Address of the data to be programmed to or read
> + *                 from the RPMB. Address is the serial number of
> + *                 the accessed block (half sector 256B).
> + * @block_count  : Number of blocks (half sectors, 256B) requested to be
> + *                 read/programmed.
> + * @result       : Includes information about the status of the write counter
> + *                 (valid, expired) and result of the access made to the RPMB.
> + * @req_resp     : Defines the type of request and response to/from the memory.
> + *
> + * The stuff bytes and big-endian properties are modeled to fit to the spec.
> + */
> +struct rpmb_frame {
> +	u8 stuff[196];
> +	u8 key_mac[32];
> +	u8 data[256];
> +	u8 nonce[16];
> +	__be32 write_counter;
> +	__be16 addr;
> +	__be16 block_count;
> +	__be16 result;
> +	__be16 req_resp;
> +} __packed;
> +
> +#define RPMB_PROGRAM_KEY	0x1	/* Program RPMB Authentication Key */
> +#define RPMB_GET_WRITE_COUNTER	0x2	/* Read RPMB write counter */
> +#define RPMB_WRITE_DATA		0x3	/* Write data to RPMB partition */
> +#define RPMB_READ_DATA		0x4	/* Read data from RPMB partition */
> +#define RPMB_RESULT_READ	0x5	/* Read result request  (Internal) */
> +
> +static int mci_read_write_blocks(struct mci *mci, u32 opcode, int write_flag, void *buf,
> +				 unsigned int buf_bytes)
> +{
> +	int blocks = buf_bytes / 512;
> +	struct mci_cmd cmd = {
> +		.cmdidx = opcode,
> +		.resp_type = MMC_RSP_R1,
> +	};
> +	struct mci_data data = {
> +		.blocks = blocks,
> +		.blocksize = sizeof(struct rpmb_frame),
> +	};
> +	int ret;
> +
> +	if (write_flag) {
> +		data.src = buf;
> +		data.flags = MMC_DATA_WRITE;
> +	} else {
> +		data.dest = buf;
> +		data.flags = MMC_DATA_READ;
> +	}
> +
> +	ret = mci_set_blockcount(mci, blocks | (write_flag & MMC_CMD23_ARG_REL_WR));
> +	if (ret)
> +		return ret;
> +
> +	return mci_send_cmd(mci, &cmd, &data);
> +}
> +
> +static int rpmb_route_frames(struct mci *mci, void *req,
> +			     unsigned int req_len, void *resp,
> +			     unsigned int resp_len)
> +{
> +	struct rpmb_frame *frm = req;
> +	unsigned int cmd_count;
> +	u16 req_type;
> +	bool write;
> +	int ret;
> +
> +	if (req_len < sizeof(*frm))
> +		return -EINVAL;
> +
> +	req_type = be16_to_cpu(frm->req_resp);
> +	switch (req_type) {
> +	case RPMB_PROGRAM_KEY:
> +		if (req_len != sizeof(struct rpmb_frame) ||
> +		    resp_len != sizeof(struct rpmb_frame))
> +			return -EINVAL;
> +		write = true;
> +		break;
> +	case RPMB_GET_WRITE_COUNTER:
> +		if (req_len != sizeof(struct rpmb_frame) ||
> +		    resp_len != sizeof(struct rpmb_frame))
> +			return -EINVAL;
> +		write = false;
> +		break;
> +	case RPMB_WRITE_DATA:
> +		if (req_len % sizeof(struct rpmb_frame) ||
> +		    resp_len != sizeof(struct rpmb_frame))
> +			return -EINVAL;
> +		write = true;
> +		break;
> +	case RPMB_READ_DATA:
> +		if (req_len != sizeof(struct rpmb_frame) ||
> +		    resp_len % sizeof(struct rpmb_frame))
> +			return -EINVAL;
> +		write = false;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	if (write)
> +		cmd_count = 3;
> +	else
> +		cmd_count = 2;
> +
> +	if (write) {
> +		struct rpmb_frame *frm = resp;
> +
> +		/* Send write request frame(s) */
> +		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK,
> +			  1 | MMC_CMD23_ARG_REL_WR, req, req_len);
> +		if (ret)
> +			goto out;
> +
> +		/* Send result request frame */
> +		memset(frm, 0, sizeof(*frm));
> +		frm->req_resp = cpu_to_be16(RPMB_RESULT_READ);
> +		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK, 1,
> +					    resp, resp_len);
> +		if (ret)
> +			goto out;
> +
> +		/* Read response frame */
> +		ret = mci_read_write_blocks(mci, MMC_CMD_READ_MULTIPLE_BLOCK, 0,
> +					    resp, resp_len);
> +		if (ret)
> +			goto out;
> +	} else {
> +		/* Send write request frame(s) */
> +		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK, 1,
> +					    req, req_len);
> +		if (ret)
> +			goto out;
> +
> +		/* Read response frame */
> +		ret = mci_read_write_blocks(mci, MMC_CMD_READ_MULTIPLE_BLOCK, 0,
> +					    resp, resp_len);
> +		if (ret)
> +			goto out;
> +	}
> +out:
> +	return ret;
> +}
> +
> +int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
> +			  void *rsp, unsigned long rsplen)
> +{
> +	/*
> +	 * Whoever crafted the data supplied to this function knows how to
> +	 * format the PRMB frames and which response is expected. If
> +	 * there's some unexpected mismatch it's more helpful to report an
> +	 * error immediately than trying to guess what was the intention
> +	 * and possibly just delay an eventual error which will be harder
> +	 * to track down.
> +	 */
> +	void *rpmb_data;
> +	int ret;
> +
> +	if (!IS_ALIGNED((uintptr_t)rsp, ARCH_DMA_MINALIGN) ||
> +	    !IS_ALIGNED(rsplen, ARCH_DMA_MINALIGN)) {
> +		pr_err_once("response or length not DMA aligned\n");

A reference to the device would be useful.

> +		return -EINVAL;
> +	}
> +
> +	mci_blk_part_switch(mci->rpmb_part);
> +
> +	/* Memory alignment is required by MMC driver */
> +	rpmb_data = dma_alloc(reqlen);
> +	if (!rpmb_data)
> +		return -ENOMEM;
> +
> +	memcpy(rpmb_data, req, reqlen);
> +
> +	ret = rpmb_route_frames(mci, rpmb_data, reqlen, rsp, rsplen);
> +
> +	free(rpmb_data);

dma_free() please

> +
> +	return ret;
> +}
> diff --git a/include/mci.h b/include/mci.h
> index 08a3e46f7d..43a0b01315 100644
> --- a/include/mci.h
> +++ b/include/mci.h
> @@ -554,6 +554,8 @@ struct mci_host {
>  	struct device *hw_dev;	/**< the host MCI hardware device */
>  	struct mci *mci;
>  	const char *devname;		/**< the devicename for the card, defaults to disk%d */
> +	int of_id;
> +	bool of_id_valid;
>  	unsigned voltages;
>  	unsigned host_caps;	/**< Host's interface capabilities, refer MMC_VDD_* */
>  	unsigned caps2;		/* More host capabilities */
> @@ -736,6 +738,9 @@ int mmc_select_timing(struct mci *mci);
>  int mci_set_blockcount(struct mci *mci, unsigned int cmdarg);
>  int mci_blk_part_switch(struct mci_part *part);
>  int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data);
> +struct mci *mci_get_rpmb_dev(unsigned int id);
> +int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
> +			  void *rsp, unsigned long rsplen);
>  
>  static inline bool mmc_card_hs200(struct mci *mci)
>  {
> 



From a.fatoum at pengutronix.de  Wed Mar 19 09:08:03 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 19 Mar 2025 17:08:03 +0100
Subject: [PATCH master 3/3] Documentation: devicetree: fix Sphinx warnings
In-Reply-To: <20250319160803.2079550-1-a.fatoum@pengutronix.de>
References: <20250319160803.2079550-1-a.fatoum@pengutronix.de>
Message-ID: <20250319160803.2079550-3-a.fatoum@pengutronix.de>

Building the barebox documentation results in an number of warnings
predominantly in the autogenerated docs from command help text.

Outside of that, there is warnings only in the DT bindings:

  bindings/barebox/virtual-reg.rst:25:
  WARNING: Inline emphasis start-string without end-string.

  bindings/barebox/virtual-reg.rst:28:
  WARNING: Definition list ends without a blank line; unexpected unindent.

  bindings/barebox/virtual-reg.rst:29:
  WARNING: Block quote ends without a blank line; unexpected unindent.

  bindings/clocks/xlnx,ps7-clkc.rst:
  WARNING: document isn't included in any toctree

Fix the devicetree binding warnings.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Documentation/devicetree/bindings/barebox/virtual-reg.rst | 2 +-
 Documentation/devicetree/index.rst                        | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/barebox/virtual-reg.rst b/Documentation/devicetree/bindings/barebox/virtual-reg.rst
index 7d576d0cef6f..a69d23144755 100644
--- a/Documentation/devicetree/bindings/barebox/virtual-reg.rst
+++ b/Documentation/devicetree/bindings/barebox/virtual-reg.rst
@@ -13,7 +13,7 @@ by subtracting ``virtual-reg`` from the first address in ``reg``.
 
 This is normally used to map I/O memory away from the zero page, so it
 can be used again to trap null pointer dereferences, while allowing
-full access to the device memory::
+full access to the device memory.
 
 .. code-block:: none
 
diff --git a/Documentation/devicetree/index.rst b/Documentation/devicetree/index.rst
index cd9270da1d21..2ca8b72be1ac 100644
--- a/Documentation/devicetree/index.rst
+++ b/Documentation/devicetree/index.rst
@@ -143,6 +143,7 @@ Contents:
    :maxdepth: 1
 
    bindings/barebox/*
+   bindings/clocks/*
    bindings/firmware/*
    bindings/leds/*
    bindings/misc/*
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 09:08:01 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 19 Mar 2025 17:08:01 +0100
Subject: [PATCH master 1/3] firmware: disable MISSING_FIRMWARE_ERROR for COMPILE_TEST builds
Message-ID: <20250319160803.2079550-1-a.fatoum@pengutronix.de>

An allyes build will enable all options possible and thus usually fail
to build, because it enables CONFIG_MISSING_FIRMWARE_ERROR along with
DRIVER_NET_FSL_FMAN, which requires firmware to function at runtime.

Fix this by disabling MISSING_FIRMWARE_ERROR if COMPILE_TEST is enabled.
This works, because Kconfig encounters COMPILE_TEST first.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 firmware/Kconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/firmware/Kconfig b/firmware/Kconfig
index ba005976c5a1..9253bc14cb0c 100644
--- a/firmware/Kconfig
+++ b/firmware/Kconfig
@@ -9,6 +9,8 @@ config EXTRA_FIRMWARE_DIR
 config MISSING_FIRMWARE_ERROR
 	bool "Fail the build when required firmware is missing"
 	default y
+	# This prevents firmware errors from breaking allyesconfig builds
+	depends on !COMPILE_TEST
 	help
 	  In-tree Defconfigs that enable multiple boards with different firmware
 	  binary requirements would say y here, so you don't need unrelated firmware
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 09:08:02 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 19 Mar 2025 17:08:02 +0100
Subject: [PATCH master 2/3] sandbox: do not enable SANDBOX_LINUX_I386 in allyesconfig
In-Reply-To: <20250319160803.2079550-1-a.fatoum@pengutronix.de>
References: <20250319160803.2079550-1-a.fatoum@pengutronix.de>
Message-ID: <20250319160803.2079550-2-a.fatoum@pengutronix.de>

On sandbox, CONFIG_32BIT and CONFIG_64BIT are determined by the used
compiler. As special case, building sandbox on x86_64 allows
selecting a 32-bit build via CONFIG_SANDBOX_LINUX_I386 if the compiler
supports it.

This option is disabled by default, but allyesconfig turns it on,
alongside drivers requiring host libraries like FTDI and SDL, which
are usually not required.

To make allyesconfig work out-of-the-box, restructure the config
symbols and give 64BIT a prompt only if i386 support is possible.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/Kconfig | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index c1a51d4f021d..7c568f9ddb29 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -44,17 +44,23 @@ config CC_HAS_LINUX_I386_SUPPORT
 
 config 64BIT
 	bool
-	default n if SANDBOX_LINUX_I386
+	prompt "64-bit barebox" if CC_HAS_LINUX_I386_SUPPORT
 	default CC_IS_64BIT
 	select ARCH_DMA_ADDR_T_64BIT
 	select PHYS_ADDR_T_64BIT
 	select ARCH_HAS_ASAN_FIBER_API if ASAN
+	help
+	  Say n here if you want to build a 32-bit barebox, either
+	  to be more similar to a target platform or to reduce
+	  memory usage when fuzzing for example.
+
+	  If unsure, say y.
 
 config 32BIT
 	def_bool !64BIT
 
 config SANDBOX_LINUX_I386
-	bool "32-bit x86 barebox" if CC_HAS_LINUX_I386_SUPPORT
+	def_bool 32_BIT && CC_HAS_LINUX_I386_SUPPORT
 
 config SANDBOX_REEXEC
 	prompt "exec(2) reset handler"
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 09:10:56 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 19 Mar 2025 17:10:56 +0100
Subject: [PATCH] fixup! commands: ubsan: hide zero division in test
Message-ID: <20250319161056.2086121-1-a.fatoum@pengutronix.de>

GCC complains that we pass the address of the variable instead of the
    variable itself:

    commands/ubsan.c: In function ?test_ubsan_divrem_overflow?:
    error: lvalue required in ?asm? statement

       63 |         __asm__ ("" : "=r" (var) : "0" (var))
          |         ^~~~~~~
    ./commands/ubsan.c:46:9: note: in expansion of macro ?OPTIMIZER_HIDE_VAR?
       46 |         OPTIMIZER_HIDE_VAR(&val2);

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 commands/ubsan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/ubsan.c b/commands/ubsan.c
index 634ab2bc60b2..debd5e2ce7de 100644
--- a/commands/ubsan.c
+++ b/commands/ubsan.c
@@ -43,7 +43,7 @@ static void test_ubsan_divrem_overflow(void)
 	volatile int val = 16;
 	volatile int val2 = 0;
 
-	OPTIMIZER_HIDE_VAR(&val2);
+	OPTIMIZER_HIDE_VAR(val2);
 
 	val /= val2;
 }
-- 
2.39.5



From uwe at kleine-koenig.org  Wed Mar 19 10:32:37 2025
From: uwe at kleine-koenig.org (=?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?=)
Date: Wed, 19 Mar 2025 18:32:37 +0100
Subject: [PATCH 0/2] arm64: rockchip: Two more additions to rockchip_v8_defconfig
Message-ID: <cover.1742405341.git.uwe@kleine-koenig.org>

Hello,

while working to support the Qnap TS-433 NAS I found the config items
enabled here quite useful. I'm not entirely sure that enabling generic
fit image is useful in general (also because it comes with a build
dependency on python3-libfdt), still here comes a suggestion to enable
it.

Best regards
Uwe

Uwe Kleine-K?nig (2):
  arm64: rockchip: Enable rockchip otp driver in defconfig
  arm64: rockchip: Enable generic fit image

 arch/arm/configs/rockchip_v8_defconfig | 3 +++
 1 file changed, 3 insertions(+)

base-commit: 9ecf814ff511c6dd6dcbbb2642d1ae9b11a20f8c
-- 
2.47.1



From uwe at kleine-koenig.org  Wed Mar 19 10:32:38 2025
From: uwe at kleine-koenig.org (=?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?=)
Date: Wed, 19 Mar 2025 18:32:38 +0100
Subject: [PATCH 1/2] arm64: rockchip: Enable rockchip otp driver in defconfig
In-Reply-To: <cover.1742405341.git.uwe@kleine-koenig.org>
References: <cover.1742405341.git.uwe@kleine-koenig.org>
Message-ID: <1fb9c1cf650ba020511788388fdfdfe995b25117.1742405341.git.uwe@kleine-koenig.org>

This driver is useful on rk3308, rk3568 and rk3588. Enable it in
rockchip_v8_defconfig.

Signed-off-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
---
 arch/arm/configs/rockchip_v8_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/configs/rockchip_v8_defconfig b/arch/arm/configs/rockchip_v8_defconfig
index cbd33d1b042d..95900368cc02 100644
--- a/arch/arm/configs/rockchip_v8_defconfig
+++ b/arch/arm/configs/rockchip_v8_defconfig
@@ -135,6 +135,8 @@ CONFIG_LED_GPIO_OF=y
 CONFIG_WATCHDOG=y
 CONFIG_WATCHDOG_POLLER=y
 CONFIG_WATCHDOG_DW=y
+CONFIG_NVMEM=y
+CONFIG_NVMEM_ROCKCHIP_OTP=y
 CONFIG_REGULATOR=y
 CONFIG_REGULATOR_FIXED=y
 CONFIG_REGULATOR_ARM_SCMI=y
-- 
2.47.1



From uwe at kleine-koenig.org  Wed Mar 19 10:32:39 2025
From: uwe at kleine-koenig.org (=?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?=)
Date: Wed, 19 Mar 2025 18:32:39 +0100
Subject: [PATCH 2/2] arm64: rockchip: Enable generic fit image
In-Reply-To: <cover.1742405341.git.uwe@kleine-koenig.org>
References: <cover.1742405341.git.uwe@kleine-koenig.org>
Message-ID: <d17c2dc494d8fc582dbee8eb8f04de34729d3ad5.1742405341.git.uwe@kleine-koenig.org>

The generic device tree 2nd stage FIT image is a quite convenient image
during development. Enable it in rockchip_v8_defconfig.

Signed-off-by: Uwe Kleine-K?nig <uwe at kleine-koenig.org>
---
 arch/arm/configs/rockchip_v8_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/rockchip_v8_defconfig b/arch/arm/configs/rockchip_v8_defconfig
index 95900368cc02..89e2bbcd6784 100644
--- a/arch/arm/configs/rockchip_v8_defconfig
+++ b/arch/arm/configs/rockchip_v8_defconfig
@@ -10,6 +10,7 @@ CONFIG_MACH_RADXA_CM3=y
 CONFIG_64BIT=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_PSCI_CLIENT=y
+CONFIG_BOARD_GENERIC_FIT=y
 CONFIG_MMU=y
 CONFIG_MALLOC_SIZE=0x0
 CONFIG_MALLOC_TLSF=y
-- 
2.47.1



From a.fatoum at pengutronix.de  Wed Mar 19 22:16:35 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:16:35 +0100
Subject: [PATCH master 2/8] include: asm-generic/pointer.h: fix ASM_PTR definition for i386
In-Reply-To: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
References: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
Message-ID: <20250320051641.1721377-3-a.fatoum@pengutronix.de>

For GNU as on i386, a .word is 16-bit wide, unlikes ARM, where it's
32-bit. The code in asm-generic/pointer.h expects .word to be
32-bit wide though, therefore to switch to .long.

Unlike C's long, an assembly .long is always 32-bit (and thus
identical to .int).

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch to fix compile error with IMD on i386 sandbox
---
 include/asm-generic/pointer.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/pointer.h b/include/asm-generic/pointer.h
index 89817ce59ebc..fbd1a831b8be 100644
--- a/include/asm-generic/pointer.h
+++ b/include/asm-generic/pointer.h
@@ -16,12 +16,12 @@
 #endif
 #elif __SIZEOF_POINTER__ == 4
 #ifdef __ASSEMBLY__
-#define ASM_PTR		.word
+#define ASM_PTR		.long
 #define ASM_SZPTR	4
 #define ASM_LGPTR	2
 #define ASM_LD_PTR(x)	LONG(x)
 #else
-#define ASM_PTR		".word"
+#define ASM_PTR		".long"
 #define ASM_SZPTR	"4"
 #define ASM_LGPTR	"2"
 #endif
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:16:33 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:16:33 +0100
Subject: [PATCH master 0/8] treewide: misc fixes
Message-ID: <20250320051641.1721377-1-a.fatoum@pengutronix.de>

Just a loose collection of fixes for master.

Ahmad Fatoum (8):
  firmware: disable MISSING_FIRMWARE_ERROR for COMPILE_TEST builds
  include: asm-generic/pointer.h: fix ASM_PTR definition for i386
  sandbox: do not enable SANDBOX_LINUX_I386 in allyesconfig
  Documentation: devicetree: fix Sphinx warnings
  ARM: mvebu: kwb_bbu: add missing header
  net: phy: fix of_get_phy_mode for XLGMII and beyond
  vsprintf: fix left indentation when formatting wide string arguments
  test: self: printf: add tests for formatting wide strings

 .../bindings/barebox/virtual-reg.rst          |  2 +-
 Documentation/devicetree/index.rst            |  1 +
 arch/arm/mach-mvebu/kwb_bbu.c                 |  1 +
 arch/sandbox/Kconfig                          | 10 ++-
 drivers/of/of_net.c                           | 36 +-------
 firmware/Kconfig                              |  2 +
 include/asm-generic/pointer.h                 |  4 +-
 include/linux/phy.h                           | 82 +++++++++++++++++++
 lib/vsprintf.c                                |  3 +-
 test/self/printf.c                            | 15 ++++
 10 files changed, 116 insertions(+), 40 deletions(-)

-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:16:37 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:16:37 +0100
Subject: [PATCH master 4/8] Documentation: devicetree: fix Sphinx warnings
In-Reply-To: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
References: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
Message-ID: <20250320051641.1721377-5-a.fatoum@pengutronix.de>

Building the barebox documentation results in an number of warnings
predominantly in the autogenerated docs from command help text.

Outside of that, there is warnings only in the DT bindings:

  bindings/barebox/virtual-reg.rst:25:
  WARNING: Inline emphasis start-string without end-string.

  bindings/barebox/virtual-reg.rst:28:
  WARNING: Definition list ends without a blank line; unexpected unindent.

  bindings/barebox/virtual-reg.rst:29:
  WARNING: Block quote ends without a blank line; unexpected unindent.

  bindings/clocks/xlnx,ps7-clkc.rst:
  WARNING: document isn't included in any toctree

Fix the devicetree binding warnings.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - no change
---
 Documentation/devicetree/bindings/barebox/virtual-reg.rst | 2 +-
 Documentation/devicetree/index.rst                        | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/barebox/virtual-reg.rst b/Documentation/devicetree/bindings/barebox/virtual-reg.rst
index 7d576d0cef6f..a69d23144755 100644
--- a/Documentation/devicetree/bindings/barebox/virtual-reg.rst
+++ b/Documentation/devicetree/bindings/barebox/virtual-reg.rst
@@ -13,7 +13,7 @@ by subtracting ``virtual-reg`` from the first address in ``reg``.
 
 This is normally used to map I/O memory away from the zero page, so it
 can be used again to trap null pointer dereferences, while allowing
-full access to the device memory::
+full access to the device memory.
 
 .. code-block:: none
 
diff --git a/Documentation/devicetree/index.rst b/Documentation/devicetree/index.rst
index cd9270da1d21..2ca8b72be1ac 100644
--- a/Documentation/devicetree/index.rst
+++ b/Documentation/devicetree/index.rst
@@ -143,6 +143,7 @@ Contents:
    :maxdepth: 1
 
    bindings/barebox/*
+   bindings/clocks/*
    bindings/firmware/*
    bindings/leds/*
    bindings/misc/*
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:16:36 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:16:36 +0100
Subject: [PATCH master 3/8] sandbox: do not enable SANDBOX_LINUX_I386 in allyesconfig
In-Reply-To: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
References: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
Message-ID: <20250320051641.1721377-4-a.fatoum@pengutronix.de>

On sandbox, CONFIG_32BIT and CONFIG_64BIT are determined by the used
compiler. As special case, building sandbox on x86_64 allows
selecting a 32-bit build via CONFIG_SANDBOX_LINUX_I386 if the compiler
supports it.

This option is disabled by default, but allyesconfig turns it on,
alongside drivers requiring host libraries like FTDI and SDL, which
are usually not required.

To make allyesconfig work out-of-the-box, restructure the config
symbols and give 64BIT a prompt only if i386 support is possible.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - fix typo in symbol name (32_BIT -> 32BIT)
---
 arch/sandbox/Kconfig | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index c1a51d4f021d..d4380aba0b5f 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -44,17 +44,23 @@ config CC_HAS_LINUX_I386_SUPPORT
 
 config 64BIT
 	bool
-	default n if SANDBOX_LINUX_I386
+	prompt "64-bit barebox" if CC_HAS_LINUX_I386_SUPPORT
 	default CC_IS_64BIT
 	select ARCH_DMA_ADDR_T_64BIT
 	select PHYS_ADDR_T_64BIT
 	select ARCH_HAS_ASAN_FIBER_API if ASAN
+	help
+	  Say n here if you want to build a 32-bit barebox, either
+	  to be more similar to a target platform or to reduce
+	  memory usage when fuzzing for example.
+
+	  If unsure, say y.
 
 config 32BIT
 	def_bool !64BIT
 
 config SANDBOX_LINUX_I386
-	bool "32-bit x86 barebox" if CC_HAS_LINUX_I386_SUPPORT
+	def_bool 32BIT && CC_HAS_LINUX_I386_SUPPORT
 
 config SANDBOX_REEXEC
 	prompt "exec(2) reset handler"
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:16:40 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:16:40 +0100
Subject: [PATCH master 7/8] vsprintf: fix left indentation when formatting wide string arguments
In-Reply-To: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
References: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
Message-ID: <20250320051641.1721377-8-a.fatoum@pengutronix.de>

leading_spaces will advance the buf pointer as needed, but currently buf
is never reassigned, breaking formatting of wchar arrays.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 lib/vsprintf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index cb42caebca16..99c63fbc33c7 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -229,7 +229,8 @@ static char *wstring(char *buf, const char *end, const wchar_t *s, int field_wid
 		s = L"<NULL>";
 
 	len = wcsnlen(s, precision);
-	leading_spaces(buf, end, len, &field_width, flags);
+
+	buf = leading_spaces(buf, end, len, &field_width, flags);
 
 	for (i = 0; i < len; ++i) {
 		if (buf < end)
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:16:38 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:16:38 +0100
Subject: [PATCH master 5/8] ARM: mvebu: kwb_bbu: add missing header
In-Reply-To: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
References: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
Message-ID: <20250320051641.1721377-6-a.fatoum@pengutronix.de>

The file uses xzalloc, but it's not defined any longer in the currently
included headers.

Include the relevant header to fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 arch/arm/mach-mvebu/kwb_bbu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-mvebu/kwb_bbu.c b/arch/arm/mach-mvebu/kwb_bbu.c
index 0fde9abb5709..b706edac6dc1 100644
--- a/arch/arm/mach-mvebu/kwb_bbu.c
+++ b/arch/arm/mach-mvebu/kwb_bbu.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <bbu.h>
+#include <xfuncs.h>
 #include <libfile.h>
 #include <linux/printk.h>
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:16:41 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:16:41 +0100
Subject: [PATCH master 8/8] test: self: printf: add tests for formatting wide strings
In-Reply-To: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
References: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
Message-ID: <20250320051641.1721377-9-a.fatoum@pengutronix.de>

Let's repeat the same string tests we already have, but with wide (%ls)
strings instead of our normal ones.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 test/self/printf.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/test/self/printf.c b/test/self/printf.c
index eae40ed242c1..3f35b5514705 100644
--- a/test/self/printf.c
+++ b/test/self/printf.c
@@ -179,6 +179,20 @@ test_string(void)
 	test("      1234", "%10.4s", "123456");
 }
 
+static void __init
+test_wstring(void)
+{
+	if (!IS_ENABLED(CONFIG_PRINTF_WCHAR))
+		return;
+
+	test("", "%ls%.0ls", L"", L"123");
+	test("ABCD|abc|123", "%ls|%.3ls|%.*ls", L"ABCD", L"abcdef", 3, L"123456");
+	test("1  |  2|3  |  4|5  ", "%-3ls|%3ls|%-*ls|%*ls|%*ls",
+	     L"1", L"2", 3, L"3", 3, L"4", -3, L"5");
+	test("1234      ", "%-10.4ls", L"123456");
+	test("      1234", "%10.4ls", L"123456");
+}
+
 #if BITS_PER_LONG == 64
 
 #define PTR_WIDTH 16
@@ -331,6 +345,7 @@ static void __init test_printf(void)
 	test_basic();
 	test_number();
 	test_string();
+	test_wstring();
 	test_pointer();
 	test_hexstr();
 	test_jsonpath();
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:16:39 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:16:39 +0100
Subject: [PATCH master 6/8] net: phy: fix of_get_phy_mode for XLGMII and beyond
In-Reply-To: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
References: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
Message-ID: <20250320051641.1721377-7-a.fatoum@pengutronix.de>

The phy_modes array needs to be kept in-sync with the
enum phy_interface_t, but this was violated by the most recent sync of
the enum type with Linux.

Th addition of new enumeration constants between existing ones resulted
in phy_modes having NULL-valued gaps, which would panic when passed
to strcmp.

Fix this by replacing the current sparse array, with a function that
always returns a string value. This is what Linux currently does.

Fixes: 63eb097f6639 ("net/phy: sync phy_interface_t types with Linux")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 drivers/of/of_net.c | 36 ++------------------
 include/linux/phy.h | 82 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 34 deletions(-)

diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index 58b4f99da111..d66de875316d 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -10,38 +10,6 @@
 #include <linux/phy.h>
 #include <linux/nvmem-consumer.h>
 
-/**
- * It maps 'enum phy_interface_t' found in include/linux/phy.h
- * into the device tree binding of 'phy-mode', so that Ethernet
- * device driver can get phy interface from device tree.
- */
-static const char *phy_modes[] = {
-	[PHY_INTERFACE_MODE_NA]		= "",
-	[PHY_INTERFACE_MODE_INTERNAL]	= "internal",
-	[PHY_INTERFACE_MODE_MII]	= "mii",
-	[PHY_INTERFACE_MODE_GMII]	= "gmii",
-	[PHY_INTERFACE_MODE_SGMII]	= "sgmii",
-	[PHY_INTERFACE_MODE_TBI]	= "tbi",
-	[PHY_INTERFACE_MODE_REVMII]	= "rev-mii",
-	[PHY_INTERFACE_MODE_RMII]	= "rmii",
-	[PHY_INTERFACE_MODE_REVRMII]	= "rev-rmii",
-	[PHY_INTERFACE_MODE_RGMII]	= "rgmii",
-	[PHY_INTERFACE_MODE_RGMII_ID]	= "rgmii-id",
-	[PHY_INTERFACE_MODE_RGMII_RXID]	= "rgmii-rxid",
-	[PHY_INTERFACE_MODE_RGMII_TXID]	= "rgmii-txid",
-	[PHY_INTERFACE_MODE_RTBI]	= "rtbi",
-	[PHY_INTERFACE_MODE_SMII]	= "smii",
-	[PHY_INTERFACE_MODE_XGMII]	= "xgmii",
-	[PHY_INTERFACE_MODE_MOCA]	= "moca",
-	[PHY_INTERFACE_MODE_QSGMII]	= "qsgmii",
-	[PHY_INTERFACE_MODE_TRGMII]	= "trgmii",
-	[PHY_INTERFACE_MODE_1000BASEX]	= "1000base-x",
-	[PHY_INTERFACE_MODE_2500BASEX]	= "2500base-x",
-	[PHY_INTERFACE_MODE_RXAUI]	= "rxaui",
-	[PHY_INTERFACE_MODE_XAUI]	= "xaui",
-	[PHY_INTERFACE_MODE_10GKR]	= "10gbase-kr",
-};
-
 /**
  * of_get_phy_mode - Get phy mode for given device_node
  * @np:	Pointer to the given device_node
@@ -60,8 +28,8 @@ int of_get_phy_mode(struct device_node *np)
 	if (err < 0)
 		return err;
 
-	for (i = 0; i < ARRAY_SIZE(phy_modes); i++)
-		if (!strcmp(pm, phy_modes[i]))
+	for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++)
+		if (!strcasecmp(pm, phy_modes(i)))
 			return i;
 
 	return -ENODEV;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index d8e53d446ef5..5cbd21f91a50 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -115,6 +115,88 @@ typedef enum {
 	PHY_INTERFACE_MODE_MAX,
 } phy_interface_t;
 
+/**
+ * phy_modes - map phy_interface_t enum to device tree binding of phy-mode
+ * @interface: enum phy_interface_t value
+ *
+ * Description: maps enum &phy_interface_t defined in this file
+ * into the device tree binding of 'phy-mode', so that Ethernet
+ * device driver can get PHY interface from device tree.
+ */
+static inline const char *phy_modes(phy_interface_t interface)
+{
+	switch (interface) {
+	case PHY_INTERFACE_MODE_NA:
+		return "";
+	case PHY_INTERFACE_MODE_INTERNAL:
+		return "internal";
+	case PHY_INTERFACE_MODE_MII:
+		return "mii";
+	case PHY_INTERFACE_MODE_GMII:
+		return "gmii";
+	case PHY_INTERFACE_MODE_SGMII:
+		return "sgmii";
+	case PHY_INTERFACE_MODE_TBI:
+		return "tbi";
+	case PHY_INTERFACE_MODE_REVMII:
+		return "rev-mii";
+	case PHY_INTERFACE_MODE_RMII:
+		return "rmii";
+	case PHY_INTERFACE_MODE_REVRMII:
+		return "rev-rmii";
+	case PHY_INTERFACE_MODE_RGMII:
+		return "rgmii";
+	case PHY_INTERFACE_MODE_RGMII_ID:
+		return "rgmii-id";
+	case PHY_INTERFACE_MODE_RGMII_RXID:
+		return "rgmii-rxid";
+	case PHY_INTERFACE_MODE_RGMII_TXID:
+		return "rgmii-txid";
+	case PHY_INTERFACE_MODE_RTBI:
+		return "rtbi";
+	case PHY_INTERFACE_MODE_SMII:
+		return "smii";
+	case PHY_INTERFACE_MODE_XGMII:
+		return "xgmii";
+	case PHY_INTERFACE_MODE_XLGMII:
+		return "xlgmii";
+	case PHY_INTERFACE_MODE_MOCA:
+		return "moca";
+	case PHY_INTERFACE_MODE_PSGMII:
+		return "psgmii";
+	case PHY_INTERFACE_MODE_QSGMII:
+		return "qsgmii";
+	case PHY_INTERFACE_MODE_TRGMII:
+		return "trgmii";
+	case PHY_INTERFACE_MODE_1000BASEX:
+		return "1000base-x";
+	case PHY_INTERFACE_MODE_1000BASEKX:
+		return "1000base-kx";
+	case PHY_INTERFACE_MODE_2500BASEX:
+		return "2500base-x";
+	case PHY_INTERFACE_MODE_5GBASER:
+		return "5gbase-r";
+	case PHY_INTERFACE_MODE_RXAUI:
+		return "rxaui";
+	case PHY_INTERFACE_MODE_XAUI:
+		return "xaui";
+	case PHY_INTERFACE_MODE_10GBASER:
+		return "10gbase-r";
+	case PHY_INTERFACE_MODE_25GBASER:
+		return "25gbase-r";
+	case PHY_INTERFACE_MODE_USXGMII:
+		return "usxgmii";
+	case PHY_INTERFACE_MODE_10GKR:
+		return "10gbase-kr";
+	case PHY_INTERFACE_MODE_100BASEX:
+		return "100base-x";
+	case PHY_INTERFACE_MODE_QUSGMII:
+		return "qusgmii";
+	default:
+		return "unknown";
+	}
+}
+
 #define PHY_INIT_TIMEOUT	100000
 #define PHY_FORCE_TIMEOUT	10
 #define PHY_AN_TIMEOUT		10
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:16:34 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:16:34 +0100
Subject: [PATCH master 1/8] firmware: disable MISSING_FIRMWARE_ERROR for COMPILE_TEST builds
In-Reply-To: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
References: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
Message-ID: <20250320051641.1721377-2-a.fatoum@pengutronix.de>

An allyes build will enable all options possible and thus usually fail
to build, because it enables CONFIG_MISSING_FIRMWARE_ERROR along with
DRIVER_NET_FSL_FMAN, which requires firmware to function at runtime.

Fix this by disabling MISSING_FIRMWARE_ERROR if COMPILE_TEST is enabled.
This works, because Kconfig encounters COMPILE_TEST first.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - no change
---
 firmware/Kconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/firmware/Kconfig b/firmware/Kconfig
index ba005976c5a1..9253bc14cb0c 100644
--- a/firmware/Kconfig
+++ b/firmware/Kconfig
@@ -9,6 +9,8 @@ config EXTRA_FIRMWARE_DIR
 config MISSING_FIRMWARE_ERROR
 	bool "Fail the build when required firmware is missing"
 	default y
+	# This prevents firmware errors from breaking allyesconfig builds
+	depends on !COMPILE_TEST
 	help
 	  In-tree Defconfigs that enable multiple boards with different firmware
 	  binary requirements would say y here, so you don't need unrelated firmware
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:20:13 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:20:13 +0100
Subject: [PATCH 0/6] fs: implement tree and truncate
Message-ID: <20250320052019.1726331-1-a.fatoum@pengutronix.de>

Turn opendir inside out, so it uses directory fds internally.
This is an important change, because it means that the inode
iterate operation will now operate on a real struct file.

This is a prerequisite for porting 9pfs from Linux as it expects
directories to be openend before iteration.

To aid with future development of file systems, introduce a tree and
a truncate command on top.

Ahmad Fatoum (6):
  fs: use filename_create/filename_lookup instead of open-coding
  fs: implement O_DIRECTORY
  fs: implement opendir in terms of fdopendir
  commands: implement tree command
  commands: add new truncate command
  Documentation: devel: add short section on file systems

 Documentation/devel/background-execution.rst |   2 +
 Documentation/devel/devel.rst                |   1 +
 Documentation/devel/filesystems.rst          |  73 +++++++
 commands/Kconfig                             |  24 +++
 commands/Makefile                            |   2 +
 commands/stat.c                              |   2 +-
 commands/tree.c                              | 159 ++++++++++++++
 commands/truncate.c                          | 100 +++++++++
 fs/fs.c                                      | 207 +++++++------------
 include/dirent.h                             |   3 +-
 test/self/dirfd.c                            |  11 +-
 11 files changed, 438 insertions(+), 146 deletions(-)
 create mode 100644 Documentation/devel/filesystems.rst
 create mode 100644 commands/tree.c
 create mode 100644 commands/truncate.c

-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:20:14 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:20:14 +0100
Subject: [PATCH 1/6] fs: use filename_create/filename_lookup instead of open-coding
In-Reply-To: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
References: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
Message-ID: <20250320052019.1726331-2-a.fatoum@pengutronix.de>

By reusing the existing file lookup code, open can open all directories,
e.g. / and /tmp/., which so far wasn't possible.

We need to be able to open these paths for directory FDs to work as one
would expect.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 fs/fs.c           | 55 ++++++++---------------------------------------
 test/self/dirfd.c |  7 +-----
 2 files changed, 10 insertions(+), 52 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 96ca60341ea4..1766719c567a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2543,9 +2543,7 @@ int openat(int dirfd, const char *pathname, int flags)
 	int error = 0;
 	struct inode *inode = NULL;
 	struct dentry *dentry = NULL;
-	struct nameidata nd;
-	const char *s;
-	struct filename *filename;
+	struct path path;
 
 	if (flags & O_TMPFILE) {
 		fsdev = get_fsdevice_by_path(dirfd, pathname);
@@ -2575,57 +2573,22 @@ int openat(int dirfd, const char *pathname, int flags)
 		return file_to_fd(f);
 	}
 
-	filename = getname(pathname);
-	if (IS_ERR(filename))
-		return PTR_ERR(filename);
-
-	set_nameidata(&nd, filename);
-
-	s = path_init(dirfd, &nd, LOOKUP_FOLLOW);
-	if (IS_ERR(s))
-		return PTR_ERR(s);
-
-	while (1) {
-		error = link_path_walk(s, &nd);
-		if (error)
-			break;
-
-		if (!d_is_dir(nd.path.dentry)) {
-			error = -ENOTDIR;
-			break;
-		}
-
-		dentry = __lookup_hash(&nd.last, nd.path.dentry, 0);
-		if (IS_ERR(dentry)) {
-			error = PTR_ERR(dentry);
-			break;
-		}
-
-		if (!d_is_symlink(dentry))
-			break;
-
-		dput(dentry);
-
-		error = lookup_last(&nd);
-		if (error <= 0)
-			break;
-
-		s = trailing_symlink(&nd);
-		if (IS_ERR(s)) {
-			error = PTR_ERR(s);
-			break;
-		}
+	if (flags & O_CREAT) {
+		dentry = filename_create(dirfd, getname(pathname), &path, 0);
+		error = PTR_ERR_OR_ZERO(dentry);
 	}
 
-	terminate_walk(&nd);
-	putname(nd.name);
+	if (!(flags & O_CREAT) || error == -EEXIST) {
+		error = filename_lookup(dirfd, getname(pathname), LOOKUP_FOLLOW, &path);
+		dentry = path.dentry;
+	}
 
 	if (error)
 		goto out1;
 
 	if (d_is_negative(dentry)) {
 		if (flags & O_CREAT) {
-			error = create(nd.path.dentry, dentry);
+			error = create(path.dentry, dentry);
 			if (error)
 				goto out1;
 		} else {
diff --git a/test/self/dirfd.c b/test/self/dirfd.c
index 644ff214fb37..20b54258715a 100644
--- a/test/self/dirfd.c
+++ b/test/self/dirfd.c
@@ -100,13 +100,8 @@ static void test_dirfd(void)
 	int fd;
 
 	fd = open("/", O_PATH);
-	if (expect(fd < 0, false, "open(/, O_PATH) = %d", fd)) {
+	if (expect(fd < 0, false, "open(/, O_PATH) = %d", fd))
 		close(fd);
-	} else {
-		pr_info("\tIgnoring expected failure\n");
-		failed_tests--;
-		skipped_tests++;
-	}
 
 #define B(dot, dotdot, zero, dev) 0b##dev##zero##dotdot##dot
 	/* We do fiften tests for every configuration
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:20:15 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:20:15 +0100
Subject: [PATCH 2/6] fs: implement O_DIRECTORY
In-Reply-To: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
References: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
Message-ID: <20250320052019.1726331-3-a.fatoum@pengutronix.de>

We already had O_DIRECTORY defined, but only used it as one of the
bits for O_TMPFILE.

Fix the O_TMPFILE branch, so it checks both bits and implement
O_DIRECTORY, so it causes an error when opening a file that's not
a directory.

This is useful for use with openat.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 commands/stat.c   |  2 +-
 fs/fs.c           | 32 ++++++++++++++++++++++----------
 test/self/dirfd.c |  6 +++---
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/commands/stat.c b/commands/stat.c
index 10662005cdda..8a96bf77b0f1 100644
--- a/commands/stat.c
+++ b/commands/stat.c
@@ -26,7 +26,7 @@ static int do_stat(int argc, char *argv[])
 			extra_flags |= O_CHROOT;
 			fallthrough;
 		case 'c':
-			dirfd = open(optarg, O_PATH | extra_flags);
+			dirfd = open(optarg, O_PATH | O_DIRECTORY | extra_flags);
 			if (dirfd < 0)
 				return dirfd;
 			break;
diff --git a/fs/fs.c b/fs/fs.c
index 1766719c567a..fd5818c36c20 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -337,16 +337,23 @@ static void put_file(struct file *f)
 
 static struct file *fd_to_file(int fd, bool o_path_ok)
 {
-	if (fd < 0 || fd >= MAX_FILES || !files[fd].fsdev) {
-		errno = EBADF;
-		return ERR_PTR(-errno);
-	}
-	if (!o_path_ok && (files[fd].f_flags & O_PATH)) {
-		errno = EINVAL;
-		return ERR_PTR(-errno);
+	int err = -EBADF;
+	unsigned flimits;
+
+	if (fd < 0 || fd >= MAX_FILES || !files[fd].fsdev)
+		goto err;
+
+	flimits = files[fd].f_flags & (O_PATH | O_DIRECTORY);
+	if (!o_path_ok && flimits) {
+		if (flimits & O_DIRECTORY)
+			err = -EBADF;
+		goto err;
 	}
 
 	return &files[fd];
+err:
+	errno = -err;
+	return ERR_PTR(err);
 }
 
 static int create(struct dentry *dir, struct dentry *dentry)
@@ -2545,7 +2552,7 @@ int openat(int dirfd, const char *pathname, int flags)
 	struct dentry *dentry = NULL;
 	struct path path;
 
-	if (flags & O_TMPFILE) {
+	if ((flags & O_TMPFILE) == O_TMPFILE) {
 		fsdev = get_fsdevice_by_path(dirfd, pathname);
 		if (!fsdev) {
 			errno = ENOENT;
@@ -2596,11 +2603,16 @@ int openat(int dirfd, const char *pathname, int flags)
 			error = -ENOENT;
 			goto out1;
 		}
-	} else if (!(flags & O_PATH)) {
-		if (d_is_dir(dentry) && !dentry_is_tftp(dentry)) {
+	} else if (d_is_dir(dentry)) {
+		if (!(flags & (O_PATH | O_DIRECTORY)) && !dentry_is_tftp(dentry)) {
 			error = -EISDIR;
 			goto out1;
 		}
+
+		flags |= O_DIRECTORY;
+	} else if (flags & O_DIRECTORY) {
+		error = -ENOTDIR;
+		goto out1;
 	}
 
 	inode = d_inode(dentry);
diff --git a/test/self/dirfd.c b/test/self/dirfd.c
index 20b54258715a..1f9b375e84ff 100644
--- a/test/self/dirfd.c
+++ b/test/self/dirfd.c
@@ -99,8 +99,8 @@ static void test_dirfd(void)
 {
 	int fd;
 
-	fd = open("/", O_PATH);
-	if (expect(fd < 0, false, "open(/, O_PATH) = %d", fd))
+	fd = open("/", O_PATH | O_DIRECTORY);
+	if (expect(fd < 0, false, "open(/, O_PATH | O_DIRECTORY) = %d", fd))
 		close(fd);
 
 #define B(dot, dotdot, zero, dev) 0b##dev##zero##dotdot##dot
@@ -119,7 +119,7 @@ static void test_dirfd(void)
 	do_test_dirfd("AT_FDCWD", AT_FDCWD,
 		      B(110,110,000,111), B(111,110,111,000),
 		      B(110,110,000,111), B(110,110,000,111));
-	do_test_dirfd("/dev", open("/dev", O_PATH),
+	do_test_dirfd("/dev", open("/dev", O_PATH | O_DIRECTORY),
 		      B(111,110,111,000), B(111,110,111,000),
 		      B(110,110,000,111), B(110,110,000,111));
 	do_test_dirfd("/dev O_CHROOT", open("/dev", O_PATH | O_CHROOT),
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:20:17 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:20:17 +0100
Subject: [PATCH 4/6] commands: implement tree command
In-Reply-To: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
References: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
Message-ID: <20250320052019.1726331-5-a.fatoum@pengutronix.de>

This is a very simple tree command inspired by busybox. We already have
ls -R for recursive directory listings, but tree uses indentation to
make it easier to see the directory structure.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 commands/Kconfig  |   9 +++
 commands/Makefile |   1 +
 commands/tree.c   | 159 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/fs.c           |   6 ++
 include/dirent.h  |   1 +
 5 files changed, 176 insertions(+)
 create mode 100644 commands/tree.c

diff --git a/commands/Kconfig b/commands/Kconfig
index fe459fa862f5..8a7a6e94f025 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1021,6 +1021,15 @@ config CMD_LS
 		  -C	column format (opposite of long format)
 		  -R	list subdirectories recursively
 
+config CMD_TREE
+	tristate
+	default y
+	prompt "tree"
+	help
+	  list contents of directories in a tree-like format.
+
+	  Usage: tree [FILEDIR...]
+
 config CMD_STAT
 	tristate
 	prompt "stat"
diff --git a/commands/Makefile b/commands/Makefile
index e152e4148b04..fa7de443cc13 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_CMD_POWEROFF)	+= poweroff.o
 obj-$(CONFIG_CMD_GO)		+= go.o
 obj-$(CONFIG_CMD_PARTITION)	+= partition.o
 obj-$(CONFIG_CMD_LS)		+= ls.o
+obj-$(CONFIG_CMD_TREE)		+= tree.o
 obj-$(CONFIG_CMD_STAT)		+= stat.o
 obj-$(CONFIG_CMD_CD)		+= cd.o
 obj-$(CONFIG_CMD_PWD)		+= pwd.o
diff --git a/commands/tree.c b/commands/tree.c
new file mode 100644
index 000000000000..9b660bb35584
--- /dev/null
+++ b/commands/tree.c
@@ -0,0 +1,159 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: ? 2022 Roger Knecht <rknecht at pm.me>
+// SPDX-FileCopyrightText: ? 2025 Ahmad Fatoum
+
+#include <stdio.h>
+#include <command.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+
+#define TREE_GAP	"    "
+#define TREE_BAR	"|   "
+#define TREE_MID	"|-- "
+#define TREE_END	"`-- "
+
+struct tree_buf {
+	char buf[80];
+};
+
+struct tree_iter {
+	struct tree_buf prefix;
+	unsigned ndirs;
+	unsigned nfiles;
+};
+
+static int tree_prefix_append(struct tree_buf *prefix, int pos, const char *suffix)
+{
+	int strsz = strlen(suffix);
+
+	if (pos + strsz + 1 < sizeof(prefix->buf))
+		memcpy(prefix->buf + pos, suffix, strsz + 1);
+
+	return pos + strsz;
+}
+
+static int tree(int dirfd, const char *path, int prefix_pos, struct tree_iter *iter)
+{
+	DIR *dir;
+	struct dirent *d;
+	int total, ret = 0;
+
+	if (ctrlc())
+		return -EINTR;
+
+	dirfd = openat(dirfd, path, O_DIRECTORY);
+	if (dirfd < 0)
+		return -errno;
+
+	printf("%s\n", path);
+
+	dir = fdopendir(dirfd);
+	if (!dir) {
+		ret = -errno;
+		goto out_close;
+	}
+
+	iter->ndirs++;
+
+	total = countdir(dir);
+	if (total < 0) {
+		ret = -errno;
+		goto out_close;
+	}
+
+	for (int i = 1; (d = readdir(dir)); i++) {
+		struct stat st;
+		int pos;
+
+		if (d->d_name[0] == '.')
+			continue;
+
+		ret = lstatat(dirfd, d->d_name, &st);
+		if (ret)
+			st.st_mode = S_IFREG;
+
+		if (i == total)
+			pos = tree_prefix_append(&iter->prefix, prefix_pos, TREE_END);
+		else
+			pos = tree_prefix_append(&iter->prefix, prefix_pos, TREE_MID);
+
+		printf("%*s", pos, iter->prefix.buf);
+
+		switch (st.st_mode & S_IFMT) {
+			char realname[PATH_MAX];
+		case S_IFLNK:
+			realname[PATH_MAX - 1] = '\0';
+
+			printf("%s", d->d_name);
+			if (readlinkat(dirfd, d->d_name, realname, PATH_MAX - 1) >= 0)
+				printf(" -> %s", realname);
+			printf("\n");
+
+			if (statat(dirfd, d->d_name, &st) || !S_ISDIR(st.st_mode))
+				iter->nfiles++;
+			else
+				iter->ndirs++;
+
+			break;
+		case S_IFDIR:
+			if (i == total)
+				pos = tree_prefix_append(&iter->prefix, prefix_pos, TREE_GAP);
+			else
+				pos = tree_prefix_append(&iter->prefix, prefix_pos, TREE_BAR);
+
+			ret = tree(dirfd, d->d_name, pos, iter);
+			if (ret)
+				goto out_closedir;
+			break;
+		default:
+			printf("%s\n", d->d_name);
+			iter->nfiles++;
+		}
+	}
+
+out_closedir:
+	closedir(dir);
+out_close:
+	close(dirfd);
+	return ret;
+}
+
+static int do_tree(int argc, char *argv[])
+{
+	const char *cwd, **args;
+	struct tree_iter iter;
+	int ret, exitcode = 0;
+
+	if (argc > 1) {
+		args = (const char **)argv + 1;
+		argc--;
+	} else {
+		cwd = getcwd();
+		args = &cwd;
+	}
+
+	iter.nfiles = iter.ndirs = 0;
+
+	for (int i = 0; i < argc; i++) {
+		iter.prefix.buf[0] = 0;
+		ret = tree(AT_FDCWD, args[i], 0, &iter);
+		if (ret) {
+			printf("%s  [error opening dir: %pe]\n", args[i], ERR_PTR(ret));
+			exitcode = 1;
+		}
+	}
+
+	printf("\n%u directories, %u files\n", iter.ndirs, iter.nfiles);
+
+	return exitcode;
+}
+
+BAREBOX_CMD_START(tree)
+	.cmd		= do_tree,
+	BAREBOX_CMD_DESC("list contents of directories in a tree-like format.")
+	BAREBOX_CMD_OPTS("[FILEDIR...]")
+	BAREBOX_CMD_GROUP(CMD_GRP_FILE)
+BAREBOX_CMD_END
diff --git a/fs/fs.c b/fs/fs.c
index 0c698981227f..3e5eb6dc8479 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1062,6 +1062,12 @@ int unreaddir(DIR *dir, const struct dirent *d)
 }
 EXPORT_SYMBOL(unreaddir);
 
+int countdir(DIR *dir)
+{
+	return list_count_nodes(&dir->entries);
+}
+EXPORT_SYMBOL(countdir);
+
 struct dirent *readdir(DIR *dir)
 {
 	struct readdir_entry *entry;
diff --git a/include/dirent.h b/include/dirent.h
index f74541d83d26..b6806aa24799 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -22,6 +22,7 @@ DIR *fdopendir(int fd);
 struct dirent *readdir(DIR *dir);
 int unreaddir(DIR *dir, const struct dirent *d);
 int rewinddir(DIR *dir);
+int countdir(DIR *dir);
 int closedir(DIR *dir);
 
 #endif /* __DIRENT_H */
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:20:16 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:20:16 +0100
Subject: [PATCH 3/6] fs: implement opendir in terms of fdopendir
In-Reply-To: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
References: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
Message-ID: <20250320052019.1726331-4-a.fatoum@pengutronix.de>

While struct filep (FILE) and struct file have been merged, we still
have two different ways the files are created: Regularly in open and
irregularly in an incomplete manner inside opendir.

This breaks file systems that expect the struct file passed to iterate
to have been opened before.

To allow porting such filesystems more easily, let's go all in on
directory FDs and implement opendir using it.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 fs/fs.c          | 114 +++++++++++++++--------------------------------
 include/dirent.h |   2 -
 2 files changed, 35 insertions(+), 81 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index fd5818c36c20..0c698981227f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2660,20 +2660,6 @@ int openat(int dirfd, const char *pathname, int flags)
 }
 EXPORT_SYMBOL(openat);
 
-static const char *fd_getpath(int fd)
-{
-	struct file *f;
-
-	if (fd < 0)
-		return ERR_PTR(errno_set(fd));
-
-	f = fd_to_file(fd, true);
-	if (IS_ERR(f))
-		return ERR_CAST(f);
-
-	return f->path;
-}
-
 int unlinkat(int dirfd, const char *pathname, int flags)
 {
 	int ret;
@@ -2758,107 +2744,77 @@ static void __release_dir(DIR *d)
 static int __opendir(DIR *d)
 {
 	int ret;
-	struct file file = {};
-	struct path *path = &d->path;
-	struct dentry *dir = path->dentry;
+	struct file *file = fd_to_file(d->fd, true);
 	struct readdir_callback rd = {
 		.ctx = {
 			.actor = fillonedir,
 		},
 	};
 
-	file.f_path.dentry = dir;
-	file.f_inode = d_inode(dir);
-	file.f_op = dir->d_inode->i_fop;
-
 	INIT_LIST_HEAD(&d->entries);
 	rd.dir = d;
 
-	ret = file.f_op->iterate(&file, &rd.ctx);
+	ret = file->f_inode->i_fop->iterate(file, &rd.ctx);
 	if (ret)
 		__release_dir(d);
 
 	return ret;
 }
 
-DIR *opendir(const char *pathname)
-{
-	int ret;
-	struct dentry *dir;
-	struct inode *inode;
-	DIR *d;
-	struct path path = {};
-
-	ret = filename_lookup(AT_FDCWD, getname(pathname),
-			      LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
-	if (ret)
-		goto out;
-
-	dir = path.dentry;
-
-	if (d_is_negative(dir)) {
-		ret = -ENOENT;
-		goto out_put;
-	}
-
-	inode = d_inode(dir);
-
-	if (!S_ISDIR(inode->i_mode)) {
-		ret = -ENOTDIR;
-		goto out_put;
-	}
-
-	d = xzalloc(sizeof(*d));
-	d->path = path;
-	d->fd = -ENOENT;
-
-	ret = __opendir(d);
-	if (ret)
-		goto out_free;
-
-	return d;
-
-out_free:
-	free(d);
-out_put:
-	path_put(&path);
-out:
-	errno_set(ret);
-
-	return NULL;
-}
-EXPORT_SYMBOL(opendir);
-
 DIR *fdopendir(int fd)
 {
-	const char *path;
+	struct stat st;
 	DIR *dir;
+	int ret;
 
-	path = fd_getpath(fd);
-	if (IS_ERR(path))
+	ret = fstat(fd, &st);
+	if (ret)
 		return NULL;
 
-	dir = opendir(path);
-	if (!dir)
-		return NULL;
+	if (!S_ISDIR(st.st_mode)) {
+		ret = -ENOTDIR;
+		goto err;
+	}
+
+	dir = xzalloc(sizeof(*dir));
 
 	/* we intentionally don't increment the reference count,
 	 * as POSIX specifies that fd ownership is transferred
 	 */
 	dir->fd = fd;
+
+	ret = __opendir(dir);
+	if (ret)
+		goto err;
+
 	return dir;
+err:
+	errno_set(ret);
+	return NULL;
 }
 EXPORT_SYMBOL(fdopendir);
 
+DIR *opendir(const char *pathname)
+{
+	int fd;
+
+	fd = open(pathname, O_DIRECTORY);
+	if (fd < 0) {
+		errno_set(fd);
+		return NULL;
+	}
+
+	return fdopendir(fd);
+}
+EXPORT_SYMBOL(opendir);
+
 int closedir(DIR *dir)
 {
 	if (!dir)
 		return errno_set(-EBADF);
 
-	path_put(&dir->path);
 	__release_dir(dir);
-	if (dir->fd >= 0)
-		close(dir->fd);
+	close(dir->fd);
 	free(dir);
 
 	return 0;
diff --git a/include/dirent.h b/include/dirent.h
index 4f7ff2a5f91f..f74541d83d26 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -3,7 +3,6 @@
 #define __DIRENT_H
 
 #include <linux/list.h>
-#include <linux/path.h>
 
 struct dirent {
 	char d_name[256];
@@ -15,7 +14,6 @@ typedef struct dir {
 	struct dirent d;
 	void *priv; /* private data for the fs driver */
 	int fd;
-	struct path path;
 	struct list_head entries;
 } DIR;
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:20:19 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:20:19 +0100
Subject: [PATCH 6/6] Documentation: devel: add short section on file systems
In-Reply-To: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
References: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
Message-ID: <20250320052019.1726331-7-a.fatoum@pengutronix.de>

barebox has a lot of commands that can be used to exercise different
aspects of a file system. Add some documentation for that.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Documentation/devel/background-execution.rst |  2 +
 Documentation/devel/devel.rst                |  1 +
 Documentation/devel/filesystems.rst          | 73 ++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 Documentation/devel/filesystems.rst

diff --git a/Documentation/devel/background-execution.rst b/Documentation/devel/background-execution.rst
index cf8675b9aa0e..e1e350785298 100644
--- a/Documentation/devel/background-execution.rst
+++ b/Documentation/devel/background-execution.rst
@@ -1,3 +1,5 @@
+.. _background_execution:
+
 Background execution in barebox
 ===============================
 
diff --git a/Documentation/devel/devel.rst b/Documentation/devel/devel.rst
index 39070074ca1b..3e9d44218334 100644
--- a/Documentation/devel/devel.rst
+++ b/Documentation/devel/devel.rst
@@ -9,6 +9,7 @@ Contents:
    :maxdepth: 2
 
    porting
+   filesystems
    background-execution
    project-ideas
 
diff --git a/Documentation/devel/filesystems.rst b/Documentation/devel/filesystems.rst
new file mode 100644
index 000000000000..454e736c701f
--- /dev/null
+++ b/Documentation/devel/filesystems.rst
@@ -0,0 +1,73 @@
+File system development in barebox
+==================================
+
+The barebox file system support is based heavily on Linux.
+
+Access to all file systems goes through the virtual file system
+layer, which provides uniform access to all mounted file systems
+under the same root.
+
+As power-fail safe writing of file system couldn't be guaranteed,
+most file systems supported by barebox are read-only.
+Safe writing is possible, however, via the :ref:`state_framework`.
+
+For an up-to-date listing of writable filesystems, refer to the
+``CONFIG_FS_WRITABLE`` Kconfig symbol.
+
+Testing File systems
+--------------------
+
+Nearly all file system operations have commands that directly exercise them:
+
++--------------------------+-----------------------------------------+
+| Command                  | Operations                              |
++==========================+=========================================+
+| :ref:`command_cat`       | ``open``, ``close``, ``read``           |
++--------------------------+-----------------------------------------+
+| :ref:`command_echo`      | ``create``, ``write``                   |
++--------------------------+-----------------------------------------+
+| :ref:`command_sync`      | ``flush``                               |
++--------------------------+-----------------------------------------+
+| :ref:`command_erase`     | ``erase``                               |
++--------------------------+-----------------------------------------+
+| :ref:`command_protect`   | ``protect``                             |
++--------------------------+-----------------------------------------+
+| :ref:`command_md`        | ``lseek``, ``memmap``                   |
++--------------------------+-----------------------------------------+
+| :ref:`command_rm`        | ``unlink``                              |
++--------------------------+-----------------------------------------+
+| :ref:`command_mkdir`     | ``mkdir``                               |
++--------------------------+-----------------------------------------+
+| :ref:`command_rmdir`     | ``rmdir``                               |
++--------------------------+-----------------------------------------+
+| :ref:`command_ln`        | ``symlink``                             |
++--------------------------+-----------------------------------------+
+| :ref:`command_readlink`  | ``readlink``                            |
++--------------------------+-----------------------------------------+
+| | :ref:`command_ls`      |  ``opendir``, ``readdir``, ``closedir`` |
+| | :ref:`command_tree`    |                                         |
++--------------------------+-----------------------------------------+
+| :ref:`command_stat`      | ``stat``                                |
++--------------------------+-----------------------------------------+
+| :ref:`command_truncate`  | ``truncate``                            |
++--------------------------+-----------------------------------------+
+
+This leaves two specialized operations that can't be easily tested
+via the shell:
+
+- ``discard_range``: Advise that a range need not be preserved
+- ``ioctl``: Issue device-specific output and input control commands
+
+Unused metadata
+---------------
+
+barebox currently ignores ownership and permission information
+inside file systems as well as special nodes like FIFOs or
+sockets. When porting file systems, these parts can be omitted.
+
+Background execution
+--------------------
+
+Outside command context (i.e. in
+:ref:`pollers and secondary barebox threads <background_execution>`),
+virtual file system access is only permitted with ramfs.
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:20:18 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:20:18 +0100
Subject: [PATCH 5/6] commands: add new truncate command
In-Reply-To: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
References: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
Message-ID: <20250320052019.1726331-6-a.fatoum@pengutronix.de>

The truncate command offers an easy way to exercise a file system's
truncate operation.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 commands/Kconfig    |  15 +++++++
 commands/Makefile   |   1 +
 commands/truncate.c | 100 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 commands/truncate.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 8a7a6e94f025..8c05b8eff606 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1904,6 +1904,21 @@ config CMD_DETECT
 		  -e	bail out if one device fails to detect
 		  -a	detect all devices
 
+config CMD_TRUNCATE
+	tristate
+	prompt "truncate"
+	help
+
+	truncate [-c] -s [+]SIZE FILE...
+
+	truncate truncates files to a given size. If a file does
+	not exist, it is created unless told otherwise.
+	Options:
+	-c		Do not create files
+	-s [+]SIZE	truncate file to SIZE, or increase by +SIZE
+
+	This command is mainly useful for VFS development.
+
 config CMD_SYNC
 	tristate
 	prompt "sync"
diff --git a/commands/Makefile b/commands/Makefile
index fa7de443cc13..36ef59b38759 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_CMD_FINDMNT)	+= findmnt.o
 obj-$(CONFIG_CMD_CRC)		+= crc.o
 obj-$(CONFIG_CMD_CLEAR)		+= clear.o
 obj-$(CONFIG_CMD_TEST)		+= test.o
+obj-$(CONFIG_CMD_TRUNCATE)	+= truncate.o
 obj-$(CONFIG_CMD_SYNC)		+= sync.o
 obj-$(CONFIG_CMD_FLASH)		+= flash.o
 obj-$(CONFIG_CMD_MEMINFO)	+= meminfo.o
diff --git a/commands/truncate.c b/commands/truncate.c
new file mode 100644
index 000000000000..5c6d74257da1
--- /dev/null
+++ b/commands/truncate.c
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2015 by Ari Sundholm <ari at tuxera.com>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <fs.h>
+
+static int do_truncate(int argc, char *argv[])
+{
+	int flags = O_CREAT | O_WRONLY;
+	int opt, modify = 0, ret = 0;
+	const char *size_str;
+	off_t size = -1;
+
+	while((opt = getopt(argc, argv, "cs:")) > 0) {
+		switch(opt) {
+		case 'c':
+			flags &= ~O_CREAT;
+			break;
+		case 's':
+			size_str = optarg;
+			if (!size_str)
+				return COMMAND_ERROR_USAGE;
+			switch (*size_str) {
+			case '+':
+				modify = 1;
+				size_str++;
+				break;
+			case '-':
+				return COMMAND_ERROR_USAGE;
+			}
+			size = strtoull_suffix(size_str, NULL, 10);
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	argv += optind;
+	argc -= optind;
+
+	if (size == -1 || argc == 0)
+		return COMMAND_ERROR_USAGE;
+
+	for (int i = 0; i < argc; i++) {
+		int fd = open(argv[i], flags, 0666);
+		if (fd < 0) {
+			if (errno != ENOENT || !(flags & O_CREAT)) {
+				perror("open");
+				ret = 1;
+			}
+			/* else: ENOENT && OPT_NOCREATE:
+			 * do not report error, exitcode is also 0.
+			 */
+			continue;
+		}
+
+		if (modify) {
+			struct stat st;
+
+			if (fstat(fd, &st) == -1) {
+				perror("fstat");
+				ret = 1;
+				goto close;
+			}
+
+			size = st.st_size + modify * size;
+		}
+
+		if (ftruncate(fd, size) == -1) {
+			perror("truncate");
+			ret = 1;
+		}
+close:
+		close(fd);
+	}
+
+	return ret;
+}
+
+BAREBOX_CMD_HELP_START(truncate)
+BAREBOX_CMD_HELP_TEXT("truncate truncates files to a given size. If a file does")
+BAREBOX_CMD_HELP_TEXT("not exist, it is created unless told otherwise.")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-c",     "Do not create files")
+BAREBOX_CMD_HELP_OPT ("-s [+]SIZE", "truncate file to SIZE, or increase by +SIZE")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(truncate)
+	.cmd		= do_truncate,
+	BAREBOX_CMD_DESC("truncate files to size")
+	BAREBOX_CMD_OPTS("[-c] -s [+]SIZE FILE...")
+	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
+	BAREBOX_CMD_HELP(cmd_truncate_help)
+BAREBOX_CMD_END
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:20:27 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:20:27 +0100
Subject: [PATCH] driver: base: class: remove device from class on registration
Message-ID: <20250320052027.1731144-1-a.fatoum@pengutronix.de>

class_remove_device is the exception and normally, a device class
doesn't change for the lifetime of a device after it's set the first
time and removal from a class is done alongside removal of the device
itself.

Let's therefore move the removal from class into core driver code.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/base/class.c       | 11 -----------
 drivers/base/driver.c      |  2 ++
 drivers/watchdog/wd_core.c |  2 +-
 include/device.h           |  2 --
 net/eth.c                  |  2 --
 5 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index d0765e496f9e..b7cc58ce0750 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -48,14 +48,3 @@ int class_register_device(struct class *class,
 	class_add_device(class, class_dev);
 	return 0;
 }
-
-void class_unregister_device(struct device *class_dev)
-{
-	list_del(&class_dev->class_list);
-	unregister_device(class_dev);
-}
-
-void class_remove_device(struct class *class, struct device *dev)
-{
-	list_del(&dev->class_list);
-}
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 603fc9d9cb0a..6363b3948f1d 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -265,6 +265,7 @@ int register_device(struct device *new_device)
 	INIT_LIST_HEAD(&new_device->parameters);
 	INIT_LIST_HEAD(&new_device->active);
 	INIT_LIST_HEAD(&new_device->bus_list);
+	INIT_LIST_HEAD(&new_device->class_list);
 
 	if (new_device->bus) {
 		if (!new_device->parent)
@@ -318,6 +319,7 @@ int unregister_device(struct device *old_dev)
 
 	list_del(&old_dev->list);
 	list_del(&old_dev->bus_list);
+	list_del(&old_dev->class_list);
 	list_del(&old_dev->active);
 
 	/* remove device from parents child list */
diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index 27371672f39c..6e239edf612d 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -255,7 +255,7 @@ int watchdog_deregister(struct watchdog *wd)
 		poller_async_unregister(&wd->poller);
 	}
 
-	class_remove_device(&watchdog_class, &wd->dev);
+	list_del_init(&wd->dev.class_list);
 
 	return 0;
 }
diff --git a/include/device.h b/include/device.h
index d3936d3b3ad6..e0c130551f9a 100644
--- a/include/device.h
+++ b/include/device.h
@@ -128,11 +128,9 @@ void class_register(struct class *class);
 	pure_initcall(register_##_name);
 
 int class_add_device(struct class *class, struct device *dev);
-void class_remove_device(struct class *class, struct device *dev);
 
 int class_register_device(struct class *class, struct device *class_dev,
 			  const char *name);
-void class_unregister_device(struct device *class_dev);
 
 extern struct list_head class_list;
 #define class_for_each_device(class, dev) list_for_each_entry((dev), &(class)->devices, class_list)
diff --git a/net/eth.c b/net/eth.c
index e4025753518c..bc2527de3670 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -539,8 +539,6 @@ void eth_unregister(struct eth_device *edev)
 	if (IS_ENABLED(CONFIG_OFDEVICE))
 		free_const(edev->nodepath);
 
-	class_remove_device(&eth_class, &edev->dev);
-
 	free(edev->devname);
 
 	unregister_device(&edev->dev);
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:20:58 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:20:58 +0100
Subject: [PATCH v2 2/3] env: add envvar_for_each helper for variable iteration
In-Reply-To: <20250320052059.1732184-1-a.fatoum@pengutronix.de>
References: <20250320052059.1732184-1-a.fatoum@pengutronix.de>
Message-ID: <20250320052059.1732184-2-a.fatoum@pengutronix.de>

Instead of opencoding the iteration where needed, implement a helper
invokes a callback on every variable.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 common/env.c          | 37 +++++++++++++++++++++++++++++++++++++
 include/environment.h |  7 +++++++
 2 files changed, 44 insertions(+)

diff --git a/common/env.c b/common/env.c
index e34e3ac078d6..fd01178aee54 100644
--- a/common/env.c
+++ b/common/env.c
@@ -123,6 +123,21 @@ static const char *getenv_raw(struct list_head *l, const char *name)
 	return NULL;
 }
 
+static int getenv_raw_call(int (*fn)(struct variable_d *v, void *data),
+			   struct list_head *l, void *data)
+{
+	struct variable_d *v;
+	int ret;
+
+	list_for_each_entry(v, l, list) {
+		ret = fn(v, data);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static const char *dev_getenv(const char *name)
 {
 	const char *pos, *val, *dot, *varname;
@@ -179,6 +194,28 @@ const char *getenv(const char *name)
 }
 EXPORT_SYMBOL(getenv);
 
+int envvar_for_each(int (*fn)(struct variable_d *v, void *data), void *data)
+{
+	struct env_context *c;
+	int ret;
+
+	c = context;
+
+	ret = getenv_raw_call(fn, &c->local, data);
+	if (ret)
+		return ret;
+
+	while (c) {
+		ret = getenv_raw_call(fn, &c->global, data);
+		if (ret)
+			return ret;
+		c = c->parent;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(envvar_for_each);
+
 static int setenv_raw(struct list_head *l, const char *name, const char *value)
 {
 	struct variable_d *v;
diff --git a/include/environment.h b/include/environment.h
index f26c68ba3e34..c24796427675 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -31,6 +31,7 @@ const char *var_name(struct variable_d *);
 
 #if IS_ENABLED(CONFIG_ENVIRONMENT_VARIABLES) && IN_PROPER
 const char *getenv(const char *);
+int envvar_for_each(int (*fn)(struct variable_d *v, void *data), void *data);
 int setenv(const char *, const char *);
 int pr_setenv(const char *, const char *fmt, ...)  __attribute__ ((format(__printf__, 2, 3)));
 void export_env_ull(const char *name, unsigned long long val);
@@ -46,6 +47,12 @@ static inline char *getenv(const char *var)
 	return NULL;
 }
 
+static inline int envvar_for_each(int (*fn)(struct list_head *l, void *data),
+				  void *data)
+{
+	return 0;
+}
+
 static inline int setenv(const char *var, const char *val)
 {
 	return 0;
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:20:57 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:20:57 +0100
Subject: [PATCH v2 1/3] complete: give device_param_complete a flags parameter
Message-ID: <20250320052059.1732184-1-a.fatoum@pengutronix.de>

We currently always complete device parameters with either a dollar sign
in front or an equal sign after. In preparation for allowing completions
with neither, give env_param_complete() a flag.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 common/complete.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/common/complete.c b/common/complete.c
index 5b8b499ed38f..6061c8ba6ecb 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -9,11 +9,15 @@
 #include <complete.h>
 #include <xfuncs.h>
 #include <fs.h>
+#include <linux/bits.h>
 #include <linux/stat.h>
 #include <libgen.h>
 #include <command.h>
 #include <environment.h>
 
+#define DEVPARAM_COMPLETE_ASSIGNMENT	BIT(0)
+#define DEVPARAM_COMPLETE_DOLLAR	BIT(1)
+
 static bool is_valid_escape(const char *str)
 {
 	return str[0] == '\\' && (str[1] == ' ' || str[1] == '\\');
@@ -170,7 +174,8 @@ int device_complete(struct string_list *sl, char *instr)
 EXPORT_SYMBOL(device_complete);
 
 static int device_param_complete(struct device *dev, const char *devname,
-				 struct string_list *sl, char *instr, int eval)
+				 struct string_list *sl, char *instr,
+				 unsigned flags)
 {
 	struct param_d *param;
 
@@ -179,8 +184,8 @@ static int device_param_complete(struct device *dev, const char *devname,
 			continue;
 
 		string_list_add_asprintf(sl, "%s%s.%s%c",
-			eval ? "$" : "", devname, param->name,
-			eval ? ' ' : '=');
+			flags & DEVPARAM_COMPLETE_DOLLAR ? "$" : "", devname, param->name,
+			flags & DEVPARAM_COMPLETE_ASSIGNMENT ? '=' : ' ');
 	}
 
 	return 0;
@@ -292,21 +297,22 @@ int tutorial_complete(struct string_list *sl, char *instr)
 }
 EXPORT_SYMBOL(tutorial_complete);
 
-static int env_param_complete(struct string_list *sl, char *instr, int eval)
+static int env_param_complete(struct string_list *sl, char *instr, unsigned flags)
 {
 	struct device *dev;
 	struct variable_d *var;
 	struct env_context *c;
 	int len;
-	char end = '=', *pos, *dot;
+	char end = ' ', *pos, *dot;
 	char *begin = "";
 
 	if (!instr)
 		instr = "";
 
-	if (eval) {
+	if (flags & DEVPARAM_COMPLETE_DOLLAR) {
 		begin = "$";
-		end = ' ';
+	} else if (flags & DEVPARAM_COMPLETE_ASSIGNMENT) {
+		end = '=';
 	}
 
 	len = strlen(instr);
@@ -338,7 +344,7 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
 		dev = get_device_by_name(devname);
 
 		if (dev)
-			device_param_complete(dev, devname, sl, dot + 1, eval);
+			device_param_complete(dev, devname, sl, dot + 1, flags);
 
 		free(devname);
 		pos = dot + 1;
@@ -348,7 +354,7 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
 
 	for_each_device(dev) {
 		if (!strncmp(instr, dev_name(dev), len))
-			device_param_complete(dev, dev_name(dev), sl, "", eval);
+			device_param_complete(dev, dev_name(dev), sl, "", flags);
 	}
 
 	return 0;
@@ -356,7 +362,7 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
 
 int env_param_noeval_complete(struct string_list *sl, char *instr)
 {
-	return env_param_complete(sl, instr, 0);
+	return env_param_complete(sl, instr, DEVPARAM_COMPLETE_ASSIGNMENT);
 }
 EXPORT_SYMBOL(env_param_noeval_complete);
 
@@ -415,7 +421,7 @@ static char* cmd_complete_lookup(struct string_list *sl, char *instr)
 
 end:
 	if (ret == COMPLETE_CONTINUE && *instr == '$')
-		env_param_complete(sl, instr + 1, 1);
+		env_param_complete(sl, instr + 1, DEVPARAM_COMPLETE_DOLLAR);
 
 	return res;
 }
@@ -460,7 +466,7 @@ int complete(char *instr, char **outstr)
 			env_param_complete(&sl, instr, 0);
 		}
 		if (*instr == '$')
-			env_param_complete(&sl, instr + 1, 1);
+			env_param_complete(&sl, instr + 1, DEVPARAM_COMPLETE_DOLLAR);
 	}
 
 	pos = strlen_escaped(instr);
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:20:59 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:20:59 +0100
Subject: [PATCH v2 3/3] commands: add varinfo command
In-Reply-To: <20250320052059.1732184-1-a.fatoum@pengutronix.de>
References: <20250320052059.1732184-1-a.fatoum@pengutronix.de>
Message-ID: <20250320052059.1732184-3-a.fatoum@pengutronix.de>

Tab completion is very helpful, but it's not sufficient for enum-typed
global variables. To know what the permissible values are, devinfo
global must be consulted, which can have a lot of output.

As alternative, let's add a varinfo command that can be used together
with parameter tab completion and that will just print out the
parameters that start with the specified string.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - lookup shell environment variables by prefix as well (Sascha)
  - completio without trailing equal sign (Sascha)
---
 commands/Kconfig   | 12 ++++++
 commands/Makefile  |  1 +
 commands/varinfo.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++
 common/complete.c  |  6 +++
 include/complete.h |  1 +
 5 files changed, 111 insertions(+)
 create mode 100644 commands/varinfo.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 8c05b8eff606..4cce4b24cc98 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -286,6 +286,18 @@ config CMD_LSPCI
 	help
 	  The lspci command allows to list all PCI devices.
 
+config CMD_VARINFO
+	tristate
+	prompt "varinfo"
+	help
+	  Show information about variables
+
+	  varinfo VAR
+
+	  Shows information about the variable in its argument. This doesn't
+	  provide more information that what's available with devinfo, but
+	  it can be useful for devices with many parameters (e.g. global).
+
 config CMD_VERSION
 	tristate
 	default y
diff --git a/commands/Makefile b/commands/Makefile
index 36ef59b38759..f97b77c7cc16 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -59,6 +59,7 @@ obj-$(CONFIG_CMD_MEMTEST)	+= memtest.o
 obj-$(CONFIG_CMD_MEMTESTER)	+= memtester/
 obj-$(CONFIG_CMD_TRUE)		+= true.o
 obj-$(CONFIG_CMD_FALSE)		+= false.o
+obj-$(CONFIG_CMD_VARINFO)	+= varinfo.o
 obj-$(CONFIG_CMD_VERSION)	+= version.o
 obj-$(CONFIG_CMD_HELP)		+= help.o
 obj-$(CONFIG_CMD_LSMOD)		+= lsmod.o
diff --git a/commands/varinfo.c b/commands/varinfo.c
new file mode 100644
index 000000000000..5965c60159ca
--- /dev/null
+++ b/commands/varinfo.c
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <command.h>
+#include <common.h>
+#include <complete.h>
+#include <driver.h>
+#include <environment.h>
+#include <fnmatch.h>
+
+struct iter_ctx {
+	const char *prefix;
+	bool found;
+};
+
+static int printenv_by_prefix(struct variable_d *v, void *data)
+{
+	struct iter_ctx *ctx = data;
+
+	if (strstarts(var_name(v), ctx->prefix)) {
+		printf("%s: %s (environment variable)\n", var_name(v), var_val(v));
+		ctx->found = true;
+	}
+
+	return 0;
+}
+
+static int do_varinfo(int argc, char *argv[])
+{
+	struct device *dev;
+	struct param_d *param;
+	const char *prefix = NULL;
+	char *arg, *dot;
+	bool found = false;
+
+	if (argc != 2)
+		return COMMAND_ERROR_USAGE;
+
+	arg = argv[1];
+
+	dot = strchr(arg, '.');
+	if (dot) {
+		*dot = '\0';
+		if (dot[1])
+			prefix = &dot[1];
+	} else {
+		struct iter_ctx ctx = { arg };
+
+		envvar_for_each(printenv_by_prefix, &ctx);
+		if (!ctx.found)
+			goto not_found;
+
+		return 0;
+	}
+
+	dev = get_device_by_name(arg);
+	if (!dev)
+		return -ENODEV;
+
+	list_for_each_entry(param, &dev->parameters, list) {
+		if (prefix && !strstarts(param->name, prefix))
+			continue;
+
+		printf("%s: %s (type: %s)", param->name,
+		       dev_get_param(dev, param->name), get_param_type(param));
+		if (param->info)
+			param->info(param);
+		printf("\n");
+		found = true;
+	}
+
+	if (!found)
+		goto not_found;
+
+	return 0;
+not_found:
+	printf("%s: no matching variable found\n", arg);
+	return 1;
+}
+
+BAREBOX_CMD_HELP_START(varinfo)
+BAREBOX_CMD_HELP_TEXT("shows information about the variable in its argument")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(varinfo)
+	.cmd		= do_varinfo,
+	BAREBOX_CMD_DESC("show information about variables")
+	BAREBOX_CMD_OPTS("VAR")
+	BAREBOX_CMD_GROUP(CMD_GRP_INFO)
+	BAREBOX_CMD_HELP(cmd_varinfo_help)
+	BAREBOX_CMD_COMPLETE(env_param_plain_complete)
+BAREBOX_CMD_END
diff --git a/common/complete.c b/common/complete.c
index 6061c8ba6ecb..6cb674a0cc9c 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -366,6 +366,12 @@ int env_param_noeval_complete(struct string_list *sl, char *instr)
 }
 EXPORT_SYMBOL(env_param_noeval_complete);
 
+int env_param_plain_complete(struct string_list *sl, char *instr)
+{
+	return env_param_complete(sl, instr, 0);
+}
+EXPORT_SYMBOL(env_param_plain_complete);
+
 static int tab_pressed = 0;
 
 void complete_reset(void)
diff --git a/include/complete.h b/include/complete.h
index 2068760ac235..21d3c0430f64 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -24,6 +24,7 @@ int devicetree_nodepath_complete(struct string_list *sl, char *instr);
 int devicetree_complete(struct string_list *sl, char *instr);
 int devicetree_file_complete(struct string_list *sl, char *instr);
 int env_param_noeval_complete(struct string_list *sl, char *instr);
+int env_param_plain_complete(struct string_list *sl, char *instr);
 int tutorial_complete(struct string_list *sl, char *instr);
 
 #endif /* __COMPLETE_ */
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:21:13 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:21:13 +0100
Subject: [PATCH v2 1/2] scripts: define le32_to_cpup and friends for host/target tools
Message-ID: <20250320052114.1732651-1-a.fatoum@pengutronix.de>

We already define le32_to_cpu and friends, but were missing so far the
p-suffixed variant, which accepts a pointer.

This is easily implemented with a bit of macro boilerplate, so let's do
that.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 scripts/compiler.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/scripts/compiler.h b/scripts/compiler.h
index d8d0e1b906df..d6807b027e03 100644
--- a/scripts/compiler.h
+++ b/scripts/compiler.h
@@ -160,6 +160,27 @@ typedef uint32_t __u32;
 # define be64_to_cpu(x)		(x)
 #endif
 
+#define DEFINE_CONV_P(endian, bits) \
+	static inline __##endian##bits endian##bits##_to_cpup(const u##bits *p) \
+	{ \
+		u##bits val; \
+		memmove(&val, p, sizeof(val)); \
+		return endian##bits##_to_cpu(val); \
+	} \
+	static inline u##bits cpu_to_##endian##bits##p(const __##endian##bits *p) \
+	{ \
+		__##endian##bits val; \
+		memmove(&val, p, sizeof(val)); \
+		return cpu_to_##endian##bits(val); \
+	}
+
+DEFINE_CONV_P(le, 16)
+DEFINE_CONV_P(le, 32)
+DEFINE_CONV_P(le, 64)
+DEFINE_CONV_P(be, 16)
+DEFINE_CONV_P(be, 32)
+DEFINE_CONV_P(be, 64)
+
 #ifndef min
 #define min(x, y) ({                            \
 	typeof(x) _min1 = (x);                  \
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 19 22:21:14 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 06:21:14 +0100
Subject: [PATCH v2 2/2] booti: sanity check image magic before parsing header
In-Reply-To: <20250320052114.1732651-1-a.fatoum@pengutronix.de>
References: <20250320052114.1732651-1-a.fatoum@pengutronix.de>
Message-ID: <20250320052114.1732651-2-a.fatoum@pengutronix.de>

booti_load_image is called directly for kernels in FIT images.
Let's have a simple check that the payload is indeed a booti
image before parsing it.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - no change
---
 common/booti.c     | 11 +++++++++--
 common/filetype.c  |  6 +++---
 include/filetype.h | 11 +++++++++++
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/common/booti.c b/common/booti.c
index 5efd4f97bbc2..c8f6b5d4fc6d 100644
--- a/common/booti.c
+++ b/common/booti.c
@@ -4,6 +4,7 @@
 #define pr_fmt(fmt) "booti: " fmt
 
 #include <common.h>
+#include <filetype.h>
 #include <memory.h>
 #include <bootm.h>
 #include <linux/sizes.h>
@@ -38,13 +39,19 @@ void *booti_load_image(struct image_data *data, phys_addr_t *oftree)
 	int ret;
 	void *fdt;
 
+	print_hex_dump_bytes("header ", DUMP_PREFIX_OFFSET, kernel_header, 80);
+
+	if ((IS_ENABLED(CONFIG_RISCV) && !is_riscv_linux_bootimage(kernel_header)) ||
+	    (IS_ENABLED(CONFIG_ARM64) && !is_arm64_linux_bootimage(kernel_header))) {
+		pr_err("Unexpected magic at offset 0x38!\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	text_offset = le64_to_cpup(kernel_header + 8);
 	image_size = le64_to_cpup(kernel_header + 16);
 
 	kernel = get_kernel_address(data->os_address, text_offset);
 
-	print_hex_dump_bytes("header ", DUMP_PREFIX_OFFSET,
-			     kernel_header, 80);
 	pr_debug("Kernel to be loaded to %lx+%lx\n", kernel, image_size);
 
 	if (kernel == UIMAGE_INVALID_ADDRESS)
diff --git a/common/filetype.c b/common/filetype.c
index 73ea17e19bd7..2a68879ee5de 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -365,11 +365,11 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (bufsize < 64)
 		return filetype_unknown;
 
-	if (le32_to_cpu(buf[14]) == 0x644d5241)
+	if (is_arm64_linux_bootimage(buf))
 		return is_dos_exe(buf8) ? filetype_arm64_efi_linux_image : filetype_arm64_linux_image;
-	if (le32_to_cpu(buf[14]) == 0x05435352)
+	if (is_riscv_linux_bootimage(buf))
 		return is_dos_exe(buf8) ? filetype_riscv_efi_linux_image : filetype_riscv_linux_image;
-	if (le32_to_cpu(buf[14]) == 0x56435352 && !memcmp(&buf[12], "barebox", 8))
+	if (is_riscv_linux_bootimage(buf) && !memcmp(&buf[12], "barebox", 8))
 		return filetype_riscv_barebox_image;
 
 	if (le32_to_cpu(buf[5]) == 0x504d5453)
diff --git a/include/filetype.h b/include/filetype.h
index c24d061e8ffa..d445140edba1 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -4,6 +4,7 @@
 
 #include <linux/string.h>
 #include <linux/types.h>
+#include <asm/byteorder.h>
 
 /*
  * List of file types we know
@@ -134,4 +135,14 @@ static inline int is_barebox_head(const char *head)
 	return is_barebox_arm_head(head) || is_barebox_mips_head(head);
 }
 
+static inline bool is_arm64_linux_bootimage(const void *header)
+{
+	return le32_to_cpup(header + 56) == 0x644d5241;
+}
+
+static inline bool is_riscv_linux_bootimage(const void *header)
+{
+	return le32_to_cpup(header + 56) == 0x05435352;
+}
+
 #endif /* __FILE_TYPE_H */
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 20 01:24:26 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 09:24:26 +0100
Subject: [PATCH master 2/2] Revert "Documentation: remove info about bridging to matrix"
In-Reply-To: <20250320082426.2124644-1-a.fatoum@pengutronix.de>
References: <20250320082426.2124644-1-a.fatoum@pengutronix.de>
Message-ID: <20250320082426.2124644-2-a.fatoum@pengutronix.de>

We have a new Matrix-to-IRC bridge since March 9th and it should help
users without an IRC bouncer. Let's mention this again in the docs.

This reverts commit 7d2ee65d176776c8a5bad22804c5b30201dc6313.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Documentation/user/introduction.rst | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/user/introduction.rst b/Documentation/user/introduction.rst
index 7cd289d73e39..cba1d09986b8 100644
--- a/Documentation/user/introduction.rst
+++ b/Documentation/user/introduction.rst
@@ -49,4 +49,6 @@ and have ``FETCH_HEAD`` point at it::
 CI tests are executed by Github Actions can be used by forking
 `the project on Github <https://github.com/barebox/barebox>`.
 
-There's also an IRC channel: #barebox on Libera Chat
+There's also an IRC channel, which is
+`bridged to Matrix  <https://app.element.io/#/room/#barebox:matrix.org>`_:
+#barebox on Libera Chat.
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 20 01:24:25 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 09:24:25 +0100
Subject: [PATCH master 1/2] Documentation: user: intro: update feedback section on ML
Message-ID: <20250320082426.2124644-1-a.fatoum@pengutronix.de>

Now that kernel.org also mirrors barebox, we don't require the midmask,
linkmask configuration we had before.

Adapt the docs accordingly and explain shazam -H a bit.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Documentation/user/introduction.rst | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/Documentation/user/introduction.rst b/Documentation/user/introduction.rst
index d68b57e50333..7cd289d73e39 100644
--- a/Documentation/user/introduction.rst
+++ b/Documentation/user/introduction.rst
@@ -22,26 +22,31 @@ Feedback
 
 For sending patches, asking for help and giving general feedback you are
 always welcome to write an e-mail to the barebox mailing list at
-<mailto:barebox at lists.infradead.org>. Most of the
-discussion of barebox takes place here:
+`barebox at lists.infradead.org <mailto:barebox at lists.infradead.org>`_.
+Most of the discussion of barebox takes place here:
 
 http://lists.infradead.org/mailman/listinfo/barebox/
 
 Mails sent to the barebox mailing list are archived on
-`lore.barebox.org <https://lore.barebox.org/barebox/>`_.
+`lore.barebox.org <https://lore.barebox.org/barebox/>`_ and
+`lore.kernel.org <https://lore.kernel.org/barebox/>`_.
 
 barebox uses a similar patch process as the Linux kernel, so most of the
 `Linux guide for submitting patches <https://www.kernel.org/doc/html/latest/process/submitting-patches.html>`_
-also applies to barebox, except forthe need to select your recipient;
+also applies to barebox, except for the need to select your recipient;
 all barebox patches go to the same list.
 
-Patch series sent there can be applied with `b4 <https://pypi.org/project/b4/>`_ ::
+Patch series can be sent and fetched from the list using `b4 <https://pypi.org/project/b4/>`_ ::
 
-   git config b4.midmask https://lore.barebox.org/%s
-   git config b4.linkmask https://lore.barebox.org/%s
    b4 shazam -M https://lore.barebox.org/$messageid # replace with link
 
-CI tests are executed by Github Actions an be used by forking
+Fixes should apply on master and new features on the next branch.
+If a series fails to apply, ``b4`` can determine/guess the base
+and have ``FETCH_HEAD`` point at it::
+
+   b4 shazam -H https://lore.kernel.org/$messageid # URL can be omitted
+
+CI tests are executed by Github Actions can be used by forking
 `the project on Github <https://github.com/barebox/barebox>`.
 
 There's also an IRC channel: #barebox on Libera Chat
-- 
2.39.5



From eagle.alexander923 at gmail.com  Thu Mar 20 02:14:13 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Thu, 20 Mar 2025 12:14:13 +0300
Subject: [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure
Message-ID: <20250320091419.42095-1-eagle.alexander923@gmail.com>

The loader function structures use the same members,
so they can be rewritten to use a single xload_instance structure.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/xload.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 9c03d2119c..4e7e80379f 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -11,6 +11,13 @@
 #include <asm/cache.h>
 #include <pbl/bio.h>
 
+struct xload_instance {
+	void __iomem *base;
+	unsigned id;
+	u8 periph;
+	s8 pins[15];
+};
+
 static void at91_fat_start_image(struct pbl_bio *bio,
 				 void *buf, unsigned int len,
 				 u32 r4)
@@ -31,12 +38,7 @@ static void at91_fat_start_image(struct pbl_bio *bio,
 	sama5_boot_xload(bb, r4);
 }
 
-static const struct sdhci_instance {
-	void __iomem *base;
-	unsigned id;
-	u8 periph;
-	s8 pins[15];
-} sdhci_instances[] = {
+static const struct xload_instance sama5d2_mci_instances[] = {
 	[0] = {
 		.base = SAMA5D2_BASE_SDHC0, .id = SAMA5D2_ID_SDMMC0, .periph = AT91_MUX_PERIPH_A,
 		.pins = { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 13, 10, 11, 12, -1 }
@@ -54,16 +56,16 @@ static const struct sdhci_instance {
 void __noreturn sama5d2_sdhci_start_image(u32 r4)
 {
 	void *buf = (void *)SAMA5_DDRCS;
-	const struct sdhci_instance *instance;
+	const struct xload_instance *instance;
 	struct pbl_bio bio;
 	const s8 *pin;
 	int ret;
 
 	ret = sama5_bootsource_instance(r4);
-	if (ret > 1)
+	if (ret > ARRAY_SIZE(sama5d2_mci_instances) - 1)
 		panic("Couldn't determine boot MCI instance\n");
 
-	instance = &sdhci_instances[ret];
+	instance = &sama5d2_mci_instances[ret];
 
 	sama5d2_pmc_enable_periph_clock(SAMA5D2_ID_PIOA);
 	for (pin = instance->pins; *pin >= 0; pin++) {
@@ -86,12 +88,7 @@ void __noreturn sama5d2_sdhci_start_image(u32 r4)
 	panic("FAT chainloading failed\n");
 }
 
-static const struct atmci_instance {
-	void __iomem *base;
-	unsigned id;
-	u8 periph;
-	s8 pins[15];
-} sama5d3_atmci_instances[] = {
+static const struct xload_instance sama5d3_mci_instances[] = {
 	[0] = {
 		.base = IOMEM(SAMA5D3_BASE_HSMCI0),
 		.id = SAMA5D3_ID_HSMCI0,
@@ -107,16 +104,16 @@ void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
 					  unsigned int slot)
 {
 	void *buf = (void *)SAMA5_DDRCS;
-	const struct atmci_instance *instance;
+	const struct xload_instance *instance;
 	struct pbl_bio bio;
 	const s8 *pin;
 	int ret;
 
 	ret = sama5_bootsource_instance(boot_src);
-	if (ret > ARRAY_SIZE(sama5d3_atmci_instances) - 1)
+	if (ret > ARRAY_SIZE(sama5d3_mci_instances) - 1)
 		panic("Couldn't determine boot MCI instance\n");
 
-	instance = &sama5d3_atmci_instances[boot_src];
+	instance = &sama5d3_mci_instances[boot_src];
 
 	sama5d3_pmc_enable_periph_clock(SAMA5D3_ID_PIOD);
 	for (pin = instance->pins; *pin >= 0; pin++) {
-- 
2.39.1



From eagle.alexander923 at gmail.com  Thu Mar 20 02:14:14 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Thu, 20 Mar 2025 12:14:14 +0300
Subject: [PATCH 2/7] ARM: at91: xload: Replace magic values with definitions
In-Reply-To: <20250320091419.42095-1-eagle.alexander923@gmail.com>
References: <20250320091419.42095-1-eagle.alexander923@gmail.com>
Message-ID: <20250320091419.42095-2-eagle.alexander923@gmail.com>

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/xload.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 4e7e80379f..fee2c715ec 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -40,12 +40,25 @@ static void at91_fat_start_image(struct pbl_bio *bio,
 
 static const struct xload_instance sama5d2_mci_instances[] = {
 	[0] = {
-		.base = SAMA5D2_BASE_SDHC0, .id = SAMA5D2_ID_SDMMC0, .periph = AT91_MUX_PERIPH_A,
-		.pins = { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 13, 10, 11, 12, -1 }
+		.base = SAMA5D2_BASE_SDHC0,
+		.id = SAMA5D2_ID_SDMMC0,
+		.periph = AT91_MUX_PERIPH_A,
+		.pins = {
+			AT91_PIN_PA2, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5,
+			AT91_PIN_PA6, AT91_PIN_PA7, AT91_PIN_PA8, AT91_PIN_PA9,
+			AT91_PIN_PA0, AT91_PIN_PA1, AT91_PIN_PA13, AT91_PIN_PA10,
+			AT91_PIN_PA11, AT91_PIN_PA12, -1
+		}
 	},
 	[1] = {
-		.base = SAMA5D2_BASE_SDHC1, .id = SAMA5D2_ID_SDMMC1, .periph = AT91_MUX_PERIPH_E,
-		.pins = { 18, 19, 20, 21, 22, 28, 30, -1 }
+		.base = SAMA5D2_BASE_SDHC1,
+		.id = SAMA5D2_ID_SDMMC1,
+		.periph = AT91_MUX_PERIPH_E,
+		.pins = {
+			AT91_PIN_PA18, AT91_PIN_PA19, AT91_PIN_PA20,
+			AT91_PIN_PA21, AT91_PIN_PA22, AT91_PIN_PA28,
+			AT91_PIN_PA30, -1
+		}
 	},
 };
 
-- 
2.39.1



From eagle.alexander923 at gmail.com  Thu Mar 20 02:14:15 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Thu, 20 Mar 2025 12:14:15 +0300
Subject: [PATCH 3/7] ARM: at91: xload: Remove len argument from at91_fat_start_image()
In-Reply-To: <20250320091419.42095-1-eagle.alexander923@gmail.com>
References: <20250320091419.42095-1-eagle.alexander923@gmail.com>
Message-ID: <20250320091419.42095-3-eagle.alexander923@gmail.com>

The len argument to at91_fat_start_image() is common for all callers,
so it can be removed.
While we're at it, let's reduce the maximum image load size,
since 2M is sufficient for all cases.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/xload.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index fee2c715ec..4fec02afe1 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -18,14 +18,12 @@ struct xload_instance {
 	s8 pins[15];
 };
 
-static void at91_fat_start_image(struct pbl_bio *bio,
-				 void *buf, unsigned int len,
-				 u32 r4)
+static void at91_fat_start_image(struct pbl_bio *bio, void *buf, u32 r4)
 {
 	void __noreturn (*bb)(void);
 	int ret;
 
-	ret = pbl_fat_load(bio, "barebox.bin", buf, len);
+	ret = pbl_fat_load(bio, "barebox.bin", buf, SZ_2M);
 	if (ret < 0) {
 		pr_err("pbl_fat_load: error %d\n", ret);
 		return;
@@ -95,7 +93,7 @@ void __noreturn sama5d2_sdhci_start_image(u32 r4)
 
 	/* TODO: eMMC boot partition handling: they are not FAT-formatted */
 
-	at91_fat_start_image(&bio, buf, SZ_16M, r4);
+	at91_fat_start_image(&bio, buf, r4);
 
 out_panic:
 	panic("FAT chainloading failed\n");
@@ -131,7 +129,7 @@ void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
 	sama5d3_pmc_enable_periph_clock(SAMA5D3_ID_PIOD);
 	for (pin = instance->pins; *pin >= 0; pin++) {
 		at91_mux_pio3_pin(IOMEM(SAMA5D3_BASE_PIOD),
-					 pin_to_mask(*pin), instance->periph, 0);
+				  pin_to_mask(*pin), instance->periph, 0);
 	}
 
 	sama5d3_pmc_enable_periph_clock(instance->id);
@@ -140,7 +138,7 @@ void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
 	if (ret)
 		goto out_panic;
 
-	at91_fat_start_image(&bio, buf, SZ_16M, boot_src);
+	at91_fat_start_image(&bio, buf, boot_src);
 
 out_panic:
 	panic("FAT chainloading failed\n");
-- 
2.39.1



From eagle.alexander923 at gmail.com  Thu Mar 20 02:14:16 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Thu, 20 Mar 2025 12:14:16 +0300
Subject: [PATCH 4/7] ARM: at91: xload: Use the variable name as described in include/mach/at91/xload.h
In-Reply-To: <20250320091419.42095-1-eagle.alexander923@gmail.com>
References: <20250320091419.42095-1-eagle.alexander923@gmail.com>
Message-ID: <20250320091419.42095-4-eagle.alexander923@gmail.com>

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/xload.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 4fec02afe1..94be353c9e 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -111,7 +111,7 @@ static const struct xload_instance sama5d3_mci_instances[] = {
 	},
 };
 
-void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
+void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
 					  unsigned int slot)
 {
 	void *buf = (void *)SAMA5_DDRCS;
@@ -120,11 +120,11 @@ void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
 	const s8 *pin;
 	int ret;
 
-	ret = sama5_bootsource_instance(boot_src);
+	ret = sama5_bootsource_instance(r4);
 	if (ret > ARRAY_SIZE(sama5d3_mci_instances) - 1)
 		panic("Couldn't determine boot MCI instance\n");
 
-	instance = &sama5d3_mci_instances[boot_src];
+	instance = &sama5d3_mci_instances[r4];
 
 	sama5d3_pmc_enable_periph_clock(SAMA5D3_ID_PIOD);
 	for (pin = instance->pins; *pin >= 0; pin++) {
@@ -138,7 +138,7 @@ void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
 	if (ret)
 		goto out_panic;
 
-	at91_fat_start_image(&bio, buf, boot_src);
+	at91_fat_start_image(&bio, buf, r4);
 
 out_panic:
 	panic("FAT chainloading failed\n");
-- 
2.39.1



From eagle.alexander923 at gmail.com  Thu Mar 20 02:14:17 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Thu, 20 Mar 2025 12:14:17 +0300
Subject: [PATCH 5/7] ARM: at91: xload: Remove intermediate variable
In-Reply-To: <20250320091419.42095-1-eagle.alexander923@gmail.com>
References: <20250320091419.42095-1-eagle.alexander923@gmail.com>
Message-ID: <20250320091419.42095-5-eagle.alexander923@gmail.com>

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/xload.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 94be353c9e..7a990f35c8 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -20,7 +20,6 @@ struct xload_instance {
 
 static void at91_fat_start_image(struct pbl_bio *bio, void *buf, u32 r4)
 {
-	void __noreturn (*bb)(void);
 	int ret;
 
 	ret = pbl_fat_load(bio, "barebox.bin", buf, SZ_2M);
@@ -29,11 +28,9 @@ static void at91_fat_start_image(struct pbl_bio *bio, void *buf, u32 r4)
 		return;
 	}
 
-	bb = buf;
-
 	sync_caches_for_execution();
 
-	sama5_boot_xload(bb, r4);
+	sama5_boot_xload(buf, r4);
 }
 
 static const struct xload_instance sama5d2_mci_instances[] = {
-- 
2.39.1



From eagle.alexander923 at gmail.com  Thu Mar 20 02:14:18 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Thu, 20 Mar 2025 12:14:18 +0300
Subject: [PATCH 6/7] ARM: at91: xload: Rename the sama5d2 output image names
In-Reply-To: <20250320091419.42095-1-eagle.alexander923@gmail.com>
References: <20250320091419.42095-1-eagle.alexander923@gmail.com>
Message-ID: <20250320091419.42095-6-eagle.alexander923@gmail.com>

Let's make the sama5d2_start_image() function dependent on the
bootsource rather than MMC-specific, so let's rename the calls
and output image names to reflect that.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/boards/sama5d27-giantboard/lowlevel.c |  4 ++--
 arch/arm/boards/sama5d27-som1/lowlevel.c       |  4 ++--
 arch/arm/mach-at91/xload.c                     | 15 ++++++++++++++-
 images/Makefile.at91                           | 16 ++++++++--------
 include/mach/at91/xload.h                      |  2 +-
 5 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/arch/arm/boards/sama5d27-giantboard/lowlevel.c b/arch/arm/boards/sama5d27-giantboard/lowlevel.c
index 49540bede0..20042e649d 100644
--- a/arch/arm/boards/sama5d27-giantboard/lowlevel.c
+++ b/arch/arm/boards/sama5d27-giantboard/lowlevel.c
@@ -15,7 +15,7 @@
 /* PCK = 492MHz, MCK = 164MHz */
 #define MASTER_CLOCK	164000000
 
-SAMA5D2_ENTRY_FUNCTION(start_sama5d27_giantboard_xload_mmc, r4)
+SAMA5D2_ENTRY_FUNCTION(start_sama5d27_giantboard_xload, r4)
 {
 	void __iomem *dbgu_base;
 
@@ -31,7 +31,7 @@ SAMA5D2_ENTRY_FUNCTION(start_sama5d27_giantboard_xload_mmc, r4)
 
 	sama5d2_udelay_init(MASTER_CLOCK);
 	sama5d2_d1g_ddrconf();
-	sama5d2_sdhci_start_image(r4);
+	sama5d2_start_image(r4);
 }
 
 extern char __dtb_z_at91_sama5d27_giantboard_start[];
diff --git a/arch/arm/boards/sama5d27-som1/lowlevel.c b/arch/arm/boards/sama5d27-som1/lowlevel.c
index 67300587fe..633e15898e 100644
--- a/arch/arm/boards/sama5d27-som1/lowlevel.c
+++ b/arch/arm/boards/sama5d27-som1/lowlevel.c
@@ -39,7 +39,7 @@ static void ek_turn_led(unsigned color)
 	}
 }
 
-SAMA5D2_ENTRY_FUNCTION(start_sama5d27_som1_ek_xload_mmc, r4)
+SAMA5D2_ENTRY_FUNCTION(start_sama5d27_som1_ek_xload, r4)
 {
 	void __iomem *dbgu_base;
 	sama5d2_lowlevel_init();
@@ -55,7 +55,7 @@ SAMA5D2_ENTRY_FUNCTION(start_sama5d27_som1_ek_xload_mmc, r4)
 	ek_turn_led(RGB_LED_RED | RGB_LED_GREEN); /* Yellow */
 	sama5d2_udelay_init(MASTER_CLOCK);
 	sama5d2_d1g_ddrconf();
-	sama5d2_sdhci_start_image(r4);
+	sama5d2_start_image(r4);
 }
 
 extern char __dtb_z_at91_sama5d27_som1_ek_start[];
diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 7a990f35c8..d3bc6f2dc9 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -61,7 +61,7 @@ static const struct xload_instance sama5d2_mci_instances[] = {
  * sama5d2_sdhci_start_image - Load and start an image from FAT-formatted SDHCI
  * @r4: value of r4 passed by BootROM
  */
-void __noreturn sama5d2_sdhci_start_image(u32 r4)
+static void __noreturn sama5d2_sdhci_start_image(u32 r4)
 {
 	void *buf = (void *)SAMA5_DDRCS;
 	const struct xload_instance *instance;
@@ -96,6 +96,19 @@ void __noreturn sama5d2_sdhci_start_image(u32 r4)
 	panic("FAT chainloading failed\n");
 }
 
+void __noreturn sama5d2_start_image(u32 r4)
+{
+	switch (sama5_bootsource(r4)) {
+	case BOOTSOURCE_MMC:
+		sama5d2_sdhci_start_image(r4);
+		break;
+	default:
+		break;
+	}
+
+	panic("Unsupported boot configuration!\n");
+}
+
 static const struct xload_instance sama5d3_mci_instances[] = {
 	[0] = {
 		.base = IOMEM(SAMA5D3_BASE_HSMCI0),
diff --git a/images/Makefile.at91 b/images/Makefile.at91
index 81e7c22e8b..54f75624ed 100644
--- a/images/Makefile.at91
+++ b/images/Makefile.at91
@@ -42,19 +42,19 @@ pblb-$(CONFIG_MACH_SAMA5D27_SOM1) += start_sama5d27_som1_ek
 FILE_barebox-sama5d27-som1-ek.img = start_sama5d27_som1_ek.pblb
 image-$(CONFIG_MACH_SAMA5D27_SOM1) += barebox-sama5d27-som1-ek.img
 
-pblb-$(CONFIG_MACH_SAMA5D27_SOM1) += start_sama5d27_som1_ek_xload_mmc
-MAX_PBL_IMAGE_SIZE_start_sama5d27_som1_ek_xload_mmc = 0x10000
-FILE_barebox-sama5d27-som1-ek-xload-mmc.img = start_sama5d27_som1_ek_xload_mmc.pblb
-image-$(CONFIG_MACH_SAMA5D27_SOM1) += barebox-sama5d27-som1-ek-xload-mmc.img
+pblb-$(CONFIG_MACH_SAMA5D27_SOM1) += start_sama5d27_som1_ek_xload
+MAX_PBL_IMAGE_SIZE_start_sama5d27_som1_ek_xload = 0x10000
+FILE_barebox-sama5d27-som1-ek-xload.img = start_sama5d27_som1_ek_xload.pblb
+image-$(CONFIG_MACH_SAMA5D27_SOM1) += barebox-sama5d27-som1-ek-xload.img
 
 pblb-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += start_sama5d27_giantboard
 FILE_barebox-groboards-sama5d27-giantboard.img = start_sama5d27_giantboard.pblb
 image-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += barebox-groboards-sama5d27-giantboard.img
 
-pblb-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += start_sama5d27_giantboard_xload_mmc
-FILE_barebox-groboards-sama5d27-giantboard-xload-mmc.img = start_sama5d27_giantboard_xload_mmc.pblb
-MAX_PBL_IMAGE_SIZE_start_sama5d27_giantboard_xload_mmc = 0xffff
-image-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += barebox-groboards-sama5d27-giantboard-xload-mmc.img
+pblb-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += start_sama5d27_giantboard_xload
+FILE_barebox-groboards-sama5d27-giantboard-xload.img = start_sama5d27_giantboard_xload.pblb
+MAX_PBL_IMAGE_SIZE_start_sama5d27_giantboard_xload = 0x10000
+image-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += barebox-groboards-sama5d27-giantboard-xload.img
 
 pblb-$(CONFIG_MACH_SKOV_ARM9CPU) += start_skov_arm9cpu_xload_mmc
 FILE_barebox-skov-arm9cpu-xload-mmc.img = start_skov_arm9cpu_xload_mmc.pblb
diff --git a/include/mach/at91/xload.h b/include/mach/at91/xload.h
index 2886490246..d5fc7596fd 100644
--- a/include/mach/at91/xload.h
+++ b/include/mach/at91/xload.h
@@ -6,7 +6,7 @@
 #include <linux/compiler.h>
 #include <pbl/bio.h>
 
-void __noreturn sama5d2_sdhci_start_image(u32 r4);
+void __noreturn sama5d2_start_image(u32 r4);
 void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
 					  unsigned int slot);
 
-- 
2.39.1



From eagle.alexander923 at gmail.com  Thu Mar 20 02:14:19 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Thu, 20 Mar 2025 12:14:19 +0300
Subject: [PATCH 7/7] ARM: at91: xload: Add QSPI boot support for SAMA5D2
In-Reply-To: <20250320091419.42095-1-eagle.alexander923@gmail.com>
References: <20250320091419.42095-1-eagle.alexander923@gmail.com>
Message-ID: <20250320091419.42095-7-eagle.alexander923@gmail.com>

This adds QSPI NOR boot support for sama5d2 CPUs.
One first-stage (after ROMboot) xload image can now boot from
both MMC and QSPI.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/xload.c | 84 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index d3bc6f2dc9..5d8105f07f 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <common.h>
+#include <filetype.h>
 #include <mach/at91/xload.h>
 #include <mach/at91/sama5_bootsource.h>
 #include <mach/at91/hardware.h>
@@ -96,12 +97,95 @@ static void __noreturn sama5d2_sdhci_start_image(u32 r4)
 	panic("FAT chainloading failed\n");
 }
 
+static const struct xload_instance sama5d2_qspi_ioset1_instances[] = {
+	[0] = {
+		.base = SAMA5D2_BASE_QSPI0,
+		.id = SAMA5D2_ID_QSPI0,
+		.periph = AT91_MUX_PERIPH_B,
+		.pins = {
+			AT91_PIN_PA0, AT91_PIN_PA1, AT91_PIN_PA2,
+			AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, -1
+		}
+	},
+	[1] = {
+		.base = SAMA5D2_BASE_QSPI1,
+		.id = SAMA5D2_ID_QSPI1,
+		.periph = AT91_MUX_PERIPH_B,
+		.pins = {
+			AT91_PIN_PA6, AT91_PIN_PA7, AT91_PIN_PA8,
+			AT91_PIN_PA9, AT91_PIN_PA10, AT91_PIN_PA11, -1
+		}
+	},
+};
+
+/**
+ * sama5d2_qspi_start_image - Start an image from QSPI NOR flash
+ * @r4: value of r4 passed by BootROM
+ */
+static void __noreturn sama5d2_qspi_start_image(u32 r4)
+{
+	void __iomem *mem, *dest = IOMEM(SAMA5_DDRCS);
+	const struct xload_instance *instance;
+	const s8 *pin;
+	u32 offs;
+	int ret;
+
+	ret = sama5_bootsource_instance(r4);
+	if (ret == 0)
+		mem = SAMA5D2_BASE_QSPI0_MEM;
+	else if (ret == 1)
+		mem = SAMA5D2_BASE_QSPI1_MEM;
+	else
+		panic("Couldn't determine boot QSPI instance\n");
+
+	instance = &sama5d2_qspi_ioset1_instances[ret];
+
+	sama5d2_pmc_enable_periph_clock(SAMA5D2_ID_PIOA);
+	for (pin = instance->pins; *pin >= 0; pin++)
+		at91_mux_pio4_set_periph(SAMA5D2_BASE_PIOA,
+					 BIT(*pin), instance->periph);
+
+	sama5d2_pmc_enable_periph_clock(instance->id);
+
+	/*
+	 * Since we booted from QSPI, we expect the QSPI registers to be
+	 * properly initialized already.
+	 * Let's just read the memory-mapped data.
+	 */
+
+	/* Find barebox pattern first */
+	for (offs = SZ_128K; offs <= SZ_1M; offs += SZ_128K) {
+		/* Fix cache coherency issue by reading each sector only once */
+		memcpy(dest, mem + offs, SZ_128K);
+
+		if (is_barebox_arm_head(dest)) {
+			u32 size = readl(dest + ARM_HEAD_SIZE_OFFSET);
+
+			pr_info("Image found at 0x%08x, size %u\n", offs, size);
+
+			/* Copy remaining barebox code */
+			if (size > SZ_128K)
+				memcpy(dest + SZ_128K, mem + offs + SZ_128K,
+				       size - SZ_128K);
+
+			sync_caches_for_execution();
+
+			sama5_boot_xload(dest, r4);
+		}
+	}
+
+	panic("No barebox image found!\n");
+}
+
 void __noreturn sama5d2_start_image(u32 r4)
 {
 	switch (sama5_bootsource(r4)) {
 	case BOOTSOURCE_MMC:
 		sama5d2_sdhci_start_image(r4);
 		break;
+	case BOOTSOURCE_SPI:
+		sama5d2_qspi_start_image(r4);
+		break;
 	default:
 		break;
 	}
-- 
2.39.1



From s.hauer at pengutronix.de  Thu Mar 20 02:22:15 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Mar 2025 10:22:15 +0100
Subject: v2025.03.0
Message-ID: <Z9veR3N6puizrAT8@pengutronix.de>

Hi All,

I am happy to announce barebox-2025.02.0.

This release introduces support for Sunxi SoCs. barebox can now run on a
Pine64+ as a generic barebox-dt-2nd.img image. Thanks Jules for working
on this.

MMCs are now much faster to erase, reportedly up 60x faster.

Linux now has support for the fixed partition device tree binding for
block devices. barebox had the same for a long time, but differently. In
barebox we register both partitions from the partition table and the
device tree. In Linux both are used exclusively, once a device tree
partitioning is found the partition table on the disk is ignored. For
this reason barebox now uses barebox,fixed-partitions as compatible.

The i.MX HAB support now supports revoking keys and burning the field
return fuse.

The K3 support continues to evolve as well, with this release we can
boot from eMMC boot partitions and fully bootstrap the SoC over USB DFU.

One nice thing worth noting is the support for overriding boot
artifacts. With this we can boot regular bootspec entries or scripts,
but replace Kernel, device tree or initrd with one specified on the
command line. This is good for "injecting" an artifact into the regular
boot flow.

See below for a full list of changes for this release.

Have Fun!
 Sascha

----------------------------------------------------------------
Ahmad Fatoum (52):
      commands: readlink: print to stdout if variable is missing
      startup: add new AUTOBOOT_HALT state
      kbuild: allow overriding mkimage
      kbuild: allow overriding compression tools
      cdev: merge identical partitions despite DEVFS_PARTITION_CAN_OVERLAP
      cmdlinepart: refuse partitions with empty name
      bootm: change default verification mode from hash to available
      FIT: factor out fit_fdt_is_compatible for readability
      FIT: do not decompress device trees to find compatible
      bootm: add helper functions for checking if FIT image is used
      boot: move global.linux.bootargs.dyn. to common code
      blspec: don't clobber bootm.image on boot attempt
      fastboot: drop useless bootm.image clobber
      bootm: don't clobber global.bootm. variables after script boot fails
      bootm: retire bootm_has_initrd
      commands: boot: add support for overriding boot artifacts
      mount: support specifying mount -o options more than once
      lib: add scatterlist abstraction
      virtio: replace virtio_sg with common scatterlist
      virtio: add token data parameter to virtqueue_add_sgs
      boot: omit menu freeing loop when CONFIG_MENU is disabled
      fs: move fs_driver open/close into struct file_operations
      fs: remove unused members in struct file_operations
      fs: drop unused FS_DRIVER_NO_DEV flag
      nfs: add $global.net.nfsport override
      usb: dwc3: fix use of bool for prompt choice
      kbuild: export HOSTPKG_CONFIG like Linux does
      sandbox: make CC_HAS_LINUX_I386_SUPPORT depend on GCC
      Makefile: clang: fix typo in -Wno-typdef-redefinition flag
      kbuild: actually include Makefile.clang for clang builds
      Makefile: clang: fail non-sandbox LLVM builds early
      mci: core: import Linux logic for higher preferred erase size
      mci: core: reset ERASE_GRP_DEF on startup
      of: factor out of_node_is_fixed_partitions check
      of: of_path: support barebox,fixed-partitions
      ARM: IMX8MP: var-dart-dt8mcustomboard.dts: use new-style partition binding
      ARM: dts: prefix all non-MTD fixed-partitions with barebox,
      of: partition: refactor of_partition_binding checks into switch
      of: partition: add Linux CONFIG_OF_PARTITION-compatible adaptive fixup mode
      sandbox: configs: disable CONFIG_NET_NETCONSOLE in sandbox_defconfig
      malloc: define a maximum malloc size
      tlsf: fail allocations exceeding MALLOC_MAX_SIZE
      dlmalloc: fail allocations exceeding MALLOC_MAX_SIZE
      sandbox: libc_malloc: fail allocations exceeding MALLOC_MAX_SIZE
      dummy_malloc: fail allocations exceeding MALLOC_MAX_SIZE
      test: self: malloc: adapt to addition of MALLOC_MAX_SIZE
      sandbox: libc_malloc: multiply, not add, args in calloc overflow check
      nfs: rename global.net.nfsport to global.nfs.port
      Documentation: user: networking: fix trivial typo
      FIT: early exit if digest fails
      net: am65-cpsw-nuss: fix out-of-bounds access
      partition: fix reference to wrong cdev in warning message

Alexander Shiyan (9):
      phy: rockchip-inno-usb2: Add support for RK3588 PHY
      phy: rockchip: add usbdp combo phy driver
      aiodev: rockchip_saradc: Add reset control support
      aiodev: rockchip_saradc: Prepare driver to add support for other SARADC variants
      aiodev: rockchip_saradc: Add support for RK3588
      gpio: add driver for SAMA5D2 PIOBU pins
      arch: treewide: Cleanup generated devicetree overlay objects
      i2c: Remove dead link to struct i2c_algorithm
      i2c: rockchip: Replace driver from kernel repository

Bastian Krause (3):
      mfd: rn5t568: add priority to reset_source_set_device()
      ARM: i.MX9: tqma93xx: remove mach/imx/romapi.h include
      commands: fix typo in CMD_AUTOMOUNT

David Dgien (1):
      kbuild: Use uname for BAREBOX_COMPILE_HOST

Jonas Rebmann (3):
      ci: add workflow for coverity analysis
      ci: add workflow for CodeQL analysis
      ci: add workflow for CodeQL analysis

Jules Maselbas (7):
      scripts: include: rename printk.h to printf.h
      clk: divider: add error code propagation
      clk: Add clock driver for sun50i-a64
      pinctrl: Add sun50i-a64 pinctrl driver
      mci: Add sunxi-mmc driver
      ARM: sunxi: Introduce mach-sunxi
      Documentation: sunxi: Add some documentation

Marco Felsch (9):
      nvmem: ocotp: add support to get/set srk_revoke sticky bit
      nvmem: ocotp: add support to query the field-return sticky bit
      hab: convert flags to use BIT() macro
      i.MX: HAB: add imx_hab_revoke_key support
      i.MX: HABv4: add more i.MX8M fuse defines
      i.MX8M: HABv4: add an option to allow key revocation
      i.MX8M: HABv4: add option to allow burning the field-return fuse
      i.MX: HAB: add imx_hab_field_return support
      i.MX: HAB: fix i.MX8MP field-return fuse

Michael Grzeschik (4):
      PWM: imx: pwm-imx-tpm: Add driver support
      ARM: i.MX93: ele: make A0 firmware optional
      video: simple-panel: add regulator support
      ARM: i.MX93: allow board code to configure the bl33 loadaddr

Michiel Schelfhout (3):
      ARM: protonic-stm32mp1: Add support for Plymovent AMQ board
      ARM: protonic-stm32mp1: Add support for reading serial from BSEC
      ARM: protonic-stm32mp1: Add shift register support for board ID and revision

Oliver ROHE (1):
      partition: msdos: fix partuuid format

Renaud Barbier (1):
      nvme: add erase operation through sanitize command

Sascha Hauer (58):
      usb: gadget: dfu: detect devices when necessary
      ARM: k3: am625: fixup Linux device tree
      ARM: k3: am625: apply RTC i2327 erratum fixup
      dts: update to v6.14-rc1
      soc: k3: Add support for Texas Instruments K3 ESM driver
      mfd: tps65219: register regmap cdev
      dts: update to v6.14-rc2
      ARM: k3: Add function to enable 32k crystal
      ARM: k3: add function to detect eMMC boot
      ARM: k3: do not mount /boot when booting from eMMC
      fip: drop typedefs
      fip: use linux list implementation
      fip: use uuid_equal() and uuid_is_null()
      fiptool: do not typedef structs
      fip: add fip_ prefix
      fip: add fip_image_open()
      ARM: k3: r5: add USB DFU and eMMC boot support
      ARM: am625-sk: enable 32k crystal
      mci: am654: parse generic mmc node properties
      ARM: k3: limit eMMC frequency to 26MHz
      ARM: k3: add eMMC barebox update handler
      dts: update to v6.14-rc3
      ARM: am625-sk: put environment on eMMC when booting from it
      serial: omap: Use ttyS as Linux console name
      ARM: k3: remove beagleplay FIT image
      ARM: am625-sk: cleanup board entry
      ARM: beagleplay: cleanup board entry
      test: create K3 dummy firmware files
      ci: container: add python3-yaml for K3
      ddr: k3: fix includes
      ARM: k3: Add k3-r5_defconfig
      usb: dwc3: am62: Use HZ_PER_KHZ
      usb: dwc3: am62: set mode valid bit before probing children
      boot: fix systemd watchdog command line argument
      Merge branch 'for-next/allwinner'
      Merge branch 'for-next/bootm-override'
      Merge branch 'for-next/dts'
      Merge branch 'for-next/imx'
      Merge branch 'for-next/imx-hab'
      Merge branch 'for-next/k3'
      Merge branch 'for-next/misc'
      Merge branch 'for-next/of-partition'
      Merge branch 'for-next/rockchip'
      Merge branch 'for-next/stm32mp1'
      fip: Store image data in single buffer
      fip: add function to parse FIP from a buffer
      parted: add partition type msdos to help text
      ARM: i.MX6: Enable PBL_VERIFY_PIGGY with HABV4 support
      ARM: i.MX9: Enable PBL_VERIFY_PIGGY with non INSECURE
      bootm: let BOOTM_OPTIONAL_SIGNED_IMAGES depend on BOOTM
      firmware: export firmware directory
      ARM: k3r5: Honour CONFIG_EXTRA_FIRMWARE_DIR
      Revert "ci: add workflow for CodeQL analysis"
      watchdog: rti_wdt: return 0 even when not ready for ping
      net: am65-cpsw-nuss: remove unused variables
      ARM: am335x_mlo_defconfig: disable unnecessary options
      serial: omap: make Linux console name configurable
      Release v2025.03.0

Stefan Kerkmann (2):
      i.mx8: ocotp: add GPx_LOCK defines
      hab: lock GP5 on i.MX8MP socs

Steffen Trumtrar (1):
      ARM: Layerscape: LS1046a: select early i2c

-- 
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-5555 |


From jonas.licht at gmail.com  Thu Mar 20 02:22:27 2025
From: jonas.licht at gmail.com (Jonas Licht)
Date: Thu, 20 Mar 2025 10:22:27 +0100
Subject: [PATCH v3] environment: support reading and writing of efivar
In-Reply-To: <20250311141713.30947-1-jonas.licht@gmail.com>
References: <20250311141713.30947-1-jonas.licht@gmail.com>
Message-ID: <20250320092300.21427-2-jonas.licht@gmail.com>

scripts/bareboxenv: skip file creation to allow reading the destination
file, when existing.

In envfs_load before reading the superblock, we check if our superblock
magic exists after an EFIVAR_ATTR_SIZE offset. This is necessary because
linux kernel adds four byte variable attributes in front of each efi
variable in sysfs. When the magic is found after EFIVAR_ATTR_SIZE, we
skip reading the four bytes variable attributes.
For envfs_save detection of an efi var is done the same way. But we need
to keep the attributes, as they are required for writing as well.

In order to write to efivars, you still need to remove immutable flag
from the file with 'chattr -i' .

Signed-off-by: Jonas Licht <jonas.licht at gmail.com>
Fixes: #29
Link: https://github.com/barebox/barebox/issues/29
---
Skip the detect code when __BAREBOX__ is defined as well.
I've noticed that the first pread in detect_efi_vars never comes back
in __BAREBOX__ , when the efivar file don't exists, but doing this on a
file at /tmp works.

 common/environment.c | 84 ++++++++++++++++++++++++++++++++++++++++----
 scripts/Makefile     |  2 ++
 scripts/bareboxenv.c | 11 +-----
 3 files changed, 80 insertions(+), 17 deletions(-)

diff --git a/common/environment.c b/common/environment.c
index 37adb5d678..70639e4037 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -32,8 +32,11 @@
 #include <magicvar.h>
 #else
 #define EXPORT_SYMBOL(x)
+#include <autoconf.h>
 #endif
 
+#define EFIVAR_ATTR_SIZE 4
+
 struct envfs_entry {
 	char *name;
 	void *buf;
@@ -290,6 +293,41 @@ static int file_remove_action(const char *filename, struct stat *statbuf,
 }
 #endif
 
+static int detect_efi_vars(int fd, void* buf_with_efi, void** wbuf, int *size) {
+	uint32_t magic;
+	int ret;
+
+	*wbuf = buf_with_efi + EFIVAR_ATTR_SIZE;
+#if !defined CONFIG_EFI || defined __BAREBOX__
+		return 0;
+#endif
+
+	ret = pread(fd, &magic, sizeof(uint32_t),
+		EFIVAR_ATTR_SIZE);
+	if (ret == -1 && errno == ENOENT) {
+		perror("pread");
+		// skip as file don't exist
+		return 0;
+	}
+	if (ret < sizeof(u_int32_t)) {
+		perror("pread");
+		return 0;
+	}
+
+	if (ENVFS_32(magic) == ENVFS_MAGIC) {
+		pr_info("Assuming EFI variable. Keeping attributes\n");
+		ret = pread(fd, buf_with_efi, EFIVAR_ATTR_SIZE, 0);
+		if (ret < EFIVAR_ATTR_SIZE) {
+			ret = -errno;
+			perror("read of efi attributes failed");
+			return ret;
+		}
+		*size += EFIVAR_ATTR_SIZE;
+		*wbuf = buf_with_efi;
+	}
+	return 0;
+}
+
 /**
  * Make the current environment persistent
  * @param[in] filename where to store
@@ -305,7 +343,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 	struct envfs_super *super;
 	int envfd, size, ret;
 	struct action_data data = {};
-	void *buf = NULL, *wbuf;
+	void *buf = NULL, *wbuf = NULL, *buf_with_efi;
 	struct envfs_entry *env;
 	const char *defenv_path = default_environment_path_get();
 
@@ -342,7 +380,9 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 		}
 	}
 
-	buf = xzalloc(size + sizeof(struct envfs_super));
+	buf_with_efi = xzalloc(size + sizeof(struct envfs_super) +
+	EFIVAR_ATTR_SIZE);
+	buf = buf_with_efi + EFIVAR_ATTR_SIZE;
 	data.writep = buf + sizeof(struct envfs_super);
 
 	super = buf;
@@ -370,7 +410,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 	super->crc = ENVFS_32(crc32(0, buf + sizeof(struct envfs_super), size));
 	super->sb_crc = ENVFS_32(crc32(0, buf, sizeof(struct envfs_super) - 4));
 
-	envfd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
+	envfd = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
 	if (envfd < 0) {
 		printf("could not open %s: %m\n", filename);
 		ret = -errno;
@@ -385,6 +425,12 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 		goto out;
 	}
 
+	/* check if we writing efi vars */
+	ret = detect_efi_vars(envfd, buf_with_efi, &wbuf, &size);
+	if (ret != 0) {
+		goto out;
+	}
+
 	ret = erase(envfd, ERASE_SIZE_ALL, 0, ERASE_TO_WRITE);
 
 	/* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */
@@ -395,12 +441,11 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 
 	size += sizeof(struct envfs_super);
 
-	wbuf = buf;
-
 	while (size) {
 		ssize_t now = write(envfd, wbuf, size);
 		if (now < 0) {
 			ret = -errno;
+			perror("write");
 			goto out;
 		}
 
@@ -418,14 +463,14 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 
 	ret = 0;
 
-#ifdef CONFIG_NVVAR
+#if defined CONFIG_NVVAR && defined __BAREBOX__
 	if (defenv_path && !strcmp(filename, defenv_path))
 	    nv_var_set_clean();
 #endif
 out:
 	close(envfd);
 out1:
-	free(buf);
+	free(buf_with_efi);
 #ifdef __BAREBOX__
 	unlink_recursive(TMPDIR, NULL);
 #endif
@@ -449,6 +494,9 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
 	int envfd;
 	int ret = 0;
 	size_t size, rsize;
+#if defined CONFIG_EFI && !defined __BAREBOX__
+	uint32_t magic;
+#endif
 
 	if (!filename)
 		filename = default_environment_path_get();
@@ -466,6 +514,28 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
 		return -1;
 	}
 
+#if defined CONFIG_EFI && !defined __BAREBOX__
+	/* check if we reading efi vars */
+	ret = pread(envfd, &magic, sizeof(uint32_t),
+		    EFIVAR_ATTR_SIZE);
+	if (ret < sizeof(u_int32_t)) {
+		perror("read");
+		ret = -errno;
+		goto out;
+	}
+
+	if (ENVFS_32(magic) == ENVFS_MAGIC) {
+		pr_info("Assuming EFI variable. Skip attributes\n");
+		ret = read(envfd, &magic,
+			   sizeof(uint32_t)); // simply reuse the memory
+		if (ret < sizeof(uint32_t)) {
+			perror("read");
+			ret = -errno;
+			goto out;
+		}
+	}
+#endif
+
 	/* read superblock */
 	ret = read(envfd, &super, sizeof(struct envfs_super));
 	if ( ret < sizeof(struct envfs_super)) {
diff --git a/scripts/Makefile b/scripts/Makefile
index 6d89af7d4f..57d8ddb54d 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -30,6 +30,7 @@ hostprogs-always-$(CONFIG_RK_IMAGE)			+= rkimage
 HOSTCFLAGS_rkimage.o = `$(PKG_CONFIG) --cflags openssl`
 HOSTLDLIBS_rkimage = `$(PKG_CONFIG) --libs openssl`
 KBUILD_HOSTCFLAGS += -I$(srctree)/scripts/include/
+KBUILD_HOSTCFLAGS += -I$(objtree)/include/generated/
 HOSTCFLAGS_mxsimage.o = `$(PKG_CONFIG) --cflags openssl`
 HOSTLDLIBS_mxsimage  = `$(PKG_CONFIG) --libs openssl`
 HOSTCFLAGS_omap3-usb-loader.o = `$(PKG_CONFIG) --cflags libusb-1.0`
@@ -57,6 +58,7 @@ omap4_usbboot-target-userccflags += `$(CROSS_PKG_CONFIG) --cflags libusb-1.0`
 omap4_usbboot-target-userldlibs += -lpthread `$(CROSS_PKG_CONFIG) --libs libusb-1.0`
 rk-usb-loader-target-userccflags += `$(CROSS_PKG_CONFIG) --cflags libusb-1.0`
 rk-usb-loader-target-userldlibs += `$(CROSS_PKG_CONFIG) --libs libusb-1.0`
+bareboxenv-target-userccflags += -I$(objtree)/include/generated/
 
 userccflags += -I $(srctree)/$(src)/include -isystem $(srctree)/scripts/include
 
diff --git a/scripts/bareboxenv.c b/scripts/bareboxenv.c
index e954447015..6b9b8d90c4 100644
--- a/scripts/bareboxenv.c
+++ b/scripts/bareboxenv.c
@@ -117,7 +117,7 @@ static void usage(char *prgname)
 int main(int argc, char *argv[])
 {
 	int opt;
-	int save = 0, load = 0, pad = 0, err = 0, fd;
+	int save = 0, load = 0, pad = 0, err = 0;
 	char *filename = NULL, *dirname = NULL;
 	unsigned envfs_flags = 0;
 	int verbose = 0;
@@ -156,15 +156,6 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	if (save) {
-		fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0644);
-		if (fd < 0) {
-			perror("open");
-			exit(1);
-		}
-		close(fd);
-	}
-
 	if (save && pad) {
 		if (truncate(filename, pad)) {
 			perror("truncate");
-- 
2.45.3



From s.hauer at pengutronix.de  Thu Mar 20 04:05:21 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Mar 2025 12:05:21 +0100
Subject: [PATCH] linux/printk.h: fix typos
Message-ID: <20250320110521.190945-1-s.hauer@pengutronix.de>

Fix typos in dev_*_once macros to make them usable.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/linux/printk.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 469ca879c7..67bdd2dc15 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -92,15 +92,15 @@ static inline int pr_print(int level, const char *format, ...)
 #define dev_crit_once(dev, format, arg...)		\
 	__dev_printf_once(2, (dev) , format , ## arg)
 #define dev_err_once(dev, format, arg...)		\
-	__dev_prin_oncetf(3, (dev) , format , ## arg)
+	__dev_printf_once(3, (dev) , format , ## arg)
 #define dev_warn_once(dev, format, arg...)		\
 	__dev_printf_once(4, (dev) , format , ## arg)
 #define dev_notice_once(dev, format, arg...)		\
-	__dev_printf(_once5, (dev) , format , ## arg)
+	__dev_printf_once(5, (dev) , format , ## arg)
 #define dev_info_once(dev, format, arg...)		\
 	__dev_printf_once(6, (dev) , format , ## arg)
 #define dev_dbg_once(dev, format, arg...)		\
-	__dev_prin_oncetf(7, (dev) , format , ## arg)
+	__dev_printf_once(7, (dev) , format , ## arg)
 #define dev_vdbg_once(dev, format, arg...)		\
 	__dev_printf_once(8, (dev) , format , ## arg)
 
-- 
2.39.5



From s.hauer at pengutronix.de  Thu Mar 20 04:45:27 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Mar 2025 12:45:27 +0100
Subject: [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a
 single xload_instance structure
In-Reply-To: <20250320091419.42095-1-eagle.alexander923@gmail.com>
References: <20250320091419.42095-1-eagle.alexander923@gmail.com>
Message-ID: <174247112729.196870.2122605639739576387.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 12:14:13 +0300, Alexander Shiyan wrote:
> The loader function structures use the same members,
> so they can be rewritten to use a single xload_instance structure.
> 
> 

Applied, thanks!

[1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure
      https://git.pengutronix.de/cgit/barebox/commit/?id=de261a15e9e6 (link may not be stable)
[2/7] ARM: at91: xload: Replace magic values with definitions
      https://git.pengutronix.de/cgit/barebox/commit/?id=b0495d1981dd (link may not be stable)
[3/7] ARM: at91: xload: Remove len argument from at91_fat_start_image()
      https://git.pengutronix.de/cgit/barebox/commit/?id=358c761c9943 (link may not be stable)
[4/7] ARM: at91: xload: Use the variable name as described in include/mach/at91/xload.h
      https://git.pengutronix.de/cgit/barebox/commit/?id=6da72bb19dd7 (link may not be stable)
[5/7] ARM: at91: xload: Remove intermediate variable
      https://git.pengutronix.de/cgit/barebox/commit/?id=9dded8d8fb04 (link may not be stable)
[6/7] ARM: at91: xload: Rename the sama5d2 output image names
      https://git.pengutronix.de/cgit/barebox/commit/?id=dca0152f2943 (link may not be stable)
[7/7] ARM: at91: xload: Add QSPI boot support for SAMA5D2
      https://git.pengutronix.de/cgit/barebox/commit/?id=2d47ec01ab52 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 20 04:45:43 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Mar 2025 12:45:43 +0100
Subject: [PATCH master 1/2] Documentation: user: intro: update feedback
 section on ML
In-Reply-To: <20250320082426.2124644-1-a.fatoum@pengutronix.de>
References: <20250320082426.2124644-1-a.fatoum@pengutronix.de>
Message-ID: <174247114397.197218.14617516113831604302.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 09:24:25 +0100, Ahmad Fatoum wrote:
> Now that kernel.org also mirrors barebox, we don't require the midmask,
> linkmask configuration we had before.
> 
> Adapt the docs accordingly and explain shazam -H a bit.
> 
> 

Applied, thanks!

[1/2] Documentation: user: intro: update feedback section on ML
      https://git.pengutronix.de/cgit/barebox/commit/?id=ee743b4a9786 (link may not be stable)
[2/2] Revert "Documentation: remove info about bridging to matrix"
      https://git.pengutronix.de/cgit/barebox/commit/?id=9cac80ac7b32 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 20 04:46:09 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Mar 2025 12:46:09 +0100
Subject: [PATCH master 0/8] treewide: misc fixes
In-Reply-To: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
References: <20250320051641.1721377-1-a.fatoum@pengutronix.de>
Message-ID: <174247116914.197531.8685191015163076060.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 06:16:33 +0100, Ahmad Fatoum wrote:
> Just a loose collection of fixes for master.
> 
> Ahmad Fatoum (8):
>   firmware: disable MISSING_FIRMWARE_ERROR for COMPILE_TEST builds
>   include: asm-generic/pointer.h: fix ASM_PTR definition for i386
>   sandbox: do not enable SANDBOX_LINUX_I386 in allyesconfig
>   Documentation: devicetree: fix Sphinx warnings
>   ARM: mvebu: kwb_bbu: add missing header
>   net: phy: fix of_get_phy_mode for XLGMII and beyond
>   vsprintf: fix left indentation when formatting wide string arguments
>   test: self: printf: add tests for formatting wide strings
> 
> [...]

Applied, thanks!

[1/8] firmware: disable MISSING_FIRMWARE_ERROR for COMPILE_TEST builds
      https://git.pengutronix.de/cgit/barebox/commit/?id=f98e851fb44a (link may not be stable)
[2/8] include: asm-generic/pointer.h: fix ASM_PTR definition for i386
      https://git.pengutronix.de/cgit/barebox/commit/?id=aac256131049 (link may not be stable)
[3/8] sandbox: do not enable SANDBOX_LINUX_I386 in allyesconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=3e99ee8d8daf (link may not be stable)
[4/8] Documentation: devicetree: fix Sphinx warnings
      https://git.pengutronix.de/cgit/barebox/commit/?id=e6fadf774de3 (link may not be stable)
[5/8] ARM: mvebu: kwb_bbu: add missing header
      https://git.pengutronix.de/cgit/barebox/commit/?id=2cb75d180cfd (link may not be stable)
[6/8] net: phy: fix of_get_phy_mode for XLGMII and beyond
      https://git.pengutronix.de/cgit/barebox/commit/?id=24a20c4f0919 (link may not be stable)
[7/8] vsprintf: fix left indentation when formatting wide string arguments
      https://git.pengutronix.de/cgit/barebox/commit/?id=e91b0cde02bc (link may not be stable)
[8/8] test: self: printf: add tests for formatting wide strings
      https://git.pengutronix.de/cgit/barebox/commit/?id=9340a6acec7c (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 20 05:06:06 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Mar 2025 13:06:06 +0100
Subject: [PATCH] linux/printk.h: fix typos
In-Reply-To: <20250320110521.190945-1-s.hauer@pengutronix.de>
References: <20250320110521.190945-1-s.hauer@pengutronix.de>
Message-ID: <174247236627.203123.4982940980055752702.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 12:05:21 +0100, Sascha Hauer wrote:
> Fix typos in dev_*_once macros to make them usable.
> 
> 

Applied, thanks!

[1/1] linux/printk.h: fix typos
      https://git.pengutronix.de/cgit/barebox/commit/?id=60ea85061eac (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 20 05:07:34 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Mar 2025 13:07:34 +0100
Subject: [PATCH] ARM: omap: remove unused file
Message-ID: <20250320120734.203685-1-s.hauer@pengutronix.de>

omap4-devices.h is not included anywhere. Remove the file.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/mach/omap/omap4-devices.h | 93 -------------------------------
 1 file changed, 93 deletions(-)
 delete mode 100644 include/mach/omap/omap4-devices.h

diff --git a/include/mach/omap/omap4-devices.h b/include/mach/omap/omap4-devices.h
deleted file mode 100644
index de73062bc5..0000000000
--- a/include/mach/omap/omap4-devices.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#ifndef __MACH_OMAP4_DEVICES_H
-#define __MACH_OMAP4_DEVICES_H
-
-#include <driver.h>
-#include <linux/sizes.h>
-#include <mach/omap/devices.h>
-#include <mach/omap/omap4-silicon.h>
-#include <mach/omap/mcspi.h>
-#include <mach/omap/omap_hsmmc.h>
-
-static inline void omap44xx_add_sram0(void)
-{
-	return omap_add_sram0(OMAP44XX_SRAM_BASE, 48 * SZ_1K);
-}
-
-static inline struct device *omap44xx_add_uart1(void)
-{
-	return omap_add_uart(0, OMAP44XX_UART1_BASE);
-}
-
-static inline struct device *omap44xx_add_uart2(void)
-{
-	return omap_add_uart(1, OMAP44XX_UART2_BASE);
-}
-
-static inline struct device *omap44xx_add_uart3(void)
-{
-	return omap_add_uart(2, OMAP44XX_UART3_BASE);
-}
-
-static inline struct device *omap44xx_add_mmc1(struct omap_hsmmc_platform_data *pdata)
-{
-	return add_generic_device("omap4-hsmmc", 0, NULL,
-			OMAP44XX_MMC1_BASE, SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_mmc2(struct omap_hsmmc_platform_data *pdata)
-{
-	return add_generic_device("omap4-hsmmc", 1, NULL,
-			OMAP44XX_MMC2_BASE, SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_mmc3(struct omap_hsmmc_platform_data *pdata)
-{
-	return add_generic_device("omap4-hsmmc", 2, NULL,
-			OMAP44XX_MMC3_BASE, SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_mmc4(struct omap_hsmmc_platform_data *pdata)
-{
-	return add_generic_device("omap4-hsmmc", 3, NULL,
-			OMAP44XX_MMC4_BASE, SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_mmc5(struct omap_hsmmc_platform_data *pdata)
-{
-	return add_generic_device("omap4-hsmmc", 4, NULL,
-			OMAP44XX_MMC5_BASE, SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_i2c1(void *pdata)
-{
-	return add_generic_device("i2c-omap4", 0, NULL, OMAP44XX_I2C1_BASE,
-			SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_i2c2(void *pdata)
-{
-	return add_generic_device("i2c-omap4", 1, NULL, OMAP44XX_I2C2_BASE,
-			SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_i2c3(void *pdata)
-{
-	return add_generic_device("i2c-omap4", 2, NULL, OMAP44XX_I2C3_BASE,
-			SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_i2c4(void *pdata)
-{
-	return add_generic_device("i2c-omap4", 3, NULL, OMAP44XX_I2C4_BASE,
-			SZ_4K, IORESOURCE_MEM, pdata);
-}
-
-static inline struct device *omap44xx_add_ehci(void *pdata)
-{
-	return add_usb_ehci_device(DEVICE_ID_DYNAMIC, OMAP44XX_EHCI_BASE,
-				OMAP44XX_EHCI_BASE + 0x10, pdata);
-}
-
-#endif /* __MACH_OMAP4_DEVICES_H */
-- 
2.39.5



From s.hauer at pengutronix.de  Thu Mar 20 05:09:07 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Mar 2025 13:09:07 +0100
Subject: [PATCH] dma: add function to check a buffer for proper DMA alignment
Message-ID: <20250320120907.204013-1-s.hauer@pengutronix.de>

Add dma_map_buf_is_aligned() which can be used to check if a buffer is
sufficiently aligned for DMA.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/dma.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/dma.h b/include/dma.h
index 5877f4b13c..41eeacc478 100644
--- a/include/dma.h
+++ b/include/dma.h
@@ -141,4 +141,9 @@ void dma_free_coherent(struct device *dev, void *mem, dma_addr_t dma_handle, siz
 void *dma_alloc_writecombine(struct device *dev, size_t size, dma_addr_t *dma_handle);
 #endif
 
+static inline bool dma_map_buf_is_aligned(struct device *dev, void *buf, size_t size)
+{
+	return IS_ALIGNED((uintptr_t)buf, ARCH_DMA_MINALIGN) &&
+		IS_ALIGNED(size, ARCH_DMA_MINALIGN);
+}
 #endif /* __DMA_H */
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 20 05:37:03 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 13:37:03 +0100
Subject: [PATCH] dma: add function to check a buffer for proper DMA
 alignment
In-Reply-To: <20250320120907.204013-1-s.hauer@pengutronix.de>
References: <20250320120907.204013-1-s.hauer@pengutronix.de>
Message-ID: <59323f53-9587-4e6c-a010-fca15789656b@pengutronix.de>

Hello Sascha,

On 3/20/25 13:09, Sascha Hauer wrote:
> Add dma_map_buf_is_aligned() which can be used to check if a buffer is
> sufficiently aligned for DMA.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  include/dma.h | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/include/dma.h b/include/dma.h
> index 5877f4b13c..41eeacc478 100644
> --- a/include/dma.h
> +++ b/include/dma.h
> @@ -141,4 +141,9 @@ void dma_free_coherent(struct device *dev, void *mem, dma_addr_t dma_handle, siz
>  void *dma_alloc_writecombine(struct device *dev, size_t size, dma_addr_t *dma_handle);
>  #endif
>  
> +static inline bool dma_map_buf_is_aligned(struct device *dev, void *buf, size_t size)

const void *.

So we don't need to case twice; once here and once at dma_map time.

> +{
> +	return IS_ALIGNED((uintptr_t)buf, ARCH_DMA_MINALIGN) &&

PTR_IS_ALIGNED

Thanks,
Ahmad

> +		IS_ALIGNED(size, ARCH_DMA_MINALIGN);
> +}
>  #endif /* __DMA_H */



From s.hauer at pengutronix.de  Thu Mar 20 05:51:09 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Mar 2025 13:51:09 +0100
Subject: [PATCH v2] dma: add function to check a buffer for proper DMA alignment
Message-ID: <20250320125109.210820-1-s.hauer@pengutronix.de>

Add dma_map_buf_is_aligned() which can be used to check if a buffer is
sufficiently aligned for DMA.

Link: https://lore.kernel.org/r/20250320120907.204013-1-s.hauer at pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

---

Changes since v2:
- make buf argument const
- use PTR_IS_ALIGNED for pointer checking
---
 include/dma.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/dma.h b/include/dma.h
index 5877f4b13c..cb44963cc0 100644
--- a/include/dma.h
+++ b/include/dma.h
@@ -141,4 +141,9 @@ void dma_free_coherent(struct device *dev, void *mem, dma_addr_t dma_handle, siz
 void *dma_alloc_writecombine(struct device *dev, size_t size, dma_addr_t *dma_handle);
 #endif
 
+static inline bool dma_map_buf_is_aligned(struct device *dev, const void *buf, size_t size)
+{
+	return PTR_IS_ALIGNED(buf, ARCH_DMA_MINALIGN) &&
+		IS_ALIGNED(size, ARCH_DMA_MINALIGN);
+}
 #endif /* __DMA_H */
-- 
2.39.5



From s.hauer at pengutronix.de  Thu Mar 20 05:52:44 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Mar 2025 13:52:44 +0100
Subject: [PATCH] fixup! commands: ubsan: hide zero division in test
In-Reply-To: <20250319161056.2086121-1-a.fatoum@pengutronix.de>
References: <20250319161056.2086121-1-a.fatoum@pengutronix.de>
Message-ID: <174247516436.211035.5665219130801008087.b4-ty@pengutronix.de>


On Wed, 19 Mar 2025 17:10:56 +0100, Ahmad Fatoum wrote:
> GCC complains that we pass the address of the variable instead of the
>     variable itself:
> 
>     commands/ubsan.c: In function ?test_ubsan_divrem_overflow?:
>     error: lvalue required in ?asm? statement
> 
>        63 |         __asm__ ("" : "=r" (var) : "0" (var))
>           |         ^~~~~~~
>     ./commands/ubsan.c:46:9: note: in expansion of macro ?OPTIMIZER_HIDE_VAR?
>        46 |         OPTIMIZER_HIDE_VAR(&val2);
> 
> [...]

Applied, thanks!

[1/1] fixup! commands: ubsan: hide zero division in test
      https://git.pengutronix.de/cgit/barebox/commit/?id=85749615acdd (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From a.fatoum at pengutronix.de  Thu Mar 20 13:30:57 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Mar 2025 21:30:57 +0100
Subject: [PATCH master] video: ssd1307fb: set default mode
Message-ID: <20250320203057.3417065-1-a.fatoum@pengutronix.de>

The framebuffer support will refuse modification of the fbX.enable
parameter if there are no modes. The ssd1307fb is the only driver
that has no provisions for populating modes and thus always runs
into this case.

The display is normally used as a small framebuffer console and the
frame buffer console support will call fb_enable sidestepping the check
in the device parameter, which caused the issue to fly under the radar
so far. If used without framebuffer console, however, the problem
becomes quickly apparent.

Reported-by: @jakthree:matrix.org
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/video/ssd1307fb.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/video/ssd1307fb.c b/drivers/video/ssd1307fb.c
index fb50e895c59a..5880f2b4a57a 100644
--- a/drivers/video/ssd1307fb.c
+++ b/drivers/video/ssd1307fb.c
@@ -77,6 +77,7 @@ struct ssd1307fb_par {
 	struct spi_device *spi;
 	u32 height;
 	struct fb_info *info;
+	struct fb_videomode mode;
 	u32 page_offset;
 	u32 prechargep1;
 	u32 prechargep2;
@@ -594,6 +595,11 @@ static int ssd1307fb_probe(struct device *dev)
 	if (ret)
 		goto reset_oled_error;
 
+	par->mode.xres = par->width;
+	par->mode.yres = par->height;
+	par->mode.name = "default";
+
+	info->mode = &par->mode;
 	info->dev.parent = dev;
 	ret = register_framebuffer(info);
 	if (ret) {
-- 
2.39.5



From a.fatoum at pengutronix.de  Fri Mar 21 03:12:18 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 21 Mar 2025 11:12:18 +0100
Subject: [PATCH master] ci: coverity: fix git hash truncation to 10 characters
Message-ID: <20250321101218.1181081-1-a.fatoum@pengutronix.de>

A misplaced $ lead to versions looking like this:

  Version: 2025.02.0-g\{84a1605196530ff77...

instead of

  Version: 2025.02.0-g84a1605196

Move it to fix.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
Untested, but looks straight-forward enough.
---
 .github/workflows/coverity.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/coverity.sh b/.github/workflows/coverity.sh
index 1fd7dd068275..ee4a481503c7 100755
--- a/.github/workflows/coverity.sh
+++ b/.github/workflows/coverity.sh
@@ -33,7 +33,7 @@ function run_coverity {
     tool_dir=$(find "$COVERITY_SCAN_TOOL_BASE" -type d -name 'cov-analysis*')
     results_archive="analysis-results.tgz"
 
-    version="$(make bareboxversion)-g{$GITHUB_SHA:0:10}"
+    version="$(make bareboxversion)-g${GITHUB_SHA:0:10}"
 
     make ARCH=sandbox sandbox_defconfig
     COVERITY_UNSUPPORTED=1 "$tool_dir/bin/cov-build" --dir "$results_dir" sh -c "make -j$(nproc) ARCH=sandbox"
-- 
2.39.5



From s.hauer at pengutronix.de  Mon Mar 24 01:14:15 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:14:15 +0100
Subject: [PATCH] mci: Do not access ext_csd on SD cards
Message-ID: <20250324081415.1697333-1-s.hauer@pengutronix.de>

SD cards do not have a ext_csd so accessing it on an SD card results in
a NULL pointer derefence. Move the production year check to
mci_mmc_decode_cid() which is executed for MMC devices only. While at
it do not access ext_csd directly. We have already populated
mci->version, so use this to check for the MMC versions which need the
production year adjustment.

Fixes: a4a78c4f32 ("mci: use struct cid")
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index c89322f61e..1e49969017 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -2377,6 +2377,12 @@ static int mci_mmc_decode_cid(struct mci *card)
 		return -EINVAL;
 	}
 
+	if (mci->version >= MMC_VERSION_4_41) {
+		/* Adjust production date as per JEDEC JESD84-B451 */
+		if (mci->cid.year < 2010)
+			mci->cid.year += 16;
+	}
+
 	return 0;
 }
 
@@ -2483,12 +2489,6 @@ static void mci_parse_cid(struct mci *mci)
 	else
 		mci_mmc_decode_cid(mci);
 
-	if (mci->ext_csd[EXT_CSD_REV] >= 5) {
-		/* Adjust production date as per JEDEC JESD84-B451 */
-		if (mci->cid.year < 2010)
-			mci->cid.year += 16;
-	}
-
 	dev_add_param_uint32_fixed(dev, "cid_mid", mci->cid.manfid, "0x%02X");
 	dev_add_param_uint32_fixed(dev, "cid_oid", mci->cid.oemid, "0x%04X");
 	dev_add_param_string_fixed(dev, "cid_pnm", mci->cid.prod_name);
-- 
2.39.5



From s.hauer at pengutronix.de  Mon Mar 24 01:19:39 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:19:39 +0100
Subject: [PATCH] mci: Do not access ext_csd on SD cards
In-Reply-To: <20250324081415.1697333-1-s.hauer@pengutronix.de>
References: <20250324081415.1697333-1-s.hauer@pengutronix.de>
Message-ID: <Z-EVm4bn5kCxlaz3@pengutronix.de>

On Mon, Mar 24, 2025 at 09:14:15AM +0100, Sascha Hauer wrote:
> SD cards do not have a ext_csd so accessing it on an SD card results in
> a NULL pointer derefence. Move the production year check to
> mci_mmc_decode_cid() which is executed for MMC devices only. While at
> it do not access ext_csd directly. We have already populated
> mci->version, so use this to check for the MMC versions which need the
> production year adjustment.
> 
> Fixes: a4a78c4f32 ("mci: use struct cid")
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  drivers/mci/mci-core.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> index c89322f61e..1e49969017 100644
> --- a/drivers/mci/mci-core.c
> +++ b/drivers/mci/mci-core.c
> @@ -2377,6 +2377,12 @@ static int mci_mmc_decode_cid(struct mci *card)
>  		return -EINVAL;
>  	}
>  
> +	if (mci->version >= MMC_VERSION_4_41) {
> +		/* Adjust production date as per JEDEC JESD84-B451 */
> +		if (mci->cid.year < 2010)
> +			mci->cid.year += 16;
> +	}

The variable is named "card" in this function, not "mci". Will fix while
applying.

Sascha


-- 
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-5555 |


From s.hauer at pengutronix.de  Mon Mar 24 01:21:54 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:21:54 +0100
Subject: [PATCH] ARM: omap: remove unused file
In-Reply-To: <20250320120734.203685-1-s.hauer@pengutronix.de>
References: <20250320120734.203685-1-s.hauer@pengutronix.de>
Message-ID: <174280451449.1706449.11712684517727883927.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 13:07:34 +0100, Sascha Hauer wrote:
> omap4-devices.h is not included anywhere. Remove the file.
> 
> 

Applied, thanks!

[1/1] ARM: omap: remove unused file
      https://git.pengutronix.de/cgit/barebox/commit/?id=eb9f1dea5c17 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:21:54 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:21:54 +0100
Subject: [PATCH 1/2] firmware: export firmware directory
In-Reply-To: <20250314094559.3631184-1-s.hauer@pengutronix.de>
References: <20250314094559.3631184-1-s.hauer@pengutronix.de>
Message-ID: <174280451447.1706449.1871814686142811700.b4-ty@pengutronix.de>


On Fri, 14 Mar 2025 10:45:58 +0100, Sascha Hauer wrote:
> The recently added k3r5 code needs firmware blobs as part of the image
> generation. It hardcodes the firmware path to $(srctree)/firmware which
> is the default, but could changed with CONFIG_EXTRA_FIRMWARE_DIR.
> 
> Move setting of $(fwdir) to the toplevel Makefile and export it to make
> it available to images/Makefile.k3. As fwdir is a bad name for an
> exported variable rename it to FIRMWARE_DIR.
> 
> [...]

Applied, thanks!

[1/2] firmware: export firmware directory
      https://git.pengutronix.de/cgit/barebox/commit/?id=906ecf8c9c37 (link may not be stable)
[2/2] ARM: k3r5: Honour CONFIG_EXTRA_FIRMWARE_DIR
      https://git.pengutronix.de/cgit/barebox/commit/?id=78ebaea8ebd0 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:21:54 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:21:54 +0100
Subject: [PATCH] mci: Do not access ext_csd on SD cards
In-Reply-To: <20250324081415.1697333-1-s.hauer@pengutronix.de>
References: <20250324081415.1697333-1-s.hauer@pengutronix.de>
Message-ID: <174280451449.1706449.2879677421176957909.b4-ty@pengutronix.de>


On Mon, 24 Mar 2025 09:14:15 +0100, Sascha Hauer wrote:
> SD cards do not have a ext_csd so accessing it on an SD card results in
> a NULL pointer derefence. Move the production year check to
> mci_mmc_decode_cid() which is executed for MMC devices only. While at
> it do not access ext_csd directly. We have already populated
> mci->version, so use this to check for the MMC versions which need the
> production year adjustment.
> 
> [...]

Applied, thanks!

[1/1] mci: Do not access ext_csd on SD cards
      https://git.pengutronix.de/cgit/barebox/commit/?id=a0747210a87d (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:25:48 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:25:48 +0100
Subject: [PATCH] dma: add function to check a buffer for proper DMA
 alignment
In-Reply-To: <20250320120907.204013-1-s.hauer@pengutronix.de>
References: <20250320120907.204013-1-s.hauer@pengutronix.de>
Message-ID: <174280474833.1707553.15299023851758848910.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 13:09:07 +0100, Sascha Hauer wrote:
> Add dma_map_buf_is_aligned() which can be used to check if a buffer is
> sufficiently aligned for DMA.
> 
> 

Applied, thanks!

[1/1] dma: add function to check a buffer for proper DMA alignment
      https://git.pengutronix.de/cgit/barebox/commit/?id=d648250202c9 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:25:48 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:25:48 +0100
Subject: [PATCH v2 00/10] Add RPMB support
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
Message-ID: <174280474835.1707553.3054692315084257990.b4-ty@pengutronix.de>


On Wed, 19 Mar 2025 16:30:51 +0100, Sascha Hauer wrote:
> This series adds the necessary pieces to provide OP-TEE access to RPMB
> partitions under barebox.
> 
> With this OP-TEE can issue RPMB requests to barebox and barebox will
> answer them accordingly.
> 
> OP-TEE will only access the RPMB when triggered by barebox. For this
> purpose I implemented access to the Android Verified Boot (AVB) variable
> store. This is implemented in U-Boot as well and the code is loosely
> based on it. The variables can be read/written using the newly
> introduced avb_pvalue command.
> 
> [...]

Applied, thanks!

[01/10] mci: implement mci_set_blockcount()
        https://git.pengutronix.de/cgit/barebox/commit/?id=b577765789e8 (link may not be stable)
[02/10] mci: export some functions for RPMB support
        https://git.pengutronix.de/cgit/barebox/commit/?id=ee62681f52a2 (link may not be stable)
[03/10] mci: detect RPMB partitions
        https://git.pengutronix.de/cgit/barebox/commit/?id=9f567b2c00e5 (link may not be stable)
[04/10] mci: add RPMB support
        https://git.pengutronix.de/cgit/barebox/commit/?id=2473d46b6616 (link may not be stable)
[05/10] tee: optee: probe successfully even when no devices are found
        https://git.pengutronix.de/cgit/barebox/commit/?id=4e1c1ab58982 (link may not be stable)
[06/10] tee: optee: implement shared mem alloc/free RPC commands
        https://git.pengutronix.de/cgit/barebox/commit/?id=551862642a1d (link may not be stable)
[07/10] tee: optee: implement RPMB support
        https://git.pengutronix.de/cgit/barebox/commit/?id=9a0ccf2424d6 (link may not be stable)
[08/10] tee: optee: implement AVB named persistent values support
        https://git.pengutronix.de/cgit/barebox/commit/?id=bb3a50911a62 (link may not be stable)
[09/10] commands: add avb_pvalue command
        https://git.pengutronix.de/cgit/barebox/commit/?id=67e3c6424ffd (link may not be stable)
[10/10] ARM: omap: remove unused file
        https://git.pengutronix.de/cgit/barebox/commit/?id=62bbd20f95f2 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:25:48 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:25:48 +0100
Subject: [PATCH 0/9] Add RPMB support
In-Reply-To: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-0-0f213382a3f3@pengutronix.de>
Message-ID: <174280474832.1707553.5088214962830407332.b4-ty@pengutronix.de>


On Wed, 12 Mar 2025 13:16:15 +0100, Sascha Hauer wrote:
> This series adds the necessary pieces to provide OP-TEE access to RPMB
> partitions under barebox.
> 
> With this OP-TEE can issue RPMB requests to barebox and barebox will
> answer them accordingly.
> 
> OP-TEE will only access the RPMB when triggered by barebox. For this
> purpose I implemented access to the Android Verified Boot (AVB) variable
> store. This is implemented in U-Boot as well and the code is loosely
> based on it. The variables can be read/written using the newly
> introduced avb_pvalue command.
> 
> [...]

Applied, thanks!

[1/9] mci: implement mci_set_blockcount()
      https://git.pengutronix.de/cgit/barebox/commit/?id=b577765789e8 (link may not be stable)
[2/9] mci: export some functions for RPMB support
      https://git.pengutronix.de/cgit/barebox/commit/?id=ee62681f52a2 (link may not be stable)
[3/9] mci: detect RPMB partitions
      https://git.pengutronix.de/cgit/barebox/commit/?id=9f567b2c00e5 (link may not be stable)
[4/9] mci: add RPMB support
      https://git.pengutronix.de/cgit/barebox/commit/?id=2473d46b6616 (link may not be stable)
[5/9] tee: optee: probe successfully even when no devices are found
      https://git.pengutronix.de/cgit/barebox/commit/?id=4e1c1ab58982 (link may not be stable)
[6/9] tee: optee: implement shared mem alloc/free RPC commands
      https://git.pengutronix.de/cgit/barebox/commit/?id=551862642a1d (link may not be stable)
[7/9] tee: optee: implement RPMB support
      https://git.pengutronix.de/cgit/barebox/commit/?id=9a0ccf2424d6 (link may not be stable)
[8/9] tee: optee: implement AVB named persistent values support
      https://git.pengutronix.de/cgit/barebox/commit/?id=bb3a50911a62 (link may not be stable)
[9/9] commands: add avb_pvalue command
      https://git.pengutronix.de/cgit/barebox/commit/?id=67e3c6424ffd (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:25:48 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:25:48 +0100
Subject: [PATCH v2] dma: add function to check a buffer for proper DMA
 alignment
In-Reply-To: <20250320125109.210820-1-s.hauer@pengutronix.de>
References: <20250320125109.210820-1-s.hauer@pengutronix.de>
Message-ID: <174280474834.1707553.15511909191647751401.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 13:51:09 +0100, Sascha Hauer wrote:
> Add dma_map_buf_is_aligned() which can be used to check if a buffer is
> sufficiently aligned for DMA.
> 
> 

Applied, thanks!

[1/1] dma: add function to check a buffer for proper DMA alignment
      https://git.pengutronix.de/cgit/barebox/commit/?id=d648250202c9 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:28:31 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:28:31 +0100
Subject: [PATCH v2 04/10] mci: add RPMB support
In-Reply-To: <63082337-c9aa-467b-9a6b-5c98e5614c88@pengutronix.de>
References: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
 <20250319-rpmb-v2-4-a8801fb35cd4@pengutronix.de>
 <63082337-c9aa-467b-9a6b-5c98e5614c88@pengutronix.de>
Message-ID: <Z-EXr6JXt0Q_MqqQ@pengutronix.de>

On Wed, Mar 19, 2025 at 04:53:02PM +0100, Ahmad Fatoum wrote:
> 
> 
> On 3/19/25 16:30, Sascha Hauer wrote:
> > This implements the MMC specific part to access RPMB partitions:
> > 
> > - Provide a function to find a RPMB capable eMMC
> > - partition switching to the RPMB partition
> > - Dissecting the OP-TEE requests into the correspnding MMC read/write
> >   multiblock commands
> > 
> > For now we only support a single eMMC RPMB partition per board. This is
> > the 99% case, but there might be systems with multiple eMMCs. The OP-TEE
> > protocol has a dev_id field to support multiple eMMCs, but OP-TEE itself
> > currently only supports a single RPMB. This means we really only need to
> > support one eMMC, but should there be multiple eMMCs on a system we will
> > need a way for the user to specify which one shall be used. As of now
> > the first one found will be used.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  drivers/mci/Kconfig    |   3 +
> >  drivers/mci/Makefile   |   1 +
> >  drivers/mci/mci-core.c |  37 +++++++--
> >  drivers/mci/rpmb.c     | 210 +++++++++++++++++++++++++++++++++++++++++++++++++
> >  include/mci.h          |   5 ++
> >  5 files changed, 251 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/mci/Kconfig b/drivers/mci/Kconfig
> > index 4641e9cdcd..09648aa771 100644
> > --- a/drivers/mci/Kconfig
> > +++ b/drivers/mci/Kconfig
> > @@ -68,6 +68,9 @@ config MCI_MMC_GPP_PARTITIONS
> >  	  Note: by default, 'MMC' devices have no 'general purpose partitions',
> >  	  it requires a special one-time configuration step to enable them.
> >  
> > +config MCI_MMC_RPMB
> > +	bool "Support eMMC replay protected memory block (RPMB)"
> > +
> >  comment "--- MCI host drivers ---"
> >  
> >  config MCI_DWC_MSHC
> > diff --git a/drivers/mci/Makefile b/drivers/mci/Makefile
> > index 5e951d695f..d3df4c1bb6 100644
> > --- a/drivers/mci/Makefile
> > +++ b/drivers/mci/Makefile
> > @@ -1,5 +1,6 @@
> >  # SPDX-License-Identifier: GPL-2.0-only
> >  obj-$(CONFIG_MCI)		+= mci-core.o
> > +obj-$(CONFIG_MCI_MMC_RPMB)	+= rpmb.o
> >  obj-$(CONFIG_MCI_AM654)		+= am654-sdhci.o
> >  obj-$(CONFIG_MCI_ARASAN)	+= arasan-sdhci.o
> >  obj-$(CONFIG_MCI_ATMEL)		+= atmel_mci.o atmel_mci_common.o
> > diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> > index 3bf0f15def..48bdd1a0c7 100644
> > --- a/drivers/mci/mci-core.c
> > +++ b/drivers/mci/mci-core.c
> > @@ -2052,7 +2052,9 @@ int mci_blk_part_switch(struct mci_part *part)
> >  	struct mci *mci = part->mci;
> >  	int ret;
> >  
> > -	if (!IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) && !IS_ENABLED(CONFIG_MCI_MMC_GPP_PARTITIONS))
> > +	if (!IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) &&
> > +	    !IS_ENABLED(CONFIG_MCI_MMC_GPP_PARTITIONS) &&
> > +	    !IS_ENABLED(CONFIG_MCI_MMC_RPMB))
> >  		return 0; /* no need */
> >  
> >  	if (mci->part_curr == part)
> > @@ -2953,7 +2955,6 @@ void mci_of_parse_node(struct mci_host *host,
> >  {
> >  	u32 bus_width;
> >  	u32 dsr_val;
> > -	const char *alias;
> >  
> >  	if (!IS_ENABLED(CONFIG_OFDEVICE))
> >  		return;
> > @@ -2961,9 +2962,14 @@ void mci_of_parse_node(struct mci_host *host,
> >  	if (!host->hw_dev || !np)
> >  		return;
> >  
> > -	alias = of_alias_get(np);
> > -	if (alias)
> > -		host->devname = xstrdup(alias);
> > +	host->of_id = of_alias_get_id(np, "mmc");
> > +	if (host->of_id < 0)
> > +		host->of_id = of_alias_get_id(np->parent, "mmc");
> > +
> > +	if (host->of_id >= 0) {
> > +		host->devname = xasprintf("mmc%u", host->of_id);
> > +		host->of_id_valid = true;
> > +	}
> >  
> >  	/* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */
> >  	if (of_property_read_u32(np, "bus-width", &bus_width) < 0) {
> > @@ -3051,3 +3057,24 @@ struct mci *mci_get_device_by_name(const char *name)
> >  
> >  	return NULL;
> >  }
> > +
> > +struct mci *mci_get_rpmb_dev(unsigned int id)
> > +{
> > +	struct mci *mci;
> > +
> > +	list_for_each_entry(mci, &mci_list, list) {
> > +		if (mci->host->of_id != id)
> > +			continue;
> > +
> > +		mci_detect_card(mci->host);
> > +
> > +		if (!mci->rpmb_part) {
> > +			dev_err(&mci->dev, "requested MMC does not have a RPMB partition\n");
> > +			return NULL;
> > +		}
> > +
> > +		return mci;
> > +	}
> > +
> > +	return NULL;
> > +}
> > diff --git a/drivers/mci/rpmb.c b/drivers/mci/rpmb.c
> > new file mode 100644
> > index 0000000000..6c693aa1ea
> > --- /dev/null
> > +++ b/drivers/mci/rpmb.c
> > @@ -0,0 +1,210 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright 2014, Staubli Faverges
> > + * Pierre Aubert
> > + *
> > + * eMMC- Replay Protected Memory Block
> > + * According to JEDEC Standard No. 84-A441
> > + */
> > +#define pr_fmt(fmt) "mmc-rpmb: " fmt
> > +
> > +#include <mci.h>
> > +#include <malloc.h>
> > +#include <dma.h>
> > +
> > +int mmc_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
> > +			  void *rsp, unsigned long rsplen);
> > +
> > +/**
> > + * struct rpmb_frame - rpmb frame as defined by eMMC 5.1 (JESD84-B51)
> > + *
> > + * @stuff        : stuff bytes
> > + * @key_mac      : The authentication key or the message authentication
> > + *                 code (MAC) depending on the request/response type.
> > + *                 The MAC will be delivered in the last (or the only)
> > + *                 block of data.
> > + * @data         : Data to be written or read by signed access.
> > + * @nonce        : Random number generated by the host for the requests
> > + *                 and copied to the response by the RPMB engine.
> > + * @write_counter: Counter value for the total amount of the successful
> > + *                 authenticated data write requests made by the host.
> > + * @addr         : Address of the data to be programmed to or read
> > + *                 from the RPMB. Address is the serial number of
> > + *                 the accessed block (half sector 256B).
> > + * @block_count  : Number of blocks (half sectors, 256B) requested to be
> > + *                 read/programmed.
> > + * @result       : Includes information about the status of the write counter
> > + *                 (valid, expired) and result of the access made to the RPMB.
> > + * @req_resp     : Defines the type of request and response to/from the memory.
> > + *
> > + * The stuff bytes and big-endian properties are modeled to fit to the spec.
> > + */
> > +struct rpmb_frame {
> > +	u8 stuff[196];
> > +	u8 key_mac[32];
> > +	u8 data[256];
> > +	u8 nonce[16];
> > +	__be32 write_counter;
> > +	__be16 addr;
> > +	__be16 block_count;
> > +	__be16 result;
> > +	__be16 req_resp;
> > +} __packed;
> > +
> > +#define RPMB_PROGRAM_KEY	0x1	/* Program RPMB Authentication Key */
> > +#define RPMB_GET_WRITE_COUNTER	0x2	/* Read RPMB write counter */
> > +#define RPMB_WRITE_DATA		0x3	/* Write data to RPMB partition */
> > +#define RPMB_READ_DATA		0x4	/* Read data from RPMB partition */
> > +#define RPMB_RESULT_READ	0x5	/* Read result request  (Internal) */
> > +
> > +static int mci_read_write_blocks(struct mci *mci, u32 opcode, int write_flag, void *buf,
> > +				 unsigned int buf_bytes)
> > +{
> > +	int blocks = buf_bytes / 512;
> > +	struct mci_cmd cmd = {
> > +		.cmdidx = opcode,
> > +		.resp_type = MMC_RSP_R1,
> > +	};
> > +	struct mci_data data = {
> > +		.blocks = blocks,
> > +		.blocksize = sizeof(struct rpmb_frame),
> > +	};
> > +	int ret;
> > +
> > +	if (write_flag) {
> > +		data.src = buf;
> > +		data.flags = MMC_DATA_WRITE;
> > +	} else {
> > +		data.dest = buf;
> > +		data.flags = MMC_DATA_READ;
> > +	}
> > +
> > +	ret = mci_set_blockcount(mci, blocks | (write_flag & MMC_CMD23_ARG_REL_WR));
> > +	if (ret)
> > +		return ret;
> > +
> > +	return mci_send_cmd(mci, &cmd, &data);
> > +}
> > +
> > +static int rpmb_route_frames(struct mci *mci, void *req,
> > +			     unsigned int req_len, void *resp,
> > +			     unsigned int resp_len)
> > +{
> > +	struct rpmb_frame *frm = req;
> > +	unsigned int cmd_count;
> > +	u16 req_type;
> > +	bool write;
> > +	int ret;
> > +
> > +	if (req_len < sizeof(*frm))
> > +		return -EINVAL;
> > +
> > +	req_type = be16_to_cpu(frm->req_resp);
> > +	switch (req_type) {
> > +	case RPMB_PROGRAM_KEY:
> > +		if (req_len != sizeof(struct rpmb_frame) ||
> > +		    resp_len != sizeof(struct rpmb_frame))
> > +			return -EINVAL;
> > +		write = true;
> > +		break;
> > +	case RPMB_GET_WRITE_COUNTER:
> > +		if (req_len != sizeof(struct rpmb_frame) ||
> > +		    resp_len != sizeof(struct rpmb_frame))
> > +			return -EINVAL;
> > +		write = false;
> > +		break;
> > +	case RPMB_WRITE_DATA:
> > +		if (req_len % sizeof(struct rpmb_frame) ||
> > +		    resp_len != sizeof(struct rpmb_frame))
> > +			return -EINVAL;
> > +		write = true;
> > +		break;
> > +	case RPMB_READ_DATA:
> > +		if (req_len != sizeof(struct rpmb_frame) ||
> > +		    resp_len % sizeof(struct rpmb_frame))
> > +			return -EINVAL;
> > +		write = false;
> > +		break;
> > +	default:
> > +		return -EINVAL;
> > +	}
> > +
> > +	if (write)
> > +		cmd_count = 3;
> > +	else
> > +		cmd_count = 2;
> > +
> > +	if (write) {
> > +		struct rpmb_frame *frm = resp;
> > +
> > +		/* Send write request frame(s) */
> > +		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK,
> > +			  1 | MMC_CMD23_ARG_REL_WR, req, req_len);
> > +		if (ret)
> > +			goto out;
> > +
> > +		/* Send result request frame */
> > +		memset(frm, 0, sizeof(*frm));
> > +		frm->req_resp = cpu_to_be16(RPMB_RESULT_READ);
> > +		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK, 1,
> > +					    resp, resp_len);
> > +		if (ret)
> > +			goto out;
> > +
> > +		/* Read response frame */
> > +		ret = mci_read_write_blocks(mci, MMC_CMD_READ_MULTIPLE_BLOCK, 0,
> > +					    resp, resp_len);
> > +		if (ret)
> > +			goto out;
> > +	} else {
> > +		/* Send write request frame(s) */
> > +		ret = mci_read_write_blocks(mci, MMC_CMD_WRITE_MULTIPLE_BLOCK, 1,
> > +					    req, req_len);
> > +		if (ret)
> > +			goto out;
> > +
> > +		/* Read response frame */
> > +		ret = mci_read_write_blocks(mci, MMC_CMD_READ_MULTIPLE_BLOCK, 0,
> > +					    resp, resp_len);
> > +		if (ret)
> > +			goto out;
> > +	}
> > +out:
> > +	return ret;
> > +}
> > +
> > +int mci_rpmb_route_frames(struct mci *mci, void *req, unsigned long reqlen,
> > +			  void *rsp, unsigned long rsplen)
> > +{
> > +	/*
> > +	 * Whoever crafted the data supplied to this function knows how to
> > +	 * format the PRMB frames and which response is expected. If
> > +	 * there's some unexpected mismatch it's more helpful to report an
> > +	 * error immediately than trying to guess what was the intention
> > +	 * and possibly just delay an eventual error which will be harder
> > +	 * to track down.
> > +	 */
> > +	void *rpmb_data;
> > +	int ret;
> > +
> > +	if (!IS_ALIGNED((uintptr_t)rsp, ARCH_DMA_MINALIGN) ||
> > +	    !IS_ALIGNED(rsplen, ARCH_DMA_MINALIGN)) {
> > +		pr_err_once("response or length not DMA aligned\n");
> 
> A reference to the device would be useful.

I am not sure how useful it is given that this is a problem pointing to
OP-TEE only and is not specific to the given mci device. Anyway, it
shouldn't hurt either, so changed to dev_err_once()

> > +		return -EINVAL;
> > +	}
> > +
> > +	mci_blk_part_switch(mci->rpmb_part);
> > +
> > +	/* Memory alignment is required by MMC driver */
> > +	rpmb_data = dma_alloc(reqlen);
> > +	if (!rpmb_data)
> > +		return -ENOMEM;
> > +
> > +	memcpy(rpmb_data, req, reqlen);
> > +
> > +	ret = rpmb_route_frames(mci, rpmb_data, reqlen, rsp, rsplen);
> > +
> > +	free(rpmb_data);
> 
> dma_free() please

OK.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Mon Mar 24 01:29:39 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:29:39 +0100
Subject: [PATCH master] video: ssd1307fb: set default mode
In-Reply-To: <20250320203057.3417065-1-a.fatoum@pengutronix.de>
References: <20250320203057.3417065-1-a.fatoum@pengutronix.de>
Message-ID: <174280497933.1707926.12649316301627767632.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 21:30:57 +0100, Ahmad Fatoum wrote:
> The framebuffer support will refuse modification of the fbX.enable
> parameter if there are no modes. The ssd1307fb is the only driver
> that has no provisions for populating modes and thus always runs
> into this case.
> 
> The display is normally used as a small framebuffer console and the
> frame buffer console support will call fb_enable sidestepping the check
> in the device parameter, which caused the issue to fly under the radar
> so far. If used without framebuffer console, however, the problem
> becomes quickly apparent.
> 
> [...]

Applied, thanks!

[1/1] video: ssd1307fb: set default mode
      https://git.pengutronix.de/cgit/barebox/commit/?id=1f39c0443fb2 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:30:54 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:30:54 +0100
Subject: [PATCH v2 1/2] scripts: define le32_to_cpup and friends for
 host/target tools
In-Reply-To: <20250320052114.1732651-1-a.fatoum@pengutronix.de>
References: <20250320052114.1732651-1-a.fatoum@pengutronix.de>
Message-ID: <174280505410.1708268.6827945109482476993.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 06:21:13 +0100, Ahmad Fatoum wrote:
> We already define le32_to_cpu and friends, but were missing so far the
> p-suffixed variant, which accepts a pointer.
> 
> This is easily implemented with a bit of macro boilerplate, so let's do
> that.
> 
> 
> [...]

Applied, thanks!

[1/2] scripts: define le32_to_cpup and friends for host/target tools
      https://git.pengutronix.de/cgit/barebox/commit/?id=abc44245f7e7 (link may not be stable)
[2/2] booti: sanity check image magic before parsing header
      https://git.pengutronix.de/cgit/barebox/commit/?id=63e9dbd07542 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:34:49 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:34:49 +0100
Subject: [PATCH] commands: add varinfo command
In-Reply-To: <20250116140740.297902-1-a.fatoum@pengutronix.de>
References: <20250116140740.297902-1-a.fatoum@pengutronix.de>
Message-ID: <174280528982.1710680.5865475384209436426.b4-ty@pengutronix.de>


On Thu, 16 Jan 2025 15:07:40 +0100, Ahmad Fatoum wrote:
> Tab completion is very helpful, but it's not sufficient for enum-typed
> global variables. To know what the permissible values are, devinfo
> global must be consulted, which can have a lot of output.
> 
> As alternative, let's add a varinfo command that can be used together
> with parameter tab completion and that will just print out the
> parameters that start with the specified string.
> 
> [...]

Applied, thanks!

[1/1] commands: add varinfo command
      https://git.pengutronix.de/cgit/barebox/commit/?id=b1e45718bb15 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:34:49 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:34:49 +0100
Subject: [PATCH v2 1/3] complete: give device_param_complete a flags
 parameter
In-Reply-To: <20250320052059.1732184-1-a.fatoum@pengutronix.de>
References: <20250320052059.1732184-1-a.fatoum@pengutronix.de>
Message-ID: <174280528983.1710680.4736779118803380266.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 06:20:57 +0100, Ahmad Fatoum wrote:
> We currently always complete device parameters with either a dollar sign
> in front or an equal sign after. In preparation for allowing completions
> with neither, give env_param_complete() a flag.
> 
> 

Applied, thanks!

[1/3] complete: give device_param_complete a flags parameter
      https://git.pengutronix.de/cgit/barebox/commit/?id=0645f4077a9e (link may not be stable)
[2/3] env: add envvar_for_each helper for variable iteration
      https://git.pengutronix.de/cgit/barebox/commit/?id=448b9d5ea617 (link may not be stable)
[3/3] commands: add varinfo command
      https://git.pengutronix.de/cgit/barebox/commit/?id=b1e45718bb15 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:35:48 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:35:48 +0100
Subject: [PATCH 0/6] fs: implement tree and truncate
In-Reply-To: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
References: <20250320052019.1726331-1-a.fatoum@pengutronix.de>
Message-ID: <174280534849.1711080.15685978528901483022.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 06:20:13 +0100, Ahmad Fatoum wrote:
> Turn opendir inside out, so it uses directory fds internally.
> This is an important change, because it means that the inode
> iterate operation will now operate on a real struct file.
> 
> This is a prerequisite for porting 9pfs from Linux as it expects
> directories to be openend before iteration.
> 
> [...]

Applied, thanks!

[1/6] fs: use filename_create/filename_lookup instead of open-coding
      https://git.pengutronix.de/cgit/barebox/commit/?id=83ffe89840e8 (link may not be stable)
[2/6] fs: implement O_DIRECTORY
      https://git.pengutronix.de/cgit/barebox/commit/?id=a1248198fa3a (link may not be stable)
[3/6] fs: implement opendir in terms of fdopendir
      https://git.pengutronix.de/cgit/barebox/commit/?id=a1da0079d162 (link may not be stable)
[4/6] commands: implement tree command
      https://git.pengutronix.de/cgit/barebox/commit/?id=4c8584c4dda5 (link may not be stable)
[5/6] commands: add new truncate command
      https://git.pengutronix.de/cgit/barebox/commit/?id=f59a9574c22c (link may not be stable)
[6/6] Documentation: devel: add short section on file systems
      https://git.pengutronix.de/cgit/barebox/commit/?id=eeb78d24f1b1 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:41:41 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:41:41 +0100
Subject: [PATCH] driver: base: class: remove device from class on
 registration
In-Reply-To: <20250320052027.1731144-1-a.fatoum@pengutronix.de>
References: <20250320052027.1731144-1-a.fatoum@pengutronix.de>
Message-ID: <174280570158.1711522.3299646559563120142.b4-ty@pengutronix.de>


On Thu, 20 Mar 2025 06:20:27 +0100, Ahmad Fatoum wrote:
> class_remove_device is the exception and normally, a device class
> doesn't change for the lifetime of a device after it's set the first
> time and removal from a class is done alongside removal of the device
> itself.
> 
> Let's therefore move the removal from class into core driver code.
> 
> [...]

Applied, thanks!

[1/1] driver: base: class: remove device from class on registration
      https://git.pengutronix.de/cgit/barebox/commit/?id=e092a8d685cf (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 01:44:24 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 09:44:24 +0100
Subject: [PATCH master] ci: coverity: fix git hash truncation to 10
 characters
In-Reply-To: <20250321101218.1181081-1-a.fatoum@pengutronix.de>
References: <20250321101218.1181081-1-a.fatoum@pengutronix.de>
Message-ID: <174280586416.1711837.16460569924122254555.b4-ty@pengutronix.de>


On Fri, 21 Mar 2025 11:12:18 +0100, Ahmad Fatoum wrote:
> A misplaced $ lead to versions looking like this:
> 
>   Version: 2025.02.0-g\{84a1605196530ff77...
> 
> instead of
> 
>   Version: 2025.02.0-g84a1605196
> 
> [...]

Applied, thanks!

[1/1] ci: coverity: fix git hash truncation to 10 characters
      https://git.pengutronix.de/cgit/barebox/commit/?id=c683c1eca2b2 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 03:24:41 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 11:24:41 +0100
Subject: [PATCH 1/2] filetype: fix MBR detection
Message-ID: <20250324102442.1750715-1-s.hauer@pengutronix.de>

is_fat_or_mbr() doesn't detect MBRs anymore because we return
filetype_unknown when it's not a FAT filesystem. Instead we may only
return early when it's explicitly a FAT filesystem, but continue
in the function in case it's not to properly detect a MBR.

Fixes: b25680a9c9 ("filetype: add file_detect_fs_type()")
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/filetype.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/filetype.c b/common/filetype.c
index ce868223d5..80e6ceb845 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -243,9 +243,12 @@ enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec)
 	if (bootsec)
 		*bootsec = 0;
 
-	if (file_detect_fs_fat(sector, 512) != filetype_fat)
+	if (get_unaligned_le16(&sector[BS_55AA]) != 0xAA55)
 		return filetype_unknown;
 
+	if (file_detect_fs_fat(sector, 512) == filetype_fat)
+		return filetype_fat;
+
 	if (bootsec)
 		/*
 		 * This must be an MBR, so return the starting sector of the
-- 
2.39.5



From s.hauer at pengutronix.de  Mon Mar 24 03:24:42 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 11:24:42 +0100
Subject: [PATCH 2/2] filetype: fix FILETYPE_STRING misspelling
In-Reply-To: <20250324102442.1750715-1-s.hauer@pengutronix.de>
References: <20250324102442.1750715-1-s.hauer@pengutronix.de>
Message-ID: <20250324102442.1750715-2-s.hauer@pengutronix.de>

The new Kconfig option checking if filetypes shall be printed as strings
was introduced as CONFIG_FILETYPE_STRING, but the check used
CONFIG_FILETYPE_STRINGS. Rename Kconfig option to match what is actually
checked for.

Fixes: 09702e4a00 ("filetype: make file type strings optional")
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/Kconfig b/common/Kconfig
index 77d03f298c..ddc76b2033 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1309,7 +1309,7 @@ config PBL_OPTEE
 	  Allows starting OP-TEE during lowlevel initialization of the PBL.
 	  Requires explicit support in the board's lowlevel file.
 
-config FILETYPE_STRING
+config FILETYPE_STRINGS
 	bool "Print file types as strings"
 	default y
 	depends on FILETYPE
-- 
2.39.5



From s.hauer at pengutronix.de  Mon Mar 24 03:29:03 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 11:29:03 +0100
Subject: (subset) [PATCH 1/2] arm64: rockchip: Enable rockchip otp
 driver in defconfig
In-Reply-To: <1fb9c1cf650ba020511788388fdfdfe995b25117.1742405341.git.uwe@kleine-koenig.org>
References: <cover.1742405341.git.uwe@kleine-koenig.org>
 <1fb9c1cf650ba020511788388fdfdfe995b25117.1742405341.git.uwe@kleine-koenig.org>
Message-ID: <174281214348.1751096.15767383479623259413.b4-ty@pengutronix.de>


On Wed, 19 Mar 2025 18:32:38 +0100, Uwe Kleine-K?nig wrote:
> This driver is useful on rk3308, rk3568 and rk3588. Enable it in
> rockchip_v8_defconfig.
> 
> 

Applied, thanks!

[1/2] arm64: rockchip: Enable rockchip otp driver in defconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=6c87417f5d53 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 24 03:37:16 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 11:37:16 +0100
Subject: [PATCH 0/2] arm64: rockchip: Two more additions to
 rockchip_v8_defconfig
In-Reply-To: <cover.1742405341.git.uwe@kleine-koenig.org>
References: <cover.1742405341.git.uwe@kleine-koenig.org>
Message-ID: <Z-E13HJbzqRv9eEi@pengutronix.de>

On Wed, Mar 19, 2025 at 06:32:37PM +0100, Uwe Kleine-K?nig wrote:
> Hello,
> 
> while working to support the Qnap TS-433 NAS I found the config items
> enabled here quite useful. I'm not entirely sure that enabling generic
> fit image is useful in general (also because it comes with a build
> dependency on python3-libfdt), still here comes a suggestion to enable
> it.

I agree that this can be quite convenient, but indeed adding more python
build dependencies is not so nice.

If Kconfig could check if scripts/make_fit.py --help can be successfully
executed then might even by default build FIT images.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Mon Mar 24 04:17:49 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Mar 2025 12:17:49 +0100
Subject: [PATCH] mci: fix data write
Message-ID: <20250324111749.2739671-1-s.hauer@pengutronix.de>

The dest and src fields in struct mci_data are a union, so we cannot not
set them both to different values. Only set one of them to make write
support operational again.

Fixes: 3854311954 ("mmc: merge block read/write functions")
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 5b892e8570..947fe44c08 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -360,8 +360,11 @@ static int mci_do_block_op(struct mci *mci, const void *src, void *dst, int bloc
 		mci->high_capacity != 0 ? blocknum : blocknum * mci->read_bl_len,
 		MMC_RSP_R1);
 
-	data.src = src;
-	data.dest = dst;
+	if (dst)
+		data.dest = dst;
+	else
+		data.src = src;
+
 	data.blocks = blocks;
 	data.blocksize = mci->read_bl_len;
 	data.flags = flags;
-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 25 00:16:10 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Mar 2025 08:16:10 +0100
Subject: [PATCH 1/2] filetype: fix MBR detection
In-Reply-To: <20250324102442.1750715-1-s.hauer@pengutronix.de>
References: <20250324102442.1750715-1-s.hauer@pengutronix.de>
Message-ID: <174288697062.1564623.13528006107213875040.b4-ty@pengutronix.de>


On Mon, 24 Mar 2025 11:24:41 +0100, Sascha Hauer wrote:
> is_fat_or_mbr() doesn't detect MBRs anymore because we return
> filetype_unknown when it's not a FAT filesystem. Instead we may only
> return early when it's explicitly a FAT filesystem, but continue
> in the function in case it's not to properly detect a MBR.
> 
> 

Applied, thanks!

[1/2] filetype: fix MBR detection
      https://git.pengutronix.de/cgit/barebox/commit/?id=34d62c6804eb (link may not be stable)
[2/2] filetype: fix FILETYPE_STRING misspelling
      https://git.pengutronix.de/cgit/barebox/commit/?id=4ea15ea6801c (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar 25 00:16:10 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Mar 2025 08:16:10 +0100
Subject: [PATCH] mci: fix data write
In-Reply-To: <20250324111749.2739671-1-s.hauer@pengutronix.de>
References: <20250324111749.2739671-1-s.hauer@pengutronix.de>
Message-ID: <174288697060.1564623.13188596761991649994.b4-ty@pengutronix.de>


On Mon, 24 Mar 2025 12:17:49 +0100, Sascha Hauer wrote:
> The dest and src fields in struct mci_data are a union, so we cannot not
> set them both to different values. Only set one of them to make write
> support operational again.
> 
> 

Applied, thanks!

[1/1] mci: fix data write
      https://git.pengutronix.de/cgit/barebox/commit/?id=f646ed68434f (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Tue Mar 25 00:22:01 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Mar 2025 08:22:01 +0100
Subject: [PATCH v2 1/2] scripts: define le32_to_cpup and friends for
 host/target tools
In-Reply-To: <20250320052114.1732651-1-a.fatoum@pengutronix.de>
References: <20250320052114.1732651-1-a.fatoum@pengutronix.de>
Message-ID: <Z-JZmexeu-CvQXU6@pengutronix.de>

On Thu, Mar 20, 2025 at 06:21:13AM +0100, Ahmad Fatoum wrote:
> We already define le32_to_cpu and friends, but were missing so far the
> p-suffixed variant, which accepts a pointer.
> 
> This is easily implemented with a bit of macro boilerplate, so let's do
> that.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> v1 -> v2:
>   - new patch
> ---
>  scripts/compiler.h | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)

This breaks compilation on riscv:

scripts/compiler.h:182:1: note: in expansion of macro 'DEFINE_CONV_P'
  182 | DEFINE_CONV_P(be, 64)
      | ^~~~~~~~~~~~~
scripts/compiler.h:170:55: error: unknown type name  __be64'
  170 |  static inline u##bits cpu_to_##endian##bits##p(const __##endian##bits *p) \
      |                                                       ^~
scripts/compiler.h:182:1: note: in expansion of macro 'DEFINE_CONV_P'
  182 | DEFINE_CONV_P(be, 64)
      | ^~~~~~~~~~~~~

I added a

#include <linux/types.h>

to scripts/compiler.h

Sascha

> 
> diff --git a/scripts/compiler.h b/scripts/compiler.h
> index d8d0e1b906df..d6807b027e03 100644
> --- a/scripts/compiler.h
> +++ b/scripts/compiler.h
> @@ -160,6 +160,27 @@ typedef uint32_t __u32;
>  # define be64_to_cpu(x)		(x)
>  #endif
>  
> +#define DEFINE_CONV_P(endian, bits) \
> +	static inline __##endian##bits endian##bits##_to_cpup(const u##bits *p) \
> +	{ \
> +		u##bits val; \
> +		memmove(&val, p, sizeof(val)); \
> +		return endian##bits##_to_cpu(val); \
> +	} \
> +	static inline u##bits cpu_to_##endian##bits##p(const __##endian##bits *p) \
> +	{ \
> +		__##endian##bits val; \
> +		memmove(&val, p, sizeof(val)); \
> +		return cpu_to_##endian##bits(val); \
> +	}
> +
> +DEFINE_CONV_P(le, 16)
> +DEFINE_CONV_P(le, 32)
> +DEFINE_CONV_P(le, 64)
> +DEFINE_CONV_P(be, 16)
> +DEFINE_CONV_P(be, 32)
> +DEFINE_CONV_P(be, 64)
> +
>  #ifndef min
>  #define min(x, y) ({                            \
>  	typeof(x) _min1 = (x);                  \
> -- 
> 2.39.5
> 
> 
> 

-- 
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-5555 |


From jmaselbas at zdiv.net  Tue Mar 25 04:52:26 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Tue, 25 Mar 2025 12:52:26 +0100
Subject: [PATCH v2] commands: hwclock: rework argument handling
In-Reply-To: <20250314213344.12335-1-jmaselbas@zdiv.net>
References: <20250314213344.12335-1-jmaselbas@zdiv.net>
Message-ID: <20250325115226.1692-1-jmaselbas@zdiv.net>

The rtc_name doesn't need to be an array, thus the argument doesn't
have to be copied, we can simply use a pointer on optarg.
Drop the array and the string copy.

Suggested-by: Sascha Hauer <s.hauer at pengutronix.de>
Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
v2:
 - remove strcpy call and use a pointer instead (Sascha)

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

diff --git a/commands/hwclock.c b/commands/hwclock.c
index c594e070ac..b04b34cd7c 100644
--- a/commands/hwclock.c
+++ b/commands/hwclock.c
@@ -83,7 +83,7 @@ static int do_hwclock(int argc, char *argv[])
 	struct rtc_device *r;
 	struct rtc_time tm;
 	struct rtc_time stm;
-	char rtc_name[16] = "rtc0";
+	const char *rtc_name = "rtc0";
 	char *env_name = NULL;
 	int opt;
 	int set = 0;
@@ -95,7 +95,7 @@ static int do_hwclock(int argc, char *argv[])
 
 		switch (opt) {
 		case 'f':
-			strncpy(rtc_name, optarg, 16);
+			rtc_name = optarg;
 			break;
 		case 's':
 			memset(&stm, 0, sizeof(stm));
-- 
2.48.1



From a.fatoum at pengutronix.de  Tue Mar 25 05:47:39 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 25 Mar 2025 13:47:39 +0100
Subject: [PATCH master 2/3] sandbox: don't build tap support code without CONFIG_DRIVER_NET_TAP
In-Reply-To: <20250325124740.4035964-1-a.fatoum@pengutronix.de>
References: <20250325124740.4035964-1-a.fatoum@pengutronix.de>
Message-ID: <20250325124740.4035964-3-a.fatoum@pengutronix.de>

There's no point in compiling tap_alloc() if it's not going to be used.
As the file unconditionally uses <linux/*.h> headers, it breaks the
build, when those are not available.

Therefore only build the file if actually needed.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/os/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile
index 7a76fb0290e8..c40bc78d31dd 100644
--- a/arch/sandbox/os/Makefile
+++ b/arch/sandbox/os/Makefile
@@ -20,7 +20,8 @@ ifeq ($(CONFIG_SANDBOX_LINUX_I386),y)
 KBUILD_CFLAGS += -m32
 endif
 
-obj-y = common.o tap.o setjmp.o
+obj-y = common.o setjmp.o
+obj-$(CONFIG_DRIVER_NET_TAP) += tap.o
 obj-$(CONFIG_MALLOC_LIBC) += libc_malloc.o
 
 CFLAGS_sdl.o = $(shell $(PKG_CONFIG) sdl2 --cflags)
-- 
2.39.5



From a.fatoum at pengutronix.de  Tue Mar 25 05:47:38 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 25 Mar 2025 13:47:38 +0100
Subject: [PATCH master 1/3] sandbox: use POSIX header instead of Linux one
In-Reply-To: <20250325124740.4035964-1-a.fatoum@pengutronix.de>
References: <20250325124740.4035964-1-a.fatoum@pengutronix.de>
Message-ID: <20250325124740.4035964-2-a.fatoum@pengutronix.de>

We include <linux/fs.h> to get a definition of BLKGETSIZE64, but this
fails on musl. Both glibc and musl make the definition available via
<sys/mount.h>, so let's use that instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/os/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 7067c94d9b45..d44213319422 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -39,7 +39,7 @@
 #include <sys/select.h>
 #include <sys/wait.h>
 #include <sys/ioctl.h>
-#include <linux/fs.h>
+#include <sys/mount.h>
 #include <sys/time.h>
 /*
  * ...except the ones needed to connect with barebox
-- 
2.39.5



From a.fatoum at pengutronix.de  Tue Mar 25 05:47:40 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 25 Mar 2025 13:47:40 +0100
Subject: [PATCH master 3/3] sandbox: os: tap: make it compile with musl
In-Reply-To: <20250325124740.4035964-1-a.fatoum@pengutronix.de>
References: <20250325124740.4035964-1-a.fatoum@pengutronix.de>
Message-ID: <20250325124740.4035964-4-a.fatoum@pengutronix.de>

musl not ship a definition of IFF_TAP. As this is ABI set in stone,
let's just duplicate the constant we need and use them as fallback, when
<linux/if_tun.h> is missing.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/os/tap.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/sandbox/os/tap.c b/arch/sandbox/os/tap.c
index 83b97ffd49c7..fbb20f2fa80f 100644
--- a/arch/sandbox/os/tap.c
+++ b/arch/sandbox/os/tap.c
@@ -21,10 +21,20 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <linux/if.h>
-#include <linux/if_tun.h>
+#include <net/if.h>
 #include <string.h>
 
+#ifdef __has_include
+#  if !__has_include(<linux/if_tun.h>)
+#    define IFF_TAP		0x0002
+#    define IFF_NO_PI	0x1000
+#    define TUNSETIFF	_IOW('T', 202, int)
+#  endif
+#endif
+#ifndef IFF_TAP
+#  include <linux/if_tun.h>
+#endif
+
 int tap_alloc(const char *dev)
 {
 	struct ifreq ifr;
-- 
2.39.5



From a.fatoum at pengutronix.de  Tue Mar 25 05:47:37 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 25 Mar 2025 13:47:37 +0100
Subject: [PATCH master 0/3] sandbox: enable building under musl
Message-ID: <20250325124740.4035964-1-a.fatoum@pengutronix.de>

Building sandbox itself as opposed to the target/host tools still fails
with musl, due to some headers not being available.

This is fixed by this series.

Ahmad Fatoum (3):
  sandbox: use POSIX header instead of Linux one
  sandbox: don't build tap support code without CONFIG_DRIVER_NET_TAP
  sandbox: os: tap: make it compile with musl

 arch/sandbox/os/Makefile |  3 ++-
 arch/sandbox/os/common.c |  2 +-
 arch/sandbox/os/tap.c    | 14 ++++++++++++--
 3 files changed, 15 insertions(+), 4 deletions(-)

-- 
2.39.5



From s.hauer at pengutronix.de  Tue Mar 25 06:46:30 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Mar 2025 14:46:30 +0100
Subject: [PATCH v2] commands: hwclock: rework argument handling
In-Reply-To: <20250325115226.1692-1-jmaselbas@zdiv.net>
References: <20250314213344.12335-1-jmaselbas@zdiv.net>
 <20250325115226.1692-1-jmaselbas@zdiv.net>
Message-ID: <174291039090.3214606.1209486625604602351.b4-ty@pengutronix.de>


On Tue, 25 Mar 2025 12:52:26 +0100, Jules Maselbas wrote:
> The rtc_name doesn't need to be an array, thus the argument doesn't
> have to be copied, we can simply use a pointer on optarg.
> Drop the array and the string copy.
> 
> 

Applied, thanks!

[1/1] commands: hwclock: rework argument handling
      https://git.pengutronix.de/cgit/barebox/commit/?id=8c796cc0e810 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From jmaselbas at zdiv.net  Tue Mar 25 07:36:50 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Tue, 25 Mar 2025 15:36:50 +0100
Subject: [PATCH] fixup! tee: optee: implement RPMB support
In-Reply-To: <20250312-rpmb-v1-7-0f213382a3f3@pengutronix.de>
References: <20250312-rpmb-v1-7-0f213382a3f3@pengutronix.de>
Message-ID: <20250325143650.29433-1-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/tee/optee/rpmb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c
index cdc8afc1a4..ca60f3cf3d 100644
--- a/drivers/tee/optee/rpmb.c
+++ b/drivers/tee/optee/rpmb.c
@@ -5,6 +5,7 @@
 
 #define pr_fmt(fmt)     "optee-rpmb: " fmt
 
+#include <common.h>
 #include <mci.h>
 
 #include "optee_msg.h"
-- 
2.48.1



From jmaselbas at zdiv.net  Tue Mar 25 08:52:58 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Tue, 25 Mar 2025 16:52:58 +0100
Subject: [PATCH] treewide: add explicit fallthrough and break
Message-ID: <20250325155258.31869-1-jmaselbas@zdiv.net>

Replace existing fallthrough comments with the `fallthrough;` pseudo-keyword.
Add a few break statement when the last case of a switch is not empty, so it
will not be forgot when a new case is added at the end.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 arch/arm/cpu/interrupts_64.c                 | 6 +++---
 arch/arm/mach-omap/omap3_generic.c           | 8 ++------
 common/bootsource.c                          | 8 ++++----
 drivers/i2c/busses/i2c-designware.c          | 3 ++-
 drivers/i2c/busses/i2c-omap.c                | 3 ++-
 drivers/mfd/rave-sp.c                        | 5 +++--
 drivers/net/e1000/main.c                     | 7 +++----
 drivers/net/phy/mv88e6xxx/port.c             | 4 ++--
 drivers/net/usb/usbnet.c                     | 2 +-
 drivers/pci/pci-imx6.c                       | 4 ++--
 drivers/serial/serial_ns16550_pci.c          | 7 +++++--
 drivers/usb/gadget/epautoconf.c              | 3 ++-
 drivers/usb/gadget/function/f_mass_storage.c | 2 +-
 drivers/usb/gadget/function/u_serial.c       | 2 +-
 drivers/usb/host/xhci.c                      | 3 ++-
 drivers/usb/musb/musb_core.c                 | 2 +-
 drivers/usb/musb/musb_gadget_ep0.c           | 7 ++++---
 drivers/usb/musb/musb_host.c                 | 6 ++++--
 fs/jffs2/readinode.c                         | 2 +-
 lib/xymodem.c                                | 2 +-
 20 files changed, 46 insertions(+), 40 deletions(-)

diff --git a/arch/arm/cpu/interrupts_64.c b/arch/arm/cpu/interrupts_64.c
index 8933cfeb42..4d4ef2bab8 100644
--- a/arch/arm/cpu/interrupts_64.c
+++ b/arch/arm/cpu/interrupts_64.c
@@ -212,13 +212,13 @@ static int aarch64_init_vectors(void)
 	switch (el) {
 	case 3:
 		asm volatile("msr vbar_el3, %0" : : "r" (&vectors) : "cc");
-		/* Fall through */
+		fallthrough;
 	case 2:
 		asm volatile("msr vbar_el2, %0" : : "r" (&vectors) : "cc");
-		/* Fall through */
+		fallthrough;
 	case 1:
 		asm volatile("msr vbar_el1, %0" : : "r" (&vectors) : "cc");
-		/* Fall through */
+		fallthrough;
 	default:
 		break;
 	}
diff --git a/arch/arm/mach-omap/omap3_generic.c b/arch/arm/mach-omap/omap3_generic.c
index f69122b580..33f78dd2d5 100644
--- a/arch/arm/mach-omap/omap3_generic.c
+++ b/arch/arm/mach-omap/omap3_generic.c
@@ -117,11 +117,9 @@ u32 get_cpu_rev(void)
 			retval = OMAP36XX_ES1_1;
 			break;
 		case 2:
-			/*
-			 * Fall through the default case.
-			 */
 		default:
 			retval = OMAP36XX_ES1_2;
+			break;
 		}
 		break;
 	case CPU_3430:
@@ -149,11 +147,9 @@ u32 get_cpu_rev(void)
 				retval = OMAP34XX_ES3;
 				break;
 			case 4:
-				/*
-				 * Same as default case
-				 */
 			default:
 				retval = OMAP34XX_ES3_1;
+				break;
 			}
 		}
 	}
diff --git a/common/bootsource.c b/common/bootsource.c
index 4bccdfdb70..d054427c6e 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -58,10 +58,10 @@ const char *bootsource_get_alias_stem(enum bootsource src)
 	case BOOTSOURCE_SPI_EEPROM:
 	case BOOTSOURCE_SPI_NOR:
 		return bootsource_str[BOOTSOURCE_SPI];
-	case BOOTSOURCE_SERIAL:	/* FALLTHROUGH */
-	case BOOTSOURCE_I2C:	/* FALLTHROUGH */
-	case BOOTSOURCE_MMC:	/* FALLTHROUGH */
-	case BOOTSOURCE_SPI:	/* FALLTHROUGH */
+	case BOOTSOURCE_SERIAL:
+	case BOOTSOURCE_I2C:
+	case BOOTSOURCE_MMC:
+	case BOOTSOURCE_SPI:
 	case BOOTSOURCE_CAN:
 		return bootsource_str[src];
 	default:
diff --git a/drivers/i2c/busses/i2c-designware.c b/drivers/i2c/busses/i2c-designware.c
index 3ba10e172a..83bf0ec3e9 100644
--- a/drivers/i2c/busses/i2c-designware.c
+++ b/drivers/i2c/busses/i2c-designware.c
@@ -565,7 +565,8 @@ static int i2c_dw_probe(struct device *pdev)
 	default:
 		dev_warn(pdev, "requested bitrate (%d) is not supported.\n"
 			 " Falling back to 100kHz", bitrate);
-	case 100000:		/* FALLTHROUGH */
+		fallthrough;
+	case 100000:
 		ic_con = DW_IC_CON_SPEED_STD;
 		break;
 	}
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 0ee4c70de5..a1a6cefd60 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -1123,7 +1123,7 @@ i2c_omap_probe(struct device *pdev)
 		major = OMAP_I2C_REV_SCHEME_0_MAJOR(i2c_omap->rev);
 		break;
 	case OMAP_I2C_SCHEME_1:
-		/* FALLTHROUGH */
+		fallthrough;
 	default:
 		i2c_omap->regs = (u8 *)reg_map_ip_v2;
 		rev = (rev << 16) |
@@ -1131,6 +1131,7 @@ i2c_omap_probe(struct device *pdev)
 		minor = OMAP_I2C_REV_SCHEME_1_MINOR(rev);
 		major = OMAP_I2C_REV_SCHEME_1_MAJOR(rev);
 		i2c_omap->rev = rev;
+		break;
 	}
 
 	i2c_omap->errata = 0;
diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c
index c7968b75f5..ff21a81026 100644
--- a/drivers/mfd/rave-sp.c
+++ b/drivers/mfd/rave-sp.c
@@ -237,9 +237,10 @@ static void *stuff(unsigned char *dest, const unsigned char *src, size_t n)
 		case RAVE_SP_ETX:
 		case RAVE_SP_DLE:
 			*dest++ = RAVE_SP_DLE;
-			/* FALLTHROUGH */
+			fallthrough;
 		default:
 			*dest++ = byte;
+			break;
 		}
 	}
 
@@ -497,7 +498,7 @@ static int rave_sp_receive_buf(struct serdev_device *serdev,
 			 * deframer buffer
 			 */
 
-			/* FALLTHROUGH */
+			fallthrough;
 
 		case RAVE_SP_EXPECT_ESCAPED_DATA:
 			if (deframer->length == sizeof(deframer->data)) {
diff --git a/drivers/net/e1000/main.c b/drivers/net/e1000/main.c
index 1f2f6fbe0b..08d8fba43b 100644
--- a/drivers/net/e1000/main.c
+++ b/drivers/net/e1000/main.c
@@ -304,7 +304,7 @@ static bool e1000_is_second_port(struct e1000_hw *hw)
 	case e1000_82571:
 		if (e1000_read_reg(hw, E1000_STATUS) & E1000_STATUS_FUNC_1)
 			return true;
-		/* Fallthrough */
+		fallthrough;
 	default:
 		return false;
 	}
@@ -785,7 +785,7 @@ static int e1000_open(struct eth_device *edev)
 		reg_data = e1000_read_reg_array(hw, E1000_FFLT, 1);
 		reg_data &= ~0x00100000;
 		e1000_write_reg_array(hw, E1000_FFLT, 1, reg_data);
-		/* Fall through */
+		fallthrough;
 	case e1000_82571:
 	case e1000_82572:
 	case e1000_ich8lan:
@@ -2795,8 +2795,7 @@ static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw)
 		/* Separate *_CFG_DONE_* bit for each port */
 		if (e1000_is_second_port(hw))
 			cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
-		/* Fall Through */
-
+		fallthrough;
 	case e1000_82571:
 	case e1000_82572:
 	case e1000_igb:
diff --git a/drivers/net/phy/mv88e6xxx/port.c b/drivers/net/phy/mv88e6xxx/port.c
index 2b3d86ddda..24b248e39d 100644
--- a/drivers/net/phy/mv88e6xxx/port.c
+++ b/drivers/net/phy/mv88e6xxx/port.c
@@ -218,7 +218,7 @@ static int mv88e6xxx_port_set_speed(struct mv88e6xxx_chip *chip, int port,
 			MV88E6390_PORT_MAC_CTL_ALTSPEED;
 		break;
 	case 10000:
-		/* all bits set, fall through... */
+		/* all bits set */
 		fallthrough;
 	case SPEED_UNFORCED:
 		ctrl = MV88E6XXX_PORT_MAC_CTL_SPEED_UNFORCED;
@@ -619,7 +619,7 @@ int mv88e6xxx_port_probe(struct mv88e6xxx_chip *chip)
 					  status);
 			switch (i) {
 			case 4:
-			case 5:	/* FALLTHROUGH */
+			case 5:
 				if (cmode == MV88E6165_PORT_STS_CMODE_SGMII) {
 					/*
 					 * Port is configured to SGMII
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 7f6b13198f..91ce1f00fa 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -37,7 +37,7 @@ int usbnet_get_endpoints(struct usbnet *dev)
 				if (!usb_endpoint_dir_in(e))
 					continue;
 				intr = 1;
-				/* FALLTHROUGH */
+				fallthrough;
 			case USB_ENDPOINT_XFER_BULK:
 				break;
 			default:
diff --git a/drivers/pci/pci-imx6.c b/drivers/pci/pci-imx6.c
index ac62d961d9..17a572722d 100644
--- a/drivers/pci/pci-imx6.c
+++ b/drivers/pci/pci-imx6.c
@@ -304,7 +304,7 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)
 
 	switch (imx6_pcie->drvdata->variant) {
 	case IMX6QP:
-	case IMX6Q:		/* FALLTHROUGH */
+	case IMX6Q:
 		/* power up core phy and enable ref clock */
 		gpr1 = readl(imx6_pcie->iomuxc_gpr + IOMUXC_GPR1);
 		gpr1 &= ~IMX6Q_GPR1_PCIE_TEST_PD;
@@ -481,7 +481,7 @@ static void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie)
 		writel(gpr12, imx6_pcie->iomuxc_gpr + IOMUXC_GPR12);
 		break;
 	case IMX6QP:
-	case IMX6Q:	/* FALLTHROUGH */
+	case IMX6Q:
 		gpr12 = readl(imx6_pcie->iomuxc_gpr + IOMUXC_GPR12);
 		gpr12 &= ~IMX6Q_GPR12_PCIE_CTL_2;
 		writel(gpr12, imx6_pcie->iomuxc_gpr + IOMUXC_GPR12);
diff --git a/drivers/serial/serial_ns16550_pci.c b/drivers/serial/serial_ns16550_pci.c
index f82b5797ce..6f19dff740 100644
--- a/drivers/serial/serial_ns16550_pci.c
+++ b/drivers/serial/serial_ns16550_pci.c
@@ -561,12 +561,13 @@ pci_timedia_setup(struct serial_private *priv,
 		break;
 	case 3:
 		offset = board->uart_offset;
-		/* FALLTHROUGH */
+		fallthrough;
 	case 4: /* BAR 2 */
 	case 5: /* BAR 3 */
 	case 6: /* BAR 4 */
 	case 7: /* BAR 5 */
 		bar = idx - 2;
+		break;
 	}
 
 	return setup_port(priv, port, bar, offset, board->reg_shift);
@@ -592,6 +593,7 @@ titan_400l_800l_setup(struct serial_private *priv,
 	default:
 		bar = 4;
 		offset = (idx - 2) * board->uart_offset;
+		break;
 	}
 
 	return setup_port(priv, port, bar, offset, board->reg_shift);
@@ -745,7 +747,7 @@ static int pci_netmos_init(struct pci_dev *dev)
 			dev->subsystem_device == 0x0299)
 		return 0;
 
-	switch (dev->device) { /* FALLTHROUGH on all */
+	switch (dev->device) {
 	case PCI_DEVICE_ID_NETMOS_9904:
 	case PCI_DEVICE_ID_NETMOS_9912:
 	case PCI_DEVICE_ID_NETMOS_9922:
@@ -853,6 +855,7 @@ static int pci_ite887x_init(struct pci_dev *dev)
 	default:
 		moan_device("Unknown ITE887x", dev);
 		ret = -ENODEV;
+		break;
 	}
 
 	/* configure all serial ports */
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index ff16abaf12..fc76a1d443 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -86,6 +86,7 @@ ep_matches (
 			case USB_ENDPOINT_XFER_ISOC:
 				if ('s' != tmp[2])	// != "-iso"
 					return 0;
+				break;
 			}
 		} else {
 			tmp = ep->name + strlen (ep->name);
@@ -134,7 +135,7 @@ ep_matches (
 		/* INT:  limit 64 bytes full speed, 1024 high/super speed */
 		if (!gadget_is_dualspeed(gadget) && max > 64)
 			return 0;
-		/* FALLTHROUGH */
+		fallthrough;
 
 	case USB_ENDPOINT_XFER_ISOC:
 		/* ISO:  limit 1023 bytes full speed, 1024 high/super speed */
diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index e099123cea..e5d10a3e3e 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -1986,7 +1986,7 @@ static int do_scsi_command(struct fsg_common *common)
 	case SCSI_RELEASE:
 	case SCSI_RESERVE:
 	case SCSI_SEND_DIAG:
-		/* Fall through */
+		fallthrough;
 
 	default:
 unknown_cmnd:
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index ca4e77c5ff..a8f30944e8 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -181,7 +181,7 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
 		/* presumably a transient fault */
 		pr_warning("%s: unexpected %s status %d\n",
 				__func__, ep->name, req->status);
-		/* FALL THROUGH */
+		fallthrough;
 	case 0:
 		/* normal completion */
 		break;
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index bad247ff9e..27d4353597 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -327,7 +327,7 @@ static unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
 								  endpt_desc);
 			break;
 		}
-		/* Fall through - SS and HS isoc/int have same decoding */
+		fallthrough; /* SS and HS isoc/int have same decoding */
 
 	case USB_SPEED_SUPER:
 		if (usb_endpoint_xfer_int(endpt_desc) ||
@@ -343,6 +343,7 @@ static unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
 								endpt_desc);
 			break;
 		}
+		fallthrough;
 		/*
 		 * Fall through for interrupt endpoint interval decoding
 		 * since it uses the same rules as low speed interrupt
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 9c6c4e7bb4..8ae0fe08ed 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -623,7 +623,7 @@ static int ep_config_from_table(struct musb *musb)
 	switch (fifo_mode) {
 	default:
 		fifo_mode = 0;
-		/* FALLTHROUGH */
+		fallthrough;
 	case 0:
 		cfg = mode_0_cfg;
 		n = ARRAY_SIZE(mode_0_cfg);
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index eed02a8581..268f67b820 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -736,7 +736,7 @@ irqreturn_t musb_g_ep0_irq(struct musb *musb)
 			musb_writeb(mbase, MUSB_TESTMODE,
 					musb->test_mode_nr);
 		}
-		/* FALLTHROUGH */
+		fallthrough;
 
 	case MUSB_EP0_STAGE_STATUSOUT:
 		/* end of sequence #1: write to host (TX state) */
@@ -768,7 +768,7 @@ irqreturn_t musb_g_ep0_irq(struct musb *musb)
 		 */
 		retval = IRQ_HANDLED;
 		musb->ep0_state = MUSB_EP0_STAGE_SETUP;
-		/* FALLTHROUGH */
+		fallthrough;
 
 	case MUSB_EP0_STAGE_SETUP:
 setup:
@@ -1025,7 +1025,7 @@ static int musb_g_ep0_halt(struct usb_ep *e, int value)
 	case MUSB_EP0_STAGE_ACKWAIT:	/* STALL for zero-length data */
 	case MUSB_EP0_STAGE_RX:		/* control-OUT data */
 		csr = musb_readw(regs, MUSB_CSR0);
-		/* FALLTHROUGH */
+		fallthrough;
 
 	/* It's also OK to issue stalls during callbacks when a non-empty
 	 * DATA stage buffer has been read (or even written).
@@ -1041,6 +1041,7 @@ static int musb_g_ep0_halt(struct usb_ep *e, int value)
 	default:
 		dev_dbg(musb->controller, "ep0 can't halt in state %d\n", musb->ep0_state);
 		status = -EINVAL;
+		break;
 	}
 
 cleanup:
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 8176accb4f..3b5fde42b1 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -824,7 +824,7 @@ static bool musb_h_ep0_continue(struct musb *musb, u16 len, struct urb *urb)
 			musb->ep0_stage = MUSB_EP0_OUT;
 			more = true;
 		}
-		/* FALLTHROUGH */
+		fallthrough;
 	case MUSB_EP0_OUT:
 		fifo_count = min_t(size_t, qh->maxpacket,
 				   urb->transfer_buffer_length -
@@ -1498,6 +1498,7 @@ int musb_urb_enqueue(
 		break;
 	default:
 		type_reg |= 0x40;
+		break;
 	}
 	qh->type_reg = type_reg;
 
@@ -1512,7 +1513,7 @@ int musb_urb_enqueue(
 			interval = max_t(u8, epd->bInterval, 1);
 			break;
 		}
-		/* FALLTHROUGH */
+		fallthrough;
 	case USB_ENDPOINT_XFER_ISOC:
 		/* ISO always uses logarithmic encoding */
 		interval = min_t(u8, epd->bInterval, 16);
@@ -1533,6 +1534,7 @@ int musb_urb_enqueue(
 		 * The upside of disabling it is simpler transfer scheduling.
 		 */
 		interval = 0;
+		break;
 	}
 	qh->intv_reg = interval;
 
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 4634ee5818..d56001e5cb 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -1248,7 +1248,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
 			dbg_readinode("symlink's target '%s' cached\n", f->target);
 		}
 
-		/* fall through... */
+		fallthrough;
 
 	case S_IFBLK:
 	case S_IFCHR:
diff --git a/lib/xymodem.c b/lib/xymodem.c
index 136741ab4a..84a9115771 100644
--- a/lib/xymodem.c
+++ b/lib/xymodem.c
@@ -461,7 +461,7 @@ static int xymodem_handle(struct xyz_ctxt *proto)
 			if (crc_tries++ > MAX_RETRIES_WITH_CRC)
 				proto->crc_mode = CRC_ADD8;
 			xy_putc(proto->cdev, invite);
-			/* Fall through */
+			fallthrough;
 		case PROTO_STATE_RECEIVE_BODY:
 			rc = xy_read_block(proto, &blk, 3 * SECOND);
 			if (rc > 0) {
-- 
2.48.1



From jmaselbas at zdiv.net  Tue Mar 25 08:53:26 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Tue, 25 Mar 2025 16:53:26 +0100
Subject: [PATCH 1/2] vsprintf: fix missing break when printing %pJP
Message-ID: <20250325155327.31981-1-jmaselbas@zdiv.net>

When the format `%pJP` was introduced the new switch case didn't had a
break at the end, it was last case in the switch. However subsequent
commit didn't add a break either, creating a potential fallthrough.
Add the missing break.

Fixes: 107eeef8f2 ("vsprintf: add support for printing MAC addresses")
Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 lib/vsprintf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index f553662ce8..0656ba3620 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -561,6 +561,7 @@ static char *pointer(const char *fmt, char *buf, const char *end, const void *pt
 	case 'J':
 		if (fmt[1] == 'P' && IS_ENABLED(CONFIG_JSMN))
 			return jsonpath_string(buf, end, ptr, field_width, precision, flags, fmt);
+		break;
         case 'M':
 		/* Colon separated: 00:01:02:03:04:05 */
 		return mac_address_string(buf, end, ptr, field_width, precision, flags, fmt);
-- 
2.48.1



From jmaselbas at zdiv.net  Tue Mar 25 08:53:27 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Tue, 25 Mar 2025 16:53:27 +0100
Subject: [PATCH 2/2] vsprintf: add explicit fallthrough
In-Reply-To: <20250325155327.31981-1-jmaselbas@zdiv.net>
References: <20250325155327.31981-1-jmaselbas@zdiv.net>
Message-ID: <20250325155327.31981-2-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 lib/vsprintf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 0656ba3620..32429dd76c 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -775,6 +775,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 
 			case 'x':
 				flags |= SMALL;
+				fallthrough;
 			case 'X':
 				base = 16;
 				break;
@@ -782,6 +783,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 			case 'd':
 			case 'i':
 				flags |= SIGN;
+				fallthrough;
 			case 'u':
 				break;
 
-- 
2.48.1



From jmaselbas at zdiv.net  Tue Mar 25 08:54:13 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Tue, 25 Mar 2025 16:54:13 +0100
Subject: [PATCH] lib: add explicit fallthrough in strtoull_suffix
Message-ID: <20250325155413.32169-1-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 lib/misc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/misc.c b/lib/misc.c
index 1cb2a6b9b5..7cb7c6224a 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -37,12 +37,15 @@ unsigned long long strtoull_suffix(const char *str, char **endp, int base)
 	switch (*end) {
 	case 'G':
 		val *= 1024;
+		fallthrough;
 	case 'M':
 		val *= 1024;
+		fallthrough;
 	case 'k':
 	case 'K':
 		val *= 1024;
 		end++;
+		break;
 	default:
 		break;
 	}
-- 
2.48.1



From jmaselbas at zdiv.net  Tue Mar 25 08:55:39 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Tue, 25 Mar 2025 16:55:39 +0100
Subject: [PATCH] mtd: spi-nor: add explicit fallthrough
Message-ID: <20250325155539.32501-1-jmaselbas@zdiv.net>

Add the fallthrough pseudo keyword: the case sets `need_wren = true;`
which is used (only read and never written) in the case below.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/mtd/spi-nor/spi-nor.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index b9b2c7f6e5..6fcb8f38fa 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -316,6 +316,7 @@ static inline int set_4byte(struct spi_nor *nor, struct flash_info *info,
 	case CFI_MFR_ST: /* Micron, actually */
 		/* Some Micron need WREN command; all will accept it */
 		need_wren = true;
+		fallthrough;
 	case CFI_MFR_MACRONIX:
 	case 0xEF /* winbond */:
 		if (need_wren)
-- 
2.48.1



From jmaselbas at zdiv.net  Tue Mar 25 08:56:14 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Tue, 25 Mar 2025 16:56:14 +0100
Subject: [PATCH] lib: add explicit break in kstrtox/strtox
Message-ID: <20250325155614.32678-1-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 lib/kstrtox.c | 1 +
 lib/strtox.c  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index 0e4b590531..2052ee94cb 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -357,6 +357,7 @@ int kstrtobool(const char *s, bool *res)
 		default:
 			break;
 		}
+		break;
 	default:
 		break;
 	}
diff --git a/lib/strtox.c b/lib/strtox.c
index b11cc8c969..679a747173 100644
--- a/lib/strtox.c
+++ b/lib/strtox.c
@@ -105,6 +105,7 @@ s64 simple_strtofract(const char *cp, char **endp, u32 division)
 		fallthrough;
 	case '+':
 		cp++;
+		break;
 	}
 
 	if (!isdigit(*cp))
-- 
2.48.1



From jmaselbas at zdiv.net  Tue Mar 25 09:00:08 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Tue, 25 Mar 2025 17:00:08 +0100
Subject: [RFC PATCH] fbconsole: add missing break
Message-ID: <20250325160008.1076-1-jmaselbas@zdiv.net>

The cursor move CSI has nothing to do with the clear-screen CSI.
The existing fallthrough looks like a bug, add the missing break.

Fixes: 27f79c05ab ("video: implement framebuffer console")
Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---

 I am not 100% sure if this is a bug or not, it feels like it sould not
 fallthrough, an extra look would be nice.


 drivers/video/fbconsole.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 24592d00ed..7462e34778 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -576,6 +576,7 @@ static void fbc_parse_csi(struct fbc_priv *priv)
 		priv->x = clamp(pos - 1, 0, (int) priv->cols - 1);
 
 		show_cursor(priv, priv->x, priv->y);
+		break;
 	case 'K':
 		pos = simple_strtoul(priv->csi, &end, 10);
 		video_invertchar(priv, priv->x, priv->y);
-- 
2.48.1



From a.fatoum at pengutronix.de  Tue Mar 25 09:58:02 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 25 Mar 2025 17:58:02 +0100
Subject: [PATCH 1/2] vsprintf: fix missing break when printing %pJP
In-Reply-To: <20250325155327.31981-1-jmaselbas@zdiv.net>
References: <20250325155327.31981-1-jmaselbas@zdiv.net>
Message-ID: <13bee917-8783-456f-9426-71e77747f050@pengutronix.de>

Hello Jules,

On 3/25/25 16:53, Jules Maselbas wrote:
> When the format `%pJP` was introduced the new switch case didn't had a
> break at the end, it was last case in the switch. However subsequent
> commit didn't add a break either, creating a potential fallthrough.
> Add the missing break.
> 
> Fixes: 107eeef8f2 ("vsprintf: add support for printing MAC addresses")
> Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>

Ouch, Good catch.

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

Thanks,
Ahmad

> ---
>  lib/vsprintf.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index f553662ce8..0656ba3620 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -561,6 +561,7 @@ static char *pointer(const char *fmt, char *buf, const char *end, const void *pt
>  	case 'J':
>  		if (fmt[1] == 'P' && IS_ENABLED(CONFIG_JSMN))
>  			return jsonpath_string(buf, end, ptr, field_width, precision, flags, fmt);
> +		break;
>          case 'M':
>  		/* Colon separated: 00:01:02:03:04:05 */
>  		return mac_address_string(buf, end, ptr, field_width, precision, flags, fmt);



From a.fatoum at pengutronix.de  Tue Mar 25 23:52:41 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 07:52:41 +0100
Subject: [PATCH] fixup! tee: optee: implement RPMB support
In-Reply-To: <20250325143650.29433-1-jmaselbas@zdiv.net>
References: <20250312-rpmb-v1-7-0f213382a3f3@pengutronix.de>
 <20250325143650.29433-1-jmaselbas@zdiv.net>
Message-ID: <579eeb04-43ef-4665-99c8-dd9d19cdbb3b@pengutronix.de>

Hello Jules,

On 25.03.25 15:36, Jules Maselbas wrote:
> Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
> ---
>  drivers/tee/optee/rpmb.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c
> index cdc8afc1a4..ca60f3cf3d 100644
> --- a/drivers/tee/optee/rpmb.c
> +++ b/drivers/tee/optee/rpmb.c
> @@ -5,6 +5,7 @@
>  
>  #define pr_fmt(fmt)     "optee-rpmb: " fmt
>  
> +#include <common.h>

Is this only for ARRAY_SIZE? Then I'd prefer we include <linux/kernel.h> or
<linux/array_size.h>, because we generally want to cut down on use of
<common.h>, if only to reduce compile time a bit.

Also, please send fixups without a reply-to for patches that are already applied.
This makes it less likely to be missed IMO.

Cheers,
Ahmad



>  #include <mci.h>
>  
>  #include "optee_msg.h"


-- 
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-5555 |


From a.fatoum at pengutronix.de  Wed Mar 26 00:59:16 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 08:59:16 +0100
Subject: [PATCH 3/6] MAKEALL: fix check_pipe_status usage
In-Reply-To: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
References: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
Message-ID: <20250326075919.3448789-4-a.fatoum@pengutronix.de>

When no logdir is specified, there is no shell pipeline to check the
status of and thus check_pipe_status will not check the status of the
just run command.

Fix this by placing check_pipe_status directly after the pipelines in
question.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 MAKEALL | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/MAKEALL b/MAKEALL
index a9409fbf7b07..85b71e2e75c1 100755
--- a/MAKEALL
+++ b/MAKEALL
@@ -101,9 +101,12 @@ with_logs_collected() {
 
 	if [ -n "${logdir}" ]; then
 		"$@" 2>&1 > "${log_report}" | tee "${log_err}"
+		check_pipe_status
 	else
 		"$@"
 	fi
+
+	return $?
 }
 
 report() {
@@ -169,7 +172,6 @@ do_build_defconfig() {
 	done
 	with_logs_collected ${MAKE} $silent_flag olddefconfig
 
-	check_pipe_status
 	configure_result="$?"
 
 	report "Configure: "
@@ -178,8 +180,6 @@ do_build_defconfig() {
 		report "OK     \n"
 
 		with_logs_collected ${MAKE} $silent_flag ${TARGET}
-
-		check_pipe_status
 		compile_result="$?"
 
 		report "Compile: " ${defconfig}
@@ -230,8 +230,6 @@ do_test_defconfig() {
 	local err=0
 
 	LG_BUILDDIR=$BUILDDIR with_logs_collected pytest --lg-env $yaml "$@"
-
-	check_pipe_status
 	compile_result="$?"
 
 	report "Test: " ${yaml}
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 00:59:13 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 08:59:13 +0100
Subject: [PATCH 0/6] ci: run tests and static analysis on allyesconfig
Message-ID: <20250326075919.3448789-1-a.fatoum@pengutronix.de>

With a one-liner fix remaining[1], sandbox now builds allyesconfig sans
SDL/libftdi to completion. Let's seize the opportunity and add it to CI,
so we easily detect breakage around allyesconfig in future.

This series also switches the recently added Coverity and CodeQL Github
Actions to use allyesconfig to extend coverage to non-sandbox related
drivers as well.

[1]: https://lore.barebox.org/barebox/20250312-rpmb-v1-7-0f213382a3f3 at pengutronix.de/T/#m4e6fcf916dd9461bbef25a93439ad8fdb36c8217

Ahmad Fatoum (6):
  sandbox: use CROSS_PKG_CONFIG when compiling sandbox arch code
  sandbox: hide sdl/libftdi symbols if libraries not found
  MAKEALL: fix check_pipe_status usage
  MAKEALL: remove use of alias in script
  ci: pytest: run test suite on sandbox allyesconfig
  ci: run static analysis on allyesconfig

 .github/workflows/codeql.yml              |  2 +-
 .github/workflows/coverity.sh             |  2 +-
 .github/workflows/test-labgrid-pytest.yml |  4 ++++
 MAKEALL                                   | 14 +++++++-------
 arch/sandbox/Kconfig                      |  6 ++++++
 arch/sandbox/Makefile                     |  4 ++--
 arch/sandbox/os/Makefile                  |  4 ++--
 drivers/gpio/Kconfig                      |  2 +-
 drivers/sound/Kconfig                     |  2 +-
 drivers/video/Kconfig                     |  2 +-
 test/sandbox/allyesconfig.yaml            | 17 +++++++++++++++++
 11 files changed, 43 insertions(+), 16 deletions(-)
 create mode 100644 test/sandbox/allyesconfig.yaml

-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 00:59:17 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 08:59:17 +0100
Subject: [PATCH 4/6] MAKEALL: remove use of alias in script
In-Reply-To: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
References: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
Message-ID: <20250326075919.3448789-5-a.fatoum@pengutronix.de>

Aliases are meant for interactive shell and not expanded by default in
scripts. As we are going to call pytest in one location only, just turn
it into a variable.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 MAKEALL | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/MAKEALL b/MAKEALL
index 85b71e2e75c1..d47f0204f1f1 100755
--- a/MAKEALL
+++ b/MAKEALL
@@ -219,7 +219,9 @@ do_build_defconfig() {
 }
 
 if command -v labgrid-pytest >/dev/null; then
-	alias pytest=labgrid-pytest
+	pytest=labgrid-pytest
+else
+	pytest=pytest
 fi
 
 do_test_defconfig() {
@@ -229,7 +231,7 @@ do_test_defconfig() {
 	local step_time_start=$(date +%s)
 	local err=0
 
-	LG_BUILDDIR=$BUILDDIR with_logs_collected pytest --lg-env $yaml "$@"
+	LG_BUILDDIR=$BUILDDIR with_logs_collected $pytest --lg-env $yaml "$@"
 	compile_result="$?"
 
 	report "Test: " ${yaml}
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 00:59:15 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 08:59:15 +0100
Subject: [PATCH 2/6] sandbox: hide sdl/libftdi symbols if libraries not found
In-Reply-To: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
References: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
Message-ID: <20250326075919.3448789-3-a.fatoum@pengutronix.de>

To make an allyesconfig build work out of the box on sandbox, let's hide
the SDL and libftdi GPIO drivers unless the libraries are already
installed.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/Kconfig  | 6 ++++++
 drivers/gpio/Kconfig  | 2 +-
 drivers/sound/Kconfig | 2 +-
 drivers/video/Kconfig | 2 +-
 4 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index 0357414a3f79..c404f73a9970 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -81,6 +81,12 @@ config CMD_SANDBOX_CPUINFO
 	help
 	  Say yes here to get a dummy cpuinfo command.
 
+config HAVE_LIBSDL2
+	def_bool $(success,$(CROSS_PKG_CONFIG) --exists sdl2)
+
+config HAVE_LIBFTDI
+	def_bool $(success,$(CROSS_PKG_CONFIG) --exists libftdi1)
+
 config SDL
 	bool
 
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index dd95e8906b39..7caa1aa96eb3 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -229,7 +229,7 @@ config GPIO_STARFIVE
 
 config GPIO_LIBFTDI1
 	bool "libftdi1 driver"
-	depends on SANDBOX
+	depends on HAVE_LIBFTDI1
 
 config GPIO_ZYNQ
 	tristate "Xilinx Zynq GPIO support"
diff --git a/drivers/sound/Kconfig b/drivers/sound/Kconfig
index bf6f715200e0..bc695fed2cd4 100644
--- a/drivers/sound/Kconfig
+++ b/drivers/sound/Kconfig
@@ -11,7 +11,7 @@ if SOUND
 
 config SOUND_SDL
 	bool "SDL sound driver for sandbox"
-	depends on SANDBOX && OFDEVICE
+	depends on HAVE_LIBSDL2 && OFDEVICE
 	select SDL
 
 config PWM_BEEPER
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 0539e2d453da..ef19948219f3 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -70,7 +70,7 @@ config DRIVER_VIDEO_STM32_LTDC
 
 config DRIVER_VIDEO_SDL
 	bool "SDL framebuffer driver"
-	depends on SANDBOX
+	depends on HAVE_LIBSDL2
 	select SDL
 
 config DRIVER_VIDEO_PXA
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 00:59:14 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 08:59:14 +0100
Subject: [PATCH 1/6] sandbox: use CROSS_PKG_CONFIG when compiling sandbox arch code
In-Reply-To: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
References: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
Message-ID: <20250326075919.3448789-2-a.fatoum@pengutronix.de>

sandbox only means that we run under Linux as host operating system
(as opposed to before). It can still be cross compiled and indeed that's
what barebox-tools in OE-core does to build the target tools.

OE-core doesn't yet build barebox for sandbox itself (only the scripts),
but nonetheless, if it did, SDL and libftdi need to be usable with the
cross toolchain, not with the host toolchain, so let's use
CROSS_PKG_CONFIG accordingly.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/Makefile    | 4 ++--
 arch/sandbox/os/Makefile | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile
index 157e856c59b1..dbdf8a6e8117 100644
--- a/arch/sandbox/Makefile
+++ b/arch/sandbox/Makefile
@@ -62,11 +62,11 @@ archprepare: maketools
 PHONY += maketools
 
 ifeq ($(CONFIG_SDL),y)
-SDL_LIBS := $(shell $(PKG_CONFIG) sdl2 --libs)
+SDL_LIBS := $(shell $(CROSS_PKG_CONFIG) sdl2 --libs)
 endif
 
 ifeq ($(CONFIG_GPIO_LIBFTDI1),y)
-FTDI1_LIBS := $(shell $(PKG_CONFIG) libftdi1 --libs)
+FTDI1_LIBS := $(shell $(CROSS_PKG_CONFIG) libftdi1 --libs)
 endif
 
 ifeq ($(CONFIG_ASAN),y)
diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile
index 7a76fb0290e8..c77702bb0c1d 100644
--- a/arch/sandbox/os/Makefile
+++ b/arch/sandbox/os/Makefile
@@ -23,8 +23,8 @@ endif
 obj-y = common.o tap.o setjmp.o
 obj-$(CONFIG_MALLOC_LIBC) += libc_malloc.o
 
-CFLAGS_sdl.o = $(shell $(PKG_CONFIG) sdl2 --cflags)
+CFLAGS_sdl.o = $(shell $(CROSS_PKG_CONFIG) sdl2 --cflags)
 obj-$(CONFIG_SDL) += sdl.o
 
-CFLAGS_ftdi.o = $(shell $(PKG_CONFIG) libftdi1 --cflags)
+CFLAGS_ftdi.o = $(shell $(CROSS_PKG_CONFIG) libftdi1 --cflags)
 obj-$(CONFIG_GPIO_LIBFTDI1) += ftdi.o
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 00:59:18 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 08:59:18 +0100
Subject: [PATCH 5/6] ci: pytest: run test suite on sandbox allyesconfig
In-Reply-To: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
References: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
Message-ID: <20250326075919.3448789-6-a.fatoum@pengutronix.de>

Building allyesconfig in CI allows us to catch early compile-time
breakage when changes are done treewide. Running pytest over it
will ensure that compile-tested drivers don't break normal startup
when unused.

Additionally, allyesconfig also enables ASAN/UBSAN, which is a nice side
effect. A future change would be adding KASAN for other architectures as
well.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 .github/workflows/test-labgrid-pytest.yml |  4 ++++
 test/sandbox/allyesconfig.yaml            | 17 +++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 test/sandbox/allyesconfig.yaml

diff --git a/.github/workflows/test-labgrid-pytest.yml b/.github/workflows/test-labgrid-pytest.yml
index 2a9f7a53aced..c43649e85fec 100644
--- a/.github/workflows/test-labgrid-pytest.yml
+++ b/.github/workflows/test-labgrid-pytest.yml
@@ -55,6 +55,10 @@ jobs:
             lgenv: 'test/sandbox/sandbox_defconfig.yaml'
             defconfig: sandbox_defconfig
 
+          - ARCH: sandbox
+            lgenv: 'test/sandbox/allyesconfig.yaml'
+            defconfig: sandbox_defconfig
+
     steps:
     - name: Checkout code
       uses: actions/checkout at v4
diff --git a/test/sandbox/allyesconfig.yaml b/test/sandbox/allyesconfig.yaml
new file mode 100644
index 000000000000..76b995127651
--- /dev/null
+++ b/test/sandbox/allyesconfig.yaml
@@ -0,0 +1,17 @@
+targets:
+  main:
+    drivers:
+      ExternalConsoleDriver:
+        cmd: !template "$LG_BUILDDIR/barebox"
+      ExternalPowerDriver:
+        cmd_on: 'true'
+        cmd_off: 'true'
+      BareboxDriver:
+        prompt: "barebox@[^:]+:[^ ]+ "
+      BareboxTestStrategy: {}
+    runner:
+      kconfig_add:
+        - CONFIG_CONSOLE_DISABLE_INPUT=n
+        - CONFIG_MALLOC_LIBC=y # for ASAN integration
+imports:
+  -  ../strategy.py
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 00:59:19 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 08:59:19 +0100
Subject: [PATCH 6/6] ci: run static analysis on allyesconfig
In-Reply-To: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
References: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
Message-ID: <20250326075919.3448789-7-a.fatoum@pengutronix.de>

Now that allyesconfig builds again for sandbox, let's switch the
coverity and CodeQL workflows to use it.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 .github/workflows/codeql.yml  | 2 +-
 .github/workflows/coverity.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index ca4b1f611d53..767c49c4beeb 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -37,7 +37,7 @@ jobs:
     - name: Build C Code
       shell: bash
       run: |
-        make ARCH=sandbox sandbox_defconfig
+        make ARCH=sandbox allyesconfig
         make -j$(nproc) ARCH=sandbox
 
     - name: Perform CodeQL Analysis
diff --git a/.github/workflows/coverity.sh b/.github/workflows/coverity.sh
index ee4a481503c7..eb6cbfe93fa7 100755
--- a/.github/workflows/coverity.sh
+++ b/.github/workflows/coverity.sh
@@ -35,7 +35,7 @@ function run_coverity {
 
     version="$(make bareboxversion)-g${GITHUB_SHA:0:10}"
 
-    make ARCH=sandbox sandbox_defconfig
+    make ARCH=sandbox allyesconfig
     COVERITY_UNSUPPORTED=1 "$tool_dir/bin/cov-build" --dir "$results_dir" sh -c "make -j$(nproc) ARCH=sandbox"
     "$tool_dir/bin/cov-import-scm" --dir "$results_dir" --scm git --log "$results_dir/scm_log.txt"
 
-- 
2.39.5



From jmaselbas at zdiv.net  Wed Mar 26 02:45:37 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Wed, 26 Mar 2025 10:45:37 +0100
Subject: [PATCH] fixup! tee: optee: implement RPMB support
In-Reply-To: <579eeb04-43ef-4665-99c8-dd9d19cdbb3b@pengutronix.de>
References: <20250312-rpmb-v1-7-0f213382a3f3@pengutronix.de>
 <20250325143650.29433-1-jmaselbas@zdiv.net>
 <579eeb04-43ef-4665-99c8-dd9d19cdbb3b@pengutronix.de>
Message-ID: <D8Q3O7QT2HAC.AQCADSVOMV2U@zdiv.net>

Hi Ahmad,

On Wed Mar 26, 2025 at 7:52 AM CET, Ahmad Fatoum wrote:
> Hello Jules,
>
> On 25.03.25 15:36, Jules Maselbas wrote:
>> Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
>> ---
>>  drivers/tee/optee/rpmb.c | 1 +
>>  1 file changed, 1 insertion(+)
>> 
>> diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c
>> index cdc8afc1a4..ca60f3cf3d 100644
>> --- a/drivers/tee/optee/rpmb.c
>> +++ b/drivers/tee/optee/rpmb.c
>> @@ -5,6 +5,7 @@
>>  
>>  #define pr_fmt(fmt)     "optee-rpmb: " fmt
>>  
>> +#include <common.h>
>
> Is this only for ARRAY_SIZE? Then I'd prefer we include <linux/kernel.h> or
Yes, this is for ARRAY_SIZE
> <linux/array_size.h>, because we generally want to cut down on use of
> <common.h>, if only to reduce compile time a bit.
okay

> Also, please send fixups without a reply-to for patches that are already applied.
> This makes it less likely to be missed IMO.
ack

> Cheers,
> Ahmad
>
>
>
>>  #include <mci.h>
>>  
>>  #include "optee_msg.h"



From jmaselbas at zdiv.net  Wed Mar 26 02:49:43 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Wed, 26 Mar 2025 10:49:43 +0100
Subject: [PATCH v2] fixup! tee: optee: implement RPMB support
Message-ID: <20250326094943.9586-1-jmaselbas@zdiv.net>

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 drivers/tee/optee/rpmb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c
index cdc8afc1a4..813c48efd8 100644
--- a/drivers/tee/optee/rpmb.c
+++ b/drivers/tee/optee/rpmb.c
@@ -5,6 +5,7 @@
 
 #define pr_fmt(fmt)     "optee-rpmb: " fmt
 
+#include <linux/array_size.h>
 #include <mci.h>
 
 #include "optee_msg.h"
-- 
2.48.1



From a.fatoum at pengutronix.de  Wed Mar 26 03:18:55 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 11:18:55 +0100
Subject: [PATCH v2] fixup! tee: optee: implement RPMB support
In-Reply-To: <20250326094943.9586-1-jmaselbas@zdiv.net>
References: <20250326094943.9586-1-jmaselbas@zdiv.net>
Message-ID: <e5e80354-638f-41e4-ad9c-0faf7320c712@pengutronix.de>

On 26.03.25 10:49, Jules Maselbas wrote:
> Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

Thanks,
Ahmad

> ---
>  drivers/tee/optee/rpmb.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c
> index cdc8afc1a4..813c48efd8 100644
> --- a/drivers/tee/optee/rpmb.c
> +++ b/drivers/tee/optee/rpmb.c
> @@ -5,6 +5,7 @@
>  
>  #define pr_fmt(fmt)     "optee-rpmb: " fmt
>  
> +#include <linux/array_size.h>
>  #include <mci.h>
>  
>  #include "optee_msg.h"


-- 
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-5555 |


From a.fatoum at pengutronix.de  Wed Mar 26 05:36:12 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 13:36:12 +0100
Subject: [PATCH 0/7] ci: container: include musl and LLVM
Message-ID: <20250326123619.282897-1-a.fatoum@pengutronix.de>

We have been using clang out-of-tree for libfuzzer and clang-analyzer.
As preparation for upstream these as well as CI jobs that make use of
them, add them LLVM to the container image.

While at it, add musl-tools as well, so we can start catching musl
breakage in CI before Yocto CI runs into it.

Ahmad Fatoum (7):
  Revert "ci: container: downgrade OpenRISC toolchain from 14.2.0 to
    13.1.0"
  ci: container: download and delete kvx.tgz in the same layer
  ci: container: don't leave labgrid checkout in /tmp
  ci: container: don't install recommended packages
  ci: container: run apt-get clean after installation
  ci: container: add musl-tools
  ci: container: install LLVM/clang

 test/Containerfile | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 05:36:16 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 13:36:16 +0100
Subject: [PATCH 4/7] ci: container: don't install recommended packages
In-Reply-To: <20250326123619.282897-1-a.fatoum@pengutronix.de>
References: <20250326123619.282897-1-a.fatoum@pengutronix.de>
Message-ID: <20250326123619.282897-5-a.fatoum@pengutronix.de>

Either we want a package and we reference it explicitly or we don't, in
which case we don't want it taking up space in the container.

This breaks SVG to png image conversion with imagemagick, because it
calls rsvg-convert. Import librsvg2-bin to provide it.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/Containerfile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/Containerfile b/test/Containerfile
index c4b2ba0ea583..73b0f1b70802 100644
--- a/test/Containerfile
+++ b/test/Containerfile
@@ -10,7 +10,7 @@ LABEL Description="This image is for building and testing barebox inside a conta
 ENV DEBIAN_FRONTEND=noninteractive
 
 # Update and install things from apt now
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
 	bison \
 	build-essential \
 	coreutils \
@@ -22,6 +22,7 @@ RUN apt-get update && apt-get install -y \
 	libgit2-dev \
 	libguestfs-tools \
 	liblz4-tool \
+	librsvg2-bin \
 	libseccomp-dev \
 	libssl-dev \
 	libtool \
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 05:36:17 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 13:36:17 +0100
Subject: [PATCH 5/7] ci: container: run apt-get clean after installation
In-Reply-To: <20250326123619.282897-1-a.fatoum@pengutronix.de>
References: <20250326123619.282897-1-a.fatoum@pengutronix.de>
Message-ID: <20250326123619.282897-6-a.fatoum@pengutronix.de>

For good measure, let's run an apt-get clean after having installed the
package to hopefully save some space.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/Containerfile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/test/Containerfile b/test/Containerfile
index 73b0f1b70802..02610196f0d9 100644
--- a/test/Containerfile
+++ b/test/Containerfile
@@ -53,6 +53,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
 	u-boot-tools \
 	yamllint \
 	yq \
+	&& apt-get clean \
 	&& rm -rf /var/lib/apt/lists/*
 
 ENV GCC_VERSION=14.2.0
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 05:36:13 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 13:36:13 +0100
Subject: [PATCH 1/7] Revert "ci: container: downgrade OpenRISC toolchain from 14.2.0 to 13.1.0"
In-Reply-To: <20250326123619.282897-1-a.fatoum@pengutronix.de>
References: <20250326123619.282897-1-a.fatoum@pengutronix.de>
Message-ID: <20250326123619.282897-2-a.fatoum@pengutronix.de>

This or1k issue turned out to be caused by the QEMU update[1] that came
with bumping the Debian release of the container image and not the
toolchain update.

We don't have the QEMU fix in the container yet, but we have a
workaround in commit b2a21df3b07b ("openrisc: dts: describe all 4 UARTs").

So let's revert the erroneous toolchain downgrade.

[1]: https://lore.kernel.org/all/20241203111513.402641-2-shorne at gmail.com/

Fixes: 6d4c6b01f4c4 ("ci: container: downgrade OpenRISC toolchain from 14.2.0 to 13.1.0")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/Containerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/Containerfile b/test/Containerfile
index 53a5443e48fe..94b3f618261c 100644
--- a/test/Containerfile
+++ b/test/Containerfile
@@ -61,7 +61,7 @@ RUN korg_crosstool_dl() { wget -nv -O - https://mirrors.edge.kernel.org/pub/tool
     korg_crosstool_dl x86_64 ${GCC_VERSION} arm-linux-gnueabi && \
     korg_crosstool_dl x86_64 ${GCC_VERSION} aarch64-linux     && \
     korg_crosstool_dl x86_64 ${GCC_VERSION} mips-linux        && \
-    korg_crosstool_dl x86_64 13.1.0         or1k-linux        && \
+    korg_crosstool_dl x86_64 ${GCC_VERSION} or1k-linux        && \
     korg_crosstool_dl x86_64 ${GCC_VERSION} powerpc-linux     && \
     korg_crosstool_dl x86_64 ${GCC_VERSION} riscv64-linux
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 05:36:18 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 13:36:18 +0100
Subject: [PATCH 6/7] ci: container: add musl-tools
In-Reply-To: <20250326123619.282897-1-a.fatoum@pengutronix.de>
References: <20250326123619.282897-1-a.fatoum@pengutronix.de>
Message-ID: <20250326123619.282897-7-a.fatoum@pengutronix.de>

The musl-tools package provides a musl-gcc wrapper that can be used to
compile applications statically against musl.

Add it to the BSP, so we can use it from CI in future.
This will enable us to:

  - catch breakage in especially host/target tools when compiled with
    musl as OpenEmbedded does in CI and Alpine/PostmarketOS does
    by default

  - distribute statically linked tools with releases.

Cc: Jules Maselbas <jmaselbas at zdiv.net>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/Containerfile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/test/Containerfile b/test/Containerfile
index 02610196f0d9..e9b044c87ab7 100644
--- a/test/Containerfile
+++ b/test/Containerfile
@@ -31,6 +31,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
 	lzma-alone \
 	lzop \
 	mount \
+	musl-tools \
 	openssl \
 	pkg-config \
 	util-linux \
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 05:36:15 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 13:36:15 +0100
Subject: [PATCH 3/7] ci: container: don't leave labgrid checkout in /tmp
In-Reply-To: <20250326123619.282897-1-a.fatoum@pengutronix.de>
References: <20250326123619.282897-1-a.fatoum@pengutronix.de>
Message-ID: <20250326123619.282897-4-a.fatoum@pengutronix.de>

The /tmp directory survives into the built container.
As pip can install directly from a remote git repository, let's use that
instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/Containerfile | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/test/Containerfile b/test/Containerfile
index 246f50d5b648..c4b2ba0ea583 100644
--- a/test/Containerfile
+++ b/test/Containerfile
@@ -77,11 +77,9 @@ RUN useradd -m -U barebox
 RUN echo barebox ALL=NOPASSWD: ALL > /etc/sudoers.d/barebox
 
 # install labgrid
-RUN cd /tmp && \
-    git clone --depth 1 -b v24.0 https://github.com/labgrid-project/labgrid && \
-    cd labgrid && \
-    pip3 install --break-system-packages . && \
-    ln -s $(which pytest) /usr/local/bin/labgrid-pytest;
+RUN pip3 install -q --no-cache-dir --break-system-packages \
+    git+https://github.com/labgrid-project/labgrid.git at v24.0 && \
+    ln -s $(which pytest) /usr/local/bin/labgrid-pytest
 
 ENV CROSS_COMPILE_arm=/opt/gcc-${GCC_VERSION}-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-
 ENV CROSS_COMPILE_arm64=/opt/gcc-${GCC_VERSION}-nolibc/aarch64-linux/bin/aarch64-linux-
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 05:36:14 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 13:36:14 +0100
Subject: [PATCH 2/7] ci: container: download and delete kvx.tgz in the same layer
In-Reply-To: <20250326123619.282897-1-a.fatoum@pengutronix.de>
References: <20250326123619.282897-1-a.fatoum@pengutronix.de>
Message-ID: <20250326123619.282897-3-a.fatoum@pengutronix.de>

The results of each RUN instruction are saved to layer in the resulting
container. Having a separate RUN instruction to delete temporary files
thus only hides them at runtime, but the files are still there eating
up space.

The common wisdom is thus to combine creation, usage and deletion of
temporary files into a single RUN instruction.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/Containerfile | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/test/Containerfile b/test/Containerfile
index 94b3f618261c..246f50d5b648 100644
--- a/test/Containerfile
+++ b/test/Containerfile
@@ -65,12 +65,10 @@ RUN korg_crosstool_dl() { wget -nv -O - https://mirrors.edge.kernel.org/pub/tool
     korg_crosstool_dl x86_64 ${GCC_VERSION} powerpc-linux     && \
     korg_crosstool_dl x86_64 ${GCC_VERSION} riscv64-linux
 
-RUN wget -nv -O kvx.tgz https://github.com/kalray/build-scripts/releases/download/v5.0.0/gcc-kalray-kvx-ubuntu-22.04-v5.0.0.tar.gz
-
-RUN echo "d27b3d6e6246f5debffee0bb01e77eb133bd32c658782a68a779cf9fb4c436bc kvx.tgz" | \
-    sha256sum --check --status
-
-RUN tar -C /opt -xzf kvx.tgz && rm kvx.tgz
+RUN tgz_checksum_dl() { set -e; wget -nv -O archive.tgz "$1"; \
+                        echo "$2 archive.tgz" | sha256sum --check --status; tar -C /opt -xzf archive.tgz; rm archive.tgz; } && \
+    tgz_checksum_dl https://github.com/kalray/build-scripts/releases/download/v5.0.0/gcc-kalray-kvx-ubuntu-22.04-v5.0.0.tar.gz \
+                    d27b3d6e6246f5debffee0bb01e77eb133bd32c658782a68a779cf9fb4c436bc
 
 RUN wget -nv "https://github.com/qemu/qemu/blob/v5.2.0/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin?raw=true" -O /usr/share/qemu/opensbi-riscv32-generic-fw_dynamic.bin
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 05:36:19 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 13:36:19 +0100
Subject: [PATCH 7/7] ci: container: install LLVM/clang
In-Reply-To: <20250326123619.282897-1-a.fatoum@pengutronix.de>
References: <20250326123619.282897-1-a.fatoum@pengutronix.de>
Message-ID: <20250326123619.282897-8-a.fatoum@pengutronix.de>

This will be used later for clang-analyzer and libfuzzer.
We intentionally use the LLVM project apt repositories for greater
flexibility in the versions we want to use, e.g. LLVM 20 is not yet
available on Debian Bookworm.

kernel.org also hosts more barebones LLVM toolchains, but we are
interested in more than that.

The LLVM layer added to the container sits at 1.04GiB, which is about
200MiB less than what we are using for the GCC toolchains.
It contains support for cross-compiling 47 different targets.

Cc: Jules Maselbas <jmaselbas at zdiv.net>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/Containerfile | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/test/Containerfile b/test/Containerfile
index e9b044c87ab7..20402c384b6f 100644
--- a/test/Containerfile
+++ b/test/Containerfile
@@ -58,6 +58,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
 	&& rm -rf /var/lib/apt/lists/*
 
 ENV GCC_VERSION=14.2.0
+ENV LLVM_VERSION=20
+
+RUN apt-get update && apt-get install -y --no-install-recommends \
+	lsb-release software-properties-common gnupg \
+	&& wget https://apt.llvm.org/llvm.sh \
+	&& chmod +x llvm.sh && ./llvm.sh ${LLVM_VERSION} \
+	&& apt-get remove -y lsb-release software-properties-common gnupg \
+	&& apt-get autoremove -y --purge \
+	&& apt-get clean \
+	&& rm -rf llvm.sh /var/lib/apt/lists/*
 
 # Manually install the kernel.org Crosstool based toolchains
 RUN korg_crosstool_dl() { wget -nv -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/${1}/${2}/${1}-gcc-${2}-nolibc-${3}.tar.xz | tar -C /opt -xJ ; } && \
@@ -92,4 +102,9 @@ ENV CROSS_COMPILE_powerpc=/opt/gcc-${GCC_VERSION}-nolibc/powerpc-linux/bin/power
 ENV CROSS_COMPILE_riscv=/opt/gcc-${GCC_VERSION}-nolibc/riscv64-linux/bin/riscv64-linux-
 ENV CROSS_COMPILE_kvx=/opt/gcc-kalray-kvx-v5.0.0/bin/kvx-elf-
 
+ENV CROSS_COMPILE_llvm=-${LLVM_VERSION}
+# Workaround for https://github.com/llvm/llvm-project/issues/112458
+RUN ln -Ts /usr/lib/llvm-${LLVM_VERSION}/lib/clang/${LLVM_VERSION}/lib/linux/ \
+           /usr/lib/llvm-${LLVM_VERSION}/lib/clang/${LLVM_VERSION}/lib/x86_64-pc-linux-gnu
+
 USER barebox:barebox
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 09:59:49 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 17:59:49 +0100
Subject: [PATCH master] fs: smhfs: fix crash when stat'ing file
Message-ID: <20250326165949.669187-1-a.fatoum@pengutronix.de>

Starting with commit 7d91d564361e ("fs: replace FILE.size by f_inode.i_size"),
struct file no longer had a size member, but instead the inode's i_size
member is used. The inode is populated by the file system core when a
file is first opened.

However, the semihosting file system creates a fake struct file to pass
to smhfs_open, which duly fails, because the inode member is
uninitialized.

Fix this for now, by faking an allocated inode as well.

The better fix would be switching to a non-legacy file system, but
that (remain)s a quest for another day.

Fixes: 7d91d564361e ("fs: replace FILE.size by f_inode.i_size")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 fs/smhfs.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/smhfs.c b/fs/smhfs.c
index e0e98f5213e9..3a3b4bdc1d94 100644
--- a/fs/smhfs.c
+++ b/fs/smhfs.c
@@ -114,12 +114,16 @@ static int smhfs_stat(struct device __always_unused *dev,
 {
 	struct file file;
 
+	file.f_inode = xzalloc(sizeof(*file.f_inode));
+
 	if (smhfs_open(NULL, &file, filename) == 0) {
 		s->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
 		s->st_size = file.f_size;
 	}
 	smhfs_close(NULL, &file);
 
+	free(file.f_inode);
+
 	return 0;
 }
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 10:00:08 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 18:00:08 +0100
Subject: [PATCH 1/3] fs: squashfs: drop unused struct squashfs_dir definition
Message-ID: <20250326170010.670379-1-a.fatoum@pengutronix.de>

The definition is at the end of the file too late to be used and indeed
it's used nowhere, so drop it.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 fs/squashfs/squashfs.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/fs/squashfs/squashfs.c b/fs/squashfs/squashfs.c
index 5441271e45f1..7ae8c1296b87 100644
--- a/fs/squashfs/squashfs.c
+++ b/fs/squashfs/squashfs.c
@@ -243,17 +243,6 @@ static int squashfs_read(struct device *_dev, struct file *f, void *buf,
 	return insize;
 }
 
-struct squashfs_dir {
-	struct file file;
-	struct dentry dentry;
-	struct dentry root_dentry;
-	struct inode inode;
-	struct qstr nm;
-	DIR dir;
-	char d_name[256];
-	char root_d_name[256];
-};
-
 static struct fs_driver squashfs_driver = {
 	.read		= squashfs_read,
 	.type		= filetype_squashfs,
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 10:00:10 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 18:00:10 +0100
Subject: [PATCH 3/3] driver: drop unused dev_open/close_default stubs
In-Reply-To: <20250326170010.670379-1-a.fatoum@pengutronix.de>
References: <20250326170010.670379-1-a.fatoum@pengutronix.de>
Message-ID: <20250326170010.670379-3-a.fatoum@pengutronix.de>

These function have been unused since 2009, so drop them already.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/driver.h | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/include/driver.h b/include/driver.h
index 59ce1d5cc9b7..76b167166954 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -21,7 +21,6 @@
 
 #include <param.h>
 
-struct file;
 struct bus_type;
 struct generic_pm_domain;
 
@@ -353,16 +352,6 @@ ssize_t mem_copy(struct device *dev, void *dst, const void *src,
 int generic_memmap_ro(struct cdev *dev, void **map, int flags);
 int generic_memmap_rw(struct cdev *dev, void **map, int flags);
 
-static inline int dev_open_default(struct device *dev, struct file *f)
-{
-	return 0;
-}
-
-static inline int dev_close_default(struct device *dev, struct file *f)
-{
-	return 0;
-}
-
 struct bus_type {
 	char *name;
 	int (*match)(struct device *dev, struct driver *drv);
-- 
2.39.5



From a.fatoum at pengutronix.de  Wed Mar 26 10:00:09 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 26 Mar 2025 18:00:09 +0100
Subject: [PATCH 2/3] common: elf: drop unused arch notes stubs
In-Reply-To: <20250326170010.670379-1-a.fatoum@pengutronix.de>
References: <20250326170010.670379-1-a.fatoum@pengutronix.de>
Message-ID: <20250326170010.670379-2-a.fatoum@pengutronix.de>

These definitions are used nowhere, so drop them.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/powerpc/include/asm/elf.h | 7 -------
 include/elf.h                  | 8 --------
 2 files changed, 15 deletions(-)

diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
index bb8762b385b8..2c938adacce5 100644
--- a/arch/powerpc/include/asm/elf.h
+++ b/arch/powerpc/include/asm/elf.h
@@ -400,13 +400,6 @@ do {									\
 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
 #define NT_SPU		1
 
-extern int arch_notes_size(void);
-extern void arch_write_notes(struct file *file);
-
-#define ELF_CORE_EXTRA_NOTES_SIZE arch_notes_size()
-#define ELF_CORE_WRITE_EXTRA_NOTES arch_write_notes(file)
-
-#define ARCH_HAVE_EXTRA_ELF_NOTES
 #endif /* CONFIG_PPC_CELL */
 
 #endif /* _ASM_POWERPC_ELF_H */
diff --git a/include/elf.h b/include/elf.h
index 8805eb4a2fc9..994db642b078 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -391,14 +391,6 @@ extern Elf64_Dyn _DYNAMIC [];
 
 #endif
 
-#ifndef ARCH_HAVE_EXTRA_ELF_NOTES
-static inline int arch_notes_size(void) { return 0; }
-static inline void arch_write_notes(struct file *file) { }
-
-#define ELF_CORE_EXTRA_NOTES_SIZE arch_notes_size()
-#define ELF_CORE_WRITE_EXTRA_NOTES arch_write_notes(file)
-#endif /* ARCH_HAVE_EXTRA_ELF_NOTES */
-
 struct elf_image {
 	struct list_head list;
 	u8 class;
-- 
2.39.5



From eagle.alexander923 at gmail.com  Wed Mar 26 22:38:00 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Thu, 27 Mar 2025 08:38:00 +0300
Subject: [PATCH] mci: atmel_mci: Merge at91_mci_bio_set_highcapacity() with at91_mci_bio_init()
Message-ID: <20250327053801.52356-1-eagle.alexander923@gmail.com>

The high-capacity parameter is always set to one of the possible values
at initialization, so there is no need to have a separate function to
configure it.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 arch/arm/mach-at91/at91sam9_xload_mmc.c |  5 +----
 arch/arm/mach-at91/xload.c              |  2 +-
 drivers/mci/atmel_mci_pbl.c             | 10 +++-------
 include/mach/at91/xload.h               |  4 ++--
 4 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/arch/arm/mach-at91/at91sam9_xload_mmc.c b/arch/arm/mach-at91/at91sam9_xload_mmc.c
index 26f268ae91..e8cd72bd56 100644
--- a/arch/arm/mach-at91/at91sam9_xload_mmc.c
+++ b/arch/arm/mach-at91/at91sam9_xload_mmc.c
@@ -94,15 +94,12 @@ void __noreturn sam9263_atmci_start_image(u32 mmc_id, unsigned int clock,
 		at91_pmc_enable_periph_clock(IOMEM(AT91SAM926X_BASE_PMC),  AT91SAM9263_ID_MCI1);
 	}
 
-	ret = at91_mci_bio_init(&bio, base, clock, (int)slot_b);
+	ret = at91_mci_bio_init(&bio, base, clock, (int)slot_b, false);
 	if (ret) {
 		pr_err("atmci_start_image: bio init faild: %d\n", ret);
 		goto out_panic;
 	}
 
-	/* at91sam9x do not support high capacity */
-	at91_mci_bio_set_highcapacity(false);
-
 	ret = pbl_fat_load(&bio, "barebox.bin", buf, SZ_16M);
 	if (ret < 0) {
 		pr_err("pbl_fat_load: error %d\n", ret);
diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 5d8105f07f..effe8802ee 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -228,7 +228,7 @@ void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
 
 	sama5d3_pmc_enable_periph_clock(instance->id);
 
-	ret = at91_mci_bio_init(&bio, instance->base, clock, slot);
+	ret = at91_mci_bio_init(&bio, instance->base, clock, slot, true);
 	if (ret)
 		goto out_panic;
 
diff --git a/drivers/mci/atmel_mci_pbl.c b/drivers/mci/atmel_mci_pbl.c
index bd4faa4de5..c94a4240db 100644
--- a/drivers/mci/atmel_mci_pbl.c
+++ b/drivers/mci/atmel_mci_pbl.c
@@ -83,7 +83,8 @@ static int at91_mci_bio_read(struct pbl_bio *bio, off_t start,
 }
 
 int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
-		      unsigned int clock, unsigned int slot)
+		      unsigned int clock, unsigned int slot,
+		      bool highcapacity_card)
 {
 	struct atmel_mci_priv *priv = &atmci_sdcard;
 	struct atmel_mci *host = &priv->host;
@@ -111,12 +112,7 @@ int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
 
 	atmci_common_set_ios(host, &ios);
 
-	priv->highcapacity_card = 1;
+	priv->highcapacity_card = highcapacity_card;
 
 	return 0;
 }
-
-void at91_mci_bio_set_highcapacity(bool highcapacity_card)
-{
-	atmci_sdcard.highcapacity_card = highcapacity_card;
-}
diff --git a/include/mach/at91/xload.h b/include/mach/at91/xload.h
index d5fc7596fd..329ccc98eb 100644
--- a/include/mach/at91/xload.h
+++ b/include/mach/at91/xload.h
@@ -12,8 +12,8 @@ void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
 
 int at91_sdhci_bio_init(struct pbl_bio *bio, void __iomem *base);
 int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
-		      unsigned int clock, unsigned int slot);
-void at91_mci_bio_set_highcapacity(bool highcapacity_card);
+		      unsigned int clock, unsigned int slot,
+		      bool highcapacity_card);
 
 void __noreturn sam9263_atmci_start_image(u32 mmc_id, unsigned int clock,
 					  bool slot_b);
-- 
2.39.1



From eagle.alexander923 at gmail.com  Wed Mar 26 22:38:01 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Thu, 27 Mar 2025 08:38:01 +0300
Subject: [PATCH] reset: Fix name of exported symbol
In-Reply-To: <20250327053801.52356-1-eagle.alexander923@gmail.com>
References: <20250327053801.52356-1-eagle.alexander923@gmail.com>
Message-ID: <20250327053801.52356-2-eagle.alexander923@gmail.com>

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 drivers/reset/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 2431a9374a..3571fe8aae 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -392,7 +392,7 @@ struct reset_control *__reset_control_get(struct device *dev, const char *id, bo
 
 	return ERR_CAST(rstc);
 }
-EXPORT_SYMBOL_GPL(reset_control_get);
+EXPORT_SYMBOL_GPL(__reset_control_get);
 
 /**
  * reset_control_put - free the reset controller
-- 
2.39.1



From a.fatoum at pengutronix.de  Wed Mar 26 23:41:42 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 07:41:42 +0100
Subject: [PATCH] mci: atmel_mci: Merge at91_mci_bio_set_highcapacity()
 with at91_mci_bio_init()
In-Reply-To: <20250327053801.52356-1-eagle.alexander923@gmail.com>
References: <20250327053801.52356-1-eagle.alexander923@gmail.com>
Message-ID: <03e0271b-8912-4c26-86d8-064236350268@pengutronix.de>

Hello Alexander,

On 27.03.25 06:38, Alexander Shiyan wrote:
> The high-capacity parameter is always set to one of the possible values
> at initialization, so there is no need to have a separate function to
> configure it.

here's an idea from IRC by the way to get rid of the parameter:

ye, that [checking CSD] is what is used normally, but the problem is doing it
while in transmission state.

  I looked into Part1_Physical_Layer_Simplified_Specification_Ver9.00.pdf
  again and for the first time I see
  "Figure 4-13 : SD Memory Card State Diagram (data transfer mode)"

  Apparently, you don't necessarily need CMD0 (Go idle) to be able to get to a
  state where you can execute CMD9 (SEND CSD), but one could also execute CMD7
  (SELECT CARD) to deselect card and then run CMD9 and get back to transmission mode

  One would need to issue a CMD3 (SEND_RELATIVE_ADDR) to get the RCA to communicate
  with the correct SD (it's argument to CMD9), but this might work.

Perhaps you're interested in trying this out :D

Cheers,
Ahmad

> 
> Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
> ---
>  arch/arm/mach-at91/at91sam9_xload_mmc.c |  5 +----
>  arch/arm/mach-at91/xload.c              |  2 +-
>  drivers/mci/atmel_mci_pbl.c             | 10 +++-------
>  include/mach/at91/xload.h               |  4 ++--
>  4 files changed, 7 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/arm/mach-at91/at91sam9_xload_mmc.c b/arch/arm/mach-at91/at91sam9_xload_mmc.c
> index 26f268ae91..e8cd72bd56 100644
> --- a/arch/arm/mach-at91/at91sam9_xload_mmc.c
> +++ b/arch/arm/mach-at91/at91sam9_xload_mmc.c
> @@ -94,15 +94,12 @@ void __noreturn sam9263_atmci_start_image(u32 mmc_id, unsigned int clock,
>  		at91_pmc_enable_periph_clock(IOMEM(AT91SAM926X_BASE_PMC),  AT91SAM9263_ID_MCI1);
>  	}
>  
> -	ret = at91_mci_bio_init(&bio, base, clock, (int)slot_b);
> +	ret = at91_mci_bio_init(&bio, base, clock, (int)slot_b, false);
>  	if (ret) {
>  		pr_err("atmci_start_image: bio init faild: %d\n", ret);
>  		goto out_panic;
>  	}
>  
> -	/* at91sam9x do not support high capacity */
> -	at91_mci_bio_set_highcapacity(false);
> -
>  	ret = pbl_fat_load(&bio, "barebox.bin", buf, SZ_16M);
>  	if (ret < 0) {
>  		pr_err("pbl_fat_load: error %d\n", ret);
> diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
> index 5d8105f07f..effe8802ee 100644
> --- a/arch/arm/mach-at91/xload.c
> +++ b/arch/arm/mach-at91/xload.c
> @@ -228,7 +228,7 @@ void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
>  
>  	sama5d3_pmc_enable_periph_clock(instance->id);
>  
> -	ret = at91_mci_bio_init(&bio, instance->base, clock, slot);
> +	ret = at91_mci_bio_init(&bio, instance->base, clock, slot, true);
>  	if (ret)
>  		goto out_panic;
>  
> diff --git a/drivers/mci/atmel_mci_pbl.c b/drivers/mci/atmel_mci_pbl.c
> index bd4faa4de5..c94a4240db 100644
> --- a/drivers/mci/atmel_mci_pbl.c
> +++ b/drivers/mci/atmel_mci_pbl.c
> @@ -83,7 +83,8 @@ static int at91_mci_bio_read(struct pbl_bio *bio, off_t start,
>  }
>  
>  int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
> -		      unsigned int clock, unsigned int slot)
> +		      unsigned int clock, unsigned int slot,
> +		      bool highcapacity_card)
>  {
>  	struct atmel_mci_priv *priv = &atmci_sdcard;
>  	struct atmel_mci *host = &priv->host;
> @@ -111,12 +112,7 @@ int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
>  
>  	atmci_common_set_ios(host, &ios);
>  
> -	priv->highcapacity_card = 1;
> +	priv->highcapacity_card = highcapacity_card;
>  
>  	return 0;
>  }
> -
> -void at91_mci_bio_set_highcapacity(bool highcapacity_card)
> -{
> -	atmci_sdcard.highcapacity_card = highcapacity_card;
> -}
> diff --git a/include/mach/at91/xload.h b/include/mach/at91/xload.h
> index d5fc7596fd..329ccc98eb 100644
> --- a/include/mach/at91/xload.h
> +++ b/include/mach/at91/xload.h
> @@ -12,8 +12,8 @@ void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
>  
>  int at91_sdhci_bio_init(struct pbl_bio *bio, void __iomem *base);
>  int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
> -		      unsigned int clock, unsigned int slot);
> -void at91_mci_bio_set_highcapacity(bool highcapacity_card);
> +		      unsigned int clock, unsigned int slot,
> +		      bool highcapacity_card);
>  
>  void __noreturn sam9263_atmci_start_image(u32 mmc_id, unsigned int clock,
>  					  bool slot_b);


-- 
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-5555 |


From s.hauer at pengutronix.de  Thu Mar 27 00:26:03 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 08:26:03 +0100
Subject: [PATCH v2] fixup! tee: optee: implement RPMB support
In-Reply-To: <20250326094943.9586-1-jmaselbas@zdiv.net>
References: <20250326094943.9586-1-jmaselbas@zdiv.net>
Message-ID: <174306036316.796053.6527779182975818765.b4-ty@pengutronix.de>


On Wed, 26 Mar 2025 10:49:43 +0100, Jules Maselbas wrote:
> 


Applied, thanks!

[1/1] fixup! tee: optee: implement RPMB support
      https://git.pengutronix.de/cgit/barebox/commit/?id=a902a2258647 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 27 00:37:08 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 08:37:08 +0100
Subject: [PATCH master] fs: smhfs: fix crash when stat'ing file
In-Reply-To: <20250326165949.669187-1-a.fatoum@pengutronix.de>
References: <20250326165949.669187-1-a.fatoum@pengutronix.de>
Message-ID: <174306102815.798497.17801663221164934626.b4-ty@pengutronix.de>


On Wed, 26 Mar 2025 17:59:49 +0100, Ahmad Fatoum wrote:
> Starting with commit 7d91d564361e ("fs: replace FILE.size by f_inode.i_size"),
> struct file no longer had a size member, but instead the inode's i_size
> member is used. The inode is populated by the file system core when a
> file is first opened.
> 
> However, the semihosting file system creates a fake struct file to pass
> to smhfs_open, which duly fails, because the inode member is
> uninitialized.
> 
> [...]

Applied, thanks!

[1/1] fs: smhfs: fix crash when stat'ing file
      https://git.pengutronix.de/cgit/barebox/commit/?id=3c57263db03b (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 27 00:38:59 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 08:38:59 +0100
Subject: [PATCH 1/2] vsprintf: fix missing break when printing %pJP
In-Reply-To: <20250325155327.31981-1-jmaselbas@zdiv.net>
References: <20250325155327.31981-1-jmaselbas@zdiv.net>
Message-ID: <174306113933.798650.17246505145151646265.b4-ty@pengutronix.de>


On Tue, 25 Mar 2025 16:53:26 +0100, Jules Maselbas wrote:
> When the format `%pJP` was introduced the new switch case didn't had a
> break at the end, it was last case in the switch. However subsequent
> commit didn't add a break either, creating a potential fallthrough.
> Add the missing break.
> 
> 

Applied, thanks!

[1/2] vsprintf: fix missing break when printing %pJP
      https://git.pengutronix.de/cgit/barebox/commit/?id=fe9805bfe283 (link may not be stable)
[2/2] vsprintf: add explicit fallthrough
      https://git.pengutronix.de/cgit/barebox/commit/?id=b2be41d98bbe (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 27 00:41:29 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 08:41:29 +0100
Subject: [PATCH] treewide: add explicit fallthrough and break
In-Reply-To: <20250325155258.31869-1-jmaselbas@zdiv.net>
References: <20250325155258.31869-1-jmaselbas@zdiv.net>
Message-ID: <174306128923.798860.14713686011962678386.b4-ty@pengutronix.de>


On Tue, 25 Mar 2025 16:52:58 +0100, Jules Maselbas wrote:
> Replace existing fallthrough comments with the `fallthrough;` pseudo-keyword.
> Add a few break statement when the last case of a switch is not empty, so it
> will not be forgot when a new case is added at the end.
> 
> 

Applied, thanks!

[1/1] treewide: add explicit fallthrough and break
      https://git.pengutronix.de/cgit/barebox/commit/?id=b1eeb46d1d6a (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 27 00:41:50 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 08:41:50 +0100
Subject: [PATCH] lib: add explicit fallthrough in strtoull_suffix
In-Reply-To: <20250325155413.32169-1-jmaselbas@zdiv.net>
References: <20250325155413.32169-1-jmaselbas@zdiv.net>
Message-ID: <174306131094.798988.15979987379835004033.b4-ty@pengutronix.de>


On Tue, 25 Mar 2025 16:54:13 +0100, Jules Maselbas wrote:
> 


Applied, thanks!

[1/1] lib: add explicit fallthrough in strtoull_suffix
      https://git.pengutronix.de/cgit/barebox/commit/?id=695626e7f267 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 27 00:43:21 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 08:43:21 +0100
Subject: [PATCH] mtd: spi-nor: add explicit fallthrough
In-Reply-To: <20250325155539.32501-1-jmaselbas@zdiv.net>
References: <20250325155539.32501-1-jmaselbas@zdiv.net>
Message-ID: <174306140136.799164.3064845755425951264.b4-ty@pengutronix.de>


On Tue, 25 Mar 2025 16:55:39 +0100, Jules Maselbas wrote:
> Add the fallthrough pseudo keyword: the case sets `need_wren = true;`
> which is used (only read and never written) in the case below.
> 
> 

Applied, thanks!

[1/1] mtd: spi-nor: add explicit fallthrough
      https://git.pengutronix.de/cgit/barebox/commit/?id=323be0d02510 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 27 00:43:53 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 08:43:53 +0100
Subject: [PATCH] lib: add explicit break in kstrtox/strtox
In-Reply-To: <20250325155614.32678-1-jmaselbas@zdiv.net>
References: <20250325155614.32678-1-jmaselbas@zdiv.net>
Message-ID: <174306143339.799296.3688953420820075475.b4-ty@pengutronix.de>


On Tue, 25 Mar 2025 16:56:14 +0100, Jules Maselbas wrote:
> 


Applied, thanks!

[1/1] lib: add explicit break in kstrtox/strtox
      https://git.pengutronix.de/cgit/barebox/commit/?id=9dff02309045 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From a.fatoum at pengutronix.de  Thu Mar 27 00:48:14 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 08:48:14 +0100
Subject: [PATCH] fixup! complete: give device_param_complete a flags parameter
Message-ID: <20250327074814.3714019-1-a.fatoum@pengutronix.de>

When completing an existing variable, we want a trailing assignment, so
the use can just start typing the value.

This was the behavior before the commit being fixed up broke it.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/complete.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/complete.c b/common/complete.c
index 6cb674a0cc9c..5327944ca93b 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -469,7 +469,7 @@ int complete(char *instr, char **outstr)
 		} else {
 			command_complete(&sl, instr);
 			path_command_complete(&sl, instr);
-			env_param_complete(&sl, instr, 0);
+			env_param_complete(&sl, instr, DEVPARAM_COMPLETE_ASSIGNMENT);
 		}
 		if (*instr == '$')
 			env_param_complete(&sl, instr + 1, DEVPARAM_COMPLETE_DOLLAR);
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 27 00:50:36 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 08:50:36 +0100
Subject: [PATCH] common: pe: fix pe reloc pointer overrun
Message-ID: <20250327075036.3719261-1-a.fatoum@pengutronix.de>

Import the fix from U-Boot commit 463e4e6476299b32452a8a:

| Author:     Aleksandar Gerasimovski <Aleksandar.Gerasimovski at belden.com>
| AuthorDate: Fri Nov 29 21:09:44 2024 +0000
|
| efi_loader: fix pe reloc pointer overrun
|
| The fix provided by 997fc12ec91 is actually introducing
| a buffer overrun, and the overrun is effective if the
| memory after the reloc section is not zeroed.
| Probably that's why this bug is not always noticeable.
|
| The problem is that 8-bytes 'rel' pointer can be 4-bytes aligned
| according to the PE Format, so the actual relocate function can
| take values after the reloc section.
|
| One example is the following dump from the reloc section:
|
|     bce26000: 3000 0000 000c 0000 0000 0000 0000 0000
|     bce26010: 7c00 9340 67e0 f900 1c00 0ea1 a400 0f20
|
| This section has two relocations at offset bce26008 and bce2600a,
| however the given size (rel_size) for this relocation is 16-bytes
| and this is coming form the efi image Misc.VirtualSize, so in this
| case the 'reloc' pointer ends at affset bce2600c and is taken as
| valid and this is where the overflow is.
|
| In our system we see this problem when we are starting the
| Boot Guard efi image.
|
| This patch is fixing the overrun while preserving the fix done
| by 997fc12ec91.
| Signed-off-by: Aleksandar Gerasimovski <aleksandar.gerasimovski at belden.com>
| Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/pe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/pe.c b/common/pe.c
index 6164dd68b7ab..65d456a2c332 100644
--- a/common/pe.c
+++ b/common/pe.c
@@ -61,7 +61,7 @@ static int pe_loader_relocate(const IMAGE_BASE_RELOCATION *rel,
 		return 0;
 
 	end = (const IMAGE_BASE_RELOCATION *)((const char *)rel + rel_size);
-	while (rel < end && rel->SizeOfBlock) {
+	while (rel + 1 < end && rel->SizeOfBlock) {
 		const uint16_t *relocs = (const uint16_t *)(rel + 1);
 		i = (rel->SizeOfBlock - sizeof(*rel)) / sizeof(uint16_t);
 		while (i--) {
-- 
2.39.5



From s.hauer at pengutronix.de  Thu Mar 27 00:56:36 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 08:56:36 +0100
Subject: [RFC PATCH] fbconsole: add missing break
In-Reply-To: <20250325160008.1076-1-jmaselbas@zdiv.net>
References: <20250325160008.1076-1-jmaselbas@zdiv.net>
Message-ID: <174306219673.807258.18174327720487776951.b4-ty@pengutronix.de>


On Tue, 25 Mar 2025 17:00:08 +0100, Jules Maselbas wrote:
> The cursor move CSI has nothing to do with the clear-screen CSI.
> The existing fallthrough looks like a bug, add the missing break.
> 
> 

Applied, thanks!

[1/1] fbconsole: add missing break
      https://git.pengutronix.de/cgit/barebox/commit/?id=5b2e47b1ff4c (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 27 01:12:51 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 09:12:51 +0100
Subject: [RFC PATCH] fbconsole: add missing break
In-Reply-To: <20250325160008.1076-1-jmaselbas@zdiv.net>
References: <20250325160008.1076-1-jmaselbas@zdiv.net>
Message-ID: <Z-UIgzNKC7RWo88j@pengutronix.de>

On Tue, Mar 25, 2025 at 05:00:08PM +0100, Jules Maselbas wrote:
> The cursor move CSI has nothing to do with the clear-screen CSI.

CSI n K is erase to beginning or end of line.

> The existing fallthrough looks like a bug, add the missing break.
> 
> Fixes: 27f79c05ab ("video: implement framebuffer console")
> Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
> ---
> 
>  I am not 100% sure if this is a bug or not, it feels like it sould not
>  fallthrough, an extra look would be nice.

Yes, really looks like a bug. Moving the cursor shouldn't erase
anything.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Thu Mar 27 01:13:51 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 09:13:51 +0100
Subject: [PATCH master 0/3] sandbox: enable building under musl
In-Reply-To: <20250325124740.4035964-1-a.fatoum@pengutronix.de>
References: <20250325124740.4035964-1-a.fatoum@pengutronix.de>
Message-ID: <174306323109.810869.3518539069422342683.b4-ty@pengutronix.de>


On Tue, 25 Mar 2025 13:47:37 +0100, Ahmad Fatoum wrote:
> Building sandbox itself as opposed to the target/host tools still fails
> with musl, due to some headers not being available.
> 
> This is fixed by this series.
> 
> Ahmad Fatoum (3):
>   sandbox: use POSIX header instead of Linux one
>   sandbox: don't build tap support code without CONFIG_DRIVER_NET_TAP
>   sandbox: os: tap: make it compile with musl
> 
> [...]

Applied, thanks!

[1/3] sandbox: use POSIX header instead of Linux one
      https://git.pengutronix.de/cgit/barebox/commit/?id=1426b121630e (link may not be stable)
[2/3] sandbox: don't build tap support code without CONFIG_DRIVER_NET_TAP
      https://git.pengutronix.de/cgit/barebox/commit/?id=97fcb63d9d67 (link may not be stable)
[3/3] sandbox: os: tap: make it compile with musl
      https://git.pengutronix.de/cgit/barebox/commit/?id=d9e696e5a5dd (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From a.fatoum at pengutronix.de  Thu Mar 27 01:17:30 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 09:17:30 +0100
Subject: [RFC PATCH] fbconsole: add missing break
In-Reply-To: <20250325160008.1076-1-jmaselbas@zdiv.net>
References: <20250325160008.1076-1-jmaselbas@zdiv.net>
Message-ID: <25429354-d27c-40dc-8d14-dcc2fef8b74e@pengutronix.de>

On 25.03.25 17:00, Jules Maselbas wrote:
> The cursor move CSI has nothing to do with the clear-screen CSI.
> The existing fallthrough looks like a bug, add the missing break.
> 
> Fixes: 27f79c05ab ("video: implement framebuffer console")
> Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
> ---
> 
>  I am not 100% sure if this is a bug or not, it feels like it sould not
>  fallthrough, an extra look would be nice.

I think it makes sense to add the break.

case 'H' (\e[{line};{column}H) is move cursor and
case 'K' (ESC[{0,1,2}K} is erase.

The code currently interprets the same integer once as line
and another time as erase type for K, which is not lines,
but rather 0 = from cursor to end of line,
           1 = from start of line to cursor
           2 = whole line 

So this patch looks correct IMO.

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

> 
> 
>  drivers/video/fbconsole.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> index 24592d00ed..7462e34778 100644
> --- a/drivers/video/fbconsole.c
> +++ b/drivers/video/fbconsole.c
> @@ -576,6 +576,7 @@ static void fbc_parse_csi(struct fbc_priv *priv)
>  		priv->x = clamp(pos - 1, 0, (int) priv->cols - 1);
>  
>  		show_cursor(priv, priv->x, priv->y);
> +		break;
>  	case 'K':
>  		pos = simple_strtoul(priv->csi, &end, 10);
>  		video_invertchar(priv, priv->x, priv->y);


-- 
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-5555 |


From s.hauer at pengutronix.de  Thu Mar 27 02:11:27 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 10:11:27 +0100
Subject: [PATCH] fixup! complete: give device_param_complete a flags
 parameter
In-Reply-To: <20250327074814.3714019-1-a.fatoum@pengutronix.de>
References: <20250327074814.3714019-1-a.fatoum@pengutronix.de>
Message-ID: <Z-UWP0f_W_AhKWRG@pengutronix.de>

On Thu, Mar 27, 2025 at 08:48:14AM +0100, Ahmad Fatoum wrote:
> When completing an existing variable, we want a trailing assignment, so
> the use can just start typing the value.
> 
> This was the behavior before the commit being fixed up broke it.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  common/complete.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/common/complete.c b/common/complete.c
> index 6cb674a0cc9c..5327944ca93b 100644
> --- a/common/complete.c
> +++ b/common/complete.c
> @@ -469,7 +469,7 @@ int complete(char *instr, char **outstr)
>  		} else {
>  			command_complete(&sl, instr);
>  			path_command_complete(&sl, instr);
> -			env_param_complete(&sl, instr, 0);
> +			env_param_complete(&sl, instr, DEVPARAM_COMPLETE_ASSIGNMENT);
>  		}
>  		if (*instr == '$')
>  			env_param_complete(&sl, instr + 1, DEVPARAM_COMPLETE_DOLLAR);
> -- 
> 2.39.5
> 
> 
> 

-- 
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-5555 |


From s.hauer at pengutronix.de  Thu Mar 27 02:13:16 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 10:13:16 +0100
Subject: [PATCH] common: pe: fix pe reloc pointer overrun
In-Reply-To: <20250327075036.3719261-1-a.fatoum@pengutronix.de>
References: <20250327075036.3719261-1-a.fatoum@pengutronix.de>
Message-ID: <174306679620.830034.5159790038260238960.b4-ty@pengutronix.de>


On Thu, 27 Mar 2025 08:50:36 +0100, Ahmad Fatoum wrote:
> Import the fix from U-Boot commit 463e4e6476299b32452a8a:
> 
> | Author:     Aleksandar Gerasimovski <Aleksandar.Gerasimovski at belden.com>
> | AuthorDate: Fri Nov 29 21:09:44 2024 +0000
> |
> | efi_loader: fix pe reloc pointer overrun
> |
> | The fix provided by 997fc12ec91 is actually introducing
> | a buffer overrun, and the overrun is effective if the
> | memory after the reloc section is not zeroed.
> | Probably that's why this bug is not always noticeable.
> |
> | The problem is that 8-bytes 'rel' pointer can be 4-bytes aligned
> | according to the PE Format, so the actual relocate function can
> | take values after the reloc section.
> |
> | One example is the following dump from the reloc section:
> |
> |     bce26000: 3000 0000 000c 0000 0000 0000 0000 0000
> |     bce26010: 7c00 9340 67e0 f900 1c00 0ea1 a400 0f20
> |
> | This section has two relocations at offset bce26008 and bce2600a,
> | however the given size (rel_size) for this relocation is 16-bytes
> | and this is coming form the efi image Misc.VirtualSize, so in this
> | case the 'reloc' pointer ends at affset bce2600c and is taken as
> | valid and this is where the overflow is.
> |
> | In our system we see this problem when we are starting the
> | Boot Guard efi image.
> |
> | This patch is fixing the overrun while preserving the fix done
> | by 997fc12ec91.
> | Signed-off-by: Aleksandar Gerasimovski <aleksandar.gerasimovski at belden.com>
> | Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> 
> [...]

Applied, thanks!

[1/1] common: pe: fix pe reloc pointer overrun
      https://git.pengutronix.de/cgit/barebox/commit/?id=d4b5f3d3d191 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 27 02:17:06 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 10:17:06 +0100
Subject: [PATCH v2] commands: hwclock: rework argument handling
In-Reply-To: <20250325115226.1692-1-jmaselbas@zdiv.net>
References: <20250314213344.12335-1-jmaselbas@zdiv.net>
 <20250325115226.1692-1-jmaselbas@zdiv.net>
Message-ID: <174306702676.912310.8567103403186302685.b4-ty@pengutronix.de>


On Tue, 25 Mar 2025 12:52:26 +0100, Jules Maselbas wrote:
> The rtc_name doesn't need to be an array, thus the argument doesn't
> have to be copied, we can simply use a pointer on optarg.
> Drop the array and the string copy.
> 
> 

Applied, thanks!

[1/1] commands: hwclock: rework argument handling
      https://git.pengutronix.de/cgit/barebox/commit/?id=7b40a21fb6fb (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 27 02:17:06 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 10:17:06 +0100
Subject: [PATCH 1/3] fs: squashfs: drop unused struct squashfs_dir
 definition
In-Reply-To: <20250326170010.670379-1-a.fatoum@pengutronix.de>
References: <20250326170010.670379-1-a.fatoum@pengutronix.de>
Message-ID: <174306702678.912310.16756791800065727032.b4-ty@pengutronix.de>


On Wed, 26 Mar 2025 18:00:08 +0100, Ahmad Fatoum wrote:
> The definition is at the end of the file too late to be used and indeed
> it's used nowhere, so drop it.
> 
> 

Applied, thanks!

[1/3] fs: squashfs: drop unused struct squashfs_dir definition
      https://git.pengutronix.de/cgit/barebox/commit/?id=7261a61d1c33 (link may not be stable)
[2/3] common: elf: drop unused arch notes stubs
      https://git.pengutronix.de/cgit/barebox/commit/?id=765b9fe03e3c (link may not be stable)
[3/3] driver: drop unused dev_open/close_default stubs
      https://git.pengutronix.de/cgit/barebox/commit/?id=b33f6518b4ee (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 27 02:21:06 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 10:21:06 +0100
Subject: [PATCH 0/7] ci: container: include musl and LLVM
In-Reply-To: <20250326123619.282897-1-a.fatoum@pengutronix.de>
References: <20250326123619.282897-1-a.fatoum@pengutronix.de>
Message-ID: <174306726658.993088.2542948432002146522.b4-ty@pengutronix.de>


On Wed, 26 Mar 2025 13:36:12 +0100, Ahmad Fatoum wrote:
> We have been using clang out-of-tree for libfuzzer and clang-analyzer.
> As preparation for upstream these as well as CI jobs that make use of
> them, add them LLVM to the container image.
> 
> While at it, add musl-tools as well, so we can start catching musl
> breakage in CI before Yocto CI runs into it.
> 
> [...]

Applied, thanks!

[1/7] Revert "ci: container: downgrade OpenRISC toolchain from 14.2.0 to 13.1.0"
      https://git.pengutronix.de/cgit/barebox/commit/?id=fc304e4f07c8 (link may not be stable)
[2/7] ci: container: download and delete kvx.tgz in the same layer
      https://git.pengutronix.de/cgit/barebox/commit/?id=69a3750c7b3c (link may not be stable)
[3/7] ci: container: don't leave labgrid checkout in /tmp
      https://git.pengutronix.de/cgit/barebox/commit/?id=864116e7642f (link may not be stable)
[4/7] ci: container: don't install recommended packages
      https://git.pengutronix.de/cgit/barebox/commit/?id=c037cd73fe99 (link may not be stable)
[5/7] ci: container: run apt-get clean after installation
      https://git.pengutronix.de/cgit/barebox/commit/?id=b99360e1c2e2 (link may not be stable)
[6/7] ci: container: add musl-tools
      https://git.pengutronix.de/cgit/barebox/commit/?id=d4122875856f (link may not be stable)
[7/7] ci: container: install LLVM/clang
      https://git.pengutronix.de/cgit/barebox/commit/?id=256014d2c998 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Thu Mar 27 02:24:21 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 10:24:21 +0100
Subject: [PATCH 0/6] ci: run tests and static analysis on allyesconfig
In-Reply-To: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
References: <20250326075919.3448789-1-a.fatoum@pengutronix.de>
Message-ID: <174306746162.1056706.7758893365524562090.b4-ty@pengutronix.de>


On Wed, 26 Mar 2025 08:59:13 +0100, Ahmad Fatoum wrote:
> With a one-liner fix remaining[1], sandbox now builds allyesconfig sans
> SDL/libftdi to completion. Let's seize the opportunity and add it to CI,
> so we easily detect breakage around allyesconfig in future.
> 
> This series also switches the recently added Coverity and CodeQL Github
> Actions to use allyesconfig to extend coverage to non-sandbox related
> drivers as well.
> 
> [...]

Applied, thanks!

[1/6] sandbox: use CROSS_PKG_CONFIG when compiling sandbox arch code
      https://git.pengutronix.de/cgit/barebox/commit/?id=1026d6df3db8 (link may not be stable)
[2/6] sandbox: hide sdl/libftdi symbols if libraries not found
      https://git.pengutronix.de/cgit/barebox/commit/?id=3763b996fac0 (link may not be stable)
[3/6] MAKEALL: fix check_pipe_status usage
      https://git.pengutronix.de/cgit/barebox/commit/?id=b88a1d166575 (link may not be stable)
[4/6] MAKEALL: remove use of alias in script
      https://git.pengutronix.de/cgit/barebox/commit/?id=61f240e31659 (link may not be stable)
[5/6] ci: pytest: run test suite on sandbox allyesconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=18bf3d40253c (link may not be stable)
[6/6] ci: run static analysis on allyesconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=a886cc803dfa (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From robin at protonic.nl  Thu Mar 27 03:00:44 2025
From: robin at protonic.nl (Robin van der Gracht)
Date: Thu, 27 Mar 2025 11:00:44 +0100
Subject: [PATCH] ARM: boards: protonic-imx6: Add prt-usb as fallback preferred boot target
Message-ID: <20250327100044.654042-1-robin@protonic.nl>

If i.e. the bootchooser target fails because of missing or broken follow-up
software, instead of doing nothing, we try to boot from usb.

Signed-off-by: Robin van der Gracht <robin at protonic.nl>
---
 arch/arm/boards/protonic-imx6/board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 4585ca4730..19e58627c6 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -496,7 +496,7 @@ static int prt_imx6_env_init(struct prt_imx6_priv *priv)
 	if (!priv->no_usb_check)
 		boot_targets = xasprintf("prt-usb %s", bootsrc);
 	else
-		boot_targets = xstrdup(bootsrc);
+		boot_targets = xasprintf("%s prt-usb", bootsrc);
 
 	ret = setenv("global.boot.default", boot_targets);
 	free(boot_targets);
-- 
2.43.0



From robin at protonic.nl  Thu Mar 27 03:01:22 2025
From: robin at protonic.nl (Robin van der Gracht)
Date: Thu, 27 Mar 2025 11:01:22 +0100
Subject: [PATCH] ARM: boards: protonic-imx6: Re-introduce generic boot target board string
Message-ID: <20250327100122.654317-1-robin@protonic.nl>

This allows using a single bootable usb drive for multiple boards.

Signed-off-by: Robin van der Gracht <robin at protonic.nl>
---
 arch/arm/boards/protonic-imx6/board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 19e58627c6..e4debb1c66 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -374,7 +374,7 @@ static int prt_imx6_usb_boot(struct bootentry *entry, int verbose, int dryrun)
 
 	*second_word = 0;
 
-	if (strcmp(buf, priv->name)) {
+	if (strcmp(buf, priv->name) && strcmp(buf, "prti6qp")) {
 		dev_err(dev, "Boot target for a different board! (got: %s expected: %s)\n",
 			buf, priv->name);
 		ret = -EINVAL;
-- 
2.43.0



From robin at protonic.nl  Thu Mar 27 03:06:34 2025
From: robin at protonic.nl (Robin van der Gracht)
Date: Thu, 27 Mar 2025 11:06:34 +0100
Subject: [PATCH 1/2] ARM: boards: protonic-imx6: prtvt7: Don't use fixed numbers for dynamic GPIOs
Message-ID: <20250327100635.656657-1-robin@protonic.nl>

The GPIO indexing differs from the pin indexing.

Signed-off-by: Robin van der Gracht <robin at protonic.nl>
---
 arch/arm/boards/protonic-imx6/board.c | 32 +++++++++++++++++++++------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 9e62dc1544..4585ca4730 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -21,6 +21,7 @@
 #include <net.h>
 #include <of_device.h>
 #include <linux/regmap.h>
+#include <of_gpio.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -740,17 +741,34 @@ static int prt_imx6_init_kvg_yaco(struct prt_imx6_priv *priv)
 	return prt_imx6_init_kvg_power(priv, PW_MODE_KVG_WITH_YACO);
 }
 
-#define GPIO_KEY_F6     (0xe0 + 5)
-#define GPIO_KEY_CYCLE  (0xe0 + 2)
-
 static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
 {
-	/* This function relies heavely on the gpio-pca9539 driver */
+	int gpio_cycle, gpio_f6;
+	struct device_node *keys, *key;
+
+	keys = of_find_compatible_node(NULL, NULL, "gpio-keys");
+	if (!keys) {
+		dev_err(priv->dev, "Can't find gpio-keys of node!\n");
+		return -ENODEV;
+	}
 
-	gpio_direction_input(GPIO_KEY_F6);
-	gpio_direction_input(GPIO_KEY_CYCLE);
+	key = of_find_node_by_name(keys, "key-cycle");
+	gpio_cycle = of_get_named_gpio_flags(key, "gpios", 0, NULL);
+	if (gpio_cycle < 0) {
+		dev_err(priv->dev, "Unable to get cycle key gpio\n");
+		return gpio_cycle;
+	}
+	gpio_request_one(gpio_cycle, GPIOF_DIR_IN | GPIOF_ACTIVE_LOW, "Cycle");
+
+	key = of_find_node_by_name(keys, "key-f6");
+	gpio_f6 = of_get_named_gpio_flags(key, "gpios", 0, NULL);
+	if (gpio_f6 < 0) {
+		dev_err(priv->dev, "Unable to get F6 key gpio\n");
+		return gpio_f6;
+	}
+	gpio_request_one(gpio_f6, GPIOF_DIR_IN | GPIOF_ACTIVE_LOW, "F6");
 
-	if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
+	if (!(gpio_is_active(gpio_cycle) && gpio_is_active(gpio_f6)))
 		priv->no_usb_check = 1;
 
 	return 0;
-- 
2.43.0



From robin at protonic.nl  Thu Mar 27 03:06:35 2025
From: robin at protonic.nl (Robin van der Gracht)
Date: Thu, 27 Mar 2025 11:06:35 +0100
Subject: [PATCH 2/2] ARM: boards: protonic-imx6: prtvt7: Use autoboot timeout for serial boot
In-Reply-To: <20250327100635.656657-1-robin@protonic.nl>
References: <20250327100635.656657-1-robin@protonic.nl>
Message-ID: <20250327100635.656657-2-robin@protonic.nl>

Enabling the autoboot timeout for serial boot makes CI easier.

Signed-off-by: Robin van der Gracht <robin at protonic.nl>
---
 arch/arm/boards/protonic-imx6/board.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 4585ca4730..2757ea12b2 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -6,6 +6,7 @@
 #include <bbu.h>
 #include <boot.h>
 #include <bootm.h>
+#include <bootsource.h>
 #include <common.h>
 #include <deep-probe.h>
 #include <environment.h>
@@ -768,9 +769,13 @@ static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
 	}
 	gpio_request_one(gpio_f6, GPIOF_DIR_IN | GPIOF_ACTIVE_LOW, "F6");
 
-	if (!(gpio_is_active(gpio_cycle) && gpio_is_active(gpio_f6)))
-		priv->no_usb_check = 1;
+	if (gpio_is_active(gpio_cycle) && gpio_is_active(gpio_f6))
+		return 0;
+
+	if (bootsource_get() == BOOTSOURCE_SERIAL)
+		return 0;
 
+	priv->no_usb_check = 1;
 	return 0;
 }
 
-- 
2.43.0



From a.fatoum at pengutronix.de  Thu Mar 27 03:20:37 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 11:20:37 +0100
Subject: [PATCH] fixup! ci: pytest: run test suite on sandbox allyesconfig
Message-ID: <20250327102037.4096431-1-a.fatoum@pengutronix.de>

Fix defconfig used. Otherwise, we build the wrong defconfig and fail at
uploading files with an already existing name.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 .github/workflows/test-labgrid-pytest.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/test-labgrid-pytest.yml b/.github/workflows/test-labgrid-pytest.yml
index c43649e85fec..e1ccac67932f 100644
--- a/.github/workflows/test-labgrid-pytest.yml
+++ b/.github/workflows/test-labgrid-pytest.yml
@@ -57,7 +57,7 @@ jobs:
 
           - ARCH: sandbox
             lgenv: 'test/sandbox/allyesconfig.yaml'
-            defconfig: sandbox_defconfig
+            defconfig: allyesconfig
 
     steps:
     - name: Checkout code
-- 
2.39.5



From s.hauer at pengutronix.de  Thu Mar 27 03:29:09 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 11:29:09 +0100
Subject: [PATCH] fixup! ci: pytest: run test suite on sandbox allyesconfig
In-Reply-To: <20250327102037.4096431-1-a.fatoum@pengutronix.de>
References: <20250327102037.4096431-1-a.fatoum@pengutronix.de>
Message-ID: <Z-UodVA82LFNSzFd@pengutronix.de>

On Thu, Mar 27, 2025 at 11:20:37AM +0100, Ahmad Fatoum wrote:
> Fix defconfig used. Otherwise, we build the wrong defconfig and fail at
> uploading files with an already existing name.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  .github/workflows/test-labgrid-pytest.yml | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/.github/workflows/test-labgrid-pytest.yml b/.github/workflows/test-labgrid-pytest.yml
> index c43649e85fec..e1ccac67932f 100644
> --- a/.github/workflows/test-labgrid-pytest.yml
> +++ b/.github/workflows/test-labgrid-pytest.yml
> @@ -57,7 +57,7 @@ jobs:
>  
>            - ARCH: sandbox
>              lgenv: 'test/sandbox/allyesconfig.yaml'
> -            defconfig: sandbox_defconfig
> +            defconfig: allyesconfig
>  
>      steps:
>      - name: Checkout code
> -- 
> 2.39.5
> 
> 
> 

-- 
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-5555 |


From a.fatoum at pengutronix.de  Thu Mar 27 03:33:53 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 11:33:53 +0100
Subject: [PATCH] fixup! Revert "ci: container: downgrade OpenRISC toolchain from 14.2.0 to 13.1.0"
Message-ID: <20250327103353.81841-1-a.fatoum@pengutronix.de>

Effectively revert 18a154ce19 ("ci: container: fix CROSS_COMPILE_openrisc
to point at correct version"), because the correct version is no longer
13.1.0..

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/Containerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/Containerfile b/test/Containerfile
index 20402c384b6f..2da786c69925 100644
--- a/test/Containerfile
+++ b/test/Containerfile
@@ -97,7 +97,7 @@ RUN pip3 install -q --no-cache-dir --break-system-packages \
 ENV CROSS_COMPILE_arm=/opt/gcc-${GCC_VERSION}-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-
 ENV CROSS_COMPILE_arm64=/opt/gcc-${GCC_VERSION}-nolibc/aarch64-linux/bin/aarch64-linux-
 ENV CROSS_COMPILE_mips=/opt/gcc-${GCC_VERSION}-nolibc/mips-linux/bin/mips-linux-
-ENV CROSS_COMPILE_openrisc=/opt/gcc-13.1.0-nolibc/or1k-linux/bin/or1k-linux-
+ENV CROSS_COMPILE_openrisc=/opt/gcc-${GCC_VERSION}-nolibc/or1k-linux/bin/or1k-linux-
 ENV CROSS_COMPILE_powerpc=/opt/gcc-${GCC_VERSION}-nolibc/powerpc-linux/bin/powerpc-linux-
 ENV CROSS_COMPILE_riscv=/opt/gcc-${GCC_VERSION}-nolibc/riscv64-linux/bin/riscv64-linux-
 ENV CROSS_COMPILE_kvx=/opt/gcc-kalray-kvx-v5.0.0/bin/kvx-elf-
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 27 03:37:37 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 11:37:37 +0100
Subject: [PATCH v2 1/2] MAKEALL: support direct options for KCONFIG_ADD
In-Reply-To: <20250317113208.1863258-1-a.fatoum@pengutronix.de>
References: <20250317113208.1863258-1-a.fatoum@pengutronix.de>
Message-ID: <ea7831f3-fe10-4145-8fd1-37c83f67d111@pengutronix.de>

Hello Sascha,

On 3/17/25 12:32, Ahmad Fatoum wrote:
> KCONFIG_ADD currently expects a list of files to be merged.
> As MAKEALL is a bash script, let's make use of process substitution
> to create temporary files out of -k CONFIG_foo=bar options.

Please pick these two patches to the ci branch to workaround the build
breakage there.

Thanks,
Ahmad

> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> v1 -> v2:
>   - fix Regex (Sascha)
> ---
>  MAKEALL | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/MAKEALL b/MAKEALL
> index 1966eedb4673..bc612b45561f 100755
> --- a/MAKEALL
> +++ b/MAKEALL
> @@ -56,7 +56,7 @@ usage() {
>  	echo "BUILDDIR    -O      build dir"
>  	echo "LOGDIR      -l      log dir"
>  	echo "REGEX       -e      regex"
> -	echo "KCONFIG_ADD -k      kconfig fragment"
> +	echo "KCONFIG_ADD -k      kconfig fragment or option"
>  	echo "TARGET      -t      Makefile target"
>  	echo "V           -v      verbosity"
>  	echo "INCREMENTAL -i"
> @@ -116,6 +116,11 @@ report() {
>  	fi
>  }
>  
> +merge_config() {
> +	with_logs_collected ./scripts/kconfig/merge_config.sh -m -O \
> +		${BUILDDIR} "$@"
> +}
> +
>  do_build_defconfig() {
>  	local arch=$1
>  	local defconfig=$2
> @@ -156,8 +161,11 @@ do_build_defconfig() {
>  	MAKE="${MAKE} $silent_flag CROSS_COMPILE=${cross_compile}"
>  	with_logs_collected ${MAKE} ${defconfig}
>  	for i in ${KCONFIG_ADD}; do
> -		with_logs_collected ./scripts/kconfig/merge_config.sh -m -O \
> -			${BUILDDIR} ${BUILDDIR}/.config $i
> +		if [[ $i =~ ^CONFIG_.*=.* ]]; then
> +			merge_config ${BUILDDIR}/.config <(echo $i)
> +		else
> +			merge_config ${BUILDDIR}/.config $i
> +		fi
>  	done
>  	with_logs_collected ${MAKE} $silent_flag olddefconfig
>  



From s.hauer at pengutronix.de  Thu Mar 27 03:48:01 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Mar 2025 11:48:01 +0100
Subject: [PATCH] fixup! Revert "ci: container: downgrade OpenRISC
 toolchain from 14.2.0 to 13.1.0"
In-Reply-To: <20250327103353.81841-1-a.fatoum@pengutronix.de>
References: <20250327103353.81841-1-a.fatoum@pengutronix.de>
Message-ID: <174307248125.2722859.14378646625721901013.b4-ty@pengutronix.de>


On Thu, 27 Mar 2025 11:33:53 +0100, Ahmad Fatoum wrote:
> Effectively revert 18a154ce19 ("ci: container: fix CROSS_COMPILE_openrisc
> to point at correct version"), because the correct version is no longer
> 13.1.0..
> 
> 

Applied, thanks!

[1/1] fixup! Revert "ci: container: downgrade OpenRISC toolchain from 14.2.0 to 13.1.0"
      https://git.pengutronix.de/cgit/barebox/commit/?id=56d8b7b49073 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From a.fatoum at pengutronix.de  Thu Mar 27 04:37:53 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 12:37:53 +0100
Subject: [PATCH] common: make TLSF the default allocator
Message-ID: <20250327113753.361094-1-a.fatoum@pengutronix.de>

Going by the most used defconfigs (multi_*_defconfig), TLSF is the most
used allocator and it supports features absent in dlmalloc like
multiple pools (used on ARMv7-R) and has KASAN integration, so there's
even less reason to use dlmalloc nowadays.

In preparation for possible removal of dlmalloc in future, switch the
default away from dlmalloc.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/Kconfig b/common/Kconfig
index ddc76b2033b2..f0cd2f0729a4 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -312,6 +312,7 @@ config EXPERIMENTAL
 
 choice
 	prompt "malloc implementation"
+	default MALLOC_TLSF
 
 config MALLOC_DLMALLOC
 	bool "dlmalloc"
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 27 04:51:31 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 12:51:31 +0100
Subject: Removal of dlmalloc?
Message-ID: <7a4edaef-a606-4b9d-bdf5-c7b5f896daae@pengutronix.de>

Hi,

We have a TLSF implemenation in barebox for >= 13 years now and it has
more features than dlmalloc like multiple pools and KASAN integration.

I think it's thus time to retire the dlmalloc we inherited from U-Boot.

Unfortunately, TLSF was not the default in the config, even though the
most common configs select it. I'd thus suggest we remove dlmalloc
altogether after v2025.06.0 is tagged.

Thoughts? Objections?

Cheers,
Ahmad


From bst at pengutronix.de  Thu Mar 27 06:20:52 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Thu, 27 Mar 2025 14:20:52 +0100
Subject: [PATCH] kbuild: undefine linux/unix macros
Message-ID: <20250327132052.3187117-1-bst@pengutronix.de>

gcc and clang, when using `-std=gnu11`, predefine `linux` and `unix` as
macros:

  $ gcc -std=gnu11 -dM -E - < /dev/null | grep -v "define _"
  #define unix 1
  #define linux 1

This causes issues in `BAREBOX_MAGICVAR()`, where variable names
containing "linux" or "unix" get incorrectly expanded, leading to invalid
names:

  barebox at Sandbox:/ magicvar
  [...]
  global.1.blkdevparts.*           Linux blkdevparts variables
  global.1.bootargs.*              Linux bootargs variables
  global.1.bootargs.console        console= argument for Linux from the stdout-path property in /chosen node
  global.1.bootargs_append         append to original oftree bootargs
  global.1.mtdparts.*              Linux mtdparts variables
  [...]

Explicitly undefine these non-conforming macros to ensure correct
behavior.

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 5c9fce83123..ff7179bf9d5 100644
--- a/Makefile
+++ b/Makefile
@@ -486,7 +486,8 @@ LINUXINCLUDE    := -Iinclude \
 		   -I$(objtree)/arch/$(SRCARCH)/include \
 		   $(USERINCLUDE)
 
-KBUILD_CPPFLAGS        := -D__KERNEL__ -D__BAREBOX__ $(LINUXINCLUDE) -fno-builtin -ffreestanding
+KBUILD_CPPFLAGS        := -D__KERNEL__ -D__BAREBOX__ $(LINUXINCLUDE) \
+			  -fno-builtin -ffreestanding -Ulinux -Uunix
 
 KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
 		   -fno-strict-aliasing -fno-common -fshort-wchar \
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 27 06:24:22 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 14:24:22 +0100
Subject: [PATCH] kbuild: undefine linux/unix macros
In-Reply-To: <20250327132052.3187117-1-bst@pengutronix.de>
References: <20250327132052.3187117-1-bst@pengutronix.de>
Message-ID: <deb2ab3f-1a24-4af3-bfea-878ecd9f545f@pengutronix.de>

Hi,

On 3/27/25 14:20, Bastian Krause wrote:
> gcc and clang, when using `-std=gnu11`, predefine `linux` and `unix` as
> macros:
> 
>   $ gcc -std=gnu11 -dM -E - < /dev/null | grep -v "define _"
>   #define unix 1
>   #define linux 1
> 
> This causes issues in `BAREBOX_MAGICVAR()`, where variable names
> containing "linux" or "unix" get incorrectly expanded, leading to invalid
> names:
> 
>   barebox at Sandbox:/ magicvar
>   [...]
>   global.1.blkdevparts.*           Linux blkdevparts variables
>   global.1.bootargs.*              Linux bootargs variables
>   global.1.bootargs.console        console= argument for Linux from the stdout-path property in /chosen node
>   global.1.bootargs_append         append to original oftree bootargs
>   global.1.mtdparts.*              Linux mtdparts variables
>   [...]
> 
> Explicitly undefine these non-conforming macros to ensure correct
> behavior.
> 
> Signed-off-by: Bastian Krause <bst at pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

Thanks,
Ahmad

> ---
>  Makefile | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 5c9fce83123..ff7179bf9d5 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -486,7 +486,8 @@ LINUXINCLUDE    := -Iinclude \
>  		   -I$(objtree)/arch/$(SRCARCH)/include \
>  		   $(USERINCLUDE)
>  
> -KBUILD_CPPFLAGS        := -D__KERNEL__ -D__BAREBOX__ $(LINUXINCLUDE) -fno-builtin -ffreestanding
> +KBUILD_CPPFLAGS        := -D__KERNEL__ -D__BAREBOX__ $(LINUXINCLUDE) \
> +			  -fno-builtin -ffreestanding -Ulinux -Uunix
>  
>  KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
>  		   -fno-strict-aliasing -fno-common -fshort-wchar \



From eagle.alexander923 at gmail.com  Thu Mar 27 07:32:18 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Thu, 27 Mar 2025 17:32:18 +0300
Subject: [PATCH] phy: rockchip: naneng-combphy: Updating the driver from the kernel repository
Message-ID: <20250327143218.1630440-1-eagle.alexander923@gmail.com>

The current rockchip-naneng-combphy PHY driver causes my RK3588
board to hang when probing PCI2 (I think due to insufficient
clock initialization).
This patch replaces the driver code from the Linux kernel repository,
and now the bootloader works fine with pcie2x1l0.pcie2x1l2 devices
on the RK3588.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 .../rockchip/phy-rockchip-naneng-combphy.c    | 1093 ++++++++++-------
 1 file changed, 651 insertions(+), 442 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-naneng-combphy.c b/drivers/phy/rockchip/phy-rockchip-naneng-combphy.c
index b334ced811..7951a109f5 100644
--- a/drivers/phy/rockchip/phy-rockchip-naneng-combphy.c
+++ b/drivers/phy/rockchip/phy-rockchip-naneng-combphy.c
@@ -6,23 +6,100 @@
  */
 
 #include <common.h>
-#include <init.h>
 #include <io.h>
 #include <of.h>
 #include <errno.h>
 #include <driver.h>
-#include <malloc.h>
 #include <linux/usb/phy.h>
 #include <linux/phy/phy.h>
+#include <linux/bitfield.h>
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/reset.h>
 #include <linux/regmap.h>
+#include <linux/units.h>
 #include <mfd/syscon.h>
 #include <linux/iopoll.h>
 #include <dt-bindings/phy/phy.h>
 
 #define BIT_WRITEABLE_SHIFT		16
+#define REF_CLOCK_24MHz			(24 * HZ_PER_MHZ)
+#define REF_CLOCK_25MHz			(25 * HZ_PER_MHZ)
+#define REF_CLOCK_100MHz		(100 * HZ_PER_MHZ)
+
+/* COMBO PHY REG */
+#define PHYREG6				0x14
+#define PHYREG6_PLL_DIV_MASK		GENMASK(7, 6)
+#define PHYREG6_PLL_DIV_SHIFT		6
+#define PHYREG6_PLL_DIV_2		1
+
+#define PHYREG7				0x18
+#define PHYREG7_TX_RTERM_MASK		GENMASK(7, 4)
+#define PHYREG7_TX_RTERM_SHIFT		4
+#define PHYREG7_TX_RTERM_50OHM		8
+#define PHYREG7_RX_RTERM_MASK		GENMASK(3, 0)
+#define PHYREG7_RX_RTERM_SHIFT		0
+#define PHYREG7_RX_RTERM_44OHM		15
+
+#define PHYREG8				0x1C
+#define PHYREG8_SSC_EN			BIT(4)
+
+#define PHYREG10			0x24
+#define PHYREG10_SSC_PCM_MASK		GENMASK(3, 0)
+#define PHYREG10_SSC_PCM_3500PPM	7
+
+#define PHYREG11			0x28
+#define PHYREG11_SU_TRIM_0_7		0xF0
+
+#define PHYREG12			0x2C
+#define PHYREG12_PLL_LPF_ADJ_VALUE	4
+
+#define PHYREG13			0x30
+#define PHYREG13_RESISTER_MASK		GENMASK(5, 4)
+#define PHYREG13_RESISTER_SHIFT		0x4
+#define PHYREG13_RESISTER_HIGH_Z	3
+#define PHYREG13_CKRCV_AMP0		BIT(7)
+
+#define PHYREG14			0x34
+#define PHYREG14_CKRCV_AMP1		BIT(0)
+
+#define PHYREG15			0x38
+#define PHYREG15_CTLE_EN		BIT(0)
+#define PHYREG15_SSC_CNT_MASK		GENMASK(7, 6)
+#define PHYREG15_SSC_CNT_SHIFT		6
+#define PHYREG15_SSC_CNT_VALUE		1
+
+#define PHYREG16			0x3C
+#define PHYREG16_SSC_CNT_VALUE		0x5f
+
+#define PHYREG17			0x40
+
+#define PHYREG18			0x44
+#define PHYREG18_PLL_LOOP		0x32
+
+#define PHYREG21			0x50
+#define PHYREG21_RX_SQUELCH_VAL		0x0D
+
+#define PHYREG27			0x6C
+#define PHYREG27_RX_TRIM_RK3588		0x4C
+
+#define PHYREG30			0x74
+
+#define PHYREG32			0x7C
+#define PHYREG32_SSC_MASK		GENMASK(7, 4)
+#define PHYREG32_SSC_DIR_MASK		GENMASK(5, 4)
+#define PHYREG32_SSC_DIR_SHIFT		4
+#define PHYREG32_SSC_UPWARD		0
+#define PHYREG32_SSC_DOWNWARD		1
+#define PHYREG32_SSC_OFFSET_MASK	GENMASK(7, 6)
+#define PHYREG32_SSC_OFFSET_SHIFT	6
+#define PHYREG32_SSC_OFFSET_500PPM	1
+
+#define PHYREG33			0x80
+#define PHYREG33_PLL_KVCO_MASK		GENMASK(4, 2)
+#define PHYREG33_PLL_KVCO_SHIFT		2
+#define PHYREG33_PLL_KVCO_VALUE		2
+#define PHYREG33_PLL_KVCO_VALUE_RK3576	4
 
 struct rockchip_combphy_priv;
 
@@ -64,22 +141,21 @@ struct rockchip_combphy_grfcfg {
 	struct combphy_reg con3_for_sata;
 	struct combphy_reg pipe_con0_for_sata;
 	struct combphy_reg pipe_con1_for_sata;
-	struct combphy_reg pipe_sgmii_mac_sel;
 	struct combphy_reg pipe_xpcs_phy_ready;
-	struct combphy_reg u3otg0_port_en;
-	struct combphy_reg u3otg1_port_en;
+	struct combphy_reg pipe_pcie1l0_sel;
+	struct combphy_reg pipe_pcie1l1_sel;
 };
 
 struct rockchip_combphy_cfg {
-	const int num_clks;
-	const struct clk_bulk_data *clks;
+	unsigned int num_phys;
+	unsigned int phy_ids[3];
 	const struct rockchip_combphy_grfcfg *grfcfg;
-	bool force_det_out; /* Tx detect Rx errata */
 	int (*combphy_cfg)(struct rockchip_combphy_priv *priv);
 };
 
 struct rockchip_combphy_priv {
-	u8 mode;
+	u8 type;
+	int id;
 	void __iomem *mmio;
 	int num_clks;
 	struct clk_bulk_data *clks;
@@ -89,26 +165,23 @@ struct rockchip_combphy_priv {
 	struct phy *phy;
 	struct reset_control *phy_rst;
 	const struct rockchip_combphy_cfg *cfg;
+	bool enable_ssc;
+	bool ext_refclk;
+	struct clk *refclk;
 };
 
-static inline bool param_read(struct regmap *base,
-			      const struct combphy_reg *reg, u32 val)
+static void rockchip_combphy_updatel(struct rockchip_combphy_priv *priv,
+				     int mask, int val, int reg)
 {
-	int ret;
-	u32 mask, orig, tmp;
-
-	ret = regmap_read(base, reg->offset, &orig);
-	if (ret)
-		return false;
+	unsigned int temp;
 
-	mask = GENMASK(reg->bitend, reg->bitstart);
-	tmp = (orig & mask) >> reg->bitstart;
-
-	return tmp == val;
+	temp = readl(priv->mmio + reg);
+	temp = (temp & ~(mask)) | val;
+	writel(temp, priv->mmio + reg);
 }
 
-static int param_write(struct regmap *base,
-		       const struct combphy_reg *reg, bool en)
+static int rockchip_combphy_param_write(struct regmap *base,
+					const struct combphy_reg *reg, bool en)
 {
 	u32 val, mask, tmp;
 
@@ -133,115 +206,47 @@ static u32 rockchip_combphy_is_ready(struct rockchip_combphy_priv *priv)
 	return val;
 }
 
-static int rockchip_combphy_pcie_init(struct rockchip_combphy_priv *priv)
-{
-	int ret = 0;
-
-	if (priv->cfg->combphy_cfg) {
-		ret = priv->cfg->combphy_cfg(priv);
-		if (ret) {
-			dev_err(priv->dev, "failed to init phy for pcie\n");
-			return ret;
-		}
-	}
-
-	return ret;
-}
-
-static int rockchip_combphy_usb3_init(struct rockchip_combphy_priv *priv)
-{
-	int ret = 0;
-
-	if (priv->cfg->combphy_cfg) {
-		ret = priv->cfg->combphy_cfg(priv);
-		if (ret) {
-			dev_err(priv->dev, "failed to init phy for usb3\n");
-			return ret;
-		}
-	}
-
-	return ret;
-}
-
-static int rockchip_combphy_sata_init(struct rockchip_combphy_priv *priv)
-{
-	int ret = 0;
-
-	if (priv->cfg->combphy_cfg) {
-		ret = priv->cfg->combphy_cfg(priv);
-		if (ret) {
-			dev_err(priv->dev, "failed to init phy for sata\n");
-			return ret;
-		}
-	}
-
-	return ret;
-}
-
-static int rockchip_combphy_sgmii_init(struct rockchip_combphy_priv *priv)
+static int rockchip_combphy_init(struct phy *phy)
 {
-	int ret = 0;
+	struct rockchip_combphy_priv *priv = phy_get_drvdata(phy);
+	const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg;
+	u32 val;
+	int ret;
 
-	if (priv->cfg->combphy_cfg) {
-		ret = priv->cfg->combphy_cfg(priv);
-		if (ret) {
-			dev_err(priv->dev, "failed to init phy for sgmii\n");
-			return ret;
-		}
+	ret = clk_bulk_prepare_enable(priv->num_clks, priv->clks);
+	if (ret) {
+		dev_err(priv->dev, "failed to enable clks\n");
+		return ret;
 	}
 
-	return ret;
-}
-
-static int rockchip_combphy_set_mode(struct rockchip_combphy_priv *priv)
-{
-	switch (priv->mode) {
+	switch (priv->type) {
 	case PHY_TYPE_PCIE:
-		rockchip_combphy_pcie_init(priv);
-		break;
 	case PHY_TYPE_USB3:
-		rockchip_combphy_usb3_init(priv);
-		break;
 	case PHY_TYPE_SATA:
-		rockchip_combphy_sata_init(priv);
-		break;
 	case PHY_TYPE_SGMII:
 	case PHY_TYPE_QSGMII:
-		return rockchip_combphy_sgmii_init(priv);
+		if (priv->cfg->combphy_cfg)
+			ret = priv->cfg->combphy_cfg(priv);
+		break;
 	default:
 		dev_err(priv->dev, "incompatible PHY type\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		break;
 	}
 
-	return 0;
-}
-
-static int rockchip_combphy_init(struct phy *phy)
-{
-	struct rockchip_combphy_priv *priv = phy_get_drvdata(phy);
-	const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg;
-	u32 val;
-	int ret;
-
-	ret = clk_bulk_enable(priv->num_clks, priv->clks);
 	if (ret) {
-		dev_err(priv->dev, "failed to enable clks\n");
-		return ret;
-	}
-
-	ret = rockchip_combphy_set_mode(priv);
-	if (ret)
+		dev_err(priv->dev, "failed to init phy for phy type %x\n", priv->type);
 		goto err_clk;
+	}
 
 	ret = reset_control_deassert(priv->phy_rst);
 	if (ret)
 		goto err_clk;
 
-	if (priv->mode == PHY_TYPE_USB3) {
-		ret = readx_poll_timeout(rockchip_combphy_is_ready,
-						priv, val,
-						val == cfg->pipe_phy_status.enable,
-						1000);
+	if (priv->type == PHY_TYPE_USB3) {
+		ret = readx_poll_timeout(rockchip_combphy_is_ready, priv, val,
+					 val == cfg->pipe_phy_status.enable,
+					 1000);
 		if (ret)
 			dev_warn(priv->dev, "wait phy status ready timeout\n");
 	}
@@ -249,7 +254,7 @@ static int rockchip_combphy_init(struct phy *phy)
 	return 0;
 
 err_clk:
-	clk_bulk_disable(priv->num_clks, priv->clks);
+	clk_bulk_disable_unprepare(priv->num_clks, priv->clks);
 
 	return ret;
 }
@@ -258,19 +263,18 @@ static int rockchip_combphy_exit(struct phy *phy)
 {
 	struct rockchip_combphy_priv *priv = phy_get_drvdata(phy);
 
-	clk_bulk_disable(priv->num_clks, priv->clks);
+	clk_bulk_disable_unprepare(priv->num_clks, priv->clks);
 	reset_control_assert(priv->phy_rst);
 
 	return 0;
 }
 
-static const struct phy_ops rochchip_combphy_ops = {
+static const struct phy_ops rockchip_combphy_ops = {
 	.init = rockchip_combphy_init,
 	.exit = rockchip_combphy_exit,
 };
 
-static struct phy *rockchip_combphy_xlate(struct device *dev,
-					  const struct of_phandle_args *args)
+static struct phy *rockchip_combphy_xlate(struct device *dev, const struct of_phandle_args *args)
 {
 	struct rockchip_combphy_priv *priv = dev->priv;
 
@@ -279,52 +283,60 @@ static struct phy *rockchip_combphy_xlate(struct device *dev,
 		return ERR_PTR(-EINVAL);
 	}
 
-	if (priv->mode != PHY_NONE && priv->mode != args->args[0])
+	if (priv->type != PHY_NONE && priv->type != args->args[0])
 		dev_warn(dev, "phy type select %d overwriting type %d\n",
-			 args->args[0], priv->mode);
+			 args->args[0], priv->type);
 
-	priv->mode = args->args[0];
+	priv->type = args->args[0];
 
 	return priv->phy;
 }
 
-static int rockchip_combphy_parse_dt(struct device *dev,
-				     struct rockchip_combphy_priv *priv)
+static int rockchip_combphy_parse_dt(struct device *dev, struct rockchip_combphy_priv *priv)
 {
-	struct device_node *np = dev->of_node;
-	const struct rockchip_combphy_cfg *phy_cfg = priv->cfg;
-	int ret, mac_id;
+	int i;
 
-	ret = clk_bulk_get(dev, priv->num_clks, priv->clks);
-	if (ret == -EPROBE_DEFER)
-		return -EPROBE_DEFER;
-	if (ret)
-		priv->num_clks = 0;
+	priv->num_clks = clk_bulk_get_all(dev, &priv->clks);
+	if (priv->num_clks < 1)
+		return -EINVAL;
 
-	priv->pipe_grf = syscon_regmap_lookup_by_phandle(np,
-							 "rockchip,pipe-grf");
+	priv->refclk = NULL;
+	for (i = 0; i < priv->num_clks; i++) {
+		if (!strncmp(priv->clks[i].id, "ref", 3)) {
+			priv->refclk = priv->clks[i].clk;
+			break;
+		}
+	}
+
+	if (!priv->refclk) {
+		dev_err(dev, "no refclk found\n");
+		return -EINVAL;
+	}
+
+	priv->pipe_grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,pipe-grf");
 	if (IS_ERR(priv->pipe_grf)) {
 		dev_err(dev, "failed to find peri_ctrl pipe-grf regmap\n");
 		return PTR_ERR(priv->pipe_grf);
 	}
 
-	priv->phy_grf = syscon_regmap_lookup_by_phandle(np,
-							"rockchip,pipe-phy-grf");
+	priv->phy_grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,pipe-phy-grf");
 	if (IS_ERR(priv->phy_grf)) {
 		dev_err(dev, "failed to find peri_ctrl pipe-phy-grf regmap\n");
 		return PTR_ERR(priv->phy_grf);
 	}
 
-	if (!of_property_read_u32(np, "rockchip,sgmii-mac-sel", &mac_id) &&
-	    (mac_id > 0))
-		param_write(priv->pipe_grf, &phy_cfg->grfcfg->pipe_sgmii_mac_sel,
-			    true);
+	priv->enable_ssc = of_property_read_bool(dev->of_node, "rockchip,enable-ssc");
+
+	priv->ext_refclk = of_property_read_bool(dev->of_node, "rockchip,ext-refclk");
 
-	priv->phy_rst = reset_control_get(dev, NULL);
+	priv->phy_rst = reset_control_get(dev, "phy");
+	/* fallback to old behaviour */
+	if (PTR_ERR(priv->phy_rst) == -ENOENT)
+		priv->phy_rst = reset_control_get(dev, NULL);
 	if (IS_ERR(priv->phy_rst))
-		return dev_errp_probe(dev, priv->phy_rst, "getting phy reset\n");
+		return dev_err_probe(dev, PTR_ERR(priv->phy_rst), "failed to get phy reset\n");
 
-	return reset_control_assert(priv->phy_rst);
+	return 0;
 }
 
 static int rockchip_combphy_probe(struct device *dev)
@@ -333,11 +345,11 @@ static int rockchip_combphy_probe(struct device *dev)
 	struct rockchip_combphy_priv *priv;
 	const struct rockchip_combphy_cfg *phy_cfg;
 	struct resource *res;
-	int ret;
+	int ret, id;
 
 	phy_cfg = device_get_match_data(dev);
 	if (!phy_cfg) {
-		dev_err(dev, "No OF match data provided\n");
+		dev_err(dev, "no OF match data provided\n");
 		return -EINVAL;
 	}
 
@@ -353,22 +365,30 @@ static int rockchip_combphy_probe(struct device *dev)
 
 	priv->mmio = IOMEM(res->start);
 
-	priv->num_clks = phy_cfg->num_clks;
-
-	priv->clks = memdup(phy_cfg->clks,
-			    phy_cfg->num_clks * sizeof(struct clk_bulk_data));
-	if (!priv->clks)
-		return -ENOMEM;
+	/* find the phy-id from the io address */
+	priv->id = -ENODEV;
+	for (id = 0; id < phy_cfg->num_phys; id++) {
+		if (res->start == phy_cfg->phy_ids[id]) {
+			priv->id = id;
+			break;
+		}
+	}
 
 	priv->dev = dev;
-	priv->mode = PHY_NONE;
+	priv->type = PHY_NONE;
 	priv->cfg = phy_cfg;
 
 	ret = rockchip_combphy_parse_dt(dev, priv);
 	if (ret)
 		return ret;
 
-	priv->phy = phy_create(dev, NULL, &rochchip_combphy_ops);
+	ret = reset_control_assert(priv->phy_rst);
+	if (ret) {
+		dev_err(dev, "failed to reset phy\n");
+		return ret;
+	}
+
+	priv->phy = phy_create(dev, NULL, &rockchip_combphy_ops);
 	if (IS_ERR(priv->phy)) {
 		dev_err(dev, "failed to create combphy\n");
 		return PTR_ERR(priv->phy);
@@ -384,146 +404,161 @@ static int rockchip_combphy_probe(struct device *dev)
 
 static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv)
 {
-	struct device_node *np = priv->dev->of_node;
 	const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg;
-	struct clk *refclk = NULL;
 	unsigned long rate;
 	u32 val;
 
-	/* Configure PHY reference clock frequency */
-	refclk = priv->clks[0].clk;
-	if (!refclk) {
-		dev_err(priv->dev, "No refclk found\n");
-		return -EINVAL;
-	}
-
-	switch (priv->mode) {
+	switch (priv->type) {
 	case PHY_TYPE_PCIE:
-		/* Set SSC downward spread spectrum */
-		val = readl(priv->mmio + (0x1f << 2));
-		val &= ~GENMASK(5, 4);
-		val |= 0x01 << 4;
-		writel(val, priv->mmio + 0x7c);
-
-		param_write(priv->phy_grf, &cfg->con0_for_pcie, true);
-		param_write(priv->phy_grf, &cfg->con1_for_pcie, true);
-		param_write(priv->phy_grf, &cfg->con2_for_pcie, true);
-		param_write(priv->phy_grf, &cfg->con3_for_pcie, true);
+		/* Set SSC downward spread spectrum. */
+		rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK,
+					 PHYREG32_SSC_DOWNWARD << PHYREG32_SSC_DIR_SHIFT,
+					 PHYREG32);
+
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con0_for_pcie, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con1_for_pcie, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con2_for_pcie, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con3_for_pcie, true);
 		break;
-	case PHY_TYPE_USB3:
-		/* Set SSC downward spread spectrum */
-		val = readl(priv->mmio + (0x1f << 2));
-		val &= ~GENMASK(5, 4);
-		val |= 0x01 << 4;
-		writel(val, priv->mmio + 0x7c);
 
-		/* Enable adaptive CTLE for USB3.0 Rx */
-		val = readl(priv->mmio + (0x0e << 2));
-		val &= ~GENMASK(0, 0);
-		val |= 0x01;
-		writel(val, priv->mmio + (0x0e << 2));
-
-		param_write(priv->phy_grf, &cfg->pipe_sel_usb, true);
-		param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false);
-		param_write(priv->phy_grf, &cfg->pipe_txelec_sel, false);
-		param_write(priv->phy_grf, &cfg->usb_mode_set, true);
+	case PHY_TYPE_USB3:
+		/* Set SSC downward spread spectrum. */
+		rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK,
+					 PHYREG32_SSC_DOWNWARD << PHYREG32_SSC_DIR_SHIFT,
+					 PHYREG32);
+
+		/* Enable adaptive CTLE for USB3.0 Rx. */
+		val = readl(priv->mmio + PHYREG15);
+		val |= PHYREG15_CTLE_EN;
+		writel(val, priv->mmio + PHYREG15);
+
+		/* Set PLL KVCO fine tuning signals. */
+		rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK,
+					 PHYREG33_PLL_KVCO_VALUE << PHYREG33_PLL_KVCO_SHIFT,
+					 PHYREG33);
+
+		/* Enable controlling random jitter. */
+		writel(PHYREG12_PLL_LPF_ADJ_VALUE, priv->mmio + PHYREG12);
+
+		/* Set PLL input clock divider 1/2. */
+		rockchip_combphy_updatel(priv, PHYREG6_PLL_DIV_MASK,
+					 PHYREG6_PLL_DIV_2 << PHYREG6_PLL_DIV_SHIFT,
+					 PHYREG6);
+
+		writel(PHYREG18_PLL_LOOP, priv->mmio + PHYREG18);
+		writel(PHYREG11_SU_TRIM_0_7, priv->mmio + PHYREG11);
+
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_sel_usb, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txelec_sel, false);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->usb_mode_set, true);
 		break;
+
 	case PHY_TYPE_SATA:
-		writel(0x41, priv->mmio + 0x38);
-		writel(0x8F, priv->mmio + 0x18);
-		param_write(priv->phy_grf, &cfg->con0_for_sata, true);
-		param_write(priv->phy_grf, &cfg->con1_for_sata, true);
-		param_write(priv->phy_grf, &cfg->con2_for_sata, true);
-		param_write(priv->phy_grf, &cfg->con3_for_sata, true);
-		param_write(priv->pipe_grf, &cfg->pipe_con0_for_sata, true);
+		/* Enable adaptive CTLE for SATA Rx. */
+		val = readl(priv->mmio + PHYREG15);
+		val |= PHYREG15_CTLE_EN;
+		writel(val, priv->mmio + PHYREG15);
+		/*
+		 * Set tx_rterm=50ohm and rx_rterm=44ohm for SATA.
+		 * 0: 60ohm, 8: 50ohm 15: 44ohm (by step abort 1ohm)
+		 */
+		val = PHYREG7_TX_RTERM_50OHM << PHYREG7_TX_RTERM_SHIFT;
+		val |= PHYREG7_RX_RTERM_44OHM << PHYREG7_RX_RTERM_SHIFT;
+		writel(val, priv->mmio + PHYREG7);
+
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con0_for_sata, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con1_for_sata, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con2_for_sata, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con3_for_sata, true);
+		rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_con0_for_sata, true);
 		break;
+
 	case PHY_TYPE_SGMII:
-		param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true);
-		param_write(priv->phy_grf, &cfg->pipe_phymode_sel, true);
-		param_write(priv->phy_grf, &cfg->pipe_sel_qsgmii, true);
-		param_write(priv->phy_grf, &cfg->sgmii_mode_set, true);
+		rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_phymode_sel, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_sel_qsgmii, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->sgmii_mode_set, true);
 		break;
+
 	case PHY_TYPE_QSGMII:
-		param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true);
-		param_write(priv->phy_grf, &cfg->pipe_phymode_sel, true);
-		param_write(priv->phy_grf, &cfg->pipe_rate_sel, true);
-		param_write(priv->phy_grf, &cfg->pipe_sel_qsgmii, true);
-		param_write(priv->phy_grf, &cfg->qsgmii_mode_set, true);
+		rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_phymode_sel, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_rate_sel, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_sel_qsgmii, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->qsgmii_mode_set, true);
 		break;
+
 	default:
 		dev_err(priv->dev, "incompatible PHY type\n");
 		return -EINVAL;
 	}
 
-	rate = clk_get_rate(refclk);
+	rate = clk_get_rate(priv->refclk);
 
 	switch (rate) {
-	case 24000000:
-		if (priv->mode == PHY_TYPE_USB3 || priv->mode == PHY_TYPE_SATA) {
-			/* Set ssc_cnt[9:0]=0101111101 & 31.5KHz */
-			val = readl(priv->mmio + (0x0e << 2));
-			val &= ~GENMASK(7, 6);
-			val |= 0x01 << 6;
-			writel(val, priv->mmio + (0x0e << 2));
-
-			val = readl(priv->mmio + (0x0f << 2));
-			val &= ~GENMASK(7, 0);
-			val |= 0x5f;
-			writel(val, priv->mmio + (0x0f << 2));
+	case REF_CLOCK_24MHz:
+		if (priv->type == PHY_TYPE_USB3 || priv->type == PHY_TYPE_SATA) {
+			/* Set ssc_cnt[9:0]=0101111101 & 31.5KHz. */
+			val = PHYREG15_SSC_CNT_VALUE << PHYREG15_SSC_CNT_SHIFT;
+			rockchip_combphy_updatel(priv, PHYREG15_SSC_CNT_MASK,
+						 val, PHYREG15);
+
+			writel(PHYREG16_SSC_CNT_VALUE, priv->mmio + PHYREG16);
 		}
 		break;
-	case 25000000:
-		param_write(priv->phy_grf, &cfg->pipe_clk_25m, true);
+
+	case REF_CLOCK_25MHz:
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_25m, true);
 		break;
-	case 100000000:
-		param_write(priv->phy_grf, &cfg->pipe_clk_100m, true);
-		if (priv->mode == PHY_TYPE_PCIE) {
-			/* PLL KVCO tuning fine */
-			val = readl(priv->mmio + (0x20 << 2));
-			val &= ~(0x7 << 2);
-			val |= 0x2 << 2;
-			writel(val, priv->mmio + (0x20 << 2));
-
-			/* Enable controlling random jitter, aka RMJ */
-			writel(0x4, priv->mmio + (0xb << 2));
-
-			val = readl(priv->mmio + (0x5 << 2));
-			val &= ~(0x3 << 6);
-			val |= 0x1 << 6;
-			writel(val, priv->mmio + (0x5 << 2));
-
-			writel(0x32, priv->mmio + (0x11 << 2));
-			writel(0xf0, priv->mmio + (0xa << 2));
-		} else if (priv->mode == PHY_TYPE_SATA) {
+
+	case REF_CLOCK_100MHz:
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_100m, true);
+		if (priv->type == PHY_TYPE_PCIE) {
+			/* PLL KVCO  fine tuning. */
+			val = PHYREG33_PLL_KVCO_VALUE << PHYREG33_PLL_KVCO_SHIFT;
+			rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK,
+						 val, PHYREG33);
+
+			/* Enable controlling random jitter. */
+			writel(PHYREG12_PLL_LPF_ADJ_VALUE, priv->mmio + PHYREG12);
+
+			val = PHYREG6_PLL_DIV_2 << PHYREG6_PLL_DIV_SHIFT;
+			rockchip_combphy_updatel(priv, PHYREG6_PLL_DIV_MASK,
+						 val, PHYREG6);
+
+			writel(PHYREG18_PLL_LOOP, priv->mmio + PHYREG18);
+			writel(PHYREG11_SU_TRIM_0_7, priv->mmio + PHYREG11);
+		} else if (priv->type == PHY_TYPE_SATA) {
 			/* downward spread spectrum +500ppm */
-			val = readl(priv->mmio + (0x1f << 2));
-			val &= ~GENMASK(7, 4);
-			val |= 0x50;
-			writel(val, priv->mmio + (0x1f << 2));
+			val = PHYREG32_SSC_DOWNWARD << PHYREG32_SSC_DIR_SHIFT;
+			val |= PHYREG32_SSC_OFFSET_500PPM << PHYREG32_SSC_OFFSET_SHIFT;
+			rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK, val, PHYREG32);
 		}
 		break;
+
 	default:
-		dev_err(priv->dev, "Unsupported rate: %lu\n", rate);
+		dev_err(priv->dev, "unsupported rate: %lu\n", rate);
 		return -EINVAL;
 	}
 
-	if (of_property_read_bool(np, "rockchip,ext-refclk")) {
-		param_write(priv->phy_grf, &cfg->pipe_clk_ext, true);
-		if (priv->mode == PHY_TYPE_PCIE && rate == 100000000) {
-			val = readl(priv->mmio + (0xc << 2));
-			val |= 0x3 << 4 | 0x1 << 7;
-			writel(val, priv->mmio + (0xc << 2));
+	if (priv->ext_refclk) {
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_ext, true);
+		if (priv->type == PHY_TYPE_PCIE && rate == REF_CLOCK_100MHz) {
+			val = PHYREG13_RESISTER_HIGH_Z << PHYREG13_RESISTER_SHIFT;
+			val |= PHYREG13_CKRCV_AMP0;
+			rockchip_combphy_updatel(priv, PHYREG13_RESISTER_MASK, val, PHYREG13);
 
-			val = readl(priv->mmio + (0xd << 2));
-			val |= 0x1;
-			writel(val, priv->mmio + (0xd << 2));
+			val = readl(priv->mmio + PHYREG14);
+			val |= PHYREG14_CKRCV_AMP1;
+			writel(val, priv->mmio + PHYREG14);
 		}
 	}
 
-	if (of_property_read_bool(np, "rockchip,enable-ssc")) {
-		val = readl(priv->mmio + (0x7 << 2));
-		val |= BIT(4);
-		writel(val, priv->mmio + (0x7 << 2));
+	if (priv->enable_ssc) {
+		val = readl(priv->mmio + PHYREG8);
+		val |= PHYREG8_SSC_EN;
+		writel(val, priv->mmio + PHYREG8);
 	}
 
 	return 0;
@@ -559,255 +594,241 @@ static const struct rockchip_combphy_grfcfg rk3568_combphy_grfcfgs = {
 	.con3_for_sata		= { 0x000c, 15, 0, 0x00, 0x4407 },
 	/* pipe-grf */
 	.pipe_con0_for_sata	= { 0x0000, 15, 0, 0x00, 0x2220 },
-	.pipe_sgmii_mac_sel	= { 0x0040, 1, 1, 0x00, 0x01 },
 	.pipe_xpcs_phy_ready	= { 0x0040, 2, 2, 0x00, 0x01 },
-	.u3otg0_port_en		= { 0x0104, 15, 0, 0x0181, 0x1100 },
-	.u3otg1_port_en		= { 0x0144, 15, 0, 0x0181, 0x1100 },
-};
-
-static const struct clk_bulk_data rk3568_clks[] = {
-	{ .id = "ref" },
-	{ .id = "apb" },
-	{ .id = "pipe" },
 };
 
 static const struct rockchip_combphy_cfg rk3568_combphy_cfgs = {
-	.num_clks	= ARRAY_SIZE(rk3568_clks),
-	.clks		= rk3568_clks,
+	.num_phys = 3,
+	.phy_ids = {
+		0xfe820000,
+		0xfe830000,
+		0xfe840000,
+	},
 	.grfcfg		= &rk3568_combphy_grfcfgs,
 	.combphy_cfg	= rk3568_combphy_cfg,
 };
 
-static int rk3588_combphy_cfg(struct rockchip_combphy_priv *priv)
+static int rk3576_combphy_cfg(struct rockchip_combphy_priv *priv)
 {
 	const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg;
-	struct clk *refclk = NULL;
 	unsigned long rate;
-	int i;
 	u32 val;
 
-	/* Configure PHY reference clock frequency */
-	for (i = 0; i < priv->num_clks; i++) {
-		if (!strncmp(priv->clks[i].id, "ref", 6)) {
-			refclk = priv->clks[i].clk;
-			break;
-		}
-	}
-
-	if (!refclk) {
-		dev_err(priv->dev, "No refclk found\n");
-		return -EINVAL;
-	}
-
-	switch (priv->mode) {
+	switch (priv->type) {
 	case PHY_TYPE_PCIE:
 		/* Set SSC downward spread spectrum */
-		val = readl(priv->mmio + (0x1f << 2));
-		val &= ~GENMASK(5, 4);
-		val |= 0x01 << 4;
-		writel(val, priv->mmio + 0x7c);
-
-		param_write(priv->phy_grf, &cfg->con0_for_pcie, true);
-		param_write(priv->phy_grf, &cfg->con1_for_pcie, true);
-		param_write(priv->phy_grf, &cfg->con2_for_pcie, true);
-		param_write(priv->phy_grf, &cfg->con3_for_pcie, true);
+		val = FIELD_PREP(PHYREG32_SSC_MASK, PHYREG32_SSC_DOWNWARD);
+		rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK, val, PHYREG32);
+
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con0_for_pcie, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con1_for_pcie, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con2_for_pcie, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con3_for_pcie, true);
 		break;
+
 	case PHY_TYPE_USB3:
 		/* Set SSC downward spread spectrum */
-		val = readl(priv->mmio + (0x1f << 2));
-		val &= ~GENMASK(5, 4);
-		val |= 0x01 << 4;
-		writel(val, priv->mmio + 0x7c);
+		val = FIELD_PREP(PHYREG32_SSC_MASK, PHYREG32_SSC_DOWNWARD);
+		rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK, val, PHYREG32);
 
 		/* Enable adaptive CTLE for USB3.0 Rx */
-		val = readl(priv->mmio + (0x0e << 2));
-		val &= ~GENMASK(0, 0);
-		val |= 0x01;
-		writel(val, priv->mmio + (0x0e << 2));
+		val = readl(priv->mmio + PHYREG15);
+		val |= PHYREG15_CTLE_EN;
+		writel(val, priv->mmio + PHYREG15);
 
 		/* Set PLL KVCO fine tuning signals */
-		val = readl(priv->mmio + (0x20 << 2));
-		val &= ~(0x7 << 2);
-		val |= 0x2 << 2;
-		writel(val, priv->mmio + (0x20 << 2));
+		rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK, BIT(3), PHYREG33);
 
 		/* Set PLL LPF R1 to su_trim[10:7]=1001 */
-		writel(0x4, priv->mmio + (0xb << 2));
+		writel(PHYREG12_PLL_LPF_ADJ_VALUE, priv->mmio + PHYREG12);
 
 		/* Set PLL input clock divider 1/2 */
-		val = readl(priv->mmio + (0x5 << 2));
-		val &= ~(0x3 << 6);
-		val |= 0x1 << 6;
-		writel(val, priv->mmio + (0x5 << 2));
+		val = FIELD_PREP(PHYREG6_PLL_DIV_MASK, PHYREG6_PLL_DIV_2);
+		rockchip_combphy_updatel(priv, PHYREG6_PLL_DIV_MASK, val, PHYREG6);
 
 		/* Set PLL loop divider */
-		writel(0x32, priv->mmio + (0x11 << 2));
+		writel(PHYREG18_PLL_LOOP, priv->mmio + PHYREG18);
 
 		/* Set PLL KVCO to min and set PLL charge pump current to max */
-		writel(0xf0, priv->mmio + (0xa << 2));
+		writel(PHYREG11_SU_TRIM_0_7, priv->mmio + PHYREG11);
 
 		/* Set Rx squelch input filler bandwidth */
-		writel(0x0d, priv->mmio + (0x14 << 2));
+		writel(PHYREG21_RX_SQUELCH_VAL, priv->mmio + PHYREG21);
 
-		param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false);
-		param_write(priv->phy_grf, &cfg->pipe_txelec_sel, false);
-		param_write(priv->phy_grf, &cfg->usb_mode_set, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txelec_sel, false);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->usb_mode_set, true);
 		break;
+
 	case PHY_TYPE_SATA:
 		/* Enable adaptive CTLE for SATA Rx */
-		val = readl(priv->mmio + (0x0e << 2));
-		val &= ~GENMASK(0, 0);
-		val |= 0x01;
-		writel(val, priv->mmio + (0x0e << 2));
+		val = readl(priv->mmio + PHYREG15);
+		val |= PHYREG15_CTLE_EN;
+		writel(val, priv->mmio + PHYREG15);
+
 		/* Set tx_rterm = 50 ohm and rx_rterm = 43.5 ohm */
-		writel(0x8F, priv->mmio + (0x06 << 2));
-
-		param_write(priv->phy_grf, &cfg->con0_for_sata, true);
-		param_write(priv->phy_grf, &cfg->con1_for_sata, true);
-		param_write(priv->phy_grf, &cfg->con2_for_sata, true);
-		param_write(priv->phy_grf, &cfg->con3_for_sata, true);
-		param_write(priv->pipe_grf, &cfg->pipe_con0_for_sata, true);
-		param_write(priv->pipe_grf, &cfg->pipe_con1_for_sata, true);
+		val = PHYREG7_TX_RTERM_50OHM << PHYREG7_TX_RTERM_SHIFT;
+		val |= PHYREG7_RX_RTERM_44OHM << PHYREG7_RX_RTERM_SHIFT;
+		writel(val, priv->mmio + PHYREG7);
+
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con0_for_sata, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con1_for_sata, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con2_for_sata, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con3_for_sata, true);
+		rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_con0_for_sata, true);
+		rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_con1_for_sata, true);
 		break;
-	case PHY_TYPE_SGMII:
-	case PHY_TYPE_QSGMII:
+
 	default:
 		dev_err(priv->dev, "incompatible PHY type\n");
 		return -EINVAL;
 	}
 
-	rate = clk_get_rate(refclk);
+	rate = clk_get_rate(priv->refclk);
 
 	switch (rate) {
-	case 24000000:
-		param_write(priv->phy_grf, &cfg->pipe_clk_24m, true);
-		if (priv->mode == PHY_TYPE_USB3 || priv->mode == PHY_TYPE_SATA) {
+	case REF_CLOCK_24MHz:
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_24m, true);
+		if (priv->type == PHY_TYPE_USB3 || priv->type == PHY_TYPE_SATA) {
 			/* Set ssc_cnt[9:0]=0101111101 & 31.5KHz */
-			val = readl(priv->mmio + (0x0e << 2));
-			val &= ~GENMASK(7, 6);
-			val |= 0x01 << 6;
-			writel(val, priv->mmio + (0x0e << 2));
-
-			val = readl(priv->mmio + (0x0f << 2));
-			val &= ~GENMASK(7, 0);
-			val |= 0x5f;
-			writel(val, priv->mmio + (0x0f << 2));
-		} else if (priv->mode == PHY_TYPE_PCIE) {
+			val = FIELD_PREP(PHYREG15_SSC_CNT_MASK, PHYREG15_SSC_CNT_VALUE);
+			rockchip_combphy_updatel(priv, PHYREG15_SSC_CNT_MASK,
+						 val, PHYREG15);
+
+			writel(PHYREG16_SSC_CNT_VALUE, priv->mmio + PHYREG16);
+		} else if (priv->type == PHY_TYPE_PCIE) {
 			/* PLL KVCO tuning fine */
-			val = readl(priv->mmio + (0x20 << 2));
-			val &= ~GENMASK(4, 2);
-			val |= 0x4 << 2;
-			writel(val, priv->mmio + (0x20 << 2));
-
-			/* Set up rx_trim */
-			val = 0x0;
-			writel(val, priv->mmio + (0x1b << 2));
-
-			/* Set up su_trim: T0_1 */
-			val = 0x90;
-			writel(val, priv->mmio + (0xa << 2));
-			val = 0x02;
-			writel(val, priv->mmio + (0xb << 2));
-			val = 0x57;
-			writel(val, priv->mmio + (0xd << 2));
-
-			val = 0x5f;
-			writel(val, priv->mmio + (0xf << 2));
+			val = FIELD_PREP(PHYREG33_PLL_KVCO_MASK, PHYREG33_PLL_KVCO_VALUE_RK3576);
+			rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK,
+						 val, PHYREG33);
+
+			/* Set up rx_pck invert and rx msb to disable */
+			writel(0x00, priv->mmio + PHYREG27);
+
+			/*
+			 * Set up SU adjust signal:
+			 * su_trim[7:0],   PLL KVCO adjust bits[2:0] to min
+			 * su_trim[15:8],  PLL LPF R1 adujst bits[9:7]=3'b011
+			 * su_trim[31:24], CKDRV adjust
+			 */
+			writel(0x90, priv->mmio + PHYREG11);
+			writel(0x02, priv->mmio + PHYREG12);
+			writel(0x57, priv->mmio + PHYREG14);
+
+			writel(PHYREG16_SSC_CNT_VALUE, priv->mmio + PHYREG16);
 		}
 		break;
-	case 25000000:
-		param_write(priv->phy_grf, &cfg->pipe_clk_25m, true);
+
+	case REF_CLOCK_25MHz:
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_25m, true);
 		break;
-	case 100000000:
-		param_write(priv->phy_grf, &cfg->pipe_clk_100m, true);
-		if (priv->mode == PHY_TYPE_PCIE) {
+
+	case REF_CLOCK_100MHz:
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_100m, true);
+		if (priv->type == PHY_TYPE_PCIE) {
 			/* gate_tx_pck_sel length select work for L1SS */
-			val = 0xc0;
-			writel(val, priv->mmio + 0x74);
+			writel(0xc0, priv->mmio + PHYREG30);
 
 			/* PLL KVCO tuning fine */
-			val = readl(priv->mmio + (0x20 << 2));
-			val &= ~GENMASK(4, 2);
-			val |= 0x4 << 2;
-			writel(val, priv->mmio + (0x20 << 2));
+			val = FIELD_PREP(PHYREG33_PLL_KVCO_MASK, PHYREG33_PLL_KVCO_VALUE_RK3576);
+			rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK,
+						 val, PHYREG33);
 
 			/* Set up rx_trim: PLL LPF C1 85pf R1 1.25kohm */
-			val = 0x4c;
-			writel(val, priv->mmio + (0x1b << 2));
-
-			/* Set up su_trim: T3_P1 650mv */
-			val = 0x90;
-			writel(val, priv->mmio + (0xa << 2));
-			val = 0x43;
-			writel(val, priv->mmio + (0xb << 2));
-			val = 0x88;
-			writel(val, priv->mmio + (0xc << 2));
-			val = 0x56;
-			writel(val, priv->mmio + (0xd << 2));
-		} else if (priv->mode == PHY_TYPE_SATA) {
+			writel(0x4c, priv->mmio + PHYREG27);
+
+			/*
+			 * Set up SU adjust signal:
+			 * su_trim[7:0],   PLL KVCO adjust bits[2:0] to min
+			 * su_trim[15:8],  bypass PLL loop divider code, and
+			 *                 PLL LPF R1 adujst bits[9:7]=3'b101
+			 * su_trim[23:16], CKRCV adjust
+			 * su_trim[31:24], CKDRV adjust
+			 */
+			writel(0x90, priv->mmio + PHYREG11);
+			writel(0x43, priv->mmio + PHYREG12);
+			writel(0x88, priv->mmio + PHYREG13);
+			writel(0x56, priv->mmio + PHYREG14);
+		} else if (priv->type == PHY_TYPE_SATA) {
 			/* downward spread spectrum +500ppm */
-			val = readl(priv->mmio + (0x1f << 2));
-			val &= ~GENMASK(7, 4);
-			val |= 0x50;
-			writel(val, priv->mmio + (0x1f << 2));
+			val = FIELD_PREP(PHYREG32_SSC_DIR_MASK, PHYREG32_SSC_DOWNWARD);
+			val |= FIELD_PREP(PHYREG32_SSC_OFFSET_MASK, PHYREG32_SSC_OFFSET_500PPM);
+			rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK, val, PHYREG32);
 
 			/* ssc ppm adjust to 3500ppm */
-			val = readl(priv->mmio + (0x9 << 2));
-			val &= ~GENMASK(3, 0);
-			val |= 0x7;
-			writel(val, priv->mmio + (0x9 << 2));
+			rockchip_combphy_updatel(priv, PHYREG10_SSC_PCM_MASK,
+						 PHYREG10_SSC_PCM_3500PPM,
+						 PHYREG10);
 		}
 		break;
+
 	default:
 		dev_err(priv->dev, "Unsupported rate: %lu\n", rate);
 		return -EINVAL;
 	}
 
-	if (of_property_read_bool(priv->dev->of_node, "rockchip,ext-refclk")) {
-		param_write(priv->phy_grf, &cfg->pipe_clk_ext, true);
-		if (priv->mode == PHY_TYPE_PCIE && rate == 100000000) {
-			val = 0x10;
-			writel(val, priv->mmio + (0x20 << 2));
-
-			val = 0x0c;
-			writel(val, priv->mmio + (0x1b << 2));
-
-			/* Set up su_trim: T3_P1 650mv */
-			val = 0x90;
-			writel(val, priv->mmio + (0xa << 2));
-			val = 0x43;
-			writel(val, priv->mmio + (0xb << 2));
-			val = 0x88;
-			writel(val, priv->mmio + (0xc << 2));
-			val = 0x56;
-			writel(val, priv->mmio + (0xd << 2));
+	if (priv->ext_refclk) {
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_ext, true);
+		if (priv->type == PHY_TYPE_PCIE && rate == REF_CLOCK_100MHz) {
+			val = FIELD_PREP(PHYREG33_PLL_KVCO_MASK, PHYREG33_PLL_KVCO_VALUE_RK3576);
+			rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK,
+						 val, PHYREG33);
+
+			/* Set up rx_trim: PLL LPF C1 85pf R1 2.5kohm */
+			writel(0x0c, priv->mmio + PHYREG27);
+
+			/*
+			 * Set up SU adjust signal:
+			 * su_trim[7:0],   PLL KVCO adjust bits[2:0] to min
+			 * su_trim[15:8],  bypass PLL loop divider code, and
+			 *                 PLL LPF R1 adujst bits[9:7]=3'b101.
+			 * su_trim[23:16], CKRCV adjust
+			 * su_trim[31:24], CKDRV adjust
+			 */
+			writel(0x90, priv->mmio + PHYREG11);
+			writel(0x43, priv->mmio + PHYREG12);
+			writel(0x88, priv->mmio + PHYREG13);
+			writel(0x56, priv->mmio + PHYREG14);
 		}
 	}
 
-	if (of_property_read_bool(priv->dev->of_node, "rockchip,enable-ssc")) {
-		val = readl(priv->mmio + (0x7 << 2));
-		val |= BIT(4);
-		writel(val, priv->mmio + (0x7 << 2));
-
-		if (priv->mode == PHY_TYPE_PCIE && rate == 24000000) {
-			/* Xin24M T0_1 650mV */
-			writel(0x00, priv->mmio + (0x10 << 2));
-			writel(0x32, priv->mmio + (0x11 << 2));
-			writel(0x00, priv->mmio + (0x1b << 2));
-			writel(0x90, priv->mmio + (0x0a << 2));
-			writel(0x02, priv->mmio + (0x0b << 2));
-			writel(0x08, priv->mmio + (0x0c << 2));
-			writel(0x57, priv->mmio + (0x0d << 2));
-			writel(0x40, priv->mmio + (0x0e << 2));
-			writel(0x5f, priv->mmio + (0x0f << 2));
-			writel(0x10, priv->mmio + (0x20 << 2));
+	if (priv->enable_ssc) {
+		val = readl(priv->mmio + PHYREG8);
+		val |= PHYREG8_SSC_EN;
+		writel(val, priv->mmio + PHYREG8);
+
+		if (priv->type == PHY_TYPE_PCIE && rate == REF_CLOCK_24MHz) {
+			/* Set PLL loop divider */
+			writel(0x00, priv->mmio + PHYREG17);
+			writel(PHYREG18_PLL_LOOP, priv->mmio + PHYREG18);
+
+			/* Set up rx_pck invert and rx msb to disable */
+			writel(0x00, priv->mmio + PHYREG27);
+
+			/*
+			 * Set up SU adjust signal:
+			 * su_trim[7:0],   PLL KVCO adjust bits[2:0] to min
+			 * su_trim[15:8],  PLL LPF R1 adujst bits[9:7]=3'b101
+			 * su_trim[23:16], CKRCV adjust
+			 * su_trim[31:24], CKDRV adjust
+			 */
+			writel(0x90, priv->mmio + PHYREG11);
+			writel(0x02, priv->mmio + PHYREG12);
+			writel(0x08, priv->mmio + PHYREG13);
+			writel(0x57, priv->mmio + PHYREG14);
+			writel(0x40, priv->mmio + PHYREG15);
+
+			writel(PHYREG16_SSC_CNT_VALUE, priv->mmio + PHYREG16);
+
+			val = FIELD_PREP(PHYREG33_PLL_KVCO_MASK, PHYREG33_PLL_KVCO_VALUE_RK3576);
+			writel(val, priv->mmio + PHYREG33);
 		}
 	}
 
 	return 0;
 }
 
-static const struct rockchip_combphy_grfcfg rk3588_combphy_grfcfgs = {
+static const struct rockchip_combphy_grfcfg rk3576_combphy_grfcfgs = {
 	/* pipe-phy-grf */
 	.pcie_mode_set		= { 0x0000, 5, 0, 0x00, 0x11 },
 	.usb_mode_set		= { 0x0000, 5, 0, 0x00, 0x04 },
@@ -817,6 +838,8 @@ static const struct rockchip_combphy_grfcfg rk3588_combphy_grfcfgs = {
 	.pipe_clk_24m		= { 0x0004, 14, 13, 0x00, 0x00 },
 	.pipe_clk_25m		= { 0x0004, 14, 13, 0x00, 0x01 },
 	.pipe_clk_100m		= { 0x0004, 14, 13, 0x00, 0x02 },
+	.pipe_phymode_sel	= { 0x0008, 1, 1, 0x00, 0x01 },
+	.pipe_rate_sel		= { 0x0008, 2, 2, 0x00, 0x01 },
 	.pipe_rxterm_sel	= { 0x0008, 8, 8, 0x00, 0x01 },
 	.pipe_txelec_sel	= { 0x0008, 12, 12, 0x00, 0x01 },
 	.pipe_txcomp_sel	= { 0x0008, 15, 15, 0x00, 0x01 },
@@ -830,31 +853,217 @@ static const struct rockchip_combphy_grfcfg rk3588_combphy_grfcfgs = {
 	.con1_for_sata		= { 0x0004, 15, 0, 0x00, 0x0000 },
 	.con2_for_sata		= { 0x0008, 15, 0, 0x00, 0x80c1 },
 	.con3_for_sata		= { 0x000c, 15, 0, 0x00, 0x0407 },
-	/* pipe-grf */
-	.pipe_con0_for_sata	= { 0x0000, 11, 5, 0x00, 0x22 },
-	.pipe_con1_for_sata	= { 0x0004, 2, 0, 0x00, 0x2 },
+	/* php-grf */
+	.pipe_con0_for_sata	= { 0x001C, 2, 0, 0x00, 0x2 },
+	.pipe_con1_for_sata	= { 0x0020, 2, 0, 0x00, 0x2 },
 };
 
+static const struct rockchip_combphy_cfg rk3576_combphy_cfgs = {
+	.num_phys = 2,
+	.phy_ids = {
+		0x2b050000,
+		0x2b060000
+	},
+	.grfcfg		= &rk3576_combphy_grfcfgs,
+	.combphy_cfg	= rk3576_combphy_cfg,
+};
+
+static int rk3588_combphy_cfg(struct rockchip_combphy_priv *priv)
+{
+	const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg;
+	unsigned long rate;
+	u32 val;
 
-static const struct clk_bulk_data rk3588_clks[] = {
-	{ .id = "ref" },
-	{ .id = "apb" },
-	{ .id = "pipe" },
+	switch (priv->type) {
+	case PHY_TYPE_PCIE:
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con0_for_pcie, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con1_for_pcie, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con2_for_pcie, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con3_for_pcie, true);
+		switch (priv->id) {
+		case 1:
+			rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_pcie1l0_sel, true);
+			break;
+		case 2:
+			rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_pcie1l1_sel, true);
+			break;
+		}
+		break;
+	case PHY_TYPE_USB3:
+		/* Set SSC downward spread spectrum */
+		rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK,
+					 PHYREG32_SSC_DOWNWARD << PHYREG32_SSC_DIR_SHIFT,
+					 PHYREG32);
+
+		/* Enable adaptive CTLE for USB3.0 Rx. */
+		val = readl(priv->mmio + PHYREG15);
+		val |= PHYREG15_CTLE_EN;
+		writel(val, priv->mmio + PHYREG15);
+
+		/* Set PLL KVCO fine tuning signals. */
+		rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK,
+					 PHYREG33_PLL_KVCO_VALUE << PHYREG33_PLL_KVCO_SHIFT,
+					 PHYREG33);
+
+		/* Enable controlling random jitter. */
+		writel(PHYREG12_PLL_LPF_ADJ_VALUE, priv->mmio + PHYREG12);
+
+		/* Set PLL input clock divider 1/2. */
+		rockchip_combphy_updatel(priv, PHYREG6_PLL_DIV_MASK,
+					 PHYREG6_PLL_DIV_2 << PHYREG6_PLL_DIV_SHIFT,
+					 PHYREG6);
+
+		writel(PHYREG18_PLL_LOOP, priv->mmio + PHYREG18);
+		writel(PHYREG11_SU_TRIM_0_7, priv->mmio + PHYREG11);
+
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txelec_sel, false);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->usb_mode_set, true);
+		break;
+	case PHY_TYPE_SATA:
+		/* Enable adaptive CTLE for SATA Rx. */
+		val = readl(priv->mmio + PHYREG15);
+		val |= PHYREG15_CTLE_EN;
+		writel(val, priv->mmio + PHYREG15);
+		/*
+		 * Set tx_rterm=50ohm and rx_rterm=44ohm for SATA.
+		 * 0: 60ohm, 8: 50ohm 15: 44ohm (by step abort 1ohm)
+		 */
+		val = PHYREG7_TX_RTERM_50OHM << PHYREG7_TX_RTERM_SHIFT;
+		val |= PHYREG7_RX_RTERM_44OHM << PHYREG7_RX_RTERM_SHIFT;
+		writel(val, priv->mmio + PHYREG7);
+
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con0_for_sata, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con1_for_sata, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con2_for_sata, true);
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->con3_for_sata, true);
+		rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_con0_for_sata, true);
+		rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_con1_for_sata, true);
+		break;
+	case PHY_TYPE_SGMII:
+	case PHY_TYPE_QSGMII:
+	default:
+		dev_err(priv->dev, "incompatible PHY type\n");
+		return -EINVAL;
+	}
+
+	rate = clk_get_rate(priv->refclk);
+
+	switch (rate) {
+	case REF_CLOCK_24MHz:
+		if (priv->type == PHY_TYPE_USB3 || priv->type == PHY_TYPE_SATA) {
+			/* Set ssc_cnt[9:0]=0101111101 & 31.5KHz. */
+			val = PHYREG15_SSC_CNT_VALUE << PHYREG15_SSC_CNT_SHIFT;
+			rockchip_combphy_updatel(priv, PHYREG15_SSC_CNT_MASK,
+						 val, PHYREG15);
+
+			writel(PHYREG16_SSC_CNT_VALUE, priv->mmio + PHYREG16);
+		}
+		break;
+
+	case REF_CLOCK_25MHz:
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_25m, true);
+		break;
+	case REF_CLOCK_100MHz:
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_100m, true);
+		if (priv->type == PHY_TYPE_PCIE) {
+			/* PLL KVCO fine tuning. */
+			val = 4 << PHYREG33_PLL_KVCO_SHIFT;
+			rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK,
+						 val, PHYREG33);
+
+			/* Enable controlling random jitter. */
+			writel(PHYREG12_PLL_LPF_ADJ_VALUE, priv->mmio + PHYREG12);
+
+			/* Set up rx_trim: PLL LPF C1 85pf R1 1.25kohm */
+			writel(PHYREG27_RX_TRIM_RK3588, priv->mmio + PHYREG27);
+
+			/* Set up su_trim:  */
+			writel(PHYREG11_SU_TRIM_0_7, priv->mmio + PHYREG11);
+		} else if (priv->type == PHY_TYPE_SATA) {
+			/* downward spread spectrum +500ppm */
+			val = PHYREG32_SSC_DOWNWARD << PHYREG32_SSC_DIR_SHIFT;
+			val |= PHYREG32_SSC_OFFSET_500PPM << PHYREG32_SSC_OFFSET_SHIFT;
+			rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK, val, PHYREG32);
+		}
+		break;
+	default:
+		dev_err(priv->dev, "Unsupported rate: %lu\n", rate);
+		return -EINVAL;
+	}
+
+	if (priv->ext_refclk) {
+		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_ext, true);
+		if (priv->type == PHY_TYPE_PCIE && rate == REF_CLOCK_100MHz) {
+			val = PHYREG13_RESISTER_HIGH_Z << PHYREG13_RESISTER_SHIFT;
+			val |= PHYREG13_CKRCV_AMP0;
+			rockchip_combphy_updatel(priv, PHYREG13_RESISTER_MASK, val, PHYREG13);
+
+			val = readl(priv->mmio + PHYREG14);
+			val |= PHYREG14_CKRCV_AMP1;
+			writel(val, priv->mmio + PHYREG14);
+		}
+	}
+
+	if (priv->enable_ssc) {
+		val = readl(priv->mmio + PHYREG8);
+		val |= PHYREG8_SSC_EN;
+		writel(val, priv->mmio + PHYREG8);
+	}
+
+	return 0;
+}
+
+static const struct rockchip_combphy_grfcfg rk3588_combphy_grfcfgs = {
+	/* pipe-phy-grf */
+	.pcie_mode_set		= { 0x0000, 5, 0, 0x00, 0x11 },
+	.usb_mode_set		= { 0x0000, 5, 0, 0x00, 0x04 },
+	.pipe_rxterm_set	= { 0x0000, 12, 12, 0x00, 0x01 },
+	.pipe_txelec_set	= { 0x0004, 1, 1, 0x00, 0x01 },
+	.pipe_txcomp_set	= { 0x0004, 4, 4, 0x00, 0x01 },
+	.pipe_clk_25m		= { 0x0004, 14, 13, 0x00, 0x01 },
+	.pipe_clk_100m		= { 0x0004, 14, 13, 0x00, 0x02 },
+	.pipe_rxterm_sel	= { 0x0008, 8, 8, 0x00, 0x01 },
+	.pipe_txelec_sel	= { 0x0008, 12, 12, 0x00, 0x01 },
+	.pipe_txcomp_sel	= { 0x0008, 15, 15, 0x00, 0x01 },
+	.pipe_clk_ext		= { 0x000c, 9, 8, 0x02, 0x01 },
+	.pipe_phy_status	= { 0x0034, 6, 6, 0x01, 0x00 },
+	.con0_for_pcie		= { 0x0000, 15, 0, 0x00, 0x1000 },
+	.con1_for_pcie		= { 0x0004, 15, 0, 0x00, 0x0000 },
+	.con2_for_pcie		= { 0x0008, 15, 0, 0x00, 0x0101 },
+	.con3_for_pcie		= { 0x000c, 15, 0, 0x00, 0x0200 },
+	.con0_for_sata		= { 0x0000, 15, 0, 0x00, 0x0129 },
+	.con1_for_sata		= { 0x0004, 15, 0, 0x00, 0x0000 },
+	.con2_for_sata		= { 0x0008, 15, 0, 0x00, 0x80c1 },
+	.con3_for_sata		= { 0x000c, 15, 0, 0x00, 0x0407 },
+	/* pipe-grf */
+	.pipe_con0_for_sata	= { 0x0000, 11, 5, 0x00, 0x22 },
+	.pipe_con1_for_sata	= { 0x0000, 2, 0, 0x00, 0x2 },
+	.pipe_pcie1l0_sel	= { 0x0100, 0, 0, 0x01, 0x0 },
+	.pipe_pcie1l1_sel	= { 0x0100, 1, 1, 0x01, 0x0 },
 };
 
 static const struct rockchip_combphy_cfg rk3588_combphy_cfgs = {
-	.num_clks	= ARRAY_SIZE(rk3588_clks),
-	.clks		= rk3588_clks,
+	.num_phys = 3,
+	.phy_ids = {
+		0xfee00000,
+		0xfee10000,
+		0xfee20000,
+	},
 	.grfcfg		= &rk3588_combphy_grfcfgs,
 	.combphy_cfg	= rk3588_combphy_cfg,
-	.force_det_out	= true,
 };
 
 static const struct of_device_id rockchip_combphy_of_match[] = {
 	{
 		.compatible = "rockchip,rk3568-naneng-combphy",
 		.data = &rk3568_combphy_cfgs,
-	}, {
+	},
+	{
+		.compatible = "rockchip,rk3576-naneng-combphy",
+		.data = &rk3576_combphy_cfgs,
+	},
+	{
 		.compatible = "rockchip,rk3588-naneng-combphy",
 		.data = &rk3588_combphy_cfgs,
 	},
-- 
2.38.2



From a.fatoum at pengutronix.de  Thu Mar 27 07:47:38 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 15:47:38 +0100
Subject: [PATCH 0/4] ci: fix sandbox allyesconfig build
Message-ID: <20250327144742.1841423-1-a.fatoum@pengutronix.de>

With these changes applied, the most recent container image can be used
to run the pytest tests for allyesconfig.

Ahmad Fatoum (4):
  sandbox: env: switch from CONFIG_DEFAULT_ENVIRONMENT_PATH to bbenv-y
  test: bthread: change comparison condition for switches vs. yields
  ci: pytest: rename build directories
  ci: pytest: enable console and libc allocator for allyesconfig

 .github/workflows/test-labgrid-pytest.yml        | 16 ++++++++++------
 arch/sandbox/board/Makefile                      |  1 +
 arch/sandbox/board/board.c                       |  3 +++
 .../{env => defaultenv-sandbox}/network/eth0     |  0
 .../{env => defaultenv-sandbox}/nv/autoboot      |  0
 arch/sandbox/configs/sandbox_defconfig           |  2 +-
 test/py/test_bthread.py                          |  3 ++-
 7 files changed, 17 insertions(+), 8 deletions(-)
 rename arch/sandbox/board/{env => defaultenv-sandbox}/network/eth0 (100%)
 rename arch/sandbox/board/{env => defaultenv-sandbox}/nv/autoboot (100%)

-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 27 07:47:40 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 15:47:40 +0100
Subject: [PATCH 2/4] test: bthread: change comparison condition for switches vs. yields
In-Reply-To: <20250327144742.1841423-1-a.fatoum@pengutronix.de>
References: <20250327144742.1841423-1-a.fatoum@pengutronix.de>
Message-ID: <20250327144742.1841423-3-a.fatoum@pengutronix.de>

The code was written with the assumption that isolated yields from test
thread to main thread and back will always be at least as fast as
unrestricted scheduling.

This assumption held so far, but breaks down in sandbox, because it's
highly influenced by the system's CPU pressure.

Just check that we can schedule @1000Hz at least in both cases.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/py/test_bthread.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/py/test_bthread.py b/test/py/test_bthread.py
index 6e7b4ba5007e..84fb9f830b0c 100644
--- a/test/py/test_bthread.py
+++ b/test/py/test_bthread.py
@@ -20,4 +20,5 @@ def test_bthread(barebox, barebox_config):
     switches = int(barebox.run_check("bthread -c")[0].split()[0])
     yields   = int(barebox.run_check("bthread -t")[0].split()[0])
 
-    assert yields < switches
+    assert yields > 1000
+    assert yields > 1000
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 27 07:47:42 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 15:47:42 +0100
Subject: [PATCH 4/4] ci: pytest: enable console and libc allocator for allyesconfig
In-Reply-To: <20250327144742.1841423-1-a.fatoum@pengutronix.de>
References: <20250327144742.1841423-1-a.fatoum@pengutronix.de>
Message-ID: <20250327144742.1841423-5-a.fatoum@pengutronix.de>

These two option are already set in the pytest YAML, but we build and
run tests in two separate stages and thus they are never applied.

Combining build and test into one doesn't play nicely with our
structure, because we build e.g. multi_v7_defconfig once and then run
multiple tests on it.

Let's workaround this in the build stage for now.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 .github/workflows/test-labgrid-pytest.yml | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/test-labgrid-pytest.yml b/.github/workflows/test-labgrid-pytest.yml
index bfb022dc7778..315868779bee 100644
--- a/.github/workflows/test-labgrid-pytest.yml
+++ b/.github/workflows/test-labgrid-pytest.yml
@@ -67,11 +67,14 @@ jobs:
       run: |
         export KBUILD_OUTPUT=build-${{matrix.arch}}-${{matrix.defconfig}}
         export ARCH=${{matrix.arch}}
+        export KCONFIG_ADD="common/boards/configs/enable_self_test.config \
+                            common/boards/configs/disable_target_tools.config"
 
-        ./MAKEALL -O ${KBUILD_OUTPUT} -l "" -v 0 \
-                -k common/boards/configs/enable_self_test.config \
-                -k common/boards/configs/disable_target_tools.config \
-                ${{matrix.defconfig}}
+        if [ ${{matrix.arch}} = sandbox ] && [ ${{matrix.defconfig}} = allyesconfig ]; then
+          KCONFIG_ADD="${KCONFIG_ADD} CONFIG_CONSOLE_DISABLE_INPUT=n CONFIG_MALLOC_LIBC=y"
+        fi
+
+        ./MAKEALL -O ${KBUILD_OUTPUT} -l "" -v 0 ${{matrix.defconfig}}
 
         if [ ${{matrix.arch}} = "riscv" ]; then
           cp /usr/share/qemu/opensbi-riscv32-generic-fw_dynamic.bin ${KBUILD_OUTPUT}/
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 27 07:47:39 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 15:47:39 +0100
Subject: [PATCH 1/4] sandbox: env: switch from CONFIG_DEFAULT_ENVIRONMENT_PATH to bbenv-y
In-Reply-To: <20250327144742.1841423-1-a.fatoum@pengutronix.de>
References: <20250327144742.1841423-1-a.fatoum@pengutronix.de>
Message-ID: <20250327144742.1841423-2-a.fatoum@pengutronix.de>

By moving it out of the config, the sandbox default environment is always
there, even when building allyesconfig.

This introduces no functional change for sandbox_defconfig, but
is useful as we start running tests against allyesconfig and want
the same environment (autoboot abortion by default) in any case.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/board/Makefile                                 | 1 +
 arch/sandbox/board/board.c                                  | 3 +++
 arch/sandbox/board/{env => defaultenv-sandbox}/network/eth0 | 0
 arch/sandbox/board/{env => defaultenv-sandbox}/nv/autoboot  | 0
 arch/sandbox/configs/sandbox_defconfig                      | 2 +-
 5 files changed, 5 insertions(+), 1 deletion(-)
 rename arch/sandbox/board/{env => defaultenv-sandbox}/network/eth0 (100%)
 rename arch/sandbox/board/{env => defaultenv-sandbox}/nv/autoboot (100%)

diff --git a/arch/sandbox/board/Makefile b/arch/sandbox/board/Makefile
index 029bfe7ff163..2b6346f6098d 100644
--- a/arch/sandbox/board/Makefile
+++ b/arch/sandbox/board/Makefile
@@ -12,6 +12,7 @@ obj-y += dev-random.o
 obj-y += watchdog.o
 obj-$(CONFIG_CMD_SANDBOX_CPUINFO) += cpuinfo.o
 obj-$(CONFIG_LED) += led.o
+bbenv-y += defaultenv-sandbox
 
 extra-y += barebox.lds
 
diff --git a/arch/sandbox/board/board.c b/arch/sandbox/board/board.c
index c8d1c99897f5..58a7b8c96f62 100644
--- a/arch/sandbox/board/board.c
+++ b/arch/sandbox/board/board.c
@@ -15,6 +15,7 @@
  */
 
 #include <common.h>
+#include <envfs.h>
 #include <driver.h>
 #include <malloc.h>
 #include <mach/linux.h>
@@ -59,6 +60,8 @@ static int devices_init(struct device *dev)
 
 	platform_device_register(&devrandom_device);
 
+	defaultenv_append_directory(defaultenv_sandbox);
+
 	return 0;
 }
 
diff --git a/arch/sandbox/board/env/network/eth0 b/arch/sandbox/board/defaultenv-sandbox/network/eth0
similarity index 100%
rename from arch/sandbox/board/env/network/eth0
rename to arch/sandbox/board/defaultenv-sandbox/network/eth0
diff --git a/arch/sandbox/board/env/nv/autoboot b/arch/sandbox/board/defaultenv-sandbox/nv/autoboot
similarity index 100%
rename from arch/sandbox/board/env/nv/autoboot
rename to arch/sandbox/board/defaultenv-sandbox/nv/autoboot
diff --git a/arch/sandbox/configs/sandbox_defconfig b/arch/sandbox/configs/sandbox_defconfig
index 251af8d0ef31..4cc9d9982c1a 100644
--- a/arch/sandbox/configs/sandbox_defconfig
+++ b/arch/sandbox/configs/sandbox_defconfig
@@ -9,7 +9,7 @@ CONFIG_PARTITION_DISK_EFI=y
 CONFIG_DEFAULT_COMPRESSION_GZIP=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_REBOOT_MODE=y
-CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/sandbox/board/env"
+CONFIG_DEFAULT_ENVIRONMENT_PATH=""
 CONFIG_STATE=y
 CONFIG_STATE_CRYPTO=y
 CONFIG_RESET_SOURCE=y
-- 
2.39.5



From a.fatoum at pengutronix.de  Thu Mar 27 07:47:41 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 27 Mar 2025 15:47:41 +0100
Subject: [PATCH 3/4] ci: pytest: rename build directories
In-Reply-To: <20250327144742.1841423-1-a.fatoum@pengutronix.de>
References: <20250327144742.1841423-1-a.fatoum@pengutronix.de>
Message-ID: <20250327144742.1841423-4-a.fatoum@pengutronix.de>

Naming the build directory after the arch means that multiple jobs will
each create a build-arm directory with different contents.

Let's factor in the name of the defconfig too, so it's
immediately clear what's what.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 .github/workflows/test-labgrid-pytest.yml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/test-labgrid-pytest.yml b/.github/workflows/test-labgrid-pytest.yml
index e1ccac67932f..bfb022dc7778 100644
--- a/.github/workflows/test-labgrid-pytest.yml
+++ b/.github/workflows/test-labgrid-pytest.yml
@@ -65,19 +65,20 @@ jobs:
 
     - name: Build
       run: |
+        export KBUILD_OUTPUT=build-${{matrix.arch}}-${{matrix.defconfig}}
         export ARCH=${{matrix.arch}}
 
-        ./MAKEALL -O build-${{matrix.arch}} -l "" -v 0 \
+        ./MAKEALL -O ${KBUILD_OUTPUT} -l "" -v 0 \
                 -k common/boards/configs/enable_self_test.config \
                 -k common/boards/configs/disable_target_tools.config \
                 ${{matrix.defconfig}}
 
         if [ ${{matrix.arch}} = "riscv" ]; then
-          cp /usr/share/qemu/opensbi-riscv32-generic-fw_dynamic.bin build-${{matrix.arch}}
+          cp /usr/share/qemu/opensbi-riscv32-generic-fw_dynamic.bin ${KBUILD_OUTPUT}/
         fi
     - name: labgrid-pytest
       run: |
-        export KBUILD_OUTPUT=build-${{matrix.arch}}
+        export KBUILD_OUTPUT=build-${{matrix.arch}}-${{matrix.defconfig}}
 
         for i in ${{matrix.lgenv}}; do
           grep -wq '\(QEMUDriver\|ExternalConsoleDriver\):' "$i" || continue
-- 
2.39.5



From eagle.alexander923 at gmail.com  Thu Mar 27 23:31:21 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Fri, 28 Mar 2025 09:31:21 +0300
Subject: [PATCH 1/2] regulator: core: Implement regulator_is_enabled() call
Message-ID: <20250328063122.36276-1-eagle.alexander923@gmail.com>

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 drivers/regulator/core.c | 11 +++++++++++
 include/regulator.h      |  6 ++++++
 2 files changed, 17 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 2c3b009ea6..c9e30ab3fd 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -610,6 +610,17 @@ int regulator_disable(struct regulator *r)
 	return regulator_disable_rdev(r->rdev);
 }
 
+int regulator_is_enabled(struct regulator *r)
+{
+	if (!r)
+		return 0;
+
+	if (r->rdev->always_on)
+		return 1;
+
+	return r->rdev->enable_count;
+}
+
 int regulator_set_voltage(struct regulator *r, int min_uV, int max_uV)
 {
 	if (!r)
diff --git a/include/regulator.h b/include/regulator.h
index 9785b8ac07..5fdf1602dd 100644
--- a/include/regulator.h
+++ b/include/regulator.h
@@ -217,6 +217,7 @@ void regulator_put(struct regulator *r);
 struct regulator *regulator_get_name(const char *name);
 int regulator_enable(struct regulator *);
 int regulator_disable(struct regulator *);
+int regulator_is_enabled(struct regulator *);
 int regulator_is_enabled_regmap(struct regulator_dev *);
 int regulator_enable_regmap(struct regulator_dev *);
 int regulator_disable_regmap(struct regulator_dev *);
@@ -285,6 +286,11 @@ static inline int regulator_disable(struct regulator *r)
 	return 0;
 }
 
+static inline int regulator_is_enabled(struct regulator *r)
+{
+	return 0;
+}
+
 static inline int regulator_set_voltage(struct regulator *regulator,
 					int min_uV, int max_uV)
 {
-- 
2.39.1



From eagle.alexander923 at gmail.com  Thu Mar 27 23:31:22 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Fri, 28 Mar 2025 09:31:22 +0300
Subject: [PATCH 2/2] gpio: clk-gpio: Updating the driver from the kernel repository
In-Reply-To: <20250328063122.36276-1-eagle.alexander923@gmail.com>
References: <20250328063122.36276-1-eagle.alexander923@gmail.com>
Message-ID: <20250328063122.36276-2-eagle.alexander923@gmail.com>

This patch replaces the driver code from the Linux kernel repository,
adding new driver variants gpio-mux-clock and gated-fixed-clock.

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 drivers/clk/clk-gpio.c | 337 ++++++++++++++++++++++++++++++++---------
 1 file changed, 264 insertions(+), 73 deletions(-)

diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c
index 940a20523e..325d523921 100644
--- a/drivers/clk/clk-gpio.c
+++ b/drivers/clk/clk-gpio.c
@@ -1,121 +1,312 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-License-Identifier: GPL-2.0
 /*
- * clk-gpio.c - clock that can be enabled and disabled via GPIO output
- * Based on Linux clk support
+ * Copyright (C) 2013 - 2014 Texas Instruments Incorporated - https://www.ti.com
  *
- * Copyright (c) 2018 Nikita Yushchenko <nikita.yoush at cogentembedded.com>
+ * Authors:
+ *    Jyri Sarha <jsarha at ti.com>
+ *    Sergej Sawazki <ce3a at gmx.de>
+ *
+ * Gpio controlled clock implementation
  */
+
 #include <common.h>
-#include <malloc.h>
+#include <regulator.h>
 #include <linux/clk.h>
+#include <linux/clk-provider.h>
 #include <linux/err.h>
-#include <gpio.h>
-#include <of_gpio.h>
-#include <init.h>
+#include <linux/gpio/consumer.h>
 
+/**
+ * struct clk_gpio - gpio gated clock
+ *
+ * @hw:		handle between common and hardware-specific interfaces
+ * @gpiod:	gpio descriptor
+ *
+ * Clock with a gpio control for enabling and disabling the parent clock
+ * or switching between two parents by asserting or deasserting the gpio.
+ *
+ * Implements .enable, .disable and .is_enabled or
+ * .get_parent, .set_parent and .determine_rate depending on which clk_ops
+ * is used.
+ */
 struct clk_gpio {
-	struct clk_hw hw;
-	const char *parent;
-	int gpio;
+	struct clk_hw	hw;
+	struct gpio_desc *gpiod;
 };
+
 #define to_clk_gpio(_hw) container_of(_hw, struct clk_gpio, hw)
 
-static int clk_gpio_enable(struct clk_hw *hw)
+static int clk_gpio_gate_enable(struct clk_hw *hw)
 {
-	struct clk_gpio *clk_gpio = to_clk_gpio(hw);
+	struct clk_gpio *clk = to_clk_gpio(hw);
+
+	gpiod_set_value(clk->gpiod, 1);
 
-	gpio_set_active(clk_gpio->gpio, true);
 	return 0;
 }
 
-static void clk_gpio_disable(struct clk_hw *hw)
+static void clk_gpio_gate_disable(struct clk_hw *hw)
+{
+	struct clk_gpio *clk = to_clk_gpio(hw);
+
+	gpiod_set_value(clk->gpiod, 0);
+}
+
+static int clk_gpio_gate_is_enabled(struct clk_hw *hw)
 {
-	struct clk_gpio *clk_gpio = to_clk_gpio(hw);
+	struct clk_gpio *clk = to_clk_gpio(hw);
 
-	gpio_set_active(clk_gpio->gpio, false);
+	return gpiod_get_value(clk->gpiod);
 }
 
-static int clk_gpio_is_enabled(struct clk_hw *hw)
+static const struct clk_ops clk_gpio_gate_ops = {
+	.enable = clk_gpio_gate_enable,
+	.disable = clk_gpio_gate_disable,
+	.is_enabled = clk_gpio_gate_is_enabled,
+};
+
+static int clk_gpio_mux_get_parent(struct clk_hw *hw)
+{
+	struct clk_gpio *clk = to_clk_gpio(hw);
+
+	return gpiod_get_value(clk->gpiod);
+}
+
+static int clk_gpio_mux_set_parent(struct clk_hw *hw, u8 index)
 {
-	struct clk_gpio *clk_gpio = to_clk_gpio(hw);
+	struct clk_gpio *clk = to_clk_gpio(hw);
 
-	return gpio_is_active(clk_gpio->gpio);
+	gpiod_set_value(clk->gpiod, index);
+
+	return 0;
 }
 
-static struct clk_ops clk_gpio_ops = {
+static const struct clk_ops clk_gpio_mux_ops = {
+	.get_parent = clk_gpio_mux_get_parent,
+	.set_parent = clk_gpio_mux_set_parent,
 	.set_rate = clk_parent_set_rate,
 	.round_rate = clk_parent_round_rate,
-	.enable = clk_gpio_enable,
-	.disable = clk_gpio_disable,
-	.is_enabled = clk_gpio_is_enabled,
 };
 
-static int of_gpio_clk_probe(struct device *dev)
+static struct clk_hw *clk_register_gpio(struct device *dev, u8 num_parents,
+					struct gpio_desc *gpiod,
+					const struct clk_ops *clk_gpio_ops)
 {
-	struct device_node *node = dev->device_node;
 	struct clk_gpio *clk_gpio;
-	enum of_gpio_flags of_flags;
-	unsigned long flags;
-	int ret;
+	struct clk_hw *hw;
+	struct clk_init_data init = {};
+	const char *parent_names[2];
+	int err;
 
 	clk_gpio = xzalloc(sizeof(*clk_gpio));
 	if (!clk_gpio)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
-	clk_gpio->parent = of_clk_get_parent_name(node, 0);
-	if (!clk_gpio->parent) {
-		ret = -EINVAL;
-		goto no_parent;
-	}
+	if (of_clk_parent_fill(dev->of_node, parent_names, num_parents) != num_parents)
+		return ERR_PTR(-EINVAL);
 
-	clk_gpio->hw.clk.ops = &clk_gpio_ops;
-	clk_gpio->hw.clk.parent_names = &clk_gpio->parent;
-	clk_gpio->hw.clk.num_parents = 1;
-
-	clk_gpio->hw.clk.name = node->name;
-	of_property_read_string(node, "clock-output-names",
-			&clk_gpio->hw.clk.name);
-
-	ret = of_get_named_gpio_flags(node, "enable-gpios", 0,
-			&of_flags);
-	if (ret >= 0 && !gpio_is_valid(ret))
-		ret = -EINVAL;
-	if (ret < 0)
-		goto no_gpio;
-	clk_gpio->gpio = ret;
-
-	flags = GPIOF_OUT_INIT_ACTIVE;
-	if (of_flags & OF_GPIO_ACTIVE_LOW)
-		flags |= GPIOF_ACTIVE_LOW;
-	ret = gpio_request_one(clk_gpio->gpio, flags, clk_gpio->hw.clk.name);
-	if (ret)
-		goto no_request;
+	init.name = dev->of_node->name;
+	of_property_read_string(dev->of_node, "clock-output-names", &init.name);
+	init.ops = clk_gpio_ops;
+	init.parent_names = parent_names;
+	init.num_parents = num_parents;
+	init.flags = CLK_SET_RATE_PARENT;
 
-	ret = bclk_register(&clk_gpio->hw.clk);
-	if (ret)
-		goto no_register;
+	clk_gpio->gpiod = gpiod;
+	clk_gpio->hw.init = &init;
 
-	return of_clk_add_provider(node, of_clk_src_simple_get, &clk_gpio->hw.clk);
+	hw = &clk_gpio->hw;
+	err =  bclk_register(&clk_gpio->hw.clk);
+	if (err)
+		return ERR_PTR(err);
 
-no_register:
-	gpio_free(clk_gpio->gpio);
-no_request:
-no_gpio:
-no_parent:
-	free(clk_gpio);
-	return ret;
+	return hw;
+}
+
+static struct clk_hw *clk_hw_register_gpio_gate(struct device *dev,
+						int num_parents,
+						struct gpio_desc *gpiod)
+{
+	return clk_register_gpio(dev, num_parents, gpiod, &clk_gpio_gate_ops);
+}
+
+static struct clk_hw *clk_hw_register_gpio_mux(struct device *dev,
+					       struct gpio_desc *gpiod)
+{
+	return clk_register_gpio(dev, 2, gpiod, &clk_gpio_mux_ops);
 }
 
-static const struct of_device_id clk_gpio_device_id[] = {
-	{ .compatible = "gpio-gate-clock", },
-	{}
+static int gpio_clk_driver_probe(struct device *dev)
+{
+	struct device_node *node = dev->of_node;
+	const char *gpio_name;
+	unsigned int num_parents;
+	struct gpio_desc *gpiod;
+	struct clk_hw *hw;
+	bool is_mux;
+
+	is_mux = of_device_is_compatible(node, "gpio-mux-clock");
+
+	num_parents = of_clk_get_parent_count(node);
+	if (is_mux && num_parents != 2)
+		return dev_err_probe(dev, -EINVAL,
+				     "mux-clock must have 2 parents\n");
+
+	gpio_name = is_mux ? "select" : "enable";
+	gpiod = gpiod_get(dev, gpio_name, GPIOD_OUT_LOW);
+	if (IS_ERR(gpiod))
+		return dev_err_probe(dev, PTR_ERR(gpiod),
+				     "Can't get '%s' named GPIO property\n", gpio_name);
+
+	if (is_mux)
+		hw = clk_hw_register_gpio_mux(dev, gpiod);
+	else
+		hw = clk_hw_register_gpio_gate(dev, num_parents, gpiod);
+	if (IS_ERR(hw))
+		return PTR_ERR(hw);
+
+	return of_clk_add_provider(node, of_clk_src_simple_get, &hw->clk);
+}
+
+static __maybe_unused const struct of_device_id clk_gpio_device_id[] = {
+	{ .compatible = "gpio-mux-clock" },
+	{ .compatible = "gpio-gate-clock" },
+	{ }
 };
 MODULE_DEVICE_TABLE(of, clk_gpio_device_id);
 
 static struct driver gpio_gate_clock_driver = {
-	.probe = of_gpio_clk_probe,
+	.probe = gpio_clk_driver_probe,
 	.name = "gpio-gate-clock",
 	.of_compatible = DRV_OF_COMPAT(clk_gpio_device_id),
 };
-
 core_platform_driver(gpio_gate_clock_driver);
+
+/**
+ * DOC: gated fixed clock, controlled with a gpio output and a regulator
+ * Traits of this clock:
+ * prepare - clk_prepare and clk_unprepare are function & control regulator
+ *           optionally a gpio that can sleep
+ * enable - clk_enable and clk_disable are functional & control gpio
+ * rate - rate is fixed and set on clock registration
+ * parent - fixed clock is a root clock and has no parent
+ */
+
+/**
+ * struct clk_gated_fixed - Gateable fixed rate clock
+ * @clk_gpio:	instance of clk_gpio for gate-gpio
+ * @supply:	supply regulator
+ * @rate:	fixed rate
+ */
+struct clk_gated_fixed {
+	struct clk_gpio clk_gpio;
+	struct regulator *supply;
+	unsigned long rate;
+};
+
+#define to_clk_gated_fixed(_clk_gpio) container_of(_clk_gpio, struct clk_gated_fixed, clk_gpio)
+
+static unsigned long clk_gated_fixed_recalc_rate(struct clk_hw *hw,
+						 unsigned long parent_rate)
+{
+	return to_clk_gated_fixed(to_clk_gpio(hw))->rate;
+}
+
+static int clk_gated_fixed_enable(struct clk_hw *hw)
+{
+	struct clk_gated_fixed *clk = to_clk_gated_fixed(to_clk_gpio(hw));
+	int ret;
+
+	ret = regulator_enable(clk->supply);
+	if (!ret)
+		gpiod_set_value(clk->clk_gpio.gpiod, 1);
+
+	return ret;
+}
+
+static void clk_gated_fixed_disable(struct clk_hw *hw)
+{
+	struct clk_gated_fixed *clk = to_clk_gated_fixed(to_clk_gpio(hw));
+
+	gpiod_set_value(clk->clk_gpio.gpiod, 0);
+
+	regulator_disable(clk->supply);
+}
+
+static int clk_gated_fixed_is_enabled(struct clk_hw *hw)
+{
+	struct clk_gated_fixed *clk = to_clk_gated_fixed(to_clk_gpio(hw));
+
+	if (clk->supply && !regulator_is_enabled(clk->supply))
+		return 0;
+
+	return clk->clk_gpio.gpiod ? gpiod_get_value(clk->clk_gpio.gpiod) : 1;
+}
+
+static const struct clk_ops clk_gated_fixed_ops = {
+	.enable = clk_gated_fixed_enable,
+	.disable = clk_gated_fixed_disable,
+	.is_enabled = clk_gated_fixed_is_enabled,
+	.recalc_rate = clk_gated_fixed_recalc_rate,
+};
+
+static int clk_gated_fixed_probe(struct device *dev)
+{
+	struct clk_gated_fixed *clk;
+	const char *clk_name;
+	u32 rate;
+	int ret;
+
+	clk = xzalloc(sizeof(*clk));
+	if (!clk)
+		return -ENOMEM;
+
+	ret = of_property_read_u32(dev->of_node, "clock-frequency", &rate);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to get clock-frequency\n");
+	clk->rate = rate;
+
+	clk_name = dev->of_node->name;
+	of_property_read_string(dev->of_node, "clock-output-names", &clk_name);
+
+	clk->supply = regulator_get_optional(dev, "vdd");
+	if (IS_ERR(clk->supply)) {
+		if (PTR_ERR(clk->supply) != -ENODEV)
+			return dev_err_probe(dev, PTR_ERR(clk->supply),
+					     "Failed to get regulator\n");
+		clk->supply = NULL;
+	}
+
+	clk->clk_gpio.gpiod = gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
+	if (IS_ERR(clk->clk_gpio.gpiod))
+		return dev_err_probe(dev, PTR_ERR(clk->clk_gpio.gpiod),
+				     "Failed to get gpio\n");
+
+
+	clk->clk_gpio.hw.init = CLK_HW_INIT_NO_PARENT(clk_name, &clk_gated_fixed_ops, 0);
+
+	ret = clk_hw_register(dev, &clk->clk_gpio.hw);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to register clock\n");
+
+	ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get,
+				     &clk->clk_gpio.hw);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed to register clock provider\n");
+
+	return 0;
+}
+
+static __maybe_unused const struct of_device_id gated_fixed_clk_match_table[] = {
+	{ .compatible = "gated-fixed-clock" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, gated_fixed_clk_match_table);
+
+static struct driver gated_fixed_clk_driver = {
+	.probe = clk_gated_fixed_probe,
+	.name = "gated-fixed-clk",
+	.of_compatible = DRV_OF_COMPAT(gated_fixed_clk_match_table),
+};
+core_platform_driver(gated_fixed_clk_driver);
-- 
2.39.1



From a.fatoum at pengutronix.de  Fri Mar 28 01:34:24 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 28 Mar 2025 09:34:24 +0100
Subject: [PATCH] blspec: drop explicit devicetree "none" handling
Message-ID: <20250328083424.512384-1-a.fatoum@pengutronix.de>

The bootloader spec mentions only that the devicetree key is optional
and doesn't list none as special value. THe barebox behavior on none
is completely bonkers as it attempts to delete barebox' own device
tree, which nowadays fails with an error message.

Drop that special handling altogether.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/blspec.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/common/blspec.c b/common/blspec.c
index 1cbadf8963af..77ae3dc21951 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -98,16 +98,8 @@ static int blspec_boot(struct bootentry *be, int verbose, int dryrun)
 
 	data.os_file = basprintf("%s/%s", abspath, linuximage);
 
-	if (devicetree) {
-		if (!strcmp(devicetree, "none")) {
-			struct device_node *node = of_get_root_node();
-			if (node)
-				of_delete_node(node);
-		} else {
-			data.oftree_file = basprintf("%s/%s", abspath,
-						       devicetree);
-		}
-	}
+	if (devicetree)
+		data.oftree_file = basprintf("%s/%s", abspath, devicetree);
 
 	if (overlays)
 		of_register_fixup(blspec_overlay_fixup, entry);
-- 
2.39.5



From a.fatoum at pengutronix.de  Fri Mar 28 01:35:09 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 28 Mar 2025 09:35:09 +0100
Subject: [PATCH] efi: payload: init: fix condition in warning message
Message-ID: <20250328083509.513606-1-a.fatoum@pengutronix.de>

The warning is supposed to point out a missing CONFIG_FS_EFI as possible
issue, but the condition was inverted, so it suggested enabling it when
it already was.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 efi/payload/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/efi/payload/init.c b/efi/payload/init.c
index 35cd8fc71661..3d9717b82540 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -371,7 +371,7 @@ static int efi_late_init(void)
 
 	if (!get_mounted_path("/boot")) {
 		pr_warn("boot device couldn't be determined%s\n",
-			IS_ENABLED(CONFIG_FS_EFI) ? " without CONFIG_FS_EFI" : "");
+			IS_ENABLED(CONFIG_FS_EFI) ? "" : " without CONFIG_FS_EFI");
 		return 0;
 	}
 
-- 
2.39.5



From a.fatoum at pengutronix.de  Fri Mar 28 01:35:49 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 28 Mar 2025 09:35:49 +0100
Subject: [PATCH 3/3] kbuild: compile *.mod.c files with -fshort-wchar
In-Reply-To: <20250328083549.514506-1-a.fatoum@pengutronix.de>
References: <20250328083549.514506-1-a.fatoum@pengutronix.de>
Message-ID: <20250328083549.514506-3-a.fatoum@pengutronix.de>

We use wchar_t in USB and EFI code, both of which expect 2-byte wide
strings. Thus, like Linux, we set -fshort-wchar in KBUILD_CFLAGS.

This flag is not passed through to the build of *.mod.c files that are
generated in a module build, leading to a linker warning.

Add it to fix this.

Cc: David Dgien <dgienda125 at gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 5c9fce83123c..4ee9780abeac 100644
--- a/Makefile
+++ b/Makefile
@@ -459,7 +459,7 @@ XZ		= xz
 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF)
 CFLAGS_KERNEL	=
 AFLAGS_KERNEL	=
-CFLAGS_MODULE	=
+CFLAGS_MODULE	= -fshort-wchar
 AFLAGS_MODULE	=
 
 LDFLAGS_MODULE  = -T common/module.lds
-- 
2.39.5



From a.fatoum at pengutronix.de  Fri Mar 28 01:35:47 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 28 Mar 2025 09:35:47 +0100
Subject: [PATCH 1/3] i2c: muxes: pca954x: switch to device_get_match_data
Message-ID: <20250328083549.514506-1-a.fatoum@pengutronix.de>

dev_get_drvdata has other semantics in barebox than in Linux and should
be removed eventually. Drop it in favor of device_get_match_data, which
avoids common bugs with pointer width difference casts.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/i2c/muxes/i2c-mux-pca954x.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 6c21b92860f0..4a926fb92b17 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -186,7 +186,6 @@ static int pca954x_probe(struct device *dev)
 	struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent);
 	int num;
 	struct pca954x *data;
-	uintptr_t tmp;
 	int ret = -ENODEV;
 	int gpio;
 	bool idle_disconnect;
@@ -210,10 +209,7 @@ static int pca954x_probe(struct device *dev)
 	if (i2c_smbus_write_byte(client, 0) < 0)
 		goto exit_free;
 
-	ret = dev_get_drvdata(dev, (const void **)&tmp);
-	data->type = tmp;
-	if (ret)
-		goto exit_free;
+	data->type = (uintptr_t)device_get_match_data(dev);
 
 	idle_disconnect = of_property_read_bool(dev->of_node,
 						"i2c-mux-idle-disconnect");
-- 
2.39.5



From a.fatoum at pengutronix.de  Fri Mar 28 01:35:48 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 28 Mar 2025 09:35:48 +0100
Subject: [PATCH 2/3] treewide: export symbols needed for i2c-mux-pca954x.ko
In-Reply-To: <20250328083549.514506-1-a.fatoum@pengutronix.de>
References: <20250328083549.514506-1-a.fatoum@pengutronix.de>
Message-ID: <20250328083549.514506-2-a.fatoum@pengutronix.de>

The module support in barebox is an experimental feature, but it can
prove useful in some situations.

Building most drivers as modules currently fails, because e.g. pr_print
and dev_printf are not exported.

Add EXPORT_SYMBOL annotations for all symbols currently used
by i2c-mux-pca954x.

Cc: David Dgien <dgienda125 at gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
David, are you still using the module support? We have added an
allyesconfig build to CI and an allmodconfig build may be added as well
if there are users.
---
 common/console_common.c | 2 ++
 drivers/base/driver.c   | 1 +
 drivers/dma/map.c       | 6 ++++++
 drivers/i2c/i2c.c       | 1 +
 4 files changed, 10 insertions(+)

diff --git a/common/console_common.c b/common/console_common.c
index a8527eee1e5a..5b7a64c99c29 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -135,6 +135,7 @@ int pr_print(int level, const char *fmt, ...)
 
 	return i;
 }
+EXPORT_SYMBOL(pr_print);
 
 int dev_printf(int level, const struct device *dev, const char *format, ...)
 {
@@ -161,6 +162,7 @@ int dev_printf(int level, const struct device *dev, const char *format, ...)
 
 	return ret;
 }
+EXPORT_SYMBOL(dev_printf);
 
 #ifdef CONFIG_CONSOLE_ALLOW_COLOR
 static unsigned int __console_allow_color = 1;
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 6363b3948f1d..edba037fa2dd 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -725,6 +725,7 @@ const void *device_get_match_data(struct device *dev)
 
 	return NULL;
 }
+EXPORT_SYMBOL(device_get_match_data);
 
 static void device_set_deferred_probe_reason(struct device *dev,
 					     const struct va_format *vaf)
diff --git a/drivers/dma/map.c b/drivers/dma/map.c
index cd0f5c3d3497..2980d4c2e790 100644
--- a/drivers/dma/map.c
+++ b/drivers/dma/map.c
@@ -7,6 +7,7 @@ void *dma_alloc(size_t size)
 {
 	return xmemalign(DMA_ALIGNMENT, ALIGN(size, DMA_ALIGNMENT));
 }
+EXPORT_SYMBOL(dma_alloc);
 
 void *dma_zalloc(size_t size)
 {
@@ -18,6 +19,7 @@ void *dma_zalloc(size_t size)
 
 	return buf;
 }
+EXPORT_SYMBOL(dma_zalloc);
 
 void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
 			     size_t size, enum dma_data_direction dir)
@@ -29,6 +31,7 @@ void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
 	if (!dev_is_dma_coherent(dev))
 		arch_sync_dma_for_cpu(ptr, size, dir);
 }
+EXPORT_SYMBOL(dma_sync_single_for_cpu);
 
 void dma_sync_single_for_device(struct device *dev, dma_addr_t address,
 					      size_t size, enum dma_data_direction dir)
@@ -40,6 +43,7 @@ void dma_sync_single_for_device(struct device *dev, dma_addr_t address,
 	if (!dev_is_dma_coherent(dev))
 		arch_sync_dma_for_device(ptr, size, dir);
 }
+EXPORT_SYMBOL(dma_sync_single_for_device);
 
 dma_addr_t dma_map_single(struct device *dev, void *ptr,
 					size_t size, enum dma_data_direction dir)
@@ -53,6 +57,7 @@ dma_addr_t dma_map_single(struct device *dev, void *ptr,
 
 	return dma_addr;
 }
+EXPORT_SYMBOL(dma_map_single);
 
 void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
 				    size_t size, enum dma_data_direction dir)
@@ -62,3 +67,4 @@ void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
 
 	debug_dma_unmap(dev, dma_addr, size, dir);
 }
+EXPORT_SYMBOL(dma_unmap_single);
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 7df645ba1c3f..49b87bb47c00 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -765,6 +765,7 @@ struct bus_type i2c_bus = {
 	.name = "i2c",
 	.match = device_match_of_modalias,
 };
+EXPORT_SYMBOL(i2c_bus);
 
 static int i2c_bus_init(void)
 {
-- 
2.39.5



From dgienda125 at gmail.com  Fri Mar 28 09:54:23 2025
From: dgienda125 at gmail.com (David Dgien)
Date: Fri, 28 Mar 2025 12:54:23 -0400
Subject: [PATCH 2/3] treewide: export symbols needed for i2c-mux-pca954x.ko
In-Reply-To: <20250328083549.514506-2-a.fatoum@pengutronix.de>
References: <20250328083549.514506-1-a.fatoum@pengutronix.de> <20250328083549.514506-2-a.fatoum@pengutronix.de>
Message-ID: <CALTtyOoKbiQFsQT1AfrXLZ+Agxbdz7iyAconRVGNNXXi6ETi6g@mail.gmail.com>

On Fri, Mar 28, 2025 at 4:35?AM Ahmad Fatoum <a.fatoum at pengutronix.de> wrote:
>
> The module support in barebox is an experimental feature, but it can
> prove useful in some situations.
>
> Building most drivers as modules currently fails, because e.g. pr_print
> and dev_printf are not exported.
>
> Add EXPORT_SYMBOL annotations for all symbols currently used
> by i2c-mux-pca954x.
>
> Cc: David Dgien <dgienda125 at gmail.com>
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> David, are you still using the module support? We have added an
> allyesconfig build to CI and an allmodconfig build may be added as well
> if there are users.

No, the program that had been using module support stopped
development, so we have no active users of module support.

There is another program considering using module support, but that
would require fixing modules for aarch64,
and that hasn't been a priority yet, nor do I know if/when it might be.

Thanks,
David Dgien

> ---
>  common/console_common.c | 2 ++
>  drivers/base/driver.c   | 1 +
>  drivers/dma/map.c       | 6 ++++++
>  drivers/i2c/i2c.c       | 1 +
>  4 files changed, 10 insertions(+)
>
> diff --git a/common/console_common.c b/common/console_common.c
> index a8527eee1e5a..5b7a64c99c29 100644
> --- a/common/console_common.c
> +++ b/common/console_common.c
> @@ -135,6 +135,7 @@ int pr_print(int level, const char *fmt, ...)
>
>         return i;
>  }
> +EXPORT_SYMBOL(pr_print);
>
>  int dev_printf(int level, const struct device *dev, const char *format, ...)
>  {
> @@ -161,6 +162,7 @@ int dev_printf(int level, const struct device *dev, const char *format, ...)
>
>         return ret;
>  }
> +EXPORT_SYMBOL(dev_printf);
>
>  #ifdef CONFIG_CONSOLE_ALLOW_COLOR
>  static unsigned int __console_allow_color = 1;
> diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> index 6363b3948f1d..edba037fa2dd 100644
> --- a/drivers/base/driver.c
> +++ b/drivers/base/driver.c
> @@ -725,6 +725,7 @@ const void *device_get_match_data(struct device *dev)
>
>         return NULL;
>  }
> +EXPORT_SYMBOL(device_get_match_data);
>
>  static void device_set_deferred_probe_reason(struct device *dev,
>                                              const struct va_format *vaf)
> diff --git a/drivers/dma/map.c b/drivers/dma/map.c
> index cd0f5c3d3497..2980d4c2e790 100644
> --- a/drivers/dma/map.c
> +++ b/drivers/dma/map.c
> @@ -7,6 +7,7 @@ void *dma_alloc(size_t size)
>  {
>         return xmemalign(DMA_ALIGNMENT, ALIGN(size, DMA_ALIGNMENT));
>  }
> +EXPORT_SYMBOL(dma_alloc);
>
>  void *dma_zalloc(size_t size)
>  {
> @@ -18,6 +19,7 @@ void *dma_zalloc(size_t size)
>
>         return buf;
>  }
> +EXPORT_SYMBOL(dma_zalloc);
>
>  void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
>                              size_t size, enum dma_data_direction dir)
> @@ -29,6 +31,7 @@ void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
>         if (!dev_is_dma_coherent(dev))
>                 arch_sync_dma_for_cpu(ptr, size, dir);
>  }
> +EXPORT_SYMBOL(dma_sync_single_for_cpu);
>
>  void dma_sync_single_for_device(struct device *dev, dma_addr_t address,
>                                               size_t size, enum dma_data_direction dir)
> @@ -40,6 +43,7 @@ void dma_sync_single_for_device(struct device *dev, dma_addr_t address,
>         if (!dev_is_dma_coherent(dev))
>                 arch_sync_dma_for_device(ptr, size, dir);
>  }
> +EXPORT_SYMBOL(dma_sync_single_for_device);
>
>  dma_addr_t dma_map_single(struct device *dev, void *ptr,
>                                         size_t size, enum dma_data_direction dir)
> @@ -53,6 +57,7 @@ dma_addr_t dma_map_single(struct device *dev, void *ptr,
>
>         return dma_addr;
>  }
> +EXPORT_SYMBOL(dma_map_single);
>
>  void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
>                                     size_t size, enum dma_data_direction dir)
> @@ -62,3 +67,4 @@ void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
>
>         debug_dma_unmap(dev, dma_addr, size, dir);
>  }
> +EXPORT_SYMBOL(dma_unmap_single);
> diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> index 7df645ba1c3f..49b87bb47c00 100644
> --- a/drivers/i2c/i2c.c
> +++ b/drivers/i2c/i2c.c
> @@ -765,6 +765,7 @@ struct bus_type i2c_bus = {
>         .name = "i2c",
>         .match = device_match_of_modalias,
>  };
> +EXPORT_SYMBOL(i2c_bus);
>
>  static int i2c_bus_init(void)
>  {
> --
> 2.39.5
>


From bst at pengutronix.de  Fri Mar 28 10:16:17 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Fri, 28 Mar 2025 18:16:17 +0100
Subject: [PATCH] bootchooser: fix state_prefix nv variable in error message
Message-ID: <20250328171617.1945875-1-bst@pengutronix.de>

The correct variable for the state prefix is
`nv.bootchooser.state_prefix`, not `nv.state_prefix`.

Fixes: cc532a3f733 ("boot: add framework for redundant boot scenarios")
Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 common/bootchooser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/bootchooser.c b/common/bootchooser.c
index 3e7bda9ab0f..6c324fb155e 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -381,7 +381,7 @@ struct bootchooser *bootchooser_get(void)
 			}
 			free(state_devname);
 		} else {
-			pr_err("State disabled, cannot use nv.state_prefix=%s\n",
+			pr_err("State disabled, cannot use nv.bootchooser.state_prefix=%s\n",
 			       state_prefix);
 			ret = -ENODEV;
 			goto err;
-- 
2.39.5



From devnull+dgienda125.gmail.com at kernel.org  Fri Mar 28 20:13:40 2025
From: devnull+dgienda125.gmail.com at kernel.org (David Dgien via B4 Relay)
Date: Fri, 28 Mar 2025 23:13:40 -0400
Subject: [PATCH] tlsf: Add tracking of added tlsf memory pools
Message-ID: <20250328-tlsf-addpool-v1-1-25fd0b060356@gmail.com>

From: David Dgien <dgienda125 at gmail.com>

When configured to use the TLSF allocator, the malloc_stats function
only walks the initial memory pool, as that is the only pool it is aware
of, and TLSF doesn't link pools together in a way that the walker can
follow.

Add wrapper functions around tlsf_add_pool and tlsf_remove_pool to add
additional tracking of added pools, so that they can be walked by the
malloc_stats function and meminfo can report accurate heap utilization.

Signed-off-by: David Dgien <dgienda125 at gmail.com>
Reviewed-by: Tyler Reece <mtreece at acm.org>
---
For this change I put the wrapper function prototypes in malloc.h, gated
by CONFIG_MALLOC_TLSF. I was split between there and memory.h, but I'm
not entirely convinced malloc.h was the right decision. I also didn't
provide stubs for when CONFIG_MALLOC_TLSF isn't enabled, as I did not
see any upstream code that utilizes tlsf_add_pool. If the project has
different preferences I can make those changes.
---
 common/tlsf_malloc.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/malloc.h     |  5 ++++
 2 files changed, 69 insertions(+)

diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
index 6a90ee47199fa9e8223f843cc95f52eebfec2aee..0e756a13d5a2665eccf8931b19dfa4e56cad15eb 100644
--- a/common/tlsf_malloc.c
+++ b/common/tlsf_malloc.c
@@ -12,8 +12,18 @@
 #include <module.h>
 #include <tlsf.h>
 
+#include <linux/kasan.h>
+#include <linux/list.h>
+
 extern tlsf_t tlsf_mem_pool;
 
+struct pool_entry {
+	pool_t pool;
+	struct list_head list;
+};
+
+static LIST_HEAD(mem_pool_list);
+
 void *malloc(size_t bytes)
 {
 	void *mem;
@@ -75,6 +85,7 @@ static void malloc_walker(void* ptr, size_t size, int used, void *user)
 
 void malloc_stats(void)
 {
+	struct pool_entry *cur_pool;
 	struct malloc_stats s;
 
 	s.used = 0;
@@ -82,5 +93,58 @@ void malloc_stats(void)
 
 	tlsf_walk_pool(tlsf_get_pool(tlsf_mem_pool), malloc_walker, &s);
 
+	list_for_each_entry(cur_pool, &mem_pool_list, list)
+		tlsf_walk_pool(cur_pool->pool, malloc_walker, &s);
+
 	printf("used: %zu\nfree: %zu\n", s.used, s.free);
 }
+
+void *malloc_add_pool(void *mem, size_t bytes)
+{
+	pool_t new_pool;
+	struct pool_entry *new_pool_entry;
+
+	if (!mem)
+		return NULL;
+
+	new_pool_entry = malloc(sizeof(struct pool_entry));
+	if (!new_pool_entry)
+		return NULL;
+
+	new_pool = tlsf_add_pool(tlsf_mem_pool, mem, bytes);
+	if (!new_pool) {
+		free(new_pool_entry);
+		return NULL;
+	}
+
+	kasan_poison_shadow(mem, bytes, KASAN_TAG_INVALID);
+
+	new_pool_entry->pool = new_pool;
+	list_add(&new_pool_entry->list, &mem_pool_list);
+
+	return (void *)new_pool;
+}
+
+int malloc_remove_pool(void *pool)
+{
+	struct pool_entry *cur_pool;
+	struct malloc_stats s;
+
+	s.used = 0;
+	s.free = 0;
+
+	list_for_each_entry(cur_pool, &mem_pool_list, list) {
+		if (cur_pool->pool == (pool_t)pool) {
+			tlsf_walk_pool(cur_pool->pool, malloc_walker, &s);
+			if (s.used)
+				return -EBUSY;
+
+			list_del(&(cur_pool->list));
+			free(cur_pool);
+			tlsf_remove_pool(tlsf_mem_pool, pool);
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
diff --git a/include/malloc.h b/include/malloc.h
index 0b74746360c08a95e593c9afe485382d02cd5c12..a3684105981eb4a27594c7cb9a71191ca9dceff3 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -21,6 +21,11 @@
 #define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
 				(unsigned long)ZERO_SIZE_PTR)
 
+#ifdef CONFIG_MALLOC_TLSF
+void *malloc_add_pool(void *mem, size_t bytes);
+int malloc_remove_pool(void *pool);
+#endif
+
 #if IN_PROPER
 void *malloc(size_t) __alloc_size(1);
 size_t malloc_usable_size(void *);

---
base-commit: d4b5f3d3d1919189c2a8ebbc6ecc531c5459acf8
change-id: 20250131-tlsf-addpool-5f42029b582c

Best regards,
-- 
David Dgien <dgienda125 at gmail.com>




From s.hauer at pengutronix.de  Sun Mar 30 23:37:52 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 08:37:52 +0200
Subject: [PATCH] bootchooser: fix state_prefix nv variable in error
 message
In-Reply-To: <20250328171617.1945875-1-bst@pengutronix.de>
References: <20250328171617.1945875-1-bst@pengutronix.de>
Message-ID: <174340307285.251180.7455257774654455628.b4-ty@pengutronix.de>


On Fri, 28 Mar 2025 18:16:17 +0100, Bastian Krause wrote:
> The correct variable for the state prefix is
> `nv.bootchooser.state_prefix`, not `nv.state_prefix`.
> 
> 

Applied, thanks!

[1/1] bootchooser: fix state_prefix nv variable in error message
      https://git.pengutronix.de/cgit/barebox/commit/?id=cb39329acd57 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Sun Mar 30 23:49:21 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 08:49:21 +0200
Subject: [PATCH 1/2] regulator: core: Implement regulator_is_enabled()
 call
In-Reply-To: <20250328063122.36276-1-eagle.alexander923@gmail.com>
References: <20250328063122.36276-1-eagle.alexander923@gmail.com>
Message-ID: <Z-o68SVbRz4-8lr0@pengutronix.de>

On Fri, Mar 28, 2025 at 09:31:21AM +0300, Alexander Shiyan wrote:
> Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
> ---
>  drivers/regulator/core.c | 11 +++++++++++
>  include/regulator.h      |  6 ++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 2c3b009ea6..c9e30ab3fd 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -610,6 +610,17 @@ int regulator_disable(struct regulator *r)
>  	return regulator_disable_rdev(r->rdev);
>  }
>  
> +int regulator_is_enabled(struct regulator *r)
> +{
> +	if (!r)
> +		return 0;
> +
> +	if (r->rdev->always_on)
> +		return 1;
> +
> +	return r->rdev->enable_count;
> +}

This differs from what Linux does. Linux will return the result of the
is_enabled hook here. We should likely do the same and only if the
is_enabled hook is not present return the enable_count.

> +
>  int regulator_set_voltage(struct regulator *r, int min_uV, int max_uV)
>  {
>  	if (!r)
> diff --git a/include/regulator.h b/include/regulator.h
> index 9785b8ac07..5fdf1602dd 100644
> --- a/include/regulator.h
> +++ b/include/regulator.h
> @@ -217,6 +217,7 @@ void regulator_put(struct regulator *r);
>  struct regulator *regulator_get_name(const char *name);
>  int regulator_enable(struct regulator *);
>  int regulator_disable(struct regulator *);
> +int regulator_is_enabled(struct regulator *);
>  int regulator_is_enabled_regmap(struct regulator_dev *);
>  int regulator_enable_regmap(struct regulator_dev *);
>  int regulator_disable_regmap(struct regulator_dev *);
> @@ -285,6 +286,11 @@ static inline int regulator_disable(struct regulator *r)
>  	return 0;
>  }
>  
> +static inline int regulator_is_enabled(struct regulator *r)
> +{
> +	return 0;
> +}

I think we should return true here as it likely makes the consumers
happier.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Sun Mar 30 23:57:58 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 08:57:58 +0200
Subject: [PATCH] blspec: drop explicit devicetree "none" handling
In-Reply-To: <20250328083424.512384-1-a.fatoum@pengutronix.de>
References: <20250328083424.512384-1-a.fatoum@pengutronix.de>
Message-ID: <174340427820.257953.936746885738788608.b4-ty@pengutronix.de>


On Fri, 28 Mar 2025 09:34:24 +0100, Ahmad Fatoum wrote:
> The bootloader spec mentions only that the devicetree key is optional
> and doesn't list none as special value. THe barebox behavior on none
> is completely bonkers as it attempts to delete barebox' own device
> tree, which nowadays fails with an error message.
> 
> Drop that special handling altogether.
> 
> [...]

Applied, thanks!

[1/1] blspec: drop explicit devicetree "none" handling
      https://git.pengutronix.de/cgit/barebox/commit/?id=6bedeada3252 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 00:03:36 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 09:03:36 +0200
Subject: [PATCH] efi: payload: init: fix condition in warning message
In-Reply-To: <20250328083509.513606-1-a.fatoum@pengutronix.de>
References: <20250328083509.513606-1-a.fatoum@pengutronix.de>
Message-ID: <174340461618.259818.13694372893646679700.b4-ty@pengutronix.de>


On Fri, 28 Mar 2025 09:35:09 +0100, Ahmad Fatoum wrote:
> The warning is supposed to point out a missing CONFIG_FS_EFI as possible
> issue, but the condition was inverted, so it suggested enabling it when
> it already was.
> 
> 

Applied, thanks!

[1/1] efi: payload: init: fix condition in warning message
      https://git.pengutronix.de/cgit/barebox/commit/?id=8b7535e2a84b (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 00:05:11 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 09:05:11 +0200
Subject: [PATCH 1/3] i2c: muxes: pca954x: switch to
 device_get_match_data
In-Reply-To: <20250328083549.514506-1-a.fatoum@pengutronix.de>
References: <20250328083549.514506-1-a.fatoum@pengutronix.de>
Message-ID: <174340471144.261611.11183009109436054971.b4-ty@pengutronix.de>


On Fri, 28 Mar 2025 09:35:47 +0100, Ahmad Fatoum wrote:
> dev_get_drvdata has other semantics in barebox than in Linux and should
> be removed eventually. Drop it in favor of device_get_match_data, which
> avoids common bugs with pointer width difference casts.
> 
> 

Applied, thanks!

[1/3] i2c: muxes: pca954x: switch to device_get_match_data
      https://git.pengutronix.de/cgit/barebox/commit/?id=a6c38b7a837c (link may not be stable)
[2/3] treewide: export symbols needed for i2c-mux-pca954x.ko
      https://git.pengutronix.de/cgit/barebox/commit/?id=9cd029dbe4fc (link may not be stable)
[3/3] kbuild: compile *.mod.c files with -fshort-wchar
      https://git.pengutronix.de/cgit/barebox/commit/?id=b2fe75b400dd (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 00:08:49 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 09:08:49 +0200
Subject: [PATCH 0/4] ci: fix sandbox allyesconfig build
In-Reply-To: <20250327144742.1841423-1-a.fatoum@pengutronix.de>
References: <20250327144742.1841423-1-a.fatoum@pengutronix.de>
Message-ID: <174340492945.261895.5641894409898783345.b4-ty@pengutronix.de>


On Thu, 27 Mar 2025 15:47:38 +0100, Ahmad Fatoum wrote:
> With these changes applied, the most recent container image can be used
> to run the pytest tests for allyesconfig.
> 
> Ahmad Fatoum (4):
>   sandbox: env: switch from CONFIG_DEFAULT_ENVIRONMENT_PATH to bbenv-y
>   test: bthread: change comparison condition for switches vs. yields
>   ci: pytest: rename build directories
>   ci: pytest: enable console and libc allocator for allyesconfig
> 
> [...]

Applied, thanks!

[1/4] sandbox: env: switch from CONFIG_DEFAULT_ENVIRONMENT_PATH to bbenv-y
      https://git.pengutronix.de/cgit/barebox/commit/?id=1faaaabc6faf (link may not be stable)
[2/4] test: bthread: change comparison condition for switches vs. yields
      https://git.pengutronix.de/cgit/barebox/commit/?id=ea6cdcd699dc (link may not be stable)
[3/4] ci: pytest: rename build directories
      https://git.pengutronix.de/cgit/barebox/commit/?id=8052dd98ab6a (link may not be stable)
[4/4] ci: pytest: enable console and libc allocator for allyesconfig
      https://git.pengutronix.de/cgit/barebox/commit/?id=bc13b2175583 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 00:10:31 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 09:10:31 +0200
Subject: [PATCH] phy: rockchip: naneng-combphy: Updating the driver
 from the kernel repository
In-Reply-To: <20250327143218.1630440-1-eagle.alexander923@gmail.com>
References: <20250327143218.1630440-1-eagle.alexander923@gmail.com>
Message-ID: <174340503196.264819.6777593892915410846.b4-ty@pengutronix.de>


On Thu, 27 Mar 2025 17:32:18 +0300, Alexander Shiyan wrote:
> The current rockchip-naneng-combphy PHY driver causes my RK3588
> board to hang when probing PCI2 (I think due to insufficient
> clock initialization).
> This patch replaces the driver code from the Linux kernel repository,
> and now the bootloader works fine with pcie2x1l0.pcie2x1l2 devices
> on the RK3588.
> 
> [...]

Applied, thanks!

[1/1] phy: rockchip: naneng-combphy: Updating the driver from the kernel repository
      https://git.pengutronix.de/cgit/barebox/commit/?id=58a37927b642 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 00:11:02 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 09:11:02 +0200
Subject: [PATCH] kbuild: undefine linux/unix macros
In-Reply-To: <20250327132052.3187117-1-bst@pengutronix.de>
References: <20250327132052.3187117-1-bst@pengutronix.de>
Message-ID: <174340506294.271298.16649780147680124517.b4-ty@pengutronix.de>


On Thu, 27 Mar 2025 14:20:52 +0100, Bastian Krause wrote:
> gcc and clang, when using `-std=gnu11`, predefine `linux` and `unix` as
> macros:
> 
>   $ gcc -std=gnu11 -dM -E - < /dev/null | grep -v "define _"
>   #define unix 1
>   #define linux 1
> 
> [...]

Applied, thanks!

[1/1] kbuild: undefine linux/unix macros
      https://git.pengutronix.de/cgit/barebox/commit/?id=3e0790af5618 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 00:22:40 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 09:22:40 +0200
Subject: Removal of dlmalloc?
In-Reply-To: <7a4edaef-a606-4b9d-bdf5-c7b5f896daae@pengutronix.de>
References: <7a4edaef-a606-4b9d-bdf5-c7b5f896daae@pengutronix.de>
Message-ID: <Z-pCwM8Y9GmsEs7D@pengutronix.de>

On Thu, Mar 27, 2025 at 12:51:31PM +0100, Ahmad Fatoum wrote:
> Hi,
> 
> We have a TLSF implemenation in barebox for >= 13 years now and it has
> more features than dlmalloc like multiple pools and KASAN integration.
> 
> I think it's thus time to retire the dlmalloc we inherited from U-Boot.
> 
> Unfortunately, TLSF was not the default in the config, even though the
> most common configs select it. I'd thus suggest we remove dlmalloc
> altogether after v2025.06.0 is tagged.
> 
> Thoughts? Objections?

No objections from my side.

The only reason for me to enable dlmalloc from time to time was that I
suspected some bug in the allocator, but it never actually turned out to
be a bug in the allocator. Now with Kasan we have far better memory
debugging facilities than back in those days, so yes, I think it's time
to schedule removal of dlmalloc.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Mon Mar 31 00:29:15 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 09:29:15 +0200
Subject: [PATCH] reset: Fix name of exported symbol
In-Reply-To: <20250327053801.52356-2-eagle.alexander923@gmail.com>
References: <20250327053801.52356-1-eagle.alexander923@gmail.com>
 <20250327053801.52356-2-eagle.alexander923@gmail.com>
Message-ID: <174340615584.309738.18206662439774489848.b4-ty@pengutronix.de>


On Thu, 27 Mar 2025 08:38:01 +0300, Alexander Shiyan wrote:
> 


Applied, thanks!

[1/1] reset: Fix name of exported symbol
      https://git.pengutronix.de/cgit/barebox/commit/?id=48f7eba7e463 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 00:29:45 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 09:29:45 +0200
Subject: [PATCH] ARM: boards: protonic-imx6: Add prt-usb as fallback
 preferred boot target
In-Reply-To: <20250327100044.654042-1-robin@protonic.nl>
References: <20250327100044.654042-1-robin@protonic.nl>
Message-ID: <174340618520.309912.2551825977733178218.b4-ty@pengutronix.de>


On Thu, 27 Mar 2025 11:00:44 +0100, Robin van der Gracht wrote:
> If i.e. the bootchooser target fails because of missing or broken follow-up
> software, instead of doing nothing, we try to boot from usb.
> 
> 

Applied, thanks!

[1/1] ARM: boards: protonic-imx6: Add prt-usb as fallback preferred boot target
      https://git.pengutronix.de/cgit/barebox/commit/?id=a30704b88a29 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 00:29:45 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 09:29:45 +0200
Subject: [PATCH] common: make TLSF the default allocator
In-Reply-To: <20250327113753.361094-1-a.fatoum@pengutronix.de>
References: <20250327113753.361094-1-a.fatoum@pengutronix.de>
Message-ID: <174340618519.309912.5605281670349590453.b4-ty@pengutronix.de>


On Thu, 27 Mar 2025 12:37:53 +0100, Ahmad Fatoum wrote:
> Going by the most used defconfigs (multi_*_defconfig), TLSF is the most
> used allocator and it supports features absent in dlmalloc like
> multiple pools (used on ARMv7-R) and has KASAN integration, so there's
> even less reason to use dlmalloc nowadays.
> 
> In preparation for possible removal of dlmalloc in future, switch the
> default away from dlmalloc.
> 
> [...]

Applied, thanks!

[1/1] common: make TLSF the default allocator
      https://git.pengutronix.de/cgit/barebox/commit/?id=c1552409af30 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 00:44:53 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 09:44:53 +0200
Subject: [PATCH] ARM: boards: protonic-imx6: Re-introduce generic boot
 target board string
In-Reply-To: <20250327100122.654317-1-robin@protonic.nl>
References: <20250327100122.654317-1-robin@protonic.nl>
Message-ID: <Z-pH9YkFy9vGiFKU@pengutronix.de>

Hi Robin,

On Thu, Mar 27, 2025 at 11:01:22AM +0100, Robin van der Gracht wrote:
> This allows using a single bootable usb drive for multiple boards.
> 
> Signed-off-by: Robin van der Gracht <robin at protonic.nl>
> ---
>  arch/arm/boards/protonic-imx6/board.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
> index 19e58627c6..e4debb1c66 100644
> --- a/arch/arm/boards/protonic-imx6/board.c
> +++ b/arch/arm/boards/protonic-imx6/board.c
> @@ -374,7 +374,7 @@ static int prt_imx6_usb_boot(struct bootentry *entry, int verbose, int dryrun)
>  
>  	*second_word = 0;
>  
> -	if (strcmp(buf, priv->name)) {
> +	if (strcmp(buf, priv->name) && strcmp(buf, "prti6qp")) {

Where does this "prti6qp" string come from? It sounds like a very
specific machine, but is used as a generic value to short circuit the
compatible check.

Shouldn't it be something like "prt,generic-imx6" or whatever else this
image is supposed to work on?

Sascha


-- 
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-5555 |


From robin at protonic.nl  Mon Mar 31 01:01:12 2025
From: robin at protonic.nl (Robin van der Gracht)
Date: Mon, 31 Mar 2025 10:01:12 +0200
Subject: [PATCH] ARM: boards: protonic-imx6: Re-introduce generic boot
 target board string
In-Reply-To: <Z-pH9YkFy9vGiFKU@pengutronix.de>
References: <20250327100122.654317-1-robin@protonic.nl>
 <Z-pH9YkFy9vGiFKU@pengutronix.de>
Message-ID: <c2a3ca37-34d3-4fe6-883c-b4d4f3c04c7b@protonic.nl>

Hi Sascha,

On 31-03-2025 09:44, Sascha Hauer wrote:
> Hi Robin,
>
> On Thu, Mar 27, 2025 at 11:01:22AM +0100, Robin van der Gracht wrote:
>> This allows using a single bootable usb drive for multiple boards.
>>
>> Signed-off-by: Robin van der Gracht <robin at protonic.nl>
>> ---
>>   arch/arm/boards/protonic-imx6/board.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
>> index 19e58627c6..e4debb1c66 100644
>> --- a/arch/arm/boards/protonic-imx6/board.c
>> +++ b/arch/arm/boards/protonic-imx6/board.c
>> @@ -374,7 +374,7 @@ static int prt_imx6_usb_boot(struct bootentry *entry, int verbose, int dryrun)
>>   
>>   	*second_word = 0;
>>   
>> -	if (strcmp(buf, priv->name)) {
>> +	if (strcmp(buf, priv->name) && strcmp(buf, "prti6qp")) {
> Where does this "prti6qp" string come from? It sounds like a very
> specific machine, but is used as a generic value to short circuit the
> compatible check.
>
> Shouldn't it be something like "prt,generic-imx6" or whatever else this
> image is supposed to work on?

Ack. This is something that grew like this historically. But we can 
still change
that to something more sensible. I like your suggestion and will create 
a new patch.

Thank you.

Regards,
Robin


From s.hauer at pengutronix.de  Mon Mar 31 01:10:34 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 31 Mar 2025 10:10:34 +0200
Subject: [PATCH 1/2] ARM: boards: protonic-imx6: prtvt7: Don't use fixed
 numbers for dynamic GPIOs
In-Reply-To: <20250327100635.656657-1-robin@protonic.nl>
References: <20250327100635.656657-1-robin@protonic.nl>
Message-ID: <Z-pN-jyaGJ50sGqg@pengutronix.de>

On Thu, Mar 27, 2025 at 11:06:34AM +0100, Robin van der Gracht wrote:
> The GPIO indexing differs from the pin indexing.
> 
> Signed-off-by: Robin van der Gracht <robin at protonic.nl>
> ---
>  arch/arm/boards/protonic-imx6/board.c | 32 +++++++++++++++++++++------
>  1 file changed, 25 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
> index 9e62dc1544..4585ca4730 100644
> --- a/arch/arm/boards/protonic-imx6/board.c
> +++ b/arch/arm/boards/protonic-imx6/board.c
> @@ -21,6 +21,7 @@
>  #include <net.h>
>  #include <of_device.h>
>  #include <linux/regmap.h>
> +#include <of_gpio.h>
>  #include <sys/mount.h>
>  #include <sys/stat.h>
>  #include <unistd.h>
> @@ -740,17 +741,34 @@ static int prt_imx6_init_kvg_yaco(struct prt_imx6_priv *priv)
>  	return prt_imx6_init_kvg_power(priv, PW_MODE_KVG_WITH_YACO);
>  }
>  
> -#define GPIO_KEY_F6     (0xe0 + 5)
> -#define GPIO_KEY_CYCLE  (0xe0 + 2)
> -
>  static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
>  {
> -	/* This function relies heavely on the gpio-pca9539 driver */
> +	int gpio_cycle, gpio_f6;
> +	struct device_node *keys, *key;
> +
> +	keys = of_find_compatible_node(NULL, NULL, "gpio-keys");
> +	if (!keys) {
> +		dev_err(priv->dev, "Can't find gpio-keys of node!\n");
> +		return -ENODEV;
> +	}
>  
> -	gpio_direction_input(GPIO_KEY_F6);
> -	gpio_direction_input(GPIO_KEY_CYCLE);
> +	key = of_find_node_by_name(keys, "key-cycle");
> +	gpio_cycle = of_get_named_gpio_flags(key, "gpios", 0, NULL);
> +	if (gpio_cycle < 0) {
> +		dev_err(priv->dev, "Unable to get cycle key gpio\n");
> +		return gpio_cycle;
> +	}
> +	gpio_request_one(gpio_cycle, GPIOF_DIR_IN | GPIOF_ACTIVE_LOW, "Cycle");
> +
> +	key = of_find_node_by_name(keys, "key-f6");
> +	gpio_f6 = of_get_named_gpio_flags(key, "gpios", 0, NULL);
> +	if (gpio_f6 < 0) {
> +		dev_err(priv->dev, "Unable to get F6 key gpio\n");
> +		return gpio_f6;
> +	}
> +	gpio_request_one(gpio_f6, GPIOF_DIR_IN | GPIOF_ACTIVE_LOW, "F6");
>  
> -	if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
> +	if (!(gpio_is_active(gpio_cycle) && gpio_is_active(gpio_f6)))
>  		priv->no_usb_check = 1;

Given that you parse the gpio-keys node here, have you thought about
using the gpio-keys driver directly instead?

input_register_notfier() should give you the necessary events when KEY_CYCLEWINDOWS
and KEY_F6 are pressed.

Sascha

-- 
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-5555 |


From robin at protonic.nl  Mon Mar 31 03:25:50 2025
From: robin at protonic.nl (Robin van der Gracht)
Date: Mon, 31 Mar 2025 12:25:50 +0200
Subject: [PATCH 1/2] ARM: boards: protonic-imx6: prtvt7: Don't use fixed
 numbers for dynamic GPIOs
In-Reply-To: <Z-pN-jyaGJ50sGqg@pengutronix.de>
References: <20250327100635.656657-1-robin@protonic.nl>
 <Z-pN-jyaGJ50sGqg@pengutronix.de>
Message-ID: <2a82c4d0-1e3c-46f6-ba6b-e82556f7117d@protonic.nl>

Hi Sacha,

On 31-03-2025 10:10, Sascha Hauer wrote:
> On Thu, Mar 27, 2025 at 11:06:34AM +0100, Robin van der Gracht wrote:
>> The GPIO indexing differs from the pin indexing.
>>
>> Signed-off-by: Robin van der Gracht <robin at protonic.nl>
>> ---
>>   arch/arm/boards/protonic-imx6/board.c | 32 +++++++++++++++++++++------
>>   1 file changed, 25 insertions(+), 7 deletions(-)
>>
>> diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
>> index 9e62dc1544..4585ca4730 100644
>> --- a/arch/arm/boards/protonic-imx6/board.c
>> +++ b/arch/arm/boards/protonic-imx6/board.c
>> @@ -21,6 +21,7 @@
>>   #include <net.h>
>>   #include <of_device.h>
>>   #include <linux/regmap.h>
>> +#include <of_gpio.h>
>>   #include <sys/mount.h>
>>   #include <sys/stat.h>
>>   #include <unistd.h>
>> @@ -740,17 +741,34 @@ static int prt_imx6_init_kvg_yaco(struct prt_imx6_priv *priv)
>>   	return prt_imx6_init_kvg_power(priv, PW_MODE_KVG_WITH_YACO);
>>   }
>>   
>> -#define GPIO_KEY_F6     (0xe0 + 5)
>> -#define GPIO_KEY_CYCLE  (0xe0 + 2)
>> -
>>   static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
>>   {
>> -	/* This function relies heavely on the gpio-pca9539 driver */
>> +	int gpio_cycle, gpio_f6;
>> +	struct device_node *keys, *key;
>> +
>> +	keys = of_find_compatible_node(NULL, NULL, "gpio-keys");
>> +	if (!keys) {
>> +		dev_err(priv->dev, "Can't find gpio-keys of node!\n");
>> +		return -ENODEV;
>> +	}
>>   
>> -	gpio_direction_input(GPIO_KEY_F6);
>> -	gpio_direction_input(GPIO_KEY_CYCLE);
>> +	key = of_find_node_by_name(keys, "key-cycle");
>> +	gpio_cycle = of_get_named_gpio_flags(key, "gpios", 0, NULL);
>> +	if (gpio_cycle < 0) {
>> +		dev_err(priv->dev, "Unable to get cycle key gpio\n");
>> +		return gpio_cycle;
>> +	}
>> +	gpio_request_one(gpio_cycle, GPIOF_DIR_IN | GPIOF_ACTIVE_LOW, "Cycle");
>> +
>> +	key = of_find_node_by_name(keys, "key-f6");
>> +	gpio_f6 = of_get_named_gpio_flags(key, "gpios", 0, NULL);
>> +	if (gpio_f6 < 0) {
>> +		dev_err(priv->dev, "Unable to get F6 key gpio\n");
>> +		return gpio_f6;
>> +	}
>> +	gpio_request_one(gpio_f6, GPIOF_DIR_IN | GPIOF_ACTIVE_LOW, "F6");
>>   
>> -	if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
>> +	if (!(gpio_is_active(gpio_cycle) && gpio_is_active(gpio_f6)))
>>   		priv->no_usb_check = 1;
> Given that you parse the gpio-keys node here, have you thought about
> using the gpio-keys driver directly instead?
>
> input_register_notfier() should give you the necessary events when KEY_CYCLEWINDOWS
> and KEY_F6 are pressed.
We tried that in the past. Building Barebox with the gpio-keys driver 
(and thus enabling the keyboard),
had the side effect that Barebox autoboot was interruptible when a user 
pressed one of the buttons
a at the right time during boot.

We reverted to this option at the time to circumvent that. But now days 
we require ctrl-c to be pressed
on almost all of our boards to interrupt autoboot. So we could give it 
another try with the gpio-keys driver.

Robin


From o.rempel at pengutronix.de  Mon Mar 31 05:29:18 2025
From: o.rempel at pengutronix.de (Oleksij Rempel)
Date: Mon, 31 Mar 2025 14:29:18 +0200
Subject: [PATCH v1] spi: add STM32F7 QSPI controller driver
Message-ID: <20250331122918.564304-1-o.rempel@pengutronix.de>

From: Ahmad Fatoum <a.fatoum at pengutronix.de>

Introduce support for the STM32F7 QSPI controller, compatible with
"st,stm32f469-qspi".

Validated on STM32MP133-based MECT1S r1 board, which includes an
F7-compatible QSPI peripheral

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 drivers/spi/Kconfig          |   8 +
 drivers/spi/Makefile         |   1 +
 drivers/spi/spi-stm32-qspi.c | 496 +++++++++++++++++++++++++++++++++++
 3 files changed, 505 insertions(+)
 create mode 100644 drivers/spi/spi-stm32-qspi.c

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index aebfe30a1343..d6e8bea13c9c 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -114,6 +114,14 @@ config SPI_ZYNQ_QSPI
 	  This enables support for the Zynq Quad SPI controller in master mode.
 	  This controller only supports SPI memory interface.
 
+config STM32_QSPI
+	bool "STM32F7 QSPI driver"
+	depends on ARCH_STM32
+	help
+	  Enable the STM32F7 Quad-SPI (QSPI) driver. This driver can be
+	  used to access the SPI NOR flash chips on platforms embedding
+	  this ST IP core.
+
 config DRIVER_SPI_STM32
 	bool "STM32 SPI driver"
 	depends on ARCH_STM32MP || COMPILE_TEST
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index d0df0f136729..a9151286ab47 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_DRIVER_SPI_DSPI) += dspi_spi.o
 obj-$(CONFIG_SPI_BCM2835) += spi-bcm2835.o
 obj-$(CONFIG_SPI_ZYNQ_QSPI) += zynq_qspi.o
 obj-$(CONFIG_SPI_NXP_FLEXSPI) += spi-nxp-fspi.o
+obj-$(CONFIG_STM32_QSPI) += spi-stm32-qspi.o
 obj-$(CONFIG_DRIVER_SPI_STM32) += stm32_spi.o
 obj-$(CONFIG_SPI_SIFIVE) += spi-sifive.o
 obj-$(CONFIG_SPI_ROCKCHIP) += spi-rockchip.o
diff --git a/drivers/spi/spi-stm32-qspi.c b/drivers/spi/spi-stm32-qspi.c
new file mode 100644
index 000000000000..d38874fd6ef6
--- /dev/null
+++ b/drivers/spi/spi-stm32-qspi.c
@@ -0,0 +1,496 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
+ * Author: Ludovic Barre <ludovic.barre at st.com> for STMicroelectronics.
+ */
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/reset.h>
+#include <linux/sizes.h>
+#include <linux/spi/spi-mem.h>
+
+#define QSPI_CR			0x00
+#define CR_EN			BIT(0)
+#define CR_ABORT		BIT(1)
+#define CR_DMAEN		BIT(2)
+#define CR_TCEN			BIT(3)
+#define CR_SSHIFT		BIT(4)
+#define CR_DFM			BIT(6)
+#define CR_FSEL			BIT(7)
+#define CR_FTHRES_SHIFT		8
+#define CR_TEIE			BIT(16)
+#define CR_TCIE			BIT(17)
+#define CR_FTIE			BIT(18)
+#define CR_SMIE			BIT(19)
+#define CR_TOIE			BIT(20)
+#define CR_APMS			BIT(22)
+#define CR_PRESC_MASK		GENMASK(31, 24)
+
+#define QSPI_DCR		0x04
+#define DCR_FSIZE_MASK		GENMASK(20, 16)
+
+#define QSPI_SR			0x08
+#define SR_TEF			BIT(0)
+#define SR_TCF			BIT(1)
+#define SR_FTF			BIT(2)
+#define SR_SMF			BIT(3)
+#define SR_TOF			BIT(4)
+#define SR_BUSY			BIT(5)
+#define SR_FLEVEL_MASK		GENMASK(13, 8)
+
+#define QSPI_FCR		0x0c
+#define FCR_CTEF		BIT(0)
+#define FCR_CTCF		BIT(1)
+#define FCR_CSMF		BIT(3)
+
+#define QSPI_DLR		0x10
+
+#define QSPI_CCR		0x14
+#define CCR_INST_MASK		GENMASK(7, 0)
+#define CCR_IMODE_MASK		GENMASK(9, 8)
+#define CCR_ADMODE_MASK		GENMASK(11, 10)
+#define CCR_ADSIZE_MASK		GENMASK(13, 12)
+#define CCR_DCYC_MASK		GENMASK(22, 18)
+#define CCR_DMODE_MASK		GENMASK(25, 24)
+#define CCR_FMODE_MASK		GENMASK(27, 26)
+#define CCR_FMODE_INDW		(0U << 26)
+#define CCR_FMODE_INDR		(1U << 26)
+#define CCR_FMODE_APM		(2U << 26)
+#define CCR_FMODE_MM		(3U << 26)
+#define CCR_BUSWIDTH_0		0x0
+#define CCR_BUSWIDTH_1		0x1
+#define CCR_BUSWIDTH_2		0x2
+#define CCR_BUSWIDTH_4		0x3
+
+#define QSPI_AR			0x18
+#define QSPI_DR			0x20
+
+#define STM32_QSPI_MAX_MMAP_SZ	SZ_256M
+#define STM32_QSPI_MAX_NORCHIP	2
+
+#define STM32_FIFO_TIMEOUT_US	30000
+#define STM32_BUSY_TIMEOUT_US	100000
+#define STM32_ABT_TIMEOUT_US	100000
+
+struct stm32_qspi_flash {
+	u32 cs;
+	u32 presc;
+};
+
+struct stm32_qspi {
+	struct spi_controller ctrl;
+	struct device *dev;
+	void __iomem *io_base;
+	void __iomem *mm_base;
+	resource_size_t mm_size;
+	struct clk *clk;
+	u32 clk_rate;
+	struct stm32_qspi_flash flash[STM32_QSPI_MAX_NORCHIP];
+	u32 fmode;
+
+	u32 dcr_reg;
+};
+
+static void stm32_qspi_read_fifo(u8 *val, void __iomem *addr)
+{
+	*val = readb_relaxed(addr);
+}
+
+static void stm32_qspi_write_fifo(u8 *val, void __iomem *addr)
+{
+	writeb_relaxed(*val, addr);
+}
+
+static int stm32_qspi_tx_poll(struct stm32_qspi *qspi,
+			      const struct spi_mem_op *op)
+{
+	void (*tx_fifo)(u8 *val, void __iomem *addr);
+	u32 len = op->data.nbytes, sr;
+	u8 *buf;
+	int ret;
+
+	if (op->data.dir == SPI_MEM_DATA_IN) {
+		tx_fifo = stm32_qspi_read_fifo;
+		buf = op->data.buf.in;
+
+	} else {
+		tx_fifo = stm32_qspi_write_fifo;
+		buf = (u8 *)op->data.buf.out;
+	}
+
+	while (len--) {
+		ret = readl_relaxed_poll_timeout(qspi->io_base + QSPI_SR,
+						 sr, (sr & SR_FTF),
+						 STM32_FIFO_TIMEOUT_US);
+		if (ret) {
+			dev_err(qspi->dev, "fifo timeout (len:%d stat:%#x)\n",
+				len, sr);
+			return ret;
+		}
+		tx_fifo(buf++, qspi->io_base + QSPI_DR);
+	}
+
+	return 0;
+}
+
+static int stm32_qspi_tx_mm(struct stm32_qspi *qspi,
+			    const struct spi_mem_op *op)
+{
+	memcpy_fromio(op->data.buf.in, qspi->mm_base + op->addr.val,
+		      op->data.nbytes);
+	return 0;
+}
+
+static int stm32_qspi_tx(struct stm32_qspi *qspi, const struct spi_mem_op *op)
+{
+	if (!op->data.nbytes)
+		return 0;
+
+	if (qspi->fmode == CCR_FMODE_MM)
+		return stm32_qspi_tx_mm(qspi, op);
+
+	return stm32_qspi_tx_poll(qspi, op);
+}
+
+static int stm32_qspi_wait_nobusy(struct stm32_qspi *qspi)
+{
+	u32 sr;
+
+	return readl_relaxed_poll_timeout(qspi->io_base + QSPI_SR, sr,
+					  !(sr & SR_BUSY),
+					  STM32_BUSY_TIMEOUT_US);
+}
+
+static int stm32_qspi_wait_cmd(struct stm32_qspi *qspi)
+{
+	u32 sr;
+	int err;
+
+	err = readl_poll_timeout(qspi->io_base + QSPI_SR,
+				 sr, (sr & SR_TCF),
+				 STM32_FIFO_TIMEOUT_US);
+
+	if (!err) {
+		sr = readl_relaxed(qspi->io_base + QSPI_SR);
+		if (sr & SR_TEF)
+			err = -EIO;
+	}
+
+	/* clear flags */
+	writel_relaxed(FCR_CTCF | FCR_CTEF, qspi->io_base + QSPI_FCR);
+	if (!err)
+		err = stm32_qspi_wait_nobusy(qspi);
+
+	return err;
+}
+
+static int stm32_qspi_get_mode(u8 buswidth)
+{
+	if (buswidth >= 4)
+		return CCR_BUSWIDTH_4;
+
+	return buswidth;
+}
+
+static int stm32_qspi_send(struct spi_device *spi, const struct spi_mem_op *op)
+{
+	struct stm32_qspi *qspi = spi_controller_get_devdata(spi->controller);
+	struct stm32_qspi_flash *flash = &qspi->flash[spi_get_chipselect(spi, 0)];
+	u32 ccr, cr;
+	int timeout, err = 0, err_poll_status = 0;
+
+	dev_dbg(qspi->dev, "cmd:%#x mode:%d.%d.%d.%d addr:%#llx len:%#x\n",
+		op->cmd.opcode, op->cmd.buswidth, op->addr.buswidth,
+		op->dummy.buswidth, op->data.buswidth,
+		op->addr.val, op->data.nbytes);
+
+	cr = readl_relaxed(qspi->io_base + QSPI_CR);
+	cr &= ~CR_PRESC_MASK & ~CR_FSEL;
+	cr |= FIELD_PREP(CR_PRESC_MASK, flash->presc);
+	cr |= FIELD_PREP(CR_FSEL, flash->cs);
+	writel_relaxed(cr, qspi->io_base + QSPI_CR);
+
+	setbits_le32(qspi->io_base + QSPI_CR, CR_EN);
+
+	if (op->data.nbytes)
+		writel_relaxed(op->data.nbytes - 1,
+			       qspi->io_base + QSPI_DLR);
+
+	ccr = qspi->fmode;
+	ccr |= FIELD_PREP(CCR_INST_MASK, op->cmd.opcode);
+	ccr |= FIELD_PREP(CCR_IMODE_MASK,
+			  stm32_qspi_get_mode(op->cmd.buswidth));
+
+	if (op->addr.nbytes) {
+		ccr |= FIELD_PREP(CCR_ADMODE_MASK,
+				  stm32_qspi_get_mode(op->addr.buswidth));
+		ccr |= FIELD_PREP(CCR_ADSIZE_MASK, op->addr.nbytes - 1);
+	}
+
+	if (op->dummy.nbytes)
+		ccr |= FIELD_PREP(CCR_DCYC_MASK,
+				  op->dummy.nbytes * 8 / op->dummy.buswidth);
+
+	if (op->data.nbytes) {
+		ccr |= FIELD_PREP(CCR_DMODE_MASK,
+				  stm32_qspi_get_mode(op->data.buswidth));
+	}
+
+	writel_relaxed(ccr, qspi->io_base + QSPI_CCR);
+
+	if (op->addr.nbytes && qspi->fmode != CCR_FMODE_MM)
+		writel_relaxed(op->addr.val, qspi->io_base + QSPI_AR);
+
+	err = stm32_qspi_tx(qspi, op);
+
+	/*
+	 * Abort in:
+	 * -error case
+	 * -read memory map: prefetching must be stopped if we read the last
+	 *  byte of device (device size - fifo size). like device size is not
+	 *  knows, the prefetching is always stop.
+	 */
+	if (err || err_poll_status || qspi->fmode == CCR_FMODE_MM)
+		goto abort;
+
+	/* wait end of tx in indirect mode */
+	err = stm32_qspi_wait_cmd(qspi);
+	if (err)
+		goto abort;
+
+	clrbits_le32(qspi->io_base + QSPI_CR, CR_EN);
+
+	return 0;
+
+abort:
+	cr = readl_relaxed(qspi->io_base + QSPI_CR) | CR_ABORT;
+	writel_relaxed(cr, qspi->io_base + QSPI_CR);
+
+	/* wait clear of abort bit by hw */
+	timeout = readl_relaxed_poll_timeout(qspi->io_base + QSPI_CR,
+					     cr, !(cr & CR_ABORT),
+					     STM32_ABT_TIMEOUT_US);
+
+	writel_relaxed(FCR_CTCF | FCR_CSMF, qspi->io_base + QSPI_FCR);
+
+	if (err || err_poll_status || timeout)
+		dev_err(qspi->dev, "%s err:%d err_poll_status:%d abort timeout:%d\n",
+			__func__, err, err_poll_status, timeout);
+
+	clrbits_le32(qspi->io_base + QSPI_CR, CR_EN);
+
+	return err;
+}
+
+static int stm32_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
+{
+	struct stm32_qspi *qspi = spi_controller_get_devdata(mem->spi->controller);
+	int ret;
+
+	if (op->data.dir == SPI_MEM_DATA_IN && op->data.nbytes)
+		qspi->fmode = CCR_FMODE_INDR;
+	else
+		qspi->fmode = CCR_FMODE_INDW;
+
+	ret = stm32_qspi_send(mem->spi, op);
+
+	return ret;
+}
+
+static int stm32_qspi_dirmap_create(struct spi_mem_dirmap_desc *desc)
+{
+	struct stm32_qspi *qspi = spi_controller_get_devdata(desc->mem->spi->controller);
+
+	if (desc->info.op_tmpl.data.dir == SPI_MEM_DATA_OUT)
+		return -EOPNOTSUPP;
+
+	/* should never happen, as mm_base == null is an error probe exit condition */
+	if (!qspi->mm_base && desc->info.op_tmpl.data.dir == SPI_MEM_DATA_IN)
+		return -EOPNOTSUPP;
+
+	if (!qspi->mm_size)
+		return -EOPNOTSUPP;
+
+	return 0;
+}
+
+static ssize_t stm32_qspi_dirmap_read(struct spi_mem_dirmap_desc *desc,
+				      u64 offs, size_t len, void *buf)
+{
+	struct stm32_qspi *qspi = spi_controller_get_devdata(desc->mem->spi->controller);
+	struct spi_mem_op op;
+	u32 addr_max;
+	int ret;
+
+	/* make a local copy of desc op_tmpl and complete dirmap rdesc
+	 * spi_mem_op template with offs, len and *buf in  order to get
+	 * all needed transfer information into struct spi_mem_op
+	 */
+	memcpy(&op, &desc->info.op_tmpl, sizeof(struct spi_mem_op));
+	dev_dbg(qspi->dev, "%s len = 0x%zx offs = 0x%llx buf = 0x%p\n", __func__, len, offs, buf);
+
+	op.data.nbytes = len;
+	op.addr.val = desc->info.offset + offs;
+	op.data.buf.in = buf;
+
+	addr_max = op.addr.val + op.data.nbytes + 1;
+	if (addr_max < qspi->mm_size && op.addr.buswidth)
+		qspi->fmode = CCR_FMODE_MM;
+	else
+		qspi->fmode = CCR_FMODE_INDR;
+
+	ret = stm32_qspi_send(desc->mem->spi, &op);
+
+	return ret ?: len;
+}
+
+static int stm32_qspi_setup(struct spi_device *spi)
+{
+	struct spi_controller *ctrl = spi->controller;
+	struct stm32_qspi *qspi = spi_controller_get_devdata(ctrl);
+	struct stm32_qspi_flash *flash;
+	u32 presc, mode;
+
+	if (!spi->max_speed_hz)
+		return -EINVAL;
+
+	mode = spi->mode & (SPI_TX_OCTAL | SPI_RX_OCTAL);
+	if (mode && gpiod_count(qspi->dev, "cs") == -ENOENT) {
+		dev_err(qspi->dev, "spi-rx-bus-width\\/spi-tx-bus-width\\/cs-gpios\n");
+		dev_err(qspi->dev, "configuration not supported\n");
+
+		return -EINVAL;
+	}
+
+	presc = DIV_ROUND_UP(qspi->clk_rate, spi->max_speed_hz) - 1;
+
+	flash = &qspi->flash[spi_get_chipselect(spi, 0)];
+	flash->cs = spi_get_chipselect(spi, 0);
+	flash->presc = presc;
+
+	setbits_le32(qspi->io_base + QSPI_CR, CR_SSHIFT);
+
+	/* set dcr fsize to max address */
+	qspi->dcr_reg = DCR_FSIZE_MASK;
+	writel_relaxed(qspi->dcr_reg, qspi->io_base + QSPI_DCR);
+
+	return 0;
+}
+
+static const struct spi_controller_mem_ops stm32_qspi_mem_ops = {
+	.exec_op	= stm32_qspi_exec_op,
+	.dirmap_create	= stm32_qspi_dirmap_create,
+	.dirmap_read	= stm32_qspi_dirmap_read,
+};
+
+static int stm32_qspi_probe(struct device *dev)
+{
+	struct spi_controller *ctrl;
+	struct reset_control *rstc;
+	struct stm32_qspi *qspi;
+	struct resource *res;
+	int ret;
+
+	qspi = xzalloc(sizeof(*qspi));
+
+	ctrl = &qspi->ctrl;
+
+	res = dev_request_mem_resource_by_name(dev, "qspi");
+	if (IS_ERR(res))
+		return PTR_ERR(res);
+
+	qspi->io_base = IOMEM(res->start);
+
+	res = dev_request_mem_resource_by_name(dev, "qspi_mm");
+	if (IS_ERR(res))
+		return PTR_ERR(res);
+
+	qspi->mm_base = IOMEM(res->start);
+
+	qspi->mm_size = resource_size(res);
+	if (qspi->mm_size > STM32_QSPI_MAX_MMAP_SZ)
+		return -EINVAL;
+
+	qspi->clk = clk_get(dev, NULL);
+	if (IS_ERR(qspi->clk))
+		return PTR_ERR(qspi->clk);
+
+	qspi->clk_rate = clk_get_rate(qspi->clk);
+	if (!qspi->clk_rate)
+		return -EINVAL;
+
+	ret = clk_prepare_enable(qspi->clk);
+	if (ret) {
+		dev_err(dev, "can not enable the clock\n");
+		return ret;
+	}
+
+	rstc = reset_control_get(dev, NULL);
+	if (IS_ERR(rstc)) {
+		ret = PTR_ERR(rstc);
+		if (ret == -EPROBE_DEFER)
+			goto err_clk_disable;
+	} else {
+		reset_control_assert(rstc);
+		udelay(2);
+		reset_control_deassert(rstc);
+	}
+
+	qspi->dev = dev;
+	dev->priv = qspi;
+
+	/* TODO: add support for multiple bits
+	 * ctrl->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD | SPI_TX_OCTAL
+	 *	| SPI_TX_DUAL | SPI_TX_QUAD | SPI_RX_OCTAL;
+	 */
+	ctrl->setup = stm32_qspi_setup;
+	ctrl->bus_num = -1;
+	ctrl->mem_ops = &stm32_qspi_mem_ops;
+	ctrl->use_gpio_descriptors = true;
+	ctrl->num_chipselect = STM32_QSPI_MAX_NORCHIP;
+	ctrl->dev = dev;
+
+	spi_controller_set_devdata(ctrl, qspi);
+
+	ret = spi_register_controller(ctrl);
+	if (ret)
+		goto err_pm_runtime_free;
+
+	return 0;
+
+err_pm_runtime_free:
+	/* disable qspi */
+	writel_relaxed(0, qspi->io_base + QSPI_CR);
+err_clk_disable:
+	clk_disable_unprepare(qspi->clk);
+
+	return ret;
+}
+
+static void stm32_qspi_remove(struct device *dev)
+{
+	struct stm32_qspi *qspi = dev->priv;
+
+	/* disable qspi */
+	writel_relaxed(0, qspi->io_base + QSPI_CR);
+	clk_disable_unprepare(qspi->clk);
+}
+
+static const struct of_device_id stm32_qspi_match[] = {
+	{.compatible = "st,stm32f469-qspi"},
+	{}
+};
+MODULE_DEVICE_TABLE(of, stm32_qspi_match);
+
+static struct driver stm32_qspi_driver = {
+	.probe	= stm32_qspi_probe,
+	.remove = stm32_qspi_remove,
+	.name = "stm32-qspi",
+	.of_match_table = stm32_qspi_match,
+};
+device_platform_driver(stm32_qspi_driver);
+
+MODULE_AUTHOR("Ludovic Barre <ludovic.barre at st.com>");
+MODULE_DESCRIPTION("STMicroelectronics STM32 quad spi driver");
+MODULE_LICENSE("GPL v2");
-- 
2.39.5



From o.rempel at pengutronix.de  Mon Mar 31 05:30:31 2025
From: o.rempel at pengutronix.de (Oleksij Rempel)
Date: Mon, 31 Mar 2025 14:30:31 +0200
Subject: [PATCH v1 3/4] arm: boards: protonic-stm32mp: fix stack corruption by passing correct ctx to stm32_bsec_optee_ta_close()
In-Reply-To: <20250331123032.626219-1-o.rempel@pengutronix.de>
References: <20250331123032.626219-1-o.rempel@pengutronix.de>
Message-ID: <20250331123032.626219-3-o.rempel@pengutronix.de>

The `stm32_bsec_optee_ta_open()` function initializes a `struct
tee_context *ctx` through a pointer-to-pointer. However, its counterpart
`stm32_bsec_optee_ta_close()` expects the context pointer directly - not
its address.

Passing `&ctx` (i.e., a `struct tee_context **`) caused incorrect access,
leading to stack corruption. This was detected by the refcounter infrastructure.

Fix this by passing `ctx` directly to `stm32_bsec_optee_ta_close()`.

This bug affected both STM32MP1 and STM32MP13 board implementations.

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 arch/arm/boards/protonic-stm32mp1/board.c  | 4 ++--
 arch/arm/boards/protonic-stm32mp13/board.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boards/protonic-stm32mp1/board.c b/arch/arm/boards/protonic-stm32mp1/board.c
index 86cda1676b48..4c8ad9e53388 100644
--- a/arch/arm/boards/protonic-stm32mp1/board.c
+++ b/arch/arm/boards/protonic-stm32mp1/board.c
@@ -121,12 +121,12 @@ static int prt_stm32_read_serial(struct device *dev)
 
 	serial[PRT_STM32_SERIAL_LEN] = 0;
 
-	stm32_bsec_optee_ta_close(&ctx);
+	stm32_bsec_optee_ta_close(ctx);
 
 	return prt_stm32_set_serial(dev, serial);
 
 exit_pta_read:
-	stm32_bsec_optee_ta_close(&ctx);
+	stm32_bsec_optee_ta_close(ctx);
 	dev_err(dev, "Failed to read serial: %pe\n", ERR_PTR(ret));
 	return ret;
 }
diff --git a/arch/arm/boards/protonic-stm32mp13/board.c b/arch/arm/boards/protonic-stm32mp13/board.c
index d48a6dbf8e44..4268db2b384c 100644
--- a/arch/arm/boards/protonic-stm32mp13/board.c
+++ b/arch/arm/boards/protonic-stm32mp13/board.c
@@ -104,12 +104,12 @@ static int prt_stm32_read_serial(struct device *dev)
 
 	serial[PRT_STM32_SERIAL_LEN] = 0;
 
-	stm32_bsec_optee_ta_close(&ctx);
+	stm32_bsec_optee_ta_close(ctx);
 
 	return prt_stm32_set_serial(dev, serial);
 
 exit_pta_read:
-	stm32_bsec_optee_ta_close(&ctx);
+	stm32_bsec_optee_ta_close(ctx);
 	dev_err(dev, "Failed to read serial: %pe\n", ERR_PTR(ret));
 	return ret;
 }
-- 
2.39.5



From o.rempel at pengutronix.de  Mon Mar 31 05:30:30 2025
From: o.rempel at pengutronix.de (Oleksij Rempel)
Date: Mon, 31 Mar 2025 14:30:30 +0200
Subject: [PATCH v1 2/4] arm: boards: protonic-stm32mp13: Use unique board driver name
In-Reply-To: <20250331123032.626219-1-o.rempel@pengutronix.de>
References: <20250331123032.626219-1-o.rempel@pengutronix.de>
Message-ID: <20250331123032.626219-2-o.rempel@pengutronix.de>

The driver was previously named "board-protonic-stm32", which is also
used by another board support file. This can lead to confusion when
both drivers are loaded, as it's hard to distinguish them in logs or
drvinfo output.

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 arch/arm/boards/protonic-stm32mp13/board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boards/protonic-stm32mp13/board.c b/arch/arm/boards/protonic-stm32mp13/board.c
index 0173e3628dc3..d48a6dbf8e44 100644
--- a/arch/arm/boards/protonic-stm32mp13/board.c
+++ b/arch/arm/boards/protonic-stm32mp13/board.c
@@ -285,7 +285,7 @@ static const struct of_device_id prt_stm32_of_match[] = {
 BAREBOX_DEEP_PROBE_ENABLE(prt_stm32_of_match);
 
 static struct driver prt_stm32_board_driver = {
-	.name = "board-protonic-stm32",
+	.name = "board-protonic-stm32mp13",
 	.probe = prt_stm32_probe,
 	.of_compatible = prt_stm32_of_match,
 };
-- 
2.39.5



From o.rempel at pengutronix.de  Mon Mar 31 05:30:32 2025
From: o.rempel at pengutronix.de (Oleksij Rempel)
Date: Mon, 31 Mar 2025 14:30:32 +0200
Subject: [PATCH v1 4/4] arm: boards: protonic-stm32mp: free shift register GPIOs after use
In-Reply-To: <20250331123032.626219-1-o.rempel@pengutronix.de>
References: <20250331123032.626219-1-o.rempel@pengutronix.de>
Message-ID: <20250331123032.626219-4-o.rempel@pengutronix.de>

The GPIOs used to access the external shift register (PL_N, CP, Q7) are
shared with other functionality - including the LED heartbeat driver.

After the board code completes reading the shift register during early
boot, the GPIOs are no longer needed for that purpose. Free them
immediately to avoid resource conflicts and allow reuse (e.g., for
LEDs or other drivers).

This change applies to both STM32MP1 and STM32MP13 board code.

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 arch/arm/boards/protonic-stm32mp1/board.c  | 8 ++++++++
 arch/arm/boards/protonic-stm32mp13/board.c | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/arch/arm/boards/protonic-stm32mp1/board.c b/arch/arm/boards/protonic-stm32mp1/board.c
index 4c8ad9e53388..9116876ad59f 100644
--- a/arch/arm/boards/protonic-stm32mp1/board.c
+++ b/arch/arm/boards/protonic-stm32mp1/board.c
@@ -230,6 +230,13 @@ static void prt_stm32_read_shift_reg(struct device *dev)
 	gpio_set_value(PRT_STM32_GPIO_HWID_CP, 1);
 }
 
+static void prt_stm32_put_gpios(void)
+{
+	gpio_free(PRT_STM32_GPIO_HWID_PL_N);
+	gpio_free(PRT_STM32_GPIO_HWID_CP);
+	gpio_free(PRT_STM32_GPIO_HWID_Q7);
+}
+
 static int prt_stm32_probe(struct device *dev)
 {
 	const struct prt_stm32_machine_data *dcfg;
@@ -247,6 +254,7 @@ static int prt_stm32_probe(struct device *dev)
 	if (!(dcfg->flags & PRT_STM32_NO_SHIFT_REG)) {
 		prt_stm32_init_shift_reg(dev);
 		prt_stm32_read_shift_reg(dev);
+		prt_stm32_put_gpios();
 	}
 
 	for (i = 0; i < ARRAY_SIZE(prt_stm32_boot_devs); i++) {
diff --git a/arch/arm/boards/protonic-stm32mp13/board.c b/arch/arm/boards/protonic-stm32mp13/board.c
index 4268db2b384c..fe251b9e7764 100644
--- a/arch/arm/boards/protonic-stm32mp13/board.c
+++ b/arch/arm/boards/protonic-stm32mp13/board.c
@@ -214,6 +214,13 @@ static void prt_stm32_read_shift_reg(struct device *dev)
 	gpio_set_value(PRT_STM32_GPIO_HWID_CP, 1);
 }
 
+static void prt_stm32_put_gpios(void)
+{
+	gpio_free(PRT_STM32_GPIO_HWID_PL_N);
+	gpio_free(PRT_STM32_GPIO_HWID_CP);
+	gpio_free(PRT_STM32_GPIO_HWID_Q7);
+}
+
 static int prt_stm32_probe(struct device *dev)
 {
 	const struct prt_stm32_machine_data *dcfg;
@@ -229,6 +236,7 @@ static int prt_stm32_probe(struct device *dev)
 	prt_stm32_read_serial(dev);
 	prt_stm32_init_shift_reg(dev);
 	prt_stm32_read_shift_reg(dev);
+	prt_stm32_put_gpios();
 
 	for (i = 0; i < ARRAY_SIZE(prt_stm32_boot_devs); i++) {
 		const struct prt_stm32_boot_dev *bd = &prt_stm32_boot_devs[i];
-- 
2.39.5



From o.rempel at pengutronix.de  Mon Mar 31 05:30:29 2025
From: o.rempel at pengutronix.de (Oleksij Rempel)
Date: Mon, 31 Mar 2025 14:30:29 +0200
Subject: [PATCH v1 1/4] arm: boards: protonic-stm32mp13: Add support for MECT1S board
Message-ID: <20250331123032.626219-1-o.rempel@pengutronix.de>

From: David Jander <david at protonic.nl>

Introduce support for the Protonic MECT1S r1 board based on STM32MP133.

Signed-off-by: David Jander <david at protonic.nl>
Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 arch/arm/boards/protonic-stm32mp13/board.c    |   5 +
 arch/arm/boards/protonic-stm32mp13/lowlevel.c |  14 +
 arch/arm/dts/Makefile                         |   4 +-
 arch/arm/dts/stm32mp133c-mect1s.dts           |  52 +++
 arch/arm/dts/stm32mp133c-mect1s.dtsi          | 360 ++++++++++++++++++
 images/Makefile.stm32mp                       |   1 +
 6 files changed, 435 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/stm32mp133c-mect1s.dts
 create mode 100644 arch/arm/dts/stm32mp133c-mect1s.dtsi

diff --git a/arch/arm/boards/protonic-stm32mp13/board.c b/arch/arm/boards/protonic-stm32mp13/board.c
index ca035cc6773c..0173e3628dc3 100644
--- a/arch/arm/boards/protonic-stm32mp13/board.c
+++ b/arch/arm/boards/protonic-stm32mp13/board.c
@@ -273,8 +273,13 @@ static const struct prt_stm32_machine_data prt_stm32_prihmb = {
 	.flags = PRT_STM32_BOOTSRC_SD | PRT_STM32_BOOTSRC_EMMC,
 };
 
+static const struct prt_stm32_machine_data prt_stm32_mect1sr1 = {
+	.flags = PRT_STM32_BOOTSRC_SPI_NOR,
+};
+
 static const struct of_device_id prt_stm32_of_match[] = {
 	{ .compatible = "pri,prihmb", .data = &prt_stm32_prihmb },
+	{ .compatible = "prt,mect1sr1", .data = &prt_stm32_mect1sr1 },
 	{ /* sentinel */ },
 };
 BAREBOX_DEEP_PROBE_ENABLE(prt_stm32_of_match);
diff --git a/arch/arm/boards/protonic-stm32mp13/lowlevel.c b/arch/arm/boards/protonic-stm32mp13/lowlevel.c
index 9de02402f518..71e658934383 100644
--- a/arch/arm/boards/protonic-stm32mp13/lowlevel.c
+++ b/arch/arm/boards/protonic-stm32mp13/lowlevel.c
@@ -6,6 +6,7 @@
 #include <mach/stm32mp/entry.h>
 
 extern char __dtb_z_stm32mp133c_prihmb_start[];
+extern char __dtb_z_stm32mp133c_mect1s_start[];
 
 ENTRY_FUNCTION(start_stm32mp133c_prihmb, r0, r1, r2)
 {
@@ -20,3 +21,16 @@ ENTRY_FUNCTION(start_stm32mp133c_prihmb, r0, r1, r2)
 
 	stm32mp1_barebox_entry(fdt);
 }
+
+ENTRY_FUNCTION(start_stm32mp133c_mect1s, r0, r1, r2)
+{
+	void *fdt;
+
+	stm32mp_cpu_lowlevel_init();
+
+	putc_ll('>');
+
+	fdt = __dtb_z_stm32mp133c_mect1s_start + get_runtime_offset();
+
+	stm32mp1_barebox_entry(fdt);
+}
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index b3ff2e738b48..3922e0fb5c86 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -118,7 +118,9 @@ lwl-$(CONFIG_MACH_PROTONIC_STM32MP1) += \
 	stm32mp151-mecio1.dtb.o \
 	stm32mp151-mect1s.dtb.o \
 	stm32mp151c-plyaqm.dtb.o
-lwl-$(CONFIG_MACH_PROTONIC_STM32MP13) += stm32mp133c-prihmb.dtb.o
+lwl-$(CONFIG_MACH_PROTONIC_STM32MP13) += \
+	stm32mp133c-mect1s.dtb.o \
+	stm32mp133c-prihmb.dtb.o
 lwl-$(CONFIG_MACH_RADXA_ROCK) += rk3188-radxarock.dtb.o
 lwl-$(CONFIG_MACH_RADXA_ROCK3) += rk3568-rock-3a.dtb.o
 lwl-$(CONFIG_MACH_RADXA_ROCK5) += rk3588-rock-5b.dtb.o
diff --git a/arch/arm/dts/stm32mp133c-mect1s.dts b/arch/arm/dts/stm32mp133c-mect1s.dts
new file mode 100644
index 000000000000..9cc971b5d4ca
--- /dev/null
+++ b/arch/arm/dts/stm32mp133c-mect1s.dts
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-3-Clause)
+// SPDX-FileCopyrightText: 2025 David Jander, Protonic Holland
+/dts-v1/;
+
+#include "stm32mp133c-mect1s.dtsi"
+#include "stm32mp131.dtsi"
+
+#ifdef CONFIG_BOOTM_FITIMAGE_PUBKEY
+#include CONFIG_BOOTM_FITIMAGE_PUBKEY
+#endif
+
+/ {
+	chosen {
+		stdout-path = "serial0:1500000n8";
+
+		environment-qspi {
+			compatible = "barebox,environment";
+			device-path = &barebox_env;
+			status = "disabled";
+		};
+	};
+};
+
+&qspi {
+	flash at 0 {
+		partitions {
+			compatible = "fixed-partitions";
+			#address-cells = <1>;
+			#size-cells = <1>;
+
+			tf-a at 0 {
+				label = "tf-a-primary";
+				reg = <0x000000 0x40000>; /* 256 KiB */
+			};
+
+			tf-a at 40000 {
+				label = "tf-a-secondary";
+				reg = <0x40000 0x40000>; /* 256 KiB */
+			};
+
+			barebox at 80000 {
+				label = "barebox-fip";
+				reg = <0x80000 0x170000>;
+			};
+
+			barebox_env: barebox-env at 1F0000 {
+				label = "barebox-environment";
+				reg = <0x1f0000 0x10000>; /* 64 KiB */
+			};
+		};
+	};
+};
diff --git a/arch/arm/dts/stm32mp133c-mect1s.dtsi b/arch/arm/dts/stm32mp133c-mect1s.dtsi
new file mode 100644
index 000000000000..ca179a636374
--- /dev/null
+++ b/arch/arm/dts/stm32mp133c-mect1s.dtsi
@@ -0,0 +1,360 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
+/dts-v1/;
+
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/input/input.h>
+#include <dt-bindings/leds/common.h>
+#include <dt-bindings/regulator/st,stm32mp13-regulator.h>
+#include <arm/st/stm32mp133.dtsi>
+#include <arm/st/stm32mp131.dtsi>
+#include <arm/st/stm32mp13xc.dtsi>
+#include <arm/st/stm32mp13-pinctrl.dtsi>
+
+/ {
+	model = "Protonic MECT1S r1 board";
+	compatible = "prt,mect1sr1", "st,stm32mp133";
+
+	aliases {
+		mdio-gpio0 = &mdio0;
+		ethernet0 = &ethernet1;
+		serial0 = &uart4;
+	};
+
+	memory at c0000000 {
+		device_type = "memory";
+		reg = <0xc0000000 0x10000000>;
+	};
+
+	reserved-memory {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+
+		optee at ce000000 {
+			reg = <0xce000000 0x02000000>;
+			no-map;
+		};
+	};
+
+	chosen {
+		stdout-path = "serial0:1500000n8";
+	};
+
+	clock_sja1105: clock-sja1105 {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <25000000>;
+	};
+
+	leds {
+		compatible = "gpio-leds";
+
+		led-green {
+			function = LED_FUNCTION_HEARTBEAT;
+			gpios = <&gpioa 14 GPIO_ACTIVE_LOW>;
+			linux,default-trigger = "heartbeat";
+			default-state = "off";
+		};
+	};
+
+	reg_3v3: regulator-3v3 {
+		compatible = "regulator-fixed";
+		regulator-name = "3v3";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
+	};
+
+	spi_gpio: spi-gpio-0 {
+		compatible = "spi-gpio";
+		sck-gpios = <&gpiob 10 GPIO_ACTIVE_HIGH>;
+		mosi-gpios = <&gpioa 8 GPIO_ACTIVE_HIGH>;
+		miso-gpios = <&gpiob 5 GPIO_ACTIVE_HIGH>;
+		cs-gpios = <&gpioa 11 GPIO_ACTIVE_LOW>;
+		num-chipselects = <1>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
+};
+
+&iwdg2 {
+	timeout-sec = <32>;
+	status = "okay";
+};
+
+&ethernet1 {
+	status = "okay";
+	pinctrl-0 = <&ethernet0_rgmii_pins_x>;
+	pinctrl-1 = <&ethernet0_rgmii_sleep_pins_x>;
+	pinctrl-names = "default", "sleep";
+	phy-mode = "rmii";
+	max-speed = <100>;
+	st,eth-clk-sel;
+
+	fixed-link {
+		speed = <100>;
+		full-duplex;
+	};
+
+	mdio0: mdio {
+		 #address-cells = <1>;
+		 #size-cells = <0>;
+		 compatible = "snps,dwmac-mdio";
+	};
+};
+
+&mdio0 {
+	/* All this DP83TG720R PHYs can't be probed before switch at 0 is
+	 * probed so we need to use compatible with PHYid
+	 */
+	/* TI DP83TG720R */
+	t1_phy0: ethernet-phy at 8 {
+		compatible = "ethernet-phy-id2000.a284";
+		reg = <8>;
+		interrupts-extended = <&gpioc 10 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&gpiof 0 GPIO_ACTIVE_LOW>;
+		reset-assert-us = <10>;
+		reset-deassert-us = <35>;
+	};
+
+	/* TI DP83TG720R */
+	t1_phy1: ethernet-phy at c {
+		compatible = "ethernet-phy-id2000.a284";
+		reg = <12>;
+		interrupts-extended = <&gpioa 4 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&gpioa 3 GPIO_ACTIVE_LOW>;
+		reset-assert-us = <10>;
+		reset-deassert-us = <35>;
+	};
+
+	/* TI DP83TG720R */
+	t1_phy2: ethernet-phy at 4 {
+		compatible = "ethernet-phy-id2000.a284";
+		reg = <4>;
+		interrupts-extended = <&gpiog 12 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&gpioa 0 GPIO_ACTIVE_LOW>;
+		reset-assert-us = <10>;
+		reset-deassert-us = <35>;
+	};
+
+	/* TI DP83TG720R */
+	t1_phy3: ethernet-phy at d {
+		compatible = "ethernet-phy-id2000.a284";
+		reg = <13>;
+		interrupts-extended = <&gpiog 3 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&gpiod 7 GPIO_ACTIVE_LOW>;
+		reset-assert-us = <10000>;
+		reset-deassert-us = <1000>;
+	};
+};
+
+&spi_gpio {
+	switch at 0 {
+		compatible = "nxp,sja1105q";
+		reg = <0>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		spi-max-frequency = <1000000>;
+		spi-rx-delay-us = <1>;
+		spi-tx-delay-us = <1>;
+		spi-cpha;
+
+		reset-gpios = <&gpioa 10 GPIO_ACTIVE_LOW>;
+
+		clocks = <&clock_sja1105>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port at 0 {
+				reg = <0>;
+				label = "t10";
+				phy-mode = "rgmii-id";
+				phy-handle = <&t1_phy0>;
+			};
+
+			port at 1 {
+				reg = <1>;
+				label = "t11";
+				phy-mode = "rgmii-id";
+				phy-handle = <&t1_phy1>;
+			};
+
+			port at 2 {
+				reg = <2>;
+				label = "t12";
+				phy-mode = "rgmii-id";
+				phy-handle = <&t1_phy2>;
+			};
+
+			port at 3 {
+				reg = <3>;
+				label = "t13";
+				phy-mode = "rgmii-id";
+				phy-handle = <&t1_phy3>;
+			};
+
+			port at 4 {
+				reg = <4>;
+				label = "cpu";
+				ethernet = <&ethernet1>;
+				phy-mode = "rmii";
+
+				/* RGMII mode is not working properly, using
+				 * RMII instead. */
+				fixed-link {
+					speed = <100>;
+					full-duplex;
+				};
+			};
+		};
+	};
+};
+
+&qspi {
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&qspi_clk_pins_a
+		     &qspi_bk1_pins_a
+		     &qspi_cs1_pins_a>;
+	pinctrl-1 = <&qspi_clk_sleep_pins_a
+		     &qspi_bk1_sleep_pins_a
+		     &qspi_cs1_sleep_pins_a>;
+	status = "okay";
+
+	flash at 0 {
+		compatible = "jedec,spi-nor";
+		reg = <0>;
+		spi-rx-bus-width = <4>;
+		spi-max-frequency = <1000000>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+	};
+};
+
+&{qspi_bk1_pins_a/pins} {
+	/delete-property/ bias-disable;
+	bias-pull-up;
+	drive-push-pull;
+	slew-rate = <1>;
+};
+
+&uart4 {
+	pinctrl-names = "default", "sleep", "idle";
+	pinctrl-0 = <&uart4_pins_a>;
+	pinctrl-1 = <&uart4_sleep_pins_a>;
+	pinctrl-2 = <&uart4_idle_pins_a>;
+	/delete-property/dmas;
+	/delete-property/dma-names;
+	status = "okay";
+};
+
+&usbh_ehci {
+	status = "okay";
+};
+
+&usbotg_hs {
+	phys = <&usbphyc_port1 0>;
+	phy-names = "usb2-phy";
+	status = "okay";
+	dr_mode = "host";
+	g-tx-fifo-size = <128 128 128 16>;
+};
+
+&usbphyc {
+	status = "okay";
+};
+
+&usbphyc_port1 {
+	phy-supply = <&reg_3v3>;
+	st,current-boost-microamp = <1000>;
+	st,decrease-hs-slew-rate;
+	st,tune-hs-dc-level = <2>;
+	st,enable-hs-rftime-reduction;
+	st,trim-hs-current = <11>;
+	st,trim-hs-impedance = <2>;
+	st,tune-squelch-level = <1>;
+	st,enable-hs-rx-gain-eq;
+	st,no-hs-ftime-ctrl;
+	st,no-lsfs-sc;
+};
+
+&pinctrl {
+	ethernet0_rgmii_pins_x: rgmii-0 {
+		pins1 {
+			/* ETH_RGMII_CLK125 */
+			pinmux = <STM32_PINMUX('F', 7, AF10)>,
+				/* ETH_RGMII_GTX_CLK */
+				<STM32_PINMUX('C', 1, AF11)>,
+				/* ETH_RGMII_TXD0 */
+				<STM32_PINMUX('G', 13, AF11)>,
+				/* ETH_RGMII_TXD1 */
+				<STM32_PINMUX('G', 14, AF11)>,
+				/* ETH_RGMII_TXD2 */
+				<STM32_PINMUX('C', 2, AF11)>,
+				/* ETH_RGMII_TXD3 */
+				<STM32_PINMUX('E', 5, AF10)>,
+				/* ETH_RGMII_TX_CTL */
+				<STM32_PINMUX('B', 11, AF11)>,
+				/* ETH_MDIO */
+				<STM32_PINMUX('A', 2, AF11)>,
+				/* ETH_MDC */
+				<STM32_PINMUX('G', 2, AF11)>;
+
+			bias-disable;
+			drive-push-pull;
+			slew-rate = <3>;
+		};
+
+		pins2 {
+			/* ETH_RGMII_RXD0 */
+			pinmux = <STM32_PINMUX('C', 4, AF11)>,
+				/* ETH_RGMII_RXD1 */
+				<STM32_PINMUX('C', 5, AF11)>,
+				/* ETH_RGMII_RXD2 */
+				<STM32_PINMUX('B', 0, AF11)>,
+				/* ETH_RGMII_RXD3 */
+				<STM32_PINMUX('B', 1, AF11)>,
+				/* ETH_RGMII_RX_CLK */
+				<STM32_PINMUX('A', 1, AF11)>,
+				/* ETH_RGMII_RX_CTL */
+				<STM32_PINMUX('A', 7, AF11)>;
+
+			bias-disable;
+		};
+	};
+
+	ethernet0_rgmii_sleep_pins_x: rgmii-sleep-0 {
+		pins1 {
+			/* ETH_RGMII_CLK125 */
+			pinmux = <STM32_PINMUX('F', 7, ANALOG)>,
+				/* ETH_RGMII_GTX_CLK */
+				<STM32_PINMUX('C', 1, ANALOG)>,
+				/* ETH_RGMII_TXD0 */
+				<STM32_PINMUX('G', 13, ANALOG)>,
+				/* ETH_RGMII_TXD1 */
+				<STM32_PINMUX('G', 14, ANALOG)>,
+				/* ETH_RGMII_TXD2 */
+				<STM32_PINMUX('C', 2, ANALOG)>,
+				/* ETH_RGMII_TXD3 */
+				<STM32_PINMUX('E', 5, ANALOG)>,
+				/* ETH_RGMII_TX_CTL */
+				<STM32_PINMUX('B', 11, ANALOG)>,
+				/* ETH_MDIO */
+				<STM32_PINMUX('A', 2, ANALOG)>,
+				/* ETH_MDC */
+				<STM32_PINMUX('G', 2, ANALOG)>,
+				/* ETH_RGMII_RXD0 */
+				<STM32_PINMUX('C', 4, ANALOG)>,
+				/* ETH_RGMII_RXD1 */
+				<STM32_PINMUX('C', 5, ANALOG)>,
+				/* ETH_RGMII_RXD2 */
+				<STM32_PINMUX('B', 0, ANALOG)>,
+				/* ETH_RGMII_RXD3 */
+				<STM32_PINMUX('B', 2, ANALOG)>,
+				/* ETH_RGMII_RX_CLK */
+				<STM32_PINMUX('A', 1, ANALOG)>,
+				/* ETH_RGMII_RX_CTL */
+				<STM32_PINMUX('A', 7, ANALOG)>;
+		};
+	};
+};
diff --git a/images/Makefile.stm32mp b/images/Makefile.stm32mp
index ba18714c69d8..4727bb093783 100644
--- a/images/Makefile.stm32mp
+++ b/images/Makefile.stm32mp
@@ -42,6 +42,7 @@ $(call build_stm32mp_image, CONFIG_MACH_PROTONIC_STM32MP1, start_mecio1, mecio1)
 $(call build_stm32mp_image, CONFIG_MACH_PROTONIC_STM32MP1, start_mect1s, mect1s)
 $(call build_stm32mp_image, CONFIG_MACH_PROTONIC_STM32MP1, start_stm32mp151c_plyaqm, stm32mp151c-plyaqm)
 $(call build_stm32mp_image, CONFIG_MACH_PROTONIC_STM32MP13, start_stm32mp133c_prihmb, stm32mp133c-prihmb)
+$(call build_stm32mp_image, CONFIG_MACH_PROTONIC_STM32MP13, start_stm32mp133c_mect1s, stm32mp133c-mect1s)
 
 $(call build_stm32mp_image, CONFIG_MACH_SEEED_ODYSSEY, start_stm32mp157c_seeed_odyssey, stm32mp157c-seeed-odyssey)
 
-- 
2.39.5



From eagle.alexander923 at gmail.com  Mon Mar 31 05:39:48 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Mon, 31 Mar 2025 15:39:48 +0300
Subject: [PATCH] clk: rockchip: rk3588: make refclko25m_ethX critical
Message-ID: <20250331123948.337747-1-eagle.alexander923@gmail.com>

Ethernet phys normally need a 25MHz refclk input. On a lot of boards
this is done with a dedicated 25MHz crystal. But the rk3588 CRU also
provides a means for that via the refclko25m_ethX clock outputs that
can be used for that function.

The mdio bus normally probes devices on the bus at runtime, by reading
specific phy registers. This requires the phy to be running and thus
also being supplied by its reference clock.

While there exist the possibility and dt-binding to declare these
input clocks for each phy in the phy-dt-node, this is only relevant
_after_ the phy has been detected and during the drivers probe-run.

This results in a chicken-and-egg-problem. The refclks in the CRU are
running on boot of course, but phy-probing can very well happen after
clk_disable_unused has run.

In the past I tried to make clock-handling part of the mdio bus code [0]
but that wasn't very well received, due to it being specific to OF and
clocks with the consensus being that resources needed for detection
need to be enabled before.

So to make probing ethernet phys using the internal refclks possible,
make those 2 clocks critical.

[0] https://lore.kernel.org/netdev/13590315.F0gNSz5aLb at diego/T/

Signed-off-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
---
 drivers/clk/rockchip/clk-rk3588.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/rockchip/clk-rk3588.c b/drivers/clk/rockchip/clk-rk3588.c
index 736ce4a543..f6d16ed0cf 100644
--- a/drivers/clk/rockchip/clk-rk3588.c
+++ b/drivers/clk/rockchip/clk-rk3588.c
@@ -794,10 +794,10 @@ static struct rockchip_clk_branch rk3588_clk_branches[] __initdata = {
 	COMPOSITE(MCLK_GMAC0_OUT, "mclk_gmac0_out", gpll_cpll_p, 0,
 			RK3588_CLKSEL_CON(15), 7, 1, MFLAGS, 0, 7, DFLAGS,
 			RK3588_CLKGATE_CON(5), 3, GFLAGS),
-	COMPOSITE(REFCLKO25M_ETH0_OUT, "refclko25m_eth0_out", gpll_cpll_p, 0,
+	COMPOSITE(REFCLKO25M_ETH0_OUT, "refclko25m_eth0_out", gpll_cpll_p, CLK_IS_CRITICAL,
 			RK3588_CLKSEL_CON(15), 15, 1, MFLAGS, 8, 7, DFLAGS,
 			RK3588_CLKGATE_CON(5), 4, GFLAGS),
-	COMPOSITE(REFCLKO25M_ETH1_OUT, "refclko25m_eth1_out", gpll_cpll_p, 0,
+	COMPOSITE(REFCLKO25M_ETH1_OUT, "refclko25m_eth1_out", gpll_cpll_p, CLK_IS_CRITICAL,
 			RK3588_CLKSEL_CON(16), 7, 1, MFLAGS, 0, 7, DFLAGS,
 			RK3588_CLKGATE_CON(5), 5, GFLAGS),
 	COMPOSITE(CLK_CIFOUT_OUT, "clk_cifout_out", gpll_cpll_24m_spll_p, 0,
-- 
2.38.2



From bst at pengutronix.de  Mon Mar 31 05:49:26 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Mon, 31 Mar 2025 14:49:26 +0200
Subject: [PATCH 3/9] doc: bootchooser: clarify marking boot successful from barebox
In-Reply-To: <20250331124932.901033-1-bst@pengutronix.de>
References: <20250331124932.901033-1-bst@pengutronix.de>
Message-ID: <20250331124932.901033-3-bst@pengutronix.de>

The previous description sounds confusing: the bootchooser framework
itself is not able to detect good or bad boots. Rephrase that sentence.

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 Documentation/user/bootchooser.rst | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
index fc36f8fb1ca..f9763a1fe14 100644
--- a/Documentation/user/bootchooser.rst
+++ b/Documentation/user/bootchooser.rst
@@ -120,13 +120,12 @@ it can report this to bootchooser from Linux userspace using the
   barebox-state -n system_state -s bootstate.system1.remaining_attempts=3
   barebox-state -s system1.remaining_attempts=3
 
-If instead the bootchooser can detect a failed boot itself using the
-:ref:`reset reason <reset_reason>` (WDG), one can mark the boot successful
-using the barebox :ref:`bootchoser command <command_bootchooser>`::
+Alternatively barebox can be configured to mark the last boot successful based
+on the :ref:`reset reason <reset_reason>` (i.e. != WDG) using the
+:ref:`bootchooser command <command_bootchooser>`::
 
   bootchooser -s
 
-to mark the last boot successful.
 This will reset the ``remaining_attempts`` counter of the *last chosen* slot to
 its default value (``reset_attempts``).
 
-- 
2.39.5



From bst at pengutronix.de  Mon Mar 31 05:49:29 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Mon, 31 Mar 2025 14:49:29 +0200
Subject: [PATCH 6/9] doc: bootchooser: rephrase global.bootchooser.reset_priorities description
In-Reply-To: <20250331124932.901033-1-bst@pengutronix.de>
References: <20250331124932.901033-1-bst@pengutronix.de>
Message-ID: <20250331124932.901033-6-bst@pengutronix.de>

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 Documentation/user/bootchooser.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
index d3469e7480a..01c5c86edb6 100644
--- a/Documentation/user/bootchooser.rst
+++ b/Documentation/user/bootchooser.rst
@@ -145,11 +145,11 @@ options not specific to any boot target.
   * ``all-zero``: If the ``remaining_attempts`` counters of all enabled targets
     are zero.
 ``global.bootchooser.reset_priorities``
-  A space-separated list of events that cause *bootchooser* to reset the priorities of
-  all boot targets. Possible values:
+  A space-separated list of conditions (checked during bootchooser start) that
+  shall cause the ``priority``  of all boot targets to be reset. Possible values:
 
-  * empty: priorities will never be reset
-  * ``all-zero``: priorities will be reset when all targets have zero priority
+  * empty: Priorities will never be reset.
+  * ``all-zero``: If all boot targets have zero ``priority``.
 ``global.bootchooser.retry``
   If set to 1, *bootchooser* retries booting until one succeeds or no more valid
   boot targets exist.
-- 
2.39.5



From bst at pengutronix.de  Mon Mar 31 05:49:27 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Mon, 31 Mar 2025 14:49:27 +0200
Subject: [PATCH 4/9] doc: bootchooser: don't recommend NV backend
In-Reply-To: <20250331124932.901033-1-bst@pengutronix.de>
References: <20250331124932.901033-1-bst@pengutronix.de>
Message-ID: <20250331124932.901033-4-bst@pengutronix.de>

The NV storage backend for bootchooser variables is featured rather
prominently, but in fact it should not be used for anything else than
maybe evaluation.

This matches the reasoning of commit 48091deb4b9 ("bootchooser: warn if
NV is used instead of barebox-state").

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 Documentation/user/bootchooser.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
index f9763a1fe14..b54e6873bc8 100644
--- a/Documentation/user/bootchooser.rst
+++ b/Documentation/user/bootchooser.rst
@@ -13,8 +13,9 @@ and implements an algorithm which selects the highest priority target to boot.
 
 Making *bootchooser* work requires a fixed set of configuration parameters
 and a storage backend for saving status information.
-Currently supported storage backends are either nv variables or the
-barebox *state* framework.
+Currently supported storage backends are either the barebox *state* framework
+or nv variables (fallback only, not meant for production, because it's not
+power-fail safe).
 
 *Bootchooser* itself is executed as a normal barebox boot target, i.e. one
 can start it via::
-- 
2.39.5



From bst at pengutronix.de  Mon Mar 31 05:49:25 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Mon, 31 Mar 2025 14:49:25 +0200
Subject: [PATCH 2/9] doc: bootchooser: drop confusing description for "remaining_attempts"
In-Reply-To: <20250331124932.901033-1-bst@pengutronix.de>
References: <20250331124932.901033-1-bst@pengutronix.de>
Message-ID: <20250331124932.901033-2-bst@pengutronix.de>

"Every attempt counter reaches zero" is not how redundant booting is
meant to be used. Usually userspace or the next barebox boot increments
the counter again. This sentence is at least confusing, so drop it
altogether.

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 Documentation/user/bootchooser.rst | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
index e318b245c14..fc36f8fb1ca 100644
--- a/Documentation/user/bootchooser.rst
+++ b/Documentation/user/bootchooser.rst
@@ -70,9 +70,7 @@ means the boot target is disabled.
 
 When booting, *bootchooser* starts the boot target with the highest ``priority`` that
 has a non-zero ``remaining_attempts`` counter. With every start of a boot target the
-``remaining_attempts`` counter of this boot target is decremented by one. This means
-every boot target's ``remaining_attempts`` counter reaches zero sooner or later and
-the boot target won't be booted anymore.
+``remaining_attempts`` counter of this boot target is decremented by one.
 This behavior assures that one can retry booting a target a limited number of
 times to handle temporary issues (such as power outage) and optionally allows
 booting a fallback in case of a permanent failure.
-- 
2.39.5



From bst at pengutronix.de  Mon Mar 31 05:49:31 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Mon, 31 Mar 2025 14:49:31 +0200
Subject: [PATCH 8/9] doc: bootchooser: rephrase scenarios
In-Reply-To: <20250331124932.901033-1-bst@pengutronix.de>
References: <20250331124932.901033-1-bst@pengutronix.de>
Message-ID: <20250331124932.901033-8-bst@pengutronix.de>

- The description of the systems and the requirements got mixed up.
  Document both separately.
- Make it clear that only bootchooser boot targets are meant here, not
  global.boot.default.
- Rephrase some other parts of the scenarios section to improve
  readability.

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 Documentation/user/bootchooser.rst | 67 ++++++++++++++++++------------
 1 file changed, 40 insertions(+), 27 deletions(-)

diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
index 53bf5f329fd..0c236de22fb 100644
--- a/Documentation/user/bootchooser.rst
+++ b/Documentation/user/bootchooser.rst
@@ -258,13 +258,23 @@ anything higher than one.
 Scenario 1
 ##########
 
-- a system that shall always boot without user interaction
-- staying in the bootloader is not an option.
+System description:
+
+- System with multiple boot targets
+- One recovery system
+
+Requirements:
+
+- System shall always boot without user interaction.
+- Staying in the bootloader is not an option.
 
 In this scenario a boot target is started for the configured number of remaining
 attempts. If it cannot be started successfully, the next boot target is chosen.
-This repeats until no boot targets are left to start, then all remaining attempts
-are reset to their defaults and the first boot target is tried again.
+This repeats until no bootchooser boot targets are left to start, then the
+recovery system is booted.
+
+If all boot target's remaining attempts or priorities are 0 during bootchooser
+start, the procedure repeats.
 
 Settings
 ^^^^^^^^
@@ -285,19 +295,24 @@ Deployment
 Recovery
 ^^^^^^^^
 
-Recovery will only be called when all boot targets are not startable (That is,
-no valid kernel found or read failure). Once a boot target is startable (a
-valid kernel is found and started) *bootchooser* will never fall through to
-the recovery boot target.
+Recovery will only be called if none of the boot targets are startable.
+As long as one boot target is startable, *bootchooser* will never fall through
+to the recovery boot target.
+
+Could be a recovery system or barebox script.
 
 Scenario 2
 ##########
 
-- a system with multiple boot targets
-- one recovery system
+System description:
+
+- A system with multiple boot targets
+- One recovery system
 
-A boot target that was booted three times without success shall never be booted
-again (except after update or user interaction).
+Requirements:
+
+- Boot targets that were booted three times unsuccessfully shall never be booted
+  again (except after update or user interaction).
 
 Settings
 ^^^^^^^^
@@ -313,26 +328,27 @@ Deployment
 ^^^^^^^^^^
 
 #. barebox or flash robot fills all boot targets with valid systems.
-#. barebox or flash robot marks boot targets as good or *state* contains non zero
+#. barebox or flash robot marks boot targets as good or *state* contains non-zero
    defaults for the remaining_attempts/priorities.
 
 Recovery
 ^^^^^^^^
 
-Done by 'recovery' boot target which is booted after *bootchooser* falls
-through due to the lack of bootable targets. This boot target can be:
-
-- a system that will be booted as recovery.
-- a barebox script that will be started.
+Recovery system or barebox script to be started after *bootchooser* found no
+bootable targets.
 
 Scenario 3
 ##########
 
-- a system with multiple boot targets
-- one recovery system
-- a power cycle shall not be counted as failed boot.
+System description:
+
+- A system with multiple boot targets
+- One recovery system
 
-Booting a boot target three times without success disables it.
+Requirements:
+
+- All enabled boot targets shall be tried after a power-on reset.
+- Booting a boot target unsuccessfully three times shall disable it.
 
 Settings
 ^^^^^^^^
@@ -353,11 +369,8 @@ Deployment
 Recovery
 ^^^^^^^^
 
-Done by 'recovery' boot target which is booted after *bootchooser* falls
-through due to the lack of bootable targets. This target can be:
-
-- a system that will be booted as recovery.
-- a barebox script that will be started.
+Recovery system or barebox script to be started after *bootchooser* found no
+bootable targets.
 
 .. _bootchooser,state_framework:
 
-- 
2.39.5



From bst at pengutronix.de  Mon Mar 31 05:49:30 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Mon, 31 Mar 2025 14:49:30 +0200
Subject: [PATCH 7/9] doc: bootchooser: document defaults of global.bootchooser.*
In-Reply-To: <20250331124932.901033-1-bst@pengutronix.de>
References: <20250331124932.901033-1-bst@pengutronix.de>
Message-ID: <20250331124932.901033-7-bst@pengutronix.de>

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 Documentation/user/bootchooser.rst | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
index 01c5c86edb6..53bf5f329fd 100644
--- a/Documentation/user/bootchooser.rst
+++ b/Documentation/user/bootchooser.rst
@@ -37,12 +37,15 @@ following configuration variables are needed to describe a *bootchooser* boot ta
 
 ``global.bootchooser.<targetname>.boot``
   This controls what barebox actually boots for this boot target. This string can
-  contain anything that the :ref:`boot <command_boot>` command understands.
+  contain anything that the :ref:`boot <command_boot>` command understands. If
+  unset, the boot script ``/env/boot/<targetname>`` is called.
 
 ``global.bootchooser.<targetname>.default_attempts``
   The default number of attempts that a boot target shall be tried before skipping it.
+  Defaults to ``bootchooser.default_attempts``, see below.
 ``global.bootchooser.<targetname>.default_priority``
   The default priority of a boot target.
+  Defaults to ``global.bootchooser.default_priority``, see below.
 
 
 Additionally the following run-time variables are needed. Unlike the configuration
@@ -125,20 +128,20 @@ options not specific to any boot target.
 
 ``global.bootchooser.disable_on_zero_attempts``
   Boolean flag. If set to 1, *bootchooser* disables a boot target (sets priority
-  to 0) whenever the remaining attempts counter reaches 0.
+  to 0) whenever the remaining attempts counter reaches 0. Defaults to 0.
 ``global.bootchooser.default_attempts``
   The default number of attempts that a boot target shall be tried before skipping
   it, used when not overwritten with the boot target specific variable of the same
-  name.
+  name. Defaults to 3.
 ``global.bootchooser.default_priority``
   The default priority of a boot target when not overwritten with the target
-  specific variable of the same name.
+  specific variable of the same name. Defaults to 1.
 ``global.bootchooser.reset_attempts``
   A space-separated list of conditions (checked during bootchooser start) that
   shall cause the ``remaining_attempts`` counters of all enabled targets to be
   reset. Possible values:
 
-  * empty: Counters will never be reset.
+  * empty: Counters will never be reset (default).
   * ``power-on``: If a power-on reset (``$global.system.reset="POR"``) is detected.
     Happens after a power cycle.
   * ``reset``: If a generic reset (``$global.system.reset="RST"``) is detected.
@@ -148,21 +151,22 @@ options not specific to any boot target.
   A space-separated list of conditions (checked during bootchooser start) that
   shall cause the ``priority``  of all boot targets to be reset. Possible values:
 
-  * empty: Priorities will never be reset.
+  * empty: Priorities will never be reset (default).
   * ``all-zero``: If all boot targets have zero ``priority``.
 ``global.bootchooser.retry``
   If set to 1, *bootchooser* retries booting until one succeeds or no more valid
   boot targets exist.
   Otherwise the ``boot`` command will return with an error after the first failed
-  boot target.
+  boot target. Defaults to 0.
 ``global.bootchooser.state_prefix``
   If set, this makes *bootchooser* use the *state* framework as backend for
   storing run-time data and defines the name of the state instance to use, see
-  :ref:`below <bootchooser,state_framework>`.
+  :ref:`below <bootchooser,state_framework>`. Defaults to an empty string.
 ``global.bootchooser.targets``
   Space-separated list of boot targets that are used. For each entry in the list
   a corresponding
   set of ``global.bootchooser.<targetname>.<variablename>`` variables must exist.
+  Defaults to an empty string.
 ``global.bootchooser.last_chosen``
   *bootchooser* sets this to the boot target that was chosen on last boot (index).
 
-- 
2.39.5



From bst at pengutronix.de  Mon Mar 31 05:49:28 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Mon, 31 Mar 2025 14:49:28 +0200
Subject: [PATCH 5/9] doc: bootchooser: move global.bootchooser.reset_attempts docs down to other variables
In-Reply-To: <20250331124932.901033-1-bst@pengutronix.de>
References: <20250331124932.901033-1-bst@pengutronix.de>
Message-ID: <20250331124932.901033-5-bst@pengutronix.de>

I don't see a reason why this variable should be documented elsewhere,
so move it down where the other variables are documented.

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 Documentation/user/bootchooser.rst | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
index b54e6873bc8..d3469e7480a 100644
--- a/Documentation/user/bootchooser.rst
+++ b/Documentation/user/bootchooser.rst
@@ -83,23 +83,7 @@ no remaining attempts left.
 
 To prevent ending up in an unbootable system after a number of failed boot
 attempts, there is also a built-in mechanism to reset the counters to their defaults,
-controlled by the ``global.bootchooser.reset_attempts`` variable. It holds a
-list of space-separated flags. Possible values are:
-
-- empty: counters will never be reset
-- ``power-on``: When bootchooser starts and a power-on reset
-  (``$global.system.reset="POR"``) is detected, the ``remaining_attempts``
-  counters of all enabled targets are reset to their defaults.
-  This means after a power cycle all boot targets will be tried again for the configured number of retries.
-- ``reset``: When bootchooser starts and a generic reset
-  (``$global.system.reset="RST"``) is detected, the ``remaining_attempts``
-  counters of all enabled targets are reset to their defaults.
-  This means that, if the systems reports a generic restart, the
-  ``remaining_attempts`` counters of all enabled targets are reset to
-  their defaults.
-- ``all-zero``: When bootchooser starts and the ``remaining_attempts``
-  counters of all enabled targets are zero, the ``remaining_attempts``
-  counters of all enabled targets are reset to their defaults.
+controlled by the ``global.bootchooser.reset_attempts`` variable.
 
 If ``global.bootchooser.retry`` is enabled (set to ``1``), the bootchooser
 algorithm will iterate through all valid boot targets (and decrease their
@@ -150,7 +134,16 @@ options not specific to any boot target.
   The default priority of a boot target when not overwritten with the target
   specific variable of the same name.
 ``global.bootchooser.reset_attempts``
-  Already described in :ref:`Bootchooser Algorithm <bootchooser,algorithm>`
+  A space-separated list of conditions (checked during bootchooser start) that
+  shall cause the ``remaining_attempts`` counters of all enabled targets to be
+  reset. Possible values:
+
+  * empty: Counters will never be reset.
+  * ``power-on``: If a power-on reset (``$global.system.reset="POR"``) is detected.
+    Happens after a power cycle.
+  * ``reset``: If a generic reset (``$global.system.reset="RST"``) is detected.
+  * ``all-zero``: If the ``remaining_attempts`` counters of all enabled targets
+    are zero.
 ``global.bootchooser.reset_priorities``
   A space-separated list of events that cause *bootchooser* to reset the priorities of
   all boot targets. Possible values:
-- 
2.39.5



From bst at pengutronix.de  Mon Mar 31 05:49:32 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Mon, 31 Mar 2025 14:49:32 +0200
Subject: [PATCH 9/9] doc: bootchooser: document NV storage backend separately
In-Reply-To: <20250331124932.901033-1-bst@pengutronix.de>
References: <20250331124932.901033-1-bst@pengutronix.de>
Message-ID: <20250331124932.901033-9-bst@pengutronix.de>

Before, the bootchooser documentation mixed up configuration options and NV
backend storage. Since these are separate concepts, document them
separately.

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 Documentation/user/bootchooser.rst | 42 +++++++++++++++++-------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
index 0c236de22fb..351e1d14e1e 100644
--- a/Documentation/user/bootchooser.rst
+++ b/Documentation/user/bootchooser.rst
@@ -31,9 +31,10 @@ or by e.g. setting ``boot.default`` to ``bootchooser``.
 Bootchooser Targets
 -------------------
 
-A *bootchooser* boot target represents one target that barebox can boot. It consists
-of a set of variables in the ``global.bootchooser.<targetname>`` namespace. The
-following configuration variables are needed to describe a *bootchooser* boot target:
+A *bootchooser* boot target represents one target that barebox can boot. The
+known targets are set in ``global.bootchooser.targets``. A target consists of a
+set of variables in the ``global.bootchooser.<targetname>`` namespace. The
+following configuration variables describe a *bootchooser* boot target:
 
 ``global.bootchooser.<targetname>.boot``
   This controls what barebox actually boots for this boot target. This string can
@@ -47,17 +48,6 @@ following configuration variables are needed to describe a *bootchooser* boot ta
   The default priority of a boot target.
   Defaults to ``global.bootchooser.default_priority``, see below.
 
-
-Additionally the following run-time variables are needed. Unlike the configuration
-variables their values are automatically updated by the *bootchooser* algorithm:
-
-``global.bootchooser.<targetname>.priority``
-  The current ``priority`` of the boot target. Higher numbers have higher priorities.
-  A ``priority`` of 0 means the boot target is disabled and won't be started.
-``global.bootchooser.<targetname>.remaining_attempts``
-  The ``remaining_attempts`` counter. Only boot targets with a ``remaining_attempts``
-  counter > 0 are started.
-
 The *bootchooser* algorithm generally only starts boot targets that have a ``priority``
 > 0 and a ``remaining_attempts`` counter > 0.
 
@@ -164,11 +154,9 @@ options not specific to any boot target.
   :ref:`below <bootchooser,state_framework>`. Defaults to an empty string.
 ``global.bootchooser.targets``
   Space-separated list of boot targets that are used. For each entry in the list
-  a corresponding
-  set of ``global.bootchooser.<targetname>.<variablename>`` variables must exist.
+  a corresponding set of variables must exist in the chosen *bootchooser* storage
+  backend.
   Defaults to an empty string.
-``global.bootchooser.last_chosen``
-  *bootchooser* sets this to the boot target that was chosen on last boot (index).
 
 .. _bootchooser,setup_example:
 
@@ -541,6 +529,24 @@ instead of the NV run-time environment variables, we just set:
    and ``bootchooser.<targetname>.default_attempts`` values in sync with the
    corresponding default values in the devicetree.
 
+Using NV Run-Time Variable Data
+-------------------------------
+
+.. note:: Using NV variables as bootchooser's storage is only meant for
+   evluation purposes, not for production. It is not power-fail safe.
+
+The following run-time variables are needed. Unlike the configuration
+variables their values are automatically updated by the *bootchooser* algorithm:
+
+``nv.bootchooser.<targetname>.priority``
+  The current ``priority`` of the boot target. Higher numbers have higher priorities.
+  A ``priority`` of 0 means the boot target is disabled and won't be started.
+``nv.bootchooser.<targetname>.remaining_attempts``
+  The ``remaining_attempts`` counter. Only boot targets with a ``remaining_attempts``
+  counter > 0 are started.
+``nv.bootchooser.last_chosen``
+  *bootchooser* sets this to the boot target that was chosen on last boot (index).
+
 Updating systems
 ----------------
 
-- 
2.39.5



From bst at pengutronix.de  Mon Mar 31 05:49:24 2025
From: bst at pengutronix.de (Bastian Krause)
Date: Mon, 31 Mar 2025 14:49:24 +0200
Subject: [PATCH 1/9] doc: bootchooser: drop article before bootchooser
Message-ID: <20250331124932.901033-1-bst@pengutronix.de>

"bootchooser" is the name of a framework, so drop the "the" before
bootchooser. This aligns with standard naming conventions for technical
terms and makes the section consistent with other parts already using
bootchooser without article.

Signed-off-by: Bastian Krause <bst at pengutronix.de>
---
 Documentation/user/bootchooser.rst | 36 +++++++++++++++---------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
index 1a2ce70bb2f..e318b245c14 100644
--- a/Documentation/user/bootchooser.rst
+++ b/Documentation/user/bootchooser.rst
@@ -8,15 +8,15 @@ kernels and multiple root file systems. The *bootchooser* framework provides
 the building blocks to model different use cases without the need to start
 from scratch over and over again.
 
-The *bootchooser* works on abstract boot targets, each with a set of properties
+*Bootchooser* works on abstract boot targets, each with a set of properties
 and implements an algorithm which selects the highest priority target to boot.
 
-To make the *bootchooser* work requires a fixed set of configuration parameters
+Making *bootchooser* work requires a fixed set of configuration parameters
 and a storage backend for saving status information.
 Currently supported storage backends are either nv variables or the
 barebox *state* framework.
 
-The *Bootchooser* itself is executed as a normal barebox boot target, i.e. one
+*Bootchooser* itself is executed as a normal barebox boot target, i.e. one
 can start it via::
 
   boot bootchooser
@@ -24,7 +24,7 @@ can start it via::
 or by e.g. setting ``boot.default`` to ``bootchooser``.
 
 .. note:: As ``boot.default`` accepts multiple values, it can also be used to
-  specify a fallback boot target in case the bootchooser fails booting, e.g.
+  specify a fallback boot target in case bootchooser fails booting, e.g.
   ``bootchooser recovery``.
 
 Bootchooser Targets
@@ -88,17 +88,17 @@ controlled by the ``global.bootchooser.reset_attempts`` variable. It holds a
 list of space-separated flags. Possible values are:
 
 - empty: counters will never be reset
-- ``power-on``: When the bootchooser starts and a power-on reset
+- ``power-on``: When bootchooser starts and a power-on reset
   (``$global.system.reset="POR"``) is detected, the ``remaining_attempts``
   counters of all enabled targets are reset to their defaults.
   This means after a power cycle all boot targets will be tried again for the configured number of retries.
-- ``reset``: When the bootchooser starts and a generic reset
+- ``reset``: When bootchooser starts and a generic reset
   (``$global.system.reset="RST"``) is detected, the ``remaining_attempts``
   counters of all enabled targets are reset to their defaults.
   This means that, if the systems reports a generic restart, the
   ``remaining_attempts`` counters of all enabled targets are reset to
   their defaults.
-- ``all-zero``: When the bootchooser starts and the ``remaining_attempts``
+- ``all-zero``: When bootchooser starts and the ``remaining_attempts``
   counters of all enabled targets are zero, the ``remaining_attempts``
   counters of all enabled targets are reset to their defaults.
 
@@ -115,7 +115,7 @@ selection of the right boot target itself, it cannot decide if the system
 booted successfully on its own.
 
 In case only the booted system itself knows when it is in a good state,
-it can report this to the bootchooser from Linux userspace using the
+it can report this to bootchooser from Linux userspace using the
 *barebox-state* tool from the dt-utils_ package.::
 
   barebox-state [-n <state variable set>] -s [<prefix>.]<target>.remaining_attempts=<reset-value>
@@ -216,7 +216,7 @@ kernel with its corresponding devicetree via boot spec (refer to
 :ref:`Bootloader Spec <bootloader_spec>` for further details).
 
 Either device can be booted with the :ref:`boot <command_boot>` command command,
-and thus can be used by the *bootchooser* and we can start to configure the
+and thus can be used by *bootchooser* and we can start to configure the
 *bootchooser* variables.
 
 The following example shows how to initialize two boot targets, ``system1`` and
@@ -324,7 +324,7 @@ Deployment
 Recovery
 ^^^^^^^^
 
-Done by 'recovery' boot target which is booted after the *bootchooser* falls
+Done by 'recovery' boot target which is booted after *bootchooser* falls
 through due to the lack of bootable targets. This boot target can be:
 
 - a system that will be booted as recovery.
@@ -358,7 +358,7 @@ Deployment
 Recovery
 ^^^^^^^^
 
-Done by 'recovery' boot target which is booted after the *bootchooser* falls
+Done by 'recovery' boot target which is booted after *bootchooser* falls
 through due to the lack of bootable targets. This target can be:
 
 - a system that will be booted as recovery.
@@ -369,13 +369,13 @@ through due to the lack of bootable targets. This target can be:
 Using the *State* Framework as Backend for Run-Time Variable Data
 -----------------------------------------------------------------
 
-Usually the *bootchooser* modifies its data in global variables which are
+Usually *bootchooser* modifies its data in global variables which are
 connected to :ref:`non volatile variables <config_device>`.
 
 Alternatively the :ref:`state_framework` can be used for this data, which
 allows to store this data redundantly in some kind of persistent memory.
 
-In order to let the *bootchooser* use the *state* framework for its storage
+In order to let *bootchooser* use the *state* framework for its storage
 backend, configure the ``bootchooser.state_prefix`` variable with the *state*
 variable set instance name.
 
@@ -392,7 +392,7 @@ At barebox run-time this will result in a *state* variable set instance called
 *some_kind_of_state*. You can also store variables unrelated to *bootchooser* (a
 serial number, MAC address, ?) in it.
 
-Extending this *state* variable set by information required by the *bootchooser*
+Extending this *state* variable set by information required by *bootchooser*
 is simply done by adding so called 'boot targets' and optionally one ``last_chosen``
 node. It then looks like:
 
@@ -463,11 +463,11 @@ used to setup the corresponding run-time environment variables in the
 
 .. important:: It is important to provide a ``default`` value for each variable
    for the case when the *state* variable set backend memory is uninitialized.
-   This is also true if default values through the *bootchooser's* environment
+   This is also true if default values through *bootchooser's* environment
    variables are defined (e.g. ``bootchooser.default_attempts``,
    ``bootchooser.default_priority`` and their corresponding boot target specific
-   variables). The former ones are forwarded to the *bootchooser* to make a
-   decision, the latter ones are used by the *bootchooser* to make a decision
+   variables). The former ones are forwarded to *bootchooser* to make a
+   decision, the latter ones are used by *bootchooser* to make a decision
    the next time.
 
 Example
@@ -550,7 +550,7 @@ regular *bootchooser* boot targets updating is done like:
 - Reboot.
 - If necessary update the now inactive, not yet updated boot target the same way.
 
-One way of updating systems is using RAUC_ which integrates well with the *bootchooser*
+One way of updating systems is using RAUC_ which integrates well with *bootchooser*
 in barebox.
 
 .. _RAUC: https://rauc.readthedocs.io/en/latest/
-- 
2.39.5



From robin at protonic.nl  Mon Mar 31 07:33:43 2025
From: robin at protonic.nl (Robin van der Gracht)
Date: Mon, 31 Mar 2025 16:33:43 +0200
Subject: [PATCH v2] ARM: boards: protonic-imx6: Re-introduce generic boot target board string
Message-ID: <20250331143343.3252321-1-robin@protonic.nl>

This allows using a single bootable usb drive for multiple boards.

Signed-off-by: Robin van der Gracht <robin at protonic.nl>
---

v2:
 - Changed generic boot target name from prti6qp to generic-imx6

 arch/arm/boards/protonic-imx6/board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index bbebbb8dc9..9292052d30 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -373,7 +373,7 @@ static int prt_imx6_usb_boot(struct bootentry *entry, int verbose, int dryrun)
 
 	*second_word = 0;
 
-	if (strcmp(buf, priv->name)) {
+	if (strcmp(buf, priv->name) && strcmp(buf, "generic-imx6")) {
 		dev_err(dev, "Boot target for a different board! (got: %s expected: %s)\n",
 			buf, priv->name);
 		ret = -EINVAL;
-- 
2.43.0


From robin at protonic.nl  Mon Mar 31 08:05:28 2025
From: robin at protonic.nl (Robin van der Gracht)
Date: Mon, 31 Mar 2025 17:05:28 +0200
Subject: [PATCH] ARM: boards: protonic-imx6: prtvt7: Use the input system for key detection
Message-ID: <20250331150528.3270385-1-robin@protonic.nl>

Static gpio mapping is deprecated. Instead query the gpio-keys driver for
pressed keys.

Signed-off-by: Robin van der Gracht <robin at protonic.nl>
---
 arch/arm/boards/protonic-imx6/board.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 9292052d30..4bfae3d608 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -13,6 +13,7 @@
 #include <globalvar.h>
 #include <gpio.h>
 #include <i2c/i2c.h>
+#include <input/input.h>
 #include <mach/imx/bbu.h>
 #include <mach/imx/imx6.h>
 #include <mach/imx/ocotp-fusemap.h>
@@ -740,19 +741,21 @@ static int prt_imx6_init_kvg_yaco(struct prt_imx6_priv *priv)
 	return prt_imx6_init_kvg_power(priv, PW_MODE_KVG_WITH_YACO);
 }
 
-#define GPIO_KEY_F6     (0xe0 + 5)
-#define GPIO_KEY_CYCLE  (0xe0 + 2)
-
 static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
 {
-	/* This function relies heavely on the gpio-pca9539 driver */
+	unsigned long *keys;
 
-	gpio_direction_input(GPIO_KEY_F6);
-	gpio_direction_input(GPIO_KEY_CYCLE);
+	/*
+	 * Prefer USB-boot and enable autoboot with timeout when CYCLE-F6 key
+	 * combination is pressed.
+	 */
+	keys = xzalloc((KEY_CYCLEWINDOWS / 8) + 1);
+	input_key_get_status(keys, KEY_CYCLEWINDOWS);
 
-	if (gpio_get_value(GPIO_KEY_CYCLE) && gpio_get_value(GPIO_KEY_F6))
+	if (!(test_bit(KEY_CYCLEWINDOWS, keys) && test_bit(KEY_F6, keys)))
 		priv->no_usb_check = 1;
 
+	free(keys);
 	return 0;
 }
 
-- 
2.43.0



From a.fatoum at pengutronix.de  Mon Mar 31 10:26:22 2025
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 31 Mar 2025 19:26:22 +0200
Subject: [PATCH] hardening: add missing word in Kconfig comment
Message-ID: <20250331172622.1848315-1-a.fatoum@pengutronix.de>

Care needs to be [taken] was missing the verb.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 lib/Kconfig.hardening | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/Kconfig.hardening b/lib/Kconfig.hardening
index ed280dd216d8..7567f3e9aaaf 100644
--- a/lib/Kconfig.hardening
+++ b/lib/Kconfig.hardening
@@ -3,7 +3,7 @@ menu "Hardening options"
 if HAS_INSECURE_DEFAULTS
 comment "This barebox configuration has CONFIG_HAS_INSECURE_DEFAULTS=y indicating"
 comment "that some of the configured options have potentially insecure defaults."
-comment "Extra care needs to be in secure booted systems."
+comment "Extra care needs to be taken in secure booted systems."
 endif
 
 config BUG_ON_DATA_CORRUPTION
-- 
2.39.5



From jmaselbas at zdiv.net  Mon Mar 31 10:40:49 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Mon, 31 Mar 2025 19:40:49 +0200
Subject: [PATCH 1/2] commands: edit: Fix potential out-of-bound access
Message-ID: <20250331174050.2606-1-jmaselbas@zdiv.net>

The local lbuf can potentially be left not nul-terminated,
and the tab expension can potentially write out-of-bound.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 commands/edit.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/commands/edit.c b/commands/edit.c
index fcf8ad90f5..3bbe60fdbf 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -53,14 +53,14 @@ static char *screenline(char *line, int *pos)
 		return lbuf;
 	}
 
-	for (i = 0; outpos < 1024; i++) {
+	for (i = 0; outpos < sizeof(lbuf) - 1; i++) {
 		if (i == textx && pos)
 			*pos = outpos;
 		if (!line[i])
 			break;
 		if (line[i] == '\t') {
 			lbuf[outpos++] = ' ';
-			while (outpos % TABSPACE)
+			while (outpos < sizeof(lbuf) - 1 && outpos % TABSPACE)
 				lbuf[outpos++] = ' ';
 			continue;
 		}
-- 
2.48.1



From jmaselbas at zdiv.net  Mon Mar 31 10:40:50 2025
From: jmaselbas at zdiv.net (Jules Maselbas)
Date: Mon, 31 Mar 2025 19:40:50 +0200
Subject: [PATCH 2/2] commands: edit: remove the memset call on screenline
In-Reply-To: <20250331174050.2606-1-jmaselbas@zdiv.net>
References: <20250331174050.2606-1-jmaselbas@zdiv.net>
Message-ID: <20250331174050.2606-2-jmaselbas@zdiv.net>

Rework the screenline function so the lbuf doesn't have to be
initialized to zero eachtime the screenline function is called.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 commands/edit.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/commands/edit.c b/commands/edit.c
index 3bbe60fdbf..28c9ab8877 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -46,11 +46,9 @@ static char *screenline(char *line, int *pos)
 	int i, outpos = 0;
 	static char lbuf[1024];
 
-	memset(lbuf, 0, 1024);
-
 	if (!line) {
-		lbuf[0] = '~';
-		return lbuf;
+		lbuf[outpos++] = '~';
+		goto out;
 	}
 
 	for (i = 0; outpos < sizeof(lbuf) - 1; i++) {
@@ -67,6 +65,8 @@ static char *screenline(char *line, int *pos)
 		lbuf[outpos++] = line[i];
 	}
 
+out:
+	lbuf[outpos] = 0;
 	return lbuf;
 }
 
-- 
2.48.1



From s.hauer at pengutronix.de  Mon Mar 31 22:36:15 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 01 Apr 2025 07:36:15 +0200
Subject: [PATCH v2] ARM: boards: protonic-imx6: Re-introduce generic
 boot target board string
In-Reply-To: <20250331143343.3252321-1-robin@protonic.nl>
References: <20250331143343.3252321-1-robin@protonic.nl>
Message-ID: <174348577516.3053429.1918774994486876062.b4-ty@pengutronix.de>


On Mon, 31 Mar 2025 16:33:43 +0200, Robin van der Gracht wrote:
> This allows using a single bootable usb drive for multiple boards.
> 
> 

Applied, thanks!

[1/1] ARM: boards: protonic-imx6: Re-introduce generic boot target board string
      https://git.pengutronix.de/cgit/barebox/commit/?id=68c0cc7e0eec (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 22:52:42 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 01 Apr 2025 07:52:42 +0200
Subject: [PATCH] ARM: boards: protonic-imx6: prtvt7: Use the input
 system for key detection
In-Reply-To: <20250331150528.3270385-1-robin@protonic.nl>
References: <20250331150528.3270385-1-robin@protonic.nl>
Message-ID: <174348676252.3090576.3500222277273196739.b4-ty@pengutronix.de>


On Mon, 31 Mar 2025 17:05:28 +0200, Robin van der Gracht wrote:
> Static gpio mapping is deprecated. Instead query the gpio-keys driver for
> pressed keys.
> 
> 

Applied, thanks!

[1/1] ARM: boards: protonic-imx6: prtvt7: Use the input system for key detection
      https://git.pengutronix.de/cgit/barebox/commit/?id=e44d472d128d (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 22:58:16 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 1 Apr 2025 07:58:16 +0200
Subject: [PATCH] ARM: boards: protonic-imx6: prtvt7: Use the input system
 for key detection
In-Reply-To: <20250331150528.3270385-1-robin@protonic.nl>
References: <20250331150528.3270385-1-robin@protonic.nl>
Message-ID: <Z-uAeJBk49WRASr9@pengutronix.de>

On Mon, Mar 31, 2025 at 05:05:28PM +0200, Robin van der Gracht wrote:
> Static gpio mapping is deprecated. Instead query the gpio-keys driver for
> pressed keys.
> 
> Signed-off-by: Robin van der Gracht <robin at protonic.nl>
> ---
>  arch/arm/boards/protonic-imx6/board.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
> index 9292052d30..4bfae3d608 100644
> --- a/arch/arm/boards/protonic-imx6/board.c
> +++ b/arch/arm/boards/protonic-imx6/board.c
> @@ -13,6 +13,7 @@
>  #include <globalvar.h>
>  #include <gpio.h>
>  #include <i2c/i2c.h>
> +#include <input/input.h>
>  #include <mach/imx/bbu.h>
>  #include <mach/imx/imx6.h>
>  #include <mach/imx/ocotp-fusemap.h>
> @@ -740,19 +741,21 @@ static int prt_imx6_init_kvg_yaco(struct prt_imx6_priv *priv)
>  	return prt_imx6_init_kvg_power(priv, PW_MODE_KVG_WITH_YACO);
>  }
>  
> -#define GPIO_KEY_F6     (0xe0 + 5)
> -#define GPIO_KEY_CYCLE  (0xe0 + 2)
> -
>  static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
>  {
> -	/* This function relies heavely on the gpio-pca9539 driver */
> +	unsigned long *keys;
>  
> -	gpio_direction_input(GPIO_KEY_F6);
> -	gpio_direction_input(GPIO_KEY_CYCLE);

I added a

	of_devices_ensure_probed_by_compatible("gpio-keys");

here to be sure you don't depend on probe order.

Sascha

-- 
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-5555 |


From s.hauer at pengutronix.de  Mon Mar 31 22:58:35 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 01 Apr 2025 07:58:35 +0200
Subject: [PATCH] hardening: add missing word in Kconfig comment
In-Reply-To: <20250331172622.1848315-1-a.fatoum@pengutronix.de>
References: <20250331172622.1848315-1-a.fatoum@pengutronix.de>
Message-ID: <174348711551.3092519.8362870496506556250.b4-ty@pengutronix.de>


On Mon, 31 Mar 2025 19:26:22 +0200, Ahmad Fatoum wrote:
> Care needs to be [taken] was missing the verb.
> 
> 

Applied, thanks!

[1/1] hardening: add missing word in Kconfig comment
      https://git.pengutronix.de/cgit/barebox/commit/?id=025f4f12b9a4 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 23:02:15 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 01 Apr 2025 08:02:15 +0200
Subject: [PATCH 1/2] commands: edit: Fix potential out-of-bound access
In-Reply-To: <20250331174050.2606-1-jmaselbas@zdiv.net>
References: <20250331174050.2606-1-jmaselbas@zdiv.net>
Message-ID: <174348733573.3093127.2426394410165542725.b4-ty@pengutronix.de>


On Mon, 31 Mar 2025 19:40:49 +0200, Jules Maselbas wrote:
> The local lbuf can potentially be left not nul-terminated,
> and the tab expension can potentially write out-of-bound.
> 
> 

Applied, thanks!

[1/2] commands: edit: Fix potential out-of-bound access
      https://git.pengutronix.de/cgit/barebox/commit/?id=d653f475709c (link may not be stable)
[2/2] commands: edit: remove the memset call on screenline
      https://git.pengutronix.de/cgit/barebox/commit/?id=4c841ff9831f (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From s.hauer at pengutronix.de  Mon Mar 31 23:06:32 2025
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 01 Apr 2025 08:06:32 +0200
Subject: [PATCH 1/9] doc: bootchooser: drop article before bootchooser
In-Reply-To: <20250331124932.901033-1-bst@pengutronix.de>
References: <20250331124932.901033-1-bst@pengutronix.de>
Message-ID: <174348759260.3094509.2737839510608167007.b4-ty@pengutronix.de>


On Mon, 31 Mar 2025 14:49:24 +0200, Bastian Krause wrote:
> "bootchooser" is the name of a framework, so drop the "the" before
> bootchooser. This aligns with standard naming conventions for technical
> terms and makes the section consistent with other parts already using
> bootchooser without article.
> 
> 

Applied, thanks!

[1/9] doc: bootchooser: drop article before bootchooser
      https://git.pengutronix.de/cgit/barebox/commit/?id=ea16eddb822a (link may not be stable)
[2/9] doc: bootchooser: drop confusing description for "remaining_attempts"
      https://git.pengutronix.de/cgit/barebox/commit/?id=7948ecca9594 (link may not be stable)
[3/9] doc: bootchooser: clarify marking boot successful from barebox
      https://git.pengutronix.de/cgit/barebox/commit/?id=5d2efb1c316a (link may not be stable)
[4/9] doc: bootchooser: don't recommend NV backend
      https://git.pengutronix.de/cgit/barebox/commit/?id=a274fe119aae (link may not be stable)
[5/9] doc: bootchooser: move global.bootchooser.reset_attempts docs down to other variables
      https://git.pengutronix.de/cgit/barebox/commit/?id=a673a31f34d5 (link may not be stable)
[6/9] doc: bootchooser: rephrase global.bootchooser.reset_priorities description
      https://git.pengutronix.de/cgit/barebox/commit/?id=f20c1c831f46 (link may not be stable)
[7/9] doc: bootchooser: document defaults of global.bootchooser.*
      https://git.pengutronix.de/cgit/barebox/commit/?id=0f28047c9303 (link may not be stable)
[8/9] doc: bootchooser: rephrase scenarios
      https://git.pengutronix.de/cgit/barebox/commit/?id=0ad5295e2048 (link may not be stable)
[9/9] doc: bootchooser: document NV storage backend separately
      https://git.pengutronix.de/cgit/barebox/commit/?id=b4c0c4615ace (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer at pengutronix.de>



From eagle.alexander923 at gmail.com  Mon Mar 31 23:20:31 2025
From: eagle.alexander923 at gmail.com (Alexander Shiyan)
Date: Tue, 1 Apr 2025 09:20:31 +0300
Subject: NOR damage problem
Message-ID: <CAP1tNvQiAqipRwBp9MBcOrPEQnbtqxr5GVZQ0vWhOnzhn3Wijw@mail.gmail.com>

Hello All!

Found NOR partition damage after use ubiformat.
There is a NOR memory (256M) connected via atmel-qspi.
First partition is RAW, the other for use via UBI.

partition at 0 {
label = "bootstrap";
reg = <0 0x20000>;
};
...
partition at e0000 {
label = "system";
reg = <0xe0000 0>;
};

barebox at Mega-Milas Informer SAMA5D2:/ md -s /dev/m25p0.bootstrap
m25p80 flash at 00: from 0x00000000, len 256
00000000: ea000012 eafffffe eafffffe eafffffe                ................
00000010: eafffffe 00004144 eafffffe eafffffe                ....DA..........
00000020: 65726162 00786f62 00000000 000040b8                barebox...... at ..
00000030: 55555555 55555555 55555555 55555555                UUUUUUUUUUUUUUUU
00000040: 55555555 55555555 55555555 55555555                UUUUUUUUUUUUUUUU
00000050: eb000c4b e1a00004 eb0008ca e1a0200e                K............ ..
00000060: e1a0300d eb000c8d e10fc000 e22cc01a                .0............,.
00000070: e31c001f e3ccc01f e38cc0d3 1a000004                ................
00000080: e38ccc01 e28fe00c e16ff00c e12ef30e                ..........o.....
00000090: e160006e e121f00c ee07cf15 ee07cf9a                n.`...!.........
000000a0: ee07cf95 ee11cf10 e3ccc085 e3cccc23                ............#...
000000b0: e38cca01 e38cc501 e3ccc002 ee01cf10                ................
000000c0: e1a0d003 e1a0f002 ee11cf30 e38cc040                ........0... at ...
000000d0: ee01cf30 e1a0f00e e24f0008 e59f1004                0.........O.....
000000e0: e0500001 e12fff1e 000000d8 e3510000                ..P.../.......Q.
000000f0: 13a03000 15813000 e5d021ff e5d031fe                .0...0...!...1..

So, at this time all OK. Next, format with UBI.

barebox at Mega-Milas Informer SAMA5D2:/ ubiformat /dev/m25p0.system -y
ubiformat: m25p0.system (nor), size 267517952 bytes (255.1 MiB),
4082 eraseblocks of 65536 bytes (64 KiB), min. I/O size 1 bytes
^Mlibscan: scanning eraseblock 0 --  0 % complete
m25p80 flash at 00: from 0x000e0000, len 64
m25p80 flash at 00: from 0x000f0000, len 64
...
m25p80 flash at 00: from 0x0ffe0000, len 64
libscan: scanning eraseblock 4081 -- 100 % complete
m25p80 flash at 00: from 0x0fff0000, len 64

ubiformat: 7 eraseblocks have valid erase counter, mean value is 0
ubiformat: 4069 eraseblocks are supposedly empty
ubiformat: warning!: 6 of 4082 eraseblocks contain non-ubifs data
ubiformat: warning!: only 7 of 4082 eraseblocks have valid erase counter
ubiformat: erase counter 0 will be used for all eraseblocks
ubiformat: note, arbitrary erase counter value may be specified using -e option
ubiformat: use erase counter 0 for all eraseblocks
ubiformat: formatting eraseblock 0 --  0 % complete
m25p80 flash at 00: at 0xe0000, len 65536
m25p80 flash at 00: at 0xf0000, len 65536
m25p80 flash at 00: at 0x100000, len 65536
m25p80 flash at 00: to 0x00100000, len 64
...
m25p80 flash at 00: to 0x000f0000, len 65536

Then check first partition:
barebox at Mega-Milas Informer SAMA5D2:/ md -s /dev/m25p0.bootstrap
m25p80 flash at 00: from 0x00000000, len 256
00000000: 22000010 00000000 00000000 00000000                ..."............
00000010: 40000000 00000000 60dc9950 00000000                ... at ....P..`....
00000020: 00000000 00000000 00000000 00000000                ................
00000030: 00000000 00000000 00000000 50040051                ............Q..P
00000040: 55555555 55555555 55555555 55555555                UUUUUUUUUUUUUUUU
00000050: eb000c4b e1a00004 eb0008ca e1a0200e                K............ ..
00000060: e1a0300d eb000c8d e10fc000 e22cc01a                .0............,.
00000070: e31c001f e3ccc01f e38cc0d3 1a000004                ................
00000080: e38ccc01 e28fe00c e16ff00c e12ef30e                ..........o.....
00000090: e160006e e121f00c ee07cf15 ee07cf9a                n.`...!.........
000000a0: ee07cf95 ee11cf10 e3ccc085 e3cccc23                ............#...
000000b0: e38cca01 e38cc501 e3ccc002 ee01cf10                ................
000000c0: e1a0d003 e1a0f002 ee11cf30 e38cc040                ........0... at ...
000000d0: ee01cf30 e1a0f00e e24f0008 e59f1004                0.........O.....
000000e0: e0500001 e12fff1e 000000d8 e3510000                ..P.../.......Q.
000000f0: 13a03000 15813000 e5d021ff e5d031fe                .0...0...!...1..
barebox at Mega-Milas Informer SAMA5D2:/

Now the first partition is broken.

Any suggestions where to look for the bug?

Thanks!


From robin at protonic.nl  Mon Mar 31 23:27:57 2025
From: robin at protonic.nl (Robin van der Gracht)
Date: Tue, 1 Apr 2025 08:27:57 +0200
Subject: [PATCH] ARM: boards: protonic-imx6: prtvt7: Use the input system
 for key detection
In-Reply-To: <Z-uAeJBk49WRASr9@pengutronix.de>
References: <20250331150528.3270385-1-robin@protonic.nl>
 <Z-uAeJBk49WRASr9@pengutronix.de>
Message-ID: <1c270035-1c5d-43c8-9bad-2a8ee0c72b19@protonic.nl>

On 01-04-2025 07:58, Sascha Hauer wrote:
> On Mon, Mar 31, 2025 at 05:05:28PM +0200, Robin van der Gracht wrote:
>> Static gpio mapping is deprecated. Instead query the gpio-keys driver for
>> pressed keys.
>>
>> Signed-off-by: Robin van der Gracht <robin at protonic.nl>
>> ---
>>   arch/arm/boards/protonic-imx6/board.c | 17 ++++++++++-------
>>   1 file changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
>> index 9292052d30..4bfae3d608 100644
>> --- a/arch/arm/boards/protonic-imx6/board.c
>> +++ b/arch/arm/boards/protonic-imx6/board.c
>> @@ -13,6 +13,7 @@
>>   #include <globalvar.h>
>>   #include <gpio.h>
>>   #include <i2c/i2c.h>
>> +#include <input/input.h>
>>   #include <mach/imx/bbu.h>
>>   #include <mach/imx/imx6.h>
>>   #include <mach/imx/ocotp-fusemap.h>
>> @@ -740,19 +741,21 @@ static int prt_imx6_init_kvg_yaco(struct prt_imx6_priv *priv)
>>   	return prt_imx6_init_kvg_power(priv, PW_MODE_KVG_WITH_YACO);
>>   }
>>   
>> -#define GPIO_KEY_F6     (0xe0 + 5)
>> -#define GPIO_KEY_CYCLE  (0xe0 + 2)
>> -
>>   static int prt_imx6_init_prtvt7(struct prt_imx6_priv *priv)
>>   {
>> -	/* This function relies heavely on the gpio-pca9539 driver */
>> +	unsigned long *keys;
>>   
>> -	gpio_direction_input(GPIO_KEY_F6);
>> -	gpio_direction_input(GPIO_KEY_CYCLE);
> I added a
>
> 	of_devices_ensure_probed_by_compatible("gpio-keys");
>
> here to be sure you don't depend on probe order.
>
> Sascha
Ack. Thanks.

Robin


