2 * Copyright (c) 2013-2014 Robert N. M. Watson
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/linker.h>
36 #include <sys/reboot.h>
38 #include <machine/bootinfo.h>
39 #include <machine/elf.h>
42 #include <bootstrap.h>
46 #ifdef LOADER_USB_SUPPORT
47 #include <storage/umass_common.h>
50 static int __elfN(exec)(struct preloaded_file *);
51 static void extract_currdev(struct bootinfo *);
53 struct devsw *devsw[] = {
56 #ifdef LOADER_USB_SUPPORT
62 struct arch_switch archsw;
64 struct file_format *file_formats[] = {
69 struct fs_ops *file_system[] = {
70 #ifdef LOADER_UFS_SUPPORT
76 struct console *consoles[] = {
77 &altera_jtag_uart_console,
81 extern void __bss_start, __bss_end;
82 extern void __heap_start, __heap_end;
85 __elfN(exec)(struct preloaded_file *fp)
92 * Capture arguments from boot2 for later reuse when launching the kernel.
93 * Note that we choose not to maintain a pointer to boo2_bootinfop after
94 * initial argument processing: this is because we might load the kernel over
95 * the spot where boot2 was running, so we can't pass that pointer on to the
96 * kernel. To be on the safe side, never reference it outside of the body of
97 * main(), instead preserving a copy.
103 struct bootinfo boot2_bootinfo;
106 main(int argc, char *argv[], char *envv[], struct bootinfo *bootinfop)
110 /* NB: Must be sure to bzero() before using any globals. */
111 bzero(&__bss_start, (uintptr_t)&__bss_end - (uintptr_t)&__bss_start);
116 boot2_bootinfo = *bootinfop; /* Copy rather than by reference. */
118 setheap((void *)&__heap_start, (void *)&__heap_end);
121 * Pick up console settings from boot2; probe console.
123 if (bootinfop->bi_boot2opts & RB_MULTIPLE) {
124 if (bootinfop->bi_boot2opts & RB_SERIAL)
125 setenv("console", "comconsole vidconsole", 1);
127 setenv("console", "vidconsole comconsole", 1);
128 } else if (bootinfop->bi_boot2opts & RB_SERIAL)
129 setenv("console", "comconsole", 1);
130 else if (bootinfop->bi_boot2opts & RB_MUTE)
131 setenv("console", "nullconsole", 1);
133 setenv("LINES", "24", 1);
135 printf("%s(%d, %p, %p, %p (%p))\n", __func__, argc, argv, envv,
136 bootinfop, (void *)bootinfop->bi_memsize);
139 * Initialise devices.
141 for (dp = devsw; *dp != NULL; dp++) {
142 if ((*dp)->dv_init != NULL)
145 extract_currdev(bootinfop);
147 printf("\n%s", bootprog_info);
149 printf("bootpath=\"%s\"\n", bootpath);
157 extract_currdev(struct bootinfo *bootinfop)
162 * Pick up boot device information from boot2.
164 * XXXRW: Someday: device units.
166 switch(bootinfop->bi_boot_dev_type) {
167 case BOOTINFO_DEV_TYPE_DRAM:
171 case BOOTINFO_DEV_TYPE_CFI:
175 case BOOTINFO_DEV_TYPE_SDCARD:
183 if (bootdev != NULL) {
184 env_setenv("currdev", EV_VOLATILE, bootdev, NULL, env_nounset);
185 env_setenv("loaddev", EV_VOLATILE, bootdev, env_noset,
194 printf("error: loader abort\n");
202 printf("error: loader exit\n");
210 printf("error: loader longjmp error\n");
218 /* We can't provide time since UTC, so just provide time since boot. */
219 return (cp0_count_get() / 100000000);
225 * NOTE: We are assuming that the CPU is running at 100MHz.
234 last = cp0_count_get();
236 curr = cp0_count_get();
238 while (usecs > 0 && delta >= 100) {