Revert "common/memsize.c: Simplify RAM size detection"
authorHans de Goede <hdegoede@redhat.com>
Tue, 9 Feb 2016 21:38:31 +0000 (22:38 +0100)
committerTom Rini <trini@konsulko.com>
Wed, 10 Feb 2016 13:34:42 +0000 (08:34 -0500)
This commit breaks bootup on sunxi boards, the get stuck
when running the main u-boot binary at:

CPU:   Allwinner H3 (SUN8I)
I2C:   ready
DRAM:

This reverts commit 8e7cba048baae68ee0916a8f52b4304277328d5e.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
common/memsize.c

index 5c0d279625a005484f055e19b8dc7183d2c4dd56..0fb9ba57b62b21d99df1fc8214c67a0016d1e63b 100644 (file)
@@ -33,28 +33,38 @@ long get_ram_size(long *base, long maxsize)
        long           size;
        int            i = 0;
 
-       for (cnt = (maxsize / sizeof(long)) >> 1; cnt >= 0; cnt >>= 1) {
+       for (cnt = (maxsize / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) {
                addr = base + cnt;      /* pointer arith! */
                sync();
-               save[i] = *addr;
+               save[i++] = *addr;
                sync();
-               if (cnt) {
-                       i++;
-                       *addr = ~cnt;
-               } else {
-                       *addr = 0;
-               }
+               *addr = ~cnt;
        }
 
+       addr = base;
+       sync();
+       save[i] = *addr;
+       sync();
+       *addr = 0;
+
        sync();
-       cnt = 0;
-       do {
+       if ((val = *addr) != 0) {
+               /* Restore the original data before leaving the function. */
+               sync();
+               *addr = save[i];
+               for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
+                       addr  = base + cnt;
+                       sync();
+                       *addr = save[--i];
+               }
+               return (0);
+       }
+
+       for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
                addr = base + cnt;      /* pointer arith! */
                val = *addr;
-               *addr = save[i--];
-               sync();
-               if (((cnt == 0) && (val != 0)) ||
-                   ((cnt != 0) && (val != ~cnt))) {
+               *addr = save[--i];
+               if (val != ~cnt) {
                        size = cnt * sizeof(long);
                        /*
                         * Restore the original data
@@ -64,16 +74,11 @@ long get_ram_size(long *base, long maxsize)
                             cnt < maxsize / sizeof(long);
                             cnt <<= 1) {
                                addr  = base + cnt;
-                               *addr = save[i--];
+                               *addr = save[--i];
                        }
                        return (size);
                }
-
-               if (cnt)
-                       cnt = cnt << 1;
-               else
-                       cnt = 1;
-       } while (cnt < maxsize / sizeof(long));
+       }
 
        return (maxsize);
 }