From 171e222ebedc75b07378b4eb75983b54196daa99 Mon Sep 17 00:00:00 2001 From: gblues Date: Tue, 8 May 2018 20:03:13 -0700 Subject: [PATCH 1/5] Add "compile" make target == DETAILS As part of the build system overhaul, I need to be able to compile without linking; this adds a "compile" target so that I can do that. Currently only implemented on the main Makefile and Wii U. --- Makefile | 2 ++ Makefile.wiiu | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 7e66bdb181..5a2e3ca75e 100644 --- a/Makefile +++ b/Makefile @@ -219,6 +219,8 @@ $(OBJDIR)/%.o: %.rc $(HEADERS) @$(if $(Q), $(shell echo echo WINDRES $<),) $(Q)$(WINDRES) -o $@ $< +compile: $(OBJ) + install: $(TARGET) rm -f $(OBJDIR)/git_version.o mkdir -p $(DESTDIR)$(BIN_DIR) 2>/dev/null || /bin/true diff --git a/Makefile.wiiu b/Makefile.wiiu index 9ac0deb15d..e6658624fc 100644 --- a/Makefile.wiiu +++ b/Makefile.wiiu @@ -316,6 +316,8 @@ $(BUILD_DIR)/$(TARGET).rpx: $(BUILD_DIR)/$(TARGET).rpx.elf $(ELF2RPL) .$(TARGET) @touch .$(TARGET).rpx.last $(Q)-$(ELF2RPL) $< $@ +compile: $(OBJ) + clean: rm -f $(OBJ) $(RPX_OBJ) $(HBL_ELF_OBJ) $(TARGET).elf $(TARGET).rpx.elf $(TARGET).rpx rm -f $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).rpx.elf $(BUILD_DIR)/$(TARGET).rpx From c161813f102cbc0548a5fe17de6cd02effae6b13 Mon Sep 17 00:00:00 2001 From: gblues Date: Tue, 8 May 2018 20:43:37 -0700 Subject: [PATCH 2/5] fix so object files are in expected location --- Makefile.wiiu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.wiiu b/Makefile.wiiu index e6658624fc..073b7f7d95 100644 --- a/Makefile.wiiu +++ b/Makefile.wiiu @@ -316,7 +316,7 @@ $(BUILD_DIR)/$(TARGET).rpx: $(BUILD_DIR)/$(TARGET).rpx.elf $(ELF2RPL) .$(TARGET) @touch .$(TARGET).rpx.last $(Q)-$(ELF2RPL) $< $@ -compile: $(OBJ) +compile: $(OBJ) $(HBL_ELF_OBJ) clean: rm -f $(OBJ) $(RPX_OBJ) $(HBL_ELF_OBJ) $(TARGET).elf $(TARGET).rpx.elf $(TARGET).rpx From f22c337cfca20016dd1c1ff530d01f27787cce25 Mon Sep 17 00:00:00 2001 From: gblues Date: Mon, 4 Jun 2018 23:50:59 -0700 Subject: [PATCH 3/5] WIIU: cleanup and build-out of wiiu bootstrap code I used the code in `wiiu/` to bootstrap my own WiiU homebrew app; this PR reflects some changes I needed to make, that might be useful upstream. 1. Clean up filesystem initialization Filesystem driver initialization was lumped in with filesystem mounting; and that was a problem in my project, because I needed to be able to remount the SD card on the fly. So, now it's split up. I've added a callback object named "hooks" that can be used by consuming applications to handle filesystem mounting and unmounting. If these hooks are not provided, then the existing default behavior occurs. 2. Expand socket handling - add `SO_NONBLOCK` flag for non-blocking socket I/O - add normal errno defines like `EWOULDBLOCK` `EAGAIN`. 3. Remove RetroArch dependencies - the exception handler protects usage of version_git with `#ifdef HAVE_GIT_VERSION` but not the include, so I added that. It also technically depends on version.h, but I'm not touching that. It's easy enough to implement and I needed the same functionality. I'm not sure what the best solution for that dependency is. - missing_libc_functions.c included features/features_cpu.h which is a libretro include. This appears to be a stale include though, because everything compiles and works without it. - an ifdef referencing the RA "WIIU" define, rather than the devkitpro "__wiiu__" define --- Makefile | 2 - Makefile.wiiu | 2 - frontend/drivers/platform_wiiu.c | 6 ++- wiiu/include/sys/socket.h | 4 ++ wiiu/main.c | 66 +++++++++++++++++++--------- wiiu/system/exception_handler.c | 3 +- wiiu/system/imports.h | 7 +++ wiiu/system/missing_libc_functions.c | 1 - wiiu/wiiu_dbg.h | 2 +- wiiu/wiiu_main.h | 16 +++++++ 10 files changed, 81 insertions(+), 28 deletions(-) create mode 100644 wiiu/wiiu_main.h diff --git a/Makefile b/Makefile index 5a2e3ca75e..7e66bdb181 100644 --- a/Makefile +++ b/Makefile @@ -219,8 +219,6 @@ $(OBJDIR)/%.o: %.rc $(HEADERS) @$(if $(Q), $(shell echo echo WINDRES $<),) $(Q)$(WINDRES) -o $@ $< -compile: $(OBJ) - install: $(TARGET) rm -f $(OBJDIR)/git_version.o mkdir -p $(DESTDIR)$(BIN_DIR) 2>/dev/null || /bin/true diff --git a/Makefile.wiiu b/Makefile.wiiu index 073b7f7d95..9ac0deb15d 100644 --- a/Makefile.wiiu +++ b/Makefile.wiiu @@ -316,8 +316,6 @@ $(BUILD_DIR)/$(TARGET).rpx: $(BUILD_DIR)/$(TARGET).rpx.elf $(ELF2RPL) .$(TARGET) @touch .$(TARGET).rpx.last $(Q)-$(ELF2RPL) $< $@ -compile: $(OBJ) $(HBL_ELF_OBJ) - clean: rm -f $(OBJ) $(RPX_OBJ) $(HBL_ELF_OBJ) $(TARGET).elf $(TARGET).rpx.elf $(TARGET).rpx rm -f $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).rpx.elf $(BUILD_DIR)/$(TARGET).rpx diff --git a/frontend/drivers/platform_wiiu.c b/frontend/drivers/platform_wiiu.c index 1960e12ec3..2f5d484cff 100644 --- a/frontend/drivers/platform_wiiu.c +++ b/frontend/drivers/platform_wiiu.c @@ -49,7 +49,7 @@ #include "../../retroarch.h" #include "../../gfx/video_driver.h" - +#include "wiiu_main.h" #include "hbl.h" #include "wiiu_dbg.h" #include "system/exception_handler.h" @@ -68,6 +68,10 @@ * The Wii U frontend driver, along with the main() method. */ +/* TODO: If we want greater control over which filesystems get mounted, + * implement callbacks and assign them below. */ +hooks_t hooks = { NULL, NULL }; + static enum frontend_fork wiiu_fork_mode = FRONTEND_FORK_NONE; static const char *elf_path_cst = WIIU_SD_PATH "retroarch/retroarch.elf"; diff --git a/wiiu/include/sys/socket.h b/wiiu/include/sys/socket.h index aa1c20f60c..3486f5130f 100644 --- a/wiiu/include/sys/socket.h +++ b/wiiu/include/sys/socket.h @@ -22,12 +22,16 @@ extern "C" { #define SO_REUSEADDR 0x0004 #define SO_NBIO 0x1014 +#define SO_NONBLOCK 0x1016 /* return codes */ #define SO_SUCCESS 0 #define SO_EWOULDBLOCK 6 +#define EWOULDBLOCK SO_EWOULDBLOCK +#define EAGAIN SO_EWOULDBLOCK +#define ENOBUFS 105 /* No buffer space available */ typedef uint32_t socklen_t; typedef uint16_t sa_family_t; diff --git a/wiiu/main.c b/wiiu/main.c index 5a2a2e698e..3fcd225294 100644 --- a/wiiu/main.c +++ b/wiiu/main.c @@ -22,6 +22,8 @@ #include #include +#include "wiiu_main.h" + #include "hbl.h" #include "fs/fs_utils.h" @@ -50,7 +52,8 @@ void __init(void); static void fsdev_init(void); static void fsdev_exit(void); -static int iosuhaxMount = 0; +bool iosuhaxMount = 0; + static int mcp_hook_fd = -1; /* HBL elf entry point */ @@ -163,35 +166,58 @@ void MCPHookClose(void) mcp_hook_fd = -1; } +static bool try_init_iosuhax(void) +{ + int result = IOSUHAX_Open(NULL); + if(result < 0) + result = MCPHookOpen(); + + return (result < 0) ? false : true; +} + +static void try_shutdown_iosuhax(void) +{ + if(!iosuhaxMount) + return; + + if (mcp_hook_fd >= 0) + MCPHookClose(); + else + IOSUHAX_Close(); + + iosuhaxMount = false; +} + static void fsdev_init(void) { - iosuhaxMount = 0; - int res = IOSUHAX_Open(NULL); + iosuhaxMount = try_init_iosuhax(); - if (res < 0) - res = MCPHookOpen(); - - if (res < 0) - mount_sd_fat("sd"); + if(hooks.fs_mount != NULL && hooks.fs_unmount != NULL) + hooks.fs_mount(); else { - iosuhaxMount = 1; - fatInitDefault(); + if(iosuhaxMount) + fatInitDefault(); + else + mount_sd_fat("sd"); } } static void fsdev_exit(void) { - if (iosuhaxMount) - { - fatUnmount("sd:"); - fatUnmount("usb:"); + if(hooks.fs_mount != NULL && hooks.fs_unmount != NULL) - if (mcp_hook_fd >= 0) - MCPHookClose(); - else - IOSUHAX_Close(); - } + hooks.fs_unmount(); else - unmount_sd_fat("sd"); + { + if (iosuhaxMount) + { + fatUnmount("sd:"); + fatUnmount("usb:"); + } + else + unmount_sd_fat("sd"); + } + + try_shutdown_iosuhax(); } diff --git a/wiiu/system/exception_handler.c b/wiiu/system/exception_handler.c index 2caa0779c7..2f2e7f8d99 100644 --- a/wiiu/system/exception_handler.c +++ b/wiiu/system/exception_handler.c @@ -23,8 +23,9 @@ #include "wiiu_dbg.h" #include "exception_handler.h" #include "version.h" +#ifdef HAVE_GIT_VERSION #include "version_git.h" - +#endif /* Settings */ #define NUM_STACK_TRACE_LINES 5 diff --git a/wiiu/system/imports.h b/wiiu/system/imports.h index 0335c18755..e3685aaa1a 100644 --- a/wiiu/system/imports.h +++ b/wiiu/system/imports.h @@ -1,6 +1,13 @@ /* coreinit */ IMPORT_BEGIN(coreinit); +IMPORT(OSScreenInit); +IMPORT(OSScreenGetBufferSizeEx); +IMPORT(OSScreenSetBufferEx); +IMPORT(OSScreenEnableEx); +IMPORT(OSScreenFlipBuffersEx); +IMPORT(OSScreenClearBufferEx); +IMPORT(OSScreenPutFontEx); IMPORT(OSFatal); IMPORT(OSDynLoad_Acquire); IMPORT(OSDynLoad_FindExport); diff --git a/wiiu/system/missing_libc_functions.c b/wiiu/system/missing_libc_functions.c index 76c69f33e3..bc47266b3a 100644 --- a/wiiu/system/missing_libc_functions.c +++ b/wiiu/system/missing_libc_functions.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include diff --git a/wiiu/wiiu_dbg.h b/wiiu/wiiu_dbg.h index 5e22701484..fa259b8d6c 100644 --- a/wiiu/wiiu_dbg.h +++ b/wiiu/wiiu_dbg.h @@ -5,7 +5,7 @@ #include #include -#ifdef WIIU +#ifdef __wiiu__ #include #ifdef __cplusplus diff --git a/wiiu/wiiu_main.h b/wiiu/wiiu_main.h new file mode 100644 index 0000000000..7c16c813c4 --- /dev/null +++ b/wiiu/wiiu_main.h @@ -0,0 +1,16 @@ +#ifndef _MAIN_H +#define _MAIN_H + +#include "wiiu/types.h" + +struct main_hooks { + void (*fs_mount)(void); + void (*fs_unmount)(void); +}; + +typedef struct main_hooks hooks_t; + +extern hooks_t hooks; +extern bool iosuhaxMount; + +#endif /* _MAIN_H */ From 8b87a53366f4efe5853633fd1b101ff0982d18cd Mon Sep 17 00:00:00 2001 From: gblues Date: Thu, 7 Jun 2018 18:41:16 -0700 Subject: [PATCH 4/5] Replace hokey "hooks" struct with weak symbol annotations - Did a test build to ensure RA built - Copied over to my FTPservU sources and ensured no compile issues there Looks solid. A lot cleaner, too. @aliaspider --- frontend/drivers/platform_wiiu.c | 5 ---- wiiu/main.c | 46 ++++++++++++++++---------------- wiiu/wiiu_main.h | 10 ++----- 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/frontend/drivers/platform_wiiu.c b/frontend/drivers/platform_wiiu.c index 2f5d484cff..96cdcc6c7b 100644 --- a/frontend/drivers/platform_wiiu.c +++ b/frontend/drivers/platform_wiiu.c @@ -49,7 +49,6 @@ #include "../../retroarch.h" #include "../../gfx/video_driver.h" -#include "wiiu_main.h" #include "hbl.h" #include "wiiu_dbg.h" #include "system/exception_handler.h" @@ -68,10 +67,6 @@ * The Wii U frontend driver, along with the main() method. */ -/* TODO: If we want greater control over which filesystems get mounted, - * implement callbacks and assign them below. */ -hooks_t hooks = { NULL, NULL }; - static enum frontend_fork wiiu_fork_mode = FRONTEND_FORK_NONE; static const char *elf_path_cst = WIIU_SD_PATH "retroarch/retroarch.elf"; diff --git a/wiiu/main.c b/wiiu/main.c index 3fcd225294..b2cc511436 100644 --- a/wiiu/main.c +++ b/wiiu/main.c @@ -188,36 +188,36 @@ static void try_shutdown_iosuhax(void) iosuhaxMount = false; } +__attribute__((weak)) +void mount_filesystems(void) +{ + if(iosuhaxMount) + fatInitDefault(); + else + mount_sd_fat("sd"); +} + +__attribute__((weak)) +void unmount_filesystems(void) +{ + if (iosuhaxMount) + { + fatUnmount("sd:"); + fatUnmount("usb:"); + } + else + unmount_sd_fat("sd"); +} + static void fsdev_init(void) { iosuhaxMount = try_init_iosuhax(); - if(hooks.fs_mount != NULL && hooks.fs_unmount != NULL) - hooks.fs_mount(); - else - { - if(iosuhaxMount) - fatInitDefault(); - else - mount_sd_fat("sd"); - } + mount_filesystems(); } static void fsdev_exit(void) { - if(hooks.fs_mount != NULL && hooks.fs_unmount != NULL) - - hooks.fs_unmount(); - else - { - if (iosuhaxMount) - { - fatUnmount("sd:"); - fatUnmount("usb:"); - } - else - unmount_sd_fat("sd"); - } - + unmount_filesystems(); try_shutdown_iosuhax(); } diff --git a/wiiu/wiiu_main.h b/wiiu/wiiu_main.h index 7c16c813c4..4a8cbdb80d 100644 --- a/wiiu/wiiu_main.h +++ b/wiiu/wiiu_main.h @@ -3,14 +3,8 @@ #include "wiiu/types.h" -struct main_hooks { - void (*fs_mount)(void); - void (*fs_unmount)(void); -}; - -typedef struct main_hooks hooks_t; - -extern hooks_t hooks; +void mount_filesystems(void); +void unmount_filesystems(void); extern bool iosuhaxMount; #endif /* _MAIN_H */ From 9ea16c0b3d706c053bb46d63a0b019a44bf4506c Mon Sep 17 00:00:00 2001 From: gblues Date: Thu, 7 Jun 2018 21:16:49 -0700 Subject: [PATCH 5/5] Updates from PR feedback (ty @aliaspider) --- wiiu/main.c | 21 +++++++++++++++------ wiiu/wiiu_main.h | 10 ---------- 2 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 wiiu/wiiu_main.h diff --git a/wiiu/main.c b/wiiu/main.c index b2cc511436..dd20c62923 100644 --- a/wiiu/main.c +++ b/wiiu/main.c @@ -22,8 +22,6 @@ #include #include -#include "wiiu_main.h" - #include "hbl.h" #include "fs/fs_utils.h" @@ -188,8 +186,15 @@ static void try_shutdown_iosuhax(void) iosuhaxMount = false; } +/** + * Mount the filesystem(s) needed by the application. By default, we + * mount the SD card to /sd. + * + * The 'iosuhaxMount' symbol used here is public and can be referenced + * in overriding implementations. + */ __attribute__((weak)) -void mount_filesystems(void) +void __mount_filesystems(void) { if(iosuhaxMount) fatInitDefault(); @@ -197,8 +202,12 @@ void mount_filesystems(void) mount_sd_fat("sd"); } +/** + * Unmount filesystems. Implementing applications should be careful to + * clean up anything mounted in __mount_filesystems() here. + */ __attribute__((weak)) -void unmount_filesystems(void) +void __unmount_filesystems(void) { if (iosuhaxMount) { @@ -213,11 +222,11 @@ static void fsdev_init(void) { iosuhaxMount = try_init_iosuhax(); - mount_filesystems(); + __mount_filesystems(); } static void fsdev_exit(void) { - unmount_filesystems(); + __unmount_filesystems(); try_shutdown_iosuhax(); } diff --git a/wiiu/wiiu_main.h b/wiiu/wiiu_main.h deleted file mode 100644 index 4a8cbdb80d..0000000000 --- a/wiiu/wiiu_main.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _MAIN_H -#define _MAIN_H - -#include "wiiu/types.h" - -void mount_filesystems(void); -void unmount_filesystems(void); -extern bool iosuhaxMount; - -#endif /* _MAIN_H */