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