public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] hi, I could not understand the memsize.c, somebody help me?
@ 2009-06-25  3:14 IaMaPlAyEr
  2009-06-25 12:56 ` Detlev Zundel
  2009-07-24  6:11 ` Wolfgang Denk
  0 siblings, 2 replies; 10+ messages in thread
From: IaMaPlAyEr @ 2009-06-25  3:14 UTC (permalink / raw)
  To: u-boot

Hi all,


I could not understand common/memsize.c, how it works?

maxsize / sizeof (long), what's meaning of it? why sizeof (long) is
dividend?

just like stack,  push every step mem addr to save:

save[i++] = *addr;
and then?


thanks

-- 
--
Sincerely,

HaveF

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] hi, I could not understand the memsize.c, somebody help me?
  2009-06-25  3:14 [U-Boot] hi, I could not understand the memsize.c, somebody help me? IaMaPlAyEr
@ 2009-06-25 12:56 ` Detlev Zundel
  2009-06-29  8:54   ` IaMaPlAyEr
  2009-07-24  6:11 ` Wolfgang Denk
  1 sibling, 1 reply; 10+ messages in thread
From: Detlev Zundel @ 2009-06-25 12:56 UTC (permalink / raw)
  To: u-boot

Hi ya,

> I could not understand common/memsize.c, how it works?

Like a charm ;)

> maxsize / sizeof (long), what's meaning of it? why sizeof (long) is
> dividend?

As the comment in line 50 states, "cnt" is used in pointer arithmetic,
so addr is increased in sizeof(long) bytes.  maxsize however is
considered to be in bytes only.  Makes sense?

> just like stack,  push every step mem addr to save:
>
> save[i++] = *addr;
> and then?

Cannot parse the question.  

The algorithm should be pretty clear however (take a paper and pencil
and work out the values of addr as it proceeds) - we save the original
content of the adressed cells and write our own pattern there (~cnt).
Then we walk these cells upward and see where the previous write did not
work like it was supposed to - voila.

Cheers
  Detlev

-- 
The continental people think life is a game. The English think
cricket is a game.
                                                     -- George Mikes
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] hi, I could not understand the memsize.c, somebody help  me?
  2009-06-25 12:56 ` Detlev Zundel
@ 2009-06-29  8:54   ` IaMaPlAyEr
  2009-06-29 11:54     ` Detlev Zundel
  0 siblings, 1 reply; 10+ messages in thread
From: IaMaPlAyEr @ 2009-06-29  8:54 UTC (permalink / raw)
  To: u-boot

hi~

thanks for your reply.
sorry for my ability of writing and understanding the code
=D

btw, How contribute my idea of this function, I means, it should be more
 clean or easy just like this:


unsigned long get_ram_size(volatile long *base, long maxsize)
{

        unsigned long mem;
        for (mem = (*base); mem < (maxsize); mem <<= 1)) {
                if (*(unsigned long *)((unsigned long)(get_ram_size) + mem)
==
                    *(unsigned long *)(get_ram_size))
                        break;
        }
}





On Thu, Jun 25, 2009 at 8:56 PM, Detlev Zundel <dzu@denx.de> wrote:

> Hi ya,
>
> > I could not understand common/memsize.c, how it works?
>
> Like a charm ;)
>
> > maxsize / sizeof (long), what's meaning of it? why sizeof (long) is
> > dividend?
>
> As the comment in line 50 states, "cnt" is used in pointer arithmetic,
> so addr is increased in sizeof(long) bytes.  maxsize however is
> considered to be in bytes only.  Makes sense?
>
> > just like stack,  push every step mem addr to save:
> >
> > save[i++] = *addr;
> > and then?
>
> Cannot parse the question.
>
> The algorithm should be pretty clear however (take a paper and pencil
> and work out the values of addr as it proceeds) - we save the original
> content of the adressed cells and write our own pattern there (~cnt).
> Then we walk these cells upward and see where the previous write did not
> work like it was supposed to - voila.
>
> Cheers
>  Detlev
>
> --
> The continental people think life is a game. The English think
> cricket is a game.
>                                                     -- George Mikes
> --
> DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
>



