Add xap cli functions to test secure

This commit is contained in:
zvecr 2022-07-07 01:57:41 +01:00
parent 6ec0ff387b
commit ced7094ddd
4 changed files with 34 additions and 8 deletions

View File

@ -876,6 +876,7 @@ ifeq ($(strip $(XAP_ENABLE)), yes)
endif endif
OPT_DEFS += -DXAP_ENABLE OPT_DEFS += -DXAP_ENABLE
OPT_DEFS += -DBOOTLOADER_JUMP_SUPPORTED
DYNAMIC_KEYMAP_ENABLE := yes DYNAMIC_KEYMAP_ENABLE := yes
SECURE_ENABLE := yes SECURE_ENABLE := yes
EMBED_INFO_JSON := yes EMBED_INFO_JSON := yes

View File

@ -70,12 +70,30 @@ class XAPShell(cmd.Cmd):
# TODO: request stuff? # TODO: request stuff?
print(self.device.info()['xap']) print(self.device.info()['xap'])
def do_status(self, arg):
"""Prints out the current device state
"""
status = self.device.status()
print('Secure:%s' % status.get('lock', '???'))
def do_unlock(self, arg): def do_unlock(self, arg):
"""Initiate secure unlock """Initiate secure unlock
""" """
self.device.unlock() self.device.unlock()
print('Unlock Requested...') print('Unlock Requested...')
def do_lock(self, arg):
"""Disable secure routes
"""
self.device.lock()
def do_reset(self, arg):
"""Jump to bootloader if unlocked
"""
if not self.device.reset():
print("Reboot to bootloader failed")
return True
def do_listen(self, arg): def do_listen(self, arg):
"""Log out XAP broadcast messages """Log out XAP broadcast messages
""" """
@ -89,9 +107,7 @@ class XAPShell(cmd.Cmd):
cli.log.info(' Secure[%s]', secure_status) cli.log.info(' Secure[%s]', secure_status)
else: else:
data_str = ' '.join(['{:02X}'.format(b) for b in data]) cli.log.info(' Broadcast: type[%02x] data:[%s]', event, data.hex())
cli.log.info(' Broadcast: type[%02x] data:[%s]', event, data_str)
except KeyboardInterrupt: except KeyboardInterrupt:
cli.log.info('Stopping...') cli.log.info('Stopping...')

View File

@ -148,9 +148,23 @@ class XAPDevice:
data['xap'] = self.version()['xap'] data['xap'] = self.version()['xap']
return data return data
def status(self):
lock = int.from_bytes(self.transaction(b'\x00\x03') or bytes(0), 'little')
data = {}
data['lock'] = XAPSecureStatus(lock).name
return data
def unlock(self): def unlock(self):
self.transaction(b'\x00\x04') self.transaction(b'\x00\x04')
def lock(self):
self.transaction(b'\x00\x05')
def reset(self):
status = int.from_bytes(self.transaction(b'\x01\x07') or bytes(0), 'little')
return status == 1
class XAPClient: class XAPClient:
@staticmethod @staticmethod

View File

@ -83,11 +83,6 @@ bool xap_respond_secure_lock(xap_token_t token, const void *data, size_t length)
return xap_respond_data(token, NULL, 0); return xap_respond_data(token, NULL, 0);
} }
// TODO: how to set this if "custom" is just an empty stub
#ifndef BOOTLOADER_JUMP_SUPPORTED
# define BOOTLOADER_JUMP_SUPPORTED
#endif
#ifdef BOOTLOADER_JUMP_SUPPORTED #ifdef BOOTLOADER_JUMP_SUPPORTED
bool xap_respond_request_bootloader_jump(xap_token_t token, const void *data, size_t length) { bool xap_respond_request_bootloader_jump(xap_token_t token, const void *data, size_t length) {
uint8_t ret = secure_is_unlocked(); uint8_t ret = secure_is_unlocked();