diff --git a/build.py b/build.py index 0895c96..b188282 100755 --- a/build.py +++ b/build.py @@ -33,6 +33,11 @@ def main(): print "\nBuilding containers..." containers.build_all_containers() + # + # Generate cinfo + # + generate_cinfo() + # # Build the kernel # diff --git a/config/configuration.py b/config/configuration.py index 9018d85..ecb2b37 100644 --- a/config/configuration.py +++ b/config/configuration.py @@ -12,6 +12,7 @@ class Container: self.id = id self.pager_lma = 0 self.pager_vma = 0 + self.pager_size = 0 self.pager_task_region_start = 0 self.pager_task_region_end = 0 self.pager_shm_region_start = 0 diff --git a/configure.py b/configure.py index 41ff267..820b804 100755 --- a/configure.py +++ b/configure.py @@ -183,15 +183,17 @@ def configure_system(options, args): bare_cont_gen = BareContGenerator() bare_cont_gen.bare_container_generate(config) - # Generate kernel cinfo structure for container definitions - generate_kernel_cinfo(config, KERNEL_CINFO_PATH) - # Print out the configuration if asked if options.print_config: config.config_print() return config +# Generate kernel cinfo structure for container definitions +def generate_cinfo(): + config = configuration_retrieve() + generate_kernel_cinfo(config, KERNEL_CINFO_PATH) + if __name__ == "__main__": opts, args = build_parse_options() diff --git a/conts/test/include/linker.lds.in b/conts/test/include/linker.lds.in index ab525c4..d9740ab 100644 --- a/conts/test/include/linker.lds.in +++ b/conts/test/include/linker.lds.in @@ -19,8 +19,11 @@ SECTIONS . = ALIGN(4K); .data : AT (ADDR(.data) - offset) { *(.data) } - .bss : AT (ADDR(.bss) - offset) { *(.bss) } - . += 0x1000; - . = ALIGN(8); - __stack = .; + .bss : AT (ADDR(.bss) - offset) + { + *(.bss) + . += 0x1000; + . = ALIGN(8); + __stack = .; + } } diff --git a/scripts/conts/containers.py b/scripts/conts/containers.py index dc59a87..c0963df 100755 --- a/scripts/conts/containers.py +++ b/scripts/conts/containers.py @@ -7,7 +7,7 @@ # import os, sys, shelve, glob from os.path import join -from tools.pyelf import elf +from tools.pyelf.elfsize import * PROJRELROOT = '../../' @@ -22,33 +22,7 @@ from scripts.linux.build_atags import * from pack import * from packall import * -def update_cinfo_pagersize(cid, pager_path): - pager_size = conv_hex(elf_binary_size(pager_path)) - with open(KERNEL_CINFO_PATH, 'r+') as f: - temp = f.read() - f.seek(0) - f.truncate(0) - f.write(temp % (cid, pager_size)) - -def elf_binary_size(img): - elffile = elf.ElfFile.from_file(img) - paddr_first = 0 - paddr_start = 0 - paddr_end = 0 - for pheader in elffile.pheaders: - x = pheader.ai - if str(x.p_type) != "LOAD": - continue - if paddr_first == 0: - paddr_first = 1 - paddr_start = x.p_paddr.value - if paddr_start > x.p_paddr.value: - paddr_start = x.p_paddr.value - if paddr_end < x.p_paddr + x.p_memsz: - paddr_end = x.p_paddr + x.p_memsz - return paddr_end - paddr_start - -def build_linux_container(projpaths, container): +def build_linux_container(config, projpaths, container): linux_builder = LinuxBuilder(projpaths, container) linux_builder.build_linux() @@ -57,11 +31,11 @@ def build_linux_container(projpaths, container): atags_builder = AtagsBuilder(projpaths, container) atags_builder.build_atags() - # Update the size of pager in cinfo.c + # Calculate and store size of pager pager_binary = \ "cont" + str(container.id) + "/linux/linux-2.6.28.10/linux.elf" - pager_path = join(BUILDDIR, pager_binary) - update_cinfo_pagersize(container.id, pager_path) + config.containers[container.id].pager_size = \ + conv_hex(elf_binary_size(join(BUILDDIR, pager_binary))) linux_container_packer = \ LinuxContainerPacker(container, linux_builder, \ @@ -84,7 +58,7 @@ def source_to_builddir(srcdir, id): # This is very similar to default container builder: # In fact this notion may become a standard convention for # calling specific bare containers -def build_posix_container(projpaths, container): +def build_posix_container(config, projpaths, container): images = [] cwd = os.getcwd() os.chdir(POSIXDIR) @@ -95,17 +69,17 @@ def build_posix_container(projpaths, container): builddir = source_to_builddir(POSIXDIR, container.id) os.path.walk(builddir, glob_by_walk, ['*.elf', images]) - # Update the size of pager in cinfo.c + # Calculate and store size of pager pager_binary = "cont" + str(container.id) + "/posix/mm0/mm0.elf" - pager_path = join(BUILDDIR, pager_binary) - update_cinfo_pagersize(container.id, pager_path) + config.containers[container.id].pager_size = \ + conv_hex(elf_binary_size(join(BUILDDIR, pager_binary))) container_packer = DefaultContainerPacker(container, images) return container_packer.pack_container() # We simply use SCons to figure all this out from container.id # Builds the test container. -def build_test_container(projpaths, container): +def build_test_container(config, projpaths, container): images = [] cwd = os.getcwd() os.chdir(TESTDIR) @@ -116,7 +90,7 @@ def build_test_container(projpaths, container): builddir = source_to_builddir(TESTDIR, container.id) os.path.walk(builddir, glob_by_walk, ['*.elf', images]) - # TODO: Need to calculate pager size and update in cinfo.c + # TODO: Need to Calculate and store size of pager container_packer = DefaultContainerPacker(container, images) return container_packer.pack_container() @@ -124,7 +98,7 @@ def build_test_container(projpaths, container): # This simply calls SCons on a given container, and collects # all images with .elf extension, instead of using whole classes # for building and packing. -def build_default_container(projpaths, container): +def build_default_container(config, projpaths, container): images = [] cwd = os.getcwd() projdir = join(join(PROJROOT, 'conts'), container.name) @@ -132,33 +106,32 @@ def build_default_container(projpaths, container): os.system("scons") os.path.walk(projdir, glob_by_walk, ['*.elf', images]) - # Update the size of pager in cinfo.c + # Calculate and store size of pager pager_binary = "conts/bare" + str(container.id) + "/main.elf" - pager_path = join(PROJROOT, pager_binary) - update_cinfo_pagersize(container.id, pager_path) + config.containers[container.id].pager_size = \ + conv_hex(elf_binary_size(join(PROJROOT, pager_binary))) container_packer = DefaultContainerPacker(container, images) return container_packer.pack_container() def build_all_containers(): config = configuration_retrieve() - cont_images = [] for container in config.containers: if container.type == 'linux': pass - cont_images.append(build_linux_container(projpaths, container)) + cont_images.append(build_linux_container(config, projpaths, container)) elif container.type == 'bare': - cont_images.append(build_default_container(projpaths, container)) + cont_images.append(build_default_container(config, projpaths, container)) elif container.type == 'posix': - cont_images.append(build_posix_container(projpaths, container)) + cont_images.append(build_posix_container(config, projpaths, container)) elif container.type == 'test': - cont_images.append(build_test_container(projpaths, container)) + cont_images.append(build_test_container(config, projpaths, container)) else: print "Error: Don't know how to build " + \ "container of type: %s" % (container.type) exit(1) - + configuration_save(config) all_cont_packer = AllContainerPacker(cont_images, config.containers) return all_cont_packer.pack_all() diff --git a/scripts/kernel/generate_kernel_cinfo.py b/scripts/kernel/generate_kernel_cinfo.py index 5ae1d19..b0c8603 100755 --- a/scripts/kernel/generate_kernel_cinfo.py +++ b/scripts/kernel/generate_kernel_cinfo.py @@ -183,7 +183,7 @@ pager_ifdefs_todotext = \ # and pager binaries are formed pager_mapsize = \ ''' -#define CONFIG_CONT%s_PAGER_SIZE %s +#define CONFIG_CONT%d_PAGER_SIZE %s ''' pager_ifdefs = \ @@ -202,7 +202,7 @@ pager_ifdefs = \ #define CONFIG_CONT%(cn)d_PAGER_MAPSIZE (CONFIG_CONT%(cn)d_PAGER_SIZE) #endif ''' -def generate_pager_memory_ifdefs(containers): +def generate_pager_memory_ifdefs(config, containers): pager_ifdef_string = "" linux = 0 for c in containers: @@ -210,13 +210,8 @@ def generate_pager_memory_ifdefs(containers): if linux == 0: pager_ifdef_string += pager_ifdefs_todotext linux = 1 - # Generate string for PAGERSIZE to be filled later by containers - id = pow(2, c.id) - str = '' - while id >= 1: - str = str + '%' - id = id - 1 - pager_ifdef_string += pager_mapsize % ( str + 'd', str + 's') + pager_ifdef_string += \ + pager_mapsize % (c.id, config.containers[c.id].pager_size) pager_ifdef_string += pager_ifdefs % { 'cn' : c.id } return pager_ifdef_string @@ -227,7 +222,7 @@ def generate_kernel_cinfo(config, cinfo_path): print "Generating kernel cinfo..." #config.config_print() - pager_ifdefs = generate_pager_memory_ifdefs(containers) + pager_ifdefs = generate_pager_memory_ifdefs(config, containers) with open(cinfo_path, 'w+') as cinfo_file: fbody = cinfo_file_start % pager_ifdefs diff --git a/tools/pyelf/elfsize.py b/tools/pyelf/elfsize.py new file mode 100644 index 0000000..8e3827e --- /dev/null +++ b/tools/pyelf/elfsize.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import elf + +# Calculate the size of loadable sections of elf binary +def elf_binary_size(img): + elffile = elf.ElfFile.from_file(img) + paddr_first = 0 + paddr_start = 0 + paddr_end = 0 + for pheader in elffile.pheaders: + x = pheader.ai + if str(x.p_type) != "LOAD": + continue + if paddr_first == 0: + paddr_first = 1 + paddr_start = x.p_paddr.value + if paddr_start > x.p_paddr.value: + paddr_start = x.p_paddr.value + if paddr_end < x.p_paddr + x.p_memsz: + paddr_end = x.p_paddr + x.p_memsz + return paddr_end - paddr_start +