Merge git://git.denx.de/u-boot-fdt
This commit is contained in:
commit
4504062b27
@ -78,11 +78,11 @@ tegra_xusb_padctl_group_parse_dt(struct tegra_xusb_padctl *padctl,
|
|||||||
const void *fdt, int node)
|
const void *fdt, int node)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int len, err;
|
int len;
|
||||||
|
|
||||||
group->name = fdt_get_name(fdt, node, &len);
|
group->name = fdt_get_name(fdt, node, &len);
|
||||||
|
|
||||||
len = fdt_count_strings(fdt, node, "nvidia,lanes");
|
len = fdt_stringlist_count(fdt, node, "nvidia,lanes");
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
error("failed to parse \"nvidia,lanes\" property");
|
error("failed to parse \"nvidia,lanes\" property");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -91,9 +91,9 @@ tegra_xusb_padctl_group_parse_dt(struct tegra_xusb_padctl *padctl,
|
|||||||
group->num_pins = len;
|
group->num_pins = len;
|
||||||
|
|
||||||
for (i = 0; i < group->num_pins; i++) {
|
for (i = 0; i < group->num_pins; i++) {
|
||||||
err = fdt_get_string_index(fdt, node, "nvidia,lanes", i,
|
group->pins[i] = fdt_stringlist_get(fdt, node, "nvidia,lanes",
|
||||||
&group->pins[i]);
|
i, NULL);
|
||||||
if (err < 0) {
|
if (!group->pins[i]) {
|
||||||
error("failed to read string from \"nvidia,lanes\" property");
|
error("failed to read string from \"nvidia,lanes\" property");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -101,8 +101,8 @@ tegra_xusb_padctl_group_parse_dt(struct tegra_xusb_padctl *padctl,
|
|||||||
|
|
||||||
group->num_pins = len;
|
group->num_pins = len;
|
||||||
|
|
||||||
err = fdt_get_string(fdt, node, "nvidia,function", &group->func);
|
group->func = fdt_stringlist_get(fdt, node, "nvidia,function", 0, NULL);
|
||||||
if (err < 0) {
|
if (!group->func) {
|
||||||
error("failed to parse \"nvidia,func\" property");
|
error("failed to parse \"nvidia,func\" property");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -223,7 +223,7 @@ tegra_xusb_padctl_config_parse_dt(struct tegra_xusb_padctl *padctl,
|
|||||||
|
|
||||||
config->name = fdt_get_name(fdt, node, NULL);
|
config->name = fdt_get_name(fdt, node, NULL);
|
||||||
|
|
||||||
fdt_for_each_subnode(fdt, subnode, node) {
|
fdt_for_each_subnode(subnode, fdt, node) {
|
||||||
struct tegra_xusb_padctl_group *group;
|
struct tegra_xusb_padctl_group *group;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ static int tegra_xusb_padctl_parse_dt(struct tegra_xusb_padctl *padctl,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdt_for_each_subnode(fdt, subnode, node) {
|
fdt_for_each_subnode(subnode, fdt, node) {
|
||||||
struct tegra_xusb_padctl_config *config = &padctl->config;
|
struct tegra_xusb_padctl_config *config = &padctl->config;
|
||||||
|
|
||||||
err = tegra_xusb_padctl_config_parse_dt(padctl, config, fdt,
|
err = tegra_xusb_padctl_config_parse_dt(padctl, config, fdt,
|
||||||
|
@ -37,13 +37,12 @@ static int uniphier_set_fdt_file(void)
|
|||||||
const char *compat;
|
const char *compat;
|
||||||
char dtb_name[256];
|
char dtb_name[256];
|
||||||
int buf_len = 256;
|
int buf_len = 256;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (getenv("fdt_file"))
|
if (getenv("fdt_file"))
|
||||||
return 0; /* do nothing if it is already set */
|
return 0; /* do nothing if it is already set */
|
||||||
|
|
||||||
ret = fdt_get_string(gd->fdt_blob, 0, "compatible", &compat);
|
compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
|
||||||
if (ret)
|
if (!compat)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (strncmp(compat, VENDOR_PREFIX, strlen(VENDOR_PREFIX)))
|
if (strncmp(compat, VENDOR_PREFIX, strlen(VENDOR_PREFIX)))
|
||||||
|
@ -103,11 +103,12 @@ static int create_pirq_routing_table(struct udevice *dev)
|
|||||||
/* extract the bdf from fdt_pci_addr */
|
/* extract the bdf from fdt_pci_addr */
|
||||||
priv->bdf = dm_pci_get_bdf(dev->parent);
|
priv->bdf = dm_pci_get_bdf(dev->parent);
|
||||||
|
|
||||||
ret = fdt_find_string(blob, node, "intel,pirq-config", "pci");
|
ret = fdt_stringlist_search(blob, node, "intel,pirq-config", "pci");
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
priv->config = PIRQ_VIA_PCI;
|
priv->config = PIRQ_VIA_PCI;
|
||||||
} else {
|
} else {
|
||||||
ret = fdt_find_string(blob, node, "intel,pirq-config", "ibase");
|
ret = fdt_stringlist_search(blob, node, "intel,pirq-config",
|
||||||
|
"ibase");
|
||||||
if (!ret)
|
if (!ret)
|
||||||
priv->config = PIRQ_VIA_IBASE;
|
priv->config = PIRQ_VIA_IBASE;
|
||||||
else
|
else
|
||||||
|
@ -602,7 +602,7 @@ int ft_board_setup(void *blob, bd_t *bd)
|
|||||||
char baseboard_name[16];
|
char baseboard_name[16];
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
fdt_shrink_to_minimum(blob); /* Make room for new properties */
|
fdt_shrink_to_minimum(blob, 0); /* Make room for new properties */
|
||||||
|
|
||||||
/* MAC addr */
|
/* MAC addr */
|
||||||
if (eth_getenv_enetaddr("ethaddr", enetaddr)) {
|
if (eth_getenv_enetaddr("ethaddr", enetaddr)) {
|
||||||
|
@ -662,7 +662,12 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|||||||
#endif
|
#endif
|
||||||
/* resize the fdt */
|
/* resize the fdt */
|
||||||
else if (strncmp(argv[1], "re", 2) == 0) {
|
else if (strncmp(argv[1], "re", 2) == 0) {
|
||||||
fdt_shrink_to_minimum(working_fdt);
|
uint extrasize;
|
||||||
|
if (argc > 2)
|
||||||
|
extrasize = simple_strtoul(argv[2], NULL, 16);
|
||||||
|
else
|
||||||
|
extrasize = 0;
|
||||||
|
fdt_shrink_to_minimum(working_fdt, extrasize);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Unrecognized command */
|
/* Unrecognized command */
|
||||||
@ -1056,7 +1061,7 @@ static char fdt_help_text[] =
|
|||||||
"fdt systemsetup - Do system-specific set up\n"
|
"fdt systemsetup - Do system-specific set up\n"
|
||||||
#endif
|
#endif
|
||||||
"fdt move <fdt> <newaddr> <length> - Copy the fdt to <addr> and make it active\n"
|
"fdt move <fdt> <newaddr> <length> - Copy the fdt to <addr> and make it active\n"
|
||||||
"fdt resize - Resize fdt to size + padding to 4k addr\n"
|
"fdt resize [<extrasize>] - Resize fdt to size + padding to 4k addr + some optional <extrasize> if needed\n"
|
||||||
"fdt print <path> [<prop>] - Recursive print starting at <path>\n"
|
"fdt print <path> [<prop>] - Recursive print starting at <path>\n"
|
||||||
"fdt list <path> [<prop>] - Print one level starting at <path>\n"
|
"fdt list <path> [<prop>] - Print one level starting at <path>\n"
|
||||||
"fdt get value <var> <path> <prop> - Get <property> and store in <var>\n"
|
"fdt get value <var> <path> <prop> - Get <property> and store in <var>\n"
|
||||||
|
@ -523,7 +523,7 @@ void fdt_fixup_ethernet(void *fdt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Resize the fdt to its actual size + a bit of padding */
|
/* Resize the fdt to its actual size + a bit of padding */
|
||||||
int fdt_shrink_to_minimum(void *blob)
|
int fdt_shrink_to_minimum(void *blob, uint extrasize)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint64_t addr, size;
|
uint64_t addr, size;
|
||||||
@ -551,6 +551,7 @@ int fdt_shrink_to_minimum(void *blob)
|
|||||||
actualsize = fdt_off_dt_strings(blob) +
|
actualsize = fdt_off_dt_strings(blob) +
|
||||||
fdt_size_dt_strings(blob) + 5 * sizeof(struct fdt_reserve_entry);
|
fdt_size_dt_strings(blob) + 5 * sizeof(struct fdt_reserve_entry);
|
||||||
|
|
||||||
|
actualsize += extrasize;
|
||||||
/* Make it so the fdt ends on a page boundary */
|
/* Make it so the fdt ends on a page boundary */
|
||||||
actualsize = ALIGN(actualsize + ((uintptr_t)blob & 0xfff), 0x1000);
|
actualsize = ALIGN(actualsize + ((uintptr_t)blob & 0xfff), 0x1000);
|
||||||
actualsize = actualsize - ((uintptr_t)blob & 0xfff);
|
actualsize = actualsize - ((uintptr_t)blob & 0xfff);
|
||||||
|
@ -503,7 +503,7 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,
|
|||||||
lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob,
|
lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob,
|
||||||
(phys_size_t)fdt_totalsize(blob));
|
(phys_size_t)fdt_totalsize(blob));
|
||||||
|
|
||||||
ret = fdt_shrink_to_minimum(blob);
|
ret = fdt_shrink_to_minimum(blob, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto err;
|
goto err;
|
||||||
of_size = ret;
|
of_size = ret;
|
||||||
|
@ -1026,7 +1026,7 @@ int fit_image_verify(const void *fit, int image_noffset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Process all hash subnodes of the component image node */
|
/* Process all hash subnodes of the component image node */
|
||||||
fdt_for_each_subnode(fit, noffset, image_noffset) {
|
fdt_for_each_subnode(noffset, fit, image_noffset) {
|
||||||
const char *name = fit_get_name(fit, noffset, NULL);
|
const char *name = fit_get_name(fit, noffset, NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1457,7 +1457,7 @@ int fit_conf_get_prop_node(const void *fit, int noffset,
|
|||||||
void fit_conf_print(const void *fit, int noffset, const char *p)
|
void fit_conf_print(const void *fit, int noffset, const char *p)
|
||||||
{
|
{
|
||||||
char *desc;
|
char *desc;
|
||||||
char *uname;
|
const char *uname;
|
||||||
int ret;
|
int ret;
|
||||||
int loadables_index;
|
int loadables_index;
|
||||||
|
|
||||||
@ -1469,7 +1469,7 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
|
|||||||
else
|
else
|
||||||
printf("%s\n", desc);
|
printf("%s\n", desc);
|
||||||
|
|
||||||
uname = (char *)fdt_getprop(fit, noffset, FIT_KERNEL_PROP, NULL);
|
uname = fdt_getprop(fit, noffset, FIT_KERNEL_PROP, NULL);
|
||||||
printf("%s Kernel: ", p);
|
printf("%s Kernel: ", p);
|
||||||
if (uname == NULL)
|
if (uname == NULL)
|
||||||
printf("unavailable\n");
|
printf("unavailable\n");
|
||||||
@ -1477,26 +1477,23 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
|
|||||||
printf("%s\n", uname);
|
printf("%s\n", uname);
|
||||||
|
|
||||||
/* Optional properties */
|
/* Optional properties */
|
||||||
uname = (char *)fdt_getprop(fit, noffset, FIT_RAMDISK_PROP, NULL);
|
uname = fdt_getprop(fit, noffset, FIT_RAMDISK_PROP, NULL);
|
||||||
if (uname)
|
if (uname)
|
||||||
printf("%s Init Ramdisk: %s\n", p, uname);
|
printf("%s Init Ramdisk: %s\n", p, uname);
|
||||||
|
|
||||||
uname = (char *)fdt_getprop(fit, noffset, FIT_FDT_PROP, NULL);
|
uname = fdt_getprop(fit, noffset, FIT_FDT_PROP, NULL);
|
||||||
if (uname)
|
if (uname)
|
||||||
printf("%s FDT: %s\n", p, uname);
|
printf("%s FDT: %s\n", p, uname);
|
||||||
|
|
||||||
uname = (char *)fdt_getprop(fit, noffset, FIT_FPGA_PROP, NULL);
|
uname = fdt_getprop(fit, noffset, FIT_FPGA_PROP, NULL);
|
||||||
if (uname)
|
if (uname)
|
||||||
printf("%s FPGA: %s\n", p, uname);
|
printf("%s FPGA: %s\n", p, uname);
|
||||||
|
|
||||||
/* Print out all of the specified loadables */
|
/* Print out all of the specified loadables */
|
||||||
for (loadables_index = 0;
|
for (loadables_index = 0;
|
||||||
fdt_get_string_index(fit, noffset,
|
uname = fdt_stringlist_get(fit, noffset, FIT_LOADABLE_PROP,
|
||||||
FIT_LOADABLE_PROP,
|
loadables_index, NULL), uname;
|
||||||
loadables_index,
|
loadables_index++) {
|
||||||
(const char **)&uname) == 0;
|
|
||||||
loadables_index++)
|
|
||||||
{
|
|
||||||
if (loadables_index == 0) {
|
if (loadables_index == 0) {
|
||||||
printf("%s Loadables: ", p);
|
printf("%s Loadables: ", p);
|
||||||
} else {
|
} else {
|
||||||
|
@ -212,7 +212,7 @@ static int fit_image_verify_sig(const void *fit, int image_noffset,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Process all hash subnodes of the component image node */
|
/* Process all hash subnodes of the component image node */
|
||||||
fdt_for_each_subnode(fit, noffset, image_noffset) {
|
fdt_for_each_subnode(noffset, fit, image_noffset) {
|
||||||
const char *name = fit_get_name(fit, noffset, NULL);
|
const char *name = fit_get_name(fit, noffset, NULL);
|
||||||
|
|
||||||
if (!strncmp(name, FIT_SIG_NODENAME,
|
if (!strncmp(name, FIT_SIG_NODENAME,
|
||||||
@ -260,7 +260,7 @@ int fit_image_verify_required_sigs(const void *fit, int image_noffset,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdt_for_each_subnode(sig_blob, noffset, sig_node) {
|
fdt_for_each_subnode(noffset, sig_blob, sig_node) {
|
||||||
const char *required;
|
const char *required;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ static int fit_config_verify_sig(const void *fit, int conf_noffset,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Process all hash subnodes of the component conf node */
|
/* Process all hash subnodes of the component conf node */
|
||||||
fdt_for_each_subnode(fit, noffset, conf_noffset) {
|
fdt_for_each_subnode(noffset, fit, conf_noffset) {
|
||||||
const char *name = fit_get_name(fit, noffset, NULL);
|
const char *name = fit_get_name(fit, noffset, NULL);
|
||||||
|
|
||||||
if (!strncmp(name, FIT_SIG_NODENAME,
|
if (!strncmp(name, FIT_SIG_NODENAME,
|
||||||
@ -438,7 +438,7 @@ int fit_config_verify_required_sigs(const void *fit, int conf_noffset,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdt_for_each_subnode(sig_blob, noffset, sig_node) {
|
fdt_for_each_subnode(noffset, sig_blob, sig_node) {
|
||||||
const char *required;
|
const char *required;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -1305,7 +1305,7 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
|
|||||||
void *buf;
|
void *buf;
|
||||||
int conf_noffset;
|
int conf_noffset;
|
||||||
int fit_img_result;
|
int fit_img_result;
|
||||||
char *uname, *name;
|
const char *uname, *name;
|
||||||
int err;
|
int err;
|
||||||
int devnum = 0; /* TODO support multi fpga platforms */
|
int devnum = 0; /* TODO support multi fpga platforms */
|
||||||
const fpga_desc * const desc = fpga_get_desc(devnum);
|
const fpga_desc * const desc = fpga_get_desc(devnum);
|
||||||
@ -1332,9 +1332,9 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
|
|||||||
case IMAGE_FORMAT_FIT:
|
case IMAGE_FORMAT_FIT:
|
||||||
conf_noffset = fit_conf_get_node(buf, images->fit_uname_cfg);
|
conf_noffset = fit_conf_get_node(buf, images->fit_uname_cfg);
|
||||||
|
|
||||||
err = fdt_get_string_index(buf, conf_noffset, FIT_FPGA_PROP, 0,
|
uname = fdt_stringlist_get(buf, conf_noffset, FIT_FPGA_PROP, 0,
|
||||||
(const char **)&uname);
|
NULL);
|
||||||
if (err < 0) {
|
if (!uname) {
|
||||||
debug("## FPGA image is not specified\n");
|
debug("## FPGA image is not specified\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1404,7 +1404,7 @@ int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
|
|||||||
int loadables_index;
|
int loadables_index;
|
||||||
int conf_noffset;
|
int conf_noffset;
|
||||||
int fit_img_result;
|
int fit_img_result;
|
||||||
char *uname;
|
const char *uname;
|
||||||
|
|
||||||
/* Check to see if the images struct has a FIT configuration */
|
/* Check to see if the images struct has a FIT configuration */
|
||||||
if (!genimg_has_config(images)) {
|
if (!genimg_has_config(images)) {
|
||||||
@ -1428,15 +1428,14 @@ int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
|
|||||||
conf_noffset = fit_conf_get_node(buf, images->fit_uname_cfg);
|
conf_noffset = fit_conf_get_node(buf, images->fit_uname_cfg);
|
||||||
|
|
||||||
for (loadables_index = 0;
|
for (loadables_index = 0;
|
||||||
fdt_get_string_index(buf, conf_noffset,
|
uname = fdt_stringlist_get(buf, conf_noffset,
|
||||||
FIT_LOADABLE_PROP,
|
FIT_LOADABLE_PROP, loadables_index,
|
||||||
loadables_index,
|
NULL), uname;
|
||||||
(const char **)&uname) == 0;
|
|
||||||
loadables_index++)
|
loadables_index++)
|
||||||
{
|
{
|
||||||
fit_img_result = fit_image_load(images,
|
fit_img_result = fit_image_load(images,
|
||||||
tmp_img_addr,
|
tmp_img_addr,
|
||||||
(const char **)&uname,
|
&uname,
|
||||||
&(images->fit_uname_cfg), arch,
|
&(images->fit_uname_cfg), arch,
|
||||||
IH_TYPE_LOADABLE,
|
IH_TYPE_LOADABLE,
|
||||||
BOOTSTAGE_ID_FIT_LOADABLE_START,
|
BOOTSTAGE_ID_FIT_LOADABLE_START,
|
||||||
|
@ -101,10 +101,10 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)
|
|||||||
|
|
||||||
debug("%s(dev=%p, name=%s, clk=%p)\n", __func__, dev, name, clk);
|
debug("%s(dev=%p, name=%s, clk=%p)\n", __func__, dev, name, clk);
|
||||||
|
|
||||||
index = fdt_find_string(gd->fdt_blob, dev->of_offset, "clock-names",
|
index = fdt_stringlist_search(gd->fdt_blob, dev->of_offset,
|
||||||
name);
|
"clock-names", name);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
debug("fdt_find_string() failed: %d\n", index);
|
debug("fdt_stringlist_search() failed: %d\n", index);
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,7 +698,7 @@ fdt_addr_t dev_get_addr_name(struct udevice *dev, const char *name)
|
|||||||
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
index = fdt_find_string(gd->fdt_blob, dev->of_offset, "reg-names",
|
index = fdt_stringlist_search(gd->fdt_blob, dev->of_offset, "reg-names",
|
||||||
name);
|
name);
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return index;
|
return index;
|
||||||
|
@ -132,7 +132,8 @@ static int gpio_dwapb_bind(struct udevice *dev)
|
|||||||
plat->base = base;
|
plat->base = base;
|
||||||
plat->bank = bank;
|
plat->bank = bank;
|
||||||
plat->pins = fdtdec_get_int(blob, node, "snps,nr-gpios", 0);
|
plat->pins = fdtdec_get_int(blob, node, "snps,nr-gpios", 0);
|
||||||
ret = fdt_get_string(blob, node, "bank-name", &plat->name);
|
plat->name = fdt_stringlist_get(blob, node, "bank-name", 0,
|
||||||
|
NULL);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
@ -773,7 +773,7 @@ static int mxc_i2c_probe(struct udevice *bus)
|
|||||||
* See Documentation/devicetree/bindings/i2c/i2c-imx.txt
|
* See Documentation/devicetree/bindings/i2c/i2c-imx.txt
|
||||||
* Use gpio to force bus idle when necessary.
|
* Use gpio to force bus idle when necessary.
|
||||||
*/
|
*/
|
||||||
ret = fdt_find_string(fdt, node, "pinctrl-names", "gpio");
|
ret = fdt_stringlist_search(fdt, node, "pinctrl-names", "gpio");
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
dev_info(dev, "i2c bus %d at %lu, no gpio pinctrl state.\n", bus->seq, i2c_bus->base);
|
dev_info(dev, "i2c bus %d at %lu, no gpio pinctrl state.\n", bus->seq, i2c_bus->base);
|
||||||
} else {
|
} else {
|
||||||
|
@ -85,10 +85,10 @@ int mbox_get_by_name(struct udevice *dev, const char *name,
|
|||||||
|
|
||||||
debug("%s(dev=%p, name=%s, chan=%p)\n", __func__, dev, name, chan);
|
debug("%s(dev=%p, name=%s, chan=%p)\n", __func__, dev, name, chan);
|
||||||
|
|
||||||
index = fdt_find_string(gd->fdt_blob, dev->of_offset, "mbox-names",
|
index = fdt_stringlist_search(gd->fdt_blob, dev->of_offset,
|
||||||
name);
|
"mbox-names", name);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
debug("fdt_find_string() failed: %d\n", index);
|
debug("fdt_stringlist_search() failed: %d\n", index);
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1348,7 +1348,7 @@ static int cpsw_eth_ofdata_to_platdata(struct udevice *dev)
|
|||||||
active_slave = fdtdec_get_int(fdt, node, "active_slave", 0);
|
active_slave = fdtdec_get_int(fdt, node, "active_slave", 0);
|
||||||
priv->data.active_slave = active_slave;
|
priv->data.active_slave = active_slave;
|
||||||
|
|
||||||
fdt_for_each_subnode(fdt, subnode, node) {
|
fdt_for_each_subnode(subnode, fdt, node) {
|
||||||
int len;
|
int len;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
|
@ -990,7 +990,7 @@ static int ks2_eth_bind_slaves(struct udevice *dev, int gbe, int *gbe_0)
|
|||||||
char *slave_name;
|
char *slave_name;
|
||||||
|
|
||||||
interfaces = fdt_subnode_offset(fdt, gbe, "interfaces");
|
interfaces = fdt_subnode_offset(fdt, gbe, "interfaces");
|
||||||
fdt_for_each_subnode(fdt, slave, interfaces) {
|
fdt_for_each_subnode(slave, fdt, interfaces) {
|
||||||
int slave_no;
|
int slave_no;
|
||||||
|
|
||||||
slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT);
|
slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT);
|
||||||
@ -1015,7 +1015,7 @@ static int ks2_eth_bind_slaves(struct udevice *dev, int gbe, int *gbe_0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sec_slave = fdt_subnode_offset(fdt, gbe, "secondary-slave-ports");
|
sec_slave = fdt_subnode_offset(fdt, gbe, "secondary-slave-ports");
|
||||||
fdt_for_each_subnode(fdt, slave, sec_slave) {
|
fdt_for_each_subnode(slave, fdt, sec_slave) {
|
||||||
int slave_no;
|
int slave_no;
|
||||||
|
|
||||||
slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT);
|
slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT);
|
||||||
|
@ -4153,7 +4153,7 @@ static int mvpp2_base_bind(struct udevice *parent)
|
|||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdt_for_each_subnode(blob, subnode, node) {
|
fdt_for_each_subnode(subnode, blob, node) {
|
||||||
/* Skip disabled ports */
|
/* Skip disabled ports */
|
||||||
if (!fdtdec_get_is_enabled(blob, subnode))
|
if (!fdtdec_get_is_enabled(blob, subnode))
|
||||||
continue;
|
continue;
|
||||||
|
@ -456,8 +456,9 @@ static int parse_phy_pins(struct udevice *dev)
|
|||||||
for (i = 0; ; i++) {
|
for (i = 0; ; i++) {
|
||||||
int pin;
|
int pin;
|
||||||
|
|
||||||
if (fdt_get_string_index(gd->fdt_blob, offset,
|
pin_name = fdt_stringlist_get(gd->fdt_blob, offset,
|
||||||
"allwinner,pins", i, &pin_name))
|
"allwinner,pins", i, NULL);
|
||||||
|
if (!pin_name)
|
||||||
break;
|
break;
|
||||||
if (pin_name[0] != 'P')
|
if (pin_name[0] != 'P')
|
||||||
continue;
|
continue;
|
||||||
|
@ -531,7 +531,7 @@ static int tegra_pcie_parse_dt(const void *fdt, int node, enum tegra_pci_id id,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fdt_for_each_subnode(fdt, subnode, node) {
|
fdt_for_each_subnode(subnode, fdt, node) {
|
||||||
unsigned int index = 0, num_lanes = 0;
|
unsigned int index = 0, num_lanes = 0;
|
||||||
struct tegra_pcie_port *port;
|
struct tegra_pcie_port *port;
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ static int comphy_probe(struct udevice *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
lane = 0;
|
lane = 0;
|
||||||
fdt_for_each_subnode(blob, subnode, node) {
|
fdt_for_each_subnode(subnode, blob, node) {
|
||||||
/* Skip disabled ports */
|
/* Skip disabled ports */
|
||||||
if (!fdtdec_get_is_enabled(blob, subnode))
|
if (!fdtdec_get_is_enabled(blob, subnode))
|
||||||
continue;
|
continue;
|
||||||
|
@ -71,7 +71,7 @@ int exynos_pinctrl_set_state(struct udevice *dev, struct udevice *config)
|
|||||||
{
|
{
|
||||||
const void *fdt = gd->fdt_blob;
|
const void *fdt = gd->fdt_blob;
|
||||||
int node = config->of_offset;
|
int node = config->of_offset;
|
||||||
unsigned int count, idx, pin_num, ret;
|
unsigned int count, idx, pin_num;
|
||||||
unsigned int pinfunc, pinpud, pindrv;
|
unsigned int pinfunc, pinpud, pindrv;
|
||||||
unsigned long reg, value;
|
unsigned long reg, value;
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -80,7 +80,7 @@ int exynos_pinctrl_set_state(struct udevice *dev, struct udevice *config)
|
|||||||
* refer to the following document for the pinctrl bindings
|
* refer to the following document for the pinctrl bindings
|
||||||
* linux/Documentation/devicetree/bindings/pinctrl/samsung-pinctrl.txt
|
* linux/Documentation/devicetree/bindings/pinctrl/samsung-pinctrl.txt
|
||||||
*/
|
*/
|
||||||
count = fdt_count_strings(fdt, node, "samsung,pins");
|
count = fdt_stringlist_count(fdt, node, "samsung,pins");
|
||||||
if (count <= 0)
|
if (count <= 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
@ -89,9 +89,8 @@ int exynos_pinctrl_set_state(struct udevice *dev, struct udevice *config)
|
|||||||
pindrv = fdtdec_get_int(fdt, node, "samsung,pin-drv", -1);
|
pindrv = fdtdec_get_int(fdt, node, "samsung,pin-drv", -1);
|
||||||
|
|
||||||
for (idx = 0; idx < count; idx++) {
|
for (idx = 0; idx < count; idx++) {
|
||||||
ret = fdt_get_string_index(fdt, node, "samsung,pins",
|
name = fdt_stringlist_get(fdt, node, "samsung,pins", idx, NULL);
|
||||||
idx, &name);
|
if (!name)
|
||||||
if (ret < 0)
|
|
||||||
continue;
|
continue;
|
||||||
reg = pin_to_bank_base(dev, name, &pin_num);
|
reg = pin_to_bank_base(dev, name, &pin_num);
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ static fdt_addr_t parse_address(int offset, const char *name, int na, int ns)
|
|||||||
int index, len = 0;
|
int index, len = 0;
|
||||||
const fdt32_t *reg;
|
const fdt32_t *reg;
|
||||||
|
|
||||||
index = fdt_find_string(gd->fdt_blob, offset, "reg-names", name);
|
index = fdt_stringlist_search(gd->fdt_blob, offset, "reg-names", name);
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return FDT_ADDR_T_NONE;
|
return FDT_ADDR_T_NONE;
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ int meson_pinctrl_probe(struct udevice *dev)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdt_for_each_subnode(gd->fdt_blob, node, dev->of_offset) {
|
fdt_for_each_subnode(node, gd->fdt_blob, dev->of_offset) {
|
||||||
if (fdt_getprop(gd->fdt_blob, node, "gpio-controller", &len)) {
|
if (fdt_getprop(gd->fdt_blob, node, "gpio-controller", &len)) {
|
||||||
gpio = node;
|
gpio = node;
|
||||||
break;
|
break;
|
||||||
|
@ -306,11 +306,11 @@ static int pinctrl_generic_set_state_subnode(struct udevice *dev,
|
|||||||
const char *name;
|
const char *name;
|
||||||
int strings_count, selector, i, ret;
|
int strings_count, selector, i, ret;
|
||||||
|
|
||||||
strings_count = fdt_count_strings(fdt, node, subnode_target_type);
|
strings_count = fdt_stringlist_count(fdt, node, subnode_target_type);
|
||||||
if (strings_count < 0) {
|
if (strings_count < 0) {
|
||||||
subnode_target_type = "groups";
|
subnode_target_type = "groups";
|
||||||
is_group = true;
|
is_group = true;
|
||||||
strings_count = fdt_count_strings(fdt, node,
|
strings_count = fdt_stringlist_count(fdt, node,
|
||||||
subnode_target_type);
|
subnode_target_type);
|
||||||
if (strings_count < 0) {
|
if (strings_count < 0) {
|
||||||
/* skip this node; may contain config child nodes */
|
/* skip this node; may contain config child nodes */
|
||||||
@ -319,9 +319,9 @@ static int pinctrl_generic_set_state_subnode(struct udevice *dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < strings_count; i++) {
|
for (i = 0; i < strings_count; i++) {
|
||||||
ret = fdt_get_string_index(fdt, node, subnode_target_type,
|
name = fdt_stringlist_get(fdt, node, subnode_target_type, i,
|
||||||
i, &name);
|
NULL);
|
||||||
if (ret < 0)
|
if (!name)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (is_group)
|
if (is_group)
|
||||||
|
@ -72,7 +72,7 @@ static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
|
|||||||
struct udevice *config;
|
struct udevice *config;
|
||||||
int state, size, i, ret;
|
int state, size, i, ret;
|
||||||
|
|
||||||
state = fdt_find_string(fdt, node, "pinctrl-names", statename);
|
state = fdt_stringlist_search(fdt, node, "pinctrl-names", statename);
|
||||||
if (state < 0) {
|
if (state < 0) {
|
||||||
char *end;
|
char *end;
|
||||||
/*
|
/*
|
||||||
|
@ -52,7 +52,7 @@ static int palmas_bind(struct udevice *dev)
|
|||||||
int node = dev->of_offset;
|
int node = dev->of_offset;
|
||||||
int subnode, len;
|
int subnode, len;
|
||||||
|
|
||||||
fdt_for_each_subnode(blob, subnode, node) {
|
fdt_for_each_subnode(subnode, blob, node) {
|
||||||
const char *name;
|
const char *name;
|
||||||
char *temp;
|
char *temp;
|
||||||
|
|
||||||
|
@ -88,10 +88,10 @@ int reset_get_by_name(struct udevice *dev, const char *name,
|
|||||||
debug("%s(dev=%p, name=%s, reset_ctl=%p)\n", __func__, dev, name,
|
debug("%s(dev=%p, name=%s, reset_ctl=%p)\n", __func__, dev, name,
|
||||||
reset_ctl);
|
reset_ctl);
|
||||||
|
|
||||||
index = fdt_find_string(gd->fdt_blob, dev->of_offset, "reset-names",
|
index = fdt_stringlist_search(gd->fdt_blob, dev->of_offset,
|
||||||
name);
|
"reset-names", name);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
debug("fdt_find_string() failed: %d\n", index);
|
debug("fdt_stringlist_search() failed: %d\n", index);
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1098,7 +1098,7 @@ static int fsl_qspi_ofdata_to_platdata(struct udevice *bus)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Count flash numbers */
|
/* Count flash numbers */
|
||||||
fdt_for_each_subnode(blob, subnode, node)
|
fdt_for_each_subnode(subnode, blob, node)
|
||||||
++flash_num;
|
++flash_num;
|
||||||
|
|
||||||
if (flash_num == 0) {
|
if (flash_num == 0) {
|
||||||
|
@ -1562,7 +1562,7 @@ int sunxi_simplefb_setup(void *blob)
|
|||||||
offset = fdt_node_offset_by_compatible(blob, -1,
|
offset = fdt_node_offset_by_compatible(blob, -1,
|
||||||
"allwinner,simple-framebuffer");
|
"allwinner,simple-framebuffer");
|
||||||
while (offset >= 0) {
|
while (offset >= 0) {
|
||||||
ret = fdt_find_string(blob, offset, "allwinner,pipeline",
|
ret = fdt_stringlist_search(blob, offset, "allwinner,pipeline",
|
||||||
pipeline);
|
pipeline);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -167,7 +167,15 @@ void ft_pci_setup(void *blob, bd_t *bd);
|
|||||||
int ft_system_setup(void *blob, bd_t *bd);
|
int ft_system_setup(void *blob, bd_t *bd);
|
||||||
|
|
||||||
void set_working_fdt_addr(ulong addr);
|
void set_working_fdt_addr(ulong addr);
|
||||||
int fdt_shrink_to_minimum(void *blob);
|
|
||||||
|
/**
|
||||||
|
* shrink down the given blob to minimum size + some extrasize if required
|
||||||
|
*
|
||||||
|
* @param blob FDT blob to update
|
||||||
|
* @param extrasize additional bytes needed
|
||||||
|
* @return 0 if ok, or -FDT_ERR_... on error
|
||||||
|
*/
|
||||||
|
int fdt_shrink_to_minimum(void *blob, uint extrasize);
|
||||||
int fdt_increase_size(void *fdt, int add_len);
|
int fdt_increase_size(void *fdt, int add_len);
|
||||||
|
|
||||||
int fdt_fixup_nor_flash_size(void *blob);
|
int fdt_fixup_nor_flash_size(void *blob);
|
||||||
|
187
include/libfdt.h
187
include/libfdt.h
@ -61,7 +61,7 @@
|
|||||||
#define FDT_ERR_NOTFOUND 1
|
#define FDT_ERR_NOTFOUND 1
|
||||||
/* FDT_ERR_NOTFOUND: The requested node or property does not exist */
|
/* FDT_ERR_NOTFOUND: The requested node or property does not exist */
|
||||||
#define FDT_ERR_EXISTS 2
|
#define FDT_ERR_EXISTS 2
|
||||||
/* FDT_ERR_EXISTS: Attemped to create a node or property which
|
/* FDT_ERR_EXISTS: Attempted to create a node or property which
|
||||||
* already exists */
|
* already exists */
|
||||||
#define FDT_ERR_NOSPACE 3
|
#define FDT_ERR_NOSPACE 3
|
||||||
/* FDT_ERR_NOSPACE: Operation needed to expand the device
|
/* FDT_ERR_NOSPACE: Operation needed to expand the device
|
||||||
@ -121,12 +121,17 @@
|
|||||||
/* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
|
/* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
|
||||||
* or similar property with a bad format or value */
|
* or similar property with a bad format or value */
|
||||||
|
|
||||||
#define FDT_ERR_TOODEEP 15
|
#define FDT_ERR_BADVALUE 15
|
||||||
|
/* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
|
||||||
|
* value. For example: a property expected to contain a string list
|
||||||
|
* is not NUL-terminated within the length of its value. */
|
||||||
|
|
||||||
|
#define FDT_ERR_TOODEEP 16
|
||||||
/* FDT_ERR_TOODEEP: The depth of a node has exceeded the internal
|
/* FDT_ERR_TOODEEP: The depth of a node has exceeded the internal
|
||||||
* libfdt limit. This can happen if you have more than
|
* libfdt limit. This can happen if you have more than
|
||||||
* FDT_MAX_DEPTH nested nodes. */
|
* FDT_MAX_DEPTH nested nodes. */
|
||||||
|
|
||||||
#define FDT_ERR_MAX 15
|
#define FDT_ERR_MAX 16
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Low-level functions (you probably don't need these) */
|
/* Low-level functions (you probably don't need these) */
|
||||||
@ -171,24 +176,27 @@ int fdt_next_subnode(const void *fdt, int offset);
|
|||||||
/**
|
/**
|
||||||
* fdt_for_each_subnode - iterate over all subnodes of a parent
|
* fdt_for_each_subnode - iterate over all subnodes of a parent
|
||||||
*
|
*
|
||||||
|
* @node: child node (int, lvalue)
|
||||||
|
* @fdt: FDT blob (const void *)
|
||||||
|
* @parent: parent node (int)
|
||||||
|
*
|
||||||
* This is actually a wrapper around a for loop and would be used like so:
|
* This is actually a wrapper around a for loop and would be used like so:
|
||||||
*
|
*
|
||||||
* fdt_for_each_subnode(fdt, node, parent) {
|
* fdt_for_each_subnode(node, fdt, parent) {
|
||||||
* ...
|
* Use node
|
||||||
* use node
|
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Note that this is implemented as a macro and node is used as iterator in
|
* if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) {
|
||||||
* the loop. It should therefore be a locally allocated variable. The parent
|
* Error handling
|
||||||
* variable on the other hand is never modified, so it can be constant or
|
* }
|
||||||
* even a literal.
|
*
|
||||||
|
* Note that this is implemented as a macro and @node is used as
|
||||||
|
* iterator in the loop. The parent variable be constant or even a
|
||||||
|
* literal.
|
||||||
*
|
*
|
||||||
* @fdt: FDT blob (const void *)
|
|
||||||
* @node: child node (int)
|
|
||||||
* @parent: parent node (int)
|
|
||||||
*/
|
*/
|
||||||
#define fdt_for_each_subnode(fdt, node, parent) \
|
#define fdt_for_each_subnode(node, fdt, parent) \
|
||||||
for (node = fdt_first_subnode(fdt, parent); \
|
for (node = fdt_first_subnode(fdt, parent); \
|
||||||
node >= 0; \
|
node >= 0; \
|
||||||
node = fdt_next_subnode(fdt, node))
|
node = fdt_next_subnode(fdt, node))
|
||||||
@ -213,7 +221,7 @@ int fdt_next_subnode(const void *fdt, int offset);
|
|||||||
#define __fdt_set_hdr(name) \
|
#define __fdt_set_hdr(name) \
|
||||||
static inline void fdt_set_##name(void *fdt, uint32_t val) \
|
static inline void fdt_set_##name(void *fdt, uint32_t val) \
|
||||||
{ \
|
{ \
|
||||||
struct fdt_header *fdth = (struct fdt_header*)fdt; \
|
struct fdt_header *fdth = (struct fdt_header *)fdt; \
|
||||||
fdth->name = cpu_to_fdt32(val); \
|
fdth->name = cpu_to_fdt32(val); \
|
||||||
}
|
}
|
||||||
__fdt_set_hdr(magic);
|
__fdt_set_hdr(magic);
|
||||||
@ -288,11 +296,13 @@ const char *fdt_string(const void *fdt, int stroffset);
|
|||||||
* @fdt: pointer to the device tree blob
|
* @fdt: pointer to the device tree blob
|
||||||
*
|
*
|
||||||
* fdt_get_max_phandle retrieves the highest phandle in the given
|
* fdt_get_max_phandle retrieves the highest phandle in the given
|
||||||
* device tree
|
* device tree. This will ignore badly formatted phandles, or phandles
|
||||||
|
* with a value of 0 or -1.
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* the highest phandle on success
|
* the highest phandle on success
|
||||||
* 0, if an error occurred
|
* 0, if no phandle was found in the device tree
|
||||||
|
* -1, if an error occurred
|
||||||
*/
|
*/
|
||||||
uint32_t fdt_get_max_phandle(const void *fdt);
|
uint32_t fdt_get_max_phandle(const void *fdt);
|
||||||
|
|
||||||
@ -356,8 +366,9 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
|
|||||||
* returns:
|
* returns:
|
||||||
* structure block offset of the requested subnode (>=0), on success
|
* structure block offset of the requested subnode (>=0), on success
|
||||||
* -FDT_ERR_NOTFOUND, if the requested subnode does not exist
|
* -FDT_ERR_NOTFOUND, if the requested subnode does not exist
|
||||||
* -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
|
* -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
|
||||||
* -FDT_ERR_BADMAGIC,
|
* tag
|
||||||
|
* -FDT_ERR_BADMAGIC,
|
||||||
* -FDT_ERR_BADVERSION,
|
* -FDT_ERR_BADVERSION,
|
||||||
* -FDT_ERR_BADSTATE,
|
* -FDT_ERR_BADSTATE,
|
||||||
* -FDT_ERR_BADSTRUCTURE,
|
* -FDT_ERR_BADSTRUCTURE,
|
||||||
@ -366,13 +377,13 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
|
|||||||
int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
|
int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_path_offset_namelen - find a tree node based on substring
|
* fdt_path_offset_namelen - find a tree node by its full path
|
||||||
* @fdt: pointer to the device tree blob
|
* @fdt: pointer to the device tree blob
|
||||||
* @path: full path of the node to locate
|
* @path: full path of the node to locate
|
||||||
* @namelen: number of characters of name to consider
|
* @namelen: number of characters of path to consider
|
||||||
*
|
*
|
||||||
* Identical to fdt_path_offset(), but only examine the first
|
* Identical to fdt_path_offset(), but only consider the first namelen
|
||||||
* namelen characters of path for matching the node path.
|
* characters of path as the path name.
|
||||||
*/
|
*/
|
||||||
int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
|
int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
|
||||||
|
|
||||||
@ -389,7 +400,8 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
|
|||||||
* address).
|
* address).
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* structure block offset of the node with the requested path (>=0), on success
|
* structure block offset of the node with the requested path (>=0), on
|
||||||
|
* success
|
||||||
* -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
|
* -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid
|
||||||
* -FDT_ERR_NOTFOUND, if the requested node does not exist
|
* -FDT_ERR_NOTFOUND, if the requested node does not exist
|
||||||
* -FDT_ERR_BADMAGIC,
|
* -FDT_ERR_BADMAGIC,
|
||||||
@ -398,10 +410,7 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
|
|||||||
* -FDT_ERR_BADSTRUCTURE,
|
* -FDT_ERR_BADSTRUCTURE,
|
||||||
* -FDT_ERR_TRUNCATED, standard meanings.
|
* -FDT_ERR_TRUNCATED, standard meanings.
|
||||||
*/
|
*/
|
||||||
static inline int fdt_path_offset(const void *fdt, const char *path)
|
int fdt_path_offset(const void *fdt, const char *path);
|
||||||
{
|
|
||||||
return fdt_path_offset_namelen(fdt, path, strlen(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_get_name - retrieve the name of a given node
|
* fdt_get_name - retrieve the name of a given node
|
||||||
@ -416,10 +425,12 @@ static inline int fdt_path_offset(const void *fdt, const char *path)
|
|||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to the node's name, on success
|
* pointer to the node's name, on success
|
||||||
* If lenp is non-NULL, *lenp contains the length of that name (>=0)
|
* If lenp is non-NULL, *lenp contains the length of that name
|
||||||
|
* (>=0)
|
||||||
* NULL, on error
|
* NULL, on error
|
||||||
* if lenp is non-NULL *lenp contains an error code (<0):
|
* if lenp is non-NULL *lenp contains an error code (<0):
|
||||||
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
|
||||||
|
* tag
|
||||||
* -FDT_ERR_BADMAGIC,
|
* -FDT_ERR_BADMAGIC,
|
||||||
* -FDT_ERR_BADVERSION,
|
* -FDT_ERR_BADVERSION,
|
||||||
* -FDT_ERR_BADSTATE, standard meanings
|
* -FDT_ERR_BADSTATE, standard meanings
|
||||||
@ -468,23 +479,26 @@ int fdt_first_property_offset(const void *fdt, int nodeoffset);
|
|||||||
int fdt_next_property_offset(const void *fdt, int offset);
|
int fdt_next_property_offset(const void *fdt, int offset);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_for_each_property - iterate over all properties of a node
|
* fdt_for_each_property_offset - iterate over all properties of a node
|
||||||
* @property_offset: property offset (int)
|
*
|
||||||
|
* @property_offset: property offset (int, lvalue)
|
||||||
* @fdt: FDT blob (const void *)
|
* @fdt: FDT blob (const void *)
|
||||||
* @node: node offset (int)
|
* @node: node offset (int)
|
||||||
*
|
*
|
||||||
* This is actually a wrapper around a for loop and would be used like so:
|
* This is actually a wrapper around a for loop and would be used like so:
|
||||||
*
|
*
|
||||||
* fdt_for_each_property(fdt, node, property) {
|
* fdt_for_each_property_offset(property, fdt, node) {
|
||||||
* ...
|
* Use property
|
||||||
* use property
|
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
|
* if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) {
|
||||||
|
* Error handling
|
||||||
|
* }
|
||||||
|
*
|
||||||
* Note that this is implemented as a macro and property is used as
|
* Note that this is implemented as a macro and property is used as
|
||||||
* iterator in the loop. It should therefore be a locally allocated
|
* iterator in the loop. The node variable can be constant or even a
|
||||||
* variable. The node variable on the other hand is never modified, so
|
* literal.
|
||||||
* it can be constant or even a literal.
|
|
||||||
*/
|
*/
|
||||||
#define fdt_for_each_property_offset(property, fdt, node) \
|
#define fdt_for_each_property_offset(property, fdt, node) \
|
||||||
for (property = fdt_first_property_offset(fdt, node); \
|
for (property = fdt_first_property_offset(fdt, node); \
|
||||||
@ -527,8 +541,8 @@ const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
|
|||||||
* @namelen: number of characters of name to consider
|
* @namelen: number of characters of name to consider
|
||||||
* @lenp: pointer to an integer variable (will be overwritten) or NULL
|
* @lenp: pointer to an integer variable (will be overwritten) or NULL
|
||||||
*
|
*
|
||||||
* Identical to fdt_get_property_namelen(), but only examine the first
|
* Identical to fdt_get_property(), but only examine the first namelen
|
||||||
* namelen characters of name for matching the property name.
|
* characters of name for matching the property name.
|
||||||
*/
|
*/
|
||||||
const struct fdt_property *fdt_get_property_namelen(const void *fdt,
|
const struct fdt_property *fdt_get_property_namelen(const void *fdt,
|
||||||
int nodeoffset,
|
int nodeoffset,
|
||||||
@ -555,7 +569,8 @@ const struct fdt_property *fdt_get_property_namelen(const void *fdt,
|
|||||||
* NULL, on error
|
* NULL, on error
|
||||||
* if lenp is non-NULL, *lenp contains an error code (<0):
|
* if lenp is non-NULL, *lenp contains an error code (<0):
|
||||||
* -FDT_ERR_NOTFOUND, node does not have named property
|
* -FDT_ERR_NOTFOUND, node does not have named property
|
||||||
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
|
||||||
|
* tag
|
||||||
* -FDT_ERR_BADMAGIC,
|
* -FDT_ERR_BADMAGIC,
|
||||||
* -FDT_ERR_BADVERSION,
|
* -FDT_ERR_BADVERSION,
|
||||||
* -FDT_ERR_BADSTATE,
|
* -FDT_ERR_BADSTATE,
|
||||||
@ -647,7 +662,8 @@ static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,
|
|||||||
* NULL, on error
|
* NULL, on error
|
||||||
* if lenp is non-NULL, *lenp contains an error code (<0):
|
* if lenp is non-NULL, *lenp contains an error code (<0):
|
||||||
* -FDT_ERR_NOTFOUND, node does not have named property
|
* -FDT_ERR_NOTFOUND, node does not have named property
|
||||||
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
|
||||||
|
* tag
|
||||||
* -FDT_ERR_BADMAGIC,
|
* -FDT_ERR_BADMAGIC,
|
||||||
* -FDT_ERR_BADVERSION,
|
* -FDT_ERR_BADVERSION,
|
||||||
* -FDT_ERR_BADSTATE,
|
* -FDT_ERR_BADSTATE,
|
||||||
@ -689,7 +705,7 @@ const char *fdt_get_alias_namelen(const void *fdt,
|
|||||||
const char *name, int namelen);
|
const char *name, int namelen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_get_alias - retreive the path referenced by a given alias
|
* fdt_get_alias - retrieve the path referenced by a given alias
|
||||||
* @fdt: pointer to the device tree blob
|
* @fdt: pointer to the device tree blob
|
||||||
* @name: name of the alias th look up
|
* @name: name of the alias th look up
|
||||||
*
|
*
|
||||||
@ -749,11 +765,11 @@ int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
|
|||||||
* structure from the start to nodeoffset.
|
* structure from the start to nodeoffset.
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
|
|
||||||
* structure block offset of the node at node offset's ancestor
|
* structure block offset of the node at node offset's ancestor
|
||||||
* of depth supernodedepth (>=0), on success
|
* of depth supernodedepth (>=0), on success
|
||||||
* -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
|
* -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag
|
||||||
* -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset
|
* -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of
|
||||||
|
* nodeoffset
|
||||||
* -FDT_ERR_BADMAGIC,
|
* -FDT_ERR_BADMAGIC,
|
||||||
* -FDT_ERR_BADVERSION,
|
* -FDT_ERR_BADVERSION,
|
||||||
* -FDT_ERR_BADSTATE,
|
* -FDT_ERR_BADSTATE,
|
||||||
@ -946,51 +962,66 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
|
|||||||
int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
|
int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_count_strings - count the number of strings in a string list
|
* fdt_stringlist_count - count the number of strings in a string list
|
||||||
* @fdt: pointer to the device tree blob
|
* @fdt: pointer to the device tree blob
|
||||||
* @node: offset of the node
|
* @nodeoffset: offset of a tree node
|
||||||
* @property: name of the property containing the string list
|
* @property: name of the property containing the string list
|
||||||
* @return: the number of strings in the given property
|
* @return:
|
||||||
|
* the number of strings in the given property
|
||||||
|
* -FDT_ERR_BADVALUE if the property value is not NUL-terminated
|
||||||
|
* -FDT_ERR_NOTFOUND if the property does not exist
|
||||||
*/
|
*/
|
||||||
int fdt_count_strings(const void *fdt, int node, const char *property);
|
int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_find_string - find a string in a string list and return its index
|
* fdt_stringlist_search - find a string in a string list and return its index
|
||||||
* @fdt: pointer to the device tree blob
|
* @fdt: pointer to the device tree blob
|
||||||
* @node: offset of the node
|
* @nodeoffset: offset of a tree node
|
||||||
* @property: name of the property containing the string list
|
* @property: name of the property containing the string list
|
||||||
* @string: string to look up in the string list
|
* @string: string to look up in the string list
|
||||||
* @return: the index of the string or negative on error
|
*
|
||||||
|
* Note that it is possible for this function to succeed on property values
|
||||||
|
* that are not NUL-terminated. That's because the function will stop after
|
||||||
|
* finding the first occurrence of @string. This can for example happen with
|
||||||
|
* small-valued cell properties, such as #address-cells, when searching for
|
||||||
|
* the empty string.
|
||||||
|
*
|
||||||
|
* @return:
|
||||||
|
* the index of the string in the list of strings
|
||||||
|
* -FDT_ERR_BADVALUE if the property value is not NUL-terminated
|
||||||
|
* -FDT_ERR_NOTFOUND if the property does not exist or does not contain
|
||||||
|
* the given string
|
||||||
*/
|
*/
|
||||||
int fdt_find_string(const void *fdt, int node, const char *property,
|
int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
|
||||||
const char *string);
|
const char *string);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_get_string_index() - obtain the string at a given index in a string list
|
* fdt_stringlist_get() - obtain the string at a given index in a string list
|
||||||
* @fdt: pointer to the device tree blob
|
* @fdt: pointer to the device tree blob
|
||||||
* @node: offset of the node
|
* @nodeoffset: offset of a tree node
|
||||||
* @property: name of the property containing the string list
|
* @property: name of the property containing the string list
|
||||||
* @index: index of the string to return
|
* @index: index of the string to return
|
||||||
* @output: return location for the string
|
* @lenp: return location for the string length or an error code on failure
|
||||||
* @return: 0 if the string was found or a negative error code otherwise
|
|
||||||
*/
|
|
||||||
int fdt_get_string_index(const void *fdt, int node, const char *property,
|
|
||||||
int index, const char **output);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fdt_get_string() - obtain the first string in a string list
|
|
||||||
* @fdt: pointer to the device tree blob
|
|
||||||
* @node: offset of the node
|
|
||||||
* @property: name of the property containing the string list
|
|
||||||
* @output: return location for the string
|
|
||||||
* @return: 0 if the string was found or a negative error code otherwise
|
|
||||||
*
|
*
|
||||||
* This is a shortcut for:
|
* Note that this will successfully extract strings from properties with
|
||||||
|
* non-NUL-terminated values. For example on small-valued cell properties
|
||||||
|
* this function will return the empty string.
|
||||||
*
|
*
|
||||||
* fdt_get_string_index(fdt, node, property, 0, output).
|
* If non-NULL, the length of the string (on success) or a negative error-code
|
||||||
|
* (on failure) will be stored in the integer pointer to by lenp.
|
||||||
|
*
|
||||||
|
* @return:
|
||||||
|
* A pointer to the string at the given index in the string list or NULL on
|
||||||
|
* failure. On success the length of the string will be stored in the memory
|
||||||
|
* location pointed to by the lenp parameter, if non-NULL. On failure one of
|
||||||
|
* the following negative error codes will be returned in the lenp parameter
|
||||||
|
* (if non-NULL):
|
||||||
|
* -FDT_ERR_BADVALUE if the property value is not NUL-terminated
|
||||||
|
* -FDT_ERR_NOTFOUND if the property does not exist
|
||||||
*/
|
*/
|
||||||
int fdt_get_string(const void *fdt, int node, const char *property,
|
const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
|
||||||
const char **output);
|
const char *property, int index,
|
||||||
|
int *lenp);
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Read-only functions (addressing related) */
|
/* Read-only functions (addressing related) */
|
||||||
@ -1060,7 +1091,7 @@ int fdt_size_cells(const void *fdt, int nodeoffset);
|
|||||||
* @nodeoffset: offset of the node whose property to change
|
* @nodeoffset: offset of the node whose property to change
|
||||||
* @name: name of the property to change
|
* @name: name of the property to change
|
||||||
* @namelen: number of characters of name to consider
|
* @namelen: number of characters of name to consider
|
||||||
* @index: index of the property to change in the array
|
* @idx: index of the property to change in the array
|
||||||
* @val: pointer to data to replace the property value with
|
* @val: pointer to data to replace the property value with
|
||||||
* @len: length of the property value
|
* @len: length of the property value
|
||||||
*
|
*
|
||||||
@ -1071,7 +1102,7 @@ int fdt_size_cells(const void *fdt, int nodeoffset);
|
|||||||
*/
|
*/
|
||||||
int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
|
int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
|
||||||
const char *name, int namelen,
|
const char *name, int namelen,
|
||||||
uint32_t index, const void *val,
|
uint32_t idx, const void *val,
|
||||||
int len);
|
int len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1700,9 +1731,11 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
|
|||||||
* change the offsets of some existing nodes.
|
* change the offsets of some existing nodes.
|
||||||
|
|
||||||
* returns:
|
* returns:
|
||||||
* structure block offset of the created nodeequested subnode (>=0), on success
|
* structure block offset of the created nodeequested subnode (>=0), on
|
||||||
|
* success
|
||||||
* -FDT_ERR_NOTFOUND, if the requested subnode does not exist
|
* -FDT_ERR_NOTFOUND, if the requested subnode does not exist
|
||||||
* -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
|
* -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE
|
||||||
|
* tag
|
||||||
* -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
|
* -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
|
||||||
* the given name
|
* the given name
|
||||||
* -FDT_ERR_NOSPACE, if there is insufficient free space in the
|
* -FDT_ERR_NOSPACE, if there is insufficient free space in the
|
||||||
|
@ -836,7 +836,7 @@ int fdtdec_get_child_count(const void *blob, int node)
|
|||||||
int subnode;
|
int subnode;
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
|
||||||
fdt_for_each_subnode(blob, subnode, node)
|
fdt_for_each_subnode(subnode, blob, node)
|
||||||
num++;
|
num++;
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
@ -1014,7 +1014,7 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property,
|
|||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
index = fdt_find_string(fdt, node, prop_names, name);
|
index = fdt_stringlist_search(fdt, node, prop_names, name);
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return index;
|
return index;
|
||||||
|
|
||||||
|
@ -35,18 +35,19 @@ int fdt_check_header(const void *fdt)
|
|||||||
|
|
||||||
const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
|
const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
|
||||||
{
|
{
|
||||||
const char *p;
|
unsigned absoffset = offset + fdt_off_dt_struct(fdt);
|
||||||
|
|
||||||
|
if ((absoffset < offset)
|
||||||
|
|| ((absoffset + len) < absoffset)
|
||||||
|
|| (absoffset + len) > fdt_totalsize(fdt))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (fdt_version(fdt) >= 0x11)
|
if (fdt_version(fdt) >= 0x11)
|
||||||
if (((offset + len) < offset)
|
if (((offset + len) < offset)
|
||||||
|| ((offset + len) > fdt_size_dt_struct(fdt)))
|
|| ((offset + len) > fdt_size_dt_struct(fdt)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
p = _fdt_offset_ptr(fdt, offset);
|
return _fdt_offset_ptr(fdt, offset);
|
||||||
|
|
||||||
if (p + len < p)
|
|
||||||
return NULL;
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
|
uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
|
||||||
|
@ -146,7 +146,7 @@ static int overlay_adjust_node_phandles(void *fdto, int node,
|
|||||||
if (!found && !ret)
|
if (!found && !ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
fdt_for_each_subnode(fdto, child, node)
|
fdt_for_each_subnode(child, fdto, node)
|
||||||
overlay_adjust_node_phandles(fdto, child, delta);
|
overlay_adjust_node_phandles(fdto, child, delta);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -248,7 +248,7 @@ static int overlay_update_local_node_references(void *fdto,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fdt_for_each_subnode(fdto, fixup_child, fixup_node) {
|
fdt_for_each_subnode(fixup_child, fdto, fixup_node) {
|
||||||
const char *fixup_child_name = fdt_get_name(fdto, fixup_child,
|
const char *fixup_child_name = fdt_get_name(fdto, fixup_child,
|
||||||
NULL);
|
NULL);
|
||||||
int tree_child;
|
int tree_child;
|
||||||
@ -511,7 +511,7 @@ static int overlay_apply_node(void *fdt, int target,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdt_for_each_subnode(fdto, node, fragment) {
|
fdt_for_each_subnode(node, fdto, fragment) {
|
||||||
const char *name = fdt_get_name(fdto, node, NULL);
|
const char *name = fdt_get_name(fdto, node, NULL);
|
||||||
int nnode;
|
int nnode;
|
||||||
int ret;
|
int ret;
|
||||||
@ -550,7 +550,7 @@ static int overlay_merge(void *dt, void *dto)
|
|||||||
{
|
{
|
||||||
int fragment;
|
int fragment;
|
||||||
|
|
||||||
fdt_for_each_subnode(dto, fragment, 0) {
|
fdt_for_each_subnode(fragment, dto, 0) {
|
||||||
int overlay;
|
int overlay;
|
||||||
int target;
|
int target;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -60,11 +60,11 @@ uint32_t fdt_get_max_phandle(const void *fdt)
|
|||||||
return max_phandle;
|
return max_phandle;
|
||||||
|
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
return 0;
|
return (uint32_t)-1;
|
||||||
|
|
||||||
phandle = fdt_get_phandle(fdt, offset);
|
phandle = fdt_get_phandle(fdt, offset);
|
||||||
if (phandle == (uint32_t)-1)
|
if (phandle == (uint32_t)-1)
|
||||||
return 0;
|
continue;
|
||||||
|
|
||||||
if (phandle > max_phandle)
|
if (phandle > max_phandle)
|
||||||
max_phandle = phandle;
|
max_phandle = phandle;
|
||||||
@ -204,6 +204,11 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fdt_path_offset(const void *fdt, const char *path)
|
||||||
|
{
|
||||||
|
return fdt_path_offset_namelen(fdt, path, strlen(path));
|
||||||
|
}
|
||||||
|
|
||||||
const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
|
const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
|
||||||
{
|
{
|
||||||
const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset);
|
const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset);
|
||||||
@ -538,80 +543,104 @@ int fdt_stringlist_contains(const char *strlist, int listlen, const char *str)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdt_count_strings(const void *fdt, int node, const char *property)
|
int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property)
|
||||||
{
|
{
|
||||||
int length, i, count = 0;
|
const char *list, *end;
|
||||||
const char *list;
|
int length, count = 0;
|
||||||
|
|
||||||
list = fdt_getprop(fdt, node, property, &length);
|
list = fdt_getprop(fdt, nodeoffset, property, &length);
|
||||||
if (!list)
|
if (!list)
|
||||||
return length;
|
return -length;
|
||||||
|
|
||||||
for (i = 0; i < length; i++) {
|
end = list + length;
|
||||||
int len = strlen(list);
|
|
||||||
|
|
||||||
list += len + 1;
|
while (list < end) {
|
||||||
i += len;
|
length = strnlen(list, end - list) + 1;
|
||||||
|
|
||||||
|
/* Abort if the last string isn't properly NUL-terminated. */
|
||||||
|
if (list + length > end)
|
||||||
|
return -FDT_ERR_BADVALUE;
|
||||||
|
|
||||||
|
list += length;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdt_find_string(const void *fdt, int node, const char *property,
|
int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
|
||||||
const char *string)
|
const char *string)
|
||||||
{
|
{
|
||||||
|
int length, len, idx = 0;
|
||||||
const char *list, *end;
|
const char *list, *end;
|
||||||
int len, index = 0;
|
|
||||||
|
|
||||||
list = fdt_getprop(fdt, node, property, &len);
|
list = fdt_getprop(fdt, nodeoffset, property, &length);
|
||||||
if (!list)
|
if (!list)
|
||||||
return len;
|
return -length;
|
||||||
|
|
||||||
end = list + len;
|
len = strlen(string) + 1;
|
||||||
len = strlen(string);
|
end = list + length;
|
||||||
|
|
||||||
while (list < end) {
|
while (list < end) {
|
||||||
int l = strlen(list);
|
length = strnlen(list, end - list) + 1;
|
||||||
|
|
||||||
if (l == len && memcmp(list, string, len) == 0)
|
/* Abort if the last string isn't properly NUL-terminated. */
|
||||||
return index;
|
if (list + length > end)
|
||||||
|
return -FDT_ERR_BADVALUE;
|
||||||
|
|
||||||
list += l + 1;
|
if (length == len && memcmp(list, string, length) == 0)
|
||||||
index++;
|
return idx;
|
||||||
|
|
||||||
|
list += length;
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -FDT_ERR_NOTFOUND;
|
return -FDT_ERR_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdt_get_string_index(const void *fdt, int node, const char *property,
|
const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
|
||||||
int index, const char **output)
|
const char *property, int idx,
|
||||||
|
int *lenp)
|
||||||
{
|
{
|
||||||
const char *list;
|
const char *list, *end;
|
||||||
int length, i;
|
int length;
|
||||||
|
|
||||||
list = fdt_getprop(fdt, node, property, &length);
|
list = fdt_getprop(fdt, nodeoffset, property, &length);
|
||||||
|
if (!list) {
|
||||||
|
if (lenp)
|
||||||
|
*lenp = length;
|
||||||
|
|
||||||
for (i = 0; i < length; i++) {
|
return NULL;
|
||||||
int len = strlen(list);
|
}
|
||||||
|
|
||||||
if (index == 0) {
|
end = list + length;
|
||||||
*output = list;
|
|
||||||
return 0;
|
while (list < end) {
|
||||||
|
length = strnlen(list, end - list) + 1;
|
||||||
|
|
||||||
|
/* Abort if the last string isn't properly NUL-terminated. */
|
||||||
|
if (list + length > end) {
|
||||||
|
if (lenp)
|
||||||
|
*lenp = -FDT_ERR_BADVALUE;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
list += len + 1;
|
if (idx == 0) {
|
||||||
i += len;
|
if (lenp)
|
||||||
index--;
|
*lenp = length - 1;
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
list += length;
|
||||||
|
idx--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -FDT_ERR_NOTFOUND;
|
if (lenp)
|
||||||
}
|
*lenp = -FDT_ERR_NOTFOUND;
|
||||||
|
|
||||||
int fdt_get_string(const void *fdt, int node, const char *property,
|
return NULL;
|
||||||
const char **output)
|
|
||||||
{
|
|
||||||
return fdt_get_string_index(fdt, node, property, 0, output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdt_node_check_compatible(const void *fdt, int nodeoffset,
|
int fdt_node_check_compatible(const void *fdt, int nodeoffset,
|
||||||
@ -623,10 +652,8 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset,
|
|||||||
prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);
|
prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);
|
||||||
if (!prop)
|
if (!prop)
|
||||||
return len;
|
return len;
|
||||||
if (fdt_stringlist_contains(prop, len, compatible))
|
|
||||||
return 0;
|
return !fdt_stringlist_contains(prop, len, compatible);
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
|
int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
|
||||||
|
@ -60,6 +60,8 @@ static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen)
|
|||||||
|
|
||||||
if (((p + oldlen) < p) || ((p + oldlen) > end))
|
if (((p + oldlen) < p) || ((p + oldlen) > end))
|
||||||
return -FDT_ERR_BADOFFSET;
|
return -FDT_ERR_BADOFFSET;
|
||||||
|
if ((p < (char *)fdt) || ((end - oldlen + newlen) < (char *)fdt))
|
||||||
|
return -FDT_ERR_BADOFFSET;
|
||||||
if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt)))
|
if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt)))
|
||||||
return -FDT_ERR_NOSPACE;
|
return -FDT_ERR_NOSPACE;
|
||||||
memmove(p + newlen, p + oldlen, end - p - oldlen);
|
memmove(p + newlen, p + oldlen, end - p - oldlen);
|
||||||
@ -164,7 +166,7 @@ static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name,
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
*prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
|
*prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
|
||||||
if (!(*prop))
|
if (!*prop)
|
||||||
return oldlen;
|
return oldlen;
|
||||||
|
|
||||||
if ((err = _fdt_splice_struct(fdt, (*prop)->data, FDT_TAGALIGN(oldlen),
|
if ((err = _fdt_splice_struct(fdt, (*prop)->data, FDT_TAGALIGN(oldlen),
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
|
int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
|
||||||
const char *name, int namelen,
|
const char *name, int namelen,
|
||||||
uint32_t index, const void *val,
|
uint32_t idx, const void *val,
|
||||||
int len)
|
int len)
|
||||||
{
|
{
|
||||||
void *propval;
|
void *propval;
|
||||||
@ -27,10 +27,10 @@ int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
|
|||||||
if (!propval)
|
if (!propval)
|
||||||
return proplen;
|
return proplen;
|
||||||
|
|
||||||
if (proplen < (len + index))
|
if (proplen < (len + idx))
|
||||||
return -FDT_ERR_NOSPACE;
|
return -FDT_ERR_NOSPACE;
|
||||||
|
|
||||||
memcpy(propval + index, val, len);
|
memcpy((char *)propval + idx, val, len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,12 +52,15 @@ static int fdt_getprop_str(void *fdt, const char *path, const char *name,
|
|||||||
const char **out)
|
const char **out)
|
||||||
{
|
{
|
||||||
int node_off;
|
int node_off;
|
||||||
|
int len;
|
||||||
|
|
||||||
node_off = fdt_path_offset(fdt, path);
|
node_off = fdt_path_offset(fdt, path);
|
||||||
if (node_off < 0)
|
if (node_off < 0)
|
||||||
return node_off;
|
return node_off;
|
||||||
|
|
||||||
return fdt_get_string(fdt, node_off, name, out);
|
*out = fdt_stringlist_get(fdt, node_off, name, 0, &len);
|
||||||
|
|
||||||
|
return len < 0 ? len : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fdt_overlay_change_int_property(struct unit_test_state *uts)
|
static int fdt_overlay_change_int_property(struct unit_test_state *uts)
|
||||||
|
Loading…
Reference in New Issue
Block a user