Generate the final link linker scripts.

This commit is contained in:
Russel Winder
2009-08-10 11:30:53 +01:00
parent 52962b5b19
commit 9cb2b7470f
4 changed files with 45 additions and 21 deletions
+1 -1
View File
@@ -261,7 +261,7 @@ else :
loaderEnvironment = baseEnvironment.Clone( loaderEnvironment = baseEnvironment.Clone(
CC = 'arm-none-linux-gnueabi-gcc', CC = 'arm-none-linux-gnueabi-gcc',
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror'], CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror'],
LINKFLAGS = ['-nostdlib', '-Tloader/mylink.lds'], LINKFLAGS = ['-nostdlib', '-T' + buildDirectory + '/loader/linker.lds'],
PROGSUFFIX = '.axf', PROGSUFFIX = '.axf',
LIBS = [libelf, libs['baremetal'], 'gcc', libs['baremetal']], LIBS = [libelf, libs['baremetal'], 'gcc', libs['baremetal']],
CPPPATH = ['#libs/elf/include', '#' + buildDirectory + '/loader']) CPPPATH = ['#libs/elf/include', '#' + buildDirectory + '/loader'])
+25 -3
View File
@@ -74,22 +74,44 @@ def createMainC(target, source, env):
for item in source[1:]: for item in source[1:]:
name = os.path.splitext(item.name)[0] name = os.path.splitext(item.name)[0]
if name == 'start' : name = 'kernel' if name == 'start' : name = 'kernel'
externs += 'extern char _start_%s[];\nextern char _end_%s[];\n' % (name, name) externs += '''
declarations += 'void *%s_entry = NULL;\n' % (name,) extern char _start_%s[];
loads += 'printf("Loading the %s...\\n");\nload_image(&%s_entry, _start_%s, _end_%s);\n' %(name, name, name, name) 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 = inFile.read()
text = text.replace('__EXTERNAL_SYMBOLS_EDIT_MARKER__', externs) text = text.replace('__EXTERNAL_SYMBOLS_EDIT_MARKER__', externs)
text = text.replace('__DECLARATIONS_EDIT_MARKER__', declarations) text = text.replace('__DECLARATIONS_EDIT_MARKER__', declarations)
text = text.replace('__LOAD_STATEMENTS_EDIT_MARKER__', loads) text = text.replace('__LOAD_STATEMENTS_EDIT_MARKER__', loads)
outFile.write(text) outFile.write(text)
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))
startAxfS = Command('start.axf.S', images[0], ksymToLds) startAxfS = Command('start.axf.S', images[0], ksymToLds)
kernelS = Command('kernel.S', images + [startAxfS], createKernelSFile) kernelS = Command('kernel.S', images + [startAxfS], createKernelSFile)
mainC = Command('main.c', ['main.c.in'] + images, createMainC) mainC = Command('main.c', ['main.c.in'] + images, createMainC)
linkerScript = Command('linker.lds', ['linker.lds.in'] + images, createLinkerScript)
objects = environment.Object(['arch.c' , kernelS, startAxfS, mainC]) objects = environment.Object(['arch.c' , kernelS, startAxfS, mainC])
Depends(objects, environment['configFiles']) Depends(objects, environment['configFiles'])
Depends(objects, images) Depends(objects, images)
program = environment.Program('final', objects + [environment['baremetal_crt0']]) program = environment.Program('final', objects + [environment['baremetal_crt0']])
Depends(program, linkerScript)
Return('program') Return('program')
+9 -15
View File
@@ -1,3 +1,11 @@
/****
**** Template for generating a linker.lds. Edit markers have replaced some items in the original file
****
**** Copyright © 2009 B Labs Ltd
****
**** Author: Russel Winder.
****/
/* /*
* Simple linker script for userspace or svc tasks. * Simple linker script for userspace or svc tasks.
* *
@@ -13,21 +21,7 @@ SECTIONS
.rodata1 : { *(.rodata1) } .rodata1 : { *(.rodata1) }
.data : .data :
{ {
_start_kernel = .; __LINKER_ITEMS_EDIT_MARKER__
*(.kernel)
_end_kernel = .;
_start_bootdesc = .;
*(.bootdesc)
_end_bootdesc = .;
_start_mm0 = .;
*(.mm0)
_end_mm0 = .;
_start_fs0 = .;
*(.fs0)
_end_fs0 = .;
_start_test0 = .;
*(.test0)
_end_test0 = .;
*(.data) *(.data)
} }
.got : { *(.got) *(.got.plt) } .got : { *(.got) *(.got.plt) }
+10 -2
View File
@@ -1,3 +1,11 @@
/****
**** Template for generating a main.c. Edit markers have replaced some items in the original file
****
**** Copyright © 2009 B Labs Ltd
****
**** Author: Russel Winder.
****/
/******************************************************************************* /*******************************************************************************
* Filename: src/main.c * * Filename: src/main.c *
* Description: Elf-loader - ELF file kernel/application bootstraper, main * * Description: Elf-loader - ELF file kernel/application bootstraper, main *
@@ -113,7 +121,7 @@ main(void)
{ {
/* Declarations added here.*/ /* Declarations added here.*/
__DECLARATIONS_EDIT_MARKER__ __DECLARATIONS_EDIT_MARKER__
arch_init(); arch_init();
@@ -121,7 +129,7 @@ main(void)
/* Loader statements added here. */ /* Loader statements added here. */
__LOAD_STATEMENTS_EDIT_MARKER__ __LOAD_STATEMENTS_EDIT_MARKER__
printf("elf-loader:\tkernel entry point is %p\n", kernel_entry); printf("elf-loader:\tkernel entry point is %p\n", kernel_entry);
arch_start_kernel(kernel_entry); arch_start_kernel(kernel_entry);