Home | History | Annotate | Line # | Download | only in bootimx23
      1 /* $Id: args_prep.c,v 1.4 2017/12/10 02:26:41 christos 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 <machine/bootconfig.h>
     81 
     82 #include <arm/imx/imx23_digctlreg.h>
     83 #include <arm/imx/imx23_uartdbgreg.h>
     84 
     85 #include "common.h"
     86 
     87 static void ngets(char *, int);
     88 
     89 #define L1_PAGE_TABLE (DRAM_BASE + MEMSIZE * 1024 * 1024 - L1_TABLE_SIZE)
     90 #define BOOTIMX23_ARGS (L1_PAGE_TABLE - MAX_BOOT_STRING - 1)
     91 
     92 #define PROMPT_DELAY 5000000 /* Wait 5 seconds user to press any key. */
     93 
     94 int
     95 args_prep(void)
     96 {
     97 	u_int prompt;
     98 	char *boot_args = (char *)BOOTIMX23_ARGS;
     99 
    100 	/* Copy default boot arguments. */
    101 	memset((void *)boot_args, 0x00, MAX_BOOT_STRING);
    102 	strcpy(boot_args, KERNEL_BOOT_ARGS);
    103 
    104 	prompt = 0;
    105 
    106 	/* Enable debug UART data reception which was not enabled by the ROM. */
    107 	uint16_t cr = REG_RD_HW(HW_UARTDBG_BASE + HW_UARTDBGCR);
    108 	cr |= HW_UARTDBGCR_RXE;
    109 	REG_WR_HW(HW_UARTDBG_BASE + HW_UARTDBGCR, cr);
    110 
    111 	printf("Press any key to drop into boot prompt...\n\r");
    112 
    113 	REG_WR(HW_DIGCTL_BASE + HW_DIGCTL_MICROSECONDS_CLR, 0xFFFFFFFF);
    114 
    115 	while (REG_RD(HW_DIGCTL_BASE + HW_DIGCTL_MICROSECONDS) < PROMPT_DELAY) {
    116 		if (!(REG_RD_HW(HW_UARTDBG_BASE + HW_UARTDBGFR) &
    117 		    HW_UARTDBGFR_RXFE)) {
    118 			/* RX FIFO is not empty, some key was pressed. */
    119 			REG_RD(HW_UARTDBG_BASE + HW_UARTDBGDR); /* Flush. */
    120 			prompt = 1;
    121 			break;
    122 		}
    123 	}
    124 
    125 	if (prompt) {
    126 		memset((void *)boot_args, 0x00, MAX_BOOT_STRING);
    127 		printf("boot: ");
    128 		ngets(boot_args, MAX_BOOT_STRING);
    129 	}
    130 
    131 	return 0;
    132 }
    133 
    134 /*
    135  * gets() with constrained input length.
    136  *
    137  * Copied from: sys/arch/ia64/stand/common/gets.c
    138  */
    139 static void
    140 ngets(char *buf, int n)
    141 {
    142 	int c;
    143 	char *lp;
    144 
    145 	for (lp = buf;;) {
    146 		switch (c = getchar() & 0177) {
    147 		case '\n':
    148 		case '\r':
    149 			*lp = '\0';
    150 			putchar('\n');
    151 			return;
    152 		case '\b':
    153 		case '\177':
    154 			if (lp > buf) {
    155 				lp--;
    156 				putchar('\b');
    157 				putchar(' ');
    158 				putchar('\b');
    159 			}
    160 			break;
    161 		case 'r'&037: {
    162 			char *p;
    163 
    164 			putchar('\n');
    165 			for (p = buf; p < lp; ++p)
    166 				putchar(*p);
    167 			break;
    168 		}
    169 		case 'u'&037:
    170 		case 'w'&037:
    171 			lp = buf;
    172 			putchar('\n');
    173 			break;
    174 		default:
    175 			if ((n < 1) || ((lp - buf) < n)) {
    176 				*lp++ = c;
    177 				putchar(c);
    178 			}
    179 		}
    180 	}
    181 	/*NOTREACHED*/
    182 }
    183