From nobody Sat Sep 26 04:01:47 2026 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 736CC4229B0 for ; Fri, 4 Sep 2026 21:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788557020; cv=none; b=C6OqHCvlY+sAq/r3H4Lk6BJYy0/8T8iwC/nD4PeI6bzlXMh1WwfCEswSO/HnILFGvbDbshbajsNs+wGKvYWvOzKAIgimmJuB930Dcm2nSzQXsU8I3Ifq6d6IZ1Iz5tSs7bhyR83g1IQD0Ca9g4nf7zjz21Jnt2Tg0X/GQmI4kqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788557020; c=relaxed/simple; bh=TnmhAN7UAS2ynuFEOPQLlzD2wvbIo/yeVWwhOMqNS58=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dKWEzntd1miUn8ZRvhwEqDwpULsYmxM7VahP5mq0zQYxFBYnJjsQczgBlFiKtSHHxyN2KzojzsON2qQBc6KSEF86pNN/fq03jF/j4om6aCLehOj1QhmHFfhRClJ4q6WiugJ8K1KgeKdbuUYVM1hMtASSlVSB9l1EFy/M/xVgAD8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hShBIqEX; arc=none smtp.client-ip=209.85.210.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hShBIqEX" Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-7f4e6b5bd30so2055669a34.0 for ; Fri, 04 Sep 2026 14:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788557016; x=1789161816; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SP5FgDVql885MI97WgCQyPWKLiok3M5jguE0MrKj3qI=; b=hShBIqEXlXU7ExGsDiGFf8YXaBrcUIXtvbFGZKB4PJCT0QLq5zQhefmyoxPKo1+Pcq y16NU7Tc83rgkutIiroHqFe05pzYJfnkyyaenOQruzD3lMrjSfXSgcvKA0RSsDjJxtRU jPDAaSeHRgEs6HnTnAHlocL1LJLyQClVIHHlVE9xKN4L5Tdkniu+qPIKYY2eWOb7+OzK 00GouZZRRHBTOC5b1OPg0LuC4K5q+vihoqfqZIBRLgFrRZ1Pd5+x4kf6aTFun1PB2+ma E3Yyj/SiO53WvbLDGaBRCpin/0xp5T4spiqHU1JsI0+B6YaXIZSeQfVLxAno1dxmBPxj amUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788557016; x=1789161816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=SP5FgDVql885MI97WgCQyPWKLiok3M5jguE0MrKj3qI=; b=SyE7UrG6XdFteKin9Jqy+A4Q111pd0zqd62nFVyAanUMgmCsCQoGUoxVJf5rRckkMK iqQR1Iyg5vw3bJNAeELjQZD0ZPBQFLTe7Q3C5lYWuQOvDgr8SWrWChE4Nn1LlltNOSUN FH16X+S76k2LzpYcjgATTGeocPRRANzq5fgQlZB5UMR7WSmY+90JLgeOUvLrzseq993l o5b46COwdmz4RiqxhsnShfbjHJ57PMvmdFF4HneYaivA1dKZhu4ErXawxBtcb5woxcGn BN+iaqritekHeeOjfQTZ255iCDscu/EICCzHc1tBzPRFkNkXWxXUBbbSkjTzZt9OO6wf mPzw== X-Forwarded-Encrypted: i=1; AKwUvBzv1c8/OdgPQi/MFABJqgU501+Bfms2ACUzSTTNCOhz/DsmWJWi1itStpcymLe2EtbhieILzJd0ANQdz1Q=@vger.kernel.org X-Gm-Message-State: AFuF++lK1VNI2f9VGrjtm3EO0cKG9d/AqE7tzFx+3ZcNfdWd/5naOEsV ypaGQg6ZxrYHoZseRAgVLJCsIn3JdtDWP7qRaQhJ5uSz/8uNEq6ydjgu X-Gm-Gg: AYBFou2GMA8dZxHSL4kl82W6lZEY6C9fbrAVFkwEzpezT1YdphJP/Iut7Xm0Jcj1Cla iBXL6WnpUBbwxroq9nqtiTBBboG+gqQWmtdzOZGkcRaz/0dLYY/uctLdzhH+g69zcXxVbQdwFI5 fFjvVlPoDW5PE/ETrt14Rlwooslkq10ebcfhVOLgDgxBLfzUy0cm5Zh0ORlXorWz8GB/4gmLCxn w/SD/OIXeUZY5d87lSlQkUw6Jo71mmkJ0Vzz2zKlK4YiTs/86Go+1Fj1qiNDGYghDwt7qG9kvIG ZIeNrYT8NHrb4O+Nc+cSyyTpam/4a6euGIlxPXNyHZotOrsu34STxhSkk4F5IPy73GFoUz4xuiU YyEiPf1B8DJAELG4xVMi6W/ONeq8h0b0TmkjUGnzBGccm80YnI6kwJ3QL1I/9MriDjH+GcZf8jn Ag3Sio5fbzbIMEno5FSAFpNINOrK4tr40EU8BBi6kRVfp92Wl9LuIksi/5XQAjCDwskr5Ir65XU KCGsnjgf44PrgrircGIBq8H4XiraP1CGm8zU/M7PcvaZd03ZjZZxRolQlME5WO3SjMKnAcCFvle n2EaFXoBV0ujL7IkzMRy8FTsop9qxH89YM3fXiKJmVQaoib5ptFywVtnges805/xThDWjo9xfO0 pSB33mPtnetxQV0FtnHM= X-Received: by 2002:a05:6820:1521:b0:6b5:ec3f:4983 with SMTP id 006d021491bc7-6b71ff594bfmr2962915eaf.30.1788557016267; Fri, 04 Sep 2026 14:23:36 -0700 (PDT) Received: from [127.0.1.1] (184-96-151-165.hlrn.qwest.net. [184.96.151.165]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-6b6dbedc6fasm4492259eaf.3.2026.09.04.14.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 14:23:35 -0700 (PDT) From: James Hilliard Date: Fri, 04 Sep 2026 15:22:11 -0600 Subject: [PATCH v2 1/3] dt-bindings: mtd: sunxi: Add randomized OOB flag Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-submit-sunxi-nand-vendor-oob-layout-v1-v2-1-b12074f4aca7@gmail.com> References: <20260904-submit-sunxi-nand-vendor-oob-layout-v1-v2-0-b12074f4aca7@gmail.com> In-Reply-To: <20260904-submit-sunxi-nand-vendor-oob-layout-v1-v2-0-b12074f4aca7@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard Cc: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, James Hilliard X-Mailer: b4 0.15.2 Allwinner NAND firmware stores the bad block marker through the controller randomizer. The mainline driver instead compensates the first two randomized bytes so that the marker remains plain on flash. On H6 and H616, the firmware also uses a fixed protected user-data placement while mainline fills the OOB space left after ECC. Add an opt-in property selecting the firmware's normal-page format for the configured controller hardware-ECC geometry. This covers the vendor-specific randomizer, bad block marker representation and protected user-data placement needed to access BSP-derived images. The property does not change raw-access semantics. Raw operations still bypass ECC and randomization and expose physical main and OOB bytes. Signed-off-by: James Hilliard --- .../devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml | 10 ++++++= ++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand= .yaml b/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml index 9d061e2216cb..8ecafc40ddcb 100644 --- a/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml +++ b/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml @@ -79,6 +79,16 @@ patternProperties: minimum: 0 maximum: 1 =20 + allwinner,randomized-oob: + type: boolean + description: + Select the normal-page format used by Allwinner NAND firmware for + the configured controller hardware-ECC geometry. Normal page + transfers use the controller randomizer, the bad block marker re= mains + in its data stream instead of being compensated to stay plain on + flash, and protected user data uses the controller-specific plac= ement + expected by the firmware. + unevaluatedProperties: false =20 required: --=20 2.53.0 From nobody Sat Sep 26 04:01:47 2026 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 481DD3C109F for ; Fri, 4 Sep 2026 21:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788557021; cv=none; b=nO1FmCdOkK4bkJ0qiARvLqHwzhppsMTtZCBMmfUhXywPPEHShWOz5MQQMpj5HTXSyuwHGFpaNdkIBGtLfB1iYCqts5/CWyWbXYLAgl0g+ZxzCDtaGKK/lSgWwpvJTQV4jNZ/f81htc74ck4UZLwjl4j9KuA2Bn2eUGdjRhINSrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788557021; c=relaxed/simple; bh=F/EHqkFfSe/60Ki8YqKwL1Qg0R+is8WeugnWTveWoZ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=buUqJox7eiMtNHnS9rHA1yPGVPvk50MtyjR8FFGt+mZ3SDCgSKePKYLgBKjDklWiLZF6gS66MD0XMU0e/hfp1idO4g0T2SjLwSAUQrxAx2CjeeDrucLi8lJB0kqxBiI5pp9GF8vysRMqZWwNUGLlv7tCpv8Of1JtY8gSHQg7nsM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YmtpDxQC; arc=none smtp.client-ip=209.85.210.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YmtpDxQC" Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-7f4e6b5bd30so2055672a34.0 for ; Fri, 04 Sep 2026 14:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788557017; x=1789161817; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1XQ+Ej6D/KOaX2kDDZnurX6Kn6xIUtOZZNoB4S54GFs=; b=YmtpDxQCiDkqgNNf/ib/cWMLw0/2y9ZWc0OynjJJs0vZcz54JRtWkDHWb4ASbfbvsN kiR12mPUN+nSFT3k2F2RGGB+Vjr+UjPsiTT8D0jsUCpU/YY09FlcPDWUq/7PwG39rM9o fbyUFf36Llpqx5dLPOn9X+sgn9kp6i/TePbvs0QZ0qYhj9AV3LlGhZYRzfiPQIDW4u6F l5pVXqkbco8g/dcZyLGdm/Fx6zQEgmfltq5yk2kCaTrCnw1p9rKM6dVnOKKJjkruopAD V3nOOcUKWCbjv/jpfcAwTBCzravJOY62e6kT1CQQcLXV1rctQ5aiTsC2mgCpWVooV6is zl0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788557017; x=1789161817; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1XQ+Ej6D/KOaX2kDDZnurX6Kn6xIUtOZZNoB4S54GFs=; b=S7WsgSKoF7DkV6JiHX6KBxn2w+NDb31ZlwOAfUAGKxZ7tnIfXTW1oQ344jIvIw05LG wASghSrgK2rCXFGlGK+daSIpR/WIoWjRoR9/aLPyuoHUi228bXpSx+CuNFOXl/PLz/4r dgzXo6+Yg+ITAOhaV+VAqBTY45EcwOgqttbfIxbBiYtXRmwZR6VHVxzt90L84N0cMFy2 B+EKZ/j40B/sOVbTq83PXOI6PwO/fn2ZTTJPPNqBDxeagMCR12pm3lu5sQSXzHHq1S3Q nSBvIGxpGkFxOdLRB9BGqKq2HgQv2gJoMXFzBWbMa1qx0ZRU3xtl4E+kuzkxpy/RfEm3 9QCw== X-Forwarded-Encrypted: i=1; AKwUvBzD19xFG4FBMjz3G5+8juvhqrUQUzKPuQ8G1LjcAl5YkNAXAFbZ67Yt09hzPlyKdaa0cC9dsl0hoT1B6MA=@vger.kernel.org X-Gm-Message-State: AFuF++ni9Bi5B8K+ae0xZ81W3KWfIzu7Bka4bOqCcRNC9hfSOwXmmlIQ um/BUyR6Br2TKN96kbObrwSH2EjnbJMNFu6qSCNHRHRunTVD4MT5EA0c X-Gm-Gg: AYBFou0tIXe1GrpUdZZv3je41n6VjZJiOl+Vu7qFOSQ+k3ctYpzz7pa4TY5VS1syMup OQ5l1tzcJx/qcnCE/QrZA++ONmLpgcNBrjnfO3DVFycA0HF+jT/hlBfkdDwooRwyDbaE82G41DA hr0N1Go9SxNocbinPxGqMQm3gacsXyS0lKryBCOQ9yAWzRtySxzsI+unzwB8pP/3ngv8nbTvoDP bhreoBtRaaF0r7B+lKkoCBz5Edgrz2cxKgJ0BeFLEjjWvOpNH1u7BcGw79O5qwNM0G4w4uGuNfW 98z20aACzxChU7Gs9IkIr26WKv0VmaE0FPI9uAD8BYprrEJnGHaMVxrF3YqrcfB9/MXlVGgGfcn Us/yJrukiaqMBAYrdxDVMqCbm7z87kP1lqlYHc8vQ0dUlKfv8h1gOismVxkJbO7dScHmxdaWuyG qt0equX8s3EG9p7g++e/aA4jteWJ2REq40LWiq9L8MUSQmtGL0r27tjfhjckdw8IxI9RVSZnNeH R2tB/f/HFNlia2K7H6xwuJNZxuQqBjN1nf2dv1t8NGaU3iiP/0t90h2xT3xWJkAAIEDOKXBJ2mf HQP2f30t8AjiISMTJVHsBd80B+/iX4Z7lYL71V3w8lSrb+CdvlIxXXrBOi1/z7RWB2h20TxrjQt NarOSQkF8xDRAGJhAGdc= X-Received: by 2002:a05:6820:60b:b0:6b5:ec3f:4988 with SMTP id 006d021491bc7-6b72054580dmr2866500eaf.35.1788557017178; Fri, 04 Sep 2026 14:23:37 -0700 (PDT) Received: from [127.0.1.1] (184-96-151-165.hlrn.qwest.net. [184.96.151.165]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-6b6dbedc6fasm4492259eaf.3.2026.09.04.14.23.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 14:23:36 -0700 (PDT) From: James Hilliard Date: Fri, 04 Sep 2026 15:22:12 -0600 Subject: [PATCH v2 2/3] mtd: rawnand: sunxi: support randomized OOB formats Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-submit-sunxi-nand-vendor-oob-layout-v1-v2-2-b12074f4aca7@gmail.com> References: <20260904-submit-sunxi-nand-vendor-oob-layout-v1-v2-0-b12074f4aca7@gmail.com> In-Reply-To: <20260904-submit-sunxi-nand-vendor-oob-layout-v1-v2-0-b12074f4aca7@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard Cc: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, James Hilliard X-Mailer: b4 0.15.2 The controller randomizer covers the bad block marker along with the rest of the OOB data. The driver currently compensates the marker bytes before writes and after reads so that they remain plain on flash. Allwinner NAND firmware instead stores the marker through the randomizer. Media using that format appears to contain bad blocks unless the randomizer is enabled while reading the marker. Honor the allwinner,randomized-oob property by marking the NAND as requiring scrambling during normal hardware-ECC transfers and leaving the marker in the randomizer data stream. Keep the existing plain marker behavior when the property is absent. Reject the property with software or disabled ECC because those paths do not operate the controller randomizer. MTD_OPS_RAW behavior remains unchanged: raw accesses bypass both ECC and randomization and expose the physical representation. The raw-NAND core's bad-block and flash-BBT paths use decoded accesses and therefore continue through the hardware-ECC/randomizer path. This changes marker handling on all supported controllers; the H6/H616 protected user-data placement is handled separately. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 83666dd6cb2a..c1246a9268ca 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -265,6 +265,7 @@ struct sunxi_nfc_timings { * @clk_rate: clk_rate required for this NAND chip * @timing_cfg: TIMING_CFG register value for this NAND chip * @timing_ctl: TIMING_CTL register value for this NAND chip + * @randomized_oob: use the randomized normal-page OOB format * @nsels: number of CS lines required by the NAND chip * @sels: array of CS lines descriptions * @user_data_bytes: array of user data lengths for all ECC steps @@ -277,6 +278,7 @@ struct sunxi_nand_chip { u32 timing_cfg; u32 timing_ctl; u8 *user_data_bytes; + bool randomized_oob; int nsels; struct sunxi_nand_chip_sel sels[] __counted_by(nsels); }; @@ -945,8 +947,9 @@ static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(struct = nand_chip *nand, u8 *oob, } } =20 - /* De-randomize the Bad Block Marker. */ - if (bbm && (nand->options & NAND_NEED_SCRAMBLING)) + /* Undo hardware de-randomization for a plain on-flash BBM. */ + if (bbm && (nand->options & NAND_NEED_SCRAMBLING) && + !sunxi_nand->randomized_oob) sunxi_nfc_randomize_bbm(nand, page, oob); } =20 @@ -1006,8 +1009,9 @@ static void sunxi_nfc_hw_ecc_set_prot_oob_bytes(struc= t nand_chip *nand, unsigned int user_data_sz =3D sunxi_nfc_user_data_sz(sunxi_nand, step); u8 user_data[SUNXI_NFC_MAX_USER_DATA_SZ] =3D {}; =20 - /* Randomize the Bad Block Marker. */ - if (bbm && (nand->options & NAND_NEED_SCRAMBLING)) { + /* Pre-randomize the BBM so the hardware writes it plain on flash. */ + if (bbm && (nand->options & NAND_NEED_SCRAMBLING) && + !sunxi_nand->randomized_oob) { memcpy(user_data, oob, user_data_sz); sunxi_nfc_randomize_bbm(nand, page, user_data); oob =3D user_data; @@ -2229,6 +2233,8 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_ch= ip *nand, =20 static int sunxi_nand_attach_chip(struct nand_chip *nand) { + struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); + struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); const struct nand_ecc_props *requirements =3D nanddev_get_ecc_requirements(&nand->base); struct nand_ecc_ctrl *ecc =3D &nand->ecc; @@ -2238,6 +2244,14 @@ static int sunxi_nand_attach_chip(struct nand_chip *= nand) if (nand->bbt_options & NAND_BBT_USE_FLASH) nand->bbt_options |=3D NAND_BBT_NO_OOB; =20 + if (sunxi_nand->randomized_oob && + ecc->engine_type !=3D NAND_ECC_ENGINE_TYPE_ON_HOST) + return dev_err_probe(nfc->dev, -EINVAL, + "Allwinner OOB format requires controller ECC\n"); + + if (sunxi_nand->randomized_oob) + nand->options |=3D NAND_NEED_SCRAMBLING; + if (nand->options & NAND_NEED_SCRAMBLING) nand->options |=3D NAND_NO_SUBPAGE_WRITE; =20 @@ -2467,6 +2481,9 @@ static int sunxi_nand_chip_init(struct device *dev, s= truct sunxi_nfc *nfc, if (!sunxi_nand) return -ENOMEM; =20 + sunxi_nand->randomized_oob =3D + of_property_read_bool(np, "allwinner,randomized-oob"); + sunxi_nand->nsels =3D nsels; =20 for (i =3D 0; i < nsels; i++) { --=20 2.53.0 From nobody Sat Sep 26 04:01:47 2026 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96457423A66 for ; Fri, 4 Sep 2026 21:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788557021; cv=none; b=jfECQqRcLCGqK29EcOXFhtKgrTxbXxhQ8DxvsMAJqxzEtJlsp4cLDsmtUFq/kd9IkJQB8nQ1htZ8lksOGOdIMMd4bofatu2L9J84BFn/KGuPgoIk6Wx/DIBAKmETXNG9IIT2d5stzNPxT/oTO+Ab3Te+K8cpZoT0R/GAmUhD8mU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788557021; c=relaxed/simple; bh=P9VhO/j3MukvM1aMlXTflvte2/XJpvtBnpClC5Qa4Bk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rKtA/UdmmzbGi4qUvcYhxS2tTVKV27pEYHBv2zl8aDba53WIXXKKHpR0MTaYlb6DFpb0JkcrJ+ekNKDTwe1DYklPZ3/+nLUFcoGx9OFXEljXTYkZmHLJY0cU20SftFXDqY5dcMlj3IG1p7vYyJQykoAnyd3uYpKNY+QKP64d4ZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HMoCAop7; arc=none smtp.client-ip=209.85.161.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HMoCAop7" Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-6b127c88220so1026293eaf.1 for ; Fri, 04 Sep 2026 14:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788557018; x=1789161818; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9BgbJZzXDYwsOLv3h9k0AMpcw0EOYW2MSapQnfQyB+Y=; b=HMoCAop77ZUbkd1i3oeZHwv+MC2U8Rq/zeMA7xdeKPTOfOBDJkkwb1A2PHqs2e+q4f twgztz3XAczgajbZWH2Fk7kUc50PyERaSBVCOJ7yTsQx7ONX7au2UYI0od8xbrkS6mju 2ihrT1LE0Y5fJGUt8B3cNy4/OUKPz1yLEvOz18R0sYMP39PwzfXCkOb7K2AQ0d2j/prT g2H8QfgZQ9dEI+bR+4Z0RVy7PpkO1DEy2OyQTo+xn9qa8Js/zD0inI0RhWck5J+Kx32O obHrKoNYMcn9OeJpEsb6B6qlKJvJwoQ4ekJUl/os5OSth1T0iiPDYpkLHQMXobL9PfAc rGag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788557018; x=1789161818; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9BgbJZzXDYwsOLv3h9k0AMpcw0EOYW2MSapQnfQyB+Y=; b=eNW7hWBIZsUtD09AOUKcsoblGR8XgjydK2hIs3b9i/IlJHeSxlWVP0kIv8+CXCd6bN horUAyWEOcHjVlidVwYUVWh5DMIz/TUlPk6dJBqBu4zGm0yXxyw92KOdtq1tIGSvmbbM GjAh26idpC+pJtPMRC7eMyonLD+nFBX9cz+2r12ESgIvJOV5Fsfum3mhg14UL3G12MJt nklX3CzhxGO3zay0BgZJ9nnTb05CSQSOYS1iFG9JTC8rewVMeevN11ai4md4VQvjmnKj 69Yonyovus9G9UTT0YVvAxJGlSfRVSuNJGuLuU1hQ0JeNuLwTKsw349C4xcH5jqzHkpH +QSA== X-Forwarded-Encrypted: i=1; AKwUvBxasydg7GQ8Gfzg9mAT4fdTTkrI3vE5eraSwPjvRISqu4jA6GESFtvrtVBkKAHdD1u3CRNMYqcx/JfzPHs=@vger.kernel.org X-Gm-Message-State: AFuF++mX9MX38YoAPntDwPgQE1MGj/nEbA3y0GT1pyowfWxA2joSs4bW tNiM6GoaLwb785XeXHMpi24RrlNLNQ3zmame/E0eL3XA1W8tB2I0CEYd X-Gm-Gg: AYBFou2KzO3kuajm70ftNlc5F5YIxiyVG/dtON/iDq7/2moHJBFU8TRx0EbT+arnnbA I76IQDlm6J8uRKjVKIk1NYCkuoik7PNxU859fAr4qQ50kD1ErIAK7nScObAUfLhuDPIZ4h8jMRe CtU/tcMmR4dZk4ZrxHRMntUXzkl03xZKzwfSmqU3UL+OXlFPpRFfVLlnnUiPS1yas3xxqWGBE88 4kGog/vReeUCK25CySR9CMcEOyoZ0N8C3MsAKVBAK4ucpQTq5j9ctdwefhWPhAMQdgTtwFfezVc ggzUpJUG/BmNrcSILoBG3PenPzD91hEFGeU+yMbftWs4yqunzmq7KgFlS+lYun18U6Kt8YodRD5 E9I+hkWaD03cw2gwor6PPTeV+cCXCklc42IG9iAMis4TvL/erzAgcwU7d3FbVKum2ipFgm7qN1D V/9L760Hox8IBvaMxr2dRIiL55DBrWcGGonGpvk/uEXYledJxMIyyorMyaWK9r8T9clYJgiii5o yLj2MLKtwehVv3emn7XLCjS4SMgPGYyO2EFz0zsJdJx1vBr12+HGv0+zaueHMo+kkcIL4MQOmGS /6GQz1uDy7/fJfdnblXkl/iZWZ3Mn/YsslOljYHwspRhDlm+uugQPzyYQItaUZDfVzmwbWiK3i7 0SyUkfDOffvI15BRt1KU= X-Received: by 2002:a05:6820:180e:b0:6b1:65ad:3181 with SMTP id 006d021491bc7-6b6fcfd957cmr8410089eaf.16.1788557018080; Fri, 04 Sep 2026 14:23:38 -0700 (PDT) Received: from [127.0.1.1] (184-96-151-165.hlrn.qwest.net. [184.96.151.165]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-6b6dbedc6fasm4492259eaf.3.2026.09.04.14.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 14:23:37 -0700 (PDT) From: James Hilliard Date: Fri, 04 Sep 2026 15:22:13 -0600 Subject: [PATCH v2 3/3] mtd: rawnand: sunxi: select the packed H6/H616 OOB layout Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-submit-sunxi-nand-vendor-oob-layout-v1-v2-3-b12074f4aca7@gmail.com> References: <20260904-submit-sunxi-nand-vendor-oob-layout-v1-v2-0-b12074f4aca7@gmail.com> In-Reply-To: <20260904-submit-sunxi-nand-vendor-oob-layout-v1-v2-0-b12074f4aca7@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard Cc: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, James Hilliard X-Mailer: b4 0.15.2 The H6/H616 controller can configure a separate protected user-data length for every ECC step. Mainline fills all space left after ECC with user data. This changes the physical ECC offsets from those used by Allwinner NAND firmware, so pages written by one layout cannot be decoded with the other. The allwinner,randomized-oob property selects the firmware's normal-page format for the configured controller hardware-ECC geometry. Use four protected user-data bytes per 1 KiB ECC step, cap the total at 16 bytes, and assign the entire total to ECC step zero. Reserve the same total before maximizing ECC strength so the selected strength leaves enough room. Keep the existing maximized mainline user-data layout when the property is absent. Older controllers have fixed four-byte user-data registers whose placement already matches the firmware and need no additional change. Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index c1246a9268ca..1265d900fc27 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -224,6 +224,9 @@ #define USER_DATA_SZ 4 #define SUNXI_NFC_MAX_USER_DATA_SZ 32 =20 +/* The randomized H6/H616 layout packs at most 16 bytes before ECC step 0.= */ +#define SUNXI_NFC_H6_MAX_USER_DATA_SZ 16 + /** * struct sunxi_nand_chip_sel - stores information related to NAND Chip Se= lect * @@ -2037,8 +2040,14 @@ static void sunxi_nand_detach_chip(struct nand_chip = *nand) sunxi_nand->user_data_bytes =3D NULL; } =20 -static int sunxi_nfc_maximize_user_data(struct nand_chip *nand, uint32_t o= obsize, - int ecc_bytes, int nsectors) +static unsigned int sunxi_nfc_h6_user_data_sz(int nsectors) +{ + return min(nsectors * USER_DATA_SZ, + SUNXI_NFC_H6_MAX_USER_DATA_SZ); +} + +static int sunxi_nfc_init_user_data(struct nand_chip *nand, uint32_t oobsi= ze, + int ecc_bytes, int nsectors) { struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); @@ -2054,6 +2063,12 @@ static int sunxi_nfc_maximize_user_data(struct nand_= chip *nand, uint32_t oobsize if (!sunxi_nand->user_data_bytes) return -ENOMEM; =20 + if (sunxi_nand->randomized_oob) { + sunxi_nand->user_data_bytes[0] =3D + sunxi_nfc_h6_user_data_sz(nsectors); + return 0; + } + for (step =3D 0; (step < nsectors) && (remaining_bytes > 0); step++) { for (i =3D 0; i < c->nuser_data_tab; i++) { if (c->user_data_len_tab[i] > remaining_bytes) @@ -2111,6 +2126,10 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_c= hip *nand, bytes -=3D 2; =20 bytes -=3D total_user_data_sz; + } else if (sunxi_nand->randomized_oob) { + total_user_data_sz =3D + sunxi_nfc_h6_user_data_sz(nsectors); + bytes -=3D total_user_data_sz; } else { /* * User-data lengths are encoded in four-byte units. Reserve @@ -2177,12 +2196,12 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_= chip *nand, nsectors =3D mtd->writesize / ecc->size; =20 /* - * The rationale for variable data length is to prioritize maximum ECC - * strength, and then use the remaining space for user data. + * The default variable-length layout prioritizes maximum ECC strength, + * then uses the remaining space for user data. */ if (nfc->caps->reg_user_data_len) { - ret =3D sunxi_nfc_maximize_user_data(nand, mtd->oobsize, - ecc->bytes, nsectors); + ret =3D sunxi_nfc_init_user_data(nand, mtd->oobsize, + ecc->bytes, nsectors); if (ret) return ret; } --=20 2.53.0