From patchwork Sun Nov 6 15:41:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Bj=C3=B8rn_Mork?= X-Patchwork-Id: 1700299 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=mork.no header.i=@mork.no header.a=rsa-sha256 header.s=b header.b=eCEYohVm; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N52jn0mRKz23ls for ; Mon, 7 Nov 2022 05:21:01 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EF36884CB2; Sun, 6 Nov 2022 19:20:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=mork.no Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=mork.no header.i=@mork.no header.b="eCEYohVm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 98ADD841D1; Sun, 6 Nov 2022 16:41:24 +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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from louie.mork.no (louie.mork.no [IPv6:2001:41c8:51:8a:feff:ff:fe00:e5]) (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 938B384374 for ; Sun, 6 Nov 2022 16:41:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=mork.no Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=bjorn@miraculix.mork.no Received: from canardo.dyn.mork.no ([IPv6:2a01:799:c9c:2c00:0:0:0:1]) (authenticated bits=0) by louie.mork.no (8.15.2/8.15.2) with ESMTPSA id 2A6FfIkG766554 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK) for ; Sun, 6 Nov 2022 15:41:19 GMT Received: from miraculix.mork.no ([IPv6:2a01:799:c9c:2c02:34cc:c78d:869d:3d9d]) (authenticated bits=0) by canardo.dyn.mork.no (8.15.2/8.15.2) with ESMTPSA id 2A6FfDid3699868 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Sun, 6 Nov 2022 16:41:13 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1667749273; bh=QMca5yVtBsjAMPET1tSj3H+G4UZbPwKyLiUJMsqDgnQ=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=eCEYohVm6sqv2Kf/WtyiXmtVXh7C95sCAMwVYrtgKAGN2fEX9T2HLdWBoxZyoloE4 n+Gp5hui5YcA5ROxJayipX4/noJxDNQKEwcNXsTcaGgDauZP7CHkW/0lq+Rv1CCWFf zghSO9qwBdtcI9d22afMYhnVa2p5ckj1f9Z0e+E0= Received: (nullmailer pid 872264 invoked by uid 1000); Sun, 06 Nov 2022 15:41:12 -0000 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: u-boot@lists.denx.de Cc: =?utf-8?q?Bj=C3=B8rn_Mork?= Subject: [RFC v2 2/2] mkimage: Align fdt images in FIT to 8 bytes Date: Sun, 6 Nov 2022 16:41:11 +0100 Message-Id: <20221106154111.872209-3-bjorn@mork.no> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221106154111.872209-1-bjorn@mork.no> References: <20221106154111.872209-1-bjorn@mork.no> MIME-Version: 1.0 X-Mailman-Approved-At: Sun, 06 Nov 2022 19:20:30 +0100 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 "In place" configurations are strongly discouraged, but known to be used. This can cause hard to debug alignment problems since the value of the "data" property only is guaranteed to be 4-byte aligned. Unconditionally aligning fdt images to 8 byte boundaries will prevent these problems, at the maximum price of 4 bytes per fdt. Signed-off-by: Bjørn Mork --- tools/fit_image.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tools/fit_image.c b/tools/fit_image.c index 923a9755b709..1e060784895d 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -24,6 +24,41 @@ static struct legacy_img_hdr header; +/** + * fit_align_fdt_images() - Align all fdt images in the FIT to 8 bytes + * + * An fdt blob must be placed at an 8 byte aligned offset if it is to + * be used "in place". This will not be verified by U-Boot. Simply align + * all IH_TYPE_FLATDT images to prevent problems. + */ +static int fit_align_fdt_images(void *fit) +{ + int images_noffset, noffset, ret; + uint8_t type; + size_t size; + const void *ptr; + + images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); + if (images_noffset < 0) { + printf("Can't find images parent node '%s' (%s)\n", + FIT_IMAGES_PATH, fdt_strerror(images_noffset)); + return images_noffset; + } + + for (noffset = fdt_first_subnode(fit, images_noffset); + noffset >= 0; + noffset = fdt_next_subnode(fit, noffset)) { + fit_image_get_type(fit, noffset, &type); + if (type != IH_TYPE_FLATDT) + continue; + + ret = fdt_alignprop(fit, noffset, FIT_DATA_PROP, 8); + if (ret < 0) + return ret; + } + return 0; +} + static int fit_add_file_data(struct image_tool_params *params, size_t size_inc, const char *tmpfile) { @@ -81,6 +116,10 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc, ¶ms->summary); } + if (!ret) { + ret = fit_align_fdt_images(ptr); + } + if (dest_blob) { munmap(dest_blob, destfd_size); close(destfd);