.
drivers/serial/serial-uclass.c
1 static void serial_find_console_or_panic(void)
2 {
3 const void *blob = gd->fdt_blob;
4 struct udevice *dev;
5 int node;
6
7 if (CONFIG_IS_ENABLED(OF_PLATDATA)) {
8 uclass_first_device(UCLASS_SERIAL, &dev);
9 if (dev) {
10 gd->cur_serial_dev = dev;
11 return;
12 }
13 } else if (CONFIG_IS_ENABLED(OF_CONTROL) && blob) {
14 /* Check for a chosen console */
15 node = fdtdec_get_chosen_node(blob, "stdout-path");
16 if (node < 0) {
17 const char *str, *p, *name;
18
19 /*
20 * Deal with things like
21 * stdout-path = "serial0:115200n8";
22 *
23 * We need to look up the alias and then follow it to
24 * the correct node.
25 */
26 str = fdtdec_get_chosen_prop(blob, "stdout-path");
27 if (str) {
28 p = strchr(str, ':');
29 name = fdt_get_alias_namelen(blob, str,
30 p ? p - str : strlen(str));
31 if (name)
32 node = fdt_path_offset(blob, name);
33 }
34 }
35 if (node < 0)
36 node = fdt_path_offset(blob, "console");
37 if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node,
38 &dev)) {
39 gd->cur_serial_dev = dev;
40 return;
41 }
42
43 /*
44 * If the console is not marked to be bound before relocation,
45 * bind it anyway.
46 */
47 if (node > 0 &&
48 !lists_bind_fdt(gd->dm_root, blob, node, &dev)) {
49 if (!device_probe(dev)) {
50 gd->cur_serial_dev = dev;
51 return;
52 }
53 }
54 }
55 if (!SPL_BUILD || !CONFIG_IS_ENABLED(OF_CONTROL) || !blob) {
56 /*
57 * Try to use CONFIG_CONS_INDEX if available (it is numbered
58 * from 1!).
59 *
60 * Failing that, get the device with sequence number 0, or in
61 * extremis just the first serial device we can find. But we
62 * insist on having a console (even if it is silent).
63 */
64 #ifdef CONFIG_CONS_INDEX
65 #define INDEX (CONFIG_CONS_INDEX - 1)
66 #else
67 #define INDEX 0
68 #endif
69 if (!uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) ||
70 !uclass_get_device(UCLASS_SERIAL, INDEX, &dev) ||
71 (!uclass_first_device(UCLASS_SERIAL, &dev) && dev)) {
72 gd->cur_serial_dev = dev;
73 return;
74 }
75 #undef INDEX
76 }
77
78 #ifdef CONFIG_REQUIRE_SERIAL_CONSOLE
79 panic_str("No serial driver found");
80 #endif
81 }
- 7번 줄은 if문은 수행되지 않습니다.
- 13번 줄의 else if문이 수행됩니다.