[U-Boot] hi, I could not understand the memsize.c, somebody help me?

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

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

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@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; } }
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

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@denx.de

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

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

-----Original Message----- From: u-boot-bounces@lists.denx.de [mailto:u-boot-bounces@lists.denx.de] On Behalf Of Wolfgang Denk Sent: Friday, July 24, 2009 11:41 AM To: IaMaPlAyEr Cc: u-boot@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@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@lists.denx.de http://lists.denx.de/mailman/listinfo/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

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.
participants (5)
-
Aggrwal Poonam-B10812
-
Detlev Zundel
-
IaMaPlAyEr
-
Kenneth Johansson
-
Wolfgang Denk