Skip to content

Commit 2f80001

Browse files
Run formatter on everything else
1 parent 7bf224c commit 2f80001

28 files changed

+1120
-978
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
#file which is invoked by the cmake build system to check if all necessary python packages are installed.
4+
# file which is invoked by the cmake build system to check if all necessary python packages are installed.
55

66
import sys
77

@@ -10,4 +10,4 @@
1010
except ImportError:
1111
exit(1)
1212

13-
exit(0)
13+
exit(0)

tools/debug_tools/crash_log_parser/crash_log_parser.py

Lines changed: 89 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -25,68 +25,72 @@
2525
from subprocess import check_output
2626
import sys
2727

28-
#arm-none-eabi-nm -nl <elf file>
28+
# arm-none-eabi-nm -nl <elf file>
2929
_NM_EXEC = "arm-none-eabi-nm"
3030
_OPT = "-nlC"
3131
_PTN = re.compile("([0-9a-f]*) ([Tt]) ([^\t\n]*)(?:\t(.*):([0-9]*))?")
3232

33+
3334
class ElfHelper(object):
3435
def __init__(self, elf_file, map_file):
35-
36-
op = check_output([_NM_EXEC, _OPT, elf_file.name]).decode('utf-8')
36+
op = check_output([_NM_EXEC, _OPT, elf_file.name]).decode("utf-8")
3737
self.maplines = map_file.readlines()
3838
self.matches = _PTN.findall(op)
3939
self.addrs = [int(x[0], 16) for x in self.matches]
40-
40+
4141
def function_addrs(self):
4242
return self.addrs
43-
43+
4444
def function_name_for_addr(self, addr):
4545
i = bisect.bisect_right(self.addrs, addr)
46-
funcname = self.matches[i-1][2]
46+
funcname = self.matches[i - 1][2]
4747
return funcname
4848

49+
4950
def print_HFSR_info(hfsr):
5051
if int(hfsr, 16) & 0x80000000:
5152
print("\t\tDebug Event Occurred")
5253
if int(hfsr, 16) & 0x40000000:
53-
print("\t\tForced exception, a fault with configurable priority has been escalated to HardFault")
54+
print("\t\tForced exception, a fault with configurable priority has been escalated to HardFault")
5455
if int(hfsr, 16) & 0x2:
55-
print("\t\tVector table read fault has occurred")
56+
print("\t\tVector table read fault has occurred")
5657

57-
def print_MMFSR_info(mmfsr, mmfar):
58+
59+
def print_MMFSR_info(mmfsr, mmfar):
5860
if int(mmfsr, 16) & 0x20:
5961
print("\t\tA MemManage fault occurred during FP lazy state preservation")
6062
if int(mmfsr, 16) & 0x10:
61-
print("\t\tA derived MemManage fault occurred on exception entry")
63+
print("\t\tA derived MemManage fault occurred on exception entry")
6264
if int(mmfsr, 16) & 0x8:
63-
print("\t\tA derived MemManage fault occurred on exception return")
65+
print("\t\tA derived MemManage fault occurred on exception return")
6466
if int(mmfsr, 16) & 0x2:
6567
if int(mmfsr, 16) & 0x80:
66-
print("\t\tData access violation. Faulting address: %s"%(str(mmfar)))
67-
else:
68-
print("\t\tData access violation. WARNING: Fault address in MMFAR is NOT valid")
68+
print("\t\tData access violation. Faulting address: %s" % (str(mmfar)))
69+
else:
70+
print("\t\tData access violation. WARNING: Fault address in MMFAR is NOT valid")
6971
if int(mmfsr, 16) & 0x1:
70-
print("\t\tMPU or Execute Never (XN) default memory map access violation on an instruction fetch has occurred")
71-
72+
print("\t\tMPU or Execute Never (XN) default memory map access violation on an instruction fetch has occurred")
73+
74+
7275
def print_BFSR_info(bfsr, bfar):
7376
if int(bfsr, 16) & 0x20:
7477
print("\t\tA bus fault occurred during FP lazy state preservation")
7578
if int(bfsr, 16) & 0x10:
76-
print("\t\tA derived bus fault has occurred on exception entry")
79+
print("\t\tA derived bus fault has occurred on exception entry")
7780
if int(bfsr, 16) & 0x8:
78-
print("\t\tA derived bus fault has occurred on exception return")
81+
print("\t\tA derived bus fault has occurred on exception return")
7982
if int(bfsr, 16) & 0x4:
80-
print("\t\tImprecise data access error has occurred")
83+
print("\t\tImprecise data access error has occurred")
8184
if int(bfsr, 16) & 0x2:
82-
if int(bfsr,16) & 0x80:
83-
print("\t\tA precise data access error has occurred. Faulting address: %s"%(str(bfar)))
84-
else:
85-
print("\t\tA precise data access error has occurred. WARNING: Fault address in BFAR is NOT valid")
85+
if int(bfsr, 16) & 0x80:
86+
print("\t\tA precise data access error has occurred. Faulting address: %s" % (str(bfar)))
87+
else:
88+
print("\t\tA precise data access error has occurred. WARNING: Fault address in BFAR is NOT valid")
8689
if int(bfsr, 16) & 0x1:
87-
print("\t\tA bus fault on an instruction prefetch has occurred")
90+
print("\t\tA bus fault on an instruction prefetch has occurred")
91+
8892

