blob: 6f66d553e7114573a6df01b2db41559181f83e83 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001# Helper/utility functions to work with the IMAGE_BOOT_FILES variable and its
2# expected behvaior with regards to the contents of the DEPLOY_DIR_IMAGE.
3#
4# The use of these functions assume that the deploy directory is populated with
5# any dependent files/etc. Such that the recipe using these functions depends
6# on the recipe that provides the files being used/queried.
7
8def boot_files_split_expand(d):
9 # IMAGE_BOOT_FILES has extra renaming info in the format '<source>;<target>'
10 for f in (d.getVar("IMAGE_BOOT_FILES") or "").split(" "):
11 parts = f.split(";", 1)
12 sources = [parts[0]]
13 if "*" in parts[0]:
14 # has glob part
15 import glob
16 deployroot = d.getVar("DEPLOY_DIR_IMAGE")
17 sources = []
18 for i in glob.glob(os.path.join(deployroot, parts[0])):
19 sources.append(os.path.basename(i))
20
21 # for all sources, yield an entry
22 for s in sources:
23 if len(parts) == 2:
24 yield s, parts[1]
25 yield s, s
26
27def boot_files_bitstream(d):
28 expectedfiles = [("bitstream", True)]
29 expectedexts = [(".bit", True), (".bin", False)]
30 # search for bitstream paths, use the renamed file. First matching is used
31 for source, target in boot_files_split_expand(d):
32 # skip boot.bin and u-boot.bin, it is not a bitstream
33 skip = ["boot.bin", "u-boot.bin"]
34 if source in skip or target in skip:
35 continue
36
37 for e, t in expectedfiles:
38 if source == e or target == e:
39 return target, t
40 for e, t in expectedexts:
41 if source.endswith(e) or target.endswith(e):
42 return target, t
43 return "", False
44
45def boot_files_dtb_filepath(d):
46 dtbs = (d.getVar("IMAGE_BOOT_FILES") or "").split(" ")
47 for source, target in boot_files_split_expand(d):
48 if target.endswith(".dtb"):
49 return target
50 return ""
51