Author Topic: Trying to get a basic app built and deployed  (Read 5624 times)

chikinpotpi (OP)

  • *
  • Posts: 8
Trying to get a basic app built and deployed
« on: August 01, 2014, 10:59:31 pm »
Hi everyone!
I am new to the gcw but have been developing software for many years on various platforms.

I am trying to just get the minimum application possible to build and deploy. If there is a sticky some place that i have missed please let me know.

i am on ubuntu and have installed the latest toolchain to /opt/

i set up the toolchain in code blocks as follows:


my code is pretty simple
Code: [Select]
#include <SDL.h>

int isExit;
SDL_Surface *screen = NULL;
SDL_Event event;

int main(int argc, char *argv[])
{
    isExit = 0;

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
    screen = SDL_SetVideoMode(320, 240, 32, SDL_SWSURFACE);
    SDL_ShowCursor(SDL_DISABLE);
   
    SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 255, 0, 0));
    SDL_Flip(screen);

    while(!isExit)
    {
        if(SDL_PollEvent(&event))
        {
            switch(event.type)
            {
                case SDL_KEYDOWN:
                case SDL_KEYUP:
                    isExit = 1;
                    break;
                default:
                    break;
            }
        }
        SDL_Delay(1);
    }

    SDL_Quit();

    return 0;
}

and i use the Open Package Creator tool to bundle up my application output:


i move the opk over to the device in  /media/data/apps/
and it shows up on the games screen, but when i run it, it flickers for a second then goes back to the main screen.

Im sure i am missing something fairly basic. Any help you all could provide would be greatly appreciated.

Thanks!

Nebuleon

  • Guest
Re: Trying to get a basic app built and deployed
« Reply #1 on: August 01, 2014, 11:07:48 pm »
Code: [Select]
  printf("I have run successfully\n"); after your event loop. Then, on the GCW Zero, press Start and enable "Output logs". Run this new application and go to /Settings/Log Viewer.

If you see the message, then what you might have done wrong is to quit on any SDL_KEYUP - because the application may receive one or more of those when it starts. In that case, just use SDL_KEYDOWN.

zear

  • * Moderator
  • Posts: 2379
Re: Trying to get a basic app built and deployed
« Reply #2 on: August 01, 2014, 11:25:16 pm »
What are the chmods of the executable? It should have the execution rights. You can set them by calling "chmod +x your_executable". I have no idea if the Open Package Creator application sets the chmods for you - I always build opks manually with "mksquashfs".
You can also make sure whether your executable is a MIPS elf by typing: "file your_executable" - maybe you accidently compiled a binary for your host architecture.

chikinpotpi (OP)

  • *
  • Posts: 8
Re: Trying to get a basic app built and deployed
« Reply #3 on: August 01, 2014, 11:37:45 pm »
Code: [Select]
  printf("I have run successfully\n"); after your event loop. Then, on the GCW Zero, press Start and enable "Output logs". Run this new application and go to /Settings/Log Viewer.

If you see the message, then what you might have done wrong is to quit on any SDL_KEYUP - because the application may receive one or more of those when it starts. In that case, just use SDL_KEYDOWN.

I tried a few things.

1) i turned on logging, but the Log Viewer Application is nowhere on my device... I am on the latest firmware from the gcw site (2014-05-05).

2) in the absence of logging i actually just tried your suggestion that there was a stray keyup leftover from when i launched the application so i removed the SDL_KEYUP case... this didn't have any effect.

So i guess the first thing i need to do is get logging up and going...

What are the chmods of the executable? It should have the execution rights. You can set them by calling "chmod +x your_executable". I have no idea if the Open Package Creator application sets the chmods for you - I always build opks manually with "mksquashfs".
You can also make sure whether your executable is a MIPS elf by typing: "file your_executable" - maybe you accidently compiled a binary for your host architecture.

file info "ELF 32-bit LSB  executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked (uses shared libs), not stripped"

ls -l results "-rwxrwxr-x"

zear

  • * Moderator
  • Posts: 2379
