Index: usr.bin/mkubootimage/mkubootimage.c =================================================================== RCS file: /cvsroot/src/usr.bin/mkubootimage/mkubootimage.c,v retrieving revision 1.27 diff -u -p -r1.27 mkubootimage.c --- usr.bin/mkubootimage/mkubootimage.c 7 Dec 2019 12:34:17 -0000 1.27 +++ usr.bin/mkubootimage/mkubootimage.c 1 Jan 2020 10:11:56 -0000 @@ -334,7 +334,8 @@ generate_header_uimg(struct uboot_image_ 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 @@ generate_header_arm64(struct arm64_image 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);