-
Notifications
You must be signed in to change notification settings - Fork 89
/
Configuration.mk
683 lines (594 loc) · 31.6 KB
/
Configuration.mk
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
################################################################################
##
## libtock-c build system configuration.
##
## This sets all of the parameters and flags required to build libtock-c
## applications for the architectures Tock supports.
##
## Included by AppMakefile.mk and TockLibrary.mk.
##
################################################################################
# Ensure that this file is only included once.
ifndef CONFIGURATION_MAKEFILE
CONFIGURATION_MAKEFILE = 1
# Remove built-in rules and variables
# n.b. no-op for make --version < 4.0
MAKEFLAGS += -r
MAKEFLAGS += -R
# Toolchain programs.
AR := -ar
AS := -as
CXX := -g++
OBJDUMP := -objdump
RANLIB := -ranlib
READELF := -readelf
SIZE := -size
# Set default region sizes for process memory requirements.
STACK_SIZE ?= 2048
APP_HEAP_SIZE ?= 1024
KERNEL_HEAP_SIZE ?= 1024
# Set default required kernel version.
KERNEL_MAJOR_VERSION ?= 2
KERNEL_MINOR_VERSION ?= 0
# PACKAGE_NAME is used to identify the application for IPC and for error
# reporting. This can be overwritten per-app to customize the name, otherwise we
# default to the name of the directory the app is in.
PACKAGE_NAME ?= $(shell basename "$(shell pwd)")
# Tock app targets.
#
# This is a list of all of the different targets to build an app for which will
# all be bundled into a TAB. This allows us to build an app for any board Tock
# supports, and wait until a TAB is installed onto a board to figure out which
# specific binary that hardware platform needs.
#
# Each entry is itself a list:
#
# 1. The name of the architecture. This is used for naming generated files and
# variables in the Makefiles. It is generally just a human-readable name.
# 2. (Optional) The name to use when creating the output file.
# 3. (Optional) The address to use as the fixed start of flash.
# 4. (Optional) The address to use as the fixed start of RAM.
#
# Specific addresses useful for the OpenTitan hardware memory map.
OPENTITAN_TOCK_TARGETS := rv32imc|rv32imc.0x20030080.0x10005000|0x20030080|0x10005000\
rv32imc|rv32imc.0x20030880.0x10008000|0x20030880|0x10008000\
rv32imc|rv32imc.0x20032080.0x10008000|0x20032080|0x10008000\
rv32imc|rv32imc.0x20034080.0x10008000|0x20034080|0x10008000
# Specific addresses useful for the ARTY-E21 FPGA softcore hardware memory map.
ARTY_E21_TOCK_TARGETS := rv32imac|rv32imac.0x40430080.0x80004000|0x40430080|0x80004000\
rv32imac|rv32imac.0x40440080.0x80007000|0x40440080|0x80007000
VEER_EL2_TOCK_TARGETS := rv32imc|rv32imc.0x20300080.0x20602000|0x20300080|0x20602000
# Include the RISC-V targets.
# rv32imac|rv32imac.0x20040080.0x80002800 # RISC-V for HiFive1b
# rv32imac|rv32imac.0x403B0080.0x3FCC0000 # RISC-V for ESP32-C3
# rv32imc|rv32imc.0x41000080.0x42008000 # RISC-V for LiteX Arty-A7
# rv32imc|rv32imc.0x00080080.0x40008000 # RISC-V for LiteX Simulator
TOCK_TARGETS ?= cortex-m0\
cortex-m3\
cortex-m4\
cortex-m7\
rv32imac|rv32imac.0x20040080.0x80002800|0x20040080|0x80002800\
rv32imac|rv32imac.0x403B0080.0x3FCC0000|0x403B0080|0x3FCC0000\
rv32imc|rv32imc.0x41000080.0x42008000|0x41000080|0x42008000\
rv32imc|rv32imc.0x00080080.0x40008000|0x00080080|0x40008000\
$(OPENTITAN_TOCK_TARGETS) \
$(ARTY_E21_TOCK_TARGETS) \
$(VEER_EL2_TOCK_TARGETS)
# Generate `TOCK_ARCH_FAMILIES`, the set of architecture families which will be
# used to determine toolchains to use in the build process.
TOCK_ARCH_FAMILIES := $(sort $(foreach target, $(TOCK_TARGETS), $(strip \
$(findstring rv32i,$(target)) \
$(findstring cortex-m,$(target)))))
# Generate `TOCK_ARCHS`, the set of architectures listed in `TOCK_TARGETS`.
#
# The architecture name is used extensively to create the correct build commands
# for each architecture. Make targets are automatically generated in
# `AppMakefile.mk` based on the list of `TOCK_TARGETS`. The remainder of this
# file uses the architecture name to pull the correct flags for each stage in
# the build process.
TOCK_ARCHS := $(sort $(foreach target, $(TOCK_TARGETS), $(firstword $(subst |, ,$(target)))))
# Check if elf2tab exists, if not, install it using cargo.
ELF2TAB ?= elf2tab
ELF2TAB_REQUIRED_VERSION := 0.12.0
ELF2TAB_EXISTS := $(shell $(SHELL) -c "command -v $(ELF2TAB)")
ELF2TAB_VERSION := $(shell $(SHELL) -c "$(ELF2TAB) --version | cut -d ' ' -f 2")
# Check elf2tab version.
UPGRADE_ELF2TAB := $(shell $(SHELL) -c "printf '%s\n%s\n' '$(ELF2TAB_REQUIRED_VERSION)' '$(ELF2TAB_VERSION)' | sort --check=quiet --version-sort || echo yes")
ifeq ($(UPGRADE_ELF2TAB),yes)
$(info Trying to update elf2tab to >= $(ELF2TAB_REQUIRED_VERSION))
ELF2TAB_EXISTS =
endif
ifndef ELF2TAB_EXISTS
$(shell cargo install elf2tab)
# Check elf2tab version after install
ELF2TAB_VERSION := $(shell $(SHELL) -c "$(ELF2TAB) --version | cut -d ' ' -f 2")
UPGRADE_ELF2TAB := $(shell $(SHELL) -c "printf '%s\n%s\n' '$(ELF2TAB_REQUIRED_VERSION)' '$(ELF2TAB_VERSION)' | sort --check=quiet --version-sort || echo yes")
ifeq ($(UPGRADE_ELF2TAB),yes)
$(error Failed to automatically update elf2tab, please update manually elf2tab to >= $(ELF2TAB_REQUIRED_VERSION))
endif
endif
################################################################################
##
## Shared build flags for all architectures in libtock-c.
##
################################################################################
# elf2tab flags.
#
# Provide the name, memory sizes, and required kernel version as arguments to
# elf2tab so it can include the parameters in the TBF header.
ELF2TAB_ARGS += -n $(PACKAGE_NAME)
ELF2TAB_ARGS += --stack $(STACK_SIZE) --app-heap $(APP_HEAP_SIZE) --kernel-heap $(KERNEL_HEAP_SIZE)
ELF2TAB_ARGS += --kernel-major $(KERNEL_MAJOR_VERSION) --kernel-minor $(KERNEL_MINOR_VERSION)
# By default, add space in the footer that can be used for credentials. This
# simplifies allowing tockloader to add credentials after a tbf is compiled.
#
# A build can opt out by setting `TBF_NO_FOOTER=1`.
ifneq ($(TBF_NO_FOOTER),)
# Opt out of default space for credentials in the footer.
else
ELF2TAB_ARGS += --minimum-footer-size 3000
endif
# Flags for building app Assembly, C, and C++ files used by all architectures.
# n.b. CPPFLAGS are shared for C and C++ sources (it's short for C PreProcessor,
# and C++ uses the C preprocessor). To specify flags for only C or C++, use
# CFLAGS for C only and CXXFLAGS for C++ only. [While we're on the trivia
# lesson, CXX is shorthand for C++ because folks on the unix/gnu side of history
# needed a valid letter rather than a symbol (an X is a rotated +). Confusingly,
# the dos/microsoft lineage chose `.cpp` to address this same issue, leading to
# confusion nowadays about the meaning of 'cpp'.]
override ASFLAGS += -mthumb
override CFLAGS += -std=gnu11
override CPPFLAGS += \
-frecord-gcc-switches\
-gdwarf-2\
-Os\
-fdata-sections -ffunction-sections\
-fstack-usage\
-D_FORTIFY_SOURCE=2\
-Wall\
-Wextra
override WLFLAGS += \
-Wl,--warn-common\
-Wl,--gc-sections\
-Wl,--build-id=none
# Include path for all architectures. To support `#include <libtock/*.h>` and
# `#include <libtock-sync/*.h>` in app source files, we include the root
# libtock-c folder in the preprocessor's search path.
override CPPFLAGS += -I$(TOCK_USERLAND_BASE_DIR)
# Flags to improve the quality and information in listings (debug target)
OBJDUMP_FLAGS += --disassemble-all --source -C --section-headers
# Use a generic linker script for all libtock-c apps.
LAYOUT ?= $(TOCK_USERLAND_BASE_DIR)/userland_generic.ld
# Various flags for a specific toolchain. Different compilers may have different
# supported features. For GCC we warn if the compiler estimates the stack usage
# will be greater than the allocated stack size.
override CPPFLAGS_gcc += -Wstack-usage=$(STACK_SIZE)
# Generic PIC flags for architectures with compiler support for FDPIC. Note!
# These flags are not sufficient for full PIC support as Tock requires. The
# `-fPIC` flag generally only allows the .text and .data sections to be at
# different relative addresses. However, the .text and RAM sections are not
# fully relocatable. Therefore, just including these flags is not sufficient to
# build a full PIC app for Tock. So, we split these out, and only include them
# for architectures where we have full PIC support.
override CPPFLAGS_PIC += \
-Wl,--emit-relocs\
-fPIC
################################################################################
##
## RISC-V compiler/linker flags
##
################################################################################
# RISC-V toolchains, irrespective of their name-tuple, can compile for
# essentially any target. Thus, try a few known names and choose the one for
# which a compiler is found.
ifneq (,$(shell which riscv64-none-elf-gcc 2>/dev/null))
TOOLCHAIN_rv32 := riscv64-none-elf
else ifneq (,$(shell which riscv32-none-elf-gcc 2>/dev/null))
TOOLCHAIN_rv32 := riscv32-none-elf
else ifneq (,$(shell which riscv64-elf-gcc 2>/dev/null))
TOOLCHAIN_rv32 := riscv64-elf
else ifneq (,$(shell which riscv64-unknown-elf-clang 2>/dev/null))
TOOLCHAIN_rv32 := riscv64-unknown-elf
else ifneq (,$(shell which riscv32-unknown-elf-clang 2>/dev/null))
TOOLCHAIN_rv32 := riscv32-unknown-elf
else
# Fallback option. We don't particularly want to throw an error as this
# configuration makefile can be useful without a proper toolchain.
TOOLCHAIN_rv32 := riscv64-unknown-elf
endif
TOOLCHAIN_rv32i := $(TOOLCHAIN_rv32)
TOOLCHAIN_rv32imc := $(TOOLCHAIN_rv32)
TOOLCHAIN_rv32imac := $(TOOLCHAIN_rv32)
# For RISC-V we default to GCC, but can support clang as well. Eventually, one
# or both toolchains might support the PIC we need, at which point we would
# default to that.
ifeq ($(CLANG),)
# Default to GCC
CC_rv32 := -gcc
else
# If `CLANG=1` on command line, use -clang.
CC_rv32 := -clang
endif
CC_rv32i := $(CC_rv32)
CC_rv32imc := $(CC_rv32)
CC_rv32imac := $(CC_rv32)
# Determine the version of the RISC-V compiler. This is used to select the
# version of the libgcc library that is compatible.
CC_rv32_version := $(shell $(TOOLCHAIN_rv32)$(CC_rv32) -dumpfullversion)
CC_rv32_version_major := $(shell echo $(CC_rv32_version) | cut -f1 -d.)
# Match compiler version to support libtock-newlib versions.
ifeq ($(CC_rv32_version_major),10)
NEWLIB_VERSION_rv32 := 4.2.0.20211231
else ifeq ($(CC_rv32_version_major),11)
NEWLIB_VERSION_rv32 := 4.2.0.20211231
else ifeq ($(CC_rv32_version_major),12)
NEWLIB_VERSION_rv32 := 4.3.0.20230120
else ifeq ($(CC_rv32_version_major),13)
NEWLIB_VERSION_rv32 := 4.3.0.20230120
else
NEWLIB_VERSION_rv32 := 4.3.0.20230120
endif
NEWLIB_VERSION_rv32i := $(NEWLIB_VERSION_rv32)
NEWLIB_VERSION_rv32imc := $(NEWLIB_VERSION_rv32)
NEWLIB_VERSION_rv32imac := $(NEWLIB_VERSION_rv32)
NEWLIB_BASE_DIR_rv32 := $(TOCK_USERLAND_BASE_DIR)/lib/libtock-newlib-$(NEWLIB_VERSION_rv32)
# Match compiler version to supported libtock-libc++ versions.
ifeq ($(CC_rv32_version_major),10)
LIBCPP_VERSION_rv32 := 10.5.0
else ifeq ($(CC_rv32_version_major),11)
LIBCPP_VERSION_rv32 := 10.5.0
else ifeq ($(CC_rv32_version_major),12)
LIBCPP_VERSION_rv32 := 12.3.0
else ifeq ($(CC_rv32_version_major),13)
LIBCPP_VERSION_rv32 := 13.2.0
else
LIBCPP_VERSION_rv32 := 13.2.0
endif
LIBCPP_VERSION_rv32i := $(LIBCPP_VERSION_rv32)
LIBCPP_VERSION_rv32imc := $(LIBCPP_VERSION_rv32)
LIBCPP_VERSION_rv32imac := $(LIBCPP_VERSION_rv32)
LIBCPP_BASE_DIR_rv32 := $(TOCK_USERLAND_BASE_DIR)/lib/libtock-libc++-$(LIBCPP_VERSION_rv32)
# Set the toolchain specific flags.
#
# Note: There are no non-gcc, clang-specific flags currently in use, so there is
# no equivalent CPPFLAGS_clang currently. If there are clang-only flags in the
# future, one can/should be added.
ifeq ($(findstring -gcc,$(CC_rv32)),-gcc)
override CPPFLAGS_toolchain_rv32 += $(CPPFLAGS_gcc)
override CFLAGS_toolchain_rv32 += $(CFLAGS_gcc)
endif
# Set the toolchain specific `CFLAGS` for RISC-V. We use the same generic
# toolchain flags for each RISC-V variant.
override CFLAGS_rv32 += $(CFLAGS_toolchain_rv32)
override CFLAGS_rv32i += $(CFLAGS_rv32)
override CFLAGS_rv32imc += $(CFLAGS_rv32)
override CFLAGS_rv32imac += $(CFLAGS_rv32)
# Set the base `CPPFLAGS` for all RISC-V variants based on the toolchain family.
override CPPFLAGS_rv32 += \
$(CPPFLAGS_toolchain_rv32) \
-isystem $(NEWLIB_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/include \
-isystem $(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/include/c++/$(LIBCPP_VERSION_rv32) \
-isystem $(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/include/c++/$(LIBCPP_VERSION_rv32)/riscv64-unknown-elf
# Set the `CPPFLAGS` for RISC-V. Here we need different flags for different
# variants.
override CPPFLAGS_rv32i += $(CPPFLAGS_rv32) \
-march=rv32i\
-mabi=ilp32\
-mcmodel=medlow
override CPPFLAGS_rv32imc += $(CPPFLAGS_rv32) \
-march=rv32imc\
-mabi=ilp32\
-mcmodel=medlow
override CPPFLAGS_rv32imac += $(CPPFLAGS_rv32) \
-march=rv32imac\
-mabi=ilp32\
-mcmodel=medlow
# Set the base `WLFLAGS` linker flags for all RISC-V variants.
override WLFLAGS_rv32 += \
-Wl,--no-relax # Prevent use of global_pointer for RISC-V.
# Use the base linker flags for each RISC-V variant.
override WLFLAGS_rv32i += $(WLFLAGS_rv32)
override WLFLAGS_rv32imc += $(WLFLAGS_rv32)
override WLFLAGS_rv32imac += $(WLFLAGS_rv32)
override SYSTEM_LIBS_rv32i += \
$(NEWLIB_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32i/ilp32/libc.a \
$(NEWLIB_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32i/ilp32/libm.a
override SYSTEM_LIBS_CXX_rv32i += \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32i/ilp32/libstdc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32i/ilp32/libsupc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/lib/gcc/riscv64-unknown-elf/$(LIBCPP_VERSION_rv32)/rv32i/ilp32/libgcc.a
override SYSTEM_LIBS_rv32imc += \
$(NEWLIB_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32im/ilp32/libc.a \
$(NEWLIB_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32im/ilp32/libm.a
override SYSTEM_LIBS_CXX_rv32imc += \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32im/ilp32/libstdc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32im/ilp32/libsupc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/lib/gcc/riscv64-unknown-elf/$(LIBCPP_VERSION_rv32)/rv32im/ilp32/libgcc.a
override SYSTEM_LIBS_rv32imac += \
$(NEWLIB_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32imac/ilp32/libc.a \
$(NEWLIB_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32imac/ilp32/libm.a
override SYSTEM_LIBS_CXX_rv32imac += \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32imac/ilp32/libstdc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32imac/ilp32/libsupc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/lib/gcc/riscv64-unknown-elf/$(LIBCPP_VERSION_rv32)/rv32imac/ilp32/libgcc.a
################################################################################
##
## Cortex-M compiler/linker flags
##
################################################################################
# Setup the correct toolchain for each architecture. ARM has a standard
# toolchain we can use for every variant.
TOOLCHAIN_cortex-m := arm-none-eabi
TOOLCHAIN_cortex-m0 := $(TOOLCHAIN_cortex-m)
TOOLCHAIN_cortex-m3 := $(TOOLCHAIN_cortex-m)
TOOLCHAIN_cortex-m4 := $(TOOLCHAIN_cortex-m)
TOOLCHAIN_cortex-m7 := $(TOOLCHAIN_cortex-m)
# Setup the correct compiler. For cortex-m we only support GCC as it is the only
# toolchain with the PIC support we need for Tock userspace apps.
CC_cortex-m := -gcc
CC_cortex-m0 := $(CC_cortex-m)
CC_cortex-m3 := $(CC_cortex-m)
CC_cortex-m4 := $(CC_cortex-m)
CC_cortex-m7 := $(CC_cortex-m)
# Determine the version of the ARM compiler. This is used to select the version
# of the libgcc library that is compatible.
CC_cortex-m_version := $(shell $(TOOLCHAIN_cortex-m)$(CC_cortex-m) -dumpfullversion)
CC_cortex-m_version_major := $(shell echo $(CC_cortex-m_version) | cut -f1 -d.)
# Match compiler version to support libtock-newlib versions.
ifeq ($(CC_cortex-m_version_major),10)
NEWLIB_VERSION_cortex-m := 4.2.0.20211231
else ifeq ($(CC_cortex-m_version_major),11)
NEWLIB_VERSION_cortex-m := 4.2.0.20211231
else ifeq ($(CC_cortex-m_version_major),12)
NEWLIB_VERSION_cortex-m := 4.3.0.20230120
else ifeq ($(CC_cortex-m_version_major),13)
NEWLIB_VERSION_cortex-m := 4.3.0.20230120
else
NEWLIB_VERSION_cortex-m := 4.3.0.20230120
endif
NEWLIB_VERSION_cortex-m0 := $(NEWLIB_VERSION_cortex-m)
NEWLIB_VERSION_cortex-m3 := $(NEWLIB_VERSION_cortex-m)
NEWLIB_VERSION_cortex-m4 := $(NEWLIB_VERSION_cortex-m)
NEWLIB_VERSION_cortex-m7 := $(NEWLIB_VERSION_cortex-m)
NEWLIB_BASE_DIR_cortex-m := $(TOCK_USERLAND_BASE_DIR)/lib/libtock-newlib-$(NEWLIB_VERSION_cortex-m)
# Match compiler version to supported libtock-libc++ versions.
ifeq ($(CC_cortex-m_version_major),10)
LIBCPP_VERSION_cortex-m := 10.5.0
else ifeq ($(CC_cortex-m_version_major),11)
LIBCPP_VERSION_cortex-m := 10.5.0
else ifeq ($(CC_cortex-m_version_major),12)
LIBCPP_VERSION_cortex-m := 12.3.0
else ifeq ($(CC_cortex-m_version_major),13)
LIBCPP_VERSION_cortex-m := 13.2.0
else
LIBCPP_VERSION_cortex-m := 13.2.0
endif
LIBCPP_VERSION_cortex-m0 := $(LIBCPP_VERSION_cortex-m)
LIBCPP_VERSION_cortex-m3 := $(LIBCPP_VERSION_cortex-m)
LIBCPP_VERSION_cortex-m4 := $(LIBCPP_VERSION_cortex-m)
LIBCPP_VERSION_cortex-m7 := $(LIBCPP_VERSION_cortex-m)
LIBCPP_BASE_DIR_cortex-m := $(TOCK_USERLAND_BASE_DIR)/lib/libtock-libc++-$(LIBCPP_VERSION_cortex-m)
# Based on the toolchain used by each architecture, add in toolchain-specific
# flags. We assume that each architecture family uses the same toolchain.
ifeq ($(findstring -gcc,$(CC_cortex-m)),-gcc)
override CPPFLAGS_toolchain_cortex-m += $(CPPFLAGS_gcc)
override CFLAGS_toolchain_cortex-m += $(CFLAGS_gcc)
endif
override CFLAGS_cortex-m += $(CFLAGS_toolchain_cortex-m)
override CFLAGS_cortex-m0 += $(CFLAGS_cortex-m)
override CFLAGS_cortex-m3 += $(CFLAGS_cortex-m)
override CFLAGS_cortex-m4 += $(CFLAGS_cortex-m)
override CFLAGS_cortex-m7 += $(CFLAGS_cortex-m)
override CPPFLAGS_cortex-m += \
$(CPPFLAGS_toolchain_cortex-m)\
$(CPPFLAGS_PIC)\
-mthumb\
-mfloat-abi=soft\
-msingle-pic-base\
-mpic-register=r9\
-mno-pic-data-is-text-relative\
-isystem $(NEWLIB_BASE_DIR_cortex-m)/arm/arm-none-eabi/include\
-isystem $(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/include/c++/$(LIBCPP_VERSION_cortex-m)\
-isystem $(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/include/c++/$(LIBCPP_VERSION_cortex-m)/arm-none-eabi
# Work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85606
override CPPFLAGS_cortex-m0 += $(CPPFLAGS_cortex-m) \
-mcpu=cortex-m0\
-march=armv6s-m
override CPPFLAGS_cortex-m3 += $(CPPFLAGS_cortex-m) \
-mcpu=cortex-m3
override CPPFLAGS_cortex-m4 += $(CPPFLAGS_cortex-m) \
-mcpu=cortex-m4
override CPPFLAGS_cortex-m7 += $(CPPFLAGS_cortex-m) \
-mcpu=cortex-m7
override SYSTEM_LIBS_cortex-m0 += \
$(NEWLIB_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v6-m/nofp/libc.a \
$(NEWLIB_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v6-m/nofp/libm.a
override SYSTEM_LIBS_CXX_cortex-m0 += \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v6-m/nofp/libstdc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v6-m/nofp/libsupc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/lib/gcc/arm-none-eabi/$(LIBCPP_VERSION_cortex-m)/thumb/v6-m/nofp/libgcc.a
override SYSTEM_LIBS_cortex-m3 += \
$(NEWLIB_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7-m/nofp/libc.a \
$(NEWLIB_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7-m/nofp/libm.a
override SYSTEM_LIBS_CXX_cortex-m3 += \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7-m/nofp/libstdc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7-m/nofp/libsupc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/lib/gcc/arm-none-eabi/$(LIBCPP_VERSION_cortex-m)/thumb/v7-m/nofp/libgcc.a
override SYSTEM_LIBS_cortex-m4 += \
$(NEWLIB_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7e-m/nofp/libc.a \
$(NEWLIB_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7e-m/nofp/libm.a
override SYSTEM_LIBS_CXX_cortex-m4 += \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7e-m/nofp/libstdc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7e-m/nofp/libsupc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/lib/gcc/arm-none-eabi/$(LIBCPP_VERSION_cortex-m)/thumb/v7e-m/nofp/libgcc.a
override SYSTEM_LIBS_cortex-m7 += \
$(NEWLIB_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7e-m/nofp/libc.a \
$(NEWLIB_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7e-m/nofp/libm.a
override SYSTEM_LIBS_CXX_cortex-m7 += \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7e-m/nofp/libstdc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/thumb/v7e-m/nofp/libsupc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/lib/gcc/arm-none-eabi/$(LIBCPP_VERSION_cortex-m)/thumb/v7e-m/nofp/libgcc.a
# Cortex-M needs an additional OBJDUMP flag.
override OBJDUMP_FLAGS_cortex-m += --disassembler-options=force-thumb
override OBJDUMP_FLAGS_cortex-m7 += $(OBJDUMP_FLAGS_cortex-m)
override OBJDUMP_FLAGS_cortex-m4 += $(OBJDUMP_FLAGS_cortex-m)
override OBJDUMP_FLAGS_cortex-m3 += $(OBJDUMP_FLAGS_cortex-m)
override OBJDUMP_FLAGS_cortex-m0 += $(OBJDUMP_FLAGS_cortex-m)
################################################################################
# Extra warning flags not enabled by Wall or Wextra.
#
# I read through the gcc manual and grabbed the ones that I thought might be
# interesting / useful. Then I grabbed that snippet below to find other things
# that were left out of the manual that may be worth adding. Below are all
# warnings and a short description supported by (arm-none-eabi)-gcc as of
# v6.2.1.
#
# http://stackoverflow.com/questions/11714827/
# List all supported warnings and their status:
# gcc -Wall -Wextra -Q --help=warning
# Below are all warnings produced in an un-merged set of sorted lists
# broken into C/C++, C only, C++ only, other languages
#
# TODO(Pat) libnrfserialization noise with these, but I think they're useful
# and I want them back when I get a chance to clean that up.
#CPPFLAGS += -Wcast-qual # # const char* -> char*
#CPPFLAGS += -Wswitch-default # # switch w/out default (doesn't cover all cases) (maybe annoying?)
#CFLAGS += -Wstrict-prototypes # # function defined w/out specifying argument types
override CPPFLAGS += -Wdate-time # # warn if __TIME__, __DATE__, or __TIMESTAMP__ used
# ^on b/c flashing assumes same code => no flash, these enforce
override CPPFLAGS += -Wfloat-equal # # floats used with '=' operator, likely imprecise
override CPPFLAGS += -Wformat-nonliteral # # can't check format string (maybe disable if annoying)
override CPPFLAGS += -Wformat-security # # using untrusted format strings (maybe disable)
override CPPFLAGS += -Wformat-y2k # # use of strftime that assumes two digit years
override CPPFLAGS += -Winit-self # # { int i = i }
override CPPFLAGS += -Wmissing-declarations # # ^same? not sure how these differ
override CPPFLAGS += -Wmissing-field-initializers # if init'ing struct w/out field names, warn if not all used
override CPPFLAGS += -Wmissing-format-attribute # # something looks printf-like but isn't marked as such
override CPPFLAGS += -Wmissing-noreturn # # __attribute__((noreturn)) like -> ! in Rust, should use it
override CPPFLAGS += -Wmultichar # # use of 'foo' instead of "foo" (surpised not on by default?)
override CPPFLAGS += -Wpointer-arith # # sizeof things not define'd (i.e. sizeof(void))
override CPPFLAGS += -Wredundant-decls # # { int i; int i; } (a lint)
override CPPFLAGS += -Wshadow # # int foo(int a) { int a = 1; } inner a shadows outer a
override CPPFLAGS += -Wunused-macros # # macro defined in this file not used
override CPPFLAGS += -Wunused-parameter # # function parameter is unused aside from its declaration
override CPPFLAGS += -Wwrite-strings # # { char* c = "foo"; c[0] = 'b' } <-- "foo" should be r/o
override CPPFLAGS_gcc += -Wlogical-op # # "suspicious use of logical operators in expressions" (a lint)
override CPPFLAGS_gcc += -Wtrampolines # # attempt to generate a trampoline on the NX stack
#CPPFLAGS += -Wabi -Wabi-tag # inter-compiler abi issues
#CPPFLAGS += -Waggregate-return # warn if things return struct's
#CPPFLAGS += -Wcast-align # { char *c; int *i = (int*) c}, 1 byte -> 4 byte align
#CPPFLAGS += -Wconversion # implicit conversion that may unexpectedly alter value
# ^ A ton of these from syscalls I think, XXX look later
#CPPFLAGS += -Wdisabled-optimization # gcc skipped an optimization for any of a thousand reasons
#CPPFLAGS += -Wdouble-promotion # warn if float -> double implicitly XXX maybe?
#CPPFLAGS += -Wformat-signedness # # { int i; printf("%d %u", i, i) } second bad (maybe annoying?)
# ^ Too obnoxious when you want hex of an int
#CPPFLAGS += -Wfloat-conversion # subset of -Wconversion
#CPPFLAGS += -Winline # something marked `inline` wasn't inlined
#CPPFLAGS += -Winvalid-pch # bad precompiled header found in an include dir
#CPPFLAGS += -Wmissing-include-dirs -- XXX Didn't try, afriad could be annoying
#CPPFLAGS += -Woverlength-strings # complier compat: strings > [509 C90, 4095 C99] chars
#CPPFLAGS += -Wpacked # struct with __attribute__((packed)) that does nothing
#CPPFLAGS += -Wpadded # padding added to a struct. Noisy for argument structs
#CPPFLAGS += -Wpedantic # strict ISO C/C++
#CPPFLAGS += -Wsign-conversion # implicit integer sign conversions, part of -Wconversion
#CPPFLAGS += -Wstack-protector # only if -fstack-protector, on by default, warn fn not protect
#CPPFLAGS += -Wsuggest-attribute=const # does what it sounds like - removed due to noise
#CPPFLAGS += -Wsuggest-attribute=pure # does what it sounds like - removed due to noise
#CPPFLAGS += -Wswitch-enum # # switch of enum doesn't explicitly cover all cases
# ^ annoying in practice, let default: do its job
#CPPFLAGS += -Wsystem-headers # warnings from system headers
#CPPFLAGS += -Wtraditional # stuff gcc allows that "traditional" C doesn't
#CPPFLAGS += -Wundef # undefined identifier is evaluated in an `#if' directive
# ^ Lots of library #if SAMD || SMAR21 stuff
# Should probably be ifdef, but too much noise
#CPPFLAGS += -Wunsafe-loop-optimizations # compiler can't divine loop bounds XXX maybe interesting?
#CPPFLAGS += -Wvariadic-macros # can't be used in ISO C
#CPPFLAGS += -Wvector-operation-performance # perf option not appropriate for these systems
#CPPFLAGS += -Wvla -- XXX Didn't try, but interested
# C-only warnings
override CFLAGS += -Wbad-function-cast # # not obvious when this would trigger, could drop if annoying
override CFLAGS += -Wmissing-prototypes # # global fn defined w/out prototype (should be static or in .h)
override CFLAGS += -Wnested-externs # # mis/weird-use of extern keyword
override CFLAGS += -Wold-style-definition # # this garbage: void bar (a) int a; { }
override CFLAGS_gcc += -Wjump-misses-init # # goto or switch skips over a variable initialization
#CFLAGS += -Wunsuffixed-float-constants # # { float f=0.67; if(f==0.67) printf("y"); else printf("n"); } => n
# ^ doesn't seem to work right? find_north does funny stuff
#CFLAGS += -Wtraditional-conversion # # prototype causes a conversion different than w/o prototype (?)
# ^ real noisy
# CXX-only warnings
override CXXFLAGS += -Wctor-dtor-privacy # # unusable class b/c everything private and no friends
override CXXFLAGS += -Wdelete-non-virtual-dtor # # catches undefined behavior
override CXXFLAGS += -Wold-style-cast # # C-style cast in C++ code
override CXXFLAGS += -Woverloaded-virtual # # subclass shadowing makes parent impl's unavailable
override CXXFLAGS += -Wsign-promo # # gcc did what spec requires, but probably not what you want
override CXXFLAGS += -Wstrict-null-sentinel # # seems like a not-very-C++ thing to do? very unsure
override CXXFLAGS += -Wsuggest-final-methods # # does what it sounds like
override CXXFLAGS += -Wsuggest-final-types # # does what it sounds like
override CXXFLAGS += -Wsuggest-override # # overridden virtual func w/out override keyword
override CXXFLAGS += -Wuseless-cast # # pretty much what ya think here
override CXXFLAGS += -Wzero-as-null-pointer-constant # use of 0 as NULL
# -Wc++-compat # # C/C++ compat issues
# -Wc++11-compat # # C11 compat issues
# -Wc++14-compat # # C14 compat issues
# -Wconditionally-supported # # conditionally-supported (C++11 [intro.defs]) constructs (?)
# -Weffc++ # violations of style guidelines from Meyers' Effective C++ books
# -Wmultiple-inheritance # used to enforce coding conventions, does what you'd think
# -Wnamespaces # used to enforce coding conventions, warn if namespace opened
# -Wnoexcept # # (?) I think warns if missing noexcept
# -Wnon-virtual-dtor # # something deeply c++, part of effc++
# -Wsynth # legacy flag, g++ != cfront
# -Wtemplates # used to enforce coding conventions, warn if new template
# -Wvirtual-inheritance # used to enforce coding conventions, does what you'd think
# Fortran-only warnings
# -Waliasing
# -Wampersand
# -Warray-temporaries
# -Wc-binding-type
# -Wcharacter-truncation
# -Wcompare-reals
# -Wconversion-extra
# -Wfunction-elimination
# -Wimplicit-interface
# -Wimplicit-procedure
# -Winteger-division
# -Wintrinsic-shadow
# -Wintrinsics-std
# -Wreal-q-constant
# -Wrealloc-lhs
# -Wrealloc-lhs-all
# -Wsurprising
# -Wtabs
# -Wtarget-lifetime
# -Wunused-dummy-argument
# -Wuse-without-only
# Objective-C(++)-only
# -Wassign-intercept
# -Wselector
# -Wstrict-selector-match
# -Wundeclared-selector
# END WARNINGS
################################################################################
# C/C++ Linter configuration
UNCRUSTIFY := $(TOCK_USERLAND_BASE_DIR)/tools/uncrustify/uncrustify.sh
# Dump configuration for verbose builds
ifneq ($(V),)
$(info )
$(info **************************************************)
$(info TOCK USERLAND BUILD SYSTEM -- VERBOSE BUILD)
$(info **************************************************)
$(info Config:)
$(info GIT: $(shell git describe --always 2>&1))
$(info $(TOOLCHAIN_cortex-m4)$(CC_cortex-m4) --version: $(shell $(TOOLCHAIN_cortex-m4)$(CC_cortex-m4) --version))
$(info $(TOOLCHAIN_rv32i)$(CC_rv32i) --version: $(shell $(TOOLCHAIN_rv32i)$(CC_rv32i) --version))
$(info LAYOUT=$(LAYOUT))
$(info MAKEFLAGS=$(MAKEFLAGS))
$(info PACKAGE_NAME=$(PACKAGE_NAME))
$(info TOCK_ARCHS=$(TOCK_ARCHS))
$(info TOCK_TARGETS=$(TOCK_TARGETS))
$(info TOCK_USERLAND_BASE_DIR=$(TOCK_USERLAND_BASE_DIR))
$(info TOOLCHAIN=$(TOOLCHAIN))
$(info **************************************************)
$(info )
endif
endif