[SC64][SW] Added API versioning

This commit is contained in:
Mateusz Faderewski 2023-02-14 23:51:00 +01:00
parent 46f7b8b794
commit 740114c62f
9 changed files with 69 additions and 5 deletions

View File

@ -6,7 +6,8 @@
| id | name | arg0 | arg1 | data | response | description | | id | name | arg0 | arg1 | data | response | description |
| --- | ---------------------- | ------------ | ------------ | ---- | ---------------- | --------------------------------------------------- | | --- | ---------------------- | ------------ | ------------ | ---- | ---------------- | --------------------------------------------------- |
| `v` | **VERSION_GET** | --- | --- | --- | api_version | Get command API version | | `v` | **HW_VERSION_GET** | --- | --- | --- | hw_version | Get HW version |
| `V` | **API_VERSION_GET** | --- | --- | --- | api_version | Get USB command API version |
| `R` | **STATE_RESET** | --- | --- | --- | --- | Reset entire flashcart state | | `R` | **STATE_RESET** | --- | --- | --- | --- | Reset entire flashcart state |
| `B` | **CIC_PARAMS_SET** | cic_params_0 | cic_params_1 | --- | --- | Set CIC disable/mode/seed/checksum | | `B` | **CIC_PARAMS_SET** | cic_params_0 | cic_params_1 | --- | --- | Set CIC disable/mode/seed/checksum |
| `c` | **CONFIG_GET** | config_id | --- | --- | current_value | Get config option | | `c` | **CONFIG_GET** | config_id | --- | --- | current_value | Get config option |

View File

@ -6,7 +6,8 @@
| id | name | arg0 | arg1 | rsp0 | rsp1 | description | | id | name | arg0 | arg1 | rsp0 | rsp1 | description |
| --- | --------------------- | ---------- | ------------ | ---------------- | -------------- | -------------------------------------------------- | | --- | --------------------- | ---------- | ------------ | ---------------- | -------------- | -------------------------------------------------- |
| `v` | **VERSION_GET** | --- | --- | api_version | --- | Get command API version | | `v` | **HW_VERSION_GET** | --- | --- | hw_version | --- | Get HW version |
| `V` | **API_VERSION_GET** | --- | --- | api_version | --- | Get N64 command API version |
| `c` | **CONFIG_GET** | config_id | --- | --- | current_value | Get config option | | `c` | **CONFIG_GET** | config_id | --- | --- | current_value | Get config option |
| `C` | **CONFIG_SET** | config_id | new_value | --- | previous_value | Set config option and get previous value | | `C` | **CONFIG_SET** | config_id | new_value | --- | previous_value | Set config option and get previous value |
| `c` | **SETTING_GET** | setting_id | --- | --- | current_value | Get persistent setting option | | `c` | **SETTING_GET** | setting_id | --- | --- | current_value | Get persistent setting option |

View File

