* [PATCH v2 1/9] fastboot: Add board_fastboot_flash/erase/get_part_info hooks
2026-12-05 10:05 [PATCH v2 0/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
@ 2026-12-05 10:05 ` Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 2/9] ARM: tegra: Refactor BCT patching process Svyatoslav Ryhel
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-12-05 10:05 UTC (permalink / raw)
To: Svyatoslav Ryhel, Thierry Reding, Tom Rini, Ilias Apalodimas,
Jonas Schwöbel, Ion Agorria, Peter Geis, Mattijs Korpershoek,
Guillaume La Roque
Cc: u-boot
From: Ion Agorria <ion@agorria.com>
This allows boards to intercept fastboot flash/erase and modify/change
behavior according to board specifics like AES encryption or RSA signing.
Add board_fastboot_get_part_info to provide info as fastboot tool queries
during flash/erase.
Signed-off-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
doc/android/fastboot.rst | 28 ++++++++++++++
drivers/fastboot/fb_command.c | 70 +++++++++++++++++++++++++++++++++++
drivers/fastboot/fb_getvar.c | 30 +++++++++++++++
3 files changed, 128 insertions(+)
diff --git a/doc/android/fastboot.rst b/doc/android/fastboot.rst
index 8e15f287f9b..e97a20365a7 100644
--- a/doc/android/fastboot.rst
+++ b/doc/android/fastboot.rst
@@ -331,6 +331,34 @@ In this case, ``cmd_parameter`` argument of the function ``fastboot_oem_board()`
will contain string "write_bootloader" and ``data`` argument is a pointer to
fastboot input buffer, which contains the contents of bootloader.img file.
+Adding Custom Flashing/Erasing Hooks
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+U-Boot allows adding a custom hook that intercepts fastboot flash and erase
+commands for partitions requiring special handling. The hook requires
+FASTBOOT_FLASH to be enabled and is implemented via the ``board_fastboot_flash()``,
+``board_fastboot_erase()``, and ``board_fastboot_get_part_info()`` helpers.
+
+``board_fastboot_flash()`` and ``board_fastboot_erase()`` intercept flash and erase
+operations. The ``char *cmd_parameter`` argument contains the partition name and
+should be used to determine which partition to operate on, even if it is not a
+physical partition. For example, Tegra devices require the bootloader to be
+encrypted with the internal AES engine (for production devices pre-Tegra 4) and
+the BCT to be decrypted, updated, and re-encrypted. This hook lets you perform
+this operation seamlessly for the end user via just::
+
+ $ fastboot flash bootloader u-boot-dtb-tegra.bin
+
+``board_fastboot_get_part_info()`` reports the size of special partitions. For
+example, Tegra devices use boot0/boot1 to store the bootloader and BCT. This
+allows exposing the entire mmcblk0 to the user without risking the boot chain,
+while none of those special partitions can be exposed through standard means.
+This helper resolves that limitation.
+
+Helpers that handle the request must return 0, after which no further handlers
+for this parameter are called. Returning -ENOTSUPP continues normal execution,
+while returning a negative error code (-error) aborts.
+
References
----------
diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c
index 63b0f5705fe..8a336913839 100644
--- a/drivers/fastboot/fb_command.c
+++ b/drivers/fastboot/fb_command.c
@@ -27,6 +27,49 @@
#define FASTBOOT_DOT_LINE_WIDTH_DEFAULT 74
+/**
+ * board_fastboot_flash() - board-specific hook for flashing
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @download_buffer: Pointer to fastboot download parameter
+ * @download_bytes: Size of downloaded file in bytes
+ * @response: Pointer to fastboot response buffer
+ *
+ * Implement a board-specific hook for partitions that require specific
+ * treatment, such as encryption, dependency updates, etc.
+ *
+ * This call is triggered first, before any other fastboot flash helpers.
+ *
+ * Return: 0 on success, or a negative errno on failure, which will trigger an
+ * abort of any fastboot flash events. Returning -ENOTSUPP will not trigger a
+ * stop of fastboot flash events.
+ */
+__weak int board_fastboot_flash(char *cmd_parameter, void *download_buffer,
+ u32 download_bytes, char *response)
+{
+ return -ENOTSUPP;
+}
+
+/**
+ * board_fastboot_erase() - board-specific hook for erasing
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ *
+ * Implement a board-specific hook for partitions that require specific
+ * treatment, such as dependency updates, flags setting, etc.
+ *
+ * This call is triggered first, before any other fastboot erase helpers.
+ *
+ * Return: 0 on success, or a negative errno on failure, which will trigger an
+ * abort of any fastboot erase events. Returning -ENOTSUPP will not trigger a
+ * stop of fastboot erase events.
+ */
+__weak int board_fastboot_erase(const char *cmd_parameter, char *response)
+{
+ return -ENOTSUPP;
+}
+
/**
* image_size - final fastboot image size
*/
@@ -458,9 +501,23 @@ void fastboot_data_complete(char *response)
*/
static void __maybe_unused flash(char *cmd_parameter, char *response)
{
+ int ret;
+
if (flashing_refuse_if_locked(response))
return;
+ if (CONFIG_IS_ENABLED(FASTBOOT_FLASH)) {
+ ret = board_fastboot_flash(cmd_parameter, fastboot_buf_addr,
+ image_size, response);
+ if (!ret)
+ return;
+
+ if (ret && ret != -ENOTSUPP) {
+ pr_debug("board_fastboot_flash failed with %d", ret);
+ return;
+ }
+ }
+
if (CONFIG_IS_ENABLED(FASTBOOT_FLASH_BLOCK))
fastboot_block_flash_write(cmd_parameter, fastboot_buf_addr,
image_size, response);
@@ -489,6 +546,19 @@ static void __maybe_unused flash(char *cmd_parameter, char *response)
*/
static void __maybe_unused erase_partition(const char *name, char *response)
{
+ int ret;
+
+ if (CONFIG_IS_ENABLED(FASTBOOT_FLASH)) {
+ ret = board_fastboot_erase(name, response);
+ if (!ret)
+ return;
+
+ if (ret && ret != -ENOTSUPP) {
+ pr_debug("board_fastboot_flash failed with %d", ret);
+ return;
+ }
+ }
+
if (CONFIG_IS_ENABLED(FASTBOOT_FLASH_BLOCK))
fastboot_block_erase(name, response);
diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c
index a85e1b0915a..fee269b5d85 100644
--- a/drivers/fastboot/fb_getvar.c
+++ b/drivers/fastboot/fb_getvar.c
@@ -32,6 +32,30 @@ static void getvar_is_userspace(char *var_parameter, char *response);
static void getvar_unlocked(char *var_parameter, char *response);
#endif
+/**
+ * board_fastboot_get_part_info() - board-specific hook to get partition size
+ *
+ * @part_name: Info for which partition name to look for
+ * @response: Pointer to fastboot response buffer
+ * @size: If not NULL, will contain partition size
+ *
+ * Implement a board-specific size check hook for partitions that require
+ * specific treatment, such as composed or hidden partitions etc.
+ *
+ * This call is triggered first, before any other fastboot get_part_info
+ * helpers.
+ *
+ * Return: the partition number on match (starting on 0), -1 on no match, or
+ * a negative errno on failure, which will trigger an abort of any fastboot
+ * get_part_info events. Returning -ENOTSUPP will not trigger a stop of
+ * fastboot get_part_info events.
+ */
+__weak int board_fastboot_get_part_info(const char *part_name, char *response,
+ size_t *size)
+{
+ return -ENOTSUPP;
+}
+
static const struct {
const char *variable;
bool list;
@@ -125,6 +149,12 @@ static int getvar_get_part_info(const char *part_name, char *response,
struct disk_partition disk_part;
struct part_info *part_info;
+ if (CONFIG_IS_ENABLED(FASTBOOT_FLASH)) {
+ r = board_fastboot_get_part_info(part_name, response, size);
+ if (r != -ENOTSUPP)
+ return r;
+ }
+
if (CONFIG_IS_ENABLED(FASTBOOT_FLASH_BLOCK)) {
r = fastboot_block_get_part_info(part_name, &dev_desc, &disk_part,
response);
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 2/9] ARM: tegra: Refactor BCT patching process
2026-12-05 10:05 [PATCH v2 0/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 1/9] fastboot: Add board_fastboot_flash/erase/get_part_info hooks Svyatoslav Ryhel
@ 2026-12-05 10:05 ` Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 3/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-12-05 10:05 UTC (permalink / raw)
To: Svyatoslav Ryhel, Thierry Reding, Tom Rini, Ilias Apalodimas,
Jonas Schwöbel, Ion Agorria, Peter Geis, Mattijs Korpershoek,
Guillaume La Roque
Cc: u-boot
From: Ion Agorria <ion@agorria.com>
Commonize the BCT patching process across all supported Tegra SoC
generations. Refactor the function to handle core logic only, allowing it
to be used in other execution pathways.
Signed-off-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
arch/arm/mach-tegra/Kconfig | 7 +-
arch/arm/mach-tegra/Makefile | 1 +
arch/arm/mach-tegra/{tegra20 => }/bct.c | 63 +++++++++---------
arch/arm/mach-tegra/bct.h | 44 +++++++++++++
arch/arm/mach-tegra/tegra124/Makefile | 1 -
arch/arm/mach-tegra/tegra124/bct.c | 86 -------------------------
arch/arm/mach-tegra/tegra124/bct.h | 24 +------
arch/arm/mach-tegra/tegra20/Makefile | 1 -
arch/arm/mach-tegra/tegra20/bct.h | 22 ++-----
arch/arm/mach-tegra/tegra30/Makefile | 1 -
arch/arm/mach-tegra/tegra30/bct.c | 84 ------------------------
arch/arm/mach-tegra/tegra30/bct.h | 22 ++-----
12 files changed, 95 insertions(+), 261 deletions(-)
rename arch/arm/mach-tegra/{tegra20 => }/bct.c (54%)
create mode 100644 arch/arm/mach-tegra/bct.h
delete mode 100644 arch/arm/mach-tegra/tegra124/bct.c
delete mode 100644 arch/arm/mach-tegra/tegra30/bct.c
diff --git a/arch/arm/mach-tegra/Kconfig b/arch/arm/mach-tegra/Kconfig
index 32cdfebfc01..ec4993788f1 100644
--- a/arch/arm/mach-tegra/Kconfig
+++ b/arch/arm/mach-tegra/Kconfig
@@ -21,6 +21,11 @@ config TEGRA_CRYPTO
select AES
select TEGRA_AES
+config TEGRA_BCT
+ bool "Tegra BCT operations"
+ depends on TEGRA20 || TEGRA30 || TEGRA124
+ select TEGRA_CRYPTO
+
config TEGRA_GP_PADCTRL
bool
@@ -267,7 +272,7 @@ config CMD_ENTERRCM
config CMD_EBTUPDATE
bool "Enable 'ebtupdate' command"
depends on TEGRA20 || TEGRA30 || TEGRA124
- select TEGRA_CRYPTO
+ select TEGRA_BCT
help
Updating u-boot from within u-boot in rather complex or even
impossible on production devices. To make it easier procedure of
diff --git a/arch/arm/mach-tegra/Makefile b/arch/arm/mach-tegra/Makefile
index 2f0341bc02a..63fd95d7208 100644
--- a/arch/arm/mach-tegra/Makefile
+++ b/arch/arm/mach-tegra/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_TEGRA_GPU) += gpu.o
obj-$(CONFIG_TEGRA_IVC) += ivc.o
ifndef CONFIG_XPL_BUILD
obj-$(CONFIG_ARMV7_PSCI) += psci.o
+obj-$(CONFIG_TEGRA_BCT) += bct.o
endif
obj-$(CONFIG_DISPLAY_CPUINFO) += sys_info.o
obj-y += pmc.o
diff --git a/arch/arm/mach-tegra/tegra20/bct.c b/arch/arm/mach-tegra/bct.c
similarity index 54%
rename from arch/arm/mach-tegra/tegra20/bct.c
rename to arch/arm/mach-tegra/bct.c
index 0270cf592c1..a4647d854a7 100644
--- a/arch/arm/mach-tegra/tegra20/bct.c
+++ b/arch/arm/mach-tegra/bct.c
@@ -13,72 +13,67 @@
#include "bct.h"
#include "uboot_aes.h"
-/*
- * @param bct boot config table start in RAM
- * @param ect bootloader start in RAM
- * @param ebt_size bootloader file size in bytes
- * Return: 0, or 1 if failed
- */
-static int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size)
+int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size)
{
- struct nvboot_config_table *bct_tbl = NULL;
- u8 ebt_hash[AES128_KEY_LENGTH] = { 0 };
- u8 *bct_hash = bct;
+ struct nvboot_config_table *bct_tbl = (struct nvboot_config_table *)bct;
bool encrypted;
int ret;
- bct += BCT_HASH;
+ bct += UBCT_LENGTH;
ebt_size = roundup(ebt_size, EBT_ALIGNMENT);
- encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE;
-
- if (encrypted) {
- ret = decrypt_data_block(bct, bct, BCT_LENGTH);
- if (ret)
- return 1;
-
- ret = encrypt_data_block(ebt, ebt, ebt_size);
- if (ret)
- return 1;
- }
-
- ret = sign_data_block(ebt, ebt_size, ebt_hash);
+ ret = sign_data_block(ebt, ebt_size, (u8 *)bct_tbl->bootloader[0].crypto_hash);
if (ret)
return 1;
- bct_tbl = (struct nvboot_config_table *)bct;
-
- memcpy((u8 *)&bct_tbl->bootloader[0].crypto_hash,
- ebt_hash, NVBOOT_CMAC_AES_HASH_LENGTH * 4);
bct_tbl->bootloader[0].entry_point = CONFIG_SPL_TEXT_BASE;
bct_tbl->bootloader[0].load_addr = CONFIG_SPL_TEXT_BASE;
bct_tbl->bootloader[0].length = ebt_size;
+ encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE;
if (encrypted) {
- ret = encrypt_data_block(bct, bct, BCT_LENGTH);
+ ret = encrypt_data_block(bct, bct, SBCT_LENGTH);
if (ret)
return 1;
}
- ret = sign_data_block(bct, BCT_LENGTH, bct_hash);
+ ret = sign_data_block(bct, SBCT_LENGTH, (u8 *)bct_tbl->crypto_hash);
if (ret)
return 1;
return 0;
+
}
+#ifdef CONFIG_CMD_EBTUPDATE
static int do_ebtupdate(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
- u32 bct_addr = hextoul(argv[1], NULL);
- u32 ebt_addr = hextoul(argv[2], NULL);
+ u8 *bct = (u8 *)hextoul(argv[1], NULL);
+ u8 *ebt = (u8 *)hextoul(argv[2], NULL);
u32 ebt_size = hextoul(argv[3], NULL);
+ bool encrypted;
+ int ret;
+
+ ebt_size = roundup(ebt_size, EBT_ALIGNMENT);
+ encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE;
+
+ if (encrypted) {
+ ret = decrypt_data_block(bct, bct, SBCT_LENGTH);
+ if (ret)
+ return 1;
+
+ ret = encrypt_data_block(ebt, ebt, ebt_size);
+ if (ret)
+ return 1;
+ }
- return bct_patch((u8 *)bct_addr, (u8 *)ebt_addr, ebt_size);
+ return bct_patch(bct, ebt, ebt_size);
}
U_BOOT_CMD(ebtupdate, 4, 0, do_ebtupdate,
- "update bootloader on re-crypted Tegra20 devices",
+ "update bootloader on re-crypted Tegra devices",
""
);
+#endif
diff --git a/arch/arm/mach-tegra/bct.h b/arch/arm/mach-tegra/bct.h
new file mode 100644
index 00000000000..76756cba8ed
--- /dev/null
+++ b/arch/arm/mach-tegra/bct.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#ifndef _BCT_H_
+#define _BCT_H_
+
+#define EBT_ALIGNMENT 0x10
+
+/*
+ * Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words)
+ */
+#define NVBOOT_CMAC_AES_HASH_LENGTH 4
+
+/*
+ * Defines the RSA modulus length in 32 bit words used for PKC secure boot.
+ */
+#define NVBOOT_SE_RSA_MODULUS_LENGTH 64
+
+/*
+ * Defines the maximum number of bootloader descriptions in the BCT.
+ */
+#define NVBOOT_MAX_BOOTLOADERS 4
+
+#ifdef CONFIG_TEGRA20
+#include "tegra20/bct.h"
+#elif CONFIG_TEGRA30
+#include "tegra30/bct.h"
+#elif CONFIG_TEGRA124
+#include "tegra124/bct.h"
+#endif
+
+#define BCT_LENGTH (UBCT_LENGTH + SBCT_LENGTH)
+
+/*
+ * Updates the hash of bootloader entry and the BCT itself
+ * It will encrypt BCT in place if the device requires it
+ *
+ * @param bct boot config table start in RAM
+ * @param ebt bootloader start in RAM
+ * @param ebt_size bootloader file size in bytes
+ * Return: 0, or 1 if failed
+ */
+int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size);
+
+#endif /* _BCT_H_ */
diff --git a/arch/arm/mach-tegra/tegra124/Makefile b/arch/arm/mach-tegra/tegra124/Makefile
index 7b93db89c0f..dee790015a3 100644
--- a/arch/arm/mach-tegra/tegra124/Makefile
+++ b/arch/arm/mach-tegra/tegra124/Makefile
@@ -6,7 +6,6 @@
#
obj-$(CONFIG_XPL_BUILD) += cpu.o
-obj-$(CONFIG_$(XPL_)CMD_EBTUPDATE) += bct.o
obj-y += clock.o
obj-y += pmc.o
diff --git a/arch/arm/mach-tegra/tegra124/bct.c b/arch/arm/mach-tegra/tegra124/bct.c
deleted file mode 100644
index 676b68dc5de..00000000000
--- a/arch/arm/mach-tegra/tegra124/bct.c
+++ /dev/null
@@ -1,86 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2022, Ramin <raminterex@yahoo.com>
- * Copyright (c) 2022, Svyatoslav Ryhel <clamor95@gmail.com>
- */
-
-#include <command.h>
-#include <log.h>
-#include <vsprintf.h>
-#include <linux/string.h>
-#include <asm/arch-tegra/crypto.h>
-#include <asm/arch-tegra/fuse.h>
-#include "bct.h"
-#include "uboot_aes.h"
-
-/*
- * @param bct boot config table start in RAM
- * @param ect bootloader start in RAM
- * @param ebt_size bootloader file size in bytes
- * Return: 0, or 1 if failed
- */
-static int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size)
-{
- struct nvboot_config_table *bct_tbl = NULL;
- u8 ebt_hash[AES128_KEY_LENGTH] = { 0 };
- u8 bct_hash[AES128_KEY_LENGTH] = { 0 };
- u8 *sbct = bct + UBCT_LENGTH;
- bool encrypted;
- int ret;
-
- ebt_size = roundup(ebt_size, EBT_ALIGNMENT);
-
- encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE;
-
- if (encrypted) {
- ret = decrypt_data_block(sbct, sbct, SBCT_LENGTH);
- if (ret)
- return 1;
-
- ret = encrypt_data_block(ebt, ebt, ebt_size);
- if (ret)
- return 1;
- }
-
- ret = sign_data_block(ebt, ebt_size, ebt_hash);
- if (ret)
- return 1;
-
- bct_tbl = (struct nvboot_config_table *)bct;
-
- memcpy((u8 *)&bct_tbl->bootloader[0].crypto_hash,
- ebt_hash, NVBOOT_CMAC_AES_HASH_LENGTH * 4);
- bct_tbl->bootloader[0].entry_point = CONFIG_SPL_TEXT_BASE;
- bct_tbl->bootloader[0].load_addr = CONFIG_SPL_TEXT_BASE;
- bct_tbl->bootloader[0].length = ebt_size;
-
- if (encrypted) {
- ret = encrypt_data_block(sbct, sbct, SBCT_LENGTH);
- if (ret)
- return 1;
- }
-
- ret = sign_data_block(sbct, SBCT_LENGTH, bct_hash);
- if (ret)
- return 1;
-
- memcpy((u8 *)&bct_tbl->crypto_hash, bct_hash,
- NVBOOT_CMAC_AES_HASH_LENGTH * 4);
-
- return 0;
-}
-
-static int do_ebtupdate(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
-{
- u32 bct_addr = hextoul(argv[1], NULL);
- u32 ebt_addr = hextoul(argv[2], NULL);
- u32 ebt_size = hextoul(argv[3], NULL);
-
- return bct_patch((u8 *)bct_addr, (u8 *)ebt_addr, ebt_size);
-}
-
-U_BOOT_CMD(ebtupdate, 4, 0, do_ebtupdate,
- "update bootloader on re-crypted Tegra124 devices",
- ""
-);
diff --git a/arch/arm/mach-tegra/tegra124/bct.h b/arch/arm/mach-tegra/tegra124/bct.h
index eb0f712d595..f7d65621c0a 100644
--- a/arch/arm/mach-tegra/tegra124/bct.h
+++ b/arch/arm/mach-tegra/tegra124/bct.h
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0+ */
-#ifndef _BCT_H_
-#define _BCT_H_
+#ifndef _TEGRA124_BCT_H_
+#define _TEGRA124_BCT_H_
/*
* Defines the BCT parametres for T124
@@ -9,24 +9,6 @@
#define UBCT_LENGTH 0x6b0 /* bytes */
#define SBCT_LENGTH 0x1950 /* bytes */
-#define BCT_HASH 0x10
-#define EBT_ALIGNMENT 0x10
-
-/*
- * Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words)
- */
-#define NVBOOT_CMAC_AES_HASH_LENGTH 4
-
-/*
- * Defines the RSA modulus length in 32 bit words used for PKC secure boot.
- */
-#define NVBOOT_SE_RSA_MODULUS_LENGTH 64
-
-/*
- * Defines the maximum number of bootloader descriptions in the BCT.
- */
-#define NVBOOT_MAX_BOOTLOADERS 4
-
struct nv_bootloader_info {
u32 version;
u32 start_blk;
@@ -52,4 +34,4 @@ struct nvboot_config_table {
u32 sbct_unused2;
};
-#endif /* _BCT_H_ */
+#endif /* _TEGRA124_BCT_H_ */
diff --git a/arch/arm/mach-tegra/tegra20/Makefile b/arch/arm/mach-tegra/tegra20/Makefile
index a3ea759d764..fad4b1bc07d 100644
--- a/arch/arm/mach-tegra/tegra20/Makefile
+++ b/arch/arm/mach-tegra/tegra20/Makefile
@@ -3,7 +3,6 @@
# (C) Copyright 2010,2011 Nvidia Corporation.
obj-$(CONFIG_XPL_BUILD) += cpu.o
-obj-$(CONFIG_$(PHASE_)CMD_EBTUPDATE) += bct.o
# The AVP is ARMv4T architecture so we must use special compiler
# flags for any startup files it might use.
diff --git a/arch/arm/mach-tegra/tegra20/bct.h b/arch/arm/mach-tegra/tegra20/bct.h
index 4b78aef7cfd..a9feba42bf6 100644
--- a/arch/arm/mach-tegra/tegra20/bct.h
+++ b/arch/arm/mach-tegra/tegra20/bct.h
@@ -1,24 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0+ */
-#ifndef _BCT_H_
-#define _BCT_H_
+#ifndef _TEGRA20_BCT_H_
+#define _TEGRA20_BCT_H_
/*
* Defines the BCT parametres for T20
*/
-#define BCT_LENGTH 0xFE0
-#define BCT_HASH 0x10
-#define EBT_ALIGNMENT 0x10
-
-/*
- * Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words)
- */
-#define NVBOOT_CMAC_AES_HASH_LENGTH 4
-
-/*
- * Defines the maximum number of bootloader descriptions in the BCT.
- */
-#define NVBOOT_MAX_BOOTLOADERS 4
+#define UBCT_LENGTH 0x10
+#define SBCT_LENGTH 0xFE0
struct nv_bootloader_info {
u32 version;
@@ -32,6 +21,7 @@ struct nv_bootloader_info {
};
struct nvboot_config_table {
+ u32 crypto_hash[NVBOOT_CMAC_AES_HASH_LENGTH];
u32 unused0[4];
u32 boot_data_version;
u32 unused1[668];
@@ -39,4 +29,4 @@ struct nvboot_config_table {
u32 unused2[508];
};
-#endif /* _BCT_H_ */
+#endif /* _TEGRA20_BCT_H_ */
diff --git a/arch/arm/mach-tegra/tegra30/Makefile b/arch/arm/mach-tegra/tegra30/Makefile
index d6351734ec0..d983800a89c 100644
--- a/arch/arm/mach-tegra/tegra30/Makefile
+++ b/arch/arm/mach-tegra/tegra30/Makefile
@@ -3,6 +3,5 @@
# Copyright (c) 2010-2012, NVIDIA CORPORATION. All rights reserved.
obj-$(CONFIG_XPL_BUILD) += cpu.o
-obj-$(CONFIG_$(PHASE_)CMD_EBTUPDATE) += bct.o
obj-y += clock.o
diff --git a/arch/arm/mach-tegra/tegra30/bct.c b/arch/arm/mach-tegra/tegra30/bct.c
deleted file mode 100644
index de668214517..00000000000
--- a/arch/arm/mach-tegra/tegra30/bct.c
+++ /dev/null
@@ -1,84 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2022, Ramin <raminterex@yahoo.com>
- * Copyright (c) 2022, Svyatoslav Ryhel <clamor95@gmail.com>
- */
-
-#include <command.h>
-#include <log.h>
-#include <vsprintf.h>
-#include <linux/string.h>
-#include <asm/arch-tegra/crypto.h>
-#include <asm/arch-tegra/fuse.h>
-#include "bct.h"
-#include "uboot_aes.h"
-
-/*
- * @param bct boot config table start in RAM
- * @param ect bootloader start in RAM
- * @param ebt_size bootloader file size in bytes
- * Return: 0, or 1 if failed
- */
-static int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size)
-{
- struct nvboot_config_table *bct_tbl = NULL;
- u8 ebt_hash[AES128_KEY_LENGTH] = { 0 };
- u8 *bct_hash = bct;
- bool encrypted;
- int ret;
-
- bct += BCT_HASH;
-
- ebt_size = roundup(ebt_size, EBT_ALIGNMENT);
-
- encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE;
-
- if (encrypted) {
- ret = decrypt_data_block(bct, bct, BCT_LENGTH);
- if (ret)
- return 1;
-
- ret = encrypt_data_block(ebt, ebt, ebt_size);
- if (ret)
- return 1;
- }
-
- ret = sign_data_block(ebt, ebt_size, ebt_hash);
- if (ret)
- return 1;
-
- bct_tbl = (struct nvboot_config_table *)bct;
-
- memcpy((u8 *)&bct_tbl->bootloader[0].crypto_hash,
- ebt_hash, NVBOOT_CMAC_AES_HASH_LENGTH * 4);
- bct_tbl->bootloader[0].entry_point = CONFIG_SPL_TEXT_BASE;
- bct_tbl->bootloader[0].load_addr = CONFIG_SPL_TEXT_BASE;
- bct_tbl->bootloader[0].length = ebt_size;
-
- if (encrypted) {
- ret = encrypt_data_block(bct, bct, BCT_LENGTH);
- if (ret)
- return 1;
- }
-
- ret = sign_data_block(bct, BCT_LENGTH, bct_hash);
- if (ret)
- return 1;
-
- return 0;
-}
-
-static int do_ebtupdate(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
-{
- u32 bct_addr = hextoul(argv[1], NULL);
- u32 ebt_addr = hextoul(argv[2], NULL);
- u32 ebt_size = hextoul(argv[3], NULL);
-
- return bct_patch((u8 *)bct_addr, (u8 *)ebt_addr, ebt_size);
-}
-
-U_BOOT_CMD(ebtupdate, 4, 0, do_ebtupdate,
- "update bootloader on re-crypted Tegra30 devices",
- ""
-);
diff --git a/arch/arm/mach-tegra/tegra30/bct.h b/arch/arm/mach-tegra/tegra30/bct.h
index 9797384da32..8420615ce62 100644
--- a/arch/arm/mach-tegra/tegra30/bct.h
+++ b/arch/arm/mach-tegra/tegra30/bct.h
@@ -1,24 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0+ */
-#ifndef _BCT_H_
-#define _BCT_H_
+#ifndef _TEGRA30_BCT_H_
+#define _TEGRA30_BCT_H_
/*
* Defines the BCT parametres for T30
*/
-#define BCT_LENGTH 0x17E0
-#define BCT_HASH 0x10
-#define EBT_ALIGNMENT 0x10
-
-/*
- * Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words)
- */
-#define NVBOOT_CMAC_AES_HASH_LENGTH 4
-
-/*
- * Defines the maximum number of bootloader descriptions in the BCT.
- */
-#define NVBOOT_MAX_BOOTLOADERS 4
+#define UBCT_LENGTH 0x10
+#define SBCT_LENGTH 0x17E0
struct nv_bootloader_info {
u32 version;
@@ -32,6 +21,7 @@ struct nv_bootloader_info {
};
struct nvboot_config_table {
+ u32 crypto_hash[NVBOOT_CMAC_AES_HASH_LENGTH];
u32 unused0[4];
u32 boot_data_version;
u32 unused1[972];
@@ -39,4 +29,4 @@ struct nvboot_config_table {
u32 unused2[508];
};
-#endif /* _BCT_H_ */
+#endif /* _TEGRA30_BCT_H_ */
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 3/9] ARM: tegra: Add custom fastboot flash handler
2026-12-05 10:05 [PATCH v2 0/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 1/9] fastboot: Add board_fastboot_flash/erase/get_part_info hooks Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 2/9] ARM: tegra: Refactor BCT patching process Svyatoslav Ryhel
@ 2026-12-05 10:05 ` Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 4/9] configs: tegra: Enable TEGRA_FASTBOOT_FLASH option Svyatoslav Ryhel
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-12-05 10:05 UTC (permalink / raw)
To: Svyatoslav Ryhel, Thierry Reding, Tom Rini, Ilias Apalodimas,
Jonas Schwöbel, Ion Agorria, Peter Geis, Mattijs Korpershoek,
Guillaume La Roque
Cc: u-boot
From: Ion Agorria <ion@agorria.com>
Implement the final piece for allowing autonomous BCT and bootloader
flashing via fastboot. Handle AES encryption of both BCT and EBT if
required, update BCT hashes and write into the required places.
Signed-off-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
arch/arm/mach-tegra/Kconfig | 11 +
arch/arm/mach-tegra/Makefile | 1 +
arch/arm/mach-tegra/bct.c | 865 ++++++++++++++++++++++++++++-
arch/arm/mach-tegra/bct.h | 60 +-
arch/arm/mach-tegra/fastboot.c | 78 +++
arch/arm/mach-tegra/tegra124/bct.h | 40 +-
arch/arm/mach-tegra/tegra20/bct.h | 33 +-
arch/arm/mach-tegra/tegra30/bct.h | 33 +-
8 files changed, 1085 insertions(+), 36 deletions(-)
create mode 100644 arch/arm/mach-tegra/fastboot.c
diff --git a/arch/arm/mach-tegra/Kconfig b/arch/arm/mach-tegra/Kconfig
index ec4993788f1..8c074dce189 100644
--- a/arch/arm/mach-tegra/Kconfig
+++ b/arch/arm/mach-tegra/Kconfig
@@ -278,4 +278,15 @@ config CMD_EBTUPDATE
impossible on production devices. To make it easier procedure of
re-cryption was created. If your device was re-crypted choose Y.
+config TEGRA_FASTBOOT_FLASH
+ bool "Enable 'fastboot flash' board hook for bootloader flashing"
+ depends on TEGRA20 || TEGRA30 || TEGRA124
+ depends on FASTBOOT_FLASH
+ select TEGRA_BCT
+ help
+ Allow flashing bootloader automatically by only providing a single
+ bootloader image via fastboot flash, the code takes care of
+ patching BCT and flashing both BCT and encrypted bootloader
+ back into boot storage if applicable.
+
endif
diff --git a/arch/arm/mach-tegra/Makefile b/arch/arm/mach-tegra/Makefile
index 63fd95d7208..b66b68c3dbb 100644
--- a/arch/arm/mach-tegra/Makefile
+++ b/arch/arm/mach-tegra/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_TEGRA_IVC) += ivc.o
ifndef CONFIG_XPL_BUILD
obj-$(CONFIG_ARMV7_PSCI) += psci.o
obj-$(CONFIG_TEGRA_BCT) += bct.o
+obj-$(CONFIG_TEGRA_FASTBOOT_FLASH) += fastboot.o
endif
obj-$(CONFIG_DISPLAY_CPUINFO) += sys_info.o
obj-y += pmc.o
diff --git a/arch/arm/mach-tegra/bct.c b/arch/arm/mach-tegra/bct.c
index a4647d854a7..2c77ff8474a 100644
--- a/arch/arm/mach-tegra/bct.c
+++ b/arch/arm/mach-tegra/bct.c
@@ -2,18 +2,127 @@
/*
* Copyright (c) 2022, Ramin <raminterex@yahoo.com>
* Copyright (c) 2022, Svyatoslav Ryhel <clamor95@gmail.com>
+ * Copyright (c) 2026, Ion Agorria <ion@agorria.com>
*/
+#include <dm.h>
+#include <blk.h>
#include <command.h>
+#include <fs.h>
#include <log.h>
+#include <mmc.h>
+#include <spi.h>
+#include <spi_flash.h>
+#include <stdlib.h>
+#include <string.h>
#include <vsprintf.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/printk.h>
#include <linux/string.h>
+
+#include <asm/arch-tegra/ap.h>
#include <asm/arch-tegra/crypto.h>
#include <asm/arch-tegra/fuse.h>
+#include <asm/arch-tegra/pmc.h>
+
#include "bct.h"
#include "uboot_aes.h"
-int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size)
+#define NV_PA_IRAM_BASE 0x40000000
+
+static int convert_to_blocks(struct blk_desc *dev_desc, int len)
+{
+ len = ((len + (dev_desc->blksz - 1)) & ~(dev_desc->blksz - 1));
+ return lldiv(len, dev_desc->blksz);
+}
+
+static int get_mmc_hwpart_from_offset(struct mmc *mmc, u32 *data_offset,
+ u32 data_size)
+{
+ /*
+ * Get which hwpart the offset is located, assuming the offset follows
+ * a linear layout as: eMMC start | [boot0] - [boot1] - [user] | eMMC end
+ */
+ if (*data_offset < mmc->capacity_boot) {
+ if (*data_offset + data_size > mmc->capacity_boot) {
+ log_err("Data doesn't fit within the boundaries of boot0 partition\n");
+ return -EINVAL;
+ }
+
+ return 1;
+ } else if (*data_offset < mmc->capacity_boot * 2) {
+ *data_offset -= mmc->capacity_boot;
+ if (*data_offset + data_size > mmc->capacity_boot) {
+ log_err("Data doesn't fit within the boundaries of boot1 partition\n");
+ return -EINVAL;
+ }
+
+ return 2;
+ } else {
+ *data_offset -= mmc->capacity_boot * 2;
+ if (*data_offset + data_size > mmc->capacity_user) {
+ log_err("Data doesn't fit within the boundaries of user partition\n");
+ return -EINVAL;
+ }
+
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+static bool is_bct_valid(struct nvboot_config_table *bct)
+{
+ int soc_expected = tegra_get_chip();
+ int soc_val = (bct->boot_data_version >> 16) & 0xff;
+
+ /* Make 0x2 and 0x3 into 0x20 and 0x30 for Tegra 2/3 */
+ if (soc_val <= 0x3)
+ soc_val <<= 4;
+
+ log_debug("Checking BCT\n");
+
+ if (!soc_expected || soc_expected != soc_val) {
+ log_debug("SoC doesn't match: soc %d bct %d\n",
+ soc_expected, soc_val);
+ return false;
+ }
+
+ if ((bct->boot_data_version & 0xf) != 1) {
+ log_debug("Boot data version not 1\n");
+ return false;
+ }
+
+ if (bct->block_size_log2 < 8 || bct->block_size_log2 > 23) {
+ log_debug("Block size out of bounds\n");
+ return false;
+ }
+
+ if (bct->page_size_log2 < 8 || bct->page_size_log2 > 14) {
+ log_debug("Page size out of bounds\n");
+ return false;
+ }
+
+ if (bct->num_param_sets > NVBOOT_MAX_PARAM_SETS) {
+ log_debug("Number of param sets out of bounds\n");
+ return false;
+ }
+
+ if (bct->num_sdram_sets > NVBOOT_MAX_SDRAM_SETS) {
+ log_debug("Number of sdram sets out of bounds\n");
+ return false;
+ }
+
+ if (bct->bootloader_used > NVBOOT_MAX_BOOTLOADERS) {
+ log_debug("Bootloader used out of bounds\n");
+ return false;
+ }
+
+ return true;
+}
+
+static int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size)
{
struct nvboot_config_table *bct_tbl = (struct nvboot_config_table *)bct;
bool encrypted;
@@ -21,7 +130,7 @@ int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size)
bct += UBCT_LENGTH;
- ebt_size = roundup(ebt_size, EBT_ALIGNMENT);
+ ebt_size = roundup(ebt_size, AES_BLOCK_LENGTH);
ret = sign_data_block(ebt, ebt_size, (u8 *)bct_tbl->bootloader[0].crypto_hash);
if (ret)
@@ -43,37 +152,759 @@ int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size)
return 1;
return 0;
+}
+static enum tegra_boot_device get_boot_device(void)
+{
+ void *fdt = (void *)gd->fdt_blob;
+ static const char * const spi_nodes[] = {
+ "/spi@7000c380", /* Tegra20 */
+ "/spi@7000d400", "/spi@7000d600", "/spi@7000d800",
+ "/spi@7000da00", "/spi@7000dc00", "/spi@7000de00"
+ };
+ int spi_node, subnode, i, ret;
+
+ for (i = 0; i < ARRAY_SIZE(spi_nodes); i++) {
+ spi_node = fdt_path_offset(fdt, spi_nodes[i]);
+ if (spi_node < 0)
+ continue;
+
+ fdt_for_each_subnode(subnode, fdt, spi_node) {
+ ret = fdt_node_check_compatible(fdt, subnode,
+ "jedec,spi-nor");
+ if (!ret)
+ return TEGRA_BOOT_DEVICE_SPI;
+ }
+ }
+
+ if (find_mmc_device(0))
+ return TEGRA_BOOT_DEVICE_MMC;
+
+ return TEGRA_BOOT_DEVICE_UNKNOWN;
}
-#ifdef CONFIG_CMD_EBTUPDATE
-static int do_ebtupdate(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
+static int access_boot_data_mmc(struct tegra_boot_update_context *ctx,
+ u8 *data_ptr, u32 data_offset, u32 data_size)
+{
+ int ret, hwpart, data_offset_blk, data_size_blk;
+ struct blk_desc *dev_desc;
+
+ /* Switch to hw partition where data will be read in MMC */
+ hwpart = get_mmc_hwpart_from_offset(ctx->mmc, &data_offset, data_size);
+ if (hwpart < 0)
+ return hwpart;
+
+ dev_desc = mmc_get_blk_desc(ctx->mmc);
+ ret = blk_dselect_hwpart(dev_desc, hwpart);
+ if (ret) {
+ log_err("Failed to select MMC hwpart %d (%d)\n", hwpart, ret);
+ return ret;
+ }
+
+ data_offset_blk = convert_to_blocks(dev_desc, data_offset);
+ data_size_blk = convert_to_blocks(dev_desc, data_size);
+
+ log_debug("hwpart: %d offset blk: 0x%x size blk: 0x%x\n",
+ hwpart, data_offset_blk, data_size_blk);
+
+ if (data_ptr) {
+ /* Writing */
+ ret = blk_dwrite(dev_desc, data_offset_blk, data_size_blk,
+ data_ptr);
+ } else {
+ /* Reading */
+ ret = blk_dread(dev_desc, data_offset_blk, data_size_blk,
+ (u8 *)CONFIG_SYS_LOAD_ADDR);
+ }
+
+ if (ret != data_size_blk) {
+ log_err("Failed to %s data at MMC (%d)\n",
+ data_ptr ? "write" : "read", ret);
+ return -EREMOTEIO;
+ }
+
+ return 0;
+}
+
+static int access_boot_data_spi(struct tegra_boot_update_context *ctx,
+ u8 *data_ptr, u32 data_offset, u32 data_size)
{
- u8 *bct = (u8 *)hextoul(argv[1], NULL);
- u8 *ebt = (u8 *)hextoul(argv[2], NULL);
- u32 ebt_size = hextoul(argv[3], NULL);
- bool encrypted;
int ret;
- ebt_size = roundup(ebt_size, EBT_ALIGNMENT);
- encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE;
+ if (!data_ptr) {
+ /* Reading */
+ ret = spi_flash_read(ctx->spi_flash, data_offset, data_size,
+ (u8 *)CONFIG_SYS_LOAD_ADDR);
+ if (ret) {
+ log_err("Failed to read data at SF (%d)\n", ret);
+ return ret;
+ }
+
+ return 0;
+ }
+
+ /* Writing */
+
+ /* Check if fits */
+ if (data_offset + data_size > ctx->spi_flash->size) {
+ log_err("Data to write doesn't fit in SF\n");
+ return ret;
+ }
+
+ /* Erase and write */
+ ret = spi_flash_erase(ctx->spi_flash, data_offset,
+ ROUND(data_size, ctx->spi_flash->erase_size));
+ if (ret) {
+ log_err("Failed to erase data at SF (%d)\n", ret);
+ return ret;
+ }
+
+ ret = spi_flash_write(ctx->spi_flash, data_offset, data_size, data_ptr);
+ if (ret) {
+ log_err("Failed to write data at SF (%d)\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int read_boot_data(struct tegra_boot_update_context *ctx,
+ u32 data_offset, u32 data_size)
+{
+ log_debug("Read boot data offset: 0x%x size: %d\n",
+ data_offset, data_size);
+
+ if (ctx->dev == TEGRA_BOOT_DEVICE_MMC)
+ return access_boot_data_mmc(ctx, NULL, data_offset, data_size);
+ else if (ctx->dev == TEGRA_BOOT_DEVICE_SPI)
+ return access_boot_data_spi(ctx, NULL, data_offset, data_size);
+
+ log_err("No boot device to read\n");
+ return -ENODEV;
+}
+
+static int write_boot_data(struct tegra_boot_update_context *ctx,
+ u8 *data_ptr, u32 data_offset, u32 data_size)
+{
+ int ret;
+
+ /* Check if data already matches to avoid writing same thing */
+ ret = read_boot_data(ctx, data_offset, data_size);
+ if (ret) {
+ log_err("Failed to read data to check (%d)\n", ret);
+ return ret;
+ }
+
+ log_debug("Write boot data ptr: %p offset: 0x%x size: %d\n",
+ data_ptr, data_offset, data_size);
+
+ if (memcmp(data_ptr, (u8 *)CONFIG_SYS_LOAD_ADDR, data_size) == 0) {
+ log_debug("Skipping write, data already matches\n");
+ return 0;
+ }
+
+ /* Write the data */
+ if (ctx->dev == TEGRA_BOOT_DEVICE_MMC) {
+ ret = access_boot_data_mmc(ctx, data_ptr, data_offset, data_size);
+ } else if (ctx->dev == TEGRA_BOOT_DEVICE_SPI) {
+ ret = access_boot_data_spi(ctx, data_ptr, data_offset, data_size);
+ } else {
+ log_err("No boot device to write\n");
+ return -ENODEV;
+ }
+ if (ret)
+ return ret;
+ /* Verify written data matches */
+ ret = read_boot_data(ctx, data_offset, data_size);
+ if (ret) {
+ log_err("Failed to read data to verify (%d)\n", ret);
+ return ret;
+ }
+
+ if (memcmp(data_ptr, (u8 *)CONFIG_SYS_LOAD_ADDR, data_size) != 0) {
+ log_err("Written data mismatches\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+/*
+ * Attempt to read a copy of BCT from boot device
+ */
+static int read_boot_device_bct(struct tegra_boot_update_context *ctx)
+{
+ int ret;
+ bool encrypted;
+
+ ret = read_boot_data(ctx, 0, BCT_LENGTH);
+ if (ret)
+ return ret;
+
+ /* Check and decrypt */
+ encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE;
if (encrypted) {
+ u8 *bct = ((u8 *)CONFIG_SYS_LOAD_ADDR) + UBCT_LENGTH;
+
ret = decrypt_data_block(bct, bct, SBCT_LENGTH);
if (ret)
- return 1;
+ return ret;
+ }
+
+ if (is_bct_valid((struct nvboot_config_table *)CONFIG_SYS_LOAD_ADDR)) {
+ if (!ctx->bct)
+ ctx->bct = (struct nvboot_config_table *)malloc(BCT_LENGTH);
+ memcpy(ctx->bct, (u8 *)CONFIG_SYS_LOAD_ADDR, BCT_LENGTH);
+ }
+
+ return 0;
+}
+
+/*
+ * Attempt to read a copy of BCT from IRAM
+ */
+static int read_iram_bct(struct tegra_boot_update_context *ctx)
+{
+ struct tegra_boot_info_table *bit =
+ (struct tegra_boot_info_table *)NV_PA_IRAM_BASE;
+ struct nvboot_config_table *bit_bct =
+ (struct nvboot_config_table *)bit->bct_ptr;
+
+ /* Make sure BIT and BCT are valid */
+ if ((bit->boot_type != 1 && bit->boot_type != 2) ||
+ bit->primary_device != 5) {
+ log_err("BIT is not valid - boot type: %d primary device: %d\n",
+ bit->boot_type, bit->primary_device);
+ return -EINVAL;
+ }
+
+ /* Couldn't get a valid one, use the one in IRAM */
+ if (!bit->bct_valid || bit->bct_size != BCT_LENGTH || !bit_bct) {
+ log_err("BIT BCT data error - valid: %d size: 0x%x ptr: 0x%p\n",
+ bit->bct_valid, bit->bct_size, bit_bct);
+ return -EINVAL;
+ }
+
+ if (is_bct_valid(bit_bct)) {
+ if (!ctx->bct)
+ ctx->bct = (struct nvboot_config_table *)malloc(BCT_LENGTH);
+ memcpy(ctx->bct, bit_bct, BCT_LENGTH);
+ }
+
+ return 0;
+}
+
+/**
+ * Applies some basic BCT adjusts loads some data from it
+ */
+static int adjust_bct(struct tegra_boot_update_context *ctx,
+ u32 *ebt_offset, u32 *ebt_size)
+{
+ struct nv_bootloader_info *info = &ctx->bct->bootloader[0];
+ int ret;
+
+ /* Get block and page size if any */
+ ctx->block_size = (1 << ctx->bct->block_size_log2);
+ ctx->page_size = (1 << ctx->bct->page_size_log2);
+
+ log_debug("BCT block: 0x%x page: 0x%x\n",
+ ctx->block_size, ctx->page_size);
+
+ if (!ctx->bct->num_sdram_sets) {
+ pr_err("BCT has no SDRAM timing, aborting\n");
+ return -ENODATA;
+ }
+
+ /* If BCT has no bootloaders defined, make a entry */
+ if (!ctx->bct->bootloader_used) {
+ log_debug("BCT has 0 bootloaders used, creating entry\n");
+
+ ctx->bct->bootloader_used = 1;
+ memset(info, 0, sizeof(struct nv_bootloader_info));
+
+ info->version = 1;
+
+ /*
+ * MMC is handled later automatically to accommodate
+ * boot1 and partition
+ */
+
+ /* Devices with SPI boot device have 1MB set by vendors*/
+ if (ctx->dev == TEGRA_BOOT_DEVICE_SPI)
+ info->start_blk = DIV_ROUND_UP(1024 * 1024,
+ ctx->block_size);
+ }
+
+ info->length = *ebt_size;
+
+ /*
+ * Copy the first/two entry into last as last resort backup
+ * in case BCT is written but not EBT, the old BL hash should
+ * still be valid
+ */
+
+ if (ctx->bct->bootloader_used <= 2) {
+ ctx->bct->bootloader_used = 2;
+ memcpy(&ctx->bct->bootloader[1], ctx->bct->bootloader,
+ sizeof(struct nv_bootloader_info));
+ } else {
+ ctx->bct->bootloader_used = 4;
+ memcpy(&ctx->bct->bootloader[2], ctx->bct->bootloader,
+ sizeof(struct nv_bootloader_info) * 2);
+ }
+
+ if (ctx->dev == TEGRA_BOOT_DEVICE_MMC) {
+ struct disk_partition part;
+
+ /*
+ * Search partition in user hwpartition if exists to use
+ * it as target instead
+ */
+ ret = blk_dselect_hwpart(mmc_get_blk_desc(ctx->mmc), 0);
+ if (ret) {
+ log_err("Failed to select MMC hwpart 0 (%d)\n", ret);
+ return ret;
+ }
+
+ ret = part_get_info_by_name(mmc_get_blk_desc(ctx->mmc),
+ "ebt", &part);
+ if (ret < 0 || (part.size * part.blksz) <= 0)
+ ret = part_get_info_by_name(mmc_get_blk_desc(ctx->mmc),
+ "bootloader", &part);
+
+ if (ret >= 0) {
+ log_debug("Bootloader partition found! num: %d\n", ret);
+
+ if ((part.size * part.blksz) < info->length) {
+ strlcpy(ctx->error, "EBT partition is too small",
+ sizeof(ctx->error));
+ return ret;
+ }
+
+ info->start_blk = DIV_ROUND_UP((ctx->mmc->capacity_boot * 2 +
+ part.start * part.blksz),
+ ctx->block_size);
+ if (info->length == 0)
+ info->length = (part.size * part.blksz);
+ } else if (info->length <= ctx->mmc->capacity_boot) {
+ /* On boot1 start */
+ info->start_blk = DIV_ROUND_UP(ctx->mmc->capacity_boot,
+ ctx->block_size);
+ } else {
+ strlcpy(ctx->error, "Doesn't fit on boot1 and no EBT partition found",
+ sizeof(ctx->error));
+ return -EREMOTEIO;
+ }
+ }
+
+ if (info->length == 0)
+ info->length = EBT_MAX_LENGTH;
+
+ if (info->start_blk == 0) {
+ strlcpy(ctx->error, "No suitable location found for bootloader!",
+ sizeof(ctx->error));
+ return -ENODEV;
+ }
+
+ /* Provide calculations for EBT */
+ *ebt_offset = info->start_blk * ctx->block_size +
+ info->start_page * ctx->page_size;
+
+ log_debug("EBT offset: 0x%x length: %d\n", *ebt_offset, info->length);
+
+ *ebt_size = info->length;
+
+ /* Last check to see if actually fits into the boot device */
+ if (ctx->dev == TEGRA_BOOT_DEVICE_MMC) {
+ u32 tmp = *ebt_offset;
+
+ ret = get_mmc_hwpart_from_offset(ctx->mmc, &tmp, *ebt_size);
+ if (ret < 0)
+ return ret;
+ } else if (ctx->dev == TEGRA_BOOT_DEVICE_SPI) {
+ if (*ebt_offset + *ebt_size > ctx->spi_flash->size) {
+ log_err("Bootloader doesn't fit in SF\n");
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static int tegra_boot_backup_to_file(struct tegra_boot_update_context *ctx,
+ const char *ifname, const char *dev_part,
+ const char *backup_file,
+ u32 data_offset, u32 data_size)
+{
+ int ret;
+ loff_t len;
+
+ ret = fs_set_blk_dev(ifname, dev_part, FS_TYPE_ANY);
+ if (ret) {
+ snprintf(ctx->error, sizeof(ctx->error),
+ "Error opening %s %s for storing backup\n",
+ ifname, dev_part);
+ return ret;
+ }
+
+ if (fs_exists(backup_file))
+ return 0;
+
+ ret = read_boot_data(ctx, data_offset, data_size);
+ if (ret) {
+ snprintf(ctx->error, sizeof(ctx->error),
+ "Read boot dev err %d for %s\n", ret, backup_file);
+ return ret;
+ }
+
+ /* Again as fs_close was called on fs_exists */
+ ret = fs_set_blk_dev(ifname, dev_part, FS_TYPE_ANY);
+ if (ret) {
+ snprintf(ctx->error, sizeof(ctx->error),
+ "Error opening %s %s for storing backup\n",
+ ifname, dev_part);
+ return ret;
+ }
+
+ ret = fs_write(backup_file, CONFIG_SYS_LOAD_ADDR, 0, data_size, &len);
+ if (ret < 0) {
+ snprintf(ctx->error, sizeof(ctx->error),
+ "fs write error %d for %s\n", ret, backup_file);
+ return ret;
+ }
+
+ /* One more time as fs_close was called on fs_write */
+ ret = fs_set_blk_dev(ifname, dev_part, FS_TYPE_ANY);
+ if (ret) {
+ snprintf(ctx->error, sizeof(ctx->error),
+ "Error opening %s %s for storing backup\n",
+ ifname, dev_part);
+ return ret;
+ }
+
+ if (!fs_exists(backup_file)) {
+ snprintf(ctx->error, sizeof(ctx->error),
+ "%s was not created, unsafe to proceed\n", backup_file);
+ return -ENOENT;
+ }
- ret = encrypt_data_block(ebt, ebt, ebt_size);
+ return 0;
+}
+
+static int tegra_boot_backup(struct tegra_boot_update_context *ctx)
+{
+ int ret;
+ const char *ifname;
+ const char *dev_part;
+ struct mmc *bak_mmc = NULL;
+
+ bak_mmc = find_mmc_device(1);
+ if (bak_mmc) {
+ /* Check sdcard slot */
+ ret = mmc_init(bak_mmc);
+ if (ret) {
+ snprintf(ctx->error, sizeof(ctx->error),
+ "sdcard init error: %d\n", ret);
+ return ret;
+ }
+
+ if (!IS_SD(bak_mmc)) {
+ snprintf(ctx->error, sizeof(ctx->error),
+ "mmc1 is not sdcard: %d\n", ret);
+ return ret;
+ }
+
+ ifname = "mmc";
+ dev_part = "1:1";
+ } else if (ctx->dev == TEGRA_BOOT_DEVICE_SPI) {
+ /* Not supposed to happen as all SPI devices we know have sdcard */
+ snprintf(ctx->error, sizeof(ctx->error),
+ "spi device but no sdcard slot\n");
+ return -ENODEV;
+ } else {
+ /* No sdcard present */
+ log_debug("No sdcard present");
+ return 0;
+ }
+
+ if (ctx->dev == TEGRA_BOOT_DEVICE_MMC) {
+ ret = tegra_boot_backup_to_file(ctx, ifname, dev_part,
+ "mmc-boot0.bak", 0,
+ ctx->mmc->capacity_boot);
if (ret)
- return 1;
+ goto err;
+
+ ret = tegra_boot_backup_to_file(ctx, ifname, dev_part,
+ "mmc-boot1.bak",
+ ctx->mmc->capacity_boot,
+ ctx->mmc->capacity_boot);
+ if (ret)
+ goto err;
+
+ ret = tegra_boot_backup_to_file(ctx, ifname, dev_part,
+ "mmc-boot-user.bak",
+ ctx->mmc->capacity_boot * 2,
+ 1024 * 1024 * 32);
+ if (ret)
+ goto err;
+ } else if (ctx->dev == TEGRA_BOOT_DEVICE_SPI) {
+ ret = tegra_boot_backup_to_file(ctx, ifname, dev_part,
+ "spi-boot.bak", 0,
+ ctx->spi_flash->size);
+ if (ret)
+ goto err;
+ } else {
+ log_err("Error: boot device not set\n");
+ return -ENODEV;
+ }
+
+err:
+ fs_close();
+
+ return ret;
+}
+
+/**
+ * Setups the tegra boot update context struct and opens any required device
+ */
+static int tegra_boot_setup_context(struct tegra_boot_update_context *ctx)
+{
+ int ret;
+
+ memset(ctx, 0, sizeof(struct tegra_boot_update_context));
+
+ ctx->dev = get_boot_device();
+
+ if (ctx->dev == TEGRA_BOOT_DEVICE_MMC) {
+ /* Find emmc device (we assume to be mmc0) */
+ ctx->mmc = find_mmc_device(0);
+ if (!ctx->mmc) {
+ log_err("Error getting mmc to write\n");
+ return -EREMOTEIO;
+ }
+
+ ret = mmc_init(ctx->mmc);
+ if (ret) {
+ log_err("mmc init failed with error: %d\n", ret);
+ return ret;
+ }
+ } else if (ctx->dev == TEGRA_BOOT_DEVICE_SPI) {
+ struct udevice *new;
+
+ /* Probe spi flash */
+ ret = spi_flash_probe_bus_cs(0, 1, &new);
+ if (ret) {
+ log_err("Error probing SF\n");
+ return ret;
+ }
+
+ ctx->spi_flash = dev_get_uclass_priv(new);
+ } else {
+ log_err("Error: boot device not set\n");
+ return -ENODEV;
+ }
+
+ return tegra_boot_backup(ctx);
+}
+
+int tegra_boot_flash_bct(struct tegra_boot_update_context *ctx,
+ struct nvboot_config_table *bct_buffer,
+ u32 bct_size)
+{
+ u32 ebt_offset, ebt_size;
+ int ret;
+
+ ret = tegra_boot_setup_context(ctx);
+ if (ret)
+ goto err;
+
+ /* Use BCT that was sent over fastboot */
+ if (bct_size != BCT_LENGTH) {
+ strlcpy(ctx->error, "BCT size too big or small", sizeof(ctx->error));
+ ret = -1;
+ goto err;
+ }
+
+ if (!is_bct_valid(bct_buffer)) {
+ strlcpy(ctx->error, "BCT is not valid", sizeof(ctx->error));
+ ret = -1;
+ goto err;
+ }
+
+ /* Check if BCT has bootloaders defined, take from boot device if valid */
+ if (bct_buffer->bootloader_used == 0) {
+ read_boot_device_bct(ctx);
+ if (ctx->bct && 0 < ctx->bct->bootloader_used) {
+ log_debug("Provided BCT doesn't have any bootloader entry\n");
+ log_debug("Using boot device's bootloaders\n");
+
+ bct_buffer->bootloader_used = ctx->bct->bootloader_used;
+ memcpy(bct_buffer->bootloader, ctx->bct->bootloader,
+ sizeof(struct nv_bootloader_info) *
+ NVBOOT_MAX_BOOTLOADERS);
+ }
+ }
+
+ if (!ctx->bct)
+ ctx->bct = (struct nvboot_config_table *)malloc(BCT_LENGTH);
+
+ memcpy(ctx->bct, (u8 *)bct_buffer, BCT_LENGTH);
+
+ if (ctx->bct->bootloader_used == 0) {
+ log_debug("BCT doesn't have any bootloader entry\n");
+ ebt_size = 0;
+ } else {
+ ebt_size = ctx->bct->bootloader[0].length;
+ }
+
+ ret = adjust_bct(ctx, &ebt_offset, &ebt_size);
+ if (ret)
+ goto err;
+
+ log_debug("Loading EBT\n");
+ ret = read_boot_data(ctx, ebt_offset, ebt_size);
+ if (ret)
+ goto err;
+
+ log_debug("Rehashing BCT\n");
+ ret = bct_patch((u8 *)ctx->bct, (u8 *)CONFIG_SYS_LOAD_ADDR, ebt_size);
+ if (ret)
+ goto err;
+
+ log_debug("Flashing BCT\n");
+ ret = write_boot_data(ctx, (u8 *)ctx->bct, 0, BCT_LENGTH);
+
+err:
+ if (ctx->bct)
+ free(ctx->bct);
+
+ if (ret) {
+ if (*ctx->error == 0)
+ strlcpy(ctx->error, "Error writing BCT",
+ sizeof(ctx->error));
+ } else {
+ puts("Flashing BCT successful!\n");
+ }
+
+ return ret ? -1 : 0;
+}
+
+int tegra_boot_flash_bootloader(struct tegra_boot_update_context *ctx,
+ u8 *ebt_buffer, u32 ebt_size)
+{
+ int ret;
+ u32 ebt_offset;
+ u32 ebt_padding;
+ bool encrypted;
+
+ ret = tegra_boot_setup_context(ctx);
+ if (ret)
+ goto err;
+
+ log_debug("Retrieving BCT\n");
+
+ ret = read_boot_device_bct(ctx);
+ if (ret)
+ goto err;
+
+ if (!ctx->bct) {
+ pr_err("No valid BCT was found in boot device\n");
+
+ ret = read_iram_bct(ctx);
+ if (ret || !ctx->bct) {
+ pr_err("No valid BCT was found in IRAM, aborting\n");
+ ret = -ENODATA;
+ goto err;
+ }
}
- return bct_patch(bct, ebt, ebt_size);
+ /* We need to align it and add a extra padding block or it will get stuck */
+ ebt_padding = (roundup(ebt_size, AES_BLOCK_LENGTH) + AES_BLOCK_LENGTH) - ebt_size;
+ memset(ebt_buffer + ebt_size, 0, ebt_padding);
+ ebt_size += ebt_padding;
+
+ ret = adjust_bct(ctx, &ebt_offset, &ebt_size);
+ if (ret)
+ goto err;
+
+ encrypted = tegra_fuse_get_operation_mode() == MODE_ODM_PRODUCTION_SECURE;
+ if (encrypted) {
+ log_debug("Encrypting bootloader\n");
+ ret = encrypt_data_block(ebt_buffer, ebt_buffer, ebt_size);
+ if (ret)
+ return ret;
+ }
+
+ log_debug("Rehashing BCT and encrypting bootloader\n");
+ ret = bct_patch((u8 *)ctx->bct, ebt_buffer, ebt_size);
+ if (ret)
+ goto err;
+
+ log_debug("Flashing BCT\n");
+ ret = write_boot_data(ctx, (u8 *)ctx->bct, 0, BCT_LENGTH);
+ if (ret)
+ goto err;
+
+ log_debug("Flashing EBT\n");
+ ret = write_boot_data(ctx, ebt_buffer, ebt_offset, ebt_size);
+
+err:
+ if (ctx->bct)
+ free(ctx->bct);
+
+ if (ret) {
+ if (*ctx->error == 0)
+ strlcpy(ctx->error, "Error writing bootloader",
+ sizeof(ctx->error));
+ } else {
+ puts("Flashing bootloader successful!\n");
+ }
+
+ return ret ? -1 : 0;
+}
+
+#ifdef CONFIG_CMD_EBTUPDATE
+static int do_ebtupdate(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct tegra_boot_update_context ctx;
+ u8 *ebt = (u8 *)hextoul(argv[1], NULL);
+ u32 ebt_size = hextoul(argv[2], NULL);
+ int ret;
+
+ ret = tegra_boot_flash_bootloader(&ctx, ebt, ebt_size);
+ if (strlen(ctx.error))
+ log_err("Error: %s\n", ctx.error);
+
+ return ret;
+}
+
+U_BOOT_CMD(ebtupdate, 3, 0, do_ebtupdate,
+ "updates the bootloader on Tegra devices from a copy in RAM",
+ "ebtupdate <addr> <size>\n"
+ ""
+);
+
+static int do_bctupdate(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ int ret;
+ struct tegra_boot_update_context ctx;
+ u8 *bct = (u8 *)hextoul(argv[1], NULL);
+ u32 bct_size = hextoul(argv[2], NULL);
+
+ ret = tegra_boot_flash_bct(&ctx, (struct nvboot_config_table *)bct,
+ bct_size);
+ if (strlen(ctx.error))
+ log_err("Error: %s\n", ctx.error);
+
+ return ret;
}
-U_BOOT_CMD(ebtupdate, 4, 0, do_ebtupdate,
- "update bootloader on re-crypted Tegra devices",
+U_BOOT_CMD(bctupdate, 3, 0, do_bctupdate,
+ "updates the BCT on Tegra devices from a copy in RAM",
+ "bctupdate <addr> <size>\n"
""
);
#endif
diff --git a/arch/arm/mach-tegra/bct.h b/arch/arm/mach-tegra/bct.h
index 76756cba8ed..73917842543 100644
--- a/arch/arm/mach-tegra/bct.h
+++ b/arch/arm/mach-tegra/bct.h
@@ -3,7 +3,26 @@
#ifndef _BCT_H_
#define _BCT_H_
-#define EBT_ALIGNMENT 0x10
+#define EBT_MAX_LENGTH (1024 * 1024 * 2) /* 2 MB */
+
+enum tegra_boot_device {
+ TEGRA_BOOT_DEVICE_UNKNOWN = 0,
+ TEGRA_BOOT_DEVICE_MMC,
+ TEGRA_BOOT_DEVICE_SPI,
+};
+
+struct tegra_boot_update_context {
+ enum tegra_boot_device dev;
+ struct nvboot_config_table *bct;
+ char error[60];
+ u32 block_size;
+ u32 page_size;
+ u8 *ebt_ptr;
+ u32 ebt_size;
+
+ struct mmc *mmc;
+ struct spi_flash *spi_flash;
+};
/*
* Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words)
@@ -15,6 +34,16 @@
*/
#define NVBOOT_SE_RSA_MODULUS_LENGTH 64
+/*
+ * Defines the maximum number of device parameters in the BCT.
+ */
+#define NVBOOT_MAX_PARAM_SETS 4
+
+/*
+ * Defines the maximum number of sdram timing descriptions in the BCT.
+ */
+#define NVBOOT_MAX_SDRAM_SETS 4
+
/*
* Defines the maximum number of bootloader descriptions in the BCT.
*/
@@ -30,15 +59,28 @@
#define BCT_LENGTH (UBCT_LENGTH + SBCT_LENGTH)
-/*
- * Updates the hash of bootloader entry and the BCT itself
- * It will encrypt BCT in place if the device requires it
+/**
+ * tegra_boot_flash_bct - Flashes the provided BCT into the boot device
+ * @ctx: Pointer to the Tegra boot update context structure
+ * @bct_buffer Pointer to the BCT structure
+ * @bct_size BCT size in bytes
+ *
+ * Return: 0, or -1 if failed
+ */
+int tegra_boot_flash_bct(struct tegra_boot_update_context *ctx,
+ struct nvboot_config_table *bct_buffer,
+ u32 bct_size);
+
+/**
+ * tegra_boot_flash_bootloader - Flashes the provided bootloader into
+ * the boot device
+ * @ctx: Pointer to the Tegra boot update context structure
+ * @ebt_buffer Pointer to the buffer containing bootloader
+ * @ebt_size Bootloader size in bytes
*
- * @param bct boot config table start in RAM
- * @param ebt bootloader start in RAM
- * @param ebt_size bootloader file size in bytes
- * Return: 0, or 1 if failed
+ * Return: 0, or -1 if failed
*/
-int bct_patch(u8 *bct, u8 *ebt, u32 ebt_size);
+int tegra_boot_flash_bootloader(struct tegra_boot_update_context *ctx,
+ u8 *ebt_buffer, u32 ebt_size);
#endif /* _BCT_H_ */
diff --git a/arch/arm/mach-tegra/fastboot.c b/arch/arm/mach-tegra/fastboot.c
new file mode 100644
index 00000000000..d8a6c8cd639
--- /dev/null
+++ b/arch/arm/mach-tegra/fastboot.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2026, Ion Agorria <ion@agorria.com>
+ * Copyright (c) 2026, Svyatoslav Ryhel <clamor95@gmail.com>
+ */
+
+#include <dm.h>
+#include <blk.h>
+#include <command.h>
+#include <fastboot.h>
+#include <fs.h>
+#include <log.h>
+#include <mmc.h>
+#include <spi.h>
+#include <spi_flash.h>
+#include <stdlib.h>
+#include <string.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/printk.h>
+
+#include <asm/arch-tegra/crypto.h>
+#include <asm/arch-tegra/fuse.h>
+#include <asm/arch-tegra/pmc.h>
+
+#include "bct.h"
+
+int board_fastboot_flash(char *cmd_parameter, void *download_buffer,
+ u32 download_bytes, char *response)
+{
+ struct tegra_boot_update_context ctx;
+ bool is_bct = !strcmp(cmd_parameter, "bct");
+ bool is_bootloader = !strcmp(cmd_parameter, "ebt") ||
+ !strcmp(cmd_parameter, "bootloader");
+ int ret = 0;
+
+ /* Continue normal fastboot flash for other partitions */
+ if (!is_bct && !is_bootloader)
+ return -ENOTSUPP;
+
+ if (is_bct)
+ ret = tegra_boot_flash_bct(&ctx, (struct nvboot_config_table *)download_buffer,
+ download_bytes);
+ else
+ ret = tegra_boot_flash_bootloader(&ctx, download_buffer,
+ download_bytes);
+
+ if (ret) {
+ if (strlen(ctx.error))
+ fastboot_fail(ctx.error, response);
+ else
+ fastboot_fail("unknown error flashing", response);
+
+ return -EINVAL;
+ }
+
+ fastboot_okay(NULL, response);
+
+ return 0;
+}
+
+int board_fastboot_get_part_info(const char *part_name, char *response,
+ size_t *size)
+{
+ if (!strcmp(part_name, "bct")) {
+ if (size)
+ *size = BCT_LENGTH;
+ return 0;
+ } else if (!strcmp(part_name, "ebt") ||
+ !strcmp(part_name, "bootloader")) {
+ if (size)
+ *size = EBT_MAX_LENGTH;
+ return 0;
+ }
+
+ /* Continue normal fastboot get_part_info() */
+ return -ENOTSUPP;
+}
diff --git a/arch/arm/mach-tegra/tegra124/bct.h b/arch/arm/mach-tegra/tegra124/bct.h
index f7d65621c0a..28fcac19e39 100644
--- a/arch/arm/mach-tegra/tegra124/bct.h
+++ b/arch/arm/mach-tegra/tegra124/bct.h
@@ -24,14 +24,46 @@ struct nv_bootloader_info {
};
struct nvboot_config_table {
- u32 ubct_unused1[196];
+ u32 badblock_table[130];
+ u8 badblock_padding[6];
+ u32 rsa_key_modulus[64];
u32 crypto_hash[NVBOOT_CMAC_AES_HASH_LENGTH];
- u32 ubct_unused2[228];
+ u32 rsa_signature[64];
+ u8 customer_data[648];
+ u32 odm_data;
+ u32 reserved1;
- u32 sbct_unused1[1318];
+ /* Signed section of BCT */
+ u32 random_aes_blk[4];
+ u32 unique_chip_id[4];
+ u32 boot_data_version;
+ u32 block_size_log2;
+ u32 page_size_log2;
+ u32 partition_size;
+ u32 num_param_sets;
+ u32 dev_type[NVBOOT_MAX_PARAM_SETS];
+ u32 dev_params[NVBOOT_MAX_PARAM_SETS * 16];
+ u32 num_sdram_sets;
+ u32 sdram[NVBOOT_MAX_SDRAM_SETS * 309];
u32 bootloader_used;
struct nv_bootloader_info bootloader[NVBOOT_MAX_BOOTLOADERS];
- u32 sbct_unused2;
+ u8 enable_fail_back;
+ u8 secure_jtag_control;
+ u8 reserved[2];
+};
+
+struct tegra_boot_info_table {
+ u8 unused1[12];
+ u32 boot_type;
+ u32 primary_device;
+ u32 secondary_device;
+ u8 unused2[26];
+ u8 bct_valid;
+ u8 unused3[13];
+ u32 bct_block;
+ u32 bct_page;
+ u32 bct_size;
+ u32 bct_ptr;
};
#endif /* _TEGRA124_BCT_H_ */
diff --git a/arch/arm/mach-tegra/tegra20/bct.h b/arch/arm/mach-tegra/tegra20/bct.h
index a9feba42bf6..34a8650ebb3 100644
--- a/arch/arm/mach-tegra/tegra20/bct.h
+++ b/arch/arm/mach-tegra/tegra20/bct.h
@@ -22,11 +22,38 @@ struct nv_bootloader_info {
struct nvboot_config_table {
u32 crypto_hash[NVBOOT_CMAC_AES_HASH_LENGTH];
- u32 unused0[4];
+ u32 random_aes_blk[4];
u32 boot_data_version;
- u32 unused1[668];
+ u32 block_size_log2;
+ u32 page_size_log2;
+ u32 partition_size;
+ u32 num_param_sets;
+ u32 dev_type[NVBOOT_MAX_PARAM_SETS];
+ u32 dev_params[NVBOOT_MAX_PARAM_SETS * 4];
+ u32 num_sdram_sets;
+ u32 sdram[NVBOOT_MAX_SDRAM_SETS * 128];
+ u32 badblock_table[130];
+ u32 bootloader_used;
struct nv_bootloader_info bootloader[NVBOOT_MAX_BOOTLOADERS];
- u32 unused2[508];
+ u8 customer_data[1184];
+ u32 odm_data;
+ u32 reserved1;
+ u8 enable_fail_back;
+ u8 reserved[3];
+};
+
+struct tegra_boot_info_table {
+ u8 unused1[12];
+ u32 boot_type;
+ u32 primary_device;
+ u32 secondary_device;
+ u8 unused2[9];
+ u8 bct_valid;
+ u8 unused3[13];
+ u32 bct_block;
+ u32 bct_page;
+ u32 bct_size;
+ u32 bct_ptr;
};
#endif /* _TEGRA20_BCT_H_ */
diff --git a/arch/arm/mach-tegra/tegra30/bct.h b/arch/arm/mach-tegra/tegra30/bct.h
index 8420615ce62..2198c77d3ac 100644
--- a/arch/arm/mach-tegra/tegra30/bct.h
+++ b/arch/arm/mach-tegra/tegra30/bct.h
@@ -22,11 +22,38 @@ struct nv_bootloader_info {
struct nvboot_config_table {
u32 crypto_hash[NVBOOT_CMAC_AES_HASH_LENGTH];
- u32 unused0[4];
+ u32 random_aes_blk[4];
u32 boot_data_version;
- u32 unused1[972];
+ u32 block_size_log2;
+ u32 page_size_log2;
+ u32 partition_size;
+ u32 num_param_sets;
+ u32 dev_type[NVBOOT_MAX_PARAM_SETS];
+ u32 dev_params[NVBOOT_MAX_PARAM_SETS * 16];
+ u32 num_sdram_sets;
+ u32 sdram[NVBOOT_MAX_SDRAM_SETS * 192];
+ u32 badblock_table[130];
+ u32 bootloader_used;
struct nv_bootloader_info bootloader[NVBOOT_MAX_BOOTLOADERS];
- u32 unused2[508];
+ u8 customer_data[2016];
+ u32 odm_data;
+ u32 reserved1;
+ u8 enable_fail_back;
+ u8 reserved[3];
+};
+
+struct tegra_boot_info_table {
+ u8 unused1[12];
+ u32 boot_type;
+ u32 primary_device;
+ u32 secondary_device;
+ u8 unused2[9];
+ u8 bct_valid;
+ u8 unused3[13];
+ u32 bct_block;
+ u32 bct_page;
+ u32 bct_size;
+ u32 bct_ptr;
};
#endif /* _TEGRA30_BCT_H_ */
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 4/9] configs: tegra: Enable TEGRA_FASTBOOT_FLASH option
2026-12-05 10:05 [PATCH v2 0/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
` (2 preceding siblings ...)
2026-12-05 10:05 ` [PATCH v2 3/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
@ 2026-12-05 10:05 ` Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 5/9] crypto: tegra_aes: Add support for Tegra124 Svyatoslav Ryhel
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-12-05 10:05 UTC (permalink / raw)
To: Svyatoslav Ryhel, Thierry Reding, Tom Rini, Ilias Apalodimas,
Jonas Schwöbel, Ion Agorria, Peter Geis, Mattijs Korpershoek,
Guillaume La Roque
Cc: u-boot
From: Ion Agorria <ion@agorria.com>
Add the fastboot flash bootloader support for devices that already had
CMD_EBTUPDATE feature enabled.
Signed-off-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
configs/endeavoru_defconfig | 1 +
configs/grouper_defconfig | 1 +
configs/ideapad-yoga-11_defconfig | 1 +
configs/mocha_defconfig | 1 +
configs/mot_defconfig | 1 +
configs/n1_defconfig | 1 +
configs/ouya_defconfig | 1 +
configs/picasso_defconfig | 1 +
configs/qc750_defconfig | 1 +
configs/star_defconfig | 1 +
configs/transformer_t20_defconfig | 1 +
configs/transformer_t30_defconfig | 1 +
configs/x3_t30_defconfig | 1 +
13 files changed, 13 insertions(+)
diff --git a/configs/endeavoru_defconfig b/configs/endeavoru_defconfig
index 54bf8367dc8..3d91ba7c7e4 100644
--- a/configs/endeavoru_defconfig
+++ b/configs/endeavoru_defconfig
@@ -14,6 +14,7 @@ CONFIG_SPL_HAVE_INIT_STACK=y
CONFIG_TEGRA30=y
CONFIG_TARGET_ENDEAVORU=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/grouper_defconfig b/configs/grouper_defconfig
index c26adb1190a..c329ced0d2e 100644
--- a/configs/grouper_defconfig
+++ b/configs/grouper_defconfig
@@ -14,6 +14,7 @@ CONFIG_SPL_HAVE_INIT_STACK=y
CONFIG_TEGRA30=y
CONFIG_TARGET_GROUPER=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/ideapad-yoga-11_defconfig b/configs/ideapad-yoga-11_defconfig
index 75f5fe24c41..7160029a646 100644
--- a/configs/ideapad-yoga-11_defconfig
+++ b/configs/ideapad-yoga-11_defconfig
@@ -14,6 +14,7 @@ CONFIG_SPL_HAVE_INIT_STACK=y
CONFIG_TEGRA30=y
CONFIG_TARGET_IDEAPAD_YOGA_11=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/mocha_defconfig b/configs/mocha_defconfig
index 1358834a66a..c5c072d8362 100644
--- a/configs/mocha_defconfig
+++ b/configs/mocha_defconfig
@@ -17,6 +17,7 @@ CONFIG_TARGET_MOCHA=y
CONFIG_TEGRA_ENABLE_UARTD=y
CONFIG_TEGRA_GPU=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/mot_defconfig b/configs/mot_defconfig
index 8e4a3469184..4c96398f161 100644
--- a/configs/mot_defconfig
+++ b/configs/mot_defconfig
@@ -15,6 +15,7 @@ CONFIG_TEGRA20=y
CONFIG_TARGET_MOT=y
CONFIG_TEGRA_ENABLE_UARTB=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/n1_defconfig b/configs/n1_defconfig
index 22a04fe700f..9aa51b3cef4 100644
--- a/configs/n1_defconfig
+++ b/configs/n1_defconfig
@@ -15,6 +15,7 @@ CONFIG_TEGRA20=y
CONFIG_TARGET_SAMSUNG_N1=y
CONFIG_TEGRA_ENABLE_UARTB=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/ouya_defconfig b/configs/ouya_defconfig
index 7bc363aa5ab..5ccecee4ea6 100644
--- a/configs/ouya_defconfig
+++ b/configs/ouya_defconfig
@@ -15,6 +15,7 @@ CONFIG_TEGRA30=y
CONFIG_TARGET_OUYA=y
CONFIG_TEGRA_ENABLE_UARTD=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=3
CONFIG_OF_BOARD_SETUP=y
diff --git a/configs/picasso_defconfig b/configs/picasso_defconfig
index 6d790b57ade..0ae401c5a84 100644
--- a/configs/picasso_defconfig
+++ b/configs/picasso_defconfig
@@ -15,6 +15,7 @@ CONFIG_TEGRA20=y
CONFIG_TARGET_PICASSO=y
CONFIG_TEGRA_ENABLE_UARTD=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/qc750_defconfig b/configs/qc750_defconfig
index cf73bfde9b6..588f6a621e3 100644
--- a/configs/qc750_defconfig
+++ b/configs/qc750_defconfig
@@ -15,6 +15,7 @@ CONFIG_TEGRA30=y
CONFIG_TARGET_QC750=y
CONFIG_TEGRA_ENABLE_UARTD=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/star_defconfig b/configs/star_defconfig
index 6d0c838eadc..04070d81728 100644
--- a/configs/star_defconfig
+++ b/configs/star_defconfig
@@ -15,6 +15,7 @@ CONFIG_TEGRA20=y
CONFIG_TARGET_STAR=y
CONFIG_TEGRA_ENABLE_UARTB=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/transformer_t20_defconfig b/configs/transformer_t20_defconfig
index bf3058440f5..e4ece34d16b 100644
--- a/configs/transformer_t20_defconfig
+++ b/configs/transformer_t20_defconfig
@@ -15,6 +15,7 @@ CONFIG_TEGRA20=y
CONFIG_TARGET_TRANSFORMER_T20=y
CONFIG_TEGRA_ENABLE_UARTD=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/transformer_t30_defconfig b/configs/transformer_t30_defconfig
index eb3e1e7088a..7324a24a429 100644
--- a/configs/transformer_t30_defconfig
+++ b/configs/transformer_t30_defconfig
@@ -14,6 +14,7 @@ CONFIG_SPL_HAVE_INIT_STACK=y
CONFIG_TEGRA30=y
CONFIG_TARGET_TRANSFORMER_T30=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/x3_t30_defconfig b/configs/x3_t30_defconfig
index 0d5eaffd104..d8123e7ec07 100644
--- a/configs/x3_t30_defconfig
+++ b/configs/x3_t30_defconfig
@@ -14,6 +14,7 @@ CONFIG_TEGRA30=y
CONFIG_TARGET_X3_T30=y
CONFIG_TEGRA_ENABLE_UARTD=y
CONFIG_CMD_EBTUPDATE=y
+CONFIG_TEGRA_FASTBOOT_FLASH=y
CONFIG_BUTTON_CMD=y
CONFIG_BOOTDELAY=0
CONFIG_AUTOBOOT_KEYED=y
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 5/9] crypto: tegra_aes: Add support for Tegra124
2026-12-05 10:05 [PATCH v2 0/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
` (3 preceding siblings ...)
2026-12-05 10:05 ` [PATCH v2 4/9] configs: tegra: Enable TEGRA_FASTBOOT_FLASH option Svyatoslav Ryhel
@ 2026-12-05 10:05 ` Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 6/9] ARM: tegra124: Add AES engine node and enable it for Mi Pad Svyatoslav Ryhel
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-12-05 10:05 UTC (permalink / raw)
To: Svyatoslav Ryhel, Thierry Reding, Tom Rini, Ilias Apalodimas,
Jonas Schwöbel, Ion Agorria, Peter Geis, Mattijs Korpershoek,
Guillaume La Roque
Cc: u-boot
From: Ion Agorria <ion@agorria.com>
Existing Tegra AES driver is compatible with Tegra124 BSEV AES function.
Other functions differ hence compatible is SoC specific.
Signed-off-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
drivers/crypto/tegra/tegra_aes.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/crypto/tegra/tegra_aes.c b/drivers/crypto/tegra/tegra_aes.c
index 55a4cec525b..974f9d2db93 100644
--- a/drivers/crypto/tegra/tegra_aes.c
+++ b/drivers/crypto/tegra/tegra_aes.c
@@ -578,6 +578,8 @@ static const struct udevice_id tegra_aes_ids[] = {
{ .compatible = "nvidia,tegra20-bsev" },
{ .compatible = "nvidia,tegra30-bsea" },
{ .compatible = "nvidia,tegra30-bsev" },
+ { .compatible = "nvidia,tegra124-bsea" },
+ { .compatible = "nvidia,tegra124-bsev" },
{ }
};
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 6/9] ARM: tegra124: Add AES engine node and enable it for Mi Pad
2026-12-05 10:05 [PATCH v2 0/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
` (4 preceding siblings ...)
2026-12-05 10:05 ` [PATCH v2 5/9] crypto: tegra_aes: Add support for Tegra124 Svyatoslav Ryhel
@ 2026-12-05 10:05 ` Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 7/9] ARM: tegra: n1: Add bsev node Svyatoslav Ryhel
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-12-05 10:05 UTC (permalink / raw)
To: Svyatoslav Ryhel, Thierry Reding, Tom Rini, Ilias Apalodimas,
Jonas Schwöbel, Ion Agorria, Peter Geis, Mattijs Korpershoek,
Guillaume La Roque
Cc: u-boot
From: Ion Agorria <ion@agorria.com>
Add BSEV (Video Bitstream Engine) node used as AES engine for crypto
operations.
Signed-off-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
arch/arm/dts/tegra124-xiaomi-mocha.dts | 4 ++++
arch/arm/dts/tegra124.dtsi | 16 ++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/arch/arm/dts/tegra124-xiaomi-mocha.dts b/arch/arm/dts/tegra124-xiaomi-mocha.dts
index 09b5c1eea05..71220a3f513 100644
--- a/arch/arm/dts/tegra124-xiaomi-mocha.dts
+++ b/arch/arm/dts/tegra124-xiaomi-mocha.dts
@@ -27,6 +27,10 @@
reg = <0x80000000 0x80000000>;
};
+ bsev@60031000 {
+ status = "okay";
+ };
+
host1x@50000000 {
dsia: dsi@54300000 {
status = "okay";
diff --git a/arch/arm/dts/tegra124.dtsi b/arch/arm/dts/tegra124.dtsi
index 1c62d1f6e7b..ff1d1e37e09 100644
--- a/arch/arm/dts/tegra124.dtsi
+++ b/arch/arm/dts/tegra124.dtsi
@@ -294,6 +294,22 @@
*/
};
+ /* Video Bitstream Engine */
+ bsev@60031000 {
+ compatible = "nvidia,tegra124-bsev";
+ reg = <0x60031000 0x1000>, <0x40008000 0x4000>;
+ reg-names = "bsev", "iram-buffer";
+ interrupts = <GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "bsev";
+ clocks = <&tegra_car TEGRA124_CLK_BSEV>,
+ <&tegra_car TEGRA124_CLK_VDE>;
+ clock-names = "bsev", "vde";
+ resets = <&tegra_car 63>,
+ <&tegra_car 61>;
+ reset-names = "bsev", "vde";
+ status = "disabled";
+ };
+
apbdma: dma@60020000 {
compatible = "nvidia,tegra124-apbdma", "nvidia,tegra148-apbdma";
reg = <0x60020000 0x1400>;
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 7/9] ARM: tegra: n1: Add bsev node
2026-12-05 10:05 [PATCH v2 0/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
` (5 preceding siblings ...)
2026-12-05 10:05 ` [PATCH v2 6/9] ARM: tegra124: Add AES engine node and enable it for Mi Pad Svyatoslav Ryhel
@ 2026-12-05 10:05 ` Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 8/9] board: tegra: Update ebtupdate usage Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 9/9] doc: cmd: Update ebtupdate description and document bctupdate command Svyatoslav Ryhel
8 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-12-05 10:05 UTC (permalink / raw)
To: Svyatoslav Ryhel, Thierry Reding, Tom Rini, Ilias Apalodimas,
Jonas Schwöbel, Ion Agorria, Peter Geis, Mattijs Korpershoek,
Guillaume La Roque
Cc: u-boot
From: Ion Agorria <ion@agorria.com>
Now that we can handle flashing on these devices enable it for AES engine
support. This is specially important for samsung-bose as it is production
device.
Signed-off-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
arch/arm/dts/tegra20-samsung-n1-common.dtsi | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm/dts/tegra20-samsung-n1-common.dtsi b/arch/arm/dts/tegra20-samsung-n1-common.dtsi
index b82e6464248..4e97dac113e 100644
--- a/arch/arm/dts/tegra20-samsung-n1-common.dtsi
+++ b/arch/arm/dts/tegra20-samsung-n1-common.dtsi
@@ -25,6 +25,10 @@
reg = <0x00000000 0x40000000>; /* 1 GB */
};
+ bsev@6001b000 {
+ status = "okay";
+ };
+
pinmux@70000014 {
pinctrl-names = "default";
pinctrl-0 = <&state_default>;
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 8/9] board: tegra: Update ebtupdate usage
2026-12-05 10:05 [PATCH v2 0/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
` (6 preceding siblings ...)
2026-12-05 10:05 ` [PATCH v2 7/9] ARM: tegra: n1: Add bsev node Svyatoslav Ryhel
@ 2026-12-05 10:05 ` Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 9/9] doc: cmd: Update ebtupdate description and document bctupdate command Svyatoslav Ryhel
8 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-12-05 10:05 UTC (permalink / raw)
To: Svyatoslav Ryhel, Thierry Reding, Tom Rini, Ilias Apalodimas,
Jonas Schwöbel, Ion Agorria, Peter Geis, Mattijs Korpershoek,
Guillaume La Roque
Cc: u-boot
From: Ion Agorria <ion@agorria.com>
Update the flashing scripts used by the bootmenu that calls ebtupdate,
now bootloader image is enough. Add ebt in picasso and n1 oem format table
as these devices may lack enough space for bootloader in eMMC boot1.
Signed-off-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
board/acer/picasso/picasso.env | 5 +-
board/asus/transformer-t30/board-info.c | 6 --
.../asus/transformer-t30/transformer-t30.env | 2 +-
.../ideapad-yoga-11/ideapad-yoga-11.env | 2 +-
board/samsung/n1/n1.env | 4 +-
board/xiaomi/mocha/mocha.env | 4 --
include/env/nvidia/prod_upd.env | 66 +++----------------
7 files changed, 13 insertions(+), 76 deletions(-)
diff --git a/board/acer/picasso/picasso.env b/board/acer/picasso/picasso.env
index d9409b07d98..b40e0c0a198 100644
--- a/board/acer/picasso/picasso.env
+++ b/board/acer/picasso/picasso.env
@@ -2,10 +2,7 @@
button_cmd_0_name=Volume Down
button_cmd_0=bootmenu
-partitions=name=emmc,start=0,size=-,uuid=${uuid_gpt_rootfs}
-
-boot_block_size_r=0x100000
-boot_block_size=0x800
+partitions=name=ebt,start=64K,size=2M,uuid=${uuid_gpt_ebt};name=rootfs,size=-,uuid=${uuid_gpt_rootfs}
boot_dev=1
bootmenu_0=mount internal storage=usb start && ums 0 mmc 0; bootmenu
diff --git a/board/asus/transformer-t30/board-info.c b/board/asus/transformer-t30/board-info.c
index e72614164b4..4bda85a6b2d 100644
--- a/board/asus/transformer-t30/board-info.c
+++ b/board/asus/transformer-t30/board-info.c
@@ -83,12 +83,6 @@ static int get_project_id(void)
log_debug("[TRANSFORMER]: project id %d (%s)\n", proj_id,
project_id_to_fdt[proj_id]);
- /* Mark tablet with SPI flash */
- if (proj_id == TF600T)
- env_set_hex("spiflash", true);
- else
- env_set_hex("spiflash", false);
-
return proj_id & 0xf;
}
diff --git a/board/asus/transformer-t30/transformer-t30.env b/board/asus/transformer-t30/transformer-t30.env
index 9b6f4079f84..2f7e8206c24 100644
--- a/board/asus/transformer-t30/transformer-t30.env
+++ b/board/asus/transformer-t30/transformer-t30.env
@@ -1,7 +1,7 @@
#include <env/nvidia/prod_upd.env>
button_cmd_0_name=Volume Down
-button_cmd_0=if spiflash; then run update_spi; else bootmenu; fi
+button_cmd_0=bootmenu
button_cmd_1_name=Lid sensor
button_cmd_1=poweroff
partitions=name=emmc,start=0,size=-,uuid=${uuid_gpt_rootfs}
diff --git a/board/lenovo/ideapad-yoga-11/ideapad-yoga-11.env b/board/lenovo/ideapad-yoga-11/ideapad-yoga-11.env
index 7bc2b80c480..2f7c8b62f1a 100644
--- a/board/lenovo/ideapad-yoga-11/ideapad-yoga-11.env
+++ b/board/lenovo/ideapad-yoga-11/ideapad-yoga-11.env
@@ -9,7 +9,7 @@ partitions=name=emmc,start=0,size=-,uuid=${uuid_gpt_rootfs}
bootmenu_0=mount internal storage=usb start && ums 0 mmc 0; bootmenu
bootmenu_1=mount external storage=usb start && ums 0 mmc 1; bootmenu
bootmenu_2=fastboot=echo Starting Fastboot protocol ...; fastboot usb 0; bootmenu
-bootmenu_3=update bootloader=run update_spi
+bootmenu_3=update bootloader=run flash_uboot
bootmenu_4=reboot RCM=enterrcm
bootmenu_5=reboot=reset
bootmenu_6=power off=poweroff
diff --git a/board/samsung/n1/n1.env b/board/samsung/n1/n1.env
index e2b883dbc10..9b20ea6e40a 100644
--- a/board/samsung/n1/n1.env
+++ b/board/samsung/n1/n1.env
@@ -2,9 +2,7 @@
button_cmd_0_name=Volume Down
button_cmd_0=bootmenu
-
-boot_block_size_r=0x80000
-boot_block_size=0x400
+partitions=name=ebt,start=64K,size=2M,uuid=${uuid_gpt_ebt};name=rootfs,size=-,uuid=${uuid_gpt_rootfs}
boot_dev=1
bootmenu_0=mount internal storage=usb start && ums 0 mmc 0; bootmenu
diff --git a/board/xiaomi/mocha/mocha.env b/board/xiaomi/mocha/mocha.env
index d93e24316f6..cca6424fc80 100644
--- a/board/xiaomi/mocha/mocha.env
+++ b/board/xiaomi/mocha/mocha.env
@@ -6,11 +6,7 @@ button_cmd_1_name=Hall sensor (back)
button_cmd_1=poweroff
button_cmd_1_name=Hall sensor (front)
button_cmd_1=poweroff
-
partitions=name=emmc,start=0,size=-,uuid=${uuid_gpt_rootfs}
-
-boot_block_size_r=0x400000
-boot_block_size=0x2000
boot_dev=1
bootmenu_0=mount internal storage=usb start && ums 0 mmc 0; bootmenu
diff --git a/include/env/nvidia/prod_upd.env b/include/env/nvidia/prod_upd.env
index 6a457d1b75b..2c5db0c138c 100644
--- a/include/env/nvidia/prod_upd.env
+++ b/include/env/nvidia/prod_upd.env
@@ -1,61 +1,13 @@
-boot_block_size_r=0x200000
-boot_block_size=0x1000
bootloader_file=u-boot-dtb-tegra.bin
-spi_size=0x400000
boot_dev=0
boot_interface=mmc
-flash_uboot=echo Preparing RAM;
- mw ${kernel_addr_r} 0 ${boot_block_size_r};
- mw ${ramdisk_addr_r} 0 ${boot_block_size_r};
- echo Reading BCT;
- mmc dev 0 1;
- mmc read ${kernel_addr_r} 0 ${boot_block_size};
- echo Reading bootloader;
- if load ${boot_interface} ${boot_dev}:1 ${ramdisk_addr_r} ${bootloader_file};
- then echo Calculating bootloader size;
- size ${boot_interface} ${boot_dev}:1 ${bootloader_file};
- ebtupdate ${kernel_addr_r} ${ramdisk_addr_r} ${filesize};
- echo Writing bootloader to eMMC;
- mmc dev 0 1;
- mmc write ${kernel_addr_r} 0 ${boot_block_size};
- mmc dev 0 2;
- mmc write ${ramdisk_addr_r} 0 ${boot_block_size};
- echo Bootloader written successfully;
- pause 'Press ANY key to reboot device...'; reset;
- else echo Reading bootloader failed;
- pause 'Press ANY key to return to bootmenu...'; bootmenu; fi
-
-update_spi=sf probe 0:1;
- echo Dumping current SPI flash content ...;
- sf read ${kernel_addr_r} 0x0 ${spi_size};
- if fatwrite mmc 1:1 ${kernel_addr_r} spi-flash-backup.bin ${spi_size};
- then echo SPI flash content was successfully written into spi-flash-backup.bin;
- echo Reading SPI flash binary;
- if load mmc 1:1 ${kernel_addr_r} repart-block.bin;
- then echo Writing bootloader into SPI flash;
- sf probe 0:1;
- sf update ${kernel_addr_r} 0x0 ${spi_size};
- echo Bootloader SUCCESSFULLY written into SPI flash;
- pause 'Press ANY key to reboot...'; reset;
- else echo Preparing RAM;
- mw ${kernel_addr_r} 0 ${boot_block_size_r};
- mw ${ramdisk_addr_r} 0 ${boot_block_size_r};
- echo Reading BCT;
- sf read ${kernel_addr_r} 0x0 ${boot_block_size_r};
- echo Reading bootloader;
- if load mmc 1:1 ${ramdisk_addr_r} ${bootloader_file};
- then echo Calculating bootloader size;
- size mmc 1:1 ${bootloader_file};
- ebtupdate ${kernel_addr_r} ${ramdisk_addr_r} ${filesize};
- echo Writing bootloader into SPI flash;
- sf probe 0:1;
- sf update ${kernel_addr_r} 0x0 ${boot_block_size_r};
- sf update ${ramdisk_addr_r} ${boot_block_size_r} ${boot_block_size_r};
- echo Bootloader written SUCCESSFULLY;
- pause 'Press ANY key to reboot...'; reset;
- else echo Reading bootloader failed;
- pause 'Press ANY key to reboot...'; reset; fi;
- fi;
- else echo SPI flash backup FAILED! Aborting ...;
- pause 'Press ANY key to reboot...'; reset; fi
+flash_uboot=echo Reading bootloader;
+ if load ${boot_interface} ${boot_dev}:1 ${ramdisk_addr_r} ${bootloader_file};
+ then echo Calculating bootloader size;
+ size ${boot_interface} ${boot_dev}:1 ${bootloader_file};
+ echo Writing bootloader to ${boot_interface} ${boot_dev}...;
+ ebtupdate ${ramdisk_addr_r} ${filesize};
+ pause 'Press ANY key to reboot device...'; reset;
+ else echo Reading bootloader failed;
+ pause 'Press ANY key to return to bootmenu...'; bootmenu; fi
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 9/9] doc: cmd: Update ebtupdate description and document bctupdate command
2026-12-05 10:05 [PATCH v2 0/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
` (7 preceding siblings ...)
2026-12-05 10:05 ` [PATCH v2 8/9] board: tegra: Update ebtupdate usage Svyatoslav Ryhel
@ 2026-12-05 10:05 ` Svyatoslav Ryhel
8 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2026-12-05 10:05 UTC (permalink / raw)
To: Svyatoslav Ryhel, Thierry Reding, Tom Rini, Ilias Apalodimas,
Jonas Schwöbel, Ion Agorria, Peter Geis, Mattijs Korpershoek,
Guillaume La Roque
Cc: u-boot
From: Ion Agorria <ion@agorria.com>
Change docs to reflect the current args and add bctupdate command docs
which is practically the same only for BCT instead of bootloader.
Signed-off-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
doc/usage/cmd/bctupdate.rst | 45 +++++++++++++++++++++++++++++++++++++
doc/usage/cmd/ebtupdate.rst | 41 +++++++++------------------------
2 files changed, 55 insertions(+), 31 deletions(-)
create mode 100644 doc/usage/cmd/bctupdate.rst
diff --git a/doc/usage/cmd/bctupdate.rst b/doc/usage/cmd/bctupdate.rst
new file mode 100644
index 00000000000..4556b8dd361
--- /dev/null
+++ b/doc/usage/cmd/bctupdate.rst
@@ -0,0 +1,45 @@
+.. SPDX-License-Identifier: GPL-2.0+:
+
+.. index::
+ single: bctupdate (command)
+
+bctupdate command
+=================
+
+Synopsis
+--------
+
+::
+
+ bctupdate [<bct_addr>] [<bct_size>]
+
+Description
+-----------
+
+The "bctupdate" command is used to self-update bootloader on Tegra 2 and Tegra 3
+production devices.
+
+The "bctupdate" performs encryption of new bootloader, loads existing BCT to
+decrypt, patch and re-encrypt. After BCT and bootloader are written in
+their respective places in the boot device.
+
+bct
+ address of the plaintext BCT pre-loaded into RAM.
+
+size
+ size of the pre-loaded bootloader.
+
+Example
+-------
+
+::
+
+ load mmc 1:1 ${kernel_addr_r} ${bootloader_file};
+ size mmc 1:1 ${bootloader_file};
+ bctupdate ${kernel_addr_r} ${filesize};
+
+Configuration
+-------------
+
+The bctupdate command is only available if CONFIG_CMD_EBTUPDATE=y and
+only on supported Tegra configurations.
diff --git a/doc/usage/cmd/ebtupdate.rst b/doc/usage/cmd/ebtupdate.rst
index 5102e6090a4..d1cd82614fa 100644
--- a/doc/usage/cmd/ebtupdate.rst
+++ b/doc/usage/cmd/ebtupdate.rst
@@ -11,23 +11,20 @@ Synopsis
::
- ebtupdate [<bct> [<ebt>] [<size>]]
+ ebtupdate [<ebt_addr>] [<ebt_size>]
Description
-----------
The "ebtupdate" command is used to self-update bootloader on Tegra 2 and Tegra 3
-production devices which were processed using re-cryption.
+production devices.
-The "ebtupdate" performs encryption of new bootloader and decryption, patching
-and re-encryption of BCT "in situ". After BCT and bootloader can be written in
-their respective places.
-
-bct
- address of BCT block pre-loaded into RAM.
+The "ebtupdate" performs encryption of new bootloader, loads existing BCT to
+decrypt, patch and re-encrypt. After BCT and bootloader are written in
+their respective places in the boot device.
ebt
- address of the bootloader pre-loaded into RAM.
+ address of the plaintext bootloader pre-loaded into RAM.
size
size of the pre-loaded bootloader.
@@ -35,32 +32,14 @@ size
Example
-------
-This is the boot log of a LG Optimus Vu:
-
::
- => mmc dev 0 1
- switch to partitions #1, OK
- mmc0(part 1) is current device
- => mmc read $kernel_addr_r 0 $boot_block_size
- MMC read: dev # 0, block # 0, count 4096 ... 4096 blocks read: OK
- => load mmc 0:1 $ramdisk_addr_r $bootloader_file
- 684783 bytes read in 44 ms (14.8 MiB/s)
- => size mmc 0:1 $bootloader_file
- => ebtupdate $kernel_addr_r $ramdisk_addr_r $filesize
- => mmc dev 0 1
- switch to partitions #1, OK
- mmc0(part 1) is current device
- => mmc write $kernel_addr_r 0 $boot_block_size
- MMC write: dev # 0, block # 0, count 4096 ... 4096 blocks written: OK
- => mmc dev 0 2
- switch to partitions #2, OK
- mmc0(part 2) is current device
- => mmc write $ramdisk_addr_r 0 $boot_block_size
- MMC write: dev # 0, block # 0, count 4096 ... 4096 blocks written: OK
+ load mmc 1:1 ${kernel_addr_r} ${bootloader_file};
+ size mmc 1:1 ${bootloader_file};
+ ebtupdate ${kernel_addr_r} ${filesize};
Configuration
-------------
The ebtupdate command is only available if CONFIG_CMD_EBTUPDATE=y and
-only on Tegra 2 and Tegra 3 configurations.
+only on supported Tegra configurations.
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread