u-boot driver model: using sandbox_defconfig, “demo hello 5” got error “Command 'demo' failed: Error -22”

王洪柱 bj_wanghz at 126.com
Fri Jun 18 05:32:36 CEST 2021


u-boot version: 2021.07-RC3
environment: Ubuntu 18.04 64-bit

[Description]
Build and run u-boot:

make sandbox_defconfig
make
./u-boot -d u-boot.dtb


Type the following on the command-line:

=> demo hello 5


I Got the following Error:

Command 'demo' failed: Error -22


If I disable CONFIG_OF_LIVE, the command will get the right answer.

[Analysis]
Index 5 is the device named 'hexagon' defined in arch/sandbox/dts/sandbox.dtsi:

hexagon {
        compatible = "demo-simple";
        colour = "white";
        sides = <6>;
    };


device_probe will call of_to_plat, which finally call demo_parse_dt in drivers/demo/demo-uclass.c.

int demo_parse_dt(struct udevice *dev)
{
    struct dm_demo_pdata *pdata = dev_get_plat(dev);
    int dn = dev_of_offset(dev);

    pdata->sides = fdtdec_get_int(gd->fdt_blob, dn, "sides", 0);
    pdata->colour = fdt_getprop(gd->fdt_blob, dn, "colour", NULL);
    if (!pdata->sides || !pdata->colour) {
        debug("%s: Invalid device tree data\n", __func__);
        return -EINVAL;
    }

    return 0;
}


With the default configurations, I got 0 for pdata->sides, and NULL for pdata->colour. Seem that fdtdec_get_int and fdt_getprop hadn't get the correct values from device tree.
With CONFIG_OF_LIVE enabled, node_ member of struct udevice will be set as a node pointer instead of an offset. dn = dev_of_offset(dev) will get an incorrect result, so "sides" and "colour" cannot be reached.




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hongzhu Wang

bj_wanghz at 126.com


More information about the U-Boot mailing list