Re: gzimg hashes

Brook Milligan <[email protected]> Mon, 6 Jul 2026 10:49:24 -0600
Newsgroups gmane.os.netbsd.current
Message-ID <[email protected]>
> On Jul 5, 2026, at 20:12, David H. Gutteridge <[email protected]> =
wrote:
>=20
> On Sun, 5 Jul 2026 at 17:42:17 -0600, Brook Milligan wrote:
>> I notice that the hashes generated for release files in the gzimg
>> directory cover the uncompressed files, not the compressed files
>> actually distributed.  This seems to be a mistake.
>>=20
>> The fix is clearly to reorder the hash generation relative to the
>> compression, but I=E2=80=99m checking here to make sure I=E2=80=99m =
not missing
>> something.
>>=20
>> Cheers,
>> Brook
>=20
> Yes, that's one of the issues raised in PR 59195 (and its duplicate,
> PR 60302), e.g.,
> =
https://nam10.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fmail-i=
ndex.netbsd.org%2Fnetbsd-bugs%2F2025%2F04%2F03%2Fmsg088095.html&data=3D05%=
7C02%7Cbrook%40biology.nmsu.edu%7Cce313e1520f249b728b708dedb04114e%7Ca3ec8=
7a89fb84158ba8ff11bace1ebaa%7C1%7C0%7C639189007694159583%7CUnknown%7CTWFpb=
GZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjo=
iTWFpbCIsIldUIjoyfQ%3D%3D%7C60000%7C%7C%7C&sdata=3D%2Bv5UsD4R9GqmbVitcRxAG=
%2F81hAsh4KAIIb0ILBfSbhc%3D&reserved=3D0

OK, thanks.  I have a patch, see below, that solves most of this.  It =
reverts the commit to src/distrib/utils/embedded/mkimage (rev 1.91) and =
moves the hashing to all (that I can find) users of mkimage.  This =
allows for a different use case for evbarm (mkimage -> uncompressed + =
later compression) versus the others (mkimage -> compressed).  It also =
solves the problem of only a single hash being created.

One problem remains: all the hashes are appended to MD5/SHA512, which =
means if those files exist from a prior run of build.sh then more hashes =
will be added to the old ones.  This is perhaps not quite correct.

Any suggestions on the correct handling of multiple runs is welcome, as =
is how to clean up gzimg prior to creating files there if that is the =
thing to do.  Alternatively, suggestions are welcome for retaining only =
the last hash for any of the files.

One final note: this does not integrate hashes in gzimg with hashes in =
sets, which is still likely a useful step.

Thanks for your feedback.

Cheers,
Brook


Index: distrib/utils/embedded/mkimage
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/distrib/utils/embedded/mkimage,v
retrieving revision 1.97
diff -u -r1.97 mkimage
--- distrib/utils/embedded/mkimage	22 May 2026 14:44:16 -0000	=
1.97
+++ distrib/utils/embedded/mkimage	6 Jul 2026 16:18:33 -0000
@@ -425,8 +425,4 @@
 	image=3D"${image}.gz"
 fi
=20
-cd "${IMAGEDIR}"
-${CKSUM} -a MD5 "$(basename "${image}")" > MD5
-${CKSUM} -a SHA512 "$(basename "${image}")" > SHA512
-
 echo ${bar} Image is ${image} ${bar}
Index: etc/etc.evbarm/Makefile.inc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/etc/etc.evbarm/Makefile.inc,v
retrieving revision 1.138
diff -u -r1.138 Makefile.inc
--- etc/etc.evbarm/Makefile.inc	20 Feb 2026 07:20:28 -0000	1.138
+++ etc/etc.evbarm/Makefile.inc	6 Jul 2026 16:18:34 -0000
@@ -96,8 +96,6 @@
 	MACHINE=3D${MACHINE} \
 	MKDTB=3D${MKDTB} \
 	MKPOSTFIX=3D${MKPOSTFIX} \
