bootadm_upgrade.c revision 630270564f9cfe09ebbccb748c7dc1d897e14135
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2014 Toomas Soome <tsoome@me.com>
*/
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <fcntl.h>
#include <strings.h>
#include <sys/multiboot.h>
#include "message.h"
#include "bootadm.h"
static void
get_findroot_cap(const char *osroot)
{
char buf[BAM_MAXLINE];
int dboot;
int error;
int ret;
const char *fcn = "get_findroot_cap()";
osroot, "boot/grub/capability");
return;
}
return;
}
dboot = 0;
}
dboot = 1;
}
}
if (bam_is_findroot == BAM_FINDROOT_UNKNOWN) {
}
out:
if (ret != 0) {
}
}
get_boot_cap(const char *osroot)
{
char *image;
uchar_t *ident;
int fd;
int m;
int error;
const char *fcn = "get_boot_cap()";
if (is_sparc()) {
/* there is no non dboot sparc new-boot */
return (BAM_SUCCESS);
}
if (fd < 0) {
return (BAM_ERROR);
}
/*
* Verify that this is a sane unix at least 8192 bytes in length
*/
return (BAM_ERROR);
}
/*
* mmap the first 8K
*/
if (image == MAP_FAILED) {
return (BAM_ERROR);
}
return (BAM_ERROR);
}
if (ident[EI_CLASS] != ELFCLASS32) {
return (BAM_ERROR);
}
/*
* The GRUB multiboot header must be 32-bit aligned and completely
* contained in the 1st 8K of the file. If the unix binary has
* a multiboot header, then it is a 'dboot' kernel. Otherwise,
* this kernel must be booted via multiboot -- we call this a
* 'multiboot' kernel.
*/
break;
}
}
if (bam_direct == BAM_DIRECT_DBOOT) {
if (bam_is_hv == BAM_HV_PRESENT) {
} else {
}
} else {
}
/* Not a fatal error if this fails */
return (BAM_SUCCESS);
}
#define INST_RELEASE "var/sadm/system/admin/INST_RELEASE"
/*
* Return true if root has been bfu'ed. bfu will blow away
* var/sadm/system/admin/INST_RELEASE, so if it's still there, we can
* assume the system has not been bfu'ed.
*/
static int
is_bfu_system(const char *root)
{
static int is_bfu = -1;
const char *fcn = "is_bfu_system()";
if (is_bfu != -1) {
return (is_bfu);
}
is_bfu = 1;
} else {
is_bfu = 0;
}
return (is_bfu);
}
/*
* Simply allocate a new line and copy in cmd + sep + arg
*/
void
{
const char *fcn = "update_line()";
}
static char *
skip_wspace(char *ptr)
{
const char *fcn = "skip_wspace()";
return (NULL);
}
(*ptr != '\n'))
break;
}
return (ptr);
}
static char *
{
const char *fcn = "rskip_bspace()";
break;
}
return (ptr);
}
/*
* The parse_kernel_line function examines a menu.lst kernel line. For
* multiboot, this is:
*
* kernel <multiboot path> <flags1> <kernel path> <flags2>
*
*
* <kernel path> may be missing, or may be any full or relative path to unix.
* We check for it by looking for a word ending in "/unix". If it ends
* it's a custom kernel, and we skip it.
*
* <flags*> are anything that doesn't fit either of the above - these will be
* copied over.
*
* For direct boot, the defaults are
*
* kernel$ <kernel path> <flags>
*
* <kernel path> is one of:
*
* If <kernel path> is any of the last four, the command may also be "kernel".
*
* <flags> is anything that isn't <kernel path>.
*
* This function is only called to convert a multiboot entry to a dboot entry
*
* For safety, we do one more check: if the kernel path starts with /boot,
* we verify that the new kernel exists before changing it. This is mainly
* done for bfu, as it may cause the failsafe archives to be a different
* boot architecture from the newly bfu'ed system.
*/
static error_t
{
char *old_ptr;
char *unix_ptr;
char *flags1_ptr;
char *flags2_ptr;
const char *fcn = "cvt_kernel_line()";
/*
* We only convert multiboot to dboot and nothing else.
*/
return (BAM_SUCCESS);
}
/*
* We're attempting to change failsafe to dboot.
* In the bfu case, we may not have a dboot failsafe
* kernel i.e. a "unix" under the "/boot" hierarchy.
* If so, just emit a message in verbose mode and
* return success.
*/
if (bam_verbose) {
}
return (BAM_SUCCESS);
}
}
/*
* Make sure we have the correct cmd
*/
/*
* only multiboot and nothing else
* i.e. flags1 = unix = flags2 = NULL
*/
goto create;
}
/*
*
* old_ptr is either at "flags1" or "unix"
*/
/*
* There is a unix.
*/
/* See if there's a flags2 past unix */
if (flags2_ptr) {
} else {
}
/* see if there is a flags1 before unix */
flags1_ptr = NULL;
} else {
*unix_ptr = '\0';
unix_ptr++;
}
} else {
/* There is no unix, there is only a bunch of flags */
}
/*
* With dboot, unix is fixed and is at the beginning. We need to
* migrate flags1 and flags2
*/
} else {
}
if (flags1_ptr != NULL) {
}
if (flags2_ptr != NULL) {
}
return (BAM_SUCCESS);
}
/*
* Similar to above, except this time we're looking at a module line,
* which is quite a bit simpler.
*
* Under multiboot, the archive line is:
*
* module /platform/i86pc/boot_archive
*
* Under directboot, the archive line is:
*
* module$ /platform/i86pc/$ISADIR/boot_archive
*
* which may be specified exactly as either of:
*
* module /platform/i86pc/boot_archive
* module /platform/i86pc/amd64/boot_archive
*
* Under multiboot, the failsafe is:
*
* module /boot/x86.miniroot-safe
*
* Under dboot, the failsafe is:
*
* module$ /boot/$ISADIR/x86.miniroot-safe
*
* which may be specified exactly as either of:
*
* module /boot/x86.miniroot-safe
* module /boot/amd64/x86.miniroot-safe
*/
static error_t
{
const char *fcn = "cvt_module_line()";
/*
* We only convert multiboot to dboot and nothing else
*/
return (BAM_SUCCESS);
}
return (BAM_SUCCESS);
}
return (BAM_MSG);
}
return (BAM_SUCCESS);
}
static void
{
int hand_num;
int hand_max;
int *hand_list;
int i;
const char *fcn = "bam_warn_hand_entries()";
if (bam_force) {
/*
* No warning needed, we are automatically converting
* the "hand" entries
*/
return;
}
hand_num = 0;
continue;
hand_max *= 2;
hand_max * sizeof (int));
}
}
"s" : "");
for (i = 0; i < hand_num; i++) {
}
bam_print_stderr("\n");
}
static entry_t *
char *grubsign,
char *grubroot,
int root_opt)
{
char opt[10];
const char *fcn = "find_matching_entry()";
!bam_force) {
continue;
}
break;
} else {
continue;
}
}
return (entry);
}
break;
}
}
break;
} else {
continue;
}
}
return (entry);
}
break;
}
}
} else if (root_opt) {
/* Neither root nor findroot */
return (entry);
}
}
return (NULL);
}
/*
* The following is a set of routines that attempt to convert the
* menu entries for the supplied osroot into a format compatible
* with the GRUB installation on osroot.
*
* Each of these conversion routines make no assumptions about
* the current state of the menu entry, it does its best to
* convert the menu entry to the new state. In the process
* we may either upgrade or downgrade.
*
* We don't make any heroic efforts at conversion. It is better
* to be conservative and bail out at the first sign of error. We will
* in such cases, point the user at the knowledge-base article
* so that they can upgrade manually.
*/
static error_t
{
int update_num;
const char *fcn = "bam_add_findroot()";
update_num = 0;
/* already converted */
continue;
}
break;
} else {
continue;
}
}
update_num = 1;
}
}
break;
}
}
}
if (update_num) {
}
return (BAM_SUCCESS);
}
static error_t
{
const char *fcn = "bam_add_hv()";
return (BAM_SUCCESS);
}
}
return (BAM_SUCCESS);
}
static error_t
char *osroot,
char *grubsign,
char *grubroot,
int root_opt)
{
int msg = 0;
const char *fcn = "bam_add_dboot()";
break;
} else {
continue;
}
}
/*
* If we have a kernel$ command, assume it
* is dboot already. If it is not a dboot
* entry, something funny is going on and
* we will leave it alone
*/
INJECT_ERROR1("ADD_DBOOT_KERN_ERR",
INJECT_ERROR1("ADD_DBOOT_KERN_MSG",
return (ret);
msg = 1;
}
}
INJECT_ERROR1("ADD_DBOOT_MOD_ERR",
INJECT_ERROR1("ADD_DBOOT_MOD_MSG",
return (ret);
msg = 1;
}
}
break;
}
}
}
return (ret);
}
/*ARGSUSED*/
{
char *osdev;
char *grubsign;
char *grubroot;
int ret1;
int ret2;
int ret3;
const char *fcn = "upgrade_menu()";
/*
* We only support upgrades. Xen may not be present
* on smaller metaclusters so we don't check for that.
*/
if (bam_is_findroot != BAM_FINDROOT_PRESENT ||
bam_direct != BAM_DIRECT_DBOOT) {
return (BAM_ERROR);
}
/*
* First get the GRUB signature
*/
return (BAM_ERROR);
}
return (BAM_ERROR);
}
/* not fatal if we can't get grubroot */
goto abort;
if (bam_is_hv == BAM_HV_PRESENT) {
goto abort;
} else
ret2 = BAM_SUCCESS;
goto abort;
} else {
}
return (BAM_WRITE);
return (BAM_ERROR);
}