-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathwscript
More file actions
777 lines (604 loc) · 28.2 KB
/
wscript
File metadata and controls
777 lines (604 loc) · 28.2 KB
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
import os
import re
import subprocess
import sys
import datetime
import time
import waflib
from waflib import Logs
from waflib.Build import BuildContext
def _normalize_kconfig_override_args(argv):
normalized = []
for arg in argv:
if arg.startswith('-DCONFIG_') and '=' in arg:
normalized.append('--kconfig-override={}'.format(arg[2:]))
else:
normalized.append(arg)
return normalized
sys.argv = _normalize_kconfig_override_args(sys.argv)
waf_dir = sys.path[0]
sys.path.append(os.path.join(waf_dir, 'tools'))
sys.path.append(os.path.join(waf_dir, 'tools/log_hashing'))
sys.path.append(os.path.join(waf_dir, 'sdk/tools/'))
sys.path.append(os.path.join(waf_dir, 'waftools'))
import waftools.gitinfo
import waftools.ldscript
import waftools.openocd
import waftools.pebble_sdk_gcc as pebble_sdk_gcc
from waftools.pebble_sdk_locator import activate_sdk
from pebble_sdk_version import set_env_sdk_version
# Prefer an installed PebbleOS SDK's binaries (toolchain, QEMU, sftool) when
# present. Done at import time so it applies to every waf invocation.
activate_sdk(waflib.Context.run_dir or os.getcwd())
LOGHASH_OUT_PATH = 'src/fw/loghash_dict.json'
RUNNERS = {
'asterix': ['openocd', 'nrfutil'],
'obelix_dvt': ['sftool'],
'obelix_pvt': ['sftool'],
'obelix_bb2': ['sftool'],
'getafix_evt': ['sftool'],
'getafix_dvt': ['sftool'],
'getafix_dvt2': ['sftool'],
}
def truncate(msg):
if msg is None:
return msg
# Don't truncate exceptions thrown by waf itself
if "Traceback " in msg:
return msg
truncate_length = 600
if len(msg) > truncate_length:
msg = msg[:truncate_length-4] + '...\n' + waflib.Logs.colors.NORMAL
return msg
def options(opt):
opt.load('pebble_arm_gcc', tooldir='waftools')
opt.load('show_configure', tooldir='waftools')
opt.load('kconfig', tooldir='waftools')
opt.recurse('src/fw')
gr = opt.add_option_group('test options')
gr.add_option('-D', '--debug_test', action='store_true',
help='Execute tests within GDB. Use alongside -M.')
gr.add_option('-M', '--match', dest='regex', default=None, action='store',
help='Run regex match tests. Example: ./waf test -M "test.*resource.*"')
gr.add_option('-L', '--list_tests', dest='list_tests', action='store_true',
help='List all test names. Usually used in conjunction with -M. Example: '
'./waf test -M test_animation -L')
gr.add_option('-T', '--test_name', dest='test_name', default=None, action='store',
help='Run only the given test name. Usually used in conjunction with -M. Example: '
'./waf test -M test_animation -T unschedule')
gr.add_option('-C', '--coverage', dest='coverage', action='store_true', help='Generate gcov test coverage data and use lcov to generate HTML report')
gr.add_option('--show_output', action='store_true', help='show test output')
gr.add_option('--no_run', action='store_true', help='Do not run the tests, just build them')
gr.add_option('--no_images', action='store_true', help='skip generation of test images, '
'which are only required for some tests and can slow down build times')
opt.add_option('--board', action='store',
choices=[ 'asterix',
'obelix_dvt',
'obelix_pvt',
'obelix_bb2',
'getafix_evt',
'getafix_dvt',
'getafix_dvt2',
'qemu_emery',
'qemu_flint',
'qemu_gabbro',
],
help='Which board we are targeting '
'asterix, obelix, getafix...')
opt.add_option('--runner', default=None, choices=['openocd', 'sftool', 'nrfutil'],
help='Which runner we are using')
opt.add_option('--openocd-jtag', action='store', default=None, dest='openocd_jtag', # default is bb2 (below)
choices=waftools.openocd.JTAG_OPTIONS.keys(),
help='Which JTAG programmer we are using '
'(bb2 (default), olimex, ev2, etc)')
opt.add_option('--nosleep', action='store_true',
help='Disable sleep and stop mode (to use JTAG+GDB)')
opt.add_option('--nostop', action='store_true',
help='Disable stop mode (to use JTAG+GDB)')
opt.add_option('--nowatch', action='store_true',
help='Disable the watchface idle timeout')
opt.add_option('--nowatchdog', action='store_true',
help='Disable automatic reboots when watchdog fires')
opt.add_option('--performance_tests', action='store_true',
help='Enables instrumentation for performance testing (off by default)')
opt.add_option('--ui_debug', action='store_true',
help='Enable window dump & layer nudge CLI cmd (off by default)')
opt.add_option('--sdkshell', action='store_true',
help='Use the sdk shell instead of the normal shell')
opt.add_option('--nolog', action='store_true',
help='Disable PBL_LOG macros to save space')
opt.add_option('--nohash', action='store_true',
help='Disable log hashing and make the logs human readable')
opt.add_option('--log-level', default='debug', choices=['error', 'warn', 'info', 'debug', 'debug_verbose'],
help='Default global log level')
opt.add_option('--flash-log-level', default='info', choices=['error', 'warn', 'info', 'debug', 'debug_verbose'],
help='Default flash log level')
opt.add_option('--compile_commands', action='store_true', help='Create a clang compile_commands.json')
opt.add_option('--onlysdk', action='store_true', help="only build the sdk")
opt.add_option('--no-link', action='store_true',
help='Do not link the final firmware binary. This is used for static analysis')
opt.add_option('--noprompt', action='store_true',
help='Disable the serial console to save space')
opt.add_option('--profiler', action='store_true', help='Enable the profiler.')
opt.add_option('--profile_interrupts', action='store_true',
help='Enable profiling of all interrupts.')
opt.add_option('--no_sandbox', action='store_true',
help='Disable the MPU for 3rd party apps.')
opt.add_option('--malloc_instrumentation', action='store_true',
help='Enables malloc instrumentation')
opt.add_option('--variant', action='store', default='normal',
choices=['normal', 'prf'],
help='Build variant: normal (default) or prf (recovery firmware)')
opt.add_option('--mfg', action='store_true', help='Enable specific MFG-only options in the PRF build')
opt.add_option('--no-pulse-everywhere',
action='store_true',
help='Disables PULSE everywhere, uses legacy logs and prompt')
def handle_configure_options(conf):
if conf.options.noprompt:
conf.env.append_value('DEFINES', 'DISABLE_PROMPT')
conf.env.DISABLE_PROMPT = True
if conf.options.malloc_instrumentation:
conf.env.append_value('DEFINES', 'MALLOC_INSTRUMENTATION')
print("Enabling malloc instrumentation")
if conf.options.performance_tests:
conf.env.PERFORMANCE_TESTS = True
if conf.options.nosleep:
conf.env.append_value('DEFINES', 'PBL_NOSLEEP')
print("Sleep/stop mode disabled")
if conf.options.nostop:
conf.env.append_value('DEFINES', 'PBL_NOSTOP')
print("Stop mode disabled")
if conf.options.nowatch:
conf.env.append_value('DEFINES', 'NO_WATCH_TIMEOUT')
print("Watch watchdog disabled")
if conf.options.nowatchdog:
conf.env.append_value('DEFINES', 'NO_WATCHDOG')
conf.env.NO_WATCHDOG = True
print("Watchdog reboot disabled")
if conf.options.performance_tests:
conf.env.append_value('DEFINES', 'PERFORMANCE_TESTS')
conf.options.profiler = True
print("Instrumentation and apps for performance measurement enabled (enables profiler)")
print(f"Log level: {conf.options.log_level.upper()}")
conf.env.append_value('DEFINES', f'DEFAULT_LOG_LEVEL=LOG_LEVEL_{conf.options.log_level.upper()}')
conf.env.append_value('DEFINES', f'FLASH_LOG_LEVEL=LOG_LEVEL_{conf.options.flash_log_level.upper()}')
if conf.options.ui_debug:
conf.env.append_value('DEFINES', 'UI_DEBUG')
if conf.options.no_sandbox:
print("Sandbox disabled")
else:
conf.env.append_value('DEFINES', 'APP_SANDBOX')
if not conf.options.nolog:
conf.env.append_value('DEFINES', 'PBL_LOG_ENABLED')
if not conf.options.nohash and not conf.env.CONFIG_QEMU:
conf.env.append_value('DEFINES', 'PBL_LOGS_HASHED')
if conf.options.profile_interrupts:
conf.env.append_value('DEFINES', 'PROFILE_INTERRUPTS')
if not conf.options.profiler:
# Can't profile interrupts without the profiler enabled
print("Enabling profiler")
conf.options.profiler = True
if conf.options.profiler:
conf.env.append_value('DEFINES', 'PROFILER')
if not conf.options.nostop:
print("Enable --nostop for accurate profiling.")
conf.env.append_value('DEFINES', 'PBL_NOSTOP')
if conf.options.lto:
print("Turning on LTO.")
if conf.options.no_link:
conf.env.NO_LINK = True
print("Not linking firmware")
if not conf.options.no_pulse_everywhere and (not conf.env.CONFIG_RELEASE or conf.options.mfg):
conf.env.append_value('DEFINES', 'PULSE_EVERYWHERE=1')
def configure(conf):
if not conf.options.board:
conf.fatal('No board selected! '
'You must pass a --board argument when configuring.')
# Has to be 'waftools.gettext' as unadorned 'gettext' will find the gettext
# module in the standard library.
conf.load('waftools.gettext')
conf.load('kconfig', tooldir='waftools')
# JS engine selection is driven entirely by CONFIG_MODDABLE_XS. Override
# per-board with `-DCONFIG_MODDABLE_XS=y/n` at configure time.
if conf.env.CONFIG_MODDABLE_XS:
conf.env.JS_ENGINE = 'moddable'
else:
conf.env.JS_ENGINE = 'none'
if not conf.options.runner:
conf.env.RUNNER = RUNNERS.get(conf.options.board, [None])[0]
else:
if conf.options.runner not in RUNNERS.get(conf.options.board, []):
conf.fatal('Runner {} is not supported on board {}'.format(
conf.options.runner, conf.options.board))
conf.env.RUNNER = conf.options.runner
if conf.env.RUNNER == 'openocd':
if conf.options.openocd_jtag:
conf.env.OPENOCD_JTAG = conf.options.openocd_jtag
elif conf.options.board in ('asterix'):
conf.env.OPENOCD_JTAG = 'swd_cmsisdap'
else:
# default to bb2
conf.env.OPENOCD_JTAG = 'bb2'
conf.env.FLASH_ITCM = False
# Set platform used for building the SDK
if conf.env.CONFIG_PLATFORM_EMERY:
conf.env.PLATFORM_NAME = 'emery'
conf.env.MIN_SDK_VERSION = 3
elif conf.env.CONFIG_PLATFORM_FLINT:
conf.env.PLATFORM_NAME = 'flint'
conf.env.MIN_SDK_VERSION = 2
elif conf.env.CONFIG_PLATFORM_GABBRO:
conf.env.PLATFORM_NAME = 'gabbro'
conf.env.MIN_SDK_VERSION = 3
else:
conf.fatal('No platform specified for {}!'.format(conf.options.board))
# Save this for later
conf.env.BOARD = conf.options.board
conf.env.VARIANT = conf.options.variant
if conf.env.VARIANT == 'prf':
conf.env.append_value('DEFINES', ['RECOVERY_FW'])
conf.env.JS_ENGINE = 'none'
# PRF variant forces JS_ENGINE='none' above. If the board's defconfig had
# CONFIG_MODDABLE_XS=y, autoconf.h was already written with the macro
# defined — undefine it on the command line so source-level guards match
# what we actually link.
if conf.env.JS_ENGINE == 'none' and conf.env.CONFIG_MODDABLE_XS:
conf.env.append_value('CFLAGS', ['-UCONFIG_MODDABLE_XS'])
conf.env.CONFIG_MODDABLE_XS = None
if conf.options.mfg:
# Note that for the most part PRF and MFG firmwares are the same, so for MFG PRF builds
# both MANUFACTURING_FW and RECOVERY_FW will be defined.
conf.env.IS_MFG = True
conf.env.append_value('DEFINES', ['MANUFACTURING_FW'])
conf.find_program('node nodejs', var='NODE',
errmsg="Unable to locate the Node command. "
"Please check your Node installation and try again.")
conf.load('protoc')
conf.recurse('src/fw')
if conf.env.RUNNER == 'openocd':
waftools.openocd.write_cfg(conf)
# Save a baseline environment that we'll use for unit tests
# Detach so operations against conf.env don't affect unit_test_env
unit_test_env = conf.env.derive()
unit_test_env.detach()
# Save a baseline environment that we'll use for ARM environments
base_env = conf.env
handle_configure_options(conf)
Logs.pprint('CYAN', 'Configuring arm_firmware environment')
conf.setenv('', base_env)
conf.load('pebble_arm_gcc', tooldir='waftools')
Logs.pprint('CYAN', 'Configuring unit test environment')
conf.setenv('local', unit_test_env)
# Strip CONFIG_* DEFINES mirrored from the configure-time board: each test
# selects its own simulated platform (asterix / obelix / gabbro) and injects
# the matching BOARD_FAMILY/PLATFORM/SCREEN_COLOR_DEPTH_BITS itself, so the
# configure board's symbols would just collide with the per-test ones.
conf.env.DEFINES = [d for d in conf.env.DEFINES
if not d.split('=', 1)[0].startswith('CONFIG_')]
# if sys.platform.startswith('linux'):
# libclang_path = subprocess.check_output(['llvm-config', '--libdir']).strip()
# conf.env.append_value('INCLUDES', [os.path.join(libclang_path, 'clang/3.2/include/'),])
# The waf clang tool likes to use llvm-ar as it's ar tool, but that doesn't work on our build
# servers. Fall back to boring old ar. This will populate the 'AR' env variable so future
# searches for what value to put into env['AR'] will find this one.
conf.find_program('ar')
conf.load('clang')
conf.load('pebble_test', tooldir='waftools')
conf.env.CLAR_DIR = conf.path.make_node('tools/clar/').abspath()
conf.env.CFLAGS = [ '-std=c11',
'-Wall',
'-Werror',
'-Wno-error=unused-variable',
'-Wno-error=unused-function',
'-Wno-error=missing-braces',
'-Wno-error=unused-const-variable',
'-Wno-error=address-of-packed-member',
'-Wno-enum-conversion',
'-g3',
'-gdwarf-4',
'-O0',
'-fdata-sections',
'-ffunction-sections' ]
# Reset LINKFLAGS so firmware-specific flags (e.g. --undefined=HAL_GetTick)
# don't leak into the host test environment.
conf.env.LINKFLAGS = []
# Apple's ARM64 linker uses chained fixups which require pointer-aligned
# relocations. Packed structs with pointer members fail to link because the
# packed layout can place pointers at non-aligned offsets. Disable chained
# fixups to use classic relocations instead.
if sys.platform == 'darwin':
conf.env.append_value('LINKFLAGS', '-Wl,-no_fixup_chains')
conf.env.append_value('DEFINES', 'CLAR_FIXTURE_PATH="' +
conf.path.make_node('tests/fixtures/').abspath() + '"')
conf.env.append_value('DEFINES', 'PBL_LOG_ENABLED')
if conf.options.compile_commands:
conf.load('clang_compilation_database', tooldir='waftools')
if not os.path.lexists('compile_commands.json'):
filename = 'compile_commands.json'
source = conf.path.get_bld().make_node(filename)
os.symlink(source.path_from(conf.path), filename)
Logs.pprint('CYAN', 'Configuring stored apps environment')
conf.setenv('stored_apps', base_env)
process_info = conf.path.find_node('src/fw/process_management/pebble_process_info.h')
set_env_sdk_version(conf, process_info)
pebble_sdk_gcc.configure(conf)
# Confirm that requirements-*.txt and requirements-osx-brew.txt have been satisfied.
import tool_check
tool_check.tool_check()
def stop_build_timer(ctx):
t = datetime.datetime.utcnow() - ctx.pbl_build_start_time
node = ctx.path.get_bld().make_node('build_time')
with open(node.abspath(), 'w') as fout:
fout.write(str(int(round(t.total_seconds()))))
def build(bld):
bld.DYNAMIC_RESOURCES = []
bld.LOGHASH_DICTS = []
# Start this timer here to include the time to generate tasks.
bld.pbl_build_start_time = datetime.datetime.utcnow()
bld.add_post_fun(stop_build_timer)
# FIXME: remove include/pbl once all modules use prefix
bld(export_includes=['include', 'include/pbl'], name='pbl_includes')
if bld.variant == 'test':
bld.set_env(bld.all_envs['local'])
bld.load('file_name_c_define', tooldir='waftools')
bld.recurse('third_party/nanopb')
bld.recurse('src/idl')
if bld.cmd == 'install':
raise Exception("install isn't a supported command. Did you mean flash?")
if bld.variant == 'pdc2png':
bld.recurse('tools')
return
if bld.variant == 'tools':
bld.recurse('tools')
return
if bld.variant == '':
# Dependency for SDK
bld.recurse('third_party/moddable')
if bld.variant == '' and bld.env.VARIANT != 'prf':
# sdk generation
bld.recurse('sdk')
if bld.options.onlysdk:
# stop here, sdk generation is done
return
# Do not enable stationary mode in PRF or release firmware
if (bld.env.VARIANT != 'prf' and not bld.env.CONFIG_QEMU and bld.env.NORMAL_SHELL != 'sdk'):
bld.env.append_value('DEFINES', 'STATIONARY_MODE')
if bld.variant == 'test':
bld.recurse('third_party/nanopb')
bld.recurse('src/libbtutil')
bld.recurse('src/libos')
bld.recurse('src/libutil')
bld.recurse('tests')
bld.recurse('tools')
return
if bld.variant == '' and bld.env.VARIANT != 'prf':
bld.recurse('stored_apps')
bld.recurse('third_party')
bld.recurse('src/libbtutil')
bld.recurse('src/bluetooth-fw')
bld.recurse('src/libc')
bld.recurse('src/libos')
bld.recurse('src/libutil')
bld.recurse('src/fw')
# Generate resources. Leave this until the end so we collect all the env['DYNAMIC_RESOURCES']
# values that the other build steps added.
bld.recurse('resources')
# if we're not linking the firmware don't run these
if not bld.env.NO_LINK:
bld.add_post_fun(size_fw)
bld.add_post_fun(size_resources)
if 'PBL_LOGS_HASHED' in bld.env.DEFINES:
bld.add_post_fun(merge_loghash_dicts)
def merge_loghash_dicts(bld):
loghash_dict = bld.path.get_bld().make_node(LOGHASH_OUT_PATH)
import log_hashing.newlogging
log_hashing.newlogging.merge_loghash_dict_json_files(loghash_dict, bld.LOGHASH_DICTS)
class SizeFirmware(BuildContext):
cmd = 'size_fw'
fun = 'size_fw'
def size_fw(ctx):
"""prints size information of the firmware"""
fw_elf = ctx.get_tintin_fw_node().change_ext('.elf')
if fw_elf is None:
ctx.fatal('No fw ELF found for size')
fw_bin = ctx.get_tintin_fw_node()
if fw_bin is None:
ctx.fatal('No fw BIN found for size')
import binutils
text, data, bss = binutils.size(fw_elf.abspath())
total = text + data
output = ('{:>7} {:>7} {:>7} {:>7} {:>7} filename\n'
'{:7} {:7} {:7} {:7} {:7x} tintin_fw.elf'.
format('text', 'data', 'bss', 'dec', 'hex', text, data, bss, total, total))
Logs.pprint('YELLOW', '\n' + output)
try:
space_left = _check_firmware_image_size(ctx, fw_bin.path_from(ctx.path))
except FirmwareTooLargeException as e:
ctx.fatal(str(e))
else:
Logs.pprint('CYAN', 'FW: ' + space_left)
class SizeResources(BuildContext):
cmd = 'size_resources'
fun = 'size_resources'
def size_resources(ctx):
"""prints size information of resources"""
if ctx.env.VARIANT == 'prf':
return
pbpack_path = ctx.path.get_bld().find_node('system_resources.pbpack')
if pbpack_path is None:
ctx.fatal('No resource pbpack found')
if ctx.env.CONFIG_SOC_NRF52:
max_size = 1024 * 1024
elif ctx.env.CONFIG_SOC_SF32LB52:
max_size = 2048 * 1024
elif ctx.env.CONFIG_QEMU:
max_size = 2048 * 1024
else:
max_size = 256 * 1024
pbpack_actual_size = os.path.getsize(pbpack_path.path_from(ctx.path))
bytes_free = max_size - pbpack_actual_size
from waflib import Logs
Logs.pprint('CYAN', 'Resources: %d/%d (%d free)\n' % (pbpack_actual_size, max_size, bytes_free))
if pbpack_actual_size > max_size:
ctx.fatal('Resources are too large for target board %d > %d'
% (pbpack_actual_size, max_size))
def size(ctx):
from waflib import Options
Options.commands = ['size_fw', 'size_resources'] + Options.commands
class test(BuildContext):
"""builds and runs the tests"""
cmd = 'test'
variant = 'test'
def docs(ctx):
"""builds the documentation out to build/doxygen"""
ctx.exec_command('doxygen Doxyfile', stdout=None, stderr=None)
class DocsSdk(BuildContext):
"""builds the sdk documentation out to build/sdk/<platformname>/doxygen_sdk"""
cmd = 'docs_sdk'
fun = 'docs_sdk'
def docs_sdk(ctx):
pebble_sdk = ctx.path.get_bld().make_node('sdk')
supported_platforms = pebble_sdk.listdir()
for platform in supported_platforms:
doxyfile = pebble_sdk.find_node(platform).find_node('Doxyfile-SDK.auto')
if doxyfile:
ctx.exec_command('doxygen {}'.format(doxyfile.path_from(ctx.path)),
stdout=None, stderr=None)
def docs_all(ctx):
"""builds the documentation with all dependency graphs out to build/doxygen"""
ctx.exec_command('doxygen Doxyfile-all-graphs', stdout=None, stderr=None)
# Bundle commands
#################################################
def _get_version_info(ctx):
# FIXME: it's probably a better idea to lift board + version info from the .bin file... this can get out of sync!
git_revision = waftools.gitinfo.get_git_revision(ctx)
if git_revision['TAG'] != '?':
version_string = git_revision['TAG']
version_ts = int(git_revision['TIMESTAMP'])
version_commit = git_revision['COMMIT']
else:
version_string = 'dev'
version_ts = 0
version_commit = ''
return version_string, version_ts, version_commit
def _make_bundle(ctx, fw_bin_path, fw_type='normal', board=None, resource_path=None, write=True):
import mkbundle
if board is None:
board = ctx.env.BOARD
b = mkbundle.PebbleBundle()
version_string, version_ts, version_commit = _get_version_info(ctx)
slot = ctx.env.SLOT if fw_type == 'normal' and ctx.env.SLOT != -1 else None
out_file = ctx.get_pbz_node(fw_type, ctx.env.BOARD, version_string, slot).path_from(ctx.path)
try:
_check_firmware_image_size(ctx, fw_bin_path)
b.add_firmware(fw_bin_path, fw_type, version_ts, version_commit, board, version_string, slot)
except FirmwareTooLargeException as e:
ctx.fatal(str(e))
except mkbundle.MissingFileException as e:
ctx.fatal('Error: Missing file ' + e.filename + ', have you run ./waf build yet?')
if resource_path is not None:
b.add_resources(resource_path, version_ts)
if not ctx.env.CONFIG_RELEASE and 'PBL_LOGS_HASHED' in ctx.env.DEFINES:
loghash_dict = ctx.path.get_bld().make_node(LOGHASH_OUT_PATH).abspath()
b.add_loghash(loghash_dict)
# Add a LICENSE.txt file
b.add_license('LICENSE')
if fw_type == 'normal':
layouts_node = ctx.path.get_bld().find_node('resources/layouts.json.auto')
if layouts_node is not None:
b.add_layouts(layouts_node.path_from(ctx.path))
if write:
b.write(out_file)
waflib.Logs.pprint('CYAN', 'Writing bundle to: %s' % out_file)
return b
class BundleCommand(BuildContext):
cmd = 'bundle'
fun = 'bundle'
def bundle(ctx):
"""bundles a firmware"""
if ctx.env.VARIANT == 'prf':
_make_bundle(ctx, ctx.get_tintin_fw_node().path_from(ctx.path), fw_type='recovery')
else:
_make_bundle(ctx, ctx.get_tintin_fw_node().path_from(ctx.path),
resource_path=ctx.get_pbpack_node().path_from(ctx.path))
# QEMU flash image commands
#################################################
class QemuImageMicroCommand(BuildContext):
cmd = 'qemu_image_micro'
fun = 'qemu_image_micro'
class QemuImageSpiCommand(BuildContext):
cmd = 'qemu_image_spi'
fun = 'qemu_image_spi'
def qemu_image_micro(ctx):
"""creates the micro-flash image for qemu"""
from intelhex import IntelHex
fw_hex = ctx.get_tintin_fw_node().change_ext('.hex')
micro_flash_node = ctx.path.get_bld().make_node('qemu_micro_flash.bin')
micro_flash_path = micro_flash_node.path_from(ctx.path)
Logs.pprint('CYAN', 'Writing micro flash image to {}'.format(micro_flash_path))
img = IntelHex(fw_hex.path_from(ctx.path))
img.padding = 0xff
flash_end = ((img.maxaddr() + 511) // 512) * 512
img.tobinfile(micro_flash_path, start=0x00000000, end=flash_end - 1)
def qemu_image_spi(ctx):
"""creates a SPI flash image for qemu"""
if ctx.env.CONFIG_QEMU:
# QEMU generic boards: resources at offset 0x620000 in 32MB flash
resources_begin = 0x620000
image_size = 0x2000000
else:
resources_begin = 0x280000
image_size = 0x400000
spi_flash_node = ctx.path.get_bld().make_node('qemu_spi_flash.bin')
spi_flash_path = spi_flash_node.path_from(ctx.path)
Logs.pprint('CYAN', 'Writing SPI flash image to {}'.format(spi_flash_path))
with open(spi_flash_path, 'wb') as qemu_spi_img_file:
# Pad the first section before system resources with FF's
qemu_spi_img_file.write(bytes([0xff]) * resources_begin)
# Write system resources:
pbpack = ctx.get_pbpack_node()
res_img = open(pbpack.path_from(ctx.path), 'rb').read()
qemu_spi_img_file.write(res_img)
# Pad with 0xFF up to image size
tail_padding_size = image_size - resources_begin - len(res_img)
qemu_spi_img_file.write(bytes([0xff]) * tail_padding_size)
# Flash commands
#################################################
class FirmwareTooLargeException(Exception):
pass
def _check_firmware_image_size(ctx, path):
BYTES_PER_K = 1024
firmware_size = os.path.getsize(path)
# Determine flash and bootloader size so we can calculate the max firmware size
if ctx.env.CONFIG_SOC_NRF52:
if ctx.env.VARIANT == 'prf' and not ctx.env.IS_MFG:
max_firmware_size = 512 * BYTES_PER_K
else:
# 1024k of flash and 32k bootloader
max_firmware_size = (1024 - 32) * BYTES_PER_K
elif ctx.env.CONFIG_SOC_SF32LB52:
if ctx.env.VARIANT == 'prf' and not ctx.env.IS_MFG:
max_firmware_size = 576 * BYTES_PER_K
else:
# 3072k of flash
max_firmware_size = 3072 * BYTES_PER_K
elif ctx.env.CONFIG_QEMU:
max_firmware_size = 4096 * BYTES_PER_K
else:
ctx.fatal('Cannot check firmware size against unknown micro family')
if firmware_size > max_firmware_size:
raise FirmwareTooLargeException('Firmware is too large! Size is 0x%x should be less than 0x%x' \
% (firmware_size, max_firmware_size))
return ('%d / %d bytes used (%d free)' %
(firmware_size, max_firmware_size, (max_firmware_size - firmware_size)))
# Tool build commands
#################################################
class build_pdc2png(BuildContext):
"""executes the pdc2png build"""
cmd = 'build_pdc2png'
variant = 'pdc2png'
class build_tools(BuildContext):
"""build all tools in tools/ dir"""
cmd = 'build_tools'
variant = 'tools'
# vim:filetype=python