Author Topic: Ndless bFLT loader  (Read 18562 times)

0 Members and 3 Guests are viewing this topic.

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Ndless bFLT loader
« Reply #15 on: April 04, 2012, 04:14:55 am »
Ah, OK, false alarm then :)
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline tangrs

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 229
  • Rating: +98/-0
    • View Profile
    • tangrs blog
Re: Ndless bFLT loader
« Reply #16 on: April 05, 2012, 10:08:47 pm »
I'm hoping to get this bFLT loader integrated into Ndless. Is there anything else that needs to be done for this to happen?

Update:

C++ toolchain is on its way! Very basic support is already working (new and delete works, function overriding works).

Source code is in a different branch at the moment. https://github.com/tangrs/ndless-bflt-loader/tree/c++-support
« Last Edit: April 06, 2012, 08:36:37 am by tangrs »

Offline atiatinini

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 19
  • Rating: +0/-0
    • View Profile
Re: Ndless bFLT loader
« Reply #17 on: May 06, 2012, 05:13:37 pm »
Any progress on this?  :)

Offline tangrs

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 229
  • Rating: +98/-0
    • View Profile
    • tangrs blog
Re: Ndless bFLT loader
« Reply #18 on: May 06, 2012, 06:39:39 pm »
Any progress on this?  :)

Been working on it on and off.

I'm trying to work out a efficient system for shared and dynamic libraries. Ater that, I'm also trying to get the C++ standard library and exceptions working.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Ndless bFLT loader
« Reply #19 on: May 06, 2012, 06:43:46 pm »
For a second I thought you were replying to your own post somewhere but then I realized you deleted your double post and the above was by someone else.

Hopefully this continues being developed :)

Offline totorigolo

  • LV2 Member (Next: 40)
  • **
  • Posts: 24
  • Rating: +9/-0
    • View Profile
Re: Ndless bFLT loader
« Reply #20 on: June 28, 2012, 04:36:19 pm »
I managed to build the toolchain on Windows with MSYS (after a lot of errors and hours). I've also patched Ndless (r632 instead of r573, because I have not found the r573 here) and I successfully make(d) it.

But when I tried to run the "test" (here), the nspire_emu console give me :
Quote from: nspire_emu
bFLT: Begin loading
bFLT: Version number does not match
bFLT: Bad header
bFLT: Caught error - exiting

<EDIT>: The true error message is :
Quote from: nspire_emu
bFLT: Begin loading
bFLT: Magic number does not match
bFLT: Bad header
bFLT: Caught error - exiting
But I tried to change the magic number ("ELF" to "bFLT") of the .tns and I obtained the error message above.
</EDIT>

I don't know what to do, because the test is supposed to work... So if you have an explanation :)

totorigolo
Sorry for my English, I'm French :)
« Last Edit: June 28, 2012, 05:12:52 pm by totorigolo »
nRGBlib - A portable graphic library for Nspire !

Offline tangrs

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 229
  • Rating: +98/-0
    • View Profile
    • tangrs blog
Re: Ndless bFLT loader
« Reply #21 on: July 03, 2012, 08:28:16 pm »
I managed to build the toolchain on Windows with MSYS (after a lot of errors and hours). I've also patched Ndless (r632 instead of r573, because I have not found the r573 here) and I successfully make(d) it.

But when I tried to run the "test" (here), the nspire_emu console give me :
Quote from: nspire_emu
bFLT: Begin loading
bFLT: Version number does not match
bFLT: Bad header
bFLT: Caught error - exiting

<EDIT>: The true error message is :
Quote from: nspire_emu
bFLT: Begin loading
bFLT: Magic number does not match
bFLT: Bad header
bFLT: Caught error - exiting
But I tried to change the magic number ("ELF" to "bFLT") of the .tns and I obtained the error message above.
</EDIT>

I don't know what to do, because the test is supposed to work... So if you have an explanation :)

totorigolo
Sorry for my English, I'm French :)

It seems that you're just renaming the ELF file to bFLT format and changing the magic number. That won't work :)

You also need to download the elf2flt program and use that to convert your ELF to a bFLT file. Look in the Makefile of the test program to see an example.

Information on how to set up a proper bFLT toolchain can be found at https://github.com/tangrs/ndless-bflt-toolchain. The toolchain contains scripts that handles all the linking commands for you so you can use it to produce a bFLT straight away.

Offline ajorians

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 105
  • Rating: +47/-0
    • View Profile
Re: Ndless bFLT loader
« Reply #22 on: April 01, 2013, 10:26:47 am »
Hi,

