From: Svyatoslav Ryhel <clamor95@gmail.com>
To: "Svyatoslav Ryhel" <clamor95@gmail.com>,
"Thierry Reding" <treding@nvidia.com>,
"Tom Rini" <trini@konsulko.com>,
"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
"Jonas Schwöbel" <jonasschwoebel@yahoo.de>,
"Ion Agorria" <ion@agorria.com>,
"Peter Geis" <pgwipeout@gmail.com>,
"Mattijs Korpershoek" <mkorpershoek@kernel.org>,
"Guillaume La Roque" <glaroque@baylibre.com>
Cc: u-boot@lists.denx.de
Subject: [PATCH v2 1/9] fastboot: Add board_fastboot_flash/erase/get_part_info hooks
Date: Sat, 5 Dec 2026 12:05:37 +0200 [thread overview]
Message-ID: <20261205100545.106967-2-clamor95@gmail.com> (raw)
In-Reply-To: <20261205100545.106967-1-clamor95@gmail.com>
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
next prev parent reply other threads:[~2026-12-05 10:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-12-05 10:05 ` [PATCH v2 2/9] ARM: tegra: Refactor BCT patching process Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 3/9] ARM: tegra: Add custom fastboot flash handler Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 4/9] configs: tegra: Enable TEGRA_FASTBOOT_FLASH option Svyatoslav Ryhel
2026-12-05 10:05 ` [PATCH v2 5/9] crypto: tegra_aes: Add support for Tegra124 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
2026-12-05 10:05 ` [PATCH v2 7/9] ARM: tegra: n1: Add bsev node 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205100545.106967-2-clamor95@gmail.com \
--to=clamor95@gmail.com \
--cc=glaroque@baylibre.com \
--cc=ilias.apalodimas@linaro.org \
--cc=ion@agorria.com \
--cc=jonasschwoebel@yahoo.de \
--cc=mkorpershoek@kernel.org \
--cc=pgwipeout@gmail.com \
--cc=treding@nvidia.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.