From 7ee53474858ff6b8fd3661615348ac44b333e0da Mon Sep 17 00:00:00 2001 From: zvecr Date: Sat, 1 Oct 2022 04:16:15 +0100 Subject: [PATCH] Add eeprom init route --- data/xap/xap_0.1.0.hjson | 20 +++++++++++++++++++- docs/xap_0.1.0.md | 3 ++- docs/xap_0.2.0.md | 3 ++- docs/xap_0.3.0.md | 3 ++- lib/python/xap_client/device.py | 6 ++++++ lib/python/xap_client/routes.py | 1 + quantum/xap/xap_handlers.c | 12 ++++++++++++ 7 files changed, 44 insertions(+), 4 deletions(-) diff --git a/data/xap/xap_0.1.0.hjson b/data/xap/xap_0.1.0.hjson index c4988a22464..eef1b05e0dd 100755 --- a/data/xap/xap_0.1.0.hjson +++ b/data/xap/xap_0.1.0.hjson @@ -321,7 +321,7 @@ ''' Jump to bootloader - May not be present – if QMK capabilities query returns “true”, then jump to bootloader is supported + May not be present - if QMK capabilities query returns “true”, then jump to bootloader is supported * 0 means secure routes are disabled, and should be considered as a failure * 1 means successful, board will jump to bootloader @@ -337,6 +337,24 @@ return_type: u32[4] return_execute: get_hardware_id } + 0x09: { + type: command + name: Reinitialize EEPROM + define: EEPROM_RESET + permissions: secure + enable_if_preprocessor: !defined(NO_RESET) + description: + ''' + Reinitializes the keyboard's EEPROM (persistent memory) + + May not be present - if QMK capabilities query returns “true”, then reinitialize is supported + + * 0 means secure routes are disabled, and should be considered as a failure + * 1 means successful, board will reinitialize and then reboot + ''' + return_type: u8 + return_execute: request_eeprom_reset + } } }, diff --git a/docs/xap_0.1.0.md b/docs/xap_0.1.0.md index 3fa4dc00ff9..de34463df2f 100644 --- a/docs/xap_0.1.0.md +++ b/docs/xap_0.1.0.md @@ -111,8 +111,9 @@ This subsystem is always present, and provides the ability to address QMK-specif | Product Name | `0x01 0x04` | |__Response:__ `string`| Retrieves the product name| | Config Blob Length | `0x01 0x05` | |__Response:__ `u16`| Retrieves the length of the configuration data bundled within the firmware| | Config Blob Chunk | `0x01 0x06` | |__Request:__ `u16`

__Response:__ `u8[32]`| Retrieves a chunk of the configuration data bundled within the firmware| -| Jump to bootloader | `0x01 0x07` | __Secure__ |__Response:__ `u8`| Jump to bootloader

May not be present – if QMK capabilities query returns “true”, then jump to bootloader is supported

* 0 means secure routes are disabled, and should be considered as a failure
* 1 means successful, board will jump to bootloader| +| Jump to bootloader | `0x01 0x07` | __Secure__ |__Response:__ `u8`| Jump to bootloader

May not be present - if QMK capabilities query returns “true”, then jump to bootloader is supported

* 0 means secure routes are disabled, and should be considered as a failure
* 1 means successful, board will jump to bootloader| | Hardware Identifier | `0x01 0x08` | |__Response:__ `u32[4]`| Retrieves a unique identifier for the board.| +| Reinitialize EEPROM | `0x01 0x09` | __Secure__ |__Response:__ `u8`| Reinitializes the keyboard's EEPROM (persistent memory)

May not be present - if QMK capabilities query returns “true”, then reinitialize is supported

* 0 means secure routes are disabled, and should be considered as a failure
* 1 means successful, board will reinitialize and then reboot| ### Keyboard - `0x02` This subsystem is always present, and reserved for vendor-specific functionality. No routes are defined by XAP. diff --git a/docs/xap_0.2.0.md b/docs/xap_0.2.0.md index 560e141fdd2..cfdece98917 100644 --- a/docs/xap_0.2.0.md +++ b/docs/xap_0.2.0.md @@ -111,8 +111,9 @@ This subsystem is always present, and provides the ability to address QMK-specif | Product Name | `0x01 0x04` | |__Response:__ `string`| Retrieves the product name| | Config Blob Length | `0x01 0x05` | |__Response:__ `u16`| Retrieves the length of the configuration data bundled within the firmware| | Config Blob Chunk | `0x01 0x06` | |__Request:__ `u16`

__Response:__ `u8[32]`| Retrieves a chunk of the configuration data bundled within the firmware| -| Jump to bootloader | `0x01 0x07` | __Secure__ |__Response:__ `u8`| Jump to bootloader

May not be present – if QMK capabilities query returns “true”, then jump to bootloader is supported

* 0 means secure routes are disabled, and should be considered as a failure
* 1 means successful, board will jump to bootloader| +| Jump to bootloader | `0x01 0x07` | __Secure__ |__Response:__ `u8`| Jump to bootloader

