{"id":2223798,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2223798/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/20260416084535.1490476-2-ghidoliemanuele@gmail.com/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/1.1/projects/18/?format=json","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},"msgid":"<20260416084535.1490476-2-ghidoliemanuele@gmail.com>","date":"2026-04-16T08:45:23","name":"[v1,1/3] common: memsize: add RAM size probe based on alias detection","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"60cb3a85c5511179514bfd7ac3017c3442d5f4ad","submitter":{"id":85913,"url":"http://patchwork.ozlabs.org/api/1.1/people/85913/?format=json","name":"Emanuele Ghidoli","email":"ghidoliemanuele@gmail.com"},"delegate":{"id":151988,"url":"http://patchwork.ozlabs.org/api/1.1/users/151988/?format=json","username":"festevam","first_name":"Fabio","last_name":"Estevam","email":"festevam@gmail.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20260416084535.1490476-2-ghidoliemanuele@gmail.com/mbox/","series":[{"id":500111,"url":"http://patchwork.ozlabs.org/api/1.1/series/500111/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=500111","date":"2026-04-16T08:45:22","name":"add Toradex Verdin iMX95 support","version":1,"mbox":"http://patchwork.ozlabs.org/series/500111/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2223798/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2223798/checks/","tags":{},"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=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=mhOL4pS0;\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=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b=\"mhOL4pS0\";\n\tdkim-atps=neutral","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=gmail.com","phobos.denx.de;\n spf=pass smtp.mailfrom=ghidoliemanuele@gmail.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)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxBTz4ZHgz1yDF\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 18:47:35 +1000 (AEST)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 2D9FE840AB;\n\tThu, 16 Apr 2026 10:47:28 +0200 (CEST)","by phobos.denx.de (Postfix, from userid 109)\n id 53CDC84105; Thu, 16 Apr 2026 10:47:24 +0200 (CEST)","from mail-wm1-x335.google.com (mail-wm1-x335.google.com\n [IPv6:2a00:1450:4864:20::335])\n (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id 552DF84105\n for <u-boot@lists.denx.de>; Thu, 16 Apr 2026 10:47:22 +0200 (CEST)","by mail-wm1-x335.google.com with SMTP id\n 5b1f17b1804b1-488b3f8fa2bso3718615e9.1\n for <u-boot@lists.denx.de>; Thu, 16 Apr 2026 01:47:22 -0700 (PDT)","from emanueleg-nb.homenet.telecomitalia.it\n (host-87-2-163-213.retail.telecomitalia.it. [87.2.163.213])\n by smtp.gmail.com with ESMTPSA id\n ffacd0b85a97d-43ead3564d8sm13391674f8f.10.2026.04.16.01.47.20\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 16 Apr 2026 01:47:21 -0700 (PDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,\n DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_GMAIL_RCVD,FREEMAIL_FROM,\n RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=no\n autolearn_force=no version=3.4.2","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1776329242; x=1776934042; darn=lists.denx.de;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=3OQzSckePx/MAGXW8zkDhFDD7+iffyF3SDq4Cg2uauA=;\n b=mhOL4pS0L8NP+bF04ORxRrg532TQ1GDSGIKNdMmpxX7k6ZdlkctVEhiayVQbXzZA5L\n 3IfLtRUsUq+cy7aXlPd12ygIjkvqSqakT7nGHQQ8Sl/ExKV4Ic+SL0FaxgK6KdkztcgQ\n +hmjAxE1fbKWD8oAInsp8ZSDr2Cta/s3Apt9d12OkjEqlX1zYzao+450iRT4AqMRuC4c\n a0GKxcQj5bx4gTAIEe0DQeSprSptHNiHzncziW20B0G4K8+ncapVaN1L78Rct66YwKXp\n JcYfS5WLBQ4d2D5cXJhvWKqyUeaX+4n7EsOKV2QOJ8+KjqwhRsaVye6Ksvd0cCYMfiHl\n WEsg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776329242; x=1776934042;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=3OQzSckePx/MAGXW8zkDhFDD7+iffyF3SDq4Cg2uauA=;\n b=YqAKJvMQelLuQIdBOPvGm+wTSFLq6hrph3IVk/bbpUWenYPgUwtd0bDk+gbqO9S4WI\n iiNYZrKxbhZ//bih+Rrskx0AYnRrHLFMm+tefZIfX9pp7GcevRSS9FJisoQl5OAKLOf3\n S8d667UwXeZ6bAc5c8FJin4AFZVbTOAGWX317OzdiRbhVdaNY5MV0CSXfXlOkbJlpDEF\n +IkxA2XTay9bmyyiQNHQG/5LjKx5uXwpuPl93t0TphQHhldK1msNjN0U0vJOuU2KBxxN\n mv+8o53gvdoMkBI2oC1FuChBIWmbJ2vOFnWN0Sm1A4wJEAVay2mEWqOeJGlOFBsm0qAU\n Y3Sw==","X-Forwarded-Encrypted":"i=1;\n AFNElJ8spPA4MA8j5fGrpMsEOXsBHMyHzVotfgzeUvG+ZnWIZQX3l7q88lFPUEKrXziwWB38KTXliNI=@lists.denx.de","X-Gm-Message-State":"AOJu0YzDX/AaG1xEaEvcl0Mu6nD+nEYB1N/JyzGyozpZXetXPq0vKTxU\n FGsqO3aZI27m6onUYu5HLmvLA32z2+8OqXhqyNVGMTHKVvOnBDHfMZjO","X-Gm-Gg":"AeBDietUPU0coL9FNRF/kUOFBvNZb2YFsN8IcF0np4vdIQi2Zj4zRvM/XW5R5n2I8Nk\n DnG8AIAMuJtWcNmhqvaoXeW+BIu8CVSUM4ymGaPnLD9AMmor24gAFD3wJOHOEKQnaqpkPnuHf11\n SLQWqXm7i86xPQE0R/hMwtMwooR+7vPcHKUVa8dQIWKE8AXAte1PJztdL1xrn+x4/tHEjYGcAB5\n XM3M5oim7YCQkuOPgGrObCw5Qv68uhAxTvCDk/K8n4qW+QpjdWXCyQvE8plLHo9kL3tvvFSblD/\n sPNF7BYNgj70d7E+qSeVXg8QLEm83rRWVxv6EHfzC+cVKpfEcokUs2gTj5V25bxtRIkuXM8LHTP\n 4fCmNfsJvzEUZjwVTymzntNfGTzZqzMABHaPvOwy0+TCp/6StmwrqsTH0PfHd5RkTrzNo4ZCiIC\n L1hx3zNBM0M4jKLNH8Ob6Vih3+6uHe1j296ysM1oSIqWJUfDkUdYbQuzoWl57xcTK/6fS8t+OwN\n 6XtfEq6dkYma6iRRznE7EcMtltv6KHiJfWSCjKl41fNnagW","X-Received":"by 2002:a05:600c:40d2:b0:488:e10c:d17f with SMTP id\n 5b1f17b1804b1-488f4800189mr26969805e9.16.1776329241428;\n Thu, 16 Apr 2026 01:47:21 -0700 (PDT)","From":"Emanuele Ghidoli <ghidoliemanuele@gmail.com>","To":"Tom Rini <trini@konsulko.com>, Stefano Babic <sbabic@nabladev.com>,\n Fabio Estevam <festevam@gmail.com>,\n \"NXP i.MX U-Boot Team\" <uboot-imx@nxp.com>,\n Francesco Dolcini <francesco.dolcini@toradex.com>","Cc":"Emanuele Ghidoli <emanuele.ghidoli@toradex.com>,\n \"Peng Fan\" <peng.fan@nxp.com>, \"Alice Guo\" <alice.guo@nxp.com>,\n \"Sumit Garg\" <sumit.garg@oss.qualcomm.com>, Simon Glass <sjg@chromium.org>,\n u-boot@lists.denx.de","Subject":"[PATCH v1 1/3] common: memsize: add RAM size probe based on alias\n detection","Date":"Thu, 16 Apr 2026 10:45:23 +0200","Message-ID":"<20260416084535.1490476-2-ghidoliemanuele@gmail.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260416084535.1490476-1-ghidoliemanuele@gmail.com>","References":"<20260416084535.1490476-1-ghidoliemanuele@gmail.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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":"From: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>\n\nAdd probe_ram_size_by_alias() to detect RAM size by checking whether a\nwrite to one address aliases to another address.\n\nCompared to get_ram_size(), this function allows the caller to:\n- limit probing to a small set of required accesses\n- avoid touching reserved or already used memory regions\n- handle non-linear alias patterns\n\nOn the iMX95 SoC, when used with LPDDR5, accesses beyond the end of an 8GB DDR\nconfiguration do not alias to the expected linear wrap-around addresses.\nInstead, the aliased addresses appears to follow a pattern related to the\nDDRC bank and bank-group addresses mapping. Experimentally, the observed\npattern is:\n\nWrite        Read\ny00000000 -> x0001c000\ny00004000 -> x00018000\ny00008000 -> x00014000\ny0000c000 -> x00010000\ny00010000 -> x0000c000\ny00014000 -> x00008000\ny00018000 -> x00004000\ny0001c000 -> x00000000\n\nThis helper makes it possible to probe RAM size by explicitly specifying\nthe probed address and the expected alias address for each size check.\n\nSigned-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>\n---\n common/memsize.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++\n include/init.h   |  7 ++++++\n 2 files changed, 63 insertions(+)","diff":"diff --git a/common/memsize.c b/common/memsize.c\nindex 1abf3fc47d73..cf46a6b17872 100644\n--- a/common/memsize.c\n+++ b/common/memsize.c\n@@ -127,6 +127,62 @@ long get_ram_size(long *base, long maxsize)\n \treturn (maxsize);\n }\n \n+/**\n+ * probe_ram_size_by_alias() - Detect RAM size using known alias addresses\n+ * @checks: Array of RAM alias probe descriptors, terminated by a NULL\n+ *\t    @probe_addr entry\n+ *\n+ * Probe RAM size by writing a test pattern to each @probe_addr and checking\n+ * whether the same pattern does not appear at the corresponding @alias_addr.\n+ * This is useful on systems where address wrap-around does not alias to the\n+ * base of memory in a linear way, so get_ram_size() cannot be used directly.\n+ * It is also useful on systems where the base of the physical memory cannot\n+ * be safely accessed, so get_ram_size() cannot be used at all.\n+ *\n+ * Return: The size associated with the first matching entry, or 0 if no match\n+ * is found.\n+ */\n+long probe_ram_size_by_alias(const struct ram_alias_check *checks)\n+{\n+\tlong save[2];\n+\tint dcache_en = dcache_status();\n+\tlong ret = 0;\n+\n+\twhile (checks->probe_addr && !ret) {\n+\t\tvolatile long *d = checks->probe_addr;\n+\t\tvolatile long *s = checks->alias_addr;\n+\n+\t\tsave[0] = *s;\n+\t\tsave[1] = *d;\n+\t\t/* Ensure s is written and not cached */\n+\t\tif (dcache_en)\n+\t\t\tdcache_flush_invalidate(s);\n+\n+\t\t*d = ~save[0];\n+\t\tsync();\n+\t\tif (dcache_en)\n+\t\t\tdcache_flush_invalidate(d);\n+\n+\t\tif (*s != ~save[0])\n+\t\t\tret = checks->size;\n+\n+\t\t/* Restore content */\n+\t\t*d = save[1];\n+\t\tsync();\n+\t\tif (dcache_en)\n+\t\t\tdcache_flush_invalidate(d);\n+\n+\t\t*s = save[0];\n+\t\tsync();\n+\t\tif (dcache_en)\n+\t\t\tdcache_flush_invalidate(s);\n+\n+\t\tchecks++;\n+\t}\n+\n+\treturn ret;\n+}\n+\n phys_size_t __weak get_effective_memsize(void)\n {\n \tphys_size_t ram_size = gd->ram_size;\ndiff --git a/include/init.h b/include/init.h\nindex 1e375da48936..c31ebd83b85e 100644\n--- a/include/init.h\n+++ b/include/init.h\n@@ -14,6 +14,12 @@\n \n #include <linux/types.h>\n \n+struct ram_alias_check {\n+\tvoid *probe_addr;\n+\tvoid *alias_addr;\n+\tlong size;\n+};\n+\n /*\n  * In case of the EFI app the UEFI firmware provides the low-level\n  * initialisation.\n@@ -88,6 +94,7 @@ int dram_init(void);\n int dram_init_banksize(void);\n \n long get_ram_size(long *base, long size);\n+long probe_ram_size_by_alias(const struct ram_alias_check *checks);\n phys_size_t get_effective_memsize(void);\n \n int testdram(void);\n","prefixes":["v1","1/3"]}