-- 
--
Sincerely,

HaveF

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] hi, I could not understand the memsize.c, somebody help  me?
  2009-06-29  8:54   ` IaMaPlAyEr
@ 2009-06-29 11:54     ` Detlev Zundel
  2009-06-30  2:53       ` IaMaPlAyEr
  0 siblings, 1 reply; 10+ messages in thread
From: Detlev Zundel @ 2009-06-29 11:54 UTC (permalink / raw)
  To: u-boot

Hi,

> thanks for your reply.
> sorry for my ability of writing and understanding the code
> =D
>
> btw, How contribute my idea of this function, I means, it should be more
> ?clean or easy just like this:
>
>
> unsigned long get_ram_size(volatile long *base, long maxsize)
> {
>
> ??????? unsigned long mem;
> ??????? for (mem = (*base); mem < (maxsize); mem <<= 1)) {
> ??????????????? if (*(unsigned long *)((unsigned long)(get_ram_size) + mem) ==
> ??????????????????? *(unsigned long *)(get_ram_size))
> ??????????????????????? break;
> ??????? }
> }

This will not work at all, sorry .  Before suggesting changes which
should be "more clean or easy", at least test them on real hardware.
You will find out that this code has lots of errors.

Some hints: 

SW: What addresses is the original code accessing?  What addresses are
    you accessing?  What values do you expect there?

HW: How does the algorithm in get_ram_size work at all?  What
    transactions does it produce on the CPU busses?  What transactions
    will your code produce?  Do you know what the CPU will do if it
    accesses RAM that is not available?

Please believe me, there is definitely *quite a bit* of understanding of
hard- and software in the current code.  If you do not know what the
questions above mean, it is highly unlikely that you can improve the
code.

Best wishes
  Detlev

-- 
Thanks so much for Emacs.  What a wondrous system -- one of the real
seven wonders of the world.  Forced to choose between Emacs and, say,
any pyramid, I'd take Emacs.       -- Robert Boyer
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] hi, I could not understand the memsize.c, somebody help  me?
  2009-06-29 11:54     ` Detlev Zundel
@ 2009-06-30  2:53       ` IaMaPlAyEr
  2009-06-30 13:50         ` Detlev Zundel
  0 siblings, 1 reply; 10+ messages in thread
From: IaMaPlAyEr @ 2009-06-30  2:53 UTC (permalink / raw)
  To: u-boot

Hi

Detlev Zundel =D

Thanks for your patient explanation, I acquired a lot.

yes, you are right, I think a little about the compatibility of the code.
yes, the compatibility!

I just find in linux, arch/mips/bcm47xx/prom.c, there is a segment code just
like what I suggest above.
And move the code to my old box which bootloader is redboot, it works well.
(Of course I also tryed memsize.c)so...

I'm lucky to have my new box which bootloader is u-boot =D


thanks for your warm-hearted hints again!


On Mon, Jun 29, 2009 at 7:54 PM, Detlev Zundel <dzu@denx.de> wrote:

> Hi,
>
> > thanks for your reply.
> > sorry for my ability of writing and understanding the code
> > =D
> >
> > btw, How contribute my idea of this function, I means, it should be more
> >  clean or easy just like this:
> >
> >
> > unsigned long get_ram_size(volatile long *base, long maxsize)
> > {
> >
> >         unsigned long mem;
> >         for (mem = (*base); mem < (maxsize); mem <<= 1)) {
> >                 if (*(unsigned long *)((unsigned long)(get_ram_size) +
> mem) ==
> >                     *(unsigned long *)(get_ram_size))
> >                         break;
> >         }
> > }
>
> This will not work at all, sorry .  Before suggesting changes which
> should be "more clean or easy", at least test them on real hardware.
> You will find out that this code has lots of errors.
>
> Some hints:
>
> SW: What addresses is the original code accessing?  What addresses are
>    you accessing?  What values do you expect there?
>
> HW: How does the algorithm in get_ram_size work at all?  What
>    transactions does it produce on the CPU busses?  What transactions
>    will your code produce?  Do you know what the CPU will do if it
>    accesses RAM that is not available?
>
> Please believe me, there is definitely *quite a bit* of understanding of
> hard- and software in the current code.  If you do not know what the
> questions above mean, it is highly unlikely that you can improve the
> code.
>
> Best wishes
>  Detlev
>
> --
> Thanks so much for Emacs.  What a wondrous system -- one of the real
> seven wonders of the world.  Forced to choose between Emacs and, say,
> any pyramid, I'd take Emacs.       -- Robert Boyer
> --
> DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
>



