checkpatch.pl: Warn if the flattree API is used
[oweals/u-boot.git] / tools / microcode-tool.py
index 71c2e91566b54605282a35d4394fc5d5a3c204cd..24c02c4fca1400de4cca31630161204170a1fe33 100755 (executable)
@@ -1,9 +1,8 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0+
 #
 # Copyright (c) 2014 Google, Inc
 #
-# SPDX-License-Identifier:      GPL-2.0+
-#
 # Intel microcode update tool
 
 from optparse import OptionParser
@@ -95,9 +94,23 @@ def ParseHeaderFiles(fname_list):
         name = os.path.splitext(name)[0]
         data = []
         with open(fname) as fd:
+            license_start = False
+            license_end = False
             for line in fd:
                 line = line.rstrip()
 
+                if len(line) >= 2:
+                    if line[0] == '/' and line[1] == '*':
+                        license_start = True
+                        continue
+                    if line[0] == '*' and line[1] == '/':
+                        license_end = True
+                        continue
+                if license_start and not license_end:
+                    # Ignore blank line
+                    if len(line) > 0:
+                        license_text.append(line)
+                    continue
                 # Omit anything after the last comma
                 words = line.split(',')[:-1]
                 data += [word + ',' for word in words]
@@ -113,15 +126,15 @@ def List(date, microcodes, model):
         microcodes:     Dict of Microcode objects indexed by name
         model:          Model string to search for, or None
     """
-    print 'Date: %s' % date
+    print('Date: %s' % date)
     if model:
         mcode_list, tried = FindMicrocode(microcodes, model.lower())
-        print 'Matching models %s:' % (', '.join(tried))
+        print('Matching models %s:' % (', '.join(tried)))
     else:
-        print 'All models:'
-        mcode_list = [microcodes[m] for m in microcodes.keys()]
+        print('All models:')
+        mcode_list = [microcodes[m] for m in list(microcodes.keys())]
     for mcode in mcode_list:
-        print '%-20s: model %s' % (mcode.name, mcode.model)
+        print('%-20s: model %s' % (mcode.name, mcode.model))
 
 def FindMicrocode(microcodes, model):
     """Find all the microcode chunks which match the given model.
@@ -151,7 +164,7 @@ def FindMicrocode(microcodes, model):
     for i in range(3):
         abbrev = model[:-i] if i else model
         tried.append(abbrev)
-        for mcode in microcodes.values():
+        for mcode in list(microcodes.values()):
             if mcode.model.startswith(abbrev):
                 found.append(mcode)
         if found:
@@ -216,17 +229,17 @@ data = <%s
     args += [mcode.words[i] for i in range(7)]
     args.append(words)
     if outfile == '-':
-        print out % tuple(args)
+        print(out % tuple(args))
     else:
         if not outfile:
             if not os.path.exists(MICROCODE_DIR):
-                print >> sys.stderr, "Creating directory '%s'" % MICROCODE_DIR
+                print("Creating directory '%s'" % MICROCODE_DIR, file=sys.stderr)
                 os.makedirs(MICROCODE_DIR)
             outfile = os.path.join(MICROCODE_DIR, mcode.name + '.dtsi')
-        print >> sys.stderr, "Writing microcode for '%s' to '%s'" % (
-                ', '.join([mcode.name for mcode in mcodes]), outfile)
+        print("Writing microcode for '%s' to '%s'" % (
+                ', '.join([mcode.name for mcode in mcodes]), outfile), file=sys.stderr)
         with open(outfile, 'w') as fd:
-            print >> fd, out % tuple(args)
+            print(out % tuple(args), file=fd)
 
 def MicrocodeTool():
     """Run the microcode tool"""
@@ -276,14 +289,14 @@ def MicrocodeTool():
     if cmd == 'list':
         List(date, microcodes, options.model)
     elif cmd == 'license':
-        print '\n'.join(license_text)
+        print('\n'.join(license_text))
     elif cmd == 'create':
         if not options.model:
             parser.error('You must specify a model to create')
         model = options.model.lower()
         if options.model == 'all':
             options.multiple = True
-            mcode_list = microcodes.values()
+            mcode_list = list(microcodes.values())
             tried = []
         else:
             mcode_list, tried = FindMicrocode(microcodes, model)