blob: d59d25fd92fe858f2435cc698e79242c4e56348b [file] [log] [blame]
David Hendricks560c6432014-02-13 13:07:50 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <inttypes.h>
21#include <lib.h>
22#include <console/console.h>
23
24int primitive_memtest(uintptr_t base, uintptr_t size)
25{
26 uintptr_t *p;
27 uintptr_t i;
28 int bad = 0;
29
30 printk(BIOS_SPEW, "Performing primitive memory test.\n");
31 printk(BIOS_SPEW, "DRAM start: 0x%08x, DRAM size: 0x%08x", base, size);
32 for(i = base; i < base + (size - 1) - sizeof(p); i += sizeof(p)) {
33 if (i % 0x100000 == 0) {
34 if ((i % 0x800000) == 0)
35 printk(BIOS_SPEW, "\n");
36 else if (i != 0)
37 printk(BIOS_SPEW, " ");
38 printk(BIOS_SPEW, "0x%08x", i);
39 }
40 p = (uintptr_t *)i;
41 *p = i;
42 }
43
44 printk(BIOS_SPEW, "\n\nReading back DRAM content");
45 for(i = base; i < base + (size - 1) - sizeof(p); i += sizeof(p)) {
46 if (i % 0x100000 == 0) {
47 if ((i % 0x800000) == 0)
48 printk(BIOS_SPEW, "\n");
49 else if (i != 0)
50 printk(BIOS_SPEW, " ");
51 printk(BIOS_SPEW, "0x%08x", i);
52 }
53
54 p = (uintptr_t *)i;
55 if (*p != i) {
56 printk(BIOS_SPEW, "\n0x%08zx: got 0x%zx\n", i, *p);
57 bad++;
58 }
59 }
60
61 printk(BIOS_SPEW, "\n");
62 printk(BIOS_SPEW, "%d errors\n", bad);
63
64 return bad;
65}