[U-Boot] [PATCH] get_ram_size: memory content of base address was not restored

Po-Yu Chuang ratbert.chuang at gmail.com
Mon Aug 9 04:25:21 CEST 2010


Dear Wolfgang,

2010/8/8 Wolfgang Denk <wd at denx.de>:
> 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


More information about the U-Boot mailing list