From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64641C433EF for ; Thu, 21 Oct 2021 14:47:48 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7D248611CE for ; Thu, 21 Oct 2021 14:47:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7D248611CE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 71B36834F4; Thu, 21 Oct 2021 16:47:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="FaFyy3d/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1CCE483488; Thu, 21 Oct 2021 16:47:11 +0200 (CEST) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3F4DB8346A for ; Thu, 21 Oct 2021 16:47:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 87B5F6121F; Thu, 21 Oct 2021 14:46:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634827618; bh=6Yv7XhEuY7qq4dEOuLB51hAK9IsELq3rfZ1w/7CciZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FaFyy3d/7G+IdgeJsBpH+ZxsMjYpOMMuJWPjXSQ/rzPzZvVtzZsrlNZiwWerHbYMX X0EJUX+yPUse0cwILzLFWioF4NvrV2yZ3C4zitG90gb+VY1xBOVUvuinoKXZPkbysu UPw5CZsZ0KMJitz2Beeb85mSIRGOx1q8rgRK5mHt6xqgon6lNbrUHJlzuKJXaZCh3u Uz0YOCnkAFc0nzWnGYRwbmFtamvqYzcKd1PgijNCHhZHt9JaQ6Pi39lEOZAKI5N8nt JwwZXsWTf/X7rt6OTzAedqdckjk1lVcwaylTqMue5gcYo4eOULvw1x1FDsIhI/zaRs hJMccD3txk19g== Received: by pali.im (Postfix) id B64D48A4; Thu, 21 Oct 2021 16:46:56 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese Cc: =?UTF-8?q?Marek=20Beh=C3=BAn?= , u-boot@lists.denx.de Subject: [PATCH 1/4] tools: kwboot: Align UART baudrate change code in BIN header to 128-bit boundary Date: Thu, 21 Oct 2021 16:46:06 +0200 Message-Id: <20211021144609.9319-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211021144609.9319-1-pali@kernel.org> References: <20211021144609.9319-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.34 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.2 at phobos.denx.de X-Virus-Status: Clean ARM executable code inside the BIN header on some mvebu platforms (e.g. A370, AXP) must always be aligned with the 128-bit boundary. This requirement can be met by inserting dummy arguments into BIN header. Signed-off-by: Pali Rohár --- tools/kwboot.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/kwboot.c b/tools/kwboot.c index 6a1a030308e7..36d0cab29d1f 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -255,7 +255,7 @@ static unsigned char kwboot_baud_code[] = { }; #define KWBOOT_BAUDRATE_BIN_HEADER_SZ (sizeof(kwboot_baud_code) + \ - sizeof(struct opt_hdr_v1) + 8) + sizeof(struct opt_hdr_v1) + 8 + 16) static const char kwb_baud_magic[16] = "$baudratechange"; @@ -1328,11 +1328,10 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz) { struct main_hdr_v1 *hdr = img; struct opt_hdr_v1 *ohdr; + uint32_t num_args; + uint32_t offset; uint32_t ohdrsz; - ohdrsz = binsz + 8 + sizeof(*ohdr); - kwboot_img_grow_hdr(img, size, ohdrsz); - if (hdr->ext & 0x1) { for_each_opt_hdr_v1 (ohdr, img) if (opt_hdr_v1_next(ohdr) == NULL) @@ -1345,13 +1344,26 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz) ohdr = (void *)(hdr + 1); } + /* + * ARM executable code inside the BIN header on some mvebu platforms + * (e.g. A370, AXP) must always be aligned with the 128-bit boundary. + * This requirement can be met by inserting dummy arguments into + * BIN header, if needed. + */ + offset = &ohdr->data[4] - (char *)img; + num_args = ((16 - offset % 16) % 16) / sizeof(uint32_t); + + ohdrsz = sizeof(*ohdr) + 4 + 4 * num_args + binsz + 4; + kwboot_img_grow_hdr(hdr, size, ohdrsz); + ohdr->headertype = OPT_HDR_V1_BINARY_TYPE; ohdr->headersz_msb = ohdrsz >> 16; ohdr->headersz_lsb = cpu_to_le16(ohdrsz & 0xffff); memset(&ohdr->data[0], 0, ohdrsz - sizeof(*ohdr)); + *(uint32_t *)&ohdr->data[0] = cpu_to_le32(num_args); - return &ohdr->data[4]; + return &ohdr->data[4 + 4 * num_args]; } static void -- 2.20.1