1# This file consists of the common useful functions for eFuse 2# 3# SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD 4# 5# SPDX-License-Identifier: GPL-2.0-or-later 6 7import esptool 8 9 10def hexify(bitstring, separator=""): 11 as_bytes = tuple(b for b in bitstring) 12 return separator.join(("%02x" % b) for b in as_bytes) 13 14 15def popcnt(b): 16 """Return number of "1" bits set in 'b'""" 17 return len([x for x in bin(b) if x == "1"]) 18 19 20def check_duplicate_name_in_list(name_list): 21 duples_name = [name for i, name in enumerate(name_list) if name in name_list[:i]] 22 if duples_name != []: 23 raise esptool.FatalError( 24 "Found repeated {} in the name list".format(duples_name) 25 ) 26 27 28class SdkConfig(object): 29 def __init__(self, path_to_file): 30 self.sdkconfig = dict() 31 if path_to_file is None: 32 return 33 with open(path_to_file, "r") as file: 34 for line in file.readlines(): 35 if line.startswith("#"): 36 continue 37 config = line.strip().split("=", 1) 38 if len(config) == 2: 39 self.sdkconfig[config[0]] = ( 40 True if config[1] == "y" else config[1].strip('"') 41 ) 42 43 def __getitem__(self, config_name): 44 try: 45 return self.sdkconfig[config_name] 46 except KeyError: 47 return False 48