Dingoonity.org

Other Portable Consoles => Gemei A330 => Topic started by: Jonesie on October 20, 2013, 10:52:38 pm

Title: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 20, 2013, 10:52:38 pm
Hi fellas,

after a long, helpful discussion with Harteex and some advice from Cex, I've been able to setup a toolchain for developing for Gemei A330 on Mac OS X. Everything seems to work, but the binaries that come out of it simply don't run on the console (frozen interface, power off as only fix).

Here's a brief summary of what we've done so far:

- Grabbed GCC + Binutils + Newlib from devkitpro.org's devkitARM. That's what I've been using since the days of the GP32/GBA (arm-none-eabi-*) and it has served me well.
- A package of libs & includes Harteex sent me. They include SDL, which I particularly fancy and need for a project of mine I intend to enjoy on the Gemei.
- Compiled Wine to stand a chance of executing dlmake.exe with wineconsole. It works. I call it with 'wineconsole --backend=curses dlmake.exe dlmake.ini'.

* Harteex kindly sent me his object and ELF files for SDLPong, which I packaged with dlmake, and found that the result runs flawlessly on the Gemei. So dlmake is actually fine.
* His ELF file and the one I generate with my toolchain only differ on the entry point address, being every other field in the header identical, *but* the object files I generate do have different sizes than his. So the problem might be related to GCC, but I fail to see what could be wrong with it, since all config/optimisation switches are being set by the Makefile.

I'm familiar with Makefiles, C/C++ and very basic GCC, but I currently ignore many things about binary formats, the linking process and the way things execute on a machine with or without OS. I understand that the OS may provide certain headers for hardware abstraction, but I have never used any of those. However, I'm really motivated and want to learn as much as possible about those things.

Thanks for reading,

Jonesie
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on October 21, 2013, 10:34:51 pm
You should take a look at your paths so that you only use headers from the SDK, not from the toolchain or your x86 headers. Also, make sure you only link to the libs in lib/cc1800.

I have access to OSX now, so I might be able to look into the problem.. however, I'm going to be busy this week, so it'll be later.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 22, 2013, 08:01:54 am
I triple checked paths & libs, rebuilt everything and I'm still stuck on the same problem. What version of GCC are you using? I've read that the latest versions of GCC produce bigger code for ARM (mine is 4.7.1), and that would explain the difference in size, but not everything else.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 22, 2013, 08:50:58 am
Oh, and I forgot to paste the configuration options from my crosscompiler:

Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
Target: arm-none-eabi
Configured with: ../../gcc-4.7.1/configure --enable-languages=c,c++,objc,obj-c++ --with-gnu-as --with-gnu-ld --with-gcc --with-march=armv4t --enable-poison-system-directories --enable-interwork --enable-multilib --disable-dependency-tracking --disable-threads --disable-win32-registry --disable-nls --disable-debug --disable-libmudflap --disable-libssp --disable-libgomp --disable-libstdcxx-pch --target=arm-none-eabi --with-newlib --with-headers=../../newlib-1.20.0/newlib/libc/include --prefix=/opt/devkitpro/devkitARM --enable-lto --with-bugurl=http://wiki.devkitpro.org/index.php/Bug_Reports --with-pkgversion='devkitARM release 41'
Thread model: single
gcc version 4.7.1 (devkitARM release 41)
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on October 22, 2013, 02:28:07 pm
I triple checked paths & libs, rebuilt everything and I'm still stuck on the same problem. What version of GCC are you using? I've read that the latest versions of GCC produce bigger code for ARM (mine is 4.7.1), and that would explain the difference in size, but not everything else.

Mostly checked the libs thing since you mentioned newlib, which you cannot use.

When I worked on this before I tested a few different toolchains, and I also noticed that the binaries produced in later version are larger. The one I use is a bit older, "arm-2007q3" (gcc versoin 4.2.1), but I'm pretty sure things worked fine with the later ones too.

Here's more details on my compiler:
Code: [Select]
Using built-in specs.
Target: arm-none-eabi
Configured with: /scratch/paul/lite-eabi/src/gcc-4.2/configure --build=i686-pc-linux-gnu --host=i686-mingw32 --target=arm-none-eabi --enable-threads --disable-libmudflap --disable-libssp --disable-libgomp --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --disable-shared --with-newlib --with-pkgversion=CodeSourcery Sourcery G++ Lite 2007q3-53 --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-headers=yes --with-sysroot=/opt/codesourcery/arm-none-eabi --with-build-sysroot=/scratch/paul/lite-eabi/install/host-i686-mingw32/arm-none-eabi --with-libiconv-prefix=/scratch/paul/lite-eabi/obj/host-libs-2007q3-53-arm-none-eabi-i686-mingw32/usr --enable-poison-system-directories --with-build-time-tools=/scratch/paul/lite-eabi/obj/tools-i686-pc-linux-gnu-2007q3-53-arm-none-eabi-i686-mingw32/arm-none-eabi/bin --with-build-time-tools=/scratch/paul/lite-eabi/obj/tools-i686-pc-linux-gnu-2007q3-53-arm-none-eabi-i686-mingw32/arm-none-eabi/bin
Thread model: single
gcc version 4.2.1 (CodeSourcery Sourcery G++ Lite 2007q3-53)
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 22, 2013, 05:38:03 pm
Yay, I'll check the actual libc I'm linking against when I arrive home. I think we're cornering the issue  ;D
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 22, 2013, 08:49:49 pm
Tried renaming the default libs directory and/or using -nodefaultlibs and/or -nostdinc options, with no luck  :'(

I don't think it's a lib problem. Remember how I linked your object files with my libs & packed the result with dlmake, and it worked flawlessly? this has something to do with the compiler, which might be producing some unsuitable code for the Gemei's CPU. Next thing to try: new toolchain  ???

Offtopic: do you know of any trick to reflash the same firmware version? My intro animation is gone after flashing 1.1 (weird, but possibly update-related), and the ChinaChip updater refuses to chew the same version again.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 23, 2013, 02:57:41 pm
Same result using arm-none-eabi from launchpad running on GNU/Linux. Now this is strange...
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on October 23, 2013, 09:27:21 pm
I'm out of ideas unfortunally. I tried to compile it myself on OS X with the arm-none-eabi compiler on macports, but it didn't work.

Maybe try an older toolchain or something.

I guess you could run my compiler with wine, but that might be a bit odd.

EDIT:
If anyone else might know / suspect what's wrong, here's both working and non-working binaries: http://www.harteex.com/temp/SDLPong.zip

EDIT2: The other comparison in a later post is probably more interesting...
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 24, 2013, 10:25:15 am
I tried to run a binary compiled with no optimisations (-O0, default value) and the object files decreased in size (because of no loop unrolling, for instance...) but the result is the same.

I'll pinpoint all available options for ARM in order to produce the most basic code and see if it runs. I guess it would be easier to know what the hell is inside the CC1800, but that's not gonna happen' :(
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on October 24, 2013, 03:16:48 pm
I tried doing the objcopy step on OS X and that seems to work.
Next up, the linker. Although that'll have to wait a few days...

Did you try an older toolchain, like the one I'm using?
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 25, 2013, 10:39:26 am
I have tried many toolchains, the oldest dating from 2011, with the same outcome. I have also tried this very morning using those switches for ARM that may make to binary more portable, with no success either.

Since binaries for older toolchains have started to disappear from FTP sites, I guess it's even more crucial that we get to the bottom of this issue and correct whatever needs to be corrected. I'm willing to build our own toolchain if that gave us enough control over this. The learning opportunities are huge.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on October 25, 2013, 03:33:29 pm
I have tried many toolchains, the oldest dating from 2011, with the same outcome. I have also tried this very morning using those switches for ARM that may make to binary more portable, with no success either.

Since binaries for older toolchains have started to disappear from FTP sites, I guess it's even more crucial that we get to the bottom of this issue and correct whatever needs to be corrected. I'm willing to build our own toolchain if that gave us enough control over this. The learning opportunities are huge.

Another piece in the puzzle: The compiler works fine, the problem is in the linker.
I compiled it on OS X, and moved the object files over to link on my toolchain, and things worked fine.

