{"id":2224243,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2224243/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/20260417071546.1610330-2-ghidoliemanuele@gmail.com/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/1.2/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,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260417071546.1610330-2-ghidoliemanuele@gmail.com>","list_archive_url":null,"date":"2026-04-17T07:13:31","name":"[v2,1/3] common: memsize: add RAM size probe based on alias detection","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"5e2138cd640f558b1e13d1fa4b973ee9fa53196b","submitter":{"id":85913,"url":"http://patchwork.ozlabs.org/api/1.2/people/85913/?format=json","name":"Emanuele Ghidoli","email":"ghidoliemanuele@gmail.com"},"delegate":{"id":151988,"url":"http://patchwork.ozlabs.org/api/1.2/users/151988/?format=json","username":"festevam","first_name":"Fabio","last_name":"Estevam","email":"festevam@gmail.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20260417071546.1610330-2-ghidoliemanuele@gmail.com/mbox/","series":[{"id":500248,"url":"http://patchwork.ozlabs.org/api/1.2/series/500248/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=500248","date":"2026-04-17T07:13:30","name":"add Toradex Verdin iMX95 support","version":2,"mbox":"http://patchwork.ozlabs.org/series/500248/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2224243/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2224243/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=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=XvEKU9ii;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=\"XvEKU9ii\";\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\n [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])\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 4fxmPw3d9fz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 17:16:04 +1000 (AEST)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 73A3384258;\n\tFri, 17 Apr 2026 09:15:54 +0200 (CEST)","by phobos.denx.de (Postfix, from userid 109)\n id A9BCC83FC0; Fri, 17 Apr 2026 09:15:52 +0200 (CEST)","from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com\n [IPv6:2a00:1450:4864:20::32d])\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 A9A5A83FC0\n for <u-boot@lists.denx.de>; Fri, 17 Apr 2026 09:15:50 +0200 (CEST)","by mail-wm1-x32d.google.com with SMTP id\n 5b1f17b1804b1-488a9033b2cso3666105e9.2\n for <u-boot@lists.denx.de>; Fri, 17 Apr 2026 00:15:50 -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 5b1f17b1804b1-488fb6dfa33sm15573955e9.0.2026.04.17.00.15.49\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Fri, 17 Apr 2026 00:15:49 -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=1776410150; x=1777014950; 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=jiPVCHfizk5nKMv0TFveCyP+YN5hGFmOdxQlu0i+Zec=;\n b=XvEKU9iiZ3g80KlyjrPoOhIQpvfhhliBKHFvDVh0J19WiHHT+bvlAxFgXK52bW7zBP\n t5IaUCb6w2yFequZB6PtB4jM1khxbI36KMX1BlDFY1ek6MmoMLoKaR3AFK55nCAzZJDw\n SXCxCmd0LNpi7Q+42TuWnUC7pN08J5qgtBsz2FB0NhU+hp/dMSNfg8e7QaLcSiiSKqBB\n zjfOBslP+VLp7e23+Ez8ZMlrOi2WKEpSrrOYxt5O/LoIpYRCX1yJkgJckkL8rtdzuEyh\n 4mtgaec/tK33oPDrsZRfqmj2+vDvG6Trk1kNZdLZmoSytIILcVNjR9T2Wcp1jRfjHrTR\n NJrw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776410150; x=1777014950;\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=jiPVCHfizk5nKMv0TFveCyP+YN5hGFmOdxQlu0i+Zec=;\n b=CkLi9YVvpV6qKLyTWuTdNCeZiQSqrKLkqCmmJ4LFCgAYkt5X3BFjziMD+rTVUdMfRG\n lRyXeu6FKmiZBQvH1TQlhY+tbNL7f/EMYMl0HB0bivRSeZ8mD8Ngsl+5kU8wtyJs0esl\n ISpeHoUcF7jrxNcCciUlkQ3AAqmqN9NMrgV62emLedy5CMuxxbWvCJfKifJVrJOo49yy\n QEhkEwUaEBamkvHBmQFDxc8iW3TMIKNrpxRsb/UZFQJdGQgsiRk0acV0xeErSXb1vjgB\n o5nZG56R3qbzQdI0jo/x3WnLMOAohshL22Q/14HpF6TibVkwgSDb8DqyGkVjCmroyjWh\n 0xOA==","X-Forwarded-Encrypted":"i=1;\n AFNElJ/ie22AWD+yhC+5vRDy0peMHqc1jJKE3DnaAwqAZZzQ2A3mW0Dy5U+4gSF++VMs9HWlx1mFv9o=@lists.denx.de","X-Gm-Message-State":"AOJu0YzVh+2L7S/At1fq3IB5kSogbvArvAcxbkWCet1SBPTAVOx4WwGf\n 35MFXNKUj7kFfv4ShL7SNiYArWEG/40oIaoZvOHwZMeKAMAg2ea5w3csG08SnRRH","X-Gm-Gg":"AeBDietE7GRa8sHIfG+kHmzPJJ9IMnQt0Edg+Ea15luxi/Ud97yGDRRMabkW2O/QNtb\n s1AAZOofyoGKIxZ/4sMuVQn1T2ZPr9rdQfjHi8NvcOcDWPiPhynKPPRgVAqznKgAucwG/IaDONb\n kQYLhZsuZOua/sz72jQ+qB3NIor95maveLRBONZeZ6fNfb8Cxfo6KulLZRpQhfxT+1CRArEKoSH\n I59peqEjyW0+2rEU2cdtYX0Bt4zWo0sw8EDOzQGoOyCmu2oe50IWGJGchehnd7oOnNI9TG0lBtk\n m25TAIfKi/MgFr3IAwUCkJlTaI7msQ0CdEnuwfcSNACyCfPZ/73ugLW359vdXJSeN7Xjq8pmaWX\n LkETN94juKjR23QCYFr3MEzr52uLQkc0bASFHg1rwpsLIt7+OA4jHM1sBSJ9DwAqVjm6131N/7P\n qDaBCXf+8OmwA8qVSy1DoVkPSlav+lLocjLIhF33c8cYZ9ngmvhwsKHDHS18Re54euN+isKXRzX\n zKVNi5+NRLc9k5zmPmqfo28yrRIhpn3WGvT7fHEA3oRanXn","X-Received":"by 2002:a05:600d:8402:b0:485:3af5:7e53 with SMTP id\n 5b1f17b1804b1-488fb77a36fmr16023315e9.19.1776410149998;\n Fri, 17 Apr 2026 00:15:49 -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 v2 1/3] common: memsize: add RAM size probe based on alias\n detection","Date":"Fri, 17 Apr 2026 09:13:31 +0200","Message-ID":"<20260417071546.1610330-2-ghidoliemanuele@gmail.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260417071546.1610330-1-ghidoliemanuele@gmail.com>","References":"<20260417071546.1610330-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 appear 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 | 59 ++++++++++++++++++++++++++++++++++++++++++++++++\n include/init.h   |  7 ++++++\n 2 files changed, 66 insertions(+)","diff":"diff --git a/common/memsize.c b/common/memsize.c\nindex 1abf3fc47d73..3ecf9bac2aac 100644\n--- a/common/memsize.c\n+++ b/common/memsize.c\n@@ -127,6 +127,65 @@ 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 = 0;\n+\tlong ret = 0;\n+\n+\tif (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))\n+\t\tdcache_en = dcache_status();\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":["v2","1/3"]}