Linux Genesis Dev Setup

Talk about development tools here

Moderator: BigEvilCorporation

Post Reply
kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Linux Genesis Dev Setup

Post by kubilus1 » Wed Sep 12, 2012 5:25 pm

UPDATE!!

I've moved the Google Code project to: https://github.com/kubilus1/gendev

BASIC INSTRUCTIONS
==================

$ git clone https://github.com/kubilus1/gendev.git
$ cd gendev
$ make

This will build the entire GCC toolchain for genesis development, plus SGDK.
Build takes about 1 hour on my system. Note this will only create C libraries for the 68K processor. For a 32x SH2
development:

$ make 32x

Now I want to create a project ...

$ cp -r /opt/toolchains/gen/skeleton mycoolproject
$ cd mycoolproject

*type type type*

$ make

----


HINT: If this complains that makeinfo is missing on Ubuntu, trying installing the texinfo package.


-----------------------------------------------------------------------------------

I wanted a one-line way of setting up a Linux based Genesis development environment from the instructions that ChillyWilly has posted previously, so I created a makefile.

User should just have to type 'make' to get basic environment up and going. This has been tested on Ubuntu 10.10 and 12.04 and may require the 'texinfo' package which provides the 'makeinfo' command.

Code: Select all

#
# HINT: If makeinfo is missing on Ubuntu, install texinfo package.
#

FILES=gcc-4.5.2.tar.bz2 gcc-g++-4.5.2.tar.bz2 gcc-objc-4.5.2.tar.bz2 \
          mpfr-2.4.2.tar.bz2 mpc-0.8.2.tar.gz gmp-5.0.5.tar.bz2 \
          binutils-2.21.1.tar.bz2 newlib-1.19.0.tar.gz makefiles-ldscripts-2.zip

all: setup build postbuild

setup: work $(FILES) work/gcc-4.5.2 work/gcc-4.5.2/mpfr work/gcc-4.5.2/mpc work/gcc-4.5.2/gmp work/binutils-2.21 work/newlib-1.19.0 work/makefile-gen

build: /opt/toolchains/gen
        echo "Build"
        cd work && \
        make -f makefile-gen

postbuild: /opt/toolchains/gen/ldscripts /opt/toolchains/gen/bin /opt/toolchains/gen/bin/bin2c \
                        /opt/toolchains/gen/bin/sjasm /opt/toolchains/gen/bin/zasm
        echo "Post build."
        echo "export GENDEV=/opt/toolchains/gen" > ~/.gendev
        echo "export PATH=\$$GENDEV/m68k-elf/bin:\$$GENDEV/bin:\$$PATH" >> ~/.gendev
        echo "export GENDEV=/opt/toolchains/gen" > ~/.32xdev
        echo "export PATH=\$$GENDEV/sh-elf/bin:\$$GENDEV/m68k-elf/bin:\$$GENDEV/bin:\$$PATH" >> ~/.32xdev

clean:
        rm -rf work

work:
        mkdir work

gcc-4.5.2.tar.bz2:
        wget http://ftp.gnu.org/gnu/gcc/gcc-4.5.2/gcc-4.5.2.tar.bz2

gcc-g++-4.5.2.tar.bz2:
        wget http://ftp.gnu.org/gnu/gcc/gcc-4.5.2/gcc-g++-4.5.2.tar.bz2

gcc-objc-4.5.2.tar.bz2:
        wget http://ftp.gnu.org/gnu/gcc/gcc-4.5.2/gcc-objc-4.5.2.tar.bz2

mpfr-2.4.2.tar.bz2:
        wget http://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.bz2

mpc-0.8.2.tar.gz:
        wget http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz

gmp-5.0.5.tar.bz2:
        wget ftp://ftp.gmplib.org/pub/gmp-5.0.5/gmp-5.0.5.tar.bz2

binutils-2.21.1.tar.bz2:
        wget http://ftp.gnu.org/gnu/binutils/binutils-2.21.1.tar.bz2

newlib-1.19.0.tar.gz:
        wget ftp://sources.redhat.com/pub/newlib/newlib-1.19.0.tar.gz

makefiles-ldscripts-2.zip:
        wget http://www.fileden.com/files/2009/2/3/2304902/makefiles-ldscripts-2.zip

bin2c-1.0.zip:
        wget http://downloads.sourceforge.net/project/bin2c/bin2c-1.0.zip

sjasm39g6.zip:
        wget http://home.wanadoo.nl/smastijn/sjasm39g6.zip

