bootadm_upgrade.c revision 843e19887f64dde75055cf8842fc4db2171eff45
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#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"
dboot_or_multiboot(const char *root)
{
char *image;
uchar_t *ident;
int fd, m;
if (fd < 0) {
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) {
} else {
}
}
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;
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
{
}
/*
* 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 three, the command may also be "kernel".
*
* <flags> is anything that isn't <kernel path>.
*
* This function is only called if it applies to our target boot environment.
* If we can't make any sense of the kernel line, an error is printed and
* BAM_ERROR is returned.
*
* The desired install type is given in the global variable bam_direct.
* If the kernel line is of a different install type, we change it to the
* preferred type. If the kernel line is already of the correct install
* type, we do nothing. Either way, BAM_SUCCESS is returned.
*
* 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
{
/* Used when changing a multiboot line to dboot */
/*
* Note that BAM_ENTRY_DBOOT refers to the entry we're looking at, not
* necessarily the system type.
*/
sizeof (DIRECT_BOOT_32) - 1) == 0) {
sizeof (DIRECT_BOOT_KERNEL) - 1) == 0) ||
sizeof (DIRECT_BOOT_64) - 1) == 0) ||
sizeof (DIRECT_BOOT_FAILSAFE_KERNEL) - 1) == 0)) {
*flags |= BAM_ENTRY_DBOOT;
sizeof (MULTI_BOOT) - 1) == 0) ||
sizeof (MULTI_BOOT_FAILSAFE) - 1) == 0)) {
*flags &= ~BAM_ENTRY_DBOOT;
} else {
return (BAM_ERROR);
}
(((*flags & BAM_ENTRY_DBOOT) == 0) &&
(bam_direct == BAM_DIRECT_MULTIBOOT))) {
/* No action needed */
return (BAM_SUCCESS);
}
if (*flags & BAM_ENTRY_MINIROOT) {
/*
* We're changing boot architectures - make sure
* the multiboot failsafe still exists.
*/
if (bam_verbose) {
}
return (BAM_SUCCESS);
}
}
/*
* Make sure we have the correct cmd - either kernel or kernel$
* The failsafe entry should always be KERNEL_CMD.
*/
/*
* Since all arguments are copied, the new arg string should be close
* in size to the old one. Just add 32 to cover the difference in
* the boot path.
*/
old_ptr++;
/*
* Transitioning from dboot to multiboot is pretty simple. We
* copy in multiboot and any args.
*/
if (bam_direct == BAM_DIRECT_MULTIBOOT) {
(*flags & BAM_ENTRY_MINIROOT) ?
} else {
(*flags & BAM_ENTRY_MINIROOT) ?
}
goto done;
}
/*
* Transitioning from multiboot to directboot is a bit more
* complicated, since we may have two sets of arguments to
* copy and a unix path to parse.
*
* First, figure out if there's a unix path.
*/
/* See if there's anything past unix */
if (*flags2_ptr == '\0') {
flags2_ptr = NULL;
}
unix_ptr--;
flags1_ptr = NULL;
} else {
}
*flags |= BAM_ENTRY_32BIT;
(!bam_force)) {
/*
* If the above strstr returns NULL, but bam_force is
* set, we'll be upgrading an Install kernel. The
* result probably won't be what was intended, but we'll
* try it anyways.
*/
return (BAM_SKIP);
}
flags2_ptr = NULL;
} else {
}
if (*flags & BAM_ENTRY_MINIROOT) {
} else if (*flags & BAM_ENTRY_32BIT) {
} else {
}
/*
* We now want to copy flags1_ptr through unix_ptr, and
* flags2_ptr through the end of the string
*/
if (flags1_ptr != NULL) {
}
if (flags2_ptr != NULL) {
}
done:
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
*
* For either dboot or multiboot, the failsafe is:
*
* module /boot/x86.miniroot-safe
*/
static error_t
{
int len;
char *new;
/*
* If necessary, BAM_ENTRY_MINIROOT was already set in flags
* in upgrade_menu(). We re-check BAM_ENTRY_DBOOT here in here
* in case the kernel and module lines differ.
*/
flags |= BAM_ENTRY_DBOOT;
flags &= ~BAM_ENTRY_DBOOT;
} else {
return (BAM_ERROR);
}
(((flags & BAM_ENTRY_DBOOT) == 0) &&
(bam_direct == BAM_DIRECT_MULTIBOOT)) ||
((flags & BAM_ENTRY_MINIROOT) &&
/* No action needed */
return (BAM_SUCCESS);
}
/*
* Make sure we have the correct cmd - either module or module$
* The failsafe entry should always be MODULE_CMD.
*/
if (flags & BAM_ENTRY_MINIROOT) {
} else if ((bam_direct == BAM_DIRECT_DBOOT) &&
((flags & BAM_ENTRY_32BIT) == 0)) {
} else {
}
return (BAM_SUCCESS);
}
/*ARGSUSED*/
{
int *hand_entries = NULL;
if (rootdev) {
}
/* Loop through all OS entries in the menu.lst file */
continue;
/*
* We only change entries added by bootadm and live upgrade,
* and warn on the rest, unless the -f flag was passed.
*/
!bam_force) {
if (num_entries == 0) {
} else {
(num_entries + 1) * sizeof (int));
}
continue;
}
found_hv = 1;
continue;
}
/*
* We make two loops through the lines. First, we check if
* there is a root entry, and if so, whether we should be
* checking this entry.
*/
continue;
grubdisk) != 0) {
/* A different slice */
skipit = 1;
}
break;
}
break;
}
}
if (skipit)
continue;
/*
* We only compare for the length of KERNEL_CMD,
* so that KERNEL_DOLLAR_CMD will also match.
*/
break;
} else if (rv != BAM_SUCCESS) {
return (rv);
}
if (rv != BAM_SUCCESS) {
return (rv);
}
}
break;
}
}
/*
* If we're upgrading to a virtualized kernel and there are no
* hv entries in menu.lst, we need to add one.
*/
}
/*
* We only want to output one error, to avoid confusing a user. We
* rank "No kernels changed" as a higher priority than "will not
* update hand-added entries", since the former implies the latter.
*/
if (found_kernel == B_FALSE) {
return (BAM_ERROR);
} else if (num_entries > 0) {
"s" : "");
for (i = 0; i < num_entries; i++) {
}
bam_print_stderr("\n");
}
return (BAM_WRITE);
}