u-boot-brain/arch/arm
Siarhei Siamashka c3d2b963c6 sunxi: Fix buggy sun6i/sun8i DRAM size detection logic
After reboot, reset or even short power off, DRAM typically retains
the old stale data for some period of time (for this type of memory,
the bits of data are stored in slowly discharging capacitors).

The current sun6i/sun8i DRAM size detection logic, which is
inherited from the Allwinner code, relies on using a large magic
signature with the hope that it is unique enough and unlikely to
ever accidentally match this leftover garbage data in RAM. But
this approach is inherently unsafe, as can be demonstrated using
the following test program:

/***** A testcase for reproducing the problem ******/

void main(int argc, char *argv[])
{
    size_t size, i;
    uint32_t *buf;
    /* Allocate the buffer */
    if (argc < 2 || !(size = (size_t)atoi(argv[1]) * 1048576) ||
                    !(buf = malloc(size))) {
        printf("Need buffer size in MiB as a cmdline argument\n");
        exit(1);
    }
    /* Fill it with the Allwinner DRAM "magic" values */
    for (i = 0; i < size / 4; i++)
        buf[i] = 0xaa55aa55 + ((uintptr_t)&buf[i] / 4) % 64;
    /* Try to reboot */
    system("reboot");
    /* And wait */
    for (;;) {}
}
/***************************************************/

If this test program is run on the device (giving it a large
chunk of memory), then the DRAM size detection logic in u-boot
gets confused after reboot and fails to initialize DRAM properly.

A better approach is not to rely on luck and abstain from making
any assumptions about the properties of the leftover garbage
data in RAM. Instead just use a more reliable code for testing
whether two different addresses refer to the same memory location.

Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2015-01-14 14:56:37 +01:00
..
cpu sunxi: Fix buggy sun6i/sun8i DRAM size detection logic 2015-01-14 14:56:37 +01:00
dts Merge branch 'master' of git://git.denx.de/u-boot-spi 2015-01-08 13:50:38 -05:00
imx-common imx: i2c: Zap unnecessary malloc() calls 2014-12-30 14:05:48 +01:00
include sunxi: Fix buggy sun6i/sun8i DRAM size detection logic 2015-01-14 14:56:37 +01:00
lib arm: build arch memset/memcpy in Thumb2 mode 2015-01-09 10:20:22 -05:00
mvebu-common arm: kirkwood: Change naming of dram functions from km_foo() to mvebu_foo() 2014-10-23 09:59:21 -04:00
config.mk arm: build arch memset/memcpy in Thumb2 mode 2015-01-09 10:20:22 -05:00
Kconfig ARM: UniPhier: select CONFIG_SPL 2014-12-18 23:34:27 +09:00
Kconfig.debug arm: debug: add Kconfig entries for lowlevel debug 2014-10-26 22:23:12 +01:00
Makefile Kbuild: introduce Makefile in arch/$ARCH/ 2014-12-08 09:35:45 -05:00