zasm-3.0.21-source-linux-2011-06-19.zip:
        wget http://k1.dyndns.org/Develop/projects/zasm/distributions/zasm-3.0.21-source-linux-2011-06-19.zip

work/makefile-gen:
        cd work && \
        unzip ../makefiles-ldscripts-2.zip

work/binutils-2.21:
        cd work && \
        tar xvjf ../binutils-2.21.1.tar.bz2 && \
        mv binutils-2.21.1 binutils-2.21

work/newlib-1.19.0:
        cd work && \
        tar xvzf ../newlib-1.19.0.tar.gz

work/gcc-4.5.2:
        cd work && \
        tar xvjf ../gcc-4.5.2.tar.bz2 && \
        tar xvjf ../gcc-g++-4.5.2.tar.bz2 && \
        tar xvjf ../gcc-objc-4.5.2.tar.bz2

work/gcc-4.5.2/mpfr: work/gcc-4.5.2
        cd work && \
        tar xvjf ../mpfr-2.4.2.tar.bz2 && \
        mv mpfr-2.4.2 gcc-4.5.2/mpfr

work/gcc-4.5.2/mpc: work/gcc-4.5.2
        cd work && \
        tar xvzf ../mpc-0.8.2.tar.gz && \
        mv mpc-0.8.2 gcc-4.5.2/mpc

work/gcc-4.5.2/gmp: work/gcc-4.5.2
        cd work && \
        tar xvjf ../gmp-5.0.5.tar.bz2 && \
        mv gmp-5.0.5 gcc-4.5.2/gmp

/opt/toolchains/gen:
        sudo mkdir -p $@
        sudo chmod 777 /opt/toolchains/gen

/opt/toolchains/gen/bin:
        mkdir $@

