1#!/usr/bin/python 2 3import struct 4import sys 5 6if len(sys.argv) != 4: 7 print sys.argv[0] + " ramdisk.img vendor_boot.img ramdisk-qemu.img" 8 sys.exit(1) 9 10f1name = sys.argv[1]; 11f2name = sys.argv[2]; 12f3name = sys.argv[3]; 13 14with open(f1name, mode='rb') as file: 15 f1buffer = file.read() 16 17with open(f2name, mode='rb') as file: 18 f2buffer = file.read() 19 20header = struct.unpack("QIIQI", f2buffer[:28]) 21if header[1] != 3: 22 print "ERROR: can only combine version 3 vendor_boot.img to ramdisk.img" 23 sys.exit(2) 24 25offset = 4096 26vendorramimg = f2buffer[offset:offset+header[4]]; 27 28print header 29with open(f3name, mode='wb') as file: 30 file.write(f1buffer) 31 file.write(vendorramimg) 32