summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2022-09-18 14:23:27 +0300
committerTom Rini <trini@konsulko.com>2022-09-23 22:13:18 +0300
commit236f73962718511e801f4ec9562075e86f737ec4 (patch)
tree8ab2a2636dc86ebb2ccb312512d5f402cf2b3e7e /common
parentd179018e4c9561afac5ca5c8878852f1171b836b (diff)
downloadu-boot-236f73962718511e801f4ec9562075e86f737ec4.tar.xz
board_f: show_dram_config: Print also real DRAM size
32-bit U-Boot builds cannot use more than around 2 GB of DDR memory. But on some platforms/boards it is possible to connect also 4 GB SODIMM DDR memory. U-Boot currently prints only effective size of RAM which can use, which may be misleading as somebody would expect that this line prints total size of connected DDR modules. So change show_dram_config code to prints both real and effective DRAM size if they are different. If they are same then print just one number like before. It is possible that effective size is just few bytes smaller than the real size, so print both numbers only in case function print_size() prints formats them differently. Signed-off-by: Pali Rohár <pali@kernel.org>
Diffstat (limited to 'common')
-rw-r--r--common/board_f.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/common/board_f.c b/common/board_f.c
index 970c8ff67f..3df4efeeff 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -57,6 +57,7 @@
#include <asm/sections.h>
#include <dm/root.h>
#include <linux/errno.h>
+#include <linux/log2.h>
/*
* Pointer to initial global data area
@@ -216,6 +217,36 @@ static int announce_dram_init(void)
return 0;
}
+/*
+ * From input size calculate its nearest rounded unit scale (multiply of 2^10)
+ * and value in calculated unit scale multiplied by 10 (as fractional fixed
+ * point number with one decimal digit), which is human natural format,
+ * same what uses print_size() function for displaying. Mathematically it is:
+ * round_nearest(val * 2^scale) = size * 10; where: 10 <= val < 10240.
+ *
+ * For example for size=87654321 we calculate scale=20 and val=836 which means
+ * that input has natural human format 83.6 M (mega = 2^20).
+ */
+#define compute_size_scale_val(size, scale, val) do { \
+ scale = ilog2(size) / 10 * 10; \
+ val = (10 * size + ((1ULL << scale) >> 1)) >> scale; \
+ if (val == 10240) { val = 10; scale += 10; } \
+} while (0)
+
+/*
+ * Check if the sizes in their natural units written in decimal format with
+ * one fraction number are same.
+ */
+static int sizes_near(unsigned long long size1, unsigned long long size2)
+{
+ unsigned int size1_scale, size1_val, size2_scale, size2_val;
+
+ compute_size_scale_val(size1, size1_scale, size1_val);
+ compute_size_scale_val(size2, size2_scale, size2_val);
+
+ return size1_scale == size2_scale && size1_val == size2_val;
+}
+
static int show_dram_config(void)
{
unsigned long long size;
@@ -232,7 +263,11 @@ static int show_dram_config(void)
}
debug("\nDRAM: ");
- print_size(size, "");
+ print_size(gd->ram_size, "");
+ if (!sizes_near(gd->ram_size, size)) {
+ printf(" (effective ");
+ print_size(size, ")");
+ }
board_add_ram_info(0);
putc('\n');