Merge branch 'newBuild' of /opt/c0-trees/codezero-russel into devel

Conflicts:

	SConstruct
	src/api/SConscript
	src/arch/arm/SConscript
	src/generic/SConscript
	tasks/bootdesc/SConstruct
This commit is contained in:
Bahadir Balban
2009-08-14 17:09:58 +03:00
47 changed files with 998 additions and 1573 deletions

View File

@@ -1,2 +0,0 @@
*.txt
bootdesc.c.append

91
tasks/bootdesc/SConscript Normal file
View File

@@ -0,0 +1,91 @@
# -*- mode: python; coding: utf-8; -*-
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
# Author: Russel Winder
import os.path
import subprocess
import shutil
Import('environment', 'images')
bootdescTemplate = \
'''
/* This file is autogenerated, do not edit by hand. */
/* Supervisor task at load time. */
struct svc_image {
char name[16];
unsigned int phys_start;
unsigned int phys_end;
} __attribute__((__packed__));
/* Supervisor task descriptor at load time */
struct bootdesc {
int desc_size;
int total_images;
struct svc_image images[];
} __attribute__((__packed__));
struct bootdesc bootdesc = {
.desc_size = sizeof(struct bootdesc) + sizeof(struct svc_image) * %s,
.total_images = %s,
.images = {
%s
},
};
'''
imageTemplate = \
''' [%s] = {
.name = "%s",
.phys_start = %s,
.phys_end = %s,
},
'''
def generateLocationData(image):
process = subprocess.Popen('tools/pyelf/readelf.py --lma-start-end ' + image.path, shell=True, stdout=subprocess.PIPE)
assert process.wait() == 0
return (process.stdout.readline().strip(), process.stdout.readline().strip().split()[1], process.stdout.readline().strip().split()[1])
def generateBootdesc(target, source, env):
'''
Extracts name, start, end information from the kernel and each svc task.
Uses this information to produce bootdesc.c
'''
with open(target[0].path, 'w' ) as f:
imagesString = ''
numberOfImages = len(source) - 1
for index in range(1, len(source)):
imagesString += imageTemplate % ((index - 1,) + generateLocationData(source[index]))
f.write(bootdescTemplate % (numberOfImages, numberOfImages, imagesString))
def relocateBootdesc(target, source, env):
name, start, end = generateLocationData(source[1])
process = subprocess.Popen(executable='arm-none-linux-gnueabi-objcopy', args=(
'--adjust-section-vma .data=' + end,
source[0].path))
assert process.wait() == 0
shutil.copyfile(source[0].path, target[0].path)
bootdescSource = environment.Command('bootdesc.c', images, generateBootdesc)
objects = environment.Object(bootdescSource)
Depends(objects, environment['configFiles'])
bootdesc = environment.Command('bootdesc.axf', environment.Program('bootdesc_intermediate', objects) + [images[0]] , relocateBootdesc)
Return('bootdesc')

View File