May not be present - if QMK capabilities query returns “true”, then jump to bootloader is supported

* 0 means secure routes are disabled, and should be considered as a failure
* 1 means successful, board will jump to bootloader| | Hardware Identifier | `0x01 0x08` | |__Response:__ `u32[4]`| Retrieves a unique identifier for the board.| +| Reinitialize EEPROM | `0x01 0x09` | __Secure__ |__Response:__ `u8`| Reinitializes the keyboard's EEPROM (persistent memory)

May not be present - if QMK capabilities query returns “true”, then reinitialize is supported

* 0 means secure routes are disabled, and should be considered as a failure
* 1 means successful, board will reinitialize and then reboot| ### Keyboard - `0x02` This subsystem is always present, and reserved for vendor-specific functionality. No routes are defined by XAP. diff --git a/docs/xap_0.3.0.md b/docs/xap_0.3.0.md index ed471927727..0b0954a160a 100644 --- a/docs/xap_0.3.0.md +++ b/docs/xap_0.3.0.md @@ -111,8 +111,9 @@ This subsystem is always present, and provides the ability to address QMK-specif | Product Name | `0x01 0x04` | |__Response:__ `string`| Retrieves the product name| | Config Blob Length | `0x01 0x05` | |__Response:__ `u16`| Retrieves the length of the configuration data bundled within the firmware| | Config Blob Chunk | `0x01 0x06` | |__Request:__ `u16`

__Response:__ `u8[32]`| Retrieves a chunk of the configuration data bundled within the firmware| -| Jump to bootloader | `0x01 0x07` | __Secure__ |__Response:__ `u8`| Jump to bootloader

May not be present – if QMK capabilities query returns “true”, then jump to bootloader is supported

* 0 means secure routes are disabled, and should be considered as a failure
* 1 means successful, board will jump to bootloader| +| Jump to bootloader | `0x01 0x07` | __Secure__ |__Response:__ `u8`| Jump to bootloader

May not be present - if QMK capabilities query returns “true”, then jump to bootloader is supported

* 0 means secure routes are disabled, and should be considered as a failure
* 1 means successful, board will jump to bootloader| | Hardware Identifier | `0x01 0x08` | |__Response:__ `u32[4]`| Retrieves a unique identifier for the board.| +| Reinitialize EEPROM | `0x01 0x09` | __Secure__ |__Response:__ `u8`| Reinitializes the keyboard's EEPROM (persistent memory)

May not be present - if QMK capabilities query returns “true”, then reinitialize is supported

* 0 means secure routes are disabled, and should be considered as a failure
* 1 means successful, board will reinitialize and then reboot| ### Keyboard - `0x02` This subsystem is always present, and reserved for vendor-specific functionality. No routes are defined by XAP. diff --git a/lib/python/xap_client/device.py b/lib/python/xap_client/device.py index 8196b6517e4..8844f98b1e3 100644 --- a/lib/python/xap_client/device.py +++ b/lib/python/xap_client/device.py @@ -225,3 +225,9 @@ class XAPDevice(XAPDeviceBase): """ status = self.int_transaction(XAPRoutes.QMK_BOOTLOADER_JUMP) return status == 1 + + def reinit(self): + """Request device reset EEPROM - Requires previous unlock + """ + status = self.int_transaction(XAPRoutes.QMK_EEPROM_RESET) + return status == 1 diff --git a/lib/python/xap_client/routes.py b/lib/python/xap_client/routes.py index c8ebb415f89..a278d29ee40 100644 --- a/lib/python/xap_client/routes.py +++ b/lib/python/xap_client/routes.py @@ -49,6 +49,7 @@ class XAPRoutes(): QMK_CONFIG_BLOB_CHUNK = b'\x01\x06' QMK_BOOTLOADER_JUMP = b'\x01\x07' QMK_HARDWARE_ID = b'\x01\x08' + QMK_EEPROM_RESET = b'\x01\x09' # KEYMAP KEYMAP_CAPABILITIES_QUERY = b'\x04\x01' KEYMAP_GET_LAYER_COUNT = b'\x04\x02' diff --git a/quantum/xap/xap_handlers.c b/quantum/xap/xap_handlers.c index c729949ff5e..38a50c95b89 100644 --- a/quantum/xap/xap_handlers.c +++ b/quantum/xap/xap_handlers.c @@ -100,6 +100,18 @@ bool xap_respond_request_bootloader_jump(xap_token_t token, const void *data, si } #endif +#ifndef NO_RESET +bool xap_respond_request_eeprom_reset(xap_token_t token, const void *data, size_t length) { + uint8_t ret = secure_is_unlocked(); + + // TODO: post to deferred queue so this request can return? + bool res = xap_respond_data(token, &ret, sizeof(ret)); + eeconfig_disable(); + soft_reset_keyboard(); + return res; +} +#endif + bool xap_respond_get_hardware_id(xap_token_t token, const void *data, size_t length) { hardware_id_t ret = get_hardware_id(); return xap_respond_data(token, &ret, sizeof(ret));