From patchwork Sun Aug 2 19:56:56 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Herbszt X-Patchwork-Id: 30477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 62DF2B7099 for ; Mon, 3 Aug 2009 06:00:31 +1000 (EST) Received: from localhost ([127.0.0.1]:41964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXhEF-0002ud-Sz for incoming@patchwork.ozlabs.org; Sun, 02 Aug 2009 16:00:23 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MXhDf-0002uY-HO for qemu-devel@nongnu.org; Sun, 02 Aug 2009 15:59:47 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MXhDZ-0002rt-TK for qemu-devel@nongnu.org; Sun, 02 Aug 2009 15:59:46 -0400 Received: from [199.232.76.173] (port=57793 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXhDZ-0002rq-PR for qemu-devel@nongnu.org; Sun, 02 Aug 2009 15:59:41 -0400 Received: from mail.gmx.net ([213.165.64.20]:53426) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MXhDZ-00073J-3J for qemu-devel@nongnu.org; Sun, 02 Aug 2009 15:59:41 -0400 Received: (qmail invoked by alias); 02 Aug 2009 19:59:34 -0000 Received: from p54BD1446.dip0.t-ipconnect.de (HELO FSCPC) [84.189.20.70] by mail.gmx.net (mp019) with SMTP; 02 Aug 2009 21:59:34 +0200 X-Authenticated: #310364 X-Provags-ID: V01U2FsdGVkX19Q+3JsvdpQK6cMYLuJNGzrF089BbCYZokpUxalAf R7wAcuTQ4ixMX0 Message-ID: From: "Sebastian Herbszt" To: "Alexander Graf" References: <75404CF870024F539884B8819ECD6E60@FSCPC> <5b31733c0908011451i69a51791r7fec576fed7c41ad@mail.gmail.com> <78B8C636C3BD4BB4B145B8A31D306E3B@FSCPC> <25CE2FD1-7DE9-453E-B3CF-34C374BE7C18@suse.de> In-Reply-To: <25CE2FD1-7DE9-453E-B3CF-34C374BE7C18@suse.de> Subject: Re: [Qemu-devel] signrom.sh and MinGW Date: Sun, 2 Aug 2009 21:56:56 +0200 MIME-Version: 1.0 X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Windows Mail 6.0.6000.16480 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16669 X-Y-GMX-Trusted: 0 X-FuHaFi: 0.44 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Filip Navara , qemu-devel@nongnu.org X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Alexander Graf wrote: > > On 02.08.2009, at 14:21, Sebastian Herbszt wrote: > >> Filip Navara wrote: >>> Sebastian Herbszt wrote: >>>> v0.11.0-rc0-182-g28e738d/pc-bios/optionrom/signrom.sh multiboot.raw >>>> multiboot.bin >>>> v0.11.0-rc0-182-g28e738d/pc-bios/optionrom/signrom.sh: * 512 - 1 : >>>> syntax >>>> error: operand expected (error token is "* 512 - 1 ") >>>> make[1]: *** [multiboot.bin] Error 1 >>>> rm multiboot.raw multiboot.img multiboot.o >>>> make: *** [romsubdir-optionrom] Error 2 >>>> >>>> pc-bios/optionrom/signrom.sh has >>>> >>>> # find out the file size >>>> x=`dd if="$1" bs=1 count=1 skip=2 2>/dev/null | od -t u1 -A n` >>>> #size=`expr $x \* 512 - 1` >>>> size=$(( $x * 512 - 1 )) >>>> >>>> but it seems (at least my) MinGW doesn't include "dd". >>>> >>> I have already reported that on the mailing list earlier. >>> Workaround/fix is to download MSYS coreutils from the MinGW download >>> page. >> >> Thanks for the hint - got it working now. >> >> On a closer look at the "od" tool, the use of "dd" seems redundant: >> >> -j, --skip-bytes=BYTES >> skip BYTES input bytes first >> >> -N, --read-bytes=BYTES >> limit dump to BYTES input bytes >> >> "od -N 1 -j 2 -t u1 -A n multiboot.raw" seems to do the same job and >> "od" is pre-shipped on >> MinGW/MSYS. But maybe "-j" and "-N" are not widely implemented. A >> possible alternative could >> be the use of "head" and "cut". > > Right, but we need dd later on anyways and I find dd parameters easier > to read than the ones from od, probably because I simply use dd more > often :-). signrom.sh currently uses dd, od, expr, cp and printf. All seem to come from coreutils. coreutils also includes the "sum" utility, which seems to compute the checksum you calculate in the for loop if the option "-s" is specified. >> In any case signrom.sh might check for the presence of tools used. > > Good idea. Please post a patch! Maybe something like the following in the hope that "which" is always available. - Sebastian diff --git a/pc-bios/optionrom/signrom.sh b/pc-bios/optionrom/signrom.sh index 4322811..31c91f1 100755 --- a/pc-bios/optionrom/signrom.sh +++ b/pc-bios/optionrom/signrom.sh @@ -23,23 +23,53 @@ # did we get proper arguments? test "$1" -a "$2" || exit 1 +DD=`which dd 2>/dev/null` +if test $? -ne 0 ; then + echo dd not found. + exit 1 +fi + +OD=`which od 2>/dev/null` +if test $? -ne 0 ; then + echo od not found. + exit 1 +fi + +EXPR=`which expr 2>/dev/null` +if test $? -ne 0 ; then + echo expr not found. + exit 1 +fi + +CP=`which cp 2>/dev/null` +if test $? -ne 0 ; then + echo cp not found. + exit 1 +fi + +PRINTF=`which printf 2>/dev/null` +if test $? -ne 0 ; then + echo printf not found. + exit 1 +fi + sum=0 # find out the file size -x=`dd if="$1" bs=1 count=1 skip=2 2>/dev/null | od -t u1 -A n` +x=`${DD} if="$1" bs=1 count=1 skip=2 2>/dev/null | ${OD} -t u1 -A n` #size=`expr $x \* 512 - 1` size=$(( $x * 512 - 1 )) # now get the checksum -nums=`od -A n -t u1 -v "$1"` +nums=`${OD} -A n -t u1 -v "$1"` for i in ${nums}; do # add each byte's value to sum - sum=`expr $sum + $i` + sum=`${EXPR} $sum + $i` done sum=$(( $sum % 256 )) sum=$(( 256 - $sum )) # and write the output file -cp "$1" "$2" -printf "\\$sum" | dd of="$2" bs=1 count=1 seek=$size conv=notrunc 2>/dev/null +${CP} "$1" "$2" +${PRINTF} "\\$sum" | ${DD} of="$2" bs=1 count=1 seek=$size conv=notrunc 2>/dev/null