mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-11-25 12:06:54 +01:00
Changed SC64 firmware version checking
This commit is contained in:
parent
22656b150c
commit
ed4c7b358b
@ -18,7 +18,8 @@
|
|||||||
#define SHADOW_ADDRESS (0x1FFC0000)
|
#define SHADOW_ADDRESS (0x1FFC0000)
|
||||||
#define EEPROM_ADDRESS (0x1FFE2000)
|
#define EEPROM_ADDRESS (0x1FFE2000)
|
||||||
|
|
||||||
#define MIN_SUPPORTED_API_VERSION (1)
|
#define SUPPORTED_MAJOR_VERSION (2)
|
||||||
|
#define SUPPORTED_MINOR_VERSION (12)
|
||||||
|
|
||||||
|
|
||||||
static flashcart_error_t load_to_flash (FIL *fil, void *address, size_t size, UINT *br) {
|
static flashcart_error_t load_to_flash (FIL *fil, void *address, size_t size, UINT *br) {
|
||||||
@ -52,19 +53,21 @@ static flashcart_error_t load_to_flash (FIL *fil, void *address, size_t size, UI
|
|||||||
|
|
||||||
|
|
||||||
static flashcart_error_t sc64_init (void) {
|
static flashcart_error_t sc64_init (void) {
|
||||||
uint32_t api_version;
|
uint16_t major;
|
||||||
|
uint16_t minor;
|
||||||
|
|
||||||
sc64_unlock();
|
sc64_unlock();
|
||||||
|
|
||||||
if (!sc64_check_presence()) {
|
if (!sc64_check_presence()) {
|
||||||
return FLASHCART_ERROR_UNSUPPORTED;
|
return FLASHCART_ERROR_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
if (sc64_get_version(&major, &minor) != SC64_OK) {
|
||||||
if (sc64_get_api_version(&api_version) != SC64_OK) {
|
|
||||||
return FLASHCART_ERROR_OUTDATED;
|
return FLASHCART_ERROR_OUTDATED;
|
||||||
}
|
}
|
||||||
|
if (major != SUPPORTED_MAJOR_VERSION) {
|
||||||
if (api_version < MIN_SUPPORTED_API_VERSION) {
|
return FLASHCART_ERROR_OUTDATED;
|
||||||
|
}
|
||||||
|
if (minor < SUPPORTED_MINOR_VERSION) {
|
||||||
return FLASHCART_ERROR_OUTDATED;
|
return FLASHCART_ERROR_OUTDATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t SR_CMD;
|
uint32_t SR_CMD;
|
||||||
uint32_t DATA[2];
|
uint32_t DATA[2];
|
||||||
uint32_t VERSION;
|
uint32_t IDENTIFIER;
|
||||||
uint32_t KEY;
|
uint32_t KEY;
|
||||||
} sc64_regs_t;
|
} sc64_regs_t;
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ typedef struct {
|
|||||||
#define SC64_SR_CMD_ERROR (1 << 30)
|
#define SC64_SR_CMD_ERROR (1 << 30)
|
||||||
#define SC64_SR_CPU_BUSY (1 << 31)
|
#define SC64_SR_CPU_BUSY (1 << 31)
|
||||||
|
|
||||||
#define SC64_VERSION_2 (0x53437632)
|
#define SC64_V2_IDENTIFIER (0x53437632)
|
||||||
|
|
||||||
#define SC64_KEY_RESET (0x00000000UL)
|
#define SC64_KEY_RESET (0x00000000UL)
|
||||||
#define SC64_KEY_UNLOCK_1 (0x5F554E4CUL)
|
#define SC64_KEY_UNLOCK_1 (0x5F554E4CUL)
|
||||||
@ -26,7 +26,7 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CMD_ID_API_VERSION_GET = 'V',
|
CMD_ID_VERSION_GET = 'V',
|
||||||
CMD_ID_CONFIG_GET = 'c',
|
CMD_ID_CONFIG_GET = 'c',
|
||||||
CMD_ID_CONFIG_SET = 'C',
|
CMD_ID_CONFIG_SET = 'C',
|
||||||
CMD_ID_WRITEBACK_SD_INFO = 'W',
|
CMD_ID_WRITEBACK_SD_INFO = 'W',
|
||||||
@ -75,7 +75,7 @@ void sc64_lock (void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool sc64_check_presence (void) {
|
bool sc64_check_presence (void) {
|
||||||
return (io_read((uint32_t) (&SC64_REGS->VERSION)) == SC64_VERSION_2);
|
return (io_read((uint32_t) (&SC64_REGS->IDENTIFIER)) == SC64_V2_IDENTIFIER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sc64_read_data (void *src, void *dst, size_t length) {
|
void sc64_read_data (void *src, void *dst, size_t length) {
|
||||||
@ -90,10 +90,11 @@ void sc64_write_data (void *src, void *dst, size_t length) {
|
|||||||
dma_wait();
|
dma_wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
sc64_error_t sc64_get_api_version (uint32_t *api_version) {
|
sc64_error_t sc64_get_version (uint16_t *major, uint16_t *minor) {
|
||||||
sc64_cmd_t cmd = { .id = CMD_ID_API_VERSION_GET };
|
sc64_cmd_t cmd = { .id = CMD_ID_VERSION_GET };
|
||||||
sc64_error_t error = sc64_execute_cmd(&cmd);
|
sc64_error_t error = sc64_execute_cmd(&cmd);
|
||||||
*api_version = cmd.rsp[0];
|
*major = ((cmd.rsp[0] >> 16) & 0xFFFF);
|
||||||
|
*minor = (cmd.rsp[0] & 0xFFFF);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ void sc64_lock (void);
|
|||||||
bool sc64_check_presence (void);
|
bool sc64_check_presence (void);
|
||||||
void sc64_read_data (void *src, void *dst, size_t length);
|
void sc64_read_data (void *src, void *dst, size_t length);
|
||||||
void sc64_write_data (void *src, void *dst, size_t length);
|
void sc64_write_data (void *src, void *dst, size_t length);
|
||||||
sc64_error_t sc64_get_api_version (uint32_t *api_version);
|
sc64_error_t sc64_get_version (uint16_t *major, uint16_t *minor);
|
||||||
sc64_error_t sc64_get_config (sc64_cfg_t cfg, void *value);
|
sc64_error_t sc64_get_config (sc64_cfg_t cfg, void *value);
|
||||||
sc64_error_t sc64_set_config (sc64_cfg_t cfg, uint32_t value);
|
sc64_error_t sc64_set_config (sc64_cfg_t cfg, uint32_t value);
|
||||||
sc64_error_t sc64_writeback_enable (void *address);
|
sc64_error_t sc64_writeback_enable (void *address);
|
||||||
|
17
src/main.c
17
src/main.c
@ -10,20 +10,11 @@
|
|||||||
|
|
||||||
static void init (void) {
|
static void init (void) {
|
||||||
assertf(usb_initialize() != CART_NONE, "No flashcart was detected");
|
assertf(usb_initialize() != CART_NONE, "No flashcart was detected");
|
||||||
switch (flashcart_init()) {
|
|
||||||
case FLASHCART_OK:
|
|
||||||
break;
|
|
||||||
case FLASHCART_ERROR_OUTDATED:
|
|
||||||
assertf(false, "Outdated flashcart firmware");
|
|
||||||
break;
|
|
||||||
case FLASHCART_ERROR_UNSUPPORTED:
|
|
||||||
assertf(false, "Unsupported flashcart");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assertf(false, "Unknown error while initializing flashcart");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
assertf(debug_init_sdfs("sd:/", -1), "Couldn't initialize SD card");
|
assertf(debug_init_sdfs("sd:/", -1), "Couldn't initialize SD card");
|
||||||
|
flashcart_error_t error = flashcart_init();
|
||||||
|
assertf(error != FLASHCART_ERROR_OUTDATED, "Outdated flashcart firmware");
|
||||||
|
assertf(error != FLASHCART_ERROR_UNSUPPORTED, "Unsupported flashcart");
|
||||||
|
assertf(error == FLASHCART_OK, "Unknown error while initializing flashcart");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deinit (void) {
|
static void deinit (void) {
|
||||||
|
Loading…
Reference in New Issue
Block a user