buildrom.py: Handle image size in PCI header

This patch makes buildrom.py check if a PCI is present in the ROM,
and fills in the image size field.

Signed-off-by: Julian Pidancet <julian.pidancet@gmail.com>
diff --git a/tools/buildrom.py b/tools/buildrom.py
index 19b715a..7ed8107 100755
--- a/tools/buildrom.py
+++ b/tools/buildrom.py
@@ -28,6 +28,11 @@
     data += "\0" * (alignpos(count, 512) - count)
     count = len(data)
 
+    # Check if a pci header is present
+    pcidata = ord(data[24:25]) + (ord(data[25:26]) << 8)
+    if pcidata != 0:
+        data = data[:pcidata + 16] + chr(count/512) + chr(0) + data[pcidata + 18:]
+
     # Fill in size field; clear checksum field
     data = data[:2] + chr(count/512) + data[3:6] + "\0" + data[7:]