Main Site Documentation

Direct binary writing for RLP


#1

Hi everyone,

I use some ELF that are too big and causes an OutOfMemoryException sometimes when I try to load it in memory. I’m using a Fez Panda II.

So I tried to use the function GHIElectronics.NETMF.Hardware.LowLevel.AddressSpace.Write

Here is my code:

private void LoadElf(string pathElfFile)
        {
            byte[] buffer = new byte[1024];
            int count, offset = 0;
            FileStream stream = File.OpenRead(pathElfFile);

            // Load by part the file
            while (stream.Position < stream.Length)
            {
                count = stream.Read(buffer, 0, 1024);

                GHIElectronics.NETMF.Hardware.LowLevel.AddressSpace.Write(0x40000440 + (uint)offset, buffer, 0, count);
                offset += count;
            }

            stream.Close();
            buffer = null;
        }

And I retrieve function addresses in the map file. But when I try to call the procedure, the Invoke never return. It is stucked in RLP side.

Is it the ELF file that I have to write in memory with this function ?

Or is this something else like the hex file ?

Thanks for your help


#2

No not elf, you need to get the bin file and load it. Search the wiki for RLPLite.

By the way, you should be able to do this. Check your compiler for settings on shrinking the elf. Also, load the elf at the very beginning of your code befor allocating any memory.

How big is your elf file?


#3

Thanks for this very quick answer :wink:

I already shrink the ELF with -s option in the makefile. But it is not enough. I prefer to use RLPLite, I just saw it in the wiki, I think it will more optimized with it.

I saw that you use Keil µVision4 but can I configure NetBeans with the Yagarto toolchain ?


#4

You will continue using RLP but that page shows how to use addresss space.


#5

Ok thanks,

Maybe I miss something but I’m not able to generate the bin file.

I cannot find the fromelf program in yagarto. I tried also the “-O binary” option in the makefile but it doesn’t works. Here is my makefile that generates the ELF:


OUTFILE=InitDriver
LINKERSCRIPT=RLP_LinkScript.lds
OUTDIRECTORY=../../Resources
INCL=
CC		=arm-none-eabi-gcc
LD		=arm-none-eabi-gcc

CCFLAGS=  -g -mlittle-endian -mcpu=arm7tdmi  -Wall -I. -I$(INCL)
CCFLAGS+= -mapcs-frame -fno-builtin -g0

LDFLAGS =-nostartfiles -Wl,--Map -Wl,$(OUTDIRECTORY)/$(OUTFILE).map
LDFLAGS+=-lc -lgcc -Wl,--omagic
LDFLAGS+=-T $(LINKERSCRIPT)

OBJS+= CSharpMethod.o

rebuild: clean all del_o

all: $(OBJS)
	$(LD) $(LDFLAGS) -o $(OUTDIRECTORY)/$(OUTFILE).elf $(OBJS)

CSharpMethod.o: CSharpMethod.c 
	$(CC) -c $(CCFLAGS) CSharpMethod.c -o CSharpMethod.o

clean:
	-rm *.o $(OUTDIRECTORY)/$(OUTFILE).elf $(OUTDIRECTORY)/$(OUTFILE).map

del_o:
	-rm *.o

del_map:
	-rm $(OUTDIRECTORY)/*.map

What is the line to add ?

Thanks :wink:


#6

I installed Keil IDE and I found fromelf in it. I just tried with the binary and it doesn’t works…

The first function works, but when I tried a second one, the Invoke never returns. I double check addresses and they are correct.

Did I miss something ?

To get the binary I launch this command with cmd.exe:

fromelf.exe --bin --output file.bin file.elf

#7

How do you generate the bin file ?

I really cannot do it with fromelf.exe.

Thanks for your help


#8

I found the problem !

So, I can generate my bin file and I can call any function of mine

But, I get stuck in C code when I call something with RLPext-> . When I want to use the RLPext pointer, to call Delay or any other tools I am stuck in the Invoke.

I think, your paste the code at the end of the RLP memory space, but what can I call to do this ?

Thanks you