10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
55648Ssetje * Common Development and Distribution License (the "License").
65648Ssetje * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*11498SJerry.Gilliam@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/param.h>
270Sstevel@tonic-gate #include <sys/fcntl.h>
280Sstevel@tonic-gate #include <sys/obpdefs.h>
290Sstevel@tonic-gate #include <sys/reboot.h>
300Sstevel@tonic-gate #include <sys/promif.h>
310Sstevel@tonic-gate #include <sys/stat.h>
320Sstevel@tonic-gate #include <sys/bootvfs.h>
330Sstevel@tonic-gate #include <sys/platnames.h>
340Sstevel@tonic-gate #include <sys/salib.h>
350Sstevel@tonic-gate #include <sys/elf.h>
360Sstevel@tonic-gate #include <sys/link.h>
370Sstevel@tonic-gate #include <sys/auxv.h>
380Sstevel@tonic-gate #include <sys/boot_policy.h>
390Sstevel@tonic-gate #include <sys/boot_redirect.h>
400Sstevel@tonic-gate #include <sys/bootconf.h>
410Sstevel@tonic-gate #include <sys/boot.h>
420Sstevel@tonic-gate #include "boot_plat.h"
430Sstevel@tonic-gate
440Sstevel@tonic-gate #define SUCCESS 0
450Sstevel@tonic-gate #define FAILURE -1
460Sstevel@tonic-gate
470Sstevel@tonic-gate #define ISSPACE(c) (c == ' ' || c == '\t')
480Sstevel@tonic-gate #define SKIP_WHITESPC(cp) while (*cp && ISSPACE(*cp)) cp++;
490Sstevel@tonic-gate
500Sstevel@tonic-gate
510Sstevel@tonic-gate #ifdef DEBUG
520Sstevel@tonic-gate int debug = 0;
530Sstevel@tonic-gate #else
540Sstevel@tonic-gate static const int debug = 0;
550Sstevel@tonic-gate #endif
560Sstevel@tonic-gate
570Sstevel@tonic-gate #define dprintf if (debug) printf
580Sstevel@tonic-gate
590Sstevel@tonic-gate #ifdef DEBUG_LISTS
600Sstevel@tonic-gate void print_memlist(struct memlist *av);
610Sstevel@tonic-gate #endif
620Sstevel@tonic-gate
630Sstevel@tonic-gate extern int (*readfile(int fd, int print))();
640Sstevel@tonic-gate extern void kmem_init(void);
650Sstevel@tonic-gate extern void *kmem_alloc(size_t, int);
660Sstevel@tonic-gate extern void kmem_free(void *, size_t);
670Sstevel@tonic-gate extern void get_boot_args(char *buf);
680Sstevel@tonic-gate extern void setup_bootops(void);
690Sstevel@tonic-gate extern struct bootops bootops;
700Sstevel@tonic-gate extern void exitto(int (*entrypoint)());
710Sstevel@tonic-gate extern void exitto64(int (*entrypoint)(), void *bootvec);
720Sstevel@tonic-gate
730Sstevel@tonic-gate int openfile(char *filename);
740Sstevel@tonic-gate
75*11498SJerry.Gilliam@Sun.COM char *default_name;
76*11498SJerry.Gilliam@Sun.COM char *default_path;
77*11498SJerry.Gilliam@Sun.COM
78*11498SJerry.Gilliam@Sun.COM int vac; /* virtual address cache type (none == 0) */
79*11498SJerry.Gilliam@Sun.COM int is_sun4v; /* sun4u vs. sun4v */
80*11498SJerry.Gilliam@Sun.COM int client_isLP64 = 1; /* SPARC clients are always LP64 */
81*11498SJerry.Gilliam@Sun.COM
82*11498SJerry.Gilliam@Sun.COM extern bootplat_defaults_t sun4u_plat_defaults;
83*11498SJerry.Gilliam@Sun.COM extern bootplat_defaults_t sun4v_plat_defaults;
840Sstevel@tonic-gate
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate * filename is the name of the standalone we're going to execute.
870Sstevel@tonic-gate */
880Sstevel@tonic-gate char filename[MAXPATHLEN];
890Sstevel@tonic-gate
900Sstevel@tonic-gate char * const defname = "kernel/sparcv9/unix";
910Sstevel@tonic-gate
920Sstevel@tonic-gate /*
930Sstevel@tonic-gate * We enable the cache by default
940Sstevel@tonic-gate * but boot -n will leave it alone...
950Sstevel@tonic-gate * that is, we use whatever state the PROM left it in.
960Sstevel@tonic-gate */
970Sstevel@tonic-gate char *mfg_name;
980Sstevel@tonic-gate int cache_state = 1;
990Sstevel@tonic-gate char filename2[MAXPATHLEN];
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate int boothowto = 0;
1020Sstevel@tonic-gate int verbosemode = 0;
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate /*
1060Sstevel@tonic-gate * Copy filename and bargs into v2args_buf, which will be exported as the
1070Sstevel@tonic-gate * boot-args boot property. We should probably warn the user if anything gets
1080Sstevel@tonic-gate * cut off.
1090Sstevel@tonic-gate */
1100Sstevel@tonic-gate void
set_client_bootargs(const char * filename,const char * bargs)1110Sstevel@tonic-gate set_client_bootargs(const char *filename, const char *bargs)
1120Sstevel@tonic-gate {
1130Sstevel@tonic-gate int i = 0;
1140Sstevel@tonic-gate const char *s;
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate s = filename;
1170Sstevel@tonic-gate while (*s != '\0' && i < V2ARGS_BUF_SZ - 1)
1180Sstevel@tonic-gate v2args_buf[i++] = *s++;
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate if (i >= V2ARGS_BUF_SZ - 2) {
1210Sstevel@tonic-gate /* Not enough room for a space and any of bargs. */
1220Sstevel@tonic-gate v2args_buf[i] = '\0';
1230Sstevel@tonic-gate return;
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate v2args_buf[i++] = ' ';
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate s = bargs;
1290Sstevel@tonic-gate while (*s != '\0' && i < V2ARGS_BUF_SZ - 1)
1300Sstevel@tonic-gate v2args_buf[i++] = *s++;
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate v2args_buf[i] = '\0';
1330Sstevel@tonic-gate }
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate /*
1360Sstevel@tonic-gate * The slice redirection file is used on the install CD
1370Sstevel@tonic-gate */
1380Sstevel@tonic-gate static int
read_redirect(char * redirect)1390Sstevel@tonic-gate read_redirect(char *redirect)
1400Sstevel@tonic-gate {
1410Sstevel@tonic-gate int fd;
1420Sstevel@tonic-gate char slicec;
1430Sstevel@tonic-gate size_t nread = 0;
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate if ((fd = open(BOOT_REDIRECT, O_RDONLY)) != -1) {
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate * Read the character out of the file - this is the
1480Sstevel@tonic-gate * slice to use, in base 36.
1490Sstevel@tonic-gate */
1500Sstevel@tonic-gate nread = read(fd, &slicec, 1);
1510Sstevel@tonic-gate (void) close(fd);
1520Sstevel@tonic-gate if (nread == 1)
1530Sstevel@tonic-gate *redirect++ = slicec;
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate *redirect = '\0';
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate return (nread == 1);
1580Sstevel@tonic-gate }
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate void
post_mountroot(char * bootfile,char * redirect)1610Sstevel@tonic-gate post_mountroot(char *bootfile, char *redirect)
1620Sstevel@tonic-gate {
1630Sstevel@tonic-gate int (*go2)();
1640Sstevel@tonic-gate int fd;
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate /* Save the bootfile, just in case we need it again */
1670Sstevel@tonic-gate (void) strcpy(filename2, bootfile);
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate for (;;) {
1700Sstevel@tonic-gate if (boothowto & RB_ASKNAME) {
1710Sstevel@tonic-gate char tmpname[MAXPATHLEN];
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate printf("Enter filename [%s]: ", bootfile);
1740Sstevel@tonic-gate (void) cons_gets(tmpname, sizeof (tmpname));
1750Sstevel@tonic-gate if (tmpname[0] != '\0')
1760Sstevel@tonic-gate (void) strcpy(bootfile, tmpname);
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate
1790Sstevel@tonic-gate if (boothowto & RB_HALT) {
1800Sstevel@tonic-gate printf("Boot halted.\n");
1810Sstevel@tonic-gate prom_enter_mon();
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate if ((fd = openfile(bootfile)) == FAILURE) {
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate /*
1870Sstevel@tonic-gate * There are many reasons why this might've
1880Sstevel@tonic-gate * happened .. but one of them is that we're
1890Sstevel@tonic-gate * on the installation CD, and we need to
1900Sstevel@tonic-gate * revector ourselves off to a different partition
1910Sstevel@tonic-gate * of the CD. Check for the redirection file.
1920Sstevel@tonic-gate */
1930Sstevel@tonic-gate if (redirect != NULL &&
1940Sstevel@tonic-gate read_redirect(redirect)) {
1950Sstevel@tonic-gate /* restore bootfile */
1960Sstevel@tonic-gate (void) strcpy(bootfile, filename2);
1970Sstevel@tonic-gate return;
1980Sstevel@tonic-gate /*NOTREACHED*/
1990Sstevel@tonic-gate }
2000Sstevel@tonic-gate
2010Sstevel@tonic-gate printf("%s: cannot open %s\n", my_own_name, bootfile);
2020Sstevel@tonic-gate boothowto |= RB_ASKNAME;
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate /* restore bootfile */
2050Sstevel@tonic-gate (void) strcpy(bootfile, filename2);
2060Sstevel@tonic-gate continue;
2070Sstevel@tonic-gate }
2080Sstevel@tonic-gate
2090Sstevel@tonic-gate if ((go2 = readfile(fd, boothowto & RB_VERBOSE)) !=
2100Sstevel@tonic-gate (int(*)()) -1) {
2110Sstevel@tonic-gate (void) close(fd);
2120Sstevel@tonic-gate } else {
2130Sstevel@tonic-gate printf("boot failed\n");
2140Sstevel@tonic-gate boothowto |= RB_ASKNAME;
2150Sstevel@tonic-gate continue;
2160Sstevel@tonic-gate }
2170Sstevel@tonic-gate
2180Sstevel@tonic-gate if (boothowto & RB_HALT) {
2190Sstevel@tonic-gate printf("Boot halted before exit to 0x%p.\n",
2200Sstevel@tonic-gate (void *)go2);
2210Sstevel@tonic-gate prom_enter_mon();
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate
2240Sstevel@tonic-gate my_own_name = bootfile;
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate dprintf("Calling exitto64(%p, %p)\n", (void *)go2,
2270Sstevel@tonic-gate (void *)elfbootvecELF64);
2280Sstevel@tonic-gate exitto64(go2, (void *)elfbootvecELF64);
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate }
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate /*ARGSUSED*/
2330Sstevel@tonic-gate static int
boot_open(char * pathname,void * arg)2340Sstevel@tonic-gate boot_open(char *pathname, void *arg)
2350Sstevel@tonic-gate {
2360Sstevel@tonic-gate dprintf("trying '%s'\n", pathname);
2370Sstevel@tonic-gate return (open(pathname, O_RDONLY));
2380Sstevel@tonic-gate }
2390Sstevel@tonic-gate
2400Sstevel@tonic-gate /*
2410Sstevel@tonic-gate * Open the given filename, expanding to it's
2420Sstevel@tonic-gate * platform-dependent location if necessary.
2430Sstevel@tonic-gate *
2440Sstevel@tonic-gate * Boot supports OBP and IEEE1275.
2450Sstevel@tonic-gate *
2460Sstevel@tonic-gate * XXX: Move side effects out of this function!
2470Sstevel@tonic-gate */
2480Sstevel@tonic-gate int
openfile(char * filename)2490Sstevel@tonic-gate openfile(char *filename)
2500Sstevel@tonic-gate {
2510Sstevel@tonic-gate static char *fullpath;
2520Sstevel@tonic-gate static int once;
2530Sstevel@tonic-gate int fd;
2540Sstevel@tonic-gate
2550Sstevel@tonic-gate if (once == 0) {
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate ++once;
2580Sstevel@tonic-gate
2590Sstevel@tonic-gate /*
2600Sstevel@tonic-gate * Setup exported 'boot' properties: 'mfg-name'.
2610Sstevel@tonic-gate * XXX: This shouldn't be a side effect of openfile().
2620Sstevel@tonic-gate */
2630Sstevel@tonic-gate if (mfg_name == NULL)
2640Sstevel@tonic-gate mfg_name = get_mfg_name();
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate fullpath = (char *)kmem_alloc(MAXPATHLEN, 0);
2670Sstevel@tonic-gate }
2680Sstevel@tonic-gate
2690Sstevel@tonic-gate if (*filename == '/') {
2700Sstevel@tonic-gate (void) strcpy(fullpath, filename);
2710Sstevel@tonic-gate fd = boot_open(fullpath, NULL);
2720Sstevel@tonic-gate return (fd);
2730Sstevel@tonic-gate }
2740Sstevel@tonic-gate
2755648Ssetje fd = open_platform_file(filename, boot_open, NULL, fullpath);
2760Sstevel@tonic-gate if (fd == -1)
2770Sstevel@tonic-gate return (-1);
2780Sstevel@tonic-gate
2790Sstevel@tonic-gate /*
2800Sstevel@tonic-gate * Copy back the name we actually found
2810Sstevel@tonic-gate */
2820Sstevel@tonic-gate (void) strcpy(filename, fullpath);
2830Sstevel@tonic-gate return (fd);
2840Sstevel@tonic-gate }
2850Sstevel@tonic-gate
2860Sstevel@tonic-gate /*
2870Sstevel@tonic-gate * Get the boot arguments from the PROM and split it into filename and
2880Sstevel@tonic-gate * options components.
2890Sstevel@tonic-gate *
2900Sstevel@tonic-gate * As per IEEE1275 and boot(1M), the boot arguments will have the syntax
2910Sstevel@tonic-gate * "[filename] [-options]". If filename is specified, it is copied into the
2920Sstevel@tonic-gate * first buffer. (Otherwise, the buffer is left alone.) The rest of the string
2930Sstevel@tonic-gate * is copied into the second buffer.
2940Sstevel@tonic-gate */
2950Sstevel@tonic-gate static void
init_bootargs(char * fname_buf,int fname_buf_sz,char * bargs_buf,int bargs_buf_sz)2960Sstevel@tonic-gate init_bootargs(char *fname_buf, int fname_buf_sz, char *bargs_buf,
2970Sstevel@tonic-gate int bargs_buf_sz)
2980Sstevel@tonic-gate {
2990Sstevel@tonic-gate const char *tp = prom_bootargs();
3000Sstevel@tonic-gate
3010Sstevel@tonic-gate if (!tp || *tp == '\0') {
3020Sstevel@tonic-gate *bargs_buf = '\0';
3030Sstevel@tonic-gate return;
3040Sstevel@tonic-gate }
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate SKIP_WHITESPC(tp);
3070Sstevel@tonic-gate
3080Sstevel@tonic-gate /*
3090Sstevel@tonic-gate * If we don't have an option indicator, then we
3100Sstevel@tonic-gate * already have our filename prepended.
3110Sstevel@tonic-gate */
3120Sstevel@tonic-gate if (*tp && *tp != '-') {
3130Sstevel@tonic-gate int i;
3140Sstevel@tonic-gate
3150Sstevel@tonic-gate /*
3160Sstevel@tonic-gate * Copy the filename into fname_buf.
3170Sstevel@tonic-gate */
3180Sstevel@tonic-gate for (i = 0; i < fname_buf_sz && *tp && !ISSPACE(*tp); ++i)
3190Sstevel@tonic-gate *fname_buf++ = *tp++;
3200Sstevel@tonic-gate
3210Sstevel@tonic-gate if (i >= fname_buf_sz) {
3220Sstevel@tonic-gate printf("boot: boot filename too long!\n");
3230Sstevel@tonic-gate printf("boot halted.\n");
3240Sstevel@tonic-gate prom_enter_mon();
3250Sstevel@tonic-gate /*NOTREACHED*/
3260Sstevel@tonic-gate } else {
3270Sstevel@tonic-gate *fname_buf = '\0';
3280Sstevel@tonic-gate }
3290Sstevel@tonic-gate
3300Sstevel@tonic-gate SKIP_WHITESPC(tp);
3310Sstevel@tonic-gate }
3320Sstevel@tonic-gate
3330Sstevel@tonic-gate /* The rest of the line is the options. */
3340Sstevel@tonic-gate while (bargs_buf_sz > 1 && *tp) {
3350Sstevel@tonic-gate *bargs_buf++ = *tp++;
3360Sstevel@tonic-gate --bargs_buf_sz;
3370Sstevel@tonic-gate }
3380Sstevel@tonic-gate *bargs_buf = '\0';
3390Sstevel@tonic-gate
3400Sstevel@tonic-gate if (bargs_buf_sz == 1) {
3410Sstevel@tonic-gate printf("boot: boot arguments too long!\n");
3420Sstevel@tonic-gate printf("boot halted.\n");
3430Sstevel@tonic-gate prom_enter_mon();
3440Sstevel@tonic-gate /*NOTREACHED*/
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate }
3470Sstevel@tonic-gate
3480Sstevel@tonic-gate boolean_t
is_netdev(char * devpath)3490Sstevel@tonic-gate is_netdev(char *devpath)
3500Sstevel@tonic-gate {
351789Sahrens pnode_t node = prom_finddevice(devpath);
3520Sstevel@tonic-gate char *options;
3530Sstevel@tonic-gate
3540Sstevel@tonic-gate if ((node == OBP_NONODE) || (node == OBP_BADNODE))
3550Sstevel@tonic-gate return (B_FALSE);
3560Sstevel@tonic-gate if (prom_devicetype(node, "network") != 0)
3570Sstevel@tonic-gate return (B_TRUE);
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate /*
3600Sstevel@tonic-gate * For Infiniband, network device names will be of the
3610Sstevel@tonic-gate * format XXX/ib@0:port=1,pkey=1234,protocol=ip[,YYY] where
3620Sstevel@tonic-gate * XXX is typically /pci@8,700000/pci@1. The device_type
3630Sstevel@tonic-gate * property will be "ib".
3640Sstevel@tonic-gate */
3650Sstevel@tonic-gate if (prom_devicetype(node, "ib") != 0) {
3660Sstevel@tonic-gate options = prom_path_options(devpath);
3670Sstevel@tonic-gate if (options != NULL) {
3680Sstevel@tonic-gate
3690Sstevel@tonic-gate #define SEARCHSTRING ",protocol=ip"
3700Sstevel@tonic-gate #define SEARCHSTRLEN strlen(SEARCHSTRING)
3710Sstevel@tonic-gate
3720Sstevel@tonic-gate if (strstr(options, ",protocol=ip,") != NULL)
3730Sstevel@tonic-gate return (B_TRUE);
3740Sstevel@tonic-gate while ((options = strstr(options, SEARCHSTRING)) !=
3750Sstevel@tonic-gate NULL) {
3760Sstevel@tonic-gate char nextc;
3770Sstevel@tonic-gate
3780Sstevel@tonic-gate nextc = options[SEARCHSTRLEN];
3790Sstevel@tonic-gate if ((nextc == ',') || (nextc == 0))
3800Sstevel@tonic-gate return (B_TRUE);
3810Sstevel@tonic-gate options += SEARCHSTRLEN;
3820Sstevel@tonic-gate }
3830Sstevel@tonic-gate }
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate return (B_FALSE);
3860Sstevel@tonic-gate }
3870Sstevel@tonic-gate
3880Sstevel@tonic-gate /*
3890Sstevel@tonic-gate * Hook for modifying the OS boot path. This hook allows us to handle
3900Sstevel@tonic-gate * device arguments that the OS can't handle.
3910Sstevel@tonic-gate */
3920Sstevel@tonic-gate void
mangle_os_bootpath(char * bpath)3930Sstevel@tonic-gate mangle_os_bootpath(char *bpath)
3940Sstevel@tonic-gate {
395789Sahrens pnode_t node;
3960Sstevel@tonic-gate char *stripped_pathname;
3970Sstevel@tonic-gate
3980Sstevel@tonic-gate node = prom_finddevice(bpath);
3990Sstevel@tonic-gate if (prom_devicetype(node, "network") == 0)
4000Sstevel@tonic-gate return;
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate /*
4030Sstevel@tonic-gate * The OS can't handle network device arguments
4040Sstevel@tonic-gate * eg: boot net:promiscuous,speed=100,duplex=full
4050Sstevel@tonic-gate * So, we remove any argument strings in the device
4060Sstevel@tonic-gate * pathname we hand off to the OS for network devices.
4070Sstevel@tonic-gate *
4080Sstevel@tonic-gate * Internally, within boot, bpath is used to access
4090Sstevel@tonic-gate * the device, but v2path (as the boot property "boot-path")
4100Sstevel@tonic-gate * is the pathname passed to the OS.
4110Sstevel@tonic-gate */
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate stripped_pathname = kmem_alloc(OBP_MAXPATHLEN, 0);
4140Sstevel@tonic-gate prom_strip_options(bpath, stripped_pathname);
4150Sstevel@tonic-gate v2path = stripped_pathname;
4160Sstevel@tonic-gate }
4170Sstevel@tonic-gate
4180Sstevel@tonic-gate /*
4190Sstevel@tonic-gate * Given the boot path in the native firmware format use
4200Sstevel@tonic-gate * the redirection string to mutate the boot path to the new device.
4210Sstevel@tonic-gate * Fix up the 'v2path' so that it matches the new firmware path.
4220Sstevel@tonic-gate */
4230Sstevel@tonic-gate void
redirect_boot_path(char * bpath,char * redirect)4240Sstevel@tonic-gate redirect_boot_path(char *bpath, char *redirect)
4250Sstevel@tonic-gate {
4260Sstevel@tonic-gate char slicec = *redirect;
4270Sstevel@tonic-gate char *p = bpath + strlen(bpath);
4280Sstevel@tonic-gate
4290Sstevel@tonic-gate /*
4300Sstevel@tonic-gate * If the redirection character doesn't fall in this
4310Sstevel@tonic-gate * range, something went horribly wrong.
4320Sstevel@tonic-gate */
4330Sstevel@tonic-gate if (slicec < '0' || slicec > '7') {
4340Sstevel@tonic-gate printf("boot: bad redirection slice '%c'\n", slicec);
4350Sstevel@tonic-gate return;
4360Sstevel@tonic-gate }
4370Sstevel@tonic-gate
4380Sstevel@tonic-gate /*
4390Sstevel@tonic-gate * Handle fully qualified OpenBoot pathname.
4400Sstevel@tonic-gate */
4410Sstevel@tonic-gate while (--p >= bpath && *p != '@' && *p != '/')
4420Sstevel@tonic-gate if (*p == ':')
4430Sstevel@tonic-gate break;
4440Sstevel@tonic-gate if (*p++ == ':') {
4450Sstevel@tonic-gate /*
4460Sstevel@tonic-gate * Convert slice number to partition 'letter'.
4470Sstevel@tonic-gate */
4480Sstevel@tonic-gate *p++ = 'a' + slicec - '0';
4490Sstevel@tonic-gate *p = '\0';
4500Sstevel@tonic-gate v2path = bpath;
4510Sstevel@tonic-gate return;
4520Sstevel@tonic-gate }
4530Sstevel@tonic-gate prom_panic("redirect_boot_path: mangled boot path!");
4540Sstevel@tonic-gate }
4550Sstevel@tonic-gate
4560Sstevel@tonic-gate #define PROM_VERS_MAX_LEN 64
4570Sstevel@tonic-gate
4580Sstevel@tonic-gate void
system_check(void)4590Sstevel@tonic-gate system_check(void)
4600Sstevel@tonic-gate {
4610Sstevel@tonic-gate char buf[PROM_VERS_MAX_LEN];
462*11498SJerry.Gilliam@Sun.COM pnode_t n;
463*11498SJerry.Gilliam@Sun.COM char arch[128];
464*11498SJerry.Gilliam@Sun.COM size_t len;
465*11498SJerry.Gilliam@Sun.COM bootplat_defaults_t *plat_defaults;
4660Sstevel@tonic-gate
467*11498SJerry.Gilliam@Sun.COM /*
468*11498SJerry.Gilliam@Sun.COM * This is a sun4v machine iff the device_type property
469*11498SJerry.Gilliam@Sun.COM * exists on the root node and has the value "sun4v".
470*11498SJerry.Gilliam@Sun.COM * Some older sunfire proms do not have such a property.
471*11498SJerry.Gilliam@Sun.COM */
472*11498SJerry.Gilliam@Sun.COM is_sun4v = 0;
473*11498SJerry.Gilliam@Sun.COM n = prom_rootnode();
474*11498SJerry.Gilliam@Sun.COM len = prom_getproplen(n, "device_type");
475*11498SJerry.Gilliam@Sun.COM if (len > 0 && len < sizeof (arch)) {
476*11498SJerry.Gilliam@Sun.COM (void) prom_getprop(n, "device_type", arch);
477*11498SJerry.Gilliam@Sun.COM arch[len] = '\0';
478*11498SJerry.Gilliam@Sun.COM dprintf("device_type=%s\n", arch);
479*11498SJerry.Gilliam@Sun.COM if (strcmp(arch, "sun4v") == 0) {
480*11498SJerry.Gilliam@Sun.COM is_sun4v = 1;
481*11498SJerry.Gilliam@Sun.COM }
482*11498SJerry.Gilliam@Sun.COM } else {
483*11498SJerry.Gilliam@Sun.COM dprintf("device_type: no such property, len=%d\n", (int)len);
484*11498SJerry.Gilliam@Sun.COM }
485*11498SJerry.Gilliam@Sun.COM
486*11498SJerry.Gilliam@Sun.COM if (!is_sun4v && cpu_is_ultrasparc_1()) {
4870Sstevel@tonic-gate printf("UltraSPARC I processors are not supported by this "
4880Sstevel@tonic-gate "release of Solaris.\n");
4890Sstevel@tonic-gate prom_exit_to_mon();
4900Sstevel@tonic-gate }
4910Sstevel@tonic-gate
492*11498SJerry.Gilliam@Sun.COM /*
493*11498SJerry.Gilliam@Sun.COM * Set up defaults per platform
494*11498SJerry.Gilliam@Sun.COM */
495*11498SJerry.Gilliam@Sun.COM plat_defaults = (is_sun4v) ?
496*11498SJerry.Gilliam@Sun.COM &sun4v_plat_defaults : &sun4u_plat_defaults;
497*11498SJerry.Gilliam@Sun.COM
498*11498SJerry.Gilliam@Sun.COM default_name = plat_defaults->plat_defaults_name;
499*11498SJerry.Gilliam@Sun.COM default_path = plat_defaults->plat_defaults_path;
500*11498SJerry.Gilliam@Sun.COM vac = plat_defaults->plat_defaults_vac;
501*11498SJerry.Gilliam@Sun.COM
502*11498SJerry.Gilliam@Sun.COM dprintf("default_name: %s\n", default_name);
503*11498SJerry.Gilliam@Sun.COM dprintf("default_path: %s\n", default_path);
504*11498SJerry.Gilliam@Sun.COM dprintf("vac: %d\n", vac);
505*11498SJerry.Gilliam@Sun.COM
5060Sstevel@tonic-gate if (prom_version_check(buf, PROM_VERS_MAX_LEN, NULL) != PROM_VER64_OK) {
5070Sstevel@tonic-gate printf("The firmware on this system does not support the 64-bit"
5080Sstevel@tonic-gate " OS.\n\tPlease upgrade to at least the following version:"
5090Sstevel@tonic-gate "\n\n\t%s\n", buf);
5100Sstevel@tonic-gate prom_exit_to_mon();
5110Sstevel@tonic-gate }
5120Sstevel@tonic-gate }
5130Sstevel@tonic-gate
5140Sstevel@tonic-gate /*
5150Sstevel@tonic-gate * Reads in the standalone (client) program and jumps to it. If this
5160Sstevel@tonic-gate * attempt fails, prints "boot failed" and returns to its caller.
5170Sstevel@tonic-gate *
5180Sstevel@tonic-gate * It will try to determine if it is loading a Unix file by
5190Sstevel@tonic-gate * looking at what should be the magic number. If it makes
5200Sstevel@tonic-gate * sense, it will use it; otherwise it jumps to the first
5210Sstevel@tonic-gate * address of the blocks that it reads in.
5220Sstevel@tonic-gate *
5230Sstevel@tonic-gate * This new boot program will open a file, read the ELF header,
5240Sstevel@tonic-gate * attempt to allocate and map memory at the location at which
5250Sstevel@tonic-gate * the client desires to be linked, and load the program at
5260Sstevel@tonic-gate * that point. It will then jump there.
5270Sstevel@tonic-gate */
5280Sstevel@tonic-gate /*ARGSUSED*/
5290Sstevel@tonic-gate int
main(void * cookie,char ** argv,int argc)5300Sstevel@tonic-gate main(void *cookie, char **argv, int argc)
5310Sstevel@tonic-gate {
5320Sstevel@tonic-gate /*
5330Sstevel@tonic-gate * bpath is the boot device path buffer.
5340Sstevel@tonic-gate * bargs is the boot arguments buffer.
5350Sstevel@tonic-gate */
5360Sstevel@tonic-gate static char bpath[OBP_MAXPATHLEN], bargs[OBP_MAXPATHLEN];
5370Sstevel@tonic-gate boolean_t user_specified_filename;
5380Sstevel@tonic-gate
5390Sstevel@tonic-gate prom_init("boot", cookie);
5400Sstevel@tonic-gate fiximp();
5410Sstevel@tonic-gate
5420Sstevel@tonic-gate system_check();
5430Sstevel@tonic-gate
5440Sstevel@tonic-gate dprintf("\nboot: V%d /boot interface.\n", BO_VERSION);
5450Sstevel@tonic-gate #ifdef HALTBOOT
5460Sstevel@tonic-gate prom_enter_mon();
5470Sstevel@tonic-gate #endif /* HALTBOOT */
5480Sstevel@tonic-gate
5490Sstevel@tonic-gate init_memlists();
5500Sstevel@tonic-gate
5510Sstevel@tonic-gate #ifdef DEBUG_LISTS
5520Sstevel@tonic-gate dprintf("Physmem avail:\n");
5530Sstevel@tonic-gate if (debug) print_memlist(pfreelistp);
5540Sstevel@tonic-gate dprintf("Virtmem avail:\n");
5550Sstevel@tonic-gate if (debug) print_memlist(vfreelistp);
5560Sstevel@tonic-gate dprintf("Phys installed:\n");
5570Sstevel@tonic-gate if (debug) print_memlist(pinstalledp);
5580Sstevel@tonic-gate prom_enter_mon();
5590Sstevel@tonic-gate #endif /* DEBUG_LISTS */
5600Sstevel@tonic-gate
5610Sstevel@tonic-gate /*
5620Sstevel@tonic-gate * Initialize the default filename (exported as "default-name" and
5630Sstevel@tonic-gate * used by kadb).
5640Sstevel@tonic-gate */
5650Sstevel@tonic-gate set_default_filename(defname);
5660Sstevel@tonic-gate
5670Sstevel@tonic-gate /*
5680Sstevel@tonic-gate * Parse the arguments ASAP in case there are any flags which may
5690Sstevel@tonic-gate * affect execution.
5700Sstevel@tonic-gate */
5710Sstevel@tonic-gate
5720Sstevel@tonic-gate /*
5730Sstevel@tonic-gate * filename is the path to the standalone. Initialize it to the empty
5740Sstevel@tonic-gate * string so we can tell whether the user specified it in the
5750Sstevel@tonic-gate * arguments.
5760Sstevel@tonic-gate */
5770Sstevel@tonic-gate filename[0] = '\0';
5780Sstevel@tonic-gate
5790Sstevel@tonic-gate /*
5800Sstevel@tonic-gate * Fetch the boot arguments from the PROM and split the filename off
5810Sstevel@tonic-gate * if it's there.
5820Sstevel@tonic-gate */
5830Sstevel@tonic-gate init_bootargs(filename, sizeof (filename), bargs, sizeof (bargs));
5840Sstevel@tonic-gate
5850Sstevel@tonic-gate /*
5860Sstevel@tonic-gate * kadb was delivered as a standalone, and as such, people got used to
5870Sstevel@tonic-gate * typing `boot kadb'. kmdb isn't a standalone - it is loaded by krtld
5880Sstevel@tonic-gate * as just another kernel module. For compatibility, though, when we
5890Sstevel@tonic-gate * see an attempt to `boot kadb' or `boot kmdb', we'll transform that
5900Sstevel@tonic-gate * into a `boot -k' (or equivalent).
5910Sstevel@tonic-gate */
5920Sstevel@tonic-gate if (strcmp(filename, "kmdb") == 0 || strcmp(filename, "kadb") == 0) {
5930Sstevel@tonic-gate boothowto |= RB_KMDB;
5940Sstevel@tonic-gate *filename = '\0'; /* let boot figure out which unix to use */
5950Sstevel@tonic-gate }
5960Sstevel@tonic-gate
5970Sstevel@tonic-gate bootflags(bargs, sizeof (bargs));
5980Sstevel@tonic-gate
5990Sstevel@tonic-gate user_specified_filename = (filename[0] != '\0');
6000Sstevel@tonic-gate
6010Sstevel@tonic-gate /* Fetch the boot path from the PROM. */
6020Sstevel@tonic-gate (void) strncpy(bpath, prom_bootpath(), sizeof (bpath) - 1);
6030Sstevel@tonic-gate bpath[sizeof (bpath) - 1] = '\0';
6040Sstevel@tonic-gate
605*11498SJerry.Gilliam@Sun.COM dprintf("arch: %s\n", is_sun4v ? "sun4v" : "sun4u");
6060Sstevel@tonic-gate dprintf("bootpath: 0x%p %s\n", (void *)bpath, bpath);
6070Sstevel@tonic-gate dprintf("bootargs: 0x%p %s\n", (void *)bargs, bargs);
6080Sstevel@tonic-gate dprintf("filename: 0x%p %s\n", (void *)filename, filename);
6090Sstevel@tonic-gate dprintf("kernname: 0x%p %s\n", (void *)kernname, kernname);
6100Sstevel@tonic-gate
6110Sstevel@tonic-gate /*
6120Sstevel@tonic-gate * *v2path will be exported to the standalone as the boot-path boot
6130Sstevel@tonic-gate * property.
6140Sstevel@tonic-gate */
6150Sstevel@tonic-gate v2path = bpath;
6160Sstevel@tonic-gate
6170Sstevel@tonic-gate /*
6180Sstevel@tonic-gate * Our memory lists should be "up" by this time
6190Sstevel@tonic-gate */
6200Sstevel@tonic-gate
6210Sstevel@tonic-gate setup_bootops();
6220Sstevel@tonic-gate
6230Sstevel@tonic-gate /*
6240Sstevel@tonic-gate * If bpath is a network card, set v2path to a copy of bpath with the
6250Sstevel@tonic-gate * options stripped off.
6260Sstevel@tonic-gate */
6270Sstevel@tonic-gate mangle_os_bootpath(bpath);
6280Sstevel@tonic-gate
629*11498SJerry.Gilliam@Sun.COM /*
630*11498SJerry.Gilliam@Sun.COM * Not necessary on sun4v as nvram is virtual
631*11498SJerry.Gilliam@Sun.COM * and kept by the guest manager on the SP.
632*11498SJerry.Gilliam@Sun.COM */
633*11498SJerry.Gilliam@Sun.COM if (!is_sun4v) {
634*11498SJerry.Gilliam@Sun.COM retain_nvram_page();
635*11498SJerry.Gilliam@Sun.COM }
6360Sstevel@tonic-gate
6370Sstevel@tonic-gate if (bootprog(bpath, bargs, user_specified_filename) == 0) {
6380Sstevel@tonic-gate post_mountroot(filename, NULL);
6390Sstevel@tonic-gate /*NOTREACHED*/
6400Sstevel@tonic-gate }
6410Sstevel@tonic-gate
6420Sstevel@tonic-gate return (0);
6430Sstevel@tonic-gate }
644