path: root/sys/tools
diff options
authorAdrian Chadd <adrian@FreeBSD.org>2016-02-02 07:02:51 +0000
committerAdrian Chadd <adrian@FreeBSD.org>2016-02-02 07:02:51 +0000
commitf4c1f0b9eb4c02ed02063283e9ef778ae92923e8 (patch)
treeee01b20f2d7a80f36d519ff2143f60bb4c2dbef2 /sys/tools
parent7325dfbb59e38848a70546ab4c6a09d7b676fea7 (diff)
Fix MFS builds when both MD_ROOT_SIZE and MFS_IMAGE are specified
MD_ROOT_SIZE and embed_mfs.sh were basically retired as part of https://reviews.freebsd.org/D2903 . However, when building a kernel with 'options MD_ROOT_SIZE' specified, this results in a non-working MFS, as within sys/dev/md/md.c we fall within the wrong # ifdef. This patch implements the following: * Allow kernels to be built without the MD_ROOT_SIZE option, which results in a kernel built as per D2903. * Allow kernels to be built with the MD_ROOT_SIZE option, which results in a kernel built similarly to the pre-D2903 way, with the following differences: * The MFS is now put in a separate section within the kernel (oldmfs, so it differs from the mfs section introduced by D2903). * embed_mfs.sh is changed, so it looks up the oldmfs section within the kernel, gets its size and offset, sees if the MFS will fit within the allocated oldmfs section and only if all is well does a dd of the MFS image into the kernel. Submitted by: Stanislav Galabov <sgalabov@gmail.com> Reviewed by: brooks, imp Differential Revision: https://reviews.freebsd.org/D5093
Notes: svn path=/head/; revision=295137
Diffstat (limited to 'sys/tools')
1 files changed, 16 insertions, 4 deletions
diff --git a/sys/tools/embed_mfs.sh b/sys/tools/embed_mfs.sh
index 785cf3f81bc0..3f20257b7a58 100644
--- a/sys/tools/embed_mfs.sh
+++ b/sys/tools/embed_mfs.sh
@@ -32,8 +32,20 @@
# $2: MFS image filename
-obs=`strings -at d $1 | grep "MFS Filesystem goes here" | awk '{print $1}'`
-dd if=$2 ibs=8192 of=$1 obs=${obs} oseek=1 conv=notrunc 2> /dev/null
+mfs_size=`stat -f '%z' $2 2> /dev/null`
+# If we can't determine MFS image size - bail.
+[ -z ${mfs_size} ] && echo "Can't determine MFS image size" && exit 1
-strings $1 | grep 'MFS Filesystem had better STOP here' > /dev/null || \
- (rm $1 && echo "MFS image too large" && false)
+sec_info=`objdump -h $1 2> /dev/null | grep " oldmfs "`
+# If we can't find the mfs section within the given kernel - bail.
+[ -z "${sec_info}" ] && echo "Can't locate mfs section within kernel" && exit 1
+sec_size=`echo ${sec_info} | awk '{printf("%d", "0x" $3)}' 2> /dev/null`
+sec_start=`echo ${sec_info} | awk '{printf("%d", "0x" $6)}' 2> /dev/null`
+# If the mfs section size is smaller than the mfs image - bail.
+[ ${sec_size} -lt ${mfs_size} ] && echo "MFS image too large" && exit 1
+# Dump the mfs image into the mfs section
+dd if=$2 ibs=8192 of=$1 obs=${sec_start} oseek=1 conv=notrunc 2> /dev/null && \
+ echo "MFS image embedded into kernel" && exit 0