From patchwork Sat Aug 1 08:01:56 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsODwqFuIE9ORFJFSiAoU0FMKQ==?= X-Patchwork-Id: 38649 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n71820DV027441 for ; Sat, 1 Aug 2009 08:02:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752327AbZHAIB5 (ORCPT ); Sat, 1 Aug 2009 04:01:57 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752256AbZHAIB5 (ORCPT ); Sat, 1 Aug 2009 04:01:57 -0400 Received: from work.salstar.sk ([158.197.240.41]:60334 "EHLO work.salstar.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751954AbZHAIB4 (ORCPT ); Sat, 1 Aug 2009 04:01:56 -0400 Received: by work.salstar.sk (Postfix, from userid 500) id E49B1C803A; Sat, 1 Aug 2009 10:01:56 +0200 (CEST) Date: Sat, 1 Aug 2009 10:01:56 +0200 From: =?utf-8?B?SsOhbiBPTkRSRUogKFNBTCk=?= To: Alexander Graf Cc: Glauber Costa , "kvm@vger.kernel.org" , "avi@redhat.com" Subject: Re: [PATCH] unbreak booting with virtio Message-ID: <20090801080156.GE2701@salstar.sk> References: <1249064349-799-1-git-send-email-glommer@redhat.com> <20090801070455.GD2701@salstar.sk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20090801070455.GD2701@salstar.sk> User-Agent: Mutt/1.5.19 (2009-01-05) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Sat, Aug 01, 2009 at 09:04:55AM +0200, Ján ONDREJ (SAL) wrote: > On Fri, Jul 31, 2009 at 09:55:39PM +0200, Alexander Graf wrote: > > > > On 31.07.2009, at 20:19, Glauber Costa wrote: > > > >> cp "$1" "$2" > >> +sum=$(echo "obase=8; $sum" | bc) > >> printf "\\$sum" | dd of="$2" bs=1 count=1 seek=$size conv=notrunc 2>/ > >> dev/null > > May be it's better to use awk: > > echo $sum | awk '{ printf("%c", $1) }' \ > | dd of="$2" bs=1 count=1 seek=$size conv=notrunc 2>/dev/null > > This version accepts decimal $sum, does not need conversion to octal. Ane may be it's better to write whole checksum in awk, it's faster and cleaner. See attached patch (I am sorry, I don't know how to use git-email). SAL diff --git a/pc-bios/optionrom/signrom.sh b/pc-bios/optionrom/signrom.sh index 4273d1f..065b6a9 100755 --- a/pc-bios/optionrom/signrom.sh +++ b/pc-bios/optionrom/signrom.sh @@ -18,28 +18,31 @@ # # Copyright Novell Inc, 2009 # Authors: Alexander Graf +# Jan Ondrej (SAL) # # Syntax: signrom.sh # did we get proper arguments? test "$1" -a "$2" || exit 1 -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` -#size=`expr $x \* 512 - 1` -size=$(( $x * 512 - 1 )) - -# now get the checksum -for i in `od -A n -t u1 -v "$1"`; do - # add each byte's value to sum - sum=$(( $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 +od -A n -t u1 -v "$1" | awk ' + BEGIN { + checksum=0 + # last byte will be replaced by checksum + last=-1 + } + { + # go over all record in row + for(i=1; i<=NF; i++) { + checksum+=$i + if (last>=0) { + printf "%c", last + } + last=$i + } + } + END { + # compute checksum + printf "%c", 256-(checksum%256) + } +' > $2