Allow md_root_setconf() to set in a miniroot as the root file system

even if MEMORY_DISK_IS_ROOT is not defined (a runtime override).
This commit is contained in:
ad 2008-05-02 13:02:31 +00:00
parent 3f1b4f1759
commit 1253c2cad4
3 changed files with 50 additions and 53 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.h,v 1.8 2007/03/04 06:01:42 christos Exp $ */ /* $NetBSD: md.h,v 1.9 2008/05/02 13:02:31 ad Exp $ */
/* /*
* Copyright (c) 1995 Gordon W. Ross * Copyright (c) 1995 Gordon W. Ross
@ -87,7 +87,7 @@ struct md_conf {
*/ */
extern void md_attach_hook(int, struct md_conf *); extern void md_attach_hook(int, struct md_conf *);
extern void md_open_hook(int, struct md_conf *); extern void md_open_hook(int, struct md_conf *);
#ifdef MEMORY_DISK_DYNAMIC
extern void md_root_setconf(char *, size_t); extern void md_root_setconf(char *, size_t);
#endif
extern int md_is_root;
#endif /* _KERNEL */ #endif /* _KERNEL */

View File

@ -1,4 +1,4 @@
/* $NetBSD: md_root.c,v 1.14 2008/04/28 20:23:47 martin Exp $ */ /* $NetBSD: md_root.c,v 1.15 2008/05/02 13:02:31 ad Exp $ */
/*- /*-
* Copyright (c) 1996 The NetBSD Foundation, Inc. * Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: md_root.c,v 1.14 2008/04/28 20:23:47 martin Exp $"); __KERNEL_RCSID(0, "$NetBSD: md_root.c,v 1.15 2008/05/02 13:02:31 ad Exp $");
#include "opt_md.h" #include "opt_md.h"
@ -83,6 +83,7 @@ char md_root_image[ROOTBYTES] = "|This is the root ramdisk!\n";
void void
md_root_setconf(char *addr, size_t size) md_root_setconf(char *addr, size_t size)
{ {
md_is_root = 1;
md_root_image = addr; md_root_image = addr;
md_root_size = size; md_root_size = size;
} }
@ -96,13 +97,13 @@ md_attach_hook(int unit, struct md_conf *md)
{ {
char pbuf[9]; char pbuf[9];
if (unit == 0) { if (unit == 0 && md_is_root) {
/* Setup root ramdisk */ /* Setup root ramdisk */
md->md_addr = (void *)md_root_image; md->md_addr = (void *)md_root_image;
md->md_size = (size_t)md_root_size; md->md_size = (size_t)md_root_size;
md->md_type = MD_KMEM_FIXED; md->md_type = MD_KMEM_FIXED;
format_bytes(pbuf, sizeof(pbuf), md->md_size); format_bytes(pbuf, sizeof(pbuf), md->md_size);
aprint_normal("md%d: internal %s image area\n", unit, pbuf); aprint_verbose("md%d: internal %s image area\n", unit, pbuf);
} }
} }
@ -113,7 +114,7 @@ void
md_open_hook(int unit, struct md_conf *md) md_open_hook(int unit, struct md_conf *md)
{ {
if (unit == 0) { if (unit == 0 && md_is_root) {
/* The root ramdisk only works single-user. */ /* The root ramdisk only works single-user. */
boothowto |= MEMORY_RBFLAGS; boothowto |= MEMORY_RBFLAGS;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_subr.c,v 1.186 2008/04/28 20:24:03 martin Exp $ */ /* $NetBSD: kern_subr.c,v 1.187 2008/05/02 13:02:31 ad Exp $ */
/*- /*-
* Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008 The NetBSD Foundation, Inc. * Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@ -79,7 +79,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.186 2008/04/28 20:24:03 martin Exp $"); __KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.187 2008/05/02 13:02:31 ad Exp $");
#include "opt_ddb.h" #include "opt_ddb.h"
#include "opt_md.h" #include "opt_md.h"
@ -723,17 +723,16 @@ isswap(struct device *dv)
*/ */
#include "md.h" #include "md.h"
#if NMD == 0
#undef MEMORY_DISK_HOOKS
#endif
#ifdef MEMORY_DISK_HOOKS #if NMD > 0
static struct device fakemdrootdev[NMD]; static struct device fakemdrootdev[NMD];
extern struct cfdriver md_cd; extern struct cfdriver md_cd;
#endif #endif
#ifdef MEMORY_DISK_IS_ROOT #ifdef MEMORY_DISK_IS_ROOT
#define BOOT_FROM_MEMORY_HOOKS 1 int md_is_root = 1;
#else
int md_is_root = 0;
#endif #endif
/* /*
@ -757,9 +756,6 @@ setroot(struct device *bootdv, int bootpartition)
{ {
struct device *dv; struct device *dv;
int len, majdev; int len, majdev;
#ifdef MEMORY_DISK_HOOKS
int i;
#endif
dev_t nrootdev; dev_t nrootdev;
dev_t ndumpdev = NODEV; dev_t ndumpdev = NODEV;
char buf[128]; char buf[128];
@ -776,21 +772,21 @@ setroot(struct device *bootdv, int bootpartition)
boothowto |= RB_ASKNAME; boothowto |= RB_ASKNAME;
#endif #endif
#ifdef MEMORY_DISK_HOOKS #if NMD > 0
for (i = 0; i < NMD; i++) { if (md_is_root) {
fakemdrootdev[i].dv_class = DV_DISK; int i;
fakemdrootdev[i].dv_cfdata = NULL; for (i = 0; i < NMD; i++) {
fakemdrootdev[i].dv_cfdriver = &md_cd; fakemdrootdev[i].dv_class = DV_DISK;
fakemdrootdev[i].dv_unit = i; fakemdrootdev[i].dv_cfdata = NULL;
fakemdrootdev[i].dv_parent = NULL; fakemdrootdev[i].dv_cfdriver = &md_cd;
snprintf(fakemdrootdev[i].dv_xname, fakemdrootdev[i].dv_unit = i;
sizeof(fakemdrootdev[i].dv_xname), "md%d", i); fakemdrootdev[i].dv_parent = NULL;
snprintf(fakemdrootdev[i].dv_xname,
sizeof(fakemdrootdev[i].dv_xname), "md%d", i);
}
bootdv = &fakemdrootdev[0];
bootpartition = 0;
} }
#endif /* MEMORY_DISK_HOOKS */
#ifdef MEMORY_DISK_IS_ROOT
bootdv = &fakemdrootdev[0];
bootpartition = 0;
#endif #endif
/* /*
@ -1117,19 +1113,19 @@ static struct device *
finddevice(const char *name) finddevice(const char *name)
{ {
const char *wname; const char *wname;
#if defined(BOOT_FROM_MEMORY_HOOKS)
int j;
#endif /* BOOT_FROM_MEMORY_HOOKS */
if ((wname = getwedgename(name, strlen(name))) != NULL) if ((wname = getwedgename(name, strlen(name))) != NULL)
return dkwedge_find_by_wname(wname); return dkwedge_find_by_wname(wname);
#ifdef BOOT_FROM_MEMORY_HOOKS #if NMD > 0
for (j = 0; j < NMD; j++) { if (md_is_root) {
if (strcmp(name, fakemdrootdev[j].dv_xname) == 0) int j;
return &fakemdrootdev[j]; for (j = 0; j < NMD; j++) {
if (strcmp(name, fakemdrootdev[j].dv_xname) == 0)
return &fakemdrootdev[j];
}
} }
#endif /* BOOT_FROM_MEMORY_HOOKS */ #endif
return device_find_by_xname(name); return device_find_by_xname(name);
} }
@ -1138,17 +1134,16 @@ static struct device *
getdisk(char *str, int len, int defpart, dev_t *devp, int isdump) getdisk(char *str, int len, int defpart, dev_t *devp, int isdump)
{ {
struct device *dv; struct device *dv;
#ifdef MEMORY_DISK_HOOKS
int i;
#endif
if ((dv = parsedisk(str, len, defpart, devp)) == NULL) { if ((dv = parsedisk(str, len, defpart, devp)) == NULL) {
printf("use one of:"); printf("use one of:");
#ifdef MEMORY_DISK_HOOKS #if NMD > 0
if (isdump == 0) if (isdump == 0 && md_is_root) {
int i;
for (i = 0; i < NMD; i++) for (i = 0; i < NMD; i++)
printf(" %s[a-%c]", fakemdrootdev[i].dv_xname, printf(" %s[a-%c]", fakemdrootdev[i].dv_xname,
'a' + MAXPARTITIONS - 1); 'a' + MAXPARTITIONS - 1);
}
#endif #endif
TAILQ_FOREACH(dv, &alldevs, dv_list) { TAILQ_FOREACH(dv, &alldevs, dv_list) {
if (DEV_USES_PARTITIONS(dv)) if (DEV_USES_PARTITIONS(dv))
@ -1189,9 +1184,6 @@ parsedisk(char *str, int len, int defpart, dev_t *devp)
const char *wname; const char *wname;
char *cp, c; char *cp, c;
int majdev, part; int majdev, part;
#ifdef MEMORY_DISK_HOOKS
int i;
#endif
if (len == 0) if (len == 0)
return (NULL); return (NULL);
@ -1218,12 +1210,16 @@ parsedisk(char *str, int len, int defpart, dev_t *devp)
} else } else
part = defpart; part = defpart;
#ifdef MEMORY_DISK_HOOKS #if NMD > 0
for (i = 0; i < NMD; i++) if (md_is_root) {
if (strcmp(str, fakemdrootdev[i].dv_xname) == 0) { int i;
dv = &fakemdrootdev[i]; for (i = 0; i < NMD; i++) {
goto gotdisk; if (strcmp(str, fakemdrootdev[i].dv_xname) == 0) {
dv = &fakemdrootdev[i];
goto gotdisk;
}
} }
}
#endif #endif
dv = finddevice(str); dv = finddevice(str);