/* Test that block device numbering works as expected */ static int dm_test_blk_devnum(struct unit_test_state *uts) { struct udevice *dev, *mmc_dev, *parent; int i; /* * Probe the devices, with the first one being probed last. This is the * one with no alias / sequence numnber. */ ut_assertok(uclass_get_device(UCLASS_MMC, 1, &dev)); ut_assertok(uclass_get_device(UCLASS_MMC, 2, &dev)); ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev)); for (i = 0; i < 3; i++) { struct blk_desc *desc; /* Check that the bblock device is attached */ ut_assertok(uclass_get_device_by_seq(UCLASS_MMC, i, &mmc_dev)); ut_assertok(blk_find_device(IF_TYPE_MMC, i, &dev)); parent = dev_get_parent(dev); ut_asserteq_ptr(parent, mmc_dev); ut_asserteq(trailing_strtol(mmc_dev->name), i); /* * Check that the block device devnum matches its parent's * sequence number */ desc = dev_get_uclass_platdata(dev); ut_asserteq(desc->devnum, i); } return 0; }
void fdt_fixup_ethernet(void *fdt) { int i, j, prop; char *tmp, *end; char mac[16]; const char *path; unsigned char mac_addr[ARP_HLEN]; int offset; if (fdt_path_offset(fdt, "/aliases") < 0) return; /* Cycle through all aliases */ for (prop = 0; ; prop++) { const char *name; /* FDT might have been edited, recompute the offset */ offset = fdt_first_property_offset(fdt, fdt_path_offset(fdt, "/aliases")); /* Select property number 'prop' */ for (i = 0; i < prop; i++) offset = fdt_next_property_offset(fdt, offset); if (offset < 0) break; path = fdt_getprop_by_offset(fdt, offset, &name, NULL); if (!strncmp(name, "ethernet", 8)) { /* Treat plain "ethernet" same as "ethernet0". */ if (!strcmp(name, "ethernet")) i = 0; else i = trailing_strtol(name); if (i != -1) { if (i == 0) strcpy(mac, "ethaddr"); else sprintf(mac, "eth%daddr", i); } else { continue; } tmp = env_get(mac); if (!tmp) continue; for (j = 0; j < 6; j++) { mac_addr[j] = tmp ? simple_strtoul(tmp, &end, 16) : 0; if (tmp) tmp = (*end) ? end + 1 : end; } do_fixup_by_path(fdt, path, "mac-address", &mac_addr, 6, 0); do_fixup_by_path(fdt, path, "local-mac-address", &mac_addr, 6, 1); } } }
int pmic_bind_children(struct udevice *pmic, ofnode parent, const struct pmic_child_info *child_info) { const struct pmic_child_info *info; struct driver *drv; struct udevice *child; const char *node_name; int bind_count = 0; ofnode node; int prefix_len; int ret; debug("%s for '%s' at node offset: %d\n", __func__, pmic->name, dev_of_offset(pmic)); ofnode_for_each_subnode(node, parent) { node_name = ofnode_get_name(node); debug("* Found child node: '%s'\n", node_name); child = NULL; for (info = child_info; info->prefix && info->driver; info++) { debug(" - compatible prefix: '%s'\n", info->prefix); prefix_len = strlen(info->prefix); if (strncmp(info->prefix, node_name, prefix_len)) continue; drv = lists_driver_lookup_name(info->driver); if (!drv) { debug(" - driver: '%s' not found!\n", info->driver); continue; } debug(" - found child driver: '%s'\n", drv->name); ret = device_bind_with_driver_data(pmic, drv, node_name, 0, node, &child); if (ret) { debug(" - child binding error: %d\n", ret); continue; } debug(" - bound child device: '%s'\n", child->name); child->driver_data = trailing_strtol(node_name); debug(" - set 'child->driver_data': %lu\n", child->driver_data); break; } if (child) bind_count++; else debug(" - compatible prefix not found\n"); }
int fdtdec_get_alias_seq(const void *blob, const char *base, int offset, int *seqp) { int base_len = strlen(base); const char *find_name; int find_namelen; int prop_offset; int aliases; find_name = fdt_get_name(blob, offset, &find_namelen); debug("Looking for '%s' at %d, name %s\n", base, offset, find_name); aliases = fdt_path_offset(blob, "/aliases"); for (prop_offset = fdt_first_property_offset(blob, aliases); prop_offset > 0; prop_offset = fdt_next_property_offset(blob, prop_offset)) { const char *prop; const char *name; const char *slash; int len, val; prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len); debug(" - %s, %s\n", name, prop); if (len < find_namelen || *prop != '/' || prop[len - 1] || strncmp(name, base, base_len)) continue; slash = strrchr(prop, '/'); if (strcmp(slash + 1, find_name)) continue; val = trailing_strtol(name); if (val != -1) { *seqp = val; debug("Found seq %d\n", *seqp); return 0; } } debug("Not found\n"); return -ENOENT; }
void fdt_fixup_ethernet(void *fdt) { int i = 0, j, prop; char *tmp, *end; char mac[16]; const char *path; unsigned char mac_addr[ARP_HLEN]; int offset; #ifdef FDT_SEQ_MACADDR_FROM_ENV int nodeoff; const struct fdt_property *fdt_prop; #endif if (fdt_path_offset(fdt, "/aliases") < 0) return; /* Cycle through all aliases */ for (prop = 0; ; prop++) { const char *name; /* FDT might have been edited, recompute the offset */ offset = fdt_first_property_offset(fdt, fdt_path_offset(fdt, "/aliases")); /* Select property number 'prop' */ for (j = 0; j < prop; j++) offset = fdt_next_property_offset(fdt, offset); if (offset < 0) break; path = fdt_getprop_by_offset(fdt, offset, &name, NULL); if (!strncmp(name, "ethernet", 8)) { /* Treat plain "ethernet" same as "ethernet0". */ if (!strcmp(name, "ethernet") #ifdef FDT_SEQ_MACADDR_FROM_ENV || !strcmp(name, "ethernet0") #endif ) i = 0; #ifndef FDT_SEQ_MACADDR_FROM_ENV else i = trailing_strtol(name); #endif if (i != -1) { if (i == 0) strcpy(mac, "ethaddr"); else sprintf(mac, "eth%daddr", i); } else { continue; } #ifdef FDT_SEQ_MACADDR_FROM_ENV nodeoff = fdt_path_offset(fdt, path); fdt_prop = fdt_get_property(fdt, nodeoff, "status", NULL); if (fdt_prop && !strcmp(fdt_prop->data, "disabled")) continue; i++; #endif tmp = env_get(mac); if (!tmp) continue; for (j = 0; j < 6; j++) { mac_addr[j] = tmp ? simple_strtoul(tmp, &end, 16) : 0; if (tmp) tmp = (*end) ? end + 1 : end; } do_fixup_by_path(fdt, path, "mac-address", &mac_addr, 6, 0); do_fixup_by_path(fdt, path, "local-mac-address", &mac_addr, 6, 1); } } }