xref: /titanic_50/usr/src/psm/stand/bootblks/common/mkbb.sh (revision 45818ee124adeaaf947698996b4f4c722afc6d1f)
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
27# defaults
28bblen=7680
29rdlen=256
30totlen=7680
31
32while getopts b:r:e: a; do
33	case $a in
34	b) bblen=$OPTARG;;
35	r) rdlen=$OPTARG;;
36	e) extra=$OPTARG
37	   totlen=15872;;
38	?) printf "Usage: %s: [ -b bb_len ] [ -r rd_len ] boot_fcode ramdisk_fcode bootblk\n" $0
39	   exit -1;;
40	esac
41done
42shift $(($OPTIND - 1))
43
44#
45# check boot code and ramdisk code for size overflow
46#
47rdoff=$(($bblen - $rdlen))
48
49bbsize=$(ls -l $1 | awk -e '{ print $5 }')
50if [ $bbsize -gt $rdoff ]; then
51    printf "$1 must be smaller than $rdoff\n"
52    exit -1
53fi
54
55rdsize=$(ls -l $2 | awk -e '{ print $5 }')
56if [ $rdsize -gt $rdlen ]; then
57    printf "$1 must be smaller than $rdlen\n"
58    exit -1
59fi
60
61#
62# make the bootblk
63#
64mkfile -n $totlen $3
65chmod 644 $3
66dd if=$1 of=$3 conv=notrunc bs=1
67dd if=$2 of=$3 conv=notrunc bs=1 oseek=$rdoff
68
69#
70# extended bootblk for zfs debug
71#
72if [ $totlen -gt $bblen ]; then
73    extsize=$(ls -l $extra | awk -e '{ print $5 }')
74    if [ $extsize -gt 16384 ]; then
75	printf "$1 must be smaller than 16k\n"
76	exit -1
77    fi
78    dd if=$extra of=$3 conv=notrunc bs=1 oseek=$bblen
79fi
80
81exit 0
82