summaryrefslogtreecommitdiff
path: root/recipes-bsp/multitech/mt-dt-overlay/init
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2020-09-18 14:34:11 -0500
committerJohn Klug <john.klug@multitech.com>2021-06-22 11:39:24 -0500
commit067a4b3a3dd4a0bccd71649303487c6dcc2ca9e3 (patch)
treec1c4f9f861696ae2c2aa737f04a08077d9bd64a2 /recipes-bsp/multitech/mt-dt-overlay/init
parentc4ea765062db2380cfd0327ccefe00f3848ce768 (diff)
downloadmeta-multitech-067a4b3a3dd4a0bccd71649303487c6dcc2ca9e3.tar.gz
meta-multitech-067a4b3a3dd4a0bccd71649303487c6dcc2ca9e3.tar.bz2
meta-multitech-067a4b3a3dd4a0bccd71649303487c6dcc2ca9e3.zip
Move overlay code from mts-io to mt-dt-overlay
Diffstat (limited to 'recipes-bsp/multitech/mt-dt-overlay/init')
-rwxr-xr-xrecipes-bsp/multitech/mt-dt-overlay/init91
1 files changed, 91 insertions, 0 deletions
diff --git a/recipes-bsp/multitech/mt-dt-overlay/init b/recipes-bsp/multitech/mt-dt-overlay/init
new file mode 100755
index 0000000..748a470
--- /dev/null
+++ b/recipes-bsp/multitech/mt-dt-overlay/init
@@ -0,0 +1,91 @@
+#!/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
+
+i2c=/sys/bus/i2c/devices/
+
+DEVTREE="/sys/kernel/config/device-tree/overlays/"
+SYSFS="/usr/sbin/mts-io-sysfs"
+
+install_dtbo_dir() {
+ for f in *.dtbo ; do
+ if ! [[ -f $f ]] ; then
+ continue
+ fi
+ if ! [[ -d ${DEVTREE} ]] ; then
+ mount configfs
+ fi
+ # f2 is the extracted device name
+ base=$(basename $f .dtbo)
+ /bin/mkdir ${DEVTREE}/$base || true
+ /bin/cat $f >${DEVTREE}/$base/dtbo
+ done
+}
+
+# Device tree format:
+# [mach]
+# [rev]
+# [file1] [file2] [file3] capability
+# [flag]
+# [file1] [file2] [file3]
+setdevtree() {
+ hw=$(${SYSFS} show hw-version)
+ mach=${hw/%-*}
+ rev=${hw/#*-/}
+ echo mach is $mach
+ echo rev is $rev
+ capd="${sysdir}/capability"
+
+ # 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
+ cd $best
+ install_dtbo_dir
+ if [[ -d capability ]] ; then
+ cd capability
+ for d in * ; do
+ if [[ -f ${capd}/$d ]] ; then
+ if (($(cat ${capd}/$d) == 1)) ; then
+ echo "This device has capabilithy $d"
+ (
+ cd $d
+ install_dtbo_dir
+ )
+ fi # Install dtbo files for a capability
+ fi # Does a given capability flag exist in the mts-io platform
+ 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