-- 
--
Sincerely,

HaveF

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] hi, I could not understand the memsize.c, somebody help  me?
  2009-06-30  2:53       ` IaMaPlAyEr
@ 2009-06-30 13:50         ` Detlev Zundel
  0 siblings, 0 replies; 10+ messages in thread
From: Detlev Zundel @ 2009-06-30 13:50 UTC (permalink / raw)
  To: u-boot

Hi,

> Thanks for your patient explanation, I acquired a lot.

Glad if it helped.

> I just find in linux, arch/mips/bcm47xx/prom.c, there is a segment code just
> like what I suggest above.
> And move the code to my old box which bootloader is redboot, it works well. (Of
> course I also tryed memsize.c)so...

Wow, you're right.  To be honest, I do not understand the code, nor do I
know why it should work.

Already in the first pointer arithmetic "mem" is obviously interpreted
as sizeof(unsigned long) bytes and not in bytes as the constants
suggest.  Moreover they reference memory based on the address of a
function and compare it to something dereferenced immediately
afterwards - not taking "sticky values" on the bus into account.  I
don't even know why the dereferences should be similar at all as no
known values are there - at least I don't see that.

Not understanding how or why this code should work, I would not dare to
reuse it.

> I'm lucky to have my new box which bootloader is u-boot =D

Yes you are :)

Cheers
  Detlev

-- 
I talk to planets baby
                                       -- Dave Wyndorf (Monstermagnet)
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] hi, I could not understand the memsize.c, somebody help me?
  2009-06-25  3:14 [U-Boot] hi, I could not understand the memsize.c, somebody help me? IaMaPlAyEr
  2009-06-25 12:56 ` Detlev Zundel
@ 2009-07-24  6:11 ` Wolfgang Denk
  2009-07-24 14:31   ` Aggrwal Poonam-B10812
  1 sibling, 1 reply; 10+ messages in thread
From: Wolfgang Denk @ 2009-07-24  6:11 UTC (permalink / raw)
  To: u-boot

Dear IaMaPlAyEr,

In message <2ae8403e0906242014k7e37b8f0tebaffaeeaea3f6bc@mail.gmail.com> you wrote:
> 
> I could not understand common/memsize.c, how it works?

It writes markers at specific memory locations and then reads these
back. The algorithm is chosen to be fast but still to be able to
detect mirrored address ranges and other memory errors.

> maxsize / sizeof (long), what's meaning of it? why sizeof (long) is
> dividend?

Please read some boot about C programming, section pointer arithmetics.

> just like stack,  push every step mem addr to save:
> 
> save[i++] = *addr;
> and then?

The test is intended to be a non-desctructive one.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"There are three principal ways to lose money: wine, women,  and  en-
gineers.  While  the first two are more pleasant, the third is by far
the more certain."                      -- Baron Rothschild, ca. 1800

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] hi, I could not understand the memsize.c, somebody help me?
  2009-07-24  6:11 ` Wolfgang Denk