89-
def print_UFSR_info(ufsr):
93+
def print_UFSR_info(ufsr):
9094
if int(ufsr, 16) & 0x200:
9195
print("\t\tDivide by zero error has occurred")
9296
if int(ufsr, 16) & 0x100:
@@ -96,100 +100,120 @@ def print_UFSR_info(ufsr):
96100
if int(ufsr, 16) & 0x4:
97101
print("\t\tAn integrity check error has occurred on EXC_RETURN")
98102
if int(ufsr, 16) & 0x2:
99-
print("\t\tInstruction executed with invalid EPSR.T or EPSR.IT field( This may be caused by Thumb bit not being set in branching instruction )")
103+
print(
104+
"\t\tInstruction executed with invalid EPSR.T or EPSR.IT field( This may be caused by Thumb bit not being set in branching instruction )"
105+
)
100106
if int(ufsr, 16) & 0x1:
101-
print("\t\tThe processor has attempted to execute an undefined instruction")
102-
103-
def print_CPUID_info(cpuid):
107+
print("\t\tThe processor has attempted to execute an undefined instruction")
108+
109+
110+
def print_CPUID_info(cpuid):
104111
if (int(cpuid, 16) & 0xF0000) == 0xC0000:
105112
print("\t\tProcessor Arch: ARM-V6M")
106-
else:
113+
else:
107114
print("\t\tProcessor Arch: ARM-V7M or above")
108-
109-
print("\t\tProcessor Variant: %X" % ((int(cpuid,16) & 0xFFF0 ) >> 4))
115+
116+
print("\t\tProcessor Variant: %X" % ((int(cpuid, 16) & 0xFFF0) >> 4))
117+
110118

111119
def parse_line_for_register(line):
112120
_, register_val = line.split(":")
113-
return register_val.strip()
121+
return register_val.strip()
122+
114123

115124
def main(crash_log, elfhelper):
116125
mmfar_val = 0
117126
bfar_val = 0
118-
lines = iter(crash_log.read().decode('utf-8').splitlines())
127+
lines = iter(crash_log.read().decode("utf-8").splitlines())
119128

