Module Name: src Committed By: jkunz Date: Sat Feb 23 16:22:39 UTC 2013
Modified Files: src/sys/arch/evbarm/imx23_olinuxino: imx23_olinuxino_machdep.c src/sys/arch/evbarm/stand/bootimx23: Makefile boot_prep.c common.c common.h Added Files: src/sys/arch/evbarm/stand/bootimx23: args_prep.c Log Message: Contribution from Petri Laakso: - Support for passing kernel arguments. - entropy_init() removed as OLINUXINO doesn't generate entropy bits without user interaction. - FIFO contents are flushed when DEBUG is enabled. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 \ src/sys/arch/evbarm/imx23_olinuxino/imx23_olinuxino_machdep.c cvs rdiff -u -r1.4 -r1.5 src/sys/arch/evbarm/stand/bootimx23/Makefile cvs rdiff -u -r0 -r1.1 src/sys/arch/evbarm/stand/bootimx23/args_prep.c cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbarm/stand/bootimx23/boot_prep.c \ src/sys/arch/evbarm/stand/bootimx23/common.c \ src/sys/arch/evbarm/stand/bootimx23/common.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/evbarm/imx23_olinuxino/imx23_olinuxino_machdep.c diff -u src/sys/arch/evbarm/imx23_olinuxino/imx23_olinuxino_machdep.c:1.1 src/sys/arch/evbarm/imx23_olinuxino/imx23_olinuxino_machdep.c:1.2 --- src/sys/arch/evbarm/imx23_olinuxino/imx23_olinuxino_machdep.c:1.1 Tue Nov 20 19:08:45 2012 +++ src/sys/arch/evbarm/imx23_olinuxino/imx23_olinuxino_machdep.c Sat Feb 23 16:22:38 2013 @@ -1,4 +1,4 @@ -/* $Id: imx23_olinuxino_machdep.c,v 1.1 2012/11/20 19:08:45 jkunz Exp $ */ +/* $Id: imx23_olinuxino_machdep.c,v 1.2 2013/02/23 16:22:38 jkunz Exp $ */ /* * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -38,6 +38,7 @@ #include <sys/param.h> #include <sys/reboot.h> #include <sys/rnd.h> +#include <sys/systm.h> #include <sys/termios.h> #include <sys/types.h> @@ -94,11 +95,11 @@ static const struct pmap_devmap imx23_de static vm_offset_t physical_freestart; static vm_offset_t physical_freeend; static u_int free_pages; -//static rndsave_t imx23_boot_rsp; BootConfig bootconfig; vm_offset_t physical_start; vm_offset_t physical_end; +static char kernel_boot_args[MAX_BOOT_STRING]; char *boot_args; paddr_t msgbufphys; @@ -142,6 +143,9 @@ pv_addr_t kernel_pt_table[NUM_KERNEL_PTS #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000) #define KERNEL_VM_SIZE (0xf0000000 - KERNEL_VM_BASE) +#define L1_PAGE_TABLE (DRAM_BASE + MEMSIZE * 1024 * 1024 - L1_TABLE_SIZE) +#define BOOTIMX23_ARGS (L1_PAGE_TABLE - MAX_BOOT_STRING - 1) + #define REG_RD(reg) *(volatile uint32_t *)(reg) #define REG_WR(reg, val) \ do { \ @@ -163,7 +167,6 @@ initarm(void *arg) cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); consinit(); - //entropy_init(); /* Talk to the user. */ #define BDSTR(s) _BDSTR(s) @@ -172,7 +175,14 @@ initarm(void *arg) #undef BDSTR #undef _BDSTR - boot_args[0] = '\0'; + /* Copy boot arguments passed from bootimx23. */ + boot_args = (char *)BOOTIMX23_ARGS; + memcpy(kernel_boot_args, boot_args, MAX_BOOT_STRING); + boot_args = kernel_boot_args; +#ifdef VERBOSE_INIT_ARM + printf("boot_args: %s\n", boot_args); +#endif + parse_mi_bootargs(boot_args); #ifdef VERBOSE_INIT_ARM printf("initarm: Configuring system ...\n"); @@ -520,38 +530,6 @@ setup_real_page_tables(void) } /* - * Generate initial random bits for rnd_init(). - */ -#ifdef notyet -static void -entropy_init(void) -{ - uint32_t tmp; - int loop, index; - - /* Test if HW_DIGCTL_ENTROPY is feeding random numbers. */ - tmp = REG_RD(HW_DIGCTL_BASE + HW_DIGCTL_ENTROPY); - if (tmp == REG_RD(HW_DIGCTL_BASE + HW_DIGCTL_ENTROPY)) - return; - - index = 0; - for (loop = 0; loop < RND_SAVEWORDS; loop++) { - imx23_boot_rsp.data[index++] = (uint8_t)(tmp); - imx23_boot_rsp.data[index++] = (uint8_t)(tmp>>8); - imx23_boot_rsp.data[index++] = (uint8_t)(tmp>>16); - imx23_boot_rsp.data[index++] = (uint8_t)(tmp>>24); - imx23_boot_rsp.entropy += 32; - tmp = REG_RD(HW_DIGCTL_BASE + HW_DIGCTL_ENTROPY); - } - - extern rndsave_t *boot_rsp; - boot_rsp = &imx23_boot_rsp; - - return; -} -#endif - -/* * Initialize console. */ static struct plcom_instance imx23_pi = { Index: src/sys/arch/evbarm/stand/bootimx23/Makefile diff -u src/sys/arch/evbarm/stand/bootimx23/Makefile:1.4 src/sys/arch/evbarm/stand/bootimx23/Makefile:1.5 --- src/sys/arch/evbarm/stand/bootimx23/Makefile:1.4 Wed Feb 6 07:19:19 2013 +++ src/sys/arch/evbarm/stand/bootimx23/Makefile Sat Feb 23 16:22:39 2013 @@ -1,15 +1,16 @@ -# $Id: Makefile,v 1.4 2013/02/06 07:19:19 matt Exp $ +# $Id: Makefile,v 1.5 2013/02/23 16:22:39 jkunz Exp $ S= ${.CURDIR}/../../../../ PROG= bootimx23 -SRCS= boot_prep.c power_prep.c clock_prep.c emi_prep.c \ - pinctrl_prep.c common.c +SRCS= args_prep.c boot_prep.c clock_prep.c common.c emi_prep.c \ + pinctrl_prep.c power_prep.c .include <bsd.own.mk> CLEANFILES+= ${PROG} CFLAGS+= -Wall -Wno-main -ffreestanding -march=armv5te -mtune=arm926ej-s -CPPFLAGS+= -D_STANDALONE +CPPFLAGS+= -D_STANDALONE -DMEMSIZE=64 +CPPFLAGS+= -DKERNEL_BOOT_ARGS=\"root=ld0a\" CPPFLAGS+= -nostdinc -I. -I${.CURDIR} -I${.OBJDIR} -I${S} -I${S}/arch CPPFLAGS+= -mabi=apcs-gnu -mfloat-abi=soft #CPPFLAGS+= -DDEBUG Index: src/sys/arch/evbarm/stand/bootimx23/boot_prep.c diff -u src/sys/arch/evbarm/stand/bootimx23/boot_prep.c:1.2 src/sys/arch/evbarm/stand/bootimx23/boot_prep.c:1.3 --- src/sys/arch/evbarm/stand/bootimx23/boot_prep.c:1.2 Sun Dec 16 19:08:44 2012 +++ src/sys/arch/evbarm/stand/bootimx23/boot_prep.c Sat Feb 23 16:22:39 2013 @@ -1,4 +1,4 @@ -/* $Id: boot_prep.c,v 1.2 2012/12/16 19:08:44 jkunz Exp $ */ +/* $Id: boot_prep.c,v 1.3 2013/02/23 16:22:39 jkunz Exp $ */ /* * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -63,5 +63,7 @@ _start(void) emi_prep(); printf("done.\n\r"); + args_prep(); + return 0; } Index: src/sys/arch/evbarm/stand/bootimx23/common.c diff -u src/sys/arch/evbarm/stand/bootimx23/common.c:1.2 src/sys/arch/evbarm/stand/bootimx23/common.c:1.3 --- src/sys/arch/evbarm/stand/bootimx23/common.c:1.2 Sun Dec 16 19:08:44 2012 +++ src/sys/arch/evbarm/stand/bootimx23/common.c Sat Feb 23 16:22:39 2013 @@ -1,4 +1,4 @@ -/* $Id: common.c,v 1.2 2012/12/16 19:08:44 jkunz Exp $ */ +/* $Id: common.c,v 1.3 2013/02/23 16:22:39 jkunz Exp $ */ /* * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -78,14 +78,29 @@ putchar(int ch) { /* Wait until transmit FIFO has space for the new character. */ - while (REG_RD(HW_UARTDBG_BASE + HW_UARTDBGFR) & HW_UARTDBGFR_TXFF); + while (REG_RD_HW(HW_UARTDBG_BASE + HW_UARTDBGFR) & HW_UARTDBGFR_TXFF); REG_WR_BYTE(HW_UARTDBG_BASE + HW_UARTDBGDR, __SHIFTIN(ch, HW_UARTDBGDR_DATA)); #ifdef DEBUG /* Flush: Wait until transmit FIFO contents are written to UART. */ - while (!(REG_RD(HW_UARTDBG_BASE + HW_UARTDBGFR) & HW_UARTDBGFR_TXFE)); + while (!(REG_RD_HW(HW_UARTDBG_BASE + HW_UARTDBGFR) & + HW_UARTDBGFR_TXFE)); #endif return; } + +/* + * Read character from debug UART. + */ +int +getchar(void) +{ + + /* Wait until receive FIFO has character(s) */ + + while (REG_RD_HW(HW_UARTDBG_BASE + HW_UARTDBGFR) & HW_UARTDBGFR_RXFE); + + return REG_RD_HW(HW_UARTDBG_BASE + HW_UARTDBGDR) & 0xFF; +} Index: src/sys/arch/evbarm/stand/bootimx23/common.h diff -u src/sys/arch/evbarm/stand/bootimx23/common.h:1.2 src/sys/arch/evbarm/stand/bootimx23/common.h:1.3 --- src/sys/arch/evbarm/stand/bootimx23/common.h:1.2 Sun Dec 16 19:08:44 2012 +++ src/sys/arch/evbarm/stand/bootimx23/common.h Sat Feb 23 16:22:39 2013 @@ -1,4 +1,4 @@ -/* $Id: common.h,v 1.2 2012/12/16 19:08:44 jkunz Exp $ */ +/* $Id: common.h,v 1.3 2013/02/23 16:22:39 jkunz Exp $ */ /* * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -37,6 +37,12 @@ do { \ *(volatile uint32_t *)((reg)) = val; \ } while (0) +#define REG_RD_HW(reg) *(volatile uint16_t *)(reg) +#define REG_WR_HW(reg, val) \ +do { \ + *(volatile uint16_t *)((reg)) = val; \ +} while (0) +#define REG_RD_BYTE(reg) *(volatile uint8_t *)(reg) #define REG_WR_BYTE(reg, val) \ do { \ *(volatile uint8_t *)((reg)) = val; \ @@ -46,7 +52,9 @@ int clock_prep(void); int emi_prep(void); int pinctrl_prep(void); int power_prep(void); +int args_prep(void); void delay(unsigned int); void putchar(int); +int getchar(void); #endif /* !_BOOTIMX23_COMMON_ */ Added files: Index: src/sys/arch/evbarm/stand/bootimx23/args_prep.c diff -u /dev/null src/sys/arch/evbarm/stand/bootimx23/args_prep.c:1.1 --- /dev/null Sat Feb 23 16:22:39 2013 +++ src/sys/arch/evbarm/stand/bootimx23/args_prep.c Sat Feb 23 16:22:39 2013 @@ -0,0 +1,182 @@ +/* $Id: args_prep.c,v 1.1 2013/02/23 16:22:39 jkunz Exp $ */ + +/* + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Petri Laakso. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* (c) for ngets() below: + * + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)gets.c 8.1 (Berkeley) 6/11/93 + */ + + +#include <sys/param.h> +#include <sys/types.h> +#include <sys/cdefs.h> + +#include <lib/libsa/stand.h> +#include <lib/libkern/libkern.h> + +#include <arm/arm32/pte.h> +#define _LOCORE +#include <arm/imx/imx23var.h> +#undef _LOCORE +#include <evbarm/bootconfig.h> + +#include <arm/imx/imx23_digctlreg.h> +#include <arm/imx/imx23_uartdbgreg.h> + +#include "common.h" + +static void ngets(char *, int); + +#define L1_PAGE_TABLE (DRAM_BASE + MEMSIZE * 1024 * 1024 - L1_TABLE_SIZE) +#define BOOTIMX23_ARGS (L1_PAGE_TABLE - MAX_BOOT_STRING - 1) + +#define PROMPT_DELAY 5000000 /* Wait 5 seconds user to press any key. */ + +int +args_prep(void) +{ + u_int prompt; + char *boot_args = (char *)BOOTIMX23_ARGS; + + /* Copy default boot arguments. */ + memset((void *)boot_args, 0x00, MAX_BOOT_STRING); + strcpy(boot_args, KERNEL_BOOT_ARGS); + + prompt = 0; + + /* Enable debug UART data reception which was not enabled by the ROM. */ + uint16_t cr = REG_RD_HW(HW_UARTDBG_BASE + HW_UARTDBGCR); + cr |= HW_UARTDBGCR_RXE; + REG_WR_HW(HW_UARTDBG_BASE + HW_UARTDBGCR, cr); + + printf("Press any key to drop into boot prompt...\n\r"); + + REG_WR(HW_DIGCTL_BASE + HW_DIGCTL_MICROSECONDS_CLR, 0xFFFFFFFF); + + while (REG_RD(HW_DIGCTL_BASE + HW_DIGCTL_MICROSECONDS) < PROMPT_DELAY) { + if (!(REG_RD_HW(HW_UARTDBG_BASE + HW_UARTDBGFR) & + HW_UARTDBGFR_RXFE)) { + /* RX FIFO is not empty, some key was pressed. */ + REG_RD(HW_UARTDBG_BASE + HW_UARTDBGDR); /* Flush. */ + prompt = 1; + break; + } + } + + if (prompt) { + memset((void *)boot_args, 0x00, MAX_BOOT_STRING); + printf("boot: "); + ngets(boot_args, MAX_BOOT_STRING); + } + + return 0; +} + +/* + * gets() with constrained input length. + * + * Copied from: sys/arch/ia64/stand/common/gets.c + */ +static void +ngets(char *buf, int n) +{ + int c; + char *lp; + + for (lp = buf;;) { + switch (c = getchar() & 0177) { + case '\n': + case '\r': + *lp = '\0'; + putchar('\n'); + return; + case '\b': + case '\177': + if (lp > buf) { + lp--; + putchar('\b'); + putchar(' '); + putchar('\b'); + } + break; + case 'r'&037: { + char *p; + + putchar('\n'); + for (p = buf; p < lp; ++p) + putchar(*p); + break; + } + case 'u'&037: + case 'w'&037: + lp = buf; + putchar('\n'); + break; + default: + if ((n < 1) || ((lp - buf) < n)) { + *lp++ = c; + putchar(c); + } + } + } + /*NOTREACHED*/ +}