Skip to content

Commit e50bd1f

Browse files
committed
gen_contents: prefix file paths for multi-disk
In multi-disk layouts, partitions.xml files are in per-storage subdirs (e.g. spinor-nvme/spinor/partitions.xml). Set file_path from the relative path between the output directory and the partitions.xml directory. Single-disk layouts where both files are in the same directory are unaffected (prefix is empty). Signed-off-by: Loïc Minier <loic.minier@oss.qualcomm.com>
1 parent ddd96d7 commit e50bd1f

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

gen_contents.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def usage():
1212
print(
1313
(
14-
"\n\tUsage: %s -t <template> -p <partitions_xml_path> -o <output> \n\tVersion 0.1\n"
14+
"\n\tUsage: %s -t <template> -p <partitions_xml_path> -o <output> [-f <file_prefix>]\n\tVersion 0.1\n"
1515
% (sys.argv[0])
1616
)
1717
)
@@ -31,7 +31,7 @@ def ParseXML(XMLFile):
3131
return None
3232

3333

34-
def UpdateMetaData(TemplateRoot, PartitionRoot, BuildId):
34+
def UpdateMetaData(TemplateRoot, PartitionRoot, BuildId, FilePrefix=""):
3535
ChipIdList = TemplateRoot.findall("product_info/chipid")
3636
DefaultStorageType = None
3737
for ChipId in ChipIdList:
@@ -54,8 +54,10 @@ def _add_file_elements(parent_element, pathname, file_path_flavor=None):
5454
"""Helper function to add file_name and file_path sub-elements."""
5555
file_name_text = os.path.basename(pathname)
5656
file_path_text = os.path.dirname(pathname)
57-
if not file_path_text: # no directory, use explicit . as current dir
58-
file_path_text = "."
57+
if not file_path_text:
58+
file_path_text = FilePrefix if FilePrefix else "."
59+
elif FilePrefix:
60+
file_path_text = FilePrefix + "/" + file_path_text
5961

6062
new_file_name = ET.SubElement(parent_element, "file_name")
6163
new_file_name.text = file_name_text
@@ -133,7 +135,8 @@ def _add_file_elements(parent_element, pathname, file_path_flavor=None):
133135
usage()
134136
try:
135137
build_id = ""
136-
opts, rem = getopt.getopt(sys.argv[1:], "t:p:o:b:")
138+
file_prefix_override = None
139+
opts, rem = getopt.getopt(sys.argv[1:], "t:p:o:b:f:")
137140
for opt, arg in opts:
138141
if opt in ["-t"]:
139142
template = arg
@@ -143,6 +146,8 @@ def _add_file_elements(parent_element, pathname, file_path_flavor=None):
143146
output_xml = arg
144147
elif opt in ["-b"]:
145148
build_id = arg
149+
elif opt in ["-f"]:
150+
file_prefix_override = arg
146151
else:
147152
usage()
148153
except Exception as argerr:
@@ -155,7 +160,19 @@ def _add_file_elements(parent_element, pathname, file_path_flavor=None):
155160
print("Selected Partition XML: " + partition_xml)
156161
partition_root = ParseXML(partition_xml)
157162

158-
UpdateMetaData(xml_root, partition_root, build_id)
163+
# compute file prefix: relative path from output dir to partitions.xml dir
164+
# e.g., output=spinor-nvme/contents.xml, partition=spinor-nvme/disk0/partitions.xml
165+
# gives prefix "disk0". Can be overridden with -f.
166+
if file_prefix_override is not None:
167+
file_prefix = file_prefix_override
168+
else:
169+
output_dir = os.path.dirname(os.path.abspath(output_xml))
170+
partition_dir = os.path.dirname(os.path.abspath(partition_xml))
171+
file_prefix = os.path.relpath(partition_dir, output_dir)
172+
if file_prefix == ".":
173+
file_prefix = ""
174+
175+
UpdateMetaData(xml_root, partition_root, build_id, file_prefix)
159176

160177
OutputTree = ET.ElementTree(xml_root)
161178
ET.indent(OutputTree, space="\t", level=0)

0 commit comments

Comments
 (0)