Generating LMA for final.elf dynamically

This commit is contained in:
Amit Mahajan
2009-10-20 01:49:38 +05:30
parent 8bb1069553
commit 89a937fc9c
3 changed files with 47 additions and 3 deletions

View File

@@ -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']},

View File

@@ -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'))

View File

@@ -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) }