From patchwork Thu Nov 25 01:06:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 1559488 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=bOMt1gsZ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J00C63kcvz9sVc for ; Thu, 25 Nov 2021 12:09:22 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From :Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=XVs6LnGIs5y9gE3+Ql+ZrALWdWKxgHbkVcu88Dt05Tk=; b=bOMt1gsZAigmZe 2sMyHOj5N+i8+ggF4noZtGwfLiBAO2LrRIeshwfhMxZ+F02fi6DSN4+pH4aXuWrOtm9zNa9gkkFpS u8Pxw8ZIMYsQzaZQzsc3tkG9Kqd7gyuOfzPqUb/TY3hgfa9JBOdaZPF8KoS1Qa1WyIq4MzBfk4Yff uOYVuIOd7hVUhNjl5pDvymKjwJcw2kYXKcHDE7ThpW6Gk2bGN/QV2xKsYJoAjVtSJmAopbeIpDMxr ZK/QalPbea310v3LaPmxuUHkKVwAxpbOWPbo8sb9dtzj9w+QxWvX2tZUDcR6xh568BkVYD8ZNpvFr pjoUZMgQcKHAzfZ1yzsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mq3E2-006AuX-Ji; Thu, 25 Nov 2021 01:06:58 +0000 Received: from fudo.makrotopia.org ([2a07:2ec0:3002::71]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mq3Dy-006Au6-R4 for openwrt-devel@lists.openwrt.org; Thu, 25 Nov 2021 01:06:56 +0000 Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.94.2) (envelope-from ) id 1mq3Dx-0007JZ-B2 for openwrt-devel@lists.openwrt.org; Thu, 25 Nov 2021 02:06:53 +0100 Date: Thu, 25 Nov 2021 01:06:46 +0000 From: Daniel Golle To: openwrt-devel@lists.openwrt.org Subject: [PATCH 2/6] base-files: preinit: load device-tree overlays Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211124_170654_903387_973AA1E4 X-CRM114-Status: GOOD ( 14.00 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add new boot hooklist 'preinit_late' 'preinit_main' returns once initramfs is detected and skips all later hooks, hence it cannot be used e.g. for loading device tree overlays which should work indepe [...] Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Add new boot hooklist 'preinit_late' 'preinit_main' returns once initramfs is detected and skips all later hooks, hence it cannot be used e.g. for loading device tree overlays which should work independently of running in initramfs of not, but needs to happen after rootfs is mounted in the "regular" squashfs+overlayfs case. Hence introduce new hooklist 'preinit_late' which is run after 'preinit_main' has completed. Introduce preinit_late hook to mount configfs and apply device tree overlays from /lib/firmware/device-tree/overlays/*.dtbo on targets which got the 'dt-overlay' feature set. Device tree overlay blobs placed into that folder will be loaded early on boot before AutoProbing kernel modules. Signed-off-by: Daniel Golle --- package/base-files/Makefile | 6 ++++++ package/base-files/files/etc/preinit | 2 ++ .../files/lib/preinit/90_apply_dt_overlays | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 package/base-files/files/lib/preinit/90_apply_dt_overlays diff --git a/package/base-files/Makefile b/package/base-files/Makefile index af5c0e6b00..b347eb4143 100644 --- a/package/base-files/Makefile +++ b/package/base-files/Makefile @@ -22,6 +22,7 @@ PKG_LICENSE:=GPL-2.0 # Extend depends from version.mk PKG_CONFIG_DEPENDS += \ CONFIG_SIGNED_PACKAGES CONFIG_TARGET_INIT_PATH CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE \ + CONFIG_HAS_DT_OVERLAY_SUPPORT \ CONFIG_NAND_SUPPORT \ CONFIG_LEGACY_SDCARD_SUPPORT \ CONFIG_CLEAN_IPKG \ @@ -189,6 +190,11 @@ else mkdir -p $(1)/var $(LN) /tmp/run $(1)/var/run endif + +ifneq ($(CONFIG_HAS_DT_OVERLAY_SUPPORT),y) + rm $(1)/lib/preinit/90_apply_dt_overlays +endif + $(LN) /tmp/resolv.conf /tmp/TZ /tmp/localtime $(1)/etc/ chmod 0600 $(1)/etc/shadow diff --git a/package/base-files/files/etc/preinit b/package/base-files/files/etc/preinit index 829574f5f1..04c11f8833 100755 --- a/package/base-files/files/etc/preinit +++ b/package/base-files/files/etc/preinit @@ -15,6 +15,7 @@ boot_hook_init preinit_main boot_hook_init failsafe boot_hook_init initramfs boot_hook_init preinit_mount_root +boot_hook_init preinit_late for pi_source_file in /lib/preinit/*; do . $pi_source_file @@ -27,3 +28,4 @@ pi_jffs2_mount_success=false pi_failsafe_net_message=false boot_run_hook preinit_main +boot_run_hook preinit_late diff --git a/package/base-files/files/lib/preinit/90_apply_dt_overlays b/package/base-files/files/lib/preinit/90_apply_dt_overlays new file mode 100644 index 0000000000..7d17947e1c --- /dev/null +++ b/package/base-files/files/lib/preinit/90_apply_dt_overlays @@ -0,0 +1,19 @@ +#!/bin/bash + +do_apply_dt_overlays() { + grep -q configfs /proc/filesystems || return 0 + mount configfs -t configfs /sys/kernel/config + local overlays_dir="/sys/kernel/config/device-tree/overlays" + [ -d "$overlays_dir" ] || return 0 + local dto dtoname + for dto in /lib/firmware/device-tree/overlays/*.dto ; do + [ -r "$dto" ] || continue + dtoname="$(basename "$dtbo" .dtbo)" + [ -e "$overlays_dir/$dtoname" ] && continue + echo " - applying device-tree overlay '$dtoname' - " + mkdir "$overlays_dir/$dtoname" + echo "$dto" > "$overlays_dir/$dtoname/path" + done +} + +boot_hook_add preinit_late do_apply_dt_overlays