Dynamic generation of pager size

This commit is contained in:
Amit Mahajan
2009-11-01 23:41:49 +05:30
parent 8d9f5f82d0
commit 55eb6260c3
8 changed files with 93 additions and 41 deletions

View File

@@ -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):

View File

@@ -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 = .;
}
}

View File

@@ -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()

View File

@@ -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 }