@@ -1,124 +0,0 @@
#
# Build script to autogenerate a bootdesc image
#
# Copyright (C) 2007 Bahadir Balban
#
import os
import sys
import shutil
from os.path import join
# The root directory of the repository where this file resides:
project_root = "../.."
tools_root = "../../tools"
kernel = join(project_root, "build/start.axf")
mm0 = join(project_root, "tasks/mm0/mm0.axf")
fs0 = join(project_root, "tasks/fs0/fs0.axf")
test0 = join(project_root, "tasks/test0/test0.axf")
#test1 = join(project_root, "tasks/test1/test1.axf")
#blkdev0 = join(project_root, "tasks/fsbin/blkdev0.axf")
images = [kernel, mm0, fs0, test0]
autogen_templ = "bootdesc.c.append"
def get_image_name_start_end(image, target):
'''
Using readelf.py utility, extracts name, start, end triplet from an arm-elf image.
'''
rest, name = os.path.split(image)
if name[-4] == ".":
name = name[:-4]
os.system(join(tools_root, "pyelf/readelf.py --lma-start-end " + \
image + " > " + target))
bootdesc_template = \
'''
struct bootdesc bootdesc = {
.desc_size = sizeof(struct bootdesc) + sizeof(struct svc_image) * %s,
.total_images = %s,
.images = {
%s
},
};
'''
images_template = \
''' [%s] = {
.name = "%s",
.phys_start = %s,
.phys_end = %s,
},
'''
images_template_end = \
'''
},
'''
def generate_bootdesc(source, target, env):
'''
Extracts name, start, end information from the kernel and each svc task.
Uses this information to produce bootdesc.c
'''
source.sort()
images = []
images_string = ""
for node in source:
if str(node)[-4:] == ".axf":
rest, imgname = os.path.split(str(node))
images.append((str(node), imgname[:-4]))
elif str(node) [-6:] == ".templ":
# Static template that has type definitions.
#rest, original_template = os.path.split(str(node))
original_template = str(node)
index = 0
for imgpath, imgname in images:
get_image_name_start_end(imgpath, imgname + ".txt")
if imgname != "start":
f = open(imgname + ".txt", "r")
svc_name = f.readline()[:-1]
[start, startval] = str.split(f.readline()[:-1])
[end, endval] = str.split(f.readline()[:-1])
f.close()
images_string += images_template % (str(index), svc_name, \
hex(int(startval, 16)), hex(int(endval, 16)))
index += 1
# Autogenerated template with actual data.
autogen_template = open(autogen_templ, "w+")
autogen_template.write(bootdesc_template % (str(index), str(index), images_string))
autogen_template.close()
os.system("cat " + original_template + " > " + str(target[0]))
os.system("cat " + autogen_templ + " >> " + str(target[0]))
# Relocate to end of mm0 instead of end of kernel
def relocate_bootdesc(source, target, env):
f = open("mm0.txt", "r")
kernel_name = f.readline()[:-1]
[start, startval] = str.split(f.readline()[:-1])
[end, endval] = str.split(f.readline()[:-1])
os.system("arm-none-linux-gnueabi-objcopy --adjust-section-vma .data=" + \
hex(int(endval,16)) + " " + str(source[0]))
os.system("mv " + str(source[0]) + " " + str(target[0]))
# The kernel build environment:
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
# We don't use -nostdinc because sometimes we need standard headers,
# such as stdarg.h e.g. for variable args, as in printk().
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror'],
LINKFLAGS = ['-nostdlib','-Tlinker.lds'],
ASFLAGS = ['-D__ASSEMBLY__'],
PROGSUFFIX = '.axf', # The suffix to use for final executable
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
LIBS = 'gcc', # libgcc.a - This is required for division routines.
CPPPATH = '#include') # `hash' ('#') is a shorthand meaning `relative to
# the root directory'. But this only works for
# well-defined variables, not all paths, and only
# if we use a relative build directory for sources.
bootdesc_src = env.Command("bootdesc.c", ["bootdesc.c.templ"] + images, generate_bootdesc)
objs = env.Object('bootdesc.c')
bootdesc = env.Program('bootdesc_data', objs)
bootdesc_relocated = env.Command("bootdesc.axf", "bootdesc_data.axf", relocate_bootdesc)
env.Depends(bootdesc_relocated, bootdesc)

View File

@@ -1,16 +0,0 @@
/* Supervisor task at load time. */
struct svc_image {
char name[16];
unsigned int phys_start;
unsigned int phys_end;
} __attribute__((__packed__));
/* Supervisor task descriptor at load time */
struct bootdesc {
int desc_size;
int total_images;
struct svc_image images[];
} __attribute__((__packed__));

24
tasks/fs0/SConscript Normal file
View File

@@ -0,0 +1,24 @@
# -*- mode: python; coding: utf-8; -*-
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
# Author: Russel Winder
Import('environment', 'previousImage')
program = environment['buildTask']('fs0', Glob('*.c') + [Glob(directory + '/*.c') for directory in [ 'src', 'src/lib', 'src/lib/elf', 'src/memfs']], environment, previousImage)
Return('program')

View File

