From a45357940a07e524a4a4798ecdd5f58dc0b130d0 Mon Sep 17 00:00:00 2001 From: Javier Viguera Date: Mon, 27 Nov 2017 13:56:43 +0100 Subject: [PATCH] libdigiapix: add udev rules for digiapix API These udev rules allow to use the digiapix API by a normal user that belongs to the 'digiapix' group. https://jira.digi.com/browse/DEL-5232 Signed-off-by: Javier Viguera --- .../libdigiapix-git/99-digiapix.rules | 22 +++++++++++++ .../libdigiapix/libdigiapix-git/digiapix.sh | 31 +++++++++++++++++++ .../libdigiapix/libdigiapix_git.bb | 9 +++++- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/99-digiapix.rules create mode 100644 meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/digiapix.sh diff --git a/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/99-digiapix.rules b/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/99-digiapix.rules new file mode 100644 index 000000000..04ec742bb --- /dev/null +++ b/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/99-digiapix.rules @@ -0,0 +1,22 @@ +# libdigiapix: configure interfaces so they can be used by group 'digiapix' + +SUBSYSTEM=="i2c-dev", GROUP="digiapix", MODE="0660" +SUBSYSTEM=="spidev", GROUP="digiapix", MODE="0660" + +# +# Use two different rules for GPIO's. +# +# 1. The first rule (gpiochip0) allows to configure the GROUP and MODE of +# the 'export' and 'unexport' files. This is basically executed once on +# boot and it's needed so a normal user (with group 'digiapix') +# is able to export/unexport gpios. +# +# 2. The second rule configures the GROUP and MODE of the sysfs files that +# are created whenever a 'gpio' is exported. +# +# This way we filter out multiple gpiochipX events that we don't want to attend +# +SUBSYSTEM=="gpio", KERNEL=="gpiochip0", ACTION=="add", RUN="/etc/udev/scripts/digiapix.sh" +SUBSYSTEM=="gpio", KERNEL!="gpiochip*", ACTION=="add", RUN="/etc/udev/scripts/digiapix.sh" + +SUBSYSTEM=="pwm", ACTION=="add", RUN="/etc/udev/scripts/digiapix.sh" diff --git a/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/digiapix.sh b/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/digiapix.sh new file mode 100644 index 000000000..bc3897c85 --- /dev/null +++ b/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/digiapix.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# +# Copyright (c) 2017, Digi International Inc. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, you can obtain one at http://mozilla.org/MPL/2.0/. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +if basename "${DEVPATH}" | grep -qs "gpiochip0$"; then + # Use 'gpiochip0' event to set group and mode for 'export/unexport' files + chown root:digiapix /sys/class/gpio/export /sys/class/gpio/unexport + chmod g+w /sys/class/gpio/export /sys/class/gpio/unexport +elif basename "${DEVPATH}" | grep -qs "pwmchip[0-9]\+$"; then + # Set group and mode for pwmchip's 'export/unexport' files + chown root:digiapix /sys${DEVPATH}/export /sys${DEVPATH}/unexport + chmod g+w /sys${DEVPATH}/export /sys${DEVPATH}/unexport +else + # Change group and mode of the sysfs files created whenever a 'gpioX' + # or 'pwmX' is exported + chown -h root:digiapix /sys${DEVPATH}/* + chmod g+w /sys${DEVPATH}/* +fi diff --git a/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix_git.bb b/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix_git.bb index 88517db7d..7d67c9075 100644 --- a/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix_git.bb +++ b/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix_git.bb @@ -18,7 +18,9 @@ LIBDIGIAPIX_GIT_URI ?= "${@base_conditional('DIGI_INTERNAL_GIT', '1' , '${LIBDIG SRC_URI = " \ ${LIBDIGIAPIX_GIT_URI};branch=${SRCBRANCH} \ + file://99-digiapix.rules \ file://board.conf \ + file://digiapix.sh \ " S = "${WORKDIR}/git" @@ -28,7 +30,12 @@ inherit pkgconfig useradd do_install() { oe_runmake 'DESTDIR=${D}' install - install -d ${D}${sysconfdir}/ + # Install udev rules for digiapix + install -d ${D}${sysconfdir}/udev/rules.d ${D}${sysconfdir}/udev/scripts + install -m 0644 ${WORKDIR}/99-digiapix.rules ${D}${sysconfdir}/udev/rules.d/ + install -m 0755 ${WORKDIR}/digiapix.sh ${D}${sysconfdir}/udev/scripts/ + + # Install board config file install -m 0644 ${WORKDIR}/board.conf ${D}${sysconfdir}/libdigiapix.conf }