aboutsummaryrefslogtreecommitdiff
path: root/drivers/ddr/fsl/main.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2022-09-23 18:42:53 -0400
committerTom Rini <trini@konsulko.com>2022-09-23 18:42:53 -0400
commit694e9008674c2008b9ccdc25a9bb3ac078e20911 (patch)
tree8ab2a2636dc86ebb2ccb312512d5f402cf2b3e7e /drivers/ddr/fsl/main.c
parent4057d64fae78e1e9bf8a5a87a823f188a1339917 (diff)
parent236f73962718511e801f4ec9562075e86f737ec4 (diff)
Merge branch '2022-09-23-4gb-ddr-in-32bit-ppc' into next
To quote the author, for the first 9 patches: This patch series fixes U-Boot code to correctly handle RAM size larger than 2 GB and then fixes fsl ddr driver to do not crash U-Boot when 4 GB DDR module is detected when U-Boot operates in 32-bit mode (as opposite of the 36-bit mode). With this patch series it is possible to boot 32-bit U-Boot with 4 GB SODIMM DDR3 module without crashes. U-Boot will still use just CONFIG_MAX_MEM_MAPPED amount of RAM, but it is better than crashing due to the truncating of 4GB value to 32-bit number (which is zero). I tested this patch series on powerpc P2020 based board but only with U-Boot v2022.04 because U-Boot master branch is still broken on P2020. And then the final two patches here are (in my mind at least) related clean-ups.
Diffstat (limited to 'drivers/ddr/fsl/main.c')
-rw-r--r--drivers/ddr/fsl/main.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/drivers/ddr/fsl/main.c b/drivers/ddr/fsl/main.c
index 1903562ac4..ed3313a531 100644
--- a/drivers/ddr/fsl/main.c
+++ b/drivers/ddr/fsl/main.c
@@ -857,17 +857,32 @@ phys_size_t __fsl_ddr_sdram(fsl_ddr_info_t *pinfo)
debug("total_memory by %s = %llu\n", __func__, total_memory);
#if !defined(CONFIG_PHYS_64BIT)
- /* Check for 4G or more. Bad. */
- if ((first_ctrl == 0) && (total_memory >= (1ull << 32))) {
+ /*
+ * Show warning about big DDR moodules. But avoid warning for 4 GB DDR
+ * modules when U-Boot supports RAM of maximal size 4 GB - 1 byte.
+ */
+ if ((first_ctrl == 0) && (total_memory - 1 > (phys_size_t)~0ULL)) {
puts("Detected ");
print_size(total_memory, " of memory\n");
- printf(" This U-Boot only supports < 4G of DDR\n");
- printf(" You could rebuild it with CONFIG_PHYS_64BIT\n");
- printf(" "); /* re-align to match init_dram print */
- total_memory = CONFIG_MAX_MEM_MAPPED;
+#ifndef CONFIG_SPL_BUILD
+ puts(" "); /* re-align to match init_dram print */
+#endif
+ puts("This U-Boot only supports <= ");
+ print_size((unsigned long long)((phys_size_t)~0ULL)+1, " of DDR\n");
+#ifndef CONFIG_SPL_BUILD
+ puts(" "); /* re-align to match init_dram print */
+#endif
+ puts("You could rebuild it with CONFIG_PHYS_64BIT\n");
+#ifndef CONFIG_SPL_BUILD
+ puts(" "); /* re-align to match init_dram print */
+#endif
}
#endif
+ /* Ensure that total_memory does not overflow on return */
+ if (total_memory > (phys_size_t)~0ULL)
+ total_memory = (phys_size_t)~0ULL;
+
return total_memory;
}
@@ -941,5 +956,9 @@ fsl_ddr_sdram_size(void)
/* Compute it once normally. */
total_memory = fsl_ddr_compute(&info, STEP_GET_SPD, 1);
+ /* Ensure that total_memory does not overflow on return */
+ if (total_memory > (phys_size_t)~0ULL)
+ total_memory = (phys_size_t)~0ULL;
+
return total_memory;
}