Add udev rules and scripts for demo platform configuration 71/23371/1
authorJan-Simon Moeller <jsmoeller@linuxfoundation.org>
Sat, 14 Dec 2019 01:40:33 +0000 (02:40 +0100)
committerScott Murray <scott.murray@konsulko.com>
Sun, 15 Dec 2019 18:01:07 +0000 (18:01 +0000)
Add recipes for udev rules and associated scripts
1) Support USB attached I2C devices for RTC and HVAC LED support.
   The RTC support loads and configures the required rtc-ds1307
   driver, and sets the time from the RTC clock.  The HVAC LED
   support configures the LED device names for use by the HVAC
   binding.

The new demo-i2c-udev-conf recipe is
added to DEMO_PLATFORM_CONF variable in packagegroup-agl-demo-platform
to have them added to the agl-demo-platform image.  Since they use
udev rules to detect the corresponding hardware, this should be safe
for all platforms.

Change-Id: Id08571b43c7ae9275496980e0a5568e145a1f653
Signed-off-by: Jan-Simon Moeller <jsmoeller@linuxfoundation.org>
(cherry picked from commit d412114c0cf132a77f3b3482c5440b1a1c961b77)

recipes-core/udev/demo-i2c-udev-conf/99-agl-led-rtc.rules [new file with mode: 0644]
recipes-core/udev/demo-i2c-udev-conf/hvac-json-in-rewrite.sh [new file with mode: 0755]
recipes-core/udev/demo-i2c-udev-conf/hvac-json-in-rewrite@.service [new file with mode: 0644]
recipes-core/udev/demo-i2c-udev-conf/hvac.json.in [new file with mode: 0644]
recipes-core/udev/demo-i2c-udev-conf/rtc-i2c-attach.sh [new file with mode: 0755]
recipes-core/udev/demo-i2c-udev-conf/rtc-i2c-attach@.service [new file with mode: 0644]
recipes-core/udev/demo-i2c-udev-conf_1.0.bb [new file with mode: 0644]
recipes-core/udev/demo-most-udev-conf_1.0.bb [new file with mode: 0644]
recipes-platform/packagegroups/packagegroup-agl-demo-platform.bb

