Dear Wolfgang,

2010/8/8 Wolfgang Denk <[email protected]>:
> Dear [email protected],
> 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
_______________________________________________
U-Boot mailing list
[email protected]
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to