From 4c7783f7409f35a3f9ef350bf6d58a6f38be6e3a Mon Sep 17 00:00:00 2001 From: Polprzewodnikowy Date: Sat, 24 Sep 2022 02:22:14 +0200 Subject: [PATCH] small fixes --- sw/bootloader/Makefile | 2 +- sw/bootloader/assets/assets.h | 2 +- sw/bootloader/src/boot.c | 2 +- sw/bootloader/src/fatfs/ffconf.h | 8 ++++---- sw/bootloader/src/ipl2.S | 2 +- sw/bootloader/src/sc64.c | 8 ++++---- sw/bootloader/src/sc64.h | 2 +- sw/bootloader/src/syscalls.c | 4 ++-- sw/controller/common.mk | 2 +- sw/controller/src/cfg.c | 8 +++++--- sw/controller/src/hw.c | 8 ++------ sw/controller/src/usb.c | 2 +- sw/pc/sc64.py | 9 ++++++++- 13 files changed, 32 insertions(+), 27 deletions(-) diff --git a/sw/bootloader/Makefile b/sw/bootloader/Makefile index 53c761f..bdbb28a 100644 --- a/sw/bootloader/Makefile +++ b/sw/bootloader/Makefile @@ -7,7 +7,7 @@ SIZE = $(TOOLCHAIN)size PYTHON = python3 FLAGS = -march=vr4300 -mtune=vr4300 $(USER_FLAGS) -CFLAGS = -Os -Wall -ffunction-sections -fdata-sections -ffreestanding -G 0 -MMD -MP +CFLAGS = -Os -Wall -ffunction-sections -fdata-sections -ffreestanding -MMD -MP ASFLAGS = -Wa,-I$(N64_INST)/mips64-elf/lib LDFLAGS = -lc -nostartfiles -Wl,--gc-sections diff --git a/sw/bootloader/assets/assets.h b/sw/bootloader/assets/assets.h index 3022de8..d87d654 100644 --- a/sw/bootloader/assets/assets.h +++ b/sw/bootloader/assets/assets.h @@ -5,7 +5,7 @@ #include -extern const uint32_t assets_sc64_logo_640_240_dimmed; +extern const uint32_t assets_sc64_logo_640_240_dimmed __attribute__((section(".assets"))); #endif diff --git a/sw/bootloader/src/boot.c b/sw/bootloader/src/boot.c index 1e7b0bb..660fb39 100644 --- a/sw/bootloader/src/boot.c +++ b/sw/bootloader/src/boot.c @@ -3,7 +3,7 @@ #include "io.h" -extern uint32_t ipl2; +extern uint32_t ipl2 __attribute__((section(".data"))); typedef struct { diff --git a/sw/bootloader/src/fatfs/ffconf.h b/sw/bootloader/src/fatfs/ffconf.h index e448f4f..330c993 100644 --- a/sw/bootloader/src/fatfs/ffconf.h +++ b/sw/bootloader/src/fatfs/ffconf.h @@ -15,7 +15,7 @@ / and optional writing functions as well. */ -#define FF_FS_MINIMIZE 0 +#define FF_FS_MINIMIZE 2 /* This option defines minimization level to remove some basic API functions. / / 0: Basic functions are fully enabled. @@ -25,7 +25,7 @@ / 3: f_lseek() function is removed in addition to 2. */ -#define FF_USE_FIND 1 +#define FF_USE_FIND 0 /* This option switches filtered directory read functions, f_findfirst() and / f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ @@ -52,7 +52,7 @@ / (0:Disable or 1:Enable) */ -#define FF_USE_FORWARD 1 +#define FF_USE_FORWARD 0 /* This option switches f_forward() function. (0:Disable or 1:Enable) */ @@ -153,7 +153,7 @@ / on character encoding. When LFN is not enabled, these options have no effect. */ -#define FF_FS_RPATH 1 +#define FF_FS_RPATH 0 /* This option configures support for relative path. / / 0: Disable relative path and remove related functions. diff --git a/sw/bootloader/src/ipl2.S b/sw/bootloader/src/ipl2.S index e99d010..abf4f4b 100644 --- a/sw/bootloader/src/ipl2.S +++ b/sw/bootloader/src/ipl2.S @@ -1,7 +1,7 @@ .set noat .set noreorder -.section .text.ipl2 +.section .data.ipl2 ipl2: .global ipl2 lui $t5, 0xBFC0 diff --git a/sw/bootloader/src/sc64.c b/sw/bootloader/src/sc64.c index 94bf232..d8b1994 100644 --- a/sw/bootloader/src/sc64.c +++ b/sw/bootloader/src/sc64.c @@ -117,12 +117,12 @@ void sc64_get_time (rtc_time_t *t) { bool sc64_usb_write_ready (void) { uint32_t result[2]; sc64_execute_cmd(SC64_CMD_USB_WRITE_STATUS, NULL, result); - return result[0]; + return (!(result[0] & (1 << 31))); } -bool sc64_usb_write (uint32_t *address, uint32_t length) { +bool sc64_usb_write (uint32_t *address, uint8_t type, uint32_t length) { while (!sc64_usb_write_ready()); - uint32_t args[2] = { (uint32_t) (address), length }; + uint32_t args[2] = { (uint32_t) (address), ((type << 24) | (length & 0xFFFFFF)) }; return sc64_execute_cmd(SC64_CMD_USB_WRITE, args, NULL); } @@ -146,7 +146,7 @@ bool sc64_usb_read (uint32_t *address, uint32_t length) { } do { sc64_execute_cmd(SC64_CMD_USB_READ_STATUS, NULL, result); - } while(result[0] & (1 << 24)); + } while(result[0] & (1 << 31)); return false; } diff --git a/sw/bootloader/src/sc64.h b/sw/bootloader/src/sc64.h index 34b9971..311661e 100644 --- a/sw/bootloader/src/sc64.h +++ b/sw/bootloader/src/sc64.h @@ -102,7 +102,7 @@ void sc64_get_boot_info (sc64_boot_info_t *info); void sc64_set_time (rtc_time_t *t); void sc64_get_time (rtc_time_t *t); bool sc64_usb_write_ready (void); -bool sc64_usb_write (uint32_t *address, uint32_t length); +bool sc64_usb_write (uint32_t *address, uint8_t type, uint32_t length); bool sc64_usb_read_ready (uint8_t *type, uint32_t *length); bool sc64_usb_read (uint32_t *address, uint32_t length); bool sc64_sd_card_init (void); diff --git a/sw/bootloader/src/syscalls.c b/sw/bootloader/src/syscalls.c index 10c5b3b..70c1327 100644 --- a/sw/bootloader/src/syscalls.c +++ b/sw/bootloader/src/syscalls.c @@ -2,8 +2,8 @@ #include -extern char _sheap; -extern char _eheap; +extern char _sheap __attribute__((section(".data"))); +extern char _eheap __attribute__((section(".data"))); caddr_t _sbrk_r (struct _reent *prt, ptrdiff_t incr) { diff --git a/sw/controller/common.mk b/sw/controller/common.mk index 7dd1016..bee414e 100644 --- a/sw/controller/common.mk +++ b/sw/controller/common.mk @@ -6,7 +6,7 @@ OBJDUMP = $(TOOLCHAIN)objdump SIZE = $(TOOLCHAIN)size FLAGS = -mcpu=cortex-m0plus -mthumb -DSTM32G030xx $(USER_FLAGS) -g -ggdb3 -CFLAGS = -Og -Wall -ffunction-sections -fdata-sections -ffreestanding -MMD -MP -I./lib +CFLAGS = -Os -Wall -ffunction-sections -fdata-sections -ffreestanding -MMD -MP -I./lib LDFLAGS = -nostartfiles -Wl,--gc-sections SRC_DIR = src diff --git a/sw/controller/src/cfg.c b/sw/controller/src/cfg.c index 3db7e22..9a13144 100644 --- a/sw/controller/src/cfg.c +++ b/sw/controller/src/cfg.c @@ -402,12 +402,14 @@ void cfg_process (void) { break; case 'M': - if (cfg_translate_address(&args[0], args[1], false)) { + if (cfg_translate_address(&args[0], args[1] & 0xFFFFFF, false)) { cfg_set_error(CFG_ERROR_BAD_ADDRESS); return; } usb_create_packet(&packet_info, PACKET_CMD_DEBUG_OUTPUT); - packet_info.dma_length = args[1]; + packet_info.data_length = 4; + packet_info.data[0] = args[1]; + packet_info.dma_length = args[1] & 0xFFFFFF; packet_info.dma_address = args[0]; packet_info.done_callback = cfg_set_usb_output_ready; if (usb_enqueue_packet(&packet_info)) { @@ -422,7 +424,7 @@ void cfg_process (void) { break; case 'U': - args[0] = p.usb_output_ready ? 1 : 0; + args[0] = p.usb_output_ready ? 0 : (1 << 31); break; case 'i': diff --git a/sw/controller/src/hw.c b/sw/controller/src/hw.c index d866244..cff7c0e 100644 --- a/sw/controller/src/hw.c +++ b/sw/controller/src/hw.c @@ -286,16 +286,15 @@ static void hw_flash_unlock (void) { while (FLASH->SR & FLASH_SR_BSY1); if (FLASH->CR & FLASH_CR_LOCK) { FLASH->KEYR = 0x45670123; + __ISB(); FLASH->KEYR = 0xCDEF89AB; } } void hw_flash_erase (void) { hw_flash_unlock(); - FLASH->CR |= FLASH_CR_MER1; - FLASH->CR |= FLASH_CR_STRT; + FLASH->CR |= (FLASH_CR_STRT | FLASH_CR_MER1); while (FLASH->SR & FLASH_SR_BSY1); - FLASH->CR &= ~(FLASH_CR_MER1); } void hw_flash_program (uint32_t offset, hw_flash_t value) { @@ -305,9 +304,6 @@ void hw_flash_program (uint32_t offset, hw_flash_t value) { __ISB(); *(__IO uint32_t *) (FLASH_BASE + offset + 4) = ((value >> 32) & 0xFFFFFFFF); while (FLASH->SR & FLASH_SR_BSY1); - if (FLASH->SR & FLASH_SR_EOP) { - FLASH->SR |= FLASH_SR_EOP; - } FLASH->CR &= ~(FLASH_CR_PG); } diff --git a/sw/controller/src/usb.c b/sw/controller/src/usb.c index f03bb93..e78f309 100644 --- a/sw/controller/src/usb.c +++ b/sw/controller/src/usb.c @@ -390,7 +390,7 @@ void usb_get_read_info (uint32_t *args) { args[0] = p.rx_args[0] & 0xFF; args[1] = p.rx_args[1]; } - args[0] |= (p.read_length > 0) ? (1 << 24) : 0; + args[0] |= (p.read_length > 0) ? (1 << 31) : 0; } void usb_init (void) { diff --git a/sw/pc/sc64.py b/sw/pc/sc64.py index 58c21a6..d17df2f 100755 --- a/sw/pc/sc64.py +++ b/sw/pc/sc64.py @@ -536,7 +536,14 @@ class SC64: print(data.decode('EUC-JP', errors='backslashreplace'), end='') def __handle_usb_packet(self, data: bytes) -> None: - print(data) + header = self.__get_int(data[0:4]) + datatype = ((header >> 24) & 0xFF) + length = (header & 0xFFFFFF) + packet = data[4:] + if (datatype == 0x01): + print(packet.decode('UTF-8', errors='backslashreplace'), end='') + else: + print(f'Unhandled USB packet - datatype: [{datatype}], length: [{length}]') def debug_loop(self, isv: bool=False, disks: Optional[list[str]]=None) -> None: dd = None