1 /* bootimage.c - Load an image and start it. Author: Kees J. Bot
4 #define BIOS 1 /* Can only be used under the BIOS. */
6 #define _POSIX_SOURCE 1
17 #include <minix/config.h>
18 #include <minix/const.h>
19 #include <minix/type.h>
20 #include <minix/syslib.h>
21 #include <minix/tty.h>
22 #include <sys/video.h>
23 #include <kernel/const.h>
24 #include <kernel/type.h>
25 #include <machine/partition.h>
30 static int block_size
= 0;
31 static int verboseboot
= VERBOSEBOOT_QUIET
;
33 #define DEBUGBASIC(params) do { \
34 if (verboseboot >= VERBOSEBOOT_BASIC) printf params; } while (0)
35 #define DEBUGMAX(params) do { \
36 if (verboseboot >= VERBOSEBOOT_MAX) printf params; } while (0)
38 extern int serial_line
;
39 extern u16_t vid_port
; /* Video i/o port. */
40 extern u32_t vid_mem_base
; /* Video memory base address. */
41 extern u32_t vid_mem_size
; /* Video memory size. */
43 #define click_shift clck_shft /* 7 char clash with click_size. */
45 /* Some kernels have extra features: */
46 #define K_I386 0x0001 /* Make the 386 transition before you call me. */
47 #define K_CLAIM 0x0002 /* I will acquire my own bss pages, thank you. */
48 #define K_CHMEM 0x0004 /* This kernel listens to chmem for its stack size. */
49 #define K_HIGH 0x0008 /* Load mm, fs, etc. in extended memory. */
50 #define K_HDR 0x0010 /* No need to patch sizes, kernel uses the headers. */
51 #define K_RET 0x0020 /* Returns to the monitor on reboot. */
52 #define K_INT86 0x0040 /* Requires generic INT support. */
53 #define K_MEML 0x0080 /* Pass a list of free memory. */
54 #define K_BRET 0x0100 /* New monitor code on shutdown in boot parameters. */
55 #define K_KHIGH 0x0200 /* Load kernel in extended memory. */
56 #define K_ALL 0x03FF /* All feature bits this monitor supports. */
59 /* Data about the different processes. */
61 #define PROCESS_MAX 16 /* Must match the space in kernel/mpx.x */
62 #define KERNEL_IDX 0 /* The first process is the kernel. */
63 #define FS 2 /* The third must be fs. */
65 struct process
{ /* Per-process memory adresses. */
66 u32_t entry
; /* Entry point. */
67 u32_t cs
; /* Code segment. */
68 u32_t ds
; /* Data segment. */
69 u32_t data
; /* To access the data segment. */
70 u32_t end
; /* End of this process, size = (end - cs). */
71 } process
[PROCESS_MAX
];
72 int n_procs
; /* Number of processes. */
74 /* Magic numbers in process' data space. */
75 #define MAGIC_OFF 0 /* Offset of magic # in data seg. */
76 #define CLICK_OFF 2 /* Offset in kernel text to click_shift. */
77 #define FLAGS_OFF 4 /* Offset in kernel text to flags. */
78 #define KERNEL_D_MAGIC 0x526F /* Kernel magic number. */
80 /* Offsets of sizes to be patched into kernel and fs. */
81 #define P_SIZ_OFF 0 /* Process' sizes into kernel data. */
82 #define P_INIT_OFF 4 /* Init cs & sizes into fs data. */
85 #define between(a, c, z) ((unsigned) ((c) - (a)) <= ((z) - (a)))
87 void pretty_image(const char *image
)
88 /* Pretty print the name of the image to load. Translate '/' and '_' to
89 * space, first letter goes uppercase. An 'r' before a digit prints as
90 * 'revision'. E.g. 'minix/1.6.16r10' -> 'Minix 1.6.16 revision 10'.
91 * The idea is that the part before the 'r' is the official Minix release
92 * and after the 'r' you can put version numbers for your own changes.
97 while ((c
= *image
++) != 0) {
98 if (c
== '/' || c
== '_') c
= ' ';
100 if (c
== 'r' && between('0', *image
, '9')) {
101 printf(" revision ");
104 if (!up
&& between('a', c
, 'z')) c
= c
- 'a' + 'A';
106 if (between('A', c
, 'Z')) up
= 1;
113 #define BUFSIZE_ZEROS 128
115 void raw_clear(u32_t addr
, u32_t count
)
116 /* Clear "count" bytes at absolute address "addr". */
118 static char zerosdata
[BUFSIZE_ZEROS
+ RAW_ALIGN
];
119 char *zeros
= zerosdata
+ RAW_ALIGN
- (unsigned) &zerosdata
% RAW_ALIGN
;
124 if (zct
> count
) zct
= count
;
125 raw_copy(addr
, mon2abs(zeros
), zct
);
130 if (zct
> count
) zct
= count
;
131 raw_copy(dst
, addr
, zct
);
137 /* Align a to a multiple of n (a power of 2): */
138 #define align(a, n) (((u32_t)(a) + ((u32_t)(n) - 1)) & ~((u32_t)(n) - 1))
139 unsigned click_shift
;
140 unsigned click_size
; /* click_size = Smallest kernel memory object. */
141 unsigned k_flags
; /* Not all kernels are created equal. */
142 u32_t reboot_code
; /* Obsolete reboot code return pointer. */
144 int params2params(char *params
, size_t psize
)
145 /* Repackage the environment settings for the kernel. */
153 for (e
= env
; e
!= nil
; e
= e
->next
) {
157 if (!(e
->flags
& E_VAR
)) continue;
159 if (e
->flags
& E_DEV
) {
160 if ((dev
= name2dev(value
)) == -1) return 0;
161 value
= ul2a10((u16_t
) dev
);
164 n
= i
+ strlen(name
) + 1 + strlen(value
) + 1;
166 strcpy(params
+ i
, name
);
167 strcat(params
+ i
, "=");
168 strcat(params
+ i
, value
);
173 if (!(k_flags
& K_MEML
)) {
174 /* Require old memory size variables. */
176 value
= ul2a10((mem
[0].base
+ mem
[0].size
) / 1024);
177 n
= i
+ 7 + 1 + strlen(value
) + 1;
179 strcpy(params
+ i
, "memsize=");
180 strcat(params
+ i
, value
);
183 value
= ul2a10(mem
[1].size
/ 1024);
184 n
= i
+ 7 + 1 + strlen(value
) + 1;
186 strcpy(params
+ i
, "emssize=");
187 strcat(params
+ i
, value
);
193 printf("Too many boot parameters\n");
196 params
[i
]= 0; /* End marked with empty string. */
200 void patch_sizes(void)
201 /* Patch sizes of each process into kernel data space, kernel ds into kernel
202 * text space, and sizes of init into data space of fs. All the patched
203 * numbers are based on the kernel click size, not hardware segments.
206 u16_t text_size
, data_size
;
208 struct process
*procp
, *initp
;
211 if (k_flags
& K_HDR
) return; /* Uses the headers. */
213 /* Patch text and data sizes of the processes into kernel data space.
215 doff
= process
[KERNEL_IDX
].data
+ P_SIZ_OFF
;
217 for (i
= 0; i
< n_procs
; i
++) {
219 text_size
= (procp
->ds
- procp
->cs
) >> click_shift
;
220 data_size
= (procp
->end
- procp
->ds
) >> click_shift
;
222 /* Two words per process, the text and data size: */
223 put_word(doff
, text_size
); doff
+= 2;
224 put_word(doff
, data_size
); doff
+= 2;
226 initp
= procp
; /* The last process must be init. */
229 if (k_flags
& (K_HIGH
|K_MEML
)) return; /* Doesn't need FS patching. */
231 /* Patch cs and sizes of init into fs data. */
232 put_word(process
[FS
].data
+ P_INIT_OFF
+0, initp
->cs
>> click_shift
);
233 put_word(process
[FS
].data
+ P_INIT_OFF
+2, text_size
);
234 put_word(process
[FS
].data
+ P_INIT_OFF
+4, data_size
);
237 int selected(const char *name
)
238 /* True iff name has no label or the proper label. */
243 if ((colon
= strchr(name
, ':')) == nil
) return 1;
244 if ((label
= b_value("label")) == nil
) return 1;
247 cmp
= strcmp(label
, name
);
252 static u32_t
proc_size(const struct image_header
*hdr
)
253 /* Return the size of a process in sectors as found in an image. */
255 u32_t len
= hdr
->process
.a_text
;
257 if (hdr
->process
.a_flags
& A_PAL
) len
+= hdr
->process
.a_hdrlen
;
258 if (hdr
->process
.a_flags
& A_SEP
) len
= align(len
, SECTOR_SIZE
);
259 len
= align(len
+ hdr
->process
.a_data
, SECTOR_SIZE
);
261 return len
>> SECTOR_SHIFT
;
264 off_t image_off
, image_size
;
265 u32_t (*vir2sec
)(u32_t vsec
); /* Where is a sector on disk? */
267 u32_t
file_vir2sec(u32_t vsec
)
268 /* Translate a virtual sector number to an absolute disk sector. */
272 if(!block_size
) { errno
= 0; return -1; }
274 if ((blk
= r_vir2abs(vsec
/ RATIO(block_size
))) == -1) {
278 return blk
== 0 ? 0 : lowsec
+ blk
* RATIO(block_size
) + vsec
% RATIO(block_size
);
281 u32_t
flat_vir2sec(u32_t vsec
)
282 /* Simply add an absolute sector offset to vsec. */
284 return lowsec
+ image_off
+ vsec
;
287 char *get_sector(u32_t vsec
)
288 /* Read a sector "vsec" from the image into memory and return its address.
289 * Return nil on error. (This routine tries to read an entire track, so
290 * the next request is usually satisfied from the track buffer.)
296 static char bufdata
[SECBUFS
* SECTOR_SIZE
+ RAW_ALIGN
];
297 static size_t count
; /* Number of sectors in the buffer. */
298 static u32_t bufsec
; /* First Sector now in the buffer. */
299 char *buf
= bufdata
+ RAW_ALIGN
- (unsigned) &bufdata
% RAW_ALIGN
;
301 if (vsec
== 0) count
= 0; /* First sector; initialize. */
303 if ((sec
= (*vir2sec
)(vsec
)) == -1) return nil
;
308 memset(buf
, 0, SECTOR_SIZE
);
312 /* Can we return a sector from the buffer? */
313 if ((sec
- bufsec
) < count
) {
314 return buf
+ ((size_t) (sec
- bufsec
) << SECTOR_SHIFT
);
317 /* Not in the buffer. */
321 /* Read a whole track if possible. */
322 while (++count
< SECBUFS
&& !dev_boundary(bufsec
+ count
)) {
324 if ((sec
= (*vir2sec
)(vsec
)) == -1) break;
327 if (sec
!= bufsec
+ count
) break;
330 /* Actually read the sectors. */
331 if ((r
= readsectors(mon2abs(buf
), bufsec
, count
)) != 0) {
340 int get_clickshift(u32_t ksec
, struct image_header
*hdr
)
341 /* Get the click shift and special flags from kernel text. */
345 if ((textp
= get_sector(ksec
)) == nil
) return 0;
347 if (hdr
->process
.a_flags
& A_PAL
) textp
+= hdr
->process
.a_hdrlen
;
348 click_shift
= * (u16_t
*) (textp
+ CLICK_OFF
);
349 k_flags
= * (u16_t
*) (textp
+ FLAGS_OFF
);
351 if ((k_flags
& ~K_ALL
) != 0) {
352 printf("%s requires features this monitor doesn't offer\n",
357 if (click_shift
< HCLICK_SHIFT
|| click_shift
> 16) {
358 printf("%s click size is bad\n", hdr
->name
);
363 click_size
= 1 << click_shift
;
368 int get_segment(u32_t
*vsec
, long *size
, u32_t
*addr
, u32_t limit
)
369 /* Read *size bytes starting at virtual sector *vsec to memory at *addr. */
377 if ((buf
= get_sector((*vsec
)++)) == nil
) return 0;
380 if (*addr
+ click_size
> limit
)
382 DEBUGMAX(("get_segment: out of memory; "
383 "addr=0x%lx; limit=0x%lx; size=%lx\n",
384 *addr
, limit
, size
));
390 DEBUGMAX(("raw_copy(0x%lx, 0x%lx/0x%x, 0x%lx)... ",
391 *addr
, mon2abs(buf
), buf
, n
));
392 raw_copy(*addr
, mon2abs(buf
), n
);
393 DEBUGMAX(("done\n"));
400 /* Zero extend to a click. */
401 n
= align(*addr
, click_size
) - *addr
;
402 DEBUGMAX(("raw_clear(0x%lx, 0x%lx)... ", *addr
, n
));
404 DEBUGMAX(("done\n"));
410 static void restore_screen(void)
412 struct boot_tty_info boot_tty_info
;
416 static u16_t consolescreen
[LINES
][CHARS
];
418 /* Try and find out what the main console was displaying
419 * by looking into video memory.
422 info_location
= vid_mem_base
+vid_mem_size
-sizeof(boot_tty_info
);
423 raw_copy(mon2abs(&boot_tty_info
), info_location
,
424 sizeof(boot_tty_info
));
426 if(boot_tty_info
.magic
== TTYMAGIC
) {
427 if((boot_tty_info
.flags
& (BTIF_CONSORIGIN
|BTIF_CONSCURSOR
)) ==
428 (BTIF_CONSORIGIN
|BTIF_CONSCURSOR
)) {
430 raw_copy(mon2abs(consolescreen
),
431 vid_mem_base
+ boot_tty_info
.consorigin
,
432 sizeof(consolescreen
));
434 for(line
= 0; line
< LINES
; line
++) {
436 for(ch
= 0; ch
< CHARS
; ch
++) {
437 u16_t newch
= consolescreen
[line
][ch
] & BYTE
;
438 if(newch
< ' ') newch
= ' ';
446 void exec_image(char *image
)
447 /* Get a Minix image into core, patch it up and execute. */
450 struct image_header hdr
;
452 u32_t vsec
, addr
, limit
, aout
, n
, totalmem
= 0;
453 struct process
*procp
; /* Process under construction. */
454 long a_text
, a_data
, a_bss
, a_stack
;
456 long processor
= a2l(b_value("processor"));
459 char params
[SECTOR_SIZE
];
460 extern char *sbrk(int);
463 /* The stack is pretty deep here, so check if heap and stack collide. */
466 if ((verb
= b_value(VERBOSEBOOTVARNAME
)) != nil
)
467 verboseboot
= a2l(verb
);
469 printf("\nLoading ");
473 vsec
= 0; /* Load this sector from image next. */
474 addr
= mem
[0].base
; /* Into this memory block. */
475 limit
= mem
[0].base
+ mem
[0].size
;
476 if (limit
> caddr
) limit
= caddr
;
478 /* Allocate and clear the area where the headers will be placed. */
479 aout
= (limit
-= PROCESS_MAX
* A_MINHDR
);
481 /* Clear the area where the headers will be placed. */
482 raw_clear(aout
, PROCESS_MAX
* A_MINHDR
);
484 /* Read the many different processes: */
485 for (i
= 0; vsec
< image_size
; i
++) {
488 if (i
== PROCESS_MAX
) {
489 printf("There are more then %d programs in %s\n",
497 DEBUGMAX(("Reading header... "));
499 if ((buf
= get_sector(vsec
++)) == nil
) return;
501 memcpy(&hdr
, buf
, sizeof(hdr
));
503 if (BADMAG(hdr
.process
)) { errno
= ENOEXEC
; return; }
505 /* Check the optional label on the process. */
506 if (selected(hdr
.name
)) break;
508 /* Bad label, skip this process. */
509 vsec
+= proc_size(&hdr
);
511 DEBUGMAX(("done\n"));
513 /* Sanity check: an 8086 can't run a 386 kernel. */
514 if (hdr
.process
.a_cpu
== A_I80386
&& processor
< 386) {
515 printf("You can't run a 386 kernel on this 80%ld\n",
521 /* Get the click shift from the kernel text segment. */
522 if (i
== KERNEL_IDX
) {
523 if (!get_clickshift(vsec
, &hdr
)) return;
524 addr
= align(addr
, click_size
);
526 /* big kernels must be loaded into extended memory */
527 if (k_flags
& K_KHIGH
) {
529 limit
= mem
[1].base
+ mem
[1].size
;
533 /* Save a copy of the header for the kernel, with a_syms
534 * misused as the address where the process is loaded at.
536 DEBUGMAX(("raw_copy(0x%x, 0x%lx, 0x%x)... ",
537 aout
+ i
* A_MINHDR
, mon2abs(&hdr
.process
), A_MINHDR
));
538 hdr
.process
.a_syms
= addr
;
539 raw_copy(aout
+ i
* A_MINHDR
, mon2abs(&hdr
.process
), A_MINHDR
);
540 DEBUGMAX(("done\n"));
543 DEBUGBASIC((" cs ds text data bss"));
544 if (k_flags
& K_CHMEM
) DEBUGBASIC((" stack"));
550 DEBUGMAX(("a_text=0x%lx; a_data=0x%lx; a_bss=0x%lx; a_flags=0x%x)\n",
551 hdr
.process
.a_text
, hdr
.process
.a_data
,
552 hdr
.process
.a_bss
, hdr
.process
.a_flags
));
554 a_text
= hdr
.process
.a_text
;
555 a_data
= hdr
.process
.a_data
;
556 a_bss
= hdr
.process
.a_bss
;
557 if (k_flags
& K_CHMEM
) {
558 a_stack
= hdr
.process
.a_total
- a_data
- a_bss
;
559 if (!(hdr
.process
.a_flags
& A_SEP
)) a_stack
-= a_text
;
564 /* Collect info about the process to be. */
567 /* Process may be page aligned so that the text segment contains
568 * the header, or have an unmapped zero page against vaxisms.
570 procp
->entry
= hdr
.process
.a_entry
;
571 if (hdr
.process
.a_flags
& A_PAL
) a_text
+= hdr
.process
.a_hdrlen
;
572 if (hdr
.process
.a_flags
& A_UZP
) procp
->cs
-= click_size
;
574 /* Separate I&D: two segments. Common I&D: only one. */
575 if (hdr
.process
.a_flags
& A_SEP
) {
576 /* Read the text segment. */
577 DEBUGMAX(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n",
578 vsec
, a_text
, addr
, limit
));
579 if (!get_segment(&vsec
, &a_text
, &addr
, limit
)) return;
580 DEBUGMAX(("get_segment done vsec=0x%lx a_text=0x%lx "
582 vsec
, a_text
, addr
));
584 /* The data segment follows. */
586 if (hdr
.process
.a_flags
& A_UZP
) procp
->ds
-= click_size
;
589 /* Add text to data to form one segment. */
590 procp
->data
= addr
+ a_text
;
591 procp
->ds
= procp
->cs
;
595 /* Read the data segment. */
596 DEBUGMAX(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n",
597 vsec
, a_data
, addr
, limit
));
598 if (!get_segment(&vsec
, &a_data
, &addr
, limit
)) return;
599 DEBUGMAX(("get_segment done vsec=0x%lx a_data=0x%lx "
601 vsec
, a_data
, addr
));
603 /* Make space for bss and stack unless... */
604 if (i
!= KERNEL_IDX
&& (k_flags
& K_CLAIM
)) a_bss
= a_stack
= 0;
606 DEBUGBASIC(("%07lx %07lx %8ld %8ld %8ld",
607 procp
->cs
, procp
->ds
, hdr
.process
.a_text
,
608 hdr
.process
.a_data
, hdr
.process
.a_bss
));
609 if (k_flags
& K_CHMEM
) DEBUGBASIC((" %8ld", a_stack
));
611 /* Note that a_data may be negative now, but we can look at it
612 * as -a_data bss bytes.
615 /* Compute the number of bss clicks left. */
617 n
= align(a_bss
, click_size
);
621 DEBUGMAX(("\nraw_clear(0x%lx, 0x%lx); limit=0x%lx... ", addr
, n
, limit
));
622 if (addr
+ n
> limit
) { errno
= ENOMEM
; return; }
624 DEBUGMAX(("done\n"));
627 /* And the number of stack clicks. */
629 n
= align(a_stack
, click_size
);
632 /* Add space for the stack. */
635 /* Process endpoint. */
638 if (verboseboot
>= VERBOSEBOOT_BASIC
)
639 printf(" %s\n", hdr
.name
);
642 mem
= addr
-startaddr
;
643 printf("%s ", hdr
.name
);
647 if (i
== 0 && (k_flags
& (K_HIGH
| K_KHIGH
)) == K_HIGH
) {
648 /* Load the rest in extended memory. */
650 limit
= mem
[1].base
+ mem
[1].size
;
654 if (verboseboot
< VERBOSEBOOT_BASIC
)
655 printf("(%dk)\n", totalmem
/1024);
657 if ((n_procs
= i
) == 0) {
658 printf("There are no programs in %s\n", image
);
663 /* Check the kernel magic number. */
664 raw_copy(mon2abs(&kmagic
),
665 process
[KERNEL_IDX
].data
+ MAGIC_OFF
, sizeof(kmagic
));
666 if (kmagic
!= KERNEL_D_MAGIC
) {
667 printf("Kernel magic number is incorrect (0x%x@0x%lx)\n",
668 kmagic
, process
[KERNEL_IDX
].data
+ MAGIC_OFF
);
673 /* Patch sizes, etc. into kernel data. */
674 DEBUGMAX(("patch_sizes()... "));
676 DEBUGMAX(("done\n"));
679 if (!(k_flags
& K_MEML
)) {
680 /* Copy the a.out headers to the old place. */
681 raw_copy(HEADERPOS
, aout
, PROCESS_MAX
* A_MINHDR
);
685 /* Run the trailer function just before starting Minix. */
686 DEBUGMAX(("run_trailer()... "));
687 if (!run_trailer()) { errno
= 0; return; }
688 DEBUGMAX(("done\n"));
690 /* Translate the boot parameters to what Minix likes best. */
691 DEBUGMAX(("params2params(0x%x, 0x%x)... ", params
, sizeof(params
)));
692 if (!params2params(params
, sizeof(params
))) { errno
= 0; return; }
693 DEBUGMAX(("done\n"));
695 /* Set the video to the required mode. */
696 if ((console
= b_value("console")) == nil
|| (mode
= a2x(console
)) == 0) {
697 mode
= strcmp(b_value("chrome"), "color") == 0 ? COLOR_MODE
:
700 DEBUGMAX(("set_mode(%d)... ", mode
));
702 DEBUGMAX(("done\n"));
704 /* Close the disk. */
705 DEBUGMAX(("dev_close()... "));
707 DEBUGMAX(("done\n"));
710 DEBUGMAX(("minix(0x%lx, 0x%lx, 0x%lx, 0x%x, 0x%x, 0x%lx)\n",
711 process
[KERNEL_IDX
].entry
, process
[KERNEL_IDX
].cs
,
712 process
[KERNEL_IDX
].ds
, params
, sizeof(params
), aout
));
713 minix(process
[KERNEL_IDX
].entry
, process
[KERNEL_IDX
].cs
,
714 process
[KERNEL_IDX
].ds
, params
, sizeof(params
), aout
);
716 if (!(k_flags
& K_BRET
)) {
717 extern u32_t reboot_code
;
718 raw_copy(mon2abs(params
), reboot_code
, sizeof(params
));
722 /* Return from Minix. Things may have changed, so assume nothing. */
726 /* Read leftover character, if any. */
729 /* Restore screen contents. */
735 ino_t
latest_version(char *version
, struct stat
*stp
)
736 /* Recursively read the current directory, selecting the newest image on
737 * the way up. (One can't use r_stat while reading a directory.)
740 char name
[NAME_MAX
+ 1];
744 if ((ino
= r_readdir(name
)) == 0) { stp
->st_mtime
= 0; return 0; }
746 newest
= latest_version(version
, stp
);
747 mtime
= stp
->st_mtime
;
750 if (S_ISREG(stp
->st_mode
) && stp
->st_mtime
> mtime
) {
752 strcpy(version
, name
);
754 stp
->st_mtime
= mtime
;
759 char *select_image(char *image
)
760 /* Look image up on the filesystem, if it is a file then we're done, but
761 * if its a directory then we want the newest file in that directory. If
762 * it doesn't exist at all, then see if it is 'number:number' and get the
763 * image from that absolute offset off the disk.
769 image
= strcpy(malloc((strlen(image
) + 1 + NAME_MAX
+ 1)
770 * sizeof(char)), image
);
772 fsok
= r_super(&block_size
) != 0;
773 if (!fsok
|| (image_ino
= r_lookup(ROOT_INO
, image
)) == 0) {
776 if (numprefix(image
, &size
) && *size
++ == ':'
778 vir2sec
= flat_vir2sec
;
779 image_off
= a2l(image
);
780 image_size
= a2l(size
);
781 strcpy(image
, "Minix");
785 printf("No image selected\n");
787 printf("Can't load %s: %s\n", image
, unix_err(errno
));
791 r_stat(image_ino
, &st
);
792 if (!S_ISREG(st
.st_mode
)) {
793 char *version
= image
+ strlen(image
);
794 char dots
[NAME_MAX
+ 1];
796 if (!S_ISDIR(st
.st_mode
)) {
797 printf("%s: %s\n", image
, unix_err(ENOTDIR
));
800 (void) r_readdir(dots
);
801 (void) r_readdir(dots
); /* "." & ".." */
804 if ((image_ino
= latest_version(version
, &st
)) == 0) {
805 printf("There are no images in %s\n", image
);
808 r_stat(image_ino
, &st
);
810 vir2sec
= file_vir2sec
;
811 image_size
= (st
.st_size
+ SECTOR_SIZE
- 1) >> SECTOR_SHIFT
;
819 /* Load Minix and run it. (Given the size of this program it is surprising
820 * that it ever gets to that.)
825 if ((image
= select_image(b_value("image"))) == nil
) return;
827 if(serial_line
>= 0) {
829 linename
[0] = serial_line
+ '0';
831 b_setvar(E_VAR
, SERVARNAME
, linename
);
838 printf("%s contains a bad program header\n", image
);
841 printf("Not enough memory to load %s\n", image
);
844 printf("Unsuspected EOF on %s\n", image
);
846 /* No error or error already reported. */;
855 * $PchId: bootimage.c,v 1.10 2002/02/27 19:39:09 philip Exp $