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

updated, using metainfo

parent 87632589
......@@ -6,37 +6,35 @@ import tempfile
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:
tmpfilename =
with zipfile.ZipFile(tf, 'w', compression=zipfile.ZIP_DEFLATED) as zo:
with zipfile.ZipFile(bootimg, "a") as zi:
il = zi.infolist()
entrypoint = None
extralibs = None
metainfo = ""
for info in il:
name = info.filename
if name == 'entrypoint':
entrypoint =
elif name == 'extralibs':
extralibs =
if name == 'metainfo':
metainfo ='utf-8')
oldcontent =
zo.writestr(name, oldcontent)
if entry_point_id is not None:
entrypoint = "id {}".format(entry_point_id).encode("utf8")
if entry_point_name is not None:
entrypoint = "name {}".format(entry_point_name).encode("utf8")
dic = {}
for line in metainfo.splitlines():
if '=' in line:
key, val = line.split('=', 1)
dic[key] = val
if extra_libraries is not None:
extralibs = extra_libraries.encode("utf8")
if entrypoint is not None:
zo.writestr("entrypoint", entrypoint)
if extralibs is not None:
zo.writestr("extralibs", extralibs)
dic['extralibs'] = extra_libraries
new_metainfo = '\n'.join("{}={}".format(k,v) for k,v in dic.items()).encode('utf8')
zo.writestr("metainfo", new_metainfo)
shutil.move(tmpfilename, bootimg)
......@@ -45,23 +43,12 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='''Set additional boot-image metadata.''',
./tools/ -n @foo -l my-boot-img.muref
./tools/ -l my-boot-img.muref
entry_point_group = parser.add_mutually_exclusive_group()
entry_point_group.add_argument('-i', '--entry-point-id',
help='set the entry point by ID'
entry_point_group.add_argument('-n', '--entry-point-name',
help='set the entry point by name'
parser.add_argument('-l', '--extra-libraries',
help='''extra libraries to load at boot-image loading time. It is a
......@@ -71,4 +58,4 @@ if __name__ == "__main__":
args = parser.parse_args()
mu_meta_set(args.bootimg, args.entry_point_id, args.entry_point_name, args.extra_libraries)
\ No newline at end of file
mu_meta_set(args.bootimg, args.extra_libraries)
\ 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