From 16c78cba92f0cb24d56eaa87356beaca4a2d7f56 Mon Sep 17 00:00:00 2001 From: Michael Tretter Date: Mon, 3 Dec 2018 16:37:53 +0100 Subject: tools: zynqmpimage: round up partition size 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 Reviewed-by: Alexander Graf Signed-off-by: Michal Simek --- tools/zynqmpbif.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/zynqmpbif.c b/tools/zynqmpbif.c index 6c8f66055d..a33c15e1f0 100644 --- a/tools/zynqmpbif.c +++ b/tools/zynqmpbif.c @@ -319,16 +319,25 @@ static int bif_add_pmufw(struct bif_entry *bf, const char *data, size_t len) static int bif_add_part(struct bif_entry *bf, const 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) { + char *newdata = malloc(len_padded); + memcpy(newdata, data, len); + memset(newdata + len, 0, len_padded - len); + data = newdata; + } + if (bf->flags & (1ULL << BIF_FLAG_PMUFW_IMAGE)) return bif_add_pmufw(bf, data, len); -- cgit From 775ed87ac4015c8b17bc9d828e3bafe4a0f7ed03 Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Fri, 14 Dec 2018 10:53:54 +0100 Subject: tools: zynqmpimage: Align image_size/image_stored_size Bootrom is not capable to work with non aligned bootloader sizes. SPL with OF_SEPARATE generates non-align images quite often that's why this change is required before OF_SEPARATE enableding. Signed-off-by: Michal Simek --- tools/zynqmpbif.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/zynqmpbif.c b/tools/zynqmpbif.c index a33c15e1f0..8c47107c7b 100644 --- a/tools/zynqmpbif.c +++ b/tools/zynqmpbif.c @@ -425,8 +425,8 @@ static int bif_add_part(struct bif_entry *bf, const char *data, size_t len) if (!bif_output.header->image_offset) bif_output.header->image_offset = cpu_to_le32(bf->offset); - bif_output.header->image_size = cpu_to_le32(len); - bif_output.header->image_stored_size = cpu_to_le32(len); + bif_output.header->image_size = cpu_to_le32(len_padded); + bif_output.header->image_stored_size = cpu_to_le32(len_padded); bif_output.header->image_attributes &= ~HEADER_CPU_SELECT_MASK; switch (bf->dest_cpu) { -- cgit