Re: Trying to get a basic app built and deployed
« Reply #4 on: August 01, 2014, 11:45:28 pm »
Your chmods seem fine.
You can find the Log Viewer application at the following location:

Just note that if your gmenu2x is set to use a language other than English, the name of this application will be different as well.

Nebuleon

  • Guest
Re: Trying to get a basic app built and deployed
« Reply #5 on: August 01, 2014, 11:48:11 pm »
I tried a few things.

1) i turned on logging, but the Log Viewer Application is nowhere on my device... I am on the latest firmware from the gcw site (2014-05-05).
<snip>
The Log Viewer appears only once you've closed an application that logged some output, while the option was enabled.

If it still doesn't appear now, then you might also want to include logging before the SDL event loop, because the rest (MIPS executable with the 'x' permission) is good.

zear

  • * Moderator
  • Posts: 2379
Re: Trying to get a basic app built and deployed
« Reply #6 on: August 01, 2014, 11:50:01 pm »
Anyway, I compiled your code, packed it manually into an OPK and it works on my GCW Zero (firmware newer than the last official release). Nebuleon is also right that SDL sees SDL_KEYUP if you keep holding the button long enough for the program to launch in the meantime.

pcercuei

  • ***
  • Posts: 1432
    • My devblog
Re: Trying to get a basic app built and deployed
« Reply #7 on: August 01, 2014, 11:54:30 pm »
I see you include <SDL.h>, that means that you call sdl-config somewhere to get the include flags? Do you call the correct one, the one in the toolchain?

chikinpotpi (OP)

  • *
  • Posts: 8
Re: Trying to get a basic app built and deployed
« Reply #8 on: August 01, 2014, 11:59:42 pm »
The Log Viewer appears only once you've closed an application that logged some output, while the option was enabled.

If it still doesn't appear now, then you might also want to include logging before the SDL event loop, because the rest (MIPS executable with the 'x' permission) is good.

ok so i removed all the SDL code and just put a printf("hello world\n"); the log viewer now exists, but its empty. so this lets me know that my program isnt executing at all.

Anyway, I compiled your code, packed it manually into an OPK and it works on my GCW Zero (firmware newer than the last official release). Nebuleon is also right that SDL sees SDL_KEYUP if you keep holding the button long enough for the program to launch in the meantime.

does the latest toolchain on the gcw public page target a newer firmware than the last public one?

where can i get the latest non public firmware?

chikinpotpi (OP)

  • *
  • Posts: 8
Re: Trying to get a basic app built and deployed
« Reply #9 on: August 02, 2014, 12:02:36 am »
I see you include <SDL.h>, that means that you call sdl-config somewhere to get the include flags? Do you call the correct one, the one in the toolchain?

im not 100% sure what that means...

my build output looks as follows.

mipsel-gcw0-linux-uclibc-gcc -Wall -g -std=c99 -I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include/SDL -c "/home/jonathan/Code/GCW Zero/TestGCW/main.c" -o obj/Debug/main.o
mipsel-gcw0-linux-uclibc-g++  -o bin/Debug/TestGCW obj/Debug/main.o   -lSDL

this is typically all i have ever had to do to get sdl desktop working...

pcercuei

  • ***
  • Posts: 1432
    • My devblog
Re: Trying to get a basic app built and deployed
« Reply #10 on: August 02, 2014, 12:12:29 am »
SDL comes with a binary called "sdl-config" that you can call with different flags to get the CFLAGS/LDFLAGS for SDL.
On the OpenDingux toolchain:
Code: [Select]
<paul:~/dev/gcw0/kernel> $ /opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/bin/sdl-config --cflags
-I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT

So you lack the two defines at the end. Not a big deal though, I doubt that makes your program crash.

What I would suggest is to connect to your Zero through telnet or SSH, and run your opk by typing "opkrun testapp.opk" after launching the "Terminal" link to disable the graphical console. Then you will have all the debug messages directly in your terminal.

zear

  • * Moderator
  • Posts: 2379
Re: Trying to get a basic app built and deployed
« Reply #11 on: August 02, 2014, 12:25:47 am »
Let's exclude Open Package Creator's fault first (nobody tested it on Linux).

