diff --git a/SConstruct.loader b/SConstruct.loader index c427c9c..83e7e9b 100644 --- a/SConstruct.loader +++ b/SConstruct.loader @@ -29,7 +29,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' + "loader/linker.lds", "-u_start"], + LINKFLAGS = ['-nostdlib', '-T' + join(BUILDDIR, 'loader/linker.lds'), "-u_start"], ASFLAGS = ['-D__ASSEMBLY__'], PROGSUFFIX = '.elf', ENV = {'PATH' : os.environ['PATH']}, diff --git a/loader/SConscript b/loader/SConscript index 57f7d9d..1ad6ec5 100644 --- a/loader/SConscript +++ b/loader/SConscript @@ -16,6 +16,45 @@ 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_lma_codezero(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)(.)(_START)", line): + array_start.append(int(line[begin : end], 16)) + elif re.search("(PHYS)(.)(_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 'LMA FOR FINAL.ELF IS : ' + 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) @@ -26,10 +65,13 @@ def gen_loader_images_S(target, source, env): 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_lma_codezero) 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')) diff --git a/loader/linker.lds b/loader/linker.lds.in similarity index 91% rename from loader/linker.lds rename to loader/linker.lds.in index d356d27..a07e50e 100644 --- a/loader/linker.lds +++ b/loader/linker.lds.in @@ -3,11 +3,13 @@ * * Copyright (C) 2008-2009 B Labs Ltd. */ + +lma_codezero = %s; ENTRY(_start) SECTIONS { - . = 0x3000000; + . = lma_codezero; .text : { *(.text.head) *(.text) } .rodata : { *(.rodata) } .rodata1 : { *(.rodata1) }