def generate_file(config): """Start to generate board.c :param config: it is a file pointer of board information for writing to """ err_dic = {} print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config) pre_vm_cnt = board_cfg_lib.get_pre_launch_cnt( board_cfg_lib.SCENARIO_INFO_FILE) # read mem size from scenario.xml hpa_size_list = board_cfg_lib.get_sub_leaf_tag( board_cfg_lib.SCENARIO_INFO_FILE, "memory", "size") ret = board_cfg_lib.is_hpa_size(hpa_size_list) if not ret: board_cfg_lib.print_red("Unknow type of host physical address size", err=True) err_dic[ 'board config: generate ve820.c failed'] = "Unknow type of host physical address size" return err_dic hpa_size = hpa_size_list[0] if pre_vm_cnt != 0 and ('0x' in hpa_size or '0X' in hpa_size): err_dic = ve820_per_launch(config, hpa_size) else: non_ve820_pre_launch(config) return err_dic
def generate_file(config): """Start to generate board.c :param config: it is a file pointer of board information for writing to """ err_dic = {} # this dictonary mapped with 'address start':'mem range' ram_range = {} if board_cfg_lib.VM_COUNT in list(VM_NUM_MAP_TOTAL_HV_RAM_SIZE.keys()): hv_ram_size = VM_NUM_MAP_TOTAL_HV_RAM_SIZE[board_cfg_lib.VM_COUNT] else: board_cfg_lib.print_red("VM num should not greater than 8", err=True) err_dic["baord config: total vm number error"] = "VM num should not greater than 8" return err_dic ram_range = get_ram_range() hv_start_addr = get_addr_for_hv(ram_range, hv_ram_size) print('CONFIG_BOARD="{}"'.format(board_cfg_lib.BOARD_NAME), file=config) print("{}".format(DESC), file=config) print("CONFIG_HV_RAM_START={}".format(hv_start_addr), file=config) print("CONFIG_HV_RAM_SIZE={}".format(hv_ram_size), file=config) return err_dic
def generate_file(config): """Start to generate board.c :param config: it is a file pointer of board information for writing to """ err_dic = {} # this dictonary mapped with 'address start':'mem range' ram_range = {} if board_cfg_lib.VM_COUNT in list(VM_NUM_MAP_TOTAL_HV_RAM_SIZE.keys()): hv_ram_size = VM_NUM_MAP_TOTAL_HV_RAM_SIZE[board_cfg_lib.VM_COUNT] else: board_cfg_lib.print_red("VM num should not greater than 8", err=True) err_dic[ "baord config: total vm number error"] = "VM num should not greater than 8" return err_dic ram_range = get_ram_range() # reseve 16M memory for hv sbuf, ramoops, etc. reserved_ram = 0xf00000 total_size = reserved_ram + hv_ram_size avl_start_addr = find_avl_memory(ram_range, str(total_size)) hv_start_addr = int(avl_start_addr, 16) + int(hex(reserved_ram), 16) print('CONFIG_BOARD="{}"'.format(board_cfg_lib.BOARD_NAME), file=config) print("{}".format(DESC), file=config) print("CONFIG_HV_RAM_START={}".format(hex(hv_start_addr)), file=config) print("CONFIG_HV_RAM_SIZE={}".format(hex(hv_ram_size)), file=config) return err_dic
def generate_file(config): """Start to generate board.c :param config: it is a file pointer of board information for writing to """ err_dic = {} # this dictonary mapped with 'address start':'mem range' ram_range = {} if board_cfg_lib.VM_COUNT in list(VM_NUM_MAP_TOTAL_HV_RAM_SIZE.keys()): hv_ram_size = VM_NUM_MAP_TOTAL_HV_RAM_SIZE[board_cfg_lib.VM_COUNT] else: board_cfg_lib.print_red("VM num should not be greater than 8", err=True) err_dic[ "board config: total vm number error"] = "VM num should not be greater than 8" return err_dic ram_range = get_ram_range() # reseve 16M memory for hv sbuf, ramoops, etc. reserved_ram = 0x1000000 # We recommend to put hv ram start address high than 0x10000000 to # reduce memory conflict with GRUB/SOS Kernel. hv_start_offset = 0x10000000 total_size = reserved_ram + hv_ram_size avl_start_addr = find_avl_memory(ram_range, str(total_size), hv_start_offset) hv_start_addr = int(avl_start_addr, 16) + int(hex(reserved_ram), 16) hv_start_addr = board_cfg_lib.round_up(hv_start_addr, MEM_ALIGN) print("{}".format(DESC), file=config) print('CONFIG_BOARD="{}"'.format(board_cfg_lib.BOARD_NAME), file=config) (serial_type, serial_value) = get_serial_type() if serial_type == "portio": print("CONFIG_SERIAL_LEGACY=y", file=config) print("CONFIG_SERIAL_PIO_BASE={}".format(serial_value), file=config) if serial_type == "mmio": print("CONFIG_SERIAL_PCI=y", file=config) print("CONFIG_SERIAL_PCI_BDF={}".format(serial_value), file=config) print("CONFIG_HV_RAM_START={}".format(hex(hv_start_addr)), file=config) print("CONFIG_HV_RAM_SIZE={}".format(hex(hv_ram_size)), file=config) cpu_core_num = len(board_cfg_lib.get_processor_info()) if cpu_core_num == 2: print("# KATA VM is not supported on dual-core systems", file=config) print("CONFIG_MAX_KATA_VM_NUM=0", file=config) if is_rdt_supported(): print("CONFIG_RDT_ENABLED=y", file=config) else: print("CONFIG_RDT_ENABLED=n", file=config) return err_dic
def gen_cat(config): """Get CAT information""" (cache_support, clos_max) = clos_info_parser() print("\n#include <board.h>", file=config) print("#include <acrn_common.h>", file=config) if cache_support == "False" or clos_max == 0: print("\nstruct platform_clos_info platform_clos_array[0];", file=config) print("uint16_t platform_clos_num = 0;", file=config) else: print( "\nstruct platform_clos_info platform_clos_array[{0}] = {{".format( clos_max), file=config) for i_cnt in range(clos_max): print("\t{", file=config) print("\t\t.clos_mask = {0},".format(hex(0xff)), file=config) if cache_support == "L2": print("\t\t.msr_index = MSR_IA32_{0}_MASK_{1},".format( cache_support, i_cnt), file=config) elif cache_support == "L3": print("\t\t.msr_index = {0}U,".format(hex(0x00000C90 + i_cnt)), file=config) else: board_cfg_lib.print_red( "The input of board_info.txt was corrupted!") sys.exit(1) print("\t},", file=config) print("};\n", file=config) print("uint16_t platform_clos_num = ", file=config, end="") print( "(uint16_t)(sizeof(platform_clos_array)/sizeof(struct platform_clos_info));", file=config) print("", file=config)
def prepare(): """Prepare to check the environment""" for excute in BIN_LIST: res = subprocess.Popen("which {}".format(excute), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) line = res.stdout.readline().decode('ascii') if not line: board_cfg_lib.print_yel("'{}' not found, please install it!".format(excute)) sys.exit(1) if excute == "git": res = subprocess.Popen("git tag -l", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) line = res.stdout.readline().decode("ascii") if "acrn" not in line: board_cfg_lib.print_red("Run this tool in acrn-hypervisor mainline source code!") sys.exit(1) for py_cache in PY_CACHES: if os.path.exists(py_cache): shutil.rmtree(py_cache)
def generate_file(config): """Start to generate board.c :param config: it is a file pointer of board information for writing to """ err_dic = {} print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config) pre_vm_cnt = board_cfg_lib.get_pre_launch_cnt( board_cfg_lib.SCENARIO_INFO_FILE) # read mem size from scenario.xml hpa_size_list = board_cfg_lib.get_sub_leaf_tag( board_cfg_lib.SCENARIO_INFO_FILE, "memory", "size") ret = board_cfg_lib.is_hpa_size(hpa_size_list) if not ret: board_cfg_lib.print_red("Unknow type of host physical address size", err=True) err_dic[ 'board config: generate ve820.c failed'] = "Unknow type of host physical address size" return err_dic # read HPA2 mem size from scenario.xml hpa2_size_list = board_cfg_lib.get_sub_leaf_tag( board_cfg_lib.SCENARIO_INFO_FILE, "memory", "size_hpa2") ret = board_cfg_lib.is_hpa_size(hpa2_size_list) if not ret: board_cfg_lib.print_red( "Unknow type of second host physical address size", err=True) err_dic[ 'board config: generate ve820.c failed'] = "Unknow type of second host physical address size" return err_dic # HPA size for both VMs should have valid length. for i in range(pre_vm_cnt): if hpa_size_list[i] == '0x0' or hpa_size_list[i] == '0X0': board_cfg_lib.print_red("HPA size should not be zero", err=True) err_dic[ 'board config: generate ve820.c failed'] = "HPA size should not be zero" return err_dic if pre_vm_cnt != 0: err_dic = ve820_per_launch(config, hpa_size_list, hpa2_size_list) else: non_ve820_pre_launch(config) return err_dic
def ui_entry_api(board_info, scenario_info, enable_commit=False): arg_list = [ 'board_cfg_gen.py', '--board', board_info, '--scenario', scenario_info ] if enable_commit: arg_list.append('--enable_commit') err_dic = board_cfg_lib.prepare() if err_dic: return err_dic err_dic = main(arg_list) return err_dic if __name__ == '__main__': err_dic = board_cfg_lib.prepare() if err_dic: for err_k, err_v in err_dic.items(): board_cfg_lib.print_red("{}: {}".format(err_k, err_v), err=True) sys.exit(1) ARGS = sys.argv err_dic = main(ARGS) if err_dic: for err_k, err_v in err_dic.items(): board_cfg_lib.print_red("{}: {}".format(err_k, err_v), err=True)
print("Config patch for NEW board {} is committed successfully!".format(board)) else: print("Config patch for {} is committed successfully!".format(board)) def usage(): """This is usage for how to use this tool""" print("usage= [h] --board <board_info_file>'") print('board_info_file, : file name of the board info"') sys.exit(1) if __name__ == '__main__': prepare() ARGS = sys.argv[1:] if ARGS[0] != '--board': usage() sys.exit(1) BOARD_INFO_FILE = ARGS[1] if not os.path.exists(BOARD_INFO_FILE): board_cfg_lib.print_red("{} is not exist!".format(BOARD_INFO_FILE)) sys.exit(1) # board_info.txt will be override board_cfg_lib.BOARD_INFO_FILE = BOARD_INFO_FILE main(BOARD_INFO_FILE)