Skip to content

Commit

Permalink
add for sivlerstone platform
Browse files Browse the repository at this point in the history
  • Loading branch information
bbinxie authored and tiantianlv committed May 7, 2020
1 parent da17822 commit ad7ca02
Show file tree
Hide file tree
Showing 27 changed files with 5,728 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

### BEGIN INIT INFO
# Provides: setup-board
# Required-Start: $portmap
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: S
# Default-Stop: 0 6
# Short-Description: Setup SilverStone board.
### END INIT INFO


case "$1" in
start)
echo -n "Setting up board... "

modprobe i2c-dev
modprobe baseboard-lpc
modprobe switchboard
modprobe mc24lc64t
modprobe ipmi_devintf

# Instantiate TLV EEPROM device on I801 bus
devname=`cat /sys/bus/i2c/devices/i2c-0/name`
if [[ $devname == 'SMBus I801 adapter at '* ]]; then
echo 24lc64t 0x56 > /sys/bus/i2c/devices/i2c-0/new_device
fi
decode-syseeprom --init 2> /dev/null &

# /bin/sh /usr/local/bin/platform_api_mgnt.sh init

echo "done."
;;

stop)
echo "done."
;;

force-reload|restart)
echo "Not supported"
;;

*)
echo "Usage: /etc/init.d/platform-modules-silverstone.init {start|stop}"
exit 1
;;
esac

exit 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
silverstone/scripts/sensors usr/bin
silverstone/scripts/platform_sensors.py usr/local/bin
silverstone/cfg/silverstone-modules.conf etc/modules-load.d
silverstone/systemd/platform-modules-silverstone.service lib/systemd/system
#silverstone/modules/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-cel_silverstone-r0
#services/platform_api/platform_api_mgnt.sh usr/local/bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
depmod -a
systemctl enable platform-modules-silverstone.service
systemctl start platform-modules-silverstone.service

#/usr/local/bin/platform_api_mgnt.sh install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__all__ = ["platform", "chassis"]
from sonic_platform import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/env python

#############################################################################
# Celestica
#
# Module contains an implementation of SONiC Platform Base API and
# provides the Chassis information which are available in the platform
#
#############################################################################

import sys
import re
import os
import subprocess
import json

try:
from sonic_platform_base.chassis_base import ChassisBase
from sonic_platform.component import Component
from sonic_platform.eeprom import Tlv
from sonic_platform.fan import Fan
from sonic_platform.sfp import Sfp
from sonic_platform.psu import Psu
from sonic_platform.thermal import Thermal
from helper import APIHelper
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

NUM_FAN_TRAY = 7
NUM_FAN = 2
NUM_PSU = 2
NUM_THERMAL = 10
NUM_SFP = 32
NUM_COMPONENT = 5

IPMI_OEM_NETFN = "0x3A"
IPMI_GET_REBOOT_CAUSE = "0x03 0x00 0x01 0x06"


class Chassis(ChassisBase):
"""Platform-specific Chassis class"""

def __init__(self):
self.config_data = {}
ChassisBase.__init__(self)
self._eeprom = Tlv()
self._api_helper = APIHelper()

for fant_index in range(0, NUM_FAN_TRAY):
for fan_index in range(0, NUM_FAN):
fan = Fan(fant_index, fan_index)
self._fan_list.append(fan)

for index in range(0, NUM_SFP):
sfp = Sfp(index)
self._sfp_list.append(sfp)

for index in range(0, NUM_PSU):
psu = Psu(index)
self._psu_list.append(psu)
for index in range(0, NUM_COMPONENT):
component = Component(index)
self._component_list.append(component)
for index in range(0, NUM_THERMAL):
thermal = Thermal(index)
self._thermal_list.append(thermal)


def get_base_mac(self):
"""
Retrieves the base MAC address for the chassis
Returns:
A string containing the MAC address in the format
'XX:XX:XX:XX:XX:XX'
"""
return self._eeprom.get_mac()

def get_serial_number(self):
"""
Retrieves the hardware serial number for the chassis
Returns:
A string containing the hardware serial number for this chassis.
"""
return self._eeprom.get_serial()

def get_system_eeprom_info(self):
"""
Retrieves the full content of system EEPROM information for the chassis
Returns:
A dictionary where keys are the type code defined in
OCP ONIE TlvInfo EEPROM format and values are their corresponding
values.
"""
return self._eeprom.get_eeprom()

def get_reboot_cause(self):
"""
Retrieves the cause of the previous reboot
Returns:
A tuple (string, string) where the first element is a string
containing the cause of the previous reboot. This string must be
one of the predefined strings in this class. If the first string
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
to pass a description of the reboot cause.
"""

