Skip to content

Commit 3a719de

Browse files
committed
Added configuration script for provisioning blank devices
1 parent 99d9498 commit 3a719de

File tree

3 files changed

+181
-4
lines changed

3 files changed

+181
-4
lines changed

scripts/at_config.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/usr/bin/env python
2+
import hid
3+
import argparse
4+
from at_kit_base import *
5+
import base64
6+
7+
# Default configuration for ATECC508A
8+
atecc508_config = bytearray.fromhex(
9+
'B0 00 55 00 8F 20 C4 44 87 20 87 20 8F 0F C4 36'
10+
'9F 0F 82 20 0F 0F C4 44 0F 0F 0F 0F 0F 0F 0F 0F'
11+
'0F 0F 0F 0F FF FF FF FF 00 00 00 00 FF FF FF FF'
12+
'00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF'
13+
'FF FF FF FF 00 00 55 55 FF FF 00 00 00 00 00 00'
14+
'33 00 1C 00 13 00 13 00 7C 00 1C 00 3C 00 33 00'
15+
'3C 00 3C 00 3C 00 30 00 3C 00 3C 00 3C 00 30 00')
16+
17+
# Default configuration for ATECC608A
18+
atecc608_config = bytearray.fromhex(
19+
'B0 00 00 01 8F 20 C4 44 87 20 87 20 8F 0F C4 36'
20+
'9F 0F 82 20 0F 0F C4 44 0F 0F 0F 0F 0F 0F 0F 0F'
21+
'0F 0F 0F 0F FF FF FF FF 00 00 00 00 FF FF FF FF'
22+
'00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
23+
'00 00 00 00 00 00 55 55 FF FF 00 00 00 00 00 00'
24+
'33 00 1C 00 13 00 13 00 7C 00 1C 00 3C 00 33 00'
25+
'3C 00 3C 00 3C 00 30 00 3C 00 3C 00 3C 00 30 00')
26+
27+
def configure_device(i2c_addr=0xC0):
28+
# Initialize the Kit Instance
29+
dev = KitDevice(hid.device())
30+
dev.open()
31+
32+
# Get id of the first device
33+
id = dev.kit_list(0)
34+
35+
# Select the device to communicate with
36+
dev.kit_select(id)
37+
38+
# Get the kit type
39+
print('\nGetting the Kit Type')
40+
kit_version = dev.kit_info(0).split(' ')[0]
41+
print(' {} Found'.format(kit_version))
42+
43+
# Check if this is the demo firmware - if not don't brick a CK590
44+
if ('GCP IoT Core Example' != dev.device.get_product_string()) and ('AT88CK590' == kit_version) and (0xC0 != i2c_addr):
45+
print(' Kit only supports I2C Address 0xC0')
46+
i2c_addr = 0xC0
47+
48+
# Get the device type
49+
print('\nGetting the Device Info')
50+
resp = dev.kit_command_resp(0x30, 0, 0, timeout_ms=5000)
51+
dev_type = resp[2]
52+
print(' Device type is {}08'.format(dev_type >> 4))
53+
54+
# Get Current I2C Address
55+
print('\nGetting the I2C Address')
56+
resp = dev.kit_command_resp(0x02, 0, 0x04, timeout_ms=5000)
57+
print(' Current Address: {:02X}'.format(resp[0]))
58+
print(' New Address: {:02X}'.format(i2c_addr))
59+
60+
# Check the zone locks
61+
print('\nReading the Lock Status')
62+
resp = dev.kit_command_resp(0x02, 0, 0x15, timeout_ms=5000)
63+
data_zone_lock = (0x55 != resp[2])
64+
config_zone_lock = (0x55 != resp[3])
65+
print(' Config Zone: {}'.format('Locked' if config_zone_lock else 'Unlocked'))
66+
print(' Data Zone: {}'.format('Locked' if data_zone_lock else 'Unlocked'))
67+
68+
# Program the configuration zone
69+
print('\nProgram Configuration')
70+
if not config_zone_lock:
71+
if 0x50 == dev_type:
72+
print(' Programming ATECC508A Configuration')
73+
config = atecc508_config
74+
elif 0x60 == dev_type:
75+
print(' Programming ATECC608A Configuration')
76+
config = atecc608_config
77+
else:
78+
print(' Unknown Device')
79+
raise ValueError('Unknown Device Type: {:02X}'.format(dev_type))
80+
81+
# Update with the target I2C Address
82+
config[0] = i2c_addr
83+
84+
# Write configuration
85+
resp = dev.write_bytes(0, 0, 16, config, timeout_ms=5000)
86+
print(' Success')
87+
88+
# Verify Config Zone
89+
print(' Verifying Configuration')
90+
resp = dev.read_bytes(0, 0, 16, len(config), timeout_ms=5000)
91+
92+
if resp != config:
93+
raise ValueError('Configuration read from the device does not match')
94+
print(' Success')
95+
96+
print(' Locking Configuration')
97+
resp = dev.kit_command_resp(0x17, 0x80, 0, timeout_ms=5000)
98+
print(' Locked')
99+
else:
100+
print(' Locked, skipping')
101+
102+
# Check data zone lock
103+
print('\nActivating Configuration')
104+
if not data_zone_lock:
105+
# Lock the data zone
106+
resp = dev.kit_command_resp(0x17, 0x81, 0, timeout_ms=5000)
107+
print(' Activated')
108+
else:
109+
print(' Already Active')
110+
111+
# Generate new keys
112+
print('\nGenerating New Keys')
113+
resp = dev.kit_command_resp(0x40, 4, 0, timeout_ms=5000)
114+
print(' Key 0 Success')
115+
116+
resp = dev.kit_command_resp(0x40, 4, 2, timeout_ms=5000)
117+
print(' Key 2 Success')
118+
119+
resp = dev.kit_command_resp(0x40, 4, 3, timeout_ms=5000)
120+
print(' Key 3 Success')
121+
122+
resp = dev.kit_command_resp(0x40, 4, 7, timeout_ms=5000)
123+
print(' Key 7 Success')
124+
125+
126+
if __name__ == '__main__':
127+
parser = argparse.ArgumentParser(description='GCP ECC Device Configuration Utility')
128+
parser.add_argument('--i2c', default='0xB0', help='I2C Address (in hex)')
129+
args = parser.parse_args()
130+
131+
configure_device(int(args.i2c,16))
132+
print('\nDevice Successfully Configured')
133+

