blob: 5453726f693270f8a028a570445d13c53e045010 [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
2 * (C) Copyright 2000
3 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk47d1a6e2002-11-03 00:01:44 +00006 */
7
8#include <common.h>
9#include <stdarg.h>
10#include <malloc.h>
Simon Glass91b136c2013-11-10 10:27:01 -070011#include <os.h>
Joe Hershberger849d5d92012-12-11 22:16:29 -060012#include <serial.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020013#include <stdio_dev.h>
wdenk27b207f2003-07-24 23:38:38 +000014#include <exports.h>
Joe Hershberger849d5d92012-12-11 22:16:29 -060015#include <environment.h>
wdenk47d1a6e2002-11-03 00:01:44 +000016
Wolfgang Denkd87080b2006-03-31 18:32:53 +020017DECLARE_GLOBAL_DATA_PTR;
18
Joe Hershberger849d5d92012-12-11 22:16:29 -060019static int on_console(const char *name, const char *value, enum env_op op,
20 int flags)
21{
22 int console = -1;
23
24 /* Check for console redirection */
25 if (strcmp(name, "stdin") == 0)
26 console = stdin;
27 else if (strcmp(name, "stdout") == 0)
28 console = stdout;
29 else if (strcmp(name, "stderr") == 0)
30 console = stderr;
31
32 /* if not actually setting a console variable, we don't care */
33 if (console == -1 || (gd->flags & GD_FLG_DEVINIT) == 0)
34 return 0;
35
36 switch (op) {
37 case env_op_create:
38 case env_op_overwrite:
39
40#ifdef CONFIG_CONSOLE_MUX
41 if (iomux_doenv(console, value))
42 return 1;
43#else
44 /* Try assigning specified device */
45 if (console_assign(console, value) < 0)
46 return 1;
47#endif /* CONFIG_CONSOLE_MUX */
48 return 0;
49
50 case env_op_delete:
51 if ((flags & H_FORCE) == 0)
52 printf("Can't delete \"%s\"\n", name);
53 return 1;
54
55 default:
56 return 0;
57 }
58}
59U_BOOT_ENV_CALLBACK(console, on_console);
60
Joe Hershbergere080d542012-12-11 22:16:30 -060061#ifdef CONFIG_SILENT_CONSOLE
62static int on_silent(const char *name, const char *value, enum env_op op,
63 int flags)
64{
65#ifndef CONFIG_SILENT_CONSOLE_UPDATE_ON_SET
66 if (flags & H_INTERACTIVE)
67 return 0;
68#endif
69#ifndef CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC
70 if ((flags & H_INTERACTIVE) == 0)
71 return 0;
72#endif
73
74 if (value != NULL)
75 gd->flags |= GD_FLG_SILENT;
76 else
77 gd->flags &= ~GD_FLG_SILENT;
78
79 return 0;
80}
81U_BOOT_ENV_CALLBACK(silent, on_silent);
82#endif
83
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020084#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
wdenk47d1a6e2002-11-03 00:01:44 +000085/*
86 * if overwrite_console returns 1, the stdin, stderr and stdout
87 * are switched to the serial port, else the settings in the
88 * environment are used
89 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020090#ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +010091extern int overwrite_console(void);
92#define OVERWRITE_CONSOLE overwrite_console()
wdenk47d1a6e2002-11-03 00:01:44 +000093#else
wdenk83e40ba2005-03-31 18:42:15 +000094#define OVERWRITE_CONSOLE 0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020095#endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
wdenk47d1a6e2002-11-03 00:01:44 +000096
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020097#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
wdenk47d1a6e2002-11-03 00:01:44 +000098
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020099static int console_setfile(int file, struct stdio_dev * dev)
wdenk47d1a6e2002-11-03 00:01:44 +0000100{
101 int error = 0;
102
103 if (dev == NULL)
104 return -1;
105
106 switch (file) {
107 case stdin:
108 case stdout:
109 case stderr:
110 /* Start new device */
111 if (dev->start) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100112 error = dev->start();
wdenk47d1a6e2002-11-03 00:01:44 +0000113 /* If it's not started dont use it */
114 if (error < 0)
115 break;
116 }
117
118 /* Assign the new device (leaving the existing one started) */
119 stdio_devices[file] = dev;
120
121 /*
122 * Update monitor functions
123 * (to use the console stuff by other applications)
124 */
125 switch (file) {
126 case stdin:
wdenk27b207f2003-07-24 23:38:38 +0000127 gd->jt[XF_getc] = dev->getc;
128 gd->jt[XF_tstc] = dev->tstc;
wdenk47d1a6e2002-11-03 00:01:44 +0000129 break;
130 case stdout:
wdenk27b207f2003-07-24 23:38:38 +0000131 gd->jt[XF_putc] = dev->putc;
132 gd->jt[XF_puts] = dev->puts;
133 gd->jt[XF_printf] = printf;
wdenk47d1a6e2002-11-03 00:01:44 +0000134 break;
135 }
136 break;
137
138 default: /* Invalid file ID */
139 error = -1;
140 }
141 return error;
142}
143
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100144#if defined(CONFIG_CONSOLE_MUX)
145/** Console I/O multiplexing *******************************************/
146
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200147static struct stdio_dev *tstcdev;
148struct stdio_dev **console_devices[MAX_FILES];
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100149int cd_count[MAX_FILES];
150
151/*
152 * This depends on tstc() always being called before getc().
153 * This is guaranteed to be true because this routine is called
154 * only from fgetc() which assures it.
155 * No attempt is made to demultiplex multiple input sources.
156 */
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100157static int console_getc(int file)
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100158{
159 unsigned char ret;
160
161 /* This is never called with testcdev == NULL */
162 ret = tstcdev->getc();
163 tstcdev = NULL;
164 return ret;
165}
166
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100167static int console_tstc(int file)
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100168{
169 int i, ret;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200170 struct stdio_dev *dev;
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100171
172 disable_ctrlc(1);
173 for (i = 0; i < cd_count[file]; i++) {
174 dev = console_devices[file][i];
175 if (dev->tstc != NULL) {
176 ret = dev->tstc();
177 if (ret > 0) {
178 tstcdev = dev;
179 disable_ctrlc(0);
180 return ret;
181 }
182 }
183 }
184 disable_ctrlc(0);
185
186 return 0;
187}
188
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100189static void console_putc(int file, const char c)
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100190{
191 int i;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200192 struct stdio_dev *dev;
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100193
194 for (i = 0; i < cd_count[file]; i++) {
195 dev = console_devices[file][i];
196 if (dev->putc != NULL)
197 dev->putc(c);
198 }
199}
200
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100201static void console_puts(int file, const char *s)
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100202{
203 int i;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200204 struct stdio_dev *dev;
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100205
206 for (i = 0; i < cd_count[file]; i++) {
207 dev = console_devices[file][i];
208 if (dev->puts != NULL)
209 dev->puts(s);
210 }
211}
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100212
213static inline void console_printdevs(int file)
214{
215 iomux_printdevs(file);
216}
217
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200218static inline void console_doenv(int file, struct stdio_dev *dev)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100219{
220 iomux_doenv(file, dev->name);
221}
222#else
223static inline int console_getc(int file)
224{
225 return stdio_devices[file]->getc();
226}
227
228static inline int console_tstc(int file)
229{
230 return stdio_devices[file]->tstc();
231}
232
233static inline void console_putc(int file, const char c)
234{
235 stdio_devices[file]->putc(c);
236}
237
238static inline void console_puts(int file, const char *s)
239{
240 stdio_devices[file]->puts(s);
241}
242
243static inline void console_printdevs(int file)
244{
245 printf("%s\n", stdio_devices[file]->name);
246}
247
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200248static inline void console_doenv(int file, struct stdio_dev *dev)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100249{
250 console_setfile(file, dev);
251}
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100252#endif /* defined(CONFIG_CONSOLE_MUX) */
253
wdenk47d1a6e2002-11-03 00:01:44 +0000254/** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
255
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200256int serial_printf(const char *fmt, ...)
wdenk47d1a6e2002-11-03 00:01:44 +0000257{
258 va_list args;
259 uint i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200260 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000261
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100262 va_start(args, fmt);
wdenk47d1a6e2002-11-03 00:01:44 +0000263
264 /* For this to work, printbuffer must be larger than
265 * anything we ever want to print.
266 */
Sonny Rao068af6f2011-10-10 09:22:31 +0000267 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100268 va_end(args);
wdenk47d1a6e2002-11-03 00:01:44 +0000269
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100270 serial_puts(printbuffer);
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200271 return i;
wdenk47d1a6e2002-11-03 00:01:44 +0000272}
273
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100274int fgetc(int file)
wdenk47d1a6e2002-11-03 00:01:44 +0000275{
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100276 if (file < MAX_FILES) {
277#if defined(CONFIG_CONSOLE_MUX)
278 /*
279 * Effectively poll for input wherever it may be available.
280 */
281 for (;;) {
282 /*
283 * Upper layer may have already called tstc() so
284 * check for that first.
285 */
286 if (tstcdev != NULL)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100287 return console_getc(file);
288 console_tstc(file);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100289#ifdef CONFIG_WATCHDOG
290 /*
291 * If the watchdog must be rate-limited then it should
292 * already be handled in board-specific code.
293 */
294 udelay(1);
295#endif
296 }
297#else
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100298 return console_getc(file);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100299#endif
300 }
wdenk47d1a6e2002-11-03 00:01:44 +0000301
302 return -1;
303}
304
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100305int ftstc(int file)
wdenk47d1a6e2002-11-03 00:01:44 +0000306{
307 if (file < MAX_FILES)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100308 return console_tstc(file);
wdenk47d1a6e2002-11-03 00:01:44 +0000309
310 return -1;
311}
312
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100313void fputc(int file, const char c)
wdenk47d1a6e2002-11-03 00:01:44 +0000314{
315 if (file < MAX_FILES)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100316 console_putc(file, c);
wdenk47d1a6e2002-11-03 00:01:44 +0000317}
318
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100319void fputs(int file, const char *s)
wdenk47d1a6e2002-11-03 00:01:44 +0000320{
321 if (file < MAX_FILES)
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100322 console_puts(file, s);
wdenk47d1a6e2002-11-03 00:01:44 +0000323}
324
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200325int fprintf(int file, const char *fmt, ...)
wdenk47d1a6e2002-11-03 00:01:44 +0000326{
327 va_list args;
328 uint i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200329 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000330
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100331 va_start(args, fmt);
wdenk47d1a6e2002-11-03 00:01:44 +0000332
333 /* For this to work, printbuffer must be larger than
334 * anything we ever want to print.
335 */
Sonny Rao068af6f2011-10-10 09:22:31 +0000336 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100337 va_end(args);
wdenk47d1a6e2002-11-03 00:01:44 +0000338
339 /* Send to desired file */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100340 fputs(file, printbuffer);
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200341 return i;
wdenk47d1a6e2002-11-03 00:01:44 +0000342}
343
344/** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
345
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100346int getc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000347{
Mark Jacksonf5c3ba72008-08-25 19:21:30 +0100348#ifdef CONFIG_DISABLE_CONSOLE
349 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
350 return 0;
351#endif
352
Graeme Russe3e454c2011-08-29 02:14:05 +0000353 if (!gd->have_console)
354 return 0;
355
wdenk47d1a6e2002-11-03 00:01:44 +0000356 if (gd->flags & GD_FLG_DEVINIT) {
357 /* Get from the standard input */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100358 return fgetc(stdin);
wdenk47d1a6e2002-11-03 00:01:44 +0000359 }
360
361 /* Send directly to the handler */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100362 return serial_getc();
wdenk47d1a6e2002-11-03 00:01:44 +0000363}
364
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100365int tstc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000366{
Mark Jacksonf5c3ba72008-08-25 19:21:30 +0100367#ifdef CONFIG_DISABLE_CONSOLE
368 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
369 return 0;
370#endif
371
Graeme Russe3e454c2011-08-29 02:14:05 +0000372 if (!gd->have_console)
373 return 0;
374
wdenk47d1a6e2002-11-03 00:01:44 +0000375 if (gd->flags & GD_FLG_DEVINIT) {
376 /* Test the standard input */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100377 return ftstc(stdin);
wdenk47d1a6e2002-11-03 00:01:44 +0000378 }
379
380 /* Send directly to the handler */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100381 return serial_tstc();
wdenk47d1a6e2002-11-03 00:01:44 +0000382}
383
Simon Glass3fa49772012-03-19 21:59:14 -0700384#ifdef CONFIG_PRE_CONSOLE_BUFFER
Graeme Russ9558b482011-09-01 00:48:27 +0000385#define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ)
386
387static void pre_console_putc(const char c)
388{
389 char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
390
391 buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
392}
393
394static void pre_console_puts(const char *s)
395{
396 while (*s)
397 pre_console_putc(*s++);
398}
399
400static void print_pre_console_buffer(void)
401{
402 unsigned long i = 0;
403 char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
404
405 if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ)
406 i = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ;
407
408 while (i < gd->precon_buf_idx)
409 putc(buffer[CIRC_BUF_IDX(i++)]);
410}
411#else
412static inline void pre_console_putc(const char c) {}
413static inline void pre_console_puts(const char *s) {}
414static inline void print_pre_console_buffer(void) {}
415#endif
416
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100417void putc(const char c)
wdenk47d1a6e2002-11-03 00:01:44 +0000418{
Simon Glass91b136c2013-11-10 10:27:01 -0700419#ifdef CONFIG_SANDBOX
420 if (!gd) {
421 os_putc(c);
422 return;
423 }
424#endif
wdenka6cccae2004-02-06 21:48:22 +0000425#ifdef CONFIG_SILENT_CONSOLE
426 if (gd->flags & GD_FLG_SILENT)
wdenkf6e20fc2004-02-08 19:38:38 +0000427 return;
wdenka6cccae2004-02-06 21:48:22 +0000428#endif
429
Mark Jacksonf5c3ba72008-08-25 19:21:30 +0100430#ifdef CONFIG_DISABLE_CONSOLE
431 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
432 return;
433#endif
434
Graeme Russe3e454c2011-08-29 02:14:05 +0000435 if (!gd->have_console)
Graeme Russ9558b482011-09-01 00:48:27 +0000436 return pre_console_putc(c);
Graeme Russe3e454c2011-08-29 02:14:05 +0000437
wdenk47d1a6e2002-11-03 00:01:44 +0000438 if (gd->flags & GD_FLG_DEVINIT) {
439 /* Send to the standard output */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100440 fputc(stdout, c);
wdenk47d1a6e2002-11-03 00:01:44 +0000441 } else {
442 /* Send directly to the handler */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100443 serial_putc(c);
wdenk47d1a6e2002-11-03 00:01:44 +0000444 }
445}
446
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100447void puts(const char *s)
wdenk47d1a6e2002-11-03 00:01:44 +0000448{
Simon Glass91b136c2013-11-10 10:27:01 -0700449#ifdef CONFIG_SANDBOX
450 if (!gd) {
451 os_puts(s);
452 return;
453 }
454#endif
455
wdenka6cccae2004-02-06 21:48:22 +0000456#ifdef CONFIG_SILENT_CONSOLE
457 if (gd->flags & GD_FLG_SILENT)
458 return;
459#endif
460
Mark Jacksonf5c3ba72008-08-25 19:21:30 +0100461#ifdef CONFIG_DISABLE_CONSOLE
462 if (gd->flags & GD_FLG_DISABLE_CONSOLE)
463 return;
464#endif
465
Graeme Russe3e454c2011-08-29 02:14:05 +0000466 if (!gd->have_console)
Graeme Russ9558b482011-09-01 00:48:27 +0000467 return pre_console_puts(s);
Graeme Russe3e454c2011-08-29 02:14:05 +0000468
wdenk47d1a6e2002-11-03 00:01:44 +0000469 if (gd->flags & GD_FLG_DEVINIT) {
470 /* Send to the standard output */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100471 fputs(stdout, s);
wdenk47d1a6e2002-11-03 00:01:44 +0000472 } else {
473 /* Send directly to the handler */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100474 serial_puts(s);
wdenk47d1a6e2002-11-03 00:01:44 +0000475 }
476}
477
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200478int printf(const char *fmt, ...)
wdenk47d1a6e2002-11-03 00:01:44 +0000479{
480 va_list args;
481 uint i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200482 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000483
Simon Glass91b136c2013-11-10 10:27:01 -0700484#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_PRE_CONSOLE_BUFFER)
Graeme Russe3e454c2011-08-29 02:14:05 +0000485 if (!gd->have_console)
486 return 0;
Graeme Russ9558b482011-09-01 00:48:27 +0000487#endif
Graeme Russe3e454c2011-08-29 02:14:05 +0000488
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100489 va_start(args, fmt);
wdenk47d1a6e2002-11-03 00:01:44 +0000490
491 /* For this to work, printbuffer must be larger than
492 * anything we ever want to print.
493 */
Sonny Rao068af6f2011-10-10 09:22:31 +0000494 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100495 va_end(args);
wdenk47d1a6e2002-11-03 00:01:44 +0000496
497 /* Print the string */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100498 puts(printbuffer);
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200499 return i;
wdenk47d1a6e2002-11-03 00:01:44 +0000500}
501
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200502int vprintf(const char *fmt, va_list args)
wdenk6dd652f2003-06-19 23:40:20 +0000503{
504 uint i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200505 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk6dd652f2003-06-19 23:40:20 +0000506
Graeme Russ9558b482011-09-01 00:48:27 +0000507#ifndef CONFIG_PRE_CONSOLE_BUFFER
Graeme Russe3e454c2011-08-29 02:14:05 +0000508 if (!gd->have_console)
509 return 0;
Graeme Russ9558b482011-09-01 00:48:27 +0000510#endif
Graeme Russe3e454c2011-08-29 02:14:05 +0000511
wdenk6dd652f2003-06-19 23:40:20 +0000512 /* For this to work, printbuffer must be larger than
513 * anything we ever want to print.
514 */
Sonny Rao068af6f2011-10-10 09:22:31 +0000515 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
wdenk6dd652f2003-06-19 23:40:20 +0000516
517 /* Print the string */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100518 puts(printbuffer);
Wolfgang Denkd9c27252010-06-20 17:14:14 +0200519 return i;
wdenk6dd652f2003-06-19 23:40:20 +0000520}
521
wdenk47d1a6e2002-11-03 00:01:44 +0000522/* test if ctrl-c was pressed */
523static int ctrlc_disabled = 0; /* see disable_ctrl() */
524static int ctrlc_was_pressed = 0;
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100525int ctrlc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000526{
wdenk47d1a6e2002-11-03 00:01:44 +0000527 if (!ctrlc_disabled && gd->have_console) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100528 if (tstc()) {
529 switch (getc()) {
wdenk47d1a6e2002-11-03 00:01:44 +0000530 case 0x03: /* ^C - Control C */
531 ctrlc_was_pressed = 1;
532 return 1;
533 default:
534 break;
535 }
536 }
537 }
538 return 0;
539}
Pierre Auberta5dffa42014-04-24 10:30:07 +0200540/* Reads user's confirmation.
541 Returns 1 if user's input is "y", "Y", "yes" or "YES"
542*/
543int confirm_yesno(void)
544{
545 int i;
546 char str_input[5];
wdenk47d1a6e2002-11-03 00:01:44 +0000547
Pierre Auberta5dffa42014-04-24 10:30:07 +0200548 /* Flush input */
549 while (tstc())
550 getc();
551 i = 0;
552 while (i < sizeof(str_input)) {
553 str_input[i] = getc();
554 putc(str_input[i]);
555 if (str_input[i] == '\r')
556 break;
557 i++;
558 }
559 putc('\n');
560 if (strncmp(str_input, "y\r", 2) == 0 ||
561 strncmp(str_input, "Y\r", 2) == 0 ||
562 strncmp(str_input, "yes\r", 4) == 0 ||
563 strncmp(str_input, "YES\r", 4) == 0)
564 return 1;
565 return 0;
566}
wdenk47d1a6e2002-11-03 00:01:44 +0000567/* pass 1 to disable ctrlc() checking, 0 to enable.
568 * returns previous state
569 */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100570int disable_ctrlc(int disable)
wdenk47d1a6e2002-11-03 00:01:44 +0000571{
572 int prev = ctrlc_disabled; /* save previous state */
573
574 ctrlc_disabled = disable;
575 return prev;
576}
577
578int had_ctrlc (void)
579{
580 return ctrlc_was_pressed;
581}
582
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100583void clear_ctrlc(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000584{
585 ctrlc_was_pressed = 0;
586}
587
588#ifdef CONFIG_MODEM_SUPPORT_DEBUG
589char screen[1024];
590char *cursor = screen;
591int once = 0;
592inline void dbg(const char *fmt, ...)
593{
594 va_list args;
595 uint i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200596 char printbuffer[CONFIG_SYS_PBSIZE];
wdenk47d1a6e2002-11-03 00:01:44 +0000597
598 if (!once) {
599 memset(screen, 0, sizeof(screen));
600 once++;
601 }
602
603 va_start(args, fmt);
604
605 /* For this to work, printbuffer must be larger than
606 * anything we ever want to print.
607 */
Sonny Rao068af6f2011-10-10 09:22:31 +0000608 i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
wdenk47d1a6e2002-11-03 00:01:44 +0000609 va_end(args);
610
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100611 if ((screen + sizeof(screen) - 1 - cursor)
612 < strlen(printbuffer) + 1) {
wdenk47d1a6e2002-11-03 00:01:44 +0000613 memset(screen, 0, sizeof(screen));
614 cursor = screen;
615 }
616 sprintf(cursor, printbuffer);
617 cursor += strlen(printbuffer);
618
619}
620#else
621inline void dbg(const char *fmt, ...)
622{
623}
624#endif
625
626/** U-Boot INIT FUNCTIONS *************************************************/
627
Mike Frysingerd7be3052010-10-20 07:18:03 -0400628struct stdio_dev *search_device(int flags, const char *name)
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200629{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200630 struct stdio_dev *dev;
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200631
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200632 dev = stdio_get_by_name(name);
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200633
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100634 if (dev && (dev->flags & flags))
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200635 return dev;
636
637 return NULL;
638}
639
Mike Frysingerd7be3052010-10-20 07:18:03 -0400640int console_assign(int file, const char *devname)
wdenk47d1a6e2002-11-03 00:01:44 +0000641{
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200642 int flag;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200643 struct stdio_dev *dev;
wdenk47d1a6e2002-11-03 00:01:44 +0000644
645 /* Check for valid file */
646 switch (file) {
647 case stdin:
648 flag = DEV_FLAGS_INPUT;
649 break;
650 case stdout:
651 case stderr:
652 flag = DEV_FLAGS_OUTPUT;
653 break;
654 default:
655 return -1;
656 }
657
658 /* Check for valid device name */
659
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200660 dev = search_device(flag, devname);
wdenk47d1a6e2002-11-03 00:01:44 +0000661
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100662 if (dev)
663 return console_setfile(file, dev);
wdenk47d1a6e2002-11-03 00:01:44 +0000664
665 return -1;
666}
667
668/* Called before relocation - use serial functions */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100669int console_init_f(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000670{
wdenk47d1a6e2002-11-03 00:01:44 +0000671 gd->have_console = 1;
wdenkf72da342003-10-10 10:05:42 +0000672
673#ifdef CONFIG_SILENT_CONSOLE
674 if (getenv("silent") != NULL)
675 gd->flags |= GD_FLG_SILENT;
676#endif
677
Graeme Russ9558b482011-09-01 00:48:27 +0000678 print_pre_console_buffer();
679
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100680 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000681}
682
Jean-Christophe PLAGNIOL-VILLARD7e3be7c2009-05-16 12:14:55 +0200683void stdio_print_current_devices(void)
684{
Jean-Christophe PLAGNIOL-VILLARD7e3be7c2009-05-16 12:14:55 +0200685 /* Print information */
686 puts("In: ");
687 if (stdio_devices[stdin] == NULL) {
688 puts("No input devices available!\n");
689 } else {
690 printf ("%s\n", stdio_devices[stdin]->name);
691 }
692
693 puts("Out: ");
694 if (stdio_devices[stdout] == NULL) {
695 puts("No output devices available!\n");
696 } else {
697 printf ("%s\n", stdio_devices[stdout]->name);
698 }
699
700 puts("Err: ");
701 if (stdio_devices[stderr] == NULL) {
702 puts("No error devices available!\n");
703 } else {
704 printf ("%s\n", stdio_devices[stderr]->name);
705 }
Jean-Christophe PLAGNIOL-VILLARD7e3be7c2009-05-16 12:14:55 +0200706}
707
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200708#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
wdenk47d1a6e2002-11-03 00:01:44 +0000709/* Called after the relocation - use desired console functions */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100710int console_init_r(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000711{
712 char *stdinname, *stdoutname, *stderrname;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200713 struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200714#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
wdenk6e592382004-04-18 17:39:38 +0000715 int i;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200716#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100717#ifdef CONFIG_CONSOLE_MUX
718 int iomux_err = 0;
719#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000720
721 /* set default handlers at first */
wdenk27b207f2003-07-24 23:38:38 +0000722 gd->jt[XF_getc] = serial_getc;
723 gd->jt[XF_tstc] = serial_tstc;
724 gd->jt[XF_putc] = serial_putc;
725 gd->jt[XF_puts] = serial_puts;
726 gd->jt[XF_printf] = serial_printf;
wdenk47d1a6e2002-11-03 00:01:44 +0000727
728 /* stdin stdout and stderr are in environment */
729 /* scan for it */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100730 stdinname = getenv("stdin");
731 stdoutname = getenv("stdout");
732 stderrname = getenv("stderr");
wdenk47d1a6e2002-11-03 00:01:44 +0000733
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200734 if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100735 inputdev = search_device(DEV_FLAGS_INPUT, stdinname);
736 outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname);
737 errdev = search_device(DEV_FLAGS_OUTPUT, stderrname);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100738#ifdef CONFIG_CONSOLE_MUX
739 iomux_err = iomux_doenv(stdin, stdinname);
740 iomux_err += iomux_doenv(stdout, stdoutname);
741 iomux_err += iomux_doenv(stderr, stderrname);
742 if (!iomux_err)
743 /* Successful, so skip all the code below. */
744 goto done;
745#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000746 }
747 /* if the devices are overwritten or not found, use default device */
748 if (inputdev == NULL) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100749 inputdev = search_device(DEV_FLAGS_INPUT, "serial");
wdenk47d1a6e2002-11-03 00:01:44 +0000750 }
751 if (outputdev == NULL) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100752 outputdev = search_device(DEV_FLAGS_OUTPUT, "serial");
wdenk47d1a6e2002-11-03 00:01:44 +0000753 }
754 if (errdev == NULL) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100755 errdev = search_device(DEV_FLAGS_OUTPUT, "serial");
wdenk47d1a6e2002-11-03 00:01:44 +0000756 }
757 /* Initializes output console first */
758 if (outputdev != NULL) {
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100759 /* need to set a console if not done above. */
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100760 console_doenv(stdout, outputdev);
wdenk47d1a6e2002-11-03 00:01:44 +0000761 }
762 if (errdev != NULL) {
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100763 /* need to set a console if not done above. */
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100764 console_doenv(stderr, errdev);
wdenk47d1a6e2002-11-03 00:01:44 +0000765 }
766 if (inputdev != NULL) {
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100767 /* need to set a console if not done above. */
Jean-Christophe PLAGNIOL-VILLARD5f032012009-02-01 17:07:52 +0100768 console_doenv(stdin, inputdev);
wdenk47d1a6e2002-11-03 00:01:44 +0000769 }
770
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100771#ifdef CONFIG_CONSOLE_MUX
772done:
773#endif
774
Simon Glass78c112c2012-12-05 14:46:43 +0000775#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
Jean-Christophe PLAGNIOL-VILLARD7e3be7c2009-05-16 12:14:55 +0200776 stdio_print_current_devices();
Simon Glass78c112c2012-12-05 14:46:43 +0000777#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
wdenk47d1a6e2002-11-03 00:01:44 +0000778
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200779#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
wdenk47d1a6e2002-11-03 00:01:44 +0000780 /* set the environment variables (will overwrite previous env settings) */
781 for (i = 0; i < 3; i++) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100782 setenv(stdio_names[i], stdio_devices[i]->name);
wdenk47d1a6e2002-11-03 00:01:44 +0000783 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200784#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
wdenk47d1a6e2002-11-03 00:01:44 +0000785
Joe Hershbergerc4e00572012-12-11 22:16:19 -0600786 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
787
wdenk47d1a6e2002-11-03 00:01:44 +0000788#if 0
789 /* If nothing usable installed, use only the initial console */
790 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100791 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000792#endif
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100793 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000794}
795
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200796#else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
wdenk47d1a6e2002-11-03 00:01:44 +0000797
798/* Called after the relocation - use desired console functions */
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100799int console_init_r(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000800{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200801 struct stdio_dev *inputdev = NULL, *outputdev = NULL;
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200802 int i;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200803 struct list_head *list = stdio_get_list();
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200804 struct list_head *pos;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200805 struct stdio_dev *dev;
wdenk47d1a6e2002-11-03 00:01:44 +0000806
wdenkd791b1d2003-04-20 14:04:18 +0000807#ifdef CONFIG_SPLASH_SCREEN
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100808 /*
809 * suppress all output if splash screen is enabled and we have
Anatolij Gustschina7490812010-03-16 15:29:33 +0100810 * a bmp to display. We redirect the output from frame buffer
811 * console to serial console in this case or suppress it if
812 * "silent" mode was requested.
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100813 */
Anatolij Gustschina7490812010-03-16 15:29:33 +0100814 if (getenv("splashimage") != NULL) {
815 if (!(gd->flags & GD_FLG_SILENT))
816 outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
817 }
wdenkf72da342003-10-10 10:05:42 +0000818#endif
819
wdenk47d1a6e2002-11-03 00:01:44 +0000820 /* Scan devices looking for input and output devices */
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200821 list_for_each(pos, list) {
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200822 dev = list_entry(pos, struct stdio_dev, list);
wdenk47d1a6e2002-11-03 00:01:44 +0000823
824 if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
825 inputdev = dev;
826 }
827 if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
828 outputdev = dev;
829 }
Jean-Christophe PLAGNIOL-VILLARDc1de7a62008-08-31 04:24:55 +0200830 if(inputdev && outputdev)
831 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000832 }
833
834 /* Initializes output console first */
835 if (outputdev != NULL) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100836 console_setfile(stdout, outputdev);
837 console_setfile(stderr, outputdev);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100838#ifdef CONFIG_CONSOLE_MUX
839 console_devices[stdout][0] = outputdev;
840 console_devices[stderr][0] = outputdev;
841#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000842 }
843
844 /* Initializes input console */
845 if (inputdev != NULL) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100846 console_setfile(stdin, inputdev);
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100847#ifdef CONFIG_CONSOLE_MUX
848 console_devices[stdin][0] = inputdev;
849#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000850 }
851
Simon Glass78c112c2012-12-05 14:46:43 +0000852#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
Jean-Christophe PLAGNIOL-VILLARD7e3be7c2009-05-16 12:14:55 +0200853 stdio_print_current_devices();
Simon Glass78c112c2012-12-05 14:46:43 +0000854#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
wdenk47d1a6e2002-11-03 00:01:44 +0000855
856 /* Setting environment variables */
857 for (i = 0; i < 3; i++) {
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100858 setenv(stdio_names[i], stdio_devices[i]->name);
wdenk47d1a6e2002-11-03 00:01:44 +0000859 }
860
Joe Hershbergerc4e00572012-12-11 22:16:19 -0600861 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
862
wdenk47d1a6e2002-11-03 00:01:44 +0000863#if 0
864 /* If nothing usable installed, use only the initial console */
865 if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100866 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000867#endif
868
Jean-Christophe PLAGNIOL-VILLARDec6f1492009-02-01 17:07:51 +0100869 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000870}
871
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200872#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */