gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > problem using kosf

#109829 - Xgame - Tue Nov 21, 2006 4:23 pm

I am trining to use kosfs, but, after putting the libs in the example, i can't compile it. I have also created the .img file, but i don't know how to include it.
please help me

Quote:

C:\devkitPro\kosf\fstest>make
fstest.c
arm-eabi-gcc -MMD -MP -MF /c/devkitPro/kosf/fstest/build/fstest.d -g -Wall -O2 -
mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork
-I/c/devkitPro/kosf/fstest/kos -I/c/devkitPro/libnds/include -I/c/devkitPro/li
bnds/include -I/c/devkitPro/kosf/fstest/build -DARM9 -c /c/devkitPro/kosf/fstes
t/source/fstest.c -o fstest.o
c:/devkitPro/kosf/fstest/source/fstest.c:12:26: error: romdisk_img.h: No such fi
le or directory
c:/devkitPro/kosf/fstest/source/fstest.c: In function 'fs_test':
c:/devkitPro/kosf/fstest/source/fstest.c:38: warning: implicit declaration of fu
nction 'malloc'
c:/devkitPro/kosf/fstest/source/fstest.c:38: warning: incompatible implicit decl
aration of built-in function 'malloc'
c:/devkitPro/kosf/fstest/source/fstest.c:39: warning: implicit declaration of fu
nction 'exit'
c:/devkitPro/kosf/fstest/source/fstest.c:39: warning: incompatible implicit decl
aration of built-in function 'exit'
c:/devkitPro/kosf/fstest/source/fstest.c:49: warning: format '%s' expects type '
char *', but argument 2 has type 'int'
c:/devkitPro/kosf/fstest/source/fstest.c:54: warning: format '%s' expects type '
char *', but argument 2 has type 'int'
c:/devkitPro/kosf/fstest/source/fstest.c:25: warning: unused variable 'i'
c:/devkitPro/kosf/fstest/source/fstest.c:25: warning: unused variable 'n'
c:/devkitPro/kosf/fstest/source/fstest.c:24: warning: unused variable 'c'
c:/devkitPro/kosf/fstest/source/fstest.c:23: warning: unused variable 'wFile'
c:/devkitPro/kosf/fstest/source/fstest.c: In function 'InitInterrupts':
c:/devkitPro/kosf/fstest/source/fstest.c:159: error: 'DISP_SR' undeclared (first
use in this function)
c:/devkitPro/kosf/fstest/source/fstest.c:159: error: (Each undeclared identifier
is reported only once
c:/devkitPro/kosf/fstest/source/fstest.c:159: error: for each function it appear
s in.)
c:/devkitPro/kosf/fstest/source/fstest.c: In function 'main':
c:/devkitPro/kosf/fstest/source/fstest.c:186: warning: implicit declaration of f
unction 'find_first_romfs_file'
make[1]: *** [fstest.o] Error 1
make: *** [build] Error 2

C:\devkitPro\kosf\fstest>








the image is called "romdisk.img" and i put it in "Source", "romdisk" and "data". i think something in makefile is wrong, but i don't know what.

#109832 - GPFerror - Tue Nov 21, 2006 4:47 pm

the latest version of that on my site was built for a older version of the devkitpro setup.

in the fstest.c include section at top
add
#include <nds/registers_alt.h>

that will fix the 'DISP_SR' undeclared or you can change it to whatever the newer libnds calls it.

in the version on my site I have
//#include "romdisk_img.h"
commented out, since the example looks for the romdisk.img appended to the end of the nds file.

Maybe you have an old version from somewhere?
http://gpf.dcemu.co.uk/ndsromdisk.shtml is where I released it.

TheLazy1 has been working on an updated version which uses the latest devkitpro which has a hook for newlib - using devoptab_t . This allow for using stdio function directly.

Troy(GPF)

#109836 - Xgame - Tue Nov 21, 2006 5:28 pm

yes, I have that version. but if I comment #include "romdisk_img.h" how can I load it?

#109844 - GPFerror - Tue Nov 21, 2006 6:17 pm

the end of the Makefile

Code:
romdisk.img:
   genromfs -f ../romdisk.img -d ../romdisk -v
   padbin 0x100 $(OUTPUT).nds
   cat $(OUTPUT).nds ../romdisk.img  > $(OUTPUT)_tmp.nds


generates the romdisk.img, pads the nds file and then concats it to the end of the nds file.

If you want to embedded the romdisk.img you would use the include line, but you need to have the Makefile generate an embeddable object with bin2s, which would create the romdisk_img.h file automatically.

Troy(GPF)
http://gpf.dcemu.co.uk

#109846 - Cthulhu - Tue Nov 21, 2006 6:22 pm

GPFerror wrote:

TheLazy1 has been working on an updated version which uses the latest devkitpro which has a hook for newlib - using devoptab_t . This allow for using stdio function directly.

Troy(GPF)


Where can i get that version?

And another question, i've been trying this FS and works great, but i have a problem (maybe because i used an emulator to run the program), when i try to read an unsigned char after an unsigned short, the char info is wrong, don't know if it is because the byte alignment (its not aligned to 4) or its an emulator thing... this happens always, i can fseek whatever position in the file and the unsigned char always have wrong info :S

#109848 - Lazy1 - Tue Nov 21, 2006 6:37 pm

Cthulhu wrote:
GPFerror wrote:

TheLazy1 has been working on an updated version which uses the latest devkitpro which has a hook for newlib - using devoptab_t . This allow for using stdio function directly.

Troy(GPF)


Where can i get that version?


