2008-11-27 03:21:16     bf537 function in l1 memory

Document created by Aaronwu Employee on Aug 8, 2013
Version 1Show Document
  • View in full screen mode

2008-11-27 03:21:16     bf537 function in l1 memory

Daniele Pagani (ITALY)

Message: 65887   

 

Dear sirs,

 

in according to:

 

http://docs.blackfin.uclinux.org/doku.php?id=using_l1_memory

 

I can use:

 

void *sram_alloc (size_t size, unsigned long flags)

 

with flag:

L1_INST_SRAM

 

The question is: how can I know the size of a function? That is, how can I use this flag?

 

Best regards,

 

Daniele.

TranslateQuoteReplyEditDelete

 

 

2008-11-27 04:20:46     Re: bf537 function in l1 memory

Yi Li (CHINA)

Message: 65898   

 

Sorry, I cannot understand your question. "L1_INST_SRAM" means allocating from L1 instruction memory.

QuoteReplyEditDelete

 

 

2008-11-27 04:53:09     Re: bf537 function in l1 memory

Daniele Pagani (ITALY)

Message: 65900   

 

In userspace, I've a function into a .s file.

 

Then, I call this function from a .c source file.

 

I want to allocate this function into l1 code memory.

 

Now I do:

 

1) I see the .o file and I see the size of the function (reading the label.end) ( now I define "size" this size)

 

2) I define a pointer the to function (ptr_function)

 

3) I use: ptr_function=sram_alloc(size,L1_INST_RAM)...

 

4) then I use: dma_memcpy(ptr_function,fuction,size)

 

5) I use ptr_function in order to call my function from l1 memory.

 

It works fine, anyway I like to know if this could be the right way.

 

Best regards,

 

Daniele.

 

 

TranslateQuoteReplyEditDelete

 

 

2008-11-27 21:05:43     Re: bf537 function in l1 memory

Mike Frysinger (UNITED STATES)

Message: 65931   

 

that's up to you to calculate as there is no standard method to do so.  if you're writing the .s file yourself, then you can put marker symbols around the function and then calculate the difference.  if it's in a C file, then you'd have to figure it out yourself (using nm or readelf or something).

 

also keep in mind that you cannot have any relative relocs in the function or it wont work at runtime.

QuoteReplyEditDelete

 

 

2008-11-27 21:10:57     Re: bf537 function in l1 memory

Mike Frysinger (UNITED STATES)

Message: 65932   

 

oh, and in general, what you're trying to do is not supported.  use FDPIC ELF and gcc attributes to selectively placed functions into L1.  that is the only method supported.

QuoteReplyEditDelete

 

 

2008-11-28 04:59:47     Re: bf537 function in l1 memory

Daniele Pagani (ITALY)

Message: 65952   

 

Dear Mike,

 

I don't understand exactly.

 

I have a .s file with a function foo

 

.global _foo;

 

.align 4;

 

_foo:

 

...

 

_foo.end;

 

Now I declare it as extern in .c file.

 

extern void foo(...).

 

If I want to allocate it in l1, I need to use:

 

__attribute__ ((l1_text));

 

when I compile I need to use:

 

bfin-linux-uclibc-gcc -fno-jump-tables

 

But, if I want to "tell" about allocation in assembler, I suppose I need to use:

 

.section l1_text;

 

in .s file and

 

extern void foo(...) __ attribute__ ((l1_text))

 

in .c file.

 

Anyway, this solution give me a:

 

"can't resolve symbol '_foo0.

 

What is wrong?

 

Thank you very much in advanced.

 

Daniele.

TranslateQuoteReplyEditDelete

 

 

2008-11-28 08:06:49     Re: bf537 function in l1 memory

Robin Getz (UNITED STATES)

Message: 65960   

 

Daniele:

 

As Mike stated - splitting up applicaitons (some in L1 and some in external memory) is only supported via fdpic. You can not use the bfin-uclinux compiler - only the bfin-linux-uclibc one.

 

-Robin

QuoteReplyEditDelete

 

 

2008-11-28 09:01:18     Re: bf537 function in l1 memory

Daniele Pagani (ITALY)

Message: 65963   

 

Dear Robin,

 

I understand what you are explain me. But I have a problem compiling with bfin-linux-uclibc-gcc and I don't understand the reason because usually I use bfin-uclinux-gcc. So, please, follow my simple example:

 

main.c

 

int main(){

 

extern my_function...

 

my_function(..);

 

}

 

********************

 

my_function.s

 

.global _my_function

 

...

 

******************

 

bfin-linux-uclibc-gcc my_function.s main.c -o main

 

I receive an error like:

 

main.c:(..): warning: warning: relocation references a different segment

 

Any suggestion?

 

Best regards,

 

Daniele.

 

 

TranslateQuoteReplyEditDelete

 

 

2008-11-28 10:38:51     Re: bf537 function in l1 memory

Daniele Pagani (ITALY)

Message: 65968   

 

Robin:

 

I've found in document the answer to my last question:

 

http://docs.blackfin.uclinux.org/doku.php?id=simple_hello_world_application_example_asm

 

Anyway, my first question is:

 

can I use the sram_alloc function in FLAT format?

 

This because I use it and I don't understand if it is supported or not.

 

Best regards,

 

Daniele.

TranslateQuoteReplyEditDelete

 

 

2008-11-28 12:23:13     Re: bf537 function in l1 memory

Robin Getz (UNITED STATES)

Message: 65976   

 

Daniele:

 

Go read the documenation:

 

http://docs.blackfin.uclinux.org/doku.php?id=using_l1_memory#using_l1_in_user_space

 