@@ -1,75 +0,0 @@
#
# User space application build script
#
# Copyright (C) 2007 Bahadir Balban
#
import os
import sys
import shutil
from os.path import join
from glob import glob
task_name = "fs0"
# The root directory of the repository where this file resides:
project_root = "../.."
tools_root = join(project_root, "tools")
prev_image = join(project_root, "tasks/mm0/mm0.axf")
libs_path = join(project_root, "libs")
ld_script = "include/linker.lds"
physical_base_ld_script = "include/physical_base.lds"
# libc paths:
libc_variant = "userspace"
libc_libpath = join(libs_path, "c/build/%s" % libc_variant)
libc_incpath = join(libc_libpath, "include")
libc_crt0 = join(libs_path, "c/build/crt/sys-userspace/arch-arm/crt0.o")
libc_name = "c-%s" % libc_variant
#libmem paths:
libmem_path = "../libmem"
libmem_incpath = "../libmem"
# libl4 paths:
libl4_path = "../libl4"
libl4_incpath1 = join(libl4_path, "include")
# libposix paths:
libposix_path = "../libposix"
libposix_incpath = join(libposix_path, "include")
# kernel paths:
kernel_incpath = join(project_root, "include")
# If crt0 is in its library path, it becomes hard to link with it.
# For instance the linker script must use an absolute path for it.
def copy_crt0(source, target, env):
os.system("cp " + str(source[0]) + " " + str(target[0]))
def get_physical_base(source, target, env):
os.system(join(tools_root, "pyelf/readelf.py --first-free-page " + \
prev_image + " >> " + physical_base_ld_script))
# The kernel build environment:
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
# We don't use -nostdinc because sometimes we need standard headers,
# such as stdarg.h e.g. for variable args, as in printk().
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror'],
LINKFLAGS = ['-nostdlib', '-T' + ld_script, "-L" + libc_libpath, "-L" + libl4_path,\
"-L" + libmem_path, "-L" + libposix_path],
ASFLAGS = ['-D__ASSEMBLY__'],
PROGSUFFIX = '.axf', # The suffix to use for final executable
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
LIBS = [libc_name, 'gcc', 'libmc', 'libl4', 'gcc', libc_name, "posix"],
CPPFLAGS = "-D__USERSPACE__",
CPPPATH = ['#include', libl4_incpath1, kernel_incpath, libc_incpath, \
libposix_incpath, libmem_incpath])
src = [glob("src/*.c"), glob("*.c"), glob("src/arch/arm/*.c"), glob("src/memfs/*.c"), glob("src/lib/*.c")]
objs = env.Object(src)
physical_base = env.Command(physical_base_ld_script, prev_image, get_physical_base)
crt0_copied = env.Command("crt0.o", libc_crt0, copy_crt0)
task = env.Program(task_name, objs + [crt0_copied])
env.Alias(task_name, task)
env.Depends(task, physical_base)

33
tasks/libl4/SConscript Normal file
View File

@@ -0,0 +1,33 @@
# -*- mode: python; coding: utf-8; -*-
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
# Author: Russel Winder
Import('environment')
e = environment.Clone()
e.Append(CPPPATH = ['include'])
# TODO: There are errors in this code that -Werror gives problems with.
e['CCFLAGS'] = ['-g', '-nostdlib', '-Wall', '-ffreestanding', '-std=gnu99']
objects = e.StaticObject(Glob('src/*.c') + Glob('src/' + e['ARCH'] + '/*.[cS]'))
Depends(objects, e['configFiles'])
library = e.StaticLibrary('l4', objects)
Return('library')

View File

@@ -1,84 +0,0 @@
#
# Copyright (C) 2007 Bahadir Balban
#
import os
import glob
import sys
from os.path import join
from string import split
# libposix paths:
libposix_libpath = "../libposix"
libposix_incpath = "../libposix/include/posix"
project_root = "../.."
kernel_headers = join(project_root, "include")
config_h = join(project_root, "include/l4/config.h")
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding'],
LINKFLAGS = ['-nostdlib'],
ASFLAGS = ['-D__ASSEMBLY__'],
ENV = {'PATH' : os.environ['PATH']},
LIBS = 'gcc',
CPPPATH = ['#include', libposix_incpath])
def extract_arch_subarch_plat(config_header):
'''
From the autogenerated kernel config.h, extracts platform, archictecture,
subarchitecture information. This is used to include the relevant headers
from the kernel directories.
'''
arch = None
subarch = None
plat = None
if not os.path.exists(config_header):
print "\n\nconfig.h does not exist. "\
"Please run: `scons configure' first\n\n"
sys.exit()
f = open(config_h, "r")
while True:
line = f.readline()
if line == "":
break
parts = split(line)
if len(parts) > 0:
if parts[0] == "#define":
if parts[1] == "__ARCH__":
arch = parts[2]
elif parts[1] == "__PLATFORM__":
plat = parts[2]
elif parts[1] == "__SUBARCH__":
subarch = parts[2]
f.close()
if arch == None:
print "Error: No config symbol found for architecture"
sys.exit()
if subarch == None:
print "Error: No config symbol found for subarchitecture"
sys.exit()
if plat == None:
print "Error: No config symbol found for platform"
sys.exit()
return arch, subarch, plat
def create_symlinks(arch):
if not os.path.exists("include/l4lib/arch"):
os.system("ln -s %s %s" % ("arch-" + arch, "include/l4lib/arch"))
arch, subarch, plat = extract_arch_subarch_plat(config_h)
create_symlinks(arch) # Creates symlinks to architecture specific directories.
headers = ["#include", "#include/libl4/arch", kernel_headers]
env.Append(CPPPATH = headers)
src = glob.glob("src/*.c") + glob.glob("src/%s/*.[cS]" % arch)
libl4 = env.StaticLibrary('l4', src)

