-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwscript
346 lines (278 loc) · 10.5 KB
/
wscript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# vim: set syntax=python:
from waflib import Configure
from waflib import Task
from waflib.Build import BuildContext
from waflib.TaskGen import after_method, before_method, feature
top = '.'
out = 'build'
Configure.autoconfig = True
CROSS = 'cross'
NATIVE = 'native'
kernel_sources = [
'kernel/address-space.cpp',
'kernel/assert.cpp',
'kernel/early-mmu.c',
'kernel/debug.cpp',
'kernel/debug-pl011.cpp',
'kernel/exception.cpp',
'kernel/init.cpp',
'kernel/interrupts.cpp',
'kernel/interrupts-pl190.cpp',
'kernel/kmalloc.cpp',
'kernel/large-object-cache.cpp',
'kernel/message.cpp',
'kernel/mmu.cpp',
'kernel/nameserver.cpp',
'kernel/object-cache.cpp',
'kernel/once.cpp',
'kernel/process.cpp',
'kernel/procmgr.cpp',
'kernel/procmgr_childwait.cpp',
'kernel/procmgr_getpid.cpp',
'kernel/procmgr_interrupts.cpp',
'kernel/procmgr_map.cpp',
'kernel/procmgr_naming.cpp',
'kernel/procmgr_sbrk.cpp',
'kernel/procmgr_spawn.cpp',
'kernel/ramfs.cpp',
'kernel/reaper.cpp',
'kernel/semaphore.cpp',
'kernel/small-object-cache.cpp',
'kernel/stdlib.c',
'kernel/string.cpp',
'kernel/syscall.cpp',
'kernel/thread.cpp',
'kernel/timer.cpp',
'kernel/timer-sp804.cpp',
'kernel/tree-map.cpp',
'kernel/vm.cpp',
'kernel/atomic.S',
'kernel/early-entry.S',
'kernel/exception-entry.S',
'kernel/high-entry.S',
'kernel/vector.S',
'newlib/stubs.c',
'newlib/sbrk-kernel.c',
]
libc_sources = [
'libc/crt.c',
'libc/syscall.c',
'libc/user_io.c',
'libc/user_message.c',
'libc/user_naming.c',
'libc/user_process.c',
'newlib/stubs.c',
'newlib/sbrk-user.c',
]
user_progs = [
('echo', ['echo.c'], 0x10000),
('echo-client', ['echo-client.c'], 0x20000),
('uio', ['uio.c'], 0x30000),
('pl011', ['pl011.cpp'], 0x40000),
('crasher', ['crasher.c'], 0x50000),
('init', ['init.c'], 0x60000),
('terminal', ['terminal.c'], 0x70000),
]
def options(opt):
opt.load('compiler_c')
opt.load('compiler_cxx')
opt.load('asm')
def configure(conf):
conf.load('doxygen')
#
# Make environment suitable for compiling custom programs that are
# used to preprocess artifacts for inclusion into the target system.
#
conf.setenv(NATIVE)
conf.load('compiler_c')
conf.load('compiler_cxx')
#
# Make enviornment to do all of the cross compiling for target system's
# user programs and kernel.
#
conf.setenv(CROSS)
conf.find_program('arm-none-eabi-as', var='AS')
conf.find_program('arm-none-eabi-ar', var='AR')
conf.find_program('arm-none-eabi-gcc', var='CC')
conf.find_program('arm-none-eabi-g++', var='CXX')
conf.find_program('arm-none-eabi-ld', var='LD')
conf.find_program('arm-none-eabi-objcopy', var='OBJCOPY')
cflags = ['-march=armv6', '-g', '-Wall', '-Werror']
asflags = ['-march=armv6', '-g']
conf.env.append_unique('CFLAGS', cflags)
conf.env.append_unique('CXXFLAGS', cflags)
conf.env.append_unique('ASFLAGS', asflags)
conf.load('gcc')
conf.load('gxx')
conf.load('gas')
# Use normal Unix suffixes on MuOS
conf.env['cprogram_PATTERN'] = '%s'
conf.env['cxxprogram_PATTERN'] = '%s'
conf.env['cstlib_PATTERN'] = 'lib%s.a'
conf.env['cxxstlib_PATTERN'] = 'lib%s.a'
conf.env['cshlib_PATTERN'] = 'lib%s.so'
conf.env['cxxshlib_PATTERN'] = 'lib%s.so'
conf.load('compiler_c')
conf.load('compiler_cxx')
conf.load('asm')
def build(bld):
#
# Unprivileged user programs
#
bld.add_group()
bld(source = libc_sources,
target = 'my_c',
includes = ['include'],
features = ['c'],
env = bld.all_envs[CROSS].derive())
for (p, src_list, link_base_addr) in user_progs:
bld.program(source = src_list,
target = p,
includes = ['include'],
linkflags = ['-nostartfiles', '-Wl,-Ttext-segment,0x%x' % link_base_addr],
use = 'my_c',
env = bld.all_envs[CROSS].derive())
#
# Tool to compile IFS
#
bld.program(source = 'fs-builder.cc',
target = 'fs-builder',
env = bld.all_envs[NATIVE].derive())
#
# Generate source code of IFS
#
bld.add_group()
bld(target = 'ramfs-image',
features = ['fs-builder'],
progs = [up[0] for up in user_progs])
#
# Main kernel image
#
bld.add_group()
image = bld.program(source = kernel_sources,
target = 'image',
includes = ['include'],
defines = ['__KERNEL__'],
linkflags = ['-nostartfiles'],
env = bld.all_envs[CROSS].derive(),
features = ['asmoffsets', 'ramfs_image', 'ldscript', 'linkermap'],
asmoffsets = 'asm-offsets.c',
ramfs_image = 'ramfs-image',
ldscript = 'kernel/kernel.ldscript')
"""
Look up the linked executable for each of the taskgens
named in taskgen.progs, and generate a RAM filesystem
containing all of them.
"""
@feature('fs-builder')
def discover_fs_builder_inputs(taskgen):
fsbuilder_link_task = taskgen.bld.get_tgen_by_name('fs-builder').link_task
prognodes = [taskgen.bld.get_tgen_by_name(p).link_task.outputs[0] for p in taskgen.progs]
target = taskgen.path.find_or_declare(taskgen.target)
# Create task, set up its environment
ramfs_task = taskgen.create_task('fs_builder', prognodes, target)
ramfs_task.env.FS_BUILDER = fsbuilder_link_task.outputs[0].abspath()
# Patch up dependencies
ramfs_task.set_run_after(fsbuilder_link_task)
taskgen.bld.add_manual_dependency(target, fsbuilder_link_task.outputs[0])
# Save reference to the task
taskgen.fs_builder_task = ramfs_task
class fs_builder(Task.Task):
run_str = '${FS_BUILDER} -o ${TGT} ${SRC}'
"""
Append the source emitted by a ram filesystem builder, to the inputs
of a regular C/C++ compiled program
"""
@feature('ramfs_image')
@before_method('process_source')
def add_ramfs_sources(taskgen):
ramfs_image = taskgen.bld.get_tgen_by_name(taskgen.ramfs_image).fs_builder_task.outputs[0]
elf_container = ramfs_image.parent.find_or_declare("%s.%d.o" % (ramfs_image.name, taskgen.idx))
elf_task = taskgen.create_task('elf_encapsulate', ramfs_image, elf_container)
# Objcopy names the ELF section encapsulating the source binary
# data as '.data' by default. We'll translate that into a more
# meaningful section name.
elf_task.env['RENAME_SECTION_ST'] = ['--rename-section', '.data=.ramfs']
# We can directly append the .o ELF file to the sources of the
# kernel. Waf is smart enough to automatically include object
# files declared as sources, into the link. See the 'fake_o'
# task over in ccroot.py.
taskgen.source.append(elf_container)
class elf_encapsulate(Task.Task):
run_str = '${OBJCOPY} -I binary -O elf32-littlearm -B arm ${RENAME_SECTION_ST} ${SRC} ${TGT}'
"""
Add a given linker script to the LINKFLAGS and update dependencies so that
the binary will re-link if the script changes.
"""
@feature('ldscript')
@after_method('apply_link')
@before_method('propagate_uselib_vars')
def apply_ldscript(taskgen):
script = taskgen.path.find_or_declare(taskgen.ldscript)
taskgen.bld.add_manual_dependency(taskgen.link_task.outputs[0], script)
taskgen.linkflags += ['-Wl,-T,%s' % script.bldpath()]
"""
Tack on linker flags to cause a linker map to be generated
"""
@feature('linkermap')
@after_method('apply_link')
@before_method('propagate_uselib_vars')
def apply_linkermap(taskgen):
mapfile = taskgen.link_task.outputs[0].change_ext('.map')
taskgen.link_task.outputs.append(mapfile)
taskgen.linkflags += ['-Wl,-Map,%s' % mapfile.bldpath()]
"""
After process_source(), so that the compiled_tasks[] will be populated already.
Before propagate_uselib_vars(), so that changes to includes[] will still be
incorporated into the finished INCLUDES environment.
"""
@feature('asmoffsets')
@after_method('process_source')
@before_method('propagate_uselib_vars')
def apply_asmoffsets(taskgen):
input = taskgen.path.find_resource(taskgen.asmoffsets)
input_ext = input.name[input.name.rfind('.'):]
asm = input.change_ext('%s.%d.s' % (input_ext, taskgen.idx))
header = input.change_ext('.h')
cxx_task = taskgen.create_task('cxx', input, asm)
cxx_task.env.CXX_TGT_F = ['-S', '-o']
cxx_task.env.append_value('CXXFLAGS', '-Wno-invalid-offsetof')
grep_task = taskgen.create_task('asmoffsets', asm, header)
taskgen.includes.append(header.parent)
# Force all our #include-using ASM tasks to run after this
asmclass = Task.classes['asm']
for asmtask in [t for t in taskgen.compiled_tasks if isinstance(t, asmclass)]:
taskgen.bld.add_manual_dependency(asmtask.outputs[0], header)
asmtask.set_run_after(grep_task)
# Put the directory holding the generated header into the search path
taskgen.includes.append(header.parent)
class asmoffsets(Task.Task):
def run(self):
outlines = []
outlines.append('#ifndef __OFFSETS_H__')
outlines.append('#define __OFFSETS_H__')
outlines.append('')
for line in self.inputs[0].read().splitlines():
if line.startswith('#define'):
outlines.append(line)
outlines.append('')
outlines.append('#endif /* __OFFSETS_H__ */')
self.outputs[0].write('\n'.join(outlines))
return 0
# Force main 'asm' to be loaded so that we can be sure that our
# custom hook for .S files get installed after asm's
from waflib.Tools import asm
from waflib.TaskGen import extension
@extension('.S')
def asm_hook(taskgen, node):
preproc = node.parent.find_or_declare('%s.%d.i' % (node.name, taskgen.idx))
t = taskgen.create_task('c', node, preproc)
t.env['CC_TGT_F'] = ['-E', '-o']
return taskgen.create_compiled_task('asm', preproc)
def doxygen(bld):
bld(features = ['doxygen'], doxyfile = 'Doxyfile')
class DoxygenContext(BuildContext):
fun = 'doxygen'
cmd = 'doxygen'
import waflib.extras.doxygen
Task.always_run(waflib.extras.doxygen.doxygen)