Skip to contentSkip to conversation

signrom: Rewrite as python script

PATCH Superseded Jan Kiszka 4 participants 5 messages Jan 24, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 signrom: Rewrite as python script

Now that we have a hard dependency on python anyway, we can replace the slow shell script to calculate the option ROM checksum with a fast AND portable python version. Tested both with python 2.7 and 3.1.

---

Getting v2 vs. v3 running wasn't straightforward, but a python expert kindly supported me.

 pc-bios/optionrom/Makefile |    2 +-
 scripts/signrom.py         |   40 +++++++++++++++++++++++++++++++++++++++
 scripts/signrom.sh         |   45 --------------------------------------------
 3 files changed, 41 insertions(+), 46 deletions(-)
 create mode 100644 scripts/signrom.py
 delete mode 100755 scripts/signrom.sh
pc-bios/optionrom/Makefile +1 -1
index 3edde85..403c0b1 100644
@@ -25,7 +25,7 @@ build-all: multiboot.bin linuxboot.bin
 	$(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@; rm -f $<,"  Building $(TARGET_DIR)$@")
 
 %.bin: %.raw
-	$(call quiet-command,$(SHELL) $(SRC_PATH)/scripts/signrom.sh $< $@; rm -f $<,"  Signing $(TARGET_DIR)$@")
+	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/signrom.py $< $@; rm -f $<,"  Signing $(TARGET_DIR)$@")
 
 clean:
 	rm -f *.o *.d *.raw *.img *.bin *~
scripts/signrom.py new file +40 -0
new file mode 100644
index 0000000..8c6d4fd
@@ -0,0 +1,40 @@
+#
+# Option ROM Signing utility
+#
+# Authors:
+#  Jan Kiszka <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPLv2.
+# See the COPYING file in the top-level directory.
+
+import sys
+import struct
+
+if len(sys.argv) < 3:
+    print('usage: signrom.py input output')
+    sys.exit(1)
+
+fin = open(sys.argv[1], 'rb')
+fout = open(sys.argv[2], 'wb')
+
+fin.seek(2)
+size = ord(fin.read(1)) * 512 - 1
+
+fin.seek(0)
+data = fin.read(size)
+fout.write(data)
+
+checksum = 0
+for b in data:
+    # catch Python 2 vs. 3 differences
+    if isinstance(b, int):
+        checksum += b
+    else:
+        checksum += ord(b)
+checksum = (256 - checksum) % 256
+
+# Python 3 no longer allows chr(checksum)
+fout.write(struct.pack('B', checksum))
+
+fin.close()
+fout.close()
scripts/signrom.sh deleted +0 -45

45 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#1 lore raw
Quoted 9 lines · Jan Kiszka

Now that we have a hard dependency on python anyway, we can replace the slow shell script to calculate the option ROM checksum with a fast AND portable python version. Tested both with python 2.7 and 3.1.

---

+++ b/scripts/signrom.py

scripts/signrom.py line 7

Quoted 7 lines
scripts/signrom.py new file +7 -0
@@ -0,0 +1,40 @@
+#
+# Option ROM Signing utility
+#
+# Authors:
+#  Jan Kiszka <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPLv2.

Any reason you aren't using GPLv2+,

scripts/signrom.sh line 8

Quoted 11 lines
scripts/signrom.sh deleted +0 -8
@@ -1,45 +0,0 @@
-#!/bin/sh
-
-# Option ROM Signing utility
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.

especially since you were replacing a more permissive license in the .sh version?

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#2 lore raw
Quoted 8 lines · Eric Blake
Quoted 7 lines · Jan Kiszka

Now that we have a hard dependency on python anyway, we can replace the slow shell script to calculate the option ROM checksum with a fast AND portable python version. Tested both with python 2.7 and 3.1.

---

Quoted 11 lines

scripts/signrom.py line 7

Quoted 9 lines

+++ b/scripts/signrom.py

scripts/signrom.py new file +7 -0
@@ -0,0 +1,40 @@
+#
+# Option ROM Signing utility
+#
+# Authors:
+#  Jan Kiszka <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPLv2.

Any reason you aren't using GPLv2+,

Internal complications. :-/

Quoted 15 lines

scripts/signrom.sh line 8

Quoted 12 lines
scripts/signrom.sh deleted +0 -8
@@ -1,45 +0,0 @@
-#!/bin/sh
-
-# Option ROM Signing utility
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.

especially since you were replacing a more permissive license in the .sh version?

I'm writing new code, this is not a derivative.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#3 lore raw
Quoted 39 lines · Jan Kiszka
Quoted 8 lines · Eric Blake
Quoted 7 lines · Jan Kiszka

Now that we have a hard dependency on python anyway, we can replace the slow shell script to calculate the option ROM checksum with a fast AND portable python version. Tested both with python 2.7 and 3.1.

---

Quoted 11 lines

scripts/signrom.py line 7

Quoted 9 lines

+++ b/scripts/signrom.py

scripts/signrom.py new file +7 -0
@@ -0,0 +1,40 @@
+#
+# Option ROM Signing utility
+#
+# Authors:
+#  Jan Kiszka <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPLv2.

Any reason you aren't using GPLv2+,

Internal complications. :-/

Quoted 15 lines

scripts/signrom.sh line 8

Quoted 12 lines
scripts/signrom.sh deleted +0 -8
@@ -1,45 +0,0 @@
-#!/bin/sh
-
-# Option ROM Signing utility
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.

especially since you were replacing a more permissive license in the .sh version?

Quoted 1 line

I'm writing new code, this is not a derivative.

Is it enough of an improvement to justify the licensing regression?

#4 lore raw
In reply to Jan Kiszka

Am 24.01.2012 16:25, schrieb Jan Kiszka:

Quoted 21 lines · Eric Blake
Quoted 8 lines · Jan Kiszka
Quoted 7 lines

Now that we have a hard dependency on python anyway, we can replace the slow shell script to calculate the option ROM checksum with a fast AND portable python version. Tested both with python 2.7 and 3.1.

---

Quoted 11 lines

scripts/signrom.py line 7

Quoted 9 lines

+++ b/scripts/signrom.py

scripts/signrom.py new file +7 -0
@@ -0,0 +1,40 @@
+#
+# Option ROM Signing utility
+#
+# Authors:
+# Jan Kiszka <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPLv2.

Any reason you aren't using GPLv2+,

Quoted 1 line

Internal complications. :-/

Then I think these complications need to be handled first.

Any new code with GLP should use GPLv2+.
Can you use a BSD like license or PD?

Regards,
Stefan

PS. Anthony, there are more scripts/*.py files with GPLv2 only. As they are all from IBM / Redhat / Blue, they can be changed to GPLv2+.