0

How is length parameter calculated from a device tree property, i,e. what is the meaning of property length and how its calculated from a device tree.

struct property {
    char    *name;
    int     length;
    void    *value;
    struct property *next;
    unsigned long _flags;
    unsigned int unique_id;
    struct bin__attribute attr;
};
Leistungsabfall
  • 6,368
  • 7
  • 33
  • 41
valmiki
  • 701
  • 9
  • 24

1 Answers1

0

Here is an example of initialization device tree node from kernel source code.

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

As you can see nothing special. Just sizeof(prop). It's msi_bitmap.c file. You can research it.

A little bit more interesting code here(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;
            }
    }
Anton Glukhov
  • 3,507
  • 1
  • 15
  • 16