summaryrefslogtreecommitdiffstats
path: root/commands/memtest.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-01-26 09:59:32 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-01-26 09:59:56 +0100
commit33ddaad19a253468ca5c67782b8d26bb9aadba14 (patch)
tree64dfa553efb6e87f54d3a1033022d08f956d723e /commands/memtest.c
parentec258b8bd09a2d8bc4eaff97030aa5ba1c3c3bee (diff)
downloadbarebox-33ddaad19a253468ca5c67782b8d26bb9aadba14.tar.gz
memtest: Fix SDRAM size calculations
Calculating the size and end of the test region as end = PAGE_ALIGN_DOWN(bank->res->end) - 1; size = end - start + 1; is wrong. For an example resource of start = 0x80000000, end = 0x8fffffff end results in: end = PAGE_ALIGN_DOWN(0x8fffffff) - 1 = 0x8fffefff instead of 0x8fffffff. The size is then calculated to size = end - start + 1 = 0x8fffefff - 0x80000000 + 1 = 0x0ffff000 instead of 0x10000000 The correct way to do this is to calculate the real size and apply a PAGE_ALIGN_DOWN afterwards: size = PAGE_ALIGN_DOWN(bank->res->end - start + 1) = 0x10000000 Fix this in three different places. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/memtest.c')
-rw-r--r--commands/memtest.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/commands/memtest.c b/commands/memtest.c
index d384436..379d82e 100644
--- a/commands/memtest.c
+++ b/commands/memtest.c
@@ -60,8 +60,7 @@ static int request_memtest_regions(struct list_head *list)
*/
if (list_empty(&bank->res->children)) {
start = PAGE_ALIGN(bank->res->start);
- end = PAGE_ALIGN_DOWN(bank->res->end) - 1;
- size = end - start + 1;
+ size = PAGE_ALIGN_DOWN(bank->res->end - start + 1);
ret = alloc_memtest_region(list, start, size);
if (ret < 0)
@@ -89,13 +88,13 @@ static int request_memtest_regions(struct list_head *list)
* Between used regions. Start from second entry.
*/
list_for_each_entry_from(r, &bank->res->children, sibling) {
- start = PAGE_ALIGN(r_prev->end);
- end = PAGE_ALIGN_DOWN(r->start);
+ start = PAGE_ALIGN(r_prev->end + 1);
+ end = r->start - 1;
r_prev = r;
if (start >= end)
continue;
- size = end - start;
+ size = PAGE_ALIGN_DOWN(end - start + 1);
ret = alloc_memtest_region(list, start, size);
if (ret < 0)
return ret;
@@ -107,8 +106,8 @@ static int request_memtest_regions(struct list_head *list)
r = list_last_entry(&bank->res->children,
struct resource, sibling);
start = PAGE_ALIGN(r->end);
- end = PAGE_ALIGN_DOWN(bank->res->end) - 1;
- size = end - start + 1;
+ end = bank->res->end;
+ size = PAGE_ALIGN_DOWN(end - start + 1);
if (start < end) {
ret = alloc_memtest_region(list, start, size);
if (ret < 0)