Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB494C433F5 for ; Tue, 11 Oct 2022 15:52:40 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D6F6584F07; Tue, 11 Oct 2022 17:52:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.b="CmxuN49+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0707884F07; Tue, 11 Oct 2022 17:52:37 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2084.outbound.protection.outlook.com [40.107.22.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B9D8C840AE for ; Tue, 11 Oct 2022 17:52:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sean.anderson@seco.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H/mzJN1fAv4ptieo6P8d41NpTuR3aOxP9iDQ5QY4qywFdQtkTtohXS5UY1MAtlDksQs8OBjyc+XRTEdHASd7YmBs5+eaZbfzcvQLUOI4CuJBNB6Ln0xetcN3264ld3P+7NnmR4AzAW8aGZH5PgR2zf3nzZQQYUXaaweqT6QUV6tDAWCOVUUnOXLQj/rVwPJr+WS35GwxWH+HpcZzEvK0SLeEHa1T2rsYFY6bfSc5rKZddlQnmt4bfyvnnl3eu0oRHLOIwwg9K64ILgOi7CkMqeuZAi7ahboWvBCogtlueIyhlr3wsKXvGcvUAZYZ/QgZavseK2iwiU3NWN4tQcXR7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=naLveZj/ucJ0qkZqy0lP4S9kwMvQdUHMD0hzsoK/6V8=; b=epBmH0Ti5W4XLd63GoaowOt1kC8Oo7qLdTfUSdZv0YZqrr4UrmbLZDbnn/Umchfeq76IYB5dPSpzcBzIJ1MPueObNf9bKoSlyavd7XxsQfyk2ThVyuYMCBnYEZkVXrLs7J780g5jpr7WcC/BCO5vMMTJO3oEgVDbiKj6SXHp1yD6XmP1lOBYkTSXwrTnsHC7tfAJEBLbIv7bzihxPnHvW9/6VK6r1g7WEP+sbvsO4wkGydhgvfzXq0I58L4KGSssv5X1W6suS/QzrJkpnbkgb3AdRC7s8wH+8dkJUN7HSrMykjLp6h3W12xJ38CZ201wxMsjNqmR5l/E+d3T3jC9+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=naLveZj/ucJ0qkZqy0lP4S9kwMvQdUHMD0hzsoK/6V8=; b=CmxuN49+SIm4xE4uQXVZLPBy3pUMst1Sx82paRgxeYaRjEb0xkfWTdrPqQgV416lkHReAoORE7elSUpNLFcGeScu7U6X0IRVP53NYcV5MLvLZNO9pphnyI8wKImf5QQlia4ZwYpYGp5vANVFFKyzh1+AVnK2w+u3madr+Ao1g+kJDNqTPeyk9uT5SOWWSTRwkJ6yIsV/EhMK8Z0zAd2U5pLjIjxZPY/yovePmFomgcstgCaTLA3PHMGZFA+5o8kx2qE6iJgD0nAqZsSCe/QLeYm63t+wta93B13EGCKG+urUw57hRw9c1JEj5dF+DaVsaIU3defSCyzow6qK4qOddg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) by AM9PR03MB6835.eurprd03.prod.outlook.com (2603:10a6:20b:281::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Tue, 11 Oct 2022 15:52:30 +0000 Received: from DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::204a:de22:b651:f86d]) by DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::204a:de22:b651:f86d%6]) with mapi id 15.20.5709.015; Tue, 11 Oct 2022 15:52:29 +0000 From: Sean Anderson Subject: Re: [PATCH] fastboot: mmc: switch to user hwpart after erase/flash To: Mattijs Korpershoek , Patrick Delaunay Cc: u-boot@lists.denx.de, Simon Glass , Jaehoon Chung , Matthias Schiffer References: <20221010-switch-hwpart-v1-0-52cbd34c72b7@baylibre.com> <87k05636o7.fsf@baylibre.com> Message-ID: <7554ecac-11a7-c58b-950e-ad6a627318cf@seco.com> Date: Tue, 11 Oct 2022 11:52:25 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: <87k05636o7.fsf@baylibre.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BLAPR05CA0010.namprd05.prod.outlook.com (2603:10b6:208:36e::19) To DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR03MB4972:EE_|AM9PR03MB6835:EE_ X-MS-Office365-Filtering-Correlation-Id: cc3b2633-1a16-450a-c8a2-08daaba09a11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kKMzPStIdpoG1akUsUpEGNxwbzkQpJI0UD/yrrq6QOPr7fSKmwZFOcXFS+FAnQY8zrTNzMg745balwfIsk+O4t2tEih7Rq2BQqdz96Drt+KIu/uWKW+i45q2DLMAV2PjFvUzobfdA/ic8lGKuVdPofgDvInd/l3addQX0PF8cSTVR8orFN/FZXI4dfjmomElRTeyd6HrZPxLsMgRwzSNsLTNs8fF5I5lnBYgyANKHt10oTyulVOyfbA75DOQgM4slEHYE6JQ1V3B+D5m0eUHLDd5X4RSBSliBBOj7LHvrijl4u0qi3WDQztuXx04P8tkBHF6h+Z6lQM9vXfuL6oMXHiGG/6Mbr33CD2+K8kOd2LmK0btRUaZNrcVktNI/5ZSHRpU6V3qpL1omalzNEXv5terKgR65LFPmW/oGZxPZQz8Hq8DX1vGN9gTqmc8vkqFfrMbEXXK85Yxad8voZf3XHL8I1A2w1P/fhtmtzbJAR/6N7clU4TIuLIe3oajWpfIrksFlw5jkFx2GNNUpzKUPg1KpDX3NCzrbsYUxl+D+8MTkCVeQ2Br9EDmbZnQOteP+WiW3C3+MUj6ZDcKNhD6RgqDMEovKGOb2ansm1CvISf4I86j1ZffxYwwJcnG6RPvfxa+Oa14n6AegyVx05uZCIMLq38IwmtJWq0A8pOWfND3xJ+OroOp8VHO5aVHtKdQ7IeCcKvDkqIvEL7JZWOL+oZahtYyR8J+SSO4NTLl9fKWkJpdMrBfORqCFPXDvK1RZx4V9ZP1oHyfZaKs1SLArn0/ubpbuvpDSBcrCKdJF6khmq0pozbjANfk5mxv6QS/lf3ZrD8bHrJETOWoLLGRC4PGgDc44vIyraSaeaXkKmY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4972.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(396003)(376002)(346002)(136003)(39850400004)(366004)(451199015)(966005)(31686004)(6486002)(478600001)(110136005)(54906003)(316002)(6506007)(52116002)(66946007)(4326008)(8676002)(53546011)(6666004)(66476007)(2616005)(41300700001)(66556008)(26005)(6512007)(2906002)(8936002)(36756003)(5660300002)(44832011)(186003)(83380400001)(38350700002)(86362001)(31696002)(38100700002)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UXo1VHJXQjQvSXZLSS9PWElSWE5RbGM5Y0I2Q2dBcXdjem5ndVp0ZElUUUti?= =?utf-8?B?OWVmOUVJSEtNVS8yeUZKMk96VE5PbzVnV1AraGswVkFlWmdpaTlSNSs2K3Vt?= =?utf-8?B?VDJhQ3VDZGMzNGNXTy9sZ29kbHNVSkg0OE5yV2dxMTNlOUgxWlVZQkxVMEcy?= =?utf-8?B?VGlYOHErQVI3VFZtaDlLWnI4eERnRlRra1FiUnR1MU1UZm54VjN4R2FINEwy?= =?utf-8?B?SVg5L3pNaXE2VkZhc2drR3gzM2lIcUlPT3R5TW1TcE55QlNvYmJHRXdvTzU3?= =?utf-8?B?UkI0RHRvemZsaWtvcVlqeEtiZEFwRG9zVjRUSnpsbm9hd2FWMW96U2Jub3Vn?= =?utf-8?B?bFdpdEtFOERIc1NpVTg2RUZHVUtXSzBFUWpkTjVIRWtUQkdPTkczMVVBZ0VO?= =?utf-8?B?N1F4M1NJOWUrODB3bEJPS0VqektGY1l3VU9IOWVzZGRaQ010c2hVTlZZaWYr?= =?utf-8?B?cnY2dWEvQW1wc21Rbmxqa1FjT3Z5ejRxQmpycFk2YzdJMk5SNGRMYzZ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UhVdURIeUttLy9JT1hqQ2dp?= =?utf-8?B?L2I5SDN3MlUzcEtqVUJNK3hFQ08xVndManBHYko0YWRoWHE4UUpKTkVoQWww?= =?utf-8?B?RHFKbEJEU3ZlZThmSHdPZHpVR0lBcnhEbEY1OVpHcEVHVUxybSs4ME40MDBq?= =?utf-8?B?b2xsa0RsNG94dGRkZ0U2T2loTldic3ZSTjhpWmdSY0tUZGx6eWZieDh5YUNL?= =?utf-8?B?UUxIZmFFRUozZDVia0liUGxnMWxFWFZYek1YaWZaSkhHdlpYRDZrcDRKZC9Z?= =?utf-8?B?QzVMRVd5TkxpMzJCRm83b3duVmtRSmROSXJQc3hCdUs0cG5hV011cTNJbVNU?= =?utf-8?B?YzdjUUN4R2hlajZwYXZFQUMwRC95NkdvQ2hEZEJvZFNwWFBrY2hkOHdvVUEw?= =?utf-8?B?enBDK3ZmR0w2KzdkdVN4UEZzalRQRFZrVldxUWdRZFY4ODJ5dm8vNGJKMVgx?= =?utf-8?B?b0F2ZU93YlIwTG9JSmR4L0hVQ0tXb0ZLU1E3ejErUEgrcElSc0R5ZkdISHdL?= =?utf-8?B?YlpQUjk5aGtCNWdCTFpFUVRNUllxQ1hGeVNIeGpHQnRRK2VKVnorYmMwdGgy?= =?utf-8?B?eTlvd3huUXU2bktPNC9tRDdTaUczbEc2aWNmQ1kvWFdKbzhuUmhOaENFSjRr?= =?utf-8?B?akxYU0Y0NW9zSUlUbE5pb2ZDUlROanBSaDFCbDBocmx2TU03Rkg2R1Z0T3o3?= =?utf-8?B?Z0w5NDU4UlA2WGdueTZEZzZJMitPdDh2ZXZkbkc4cnZjNFRtQjdjdUxFVk1W?= =?utf-8?B?K3c9PQ==?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc3b2633-1a16-450a-c8a2-08daaba09a11 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4972.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2022 15:52:29.6195 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oS0CACcALYlljy5TxFu7CYGVjag5wm73ae8SGHxXITelQGOEq4nom2lq+9P8wvMVqv2wmYwe0QveQ4PwDh3NLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB6835 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 10/11/22 8:07 AM, Mattijs Korpershoek wrote: > Hi Sean, > > Thank you for your review. > > On Mon, Oct 10, 2022 at 11:38, Sean Anderson wrote: > >> On 10/10/22 4:05 AM, Mattijs Korpershoek wrote: >>> Before erasing (or flashing) an mmc hardware partition, such as >>> mmc0boot0 or mmc0boot1, we select it using blk_dselect_hwpart(). >>> >>> However, we don't select back the normal (userdata) hwpartition >>> afterwards. >>> >>> For example, the following sequence is broken: >>> >>> $ fastboot erase mmc2boot1 # switch to hwpart 1 >>> $ fastboot reboot bootloader # attempts to read GPT from hwpart 1 >>> >>>> writing 128 blocks starting at 8064... >>>> ........ wrote 65536 bytes to 'mmc0boot1' >>>> GUID Partition Table Header signature is wrong: 0xFB4EC30FC5B7E5B2 != 0x5452415020494645 >>>> find_valid_gpt: *** ERROR: Invalid GPT *** >>>> GUID Partition Table Header signature is wrong: 0x0 != 0x5452415020494645 >>>> find_valid_gpt: *** ERROR: Invalid Backup GPT *** >>>> Error: mmc 2:misc read failed (-2) >>> >>> The GPT is stored in hwpart0 (userdata), not hwpart1 (mmc0boot1) >> >> This seems like a problem with your boot script. You should run `mmc dev >> ${mmcdev}` (and `mmc rescan`) before trying to access any MMC >> partitions. This is especially important after fastbooting, since the >> partition layout (or active hardware partition) may have changed. > > I don't think I can fix this in my boot script. > My boot script runs => fastboot usb 0 which will start a loop to receive > fastboot commands from the host. > > The full u-boot env i'm using is in include/configs/meson64_android.h > > This loop will go on until "fastboot reboot " is called. > > I do can "work around" this by using the following fastboot sequence: > $ fastboot erase mmc2boot1 > $ fastboot oem format # switch backs to hwpart 0 (USER) > $ fastboot reboot bootloader > > But that's not a good option to me. From a user's perspective, it should > not matter in which order we issue fastboot commands to the board. > > Maybe I should fix bcb.c instead to make sure that it selects hwpart0 > before reading/writing into the bcb partition ? Yes. The bcb command should be using something like part_get_info_by_dev_and_name_or_num instead of using its own bespoke parsing. Unfortunately, command syntax is part of the API, but at the very least you can fall back to something sane if argv[2] ("devnum") doesn't parse as an int (aka it's the ifname). --Sean >> >>> As the blk documentation states: >>>> Once selected only the region of the device >>>> covered by that partition is accessible. >>> >>> Add a cleanup function, fastboot_mmc_select_default_hwpart() which >>> selects back the default hwpartition (userdata). >>> >>> Note: this is more visible since >>> commit a362ce214f03 ("fastboot: Implement generic fastboot_set_reboot_flag") >>> because "fastboot reboot bootloader" will access the "misc" partition. >>> >>> Signed-off-by: Mattijs Korpershoek >>> --- >>> This fix has been used for over a year in the AOSP tree at [1] >>> >>> [1] https://android.googlesource.com/device/amlogic/yukawa/+/c008ddaec0943adda394b229e83e147f6165773c >>> --- >>> drivers/fastboot/fb_mmc.c | 20 +++++++++++++++++--- >>> include/mmc.h | 1 + >>> 2 files changed, 18 insertions(+), 3 deletions(-) >>> >>> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c >>> index 033c510bc096..dedef7c4deb1 100644 >>> --- a/drivers/fastboot/fb_mmc.c >>> +++ b/drivers/fastboot/fb_mmc.c >>> @@ -199,6 +199,12 @@ static void write_raw_image(struct blk_desc *dev_desc, >>> fastboot_okay(NULL, response); >>> } >>> >>> +static void fastboot_mmc_select_default_hwpart(struct blk_desc *dev_desc) >>> +{ >>> + if (blk_dselect_hwpart(dev_desc, MMC_PART_USERDATA)) >> >> If you really want to do this, we shoud save the current partition and >> restore if after fastbooting. Always switching to hardware partition 0 >> is just as broken as the current behavior. > > ACK. This patch just replaces one broken behaviour by another one. I > will see if I can save the hardware partition state instead or patch the > bcb command. > > >> >> --Sean >> >