@ -24,7 +24,8 @@ typedef struct {
#define SC64_KEY_LOCK (0xFFFFFFFFUL) #define SC64_KEY_LOCK (0xFFFFFFFFUL)
typedef enum { typedef enum {
SC64_CMD_VERSION_GET = 'v', SC64_CMD_HW_VERSION_GET = 'v',
SC64_CMD_API_VERSION_GET = 'V',
SC64_CMD_CONFIG_GET = 'c', SC64_CMD_CONFIG_GET = 'c',
SC64_CMD_CONFIG_SET = 'C', SC64_CMD_CONFIG_SET = 'C',
SC64_CMD_SETTING_GET = 'a', SC64_CMD_SETTING_GET = 'a',

View File

@ -25,6 +25,7 @@ SRC_FILES = \
timer.c \ timer.c \
update.c \ update.c \
usb.c \ usb.c \
version.c \
writeback.c writeback.c
include common.mk include common.mk

View File

@ -7,6 +7,7 @@
#include "rtc.h" #include "rtc.h"
#include "sd.h" #include "sd.h"
#include "usb.h" #include "usb.h"
#include "version.h"
#include "writeback.h" #include "writeback.h"
@ -464,6 +465,10 @@ void cfg_process (void) {
args[0] = cfg_get_version(); args[0] = cfg_get_version();
break; break;
case 'V':
args[0] = version_api(API_N64);
break;
case 'c': case 'c':
if (cfg_query(args)) { if (cfg_query(args)) {
cfg_set_error(CFG_ERROR_BAD_CONFIG_ID); cfg_set_error(CFG_ERROR_BAD_CONFIG_ID);

View File

@ -7,6 +7,7 @@
#include "rtc.h" #include "rtc.h"
#include "update.h" #include "update.h"
#include "usb.h" #include "usb.h"
#include "version.h"
enum rx_state { enum rx_state {
@ -162,6 +163,13 @@ static void usb_rx_process (void) {
p.response_info.data[0] = cfg_get_version(); p.response_info.data[0] = cfg_get_version();
break; break;
case 'V':
p.rx_state = RX_STATE_IDLE;
p.response_pending = true;
p.response_info.data_length = 4;
p.response_info.data[0] = version_api(API_USB);
break;
case 'R': case 'R':
cfg_reset_state(); cfg_reset_state();
cic_reset_parameters(); cic_reset_parameters();

View File

@ -0,0 +1,17 @@
#include "version.h"
#define VERSION_API_USB (1)
#define VERSION_API_N64 (1)
uint32_t version_api (version_api_type_t type) {
switch (type) {
case API_USB:
return VERSION_API_USB;
case API_N64:
return VERSION_API_N64;
default:
return 0;
}
}

View File

@ -0,0 +1,17 @@
#ifndef VERSION_H__
#define VERSION_H__
#include <stdint.h>
typedef enum {
API_USB,
API_N64,
} version_api_type_t;
uint32_t version_api (version_api_type_t type);
#endif

View File

@ -319,6 +319,8 @@ class SC64:
SCREENSHOT = 4 SCREENSHOT = 4
GDB = 0xDB GDB = 0xDB
__MIN_SUPPORTED_API_VERSION = 1
__isv_line_buffer: bytes = b'' __isv_line_buffer: bytes = b''
__debug_header: Optional[bytes] = None __debug_header: Optional[bytes] = None
__gdb_client: Optional[socket.socket] = None __gdb_client: Optional[socket.socket] = None
@ -327,11 +329,20 @@ class SC64:
self.__link = SC64Serial() self.__link = SC64Serial()
version = self.__link.execute_cmd(cmd=b'v') version = self.__link.execute_cmd(cmd=b'v')
if (version != b'SCv2'): if (version != b'SCv2'):
raise ConnectionException('Unknown SC64 API version') raise ConnectionException('Unknown SC64 HW version')
def __get_int(self, data: bytes) -> int: def __get_int(self, data: bytes) -> int:
return int.from_bytes(data[:4], byteorder='big') return int.from_bytes(data[:4], byteorder='big')
def check_api_version(self) -> None:
try:
data = self.__link.execute_cmd(cmd=b'V')
except ConnectionException:
raise ConnectionException('Outdated SC64 API, please update firmware')
version = self.__get_int(data)
if (version < self.__MIN_SUPPORTED_API_VERSION):
raise ConnectionException('Unsupported SC64 API version, please update firmware')
def __set_config(self, config: __CfgId, value: int) -> None: def __set_config(self, config: __CfgId, value: int) -> None:
try: try:
self.__link.execute_cmd(cmd=b'C', args=[config, value]) self.__link.execute_cmd(cmd=b'C', args=[config, value])
@ -877,6 +888,8 @@ if __name__ == '__main__':
sc64.update_firmware(f.read(), status_callback) sc64.update_firmware(f.read(), status_callback)
print('done') print('done')
sc64.check_api_version()
if (args.update_bootloader): if (args.update_bootloader):
with open(args.update_bootloader, 'rb') as f: with open(args.update_bootloader, 'rb') as f:
print('Uploading Bootloader... ', end='', flush=True) print('Uploading Bootloader... ', end='', flush=True)