char *fdtparse_get_path(const void *fdt, int offset) { int err, size; char *path = NULL; /* Make an arbitrary best guess at the max path size */ size = 32; do { /* * There wasn't enough space last time, * free that attempt and try again. */ if (path) { free(path); size += 32; } path = malloc(size); if (!path) { fprintf(stderr, "%s: Unable to allocate %d bytes for path\n", __func__, size); return NULL; } err = fdt_get_path(fdt, offset, path, size); } while (err == -FDT_ERR_NOSPACE); if (err) { free(path); return NULL; } return path; }
static int ti_musb_get_usb_index(int node) { const void *fdt = gd->fdt_blob; int i = 0; char path[64]; const char *alias_path; char alias[16]; fdt_get_path(fdt, node, path, sizeof(path)); do { snprintf(alias, sizeof(alias), "usb%d", i); alias_path = fdt_get_alias(fdt, alias); if (alias_path == NULL) { debug("USB index not found\n"); return -ENOENT; } if (!strcmp(path, alias_path)) return i; i++; } while (alias_path); return -ENOENT; }
status_t of_get_next_device(int *_cookie, int root, const char *type, char *path, size_t pathSize) { int next; int err; int startoffset = *_cookie ? *_cookie : -1; // iterate by property value next = fdt_node_offset_by_prop_value(gFDT, startoffset, "device_type", type, strlen(type) + 1); TRACE(("of_get_next_device(c:%d, %d, '%s', %p, %zd) soffset=%d next=%d\n", *_cookie, root, type, path, pathSize, startoffset, fdt2of(next))); if (next < 0) return B_ENTRY_NOT_FOUND; // make sure root is the parent int parent = next; while (root && parent) { parent = fdt_parent_offset(gFDT, parent); if (parent == root) break; if (parent <= 0) return B_ENTRY_NOT_FOUND; } *_cookie = next; err = fdt_get_path(gFDT, next, path, pathSize); if (err < 0) return B_ERROR; return B_OK; }
static void check_path_buf(void *fdt, const char *path, int pathlen, int buflen) { int offset; char buf[buflen+1]; int len; offset = fdt_path_offset(fdt, path); if (offset < 0) FAIL("Couldn't find path \"%s\": %s", path, fdt_strerror(offset)); memset(buf, POISON, sizeof(buf)); /* poison the buffer */ len = fdt_get_path(fdt, offset, buf, buflen); verbose_printf("get_path() %s -> %d -> %s\n", path, offset, buf); if (buflen <= pathlen) { if (len != -FDT_ERR_NOSPACE) FAIL("fdt_get_path([%d bytes]) returns %d with " "insufficient buffer space", buflen, len); } else { if (len < 0) FAIL("fdt_get_path([%d bytes]): %s", buflen, fdt_strerror(len)); if (len != 0) FAIL("fdt_get_path([%d bytes]) returns %d " "instead of 0", buflen, len); if (strcmp(buf, path) != 0) FAIL("fdt_get_path([%d bytes]) returns \"%s\" " "instead of \"%s\"", buflen, buf, path); } if (buf[buflen] != POISON) FAIL("fdt_get_path([%d bytes]) overran buffer", buflen); }
static void fdt_fixup_pci_liodn_offsets(void *fdt, const char *compat, int ep_liodn_start) { int off, pci_idx = 0, pci_cnt = 0, i, rc; const uint32_t *base_liodn; uint32_t liodn_offs[CONFIG_SYS_MAX_PCI_EPS + 1] = { 0 }; /* * Count the number of pci nodes. * It's needed later when the interleaved liodn offsets are generated. */ off = fdt_node_offset_by_compatible(fdt, -1, compat); while (off != -FDT_ERR_NOTFOUND) { pci_cnt++; off = fdt_node_offset_by_compatible(fdt, off, compat); } for (off = fdt_node_offset_by_compatible(fdt, -1, compat); off != -FDT_ERR_NOTFOUND; off = fdt_node_offset_by_compatible(fdt, off, compat)) { base_liodn = fdt_getprop(fdt, off, "fsl,liodn", &rc); if (!base_liodn) { char path[64]; if (fdt_get_path(fdt, off, path, sizeof(path)) < 0) strcpy(path, "(unknown)"); printf("WARNING Could not get liodn of node %s: %s\n", path, fdt_strerror(rc)); continue; } for (i = 0; i < CONFIG_SYS_MAX_PCI_EPS; i++) liodn_offs[i + 1] = ep_liodn_start + i * pci_cnt + pci_idx - *base_liodn; rc = fdt_setprop(fdt, off, "fsl,liodn-offset-list", liodn_offs, sizeof(liodn_offs)); if (rc) { char path[64]; if (fdt_get_path(fdt, off, path, sizeof(path)) < 0) strcpy(path, "(unknown)"); printf("WARNING Unable to set fsl,liodn-offset-list for " "node %s: %s\n", path, fdt_strerror(rc)); continue; } pci_idx++; } }
static char *fdt_wrapper_get_path(const void *devp, char *buf, int len) { int rc; rc = fdt_get_path(fdt, devp_offset(devp), buf, len); if (check_err(rc)) return NULL; return buf; }
static void compare_node(const void *fdt1, int offset1, const void *fdt2, int offset2) { int err; char path1[PATH_MAX], path2[PATH_MAX]; CHECK(fdt_get_path(fdt1, offset1, path1, sizeof(path1))); CHECK(fdt_get_path(fdt2, offset2, path2, sizeof(path2))); if (!streq(path1, path2)) TEST_BUG("Path mismatch %s vs. %s\n", path1, path2); verbose_printf("Checking %s\n", path1); compare_properties(fdt1, offset1, fdt2, offset2); compare_properties(fdt2, offset2, fdt1, offset1); compare_subnodes(fdt1, offset1, fdt2, offset2, 1); compare_subnodes(fdt2, offset2, fdt1, offset1, 0); }
static int fit_config_get_hash_list(void *fit, int conf_noffset, int sig_offset, struct strlist *node_inc) { int allow_missing; const char *prop, *iname, *end; const char *conf_name, *sig_name; char name[200], path[200]; int image_count; int ret, len; conf_name = fit_get_name(fit, conf_noffset, NULL); sig_name = fit_get_name(fit, sig_offset, NULL); /* * Build a list of nodes we need to hash. We always need the root * node and the configuration. */ strlist_init(node_inc); snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH, conf_name); if (strlist_add(node_inc, "/") || strlist_add(node_inc, name)) goto err_mem; /* Get a list of images that we intend to sign */ prop = fit_config_get_image_list(fit, sig_offset, &len, &allow_missing); if (!prop) return 0; /* Locate the images */ end = prop + len; image_count = 0; for (iname = prop; iname < end; iname += strlen(iname) + 1) { int noffset; int image_noffset; int hash_count; image_noffset = fit_conf_get_prop_node(fit, conf_noffset, iname); if (image_noffset < 0) { printf("Failed to find image '%s' in configuration '%s/%s'\n", iname, conf_name, sig_name); if (allow_missing) continue; return -ENOENT; } ret = fdt_get_path(fit, image_noffset, path, sizeof(path)); if (ret < 0) goto err_path; if (strlist_add(node_inc, path)) goto err_mem; snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH, conf_name); /* Add all this image's hashes */ hash_count = 0; for (noffset = fdt_first_subnode(fit, image_noffset); noffset >= 0; noffset = fdt_next_subnode(fit, noffset)) { const char *name = fit_get_name(fit, noffset, NULL); if (strncmp(name, FIT_HASH_NODENAME, strlen(FIT_HASH_NODENAME))) continue; ret = fdt_get_path(fit, noffset, path, sizeof(path)); if (ret < 0) goto err_path; if (strlist_add(node_inc, path)) goto err_mem; hash_count++; } if (!hash_count) { printf("Failed to find any hash nodes in configuration '%s/%s' image '%s' - without these it is not possible to verify this image\n", conf_name, sig_name, iname); return -ENOMSG; } image_count++; } if (!image_count) { printf("Failed to find any images for configuration '%s/%s'\n", conf_name, sig_name); return -ENOMSG; } return 0; err_mem: printf("Out of memory processing configuration '%s/%s'\n", conf_name, sig_name); return -ENOMEM; err_path: printf("Failed to get path for image '%s' in configuration '%s/%s': %s\n", iname, conf_name, sig_name, fdt_strerror(ret)); return -ENOENT; }