diff --git a/SConstruct b/SConstruct index 810891a..93bf3c6 100644 --- a/SConstruct +++ b/SConstruct @@ -261,7 +261,7 @@ else : loaderEnvironment = baseEnvironment.Clone( CC = 'arm-none-linux-gnueabi-gcc', CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror'], - LINKFLAGS = ['-nostdlib', '-Tloader/mylink.lds'], + LINKFLAGS = ['-nostdlib', '-T' + buildDirectory + '/loader/linker.lds'], PROGSUFFIX = '.axf', LIBS = [libelf, libs['baremetal'], 'gcc', libs['baremetal']], CPPPATH = ['#libs/elf/include', '#' + buildDirectory + '/loader']) diff --git a/loader/SConscript b/loader/SConscript index 814bdec..819b2f3 100644 --- a/loader/SConscript +++ b/loader/SConscript @@ -74,22 +74,44 @@ def createMainC(target, source, env): for item in source[1:]: name = os.path.splitext(item.name)[0] if name == 'start' : name = 'kernel' - externs += 'extern char _start_%s[];\nextern char _end_%s[];\n' % (name, name) - declarations += 'void *%s_entry = NULL;\n' % (name,) - loads += 'printf("Loading the %s...\\n");\nload_image(&%s_entry, _start_%s, _end_%s);\n' %(name, name, name, name) + 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) +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) kernelS = Command('kernel.S', images + [startAxfS], createKernelSFile) 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]) Depends(objects, environment['configFiles']) Depends(objects, images) program = environment.Program('final', objects + [environment['baremetal_crt0']]) +Depends(program, linkerScript) Return('program') diff --git a/loader/mylink.lds b/loader/linker.lds.in similarity index 54% rename from loader/mylink.lds rename to loader/linker.lds.in index c2b8a15..5e6da93 100644 --- a/loader/mylink.lds +++ b/loader/linker.lds.in @@ -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. * @@ -13,21 +21,7 @@ SECTIONS .rodata1 : { *(.rodata1) } .data : { - _start_kernel = .; - *(.kernel) - _end_kernel = .; - _start_bootdesc = .; - *(.bootdesc) - _end_bootdesc = .; - _start_mm0 = .; - *(.mm0) - _end_mm0 = .; - _start_fs0 = .; - *(.fs0) - _end_fs0 = .; - _start_test0 = .; - *(.test0) - _end_test0 = .; +__LINKER_ITEMS_EDIT_MARKER__ *(.data) } .got : { *(.got) *(.got.plt) } diff --git a/loader/main.c.in b/loader/main.c.in index 2c6ac01..6231d64 100644 --- a/loader/main.c.in +++ b/loader/main.c.in @@ -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 * * Description: Elf-loader - ELF file kernel/application bootstraper, main * @@ -113,7 +121,7 @@ main(void) { /* Declarations added here.*/ - __DECLARATIONS_EDIT_MARKER__ +__DECLARATIONS_EDIT_MARKER__ arch_init(); @@ -121,7 +129,7 @@ main(void) /* Loader statements added here. */ - __LOAD_STATEMENTS_EDIT_MARKER__ +__LOAD_STATEMENTS_EDIT_MARKER__ printf("elf-loader:\tkernel entry point is %p\n", kernel_entry); arch_start_kernel(kernel_entry);