[{"id":3063716,"web_url":"http://patchwork.ozlabs.org/comment/3063716/","msgid":"<CAJaLiFyxGUe7SEuFEUNhOKXCycGF8BpD4oDrEoYkALW4sZR2qA@mail.gmail.com>","list_archive_url":null,"date":"2023-02-23T05:23:16","subject":"Re: [PATCH RFC u-boot-mvebu 15/59] tools: kwboot: Fix parsing UART\n image without data checksum","submitter":{"id":74035,"url":"http://patchwork.ozlabs.org/api/people/74035/","name":"Tony Dinh","email":"mibodhi@gmail.com"},"content":"Hi Pali,\n\nOn Tue, Feb 21, 2023 at 12:22 PM Pali Rohár <pali@kernel.org> wrote:\n>\n> The 32-bit data checksum in UART image is not checked by the BootROM and\n> also Marvell tools do not generate it.\n>\n> So if data checksum stored in UART image does not match calculated checksum\n> from the image then treat those checksum bytes as part of the executable\n> image code (and not as the checksum) and for compatibility with the rest of\n> the code manually insert data checksum into the in-memory image after the\n> executable code, without overwriting it.\n>\n> This should allow to boot UART images generated by Marvell tools.\n\nTested with GTI Mirabox (Armada 370). Using the stock u-boot image\nfrom NAND mtd0 (nanddump), I've modified the u-boot CONFIG_SYS_PROMPT\ntext using hexedit. The image checksum should be invalid after that.\nNew kwboot booted it without problem.\n\nTested-by: Tony Dinh <mibodhi@gmail.com>\n\nThanks,\nTony\n\n>\n> Signed-off-by: Pali Rohár <pali@kernel.org>\n> ---\n>  tools/kwboot.c | 15 +++++++++++++--\n>  1 file changed, 13 insertions(+), 2 deletions(-)\n>\n> diff --git a/tools/kwboot.c b/tools/kwboot.c\n> index 7a7dd5bf3d7b..da840864b565 100644\n> --- a/tools/kwboot.c\n> +++ b/tools/kwboot.c\n> @@ -1990,8 +1990,18 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)\n>             *size < le32_to_cpu(hdr->srcaddr) + le32_to_cpu(hdr->blocksize))\n>                 goto err;\n>\n> -       if (kwboot_img_csum32(img) != *kwboot_img_csum32_ptr(img))\n> -               goto err;\n> +       /*\n> +        * The 32-bit data checksum is optional for UART image. If it is not\n> +        * present (checksum detected as invalid) then grow data part of the\n> +        * image for the checksum, so it can be inserted there.\n> +        */\n> +       if (kwboot_img_csum32(img) != *kwboot_img_csum32_ptr(img)) {\n> +               if (hdr->blockid != IBR_HDR_UART_ID) {\n> +                       fprintf(stderr, \"Image has invalid data checksum\\n\");\n> +                       goto err;\n> +               }\n> +               kwboot_img_grow_data_right(img, size, sizeof(uint32_t));\n> +       }\n>\n>         is_secure = kwboot_img_is_secure(img);\n>\n> @@ -2256,6 +2266,7 @@ main(int argc, char **argv)\n>                                  KWBOOT_XM_BLKSZ +\n>                                  sizeof(kwboot_baud_code) +\n>                                  sizeof(kwboot_baud_code_data_jump) +\n> +                                sizeof(uint32_t) +\n>                                  KWBOOT_XM_BLKSZ;\n>\n>         if (imgpath) {\n> --\n> 2.20.1\n>","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=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20210112 header.b=BjsHc5N1;\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=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=\"BjsHc5N1\";\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=mibodhi@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 (P-384) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4PMhJf6gzwz245y\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Feb 2023 16:23:45 +1100 (AEDT)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id DD45285AC6;\n\tThu, 23 Feb 2023 06:23:34 +0100 (CET)","by phobos.denx.de (Postfix, from userid 109)\n id 5D80185A68; Thu, 23 Feb 2023 06:23:32 +0100 (CET)","from mail-vs1-xe34.google.com (mail-vs1-xe34.google.com\n [IPv6:2607:f8b0:4864:20::e34])\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 B7D5D85ACE\n for <u-boot@lists.denx.de>; Thu, 23 Feb 2023 06:23:28 +0100 (CET)","by mail-vs1-xe34.google.com with SMTP id j14so13343016vse.3\n for <u-boot@lists.denx.de>; Wed, 22 Feb 2023 21:23:28 -0800 (PST)"],"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,DKIM_SIGNED,\n DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE,\n SPF_PASS autolearn=ham autolearn_force=no version=3.4.2","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:from:to:cc:subject:date\n :message-id:reply-to;\n bh=jHZIIBQleP6gdB5GGo1s+ovodLO0HijxJFRsrX+pd8w=;\n b=BjsHc5N1g0sMRdptCdiMIN8jcpm39MSftVdcrL8fZsZUn4jClrwpGUXdDo+P2AtX1f\n GnKfxP3Zf7hRYNn4e6C7gBmGFlqBvFIktDGdeEMFswRv157PgIvfqqETZFy6LVFZqXTa\n 36HfD7I4vKRAG410aVD/IRBo0SQ2Wrt9zv4CIdJ0B60XCBOJZSolQpyKkk3XX5lmggMf\n 5eCAUs/iY1Q5RGDJ4tV23wIdCRXfSHOgIfHNCGOPDGGBLxvTbMWmJyu3vBzUrnzmwpUj\n Hdh12+Tsx4GL8TiBZmk5KaLUz21Hsu80Fo8wuycGd5cQ2sxjDYg6RDhfRGqR2UQY+9LR\n rJfw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20210112;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=jHZIIBQleP6gdB5GGo1s+ovodLO0HijxJFRsrX+pd8w=;\n b=fDTcdUU2MSQhFpcpY/Ke4u2c50jUSoyx/600Rjp0l1ffQt0Ff5wsrebA0fVTf4A96y\n XKaKU4ygaSH/qPUCe8vxKua89xV/zjFVouT6UrjjqW3ahhw+7GK9i8lo7Kl8SgM45Hqm\n 5TqCLP1ESGmmIRn1r3ZoOe2+O8d2dKHT0lnUs5PigQId5oJhZsmlHM9C0JY9v2nHgkGA\n EquQcHZBWAv4xVfxC7E3lru/k+Xs6CisJ5jYccKJ+Vi3xud1pjT3Z/iOEVMYtIyUTIMF\n h3EaUryL5Flrb9M7C+gwzAlwRs0meH2CpWHwN/yJ2vkil8eEGvOOg0/jVfAGK3gunrmi\n 6hXw==","X-Gm-Message-State":"AO0yUKXe36yjRJTc+kCJ6VhwKjKV6+kLC7MHYfEQpcn4VJHTDnTLcFpj\n IQEY9SOWgxufjGyN/vytNvxoxj/+OJ2jkcAEDCA=","X-Google-Smtp-Source":"\n AK7set/arHAJTKJpBBBREoIrKqnteZyt1pVIelevBTn9E3T0NaLngmQhxKC4Z7A+VFL/vkuyEwQJdDKrWY18jNCmiiI=","X-Received":"by 2002:ab0:54da:0:b0:687:afc8:ffb9 with SMTP id\n q26-20020ab054da000000b00687afc8ffb9mr1854869uaa.2.1677129807297; Wed, 22 Feb\n 2023 21:23:27 -0800 (PST)","MIME-Version":"1.0","References":"<20230221201925.9644-1-pali@kernel.org>\n <20230221201925.9644-16-pali@kernel.org>","In-Reply-To":"<20230221201925.9644-16-pali@kernel.org>","From":"Tony Dinh <mibodhi@gmail.com>","Date":"Wed, 22 Feb 2023 21:23:16 -0800","Message-ID":"\n <CAJaLiFyxGUe7SEuFEUNhOKXCycGF8BpD4oDrEoYkALW4sZR2qA@mail.gmail.com>","Subject":"Re: [PATCH RFC u-boot-mvebu 15/59] tools: kwboot: Fix parsing UART\n image without data checksum","To":"=?utf-8?q?Pali_Roh=C3=A1r?= <pali@kernel.org>","Cc":"u-boot@lists.denx.de, Stefan Roese <sr@denx.de>,\n Josua Mayer <josua@solid-run.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","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"}}]