blob: af4403877e2f408da19d0b6d8cadab9f250dca7e [file] [log] [blame]
John Stultzaccad872017-07-06 13:56:07 -07001#!/usr/bin/python
Vishal Bhoj9a67d912016-06-09 10:02:07 +01002
3import sys, os, argparse, ConfigParser
4
5default_filename='platforms.config'
6
7def list_platforms():
8 for p in platforms: print p
9
10def shortlist_platforms():
11 for p in platforms: print p,
12
13def get_images():
14 if args.platform:
15 try:
16 value = config.get(args.platform, "EXTRA_FILES")
17 print value,
18 except:
19 pass
20 try:
21 value = config.get(args.platform, "BUILD_ATF")
22 if value == "yes":
23 print "bl1.bin fip.bin"
24 return True
25 except:
26 try:
27 value = config.get(args.platform, "UEFI_BIN")
28 print value
29 return True
30 except:
31 print "No images found!"
32 else:
33 print "No platform specified!"
34
35 return False
36
37def get_option():
38 if args.platform:
39 if args.option:
40 try:
41 value = config.get(args.platform, args.option)
42 if value:
43 print value
44 return True
45 except:
46 return True # Option not found, return True, and no output
47 else:
48 print "No option specified!"
49 else:
50 print "No platform specified!"
51 return False
52
53parser = argparse.ArgumentParser(description='Parses platform configuration for Linaro UEFI build scripts.')
54parser.add_argument('-c', '--config-file', help='Specify a non-default platform config file.', required=False)
55parser.add_argument('-p', '--platform', help='Read configuration for PLATFORM only.', required=False)
56parser.add_argument('command', action="store", help='Action to perform')
57parser.add_argument('-o', '--option', help='Option to retreive')
58
59args = parser.parse_args()
60if args.config_file:
61 config_filename = args.config_file
62else:
63 config_filename = os.path.dirname(os.path.realpath(sys.argv[0])) + '/' + default_filename
64
65config = ConfigParser.ConfigParser()
66config.read(config_filename)
67
68platforms = config.sections()
69
70commands = {"shortlist": shortlist_platforms,
71 "list": list_platforms,
72 "images": get_images,
73 "get": get_option}
74
75try:
76 retval = commands[args.command]()
77except:
78 print ("Unrecognized command '%s'" % args.command)
79
80if retval != True:
81 sys.exit(1)