I am happy to say I got all of the example code working!

But I did run into an issue; and I'll see what I can find out but I figured I'd still post it in case others already seen the same thing.

So with the shared_library_test after I already got everything building and working with no problems I then tried to expand on it.

I wanted to make example_executable a nSDL executable.  So I added another include at the top of main.c:
#include <SDL/SDL.h>

Then somewhere in the main function I added some code to utilize something in nSDL; I added this line:
SDL_Init(SDL_INIT_VIDEO);

The nspire-bflt-ld command was adjusted to have -lSDL and the error I am getting is:
Code: [Select]
ajorians@ajlaptop:~/Downloads/bflt/ndless-bflt-toolchain-master/shared_library_test/example_executable> makenspire-bflt-gcc -Wl,-R,../example_shared_lib/bin/lib3.so.tns.gdb -r -o test.bflt.tns.o
nspire-bflt-gcc -Wall -W -c main.c
main.c: In function ‘main’:
main.c:24:14: warning: unused parameter ‘argc’ [-Wunused-parameter]
main.c:24:26: warning: unused parameter ‘argv’ [-Wunused-parameter]
nspire-bflt-ld test.bflt.tns.o main.o ../example_shared_lib/bin/lib3_wraps.o -o test.bflt.tns -Wl,--wrap,library_call 
/home/ajorians/bin/arm-none-eabi-gcc -Wl,-elf2flt -nostartfiles -T /home/ajorians/Downloads/ndless-v3.1-beta-r695-sdk/ndless/bin/../system/ldscript_bflt -L /home/ajorians/Downloads/ndless-v3.1-beta-r695-sdk/ndless/bin/../lib -static /home/ajorians/Downloads/ndless-v3.1-beta-r695-sdk/ndless/bin/../system/crt0_bflt.o /home/ajorians/Downloads/ndless-v3.1-beta-r695-sdk/ndless/bin/../system/osstub.o test.bflt.tns.o main.o ../example_shared_lib/bin/lib3_wraps.o -o test.bflt.tns -Wl,--wrap,library_call -lSDL -lnspireio -lndls
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_NONE unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_NONE unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_NONE unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_NONE unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_NONE unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_NONE unsupported in this context
ERROR: reloc type R_ARM_PREL31 unsupported in this context
ERROR: reloc type R_ARM_NONE unsupported in this context
48 bad relocs
collect2: ld returned 1 exit status
make: *** [test.bflt.tns] Error 1

I can change example_executable to be a nRGBLib or nspireio executable but nSDL executable gave the above errors.

I'll keep looking for other ways to do things and I'll let you guys know what I find!  Let me know if you have any ideas or hints! :)

Thanks for your time!

Offline ExtendeD

  • Project Author
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: Ndless bFLT loader
« Reply #23 on: April 01, 2013, 04:29:49 pm »
The loader has actually been integrated to Ndless's trunk a while ago but I'm getting the same error when linking to nSDL. Without any solution I can't release the update.
Ndless.me with the finest TI-Nspire programs

Offline tangrs

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 229
  • Rating: +98/-0
    • View Profile
    • tangrs blog
Re: Ndless bFLT loader
« Reply #24 on: April 01, 2013, 06:22:47 pm »
Yes, during development I also got a lot of these errors. Unfortunately, I'm not exactly certain of why these errors occur. I suspect the elf2flt program is too old to handle the new kinds of relocations in gcc. I understand this is a bit of a pain for a lot of people so I'll probably end up either writing a custom program to do the conversions from ELF to bFLT when I have time.

Technically speaking, elf2flt is trying to handle most of the linking which is why it's giving all these errors. In reality, we can tell the linker to do it for us and add the --emit-relocs flag. This creates a section in the ELF file that has a list of relocations that the linker did. All we have to do is search for the R_ARM_ABS32 relocations and somehow add the base address to it at run time.

The program I am thinking of writing will call the linker to link it for us while adding the --emit-relocs flag. It will then dump the text and data section into a bFLT file and search through the list of relocs for R_ARM_ABS32 types and add them to the relocations list in the bFLT file.

Sorry for all this mess. The runtime linker might be working but the toolchain doesn't appear to :(
« Last Edit: April 01, 2013, 06:23:20 pm by tangrs »

Offline ajorians

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 105
  • Rating: +47/-0
    • View Profile
Re: Ndless bFLT loader
« Reply #25 on: April 01, 2013, 08:20:47 pm »
Thank you so much for your replies!  Your answers were very helpful!

Have a great day!