diff options
Diffstat (limited to 'meta-facebook/meta-yosemite/recipes-yosemite/fbutils/files/ast-functions')
-rw-r--r-- | meta-facebook/meta-yosemite/recipes-yosemite/fbutils/files/ast-functions | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/fbutils/files/ast-functions b/meta-facebook/meta-yosemite/recipes-yosemite/fbutils/files/ast-functions new file mode 100644 index 0000000..f29514f --- /dev/null +++ b/meta-facebook/meta-yosemite/recipes-yosemite/fbutils/files/ast-functions @@ -0,0 +1,147 @@ +# Copyright 2014-present Facebook. All Rights Reserved. +DEVMEM=/sbin/devmem + +devmem_set_bit() { + local addr + local val + addr=$1 + val=$($DEVMEM $addr) + val=$((val | (0x1 << $2))) + $DEVMEM $addr 32 $val +} + +devmem_clear_bit() { + local addr + local val + addr=$1 + val=$($DEVMEM $addr) + val=$((val & ~(0x1 << $2))) + $DEVMEM $addr 32 $val +} + +scu_addr() { + echo $((0x1E6E2000 + 0x$1)) +} + +GPIODIR="/sys/class/gpio" +GPIOEXPORT="$GPIODIR/export" + +gpio_dir() { + echo "$GPIODIR/gpio$1" +} + +gpio_name2value() { + local first remaining base val + remaining=$1 + val=0 + while [ -n "$remaining" ]; do + first=${remaining:0:1} + case "$first" in + [[:lower:]]) + base=$(printf "%d" "'$first'") + base=$((base - 96)) + val=$((val * 26 + base)) + ;; + [[:upper:]]) + base=$(printf "%d" "'$first'") + base=$((base - 64)) + val=$((val * 26 + base)) + ;; + *) + if [ $val -gt 0 ]; then + val=$((val-1)) + fi + val=$((val * 8 + $remaining)) + break + ;; + esac + remaining=${remaining:1} + done + echo "$val" +} + +gpio_export() { + local gpio + gpio=$(gpio_name2value $1) + dir=$(gpio_dir $gpio) + if [ ! -d ${dir} ]; then + echo $gpio > $GPIOEXPORT + fi +} + +gpio_set() { + local gpio + local val + gpio=$(gpio_name2value $1) + val=$2 + dir=$(gpio_dir $gpio) + if [ ! -d ${dir} ]; then + echo $gpio > $GPIOEXPORT + fi + echo out > ${dir}/direction + echo $val > ${dir}/value +} + +gpio_get() { + local gpio + local val + gpio=$(gpio_name2value $1) + dir=$(gpio_dir $gpio) + if [ ! -d ${dir} ]; then + echo $gpio > $GPIOEXPORT + fi + echo in > ${dir}/direction + cat ${dir}/value +} + +# Check to see if BMC power-on-reset +is_bmc_por() { + local val + # Read the Watch Dog Counter + val=$(devmem 0x1e785010 2>/dev/null) + if [ "$((val & 0xff00))" == "0" ]; then + # Power ON Reset + echo 1 + else + echo 0 + fi +} + +# Check to see if server is present in given slot or not +is_server_prsnt() { + local prsnt + + case $1 in + 1) + prsnt=$(gpio_get H5) + ;; + 2) + prsnt=$(gpio_get H4) + ;; + 3) + prsnt=$(gpio_get H7) + ;; + 4) + prsnt=$(gpio_get H6) + ;; + *) + prsnt=$(gpio_get H4) + ;; + esac + + if [ $prsnt == "0" ]; then + echo 1 + else + echo 0 + fi +} + +yosemite_is_server_on() { + local curr_pwr_cpu + curr_pwr_cpu=$(python -c 'import sys; sys.path.append("/usr/local/fbpackages/utils"); import power_util; print power_util.get_pwr_cpu()') + if [ $curr_pwr_cpu == "1" ]; then + echo 1 + else + echo 0 + fi +} |