All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Jacques Hiblot <jjhiblot@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH v2 1/3] tools: moveconfig: Add an option to build a fuller database of options
Date: Wed, 3 Oct 2018 15:53:50 +0200	[thread overview]
Message-ID: <1538574832-21910-2-git-send-email-jjhiblot@ti.com> (raw)
In-Reply-To: <1538574832-21910-1-git-send-email-jjhiblot@ti.com>

"moveconfig -b" will build a database of config options based on the
content of include/config/auto.conf that reflects the .config

Add a new option '-B' that does essentially the same, except that it uses
the content of u-boot.cfg, spl/u-boot.cfg and tpl/u-boot.cfg.
This allows to get the options from .config AND the headers for all the
possible binary types (u-boot, SPL and TPL)

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---

Changes in v2: None

 tools/moveconfig.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 49 insertions(+), 7 deletions(-)

diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index caa81ac..85c2b8b 100755
--- a/tools/moveconfig.py
+++ b/tools/moveconfig.py
@@ -1151,9 +1151,17 @@ class Slot:
                                    self.ps.stderr.read())
         self.finish(False)
 
+    def remove_cfg_files(self):
+        for base in ['.', 'spl', 'tpl']:
+            try:
+                os.remove(os.path.join(self.build_dir, base, "u-boot.cfg"))
+            except:
+                pass
+
     def do_defconfig(self):
         """Run 'make <board>_defconfig' to create the .config file."""
-
+        # first remove old cfg files that may have been produced earlier
+        self.remove_cfg_files()
         cmd = list(self.make_cmd)
         cmd.append(self.defconfig)
         self.ps = subprocess.Popen(cmd, stdout=self.devnull,
@@ -1182,15 +1190,43 @@ class Slot:
                                    cwd=self.current_src_dir)
         self.state = STATE_AUTOCONF
 
+
     def do_build_db(self):
         """Add the board to the database"""
-        configs = {}
-        with open(os.path.join(self.build_dir, AUTO_CONF_PATH)) as fd:
-            for line in fd.readlines():
+        def conf_to_dic(filename):
+            configs = {}
+            if not os.path.isfile(filename):
+                return None
+
+            try:
+                if filename.endswith("u-boot.cfg"):
+                        with tempfile.NamedTemporaryFile(delete = True) as fd:
+                            lines = subprocess.check_call("sed -n -f tools/scripts/define2mk.sed {}".format(filename).split(), stdout = fd)
+                            fd.seek(0)
+                            lines = fd.readlines()
+                else:
+                        with open(filename, "r") as fd:
+                            lines = fd.readlines()
+            except:
+                return None
+
+            for line in lines:
                 if line.startswith('CONFIG'):
                     config, value = line.split('=', 1)
                     configs[config] = value.rstrip()
-        self.db_queue.put([self.defconfig, configs])
+            return configs
+
+        list_of_conf = []
+        if self.options.build_full_db:
+            list_of_conf.append((self.defconfig,"u-boot.cfg"))
+            list_of_conf.append(("{} SPL".format(self.defconfig),"spl/u-boot.cfg"))
+            list_of_conf.append(("{} TPL".format(self.defconfig),"tpl/u-boot.cfg"))
+        else:
+            list_of_conf.append((self.defconfig,AUTO_CONF_PATH))
+        for name,conf_file in list_of_conf:
+            configs = conf_to_dic(os.path.join(self.build_dir, conf_file))
+            if configs:
+                self.db_queue.put([name, configs])
         self.finish(True)
 
     def do_savedefconfig(self):
@@ -1770,7 +1806,9 @@ def main():
                       help="don't show options which are already marked as "
                       'implying others')
     parser.add_option('-b', '--build-db', action='store_true', default=False,
-                      help='build a CONFIG database')
+                      help='build a CONFIG database based only on auto.conf')
+    parser.add_option('-B', '--build-full-db', action='store_true', default=False,
+                      help='build a CONFIG database based only on u-boot.cfg (and also for SPL and TPL)')
     parser.add_option('-c', '--color', action='store_true', default=False,
                       help='display the log in color')
     parser.add_option('-C', '--commit', action='store_true', default=False,
@@ -1807,6 +1845,9 @@ def main():
 
     (options, configs) = parser.parse_args()
 
+    if options.build_full_db:
+        options.build_db = True
+
     if len(configs) == 0 and not any((options.force_sync, options.build_db,
                                       options.imply)):
         parser.print_usage()
@@ -1875,7 +1916,8 @@ def main():
 
     if options.build_db:
         with open(CONFIG_DATABASE, 'w') as fd:
-            for defconfig, configs in config_db.iteritems():
+            for defconfig in sorted(config_db.keys()):
+                configs = config_db[defconfig]
                 fd.write('%s\n' % defconfig)
                 for config in sorted(configs.keys()):
                     fd.write('   %s=%s\n' % (config, configs[config]))
-- 
2.7.4

  reply	other threads:[~2018-10-03 13:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-03 13:53 [U-Boot] [RFC PATCH v2 0/3] python tools to inspect configs Jean-Jacques Hiblot
2018-10-03 13:53 ` Jean-Jacques Hiblot [this message]
2018-10-09 16:20   ` [U-Boot] [RFC PATCH v2 1/3] tools: moveconfig: Add an option to build a fuller database of options Simon Glass
2018-10-03 13:53 ` [U-Boot] [RFC PATCH v2 2/3] tools: Add a tool to get a list of defconfigs based on filters Jean-Jacques Hiblot
2018-10-09 16:20   ` Simon Glass
2018-10-18 12:03     ` Jean-Jacques Hiblot
2018-10-18 14:36     ` Jean-Jacques Hiblot
2018-10-03 13:53 ` [U-Boot] [RFC PATCH v2 3/3] tools: Add a tool to get an overview of the usage of CONFIG options Jean-Jacques Hiblot
2018-10-09 16:20   ` Simon Glass
2018-10-18 11:38     ` Jean-Jacques Hiblot

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=1538574832-21910-2-git-send-email-jjhiblot@ti.com \
    --to=jjhiblot@ti.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.