39
tasks/libmem/SConscript Normal file
View File

@@ -0,0 +1,39 @@
# -*- mode: python; coding: utf-8; -*-
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
# Author: Russel Winder
Import('environment')
e = environment.Clone()
e.Append(CPPPATH = ['#tasks/libl4/include' , '.' ])
mmObjects = e.StaticObject(Glob('mm/*.c'))
Depends(mmObjects, e['configFiles'])
mmLibrary = e.StaticLibrary('mm', mmObjects)
kmObjects = e.StaticObject(Glob('kmalloc/*.c'))
Depends(kmObjects, e['configFiles'])
kmLibrary = e.StaticLibrary('km', kmObjects)
mcObjects = e.StaticObject(Glob('memcache/*.c'))
Depends(mcObjects, e['configFiles'])
mcLibrary = e.StaticLibrary('mc', mcObjects)
libraries = (mmLibrary, kmLibrary, mcLibrary)
Return('libraries')

View File

@@ -1,67 +0,0 @@
#
# Copyright (C) 2007 Bahadir Balban
#
import os
import glob
import sys
from os.path import join
from string import split
project_root = "../.."
headers_root = join(project_root, "include/l4")
config_h = join(headers_root, "config.h")
#libl4 paths
libl4_headers = join(project_root, "tasks/libl4/include")
libl4_libpath = join(project_root, "tasks/libl4")
mm = "mm"
kmalloc = "kmalloc"
memcache = "memcache"
tests = "tests"
mm_dir = mm
kmalloc_dir = kmalloc
memcache_dir = memcache
tests_dir = tests
test_env = Environment(CC = 'gcc -m32',
CCFLAGS = ['-g', '-std=gnu99', '-Wall', '-Werror'],
ENV = {'PATH' : os.environ['PATH']},
LIBS = ['gcc', 'mm', 'km', 'mc'],
LIBPATH = ['#'],
CPPPATH = ['#include', join(project_root, "include"), "#", libl4_headers])
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
CCFLAGS = ['-g', '-nostdlib', '-Wall', '-Werror', '-ffreestanding', '-std=gnu99'],
LINKFLAGS = ['-nostdlib'],
ENV = {'PATH' : os.environ['PATH']},
LIBS = 'gcc',
CPPPATH = [join(project_root, "include"), "#", libl4_headers])
if os.path.exists(config_h) is False:
print "\nThis build requires a valid kernel configuration header."
print "Please run `scons configure' in the kernel root directory."
print "Choose the `tests' target to build memory allocator tests,"
print "or any other target for real use.\n"
sys.exit()
mm_src = glob.glob("%s/*.c" % mm_dir)
kmalloc_src = glob.glob("%s/*.c" % kmalloc_dir)
memcache_src = glob.glob("%s/*.c" % memcache_dir)
tests_src = glob.glob ("%s/*.c" % tests_dir)
if "tests" in COMMAND_LINE_TARGETS:
print "WARNING!!! Did you configure the kernel with test target first???"
libmm = test_env.StaticLibrary(mm, mm_src)
libkmalloc = test_env.StaticLibrary("km", kmalloc_src)
libmemcache = test_env.StaticLibrary("mc", memcache_src)
test_prog = test_env.Program("test", tests_src)
env.Alias("tests", test_prog)
else:
libmm = env.StaticLibrary(mm, mm_src)
libkmalloc = env.StaticLibrary("km", kmalloc_src)
libmemcache = env.StaticLibrary("mc", memcache_src)

View File

@@ -1,9 +0,0 @@
# Inherit global environment
Import('env')
# The set of source files associated with this SConscript file.
src_local = ['main.c', 'test_kmalloc.c', 'test_memcache.c', 'test_allocpage.c', 'test_alloc_generic.c', 'debug.c', 'memory.c', 'clz.c']
obj = env.Object(src_local)
Return('obj')

33
tasks/libposix/SConscript Normal file
View File

@@ -0,0 +1,33 @@
# -*- mode: python; coding: utf-8; -*-
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
# Author: Russel Winder
Import('environment')
e = environment.Clone()
e.Append(CPPPATH = ['include', 'include/posix', '#tasks/libl4/include'])
# TODO: There are errors in this code that -Werror gives problems with.
e['CCFLAGS'] = ['-g', '-nostdlib', '-Wall', '-ffreestanding', '-std=gnu99']
objects = e.StaticObject(Glob('*.c'))
Depends(objects, e['configFiles'])
library = e.StaticLibrary('posix', objects)
Return('library')

View File

@@ -1,74 +0,0 @@
#
# Copyright (C) 2007 Bahadir Balban
#
import os
import glob
import sys
from os.path import join
from string import split
project_root = "../.."
kernel_headers = join(project_root, "include")
l4lib_headers = join(project_root, "tasks/libl4/include")
config_h = join(project_root, "include/l4/config.h")
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
CCFLAGS = ['-g', '-std=gnu99', '-nostdlib', '-ffreestanding'],
LINKFLAGS = ['-nostdlib'],
CPPPATH = ['#include'],
ENV = {'PATH' : os.environ['PATH']},
LIBS = 'gcc')
def extract_arch_subarch_plat(config_header):
'''
From the autogenerated kernel config.h, extracts platform, archictecture,
subarchitecture information. This is used to include the relevant headers
from the kernel directories.
'''
arch = None
subarch = None
plat = None
if not os.path.exists(config_header):
print "\n\nconfig.h does not exist. "\
"Please run: `scons configure' first\n\n"
sys.exit()
f = open(config_h, "r")
while True:
line = f.readline()
if line == "":
break
parts = split(line)
if len(parts) > 0:
if parts[0] == "#define":
if parts[1] == "__ARCH__":
arch = parts[2]
elif parts[1] == "__PLATFORM__":
plat = parts[2]
elif parts[1] == "__SUBARCH__":
subarch = parts[2]
f.close()
if arch == None:
print "Error: No config symbol found for architecture"
sys.exit()
if subarch == None:
print "Error: No config symbol found for subarchitecture"
sys.exit()
if plat == None:
print "Error: No config symbol found for platform"
sys.exit()
return arch, subarch, plat
arch, subarch, plat = extract_arch_subarch_plat(config_h)
headers = ["#include/posix", l4lib_headers, kernel_headers]
env.Append(CPPPATH = headers)
src = glob.glob("src/*.c") + glob.glob("*.c")
libposix = env.StaticLibrary('posix', src)

24
tasks/mm0/SConscript Normal file
View File

@@ -0,0 +1,24 @@
# -*- mode: python; coding: utf-8; -*-
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
# Author: Russel Winder
Import('environment', 'previousImage')
program = environment['buildTask']('mm0', Glob('*.c') + [Glob(directory + '/*.c') for directory in [ 'src', 'src/lib', 'src/lib/elf', 'src/arch-' + environment['ARCH']]], environment, previousImage)
Return('program')

View File

