diff --git a/Makefile b/Makefile index ba1b026..2524498 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ SHARE := ./share SOURCES := source CFILES := $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.c)) OFILES := $(CFILES:.c=.o) -INSTALLDIR ?= $(PORTLIBS) +INSTALLDIR ?= $(WUT_ROOT) CFLAGS += -O3 #--------------------------------------------------------------------------------- @@ -29,9 +29,6 @@ clean: rm -rf $(OFILES) $(CFILES:.c=.d) $(TARGET) #--------------------------------------------------------------------------------- -# wut and portlibs +# wut #--------------------------------------------------------------------------------- -include $(WUT_ROOT)/share/wut.mk -PORTLIBS := $(DEVKITPRO)/portlibs/ppc -LDFLAGS += -L$(PORTLIBS)/lib -CFLAGS += -I$(PORTLIBS)/include \ No newline at end of file +include $(WUT_ROOT)/share/wut.mk \ No newline at end of file diff --git a/README.txt b/README.txt index c180e08..9fa4450 100644 --- a/README.txt +++ b/README.txt @@ -2,31 +2,54 @@ libromfs-wiiu --------------------------------------------------------------------------------- -* Informations +**** Informations **** This library provides a romfs partition implementation for the Nintendo Wii U. It's a special filesystem where files needed by applications can be stored in a read-only manner and embedded into the executable (removing the need for additional files on the sdcard). It provides provides low latency and access times since files, once the app has loaded, are stored in memory instead of being loaded from the sdcard. +This library is made for use with WUT -* Usage -Usage may vary over time, as the current implementation isn't optimal. Currently: +**** API **** + is the main header + + int romfsInit(void) + Mounts app's romfs. Returns 0 if succesfull or a negative + value if there was an error + + int romfsExit(void) + Unmounts app's romfs. Returns 0 if succesfull or a negative + value if there was an error + +romfs can be accessed trough normal file functions, +at the mountpoint "romfs:/" + + +**** Usage **** +[Usage may vary over time] - Create a romfs folder in the source tree - Edit your Makefile and add: 1. A ROMFS variable, specifying the relative path to the romfs folder - 2. An "include $(DEVKITPRO)/portlibs/ppc/share/romfs-wiiu.mk" (make sure + 2. An "include $(WUT_ROOT)/share/romfs-wiiu.mk" (make sure it's included *after* exporting the ROMFS variable or it won't work) - 3. $(ROMFS_TARGET) to target dependencies and linked objects + 3. $(ROMFS_TARGET) to target's dependencies and linked objects + 4. $(ROMFS_LDFLAGS) to app's LDFLAGS + - Add calls to romfsInit() and romfsExit() in your application's code + + +**** Installation **** +The library can be installed by running "make install" in this repo's root. +By default the library will be installed to $WUT_ROOT. The installation path +can be customized with the INSTALLDIR parameter. -* Installing -Run "make install" in this repository's root. -Make sure you exported the $DEVKITPRO envrivrioment variable and that $DEVKITPRO/portlibs is writable. +Make sure you exported the $DEVKITPRO and $WUT_ROOT envrivrioment variables and +that $WUT_ROOT is writable. -* Implementation -The library is currently implemented by having a tar filesystem compressed from a romfs folder +**** Implementation **** +The library is currently implemented by having a tar filesystem built from a romfs folder at compile time and then stored as a variable in .data with a fixed name (this is not an optimal -solution, and may change in the future). +solution, and may change in the future). No compression is currently used. diff --git a/include/romfs-wiiu.h b/include/romfs-wiiu.h index a49f9b1..b432a54 100644 --- a/include/romfs-wiiu.h +++ b/include/romfs-wiiu.h @@ -1,15 +1,16 @@ -#ifndef __WIIU_ROMFS -#define __WIIU_ROMFS +#pragma once #ifdef __cplusplus extern "C" { #endif -uint32_t romfsInit(); -uint32_t romfsExit(); + +int romfsInit(void); + + +int romfsExit(void); + #ifdef __cplusplus } #endif - -#endif \ No newline at end of file diff --git a/share/romfs-wiiu.mk b/share/romfs-wiiu.mk index c846573..8436216 100644 --- a/share/romfs-wiiu.mk +++ b/share/romfs-wiiu.mk @@ -2,24 +2,20 @@ ifneq ($(strip $(V)), 1) Q ?= @ endif -#--------------------------------------------------------------------------------- -# romfs folder (should be set by app's makefile) -#--------------------------------------------------------------------------------- -ROMFS ?= romfs +ROMFS_LDFLAGS := -lromfs-wiiu -#--------------------------------------------------------------------------------- -# romfs target (must be added to obj files that'll be linked in app's makefile) -#--------------------------------------------------------------------------------- -ROMFS_TARGET := app.romfs.o +ifneq ($(strip $(ROMFS)),) -#--------------------------------------------------------------------------------- -# You probably don't need anything from there -#--------------------------------------------------------------------------------- -ROMFS_LDFLAGS := -lromfs-wiiu -LDFLAGS += $(ROMFS_LDFLAGS) +ROMFS_TARGET := app.romfs.o %.romfs.o: $(ROMFS) @echo ROMFS $(notdir $@) $(Q)tar -H ustar -cvf romfs.tar -C $(ROMFS) . $(Q)$(OBJCOPY) --input binary --output elf32-powerpc --binary-architecture powerpc:common romfs.tar $@ @rm -f romfs.tar + +else + +ROMFS_TARGET := + +endif \ No newline at end of file diff --git a/source/romfs.c b/source/romfs.c index ecf4f4c..fe0a341 100644 --- a/source/romfs.c +++ b/source/romfs.c @@ -416,26 +416,28 @@ static devoptab_t romfs_devoptab = { //! Library functions //!---------------------------------------------------------------------- -extern char _binary_romfs_tar_start[]; -extern char _binary_romfs_tar_end[]; +extern char _binary_romfs_tar_start[] __attribute__((weak)); +extern char _binary_romfs_tar_end[] __attribute__((weak)); static int romfs_initialised = 0; -uint32_t romfsInit() { +int romfsInit(void) { if (romfs_initialised) return 0; + if (!_binary_romfs_tar_start || !_binary_romfs_tar_end) + return -2; tar_create_entries(_binary_romfs_tar_start, _binary_romfs_tar_end); if (AddDevice(&romfs_devoptab) == -1) { node_destroytree(NULL, 0); - return 1; + return -1; } romfs_initialised = 1; return 0; } -uint32_t romfsExit() { +int romfsExit(void) { if (!romfs_initialised) - return 1; + return -1; RemoveDevice("romfs:"); node_destroytree(NULL, 0); romfs_initialised = 0;