aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf.py31
-rw-r--r--scripts/conf.py8
-rwxr-xr-xscripts/kconfig_parse.py22
-rwxr-xr-xscripts/sat_solution.py46
4 files changed, 107 insertions, 0 deletions
diff --git a/conf.py b/conf.py
new file mode 100644
index 0000000..1893fcc
--- /dev/null
+++ b/conf.py
@@ -0,0 +1,31 @@
+import os
+
+def pf(rfile):
+ "Relative patch of file is decoded to absolute acording to working tree."
+ return os.path.dirname(os.path.realpath(__file__)) + '/' + rfile
+
+def checkXf(f, message):
+ if os.path.isfile(f) and os.access(f, os.X_OK):
+ return f
+ else:
+ print('Error: Missing executable file "' + f + '"\n' + message,
+ file=sys.stderr)
+ return None
+
+# Global configs
+SRCARCH = 'x86' # Kernel architecture
+ARCH = SRCARCH
+
+# Path settings
+linux_sources = pf('linux')
+linux_kconfig_head = 'Kconfig'
+
+build_folder = pf('build/')
+symbol_map_file = build_folder + '/symbol_map' # Also defined in kconfig_parser
+rules_file = build_folder + '/rules' # Also defined in kconfig_parser
+solved_file = build_folder + '/solved'
+required_file = build_folder + '/required'
+solution_file = build_folder + '/solution'
+
+
+kconfig_parser = checkXf(pf('programs/kconfig_parser'),'You must build programs first.')
diff --git a/scripts/conf.py b/scripts/conf.py
new file mode 100644
index 0000000..fc716b1
--- /dev/null
+++ b/scripts/conf.py
@@ -0,0 +1,8 @@
+#!/bin/python3
+# This file is only loading ../conf.py
+import os
+import importlib.machinery
+
+confpy = os.path.dirname(__file__) + "/../conf.py"
+
+conf = importlib.machinery.SourceFileLoader("module.name", confpy).load_module()
diff --git a/scripts/kconfig_parse.py b/scripts/kconfig_parse.py
new file mode 100755
index 0000000..36d690b
--- /dev/null
+++ b/scripts/kconfig_parse.py
@@ -0,0 +1,22 @@
+#!/bin/python3
+import os
+import sys
+import subprocess
+from conf import conf
+
+def kconfig_parser():
+ "Execute kconfig_parser in linux_sources directory and parsed output is placed to build_folder."
+ env = dict(os.environ)
+ env['SRCARCH'] = conf.SRCARCH
+ env['ARCH'] = conf.ARCH
+ env['KERNELVERSION'] = 'KERNELVERSION'
+ wd = os.getcwd()
+ os.chdir(conf.linux_sources)
+ subprocess.call([conf.kconfig_parser, conf.linux_kconfig_head, conf.build_folder],
+ env=env)
+
+def main():
+ kconfig_parser()
+
+if __name__ == "__main__":
+ main()
diff --git a/scripts/sat_solution.py b/scripts/sat_solution.py
new file mode 100755
index 0000000..1a44678
--- /dev/null
+++ b/scripts/sat_solution.py
@@ -0,0 +1,46 @@
+#!/bin/python3
+import os
+import sys
+import tempfile
+import subprocess
+from conf import conf
+
+if not os.path.isfile(conf.rules_file):
+ print("Error: Rules are not generated yet, or wrong build_folder.\nCheck existence of " + rules_file, file=sys.stderr)
+ sys.exit(1)
+
+
+#w_file = tempfile.NamedTemporaryFile(delete=False)
+w_file = open('bld', 'w')
+# Join files to one single file
+lines = set()
+for ln in open(conf.rules_file, 'r'):
+ if ln not in lines:
+ lines.add(ln)
+if os.path.isfile(conf.solved_file):
+ for ln in open(conf.solved_file, 'r'):
+ if ln not in lines:
+ lines.add(ln)
+if os.path.isfile(conf.required_file):
+ for ln in open(conf.required_file, 'r'):
+ if ln not in lines:
+ lines.add(ln)
+
+with open(conf.symbol_map_file) as f:
+ for var_num, l in enumerate(f):
+ pass
+ var_num += 1
+lines_count = len(lines)
+
+first_line = "p cnf " + str(var_num) + " " + str(lines_count)
+w_file.write(first_line + '\n')
+for ln in lines:
+ w_file.write(ln)
+
+w_file.close()
+
+print("temp file: " + w_file.name)
+print("Output: " + conf.solution_file)
+subprocess.call(['minisat', w_file.name, conf.solution_file])
+
+#os.remove(w_file.name)