1208749Sraj#!/bin/sh
2208749Sraj#
3208749Sraj# Copyright (c) 2010 The FreeBSD Foundation
4208749Sraj# All rights reserved.
5208749Sraj#
6208749Sraj# This software was developed by Semihalf under sponsorship from
7208749Sraj# the FreeBSD Foundation.
8208749Sraj#
9208749Sraj# Redistribution and use in source and binary forms, with or without
10208749Sraj# modification, are permitted provided that the following conditions
11208749Sraj# are met:
12208749Sraj# 1. Redistributions of source code must retain the above copyright
13208749Sraj#    notice, this list of conditions and the following disclaimer.
14208749Sraj# 2. Redistributions in binary form must reproduce the above copyright
15208749Sraj#    notice, this list of conditions and the following disclaimer in the
16208749Sraj#    documentation and/or other materials provided with the distribution.
17208749Sraj#
18208749Sraj# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19208749Sraj# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20208749Sraj# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21208749Sraj# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22208749Sraj# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23208749Sraj# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24208749Sraj# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25208749Sraj# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26208749Sraj# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27208749Sraj# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28208749Sraj# SUCH DAMAGE.
29208749Sraj#
30208749Sraj# $FreeBSD$
31208749Sraj
32208749Sraj# $1: kernel filename
33208749Sraj# $2: device tree blob filename
34208749Sraj
35208749Srajdtbsize=`ls -l $2 | awk '{print $5}'`
36208749Srajobs=`strings -at d $1 | grep "Device Tree Blob STARTS here" | awk '{print $1}'`
37208749Srajeol=`strings -at d $1 | grep "Device Tree Blob STOPS here" | awk '{print $1}'`
38208749Srajsz=$((eol - obs));
39208749Srajif [ $sz -lt $dtbsize ]
40208749Srajthen
41208749Sraj	echo "Selected blob is too big to reembed. Please rebuild the kernel."
42208749Sraj	exit
43208749Srajfi
44208749Srajdd if=$2 ibs=${dtbsize} of=$1 obs=${obs} oseek=1 conv=notrunc 2> /dev/null
45