diff --git a/recipes-core/udev/demo-i2c-udev-conf/99-agl-led-rtc.rules b/recipes-core/udev/demo-i2c-udev-conf/99-agl-led-rtc.rules
new file mode 100644 (file)
index 0000000..34fa067
--- /dev/null
@@ -0,0 +1,20 @@
+# skip instantiation of rtc in this processing
+ACTION=="add", SUBSYSTEM=="i2c", DRIVER=="rtc-ds1307", GOTO="hwclock_end"
+
+# load the required drivers (if not already present) - your job to make sure they are there !
+ACTION=="add", ENV{DEVTYPE}=="usb_interface", ENV{DRIVER}=="i2c-tiny-usb", RUN+="/usr/bin/logger 'Loading leds-blinkm'", RUN+="/sbin/modprobe leds-blinkm"
+ACTION=="add", ENV{DEVTYPE}=="usb_interface", ENV{DRIVER}=="i2c-tiny-usb", RUN+="/usr/bin/logger 'Loading rtc driver'", RUN+="/sbin/modprobe rtc-ds1307"
+
+# %k is the blinkm i2c device e.g. 6-0009
+ACTION=="add", ENV{DRIVER}=="blinkm", SUBSYSTEM=="i2c", RUN+="/usr/bin/logger 'the blinkm device is %k'", TAG+="systemd", ENV{SYSTEMD_WANTS}="hvac-json-in-rewrite@%k.service", GOTO="very_end"
+# FIXME: We do not exclude the blinkm on the next lines, yet. The rule is too broad, but that is all we know already. Above is actually later in time.
+#        For now this is not critical as the rtc init will just fail and we're done.
+
+# %k is the i2c bus e.g. i2c-6
+ACTION=="add", SUBSYSTEM=="i2c", ATTRS{idProduct}=="c631", TAG+="systemd", ENV{SYSTEMD_WANTS}="rtc-i2c-attach@%k.service"
+
+# GOTO EXIT
+LABEL="hwclock_end"
+ACTION=="add", SUBSYSTEM=="rtc", RUN+="/bin/sleep 1", RUN+="/sbin/hwclock -f /dev/%k --hctosys --utc", TAG+="systemd"
+
+LABEL="very_end"
diff --git a/recipes-core/udev/demo-i2c-udev-conf/hvac-json-in-rewrite.sh b/recipes-core/udev/demo-i2c-udev-conf/hvac-json-in-rewrite.sh
new file mode 100755 (executable)
index 0000000..5557660
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# (C) 2018 Jan-Simon Möller, dl9pf@gmx.de, jsmoeller@linuxfoundation.org
+# License: Apache License 2.0
+
+#set -x
+set -e
+
+if [ $1 ] ; then
+    # The device is always 0009 -> 9 . Only change is the i2c IF .
+    LED=`echo $1 | sed -e "s#0009#9#g"`
+    if [ $? -eq 0 ] ; then
+       echo "$LED"
+       sed -e "s#@DEVICE@#$LED#" /etc/hvac.json.in > /etc/hvac.json
+    else
+       echo "Invalid argument"
+       exit 1
+    fi
+else
+    echo "Need argument"
+    exit 1
+fi
\ No newline at end of file
diff --git a/recipes-core/udev/demo-i2c-udev-conf/hvac-json-in-rewrite@.service b/recipes-core/udev/demo-i2c-udev-conf/hvac-json-in-rewrite@.service
new file mode 100644 (file)
index 0000000..2fb0995
--- /dev/null
@@ -0,0 +1,8 @@
+[Unit]
+Description=AGL hvac LED write /etc/hvac.json
+#Before= todo: add dependency of hvac service ?
+
+[Service]
+Type=oneshot
+ExecStartPre=/usr/bin/logger '#hvac i2c device has been attached - %i'
+ExecStart=/usr/sbin/hvac-json-in-rewrite.sh %i
diff --git a/recipes-core/udev/demo-i2c-udev-conf/hvac.json.in b/recipes-core/udev/demo-i2c-udev-conf/hvac.json.in
new file mode 100644 (file)
index 0000000..01541a6
--- /dev/null
@@ -0,0 +1,7 @@
+{
+    "ledtemp": {
+       "red": "/sys/class/leds/blinkm-@DEVICE@-red/brightness",
+       "green": "/sys/class/leds/blinkm-@DEVICE@-green/brightness",
+       "blue": "/sys/class/leds/blinkm-@DEVICE@-blue/brightness"
+    }
+}
diff --git a/recipes-core/udev/demo-i2c-udev-conf/rtc-i2c-attach.sh b/recipes-core/udev/demo-i2c-udev-conf/rtc-i2c-attach.sh
new file mode 100755 (executable)
index 0000000..b45d83a
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# ds1307
+echo "ds1307 0x68" > /sys/class/i2c-dev/$1/device/new_device
+
+#ds3231
+#echo "ds1307 0x57" > /sys/class/i2c-dev/$1/device/new_device
+
+#pcf85063
+#echo "pcf85063 0x51" > /sys/class/i2c-dev/$1/device/new_device
+
diff --git a/recipes-core/udev/demo-i2c-udev-conf/rtc-i2c-attach@.service b/recipes-core/udev/demo-i2c-udev-conf/rtc-i2c-attach@.service
new file mode 100644 (file)
index 0000000..8788a25
--- /dev/null
@@ -0,0 +1,4 @@
+[Service]
+Type=oneshot
+ExecStartPre=/bin/echo '#i2c rtc device has been attached'
+ExecStart=/usr/sbin/rtc-i2c-attach.sh %i
diff --git a/recipes-core/udev/demo-i2c-udev-conf_1.0.bb b/recipes-core/udev/demo-i2c-udev-conf_1.0.bb
new file mode 100644 (file)
index 0000000..04101cf
--- /dev/null
@@ -0,0 +1,35 @@
+SUMMARY = "USB attached I2C demo hardware udev configuration"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
+
+SRC_URI = "file://hvac-json-in-rewrite.sh \
+           file://rtc-i2c-attach.sh \
+           file://hvac-json-in-rewrite@.service \
+           file://rtc-i2c-attach@.service \
+           file://99-agl-led-rtc.rules \
+           file://hvac.json.in \
+"
+
+do_compile[noexec] = "1"
+
+do_install() {
+    install -d ${D}${sysconfdir}
+    install -m 0644 ${WORKDIR}/hvac.json.in ${D}${sysconfdir}
+
+    install -d ${D}${sbindir}
+    install -m 0755 ${WORKDIR}/hvac-json-in-rewrite.sh ${D}${sbindir}
+    install -m 0755 ${WORKDIR}/rtc-i2c-attach.sh ${D}${sbindir}
+
+    if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
+        install -d ${D}${systemd_system_unitdir}
+        install -m 0644 ${WORKDIR}/hvac-json-in-rewrite@.service ${D}${systemd_system_unitdir}
+        install -m 0644 ${WORKDIR}/rtc-i2c-attach@.service ${D}${systemd_system_unitdir}
+
+        install -d ${D}${sysconfdir}/udev/rules.d
+        install -m 0644 ${WORKDIR}/99-agl-led-rtc.rules ${D}${sysconfdir}/udev/rules.d/
+    fi
+}
+
+FILES_${PN} += "${systemd_unitdir}"
+
+RDEPENDS_${PN} += "bash"
diff --git a/recipes-core/udev/demo-most-udev-conf_1.0.bb b/recipes-core/udev/demo-most-udev-conf_1.0.bb
new file mode 100644 (file)
index 0000000..ab71f96
--- /dev/null
@@ -0,0 +1,19 @@
+SUMMARY = "MOST demo hardware udev configuration"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
+
+SRC_URI = "file://99-agl-fibredyne-amp.rules \
+           file://enable-agl-demo-hal.sh \
+"
+
+do_compile[noexec] = "1"
+
+do_install() {
+    install -d ${D}${sbindir}
+    install -m 0755 ${WORKDIR}/enable-agl-demo-hal.sh ${D}${sbindir}
+
+    install -d ${D}${sysconfdir}/udev/rules.d
+    install -m 0644 ${WORKDIR}/99-agl-fibredyne-amp.rules ${D}${sysconfdir}/udev/rules.d/
+}
+
+RDEPENDS_${PN} += "bash"
index 2f2804b..65e043e 100644 (file)
@@ -68,11 +68,20 @@ QTAGLEXTRAS = "${@bb.utils.contains("DISTRO_FEATURES", "agl-hmi-framework", " qt
 MAPVIEWER = "${@bb.utils.contains("PREFERRED_RPROVIDER_virtual/navigation", "ondemandnavi", "tbtnavi", "",d)}"
 CLUSTER_SUPPORT = "${@bb.utils.contains("DISTRO_FEATURES", "agl-cluster-demo-support", "${MAPVIEWER} cluster-demo-network-config", "",d)}"
 
