test
3.13 KB
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
#!/usr/bin/env python3
import os
import sys
import time
import subprocess
import serial.tools.list_ports
from test_common import (
DeviceUnderTestAeadUARTP,
eprint,
FileMutex,
run_nist_lws_aead_test,
)
def get_serial():
ports = serial.tools.list_ports.comports()
devices = [
p.device
for p in ports
if (p.vid == 4292 and p.pid == 60000)
]
devices.sort()
return devices[0]
class ESP32(DeviceUnderTestAeadUARTP):
def __init__(self, build_dir):
DeviceUnderTestAeadUARTP.__init__(self)
self.uart_device = get_serial()
devname = os.path.basename(self.uart_device)
self.lock = FileMutex('/var/lock/lwc-compare.%s.lock' % devname)
self.build_dir = build_dir
self.template_path = os.path.dirname(sys.argv[0])
self.pio_packages_path = "/home/tester/.platformio/packages/"
self.esptoolpy_path = os.path.join(
self.pio_packages_path, "tool-esptoolpy/esptool.py")
self.partitionspath = os.path.join(build_dir, 'partitions.bin')
self.firmware_path = os.path.join(build_dir, 'firmware.bin')
# Convert elf to bin
cmd = ['python3', self.esptoolpy_path]
cmd += ['--chip', 'esp32']
cmd += ['elf2image', os.path.join(build_dir, 'firmware.elf')]
subprocess.check_call(cmd)
def firmware_size(self):
return os.stat(self.firmware_path).st_size
def reset(self):
self.ser.setDTR(False) # IO0=HIGH
self.ser.setRTS(True) # EN=LOW, chip in reset1
time.sleep(0.1)
self.ser.setDTR(False) # IO0=HIGH
self.ser.setRTS(False) # EN=HIGH, chip out of reset
time.sleep(1)
def flash(self):
arduinoespressif32_path = os.path.join(
self.pio_packages_path, "framework-arduinoespressif32/")
boot_app0_path = os.path.join(
arduinoespressif32_path,
"tools/partitions/boot_app0.bin")
bootloader_path = os.path.join(
arduinoespressif32_path,
"tools/sdk/bin/bootloader_dio_80m.bin")
partitions = [
(0xe000, boot_app0_path),
(0x1000, bootloader_path),
(0x10000, self.firmware_path),
(0x8000, self.partitionspath)
]
cmd = ['python3', self.esptoolpy_path]
cmd += ['--chip', 'esp32']
cmd += ['--before', 'default_reset', '--after', 'hard_reset']
cmd += ['--port', self.uart_device]
cmd += ['write_flash', '-z']
for addr, path in partitions:
cmd += ['0x%x' % addr, path]
subprocess.check_call(cmd)
eprint("Firmware flashed.")
self.ser = serial.Serial(
self.uart_device,
baudrate=500000,
timeout=5)
self.reset()
def dump_ram(self):
return None
def main(argv):
if len(argv) != 2:
print("Usage: test build_dir")
return 1
build_dir = argv[1]
kat_path = os.path.join(build_dir, 'LWC_AEAD_KAT.txt')
dut = ESP32(build_dir)
run_nist_lws_aead_test(dut, kat_path, build_dir, 0x0020)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))