diff --git a/build.py b/build.py index 410ac3a..0895c96 100755 --- a/build.py +++ b/build.py @@ -21,13 +21,6 @@ def main(): # configure_system(opts, args) - # - # Build the kernel - # - print "\nBuilding the kernel..." - os.chdir(PROJROOT) - os.system("scons") - # # Build userspace libraries # @@ -40,6 +33,13 @@ def main(): print "\nBuilding containers..." containers.build_all_containers() + # + # Build the kernel + # + print "\nBuilding the kernel..." + os.chdir(PROJROOT) + os.system("scons") + # # Build libs and loader # diff --git a/config/cml/container_ruleset.template b/config/cml/container_ruleset.template index 285dec6..67e55fd 100644 --- a/config/cml/container_ruleset.template +++ b/config/cml/container_ruleset.template @@ -33,7 +33,6 @@ CONT%(cn)d_VIRT5_END 'Container %(cn)d Virtual Region 5 End Address' CONT%(cn)d_PAGER_LMA 'Container %(cn)d Pager LMA' CONT%(cn)d_PAGER_VMA 'Container %(cn)d Pager VMA' -CONT%(cn)d_PAGER_MAPSIZE 'Container %(cn)d Pager Initial Map Size (Optional)' CONT%(cn)d_PAGER_SHM_START 'Container %(cn)d Shared Mappings Region Start' CONT%(cn)d_PAGER_SHM_END 'Container %(cn)d Shared Mappings Region End' CONT%(cn)d_PAGER_TASK_START 'Container %(cn)d Task Address Space Region Start' @@ -44,11 +43,9 @@ CONT%(cn)d_LINUX_ZRELADDR 'Container %(cn)d Linux ZRELADDR parameter' CONT%(cn)d_LINUX_PAGE_OFFSET 'Container %(cn)d Linux PAGE_OFFSET Parameter' CONT%(cn)d_LINUX_PHYS_OFFSET 'Container %(cn)d Linux PHYS_OFFSET Parameter' CONT%(cn)d_LINUX_ROOTFS_ADDRESS 'Container %(cn)d Linux ROOTFS Address' -CONT%(cn)d_LINUX_MAPSIZE 'Container %(cn)d Linux Initial Kernel Map Size Parameter' default CONT%(cn)d_PAGER_LMA from 0x0 default CONT%(cn)d_PAGER_VMA from 0x0 -default CONT%(cn)d_PAGER_MAPSIZE from 0x0 default CONT%(cn)d_PAGER_SHM_START from 0x0 default CONT%(cn)d_PAGER_SHM_END from 0x0 default CONT%(cn)d_PAGER_TASK_START from 0x0 @@ -59,7 +56,6 @@ default CONT%(cn)d_LINUX_ZRELADDR from 0x0 default CONT%(cn)d_LINUX_PAGE_OFFSET from 0x0 default CONT%(cn)d_LINUX_PHYS_OFFSET from 0x0 default CONT%(cn)d_LINUX_ROOTFS_ADDRESS from 0x0 -default CONT%(cn)d_LINUX_MAPSIZE from 0x0 default CONT%(cn)d_VIRTMEM_REGIONS from 1 default CONT%(cn)d_PHYSMEM_REGIONS from 1 @@ -138,7 +134,6 @@ cont%(cn)d_posix_pager_params 'Container %(cn)d POSIX Pager Parameters' menu cont%(cn)d_bare_pager_params CONT%(cn)d_PAGER_LMA@ CONT%(cn)d_PAGER_VMA@ - CONT%(cn)d_PAGER_MAPSIZE@ menu cont%(cn)d_posix_pager_params CONT%(cn)d_PAGER_SHM_START@ @@ -154,7 +149,6 @@ menu cont%(cn)d_linux_pager_params CONT%(cn)d_LINUX_PAGE_OFFSET@ CONT%(cn)d_LINUX_PHYS_OFFSET@ CONT%(cn)d_LINUX_ROOTFS_ADDRESS@ - CONT%(cn)d_LINUX_MAPSIZE@ menu cont%(cn)d_virtmem_list CONT%(cn)d_VIRTMEM_REGIONS% diff --git a/config/configuration.py b/config/configuration.py index 0453e3a..9018d85 100644 --- a/config/configuration.py +++ b/config/configuration.py @@ -12,7 +12,6 @@ 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 @@ -23,7 +22,6 @@ class Container: self.linux_page_offset = 0 self.linux_phys_offset = 0 self.linux_rootfs_address = 0 - self.linux_mapsize = 0 self.physmem = {} self.physmem["START"] = {} self.physmem["END"] = {} @@ -45,7 +43,6 @@ class Container: print 'Container Pager task region end: %s' % conv_hex(self.pager_task_region_end) print 'Container Pager utcb region start: %s' % conv_hex(self.pager_utcb_region_start) print 'Container Pager utcb region end: %s' % conv_hex(self.pager_utcb_region_end) - print 'Container Pager size: %s' % conv_hex(self.pager_size) print 'Container Virtual regions: %s' % self.virt_regions print 'Container Physical regions: %s' % self.phys_regions @@ -143,10 +140,6 @@ class configuration: self.containers[id].pager_task_region_start = int(val, 0) elif param[:len("PAGER_TASK_END")] == "PAGER_TASK_END": self.containers[id].pager_task_region_end = int(val, 0) - elif param[:len("PAGER_MAPSIZE")] == "PAGER_MAPSIZE": - self.containers[id].pager_size = int(val, 0) - elif param[:len("LINUX_MAPSIZE")] == "LINUX_MAPSIZE": - self.containers[id].linux_mapsize = int(val, 0) elif param[:len("LINUX_PAGE_OFFSET")] == "LINUX_PAGE_OFFSET": self.containers[id].linux_page_offset = int(val, 0) self.containers[id].pager_vma += int(val, 0) diff --git a/scripts/bare/bare_generator.py b/scripts/bare/bare_generator.py index e9ace5d..3c6f1c2 100755 --- a/scripts/bare/bare_generator.py +++ b/scripts/bare/bare_generator.py @@ -57,7 +57,6 @@ class BareContGenerator: name_header = '\n[Container Name]\n' pager_lma_header = '\n[Container Pager LMA]\n' pager_vma_header = '\n[Container Pager VMA]\n' - pager_size_header = '\n[Container Pager Size]\n' pager_virtmem_header = '\n[Container Virtmem Region %s]\n' pager_physmem_header = '\n[Container Physmem Region %s]\n' @@ -70,8 +69,6 @@ class BareContGenerator: fout.write('\t' + cont.name + '\n') fout.write(pager_lma_header) fout.write('\t' + conv_hex(cont.pager_lma) + '\n') - fout.write(pager_size_header) - fout.write('\t' + conv_hex(cont.pager_size) + '\n') fout.write(pager_vma_header) fout.write('\t' + conv_hex(cont.pager_vma) + '\n') for ireg in range(cont.virt_regions): diff --git a/scripts/bare/files/linker.lds.in b/scripts/bare/files/linker.lds.in index ab525c4..d9740ab 100644 --- a/scripts/bare/files/linker.lds.in +++ b/scripts/bare/files/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 4207cc8..dc59a87 100755 --- a/scripts/conts/containers.py +++ b/scripts/conts/containers.py @@ -7,6 +7,7 @@ # import os, sys, shelve, glob from os.path import join +from tools.pyelf import elf PROJRELROOT = '../../' @@ -21,17 +22,50 @@ 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): linux_builder = LinuxBuilder(projpaths, container) linux_builder.build_linux() + rootfs_builder = RootfsBuilder(projpaths, container) rootfs_builder.build_rootfs() atags_builder = AtagsBuilder(projpaths, container) atags_builder.build_atags() - linux_container_packer = LinuxContainerPacker(container, \ - linux_builder, \ - rootfs_builder, \ - atags_builder) + + # Update the size of pager in cinfo.c + 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) + + linux_container_packer = \ + LinuxContainerPacker(container, linux_builder, \ + rootfs_builder, atags_builder) return linux_container_packer.pack_container() def glob_by_walk(arg, dirname, names): @@ -60,6 +94,12 @@ def build_posix_container(projpaths, container): os.system(scons_cmd) builddir = source_to_builddir(POSIXDIR, container.id) os.path.walk(builddir, glob_by_walk, ['*.elf', images]) + + # Update the size of pager in cinfo.c + pager_binary = "cont" + str(container.id) + "/posix/mm0/mm0.elf" + pager_path = join(BUILDDIR, pager_binary) + update_cinfo_pagersize(container.id, pager_path) + container_packer = DefaultContainerPacker(container, images) return container_packer.pack_container() @@ -75,6 +115,9 @@ def build_test_container(projpaths, container): os.system(scons_cmd) 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 + container_packer = DefaultContainerPacker(container, images) return container_packer.pack_container() @@ -88,10 +131,15 @@ def build_default_container(projpaths, container): os.chdir(projdir) os.system("scons") os.path.walk(projdir, glob_by_walk, ['*.elf', images]) + + # Update the size of pager in cinfo.c + pager_binary = "conts/bare" + str(container.id) + "/main.elf" + pager_path = join(PROJROOT, pager_binary) + update_cinfo_pagersize(container.id, pager_path) + container_packer = DefaultContainerPacker(container, images) return container_packer.pack_container() - def build_all_containers(): config = configuration_retrieve() diff --git a/scripts/kernel/generate_kernel_cinfo.py b/scripts/kernel/generate_kernel_cinfo.py index c419c5f..5ae1d19 100755 --- a/scripts/kernel/generate_kernel_cinfo.py +++ b/scripts/kernel/generate_kernel_cinfo.py @@ -60,11 +60,11 @@ cinfo_end = \ pager_start = \ ''' \t\t[0] = { -\t\t\t.start_address = (CONFIG_CONT%d_START_PC_ADDR), -\t\t\t.pager_lma = __pfn(CONFIG_CONT%d_PAGER_LMA), -\t\t\t.pager_vma = __pfn(CONFIG_CONT%d_PAGER_VMA), -\t\t\t.pager_size = __pfn(CONFIG_CONT%d_PAGER_MAPSIZE), -\t\t\t.ncaps = %d, +\t\t\t.start_address = (CONFIG_CONT%(cn)d_START_PC_ADDR), +\t\t\t.pager_lma = __pfn(CONFIG_CONT%(cn)d_PAGER_LMA), +\t\t\t.pager_vma = __pfn(CONFIG_CONT%(cn)d_PAGER_VMA), +\t\t\t.pager_size = __pfn(page_align_up(CONFIG_CONT%(cn)d_PAGER_MAPSIZE)), +\t\t\t.ncaps = %(caps)d, \t\t\t.caps = { ''' pager_end = \ @@ -179,6 +179,13 @@ pager_ifdefs_todotext = \ * complains that type deduction could not be done. */''' +# This will be filled after the containers are compiled +# and pager binaries are formed +pager_mapsize = \ +''' +#define CONFIG_CONT%s_PAGER_SIZE %s +''' + pager_ifdefs = \ ''' #if defined(CONFIG_CONT%(cn)d_TYPE_LINUX) @@ -187,9 +194,12 @@ pager_ifdefs = \ CONFIG_CONT%(cn)d_LINUX_PAGE_OFFSET) #define CONFIG_CONT%(cn)d_PAGER_LMA (CONFIG_CONT%(cn)d_LINUX_PHYS_OFFSET) #define CONFIG_CONT%(cn)d_PAGER_VMA (CONFIG_CONT%(cn)d_LINUX_PAGE_OFFSET) - #define CONFIG_CONT%(cn)d_PAGER_MAPSIZE CONFIG_CONT%(cn)d_LINUX_MAPSIZE + #define CONFIG_CONT%(cn)d_PAGER_MAPSIZE \\ + (CONFIG_CONT%(cn)d_PAGER_SIZE + CONFIG_CONT%(cn)d_LINUX_ZRELADDR - \\ + CONFIG_CONT%(cn)d_LINUX_PHYS_OFFSET) #else #define CONFIG_CONT%(cn)d_START_PC_ADDR (CONFIG_CONT%(cn)d_PAGER_VMA) + #define CONFIG_CONT%(cn)d_PAGER_MAPSIZE (CONFIG_CONT%(cn)d_PAGER_SIZE) #endif ''' def generate_pager_memory_ifdefs(containers): @@ -200,6 +210,13 @@ 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_ifdefs % { 'cn' : c.id } return pager_ifdef_string @@ -219,7 +236,7 @@ def generate_kernel_cinfo(config, cinfo_path): # Currently only these are considered as capabilities total_caps = c.virt_regions + c.phys_regions + total_other_caps fbody += cinfo_start % (c.id, c.name) - fbody += pager_start % (c.id, c.id, c.id, c.id, total_caps) + fbody += pager_start % { 'cn' : c.id, 'caps' : total_caps} cap_index = 0 for mem_index in range(c.virt_regions): fbody += cap_virtmem % { 'capidx' : cap_index, 'cn' : c.id, 'vn' : mem_index } diff --git a/src/generic/container.c b/src/generic/container.c index a939af9..73ee897 100644 --- a/src/generic/container.c +++ b/src/generic/container.c @@ -142,8 +142,8 @@ int init_pager(struct pager *pager, cap->resid = CAP_RESID_NONE; } - printk("%s: Mapping %lu pages from 0x%lx to 0x%lx for %s\n", - __KERNELNAME__, + printk("%s: Mapping %lx bytes (%lx pages) from 0x%lx to 0x%lx for %s\n", + __KERNELNAME__, pager->memsize, __pfn(page_align_up(pager->memsize)), pager->start_lma, pager->start_vma, cont->name);