From ce62459d13b5e473d2f6e0664abe6c37eefaa314 Mon Sep 17 00:00:00 2001 From: Russel Winder Date: Mon, 17 Aug 2009 19:24:18 +0100 Subject: [PATCH] Correct the problem of not loading test_exec. Remove the linker script and assembler load source in favour of generating the source so that the correct path is in the source. --- SConstruct | 6 +-- tasks/test0/SConscript | 65 +++++++++++++++++++++++- tasks/test0/include/test_exec_linker.lds | 37 -------------- tasks/test0/test_exec.S | 5 -- 4 files changed, 67 insertions(+), 46 deletions(-) delete mode 100644 tasks/test0/include/test_exec_linker.lds delete mode 100644 tasks/test0/test_exec.S diff --git a/SConstruct b/SConstruct index 0b8f106..406ff39 100644 --- a/SConstruct +++ b/SConstruct @@ -209,8 +209,8 @@ else : objects = e.StaticObject(sources) Depends(objects, e['configFiles']) program = e.Program(programName, objects + ['#' + e['userspace_crt0'][0].name]) - physicalBaseLinkerScript = Command('include/physical_base.lds', previousImage, 'tools/pyelf/readelf.py --first-free-page ' + previousImage[0].path + ' >> $TARGET') - Depends(program, [physicalBaseLinkerScript, e['userspace_crt0']]) + environment['physicalBaseLinkerScript'] = Command('include/physical_base.lds', previousImage, 'tools/pyelf/readelf.py --first-free-page ' + previousImage[0].path + ' >> $TARGET') + Depends(program, [environment['physicalBaseLinkerScript'], e['userspace_crt0']]) return program tasksEnvironment = baseEnvironment.Clone( @@ -225,7 +225,7 @@ else : buildTask = buildTask) #### -#### TODO: Why doe the linker require crt0.o to be in the current directory and named as such. Is it +#### TODO: Why does the linker require crt0.o to be in the current directory and named as such. Is it #### because of the text in the linker script? #### diff --git a/tasks/test0/SConscript b/tasks/test0/SConscript index 68267ef..08ca01c 100644 --- a/tasks/test0/SConscript +++ b/tasks/test0/SConscript @@ -19,6 +19,69 @@ Import('environment', 'previousImage') -program = environment['buildTask']('test0', Glob('*.c') + Glob('src/*.c'), environment, previousImage, ['#tasks/libposix/include/posix']) +taskName = 'test0' + +def createTestExecLinkerScript(target, source, env): + with open(target[0].path, 'w') as outFile: + outFile.write(''' +/* + * Simple linker script for userspace or svc tasks. + * + * Copyright (C) 2007 Bahadir Balban + */ + +/* + * The only catch with this linker script is that everything + * is linked starting at virtual_base, and loaded starting + * at physical_base. virtual_base is the predefined region + * of virtual memory for userland applications. physical_base + * is determined at build-time, it is one of the subsequent pages + * that come after the kernel image's load area. + */ +/* USER_AREA_START, see memlayout.h */ +virtual_base = 0x10000000; +__stack = (0x20000000 - 0x1000 - 8); /* First page before the env/args */ +INCLUDE "%s" + +/* physical_base = 0x228000; */ +offset = virtual_base - physical_base; + +ENTRY(_start) + +SECTIONS +{ + . = virtual_base; + _start_text = .; + .text : AT (ADDR(.text) - offset) { crt0.o(.text) *(.text) } + /* rodata is needed else your strings will link at physical! */ + .rodata : AT (ADDR(.rodata) - offset) { *(.rodata) } + .rodata1 : AT (ADDR(.rodata1) - offset) { *(.rodata1) } + . = ALIGN(4K); + .data : AT (ADDR(.data) - offset) { *(.data) } + .bss : AT (ADDR(.bss) - offset) { *(.bss) } + _end = .; +} +''' % ( source[0].path )) + +def createTestExecS(target, source, env): + with open(target[0].path, 'w') as outFile: + outFile.write(''' +.section .testexec + +.align 4 +.incbin "%s" +.align 4 +''' % ( source[0].path )) + +testTaskEnvironment = environment.Clone() +testTaskEnvironment.Append(CPPPATH=['#tasks/libposix/include/posix']) +testExecLinkerScript = Command('#build/tasks/' + taskName + '/include/test_exec_linker.lds', testTaskEnvironment['physicalBaseLinkerScript'], createTestExecLinkerScript) +testExecEnvironment = testTaskEnvironment.Clone() +testExecEnvironment.Append(LINKFLAGS=['-T' + testExecLinkerScript[0].path]) +testExec = testExecEnvironment.Program('test_exec', Glob('src/test_exec/*.c') + ['#' + environment['userspace_crt0'][0].name]) +Depends(testExec, testExecLinkerScript) +testExecS = Command('#build/tasks/' + taskName + '/test_exec.S', testExec, createTestExecS) +program = testTaskEnvironment['buildTask'](taskName, Glob('*.c') + Glob('src/*.c') + testExecS, testTaskEnvironment, previousImage) +Depends(program, testExec) Return('program') diff --git a/tasks/test0/include/test_exec_linker.lds b/tasks/test0/include/test_exec_linker.lds deleted file mode 100644 index 9ac1736..0000000 --- a/tasks/test0/include/test_exec_linker.lds +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Simple linker script for userspace or svc tasks. - * - * Copyright (C) 2007 Bahadir Balban - */ - -/* - * The only catch with this linker script is that everything - * is linked starting at virtual_base, and loaded starting - * at physical_base. virtual_base is the predefined region - * of virtual memory for userland applications. physical_base - * is determined at build-time, it is one of the subsequent pages - * that come after the kernel image's load area. - */ -/* USER_AREA_START, see memlayout.h */ -virtual_base = 0x10000000; -__stack = (0x20000000 - 0x1000 - 8); /* First page before the env/args */ -INCLUDE "include/physical_base.lds" - -/* physical_base = 0x228000; */ -offset = virtual_base - physical_base; - -ENTRY(_start) - -SECTIONS -{ - . = virtual_base; - _start_text = .; - .text : AT (ADDR(.text) - offset) { crt0.o(.text) *(.text) } - /* rodata is needed else your strings will link at physical! */ - .rodata : AT (ADDR(.rodata) - offset) { *(.rodata) } - .rodata1 : AT (ADDR(.rodata1) - offset) { *(.rodata1) } - . = ALIGN(4K); - .data : AT (ADDR(.data) - offset) { *(.data) } - .bss : AT (ADDR(.bss) - offset) { *(.bss) } - _end = .; -} diff --git a/tasks/test0/test_exec.S b/tasks/test0/test_exec.S deleted file mode 100644 index d78833d..0000000 --- a/tasks/test0/test_exec.S +++ /dev/null @@ -1,5 +0,0 @@ -.section .testexec - -.align 4 -.incbin "test_exec.axf" -.align 4