[U-Boot-Users] [PATCH] RFC: generic property fixup mechanism for LIBFDT

Grant Likely grant.likely at secretlab.ca
Wed Aug 29 20:01:49 CEST 2007


On 8/23/07, Jerry Van Baren <gerald.vanbaren at smiths-aerospace.com> wrote:
> The first half of Grant's comment was:
>  > These 4 functions are pretty close to identical (except for the
>  > parameter to cpu_to_be32()).  Surely there is a more compact way to do
>  > this.
>
> My answer is "no, the whole reason there is one line different is
> because it *has to be*."  As the French say about the "Y" chromosome
> "...and viva la difference."  My first attempt, and Bartlomiej's
> proposed patch, tried (tries) to put the value in the table, but it is a
> *WORSE* solution because you have the problem with byteswapping or not
> and different sizes of values.  The scorecard for putting the values in
> the tables and also having it maintainable is 0 for 2.

Yes, this is the icky bit; but I still  argue that there is a more
compact way to do it.  Table driven is nice when it works; but (as I
also mentioned in my original comment) whie it doesn't its probably
better to just fall back to something programatic

ie (totally untested):

static int fixup_prop(void *fdt, char *node, char *prop, void *val, int size)
{
        int nodeoffset;
        int rc;

        nodeoffset = fdt_find_node_by_path(fdt, node);
        if (nodeoffset < 0) {
                debug("Couldn't find %s: %s\n", node, fdt_strerror(nodeoffset));
                return nodeoffset;
        }

        rc = fdt_get_property(fdt, nodeoffset, prop, 0)
        if (rc)
                goto err;

        rc = fdt_setprop(fdt, nodeoffset, prop, val, size);
        if (rc)
                goto err;

err:
        debug("Problem setting %s = %s: %s\n", node, prop, fdt_strerror(rc));
        return rc;
}

static int fixup_int_prop(void *fdt, char *node, char *prop, u32 val)
{
        val = cpu_to_be32(val);
        return ft_fixup_int_prop(fdt, node, prop, &val, sizeof(val));
}

void
ft_cpu_setup(void *blob, bd_t *bd)
{
        fixup_int_prop(blob, "/cpus/" OF_CPU, "timebase-frequency", OF_TBCLK);
        fixup_int_prop(blob, "/cpus/" OF_CPU, "bus-frequency", bd->bi_busfreq);
        fixup_int_prop(blob, "/cpus/" OF_CPU, "clock-frequency",
bd->bi_intfreq);
        fixup_int_prop(blob, "/cpus/" OF_CPU, "bus-frequency", bd->ipbfreq);
        fixup_prop(blob, "/" OF_SOC "/ethernet at 3000", "mac-address",
                   bd->bi_enetaddr, 6);
        fixup_prop(blob, "/" OF_SOC "/ethernet at 3000", "local-mac-address",
                   bd->bi_enetaddr, 6);
}

This adds 2 helper functions instead of 5, and one of them is the same
path for all of the fixups.  Drops the table approach entirely due to
the problems with extracting values out of bd.  (Which is what I meant
in the third part of my original comment)

The 2 new helpers could also be generalized for use by all boards.

Cheers,
g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
grant.likely at secretlab.ca
(403) 399-0195




More information about the U-Boot mailing list