It is pretty clear: "The bfin-uclinux-gcc (flat format) does not support using L1 memory."

 

-Robin

QuoteReplyEditDelete

 

 

2008-11-28 14:01:30     Re: bf537 function in l1 memory

Mike Frysinger (UNITED STATES)

Message: 65980   

 

the sram_alloc() function does not care what binary format you're using.  it's just like malloc()/free().

QuoteReplyEditDelete

 

 

2008-11-28 14:45:15     Re: bf537 function in l1 memory

Daniele Pagani (ITALY)

Message: 65982   

 

Dear Mike and Robin,

 

sorry, but I'm a little confused.

 

Here the lines that I don't understand:

 

"There are now three new Blackfin specific system calls in kernel. They are exported in uClibc. They can be used in both FDPIC and FLAT.

 

To use these three functions, you need

 

#include <bfin_sram.h>

 

void *sram_alloc (size_t size, unsigned long flags)

int sram_free (void *addr)

void *dma_memcpy (void *dest, const void *src, size_t size)

 

"

 

These lines are from: http://docs.blackfin.uclinux.org/doku.php?id=using_l1_memory#dynamically_allocating1

 

(Please, Robin, I don't find the text that you've reported in this document.)

 

So, in my opinion, these lines are clear, I can use sram_alloc also with FLAT.

 

What I don't understand?

 

Thank you very much,

 

Best regards,

 

Daniele.

 

 

TranslateQuoteReplyEditDelete

 

 

2008-11-28 14:49:18     Re: bf537 function in l1 memory

Daniele Pagani (ITALY)

Message: 65984   

 

Sorry, and I add also the example from the same document:

Test Code

 

#include <stdio.h>

#include <bfin_sram.h>

 

int main(int argc, char *argv[])

{

    char *sram = sram_alloc(256, L1_INST_SRAM);

    printf("sram=%p\n", sram);

    sram_free(sram);

    return 0;

}

 

To build as BFLT:

 

bfin-uclinux-gcc -Wl,-elf2flt test.c -o test

 

This is exactly my situation, that is, I alloc data and instruction ram and I put in it function and data.

 

Why it is not supported?

 

Daniele

TranslateQuoteReplyEditDelete

 

 

2008-11-28 15:32:12     Re: bf537 function in l1 memory

Mike Frysinger (UNITED STATES)

Message: 65985   

 

they are two different sections.  the comments in one section apply to that section alone.

QuoteReplyEditDelete

 

 

2008-11-28 15:33:10     Re: bf537 function in l1 memory

Mike Frysinger (UNITED STATES)

Message: 65986   

 

using sram_alloc() to allocate text memory and than manually copying a function into it an copying may work -- if you take precautions.  but this isnt supported, so if things crash, it's up to you to figure out what went wrong.

QuoteReplyEditDelete

 

 

2008-11-28 20:47:04     Re: bf537 function in l1 memory

Robin Getz (UNITED STATES)

Message: 65994   

 

Daniele:

 

Goto the link I gave you - it is in the 2nd paragraph.

 

It does not work natively with flat. As Mike said - if you understand things well enough - you may be able to force it to work with flat - however - it appears from the examples you are posting, that this is not you - so don't try - we don't support it.

 

Use bfin-linux-uclibc - we can answer questions about that.

 

-Robin

QuoteReplyEditDelete

 

 

2008-11-30 08:41:16     Re: bf537 function in l1 memory

Daniele Pagani (ITALY)

Message: 66038   

 

Dear Robin,

 

the problem form me is not "flat" or "fdpic", but is statically or dinamically allocation in L1.

 

I understand that is better now for my low skills about the matter using static, but I'm not sure that I've enough space.

 

The customer could choose (runtime) the audio alghoritm, from fir to iir and so on, so for me could be interesting alloc/free piece of code (variable and instructions) into L1.

 

I need to put them in L1 for performance reasons.

 

So,I'll use fdpic and I'll statically define function and variable in L1.

 

But, considering fdpic, I've not clear a question:

 

http://docs.blackfin.uclinux.org/doku.php?id=simple_hello_world_application_example_asm

 

paragraph Assembly code (fdpic elf 1 and 2)

 

I understand the example, but what I need is calling a function defined in .s assembler file from a .c file? That is:

 

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

 

my_function.s

 

.global _my_function

 

.section .l1.text

 

_my_function:

 

...

 

_my_function.end:

 

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

 

main.c

 

extern void my_function(..); // Do I need to use also __attribute__ ((l1.text)) ?

 

int main(){

 

...my_function(...)

 

}

 

Then, I'll use bfin-linux-uclibc-gcc to do the rest.

 

Any suggestions?

 

Best regards,

 

Daniele.

 

 

 

 

TranslateQuoteReplyEditDelete

 

 

2008-11-30 13:44:58     Re: bf537 function in l1 memory

Mike Frysinger (UNITED STATES)

Message: 66045   

 

you should have attribute markings on all function prototypes and definitions.

 

if people are doing things on the fly, then use FDPIC and plugins.  then you can easily load/unload different codecs on the fly.

QuoteReplyEditDelete

 

 

2008-11-30 22:14:39     Re: bf537 function in l1 memory

Sonic Zhang (CHINA)

Message: 66048   

 

You can load code in/out L1 dynamically by FDPIC library as well.

 

Just put all L1 code into several FDPIC libraries, which is small than the available L1 SRAM. Then, load library and access functions by dlopen(), dlclose(), dlsym(), etc in your application per request.

Attachments

    Outcomes