I've put the two elf files which were using the same object files, and some readelf and objdump output here: http://www.harteex.com/temp/cc1800-linker-problems/
Haven't looked that much at it, but I don't know what to conclude really.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 25, 2013, 07:51:18 pm
Maybe the startup files have substantially changed since the release of your old toolchain? if the .o files are correct and the objcopy step gets done without incident, the only thing that's left is the startup files for the C/C++ runtime (crt0.o, crtbegin.o ... ). I have tried linking with -nostartfiles and a crt0.S extracted from another ARM toolchain with no improvement whatsoever, but maybe it's worth checking the outcome with the ones from your toolchain!
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on October 28, 2013, 02:41:01 pm
Here's my toolchain if you want to try things: http://www.harteex.com/temp/arm-2007q3.zip

However I spoke to flatmush who suggested it might be the newer linker doing something that dlmake doesn't understand. He gave me few hints of what could be wrong, so I'll compare the files and also see if I can get it to run with flatmush' elf2app program.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 28, 2013, 02:57:49 pm
That's excelent - thank you :)
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 29, 2013, 01:35:57 pm
I've made a quick test with elf2app.py, substituting those references to the mips compiler for arm-none-eabi ones. I've ended up with a 2KB .app file and no error messages. Something is wrong 8)

I'll dive into the code to try and see what's causing this behaviour.

 
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on October 31, 2013, 04:17:03 am
I've made a quick test with elf2app.py, substituting those references to the mips compiler for arm-none-eabi ones. I've ended up with a 2KB .app file and no error messages. Something is wrong 8)

I'll dive into the code to try and see what's causing this behaviour.

Not sure how the py version is implemented, but there is a c version of elf2app in the dingoo-sdk.
It's not possible to just change to the arm toolchain, as other things are different, like some parts of the header.
If you're interested in the format, here's a document: http://code.google.com/p/dingoo-sdk/source/browse/trunk/dingoo_sdk/doc/CCDL_APP_Format.txt

I currently have quite many things on my todo list, so I'll have to see when I have time to look more into this (maybe during the weekend).
For now, if you don't want to wait, I'd recommend you to try the same version (or at least around the same) of the toolchain that I use, as that should work.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on October 31, 2013, 07:59:07 am
Not sure how the py version is implemented, but there is a c version of elf2app in the dingoo-sdk.
It's not possible to just change to the arm toolchain, as other things are different, like some parts of the header.
If you're interested in the format, here's a document: http://code.google.com/p/dingoo-sdk/source/browse/trunk/dingoo_sdk/doc/CCDL_APP_Format.txt

Much obliged! I'll look into that.

I currently have quite many things on my todo list, so I'll have to see when I have time to look more into this (maybe during the weekend).
For now, if you don't want to wait, I'd recommend you to try the same version (or at least around the same) of the toolchain that I use, as that should work.

Don't worry about the timing. We're moving home this very weekend, so I'll have my hands full for a couple of days too. Also, I'm keen on learning everything I can about toolchains, linkers, binary formats, etc. The Gemei A330 is probably one of the last non-Android consoles to ever grace the market and I would like to make the most of it, for I don't really dig Android as a hobbyist gaming/development platform/paradigm.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: chevette on November 01, 2013, 12:19:24 am
Jonesie: I really like your enthusiasm.....the A330 is a really good piece of hardware and never got the love it deserves. Hopefully you'll figure it all out.....thanks for your efforts.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on November 04, 2013, 10:12:13 am
Jonesie: I really like your enthusiasm.....the A330 is a really good piece of hardware and never got the love it deserves. Hopefully you'll figure it all out.....thanks for your efforts.

Hi,

thank you for your message. I'm this enthusiastic mostly because the console is 100% new to me, but I think it's more than worth mentioning that Harteex remains equally enthusiastic after all the time he has spent with it. I wouldn't have made any progress without his skills and support.

By the way, already moved to our new house. Lots of space, including a room for developing stuff. Now I need internet access :-)
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: fosamax on November 04, 2013, 12:12:50 pm
I hope that you could find a way to avoid audio latency that is probably the most worrying trouble with the gemei.

The lack of proper documentation is also problematic.

if you can, take a look at http://drlionrsm.blogspot.fr/2013/07/dingoo-emulation-pack-v20.html#more  (http://drlionrsm.blogspot.fr/2013/07/dingoo-emulation-pack-v20.html#more) since it's something that may worth being ported to the gemei.

Thanks to Jonesie and Harteex !
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on November 05, 2013, 05:13:03 pm
I hope that you could find a way to avoid audio latency that is probably the most worrying trouble with the gemei.

