[PATCH 2/3] arm: mediatek: add RITY devicetree compatibility commands

Carlo Caione <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <20260828-ccaione-upstream-mtk-fdt-prepare-v1-2-bf80b489eb0f@baylibre.com>
RITY boot environments invoke dtbprobe before EFI boot, or fdtprobe when
devicetree authentication is enabled. These command names and their
positional arguments form part of the RITY image interface.

Register compatibility aliases beside mtk_fdt_prepare and share the common
argument parser and preparation service. Expose only the alias appropriate
to the selected security mode.

Keep the authenticated fdtprobe failure policy: failure to authenticate a
signed DTB or DTBO wrapper is fatal and panics with the established
diagnostic. Other preparation failures return to the caller, and
mtk_fdt_prepare remains recoverable for interactive diagnosis.

Signed-off-by: Carlo Caione <[email protected]>
---
 arch/arm/mach-mediatek/Kconfig           |  3 ++
 arch/arm/mach-mediatek/cmd_fdt_prepare.c | 47 ++++++++++++++++++++++++++++----
 2 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-mediatek/Kconfig b/arch/arm/mach-mediatek/Kconfig
index 75fa88a1510..aedc5992965 100644
--- a/arch/arm/mach-mediatek/Kconfig
+++ b/arch/arm/mach-mediatek/Kconfig
@@ -240,6 +240,9 @@ config CMD_MTK_FDT_PREPARE
 	  environment. It also accepts the interface, device and path arguments
 	  explicitly.
 
+	  Also provide the RITY-compatible dtbprobe command, or fdtprobe
+	  when devicetree authentication is enabled.
+
 config MTK_FDT_AUTH
 	bool "Authenticate MediaTek RITY devicetrees"
 	depends on MTK_FDT_PREPARE && FIT_SIGNATURE
diff --git a/arch/arm/mach-mediatek/cmd_fdt_prepare.c b/arch/arm/mach-mediatek/cmd_fdt_prepare.c
index 91d56f747ef..5184aa851a7 100644
--- a/arch/arm/mach-mediatek/cmd_fdt_prepare.c
+++ b/arch/arm/mach-mediatek/cmd_fdt_prepare.c
@@ -4,21 +4,32 @@
  */
 
 #include <command.h>
+#include <vsprintf.h>
+#include <linux/errno.h>
 
 #include "fdt_prepare.h"
 
-static int do_mtk_fdt_prepare(struct cmd_tbl *cmdtp, int flag, int argc,
-			      char *const argv[])
+static int run_mtk_fdt_prepare(int argc, char *const argv[], int *retp)
 {
-	int ret;
-
 	if (argc == 1)
-		ret = mtk_fdt_prepare();
+		*retp = mtk_fdt_prepare();
 	else if (argc == 4)
-		ret = mtk_fdt_prepare_from(argv[1], argv[2], argv[3]);
+		*retp = mtk_fdt_prepare_from(argv[1], argv[2], argv[3]);
 	else
 		return CMD_RET_USAGE;
 
+	return CMD_RET_SUCCESS;
+}
+
+static int do_mtk_fdt_prepare(struct cmd_tbl *cmdtp, int flag, int argc,
+			      char *const argv[])
+{
+	int ret, status;
+
+	status = run_mtk_fdt_prepare(argc, argv, &ret);
+	if (status)
+		return status;
+
 	return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
 }
 
@@ -29,3 +40,27 @@ static int do_mtk_fdt_prepare(struct cmd_tbl *cmdtp, int flag, int argc,
 U_BOOT_CMD(mtk_fdt_prepare, 4, 1, do_mtk_fdt_prepare,
 	   "load and assemble the MediaTek RITY devicetree",
 	   MTK_FDT_PREPARE_USAGE);
+
+#if CONFIG_IS_ENABLED(MTK_FDT_AUTH)
+static int do_mtk_fdt_prepare_auth(struct cmd_tbl *cmdtp, int flag, int argc,
+				   char *const argv[])
+{
+	int ret, status;
+
+	status = run_mtk_fdt_prepare(argc, argv, &ret);
+	if (status)
+		return status;
+	if (ret == -EKEYREJECTED)
+		panic("Invalid dtb/dtbo.");
+
+	return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(fdtprobe, 4, 1, do_mtk_fdt_prepare_auth,
+	   "load and assemble an authenticated MediaTek RITY devicetree",
+	   MTK_FDT_PREPARE_USAGE);
+#else
+U_BOOT_CMD(dtbprobe, 4, 1, do_mtk_fdt_prepare,
+	   "load and assemble a MediaTek RITY devicetree",
+	   MTK_FDT_PREPARE_USAGE);
+#endif

-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.