Skip to contentSkip to conversation

arm: imx8m: imx8mm-cl-iot-gate: Add support for detect memory size

PATCH Superseded Ying-Chun Liu 3 participants 6 messages Aug 23, 2021 Arm i.MX and Layerscape

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover arm: imx8m: imx8mm-cl-iot-gate: Add support for detect memory size

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

When purchasing imx8mm-cl-iot-gate it is able to customize the memory size. It could be 1GB, 2GB and 4GB. We implement board_phys_sdram_size() to detect the memory size for usage.

This patch was trying to fix the regression on mainline U-boot for imx8mm-cl-iot-gate. However this is not related to the regression. But we should have this implemented anyway.

Ying-Chun Liu (PaulLiu) (1):
arm: imx8m: imx8mm-cl-iot-gate: Add support for detect memory size

 .../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c   | 25 +++++++++++++++++++
 include/configs/imx8mm-cl-iot-gate.h          |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/1 arm: imx8m: imx8mm-cl-iot-gate: Add support for detect memory size

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

When purchasing imx8mm-cl-iot-gate it is able to customize the memory size. It could be 1GB, 2GB and 4GB. We implement board_phys_sdram_size() to detect the memory size for usage.

Cc Fabio Estevam <[email protected]>
Cc Frieder Schrempf <[email protected]>
Cc uboot-imx <[email protected]>
---
 .../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c   | 25 +++++++++++++++++++
 include/configs/imx8mm-cl-iot-gate.h          |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +25 -0
index eabcc842a4..01c6011b75 100644
@@ -14,8 +14,33 @@
 #include <asm/arch/sys_proto.h>
 #include <asm/io.h>
 
+#include "ddr/ddr.h"
+
 DECLARE_GLOBAL_DATA_PTR;
 
