def get_board_props(board_name=None): if not board_name: board_name = get_rpi_model() cpu_profile = get_board_property(board_name, 'cpu_profile') if not cpu_profile: cpu_profile = RPI_1_CPU_PROFILE board_module = re.sub(r'[-/ ]', '_', cpu_profile).lower() try: board = importlib.import_module( '{}.{}'.format(__name__, board_module) ) except ImportError: logger.error('Board not found') return None required_props = ['CLOCKING', 'DEFAULT_CONFIG'] for prop in required_props: if not hasattr(board, prop): logger.error('No {} data in board config' .format(prop.replace('_', ' ').lower())) return None # TODO: Validate board info return board
def get_board_props(board_name=None): if not board_name: board_name = get_rpi_model() cpu_profile = get_board_property(board_name, 'cpu_profile') if not cpu_profile: cpu_profile = RPI_1_CPU_PROFILE board_module = re.sub(r'[-/ ]', '_', cpu_profile).lower() try: board = importlib.import_module('{}.{}'.format(__name__, board_module)) except ImportError: logger.error('Board not found') return None required_props = ['CLOCKING', 'DEFAULT_CONFIG'] for prop in required_props: if not hasattr(board, prop): logger.error('No {} data in board config'.format( prop.replace('_', ' ').lower())) return None # TODO: Validate board info return board
def test_board_property(board, board_property): from kano.utils.hardware import get_board_property prop_val = get_board_property(board.key, board_property.property) if board.is_valid: if board_property.is_valid: assert prop_val == getattr(board, board_property.property) else: assert prop_val is None else: assert prop_val is None
def get_matching_board_profile(): curr = {} for key in CLOCK_KEYS: curr[key] = get_config_value(key) def does_board_match(board): values = board.CLOCKING['values'] for oc_setting in values.itervalues(): if values_equal(oc_setting, curr): return True return False for board_key in BOARD_PROPERTIES.iterkeys(): board_props = get_board_props(board_key) if does_board_match(board_props): logger.debug("Matched the board {} with the current settings" .format(board_key)) return get_board_property(board_key, 'cpu_profile') return False
def check_clock_config_matches_chip(): """ Check if the clock setting in the current config is supported on the chip we have booted on. If not, try to restore from a backup file. If that is not possible, set to a default appropraite to this chip. """ current_model = get_rpi_model() current_model_profile = get_board_property(current_model, 'cpu_profile') if current_model_profile is None: logger.error("Unknown pi model {}, not messing with config.txt", current_model) return False old_model_profile = overclock.get_matching_board_profile() logger.debug("Checked the two boards, the old one is {} type " \ "and the new one is {} type" .format(old_model_profile, current_model_profile)) if current_model_profile == old_model_profile: # Config looks good return False new_config = BootConfig.new_from_model(current_model) if old_model_profile: logger.info("Config settings match for {} but running {}. " "Backing up old settings and restoring new settings" .format(old_model_profile, current_model_profile)) old_config = BootConfig.new_from_model(old_model_profile) overclock.backup_overclock_values(old_config) restore_config(new_config, current_model) return True # we need to reboot if we get here
def get_matching_board_profile(): curr = {} for key in CLOCK_KEYS: curr[key] = get_config_value(key) def does_board_match(board): values = board.CLOCKING['values'] for oc_setting in values.itervalues(): if values_equal(oc_setting, curr): return True return False for board_key in BOARD_PROPERTIES.iterkeys(): board_props = get_board_props(board_key) if does_board_match(board_props): logger.debug( "Matched the board {} with the current settings".format( board_key)) return get_board_property(board_key, 'cpu_profile') return False
def get_model_name(): model = get_rpi_model() model_name = get_board_property(model, 'name') return model_name