120129
for eachline in lines:
121130
if "++ MbedOS Fault Handler ++" in eachline:
122131
break
123132
else:
124-
print("ERROR: Unable to find \"MbedOS Fault Handler\" header")
133+
print('ERROR: Unable to find "MbedOS Fault Handler" header')
125134
return
126-
135+
127136
for eachline in lines:
128137
if "-- MbedOS Fault Handler --" in eachline:
129138
break
130-
139+
131140
elif eachline.startswith("PC"):
132141
pc_val = parse_line_for_register(eachline)
133142
if elfhelper:
134143
pc_name = elfhelper.function_name_for_addr(int(pc_val, 16))
135144
else:
136145
pc_name = "<unknown-symbol>"
137-
146+
138147
elif eachline.startswith("LR"):
139148
lr_val = parse_line_for_register(eachline)
140149
if elfhelper:
141150
lr_name = elfhelper.function_name_for_addr(int(lr_val, 16))
142151
else:
143152
lr_name = "<unknown-symbol>"
144-
153+
145154
elif eachline.startswith("SP"):
146155
sp_val = parse_line_for_register(eachline)
147-
156+
148157
elif eachline.startswith("HFSR"):
149158
hfsr_val = parse_line_for_register(eachline)
150-
159+
151160
elif eachline.startswith("MMFSR"):
152161
mmfsr_val = parse_line_for_register(eachline)
153-
162+
154163
elif eachline.startswith("BFSR"):
155164
bfsr_val = parse_line_for_register(eachline)
156-
165+
157166
elif eachline.startswith("UFSR"):
158167
ufsr_val = parse_line_for_register(eachline)
159-
168+
160169
elif eachline.startswith("CPUID"):
161170
cpuid_val = parse_line_for_register(eachline)
162-
171+
163172
elif eachline.startswith("MMFAR"):
164173
mmfar_val = parse_line_for_register(eachline)
165-
174+
166175
elif eachline.startswith("BFAR"):
167-
bfar_val = parse_line_for_register(eachline)
168-
169-
print("\nCrash Info:")
176+
bfar_val = parse_line_for_register(eachline)
177+
178+
print("\nCrash Info:")
170179
print("\tCrash location = %s [0x%s] (based on PC value)" % (pc_name.strip(), str(pc_val)))
171-
print("\tCaller location = %s [0x%s] (based on LR value)" % (lr_name.strip(), str(lr_val)))
180+
print("\tCaller location = %s [0x%s] (based on LR value)" % (lr_name.strip(), str(lr_val)))
172181
print("\tStack Pointer at the time of crash = [%s]" % (str(sp_val)))
173-
182+
174183
print("\tTarget and Fault Info:")
175184
print_CPUID_info(cpuid_val)
176185
print_HFSR_info(hfsr_val)
177186
print_MMFSR_info(mmfsr_val, mmfar_val)
178187
print_BFSR_info(bfsr_val, bfar_val)
179188
print_UFSR_info(ufsr_val)
180-
181-
182-
if __name__ == '__main__':
189+
190+
191+
if __name__ == "__main__":
183192
import argparse
184-
185-
parser = argparse.ArgumentParser(description='Analyse mbed-os crash log. This tool requires arm-gcc binary utilities to be available in current path as it uses \'nm\' command')
193+
194+
parser = argparse.ArgumentParser(
195+
description="Analyse mbed-os crash log. This tool requires arm-gcc binary utilities to be available in current path as it uses 'nm' command"
196+
)
186197
# specify arguments
187-
parser.add_argument(metavar='CRASH LOG', type=argparse.FileType('rb', 0),
188-
dest='crashlog',help='path to crash log file')
189-
parser.add_argument(metavar='ELF FILE', type=argparse.FileType('rb', 0),
190-
nargs='?',const=None,dest='elffile',help='path to elf file')
191-
parser.add_argument(metavar='MAP FILE', type=argparse.FileType('rb', 0),
192-
nargs='?',const=None,dest='mapfile',help='path to map file')
198+
parser.add_argument(
199+
metavar="CRASH LOG", type=argparse.FileType("rb", 0), dest="crashlog", help="path to crash log file"
200+
)
201+
parser.add_argument(
202+
metavar="ELF FILE",
203+
type=argparse.FileType("rb", 0),
204+
nargs="?",
205+
const=None,
206+
dest="elffile",
207+
help="path to elf file",
208+
)
209+
parser.add_argument(
210+
metavar="MAP FILE",
211+
type=argparse.FileType("rb", 0),
212+
nargs="?",
213+
const=None,
214+
dest="mapfile",
215+
help="path to map file",
216+
)
193217

194218
# get and validate arguments
195219
args = parser.parse_args()
@@ -200,14 +224,13 @@ def main(crash_log, elfhelper):
200224
else:
201225
print("ELF or MAP file missing, logging raw values.")
202226
elfhelper = None
203-
227+
204228
# parse input and write to output
205229
main(args.crashlog, elfhelper)
206-
207-
#close all files
230+
231+
# close all files
208232
if args.elffile:
209233
args.elffile.close()
210234
if args.mapfile:
211235
args.mapfile.close()
212236
args.crashlog.close()
213-

tools/psa/tfm/bin_utils/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@
1616

1717
from .assemble import Assembly
1818

19-
__all__ = [
20-
'Assembly'
21-
]
19+
__all__ = ["Assembly"]

