Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A73A6C38A02 for ; Fri, 28 Oct 2022 17:53:56 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C9EE0850B9; Fri, 28 Oct 2022 19:53:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id BB74184EDD; Fri, 28 Oct 2022 17:52:11 +0200 (CEST) Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1CE7984E42 for ; Fri, 28 Oct 2022 17:52:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mkl@pengutronix.de Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=bjornoya.blackshift.org) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ooReS-00047X-N5; Fri, 28 Oct 2022 17:52:08 +0200 Received: from pengutronix.de (unknown [IPv6:2a01:4f8:1c1c:29e9:22:41ff:fe00:1400]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id 762D010CECD; Fri, 28 Oct 2022 15:52:07 +0000 (UTC) Date: Fri, 28 Oct 2022 17:52:05 +0200 From: Marc Kleine-Budde To: u-boot@lists.denx.de Cc: embedded@vivavis.com Subject: mkimage regression: legacy images with Image Type IH_TYPE_FLATDT Message-ID: <20221028155205.ojw6tcso2fofgnhm@pengutronix.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ijhjklmasq4uhhtp" Content-Disposition: inline X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: u-boot@lists.denx.de X-Mailman-Approved-At: Fri, 28 Oct 2022 19:53:32 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean --ijhjklmasq4uhhtp Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello! ld;dr: I want to create legacy images with Image Type IH_TYPE_FLATDT. Details: During the migration of an older system to recent yocto, we noticed that the u-boot's mkimage doesn't work anymore as expected. The system runs an older version of u-boot and requires the kernel's dtb wrapped in a legacy u-boot image. With the old u-boot (v2009.08) the following command was used to create the uimage containing the dtb: | mkimage -A arm -O linux -T flat_dt -C none -d e.g.: | $ mkimage-v2009.08-144-g449609f5b11c -A arm -O linux -T flat_dt -C none -= d ./vivavis-skalar-pro.dtb out-v2009.08-144-g449609f5b11c | Image Name: =20 | Created: Wed Feb 2 22:22:22 2022 | Image Type: ARM Linux Flat Device Tree (uncompressed) | Data Size: 21726 Bytes =3D 21.22 kB =3D 0.02 MB | Load Address: 00000000 | Entry Point: 00000000 |=20 | $ file out-v2009.08-144-g449609f5b11c | out-v2009.08-144-g449609f5b11c: u-boot legacy uImage, , Linux/ARM, | Binary Flat Device Tree BLOB (Not compressed), 21726 bytes, Wed Feb 2 | 21:22:22 2022, Load Address: 00000000, Entry Point: 00000000, Header | CRC: 0X945F44C9, Data CRC: 0XDCA9BDD With the new u-boot: | $ mkimage -A arm -O linux -T flat_dt -C none -d ./vivavis-skalar-pro.dtb = out-upstream | mkimage: Can't set header for FIT Image support: Success |=20 | echo $? | 1 The command fails. (...and prints the error message "Success". I'll send a patch to fix that). An image is (partially) generated, but it's neither a valid legacy image nor a FIT image: | $ file out-upstream = =20 | out-upstream: data |=20 | $ hexdump -C out-upstream | head -10 | 00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |............= =2E...| | * | 00000040 d0 0d fe ed 00 00 54 de 00 00 00 38 00 00 50 9c |......T....8= =2E.P.| | 00000050 00 00 00 28 00 00 00 11 00 00 00 10 00 00 00 00 |...(........= =2E...| | 00000060 00 00 04 42 00 00 50 64 00 00 00 00 00 00 00 00 |...B..Pd....= =2E...| | 00000070 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 |............= =2E...| | 00000080 00 00 00 03 00 00 00 04 00 00 00 00 00 00 00 01 |............= =2E...| | 00000090 00 00 00 03 00 00 00 04 00 00 00 0f 00 00 00 01 |............= =2E...| | 000000a0 00 00 00 03 00 00 00 13 00 00 00 1b 56 49 56 41 |............= VIVA| | 000000b0 56 49 53 20 53 6b 61 6c 61 72 2e 70 72 6f 00 00 |VIS Skalar.p= ro..| The main difference between the old u-boot and recent u-boot, is that the old u-boot (obviously) always creates legacy images, with the struct legacy_img_hdr::ih_type in the header set to the type given with the '-T' command line argument. With new mkimage, it's a bit different. The type of the -T command line parameter is used to select the actual image type. This is done by iterating over all image types and calling the check_image_type callback to find a matching image provider. The FIT image ("fit_common.c") matches on types IH_TYPE_FLATDT (which corresponds to "-T flat_dt") while the legacy image ("tools/default_image.c") matches on the following image types: IH_TYPE_STANDALONE, /* Standalone Program */ IH_TYPE_KERNEL, /* OS Kernel Image */ IH_TYPE_RAMDISK, /* RAMDisk Image */ IH_TYPE_MULTI, /* Multi-File Image */ IH_TYPE_FIRMWARE, /* Firmware Image */ IH_TYPE_SCRIPT, /* Script file */ IH_TYPE_FILESYSTEM, /* Filesystem Image (any type) */ For work around the problem, I disabled FIT image support entirely and let the legacy image pick up IH_TYPE_FLATDT, too: diff --git a/tools/default_image.c b/tools/default_image.c index 4a067e65862e..ab145001e49d 100644 --- a/tools/default_image.c +++ b/tools/default_image.c @@ -26,7 +26,7 @@ static struct legacy_img_hdr header; =20 static int image_check_image_types(uint8_t type) { - if (((type > IH_TYPE_INVALID) && (type < IH_TYPE_FLATDT)) || + if (((type > IH_TYPE_INVALID) && (type <=3D IH_TYPE_FLATDT)) || (type =3D=3D IH_TYPE_KERNEL_NOLOAD) || (type =3D=3D IH_TYPE_FIR= MWARE_IVT)) return EXIT_SUCCESS; else diff --git a/tools/fit_common.c b/tools/fit_common.c index 01649760ac00..a967449103f0 100644 --- a/tools/fit_common.c +++ b/tools/fit_common.c @@ -43,9 +43,11 @@ int fit_verify_header(unsigned char *ptr, int image_size, =20 int fit_check_image_types(uint8_t type) { +#if 0 if (type =3D=3D IH_TYPE_FLATDT) return EXIT_SUCCESS; else +#endif return EXIT_FAILURE; } I though of adding a command line parameter to force legacy images, regardless of the -T value (which means passing the parsed command line parameters down into the check_image_type callback). Are the better options or am I using mkimage wrong? regards, Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | --ijhjklmasq4uhhtp Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEBsvAIBsPu6mG7thcrX5LkNig010FAmNb+qMACgkQrX5LkNig 012LwQf/XKKBnXaHeRGDxZTAaYGugGB0NLXAW8E2v9htzUCDlitB1VJDyo9NHZqK JBsaz9OKcxY18gOmhQSsfEHvA8sENKsURYhRzlgl2yTz6z0VjCbmRwYsdk8skA2L sLBd9hOcWBkLNbc314QILw2/f34WQmztwY+MViKByi7+92VbpAd3ZzF25TnypVm/ zKztN1xDYFqBzdypfATRiCiPYF6RkyWFUYARhH2ZmvmqoK66+MsY53fGGpXmYUsz NTpw2+V6EPQ6RKbaJGlwGCgrSwjWWkJrRx9WCwhpftO023dsgVy4p379DXZuvPqj ZCEjUP5Ck+jmsrg5Mq7G+CA8kdCzuQ== =ArIi -----END PGP SIGNATURE----- --ijhjklmasq4uhhtp--