From: ljsebald <ljs...@us...> - 2023-06-08 00:15:51
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A serial program loader for the Dreamcast.". The branch, master has been updated via 62f5b4d83a1f6fede8eb59b333ed25a6299200c1 (commit) via 95628f1737926409ce2fff63f760ecd2f1b5791d (commit) via f9e809d69af432d8ae4da9f3fdb971ccac9662a9 (commit) via f2ee6bfbcd4c72baa6f4d25adaaec65a70c5b305 (commit) via 2dfabbf29cf44a01d5a07afbda11c98918e9aa03 (commit) via c6dab7f29b583359a9412abb06a93ac0b35321ce (commit) via d0767aeceb491d4336ee2792369db2e2453b8272 (commit) via 2b0af8b30f9744d8340f0d84571341849c7f0b32 (commit) via 8401e6587863d0ed9baf2c811c14ed0402327102 (commit) via f429a6f3b4af2d4cc2b4b1880ceb720865b78fff (commit) via 124d4729c619b56e4d052c261bca711c653692f3 (commit) from ac4a00d7165f2b84cea985a5f389a575ddf66ced (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 62f5b4d83a1f6fede8eb59b333ed25a6299200c1 Author: darcagn <da...@pr...> Date: Wed Jun 7 19:15:24 2023 -0500 Set initial speed to a constant 56kbps and rework defaults from Makefile.cfg (#14) commit 95628f1737926409ce2fff63f760ecd2f1b5791d Merge: ac4a00d f9e809d Author: Lawrence Sebald <ljs...@us...> Date: Sun Mar 12 21:47:00 2023 -0400 Merge pull request #9 from sizious/build-compat-updates Additional MinGW/MinGW-w64 build updates. commit f9e809d69af432d8ae4da9f3fdb971ccac9662a9 Author: SiZiOUS <si...@gm...> Date: Sat Mar 11 22:36:03 2023 +0100 Removing useless white spaces in `Makefile.cfg`. Again. commit f2ee6bfbcd4c72baa6f4d25adaaec65a70c5b305 Author: SiZiOUS <si...@gm...> Date: Sat Mar 11 22:24:18 2023 +0100 `dc-tool`: Removing useless white spaces in `Makefile`. commit 2dfabbf29cf44a01d5a07afbda11c98918e9aa03 Author: SiZiOUS <si...@gm...> Date: Sat Mar 11 22:03:23 2023 +0100 `Makefile.cfg`: Adding some comments. commit c6dab7f29b583359a9412abb06a93ac0b35321ce Author: SiZiOUS <si...@gm...> Date: Sat Mar 11 21:25:02 2023 +0100 Use of `STANDALONE_BINARY` for static flag instead of `HOSTLDFLAGS`. STANDALONE_BINARY is now activated by default on Windows (i.e., Cygwin, MinGW/MSYS and MinGW-w64/MSYS2). Added some comments on libbfd. commit d0767aeceb491d4336ee2792369db2e2453b8272 Author: SiZiOUS <si...@gm...> Date: Mon Mar 6 10:08:31 2023 +0100 `dc-tool`: Adding compatibility layer for MinGW/MSYS in case of the toolchains were built on MinGW-w64/MSYS2 Mainly, this is for linking 'dc-tool' with 'libbfd'. Declaring these functions will let us to build 'dc-tool' even if 'sh-elf' toolchain was built on MinGW-w64/MSYS2. The new 'utils.c' file provides the following functions: `vasprintf`, `libintl_asprintf`, `__ms_vsnprintf` and `_imp____acrt_iob_func`. commit 2b0af8b30f9744d8340f0d84571341849c7f0b32 Author: SiZiOUS <si...@gm...> Date: Mon Mar 6 09:47:18 2023 +0100 `dc-tool`: Fix white space typo for `ZLIB_REQUIRED`. Sorry about that. commit 8401e6587863d0ed9baf2c811c14ed0402327102 Author: SiZiOUS <si...@gm...> Date: Mon Mar 6 09:41:19 2023 +0100 `dc-tool`: Adding `-static` on the top and concatenate `LDFLAGS` commit f429a6f3b4af2d4cc2b4b1880ceb720865b78fff Author: SiZiOUS <si...@gm...> Date: Mon Mar 6 09:38:34 2023 +0100 `dc-tool`: Better handling of zlib linking Now `-lz` is added to the command line once at the correct position. commit 124d4729c619b56e4d052c261bca711c653692f3 Author: SiZiOUS <si...@gm...> Date: Mon Mar 6 09:29:39 2023 +0100 `dc-tool`: Adding some comments to `Makefile`. ----------------------------------------------------------------------- Summary of changes: Makefile.cfg | 37 +++++++++++++++-------- host-src/tool/Makefile | 36 ++++++++++++++++------- host-src/tool/dc-tool.c | 22 +++++++------- host-src/tool/utils.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ target-src/dcload/Makefile | 2 +- target-src/dcload/dcload.c | 6 ++-- 6 files changed, 140 insertions(+), 36 deletions(-) create mode 100644 host-src/tool/utils.c diff --git a/Makefile.cfg b/Makefile.cfg index 561255c..56bc457 100644 --- a/Makefile.cfg +++ b/Makefile.cfg @@ -12,7 +12,6 @@ HOSTLDFLAGS = -L/usr/local/lib # For MinGW/MSYS, MinGW-w64/MSYS2 and Cygwin ifdef WINDOWS HOSTCFLAGS += -D_WIN32 - HOSTLDFLAGS += -static EXECUTABLEEXTENSION = .exe endif @@ -23,8 +22,9 @@ TARGETPREFIX = /opt/toolchains/dc/sh-elf # dir to install dc-tool in TOOLINSTALLDIR = /opt/toolchains/dc/bin -# To build dc-tool, we need to use libelf or libfd -# By default, libelf is used +# To build dc-tool, we need to use libelf or libbfd +# By default, libelf is used, except for MinGW/MSYS which uses libbfd. +# libbfd is installed using dc-chain, an utility provided with KallistiOS. # Define this if you want to use libbfd instead of libelf (which is default) WITH_BFD = 0 @@ -34,10 +34,10 @@ ifdef MINGW WITH_BFD = 1 endif -# You may have to change the paths for BFDLIB and BFDINCLUDE to the correct -# ones for your system. These must point to your sh-elf bfd, not the system one! -# If you built the dc-chain with the v0.4, you'll have it installed in the -# correct location. +# You may have to change the paths for BFDLIB and BFDINCLUDE to the correct +# ones for your system. These must point to your sh-elf BFD, not the system one! +# If you built your Sega Dreamcast toolchains with dc-chain, you'll have it +# installed in the correct location. BFDLIB = $(TARGETPREFIX)/lib BFDINCLUDE = $(TARGETPREFIX)/include @@ -60,7 +60,7 @@ TARGETLD = $(TARGETPREFIX)/bin/sh-elf-ld # set TARGETCCVER to 3 or 4, depending on your SH compiler version (gcc 3.x or gcc 4.x) # this line tries to detect the version automatically - +# This only matters for building the example sources. # if version > 4 then it's 4 TARGETCCVER = $(shell $(TARGETCC) --version | head -1 | sed "s/.* \([[:digit:]][[:digit:]]*\)\.[[:digit:]][[:digit:]]*.*/\1/") ifeq ($(shell test $(TARGETCCVER) -gt 4; echo $$?),0) @@ -69,23 +69,36 @@ endif # You generally shouldn't change this unless you are making forked # versions (or test versions) -VERSION = 1.0.6 +# Version numbers must be of the form x.x.x +VERSION = 1.0.6 # Define this if you want a standalone, statically linked, no dependency binary -# This is on by default for MinGW/MSYS #STANDALONE_BINARY = 1 +# This is on by default for Windows (MinGW/MSYS, MinGW-w64/MSYS2 and Cygwin) +ifdef WINDOWS + STANDALONE_BINARY = 1 +endif + # this is the default port for dc-tool, it can be changed on the commandline +# used for *nix systems SERIALDEVICE = /dev/ttyS0 +# alternative setting for USB-based serial interfaces +#SERIALDEVICE = /dev/ttyUSB0 # macOS -- you'll need to go look in /dev to see what the actual device # name is, and depending on the device, it must be plugged into the same # port each time. #SERIALDEVICE = /dev/cu.usbserial-5B24 +# Windows -- it's usually COM1 ifdef WINDOWS SERIALDEVICE = COM1 endif -# default serial speed - YOU DO NOT NEED TO CHANGE THIS -SERIALSPEED = 57600 +# default speed for dc-tool - after initial connection is established, connection +# speed will change to this value, same as using the -b argument +# value must be one of 9600, 19200, 38400, 57600, 115200, 500000, or 1500000 +TOOL_DEFAULT_SPEED = 57600 +# USB-based serial devices can potentially achieve speeds of 500000 or 1500000 baud +#TOOL_DEFAULT_SPEED = 500000 diff --git a/host-src/tool/Makefile b/host-src/tool/Makefile index 7b8668f..bde45de 100644 --- a/host-src/tool/Makefile +++ b/host-src/tool/Makefile @@ -3,10 +3,20 @@ include ../../Makefile.cfg LZOPATH = ../../minilzo.106 CC = $(HOSTCC) -CFLAGS = $(HOSTCFLAGS) -DDCLOAD_VERSION=\"$(VERSION)\" -DBAUD_RATE=$(SERIALSPEED) -DSERIALDEVICE="\"$(SERIALDEVICE)\"" -DHAVE_GETOPT -DB1500000 -DB500000 +CFLAGS = $(HOSTCFLAGS) -DDCLOAD_VERSION=\"$(VERSION)\" -DDEFAULT_SPEED=$(TOOL_DEFAULT_SPEED) -DSERIALDEVICE="\"$(SERIALDEVICE)\"" -DHAVE_GETOPT -DB1500000 -DB500000 LDFLAGS = $(HOSTLDFLAGS) -INCLUDE = -I$(LZOPATH) -I/usr/local/include +INCLUDE = -I$(LZOPATH) -I/usr/local/include +# Adding static flag if asked +ifeq ($(STANDALONE_BINARY),1) + LDFLAGS += -static +endif + +# Determine if we need zlib or not in that context for building dc-tool +# The purpose of that is just to have '-lz' once at the end of the command line +ZLIB_REQUIRED := 0 + +# Linking with 'libelf' or 'libbfd' (sh-elf), depending of 'Makefile.cfg' ifeq ($(WITH_BFD),1) # Starting from Binutils 2.40, SFrame is required when using BFD LIBSFRAME = @@ -15,29 +25,33 @@ ifeq ($(WITH_BFD),1) endif CFLAGS += -DWITH_BFD - LDFLAGS = -L$(BFDLIB) -lbfd $(LIBSFRAME) -liberty -lintl -lz + LDFLAGS += -L$(BFDLIB) -lbfd $(LIBSFRAME) -liberty -lintl INCLUDE += -I$(BFDINCLUDE) + + ZLIB_REQUIRED := 1 else - LDFLAGS = -L$(ELFLIB) -lelf + LDFLAGS += -L$(ELFLIB) -lelf INCLUDE += -I$(ELFINCLUDE) endif -# Additional libraries for MinGW/MSYS +# Additional libraries for MinGW/MSYS or MinGW-w64/MSYS2 ifdef MINGW32 LDFLAGS += -lws2_32 -lwsock32 -liconv + ZLIB_REQUIRED := 1 endif -ifdef STANDALONE_BINARY - LDFLAGS += -lz -static +# Add zlib to the command line end... if required +ifeq ($(ZLIB_REQUIRED),1) + LDFLAGS += -lz endif DCTOOL = dc-tool-ser$(EXECUTABLEEXTENSION) -OBJECTS = dc-tool.o minilzo.o syscalls.o unlink.o +OBJECTS = dc-tool.o minilzo.o syscalls.o unlink.o utils.o LZOFILES = $(LZOPATH)/minilzo.c $(LZOPATH)/minilzo.h $(LZOPATH)/lzoconf.h .c.o: - $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< + $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< all: $(DCTOOL) @@ -48,7 +62,7 @@ minilzo.o: $(LZOFILES) $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< .PHONY : install -install: $(DCTOOL) | $(TOOLINSTALLDIR) +install: $(DCTOOL) | $(TOOLINSTALLDIR) cp $(DCTOOL) $(TOOLINSTALLDIR) $(TOOLINSTALLDIR): -mkdir $(TOOLINSTALLDIR) @@ -58,5 +72,5 @@ clean: rm -f $(OBJECTS) .PHONY : distclean -distclean: clean +distclean: clean rm -f $(DCTOOL) diff --git a/host-src/tool/dc-tool.c b/host-src/tool/dc-tool.c index 8883182..b4651b2 100644 --- a/host-src/tool/dc-tool.c +++ b/host-src/tool/dc-tool.c @@ -71,6 +71,8 @@ SOCKET gdb_server_socket = 0; SOCKET socket_fd = 0; #endif +#define INITIAL_SPEED 57600 + #define DCLOADBUFFER 16384 /* was 8192 */ #ifdef _WIN32 #define DATA_BITS 8 @@ -576,8 +578,8 @@ int open_serial(char *devicename, unsigned int speed, unsigned int *speedtest) speedsel = B9600; break; default: - printf("Unsupported baudrate (%d) - switching to default (%d)\n", speed, BAUD_RATE); - *speedtest = speed = BAUD_RATE; + printf("Unsupported baudrate (%d) - falling back to initial baudrate (%d)\n", speed, INITIAL_SPEED); + *speedtest = speed = INITIAL_SPEED; break; } } @@ -761,7 +763,7 @@ void usage(void) printf("-a <address> Set address to <address> (default: 0x8c010000)\n"); printf("-s <size> Set size to <size>\n"); printf("-t <device> Use <device> to communicate with dc (default: %s)\n", SERIALDEVICE); - printf("-b <baudrate> Use <baudrate> (default: %d)\n", BAUD_RATE); + printf("-b <baudrate> Use <baudrate> (default: %d)\n", DEFAULT_SPEED); printf("-e Try alternate 115200 (must also use -b 115200)\n"); printf("-E Use an external clock for the DC's serial port\n"); printf("-n Do not attach console and fileserver\n"); @@ -1180,7 +1182,7 @@ int main(int argc, char *argv[]) unsigned int dumbterm = 0; unsigned int quiet = 0; unsigned char command = 0; - unsigned int dummy, speed = BAUD_RATE; + unsigned int dummy, speed = DEFAULT_SPEED; char *device_name = SERIALDEVICE; unsigned int cdfs_redir = 0; unsigned char *isofile = 0; @@ -1310,16 +1312,16 @@ int main(int argc, char *argv[]) printf("External clock usage enabled\n"); /* test for resonable baud - this is for POSIX systems */ - if (speed != BAUD_RATE) { + if (speed != INITIAL_SPEED) { if (open_serial(device_name, speed, &speed)<0) return 1; close_serial(); } - if (open_serial(device_name, BAUD_RATE, &dummy)<0) + if (open_serial(device_name, INITIAL_SPEED, &dummy)<0) return 1; - if (speed != BAUD_RATE) + if (speed != INITIAL_SPEED) change_speed(device_name, speed); switch (command) { @@ -1342,9 +1344,9 @@ int main(int argc, char *argv[]) case 'u': printf("Upload <%s> at <0x%x>\n", filename, address); upload(filename, address); - change_speed(device_name, BAUD_RATE); + change_speed(device_name, INITIAL_SPEED); break; - case 'd': + case 'd': if (!size) { printf("You must specify a size (-s <size>) with download (-d <filename>)\n"); cleanup(); @@ -1353,7 +1355,7 @@ int main(int argc, char *argv[]) printf("Download %d bytes at <0x%x> to <%s>\n", size, address, filename); download(filename, address, size, quiet); - change_speed(device_name, BAUD_RATE); + change_speed(device_name, INITIAL_SPEED); break; default: if (dumbterm) diff --git a/host-src/tool/utils.c b/host-src/tool/utils.c new file mode 100644 index 0000000..ad5708f --- /dev/null +++ b/host-src/tool/utils.c @@ -0,0 +1,73 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> + +/* Detect MinGW/MSYS vs. MinGW-w64/MSYS2 */ +#ifdef __MINGW32__ +#include <_mingw.h> +# ifdef __MINGW64_VERSION_MAJOR +# define __RT_MINGW_W64__ +# else +# define __RT_MINGW_ORG__ +# endif +#endif /* __MINGW32__ */ + +#ifdef __RT_MINGW_ORG__ + +/* + * Compatibility layer for original, legacy MinGW/MSYS environment. + * This allow toolchains built on MinGW-w64/MSYS2 to be usable with MinGW/MSYS. + * Mainly, this is for linking 'dc-tool' with 'libbfd'. Declaring these + * functions will let us to build 'dc-tool' even if 'sh-elf' toolchain was built + * on MinGW-w64/MSYS2. + */ + +// Thanks to Dietrich Epp +// See: https://stackoverflow.com/a/40160038 +int vasprintf(char **strp, const char *fmt, va_list ap) { + int len = _vscprintf(fmt, ap); + if (len == -1) { + return -1; + } + size_t size = (size_t)len + 1; + char *str = malloc(size); + if (!str) { + return -1; + } + int r = __mingw_vsnprintf(str, len + 1, fmt, ap); + if (r == -1) { + free(str); + return -1; + } + *strp = str; + return r; +} + +// Thanks to Dietrich Epp +// See: https://stackoverflow.com/a/40160038 +int __cdecl __MINGW_NOTHROW libintl_asprintf(char **strp, const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + int r = vasprintf(strp, fmt, ap); + va_end(ap); + return r; +} + +// See: https://stackoverflow.com/a/60380005 +int __cdecl __MINGW_NOTHROW __ms_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr) { + return __mingw_vsnprintf(buffer, count, format, argptr); +} + +// Thanks to Kenji Uno and god +// See: https://github.com/HiraokaHyperTools/libacrt_iob_func +// See: https://stackoverflow.com/a/30894349 +FILE * __cdecl __MINGW_NOTHROW _imp____acrt_iob_func(int handle) { + switch (handle) { + case 0: return stdin; + case 1: return stdout; + case 2: return stderr; + } + return NULL; +} + +#endif /* __RT_MINGW_ORG__ */ diff --git a/target-src/dcload/Makefile b/target-src/dcload/Makefile index 01572c0..1ec8067 100644 --- a/target-src/dcload/Makefile +++ b/target-src/dcload/Makefile @@ -4,7 +4,7 @@ LZOPATH = ../../minilzo.106 LZO = ../../host-src/misc/lzo CC = $(TARGETCC) -CFLAGS = $(TARGETCFLAGS) -DDCLOAD_VERSION=\"$(VERSION)\" -DSERIALSPEED=$(SERIALSPEED) +CFLAGS = $(TARGETCFLAGS) -DDCLOAD_VERSION=\"$(VERSION)\" INCLUDE = -I$(LZOPATH) -I../../target-inc OBJCOPY = $(TARGETOBJCOPY) diff --git a/target-src/dcload/dcload.c b/target-src/dcload/dcload.c index 5fc8c39..253c43a 100644 --- a/target-src/dcload/dcload.c +++ b/target-src/dcload/dcload.c @@ -25,6 +25,8 @@ #define NAME "dcload-serial " DCLOAD_VERSION +#define INITIAL_SPEED 57600 + #define VIDMODEREG (volatile unsigned int *)0xa05f8044 #define VIDBORDER (volatile unsigned int *)0xa05f8040 @@ -312,7 +314,7 @@ int main(void) unsigned int console; unsigned int start; - scif_init(SERIALSPEED); + scif_init(INITIAL_SPEED); cdfs_redir_save(); /* will only save value once */ cdfs_redir_disable(); @@ -418,7 +420,7 @@ int main(void) scif_puts("\n"); break; default: - scif_init(SERIALSPEED); + scif_init(INITIAL_SPEED); break; } } hooks/post-receive -- A serial program loader for the Dreamcast. |