mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-22 05:59:15 +01:00
improved docker build, pyft232 instead of pyserial
This commit is contained in:
parent
42649d315b
commit
fbf26193d6
2
.vscode/tasks.json
vendored
2
.vscode/tasks.json
vendored
@ -31,7 +31,7 @@
|
||||
"group": "build"
|
||||
},
|
||||
{
|
||||
"label": "build_n64_bootloader",
|
||||
"label": "build_n64",
|
||||
"type": "shell",
|
||||
"command": "./docker_build.sh n64 -d",
|
||||
"presentation": {
|
||||
|
3
build.sh
3
build.sh
@ -22,7 +22,6 @@ BUILT_RELEASE=false
|
||||
FORCE_CLEAN=false
|
||||
SKIP_FPGA_REBUILD=false
|
||||
DEBUG_ENABLED=false
|
||||
USER_FLAGS+=" -D__SC64_VERSION=\"$__SC64_VERSION\""
|
||||
|
||||
build_cic () {
|
||||
if [ "$BUILT_CIC" = true ]; then return; fi
|
||||
@ -41,7 +40,7 @@ build_n64 () {
|
||||
if [ "$FORCE_CLEAN" = true ]; then
|
||||
make clean
|
||||
fi
|
||||
make all -j USER_FLAGS="$USER_FLAGS"
|
||||
make all -j USER_FLAGS="$USER_FLAGS -DGIT_BRANCH='$GIT_BRANCH' -DGIT_TAG='$GIT_TAG' -DGIT_SHA='$GIT_SHA' -DGIT_MESSAGE='$GIT_MESSAGE'"
|
||||
popd > /dev/null
|
||||
|
||||
BUILT_N64=true
|
||||
|
@ -1,23 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
GIT_SHA=$(git rev-parse HEAD)
|
||||
GIT_TAG=$(git describe --tags --exact-match 2> /dev/null)
|
||||
CONTAINER_NAME="sc64builder"
|
||||
|
||||
if [ -z $GIT_TAG ]; then
|
||||
GIT_TAG="develop"
|
||||
docker ps | grep $CONTAINER_NAME > /dev/null
|
||||
|
||||
if [ $? -eq 1 ]; then
|
||||
docker run \
|
||||
-dt --rm \
|
||||
--name $CONTAINER_NAME \
|
||||
--user $(id -u):$(id -g) \
|
||||
--mount type=bind,src="$(pwd)",target="/workdir" \
|
||||
ghcr.io/polprzewodnikowy/sc64env:v1.2
|
||||
fi
|
||||
|
||||
__SC64_VERSION=$(printf "[ %q | %q | %q ]" $GIT_BRANCH $GIT_TAG $GIT_SHA)
|
||||
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
GIT_TAG=$(git describe --tags 2> /dev/null)
|
||||
GIT_SHA=$(git rev-parse HEAD)
|
||||
GIT_MESSAGE=$(git log -1 --pretty=format:%B)
|
||||
|
||||
if [ -t 1 ]; then
|
||||
DOCKER_OPTIONS="-it"
|
||||
fi
|
||||
|
||||
docker run \
|
||||
--rm $DOCKER_OPTIONS \
|
||||
--user $(id -u):$(id -g) \
|
||||
--mount type=bind,src="$(pwd)",target="/workdir" \
|
||||
-e __SC64_VERSION="$__SC64_VERSION" \
|
||||
ghcr.io/polprzewodnikowy/sc64env:v1.2 \
|
||||
docker exec \
|
||||
$DOCKER_OPTIONS \
|
||||
-e GIT_BRANCH="$GIT_BRANCH" \
|
||||
-e GIT_TAG="$GIT_TAG" \
|
||||
-e GIT_SHA="$GIT_SHA" \
|
||||
-e GIT_MESSAGE="$GIT_MESSAGE" \
|
||||
$CONTAINER_NAME \
|
||||
./build.sh $@
|
||||
|
@ -29,6 +29,7 @@ SRC_FILES = \
|
||||
sc64.c \
|
||||
storage.c \
|
||||
syscalls.c \
|
||||
version.c \
|
||||
fatfs/diskio.c \
|
||||
fatfs/ff.c \
|
||||
fatfs/ffsystem.c \
|
||||
@ -71,6 +72,10 @@ all: $(BUILD_DIR)/n64boot.hex print_size
|
||||
clean:
|
||||
@rm -rf ./$(BUILD_DIR)/*
|
||||
|
||||
.PHONY: all clean print_size
|
||||
$(BUILD_DIR)/version.c.o: .FORCE
|
||||
|
||||
.FORCE:
|
||||
|
||||
.PHONY: .FORCE all clean print_size
|
||||
|
||||
-include $(DEPS)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "font.h"
|
||||
#include "io.h"
|
||||
#include "sc64.h"
|
||||
#include "version.h"
|
||||
#include "vr4300.h"
|
||||
|
||||
|
||||
@ -54,9 +55,6 @@ typedef struct {
|
||||
} exception_t;
|
||||
|
||||
|
||||
#define STR(x) #x
|
||||
#define XSTR(s) STR(s)
|
||||
|
||||
#define EXCEPTION_INTERRUPT (0)
|
||||
#define EXCEPTION_SYSCALL (8)
|
||||
|
||||
@ -74,7 +72,8 @@ typedef struct {
|
||||
#define FOREGROUND_COLOR (0x000000FFUL)
|
||||
#define BORDER_COLOR (0x2F2F2FFFUL)
|
||||
|
||||
#define LINE_HEIGHT (12)
|
||||
#define LINE_HEIGHT (10)
|
||||
#define START_X_OFFSET (19)
|
||||
|
||||
|
||||
static const vi_regs_t vi_config[] = {{
|
||||
@ -167,7 +166,7 @@ static void exception_draw_character (int x, int y, char c) {
|
||||
}
|
||||
|
||||
static void exception_print_string (const char *s) {
|
||||
static int x = BORDER_WIDTH;
|
||||
static int x = BORDER_WIDTH + (START_X_OFFSET * FONT_WIDTH);
|
||||
static int y = BORDER_HEIGHT;
|
||||
|
||||
while (*s != '\0') {
|
||||
@ -223,13 +222,19 @@ static const char *exception_get_description (uint8_t exception_code) {
|
||||
|
||||
|
||||
void exception_fatal_handler (uint32_t exception_code, uint32_t interrupt_mask, exception_t *e) {
|
||||
version_t *version = version_get();
|
||||
uint32_t sc64_version = pi_io_read(&SC64->VERSION);
|
||||
uint32_t *instruction_address = (((uint32_t *) (e->epc.u32)) + ((e->cr & C0_CR_BD) ? 1 : 0));
|
||||
|
||||
exception_init_screen();
|
||||
|
||||
exception_print("----- SummerCart64 n64boot -----\n");
|
||||
exception_print("branch: %s\n", version->git_branch);
|
||||
exception_print("tag: %s\n", version->git_tag);
|
||||
exception_print("sha: %s\n", version->git_sha);
|
||||
exception_print("msg: %s\n\n", version->git_message);
|
||||
exception_print("%s at pc: 0x%08lX\n\n", exception_get_description(exception_code), e->epc.u32);
|
||||
exception_print("sr: 0x%08lX cr: 0x%08lX\n", e->sr, e->cr);
|
||||
exception_print("sr: 0x%08lX cr: 0x%08lX hw: 0x%08lX [%4s]\n", e->sr, e->cr, sc64_version, (char *) (&sc64_version));
|
||||
exception_print("zr: 0x%08lX at: 0x%08lX v0: 0x%08lX v1: 0x%08lX\n", e->zr.u32, e->at.u32, e->v0.u32, e->v1.u32);
|
||||
exception_print("a0: 0x%08lX a1: 0x%08lX a2: 0x%08lX a3: 0x%08lX\n", e->a0.u32, e->a1.u32, e->a2.u32, e->a3.u32);
|
||||
exception_print("t0: 0x%08lX t1: 0x%08lX t2: 0x%08lX t3: 0x%08lX\n", e->t0.u32, e->t1.u32, e->t2.u32, e->t3.u32);
|
||||
@ -238,12 +243,10 @@ void exception_fatal_handler (uint32_t exception_code, uint32_t interrupt_mask,
|
||||
exception_print("s4: 0x%08lX s5: 0x%08lX s6: 0x%08lX s7: 0x%08lX\n", e->s4.u32, e->s5.u32, e->s6.u32, e->s7.u32);
|
||||
exception_print("t8: 0x%08lX t9: 0x%08lX k0: 0x%08lX k1: 0x%08lX\n", e->t8.u32, e->t9.u32, e->k0.u32, e->k1.u32);
|
||||
exception_print("gp: 0x%08lX sp: 0x%08lX fp: 0x%08lX ra: 0x%08lX\n\n", e->gp.u32, e->sp.u32, e->fp.u32, e->ra.u32);
|
||||
exception_print("vr: 0x%08lX = [%4s]\n", sc64_version, (char *) (&sc64_version));
|
||||
exception_print("%s\n\n", XSTR(__SC64_VERSION));
|
||||
|
||||
if (exception_code == EXCEPTION_INTERRUPT) {
|
||||
if (interrupt_mask & INTERRUPT_MASK_TIMER) {
|
||||
exception_print("Bootloader did not finish within 1 second limit\n");
|
||||
exception_print("Bootloader did not finish within 1 second limit\n\n");
|
||||
}
|
||||
} else if (exception_code == EXCEPTION_SYSCALL) {
|
||||
uint32_t code = (((*instruction_address) & SYSCALL_CODE_MASK) >> SYSCALL_CODE_BIT);
|
||||
@ -252,6 +255,7 @@ void exception_fatal_handler (uint32_t exception_code, uint32_t interrupt_mask,
|
||||
const char *fmt = (const char *) (e->a0.u32);
|
||||
va_list args = *((va_list *) (e->sp.u32));
|
||||
exception_vprint(fmt, args);
|
||||
exception_print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
18
sw/n64/src/version.c
Normal file
18
sw/n64/src/version.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#define STR(x) #x
|
||||
#define XSTR(s) STR(s)
|
||||
|
||||
|
||||
version_t version = {
|
||||
.git_branch = XSTR(GIT_BRANCH),
|
||||
.git_tag = XSTR(GIT_TAG),
|
||||
.git_sha = XSTR(GIT_SHA),
|
||||
.git_message = XSTR(GIT_MESSAGE),
|
||||
};
|
||||
|
||||
|
||||
version_t *version_get (void) {
|
||||
return &version;
|
||||
}
|
16
sw/n64/src/version.h
Normal file
16
sw/n64/src/version.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef VERSION_H__
|
||||
#define VERSION_H__
|
||||
|
||||
|
||||
typedef const struct {
|
||||
const char *git_branch;
|
||||
const char *git_tag;
|
||||
const char *git_sha;
|
||||
const char *git_message;
|
||||
} version_t;
|
||||
|
||||
|
||||
const version_t *version_get (void);
|
||||
|
||||
|
||||
#endif
|
@ -1,2 +1,2 @@
|
||||
progressbar2==3.55.0
|
||||
pyserial==3.5
|
||||
pyft232==0.12
|
||||
|
@ -1,8 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from ft232 import Ft232, Ft232Exception
|
||||
from io import TextIOWrapper
|
||||
from serial import Serial, SerialException
|
||||
from serial.tools import list_ports
|
||||
import argparse
|
||||
import filecmp
|
||||
import os
|
||||
@ -61,7 +60,7 @@ class SC64:
|
||||
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.__serial = None
|
||||
self.__usb = None
|
||||
self.__progress_init = None
|
||||
self.__progress_value = None
|
||||
self.__progress_finish = None
|
||||
@ -73,8 +72,8 @@ class SC64:
|
||||
|
||||
|
||||
def __del__(self) -> None:
|
||||
if (self.__serial):
|
||||
self.__serial.close()
|
||||
if (self.__usb):
|
||||
self.__usb.close()
|
||||
if (self.__fsd_file):
|
||||
self.__fsd_file.close()
|
||||
|
||||
@ -103,18 +102,17 @@ class SC64:
|
||||
|
||||
|
||||
def reset_link(self) -> None:
|
||||
self.__serial.write(b"\x1BR")
|
||||
while (self.__serial.in_waiting):
|
||||
self.__serial.read_all()
|
||||
time.sleep(0.1)
|
||||
self.__usb.write(b"\x1BR")
|
||||
time.sleep(0.1)
|
||||
self.__usb.flushInput()
|
||||
|
||||
|
||||
def __read(self, bytes: int) -> bytes:
|
||||
return self.__serial.read(bytes)
|
||||
return self.__usb.read(bytes)
|
||||
|
||||
|
||||
def __write(self, data: bytes) -> None:
|
||||
self.__serial.write(self.__escape(data))
|
||||
self.__usb.write(self.__escape(data))
|
||||
|
||||
|
||||
def __read_long(self, length: int) -> bytes:
|
||||
@ -147,29 +145,25 @@ class SC64:
|
||||
self.__write_int(arg2)
|
||||
|
||||
|
||||
def reset_n64(self) -> None:
|
||||
self.__usb.cbus_setup(mask=1, init=0)
|
||||
time.sleep(0.1)
|
||||
self.__usb.cbus_setup(mask=0)
|
||||
|
||||
|
||||
def __find_sc64(self) -> None:
|
||||
ports = list_ports.comports()
|
||||
device_found = False
|
||||
if (self.__usb != None and not self.__usb.closed):
|
||||
self.__usb.close()
|
||||
|
||||
if (self.__serial != None and self.__serial.isOpen()):
|
||||
self.__serial.close()
|
||||
|
||||
for p in ports:
|
||||
if (p.vid == 0x0403 and p.pid == 0x6014 and p.serial_number.startswith("SC64")):
|
||||
try:
|
||||
self.__serial = Serial(p.device, timeout=1.0, write_timeout=1.0)
|
||||
self.__serial.flushOutput()
|
||||
self.reset_link()
|
||||
self.__probe_device()
|
||||
except (SerialException, SC64Exception):
|
||||
if (self.__serial):
|
||||
self.__serial.close()
|
||||
continue
|
||||
device_found = True
|
||||
break
|
||||
|
||||
if (not device_found):
|
||||
raise SC64Exception("No SummerCart64 device was found")
|
||||
try:
|
||||
self.__usb = Ft232(description="SummerCart64")
|
||||
self.__usb.flushOutput()
|
||||
self.reset_link()
|
||||
self.__probe_device()
|
||||
except Ft232Exception as e:
|
||||
if (self.__usb):
|
||||
self.__usb.close()
|
||||
raise SC64Exception(f"No SummerCart64 device was found: {e}")
|
||||
|
||||
|
||||
def __probe_device(self) -> None:
|
||||
@ -255,10 +249,10 @@ class SC64:
|
||||
|
||||
def update_firmware(self, file: str) -> None:
|
||||
self.__write_file_to_sdram(file, self.__UPDATE_OFFSET)
|
||||
saved_timeout = self.__serial.timeout
|
||||
self.__serial.timeout = 20.0
|
||||
saved_timeout = self.__usb.timeout
|
||||
self.__usb.timeout = 20.0
|
||||
self.__change_config(self.__CFG_ID_FLASH_PROGRAM, self.__UPDATE_OFFSET)
|
||||
self.__serial.timeout = saved_timeout
|
||||
self.__usb.timeout = saved_timeout
|
||||
self.__reconfigure()
|
||||
self.__find_sc64()
|
||||
|
||||
@ -820,6 +814,8 @@ if __name__ == "__main__":
|
||||
sc64.download_save(save_file)
|
||||
else:
|
||||
sc64.upload_save(save_file)
|
||||
|
||||
sc64.reset_n64()
|
||||
|
||||
if (debug_server):
|
||||
sc64.debug_init(sd_file, disk_file, is_viewer_enabled)
|
||||
|
Loading…
Reference in New Issue
Block a user