Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2197087/?format=api
{ "id": 2197087, "url": "http://patchwork.ozlabs.org/api/patches/2197087/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/20260217035643.2383088-1-varadarajan.narayanan@oss.qualcomm.com/", "project": { "id": 18, "url": "http://patchwork.ozlabs.org/api/projects/18/?format=api", "name": "U-Boot", "link_name": "uboot", "list_id": "u-boot.lists.denx.de", "list_email": "u-boot@lists.denx.de", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260217035643.2383088-1-varadarajan.narayanan@oss.qualcomm.com>", "list_archive_url": null, "date": "2026-02-17T03:56:43", "name": "fs: fat: Handle 'FAT sector size mismatch'", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "355bc51e80b3151112c4c1303fa777fd6c5916d2", "submitter": { "id": 92283, "url": "http://patchwork.ozlabs.org/api/people/92283/?format=api", "name": "Varadarajan Narayanan", "email": "varadarajan.narayanan@oss.qualcomm.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/uboot/patch/20260217035643.2383088-1-varadarajan.narayanan@oss.qualcomm.com/mbox/", "series": [ { "id": 492367, "url": "http://patchwork.ozlabs.org/api/series/492367/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=492367", "date": "2026-02-17T03:56:43", "name": "fs: fat: Handle 'FAT sector size mismatch'", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/492367/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2197087/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2197087/checks/", "tags": {}, "related": [], "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 (2048-bit key;\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=JL+By6Cr;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=jp9YoKQS;\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=none (p=none dis=none) header.from=oss.qualcomm.com", "phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de", "phobos.denx.de;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com\n header.b=\"JL+By6Cr\";\n\tdkim=pass (2048-bit key;\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.b=\"jp9YoKQS\";\n\tdkim-atps=neutral", "phobos.denx.de; dmarc=none (p=none dis=none)\n header.from=oss.qualcomm.com", "phobos.denx.de; spf=pass\n smtp.mailfrom=varadarajan.narayanan@oss.qualcomm.com" ], "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 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fFQnZ0c21z1xpl\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 17 Feb 2026 14:57:05 +1100 (AEDT)", "from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 99E5583AA9;\n\tTue, 17 Feb 2026 04:56:57 +0100 (CET)", "by phobos.denx.de (Postfix, from userid 109)\n id EDDDF83B8A; Tue, 17 Feb 2026 04:56:56 +0100 (CET)", "from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com\n [205.220.168.131])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id CAD9F83642\n for <u-boot@lists.denx.de>; Tue, 17 Feb 2026 04:56:52 +0100 (CET)", "from pps.filterd (m0279867.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 61GG1iGe048833\n for <u-boot@lists.denx.de>; Tue, 17 Feb 2026 03:56:51 GMT", "from mail-pl1-f199.google.com (mail-pl1-f199.google.com\n [209.85.214.199])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cc6d8154j-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <u-boot@lists.denx.de>; Tue, 17 Feb 2026 03:56:50 +0000 (GMT)", "by mail-pl1-f199.google.com with SMTP id\n d9443c01a7336-2aaf2ce5d81so45433685ad.1\n for <u-boot@lists.denx.de>; Mon, 16 Feb 2026 19:56:50 -0800 (PST)", "from hu-varada-blr.qualcomm.com\n (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19])\n by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2ad1aaeaa5bsm83180535ad.81.2026.02.16.19.56.46\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Mon, 16 Feb 2026 19:56:48 -0800 (PST)" ], "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,DKIM_SIGNED,\n DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,\n RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED,\n SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2", "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n cc:content-transfer-encoding:date:from:message-id:mime-version\n :subject:to; s=qcppdkim1; bh=IdfX1Oc7GL432U+hxn/TwiZvllP0ElxFiSk\n TkqA5dso=; b=JL+By6CriOjIiiJuQdnM1ZTCOXKtrpuvTljjtQtbkuAL1vOfNvV\n irFYUfF1TncLBkbHyqlKNJ6YORRVzhtRh0UelMN1MRYNxcO0oM//4gFvVXck4V6R\n ghXUhNRX49fBxUe3wtHMPzqqfrDyuR5odlimeopOr281pbbPwZLuAW4s1hY0lj99\n VefavEuI7eynb48ouzKBSPmZPaUDsbdKpRQkoCdoAU0qxNxDsNcYYcFNXJfW7CTm\n GqP8qIysgaayRZiB7httMay6y7911p9wUb/sDtv+1TwG/OJmvM/fleUujgxXPrq2\n E4BAg4/IA8xN3vafeojbLtnKwDbclsiAtrw==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1771300610; x=1771905410; darn=lists.denx.de;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:from:to:cc:subject:date:message-id:reply-to;\n bh=IdfX1Oc7GL432U+hxn/TwiZvllP0ElxFiSkTkqA5dso=;\n b=jp9YoKQSAwMhYU5k/477sjP/QYYaKIYMg6C97s3OtI51fLFX0mzNku8vpZQFt+4qoz\n uh4dEtvGKERAl0lraAc+HHxiQo0tE0tLPOBYLAbC2J3wNLzZoZSeg6eZ3kmuD5IG4gEL\n AOR4qwBCP+d01RfCdk/Jz1PUICLrRyYXei2cQugVrjUWbSZ0x+4Cq2taYiLf6hETWJ4t\n fi9hZJIOg+hjriqDyv/W5QYSBaaddECG1Ar7nGQp/ndxujyD8h3iZ5us0hNXUOvGy1lR\n McYTDP/7sB+wnyLcQHWcIa+gYga9TiL33ffXD8MFqD0L90b0quqtZeHFvVGZZZiBAkJo\n URRA==" ], "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1771300610; x=1771905410;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=IdfX1Oc7GL432U+hxn/TwiZvllP0ElxFiSkTkqA5dso=;\n b=gCQ2OFIUjowj7KoP3cnYV7jhtQgDLvr6CIPrxCwYAn5/n9YUMFNG+wn9a4m5bPpdJW\n VoLHczaZ1Jiy6i/+PfI67+lrMQnhFz2wXTUgAJ5XVIhFoF8eInn3WdQGegYfRBTXQ4XE\n aTozCXEly6n4C1c9PG0gCQIMTVs+DzPCVWWfnEB/hV5oEN1pg2JDp9ThHw0kfoO0yY5J\n 9W4hbLkxGrr7ng2/zLnUqsgsBpJ7VVclvz8x3Hy+4F5VdrLH+GuEqPAqL/mRMNqMnw1z\n hz3sJ5Ykz0iEjM7V4D+8AZeQze2Srl/DZ1NHvLBaFyKaEjjRsaNnfKkicbjztBwD9iRt\n cKaw==", "X-Forwarded-Encrypted": "i=1;\n AJvYcCXaKCCHJGgcvwGafGIQYoS1qt7AOhXdJ017ciOwtCErwZ8ZKsesVKEb1CTTt+5Mf4CuIf30gv0=@lists.denx.de", "X-Gm-Message-State": "AOJu0YwvJdqZ2PNjN4f85+R8YBWckEplSfPi6wnDHWd9wTN30TvSQ7Aw\n lvDtZOCWtAmUlc926cmjTHHhI7D22C5ELKipcfL6q9MBXaulUMOXDqwbZxOD43AKHRROs7ZM6br\n pM+hLm6ZZpPW2dDA6dSb2OFNtsNUpue8kNqHMT8rCRlS8zSOgEzs7PW82", "X-Gm-Gg": "AZuq6aLpSv/HcIl/YNBjB+SBdg1dg4HVppVrIkvtrsCA3UQWEjKG+83sOPCBqajolHh\n 2MOCLt/pSJ/zgXIJg5PV4FAoomvCXRkAL4xx0QLuOB3c4OfvKpLOZNxe4abpIZGMPTiwF+7Xb1v\n kfuU1iRwZvBZMKdROyybfW1gM7jxaw1sfLGeAKZ8gWJYanT+THQZN3KxM09OjqyWOlrYdoPiTit\n jDT7p1NnWVURKaMYk17hEPelcVPvnuQ+Y4avfu3StI89nOOOB9bpIIQjc7K4pXZEsQRDffXJep8\n T54aLBHfZC03Jjvgg3t3VmMU0UXvzSWK1y8oxtcsygkp5bWB0Dy2V7XVhAnzc2Q8+RE3rFrl5Xs\n O+DV1OW9zDNNWkjxRneaqoBimXv5ydXC2ffRkVLtWOUs8F2iQRlVLDm+ko/x7fqEuCyz01xfq8z\n 2C/+v/bvQBY61KDaOQf+N0++v5rq2RJKTYeZ9SpLXi1qTFf0r2Upw=", "X-Received": [ "by 2002:a17:903:1aa7:b0:2aa:e23c:2697 with SMTP id\n d9443c01a7336-2ad175b1491mr86922205ad.57.1771300609972;\n Mon, 16 Feb 2026 19:56:49 -0800 (PST)", "by 2002:a17:903:1aa7:b0:2aa:e23c:2697 with SMTP id\n d9443c01a7336-2ad175b1491mr86922035ad.57.1771300609422;\n Mon, 16 Feb 2026 19:56:49 -0800 (PST)" ], "From": "Varadarajan Narayanan <varadarajan.narayanan@oss.qualcomm.com>", "To": "trini@konsulko.com, gabriel.dalimonte@gmail.com, u-boot@lists.denx.de", "Cc": "caleb.connolly@linaro.org, balaji.selvanathan@oss.qualcomm.com,\n Varadarajan Narayanan <varadarajan.narayanan@oss.qualcomm.com>", "Subject": "[PATCH] fs: fat: Handle 'FAT sector size mismatch'", "Date": "Tue, 17 Feb 2026 09:26:43 +0530", "Message-Id": "<20260217035643.2383088-1-varadarajan.narayanan@oss.qualcomm.com>", "X-Mailer": "git-send-email 2.34.1", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-Authority-Analysis": "v=2.4 cv=bqVBxUai c=1 sm=1 tr=0 ts=6993e702 cx=c_pps\n a=JL+w9abYAAE89/QcEU+0QA==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17\n a=HzLeVaNsDn8A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22\n a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=5p_tG3gqAAAA:8\n a=NEAV23lmAAAA:8 a=YfCOm-DyAAAA:8 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8\n a=COk6AnOGAAAA:8 a=kvHvfpOrqeMORAa8gaAA:9 a=324X-CrmTo6CU4MGRt3R:22\n a=zQLMK8awuJ6_Hvp-_9Ux:22 a=TjNXssC_j7lpFel5tvFf:22", "X-Proofpoint-Spam-Details-Enc": "AW1haW4tMjYwMjE3MDAyOSBTYWx0ZWRfX5RO2Qhbdfj9Y\n xpdGX7C1xK5oCfLLsloOIo9QcAPODq1ZtLqGGJjC8OCTAAtsKMDLOqiVFCUBPfC5fGbojtF+mti\n u/PSPPOFu8vJjGBsDf30k5+jqd1Fb6kHhkq9REZbFvO4aq4raHf55mcN7tUVYVnyjLzGQyohpG6\n 9tYumzLgZIxsgk3fg5LUm/Yi/Yta3+2U2Kn+Y/H40T4xiOLMcKxeyEakCClUuuFAj96r+RPPlzn\n vlAMQc4vl4+NPg2MX0XKccLvJvjG9nBL0uOXqpLIqIdupKhq+W34CDA+WXfBgOka5wq8aN7mJfl\n NJdO+5QeutEI/5O3QYIaP/Y5LLg+Zq2CHwwy79RzNTnZaOJR8EbUiEOZ4HwSVmJ+1FplxdKPdpQ\n gDujxDBeJ7LMt9Xg3BsGaj+E61GgB/gWxIUhdZkLVZBP2UiqNnbVjLT49ZFrYQt6AAukniiBtVf\n 7rS6cliO5CCKmkUSQ1g==", "X-Proofpoint-GUID": "XF2j3RvdJ0ma0u41s9LUxVKiAtkcYD-p", "X-Proofpoint-ORIG-GUID": "XF2j3RvdJ0ma0u41s9LUxVKiAtkcYD-p", "X-Proofpoint-Virus-Version": "vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-02-16_08,2026-02-16_04,2025-10-01_01", "X-Proofpoint-Spam-Details": "rule=outbound_notspam policy=outbound score=0\n malwarescore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0\n priorityscore=1501 spamscore=0 adultscore=0 phishscore=0 clxscore=1015\n suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc=\n route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000\n definitions=main-2602170029", "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" }, "content": "Do FAT read and write based on the device sector size\ninstead of the size recorded in the FAT meta data.\n\nFAT code issues i/o in terms of the sector size. Convert that to\ndevice sector size before doing the actual i/o. Additionally,\nhandle leading/trailing blocks when the meta data based block\nno and i/o size is not an exact multiple of the device sector\nsize or vice versa.\n\nTested on UFS device with sector size 4096 and meta data recorded\nsector size 512.\n\nSigned-off-by: Varadarajan Narayanan <varadarajan.narayanan@oss.qualcomm.com>\n---\nChanges in v5:\n- Fix CI error reported in https://dev.azure.com/u-boot/u-boot/_build/results?buildId=12821&view=logs&j=a007cd84-3be0-5a02-8a7a-a34fb3052485&t=216c79d4-eaff-5600-0b8f-3a63c01a45d6\n- All CI tests passed. (Please see https://github.com/u-boot/u-boot/pull/868)\n- U-boot SPL for (am335x_evm, am335x_hs_evm, am335x_hs_evm_spi) includes the\n FAT driver. The additional checks done in this patch resulted in increased\n code size causing it to overshoot the '.sram' area.\n- Address this by using the existing disk_read & disk_write routines for\n SPL.\n- Also bail out in case of sector size mismatch for SPL\n\nChanges in v4:\n- Fix clang warning reported in https://source.denx.de/u-boot/u-boot/-/jobs/1365316\n- Remove unused function 'size_to_blocks()'\n- Triggered CI, it fails with this error https://dev.azure.com/u-boot/u-boot/_build/results?buildId=12817&view=logs&j=a007cd84-3be0-5a02-8a7a-a34fb3052485&t=216c79d4-eaff-5600-0b8f-3a63c01a45d6&l=405. But that seems to be seen on top-of-tree without this change also.\n- Link to v3: https://lore.kernel.org/u-boot/20260122063442.2622684-1-balaji.selvanathan@oss.qualcomm.com/\n\nChanges in v3:\n- Respin, no changes\n- Link to v2: https://lore.kernel.org/u-boot/20241125085213.460723-1-quic_varada@quicinc.com/\n\nChanges in v2:\n- fat_sect_size is declared as static\n- The else block in disk_write() function has been removed\n- The commit message has additional details about testing\n- Link to v1: https://lore.kernel.org/u-boot/20241119073048.3469260-1-quic_varada@quicinc.com/\n---\n fs/fat/fat.c | 210 ++++++++++++++++++++++++++++++++++++++++++++-\n fs/fat/fat_write.c | 2 +\n 2 files changed, 210 insertions(+), 2 deletions(-)", "diff": "diff --git a/fs/fat/fat.c b/fs/fat/fat.c\nindex 9ce5df59f9b..a725d924fd9 100644\n--- a/fs/fat/fat.c\n+++ b/fs/fat/fat.c\n@@ -45,11 +45,13 @@ static void downcase(char *str, size_t len)\n \n static struct blk_desc *cur_dev;\n static struct disk_partition cur_part_info;\n+static int fat_sect_size;\n \n #define DOS_BOOT_MAGIC_OFFSET\t0x1fe\n #define DOS_FS_TYPE_OFFSET\t0x36\n #define DOS_FS32_TYPE_OFFSET\t0x52\n \n+#if IS_ENABLED(CONFIG_SPL_FS_FAT)\n static int disk_read(__u32 block, __u32 nr_blocks, void *buf)\n {\n \tulong ret;\n@@ -64,6 +66,206 @@ static int disk_read(__u32 block, __u32 nr_blocks, void *buf)\n \n \treturn ret;\n }\n+#else\n+static inline __u32 sect_to_block(__u32 sect, __u32 *off)\n+{\n+\t*off = 0;\n+\tif (fat_sect_size && fat_sect_size < cur_part_info.blksz) {\n+\t\tint div = cur_part_info.blksz / fat_sect_size;\n+\n+\t\t*off = sect % div;\n+\t\treturn sect / div;\n+\t} else if (fat_sect_size && (fat_sect_size > cur_part_info.blksz)) {\n+\t\treturn sect * (fat_sect_size / cur_part_info.blksz);\n+\t}\n+\n+\treturn sect;\n+}\n+\n+static int disk_read(__u32 sect, __u32 nr_sect, void *buf)\n+{\n+\tint ret;\n+\t__u8 *block = NULL;\n+\t__u32 rem, size;\n+\t__u32 s, n;\n+\n+\trem = nr_sect * fat_sect_size;\n+\t/*\n+\t * block N block N + 1 block N + 2\n+\t * +-+-+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n+\t * | | | | |s|e|c|t|o|r| | |s|e|c|t|o|r| | |s|e|c|t|o|r| | | | |\n+\t * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n+\t * . . . | | | | . . .\n+\t * ------+---------------+---------------+---------------+------\n+\t * |<--- FAT reads in sectors --->|\n+\t *\n+\t * | part 1 | part 2 | part 3 |\n+\t *\n+\t */\n+\n+\t/* Do part 1 */\n+\tif (fat_sect_size) {\n+\t\t__u32 offset;\n+\n+\t\t/* Read one block and copy out the leading sectors */\n+\t\tblock = malloc_cache_aligned(cur_dev->blksz);\n+\t\tif (!block) {\n+\t\t\tprintf(\"Error: allocating block: %lu\\n\", cur_dev->blksz);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\ts = sect_to_block(sect, &offset);\n+\t\toffset = offset * fat_sect_size;\n+\n+\t\tret = blk_dread(cur_dev, cur_part_info.start + s, 1, block);\n+\t\tif (ret != 1) {\n+\t\t\tret = -1;\n+\t\t\tgoto exit;\n+\t\t}\n+\n+\t\tif (rem > (cur_part_info.blksz - offset))\n+\t\t\tsize = cur_part_info.blksz - offset;\n+\t\telse\n+\t\t\tsize = rem;\n+\n+\t\tmemcpy(buf, block + offset, size);\n+\t\trem -= size;\n+\t\tbuf += size;\n+\t\ts++;\n+\t} else {\n+\t\t/*\n+\t\t * fat_sect_size not being set implies, this is the first read\n+\t\t * to partition. The first sector is being read to get the\n+\t\t * FS meta data. The FAT sector size is got from this meta data.\n+\t\t */\n+\t\tret = blk_dread(cur_dev, cur_part_info.start + s, 1, buf);\n+\t\tif (ret != 1)\n+\t\t\treturn -1;\n+\t}\n+\n+\t/* Do part 2, read directly into the given buffer */\n+\tif (rem > cur_part_info.blksz) {\n+\t\tn = rem / cur_part_info.blksz;\n+\t\tret = blk_dread(cur_dev, cur_part_info.start + s, n, buf);\n+\t\tif (ret != n) {\n+\t\t\tret = -1;\n+\t\t\tgoto exit;\n+\t\t}\n+\t\tbuf += n * cur_part_info.blksz;\n+\t\trem = rem % cur_part_info.blksz;\n+\t\ts += n;\n+\t}\n+\n+\t/* Do part 3, read a block and copy the trailing sectors */\n+\tif (rem) {\n+\t\tret = blk_dread(cur_dev, cur_part_info.start + s, 1, block);\n+\t\tif (ret != 1) {\n+\t\t\tret = -1;\n+\t\t\tgoto exit;\n+\t\t} else {\n+\t\t\tmemcpy(buf, block, rem);\n+\t\t}\n+\t}\n+exit:\n+\tif (block)\n+\t\tfree(block);\n+\n+\treturn (ret == -1) ? -1 : nr_sect;\n+}\n+\n+int disk_write(__u32 sect, __u32 nr_sect, void *buf)\n+{\n+\tint ret;\n+\t__u8 *block = NULL;\n+\t__u32 rem, size;\n+\t__u32 s, n;\n+\n+\trem = nr_sect * fat_sect_size;\n+\t/*\n+\t * block N block N + 1 block N + 2\n+\t * +-+-+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n+\t * | | | | |s|e|c|t|o|r| | |s|e|c|t|o|r| | |s|e|c|t|o|r| | | | |\n+\t * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n+\t * . . . | | | | . . .\n+\t * ------+---------------+---------------+---------------+------\n+\t * |<--- FAT reads in sectors --->|\n+\t *\n+\t * | part 1 | part 2 | part 3 |\n+\t *\n+\t */\n+\n+\t/* Do part 1 */\n+\tif (fat_sect_size) {\n+\t\t__u32 offset;\n+\n+\t\t/* Read one block and overwrite the leading sectors */\n+\t\tblock = malloc_cache_aligned(cur_dev->blksz);\n+\t\tif (!block) {\n+\t\t\tprintf(\"Error: allocating block: %lu\\n\", cur_dev->blksz);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\ts = sect_to_block(sect, &offset);\n+\t\toffset = offset * fat_sect_size;\n+\n+\t\tret = blk_dread(cur_dev, cur_part_info.start + s, 1, block);\n+\t\tif (ret != 1) {\n+\t\t\tret = -1;\n+\t\t\tgoto exit;\n+\t\t}\n+\n+\t\tif (rem > (cur_part_info.blksz - offset))\n+\t\t\tsize = cur_part_info.blksz - offset;\n+\t\telse\n+\t\t\tsize = rem;\n+\n+\t\tmemcpy(block + offset, buf, size);\n+\t\tret = blk_dwrite(cur_dev, cur_part_info.start + s, 1, block);\n+\t\tif (ret != 1) {\n+\t\t\tret = -1;\n+\t\t\tgoto exit;\n+\t\t}\n+\n+\t\trem -= size;\n+\t\tbuf += size;\n+\t\ts++;\n+\t}\n+\n+\t/* Do part 2, write directly from the given buffer */\n+\tif (rem > cur_part_info.blksz) {\n+\t\tn = rem / cur_part_info.blksz;\n+\t\tret = blk_dwrite(cur_dev, cur_part_info.start + s, n, buf);\n+\t\tif (ret != n) {\n+\t\t\tret = -1;\n+\t\t\tgoto exit;\n+\t\t}\n+\t\tbuf += n * cur_part_info.blksz;\n+\t\trem = rem % cur_part_info.blksz;\n+\t\ts += n;\n+\t}\n+\n+\t/* Do part 3, read a block and copy the trailing sectors */\n+\tif (rem) {\n+\t\tret = blk_dread(cur_dev, cur_part_info.start + s, 1, block);\n+\t\tif (ret != 1) {\n+\t\t\tret = -1;\n+\t\t\tgoto exit;\n+\t\t} else {\n+\t\t\tmemcpy(block, buf, rem);\n+\t\t}\n+\t\tret = blk_dwrite(cur_dev, cur_part_info.start + s, 1, block);\n+\t\tif (ret != 1) {\n+\t\t\tret = -1;\n+\t\t\tgoto exit;\n+\t\t}\n+\t}\n+exit:\n+\tif (block)\n+\t\tfree(block);\n+\n+\treturn (ret == -1) ? -1 : nr_sect;\n+}\n+#endif /* CONFIG_SPL_FS_FAT */\n \n int fat_set_blk_dev(struct blk_desc *dev_desc, struct disk_partition *info)\n {\n@@ -581,6 +783,7 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize)\n \t\treturn -1;\n \t}\n \n+\tfat_sect_size = 0;\n \tif (disk_read(0, 1, block) < 0) {\n \t\tdebug(\"Error: reading block\\n\");\n \t\tret = -1;\n@@ -651,11 +854,14 @@ static int get_fs_info(fsdata *mydata)\n \tmydata->rootdir_sect = mydata->fat_sect + mydata->fatlength * bs.fats;\n \n \tmydata->sect_size = get_unaligned_le16(bs.sector_size);\n+\tfat_sect_size = mydata->sect_size;\n \tmydata->clust_size = bs.cluster_size;\n \tif (mydata->sect_size != cur_part_info.blksz) {\n-\t\tlog_err(\"FAT sector size mismatch (fs=%u, dev=%lu)\\n\",\n-\t\t\tmydata->sect_size, cur_part_info.blksz);\n+\t\tlog_info(\"FAT sector size mismatch (fs=%u, dev=%lu)\\n\",\n+\t\t\t mydata->sect_size, cur_part_info.blksz);\n+#if IS_ENABLED(CONFIG_SPL_FS_FAT)\n \t\treturn -1;\n+#endif\n \t}\n \tif (mydata->clust_size == 0) {\n \t\tlog_err(\"FAT cluster size not set\\n\");\ndiff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c\nindex 0b924541187..86132a9177c 100644\n--- a/fs/fat/fat_write.c\n+++ b/fs/fat/fat_write.c\n@@ -192,6 +192,7 @@ out:\n }\n \n static int total_sector;\n+#if IS_ENABLED(CONFIG_SPL_FS_FAT)\n static int disk_write(__u32 block, __u32 nr_blocks, void *buf)\n {\n \tulong ret;\n@@ -211,6 +212,7 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf)\n \n \treturn ret;\n }\n+#endif /* CONFIG_SPL_FS_FAT */\n \n /*\n * Write fat buffer into block device\n", "prefixes": [] }