Wed Jan 1 10:35:10 2020 UTC ()
Adjust image size appropriately when using update_image

OK jmcneill


(skrll)
diff -r1.27 -r1.28 src/usr.bin/mkubootimage/mkubootimage.c

cvs diff -r1.27 -r1.28 src/usr.bin/mkubootimage/mkubootimage.c (expand / switch to context diff)
--- src/usr.bin/mkubootimage/mkubootimage.c 2019/12/07 12:34:17 1.27
+++ src/usr.bin/mkubootimage/mkubootimage.c 2020/01/01 10:35:10 1.28
@@ -1,4 +1,4 @@
-/* $NetBSD: mkubootimage.c,v 1.27 2019/12/07 12:34:17 wiz Exp $ */
+/* $NetBSD: mkubootimage.c,v 1.28 2020/01/01 10:35:10 skrll Exp $ */
 
 /*-
  * Copyright (c) 2010 Jared D. McNeill <jmcneill@invisible.ca>
@@ -30,7 +30,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: mkubootimage.c,v 1.27 2019/12/07 12:34:17 wiz Exp $");
+__RCSID("$NetBSD: mkubootimage.c,v 1.28 2020/01/01 10:35:10 skrll Exp $");
 
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -334,7 +334,8 @@
 		iov[2].iov_len = st.st_size;
 		crc = crc32v(iov, 3);
 	} else {
-		dsize = st.st_size;
+		dsize = update_image ?
+		    st.st_size - sizeof(*hdr) : st.st_size;
 		crc = crc32(p, st.st_size);
 	}
 	munmap(p, st.st_size);
@@ -387,10 +388,13 @@
 	flags |= ARM64_FLAGS_PHYS_PLACEMENT_ANY;
 #endif
 
+	const uint64_t dsize = update_image ?
+	   st.st_size - sizeof(*hdr) : st.st_size;
+
 	memset(hdr, 0, sizeof(*hdr));
 	hdr->code0 = htole32(ARM64_CODE0);
 	hdr->text_offset = htole64(image_entrypoint);
-	hdr->image_size = htole64(st.st_size + sizeof(*hdr));
+	hdr->image_size = htole64(dsize);
 	hdr->flags = htole32(flags);
 	hdr->magic = htole32(ARM64_MAGIC);