mirror of
https://github.com/drasko/codezero.git
synced 2026-01-14 20:03:16 +01:00
Changes since April
Clean up of build directories. Simplifications to capability model.
This commit is contained in:
@@ -1,79 +1,7 @@
|
||||
# -*- mode: python; coding: utf-8; -*-
|
||||
#
|
||||
# Codezero -- a microkernel for embedded systems.
|
||||
#
|
||||
# Copyright © 2009 B Labs Ltd
|
||||
|
||||
import os, sys, shelve
|
||||
from os.path import join
|
||||
|
||||
Import('env')
|
||||
|
||||
###
|
||||
### FIXME: We are missing the dependency on containers.elf
|
||||
###
|
||||
PROJRELROOT = '../../'
|
||||
|
||||
from config.projpaths import *
|
||||
from scripts.loader.generate_loader_asm import *
|
||||
from config.lib import *
|
||||
|
||||
# Function to determine the LMA for 'final.elf'
|
||||
def find_loader_load_address(target, source, env):
|
||||
# Start/end addresses of various physical memory regions defined
|
||||
array_start = []
|
||||
array_end = []
|
||||
|
||||
with open(join(PROJROOT, CONFIG_H), 'r')as file:
|
||||
for line in file:
|
||||
begin = line.rfind(" ")
|
||||
end = len(line)
|
||||
if re.search("(PHYS)([0-9]){1,4}(_START)", line):
|
||||
array_start.append(int(line[begin : end], 16))
|
||||
elif re.search("(PHYS)([0-9]){1,4}(_END)", line):
|
||||
array_end.append(int(line[begin : end], 16))
|
||||
array_start.sort()
|
||||
array_end.sort()
|
||||
|
||||
# Size of physical memory hole we need for 'final.elf' say 16MB
|
||||
mem_needed = 0x1000000
|
||||
# Default LMA = 32MB, if we have no container
|
||||
loadaddr = 0x1000000
|
||||
for index,end in enumerate(array_end):
|
||||
loadaddr = end
|
||||
if (index+1) >= len(array_start):
|
||||
# Reached end of start_array
|
||||
break
|
||||
else:
|
||||
start = array_start[index+1]
|
||||
if start-end >= mem_needed:
|
||||
break
|
||||
|
||||
# Create target file
|
||||
with open(source[1].path, 'r') as input:
|
||||
buffer = input.read()
|
||||
#print 'Load address for final.elf: ' + str(conv_hex(loadaddr))
|
||||
with open(target[0].path, 'w+') as output:
|
||||
output.write(buffer % str(conv_hex(loadaddr)))
|
||||
|
||||
def ksym_to_loader(target, source, env):
|
||||
generate_ksym_to_loader(target[0].path, source[0].path)
|
||||
|
||||
def gen_loader_images_S(target, source, env):
|
||||
generate_image_S(target[0].path, source)
|
||||
|
||||
loader_ksyms = Command(join(PROJROOT, 'loader/ksyms.S'), join(BUILDDIR, 'kernel.elf'), ksym_to_loader)
|
||||
loader_image_S = Command(join(PROJROOT, 'loader/images.S'), [join(BUILDDIR, 'kernel.elf'), join(BUILDDIR, 'conts/containers.elf')], \
|
||||
gen_loader_images_S)
|
||||
lma_lds = Command(join(BUILDDIR, 'loader/linker.lds'), \
|
||||
[join(BUILDDIR, 'kernel.elf'), \
|
||||
join(PROJROOT, 'loader/linker.lds.in')], find_loader_load_address)
|
||||
src = Glob('*.[cS]')
|
||||
objs = env.Object(src)
|
||||
|
||||
Depends(src, lma_lds)
|
||||
Depends(src, loader_ksyms)
|
||||
Depends(src, loader_image_S)
|
||||
Depends(objs, join(BUILDDIR, 'conts/containers.elf'))
|
||||
Depends(objs, join(BUILDDIR, 'kernel.elf'))
|
||||
Return('objs', 'loader_image_S')
|
||||
Return('objs')
|
||||
|
||||
135
loader/SConstruct
Normal file
135
loader/SConstruct
Normal file
@@ -0,0 +1,135 @@
|
||||
# -*- mode: python; coding: utf-8; -*-
|
||||
#
|
||||
# Codezero -- a microkernel for embedded systems.
|
||||
#
|
||||
# P.S : This file is called from PROJROOT directory,
|
||||
# so all paths are given relative to PROJROOT.
|
||||
#
|
||||
# Copyright © 2009 B Labs Ltd
|
||||
|
||||
import os, sys
|
||||
from os.path import join
|
||||
|
||||
sys.path.append(os.getcwd())
|
||||
|
||||
from scripts.config.configuration import *
|
||||
from scripts.config.projpaths import *
|
||||
from scripts.loader.generate_loader_asm import *
|
||||
|
||||
config = configuration_retrieve()
|
||||
arch = config.arch
|
||||
gcc_arch_flag = config.gcc_arch_flag
|
||||
symbols = config.all
|
||||
|
||||
variant = 'baremetal'
|
||||
|
||||
# Locally important paths are here
|
||||
LIBC_PATH = 'loader/libs/c'
|
||||
LIBC_LIBPATH = join(BUILDDIR, LIBC_PATH)
|
||||
LIBC_INCPATH = ['#' + join(LIBC_PATH, 'include'),
|
||||
'#' + join(LIBC_PATH, 'include/arch/' + arch)]
|
||||
|
||||
LIBELF_PATH = 'loader/libs/elf'
|
||||
LIBELF_LIBPATH = join(BUILDDIR, LIBELF_PATH)
|
||||
LIBELF_INCPATH = '#' + join(LIBELF_PATH, 'include')
|
||||
|
||||
env = Environment(CC = config.toolchain_kernel + 'gcc',
|
||||
AR = config.toolchain_kernel + 'ar',
|
||||
RANLIB = config.toolchain_kernel + 'ranlib',
|
||||
# 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', '-march=' + gcc_arch_flag],
|
||||
LINKFLAGS = ['-nostdlib', '-T' + join(BUILDDIR, 'loader/linker.lds'),
|
||||
'-u_start'],
|
||||
ASFLAGS = ['-D__ASSEMBLY__'],
|
||||
PROGSUFFIX = '.elf',
|
||||
ENV = {'PATH' : os.environ['PATH']},
|
||||
LIBS = ['gcc', 'elf', 'libdev-baremetal', 'c-baremetal', 'gcc'],
|
||||
LIBPATH = [LIBDEV_BAREMETAL_LIBPATH, LIBELF_LIBPATH, LIBC_LIBPATH],
|
||||
CPPPATH = [KERNEL_HEADERS, LIBDEV_INCLUDE, LIBC_INCPATH, LIBELF_INCPATH],
|
||||
CPPFLAGS = '-include l4/config.h -include l4/macros.h \
|
||||
-include l4/types.h -D__KERNEL__')
|
||||
|
||||
libdev_builddir = join(join(BUILDDIR, LIBDEV_RELDIR), 'sys-' + variant)
|
||||
objs = SConscript(join(LIBDEV_RELDIR, 'SConscript'), duplicate = 0,
|
||||
exports = { 'env' : env, 'type' : variant, 'build_dir' : libdev_builddir},
|
||||
variant_dir = join(BUILDDIR, LIBDEV_RELDIR))
|
||||
|
||||
objs += SConscript('loader/libs/c/SConscript', duplicate = 0,
|
||||
exports = { 'env' : env, 'type' : variant},
|
||||
variant_dir = join(BUILDDIR, 'loader/libs/c'))
|
||||
|
||||
objs += SConscript('loader/libs/elf/SConscript', duplicate = 0,
|
||||
exports = { 'env' : env },
|
||||
variant_dir = join(BUILDDIR, 'loader/libs/elf'))
|
||||
|
||||
objs += SConscript('loader/SConscript', duplicate = 0,
|
||||
exports = { 'env' : env },
|
||||
variant_dir = join(BUILDDIR, 'loader'))
|
||||
|
||||
#
|
||||
# Find the LMA for FINAL_ELF
|
||||
# Let size of physical memory hole needed for FINAL_ELF be 16MB
|
||||
# and default LMA = 32MB,
|
||||
# FIXME: default LMA = get_kernel_end_address()
|
||||
#
|
||||
def find_loader_load_address(target, source, env):
|
||||
# Start/end addresses of various physical memory regions defined
|
||||
array_start = []
|
||||
array_end = []
|
||||
|
||||
for sym, val in symbols:
|
||||
if re.search("(PHYS)([0-9]){1,4}(_START)", sym):
|
||||
array_start.append(int(val, 0))
|
||||
elif re.search("(PHYS)([0-9]){1,4}(_END)", sym):
|
||||
array_end.append(int(val, 0))
|
||||
array_start.sort()
|
||||
array_end.sort()
|
||||
|
||||
mem_needed = 0x1000000
|
||||
loadaddr = 0x1000000
|
||||
for index, end in enumerate(array_end):
|
||||
loadaddr = end
|
||||
if (index+1) >= len(array_start):
|
||||
# Reached end of start_array
|
||||
break
|
||||
else:
|
||||
start = array_start[index+1]
|
||||
if start - end >= mem_needed:
|
||||
break
|
||||
|
||||
# Create target file
|
||||
with open(source[1].path, 'r') as input:
|
||||
buffer = input.read()
|
||||
#print '\nLoad address for FINAL_ELF: ' + str(conv_hex(loadaddr))
|
||||
with open(target[0].path, 'w+') as output:
|
||||
output.write(buffer % str(loadaddr))
|
||||
return None
|
||||
|
||||
def ksym_to_loader(target, source, env):
|
||||
generate_ksym_to_loader(target[0].path, source[0].path)
|
||||
|
||||
def gen_loader_images_S(target, source, env):
|
||||
generate_image_S(target[0].path, source)
|
||||
|
||||
# Builders
|
||||
loader_image_S = Builder(action = gen_loader_images_S)
|
||||
env.Append(BUILDERS = {'IMAGE_S' : loader_image_S})
|
||||
env.IMAGE_S(join(BUILDDIR, 'loader/images.S'), [KERNEL_ELF, join(BUILDDIR, 'conts/containers.elf')])
|
||||
objs += env.Object(join(BUILDDIR, 'loader/images.S'))
|
||||
|
||||
loader_ksyms = Builder(action = ksym_to_loader)
|
||||
env.Append(BUILDERS = {'LOADER_KSYSM' : loader_ksyms})
|
||||
env.LOADER_KSYSM(join(BUILDDIR, 'loader/ksyms.S'), [KERNEL_ELF])
|
||||
objs += env.Object(join(BUILDDIR, 'loader/ksyms.S'))
|
||||
|
||||
lma_lds = Builder(action = find_loader_load_address)
|
||||
env.Append(BUILDERS = {'LMA_LDS' : lma_lds})
|
||||
env.LMA_LDS(join(BUILDDIR, 'loader/linker.lds'), [KERNEL_ELF, 'loader/linker.lds.in'])
|
||||
|
||||
final_elf = env.Program(FINAL_ELF, objs)
|
||||
|
||||
Depends(objs,join(BUILDDIR, 'conts/containers.elf'))
|
||||
Depends(objs,join(BUILDDIR, 'kernel.elf'))
|
||||
Depends(final_elf, join(BUILDDIR, 'loader/linker.lds'))
|
||||
@@ -9,13 +9,16 @@ from os.path import join
|
||||
|
||||
# Get global paths
|
||||
PROJRELROOT = '../../../'
|
||||
|
||||
sys.path.append(PROJRELROOT)
|
||||
|
||||
from config.configuration import *
|
||||
from config.projpaths import *
|
||||
from scripts.config.configuration import *
|
||||
from scripts.config.projpaths import *
|
||||
|
||||
Import('env', 'arch', 'platform', 'type')
|
||||
config = configuration_retrieve()
|
||||
arch = config.arch
|
||||
platform = config.platform
|
||||
|
||||
Import('env', 'type')
|
||||
variant = type
|
||||
|
||||
e = env.Clone()
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# Copyright © 2009 B Labs Ltd
|
||||
|
||||
import os, sys, shelve
|
||||
from configure import *
|
||||
from scripts.config.config_invoke import *
|
||||
|
||||
variant = "baremetal"
|
||||
config = configuration_retrieve()
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <l4/config.h>
|
||||
#include <libdev/uart.h>
|
||||
#include <dev/uart.h>
|
||||
|
||||
int __fputc(int c, FILE *stream)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import os, sys, shelve
|
||||
from os.path import join
|
||||
from configure import *
|
||||
from scripts.config.config_invoke import *
|
||||
|
||||
config = configuration_retrieve()
|
||||
arch = config.arch
|
||||
|
||||
@@ -376,16 +376,16 @@ elf_loadFile(void *elfFile, bool phys)
|
||||
pheader_type = elf_getProgramHeaderType(elfFile, i);
|
||||
// printf("Elf program header type: %p\n", pheader_type);
|
||||
// Comment
|
||||
//printf("Copying to range from 0x%x to 0x%x of size: 0x%x\n", (unsigned int)dest, (unsigned int)dest + (unsigned int)len, (unsigned int)len);
|
||||
printf("Copying to range from 0x%x to 0x%x of size: 0x%x\n", (unsigned int)dest, (unsigned int)dest + (unsigned int)len, (unsigned int)len);
|
||||
memcpy((void*) (uintptr_t) dest, (void*) (uintptr_t) src, len);
|
||||
dest += len;
|
||||
clrsize = elf_getProgramHeaderMemorySize(elfFile, i) - len;
|
||||
// printf("Clearing memory... starting from %x, size: %x\n", (unsigned int)dest, (unsigned int)clrsize);
|
||||
printf("Clearing memory... starting from %x, size: %x\n", (unsigned int)dest, (unsigned int)clrsize);
|
||||
memset((void*) (uintptr_t) dest, 0, clrsize);
|
||||
// printf("Memory cleared.\n");
|
||||
}
|
||||
// And this one
|
||||
// printf("\n");
|
||||
printf("\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ ENTRY(_start)
|
||||
SECTIONS
|
||||
{
|
||||
. = load_address;
|
||||
_start_loader = .;
|
||||
.text : { *(.text.head) *(.text) }
|
||||
.rodata : { *(.rodata) }
|
||||
.rodata1 : { *(.rodata1) }
|
||||
@@ -26,4 +27,5 @@ SECTIONS
|
||||
}
|
||||
.got : { *(.got) *(.got.plt) }
|
||||
.bss : { *(.bss) }
|
||||
_end_loader = .;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ extern char _start_kernel[];
|
||||
extern char _end_kernel[];
|
||||
extern char _start_containers[];
|
||||
extern char _end_containers[];
|
||||
extern char _start_loader[];
|
||||
extern char _end_loader[];
|
||||
|
||||
/* This is a kernel symbol exported to loader's linker script from kernel build */
|
||||
extern char bkpt_phys_to_virt[];
|
||||
@@ -105,11 +107,16 @@ void arch_start_kernel(void *entry)
|
||||
func(0);
|
||||
}
|
||||
|
||||
#define __NAME__ "ELF Loader"
|
||||
int main(void)
|
||||
{
|
||||
unsigned long *kernel_entry;
|
||||
|
||||
printf("ELF Loader: Started.\n");
|
||||
printf("%s: Loader image size: %luKB, placed "
|
||||
"at physical 0x%lx - 0x%lx\n",
|
||||
__NAME__, (unsigned long)(_end_loader - _start_loader) / 1024,
|
||||
(unsigned long)_start_loader,
|
||||
(unsigned long)_end_loader);
|
||||
|
||||
printf("Loading the kernel...\n");
|
||||
load_elf_image(&kernel_entry, (void *)_start_kernel);
|
||||
|
||||
Reference in New Issue
Block a user