int fdtdec_get_chosen_node(const void *blob, const char *name) { const char *prop; prop = fdtdec_get_chosen_prop(blob, name); if (!prop) return -FDT_ERR_NOTFOUND; return fdt_path_offset(blob, prop); }
static int serial_check_stdout(const void *blob, struct udevice **devp) { int node; /* Check for a chosen console */ node = fdtdec_get_chosen_node(blob, "stdout-path"); if (node < 0) { const char *str, *p, *name; /* * Deal with things like * stdout-path = "serial0:115200n8"; * * We need to look up the alias and then follow it to the * correct node. */ str = fdtdec_get_chosen_prop(blob, "stdout-path"); if (str) { p = strchr(str, ':'); name = fdt_get_alias_namelen(blob, str, p ? p - str : strlen(str)); if (name) node = fdt_path_offset(blob, name); } } if (node < 0) node = fdt_path_offset(blob, "console"); if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node, devp)) return 0; /* * If the console is not marked to be bound before relocation, bind it * anyway. */ if (node > 0 && !lists_bind_fdt(gd->dm_root, offset_to_ofnode(node), devp)) { if (!device_probe(*devp)) return 0; } return -ENODEV; }
static void serial_find_console_or_panic(void) { const void *blob = gd->fdt_blob; struct udevice *dev; int node; if (CONFIG_IS_ENABLED(OF_CONTROL) && blob) { /* Check for a chosen console */ node = fdtdec_get_chosen_node(blob, "stdout-path"); if (node < 0) { const char *str, *p, *name; /* * Deal with things like * stdout-path = "serial0:115200n8"; * * We need to look up the alias and then follow it to * the correct node. */ str = fdtdec_get_chosen_prop(blob, "stdout-path"); if (str) { p = strchr(str, ':'); name = fdt_get_alias_namelen(blob, str, p ? p - str : strlen(str)); if (name) node = fdt_path_offset(blob, name); } } if (node < 0) node = fdt_path_offset(blob, "console"); if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node, &dev)) { gd->cur_serial_dev = dev; return; } /* * If the console is not marked to be bound before relocation, * bind it anyway. */ if (node > 0 && !lists_bind_fdt(gd->dm_root, blob, node, &dev)) { if (!device_probe(dev)) { gd->cur_serial_dev = dev; return; } } } if (!SPL_BUILD || !CONFIG_IS_ENABLED(OF_CONTROL) || !blob) { /* * Try to use CONFIG_CONS_INDEX if available (it is numbered * from 1!). * * Failing that, get the device with sequence number 0, or in * extremis just the first serial device we can find. But we * insist on having a console (even if it is silent). */ #ifdef CONFIG_CONS_INDEX #define INDEX (CONFIG_CONS_INDEX - 1) #else #define INDEX 0 #endif if (!uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) || !uclass_get_device(UCLASS_SERIAL, INDEX, &dev) || (!uclass_first_device(UCLASS_SERIAL, &dev) && dev)) { gd->cur_serial_dev = dev; return; } #undef INDEX } #ifdef CONFIG_REQUIRE_SERIAL_CONSOLE panic_str("No serial driver found"); #endif }