diff --git a/SConstruct b/SConstruct index fa2fd1d..4bf9f19 100644 --- a/SConstruct +++ b/SConstruct @@ -25,7 +25,7 @@ from __future__ import with_statement import os includeDirectory = 'include' -containersDirectory = 'containers' +containersDirectory = 'conts' toolsDirectory = 'tools' cml2ToolsDirectory = toolsDirectory + '/cml2-tools' buildDirectory = 'build' @@ -177,7 +177,7 @@ configuration data. 'scons -h' will then print the project help. ########## Handle all the container creation ####################### - containers = SConscript('containers/SConscript', variant_dir = buildDirectory + '/containers', duplicate = 0, exports = {'environment': baseEnvironment, 'startAxf': startAxf}) + containers = SConscript(containersDirectory + '/linux/SConscript', variant_dir = buildDirectory + '/' + containersDirectory, duplicate = 0, exports = {'environment': baseEnvironment, 'startAxf': startAxf}) Alias('containers', containers) baseEnvironment['targetHelpEntries']['containers'] = 'build all the containers.' diff --git a/conts/linux/SConscript b/conts/linux/SConscript new file mode 100644 index 0000000..71f7e9e --- /dev/null +++ b/conts/linux/SConscript @@ -0,0 +1,106 @@ +# +# Build script to autogenerate and compile a container image +# +# Copyright (C) 2009 B Labs +# +import os +import sys +import shutil +from os.path import join + +linux_kernel_path = join("/opt/codezero/build/conts/linux/arch/arm/boot/compressed/vmlinux") +rootfs_path = join("rootfs/rootfs.elf") + +container_assembler_body = \ +''' +.align 4 +.section .img.%d +.incbin "%s" +''' + +container_lds_start = \ +'''/* + * Autogenerated linker script that embeds each container image. + * + * Copyright (C) 2009 B Labs + */ + +SECTIONS +{''' + +container_lds_body = \ +''' + .img.%d : { *(.img.%d) }''' + +container_lds_end = \ +''' +} +''' + +# TODO: This might be done much more elegantly and flexibly. +# +# But it makes sense to put the image finding logic to a function +# rather than hard-code it in an array at the beginning. +def collect_images(target, source, env): + cmd1 = "cp " + linux_kernel_path + " ./" + cmd2 = "cp " + rootfs_path + " ./" + os.system(cmd1) + os.system(cmd2) + os.system("echo " + cmd1) + os.system("echo " + cmd2) + + images.append("vmlinux") + images.append("rootfs.elf") + for i in images: + print i + +def generate_container_assembler(source, target, env): + f = open("container.S", "w+") + file_body = "" + img_i = 0 + for img in source: + file_body += container_assembler_body % (img_i, img) + img_i += 1 + + f.write(file_body) + f.close() + +def generate_container_lds(source, target, env): + f = open("container.lds", "w+") + img_i = 0 + file_body = container_lds_start + for img in source: + file_body += container_lds_body % (img_i, img_i) + img_i += 1 + file_body += container_lds_end + f.write(file_body) + f.close() + +def build_rootfs(source, target, env): + os.chdir("./rootfs") + os.system("./build_rootfs.sh") + os.chdir("..") + +def build_linux(source, target, env): + os.system("./build_linux.sh") + +env = Environment(CC = 'arm-none-linux-gnueabi-gcc', + CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', \ + '-std=gnu99', '-Wall', '-Werror'], + LINKFLAGS = ['-nostdlib'], + PROGSUFFIX = '.elf', # The suffix to use for final executable + ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path + ) +images = [] +linux_kernel = env.Command(linux_kernel_path, "linux-2.6.28.10", build_linux) +rootfs = env.Command(rootfs_path, "rootfs/rootfs.img", build_rootfs) +env.Command(["vmlinux", "rootfs.elf"], [linux_kernel_path, rootfs_path], collect_images) +container_S = env.Command("container.S", ["vmlinux", "rootfs.elf"], generate_container_assembler) +container_lds = env.Command("container.lds", ["vmlinux", "rootfs.elf"], generate_container_lds) + +env.Replace(LINKFLAGS = ['-nostdlib', '-Tcontainer.lds']) +env.Replace(PROGSUFFIX = '.elf') +objs = env.Object('container.S') +container = env.Program('container.elf', objs) +env.Depends(container, [linux_kernel, rootfs, container_S, container_lds]) + diff --git a/conts/SConscript b/conts/posix/SConscript similarity index 100% rename from conts/SConscript rename to conts/posix/SConscript