diff --git a/src/hsm/cmd_extras.c b/src/hsm/cmd_extras.c index f0b6d58..cce598b 100644 --- a/src/hsm/cmd_extras.c +++ b/src/hsm/cmd_extras.c @@ -19,6 +19,7 @@ #include "mbedtls/ecdh.h" #ifdef PICO_PLATFORM #include "pico/aon_timer.h" +#include "hardware/watchdog.h" #else #include #include @@ -35,6 +36,7 @@ #define CMD_DATETIME 0xA #define CMD_DYNOPS 0x6 #define CMD_SECURE_LOCK 0x3A +#define CMD_REBOOT 0xFB #define SECURE_LOCK_KEY_AGREEMENT 0x1 #define SECURE_LOCK_ENABLE 0x2 #define SECURE_LOCK_MASK 0x3 @@ -287,6 +289,14 @@ int cmd_extras() { } } } +#endif +#ifdef PICO_PLATFORM + else if (P1(apdu) == CMD_REBOOT) { + if (apdu.nc != 0) { + return SW_WRONG_LENGTH(); + } + watchdog_reboot(0, 0, 100); + } #endif else { return SW_INCORRECT_P1P2(); diff --git a/tools/pico-hsm-tool.py b/tools/pico-hsm-tool.py index 944b6b3..95ea01a 100644 --- a/tools/pico-hsm-tool.py +++ b/tools/pico-hsm-tool.py @@ -149,6 +149,8 @@ def parse_args(): parser_otp.add_argument('--lock', help='Lock & protect (no other firmwares can be loaded)', action='store_true') parser_otp.add_argument('--index', help='Bootkey index [0-3]', type=int, default=0, choices=[0, 1, 2, 3]) + parser_reboot = subparser.add_parser('reboot', help='Reboots the Pico HSM.') + args = parser.parse_args() return args @@ -507,6 +509,9 @@ def otp(picohsm, args): elif (args.subcommand == 'secure_boot'): picohsm.secure_boot(BOOTKEY, bootkey_index=args.index, lock=args.lock) +def reboot(picohsm, args): + picohsm.reboot() + def main(args): sys.stderr.buffer.write(b'Pico HSM Tool v2.0\n') sys.stderr.buffer.write(b'Author: Pol Henarejos\n') @@ -537,6 +542,8 @@ def main(args): phy(picohsm, args) elif (args.command == 'otp'): otp(picohsm, args) + elif (args.command == 'reboot'): + reboot(picohsm, args) def run(): args = parse_args()