That is one of the most intriguing points. I've noticed that there are emulators with and without lag. I'll try to figure it out, of course.

if you can, take a look at http://drlionrsm.blogspot.fr/2013/07/dingoo-emulation-pack-v20.html#more  (http://drlionrsm.blogspot.fr/2013/07/dingoo-emulation-pack-v20.html#more) since it's something that may worth being ported to the gemei.

I've peeked at that page and it looks interesting. I'm more than anything interested in porting my games to the Gemei, but won't say no to this kind of things.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on November 05, 2013, 08:49:42 pm
I hope that you could find a way to avoid audio latency that is probably the most worrying trouble with the gemei.

I wonder if there is some way of configuring the hardware for this, for example through some gpio...

if you can, take a look at http://drlionrsm.blogspot.fr/2013/07/dingoo-emulation-pack-v20.html#more  (http://drlionrsm.blogspot.fr/2013/07/dingoo-emulation-pack-v20.html#more) since it's something that may worth being ported to the gemei.

I don't know how to create a SIM file atm unfortunally. If that would be solved, porting over those emulators would probably be very easy.
(Although unrelated to lion's emulators) I have hugo (PCE) running on the gemei, but as said, didn't figure out how to make it work as an emulator, so I didn't really do much more with it.


As for the device itself, it's form factor and controls beats any other device imo.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on November 06, 2013, 02:48:54 pm
I don't know how to create a SIM file atm unfortunally. If that would be solved, porting over those emulators would probably be very easy.
(Although unrelated to lion's emulators) I have hugo (PCE) running on the gemei, but as said, didn't figure out how to make it work as an emulator, so I didn't really do much more with it.

We can look into that too :)

As for the device itself, it's form factor and controls beats any other device imo.

Mine makes wonkie noises when pressing right on the D-pad, but other than that I'm 100% satisfied with it. Maybe I should open the case and polish it a little bit in order to get this straight. That noise can be irritating sometimes :D
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on November 08, 2013, 02:29:58 am
I noticed the origin memory address was different between my working binaries and my non-working ones compiled on OSX. So I then tried to manually change this with a hex editor, and it seemed to work.

Grab the following code and compile it for your OS. Then after compiling any gemei application such as SDLPong, run my code on the .cc file, and hopefully the cc file should run on your gemei:
http://pastebin.com/ZZ4krdtX

But it would still be nice to get flatmush elf2app tool work with the gemei to not depend on the dlmake exe file..
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on November 08, 2013, 04:16:06 pm
I noticed the origin memory address was different between my working binaries and my non-working ones compiled on OSX. So I then tried to manually change this with a hex editor, and it seemed to work.

Grab the following code and compile it for your OS. Then after compiling any gemei application such as SDLPong, run my code on the .cc file, and hopefully the cc file should run on your gemei:
http://pastebin.com/ZZ4krdtX

But it would still be nice to get flatmush elf2app tool work with the gemei to not depend on the dlmake exe file..

That's great. I'll try it ASAP.

If the only thing that's actually making a difference is the entry point address, we could supply the -e0x138008b8 swich to ld as see what happens. I guess we could even specify it in the link script :)
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on November 09, 2013, 07:08:36 pm
Excellent! It worked like a charm.

However, I've failed to reproduce the result neither using ld input (the -e parameter) nor as a link script statement. I'm misunderstanding something, that's for sure.

I've triple-checked that the entry address for the ELF binary is indeed 0x138008b8, which was the entry point on the ELF file you sent me and that I dlmake'd into a working CC file under wine.

I have to go on the hunt for new furniture, but I'll keep trying later on :)
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on November 10, 2013, 12:48:28 am
Excellent! It worked like a charm.

However, I've failed to reproduce the result neither using ld input (the -e parameter) nor as a link script statement. I'm misunderstanding something, that's for sure.

I've triple-checked that the entry address for the ELF binary is indeed 0x138008b8, which was the entry point on the ELF file you sent me and that I dlmake'd into a working CC file under wine.

I have to go on the hunt for new furniture, but I'll keep trying later on :)

Great that it worked!

The origin is the address where the code will be loaded into on the gemei, not the address of the entry function.

Good luck with the furniture! :)
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on November 10, 2013, 07:22:47 am
The origin is the address where the code will be loaded into on the gemei, not the address of the entry function.

