1 |
2 |
drasko |
|
2 |
|
|
Import('config', 'environment', 'previmage', 'contid')
|
3 |
|
|
|
4 |
|
|
import os, sys
|
5 |
|
|
|
6 |
|
|
arch = config.arch
|
7 |
|
|
|
8 |
|
|
sys.path.append('../../../../')
|
9 |
|
|
from config.lib import *
|
10 |
|
|
from tools.pyelf.lmanext import *
|
11 |
|
|
|
12 |
|
|
src = [Glob('*.c') + Glob('test_exec.S') + Glob('src/*.[Sc]') + Glob('src/arch/arm/*.c')]
|
13 |
|
|
|
14 |
|
|
container = next((c for c in config.containers if int(c.id) == int(contid)), None)
|
15 |
|
|
|
16 |
|
|
asm_string = \
|
17 |
|
|
'''
|
18 |
|
|
.align 4
|
19 |
|
|
.section .testexec
|
20 |
|
|
.incbin "%s"
|
21 |
|
|
'''
|
22 |
|
|
|
23 |
|
|
test_exec_linker_lds_in = \
|
24 |
|
|
'''
|
25 |
|
|
/*
|
26 |
|
|
* Simple linker script for userspace or svc tasks.
|
27 |
|
|
*
|
28 |
|
|
* Copyright (C) 2007 Bahadir Balban
|
29 |
|
|
*/
|
30 |
|
|
|
31 |
|
|
virtual_base = %s;
|
32 |
|
|
|
33 |
|
|
/* First page before the env/args */
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
ENTRY(_start)
|
37 |
|
|
|
38 |
|
|
SECTIONS
|
39 |
|
|
{
|
40 |
|
|
. = virtual_base;
|
41 |
|
|
.text : { *(.text.head) *(.text) }
|
42 |
|
|
.rodata : { *(.rodata) }
|
43 |
|
|
.rodata1 : { *(.rodata1) }
|
44 |
|
|
. = ALIGN(4K);
|
45 |
|
|
.data : { *(.data) }
|
46 |
|
|
.bss : { *(.bss) }
|
47 |
|
|
}
|
48 |
|
|
'''
|
49 |
|
|
|
50 |
|
|
def generate_incbin_asm(target, source, env):
|
51 |
|
|
with open(target[0].path, 'w+') as asm_out:
|
52 |
|
|
asm_out.write(asm_string % source[0].path)
|
53 |
|
|
|
54 |
|
|
def generate_lma_lds(target, source, env):
|
55 |
|
|
with open(source[1].path, 'r') as lds_in:
|
56 |
|
|
with open(target[0].path, 'w+') as lds_out:
|
57 |
|
|
linker_script = lds_in.read()
|
58 |
|
|
lds_out.write(linker_script % (conv_hex(container.pager_task_region_start), next_available_lma(source[0].path)))
|
59 |
|
|
|
60 |
|
|
def generate_test_exec_lds(target, source, env):
|
61 |
|
|
with open(target[0].path, 'w+') as lds_out:
|
62 |
|
|
lds_out.write(test_exec_linker_lds_in % conv_hex(container.pager_task_region_start))
|
63 |
|
|
|
64 |
|
|
lma_lds = Command('include/linker.lds', [previmage, 'include/linker.lds.in'], generate_lma_lds)
|
65 |
|
|
test_exec_lds = Command('include/test_exec_linker.lds', [], generate_test_exec_lds)
|
66 |
|
|
|
67 |
|
|
env = environment.Clone()
|
68 |
|
|
test_exec_env = environment.Clone()
|
69 |
|
|
|
70 |
|
|
test_exec_env.Append(LIBS = ['posix', 'c-userspace'])
|
71 |
|
|
test_exec_env.Append(LINKFLAGS = '-T' + test_exec_lds[0].path)
|
72 |
|
|
test_exec_env.Append(CPPFLAGS = ' -D__USERSPACE__ -include l4lib/macros.h ')
|
73 |
|
|
test_exec_env.Replace(PROGSUFFIX = '')
|
74 |
|
|
test_exec_src = Glob('src/test_exec/*.[cS]')
|
75 |
|
|
test_exec_objs = test_exec_env.Object(test_exec_src)
|
76 |
|
|
test_exec = test_exec_env.Program('src/test_exec/test_exec', test_exec_objs)
|
77 |
|
|
test_exec_asm = Command('test_exec.S', test_exec, generate_incbin_asm)
|
78 |
|
|
Depends(test_exec, test_exec_objs)
|
79 |
|
|
Depends(test_exec, test_exec_lds)
|
80 |
|
|
AlwaysBuild(test_exec_lds)
|
81 |
|
|
|
82 |
|
|
env.Append(LIBS = ['posix', 'c-userspace'])
|
83 |
|
|
env.Append(LINKFLAGS = '-T' + lma_lds[0].path)
|
84 |
|
|
env.Append(CPPFLAGS = ' -D__USERSPACE__ -include l4lib/macros.h ')
|
85 |
|
|
env.Replace(PROGSUFFIX = '')
|
86 |
|
|
objs = env.Object(src + test_exec_asm)
|
87 |
|
|
test0 = env.Program('test0', objs)
|
88 |
|
|
|
89 |
|
|
elf_wrap_string = \
|
90 |
|
|
'''
|
91 |
|
|
.align 4
|
92 |
|
|
.section .data
|
93 |
|
|
.incbin "%s"
|
94 |
|
|
'''
|
95 |
|
|
|
96 |
|
|
def elf_wrap_asm(target, source, env):
|
97 |
|
|
with open(target[0].path, 'w+') as asm_out:
|
98 |
|
|
asm_out.write(elf_wrap_string % source[0].path)
|
99 |
|
|
|
100 |
|
|
def elf_wrap_lds(target, source, env):
|
101 |
|
|
with open(source[1].path, 'r') as lds_in:
|
102 |
|
|
with open(target[0].path, 'w+') as lds_out:
|
103 |
|
|
linker_script = lds_in.read()
|
104 |
|
|
lds_out.write(linker_script % next_available_lma(source[0].path))
|
105 |
|
|
|
106 |
|
|
# This further wraps the test0 elf image in another elf. Required.
|
107 |
|
|
elf_wrap_env = environment.Clone()
|
108 |
|
|
elf_wrapped_asm = Command('test0_elf_wrapped.S', test0, elf_wrap_asm)
|
109 |
|
|
elf_wrapped_lds = Command('include/elf_wrapper.lds', [previmage, 'include/elf_wrapper.lds.in'], elf_wrap_lds)
|
110 |
|
|
elf_wrap_env.Append(LINKFLAGS = '-T' + elf_wrapped_lds[0].path)
|
111 |
|
|
elf_wrap_objs = elf_wrap_env.Object(elf_wrapped_asm)
|
112 |
|
|
test0_elf_elf = elf_wrap_env.Program('test0_elf.elf', elf_wrap_objs)
|
113 |
|
|
|
114 |
|
|
# So that everytime test0 is built, elf_wrap_objs
|
115 |
|
|
# gets built (even though elf_wrapped_asm remains the same
|
116 |
|
|
Depends(elf_wrap_objs, test0)
|
117 |
|
|
Depends(test0, lma_lds)
|
118 |
|
|
Depends(test0, test_exec)
|
119 |
|
|
Depends(lma_lds, previmage)
|
120 |
|
|
AlwaysBuild(lma_lds)
|
121 |
|
|
Depends(test0_elf_elf, elf_wrapped_lds)
|
122 |
|
|
Return('test0_elf_elf')
|