diff options
Diffstat (limited to 'meta-edison-distro/recipes-support')
29 files changed, 1101 insertions, 0 deletions
diff --git a/meta-edison-distro/recipes-support/blink-led/blink-led_0.1.bb b/meta-edison-distro/recipes-support/blink-led/blink-led_0.1.bb new file mode 100644 index 0000000..9fff7d2 --- /dev/null +++ b/meta-edison-distro/recipes-support/blink-led/blink-led_0.1.bb @@ -0,0 +1,23 @@ +DESCRIPTION = "Blinks the Edison LED" +SECTION = "base" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +FILESEXTRAPATHS_prepend := "${THISDIR}/files/" + +SRC_URI = "file://blink-led" +SRC_URI += "file://blink-led.service" + +S = "${WORKDIR}" + +do_install() { + install -d ${D}${bindir} + install -m 0755 blink-led ${D}${bindir} + + # Copy service file + install -d ${D}/${systemd_unitdir}/system + install -m 644 ${WORKDIR}/blink-led.service ${D}/${systemd_unitdir}/system +} + +FILES_${PN} += "${base_libdir}/systemd/system/blink-led.service" +FILES_${PN} += "${bindir}/blink-led" diff --git a/meta-edison-distro/recipes-support/blink-led/files/blink-led b/meta-edison-distro/recipes-support/blink-led/files/blink-led new file mode 100755 index 0000000..f8b884f --- /dev/null +++ b/meta-edison-distro/recipes-support/blink-led/files/blink-led @@ -0,0 +1,109 @@ +#!/usr/bin/env python + +# +# Edison LED blinker +# +# Copyright (c) 2014, Intel Corporation. +# Fabien Chereau <fabien.chereau@intel.com> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# This is a very poor implementation as it uses subprocesses for init + +import subprocess +import time +import argparse +import signal +import sys + +initial_led_state = "high" + +def write_led(value): + with open("/sys/class/gpio/gpio40/direction","w") as lf: + lf.write(value) + +def blink_once(): + write_led("low") + time.sleep(1./args.frequency*args.duty_cycle) + write_led("high") + time.sleep(1./args.frequency*(1.-args.duty_cycle)) + +def deinit_led_gpio(): + # Revert to default state with LED activated + write_led(initial_led_state) + + # Deinit LED GPIO + subprocess.call(""" + echo 40 >/sys/class/gpio/unexport + echo 214 >/sys/class/gpio/unexport + echo 243 >/sys/class/gpio/unexport + echo 261 >/sys/class/gpio/unexport + """, shell=True) + +def signal_term_handler(signal, frame): + print 'Signal intercepted: de-initing LED GPIOs' + deinit_led_gpio() + sys.exit(0) + + +parser = argparse.ArgumentParser(description='Blink the Edison Arduino board LED.') +parser.add_argument('--frequency', type=float, default=4, help='blink frequency in Hz') +parser.add_argument('--duration', type=float, default=-1, help='duration of the blink in seconds. Negative value means no timeout, i.e. it will stop when the program is killed.') +parser.add_argument('--duty_cycle', type=float, default=0.5, help='duty cycle between 0 and 1') + +args = parser.parse_args() + +# Allows to quit cleanly with CRTL+C or SIGTERM (systemd use SIGTERM to kill a service by default) +signal.signal(signal.SIGTERM, signal_term_handler) +signal.signal(signal.SIGINT, signal_term_handler) + +# Init GPIO mux for LED control +subprocess.call(""" +echo 40 >/sys/class/gpio/export +echo 214 >/sys/class/gpio/export +echo 243 >/sys/class/gpio/export +echo 261 >/sys/class/gpio/export +echo high >/sys/class/gpio/gpio214/direction +echo mode0 > /sys/kernel/debug/gpio_debug/gpio40/current_pinmux +echo low >/sys/class/gpio/gpio243/direction +echo high >/sys/class/gpio/gpio261/direction +echo low >/sys/class/gpio/gpio214/direction""", shell=True) + +# Save current LED value for reverting to proper state at exit +try: + lf = open("/sys/class/gpio/gpio40/value","r") + v = lf.read() + lf.close() + if v[0] == '0': + initial_led_state = "low" + else: + initial_led_state = "high" +except: + print "Can't get current LED state" + +# Blink LED +if args.duration >= 0: + for i in range(0, int(args.duration*args.frequency)): + blink_once() +else: + while True: + blink_once() + +deinit_led_gpio() + diff --git a/meta-edison-distro/recipes-support/blink-led/files/blink-led.service b/meta-edison-distro/recipes-support/blink-led/files/blink-led.service new file mode 100644 index 0000000..3dcb2ab --- /dev/null +++ b/meta-edison-distro/recipes-support/blink-led/files/blink-led.service @@ -0,0 +1,10 @@ +[Unit] +Description=Edison Arduino board LED Blinker + +[Service] +ExecStart=/usr/bin/blink-led +Restart=on-failure + +[Install] +WantedBy=basic.target + diff --git a/meta-edison-distro/recipes-support/cleanjournal/cleanjournal.bb b/meta-edison-distro/recipes-support/cleanjournal/cleanjournal.bb new file mode 100644 index 0000000..cc21638 --- /dev/null +++ b/meta-edison-distro/recipes-support/cleanjournal/cleanjournal.bb @@ -0,0 +1,31 @@ +DESCRIPTION = "Cleanjournal tool. Remove all corrupted journald entries at startup." +SECTION = "base" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + + +SRC_URI += "file://cleanjournal.service" +SRC_URI += "file://clean_journal.sh" + +SYSTEMD_SERVICE_${PN} = "cleanjournal.service" + +RDEPENDS_${PN} = "systemd" +DEPENDS = "systemd" +inherit systemd + +do_install() { + # install service file + install -d ${D}${systemd_unitdir}/system + install -c -m 0644 ${WORKDIR}/cleanjournal.service ${D}${systemd_unitdir}/system + + # install cleanjournal script + install -d ${D}${sbindir} + install -c -m 0755 ${WORKDIR}/clean_journal.sh ${D}${sbindir} +} + +# As this package is tied to systemd, only build it when we're also building systemd. +python () { + if not oe.utils.contains ('DISTRO_FEATURES', 'systemd', True, False, d): + raise bb.parse.SkipPackage("'systemd' not in DISTRO_FEATURES") +} + diff --git a/meta-edison-distro/recipes-support/cleanjournal/files/clean_journal.sh b/meta-edison-distro/recipes-support/cleanjournal/files/clean_journal.sh new file mode 100644 index 0000000..5758d09 --- /dev/null +++ b/meta-edison-distro/recipes-support/cleanjournal/files/clean_journal.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# +# Cleanjournal script +# +# Copyright (c) 2014, Intel Corporation. +# Fabien Rodriguez <fabienx.rodriguez@intel.com> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +# +# This script checks if the remaining space in root partition is lower than 10%. +# In that case, the corrupted journald entries (ended by '~') will be deleted +# one by one until remaining space becomes greater or equal to 10%. +# At each boot, the script is launched by systemd at startup. +# + +# max allowed free space is 10% +max_allowed_free_space=10 + +# check remaining space and update clean_journal_needed variable +check_free_space() { + current_free_space=$(df -h | grep /dev/root | awk '{print 100 - $5}' | sed 's/%//') + if [ "$current_free_space" -lt "$max_allowed_free_space" ]; then + clean_journal_needed=true + else + clean_journal_needed=false + fi +} + +check_free_space +if [ "$clean_journal_needed" = true ]; then + # delete each journald corrupted entry + # until remaining space becomes greater than 10% + for corrupted_journal_file in $(find /var/log/journal/ -name '*~'); do + rm "$corrupted_journal_file" + check_free_space + if [ "$clean_journal_needed" = false ]; then + break + fi + done +fi + diff --git a/meta-edison-distro/recipes-support/cleanjournal/files/cleanjournal.service b/meta-edison-distro/recipes-support/cleanjournal/files/cleanjournal.service new file mode 100644 index 0000000..ab704f3 --- /dev/null +++ b/meta-edison-distro/recipes-support/cleanjournal/files/cleanjournal.service @@ -0,0 +1,10 @@ +[Unit] +Description=Cleanjournal service + +[Service] +ExecStart=/usr/sbin/clean_journal.sh +Restart=no + +[Install] +WantedBy=basic.target + diff --git a/meta-edison-distro/recipes-support/crashlog/crashlog.bb b/meta-edison-distro/recipes-support/crashlog/crashlog.bb new file mode 100644 index 0000000..2ef10ce --- /dev/null +++ b/meta-edison-distro/recipes-support/crashlog/crashlog.bb @@ -0,0 +1,31 @@ +DESCRIPTION = "Crashlog tool. Retrieve last saved kernel message in case of crash" +SECTION = "base" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + + +SRC_URI += "file://crashlog.service" +SRC_URI += "file://retrieve_crashlog.sh" + +SYSTEMD_SERVICE_${PN} = "crashlog.service" + +RDEPENDS_${PN} = "systemd" +DEPENDS = "systemd" +inherit systemd + +do_install() { + # install service file + install -d ${D}${systemd_unitdir}/system + install -c -m 0644 ${WORKDIR}/crashlog.service ${D}${systemd_unitdir}/system + + # install crashlog script + install -d ${D}${sbindir} + install -c -m 0755 ${WORKDIR}/retrieve_crashlog.sh ${D}${sbindir} +} + +# As this package is tied to systemd, only build it when we're also building systemd. +python () { + if not oe.utils.contains ('DISTRO_FEATURES', 'systemd', True, False, d): + raise bb.parse.SkipPackage("'systemd' not in DISTRO_FEATURES") +} + diff --git a/meta-edison-distro/recipes-support/crashlog/files/crashlog.service b/meta-edison-distro/recipes-support/crashlog/files/crashlog.service new file mode 100644 index 0000000..a2c7aab --- /dev/null +++ b/meta-edison-distro/recipes-support/crashlog/files/crashlog.service @@ -0,0 +1,10 @@ +[Unit] +Description=Crashlog service + +[Service] +ExecStart=/usr/sbin/retrieve_crashlog.sh +Restart=no + +[Install] +WantedBy=basic.target + diff --git a/meta-edison-distro/recipes-support/crashlog/files/retrieve_crashlog.sh b/meta-edison-distro/recipes-support/crashlog/files/retrieve_crashlog.sh new file mode 100755 index 0000000..a7f007c --- /dev/null +++ b/meta-edison-distro/recipes-support/crashlog/files/retrieve_crashlog.sh @@ -0,0 +1,98 @@ +#!/bin/sh + +# +# Crashlog script +# +# Copyright (c) 2014, Intel Corporation. +# Simon Desfarges <simonx.desfarges@intel.com> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +# +# This script automatically gather kernel logs in case of crashing. +# At each boot, the script is launched by systemd at startup. +# It detects the boot reason and in case of watchdog reboot +# (saying the platform hanged) the script will save the kernel +# log into a file named crashlog_xxxx. +# + +ipanic_console_path=/proc/emmc_ipanic_console +crashlog_path=/home/root + +# line containing 'WAKESRC' looks like: +# 'Jan 01 00:00:12 edison kernel: [BOOT] WAKESRC=[real reset] (osnib)' +# wakesrc is the 4th field with [ and ] separators +# List of available wake sources is in driver/platform/x86/intel_scu_ipcutil.c + +wakesrc=$(journalctl -k -b -0 | grep WAKESRC | awk -F'[][]' '{print $4}') + +# any watchdog boot implies a crash +tmp=$(echo -n "${wakesrc}" | grep watchdog) +if [ -n "${tmp}" ]; then + # get the last sequence number (ie for crashlog_00001, get the 1) + last_sequence_number=$(ls ${crashlog_path}/crashlog_* | tail -1 | awk -F_ '{print $NF}' | awk -F. '{print $NR}') + if [ -z $last_sequence_number ]; then + last_sequence_number="0" + fi + + new_sequence_number=$(expr ${last_sequence_number} + 1) + new_name=$(printf "crashlog_%05d" $new_sequence_number) + + # create working directory + mkdir ${crashlog_path}/${new_name} + + # write crashfile + crashfile_path=${crashlog_path}/${new_name}/crashfile + + event="CRASH" + manufacturer="Intel Corporation" + product_name=$(cat /factory/hardware_model) + version=$(cat /factory/hardware_version) + serial_number=$(cat /factory/serial_number) + linux_version=$(uname -a) + build_version=$(cat /etc/version) + date=$(date) + + echo "EVENT=${event}" > ${crashfile_path} + echo "Manufacturer : ${manufacturer}" >> ${crashfile_path} + echo "Product name : ${product_name}" >> ${crashfile_path} + echo "Version : ${version}" >> ${crashfile_path} + echo "Serial Number : ${serial_number}" >> ${crashfile_path} + echo "Linux version : ${linux_version}" >> ${crashfile_path} + echo "Build version : ${build_version}" >> ${crashfile_path} + echo "Date : ${date}" >> ${crashfile_path} + echo -e "Wake source : ${wakesrc}" >> ${crashfile_path} + + # write full journal binary & logs from previous boot + journalctl -b -1 -o short-monotonic > ${crashlog_path}/${new_name}/journal_logs + journalctl -b -1 -o export > ${crashlog_path}/${new_name}/journal_binary + + # write panic trace + if [ -e ${ipanic_console_path} ]; then + cat ${ipanic_console_path} > ${crashlog_path}/${new_name}/panic + echo clear > ${ipanic_console_path} + fi + + # create archive and clear folder + tar -zcf ${crashlog_path}/${new_name}.tar.gz -C ${crashlog_path} ${new_name} + rm -rf ${crashlog_path}/${new_name} + +fi + diff --git a/meta-edison-distro/recipes-support/edison-mcu/files/intel_mcu.bin b/meta-edison-distro/recipes-support/edison-mcu/files/intel_mcu.bin Binary files differnew file mode 100644 index 0000000..dcf0544 --- /dev/null +++ b/meta-edison-distro/recipes-support/edison-mcu/files/intel_mcu.bin diff --git a/meta-edison-distro/recipes-support/edison-mcu/files/mcu_fw_loader.service b/meta-edison-distro/recipes-support/edison-mcu/files/mcu_fw_loader.service new file mode 100644 index 0000000..0057ab6 --- /dev/null +++ b/meta-edison-distro/recipes-support/edison-mcu/files/mcu_fw_loader.service @@ -0,0 +1,10 @@ +[Unit] +Description=Daemon to load edison mcu app binary +After=syslog.target + +[Service] +ExecStart=/etc/intel_mcu/mcu_fw_loader.sh + +[Install] +WantedBy=multi-user.target + diff --git a/meta-edison-distro/recipes-support/edison-mcu/files/mcu_fw_loader.sh b/meta-edison-distro/recipes-support/edison-mcu/files/mcu_fw_loader.sh new file mode 100644 index 0000000..734352d --- /dev/null +++ b/meta-edison-distro/recipes-support/edison-mcu/files/mcu_fw_loader.sh @@ -0,0 +1,12 @@ +#!/bin/sh +#author: JiuJin Hong (jiujinx.hong@intel.com) +if [ ! -d "/sys/devices/platform/intel_mcu" ];then + exit +fi + +if [ ! -f "/lib/firmware/intel_mcu.bin" ];then + exit +fi + +echo "load mcu app" > /sys/devices/platform/intel_mcu/control + diff --git a/meta-edison-distro/recipes-support/edison-mcu/mcu-fw-bin_0.1.bb b/meta-edison-distro/recipes-support/edison-mcu/mcu-fw-bin_0.1.bb new file mode 100644 index 0000000..eafb813 --- /dev/null +++ b/meta-edison-distro/recipes-support/edison-mcu/mcu-fw-bin_0.1.bb @@ -0,0 +1,17 @@ +DESCRIPTION = "This is edison mcu fw binary." +HOMEPAGE = "http://www.intel.com" +LICENSE = "CLOSED" + +FILESEXTRAPATHS_prepend := "${THISDIR}/files/" + +SRC_URI = "file://intel_mcu.bin" + +S = "${WORKDIR}" + +do_install () { + install -v -d ${D}/${base_libdir}/firmware/ + install -m 644 intel_mcu.bin ${D}/${base_libdir}/firmware/ +} + +FILES_${PN} = "${base_libdir}/firmware/" + diff --git a/meta-edison-distro/recipes-support/edison-mcu/mcu-fw-load_0.1.bb b/meta-edison-distro/recipes-support/edison-mcu/mcu-fw-load_0.1.bb new file mode 100644 index 0000000..a48aa10 --- /dev/null +++ b/meta-edison-distro/recipes-support/edison-mcu/mcu-fw-load_0.1.bb @@ -0,0 +1,23 @@ +DESCRIPTION = "This is intel mcu app download daemon." +HOMEPAGE = "http://www.intel.com" +LICENSE = "CLOSED" + +FILESEXTRAPATHS_prepend := "${THISDIR}/files/" + +SRC_URI = "file://mcu_fw_loader.service \ + file://mcu_fw_loader.sh" + +SYSTEMD_SERVICE_${PN} = "mcu_fw_loader.service" + +S = "${WORKDIR}" + +inherit systemd + +do_install () { + install -d ${D}${sysconfdir}/intel_mcu/ + install -m 0755 mcu_fw_loader.sh ${D}${sysconfdir}/intel_mcu/ + + install -d ${D}${systemd_unitdir}/system/ + install -m 0644 mcu_fw_loader.service ${D}${systemd_unitdir}/system/ +} + diff --git a/meta-edison-distro/recipes-support/edison-sst/files/fw_sst_119a.bin b/meta-edison-distro/recipes-support/edison-sst/files/fw_sst_119a.bin Binary files differnew file mode 100644 index 0000000..b704fb6 --- /dev/null +++ b/meta-edison-distro/recipes-support/edison-sst/files/fw_sst_119a.bin diff --git a/meta-edison-distro/recipes-support/edison-sst/sst-fw-bin_0.1.bb b/meta-edison-distro/recipes-support/edison-sst/sst-fw-bin_0.1.bb new file mode 100644 index 0000000..a6c7021 --- /dev/null +++ b/meta-edison-distro/recipes-support/edison-sst/sst-fw-bin_0.1.bb @@ -0,0 +1,19 @@ +DESCRIPTION = "This is edison sst fw binary." +HOMEPAGE = "http://www.intel.com" +LICENSE = "CLOSED" + +FILESEXTRAPATHS_prepend := "${THISDIR}/files/" + +SRC_URI = "file://fw_sst_119a.bin" + +S = "${WORKDIR}" + +do_install () { + install -v -d ${D}/${base_libdir}/firmware/ + install -m 644 fw_sst_119a.bin ${D}/${base_libdir}/firmware/ +} + +INSANE_SKIP_${PN} = "arch" + +FILES_${PN} = "${base_libdir}/firmware/" + diff --git a/meta-edison-distro/recipes-support/i2c-tools/i2c-tools-3.0.3/Module.mk b/meta-edison-distro/recipes-support/i2c-tools/i2c-tools-3.0.3/Module.mk new file mode 100644 index 0000000..7c7b636 --- /dev/null +++ b/meta-edison-distro/recipes-support/i2c-tools/i2c-tools-3.0.3/Module.mk @@ -0,0 +1,72 @@ +# EEPROMER +# +# Licensed under the GNU General Public License. + +EEPROMER_DIR := eepromer + +EEPROMER_CFLAGS := -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \ + -Wcast-align -Wwrite-strings -Wnested-externs -Winline \ + -W -Wundef -Wmissing-prototypes -Iinclude + +EEPROMER_TARGETS := eepromer eeprom eeprog + +# +# Programs +# + +$(EEPROMER_DIR)/eepromer: $(EEPROMER_DIR)/eepromer.o + $(CC) $(LDFLAGS) -o $@ $^ + +$(EEPROMER_DIR)/eeprom: $(EEPROMER_DIR)/eeprom.o + $(CC) $(LDFLAGS) -o $@ $^ + +$(EEPROMER_DIR)/eeprog: $(EEPROMER_DIR)/eeprog.o $(EEPROMER_DIR)/24cXX.o + $(CC) $(LDFLAGS) -o $@ $^ + +# +# Objects +# + +$(EEPROMER_DIR)/eepromer.o: $(EEPROMER_DIR)/eepromer.c + $(CC) $(CFLAGS) $(EEPROMER_CFLAGS) -c $< -o $@ + +$(EEPROMER_DIR)/eeprom.o: $(EEPROMER_DIR)/eeprom.c + $(CC) $(CFLAGS) $(EEPROMER_CFLAGS) -c $< -o $@ + +$(EEPROMER_DIR)/eeprog.o: $(EEPROMER_DIR)/eeprog.c + $(CC) $(CFLAGS) $(EEPROMER_CFLAGS) -c $< -o $@ + +$(EEPROMER_DIR)/24cXX.o: $(EEPROMER_DIR)/24cXX.c + $(CC) $(CFLAGS) $(EEPROMER_CFLAGS) -c $< -o $@ + +# +# Commands +# + +all-eepromer: $(addprefix $(EEPROMER_DIR)/,$(EEPROMER_TARGETS)) + +strip-eepromer: $(addprefix $(EEPROMER_DIR)/,$(EEPROMER_TARGETS)) + strip $(addprefix $(EEPROMER_DIR)/,$(EEPROMER_TARGETS)) + +clean-eepromer: + $(RM) $(addprefix $(EEPROMER_DIR)/,*.o $(EEPROMER_TARGETS)) + +install-eepromer: $(addprefix $(EEPROMER_DIR)/,$(EEPROMER_TARGETS)) + $(INSTALL_DIR) $(DESTDIR)$(sbindir) $(DESTDIR)$(man8dir) + for program in $(EEPROMER_TARGETS) ; do \ + $(INSTALL_PROGRAM) $(EEPROMER_DIR)/$$program $(DESTDIR)$(sbindir) ; done + +uninstall-eepromer: + for program in $(EEPROMER_TARGETS) ; do \ + $(RM) $(DESTDIR)$(sbindir)/$$program ; \ + $(RM) $(DESTDIR)$(man8dir)/$$program.8 ; done + +all: all-eepromer + +strip: strip-eepromer + +clean: clean-eepromer + +install: install-eepromer + +uninstall: uninstall-eepromer diff --git a/meta-edison-distro/recipes-support/i2c-tools/i2c-tools_3.0.3.bb b/meta-edison-distro/recipes-support/i2c-tools/i2c-tools_3.0.3.bb new file mode 100644 index 0000000..021090c --- /dev/null +++ b/meta-edison-distro/recipes-support/i2c-tools/i2c-tools_3.0.3.bb @@ -0,0 +1,24 @@ +DESCRIPTION = "Set of i2c tools for linux" +SECTION = "base" +LICENSE = "GPLv2" +LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe" + +SRC_URI = "http://dl.lm-sensors.org/i2c-tools/releases/i2c-tools-${PV}.tar.bz2 \ + file://Module.mk \ + " +SRC_URI[md5sum] = "511376eed04455cdb277ef19c5f73bb4" +SRC_URI[sha256sum] = "23b28e474741834e3f1b35b0686528769a13adc92d2ff5603cbda1d6bd5e5629" + +inherit autotools + +do_compile_prepend() { + cp ${WORKDIR}/Module.mk ${S}/eepromer/ + sed -i 's#/usr/local#/usr#' Makefile + echo "include eepromer/Module.mk" >> Makefile +} + +do_install_append() { + install -d ${D}${includedir}/linux + install -m 0644 include/linux/i2c-dev.h ${D}${includedir}/linux/i2c-dev-user.h + rm -f ${D}${includedir}/linux/i2c-dev.h +} diff --git a/meta-edison-distro/recipes-support/pwr-button-handler/files/pwr-button-handler.c b/meta-edison-distro/recipes-support/pwr-button-handler/files/pwr-button-handler.c new file mode 100644 index 0000000..d598160 --- /dev/null +++ b/meta-edison-distro/recipes-support/pwr-button-handler/files/pwr-button-handler.c @@ -0,0 +1,167 @@ +/* + * Edison PWR button handler + * + * Copyright (c) 2014, Intel Corporation. + * Fabien Chereau <fabien.chereau@intel.com> + * Loïc Akue <loicx.akue@intel.com> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <string.h> +#include <assert.h> +#include <sys/poll.h> +#include <fcntl.h> +#include <sys/time.h> +#include <sys/ioctl.h> +#include <sys/types.h> + +/* See full definitions in include/linux/input.h */ +/* Also find more doc in Documentation/input/input.txt */ +#define EV_KEY 0x01 +/* Edison Arduino board PWR button code */ +#define KEY_POWER 116 + +/* We use 2 seconds for now */ +#define EDISON_OOBE_PRESS_TIMEOUT 2 + +struct input_event { + struct timeval time; + unsigned short type; + unsigned short code; + unsigned int value; +}; + + +int main(int argc, char **argv) +{ + struct timeval tv; + struct input_event event; + struct pollfd p; + int fd, n; + ssize_t len; + + if (argc!=3) + { + printf("Usage:\n"); + printf(" %s \"command_line1\" \"command_line2\"\n", argv[0]); + printf(" command_line1: a command line to execute when the PWR button is pressed for more than 2s\n"); + printf(" command_line2: a second command line to execute when the PWR button is released (after being pressed for more than 2s)\n"); + return -1; + } + + + /* Time of the last press event. + We reset this to zero when the button is released */ + time_t time_at_last_press = 0; + + int event_already_fired = 0; + + fd = open("/dev/input/event1", O_RDONLY); + if (fd < 0) { + perror("Can't open /dev/input/event1 device"); + return fd; + } + + memset(&p, 0, sizeof(p)); + p.fd = fd; + p.events = POLLIN; + + while (1) { + /* Refresh every 20 ms if the user already started pressing the button */ + n = poll(&p, 1, time_at_last_press==0 ? -1 : 20); + if (n < 0) { + perror("Failed to poll /dev/input/event1 device"); + break; + } + if (n==0) { + /* Poll timed out */ + gettimeofday(&tv, NULL); + if (tv.tv_sec - time_at_last_press >= EDISON_OOBE_PRESS_TIMEOUT && event_already_fired == 0) + { + event_already_fired = 1; + printf("Edison PWR button was pressed more than 2s\n"); + fflush(stdout); + system(argv[1]); + } + continue; + } + + len = read(fd, &event, sizeof(event)); + if (len < 0) { + perror("Reading of /dev/input/event1 events failed"); + break; + } + + if (len != sizeof(event)) { + perror("Wrong size of input_event struct"); + break; + } + + /* ignore non KEY event, and non PWR button events */ + if (event.type != EV_KEY || event.code != KEY_POWER) + continue; + + gettimeofday(&tv, NULL); + +#ifndef NDEBUG + printf("%ld.%06u: type=%u code=%u value=%u\n", + (long) tv.tv_sec, (unsigned int) tv.tv_usec, + event.type, event.code, event.value); + fflush(stdout); +#endif + + switch (event.value) + { + case 1: /* Regular press */ + assert(time_at_last_press==0); + assert(event_already_fired==0); + time_at_last_press = tv.tv_sec; + break; + case 2: /* Auto repeat press */ + if (time_at_last_press == 0) + { + /* This could happen if the user start pressing before the kernel starts */ + time_at_last_press = tv.tv_sec; + } + break; + case 0: /* Release */ + if (event_already_fired != 0) + { + printf("Edison PWR button was pressed more than 2s and released\n"); + fflush(stdout); + system(argv[2]); + } + time_at_last_press = 0; + event_already_fired = 0; + break; + default: + printf("Warning: unhandled PWR button event value: %u\n", event.value); + } + } + + close(fd); + + return 0; +} diff --git a/meta-edison-distro/recipes-support/pwr-button-handler/files/pwr-button-handler.service b/meta-edison-distro/recipes-support/pwr-button-handler/files/pwr-button-handler.service new file mode 100644 index 0000000..a53c10b --- /dev/null +++ b/meta-edison-distro/recipes-support/pwr-button-handler/files/pwr-button-handler.service @@ -0,0 +1,10 @@ +[Unit] +Description=Edison PWR button handler + +[Service] +ExecStart=/usr/bin/pwr_button_handler "/bin/systemctl start blink-led" "sh -c \"/bin/systemctl stop blink-led && /usr/bin/configure_edison --enableOneTimeSetup\"" +Restart=on-failure + +[Install] +WantedBy=default.target + diff --git a/meta-edison-distro/recipes-support/pwr-button-handler/pwr-button-handler_0.1.bb b/meta-edison-distro/recipes-support/pwr-button-handler/pwr-button-handler_0.1.bb new file mode 100644 index 0000000..f58aeb0 --- /dev/null +++ b/meta-edison-distro/recipes-support/pwr-button-handler/pwr-button-handler_0.1.bb @@ -0,0 +1,37 @@ +DESCRIPTION = "Daemon listening to Edison PWR long button press, and starting OOBE service when it happens" +SECTION = "base" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +FILESEXTRAPATHS_prepend := "${THISDIR}/files/" + +inherit systemd + +SYSTEMD_SERVICE_${PN} = "pwr-button-handler.service" + +SRC_URI = "file://pwr-button-handler.c" +SRC_URI += "file://pwr-button-handler.service" + +S = "${WORKDIR}" + +do_compile() { + ${CC} $CFLAGS -DNDEBUG -o pwr_button_handler pwr-button-handler.c +} + +do_install() { + install -d ${D}${bindir} + install -m 0755 pwr_button_handler ${D}${bindir} + + # Copy service file + install -d ${D}/${systemd_unitdir}/system + install -m 644 ${WORKDIR}/pwr-button-handler.service ${D}/${systemd_unitdir}/system + + # And enable it at startup + install -d ${D}${sysconfdir}/systemd/system/default.target.wants + ln -sf ${systemd_unitdir}/system/pwr-button-handler.service \ + ${D}${sysconfdir}/systemd/system/default.target.wants/pwr-button-handler.service +} + +FILES_${PN} = "${base_libdir}/systemd/system/pwr-button-handler.service" +FILES_${PN} += "${sysconfdir}/systemd/system/default.target.wants/pwr-button-handler.service" +FILES_${PN} += "${bindir}/pwr_button_handler" diff --git a/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/0001-minimal-IEEE802.15.4-allowed.patch b/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/0001-minimal-IEEE802.15.4-allowed.patch new file mode 100644 index 0000000..9d3d60d --- /dev/null +++ b/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/0001-minimal-IEEE802.15.4-allowed.patch @@ -0,0 +1,22 @@ +From: Sergey Lapin <slapin@slind.org> +Date: Wed, 28 Jan 2009 16:34:15 +0300 +Subject: [PATCH] minimal IEEE802.15.4 allowed + +--- + tcpdump.c | 3 +++ + 1 files changed, 3 insertions(+), 0 deletions(-) + +diff --git a/tcpdump.c b/tcpdump.c +index 06683af..fbc944c 100644 +--- a/tcpdump.c ++++ b/tcpdump.c +@@ -282,6 +282,9 @@ static struct printer printers[] = { + #ifdef DLT_MFR + { mfr_if_print, DLT_MFR }, + #endif ++#ifdef DLT_IEEE802_15_4 ++ { raw_if_print, DLT_IEEE802_15_4 }, ++#endif + #if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H) + { bt_if_print, DLT_BLUETOOTH_HCI_H4_WITH_PHDR}, + #endif diff --git a/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/configure.patch b/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/configure.patch new file mode 100644 index 0000000..3955ddb --- /dev/null +++ b/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/configure.patch @@ -0,0 +1,29 @@ +--- + aclocal.m4 | 1 - + configure.in | 1 + + 2 files changed, 1 insertions(+), 1 deletions(-) + +diff --git a/aclocal.m4 b/aclocal.m4 +index 40b5866..0c662b0 100644 +--- a/aclocal.m4 ++++ b/aclocal.m4 +@@ -40,7 +40,6 @@ dnl + AC_DEFUN(AC_LBL_C_INIT_BEFORE_CC, + [AC_PREREQ(2.50) + AC_BEFORE([$0], [AC_LBL_C_INIT]) +- AC_BEFORE([$0], [AC_PROG_CC]) + AC_BEFORE([$0], [AC_LBL_FIXINCLUDES]) + AC_BEFORE([$0], [AC_LBL_DEVEL]) + AC_ARG_WITH(gcc, [ --without-gcc don't use gcc]) +diff --git a/configure.in b/configure.in +index 11257c9..7f9591c 100644 +--- a/configure.in ++++ b/configure.in +@@ -19,6 +19,7 @@ AC_REVISION($Revision: 1.204 $) + AC_PREREQ(2.50) + AC_INIT(tcpdump.c) + ++AC_PROG_CC + AC_CANONICAL_HOST + + AC_LBL_C_INIT_BEFORE_CC(V_CCOPT, V_INCLS) diff --git a/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/ipv6-cross.patch b/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/ipv6-cross.patch new file mode 100644 index 0000000..c8a0373 --- /dev/null +++ b/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/ipv6-cross.patch @@ -0,0 +1,41 @@ +--- + configure.in | 12 ++++++++---- + 1 files changed, 8 insertions(+), 4 deletions(-) + +diff --git a/configure.in b/configure.in +index eb3e5e8..11257c9 100644 +--- a/configure.in ++++ b/configure.in +@@ -181,8 +181,9 @@ yes) AC_MSG_RESULT(yes) + ipv6=no + ;; + esac ], +- +- AC_TRY_RUN([ /* AF_INET6 available check */ ++[ ++ if test x"$cross_compiling" != "xyes"; then ++ AC_TRY_RUN([ /* AF_INET6 avalable check */ + #include <sys/types.h> + #include <sys/socket.h> + main() +@@ -201,7 +202,10 @@ main() + ipv6=no], + [ AC_MSG_RESULT(no) + ipv6=no] +-)) ++ ) ++else ++ AC_MSG_FAILURE([Unable to check for ipv6 when crosscompiling, please specify.]) ++fi]) + + ipv6type=unknown + ipv6lib=none +@@ -316,7 +320,7 @@ if test "$ipv6" = "yes" -a "$ipv6lib" != "none"; then + fi + + +-if test "$ipv6" = "yes"; then ++if test x"$cross_compiling" != "xyes" -a "$ipv6" = "yes"; then + # + # XXX - on Tru64 UNIX 5.1, there is no "getaddrinfo()" + # function in libc; there are "ngetaddrinfo()" and diff --git a/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/tcpdump_configure_no_-O2.patch b/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/tcpdump_configure_no_-O2.patch new file mode 100644 index 0000000..7929da5 --- /dev/null +++ b/meta-edison-distro/recipes-support/tcpdump/tcpdump-4.1.1/tcpdump_configure_no_-O2.patch @@ -0,0 +1,42 @@ +--- + configure | 8 ++++---- + 1 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/configure b/configure +index cb51d19..73d51af 100755 +--- a/configure ++++ b/configure +@@ -2691,13 +2691,13 @@ if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS + elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then +- CFLAGS="-g -O2" ++ CFLAGS="-g" + else + CFLAGS="-g" + fi + else + if test "$GCC" = yes; then +- CFLAGS="-O2" ++ CFLAGS="" + else + CFLAGS= + fi +@@ -2830,7 +2830,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu + if test "$GCC" = yes ; then + if test "$SHLICC2" = yes ; then + ac_cv_lbl_gcc_vers=2 +- V_CCOPT="-O2" ++ V_CCOPT="" + else + { echo "$as_me:$LINENO: checking gcc version" >&5 + echo $ECHO_N "checking gcc version... $ECHO_C" >&6; } +@@ -2847,7 +2847,7 @@ fi + { echo "$as_me:$LINENO: result: $ac_cv_lbl_gcc_vers" >&5 + echo "${ECHO_T}$ac_cv_lbl_gcc_vers" >&6; } + if test $ac_cv_lbl_gcc_vers -gt 1 ; then +- V_CCOPT="-O2" ++ V_CCOPT="" + fi + fi + else diff --git a/meta-edison-distro/recipes-support/tcpdump/tcpdump_4.1.1.bb b/meta-edison-distro/recipes-support/tcpdump/tcpdump_4.1.1.bb new file mode 100644 index 0000000..6b81ed0 --- /dev/null +++ b/meta-edison-distro/recipes-support/tcpdump/tcpdump_4.1.1.bb @@ -0,0 +1,41 @@ +DESCRIPTION = "A sophisticated network protocol analyzer" +HOMEPAGE = "http://www.tcpdump.org/" +LICENSE = "BSD" +LIC_FILES_CHKSUM = "file://LICENSE;md5=1d4b0366557951c84a94fabe3529f867" +SECTION = "console/network" +DEPENDS = "libpcap" +PR = "r1" + +SRC_URI = " \ + http://www.tcpdump.org/release/tcpdump-${PV}.tar.gz \ + file://tcpdump_configure_no_-O2.patch \ + file://0001-minimal-IEEE802.15.4-allowed.patch \ + file://ipv6-cross.patch \ + file://configure.patch \ +" + +inherit autotools +# ac_cv_linux_vers=${ac_cv_linux_vers=2} + +EXTRA_OECONF = "--without-crypto \ + ${@base_contains('DISTRO_FEATURES', 'ipv6', '--enable-ipv6', '--disable-ipv6', d)}" + +do_configure() { + # AC_CHECK_LIB(dlpi.. was looking to host /lib + sed -i 's:-L/lib:-L${STAGING_LIBDIR}:g' ./configure.in + + gnu-configize + autoconf + oe_runconf + sed -i 's:/usr/lib:${STAGING_LIBDIR}:' ./Makefile + sed -i 's:/usr/include:${STAGING_INCDIR}:' ./Makefile +} + +do_install_append() { + # tcpdump 4.1.1 installs a copy to /usr/sbin/tcpdump.4.1.1 + rm -f ${D}${sbindir}/tcpdump.${PV} +} + +SRC_URI[md5sum] = "d0dd58bbd6cd36795e05c6f1f74420b0" +SRC_URI[sha256sum] = "e6cd4bbd61ec7adbb61ba8352c4b4734f67b8caaa845d88cb826bc0b9f1e7f0a" + diff --git a/meta-edison-distro/recipes-support/watchdog-sample/watchdog-sample.bb b/meta-edison-distro/recipes-support/watchdog-sample/watchdog-sample.bb new file mode 100644 index 0000000..f0369bc --- /dev/null +++ b/meta-edison-distro/recipes-support/watchdog-sample/watchdog-sample.bb @@ -0,0 +1,46 @@ +DESCRIPTION = "Watchdog sample daemon" +SECTION = "base" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +FILESEXTRAPATHS_prepend := "${THISDIR}/watchdog-sample/" + +SRC_URI += "file://watchdog-sample.service" +SRC_URI += "file://watchdog-sample.c" + +SYSTEMD_SERVICE_${PN} = "watchdog-sample.service" + +RDEPENDS_${PN} = "systemd" +DEPENDS = "systemd" + +S = "${WORKDIR}" + +do_compile() { + $CC $CFLAGS ${S}/watchdog-sample.c `pkg-config --cflags --libs --print-errors libsystemd` -o watchdog-sample +} + +do_install() { + # install service file + install -d ${D}${systemd_unitdir}/system + install -c -m 0644 ${WORKDIR}/watchdog-sample.service ${D}${systemd_unitdir}/system + + # enable the service + install -d ${D}${sysconfdir}/systemd/system/basic.target.wants + ln -sf ${systemd_unitdir}/system/watchdog-sample.service \ + ${D}${sysconfdir}/systemd/system/basic.target.wants/watchdog-sample.service + + # install watchdog binary + install -d ${D}${bindir} + install -c -m 0755 ${B}/watchdog-sample ${D}${bindir} +} + +FILES_${PN} = "${base_libdir}/systemd/system/watchdog-sample.service" +FILES_${PN} += "${sysconfdir}/systemd/system/basic.target.wants/watchdog-sample.service" +FILES_${PN} += "${bindir}/watchdog-sample" + +# As this package is tied to systemd, only build it when we're also building systemd. +python () { + if not oe.utils.contains ('DISTRO_FEATURES', 'systemd', True, False, d): + raise bb.parse.SkipPackage("'systemd' not in DISTRO_FEATURES") +} + diff --git a/meta-edison-distro/recipes-support/watchdog-sample/watchdog-sample/watchdog-sample.c b/meta-edison-distro/recipes-support/watchdog-sample/watchdog-sample/watchdog-sample.c new file mode 100644 index 0000000..7bba6ff --- /dev/null +++ b/meta-edison-distro/recipes-support/watchdog-sample/watchdog-sample/watchdog-sample.c @@ -0,0 +1,92 @@ +/* + * Watchdog daemon sample code + * + * Copyright (c) 2014, Intel Corporation. + * Simon Desfarges <simonx.desfarges@intel.com> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/* + * This file is a simple example on the use of the systemd SW watchdog. + * At startup, the program will create a file in /tmp/watchdog-sample.tmp; + * if the file is removed while the program is running, the program will not + * ping systemd watchdog, resulting in a restart of the program (depending on + * the service configuration). + * This file allow to simulate a hang in the watchdog-critical program. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include <systemd/sd-daemon.h> + +int main(int argc, char * argv[]) { + uint32_t wd_timeout; // in seconds + uint32_t sleep_time; + int err; + char path[] = "/tmp/watchdog-sample.tmp"; + int fd; + if(argc == 2) { + wd_timeout = atoi(argv[1]); + fprintf(stderr, SD_WARNING "Will ping every %ds \n", wd_timeout/2); + } else { + errno=EINVAL; + sd_notifyf(0, SD_EMERG "STATUS=Failed to start up: %s\n" + "ERRNO=%i", + strerror(errno), errno); + exit(-1); + } + + if(wd_timeout == 0) { + sd_notify(0, "Systemd SW watchdog disabled, nothing to do\n"); + exit(0); + } + + fd = open(path, O_RDWR | O_CREAT | O_SYNC, 777); + if(fd == -1) { + sd_notifyf(0, SD_EMERG "STATUS=Failed to create file: %s\n" + "ERRNO=%i", + strerror(errno), errno); + exit(-1); + } + write(fd,"A", 1); + fsync(fd); + close(fd); + + /* Here, systemd WD is enabled and waiting for ping */ + /* wd_timeout variable contains the timeout. We need to ping every wd_timeout/2 */ + sleep_time = wd_timeout/2; + sd_notify(0, "READY=1\n"); + + while(1) { + sd_notify(0, "WATCHDOG=1\n"); + sleep(sleep_time); + + if(access(path, F_OK) == -1) { + sd_notify(0, SD_EMERG "TEMP file disappeared, falling in hang mode\n"); + while(1); + } + } +} + diff --git a/meta-edison-distro/recipes-support/watchdog-sample/watchdog-sample/watchdog-sample.service b/meta-edison-distro/recipes-support/watchdog-sample/watchdog-sample/watchdog-sample.service new file mode 100644 index 0000000..dacb5e0 --- /dev/null +++ b/meta-edison-distro/recipes-support/watchdog-sample/watchdog-sample/watchdog-sample.service @@ -0,0 +1,15 @@ +[Unit] +Description=Watchdog sample daemon + +[Service] +Environment="Timeout=30" +ExecStart=/usr/bin/watchdog-sample ${Timeout} +WatchdogSec=30s +Restart=on-failure +StartLimitInterval=4min +StartLimitBurst=4 +StartLimitAction=reboot-force + +[Install] +WantedBy=basic.target + |