RITY boot environments use bootembedded as the legacy boot target. The command is part of the interface shared by the generated environment and U-Boot.
Locate the appended RITY FIT script after U-Boot's separate control devicetree and execute it through the standard source command. This avoids duplicating the legacy boot policy in C and retains source and bootm authentication for secure builds. Keep the command independently selectable because legacy FIT boot does not depend on mtk_fdt_prepare. Place it under cmd/mediatek and document the expected appended-image layout and execution path. Signed-off-by: Carlo Caione <[email protected]> --- cmd/mediatek/Kconfig | 7 +++++ cmd/mediatek/Makefile | 1 + cmd/mediatek/bootembedded.c | 59 ++++++++++++++++++++++++++++++++++++++++++ doc/usage/cmd/bootembedded.rst | 51 ++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) diff --git a/cmd/mediatek/Kconfig b/cmd/mediatek/Kconfig index 31fa6e8d528..1a06c25c627 100644 --- a/cmd/mediatek/Kconfig +++ b/cmd/mediatek/Kconfig @@ -21,4 +21,11 @@ config CMD_MTK_FDT_PREPARE Also provide the RITY-compatible dtbprobe command, or fdtprobe when devicetree authentication is enabled. +config CMD_MTK_BOOTEMBEDDED + bool "Enable the RITY-compatible 'bootembedded' command" + depends on CMD_SOURCE && OF_SEPARATE + help + Provide the RITY legacy-boot command. Locate and run the boot script + appended after the separate U-Boot control devicetree. + endif diff --git a/cmd/mediatek/Makefile b/cmd/mediatek/Makefile index 82f3d0dc412..93e6847d7ac 100644 --- a/cmd/mediatek/Makefile +++ b/cmd/mediatek/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0+ obj-$(CONFIG_CMD_MTK_FDT_PREPARE) += fdt_prepare.o +obj-$(CONFIG_CMD_MTK_BOOTEMBEDDED) += bootembedded.o diff --git a/cmd/mediatek/bootembedded.c b/cmd/mediatek/bootembedded.c new file mode 100644 index 00000000000..99f92667223 --- /dev/null +++ b/cmd/mediatek/bootembedded.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2026 Carlo Caione <[email protected]> + */ + +#include <asm-generic/sections.h> +#include <command.h> +#include <mapmem.h> +#include <linux/kernel.h> +#include <linux/libfdt.h> + +static int do_bootembedded(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + ulong control_fdt_addr, script_addr; + const void *control_fdt, *script; + int ret; + + /* + * The control devicetree and the boot script are appended to the + * U-Boot binary, so they stay at the load address even after U-Boot + * has relocated itself. Derive that address from the image size, + * which is relocation invariant, instead of from _end, which moves + * with the relocated image. + */ + control_fdt_addr = CONFIG_TEXT_BASE + (ulong)(_end - (char *)&_start); + control_fdt = map_sysmem(control_fdt_addr, 0); + ret = fdt_check_header(control_fdt); + if (ret) { + printf("Invalid appended U-Boot control devicetree (%d)\n", ret); + goto unmap_control_fdt; + } + + /* + * RITY image generation pads the image to a multiple of 8 bytes before + * appending the script ('dd bs=8 conv=sync'), because libfdt requires + * 8-byte alignment. Keep both sides in sync. + */ + script_addr = ALIGN(control_fdt_addr + fdt_totalsize(control_fdt), 8); + unmap_sysmem(control_fdt); + + script = map_sysmem(script_addr, 0); + ret = fdt_check_header(script); + unmap_sysmem(script); + if (ret) { + printf("No valid appended MediaTek boot script (%d)\n", ret); + return CMD_RET_FAILURE; + } + + printf("Running appended MediaTek boot script at 0x%lx\n", script_addr); + return run_commandf("source %lx", script_addr); + +unmap_control_fdt: + unmap_sysmem(control_fdt); + return CMD_RET_FAILURE; +} + +U_BOOT_CMD(bootembedded, 1, 1, do_bootembedded, + "run the appended MediaTek embedded boot script", ""); diff --git a/doc/usage/cmd/bootembedded.rst b/doc/usage/cmd/bootembedded.rst new file mode 100644 index 00000000000..ebb2e5a32b0 --- /dev/null +++ b/doc/usage/cmd/bootembedded.rst @@ -0,0 +1,51 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright (C) 2026 Carlo Caione <[email protected]> + +.. index:: + single: bootembedded (command) + +bootembedded command +==================== + +Synopsis +-------- + +:: + + bootembedded + +Description +----------- + +The ``bootembedded`` command runs the RITY legacy boot script appended to the +U-Boot image. It locates U-Boot's separate control devicetree immediately +after the binary, validates it and uses its size to locate the script at the +next 8-byte-aligned address. + +The appended script is passed to the standard :doc:`source` command. The +script retains the legacy boot policy and can use the standard ``bootm`` +authentication path for secure boot. + +Image layout +------------ + +The command expects this layout at ``CONFIG_TEXT_BASE``:: + + +----------------------------+ + | U-Boot binary | + +----------------------------+ + | separate control DTB | + +----------------------------+ + | padding to 8-byte boundary | + +----------------------------+ + | RITY FIT boot script | + +----------------------------+ + +RITY image generation pads the control devicetree and script boundary with +``dd bs=8 conv=sync``. + +Configuration +------------- + +The command is available when ``CONFIG_CMD_MTK_BOOTEMBEDDED`` is enabled. It +requires ``CONFIG_CMD_SOURCE`` and ``CONFIG_OF_SEPARATE``. -- 2.55.0
