mirror of
https://github.com/drasko/codezero.git
synced 2026-04-23 04:09:04 +02:00
Generating LMA for final.elf dynamically
This commit is contained in:
@@ -29,7 +29,7 @@ env = Environment(CC = 'arm-none-eabi-gcc',
|
|||||||
# such as stdarg.h e.g. for variable args, as in printk().
|
# such as stdarg.h e.g. for variable args, as in printk().
|
||||||
CCFLAGS = ['-g', '-mcpu=arm926ej-s', '-nostdlib', '-ffreestanding', \
|
CCFLAGS = ['-g', '-mcpu=arm926ej-s', '-nostdlib', '-ffreestanding', \
|
||||||
'-std=gnu99', '-Wall', '-Werror'],
|
'-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__'],
|
ASFLAGS = ['-D__ASSEMBLY__'],
|
||||||
PROGSUFFIX = '.elf',
|
PROGSUFFIX = '.elf',
|
||||||
ENV = {'PATH' : os.environ['PATH']},
|
ENV = {'PATH' : os.environ['PATH']},
|
||||||
|
|||||||
@@ -16,6 +16,45 @@ PROJRELROOT = '../../'
|
|||||||
|
|
||||||
from config.projpaths import *
|
from config.projpaths import *
|
||||||
from scripts.loader.generate_loader_asm 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):
|
def ksym_to_loader(target, source, env):
|
||||||
generate_ksym_to_loader(target[0].path, source[0].path)
|
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_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')], \
|
loader_image_S = Command(join(PROJROOT, 'loader/images.S'), [join(BUILDDIR, 'kernel.elf'), join(BUILDDIR, 'conts/containers.elf')], \
|
||||||
gen_loader_images_S)
|
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]')
|
src = Glob('*.[cS]')
|
||||||
objs = env.Object(src)
|
objs = env.Object(src)
|
||||||
|
|
||||||
|
Depends(src, lma_lds)
|
||||||
Depends(src, loader_ksyms)
|
Depends(src, loader_ksyms)
|
||||||
Depends(src, loader_image_S)
|
Depends(src, loader_image_S)
|
||||||
Depends(objs, join(BUILDDIR, 'conts/containers.elf'))
|
Depends(objs, join(BUILDDIR, 'conts/containers.elf'))
|
||||||
|
|||||||
@@ -3,11 +3,13 @@
|
|||||||
*
|
*
|
||||||
* Copyright (C) 2008-2009 B Labs Ltd.
|
* Copyright (C) 2008-2009 B Labs Ltd.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
lma_codezero = %s;
|
||||||
ENTRY(_start)
|
ENTRY(_start)
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
. = 0x3000000;
|
. = lma_codezero;
|
||||||
.text : { *(.text.head) *(.text) }
|
.text : { *(.text.head) *(.text) }
|
||||||
.rodata : { *(.rodata) }
|
.rodata : { *(.rodata) }
|
||||||
.rodata1 : { *(.rodata1) }
|
.rodata1 : { *(.rodata1) }
|
||||||
Reference in New Issue
Block a user