Changes since April

Clean up of build directories.
Simplifications to capability model.
This commit is contained in:
Bahadir Balban
2010-06-01 15:08:13 +03:00
parent aef14b55ec
commit 6fa4884a5a
450 changed files with 10449 additions and 7383 deletions

259
scripts/linux/build_linux.py Executable file → Normal file
View File

@@ -9,13 +9,12 @@ import os, sys, shelve, string
from os.path import join
PROJRELROOT = '../../'
SCRIPTROOT = os.path.abspath(os.path.dirname("."))
SCRIPTROOT = os.path.abspath(os.path.dirname('.'))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
from config.projpaths import *
from config.configuration import *
from config.lib import *
from scripts.config.projpaths import *
from scripts.config.configuration import *
from scripts.config.lib import *
LINUX_KERNEL_BUILDDIR = join(BUILDDIR, os.path.relpath(LINUX_KERNELDIR, PROJROOT))
@@ -23,105 +22,44 @@ LINUX_KERNEL_BUILDDIR = join(BUILDDIR, os.path.relpath(LINUX_KERNELDIR, PROJROOT
# conts/linux -> build/cont[0-9]/linux
def source_to_builddir(srcdir, id):
cont_builddir = \
os.path.relpath(srcdir, \
PROJROOT).replace("conts", \
"cont" + str(id))
os.path.relpath(srcdir, PROJROOT).replace('conts', 'cont' + str(id))
return join(BUILDDIR, cont_builddir)
class LinuxUpdateKernel:
def __init__(self, container):
# List for setting/unsetting .config params of linux
self.config_param_list = \
(['PCI', 'SET'],['AEABI', 'SET'],
['SCSI', 'SET'],['BLK_DEV_SD', 'SET'],
['SYM53C8XX_2', 'SET'],['INPUT_EVDEV', 'SET'],
['INOTIFY', 'SET'],['DEBUG_INFO', 'SET'],
['USB_SUPPORT', 'UNSET'],['SOUND', 'UNSET'],)
# List of CPUIDs, to be used by linux based on codezero config
self.cpuid_list = (['ARM926', '0x41069265'],
['CORTEXA8', '0x410fc080'],
['ARM11MPCORE', '0x410fb022'],
['CORTEXA9', '0x410fc090'])
self.cpuid_list = {'ARM926' : '0x41069265',
'CORTEXA8' : '0x410fc080',
'ARM11MPCORE': '0x410fb022',
'CORTEXA9' : '0x410fc090'}
# List of ARCHIDs, to be used by linux based on codezero config
self.archid_list = (['PB926', '0x183'],
['EB', '0x33B'],
['PB11MPCORE', '0x3D4'],
['BEAGLE', '0x60A'],
['PBA9', '0x76D'],
['PBA8', '0x769'])
self.archid_list = {'PB926' : '0x183',
'EB' : '0x33B',
'BEAGLE': '0x60A',
'PBA9' : '0x76D'}
# Path of system_macros header file
self.system_macros_h_out = \
join(LINUX_KERNELDIR,
'arch/codezero/include/virtualization/system_macros.h')
self.system_macros_h_in = \
join(LINUX_KERNELDIR,
'arch/codezero/include/virtualization/system_macros.h.in')
self.system_macros_h_out = join(LINUX_KERNELDIR, 'arch/arm/include/vmm/system_macros.h')
self.system_macros_h_in = join(LINUX_KERNELDIR, 'arch/arm/include/vmm/system_macros.h.in')
#Path for kernel_param file
self.kernel_param_out = \
join(LINUX_KERNELDIR, 'arch/codezero/include/virtualization/kernel_param')
self.kernel_param_in = \
join(LINUX_KERNELDIR, 'arch/codezero/include/virtualization/kernel_param.in')
# Replace line(having input_pattern) in filename with new_data
def replace_line(self, filename, input_pattern, new_data, prev_line):
with open(filename, 'r+') as f:
flag = 0
temp = 0
x = re.compile(input_pattern)
for line in f:
if '' != prev_line:
if temp == prev_line and re.match(x, line):
flag = 1
break
temp = line
else:
if re.match(x, line):
flag = 1
break
if flag == 0:
#print 'Warning: No match found for the parameter'
return
else:
# Prevent recompilation in case kernel parameter is same
if new_data != line:
f.seek(0)
l = f.read()
# Need to truncate file because, size of contents to be
# written may be less than the size of original file.
f.seek(0)
f.truncate(0)
# Write back to file
f.write(l.replace(line, new_data))
self.kconfig_in = join(LINUX_KERNELDIR, 'arch/arm/Kconfig.in')
self.kconfig_out = join(LINUX_KERNELDIR, 'arch/arm/Kconfig')
# Update kernel parameters
def update_kernel_params(self, config, container):
# Update PAGE_OFFSET
# FIXME: Find a way to add this in system_macros.h or kernel_param
# issue is we have to update this in KCONFIG file which cannot
# have dependency on other files.
file = join(LINUX_KERNELDIR, 'arch/codezero/Kconfig')
param = str(conv_hex(container.linux_page_offset))
new_data = ('\t' + 'default ' + param + '\n')
data_to_replace = "(\t)(default )"
prev_line = ('\t'+'default 0x80000000 if VMSPLIT_2G' + '\n')
self.replace_line(file, data_to_replace, new_data, prev_line)
with open(self.kconfig_out, 'w+') as output:
with open(self.kconfig_in, 'r') as input:
output.write(input.read() % \
{'phys_offset' : str(conv_hex(container.linux_phys_offset)), \
'page_offset' : str(conv_hex(container.linux_page_offset)), \
'ztextaddr' : str(conv_hex(container.linux_phys_offset)), \
'zreladdr' : str(conv_hex(container.linux_zreladdr))})
# Update ARCHID, CPUID and ATAGS ADDRESS
for cpu_type, cpu_id in self.cpuid_list:
if cpu_type == config.cpu.upper():
cpuid = cpu_id
break
for arch_type, arch_id in self.archid_list:
if arch_type == config.platform.upper():
archid = arch_id
break
# Update ARCHID, CPUID and ATAGS ADDRESS
cpuid = self.cpuid_list[config.cpu.upper()]
archid = self.archid_list[config.platform.upper()]
# Create system_macros header
with open(self.system_macros_h_out, 'w+') as output:
@@ -129,38 +67,15 @@ class LinuxUpdateKernel:
output.write(input.read() % \
{'cpuid' : cpuid, \
'archid' : archid, \
'atags' : str(conv_hex(container.linux_page_offset + 0x100)), \
'ztextaddr' : str(conv_hex(container.linux_phys_offset)), \
'phys_offset' : str(conv_hex(container.linux_phys_offset)), \
'page_offset' : str(conv_hex(container.linux_page_offset)), \
'zreladdr' : str(conv_hex(container.linux_zreladdr))})
'atags' : str(conv_hex(container.linux_page_offset + 0x100))})
with open(self.kernel_param_out, 'w+') as output:
with open(self.kernel_param_in, 'r') as input:
output.write(input.read() % \
{'ztextaddr' : str(conv_hex(container.linux_phys_offset)), \
'phys_offset' : str(conv_hex(container.linux_phys_offset)), \
'page_offset' : str(conv_hex(container.linux_page_offset)), \
'zreladdr' : str(conv_hex(container.linux_zreladdr))})
def modify_kernel_config(self, linux_builddir):
file = join(linux_builddir, '.config')
for param_name, param_value in self.config_param_list:
param = 'CONFIG_' + param_name
prev_line = ''
if param_value == 'SET':
data_to_replace = ('# ' + param)
new_data = (param + '=y' + '\n')
else:
data_to_replace = param
new_data = ('# ' + param + ' is not set' + '\n')
self.replace_line(file, data_to_replace, new_data, prev_line)
def clean(self):
os.system('rm -f ' + self.system_macros_h_out)
os.system('rm -f ' + self.kconfig_out)
class LinuxBuilder:
def __init__(self, pathdict, container):
self.LINUX_KERNELDIR = pathdict["LINUX_KERNELDIR"]
def __init__(self, pathdict, container, opts):
self.LINUX_KERNELDIR = pathdict['LINUX_KERNELDIR']
# Calculate linux kernel build directory
self.LINUX_KERNEL_BUILDDIR = \
@@ -169,57 +84,98 @@ class LinuxBuilder:
self.container = container
self.kernel_binary_image = \
join(os.path.relpath(self.LINUX_KERNEL_BUILDDIR, LINUX_KERNELDIR), \
"vmlinux")
self.kernel_image = join(self.LINUX_KERNEL_BUILDDIR, "linux.elf")
'vmlinux')
self.kernel_image = join(self.LINUX_KERNEL_BUILDDIR, 'linux.elf')
self.kernel_updater = LinuxUpdateKernel(self.container)
self.build_config_file = join(self.LINUX_KERNEL_BUILDDIR, '.config')
self.platform_config_file = None
# Default configuration file to use based on selected platform
self.platform_config_file = (['PB926', 'versatile_defconfig'],
['BEAGLE', 'omap3_beagle_defconfig'],
['PBA8', 'realview_defconfig'],
['PBA9', 'realview-smp_defconfig'],
['PB11MPCORE', 'realview-smp_defconfig'],)
self.platform_config_files = {'PB926' : 'versatile',
'BEAGLE' : 'omap3_beagle',
'PBA9' : 'vexpress_a9'}
# This one is for EB, EB can have 1136/1176/11MPCore/A8/A9 coretiles
self.cpu_config_file = {'CORTEXA8': 'eb-a8',
'CORTEXA9': 'eb-a9',
'ARM1136' : 'eb-1136',
'ARM11MPCORE': 'eb-11mpcore'}
def build_linux(self, config):
def print_verbose(self, text):
print "########################################################"
print "########################################################"
print "# " + text
print "########################################################"
print "########################################################"
def defconfig_to_config(self, config):
# First get the linux configuration file corresponding to chosen platform
self.platform_defconfig = ''
if config.platform.upper() == 'EB':
self.platform_defconfig = self.cpu_config_file[config.cpu.upper()]
else:
self.platform_defconfig = self.platform_config_files[config.platform.upper()]
if not self.platform_defconfig:
print 'Platform detected as: ' + config.platform
print 'Could not find relevant linux config file please review configuration'
sys.exit(1)
# Create a config file from the corresponding defconfig
os.system("make " + self.platform_defconfig + "_defconfig O=" + self.LINUX_KERNEL_BUILDDIR)
def build_linux(self, config, opts):
print '\nBuilding the linux kernel...'
os.chdir(self.LINUX_KERNELDIR)
if not os.path.exists(self.LINUX_KERNEL_BUILDDIR):
os.makedirs(self.LINUX_KERNEL_BUILDDIR)
for platform, config_file in self.platform_config_file:
if platform == config.platform.upper():
configuration_file = config_file
os.system("make ARCH=codezero CROSS_COMPILE=" + \
config.toolchain_userspace + \
" O=" + self.LINUX_KERNEL_BUILDDIR + " " + configuration_file)
self.kernel_updater.modify_kernel_config(self.LINUX_KERNEL_BUILDDIR)
# Update linux configuration based on codezero config
# TODO: This may be changed from run-always to run-on-modification.
self.kernel_updater.update_kernel_params(config, self.container)
os.system("make ARCH=codezero CROSS_COMPILE=" + \
config.toolchain_userspace + \
" O=" + self.LINUX_KERNEL_BUILDDIR + " menuconfig")
os.system("make ARCH=codezero " + \
"CROSS_COMPILE=" + config.toolchain_userspace + \
" O=" + self.LINUX_KERNEL_BUILDDIR)
# Is this the first time the kernel is to be configured?
if not os.path.exists(self.build_config_file):
self.print_verbose("Config file does not exist. Creating from defconfig")
self.defconfig_to_config(config)
# Batch mode runs without invoking configure stage
if opts.batch:
# Build the kernel directly
os.system('make ARCH=arm CROSS_COMPILE=' + config.toolchain_kernel + \
' O=' + self.LINUX_KERNEL_BUILDDIR + ' ' + self.build_config_file)
else:
# Configure the kernel
os.system('make ARCH=arm CROSS_COMPILE=' + config.toolchain_kernel + \
' O=' + self.LINUX_KERNEL_BUILDDIR + ' menuconfig')
if not os.path.exists(self.build_config_file):
self.print_verbose("Config file doesnt exist after building: " + self.build_config_file)
sys.exit(1)
# Build the kernel
os.system('make V=1 ARCH=arm ' + '-j ' + opts.jobs + \
' CROSS_COMPILE=' + config.toolchain_kernel + \
' O=' + self.LINUX_KERNEL_BUILDDIR + ' Image')
# Generate kernel_image, elf to be used by codezero
linux_elf_gen_cmd = (config.toolchain_userspace + "objcopy -R .note \
-R .note.gnu.build-id -R .comment -S --change-addresses " + \
linux_elf_gen_cmd = (config.toolchain_userspace + 'objcopy -R .note \
-R .note.gnu.build-id -R .comment -S --change-addresses ' + \
str(conv_hex(-self.container.linux_page_offset + self.container.linux_phys_offset)) + \
" " + self.kernel_binary_image + " " + self.kernel_image)
' ' + self.kernel_binary_image + ' ' + self.kernel_image)
#print cmd
os.system(linux_elf_gen_cmd)
print 'Done...'
def clean(self):
def clean(self, config):
print 'Cleaning linux kernel build...'
if os.path.exists(self.LINUX_KERNEL_BUILDDIR):
shutil.rmtree(self.LINUX_KERNEL_BUILDDIR)
self.kernel_updater.clean()
os.system('rm -f ' + self.kernel_image)
os.chdir(self.LINUX_KERNELDIR)
os.system('make ARCH=arm CROSS_COMPILE=' + config.toolchain_kernel + \
' O=' + self.LINUX_KERNEL_BUILDDIR + ' clean')
print 'Done...'
if __name__ == "__main__":
if __name__ == '__main__':
# This is only a default test case
container = Container()
container.id = 0
@@ -227,7 +183,8 @@ if __name__ == "__main__":
if len(sys.argv) == 1:
linux_builder.build_linux()
elif "clean" == sys.argv[1]:
elif 'clean' == sys.argv[1]:
linux_builder.clean()
else:
print " Usage: %s [clean]" % (sys.argv[0])
print ' Usage: %s [clean]' % (sys.argv[0])