From 337f584e1430aa1bff9b723290c36ab5846f154a Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Mon, 11 Feb 2019 15:23:52 +0700 Subject: [PATCH 1/2] [platform/cel] - add fppga upgrade tool --- .../sonic-platform-modules-cel/debian/rules | 4 + .../tools/fpga_prog/fpga_prog.c | 282 ++++++++++++++++++ 2 files changed, 286 insertions(+) create mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/fpga_prog/fpga_prog.c diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/rules b/platform/broadcom/sonic-platform-modules-cel/debian/rules index ee85ade4415f..062974c45a89 100755 --- a/platform/broadcom/sonic-platform-modules-cel/debian/rules +++ b/platform/broadcom/sonic-platform-modules-cel/debian/rules @@ -15,6 +15,7 @@ override_dh_auto_build: make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules; \ done) make -C $(MOD_SRC_DIR)/tools/ispvme_12.2; + gcc $(MOD_SRC_DIR)/tools/fpga_prog/fpga_prog.c -o $(MOD_SRC_DIR)/tools/fpga_prog/fpga_prog; override_dh_auto_install: (for mod in $(MODULE_DIRS); do \ @@ -26,6 +27,9 @@ override_dh_auto_install: debian/platform-modules-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ cp $(MOD_SRC_DIR)/tools/ispvme_12.2/ispvm \ debian/platform-modules-$${mod}/usr/local/bin/; \ + ls $(MOD_SRC_DIR)/tools/fpga_prog; \ + cp $(MOD_SRC_DIR)/tools/fpga_prog/fpga_prog \ + debian/platform-modules-$${mod}/usr/local/bin/; \ done) override_dh_usrlocal: diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/fpga_prog/fpga_prog.c b/platform/broadcom/sonic-platform-modules-cel/tools/fpga_prog/fpga_prog.c new file mode 100644 index 000000000000..c640c8ad0064 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-cel/tools/fpga_prog/fpga_prog.c @@ -0,0 +1,282 @@ +/******************************************************************** +Author: Sittisak Sinprem + flash_spi_fpga + + user-space appliction to flash SPI FLASH + + As a "root" previledge, this program can run well + while other user group would report system errors under Linux OS. + +*********************************************************************/ + +#include +#include +#include +#include //for open() +#include //for close() +#include +#include + +/** + * The FPGA SPI Flash update application + * This application read the binary image file and program + * into flash memory. The erasing time can be long the + * the WAIT_WRITE_READY_SEC should be more than 30 seconds. + */ + +#define WAIT_WRITE_READY_SEC 180 +#define WAIT_WRITE_CONTINUE_CYCLE 100000 + +#define REG_SPI_WR_EN 0x1200 +#define REG_SPI_WR_DAT 0x1204 +#define REG_SPI_CHK_ID 0x1208 +#define REG_SPI_VERIFY 0x120C +#define REG_SPI_STAT 0x1210 +#define REG_SPI_RESET 0x1214 + +#define SPI_STAT_MARK_READY (1 << 15) +#define SPI_STAT_MARK_DONE (1 << 14) +#define SPI_STAT_MARK_ERROR_ANY (1 << 13) +#define SPI_STAT_MARK_ERROR_CHKID (1 << 12) +#define SPI_STAT_MARK_ERROR_ERASE (1 << 11) +#define SPI_STAT_MARK_ERROR_PROG (1 << 10) +#define SPI_STAT_MARK_ERROR_TOUT (1 << 9) +#define SPI_STAT_MARK_ERROR_CRC (1 << 8) +#define SPI_STAT_MARK_STG_STARTED (1 << 7) +#define SPI_STAT_MARK_STG_INITED (1 << 6) +#define SPI_STAT_MARK_STG_CHECKED_ID (1 << 5) +#define SPI_STAT_MARK_STG_ERSD_SW (1 << 4) +#define SPI_STAT_MARK_STG_UP_ERSD_IMG (1 << 3) +#define SPI_STAT_MARK_STG_UP_PRG_IMG (1 << 2) +#define SPI_STAT_MARK_STG_VERIFIED (1 << 1) +#define SPI_STAT_MARK_STG_PRG_CMPT (1 << 0) + +#define debug(fmt,args...) printf("debug : "fmt"\n",##args) +#define reg_write(reg,value) func_write(reg,value) +#define reg_read(reg,value) value = func_read(reg) + +#define DEV_CHAR_FILENAME "/dev/fwupgrade" + +struct fpga_reg_data { + uint32_t reg; + uint32_t value; +}; + +enum{ + READREG, + WRITEREG +}; + +unsigned int func_write(int addr,unsigned long value){ + int fd; + int ret; + struct fpga_reg_data fpga_reg; + + fd = open(DEV_CHAR_FILENAME, O_RDWR); + + fpga_reg.reg = addr; + fpga_reg.value = value; + + ioctl(fd, WRITEREG, (void *)&fpga_reg); + + close(fd); + return 0; +} + +unsigned int func_read(int addr){ + int fd; + int ret; + + struct fpga_reg_data fpga_reg; + + fd = open(DEV_CHAR_FILENAME, O_RDWR); + + fpga_reg.reg = addr; + + ioctl(fd, READREG, (void *)&fpga_reg); + + close(fd); + return fpga_reg.value; +} + +void dump_status(int Stat){ + debug("#########################"); + debug("%d ready(1)/busy(0)", (Stat&SPI_STAT_MARK_READY)!=0); + debug("%d done", (Stat&SPI_STAT_MARK_DONE)!=0); + debug("%d error any", (Stat&SPI_STAT_MARK_ERROR_ANY)!=0); + debug("%d error checkId", (Stat&SPI_STAT_MARK_ERROR_CHKID)!=0); + debug("%d error erase", (Stat&SPI_STAT_MARK_ERROR_ERASE)!=0); + debug("%d error program", (Stat&SPI_STAT_MARK_ERROR_PROG)!=0); + debug("%d error timeout", (Stat&SPI_STAT_MARK_ERROR_TOUT)!=0); + debug("%d error crc", (Stat&SPI_STAT_MARK_ERROR_CRC)!=0); + debug("%d stage started", (Stat&SPI_STAT_MARK_STG_STARTED)!=0); + debug("%d stage inited", (Stat&SPI_STAT_MARK_STG_INITED)!=0); + debug("%d stage checked id", (Stat&SPI_STAT_MARK_STG_CHECKED_ID)!=0); + debug("%d stage erasred", (Stat&SPI_STAT_MARK_STG_ERSD_SW)!=0); + debug("%d stage upload erase img", (Stat&SPI_STAT_MARK_STG_UP_ERSD_IMG)!=0); + debug("%d stage upload program img",(Stat&SPI_STAT_MARK_STG_UP_PRG_IMG)!=0); + debug("%d stage verified", (Stat&SPI_STAT_MARK_STG_VERIFIED)!=0); + debug("%d stage completed", (Stat&SPI_STAT_MARK_STG_PRG_CMPT)!=0); +} + +int flash_program(char *data,int lens){ + int ctimeout; + int error =0; + unsigned long Stat = 0; + + reg_read(REG_SPI_RESET,Stat); + printf("Read Reset is %x\n",Stat); + printf("Reset Module \n"); + reg_write(REG_SPI_RESET,0x1); // reset + sleep(1); + reg_write(REG_SPI_RESET,0x0); // normal mode + ctimeout=0; + do{ // wait for done flag + reg_read(REG_SPI_STAT,Stat); + if(Stat & SPI_STAT_MARK_ERROR_ANY){ + dump_status(Stat); + error = Stat; + break; + } + if(ctimeout++ > WAIT_WRITE_READY_SEC){ + error = Stat| SPI_STAT_MARK_ERROR_TOUT; + debug("wait ready timeout . . ."); + break; + } + printf(" waiting status to ready ... %d s. status = %x\n",ctimeout,Stat); + sleep(1); + }while((Stat & 0x80F8) != 0x80F8); + if(error){ + return -1; + } + printf("Ready\n"); + + + for(int i=0;i WAIT_WRITE_CONTINUE_CYCLE){ + error = Stat| SPI_STAT_MARK_ERROR_TOUT; + debug("wait ready timeout . . ."); + break; + } + }while((Stat & 0x80F8) != 0x80F8); + + if(error){ + printf("FPGA programing fail at %d/%d\n",i,lens); + debug("Status = %4.4X",error); + break; + } + + i +=4; + + if(i%(lens/40*4)==0){ + printf("FPGA programing . . . %d/%d\n",i,lens); + } + } + + dump_status(Stat); + printf("Status = %4.4X\n",Stat); + + reg_write(REG_SPI_WR_EN,0x0); // write protect + reg_write(REG_SPI_RESET,0x1); // module reset + + return error; +} + +int main(int argc,char **argv){ + FILE *pFILE; + int filesize; + char *filename; + char *fpga_buff; + int status; + int max_size = 128; + int current_size = max_size; + int i = 0; + int c = EOF; + + printf(" FPGA PROGRAMMNG version 0.1.1 \n"); + printf(" build date : %s %s\n",__DATE__,__TIME__); + + filename = NULL; + filename = malloc(max_size); + if(!filename){ + exit(-12); /* Out of memory */ + } + + if(argc<2){ + printf("please enter filename : "); + while((c = getchar()) != '\n' && c != EOF ){ + + filename[i++] = (char)c; + if(i == current_size){ + current_size += max_size; + filename = realloc(filename, current_size); + } + } + filename[i] = '\0'; + }else{ + i = strlen(argv[1]) + 1; + filename = realloc(filename, i); + strcpy(filename, argv[1]); + } + + pFILE = fopen(filename,"rb"); + free(filename); + if (pFILE == NULL) + { + printf("Could not open the file %s, exit\n",filename); + return -5; + } + + fseek(pFILE , 0 , SEEK_END); + filesize = ftell (pFILE); + rewind(pFILE); + fpga_buff = malloc(filesize); + if(fpga_buff==NULL){ + printf("Can't Allocate memory \n"); + return -5; + } + + fread(fpga_buff,1,filesize,pFILE); + fclose(pFILE); + + printf(" Start FPGA Flash ... \n"); + + status = flash_program(fpga_buff,filesize); + + if(status == 0){ + printf(" Programing finish \n"); + }else{ + printf(" Program Error : error code %4.4x \n",status); + } + + return status; +} From 785cd08e997fe431aa742a3997762a08bc1def8d Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Mon, 11 Feb 2019 15:26:31 +0700 Subject: [PATCH 2/2] [device/alibaba] - Update device plugins to latest version --- .../plugins/fanutil.py | 40 +++-- .../plugins/fwmgrutil.py | 148 ++++++++++++++---- .../plugins/psuutil.py | 20 ++- .../plugins/sensorutil.py | 24 +++ .../plugins/fanutil.py | 40 +++-- .../plugins/fwmgrutil.py | 146 +++++++++++++---- .../plugins/psuutil.py | 20 ++- .../plugins/sensorutil.py | 24 +++ .../plugins/fanutil.py | 44 ++++-- .../plugins/fwmgrutil.py | 148 ++++++++++++++---- .../plugins/psuutil.py | 20 ++- .../plugins/sensorutil.py | 24 +++ .../tools/platformutil.py | 40 ++++- 13 files changed, 605 insertions(+), 133 deletions(-) diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fanutil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fanutil.py index 33866a6f9377..dab2f64dd5e0 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fanutil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fanutil.py @@ -2,11 +2,11 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.1" +__version__ = "0.1.2" __status__ = "Development" -import re import requests +import re class FanUtil(): @@ -249,27 +249,35 @@ def get_all(self): # Set fan FRU data. fan_fru_dict = dict() + fan_raw_idx = 1 for fan_fru in self.fru_data_list: - if len(fan_fru) == 0: - continue fru_dict = dict() - fan_key = fan_fru[0].split() fan_ps = False - if str(fan_key[-1]).lower() == "absent": - fan_idx = int(re.findall('\d+', fan_key[0])[0]) + if len(fan_fru) == 0: + fan_idx = fan_raw_idx + fan_pn = "N/A" + fan_sn = "N/A" else: - fan_idx = int(re.findall('\d+', fan_key[-1])[0]) - fan_ps = True - pn = [s for s in fan_fru if "Part" in s] - sn = [s for s in fan_fru if "Serial" in s] - fan_pn = pn[0].split(":")[-1].strip() if len(pn) > 0 else 'N/A' - fan_sn = sn[0].split(":")[-1].strip() if len(sn) > 0 else 'N/A' + fan_key = fan_fru[0].split() + if str(fan_key[-1]).lower() == "absent": + fan_idx = int(re.findall('\d+', fan_key[0])[0]) + + else: + fan_idx = int(re.findall('\d+', fan_key[-1])[0]) + fan_ps = True + pn = [s for s in fan_fru if "Part" in s] + sn = [s for s in fan_fru if "Serial" in s] + fan_pn = pn[0].split( + ":")[-1].strip() if len(pn) > 0 else 'N/A' + fan_sn = sn[0].split( + ":")[-1].strip() if len(sn) > 0 else 'N/A' fru_dict["PN"] = "N/A" if not fan_pn or fan_pn == "" else fan_pn fru_dict["SN"] = "N/A" if not fan_sn or fan_sn == "" else fan_sn fru_dict["Present"] = fan_ps fan_fru_dict[fan_idx] = fru_dict + fan_raw_idx += 1 # Set fan sensor data. for sensor_data in self.sensor_data_list: @@ -284,13 +292,17 @@ def get_all(self): fan_data = sensor_data.get(fan_key) fan_sp_list = map(int, re.findall(r'\d+', fan_data)) fan_dict["Present"] = fan_fru_dict[f_index]["Present"] - if fan_dict["Present"]: + if fan_dict["Present"] or fan_sp_list[0] > 0: + fan_dict["Present"] = True fan_dict["Speed"] = fan_sp_list[0] fan_dict["Running"] = True if fan_dict["Speed"] > 0 else False fan_dict["LowThd"] = fan_sp_list[1] fan_dict["HighThd"] = fan_sp_list[2] fan_dict["PN"] = fan_fru_dict[f_index]["PN"] fan_dict["SN"] = fan_fru_dict[f_index]["SN"] + fan_dict["AirFlow"] = "FTOB" if "R1241-F9001" in fan_dict["PN"] else "Unknown" + fan_dict["AirFlow"] = "BTOF" if "R1241-F9002" in fan_dict["PN"] else fan_dict["AirFlow"] + fan_dict["Status"] = True if fan_dict["AirFlow"] != "Unknown" else False fan_name = 'FAN{}_{}'.format(f_index, pos) all_fan_dict[fan_name] = fan_dict break diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py index 15a6bafb3b4b..5d072bbeae26 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py @@ -5,6 +5,7 @@ import subprocess import requests +import os try: from sonic_fwmgr.fwgmr_base import FwMgrUtilBase @@ -20,6 +21,7 @@ def __init__(self): self.platform_name = "AS1332h" self.onie_config_file = "/host/machine.conf" self.bmc_info_url = "http://240.1.1.1:8080/api/sys/bmc" + self.bmc_raw_command_url = "http://240.1.1.1:8080/api/sys/raw" self.onie_config_file = "/host/machine.conf" self.cpldb_version_path = "/sys/devices/platform/%s.cpldb/getreg" % self.platform_name self.fpga_version_path = "/sys/devices/platform/%s.switchboard/FPGA/getreg" % self.platform_name @@ -43,7 +45,7 @@ def get_bmc_version(self): :returns: version string """ - bmc_version = "None" + bmc_version = None bmc_version_key = "OpenBMC Version" bmc_info_req = requests.get(self.bmc_info_url) @@ -51,7 +53,7 @@ def get_bmc_version(self): bmc_info = bmc_info_json.get('Information') bmc_version = bmc_info.get(bmc_version_key) - return bmc_version + return str(bmc_version) def get_cpld_version(self): """Get CPLD version from SONiC @@ -83,9 +85,10 @@ def get_cpld_version(self): int(CPLD_3[2], 16), int(CPLD_3[3], 16)) CPLD_4 = 'None' if CPLD_4 is 'None' else "{}.{}".format( int(CPLD_4[2], 16), int(CPLD_4[3], 16)) - FAN_CPLD = 'None' if CPLD_4 is None else "{:.1f}".format(float(fan_cpld)) + FAN_CPLD = 'None' if CPLD_4 is None else "{:.1f}".format( + float(fan_cpld)) - cpld_version_dict={} + cpld_version_dict = {} cpld_version_dict.update({'CPLD_B': CPLD_B}) cpld_version_dict.update({'CPLD_C': CPLD_C}) cpld_version_dict.update({'CPLD_1': CPLD_1}) @@ -101,57 +104,144 @@ def get_bios_version(self): :returns: version string """ - bios_version='None' + bios_version = None - p=subprocess.Popen( + p = subprocess.Popen( ["sudo", "dmidecode", "-s", "bios-version"], stdout=subprocess.PIPE) - raw_data=str(p.communicate()[0]) - raw_data_list=raw_data.split("\n") - bios_version=raw_data_list[0] if len( + raw_data = str(p.communicate()[0]) + raw_data_list = raw_data.split("\n") + bios_version = raw_data_list[0] if len( raw_data_list) == 1 else raw_data_list[-2] - return bios_version + return str(bios_version) def get_onie_version(self): """Get ONiE version from SONiC :returns: version string """ - onie_verison='None' + onie_verison = None - onie_version_keys="onie_version" - onie_config_file=open(self.onie_config_file, "r") + onie_version_keys = "onie_version" + onie_config_file = open(self.onie_config_file, "r") for line in onie_config_file.readlines(): if onie_version_keys in line: - onie_version_raw=line.split('=') - onie_verison=onie_version_raw[1].strip() + onie_version_raw = line.split('=') + onie_verison = onie_version_raw[1].strip() break - return onie_verison + return str(onie_verison) def get_pcie_version(self): - """Get PCiE version from SONiC - :returns: version string + """Get PCiE version from SONiC + :returns: version dict { "PCIE_FW_LOADER": "2.5", "PCIE_FW": "D102_08" } + """ - cmd="sudo bcmcmd 'pciephy fw version'" - p=subprocess.Popen( + cmd = "sudo bcmcmd 'pciephy fw version'" + p = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - raw_data, err=p.communicate() - if err is not '': - return 'None' - else: - lines=raw_data.split('\n') + raw_data, err = p.communicate() + + pcie_version = dict() + pcie_version["PCIE_FW_LOADER"] = 'None' + pcie_version["PCIE_FW"] = 'None' + + if err == '': + lines = raw_data.split('\n') for line in lines: if 'PCIe FW loader' in line: - version=line.split(':')[1].strip() - return str(version) + pcie_version["PCIE_FW_LOADER"] = line.split(':')[1].strip() + elif 'PCIe FW version' in line: + pcie_version["PCIE_FW"] = line.split(':')[1].strip() + return pcie_version def get_fpga_version(self): """Get FPGA version from SONiC :returns: version string """ - version=self.__get_register_value(self.fpga_version_path, '0x00') + version = self.__get_register_value(self.fpga_version_path, '0x00') if version is not 'None': - version="{}.{}".format( + version = "{}.{}".format( int(version[2:][:4], 16), int(version[2:][4:], 16)) return str(version) + + def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): + """ + @fw_type MANDATORY, firmware type, should be one of the strings: 'cpld', 'fpga', 'bios', 'bmc' + @fw_path MANDATORY, target firmware file + @fw_extra OPTIONAL, extra information string, + + for fw_type 'cpld' and 'fpga': it can be used to indicate specific cpld, such as 'cpld1', 'cpld2', ... + or 'cpld_fan_come_board', etc. If None, upgrade all CPLD/FPGA firmware. for fw_type 'bios' and 'bmc', + value should be one of 'master' or 'slave' or 'both' + """ + + if fw_type == 'bmc': + + # Copy BMC image file to BMC + scp_command = 'scp ' + \ + os.path.abspath(fw_path) + ' root@240.1.1.1:/home/root/' + + print "Uploading image to BMC..." + print "Running command : ", scp_command + print "Please enter the BMC password" + p = subprocess.Popen( + scp_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + + if err != "": + print "Failed" + return False + + print "Installing BMC image..." + + filename_w_ext = os.path.basename(fw_path) + json_data = dict() + json_data["data"] = "flashcp /home/root/" + \ + filename_w_ext + " /dev/mtd5" + json_data["timeout"] = 300 + + r = requests.post(self.bmc_raw_command_url, json=json_data) + if r.status_code == 200: + print "DONE, Rebooting BMC....." + reboot_dict = dict() + reboot_dict["data"] = "reboot" + r = requests.post(self.bmc_raw_command_url, json=reboot_dict) + else: + print "Failed" + return False + + elif fw_type == 'fpga': + command = 'fpga_prog ' + fw_path + print "Running command : ", command + process = subprocess.Popen( + command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + while True: + output = process.stdout.readline() + if output == '' and process.poll() is not None: + break + if output: + print output.strip() + rc = process.poll() + return rc + + elif 'cpld' in fw_type: + command = 'ispvm ' + fw_path + if fw_extra is not None: + command = 'ispvm -c ' + \ + str(fw_extra) + " " + os.path.abspath(fw_path) + print "Running command : ", command + process = subprocess.Popen( + command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + while True: + output = process.stdout.readline() + if output == '' and process.poll() is not None: + break + if output: + print output.strip() + rc = process.poll() + return rc + + return None diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py index 242beb570e6a..b752c6169645 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py @@ -2,7 +2,7 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.2" +__version__ = "0.1.3" __status__ = "Development" import requests @@ -36,6 +36,15 @@ def request_data(self): self.psu_info_list = psu_info_json.get('Information') return self.fru_status_list, self.psu_info_list + def airflow_selector(self, pn): + # Set input type. + return { + "DPS-1100FB": "FTOB", + "DPS-1100AB": "BTOF", + "FSJ026-A20G": "FTOB", + "FSJ038-A20G": "BTOF" + }.get(pn, "Unknown") + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -213,12 +222,21 @@ def get_all(self): "Present")).strip() == "Present" else False psu_pw_status = True if str(fru_status.get( "Power Status")).strip() == "OK" else False + psu_pw_type = str(fru_status.get( + "Power Type")).strip() + ac_status = True if str(fru_status.get( + "AC Status")).strip().upper() == "OK" else False psu_status_dict["Present"] = psu_ps_status if psu_ps_status: psu_status_dict["PowerStatus"] = psu_pw_status psu_status_dict["PN"] = psu_info_dict[psu_idx]["PN"] psu_status_dict["SN"] = psu_info_dict[psu_idx]["SN"] + psu_status_dict["InputType"] = psu_pw_type + psu_status_dict["InputStatus"] = True if psu_pw_status and psu_ps_status else False + psu_status_dict["OutputStatus"] = ac_status + psu_status_dict["AirFlow"] = self.airflow_selector( + psu_status_dict["PN"].split()[0]) all_psu_dict[find_psu[0]] = psu_status_dict return all_psu_dict diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py index bb526aa8a174..4bf14ce6310b 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py @@ -13,6 +13,7 @@ class SensorUtil(): def __init__(self): self.sensor_url = "http://240.1.1.1:8080/api/sys/sensors" + self.sys_fruid_url = "http://240.1.1.1:8080/api/sys/fruid/sys" self.sensor_info_list = None def request_data(self): @@ -21,6 +22,9 @@ def request_data(self): sensor_data_req = requests.get(self.sensor_url) sensor_json = sensor_data_req.json() self.sensor_info_list = sensor_json.get('Information') + sys_fruid_req = requests.get(self.sys_fruid_url) + sys_fruid_json = sys_fruid_req.json() + self.sys_fruid_list = sys_fruid_json.get('Information') return self.sensor_info_list def input_type_selector(self, unit): @@ -291,6 +295,22 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): return sensor_input_high_threshold + def get_sys_airflow(self): + sys_air_flow = "Unknown" + sys_pn_data = [ + v.split(":") for v in self.sys_fruid_list if "Product Part Number" in v] + + if len(sys_pn_data) == 0: + return sys_air_flow + + sys_pn = sys_pn_data[0][1] + if "R1241-F0001" in sys_pn: + sys_air_flow = "FTOB" + elif"R1241-F0002" in sys_pn: + sys_air_flow = "BTOF" + + return sys_air_flow + def get_all(self): all_sensor_dict = dict() @@ -336,4 +356,8 @@ def get_all(self): all_sensor_dict[self.sensor_name].update(sensor_dict) + sensor_dict = dict() + sensor_dict["Sys_AirFlow"] = self.get_sys_airflow() + all_sensor_dict["TEMPERATURE"].update(sensor_dict) + return all_sensor_dict diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fanutil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fanutil.py index 33866a6f9377..dab2f64dd5e0 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fanutil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fanutil.py @@ -2,11 +2,11 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.1" +__version__ = "0.1.2" __status__ = "Development" -import re import requests +import re class FanUtil(): @@ -249,27 +249,35 @@ def get_all(self): # Set fan FRU data. fan_fru_dict = dict() + fan_raw_idx = 1 for fan_fru in self.fru_data_list: - if len(fan_fru) == 0: - continue fru_dict = dict() - fan_key = fan_fru[0].split() fan_ps = False - if str(fan_key[-1]).lower() == "absent": - fan_idx = int(re.findall('\d+', fan_key[0])[0]) + if len(fan_fru) == 0: + fan_idx = fan_raw_idx + fan_pn = "N/A" + fan_sn = "N/A" else: - fan_idx = int(re.findall('\d+', fan_key[-1])[0]) - fan_ps = True - pn = [s for s in fan_fru if "Part" in s] - sn = [s for s in fan_fru if "Serial" in s] - fan_pn = pn[0].split(":")[-1].strip() if len(pn) > 0 else 'N/A' - fan_sn = sn[0].split(":")[-1].strip() if len(sn) > 0 else 'N/A' + fan_key = fan_fru[0].split() + if str(fan_key[-1]).lower() == "absent": + fan_idx = int(re.findall('\d+', fan_key[0])[0]) + + else: + fan_idx = int(re.findall('\d+', fan_key[-1])[0]) + fan_ps = True + pn = [s for s in fan_fru if "Part" in s] + sn = [s for s in fan_fru if "Serial" in s] + fan_pn = pn[0].split( + ":")[-1].strip() if len(pn) > 0 else 'N/A' + fan_sn = sn[0].split( + ":")[-1].strip() if len(sn) > 0 else 'N/A' fru_dict["PN"] = "N/A" if not fan_pn or fan_pn == "" else fan_pn fru_dict["SN"] = "N/A" if not fan_sn or fan_sn == "" else fan_sn fru_dict["Present"] = fan_ps fan_fru_dict[fan_idx] = fru_dict + fan_raw_idx += 1 # Set fan sensor data. for sensor_data in self.sensor_data_list: @@ -284,13 +292,17 @@ def get_all(self): fan_data = sensor_data.get(fan_key) fan_sp_list = map(int, re.findall(r'\d+', fan_data)) fan_dict["Present"] = fan_fru_dict[f_index]["Present"] - if fan_dict["Present"]: + if fan_dict["Present"] or fan_sp_list[0] > 0: + fan_dict["Present"] = True fan_dict["Speed"] = fan_sp_list[0] fan_dict["Running"] = True if fan_dict["Speed"] > 0 else False fan_dict["LowThd"] = fan_sp_list[1] fan_dict["HighThd"] = fan_sp_list[2] fan_dict["PN"] = fan_fru_dict[f_index]["PN"] fan_dict["SN"] = fan_fru_dict[f_index]["SN"] + fan_dict["AirFlow"] = "FTOB" if "R1241-F9001" in fan_dict["PN"] else "Unknown" + fan_dict["AirFlow"] = "BTOF" if "R1241-F9002" in fan_dict["PN"] else fan_dict["AirFlow"] + fan_dict["Status"] = True if fan_dict["AirFlow"] != "Unknown" else False fan_name = 'FAN{}_{}'.format(f_index, pos) all_fan_dict[fan_name] = fan_dict break diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py index 498c5da98f31..aaf0dae543b7 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py @@ -5,6 +5,7 @@ import subprocess import requests +import os try: from sonic_fwmgr.fwgmr_base import FwMgrUtilBase @@ -20,6 +21,7 @@ def __init__(self): self.platform_name = "AS1348f8h" self.onie_config_file = "/host/machine.conf" self.bmc_info_url = "http://240.1.1.1:8080/api/sys/bmc" + self.bmc_raw_command_url = "http://240.1.1.1:8080/api/sys/raw" self.onie_config_file = "/host/machine.conf" self.cpldb_version_path = "/sys/devices/platform/%s.cpldb/getreg" % self.platform_name self.fpga_version_path = "/sys/devices/platform/%s.switchboard/FPGA/getreg" % self.platform_name @@ -43,7 +45,7 @@ def get_bmc_version(self): :returns: version string """ - bmc_version = "None" + bmc_version = None bmc_version_key = "OpenBMC Version" bmc_info_req = requests.get(self.bmc_info_url) @@ -51,7 +53,7 @@ def get_bmc_version(self): bmc_info = bmc_info_json.get('Information') bmc_version = bmc_info.get(bmc_version_key) - return bmc_version + return str(bmc_version) def get_cpld_version(self): """Get CPLD version from SONiC @@ -83,9 +85,10 @@ def get_cpld_version(self): int(CPLD_3[2], 16), int(CPLD_3[3], 16)) CPLD_4 = 'None' if CPLD_4 is 'None' else "{}.{}".format( int(CPLD_4[2], 16), int(CPLD_4[3], 16)) - FAN_CPLD = 'None' if CPLD_4 is None else "{:.1f}".format(float(fan_cpld)) + FAN_CPLD = 'None' if CPLD_4 is None else "{:.1f}".format( + float(fan_cpld)) - cpld_version_dict={} + cpld_version_dict = {} cpld_version_dict.update({'CPLD_B': CPLD_B}) cpld_version_dict.update({'CPLD_C': CPLD_C}) cpld_version_dict.update({'CPLD_1': CPLD_1}) @@ -101,57 +104,144 @@ def get_bios_version(self): :returns: version string """ - bios_version='None' + bios_version = None - p=subprocess.Popen( + p = subprocess.Popen( ["sudo", "dmidecode", "-s", "bios-version"], stdout=subprocess.PIPE) - raw_data=str(p.communicate()[0]) - raw_data_list=raw_data.split("\n") - bios_version=raw_data_list[0] if len( + raw_data = str(p.communicate()[0]) + raw_data_list = raw_data.split("\n") + bios_version = raw_data_list[0] if len( raw_data_list) == 1 else raw_data_list[-2] - return bios_version + return str(bios_version) def get_onie_version(self): """Get ONiE version from SONiC :returns: version string """ - onie_verison='None' + onie_verison = None - onie_version_keys="onie_version" - onie_config_file=open(self.onie_config_file, "r") + onie_version_keys = "onie_version" + onie_config_file = open(self.onie_config_file, "r") for line in onie_config_file.readlines(): if onie_version_keys in line: - onie_version_raw=line.split('=') - onie_verison=onie_version_raw[1].strip() + onie_version_raw = line.split('=') + onie_verison = onie_version_raw[1].strip() break - return onie_verison + return str(onie_verison) def get_pcie_version(self): """Get PCiE version from SONiC - :returns: version string + :returns: version dict { "PCIE_FW_LOADER": "2.5", "PCIE_FW": "D102_08" } + """ - cmd="sudo bcmcmd 'pciephy fw version'" - p=subprocess.Popen( + cmd = "sudo bcmcmd 'pciephy fw version'" + p = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - raw_data, err=p.communicate() - if err is not '': - return 'None' - else: - lines=raw_data.split('\n') + raw_data, err = p.communicate() + + pcie_version = dict() + pcie_version["PCIE_FW_LOADER"] = 'None' + pcie_version["PCIE_FW"] = 'None' + + if err == '': + lines = raw_data.split('\n') for line in lines: if 'PCIe FW loader' in line: - version=line.split(':')[1].strip() - return str(version) + pcie_version["PCIE_FW_LOADER"] = line.split(':')[1].strip() + elif 'PCIe FW version' in line: + pcie_version["PCIE_FW"] = line.split(':')[1].strip() + return pcie_version def get_fpga_version(self): """Get FPGA version from SONiC :returns: version string """ - version=self.__get_register_value(self.fpga_version_path, '0x00') + version = self.__get_register_value(self.fpga_version_path, '0x00') if version is not 'None': - version="{}.{}".format( + version = "{}.{}".format( int(version[2:][:4], 16), int(version[2:][4:], 16)) return str(version) + + def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): + """ + @fw_type MANDATORY, firmware type, should be one of the strings: 'cpld', 'fpga', 'bios', 'bmc' + @fw_path MANDATORY, target firmware file + @fw_extra OPTIONAL, extra information string, + + for fw_type 'cpld' and 'fpga': it can be used to indicate specific cpld, such as 'cpld1', 'cpld2', ... + or 'cpld_fan_come_board', etc. If None, upgrade all CPLD/FPGA firmware. for fw_type 'bios' and 'bmc', + value should be one of 'master' or 'slave' or 'both' + """ + + if fw_type == 'bmc': + + # Copy BMC image file to BMC + scp_command = 'scp ' + \ + os.path.abspath(fw_path) + ' root@240.1.1.1:/home/root/' + + print "Uploading image to BMC..." + print "Running command : ", scp_command + print "Please enter the BMC password" + p = subprocess.Popen( + scp_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + + if err != "": + print "Failed" + return False + + print "Installing BMC image..." + + filename_w_ext = os.path.basename(fw_path) + json_data = dict() + json_data["data"] = "flashcp /home/root/" + \ + filename_w_ext + " /dev/mtd5" + json_data["timeout"] = 300 + + r = requests.post(self.bmc_raw_command_url, json=json_data) + if r.status_code == 200: + print "DONE, Rebooting BMC....." + reboot_dict = dict() + reboot_dict["data"] = "reboot" + r = requests.post(self.bmc_raw_command_url, json=reboot_dict) + else: + print "Failed" + return False + + elif fw_type == 'fpga': + command = 'fpga_prog ' + fw_path + print "Running command : ", command + process = subprocess.Popen( + command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + while True: + output = process.stdout.readline() + if output == '' and process.poll() is not None: + break + if output: + print output.strip() + rc = process.poll() + return rc + + elif 'cpld' in fw_type: + command = 'ispvm ' + fw_path + if fw_extra is not None: + command = 'ispvm -c ' + \ + str(fw_extra) + " " + os.path.abspath(fw_path) + print "Running command : ", command + process = subprocess.Popen( + command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + while True: + output = process.stdout.readline() + if output == '' and process.poll() is not None: + break + if output: + print output.strip() + rc = process.poll() + return rc + + return None diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py index 242beb570e6a..b752c6169645 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py @@ -2,7 +2,7 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.2" +__version__ = "0.1.3" __status__ = "Development" import requests @@ -36,6 +36,15 @@ def request_data(self): self.psu_info_list = psu_info_json.get('Information') return self.fru_status_list, self.psu_info_list + def airflow_selector(self, pn): + # Set input type. + return { + "DPS-1100FB": "FTOB", + "DPS-1100AB": "BTOF", + "FSJ026-A20G": "FTOB", + "FSJ038-A20G": "BTOF" + }.get(pn, "Unknown") + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -213,12 +222,21 @@ def get_all(self): "Present")).strip() == "Present" else False psu_pw_status = True if str(fru_status.get( "Power Status")).strip() == "OK" else False + psu_pw_type = str(fru_status.get( + "Power Type")).strip() + ac_status = True if str(fru_status.get( + "AC Status")).strip().upper() == "OK" else False psu_status_dict["Present"] = psu_ps_status if psu_ps_status: psu_status_dict["PowerStatus"] = psu_pw_status psu_status_dict["PN"] = psu_info_dict[psu_idx]["PN"] psu_status_dict["SN"] = psu_info_dict[psu_idx]["SN"] + psu_status_dict["InputType"] = psu_pw_type + psu_status_dict["InputStatus"] = True if psu_pw_status and psu_ps_status else False + psu_status_dict["OutputStatus"] = ac_status + psu_status_dict["AirFlow"] = self.airflow_selector( + psu_status_dict["PN"].split()[0]) all_psu_dict[find_psu[0]] = psu_status_dict return all_psu_dict diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py index bb526aa8a174..4bf14ce6310b 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py @@ -13,6 +13,7 @@ class SensorUtil(): def __init__(self): self.sensor_url = "http://240.1.1.1:8080/api/sys/sensors" + self.sys_fruid_url = "http://240.1.1.1:8080/api/sys/fruid/sys" self.sensor_info_list = None def request_data(self): @@ -21,6 +22,9 @@ def request_data(self): sensor_data_req = requests.get(self.sensor_url) sensor_json = sensor_data_req.json() self.sensor_info_list = sensor_json.get('Information') + sys_fruid_req = requests.get(self.sys_fruid_url) + sys_fruid_json = sys_fruid_req.json() + self.sys_fruid_list = sys_fruid_json.get('Information') return self.sensor_info_list def input_type_selector(self, unit): @@ -291,6 +295,22 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): return sensor_input_high_threshold + def get_sys_airflow(self): + sys_air_flow = "Unknown" + sys_pn_data = [ + v.split(":") for v in self.sys_fruid_list if "Product Part Number" in v] + + if len(sys_pn_data) == 0: + return sys_air_flow + + sys_pn = sys_pn_data[0][1] + if "R1241-F0001" in sys_pn: + sys_air_flow = "FTOB" + elif"R1241-F0002" in sys_pn: + sys_air_flow = "BTOF" + + return sys_air_flow + def get_all(self): all_sensor_dict = dict() @@ -336,4 +356,8 @@ def get_all(self): all_sensor_dict[self.sensor_name].update(sensor_dict) + sensor_dict = dict() + sensor_dict["Sys_AirFlow"] = self.get_sys_airflow() + all_sensor_dict["TEMPERATURE"].update(sensor_dict) + return all_sensor_dict diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fanutil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fanutil.py index d3e8334271b8..7c37088b927e 100644 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fanutil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fanutil.py @@ -1,7 +1,12 @@ #!/usr/bin/env python -import re +__author__ = 'Wirut G.' +__license__ = "GPL" +__version__ = "0.1.2" +__status__ = "Development" + import requests +import re class FanUtil(): @@ -244,27 +249,35 @@ def get_all(self): # Set fan FRU data. fan_fru_dict = dict() + fan_raw_idx = 1 for fan_fru in self.fru_data_list: - if len(fan_fru) == 0: - continue fru_dict = dict() - fan_key = fan_fru[0].split() fan_ps = False - if str(fan_key[-1]).lower() == "absent": - fan_idx = int(re.findall('\d+', fan_key[0])[0]) + if len(fan_fru) == 0: + fan_idx = fan_raw_idx + fan_pn = "N/A" + fan_sn = "N/A" else: - fan_idx = int(re.findall('\d+', fan_key[-1])[0]) - fan_ps = True - pn = [s for s in fan_fru if "Part" in s] - sn = [s for s in fan_fru if "Serial" in s] - fan_pn = pn[0].split(":")[-1].strip() if len(pn) > 0 else 'N/A' - fan_sn = sn[0].split(":")[-1].strip() if len(sn) > 0 else 'N/A' + fan_key = fan_fru[0].split() + if str(fan_key[-1]).lower() == "absent": + fan_idx = int(re.findall('\d+', fan_key[0])[0]) + + else: + fan_idx = int(re.findall('\d+', fan_key[-1])[0]) + fan_ps = True + pn = [s for s in fan_fru if "Part" in s] + sn = [s for s in fan_fru if "Serial" in s] + fan_pn = pn[0].split( + ":")[-1].strip() if len(pn) > 0 else 'N/A' + fan_sn = sn[0].split( + ":")[-1].strip() if len(sn) > 0 else 'N/A' fru_dict["PN"] = "N/A" if not fan_pn or fan_pn == "" else fan_pn fru_dict["SN"] = "N/A" if not fan_sn or fan_sn == "" else fan_sn fru_dict["Present"] = fan_ps fan_fru_dict[fan_idx] = fru_dict + fan_raw_idx += 1 # Set fan sensor data. for sensor_data in self.sensor_data_list: @@ -279,15 +292,18 @@ def get_all(self): fan_data = sensor_data.get(fan_key) fan_sp_list = map(int, re.findall(r'\d+', fan_data)) fan_dict["Present"] = fan_fru_dict[f_index]["Present"] - if fan_dict["Present"]: + if fan_dict["Present"] or fan_sp_list[0] > 0: + fan_dict["Present"] = True fan_dict["Speed"] = fan_sp_list[0] fan_dict["Running"] = True if fan_dict["Speed"] > 0 else False fan_dict["LowThd"] = fan_sp_list[1] fan_dict["HighThd"] = fan_sp_list[2] fan_dict["PN"] = fan_fru_dict[f_index]["PN"] fan_dict["SN"] = fan_fru_dict[f_index]["SN"] + fan_dict["AirFlow"] = "FTOB" if "R1240-G0009" in fan_dict["PN"] else "Unknown" + fan_dict["Status"] = True if fan_dict["AirFlow"] != "Unknown" else False fan_name = 'FAN{}_{}'.format(f_index, pos) all_fan_dict[fan_name] = fan_dict break - return all_fan_dict \ No newline at end of file + return all_fan_dict diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py index a4d202389a4e..58b5a4ece421 100644 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py @@ -5,6 +5,7 @@ import subprocess import requests +import os try: from sonic_fwmgr.fwgmr_base import FwMgrUtilBase @@ -20,6 +21,7 @@ def __init__(self): self.platform_name = "AS23128h" self.onie_config_file = "/host/machine.conf" self.bmc_info_url = "http://240.1.1.1:8080/api/sys/bmc" + self.bmc_raw_command_url = "http://240.1.1.1:8080/api/sys/raw" self.onie_config_file = "/host/machine.conf" self.cpldb_version_path = "/sys/devices/platform/%s.cpldb/getreg" % self.platform_name self.fpga_version_path = "/sys/devices/platform/%s.switchboard/FPGA/getreg" % self.platform_name @@ -43,7 +45,7 @@ def get_bmc_version(self): :returns: version string """ - bmc_version = "None" + bmc_version = None bmc_version_key = "OpenBMC Version" bmc_info_req = requests.get(self.bmc_info_url) @@ -51,7 +53,7 @@ def get_bmc_version(self): bmc_info = bmc_info_json.get('Information') bmc_version = bmc_info.get(bmc_version_key) - return bmc_version + return str(bmc_version) def get_cpld_version(self): """Get CPLD version from SONiC @@ -83,9 +85,10 @@ def get_cpld_version(self): int(CPLD_3[2], 16), int(CPLD_3[3], 16)) CPLD_4 = 'None' if CPLD_4 is 'None' else "{}.{}".format( int(CPLD_4[2], 16), int(CPLD_4[3], 16)) - FAN_CPLD = 'None' if CPLD_4 is None else "{:.1f}".format(float(fan_cpld)) + FAN_CPLD = 'None' if CPLD_4 is None else "{:.1f}".format( + float(fan_cpld)) - cpld_version_dict={} + cpld_version_dict = {} cpld_version_dict.update({'CPLD_B': CPLD_B}) cpld_version_dict.update({'CPLD_C': CPLD_C}) cpld_version_dict.update({'CPLD_1': CPLD_1}) @@ -101,57 +104,144 @@ def get_bios_version(self): :returns: version string """ - bios_version='None' + bios_version = None - p=subprocess.Popen( + p = subprocess.Popen( ["sudo", "dmidecode", "-s", "bios-version"], stdout=subprocess.PIPE) - raw_data=str(p.communicate()[0]) - raw_data_list=raw_data.split("\n") - bios_version=raw_data_list[0] if len( + raw_data = str(p.communicate()[0]) + raw_data_list = raw_data.split("\n") + bios_version = raw_data_list[0] if len( raw_data_list) == 1 else raw_data_list[-2] - return bios_version + return str(bios_version) def get_onie_version(self): """Get ONiE version from SONiC :returns: version string """ - onie_verison='None' + onie_verison = None - onie_version_keys="onie_version" - onie_config_file=open(self.onie_config_file, "r") + onie_version_keys = "onie_version" + onie_config_file = open(self.onie_config_file, "r") for line in onie_config_file.readlines(): if onie_version_keys in line: - onie_version_raw=line.split('=') - onie_verison=onie_version_raw[1].strip() + onie_version_raw = line.split('=') + onie_verison = onie_version_raw[1].strip() break - return onie_verison + return str(onie_verison) def get_pcie_version(self): - """Get PCiE version from SONiC - :returns: version string + """Get PCiE version from SONiC + :returns: version dict { "PCIE_FW_LOADER": "2.5", "PCIE_FW": "D102_08" } + """ - cmd="sudo bcmcmd 'pciephy fw version'" - p=subprocess.Popen( + cmd = "sudo bcmcmd 'pciephy fw version'" + p = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - raw_data, err=p.communicate() - if err is not '': - return 'None' - else: - lines=raw_data.split('\n') + raw_data, err = p.communicate() + + pcie_version = dict() + pcie_version["PCIE_FW_LOADER"] = 'None' + pcie_version["PCIE_FW"] = 'None' + + if err == '': + lines = raw_data.split('\n') for line in lines: if 'PCIe FW loader' in line: - version=line.split(':')[1].strip() - return str(version) + pcie_version["PCIE_FW_LOADER"] = line.split(':')[1].strip() + elif 'PCIe FW version' in line: + pcie_version["PCIE_FW"] = line.split(':')[1].strip() + return pcie_version def get_fpga_version(self): """Get FPGA version from SONiC :returns: version string """ - version=self.__get_register_value(self.fpga_version_path, '0x00') + version = self.__get_register_value(self.fpga_version_path, '0x00') if version is not 'None': - version="{}.{}".format( + version = "{}.{}".format( int(version[2:][:4], 16), int(version[2:][4:], 16)) return str(version) + + def firmware_upgrade(self, fw_type, fw_path, fw_extra=None): + """ + @fw_type MANDATORY, firmware type, should be one of the strings: 'cpld', 'fpga', 'bios', 'bmc' + @fw_path MANDATORY, target firmware file + @fw_extra OPTIONAL, extra information string, + + for fw_type 'cpld' and 'fpga': it can be used to indicate specific cpld, such as 'cpld1', 'cpld2', ... + or 'cpld_fan_come_board', etc. If None, upgrade all CPLD/FPGA firmware. for fw_type 'bios' and 'bmc', + value should be one of 'master' or 'slave' or 'both' + """ + + if fw_type == 'bmc': + + # Copy BMC image file to BMC + scp_command = 'scp ' + \ + os.path.abspath(fw_path) + ' root@240.1.1.1:/home/root/' + + print "Uploading image to BMC..." + print "Running command : ", scp_command + print "Please enter the BMC password" + p = subprocess.Popen( + scp_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + + if err != "": + print "Failed" + return False + + print "Installing BMC image..." + + filename_w_ext = os.path.basename(fw_path) + json_data = dict() + json_data["data"] = "flashcp /home/root/" + \ + filename_w_ext + " /dev/mtd5" + json_data["timeout"] = 300 + + r = requests.post(self.bmc_raw_command_url, json=json_data) + if r.status_code == 200: + print "DONE, Rebooting BMC....." + reboot_dict = dict() + reboot_dict["data"] = "reboot" + r = requests.post(self.bmc_raw_command_url, json=reboot_dict) + else: + print "Failed" + return False + + elif fw_type == 'fpga': + command = 'fpga_prog ' + fw_path + print "Running command : ", command + process = subprocess.Popen( + command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + while True: + output = process.stdout.readline() + if output == '' and process.poll() is not None: + break + if output: + print output.strip() + rc = process.poll() + return rc + + elif 'cpld' in fw_type: + command = 'ispvm ' + fw_path + if fw_extra is not None: + command = 'ispvm -c ' + \ + str(fw_extra) + " " + os.path.abspath(fw_path) + print "Running command : ", command + process = subprocess.Popen( + command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + while True: + output = process.stdout.readline() + if output == '' and process.poll() is not None: + break + if output: + print output.strip() + rc = process.poll() + return rc + + return None diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py index e4910b1914b7..cfc4bc5ff3f5 100644 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py @@ -2,7 +2,7 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.2" +__version__ = "0.1.3" __status__ = "Development" import requests @@ -36,6 +36,15 @@ def request_data(self): self.psu_info_list = psu_info_json.get('Information') return self.fru_status_list, self.psu_info_list + def airflow_selector(self, pn): + # Set input type. + return { + "DPS-1100FB": "FTOB", + "DPS-1100AB": "BTOF", + "FSJ026-A20G": "FTOB", + "FSJ038-A20G": "BTOF" + }.get(pn, "Unknown") + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -213,12 +222,21 @@ def get_all(self): "Present")).strip() == "Present" else False psu_pw_status = True if str(fru_status.get( "Power Status")).strip() == "OK" else False + psu_pw_type = str(fru_status.get( + "Power Type")).strip() + ac_status = True if str(fru_status.get( + "AC Status")).strip().upper() == "OK" else False psu_status_dict["Present"] = psu_ps_status if psu_ps_status: psu_status_dict["PowerStatus"] = psu_pw_status psu_status_dict["PN"] = psu_info_dict[psu_idx]["PN"] psu_status_dict["SN"] = psu_info_dict[psu_idx]["SN"] + psu_status_dict["InputType"] = psu_pw_type + psu_status_dict["InputStatus"] = True if psu_pw_status and psu_ps_status else False + psu_status_dict["OutputStatus"] = ac_status + psu_status_dict["AirFlow"] = self.airflow_selector( + psu_status_dict["PN"].split()[0]) all_psu_dict[find_psu[0]] = psu_status_dict return all_psu_dict diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py index 41c42fc90ed9..fc437dc8c8b7 100644 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py @@ -13,6 +13,7 @@ class SensorUtil(): def __init__(self): self.sensor_url = "http://240.1.1.1:8080/api/sys/sensors" + self.sys_fruid_url = "http://240.1.1.1:8080/api/sys/fruid/sys" self.sensor_info_list = None def request_data(self): @@ -21,6 +22,9 @@ def request_data(self): sensor_data_req = requests.get(self.sensor_url) sensor_json = sensor_data_req.json() self.sensor_info_list = sensor_json.get('Information') + sys_fruid_req = requests.get(self.sys_fruid_url) + sys_fruid_json = sys_fruid_req.json() + self.sys_fruid_list = sys_fruid_json.get('Information') return self.sensor_info_list def input_type_selector(self, unit): @@ -311,6 +315,22 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): return sensor_input_high_threshold + def get_sys_airflow(self): + sys_air_flow = "Unknown" + sys_pn_data = [ + v.split(":") for v in self.sys_fruid_list if "Product Part Number" in v] + + if len(sys_pn_data) == 0: + return sys_air_flow + + sys_pn = sys_pn_data[0][1] + if "R1240-F0001" in sys_pn: + sys_air_flow = "FTOB" + elif"R1240-F0002" in sys_pn: + sys_air_flow = "BTOF" + + return sys_air_flow + def get_all(self): all_sensor_dict = dict() @@ -356,4 +376,8 @@ def get_all(self): all_sensor_dict[self.sensor_name].update(sensor_dict) + sensor_dict = dict() + sensor_dict["Sys_AirFlow"] = self.get_sys_airflow() + all_sensor_dict["TEMPERATURE"].update(sensor_dict) + return all_sensor_dict diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/platformutil.py b/platform/broadcom/sonic-platform-modules-cel/tools/platformutil.py index 4b1aca2088dc..aeacdd523388 100644 --- a/platform/broadcom/sonic-platform-modules-cel/tools/platformutil.py +++ b/platform/broadcom/sonic-platform-modules-cel/tools/platformutil.py @@ -83,6 +83,8 @@ # // "HighThd": 15000.0, # // "PN": "PN-EXAMPLE-123", # // "SN": "SN-EXAMPLE-123" +# // "Status": True, +# // "AirFlow": "FTOB" # // }, # // "FAN1_2": { # // "Present": True, @@ -92,6 +94,8 @@ # // "HighThd": 15000.0, # // "PN": "PN-EXAMPLE-456", # // "SN": "SN-EXAMPLE-456" +# // "Status": True, +# // "AirFlow": "BTOF" # // }, # // "FAN2_1": { # // "Present": True, @@ -109,7 +113,6 @@ # // } # // } # dict get_all() - # # class SensorUtil: # int get_num_sensors(); //get the number of sensors @@ -133,6 +136,37 @@ # // Return python 'dict' objects, example: # // { # // "SensorName1": { +# // "CPU_TEMP": +# // "Type": "temperature", +# // "Value": 37.3, +# // "LowThd": 0.0, +# // "HighThd": 110.0 +# // }, +# // "SWITCH_TEMP": { +# // "Type": "temperature", +# // "Value": 45.2, +# // "LowThd": 0.0, +# // "HighThd": 108.0 +# // }, +# // "INLET_TEMP": { +# // "Type": "temperature", +# // "Value": 22.0, +# // "LowThd": 0.0, +# // "HighThd": 70.0 +# // }, +# // "Sys_AirFlow": "BTOF", +# // "Switch_VDDCore_0.8v": { +# // "Type": "voltage", +# // "Value": 0.75, +# // "LowThd": 0.7, +# // "HighThd": 0.85 +# // }, +# // "Cpu_VDDCore_0.8v": { +# // "Type": "voltage", +# // "Value": 0.75, +# // "LowThd": 0.7, +# // "HighThd": 0.85 +# // }, # // "SensorInput1": { # // "Type": "temperature", # // "Value": 30.0, @@ -181,7 +215,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -VERSION = '1.1' +VERSION = '1.2' SYSLOG_IDENTIFIER = "platformutil" PLATFORM_PSU_MODULE_NAME = "psuutil" @@ -527,6 +561,8 @@ def status(ctx): si_names = [ k for k in sensor_obj.keys() ] si_names.sort() for si_name in si_names: + if si_name == "Sys_AirFlow": + continue si = sensor_obj[si_name] stype = si.get('Type') sval = si.get('Value')