@ 2009-07-24 14:31   ` Aggrwal Poonam-B10812
  2009-07-24 15:13     ` Detlev Zundel
  2009-07-24 15:21     ` Kenneth Johansson
  0 siblings, 2 replies; 10+ messages in thread
From: Aggrwal Poonam-B10812 @ 2009-07-24 14:31 UTC (permalink / raw)
  To: u-boot

 

> -----Original Message-----
> From: u-boot-bounces at lists.denx.de 
> [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Wolfgang Denk
> Sent: Friday, July 24, 2009 11:41 AM
> To: IaMaPlAyEr
> Cc: u-boot at lists.denx.de
> Subject: Re: [U-Boot] hi, I could not understand the 
> memsize.c,somebody help me?
> 
> Dear IaMaPlAyEr,
> 
> In message 
> <2ae8403e0906242014k7e37b8f0tebaffaeeaea3f6bc@mail.gmail.com> 
> you wrote:
> > 
> > I could not understand common/memsize.c, how it works?
> 
> It writes markers at specific memory locations and then reads 
> these back. The algorithm is chosen to be fast but still to 
> be able to detect mirrored address ranges and other memory errors.
Suppose I configure MAX_MEM)SIZE as 1Gig and the actual memory on the
board is 512M, is this function supposed to return 512M?
> 
> > maxsize / sizeof (long), what's meaning of it? why sizeof (long) is 
> > dividend?
> 
> Please read some boot about C programming, section pointer 
> arithmetics.
> 
> > just like stack,  push every step mem addr to save:
> > 
> > save[i++] = *addr;
> > and then?
> 
> The test is intended to be a non-desctructive one.
> 
> Best regards,
> 
> Wolfgang Denk
> 
> -- 
> DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: 
> wd at denx.de "There are three principal ways to lose money: 
> wine, women,  and  en- gineers.  While  the first two are 
> more pleasant, the third is by far
> the more certain."                      -- Baron Rothschild, ca. 1800
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] hi, I could not understand the memsize.c, somebody help me?
  2009-07-24 14:31   ` Aggrwal Poonam-B10812
@ 2009-07-24 15:13     ` Detlev Zundel
  2009-07-24 15:21     ` Kenneth Johansson
  1 sibling, 0 replies; 10+ messages in thread
From: Detlev Zundel @ 2009-07-24 15:13 UTC (permalink / raw)
  To: u-boot

Hi Aggrwal,

>> > I could not understand common/memsize.c, how it works?
>> 
>> It writes markers at specific memory locations and then reads 
>> these back. The algorithm is chosen to be fast but still to 
>> be able to detect mirrored address ranges and other memory errors.
> Suppose I configure MAX_MEM)SIZE as 1Gig and the actual memory on the
> board is 512M, is this function supposed to return 512M?

That's the spirit, indeed.

Cheers
  Detlev

-- 
(define Y (lambda (f)
	    ((lambda (g) (f (lambda (x) ((g g) x))))
	     (lambda (g) (f (lambda (x) ((g g) x)))))))
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] hi, I could not understand the memsize.c, somebody help me?
  2009-07-24 14:31   ` Aggrwal Poonam-B10812
  2009-07-24 15:13     ` Detlev Zundel
@ 2009-07-24 15:21     ` Kenneth Johansson
  1 sibling, 0 replies; 10+ messages in thread
From: Kenneth Johansson @ 2009-07-24 15:21 UTC (permalink / raw)
  To: u-boot

On Fri, 2009-07-24 at 20:01 +0530, Aggrwal Poonam-B10812 wrote:
> > > I could not understand common/memsize.c, how it works?
> > 
> > It writes markers at specific memory locations and then reads 
> > these back. The algorithm is chosen to be fast but still to 
> > be able to detect mirrored address ranges and other memory errors.
> Suppose I configure MAX_MEM)SIZE as 1Gig and the actual memory on the
> board is 512M, is this function supposed to return 512M?

Yes in this case but if you had 384M it would have returned 256M.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-07-24 15:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-25  3:14 [U-Boot] hi, I could not understand the memsize.c, somebody help me? IaMaPlAyEr
2009-06-25 12:56 ` Detlev Zundel
2009-06-29  8:54   ` IaMaPlAyEr
2009-06-29 11:54     ` Detlev Zundel
2009-06-30  2:53       ` IaMaPlAyEr
2009-06-30 13:50         ` Detlev Zundel
2009-07-24  6:11 ` Wolfgang Denk
2009-07-24 14:31   ` Aggrwal Poonam-B10812
2009-07-24 15:13     ` Detlev Zundel
2009-07-24 15:21     ` Kenneth Johansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox