1 /* $NetBSD: boot.c,v 1.1 2002/11/09 06:20:39 cgd Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Ralph Campbell. 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)boot.c 8.1 (Berkeley) 6/10/93 39 */ 40 41 #include <lib/libsa/stand.h> 42 #include <lib/libkern/libkern.h> 43 #include <lib/libsa/loadfile.h> 44 45 #include <sys/param.h> 46 #include <sys/exec.h> 47 #include <sys/exec_ecoff.h> 48 49 #include "stand/common/common.h" 50 #include "stand/common/cfe_api.h" 51 52 #include <machine/autoconf.h> 53 54 #if !defined(UNIFIED_BOOTBLOCK) && !defined(SECONDARY_BOOTBLOCK) 55 #error not UNIFIED_BOOTBLOCK and not SECONDARY_BOOTBLOCK 56 #endif 57 58 char boot_file[128]; 59 char boot_flags[128]; 60 extern int debug; 61 62 struct bootinfo_v1 bootinfo; 63 64 paddr_t ffp_save, ptbr_save; 65 66 int debug; 67 68 char *kernelnames[] = { 69 "netbsd", "netbsd.gz", 70 "netbsd.bak", "netbsd.bak.gz", 71 "netbsd.old", "netbsd.old.gz", 72 "onetbsd", "onetbsd.gz", 73 "netbsd.mips", "netbsd.mips.gz", 74 NULL 75 }; 76 77 int 78 #if defined(UNIFIED_BOOTBLOCK) 79 main(long fwhandle,long evector,long fwentry,long fwseal) 80 #else /* defined(SECONDARY_BOOTBLOCK) */ 81 main(long fwhandle,long fd,long fwentry) 82 #endif 83 { 84 char *name, **namep; 85 u_long marks[MARK_MAX]; 86 u_int32_t entry; 87 int win; 88 89 /* Init prom callback vector. */ 90 cfe_init(fwhandle,fwentry); 91 92 /* Init the console device */ 93 init_console(); 94 95 /* print a banner */ 96 printf("\n"); 97 printf("NetBSD/sbmips " NETBSD_VERS " " BOOT_TYPE_NAME " Bootstrap, Revision %s\n", 98 bootprog_rev); 99 printf("(%s, %s)\n", bootprog_maker, bootprog_date); 100 printf("\n"); 101 102 /* set up the booted device descriptor */ 103 #if defined(UNIFIED_BOOTBLOCK) 104 if (!booted_dev_open()) { 105 printf("Boot device (%s) open failed.\n", 106 booted_dev_name[0] ? booted_dev_name : "unknown"); 107 goto fail; 108 } 109 #else /* defined(SECONDARY_BOOTBLOCK) */ 110 booted_dev_setfd(fd); 111 #endif 112 113 printf("\n"); 114 115 boot_file[0] = 0; 116 cfe_getenv("KERNEL_FILE",boot_file,sizeof(boot_file)); 117 118 boot_flags[0] = 0; 119 cfe_getenv("BOOT_FLAGS",boot_flags,sizeof(boot_flags)); 120 121 if (boot_file[0] != 0) 122 (void)printf("Boot file: %s\n", boot_file); 123 (void)printf("Boot flags: %s\n", boot_flags); 124 125 if (strchr(boot_flags, 'i') || strchr(boot_flags, 'I')) { 126 printf("Boot file: "); 127 gets(boot_file); 128 } 129 130 memset(marks, 0, sizeof marks); 131 if (boot_file[0] != '\0') 132 win = loadfile(name = boot_file, marks, LOAD_KERNEL) == 0; 133 else 134 for (namep = kernelnames, win = 0; *namep != NULL && !win; 135 namep++) 136 win = loadfile(name = *namep, marks, LOAD_KERNEL) == 0; 137 138 entry = marks[MARK_ENTRY]; 139 booted_dev_close(); 140 printf("\n"); 141 if (!win) 142 goto fail; 143 144 (void)printf("Entering %s at 0x%lx...\n", name, (long)entry); 145 146 cfe_flushcache(0); 147 148 bzero(&bootinfo,sizeof(bootinfo)); 149 bootinfo.version = BOOTINFO_VERSION; 150 bootinfo.reserved = 0; 151 bootinfo.ssym = marks[MARK_SYM]; 152 bootinfo.esym = marks[MARK_END]; 153 strncpy(bootinfo.boot_flags,boot_flags,sizeof(bootinfo.boot_flags)); 154 strncpy(bootinfo.booted_kernel,name,sizeof(bootinfo.booted_kernel)); 155 bootinfo.fwhandle = fwhandle; 156 bootinfo.fwentry = fwentry; 157 158 (*(void (*)(long,long,long,long))entry)(fwhandle, 159 BOOTINFO_MAGIC, 160 (long)&bootinfo, 161 fwentry); 162 163 (void)printf("KERNEL RETURNED!\n"); 164 165 fail: 166 (void)printf("Boot failed! Halting...\n"); 167 halt(); 168 return 1; 169 } 170 171 172 173