Esempio n. 1
0
def import_xls(regmap, path):
    xlsx = pd.ExcelFile(path)

    ipreglist = None
    ipregmap = None

    for sheet_name in xlsx.sheet_names:

        if sheet_name.find('IPREGLIST') == 0:
            ipreglist = xlsx.parse(sheet_name)
        elif sheet_name.find('IPREGMAP') == 0:
            ipregmap = xlsx.parse(sheet_name)

    if ipreglist is not None:
        for index, row in ipreglist.iterrows():
            regmap.add_register(
                rmap.Register(
                  name=str(row['Register Name']),
                  offset=int(row['Address'], 0),
                  width=row['Size'],
                  desc=str(row['Description'])
                )
            )

    if ipregmap is not None:
        for index, row in ipregmap.iterrows():
            reg = regmap.get_register(row['Register'])

            if row['Bit field'] == '-':
                continue

            reg.add_regfield(
                rmap.Regfield(
                    name=str(row['Bit field']),
                    width=int(row['Size']),
                    bit=int(row['Bit Position']),
                    access=str(row['Host Access Type']),
                    desc=str(row['Description']),
                    reg_reset=reg.reset
                )
            )
def __parse_elem_from_type(regmap_obj, name, config):
    if type(config) not in [js.config_object]:
        return

    obj_type = config.get_child_str('type')

    if obj_type is not None:

        if obj_type == 'register':

            reg = regmap_obj.add_register(
                rmap.Register(name=name,
                              offset=config.get_child_int('offset'),
                              width=config.get_child_int('width'),
                              desc=config.get_child_str('desc'),
                              reset=config.get_child_int('reset'),
                              help=config.get_child_str('help'),
                              parent=regmap_obj))

            content = config.get('content')
            if content is not None:
                for name, field in content.get_items().items():
                    reg.add_regfield(
                        rmap.Regfield(name=name,
                                      full_name=field.get_child_str('name'),
                                      width=field.get_child_int('width'),
                                      bit=field.get_child_int('bit'),
                                      access=field.get_child_str('access'),
                                      desc=field.get_child_str('desc'),
                                      reset=field.get_child_str('reset'),
                                      reg_reset=reg.reset))

            return

        elif obj_type == 'group':
            group = regmap_obj.add_regmap(
                rmap.Regmap(name=name,
                            offset=config.get_child_int('offset'),
                            parent=regmap_obj))

            __parse_elem(group, name, config)

            return

        elif obj_type == 'template':
            group = regmap_obj.add_regmap(
                rmap.Regmap(name=name,
                            offset=config.get_child_int('offset'),
                            parent=regmap_obj))

            __parse_elem(group, name, config)

            return

        elif obj_type == 'custom':
            for name, obj in config.get_items().items():
                if obj.get_child_str('type') is not None:
                    regmap_obj.add_constant(
                        rmap.Constant(name=name,
                                      type=obj.get_child_str('type'),
                                      value=obj.get_child_str('value'),
                                      parent=regmap_obj))

            return

    __parse_elem(regmap_obj, name, config)
