public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] tools: zynqmpimage: round up partition size
@ 2018-11-28 10:47 Michael Tretter
  2018-12-03 13:14 ` Michal Simek
  2018-12-03 15:37 ` [U-Boot] [PATCH v2] " Michael Tretter
  0 siblings, 2 replies; 11+ messages in thread
From: Michael Tretter @ 2018-11-28 10:47 UTC (permalink / raw)
  To: u-boot

The FSBL copies "Total Partition Word Length" * 4 bytes from the boot.bin,
which implies that the partition size is 4 byte aligned. When writing the
partition, mkimage calculates "Total Partition Word Length" by dividing
the size by 4. This implicitly cuts unaligned bytes at the end of the
added binary.

Instead of rounding down, the size must be round up to 4 bytes and the
binary padded accordingly.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
 tools/zynqmpbif.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/tools/zynqmpbif.c b/tools/zynqmpbif.c
index 6c8f66055d..885a037da6 100644
--- a/tools/zynqmpbif.c
+++ b/tools/zynqmpbif.c
@@ -316,19 +316,29 @@ static int bif_add_pmufw(struct bif_entry *bf, const char *data, size_t len)
 	return 0;
 }
 
-static int bif_add_part(struct bif_entry *bf, const char *data, size_t len)
+static int bif_add_part(struct bif_entry *bf, char *data, size_t len)
 {
 	size_t parthdr_offset = 0;
+	size_t len_padded = ROUND(len, 4);
+
 	struct partition_header parthdr = {
-		.len_enc = cpu_to_le32(len / 4),
-		.len_unenc = cpu_to_le32(len / 4),
-		.len = cpu_to_le32(len / 4),
+		.len_enc = cpu_to_le32(len_padded / 4),
+		.len_unenc = cpu_to_le32(len_padded / 4),
+		.len = cpu_to_le32(len_padded / 4),
 		.entry_point = cpu_to_le64(bf->entry),
 		.load_address = cpu_to_le64(bf->load),
 	};
 	int r;
 	uint32_t csum;
 
+	if (len != len_padded) {
+		data = realloc(data, len_padded);
+		while (len < len_padded) {
+			data[len] = 0;
+			len++;
+		}
+	}
+
 	if (bf->flags & (1ULL << BIF_FLAG_PMUFW_IMAGE))
 		return bif_add_pmufw(bf, data, len);
 
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-12-17 17:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-28 10:47 [U-Boot] [PATCH] tools: zynqmpimage: round up partition size Michael Tretter
2018-12-03 13:14 ` Michal Simek
2018-12-03 13:42   ` Alexander Graf
2018-12-03 14:33     ` Michal Simek
2018-12-03 15:19     ` Michael Tretter
2018-12-03 15:27       ` Alexander Graf
2018-12-17 13:27     ` Michal Simek
2018-12-17 17:08       ` Michael Tretter
2018-12-03 15:37 ` [U-Boot] [PATCH v2] " Michael Tretter
2018-12-03 15:44   ` Alexander Graf
2018-12-04 11:21   ` Michal Simek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox