[SOLVED] Extract romdisk file from a Dreamcast ELF?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
Indiket
DC Developer
DC Developer
Posts: 99
Joined: Sun Sep 05, 2010 5:44 am
Has liked: 0
Been liked: 0

[SOLVED] Extract romdisk file from a Dreamcast ELF?

Post by Indiket » Sat Jun 14, 2014 1:43 pm

Hello dreamers!! :)

I've been recently looking for old Dreamcast sources, in order to preserve them into KOS, but I've found a case that I think you guys can help me.

There's a Dreamcast demo (burrritos) that source code is available, with an ELF file. But unfortunately, the source code does not include the resources files (they are inside a ROMDISK of the ELF file). So here's my questions.

1. Is it possible to extract the romdisk.img file from an ELF file? I think it can be done (ie. the -rom1fs- heder), but I need to be sure that is not a crazyness hehe.
2. If so, is there any tool to do it? I looked a bit with sh-elf-readelf and sh-elf-objcopy, but no luck. Maybe with the right command, can it be extracted? I think must be related to .rodata section, too.
3. If no tool exists, could it be done manually by hex-editing?
4. If I have success, I saw that KOS has a rdtest utility to check romdisk files. Can it be used to extract data files inside them? Or just mounting with Isobuster or similar? Maybe with another little tool?

Keep dreaming! ;)
Last edited by Indiket on Sun Jun 15, 2014 2:44 am, edited 1 time in total.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5404
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 1 time
Been liked: 16 times
Contact:

Re: Extract romdisk file from a Dreamcast ELF?

Post by BlueCrab » Sat Jun 14, 2014 2:19 pm

Well, I'm not aware of any tools specifically that would allow you to do it, but if what you have is an unstripped elf file, it shouldn't be all that hard to parse the file, find the romdisk's symbol in the symtab, and then copy it out once you know where in the file it is and the size of it.

With a little bit of work, you could probably cobble something together out of KOS' elf file parsing code to do it.

Once you have it out, I'd imagine it'd be pretty easy to open it up with some sort of program. If you have a Linux machine handy, you should be able to mount it there, assuming the kernel still supports those images (I'd imagine it does for initrd stuff).
User avatar
|darc|
DCEmu Webmaster
DCEmu Webmaster
Posts: 16183
Joined: Wed Mar 14, 2001 6:00 pm
Location: New Orleans, LA
Has liked: 25 times
Been liked: 5 times
Contact:

Re: Extract romdisk file from a Dreamcast ELF?

Post by |darc| » Sat Jun 14, 2014 6:43 pm

Created an empty romdisk and saw that the romdisk starts with the text "-rom1fs-"

The following command gives the offset of the header within the file, in decimal format

Code: Select all

strings -a -t d burritro2.elf | grep "\-rom1fs\-"
which returns 57736

Mounted the romdisk successfully in Linux with the command

Code: Select all

mount burritro2.elf -t romfs /mnt/romfs -o offset=57736
ZIP file attached with the contents of the romdisk.
Attachments
burritro2.zip
burritro 2 romdisk contents
(466.94 KiB) Downloaded 68 times
It's thinking...
User avatar
Indiket
DC Developer
DC Developer
Posts: 99
Joined: Sun Sep 05, 2010 5:44 am
Has liked: 0
Been liked: 0

Re: Extract romdisk file from a Dreamcast ELF?

Post by Indiket » Sun Jun 15, 2014 2:43 am

Thanks for your answers BlueCrab and |darc| !! :grin: :grin:

Btw, really nice solution |darc| , it's so simple and elegant 8-) But unfortunately I wrote a C code solution one hour before I saw your answer xD.

I attach this two small .c files (both are GPL):

- getromfs.c : Is my "quick & dirty" code to extract the Romdisk file from the original one. Probably it has some errors and not polite code, but it worked for me ;)
- romfsck.c : A cool tool from Harald Welte that reads a ROMFS file and extract its contents. With -x argument can work in a different path.

Maybe it can be useful for Cygwin environments, that could have problems mounting ROMFS files.
Attachments
getromfs.zip
A quick and dirty code to extract a ROMFS file from another one.
(1.51 KiB) Downloaded 85 times
romfsck.zip
Tool to extract contents of a ROMFS file.
(2.14 KiB) Downloaded 96 times
User avatar
Indiket
DC Developer
DC Developer
Posts: 99
Joined: Sun Sep 05, 2010 5:44 am
Has liked: 0
Been liked: 0

Re: [SOLVED] Extract romdisk file from a Dreamcast ELF?

Post by Indiket » Sun Jun 22, 2014 3:45 am

FYI, I've just finished the preservation of this cool techdemo (compiles flawlessly on KOS 2.x).

Attaching updated source code and binary, enjoy!!
Attachments
burritroV2-PVR.zip
BurritroV2 tech demo updated to modern KOS (PVR, Maple, SPU...).
(1.02 MiB) Downloaded 73 times
User avatar
Neoblast
DC Developer
DC Developer
Posts: 312
Joined: Sat Dec 01, 2007 8:51 am
Has liked: 0
Been liked: 0

Re: [SOLVED] Extract romdisk file from a Dreamcast ELF?

Post by Neoblast » Wed Jun 25, 2014 8:44 am

Nice, now we can update ancient ports and demos in an easier way :)
Amazing job mate
Post Reply