forked from google/pebble
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwscript
1742 lines (1331 loc) · 60.8 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
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
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json
import os
import subprocess
import sys
import pexpect
import zipfile
import datetime
import time
import waflib
from waflib import Node, Logs
from waflib.Build import BuildContext
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.asm
import waftools.gitinfo
import waftools.ldscript
import waftools.openocd
import waftools.xcode_pebble
LOGHASH_OUT_PATH = 'src/fw/loghash_dict.json'
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 run_arm_gdb(ctx, elf_node, cmd_str="", target_server_port=3333):
from tools.gdb_driver import find_gdb_path
arm_none_eabi_path = find_gdb_path()
if arm_none_eabi_path is None:
ctx.fatal("pebble-gdb not found!")
os.system('{} {} {} --ex="target remote :{}"'.format(
arm_none_eabi_path, elf_node.path_from(ctx.path),
cmd_str, target_server_port)
)
def options(opt):
opt.load('pebble_arm_gcc', tooldir='waftools')
opt.load('show_configure', tooldir='waftools')
opt.recurse('applib-targets')
opt.recurse('tests')
opt.recurse('src/bluetooth-fw')
opt.recurse('src/fw')
opt.recurse('src/idl')
opt.recurse('sdk')
opt.add_option('--board', action='store',
choices=[ 'bb2',
'ev2_4',
'v1_5',
'v2_0',
'snowy_bb2', # alias for snowy_dvt, but with #define IS_BIGBOARD
'snowy_evt2',
'snowy_dvt',
'snowy_s3',
'spalding_bb2', # snowy_bb2 with s4 display
'spalding_evt',
'spalding',
'silk_evt',
'silk_bb',
'silk',
'silk_bb2',
'cutts_bb',
'robert_bb',
'robert_bb2',
'robert_evt',
'robert_es',
'asterix_evt1',],
help='Which board we are targeting '
'bb2, snowy_dvt, spalding, silk...')
opt.add_option('--jtag', action='store', default=None, dest='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('--internal_sdk_build', action='store_true',
help='Build the internal version of the SDK')
opt.add_option('--future_ux', action='store_true',
help='Build future UX features and APIs. Implies --internal_sdk_build.')
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('--lowpowerdebug', action='store_true',
help='Lowpowerdebug can be toggled from the CLI but is off by default. This just turns it on by default')
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('--test_apps', action='store_true',
help='Enables test apps (off by default)')
opt.add_option('--test_apps_list', type=str,
help='Specify AppInstallId\'s of the test apps to be compiled with the firmware')
opt.add_option('--performance_tests', action='store_true',
help='Enables instrumentation + apps for performance testing (off by default)')
opt.add_option('--verbose_logs', action='store_true',
help='Enables verbose logs (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('--qemu', action='store_true',
help='Build an image for qemu instead of a real board.')
opt.add_option('--nojs', action='store_true', help='Removes js support from the current build.')
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('--lang',
action='store',
default='en_US',
help='Which language to package (isocode)')
opt.add_option('--compile_commands', action='store_true', help='Create a clang compile_commands.json')
opt.add_option('--file', action='store', help='Specify a file to use with the flash_fw command')
opt.add_option('--tty',
help='Selects a tty to use for serial imaging. Must be specified for all image commands')
opt.add_option('--baudrate', action='store', type=int, help='Optional: specifies the baudrate to run the targetted uart at')
opt.add_option('--onlysdk', action='store_true', help="only build the sdk")
opt.add_option('--qemu_host', default='localhost:12345',
help='host:port for the emulator console connection')
opt.add_option('--force-fit-tintin', action='store_true',
help='Force fit for Tintin')
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('--build_test_apps', action='store_true',
help='Turns on building of test apps')
opt.add_option('--bb_large_spi', action='store_true',
help='Sets a flag to use all 8MB of BigBoard flash')
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('--voice_debug', action='store_true',
help='Enable all voice logging.')
opt.add_option('--voice_codec_tests', action='store_true',
help='Enable voice codec tests. Enables the profiler')
opt.add_option('--battery_debug', action='store_true',
help='Set the PMIC\'s max charging voltage to 4.3V.')
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('--infinite_backlight', action='store_true',
help='Makes the backlight never time-out.')
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')
opt.add_option('--bootloader-test', action='store', default='none',
choices=['none', 'stage1', 'stage2'],
help='Build bootloader test (stage1 or stage2). Implies --mfg.')
opt.add_option('--reboot_on_bt_crash', action='store_true', help='Forces a BT '
'chip crash to immediately force a system reboot instead of just cycling airplane mode. '
'This makes it easier for us to actually get crash info')
def handle_configure_options(conf):
if conf.options.noprompt:
conf.env.append_value('DEFINES', 'DISABLE_PROMPT')
conf.env.DISABLE_PROMPT = True
if conf.options.beta or conf.options.release:
conf.env.append_value('DEFINES', 'RELEASE')
if conf.options.malloc_instrumentation:
conf.env.append_value('DEFINES', 'MALLOC_INSTRUMENTATION')
print("Enabling malloc instrumentation")
if conf.options.qemu:
conf.env.append_value('DEFINES', 'TARGET_QEMU')
if conf.options.test_apps_list:
conf.options.test_apps = True
conf.env.test_apps_list = conf.options.test_apps_list.split(",")
print("Enabling test apps: " + str(conf.options.test_apps_list))
if conf.options.build_test_apps or conf.options.test_apps:
conf.env.BUILD_TEST_APPS = True
if conf.options.performance_tests:
conf.env.PERFORMANCE_TESTS = True
if conf.options.voice_debug:
conf.env.VOICE_DEBUG = True
if conf.options.voice_codec_tests:
conf.env.VOICE_CODEC_TESTS = True
conf.env.append_value('DEFINES', 'VOICE_CODEC_TESTS')
conf.options.profiler = True
if conf.env.MICRO_FAMILY == 'STM32F4':
if conf.options.lowpowerdebug and not conf.options.nosleep:
Logs.warn('On snowy --lowpowerdebug can only be used with --nosleep. Forcing --nosleep on!\n'
'See PBL-10174.')
conf.env.append_value('DEFINES', 'PBL_NOSLEEP')
if 'bb' in conf.options.board or conf.options.board in ('asterix_evt1'):
conf.env.append_value('DEFINES', 'IS_BIGBOARD')
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.lowpowerdebug:
conf.env.append_value('DEFINES', 'LOW_POWER_DEBUG')
print("Sleep and Stop mode debugging enabled")
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.reboot_on_bt_crash:
conf.env.append_value('DEFINES', 'REBOOT_ON_BT_CRASH=1')
print("BT now crash will trigger an MCU reboot")
if conf.options.test_apps:
conf.env.append_value('DEFINES', 'ENABLE_TEST_APPS')
print("Im in ur firmware, bloatin ur binz! (Test apps enabled)")
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)")
if conf.options.verbose_logs:
conf.env.append_value('DEFINES', 'VERBOSE_LOGGING')
print("Verbose logging enabled")
if conf.options.ui_debug:
conf.env.append_value('DEFINES', 'UI_DEBUG')
if conf.options.no_sandbox or conf.options.qemu:
print("Sandbox disabled")
else:
conf.env.append_value('DEFINES', 'APP_SANDBOX')
if conf.options.bb_large_spi:
conf.env.append_value('DEFINES', 'LARGE_SPI_FLASH')
print("Enabling 8MB BigBoard flash")
if not conf.options.nolog:
conf.env.append_value('DEFINES', 'PBL_LOG_ENABLED')
if not conf.options.nohash:
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.voice_debug:
conf.env.append_value('DEFINES', 'VOICE_DEBUG')
if conf.options.battery_debug:
conf.env.append_value('DEFINES', 'BATTERY_DEBUG')
print("Enabling higher battery charge voltage.")
if conf.options.future_ux and not conf.is_tintin():
print("Future UX features enabled.")
conf.env.FUTURE_UX = True
conf.env.INTERNAL_SDK_BUILD = bool(conf.options.internal_sdk_build)
if conf.env.INTERNAL_SDK_BUILD:
print("Internal SDK enabled")
if conf.options.force_fit_tintin:
conf.env.append_value('DEFINES', 'TINTIN_FORCE_FIT')
print("Functionality is secondary to usability")
if (conf.is_snowy_compatible() and not conf.options.no_lto) or conf.options.lto:
conf.options.lto = True
print("Turning on LTO.")
if conf.options.no_link:
conf.env.NO_LINK = True
print("Not linking firmware")
if conf.options.infinite_backlight and 'bb' in conf.options.board:
conf.env.append_value('DEFINES', 'INFINITE_BACKLIGHT')
print("Enabling infinite backlight.")
if conf.options.bootloader_test in ['stage1', 'stage2']:
print("Forcing MFG on for bootloader test build.")
conf.options.mfg = True
if conf.options.bootloader_test == 'stage1':
conf.env.append_value('DEFINES', 'BOOTLOADER_TEST_STAGE1=1')
conf.env.append_value('DEFINES', 'BOOTLOADER_TEST_STAGE2=0')
elif conf.options.bootloader_test == 'stage2':
conf.env.append_value('DEFINES', 'BOOTLOADER_TEST_STAGE1=0')
conf.env.append_value('DEFINES', 'BOOTLOADER_TEST_STAGE2=1')
else:
conf.env.append_value('DEFINES', 'BOOTLOADER_TEST_STAGE1=0')
conf.env.append_value('DEFINES', 'BOOTLOADER_TEST_STAGE2=0')
if not conf.options.mfg and not conf.options.no_pulse_everywhere:
conf.env.append_value('DEFINES', 'PULSE_EVERYWHERE=1')
def _create_cm0_env(conf):
prev_env = conf.env
prev_variant = conf.variant
# Create a new Cortex M0 environment that's used to build for the DA14681:
conf.setenv('cortex-m0')
# Copy the defines fron the stock env into our m0 env
conf.env.append_unique('DEFINES', prev_env.DEFINES)
Logs.pprint('CYAN', 'Configuring ARM cortex-m0 environment')
conf.env.append_unique('DEFINES', 'ARCH_NO_NATIVE_LONG_DIVIDE')
CPU_FLAGS = ['-mcpu=cortex-m0', '-mthumb']
OPT_FLAGS = [
'-fvar-tracking-assignments', # Track variable locations better
'-fmessage-length=0', '-fsigned-char',
'-fbuiltin',
'-fno-builtin-itoa',
'-ffreestanding',
'-Os',
]
if not conf.options.no_debug:
OPT_FLAGS += [
'-g3',
'-gdwarf-4', # More detailed debug info
]
C_FLAGS = ['-std=c11', '-ffunction-sections',
'-Wall', '-Wextra', '-Werror', '-Wpointer-arith',
'-Wno-unused-parameter', '-Wno-missing-field-initializers',
'-Wno-error=unused-parameter',
'-Wno-error=unused-const-variable',
'-Wno-packed-bitfield-compat',
'-Wno-address-of-packed-member',
'-Wno-expansion-to-defined',
'-Wno-enum-int-mismatch',
'-Wno-enum-conversion']
conf.find_program('arm-none-eabi-gcc', var='CC', mandatory=True)
conf.env.AS = conf.env.CC
for tool in ['ar', 'objcopy']:
conf.find_program('arm-none-eabi-' + tool, var=tool.upper(),
mandatory=True)
conf.env.append_unique('CFLAGS', CPU_FLAGS + OPT_FLAGS + C_FLAGS)
ASFLAGS = ['-x', 'assembler-with-cpp']
conf.env.append_unique('ASFLAGS', ASFLAGS + CPU_FLAGS + OPT_FLAGS)
conf.env.append_unique('LINKFLAGS',
['-Wl,--cref',
'-Wl,--gc-sections',
'-nostdlib',
] + CPU_FLAGS + OPT_FLAGS)
conf.load('gcc gas objcopy ldscript')
conf.load('file_name_c_define')
conf.variant = prev_variant
conf.env = prev_env
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.recurse('platform')
conf.env.QEMU = conf.options.qemu
conf.env.NOJS = conf.options.nojs
# The BT controller is the only thing different between robert_es and robert_evt, so just
# retend robert_es is robert_evt. We'll be removing robert_es fairly soon anyways.
bt_board = None
if conf.options.board == 'robert_es':
bt_board = 'robert_es'
conf.options.board = 'robert_evt'
if conf.options.jtag:
conf.env.JTAG = conf.options.jtag
elif conf.options.board in ('snowy_bb2', 'spalding_bb2'):
conf.env.JTAG = 'jtag_ftdi'
elif conf.options.board in ('cutts_bb', 'robert_bb', 'robert_bb2', 'robert_evt',
'silk_evt', 'silk_bb', 'silk_bb2', 'silk'):
conf.env.JTAG = 'swd_ftdi'
elif conf.options.board in ('asterix_evt1'):
conf.env.JTAG = 'cmsis-dap'
else:
# default to bb2
conf.env.JTAG = 'bb2'
# Cutts and Robert access flash through the ITCM bus (except in QEMU)
if (conf.is_cutts() or conf.is_robert()) and not conf.env.QEMU:
conf.env.FLASH_ITCM = True
else:
conf.env.FLASH_ITCM = False
# Set platform used for building the SDK
if conf.is_tintin():
conf.env.PLATFORM_NAME = 'aplite'
conf.env.MIN_SDK_VERSION = 2
elif conf.is_spalding():
conf.env.PLATFORM_NAME = 'chalk'
conf.env.MIN_SDK_VERSION = 3
elif conf.is_snowy_compatible():
conf.env.PLATFORM_NAME = 'basalt'
conf.env.MIN_SDK_VERSION = 2
elif conf.is_silk() or conf.is_asterix():
conf.env.PLATFORM_NAME = 'diorite'
conf.env.MIN_SDK_VERSION = 2
elif conf.is_cutts() or conf.is_robert():
conf.env.PLATFORM_NAME = 'emery'
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
if conf.is_tintin():
conf.env.MICRO_FAMILY = 'STM32F2'
elif conf.is_snowy_compatible() or conf.is_silk():
conf.env.MICRO_FAMILY = 'STM32F4'
elif conf.is_cutts() or conf.is_robert():
conf.env.MICRO_FAMILY = 'STM32F7'
elif conf.is_asterix():
conf.env.MICRO_FAMILY = 'NRF52840'
else:
conf.fatal('No micro family specified for {}!'.format(conf.options.board))
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.recurse('src/idl')
conf.recurse('src/fw')
conf.recurse('sdk')
conf.recurse('bin/boot')
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)
# robert_es is the exact same as robert_evt, except for the BT chip, so gets converted to
# robert_evt above, but we need to handle it as robert_es here.
if bt_board is None:
bt_board = conf.get_board()
# Select BT controller based on configuration:
if conf.env.QEMU:
conf.env.bt_controller = 'qemu'
conf.env.append_value('DEFINES', ['BT_CONTROLLER_QEMU'])
elif conf.is_tintin() or conf.is_snowy() or conf.is_spalding():
conf.env.bt_controller = 'cc2564x'
conf.env.append_value('DEFINES', ['BT_CONTROLLER_CC2564X'])
elif conf.is_asterix():
conf.env.bt_controller = 'nrf52'
conf.env.append_value('DEFINES', ['BT_CONTROLLER_NRF52'])
elif bt_board in ('silk_bb2', 'silk', 'robert_bb2', 'robert_evt'):
conf.env.bt_controller = 'da14681-01'
conf.env.append_value('DEFINES', ['BT_CONTROLLER_DA14681'])
else:
conf.env.bt_controller = 'da14681-00'
conf.env.append_value('DEFINES', ['BT_CONTROLLER_DA14681'])
_create_cm0_env(conf)
conf.recurse('src/bluetooth-fw')
Logs.pprint('CYAN', 'Configuring arm_firmware environment')
conf.setenv('', base_env)
conf.load('pebble_arm_gcc', tooldir='waftools')
conf.setenv('arm_prf_mode', env=conf.env)
conf.env.append_value('DEFINES', ['RECOVERY_FW'])
Logs.pprint('CYAN', 'Configuring unit test environment')
conf.setenv('local', unit_test_env)
# 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' ]
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)
prev_env = conf.env
Logs.pprint('CYAN', 'Configuring 32 bit host environment')
# Copy 'local' to serve as the basis for '32bit':
env_32bit = conf.env.derive().detach()
env_32bit.append_value('CFLAGS', '-m32')
env_32bit.append_value('LINKFLAGS', '-m32')
env_32bit.LINK_CC = 'gcc'
conf.all_envs['32bit'] = env_32bit
conf.set_env(prev_env)
# Note: this will modify the 'local' conf when targeting emscripten:
conf.recurse('applib-targets')
Logs.pprint('CYAN', 'Configuring stored apps environment')
conf.setenv('stored_apps', base_env)
conf.recurse('stored_apps')
# Confirm that requirements-*.txt and requirements-osx-brew.txt have been satisfied.
import tool_check
tool_check.tool_check()
# Warn user not to use Cutts BB build with a Robert screen
if conf.options.board == 'cutts_bb':
Logs.warn('NOTE: Do not use this build with a C2/Robert display '
'(6V6 rail will damage the display)')
def _run_remote_suite(ctx, suite):
# PEBBLESDK_TEST_ROOT must be defined in order to initiate integration tests
try:
pebblesdk_test_root = os.environ['PEBBLESDK_TEST_ROOT']
except KeyError:
waflib.Logs.pprint('RED', 'Error: environment variable $PEBBLESDK_TEST_ROOT must be defined')
return
# Check if firmware has been built
# Assume we're looking for a "normal" PBZ, as recovery PBZs aren't supported by integration tests
fw_bin_path = ctx.get_tintin_fw_node().abspath()
fw_bin_exists = os.path.isfile(fw_bin_path)
if not fw_bin_exists:
waflib.Logs.pprint('RED', ('Error: BIN not found at expected location {}, '
'have you run `waf build` yet?'.format(fw_bin_path)))
return
# Check if firmware has been bundled
version_string, version_ts, _ = _get_version_info(ctx)
fw_type = 'qemu' if ctx.env.QEMU else 'normal'
fw_pbz_path = ctx.get_pbz_node(fw_type, ctx.env.BOARD, version_string).abspath()
fw_pbz_exists = os.path.isfile(fw_pbz_path)
if not fw_pbz_exists:
waflib.Logs.pprint('CYAN', ('Warning: PBZ not found at expected location {}, '
'running `waf bundle`...').format(fw_pbz_path))
bundle(ctx)
# Run power tests using remote_runner.py
remote_runner_path = os.path.join(pebblesdk_test_root, 'remote_runner.py')
if not os.path.isfile(remote_runner_path):
waflib.Logs.pprint('RED', ('Error: remote_runner.py not found in {}. '
'Are you sure that PEBBLESDK_TEST_ROOT is defined correctly?'
.format(pebblesdk_test_root)))
return
subprocess.call([remote_runner_path, '--pbz', fw_pbz_path, '[%s]' % suite])
class power_test(BuildContext):
cmd = 'power_test'
def execute_build(ctx):
_run_remote_suite(ctx, 'power')
class integration_test(BuildContext):
cmd = 'integration_test'
def execute_build(ctx):
_run_remote_suite(ctx, 'tintin_3x')
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)
if bld.variant in ('test', 'test_rocky_emx', 'applib'):
bld.set_env(bld.all_envs['local'])
bld.load('file_name_c_define', tooldir='waftools')
bld.recurse('platform')
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('src/libutil')
bld.recurse('tools')
return
if bld.variant == 'tools':
bld.recurse('tools')
return
if bld.variant in ('', 'applib', 'prf'):
# Dependency for SDK
bld.recurse('src/fw/vendor/jerryscript')
if bld.variant == '':
# sdk generation
bld.recurse('sdk')
if bld.variant == 'applib':
bld.recurse('resources')
bld.recurse('src/libutil')
bld.recurse('src/fw')
bld.recurse('src/fw/vendor/nanopb')
bld.recurse('src/include')
bld.recurse('applib-targets')
return
if bld.options.onlysdk:
# stop here, sdk generation is done
return
# Do not enable stationary mode in PRF or release firmware
if (bld.variant != 'prf' and not bld.env.QEMU and bld.env.NORMAL_SHELL != 'sdk'):
bld.env.append_value('DEFINES', 'STATIONARY_MODE')
if bld.variant == 'prf':
bld.set_env(bld.all_envs['arm_prf_mode'])
elif bld.variant == 'test':
if bld.env.APPLIB_TARGET == 'emscripten':
bld.fatal('Did you mean ./waf test_rocky_emx ?')
bld.recurse('src/include')
bld.recurse('src/fw/vendor/jerryscript')
bld.recurse('src/fw/vendor/nanopb')
bld.recurse('src/libbtutil')
bld.recurse('src/libos')
bld.recurse('src/libutil')
bld.recurse('tools')
bld.recurse('tests')
return
elif bld.variant == 'test_rocky_emx':
if bld.env.APPLIB_TARGET != 'emscripten':
bld.fatal('Make sure to ./waf configure with --target=emscripten')
bld.recurse('src/libutil')
bld.recurse('src/libos')
bld.recurse('src/fw/vendor/jerryscript')
bld.recurse('src/fw/vendor/nanopb')
bld.recurse('applib-targets')
bld.recurse('tools')
bld.recurse('tests')
return
if bld.variant == '':
bld.recurse('stored_apps')
bld.recurse('src/include')
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')
if sys.platform != 'darwin':
bld.recurse('tools/qemu_spi_cooker')
# 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)
class build_prf(BuildContext):
"""executes the recovery firmware build"""
cmd = 'build_prf'
variant = 'prf'
class build_applib(BuildContext):
cmd = 'build_applib'
variant = 'applib'
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:
if ctx.env.MICRO_FAMILY == 'STM32F2' and ctx.env.QEMU:
# Let us off with a warning for now
Logs.warn(str(e))
else:
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.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.MICRO_FAMILY == 'STM32F4':
max_size = 512 * 1024
elif ctx.env.MICRO_FAMILY == 'STM32F7':
max_size = 1024 * 1024
elif ctx.env.MICRO_FAMILY == 'NRF52840':
max_size = 512 * 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 size_prf(BuildContext):
"""checks the size of PRF"""
cmd = 'size_prf'
variant = 'prf'
class test(BuildContext):
"""builds and runs the tests"""
cmd = 'test'
variant = 'test'
class test_rocky_emx(BuildContext):
"""builds and runs the tests"""
cmd = 'test_rocky_emx'
variant = 'test_rocky_emx'
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)
out_file = ctx.get_pbz_node(fw_type, ctx.env.BOARD, version_string).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)
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 'RELEASE' not in ctx.env.DEFINES 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.txt')
# make sure ctx.capability is available
ctx.recurse('platform', mandatory=False)
if ctx.capability('HAS_JAVASCRIPT'):
js_tooling = ctx.path.get_bld().find_node('src/fw/vendor/jerryscript/js_tooling/js_tooling.js')
if js_tooling is not None:
b.add_jstooling(js_tooling.path_from(ctx.path), ctx.capability('JAVASCRIPT_BYTECODE_VERSION'))
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.QEMU:
bundle_qemu(ctx)
else:
_make_bundle(ctx, ctx.get_tintin_fw_node().path_from(ctx.path),
resource_path=ctx.get_pbpack_node().path_from(ctx.path))
_generate_release_notes(ctx)
def _generate_release_notes(ctx):
def _write_tag_to_release_notes(task):
output = task.outputs[0].abspath()
tag = task.generator.version_tag
with open(output, 'w') as f:
f.write(tag)
task.dep_vars = tag
git_revision = waftools.gitinfo.get_git_revision(ctx)
version = "{}.{}".format(git_revision['MAJOR_VERSION'], git_revision['MINOR_VERSION'])
version_hotfix = "{}.{}".format(version, git_revision['PATCH_VERSION'])
summary_node = ctx.path.find_node('release-notes').find_node('summary-{}.txt'.format(version_hotfix))
if summary_node is None: