fpga update tested

This commit is contained in:
Polprzewodnikowy 2022-08-19 11:35:58 +02:00
parent eb7443d95d
commit 05c3e1e4cf
6 changed files with 51 additions and 17 deletions

View File

@ -71,6 +71,9 @@ build_update () {
build_fpga build_fpga
pushd sw/update > /dev/null pushd sw/update > /dev/null
if [ "$FORCE_CLEAN" = true ]; then
rm -f ./sc64.upd
fi
INFO="" INFO=""
if [ ! -z "${GIT_BRANCH+x}" ]; then INFO+=" $GIT_BRANCH"; fi if [ ! -z "${GIT_BRANCH+x}" ]; then INFO+=" $GIT_BRANCH"; fi
if [ ! -z "${GIT_TAG+x}" ]; then INFO+=" $GIT_TAG"; fi if [ ! -z "${GIT_TAG+x}" ]; then INFO+=" $GIT_TAG"; fi

View File

@ -19,7 +19,7 @@ header_crc:
.org 0x20, 0x00 .org 0x20, 0x00
header_text_info: header_text_info:
.ascii "n64boot SummerCart64" .ascii "SC64 bootloader"
.org 0x40, 0x00 .org 0x40, 0x00

View File

@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
set -e
case "$1" in case "$1" in
all) all)
make all -j -f loader.mk USER_FLAGS="$USER_FLAGS" make all -j -f loader.mk USER_FLAGS="$USER_FLAGS"

View File

@ -194,7 +194,7 @@ bool cfg_query (uint32_t *args) {
args[1] = p.tv_type; args[1] = p.tv_type;
break; break;
case CFG_ID_FLASH_ERASE_BLOCK: case CFG_ID_FLASH_ERASE_BLOCK:
args[1] = 0xFFFFFFFF; args[1] = FLASH_ERASE_BLOCK_SIZE;
break; break;
case CFG_ID_DD_DRIVE_TYPE: case CFG_ID_DD_DRIVE_TYPE:
args[1] = dd_get_drive_type(); args[1] = dd_get_drive_type();

View File

@ -44,7 +44,7 @@ static uint32_t update_align (uint32_t value) {
} }
static uint32_t update_checksum (uint32_t address, uint32_t length) { static uint32_t update_checksum (uint32_t address, uint32_t length) {
uint8_t buffer[32]; uint8_t buffer[128];
uint32_t block_size; uint32_t block_size;
uint32_t checksum = 0; uint32_t checksum = 0;
hw_crc32_reset(); hw_crc32_reset();
@ -145,6 +145,40 @@ static void update_status_notify (update_status_t status) {
} }
} }
static bool mcu_update (uint32_t address, uint32_t length) {
hw_flash_t buffer;
hw_flash_erase();
for (uint32_t offset = 0; offset < length; offset += sizeof(hw_flash_t)) {
fpga_mem_read(address + offset, sizeof(hw_flash_t), (uint8_t *) (&buffer));
hw_flash_program(offset, buffer);
if (hw_flash_read(offset) != buffer) {
return true;
}
}
return false;
}
static bool bootloader_update (uint32_t address, uint32_t length) {
uint8_t update_buffer[FPGA_MAX_MEM_TRANSFER];
uint8_t verify_buffer[FPGA_MAX_MEM_TRANSFER];
for (uint32_t offset = 0; offset < BOOTLOADER_LENGTH; offset += FLASH_ERASE_BLOCK_SIZE) {
flash_erase_block(BOOTLOADER_ADDRESS + offset);
}
for (uint32_t offset = 0; offset < length; offset += FPGA_MAX_MEM_TRANSFER) {
fpga_mem_copy(address + offset, BOOTLOADER_ADDRESS + offset, FPGA_MAX_MEM_TRANSFER);
}
for (uint32_t offset = 0; offset < length; offset += sizeof(verify_buffer)) {
fpga_mem_read(address + offset, sizeof(update_buffer), update_buffer);
fpga_mem_read(BOOTLOADER_ADDRESS + offset, sizeof(verify_buffer), verify_buffer);
for (int i = 0; i < sizeof(verify_buffer); i++) {
if (update_buffer[i] != verify_buffer[i]) {
return true;
}
}
}
return false;
}
update_error_t update_backup (uint32_t address, uint32_t *length) { update_error_t update_backup (uint32_t address, uint32_t *length) {
uint32_t mcu_length; uint32_t mcu_length;
@ -247,19 +281,13 @@ void update_perform (void) {
uint32_t length; uint32_t length;
if (parameters.flags & LOADER_FLAGS_UPDATE_MCU) { if (parameters.flags & LOADER_FLAGS_UPDATE_MCU) {
hw_flash_t buffer;
update_status_notify(UPDATE_STATUS_MCU); update_status_notify(UPDATE_STATUS_MCU);
fpga_mem_read(parameters.mcu_address - 4, sizeof(length), (uint8_t *) (&length)); fpga_mem_read(parameters.mcu_address - 4, sizeof(length), (uint8_t *) (&length));
hw_flash_erase(); if (mcu_update(parameters.mcu_address, length)) {
for (uint32_t offset = 0; offset < length; offset += sizeof(hw_flash_t)) {
fpga_mem_read(parameters.mcu_address + offset, sizeof(hw_flash_t), (uint8_t *) (&buffer));
hw_flash_program(offset, buffer);
if (hw_flash_read(offset) != buffer) {
update_status_notify(UPDATE_STATUS_ERROR); update_status_notify(UPDATE_STATUS_ERROR);
while (1); while (1);
} }
} }
}
if (parameters.flags & LOADER_FLAGS_UPDATE_FPGA) { if (parameters.flags & LOADER_FLAGS_UPDATE_FPGA) {
update_status_notify(UPDATE_STATUS_FPGA); update_status_notify(UPDATE_STATUS_FPGA);
@ -273,11 +301,9 @@ void update_perform (void) {
if (parameters.flags & LOADER_FLAGS_UPDATE_BOOTLOADER) { if (parameters.flags & LOADER_FLAGS_UPDATE_BOOTLOADER) {
update_status_notify(UPDATE_STATUS_BOOTLOADER); update_status_notify(UPDATE_STATUS_BOOTLOADER);
fpga_mem_read(parameters.bootloader_address - 4, sizeof(length), (uint8_t *) (&length)); fpga_mem_read(parameters.bootloader_address - 4, sizeof(length), (uint8_t *) (&length));
for (uint32_t offset = 0; offset < BOOTLOADER_LENGTH; offset += FLASH_ERASE_BLOCK_SIZE) { if (bootloader_update(parameters.bootloader_address, length)) {
flash_erase_block(BOOTLOADER_ADDRESS + offset); update_status_notify(UPDATE_STATUS_ERROR);
} while (1);
for (uint32_t offset = 0; offset < length; offset += FPGA_MAX_MEM_TRANSFER) {
fpga_mem_copy(parameters.bootloader_address + offset, BOOTLOADER_ADDRESS + offset, FPGA_MAX_MEM_TRANSFER);
} }
} }

View File

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import argparse import argparse
import math import math
import os import os
@ -7,6 +9,7 @@ from datetime import datetime
from io import BufferedRandom from io import BufferedRandom
class JedecError(Exception): class JedecError(Exception):
pass pass