986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje/*
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * CDDL HEADER START
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje *
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * The contents of this file are subject to the terms of the
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * Common Development and Distribution License (the "License").
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * You may not use this file except in compliance with the License.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje *
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * or http://www.opensolaris.org/os/licensing.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * See the License for the specific language governing permissions
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * and limitations under the License.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje *
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * When distributing Covered Code, include this CDDL HEADER in each
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * If applicable, add the following below this CDDL HEADER, with the
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * fields enclosed by brackets "[]" replaced with your own identifying
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * information: Portions Copyright [yyyy] [name of copyright owner]
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje *
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * CDDL HEADER END
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje */
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje/*
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * Use is subject to license terms.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje */
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/types.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/param.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/fcntl.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/obpdefs.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/reboot.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/promif.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/stat.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/bootvfs.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/platnames.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/salib.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/elf.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/link.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/auxv.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/boot_policy.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/boot_redirect.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/bootconf.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include <sys/boot.h>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include "boot_plat.h"
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#include "ramdisk.h"
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#define SUCCESS 0
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#define FAILURE -1
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#ifdef DEBUG
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjeextern int debug = 0;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#else
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjestatic const int debug = 0;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#endif
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje#define dprintf if (debug) printf
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjechar *def_boot_archive = "boot_archive";
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjechar *def_miniroot = "miniroot";
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjeextern char cmd_line_boot_archive[];
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjeextern int openfile(char *filename);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjestatic int
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjeread_and_boot_ramdisk(int fd)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje{
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje struct stat st;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje caddr_t virt;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje size_t size;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje extern ssize_t xread(int, char *, size_t);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if ((fstat(fd, &st) != 0) ||
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje ((virt = create_ramdisk(RD_ROOTFS, st.st_size, NULL)) == NULL))
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje return (-1);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dprintf("reading boot archive ...\n");
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if ((size = xread(fd, (char *)virt, st.st_size)) != st.st_size) {
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje (void) printf("Error reading boot archive, bytes read = %ld, "
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje "filesize = %ld\n", (long)size, (long)st.st_size);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje destroy_ramdisk(RD_ROOTFS);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje return (-1);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje }
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje boot_ramdisk(RD_ROOTFS);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje /* NOT REACHED */
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje return (0); /* to make cc happy */
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje}
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjestatic void
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjepost_mountroot_nfs(void)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje{
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje int fd;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje char *fn;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje char tmpname[MAXPATHLEN];
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje for (;;) {
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fn = NULL;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if (boothowto & RB_ASKNAME) {
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India char ctmpname[MAXPATHLEN];
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fn = (cmd_line_boot_archive[0] != '\0') ?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje cmd_line_boot_archive : def_boot_archive;
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /* Avoid buffer overrun */
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) strncpy(tmpname, fn, strlen(fn)+1);
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India fn = tmpname;
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje printf("Enter filename [%s]: ", fn);
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) cons_gets(ctmpname, sizeof (ctmpname));
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India if (ctmpname[0] != '\0') {
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) strncpy(tmpname, ctmpname,
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India strlen(ctmpname)+1);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fn = tmpname;
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India }
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje }
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if (boothowto & RB_HALT) {
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje printf("Boot halted.\n");
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje prom_enter_mon();
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje }
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India if (fn != NULL) {
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fd = openfile(fn);
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India } else if (cmd_line_boot_archive[0] != '\0') {
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) strncpy(tmpname, cmd_line_boot_archive,
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India strlen(cmd_line_boot_archive)+1);
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India fn = tmpname;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fd = openfile(fn);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje } else {
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) strncpy(tmpname, def_boot_archive,
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India strlen(def_boot_archive)+1);
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India fn = tmpname;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if ((fd = openfile(fn)) == FAILURE) {
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) strncpy(tmpname, def_miniroot,
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India strlen(def_miniroot)+1);
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India fn = tmpname;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fd = openfile(fn);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje }
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje }
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India if (fn != tmpname || tmpname[0] == '\0') {
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India printf("Possible buffer overrun, "
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India "entering boot prompt\n");
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India prom_enter_mon();
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India }
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if (fd == FAILURE) {
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India if (strncmp(fn, def_miniroot,
75e04b8fa133ad94dc80199131b8ec3e2729bdafphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India strlen(def_miniroot)+1) != 0)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje printf("cannot open %s\n", fn);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje else
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje printf("cannot open neither %s nor %s\n",
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje def_boot_archive, def_miniroot);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje } else {
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje /*
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * this function does not return if successful.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje */
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje (void) read_and_boot_ramdisk(fd);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje printf("boot failed\n");
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje (void) close(fd);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje }
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje boothowto |= RB_ASKNAME;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje }
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje}
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje/*
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * bpath is the boot device path buffer.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * bargs is the boot arguments buffer.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje */
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje/*ARGSUSED*/
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjeint
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjebootprog(char *bpath, char *bargs, boolean_t user_specified_filename)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje{
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje systype = set_fstype(v2path, bpath);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if (verbosemode) {
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje printf("device path '%s'\n", bpath);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if (strcmp(bpath, v2path) != 0)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje printf("client path '%s'\n", v2path);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje }
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if (mountroot(bpath) != SUCCESS)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje prom_panic("Could not mount filesystem.");
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje /*
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * kernname (default-name) might have changed if mountroot() called
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje * boot_nfs_mountroot(), and it called set_default_filename().
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje */
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if (!user_specified_filename)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje (void) strcpy(filename, kernname);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if (verbosemode)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje printf("standalone = `%s', args = `%s'\n", filename, bargs);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje set_client_bootargs(filename, bargs);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje post_mountroot_nfs();
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje return (1);
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje}