Skip to contentSkip to conversation

unbreak booting with virtio

PATCH In review Glauber Costa 5 participants 10 messages Jul 31, 2009 – Aug 3, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unbreak booting with virtio

Since commit 89e671e3, extboot is broken due to wrong checksum

The problem is that printf "\\$sum" syntax will require an octal representation, so the fix I'm proposing is to convert it first.

---
 pc-bios/optionrom/signrom.sh |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
pc-bios/optionrom/signrom.sh +1 -0
index 4322811..3512cc4 100755
@@ -42,4 +42,5 @@ sum=$(( 256 - $sum ))
 
 # and write the output file
 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
Signature · 1 line
1.6.2.2
#1 lore raw
Quoted 4 lines · Glauber Costa

Since commit 89e671e3, extboot is broken due to wrong checksum

The problem is that printf "\\$sum" syntax will require an octal representation, so the fix I'm proposing is to convert it first.

Is there no easy way to tell printf we're on decimal? I don't have a Linux system handy atm, but I thought \90 was in fact a 90.

Either way, my only complaint would be to introduce a dependency on bc.

Alex

Quoted 20 lines

---
pc-bios/optionrom/signrom.sh | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)
pc-bios/optionrom/signrom.sh +0 -0
index 4322811..3512cc4 100755
@@ -42,4 +42,5 @@ sum=$(( 256 - $sum ))
 
 # and write the output file

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

Signature · 1 line
1.6.2.2
#2 lore raw
Quoted 5 lines · Alexander Graf
Quoted 2 lines · Glauber Costa

Since commit 89e671e3, extboot is broken due to wrong checksum

Quoted 7 lines
Quoted 2 lines

The problem is that printf "\\$sum" syntax will require an octal representation, so the fix I'm proposing is to convert it first.

Is there no easy way to tell printf we're on decimal? I don't have a Linux system handy atm, but I thought \90 was in fact a 90.

Either way, my only complaint would be to introduce a dependency on bc.

Not that I'm aware of.
But would be happy to know, too.

#3 lore raw
Quoted 9 lines · Glauber Costa
Quoted 8 lines · Alexander Graf
Quoted 4 lines · Glauber Costa

Since commit 89e671e3, extboot is broken due to wrong checksum

The problem is that printf "\\$sum" syntax will require an octal representation, so the fix I'm proposing is to convert it first.

Quoted 6 lines
Quoted 4 lines

Is there no easy way to tell printf we're on decimal? I don't have a Linux system handy atm, but I thought \90 was in fact a 90.

Either way, my only complaint would be to introduce a dependency on bc.

Not that I'm aware of.
But would be happy to know, too.

Hum, reading the documentation again it in fact needs an octal number. But we could use printf for the conversion as well!

$ printf "%o" 65
101

That wouldn't introduce a new dependency that might be missing on random OSs and looks rather clean to me.

Alex

#4 lore raw
In reply to Alexander Graf
Quoted 5 lines · Alexander Graf
Quoted 2 lines · Glauber Costa

Since commit 89e671e3, extboot is broken due to wrong checksum

Quoted 12 lines
Quoted 2 lines

The problem is that printf "\\$sum" syntax will require an octal representation, so the fix I'm proposing is to convert it first.

Is there no easy way to tell printf we're on decimal? I don't have a Linux system handy atm, but I thought \90 was in fact a 90.

Either way, my only complaint would be to introduce a dependency on bc.

Quoted 4 lines

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.

SAL

#5 lore raw
Quoted 9 lines · Ján ONDREJ (SAL)
Quoted 7 lines · Alexander Graf
Quoted 4 lines · Glauber Costa

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

Quoted 6 lines

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

pc-bios/optionrom/signrom.sh +22 -19
index 4273d1f..065b6a9 100755
@@ -18,28 +18,31 @@
 #
 # Copyright Novell Inc, 2009
 #   Authors: Alexander Graf <[email protected]>
+#            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
#6 lore raw
Quoted 13 lines · Ján ONDREJ (SAL)
Quoted 12 lines · Ján ONDREJ (SAL)
Quoted 8 lines · Alexander Graf
Quoted 5 lines · Glauber Costa

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:

Quoted 8 lines
Quoted 4 lines

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).

My awk magic is pretty bad, but I think this version is missing the padding, right?

Alex

#7 lore raw
Quoted 19 lines · Alexander Graf
Quoted 16 lines · Ján ONDREJ (SAL)
Quoted 15 lines · Ján ONDREJ (SAL)
Quoted 8 lines · Alexander Graf
Quoted 5 lines · Glauber Costa

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

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

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).

My awk magic is pretty bad, but I think this version is missing the padding, right?

Right. If you prefer this version agains Paolos double printf, I can update it, if not, just use Pauols solution.

SAL

#8 lore raw
In reply to Alexander Graf
Quoted 5 lines · Alexander Graf
Quoted 2 lines · Glauber Costa

Since commit 89e671e3, extboot is broken due to wrong checksum

Quoted 7 lines
Quoted 2 lines

The problem is that printf "\\$sum" syntax will require an octal representation, so the fix I'm proposing is to convert it first.

Is there no easy way to tell printf we're on decimal? I don't have a Linux system handy atm, but I thought \90 was in fact a 90.

Either way, my only complaint would be to introduce a dependency on bc.

printf printf '\\%o' $sum

Paolo

#9 lore raw
In reply to Glauber Costa
Quoted 6 lines · Glauber Costa

Since commit 89e671e3, extboot is broken due to wrong checksum

The problem is that printf "\\$sum" syntax will require an octal representation, so the fix I'm proposing is to convert it first.

Whichever way this gets resolved, please send it upstream since the bug exists there.

Signature · 1 line
error compiling committee.c: too many arguments to function