Copying the way source, target files are referred, loader/SConscript now works with new setup.

modified:   loader/SConscript
	new file:   loader/main.c
	deleted:    loader/main.c.in
This commit is contained in:
Bahadir Balban
2009-09-08 22:18:04 +03:00
parent 8697a824be
commit 16f20a9d3a
3 changed files with 85 additions and 241 deletions

View File

@@ -61,80 +61,73 @@ def ksymToLds(target, source, env):
.equ %s, %s
''' % (symbol, symbol, symbol, convertAddress(address)))
def createKernelSFile(target, source, env):
with open(target[0].path, 'w') as asmFile:
asmFile.write('''
/*
* This file is autogenerated.
container_assembler_start = \
'''
.align 4
.section .kernel
.incbin "%s"
'''
container_assembler_body = \
'''
.align 4
.section .cont.%d
.incbin "%s"
'''
container_lds_start = \
'''/*
* Autogenerated linker script that embeds each container image.
*
* This file defines kernel symbols extracted from the
* kernel image in their physical address.
* Copyright (C) 2009 B Labs
*/
.include "%s"
SECTIONS
{'''
.section .kernel
container_lds_body = \
'''
.cont.%d : { *(.cont.%d) }'''
.incbin "%s"
container_lds_end = \
'''
}
'''
''' % (source[0].path , source[1].path))
for image in source[2:]:
asmFile.write('''
.align 4
.section .%s
.incbin "%s"
''' % (os.path.splitext(image.name)[0], image.path))
def generate_container_assembler(source, target, env):
with open(target[0].path, "w+") as f:
file_body = container_assembler_start % (str(source[0]))
img_i = 0
for img in source[1:]:
file_body += container_assembler_body % (img_i, img)
img_i += 1
def createMainC(target, source, env):
with open(source[0].path) as inFile:
with open(target[0].path, 'w') as outFile:
externs = ''
declarations = ''
loads = ''
for item in source[1:]:
name = os.path.splitext(item.name)[0]
if name == 'start' : name = 'kernel'
externs += '''
extern char _start_%s[];
extern char _end_%s[];
''' % (name, name)
declarations += ' void *%s_entry = NULL;\n' % (name,)
loads += '''
printf("Loading the %s...\\n");
load_image(&%s_entry, _start_%s, _end_%s);
''' %(name, name, name, name)
text = inFile.read()
text = text.replace('__EXTERNAL_SYMBOLS_EDIT_MARKER__', externs)
text = text.replace('__DECLARATIONS_EDIT_MARKER__', declarations)
text = text.replace('__LOAD_STATEMENTS_EDIT_MARKER__', loads)
outFile.write(text)
f.write(file_body)
f.close()
def createLinkerScript(target, source, env):
with open(source[0].path) as inFile:
with open(target[0].path, 'w') as outFile:
linkerItems = ''
for item in source[1:]:
name = os.path.splitext(item.name)[0]
if name == 'start' : name = 'kernel'
linkerItems += '''
_start_%s = .;
*(.%s)
_end_%s = .;
''' % (name, name, name)
outFile.write(inFile.read().replace('__LINKER_ITEMS_EDIT_MARKER__', linkerItems))
def generate_container_lds(source, target, env):
with open(target[0].path, "w+") as f:
img_i = 0
file_body = container_lds_start
for img in source[1:]:
file_body += container_lds_body % (img_i, img_i)
img_i += 1
file_body += container_lds_end
f.write(file_body)
f.close()
startAxfS = Command('start.axf.S', images[0], ksymToLds)
# In the following, it is crucially important that the order of the sources is as it is -- assumptions are
# made in the functions doing the processing.
kernelS = Command('kernel.S', [startAxfS] + images, createKernelSFile)
mainC = Command('main.c', ['main.c.in'] + images, createMainC)
linkerScript = Command('linker.lds', ['linker.lds.in'] + images, createLinkerScript)
kernelS = Command('containers.S', images, generate_container_assembler)
linkerScript = Command('linker.lds', images, generate_container_lds)
## TODO: deal with the situation where there are other .c and .S files in the directory.
objects = e.Object(['arch.c' , kernelS, startAxfS, mainC])
objects = e.Object(['arch.c' , 'main.c', kernelS, startAxfS])
Depends(objects, e['configFiles'])
Depends(objects, images)
program = e.Program('final', objects + [e['baremetal_crt0']])