+int board_phys_sdram_size(phys_size_t *size)
+{
+	struct lpddr4_tcm_desc *lpddr4_tcm_desc =
+		(struct lpddr4_tcm_desc *)TCM_DATA_CFG;
+
+	switch (lpddr4_tcm_desc->size) {
+	case 4096:
+	case 2048:
+	case 1024:
+		*size = (1L << 20) * lpddr4_tcm_desc->size;
+		break;
+	default:
+		printf("%s: DRAM size %uM is not supported\n",
+		       __func__,
+		       lpddr4_tcm_desc->size);
+		while (1)
+			;
+		break;
+	};
+
+	return 0;
+}
+
 static int setup_fec(void)
 {
 	if (IS_ENABLED(CONFIG_FEC_MXC)) {
include/configs/imx8mm-cl-iot-gate.h +1 -1
index faeee2178c..1e835563d6 100644
@@ -158,7 +158,7 @@
 
 #define CONFIG_SYS_SDRAM_BASE		0x40000000
 #define PHYS_SDRAM			0x40000000
-#define PHYS_SDRAM_SIZE			0x80000000 /* 2GB DDR */
+#define PHYS_SDRAM_SIZE			0x40000000 /* 1GB DDR */
 
 #define CONFIG_MXC_UART_BASE		UART3_BASE_ADDR
 
Signature · 1 line
2.32.0
reviewer
#2 lore raw

Hi Paul,

Thanks for taking care of this.

Quoted 7 lines · Ying-Chun Liu
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +7 -0
+int board_phys_sdram_size(phys_size_t *size)
+{
+       struct lpddr4_tcm_desc *lpddr4_tcm_desc =
+               (struct lpddr4_tcm_desc *)TCM_DATA_CFG;
+
+       switch (lpddr4_tcm_desc->size) {
+       case 4096:

board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c line 37

Quoted 10 lines
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +10 -0
+       case 2048:
+       case 1024:
+               *size = (1L << 20) * lpddr4_tcm_desc->size;
+               break;
+       default:
+               printf("%s: DRAM size %uM is not supported\n",
+                      __func__,
+                      lpddr4_tcm_desc->size);
+               while (1)
+                       ;

Shouldn't the while(1) be replaced by hang() instead?

include/configs/imx8mm-cl-iot-gate.h line 161

Quoted 4 lines

#define CONFIG_SYS_SDRAM_BASE 0x40000000
#define PHYS_SDRAM 0x40000000

include/configs/imx8mm-cl-iot-gate.h +1 -1
-#define PHYS_SDRAM_SIZE                        0x80000000 /* 2GB DDR */
+#define PHYS_SDRAM_SIZE                        0x40000000 /* 1GB DDR */

This looks like an unnecessary change for me, as the board size is detected in run-time.

#3 lore raw
In reply to Ying-Chun Liu

Hi Paul

Quoted 37 lines · Ying-Chun Liu

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

When purchasing imx8mm-cl-iot-gate it is able to customize the memory size. It could be 1GB, 2GB and 4GB. We implement board_phys_sdram_size() to detect the memory size for usage.

Cc Fabio Estevam <[email protected]>
Cc Frieder Schrempf <[email protected]>
Cc uboot-imx <[email protected]>

---
 .../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c   | 25 +++++++++++++++++++ include/configs/imx8mm-cl-iot-gate.h          |  2 +-

 2 files changed, 26 insertions(+), 1 deletion(-)
board/compulab/imx8mm-cl-iot-gate/imx8mm- renamed from board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +0 -0

cl-iot-gate.c
index eabcc842a4..01c6011b75 100644

board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +0 -0
@@ -14,8 +14,33 @@
  #include <asm/arch/sys_proto.h>
  #include <asm/io.h>

board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +2 -0
+#include "ddr/ddr.h"
+

 DECLARE_GLOBAL_DATA_PTR;

board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +9 -0
+int board_phys_sdram_size(phys_size_t *size)
+{
+       struct lpddr4_tcm_desc *lpddr4_tcm_desc =
+               (struct lpddr4_tcm_desc *)TCM_DATA_CFG;
+
+       switch (lpddr4_tcm_desc->size) {
+       case 4096:
+       case 2048:
+       case 1024:

board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c line 39

Quoted 10 lines
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +10 -0
+               *size = (1L << 20) * lpddr4_tcm_desc->size;
+               break;
+       default:
+               printf("%s: DRAM size %uM is not supported\n",
+                      __func__,
+                      lpddr4_tcm_desc->size);
+               while (1)
+                       ;
+               break;
+       };

Why not simply using generic get_ram_size() as we e.g. did here [1]?

Quoted 15 lines
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +4 -0
+
+       return 0;
+}
+

 static int setup_fec(void)
 {
        if (IS_ENABLED(CONFIG_FEC_MXC)) {

include/configs/imx8mm-cl-iot-gate.h +0 -0
index faeee2178c..1e835563d6 100644
@@ -158,7 +158,7 @@


 #define CONFIG_SYS_SDRAM_BASE          0x40000000 #define PHYS_SDRAM                     0x40000000

include/configs/imx8mm-cl-iot-gate.h line 161

Quoted 2 lines
include/configs/imx8mm-cl-iot-gate.h +1 -1
-#define PHYS_SDRAM_SIZE                        0x80000000 /* 2GB DDR */
+#define PHYS_SDRAM_SIZE                        0x40000000 /* 1GB DDR */

In our implementation we use PHYS_SDRAM_SIZE as the upper limit which get_ram_size() then actually tests for.

Quoted 1 line

 #define CONFIG_MXC_UART_BASE           UART3_BASE_ADDR

[1] https://marc.info/?l=u-boot&m=160387919927218

Cheers

Marcel

author
#4 lore raw

Hi Marcel,

Thanks for the comment.
But isn't it more straightforward to use TCM data?
I mean it is already tested when DRAM initializes.
Also there's already a commit that avoids U-boot using address more than 4GB on imx8m platform for some reasons I don't know in detail but the commit is e27bddff .
Because the base is 0x40000000. So 4GB address means it is about 3G left. But the largest memory we can purchase is 4GB. Which is already beyond the limit.
And I don't have Compluab 4GB boards.
So I think we should avoid directly testing the address more than 4GB addr? We just report the correct memory size here based on the DRAM init test. And restrict the memory usage by board_get_usable_ram_top() by previous commit.

The Compulab board is using various memory chips. They only let you to choose the size, not the company/brand. So the dram init code actually test every brand of the chips at beginning (SPL) so we have the correct brand and size stored in TCM area. I have 5 Compulab boards on my hand. All of them are 2GB ram but different brand. But it is still not covered all the combinations I think.

So, can we keep using the TCM data rather than do the actual testing?

Yours,
Paul

Quoted 84 lines · Marcel Ziswiler

Hi Paul

Quoted 10 lines · Ying-Chun Liu

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

When purchasing imx8mm-cl-iot-gate it is able to customize the memory size. It could be 1GB, 2GB and 4GB. We implement board_phys_sdram_size() to detect the memory size for usage.

Cc Fabio Estevam <[email protected]>
Cc Frieder Schrempf <[email protected]>
Cc uboot-imx <[email protected]>

Review

Quoted 6 lines
---
 .../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c   | 25 +++++++++++++++++++
 include/configs/imx8mm-cl-iot-gate.h          |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/board/compulab/imx8mm-cl-iot-gate/imx8mm-

Quoted 21 lines

cl-iot-gate.c
index eabcc842a4..01c6011b75 100644

board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +11 -0
@@ -14,8 +14,33 @@
 #include <asm/arch/sys_proto.h>
 #include <asm/io.h>
 
+#include "ddr/ddr.h"
+
 DECLARE_GLOBAL_DATA_PTR;
 
+int board_phys_sdram_size(phys_size_t *size)
+{
+       struct lpddr4_tcm_desc *lpddr4_tcm_desc =
+               (struct lpddr4_tcm_desc *)TCM_DATA_CFG;
+
+       switch (lpddr4_tcm_desc->size) {
+       case 4096:
+       case 2048:
+       case 1024:

board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c line 39

Quoted 10 lines
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +10 -0
+               *size = (1L << 20) * lpddr4_tcm_desc->size;
+               break;
+       default:
+               printf("%s: DRAM size %uM is not supported\n",
+                      __func__,
+                      lpddr4_tcm_desc->size);
+               while (1)
+                       ;
+               break;
+       };

Why not simply using generic get_ram_size() as we e.g. did here [1]?

Review

Quoted 8 lines
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +4 -0
+
+       return 0;
+}
+
 static int setup_fec(void)
 {
        if (IS_ENABLED(CONFIG_FEC_MXC)) {
(quoted diff) +0 -0

b/include/configs/imx8mm-cl-iot-gate.h

include/configs/imx8mm-cl-iot-gate.h line 161

Quoted 9 lines

index faeee2178c..1e835563d6 100644

include/configs/imx8mm-cl-iot-gate.h +1 -1
@@ -158,7 +158,7 @@
 
 #define CONFIG_SYS_SDRAM_BASE          0x40000000
 #define PHYS_SDRAM                     0x40000000
-#define PHYS_SDRAM_SIZE                        0x80000000 /* 2GB DDR */
+#define PHYS_SDRAM_SIZE                        0x40000000 /* 1GB DDR */

In our implementation we use PHYS_SDRAM_SIZE as the upper limit which get_ram_size() then actually tests for.

include/configs/imx8mm-cl-iot-gate.h line 163

Quoted 1 line
include/configs/imx8mm-cl-iot-gate.h +0 -0
 #define CONFIG_MXC_UART_BASE           UART3_BASE_ADDR

[1] https://marc.info/?l=u-boot&m=160387919927218

Cheers

Marcel

#5 lore raw

Hi Paul

Quoted 4 lines · PaulLiu

Hi Marcel,

Thanks for the comment.
But isn't it more straightforward to use TCM data?

It was not quite clear to me what you were talking about. So I had a quick look at CompuLab's implementation of all this. Let us hope it works fine but I would not exactly call this straightforward.

Quoted 3 lines

I mean it is already tested when DRAM initializes.
Also there's already a commit that avoids U-boot using address more than 4GB on imx8m platform for some reasons I don't know in detail but the commit is e27bddff .

I don't think any of this would be needed if everybody would agree on using the generic get_ram_size() routine. The world could be so much simpler!

Quoted 3 lines

Because the base is 0x40000000. So 4GB address means it is about 3G left. But the largest memory we can purchase is 4GB. Which is already beyond the limit. And I don't have Compluab 4GB boards.

Yeah, I remember from the i.MX 8M Plus this actually requires 64-bit addressing to really work.

Quoted 1 line

So I think we should avoid directly testing the address more than 4GB addr?

Well, in the 32-bit world there is nothing beyond those 4GB (;-p).

Quoted 2 lines

We just report the correct memory size here based on the DRAM init test. And restrict the memory usage by board_get_usable_ram_top() by previous commit.

To be honest, I really think this is done totally the wrong way around, but then as it is not my board I won't stand in anybody's way...

Quoted 4 lines

The Compulab board is using various memory chips. They only let you to choose the size, not the company/brand. So the dram init code actually test every brand of the chips at beginning (SPL) so we have the correct brand and size stored in TCM area. I have 5 Compulab boards on my hand. All of them are 2GB ram but different brand. But it is still not covered all the combinations I think.

Yes, I saw that. Considering that NXP was unable to provide anything halfway generic this looks OKish.

Quoted 1 line

So, can we keep using the TCM data rather than do the actual testing?

Sure, as stated above, I won't stay in your way. Just thought it worth pitching a more generic way of going about RAM sizing.

Quoted 2 lines

Yours,
Paul

Cheers

Marcel

Quoted 83 lines · Marcel Ziswiler
Quoted 82 lines

Hi Paul

board/compulab/imx8mm-cl-iot-

Quoted 16 lines · Ying-Chun Liu

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

When purchasing imx8mm-cl-iot-gate it is able to customize the memory size. It could be 1GB, 2GB and 4GB. We implement board_phys_sdram_size() to detect the memory size for usage.

Cc Fabio Estevam <[email protected]>
Cc Frieder Schrempf <[email protected]>
Cc uboot-imx <[email protected]>

---
 .../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c   | 25 +++++++++++++++++++ include/configs/imx8mm-cl-iot-gate.h          |  2 +-

 2 files changed, 26 insertions(+), 1 deletion(-)
board/compulab/imx8mm-cl-iot- renamed from board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +0 -0

gate/imx8mm-

Quoted 21 lines

cl-iot-gate.c
index eabcc842a4..01c6011b75 100644

board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +0 -0
@@ -14,8 +14,33 @@
  #include <asm/arch/sys_proto.h>
  #include <asm/io.h>

board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +2 -0
+#include "ddr/ddr.h"
+

 DECLARE_GLOBAL_DATA_PTR;

board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +9 -0
+int board_phys_sdram_size(phys_size_t *size)
+{
+       struct lpddr4_tcm_desc *lpddr4_tcm_desc =
+               (struct lpddr4_tcm_desc *)TCM_DATA_CFG;
+
+       switch (lpddr4_tcm_desc->size) {
+       case 4096:
+       case 2048:
+       case 1024:

board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c line 39

Quoted 10 lines
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +10 -0
+               *size = (1L << 20) * lpddr4_tcm_desc->size;
+               break;
+       default:
+               printf("%s: DRAM size %uM is not supported\n",
+                      __func__,
+                      lpddr4_tcm_desc->size);
+               while (1)
+                       ;
+               break;
+       };

Why not simply using generic get_ram_size() as we e.g. did here [1]?

Quoted 15 lines
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +4 -0
+
+       return 0;
+}
+

 static int setup_fec(void)
 {
        if (IS_ENABLED(CONFIG_FEC_MXC)) {

include/configs/imx8mm-cl-iot-gate.h +0 -0
index faeee2178c..1e835563d6 100644
@@ -158,7 +158,7 @@


 #define CONFIG_SYS_SDRAM_BASE          0x40000000 #define PHYS_SDRAM                     0x40000000

include/configs/imx8mm-cl-iot-gate.h line 161

Quoted 2 lines
include/configs/imx8mm-cl-iot-gate.h +1 -1
-#define PHYS_SDRAM_SIZE                        0x80000000 /* 2GB DDR */
+#define PHYS_SDRAM_SIZE                        0x40000000 /* 1GB DDR */

In our implementation we use PHYS_SDRAM_SIZE as the upper limit which get_ram_size() then actually tests for.

Quoted 1 line

 #define CONFIG_MXC_UART_BASE           UART3_BASE_ADDR

[1] https://marc.info/?l=u-boot&m=160387919927218

Cheers

Marcel