1986fd29aSsetje#!/bin/ksh
2986fd29aSsetje#
3986fd29aSsetje# CDDL HEADER START
4986fd29aSsetje#
5986fd29aSsetje# The contents of this file are subject to the terms of the
6986fd29aSsetje# Common Development and Distribution License (the "License").
7986fd29aSsetje# You may not use this file except in compliance with the License.
8986fd29aSsetje#
9986fd29aSsetje# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10986fd29aSsetje# or http://www.opensolaris.org/os/licensing.
11986fd29aSsetje# See the License for the specific language governing permissions
12986fd29aSsetje# and limitations under the License.
13986fd29aSsetje#
14986fd29aSsetje# When distributing Covered Code, include this CDDL HEADER in each
15986fd29aSsetje# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16986fd29aSsetje# If applicable, add the following below this CDDL HEADER, with the
17986fd29aSsetje# fields enclosed by brackets "[]" replaced with your own identifying
18986fd29aSsetje# information: Portions Copyright [yyyy] [name of copyright owner]
19986fd29aSsetje#
20986fd29aSsetje# CDDL HEADER END
21986fd29aSsetje#
22986fd29aSsetje#
23986fd29aSsetje# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24986fd29aSsetje# Use is subject to license terms.
25986fd29aSsetje#
26986fd29aSsetje
27986fd29aSsetje# defaults
28986fd29aSsetjebblen=7680
29986fd29aSsetjerdlen=256
30986fd29aSsetjetotlen=7680
31986fd29aSsetje
32986fd29aSsetjewhile getopts b:r:e: a; do
33986fd29aSsetje	case $a in
34986fd29aSsetje	b) bblen=$OPTARG;;
35986fd29aSsetje	r) rdlen=$OPTARG;;
36986fd29aSsetje	e) extra=$OPTARG
37986fd29aSsetje	   totlen=15872;;
38986fd29aSsetje	?) printf "Usage: %s: [ -b bb_len ] [ -r rd_len ] boot_fcode ramdisk_fcode bootblk\n" $0
39986fd29aSsetje	   exit -1;;
40986fd29aSsetje	esac
41986fd29aSsetjedone
42986fd29aSsetjeshift $(($OPTIND - 1))
43986fd29aSsetje
44986fd29aSsetje#
45986fd29aSsetje# check boot code and ramdisk code for size overflow
46986fd29aSsetje#
47986fd29aSsetjerdoff=$(($bblen - $rdlen))
48986fd29aSsetje
49*55dca7cbSToomas Soomebbsize=$(ls -l $1 | awk '{ print $5 }')
50986fd29aSsetjeif [ $bbsize -gt $rdoff ]; then
51986fd29aSsetje    printf "$1 must be smaller than $rdoff\n"
52986fd29aSsetje    exit -1
53986fd29aSsetjefi
54986fd29aSsetje
55*55dca7cbSToomas Soomerdsize=$(ls -l $2 | awk '{ print $5 }')
56986fd29aSsetjeif [ $rdsize -gt $rdlen ]; then
57986fd29aSsetje    printf "$1 must be smaller than $rdlen\n"
58986fd29aSsetje    exit -1
59986fd29aSsetjefi
60986fd29aSsetje
61986fd29aSsetje#
62986fd29aSsetje# make the bootblk
63986fd29aSsetje#
64986fd29aSsetjemkfile -n $totlen $3
65986fd29aSsetjechmod 644 $3
66986fd29aSsetjedd if=$1 of=$3 conv=notrunc bs=1
67986fd29aSsetjedd if=$2 of=$3 conv=notrunc bs=1 oseek=$rdoff
68986fd29aSsetje
69986fd29aSsetje#
70986fd29aSsetje# extended bootblk for zfs debug
71986fd29aSsetje#
72986fd29aSsetjeif [ $totlen -gt $bblen ]; then
73*55dca7cbSToomas Soome    extsize=$(ls -l $extra | awk '{ print $5 }')
748a9764c3SToomas Soome    if [ $extsize -gt 16384 ]; then
758a9764c3SToomas Soome	printf "$1 must be smaller than 16k\n"
76986fd29aSsetje	exit -1
77986fd29aSsetje    fi
78986fd29aSsetje    dd if=$extra of=$3 conv=notrunc bs=1 oseek=$bblen
79986fd29aSsetjefi
80986fd29aSsetje
81986fd29aSsetjeexit 0
82