There is no official release, I just made some modifications to the library and sent those off to GPF.
If you want I can give you the changes needed to allow using standard I/O functions.

[Slightly off topic]
Is there any way to get the arm9 start address and size?
If I can get those numbers it will be possible for gbamp/wmb users to append a romdisk to the arm9 binary.

#109852 - tepples - Tue Nov 21, 2006 7:26 pm

Sure, you can append the datafile to the ARM9. This worked until devkitPro R12 or thereabouts, when the DS linker script was changed to start the BSS and heap immediately after the ARM9 binary and will overwrite any appended file when zeroing BSS. (We're on R19b now.) I'd guess that the most reliable method is to make an empty 1 MB file with a known content, use bin2s to link that into the ARM9 binary, and at the artist's side, replace that file with your romdisk.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#109854 - Cthulhu - Tue Nov 21, 2006 8:08 pm

Lazy1 wrote:

If you want I can give you the changes needed to allow using standard I/O functions.


Yes, please :D

By the way, is there some type of size limit in the romdisk?

#109855 - Lazy1 - Tue Nov 21, 2006 8:21 pm

Add this to the bottom of fs_romdisk.c:

Code:

/* RomdiskFS newlib integration code
 * 2006 - TheLazy1 (lazyone.drunkencoders.com)
 *
 * Thanks to: Chishm for libfat which I referenced to get this working.
*/


static int romfs_open( struct _reent* r, void* fileStruct, const char* path, int flags, int mode ) {
   int fileHandle = -1;
   int openFlags = 0;

   /* ( flags & O_WRONLY ) return -1;
   if ( flags & O_RDWR ) return -1;
   if ( flags & O_APPEND ) return -1;
   if ( flags & O_CREAT ) return -1;
   if ( flags & O_EXCL ) return -1;
   if ( flags & O_TRUNC ) return -1;
   */

   if (    ( flags & O_WRONLY )    ||
      ( flags & O_RDWR )   ||
      ( flags & O_APPEND )   ||
      ( flags & O_CREAT )   ||
      ( flags & O_EXCL )      ||
      ( flags & O_TRUNC ) )
   {
      r->_errno = EROFS;
      return -1;
   }

   if ( flags & O_RDONLY ) openFlags |= O_RDONLY;

   fileHandle = fs_open( path, openFlags );
   *( ( int* ) fileStruct ) = fileHandle;

   if ( fileHandle == -1 ) {
      r->_errno = ENOENT;
   }

   return fileHandle;
}

static int romfs_close( struct _reent* r, int fd ) {
   fs_close( *( ( int* ) fd ) );
   return 1;
}

static int romfs_write( struct _reent* r, int fd, const char* ptr, int len ) {
   r->_errno = EROFS;
   return -1;
}

static int romfs_read( struct _reent* r, int fd, char* ptr, int len ) {
   return fs_read( *( ( int* ) fd ), ptr, len );
}

static int romfs_seek( struct _reent* r, int fd, int pos, int dir ) {
   return fs_seek( *( ( int* ) fd ), pos, dir );
}

static int romfs_fstat( struct _reent* r, int fd, struct stat* st ) {
   r->_errno = ENOSYS;
   return -1;
}

static int romfs_stat( struct _reent* r, const char* file, struct stat* st ) {
   r->_errno = ENOSYS;
   return -1;
}

static int romfs_link( struct _reent* r, const char* existing, const char* new ) {
   r->_errno = EROFS;
   return -1;
}

static int romfs_unlink( struct _reent* r, const char* name ) {
   r->_errno = EROFS;
   return -1;
}

static int romfs_chdir( struct _reent* r, const char* name ) {
   r->_errno = ENOSYS;
   return -1;
}

static const devoptab_t romfsIO = {
   "romfs",
   4,
   &romfs_open,
   &romfs_close,
   &romfs_write,
   &romfs_read,
   &romfs_seek,
   &romfs_fstat,
   &romfs_stat,
   &romfs_link,
   &romfs_unlink,
   &romfs_chdir
};

int romfsInit( int searchAddress, const char* mountPoint ) {
   const u8* romfsBase = NULL;

   sysSetCartOwner( true );

   if ( ( romfsBase = ( const u8* ) find_first_romfs_file( ( const void* ) searchAddress ) ) != NULL ) {
      fs_romdisk_init( );
      fs_romdisk_mount( mountPoint, romfsBase, 0 );

      AddDevice( &romfsIO );
      setDefaultDevice( FindDevice( "romfs:" ) );

      return 1;
   }

   return 0;
}

int romfsInitDefault( void ) {
   return romfsInit( 0x08000000, "/" );
}


Add this to the bottom of fs_romdisk.h:

Code:

/* Initialize romfs, start looking for the romdisk at "searchAddress" */
int romfsInit( int searchAddress, const char* mountPoint );

/* Initializes romfs, looks for the romdisk starting at 0x08000000 */
int romfsInitDefault( void );


As you can see a few functions are not implemented, but last I checked this code works fine.

#114249 - GPFerror - Fri Jan 05, 2007 8:55 pm

I have added TheLazyOne's newlib changes to the code and lib on my site

http://gpf.dcemu.co.uk/ndsromdisk.shtml

Troy(GPF)

#114323 - Payk - Sat Jan 06, 2007 5:50 pm

Quote:
By the way, is there some type of size limit in the romdisk?

Yes sure. It uese the GBA-ROMSPACE. The gba games had max. 32MB so same for KOSFS as long as you attach file at the end of the rom. Otherwhise you will just have the 4MB main ram for datas and code. But 32MB is quite enough for homebrew...