diff options
author | Tian Fang <tfang@fb.com> | 2015-12-14 22:08:40 -0800 |
---|---|---|
committer | Tian Fang <tfang@fb.com> | 2015-12-15 09:49:21 -0800 |
commit | e65a7944211c70f6b5cfb6cedd73cc31105319de (patch) | |
tree | 067082251bc52bc6c09ca87feaa1352d0468a5ac /meta-facebook/meta-wedge/recipes-wedge/fbutils | |
parent | 8a67fbdd0e251bb34d55992b0771edba1837d589 (diff) | |
download | ast2050-yocto-openbmc-e65a7944211c70f6b5cfb6cedd73cc31105319de.zip ast2050-yocto-openbmc-e65a7944211c70f6b5cfb6cedd73cc31105319de.tar.gz |
Sync to internal OpenBMC repo f926614
Diffstat (limited to 'meta-facebook/meta-wedge/recipes-wedge/fbutils')
8 files changed, 11 insertions, 926 deletions
diff --git a/meta-facebook/meta-wedge/recipes-wedge/fbutils/fbutils_0.1.bb b/meta-facebook/meta-wedge/recipes-wedge/fbutils/fbutils_0.1.bb deleted file mode 100644 index 753adbe..0000000 --- a/meta-facebook/meta-wedge/recipes-wedge/fbutils/fbutils_0.1.bb +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright 2014-present Facebook. All Rights Reserved. -SUMMARY = "Utilities" -DESCRIPTION = "Various utilities" -SECTION = "base" -PR = "r1" -LICENSE = "GPLv2" -LIC_FILES_CHKSUM = "file://COPYING;md5=eb723b61539feef013de476e68b5c50a" - -SRC_URI = "file://ast-functions \ - file://us_console.sh \ - file://sol.sh \ - file://power_led.sh \ - file://post_led.sh \ - file://reset_usb.sh \ - file://setup-gpio.sh \ - file://setup_rov.sh \ - file://mdio.py \ - file://bcm5396.py \ - file://bcm5396_util.py \ - file://mount_data0.sh \ - file://eth0_mac_fixup.sh \ - file://wedge_power.sh \ - file://power-on.sh \ - file://wedge_us_mac.sh \ - file://setup_switch.py \ - file://create_vlan_intf \ - file://watch-fc.sh \ - file://fcswitcher.sh \ - file://rc.early \ - file://rc.local \ - file://src \ - file://COPYING \ - " - -pkgdir = "utils" - -S = "${WORKDIR}" - -binfiles = "us_console.sh sol.sh power_led.sh post_led.sh \ - reset_usb.sh mdio.py setup_rov.sh wedge_power.sh wedge_us_mac.sh \ - bcm5396.py bcm5396_util.py setup_switch.py watch-fc.sh" - -DEPENDS_append = "update-rc.d-native" - -do_install() { - dst="${D}/usr/local/fbpackages/${pkgdir}" - install -d $dst - install -m 644 ast-functions ${dst}/ast-functions - localbindir="${D}/usr/local/bin" - install -d ${localbindir} - for f in ${binfiles}; do - install -m 755 $f ${dst}/${f} - ln -s ../fbpackages/${pkgdir}/${f} ${localbindir}/${f} - done - - # common lib and include files - install -d ${D}${includedir}/facebook - install -m 0644 src/include/log.h ${D}${includedir}/facebook/log.h - install -m 0644 src/include/i2c-dev.h ${D}${includedir}/facebook/i2c-dev.h - - # init - install -d ${D}${sysconfdir}/init.d - install -d ${D}${sysconfdir}/rcS.d - # the script to mount /mnt/data - install -m 0755 ${WORKDIR}/mount_data0.sh ${D}${sysconfdir}/init.d/mount_data0.sh - update-rc.d -r ${D} mount_data0.sh start 03 S . - install -m 0755 ${WORKDIR}/rc.early ${D}${sysconfdir}/init.d/rc.early - update-rc.d -r ${D} rc.early start 04 S . - install -m 755 setup-gpio.sh ${D}${sysconfdir}/init.d/setup-gpio.sh - update-rc.d -r ${D} setup-gpio.sh start 59 S . - # create VLAN intf automatically - install -d ${D}/${sysconfdir}/network/if-up.d - install -m 755 create_vlan_intf ${D}${sysconfdir}/network/if-up.d/create_vlan_intf - # networking is done after rcS, any start level within rcS - # for mac fixup should work - install -m 755 eth0_mac_fixup.sh ${D}${sysconfdir}/init.d/eth0_mac_fixup.sh - update-rc.d -r ${D} eth0_mac_fixup.sh start 70 S . - install -m 755 power-on.sh ${D}${sysconfdir}/init.d/power-on.sh - update-rc.d -r ${D} power-on.sh start 85 S . - install -m 755 fcswitcher.sh ${D}${sysconfdir}/init.d/fcswitcher.sh - update-rc.d -r ${D} fcswitcher.sh start 90 S . - install -m 0755 ${WORKDIR}/rc.local ${D}${sysconfdir}/init.d/rc.local - update-rc.d -r ${D} rc.local start 99 2 3 4 5 . -} - -FILES_${PN} += "/usr/local ${sysconfdir}" diff --git a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/ast-functions b/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/ast-functions deleted file mode 100644 index dd53ad1..0000000 --- a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/ast-functions +++ /dev/null @@ -1,222 +0,0 @@ -# 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 -} - -wedge_iso_buf_enable() { - # GPIOC2 (18) to low, SCU90[0] and SCU90[24] must be 0 - devmem_clear_bit $(scu_addr 90) 0 - devmem_clear_bit $(scu_addr 90) 24 - gpio_set 18 0 -} - -wedge_iso_buf_disable() { - # GPIOC2 (18) to low, SCU90[0] and SCU90[24] must be 0 - devmem_clear_bit $(scu_addr 90) 0 - devmem_clear_bit $(scu_addr 90) 24 - gpio_set 18 1 -} - -wedge_is_us_on() { - local val n retries prog - if [ $# -gt 0 ]; then - retries="$1" - else - retries=1 - fi - if [ $# -gt 1 ]; then - prog="$2" - else - prog="" - fi - n=1 - while true; do - val=$(cat /sys/class/i2c-adapter/i2c-4/4-0040/gpio_inputs 2>/dev/null) - if [ -n "$val" ]; then - break - fi - n=$((n+1)) - if [ $n -gt $retries ]; then - echo -n " failed to read GPIO. " - val=0 - break - fi - echo -n "$prog" - sleep 1 - done - if [ "$((val & (0x1 << 14)))" != "0" ]; then - # powered on already - return 0 - else - return 1 - fi -} - - -# Return the board type, 'LC', 'FC-LEFT', 'FC-RIGHT', or, 'WEDGE' -wedge_board_type() { - local pn - pn=$(/usr/bin/weutil 2> /dev/null | grep -i '^Location on Fabric:') - case "$pn" in - *LEFT*) - echo 'FC-LEFT' - ;; - *RIGHT*) - echo 'FC-RIGHT' - ;; - *LC*) - echo 'LC' - ;; - *) - echo 'WEDGE' - ;; - esac -} - -# On FC, FAB_SLOT_ID (GPIOU0), low == FC0; high == FC1 -# On LC, Wedge, -# board rev < 3: -# GPIOU0(ID0), GPIOU1(ID1), GPIOU2(ID2), GPIOU3(ID3) -# else: -# GPIOU6(ID0), GPIOU7(ID1), GPIOV0(ID2), GPIOV1(ID3) -# -# ID[2:0] ID3 Slot# -# 000 0 1 -# 000 1 2 -# 001 0 3 -# 001 1 4 -# 010 0 5 -# 010 1 6 -# 011 0 7 -# 011 1 8 - -wedge_slot_id() { - local type slot id3 id2 id1 id0 FC_CARD_BASE board_rev - FC_CARD_BASE=65 - if [ "$1" = "FC-LEFT" ]; then - # fabric card left - slot=$(gpio_get U0) - slot=$((FC_CARD_BASE + slot * 2)) - elif [ "$1" = "FC-RIGHT" ]; then - # fabric card right - slot=$(gpio_get U0) - slot=$((FC_CARD_BASE + slot * 2 + 1)) - else - # either edge or LC - # need to check the board rev - board_rev=$(wedge_board_rev) - if [ $board_rev -lt 3 ]; then - id0=$(gpio_get U0) - id1=$(gpio_get U1) - id2=$(gpio_get U2) - id3=$(gpio_get U3) - else - id0=$(gpio_get U6) - id1=$(gpio_get U7) - id2=$(gpio_get V0) - id3=$(gpio_get V1) - fi - slot=$(((id2 * 4 + id1 * 2 + id0) * 2 + id3 + 1)) - fi - echo "$slot" -} - -# wedge_board_rev() is only valid after GPIO Y0, Y1, and Y2 are enabled -wedge_board_rev() { - local val0 val1 val2 - val0=$(cat /sys/class/gpio/gpio192/value 2>/dev/null) - val1=$(cat /sys/class/gpio/gpio193/value 2>/dev/null) - val2=$(cat /sys/class/gpio/gpio194/value 2>/dev/null) - echo $((val0 | (val1 << 1) | (val2 << 2))) -} diff --git a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/at93c46.py b/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/at93c46.py deleted file mode 100644 index 368b807..0000000 --- a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/at93c46.py +++ /dev/null @@ -1,260 +0,0 @@ -# Copyright 2004-present Facebook. All rights reserved. - -import subprocess -import struct -import sys - -class VerboseLogger: - def __init__(self, verbose=False): - self.verbose = verbose - - def _verbose_print(self, caption, bytestream=None): - ''' - Print a bytestream to stdout if verbose is enabled. - ''' - if self.verbose: - if bytestream is not None: - sys.stderr.write("{}: {}\n".format(caption, " ".join(['{:02X}'.format(ord(x)) for x in bytestream]))) - else: - sys.stderr.write("{}\n".format(caption)) - -class AT93C46SPI(VerboseLogger): - '''The class to access AT93C46 through SPI intf''' - SPI_CMD = 'spi-bb' - - def __init__(self, bus_width, gpio_cs, gpio_ck, gpio_do, gpio_di, - verbose=False): - if bus_width != 8 and bus_width != 16: - raise Exception("Invalid bus width for AT93C46!") - - self.bus_width = bus_width - self.gpio_cs = gpio_cs - self.gpio_ck = gpio_ck - self.gpio_do = gpio_do - self.gpio_di = gpio_di - self.verbose = verbose - - self.addr_bits = 6 if self.bus_width == 16 else 7 - self.addr_mask = 0x3F if self.bus_width == 16 else 0x7F - - def __shift(self, bytestream, value): - ''' - Shift an entire byte stream by value bits. - ''' - binary = "".join(['{:08b}'.format(ord(x)) for x in bytestream]) - if value > 0: - binary = binary[value:] + '0' * value - else: - binary = '0' * (-value) + binary[:value] - return "".join([chr(int(binary[x:x+8],2)) for x in range(0, len(binary), 8)]) - - def __io(self, op, addr, data=None): - ''' - Perform an IO operation against the EEPROM - ''' - write_bits = self.addr_bits + 3 - if data is not None: - # If giving data, we are doing a write command so - # no need to read any data. - write_bits = write_bits + self.bus_width - read_bits = 0 - else: - # If not giving data, we are doing either a read - # command or a set command, so read the result. - # We pad with an extra bit due to a dummy bit introduced - # by a delay for address decoding on chip. - read_bits = self.addr_bits + 4 + self.bus_width - - # Format the command itself - cmd_loc = 6 if self.bus_width == 16 else 7 - instruction = addr & self.addr_mask - instruction = instruction | ((0x4 | (op & 0x3)) << cmd_loc) - if data is not None: - if self.bus_width == 16: - write_data = struct.pack(">HH", instruction, data & 0xFFFF) - else: - write_data = struct.pack(">HB", instruction, data & 0xFF) - else: - write_data = struct.pack(">H", instruction) - write_data = self.__shift(write_data, 16 - (cmd_loc + 3)) - - self._verbose_print("Write data", write_data) - - # Run the command with the bitbang driver - if read_bits > 0: - data_portion = "-r {} -w {}".format(read_bits, write_bits) - else: - data_portion = "-w {}".format(write_bits) - - cmd = "{} -s {} -c {} -o {} -i {} -b {}".format( - self.SPI_CMD, self.gpio_cs, self.gpio_ck, self.gpio_do, - self.gpio_di, data_portion - ) - - self._verbose_print("Command: {}".format(cmd)) - - out = subprocess.Popen(cmd.split(), - stdout=subprocess.PIPE, - stdin = subprocess.PIPE)\ - .communicate(input=write_data) - - # Format the response - read_data = self.__shift(out[0], cmd_loc + 4) - if self.bus_width == 16: - read_data = read_data[:2] - self._verbose_print("Read data", read_data) - return struct.unpack(">H", read_data)[0] - else: - read_data = read_data[:1] - self._verbose_print("Read data", read_data) - return struct.unpack(">B", read_data)[0] - - def read(self, addr): - return self.__io(0x2, addr) - - def ewen(self): - self.__io(0x0, 0x3 << (self.addr_bits - 2)) - - def erase(self, addr): - self.__io(0x3, addr) - - def write(self, addr, data): - self.__io(0x1, addr, data) - - def eral(self): - self.__io(0x0, 0x2 << (self.addr_bits - 2)) - - def wral(self, data): - self.__io(0x0, 0x1 << (self.addr_bits - 2), data) - - def ewds(self): - self.__io(0x0, 0x0) - -class AT93C46(VerboseLogger): - ''' - The class which handles accessing memory on the AT93C46 chip. - ''' - AT93C46_MEMORY_SIZE = 128 - - def __init__(self, bus_width, gpio_cs, gpio_ck, gpio_do, gpio_di, - byte_swap, verbose=False): - self.bus_width = bus_width - self.verbose = verbose - self.byte_swap = byte_swap - - self.spi = AT93C46SPI(bus_width=bus_width, gpio_cs=gpio_cs, - gpio_ck=gpio_ck, gpio_do=gpio_do, - gpio_di=gpio_di, verbose=verbose) - - def __swap(self, value): - ''' - Swap bytes for a 16-bit integer if instructed to do so. - ''' - if self.bus_width == 16: - if self.byte_swap: - return ((value >> 8) & 0xFF) | ((value << 8) & 0xFF00) - else: - return value - else: - return value - - def erase(self, offset=None, limit=None): - ''' - Erase the chip. - ''' - if offset is None: - offset = 0 - if limit is None: - limit = self.AT93C46_MEMORY_SIZE - - if offset < 0 or offset + limit > self.AT93C46_MEMORY_SIZE: - raise Exception("Erase would be out of bounds!") - if self.bus_width == 16 and \ - ((offset & 1) != 0 or ((offset + limit) & 1) != 0): - raise Exception("Erase can't start or end on odd boundary in 16-bit mode!") - - if offset == 0 and limit == self.AT93C46_MEMORY_SIZE: - # Special case when we are erasing the entire chip - self.spi.ewen() - self.spi.eral() - self.spi.ewds() - - self._verbose_print("Erased entire chip") - else: - # Regular case - if self.bus_width == 16: - real_offset = offset / 2 - real_limit = limit / 2 - else: - real_offset = offset - real_limit = limit - - self.spi.ewen() - for addr in range(real_offset, real_offset + real_limit): - self.spi.erase(addr) - self.spi.ewds() - - self._verbose_print("Erased {} bytes from offset {}".format(limit, offset)) - - def read(self, offset=None, limit=None): - ''' - Read the chip into a memory buffer. - ''' - if offset is None: - offset = 0 - if limit is None: - limit = self.AT93C46_MEMORY_SIZE - - if offset < 0 or offset + limit > self.AT93C46_MEMORY_SIZE: - raise Exception("Read would be out of bounds!") - if self.bus_width == 16 and \ - ((offset & 1) != 0 or ((offset + limit) & 1) != 0): - raise Exception("Read can't start or end on odd boundary in 16-bit mode!") - - output = "" - if self.bus_width == 16: - real_offset = offset / 2 - real_limit = limit / 2 - pack_instruction = "=H" - else: - real_offset = offset - real_offset - pack_instruction = "=B" - - for addr in range(real_offset, real_offset + real_limit): - output = output + struct.pack(pack_instruction, self.__swap(self.spi.read(addr))) - - self._verbose_print("Read {} bytes from offset {}".format(limit, offset), output) - - return output - - def write(self, data, offset=None): - ''' - Write a memory buffer to the chip. - ''' - if offset is None: - offset = 0 - - if offset < 0 or offset + len(data) > self.AT93C46_MEMORY_SIZE: - raise Exception("Write would be out of bounds!") - if self.bus_width == 16 and \ - ((offset & 1) != 0 or ((offset + len(data)) & 1) != 0): - raise Exception("Write can't start or end on odd boundary in 16-bit mode!") - - if self.bus_width == 16: - offset_divisor = 2 - pack_instruction = "=H" - else: - offset_divisor = 1 - pack_instruction = "=B" - - self.spi.ewen() - for addr in range(offset, offset + len(data), offset_divisor): - actual_addr = addr / offset_divisor - value = self.__swap(struct.unpack(pack_instruction, data[(addr - offset):(addr - offset) + offset_divisor])[0]) - - self.spi.erase(actual_addr) - self.spi.write(actual_addr, value) - self.spi.ewds() - - self._verbose_print("Wrote {} bytes from offset {}".format(len(data), offset), data) diff --git a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/at93c46_util.py b/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/at93c46_util.py deleted file mode 100755 index 8910002..0000000 --- a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/at93c46_util.py +++ /dev/null @@ -1,178 +0,0 @@ -#!/usr/bin/python -S -# Copyright 2004-present Facebook. All rights reserved. - -from argparse import ArgumentParser -from at93c46 import AT93C46, AT93C46SPI -import sys - -def get_raw(args): - return AT93C46SPI(args.bus_width, args.cs, args.clk, args.mosi, args.miso, - args.verbose) - -def get_chip(args): - return AT93C46(args.bus_width, args.cs, args.clk, args.mosi, args.miso, - args.byte_swap, args.verbose) - -def access_parser(ap): - # Default, based on currenct HW configuration - SPI_CS_DEFAULT = 68 - SPI_CLK_DEFAULT = 69 - SPI_MOSI_DEFAULT = 70 - SPI_MISO_DEFAULT = 71 - - spi_group = ap.add_argument_group('SPI Access') - spi_group.add_argument('--cs', type=int, default=SPI_CS_DEFAULT, - help='The GPIO number for SPI CS pin (default: %s)' - % SPI_CS_DEFAULT) - spi_group.add_argument('--clk', type=int, default=SPI_CLK_DEFAULT, - help='The GPIO number for SPI CLK pin (default: %s)' - % SPI_CLK_DEFAULT) - spi_group.add_argument('--mosi', type=int, default=SPI_MOSI_DEFAULT, - help='The GPIO number for SPI MOSI pin (default: %s)' - % SPI_MOSI_DEFAULT) - spi_group.add_argument('--miso', type=int, default=SPI_MISO_DEFAULT, - help='The GPIO number for SPI MISO pin (default: %s)' - % SPI_MISO_DEFAULT) - -def bus_width_parser(ap): - # Default, based on currenct HW configuration - AT83C46_BUS_WIDTH = 16 - - bus_group = ap.add_argument_group('Bus Width') - bus_group.add_argument('--bus-width', type=int, default=AT83C46_BUS_WIDTH, - help='The configured bus width (default: %s)' - % AT83C46_BUS_WIDTH) - -def read_raw(args): - raw = get_raw(args) - val = raw.read(args.address) - - if args.int: - print "{}".format(val) - else: - if args.bus_width == 16: - print "0x{:04X}".format(val) - else: - print "0x{:02X}".format(val) - -def write_raw(args): - if args.value[:2] == "0x": - value = int(args.value, 16) - else: - value = int(args.value) - - raw = get_raw(args) - raw.ewen() - raw.erase(args.address) - raw.write(args.address, value) - raw.ewds() - -def erase_raw(args): - raw = get_raw(args) - raw.ewen() - raw.erase(args.address) - raw.ewds() - -def raw_subparser(subparsers): - raw_parser = subparsers.add_parser('raw', help='Raw memory access') - raw_sub = raw_parser.add_subparsers() - - read_parser = raw_sub.add_parser('read', help='Read a single memory address') - read_parser.add_argument('address', type=int, help='The memory address') - read_parser.add_argument('--int', action='store_true', - help='Display output as an integer') - read_parser.set_defaults(func=read_raw) - - write_parser = raw_sub.add_parser('write', help='Write a single memory address') - write_parser.add_argument('address', type=int, help='The memory address') - write_parser.add_argument('value', type=str, help='The value to write, either integer or hex') - write_parser.set_defaults(func=write_raw) - - erase_parser = raw_sub.add_parser('erase', help='Erase a single memory address') - erase_parser.add_argument('address', type=int, help='The memory address') - erase_parser.set_defaults(func=erase_raw) - -def read_chip(args): - chip = get_chip(args) - data = chip.read(args.start, args.length) - - if args.file is None: - sys.stdout.write(data) - else: - fp = open(args.file, "wb") - fp.write(data) - -def write_chip(args): - chip = get_chip(args) - - # Either way, limit reads to the size of the chip - if args.file is None: - data = sys.stdin.read(AT93C46.AT93C46_MEMORY_SIZE) - else: - fp = open(args.file, "rb") - data = fp.read(AT93C46.AT93C46_MEMORY_SIZE) - - if args.length is not None: - # Make sure length is correct - if len(data) < args.length: - data = data + '\x00' * (args.length - len(data)) - if len(data) > args.length: - data = data[:args.length] - - chip.write(data, args.start) - -def erase_chip(args): - chip = get_chip(args) - chip.erase(args.start, args.length) - -def chip_subparser(subparsers): - chip_parser = subparsers.add_parser('chip', help='Chip-level access') - chip_sub = chip_parser.add_subparsers() - - read_parser = chip_sub.add_parser('read', help='Read from the chip') - read_parser.add_argument('--start', type=int, - help='The memory address to start at (default: 0)') - read_parser.add_argument('--length', type=int, - help='The number of bytes to read (default: whole chip)') - read_parser.add_argument('--file', type=str, - help='File to operate on (default: stdout)') - read_parser.add_argument('--byte-swap', action='store_true', - help='Byte swap values for 16-bit reads/writes') - read_parser.set_defaults(func=read_chip) - - write_parser = chip_sub.add_parser('write', help='Write to the chip') - write_parser.add_argument('--start', type=int, - help='The memory address to start at (default: 0)') - write_parser.add_argument('--length', type=int, - help='The number of bytes to write (default: file length)') - write_parser.add_argument('--file', type=str, - help='File to operate on (default: stdin)') - write_parser.add_argument('--byte-swap', action='store_true', - help='Byte swap values for 16-bit reads/writes') - write_parser.set_defaults(func=write_chip) - - erase_parser = chip_sub.add_parser('erase', help='Erase the chip') - erase_parser.add_argument('--start', type=int, - help='The memory address to start at (default: 0)') - erase_parser.add_argument('--length', type=int, - help='The number of bytes to erase (default: whole chip)') - erase_parser.set_defaults(func=erase_chip) - -if __name__ == "__main__": - # General arguments - ap = ArgumentParser() - ap.add_argument('--verbose', action='store_true', - help='Print verbose debugging information') - - # SPI and bus width arguments - access_parser(ap) - bus_width_parser(ap) - - # Functionality - subparsers = ap.add_subparsers() - raw_subparser(subparsers) - chip_subparser(subparsers) - - # Command runner - args = ap.parse_args() - args.func(args) diff --git a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/fcswitcher.sh b/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/fcswitcher.sh deleted file mode 100755 index 53e24f3..0000000 --- a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/fcswitcher.sh +++ /dev/null @@ -1,83 +0,0 @@ -#! /bin/sh -# -# Copyright 2014-present Facebook. All Rights Reserved. -# -# This program file is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program in a file named COPYING; if not, write to the -# Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, -# Boston, MA 02110-1301 USA -# - -### BEGIN INIT INFO -# Provides: usbcons -# Required-Start: -# Required-Stop: -# Default-Start: S -# Default-Stop: 0 6 -# Short-Description: Creates a virtual USB serial device and starts a console -# on it. -# -### END INIT INFO - -PATH=/sbin:/bin:/usr/sbin:/usr/bin -NAME="FC Switcher" -DESC="FC Failover Daemon" - -# source function library -. /etc/init.d/functions - -. /usr/local/fbpackages/utils/ast-functions - -STOPPER= -ACTION="$1" - -case "$ACTION" in - start) - if [ "$(wedge_board_type)" = "LC" ]; then - # Ability to prevent this from starting by editing cmdline in u-boot. - # Keeping this here until I get gadget switching working properly. (t4906522) - /usr/local/bin/watch-fc.sh > /dev/null 2>&1 & - echo "$NAME." - else - echo 'skipping watch-fc.sh: only necessary on six-pack line cards.' - fi - ;; - stop) - echo -n "Stopping $DESC: " - killall watch-fc.sh - echo "$NAME." - ;; - restart|force-reload) - echo -n "Restarting $DESC: " - killall watch-fc.sh - if [ "$(wedge_board_type)" = "LC" ]; then - sleep 1 - /usr/local/bin/watch-fc.sh > /dev/null 2>&1 & - echo "$NAME." - else - echo 'skipping watch-fc.sh: only necessary on six-pack line cards.' - fi - ;; - status) - status watch-fc.sh - exit $? - ;; - *) - N=${0##*/} - N=${N#[SK]??} - echo "Usage: $N {start|stop|status|restart|force-reload}" >&2 - exit 1 - ;; -esac - -exit 0 diff --git a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/setup_rov.sh b/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/setup_rov.sh index 1400464..4ff6f24 100755 --- a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/setup_rov.sh +++ b/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/setup_rov.sh @@ -56,12 +56,19 @@ target_volts=$(( $target_volts * 1 )) # normalize to decimal rmmod pmbus reload=$? -# Get current voltage value +# Get current voltage value. +# The device here is NCP4200. It turns out the first i2c transaction to this +# device always fails. The spec does not mention anything about NCP4200 i2c +# engine start delay. However, each time, when the isolation buffer between the +# BMC i2c controller and NCP4200 is disabled and re-enabled, the first i2c +# transaction to NCP4200 always fails. +# To workaround this issue, we are doing the first read twice. +cur_volts=$(i2cget -y 1 0x60 0x8b w 2> /dev/null) cur_volts=$(i2cget -y 1 0x60 0x8b w) cur_volts=$(( $cur_volts * 1 )) # normalize to decimal # Only bounce the T2 if we actually need to modify the voltage -if [ $cur_volts -ne $target_volts ]; then +if [ $cur_volts -ne $target_volts ]; then # Set values before turning out output; we're using "PCIE, then MCS" echo 1 > /sys/class/gpio/gpio42/value echo 1 > /sys/class/gpio/gpio43/value @@ -71,7 +78,7 @@ if [ $cur_volts -ne $target_volts ]; then echo out > /sys/class/gpio/gpio16/direction # T2 is in reset; note that this may cause NMI messages on the uServer, # which shouldn't be up anyway when this is first run. - + # Set the requested value to the current value to avoid rapid shifts i2cset -y 1 0x60 0x21 $cur_volts w # Enable the requested voltage @@ -81,7 +88,7 @@ if [ $cur_volts -ne $target_volts ]; then # Set the target voltage i2cset -y 1 0x60 0x21 $target_volts w - + sleep 1 # Let T2 come out of reset diff --git a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/src/include/log.h b/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/src/include/log.h deleted file mode 100644 index a69d69e..0000000 --- a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/src/include/log.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2014-present Facebook. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#ifndef LOG_H -#define LOG_H - -#include <stdio.h> -#include <string.h> - -//#define DEBUG -//#define VERBOSE - -#define _LOG(dst, fmt, ...) do { \ - fprintf(dst, "%s:%d " fmt "\n", \ - __FUNCTION__, __LINE__, ##__VA_ARGS__); \ - fflush(dst); \ -} while(0) - -#define LOG_ERR(err, fmt, ...) do { \ - char buf[128]; \ - strerror_r(err, buf, sizeof(buf)); \ - _LOG(stderr, "ERROR " fmt ": %s", ##__VA_ARGS__, buf); \ -} while(0) - -#define LOG_INFO(fmt, ...) do { \ - _LOG(stdout, fmt, ##__VA_ARGS__); \ -} while(0) - -#ifdef DEBUG -#define LOG_DBG(fmt, ...) do { \ - _LOG(stdout, fmt, ##__VA_ARGS__); \ -} while(0) -#else -#define LOG_DBG(fmt, ...) -#endif - -#ifdef VERBOSE -#define LOG_VER(fmt, ...) do { \ - _LOG(stdout, fmt, ##__VA_ARGS__); \ -} while(0) -#else -#define LOG_VER(fmt, ...) -#endif - -#endif diff --git a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/watch-fc.sh b/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/watch-fc.sh deleted file mode 100755 index d04b7cd..0000000 --- a/meta-facebook/meta-wedge/recipes-wedge/fbutils/files/watch-fc.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -# -# Copyright 2014-present Facebook. All Rights Reserved. -# -# This program file is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program in a file named COPYING; if not, write to the -# Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, -# Boston, MA 02110-1301 USA -# - -. /usr/local/fbpackages/utils/ast-functions - -MAC1LINK=0 # GPIOA0 -FAB0_PRES=20 # GPIOC4 -FAB1_PRES=21 # GPIOC5 -while true; do - # fabN_pres: active low. - if [ $(gpio_get $FAB0_PRES) = 0 ]; then - gpio_set $MAC1LINK 0 - elif [ $(gpio_get $FAB1_PRES) = 0 ]; then - gpio_set $MAC1LINK 1 - fi - sleep 1 -done |