{"id":1745910,"url":"http://patchwork.ozlabs.org/api/patches/1745910/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/20230221201925.9644-18-pali@kernel.org/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/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":"<20230221201925.9644-18-pali@kernel.org>","list_archive_url":null,"date":"2023-02-21T20:18:43","name":"[RFC,u-boot-mvebu,17/59] tools: kwboot: Add check that kwbimage contains DDR init code","commit_ref":"a190667b111bd2731a8cef173c0e84e14fb14218","pull_url":null,"state":"accepted","archived":false,"hash":"52ffe71ec61779a28a51638cb670fa4a261f5333","submitter":{"id":78810,"url":"http://patchwork.ozlabs.org/api/people/78810/?format=json","name":"Pali Rohár","email":"pali@kernel.org"},"delegate":{"id":1696,"url":"http://patchwork.ozlabs.org/api/users/1696/?format=json","username":"stroese","first_name":"Stefan","last_name":"Roese","email":"sr@denx.de"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20230221201925.9644-18-pali@kernel.org/mbox/","series":[{"id":343058,"url":"http://patchwork.ozlabs.org/api/series/343058/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=343058","date":"2023-02-21T20:18:27","name":"arm: mvebu: Various fixes","version":1,"mbox":"http://patchwork.ozlabs.org/series/343058/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/1745910/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/1745910/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 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=<UNKNOWN>)","legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=XstpJKGj;\n\tdkim-atps=neutral","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=kernel.org","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=kernel.org header.i=@kernel.org header.b=\"XstpJKGj\";\n\tdkim-atps=neutral","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=kernel.org","phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org"],"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 (P-384) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4PLrcQ22lYz23j7\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Feb 2023 07:34:30 +1100 (AEDT)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 46F7885AE6;\n\tTue, 21 Feb 2023 21:25:20 +0100 (CET)","by phobos.denx.de (Postfix, from userid 109)\n id 97F4385AFC; Tue, 21 Feb 2023 21:24:01 +0100 (CET)","from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75])\n (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id 4FE8085AAC\n for <u-boot@lists.denx.de>; Tue, 21 Feb 2023 21:22:33 +0100 (CET)","from smtp.kernel.org (relay.kernel.org [52.25.139.140])\n (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n (No client certificate requested)\n by ams.source.kernel.org (Postfix) with ESMTPS id F1099B81098;\n Tue, 21 Feb 2023 20:22:32 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 630A7C433AC;\n Tue, 21 Feb 2023 20:22:31 +0000 (UTC)","by pali.im (Postfix)\n id 0AE332B55; Tue, 21 Feb 2023 21:22:30 +0100 (CET)"],"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,DKIMWL_WL_HIGH,\n DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,\n SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n s=k20201202; t=1677010951;\n bh=LBYvVR5kO39sbPIG0sxUaJZr8qaPTLWuFPtiXl3g7FA=;\n h=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n b=XstpJKGjEaWe+xzqmCJykbyiwQudtS6ESIJk0k25CHs8juOsq/K3AlvEwonpVMHNo\n 8y2yhIOm1i1rv6v4HcpG6lImC8KLKS6TeqM2xOu5Gu9XpkrQ44Ti53GGq7uRW+ztzc\n s0rrFDRsONXZJ1TJPtdUTxxtVwrdUAVDVvsF6CWiVmUAtSioiDbbOXR4MOEYUlxNTG\n A7EFEaYkAJGAMr6v9O0Qjvk/ducfiVNhtQPRvJwTMcD18ukEjq3wGcxs9yO+QWB36L\n /yKhj3ecL3m5wP71j7p1CtK93Fej5uzaIHy4aqH6NNePZepHk5iIZbJNuB2JWND9rg\n lKKeVEofO3e8w==","From":"=?utf-8?q?Pali_Roh=C3=A1r?= <pali@kernel.org>","To":"u-boot@lists.denx.de","Cc":"Stefan Roese <sr@denx.de>, Tony Dinh <mibodhi@gmail.com>,\n Josua Mayer <josua@solid-run.com>","Subject":"[PATCH RFC u-boot-mvebu 17/59] tools: kwboot: Add check that kwbimage\n contains DDR init code","Date":"Tue, 21 Feb 2023 21:18:43 +0100","Message-Id":"<20230221201925.9644-18-pali@kernel.org>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20230221201925.9644-1-pali@kernel.org>","References":"<20230221201925.9644-1-pali@kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","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.6 at phobos.denx.de","X-Virus-Status":"Clean"},"content":"Some NOR images may be execute-in-place and do not contain DDR init code in\nits kwbimage header. Such images cannot be booted over UART as BootROM\nloads them to RAM. Add check that kwbimage contains DDR init code in its\nheader (either as binary code header or as the simple register-value set).\n\nIn some cases it is possible to load very small image into L2SRAM and when\nDDR init code is not required. So check for L2SRAM load address and skip\nDDR init code check in this case.\n\nSigned-off-by: Pali Rohár <pali@kernel.org>\n---\n tools/kwboot.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 48 insertions(+)","diff":"diff --git a/tools/kwboot.c b/tools/kwboot.c\nindex c8c7a8d24658..f624edc7798f 100644\n--- a/tools/kwboot.c\n+++ b/tools/kwboot.c\n@@ -1780,6 +1780,47 @@ kwboot_img_is_secure(void *img)\n \treturn 0;\n }\n \n+static int\n+kwboot_img_has_ddr_init(void *img)\n+{\n+\tconst struct register_set_hdr_v1 *rhdr;\n+\tconst struct main_hdr_v0 *hdr0;\n+\tstruct opt_hdr_v1 *ohdr;\n+\tu32 ohdrsz;\n+\tint last;\n+\n+\t/*\n+\t * kwbimage v0 image headers contain DDR init code either in\n+\t * extension header or in binary code header.\n+\t */\n+\tif (kwbimage_version(img) == 0) {\n+\t\thdr0 = img;\n+\t\treturn hdr0->ext || hdr0->bin;\n+\t}\n+\n+\t/*\n+\t * kwbimage v1 image headers contain DDR init code either in binary\n+\t * code header or in a register set list header with SDRAM_SETUP.\n+\t */\n+\tfor_each_opt_hdr_v1 (ohdr, img) {\n+\t\tif (ohdr->headertype == OPT_HDR_V1_BINARY_TYPE)\n+\t\t\treturn 1;\n+\t\tif (ohdr->headertype == OPT_HDR_V1_REGISTER_TYPE) {\n+\t\t\trhdr = (const struct register_set_hdr_v1 *)ohdr;\n+\t\t\tohdrsz = opt_hdr_v1_size(ohdr);\n+\t\t\tif (ohdrsz >= sizeof(*ohdr) + sizeof(rhdr->data[0].last_entry)) {\n+\t\t\t\tohdrsz -= sizeof(*ohdr) + sizeof(rhdr->data[0].last_entry);\n+\t\t\t\tlast = ohdrsz / sizeof(rhdr->data[0].entry);\n+\t\t\t\tif (rhdr->data[last].last_entry.delay ==\n+\t\t\t\t    REGISTER_SET_HDR_OPT_DELAY_SDRAM_SETUP)\n+\t\t\t\t\treturn 1;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n static void *\n kwboot_img_grow_data_right(void *img, size_t *size, size_t grow)\n {\n@@ -2011,6 +2052,13 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)\n \t\tkwboot_img_grow_data_right(img, size, sizeof(uint32_t));\n \t}\n \n+\tif (!kwboot_img_has_ddr_init(img) &&\n+\t    (le32_to_cpu(hdr->destaddr) < 0x40000000 ||\n+\t     le32_to_cpu(hdr->destaddr) + le32_to_cpu(hdr->blocksize) > 0x40034000)) {\n+\t\tfprintf(stderr, \"Image does not contain DDR init code needed for UART booting\\n\");\n+\t\tgoto err;\n+\t}\n+\n \tis_secure = kwboot_img_is_secure(img);\n \n \tif (hdr->blockid != IBR_HDR_UART_ID) {\n","prefixes":["RFC","u-boot-mvebu","17/59"]}