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