Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2225022/?format=api
{ "id": 2225022, "url": "http://patchwork.ozlabs.org/api/patches/2225022/?format=api", "web_url": "http://patchwork.ozlabs.org/project/swupdate/patch/20260420094516.96381-1-stefano.babic@swupdate.org/", "project": { "id": 58, "url": "http://patchwork.ozlabs.org/api/projects/58/?format=api", "name": "swupdate development", "link_name": "swupdate", "list_id": "swupdate.googlegroups.com", "list_email": "swupdate@googlegroups.com", "web_url": "https://github.com/sbabic/swupdate", "scm_url": "git://github.com/sbabic/swupdate", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260420094516.96381-1-stefano.babic@swupdate.org>", "list_archive_url": null, "date": "2026-04-20T09:45:16", "name": "flash: fix writing at a specific offset", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "1b694ed74b51de757116e073227238d11d8a8d07", "submitter": { "id": 86869, "url": "http://patchwork.ozlabs.org/api/people/86869/?format=api", "name": "Stefano Babic", "email": "stefano.babic@swupdate.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/swupdate/patch/20260420094516.96381-1-stefano.babic@swupdate.org/mbox/", "series": [ { "id": 500576, "url": "http://patchwork.ozlabs.org/api/series/500576/?format=api", "web_url": "http://patchwork.ozlabs.org/project/swupdate/list/?series=500576", "date": "2026-04-20T09:45:16", "name": "flash: fix writing at a specific offset", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/500576/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2225022/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2225022/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<swupdate+bncBD2ZDGN6SEKRBMPLS7HQMGQEFYDX6BY@googlegroups.com>", "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=googlegroups.com header.i=@googlegroups.com\n header.a=rsa-sha256 header.s=20251104 header.b=qtuuZOPL;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com\n (client-ip=2a00:1450:4864:20::338; helo=mail-wm1-x338.google.com;\n envelope-from=swupdate+bncbd2zdgn6sekrbmpls7hqmgqefydx6by@googlegroups.com;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from mail-wm1-x338.google.com (mail-wm1-x338.google.com\n [IPv6:2a00:1450:4864:20::338])\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 4fzgb24b43z1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 19:45:33 +1000 (AEST)", "by mail-wm1-x338.google.com with SMTP id\n 5b1f17b1804b1-488c213b485sf24902625e9.2\n for <incoming@patchwork.ozlabs.org>;\n Mon, 20 Apr 2026 02:45:33 -0700 (PDT)", "by 2002:a05:600c:5254:b0:483:7631:bef7 with SMTP id\n 5b1f17b1804b1-488f4b18c95ls38980065e9.2.-pod-prod-08-eu; Mon, 20 Apr 2026\n 02:45:20 -0700 (PDT)", "from mout.kundenserver.de (mout.kundenserver.de. [217.72.192.74])\n by gmr-mx.google.com with ESMTPS id\n 5b1f17b1804b1-4891cd4cbdbsi439645e9.2.2026.04.20.02.45.19\n for <swupdate@googlegroups.com>\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Mon, 20 Apr 2026 02:45:19 -0700 (PDT)", "from client.hidden.invalid by mrelayeu.kundenserver.de (mreue109\n [212.227.15.153]) with ESMTPSA (Nemesis) id 1N5G1T-1vDXiM2Az7-015EKd; Mon, 20\n Apr 2026 11:45:19 +0200" ], "ARC-Seal": [ "i=2; a=rsa-sha256; t=1776678326; cv=pass;\n d=google.com; s=arc-20240605;\n b=ShdSj+ipj7oHdNrKNGztP5/GlK4JhNoAqGVnx1ijYeX0Wg6ARuiWF6buNJ5lFOf4aa\n sW2+pI0+aWLWE0CF6ynk1MAdRZXKh1wfVBkdZF4qXO/JAVOAL4gSkgxEE8CtGy3eKjpI\n uSRr0r48F4J5wgpd+HlvP6uoQyjUoYs7UA1n5ctHORYL/fiDsA1j+dR6cG5ZVxi7ryd4\n 9FEd8+2ZCm5CrzPGgX8e8WbEC7UDcs33TXb34vyxMr5gtr/5Yk5juGWUDegsTgaepBj8\n 4b+jftCVEx3zkzxYlItwh3EKKwu855dh0UwDdE17reoNOWNiLvp5iR/FBkkp4Uw/OrmA\n 0c7Q==", "i=1; a=rsa-sha256; t=1776678320; cv=none;\n d=google.com; s=arc-20240605;\n b=iP6vB1QGXBmd40GTM7AQvSsGBOvoaSh/jCZxgtUnmvl2wavyjHNpxmP6Y1rxffc9f4\n phmFsQ95zcO5Wj1huWMHIb1LqSMg45N/4lnplliPWLgKj/2l6RTb7yoxNJbb6RxAx24u\n hlaZnIRB/i2eNiXjmsZEVB8Zjd2+8WUmAzT1r0X5hzDkJ2BsMYwqAuZmBGNKjDIIbTfw\n Lho152b5cVvG/KWQDoGTj4isSxjY5idifgV4dEDUJVUH0pP908EX4ifWXMfJ3oGlOKZZ\n +9EhP/siAXO7D+1ow+rkmQoUIU/E/OzglpGpQD9/PBgAx71EZF3w1X8EWD8F+1/l97Oa\n gyLQ==" ], "ARC-Message-Signature": [ "i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post\n :list-id:mailing-list:precedence:ui-outboundreport:mime-version\n :message-id:date:subject:cc:to:from:sender:dkim-signature;\n bh=UD9olZx5BV0Soud2GKiRBgM07cN/mQQQ9hTUb/AL49c=;\n fh=0EWDmnSXkf2jVV4cVA02e/KrGPrCSwqjwRT0/MmX1Hw=;\n b=UDagfjLvzeffhZHYwsLyDyZguHGSngceYeK96+tXuIHEbxqQFatxnXxUBL26cOVhAv\n uD3EZzuggeBBu8qYpWfcNCbToOtYrRev83j+NMj2oPTaCEbvnFi4N8T9G0ijV3XCU96c\n u8ML3cZ3MiV+2q9jpmdomj6kMKHyiJH/SUFyIIk1fa+p3BVFbJ+KYFJsoDhALZNfPGHR\n Sx5R2uzxWZ6Z8rdgusvs9T6pObWvOwJ+xQEztgaST8lBdbAh/v+uGXQZBWzhtaXoNeOY\n Pdk63oN4LdrhMmycPPWhRfYfy6kgIXjSB6n8CnHCH/LqxBJKdlxtAQNXhsBlqyCL/4D7\n cdFg==;\n darn=patchwork.ozlabs.org", "i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=ui-outboundreport:content-transfer-encoding:mime-version:message-id\n :date:subject:cc:to:from:dkim-signature;\n bh=zzL5YsfmeeEMec6oQWH8xkBiZjo4UgD0suJNBlK0Q2Q=;\n fh=TiEWcqMcKpHk5s7uErzpntoONrNfOXwKpI5P8bIlggk=;\n b=FLxuLvaDTqgOAGc9MmIyGEkIt0kW+yqGsmE4Yf2mV+tXOIZfWG4Ib9+VCef1hHl2eb\n YeVKYqdsvFwOam8fVuXA0Z8iMVONEg3isNIAwj410QFqF0myr6NF36X8di6LLv3CBIiw\n UmopXj/xlCcd4ZUnTszNRpa8G/+Dm76secyX7oMoQflNA9l+K9Z/ADZsFMT2KodIsSNH\n 9KtiwEInvW15XwCIUmlool9IOjETRVi8SAQSuI9bN2YYHlAC8zurU0DaQG/k7thELUCV\n mAYT6kbmZCj9NgR5BhJfcabxytJelJeyhrYxAg4EaaJTaAXJonf39vnS3XEnUaf5BWpV\n Qm8Q==;\n dara=google.com" ], "ARC-Authentication-Results": [ "i=2; gmr-mx.google.com;\n dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=tnHonOt1;\n spf=pass (google.com: domain of stefano.babic@swupdate.org designates\n 217.72.192.74 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org;\n dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=swupdate.org", "i=1; gmr-mx.google.com;\n dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=tnHonOt1;\n spf=pass (google.com: domain of stefano.babic@swupdate.org designates\n 217.72.192.74 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org;\n dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=swupdate.org" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=googlegroups.com; s=20251104; t=1776678326; x=1777283126;\n darn=patchwork.ozlabs.org;\n h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post\n :list-id:mailing-list:precedence:x-original-authentication-results\n :x-original-sender:ui-outboundreport:mime-version:message-id:date\n :subject:cc:to:from:sender:from:to:cc:subject:date:message-id\n :reply-to;\n bh=UD9olZx5BV0Soud2GKiRBgM07cN/mQQQ9hTUb/AL49c=;\n b=qtuuZOPLZa2cLCkK0uUKSlF9cRU3GDKupZ4BFwdesKPNHX4PWMRJMd7KnDTezD090/\n /mBmMQZHPwAikaf1PaID77Voa3hoXaK6VcpuJ51OCuZNRZK7nEN1OamEB0Y6hv6DzHbS\n gQivd+5CXFqb0pvqf6ZaXmljx3pi0MT3Nls1Ogj5SLWNKrPodxEu/SbWdAXt4Vs/lScP\n BoMlbYS/4Q36Fk/T8GjAAxNOxDDfHZmU2zmALlzLQMpY5+j2QSO/DYnjx9ywNSJRZle/\n GEGq60v5CNN80ftcBwdv2y++e7XF/orb9N5t6bDUTVxDRqC7pPCM/SBqz9Usm1yK2j0u\n PcMg==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776678326; x=1777283126;\n h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post\n :x-spam-checked-in-group:list-id:mailing-list:precedence\n :x-original-authentication-results:x-original-sender\n :ui-outboundreport:mime-version:message-id:date:subject:cc:to:from\n :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date\n :message-id:reply-to;\n bh=UD9olZx5BV0Soud2GKiRBgM07cN/mQQQ9hTUb/AL49c=;\n b=S9zeDxe/ltL56HVt0W7KTF4optqXP5Jm4u00cHC78fj4+VC/3w5BP/d6gMIKIb5bK3\n hJwWWl2pcfK9p1hrJMjV/Zry7lDWklXSP1P0Hp4bRH2H2ELNsbfIIwHT6BSmvKUL09GN\n sBsiztcav4/dKoh5z+pPHC0h9dWiYCdys3sK/Z0OuDlPPeIqqxpmpV+siiGeraWRBKee\n +VBpcfzdttoqFkdLZaoX+Z5Ak6zpVdDMvN47kdEMZFHV4YqCGfsZHibmwlKcl7m6Iijr\n BZc3d9bOqG2TThDIg7QVF5uBCyK2E5Ktz3Ot3/ZO7SqgXcZWVjYXm6+zmjF6isVw1ilg\n wmcw==", "Sender": "swupdate@googlegroups.com", "X-Forwarded-Encrypted": "i=2;\n AFNElJ9N6lBvLArD3nJz0pq6+/Rpt93SJxh+CjFkkWw+0Cp/njst3rvJo9/1PI572N6UCUAYqJO9rQVSuA==@patchwork.ozlabs.org", "X-Gm-Message-State": "AOJu0Yw99pG6ap434Bq4etUWReje3KPmnoqS02wlN3NWAyHpbLsypkcR\n\tv9yNY17raUODQBilzmsf/TgydG+TY/rnhPv3ZW8EAFCsi8qQtJqTmoG+", "X-Received": [ "by 2002:a05:600c:4e4f:b0:488:ab37:b442 with SMTP id\n 5b1f17b1804b1-488fb793c6bmr187663715e9.28.1776678325429;\n Mon, 20 Apr 2026 02:45:25 -0700 (PDT)", "by 2002:a05:600c:3e1a:b0:489:1ca2:eafd with SMTP id\n 5b1f17b1804b1-4891ca2ee65mr44303785e9.11.1776678320070;\n Mon, 20 Apr 2026 02:45:20 -0700 (PDT)" ], "X-BeenThere": "swupdate@googlegroups.com;\n h=\"AYAyTiK+FRZFEoFpoSaw4pLdw9HMO6QPeWQp70BW4dmKQNZDAQ==\"", "Received-SPF": "pass (google.com: domain of stefano.babic@swupdate.org\n designates 217.72.192.74 as permitted sender) client-ip=217.72.192.74;", "X-UI-Sender-Class": "55c96926-9e95-11ee-ae09-1f7a4046a0f6", "From": "Stefano Babic <stefano.babic@swupdate.org>", "To": "swupdate@googlegroups.com", "Cc": "Stefano Babic <stefano.babic@swupdate.org>", "Subject": "[swupdate] [PATCH] flash: fix writing at a specific offset", "Date": "Mon, 20 Apr 2026 11:45:16 +0200", "Message-ID": "<20260420094516.96381-1-stefano.babic@swupdate.org>", "X-Mailer": "git-send-email 2.43.0", "MIME-Version": "1.0", "X-Provags-ID": "V03:K1:hxNBVUwgv0rEstqLWD3p4FMlsxjIeBWIZ0yrFWCEisqsq9NJtfh\n qILGw3vWZk5buDRZ/iezha8ROrY36X9aWhK6KR6yfOLkZ70xplnChfHlwDmIaXLHn4gdX4P\n SCHjzWrphkKyFZwINvMkMjwfsQxgHThU/M3XOSEGGlQnpNYvGEGKARERPrMXt0HeG/Xa7W/\n /hIIfozrwXzMQIA4it5oQ==", "X-Spam-Flag": "NO", "UI-OutboundReport": "notjunk:1;M01:P0:3xhYrTqngo8=;TsPjJMiL4X2bzxdOIF9MqYGtzeX\n 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", "X-Original-Sender": "stefano.babic@swupdate.org", "X-Original-Authentication-Results": "gmr-mx.google.com; dkim=pass\n header.i=@swupdate.org header.s=s1-ionos header.b=tnHonOt1; spf=pass\n (google.com: domain of stefano.babic@swupdate.org designates 217.72.192.74 as\n permitted sender) smtp.mailfrom=stefano.babic@swupdate.org; dmarc=pass\n (p=NONE sp=NONE dis=NONE) header.from=swupdate.org", "Content-Type": "text/plain; charset=\"UTF-8\"", "Precedence": "list", "Mailing-list": "list swupdate@googlegroups.com;\n contact swupdate+owners@googlegroups.com", "List-ID": "<swupdate.googlegroups.com>", "X-Spam-Checked-In-Group": "swupdate@googlegroups.com", "X-Google-Group-Id": "605343134186", "List-Post": "<https://groups.google.com/group/swupdate/post>,\n <mailto:swupdate@googlegroups.com>", "List-Help": "<https://groups.google.com/support/>,\n <mailto:swupdate+help@googlegroups.com>", "List-Archive": "<https://groups.google.com/group/swupdate", "List-Subscribe": "<https://groups.google.com/group/swupdate/subscribe>,\n <mailto:swupdate+subscribe@googlegroups.com>", "List-Unsubscribe": "\n <mailto:googlegroups-manage+605343134186+unsubscribe@googlegroups.com>,\n <https://groups.google.com/group/swupdate/subscribe>" }, "content": "Writing with an offset was supported until 3f230e0e30, but\ndata between start of sector and offset were lost. The commit above adds\nsupport to make NAND flash streamable, but remove the possibility to\nwrite flash at a specific offset. This cause a regression because many\nSOCs require that the bootloader is stored at a specific address that is\nnot aligned with the sector erase address.\n\nRemoving the check is not enough, and the patch will improve as:\n\n- detect if offset is not aligned\n- read all data between start of sector and required offset in the first\n write\n- write back the new data after erasing sector, this preserve the data\n before the offset.\n\nSigned-off-by: Stefano Babic <stefano.babic@swupdate.org>\n---\n handlers/flash_handler.c | 65 +++++++++++++++++++++++++++++++++++-----\n 1 file changed, 57 insertions(+), 8 deletions(-)", "diff": "diff --git a/handlers/flash_handler.c b/handlers/flash_handler.c\nindex 4bfe8bb3..53e41032 100644\n--- a/handlers/flash_handler.c\n+++ b/handlers/flash_handler.c\n@@ -113,6 +113,10 @@ struct flash_priv {\n \tint filebuf_len;\n \t/* An offset within the erase block (data bytes) to write from: */\n \tint writebuf_offset;\n+\t/* Start offset (it is img->seek) */\n+\toff_t start_offset;\n+\t/* Detect if this is first run to handle start_offset */\n+\tbool first_run;\n \t/* Current flash erase block: */\n \tint eb;\n \t/*\n@@ -391,7 +395,54 @@ static int flash_write(void *out, const void *buf, size_t len)\n {\n \tint ret;\n \tstruct flash_priv *priv = (struct flash_priv *)out;\n-\tconst unsigned char **pbuf = (const unsigned char**)&buf;\n+\tconst unsigned char **pbuf = NULL;\n+\tvoid *rdbuf = NULL;\n+\n+\t/* \n+\t * If we want to write to an offset not aligned\n+\t * with sectore, create a new buffer by reading data from the device\n+\t * until the offset and concatenate with the received data\n+\t * to get again data aligned with sector start.\n+\t */\n+\tif (priv->first_run) {\n+\t\t/*\n+\t\t * Check if offset is not aligned with sector\n+\t\t */\n+\t\tif (priv->start_offset & (priv->mtd->eb_size - 1)) {\n+\t\t\tint rdlen = priv->start_offset % priv->mtd->eb_size;\n+\t\t\tunsigned char *read_modify_buf = (unsigned char *)malloc(rdlen + len);\n+\t\t\tif (!read_modify_buf) {\n+\t\t\t\tERROR(\"OOM to allocate %lu bytes of memory\", rdlen + len);\n+\t\t\t\treturn -ENOMEM;\n+\t\t\t}\n+\t\t\trdbuf = read_modify_buf;\n+\t\t\t/* We can use fdout because we have not yet written into it */\n+\t\t\tif (lseek(priv->fdout, priv->mtd->eb_size * priv->eb, SEEK_SET) < 0) {\n+\t\t\t\tERROR(\"lseek error by resetting MTD file descriptor\");\n+\t\t\t\tfree(read_modify_buf);\n+\t\t\t\treturn -EIO;\n+\t\t\t}\n+\t\t\tret = read(priv->fdout, read_modify_buf, rdlen);\n+\t\t\tif (ret < 0) {\n+\t\t\t\tERROR(\"Cannot read back from mtd%d\", priv->mtdnum);\n+\t\t\t\tfree(read_modify_buf);\n+\t\t\t\treturn -EIO;\n+\t\t\t}\n+\t\t\tif (lseek(priv->fdout, 0, SEEK_SET) < 0) {\n+\t\t\t\tERROR(\"lseek error by resetting MTD file descriptor\");\n+\t\t\t\tfree(read_modify_buf);\n+\t\t\t\treturn -EIO;\n+\t\t\t}\n+\t\t\t/*\n+\t\t\t * Concatenate the data\n+\t\t\t */\n+\t\t\tmemcpy(&read_modify_buf[rdlen], buf, len);\n+\t\t\tpbuf = (const unsigned char**)&read_modify_buf;\n+\t\t\tlen += rdlen;\n+\t\t\tpriv->first_run = false;\n+\t\t}\n+\t} else\n+\t\tpbuf = (const unsigned char**)&buf;\n \n \twhile ((len > 0) || flash_has_pending_data(priv)) {\n \t\tunsigned char *wbuf;\n@@ -467,6 +518,9 @@ static int flash_write(void *out, const void *buf, size_t len)\n \t\t}\n \t}\n \n+\tif (rdbuf) {\n+\t\tfree(rdbuf);\n+\t}\n \treturn 0;\n }\n \n@@ -509,13 +563,6 @@ static int flash_write_image(int mtdnum, struct img_type *img)\n \t\treturn -ENODEV;\n \t}\n \n-\tif (img->seek & (priv.mtd->eb_size - 1)) {\n-\t\tERROR(\"The start address is not erase-block-aligned!\\n\"\n-\t\t \"The erase block of this flash is 0x%x.\\n\",\n-\t\t priv.mtd->eb_size);\n-\t\treturn -EINVAL;\n-\t}\n-\n \tpriv.imglen = get_output_size(img, true);\n \tif (priv.imglen < 0) {\n \t\tWARN(\"Failed to determine output size, getting MTD size.\");\n@@ -562,9 +609,11 @@ static int flash_write_image(int mtdnum, struct img_type *img)\n \tpriv.filebuf_len = 0;\n \tpriv.writebuf_offset = 0;\n \tpriv.eb = (int)(img->seek / priv.mtd->eb_size);\n+\tpriv.start_offset = img->seek;\n \tpriv.eb_end = (int)(priv.mtd->size / priv.mtd->eb_size);\n \tpriv.check_bad = true;\n \tpriv.check_locked = true;\n+\tpriv.first_run = true;\n \n \tret = priv.filebuf_size;\n \tif (!priv.is_nand)\n", "prefixes": [] }