0

如何从设备树属性计算长度参数,即 属性长度的含义是什么以及它是如何从设备树中计算出来的。

struct property {
    char    *name;
    int     length;
    void    *value;
    struct property *next;
    unsigned long _flags;
    unsigned int unique_id;
    struct bin__attribute attr;
};
4

1 回答 1

0

这是一个从内核源代码初始化设备树节点的示例。

/* There should really .. oh whatever */
memset(&prop, 0, sizeof(prop));
prop.name = prop_name;
prop.value = &prop_data;
prop.length = sizeof(prop_data);

如您所见,没有什么特别的。只是 sizeof(prop)。它是 msi_bitmap.c 文件。你可以研究一下。

这里有一些更有趣的代码(drivers/of/fdt.c):

    /* process properties */
    for (offset = fdt_first_property_offset(blob, *poffset);
         (offset >= 0);
         (offset = fdt_next_property_offset(blob, offset))) {
            const char *pname;
            u32 sz;

            if (!(p = fdt_getprop_by_offset(blob, offset, &pname, &sz))) {
                    offset = -FDT_ERR_INTERNAL;
                    break;
            }

            if (pname == NULL) {
                    pr_info("Can't find property name in list !\n");
                    break;
            }
            if (strcmp(pname, "name") == 0)
                    has_name = 1;
            pp = unflatten_dt_alloc(&mem, sizeof(struct property),
                                    __alignof__(struct property));
            if (!dryrun) {
                    /* We accept flattened tree phandles either in
                     * ePAPR-style "phandle" properties, or the
                     * legacy "linux,phandle" properties.  If both
                     * appear and have different values, things
                     * will get weird.  Don't do that. */
                    if ((strcmp(pname, "phandle") == 0) ||
                        (strcmp(pname, "linux,phandle") == 0)) {
                            if (np->phandle == 0)
                                    np->phandle = be32_to_cpup(p);
                    }
                    /* And we process the "ibm,phandle" property
                     * used in pSeries dynamic device tree
                     * stuff */
                    if (strcmp(pname, "ibm,phandle") == 0)
                            np->phandle = be32_to_cpup(p);
                    pp->name = (char *)pname;
                    pp->length = sz;
                    pp->value = (__be32 *)p;
                    *prev_pp = pp;
                    prev_pp = &pp->next;
            }
    }
于 2015-05-08T22:25:13.100 回答