scripts/at_kit_base.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
DEVICE_HID_PID = 0x2312
1212
KIT_VERSION = "2.0.0"
1313

14-
KIT_APP_COMMAND_SET_TIME = 0
15-
1614

1715
def kit_crc(data):
1816
"""Return bytes object of the crc based on the input data bytes"""
@@ -89,11 +87,17 @@ def kit_select(self, dev):
8987
"""Select the device with the given address"""
9088
self.kit_write('e:p:s', struct.pack("<B", dev))
9189
return self.kit_read(0)
90+
91+
def kit_info(self, param1):
92+
self.kit_write('b:f', struct.pack("<B", param1))
93+
return self.kit_read()
9294

9395
def kit_command(self, opcode, param1, param2, data=b'', timeout_ms=0):
9496
l2s = len(data) + 7 # length(1) + opcode(1) + param1(1) + param2(2) + crc(2)
9597
# Make Packet
9698
d2s = struct.pack("<BBBH", l2s, opcode, param1, param2)
99+
# Append the data
100+
d2s += data
97101
# Append CRC
98102
d2s += kit_crc(d2s)
99103
# Send the command
@@ -102,3 +106,43 @@ def kit_command(self, opcode, param1, param2, data=b'', timeout_ms=0):
102106
resp = self.kit_read(timeout_ms=timeout_ms)
103107
# Parse the response
104108
return self.kit_parse_reply(resp)
109+
110+
@staticmethod
111+
def kit_parse_resp(resp):
112+
if 0 != resp['status']:
113+
raise ValueError('Command returned error {}'.format(resp['status']))
114+
else:
115+
return bytes.fromhex(resp['data'])[1:-2]
116+
117+
def kit_command_resp(self, opcode, param1, param2, data=b'', timeout_ms=0):
118+
return self.kit_parse_resp(self.kit_command(opcode, param1, param2, data, timeout_ms))
119+
120+
@staticmethod
121+
def _calc_addr(zone, slot, offset):
122+
block = int(offset/32)
123+
offset = int(offset/4) & 0x07
124+
if 2 == zone:
125+
addr = (slot << 3) | offset | (block << 8)
126+
elif 0 == zone:
127+
addr = (block << 3) | offset
128+
else:
129+
raise ValueError('Invalid Zone')
130+
131+
return addr
132+
133+
def read_bytes(self, zone, slot, offset, length, timeout_ms=0):
134+
resp = bytearray()
135+
for x in range(int(offset/4)*4, offset+length, 4):
136+
resp += self.kit_command_resp(0x02, zone, self._calc_addr(zone, slot, x), timeout_ms=timeout_ms)
137+
return bytes(resp[offset % 4:(offset % 4) + length])
138+
139+
def write_bytes(self, zone, slot, offset, data, timeout_ms=0):
140+
idx = 0
141+
for x in range(int(offset/4)*4, offset+len(data), 4):
142+
self.kit_command_resp(0x12, zone, self._calc_addr(zone, slot, x), data=data[idx:idx+4], timeout_ms=timeout_ms)
143+
idx += 4
144+
145+
146+
147+
148+

src/atca_kit_client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ const char StringSha204[] = "SHA204 "; //!< SHA204 string
5858
const char StringAes132[] = "AES132 "; //!< AES132 string
5959
const char StringEcc508[] = "ECC108 "; //!< ECC108 string
6060

61-
const char StringKitShort[] = "CK590 "; //!< short string of Microbase kit
62-
const char StringKit[] = "AT88CK590 "; //!< long string of Microbase kit
61+
const char StringKitShort[] = "CK101 "; //!< short string of Microbase kit
62+
const char StringKit[] = "AT88CK101STK "; //!< long string of Microbase kit
6363

6464
device_info_t device_info[DISCOVER_DEVICE_COUNT_MAX];
6565
uint8_t device_count = 0;

0 commit comments

Comments
 (0)