summaryrefslogtreecommitdiffstats
path: root/scripts/lib/bsp/engine.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/bsp/engine.py')
-rw-r--r--scripts/lib/bsp/engine.py141
1 files changed, 76 insertions, 65 deletions
diff --git a/scripts/lib/bsp/engine.py b/scripts/lib/bsp/engine.py
index d406e79fe4..7431860547 100644
--- a/scripts/lib/bsp/engine.py
+++ b/scripts/lib/bsp/engine.py
@@ -1039,7 +1039,9 @@ def gen_program_machine_lines(machine, program_lines):
1039 Use the input values we got from the command line. 1039 Use the input values we got from the command line.
1040 """ 1040 """
1041 line = "machine = \"" + machine + "\"" 1041 line = "machine = \"" + machine + "\""
1042 program_lines.append(line)
1042 1043
1044 line = "layer_name = \"" + machine + "\""
1043 program_lines.append(line) 1045 program_lines.append(line)
1044 1046
1045 1047
@@ -1321,10 +1323,13 @@ def capture_context(context):
1321 return captured_context 1323 return captured_context
1322 1324
1323 1325
1324def expand_targets(context, bsp_output_dir): 1326def expand_targets(context, bsp_output_dir, expand_common=True):
1325 """ 1327 """
1326 Expand all the tags in both the common and machine-specific 1328 Expand all the tags in both the common and machine-specific
1327 'targets'. 1329 'targets'.
1330
1331 If expand_common is False, don't expand the common target (this
1332 option is used to create special-purpose layers).
1328 """ 1333 """
1329 target_files = [] 1334 target_files = []
1330 1335
@@ -1336,8 +1341,9 @@ def expand_targets(context, bsp_output_dir):
1336 bsp_path = lib_path + '/bsp' 1341 bsp_path = lib_path + '/bsp'
1337 arch_path = bsp_path + '/substrate/target/arch' 1342 arch_path = bsp_path + '/substrate/target/arch'
1338 1343
1339 common = os.path.join(arch_path, "common") 1344 if expand_common:
1340 expand_target(common, target_files, bsp_output_dir) 1345 common = os.path.join(arch_path, "common")
1346 expand_target(common, target_files, bsp_output_dir)
1341 1347
1342 arches = os.listdir(arch_path) 1348 arches = os.listdir(arch_path)
1343 if arch not in arches or arch == "common": 1349 if arch not in arches or arch == "common":
@@ -1352,21 +1358,22 @@ def expand_targets(context, bsp_output_dir):
1352 return target_files 1358 return target_files
1353 1359
1354 1360
1355def yocto_layer_create(layer_name, scripts_path, layer_output_dir, codedump, properties_file): 1361def yocto_common_create(machine, target, scripts_path, layer_output_dir, codedump, properties_file, properties_str="", expand_common=True):
1356 """ 1362 """
1357 Create yocto layer 1363 Common layer-creation code
1358 1364
1359 layer_name - user-defined layer name 1365 machine - user-defined machine name (if needed, will generate 'machine' var)
1366 target - the 'target' the layer will be based on, must be one in
1367 scripts/lib/bsp/substrate/target/arch
1360 scripts_path - absolute path to yocto /scripts dir 1368 scripts_path - absolute path to yocto /scripts dir
1361 bsp_output_dir - dirname to create for BSP 1369 layer_output_dir - dirname to create for layer
1362 codedump - dump generated code to bspgen.out 1370 codedump - dump generated code to bspgen.out
1363 properties_file - use values from here if nonempty i.e no prompting 1371 properties_file - use values from this file if nonempty i.e no prompting
1364 1372 properties_str - use values from this string if nonempty i.e no prompting
1365 arch - the arch for a generic layer is 'generic-layer', defined in 1373 expand_common - boolean, use the contents of (for bsp layers) arch/common
1366 scripts/lib/bsp/substrate/target/generic-layer
1367 """ 1374 """
1368 if os.path.exists(bsp_output_dir): 1375 if os.path.exists(layer_output_dir):
1369 print "\nBSP output dir already exists, exiting. (%s)" % bsp_output_dir 1376 print "\nlayer output dir already exists, exiting. (%s)" % layer_output_dir
1370 sys.exit(1) 1377 sys.exit(1)
1371 1378
1372 properties = None 1379 properties = None
@@ -1380,10 +1387,10 @@ def yocto_layer_create(layer_name, scripts_path, layer_output_dir, codedump, pro
1380 1387
1381 properties = json.load(infile) 1388 properties = json.load(infile)
1382 1389
1383 os.mkdir(bsp_output_dir) 1390 os.mkdir(layer_output_dir)
1384 1391
1385 context = create_context(machine, arch, scripts_path) 1392 context = create_context(machine, target, scripts_path)
1386 target_files = expand_targets(context, bsp_output_dir) 1393 target_files = expand_targets(context, layer_output_dir, expand_common)
1387 1394
1388 input_lines = gather_inputlines(target_files) 1395 input_lines = gather_inputlines(target_files)
1389 1396
@@ -1405,7 +1412,22 @@ def yocto_layer_create(layer_name, scripts_path, layer_output_dir, codedump, pro
1405 1412
1406 run_program_lines(program_lines, codedump) 1413 run_program_lines(program_lines, codedump)
1407 1414
1408 print "New %s BSP created in %s" % (arch, bsp_output_dir) 1415
1416def yocto_layer_create(layer_name, scripts_path, layer_output_dir, codedump, properties_file):
1417 """
1418 Create yocto layer
1419
1420 layer_name - user-defined layer name
1421 scripts_path - absolute path to yocto /scripts dir
1422 layer_output_dir - dirname to create for layer
1423 codedump - dump generated code to bspgen.out
1424 properties_file - use values from this file if nonempty i.e no prompting
1425 properties - use values from this string if nonempty i.e no prompting
1426 """
1427 yocto_common_create(layer_name, "layer", scripts_path, layer_output_dir, codedump, properties_file, False)
1428
1429 print "\nNew layer created in %s.\n" % (layer_output_dir)
1430 print "Don't forget to add it to your BBLAYERS (for details see %s\README)." % (layer_output_dir)
1409 1431
1410 1432
1411def yocto_bsp_create(machine, arch, scripts_path, bsp_output_dir, codedump, properties_file): 1433def yocto_bsp_create(machine, arch, scripts_path, bsp_output_dir, codedump, properties_file):
@@ -1418,49 +1440,12 @@ def yocto_bsp_create(machine, arch, scripts_path, bsp_output_dir, codedump, prop
1418 scripts_path - absolute path to yocto /scripts dir 1440 scripts_path - absolute path to yocto /scripts dir
1419 bsp_output_dir - dirname to create for BSP 1441 bsp_output_dir - dirname to create for BSP
1420 codedump - dump generated code to bspgen.out 1442 codedump - dump generated code to bspgen.out
1421 properties_file - use values from here if nonempty i.e no prompting 1443 properties_file - use values from this file if nonempty i.e no prompting
1444 properties - use values from this string if nonempty i.e no prompting
1422 """ 1445 """
1423 if os.path.exists(bsp_output_dir): 1446 yocto_common_create(machine, arch, scripts_path, bsp_output_dir, codedump, properties_file)
1424 print "\nBSP output dir already exists, exiting. (%s)" % bsp_output_dir
1425 sys.exit(1)
1426 1447
1427 properties = None 1448 print "\nNew %s BSP created in %s" % (arch, bsp_output_dir)
1428
1429 if properties_file:
1430 try:
1431 infile = open(properties_file, "r")
1432 except IOError:
1433 print "Couldn't open properties file %s for reading, exiting" % properties_file
1434 sys.exit(1)
1435
1436 properties = json.load(infile)
1437
1438 os.mkdir(bsp_output_dir)
1439
1440 context = create_context(machine, arch, scripts_path)
1441 target_files = expand_targets(context, bsp_output_dir)
1442
1443 input_lines = gather_inputlines(target_files)
1444
1445 program_lines = []
1446
1447 gen_program_header_lines(program_lines)
1448
1449 gen_initial_property_vals(input_lines, program_lines)
1450
1451 if properties:
1452 gen_supplied_property_vals(properties, program_lines)
1453
1454 gen_program_machine_lines(machine, program_lines)
1455
1456 if not properties:
1457 gen_program_input_lines(input_lines, program_lines, context)
1458
1459 gen_program_lines(target_files, program_lines)
1460
1461 run_program_lines(program_lines, codedump)
1462
1463 print "New %s BSP created in %s" % (arch, bsp_output_dir)
1464 1449
1465 1450
1466def print_dict(items, indent = 0): 1451def print_dict(items, indent = 0):
@@ -1508,15 +1493,15 @@ def get_properties(input_lines):
1508 return properties 1493 return properties
1509 1494
1510 1495
1511def yocto_bsp_list_properties(arch, scripts_path, properties_file): 1496def yocto_layer_list_properties(arch, scripts_path, properties_file, expand_common=True):
1512 """ 1497 """
1513 List the complete set of properties for all the input items in the 1498 List the complete set of properties for all the input items in the
1514 BSP. If properties_file is non-null, write the complete set of 1499 layer. If properties_file is non-null, write the complete set of
1515 properties as a nested JSON object corresponding to a possibly 1500 properties as a nested JSON object corresponding to a possibly
1516 nested dictionary. 1501 nested dictionary.
1517 """ 1502 """
1518 context = create_context("unused", arch, scripts_path) 1503 context = create_context("unused", arch, scripts_path)
1519 target_files = expand_targets(context, "unused") 1504 target_files = expand_targets(context, "unused", expand_common)
1520 1505
1521 input_lines = gather_inputlines(target_files) 1506 input_lines = gather_inputlines(target_files)
1522 1507
@@ -1605,7 +1590,7 @@ def print_values(type, values_list):
1605 print "[\"%s\", \"%s\"]" % (value[0], value[1]) 1590 print "[\"%s\", \"%s\"]" % (value[0], value[1])
1606 1591
1607 1592
1608def yocto_bsp_list_property_values(arch, property, scripts_path, properties_file): 1593def yocto_layer_list_property_values(arch, property, scripts_path, properties_file, expand_common=True):
1609 """ 1594 """
1610 List the possible values for a given input property. If 1595 List the possible values for a given input property. If
1611 properties_file is non-null, write the complete set of properties 1596 properties_file is non-null, write the complete set of properties
@@ -1614,7 +1599,7 @@ def yocto_bsp_list_property_values(arch, property, scripts_path, properties_file
1614 context = create_context("unused", arch, scripts_path) 1599 context = create_context("unused", arch, scripts_path)
1615 context["name"] = property 1600 context["name"] = property
1616 1601
1617 target_files = expand_targets(context, "unused") 1602 target_files = expand_targets(context, "unused", expand_common)
1618 1603
1619 input_lines = gather_inputlines(target_files) 1604 input_lines = gather_inputlines(target_files)
1620 1605
@@ -1697,13 +1682,39 @@ def yocto_bsp_list(args, scripts_path, properties_file):
1697 1682
1698 if len(args) == 2: 1683 if len(args) == 2:
1699 if args[1] == "properties": 1684 if args[1] == "properties":
1700 yocto_bsp_list_properties(arch, scripts_path, properties_file) 1685 yocto_layer_list_properties(arch, scripts_path, properties_file)
1701 else: 1686 else:
1702 return False 1687 return False
1703 1688
1704 if len(args) == 3: 1689 if len(args) == 3:
1705 if args[1] == "property": 1690 if args[1] == "property":
1706 yocto_bsp_list_property_values(arch, args[2], scripts_path, properties_file) 1691 yocto_layer_list_property_values(arch, args[2], scripts_path, properties_file)
1692 else:
1693 return False
1694
1695 return True
1696
1697
1698def yocto_layer_list(args, scripts_path, properties_file):
1699 """
1700 Print the complete list of input properties defined by the layer,
1701 or the possible values for a particular layer property.
1702 """
1703 if len(args) < 1:
1704 return False
1705
1706 if len(args) < 1 or len(args) > 2:
1707 return False
1708
1709 if len(args) == 1:
1710 if args[0] == "properties":
1711 yocto_layer_list_properties("layer", scripts_path, properties_file, False)
1712 else:
1713 return False
1714
1715 if len(args) == 2:
1716 if args[0] == "property":
1717 yocto_layer_list_property_values("layer", args[1], scripts_path, properties_file, False)
1707 else: 1718 else:
1708 return False 1719 return False
1709 1720