status, raw_cause = self._api_helper.ipmi_raw(
IPMI_OEM_NETFN, IPMI_GET_REBOOT_CAUSE)
hx_cause = raw_cause.split()[0] if status and len(
raw_cause.split()) > 0 else 00
reboot_cause = {
"00": self.REBOOT_CAUSE_HARDWARE_OTHER,
"11": self.REBOOT_CAUSE_POWER_LOSS,
"22": self.REBOOT_CAUSE_NON_HARDWARE,
"33": self.REBOOT_CAUSE_HARDWARE_OTHER,
"44": self.REBOOT_CAUSE_NON_HARDWARE,
"55": self.REBOOT_CAUSE_NON_HARDWARE,
"66": self.REBOOT_CAUSE_WATCHDOG,
"77": self.REBOOT_CAUSE_NON_HARDWARE
}.get(hx_cause, self.REBOOT_CAUSE_HARDWARE_OTHER)

description = {
"00": "Unknown reason",
"11": "The last reset is Power on reset",
"22": "The last reset is soft-set CPU warm reset",
"33": "The last reset is soft-set CPU cold reset",
"44": "The last reset is CPU warm reset",
"55": "The last reset is CPU cold reset",
"66": "The last reset is watchdog reset",
"77": "The last reset is power cycle reset"
}.get(hx_cause, "Unknown reason")

return (reboot_cause, description)
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env python

#############################################################################
# Celestica
#
# Component contains an implementation of SONiC Platform Base API and
# provides the components firmware management function
#
#############################################################################

import json
import os.path

try:
from sonic_platform_base.component_base import ComponentBase
from helper import APIHelper
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

COMPONENT_LIST = [
("BIOS", "Basic Input/Output System"),
("BMC", "Baseboard Management Controller"),
("SWITCH_CPLD", "Switch board CPLD"),
("BASE_CPLD", "Base board CPLD"),
("FPGA", "Field-programmable gate array")
]
SW_CPLD_VER_PATH = "/sys/module/switch_cpld/version"
BASE_CPLD_VER_PATH = "/sys/module/baseboard_lpc/version"
CPLD_UPGRADE_OPT = 4
BIOS_VER_PATH = "/sys/class/dmi/id/bios_version"
BIOS__UPGRADE_OPT = 2
BMC_VER_CMD = "ipmitool mc info | grep 'Firmware Revision'"
BMC_UPGRADE_OPT = 1
CFUFLASH_FW_UPGRADE_CMD = "CFUFLASH -cd -d {} -mse 3 {}"
MEM_PCI_RESOURCE = "/sys/bus/pci/devices/0000:09:00.0/resource0"
FPGA_VER_MEM_OFFSET = 0


class Component(ComponentBase):
"""Platform-specific Component class"""

DEVICE_TYPE = "component"

def __init__(self, component_index):
ComponentBase.__init__(self)
self.index = component_index
self.name = self.get_name()
self._api_helper = APIHelper()

def __get_bmc_ver(self):
bmc_ver = "Unknown"
status, raw_bmc_data = self._api_helper.run_command(BMC_VER_CMD)
if status:
bmc_ver_data = raw_bmc_data.split(":")
bmc_ver = bmc_ver_data[-1].strip() if len(
bmc_ver_data) > 1 else bmc_ver
return bmc_ver

def __get_fpga_ver(self):
fpga_ver = "Unknown"
status, reg_val = self._api_helper.pci_get_value(
MEM_PCI_RESOURCE, FPGA_VER_MEM_OFFSET)
if status:
major = reg_val[0] >> 16
minor = int(bin(reg_val[0])[16:32], 2)
fpga_ver = '{}.{}'.format(major, minor)
return fpga_ver

def get_name(self):
"""
Retrieves the name of the component
Returns:
A string containing the name of the component
"""
return COMPONENT_LIST[self.index][0]

def get_description(self):
"""
Retrieves the description of the component
Returns:
A string containing the description of the component
"""
return COMPONENT_LIST[self.index][1]

def get_firmware_version(self):
"""
Retrieves the firmware version of module
Returns:
string: The firmware versions of the module
"""
fw_version = {
"BIOS": self._api_helper.read_txt_file(BIOS_VER_PATH),
"BMC": self.__get_bmc_ver(),
"FPGA": self.__get_fpga_ver(),
"SWITCH_CPLD": self._api_helper.read_txt_file(SW_CPLD_VER_PATH),
"BASE_CPLD": self._api_helper.read_txt_file(BASE_CPLD_VER_PATH),
}.get(self.name, "Unknown")

return fw_version

def install_firmware(self, image_path):
"""
Install firmware to module
Args:
image_path: A string, path to firmware image
Returns:
A boolean, True if install successfully, False if not
"""
install_command = {
"BMC": CFUFLASH_FW_UPGRADE_CMD.format(BMC_UPGRADE_OPT, image_path),
"BIOS": CFUFLASH_FW_UPGRADE_CMD.format(BIOS__UPGRADE_OPT, image_path),
"SWITCH_CPLD": CFUFLASH_FW_UPGRADE_CMD.format(CPLD_UPGRADE_OPT, image_path),
"BASE_CPLD": CFUFLASH_FW_UPGRADE_CMD.format(CPLD_UPGRADE_OPT, image_path)
}.get(self.name, None)

if not os.path.isfile(image_path) or install_command is None:
return False

# print(install_command)
status = self._api_helper.run_interactive_command(install_command)
return status
Loading

0 comments on commit ad7ca02

Please sign in to comment.