[{"id":3683638,"web_url":"http://patchwork.ozlabs.org/comment/3683638/","msgid":"<CAFLszTgHEW8ywXEtAqOs7rHHUPYFGXRmurAJFqVdORxr2vBGBQ@mail.gmail.com>","list_archive_url":null,"date":"2026-04-28T18:20:40","subject":"Re: [PATCH v2 2/4] fastboot: Add GPT/MBR partition table flashing\n helper functions","submitter":{"id":6170,"url":"http://patchwork.ozlabs.org/api/people/6170/","name":"Simon Glass","email":"sjg@chromium.org"},"content":"Hi Balaji,\n\nOn 2026-04-27T12:06:41, Balaji Selvanathan\n<balaji.selvanathan@oss.qualcomm.com> wrote:\n> fastboot: Add GPT/MBR partition table flashing helper functions\n>\n> Add fastboot_flash_gpt_partition_table() and\n> fastboot_flash_mbr_partition_table() helper functions that handle\n> flashing of GPT and MBR partition tables to block devices.\n>\n> The MMC backend now uses these helper functions for GPT and MBR\n> operations, simplifying the code while maintaining the same\n> functionality.\n>\n> Signed-off-by: Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>\n>\n> drivers/fastboot/fb_common.c | 94 ++++++++++++++++++++++++++++++++++++++++++++\n>  drivers/fastboot/fb_mmc.c    | 49 ++++-------------------\n>  include/fastboot-internal.h  | 30 ++++++++++++++\n>  3 files changed, 131 insertions(+), 42 deletions(-)\n\n> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c\n> @@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size)\n> +     dev_desc = blk_get_dev(interface, device);\n> +     if (!dev_desc) {\n> +             fastboot_fail(\"no such device\", response);\n> +             return;\n> +     }\n\nLooks like a regression for the MMC path: the current\nfastboot_mmc_get_dev() rejects dev_desc->type == DEV_TYPE_UNKNOWN (mmc\ndriver present but no card) and reports 'invalid mmc device'. That\ncheck is gone after this refactor, so an unprobed mmc falls through to\nis_valid_gpt_buf() / write_mbr_and_gpt_partitions() with an unusable\ndev_desc  - please add the DEV_TYPE_UNKNOWN check in both helpers so\nthe common path is at least as strict as the code it replaces.\n\n> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c\n> @@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size)\n> +#if CONFIG_IS_ENABLED(EFI_PARTITION)\n> +/**\n> + * fastboot_flash_gpt_partition_table() - Flash GPT partition table\n> + * @interface: Block interface name (e.g., 'mmc', 'scsi')\n> + * @device: Device number\n> + * @download_buffer: Buffer containing GPT data\n> + * @response: Fastboot response buffer\n> + */\n> +void fastboot_flash_gpt_partition_table(const char *interface,\n> +                                     int device,\n> +                                     void *download_buffer,\n> +                                     char *response)\n\nThe two helpers are almost identical - only is_valid_*_buf(),\nwrite_mbr_*() and a couple of printed strings differ. Please factor\nthe common parts (interface check, blk_get_dev(), DEV_TYPE_UNKNOWN\ncheck, part_init() + okay) and have the GPT and MBR variants supply\njust the validate/write step. As written, the fail-paths are\nduplicated and will drift over time.\n\n> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c\n> @@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size)\n> +     if (is_valid_gpt_buf(dev_desc, download_buffer)) {\n> +             printf(\"%s: invalid GPT - refusing to write to flash\\n\", __func__);\n\nfb_common.c does not include <part.h> or <blk.h> even though it now\ncalls blk_get_dev(), is_valid_gpt_buf(),\nwrite_mbr_and_gpt_partitions(), is_valid_dos_buf(), write_mbr_sector()\nand part_init(). It builds today via a transitive include, but let's\nadd explicit includes.\n\n> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c\n> @@ -343,7 +343,7 @@ int fastboot_mmc_get_part_info(const char *part_name,\n> -static struct blk_desc *fastboot_mmc_get_dev(char *response)\n> +static struct blk_desc __maybe_unused *fastboot_mmc_get_dev(char *response)\n\nThe convention is 'static __maybe_unused struct blk_desc\n*fastboot_mmc_get_dev(...)'\n\n> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c\n> @@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size)\n> +     if (!interface || !strcmp(interface, \"\")) {\n> +             fastboot_fail(\"block interface isn't provided\", response);\n> +             return;\n> +     }\n\nThe MMC caller passes the literal 'mmc', so this branch is dead on\nthat path. The check is really for the block backend in patch 3, where\nthe interface comes from CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME.\nThat validation belongs in the block caller (alongside the\nparse_device_partition() call), not duplicated in both common helpers\n- same reason fastboot_block_get_part_info() already does the check\nitself.\n\nRegards,\nSimon","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256\n header.s=google header.b=nh0yD/nA;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=85.214.62.61; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=chromium.org","phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de","phobos.denx.de;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=chromium.org header.i=@chromium.org\n header.b=\"nh0yD/nA\";\n\tdkim-atps=neutral","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=chromium.org","phobos.denx.de;\n spf=pass smtp.mailfrom=sjg@chromium.org"],"Received":["from phobos.denx.de (phobos.denx.de [85.214.62.61])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4pf33Zzlz1xrS\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 04:20:59 +1000 (AEST)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 9A48084692;\n\tTue, 28 Apr 2026 20:20:56 +0200 (CEST)","by phobos.denx.de (Postfix, from userid 109)\n id 93B23846B2; Tue, 28 Apr 2026 20:20:55 +0200 (CEST)","from mail-ej1-x633.google.com (mail-ej1-x633.google.com\n [IPv6:2a00:1450:4864:20::633])\n (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id 0182F84686\n for <u-boot@lists.denx.de>; Tue, 28 Apr 2026 20:20:53 +0200 (CEST)","by mail-ej1-x633.google.com with SMTP id\n a640c23a62f3a-bb91b426e40so48385966b.0\n for <u-boot@lists.denx.de>; Tue, 28 Apr 2026 11:20:52 -0700 (PDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,\n DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,\n RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham\n autolearn_force=no version=3.4.2","ARC-Seal":"i=1; a=rsa-sha256; t=1777400452; cv=none;\n d=google.com; s=arc-20240605;\n b=k2qdhyULWocQZPfmYor+guCGYgrodprMVK7uKY6ypVgZ6XODbSRmIAuL5SKLFBS+xX\n LEFqPKlWELNJfnKdFW9rFzUYiu4W5myDdbq46tojNe8ai3Ht/mLxSHRB1Wx2gMWy9Srb\n KrkHB3XXaDewtme6UfoojTL4Jm1JwFPMAcU9z3peotB7l1SFYzyJG4lvEJRfmb0CCPQR\n J9UuoGC9NrkLAM5MaxCL6mJg+Ddof4rtak19qGifQVQiz49nEUqQeAUKxtDCing9XPcM\n XnRxxnrKgrzpDoRhoHv94LMY2dJNje2QnapRQTzM/3qLEfEz+5xv6PI8NtHN7ltG0ip8\n l68g==","ARC-Message-Signature":"i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=cc:to:subject:message-id:date:from:in-reply-to:references\n :mime-version:dkim-signature;\n bh=1pDTqgmjCa3ONi2WbpVOWSkNavIsxiYxP3cjbaMgikc=;\n fh=FSZLg1kBZKtmq7hkO96s8J8bywdf/NrVlQg027zGQAY=;\n b=Dwhwv4Baj11XzVXxAZarorvihf/nxkRA6ODzP+KQjpHMogoEgWFGdg5ND4OezAFX/G\n a+Di/cY5BcXZLFrnl5VobT/2pKB8O/1vXYEvV5zoRuvX+1WOs0rIG7+774YyocyTpDG4\n LM390xp1zbfsGjnieH9iGSUSgk6zoQTKn90kny2+OACq5I7jae4jQcNdSaoOMymLzfRR\n SIoZoMNImtdspij1Fifvlg7+ynYL8ohoD+4sYB46Q3RJB631IFhyYeS8ZmEIDJVm5hGR\n mqz3/08Z1pyzpNU8wjKt+tqwUtZ2nZv1bmjVKCTSwCO1yk9zaVLRpBQonW2RNxhqX4Lh\n 7mgg==; darn=lists.denx.de","ARC-Authentication-Results":"i=1; mx.google.com; arc=none","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=chromium.org; s=google; t=1777400452; x=1778005252; darn=lists.denx.de;\n h=cc:to:subject:message-id:date:from:in-reply-to:references\n :mime-version:from:to:cc:subject:date:message-id:reply-to;\n bh=1pDTqgmjCa3ONi2WbpVOWSkNavIsxiYxP3cjbaMgikc=;\n b=nh0yD/nAATvzH6lj9rRzjsIt9xZnPG/Tfd+lFuLVpuBaX5B5u+qByMSTmVeTKC1Vgd\n GFCJxbPmFtwlvkXGupz8mdW3nAeiV0CHbDvYr7ZlJIjJWAEuWra8iEpgVJT4YGVkJlLT\n vMjLp6Q7m5Nm/Ej3dmou0ipVqUenhWKGxHqeA=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777400452; x=1778005252;\n h=cc:to:subject:message-id:date:from:in-reply-to:references\n :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=1pDTqgmjCa3ONi2WbpVOWSkNavIsxiYxP3cjbaMgikc=;\n b=pH4GvUeqE2AztHsSVuhbNZJwW0v3YT0eBmFVf8wnQIfbL8RXNxUky/0wJvAY68G3GY\n N8qY7HOc+d8p3s+pbR3KUPzY0sf2/Ap8gCT1FrqrwpBzg5cFFXSEL43RRZCA+vVxc4oK\n +DU0nGpWf2osdd/G6BYXFBHT0EUu2D5cRiVSQ+wcgPbADaUpt1qompl9xp3lmLyrKECQ\n mAig2QEHfhTL8YJiCardbWZmoX9ewUJ32WgKg0XWgpbw1wYYn3SfJL/3nZcWJtf56D04\n 3FnbX35uLQY/+hbhLYCBZgQr/fHyCcwiOC8qPaAXt/qBTSUjPKO1j5uNxMrauTwGWkP/\n /VOw==","X-Gm-Message-State":"AOJu0YzlywaB6yqNEKoVnswPIHwP6pwZL0K6SBpMZf6VA2IM6v+OjyVR\n JfREqCJhBJGpcoJzNpS0eWZJfQbk+Q5nb8GErwJaslFymaQwHl8pxiyQhWgdAegysUssoreUXzE\n pTYZKEf50u1jjO/6EnTN1slmWmBbaKN/8IeE/wCHs","X-Gm-Gg":"AeBDiesVRxqNQOF6nk9Q53ypGU3iQ/7p2HG4yPVYHCHCl01QU1LoVWO7R/e9uKc/Z2p\n IJQU5056Ph26SfZzWNcvpD7x8eYiGQLdvckF0tiKBOKYONlS8jMhV7jatILVSlVPCIiwzcGfFmN\n WYPWpJd+/2AvsxwuCVOwKtfaTbh59tMvXENCzVlVDpyUjaoiUSUFv9YxOkKsoFQlV8VtaaSxXg/\n vfVwFeBuxkGc8SyBH1Kj8XqAZVLIhChHq0eAnMPzrf3rVtggx5ENnb0asHTvqxwj30N1xY+sdv+\n p2ul8W3fOvkmvnuW","X-Received":"by 2002:a17:907:93c3:b0:ba7:f5fd:edd2 with SMTP id\n a640c23a62f3a-bb93eb5124dmr21485266b.42.1777400452349; Tue, 28 Apr 2026\n 11:20:52 -0700 (PDT)","MIME-Version":"1.0","References":"<20260427-fb_gpt-v2-0-9e7fe3c1649a@oss.qualcomm.com>\n <20260427-fb_gpt-v2-2-9e7fe3c1649a@oss.qualcomm.com>","In-Reply-To":"<20260427-fb_gpt-v2-2-9e7fe3c1649a@oss.qualcomm.com>","From":"Simon Glass <sjg@chromium.org>","Date":"Tue, 28 Apr 2026 12:20:40 -0600","X-Gm-Features":"AVHnY4LzCiSBJPtnzOfQSQcawaZVtaiMDef1jEH-jL2IekXwcrs20RL3s6rAx-M","Message-ID":"\n <CAFLszTgHEW8ywXEtAqOs7rHHUPYFGXRmurAJFqVdORxr2vBGBQ@mail.gmail.com>","Subject":"Re: [PATCH v2 2/4] fastboot: Add GPT/MBR partition table flashing\n helper functions","To":"balaji.selvanathan@oss.qualcomm.com","Cc":"u-boot@lists.denx.de, Mattijs Korpershoek <mkorpershoek@kernel.org>,\n Tom Rini <trini@konsulko.com>, Heiko Schocher <hs@nabladev.com>,\n Neil Armstrong <neil.armstrong@linaro.org>,\n Dmitrii Merkurev <dimorinny@google.com>,\n Adrian Freihofer <adrian.freihofer@siemens.com>, Peng Fan <peng.fan@nxp.com>,\n Jaehoon Chung <jh80.chung@samsung.com>,\n \"Ariel D'Alessandro\" <ariel.dalessandro@collabora.com>","Content-Type":"text/plain; charset=\"UTF-8\"","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.39","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<https://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>","X-Virus-Scanned":"clamav-milter 0.103.8 at phobos.denx.de","X-Virus-Status":"Clean"}}]