| 1 |
2 |
drasko |
# -*- mode: python; coding: utf-8; -*-
|
| 2 |
|
|
#
|
| 3 |
|
|
# Codezero -- a microkernel for embedded systems.
|
| 4 |
|
|
#
|
| 5 |
|
|
# Copyright © 2009 B Labs Ltd
|
| 6 |
|
|
|
| 7 |
|
|
import os, sys, shelve
|
| 8 |
|
|
from os.path import join
|
| 9 |
|
|
|
| 10 |
|
|
Import('env')
|
| 11 |
|
|
|
| 12 |
|
|
###
|
| 13 |
|
|
### FIXME: We are missing the dependency on containers.elf
|
| 14 |
|
|
###
|
| 15 |
|
|
PROJRELROOT = '../../'
|
| 16 |
|
|
|
| 17 |
|
|
from config.projpaths import *
|
| 18 |
|
|
from scripts.loader.generate_loader_asm import *
|
| 19 |
|
|
from config.lib import *
|
| 20 |
|
|
|
| 21 |
|
|
# Function to determine the LMA for 'final.elf'
|
| 22 |
|
|
def find_loader_load_address(target, source, env):
|
| 23 |
|
|
# Start/end addresses of various physical memory regions defined
|
| 24 |
|
|
array_start = []
|
| 25 |
|
|
array_end = []
|
| 26 |
|
|
|
| 27 |
|
|
with open(join(PROJROOT, CONFIG_H), 'r')as file:
|
| 28 |
|
|
for line in file:
|
| 29 |
|
|
begin = line.rfind(" ")
|
| 30 |
|
|
end = len(line)
|
| 31 |
|
|
if re.search("(PHYS)([0-9]){1,4}(_START)", line):
|
| 32 |
|
|
array_start.append(int(line[begin : end], 16))
|
| 33 |
|
|
elif re.search("(PHYS)([0-9]){1,4}(_END)", line):
|
| 34 |
|
|
array_end.append(int(line[begin : end], 16))
|
| 35 |
|
|
array_start.sort()
|
| 36 |
|
|
array_end.sort()
|
| 37 |
|
|
|
| 38 |
|
|
# Size of physical memory hole we need for 'final.elf' say 16MB
|
| 39 |
|
|
mem_needed = 0x1000000
|
| 40 |
|
|
# Default LMA = 32MB, if we have no container
|
| 41 |
|
|
loadaddr = 0x1000000
|
| 42 |
|
|
for index,end in enumerate(array_end):
|
| 43 |
|
|
loadaddr = end
|
| 44 |
|
|
if (index+1) >= len(array_start):
|
| 45 |
|
|
# Reached end of start_array
|
| 46 |
|
|
break
|
| 47 |
|
|
else:
|
| 48 |
|
|
start = array_start[index+1]
|
| 49 |
|
|
if start-end >= mem_needed:
|
| 50 |
|
|
break
|
| 51 |
|
|
|
| 52 |
|
|
# Create target file
|
| 53 |
|
|
with open(source[1].path, 'r') as input:
|
| 54 |
|
|
buffer = input.read()
|
| 55 |
|
|
#print 'Load address for final.elf: ' + str(conv_hex(loadaddr))
|
| 56 |
|
|
with open(target[0].path, 'w+') as output:
|
| 57 |
|
|
output.write(buffer % str(conv_hex(loadaddr)))
|
| 58 |
|
|
|
| 59 |
|
|
def ksym_to_loader(target, source, env):
|
| 60 |
|
|
generate_ksym_to_loader(target[0].path, source[0].path)
|
| 61 |
|
|
|
| 62 |
|
|
def gen_loader_images_S(target, source, env):
|
| 63 |
|
|
generate_image_S(target[0].path, source)
|
| 64 |
|
|
|
| 65 |
|
|
loader_ksyms = Command(join(PROJROOT, 'loader/ksyms.S'), join(BUILDDIR, 'kernel.elf'), ksym_to_loader)
|
| 66 |
|
|
loader_image_S = Command(join(PROJROOT, 'loader/images.S'), [join(BUILDDIR, 'kernel.elf'), join(BUILDDIR, 'conts/containers.elf')], \
|
| 67 |
|
|
gen_loader_images_S)
|
| 68 |
|
|
lma_lds = Command(join(BUILDDIR, 'loader/linker.lds'), \
|
| 69 |
|
|
[join(BUILDDIR, 'kernel.elf'), \
|
| 70 |
|
|
join(PROJROOT, 'loader/linker.lds.in')], find_loader_load_address)
|
| 71 |
|
|
src = Glob('*.[cS]')
|
| 72 |
|
|
objs = env.Object(src)
|
| 73 |
|
|
|
| 74 |
|
|
Depends(src, lma_lds)
|
| 75 |
|
|
Depends(src, loader_ksyms)
|
| 76 |
|
|
Depends(src, loader_image_S)
|
| 77 |
|
|
Depends(objs, join(BUILDDIR, 'conts/containers.elf'))
|
| 78 |
|
|
Depends(objs, join(BUILDDIR, 'kernel.elf'))
|
| 79 |
|
|
Return('objs', 'loader_image_S')
|