From 880b9e8b4c99ad99eee14079d5a6162733ef4931 Mon Sep 17 00:00:00 2001 From: Roberto Vargas Date: Tue, 19 Dec 2017 11:56:57 +0000 Subject: [PATCH 1/2] Add padding at the end of the last entry This patch adds padding bytes at the end of the last image in the fip to be able to transfer by DMA the last image. Change-Id: I8c6f07dee389cb3d1dc919936d9d52841d7e5723 Signed-off-by: Roberto Vargas Signed-off-by: Dimitris Papastamos Signed-off-by: David Cunado --- tools/fiptool/fiptool.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/fiptool/fiptool.c b/tools/fiptool/fiptool.c index 1dcb7e8e6..33c451e4e 100644 --- a/tools/fiptool/fiptool.c +++ b/tools/fiptool/fiptool.c @@ -492,7 +492,7 @@ static int pack_images(const char *filename, uint64_t toc_flags, unsigned long a fip_toc_header_t *toc_header; fip_toc_entry_t *toc_entry; char *buf; - uint64_t entry_offset, buf_size, payload_size = 0; + uint64_t entry_offset, buf_size, payload_size = 0, pad_size; size_t nr_images = 0; for (desc = image_desc_head; desc != NULL; desc = desc->next) @@ -526,9 +526,13 @@ static int pack_images(const char *filename, uint64_t toc_flags, unsigned long a entry_offset += image->toc_e.size; } - /* Append a null uuid entry to mark the end of ToC entries. */ + /* + * Append a null uuid entry to mark the end of ToC entries. + * NOTE the offset address for the last toc_entry must match the fip + * size. + */ memset(toc_entry, 0, sizeof(*toc_entry)); - toc_entry->offset_address = entry_offset; + toc_entry->offset_address = (entry_offset + align - 1) & ~(align - 1); /* Generate the FIP file. */ fp = fopen(filename, "wb"); @@ -555,6 +559,13 @@ static int pack_images(const char *filename, uint64_t toc_flags, unsigned long a xfwrite(image->buffer, image->toc_e.size, fp, filename); } + if (fseek(fp, entry_offset, SEEK_SET)) + log_errx("Failed to set file position"); + + pad_size = toc_entry->offset_address - entry_offset; + while (pad_size--) + fputc(0x0, fp); + fclose(fp); return 0; } From 4069fb5f39448693c51cb50c4891462a25856a9f Mon Sep 17 00:00:00 2001 From: Jett Zhou Date: Fri, 24 Nov 2017 16:03:58 +0800 Subject: [PATCH 2/2] docs: Update the ToC end marker description in the document Change-Id: I2e29a63f08aed3b8ea0bb10170a3d55b8d033e62 Signed-off-by: Jett Zhou Signed-off-by: David Cunado --- docs/firmware-design.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/firmware-design.rst b/docs/firmware-design.rst index 405964d24..3cb004a4c 100644 --- a/docs/firmware-design.rst +++ b/docs/firmware-design.rst @@ -1868,9 +1868,11 @@ Firmware Image Package layout The FIP layout consists of a table of contents (ToC) followed by payload data. The ToC itself has a header followed by one or more table entries. The ToC is -terminated by an end marker entry. All ToC entries describe some payload data -that has been appended to the end of the binary package. With the information -provided in the ToC entry the corresponding payload data can be retrieved. +terminated by an end marker entry, and since the size of the ToC is 0 bytes, +the offset equals the total size of the FIP file. All ToC entries describe some +payload data that has been appended to the end of the binary package. With the +information provided in the ToC entry the corresponding payload data can be +retrieved. ::