diff options
author | atinm <atin.malaviya@gmail.com> | 2011-05-17 11:12:26 -0400 |
---|---|---|
committer | atinm <atin.malaviya@gmail.com> | 2011-05-17 11:12:26 -0400 |
commit | 93a7e5951c8dfcdf609161875493ef6925f68ca7 (patch) | |
tree | 4f6a18bc3d66a41021e627412a54bb80567264c3 /mkshbootimg.py | |
parent | 306e030c5772b1cd1d38a4801db2bc128021003a (diff) | |
download | device_samsung_aries-common-93a7e5951c8dfcdf609161875493ef6925f68ca7.zip device_samsung_aries-common-93a7e5951c8dfcdf609161875493ef6925f68ca7.tar.gz device_samsung_aries-common-93a7e5951c8dfcdf609161875493ef6925f68ca7.tar.bz2 |
moved to device/samsung/aries-common
Diffstat (limited to 'mkshbootimg.py')
-rwxr-xr-x | mkshbootimg.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/mkshbootimg.py b/mkshbootimg.py new file mode 100755 index 0000000..dcc8294 --- /dev/null +++ b/mkshbootimg.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +import sys, os + +def copydata(outfile, infile): + while 1: + data = infile.read(512) + if (data): + outfile.write(data) + else: + break + +def alignoffset(outfile): + offset = outfile.tell() + outfile.seek((offset + 511) & ~511) + return outfile.tell() + +def appendimage(outfile, infile): + offset = alignoffset(outfile) + copydata(outfile, infile) + length = alignoffset(outfile) - offset + assert (offset % 512 == 0) + assert (length % 512 == 0) + return (offset/512, length/512) + +if len(sys.argv) < 4: + print "Usage:", sys.argv[0], "output kernel boot [recovery]" + sys.exit(1) + +outfile = open(sys.argv[1], 'wb') +kernel = open(sys.argv[2], 'r') +boot = open(sys.argv[3], 'r') +recovery = None +if (len(sys.argv) == 5): + recovery = open(sys.argv[4], 'r') +offset_table = "\n\nBOOT_IMAGE_OFFSETS\n" +copydata(outfile, kernel) +table_loc = alignoffset(outfile) +outfile.write('\x00' * 512) +offset_table += "boot_offset=%d;boot_len=%d;" % appendimage(outfile, boot) +if recovery: + offset_table += "recovery_offset=%d;recovery_len=%d;" % appendimage(outfile, recovery) +offset_table += "\n\n" +outfile.seek(table_loc) +outfile.write(offset_table) +outfile.flush() +os.fsync(outfile.fileno()) +outfile.close() |