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 /* This tries to preserve the old list if an error occurs. */
26 int iomux_doenv(const int console
, const char *arg
)
28 char *console_args
, *temp
, **start
;
29 int i
, j
, k
, io_flag
, cs_idx
, repeat
;
30 struct stdio_dev
*dev
;
31 struct stdio_dev
**cons_set
;
33 console_args
= strdup(arg
);
34 if (console_args
== NULL
)
37 * Check whether a comma separated list of devices was
38 * entered and count how many devices were entered.
39 * The array start[] has pointers to the beginning of
40 * each device name (up to MAX_CONSARGS devices).
42 * Have to do this twice - once to count the number of
43 * commas and then again to populate start.
48 temp
= strchr(temp
, ',');
54 /* There's always one entry more than the number of commas. */
58 start
= (char **)malloc(i
* sizeof(char *));
64 start
[0] = console_args
;
66 temp
= strchr(start
[i
++], ',');
72 cons_set
= (struct stdio_dev
**)calloc(i
, sizeof(struct stdio_dev
*));
73 if (cons_set
== NULL
) {
81 io_flag
= DEV_FLAGS_INPUT
;
85 io_flag
= DEV_FLAGS_OUTPUT
;
95 for (j
= 0; j
< i
; j
++) {
97 * Check whether the device exists and is valid.
98 * console_assign() also calls search_device(),
99 * but I need the pointer to the device.
101 dev
= search_device(io_flag
, start
[j
]);
105 * Prevent multiple entries for a device.
108 for (k
= 0; k
< cs_idx
; k
++) {
109 if (dev
== cons_set
[k
]) {
117 * Try assigning the specified device.
118 * This could screw up the console settings for apps.
120 if (console_assign(console
, start
[j
]) < 0)
122 cons_set
[cs_idx
++] = dev
;
126 /* failed to set any console */
131 /* Works even if console_devices[console] is NULL. */
132 console_devices
[console
] =
133 (struct stdio_dev
**)realloc(console_devices
[console
],
134 cs_idx
* sizeof(struct stdio_dev
*));
135 if (console_devices
[console
] == NULL
) {
139 memcpy(console_devices
[console
], cons_set
, cs_idx
*
140 sizeof(struct stdio_dev
*));
142 cd_count
[console
] = cs_idx
;
147 #endif /* CONSOLE_MUX */