From 0d2ec30f9cb6a0b2fa02d15722425655dc5074b1 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Fri, 18 Sep 2009 17:47:37 +0300 Subject: [PATCH] Added functionality to create a bare container --- config/cml/arm.cml | 2 +- config/configuration.py | 5 ++ configure.py | 23 ++++--- scripts/bare/SConstruct.in | 0 scripts/bare/__init__.py | 0 scripts/bare/bare_generator.py | 103 +++++++++++++++++++++++++++++ scripts/bare/build.readme.in | 115 +++++++++++++++++++++++++++++++++ scripts/bare/container.desc.in | 0 8 files changed, 239 insertions(+), 9 deletions(-) create mode 100644 scripts/bare/SConstruct.in create mode 100644 scripts/bare/__init__.py create mode 100644 scripts/bare/bare_generator.py create mode 100644 scripts/bare/build.readme.in create mode 100644 scripts/bare/container.desc.in diff --git a/config/cml/arm.cml b/config/cml/arm.cml index 5ec750a..1cd77fd 100644 --- a/config/cml/arm.cml +++ b/config/cml/arm.cml @@ -187,7 +187,7 @@ choices container1_type CONFIG_CONT1_TYPE_LINUX CONFIG_CONT1_TYPE_BARE CONFIG_CONT1_TYPE_C0_POSIX - default CONFIG_CONT1_TYPE_LINUX + default CONFIG_CONT1_TYPE_BARE menu cont0_menu container0_type diff --git a/config/configuration.py b/config/configuration.py index 75215db..6af28c0 100644 --- a/config/configuration.py +++ b/config/configuration.py @@ -5,6 +5,7 @@ from projpaths import * class Container: def __init__(self): + self.dirname = None self.name = None self.type = None self.id = None @@ -67,6 +68,10 @@ class configuration: self.containers[id].lma_start = val elif param[:len("PHYS_END")] == "PHYS_END": self.containers[id].lma_end = val + elif param[:len("OPT_DIRNAME")] == "OPT_DIRNAME": + dirname = val[1:-1].lower() + self.containers[id].dirname = dirname + self.containers[id].name = dirname else: param1, param2 = param.split("_", 1) if param1 == "TYPE": diff --git a/configure.py b/configure.py index 7b0bba4..0835424 100755 --- a/configure.py +++ b/configure.py @@ -5,20 +5,21 @@ import os, sys, shelve, shutil from os.path import join from config.projpaths import * from config.configuration import * +from scripts.bare.bare_generator import * -def cml2_header_to_symbols(cml2_header, symbols): +def cml2_header_to_symbols(cml2_header, config): with file(cml2_header) as header_file: for line in header_file: - pair = symbols.line_to_name_value(line) + pair = config.line_to_name_value(line) if pair is not None: name, value = pair - symbols.get_all(name, value) - symbols.get_arch(name, value) - symbols.get_subarch(name, value) - symbols.get_platform(name, value) - symbols.get_ncontainers(name, value) - symbols.get_container_parameters(name, value) + config.get_all(name, value) + config.get_arch(name, value) + config.get_subarch(name, value) + config.get_platform(name, value) + config.get_ncontainers(name, value) + config.get_container_parameters(name, value) def cml2_update_config_h(config_h_path, config): with open(config_h_path, "a") as config_h: @@ -43,7 +44,13 @@ def configure_kernel(cml_file): cml2_configure(cml_file) cml2_header_to_symbols(CML2_CONFIG_H, config) cml2_update_config_h(CONFIG_H, config) + configuration_save(config) + + # Generate bare container files if new ones defined + bare_cont_gen = BareContGenerator() + bare_cont_gen.bare_container_generate(config) + #config.config_print() if __name__ == "__main__": diff --git a/scripts/bare/SConstruct.in b/scripts/bare/SConstruct.in new file mode 100644 index 0000000..e69de29 diff --git a/scripts/bare/__init__.py b/scripts/bare/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/bare/bare_generator.py b/scripts/bare/bare_generator.py new file mode 100644 index 0000000..8807f7a --- /dev/null +++ b/scripts/bare/bare_generator.py @@ -0,0 +1,103 @@ +#! /usr/bin/env python2.6 +# -*- mode: python; coding: utf-8; -*- +# +# Codezero -- Virtualization microkernel for embedded systems. +# +# Copyright © 2009 B Labs Ltd +# +import os, sys, shelve, glob +from os.path import join + +PROJRELROOT = '../../' + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT))) +sys.path.append(os.path.abspath("../")) + +SCRIPTROOT = os.path.abspath(os.path.dirname(__file__)) + +from config.projpaths import * +from config.configuration import * + +class BareContGenerator: + def __init__(self): + self.CONT_SRC_DIR = '' # Set when container is selected + self.BARE_SRC_BASEDIR = join(PROJROOT, 'conts') + + self.build_script_in = join(SCRIPTROOT, 'SConstruct.in') + self.build_readme_in = join(SCRIPTROOT, 'build.readme.in') + self.build_desc_in = join(SCRIPTROOT, 'container.desc.in') + + self.build_script_name = 'SConstruct' + self.build_readme_name = 'build.readme' + self.build_desc_name = 'container.description' + + self.build_script_out = None + self.build_readme_out = None + self.build_desc_out = None + self.main_builder_name = 'build.py' + self.main_configurator_name = 'configure.py' + self.mailing_list_url = 'http://lists.l4dev.org/mailman/listinfo/codezero-devel' + + def create_bare_dirtree(self, config, cont): + # First, create the container directory structure + os.mkdir(self.CONT_SRC_DIR) + os.mkdir(join(self.CONT_SRC_DIR, 'src')) + os.mkdir(join(self.CONT_SRC_DIR, 'include')) + + def copy_bare_build_desc(self, config, cont): + with open(self.build_desc_in) as fin: + str = fin.read() + with open(self.build_desc_out, 'w+') as fout: + # Make any manipulations here + fout.write(str) + + def copy_bare_build_readme(self, config, cont): + with open(self.build_readme_in) as fin: + str = fin.read() + with open(self.build_readme_out, 'w+') as fout: + # Make any manipulations here + fout.write(str % (self.mailing_list_url, \ + cont.name, \ + self.build_desc_name, \ + self.main_builder_name, \ + self.main_configurator_name, \ + self.main_configurator_name)) + + def copy_bare_build_script(self, config, cont): + with open(self.build_script_in) as fin: + str = fin.read() + with open(self.build_script_out, 'w+') as fout: + # Make any manipulations here + fout.write(str) + + def create_bare_sources(self, config, cont): + # Determine container directory name. + self.CONT_SRC_DIR = join(self.BARE_SRC_BASEDIR, cont.dirname.lower()) + print "container source dir: " + self.CONT_SRC_DIR + + self.build_script_out = join(self.CONT_SRC_DIR, self.build_script_name) + self.build_readme_out = join(self.CONT_SRC_DIR, self.build_readme_name) + self.build_desc_out = join(self.CONT_SRC_DIR, self.build_desc_name) + + self.create_bare_dirtree(config, cont) + self.copy_bare_build_script(config, cont) + self.copy_bare_build_readme(config, cont) + self.copy_bare_build_desc(config, cont) + #copy_bare_sources(config, cont) + + def check_create_bare_sources(self, config): + for cont in config.containers: + if cont.type == "bare": + print "Cont type: " + cont.type + if not os.path.exists(join(self.BARE_SRC_BASEDIR, cont.dirname)): + print "Creating new at " + join(self.BARE_SRC_BASEDIR, cont.dirname) + self.create_bare_sources(config, cont) + + def bare_container_generate(self, config): + self.check_create_bare_sources(config) + +if __name__ == "__main__": + config = configuration_retrieve() + bare_cont = BareContGenerator() + bare_cont.bare_container_generate(config) + diff --git a/scripts/bare/build.readme.in b/scripts/bare/build.readme.in new file mode 100644 index 0000000..2ddfbef --- /dev/null +++ b/scripts/bare/build.readme.in @@ -0,0 +1,115 @@ + Codezero Buildsystem For This Container + + Autogenerated by the Build system + + +This is an autogenerated file that is meant to walk you through the build +process. It is meant to be the most simple to get on with, therefore if +you feel any complications, please reach us on our l4dev.org mailing list +on %s + +You have created a new container called `%s'. + +The parameters you have supplied are described in the "%s" file +placed at the top-level directory. Note, that this is only an informative +file for your reference, and it can be optionally removed. + + + 1. Directory Structure: + +1.1) Directory tree: +. +|-- SConstruct +|-- build.readme +|-- container.desc +|-- include +| `-- linker.lds.example +|-- main.c +`-- src + |-- test.c + |-- test1.c + |-- test2.c + `-- test3.c + +In the above directory tree: + +1.2) |-- SConstruct + +This is the top-level build file, that will build your project in its current +state. You may freely reorganize directories, but must reflect changes in this +file. For more, please see the SCons build tool at http://www.scons.org/ + +The build system will search for this file, and execute it by the: + +`scons' + +command at the root of the directory. You may issue the same command manually +for building and testing your build. If you choose to use another build tool +such as make, you may freely replace scons, and the build system will search +and call your custom build command. + +1.3) |--include + `--src + +These are the directories that include your header files and sources. You may +freely change and reorganize these, but make sure to have a valid build file +that reflects those changes at the top-level directory. + +1.4) |-- include + | `-- linker.lds.example + +This is an example linker script for your project. Using this as your default +linker script is often useful, since it has been autogenerated to contain all +the parameters you need for the memory regions of your application defined at +configuration time. You may freely replace it, but make sure to edit the +top-level build script accordingly. + + + 2. Build Process + +2.1) Build overview + +The complete Codezero system will be built from a top-level `%s' script by +that resides in the top-level directory of Codezero sources. + +The Codezero system build script will build this container at a certain stage +during the build, by referring to build script file named such as `SConstruct' +or `Makefile' that resides in this container's top-level directory. + +Once the executables are built, it will search for all files with a .elf +extension in any of the subdirectories, and recognize those as loadable +executables. There may be more than one of these files present after the build. + +In the future this behaviour may change such that the loadable executable files +are also specified in the configuration. + +Finally, executables of all containers will be picked up and built into the +final.elf file, which is a self-loading elf executable. + + + 3. Reconfiguring this container + +If you want to reconfigure the container with new parameters, you may do so by +executing the `%s' script at the top-level Codezero directory by: + +'./%s' + +This will populate only brand new container directories with new files. It will +update it's existing internal configuration for existing containers (such as +container memory regions) but it won't touch any files that exist under an +already-defined container. + +If you want to start from scratch, specify a new directory name, if you want +to reconfigure existing container parameters, run this on an existing directory, +and it will only update its internal records for this container, but not touch +the directory. + + + 4. Example source files + +Example source files populated by the configuration contain valid examples +of how the generic libl4 userspace library can be used. Each test contains a +valid example from the available API, and may be modified, changed and removed +freely. + + diff --git a/scripts/bare/container.desc.in b/scripts/bare/container.desc.in new file mode 100644 index 0000000..e69de29