From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 051B5C433F5 for ; Mon, 4 Oct 2021 10:31:53 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 9846761216 for ; Mon, 4 Oct 2021 10:31:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9846761216 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kontron.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 585E3811CF; Mon, 4 Oct 2021 12:31:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=kontron.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=mysnt.onmicrosoft.com header.i=@mysnt.onmicrosoft.com header.b="dfS4XAol"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A2B0812B6; Mon, 4 Oct 2021 12:31:47 +0200 (CEST) Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-ve1eur02on0713.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe06::713]) (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 6ED0180FA5 for ; Mon, 4 Oct 2021 12:31:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=kontron.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=frieder.schrempf@kontron.de ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PozIw9PvJ+XwY4ZUWZOWLl8mK0+zke2m/9+d4aI+oxNvGBBJ7H31aLsm22dijZJpzPhQMrkL0eQbBFxltbelCdEhBeSXldFk5Vz3C/HtcsJ4G+pq55Y0iVa7QGc9qW+KYuF5yHrbv0aGKsM61ucI/9rYB0Q4vq2KROlBoKF8IJdW1ukJUD3SjD8EI40CNe/FmNj7eNmIkvNpMV3GX9CHxWfzSuorPzmPK0pXVQqviqnXpOEvtb1L1mWEZrCGxNo/Ph54pdwM9xx1ltm2I7FVM8QTdER0xK9tVRbzaNBmjHnuk9aRblAuGxdo1n8+Scj2MsUtkkH5RdfOloQuvelExw== 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=1CIqQn3J2Yj/xXQ81L9Gj1MFA95wy3V1a6NAU5TYmEQ=; b=deq1/QHEQJVPPX3HE5bFfrU4+AOIrcvxHn2/St6Jm+y9yY0F8Wk4Cx5puKVn7tQhHuENPVM0HBnk/CV0wLhGSBriIQhTiw8b5pGMmVCro1oDvk76sZ6JcksKIpNTg9tRNY/kMjwmK7x+g8gPd7/JajA+9Ju4M+vC0X201qoiCQF3jnGTvVynr0O0PoUCdOEXwwv6KYY2+UnNymk9EMpnoJClARylwvOYnlj5UVZLTRvfwb/522hNRKZJjrLBJVDYoWS/hH6PxT5z6Ml6G7SWUDpjlwoRHhjzaWfNFLnd1+DdRmzKWohTaULWr6QGxprjQclskyRPQLkA7iDP7hMbMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=kontron.de; dmarc=pass action=none header.from=kontron.de; dkim=pass header.d=kontron.de; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mysnt.onmicrosoft.com; s=selector2-mysnt-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1CIqQn3J2Yj/xXQ81L9Gj1MFA95wy3V1a6NAU5TYmEQ=; b=dfS4XAolcCPTM4ZHcSVzVOJR3ttqRz57R5gGOtV86ZrhRpYodDDyaiHznvNOvUDddAKg1HiiRCCV9P1CfMOlxm+rBhusTD6JZDq6Od5+511e94kWB0IRl10yEVjp2INaoE01QcE0kkolmD3MDuXGgsoKW+h2o0B9S0xSGVH7cJc= Authentication-Results: walle.cc; dkim=none (message not signed) header.d=none;walle.cc; dmarc=none action=none header.from=kontron.de; Received: from AM0PR10MB2963.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:157::14) by AM0PR10MB2386.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:d4::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.22; Mon, 4 Oct 2021 10:31:42 +0000 Received: from AM0PR10MB2963.EURPRD10.PROD.OUTLOOK.COM ([fe80::216b:62be:3272:2560]) by AM0PR10MB2963.EURPRD10.PROD.OUTLOOK.COM ([fe80::216b:62be:3272:2560%6]) with mapi id 15.20.4566.022; Mon, 4 Oct 2021 10:31:42 +0000 Message-ID: Date: Mon, 4 Oct 2021 12:31:40 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Subject: Re: [PATCH] cmd: sf: Support unaligned flash updates with 'sf update' Content-Language: en-US To: Michael Walle Cc: Frieder Schrempf , u-boot@lists.denx.de, Heiko Thiery , Bin Meng , Jagan Teki , Pratyush Yadav , Sean Anderson , Simon Glass References: <20210930161926.2748887-1-frieder@fris.de> <92ca13e960f4e862c0fdd83373255301@walle.cc> <0b725bbb-0bc6-2ce3-d861-18bbd8f34059@kontron.de> From: Frieder Schrempf In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AS8PR04CA0162.eurprd04.prod.outlook.com (2603:10a6:20b:331::17) To AM0PR10MB2963.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:157::14) MIME-Version: 1.0 Received: from [192.168.103.172] (77.246.119.226) by AS8PR04CA0162.eurprd04.prod.outlook.com (2603:10a6:20b:331::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Mon, 4 Oct 2021 10:31:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0d15c2e2-9deb-427f-a8fe-08d9872227f7 X-MS-TrafficTypeDiagnostic: AM0PR10MB2386: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XZKI/yPeKM+G+v+/HpPGX+VsL3/UgYtDRfLRKwKX0uRHVUxG0AfEI4O/Yz9E75y8zLyIF1YlsPHL+4b8H0RiEpvydER8GVf2tqNB7CgJJ4bslohVdF0wXm3ZXUmPWVmQkwrU3C07vW7Th7v9nZ9Xa0fyWhpNCyKlSs+XL0+0FZ57s9afR3N+S+cvRPU2qwvyLRgilNcnPqAlDpwN+WEisDeW2Te50PfmVwxtewbeMzOzS7RLZsBEMY90sEug5wbGIg+swTxHmfx/thJX+FKsqrTVPXi8fzoNOqI5MLVnN1wDC5vDLKvvi2I+QDh9IeU6P7f8kRgm0JEnb+nWIOtt7pvPZ/Zh3iJbVK19Q/bDBJ1AFQzRyRIvsB7dkDx1OJJPPbx1fSq+W6UDYtbq+wqntD4W/LPRvm44yVJCGSLN0SMB8iLu6wXmCA24n4qVk0jy2LA8wrl0o7h8Y3zfD3E85Ou6xp9w+3feXvh+3JOZysOZQNPDCAp3aGetGyP/uOaIqj8+utJ1Bf6UwSXCZmlw//XkKR5dnNkJLIMJW+vLBGmwvfAmBujJf88dvH5o08/qsfGUsoMIi2lxcmhjR98qcJHp9mK7PzJeMjAQafqO3RMGB6VwEAHuSdJHwZM7w0xOpEwqmHjjqlGgaK0l+bAxkNA2HJBbs7Jt1bFjQ8i+LRMFeVI862X2yLY8LsRhs24zG39aPkUyVFmn/b9QO6L4LpFlEMteVFFc+NQnYUqZjR0= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR10MB2963.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(4636009)(366004)(26005)(83380400001)(36756003)(31686004)(66556008)(186003)(2616005)(53546011)(66476007)(66946007)(508600001)(4326008)(8936002)(6486002)(6916009)(86362001)(15650500001)(54906003)(44832011)(5660300002)(38100700002)(316002)(16576012)(8676002)(956004)(2906002)(31696002)(45980500001)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?cm1tUEgrd3FTa3RwYmdhZDdOYTNFZVRQejEyY2pYZmdSWDdXZDRrVmo2ZWZx?= =?utf-8?B?M29TT1MzZGI3WkNBVVdNaE5CWFRPLzdaSjNQNnVRcWtkaWRhWktYU09rVThI?= =?utf-8?B?T1FaWWJFR3AxeWoweUlhQUtRZlp2clhVVVFMTXpPd0VhTG12dk1tTTFoendL?= =?utf-8?B?QlBzYjhDWWJXaUlZMkgvTGpqcWhHM3ZoWFBUNW1zR1c2YU5aQytLTEoraFNl?= =?utf-8?B?bGpkYXJLelMxck1PMWRNQWpjMlg0S0Rrb3A3RzlodUgxRjNKRVV2N2N0dlFI?= =?utf-8?B?NWlLbFF4a2VEe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R6?= =?utf-8?B?aG9kM0FHQnl2N0JNV1djRngwYkw0YS9LcnFEYkFmd2VKdE1kS0JZQ2lMem1M?= =?utf-8?B?WTdMcU45RDVpVElDYU1OWmJHbk8zZENSRzl2ckZWRlp0L0pVd2txWmFZR0d3?= =?utf-8?B?c0dIcnptNFlpdVRFZHMrY1Excy9TemZ4RHZtWnlBK09VaTZ1T0E3ZkF3bnAx?= =?utf-8?B?U1gydU52R2FRL005Z25CUlloN3I0ejlJTXVGVFloWDFIMXVCVnV2eEJ0Skkr?= =?utf-8?B?aTN2UlVITUkxbC9oeGxyMjBGR3RjQVBOalhzTVlkMmxEeDBXNlBmZHc1dVJ0?= =?utf-8?B?dWVxUXpkZG9wUUZFbVFmbDlvMU8ycHFzdk44UXpXdzhCTXdoRDU3QWRoUnMv?= =?utf-8?B?U1dWRVByckkxak9rNjlJcXJGTmZYUEg1Zk1weld0N1pEeGtrL0IvTkVqK2N4?= =?utf-8?B?Y3dXb2swSHptaDFpN01zODFKQVcyQUJ6a0Mwc0JJNVMvSS94Qm4yV0d4VTlY?= =?utf-8?B?Q1gyV2p2bEY5SEw2VzYyOGlqNEErVnR2V1o0ZHNCUW5GVnRXcU5CazdIL2lo?= =?utf-8?Q?R6G8kCrZbE+4cUSllEaP2Kpn7glXwc1MyKfPuXz?= X-OriginatorOrg: kontron.de X-MS-Exchange-CrossTenant-Network-Message-Id: 0d15c2e2-9deb-427f-a8fe-08d9872227f7 X-MS-Exchange-CrossTenant-AuthSource: AM0PR10MB2963.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2021 10:31:42.3253 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8c9d3c97-3fd9-41c8-a2b1-646f3942daf1 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1u/iw+eqQaYB/GLunKSFxjs+XVXAL4r15VOSRR1zOmNomdyNWBcfv5m3kNRTqAmx3koB4MmHIeCd6heLv+Iazd0DKJSdJJYPE1uvd3Dj6Ng= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR10MB2386 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean On 30.09.21 23:08, Michael Walle wrote: > Am 2021-09-30 19:17, schrieb Frieder Schrempf: >> On 30.09.21 18:35, Michael Walle wrote: >>> Am 2021-09-30 18:19, schrieb Frieder Schrempf: >>>> In order to support unaligned updates, we simply read the first full >>>> block and check only the requested part of the block for changes. If >>>> necessary, the block is erased, the first (unchanged) part of the block >>>> is written back together with the second part of the block (updated >>>> data). >>> >>> I'm not sure what I should think of this. You might loose that unchanged >>> part if there is an power loss in the middle, even worse, you likely >>> don't >>> have this part anymore because it isn't part of the data you want to >>> write >>> to the flash. >>> >>> Maybe add an parameter for allow (unsafe) unaligned updates? >>> >>> Now you might argue, that with "sf erase, sf write" you can do the same >>> harm, to which i reply: but then it is intentional ;) Because "sf erase" >>> just works on sector boundaries (which isn't really checked in the >>> command, >>> i just realized, but at least my driver returns EINVAL) and then the >>> user has to include the "unchanged part" for the arguments on the >>> commandline. >> >> True, but "sf update" already is "unsafe" even without supporting >> unaligned start offsets. The code already handles partial sector writes >> for the last sector in the same way (read, erase, write), which is also >> prone to data loss in case of power loss. > > Ah, I missed that. Yes, in this case, we don't loose anything. Agreed. > >> So this patch in fact just adds support for partial sector updates for >> the first sector. It is slightly more probable to loose data, but it >> doesn't introduce new "unsafe" behavior. >> >> Maybe we could cover this by adding a warning to the documentation, or >> even printing a warning? > > Heh, although I was using "sf update" all the time, I wasn't aware of > the read - "partly modify" - write cycle. Maybe it's just me being > over cautious. > > Printing a warning might scare users, though. I'd prefer to fix the > online help, where only "erase and write" is mentioned. Which document are you referring to? I don't really see the "sf" command documented anywhere.