Skip to contentSkip to conversation

Replace signrom with shell script

PATCH New Alexander Graf 1 participant 1 message Jul 1, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Replace signrom with shell script

In order to not execute code we just compiled, let's replace signrom with a shell script that does the same thing while staying compatible to pretty much every system available.

This should make cross-compilation for windows easier.

---
 pc-bios/optionrom/Makefile   |    9 ++---
 pc-bios/optionrom/signrom.c  |   79 ------------------------------------------
 pc-bios/optionrom/signrom.sh |   17 +++++++++
 3 files changed, 20 insertions(+), 85 deletions(-)
 delete mode 100644 pc-bios/optionrom/signrom.c
 create mode 100755 pc-bios/optionrom/signrom.sh
pc-bios/optionrom/Makefile +3 -6
index c4a6f42..1d9b5d8 100644
@@ -37,12 +37,9 @@ build-all: multiboot.bin
 %.img: %.o
 	$(LD) --oformat binary -Ttext 0 -o $@ $<
 
-%.bin: %.img signrom
-	./signrom $< $@
+%.bin: %.img
+	./signrom.sh $< $@
 	cp $@ $(SRC_PATH)/pc-bios/
 
-signrom: signrom.c
-	$(CC) -o $@ -g -Wall $^
-
 clean:
-	$(RM) *.o *.img *.bin signrom *~
+	$(RM) *.o *.img *.bin *~
pc-bios/optionrom/signrom.c deleted +0 -79

79 lines not on this page · raw message

pc-bios/optionrom/signrom.sh new file +17 -0
new file mode 100755
index 0000000..a53c14c
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+declare -i sum=0
+
+for i in `od -t u1 -v "$1"`; do
+    # skip the header column
+    [ "${i:0:1}" = "0" ] && continue
+
+    # add each byte's value to sum
+    let sum=$sum+$i
+done
+
+sum=$sum%256
+sum=256-$sum
+
+cp "$1" "$2"
+printf "\\$sum" | dd of="$2" bs=1 count=1 seek=511 conv=notrunc
Signature · 1 line
1.6.0.2