tools/psa/tfm/bin_utils/assemble.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
offset_re = re.compile(r"^\s*RE_([0-9A-Z_]+)_IMAGE_OFFSET\s*=\s*(.*)")
3333
size_re = re.compile(r"^\s*RE_([0-9A-Z_]+)_IMAGE_MAX_SIZE\s*=\s*(.*)")
3434

35-
class Assembly():
35+
36+
class Assembly:
3637
def __init__(self, layout_path, output):
3738
self.output = output
3839
self.layout_path = layout_path
@@ -50,46 +51,44 @@ def find_slots(self):
5051
offsets = macro_parser.evaluate_macro(self.layout_path, offset_re, 1, 2)
5152
sizes = macro_parser.evaluate_macro(self.layout_path, size_re, 1, 2)
5253

53-
if 'SECURE' not in offsets:
54+
if "SECURE" not in offsets:
5455
raise Exception("Image config does not have secure partition")
5556

56-
if 'NON_SECURE' not in offsets:
57+
if "NON_SECURE" not in offsets:
5758
raise Exception("Image config does not have non-secure partition")
5859

5960
self.offsets = offsets
6061
self.sizes = sizes
6162

6263
def add_image(self, source, partition):
63-
with open(self.output, 'ab') as ofd:
64+
with open(self.output, "ab") as ofd:
6465
ofd.seek(0, os.SEEK_END)
6566
pos = ofd.tell()
6667
if pos > self.offsets[partition]:
6768
raise Exception("Partitions not in order, unsupported")
6869
if pos < self.offsets[partition]:
69-
ofd.write(b'\xFF' * (self.offsets[partition] - pos))
70+
ofd.write(b"\xff" * (self.offsets[partition] - pos))
7071
statinfo = os.stat(source)
7172
if statinfo.st_size > self.sizes[partition]:
7273
raise Exception("Image {} is too large for partition".format(source))
73-
with open(source, 'rb') as rfd:
74+
with open(source, "rb") as rfd:
7475
shutil.copyfileobj(rfd, ofd, 0x10000)
7576

77+
7678
def main():
7779
parser = argparse.ArgumentParser()
7880

79-
parser.add_argument('-l', '--layout', required=True,
80-
help='Location of the file that contains preprocessed macros')
81-
parser.add_argument('-s', '--secure', required=True,
82-
help='Unsigned secure image')
83-
parser.add_argument('-n', '--non_secure',
84-
help='Unsigned non-secure image')
85-
parser.add_argument('-o', '--output', required=True,
86-
help='Filename to write full image to')
81+
parser.add_argument("-l", "--layout", required=True, help="Location of the file that contains preprocessed macros")
82+
parser.add_argument("-s", "--secure", required=True, help="Unsigned secure image")
83+
parser.add_argument("-n", "--non_secure", help="Unsigned non-secure image")
84+
parser.add_argument("-o", "--output", required=True, help="Filename to write full image to")
8785

8886
args = parser.parse_args()
8987
output = Assembly(args.layout, args.output)
9088

9189
output.add_image(args.secure, "SECURE")
9290
output.add_image(args.non_secure, "NON_SECURE")
9391

94-
if __name__ == '__main__':
92+
93+
if __name__ == "__main__":
9594
main()

tools/psa/tfm/bin_utils/imgtool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818

1919
from imgtool import main
2020

21-
if __name__ == '__main__':
21+
if __name__ == "__main__":
2222
main.imgtool()

tools/psa/tfm/bin_utils/imgtool/boot_record.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ class SwComponent(int, Enum):
2424
Software component property IDs specified by
2525
Arm's PSA Attestation API 1.0 document.
2626
"""
27+
2728
TYPE = 1
2829
MEASUREMENT_VALUE = 2
2930
VERSION = 4
3031
SIGNER_ID = 5
3132
MEASUREMENT_DESCRIPTION = 6
3233

3334

34-
def create_sw_component_data(sw_type, sw_version, sw_measurement_description,
35-
sw_measurement_value, sw_signer_id):
36-
35+
def create_sw_component_data(sw_type, sw_version, sw_measurement_description, sw_measurement_value, sw_signer_id):
3736
# List of software component properties (Key ID + value)
3837
properties = {
3938
SwComponent.TYPE: sw_type,

0 commit comments

Comments
 (0)