Esempio n. 3
0
def import_md(regmap, path):
    with open(path, "rt") as fh:
        raw_text = fh.read()
        html_text = mt.markdown(raw_text)
        with open(path+'.html', 'wt') as fh2: fh2.write(html_text)
        bs = BeautifulSoup(html_text, "html.parser")

        block = {}

        most_headers_names = ['h'+str(i) for i in range(1, 10)]

        # get block name, first header
        name_header_node = bs(most_headers_names)[0]
        if name_header_node:
            block['name'] = name_header_node.decode_contents()
        else:
            raise RuntimeError("Cannot find block name header")

        # get block description
        # first header with 'description' in it
        description_header_node = None
        for i in bs(header_name(header_node_level(name_header_node) +1)):
            if 'description' in i.decode_contents().lower():
                description_header_node = i
                break

        if not description_header_node:
            raise RuntimeError("Cannot find a description header")
            
        # description nodes
        # between description header and next header of another hierarchy
        block['description'] = get_description(description_header_node)

        # register table
        # find an header named register
        # with the same hierarchy than description
        register_header_node = None
        for i in bs(header_name(header_node_level(name_header_node) +1)):
            if 'register' in i.decode_contents().lower():
                register_header_node = i
                break

        if not register_header_node:
            raise RuntimeError("Cannot find a register header")

        # find the register table, should be just after this header
        register_table = None
        for i in register_header_node.find_next_siblings('table'):
            headrow = i.thead.tr
            if headrow.th:
                s = headrow.th.decode_contents().lower()
                if 'register name' in s:
                    # looks like a valid register table
                    register_table = i
                    break
        
        # parse registers
        for register_row in register_table.tbody('tr'):
            r = []
            for register_el in register_row('td'):
                r.append(register_el.decode_contents())

            reg = regmap.add_register(
                rmap.Register(
                name=r[0],
                offset=int(r[1], 0)
                )
            )

            try:
                default_index = get_table_index(register_table, 'Properties')
                if default_index != -1:
                    for prop in r[default_index].split():
                        key, value = prop.split('=')
                        if key == 'template':
                            reg.template = value

                default_index = get_table_index(register_table, 'Size')
                if default_index != -1:
                    # Too many IPs has wrong register width, hard-code it to 32 bits
                    reg.width = 32 # int(r[default_index], 0)

                default_index = get_table_index(register_table, names=['Default', 'Reset Value'])
                if default_index != -1:
                    reg.reset = int(r[default_index], 0)

                desc_index = get_table_index(register_table, 'Description')
                if desc_index == -1:
                    desc_index = get_table_index(register_table, 'Short description')

                if desc_index != -1:
                    if len(r) > desc_index:
                        reg.desc = r[desc_index]

                do_reset_index = get_table_index(register_table, 'Reset')
                if do_reset_index != -1:
                    reg.do_reset = int(r[do_reset_index])

            except:
                print ('Caught error while parsing register (name: %s)' % r[0])
                raise

        # Now for each register parse the field table
        for register in regmap.get_registers():
            node = get_register_node(register_header_node, register.get_field_template())

            if node is not None and register.desc is None:
                description = get_description(node)
                register.desc = description

            if node is not None:
                fields_table = get_register_field_table(node)

                if fields_table is not None:
                    for field_row in fields_table.tbody('tr'):
                        r = []
                        for field_el in field_row('td'):
                            r.append(field_el.decode_contents())

                        name_index = get_table_index(fields_table, names=['Field Name'])
                        bit_index = get_table_index(fields_table, names=['Offset', 'Bit'])
                        width_index = get_table_index(fields_table, names=['Size', 'Width'])
                        access_index = get_table_index(fields_table, names=['Host Access Type', 'Access Type'])
                        reset_index = get_table_index(fields_table, names=['Default', 'Reset Value'])

                        regfield = register.add_regfield(
                            rmap.Regfield(
                                name=r[name_index],
                                width=int(r[width_index], 0),
                                bit=int(r[bit_index], 0),
                                access=r[access_index]
                            )
                        )

                        desc_index = get_table_index(fields_table, 'Description')
                        if desc_index == -1:
                            desc_index = get_table_index(fields_table, 'Short description')

                        if desc_index != -1:
                            register.get_regfield(r[0]).desc = r[desc_index]

                        if reset_index != -1:
                            regfield.reset = int(r[reset_index], 0)

            for field in register.get_fields():
                field_node = get_register_field_node(node, field.name)

                if field_node is not None and field.desc is None:
                    description = get_description(field_node)
                    field.desc = description

        commands_top_node = get_top_node(bs, name_header_node, 'commands')

        if commands_top_node is not None:
            for command_node in get_nodes(commands_top_node, 1):
                cmdmap = rmap.Cmdmap(name=command_node.decode_contents())
                regmap.add_cmdmap(cmdmap)

                table_node = get_table_node(command_node, 'Command Name')

                if table_node is not None:

                    size_index = get_table_index(table_node, 'Size')
                    id_index = get_table_index(table_node, 'Command field')
                    if id_index == -1:
                        id_index = get_table_index(table_node, 'id')

                    for row in get_table(table_node):

                        if size_index != -1:
                            size = int(row[size_index], 0)
                        else:
                            size = 32

                        cmdmap.add_cmd(
                            rmap.Cmd(
                                name=row[0],
                                code=row[id_index],
                                width=size
                            )
                        )

                        desc_index = get_table_index(get_table_node(command_node, 'Command Name'), 'Description')
                        if desc_index == -1:
                            desc_index = get_table_index(get_table_node(command_node, 'Command Name'), 'Short description')

                        if desc_index != -1 and len(row) >= desc_index + 1:
                            cmdmap.get_cmd(row[0]).desc = row[desc_index]

                    for cmd in cmdmap.get_cmds():
                        node = get_node(command_node, cmd.name)

                        if node is not None:
                            if cmd.desc is None:
                                cmd.desc = get_description(node)

                            table = get_table_node(node, 'Field Name')

                        if node is not None and table is not None:

                            for row in get_table(table):
                                cmd.add_cmdfield(
                                    rmap.Cmdfield(
                                        name=row[0],
                                        width=int(row[2], 0),
                                        offset=int(row[1], 0),
                                        value=row[3]
                                    )
                                )

                                desc_index = get_table_index(get_table_node(node, 'Field Name'), 'Description')
                                if desc_index == -1:
                                    desc_index = get_table_index(get_table_node(node, 'Field Name'), 'Short description')

                                if desc_index != -1 and len(row) >= desc_index + 1:
                                    cmd.get_cmdfield(row[0]).desc = row[desc_index]

                                if cmd.get_cmdfield(row[0]).desc is None:
                                    desc_node = get_node(node, row[0], 2)
                                    if desc_node is not None:
                                        cmd.get_cmdfield(row[0]).desc = get_description(desc_node)

                        else:
                            cmd.add_cmdfield(
                                rmap.Cmdfield(
                                    value=cmd.code,
                                    width=cmd.width,
                                    name=cmd.name,
                                    offset=0
                                )
                            )
