This source file includes following definitions.
- boot
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 #include <sys/param.h>
32 #include <sys/reboot.h>
33 #include <sys/stat.h>
34 #include <libsa.h>
35 #include <lib/libsa/loadfile.h>
36 #include <lib/libkern/funcs.h>
37
38 #include "cmd.h"
39
40 #ifndef KERNEL
41 #define KERNEL "/bsd"
42 #endif
43
44 char prog_ident[40];
45 char *progname = "BOOT";
46
47 extern const char version[];
48 struct cmd_state cmd;
49
50
51 int bootprompt = 1;
52 char *kernelfile = KERNEL;
53
54 void
55 boot(dev_t bootdev)
56 {
57 int fd;
58 int try = 0, st;
59 u_long marks[MARK_MAX];
60
61 machdep();
62
63 snprintf(prog_ident, sizeof(prog_ident),
64 ">> OpenBSD/" MACHINE " %s %s", progname, version);
65 printf("%s\n", prog_ident);
66
67 devboot(bootdev, cmd.bootdev);
68 strlcpy(cmd.image, kernelfile, sizeof(cmd.image));
69 cmd.boothowto = 0;
70 cmd.conf = "/etc/boot.conf";
71 cmd.addr = (void *)DEFAULT_KERNEL_ADDRESS;
72 cmd.timeout = 5;
73
74 st = read_conf();
75 if (!bootprompt)
76 snprintf(cmd.path, sizeof cmd.path, "%s:%s",
77 cmd.bootdev, cmd.image);
78
79 while (1) {
80
81 if (bootprompt && st <= 0)
82 do {
83 printf("boot> ");
84 } while(!getcmd());
85 st = 0;
86 bootprompt = 1;
87
88 printf("booting %s: ", cmd.path);
89 marks[MARK_START] = (u_long)cmd.addr;
90 if ((fd = loadfile(cmd.path, marks, LOAD_ALL)) != -1) {
91 close(fd);
92 break;
93 }
94
95 kernelfile = KERNEL;
96 try++;
97 strlcpy(cmd.image, kernelfile, sizeof(cmd.image));
98 printf(" failed(%d). will try %s\n", errno, kernelfile);
99
100 if (try < 2) {
101 if (cmd.timeout > 0)
102 cmd.timeout++;
103 } else {
104 if (cmd.timeout)
105 printf("Turning timeout off.\n");
106 cmd.timeout = 0;
107 }
108 }
109
110
111 run_loadfile(marks, cmd.boothowto);
112 }
113
114 #ifdef _TEST
115 int
116 main()
117 {
118 boot(0);
119 return 0;
120 }
121 #endif