mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
Generating LMA for final.elf dynamically
This commit is contained in:
@@ -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'))
|
||||
|
||||
Reference in New Issue
Block a user