All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 01/23] x86: Enhance the microcode tool to support header files as input
Date: Tue, 27 Jan 2015 16:59:21 +0800	[thread overview]
Message-ID: <CAEUhbmWmSA02gyCtNNn62VMH=+qeMaRBewmDoiZE9wsDdLifdQ@mail.gmail.com> (raw)
In-Reply-To: <1422321801-6743-2-git-send-email-sjg@chromium.org>

Hi Simon,

On Tue, Jan 27, 2015 at 9:22 AM, Simon Glass <sjg@chromium.org> wrote:
> Sometimes microcode is delivered as a header file. Allow the tool to
> support this as well as collecting multiple microcode blocks into a
> single update.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---

Tested-by: Bin Meng <bmeng.cn@gmail.com>

But please see my comments below.

>  tools/microcode-tool.py | 90 ++++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 70 insertions(+), 20 deletions(-)
>
> diff --git a/tools/microcode-tool.py b/tools/microcode-tool.py
> index 003716d..71c2e91 100755
> --- a/tools/microcode-tool.py
> +++ b/tools/microcode-tool.py
> @@ -76,6 +76,35 @@ def ParseFile(fname):
>          microcodes[name] = Microcode(name, data)
>      return date, license_text, microcodes
>
> +def ParseHeaderFiles(fname_list):
> +    """Parse a list of header files and return the component parts
> +
> +    Args:
> +        fname_list: List of files to parse
> +    Returns:
> +            date:         String containing date from the file's header
> +            license_text: List of text lines for the license file
> +            microcodes:   List of Microcode objects from the file
> +    """
> +    microcodes = {}
> +    license_text = []
> +    date = ''
> +    name = None
> +    for fname in fname_list:
> +        name = os.path.basename(fname).lower()
> +        name = os.path.splitext(name)[0]
> +        data = []
> +        with open(fname) as fd:
> +            for line in fd:
> +                line = line.rstrip()
> +
> +                # Omit anything after the last comma
> +                words = line.split(',')[:-1]
> +                data += [word + ',' for word in words]
> +        microcodes[name] = Microcode(name, data)
> +    return date, license_text, microcodes
> +
> +
>  def List(date, microcodes, model):
>      """List the available microcode chunks
>
> @@ -129,13 +158,13 @@ def FindMicrocode(microcodes, model):
>              break
>      return found, tried
>
> -def CreateFile(date, license_text, mcode, outfile):
> +def CreateFile(date, license_text, mcodes, outfile):
>      """Create a microcode file in U-Boot's .dtsi format
>
>      Args:
>          date:       String containing date of original microcode file
>          license:    List of text lines for the license file
> -        mcode:      Microcode object to write
> +        mcodes:      Microcode objects to write (normally only 1)
>          outfile:    Filename to write to ('-' for stdout)
>      """
>      out = '''/*%s
> @@ -159,15 +188,22 @@ intel,processor-flags = <%#x>;
>  data = <%s
>  \t>;'''
>      words = ''
> -    for i in range(len(mcode.words)):
> -        if not (i & 3):
> -            words += '\n'
> -        val = mcode.words[i]
> -        # Change each word so it will be little-endian in the FDT
> -        # This data is needed before RAM is available on some platforms so we
> -        # cannot do an endianness swap on boot.
> -        val = struct.unpack("<I", struct.pack(">I", val))[0]
> -        words += '\t%#010x' % val
> +    add_comments = len(mcodes) > 1
> +    for mcode in mcodes:
> +        if add_comments:
> +            words += '\n/* %s */' % mcode.name
> +        for i in range(len(mcode.words)):
> +            if not (i & 3):
> +                words += '\n'
> +            val = mcode.words[i]
> +            # Change each word so it will be little-endian in the FDT
> +            # This data is needed before RAM is available on some platforms so
> +            # we cannot do an endianness swap on boot.
> +            val = struct.unpack("<I", struct.pack(">I", val))[0]
> +            words += '\t%#010x' % val
> +
> +    # Use the first microcode for the headers
> +    mcode = mcodes[0]
>
>      # Take care to avoid adding a space before a tab
>      text = ''
> @@ -187,8 +223,8 @@ data = <%s
>                  print >> sys.stderr, "Creating directory '%s'" % MICROCODE_DIR
>                  os.makedirs(MICROCODE_DIR)
>              outfile = os.path.join(MICROCODE_DIR, mcode.name + '.dtsi')
> -            print >> sys.stderr, "Writing microcode for '%s' to '%s'" % (
> -                     mcode.name, outfile)
> +        print >> sys.stderr, "Writing microcode for '%s' to '%s'" % (
> +                ', '.join([mcode.name for mcode in mcodes]), outfile)
>          with open(outfile, 'w') as fd:
>              print >> fd, out % tuple(args)
>
> @@ -198,8 +234,12 @@ def MicrocodeTool():
>      parser = OptionParser()
>      parser.add_option('-d', '--mcfile', type='string', action='store',
>                      help='Name of microcode.dat file')
> +    parser.add_option('-H', '--headerfile', type='string', action='append',
> +                    help='Name of .h file containing microcode')
>      parser.add_option('-m', '--model', type='string', action='store',
> -                    help='Model name to extract')
> +                    help="Model name to extract ('all' for all)")
> +    parser.add_option('-M', '--multiple', type='string', action='store',
> +                    help="Allow output of multiple models")
>      parser.add_option('-o', '--outfile', type='string', action='store',
>                      help='Filename to use for output (- for stdout), default is'
>                      ' %s/<name>.dtsi' % MICROCODE_DIR)
> @@ -224,9 +264,14 @@ def MicrocodeTool():
>      if cmd not in commands:
>          parser.error("Unknown command '%s'" % cmd)
>
> -    if not options.mcfile:
> -        parser.error('You must specify a microcode file')
> -    date, license_text, microcodes = ParseFile(options.mcfile)
> +    if (not not options.mcfile) != (not not options.mcfile):
> +        parser.error("You must specify either header files or a microcode file, not both")
> +    if options.headerfile:
> +        date, license_text, microcodes = ParseHeaderFiles(options.headerfile)
> +    elif options.mcfile:
> +        date, license_text, microcodes = ParseFile(options.mcfile)
> +    else:
> +        parser.error('You must specify a microcode file (or header files)')
>
>      if cmd == 'list':
>          List(date, microcodes, options.model)
> @@ -236,16 +281,21 @@ def MicrocodeTool():
>          if not options.model:
>              parser.error('You must specify a model to create')
>          model = options.model.lower()
> -        mcode_list, tried = FindMicrocode(microcodes, model)
> +        if options.model == 'all':
> +            options.multiple = True
> +            mcode_list = microcodes.values()
> +            tried = []
> +        else:
> +            mcode_list, tried = FindMicrocode(microcodes, model)
>          if not mcode_list:
>              parser.error("Unknown model '%s' (%s) - try 'list' to list" %
>                          (model, ', '.join(tried)))
> -        if len(mcode_list) > 1:
> +        if not options.multiple and len(mcode_list) > 1:
>              parser.error("Ambiguous model '%s' (%s) matched %s - try 'list' "
>                          "to list or specify a particular file" %
>                          (model, ', '.join(tried),
>                          ', '.join([m.name for m in mcode_list])))
> -        CreateFile(date, license_text, mcode_list[0], options.outfile)
> +        CreateFile(date, license_text, mcode_list, options.outfile)
>      else:
>          parser.error("Unknown command '%s'" % cmd)
>
> --

My testing results show that, compared to '-d microcode.dat' approach,
generated microcode.dtsi using '-H' does not have license header and
date set. Is this intentional?

Regards,
Bin

  reply	other threads:[~2015-01-27  8:59 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-27  1:22 [U-Boot] [PATCH 0/23] x86: Add bare support for Intel Minnowboard Max Simon Glass
2015-01-27  1:22 ` [U-Boot] [PATCH 01/23] x86: Enhance the microcode tool to support header files as input Simon Glass
2015-01-27  8:59   ` Bin Meng [this message]
2015-01-27 15:12     ` Simon Glass
2015-01-28  1:10       ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 02/23] pci: Add a function to find a device by class Simon Glass
2015-01-27  9:53   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 03/23] x86: pci: Add PCI IDs for Minnowboard Max Simon Glass
2015-01-27  9:44   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 04/23] x86: video: Enable video " Simon Glass
2015-01-27  9:45   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 05/23] usb: pci: Use pci_find_class() to find the device Simon Glass
2015-01-27  9:55   ` Bin Meng
2015-01-27 17:50   ` Marek Vasut
2015-01-27 20:53     ` Simon Glass
2015-01-27 21:16       ` Marek Vasut
2015-01-27  1:23 ` [U-Boot] [PATCH 06/23] usb: pci: Add XHCI driver for PCI Simon Glass
2015-01-27 10:06   ` Bin Meng
2015-01-27 17:57   ` Marek Vasut
2015-01-27 20:52     ` Simon Glass
2015-01-27 21:18       ` Marek Vasut
2015-01-27  1:23 ` [U-Boot] [PATCH 07/23] x86: Add an option to enabling building a ROM file Simon Glass
2015-01-27 10:14   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 08/23] x86: Make MMCONF_BASE_ADDRESS common across x86 Simon Glass
2015-01-27 10:22   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 09/23] x86: video: Allow video ROM execution to fall back to the other method Simon Glass
2015-01-27 10:37   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 10/23] x86: bootstage: Add time measurement for vesa start-up Simon Glass
2015-01-27 10:42   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 11/23] x86: Move common FSP code into a common location Simon Glass
2015-01-27 10:52   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 12/23] x86: Adjust the FSP types slightly Simon Glass
2015-01-27 12:25   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 13/23] x86: Make CAR and DRAM FSP code common Simon Glass
2015-01-27 12:27   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 14/23] x86: Move common FSP functions into a common file Simon Glass
2015-01-27 12:20   ` Bin Meng
2015-01-27 15:15     ` Simon Glass
2015-01-28  1:12       ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 15/23] x86: Remove unnecessary casts and fix comment typos Simon Glass
2015-01-27 12:32   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 16/23] x86: Allow FSP Kconfig settings for all x86 Simon Glass
2015-01-27 12:45   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 17/23] x86: Define cache line size Simon Glass
2015-01-27 13:05   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 18/23] x86: Allow a UART to be set up before the FSP is ready Simon Glass
2015-01-27 13:12   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 19/23] x86: spi: Support ValleyView in ICH SPI driver Simon Glass
2015-01-27 14:00   ` Bin Meng
2015-01-28  5:17     ` Simon Glass
2015-01-28  6:02       ` Bin Meng
2015-01-28 23:45         ` Simon Glass
2015-01-27  1:23 ` [U-Boot] [PATCH 20/23] scsi: bootstage: Measure time taken to scan the bus Simon Glass
2015-01-27 13:20   ` Bin Meng
2015-01-27 17:38   ` Rob Herring
2015-01-28  1:20     ` Bin Meng
2015-01-28  5:07       ` Simon Glass
2015-01-27  1:23 ` [U-Boot] [PATCH 21/23] x86: Enable bootstage features Simon Glass
2015-01-27 13:26   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 22/23] x86: Add some documentation on how to port U-Boot on x86 Simon Glass
2015-01-27  8:51   ` Bin Meng
2015-01-27  1:23 ` [U-Boot] [PATCH 23/23] x86: Add support for Intel Minnowboard Max Simon Glass
2015-01-27 14:25   ` Bin Meng
2015-01-27 14:31 ` [U-Boot] [PATCH 0/23] x86: Add bare " Bin Meng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEUhbmWmSA02gyCtNNn62VMH=+qeMaRBewmDoiZE9wsDdLifdQ@mail.gmail.com' \
    --to=bmeng.cn@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.