mirror of
https://gitee.com/Vancouver2017/luban-lite.git
synced 2025-12-17 17:48:55 +00:00
v1.0.3
This commit is contained in:
@@ -11,6 +11,7 @@ from collections import OrderedDict
|
||||
|
||||
VERBOSE = False
|
||||
|
||||
|
||||
def parse_image_cfg(cfgfile):
|
||||
""" Load image configuration file
|
||||
Args:
|
||||
@@ -33,6 +34,7 @@ def parse_image_cfg(cfgfile):
|
||||
cfg = json.loads(jsonstr, object_pairs_hook=OrderedDict)
|
||||
return cfg
|
||||
|
||||
|
||||
def size_str_to_int(size_str):
|
||||
if "k" in size_str or "K" in size_str:
|
||||
numstr = re.sub(r"[^0-9]", "", size_str)
|
||||
@@ -49,9 +51,11 @@ def size_str_to_int(size_str):
|
||||
return 0
|
||||
return int(size_str, 10)
|
||||
|
||||
|
||||
def aic_create_parts_json(cfg):
|
||||
mtd = ""
|
||||
ubi = ""
|
||||
nftl = ""
|
||||
gpt = ""
|
||||
|
||||
part_str = '{\n\t"partitions": {\n'
|
||||
@@ -68,6 +72,7 @@ def aic_create_parts_json(cfg):
|
||||
if len(partitions) == 0:
|
||||
print("Partition table is empty")
|
||||
sys.exit(1)
|
||||
|
||||
for part in partitions:
|
||||
itemstr = ""
|
||||
if "size" not in partitions[part]:
|
||||
@@ -81,9 +86,12 @@ def aic_create_parts_json(cfg):
|
||||
itemstr += "@{}".format(partitions[part]["offset"])
|
||||
part_offs = size_str_to_int(partitions[part]["offset"])
|
||||
itemstr += "({})".format(part)
|
||||
|
||||
mtd += itemstr + ","
|
||||
if "ubi" in partitions[part]:
|
||||
part_type.append("ubi")
|
||||
if "ubi" not in part_type:
|
||||
part_type.append("ubi")
|
||||
|
||||
volumes = partitions[part]["ubi"]
|
||||
if len(volumes) == 0:
|
||||
print("Volume of {} is empty".format(part))
|
||||
@@ -100,11 +108,34 @@ def aic_create_parts_json(cfg):
|
||||
ubi += itemstr + ","
|
||||
ubi = ubi[0:-1] + ";"
|
||||
|
||||
if "nftl" in partitions[part]:
|
||||
if "nftl" not in part_type:
|
||||
part_type.append("nftl")
|
||||
nftl_volumes = partitions[part]["nftl"]
|
||||
if len(nftl_volumes) == 0:
|
||||
print("Volume of {} is empty".format(part))
|
||||
sys.exit(1)
|
||||
nftl += "{}:".format(part)
|
||||
for vol in nftl_volumes:
|
||||
itemstr = ""
|
||||
if "size" not in nftl_volumes[vol]:
|
||||
print("No size value for nftl volume: {}".format(vol))
|
||||
itemstr += nftl_volumes[vol]["size"]
|
||||
if "offset" in nftl_volumes[vol]:
|
||||
itemstr += "@{}".format(nftl_volumes[vol]["offset"])
|
||||
itemstr += "({})".format(vol)
|
||||
nftl += itemstr + ","
|
||||
nftl = nftl[0:-1] + ";"
|
||||
|
||||
mtd = mtd[0:-1]
|
||||
part_str += "\t\t\"mtd\" : \"{}\",\n".format(mtd)
|
||||
if len(ubi) > 0:
|
||||
ubi = ubi[0:-1]
|
||||
part_str += "\t\t\"ubi\" : \"{}\",\n".format(ubi)
|
||||
if len(nftl) > 0:
|
||||
nftl = nftl[0:-1]
|
||||
part_str += "\t\t\"nftl\" : \"{}\",\n".format(nftl)
|
||||
|
||||
elif media_type == "mmc":
|
||||
part_type.append("gpt")
|
||||
partitions = cfg[media_type]["partitions"]
|
||||
@@ -131,9 +162,11 @@ def aic_create_parts_json(cfg):
|
||||
part_str += "\t}\n}"
|
||||
return part_str
|
||||
|
||||
|
||||
def aic_create_parts_string(cfg):
|
||||
mtd = ""
|
||||
ubi = ""
|
||||
nftl = ""
|
||||
gpt = ""
|
||||
|
||||
part_str = ""
|
||||
@@ -182,14 +215,38 @@ def aic_create_parts_string(cfg):
|
||||
itemstr += "({})".format(vol)
|
||||
ubi += itemstr + ","
|
||||
ubi = ubi[0:-1] + ";"
|
||||
|
||||
if "nftl" in partitions[part]:
|
||||
nftl_volumes = partitions[part]["nftl"]
|
||||
if len(nftl_volumes) == 0:
|
||||
print("Volume of {} is empty".format(part))
|
||||
sys.exit(1)
|
||||
nftl += "{}:".format(part)
|
||||
for vol in nftl_volumes:
|
||||
itemstr = ""
|
||||
if "size" not in nftl_volumes[vol]:
|
||||
print("No size value for ubi volume: {}".format(vol))
|
||||
itemstr += nftl_volumes[vol]["size"]
|
||||
if "offset" in nftl_volumes[vol]:
|
||||
itemstr += "@{}".format(nftl_volumes[vol]["offset"])
|
||||
itemstr += "({})".format(vol)
|
||||
nftl += itemstr + ","
|
||||
nftl = nftl[0:-1] + ";"
|
||||
|
||||
if media_type == "spi-nor":
|
||||
fal_cfg += " {}FAL_PART_MAGIC_WORD, \"{}\", FAL_USING_NOR_FLASH_DEV_NAME, {},{},0{}, \\\n".format("{", part, part_offs, part_size, "}")
|
||||
fal_cfg += " {}FAL_PART_MAGIC_WORD, \"{}\",".format("{", part)
|
||||
fal_cfg += "FAL_USING_NOR_FLASH_DEV_NAME, "
|
||||
fal_cfg += "{},{},0{}, \\\n".format(part_offs, part_size, "}")
|
||||
|
||||
mtd = mtd[0:-1]
|
||||
part_str = "#define IMAGE_CFG_JSON_PARTS_MTD \"{}\"\n".format(mtd)
|
||||
if len(ubi) > 0:
|
||||
ubi = ubi[0:-1]
|
||||
part_str += "#define IMAGE_CFG_JSON_PARTS_UBI \"{}\"\n".format(ubi)
|
||||
if len(nftl) > 0:
|
||||
nftl = nftl[0:-1]
|
||||
part_str += "#define IMAGE_CFG_JSON_PARTS_NFTL \"{}\"\n".format(nftl)
|
||||
|
||||
if media_type == "spi-nor":
|
||||
fal_cfg += "}\n#endif\n"
|
||||
part_str += fal_cfg
|
||||
@@ -239,9 +296,10 @@ if __name__ == "__main__":
|
||||
f.write(parts)
|
||||
|
||||
parts = aic_create_parts_string(cfg)
|
||||
if args.outfile == None:
|
||||
if args.outfile is None:
|
||||
print(parts)
|
||||
else:
|
||||
print("args.outfile: ", args.outfile)
|
||||
with open(args.outfile, "w+") as f:
|
||||
f.write("/* This is an auto generated file, please don't modify it. */\n\n")
|
||||
f.write("#ifndef _AIC_IMAGE_CFG_JSON_PARTITION_TABLE_H_\n")
|
||||
|
||||
Reference in New Issue
Block a user