meta-facebook: obmc_functions : Add Command script
1. Add Command script to avoid shellcheck fail.
example.
gpioset $(gpiofind line_name)=1
need change to gpioset "$(gpiofind line_name)"=1 to avoid shellcheck
fail but it can't work.
2. Add set_gpio and get_gpio script for all meta-facebook platform
Usage:
set_gpio LINE_NAME SetValue
val="$(get_gpio "LINE_NAME")"
Change-Id: I99cb2e60e29a24a273d0bb9e0cb276106d730b22
Signed-off-by: Peter Yin <peter.yin@quantatw.com>
diff --git a/meta-facebook/recipes-fb/obmc_functions/fb-common-functions_0.1.bb b/meta-facebook/recipes-fb/obmc_functions/fb-common-functions_0.1.bb
new file mode 100644
index 0000000..ab50539
--- /dev/null
+++ b/meta-facebook/recipes-fb/obmc_functions/fb-common-functions_0.1.bb
@@ -0,0 +1,13 @@
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+RDEPENDS:${PN} += " bash"
+
+SRC_URI += " \
+ file://fb-common-functions \
+ "
+
+do_install() {
+ install -d ${D}${libexecdir}
+ install -m 0755 ${WORKDIR}/fb-common-functions ${D}${libexecdir}
+}
diff --git a/meta-facebook/recipes-fb/obmc_functions/files/fb-common-functions b/meta-facebook/recipes-fb/obmc_functions/files/fb-common-functions
new file mode 100644
index 0000000..b04332a
--- /dev/null
+++ b/meta-facebook/recipes-fb/obmc_functions/files/fb-common-functions
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+get_gpio()
+{
+ local NET_NAME=$1
+ local RET_VAL
+
+ mapfile -t -d " " GPIO_INFO < <(gpiofind "$NET_NAME")
+ if [ "${#GPIO_INFO[@]}" -ne 2 ]; then
+ echo "get_gpio: can not find gpio, $NET_NAME" >&2
+ return 1
+ fi
+ if ! RET_VAL=$(gpioget "${GPIO_INFO[0]}" "${GPIO_INFO[1]%$'\n'}") ; then
+ echo "get_gpio: get ${NET_NAME} failed" >&2
+ return 1
+ fi
+ echo "${RET_VAL}"
+ return 0
+}
+
+set_gpio()
+{
+ local NET_NAME=$1
+ local OUT_VAL=$2
+ mapfile -t -d " " GPIO_INFO < <(gpiofind "$NET_NAME")
+ if [ "${#GPIO_INFO[@]}" -ne 2 ]; then
+ echo "set_gpio: can not find gpio, $NET_NAME"
+ return 1
+ fi
+
+ echo -n "set_gpio: set $NET_NAME = $OUT_VAL"
+ if ! gpioset "${GPIO_INFO[0]}" "${GPIO_INFO[1]%$'\n'}"="$OUT_VAL"; then
+ echo " failed"
+ return 1
+ fi
+
+ echo " success"
+ return 0
+}
diff --git a/meta-facebook/recipes-fb/packagegroups/packagegroup-fb-apps.bb b/meta-facebook/recipes-fb/packagegroups/packagegroup-fb-apps.bb
index dd6eeab..e92b52d 100644
--- a/meta-facebook/recipes-fb/packagegroups/packagegroup-fb-apps.bb
+++ b/meta-facebook/recipes-fb/packagegroups/packagegroup-fb-apps.bb
@@ -64,5 +64,6 @@
phosphor-fan-sensor-monitor \
phosphor-gpio-monitor-monitor \
tzdata-core \
+ fb-common-functions \
${RDEPENDS_PN_SYSTEM_EXTRAS} \
"