@@ -1,136 +0,0 @@
#
# User space application build script
#
# Copyright (C) 2007 Bahadir Balban
#
import os
import sys
import shutil
from string import split
from os.path import join
from glob import glob
task_name = "mm0"
# The root directory of the repository where this file resides:
project_root = "../.."
tools_root = join(project_root, "tools")
prev_image = join(project_root, "build/start.axf")
libs_path = join(project_root, "libs")
ld_script = "include/linker.lds"
physical_base_ld_script = "include/physical_base.lds"
# libc paths:
libc_variant = "userspace"
libc_libpath = join(libs_path, "c/build/%s" % libc_variant)
libc_incpath = join(libc_libpath, "include")
libc_crt0 = join(libs_path, "c/build/crt/sys-userspace/arch-arm/crt0.o")
libc_name = "c-%s" % libc_variant
# libl4 paths:
libl4_path = "../libl4"
libl4_incpath = join(libl4_path, "include")
# libposix paths:
libposix_path = "../libposix"
libposix_incpath = join(libposix_path, "include")
#libmem paths:
libmem_path = "../libmem"
libmem_incpath = "../libmem"
# kernel paths:
kernel_incpath = join(project_root, "include")
# Kernel config header.
config_h = join(project_root, "include/l4/config.h")
# If crt0 is in its library path, it becomes hard to link with it.
# For instance the linker script must use an absolute path for it.
def copy_crt0(source, target, env):
os.system("cp " + str(source[0]) + " " + str(target[0]))
def get_physical_base(source, target, env):
os.system(join(tools_root, "pyelf/readelf.py --first-free-page " + \
prev_image +" >> " + physical_base_ld_script))
# The kernel build environment:
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
# We don't use -nostdinc because sometimes we need standard headers,
# such as stdarg.h e.g. for variable args, as in printk().
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror' ],
LINKFLAGS = ['-nostdlib', '-T' + ld_script, "-L" + libc_libpath, "-L" + libl4_path, \
"-L" + libposix_path, "-L" + libmem_path],
ASFLAGS = ['-D__ASSEMBLY__'],
PROGSUFFIX = '.axf', # The suffix to use for final executable
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
LIBS = [libc_name, 'libl4', 'libmm', 'libmc', 'libkm', 'libposix', \
'gcc', libc_name], # libgcc.a - This is required for division routines.
CPPFLAGS = "-D__USERSPACE__",
CPPPATH = ['#include', libl4_incpath, libc_incpath, kernel_incpath, \
libmem_incpath, libposix_incpath])
def extract_arch_subarch_plat(config_header):
'''
From the autogenerated kernel config.h, extracts platform, archictecture,
subarchitecture information. This is used to include the relevant headers
from the kernel directories.
'''
arch = None
subarch = None
plat = None
if not os.path.exists(config_header):
print "\n\nconfig.h does not exist. "\
"Please run: `scons configure' first\n\n"
sys.exit()
f = open(config_h, "r")
while True:
line = f.readline()
if line == "":
break
parts = split(line)
if len(parts) > 0:
if parts[0] == "#define":
if parts[1] == "__ARCH__":
arch = parts[2]
elif parts[1] == "__PLATFORM__":
plat = parts[2]
elif parts[1] == "__SUBARCH__":
subarch = parts[2]
f.close()
if arch == None:
print "Error: No config symbol found for architecture"
sys.exit()
if subarch == None:
print "Error: No config symbol found for subarchitecture"
sys.exit()
if plat == None:
print "Error: No config symbol found for platform"
sys.exit()
return arch, subarch, plat
def create_symlinks(arch):
arch_path = "include/arch"
arch_path2 ="src/arch"
if os.path.exists(arch_path):
os.system("rm %s" % (arch_path))
os.system("ln -s %s %s" % ("arch-" + arch, arch_path))
if os.path.exists(arch_path2):
os.system("rm %s" % (arch_path2))
os.system("ln -s %s %s" % ("arch-" + arch, arch_path2))
arch, subarch, plat = extract_arch_subarch_plat(config_h)
create_symlinks(arch) # Creates symlinks to architecture specific directories.
src = [glob("src/*.c"), glob("src/lib/*.c"), glob("src/lib/elf/*.c"), glob("*.c"), glob("src/arch/*.c")]
objs = env.Object(src)
physical_base = env.Command(physical_base_ld_script, prev_image, get_physical_base)
crt0_copied = env.Command("crt0.o", libc_crt0, copy_crt0)
task = env.Program(task_name, objs + [crt0_copied])
env.Alias(task_name, task)
env.Depends(task, physical_base)

22
tasks/taskOrder.py Normal file
View File

@@ -0,0 +1,22 @@
# -*- mode: python; coding: utf-8; -*-
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
# Author: Russel Winder
# A sequence determining the order of tasks in the packing.
taskOrder = ('mm0', 'fs0', 'test0')

24
tasks/test0/SConscript Normal file
View File

@@ -0,0 +1,24 @@
# -*- mode: python; coding: utf-8; -*-
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
# Author: Russel Winder
Import('environment', 'previousImage')
program = environment['buildTask']('test0', Glob('*.c') + Glob('src/*.c'), environment, previousImage, ['#tasks/libposix/include/posix'])
Return('program')

View File

