diff --git a/conts/posix/SConstruct b/conts/posix/SConstruct index 0320032..e94e026 100644 --- a/conts/posix/SConstruct +++ b/conts/posix/SConstruct @@ -13,6 +13,7 @@ sys.path.append(PROJRELROOT) from config.projpaths import * from config.configuration import * +from config.lib import * config = configuration_retrieve() arch = config.arch @@ -45,7 +46,7 @@ LIBPOSIX_LIBPATH = join(BUILDDIR, LIBPOSIX_RELDIR) env = Environment(CC = 'arm-none-linux-gnueabi-gcc', CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', \ '-std=gnu99', '-Wall', '-Werror'], - LINKFLAGS = ['-nostdlib'], \ + LINKFLAGS = ['-nostdlib'], ASFLAGS = ['-D__ASSEMBLY__'], PROGSUFFIX = '.elf', ENV = {'PATH' : os.environ['PATH']}, @@ -65,19 +66,19 @@ libposix = SConscript('libposix/SConscript', \ mm0_env = env.Clone() mm0_env.Append(CPPPATH = LIBPOSIX_INCLUDE_SERVER) mm0 = SConscript('mm0/SConscript', \ - exports = { 'config' : config, 'env' : mm0_env, 'contid' : contid}, duplicate = 0, \ + exports = { 'config' : config, 'env' : mm0_env, 'contid' : contid }, duplicate = 0, \ variant_dir = join(BUILDDIR, 'cont' + str(contid) + '/posix' + '/mm0')) fs0_env = env.Clone() fs0_env.Append(CPPPATH = LIBPOSIX_INCLUDE_SERVER) fs0 = SConscript('fs0/SConscript', \ - exports = { 'config' : config, 'env' : fs0_env, 'contid' : contid}, duplicate = 0, \ + exports = { 'config' : config, 'env' : fs0_env, 'contid' : contid, 'previmage' : mm0 }, duplicate = 0, \ variant_dir = join(BUILDDIR, 'cont' + str(contid) + '/posix' + '/fs0')) test0_env = env.Clone() test0_env.Replace(CPPPATH = ['include', KERNEL_INCLUDE, LIBL4_INCLUDE, LIBMEM_INCLUDE]) test0 = SConscript('test0/SConscript', \ - exports = { 'config' : config, 'environment' : test0_env, 'contid' : contid}, duplicate = 0, \ + exports = { 'config' : config, 'environment' : test0_env, 'contid' : contid, 'previmage' : fs0 }, duplicate = 0, \ variant_dir = join(BUILDDIR, 'cont' + str(contid) + '/posix' + '/test0')) images = [mm0, fs0, test0] diff --git a/conts/posix/fs0/SConscript b/conts/posix/fs0/SConscript index 0356014..97ba5ff 100644 --- a/conts/posix/fs0/SConscript +++ b/conts/posix/fs0/SConscript @@ -1,17 +1,29 @@ -Import('config', 'env', 'contid') +Import('config', 'env', 'previmage', 'contid') import os, sys arch = config.arch +sys.path.append('../../../../') +from config.lib import * +from tools.pyelf.lmanext import * + src = [Glob('*.c') + Glob('src/*.c') + Glob('src/arch/arm/*.c') + Glob('src/memfs/*.c') + Glob('src/lib/*.c')] +def generate_lma_lds(target, source, env): + with open(source[1].path, 'r') as lds_in: + with open(target[0].path, 'w+') as lds_out: + linker_script = lds_in.read() + lds_out.write(linker_script % next_available_lma(source[0].path)) + +lma_lds = Command('include/linker.lds', [previmage, 'include/linker.lds.in'], generate_lma_lds) + e = env.Clone() e.Append(LIBS = 'posix') -e.Append(LINKFLAGS = ['-T' + "fs0/include/linker.lds", '-u_start']) +e.Append(LINKFLAGS = ['-T' + lma_lds[0].path, '-u_start']) objs = e.Object(src) fs0 = e.Program('fs0.elf', objs) - +Depends(fs0, lma_lds) Return('fs0') diff --git a/conts/posix/fs0/include/linker.lds b/conts/posix/fs0/include/linker.lds.in similarity index 70% rename from conts/posix/fs0/include/linker.lds rename to conts/posix/fs0/include/linker.lds.in index 90173fc..3fb6458 100644 --- a/conts/posix/fs0/include/linker.lds +++ b/conts/posix/fs0/include/linker.lds.in @@ -4,17 +4,9 @@ * Copyright (C) 2007 Bahadir Balban */ -/* - * The only catch with this linker script is that everything - * is linked starting at virtual_base, and loaded starting - * at physical_base. virtual_base is the predefined region - * of virtual memory for userland applications. physical_base - * is determined at build-time, it is one of the subsequent pages - * that come after the kernel image's load area. - */ /* USER_AREA_START, see memlayout.h */ virtual_base = 0x10000000; -physical_base = 0x8000; +physical_base = %s; __stack = (0x20000000 - 0x1000 - 8); /* First page before env/args page */ /* INCLUDE "include/physical_base.lds" */ diff --git a/conts/posix/mm0/SConscript b/conts/posix/mm0/SConscript index f7e8790..369e6f1 100644 --- a/conts/posix/mm0/SConscript +++ b/conts/posix/mm0/SConscript @@ -5,6 +5,11 @@ import os, sys arch = config.arch +sys.path.append('../../../../') +from config.lib import * + +container = next((c for c in config.containers if int(c.id) == int(contid)), None) + def create_symlinks(arch): arch_path = "include/arch" arch_path2 ="src/arch" @@ -15,12 +20,22 @@ def create_symlinks(arch): os.system("rm %s" % (arch_path2)) os.system("ln -s %s %s" % ("arch-" + arch, arch_path2)) +def generate_lma_lds(target, source, env): + with open(source[0].path, 'r') as lds_in: + with open(target[0].path, 'w+') as lds_out: + linker_script = lds_in.read() + lds_out.write(linker_script % conv_hex(container.pager_lma)) + +lma_lds = Command('include/linker.lds', 'include/linker.lds.in', generate_lma_lds) + src = [Glob('*.c') + Glob('src/*.c') + Glob('src/lib/*.c') + Glob('src/lib/elf/*.c') + Glob('src/arch/*.c')] e = env.Clone() -e.Append(LINKFLAGS = ['-T' + "mm0/include/linker.lds", '-u_start']) +e.Append(LINKFLAGS = ['-T' + lma_lds[0].path, '-u_start']) objs = e.Object(src) mm0 = e.Program('mm0.elf', objs) +Depends(mm0, lma_lds) Return('mm0') + diff --git a/conts/posix/mm0/include/linker.lds b/conts/posix/mm0/include/linker.lds.in similarity index 98% rename from conts/posix/mm0/include/linker.lds rename to conts/posix/mm0/include/linker.lds.in index 190f2fe..f91dd53 100644 --- a/conts/posix/mm0/include/linker.lds +++ b/conts/posix/mm0/include/linker.lds.in @@ -14,7 +14,7 @@ */ /* INITTASK_AREA_START, see memlayout.h */ virtual_base = 0xE0000000; -physical_base = 0x8000; +physical_base = %s; /* INCLUDE "include/physical_base.lds" */ diff --git a/conts/posix/test0/SConscript b/conts/posix/test0/SConscript index 1fd4759..f36d904 100644 --- a/conts/posix/test0/SConscript +++ b/conts/posix/test0/SConscript @@ -1,20 +1,33 @@ -Import('config', 'environment', 'contid') +Import('config', 'environment', 'previmage', 'contid') import os, sys arch = config.arch +sys.path.append('../../../../') +from config.lib import * +from tools.pyelf.lmanext import * + src = [Glob('*.[cS]') + Glob('src/*.c') + Glob('src/arch/arm/*.c')] +def generate_lma_lds(target, source, env): + with open(source[1].path, 'r') as lds_in: + with open(target[0].path, 'w+') as lds_out: + linker_script = lds_in.read() + lds_out.write(linker_script % next_available_lma(source[0].path)) + +lma_lds = Command('include/linker.lds', [previmage, 'include/linker.lds.in'], generate_lma_lds) + env = environment.Clone() test_env = environment.Clone() env.Append(LIBS = ['posix', 'c-userspace']) -env.Append(LINKFLAGS = ['-T' + "test0/include/linker.lds", '-u_start']) +env.Append(LINKFLAGS = ['-T' + lma_lds[0].path, '-u_start']) env.Append(CPPFLAGS = ' -D__USERSPACE__') objs = env.Object(src) test0 = env.Program('test0.elf', objs) +Depends(test0, lma_lds) test_env.Append(LIBS = ['posix', 'c-userspace']) test_env.Append(LINKFLAGS = ['-T' + "test0/include/test_exec_linker.lds", '-u_start']) diff --git a/conts/posix/test0/include/linker.lds b/conts/posix/test0/include/linker.lds.in similarity index 98% rename from conts/posix/test0/include/linker.lds rename to conts/posix/test0/include/linker.lds.in index e2edf97..8ee4e7b 100644 --- a/conts/posix/test0/include/linker.lds +++ b/conts/posix/test0/include/linker.lds.in @@ -14,7 +14,7 @@ */ /* USER_AREA_START, see memlayout.h */ virtual_base = 0x10000000; -physical_base = 0x8000; +physical_base = %s; __stack = (0x20000000 - 0x1000 - 8); /* First page before the env/args */ /* INCLUDE "include/physical_base.lds" */ diff --git a/scripts/conts/containers.py b/scripts/conts/containers.py index bc7a90a..8d7ed8d 100755 --- a/scripts/conts/containers.py +++ b/scripts/conts/containers.py @@ -30,15 +30,32 @@ def build_linux_container(projpaths, container): rootfs_builder) return linux_container_packer.pack_container() -def build_posix_container(projpaths, container): - posix_builder = PosixBuilder(projpaths, container) - posix_builder.build_posix() - def glob_by_walk(arg, dirname, names): ext, imglist = arg files = glob.glob(join(dirname, ext)) imglist.extend(files) +def source_to_builddir(srcdir, id): + cont_builddir = \ + os.path.relpath(srcdir, \ + PROJROOT).replace("conts", \ + "cont" + str(id)) + return join(BUILDDIR, cont_builddir) + +# We simply use SCons to figure all this out from container.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): + images = [] + print '\nBuilding the Posix Container...' + scons_cmd = 'scons -f ' + join(POSIXDIR, 'SConstruct') + ' cont=' str(container.id) + print "Issuing scons command: %s" % scons_cmd + os.system(scons_cmd) + builddir = source_to_builddir(POSIXDIR, container.id) + os.path.walk(builddir, glob_by_walk, ['*.elf', images]) + container_packer = DefaultContainerPacker(container, images) + return container_packer.pack_container() # This simply calls SCons on a given container, and collects # all images with .elf extension, instead of using whole classes