args_prep.c revision 1.1.14.2 1 1.1.14.2 yamt /* $Id: args_prep.c,v 1.1.14.2 2014/05/22 11:39:43 yamt Exp $ */
2 1.1.14.2 yamt
3 1.1.14.2 yamt /*
4 1.1.14.2 yamt * Copyright (c) 2012 The NetBSD Foundation, Inc.
5 1.1.14.2 yamt * All rights reserved.
6 1.1.14.2 yamt *
7 1.1.14.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.1.14.2 yamt * by Petri Laakso.
9 1.1.14.2 yamt *
10 1.1.14.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.1.14.2 yamt * modification, are permitted provided that the following conditions
12 1.1.14.2 yamt * are met:
13 1.1.14.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.1.14.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.1.14.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.14.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.1.14.2 yamt * documentation and/or other materials provided with the distribution.
18 1.1.14.2 yamt *
19 1.1.14.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1.14.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.14.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.14.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1.14.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.14.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.14.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.14.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.14.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.14.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.14.2 yamt * POSSIBILITY OF SUCH DAMAGE.
30 1.1.14.2 yamt */
31 1.1.14.2 yamt
32 1.1.14.2 yamt /* (c) for ngets() below:
33 1.1.14.2 yamt *
34 1.1.14.2 yamt * Copyright (c) 1993
35 1.1.14.2 yamt * The Regents of the University of California. All rights reserved.
36 1.1.14.2 yamt *
37 1.1.14.2 yamt * Redistribution and use in source and binary forms, with or without
38 1.1.14.2 yamt * modification, are permitted provided that the following conditions
39 1.1.14.2 yamt * are met:
40 1.1.14.2 yamt * 1. Redistributions of source code must retain the above copyright
41 1.1.14.2 yamt * notice, this list of conditions and the following disclaimer.
42 1.1.14.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
43 1.1.14.2 yamt * notice, this list of conditions and the following disclaimer in the
44 1.1.14.2 yamt * documentation and/or other materials provided with the distribution.
45 1.1.14.2 yamt * 3. All advertising materials mentioning features or use of this software
46 1.1.14.2 yamt * must display the following acknowledgement:
47 1.1.14.2 yamt * This product includes software developed by the University of
48 1.1.14.2 yamt * California, Berkeley and its contributors.
49 1.1.14.2 yamt * 4. Neither the name of the University nor the names of its contributors
50 1.1.14.2 yamt * may be used to endorse or promote products derived from this software
51 1.1.14.2 yamt * without specific prior written permission.
52 1.1.14.2 yamt *
53 1.1.14.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 1.1.14.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 1.1.14.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 1.1.14.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 1.1.14.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 1.1.14.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 1.1.14.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 1.1.14.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 1.1.14.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 1.1.14.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 1.1.14.2 yamt * SUCH DAMAGE.
64 1.1.14.2 yamt *
65 1.1.14.2 yamt * @(#)gets.c 8.1 (Berkeley) 6/11/93
66 1.1.14.2 yamt */
67 1.1.14.2 yamt
68 1.1.14.2 yamt
69 1.1.14.2 yamt #include <sys/param.h>
70 1.1.14.2 yamt #include <sys/types.h>
71 1.1.14.2 yamt #include <sys/cdefs.h>
72 1.1.14.2 yamt
73 1.1.14.2 yamt #include <lib/libsa/stand.h>
74 1.1.14.2 yamt #include <lib/libkern/libkern.h>
75 1.1.14.2 yamt
76 1.1.14.2 yamt #include <arm/arm32/pte.h>
77 1.1.14.2 yamt #define _LOCORE
78 1.1.14.2 yamt #include <arm/imx/imx23var.h>
79 1.1.14.2 yamt #undef _LOCORE
80 1.1.14.2 yamt #include <evbarm/bootconfig.h>
81 1.1.14.2 yamt
82 1.1.14.2 yamt #include <arm/imx/imx23_digctlreg.h>
83 1.1.14.2 yamt #include <arm/imx/imx23_uartdbgreg.h>
84 1.1.14.2 yamt
85 1.1.14.2 yamt #include "common.h"
86 1.1.14.2 yamt
87 1.1.14.2 yamt static void ngets(char *, int);
88 1.1.14.2 yamt
89 1.1.14.2 yamt #define L1_PAGE_TABLE (DRAM_BASE + MEMSIZE * 1024 * 1024 - L1_TABLE_SIZE)
90 1.1.14.2 yamt #define BOOTIMX23_ARGS (L1_PAGE_TABLE - MAX_BOOT_STRING - 1)
91 1.1.14.2 yamt
92 1.1.14.2 yamt #define PROMPT_DELAY 5000000 /* Wait 5 seconds user to press any key. */
93 1.1.14.2 yamt
94 1.1.14.2 yamt int
95 1.1.14.2 yamt args_prep(void)
96 1.1.14.2 yamt {
97 1.1.14.2 yamt u_int prompt;
98 1.1.14.2 yamt char *boot_args = (char *)BOOTIMX23_ARGS;
99 1.1.14.2 yamt
100 1.1.14.2 yamt /* Copy default boot arguments. */
101 1.1.14.2 yamt memset((void *)boot_args, 0x00, MAX_BOOT_STRING);
102 1.1.14.2 yamt strcpy(boot_args, KERNEL_BOOT_ARGS);
103 1.1.14.2 yamt
104 1.1.14.2 yamt prompt = 0;
105 1.1.14.2 yamt
106 1.1.14.2 yamt /* Enable debug UART data reception which was not enabled by the ROM. */
107 1.1.14.2 yamt uint16_t cr = REG_RD_HW(HW_UARTDBG_BASE + HW_UARTDBGCR);
108 1.1.14.2 yamt cr |= HW_UARTDBGCR_RXE;
109 1.1.14.2 yamt REG_WR_HW(HW_UARTDBG_BASE + HW_UARTDBGCR, cr);
110 1.1.14.2 yamt
111 1.1.14.2 yamt printf("Press any key to drop into boot prompt...\n\r");
112 1.1.14.2 yamt
113 1.1.14.2 yamt REG_WR(HW_DIGCTL_BASE + HW_DIGCTL_MICROSECONDS_CLR, 0xFFFFFFFF);
114 1.1.14.2 yamt
115 1.1.14.2 yamt while (REG_RD(HW_DIGCTL_BASE + HW_DIGCTL_MICROSECONDS) < PROMPT_DELAY) {
116 1.1.14.2 yamt if (!(REG_RD_HW(HW_UARTDBG_BASE + HW_UARTDBGFR) &
117 1.1.14.2 yamt HW_UARTDBGFR_RXFE)) {
118 1.1.14.2 yamt /* RX FIFO is not empty, some key was pressed. */
119 1.1.14.2 yamt REG_RD(HW_UARTDBG_BASE + HW_UARTDBGDR); /* Flush. */
120 1.1.14.2 yamt prompt = 1;
121 1.1.14.2 yamt break;
122 1.1.14.2 yamt }
123 1.1.14.2 yamt }
124 1.1.14.2 yamt
125 1.1.14.2 yamt if (prompt) {
126 1.1.14.2 yamt memset((void *)boot_args, 0x00, MAX_BOOT_STRING);
127 1.1.14.2 yamt printf("boot: ");
128 1.1.14.2 yamt ngets(boot_args, MAX_BOOT_STRING);
129 1.1.14.2 yamt }
130 1.1.14.2 yamt
131 1.1.14.2 yamt return 0;
132 1.1.14.2 yamt }
133 1.1.14.2 yamt
134 1.1.14.2 yamt /*
135 1.1.14.2 yamt * gets() with constrained input length.
136 1.1.14.2 yamt *
137 1.1.14.2 yamt * Copied from: sys/arch/ia64/stand/common/gets.c
138 1.1.14.2 yamt */
139 1.1.14.2 yamt static void
140 1.1.14.2 yamt ngets(char *buf, int n)
141 1.1.14.2 yamt {
142 1.1.14.2 yamt int c;
143 1.1.14.2 yamt char *lp;
144 1.1.14.2 yamt
145 1.1.14.2 yamt for (lp = buf;;) {
146 1.1.14.2 yamt switch (c = getchar() & 0177) {
147 1.1.14.2 yamt case '\n':
148 1.1.14.2 yamt case '\r':
149 1.1.14.2 yamt *lp = '\0';
150 1.1.14.2 yamt putchar('\n');
151 1.1.14.2 yamt return;
152 1.1.14.2 yamt case '\b':
153 1.1.14.2 yamt case '\177':
154 1.1.14.2 yamt if (lp > buf) {
155 1.1.14.2 yamt lp--;
156 1.1.14.2 yamt putchar('\b');
157 1.1.14.2 yamt putchar(' ');
158 1.1.14.2 yamt putchar('\b');
159 1.1.14.2 yamt }
160 1.1.14.2 yamt break;
161 1.1.14.2 yamt case 'r'&037: {
162 1.1.14.2 yamt char *p;
163 1.1.14.2 yamt
164 1.1.14.2 yamt putchar('\n');
165 1.1.14.2 yamt for (p = buf; p < lp; ++p)
166 1.1.14.2 yamt putchar(*p);
167 1.1.14.2 yamt break;
168 1.1.14.2 yamt }
169 1.1.14.2 yamt case 'u'&037:
170 1.1.14.2 yamt case 'w'&037:
171 1.1.14.2 yamt lp = buf;
172 1.1.14.2 yamt putchar('\n');
173 1.1.14.2 yamt break;
174 1.1.14.2 yamt default:
175 1.1.14.2 yamt if ((n < 1) || ((lp - buf) < n)) {
176 1.1.14.2 yamt *lp++ = c;
177 1.1.14.2 yamt putchar(c);
178 1.1.14.2 yamt }
179 1.1.14.2 yamt }
180 1.1.14.2 yamt }
181 1.1.14.2 yamt /*NOTREACHED*/
182 1.1.14.2 yamt }
183