From 1ce9e1b8622eddc61458e8212d63e42bd97a807f Mon Sep 17 00:00:00 2001 From: Ramon Moesching Date: Fri, 5 Apr 2019 16:00:06 +0200 Subject: [PATCH] um-service-cfg: Configuration support for user module services User module provides few information over i2c bus, e.g. ip, version,.. Access /proc/device-tree/user_module/ for checking availability of user module and get information and stores settings under /etc/user-module/ Port definitions for each services is provided through this recipe and not through device tree. Would be nice feature for future improvements. socket-uart and cannelloni depends on that recipe. BugzID: 56443 Signed-off-by: Ramon Moesching --- recipes-extended/um-service-cfg/config/ports | 0 .../files/um-rgpio-config.service | 13 +++++ .../um-service-cfg/files/um-rgpio-config.sh | 15 +++++ .../files/um-service-config.service | 10 ++++ .../um-service-cfg/files/um-service-config.sh | 42 ++++++++++++++ .../um-service-cfg/files/user-module.target | 4 ++ .../um-service-cfg/um-service-cfg_0.0.1.bb | 58 +++++++++++++++++++ 7 files changed, 142 insertions(+) create mode 100644 recipes-extended/um-service-cfg/config/ports create mode 100644 recipes-extended/um-service-cfg/files/um-rgpio-config.service create mode 100644 recipes-extended/um-service-cfg/files/um-rgpio-config.sh create mode 100644 recipes-extended/um-service-cfg/files/um-service-config.service create mode 100644 recipes-extended/um-service-cfg/files/um-service-config.sh create mode 100644 recipes-extended/um-service-cfg/files/user-module.target create mode 100644 recipes-extended/um-service-cfg/um-service-cfg_0.0.1.bb diff --git a/recipes-extended/um-service-cfg/config/ports b/recipes-extended/um-service-cfg/config/ports new file mode 100644 index 0000000..e69de29 diff --git a/recipes-extended/um-service-cfg/files/um-rgpio-config.service b/recipes-extended/um-service-cfg/files/um-rgpio-config.service new file mode 100644 index 0000000..5101f0a --- /dev/null +++ b/recipes-extended/um-service-cfg/files/um-rgpio-config.service @@ -0,0 +1,13 @@ +[Unit] +Description=Check whether user module is present and configure user space services +Requires=um-service-config.service user-module.target +After=um-service-config.service user-module.target + + +[Service] +Type=oneshot +ExecStart=/usr/bin/um-rgpio-config +EnvironmentFile=/etc/user-module/network.conf + +[Install] +WantedBy=user-module.target diff --git a/recipes-extended/um-service-cfg/files/um-rgpio-config.sh b/recipes-extended/um-service-cfg/files/um-rgpio-config.sh new file mode 100644 index 0000000..1f7234a --- /dev/null +++ b/recipes-extended/um-service-cfg/files/um-rgpio-config.sh @@ -0,0 +1,15 @@ +#!/bin/sh +UM_SYSFS_REMOTE_GPIO="/sys/class/remote-gpio/remote-gpio/config" + +if [ -z $USER_MODULE_ipv4_addr ]; then + echo Start script by systemd service or set variables +else + if [ -d $UM_SYSFS_REMOTE_GPIO ]; then + if [[ `cat $UM_SYSFS_REMOTE_GPIO/ip` != $USER_MODULE_ipv4_addr || `cat $UM_SYSFS_REMOTE_GPIO/port` != $USER_MODULE_ipv4_port ]]; then + echo $USER_MODULE_ipv4_addr > $UM_SYSFS_REMOTE_GPIO/ip + echo $USER_MODULE_remote_gpio_port > $UM_SYSFS_REMOTE_GPIO/port + fi + exit 0 + fi +fi +exit 1 diff --git a/recipes-extended/um-service-cfg/files/um-service-config.service b/recipes-extended/um-service-cfg/files/um-service-config.service new file mode 100644 index 0000000..8168c92 --- /dev/null +++ b/recipes-extended/um-service-cfg/files/um-service-config.service @@ -0,0 +1,10 @@ +[Unit] +Description=Check whether user module is present and configure user space services +After=user-module.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/um-service-config + +[Install] +WantedBy=user-module.target diff --git a/recipes-extended/um-service-cfg/files/um-service-config.sh b/recipes-extended/um-service-cfg/files/um-service-config.sh new file mode 100644 index 0000000..e2bbd4e --- /dev/null +++ b/recipes-extended/um-service-cfg/files/um-service-config.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +UM_CONFIG_PATH=/etc/user-module +UM_CONFIG_FILE=network.conf +UM_CONFIG=$UM_CONFIG_PATH/$UM_CONFIG_FILE +UM_PORTS=$UM_CONFIG_PATH/ports + +UM_DTS_NODE=/proc/device-tree/user_module + +DEBUG_NOTE_ORIGIN=$0 + +if [ -f $UM_CONFIG ]; then + rm $UM_CONFIG +else + mkdir -p $UM_CONFIG_PATH +fi + + +# fetch user module status and network informations +for f in $UM_DTS_NODE/*; do + echo "USER_MODULE_${f##*/}=\"`cat $f`\"" | sed -E "s/,|-/_/g" >> $UM_CONFIG +done + +cat $UM_PORTS >> $UM_CONFIG + +# source all fetched informations +source $UM_CONFIG + +if [[ $USER_MODULE_status = "disabled" ]]; then + exit 1 +fi + +ping $USER_MODULE_ipv4_addr -w 3 -c 1 + +if [ $? -eq 0 ]; then + echo $DEBUG_NOTE_ORIGIN: Target with ipv4 $USER_MODULE_ipv4_addr available + exit 0 +else + echo $DEBUG_NOTE_ORIGIN: Target with ipv4 $USER_MODULE_ipv4_addr not available + exit 1 +fi + diff --git a/recipes-extended/um-service-cfg/files/user-module.target b/recipes-extended/um-service-cfg/files/user-module.target new file mode 100644 index 0000000..104fbc3 --- /dev/null +++ b/recipes-extended/um-service-cfg/files/user-module.target @@ -0,0 +1,4 @@ +[Unit] +Description=Just fetch user module informations from proc filesystem +After=network-online.target +Wants=network-online.target diff --git a/recipes-extended/um-service-cfg/um-service-cfg_0.0.1.bb b/recipes-extended/um-service-cfg/um-service-cfg_0.0.1.bb new file mode 100644 index 0000000..a572f79 --- /dev/null +++ b/recipes-extended/um-service-cfg/um-service-cfg_0.0.1.bb @@ -0,0 +1,58 @@ +# Copyright (C) 2019 Ramon Moesching +# Released under the MIT license (see COPYING.MIT for the terms) +inherit systemd +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" +FILESEXTRAPATHS_prepend := "${THISDIR}/config:" + +SRC_URI = " \ + file://um-service-config.service \ + file://um-service-config.sh \ + file://user-module.target \ + file://um-rgpio-config.sh \ + file://um-rgpio-config.service \ + file://ports \ + " + +FILES_${PN} = "${systemd_unitdir}/system ${bindir} /etc/user-module" + +SYSTEMD_SERVICE_${PN} =" \ + um-service-config.service \ + um-rgpio-config.service \ + user-module.target \ + " + +do_install_append() { +# port config + echo "USER_MODULE_kline_port=\"2202\"" >> ${WORKDIR}/ports + echo "USER_MODULE_lin_port=\"2200\"" >> ${WORKDIR}/ports + echo "USER_MODULE_uart_port=\"2204\"" >> ${WORKDIR}/ports + echo "USER_MODULE_cannellonie_port_remote=\"20000\"" >> ${WORKDIR}/ports + echo "USER_MODULE_cannellonie_port_local=\"20000\"" >> ${WORKDIR}/ports + echo "USER_MODULE_remote_gpio_port=\"6666\"" >> ${WORKDIR}/ports + + install -d ${D}/etc/user-module + install -m 644 ${WORKDIR}/ports ${D}/etc/user-module/ports +} + + +do_install() { + + install -d ${D}${systemd_unitdir}/system + install -m 644 ${WORKDIR}/um-service-config.service ${D}${systemd_unitdir}/system/ + + install -d ${D}${systemd_system_unitdir}/ + install -m 0644 ${WORKDIR}/user-module.target ${D}${systemd_system_unitdir}/ + + install -d ${D}${systemd_system_unitdir}/multi-user.target.wants + ln -sf ${systemd_system_unitdir}/user-module.target ${D}${systemd_system_unitdir}/multi-user.target.wants/user-module.target + + install -d ${D}${bindir} + install -m 744 ${WORKDIR}/um-service-config.sh ${D}${bindir}/um-service-config + + install -d ${D}${systemd_unitdir}/system + install -m 644 ${WORKDIR}/um-rgpio-config.service ${D}${systemd_unitdir}/system/ + install -d ${D}${bindir} + install -m 744 ${WORKDIR}/um-rgpio-config.sh ${D}${bindir}/um-rgpio-config +} +