Пример #1
0
def check_serial_state (tries):
    # Read EEPROM as we can have unlimited reads
    # It adds a few seconds to boot up, but makes sure serial is there
    bplane = read_eeprom_serial.backplane()
    if bplane.read_eeprom_content() == FAIL:
        print "Unable to read EEPROM content"
        return FAIL

    # Check if EEPROM present in ID 3
    serial = bplane.get_serial_eeprom()
    if serial == '':
        if set_serial(bplane) == FAIL:
            print "Could not write to the EEPROM"
            tries = int(tries) + 1
            update_attempt_counter(tries)
            return FAIL
        else:
            # Serial updated just create the file and set attempts
            print "Set the serial in the EEPROM"
    else:
        # If the file is ever deleted, create the file since serial is present
        print "Serial %s is already set in the system" % serial
 
    tries = "SET"
    if update_attempt_counter(tries) == FAIL:
        return FAIL

    return PASS
Пример #2
0
def main():
    if len(sys.argv) < 2 or len(sys.argv) > 3:
        usage()
        sys.exit(1)
    elif '--get-serial' == sys.argv[1]:
        bplane = read_eeprom_serial.backplane()
        if bplane.read_eeprom_content():
            sys.exit(1)

        print bplane.get_serial_eeprom()
        
    elif '--set-serial' == sys.argv[1]:
        if len(sys.argv) < 3:
            usage()
            sys.exit(1)
        serial = sys.argv[2]
        bplane = read_eeprom_serial.backplane()
        if bplane.read_eeprom_content():
            sys.exit(1)

        eeprom_ser = bplane.get_serial_eeprom()
        orig_line = bplane.orig_line
        rvbd_sec = bplane.rvbd_sec
        if "" == eeprom_ser:
            set_eeprom_state("RW")
            write_eeprom_content(serial, orig_line, rvbd_sec, False)
            set_eeprom_state("RO")
        elif serial != eeprom_ser:
            set_eeprom_state("RW")
            write_eeprom_content(serial, orig_line, rvbd_sec, True)
            set_eeprom_state("RO")
        else:
            # EEPROM content is fine, move on
            sys.exit(0)
    else:
        usage()
        sys.exit(0)