boot2.c revision 199767f8919635c4928607450d9e0abb932109ce
/*-
* Copyright (c) 2008 John Hay
* Copyright (c) 2006 M Warner Losh <imp@freebsd.org>
* Copyright (c) 1998 Robert Nordier
* All rights reserved.
*
* Redistribution and use in source and binary forms are freely
* permitted provided that the above copyright notice and this
* paragraph and the following disclaimer are duplicated in all
* such forms.
*
* This software is provided "AS IS" and without any express or
* implied warranties, including, without limitation, the implied
* warranties of merchantability and fitness for a particular
* purpose.
*/
__FBSDID("$FreeBSD$");
#include <sys/disklabel.h>
#include <stdarg.h>
#include "lib.h"
#include "board.h"
#include "paths.h"
#include "rbx.h"
#define PATH_KERNEL "/boot/kernel/kernel.gz.tramp"
#define NOPT 6
};
unsigned board_id; /* board type to pass to kernel, if set by board_* code */
unsigned dsk_start;
static char cmd[512];
static char kname[1024];
int main(void);
static void load(void);
static int parse(void);
static int dskread(void *, unsigned, unsigned);
#ifdef FIXUP_BOOT_DRV
static void fixup_boot_drv(caddr_t, int, int, int);
#endif
#define UFS_SMALL_CGBASE
#include "ufsread.c"
#ifdef DEBUG
#else
#endif
static inline int
{
return -1;
return 0;
}
static inline void
getstr(int c)
{
char *s;
s = cmd;
if (c == 0)
c = getc(10000);
for (;;) {
switch (c) {
case 0:
break;
case '\177':
case '\b':
if (s > cmd) {
s--;
printf("\b \b");
}
break;
case '\n':
case '\r':
*s = 0;
return;
default:
*s++ = c;
xputchar(c);
}
c = getc(10000);
}
}
int
main(void)
{
int autoboot, c = 0;
board_init();
autoboot = 1;
/* Process configuration file */
if (*cmd) {
if (parse())
autoboot = 0;
/* Do not process this command twice */
*cmd = 0;
}
if (*kname == '\0')
/* Present the user with the boot2 prompt. */
for (;;) {
if (!autoboot ||
getstr(c);
xputchar('\n');
autoboot = 0;
c = 0;
if (parse())
xputchar('\a');
else
load();
}
return (1);
}
static void
load(void)
{
caddr_t p;
int i, j;
#ifdef FIXUP_BOOT_DRV
int klen;
klen = 0;
#endif
if (!ls)
return;
}
return;
return;
}
return;
j++;
}
for (i = 0; i < 2; i++) {
#ifdef FIXUP_BOOT_DRV
staddr = p;
#endif
return;
}
#ifdef FIXUP_BOOT_DRV
#endif
}
static int
parse()
{
char *ep, *p;
int c, i;
while ((c = *arg++)) {
if (c == ' ' || c == '\t' || c == '\n')
continue;
ep = p;
if (*p)
*p++ = 0;
if (c == '-') {
while ((c = *arg++)) {
for (i = 0; c != optstr[i]; i++)
if (i == NOPT - 1)
return -1;
}
} else {
arg--;
return -1;
}
}
arg = p;
}
return 0;
}
static int
{
struct dos_partition *dp;
struct disklabel *d;
char *sec;
int i;
if (!dsk_meta) {
dsk_start = 0;
return -1;
for (i = 0; i < NDOSPART; i++) {
break;
}
if (i == NDOSPART)
return -1;
/*
* Although dp_start is aligned within the disk
* partition structure, DOSPARTOFF is 446, which is
* only word (2) aligned, not longword (4) aligned.
* Cope by using memcpy to fetch the start of this
* partition.
*/
return -1;
d = (void *)(sec + LABELOFFSET);
return -1;
}
if (!d->d_partitions[0].p_size) {
return -1;
}
dsk_meta++;
}
}
#ifdef FIXUP_BOOT_DRV
/*
* fixup_boot_drv() will try to find the ROOTDEVNAME spec in the kernel
* and change it to what was specified on the comandline or /boot.conf
* file or to what was encountered on the disk. It will try to handle 3
* different disk layouts, raw (dangerously dedicated), slice only and
* slice + partition. It will look for the following strings in the
* kernel, but if it is one of the first three, the string in the kernel
* must use the correct form to match the actual disk layout:
* - ufs:ad0a
* - ufs:ad0s1
* - ufs:ad0s1a
* - ufs:ROOTDEVNAME
* In the case of the first three strings, only the "a" at the end and
* the "1" after the "s" will be modified, if they exist. The string
* length will not be changed. In the case of the last string, the
* whole string will be built up and nul, '\0' terminated.
*/
static void
{
DPRINTF("fixup_boot_drv: 0x%x, %d, slice %d, partition %d\n",
if (bs > 4)
return;
if (bp > 7)
return;
p[0] = 'a'; p[1] = 'd'; p[2] = '0'; /* ad0 */
p += 3;
if (bs > 0) {
/* append slice */
*p++ = 's';
*p++ = bs + '0';
}
if (disk_layout != DL_SLICE) {
/* append partition */
*p++ = bp + 'a';
}
*p = '\0';
} else {
if (*p == 's') {
/* fix slice */
p++;
*p++ = bs + '0';
}
if (*p == 'a')
*p = bp + 'a';
}
}
printf("Could not locate \"%s\" to fix kernel boot device, "
"check ROOTDEVNAME is set\n", op);
return;
}
}
#endif