All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: Stefan Roese <sr@denx.de>
Cc: "Marek Behún" <marek.behun@nic.cz>, 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	[thread overview]
Message-ID: <20211021144609.9319-2-pali@kernel.org> (raw)
In-Reply-To: <20211021144609.9319-1-pali@kernel.org>

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 <pali@kernel.org>
---
 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


  reply	other threads:[~2021-10-21 14:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21 14:46 [PATCH 0/4] arm: mvebu: Fix usage of BIN header arguments Pali Rohár
2021-10-21 14:46 ` Pali Rohár [this message]
2021-10-22  6:47   ` [PATCH 1/4] tools: kwboot: Align UART baudrate change code in BIN header to 128-bit boundary Stefan Roese
2021-10-21 14:46 ` [PATCH 2/4] tools: kwbimage: Align BIN header executable code " Pali Rohár
2021-10-22  6:47   ` Stefan Roese
2021-10-21 14:46 ` [PATCH 3/4] arm: mvebu: Add documentation for save_boot_params() function Pali Rohár
2021-10-22  6:47   ` Stefan Roese
2021-10-21 14:46 ` [PATCH 4/4] arm: mvebu: Remove dummy BIN header arguments for SPL binary Pali Rohár
2021-10-22  6:48   ` Stefan Roese
2021-10-28 10:48 ` [PATCH 0/4] arm: mvebu: Fix usage of BIN header arguments Stefan Roese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211021144609.9319-2-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=marek.behun@nic.cz \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.