def find_p2sb_bar_addr(): if not is_matched_board(('ehl-crb-b')): common.print_red('find_p2sb_bar_addr() can only be called for board ehl-crb-b', err=True) sys.exit(1) iomem_lines = get_info(common.BOARD_INFO_FILE, "<IOMEM_INFO>", "</IOMEM_INFO>") for line in iomem_lines: if 'INTC1020:' in line: start_addr = int(line.split('-')[0], 16) & 0xFF000000 return start_addr common.print_red('p2sb device is not found in board file %s!\n' % common.BOARD_INFO_FILE, err=True) sys.exit(1)
def get_memory(hv_info, config): # this dictonary mapped with 'address start':'mem range' ram_range = {} if common.VM_COUNT in list(VM_NUM_MAP_TOTAL_HV_RAM_SIZE.keys()): hv_ram_size = VM_NUM_MAP_TOTAL_HV_RAM_SIZE[common.VM_COUNT] else: common.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 = common.round_up(hv_start_addr, MEM_ALIGN) if not hv_info.mem.hv_ram_start: print("CONFIG_HV_RAM_START={}".format(hex(hv_start_addr)), file=config) else: print("CONFIG_HV_RAM_START={}".format(hv_info.mem.hv_ram_start), file=config) if not hv_info.mem.hv_ram_size: print("CONFIG_HV_RAM_SIZE={}".format(hex(hv_ram_size)), file=config) else: print("CONFIG_HV_RAM_SIZE={}".format(hv_info.mem.hv_ram_size), file=config) print("CONFIG_PLATFORM_RAM_SIZE={}".format(hv_info.mem.platform_ram_size), file=config) print("CONFIG_LOW_RAM_SIZE={}".format(hv_info.mem.low_ram_size), file=config) print("CONFIG_SOS_RAM_SIZE={}".format(hv_info.mem.sos_ram_size), file=config) print("CONFIG_UOS_RAM_SIZE={}".format(hv_info.mem.uos_ram_size), file=config) print("CONFIG_STACK_SIZE={}".format(hv_info.mem.stack_size), file=config)
def main(args): """ This is main function to start generate source code related with board :param args: it is a command line args for the script """ err_dic = {} (err_dic, params) = common.get_param(args) if err_dic: return err_dic # check env err_dic = common.prepare() if err_dic: return err_dic common.BOARD_INFO_FILE = params['--board'] common.SCENARIO_INFO_FILE = params['--scenario'] common.get_vm_num(params['--scenario']) common.get_vm_types() # get board name (err_dic, board_name) = common.get_board_name() # get scenario name (err_dic, scenario) = common.get_scenario_name() if err_dic: return err_dic if common.VM_COUNT > common.MAX_VM_NUM: err_dic[ 'vm count'] = "The vm count in config xml should be less or equal {}!".format( common.MAX_VM_NUM) return err_dic # check if this is the scenario config which matched board info (err_dic, status) = common.is_config_file_match() if not status: err_dic[ 'scenario config'] = "The board xml and scenario xml should be matched!" return err_dic if params['--out']: if os.path.isabs(params['--out']): scenario_dir = os.path.join(params['--out'], scenario + '/') config_hv = os.path.join(params['--out'], board_name + GEN_FILE[3]) else: scenario_dir = os.path.join(ACRN_PATH + params['--out'], scenario + '/') config_hv = os.path.join(ACRN_PATH + params['--out'], board_name + GEN_FILE[3]) else: scenario_dir = os.path.join(ACRN_CONFIG_DEF, scenario + '/') config_hv = os.path.join(ACRN_CONFIGS, board_name + GEN_FILE[3]) common.print_yel("{}".format("Override board defconfig...", warn=True)) common.mkdir(scenario_dir) vm_config_h = scenario_dir + GEN_FILE[0] vm_config_c = scenario_dir + GEN_FILE[1] pci_config_c = scenario_dir + GEN_FILE[2] # parse the scenario.xml get_scenario_item_values(params['--board'], params['--scenario']) (err_dic, scenario_items) = validate_scenario_setting(params['--board'], params['--scenario']) if err_dic: common.print_red("Validate the scenario item failure", err=True) return err_dic # generate board defconfig with open(config_hv, 'w+') as config: err_dic = board_defconfig.generate_file(scenario_items['hv'], config) if err_dic: return err_dic # generate vm_configuration.h with open(vm_config_h, 'w') as config: vm_configurations_h.generate_file(scenario_items, config) # generate vm_configuration.c with open(vm_config_c, 'w') as config: err_dic = vm_configurations_c.generate_file(scenario_items['vm'], config) if err_dic: return err_dic # generate pci_dev.c for vm_i, pci_dev_num in scenario_items['vm'].cfg_pci.pci_dev_num.items(): if pci_dev_num >= 2: with open(pci_config_c, 'w') as config: pci_dev_c.generate_file(scenario_items['vm'], config) break if not err_dic: print( "Scenario configurations for {} is generated successfully.".format( scenario)) else: print("Scenario configurations for {} is generated failed.".format( scenario)) return err_dic
else: print("Scenario configurations for {} is generated failed.".format( scenario)) return err_dic def ui_entry_api(board_info, scenario_info, out=''): arg_list = [ 'board_cfg_gen.py', '--board', board_info, '--scenario', scenario_info, '--out', out ] err_dic = common.prepare() if err_dic: return err_dic err_dic = main(arg_list) return err_dic if __name__ == '__main__': ARGS = sys.argv err_dic = main(ARGS) if err_dic: for err_k, err_v in err_dic.items(): common.print_red("{}: {}".format(err_k, err_v), err=True)
def main(args): """ Generate board related source code :param args: command line args """ err_dic = {} (err_dic, params) = common.get_param(args) if err_dic: return err_dic # check env err_dic = common.prepare() if err_dic: return err_dic common.BOARD_INFO_FILE = params['--board'] common.SCENARIO_INFO_FILE = params['--scenario'] common.get_vm_num(params['--scenario']) common.get_vm_types() # get board name (err_dic, board_name) = common.get_board_name() # get scenario name (err_dic, scenario) = common.get_scenario_name() if err_dic: return err_dic if common.VM_COUNT > common.MAX_VM_NUM: err_dic[ 'vm count'] = "Number of VMs in scenario xml file should be no greater than {}!".format( common.MAX_VM_NUM) return err_dic # check if this is the scenario config which matches board info (err_dic, status) = common.is_config_file_match() if not status: err_dic[ 'scenario config'] = "The board xml file does not match scenario xml file!" return err_dic if params['--out']: if os.path.isabs(params['--out']): scen_output = params['--out'] + "/scenarios/" + scenario + "/" else: scen_output = ACRN_PATH + params[ '--out'] + "/scenarios/" + scenario + "/" else: scen_output = ACRN_CONFIG_DEF + "/" + scenario + "/" scen_board = scen_output + board_name + "/" common.mkdir(scen_board) common.mkdir(scen_output) vm_config_h = scen_output + GEN_FILE[0] vm_config_c = scen_output + GEN_FILE[1] pci_config_c = scen_board + GEN_FILE[2] config_hv = scen_board + board_name + GEN_FILE[3] ivshmem_config_h = scen_board + GEN_FILE[4] pt_intx_config_c = scen_board + GEN_FILE[5] # parse the scenario.xml get_scenario_item_values(params['--board'], params['--scenario']) (err_dic, scenario_items) = validate_scenario_setting(params['--board'], params['--scenario']) if err_dic: common.print_red("Scenario xml file validation failed:", err=True) return err_dic # generate board defconfig with open(config_hv, 'w+') as config: err_dic = board_defconfig.generate_file(scenario_items['hv'], config) if err_dic: return err_dic # generate vm_configuration.h with open(vm_config_h, 'w') as config: vm_configurations_h.generate_file(scenario_items, config) # generate vm_configuration.c with open(vm_config_c, 'w') as config: err_dic = vm_configurations_c.generate_file(scenario_items, config) if err_dic: return err_dic # generate ivshmem_cfg.h with open(ivshmem_config_h, 'w') as config: ivshmem_cfg_h.generate_file(scenario_items, config) # generate pci_dev.c with open(pci_config_c, 'w') as config: pci_dev_c.generate_file(scenario_items['vm'], config) # generate pt_intx.c with open(pt_intx_config_c, 'w') as config: pt_intx_c.generate_file(scenario_items['vm'], config) # generate ASL code of ACPI tables for Pre-launched VMs asl_gen.main(args) if not err_dic: print("Scenario configuration files were created successfully.") else: print("Failed to create scenario configuration files.") return err_dic
def get_memory(hv_info, config): # this dictonary mapped with 'address start':'mem range' ram_range = {} if common.VM_COUNT in list(VM_NUM_MAP_TOTAL_HV_RAM_SIZE.keys()): hv_ram_size = VM_NUM_MAP_TOTAL_HV_RAM_SIZE[common.VM_COUNT] else: common.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 ivshmem_enabled = common.get_hv_item_tag(common.SCENARIO_INFO_FILE, "FEATURES", "IVSHMEM", "IVSHMEM_ENABLED") total_shm_size = 0 if ivshmem_enabled == 'y': raw_shmem_regions = common.get_hv_item_tag(common.SCENARIO_INFO_FILE, "FEATURES", "IVSHMEM", "IVSHMEM_REGION") for raw_shm in raw_shmem_regions: if raw_shm is None or raw_shm.strip() == '': continue raw_shm_splited = raw_shm.split(',') if len(raw_shm_splited) == 3 and raw_shm_splited[0].strip() != '' \ and raw_shm_splited[1].strip() != '' and len(raw_shm_splited[2].strip().split(':')) >= 1: try: size = raw_shm_splited[1].strip() int_size = int(size) * 0x100000 total_shm_size += int_size except Exception as e: print(e) hv_ram_size += total_shm_size if hv_ram_size > HV_RAM_SIZE_MAX: common.print_red("requested RAM size should be smaller then {}".format( HV_RAM_SIZE_MAX), err=True) err_dic["board config: total vm number error"] = \ "requested RAM size should be smaller then {}".format(HV_RAM_SIZE_MAX) return err_dic # 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 for start_addr in list(board_cfg_lib.USED_RAM_RANGE): if hv_start_offset <= start_addr < 0x80000000: del board_cfg_lib.USED_RAM_RANGE[start_addr] ram_range = board_cfg_lib.get_ram_range() avl_start_addr = board_cfg_lib.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 = common.round_up(hv_start_addr, MEM_ALIGN) board_cfg_lib.USED_RAM_RANGE[hv_start_addr] = total_size if not hv_info.mem.hv_ram_start: print("CONFIG_HV_RAM_START={}".format(hex(hv_start_addr)), file=config) else: print("CONFIG_HV_RAM_START={}".format(hv_info.mem.hv_ram_start), file=config) if not hv_info.mem.hv_ram_size: print("CONFIG_HV_RAM_SIZE={}".format(hex(hv_ram_size)), file=config) else: print("CONFIG_HV_RAM_SIZE={}".format(hv_info.mem.hv_ram_size), file=config) print("CONFIG_PLATFORM_RAM_SIZE={}".format(hv_info.mem.platform_ram_size), file=config) print("CONFIG_LOW_RAM_SIZE={}".format(hv_info.mem.low_ram_size), file=config) print("CONFIG_SOS_RAM_SIZE={}".format(hv_info.mem.sos_ram_size), file=config) print("CONFIG_UOS_RAM_SIZE={}".format(hv_info.mem.uos_ram_size), file=config) print("CONFIG_STACK_SIZE={}".format(hv_info.mem.stack_size), file=config) print("CONFIG_IVSHMEM_ENABLED={}".format(hv_info.mem.ivshmem_enable), file=config)
def main(args): """ This is main function to start generate source code related with board :param args: it is a command line args for the script """ err_dic = {} (err_dic, board_info_file, scenario_info_file, output_folder) = common.get_param(args) if err_dic: return err_dic if output_folder: common.ACRN_CONFIG_TARGET = os.path.abspath(output_folder) + '/' # check env err_dic = common.prepare() if err_dic: return err_dic common.BOARD_INFO_FILE = board_info_file common.SCENARIO_INFO_FILE = scenario_info_file # get scenario name (err_dic, scenario) = common.get_scenario_name() if err_dic: return err_dic # check if this is the scenario config which matched board info (err_dic, status) = common.is_config_file_match() if not status: err_dic[ 'scenario config: Not match'] = "The board xml and scenario xml should be matched!" return err_dic if common.ACRN_CONFIG_TARGET: scenario_dir = common.ACRN_CONFIG_TARGET + scenario + '/' else: scenario_dir = ACRN_CONFIG_DEF + scenario + '/' common.mkdir(scenario_dir) vm_config_h = scenario_dir + GEN_FILE[0] vm_config_c = scenario_dir + GEN_FILE[1] pci_config_c = scenario_dir + GEN_FILE[2] # parse the scenario.xml get_scenario_item_values(board_info_file, scenario_info_file) (err_dic, vm_info) = validate_scenario_setting(board_info_file, scenario_info_file) if err_dic: common.print_red("Validate the scenario item failue", err=True) return err_dic # get kata vm count if scenario != "logical_partition": scenario_cfg_lib.KATA_VM_COUNT = common.VM_COUNT - scenario_cfg_lib.DEFAULT_VM_COUNT[ scenario] if scenario_cfg_lib.KATA_VM_COUNT > 1: err_dic[ 'scenario config: kata vm count err'] = "Only one kata vm is supported!" return err_dic # generate vm_configuration.h with open(vm_config_h, 'w') as config: vm_configurations_h.generate_file(scenario, vm_info, config) # generate vm_configuration.c with open(vm_config_c, 'w') as config: err_dic = vm_configurations_c.generate_file(scenario, vm_info, config) if err_dic: return err_dic # generate pci_dev.c if scenario is logical_partition if scenario == 'logical_partition': with open(pci_config_c, 'w') as config: pci_dev_c.generate_file(config) if not err_dic: print( "Scenario configurations for {} is generated successfully.".format( scenario)) else: print("Scenario configurations for {} is generated failed.".format( scenario)) return err_dic
def main(args): """ Generate board related source code :param args: command line args """ err_dic = {} (err_dic, params) = common.get_param(args) if err_dic: return err_dic # check env err_dic = common.prepare() if err_dic: return err_dic common.BOARD_INFO_FILE = params['--board'] common.SCENARIO_INFO_FILE = params['--scenario'] common.get_vm_num(params['--scenario']) common.get_load_order() # get board name (err_dic, board_name) = common.get_board_name() # get scenario name (err_dic, scenario) = common.get_scenario_name() if err_dic: return err_dic if common.VM_COUNT > common.MAX_VM_NUM: err_dic['vm count'] = "Number of VMs in scenario xml file should be no greater than hv/CAPACITIES/MAX_VM_NUM ! " \ "Now this value is {}.".format(common.MAX_VM_NUM) return err_dic if params['--out']: if os.path.isabs(params['--out']): scen_output = params['--out'] + "/scenarios/" + scenario + "/" else: scen_output = ACRN_PATH + params[ '--out'] + "/scenarios/" + scenario + "/" else: scen_output = ACRN_CONFIG_DEF + "/" + scenario + "/" scen_board = scen_output + "/" common.mkdir(scen_board) common.mkdir(scen_output) vm_config_h = scen_output + GEN_FILE[0] vm_config_c = scen_output + GEN_FILE[1] pci_config_c = scen_board + GEN_FILE[2] config_hv = scen_board + board_name + GEN_FILE[3] ivshmem_config_h = scen_board + GEN_FILE[4] pt_intx_config_c = scen_board + GEN_FILE[5] # parse the scenario.xml get_scenario_item_values(params['--board'], params['--scenario']) (err_dic, scenario_items) = validate_scenario_setting(params['--board'], params['--scenario']) if err_dic: common.print_red("Scenario xml file validation failed:", err=True) return err_dic # generate board defconfig with open(config_hv, 'w+') as config: err_dic = board_defconfig.generate_file(scenario_items['hv'], config) if err_dic: return err_dic # generate ASL code of ACPI tables for Pre-launched VMs if not err_dic: err_dic = asl_gen.main(args) if not err_dic: print("Scenario configuration files were created successfully.") else: print("Failed to create scenario configuration files.") return err_dic
def get_memory(hv_info, config): # this dictonary mapped with 'address start':'mem range' ram_range = {} post_launched_vm_num = 0 for id in common.VM_TYPES: if common.VM_TYPES[id] in scenario_cfg_lib.VM_DB and \ scenario_cfg_lib.VM_DB[common.VM_TYPES[id]]["load_type"] == "POST_LAUNCHED_VM": post_launched_vm_num += 1 hv_ram_size = common.HV_BASE_RAM_SIZE + common.POST_LAUNCHED_VM_RAM_SIZE * post_launched_vm_num ivshmem_enabled = common.get_hv_item_tag(common.SCENARIO_INFO_FILE, "FEATURES", "IVSHMEM", "IVSHMEM_ENABLED") total_shm_size = 0 if ivshmem_enabled == 'y': raw_shmem_regions = common.get_hv_item_tag(common.SCENARIO_INFO_FILE, "FEATURES", "IVSHMEM", "IVSHMEM_REGION") for raw_shm in raw_shmem_regions: if raw_shm is None or raw_shm.strip() == '': continue raw_shm_splited = raw_shm.split(',') if len(raw_shm_splited) == 3 and raw_shm_splited[0].strip() != '' \ and raw_shm_splited[1].strip() != '' and len(raw_shm_splited[2].strip().split(':')) >= 1: try: size = raw_shm_splited[1].strip() int_size = int(size) * 0x100000 total_shm_size += int_size except Exception as e: print(e) hv_ram_size += 2 * max(total_shm_size, 0x200000) if hv_ram_size > HV_RAM_SIZE_MAX: common.print_red("requested RAM size should be smaller then {}".format( HV_RAM_SIZE_MAX), err=True) err_dic["board config: total vm number error"] = \ "requested RAM size should be smaller then {}".format(HV_RAM_SIZE_MAX) return err_dic # 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 for start_addr in list(board_cfg_lib.USED_RAM_RANGE): if hv_start_offset <= start_addr < 0x80000000: del board_cfg_lib.USED_RAM_RANGE[start_addr] ram_range = board_cfg_lib.get_ram_range() avl_start_addr = board_cfg_lib.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 = common.round_up(hv_start_addr, MEM_ALIGN) board_cfg_lib.USED_RAM_RANGE[hv_start_addr] = total_size if not hv_info.mem.hv_ram_start: print("CONFIG_HV_RAM_START={}".format(hex(hv_start_addr)), file=config) else: print("CONFIG_HV_RAM_START={}".format(hv_info.mem.hv_ram_start), file=config) if not hv_info.mem.hv_ram_size: print("CONFIG_HV_RAM_SIZE={}".format(hex(hv_ram_size)), file=config) else: print("CONFIG_HV_RAM_SIZE={}".format(hv_info.mem.hv_ram_size), file=config) print("CONFIG_PLATFORM_RAM_SIZE={}".format(hv_info.mem.platform_ram_size), file=config) print("CONFIG_LOW_RAM_SIZE={}".format(hv_info.mem.low_ram_size), file=config) print("CONFIG_STACK_SIZE={}".format(hv_info.mem.stack_size), file=config) print("CONFIG_IVSHMEM_ENABLED={}".format(hv_info.mem.ivshmem_enable), file=config)
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 common.VM_COUNT in list(VM_NUM_MAP_TOTAL_HV_RAM_SIZE.keys()): hv_ram_size = VM_NUM_MAP_TOTAL_HV_RAM_SIZE[common.VM_COUNT] else: common.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 = common.round_up(hv_start_addr, MEM_ALIGN) # add config scenario name (err_dic, scenario_name) = common.get_scenario_name() print("{}".format(DESC), file=config) print("CONFIG_{}=y".format(scenario_name.upper()), 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 scenario_name == "sdc" and cpu_core_num > 2: print("CONFIG_MAX_KATA_VM_NUM=1", file=config) else: 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) print("CONFIG_ENFORCE_VALIDATED_ACPI_INFO=y", file=config) return err_dic