From patchwork Fri Jun 26 11:29:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Chalain X-Patchwork-Id: 1317574 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Jq16cYg2; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49tZRS6x1Zz9sPF for ; Fri, 26 Jun 2020 21:29:40 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 0A6D686CE7; Fri, 26 Jun 2020 11:29:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9CqtdDwIM52p; Fri, 26 Jun 2020 11:29:35 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id E335686C28; Fri, 26 Jun 2020 11:29:34 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 3F8A31BF36E for ; Fri, 26 Jun 2020 11:29:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 32AF2233A6 for ; Fri, 26 Jun 2020 11:29:34 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iNqt9ZOKwmD5 for ; Fri, 26 Jun 2020 11:29:32 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by silver.osuosl.org (Postfix) with ESMTPS id 9E40D226E5 for ; Fri, 26 Jun 2020 11:29:32 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id h15so9138910wrq.8 for ; Fri, 26 Jun 2020 04:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=wyOxT9eYjFMO0SiV4/nKYrhw8JaSgq44zyyLMCLt6QM=; b=Jq16cYg2GHQCXp2zQxlwVLKwkilJuSHmsMDrp2cIG5+51e0mQtq/BPkl4ptb0pTc2X gIwc3v6j+roQ2Z3hlXIV1Sz1myGL0ElQDxNhI89FC7p4+JcJ7sICAktxc1JYPjwEQV3E dOpsxAqv1T5IsQ7xpEju9gD6IIla2cgI3Pbz6/8vTrw36ede9d4Ud928NHjhYSpv14pP kdhRPbjG7wy+ZSgYQQDht1TKcxXR19MlNFx70f9GJcEVnjAPW3/DBEH6C3Ps+DnhtMks EjgCXAGMDZ4GHek/EPGG58/6VDLN2RwK3bJV6pgr9C8tjp9LYe+aSQg8MGyehdj+Tz3+ W74g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=wyOxT9eYjFMO0SiV4/nKYrhw8JaSgq44zyyLMCLt6QM=; b=Cr9svISIyL2hO25CL0LLcwoCMlDh396Y1do0UoOkvn44OF97FSxpadaa/LGLEDDd0s nnXLJ0hDOACGJ/t3+yj6XEN5/MCZwJpyHrj8QUnasOqVjR+bX6M84yzyOunHFc42BGkr Z2MBOfQbs8bGxubC0O4q2s4SmNy3UOhgUgjWX2lSZ8W+DtPtOznUayFO9opZbxvM/q6f z3u0/THOqvnyo1dTz8zASCP89ZiXTpiVs8bedJVHafXL7oYcfsz4fEiRAsV90n78eAGR bLl5TrK04EZhfHSwwNE9ceYc5BHd3Hs5PwtODfOrOkklEiPRL/sM4DZ/ZeNalM/HlXkf vh6Q== X-Gm-Message-State: AOAM5306VxslxVZAJlLhvT01moKZtSC5gP/AomdteZy98NEfQHX1tzQx PEJt1Li6ZKghig8aWdHpN/vIX2oj X-Google-Smtp-Source: ABdhPJwq90I418OJlXaRUcWtdnW6dPKOtT7E/ycgVb40sTDxehauN/xnnlGlTYY+k5ZnNIJDaJ+ttw== X-Received: by 2002:adf:ed87:: with SMTP id c7mr3103822wro.422.1593170970583; Fri, 26 Jun 2020 04:29:30 -0700 (PDT) Received: from cush.home ([2a01:cb15:817e:2500:8ab6:dc03:318a:34e2]) by smtp.googlemail.com with ESMTPSA id 92sm30018423wrr.96.2020.06.26.04.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 04:29:29 -0700 (PDT) From: Marc Chalain To: buildroot@buildroot.org Date: Fri, 26 Jun 2020 13:29:19 +0200 Message-Id: <20200626112919.27946-1-marc.chalain@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [Buildroot] [PATCH 1/1] package/gpiod: add gpiod hardware handling daemon X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Chalain MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Gpiod is a little daemon to trig gpio event and launch scripts on level changing events. As udev or mdev, it reads rules files to attach scripts on events. and launch the scripts with environment variables to describe the event. It uses libgpiod to monitor the gpio and libconfig to read the rules. It is tested on Raspberry Pi (0,3,4) with success. Signed-off-by: Marc Chalain --- package/Config.in | 1 + package/gpiod/Config.in | 14 +++++++++ package/gpiod/S20gpiod.in | 56 ++++++++++++++++++++++++++++++++++ package/gpiod/gpiod.hash | 2 ++ package/gpiod/gpiod.mk | 52 +++++++++++++++++++++++++++++++ package/gpiod/gpiod.service.in | 11 +++++++ 6 files changed, 136 insertions(+) create mode 100644 package/gpiod/Config.in create mode 100755 package/gpiod/S20gpiod.in create mode 100644 package/gpiod/gpiod.hash create mode 100644 package/gpiod/gpiod.mk create mode 100644 package/gpiod/gpiod.service.in diff --git a/package/Config.in b/package/Config.in index 6a34a895af..c86315630f 100644 --- a/package/Config.in +++ b/package/Config.in @@ -458,6 +458,7 @@ endmenu source "package/freescale-imx/Config.in" source "package/fxload/Config.in" source "package/gcnano-binaries/Config.in" + source "package/gpiod/Config.in" source "package/gpm/Config.in" source "package/gpsd/Config.in" source "package/gptfdisk/Config.in" diff --git a/package/gpiod/Config.in b/package/gpiod/Config.in new file mode 100644 index 0000000000..e9ba5bdba3 --- /dev/null +++ b/package/gpiod/Config.in @@ -0,0 +1,14 @@ +config BR2_PACKAGE_GPIOD + bool "gpiod: gpio monitor daemon" + depends on BR2_USE_MMU + depends on BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_8 # libgpiod + select BR2_PACKAGE_LIBGPIOD + select BR2_PACKAGE_LIBCONFIG + help + GPIOD monitors gpio events and start scripts. + The daemon loads rules defining a gpio and + the scripts to launch when the level of gpio changes. + +comment "gpiod needs a toolchain w/ kernel headers >= 4.8" + depends on !BR2_USE_MMU + depends on !BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_8 diff --git a/package/gpiod/S20gpiod.in b/package/gpiod/S20gpiod.in new file mode 100755 index 0000000000..2cc77af145 --- /dev/null +++ b/package/gpiod/S20gpiod.in @@ -0,0 +1,56 @@ +#!/bin/sh +# +# Starts gpiod. +# + +DAEMON="gpiod" +PIDFILE="/var/run/$DAEMON.pid" + +OPTIONS="" + +[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON" + +start() { + printf 'Starting %s: ' "$DAEMON" + OPTIONS="${OPTIONS} -p ${PIDFILE}" + OPTIONS="${OPTIONS} -D" + start-stop-daemon -S -q -x "@PREFIX@/sbin/$DAEMON" \ + -- $OPTIONS + status=$? + if [ "$status" -eq 0 ]; then + echo "OK" + else + echo "FAIL" + fi + return "$status" +} + +stop() { + printf 'Stopping %s: ' "$DAEMON" + start-stop-daemon -K -q -p "$PIDFILE" + status=$? + if [ "$status" -eq 0 ]; then + rm -f "$PIDFILE" + echo "OK" + else + echo "FAIL" + fi + return "$status" +} + +restart() { + stop + sleep 1 + start +} + +case "$1" in + start|stop|restart) + "$1";; + reload) + # Restart, since there is no true "reload" feature. + restart;; + *) + echo "Usage: $0 {start|stop|restart|reload}" + exit 1 +esac diff --git a/package/gpiod/gpiod.hash b/package/gpiod/gpiod.hash new file mode 100644 index 0000000000..af0486f792 --- /dev/null +++ b/package/gpiod/gpiod.hash @@ -0,0 +1,2 @@ +sha256 d042c0394071ea8fc7464f02c2e599021d15a9891bd378677b000aa373436c89 gpiod-1.1.tar.gz +sha256 dfba39760e099e2a64567309f0c6ceacaf9e6473bf79835fe0f8a8580651ff49 LICENSE diff --git a/package/gpiod/gpiod.mk b/package/gpiod/gpiod.mk new file mode 100644 index 0000000000..cef3a58fd5 --- /dev/null +++ b/package/gpiod/gpiod.mk @@ -0,0 +1,52 @@ +################################################################################ +# +# gpiod +# +################################################################################ + +GPIOD_VERSION = 1.1 +GPIOD_SITE = $(call github,mchalain,gpiod,$(GPIOD_VERSION)) +GPIOD_LICENSE = BSD +GPIOD_LICENSE_FILES = LICENSE + +PREFIX=/usr +SYSCONFDIR=/etc/gpiod + +GPIOD_MAKE_OPTS = \ + prefix=$(PREFIX) \ + sysconfdir=$(SYSCONFDIR) + +GPIOD_DEPENDENCIES = \ + libgpiod \ + libconfig + +define GPIOD_CONFIGURE_CMDS + $(TARGET_CONFIGURE_OPTS) $(TARGET_MAKE_ENV) \ + $(MAKE1) -C $(@D) $(GPIOD_MAKE_OPTS) defconfig +endef + +define GPIOD_BUILD_CMDS + $(TARGET_CONFIGURE_OPTS) $(TARGET_MAKE_ENV) \ + $(MAKE1) -C $(@D) $(GPIOD_MAKE_OPTS) +endef + +define GPIOD_INSTALL_TARGET_CMDS + $(INSTALL) -d -m 755 $(TARGET_DIR)$(SYSCONFDIR)/rules.d + $(MAKE) -C $(@D) $(GPIOD_MAKE_OPTS) \ + DESTDIR="$(TARGET_DIR)" install +endef + +define GPIOD_INSTALL_INIT_SYSTEMD + cp $(GPIOD_PKGDIR)/gpiod.service.in $(@D)/gpiod.service + $(SED) "s,@PREFIX@,$(PREFIX),g" $(@D)/gpiod.service + $(INSTALL) -D -m 644 $(@D)/gpiod.service \ + $(TARGET_DIR)/usr/lib/systemd/system/gpiod.service +endef +define GPIOD_INSTALL_INIT_SYSV + cp $(GPIOD_PKGDIR)/S20gpiod.in $(@D)/S20gpiod + $(SED) "s,@PREFIX@,$(PREFIX),g" $(@D)/S20gpiod + $(INSTALL) -D -m 755 $(@D)/S20gpiod \ + $(TARGET_DIR)/etc/init.d/S20gpiod +endef + +$(eval $(generic-package)) diff --git a/package/gpiod/gpiod.service.in b/package/gpiod/gpiod.service.in new file mode 100644 index 0000000000..38a573ccf4 --- /dev/null +++ b/package/gpiod/gpiod.service.in @@ -0,0 +1,11 @@ +[Unit] +Description=GPIO event handler daemon + +[Service] +Type=forking +ExecStart=@PREFIX@/sbin/gpiod -D -p /var/run/gpiod.pid +ExecStop=@PREFIX@/sbin/gpiod -K -p /var/run/gpiod.pid +Restart=always + +[Install] +WantedBy=multi-user.target