+# Hook for demo platform configuration
+# ATM used for:
+# 1) Adding udev configuration and scripts for supporting USB attached
+#    I2C devices for RTC and HVAC LED support.
+DEMO_PLATFORM_CONF = " demo-i2c-udev-conf "
+
 # Preload poi API key for demo if requested, and potentially maps for older
 # navigation application if it is configured.
 DEMO_MAPS_LOCALE ?= "uk"
 DEMO_PRELOAD_MAPS = "${@bb.utils.contains("PREFERRED_RPROVIDER_virtual/navigation", "navigation", " navigation-maps-${DEMO_MAPS_LOCALE}", "",d)}"
-DEMO_PRELOAD = "${@bb.utils.contains("DISTRO_FEATURES", "agl-demo-preload", " ${DEMO_PRELOAD_MAPS} poiapp-api-key", "",d)}"
+
+# Preload only if agl-demo-preload is set
+DEMO_PRELOAD = "${@bb.utils.contains("DISTRO_FEATURES", "agl-demo-preload", " ${DEMO_PRELOAD_MAPS} ${DEMO_PLATFORM_CONF} poiapp-api-key", "",d)}"
+
 
 # Hook for demo platform configuration
 # ATM, only used to disable btwilink module on [MH]3ULCB + Kingfisher by default,