From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 242DB606A322 for ; Sat, 5 Dec 2026 10:06:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.u-boot-project.org header.i=@lists.u-boot-project.org header.a=rsa-sha256 header.s=default header.b=yQSayvta; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0rqAf1pK Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 6E5AD60683; Sat, 5 Dec 2026 10:06:27 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id hq911mQHgIZy; Sat, 5 Dec 2026 10:06:25 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp3.osuosl.org 3578E60619 Authentication-Results: smtp3.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1796465185; b=EeCI5EG3rOWXOzz/I9WrcXhGY3SstS6NV7djVd+Y8O+bRrh6N0Tt//pr08kwHC6h4dlX OgFhaTLvzzEaIhJSdbDh/ptoGZSYuuW/Yj2bL9kVAJCg6aW+1t8szPyuN+VIFCY3x0wgQ h6Y6cWQa3nfqKEKtUbXr0U3aT7fQnC0r3Ts9ReaAbetHpd0MY4JiEqLX3ccLdxd5d+aMW wfn0w3V5oAKSrV8udZOJzEbBuVaOBXMvVxC01hlJgWMiW1lmfR5Nm1Ec0MJ5hny9LE7Ma zrmTXmW0V0Qh14x45JKvIq37OaejxXoNhUQnWSMnDE2XqSluTgPBo4yPlboW3e6H/tw== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1796465185; h=X-Comment:DKIM-Signature:X-Original-To:Delivered-To:Received: Received:X-Virus-Scanned:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Spam-Status:Received:ARC-Filter:X-Comment:Received:Received: Received:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Virus-Scanned:X-Virus-Status:X-BeenThere: X-Mailman-Version:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:Errors-To; bh=ujZ7+fwyKmqZKxh99zhzkpniU7iYMb5rvpe+jhNWQQw=; b=F1P2MKeHaGWNn3WSOlVFCo6Fy3wJHNcMkLZDxLzsyPj7yEM3vTTPUpkLFk53VOsicH4n XoTiPcAomM4w8HdRTO685q68Twvcl8tBBNU9BG7rMv6E17fMu6u1fwW7MX+kfMgYJ9TqH BzWvNtsbdXMVzRsb/zUDO2a2yb3kzo/rpiSahMjAevJZ0eFfbLAUjo3jOES6ff+u9eEor 8kjSZNCPcbzXku5CZcmXw2vCrY1Jhu1cX4g98lu4VrkI8EgJ+zP0fCJCw6r9t1LLRHNcB P8GV36F2NyvykYwPIzBODvWIvbyiKcmR1UiUKEU/TNd9I1NL7Mr0f3pKyKTEPk9/+Mg== ARC-Authentication-Results: i=1; smtp3.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=u-boot-bounces@lists.u-boot-project.org; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.u-boot-project.org; s=default; t=1796465185; bh=ujZ7+fwyKmqZKxh99zhzkpniU7iYMb5rvpe+jhNWQQw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=yQSayvtaD9aG0IxR7T2Vh+DOszIUT4i4GQoz8xHihZ7ibtikCbuZh5BaSodXacGx7 W6FokIWWVlRkX7POjqidgAwHBuAeuTUGblg1EXNx9Rek6R3JOukR60Qp9sv+ZTGvS+ 2xx53aZCrfKQ0lkxhnNA4a33t8SUHJmpMv34KSIrjGSOf5A5IS/ae03zn/lbfVTE1z BMioiFl9XNvImePACTI3kPEcYtJfAkhLkJ4+ZD3pwYC5U6ZYcUkqqtUN7TQHhhO6oA OmrhtxwKEHwnemI/0LMxUYNpv1EtNaI6kabmYI4NKEvcWERAAr+0DdUf5bIn9JR16c jYTSRxtbKBHdg== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp3.osuosl.org (Postfix) with ESMTP id 3578E60619; Sat, 5 Dec 2026 10:06:25 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists1.osuosl.org (Postfix) with ESMTP id 30058158 for ; Sat, 5 Dec 2026 10:06:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 15A1540E07 for ; Sat, 5 Dec 2026 10:06:24 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 4ciF1YBO_NyT for ; Sat, 5 Dec 2026 10:06:23 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp4.osuosl.org 78ED040E05 Authentication-Results: smtp4.osuosl.org; arc=none smtp.remote-ip=85.214.62.61 X-Comment: SPF check N/A for local connections - client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=clamor95@gmail.com; receiver= Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp4.osuosl.org; spf=fail smtp.mailfrom=gmail.com Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0rqAf1pK Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by smtp4.osuosl.org (Postfix) with ESMTPS id 78ED040E05 for ; Sat, 5 Dec 2026 10:06:22 +0000 (UTC) Received: by phobos.denx.de (Postfix, from userid 109) id 71999847EC; Sat, 5 Dec 2026 11:06:20 +0100 (CET) Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 478B683EF9 for ; Sat, 5 Dec 2026 11:06:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=clamor95@gmail.com Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-6b87a240de3so1952992a12.1 for ; Sat, 05 Dec 2026 02:06:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796465173; x=1797069973; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ujZ7+fwyKmqZKxh99zhzkpniU7iYMb5rvpe+jhNWQQw=; b=0rqAf1pKcrnA4B7ewxpMeucRyXhnqjxLw5mcM5xgJRCaY6saIJ3gRNCz3Nhd1wnGLr sr24MzAG4m0xO87y3exzKFPmNQDdwhabWZxwbJcWu6I0qWu5BXch8KAhf4pS0ArbXny1 FNzF+/zPyfIVuYA+/z8x9uuv5UUBl3zn80YzJeXPyw8uIeEOVkNGfwhaccZ7JhDIkZ7k Gila8xwUeHsbyg9oC12y84AqP7Sj+BPa5hokej55vB2JeaLZbbjrxOJPEbwjkTnqZ/oT wmxlwuNGs49UHsb/9kAMMgUE+HOmoh/auGVs3+zp5oc/tELiZv0mw1ZmE9Y0m1ZWu+7E aBLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796465173; x=1797069973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ujZ7+fwyKmqZKxh99zhzkpniU7iYMb5rvpe+jhNWQQw=; b=gXW8CrxnDS8bna3lHI6NNiYwD49NhOYLWAiQSEe0wxbsdCaGbGhZ0PQmQmB0wVtaQH QBOgx3eBnuFUS8Bna1+XzE2z9yMNvjWZAlx6D73/KXEP+JMqt5dsZSX+dSR2lv5TgH9j 4B9MqAQhQFHY5Z5nqXn4lBbk6//pzUTIzal/XbWNr7eWnCJR8GhCPIVOhkVehjRJ8zaH wBLWbOap4nnH1sQdq4cvuLUygR5XwI50ocOefbJdtqI1tbNaECsWzE7LVr9zJGR8oI5J pefVLNPJQt8I+juOhJfyW/IqWb8cGF/V2yMhFviLlhESYyv/XPI5X0laoy6NJSSiuOrh QAWA== X-Gm-Message-State: AB4q+uFbMs8ydlBnwzeq228lhFp6AuQ/oMOUstQL15jWvF08oEmIf7dv w1byJz/Nal8og9/TcqXnZFS3vaBLbQFXvPBIXtBTnGE8X6A9DXhKqhG9 X-Gm-Gg: AZFdTZef5HvRP7L+JLcM1OkuWEIQ4kiXQtlYOJvcS+E5JIK93mglRYIJXCiDq8fnuLk lF6HYG4UQ3kPdKuY29fney/rZAfCOGJq9beHg5kinOG+3c6oXB7mjNPKRqF97gFAUi/0QEFMsLD vu+oj6h7tbtU6G28kZpaUEMpmlesV32O4q2bm+3y5Otpd6JBZIPd7Mmoj5tc/G5dK6Lx/JFaeeZ LoIO9YBp/Hjv0lhTVR5u6T+Ud7DnzXmFdlCS9xzP+L3yaf6hIzhzJJw4BqLDqmbtiZw8UOVcXpn sT9NlEQhHow+tV3rWQm7vgdg0n9IrjrMyfss1lYw222gutagrZ4266cpFj9avqIE7X8jGW1MUoc 8RQRFP5MF0LzRK/YjUsYoaAmGA4tx+V9m7ecJ6m8mKEt1j2n0nyzOMnGSBaoG7R8RkXhoIg4kJx +1Dx7plJ9hEwhyiIWbKAQ0Wniwk8+O+SYCvxcGrAKVyaVuHYciMWzXwTqY73ctMrW6Y9yn5y1AG G99Iix2SDUF9T/CpKPcJO3m5gHdCCMumXOy5LbYM2XxmgnLpFNzScaGjShNwvlZZU2LJXBntEdO O0WHVVB3SoAzmQxmsR7pNnGflwqLHsIsMYzJnm2riTYq0TIJuOta3TA8i92QNyD8gOIEEx/SnIN emh577tvRmg== X-Received: by 2002:a05:6402:3642:b0:6bc:6c5c:c786 with SMTP id 4fb4d7f45d1cf-6bcc22536f9mr2769208a12.37.1796465172398; Sat, 05 Dec 2026 02:06:12 -0800 (PST) Received: from xeon ([188.163.112.54]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c525b64dd0dsm231759366b.83.2026.12.05.02.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 02:06:11 -0800 (PST) From: Svyatoslav Ryhel To: Svyatoslav Ryhel , Thierry Reding , Tom Rini , Ilias Apalodimas , =?UTF-8?q?Jonas=20Schw=C3=B6bel?= , Ion Agorria , Peter Geis , Mattijs Korpershoek , Guillaume La Roque 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 Message-ID: <20261205100545.106967-2-clamor95@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261205100545.106967-1-clamor95@gmail.com> References: <20261205100545.106967-1-clamor95@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean X-BeenThere: u-boot@lists.u-boot-project.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: U-Boot discussion List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_FAIL,SPF_HELO_NONE, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Ion Agorria 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 Signed-off-by: Svyatoslav Ryhel --- 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