From: IaMaPlAyEr Date: Mon, 29 Jun 2009 16:54:52 +0800 Subject: [U-Boot] hi, I could not understand the memsize.c, somebody help me? In-Reply-To: References: <2ae8403e0906242014k7e37b8f0tebaffaeeaea3f6bc@mail.gmail.com> Message-ID: <2ae8403e0906290154s216ea12atc5cdbe688f2cb49b@mail.gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 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