@@ -1,109 +0,0 @@
#
# User space application build script
#
# Copyright (C) 2007 Bahadir Balban
#
import os
import sys
import shutil
from os.path import join
from glob import glob
task_name = "test0"
# The root directory of the repository where this file resides:
project_root = "../.."
tools_root = join(project_root, "tools")
prev_image = join(project_root, "tasks/fs0/fs0.axf")
libs_path = join(project_root, "libs")
ld_script = "include/linker.lds"
physical_base_ld_script = "include/physical_base.lds"
# Libc situation:
# Libposix has uClibc (and therefore posix) headers.
# NICTA libc implements printf for us for now.
# Libposix implements posix calls for us, e.g. mmap.
# In conclusion nicta libc and libposix complement each other
# they should not clash. In future libposix will be part of uclibc
# and uclibc will be used.
# libc paths:
libc_variant = "userspace"
libc_libpath = join(libs_path, "c/build/%s" % libc_variant)
libc_incpath = join(libc_libpath, "include")
libc_crt0 = join(libs_path, "c/build/crt/sys-userspace/arch-arm/crt0.o")
libc_name = "c-%s" % libc_variant
# libposix paths:
libposix_libpath = "../libposix"
libposix_incpath = "../libposix/include/posix"
# libl4 paths:
libl4_path = "../libl4"
libl4_incpath = join(libl4_path, "include")
# kernel paths:
kernel_incpath = join(project_root, "include")
# If crt0 is in its library path, it becomes hard to link with it.
# For instance the linker script must use an absolute path for it.
def copy_crt0(source, target, env):
os.system("cp " + str(source[0]) + " " + str(target[0]))
def get_physical_base(source, target, env):
os.system(join(tools_root, "pyelf/readelf.py --first-free-page " + \
prev_image + " >> " + physical_base_ld_script))
# The kernel build environment:
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
# We don't use -nostdinc because sometimes we need standard headers,
# such as stdarg.h e.g. for variable args, as in printk().
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror'],
LINKFLAGS = ['-nostdlib', '-T' + ld_script, "-L" + libc_libpath, "-L" + libl4_path, \
'-L' + libposix_libpath],
ASFLAGS = ['-D__ASSEMBLY__'],
PROGSUFFIX = '.axf', # The suffix to use for final executable
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
LIBS = [libc_name, 'gcc', libc_name, 'libl4', 'libposix', libc_name],
CPPFLAGS = "-D__USERSPACE__",
CPPPATH = ['#include', libl4_incpath, libposix_incpath, kernel_incpath])
test_exec_ld_script = "include/test_exec_linker.lds"
# The kernel build environment:
test_exec_env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
# We don't use -nostdinc because sometimes we need standard headers,
# such as stdarg.h e.g. for variable args, as in printk().
CCFLAGS = ['-O3', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror'],
LINKFLAGS = ['-nostdlib', '-T' + test_exec_ld_script, "-L" + libc_libpath, "-L" + libl4_path, \
'-L' + libposix_libpath],
ASFLAGS = ['-D__ASSEMBLY__'],
PROGSUFFIX = '.axf', # The suffix to use for final executable
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
LIBS = [libc_name, 'gcc', libc_name, 'libl4', 'libposix', libc_name],
CPPFLAGS = "-D__USERSPACE__",
CPPPATH = ['#include', libl4_incpath, libposix_incpath, kernel_incpath])
src = [glob("src/*.c"), glob("*.c"), glob("*.S"), glob("src/arch/arm/*.c"), glob("../libcont/*.c")]
objs = env.Object(src)
physical_base = env.Command(physical_base_ld_script, prev_image, get_physical_base)
crt0_copied = env.Command("crt0.o", libc_crt0, copy_crt0)
test_exec_src = [glob("src/test_exec/*.c")]
test_exec_objs = test_exec_env.Object(test_exec_src)
test_exec_name = "test_exec"
test_exec = test_exec_env.Program(test_exec_name, test_exec_objs + [crt0_copied])
test_exec_env.Alias(test_exec_name, test_exec)
env.Depends(objs, test_exec)
task = env.Program(task_name, objs + [crt0_copied])
env.Alias(task_name, task)
# I find this to be a BUG related to SCons. SCons is still good compared to
# notoriously horrible makefiles, but it could have been better.
# if test_exec doesn't depend on physical_base, test_exec is compiled but
# task complains that physical_base is not there. However we already declared
# its dependency below.
env.Depends(test_exec, physical_base)
env.Depends(task, physical_base)