xref: /titanic_50/usr/src/psm/stand/bootblks/common/mkbb.sh (revision d4c0a8c59bf9b2697b3dda08963d7f424dcba394)
1#!/bin/ksh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26#ident	"%Z%%M%	%I%	%E% SMI"
27#
28
29#!/bin/sh
30
31# defaults
32bblen=7680
33rdlen=256
34totlen=7680
35
36while getopts b:r:e: a; do
37	case $a in
38	b) bblen=$OPTARG;;
39	r) rdlen=$OPTARG;;
40	e) extra=$OPTARG
41	   totlen=15872;;
42	?) printf "Usage: %s: [ -b bb_len ] [ -r rd_len ] boot_fcode ramdisk_fcode bootblk\n" $0
43	   exit -1;;
44	esac
45done
46shift $(($OPTIND - 1))
47
48#
49# check boot code and ramdisk code for size overflow
50#
51rdoff=$(($bblen - $rdlen))
52
53bbsize=$(ls -l $1 | awk -e '{ print $5 }')
54if [ $bbsize -gt $rdoff ]; then
55    printf "$1 must be smaller than $rdoff\n"
56    exit -1
57fi
58
59rdsize=$(ls -l $2 | awk -e '{ print $5 }')
60if [ $rdsize -gt $rdlen ]; then
61    printf "$1 must be smaller than $rdlen\n"
62    exit -1
63fi
64
65#
66# make the bootblk
67#
68mkfile -n $totlen $3
69chmod 644 $3
70dd if=$1 of=$3 conv=notrunc bs=1
71dd if=$2 of=$3 conv=notrunc bs=1 oseek=$rdoff
72
73#
74# extended bootblk for zfs debug
75#
76if [ $totlen -gt $bblen ]; then
77    extsize=$(ls -l $extra | awk -e '{ print $5 }')
78    if [ $extsize -gt 8192 ]; then
79	printf "$1 must be smaller than 8k\n"
80	exit -1
81    fi
82    dd if=$extra of=$3 conv=notrunc bs=1 oseek=$bblen
83fi
84
85exit 0
86