-	CKSUM=3D${CKSUM} \
-	IMAGEDIR=3D${IMAGE.dir} \
 	${HOST_SH} ${MKIMAGE} -h ${.TARGET:S/smp_//} -D ${DESTDIR} \
 	    -S ${NETBSDSRCDIR} -B ${IMAGEENDIAN} ${MKI_OPTS.${.TARGET}} =
\
 	    ${IMAGE.dir}/${.TARGET:S/smp_//}.img
@@ -107,10 +105,13 @@
 	@${TOOL_INSTALLBOOT} -m ${MACHINE} -o board=3D${f} \
 			${IMAGE.dir}/${.TARGET:S/smp_//}-${f}.img \
 		&& ${TOOL_GZIP} -f =
${IMAGE.dir}/${.TARGET:S/smp_//}-${f}.img \
+		&& (cd ${IMAGE.dir} && (for i in MD5 SHA512; do ${CKSUM} =
-a $${i} ${.TARGET:S/smp_//}-${f}.img.gz >> $${i}; done)) \
 		|| rm ${IMAGE.dir}/${.TARGET:S/smp_//}-${f}.img
 .endfor
 	@echo "=3D=3D=3D> Compressing image =
${IMAGE.dir}/${.TARGET:S/smp_//}.img"
 	${TOOL_GZIP} -f ${GZIP_N_FLAG} -9 =
${IMAGE.dir}/${.TARGET:S/smp_//}.img
+	@echo "=3D=3D=3D> Calculating hashes for image =
${IMAGE.dir}/${.TARGET:S/smp_//}.img.gz"
+	(cd ${IMAGE.dir} && (for i in MD5 SHA512; do ${CKSUM} -a $${i} =
${.TARGET:S/smp_//}.img.gz >> $${i}; done))
=20
 ARCHES.earmv4=3D		armv4
 ARCHES.earmv4eb=3D	armv4
Index: etc/etc.evbmips/Makefile.inc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/etc/etc.evbmips/Makefile.inc,v
retrieving revision 1.32
diff -u -r1.32 Makefile.inc
--- etc/etc.evbmips/Makefile.inc	22 Mar 2025 09:25:14 -0000	=
1.32
+++ etc/etc.evbmips/Makefile.inc	6 Jul 2026 16:18:34 -0000
@@ -70,11 +70,11 @@
 	MACHINE=3D${MACHINE} \
 	MKDTB=3D${MKDTB} \
 	MKPOSTFIX=3D${MKPOSTFIX} \
-	CKSUM=3D${CKSUM} \
-	IMAGEDIR=3D${IMAGE.dir} \
 	${HOST_SH} ${MKIMAGE} -h ${.TARGET:S/smp_//} -D ${DESTDIR} \
             -S ${NETBSDSRCDIR} -B ${IMAGEENDIAN} ${MKI_OPTS.${.TARGET}} =
\
             ${IMAGE.dir}/${.TARGET:S/smp_//}.img.gz
+        @echo "=3D=3D=3D> Calculating hashes for image =
${IMAGE.dir}/${.TARGET:S/smp_//}.img.gz"
+	(cd ${IMAGE.dir} && (for i in MD5 SHA512; do ${CKSUM} -a $${i} =
${.TARGET:S/smp_//}.img.gz >> $${i}; done))
=20
 .if !empty(MACHINE_ARCH:Mmips*64eb)
 smp_octeon: __mkimage
Index: etc/etc.evbppc/Makefile.inc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/etc/etc.evbppc/Makefile.inc,v
retrieving revision 1.22
diff -u -r1.22 Makefile.inc
--- etc/etc.evbppc/Makefile.inc	10 Jan 2026 06:56:58 -0000	1.22
+++ etc/etc.evbppc/Makefile.inc	6 Jul 2026 16:18:34 -0000
@@ -58,11 +58,11 @@
 	MACHINE=3D${MACHINE} \
 	MKDTB=3D${MKDTB} \
 	MKPOSTFIX=3D${MKPOSTFIX} \
-	CKSUM=3D${CKSUM} \
-	IMAGEDIR=3D${IMAGE.dir} \
 	${HOST_SH} -x ${MKIMAGE} -h ${.TARGET:S/smp_//} -D ${DESTDIR} \
             -S ${NETBSDSRCDIR} -B ${IMAGEENDIAN} ${MKI_OPTS.${.TARGET}} =
\
             ${IMAGE.dir}/${.TARGET:S/smp_//}.img.gz
+        @echo "=3D=3D=3D> Calculating hashes for image =
${IMAGE.dir}/${.TARGET:S/smp_//}.img.gz"
+        (cd ${IMAGE.dir} && (for i in MD5 SHA512; do ${CKSUM} -a $${i} =
${.TARGET:S/smp_//}.img.gz >> $${i}; done))
=20
 smp_nintendo: __mkimage
 	cd ${KERNSRCDIR}/arch/evbppc/stand/wii && ${MAKE} release
Index: etc/etc.riscv/Makefile.inc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/etc/etc.riscv/Makefile.inc,v
retrieving revision 1.7
diff -u -r1.7 Makefile.inc
--- etc/etc.riscv/Makefile.inc	22 Mar 2025 09:25:14 -0000	1.7
+++ etc/etc.riscv/Makefile.inc	6 Jul 2026 16:18:34 -0000
@@ -34,12 +34,11 @@
 	MACHINE=3D${MACHINE} \
 	MKDTB=3D${MKDTB} \
 	MKPOSTFIX=3D${MKPOSTFIX} \
-	CKSUM=3D${CKSUM} \
-	IMAGEDIR=3D${IMAGE.dir} \
 	${HOST_SH} ${MKIMAGE} -h ${.TARGET:S/smp_//} -D ${DESTDIR} \
             -S ${NETBSDSRCDIR} ${MKI_OPTS.${.TARGET}} \
             ${IMAGE.dir}/${.TARGET:S/smp_//}.img.gz
-
+        @echo "=3D=3D=3D> Calculating hashes for image =
${IMAGE.dir}/${.TARGET:S/smp_//}.img.gz"
+        (cd ${IMAGE.dir} && (for i in MD5 SHA512; do ${CKSUM} -a $${i} =
${.TARGET:S/smp_//}.img.gz >> $${i}; done))
=20
 .if ${MACHINE_ARCH} =3D=3D "riscv64"
 .if ${HAVE_UEFI} =3D=3D "yes"