1) Install mksquashfs from your distribution's repository (usually comes with squashfs-tools or similar package in most distributions)
2) Prepare a text file (with Unix line breaks), named default.gcw0.desktop and the following content:
Code: [Select]
Name=Testing
Comment=Just testing
Exec=your_executable
Terminal=false
Type=Application
StartupNotify=true
Categories=games;
3) Make sure to run: chmod +x your_executable to set the correct chmods.
4) Run:
Code: [Select]
mksquashfs your_executable default.gcw0.desktop test.opk -all-root -noappend -no-exports -no-xattrs5) Attempt to run it on GCW Zero, with logs ON.

chikinpotpi (OP)

  • *
  • Posts: 8
Re: Trying to get a basic app built and deployed
« Reply #12 on: August 02, 2014, 12:27:30 am »
What I would suggest is to connect to your Zero through telnet or SSH, and run your opk by typing "opkrun testapp.opk" after launching the "Terminal" link to disable the graphical console. Then you will have all the debug messages directly in your terminal.

ok so i did that, and the application works when i am in terminal mode and i run it via ssh...

but the application still wont run from the desktop.

zear

  • * Moderator
  • Posts: 2379
Re: Trying to get a basic app built and deployed
« Reply #13 on: August 02, 2014, 12:30:40 am »
Feel free to upload your OPK so we can inspect it.

chikinpotpi (OP)

  • *
  • Posts: 8
Re: Trying to get a basic app built and deployed
« Reply #14 on: August 02, 2014, 12:38:30 am »
Feel free to upload your OPK so we can inspect it.

i have put my opk on my site.

http://chikinpotpi.com/opk/test.opk



zear

  • * Moderator
  • Posts: 2379
Re: Trying to get a basic app built and deployed
« Reply #15 on: August 02, 2014, 01:20:34 am »
Upon examining the OPK:
Code: [Select]
Icon=home/jonathan/Downloads/favicon1) There is no such path as "home/", every absolute path in Unix/Linux must begin with "/"
2) There is no such location inside GCW Zero as the one above - this is attempting to link to your PC
3) Icons should be located inside the OPK and then you can use "./" to denote the local directory
4) If the icon is unused, remove the "Icon" line.

The OPK is not working possibly because the icon line is broken.

chikinpotpi (OP)

  • *
  • Posts: 8
Re: Trying to get a basic app built and deployed
« Reply #16 on: August 02, 2014, 01:32:23 am »
Upon examining the OPK:
Code: [Select]
Icon=home/jonathan/Downloads/favicon1) There is no such path as "home/", every absolute path in Unix/Linux must begin with "/"
2) There is no such location inside GCW Zero as the one above - this is attempting to link to your PC
3) Icons should be located inside the OPK and then you can use "./" to denote the local directory
4) If the icon is unused, remove the "Icon" line.

The OPK is not working possibly because the icon line is broken.

awesome!

this is what i get for using a tool to build my opk instead of doing it manually... i assumed it was relocating all the files i selected into a temp folder and compressing that. It just needed my icon to be in the same folder.

as for the crashes, it seems that the desktop didnt appreciate my malformed icon path. I made a desktop file manually and created my own opk from the command line and everything works now

Thank you all so much!

zear

  • * Moderator
  • Posts: 2379
Re: Trying to get a basic app built and deployed
« Reply #17 on: August 02, 2014, 01:43:32 am »
Glad to hear you got it working. And thanks - with your help we managed to find a bug in gmenu2x that is normally supposed to handle malformed icon paths :)

And just to clarify - it's the gmenu2x (the menu application) that didn't appreciate the malformed path, not the .desktop config itself. opkrun read the .desktop without a problem, thus it's not an issue of .desktop :)

Optimus

  • *
  • Posts: 102
Re: Trying to get a basic app built and deployed
« Reply #18 on: August 03, 2014, 06:00:01 pm »
Hah, by reading parts of this thread I realized what was going on with one of my projects yesterday, that didn't manage to run like the rest, this didn't have it's own icon in the folder and I just provided one from outside. Good to know.