Esempio n. 4
0
def import_xls(regmap, path):
    xlsx = pd.ExcelFile(path)

    ipinfo = None
    ipreglist = None
    ipregmap = None
    ipfsmfmtmap = None

    for sheet_name in xlsx.sheet_names:

        if sheet_name.find('Info') == 0:
            ipinfo = xlsx.parse(sheet_name)
        elif sheet_name.find('IPREGLIST') == 0:
            ipreglist = xlsx.parse(sheet_name)
        elif sheet_name.find('IPREGMAP') == 0:
            ipregmap = xlsx.parse(sheet_name)
        elif sheet_name.find('IPFSMFMTMAP') == 0:
            ipfsmfmtmap = xlsx.parse(sheet_name)

        #if ipinfo is not None:
        #    for index, row in ipinfo.iterrows():
        #        if row[1] == "IP type":
        #            regmap.name = row[2]
        #            print ("Regmap name from xls %s" % regmap.name)

    if ipreglist is not None:
        for index, row in ipreglist.iterrows():

            if not isinstance(row['Register Name'], str):
                continue

            reset_val = row.get('Default Value')

            if reset_val is not None:
                if not isinstance(reset_val, int):
                    try:
                        reset_val = int(row['Default Value'], 0)
                    except:
                        reset_val = None

            regmap.add_register(
                rmap.Register(
                  name=str(row['Register Name']),
                  offset=int(row['Address'], 0),
                  width=row['Size'],
                  desc=str(row['Description']),
                  reset=reset_val
                )
            )
            regmap.range=str(int(row['Address'], 0))

    if ipregmap is not None:
        for index, row in ipregmap.iterrows():
            reg_name = row['Register']

            reg = regmap.get_register(reg_name)

            if row['Bit field'] == '-':
                continue

            if reg is None:
                raise Exception("Found bitfield for unknown register: " + reg_name)

            reset_val = row.get('Reset Value')

            if reset_val is not None:
                if not isinstance(reset_val, int):
                    try:
                        if isinstance(reset_val, str):
                            reset_val = int(row['Reset Value'], 0)
                        else:
                            reset_val = int(row['Reset Value'])
                    except:
                        reset_val = None

            reg.add_regfield(
                rmap.Regfield(
                    name=str(row['Bit field']),
                    width=int(row['Size']),
                    bit=int(row['Bit Position']),
                    access=str(row['Host Access Type']),
                    desc=get_description(str(row['Description'])),
                    reg_reset=reg.reset,
                    reset=reset_val
                )
            )
