Skip to contentSkip to conversation

memsize.c patch

U-Boot-Users Sangmoon Kim 2 participants 5 messages Apr 2, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

When get_ram_size(common/memsize.c) is called on a MPC8245 board which has 256MB SDRAM, booting stops.
This is because the function tries to read outside BAT boundary. This patch fixes the problem.
I tested it on our board(board/etin/debris).

Regards,
Sangmoon Kim
-------------- next part --------------
A non-text attachment was scrubbed...
Name: memsize.patch
Type: application/octet-stream
Size: 523 bytes
Desc: not available
Url : http://lists.denx.de/pipermail/u-boot/attachments/20040402/835c33a4/attachment.obj

#1 lore raw
Quoted 4 lines · In message <000c01c41868$34814910$212d4cdc@smkim> you wrote:

When get_ram_size(common/memsize.c) is called on a MPC8245 board which has 256MB SDRAM, booting stops.
This is because the function tries to read outside BAT boundary.

This is intentional. You can only find out how much mempory is installed when you test beyound the end - otrherwise there might be more memory, right? You must map more memory, then.

Quoted 2 lines

This patch fixes the problem.
I tested it on our board(board/etin/debris).

But it breaks many other boards.

Review

Quoted 9 lines
(quoted diff) +4 -3
 	for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
 		addr = base + cnt;	/* pointer arith! */
-		val = *addr;
-		*addr = save[--i];
-		if (val != ~cnt) {
+		if (addr < maxsize) {
+			val = *addr;
+			*addr = save[--i];
+		}

Just a simple question: what happens if base != 0 ?

Rejected.

Wolfgang Denk

Signature · 3 lines
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd at denx.de
An armed society is a polite society.
#2 lore raw

Hi,

Quoted 5 lines

This is intentional. You can only find out how much mempory is installed when you test beyound the end - otrherwise there might be more memory, right? You must map more memory, then.

I know this is intentional.
But in case of MPC8245 which has 4 DBATs.
We need one DBAT for DCACHE, one for PCI and one for Flash. Then there is only one DBAT left for SDRAM.
The maximum size of DBAT is 256M bytes.
So the maximum capacity of SDRAM that u-boot can handle is 256M bytes. Now if the CFG_MAX_RAM_SIZE is set to 256M and 256M SDRAM is installed, the get_ram_size routine tries to read some value at (base + 0x10000000) which is outside of block address translation.
Then the board hangs.
The patch fixes the problem.

Quoted 3 lines

Just a simple question: what happens if base != 0 ?

I forgot that.
Then how about this.

for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
addr = base + cnt; /* pointer arith! */

-               val = *addr;
-               *addr = save[--i];
-               if (val != ~cnt) {
+               if (addr < (base + maxsize)) {

+ val = *addr;
+ *addr = save[--i];
+ }
+ if ((val != ~cnt) || (addr >= base + maxsize)) {

Regards,
Sangmoon Kim

#3 lore raw

Hi,
You are right.
Sorry for the wrong arguing.
Actually I was debugging my code(board/etin/debris/debrs.c) from old version of u-boot.
Because I found some problem of my initdram.
After I fixed the problem I found that u-boot gets to use the simular code. And asumed that u-boot has the same problem.
The difference was this.

My code : for (cnt = 1; cnt <= CFG_MAX_RAM_SIZE / sizeof(long); cnt <<= 1) u-boot : for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1)

Isn't it fun?

Regards,
Sangmoon Kim

----- Original Message -----
From: "Sangmoon Kim" <[email protected]>
To: "Wolfgang Denk" <[email protected]>
Cc: <[email protected]>
Sent: Friday, April 02, 2004 6:25 PM
Subject: Re: [U-Boot-Users] memsize.c patch

Quoted 53 lines

Hi,

Quoted 5 lines

This is intentional. You can only find out how much mempory is installed when you test beyound the end - otrherwise there might be more memory, right? You must map more memory, then.

I know this is intentional.
But in case of MPC8245 which has 4 DBATs.
We need one DBAT for DCACHE, one for PCI and one for Flash. Then there is only one DBAT left for SDRAM.
The maximum size of DBAT is 256M bytes.
So the maximum capacity of SDRAM that u-boot can handle is 256M bytes. Now if the CFG_MAX_RAM_SIZE is set to 256M and 256M SDRAM is installed, the get_ram_size routine tries to read some value at (base + 0x10000000) which is outside of block address translation.
Then the board hangs.
The patch fixes the problem.

Quoted 3 lines

Just a simple question: what happens if base != 0 ?

I forgot that.
Then how about this.

for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
addr = base + cnt; /* pointer arith! */

(quoted diff) +5 -3
-               val = *addr;
-               *addr = save[--i];
-               if (val != ~cnt) {
+               if (addr < (base + maxsize)) {
+                       val = *addr;
+                       *addr = save[--i];
+               }
+               if ((val != ~cnt) || (addr >= base + maxsize)) {

Regards,
Sangmoon Kim

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
U-Boot-Users mailing list
U-Boot-Users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users

#4 lore raw
In reply to Sangmoon Kim
Quoted 2 lines · In message <001201c41894$7f766af0$212d4cdc@smkim> you wrote:

The patch fixes the problem.

This patch breaks the logic on all other boards.

Best regards,

Wolfgang Denk

Signature · 4 lines
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd at denx.de
You've no idea of what a poor opinion  I  have  of  myself,  and  how
little I deserve it.                                  - W. S. Gilbert