Home | History | Annotate | Line # | Download | only in lcboot
main.c revision 1.3.2.3
      1  1.3.2.3  skrll /* $NetBSD: main.c,v 1.3.2.3 2004/09/21 13:16:12 skrll Exp $ */
      2      1.1    igy 
      3      1.1    igy /*
      4  1.3.2.1  skrll  * Copyright (c) 2003 Naoto Shimazaki.
      5      1.1    igy  * All rights reserved.
      6      1.1    igy  *
      7      1.1    igy  * Redistribution and use in source and binary forms, with or without
      8      1.1    igy  * modification, are permitted provided that the following conditions
      9      1.1    igy  * are met:
     10      1.1    igy  * 1. Redistributions of source code must retain the above copyright
     11      1.1    igy  *    notice, this list of conditions and the following disclaimer.
     12      1.1    igy  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1    igy  *    notice, this list of conditions and the following disclaimer in the
     14      1.1    igy  *    documentation and/or other materials provided with the distribution.
     15  1.3.2.1  skrll  *
     16  1.3.2.1  skrll  * THIS SOFTWARE IS PROVIDED BY NAOTO SHIMAZAKI AND CONTRIBUTORS ``AS IS''
     17  1.3.2.1  skrll  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     18  1.3.2.1  skrll  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.3.2.1  skrll  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE NAOTO OR CONTRIBUTORS BE
     20  1.3.2.1  skrll  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21      1.1    igy  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22      1.1    igy  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23      1.1    igy  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24      1.1    igy  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.3.2.1  skrll  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     26  1.3.2.1  skrll  * THE POSSIBILITY OF SUCH DAMAGE.
     27      1.1    igy  */
     28      1.1    igy 
     29      1.1    igy /*
     30      1.1    igy  * Boot loader for L-Card+
     31      1.1    igy  *
     32      1.1    igy  * ROM Map
     33      1.1    igy  * -------
     34      1.1    igy  * ROM1
     35      1.1    igy  * BFFF FFFF	------------------------------
     36      1.1    igy  *
     37      1.1    igy  *		reserved
     38      1.1    igy  *
     39      1.1    igy  * BF80 0000	------------------------------
     40      1.1    igy  *
     41      1.1    igy  * ROM0
     42      1.1    igy  * BFFF FFFF	------------------------------
     43      1.1    igy  *
     44      1.1    igy  *		user storage (max 2Mbytes)
     45      1.1    igy  *
     46      1.1    igy  * BFE0 0000	------------------------------
     47      1.1    igy  *
     48      1.1    igy  *		reserved
     49      1.1    igy  *
     50      1.1    igy  * BFD4 0000	------------------------------
     51      1.1    igy  *
     52      1.1    igy  *		boot params
     53      1.1    igy  *
     54      1.1    igy  * BFD2 0000	------------------------------
     55      1.1    igy  *
     56      1.1    igy  *		second boot loader (mirror image)
     57      1.1    igy  *		or Linux Kernel
     58      1.1    igy  *
     59      1.1    igy  * BFD0 0000	------------------------------
     60      1.1    igy  *
     61      1.1    igy  *		first boot loader (L-Card+ original loader)
     62      1.1    igy  *
     63      1.1    igy  *		reset vector
     64      1.1    igy  * BFC0 0000	------------------------------
     65      1.1    igy  *
     66      1.1    igy  *		gziped kernel image (max 4Mbytes)
     67      1.1    igy  *
     68      1.1    igy  * BF80 0000	------------------------------
     69      1.1    igy  *
     70      1.1    igy  *
     71      1.1    igy  *
     72      1.1    igy  * RAM Map
     73      1.1    igy  * -------
     74      1.1    igy  *
     75      1.1    igy  * 80FF FFFF	------------------------------
     76      1.1    igy  *		ROM ICE work
     77      1.1    igy  * 80FF FE00	------------------------------
     78      1.1    igy  *		ROM ICE stack
     79      1.1    igy  * 80FF FDA8	------------------------------
     80      1.1    igy  *
     81      1.1    igy  *
     82      1.1    igy  *
     83      1.1    igy  *		kernel
     84      1.1    igy  * 8004 0000	------------------------------
     85      1.1    igy  *		kernel stack (growing to lower)
     86      1.1    igy  *
     87      1.1    igy  *
     88      1.1    igy  *		boot loader heap (growing to upper)
     89      1.1    igy  *		boot loader text & data (at exec time)
     90      1.1    igy  * 8000 1000	------------------------------
     91      1.1    igy  *		vector table
     92      1.1    igy  * 8000 0000	------------------------------
     93      1.1    igy  *
     94      1.1    igy  *		virtual memory space
     95      1.1    igy  *
     96      1.1    igy  * 0000 0000	------------------------------
     97      1.1    igy  *
     98      1.1    igy  *
     99      1.1    igy  *
    100      1.1    igy  * ROMCS0 <-> ROMCS3 mapping
    101      1.1    igy  *
    102      1.1    igy  *  ROMCS0        ROMCS3
    103      1.1    igy  * BE7F FFFF <-> BFFF FFFF
    104      1.1    igy  * BE40 0000 <-> BFC0 0000	reset vector
    105      1.1    igy  * BE00 0000 <-> BF80 0000
    106      1.1    igy  *
    107      1.1    igy  *
    108      1.1    igy  */
    109  1.3.2.1  skrll #include <sys/cdefs.h>
    110  1.3.2.3  skrll __KERNEL_RCSID(0, "$NetBSD: main.c,v 1.3.2.3 2004/09/21 13:16:12 skrll Exp $");
    111      1.1    igy 
    112      1.1    igy #include <lib/libsa/stand.h>
    113  1.3.2.1  skrll 
    114      1.1    igy #include <lib/libsa/loadfile.h>
    115      1.1    igy #include <lib/libkern/libkern.h>
    116      1.1    igy 
    117      1.1    igy #include <hpcmips/vr/vripreg.h>
    118      1.1    igy #include <hpcmips/vr/cmureg.h>
    119      1.1    igy #include <hpcmips/vr/vr4181giureg.h>
    120      1.1    igy 
    121      1.1    igy #include "extern.h"
    122      1.1    igy #include "i28f128reg.h"
    123      1.1    igy 
    124      1.1    igy /* XXX */
    125      1.1    igy #define ISABRGCTL	0x00
    126      1.1    igy #define ISABRGSTS	0x02
    127      1.1    igy #define XISACTL		0x04
    128      1.1    igy 
    129      1.1    igy #define BOOTTIMEOUT	9	/* must less than 10 */
    130      1.1    igy #define LINEBUFLEN	80
    131      1.1    igy 
    132      1.1    igy extern const char bootprog_rev[];
    133      1.1    igy extern const char bootprog_name[];
    134      1.1    igy extern const char bootprog_date[];
    135      1.1    igy extern const char bootprog_maker[];
    136      1.1    igy 
    137      1.1    igy static void command_help(char *opt);
    138      1.1    igy static void command_dump(char *opt);
    139      1.1    igy static void command_boot(char *opt);
    140      1.1    igy static void command_load(char *opt);
    141      1.1    igy static void command_fill(char *opt);
    142      1.1    igy static void command_write(char *opt);
    143  1.3.2.1  skrll static void command_option(char *subcmd);
    144  1.3.2.1  skrll static void opt_subcmd_print(char *opt);
    145  1.3.2.1  skrll static void opt_subcmd_read(char *opt);
    146  1.3.2.1  skrll static void opt_subcmd_write(char *opt);
    147  1.3.2.1  skrll static void opt_subcmd_path(char *opt);
    148  1.3.2.1  skrll static void opt_subcmd_bootp(char *opt);
    149  1.3.2.1  skrll static void opt_subcmd_ip(char *opt);
    150  1.3.2.1  skrll 
    151  1.3.2.1  skrll 
    152  1.3.2.1  skrll struct boot_option	bootopts;
    153      1.1    igy 
    154      1.1    igy static struct bootmenu_command commands[] = {
    155      1.1    igy 	{ "?",		command_help },
    156      1.1    igy 	{ "h",		command_help },
    157      1.1    igy 	{ "d",		command_dump },
    158      1.1    igy 	{ "b",		command_boot },
    159      1.1    igy 	{ "l",		command_load },
    160      1.1    igy 	{ "f",		command_fill },
    161      1.1    igy 	{ "w",		command_write },
    162  1.3.2.1  skrll 	{ "o",		command_option },
    163  1.3.2.1  skrll 	{ NULL,		NULL },
    164  1.3.2.1  skrll };
    165  1.3.2.1  skrll 
    166  1.3.2.1  skrll static struct bootmenu_command opt_subcommands[] = {
    167  1.3.2.1  skrll 	{ "p",		opt_subcmd_print },
    168  1.3.2.1  skrll 	{ "r",		opt_subcmd_read },
    169  1.3.2.1  skrll 	{ "w",		opt_subcmd_write },
    170  1.3.2.1  skrll 	{ "path",	opt_subcmd_path },
    171  1.3.2.1  skrll 	{ "bootp",	opt_subcmd_bootp },
    172  1.3.2.1  skrll 	{ "ip",		opt_subcmd_ip },
    173      1.1    igy 	{ NULL,		NULL },
    174      1.1    igy };
    175      1.1    igy 
    176      1.1    igy static void
    177      1.1    igy print_banner(void)
    178      1.1    igy {
    179      1.1    igy 	printf("\n");
    180      1.1    igy 	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
    181      1.1    igy 	printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
    182      1.1    igy #if 0
    183      1.1    igy 	printf(">> Memory: %d/%d k\n", getbasemem(), getextmem());
    184      1.1    igy #endif
    185      1.1    igy }
    186      1.1    igy 
    187      1.1    igy static void
    188      1.1    igy init_devices(void)
    189      1.1    igy {
    190      1.1    igy 	/* Init RTC */
    191      1.1    igy 	REGWRITE_2(VRETIMEH, 0, 0);
    192      1.1    igy 	REGWRITE_2(VRETIMEM, 0, 0);
    193      1.1    igy 	REGWRITE_2(VRETIMEL, 0, 0);
    194      1.1    igy 
    195      1.1    igy 
    196      1.1    igy 	/*
    197      1.1    igy 	 * CLKSPEEDREG	0x6012
    198      1.1    igy 	 *	DIV	DIV2 mode
    199      1.1    igy 	 *	CLKSP	18 (0x12)
    200      1.1    igy 	 *	PClock (CPU clock)		65.536MHz
    201      1.1    igy 	 *		PClock = (18.432MHz / CLKSP) x 64
    202      1.1    igy 	 *		       = (18.432MHz / 18) x 64
    203      1.1    igy 	 *		       = 65.536MHz
    204      1.1    igy 	 *	TClock (peripheral clock)	32.768MHz
    205      1.1    igy 	 *		TClock = PClock / DIV
    206      1.1    igy 	 *		       = 65.536MHz / 2
    207      1.1    igy 	 *		       = 32.768MHz
    208      1.1    igy 	 */
    209      1.1    igy 
    210      1.1    igy 	/*
    211      1.1    igy 	 * setup ISA BUS clock freqency
    212      1.1    igy 	 *
    213      1.1    igy 	 * set PCLK (internal peripheral clock) to 32.768MHz (TClock / 1)
    214      1.1    igy 	 * set External ISA bus clock to 10.922MHz (TClock / 3)
    215      1.1    igy 	 */
    216      1.1    igy 	REGWRITE_2(VR4181_ISABRG_ADDR, ISABRGCTL, 0x0003);
    217      1.1    igy 	REGWRITE_2(VR4181_ISABRG_ADDR, XISACTL, 0x0401);
    218      1.1    igy 
    219      1.1    igy 	/*
    220      1.1    igy 	 * setup peripheral's clock supply
    221      1.1    igy 	 *
    222      1.1    igy 	 * CSU: disable
    223      1.1    igy 	 * AIU: enable (AIU, ADU, ADU18M)
    224      1.1    igy 	 * PIU: disable
    225      1.1    igy 	 * SIU: enable (SIU18M)
    226      1.1    igy 	 */
    227      1.1    igy 	REGWRITE_2(VR4181_CMU_ADDR, 0, CMUMASK_SIU | CMUMASK_AIU);
    228      1.1    igy 
    229      1.1    igy 	/*
    230      1.1    igy 	 * setup GPIO
    231      1.1    igy 	 */
    232      1.1    igy #if 0
    233      1.1    igy 	/* L-Card+ generic setup */
    234      1.1    igy 	/*
    235      1.1    igy 	 * pin   mode	comment
    236      1.1    igy 	 * GP0 : GPI	not used
    237      1.1    igy 	 * GP1 : GPI	not used
    238      1.1    igy 	 * GP2 : GPO	LED6 (0: on  1: off)
    239      1.1    igy 	 * GP3 : PCS0	chip select for CS8900A Lan controller
    240      1.1    igy 	 * GP4 : GPI	IRQ input from CS8900A
    241      1.1    igy 	 * GP5 : GPI	not used
    242      1.1    igy 	 * GP6 : GPI	not used
    243      1.1    igy 	 * GP7 : GPI	reserved by TANBAC TB0193
    244      1.1    igy 	 */
    245      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PIOD_L_REG_W, 0xffff);
    246      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE0_REG_W,
    247      1.1    igy 		   GP3_PCS0 | GP2_GPO);
    248      1.1    igy 	/*
    249      1.1    igy 	 * pin   mode	comment
    250      1.1    igy 	 * GP8 : GPO	LED5 (0: on  1: off)
    251      1.1    igy 	 * GP9 : GPI	CD2
    252      1.1    igy 	 * GP10: GPI	CD1
    253      1.1    igy 	 * GP11: GPI	not used
    254      1.1    igy 	 * GP12: GPI	not used
    255      1.1    igy 	 * GP13: GPI	not used
    256      1.1    igy 	 * GP14: GPI	not used
    257      1.1    igy 	 * GP15: GPI	not used
    258      1.1    igy 	 */
    259      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE1_REG_W, GP8_GPO);
    260      1.1    igy 	/*
    261      1.1    igy 	 * pin   mode	comment
    262      1.1    igy 	 * GP16: IORD	ISA bus
    263      1.1    igy 	 * GP17: IOWR	ISA bus
    264      1.1    igy 	 * GP18: IORDY	ISA bus
    265      1.1    igy 	 * GP19: GPI	not used
    266      1.1    igy 	 * GP20: GPI	not used
    267      1.1    igy 	 * GP21: RESET	resets CS8900A
    268      1.1    igy 	 * GP22: ROMCS0	ROM chip select
    269      1.1    igy 	 * GP23: ROMCS1	ROM chip select
    270      1.1    igy 	 */
    271      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE2_REG_W,
    272      1.1    igy 		   GP23_ROMCS1 | GP22_ROMCS0 | GP21_RESET
    273      1.1    igy 		   | GP18_IORDY | GP17_IOWR | GP16_IORD);
    274      1.1    igy 	/*
    275      1.1    igy 	 * GP24: ROMCS2	ROM chip select
    276      1.1    igy 	 * GP25: RxD1	SIU1
    277      1.1    igy 	 * GP26: TxD1	SIU1
    278      1.1    igy 	 * GP27: RTS1	SIU1
    279      1.1    igy 	 * GP28: CTS1	SIU1
    280      1.1    igy 	 * GP29: GPI	LED3
    281      1.1    igy 	 * GP30: GPI	reserved by TANBAC TB0193
    282      1.1    igy 	 * GP31: GPI	LED4
    283      1.1    igy 	 */
    284      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE3_REG_W,
    285      1.1    igy 		   GP30_GPI
    286      1.1    igy 		   | GP28_CTS1 | GP27_RTS1 | GP26_TxD1 | GP25_RxD1
    287      1.1    igy 		   | GP24_ROMCS2);
    288      1.1    igy #else
    289      1.1    igy 	/* e-care node specific setup */
    290      1.1    igy 	/*
    291      1.1    igy 	 * pin   mode	comment
    292      1.1    igy 	 * GP0 : GPO	ECNRTC_RST
    293      1.1    igy 	 * GP1 : GPO	ECNRTC_CLK
    294      1.1    igy 	 * GP2 : GPO	LED6 (0: on  1: off)
    295      1.1    igy 	 * GP3 : PCS0	chip select for CS8900A Lan controller
    296      1.1    igy 	 * GP4 : GPI	IRQ input from CS8900A
    297      1.1    igy 	 * GP5 : GPO	ECNRTC_DIR
    298      1.1    igy 	 * GP6 : GPO	ECNRTC_OUT
    299      1.1    igy 	 * GP7 : GPI	reserved by TANBAC TB0193
    300      1.1    igy 	 */
    301      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PIOD_L_REG_W, 0xffff);
    302      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE0_REG_W,
    303      1.1    igy 		   GP6_GPO | GP5_GPO | GP3_PCS0
    304      1.1    igy 		   | GP2_GPO | GP1_GPO | GP0_GPO);
    305      1.1    igy 
    306      1.1    igy 	/*
    307      1.1    igy 	 * pin   mode	comment
    308      1.1    igy 	 * GP8 : GPO	LED5 (0: on  1: off)
    309      1.1    igy 	 * GP9 : GPI	CD2
    310      1.1    igy 	 * GP10: GPI	CD1
    311      1.1    igy 	 * GP11: GPI	not used
    312      1.1    igy 	 * GP12: GPI	ECNRTC_IN
    313      1.1    igy 	 * GP13: GPI	not used
    314      1.1    igy 	 * GP14: GPI	not used
    315      1.1    igy 	 * GP15: GPI	not used
    316      1.1    igy 	 */
    317      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE1_REG_W,
    318      1.1    igy 		   GP12_GPI | GP8_GPO);
    319      1.1    igy 
    320      1.1    igy 	/*
    321      1.1    igy 	 * pin   mode	comment
    322      1.1    igy 	 * GP16: IORD	ISA bus
    323      1.1    igy 	 * GP17: IOWR	ISA bus
    324      1.1    igy 	 * GP18: IORDY	ISA bus
    325      1.1    igy 	 * GP19: GPI	not used
    326      1.1    igy 	 * GP20: GPI	not used
    327      1.1    igy 	 * GP21: RESET	resets CS8900A
    328      1.1    igy 	 * GP22: ROMCS0	ROM chip select
    329      1.1    igy 	 * GP23: ROMCS1	ROM chip select
    330      1.1    igy 	 */
    331      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE2_REG_W,
    332      1.1    igy 		   GP23_ROMCS1 | GP22_ROMCS0 | GP21_RESET
    333      1.1    igy 		   | GP18_IORDY | GP17_IOWR | GP16_IORD);
    334      1.1    igy 	/*
    335      1.1    igy 	 * GP24: ROMCS2	ROM chip select
    336      1.1    igy 	 * GP25: RxD1	SIU1
    337      1.1    igy 	 * GP26: TxD1	SIU1
    338      1.1    igy 	 * GP27: RTS1	SIU1
    339      1.1    igy 	 * GP28: CTS1	SIU1
    340      1.1    igy 	 * GP29: GPI	LED3
    341      1.1    igy 	 * GP30: GPI	reserved by TANBAC TB0193
    342      1.1    igy 	 * GP31: GPI	LED4
    343      1.1    igy 	 */
    344      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_MODE3_REG_W,
    345      1.1    igy 		   GP30_GPI
    346      1.1    igy 		   | GP28_CTS1 | GP27_RTS1 | GP26_TxD1 | GP25_RxD1
    347      1.1    igy 		   | GP24_ROMCS2);
    348      1.1    igy #endif
    349      1.1    igy 
    350      1.1    igy #if 0
    351      1.1    igy 	/*
    352      1.1    igy 	 * setup interrupt
    353      1.1    igy 	 *
    354      1.1    igy 	 * I4TYP:  falling edge trigger
    355      1.1    igy 	 * GIMSK4: unmask
    356      1.1    igy 	 * GIEN4:  enable
    357      1.1    igy 	 * other:  unused, mask, disable
    358      1.1    igy 	 */
    359      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_INTTYP_L_REG_W,
    360      1.1    igy 		   I4TYP_HIGH_LEVEL);
    361      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_INTMASK_REG_W,
    362      1.1    igy 		   0xffffU & ~GIMSK4);
    363      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_INTEN_REG_W, GIEN4);
    364      1.1    igy #endif
    365      1.1    igy 
    366      1.1    igy 	/*
    367      1.1    igy 	 * programmable chip select
    368      1.1    igy 	 *
    369      1.1    igy 	 * PCS0 is used to select CS8900A Ethernet controller
    370      1.1    igy 	 * on TB0193
    371      1.1    igy 	 *
    372      1.1    igy 	 * PCS0:
    373      1.1    igy 	 *	0x14010000 - 0x14010fff
    374      1.1    igy 	 *	I/O access, 16bit cycle, both of read/write
    375      1.1    igy 	 * PCS1: unused
    376      1.1    igy 	 */
    377      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PCS0STRA_REG_W, 0x0000);
    378      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PCS0STPA_REG_W, 0x0fff);
    379      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PCS0HIA_REG_W, 0x1401);
    380      1.1    igy 	REGWRITE_2(VR4181_GIU81_ADDR, VR4181GIU_PCSMODE_REG_W,
    381      1.1    igy 		   PCS0MIOB_IO | PCS0DSIZE_16BIT | PCS0MD_READWRITE);
    382      1.1    igy }
    383      1.1    igy 
    384      1.1    igy /*
    385      1.1    igy  * chops the head from the arguments and returns the arguments if any,
    386      1.1    igy  * or possibly an empty string.
    387      1.1    igy  */
    388      1.1    igy static char *
    389      1.1    igy get_next_arg(char *arg)
    390      1.1    igy {
    391      1.1    igy 	char *opt;
    392      1.1    igy 
    393      1.1    igy 	if ((opt = strchr(arg, ' ')) == NULL) {
    394      1.1    igy 		opt = "";
    395      1.1    igy 	} else {
    396      1.1    igy 		*opt++ = '\0';
    397      1.1    igy 	}
    398      1.1    igy 
    399      1.1    igy         /* trim leading blanks */
    400      1.1    igy 	while (*opt == ' ')
    401      1.1    igy 		opt++;
    402      1.1    igy 
    403      1.1    igy 	return opt;
    404      1.1    igy }
    405      1.1    igy 
    406      1.1    igy static void
    407      1.1    igy command_help(char *opt)
    408      1.1    igy {
    409      1.1    igy 	printf("commands are:\n"
    410  1.3.2.1  skrll 	       "boot:\tb\n"
    411  1.3.2.1  skrll 	       "dump:\td addr [addr]\n"
    412  1.3.2.1  skrll 	       "fill:\tf addr addr char\n"
    413  1.3.2.1  skrll 	       "load:\tl [offset] (with following S-Record)\n"
    414  1.3.2.1  skrll 	       "write:\tw dst src len\n"
    415  1.3.2.1  skrll 	       "option:\to subcommand [params]\n"
    416  1.3.2.1  skrll 	       "help:\th|?\n"
    417  1.3.2.1  skrll 	       "\n"
    418  1.3.2.1  skrll 	       "option subcommands are:\n"
    419  1.3.2.1  skrll 	       "print:\to p\n"
    420  1.3.2.1  skrll 	       "read:\to r\n"
    421  1.3.2.1  skrll 	       "write:\to w\n"
    422  1.3.2.1  skrll 	       "path:\to path pathname\n"
    423  1.3.2.1  skrll 	       "bootp:\to bootp yes|no\n"
    424  1.3.2.1  skrll 	       "ip:\to ip remote local netmask gateway\n"
    425  1.3.2.1  skrll 		);
    426      1.1    igy }
    427      1.1    igy 
    428      1.1    igy static void
    429      1.1    igy bad_param(void)
    430      1.1    igy {
    431      1.1    igy 	printf("bad param\n");
    432      1.1    igy 	command_help(NULL);
    433      1.1    igy }
    434      1.1    igy 
    435      1.1    igy static const u_int8_t print_cnv[] = {
    436      1.1    igy 	'0', '1', '2', '3', '4', '5', '6', '7',
    437      1.1    igy 	'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
    438      1.1    igy 
    439      1.1    igy static void
    440      1.1    igy printhexul(u_int32_t n)
    441      1.1    igy {
    442      1.1    igy 	int	i;
    443      1.1    igy 
    444      1.1    igy 	for (i = 28; i >= 0; i -= 4)
    445      1.1    igy 		putchar(print_cnv[(n >> i) & 0x0f]);
    446      1.1    igy }
    447      1.1    igy 
    448      1.1    igy static void
    449      1.1    igy printhexuc(u_int8_t n)
    450      1.1    igy {
    451      1.1    igy 	int	i;
    452      1.1    igy 
    453      1.1    igy 	for (i = 4; i >= 0; i -= 4)
    454      1.1    igy 		putchar(print_cnv[(n >> i) & 0x0f]);
    455      1.1    igy }
    456      1.1    igy 
    457      1.1    igy static void
    458      1.1    igy command_dump(char *opt)
    459      1.1    igy {
    460      1.1    igy 	char		*endptr;
    461      1.1    igy 	const char	*p;
    462      1.1    igy 	const char	*line_fence;
    463      1.1    igy 	const char	*limit;
    464      1.1    igy 
    465      1.1    igy 	p = (const char *) strtoul(opt, &endptr, 16);
    466      1.1    igy 	if (opt == endptr) {
    467      1.1    igy 		bad_param();
    468      1.1    igy 		return;
    469      1.1    igy 	}
    470      1.1    igy 
    471      1.1    igy 	opt = get_next_arg(opt);
    472      1.1    igy 	limit = (const char *) strtoul(opt, &endptr, 16);
    473      1.1    igy 	if (opt == endptr) {
    474      1.1    igy 		limit = p + 256;
    475      1.1    igy 	}
    476      1.1    igy 
    477      1.1    igy 	for (;;) {
    478      1.1    igy 		printhexul((u_int32_t) p);
    479      1.1    igy 		putchar(' ');
    480      1.1    igy 		line_fence = p + 16;
    481      1.1    igy 		while (p < line_fence) {
    482      1.1    igy 			printhexuc(*p++);
    483      1.1    igy 			putchar(' ');
    484      1.1    igy 			if (p >= limit) {
    485      1.1    igy 				putchar('\n');
    486      1.1    igy 				return;
    487      1.1    igy 			}
    488      1.1    igy 		}
    489      1.1    igy 		putchar('\n');
    490      1.1    igy 		if (ISKEY) {
    491      1.1    igy 			if (getchar() == '\x03')
    492      1.1    igy 				break;
    493      1.1    igy 		}
    494      1.1    igy 	}
    495      1.1    igy }
    496      1.1    igy 
    497      1.1    igy static void
    498      1.1    igy command_boot(char *opt)
    499      1.1    igy {
    500      1.1    igy 	u_long	marks[MARK_MAX];
    501      1.1    igy 
    502      1.1    igy 	marks[MARK_START] = 0;
    503  1.3.2.1  skrll 	if (loadfile(bootopts.b_pathname, marks, LOAD_KERNEL)) {
    504  1.3.2.1  skrll 		printf("loadfile failed\n");
    505  1.3.2.1  skrll 		return;
    506  1.3.2.1  skrll 	}
    507      1.1    igy 	start_netbsd();
    508      1.1    igy 	/* no return */
    509      1.1    igy }
    510      1.1    igy 
    511      1.1    igy /*
    512      1.1    igy  * loading S-Record
    513      1.1    igy  */
    514      1.1    igy static int
    515      1.1    igy load_srec(char *offset)
    516      1.1    igy {
    517      1.1    igy 	char		s2lbuf[9];
    518      1.1    igy 	char		c;
    519      1.1    igy 	char		rectype;
    520      1.1    igy 	u_int32_t	reclen;
    521      1.1    igy 	u_int32_t	reclen_bk;
    522      1.1    igy 	u_int32_t	recaddr;
    523      1.1    igy 	char		*endptr;
    524      1.1    igy 	char		*p;
    525      1.1    igy 	u_int32_t	sum;
    526      1.1    igy 	int		err = 0;
    527      1.1    igy 
    528      1.1    igy 	for (;;) {
    529      1.1    igy 		/*
    530      1.1    igy 		 * the first step is to read a S-Record.
    531      1.1    igy 		 */
    532      1.1    igy 		if ((c = getchar()) != 'S')
    533      1.1    igy 			goto out;
    534      1.1    igy 
    535      1.1    igy 		rectype = getchar();
    536      1.1    igy 
    537      1.1    igy 		s2lbuf[0] = getchar();
    538      1.1    igy 		s2lbuf[1] = getchar();
    539      1.1    igy 		s2lbuf[2] = '\0';
    540      1.1    igy 		reclen_bk = reclen = strtoul(s2lbuf, &endptr, 16);
    541      1.1    igy 		if (endptr != &s2lbuf[2])
    542      1.1    igy 			goto out;
    543      1.1    igy 		sum = reclen;
    544      1.1    igy 
    545      1.1    igy 		p = s2lbuf;
    546      1.1    igy 
    547      1.1    igy 		switch (rectype) {
    548      1.1    igy 		case '0':
    549      1.1    igy 			/* just ignore */
    550      1.1    igy 			do {
    551      1.1    igy 				c = getchar();
    552      1.1    igy 			} while (c != '\r' && c != '\n');
    553      1.1    igy 			continue;
    554      1.1    igy 
    555      1.1    igy 		case '3':
    556      1.1    igy 			*p++ = getchar();
    557      1.1    igy 			*p++ = getchar();
    558      1.1    igy 			reclen--;
    559      1.1    igy 			/* FALLTHRU */
    560      1.1    igy 		case '2':
    561      1.1    igy 			*p++ = getchar();
    562      1.1    igy 			*p++ = getchar();
    563      1.1    igy 			reclen--;
    564      1.1    igy 			/* FALLTHRU */
    565      1.1    igy 		case '1':
    566      1.1    igy 			*p++ = getchar();
    567      1.1    igy 			*p++ = getchar();
    568      1.1    igy 			*p++ = getchar();
    569      1.1    igy 			*p++ = getchar();
    570      1.1    igy 			*p = '\0';
    571      1.1    igy 			reclen -= 2;
    572      1.1    igy 
    573      1.1    igy 			recaddr = strtoul(s2lbuf, &endptr, 16);
    574      1.1    igy 			if (endptr != p)
    575      1.1    igy 				goto out;
    576      1.1    igy 			sum += (recaddr >> 24) & 0xff;
    577      1.1    igy 			sum += (recaddr >> 16) & 0xff;
    578      1.1    igy 			sum += (recaddr >> 8) & 0xff;
    579      1.1    igy 			sum += recaddr & 0xff;
    580      1.1    igy 
    581      1.1    igy 			p = offset + recaddr;
    582      1.1    igy 			/*
    583      1.1    igy 			 * XXX
    584      1.1    igy 			 * address range is must be chaked here!
    585      1.1    igy 			 */
    586      1.1    igy 			reclen--;
    587      1.1    igy 			s2lbuf[2] = '\0';
    588      1.1    igy 			while (reclen > 0) {
    589      1.1    igy 				s2lbuf[0] = getchar();
    590      1.1    igy 				s2lbuf[1] = getchar();
    591      1.1    igy 				*p = (u_int8_t) strtoul(s2lbuf, &endptr, 16);
    592      1.1    igy 				if (endptr != &s2lbuf[2])
    593      1.1    igy 					goto out;
    594      1.1    igy 				sum += *p++;
    595      1.1    igy 				reclen--;
    596      1.1    igy 			}
    597      1.1    igy 			break;
    598      1.1    igy 
    599      1.1    igy 		case '7':
    600      1.1    igy 		case '8':
    601      1.1    igy 		case '9':
    602      1.1    igy 			goto out2;
    603      1.1    igy 
    604      1.1    igy 		default:
    605      1.1    igy 			goto out;
    606      1.1    igy 		}
    607      1.1    igy 
    608      1.1    igy 		s2lbuf[0] = getchar();
    609      1.1    igy 		s2lbuf[1] = getchar();
    610      1.1    igy 		s2lbuf[2] = '\0';
    611      1.1    igy 		sum += (strtoul(s2lbuf, &endptr, 16) & 0xff);
    612      1.1    igy 		sum &= 0xff;
    613      1.1    igy 		if (sum != 0xff) {
    614      1.1    igy 			printf("checksum error\n");
    615      1.1    igy 			err = 1;
    616      1.1    igy 			goto out2;
    617      1.1    igy 		}
    618      1.1    igy 
    619      1.1    igy 		c = getchar();
    620      1.1    igy 		if (c != '\r' && c != '\n')
    621      1.1    igy 			goto out;
    622      1.1    igy 	}
    623      1.1    igy 	/* never reach */
    624      1.1    igy 	return 1;
    625      1.1    igy 
    626      1.1    igy out:
    627      1.1    igy 	printf("invalid S-Record\n");
    628      1.1    igy 	err = 1;
    629      1.1    igy 
    630      1.1    igy out2:
    631      1.1    igy 	do {
    632      1.1    igy 		c = getchar();
    633      1.1    igy 	} while (c != '\r' && c != '\n');
    634      1.1    igy 
    635      1.1    igy 	return err;
    636      1.1    igy }
    637      1.1    igy 
    638      1.1    igy static void
    639      1.1    igy command_load(char *opt)
    640      1.1    igy {
    641      1.1    igy 	char	*endptr;
    642      1.1    igy 	char	*offset;
    643      1.1    igy 
    644      1.1    igy 	offset = (char *) strtoul(opt, &endptr, 16);
    645      1.1    igy 	if (opt == endptr)
    646      1.1    igy 		offset = 0;
    647      1.1    igy 	load_srec(offset);
    648      1.1    igy }
    649      1.1    igy 
    650      1.1    igy static void
    651      1.1    igy command_fill(char *opt)
    652      1.1    igy {
    653      1.1    igy 	char	*endptr;
    654      1.1    igy 	char	*p;
    655      1.1    igy 	char	*limit;
    656      1.1    igy 	int	c;
    657      1.1    igy 
    658      1.1    igy 	p = (char *) strtoul(opt, &endptr, 16);
    659      1.1    igy 	if (opt == endptr) {
    660      1.1    igy 		bad_param();
    661      1.1    igy 		return;
    662      1.1    igy 	}
    663      1.1    igy 
    664      1.1    igy 	opt = get_next_arg(opt);
    665      1.1    igy 	limit = (char *) strtoul(opt, &endptr, 16);
    666      1.1    igy 	if (opt == endptr) {
    667      1.1    igy 		bad_param();
    668      1.1    igy 		return;
    669      1.1    igy 	}
    670      1.1    igy 
    671      1.1    igy 	opt = get_next_arg(opt);
    672      1.1    igy 	c = strtoul(opt, &endptr, 16);
    673      1.1    igy 	if (opt == endptr)
    674      1.1    igy 		c = '\0';
    675      1.1    igy 
    676      1.1    igy 	memset(p, c, limit - p);
    677      1.1    igy }
    678      1.1    igy 
    679      1.1    igy static void
    680  1.3.2.1  skrll check_write_verify_flash(u_int32_t src, u_int32_t dst, size_t len)
    681      1.1    igy {
    682      1.1    igy 	int		status;
    683      1.1    igy 
    684      1.1    igy 	if ((dst & I28F128_BLOCK_MASK) != 0) {
    685      1.1    igy 		printf("dst addr must be aligned to block boundary (0x%x)\n",
    686      1.1    igy 		       I28F128_BLOCK_SIZE);
    687      1.1    igy 		return;
    688      1.1    igy 	}
    689      1.1    igy 
    690      1.1    igy 	if (i28f128_probe((void *) dst)) {
    691      1.1    igy 		printf("dst addr is not a intel 28F128\n");
    692      1.1    igy 	} else {
    693      1.1    igy 		printf("intel 28F128 detected\n");
    694      1.1    igy 	}
    695      1.1    igy 
    696      1.1    igy 	if ((status = i28f128_region_write((void *) dst, (void *) src, len))
    697      1.1    igy 	    != 0) {
    698      1.1    igy 		printf("write mem to flash failed status = %x\n", status);
    699      1.1    igy 		return;
    700      1.1    igy 	}
    701      1.1    igy 
    702      1.2    igy 	printf("verifying...");
    703      1.2    igy 	if (memcmp((void *) dst, (void *) src, len)) {
    704      1.2    igy 		printf("verify error\n");
    705      1.2    igy 		return;
    706      1.2    igy 	}
    707      1.2    igy 	printf("ok\n");
    708      1.2    igy 
    709      1.2    igy 	printf("writing memory to flash succeeded\n");
    710  1.3.2.1  skrll }
    711  1.3.2.1  skrll 
    712  1.3.2.1  skrll static void
    713  1.3.2.1  skrll command_write(char *opt)
    714  1.3.2.1  skrll {
    715  1.3.2.1  skrll 	char		*endptr;
    716  1.3.2.1  skrll 	u_int32_t	src;
    717  1.3.2.1  skrll 	u_int32_t	dst;
    718  1.3.2.1  skrll 	size_t		len;
    719  1.3.2.1  skrll 
    720  1.3.2.1  skrll 	dst = strtoul(opt, &endptr, 16);
    721  1.3.2.1  skrll 	if (opt == endptr)
    722  1.3.2.1  skrll 		goto out;
    723  1.3.2.1  skrll 
    724  1.3.2.1  skrll 	opt = get_next_arg(opt);
    725  1.3.2.1  skrll 	src = strtoul(opt, &endptr, 16);
    726  1.3.2.1  skrll 	if (opt == endptr)
    727  1.3.2.1  skrll 		goto out;
    728  1.3.2.1  skrll 
    729  1.3.2.1  skrll 	opt = get_next_arg(opt);
    730  1.3.2.1  skrll 	len = strtoul(opt, &endptr, 16);
    731  1.3.2.1  skrll 	if (opt == endptr)
    732  1.3.2.1  skrll 		goto out;
    733  1.3.2.1  skrll 
    734  1.3.2.1  skrll 	check_write_verify_flash(src, dst, len);
    735      1.1    igy 	return;
    736      1.1    igy 
    737      1.1    igy out:
    738      1.1    igy 	bad_param();
    739      1.1    igy 	return;
    740      1.1    igy }
    741      1.1    igy 
    742      1.1    igy static void
    743  1.3.2.1  skrll command_option(char *subcmd)
    744  1.3.2.1  skrll {
    745  1.3.2.1  skrll 	char	*opt;
    746  1.3.2.1  skrll 	int	i;
    747  1.3.2.1  skrll 
    748  1.3.2.1  skrll 	opt = get_next_arg(subcmd);
    749  1.3.2.1  skrll 
    750  1.3.2.1  skrll 	/* dispatch subcommand */
    751  1.3.2.1  skrll 	for (i = 0; opt_subcommands[i].c_name != NULL; i++) {
    752  1.3.2.1  skrll 		if (strcmp(subcmd, opt_subcommands[i].c_name) == 0) {
    753  1.3.2.1  skrll 			opt_subcommands[i].c_fn(opt);
    754  1.3.2.1  skrll 			break;
    755  1.3.2.1  skrll 		}
    756  1.3.2.1  skrll 	}
    757  1.3.2.1  skrll 	if (opt_subcommands[i].c_name == NULL) {
    758  1.3.2.1  skrll 		printf("unknown option subcommand\n");
    759  1.3.2.1  skrll 		command_help(NULL);
    760  1.3.2.1  skrll 	}
    761  1.3.2.1  skrll }
    762  1.3.2.1  skrll 
    763  1.3.2.1  skrll static void
    764  1.3.2.1  skrll opt_subcmd_print(char *opt)
    765  1.3.2.1  skrll {
    766  1.3.2.1  skrll 	printf("boot options:\n"
    767  1.3.2.1  skrll 	       "magic:\t\t%s\n"
    768  1.3.2.1  skrll 	       "pathname:\t`%s'\n"
    769  1.3.2.1  skrll 	       "bootp:\t\t%s\n",
    770  1.3.2.1  skrll 	       bootopts.b_magic == BOOTOPT_MAGIC ? "ok" : "bad",
    771  1.3.2.1  skrll 	       bootopts.b_pathname,
    772  1.3.2.1  skrll 	       bootopts.b_flags & B_F_USE_BOOTP ? "yes" : "no");
    773  1.3.2.1  skrll 	printf("remote IP:\t%s\n", inet_ntoa(bootopts.b_remote_ip));
    774  1.3.2.1  skrll 	printf("local IP:\t%s\n", inet_ntoa(bootopts.b_local_ip));
    775  1.3.2.1  skrll 	printf("netmask:\t%s\n", intoa(bootopts.b_netmask));
    776  1.3.2.1  skrll 	printf("gateway IP:\t%s\n", inet_ntoa(bootopts.b_gate_ip));
    777  1.3.2.1  skrll }
    778  1.3.2.1  skrll 
    779  1.3.2.1  skrll static void
    780  1.3.2.1  skrll opt_subcmd_read(char *opt)
    781  1.3.2.1  skrll {
    782  1.3.2.1  skrll 	bootopts = *((struct boot_option *) BOOTOPTS_BASE);
    783  1.3.2.1  skrll 	if (bootopts.b_magic != BOOTOPT_MAGIC)
    784  1.3.2.1  skrll 		bootopts.b_pathname[0] = '\0';
    785  1.3.2.1  skrll }
    786  1.3.2.1  skrll 
    787  1.3.2.1  skrll static void
    788  1.3.2.1  skrll opt_subcmd_write(char *opt)
    789  1.3.2.1  skrll {
    790  1.3.2.1  skrll 	bootopts.b_magic = BOOTOPT_MAGIC;
    791  1.3.2.1  skrll 
    792  1.3.2.1  skrll 	check_write_verify_flash((u_int32_t) &bootopts, BOOTOPTS_BASE,
    793  1.3.2.1  skrll 				 sizeof bootopts);
    794  1.3.2.1  skrll }
    795  1.3.2.1  skrll 
    796  1.3.2.1  skrll static void
    797  1.3.2.1  skrll opt_subcmd_path(char *opt)
    798  1.3.2.1  skrll {
    799  1.3.2.1  skrll 	strlcpy(bootopts.b_pathname, opt, sizeof bootopts.b_pathname);
    800  1.3.2.1  skrll }
    801  1.3.2.1  skrll 
    802  1.3.2.1  skrll static void
    803  1.3.2.1  skrll opt_subcmd_bootp(char *opt)
    804  1.3.2.1  skrll {
    805  1.3.2.1  skrll 	if (strcmp(opt, "yes") == 0) {
    806  1.3.2.1  skrll 		bootopts.b_flags |= B_F_USE_BOOTP;
    807  1.3.2.1  skrll 	} else if (strcmp(opt, "no") == 0) {
    808  1.3.2.1  skrll 		bootopts.b_flags &= ~B_F_USE_BOOTP;
    809  1.3.2.1  skrll 	} else {
    810  1.3.2.1  skrll 		bad_param();
    811  1.3.2.1  skrll 	}
    812  1.3.2.1  skrll }
    813  1.3.2.1  skrll 
    814  1.3.2.1  skrll static void
    815  1.3.2.1  skrll opt_subcmd_ip(char *opt)
    816  1.3.2.1  skrll {
    817  1.3.2.1  skrll 	bootopts.b_remote_ip.s_addr = inet_addr(opt);
    818  1.3.2.1  skrll 	opt = get_next_arg(opt);
    819  1.3.2.1  skrll 	bootopts.b_local_ip.s_addr = inet_addr(opt);
    820  1.3.2.1  skrll 	opt = get_next_arg(opt);
    821  1.3.2.1  skrll 	bootopts.b_netmask = inet_addr(opt);
    822  1.3.2.1  skrll 	opt = get_next_arg(opt);
    823  1.3.2.1  skrll 	bootopts.b_gate_ip.s_addr = inet_addr(opt);
    824  1.3.2.1  skrll }
    825  1.3.2.1  skrll 
    826  1.3.2.1  skrll static void
    827      1.1    igy bootmenu(void)
    828      1.1    igy {
    829      1.1    igy 	char	input[LINEBUFLEN];
    830      1.1    igy 	char	*cmd;
    831      1.1    igy 	char	*opt;
    832      1.1    igy 	int	i;
    833      1.1    igy 
    834      1.1    igy 	for (;;) {
    835      1.1    igy 
    836      1.1    igy 		/* input a line */
    837      1.1    igy 		input[0] = '\0';
    838      1.1    igy 		printf("> ");
    839      1.1    igy 		gets(input);
    840      1.1    igy 		cmd = input;
    841      1.1    igy 
    842      1.1    igy 		/* skip leading whitespace. */
    843      1.1    igy 		while(*cmd == ' ')
    844      1.1    igy 			cmd++;
    845      1.1    igy 
    846      1.1    igy 		if(*cmd) {
    847      1.1    igy 			/* here, some command entered */
    848      1.1    igy 
    849      1.1    igy 			opt = get_next_arg(cmd);
    850      1.1    igy 
    851      1.1    igy 			/* dispatch command */
    852      1.1    igy 			for (i = 0; commands[i].c_name != NULL; i++) {
    853      1.1    igy 				if (strcmp(cmd, commands[i].c_name) == 0) {
    854      1.1    igy 					commands[i].c_fn(opt);
    855      1.1    igy 					break;
    856      1.1    igy 				}
    857      1.1    igy 			}
    858      1.1    igy 			if (commands[i].c_name == NULL) {
    859      1.1    igy 				printf("unknown command\n");
    860      1.1    igy 				command_help(NULL);
    861      1.1    igy 			}
    862      1.1    igy 		}
    863      1.1    igy 
    864      1.1    igy 	}
    865      1.1    igy }
    866      1.1    igy 
    867      1.1    igy static char
    868      1.1    igy awaitkey(void)
    869      1.1    igy {
    870      1.1    igy 	int	i;
    871      1.1    igy 	int	j;
    872      1.1    igy 	char	c = 0;
    873      1.1    igy 
    874      1.1    igy 	while (ISKEY)
    875      1.1    igy 		getchar();
    876      1.1    igy 
    877      1.1    igy 	for (i = BOOTTIMEOUT; i > 0; i--) {
    878      1.1    igy 		printf("%d\b", i);
    879      1.1    igy 		for (j = 0; j < 1000000; j++) {
    880      1.1    igy 			if (ISKEY) {
    881      1.1    igy 				while (ISKEY)
    882      1.1    igy 					c = getchar();
    883      1.1    igy 				goto out;
    884      1.1    igy 			}
    885      1.1    igy 		}
    886      1.1    igy 	}
    887      1.1    igy 
    888      1.1    igy out:
    889      1.1    igy 	printf("0\n");
    890      1.1    igy 	return(c);
    891      1.3    igy }
    892      1.3    igy 
    893      1.3    igy __dead void
    894      1.3    igy _rtt(void)
    895      1.3    igy {
    896      1.3    igy 	for (;;)
    897      1.3    igy 		;
    898      1.1    igy }
    899      1.1    igy 
    900      1.1    igy int
    901      1.1    igy main(void)
    902      1.1    igy {
    903      1.1    igy 	char	c;
    904      1.1    igy 
    905      1.1    igy 	init_devices();
    906      1.1    igy 
    907      1.1    igy 	comcninit();
    908      1.1    igy 
    909  1.3.2.1  skrll 	opt_subcmd_read(NULL);
    910  1.3.2.1  skrll 
    911      1.1    igy 	print_banner();
    912      1.1    igy 
    913      1.1    igy 	c = awaitkey();
    914      1.1    igy 	if (c != '\r' && c != '\n' && c != '\0') {
    915      1.1    igy 		printf("type \"?\" or \"h\" for help.\n");
    916      1.1    igy 		bootmenu(); /* does not return */
    917      1.1    igy 	}
    918      1.1    igy 
    919      1.1    igy 	command_boot(NULL);
    920  1.3.2.1  skrll 	/*
    921  1.3.2.1  skrll 	 * command_boot() returns only if it failed to boot.
    922  1.3.2.1  skrll 	 * we enter to boot menu in this case.
    923  1.3.2.1  skrll 	 */
    924  1.3.2.1  skrll 	bootmenu();
    925  1.3.2.1  skrll 
    926      1.1    igy 	return 0;
    927      1.1    igy }
    928