aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf.py72
-rw-r--r--scripts/conf.py4
-rw-r--r--scripts/initialize.py23
-rw-r--r--scripts/iteration.py7
-rw-r--r--scripts/kernel.py16
-rw-r--r--scripts/phase.py5
-rw-r--r--scripts/solution.py33
-rw-r--r--scripts/utils.py7
8 files changed, 91 insertions, 76 deletions
diff --git a/conf.py b/conf.py
index 722332d..54c5f20 100644
--- a/conf.py
+++ b/conf.py
@@ -1,51 +1,55 @@
import os
from exceptions import MissingFile
-def pf(rfile):
- "Relative patch of file is decoded to absolute acording to working tree."
- return os.path.dirname(os.path.realpath(__file__)) + '/' + rfile
-
# Global configs
SRCARCH = 'x86' # Kernel architecture
ARCH = SRCARCH
linux_make_args = ['-j8']
novaboot_args = ['--qemu=qemu-system-x86_64']
-# Path settings
-dot_confmk = pf('.conf.mk')
-
-linux_sources = pf('linux')
-linux_kconfig_head = 'Kconfig'
-linux_dot_config = linux_sources + '/.config'
-linux_image = linux_sources + '/arch/' + ARCH + '/boot/bzImage'
-
-build_folder = pf('build/')
-phase_file = build_folder + '/phase'
-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'
-dot_config_fragment_file = build_folder + '/dot_config_fragment'
-dot_config_back_file = build_folder + '/dot_config_back'
-solution_file = build_folder + '/solution'
-iteration_file = build_folder + '/iteration'
-
-buildroot_def_config = pf('scripts/buildroot_recipe/buildroot.def.config')
-buildroot_inittab_directive = pf('scripts/buildroot_recipe/inittab_directive')
-buildroot_initscript = pf('scripts/buildroot_recipe/linux-conf-perf')
-buildroot_initram = pf('scripts/buildroot/output/images/rootfs.cpio.gz')
-
-# Programs paths
-parse_kconfig = pf('scripts/parse_kconfig/parse')
-write_config = pf('scripts/write_config/write')
-novaboot = pf('scripts/novaboot/novaboot')
-
# Programs output show/hide
parse_kconfig_output = False
minisat_output = False
kernel_config_output = True
kernel_make_output = True
-boot_output = True
+boot_output = False
+
+#######################################
+# Path settings
+dot_confmk = '.conf.mk'
+benchmark_python = 'benchmark.py'
+
+linux_sources = 'linux/'
+linux_kconfig_head = linux_sources + 'Kconfig'
+linux_dot_config = linux_sources + '.config'
+linux_image = linux_sources + 'arch/' + ARCH + '/boot/bzImage'
+
+build_folder = 'build/'
+phase_file = build_folder + 'phase'
+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'
+dot_config_fragment_file = build_folder + 'dot_config_fragment'
+dot_config_back_file = build_folder + 'dot_config_back'
+solution_file = build_folder + 'solution'
+iteration_file = build_folder + 'iteration'
+output_confs = build_folder + 'output_confs'
+
+output_folder = build_folder + 'output/'
+
+buildroot_def_config = 'scripts/buildroot_recipe/buildroot.def.config'
+buildroot_inittab_directive = 'scripts/buildroot_recipe/inittab_directive'
+buildroot_initscript = 'scripts/buildroot_recipe/linux-conf-perf'
+buildroot_initram = 'scripts/buildroot/output/images/rootfs.cpio.gz'
initram = build_folder + 'initram.gz'
nbscript = 'scripts/nbscript'
+
+# Programs paths
+parse_kconfig = 'scripts/parse_kconfig/parse'
+write_config = 'scripts/write_config/write'
+novaboot = 'scripts/novaboot/novaboot'
+
+
+absroot = os.path.dirname(os.path.realpath(__file__))
diff --git a/scripts/conf.py b/scripts/conf.py
index c2f891d..b3a0fee 100644
--- a/scripts/conf.py
+++ b/scripts/conf.py
@@ -5,3 +5,7 @@ import importlib.machinery
confpy = os.path.dirname(__file__) + "/../conf.py"
conf = importlib.machinery.SourceFileLoader("module.name", confpy).load_module()
+
+def sf(path):
+ return os.path.join(os.path.relpath(conf.absroot), path)
+ return '../' + path
diff --git a/scripts/initialize.py b/scripts/initialize.py
index 8b04610..8fb06df 100644
--- a/scripts/initialize.py
+++ b/scripts/initialize.py
@@ -5,41 +5,42 @@ import shutil
import utils
from conf import conf
+from conf import sf
from exceptions import MissingFile
def parse_kconfig():
"Execute parse_kconfig in linux_sources directory."
env = dict(os.environ)
wd = os.getcwd()
- os.chdir(conf.linux_sources)
+ os.chdir(sf(conf.linux_sources))
if conf.parse_kconfig_output:
- subprocess.call([conf.parse_kconfig, conf.linux_kconfig_head, conf.build_folder, "-v", "-v"], env=utils.get_kernel_env())
+ subprocess.call([sf(conf.parse_kconfig), sf(conf.linux_kconfig_head), sf(conf.build_folder), "-v", "-v"], env=utils.get_kernel_env())
else:
- subprocess.call([conf.parse_kconfig, conf.linux_kconfig_head, conf.build_folder], env=utils.get_kernel_env())
+ subprocess.call([sf(conf.parse_kconfig), sf(conf.linux_kconfig_head), sf(conf.build_folder)], env=utils.get_kernel_env())
os.chdir(wd)
def gen_requred():
"Generates required depenpency from .config file in linux source tree."
- if not os.path.isfile(conf.linux_sources + '/.config'):
- raise MissingFile(conf.linux_sources + '/.config',
+ if not os.path.isfile(sf(conf.linux_dot_config)):
+ raise MissingFile(sf(conf.linux_dot_config),
'Generate initial configuration. Execute make defconfig in linux folder. Or use make menuconfig and change configuration.')
utils.build_symbol_map() # Ensure smap existence
srmap = {value:key for key, value in utils.smap.items()}
try:
- os.remove(conf.required_file)
- os.remove(conf.dot_config_fragment_file)
+ os.remove(sf(conf.required_file))
+ os.remove(sf(conf.dot_config_fragment_file))
except OSError:
pass
- shutil.copy(conf.linux_dot_config, conf.dot_config_back_file)
+ shutil.copy(sf(conf.linux_dot_config), sf(conf.dot_config_back_file))
- with open(conf.linux_sources + '/.config', 'r') as f:
- with open(conf.required_file, 'w') as freq:
- with open(conf.dot_config_fragment_file, 'w') as fconf:
+ with open(sf(conf.linux_dot_config), 'r') as f:
+ with open(sf(conf.required_file), 'w') as freq:
+ with open(sf(conf.dot_config_fragment_file), 'w') as fconf:
for line in f:
if (line[0] == '#') or (not '=' in line):
continue
diff --git a/scripts/iteration.py b/scripts/iteration.py
index f885b37..ef5a3f0 100644
--- a/scripts/iteration.py
+++ b/scripts/iteration.py
@@ -1,12 +1,13 @@
from conf import conf
+from conf import sf
def reset():
- with open(conf.iteration_file, 'w') as f:
+ with open(sf(conf.iteration_file), 'w') as f:
f.write('0')
def inc():
- with open(conf.iteration_file, 'r') as f:
+ with open(sf(conf.iteration_file), 'r') as f:
it = int(f.read())
it += 1
- with open(conf.iteration_file, 'w') as f:
+ with open(sf(conf.iteration_file), 'w') as f:
f.write(str(it))
diff --git a/scripts/kernel.py b/scripts/kernel.py
index a95202f..d698e4c 100644
--- a/scripts/kernel.py
+++ b/scripts/kernel.py
@@ -3,19 +3,19 @@ import sys
import subprocess
from conf import conf
+from conf import sf
import utils
def config():
- # Executing old linux config
env = dict(os.environ)
wd = os.getcwd()
- os.chdir(conf.linux_sources)
+ os.chdir(sf(conf.linux_sources))
if conf.kernel_config_output:
- sprc = subprocess.call([conf.write_config, conf.linux_kconfig_head,
- conf.build_folder], env=utils.get_kernel_env())
+ sprc = subprocess.call([sf(conf.write_config), sf(conf.linux_kconfig_head),
+ sf(conf.build_folder)], env=utils.get_kernel_env())
else:
- sprc = subprocess.call([conf.write_config, conf.linux_kconfig_head,
- conf.build_folder], stdout=subprocess.DEVNULL,
+ sprc = subprocess.call([sf(conf.write_config), sf(conf.linux_kconfig_head),
+ sf(conf.build_folder)], stdout=subprocess.DEVNULL,
env=utils.get_kernel_env())
os.chdir(wd)
@@ -23,7 +23,7 @@ def config_noprogram():
# Executing old linux config
env = dict(os.environ)
wd = os.getcwd()
- os.chdir(conf.linux_sources)
+ os.chdir(sf(conf.linux_sources))
if conf.kernel_config_output:
sprc = subprocess.call('yes "" | make oldconfig', shell=True,
env=utils.get_kernel_env())
@@ -34,7 +34,7 @@ def config_noprogram():
def make():
wd = os.getcwd()
- os.chdir(conf.linux_sources)
+ os.chdir(sf(conf.linux_sources))
if conf.kernel_make_output:
subprocess.call(['make'] + conf.linux_make_args,
env=utils.get_kernel_env())
diff --git a/scripts/phase.py b/scripts/phase.py
index fe7b4b1..390087f 100644
--- a/scripts/phase.py
+++ b/scripts/phase.py
@@ -2,6 +2,7 @@ import os
import sys
from conf import conf
+from conf import sf
phases = ("Not Initialized", #0
"Initializing", #1
@@ -18,7 +19,7 @@ phases = ("Not Initialized", #0
def get():
try:
- with open(conf.phase_file) as f:
+ with open(sf(conf.phase_file)) as f:
txtPhase = f.readline().rstrip()
if not txtPhase in phases:
raise PhaseMismatch()
@@ -27,7 +28,7 @@ def get():
return 0
def set(phs):
- with open(conf.phase_file, 'w') as f:
+ with open(sf(conf.phase_file), 'w') as f:
f.write(phases[phs])
def pset(str):
diff --git a/scripts/solution.py b/scripts/solution.py
index 21e1cea..3fddb6b 100644
--- a/scripts/solution.py
+++ b/scripts/solution.py
@@ -5,6 +5,7 @@ import subprocess
import utils
from conf import conf
+from conf import sf
from exceptions import NoSolution
def generate():
@@ -18,29 +19,29 @@ def generate():
solution_file
"""
# Check if rules_file exist. If it was generated.
- if not os.path.isfile(conf.rules_file):
+ if not os.path.isfile(sf(conf.rules_file)):
raise Exception("Rules file missing. Run parse_kconfig and check ecistence of " + rules_file)
w_file = tempfile.NamedTemporaryFile(delete=False)
# Join files to one single temporary file
lines = set()
- with open(conf.rules_file, 'r') as f:
- for lnn in open(conf.rules_file, 'r'):
+ with open(sf(conf.rules_file), 'r') as f:
+ for lnn in open(sf(conf.rules_file), 'r'):
ln = lnn.rstrip()
if ln not in lines:
lines.add(ln)
- if os.path.isfile(conf.solved_file):
- for lnn in open(conf.solved_file, 'r'):
+ if os.path.isfile(sf(conf.solved_file)):
+ for lnn in open(sf(conf.solved_file), 'r'):
ln = lnn.rstrip()
if ln not in lines:
lines.add(ln)
- if os.path.isfile(conf.required_file):
- for lnn in open(conf.required_file, 'r'):
+ if os.path.isfile(sf(conf.required_file)):
+ for lnn in open((conf.required_file), 'r'):
ln = lnn.rstrip()
if ln not in lines:
lines.add(ln)
- with open(conf.symbol_map_file) as f:
+ with open(sf(conf.symbol_map_file)) as f:
for var_num, l in enumerate(f):
pass
var_num += 1
@@ -55,9 +56,9 @@ def generate():
# Execute minisat
if conf.minisat_output:
- subprocess.call(['minisat', w_file.name, conf.solution_file])
+ subprocess.call(['minisat', w_file.name, sf(conf.solution_file)])
else:
- subprocess.call(['minisat', w_file.name, conf.solution_file], stdout=subprocess.DEVNULL)
+ subprocess.call(['minisat', w_file.name, sf(conf.solution_file)], stdout=subprocess.DEVNULL)
os.remove(w_file.name)
@@ -65,20 +66,22 @@ def apply():
"""Apply generated solution to kernel source.
"""
# Check if solution_file exist
- if not os.path.isfile(conf.solution_file):
- raise Exception("Solution file is missing. Run sat_solution and check existence of " + conf.solution_file)
+ if not os.path.isfile(sf(conf.solution_file)):
+ raise Exception("Solution file is missing. Run sat_solution and check existence of " + sf(conf.solution_file))
utils.build_symbol_map() # Ensure smap existence
# Read solution if satisfiable
- with open(conf.solution_file, 'r') as f:
+ with open(sf(conf.solution_file), 'r') as f:
if not f.readline().rstrip() == 'SAT':
raise NoSolution()
solut = f.readline().split()
solut.remove('0') # Remove 0 at the end
+
+
# Write negotation solution to solver_file
- with open(conf.solved_file, 'a') as f:
+ with open(sf(conf.solved_file), 'a') as f:
for txt in solut:
if txt[0] == '-':
ntx = ""
@@ -89,7 +92,7 @@ def apply():
f.write("\n")
# Write solution to .config file in linux source folder
- with open(conf.linux_sources + '/.config', 'w') as f:
+ with open(sf(conf.linux_dot_config), 'w') as f:
for txt in solut:
if txt[0] == '-':
nt = True
diff --git a/scripts/utils.py b/scripts/utils.py
index 161ed8a..7f8e301 100644
--- a/scripts/utils.py
+++ b/scripts/utils.py
@@ -1,6 +1,7 @@
import os
import sys
from conf import conf
+from conf import sf
from exceptions import MissingFile
def build_symbol_map():
@@ -12,11 +13,11 @@ def build_symbol_map():
smap
except NameError:
# Check if symbol_map_file exist
- if not os.path.isfile(conf.symbol_map_file):
- raise MissingFile(conf.symbol_map_file, "Run parse_kconfig to generate it.")
+ if not os.path.isfile(sf(conf.symbol_map_file)):
+ raise MissingFile(sf(conf.symbol_map_file), "Run parse_kconfig to generate it.")
smap = dict()
- with open(conf.symbol_map_file) as f:
+ with open(sf(conf.symbol_map_file)) as f:
for lnn in f:
w = lnn.rstrip().split(sep=':')
smap[w[0]] = w[1]