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 DEBUG_PRINT(params, level) do { \
34 if (verboseboot >= (level)) printf params; } while (0)
35 #define DEBUGBASIC(params) DEBUG_PRINT(params, VERBOSEBOOT_BASIC)
36 #define DEBUGEXTRA(params) DEBUG_PRINT(params, VERBOSEBOOT_EXTRA)
37 #define DEBUGMAX(params) DEBUG_PRINT(params, VERBOSEBOOT_MAX)
39 extern int serial_line
;
40 extern u16_t vid_port
; /* Video i/o port. */
41 extern u32_t vid_mem_base
; /* Video memory base address. */
42 extern u32_t vid_mem_size
; /* Video memory size. */
44 #define click_shift clck_shft /* 7 char clash with click_size. */
46 /* Some kernels have extra features: */
47 #define K_I386 0x0001 /* Make the 386 transition before you call me. */
48 #define K_CLAIM 0x0002 /* I will acquire my own bss pages, thank you. */
49 #define K_CHMEM 0x0004 /* This kernel listens to chmem for its stack size. */
50 #define K_HIGH 0x0008 /* Load mm, fs, etc. in extended memory. */
51 #define K_HDR 0x0010 /* No need to patch sizes, kernel uses the headers. */
52 #define K_RET 0x0020 /* Returns to the monitor on reboot. */
53 #define K_INT86 0x0040 /* Requires generic INT support. */
54 #define K_MEML 0x0080 /* Pass a list of free memory. */
55 #define K_BRET 0x0100 /* New monitor code on shutdown in boot parameters. */
56 #define K_KHIGH 0x0200 /* Load kernel in extended memory. */
57 #define K_ALL 0x03FF /* All feature bits this monitor supports. */
60 /* Data about the different processes. */
62 #define PROCESS_MAX 16 /* Must match the space in kernel/mpx.x */
63 #define KERNEL_IDX 0 /* The first process is the kernel. */
64 #define FS 2 /* The third must be fs. */
66 struct process
{ /* Per-process memory adresses. */
67 u32_t entry
; /* Entry point. */
68 u32_t cs
; /* Code segment. */
69 u32_t ds
; /* Data segment. */
70 u32_t data
; /* To access the data segment. */
71 u32_t end
; /* End of this process, size = (end - cs). */
72 } process
[PROCESS_MAX
];
73 int n_procs
; /* Number of processes. */
75 /* Magic numbers in process' data space. */
76 #define MAGIC_OFF 0 /* Offset of magic # in data seg. */
77 #define CLICK_OFF 2 /* Offset in kernel text to click_shift. */
78 #define FLAGS_OFF 4 /* Offset in kernel text to flags. */
79 #define KERNEL_D_MAGIC 0x526F /* Kernel magic number. */
81 /* Offsets of sizes to be patched into kernel and fs. */
82 #define P_SIZ_OFF 0 /* Process' sizes into kernel data. */
83 #define P_INIT_OFF 4 /* Init cs & sizes into fs data. */
86 #define between(a, c, z) ((unsigned) ((c) - (a)) <= ((z) - (a)))
88 void pretty_image(const char *image
)
89 /* Pretty print the name of the image to load. Translate '/' and '_' to
90 * space, first letter goes uppercase. An 'r' before a digit prints as
91 * 'revision'. E.g. 'minix/1.6.16r10' -> 'Minix 1.6.16 revision 10'.
92 * The idea is that the part before the 'r' is the official Minix release
93 * and after the 'r' you can put version numbers for your own changes.
98 while ((c
= *image
++) != 0) {
99 if (c
== '/' || c
== '_') c
= ' ';
101 if (c
== 'r' && between('0', *image
, '9')) {
102 printf(" revision ");
105 if (!up
&& between('a', c
, 'z')) c
= c
- 'a' + 'A';
107 if (between('A', c
, 'Z')) up
= 1;
114 #define BUFSIZE_ZEROS 128
116 void raw_clear(u32_t addr
, u32_t count
)
117 /* Clear "count" bytes at absolute address "addr". */
119 static char zerosdata
[BUFSIZE_ZEROS
+ RAW_ALIGN
];
120 char *zeros
= zerosdata
+ RAW_ALIGN
- (unsigned) &zerosdata
% RAW_ALIGN
;
125 if (zct
> count
) zct
= count
;
126 raw_copy(addr
, mon2abs(zeros
), zct
);
131 if (zct
> count
) zct
= count
;
132 raw_copy(dst
, addr
, zct
);
138 /* Align a to a multiple of n (a power of 2): */
139 #define align(a, n) (((u32_t)(a) + ((u32_t)(n) - 1)) & ~((u32_t)(n) - 1))
140 unsigned click_shift
;
141 unsigned click_size
; /* click_size = Smallest kernel memory object. */
142 unsigned k_flags
; /* Not all kernels are created equal. */
143 u32_t reboot_code
; /* Obsolete reboot code return pointer. */
145 int params2params(char *params
, size_t psize
)
146 /* Repackage the environment settings for the kernel. */
154 for (e
= env
; e
!= nil
; e
= e
->next
) {
158 if (!(e
->flags
& E_VAR
)) continue;
160 if (e
->flags
& E_DEV
) {
161 if ((dev
= name2dev(value
)) == -1) return 0;
162 value
= ul2a10((u16_t
) dev
);
165 n
= i
+ strlen(name
) + 1 + strlen(value
) + 1;
167 strcpy(params
+ i
, name
);
168 strcat(params
+ i
, "=");
169 strcat(params
+ i
, value
);
174 if (!(k_flags
& K_MEML
)) {
175 /* Require old memory size variables. */
177 value
= ul2a10((mem
[0].base
+ mem
[0].size
) / 1024);
178 n
= i
+ 7 + 1 + strlen(value
) + 1;
180 strcpy(params
+ i
, "memsize=");
181 strcat(params
+ i
, value
);
184 value
= ul2a10(mem
[1].size
/ 1024);
185 n
= i
+ 7 + 1 + strlen(value
) + 1;
187 strcpy(params
+ i
, "emssize=");
188 strcat(params
+ i
, value
);
194 printf("Too many boot parameters\n");
197 params
[i
]= 0; /* End marked with empty string. */
201 void patch_sizes(void)
202 /* Patch sizes of each process into kernel data space, kernel ds into kernel
203 * text space, and sizes of init into data space of fs. All the patched
204 * numbers are based on the kernel click size, not hardware segments.
207 u16_t text_size
, data_size
;
209 struct process
*procp
, *initp
;
212 if (k_flags
& K_HDR
) return; /* Uses the headers. */
214 /* Patch text and data sizes of the processes into kernel data space.
216 doff
= process
[KERNEL_IDX
].data
+ P_SIZ_OFF
;
218 for (i
= 0; i
< n_procs
; i
++) {
220 text_size
= (procp
->ds
- procp
->cs
) >> click_shift
;
221 data_size
= (procp
->end
- procp
->ds
) >> click_shift
;
223 /* Two words per process, the text and data size: */
224 put_word(doff
, text_size
); doff
+= 2;
225 put_word(doff
, data_size
); doff
+= 2;
227 initp
= procp
; /* The last process must be init. */
230 if (k_flags
& (K_HIGH
|K_MEML
)) return; /* Doesn't need FS patching. */
232 /* Patch cs and sizes of init into fs data. */
233 put_word(process
[FS
].data
+ P_INIT_OFF
+0, initp
->cs
>> click_shift
);
234 put_word(process
[FS
].data
+ P_INIT_OFF
+2, text_size
);
235 put_word(process
[FS
].data
+ P_INIT_OFF
+4, data_size
);
238 int selected(const char *name
)
239 /* True iff name has no label or the proper label. */
244 if ((colon
= strchr(name
, ':')) == nil
) return 1;
245 if ((label
= b_value("label")) == nil
) return 1;
248 cmp
= strcmp(label
, name
);
253 static u32_t
proc_size(const struct image_header
*hdr
)
254 /* Return the size of a process in sectors as found in an image. */
256 u32_t len
= hdr
->process
.a_text
;
258 if (hdr
->process
.a_flags
& A_PAL
) len
+= hdr
->process
.a_hdrlen
;
259 if (hdr
->process
.a_flags
& A_SEP
) len
= align(len
, SECTOR_SIZE
);
260 len
= align(len
+ hdr
->process
.a_data
, SECTOR_SIZE
);
262 return len
>> SECTOR_SHIFT
;
265 off_t image_off
, image_size
;
266 u32_t (*vir2sec
)(u32_t vsec
); /* Where is a sector on disk? */
268 u32_t
file_vir2sec(u32_t vsec
)
269 /* Translate a virtual sector number to an absolute disk sector. */
273 if(!block_size
) { errno
= 0; return -1; }
275 if ((blk
= r_vir2abs(vsec
/ RATIO(block_size
))) == -1) {
279 return blk
== 0 ? 0 : lowsec
+ blk
* RATIO(block_size
) + vsec
% RATIO(block_size
);
282 u32_t
flat_vir2sec(u32_t vsec
)
283 /* Simply add an absolute sector offset to vsec. */
285 return lowsec
+ image_off
+ vsec
;
288 char *get_sector(u32_t vsec
)
289 /* Read a sector "vsec" from the image into memory and return its address.
290 * Return nil on error. (This routine tries to read an entire track, so
291 * the next request is usually satisfied from the track buffer.)
297 static char bufdata
[SECBUFS
* SECTOR_SIZE
+ RAW_ALIGN
];
298 static size_t count
; /* Number of sectors in the buffer. */
299 static u32_t bufsec
; /* First Sector now in the buffer. */
300 char *buf
= bufdata
+ RAW_ALIGN
- (unsigned) &bufdata
% RAW_ALIGN
;
302 if (vsec
== 0) count
= 0; /* First sector; initialize. */
304 if ((sec
= (*vir2sec
)(vsec
)) == -1) return nil
;
309 memset(buf
, 0, SECTOR_SIZE
);
313 /* Can we return a sector from the buffer? */
314 if ((sec
- bufsec
) < count
) {
315 return buf
+ ((size_t) (sec
- bufsec
) << SECTOR_SHIFT
);
318 /* Not in the buffer. */
322 /* Read a whole track if possible. */
323 while (++count
< SECBUFS
&& !dev_boundary(bufsec
+ count
)) {
325 if ((sec
= (*vir2sec
)(vsec
)) == -1) break;
328 if (sec
!= bufsec
+ count
) break;
331 /* Actually read the sectors. */
332 if ((r
= readsectors(mon2abs(buf
), bufsec
, count
)) != 0) {
341 int get_clickshift(u32_t ksec
, struct image_header
*hdr
)
342 /* Get the click shift and special flags from kernel text. */
346 if ((textp
= get_sector(ksec
)) == nil
) return 0;
348 if (hdr
->process
.a_flags
& A_PAL
) textp
+= hdr
->process
.a_hdrlen
;
349 click_shift
= * (u16_t
*) (textp
+ CLICK_OFF
);
350 k_flags
= * (u16_t
*) (textp
+ FLAGS_OFF
);
352 if ((k_flags
& ~K_ALL
) != 0) {
353 printf("%s requires features this monitor doesn't offer\n",
358 if (click_shift
< HCLICK_SHIFT
|| click_shift
> 16) {
359 printf("%s click size is bad\n", hdr
->name
);
364 click_size
= 1 << click_shift
;
369 int get_segment(u32_t
*vsec
, long *size
, u32_t
*addr
, u32_t limit
)
370 /* Read *size bytes starting at virtual sector *vsec to memory at *addr. */
378 if ((buf
= get_sector((*vsec
)++)) == nil
) return 0;
381 if (*addr
+ click_size
> limit
)
383 DEBUGEXTRA(("get_segment: out of memory; "
384 "addr=0x%lx; limit=0x%lx; size=%lx\n",
385 *addr
, limit
, size
));
391 DEBUGMAX(("raw_copy(0x%lx, 0x%lx/0x%x, 0x%lx)... ",
392 *addr
, mon2abs(buf
), buf
, n
));
393 raw_copy(*addr
, mon2abs(buf
), n
);
394 DEBUGMAX(("done\n"));
401 /* Zero extend to a click. */
402 n
= align(*addr
, click_size
) - *addr
;
403 DEBUGMAX(("raw_clear(0x%lx, 0x%lx)... ", *addr
, n
));
405 DEBUGMAX(("done\n"));
411 static void restore_screen(void)
413 struct boot_tty_info boot_tty_info
;
417 static u16_t consolescreen
[LINES
][CHARS
];
419 /* Try and find out what the main console was displaying
420 * by looking into video memory.
423 info_location
= vid_mem_base
+vid_mem_size
-sizeof(boot_tty_info
);
424 raw_copy(mon2abs(&boot_tty_info
), info_location
,
425 sizeof(boot_tty_info
));
427 if(boot_tty_info
.magic
== TTYMAGIC
) {
428 if((boot_tty_info
.flags
& (BTIF_CONSORIGIN
|BTIF_CONSCURSOR
)) ==
429 (BTIF_CONSORIGIN
|BTIF_CONSCURSOR
)) {
431 raw_copy(mon2abs(consolescreen
),
432 vid_mem_base
+ boot_tty_info
.consorigin
,
433 sizeof(consolescreen
));
435 for(line
= 0; line
< LINES
; line
++) {
437 for(ch
= 0; ch
< CHARS
; ch
++) {
438 u16_t newch
= consolescreen
[line
][ch
] & BYTE
;
439 if(newch
< ' ') newch
= ' ';
447 void exec_image(char *image
)
448 /* Get a Minix image into core, patch it up and execute. */
451 struct image_header hdr
;
453 u32_t vsec
, addr
, limit
, aout
, n
, totalmem
= 0;
454 struct process
*procp
; /* Process under construction. */
455 long a_text
, a_data
, a_bss
, a_stack
;
457 long processor
= a2l(b_value("processor"));
460 char params
[SECTOR_SIZE
];
461 extern char *sbrk(int);
464 /* The stack is pretty deep here, so check if heap and stack collide. */
467 if ((verb
= b_value(VERBOSEBOOTVARNAME
)) != nil
)
468 verboseboot
= a2l(verb
);
470 printf("\nLoading ");
474 vsec
= 0; /* Load this sector from image next. */
475 addr
= mem
[0].base
; /* Into this memory block. */
476 limit
= mem
[0].base
+ mem
[0].size
;
477 if (limit
> caddr
) limit
= caddr
;
479 /* Allocate and clear the area where the headers will be placed. */
480 aout
= (limit
-= PROCESS_MAX
* A_MINHDR
);
482 /* Clear the area where the headers will be placed. */
483 raw_clear(aout
, PROCESS_MAX
* A_MINHDR
);
485 /* Read the many different processes: */
486 for (i
= 0; vsec
< image_size
; i
++) {
489 if (i
== PROCESS_MAX
) {
490 printf("There are more then %d programs in %s\n",
498 DEBUGEXTRA(("Reading header... "));
500 if ((buf
= get_sector(vsec
++)) == nil
) return;
502 memcpy(&hdr
, buf
, sizeof(hdr
));
504 if (BADMAG(hdr
.process
)) { errno
= ENOEXEC
; return; }
506 /* Check the optional label on the process. */
507 if (selected(hdr
.name
)) break;
509 /* Bad label, skip this process. */
510 vsec
+= proc_size(&hdr
);
512 DEBUGEXTRA(("done\n"));
514 /* Sanity check: an 8086 can't run a 386 kernel. */
515 if (hdr
.process
.a_cpu
== A_I80386
&& processor
< 386) {
516 printf("You can't run a 386 kernel on this 80%ld\n",
522 /* Get the click shift from the kernel text segment. */
523 if (i
== KERNEL_IDX
) {
524 if (!get_clickshift(vsec
, &hdr
)) return;
525 addr
= align(addr
, click_size
);
527 /* big kernels must be loaded into extended memory */
528 if (k_flags
& K_KHIGH
) {
530 limit
= mem
[1].base
+ mem
[1].size
;
534 /* Save a copy of the header for the kernel, with a_syms
535 * misused as the address where the process is loaded at.
537 DEBUGEXTRA(("raw_copy(0x%x, 0x%lx, 0x%x)... ",
538 aout
+ i
* A_MINHDR
, mon2abs(&hdr
.process
), A_MINHDR
));
539 hdr
.process
.a_syms
= addr
;
540 raw_copy(aout
+ i
* A_MINHDR
, mon2abs(&hdr
.process
), A_MINHDR
);
541 DEBUGEXTRA(("done\n"));
544 DEBUGBASIC((" cs ds text data bss"));
545 if (k_flags
& K_CHMEM
) DEBUGBASIC((" stack"));
551 DEBUGEXTRA(("a_text=0x%lx; a_data=0x%lx; a_bss=0x%lx; a_flags=0x%x)\n",
552 hdr
.process
.a_text
, hdr
.process
.a_data
,
553 hdr
.process
.a_bss
, hdr
.process
.a_flags
));
555 a_text
= hdr
.process
.a_text
;
556 a_data
= hdr
.process
.a_data
;
557 a_bss
= hdr
.process
.a_bss
;
558 if (k_flags
& K_CHMEM
) {
559 a_stack
= hdr
.process
.a_total
- a_data
- a_bss
;
560 if (!(hdr
.process
.a_flags
& A_SEP
)) a_stack
-= a_text
;
565 /* Collect info about the process to be. */
568 /* Process may be page aligned so that the text segment contains
569 * the header, or have an unmapped zero page against vaxisms.
571 procp
->entry
= hdr
.process
.a_entry
;
572 if (hdr
.process
.a_flags
& A_PAL
) a_text
+= hdr
.process
.a_hdrlen
;
573 if (hdr
.process
.a_flags
& A_UZP
) procp
->cs
-= click_size
;
575 /* Separate I&D: two segments. Common I&D: only one. */
576 if (hdr
.process
.a_flags
& A_SEP
) {
577 /* Read the text segment. */
578 DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n",
579 vsec
, a_text
, addr
, limit
));
580 if (!get_segment(&vsec
, &a_text
, &addr
, limit
)) return;
581 DEBUGEXTRA(("get_segment done vsec=0x%lx a_text=0x%lx "
583 vsec
, a_text
, addr
));
585 /* The data segment follows. */
587 if (hdr
.process
.a_flags
& A_UZP
) procp
->ds
-= click_size
;
590 /* Add text to data to form one segment. */
591 procp
->data
= addr
+ a_text
;
592 procp
->ds
= procp
->cs
;
596 /* Read the data segment. */
597 DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n",
598 vsec
, a_data
, addr
, limit
));
599 if (!get_segment(&vsec
, &a_data
, &addr
, limit
)) return;
600 DEBUGEXTRA(("get_segment done vsec=0x%lx a_data=0x%lx "
602 vsec
, a_data
, addr
));
604 /* Make space for bss and stack unless... */
605 if (i
!= KERNEL_IDX
&& (k_flags
& K_CLAIM
)) a_bss
= a_stack
= 0;
607 DEBUGBASIC(("%07lx %07lx %8ld %8ld %8ld",
608 procp
->cs
, procp
->ds
, hdr
.process
.a_text
,
609 hdr
.process
.a_data
, hdr
.process
.a_bss
));
610 if (k_flags
& K_CHMEM
) DEBUGBASIC((" %8ld", a_stack
));
612 /* Note that a_data may be negative now, but we can look at it
613 * as -a_data bss bytes.
616 /* Compute the number of bss clicks left. */
618 n
= align(a_bss
, click_size
);
622 DEBUGEXTRA(("\nraw_clear(0x%lx, 0x%lx); limit=0x%lx... ", addr
, n
, limit
));
623 if (addr
+ n
> limit
) { errno
= ENOMEM
; return; }
625 DEBUGEXTRA(("done\n"));
628 /* And the number of stack clicks. */
630 n
= align(a_stack
, click_size
);
633 /* Add space for the stack. */
636 /* Process endpoint. */
639 if (verboseboot
>= VERBOSEBOOT_BASIC
)
640 printf(" %s\n", hdr
.name
);
643 mem
= addr
-startaddr
;
644 printf("%s ", hdr
.name
);
648 if (i
== 0 && (k_flags
& (K_HIGH
| K_KHIGH
)) == K_HIGH
) {
649 /* Load the rest in extended memory. */
651 limit
= mem
[1].base
+ mem
[1].size
;
655 if (verboseboot
< VERBOSEBOOT_BASIC
)
656 printf("(%dk)\n", totalmem
/1024);
658 if ((n_procs
= i
) == 0) {
659 printf("There are no programs in %s\n", image
);
664 /* Check the kernel magic number. */
665 raw_copy(mon2abs(&kmagic
),
666 process
[KERNEL_IDX
].data
+ MAGIC_OFF
, sizeof(kmagic
));
667 if (kmagic
!= KERNEL_D_MAGIC
) {
668 printf("Kernel magic number is incorrect (0x%x@0x%lx)\n",
669 kmagic
, process
[KERNEL_IDX
].data
+ MAGIC_OFF
);
674 /* Patch sizes, etc. into kernel data. */
675 DEBUGEXTRA(("patch_sizes()... "));
677 DEBUGEXTRA(("done\n"));
680 if (!(k_flags
& K_MEML
)) {
681 /* Copy the a.out headers to the old place. */
682 raw_copy(HEADERPOS
, aout
, PROCESS_MAX
* A_MINHDR
);
686 /* Run the trailer function just before starting Minix. */
687 DEBUGEXTRA(("run_trailer()... "));
688 if (!run_trailer()) { errno
= 0; return; }
689 DEBUGEXTRA(("done\n"));
691 /* Translate the boot parameters to what Minix likes best. */
692 DEBUGEXTRA(("params2params(0x%x, 0x%x)... ", params
, sizeof(params
)));
693 if (!params2params(params
, sizeof(params
))) { errno
= 0; return; }
694 DEBUGEXTRA(("done\n"));
696 /* Set the video to the required mode. */
697 if ((console
= b_value("console")) == nil
|| (mode
= a2x(console
)) == 0) {
698 mode
= strcmp(b_value("chrome"), "color") == 0 ? COLOR_MODE
:
701 DEBUGEXTRA(("set_mode(%d)... ", mode
));
703 DEBUGEXTRA(("done\n"));
705 /* Close the disk. */
706 DEBUGEXTRA(("dev_close()... "));
708 DEBUGEXTRA(("done\n"));
711 DEBUGEXTRA(("minix(0x%lx, 0x%lx, 0x%lx, 0x%x, 0x%x, 0x%lx)\n",
712 process
[KERNEL_IDX
].entry
, process
[KERNEL_IDX
].cs
,
713 process
[KERNEL_IDX
].ds
, params
, sizeof(params
), aout
));
714 minix(process
[KERNEL_IDX
].entry
, process
[KERNEL_IDX
].cs
,
715 process
[KERNEL_IDX
].ds
, params
, sizeof(params
), aout
);
717 if (!(k_flags
& K_BRET
)) {
718 extern u32_t reboot_code
;
719 raw_copy(mon2abs(params
), reboot_code
, sizeof(params
));
723 /* Return from Minix. Things may have changed, so assume nothing. */
727 /* Read leftover character, if any. */
730 /* Restore screen contents. */
736 ino_t
latest_version(char *version
, struct stat
*stp
)
737 /* Recursively read the current directory, selecting the newest image on
738 * the way up. (One can't use r_stat while reading a directory.)
741 char name
[NAME_MAX
+ 1];
745 if ((ino
= r_readdir(name
)) == 0) { stp
->st_mtime
= 0; return 0; }
747 newest
= latest_version(version
, stp
);
748 mtime
= stp
->st_mtime
;
751 if (S_ISREG(stp
->st_mode
) && stp
->st_mtime
> mtime
) {
753 strcpy(version
, name
);
755 stp
->st_mtime
= mtime
;
760 char *select_image(char *image
)
761 /* Look image up on the filesystem, if it is a file then we're done, but
762 * if its a directory then we want the newest file in that directory. If
763 * it doesn't exist at all, then see if it is 'number:number' and get the
764 * image from that absolute offset off the disk.
770 image
= strcpy(malloc((strlen(image
) + 1 + NAME_MAX
+ 1)
771 * sizeof(char)), image
);
773 fsok
= r_super(&block_size
) != 0;
774 if (!fsok
|| (image_ino
= r_lookup(ROOT_INO
, image
)) == 0) {
777 if (numprefix(image
, &size
) && *size
++ == ':'
779 vir2sec
= flat_vir2sec
;
780 image_off
= a2l(image
);
781 image_size
= a2l(size
);
782 strcpy(image
, "Minix");
786 printf("No image selected\n");
788 printf("Can't load %s: %s\n", image
, unix_err(errno
));
792 r_stat(image_ino
, &st
);
793 if (!S_ISREG(st
.st_mode
)) {
794 char *version
= image
+ strlen(image
);
795 char dots
[NAME_MAX
+ 1];
797 if (!S_ISDIR(st
.st_mode
)) {
798 printf("%s: %s\n", image
, unix_err(ENOTDIR
));
801 (void) r_readdir(dots
);
802 (void) r_readdir(dots
); /* "." & ".." */
805 if ((image_ino
= latest_version(version
, &st
)) == 0) {
806 printf("There are no images in %s\n", image
);
809 r_stat(image_ino
, &st
);
811 vir2sec
= file_vir2sec
;
812 image_size
= (st
.st_size
+ SECTOR_SIZE
- 1) >> SECTOR_SHIFT
;
820 /* Load Minix and run it. (Given the size of this program it is surprising
821 * that it ever gets to that.)
826 if ((image
= select_image(b_value("image"))) == nil
) return;
828 if(serial_line
>= 0) {
830 linename
[0] = serial_line
+ '0';
832 b_setvar(E_VAR
, SERVARNAME
, linename
);
839 printf("%s contains a bad program header\n", image
);
842 printf("Not enough memory to load %s\n", image
);
845 printf("Unsuspected EOF on %s\n", image
);
847 /* No error or error already reported. */;
856 * $PchId: bootimage.c,v 1.10 2002/02/27 19:39:09 philip Exp $