From a8ac2345f48d6e81001a501a1ef500db162517d9 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Mon, 30 Dec 2024 19:42:08 +0000 Subject: [PATCH] [Nx] allow for per vfs build options, add switch workflow. --- .github/workflows/build_switch.yml | 31 +++++ CMakeLists.txt | 176 ++++++++++++++++----------- src/platform/nx/vfs/vfs_nx_gc.c | 1 + src/platform/nx/vfs/vfs_nx_hdd.c | 1 + src/platform/nx/vfs/vfs_nx_save.c | 1 + src/platform/nx/vfs/vfs_nx_stdio.c | 1 + src/platform/nx/vfs/vfs_nx_storage.c | 1 + src/platform/nx/vfs_nx.c | 25 +++- src/platform/nx/vfs_nx.h | 41 ++++++- 9 files changed, 202 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/build_switch.yml diff --git a/.github/workflows/build_switch.yml b/.github/workflows/build_switch.yml new file mode 100644 index 0000000..982b702 --- /dev/null +++ b/.github/workflows/build_switch.yml @@ -0,0 +1,31 @@ +name: build_switch + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + preset: [switch] + runs-on: ${{ matrix.os }} + container: devkitpro/devkita64:latest + + steps: + - uses: actions/checkout@v3 + + # fetch latest cmake + - uses: lukka/get-cmake@latest + + - name: Configure CMake + # disable ftp-gc until dkpa64 container uses latest libnx + run: | + cmake --preset ${{ matrix.preset }} -DUSE_VFS_GC=0 + + - name: Build + run: cmake --build --preset ${{ matrix.preset }} --parallel 4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 78b4a2f..0256b2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,96 +216,130 @@ if (FTPSRV_LIB_BUILD) ) else() if (NINTENDO_SWITCH) + if (NOT DEFINED USE_VFS_SAVE) + set(USE_VFS_SAVE TRUE) + endif() + if (NOT DEFINED USE_VFS_STORAGE) + set(USE_VFS_STORAGE TRUE) + endif() + if (NOT DEFINED USE_VFS_GC) + set(USE_VFS_GC TRUE) + endif() + if (NOT DEFINED USE_VFS_USBHSFS) + set(USE_VFS_USBHSFS TRUE) + endif() + ftp_set_options(ftpsrv 769 128 1024*64) fetch_minini() - set(USBHSFS_GPL ON) - FetchContent_Declare(libusbhsfs - GIT_REPOSITORY https://github.com/DarkMatterCore/libusbhsfs.git - GIT_TAG v0.2.9 + set(NX_SRC + src/platform/nx/vfs_nx.c + src/platform/nx/vfs/vfs_nx_none.c + src/platform/nx/vfs/vfs_nx_root.c + src/platform/nx/vfs/vfs_nx_fs.c + src/platform/nx/reboot_to_payload/ams_bpc.c + src/platform/nx/reboot_to_payload/reboot_to_payload.c + src/platform/nx/rtc/max77620-rtc.c + src/platform/nx/custom_commands.c + src/platform/nx/utils.c + src/log/log.c ) - FetchContent_MakeAvailable(libusbhsfs) - add_library(libusbhsfs - ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_drive.c - ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_log.c - ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_manager.c - ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_mount.c - ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_request.c - ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_scsi.c - ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_utils.c + target_compile_definitions(ftpsrv PUBLIC + FTP_VFS_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/nx/vfs_nx.h" + FTP_SOCKET_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/unistd/socket_unistd.h" + VFS_NX_BUFFER_WRITES=1 ) - target_include_directories(libusbhsfs PUBLIC ${libusbhsfs_SOURCE_DIR}/include) + if (USE_VFS_SAVE) + list(APPEND NX_SRC src/platform/nx/vfs/vfs_nx_save.c) + endif() + if (USE_VFS_STORAGE) + list(APPEND NX_SRC src/platform/nx/vfs/vfs_nx_storage.c) + endif() + if (USE_VFS_GC) + list(APPEND NX_SRC src/platform/nx/vfs/vfs_nx_gc.c) + endif() - # fatfs stuff - target_sources(libusbhsfs PRIVATE - ${libusbhsfs_SOURCE_DIR}/source/fatfs/diskio.c - ${libusbhsfs_SOURCE_DIR}/source/fatfs/ff_dev.c - ${libusbhsfs_SOURCE_DIR}/source/fatfs/ff.c - ${libusbhsfs_SOURCE_DIR}/source/fatfs/ffsystem.c - ${libusbhsfs_SOURCE_DIR}/source/fatfs/ffunicode.c + add_executable(ftpexe + src/platform/nx/main.c + ${NX_SRC} ) - # sxos stuff - target_sources(libusbhsfs PRIVATE - ${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs_dev.c - ${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs.c + target_compile_definitions(ftpexe PUBLIC + USE_VFS_SAVE=$ + USE_VFS_STORAGE=$ + USE_VFS_GC=$ + USE_VFS_USBHSFS=$ ) - if (USBHSFS_GPL) + if (USE_VFS_USBHSFS) + set(USBHSFS_GPL ON) + FetchContent_Declare(libusbhsfs + GIT_REPOSITORY https://github.com/DarkMatterCore/libusbhsfs.git + GIT_TAG v0.2.9 + ) + + FetchContent_MakeAvailable(libusbhsfs) + add_library(libusbhsfs + ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_drive.c + ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_log.c + ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_manager.c + ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_mount.c + ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_request.c + ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_scsi.c + ${libusbhsfs_SOURCE_DIR}/source/usbhsfs_utils.c + ) + + target_include_directories(libusbhsfs PUBLIC ${libusbhsfs_SOURCE_DIR}/include) + + # fatfs stuff target_sources(libusbhsfs PRIVATE - ${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_dev.c - ${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_disk_io.c - ${libusbhsfs_SOURCE_DIR}/source/lwext4/ext.c + ${libusbhsfs_SOURCE_DIR}/source/fatfs/diskio.c + ${libusbhsfs_SOURCE_DIR}/source/fatfs/ff_dev.c + ${libusbhsfs_SOURCE_DIR}/source/fatfs/ff.c + ${libusbhsfs_SOURCE_DIR}/source/fatfs/ffsystem.c + ${libusbhsfs_SOURCE_DIR}/source/fatfs/ffunicode.c + ) - ${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_dev.c - ${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_disk_io.c - ${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs.c + # sxos stuff + target_sources(libusbhsfs PRIVATE + ${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs_dev.c + ${libusbhsfs_SOURCE_DIR}/source/sxos/usbfs.c ) - find_library(ntfs_3g_lib ntfs-3g REQUIRED) - find_path(ntfs_3g_inc ntfs-3g REQUIRED) + if (USBHSFS_GPL) + target_sources(libusbhsfs PRIVATE + ${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_dev.c + ${libusbhsfs_SOURCE_DIR}/source/lwext4/ext_disk_io.c + ${libusbhsfs_SOURCE_DIR}/source/lwext4/ext.c - find_library(lwext4_lib lwext4 REQUIRED) - find_path(lwext4_inc ext4.h REQUIRED) + ${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_dev.c + ${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs_disk_io.c + ${libusbhsfs_SOURCE_DIR}/source/ntfs-3g/ntfs.c + ) - target_link_libraries(libusbhsfs PRIVATE ${ntfs_3g_lib} ${lwext4_lib}) - target_include_directories(libusbhsfs PRIVATE ${ntfs_3g_inc} ${lwext4_inc}) - target_compile_definitions(libusbhsfs PRIVATE GPL_BUILD) - endif() + find_library(ntfs_3g_lib ntfs-3g REQUIRED) + find_path(ntfs_3g_inc ntfs-3g REQUIRED) - target_compile_definitions(ftpsrv PUBLIC - FTP_VFS_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/nx/vfs_nx.h" - FTP_SOCKET_HEADER="${CMAKE_CURRENT_SOURCE_DIR}/src/platform/unistd/socket_unistd.h" - VFS_NX_BUFFER_WRITES=1 - ) + find_library(lwext4_lib lwext4 REQUIRED) + find_path(lwext4_inc ext4.h REQUIRED) - set(NX_SRC - src/platform/nx/vfs_nx.c - src/platform/nx/vfs/vfs_nx_none.c - src/platform/nx/vfs/vfs_nx_root.c - src/platform/nx/vfs/vfs_nx_fs.c - src/platform/nx/vfs/vfs_nx_save.c - src/platform/nx/vfs/vfs_nx_storage.c - src/platform/nx/vfs/vfs_nx_gc.c - src/platform/nx/utils.c - src/platform/nx/reboot_to_payload/ams_bpc.c - src/platform/nx/reboot_to_payload/reboot_to_payload.c - src/platform/nx/rtc/max77620-rtc.c - src/platform/nx/custom_commands.c - src/log/log.c - ) + target_link_libraries(libusbhsfs PRIVATE ${ntfs_3g_lib} ${lwext4_lib}) + target_include_directories(libusbhsfs PRIVATE ${ntfs_3g_inc} ${lwext4_inc}) + target_compile_definitions(libusbhsfs PRIVATE GPL_BUILD) + endif() + + target_link_libraries(ftpexe PRIVATE libusbhsfs) + + target_sources(ftpexe PRIVATE + src/platform/nx/vfs/vfs_nx_stdio.c + src/platform/nx/vfs/vfs_nx_hdd.c + ) + endif() - add_executable(ftpexe - src/platform/nx/main.c - src/platform/nx/vfs/vfs_nx_stdio.c - src/platform/nx/vfs/vfs_nx_hdd.c - ${NX_SRC} - ) - target_compile_definitions(ftpexe PUBLIC USE_USBHSFS=1) ftp_add(ftpexe) - target_link_libraries(ftpexe PRIVATE ftpsrv minIni libusbhsfs) + target_link_libraries(ftpexe PRIVATE ftpsrv minIni) nx_generate_nacp( OUTPUT ftpexe.nacp @@ -337,6 +371,12 @@ else() ftp_add(sysftp) target_link_libraries(sysftp PRIVATE ftpsrv_sysmod minIni) + target_compile_definitions(ftpexe PUBLIC + USE_VFS_SAVE=$ + USE_VFS_STORAGE=$ + USE_VFS_GC=$ + ) + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/420000000000011B) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/420000000000011B/flags) diff --git a/src/platform/nx/vfs/vfs_nx_gc.c b/src/platform/nx/vfs/vfs_nx_gc.c index 49fdde6..1dc5b39 100644 --- a/src/platform/nx/vfs/vfs_nx_gc.c +++ b/src/platform/nx/vfs/vfs_nx_gc.c @@ -4,6 +4,7 @@ */ #include "ftpsrv_vfs.h" +#include "vfs_nx_gc.h" #include "log/log.h" #include #include diff --git a/src/platform/nx/vfs/vfs_nx_hdd.c b/src/platform/nx/vfs/vfs_nx_hdd.c index 5c9776a..aa1d344 100644 --- a/src/platform/nx/vfs/vfs_nx_hdd.c +++ b/src/platform/nx/vfs/vfs_nx_hdd.c @@ -4,6 +4,7 @@ */ #include "ftpsrv_vfs.h" +#include "vfs_nx_hdd.h" #include "log/log.h" #include #include diff --git a/src/platform/nx/vfs/vfs_nx_save.c b/src/platform/nx/vfs/vfs_nx_save.c index ac38c4a..4d5aa6c 100644 --- a/src/platform/nx/vfs/vfs_nx_save.c +++ b/src/platform/nx/vfs/vfs_nx_save.c @@ -4,6 +4,7 @@ */ #include "ftpsrv_vfs.h" +#include "vfs_nx_save.h" #include "../utils.h" #include "log/log.h" #include diff --git a/src/platform/nx/vfs/vfs_nx_stdio.c b/src/platform/nx/vfs/vfs_nx_stdio.c index 3c82573..ee955e6 100644 --- a/src/platform/nx/vfs/vfs_nx_stdio.c +++ b/src/platform/nx/vfs/vfs_nx_stdio.c @@ -4,6 +4,7 @@ */ #include "ftpsrv_vfs.h" +#include "vfs_nx_stdio.h" #include "log/log.h" #include #include diff --git a/src/platform/nx/vfs/vfs_nx_storage.c b/src/platform/nx/vfs/vfs_nx_storage.c index 2348b47..5b7476d 100644 --- a/src/platform/nx/vfs/vfs_nx_storage.c +++ b/src/platform/nx/vfs/vfs_nx_storage.c @@ -1,4 +1,5 @@ #include "ftpsrv_vfs.h" +#include "vfs_nx_storage.h" #include "log/log.h" #include #include diff --git a/src/platform/nx/vfs_nx.c b/src/platform/nx/vfs_nx.c index 6ee0464..6cf253f 100644 --- a/src/platform/nx/vfs_nx.c +++ b/src/platform/nx/vfs_nx.c @@ -26,10 +26,16 @@ static const FtpVfs* g_vfs[] = { [VFS_TYPE_NONE] = &g_vfs_none, [VFS_TYPE_ROOT] = &g_vfs_root, [VFS_TYPE_FS] = &g_vfs_fs, +#if USE_VFS_SAVE [VFS_TYPE_SAVE] = &g_vfs_save, +#endif +#if USE_VFS_STORAGE [VFS_TYPE_STORAGE] = &g_vfs_storage, +#endif +#if USE_VFS_GC [VFS_TYPE_GC] = &g_vfs_gc, -#if USE_USBHSFS +#endif +#if USE_VFS_USBHSFS [VFS_TYPE_STDIO] = &g_vfs_stdio, [VFS_TYPE_HDD] = &g_vfs_hdd, #endif @@ -299,8 +305,10 @@ void vfs_nx_init(bool enable_devices, bool save_writable, bool mount_bis) { } // bis storage +#if USE_VFS_STORAGE vfs_storage_init(); vfs_nx_add_device("bis", VFS_TYPE_STORAGE); +#endif // bis fs if (mount_bis) { @@ -351,13 +359,18 @@ void vfs_nx_init(bool enable_devices, bool save_writable, bool mount_bis) { } } +#if USE_VFS_GC if (R_SUCCEEDED(vfs_gc_init())) { vfs_nx_add_device("gc", VFS_TYPE_GC); } +#endif +#if USE_VFS_SAVE vfs_save_init(save_writable); vfs_nx_add_device("save", VFS_TYPE_SAVE); -#if USE_USBHSFS +#endif + +#if USE_VFS_USBHSFS if (R_SUCCEEDED(romfsMountFromCurrentProcess("romfs"))) { vfs_nx_add_device("romfs", VFS_TYPE_STDIO); } @@ -388,11 +401,17 @@ void vfs_nx_init(bool enable_devices, bool save_writable, bool mount_bis) { void vfs_nx_exit(void) { if (g_enabled_devices) { +#if USE_VFS_GC vfs_gc_exit(); +#endif +#if USE_VFS_STORAGE vfs_storage_exit(); +#endif +#if USE_VFS_SAVE vfs_save_exit(); +#endif vfs_root_exit(); -#if USE_USBHSFS +#if USE_VFS_USBHSFS romfsUnmount("romfs_qlaunch"); romfsUnmount("romfs"); vfs_hdd_exit(); diff --git a/src/platform/nx/vfs_nx.h b/src/platform/nx/vfs_nx.h index 1c1c9c0..5898007 100644 --- a/src/platform/nx/vfs_nx.h +++ b/src/platform/nx/vfs_nx.h @@ -14,10 +14,17 @@ extern "C" { #include "vfs/vfs_nx_none.h" #include "vfs/vfs_nx_root.h" #include "vfs/vfs_nx_fs.h" + +#if USE_VFS_SAVE #include "vfs/vfs_nx_save.h" +#endif +#if USE_VFS_STORAGE #include "vfs/vfs_nx_storage.h" +#endif +#if USE_VFS_GC #include "vfs/vfs_nx_gc.h" -#if USE_USBHSFS +#endif +#if USE_VFS_USBHSFS #include "vfs/vfs_nx_stdio.h" #include "vfs/vfs_nx_hdd.h" #endif @@ -26,10 +33,16 @@ enum VFS_TYPE { VFS_TYPE_NONE, VFS_TYPE_ROOT, // list root devices VFS_TYPE_FS, // list native fs devices +#if USE_VFS_SAVE VFS_TYPE_SAVE, // list saves, uses fs +#endif +#if USE_VFS_STORAGE VFS_TYPE_STORAGE, // list read-only bis storage +#endif +#if USE_VFS_GC VFS_TYPE_GC, // list cert and secure partition -#if USE_USBHSFS +#endif +#if USE_VFS_USBHSFS VFS_TYPE_STDIO, // used for romfs and hdd VFS_TYPE_HDD, // list hdd, uses unistd #endif @@ -40,10 +53,16 @@ struct FtpVfsFile { union { struct VfsRootFile root; struct VfsFsFile fs; +#if USE_VFS_SAVE struct VfsSaveFile save; +#endif +#if USE_VFS_STORAGE struct VfsStorageFile storage; +#endif +#if USE_VFS_GC struct VfsGcFile gc; -#if USE_USBHSFS +#endif +#if USE_VFS_USBHSFS struct VfsStdioFile stdio; struct VfsHddFile usbhsfs; #endif @@ -55,10 +74,16 @@ struct FtpVfsDir { union { struct VfsRootDir root; struct VfsFsDir fs; +#if USE_VFS_SAVE struct VfsSaveDir save; +#endif +#if USE_VFS_STORAGE struct VfsStorageDir storage; +#endif +#if USE_VFS_GC struct VfsGcDir gc; -#if USE_USBHSFS +#endif +#if USE_VFS_USBHSFS struct VfsStdioDir stdio; struct VfsHddDir usbhsfs; #endif @@ -70,10 +95,16 @@ struct FtpVfsDirEntry { union { struct VfsRootDirEntry root; struct VfsFsDirEntry fs; +#if USE_VFS_SAVE struct VfsSaveDirEntry save; +#endif +#if USE_VFS_STORAGE struct VfsStorageDirEntry storage; +#endif +#if USE_VFS_GC struct VfsGcDirEntry gc; -#if USE_USBHSFS +#endif +#if USE_VFS_USBHSFS struct VfsStdioDirEntry stdio; struct VfsHddDirEntry usbhsfs; #endif