public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Markus Klotzbuecher <mk@mkio.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 1/9] moveconfig: expand simple expressions
Date: Wed, 15 May 2019 15:15:52 +0200	[thread overview]
Message-ID: <20190515131600.28798-2-mk@mkio.de> (raw)
In-Reply-To: <20190515131600.28798-1-mk@mkio.de>

From: Markus Klotzbuecher <markus.klotzbuecher@kistler.com>

Add support for expanding simple expressions and sizes such as
"(4 * 1024)", "(512 << 10)" or "(SZ_256K)".

This can help to significantly reduce the number of "suspicious"
moves, such as

 'CONFIG_ENV_SIZE="(64 << 10)"' was removed by savedefconfig.

If the expansion fails, it falls back to the original string.

Signed-off-by: Markus Klotzbuecher <markus.klotzbuecher@kistler.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Heiko Schocher <hs@denx.de>
---
Changes for v2: new patch

 tools/moveconfig.py | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index 1a214c5605..0bbc7c1991 100755
--- a/tools/moveconfig.py
+++ b/tools/moveconfig.py
@@ -354,6 +354,26 @@ CONFIG_DATABASE = 'moveconfig.db'
 
 CONFIG_LEN = len('CONFIG_')
 
+SIZES = {
+    "SZ_1":    0x00000001, "SZ_2":    0x00000002,
+    "SZ_4":    0x00000004, "SZ_8":    0x00000008,
+    "SZ_16":   0x00000010, "SZ_32":   0x00000020,
+    "SZ_64":   0x00000040, "SZ_128":  0x00000080,
+    "SZ_256":  0x00000100, "SZ_512":  0x00000200,
+    "SZ_1K":   0x00000400, "SZ_2K":   0x00000800,
+    "SZ_4K":   0x00001000, "SZ_8K":   0x00002000,
+    "SZ_16K":  0x00004000, "SZ_32K":  0x00008000,
+    "SZ_64K":  0x00010000, "SZ_128K": 0x00020000,
+    "SZ_256K": 0x00040000, "SZ_512K": 0x00080000,
+    "SZ_1M":   0x00100000, "SZ_2M":   0x00200000,
+    "SZ_4M":   0x00400000, "SZ_8M":   0x00800000,
+    "SZ_16M":  0x01000000, "SZ_32M":  0x02000000,
+    "SZ_64M":  0x04000000, "SZ_128M": 0x08000000,
+    "SZ_256M": 0x10000000, "SZ_512M": 0x20000000,
+    "SZ_1G":   0x40000000, "SZ_2G":   0x80000000,
+    "SZ_4G":  0x100000000
+}
+
 ### helper functions ###
 def get_devnull():
     """Get the file object of '/dev/null' device."""
@@ -777,6 +797,25 @@ def cleanup_readme(configs, options):
     with open('README', 'w') as f:
         f.write(''.join(newlines))
 
+def try_expand(line):
+    """If value looks like an expression, try expanding it
+    Otherwise just return the existing value
+    """
+    if line.find('=') == -1:
+        return line
+
+    try:
+        cfg, val = re.split("=", line)
+        val= val.strip('\"')
+        if re.search("[*+-/]|<<|SZ_+|\(([^\)]+)\)", val):
+            newval = hex(eval(val, SIZES))
+            print "\tExpanded expression %s to %s" % (val, newval)
+            return cfg+'='+newval
+    except:
+        print "\tFailed to expand expression in %s" % line
+
+    return line
+
 
 ### classes ###
 class Progress:
@@ -891,6 +930,8 @@ class KconfigParser:
         else:
             new_val = not_set
 
+        new_val = try_expand(new_val)
+
         for line in dotconfig_lines:
             line = line.rstrip()
             if line.startswith(config + '=') or line == not_set:
-- 
2.20.1

  reply	other threads:[~2019-05-15 13:15 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-15 13:15 [U-Boot] [PATCH v2 0/9] miscellaneous ubispl and ubi improvements Markus Klotzbuecher
2019-05-15 13:15 ` Markus Klotzbuecher [this message]
2019-06-13  3:30   ` [U-Boot] [PATCH v2 1/9] moveconfig: expand simple expressions Heiko Schocher
2020-01-25 21:46   ` Heinrich Schuchardt
2020-01-29  8:44     ` Markus Klotzbuecher
2020-01-29 11:54       ` Heinrich Schuchardt
2019-05-15 13:15 ` [U-Boot] [PATCH v2 2/9] env: ubi: KConfig: add CONFIG_ENV_UBI_VOLUME_REDUND Markus Klotzbuecher
2019-06-13  3:31   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 3/9] at91, omap2plus: configs: migrate CONFIG_ENV_ to defconfigs Markus Klotzbuecher
2019-06-13  3:31   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 4/9] env: ubi: support configurable VID offset Markus Klotzbuecher
2019-06-13  3:31   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 5/9] ubi: fix UBI_SILENCE_MSG Markus Klotzbuecher
2019-06-13  3:32   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 6/9] ubispl: migrate configuration to Kconfig Markus Klotzbuecher
2019-06-13  3:32   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 7/9] configs: migrate ubispl boards to KConfig Markus Klotzbuecher
2019-05-20 20:50   ` Enric Balletbo Serra
2019-06-13  3:32   ` Heiko Schocher
2019-05-15 13:15 ` [U-Boot] [PATCH v2 8/9] ubispl: add support for loading volumes by name Markus Klotzbuecher
2019-06-13  3:33   ` Heiko Schocher
2019-05-15 13:16 ` [U-Boot] [PATCH v2 9/9] ubispl: introduce separate CONFIG_UBI_SPL_SILENCE_MSG Markus Klotzbuecher
2019-06-13  3:33   ` Heiko Schocher
2019-06-05 10:39 ` [U-Boot] [PATCH v2 0/9] miscellaneous ubispl and ubi improvements Markus Klotzbuecher

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=20190515131600.28798-2-mk@mkio.de \
    --to=mk@mkio.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox