Commit b237d358 authored by Markus Klotzbuecher's avatar Markus Klotzbuecher Committed by Heiko Schocher
Browse files

moveconfig: expand simple expressions

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: default avatarMarkus Klotzbuecher <>
Cc: Masahiro Yamada <>
Cc: Heiko Schocher <>
parent e5aee22e
......@@ -354,6 +354,26 @@ CONFIG_DATABASE = 'moveconfig.db'
"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:
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
cfg, val = re.split("=", line)
val= val.strip('\"')
if"[*+-/]|<<|SZ_+|\(([^\)]+)\)", val):
newval = hex(eval(val, SIZES))
print "\tExpanded expression %s to %s" % (val, newval)
return cfg+'='+newval
print "\tFailed to expand expression in %s" % line
return line
### classes ###
class Progress:
......@@ -891,6 +930,8 @@ class KconfigParser:
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:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment