1fcfdd827SRafal Jaworowski#!/bin/sh 2fcfdd827SRafal Jaworowski# 3fcfdd827SRafal Jaworowski# Copyright (C) 2008 The FreeBSD Project. All rights reserved. 4fcfdd827SRafal Jaworowski# 5fcfdd827SRafal Jaworowski# Redistribution and use in source and binary forms, with or without 6fcfdd827SRafal Jaworowski# modification, are permitted provided that the following conditions 7fcfdd827SRafal Jaworowski# are met: 8fcfdd827SRafal Jaworowski# 1. Redistributions of source code must retain the above copyright 9fcfdd827SRafal Jaworowski# notice, this list of conditions and the following disclaimer. 10fcfdd827SRafal Jaworowski# 2. Redistributions in binary form must reproduce the above copyright 11fcfdd827SRafal Jaworowski# notice, this list of conditions and the following disclaimer in the 12fcfdd827SRafal Jaworowski# documentation and/or other materials provided with the distribution. 13fcfdd827SRafal Jaworowski# 14fcfdd827SRafal Jaworowski# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15fcfdd827SRafal Jaworowski# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16fcfdd827SRafal Jaworowski# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17fcfdd827SRafal Jaworowski# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 18fcfdd827SRafal Jaworowski# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19fcfdd827SRafal Jaworowski# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20fcfdd827SRafal Jaworowski# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21fcfdd827SRafal Jaworowski# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22fcfdd827SRafal Jaworowski# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23fcfdd827SRafal Jaworowski# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24fcfdd827SRafal Jaworowski# SUCH DAMAGE. 25fcfdd827SRafal Jaworowski# 26fcfdd827SRafal Jaworowski# $FreeBSD$ 27fcfdd827SRafal Jaworowski# 28fcfdd827SRafal Jaworowski# Embed the MFS image into the kernel body (expects space reserved via 29fcfdd827SRafal Jaworowski# MD_ROOT_SIZE) 30fcfdd827SRafal Jaworowski# 31fcfdd827SRafal Jaworowski# $1: kernel filename 32fcfdd827SRafal Jaworowski# $2: MFS image filename 33fcfdd827SRafal Jaworowski# 34fcfdd827SRafal Jaworowski 35*0bf94a08SEd Masteif [ $# -ne 2 ]; then 36*0bf94a08SEd Maste echo "usage: $(basename $0) target mfs_image" 37*0bf94a08SEd Maste exit 0 38*0bf94a08SEd Mastefi 39*0bf94a08SEd Masteif [ ! -w "$1" ]; then 40*0bf94a08SEd Maste echo $1 not writable 41*0bf94a08SEd Maste exit 1 42*0bf94a08SEd Mastefi 43*0bf94a08SEd Maste 44f4c1f0b9SAdrian Chaddmfs_size=`stat -f '%z' $2 2> /dev/null` 45f4c1f0b9SAdrian Chadd# If we can't determine MFS image size - bail. 46f4c1f0b9SAdrian Chadd[ -z ${mfs_size} ] && echo "Can't determine MFS image size" && exit 1 47fcfdd827SRafal Jaworowski 480a502389SLi-Wen Hsusec_info=`elfdump -c $1 2> /dev/null | grep -A 5 -E "sh_name: oldmfs$"` 49f4c1f0b9SAdrian Chadd# If we can't find the mfs section within the given kernel - bail. 50*0bf94a08SEd Maste[ -z "${sec_info}" ] && echo "Can't locate mfs section within $1" && exit 1 51f4c1f0b9SAdrian Chadd 520a502389SLi-Wen Hsusec_size=`echo "${sec_info}" | awk '/sh_size/ {print $2}' 2> /dev/null` 530a502389SLi-Wen Hsusec_start=`echo "${sec_info}" | awk '/sh_offset/ {print $2}' 2> /dev/null` 54f4c1f0b9SAdrian Chadd 55f4c1f0b9SAdrian Chadd# If the mfs section size is smaller than the mfs image - bail. 56f4c1f0b9SAdrian Chadd[ ${sec_size} -lt ${mfs_size} ] && echo "MFS image too large" && exit 1 57f4c1f0b9SAdrian Chadd 58f4c1f0b9SAdrian Chadd# Dump the mfs image into the mfs section 59f4c1f0b9SAdrian Chadddd if=$2 ibs=8192 of=$1 obs=${sec_start} oseek=1 conv=notrunc 2> /dev/null && \ 60f4c1f0b9SAdrian Chadd echo "MFS image embedded into kernel" && exit 0 61