1
/* Second stage boot loader
3
Coyright (C) 1996 Pete A. Zaitcev
7
1996,1997,1998,1999 Jakub Jelinek
10
This program is free software; you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation; either version 2 of the License, or
13
(at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25
/* TODO: This file is a good candidate for rewrite from scratch. */
29
#include <linux/elf.h>
30
#include <stringops.h>
33
#define NULL (void *)0
39
unsigned int linux_ver;
41
unsigned short root_flags;
42
unsigned short root_dev;
43
unsigned short ram_flags;
44
unsigned int ramdisk_image;
45
unsigned int ramdisk_size;
47
unsigned int reboot_cmd_ptr_high;
48
unsigned int reboot_cmd_ptr_low;
50
unsigned int bootstr_info_ptr_high;
51
unsigned int bootstr_info_ptr_low;
53
unsigned long long ramdisk_image64;
56
/* This has to be first initialized variable in main.c */
58
extern char silo_conf[256];
59
extern unsigned char silo_conf_part, silo_conf_parts[32], raid_dsk_number;
67
enum arch architecture;
68
static int timer_status = 0;
69
static char *initrd_start;
70
static int initrd_size;
71
static int initrd_defpart;
72
static char *initrd_defdevice;
73
static char *initrd_string;
74
static int initrd_prompt;
75
static int pause_after;
76
static char *pause_message = "Press ENTER to continue.";
77
static int show_arguments = 0;
78
static char given_bootargs [512];
79
static char my_bootargs [512];
80
static int given_bootargs_by_user = 0;
81
static char sol_params [512];
82
static int fill_reboot_cmd = 0;
83
static char other_device [512];
84
static int reboot = 0;
85
static int floppyswap = 0;
86
int tab_ambiguous = 0;
91
int initrd_can_do_64bit_phys = 0;
93
static void parse_name (char *, int, char **, int *, char **);
95
static char *next_tok (char *t) {
96
while (*t++); /* That was easy */
100
/* Check for possible file and target completions. Return non-zero if
101
* the caller needs to re-output the command line. */
102
static int tab_complete(void) {
103
int image_len, defpart, part, ret = 0;
105
char *p = cfg_get_strg (0, "partition");
108
if ((r = strrchr(cbuff, ' ')) == NULL)
113
if (p && *p >= '1' && *p <= '8' && !p[1])
116
silo_fatal("\nDefault partition could not be found");
121
parse_name (r, defpart, &device, &part, &kname);
123
/* Maybe this isn't a disk file. Maybe it's a silo.conf defined
126
ret = cfg_print_images (NULL, r);
128
char *addr = (char *)0x4000;
129
int count = cfg_print_images (addr, r);
132
int len2 = strlen(cbuff);
133
/* We have some completions... */
135
/* Just one, complete it... */
137
cbuff[len2] = addr[len];
139
prom_puts(cbuff + len2, 1);
144
prom_puts(cbuff + len2, 1);
145
} else if (count > 1) { /* This should always be true, if we get here */
146
/* Complete the line as much as possible */
147
int common = 1, orig = len, i;
148
while (common && addr[len]) {
149
char *cur = next_tok(addr);
150
for (i = 1; i < count && common; i++, cur = next_tok(cur))
151
if (addr[len] != cur[len])
155
cbuff[len2] = addr[len];
157
prom_puts(cbuff + len2, 1);
168
if (!device) device = cfg_get_strg (0, "device");
170
if (silo_load_file(device, part, kname, (unsigned char *) 0x4000,
171
(unsigned char *) &_start, &image_len,
172
LOADFILE_LS_MATCH|LOADFILE_QUIET, 0))
173
if (do_ls((unsigned char *)0x4000, &tab_ambiguous))
181
static void maintabfunc (void)
184
/* Nothing on the command line, just list the possible images from
185
* the config file. */
186
if (cfg_print_images (NULL, NULL))
187
printf ("boot: %s", cbuff);
189
/* If tab_complete() returns non-zero, then it just listed
190
* possible completions, and we need to redo our command line. */
192
printf ("boot: %s", cbuff);
197
static void parse_name (char *imagename, int defpart, char **device,
198
int *part, char **kname)
200
static char parsebuf[1024];
202
strcpy (parsebuf, imagename);
203
imagename = parsebuf;
206
if (prom_vers == PROM_V0) {
207
static char v0_buffer[20];
208
*kname = silo_v0_device(imagename);
210
memcpy (v0_buffer, imagename, *kname - imagename + 1);
211
v0_buffer [*kname - imagename + 1] = 0;
217
*kname = strchr (imagename, ';');
227
if (**kname >= '0' && **kname <= '8' && (*kname)[1] == '[') {
228
*part = **kname - '0';
232
if (**kname == '[') {
237
if (**kname >= '1' && **kname <= '8') {
238
if ((*kname)[1] == '/' || !(*kname)[1]) {
239
*part = **kname - '0';
245
} else if (**kname == '/') {
256
static void check_initrd (char *label, int defpart, char *defdevice)
260
initrd_string = cfg_get_strg (label, "initrd");
262
initrd_defpart = defpart;
263
initrd_defdevice = defdevice;
265
p = cfg_get_strg (label, "initrd-size");
266
if (p) initrd_size = atoi (p);
267
initrd_prompt = cfg_get_flag (label, "initrd-prompt");
271
static int dig_into_params (char *params)
279
while (*p == ' ') p++;
281
if (!strncmp (p, "initrd", 6)) {
285
for (q = p++; *q && *q != ' '; q++);
287
initrd_string = malloc (q - p + 1);
288
memcpy (initrd_string, p, q - p);
289
initrd_string [q - p] = 0;
290
memset (p - 7, ' ', q - p + 7);
292
} else if (!strncmp (p, "-prompt", 7)) {
294
memset (p - 6, ' ', 7 + 6);
295
} else if (!strncmp (p, "-size=", 6)) {
301
for (q = p; *q >= '0' && *q <= '9'; q++);
302
memset (p - 12, ' ', q - p + 12);
305
} else if (!strncmp (p, "pause-after", 11)) {
308
} else if (!strncmp (p, "show-arguments", 14)) {
311
} else if (!strncmp (p, "root=", 5)) {
314
while (*last_root != ' ') *last_root++ = ' ';
317
} else if (!strncmp (p, "nfsroot=", 8)) {
320
while (*p && *p != ' ') p++;
325
static void check_password(char *str)
329
for (i = 0; i < 3; i++) {
330
printf ("\n%sassword: ", str);
332
silo_cmdedit((void (*)(void)) 0, 1);
334
if (!strcmp (password, passwdbuff))
337
printf ("Wrong password. Please try again...");
339
printf ("Seems like you don't know the access password...\n");
343
static char *ls_options(char *parms)
348
for (p = parms + 1;*p && *p != ' ';p++) {
350
case 'l': ls_opt |= LSOPT_L; break;
351
case 't': ls_opt |= LSOPT_T; break;
352
case 'r': ls_opt |= LSOPT_R; break;
354
printf ("Unhandled options to ls: `%s' - only l, t and r supported\n", parms);
358
while (*p == ' ') p++;
363
static int get_params (char **device, int *part, char **kname, char **proll,
370
char *imagename = 0, *label = 0;
371
int timeout = -1, beg = 0, end;
372
static char buffer[2048], buffer2[2048];
373
static char prollb[256]; /* Hmm */
374
static int first = 1;
376
int from_siloconf = 0;
377
static int no_prom_args = 0;
381
if (raid_dsk_number) {
382
defpart = silo_conf_parts[raid_dsk_number - 1];
383
if (defpart < 1 || defpart > 8)
398
defdevice = cfg_get_strg (0, "device");
400
/* For RAID1 avoid using this at all, it makes no sense
402
p = cfg_get_strg (0, "partition");
403
if (p && *p >= '1' && *p <= '8' && !p[1])
408
p = cfg_get_strg (0, "timeout");
411
if (no_prom_args) p = 0;
412
else p = silo_get_bootargs(0);
413
if (p) while (*p == ' ') p++;
415
for (q = p; *q && *q != ' '; q++);
418
while (*q == ' ') q++;
424
} else if (!timeout) {
426
c = prom_nbgetchar ();
427
if (c != -1 && c != '\n' && c != '\r') {
431
} else if (c >= ' ') {
437
imagename = cfg_get_default ();
440
} else if (timeout != -1) {
442
if (!init_timer ()) timer_status = 1;
443
else timer_status = -1;
446
if (timer_status <= 0) {
447
printf ("\nYour timeout %d.%ds will never expire, since counter couldn't"
448
"\nbe initialized\nboot: ", timeout/10, timeout % 10);
452
c = prom_nbgetchar ();
455
end = beg + 10 * timeout;
457
c = prom_nbgetchar ();
460
} while (get_ticks () <= end);
462
if (c != -1 && c != '\n' && c != '\r') {
466
} else if (c >= ' ') {
470
if (cfg_get_flag (cbuff, "single-key"))
474
imagename = cfg_get_default ();
477
if (timer_status >= 1) {
485
if ((!*cbuff || (timeout > 0 && timer_status < 0)) && !tabbedout)
487
silo_cmdedit(maintabfunc, 0);
489
for (p = cbuff; *p == ' '; p++);
491
while ((*q++ = *p++) != 0);
493
strcpy (given_bootargs, cbuff);
494
given_bootargs_by_user = 1;
497
imagename = cfg_get_default ();
499
p = strchr (cbuff, ' ');
504
while (*p && *p <= ' ')
511
p = cfg_get_strg (imagename, "image");
517
p = cfg_get_strg (0, "pause-message");
518
if (p) pause_message = p;
520
if (**params && password)
521
check_password ("To specify image arguments you need to enter your p");
523
defdevice = cfg_get_strg (label, "device");
525
if (!raid_dsk_number)
528
p = cfg_get_strg (label, "partition");
529
if (p && *p >= '1' && *p <= '8' && !p[1])
534
if (cfg_get_flag (label, "fill-reboot-cmd"))
536
if (cfg_get_strg (label, "other"))
538
else if (cfg_get_flag (label, "solaris"))
540
p = cfg_get_strg (label, "literal");
542
p = cfg_get_strg (label, "append");
551
} else if (!solaris && !other) {
552
p = cfg_get_strg (label, "root");
559
if (cfg_get_flag (label, "read-only")) {
563
if (cfg_get_flag (label, "read-write")) {
567
p = cfg_get_strg (label, "ramdisk");
569
strcpy (q, "ramdisk=");
574
p = cfg_get_strg (label, "append");
580
check_initrd (label, defpart, defdevice);
583
p = cfg_get_strg (label, "proll");
584
if (p && strlen (p) < sizeof(prollb)-1) {
590
char *oth_device = 0;
594
parse_name (imagename, -1, &oth_device, &other_part, &oth_kname);
595
if (other_part == -1 || oth_kname) {
596
printf ("Wrong syntax for other= parameter. The parameter should be\n");
597
if (prom_vers == PROM_V0)
598
printf ("either a single number 1-8 (ie. partition of the current disk)\n"
599
"or sd(X,Y,Z)N (ie. some other disk plus partition number)\n"
600
"e.g. sd(0,3,2)4\n");
602
printf ("either a single number 1-8 (ie. partition of the current disk)\n"
603
"or /prom/path/name;N (ie. some other disk plus partition number)\n"
604
"e.g. /iommu/sbus/espdma/esp/sd@3,0;3 \n");
610
oth_device = defdevice;
612
oth_device = silo_disk_get_bootdevice();
614
strcpy (other_device, oth_device);
615
p = cfg_get_strg (label, "bootblock");
621
if (architecture == sun4u)
623
strcpy (bufx, "x[1-16]");
624
*bufx = other_part + '0';
625
defdevice = other_device;
626
defpart = other_part;
629
pause_after = cfg_get_flag (label, "pause-after");
630
p = cfg_get_strg (label, "pause-message");
631
if (p) pause_message = p;
637
if (no_prom_args) p = 0;
638
else p = silo_get_bootargs(0);
639
if (p) while (*p == ' ') p++;
641
for (q = p; *q && *q != ' '; q++);
644
while (*q == ' ') q++;
654
silo_cmdedit((void (*)(void)) 0, 0);
656
for (p = cbuff; *p == ' '; p++);
658
while ((*q++ = *p++) != 0);
660
strcpy (given_bootargs, cbuff);
661
given_bootargs_by_user = 1;
663
p = strchr (cbuff, ' ');
669
while (*p && *p <= ' ')
676
if (!strcmp (imagename, "halt"))
678
if (!label && password)
679
check_password ("To boot a custom image you need to enter your p");
680
if (!strcmp (imagename, "xxdebug"))
682
if (!strcmp (imagename, "help")) {
683
if (prom_vers == PROM_V0)
684
printf ("You have to type image name as {XY(...)}partno/path or {XY(...)}partno[mm-nn],\n"
685
"where XY(...) is the optional v0 prom device name (if partition number is specified,\n"
686
"it should be Sun partition number (zero based) of any partition starting at cyl. 0)\n"
687
"({} means that it is optional) and partno is a Linux partition number from 1 to 8.\n"
688
"You can specify a path into filesystem (ext2fs, ufs) - has to start with / - or\n"
689
"[mm-nn] as range of phys. blocks (512B).\n");
691
printf ("You have to type image name as [prom_path;]partno/path, where partno is a\n"
692
"number from 1 to 8. If partno is not specified, either default from silo.conf\n"
693
"(partition=X) or 1 will be used. Instead of /path you can type [mm-nn] to\n"
694
"specify a range of phys. blocks (512B)\n");
695
printf ("If you use silo.conf and have some image= sections there, you can type\n"
696
"its label or alias name instead of the above described image names.\n"
697
"Pressing just enter will load default image with default arguments. Special\n"
698
"image names `halt' and `help' can be used to fall back to PROM or display\n"
699
"help. All three types of image names can be followed by additional arguments.\n"
701
if (prom_vers == PROM_V0)
702
printf (" /boot/vmlinux.gz root=/dev/sda4\n"
703
" 2/boot/mykernel.gz root=/dev/sda2\n"
704
" sd(0,6,2)5/boot/old.b\n"
705
" sd(1,2,0)[1-16] root=/dev/sda4\n");
707
printf (" /iommu/sbus/espdma/esp/sd@3,0;4/boot/vmlinux.gz root=/dev/sda4\n"
709
" /sbus/espdma/esp/sd@0,0;3[1-16] root=/dev/sda4\n");
710
printf (" linux root=/dev/sda4\n"
715
strcpy (buffer2, imagename);
717
if (!label && (!strcmp (imagename, "cat") || !strcmp (imagename, "ls"))) {
718
if (*imagename == 'c')
722
*params = ls_options (*params);
725
p = strchr (imagename, ' ');
730
while (*p && *p <= ' ')
734
} else if (label && (!strncmp (imagename, "cat ", 4) || !strncmp (imagename, "ls ", 3))) {
735
if (*imagename == 'c') {
738
while (*imagename == ' ') imagename++;
742
while (*imagename == ' ') imagename++;
743
imagename = ls_options (imagename);
746
parse_name (imagename, -2, device, part, kname);
749
if (*kname && *part == -2) {
759
strcpy (other_device, silo_disk_get_bootdevice());
761
strcpy (other_device, *device);
762
p = strstr (*params, "bootblock=");
763
if (p && (p == *params || p[-1] == ' ') && p[10] && p[10] != ' ') {
768
while (*p && *p != ' ')
771
parse_name (tmp, defpart, device, part, kname);
773
p = strstr (*params, "bootblock=");
774
memset (p, ' ', q - tmp + 10);
778
printf ("Syntax of your bootblock= parameter is wrong. Please see help\n");
782
*kname = strdup ("[1-16]");
783
if (architecture == sun4u)
794
int options_node, len;
795
int is_from_prom = 0;
799
if ((options_node = prom_searchsiblings (prom_getchild (prom_root_node), "options")) != 0) {
800
if (prom_vers != PROM_V0) {
801
prom_getstring (options_node, v = "boot-file", buffer3, 2048);
802
len = prom_getproplen (options_node, v);
803
if (len < 0) len = 0;
805
if (!strcmp (buffer3, my_bootargs))
808
prom_getstring (options_node, v = "diag-file", buffer3, 2048);
809
len = prom_getproplen (options_node, v);
810
if (len < 0) len = 0;
812
if (!strcmp (buffer3, my_bootargs))
816
prom_getstring (options_node, v = "boot-from", buffer3, 2048);
817
len = prom_getproplen (options_node, v);
818
if (len < 0) len = 0;
820
if (!strcmp (buffer3, my_bootargs))
828
given_bootargs_by_user = 1;
829
printf ("You have `%s' string in your %s variable.\n"
830
"This string doesn't contain valid arguments to SILO.\n"
831
"Consider doing setenv %s. Anyway, SILO will continue as\n"
832
"if there were no arguments in %s.\n", buffer3, v, v, v);
836
printf ("Your imagename `%s' and arguments `%s' have either wrong syntax,\n"
837
"or describe a label which is not present in silo.conf\n"
838
"Type `help' at the boot: prompt if you need it and then try again.\n", buffer2, *params ? *params : "");
839
} else if (!solaris) {
840
p = strstr (*params, "solaris");
841
if (p && (p == *params || p[-1] == ' ') && (!p[7] || p[7] == ' ')) {
844
} else if (!strcmp (*kname, "/kernel/unix"))
846
if (!fill_reboot_cmd) {
847
p = strstr (*params, "fill-reboot-cmd");
848
if (p && (p == *params || p[-1] == ' ') && (!p[15] || p[15] == ' ')) {
857
static void initrd_lenfunc (int len, char **filebuffer, char **filelimit)
859
extern unsigned long long initrd_phys;
861
initrd_start = memory_find ((len + 16383) & ~16383);
863
silo_fatal("You do not have enough continuous available memory "
864
"for such initial ramdisk.");
868
*filebuffer = initrd_start;
869
*filelimit = initrd_start + ((len + 16383) & ~16383);
870
printf("Loading initial ramdisk (%d bytes at 0x%Lx phys, 0x%x virt)...\n", len,
871
initrd_phys, initrd_start);
874
static int parse_executable (unsigned char *base, int image_len, unsigned int *poff,
875
int *plen, unsigned *pstart, char *image_name)
886
unsigned st = (unsigned int) base;
888
/* By this point the first sector is loaded (and the rest of */
889
/* the kernel) so we check if it is an executable file, either */
890
/* an a.out or an elf binary */
893
if (hp.a->magic == 0x01030107) {
895
printf ("\nYour Solaris `ufsboot' is not an ELF image. Try again.\n");
898
off = sizeof (struct aout_hdr);
899
if (image_len > hp.a->ltext + hp.a->ldata)
900
len = hp.a->ltext + hp.a->ldata;
904
} else if (hp.e->e_ident[EI_MAG0] == ELFMAG0 &&
905
hp.e->e_ident[EI_MAG1] == ELFMAG1 &&
906
hp.e->e_ident[EI_MAG2] == ELFMAG2 &&
907
hp.e->e_ident[EI_MAG3] == ELFMAG3) {
909
if (hp.e->e_ident[EI_DATA] != ELFDATA2MSB) {
910
silo_fatal("Image is not a MSB ELF");
913
if (hp.e->e_ident[EI_CLASS] == ELFCLASS32) {
916
p = (Elf32_Phdr *) (hp.b + hp.e->e_phoff);
917
if (p->p_type != PT_LOAD) {
918
silo_fatal("Cannot find a loadable segment in your "
924
unsigned long sa = (unsigned long)&_start;
926
for (i = 0; i < hp.e->e_phnum; i++, p++) {
927
if (p->p_vaddr < 0x4000 + image_len ||
928
p->p_vaddr + p->p_memsz >= sa) {
929
silo_fatal("Unable to handle your "
930
"Solaris `ufsboot' bootloader.");
933
memcpy ((char *)p->p_vaddr,
934
(char *)(0x4000 + p->p_offset), p->p_filesz);
935
if (p->p_filesz < p->p_memsz)
936
memset ((char *)(p->p_vaddr + p->p_filesz), 0,
937
p->p_memsz - p->p_filesz);
945
Elf32_Phdr *q = p + 1;
947
for (i = 1; i < hp.e->e_phnum; i++, q++) {
948
if (q->p_type != PT_LOAD)
950
n = q->p_offset - p->p_offset;
951
if (q->p_vaddr - p->p_vaddr == n &&
952
q->p_paddr - p->p_paddr == n &&
953
p->p_memsz == p->p_filesz &&
955
p->p_filesz = n + q->p_filesz;
956
p->p_memsz = n + q->p_memsz;
958
silo_fatal("Multiple loadable segments in "
963
off = p->p_offset + hp.e->e_entry - p->p_vaddr;
965
if (len > image_len) len = image_len;
968
} else if (hp.e->e_ident[EI_CLASS] == ELFCLASS64) {
970
unsigned long long n;
974
p = (Elf64_Phdr *) (hp.b + hp.f->e_phoff);
975
if (p->p_type != PT_LOAD) {
976
silo_fatal("Cannot find a loadable segment in your "
982
unsigned long sa = (unsigned long)&_start;
984
for (i = 0; i < hp.f->e_phnum; i++, p++) {
985
if (p->p_vaddr < 0x4000 + image_len ||
986
p->p_vaddr + p->p_memsz >= sa) {
988
silo_fatal("Unable to handle your "
989
"Solaris `ufsboot' bootloader.");
992
memcpy ((Elf64_Addr *)(long)(p->p_vaddr),
993
(Elf64_Addr *)(long)(0x4000 + p->p_offset),
995
if (p->p_filesz < p->p_memsz)
996
memset ((Elf64_Addr *)(long)(p->p_vaddr + p->p_filesz),
997
0, p->p_memsz - p->p_filesz);
1003
for (i = 1; i < hp.f->e_phnum; i++, q++) {
1004
if (q->p_type != PT_LOAD)
1006
n = q->p_offset - p->p_offset;
1007
if (q->p_vaddr - p->p_vaddr == n &&
1008
q->p_paddr - p->p_paddr == n &&
1009
p->p_memsz == p->p_filesz &&
1012
p->p_filesz = n + q->p_filesz;
1013
p->p_memsz = n + q->p_memsz;
1015
silo_fatal("Multiple loadable segments "
1016
"in your ELF image");
1021
off = p->p_offset + hp.f->e_entry - p->p_vaddr;
1023
if (len > image_len) len = image_len;
1034
printf ("\nUnknown image %s format\n", image_name);
1039
/* Here we are launched */
1043
int len = 0, image_len;
1044
char *kname, *params, *device;
1046
unsigned char *image_base = (unsigned char *) 0x4000;
1047
char *kernel_params;
1049
int isfile, fileok = 0;
1050
unsigned int ret_offset = 0;
1051
char *params_device = 0;
1052
int silo_conf_partition;
1054
prom_ranges_init ();
1056
architecture = silo_get_architecture();
1057
strcpy (given_bootargs, silo_get_bootargs(1));
1058
strcpy (my_bootargs, silo_get_bootargs(0));
1061
if (silo_diskinit() == -1)
1065
if (architecture == sun4u) {
1066
char buffer[512], *p;
1067
int node = prom_finddevice("/chosen");
1069
prom_getstring(node, "bootpath", buffer, 512);
1070
if (strstr(buffer, "fdthree")) {
1071
p = strchr (buffer, ':');
1073
node = prom_finddevice(buffer);
1075
if (prom_getintdefault (node, "unit", 0) == 1)
1082
/* Here should be code #ifdef TFTP, that will handle loading of silo.conf via tftp and this code should be on the other side #ifndef TFTP */
1083
silo_conf_partition = silo_conf_part;
1085
if (raid_dsk_number)
1086
silo_conf_partition = silo_conf_parts[raid_dsk_number - 1];
1088
if (*silo_conf && silo_conf_partition >= 1 && silo_conf_partition <= 8) {
1091
fileok = silo_load_file(0, silo_conf_partition, silo_conf,
1092
(unsigned char *) 0x4000,
1093
(unsigned char *) &_start,
1094
&len, LOADFILE_GZIP | LOADFILE_NO_ROTATE, 0);
1095
if (!fileok || (unsigned) len >= 65535)
1096
printf ("\nCouldn't load %s\n", silo_conf);
1098
if (!cfg_parse (silo_conf, (char *) 0x4000, len)) {
1103
if (raid_dsk_number)
1104
defpart = silo_conf_partition;
1106
p = cfg_get_strg (0, "message");
1108
q = cfg_get_strg (0, "partition");
1109
if (q && *q >= '1' && *q <= '8' && !q[1])
1111
parse_name (p, defpart, &device, &part, &kname);
1114
device = cfg_get_strg (0, "device");
1116
if (silo_load_file(device, part, kname,
1117
(unsigned char *) 0x4000,
1118
(unsigned char *) &_start, &len,
1119
LOADFILE_GZIP, 0)) {
1120
*(unsigned char *) (0x4000 + len) = 0;
1122
print_message ((char *) 0x4000);
1127
password = cfg_get_strg (0, "password");
1128
if (password && !cfg_get_flag (0, "restricted")) {
1129
check_password ("P");
1133
printf ("Syntax error in %s\n"
1134
"Please check the file for obvious bugs, and if you think it is correct, get\n"
1135
"latest version of SILO. If problems still survive, contact the author\n", silo_conf);
1141
printf ("No config file loaded, you can boot just from this command line\n"
1142
"Type [prompath;]part/path_to_image [parameters] on the prompt\n"
1143
"E.g. /iommu/sbus/espdma/esp/sd@3,0;4/vmlinux root=/dev/sda4\n"
1144
"or 2/vmlinux.live (to load vmlinux.live from 2nd partition of boot disk)\n");
1146
isfile = 0; /* RC = 0 invalid file or not an executable */
1148
switch (get_params (&device, &part, &kname, &proll, ¶ms)) {
1158
if (other && reboot)
1162
char *p = seed_part_into_device ((!device || !*device) ? silo_disk_get_bootdevice() : device, part);
1163
strcpy (sol_params, p);
1164
params_device = strchr (sol_params, 0) + 1;
1165
strcpy (params_device, kname);
1166
if (params && *params) {
1167
strcat (params_device, " ");
1168
strcat (params_device, params);
1172
if (load_cmd == CMD_BOOT && proll != 0) {
1173
if (other || solaris) {
1174
printf ("\nNeither \"other\" nor \"solaris\" are compatible with proll\n");
1177
if (!silo_load_file(device, part, proll, (unsigned char *) 0x4000,
1178
(unsigned char *) 0x40000, &image_len,
1179
LOADFILE_GZIP, 0)) {
1180
printf ("\nProll not found.... try again\n");
1183
if (!parse_executable ((unsigned char *)0x4000, image_len, &off,
1186
memcpy ((char *) 0x4000, ((char *) 0x4000) + off, len);
1188
image_base = (unsigned char *) 0x40000;
1189
if (!silo_load_file(device, part, kname, image_base,
1190
(unsigned char *) &_start, &image_len,
1191
LOADFILE_GZIP, 0)) {
1192
printf ("\nImage not found.... try again\n");
1195
if (!(isfile = parse_executable (image_base, image_len,
1196
&off, &len, NULL, kname)))
1198
ret_offset = 0x4000;
1201
unsigned char *image_end = (unsigned char *)&_start;
1203
/* See if we can use some extra memory for the kernel */
1209
mem = (unsigned char *)image_memory_find(size);
1213
mem = (unsigned char *)image_memory_find(size);
1218
image_end = image_base + size - 0x4000;
1219
printf("Allocated %d Megs of memory at 0x%x for kernel\n",
1220
size >> 20, image_base - 0x4000);
1224
if (!silo_load_file(device, part, kname, image_base, image_end,
1225
&image_len, ((load_cmd == CMD_LS) ?
1227
LOADFILE_GZIP), 0)) {
1228
printf ("\nImage not found.... try again\n");
1231
image_memory_release();
1236
if (load_cmd == CMD_CAT) {
1237
*(image_base + image_len) = 0;
1238
printf ("%s", image_base);
1242
if (load_cmd == CMD_LS) {
1243
do_ls (image_base, NULL);
1247
isfile = parse_executable (image_base, image_len, &off, &len,
1248
&ret_offset, kname);
1254
params = params_device;
1255
params_device = sol_params;
1256
} else if (!other) {
1257
struct HdrS_struct *hdrs;
1261
memcpy (image_base, image_base + off, len);
1263
hdrs = (struct HdrS_struct *)
1264
silo_find_linux_HdrS((char *)image_base, image_len);
1266
if (hdrs && hdrs->ver < 0x300 && image_base != (unsigned char *)0x4000) {
1267
/* Kernel doesn't support being loaded to other than
1268
* phys_base, so let's try to copy it down there. */
1269
if ((unsigned int)&_start - 0x4000 < len) {
1270
/* Fuck, can't do that */
1271
printf("Your kernel cannot fit into the memory destination. This\n"
1272
"can be resolved by recompiling the kernel with more devices\n"
1273
"built as modules, or upgrading your kernel to one that\n"
1274
"supports being loaded to higher memory areas (currently\n"
1275
"2.6.3+ or 2.4.26+).\n");
1279
printf("Kernel doesn't support loading to high memory, relocating...");
1281
/* Ok, it fits, so copy it down there */
1282
memcpy ((char *)0x4000, image_base, len);
1283
image_base = (unsigned char *)0x4000;
1285
/* Readjust some things */
1286
ret_offset = 0x4000;
1287
hdrs = (struct HdrS_struct *)
1288
silo_find_linux_HdrS((char *)image_base, image_len);
1294
unsigned int linux_ver = hdrs->linux_ver;
1296
printf("Loaded kernel version %d.%d.%d\n", (linux_ver >> 16) & 0xff,
1297
(linux_ver >> 8) & 0xff, linux_ver & 0xff);
1299
if (fill_reboot_cmd && hdrs->ver >= 0x201) { /* ie. uses reboot_command */
1300
char *q = (char *)hdrs->reboot_cmd_ptr_high;
1303
/* On Ultra there is xword there, this hack makes
1306
if (q == (char *)0xfffff800 || !q)
1307
q = (char *)hdrs->reboot_cmd_ptr_low;
1308
q = (char *)(((unsigned long)q)& 0x003fffff);
1309
if (q >= (char *)0x4000 && q <= (char *)0x300000) {
1310
if (given_bootargs_by_user) {
1311
if (strlen (silo_disk_get_bootdevice()) <= 254) {
1312
strcpy (q, silo_disk_get_bootdevice());
1314
if (strlen (given_bootargs) < 255 - (r - q)) {
1316
strcpy (r, given_bootargs);
1319
} else if (strlen (given_bootargs) <= 255)
1320
strcpy (q, given_bootargs);
1323
if (!dig_into_params (params) && !hdrs->root_dev) {
1326
s1 = cfg_get_strg(0, "root");
1328
s2 = malloc(strlen(params) + 8 + strlen(s1));
1330
strcat(s2, " root=");
1336
if (hdrs->ver >= 0x202) {
1337
if (architecture == sun4u)
1338
kernel_params = (char *)((hdrs->bootstr_info_ptr_low - 0x400000) +
1339
(image_base - 0x4000));
1341
kernel_params = (char *)(hdrs->bootstr_info_ptr_low & 0x3fffff);
1344
/* Some UltraAX machines have /dev/fd1 floppies only. */
1348
for (s1 = params; (s1 = strstr(s1, "root=/dev/fd0")) != NULL; s1 += 13)
1352
if (initrd_string) {
1353
char *q, *r, *initrd_device, *initrd_kname, *initrd_limit, *initrd_cur, c;
1355
int initrd_partno, len, statusok = 0;
1357
if (hdrs->ver >= 0x301)
1358
initrd_can_do_64bit_phys = 1;
1360
q = strchr (initrd_string, '|');
1361
if (q && !initrd_size) {
1362
silo_fatal("When more than one initial ramdisk piece "
1363
"is specified, you have to give\n"
1364
"a non-zero initrd-size option which is no "
1365
"shorter than sum of all pieces\n"
1366
"lengths. Try again...\n");
1370
initrd_start = memory_find ((initrd_size + 16383) & ~16383);
1371
if (!initrd_start) {
1372
silo_fatal("You do not have enough continuous "
1373
"available memory for such initial "
1377
string = strdup (initrd_string);
1378
q = strchr (string, '|');
1380
initrd_cur = initrd_start;
1381
initrd_limit = initrd_start + ((initrd_size + 16383) & ~16383);
1382
printf ("Loading parts of initial ramdisk...\n");
1386
parse_name (r, initrd_defpart, &initrd_device, &initrd_partno, &initrd_kname);
1387
if (!initrd_kname) break;
1388
if (!initrd_device) initrd_device = initrd_defdevice;
1389
if (!silo_load_file(initrd_device, initrd_partno,
1390
initrd_kname, (unsigned char *)initrd_cur,
1391
(unsigned char *)initrd_limit, &len, 0, 0))
1399
q = strchr (r, '|');
1400
if (!q) q = strchr (r, 0);
1401
if (initrd_prompt) {
1403
printf ("Insert next media and press ENTER");
1409
printf("Loaded initial ramdisk (%d bytes at 0x%x)...\n", (unsigned int)initrd_cur -
1410
(unsigned int)initrd_start, initrd_start);
1412
extern unsigned long long sun4u_initrd_phys;
1413
extern unsigned long sun4m_initrd_pa;
1415
if (architecture == sun4u) {
1416
if (initrd_can_do_64bit_phys) {
1417
hdrs->ramdisk_image64 =
1418
sun4u_initrd_phys + 0x400000ULL;
1420
hdrs->ramdisk_image =
1421
(unsigned int)sun4u_initrd_phys + 0x400000;
1423
} else if (sun4m_initrd_pa) {
1424
hdrs->ramdisk_image = ((unsigned int)sun4m_initrd_pa);
1426
hdrs->ramdisk_image = ((unsigned int)initrd_start | 0xf0000000);
1428
hdrs->ramdisk_size = initrd_size;
1430
printf ("Error: initial ramdisk loading failed. No initrd will be used.\n");
1432
parse_name (initrd_string, initrd_defpart, &initrd_device, &initrd_partno, &initrd_kname);
1434
if (!initrd_device) initrd_device = initrd_defdevice;
1435
if (silo_load_file(initrd_device, initrd_partno,
1436
initrd_kname, (unsigned char *) 0x300000,
1437
(unsigned char *) LARGE_RELOC,
1438
0, 0, initrd_lenfunc)) {
1439
extern unsigned long long sun4u_initrd_phys;
1440
extern unsigned long sun4m_initrd_pa;
1442
if (architecture == sun4u) {
1443
if (initrd_can_do_64bit_phys) {
1444
hdrs->ramdisk_image64 =
1445
sun4u_initrd_phys + 0x400000ULL;
1447
hdrs->ramdisk_image =
1448
(unsigned int)sun4u_initrd_phys + 0x400000;
1450
} else if (sun4m_initrd_pa) {
1451
hdrs->ramdisk_image = ((unsigned int)sun4m_initrd_pa);
1453
hdrs->ramdisk_image = ((unsigned int)initrd_start | 0xf0000000);
1455
hdrs->ramdisk_size = initrd_size;
1458
printf ("Error: initial ramdisk loading failed. No initrd will be used.\n");
1465
if (off != 0 && !reboot)
1466
memcpy (image_base, image_base + off, len);
1467
p = seed_part_into_device (other_device, other_part);
1468
strcpy (other_device, p);
1469
params_device = other_device;
1473
if (timer_status >= 1)
1476
silo_set_prollargs(params, (unsigned int)image_base, len);
1477
if (show_arguments) {
1478
printf ("Arguments: \"%s\"\n");
1482
silo_set_bootargs(params, params_device);
1484
if (kernel_params) {
1485
extern char barg_out[];
1486
int len = *(unsigned int *)kernel_params;
1488
strncpy (kernel_params + 8, barg_out, len);
1489
kernel_params [8 + len - 1] = 0;
1490
*(unsigned int *)(kernel_params + 4) = 1;
1493
if (show_arguments) {
1494
silo_show_bootargs();
1500
printf ("%s", pause_message);
1507
if (other && reboot) {
1508
strcpy (sol_params, params_device);
1509
strcat (sol_params, " ");
1510
strcat (sol_params, params);
1511
prom_reboot(sol_params);