示例#1
0
def get_valid_ttys_for_vuart(ttys_n):
    """
    Get available ttysn list for vuart0/vuart1
    :param ttys_n: the serial port was chosen as hv console
     """
    vuart0_valid = []
    vuart1_valid = ['ttyS0', 'ttyS1', 'ttyS2', 'ttyS3']
    ttys_lines = board_cfg_lib.get_info(common.BOARD_INFO_FILE, "<TTYS_INFO>", "</TTYS_INFO>")
    if ttys_lines:
        vuart0_valid.clear()
        for tty_line in ttys_lines:
            tmp_dic = {}
            #seri:/dev/ttySx type:mmio base:0x91526000 irq:4 [bdf:"00:18.0"]
            #seri:/dev/ttySy type:portio base:0x2f8 irq:5
            tty = tty_line.split('/')[2].split()[0]
            ttys_irq = tty_line.split()[3].split(':')[1].strip()
            ttys_type = tty_line.split()[1].split(':')[1].strip()
            tmp_dic['irq'] = int(ttys_irq)
            tmp_dic['type'] = ttys_type
            NATIVE_TTYS_DIC[tty] = tmp_dic
            vuart0_valid.append(tty)
            if tty and tty in vuart1_valid:
                vuart1_valid.remove(tty)

    if not vuart1_valid:
        common.print_yel("ttyS are fully used. ttyS0 is used for hv_console, ttyS1 is used for vuart1!", warn=True)
        vuart1_valid = ['ttyS0', 'ttyS1', 'ttyS2', 'ttyS3']
        if ttys_n in vuart1_valid:
            vuart1_valid.remove(ttys_n)

    return (vuart0_valid, vuart1_valid)
def get_serial_type():
    """ Get serial console type specified by user """
    ttys_type = ''
    ttys_value = ''

    # Get ttySx information from board config file
    ttys_lines = board_cfg_lib.get_info(common.BOARD_INFO_FILE, "<TTYS_INFO>", "</TTYS_INFO>")

    # Get ttySx from scenario config file which selected by user
    (err_dic, ttyn) = board_cfg_lib.parser_hv_console()
    if err_dic:
        hv_cfg_lib.ERR_LIST.update(err_dic)

    # query the serial type from board config file
    for line in ttys_lines:
        if ttyn in line:
            # line format:
            # seri:/dev/ttyS0 type:portio base:0x3F8 irq:4
            # seri:/dev/ttyS0 type:mmio base:0xB3640000 irq:4 [bdf:"0:x.y"]
            ttys_type = line.split()[1].split(':')[1]
            if ttys_type == "portio":
                ttys_value = line.split()[2].split(':')[1]
            elif ttys_type == "mmio":
                if 'bdf' in line:
                    ttys_value = line.split()[-1].split('"')[1:-1][0]
                else:
                    common.print_yel("You have chosen a MMIO PCI serial that BDF does not existed for HV console.", warn=True)
            break

    return (ttys_type, ttys_value)
示例#3
0
def fn(board_etree, scenario_etree, allocation_etree):
    native_ttys = lib.lib.get_native_ttys()
    pio_list = [
        base for base in VALID_PIO
        if all(native_ttys[tty]['base'] != base for tty in native_ttys.keys())
    ]
    # This pio_list is workaround. Since there are whl-ipc-i7 and whl-ipc-i5 which occupy all valid pio ports.
    # It would fail to allocate pio base for enabled sos legacy vuart1. In that case, we allow vuart1 take one pio
    # base which is used in native.
    full = False
    if len(pio_list) == 0:
        full = True
        pio_list = VALID_PIO

    vuart_valid = ['ttyS0', 'ttyS1', 'ttyS2', 'ttyS3']
    hv_debug_console = lib.lib.parse_hv_console(scenario_etree)

    scenario_sos_vm_node = common.get_node("//vm[vm_type = 'SOS_VM']",
                                           scenario_etree)
    if scenario_sos_vm_node is not None:
        vm_id = common.get_node("./@id", scenario_sos_vm_node)
        if common.get_node("./legacy_vuart[@id = '0']/base/text()",
                           scenario_sos_vm_node) != "INVALID_COM_BASE":
            vuart0_base = ""
            if hv_debug_console in vuart_valid and hv_debug_console in native_ttys.keys(
            ) and native_ttys[hv_debug_console]['type'] == "portio":
                vuart0_base = native_ttys[hv_debug_console]['base']
                if vuart0_base in pio_list:
                    remove_pio(pio_list, vuart0_base)
            else:
                vuart0_base = alloc_pio(pio_list)
                if full:
                    common.print_yel(
                        "All available pio bases are used by native fully. '{}' is taken by sos legacy vuart 0."
                        .format(vuart0_base),
                        warn=True)

            create_vuart_base_node(allocation_etree, str(vm_id), "0",
                                   vuart0_base)

        if common.get_node("./legacy_vuart[@id = '1']/base/text()",
                           scenario_sos_vm_node) != "INVALID_COM_BASE":
            vuart1_base = alloc_pio(pio_list)
            if full:
                common.print_yel(
                    "All available pio bases are used by native fully. '{}' is taken by sos legacy vuart 1."
                    .format(vuart1_base),
                    warn=True)

            create_vuart_base_node(allocation_etree, str(vm_id), "1",
                                   vuart1_base)
示例#4
0
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