All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ján ONDREJ (SAL)" <ondrejj@salstar.sk>
To: Alexander Graf <agraf@suse.de>
Cc: Glauber Costa <glommer@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"avi@redhat.com" <avi@redhat.com>
Subject: Re: [PATCH] unbreak booting with virtio
Date: Sat, 1 Aug 2009 10:01:56 +0200	[thread overview]
Message-ID: <20090801080156.GE2701@salstar.sk> (raw)
In-Reply-To: <20090801070455.GD2701@salstar.sk>

[-- Attachment #1: Type: text/plain, Size: 738 bytes --]

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 <glommer@redhat.com> 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

[-- Attachment #2: signrom-awk.patch --]
[-- Type: text/plain, Size: 1342 bytes --]

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 <agraf@suse.de>
+#            Jan Ondrej (SAL) <ondrejj(at)salstar.sk>
 #
 # Syntax: signrom.sh <input> <output>
 
 # 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

  reply	other threads:[~2009-08-01  8:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-31 18:19 [PATCH] unbreak booting with virtio Glauber Costa
2009-07-31 19:55 ` Alexander Graf
2009-07-31 23:39   ` Glauber Costa
2009-08-01  8:23     ` Alexander Graf
2009-08-01  7:04   ` Ján ONDREJ (SAL)
2009-08-01  8:01     ` Ján ONDREJ (SAL) [this message]
2009-08-01  8:19       ` Alexander Graf
2009-08-01  8:47         ` Ján ONDREJ (SAL)
2009-08-01  8:20   ` Paolo Bonzini
2009-08-03 12:37 ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090801080156.GE2701@salstar.sk \
    --to=ondrejj@salstar.sk \
    --cc=agraf@suse.de \
    --cc=avi@redhat.com \
    --cc=glommer@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.