2009-03-26 23:42:37     u-boot bootelf loading >=64K section to L2 misbehaves

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

2009-03-26 23:42:37     u-boot bootelf loading >=64K section to L2 misbehaves

Rajiv Adhikary (UNITED STATES)

Message: 71649   

 

https://blackfin.uclinux.org/gf/project/u-boot/scmsvn/?action=browse&path=/trunk/u-boot-1.1.6/lib_blackfin/string.c&view=markup

 

says in a comment for function dma_memcpy_nocache

 

/* This version misbehaves for count values of 0 and 2^16+.

* Perhaps we should detect that ?  Nowhere do we actually

* use dma memcpy for those types of lengths though ...

*/

 

However if a baremetal elf has a data section that is larger than or equal to 64K that is to go to internal L2 SRAM (in a BF548), then this function will misbehave.

 

My hack is to modify memcpy function from the same file to:

 

   if (count >= (64*1024))

   {

      /* DMA cannot handle more than 64K */

        return memcpy_ASM(dst, src, count);

 

   }else if (addr_bfin_on_chip_mem(dst)) {

...

QuoteReplyEditDelete

 

 

2009-03-26 23:49:35     Re: u-boot bootelf loading >=64K section to L2 misbehaves

Mike Frysinger (UNITED STATES)

Message: 71651   

 

this has already been fixed in a different way in latest u-boot

QuoteReplyEditDelete

 

 

2009-03-27 08:30:29     Re: u-boot bootelf loading >=64K section to L2 misbehaves

Rajiv Adhikary (UNITED STATES)

Message: 71693   

 

Could you be more specific how it was fixed?

 

I am seeing this on U-Boot 1.1.6-svn1694 which I thought was fairly recent.

 

I will try updating to the head again and check.

 

 

QuoteReplyEditDelete

 

 

2009-03-27 10:03:47     Re: u-boot bootelf loading >=64K section to L2 misbehaves

Rajiv Adhikary (UNITED STATES)

Message: 71695   

 

Could you please tell me which branch it was fixed?

 

I tried the head (U-boot 1.1.6-svn1741). I am still seeing the same thing.

 

The elf file for a baremetal application has a data section that is 65545 bytes long which is intended to be placed in L2 SRAM.

 

Only (65545-64K) gets copied when I use bootelf  to boot this application.

 

 

QuoteReplyEditDelete

 

 

2009-03-27 12:23:58     Re: u-boot bootelf loading >=64K section to L2 misbehaves

Mike Frysinger (UNITED STATES)

Message: 71703   

 

1.1.6 in trunk is not maintained.  it's kept around only so long as 2008.10+ is found to be regression free.  you should be using 2008.10 for new development.

QuoteReplyEditDelete

 

 

2009-03-31 10:57:08     Re: u-boot bootelf loading >=64K section to L2 misbehaves

Rajiv Adhikary (UNITED STATES)

Message: 71886   

 

Thank you. I do not see this issue with the U-Boot 2008.10-svn1764.

 

But I have a different observation.

 

U-Boot 1.1.6 used to clear the bss sections upon bootelf command.

 

U-Boot 2008.10 says "Loading phdr 2 to 0xff904000 (0 bytes)" and does not clear the section.

 

Is it intended that the startup of the baremetal application will clear the bss sections?

QuoteReplyEditDelete

 

 

2009-03-31 13:54:14     Re: u-boot bootelf loading >=64K section to L2 misbehaves

Robin Getz (UNITED STATES)

Message: 71892   

 

Rajiv:

 

I thought it is the elf's responsibility to clear it's own bss. the elf loader (U-Boot, or gdb) doesn't know which section is which...

 

but - in u-boot-2008.10/common/cmd_elf.c - it appears to depend on how you built it up.

 

Have a look for CONFIG_ELF_SIMPLE_LOAD (if this is defined, it will not clear BSS). If it is defined:

 

 

                if (strtab) {

                        printf ("%sing %s @ 0x%08lx (%ld bytes)\n",

                                (shdr->sh_type == SHT_NOBITS) ?

                                        "Clear" : "Load",

                                &strtab[shdr->sh_name],

                                (unsigned long) shdr->sh_addr,

                                (long) shdr->sh_size);

                }

 

 

should clear it. (if the elf header is correct).

 

Since in u-boot-2008.10/include/configs/bfin_adi_common.h, there is a:

 

# define CONFIG_ELF_SIMPLE_LOAD

 

no clearing will occur. Just take that line out, and try again.

 

Mike - any idea why that is set on default? I wouldn't think that is correct?

QuoteReplyEditDelete

 

 

2009-03-31 15:19:09     Re: u-boot bootelf loading >=64K section to L2 misbehaves

Mike Frysinger (UNITED STATES)

Message: 71897   

 

this should change that (havent actually tested):

 

--- a/common/cmd_elf.c

+++ b/common/cmd_elf.c

@@ -276,7 +276,10 @@ unsigned long load_elf_image (unsigned long addr)

        void *src = (void *) addr + phdr->p_offset;

        printf ("Loading phdr %i to 0x%p (%i bytes)\n",

                i, dst, phdr->p_filesz);

-       memcpy (dst, src, phdr->p_filesz);

+       if (phdr->p_filesz)

+           memcpy (dst, src, phdr->p_filesz);

+       if (phdr->p_filesz != phdr->p_memsz)

+           memset (dst + phdr->p_filesz, 0x00, phdr->p_memsz - phdr->p_filesz);

        flush_cache ((unsigned long)dst, phdr->p_filesz);

        ++phdr;

    }

QuoteReplyEditDelete

 

 

2009-04-01 10:27:18     Re: u-boot bootelf loading >=64K section to L2 misbehaves

Robin Getz (UNITED STATES)

Message: 71960   

 

Mike:

 

Are you going to commit & send upstream? or wait for Rajiv to confirm that it works? (And then the print looks wonky - since it still says "Loading"?)

 

-Robin

QuoteReplyEditDelete

 

 

2009-04-01 11:11:38     Re: u-boot bootelf loading >=64K section to L2 misbehaves

Mike Frysinger (UNITED STATES)

Message: 71962   

 

the simple load code is currently Blackfin local ... i need to tweak it a little to make upstream happy

 

if Rajiv confirms it works, i can commit it to our svn tree

QuoteReplyEditDelete

 

 

2009-04-01 11:39:39     Re: u-boot bootelf loading >=64K section to L2 misbehaves

Rajiv Adhikary (UNITED STATES)

Message: 71965   

 

Thank you Robin, Mike.

 

I confirm that Mike's changes work for me.

 

About bootelf clearing bss sections - I was merely noting a change in behavior from the u-boot 1.1.6 released version and the u-boot 2008.10.

 

It is convenient if bootelf does it.  Since baremetal applications try to maximize internal memory usage, they tend to split up bss sections. Having ldf report the start and stop of many bss sections and the runtime setup clearing each one is clumsy.

Attachments

    Outcomes