ath79: dongwon-header: don't read the CRC from a pipe with dd

The factory image of the Dongwon DW02-412H sometimes carries a broken
header CRC, as seen by the rebuilder:

  -Header CRC: 0X990A0000
  +Header CRC: 0X990A9FB7

The CRC is written with printf piped into dd bs=4 count=1. Bash's printf
writes its output line buffered, so a CRC holding a 0x0a byte is written
in two parts:

  write(1, "\231\n", 2) = 2
  write(1, "\237\267", 2) = 2

If dd reads the pipe between the two writes, it gets a short block, and
with count=1 it stops there and leaves the rest of the CRC zero. This
depends on the scheduling, so busy builders hit it while idle machines
almost never do. Delaying the writes reproduces it every time:

  old: CRC be f8 0a 00
  new: CRC be f8 0a 17

Put the header together by concatenation instead, so the image no longer
goes through dd. Without the race, the output is the same as before
(300 random kernels, all identical and with valid CRCs).

Link: https://github.com/openwrt/openwrt/pull/25867
Signed-off-by: Paul Spooren <mail@aparcar.org>
This commit is contained in:
Paul Spooren committed 2026-10-13 21:13:27 +02:00
1 parent beda530aac
commit f6ef30a35e
1 file changed
+5 -4
+5 -4
View File
@@ -5,10 +5,11 @@ define Build/dongwon-header
( \
header_crc="$$(head -c 68 $@.tmp | gzip -c | \
tail -c 8 | od -An -N4 -tx4 --endian little | tr -d ' \n')"; \
printf "$$(echo $$header_crc | sed 's/../\\x&/g')" | \
dd of=$@.tmp bs=4 count=1 seek=1 conv=notrunc \
)
mv $@.tmp $@
head -c 4 $@.tmp; \
printf "$$(echo $$header_crc | sed 's/../\\x&/g')"; \
tail -c +9 $@.tmp; \
) > $@
rm -f $@.tmp
endef
define Build/meraki-header