1 // SPDX-License-Identifier: GPL-2.0+
4 * Gary Jennejohn, DENX Software Engineering GmbH, garyj@denx.de.
12 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
13 void iomux_printdevs(const int console)
16 struct stdio_dev *dev;
18 for (i = 0; i < cd_count[console]; i++) {
19 dev = console_devices[console][i];
20 printf("%s ", dev->name);
25 int iomux_match_device(struct stdio_dev **set, const int n, struct stdio_dev *sdev)
29 for (i = 0; i < n; i++)
35 /* This tries to preserve the old list if an error occurs. */
36 int iomux_doenv(const int console, const char *arg)
38 char *console_args, *temp, **start;
39 int i, j, io_flag, cs_idx, repeat;
40 struct stdio_dev **cons_set, **old_set;
41 struct stdio_dev *dev;
43 console_args = strdup(arg);
44 if (console_args == NULL)
47 * Check whether a comma separated list of devices was
48 * entered and count how many devices were entered.
49 * The array start[] has pointers to the beginning of
50 * each device name (up to MAX_CONSARGS devices).
52 * Have to do this twice - once to count the number of
53 * commas and then again to populate start.
58 /* There's always one entry more than the number of commas. */
61 temp = strchr(temp, ',');
67 start = (char **)malloc(i * sizeof(char *));
73 start[0] = console_args;
75 temp = strchr(start[i++], ',');
81 cons_set = (struct stdio_dev **)calloc(i, sizeof(struct stdio_dev *));
82 if (cons_set == NULL) {
88 io_flag = stdio_file_to_flags(console);
97 for (j = 0; j < i; j++) {
99 * Check whether the device exists and is valid.
100 * console_assign() also calls console_search_dev(),
101 * but I need the pointer to the device.
103 dev = console_search_dev(io_flag, start[j]);
107 * Prevent multiple entries for a device.
109 repeat = iomux_match_device(cons_set, cs_idx, dev);
113 * Try assigning the specified device.
114 * This could screw up the console settings for apps.
116 if (console_assign(console, start[j]) < 0)
118 cons_set[cs_idx++] = dev;
122 /* failed to set any console */
128 old_set = console_devices[console];
129 repeat = cd_count[console];
131 console_devices[console] = cons_set;
132 cd_count[console] = cs_idx;
134 /* Stop dropped consoles */
135 for (i = 0; i < repeat; i++) {
136 j = iomux_match_device(cons_set, cs_idx, old_set[i]);
138 console_stop(console, old_set[i]);
144 #endif /* CONSOLE_MUX */