0

u-boot version: 2021.07-RC3

[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

[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;
}

Here, 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.
I notice that dn here is in int type, but dev->node_.of_offset is in long type. So dn contains a truncated offset value. However, I'm not sure if the error I got is related to this.

Wanghz
  • 305
  • 2
  • 12
  • It is preferable to send your bug report and possible patches to the U-Boot mailing list and to Simon Glass who is the maintainer for the driver model. See file MAINTAINERS. – Xypron Jun 17 '21 at 18:44
  • Okay, I'll try. – Wanghz Jun 18 '21 at 02:46

1 Answers1

1

I face similar issue too. I follow your clues and edit like this. It seems working.

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

    pdata->sides =  dev_read_s32_default(dev, "sides", 0);
    pdata->colour =  dev_read_prop(dev, "colour", NULL);

    if (!pdata->sides || !pdata->colour) {
        printf("%s: Invalid device tree data\n", __func__);
        return -EINVAL;
    }

    return 0;
}

I am quite new to u-boot. Anyone found better way, please correct me.