tools: mkimage: use common ALIGN to do the size align
[oweals/u-boot.git] / tools / genboardscfg.py
index c2efad55ab4609ed17c006551b2dd0ce6eee3c1e..4f6382bc7ca92c0b80f353537d34fe47f844c3ff 100755 (executable)
@@ -1,9 +1,8 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0+
 #
 # Author: Masahiro Yamada <yamada.m@jp.panasonic.com>
 #
-# SPDX-License-Identifier:     GPL-2.0+
-#
 
 """
 Converter from Kconfig and MAINTAINERS to a board database.
@@ -11,8 +10,6 @@ Converter from Kconfig and MAINTAINERS to a board database.
 Run 'tools/genboardscfg.py' to create a board database.
 
 Run 'tools/genboardscfg.py -h' for available options.
-
-Python 2.6 or later, but not Python 3.x is necessary to run this script.
 """
 
 import errno
@@ -25,7 +22,7 @@ import sys
 import tempfile
 import time
 
-sys.path.append(os.path.join(os.path.dirname(__file__), 'buildman'))
+sys.path.insert(1, os.path.join(os.path.dirname(__file__), 'buildman'))
 import kconfiglib
 
 ### constant variables ###
@@ -92,7 +89,7 @@ def output_is_new(output):
 
     # Detect a board that has been removed since the current board database
     # was generated
-    with open(output) as f:
+    with open(output, encoding="utf-8") as f:
         for line in f:
             if line[0] == '#' or line == '\n':
                 continue
@@ -119,12 +116,12 @@ class KconfigScanner:
     }
 
     def __init__(self):
-        """Scan all the Kconfig files and create a Config object."""
+        """Scan all the Kconfig files and create a Kconfig object."""
         # Define environment variables referenced from Kconfig
         os.environ['srctree'] = os.getcwd()
         os.environ['UBOOTVERSION'] = 'dummy'
         os.environ['KCONFIG_OBJDIR'] = ''
-        self._conf = kconfiglib.Config()
+        self._conf = kconfiglib.Kconfig(warn=False)
 
     def __del__(self):
         """Delete a leftover temporary file before exit.
@@ -167,7 +164,6 @@ class KconfigScanner:
                     f.write(line[colon + 1:])
 
         self._conf.load_config(self._tmpfile)
-
         try_remove(self._tmpfile)
         self._tmpfile = None
 
@@ -175,8 +171,8 @@ class KconfigScanner:
 
         # Get the value of CONFIG_SYS_ARCH, CONFIG_SYS_CPU, ... etc.
         # Set '-' if the value is empty.
-        for key, symbol in self._SYMBOL_TABLE.items():
-            value = self._conf.get_symbol(symbol).get_value()
+        for key, symbol in list(self._SYMBOL_TABLE.items()):
+            value = self._conf.syms.get(symbol).str_value
             if value:
                 params[key] = value
             else:
@@ -240,8 +236,8 @@ def scan_defconfigs(jobs=1):
     processes = []
     queues = []
     for i in range(jobs):
-        defconfigs = all_defconfigs[total_boards * i / jobs :
-                                    total_boards * (i + 1) / jobs]
+        defconfigs = all_defconfigs[total_boards * i // jobs :
+                                    total_boards * (i + 1) // jobs]
         q = multiprocessing.Queue(maxsize=-1)
         p = multiprocessing.Process(target=scan_defconfigs_for_multiprocess,
                                     args=(q, defconfigs))
@@ -288,17 +284,19 @@ class MaintainersDatabase:
           'Active', 'Orphan' or '-'.
         """
         if not target in self.database:
-            print >> sys.stderr, "WARNING: no status info for '%s'" % target
+            print("WARNING: no status info for '%s'" % target, file=sys.stderr)
             return '-'
 
         tmp = self.database[target][0]
         if tmp.startswith('Maintained'):
             return 'Active'
+        elif tmp.startswith('Supported'):
+            return 'Active'
         elif tmp.startswith('Orphan'):
             return 'Orphan'
         else:
-            print >> sys.stderr, ("WARNING: %s: unknown status for '%s'" %
-                                  (tmp, target))
+            print(("WARNING: %s: unknown status for '%s'" %
+                                  (tmp, target)), file=sys.stderr)
             return '-'
 
     def get_maintainers(self, target):
@@ -309,7 +307,7 @@ class MaintainersDatabase:
           they are separated with colons.
         """
         if not target in self.database:
-            print >> sys.stderr, "WARNING: no maintainers for '%s'" % target
+            print("WARNING: no maintainers for '%s'" % target, file=sys.stderr)
             return ''
 
         return ':'.join(self.database[target][1])
@@ -326,7 +324,7 @@ class MaintainersDatabase:
         targets = []
         maintainers = []
         status = '-'
-        for line in open(file):
+        for line in open(file, encoding="utf-8"):
             # Check also commented maintainers
             if line[:3] == '#M:':
                 line = line[1:]
@@ -400,21 +398,23 @@ def format_and_output(params_list, output):
     # ignore case when sorting
     output_lines.sort(key=str.lower)
 
-    with open(output, 'w') as f:
+    with open(output, 'w', encoding="utf-8") as f:
         f.write(COMMENT_BLOCK + '\n'.join(output_lines) + '\n')
 
-def gen_boards_cfg(output, jobs=1, force=False):
+def gen_boards_cfg(output, jobs=1, force=False, quiet=False):
     """Generate a board database file.
 
     Arguments:
       output: The name of the output file
       jobs: The number of jobs to run simultaneously
       force: Force to generate the output even if it is new
+      quiet: True to avoid printing a message if nothing needs doing
     """
     check_top_directory()
 
     if not force and output_is_new(output):
-        print "%s is up to date. Nothing to do." % output
+        if not quiet:
+            print("%s is up to date. Nothing to do." % output)
         sys.exit(0)
 
     params_list = scan_defconfigs(jobs)
@@ -435,9 +435,11 @@ def main():
                       help='the number of jobs to run simultaneously')
     parser.add_option('-o', '--output', default=OUTPUT_FILE,
                       help='output file [default=%s]' % OUTPUT_FILE)
+    parser.add_option('-q', '--quiet', action="store_true", help='run silently')
     (options, args) = parser.parse_args()
 
-    gen_boards_cfg(options.output, jobs=options.jobs, force=options.force)
+    gen_boards_cfg(options.output, jobs=options.jobs, force=options.force,
+                   quiet=options.quiet)
 
 if __name__ == '__main__':
     main()