Skip to content

Commit

Permalink
[as4630-54te] Add to support AP2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ec-michael-shih committed Feb 19, 2021
1 parent 638a205 commit cdc1291
Show file tree
Hide file tree
Showing 18 changed files with 2,362 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

try:
import exceptions
import binascii
import time
import optparse
Expand Down
11 changes: 7 additions & 4 deletions device/accton/x86_64-accton_as4630_54te-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_presence(self, port_num):
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print ('Error: unable to access file: %s') % str(e)
return False

if content == "1":
Expand Down Expand Up @@ -109,7 +109,7 @@ def get_low_power_mode(self, port_num):
return False

except IOError as e:
print "Error: unable to open file: %s" % str(e)
print ('Error: unable to open file: %s') % str(e)
return False
finally:
if eeprom is not None:
Expand All @@ -131,15 +131,18 @@ def set_low_power_mode(self, port_num, lpmode):
regval = 0x3 if lpmode else 0x1

buffer = create_string_buffer(1)
buffer[0] = chr(regval)
if sys.version_info[0] >= 3:
buffer[0] = regval
else:
buffer[0] = chr(regval)

# Write to eeprom
eeprom = open(self.port_to_eeprom_mapping[port_num], "r+b")
eeprom.seek(93)
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print ('Error: unable to open file: %s') % str(e)
return False
finally:
if eeprom is not None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__all__ = ['chassis', 'eeprom', 'platform', 'psu', 'sfp', 'thermal', 'fan']
from . import platform
194 changes: 194 additions & 0 deletions device/accton/x86_64-accton_as4630_54te-r0/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
#############################################################################
# Edgecore
#
# Module contains an implementation of SONiC Platform Base API and
# provides the Chassis information which are available in the platform
#
#############################################################################

import os

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

NUM_FAN_TRAY = 3
NUM_FAN = 2
NUM_PSU = 2
NUM_THERMAL = 3
NUM_QSFP = 6
PORT_START = 49
PORT_END = 54
NUM_COMPONENT = 2
HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/"
PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/"
REBOOT_CAUSE_FILE = "reboot-cause.txt"
PREV_REBOOT_CAUSE_FILE = "previous-reboot-cause.txt"
HOST_CHK_CMD = "docker > /dev/null 2>&1"


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

def __init__(self):
ChassisBase.__init__(self)
self._api_helper = APIHelper()
self._api_helper = APIHelper()
self.is_host = self._api_helper.is_host()

self.config_data = {}

self.__initialize_fan()
self.__initialize_psu()
self.__initialize_thermals()
self.__initialize_components()
self.__initialize_sfp()
self.__initialize_eeprom()

def __initialize_sfp(self):
from sonic_platform.sfp import Sfp
for index in range(0, PORT_END):
sfp = Sfp(index)
self._sfp_list.append(sfp)
self.sfp_module_initialized = True

def __initialize_fan(self):
from sonic_platform.fan import Fan
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)

def __initialize_psu(self):
from sonic_platform.psu import Psu
for index in range(0, NUM_PSU):
psu = Psu(index)
self._psu_list.append(psu)

def __initialize_thermals(self):
from sonic_platform.thermal import Thermal
for index in range(0, NUM_THERMAL):
thermal = Thermal(index)
self._thermal_list.append(thermal)

def __initialize_eeprom(self):
from sonic_platform.eeprom import Tlv
self._eeprom = Tlv()

def __initialize_components(self):
from sonic_platform.component import Component
for index in range(0, NUM_COMPONENT):
component = Component(index)
self._component_list.append(component)

def __initialize_watchdog(self):
from sonic_platform.watchdog import Watchdog
self._watchdog = Watchdog()


def __is_host(self):
return os.system(HOST_CHK_CMD) == 0

def __read_txt_file(self, file_path):
try:
with open(file_path, 'r') as fd:
data = fd.read()
return data.strip()
except IOError:
pass
return None

def get_name(self):
"""
Retrieves the name of the device
Returns:
string: The name of the device
"""

return self._api_helper.hwsku

def get_presence(self):
"""
Retrieves the presence of the Chassis
Returns:
bool: True if Chassis is present, False if not
"""
return True

def get_status(self):
"""
Retrieves the operational status of the device
Returns:
A boolean value, True if device is operating properly, False if not
"""
return True

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.
"""

reboot_cause_path = (HOST_REBOOT_CAUSE_PATH + REBOOT_CAUSE_FILE)
sw_reboot_cause = self._api_helper.read_txt_file(
reboot_cause_path) or "Unknown"


return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause)

def get_sfp(self, index):
"""
Retrieves sfp represented by (1-based) index <index>
Args:
index: An integer, the index (1-based) of the sfp to retrieve.
The index should be the sequence of a physical port in a chassis,
starting from 1.
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
Returns:
An object dervied from SfpBase representing the specified sfp
"""
sfp = None
if not self.sfp_module_initialized:
self.__initialize_sfp()

try:
# The index will start from 1
sfp = self._sfp_list[index-1]
except IndexError:
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list)))
return sfp
121 changes: 121 additions & 0 deletions device/accton/x86_64-accton_as4630_54te-r0/sonic_platform/component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#############################################################################
# Celestica
#
# Component contains an implementation of SONiC Platform Base API and
# provides the components firmware management function
#
#############################################################################

import shlex
import subprocess


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")

CPLD_ADDR_MAPPING = {
"CPLD1": "3-0060"
}
SYSFS_PATH = "/sys/bus/i2c/devices/"
BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version"
COMPONENT_LIST= [
("CPLD1", "CPLD 1"),
("BIOS", "Basic Input/Output System")

]

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

DEVICE_TYPE = "component"

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

def __run_command(self, command):
# Run bash command and print output to stdout
try:
process = subprocess.Popen(
shlex.split(command), stdout=subprocess.PIPE)
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
rc = process.poll()
if rc != 0:
return False
except Exception:
return False
return True

def __get_bios_version(self):
# Retrieves the BIOS firmware version
try:
with open(BIOS_VERSION_PATH, 'r') as fd:
bios_version = fd.read()
return bios_version.strip()
except Exception as e:
return None

def __get_cpld_version(self):
# Retrieves the CPLD firmware version
cpld_version = dict()
for cpld_name in CPLD_ADDR_MAPPING:
try:
cpld_path = "{}{}{}".format(SYSFS_PATH, CPLD_ADDR_MAPPING[cpld_name], '/version')
cpld_version_raw= self._api_helper.read_txt_file(cpld_path)
cpld_version[cpld_name] = "{}".format(int(cpld_version_raw,16))
except Exception as e:
print('Get exception when read cpld')
cpld_version[cpld_name] = 'None'

return cpld_version

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 = None

if self.name == "BIOS":
fw_version = self.__get_bios_version()
elif "CPLD" in self.name:
cpld_version = self.__get_cpld_version()
fw_version = cpld_version.get(self.name)

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
"""
raise NotImplementedError
Loading

0 comments on commit cdc1291

Please sign in to comment.