-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_arm
82 lines (71 loc) · 1.96 KB
/
env_arm
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
import os
CORE = "cortex-m4"
OPTIMIZATION_LEVEL = "s"
"""
Define build environment
References:
- https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
"""
env_arm = Environment(
ENV=os.environ,
tools=["mingw"],
CC="arm-none-eabi-gcc",
OBJCOPY="arm-none-eabi-objcopy",
OBJDUMP="arm-none-eabi-objdump",
SIZE="arm-none-eabi-size",
CFLAGS=[
"-std=c99",
"-fmessage-length=0",
"-ffunction-sections",
"-fdata-sections",
],
ASFLAGS=[],
LINKFLAGS=[
"-nostartfiles",
"-specs=nano.specs",
"-u", "_printf_float",
"-u", "_scanf_float",
"-specs=nosys.specs",
"-Wl,--gc-sections",
],
CPPPATH=[],
CPPDEFINES=[],
LIBS=[
"m",
]
)
""" Define additional flags """
COMMON_FLAGS = [
"-O{}".format(OPTIMIZATION_LEVEL),
"-mcpu={}".format(CORE),
"-mthumb",
"-mfloat-abi=hard",
"-mfpu=auto",
"-Wall",
"-g",
"-pipe",
]
env_arm["CFLAGS"].extend(COMMON_FLAGS)
env_arm["LINKFLAGS"].extend(COMMON_FLAGS)
"""
Define builders
References:
- https://sourceware.org/binutils/docs/binutils/objcopy.html
- https://sourceware.org/binutils/docs/binutils/objdump.html
- https://sourceware.org/binutils/docs/binutils/size.html
"""
def objcopy_generator(source, target, env, for_signature):
"""
:raise: KeyError if target format is not supported.
"""
file_basename, file_ext = os.path.splitext(target[0].name)
file_ext = file_ext.lstrip(".") # Strip leading '.' if any (i.e. ".hex" -> "hex")
ext_fmt_map = {
"bin": "binary",
"hex": "ihex",
}
return "$OBJCOPY -O {} $SOURCE $TARGET".format(ext_fmt_map[file_ext])
env_arm["BUILDERS"]["Objcopy"] = Builder(generator=objcopy_generator)
env_arm["BUILDERS"]["Objdump"] = Builder(action="$OBJDUMP --source --all-headers --demangle --line-numbers --wide $SOURCE > $TARGET")
env_arm["BUILDERS"]["Size"] = Builder(action="$SIZE --format=berkeley $SOURCE")
Export("env_arm")