diff options
Diffstat (limited to 'recipes-bsp/multitech')
-rwxr-xr-x | recipes-bsp/multitech/mt-dt-overlay/init-default (renamed from recipes-bsp/multitech/mt-dt-overlay/init) | 0 | ||||
-rwxr-xr-x | recipes-bsp/multitech/mt-dt-overlay/init-mtcpmhs | 130 | ||||
-rw-r--r-- | recipes-bsp/multitech/mt-dt-overlay_1.2.7.bb | 9 |
3 files changed, 137 insertions, 2 deletions
diff --git a/recipes-bsp/multitech/mt-dt-overlay/init b/recipes-bsp/multitech/mt-dt-overlay/init-default index 4c82e12..4c82e12 100755 --- a/recipes-bsp/multitech/mt-dt-overlay/init +++ b/recipes-bsp/multitech/mt-dt-overlay/init-default diff --git a/recipes-bsp/multitech/mt-dt-overlay/init-mtcpmhs b/recipes-bsp/multitech/mt-dt-overlay/init-mtcpmhs new file mode 100755 index 0000000..defb318 --- /dev/null +++ b/recipes-bsp/multitech/mt-dt-overlay/init-mtcpmhs @@ -0,0 +1,130 @@ +#!/bin/bash +# This script must be run after mts-io +# to read the hw-version, +# but before anything else needs the +# device tree. +sysdir=/sys/devices/platform/mts-io + +I2CDIR="/sys/bus/i2c/devices" +eepromPath="${I2CDIR}/0-0056/eeprom" + +DEVTREE="/sys/kernel/config/device-tree/overlays/" +SYSFS="/usr/sbin/mts-io-sysfs" +AP1_EEPROM=${I2CDIR}"/i2c-2/2-0050/eeprom" +AP2_EEPROM=${I2CDIR}"/i2c-2/2-0052/eeprom" + +install_all_dtbo() { + for f in *.dtbo ; do + if ! [[ -f $f ]] ; then + continue + fi + # f2 is the extracted device name + base=$(basename $f .dtbo) + /bin/mkdir ${DEVTREE}/$base || true + /bin/cat $f >${DEVTREE}/$base/dtbo + done +} + +install_dtbo_dir() { + if ! [[ -d ${DEVTREE} ]] ; then + mount configfs + fi + install_all_dtbo + gpiob1=0 + gpiob2=0 + if [[ -f $AP1_EEPROM ]] ; then + eeprom1=$(mts-id-eeprom --accessory-card --in-file "$AP1_EEPROM" 2>/dev/null) + if [[ $eeprom1 =~ [[:space:]]hw-version:[[:space:]]*\"MTAC-GPIOB- ]] ; then + gpiob1=1 + fi + fi + if [[ -f $AP2_EEPROM ]] ; then + eeprom2=$(mts-id-eeprom --accessory-card --in-file "$AP2_EEPROM" 2>/dev/null) + if [[ $eeprom2 =~ [[:space:]]hw-version:[[:space:]]*\"MTAC-GPIOB- ]] ; then + gpiob2=1 + fi + fi + + if ((gpiob1 == 1)) || ((gpiob2 == 1)) ; then + /usr/bin/logger -t "mts-io" -p daemon.info -s 'Loading MTAC-GPIOB Device Tree' + cd gpiob + else + /usr/bin/logger -t "mts-io" -p daemon.info -s 'Loading standard SPI Device Tree' + cd lora + fi + install_all_dtbo +} + +# Device tree format: +# [mach] +# [rev] +# [file1] [file2] [file3] capability +# [flag] +# [file1] [file2] [file3] +setdevtree() { + eeprom=$(mts-id-eeprom --in-file "$eepromPath" 2>/dev/null) + [[ $eeprom =~ [[:space:]]hw-version:[[:space:]]*\"([^\"]+) ]] + hw=${BASH_REMATCH[1]} + mach=${hw/%-*} + rev=${hw/#*-/} + echo mach is $mach + echo rev is $rev + + regx='capa-(.*):[[:space:]]*true' + capflags=$(echo "$eeprom" | egrep "$regx" | sed -e 's/capa-//g' -e 's/: true//') + capflags=" ${capflags} " + + # add device tree overlays, if they exist. + [[ -d /lib/dtoverlays ]] || return 1 + ( + cd /lib/dtoverlays + + cd ${mach} + + best="-1" + for d in * ; do + if awk "BEGIN{if ($d <= $rev)exit 1}" ; then + continue + fi + if awk "BEGIN{if ($d < $best)exit 1}" ; then + best="$d" + fi + done + if [[ $best == -1 ]] ; then + # No overlay found + exit 0 + fi + cd $best + install_dtbo_dir + if [[ -d capability ]] ; then + cd capability + for d in * ; do + echo "We have found overlay capability directory $d" + if [[ ${capflags} =~ [[:space:]]${d}[[:space:]] ]] ; then + echo "This device has capabilithy $d so install the overlay" + ( + cd $d + install_dtbo_dir + ) + fi # Does a given capability flag exist in the EEPROM + done # Loop over all capabilities for this machine and version overlays + fi # Is there a capability directory to be installed? + ) +} + +case $1 in + start) + /usr/bin/logger -t "mts-io" -p daemon.info -s "Loading device tree overlay" + setdevtree + ;; + + stop) + echo "Not implemented" + ;; + + *) + echo "Usage: $0 {start|stop}" + exit 2 + ;; +esac + diff --git a/recipes-bsp/multitech/mt-dt-overlay_1.2.7.bb b/recipes-bsp/multitech/mt-dt-overlay_1.2.7.bb index 260faea..d9b4f7a 100644 --- a/recipes-bsp/multitech/mt-dt-overlay_1.2.7.bb +++ b/recipes-bsp/multitech/mt-dt-overlay_1.2.7.bb @@ -28,7 +28,8 @@ PR = "r1" SRC_URI = " \ git://git.multitech.net/mt-dt-overlay.git;protocol=git \ - file://init \ + file://init-default \ + file://init-mtcpmhs \ " SRCREV = "${PV}" @@ -61,7 +62,11 @@ addtask install after do_compile # do_install () { install -d ${D}/${sysconfdir}/init.d - install -m 0755 ${WORKDIR}/init ${D}/${sysconfdir}/init.d/${PN} + if [ ${MACHINE} = "mtcpmhs" ] ; then + install -m 0755 ${WORKDIR}/init-mtcpmhs ${D}/${sysconfdir}/init.d/${PN} + else + install -m 0755 ${WORKDIR}/init-default ${D}/${sysconfdir}/init.d/${PN} + fi # Copy files to /lib/dt-overlay/main (mtac cards will be in mtac) if [ -e ${AT91BOOTSTRAP_MACHINE} ]; then install -d ${D}/${dt_dir} |