Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lwc
/
compare
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
30d6aa6a
authored
Jul 26, 2019
by
Enrico Pozzobon
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'measure-ram'
parents
37b488e1
b11a94d8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
19 deletions
+82
-19
templates/f7/flash.jlink
+0
-7
templates/f7/ram_pattern.bin
+0
-0
templates/f7/test
+72
-12
test.py
+10
-0
No files found.
templates/f7/flash.jlink
deleted
100644 → 0
View file @
37b488e1
if SWD
speed 4000
device STM32F746ZG
loadbin build/f7.bin 0x8000000
r
g
exit
templates/f7/ram_pattern.bin
0 → 100644
View file @
30d6aa6a
File added
templates/f7/test
View file @
30d6aa6a
...
...
@@ -8,17 +8,52 @@ import serial
import
subprocess
RAM_SIZE
=
0x50000
def
eprint
(
*
args
,
**
kargs
):
print
(
*
args
,
file
=
sys
.
stderr
,
**
kargs
)
def
flash
():
def
popen_jlink
():
pipe
=
subprocess
.
PIPE
cmd
=
[
'JLinkExe'
,
'flash.jlink'
]
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
sys
.
stderr
,
stdin
=
pipe
)
stdout
,
stderr
=
p
.
communicate
(
""
)
cmd
=
[
'JLinkExe'
]
cmd
.
extend
([
'-autoconnect'
,
'1'
])
cmd
.
extend
([
'-device'
,
'STM32F746ZG'
])
cmd
.
extend
([
'-if'
,
'swd'
])
cmd
.
extend
([
'-speed'
,
'4000'
])
return
subprocess
.
Popen
(
cmd
,
stdout
=
sys
.
stderr
,
stdin
=
pipe
)
def
flash
():
p
=
popen_jlink
()
return
p
.
communicate
((
"""
loadbin build/f7.bin 0x8000000
r
g
exit
"""
)
.
encode
(
'ascii'
))
def
fill_ram
():
p
=
popen_jlink
()
return
p
.
communicate
((
"""
h
loadbin ram_pattern.bin 0x20000000
savebin ram_copy.bin 0x20000000 0x
%
x
r
g
exit
"""
%
RAM_SIZE
)
.
encode
(
'ascii'
))
def
dump_ram
():
p
=
popen_jlink
()
return
p
.
communicate
((
"""
h
savebin ram_dump.bin 0x20000000 0x
%
x
exit
"""
%
RAM_SIZE
)
.
encode
(
'ascii'
))
def
get_serial
():
import
serial.tools.list_ports
...
...
@@ -113,16 +148,10 @@ def main(argv):
uartp
=
UARTP
(
ser
)
flash
()
fill_ram
()
eprint
(
"Flashed"
)
time
.
sleep
(
0.1
)
ser
.
setDTR
(
False
)
# IO0=HIGH
ser
.
setRTS
(
True
)
# EN=LOW, chip in reset
time
.
sleep
(
0.1
)
ser
.
setDTR
(
False
)
# IO0=HIGH
ser
.
setRTS
(
False
)
# EN=HIGH, chip out of reset
time
.
sleep
(
1
)
def
stdin_read
(
n
):
b
=
sys
.
stdin
.
buffer
.
read
(
n
)
if
len
(
b
)
!=
n
:
...
...
@@ -176,6 +205,37 @@ def main(argv):
raise
Exception
(
"Unacknowledged variable transfer"
)
eprint
(
"Operation
%
c completed successfully"
%
action
)
elif
action
in
b
"u"
:
dump_ram
()
with
open
(
"ram_copy.bin"
,
'rb'
)
as
dump
:
dump_a
=
dump
.
read
()
with
open
(
"ram_dump.bin"
,
'rb'
)
as
dump
:
dump_b
=
dump
.
read
()
if
len
(
dump_a
)
!=
RAM_SIZE
or
len
(
dump_b
)
!=
RAM_SIZE
:
raise
Exception
(
"Wrong dump sizes: 0x
%
x, 0x
%
x"
%
(
len
(
dump_a
),
len
(
dump_b
)))
streaks
=
[]
streak_beg
=
0
streak_end
=
0
for
i
in
range
(
len
(
dump_a
)):
if
dump_a
[
i
]
==
dump_b
[
i
]:
streak_end
=
i
else
:
if
streak_end
!=
streak_beg
:
streaks
.
append
((
streak_beg
,
streak_end
))
streak_beg
=
i
streak_end
=
i
for
b
,
e
in
streaks
:
eprint
(
"equal bytes from 0x
%
x to 0x
%
x (length:
%
d)"
%
(
b
,
e
,
e
-
b
))
b
,
e
=
max
(
streaks
,
key
=
lambda
a
:
a
[
1
]
-
a
[
0
])
eprint
(
"longest equal bytes streak from 0x
%
x to 0x
%
x (length:
%
d)"
%
(
b
,
e
,
e
-
b
))
v
=
struct
.
pack
(
"<II"
,
4
,
e
-
b
)
sys
.
stdout
.
buffer
.
write
(
v
)
sys
.
stdout
.
flush
()
else
:
raise
Exception
(
"Unknown action
%
c"
%
action
)
...
...
test.py
View file @
30d6aa6a
...
...
@@ -6,6 +6,8 @@ import sys
import
struct
from
subprocess
import
Popen
,
PIPE
MEASURE_TIME
=
True
MEASURE_RAM
=
False
def
main
(
argv
):
if
len
(
argv
)
<
3
:
...
...
@@ -16,10 +18,12 @@ def main(argv):
for
attempt
in
range
(
3
):
print
(
"beginning test
%
d of '
%
s' using test vectors '
%
s'"
%
(
attempt
,
' '
.
join
(
cmd
),
argv
[
1
]))
try
:
if
MEASURE_TIME
:
measurements
=
begin_measurement
()
try
:
test
(
argv
[
1
],
cmd
)
finally
:
if
MEASURE_TIME
:
end_measurement
(
measurements
)
print
(
"TEST SUCCESSFUL"
)
return
0
...
...
@@ -115,6 +119,12 @@ def test(test_file, cmd):
if
m
!=
output
:
raise
Exception
(
"output of encryption is different from expected ciphertext"
)
if
MEASURE_RAM
:
write
(
b
'u'
)
output
=
obtain
()
print
(
" untouched memory =
%
d"
%
struct
.
unpack
(
"<I"
,
output
))
break
elif
res
is
not
None
:
if
res
[
1
]
.
lower
()
==
'count'
:
i
=
int
(
res
[
2
],
10
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment