mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
Generate the final link linker scripts.
This commit is contained in:
@@ -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'])
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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) }
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user