diff --git a/config/configuration.py b/config/configuration.py index d657b9a..67b7d44 100644 --- a/config/configuration.py +++ b/config/configuration.py @@ -1,15 +1,23 @@ #! /usr/bin/env python2.6 # -*- mode: python; coding: utf-8; -*- - import os, sys, shelve, shutil +from projpaths import * -class config_symbols: +class container: + name = None + type = None + id = None + lma_start = None + lma_end = None + vma_start = None + vma_end = None + +class configuration: arch = None subarch = None platform = None - kbuild = [] all = [] - + containers = [] # Get all name value symbols def get_all(self, name, val): self.all.append([name, val]) @@ -45,3 +53,8 @@ class config_symbols: if name[:len("CONFIG_CONTAINERS")] == "CONFIG_CONTAINERS": self.ncontainers = val +def configuration_retrieve(): + # Get configuration information + config_shelve = shelve.open(CONFIG_SHELVE) + configuration = config_shelve["configuration"] + return configuration diff --git a/configure.py b/configure.py index d063fbd..a794419 100755 --- a/configure.py +++ b/configure.py @@ -6,9 +6,8 @@ from os.path import join from config.projpaths import * from config.configuration import * -symbols = config_symbols() -def cml2_header_to_symbols(cml2_header): +def cml2_header_to_symbols(cml2_header, symbols): with file(cml2_header) as header_file: for line in header_file: pair = symbols.line_to_name_value(line) @@ -20,11 +19,11 @@ def cml2_header_to_symbols(cml2_header): symbols.get_platform(name, value) symbols.get_ncontainers(name, value) -def cml2_update_config_h(symbols, config_h_path): +def cml2_update_config_h(config_h_path, config): with open(config_h_path, "a") as config_h: - config_h.write("#define __ARCH__ " + symbols.arch + '\n') - config_h.write("#define __PLATFORM__ " + symbols.platform + '\n') - config_h.write("#define __SUBARCH__ " + symbols.subarch + '\n') + config_h.write("#define __ARCH__ " + config.arch + '\n') + config_h.write("#define __PLATFORM__ " + config.platform + '\n') + config_h.write("#define __SUBARCH__ " + config.subarch + '\n') def cml2_configure(cml2_config_file): os.system(CML2TOOLSDIR + '/cmlcompile.py -o ' + CML2RULES + ' ' + cml2_config_file) @@ -34,26 +33,29 @@ def cml2_configure(cml2_config_file): os.mkdir("build/l4") shutil.copy(CML2_CONFIG_H, CONFIG_H) -def save_configuration(): +def save_configuration(configuration): if not os.path.exists(CONFIG_SHELVE_DIR): os.mkdir(CONFIG_SHELVE_DIR) config_shelve = shelve.open(CONFIG_SHELVE) - config_shelve["config_symbols"] = symbols - config_shelve["arch"] = symbols.arch - config_shelve["subarch"] = symbols.subarch - config_shelve["platform"] = symbols.platform - config_shelve["all_symbols"] = symbols.all + config_shelve["configuration"] = configuration + config_shelve["arch"] = configuration.arch + config_shelve["subarch"] = configuration.subarch + config_shelve["platform"] = configuration.platform + config_shelve["all_symbols"] = configuration.all config_shelve.close() def configure_kernel(cml_file): + config = configuration() + if not os.path.exists(BUILDDIR): os.mkdir(BUILDDIR) cml2_configure(cml_file) - cml2_header_to_symbols(CML2_CONFIG_H) - cml2_update_config_h(symbols, CONFIG_H) - save_configuration() + cml2_header_to_symbols(CML2_CONFIG_H, config) + cml2_update_config_h(CONFIG_H, config) + save_configuration(config) if __name__ == "__main__": configure_kernel(join(CML2_CONFIG_SRCDIR, "arm.cml")) + diff --git a/conts/linux/SConscript b/conts/linux/SConscript index 67b140d..5b936d7 100644 --- a/conts/linux/SConscript +++ b/conts/linux/SConscript @@ -4,19 +4,111 @@ # Copyright (C) 2009 B Labs # import os +import sys +import shutil from os.path import join Import('environment') -cwd = os.getcwd() +env = environment.Clone() -os.chdir("/opt/codezero/conts/linux") +linux_kernel_path = join("/opt/codezero/build/conts/linux/arch/arm/boot/compressed/vmlinux") +rootfs_path = join("rootfs/rootfs.elf") -os.system("scons") +container_assembler_body = \ +''' +.align 4 +.section .img.%d +.incbin "%s" +''' -image = [] -image.append(File("container.elf")) +container_lds_start = \ +'''/* + * Autogenerated linker script that embeds each container image. + * + * Copyright (C) 2009 B Labs + */ -os.chdir(cwd) +SECTIONS +{''' -Return('image') +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() + +linux_builddir="/opt/codezero/build/conts/linux/build" +linux_srcdir = "/opt/codezero/conts/linux/linux-2.6.28.10" +linux_image = join(linux_builddir, "arch/arm/compressed/vmlinux") + +def build_linux(source, target, env): + cwd = os.getcwd() + os.chdir(source[0].path) + print target[1].path + os.system("mkdir -p " + linux_builddir) + os.system("make defconfig " + "ARCH=arm " + "O=" + linux_builddir) + os.system("make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- O=" + linux_builddir) + os.chdir(cwd) + +images = [] +linux_kernel = env.Command([linux_image, linux_builddir], linux_srcdir, 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]) + +#image = [] +#image.append(File("container.elf")) + + +Return('linux_kernel') diff --git a/loader/SConstruct b/loader/SConstruct index 535aa67..bc2b2ac 100644 --- a/loader/SConstruct +++ b/loader/SConstruct @@ -5,31 +5,21 @@ # Copyright © 2009 B Labs Ltd import os, sys, shelve +from os.path import join # Get global paths PROJRELROOT = '../' -cwd = os.getcwd() -os.chdir(PROJRELROOT) -execfile("configdata.py") -os.chdir(cwd) - -# Get configuration information -config_shelve = shelve.open(CONFIG_SHELVE) - -#symbols = config_shelve["config_symbols"] -arch = config_shelve["arch"] -subarch = config_shelve["subarch"] -platform = config_shelve["platform"] -all_syms = config_shelve["all_symbols"] +arch = 'arm' +platform = 'pb926' # Locally important paths are here -LIBC_PATH = '../libs/c' +LIBC_PATH = 'libs/c' LIBC_LIBPATH = LIBC_PATH LIBC_INCPATH = [join(LIBC_PATH, 'include'), \ join(LIBC_PATH, 'include/arch/' + arch)] LIBC_CRT_PATH = join(LIBC_PATH, "crt/sys-baremetal/arch-" + arch + "/crt0.o") -LIBELF_PATH = '../libs/elf' +LIBELF_PATH = 'libs/elf' LIBELF_LIBPATH = LIBELF_PATH LIBELF_INCPATH = join(LIBELF_PATH, 'include') @@ -38,7 +28,7 @@ env = Environment(CC = 'arm-none-eabi-gcc', # such as stdarg.h e.g. for variable args, as in printk(). CCFLAGS = ['-g', '-mcpu=arm926ej-s', '-nostdlib', '-ffreestanding', \ '-std=gnu99', '-Wall', '-Werror'], - LINKFLAGS = ['-nostdlib', '-T' + "linker.lds"], + LINKFLAGS = ['-nostdlib', '-T' + "linker.lds", "-u_start"], ASFLAGS = ['-D__ASSEMBLY__'], PROGSUFFIX = '.elf', ENV = {'PATH' : os.environ['PATH']}, @@ -46,15 +36,7 @@ env = Environment(CC = 'arm-none-eabi-gcc', LIBPATH = [LIBC_LIBPATH, LIBELF_LIBPATH], CPPPATH = ['#include', LIBC_INCPATH, LIBELF_INCPATH]) -config_shelve = shelve.open(CONFIG_SHELVE) -#symbols = config_shelve["config_symbols"] -arch = config_shelve["arch"] -subarch = config_shelve["subarch"] -platform = config_shelve["platform"] -all_syms = config_shelve["all_symbols"] - src = Glob('*.[cS]') -crt0 = Glob(LIBC_CRT_PATH) objs = env.Object(src) -env.Program('final.elf', objs + crt0) +env.Program('final.elf', objs) diff --git a/loader/libs/c/SConstruct b/loader/libs/c/SConstruct index 6188362..48da97a 100644 --- a/loader/libs/c/SConstruct +++ b/loader/libs/c/SConstruct @@ -6,11 +6,10 @@ import os, sys, shelve -PROJROOT="../../../" -cwd = os.getcwd() -os.chdir(PROJROOT) -execfile("configure.py") -os.chdir(cwd) +arch = 'arm' +subarch = 'v5' +platform = 'pb926' +variant = "baremetal" env = Environment(CC = 'arm-none-eabi-gcc', # We don't use -nostdinc because sometimes we need standard headers, @@ -24,15 +23,6 @@ env = Environment(CC = 'arm-none-eabi-gcc', LIBS = 'gcc', # libgcc.a - This is required for division routines. CPPPATH = "#include") -config_shelve = shelve.open(CONFIG_SHELVE) -#symbols = config_shelve["config_symbols"] -arch = config_shelve["arch"] -subarch = config_shelve["subarch"] -platform = config_shelve["platform"] -all_syms = config_shelve["all_symbols"] - -variant = "baremetal" - e = env.Clone() e.Append(CPPPATH = ['include/sys-' + variant + '/arch-' + arch]) e.Append(CCFLAGS = '-nostdinc') diff --git a/loader/libs/elf/SConscript b/loader/libs/elf/SConscript index 91e95f0..5334e6e 100644 --- a/loader/libs/elf/SConscript +++ b/loader/libs/elf/SConscript @@ -1,5 +1,5 @@ # -*- mode: python; coding: utf-8; -*- - +# # Codezero -- a microkernel for embedded systems. # # Copyright © 2009 B Labs Ltd diff --git a/loader/libs/elf/SConstruct b/loader/libs/elf/SConstruct index bdef6ad..8d177a8 100644 --- a/loader/libs/elf/SConstruct +++ b/loader/libs/elf/SConstruct @@ -5,22 +5,13 @@ # Copyright © 2009 B Labs Ltd import os, sys, shelve +from os.path import join + +arch = 'arm' +platform = 'pb926' # Get global paths PROJRELROOT="../../../" -cwd = os.getcwd() -os.chdir(PROJRELROOT) -execfile("configure.py") -os.chdir(cwd) - -# Get configuration information -config_shelve = shelve.open(CONFIG_SHELVE) -#symbols = config_shelve["config_symbols"] -arch = config_shelve["arch"] -subarch = config_shelve["subarch"] -platform = config_shelve["platform"] -all_syms = config_shelve["all_symbols"] - # Locally important paths are here LIBC_PATH = '../c'