Skip to content

Commit

Permalink
[SC64][SW] Changed firmware version reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Polprzewodnikowy committed Feb 20, 2023
1 parent 56cdd3a commit 409ba28
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 152 deletions.
24 changes: 12 additions & 12 deletions docs/01_memory_map.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- [SC64 registers](#sc64-registers)
- [`0x1FFF_0000`: **STATUS/COMMAND**](#0x1fff_0000-statuscommand)
- [`0x1FFF_0004`: **DATA0** and `0x1FFF_0008`: **DATA1**](#0x1fff_0004-data0-and-0x1fff_0008-data1)
- [`0x1FFF_000C`: **VERSION**](#0x1fff_000c-version)
- [`0x1FFF_000C`: **IDENTIFIER**](#0x1fff_000c-identifier)
- [`0x1FFF_0010`: **KEY**](#0x1fff_0010-key)
- [Command execution flow](#command-execution-flow)

Expand Down Expand Up @@ -87,13 +87,13 @@ SC64 contains small register region used for communication between N64 and contr
Protocol is command based with support for up to 256 diferrent commands and two 32-bit argument/result values per operation.
Support for interrupts is provided but currently no command relies on it, 64DD IRQ is handled separately.

| name | address | size | access | usage |
| ------------------ | ------------- | ------- | ------ | -------------------------------- |
| **STATUS/COMMAND** | `0x1FFF_0000` | 4 bytes | RW | Command execution and status |
| **DATA0** | `0x1FFF_0004` | 4 bytes | RW | Command argument/result 0 |
| **DATA1** | `0x1FFF_0008` | 4 bytes | RW | Command argument/result 1 |
| **VERSION** | `0x1FFF_000C` | 4 bytes | RW | Hardware version and IRQ clear |
| **KEY** | `0x1FFF_0010` | 4 bytes | W | SC64 register access lock/unlock |
| name | address | size | access | usage |
| ------------------ | ------------- | ------- | ------ | ---------------------------------- |
| **STATUS/COMMAND** | `0x1FFF_0000` | 4 bytes | RW | Command execution and status |
| **DATA0** | `0x1FFF_0004` | 4 bytes | RW | Command argument/result 0 |
| **DATA1** | `0x1FFF_0008` | 4 bytes | RW | Command argument/result 1 |
| **IDENTIFIER** | `0x1FFF_000C` | 4 bytes | RW | Flashcart identifier and IRQ clear |
| **KEY** | `0x1FFF_0010` | 4 bytes | W | SC64 register access lock/unlock |

---

Expand Down Expand Up @@ -121,11 +121,11 @@ Note: Result is valid only when command has executed and `CMD_BUSY` bit is reset

---

#### `0x1FFF_000C`: **VERSION**
#### `0x1FFF_000C`: **IDENTIFIER**

| name | bits | access | meaning |
| --------- | ------ | ------ | --------------------------------------------- |
| `VERSION` | [31:0] | RW | Hardware version (ASCII `SCv2`) and IRQ clear |
| name | bits | access | meaning |
| ------------ | ------ | ------ | ------------------------------------------------- |
| `IDENTIFIER` | [31:0] | RW | Flashcart identifier (ASCII `SCv2`) and IRQ clear |

Note: Writing any value to this register will clear pending flashcart interrupt.

Expand Down
44 changes: 22 additions & 22 deletions docs/02_usb_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

## USB commands

| id | name | arg0 | arg1 | data | response | description |
| --- | ---------------------- | ------------ | ------------ | ---- | ---------------- | --------------------------------------------------- |
| `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 |
| `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_SET** | config_id | new_value | --- | --- | Set config option |
| `a` | **SETTING_GET** | setting_id | --- | --- | current_value | Get persistent setting |
| `A` | **SETTING_SET** | setting_id | new_value | --- | --- | Set persistent setting |
| `t` | **TIME_GET** | --- | --- | --- | time | Get current RTC value |
| `T` | **TIME_SET** | time_0 | time_1 | --- | --- | Set RTC value |
| `m` | **MEMORY_READ** | address | length | --- | data | Read data from specified memory address |
| `M` | **MEMORY_WRITE** | address | length | data | --- | Write data to specified memory address |
| `D` | **DD_SET_BLOCK_READY** | success | --- | --- | --- | Notify flashcart about 64DD block readiness |
| `U` | **USB_WRITE** | type | length | data | N/A | Send data to be received by app running on N64 |
| `f` | **FIRMWARE_BACKUP** | address | --- | --- | status/length | Backup firmware to specified memory address |
| `F` | **FIRMWARE_UPDATE** | address | length | --- | status | Update firmware from specified memory address |
| `p` | **FLASH_WAIT_BUSY** | wait | --- | --- | erase_block_size | Wait until flash ready / get flash block erase size |
| `P` | **FLASH_ERASE_BLOCK** | address | --- | --- | --- | Start flash block erase |
| `?` | **DEBUG_GET** | --- | --- | --- | debug_data | Get internal FPGA debug info |
| `%` | **STACK_USAGE_GET** | --- | --- | --- | stack_usage | Get per task stack usage |
| id | name | arg0 | arg1 | data | response | description |
| --- | ---------------------- | ------------ | ------------ | ---- | ---------------- | ------------------------------------------------------------- |
| `v` | **IDENTIFIER_GET** | --- | --- | --- | identifier | Get flashcart identifier `SCv2` |
| `V` | **VERSION_GET** | --- | --- | --- | version | Get flashcart firmware version |
| `R` | **STATE_RESET** | --- | --- | --- | --- | Reset flashcart state (CIC params and config options) |
| `B` | **CIC_PARAMS_SET** | cic_params_0 | cic_params_1 | --- | --- | Set CIC emulation parameters (disable/seed/checksum) |
| `c` | **CONFIG_GET** | config_id | --- | --- | current_value | Get config option |
| `C` | **CONFIG_SET** | config_id | new_value | --- | --- | Set config option |
| `a` | **SETTING_GET** | setting_id | --- | --- | current_value | Get persistent setting option |
| `A` | **SETTING_SET** | setting_id | new_value | --- | --- | Set persistent setting option |
| `t` | **TIME_GET** | --- | --- | --- | time | Get current RTC value |
| `T` | **TIME_SET** | time_0 | time_1 | --- | --- | Set new RTC value |
| `m` | **MEMORY_READ** | address | length | --- | data | Read data from specified memory address |
| `M` | **MEMORY_WRITE** | address | length | data | --- | Write data to specified memory address |
| `U` | **USB_WRITE** | type | length | data | N/A | Send data to be received by app running on N64 (no response!) |
| `D` | **DD_SET_BLOCK_READY** | success | --- | --- | --- | Notify flashcart about 64DD block readiness |
| `p` | **FLASH_WAIT_BUSY** | wait | --- | --- | erase_block_size | Wait until flash ready / Get flash block erase size |
| `P` | **FLASH_ERASE_BLOCK** | address | --- | --- | --- | Start flash block erase |
| `f` | **FIRMWARE_BACKUP** | address | --- | --- | status/length | Backup firmware to specified memory address |
| `F` | **FIRMWARE_UPDATE** | address | length | --- | status | Update firmware from specified memory address |
| `?` | **DEBUG_GET** | --- | --- | --- | debug_data | Get internal FPGA debug info |
| `%` | **STACK_USAGE_GET** | --- | --- | --- | stack_usage | Get per task stack usage |
7 changes: 3 additions & 4 deletions docs/03_n64_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

| id | name | arg0 | arg1 | rsp0 | rsp1 | description |
| --- | --------------------- | ---------- | ------------ | ---------------- | -------------- | -------------------------------------------------- |
| `v` | **HW_VERSION_GET** | --- | --- | hw_version | --- | Get HW version |
| `V` | **API_VERSION_GET** | --- | --- | api_version | --- | Get N64 command API version |
| `v` | **IDENTIFIER_GET** | --- | --- | identifier | --- | Get flashcart identifier `SCv2` |
| `V` | **VERSION_GET** | --- | --- | version | --- | Get flashcart firmware version |
| `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` | **SETTING_GET** | setting_id | --- | --- | current_value | Get persistent setting option |
| `C` | **SETTING_SET** | setting_id | new_value | --- | --- | Set persistent setting option |
| `t` | **TIME_GET** | --- | --- | time_0 | time_1 | Get current RTC value |
| `T` | **TIME_SET** | time_0 | time_1 | --- | --- | Set RTC value |
| `T` | **TIME_SET** | time_0 | time_1 | --- | --- | Set new RTC value |
| `m` | **USB_READ** | pi_address | length | --- | --- | Receive data from USB to flashcart |
| `M` | **USB_WRITE** | pi_address | length/type | --- | --- | Send data from from flashcart to USB |
| `u` | **USB_READ_STATUS** | --- | --- | read_status/type | length | Get USB read status and type/length |
Expand All @@ -27,4 +27,3 @@
| `K` | **FLASH_PROGRAM** | pi_address | length | --- | --- | Program flash with bytes loaded into data buffer |
| `p` | **FLASH_WAIT_BUSY** | wait | --- | erase_block_size | --- | Wait until flash ready / get block erase size |
| `P` | **FLASH_ERASE_BLOCK** | pi_address | --- | --- | --- | Start flash block erase |
| `?` | **DEBUG_GET** | --- | --- | debug_data_0 | debug_data_1 | Get internal FPGA debug info |
8 changes: 4 additions & 4 deletions fw/rtl/mcu/mcu_top.sv
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ module mcu_top (
REG_CFG_DATA_0,
REG_CFG_DATA_1,
REG_CFG_CMD,
REG_CFG_VERSION,
REG_CFG_IDENTIFIER,
REG_FLASHRAM_SCR,
REG_FLASH_SCR,
REG_RTC_SCR,
Expand Down Expand Up @@ -363,7 +363,7 @@ module mcu_top (

logic bootloader_skip;

assign n64_scb.cfg_version = 32'h53437632;
assign n64_scb.cfg_identifier = 32'h53437632;

logic dd_bm_ack;

Expand Down Expand Up @@ -460,8 +460,8 @@ module mcu_top (
};
end

REG_CFG_VERSION: begin
reg_rdata <= n64_scb.cfg_version;
REG_CFG_IDENTIFIER: begin
reg_rdata <= n64_scb.cfg_identifier;
end

REG_FLASHRAM_SCR: begin
Expand Down
10 changes: 5 additions & 5 deletions fw/rtl/n64/n64_cfg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module n64_cfg (
REG_DATA_0_L,
REG_DATA_1_H,
REG_DATA_1_L,
REG_VERSION_H,
REG_VERSION_L,
REG_IDENTIFIER_H,
REG_IDENTIFIER_L,
REG_KEY_H,
REG_KEY_L
} e_reg;
Expand All @@ -39,8 +39,8 @@ module n64_cfg (
REG_DATA_0_L: reg_bus.rdata = n64_scb.cfg_wdata[0][15:0];
REG_DATA_1_H: reg_bus.rdata = n64_scb.cfg_wdata[1][31:16];
REG_DATA_1_L: reg_bus.rdata = n64_scb.cfg_wdata[1][15:0];
REG_VERSION_H: reg_bus.rdata = n64_scb.cfg_version[31:16];
REG_VERSION_L: reg_bus.rdata = n64_scb.cfg_version[15:0];
REG_IDENTIFIER_H: reg_bus.rdata = n64_scb.cfg_identifier[31:16];
REG_IDENTIFIER_L: reg_bus.rdata = n64_scb.cfg_identifier[15:0];
REG_KEY_H: reg_bus.rdata = 16'd0;
REG_KEY_L: reg_bus.rdata = 16'd0;
endcase
Expand Down Expand Up @@ -83,7 +83,7 @@ module n64_cfg (
REG_DATA_0_L: n64_scb.cfg_rdata[0][15:0] <= reg_bus.wdata;
REG_DATA_1_H: n64_scb.cfg_rdata[1][31:16] <= reg_bus.wdata;
REG_DATA_1_L: n64_scb.cfg_rdata[1][15:0] <= reg_bus.wdata;
REG_VERSION_H: irq <= 1'b0;
REG_IDENTIFIER_H: irq <= 1'b0;
REG_KEY_H, REG_KEY_L: begin
lock_sequence_counter <= lock_sequence_counter + 1'd1;
if (reg_bus.wdata != 16'hFFFF) begin
Expand Down
6 changes: 3 additions & 3 deletions fw/rtl/n64/n64_scb.sv
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interface n64_scb ();
logic [7:0] cfg_cmd;
logic [31:0] cfg_rdata [0:1];
logic [31:0] cfg_wdata [0:1];
logic [31:0] cfg_version;
logic [31:0] cfg_identifier;

logic [15:0] save_count;

Expand Down Expand Up @@ -94,7 +94,7 @@ interface n64_scb ();
input cfg_cmd,
input cfg_rdata,
output cfg_wdata,
output cfg_version,
output cfg_identifier,

input save_count,

Expand Down Expand Up @@ -194,7 +194,7 @@ interface n64_scb ();
output cfg_cmd,
output cfg_rdata,
input cfg_wdata,
input cfg_version
input cfg_identifier
);

modport save_counter (
Expand Down
15 changes: 7 additions & 8 deletions sw/bootloader/src/sc64.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
typedef struct {
io32_t SR_CMD;
io32_t DATA[2];
io32_t VERSION;
io32_t IDENTIFIER;
io32_t KEY;
} sc64_regs_t;

Expand All @@ -16,16 +16,16 @@ typedef struct {
#define SC64_SR_CMD_ERROR (1 << 30)
#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_UNLOCK_1 (0x5F554E4CUL)
#define SC64_KEY_UNLOCK_2 (0x4F434B5FUL)
#define SC64_KEY_LOCK (0xFFFFFFFFUL)

typedef enum {
SC64_CMD_HW_VERSION_GET = 'v',
SC64_CMD_API_VERSION_GET = 'V',
SC64_CMD_IDENTIFIER_GET = 'v',
SC64_CMD_VERSION_GET = 'V',
SC64_CMD_CONFIG_GET = 'c',
SC64_CMD_CONFIG_SET = 'C',
SC64_CMD_SETTING_GET = 'a',
Expand All @@ -45,7 +45,6 @@ typedef enum {
SC64_CMD_FLASH_PROGRAM = 'K',
SC64_CMD_FLASH_WAIT_BUSY = 'p',
SC64_CMD_FLASH_ERASE_BLOCK = 'P',
SC64_CMD_DEBUG_GET = '?',
} cmd_id_t;

typedef enum {
Expand Down Expand Up @@ -98,8 +97,8 @@ void sc64_lock (void) {
}

bool sc64_check_presence (void) {
uint32_t version = pi_io_read(&SC64_REGS->VERSION);
if (version == SC64_VERSION_2) {
uint32_t identifier = pi_io_read(&SC64_REGS->IDENTIFIER);
if (identifier == SC64_V2_IDENTIFIER) {
sc64_wait_cpu_busy();
return true;
}
Expand All @@ -114,7 +113,7 @@ bool sc64_irq_pending (void) {
}

void sc64_irq_clear (void) {
pi_io_write(&SC64_REGS->VERSION, 0);
pi_io_write(&SC64_REGS->IDENTIFIER, 0);
}

uint32_t sc64_get_config (sc64_cfg_id_t id) {
Expand Down
13 changes: 4 additions & 9 deletions sw/controller/src/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ static bool cfg_set_save_type (save_type_t save_type) {
}


uint32_t cfg_get_version (void) {
return fpga_reg_get(REG_CFG_VERSION);
uint32_t cfg_get_identifier (void) {
return fpga_reg_get(REG_CFG_IDENTIFIER);
}

bool cfg_query (uint32_t *args) {
Expand Down Expand Up @@ -468,11 +468,11 @@ void cfg_process (void) {

switch (cmd) {
case 'v':
args[0] = cfg_get_version();
args[0] = cfg_get_identifier();
break;

case 'V':
args[0] = version_api(API_N64);
args[0] = version_firmware();
break;

case 'c':
Expand Down Expand Up @@ -666,11 +666,6 @@ void cfg_process (void) {
}
break;

case '?':
args[0] = fpga_reg_get(REG_DEBUG_0);
args[1] = fpga_reg_get(REG_DEBUG_1);
break;

default:
cfg_set_error(CFG_ERROR_UNKNOWN_CMD);
return;
Expand Down
2 changes: 1 addition & 1 deletion sw/controller/src/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef enum {
} save_type_t;


uint32_t cfg_get_version (void);
uint32_t cfg_get_identifier (void);
bool cfg_query (uint32_t *args);
bool cfg_update (uint32_t *args);
bool cfg_query_setting (uint32_t *args);
Expand Down
2 changes: 1 addition & 1 deletion sw/controller/src/fpga.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef enum {
REG_CFG_DATA_0,
REG_CFG_DATA_1,
REG_CFG_CMD,
REG_CFG_VERSION,
REG_CFG_IDENTIFIER,
REG_FLASHRAM_SCR,
REG_FLASH_SCR,
REG_RTC_SCR,
Expand Down
Loading

0 comments on commit 409ba28

Please sign in to comment.