From 6cb445cb9e6fbcc7382d57b507183849e3ce7c2c Mon Sep 17 00:00:00 2001 From: ciju-juniper <53076238+ciju-juniper@users.noreply.github.com> Date: Sun, 20 Oct 2019 09:16:32 +0530 Subject: [PATCH] [Juniper][QFX5210]Adding the system reboot handler (#3599) The following changes are done as part of this commit: - Adding the system reboot handler - Adding swizzle reset case for the reboot reason - Workaround for the boot problem from Golden bios - Adding the logging messages for platform scripts - EEPROM parsing and library routines --- .../sonic-platform-juniper-qfx5210.postinst | 20 +++ .../modules/x86-64-juniper-qfx5210-64x-psu.c | 84 +++++++-- .../service/qfx5210-platform-init.service | 2 + .../qfx5210/sonic_platform/chassis.py | 138 +++++++++++++- .../qfx5210/utils/juniper_qfx5210_monitor.py | 54 +++++- .../qfx5210/utils/juniper_qfx5210_util.py | 170 ++++++++++++++++-- 6 files changed, 429 insertions(+), 39 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-juniper/debian/sonic-platform-juniper-qfx5210.postinst b/platform/broadcom/sonic-platform-modules-juniper/debian/sonic-platform-juniper-qfx5210.postinst index 1b00ceb568e6..dcff39f53799 100644 --- a/platform/broadcom/sonic-platform-modules-juniper/debian/sonic-platform-juniper-qfx5210.postinst +++ b/platform/broadcom/sonic-platform-modules-juniper/debian/sonic-platform-juniper-qfx5210.postinst @@ -1,2 +1,22 @@ systemctl enable qfx5210-platform-init.service systemctl start qfx5210-platform-init.service + +# There are primary and secondary bios in qfx5210 platform. +# There is a problem with bios which prevents the OS booting from the +# secondary bios when the OS was installed using primary bios. +# Secondary bios fails to detect the UEFI partition. Right now +# the workaround is to have a folder structure /EFI/BOOT/BOOT64x.efi + +SONIC_VERSION=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v build_version) +FIRST_BOOT_FILE="/host/image-${SONIC_VERSION}/platform/firsttime" + +if [ -f $FIRST_BOOT_FILE ]; then + mkdir /tmp/sda1 + mount /dev/sda1 /tmp/sda1 + cd /tmp/sda1/EFI + mkdir BOOT > /dev/null 2>&1 + cp SONiC-OS/grubx64.efi BOOT/BOOTX64.EFI + cd /tmp + umount sda1 + efibootmgr -c -L "SONiC" -l "\EFI\BOOT\BOOTX64.EFI" > /dev/null 2>&1 +fi diff --git a/platform/broadcom/sonic-platform-modules-juniper/qfx5210/modules/x86-64-juniper-qfx5210-64x-psu.c b/platform/broadcom/sonic-platform-modules-juniper/qfx5210/modules/x86-64-juniper-qfx5210-64x-psu.c index d42e61b3c51b..cb283d2d4a1c 100644 --- a/platform/broadcom/sonic-platform-modules-juniper/qfx5210/modules/x86-64-juniper-qfx5210-64x-psu.c +++ b/platform/broadcom/sonic-platform-modules-juniper/qfx5210/modules/x86-64-juniper-qfx5210-64x-psu.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #define PSU_STATUS_I2C_ADDR 0x60 #define PSU_STATUS_I2C_REG_OFFSET 0x03 @@ -46,6 +48,10 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); static struct qfx5210_64x_psu_data *qfx5210_64x_psu_update_device(struct device *dev); extern int juniper_i2c_cpld_read (u8 cpld_addr, u8 reg); +/* + * This function is defined in juniper_i2c_cpld.c + */ +extern int juniper_i2c_cpld_write(unsigned short, u8, u8); /* Addresses scanned */ @@ -78,6 +84,36 @@ static struct attribute *qfx5210_64x_psu_attributes[] = { NULL }; +static int qfx5210_cpld_soft_reset(struct notifier_block *nb, + unsigned long action, + void *data) +{ + int ret = 0; + + switch (action) { + case SYS_POWER_OFF: + case SYS_HALT: + printk(KERN_CRIT "System halt/power_off\n"); + break; + case SYS_RESTART: + printk(KERN_CRIT "System restart: qfx5210_cpld_soft_reset\n"); + ret = juniper_i2c_cpld_write(0x65, 0x04, 0x01); + if (ret) { + printk(KERN_CRIT "qfx5210_cpld_soft_reset failed\n"); + } + msleep(100); + break; + default: + /* Do Nothing */ + break; + } + return NOTIFY_DONE; +} + +static struct notifier_block qfx5210_nb = { + .notifier_call = qfx5210_cpld_soft_reset, +}; + static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf) { @@ -103,11 +139,6 @@ static const struct attribute_group qfx5210_64x_psu_group = { .attrs = qfx5210_64x_psu_attributes, }; -/* - * This function is defined in juniper_i2c_cpld.c - */ -extern int juniper_i2c_cpld_write(unsigned short, u8, u8); - /* * QFX5210 power off sequence */ @@ -126,7 +157,6 @@ static void qfx5210_cpld_power_off(void) */ static void (*default_pm_power_off)(void); - static int qfx5210_64x_psu_probe(struct i2c_client *client, const struct i2c_device_id *dev_id) { @@ -165,12 +195,7 @@ static int qfx5210_64x_psu_probe(struct i2c_client *client, dev_info(&client->dev, "%s: psu '%s'\n", dev_name(data->hwmon_dev), client->name); - /* - * Store the default poweroff handler for later usage - */ - default_pm_power_off = pm_power_off; - pm_power_off = qfx5210_cpld_power_off; - + return 0; exit_remove: @@ -189,19 +214,14 @@ static int qfx5210_64x_psu_remove(struct i2c_client *client) hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&client->dev.kobj, &qfx5210_64x_psu_group); kfree(data); - - /* - * Restore the poweroff handler - */ - pm_power_off = default_pm_power_off; - + return 0; } enum psu_index { qfx5210_64x_psu1, - qfx5210_64x_psu2 + qfx5210_64x_psu2 }; static const struct i2c_device_id qfx5210_64x_psu_id[] = { @@ -259,11 +279,37 @@ static struct qfx5210_64x_psu_data *qfx5210_64x_psu_update_device(struct device static int __init qfx5210_64x_psu_init(void) { + /* + * Store the default poweroff handler for later usage + */ + default_pm_power_off = pm_power_off; + /* + * Register the cpld poweroff handler + */ + pm_power_off = qfx5210_cpld_power_off; + /* + * Register the cpld soft reset handler + */ + if(register_reboot_notifier(&qfx5210_nb)) { + printk(KERN_ALERT "Restart handler registration failed\n"); + } + return i2c_add_driver(&qfx5210_64x_psu_driver); } static void __exit qfx5210_64x_psu_exit(void) { + /* + * Restore the poweroff handler + */ + pm_power_off = default_pm_power_off; + /* + * Unregister the cpld soft reset handler + */ + if (!unregister_restart_handler(&qfx5210_nb)) { + printk(KERN_CRIT "Failed to uregister restart handler\n"); + } + i2c_del_driver(&qfx5210_64x_psu_driver); } diff --git a/platform/broadcom/sonic-platform-modules-juniper/qfx5210/service/qfx5210-platform-init.service b/platform/broadcom/sonic-platform-modules-juniper/qfx5210/service/qfx5210-platform-init.service index b6a446ec1752..46377aa9fdc8 100755 --- a/platform/broadcom/sonic-platform-modules-juniper/qfx5210/service/qfx5210-platform-init.service +++ b/platform/broadcom/sonic-platform-modules-juniper/qfx5210/service/qfx5210-platform-init.service @@ -8,6 +8,8 @@ DefaultDependencies=no ExecStartPre=/usr/local/bin/juniper_qfx5210_util.py install ExecStart=/usr/local/bin/juniper_qfx5210_monitor.py RemainAfterExit=yes +StandardOutput=syslog+console +StandardError=syslog+console [Install] WantedBy=multi-user.target diff --git a/platform/broadcom/sonic-platform-modules-juniper/qfx5210/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-juniper/qfx5210/sonic_platform/chassis.py index 5d56ef3a0cde..674d9184df3c 100755 --- a/platform/broadcom/sonic-platform-modules-juniper/qfx5210/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-juniper/qfx5210/sonic_platform/chassis.py @@ -60,7 +60,7 @@ def __init__(self): def get_qfx5210_parameter_value(self,parameter_name): try: - with open("/var/run/qfx5210_eeprom", "r") as file: + with open("/var/run/eeprom", "r") as file: for item in file: content = item.split('=') if content[0] == parameter_name: @@ -71,29 +71,32 @@ def get_qfx5210_parameter_value(self,parameter_name): return "False" def get_product_name(self): - product_name_list = self.get_qfx5210_parameter_value('ProductName') + product_name_list = self.get_qfx5210_parameter_value('Product Name') if product_name_list: product_name = ''.join(product_name_list) return product_name else: return False + def get_part_number(self): - part_number_list = self.get_qfx5210_parameter_value('PartNumber') + part_number_list = self.get_qfx5210_parameter_value('Part Number') if part_number_list: part_number = ''.join(part_number_list) return part_number else: return False + def get_serial_number(self): - serial_number_list = self.get_qfx5210_parameter_value('SerialNumber') + serial_number_list = self.get_qfx5210_parameter_value('Serial Number') if serial_number_list: serial_number = ''.join(serial_number_list) return serial_number else: return False + def get_base_mac(self): mac_list = self.get_qfx5210_parameter_value('MAC') if mac_list: @@ -102,13 +105,134 @@ def get_base_mac(self): else: return False + + def get_mfg_date(self): + mfgdate_list = self.get_qfx5210_parameter_value('Manufacture Date') + if mfgdate_list: + mfgdate = ''.join(mfgdate_list) + return mfgdate + else: + return False + + def get_deviceversion_name(self): + device_version_list = self.get_qfx5210_parameter_value('Device Version') + if device_version_list: + deviceversion_name = ''.join(device_version_list) + return deviceversion_name + else: + return False + def get_platform_name(self): - platform_name_list = self.get_qfx5210_parameter_value('PlatformName') + platform_name_list = self.get_qfx5210_parameter_value('Platform Name') if platform_name_list: platform_name = ''.join(platform_name_list) return platform_name else: return False + + def get_MACnumber_name(self): + MACnumber_name_list = self.get_qfx5210_parameter_value('Number of MAC Addresses') + if MACnumber_name_list: + MACnumber_name = ''.join(MACnumber_name_list) + return MACnumber_name + else: + return False + + def get_vendor_name(self): + vendor_name_list = self.get_qfx5210_parameter_value('Vendor Name') + if vendor_name_list: + vendor_name = ''.join(vendor_name_list) + return vendor_name + else: + return False + + def get_mfg_name(self): + mfg_name_list = self.get_qfx5210_parameter_value('Manufacture Name') + if mfg_name_list: + mfg_name = ''.join(mfg_name_list) + return mfg_name + else: + return False + + def get_vendorext_name(self): + vendorext_list = self.get_qfx5210_parameter_value('Vendor Extension') + if vendorext_list: + vendorext = ''.join(vendorext_list) + return vendorext + else: + return False + + def get_vendorextIANA_name(self): + vendorext_list = self.get_qfx5210_parameter_value('IANA') + if vendorext_list: + vendorext = ''.join(vendorext_list) + return vendorext + else: + return False + + def get_vendorextASMREV_name(self): + vendorext_list = self.get_qfx5210_parameter_value('Assembly Part Number Rev') + if vendorext_list: + vendorext = ''.join(vendorext_list) + return vendorext + else: + return False + + def get_vendorextASMPartNum_name(self): + vendorext_list = self.get_qfx5210_parameter_value('Assembly Part Number') + if vendorext_list: + vendorext = ''.join(vendorext_list) + return vendorext + else: + return False + + def get_vendorextASMID_name(self): + vendorext_list = self.get_qfx5210_parameter_value('Assembly ID') + if vendorext_list: + vendorext = ''.join(vendorext_list) + return vendorext + else: + return False + + def get_vendorextASMMajNum_name(self): + vendorext_list = self.get_qfx5210_parameter_value('Assembly Major Revision') + if vendorext_list: + vendorext = ''.join(vendorext_list) + return vendorext + else: + return False + + def get_vendorextASMMinNum_name(self): + vendorext_list = self.get_qfx5210_parameter_value('Assembly Minor Revision') + if vendorext_list: + vendorext = ''.join(vendorext_list) + return vendorext + else: + return False + + def get_vendorextCLEI_name(self): + vendorext_list = self.get_qfx5210_parameter_value('CLEI code') + if vendorext_list: + vendorext = ''.join(vendorext_list) + return vendorext + else: + return False + + def get_onieversion_name(self): + onieversion_name_list = self.get_qfx5210_parameter_value('ONIE Version') + if onieversion_name_list: + onieversion_name = ''.join(onieversion_name_list) + return onieversion_name + else: + return False + + def get_crc_name(self): + crc_list = self.get_qfx5210_parameter_value('CRC') + if crc_list: + crc_name = ''.join(crc_list) + return crc_name + else: + return False def get_fan_type(self, fantype_path): try: @@ -134,6 +258,8 @@ def get_reboot_cause(self): return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None) elif last_reboot_reason == "0x20": return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None) + elif last_reboot_reason == "0x10": + return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Swizzle Reset") else: return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Unknown reason") else: @@ -145,5 +271,7 @@ def get_reboot_cause(self): return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None) elif last_reboot_reason == "0x20": return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None) + elif last_reboot_reason == "0x10": + return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Swizzle Reset") else: return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Unknown reason") diff --git a/platform/broadcom/sonic-platform-modules-juniper/qfx5210/utils/juniper_qfx5210_monitor.py b/platform/broadcom/sonic-platform-modules-juniper/qfx5210/utils/juniper_qfx5210_monitor.py index a74bce042ac3..d225400121b8 100755 --- a/platform/broadcom/sonic-platform-modules-juniper/qfx5210/utils/juniper_qfx5210_monitor.py +++ b/platform/broadcom/sonic-platform-modules-juniper/qfx5210/utils/juniper_qfx5210_monitor.py @@ -53,10 +53,16 @@ # Deafults VERSION = '1.0' -FUNCTION_NAME = '/usr/local/bin/juniper_qfx5210_monitor' +FUNCTION_NAME = '/var/log/juniper_qfx5210_monitor' + + +global log_file +global log_level global isPlatformAFI +global isFireThresholdReached +FireThresholdSecsRemaining = 120 temp_policy_AFI = { 0: [[70, 0, 48000], [70, 48000, 53000], [80, 53000, 0], [80, 53000, 58000], [100, 58000, 0], ['Yellow Alarm', 64000, 70000], ['Red Alarm', 70000, 75000], ['Fire Shut Alarm', 75000, 0]], @@ -268,6 +274,8 @@ def set_alarm_led_brightness(self, val): def getSensorTemp(self): sum = 0 global isPlatformAFI + global isFireThresholdReached + global FireThresholdSecsRemaining #AFI if (isPlatformAFI == True): temp_policy = temp_policy_AFI @@ -287,6 +295,17 @@ def getSensorTemp(self): 5: [0,0,0,0,0,0,0,0], 6: [0,0,0,0,0,0,0,0], } + # if the Firethreshold Flag is set and 120 seconds have elapsed, invoking the "poweroff" to shutdown the box + if (isFireThresholdReached == True): + firethr = FireThresholdSecsRemaining - 20 + logging.critical('CRITICAL: Fire Threshold reached: System is going to shutdown in %s seconds', firethr) + print "Fire Threshold reached: System is going to shutdown in %s seconds\n" % firethr + FireThresholdSecsRemaining = FireThresholdSecsRemaining - 20 + if (FireThresholdSecsRemaining == 20): + isFireThresholdReached == False + time.sleep(20) + cmd = "poweroff" + returned_value = os.system(cmd) for x in range(self.SENSOR_CORETEMP_NUM_ON_MAIN_BOARD): if x < self.SENSOR_NUM_ON_MAIN_BOARD: @@ -332,6 +351,9 @@ def getSensorTemp(self): fan = QFX5210_FanUtil() # CHECK IF ANY TEMPERATURE SENSORS HAS SET FIRE SHUTDOWN FLAG if SensorFlag[0][7] or SensorFlag[1][7] or SensorFlag[2][7] or SensorFlag[3][7] or SensorFlag[4][7] or SensorFlag[5][7] or SensorFlag[6][7]: + isFireThresholdReached = True + logging.critical('CRITICAL: Fire Threshold reached: System is going to shutdown in 120 seconds') + print "CRITICAL: Fire Threshold reached: System is going to shutdown in 120 seconds\n" value = self.get_alarm_led_brightness() if ( value > 0): self.set_alarm_led_brightness(0) @@ -399,12 +421,32 @@ def getSensorTemp(self): class device_monitor(object): - def __init__(self): + def __init__(self, log_file, log_level): + global isPlatformAFI + global isFireThresholdReached MASTER_LED_PATH = '/sys/class/leds/master/brightness' SYSTEM_LED_PATH = '/sys/class/leds/system/brightness' FANTYPE_PATH = '/sys/bus/i2c/devices/17-0068/fan1_direction' + """Needs a logger and a logger level.""" + # set up logging to file + logging.basicConfig( + filename=log_file, + filemode='w', + level=log_level, + format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', + datefmt='%H:%M:%S' + ) + + # set up logging to console + if log_level == logging.DEBUG: + console = logging.StreamHandler() + console.setLevel(log_level) + formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') + console.setFormatter(formatter) + logging.getLogger('').addHandler(console) + import sonic_platform platform = sonic_platform.platform.Platform() chassis = platform.get_chassis() @@ -418,7 +460,8 @@ def __init__(self): isPlatformAFI = False else: isPlatformAFI = True - + + isFireThresholdReached = False master_led_value = 1 try: @@ -444,7 +487,10 @@ def manage_device(self): thermal.getSensorTemp() def main(): - monitor = device_monitor() + log_file = '%s.log' % FUNCTION_NAME + log_level = logging.DEBUG + + monitor = device_monitor(log_file, log_level) while True: monitor.manage_device() time.sleep(20) diff --git a/platform/broadcom/sonic-platform-modules-juniper/qfx5210/utils/juniper_qfx5210_util.py b/platform/broadcom/sonic-platform-modules-juniper/qfx5210/utils/juniper_qfx5210_util.py index ccb32a3a894a..b3f130af41c0 100755 --- a/platform/broadcom/sonic-platform-modules-juniper/qfx5210/utils/juniper_qfx5210_util.py +++ b/platform/broadcom/sonic-platform-modules-juniper/qfx5210/utils/juniper_qfx5210_util.py @@ -56,7 +56,7 @@ ALL_DEVICE = {} DEVICE_NO = {'led':4, 'fan':4,'thermal':6, 'psu':2, 'sfp':64} FORCE = 0 - +FUNCTION_NAME = '/var/log/juniper_qfx5210_util' if DEBUG == True: print sys.argv[0] @@ -67,6 +67,9 @@ def main(): global DEBUG global args global FORCE + + log_file = '%s.log' % FUNCTION_NAME + log_level = logging.DEBUG if len(sys.argv)<2: show_help() @@ -75,11 +78,25 @@ def main(): 'debug', 'force', ]) + logging.basicConfig( + filename=log_file, + filemode='w', + level=log_level, + format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', + datefmt='%H:%M:%S') + if DEBUG == True: print options print args print len(sys.argv) - + # set up logging to console + if log_level == logging.DEBUG: + console = logging.StreamHandler() + console.setLevel(log_level) + formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') + console.setFormatter(formatter) + logging.getLogger('').addHandler(console) + for opt, arg in options: if opt in ('-h', '--help'): show_help() @@ -114,7 +131,7 @@ def main(): else: show_help() - DisableWatchDogCmd = '/usr/sbin/i2cset -y 0 0x65 0x3 0x04' + DisableWatchDogCmd = '/usr/sbin/i2cset -f -y 0 0x65 0x3 0x04' # Disable watchdog try: os.system(DisableWatchDogCmd) @@ -131,6 +148,135 @@ def main(): print 'Error: Execution of "%s" failed', CPUeepromFileCmd return False + eeprom_ascii = '/etc/init.d/eeprom_qfx5210_ascii' + # Read file contents in Hex format + with open(eeprom_ascii, 'rb') as Hexformat: + content = Hexformat.read() + Hexformatoutput = binascii.hexlify(content) + + eeprom_hex = '/etc/init.d/eeprom_qfx5210_hex' + #Write contents of CPU EEPROM to new file in hexa format + with open(eeprom_hex, 'wb+') as Hexfile: + Hexfile.write(Hexformatoutput) + + # Read from EEPROM Hex file and extract the different fields like Product name, + # Part Number, Serial Number MAC Address, Mfg Date ... etc and store in /var/run/eeprom file + with open(eeprom_hex, 'rb') as eeprom_hexfile: + # moving the file pointer to required position where product name is stored in EEPROM file and reading the required bytes from this position + + product_position = eeprom_hexfile.seek(26, 0) + product_read = eeprom_hexfile.read(36) + product_name = binascii.unhexlify(product_read) + + # creating the "/var/run/eeprom" file and storing all the values of different fields in this file. + eeprom_file = open ("/var/run/eeprom", "a+") + eeprom_file.write("Product Name=%s\r\n" % str(product_name)) + + # like wise we are moving the file pointer to respective position where other fields are stored and extract these fields and store in /var/run/eeprom file + partnumber_position = eeprom_hexfile.seek(66, 0) + partnumber_read = eeprom_hexfile.read(20) + partnumber_name = binascii.unhexlify(partnumber_read) + eeprom_file.write("Part Number=%s\r\n" % str(partnumber_name)) + + serialnumber_position = eeprom_hexfile.seek(90, 0) + serialnumber_read = eeprom_hexfile.read(24) + serialnumber_name = binascii.unhexlify(serialnumber_read) + eeprom_file.write("Serial Number=%s\r\n" % str(serialnumber_name)) + + macaddress_position = eeprom_hexfile.seek(118, 0) + macaddress_read = eeprom_hexfile.read(12) + macaddress_name="" + for i in range(0,12,2): + macaddress_name += macaddress_read[i:i+2] + ":" + macaddress_name=macaddress_name[:-1] + eeprom_file.write("MAC Address=%s\r\n" % str(macaddress_name)) + + mfgdate_position = eeprom_hexfile.seek(132, 0) + mfgdate_read = eeprom_hexfile.read(40) + mfgdate_name = binascii.unhexlify(mfgdate_read) + eeprom_file.write("Manufacture Date=%s\r\n" % str(mfgdate_name)) + + devversion_position = eeprom_hexfile.seek(176, 0) + devversion_read = eeprom_hexfile.read(2) + eeprom_file.write("Device Version=%s\r\n" % str(devversion_read)) + + platform_position = eeprom_hexfile.seek(182, 0) + platform_read = eeprom_hexfile.read(68) + platform_name = binascii.unhexlify(platform_read) + eeprom_file.write("Platform Name=%s\r\n" % str(platform_name)) + + MACnumber_position = eeprom_hexfile.seek(254, 0) + MACnumber_read = eeprom_hexfile.read(4) + MACnumber = int(MACnumber_read, 16) + eeprom_file.write("Number of MAC Addresses=%s\r\n" % str(MACnumber)) + + vendorName_position = eeprom_hexfile.seek(262, 0) + vendorName_read = eeprom_hexfile.read(40) + vendorName = binascii.unhexlify(vendorName_read) + eeprom_file.write("Vendor Name=%s\r\n" % str(vendorName)) + + mfgname_position = eeprom_hexfile.seek(306, 0) + mfgname_read = eeprom_hexfile.read(40) + mfgname = binascii.unhexlify(mfgname_read) + eeprom_file.write("Manufacture Name=%s\r\n" % str(mfgname)) + + vendorext_position = eeprom_hexfile.seek(350, 0) + vendorext_read = eeprom_hexfile.read(124) + vendorext="" + vendorext += "0x" + vendorext_read[0:2] + for i in range(2,124,2): + vendorext += " 0x" + vendorext_read[i:i+2] + eeprom_file.write("Vendor Extension=%s\r\n" % str(vendorext)) + + IANA_position = eeprom_hexfile.seek(350, 0) + IANA_read = eeprom_hexfile.read(8) + IANAName = binascii.unhexlify(IANA_read) + eeprom_file.write("IANA=%s\r\n" % str(IANAName)) + + ASMpartrev_position = eeprom_hexfile.seek(358, 0) + ASMpartrev_read = eeprom_hexfile.read(4) + ASMpartrev = binascii.unhexlify(ASMpartrev_read) + eeprom_file.write("Assembly Part Number Rev=%s\r\n" % str(ASMpartrev)) + + ASMpartnum_position = eeprom_hexfile.seek(374, 0) + ASMpartnum_read = eeprom_hexfile.read(20) + ASMpartnum_read = binascii.unhexlify(ASMpartnum_read) + eeprom_file.write("Assembly Part Number=%s\r\n" % str(ASMpartnum_read)) + + ASMID_position = eeprom_hexfile.seek(402, 0) + ASMID_read = eeprom_hexfile.read(4) + ASMID_read_upper = ASMID_read.upper() + eeprom_file.write("Assembly ID=0x%s\r\n" % str(ASMID_read_upper)) + + ASMHWMajRev_position = eeprom_hexfile.seek(410, 0) + ASMHWMajRev_read = eeprom_hexfile.read(2) + eeprom_file.write("Assembly Major Revision=0x%s\r\n" % str(ASMHWMajRev_read)) + + ASMHWMinRev_position = eeprom_hexfile.seek(416, 0) + ASMHWMinRev_read = eeprom_hexfile.read(2) + eeprom_file.write("Assembly Minor Revision=0x%s\r\n" % str(ASMHWMinRev_read)) + + Deviation_position = eeprom_hexfile.seek(422, 0) + Deviation_read = eeprom_hexfile.read(28) + Deviation_read_upper = Deviation_read.upper() + eeprom_file.write("Deviation=0x%s\r\n" % str(Deviation_read_upper)) + + CLEI_position = eeprom_hexfile.seek(450, 0) + CLEI_read = eeprom_hexfile.read(20) + CLEI_name = binascii.unhexlify(CLEI_read) + eeprom_file.write("CLEI code=%s\r\n" % str(CLEI_name)) + + ONIEversion_position = eeprom_hexfile.seek(478, 0) + ONIEversion_read = eeprom_hexfile.read(22) + ONIEversion = binascii.unhexlify(ONIEversion_read) + eeprom_file.write("ONIE Version=%s\r\n" % str(ONIEversion)) + + CRC_position = eeprom_hexfile.seek(504, 0) + CRC = eeprom_hexfile.read(8) + eeprom_file.write("CRC=%s\r\n" % str(CRC)) + + eeprom_file.close() + return True def show_help(): @@ -152,7 +298,7 @@ def show_eeprom_help(): def my_log(txt): if DEBUG == True: - print "[ROY]"+txt + print txt return def log_os_system(cmd, show): @@ -253,7 +399,9 @@ def driver_uninstall(): 'echo cpld_qfx5210 0x60 > /sys/bus/i2c/devices/i2c-19/new_device', 'echo cpld_plain 0x62 > /sys/bus/i2c/devices/i2c-20/new_device', 'echo cpld_plain 0x64 > /sys/bus/i2c/devices/i2c-21/new_device', -'echo cpld_plain 0x66 > /sys/bus/i2c/devices/i2c-22/new_device'] +'echo cpld_plain 0x66 > /sys/bus/i2c/devices/i2c-22/new_device', +'echo cpld_plain 0x65 > /sys/bus/i2c/devices/i2c-0/new_device 2>/dev/null' +] def i2c_order_check(): return 0 @@ -322,9 +470,9 @@ def system_ready(): return True def do_install(): - print "Checking system...." + logging.info('Checking system....') if driver_check() == False: - print "No driver, installing...." + logging.info('No driver, installing....') status = driver_install() if status: if FORCE == 0: @@ -332,7 +480,7 @@ def do_install(): else: print PROJECT_NAME.upper()+" drivers detected...." if not device_exist(): - print "No device, installing...." + logging.info('No device, installing....') status = device_install() if status: if FORCE == 0: @@ -342,11 +490,11 @@ def do_install(): return def do_uninstall(): - print "Checking system...." + logging.info('Checking system....') if not device_exist(): print PROJECT_NAME.upper() +" has no device installed...." else: - print "Removing device...." + logging.info('Removing device....') status = device_uninstall() if status: if FORCE == 0: @@ -355,7 +503,7 @@ def do_uninstall(): if driver_check()== False : print PROJECT_NAME.upper() +" has no driver installed...." else: - print "Removing installed driver...." + logging.info('Removing installed driver....') status = driver_uninstall() if status: if FORCE == 0: