mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-25 23:24:15 +01:00
small fixes
This commit is contained in:
parent
76296a44d8
commit
201a4d023a
@ -157,6 +157,31 @@ static vendor_error_t lcmxo2_fail (vendor_error_t error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
uint32_t vendor_flash_size (void) {
|
||||
return (FLASH_PAGE_SIZE * FLASH_NUM_PAGES);
|
||||
}
|
||||
|
||||
vendor_error_t vendor_backup (uint32_t address, uint32_t *length) {
|
||||
uint8_t buffer[FLASH_PAGE_SIZE];
|
||||
|
||||
*length = 0;
|
||||
|
||||
lcmxo2_reset_bus();
|
||||
if (lcmxo2_enable_flash()) {
|
||||
return lcmxo2_fail(VENDOR_ERROR_INIT);
|
||||
}
|
||||
lcmxo2_reset_flash_address();
|
||||
for (int i = 0; i < (FLASH_PAGE_SIZE * FLASH_NUM_PAGES); i += FLASH_PAGE_SIZE) {
|
||||
lcmxo2_read_flash_page(buffer);
|
||||
fpga_mem_write(address + i, FLASH_PAGE_SIZE, buffer);
|
||||
*length += FLASH_PAGE_SIZE;
|
||||
}
|
||||
lcmxo2_disable_flash();
|
||||
lcmxo2_cleanup();
|
||||
|
||||
return VENDOR_OK;
|
||||
}
|
||||
|
||||
vendor_error_t vendor_update (uint32_t address, uint32_t length) {
|
||||
uint8_t buffer[FLASH_PAGE_SIZE];
|
||||
uint8_t verify_buffer[FLASH_PAGE_SIZE];
|
||||
@ -202,27 +227,6 @@ vendor_error_t vendor_update (uint32_t address, uint32_t length) {
|
||||
return VENDOR_OK;
|
||||
}
|
||||
|
||||
vendor_error_t vendor_backup (uint32_t address, uint32_t *length) {
|
||||
uint8_t buffer[FLASH_PAGE_SIZE];
|
||||
|
||||
*length = 0;
|
||||
|
||||
lcmxo2_reset_bus();
|
||||
if (lcmxo2_enable_flash()) {
|
||||
return lcmxo2_fail(VENDOR_ERROR_INIT);
|
||||
}
|
||||
lcmxo2_reset_flash_address();
|
||||
for (int i = 0; i < (FLASH_PAGE_SIZE * FLASH_NUM_PAGES); i += FLASH_PAGE_SIZE) {
|
||||
lcmxo2_read_flash_page(buffer);
|
||||
fpga_mem_write(address + i, FLASH_PAGE_SIZE, buffer);
|
||||
*length += FLASH_PAGE_SIZE;
|
||||
}
|
||||
lcmxo2_disable_flash();
|
||||
lcmxo2_cleanup();
|
||||
|
||||
return VENDOR_OK;
|
||||
}
|
||||
|
||||
vendor_error_t vendor_reconfigure (void) {
|
||||
lcmxo2_reset_bus();
|
||||
lcmxo2_refresh();
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
|
||||
typedef enum {
|
||||
UPDATE_STATUS_NONE = 0,
|
||||
UPDATE_STATUS_START = 1,
|
||||
UPDATE_STATUS_MCU_START = 2,
|
||||
UPDATE_STATUS_MCU_DONE = 3,
|
||||
@ -31,7 +30,7 @@ static const uint8_t update_token[16] = "SC64 Update v2.0";
|
||||
static uint8_t status_data[12] = {
|
||||
'P', 'K', 'T', PACKET_CMD_UPDATE_STATUS,
|
||||
0, 0, 0, 4,
|
||||
0, 0, 0, UPDATE_STATUS_NONE,
|
||||
0, 0, 0, UPDATE_STATUS_START,
|
||||
};
|
||||
|
||||
|
||||
@ -132,16 +131,18 @@ static void update_status_notify (update_status_t status) {
|
||||
|
||||
update_error_t update_backup (uint32_t address, uint32_t *length) {
|
||||
hw_flash_t buffer;
|
||||
uint32_t mcu_length;
|
||||
uint32_t fpga_length;
|
||||
|
||||
*length += update_write_token(&address);
|
||||
|
||||
*length += update_prepare_chunk(&address, CHUNK_ID_MCU_DATA);
|
||||
for (uint32_t offset = 0; offset < hw_flash_size(); offset += sizeof(hw_flash_t)) {
|
||||
mcu_length = hw_flash_size();
|
||||
for (uint32_t offset = 0; offset < mcu_length; offset += sizeof(hw_flash_t)) {
|
||||
buffer = hw_flash_read(offset);
|
||||
fpga_mem_write(address + offset, sizeof(hw_flash_t), (uint8_t *) (&buffer));
|
||||
}
|
||||
*length += update_finalize_chunk(&address, hw_flash_size());
|
||||
*length += update_finalize_chunk(&address, mcu_length);
|
||||
|
||||
*length += update_prepare_chunk(&address, CHUNK_ID_FPGA_DATA);
|
||||
if (vendor_backup(address, &fpga_length) != VENDOR_OK) {
|
||||
@ -153,7 +154,7 @@ update_error_t update_backup (uint32_t address, uint32_t *length) {
|
||||
}
|
||||
|
||||
update_error_t update_prepare (uint32_t address, uint32_t length) {
|
||||
uint32_t end_address = address + length;
|
||||
uint32_t end_address = (address + length);
|
||||
chunk_id_t id;
|
||||
uint32_t data_address;
|
||||
uint32_t data_length;
|
||||
@ -177,11 +178,17 @@ update_error_t update_prepare (uint32_t address, uint32_t length) {
|
||||
break;
|
||||
|
||||
case CHUNK_ID_MCU_DATA:
|
||||
if (data_length > hw_flash_size()) {
|
||||
return UPDATE_ERROR_SIZE;
|
||||
}
|
||||
parameters.mcu_address = data_address;
|
||||
parameters.mcu_length = data_length;
|
||||
break;
|
||||
|
||||
case CHUNK_ID_FPGA_DATA:
|
||||
if (data_length > vendor_flash_size()) {
|
||||
return UPDATE_ERROR_SIZE;
|
||||
}
|
||||
parameters.fpga_address = data_address;
|
||||
parameters.fpga_length = data_length;
|
||||
break;
|
||||
|
@ -10,6 +10,7 @@ typedef enum {
|
||||
UPDATE_OK,
|
||||
UPDATE_ERROR_TOKEN,
|
||||
UPDATE_ERROR_CHECKSUM,
|
||||
UPDATE_ERROR_SIZE,
|
||||
UPDATE_ERROR_UNKNOWN_CHUNK,
|
||||
UPDATE_ERROR_READ,
|
||||
} update_error_t;
|
||||
|
@ -15,8 +15,9 @@ typedef enum {
|
||||
} vendor_error_t;
|
||||
|
||||
|
||||
vendor_error_t vendor_update (uint32_t address, uint32_t length);
|
||||
uint32_t vendor_flash_size (void);
|
||||
vendor_error_t vendor_backup (uint32_t address, uint32_t *length);
|
||||
vendor_error_t vendor_update (uint32_t address, uint32_t length);
|
||||
vendor_error_t vendor_reconfigure (void);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user