3 * Gary Jennejohn, DENX Software Engineering GmbH, garyj@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
13 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
14 void iomux_printdevs(const int console)
17 struct stdio_dev *dev;
19 for (i = 0; i < cd_count[console]; i++) {
20 dev = console_devices[console][i];
21 printf("%s ", dev->name);
26 /* This tries to preserve the old list if an error occurs. */
27 int iomux_doenv(const int console, const char *arg)
29 char *console_args, *temp, **start;
30 int i, j, k, io_flag, cs_idx, repeat;
31 struct stdio_dev *dev;
32 struct stdio_dev **cons_set;
34 console_args = strdup(arg);
35 if (console_args == NULL)
38 * Check whether a comma separated list of devices was
39 * entered and count how many devices were entered.
40 * The array start[] has pointers to the beginning of
41 * each device name (up to MAX_CONSARGS devices).
43 * Have to do this twice - once to count the number of
44 * commas and then again to populate start.
49 temp = strchr(temp, ',');
55 /* There's always one entry more than the number of commas. */
59 start = (char **)malloc(i * sizeof(char *));
65 start[0] = console_args;
67 temp = strchr(start[i++], ',');
73 cons_set = (struct stdio_dev **)calloc(i, sizeof(struct stdio_dev *));
74 if (cons_set == NULL) {
82 io_flag = DEV_FLAGS_INPUT;
86 io_flag = DEV_FLAGS_OUTPUT;
96 for (j = 0; j < i; j++) {
98 * Check whether the device exists and is valid.
99 * console_assign() also calls search_device(),
100 * but I need the pointer to the device.
102 dev = search_device(io_flag, start[j]);
106 * Prevent multiple entries for a device.
109 for (k = 0; k < cs_idx; k++) {
110 if (dev == cons_set[k]) {
118 * Try assigning the specified device.
119 * This could screw up the console settings for apps.
121 if (console_assign(console, start[j]) < 0)
123 cons_set[cs_idx++] = dev;
127 /* failed to set any console */
132 /* Works even if console_devices[console] is NULL. */
133 console_devices[console] =
134 (struct stdio_dev **)realloc(console_devices[console],
135 cs_idx * sizeof(struct stdio_dev *));
136 if (console_devices[console] == NULL) {
140 memcpy(console_devices[console], cons_set, cs_idx *
141 sizeof(struct stdio_dev *));
143 cd_count[console] = cs_idx;
148 #endif /* CONSOLE_MUX */