Commit 12b2d179 authored by John Zhang's avatar John Zhang

updated mar.py, using metainfo

parent 87632589
...@@ -6,37 +6,35 @@ import tempfile ...@@ -6,37 +6,35 @@ import tempfile
import shutil import shutil
def mu_meta_set(bootimg, entry_point_id=None, entry_point_name=None, extra_libraries=None): def mu_meta_set(bootimg, extra_libraries=None):
with tempfile.NamedTemporaryFile(delete=False) as tf: with tempfile.NamedTemporaryFile(delete=False) as tf:
tmpfilename = tf.name tmpfilename = tf.name
with zipfile.ZipFile(tf, 'w', compression=zipfile.ZIP_DEFLATED) as zo: with zipfile.ZipFile(tf, 'w', compression=zipfile.ZIP_DEFLATED) as zo:
with zipfile.ZipFile(bootimg, "a") as zi: with zipfile.ZipFile(bootimg, "a") as zi:
il = zi.infolist() il = zi.infolist()
entrypoint = None metainfo = ""
extralibs = None
for info in il: for info in il:
name = info.filename name = info.filename
if name == 'entrypoint': if name == 'metainfo':
entrypoint = zi.read(info) metainfo = zi.read(info).decode('utf-8')
elif name == 'extralibs':
extralibs = zi.read(info)
else: else:
oldcontent = zi.read(info) oldcontent = zi.read(info)
zo.writestr(name, oldcontent) zo.writestr(name, oldcontent)
if entry_point_id is not None: dic = {}
entrypoint = "id {}".format(entry_point_id).encode("utf8") for line in metainfo.splitlines():
if entry_point_name is not None: if '=' in line:
entrypoint = "name {}".format(entry_point_name).encode("utf8") key, val = line.split('=', 1)
dic[key] = val
if extra_libraries is not None: if extra_libraries is not None:
extralibs = extra_libraries.encode("utf8") dic['extralibs'] = extra_libraries
new_metainfo = '\n'.join("{}={}".format(k,v) for k,v in dic.items()).encode('utf8')
if entrypoint is not None: zo.writestr("metainfo", new_metainfo)
zo.writestr("entrypoint", entrypoint)
if extralibs is not None:
zo.writestr("extralibs", extralibs)
shutil.move(tmpfilename, bootimg) shutil.move(tmpfilename, bootimg)
...@@ -45,23 +43,12 @@ if __name__ == "__main__": ...@@ -45,23 +43,12 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='''Set additional boot-image metadata.''', description='''Set additional boot-image metadata.''',
epilog='''Example: epilog='''Example:
./tools/mar.py -n @foo -l libm.so:/path/to/mylib.so my-boot-img.muref ./tools/mar.py -l libm.so:/path/to/mylib.so my-boot-img.muref
''' '''
) )
entry_point_group = parser.add_mutually_exclusive_group() entry_point_group = parser.add_mutually_exclusive_group()
entry_point_group.add_argument('-i', '--entry-point-id',
metavar="MuID",
type=int,
help='set the entry point by ID'
)
entry_point_group.add_argument('-n', '--entry-point-name',
metavar="MuName",
help='set the entry point by name'
)
parser.add_argument('-l', '--extra-libraries', parser.add_argument('-l', '--extra-libraries',
metavar="colon-separated-libs", metavar="colon-separated-libs",
help='''extra libraries to load at boot-image loading time. It is a help='''extra libraries to load at boot-image loading time. It is a
...@@ -71,4 +58,4 @@ if __name__ == "__main__": ...@@ -71,4 +58,4 @@ if __name__ == "__main__":
args = parser.parse_args() args = parser.parse_args()
mu_meta_set(args.bootimg, args.entry_point_id, args.entry_point_name, args.extra_libraries) mu_meta_set(args.bootimg, args.extra_libraries)
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment