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.