From 4d5c75a54ef4a5efed5b51918e94c38f12cf1a0a Mon Sep 17 00:00:00 2001
From: Hauke Mehrtens <hauke@hauke-m.de>
Date: Sun, 30 Sep 2012 11:42:16 +0000
Subject: [PATCH] improve the check for the memory size

This will hopefully fix bug #9360 and #9097 in trunk.

SVN-Revision: 33596
---
 ...CM47XX-improve-memory-size-detection.patch | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 target/linux/brcm47xx/patches-3.3/192-MIPS-BCM47XX-improve-memory-size-detection.patch

diff --git a/target/linux/brcm47xx/patches-3.3/192-MIPS-BCM47XX-improve-memory-size-detection.patch b/target/linux/brcm47xx/patches-3.3/192-MIPS-BCM47XX-improve-memory-size-detection.patch
new file mode 100644
index 0000000000..548178c29e
--- /dev/null
+++ b/target/linux/brcm47xx/patches-3.3/192-MIPS-BCM47XX-improve-memory-size-detection.patch
@@ -0,0 +1,42 @@
+--- a/arch/mips/bcm47xx/prom.c
++++ b/arch/mips/bcm47xx/prom.c
+@@ -1,6 +1,7 @@
+ /*
+  *  Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
+  *  Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net>
++ *  Copyright (C) 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
+  *
+  *  This program is free software; you can redistribute  it and/or modify it
+  *  under  the terms of  the GNU General  Public License as published by the
+@@ -60,6 +61,7 @@ static __init void prom_init_mem(void)
+ {
+ 	unsigned long mem;
+ 	unsigned long max;
++	unsigned long off, data, off1, data1;
+ 	struct cpuinfo_mips *c = &current_cpu_data;
+ 
+ 	/* Figure out memory size by finding aliases.
+@@ -77,15 +79,19 @@ static __init void prom_init_mem(void)
+ 	 * max contains the biggest possible address supported by the platform.
+ 	 * If the method wants to try something above we assume 128MB ram.
+ 	 */
+-	max = ((unsigned long)(prom_init) | ((128 << 20) - 1));
++	off = (unsigned long)prom_init;
++	data = *(unsigned long *)prom_init;
++	off1 = off + 4;
++	data1 = *(unsigned long *)off1;
++	max = off | ((128 << 20) - 1);
+ 	for (mem = (1 << 20); mem < (128 << 20); mem += (1 << 20)) {
+-		if (((unsigned long)(prom_init) + mem) > max) {
++		if ((off + mem) > max) {
+ 			mem = (128 << 20);
+ 			printk(KERN_DEBUG "assume 128MB RAM\n");
+ 			break;
+ 		}
+-		if (*(unsigned long *)((unsigned long)(prom_init) + mem) ==
+-		    *(unsigned long *)(prom_init))
++		if ((*(unsigned long *)(off + mem) == data) &&
++			(*(unsigned long *)(off1 + mem) == data1))
+ 			break;
+ 	}
+ 
-- 
2.30.2