That's right, but I've noticed that the origin address can also be specified in link.xn:

Code: [Select]
MEMORY
{
        ram (wx) : ORIGIN = 0x13800000, LENGTH = 16M
}

Is that the value you're patching? I can see that you're writing 0x80 and 0x13 in your code, but I don't know if it is just a matter of coincidence or if you're enforcing this value because the linker failed to set it.

Thanks for all your help, and sorry to keep bugging you with so many questions.   

Good luck with the furniture! :)

Thanks! We've managed to spot all three needed pieces of furniture in a community-managed second-hand furniture store for ?65, delivery included. This was a triumph!
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on November 11, 2013, 10:18:18 pm
The origin is the address where the code will be loaded into on the gemei, not the address of the entry function.

That's right, but I've noticed that the origin address can also be specified in link.xn:

Code: [Select]
MEMORY
{
        ram (wx) : ORIGIN = 0x13800000, LENGTH = 16M
}

Is that the value you're patching? I can see that you're writing 0x80 and 0x13 in your code, but I don't know if it is just a matter of coincidence or if you're enforcing this value because the linker failed to set it.

Yea that's the value, it's in the other order in my program since I'm writing bytes and it's little endian... and I'm also not checking / writing the other zeroes, so it can be improved :P

So this could be an issue with dlmake and a new linker format, but also an issue where the linker does not pick up this value..
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on November 25, 2013, 10:25:14 am
I'm spending the little time I've got these days to study how things have been done in the SDL port. I find it quite strange how an OS task is being created every time you want to play some audio samples  ::)

Is that the proper way of doing it, or is it just a fix because of documentation being scarce?
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on November 25, 2013, 06:54:31 pm
I'm spending the little time I've got these days to study how things have been done in the SDL port. I find it quite strange how an OS task is being created every time you want to play some audio samples  ::)

Is that the proper way of doing it, or is it just a fix because of documentation being scarce?

The thread is created when you init audio, not every time you play a sample. You need to do the mixing in its own thread, otherwise you might not be able to feed it with audio data fast enough.
For example, if the drawing takes more time than it takes to play what's in the buffer, you would hear cracks in the music.

There are actually two threads, on that is mixing, and one that is writing it to wave out. The reason is because waveout_write is blocking, at least on the dingoo, so if you would use just one thread, there would be silence during the mixing.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on November 27, 2013, 10:08:26 am
Excellent explanation, thank you very much! This thing gets more and more interesting every day.

I've been trying to understand how things were done in other HAL's running on different architectures. Precisely, on GP2X (minimal lib) and GP32 (SDL). I would like to study how GPIO works. I've never worked at very low level, except for some work I did on microchip and intel microcontrollers in the late 90's.

I do have a question: doesn't the operating system prevent software to use these kind of low level resources? I mean, as far as I can remember, I was told quite a while ago that modern operating systems enforce the use of system calls, effectively preventing loadable programs from programming the hardware directly. Here's hoping that this is not the case, though ;D
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on November 29, 2013, 12:51:54 am
I do have a question: doesn't the operating system prevent software to use these kind of low level resources? I mean, as far as I can remember, I was told quite a while ago that modern operating systems enforce the use of system calls, effectively preventing loadable programs from programming the hardware directly. Here's hoping that this is not the case, though ;D

Well, MicroC/OS-II is a very small OS for embedded devices. Everything runs in kernel mode, so you can do what you want.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on November 29, 2013, 10:18:40 am
Ok, that's the difference then. Thanks!

I'll keep studying existing code  ;D
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Jonesie on January 08, 2014, 10:27:34 am
Just a quick message to state that I haven't ran away, just don't feel like posting until I have something to share :D
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: flexus on January 09, 2014, 05:44:00 pm
Nice to hear this from you. I belive in success!
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: Harteex on January 09, 2014, 09:19:30 pm
Just a quick message to state that I haven't ran away, just don't feel like posting until I have something to share :D

Looking forward to see what you're up to :)
I haven't had any time to do anything for the Gemei myself unfortunally.
Title: Re: Developing for Gemei A330 on Mac OS X
Post by: chevette on January 09, 2014, 10:13:53 pm
Glad you're still on the scene!!!