Date: Sat, 29 Jun 2002 23:31:27 GMT From: W Gerald Hicks <gehicks@gehicks.dyndns.org> To: FreeBSD-gnats-submit@FreeBSD.org Subject: kern/40021: [patch] use ld(1) to build kernel with linked-in md(4) filesys Message-ID: <200206292331.g5TNVRRu000860@gehicks.dyndns.org>
next in thread | raw e-mail | index | archive | help
>Number: 40021
>Category: kern
>Synopsis: [patch] use ld(1) to build kernel with linked-in md(4) filesys
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sat Jun 29 16:30:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: W Gerald Hicks
>Release: FreeBSD 5.0-CURRENT i386
>Organization:
Glenayre Electronics
>Environment:
FreeBSD 5.0-CURRENT i386
>Description:
[this is a prototype, needs review and feedback before committing]
FreeBSD formerly used a scheme of preallocating a fixed size
region of memory for an embedded MFS filesystem image which
was subsequently patched after kernel build with a utility
program (write_mfs_in_kernel).
This scheme is no longer used by sysinstall since md(4) and
/boot/loader provides the ability to load an md(4) filesystem
like a module.
Some applications such as picoBSD and etherboot still need a
linked-in filesystem. This patch allows one to specify an object
file created with mdconfig(8) and objcopy(1) to be linked into the
kernel image. This has the added benefit of allowing a flexible
size for the filesystem.
The patch deprecates 'options MD_ROOT_SIZE' replacing it with
'makeoptions MD_ROOT_IMAGE="mdimage.o"' where mdimage.o
is a file created something like this:
dd if=/dev/zero of=mdimage -bs=1024 count=4096
mdconfig -a -t vnode -f mdimage -s 4096k -u 4
disklabel -r -w md4 auto
newfs /dev/md4c
mount /dev/md4c /mnt
.
. put stuff on it
.
umount /mnt
mdconfig -d -u 4
objcopy -I binary -O elf32-i386 -B i386 \
--redefine-symbol _binary_mdimage_start=md_root_image \
--redefine-symbol _binary_mdimage_size=md_root_image_size \
mdimage /tmp/mdimage.o
Add the image to the kernel config:
makeoption MD_ROOT_IMAGE="/tmp/mdimage.o" # needs option MD_ROOT
Configure and build a kernel as usual; the contents of mdimage.o
will provide the linked-in md(4) root file system.
>How-To-Repeat:
Apply the patch :-)
>Fix:
Index: src/sys/conf/NOTES
===================================================================
RCS file: /home/ncvs/src/sys/conf/NOTES,v
retrieving revision 1.1041
diff -u -r1.1041 NOTES
--- src/sys/conf/NOTES 26 Jun 2002 03:34:43 -0000 1.1041
+++ src/sys/conf/NOTES 26 Jun 2002 21:23:04 -0000
@@ -633,13 +633,12 @@
# directories at the expense of some memory.
options UFS_DIRHASH
-# Make space in the kernel for a root filesystem on a md device.
-# Define to the number of kilobytes to reserve for the filesystem.
-options MD_ROOT_SIZE=10
-
# Make the md device a potential root device, either with preloaded
# images of type mfs_root or md_root.
options MD_ROOT
+
+# Specify an object file to link in as a MD filesystem image (needs MD_ROOT)
+makeoptions MD_ROOT_IMAGE="/tmp/mdimage.o"
# Allow this many swap-devices.
#
Index: src/sys/conf/kern.pre.mk
===================================================================
RCS file: /home/ncvs/src/sys/conf/kern.pre.mk,v
retrieving revision 1.13
diff -u -r1.13 kern.pre.mk
--- src/sys/conf/kern.pre.mk 16 Jun 2002 10:42:05 -0000 1.13
+++ src/sys/conf/kern.pre.mk 26 Jun 2002 21:22:16 -0000
@@ -88,6 +88,10 @@
${SIZE} ${FMT} ${.TARGET} ; chmod 755 ${.TARGET}
SYSTEM_DEP+= $S/conf/ldscript.$M
+.if defined(MD_ROOT_IMAGE)
+SYSTEM_OBJS+= ${MD_ROOT_IMAGE}
+.endif
+
# MKMODULESENV is set here so that port makefiles can augment
# them.
Index: src/sys/conf/options
===================================================================
RCS file: /home/ncvs/src/sys/conf/options,v
retrieving revision 1.327
diff -u -r1.327 options
--- src/sys/conf/options 26 Jun 2002 03:34:43 -0000 1.327
+++ src/sys/conf/options 26 Jun 2002 21:15:37 -0000
@@ -81,7 +81,6 @@
KTRACE_REQUEST_POOL opt_ktrace.h
LIBICONV
MD_ROOT opt_md.h
-MD_ROOT_SIZE opt_md.h
NTIMECOUNTER opt_ntp.h
NSWAPDEV opt_swap.h
PPS_SYNC opt_ntp.h
Index: src/sys/dev/md/md.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/md/md.c,v
retrieving revision 1.66
diff -u -r1.66 md.c
--- src/sys/dev/md/md.c 24 Jun 2002 12:07:02 -0000 1.66
+++ src/sys/dev/md/md.c 26 Jun 2002 21:15:37 -0000
@@ -62,6 +62,7 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bio.h>
+#include <sys/cdefs.h>
#include <sys/conf.h>
#include <sys/devicestat.h>
#include <sys/disk.h>
@@ -101,10 +102,10 @@
static int md_debug;
SYSCTL_INT(_debug, OID_AUTO, mddebug, CTLFLAG_RW, &md_debug, 0, "");
-#if defined(MD_ROOT) && defined(MD_ROOT_SIZE)
-/* Image gets put here: */
-static u_char mfs_root[MD_ROOT_SIZE*1024] = "MFS Filesystem goes here";
-static u_char end_mfs_root[] __unused = "MFS Filesystem had better STOP here";
+#if defined(MD_ROOT)
+extern u_char md_root_image[]; __weak_reference(0, md_root_image);
+extern int md_root_image_size; __weak_reference(0, md_root_image_size);
+size_t md_root_size = (size_t) &md_root_image_size; /* size == sym_addr */
#endif
static int mdrootready;
@@ -1084,8 +1085,9 @@
u_char *ptr, *name, *type;
unsigned len;
-#ifdef MD_ROOT_SIZE
- md_preloaded(mfs_root, MD_ROOT_SIZE*1024);
+#ifdef MD_ROOT
+ if(md_root_image != NULL && md_root_size != 0)
+ md_preloaded(md_root_image, md_root_size);
#endif
mod = NULL;
while ((mod = preload_search_next_name(mod)) != NULL) {
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206292331.g5TNVRRu000860>
