def _read_mboard_eeprom(self): """ Read out mboard EEPROM. Returns a tuple: (eeprom_dict, eeprom_rawdata), where the the former is a de-serialized dictionary representation of the data, and the latter is a binary string with the raw data. If no EEPROM is defined, returns empty values. """ if len(self.mboard_eeprom_addr): self.log.trace("Reading EEPROM from address `{}'..." .format(self.mboard_eeprom_addr)) if (not get_eeprom_paths(self.mboard_eeprom_addr)): raise RuntimeError("No EEPROM found at address `{}'" .format(self.mboard_eeprom_addr)) (eeprom_head, eeprom_rawdata) = eeprom.read_eeprom( get_eeprom_paths(self.mboard_eeprom_addr)[0], self.mboard_eeprom_offset, eeprom.MboardEEPROM.eeprom_header_format, eeprom.MboardEEPROM.eeprom_header_keys, self.mboard_eeprom_magic, self.mboard_eeprom_max_len, ) self.log.trace("Found EEPROM metadata: `{}'" .format(str(eeprom_head))) self.log.trace("Read {} bytes of EEPROM data." .format(len(eeprom_rawdata))) return eeprom_head, eeprom_rawdata # Nothing defined? Return defaults. self.log.trace("No mboard EEPROM path defined. " "Skipping mboard EEPROM readout.") return {}, b''
def _read_mboard_eeprom(self): """ Read out mboard EEPROM. Returns a tuple: (eeprom_dict, eeprom_rawdata), where the the former is a de-serialized dictionary representation of the data, and the latter is a binary string with the raw data. If no EEPROM is defined, returns empty values. """ if self.mboard_eeprom_addr: self.log.trace("Reading EEPROM from address `{}'...".format( self.mboard_eeprom_addr)) eeprom_paths = get_eeprom_paths(self.mboard_eeprom_addr) if not eeprom_paths: self.log.error("Could not identify EEPROM paths for %s!", self.mboard_eeprom_addr) return {}, b'' self.log.trace("Found mboard EEPROM path: %s", eeprom_paths[0]) (eeprom_head, eeprom_rawdata) = \ self.__class__.mboard_eeprom_reader(eeprom_paths[0]) self.log.trace("Found EEPROM metadata: `{}'".format( str(eeprom_head))) self.log.trace("Read {} bytes of EEPROM data.".format( len(eeprom_rawdata))) return eeprom_head, eeprom_rawdata # Nothing defined? Return defaults. self.log.trace("No mboard EEPROM path defined. " "Skipping mboard EEPROM readout.") return {}, b''
def _get_dboard_eeprom_info(self): """ Read back EEPROM info from the daughterboards """ assert self.dboard_eeprom_addr self.log.trace("Identifying dboard EEPROM paths from `{}'...".format( self.dboard_eeprom_addr)) dboard_eeprom_path = \ get_eeprom_paths(self.dboard_eeprom_addr)[self.dboard_eeprom_path_index] self.log.trace( "Using dboard EEPROM paths: {}".format(dboard_eeprom_path)) self.log.debug("Reading EEPROM info for dboard...") dboard_eeprom_md, dboard_eeprom_rawdata = e31x_legacy_eeprom.read_eeprom( False, # is not motherboard. dboard_eeprom_path, self.dboard_eeprom_offset, e31x_legacy_eeprom.DboardEEPROM.eeprom_header_format, e31x_legacy_eeprom.DboardEEPROM.eeprom_header_keys, self.dboard_eeprom_max_len) self.log.trace("Read %d bytes of dboard EEPROM data.", len(dboard_eeprom_rawdata)) db_pid = dboard_eeprom_md.get('pid') if db_pid is None: self.log.warning("No DB PID found in dboard EEPROM!") else: self.log.debug("Found DB PID in EEPROM: 0x{:04X}".format(db_pid)) return [{ 'eeprom_md': dboard_eeprom_md, 'eeprom_rawdata': dboard_eeprom_rawdata, 'pid': db_pid, }]
def _read_mboard_eeprom(self): """ Read out mboard EEPROM. Returns a tuple: (eeprom_dict, eeprom_rawdata), where the the former is a de-serialized dictionary representation of the data, and the latter is a binary string with the raw data. If no EEPROM is defined, returns empty values. """ eeprom_path = \ get_eeprom_paths(self.mboard_eeprom_addr)[self.mboard_eeprom_path_index] if not eeprom_path: self.log.error("Could not identify EEPROM path for %s!", self.mboard_eeprom_addr) return {}, b'' self.log.trace("MB EEPROM: Using path {}".format(eeprom_path)) (eeprom_head, eeprom_rawdata) = e31x_legacy_eeprom.read_eeprom( True, # is_motherboard eeprom_path, self.mboard_eeprom_offset, e31x_legacy_eeprom.MboardEEPROM.eeprom_header_format, e31x_legacy_eeprom.MboardEEPROM.eeprom_header_keys, self.mboard_eeprom_max_len) self.log.trace("Read %d bytes of EEPROM data.", len(eeprom_rawdata)) return eeprom_head, eeprom_rawdata
def _read_mboard_eeprom(self): """ Read out mboard EEPROM. Returns a tuple: (eeprom_dict, eeprom_rawdata), where the the former is a de-serialized dictionary representation of the data, and the latter is a binary string with the raw data. If no EEPROM is defined, returns empty values. """ if len(self.mboard_eeprom_addr): self.log.trace("Reading EEPROM from address `{}'..." .format(self.mboard_eeprom_addr)) (eeprom_head, eeprom_rawdata) = eeprom.read_eeprom( get_eeprom_paths(self.mboard_eeprom_addr)[0], self.mboard_eeprom_offset, eeprom.MboardEEPROM.eeprom_header_format, eeprom.MboardEEPROM.eeprom_header_keys, self.mboard_eeprom_magic, self.mboard_eeprom_max_len, ) self.log.trace("Found EEPROM metadata: `{}'" .format(str(eeprom_head))) self.log.trace("Read {} bytes of EEPROM data." .format(len(eeprom_rawdata))) return eeprom_head, eeprom_rawdata # Nothing defined? Return defaults. self.log.trace("No mboard EEPROM path defined. " "Skipping mboard EEPROM readout.") return {}, b''
def _read_mboard_eeprom(self): """ Read out mboard EEPROM. Returns a tuple: (eeprom_dict, eeprom_rawdata), where the the former is a de-serialized dictionary representation of the data, and the latter is a binary string with the raw data. If no EEPROM is defined, returns empty values. """ if len(self.mboard_eeprom_addr): (eeprom_head, eeprom_rawdata) = e31x_legacy_eeprom.read_eeprom( True, # isMotherboard get_eeprom_paths(self.mboard_eeprom_addr)[self.mboard_eeprom_path_index], self.mboard_eeprom_offset, e31x_legacy_eeprom.MboardEEPROM.eeprom_header_format, e31x_legacy_eeprom.MboardEEPROM.eeprom_header_keys, self.mboard_eeprom_max_len ) self.log.trace("Found EEPROM metadata: `{}'" .format(str(eeprom_head))) self.log.trace("Read {} bytes of EEPROM data." .format(len(eeprom_rawdata))) return eeprom_head, eeprom_rawdata # Nothing defined? Return defaults. self.log.trace("No mboard EEPROM path defined. " "Skipping mboard EEPROM readout.") return {}, b''
def _init_mboard_with_eeprom(self): """ Starts the device initialization. Typically requires reading from an EEPROM. """ if len(self.mboard_eeprom_addr): self.log.trace("Reading EEPROM from address `{}'...".format( self.mboard_eeprom_addr)) (self._eeprom_head, self._eeprom_rawdata) = eeprom.read_eeprom( get_eeprom_paths(self.mboard_eeprom_addr)[0], eeprom.MboardEEPROM.eeprom_header_format, eeprom.MboardEEPROM.eeprom_header_keys, self.mboard_eeprom_magic, self.mboard_eeprom_max_len, ) self.log.trace("Found EEPROM metadata: `{}'".format( str(self._eeprom_head))) self.log.trace("Read {} bytes of EEPROM data.".format( len(self._eeprom_rawdata))) for key in ('pid', 'serial', 'rev', 'eeprom_version'): # In C++, we can only handle dicts if all the values are of the # same type. So we must convert them all to strings here: try: self.mboard_info[key] = str(self._eeprom_head.get(key, ''), 'ascii') except TypeError: self.mboard_info[key] = str(self._eeprom_head.get(key, '')) if 'pid' in self._eeprom_head \ and self._eeprom_head['pid'] not in self.pids: self.log.error( "Found invalid PID in EEPROM: 0x{:04X}. " \ "Valid PIDs are: {}".format( self._eeprom_head['pid'], ", ".join(["0x{:04X}".format(x) for x in self.pids]), ) ) raise RuntimeError("Invalid PID found in EEPROM.") if 'rev' in self._eeprom_head: try: rev_numeric = int(self._eeprom_head.get('rev')) except (ValueError, TypeError): raise RuntimeError( "Invalid revision info read from EEPROM!") if self.mboard_max_rev is not None \ and rev_numeric > self.mboard_max_rev: raise RuntimeError( "Device has revision `{}', but max supported " \ "revision is `{}'".format( rev_numeric, self.mboard_max_rev )) else: raise RuntimeError("No revision found in EEPROM.") else: self.log.trace("No EEPROM address to read from.") self._eeprom_head = {} self._eeprom_rawdata = '' self.log.info("Device serial number: {}".format( self.mboard_info.get('serial', 'n/a')))
def _get_dboard_eeprom_info(self): """ Read back EEPROM info from the daughterboards """ if self.dboard_eeprom_addr is None: self.log.debug("No dboard EEPROM addresses given.") return [] dboard_eeprom_addrs = self.dboard_eeprom_addr \ if isinstance(self.dboard_eeprom_addr, list) \ else [self.dboard_eeprom_addr] dboard_eeprom_paths = [] self.log.trace( "Identifying dboard EEPROM paths from addrs `{}'...".format( ",".join(dboard_eeprom_addrs))) for dboard_eeprom_addr in dboard_eeprom_addrs: self.log.trace("Resolving %s...", dboard_eeprom_addr) dboard_eeprom_paths += get_eeprom_paths(dboard_eeprom_addr) self.log.trace("Found dboard EEPROM paths: {}".format( ",".join(dboard_eeprom_paths))) if len(dboard_eeprom_paths) > self.max_num_dboards: self.log.warning("Found more EEPROM paths than daughterboards. " "Ignoring some of them.") dboard_eeprom_paths = dboard_eeprom_paths[:self.max_num_dboards] dboard_info = [] for dboard_idx, dboard_eeprom_path in enumerate(dboard_eeprom_paths): self.log.debug("Reading EEPROM info for dboard %d...", dboard_idx) dboard_eeprom_md, dboard_eeprom_rawdata = eeprom.read_eeprom( dboard_eeprom_path, self.dboard_eeprom_offset, eeprom.DboardEEPROM.eeprom_header_format, eeprom.DboardEEPROM.eeprom_header_keys, self.dboard_eeprom_magic, self.dboard_eeprom_max_len, ) self.log.trace("Found dboard EEPROM metadata: `{}'".format( str(dboard_eeprom_md))) self.log.trace("Read %d bytes of dboard EEPROM data.", len(dboard_eeprom_rawdata)) db_pid = dboard_eeprom_md.get('pid') if db_pid is None: self.log.warning("No dboard PID found in dboard EEPROM!") else: self.log.debug( "Found dboard PID in EEPROM: 0x{:04X}".format(db_pid)) dboard_info.append({ 'eeprom_md': dboard_eeprom_md, 'eeprom_rawdata': dboard_eeprom_rawdata, 'pid': db_pid, }) return dboard_info
def _get_dboard_eeprom_info(self): """ Read back EEPROM info from the daughterboards """ if self.dboard_eeprom_addr is None: self.log.debug("No dboard EEPROM addresses given.") return [] dboard_eeprom_addrs = self.dboard_eeprom_addr \ if isinstance(self.dboard_eeprom_addr, list) \ else [self.dboard_eeprom_addr] dboard_eeprom_paths = [] self.log.trace("Identifying dboard EEPROM paths from addrs `{}'..." .format(",".join(dboard_eeprom_addrs))) for dboard_eeprom_addr in dboard_eeprom_addrs: self.log.trace("Resolving %s...", dboard_eeprom_addr) dboard_eeprom_paths += get_eeprom_paths(dboard_eeprom_addr) self.log.trace("Found dboard EEPROM paths: {}" .format(",".join(dboard_eeprom_paths))) if len(dboard_eeprom_paths) > self.max_num_dboards: self.log.warning("Found more EEPROM paths than daughterboards. " "Ignoring some of them.") dboard_eeprom_paths = dboard_eeprom_paths[:self.max_num_dboards] dboard_info = [] for dboard_idx, dboard_eeprom_path in enumerate(dboard_eeprom_paths): self.log.debug("Reading EEPROM info for dboard %d...", dboard_idx) dboard_eeprom_md, dboard_eeprom_rawdata = eeprom.read_eeprom( dboard_eeprom_path, self.dboard_eeprom_offset, eeprom.DboardEEPROM.eeprom_header_format, eeprom.DboardEEPROM.eeprom_header_keys, self.dboard_eeprom_magic, self.dboard_eeprom_max_len, ) self.log.trace("Found dboard EEPROM metadata: `{}'" .format(str(dboard_eeprom_md))) self.log.trace("Read %d bytes of dboard EEPROM data.", len(dboard_eeprom_rawdata)) db_pid = dboard_eeprom_md.get('pid') if db_pid is None: self.log.warning("No dboard PID found in dboard EEPROM!") else: self.log.debug("Found dboard PID in EEPROM: 0x{:04X}" .format(db_pid)) dboard_info.append({ 'eeprom_md': dboard_eeprom_md, 'eeprom_rawdata': dboard_eeprom_rawdata, 'pid': db_pid, }) return dboard_info
def _init_user_eeprom(self, eeprom_info): """ Reads out user-data EEPROM, and intializes a BufferFS object from that. """ self.log.trace("Initializing EEPROM user data...") eeprom_paths = get_eeprom_paths(eeprom_info.get('label')) self.log.trace( "Found the following EEPROM paths: `{}'".format(eeprom_paths)) eeprom_path = eeprom_paths[self.slot_idx] self.log.trace("Selected EEPROM path: `{}'".format(eeprom_path)) user_eeprom_offset = eeprom_info.get('offset', 0) self.log.trace("Selected EEPROM offset: %d", user_eeprom_offset) user_eeprom_data = open(eeprom_path, 'rb').read()[user_eeprom_offset:] self.log.trace("Total EEPROM size is: %d bytes", len(user_eeprom_data)) return BufferFS(user_eeprom_data, max_size=eeprom_info.get('max_size'), alignment=eeprom_info.get('alignment', 1024), log=self.log), eeprom_path
def _init_user_eeprom(self, eeprom_info): """ Reads out user-data EEPROM, and intializes a BufferFS object from that. """ self.log.trace("Initializing EEPROM user data...") eeprom_paths = get_eeprom_paths(eeprom_info.get('label')) self.log.trace("Found the following EEPROM paths: `{}'".format( eeprom_paths)) eeprom_path = eeprom_paths[self.slot_idx] self.log.trace("Selected EEPROM path: `{}'".format(eeprom_path)) user_eeprom_offset = eeprom_info.get('offset', 0) self.log.trace("Selected EEPROM offset: %d", user_eeprom_offset) user_eeprom_data = open(eeprom_path, 'rb').read()[user_eeprom_offset:] self.log.trace("Total EEPROM size is: %d bytes", len(user_eeprom_data)) return BufferFS( user_eeprom_data, max_size=eeprom_info.get('max_size'), alignment=eeprom_info.get('alignment', 1024), log=self.log ), eeprom_path
def _init_dboards(self, override_dboard_pids, default_args): """ Initialize all the daughterboards """ # Go, go, go! override_dboard_pids = override_dboard_pids or [] if override_dboard_pids: self.log.warning("Overriding daughterboard PIDs with: {}".format( override_dboard_pids)) dboard_eeprom_addrs = self.dboard_eeprom_addr \ if isinstance(self.dboard_eeprom_addr, list) \ else [self.dboard_eeprom_addr] dboard_eeprom_paths = [] self.log.trace( "Identifying dboard EEPROM paths from addrs `{}'...".format( ",".join(dboard_eeprom_addrs))) for dboard_eeprom_addr in dboard_eeprom_addrs: self.log.trace("Resolving %s...", dboard_eeprom_addr) dboard_eeprom_paths += get_eeprom_paths(dboard_eeprom_addr) self.log.trace("Found dboard EEPROM paths: {}".format( ",".join(dboard_eeprom_paths))) if len(dboard_eeprom_paths) > self.max_num_dboards: self.log.warning("Found more EEPROM paths than daughterboards. " "Ignoring some of them.") dboard_eeprom_paths = dboard_eeprom_paths[:self.max_num_dboards] if len(override_dboard_pids) and \ len(override_dboard_pids) < len(dboard_eeprom_paths): self.log.warning("--override-db-pids is going to skip dboards.") dboard_eeprom_paths = \ dboard_eeprom_paths[:len(override_dboard_pids)] for dboard_idx, dboard_eeprom_path in enumerate(dboard_eeprom_paths): self.log.debug("Initializing dboard %d...", dboard_idx) dboard_eeprom_md, dboard_eeprom_rawdata = eeprom.read_eeprom( dboard_eeprom_path, eeprom.DboardEEPROM.eeprom_header_format, eeprom.DboardEEPROM.eeprom_header_keys, self.dboard_eeprom_magic, self.dboard_eeprom_max_len, ) self.log.trace("Found dboard EEPROM metadata: `{}'".format( str(dboard_eeprom_md))) self.log.trace("Read %d bytes of dboard EEPROM data.", len(dboard_eeprom_rawdata)) if len(override_dboard_pids) > dboard_idx: db_pid = override_dboard_pids[dboard_idx] self.log.warning("Overriding dboard PID for dboard {} " "with 0x{:04X}.".format(dboard_idx, db_pid)) else: db_pid = dboard_eeprom_md.get('pid') if db_pid is None: self.log.warning("No dboard PID found in dboard EEPROM!") else: self.log.debug( "Found dboard PID in EEPROM: 0x{:04X}".format(db_pid)) db_class = get_dboard_class_from_pid(db_pid) if db_class is None: self.log.warning("Could not identify daughterboard class " "for PID {:04X}!".format(db_pid)) continue if len(self.dboard_spimaster_addrs) > dboard_idx: spi_nodes = sorted( get_spidev_nodes(self.dboard_spimaster_addrs[dboard_idx])) self.log.trace("Found spidev nodes: {0}".format(spi_nodes)) else: spi_nodes = [] self.log.warning("No SPI nodes for dboard %d.", dboard_idx) dboard_info = { 'eeprom_md': dboard_eeprom_md, 'eeprom_rawdata': dboard_eeprom_rawdata, 'pid': db_pid, 'spi_nodes': spi_nodes, 'default_args': default_args, } # This will actually instantiate the dboard class: self.dboards.append(db_class(dboard_idx, **dboard_info)) self.log.info("Found %d daughterboard(s).", len(self.dboards))