/opt/toolchains/gen/ldscripts: work/makefile-gen
        mkdir $@
        cp work/*.ld $@/.

/opt/toolchains/gen/bin/bin2c: bin2c-1.0.zip
        cd work && \
        unzip ../bin2c-1.0.zip && \
        cd bin2c && \
        gcc bin2c.c -o bin2c && \
        cp bin2c $@ 

/opt/toolchains/gen/bin/sjasm: sjasm39g6.zip
        - mkdir work/sjasm
        cd work/sjasm && \
        unzip ../../sjasm39g6.zip && \
        cp sjasm $@ && \
        chmod +x $@

/opt/toolchains/gen/bin/zasm: zasm-3.0.21-source-linux-2011-06-19.zip
        - mkdir work/zasm 
        cd work/zasm && \
        unzip ../../$< && \
        cd zasm-3.0.21-i386-ubuntu-linux-2011-06-19/source && \
        make && \
        cp zasm $@
Update 10-15-12: Added zasm, sjasm and bin2c tools, plus ~/.gendev and ~/.32xdev scripts.
Last edited by kubilus1 on Sun Jun 07, 2015 3:51 pm, edited 6 times in total.

doragasu
Very interested
Posts: 125
Joined: Tue Oct 09, 2012 8:15 am

Post by doragasu » Tue Oct 09, 2012 11:09 am

I'm using your makefile to build the SDK right now. It will save me a lot of time, Thanks!

Dunno why, it had problems with multiline sentences, so I had to convert them all to single line to get it working.

The only thing I'm missing in your script is SGDK library compilation. Do you have a script or tutorial about building SGDK library for Linux?

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Tue Oct 09, 2012 6:33 pm

doragasu wrote:I'm using your makefile to build the SDK right now. It will save me a lot of time, Thanks!

Dunno why, it had problems with multiline sentences, so I had to convert them all to single line to get it working.
You need to be careful when getting makefiles from code boxes in forums - many convert hard tabs into spaces, but make WILL NOT accept spaces as whitespace before commands (on those multi-line commands). You need to convert those spaces into hard tabs before the makefile will work. Or make them one line like you did.
The only thing I'm missing in your script is SGDK library compilation. Do you have a script or tutorial about building SGDK library for Linux?
I made a makefile for linux on an old version, but not the current one. I need to get around to that sometime. Here's the old makefile...

Code: Select all

CC = m68k-elf-gcc
AR = m68k-elf-ar
RANLIB = m68k-elf-ranlib
OBJC = m68k-elf-objcopy
RM = rm -f
ASMZ80 = zasm
BINTOC = bin2c

OPTION= -Dnologo_

libmd.a_OBJS = base.o tools.o vdp.o font.o vdp_bg.o vdp_dma.o \
	vdp_pal.o vdp_spr.o vdp_tile.o bitmap.o bitmapx.o z80_ctrl.o \
	tab_sin.o tab_log2.o tab_pow2.o maths.o maths3D.o ym2612.o \
	psg.o audio.o joy.o timer.o logo_lib.o z80_drv1.o z80_drv2.o \
	z80_mvst.o

INCS = -I./include
FLAGS = $(OPTION) -m68000 -Wall -O1 -c -fomit-frame-pointer $(INCS)
FLAGSZ80 = -vb2

all: z80_drv1.o80 z80_drv1.c z80_drv2.o80 z80_drv2.c md.o $(libmd.a_OBJS) libmd.a

%.a: $(libmd.a_OBJS)
	$(RM) $@
	$(AR) cru $@ $($@_OBJS)
	$(RANLIB) $@

%.o80: %.s80
	$(ASMZ80) $(FLAGSZ80) -o $@ -i $<

%.c: %.o80
	$(BINTOC) $<

%.o: %.c
	$(CC) $(FLAGS) -c $< -o $@

%.o: %.s
	$(CC) $(FLAGS) -c $< -o $@

clean:
	$(RM) -rf *.o *.a *.o80 *.log
	$(RM) -f z80_drv1.c z80_drv1.h z80_drv2.c z80_drv2.h

install: all
	cp include/*.h $(GENDEV)/m68k-elf/include
	cp libmd.a $(GENDEV)/m68k-elf/lib
	cp md.o $(GENDEV)/m68k-elf/lib
Don't forget what I said about hard tabs and makefiles! :D

doragasu
Very interested
Posts: 125
Joined: Tue Oct 09, 2012 8:15 am

Post by doragasu » Wed Oct 10, 2012 9:01 am

Thanks, ill try that.

PS: I know spaces must be converted to tabs, and I did it, but it still failed to work until I converted all multiline sentences into single line ones. Maybe it would be better next time to upload makefiles to pastebin or similar.

doragasu
Very interested
Posts: 125
Joined: Tue Oct 09, 2012 8:15 am

Post by doragasu » Wed Oct 10, 2012 9:14 am

Before starting to get my hands dirty, I had another look to your Makefile and saw it needs two tools I don't have: zasm and bin2c. I can see bintos is included in SGDK sources, but not bin2c. Also zasm is not in Ubuntu repositories.

Where can I find these two tools? Is bin2c this?

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Oct 10, 2012 11:58 am

I normally replaced all bintoc reference to bintos as bintos is preferable in many ways :)

doragasu
Very interested
Posts: 125
Joined: Tue Oct 09, 2012 8:15 am

Post by doragasu » Wed Oct 10, 2012 1:09 pm

Hehe, and wouldn't it be preferable using objcopy rather than bintoc or bintos :wink:

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Wed Oct 10, 2012 7:25 pm

doragasu wrote:Hehe, and wouldn't it be preferable using objcopy rather than bintoc or bintos :wink:
No. Bintoc and bintos convert a binary into source data (either C or asm style depending on which you use). Objcopy cannot do that. Of course, that requires an extra tool that you may or may not have. What I've taken to doing recently is making another .s file that .incbin's the binary and not using bintoc or bintos.

And zasm is this:
http://k1.dyndns.org/Develop/projects/z ... ributions/

Some people use sjasm/sjasm+ instead... be aware that the two have very different syntaxes, so depending on which you use, you may have to edit the z80 source to get it to assemble.

Mask of Destiny
Very interested
Posts: 615
Joined: Thu Nov 30, 2006 6:30 am

Post by Mask of Destiny » Wed Oct 10, 2012 8:27 pm

Chilly Willy wrote: No. Bintoc and bintos convert a binary into source data (either C or asm style depending on which you use). Objcopy cannot do that. Of course, that requires an extra tool that you may or may not have. What I've taken to doing recently is making another .s file that .incbin's the binary and not using bintoc or bintos.
They don't literally do the same thing, but they both can be used to put a chunk of binary data in your final executable and make it accessible via a symbol in your source code. Here's a simple example of using objcopy to do that: http://www.linuxjournal.com/content/emb ... rsion-5967

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Wed Oct 10, 2012 10:35 pm

Mask of Destiny wrote:
Chilly Willy wrote: No. Bintoc and bintos convert a binary into source data (either C or asm style depending on which you use). Objcopy cannot do that. Of course, that requires an extra tool that you may or may not have. What I've taken to doing recently is making another .s file that .incbin's the binary and not using bintoc or bintos.
They don't literally do the same thing, but they both can be used to put a chunk of binary data in your final executable and make it accessible via a symbol in your source code. Here's a simple example of using objcopy to do that: http://www.linuxjournal.com/content/emb ... rsion-5967
Nice! I hadn't seem something like that before. Gcc is even MORE useful than I thought! :lol:

Hmm - how about multiple binaries? That method seems to only handle one binary.

EDIT: "The symbol names are formed by prepending _binary_ and appending _start or _end to the file name." Okay, that answers that. :)

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Thu Oct 11, 2012 3:44 am

Updated the Linux SGDK Makefile for the latest SVN. It seems that sjasm is necessary to build the z80 stuff in this dev kit (http://home.wanadoo.nl/smastijn/sjasm.html)

However, I had an issue with about an invalid operand with several of the z80 files "z80_drv1.s80(512) : Illegal operand". Commenting this out allows the rest to compile, but surely messes up the utility of these z80 drivers.

And the Makefile (note the aforementioned tabs to spaces issues --- I need to make this it's own google code or github project!)

Code: Select all


CC = m68k-elf-gcc 
AR = m68k-elf-ar 
RANLIB = m68k-elf-ranlib 
OBJC = m68k-elf-objcopy 
RM = rm -f 
ASMZ80 = sjasm3 
BINTOC = bin2c 

OPTION= -Dnologo_ 

libmd.a_OBJS = bmp.o everdrive.o logo_lib.o psg.o tab_bmp.o \
        tab_sin.o tfcplay.o vdp_bg.o vdp_spr.o z80_drv1.o bmp_cmn.o \
        fat16.o maths3D.o sound.o tab_cnv.o tab_sqrt.o timer.o vdp.o \
        vdp_tile.o z80_drv2.o bmp_ff.o font.o maths.o string.o  \
        tab_log10.o tab_vol.o tools.o vdp_dma.o ym2612.o bmp_intr.o \
        joy.o memory.o sys.o tab_log2.o tab_vram.o types.o vdp_pal.o \
        sys_a.o bmp_cmn_a.o bmp_ff_a.o \
        kdebug.o maths3D_a.o smp_null_pcm.o smp_null.o vdp_tile_a.o \
        z80_drv3.o z80_drv4.o z80_mvs.o z80_tfm.o z80_ctrl.o

INCS = -I../include 
FLAGS = $(OPTION) -m68000 -Wall -O1 -c -fomit-frame-pointer $(INCS) 
FLAGSZ80 = -isrc -i../include  

all: z80_drv1.o80 z80_drv1.c z80_drv2.o80 z80_drv2.c $(libmd.a_OBJS) libmd.a

%.a: $(libmd.a_OBJS) 
        $(RM) $@ 
        $(AR) cru $@ $($@_OBJS) 
        $(RANLIB) $@ 

%.o80: %.s80 
        $(ASMZ80) $(FLAGSZ80) $< $@ out.lst 

%.c: %.o80 
        $(BINTOC) -o $@ $< 

%.h: %.o80 
        $(BINTOC) -o $@ $< 


%.o: %.c 
        $(CC) $(FLAGS) -c $< -o $@ 

%.o: %.s 
        $(CC) $(FLAGS) -c $< -o $@ 

clean:
        $(RM) -rf *.o *.a *.o80 *.log *.lst
        $(RM) -f z80_drv1.c z80_drv2.c 

install: all 
        cp ../include/*.h $(GENDEV)/m68k-elf/include 
        cp libmd.a $(GENDEV)/m68k-elf/lib 
EDIT: Updated the Makefile so it actually makes something useful!
Last edited by kubilus1 on Mon Oct 15, 2012 1:22 am, edited 1 time in total.

doragasu
Very interested
Posts: 125
Joined: Tue Oct 09, 2012 8:15 am

Post by doragasu » Thu Oct 11, 2012 8:53 am

I'll try the Makefile when I get some time. Again, thanks!

BTW, I used objcopy to embed stuff in the ROM when doing some experiments for the GBA.

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Fri Oct 12, 2012 2:28 pm

BTW: Use sjasm 0.39g6, the 0.42 version gives the error I mentioned.

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Mon Oct 15, 2012 4:18 pm

Added zasm, bin2c and sjasm tools to the Makefile at the top of the page.

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Created gendev project for Linux Genesis development.

Post by kubilus1 » Wed Oct 24, 2012 6:50 pm

I went ahead and created a google code project for Linux Genesis development called gendev. http://code.google.com/p/gendev/

Currently this will allow the user to easily setup a development environment, plus setup and install SGDK. I also included a skeleton of what is required to build projects using SGDK on Linux.

Hopefully this will help new developers more easily get into the scene.

(PS: No more changing spaces to tabs in makefiles!!)

Post Reply