Files
openwrt/tools/coreutils/Makefile
T
Paul Spooren de24245e08 build: read full blocks from pipes in image headers
Many image recipes write header fields with printf or echo piped into
dd bs=N count=1 conv=sync. Bash writes the output of both line
buffered, so a field holding a 0x0a byte reaches the pipe in two writes.
If dd reads between them, it gets a short block, pads it with zeros due
to conv=sync and stops due to count=1, so the rest of the field is
lost. This depends on the scheduling of the builder, and the rebuilder
has caught it in a ZNET header of the Zyxel WSM20:

  -00000000: 5a4e 4554 80cd 7900 530a 4132 530a 0000  ZNET..y.S.A2S...
  +00000000: 5a4e 4554 80cd 7900 530a 4132 530a 4132  ZNET..y.S.A2S.A2

Fields holding sizes, CRCs or MD5 sums hit this at random, e.g. in
elx-header, iodata-mstc-header2, seil-header or nec-fw. Text fields
only hit it if they contain a newline, but they use the same pattern.
dongwon-header had the same problem and no longer uses dd since
commit f6ef30a35e ("ath79: dongwon-header: don't read the CRC from a
pipe with dd").

Pass iflag=fullblock to every dd that reads such a pipe with count= or
conv=sync, so dd reads until the block is full or the input ends.
dd with bs=1 is left alone, as a read always returns a full block there.

iflag=fullblock is supported by GNU and uutils dd, like
oflag=seek_bytes already used in ramips. Build dd in tools/coreutils as
well, so hosts other than Linux get GNU dd next to the GNU date and
stat the images already need.

Link: https://github.com/openwrt/openwrt/pull/25897
Signed-off-by: Paul Spooren <mail@aparcar.org>
2026-10-14 18:40:19 +02:00

83 lines
2.4 KiB
Makefile

#
# Copyright (C) 2015 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=coreutils
PKG_CPE_ID:=cpe:/a:gnu:coreutils
PKG_VERSION:=9.6
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@GNU/coreutils
PKG_HASH:=2bec616375002c92c1ed5ead32a092b174fe44c14bc736d32e5961053b821d84
HOST_BUILD_PARALLEL := 1
PKG_PROGRAMS:=chown cp date dd ginstall ln readlink realpath rmdir seq stat touch
include $(INCLUDE_DIR)/host-build.mk
export GNULIB_SRCDIR:=$(HOST_GNULIB_SRCDIR)
HOST_GNULIB_SKIP := \
lib/iconv_open-aix.gperf \
lib/iconv_open-hpux.gperf \
lib/iconv_open-irix.gperf \
lib/iconv_open-osf.gperf \
lib/iconv_open-solaris.gperf \
lib/iconv_open-zos.gperf
HOST_CONFIGURE_ARGS += \
--enable-install-program=$(subst $(space),$(comma),$(strip $(PKG_PROGRAMS)))
HOST_MAKE_FLAGS += \
$(AM_TOOL_PATHS) AUTOPOINT="$(TRUE)" GTKDOCIZE="$(TRUE)" \
am__CONFIG_DISTCLEAN_FILES= \
MAINTAINERCLEANFILES='$$$$(filter-out lib/iconv_open% %.texi,$$$$(BUILT_SOURCES))' \
PROGRAMS="$(patsubst %,src/%,$(PKG_PROGRAMS))" \
LIBRARIES= MANS= SUBDIRS=.
define Host/Bootstrap
( \
cd $(HOST_BUILD_DIR); \
$(AM_TOOL_PATHS) AUTOPOINT="$(TRUE)" GTKDOCIZE="$(TRUE)" \
./bootstrap \
--bootstrap-sync \
--force \
--no-git \
--skip-po \
--gnulib-srcdir=$(GNULIB_SRCDIR) \
)
endef
define Host/Prepare
$(call Host/Prepare/Default)
$(if $(QUILT),,$(call Host/Bootstrap))
endef
define Host/Configure
$(if $(QUILT),$(call Host/Bootstrap))
$(foreach src,$(HOST_GNULIB_SKIP),mv -f $(HOST_BUILD_DIR)/$(src)~ $(HOST_BUILD_DIR)/$(src) || true; )
$(call Host/Configure/Default)
$(call Host/Uninstall)
$(call Host/Compile/Default,lib/config.h)
endef
define Host/Install
$(INSTALL_DIR) $(1)/bin
$(foreach prog,$(filter-out g%,$(PKG_PROGRAMS)),$(INSTALL_BIN) $(patsubst %,$(HOST_BUILD_DIR)/src/%,$(prog)) $(1)/bin/g$(prog); )
$(foreach prog,$(filter g%,$(PKG_PROGRAMS)),$(INSTALL_BIN) $(patsubst %,$(HOST_BUILD_DIR)/src/%,$(prog)) $(1)/bin/$(prog); )
$(foreach prog,$(filter-out g%,$(PKG_PROGRAMS)),g$(LN) g$(prog) $(1)/bin/$(prog); )
$(foreach prog,$(filter g%,$(PKG_PROGRAMS)),g$(LN) $(prog) $(1)/bin/$(patsubst g%,%,$(prog)); )
endef
define Host/Uninstall
#$(call Host/Compile/Default,uninstall) # Removes necessary symlinks
-$(call Host/Compile/Default,maintainer-clean) # Clean bootstrap files from the release
endef
$(eval $(call HostBuild))