From patchwork Fri Aug 23 21:06:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 1152438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MNhyDNg9"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ut2RlT55"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 46FYqg5HrPz9s7T for ; Sat, 24 Aug 2019 07:06:55 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date:To :From: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=cbM5e9zn2K/0DtQONjsUpguLDovA7xOXgMwtrzYaRhY=; b=MNhyDNg9wSNwt3 e+dBsHqOcx09Pip749rXxKLLiXeAGzl09/aPmlVYlsEiGN79tDJXxEXSvFrXE2/L4TNEeRfa8bzzA Dop7ir9qBqlH0RpPT/qO1r32nREIiRLaNJtlALvLqZIx1/fq4BXsCF/HbbF2Ciak8Gad7RUUfGS1a 9ygtYysTiMNX60z4cN+2RxL9n2LPFQdCZFIK21BHBkFOK9Q0VU1Ef5tj9mBGnbIcvFPID8z7H9U13 sC0bELMkWFi/dsBWvaWALrGq3/KUKCncckqGkiWxu6R+ra2z2715SQwdUJlAIUZbWNoTZnbs9iNRr QQqoYCv/RwM05hRSj4SA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i1Glf-0003XF-Fl; Fri, 23 Aug 2019 21:06:43 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i1GlX-0003MM-07 for openwrt-devel@lists.openwrt.org; Fri, 23 Aug 2019 21:06:36 +0000 Received: by mail-wm1-x341.google.com with SMTP id 10so10025520wmp.3 for ; Fri, 23 Aug 2019 14:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=2Dqpa5qML0ko8r2Yy3aIwg779SaBn3b3leAczsxwc0Y=; b=ut2RlT55CTjKW+fm3kjca2umgkuqJxQjpNbh1KoYyKW07/5gah/fICGnkeocB97b+W 520ArB7YTyJidN9lNG0XmMlC30YZHAe33Ec4Unvr+Rjmd6LhBG5nG7LYuUNa0h+64dJV gKdWkPf9r4SNVtAn0cl4U7C4aM9edpbTbpeIWFov/RSZy9Qm0++x82o48u2PaKQXCMit vEWsQ5nbOdgU5qICHk90ahpTiZ/4zdGWlKDj6q9QbsuYIsrqI3rv6IAfZOMFBctzg9xu LKQLQKHurSu4BqIGcJbT5qgzaZH+Qlg7vAq2T6ByHg7J/6GdglxStEMwg3LUEMzAZAE7 T/FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=2Dqpa5qML0ko8r2Yy3aIwg779SaBn3b3leAczsxwc0Y=; b=ddSubbr8fhSwaVJLKudrZNCxiVdRtnq15HHkU6kAIKKKRTtr/COhtywpzy2g+G4QTZ lKurG7SjtTambDOHLjfN1ZfmpXjLPz7GrKqXB4axURUEeH/pinbB9CGsyA3vfkuoeNCG SNduF2KhUCX9bficl6i6v8qy/Cg2Hw21DF4irMCqB0JHYXcWwqOFOoG8F3WzRrDe2NCy I7biCYuIyuZPaDMg/Q6WMsT7pwlPQe1b2vw+tGa0/kiF80D6waQawZkfTEHY2rxj08a3 xRlqIxtPjSd2fGL+ObAzDwi+iJ8e7Ls+PzXlKsywmkpSYifthmI5as8qON1nDmKPvYTR dQ+g== X-Gm-Message-State: APjAAAXwx1jT6NWtivCdtyE7wkan0dTo94mJVj8VE787AitNJdTxUAI0 1LkKD52WcYM1xKh8KXS16n9ABxbw X-Google-Smtp-Source: APXvYqzINyzMD/NBbbDx2vafqC/OIx63RzsRhlWGiOaFKIcP/nQbJSCIS6fRDSCoQ4j/rdsrBtq5GQ== X-Received: by 2002:a7b:cbc6:: with SMTP id n6mr7724643wmi.6.1566594392977; Fri, 23 Aug 2019 14:06:32 -0700 (PDT) Received: from debian64.daheim (p5B0D7455.dip0.t-ipconnect.de. [91.13.116.85]) by smtp.gmail.com with ESMTPSA id t13sm4778230wrr.0.2019.08.23.14.06.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2019 14:06:32 -0700 (PDT) Received: from chuck by debian64.daheim with local (Exim 4.92.1) (envelope-from ) id 1i1GlT-0006BY-Tf for openwrt-devel@lists.openwrt.org; Fri, 23 Aug 2019 23:06:31 +0200 From: Christian Lamparter To: openwrt-devel@lists.openwrt.org Date: Fri, 23 Aug 2019 23:06:30 +0200 Message-Id: X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190823_140635_045107_7F2FD05F X-CRM114-Status: GOOD ( 13.23 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:341 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (chunkeey[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [OpenWrt-Devel] [RFC PATCH 1/2] softoff: add softoff utility X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 The softoff package replaces the poweroff command with a scripts that utilize the existing sysupgrade code to perform a "soft" poweroff (in a way that the device is no longer responsive). So this makes it safer to disconnect and be moved. By design, sysupgrade already stops services and closes any running application, as well as unmounts any active partition. This scripts piggybacks on what's provided by sysupgrade, but also puts all active SATA/SCSI/UAS/USB-attached HDDs into standby by telling the kernel they are no longer needed (and the kernel will do the rest) and tries to switch all available LEDs to the off state (the trigger "none" will only switch off managed LEDs) before causes the device to enter a infinite loop. This works especially well with embedded devices without a real poweroff method (many SoC platform drivers just map the shutdown() to reset()) or suffer because the platform has a no-way-out watchdog that can trigger a hardware reboot which can bring the device out of its "poweroff" state. Signed-off-by: Christian Lamparter --- package/utils/softoff/Makefile | 36 +++++++++++++++++++++++++++++ package/utils/softoff/files/softoff | 36 +++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 package/utils/softoff/Makefile create mode 100644 package/utils/softoff/files/softoff diff --git a/package/utils/softoff/Makefile b/package/utils/softoff/Makefile new file mode 100644 index 0000000000..28930e9bde --- /dev/null +++ b/package/utils/softoff/Makefile @@ -0,0 +1,36 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=softoff +PKG_RELEASE:=1 +PKG_LICENSE:=GPL-2.0 +PKG_MAINTAINER:=Christian Lamparter + +include $(INCLUDE_DIR)/package.mk + +define Package/softoff + PKGARCH:=all + SECTION:=utils + CATEGORY:=Utilities + TITLE:=softoff utility +endef + +define Package/softoff/description + the softoff package replaces the poweroff command with scripts that + utilize the sysupgrade code to perform a "softer" poweroff. + The script will try to close any running application, unmount any active + partition as well as putting any connected HDD to standby (for shutdown). + This allows embedded devices with out a working poweroff method to become + unavailable. +endef + +define Build/Compile + true +endef + +define Package/softoff/install-overlay + $(INSTALL_DIR) $(1)/sbin + $(INSTALL_BIN) ./files/softoff $(1)/sbin/softoff + $(LN) softoff $(1)/sbin/poweroff +endef + +$(eval $(call BuildPackage,softoff)) diff --git a/package/utils/softoff/files/softoff b/package/utils/softoff/files/softoff new file mode 100644 index 0000000000..e25bdba8f2 --- /dev/null +++ b/package/utils/softoff/files/softoff @@ -0,0 +1,36 @@ +#!/bin/sh + +. /lib/functions.sh +. /lib/functions/system.sh +. /lib/upgrade/common.sh + +case "$1" in +stage2) + for dev in /sys/block/sd*[a-z]; do + [ -d "$dev" ] && echo "1" > "$dev/device/delete" + done + + for led in /sys/class/leds/*; do + [ -d "$led" ] && { + echo "none" > "$led/trigger" + echo "0" > "$led/brightness" + } + done + + while :; do + sleep 10000; + done + ;; +*) + install_bin /sbin/upgraded + install_bin "$0" + + ifdown -a + + ubus call system sysupgrade "{ + \"prefix\": $(json_string "$RAM_ROOT"), + \"path\": $(json_string "badfile"), + \"command\": $(json_string "$0 stage2") + }" + ;; +esac From patchwork Fri Aug 23 21:06:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 1152437 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="SRWGX5t9"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SKtGNEJ9"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 46FYqS1KBQz9s7T for ; Sat, 24 Aug 2019 07:06:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=O/bNXbEWi1cEJx3S6+LBZbfOvAH4oZVcnpd1DmgKrAI=; b=SRWGX5t9VGbpwvFZ2i2mXP032E RqLfv8Uo4bzBBFEPSchBJtezK5A+Cv/2oyJeLwdZC/wsFgIKziio5Us8XrbkeO5K+3U3kH0cRqBBW LnmhXbzHOzNPSQEI+/hcxBZ4Sf92Iw+lp2FvTiuB/oDqAZeCMjdC7Fw7tvyCyPPqaZCNZ+otrtdxt TChCa9GNCzahfs4vRhhQ6LRso6OTuYqVxxEzshCG4loy7cqa+3BV10d9mdxUG9i50bNUKL24GntlT vghaH50OFiNKkiuznUkvlR+4rS6N2ZJVeQFmCk0UyI1e9I9Y+8Bg9RSD8hI9tjAWkBU6lwdVPxuCI 8Y865/YQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i1GlZ-0003N5-6e; Fri, 23 Aug 2019 21:06:37 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i1GlX-0003MN-34 for openwrt-devel@lists.openwrt.org; Fri, 23 Aug 2019 21:06:36 +0000 Received: by mail-wm1-x343.google.com with SMTP id g67so10317041wme.1 for ; Fri, 23 Aug 2019 14:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WVczKFYaBq+XbN4ycsWp1oRbhgeWG1d3HJep5XKtCvI=; b=SKtGNEJ91sQI7nSnnkkxO4+HS/qqBv8M71Quaf6MJHqTHq6PkZQSVUTkXFKcnLjspD r50slqcUuLyclvW2lykrZGgcBCzKIVCn/HJpG9WIv5uTBRvnIWsZOI0PwFYipYRkodn2 kmW/uLNrmTKsroag/0Z5Ylibop4YJlYRqDas5w8pt/Px/V8KsYUlUYMeU5DNVxCpMwj8 gDQReiHAJAn1vXyf3E36aX8fdERPXBCGISuwC6ho1CkfPJzQowySKcgNCnHjfPl/eMeX luNVMnXmTmiEmuL5U4v8wlhWCVu7dn1Cg+eYlxCmnG7nPIE5/8JKKHlTrggDqHB5HrQb tJdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WVczKFYaBq+XbN4ycsWp1oRbhgeWG1d3HJep5XKtCvI=; b=Z70O/ZJAvE4w81L6E5LNnEYzyYFC+Ux4YhRKkTHe/k6ajlxU9F2kPI1GjsNqT6dFsJ 2zt2p/v6ZKKasjixUzOyK1LR+9Yk4l2p8LbuO64H37AyUyjq6H69PQ2jfCYi9kMa0bwl Z6ZSzII5tOZE/YbP8zhnzNxHagtHCOB2yZOAPG6KSS17+X2olZOqxIey0iKRjDqhEZKJ AYt3pLU3sSwUz0CZLGsI58mIqw3jcyrO3zSfe5GyX/8gciFrjAtsFDUVtWLp744r+tRd lmWtqFbbLOy3sH2v400KLLgRInuj65tIQ7yW+VckDAD2egUspBUy/+L0Y/N3IwCVgt5p 3Ovw== X-Gm-Message-State: APjAAAX/Pev/CnmDFd3eQ3+Q8SSno6d0J+HYRtnt+ll6UPGwFQk0HQWn hona32DaeD9nGfQs43Db3rZVQTzt X-Google-Smtp-Source: APXvYqxiOgUotDFJ/UTSFW9GZ3CahefzUOKP0hq1ISjPeYsJ6NiYmw8tEFEZOUiWRePa0C5rCUksEA== X-Received: by 2002:a1c:ef09:: with SMTP id n9mr7092683wmh.23.1566594393207; Fri, 23 Aug 2019 14:06:33 -0700 (PDT) Received: from debian64.daheim (p5B0D7455.dip0.t-ipconnect.de. [91.13.116.85]) by smtp.gmail.com with ESMTPSA id b15sm3227953wrt.77.2019.08.23.14.06.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2019 14:06:32 -0700 (PDT) Received: from chuck by debian64.daheim with local (Exim 4.92.1) (envelope-from ) id 1i1GlT-0006Bb-Ud for openwrt-devel@lists.openwrt.org; Fri, 23 Aug 2019 23:06:31 +0200 From: Christian Lamparter To: openwrt-devel@lists.openwrt.org Date: Fri, 23 Aug 2019 23:06:31 +0200 Message-Id: <7f843b505843bd1fee347a1b46df6513de8bf735.1566587318.git.chunkeey@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190823_140635_137680_0739EB80 X-CRM114-Status: GOOD ( 10.57 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:343 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (chunkeey[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [OpenWrt-Devel] [RFC PATCH 2/2] apm821xx: utilize softoff on the MyBook Live Series X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 This was a requested feature on the forum some long time ago. The original vendor firmware from Western Digital allowed the device to enter a shutdown-like state and remain there indefinitely. Because OpenWrt sets the platform's nowayout watchdog, this device will reboot after some time even when poweroff gets called and the kernel supposed to just do its infinite loop thing. With this somewhat universal "softoff" the device will be able to enter a similar-but-different shutdown-like state with the HDDs in a safer standby mode so it can be moved and disconnected. Signed-off-by: Christian Lamparter --- target/linux/apm821xx/image/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/linux/apm821xx/image/Makefile b/target/linux/apm821xx/image/Makefile index acfd478755..82e84f72f9 100644 --- a/target/linux/apm821xx/image/Makefile +++ b/target/linux/apm821xx/image/Makefile @@ -230,7 +230,8 @@ ifeq ($(SUBTARGET),sata) define Device/wd_mybooklive DEVICE_VENDOR := Western Digital DEVICE_MODEL := My Book Live Series (Single + Duo) - DEVICE_PACKAGES := kmod-usb-dwc2 kmod-usb-ledtrig-usbport kmod-usb-storage kmod-fs-vfat wpad-basic + DEVICE_PACKAGES := kmod-usb-dwc2 kmod-usb-ledtrig-usbport kmod-usb-storage \ + kmod-fs-vfat wpad-basic softoff DEVICE_TYPE := nas DEVICE_DTS := wd-mybooklive SUPPORTED_DEVICES += mbl wd,mybooklive-duo