Esempio n. 5
0
def import_xls(regmap, path):
    xlsx = pd.ExcelFile(path)

    ipreglist = None
    ipregmap = None
    ipfsmfmtmap = None

    for sheet_name in xlsx.sheet_names:

        if sheet_name.find('IPREGLIST') == 0:
            ipreglist = xlsx.parse(sheet_name)
        elif sheet_name.find('IPREGMAP') == 0:
            ipregmap = xlsx.parse(sheet_name)
        elif sheet_name.find('IPFSMFMTMAP') == 0:
            ipfsmfmtmap = xlsx.parse(sheet_name)

    if ipreglist is not None:
        for index, row in ipreglist.iterrows():
            regmap.add_register(
                rmap.Register(name=str(row['Register Name']),
                              offset=int(row['Address'], 0),
                              width=row['Size'],
                              desc=str(row['Description'])))

    if ipregmap is not None:
        for index, row in ipregmap.iterrows():
            reg_name = row['Register']

            reg = regmap.get_register(reg_name)

            if row['Bit field'] == '-':
                continue

            if reg is None:
                raise Exception("Found bitfield for unknown register: " +
                                reg_name)

            reg.add_regfield(
                rmap.Regfield(name=str(row['Bit field']),
                              width=int(row['Size']),
                              bit=int(row['Bit Position']),
                              access=str(row['Host Access Type']),
                              desc=get_description(str(row['Description'])),
                              reg_reset=reg.reset))

    if ipfsmfmtmap is not None:
        for index, row in ipfsmfmtmap.iterrows():
            reg_name = '%s_%s' % (row['Register name'], row['Format Name'])

            reg = regmap.get_register(reg_name)

            if reg is None:
                reg = regmap.add_register(
                    rmap.Register(name=reg_name,
                                  offset=None,
                                  width=row['Size'],
                                  desc=get_description(row['Description'])))

            if row['Bit field'] == '-':
                continue

            reg.add_regfield(
                rmap.Regfield(name=get_name(row['Bit field']),
                              width=int(row['Size']),
                              bit=int(row['Bit Position']),
                              access=str(row['Host Access Type']),
                              desc=get_description(row['Description']),
                              reg_reset=reg.reset))
def import_xls(regmap, cmdmap, path):
    xlsx = pd.ExcelFile(path)

    ipreglist = None
    ipregmap = None
    ipcmdlist = None
    ipcmdmap = None

    for sheet_name in xlsx.sheet_names:

        if sheet_name.find('IPREGLIST') == 0:
            ipreglist = xlsx.parse(sheet_name)
        elif sheet_name.find('IPREGMAP') == 0:
            ipregmap = xlsx.parse(sheet_name)
        elif sheet_name.find('IPINDIRECTREGLIST') == 0:
            ipindirectreglist = xlsx.parse(sheet_name)
        elif sheet_name.find('IPINDIRECTREGMAP') == 0:
            ipindirectregmap = xlsx.parse(sheet_name)
        elif sheet_name.find('IPUDMACMDLIST') == 0:
            ipcmdlist = xlsx.parse(sheet_name)
        elif sheet_name.find('IPUDMACMDMAP') == 0:
            ipcmdmap = xlsx.parse(sheet_name)

    if ipreglist is not None:
        for index, row in ipreglist.iterrows():
            regmap.add_register(
                rmap.Register(name=row['Register Name'],
                              offset=int(row['Address'], 0),
                              width=row['Size'],
                              desc=row['Description']))

    if ipregmap is not None:
        for index, row in ipregmap.iterrows():
            reg = regmap.get_register(row['Register'])

            if row['Bit field'] == '-':
                continue

            reg.add_regfield(
                rmap.Regfield(name=row['Bit field'],
                              width=row['Size'],
                              bit=row['Bit Position'],
                              access=row['Host Access Type'],
                              desc=row['Description'],
                              reg_reset=reg.reset))

    if ipcmdlist is not None:
        for index, row in ipcmdlist.iterrows():
            cmdmap.add_cmd(
                cmap.Cmd(name=row['Command name'],
                         code=int(row['Command field'], 0),
                         width=row['Size'],
                         desc=row['Description']))

    if ipcmdmap is not None:
        for index, row in ipcmdmap.iterrows():
            cmd = cmdmap.get_command(row['Command name'])

            if row['Bit position'] == '-':
                continue

            cmd.add_cmdfield(
                cmap.Cmdfield(
                    name=row['Parameter bit field'],
                    width=row['Size'],
                    offset=int(row['Bit position']),
                    value=row['Field value'],
                    desc=row['Description'],
                ))