diff --git a/board/aarch64/bananapi-bpi-r3/rootfs/usr/share/product/bananapi,bpi-r3/etc/product/init.d/S01-trigger-udev.sh b/board/aarch64/bananapi-bpi-r3/rootfs/usr/share/product/bananapi,bpi-r3/etc/product/init.d/S01-trigger-udev.sh deleted file mode 100755 index facaccd16..000000000 --- a/board/aarch64/bananapi-bpi-r3/rootfs/usr/share/product/bananapi,bpi-r3/etc/product/init.d/S01-trigger-udev.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -udevadm control --reload-rules -udevadm trigger --subsystem-match=net --action=add diff --git a/board/aarch64/friendlyarm-nanopi-r2s/rootfs/usr/share/product/friendlyarm,nanopi-r2s/etc/product/init.d/S01-trigger-udev.sh b/board/aarch64/friendlyarm-nanopi-r2s/rootfs/usr/share/product/friendlyarm,nanopi-r2s/etc/product/init.d/S01-trigger-udev.sh deleted file mode 100755 index facaccd16..000000000 --- a/board/aarch64/friendlyarm-nanopi-r2s/rootfs/usr/share/product/friendlyarm,nanopi-r2s/etc/product/init.d/S01-trigger-udev.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -udevadm control --reload-rules -udevadm trigger --subsystem-match=net --action=add diff --git a/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,4-compute-module/etc/product/init.d/S01-trigger-udev.sh b/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,4-compute-module/etc/product/init.d/S01-trigger-udev.sh deleted file mode 100755 index 94fdb56e7..000000000 --- a/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,4-compute-module/etc/product/init.d/S01-trigger-udev.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# Workaround for: https://github.com/kernelkit/infix/issues/1357 -udevadm control --reload-rules -udevadm trigger --subsystem-match=net --action=add diff --git a/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,4-model-b/etc/product/init.d/S01-trigger-udev.sh b/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,4-model-b/etc/product/init.d/S01-trigger-udev.sh deleted file mode 100755 index 94fdb56e7..000000000 --- a/board/aarch64/raspberrypi-rpi64/rootfs/usr/share/product/raspberrypi,4-model-b/etc/product/init.d/S01-trigger-udev.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# Workaround for: https://github.com/kernelkit/infix/issues/1357 -udevadm control --reload-rules -udevadm trigger --subsystem-match=net --action=add diff --git a/board/common/rootfs/usr/lib/finit/system/05-pre-udev.conf b/board/common/rootfs/usr/lib/finit/system/05-pre-udev.conf new file mode 100644 index 000000000..4dfe97c68 --- /dev/null +++ b/board/common/rootfs/usr/lib/finit/system/05-pre-udev.conf @@ -0,0 +1,18 @@ +# Copy product-specific files (udev rules, factory config, etc.) to / +# based on DT compatible strings, before udevd processes any events. +# +# fires after all filesystems are mounted but before +# finit enters runlevel S and starts any service, so the run task is +# guaranteed to start ahead of udevd. The +# condition below then blocks udevd until pre-udev has finished. +# +# Systems without a matching product directory exit immediately. +run name:preudev cgroup.init [S] log \ + /usr/libexec/infix/pre-udev -- Probing platform + +# Hold udevd back until pre-udev has had a chance to install any +# product-specific udev rules so that they are applied on first pass. +service nowarn cgroup.system name:udevd notify:none env:-/etc/default/udevd pid:udevd log \ + [S12345789] /lib/systemd/systemd-udevd $UDEVD_ARGS -- Device event daemon (udev) +service nowarn cgroup.system name:udevd notify:none env:-/etc/default/udevd pid:udevd log \ + [S12345789] udevd $UDEVD_ARGS -- Device event daemon (udev) diff --git a/board/common/rootfs/usr/lib/finit/system/20-hw-wait.conf b/board/common/rootfs/usr/lib/finit/system/20-hw-wait.conf index 5d6bc0c12..7b436fbbe 100644 --- a/board/common/rootfs/usr/lib/finit/system/20-hw-wait.conf +++ b/board/common/rootfs/usr/lib/finit/system/20-hw-wait.conf @@ -5,5 +5,5 @@ run nowarn if:udevd cgroup.init log \ # Now that everything should be probed, do a final pass over the # uevent queue before starting syslogd and everything else -run nowarn if:udevd cgroup.init :post log \ +run nowarn if:udevd cgroup.init :post log \ [S] udevadm settle -t 30 -- diff --git a/board/common/rootfs/usr/libexec/infix/init.d/05-product b/board/common/rootfs/usr/libexec/infix/init.d/05-product index 285ca5606..ea5a1af85 100755 --- a/board/common/rootfs/usr/libexec/infix/init.d/05-product +++ b/board/common/rootfs/usr/libexec/infix/init.d/05-product @@ -1,40 +1,22 @@ #!/bin/sh -# Find, install, and run product specific files and script in /etc -# before resuming bootstrap. +# Run product specific init scripts and set bootstrap conditions. +# +# Product-specific files (udev rules, factory config, etc.) are already +# copied to / by the pre-udev run task before udevd starts. This +# script handles the remaining product init: running custom scripts +# from /etc/product/init.d/ and setting finit conditions. # # Use /etc/product/init.d/S01-myscript for scripts, may be a symlink, it # will be called with `start` as its only argument. -# -# The compatible array is listed in the same order as the device tree, -# most significant to least. Hence the reverse.[], to ensure overrides -# are applied in order of significance. ident=$(basename "$0") PRODUCT_INIT=/etc/product/init.d -PREFIXD=/usr/share/product -COMPATIBLES=$(jq -r '.compatible | reverse.[] | ascii_downcase' /run/system.json) note() { logger -I $$ -k -p user.notice -t "$ident" "$1" } -found=false -for PRODUCT in $COMPATIBLES; do - DIR="$PREFIXD/$PRODUCT" - if [ -d "$DIR" ]; then - note "Using vendor/product-specific defaults for $PRODUCT." - for dir in "$DIR"/*; do - [ -d "$dir" ] && cp -a "$dir" / - done - found=true - fi -done - -if [ "$found" = false ]; then - note "No vendor/product-specific directory found, using built-in defaults." -fi - # Conditions for bootstrap services, this enables product specific # init scripts to prevent select services from starting. initctl -nbq cond set led diff --git a/board/common/rootfs/usr/libexec/infix/pre-udev b/board/common/rootfs/usr/libexec/infix/pre-udev new file mode 100755 index 000000000..2cbc4b1f1 --- /dev/null +++ b/board/common/rootfs/usr/libexec/infix/pre-udev @@ -0,0 +1,48 @@ +#!/bin/sh +# Copy product-specific files to / based on DT compatible strings. +# Designed to run before udevd, so that udev rules are in place when +# the kernel starts enumerating devices. No Python, no jq, no syslogd. +# +# Mirrors the platform detection from 00-probe and the copy logic from +# 05-product, but reads the DT directly instead of /run/system.json. + +PREFIXD=/usr/share/product +COMPAT=/sys/firmware/devicetree/base/compatible +IDENT=$(basename "$0") + +note() +{ + logger -I $$ -k -p user.notice -t "$IDENT" "$*" +} + +# Only DT-based systems have product-specific data keyed by compatible. +# QEMU and x86/DMI systems have no product dirs to copy. +[ -f "$COMPAT" ] || exit 0 + +# The DT compatible property is a null-separated list of strings, +# ordered most-specific first (e.g. "bananapi,bpi-r3\0mediatek,mt7986a"). +# Reverse the list so least-specific is applied first and more-specific +# overrides it, matching the behaviour of 05-product. +reversed="" +while IFS= read -r c; do + [ -n "$c" ] || continue + reversed="$c${reversed:+ $reversed}" +done <