Skip to contentSkip to conversation

get_ram_size: memory content of base address was not restored

PATCH New ratbert.chuang at gmail.com 2 participants 3 messages May 25, 2010 – Aug 9, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 get_ram_size: memory content of base address was not restored

From: Po-Yu Chuang <[email protected]>

---
 common/memsize.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
common/memsize.c +1 -0
index 6c275c9..99469ab 100644
@@ -74,6 +74,7 @@ long get_ram_size(volatile long *base, long maxsize)
                return (0);
        }
 
+       *addr = save[i];
        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
                addr = base + cnt;      /* pointer arith! */
                val = *addr;

--
1.6.0.4

#1 lore raw

PATCH 1/1 get_ram_size: memory content of base address was not restored

Dear ratbert.chuang at gmail.com,

Quoted 13 lines · In message <[email protected]> you…

From: Po-Yu Chuang <[email protected]>

---
 common/memsize.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
common/memsize.c +0 -0
index 6c275c9..99469ab 100644

common/memsize.c long get_ram_size(volatile long *base, long maxsize) · line 80

Quoted 7 lines
common/memsize.c +1 -0
@@ -74,6 +74,7 @@ long get_ram_size(volatile long *base, long maxsize)
                return (0);
        }
 
+       *addr = save[i];
        for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
                addr = base + cnt;      /* pointer arith! */
                val = *addr;

I think this patch is wrong. The value at address (base + 0) is never saved, so there is no need to restore it (nor did we store it's value anywhere).

Best regards,

Wolfgang Denk

Signature · 5 lines
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
The important thing about being a leader is not being right or wrong,
but being *certain*.                    - Terry Pratchett, _Truckers_
#2 lore raw

PATCH 1/1 get_ram_size: memory content of base address was not restored

Dear Wolfgang,

2010/8/8 Wolfgang Denk <[email protected]>:

Quoted 4 lines

Dear ratbert.chuang at gmail.com,
I think this patch is wrong. The value at address (base + 0) is never saved, so there is no need to restore it (nor did we store it's value anywhere).

The value at base+0 is saved. Please see the following explanation.

long get_ram_size(volatile long *base, long maxsize)

{
	volatile long *addr;
	long           save[32];
	long           cnt;
	long           val;
	long           size;
	int            i = 0;

	for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
		addr = base + cnt;	/* pointer arith! */
		sync ();
		save[i++] = *addr;
		sync ();
		*addr = ~cnt;
	}

	addr = base;
	sync ();
	save[i] = *addr;	<----- value of [base+0] is saved.
	sync ();
	*addr = 0;		<----- [base+0] is modified.

	sync ();
	if ((val = *addr) != 0) {
		/* Restore the original data before leaving the function.
		 */
		sync ();
		*addr = save[i];		<----- value of [base+0] is restored.
		for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
			addr  = base + cnt;
			sync ();
			*addr = save[--i];
		}
		return (0);
	}

+ *addr = save[i]; <----- Therefore we should also restore [base+0] here.

	for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
		addr = base + cnt;	/* pointer arith! */
		val = *addr;
		*addr = save[--i];
		if (val != ~cnt) {
			size = cnt * sizeof (long);
			/* Restore the original data before leaving the function.
			 */
			for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
				addr  = base + cnt;
				*addr = save[--i];
			}
			return (size);
		}
	}

	return (maxsize);
}

best regards,
Po-Yu Chuang