diff mbox series

[U-Boot,4/4] tools: imx8image: flatten container header only when creating container

Message ID 20181101064937.28731-4-peng.fan@nxp.com
State Superseded
Delegated to: Stefano Babic
Headers show
Series [U-Boot,1/4] tools: imx8image: check lseek return value | expand

Commit Message

Peng Fan Nov. 1, 2018, 6:42 a.m. UTC
If there is no CONTAINER entry, there is no need to flatten container
header.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 tools/imx8image.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/tools/imx8image.c b/tools/imx8image.c
index f3d1658f11..6ed5781979 100644
--- a/tools/imx8image.c
+++ b/tools/imx8image.c
@@ -909,17 +909,19 @@  static int build_container(soc_type_t soc, uint32_t sector_size,
 		exit(EXIT_FAILURE);
 	}
 
-	/* Note: Image offset are not contained in the image */
-	tmp = flatten_container_header(&imx_header, container + 1, &size,
-				       file_padding);
-	/* Write image header */
-	if (write(ofd, tmp, size) != size) {
-		fprintf(stderr, "error writing image hdr\n");
-		exit(EXIT_FAILURE);
-	}
+	if (container >= 0) {
+		/* Note: Image offset are not contained in the image */
+		tmp = flatten_container_header(&imx_header, container + 1,
+					       &size, file_padding);
+		/* Write image header */
+		if (write(ofd, tmp, size) != size) {
+			fprintf(stderr, "error writing image hdr\n");
+			exit(EXIT_FAILURE);
+		}
 
-	/* Clean-up memory used by the headers */
-	free(tmp);
+		/* Clean-up memory used by the headers */
+		free(tmp);
+	}
 
 	/*
 	 * step through the image stack again this time copying