1
1
#!/usr/bin/env python3
2
+
3
+ # vim: ai:ts=4:sw=4
4
+
2
5
import sys
3
6
from os import walk
4
7
import os
5
8
import re
6
9
import yaml
7
10
import pprint
11
+ import argparse
8
12
9
13
from devicetree import parse_file
10
14
@@ -503,7 +507,7 @@ def print_key_value(k, v, tabstop):
503
507
504
508
return
505
509
506
- def generate_include_file (defs ):
510
+ def generate_include_file (defs , fixup ):
507
511
compatible = reduced ['/' ]['props' ]['compatible' ][0 ]
508
512
509
513
sys .stdout .write ("/**************************************************\n " )
@@ -539,18 +543,40 @@ def generate_include_file(defs):
539
543
print_key_value (prop , defs [node ].get (prop ), maxtabstop )
540
544
sys .stdout .write ("\n " )
541
545
542
- sys .stdout .write ("#endif\n " );
543
-
544
- def main (args ):
545
- if len (args ) < 2 :
546
- print ('Usage: %s filename.dts path_to_yaml' % args [0 ])
546
+ if fixup and os .path .exists (fixup ):
547
+ sys .stdout .write ("\n " )
548
+ sys .stdout .write ("/* Following definitions fixup the generated include */\n " )
549
+ try :
550
+ with open (fixup , "r" ) as fd :
551
+ for line in fd .readlines ():
552
+ sys .stdout .write (line )
553
+ sys .stdout .write ("\n " )
554
+ except :
555
+ raise Exception ("Input file " + os .path .abspath (fixup ) + " does not exist." )
556
+
557
+ sys .stdout .write ("#endif\n " )
558
+
559
+ def parse_arguments ():
560
+
561
+ parser = argparse .ArgumentParser (description = __doc__ ,
562
+ formatter_class = argparse .RawDescriptionHelpFormatter )
563
+ parser .add_argument ("-d" , "--dts" , help = "DTS file" )
564
+ parser .add_argument ("-y" , "--yaml" , help = "YAML file" )
565
+ parser .add_argument ("-f" , "--fixup" , help = "Fixup file" )
566
+
567
+ return parser .parse_args ()
568
+
569
+ def main ():
570
+ args = parse_arguments ()
571
+ if not args .dts or not args .yaml :
572
+ print ('Usage: %s -d filename.dts -y path_to_yaml' % sys .argv [0 ])
547
573
return 1
548
574
549
575
try :
550
- with open (args [ 1 ] , "r" ) as fd :
576
+ with open (args . dts , "r" ) as fd :
551
577
d = parse_file (fd )
552
578
except :
553
- raise Exception ("Input file " + os .path .abspath (args [ 1 ] ) + " does not exist." )
579
+ raise Exception ("Input file " + os .path .abspath (args . dts ) + " does not exist." )
554
580
555
581
# compress list to nodes w/ paths, add interrupt parent
556
582
compress_nodes (d ['/' ], '/' )
@@ -572,7 +598,7 @@ def main(args):
572
598
573
599
# scan YAML files and find the ones we are interested in
574
600
yaml_files = []
575
- for (dirpath , dirnames , filenames ) in walk (args [ 2 ] ):
601
+ for (dirpath , dirnames , filenames ) in walk (args . yaml ):
576
602
yaml_files .extend ([f for f in filenames if re .match ('.*\.yaml\Z' , f )])
577
603
yaml_files = [dirpath + '/' + t for t in yaml_files ]
578
604
break
@@ -628,9 +654,7 @@ def main(args):
628
654
extract_reg_prop (chosen ['zephyr,sram' ], None , defs , "CONFIG_SRAM" , 1024 )
629
655
630
656
# generate include file
631
- generate_include_file (defs )
657
+ generate_include_file (defs , args . fixup )
632
658
633
659
if __name__ == '__main__' :
634
- # test1.py executed as script
635
- # do something
636
- sys .exit (main (sys .argv ))
660
+ main ()
0 commit comments