Support for 4 GB DDR modules for 32-bit U-Boot builds
Subsystems (15)
PATCH 1/9 common/memsize.c: Fix get_effective_memsize() to always check for CONFIG_MAX_MEM_MAPPED
In reply to Pali RohárCONFIG_MAX_MEM_MAPPED when defined specifies upper memory mapped limit. So check for it always, and not only when CONFIG_VERY_BIG_RAM is defined.
--- common/memsize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/memsize.c +1 -1
@@ -94,7 +94,7 @@ long get_ram_size(long *base, long maxsize)phys_size_t __weak get_effective_memsize (void ) { -#ifndef CONFIG_VERY_BIG_RAM +#ifndef CONFIG_MAX_MEM_MAPPED return gd->ram_size;#else /* limit stack to what we can reasonable map */
Signature · 1 line
2.20.1
cover Support for 4 GB DDR modules for 32-bit U-Boot builds
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.
Pali Rohár (9):
common/memsize.c: Fix get_effective_memsize() to always check for
CONFIG_MAX_MEM_MAPPED
common/memsize.c: Fix get_effective_memsize() to check for overflow
board_f: Fix types for board_get_usable_ram_top()
board_f: Fix printing gd->ram_size and gd->ram_top
ddr: fsl: Fix checking for maximal mappable memory
ddr: fsl: Fix fsl_ddr_sdram_size() for 4GB modules with 32-bit
phys_size_t
ddr: fsl: Allow to detect 4 GB DDR modules in 32-bit mode
ddr: fsl: Fix re-align of verbose DRAM information for non-SPL builds powerpc/mpc85xx: Explain TLB unmapped memory message
arch/arm/mach-imx/imx8m/soc.c | 2 +- arch/arm/mach-mvebu/arm64-common.c | 2 +- arch/arm/mach-rockchip/sdram.c | 2 +- arch/arm/mach-stm32mp/dram_init.c | 2 +- arch/arm/mach-sunxi/board.c | 2 +- arch/arm/mach-tegra/board2.c | 2 +- arch/mips/mach-jz47xx/jz4780/jz4780.c | 2 +- arch/mips/mach-octeon/dram.c | 2 +- arch/powerpc/cpu/mpc85xx/tlb.c | 2 +- arch/riscv/cpu/fu540/dram.c | 2 +- arch/riscv/cpu/fu740/dram.c | 2 +- arch/riscv/cpu/generic/dram.c | 2 +- arch/x86/cpu/broadwell/sdram.c | 2 +- arch/x86/cpu/coreboot/sdram.c | 2 +- arch/x86/cpu/efi/payload.c | 2 +- arch/x86/cpu/efi/sdram.c | 2 +- arch/x86/cpu/intel_common/mrc.c | 4 ++-- arch/x86/cpu/ivybridge/sdram.c | 2 +- arch/x86/cpu/qemu/dram.c | 2 +- arch/x86/cpu/quark/dram.c | 2 +- arch/x86/cpu/slimbootloader/sdram.c | 2 +- arch/x86/cpu/tangier/sdram.c | 2 +- arch/x86/include/asm/mrc_common.h | 2 +- arch/x86/include/asm/u-boot-x86.h | 2 +- arch/x86/lib/fsp1/fsp_dram.c | 2 +- arch/x86/lib/fsp2/fsp_dram.c | 2 +- board/broadcom/bcmns3/ns3.c | 2 +- board/imgtec/boston/ddr.c | 2 +- board/menlo/m53menlo/m53menlo.c | 2 +- board/raspberrypi/rpi/rpi.c | 2 +- board/ti/am65x/evm.c | 2 +- board/ti/j721e/evm.c | 2 +- board/ti/j721s2/evm.c | 2 +- board/xilinx/zynqmp/zynqmp.c | 2 +- common/board_f.c | 6 ++--- common/memsize.c | 20 ++++++++++++---- drivers/ddr/fsl/lc_common_dimm_params.c | 3 +++ drivers/ddr/fsl/main.c | 31 ++++++++++++++++++++----- drivers/video/fsl_dcu_fb.c | 2 +- include/init.h | 2 +- 40 files changed, 84 insertions(+), 50 deletions(-)
Signature · 1 line
2.20.1
PATCH 2/9 common/memsize.c: Fix get_effective_memsize() to check for overflow
Ensure that top of RAM can be represented by phys_size_t type. If RAM is too large or RAM base address is too upper then limit RAM size to prevent address space overflow.
--- common/memsize.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
common/memsize.c +15 -3
@@ -94,11 +94,23 @@ long get_ram_size(long *base, long maxsize)phys_size_t __weak get_effective_memsize (void ) { +phys_size_t ram_size = gd->ram_size; + +/* +* Check for overflow and limit ram size to some representable value. +* It is required that ram_base + ram_size must be representable by +* phys_size_t type and must be aligned by direct access, therefore +* calculate it from last 4kB sector which should work as alignment +* on any platform. +*/ +if (gd->ram_base + ram_size < gd->ram_base) + ram_size = ((phys_size_t )~0xfffULL ) - gd->ram_base; +#ifndef CONFIG_MAX_MEM_MAPPED -return gd->ram_size; +return ram_size;#else /* limit stack to what we can reasonable map */ -return ((gd->ram_size >CONFIG_MAX_MEM_MAPPED ) ? -CONFIG_MAX_MEM_MAPPED : gd->ram_size); +return ((ram_size >CONFIG_MAX_MEM_MAPPED ) ? +CONFIG_MAX_MEM_MAPPED : ram_size);#endif }
Signature · 1 line
2.20.1
PATCH 6/9 ddr: fsl: Fix fsl_ddr_sdram_size() for 4GB modules with 32-bit phys_size_t
In reply to Pali RohárFunction fsl_ddr_compute() always return size in unsigned long long type, but function fsl_ddr_sdram_size() returns size in phys_size_t type.
When 36-bit addressing mode is not enabled then phys_size_t type is only 32-bit and thus it cannot store value 4GB (0x100000000). Function fsl_ddr_sdram_size() in this case returns truncated value 0x0.
Fix this issue by returning the highest representable value, which is 0xffffffff (4GB - 1 byte).
This change fixes crashing of proper U-Boot because it detected 4 GB module as RAM with zero size.
--- drivers/ddr/fsl/main.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/ddr/fsl/main.c +4 -0
@@ -949,5 +949,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; }
Signature · 1 line
2.20.1
PATCH 5/9 ddr: fsl: Fix checking for maximal mappable memory
In reply to Pali RohárCheck needs to be done against CONFIG_MAX_MEM_MAPPED macro and not fixed size 4GB (as CONFIG_MAX_MEM_MAPPED can be lower and for example for e500 cores it is just 2GB). Also fix printf re-align, which should be applied only for non-SPL builds, during init_dram() call.
--- drivers/ddr/fsl/main.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/ddr/fsl/main.c +14 -5
@@ -856,13 +856,22 @@ 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 ))) { +/* Check for more than max memory. Bad. */ +if ((first_ctrl ==0 ) && (total_memory >CONFIG_MAX_MEM_MAPPED )) {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 */ +#ifndef CONFIG_SPL_BUILD +puts (" " );/* re-align to match init_dram print */ +#endif +puts ("This U-Boot only supports <= " ); +print_size (CONFIG_MAX_MEM_MAPPED ," 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 total_memory =CONFIG_MAX_MEM_MAPPED ; }#endif
Signature · 1 line
2.20.1
PATCH 4/9 board_f: Fix printing gd->ram_size and gd->ram_top
In reply to Pali RohárMembers gd->ram_size and gd->ram_top are of type phys_addr_t which does not have to fit into ulong type. So cast them into unsigned long long.
--- common/board_f.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common/board_f.c +2 -2
@@ -325,7 +325,7 @@ static int setup_dest_addr(void)/* * Ram is setup, size stored in gd !! */ -debug ("Ram size: %08lX\n" , (ulong )gd->ram_size); +debug ("Ram size: %08llX\n" , (unsigned long long )gd->ram_size);#if defined(CONFIG_SYS_MEM_TOP_HIDE )/* * Subtract specified amount of memory to hide so that it won't
@@ -345,7 +345,7 @@ static int setup_dest_addr(void) gd->ram_top = gd->ram_base +get_effective_memsize (); gd->ram_top =board_get_usable_ram_top (gd->mon_len); gd->relocaddr = gd->ram_top; -debug ("Ram top: %08lX\n" , (ulong )gd->ram_top); +debug ("Ram top: %08llX\n" , (unsigned long long )gd->ram_top);#if defined(CONFIG_MP ) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500 ))/* * We need to make sure the location we intend to put secondary core
Signature · 1 line
2.20.1
PATCH 9/9 powerpc/mpc85xx: Explain TLB unmapped memory message
In reply to Pali RohárCurrently U-Boot SPL prints just generic message "2 GiB left unmapped". Change it to more detailed "2 GiB of DDR memory left unmapped in U-Boot". This is just U-Boot configuration and operating system may map more (or also less) memory.
--- arch/powerpc/cpu/mpc85xx/tlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/cpu/mpc85xx/tlb.c +1 -1
@@ -311,7 +311,7 @@ unsigned int setup_ddr_tlbs_phys(phys_addr_t p_addr,if (size || memsize >CONFIG_MAX_MEM_MAPPED ) {print_size (memsize >CONFIG_MAX_MEM_MAPPED ? memsize -CONFIG_MAX_MEM_MAPPED + size : size, -" left unmapped\n" ); +" of DDR memory left unmapped in U-Boot\n" ); }return memsize_in_meg;
Signature · 1 line
2.20.1
PATCH 8/9 ddr: fsl: Fix re-align of verbose DRAM information for non-SPL builds
In reply to Pali RohárDuring init_dram() is called also compute_lowest_common_dimm_parameters() function which prints multi-line detailed output. So print also re-aligning filler after "Detected ?DIMM" line to have "DRAM: " output aligned.
--- drivers/ddr/fsl/lc_common_dimm_params.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/ddr/fsl/lc_common_dimm_params.c +3 -0
@@ -422,6 +422,9 @@ compute_lowest_common_dimm_parameters(const unsigned int ctrl_num, dimm_params[i].mpart);#endif } +#ifndef CONFIG_SPL_BUILD +puts (" " ); +#endif } }
Signature · 1 line
2.20.1
PATCH 7/9 ddr: fsl: Allow to detect 4 GB DDR modules in 32-bit mode
In reply to Pali RohárU-Boot core code already handles the case when RAM size is bigger than CONFIG_MAX_MEM_MAPPED. So there is no need to do duplicate check in fsl ddr driver for CONFIG_MAX_MEM_MAPPED. Instead simplify code to just check if RAM size can be representable in phys_size_t type. And avoid printing warning if phys_size_t is just 1 byte smaller than RAM size, which is the typical situation with 4 GB DDR module.
--- drivers/ddr/fsl/main.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/ddr/fsl/main.c +10 -4
@@ -856,15 +856,18 @@ 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 more than max memory. Bad. */ -if ((first_ctrl ==0 ) && (total_memory >CONFIG_MAX_MEM_MAPPED )) { +/* +* 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" );#ifndef CONFIG_SPL_BUILD puts (" " );/* re-align to match init_dram print */ #endif puts ("This U-Boot only supports <= " ); -print_size (CONFIG_MAX_MEM_MAPPED ," of DDR\n" ); +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
@@ -872,10 +875,13 @@ phys_size_t __fsl_ddr_sdram(fsl_ddr_info_t *pinfo)#ifndef CONFIG_SPL_BUILD puts (" " );/* re-align to match init_dram print */ #endif - total_memory = CONFIG_MAX_MEM_MAPPED; }#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; }
Signature · 1 line
2.20.1
PATCH 3/9 board_f: Fix types for board_get_usable_ram_top()
In reply to Pali RohárCommit 37dc958947ed ("global_data.h: Change ram_top type to phys_addr_t") changed type of ram_top member from ulong to phys_addr_t but did not changed types in board_get_usable_ram_top() function which returns value for ram_top.
So change ulong to phys_addr_t type also in board_get_usable_ram_top() signature and implementations.
--- arch/arm/mach-imx/imx8m/soc.c | 2 +- arch/arm/mach-mvebu/arm64-common.c | 2 +- arch/arm/mach-rockchip/sdram.c | 2 +- arch/arm/mach-stm32mp/dram_init.c | 2 +- arch/arm/mach-sunxi/board.c | 2 +- arch/arm/mach-tegra/board2.c | 2 +- arch/mips/mach-jz47xx/jz4780/jz4780.c | 2 +- arch/mips/mach-octeon/dram.c | 2 +- arch/riscv/cpu/fu540/dram.c | 2 +- arch/riscv/cpu/fu740/dram.c | 2 +- arch/riscv/cpu/generic/dram.c | 2 +- arch/x86/cpu/broadwell/sdram.c | 2 +- arch/x86/cpu/coreboot/sdram.c | 2 +- arch/x86/cpu/efi/payload.c | 2 +- arch/x86/cpu/efi/sdram.c | 2 +- arch/x86/cpu/intel_common/mrc.c | 4 ++-- arch/x86/cpu/ivybridge/sdram.c | 2 +- arch/x86/cpu/qemu/dram.c | 2 +- arch/x86/cpu/quark/dram.c | 2 +- arch/x86/cpu/slimbootloader/sdram.c | 2 +- arch/x86/cpu/tangier/sdram.c | 2 +- arch/x86/include/asm/mrc_common.h | 2 +- arch/x86/include/asm/u-boot-x86.h | 2 +- arch/x86/lib/fsp1/fsp_dram.c | 2 +- arch/x86/lib/fsp2/fsp_dram.c | 2 +- board/broadcom/bcmns3/ns3.c | 2 +- board/imgtec/boston/ddr.c | 2 +- board/menlo/m53menlo/m53menlo.c | 2 +- board/raspberrypi/rpi/rpi.c | 2 +- board/ti/am65x/evm.c | 2 +- board/ti/j721e/evm.c | 2 +- board/ti/j721s2/evm.c | 2 +- board/xilinx/zynqmp/zynqmp.c | 2 +- common/board_f.c | 2 +- drivers/video/fsl_dcu_fb.c | 2 +- include/init.h | 2 +- 36 files changed, 37 insertions(+), 37 deletions(-)
arch/arm/mach-imx/imx8m/soc.c +1 -1
@@ -309,7 +309,7 @@ phys_size_t get_effective_memsize(void)#endif } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {ulong top_addr =PHYS_SDRAM + gd->ram_size;
arch/arm/mach-mvebu/arm64-common.c +1 -1
@@ -30,7 +30,7 @@ DECLARE_GLOBAL_DATA_PTR;*/ #define USABLE_RAM_SIZE 0x80000000 -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {if (gd->ram_size >USABLE_RAM_SIZE )return USABLE_RAM_SIZE ;
arch/arm/mach-rockchip/sdram.c +1 -1
@@ -205,7 +205,7 @@ int dram_init(void)return 0 ; } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {unsigned long top =CONFIG_SYS_SDRAM_BASE +SDRAM_MAX_SIZE ;
arch/arm/mach-stm32mp/dram_init.c +1 -1
@@ -40,7 +40,7 @@ int dram_init(void)return 0 ; } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {phys_size_t size;phys_addr_t reg;
arch/arm/mach-sunxi/board.c +1 -1
@@ -65,7 +65,7 @@ static struct mm_region sunxi_mem_map[] = { };struct mm_region *mem_map = sunxi_mem_map; -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {/* Some devices (like the EMAC) have a 32-bit DMA limit. */ if (gd->ram_top > (1ULL <<32 ))
arch/arm/mach-tegra/board2.c +1 -1
@@ -401,7 +401,7 @@ int dram_init_banksize(void)* This function is called before dram_init_banksize(), so we can't simply * return gd->bd->bi_dram[1].start + gd->bd->bi_dram[1].size. */ -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {ulong ram_top;
arch/mips/mach-jz47xx/jz4780/jz4780.c +1 -1
@@ -76,7 +76,7 @@ void board_init_f(ulong dummy) }#endif /* CONFIG_SPL_BUILD */ -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {return CONFIG_SYS_SDRAM_BASE + (256 *1024 *1024 ); }
arch/mips/mach-octeon/dram.c +1 -1
@@ -77,7 +77,7 @@ phys_size_t get_effective_memsize(void)return UBOOT_RAM_SIZE_MAX ; } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {if (IS_ENABLED (CONFIG_RAM_OCTEON )) {/* Map a maximum of 256MiB - return not size but address */
arch/riscv/cpu/fu540/dram.c +1 -1
@@ -21,7 +21,7 @@ int dram_init_banksize(void)return fdtdec_setup_memory_banksize (); } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {/* * Ensure that we run from first 4GB so that all
arch/riscv/cpu/fu740/dram.c +1 -1
@@ -20,7 +20,7 @@ int dram_init_banksize(void)return fdtdec_setup_memory_banksize (); } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {#ifdef CONFIG_64BIT /*
arch/riscv/cpu/generic/dram.c +1 -1
@@ -21,7 +21,7 @@ int dram_init_banksize(void)return fdtdec_setup_memory_banksize (); } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {/* * Ensure that we run from first 4GB so that all
arch/x86/cpu/broadwell/sdram.c +1 -1
@@ -25,7 +25,7 @@#include <asm/arch/pei_data.h> #include <asm/arch/pm.h> -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {return mrc_common_board_get_usable_ram_top (total_size); }
arch/x86/cpu/coreboot/sdram.c +1 -1
@@ -27,7 +27,7 @@ unsigned int install_e820_map(unsigned int max_entries,* address, and how far U-Boot is moved by relocation are set in the global * data structure. */ -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {uintptr_t dest_addr =0 ;int i;
arch/x86/cpu/efi/payload.c +1 -1
@@ -27,7 +27,7 @@ DECLARE_GLOBAL_DATA_PTR;* the relocation address, and how far U-Boot is moved by relocation are * set in the global data structure. */ -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {struct efi_mem_desc *desc, *end;struct efi_entry_memmap *map;
arch/x86/cpu/efi/sdram.c +1 -1
@@ -11,7 +11,7 @@DECLARE_GLOBAL_DATA_PTR ; -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {return (ulong )efi_get_ram_base () + gd->ram_size; }
arch/x86/cpu/intel_common/mrc.c +2 -2
@@ -25,7 +25,7 @@ static const char *const ecc_decoder[] = { "active" }; -ulong mrc_common_board_get_usable_ram_top (ulong total_size) +phys_size_t mrc_common_board_get_usable_ram_top (phys_size_t total_size) {struct memory_info *info = &gd->arch.meminfo;uintptr_t dest_addr =0 ;
@@ -50,7 +50,7 @@ ulong mrc_common_board_get_usable_ram_top(ulong total_size) dest_addr = largest->start + largest->size; -return (ulong )dest_addr; +return (phys_size_t )dest_addr; }void mrc_common_dram_init_banksize (void )
arch/x86/cpu/ivybridge/sdram.c +1 -1
@@ -44,7 +44,7 @@ DECLARE_GLOBAL_DATA_PTR;#define CMOS_OFFSET_MRC_SEED_S3 156#define CMOS_OFFSET_MRC_SEED_CHK 160 -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {return mrc_common_board_get_usable_ram_top (total_size); }
arch/x86/cpu/qemu/dram.c +1 -1
@@ -71,7 +71,7 @@ int dram_init_banksize(void)* the relocation address, and how far U-Boot is moved by relocation are * set in the global data structure. */ -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {return qemu_get_low_memory_size (); }
arch/x86/cpu/quark/dram.c +1 -1
@@ -184,7 +184,7 @@ int dram_init_banksize(void)* the relocation address, and how far U-Boot is moved by relocation are * set in the global data structure. */ -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {return gd->ram_size; }
arch/x86/cpu/slimbootloader/sdram.c +1 -1
@@ -48,7 +48,7 @@ static struct sbl_memory_map_info *get_memory_map_info(void)* @total_size: The memory size that u-boot occupies * Return: : The top available memory address lower than 4GB */ -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {struct sbl_memory_map_info *data;int i;
arch/x86/cpu/tangier/sdram.c +1 -1
@@ -204,7 +204,7 @@ unsigned int install_e820_map(unsigned int max_entries,* address, and how far U-Boot is moved by relocation are set in the global * data structure. */ -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {struct sfi_table_simple *sb;struct sfi_mem_entry *mentry;
arch/x86/include/asm/mrc_common.h +1 -1
@@ -47,7 +47,7 @@ int mrc_add_memory_area(struct memory_info *info, uint64_t start,* the relocation address, and how far U-Boot is moved by relocation are * set in the global data structure. */ -ulong mrc_common_board_get_usable_ram_top (ulong total_size); +phys_size_t mrc_common_board_get_usable_ram_top (phys_size_t total_size);void mrc_common_dram_init_banksize (void );
arch/x86/include/asm/u-boot-x86.h +1 -1
@@ -77,7 +77,7 @@ int x86_cleanup_before_linux(void);void x86_enable_caches (void );void x86_disable_caches (void );int x86_init_cache (void ); -ulong board_get_usable_ram_top (ulong total_size); +phys_size_t board_get_usable_ram_top (phys_size_t total_size);int default_print_cpuinfo (void );/* Set up a UART which can be used with printch(), printhex8(), etc. */
arch/x86/lib/fsp1/fsp_dram.c +1 -1
@@ -34,7 +34,7 @@ int dram_init(void)* the relocation address, and how far U-Boot is moved by relocation are * set in the global data structure. */ -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {return fsp_get_usable_lowmem_top (gd->arch.hob_list); }
arch/x86/lib/fsp2/fsp_dram.c +1 -1
@@ -77,7 +77,7 @@ int dram_init(void)return 0 ; } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {if (!ll_boot_init ())return gd->ram_size;
board/broadcom/bcmns3/ns3.c +1 -1
@@ -183,7 +183,7 @@ int dram_init_banksize(void) }/* Limit RAM used by U-Boot to the DDR first bank End region */ -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {return BCM_NS3_MEM_END ; }
board/imgtec/boston/ddr.c +1 -1
@@ -23,7 +23,7 @@ int dram_init(void)return 0 ; } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {DECLARE_GLOBAL_DATA_PTR ;
board/menlo/m53menlo/m53menlo.c +1 -1
@@ -42,7 +42,7 @@ DECLARE_GLOBAL_DATA_PTR;static u32 mx53_dram_size[2 ]; -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {/* * WARNING: We must override get_effective_memsize() function here
board/raspberrypi/rpi/rpi.c +1 -1
@@ -335,7 +335,7 @@ static void set_fdt_addr(void)/* * Prevent relocation from stomping on a firmware provided FDT blob. */ -unsigned long board_get_usable_ram_top (unsigned long total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {if ((gd->ram_top - fw_dtb_pointer) >SZ_64M )return gd->ram_top;
board/ti/am65x/evm.c +1 -1
@@ -61,7 +61,7 @@ int dram_init(void)return 0 ; } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {#ifdef CONFIG_PHYS_64BIT /* Limit RAM used by U-Boot to the DDR low region */
board/ti/j721e/evm.c +1 -1
@@ -57,7 +57,7 @@ int dram_init(void)return 0 ; } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {#ifdef CONFIG_PHYS_64BIT /* Limit RAM used by U-Boot to the DDR low region */
board/ti/j721s2/evm.c +1 -1
@@ -46,7 +46,7 @@ int dram_init(void)return 0 ; } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {#ifdef CONFIG_PHYS_64BIT /* Limit RAM used by U-Boot to the DDR low region */
board/xilinx/zynqmp/zynqmp.c +1 -1
@@ -511,7 +511,7 @@ int dram_init(void)return 0 ; } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {phys_size_t size;phys_addr_t reg;
common/board_f.c +1 -1
@@ -302,7 +302,7 @@ __weak int mach_cpu_init(void) }/* Get the top of usable RAM */ -__weak ulong board_get_usable_ram_top (ulong total_size) +__weak phys_size_t board_get_usable_ram_top (phys_size_t total_size) {#if defined(CONFIG_SYS_SDRAM_BASE ) &&CONFIG_SYS_SDRAM_BASE >0 /*
drivers/video/fsl_dcu_fb.c +1 -1
@@ -372,7 +372,7 @@ int fsl_dcu_init(struct fb_info *fbinfo, unsigned int xres,return 0 ; } -ulong board_get_usable_ram_top (ulong total_size) +phys_size_t board_get_usable_ram_top (phys_size_t total_size) {return gd->ram_top -CONFIG_VIDEO_FSL_DCU_MAX_FB_SIZE_MB ; }
include/init.h +1 -1
@@ -290,7 +290,7 @@ int show_board_info(void);* * @param total_size Size of U-Boot (unused?) */ -ulong board_get_usable_ram_top (ulong total_size); +phys_size_t board_get_usable_ram_top (phys_size_t total_size);int board_early_init_f (void );
Signature · 1 line
2.20.1
Re: [PATCH 4/9] board_f: Fix printing gd->ram_size and gd->ram_top
In reply to Pali RohárHi Pali,
Quoted 3 lines · Pali Rohár
Members
gd->ram_sizeandgd->ram_topare of typephys_addr_twhich does not have to fit into ulong type. So cast them into unsigned long long.
Which board does this break?
Quoted 30 lines
Fixes 37dc958947ed ("global_data.h: Change ram_top type to phys_addr_t")Signed-off-by Pali Rohár <[email protected]>--- common/board_f.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)common/board_f.c +2
-3@@ -325,7 +325,7 @@ static int setup_dest_addr(void)/* * Ram is setup, size stored in gd !! */ -debug ("Ram size: %08lX\n" , (ulong )gd->ram_size); +debug ("Ram size: %08llX\n" , (unsigned long long )gd->ram_size);#if defined(CONFIG_SYS_MEM_TOP_HIDE )/* * Subtract specified amount of memory to hide so that it won't @@ -345,7 +345,7 @@ static int setup_dest_addr(void) gd->ram_top = gd->ram_base +get_effective_memsize (); gd->ram_top =board_get_usable_ram_top (gd->mon_len); gd->relocaddr = gd->ram_top; -debug ("Ram top: %08lX\n" , (ulong )gd->ram_top); +debug ("Ram top: %08llX\n" , (unsigned long long )gd->ram_top);#if defined(CONFIG_MP ) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500 ))/* * We need to make sure the location we intend to put secondary core --
Quoted 2 lines
2.20.1
This seems OK, as it still only shows 8 digits in most cases.
Re: [PATCH 3/9] board_f: Fix types for board_get_usable_ram_top()
In reply to Pali RohárQuoted 20 lines · Pali Rohár
Commit
37dc958947ed("global_data.h: Changeram_toptype tophys_addr_t") changed type ofram_topmember from ulong tophys_addr_tbut did not changed types inboard_get_usable_ram_top()function which returns value forram_top.So change ulong to
phys_addr_ttype also inboard_get_usable_ram_top()signature and implementations.Fixes 37dc958947ed ("global_data.h: Change ram_top type to phys_addr_t")Signed-off-by Pali Rohár <[email protected]>--- arch/arm/mach-imx/imx8m/soc.c | 2 +- arch/arm/mach-mvebu/arm64-common.c | 2 +- arch/arm/mach-rockchip/sdram.c | 2 +- arch/arm/mach-stm32mp/dram_init.c | 2 +- arch/arm/mach-sunxi/board.c | 2 +- arch/arm/mach-tegra/board2.c | 2 +- arch/mips/mach-jz47xx/jz4780/jz4780.c | 2 +- arch/mips/mach-octeon/dram.c | 2 +-
Quoted 8 lines
arch/riscv/cpu/fu540/dram.c | 2 +- arch/riscv/cpu/fu740/dram.c | 2 +- arch/riscv/cpu/generic/dram.c | 2 +- arch/x86/cpu/broadwell/sdram.c | 2 +- arch/x86/cpu/coreboot/sdram.c | 2 +- arch/x86/cpu/efi/payload.c | 2 +- arch/x86/cpu/efi/sdram.c | 2 +- arch/x86/cpu/intel_common/mrc.c | 4 ++--
Re: [PATCH 8/9] ddr: fsl: Fix re-align of verbose DRAM information for non-SPL builds
In reply to Pali RohárHi,
Quoted 9 lines · Pali Rohár
During
init_dram()is called alsocompute_lowest_common_dimm_parameters()function which prints multi-line detailed output. So print also re-aligning filler after "Detected ?DIMM" line to have "DRAM: " output aligned.Signed-off-by Pali Rohár <[email protected]>--- drivers/ddr/fsl/lc_common_dimm_params.c | 3 +++ 1 file changed, 3 insertions(+)
At some point could this move to drivers/ram ?
Regards,
Simon
Re: [PATCH 8/9] ddr: fsl: Fix re-align of verbose DRAM information for non-SPL builds
Quoted 8 lines · Simon Glass
Hi,
Quoted 5 lines · Pali Rohár
During
init_dram()is called alsocompute_lowest_common_dimm_parameters()function which prints multi-line detailed output. So print also re-aligning filler after "Detected ?DIMM" line to have "DRAM: " output aligned.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Pali Rohár <[email protected]>--- drivers/ddr/fsl/lc_common_dimm_params.c | 3 +++ 1 file changed, 3 insertions(+)At some point could this move to
drivers/ram?
Depends on if we're keeping / making drivers/ram mean uses uclass and drivers/ddr does not, I think.
Signature · 1 line
Tom
Re: [PATCH 8/9] ddr: fsl: Fix re-align of verbose DRAM information for non-SPL builds
Hi Tom,
Quoted 15 lines · Tom Rini
Quoted 13 lines · Simon Glass
Hi,
Quoted 9 lines · Pali Rohár
During
init_dram()is called alsocompute_lowest_common_dimm_parameters()function which prints multi-line detailed output. So print also re-aligning filler after "Detected ?DIMM" line to have "DRAM: " output aligned.Signed-off-by Pali Rohár <[email protected]>--- drivers/ddr/fsl/lc_common_dimm_params.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 4 lines
Quoted 1 line
At some point could this move to
drivers/ram?Depends on if we're keeping / making
drivers/rammean uses uclass anddrivers/ddrdoes not, I think.
Yes, except for Altera:
$ git grep UCLASS_RAM drivers/ddr drivers/ddr/altera/sdram_gen5.c: .id = UCLASS_RAM, drivers/ddr/altera/sdram_soc64.c: .id = UCLASS_RAM,
Regards,
Simon
Re: [PATCH 8/9] ddr: fsl: Fix re-align of verbose DRAM information for non-SPL builds
Quoted 20 lines · Simon Glass
Hi Tom,
Quoted 17 lines · Tom Rini
Quoted 14 lines · Simon Glass
Hi,
Quoted 9 lines · Pali Rohár
During
init_dram()is called alsocompute_lowest_common_dimm_parameters()function which prints multi-line detailed output. So print also re-aligning filler after "Detected ?DIMM" line to have "DRAM: " output aligned.Signed-off-by Pali Rohár <[email protected]>--- drivers/ddr/fsl/lc_common_dimm_params.c | 3 +++ 1 file changed, 3 insertions(+)At some point could this move to
drivers/ram?
Quoted 8 lines
Quoted 2 lines
Depends on if we're keeping / making
drivers/rammean uses uclass anddrivers/ddrdoes not, I think.Yes, except for Altera:
$ git grep UCLASS_RAM drivers/ddr drivers/ddr/altera/sdram_gen5.c: .id = UCLASS_RAM, drivers/ddr/altera/sdram_soc64.c: .id = UCLASS_RAM,
Then we should move those over to drivers/ram/altera/ and leave the rest as-is. And of course, totally outside the scope of this series.
Signature · 1 line
Tom
Re: [PATCH 4/9] board_f: Fix printing gd->ram_size and gd->ram_top
In reply to Simon GlassQuoted 8 lines · On Friday 09 September 2022 12:20:57 Simon Glass wrote:
Hi Pali,
Quoted 3 lines · Pali Rohár
Members
gd->ram_sizeandgd->ram_topare of typephys_addr_twhich does not have to fit into ulong type. So cast them into unsigned long long.Which board does this break?
Uff.. I'm not sure right now as I have this patch for months. Anyway, looking at it I think the issue is with 36-bit powerpc stuff where phys_addr_t is 64-bit, ulong is 32-bit and therefore ram_size can be up to 64 GB. Of course addressable RAM maximally 4 GB. Anyway, there should not be any break, this is just debug output.
Quoted 35 lines
Quoted 30 lines
Fixes 37dc958947ed ("global_data.h: Change ram_top type to phys_addr_t")Signed-off-by Pali Rohár <[email protected]>--- common/board_f.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)common/board_f.c +2
-3@@ -325,7 +325,7 @@ static int setup_dest_addr(void)/* * Ram is setup, size stored in gd !! */ -debug ("Ram size: %08lX\n" , (ulong )gd->ram_size); +debug ("Ram size: %08llX\n" , (unsigned long long )gd->ram_size);#if defined(CONFIG_SYS_MEM_TOP_HIDE )/* * Subtract specified amount of memory to hide so that it won't @@ -345,7 +345,7 @@ static int setup_dest_addr(void) gd->ram_top = gd->ram_base +get_effective_memsize (); gd->ram_top =board_get_usable_ram_top (gd->mon_len); gd->relocaddr = gd->ram_top; -debug ("Ram top: %08lX\n" , (ulong )gd->ram_top); +debug ("Ram top: %08llX\n" , (unsigned long long )gd->ram_top);#if defined(CONFIG_MP ) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500 ))/* * We need to make sure the location we intend to put secondary core -- Quoted 2 lines
2.20.1
Reviewed-by Simon Glass <[email protected]>
Quoted 1 line
This seems OK, as it still only shows 8 digits in most cases.
No? IIRC %08 prints at least 8 digits (not at most).
[PATCH 10/9] powerpc/mpc85xx: Fix re-align of unmapped DDR memory message for non-SPL builds
In reply to Pali RohárDuring init_dram() is called also setup_ddr_tlbs_phys() function which may print message about unmapped DDR memory. So in this case print also re-aligning filler after unmapped DDR memory message.
--- arch/powerpc/cpu/mpc85xx/tlb.c | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/cpu/mpc85xx/tlb.c +3 -0
@@ -312,6 +312,9 @@ unsigned int setup_ddr_tlbs_phys(phys_addr_t p_addr,print_size (memsize >CONFIG_MAX_MEM_MAPPED ? memsize -CONFIG_MAX_MEM_MAPPED + size : size," of DDR memory left unmapped in U-Boot\n" ); +#ifndef CONFIG_SPL_BUILD +puts (" " ); +#endif }return memsize_in_meg;
Signature · 1 line
2.20.1
Re: [PATCH 4/9] board_f: Fix printing gd->ram_size and gd->ram_top
In reply to Pali RohárHi Pali,
Quoted 9 lines · Pali Rohár
Quoted 7 lines · On Friday 09 September 2022 12:20:57 Simon Glass wrote:
Hi Pali,
Quoted 3 lines · Pali Rohár
Members
gd->ram_sizeandgd->ram_topare of typephys_addr_twhich does not have to fit into ulong type. So cast them into unsigned long long.
Quoted 7 lines
Quoted 1 line
Which board does this break?
Uff.. I'm not sure right now as I have this patch for months. Anyway, looking at it I think the issue is with 36-bit powerpc stuff where
phys_addr_tis 64-bit, ulong is 32-bit and thereforeram_sizecan be up to 64 GB. Of course addressable RAM maximally 4 GB. Anyway, there should not be any break, this is just debug output.
OK
Quoted 36 lines
Quoted 36 lines
Quoted 31 lines
Fixes 37dc958947ed ("global_data.h: Change ram_top type to phys_addr_t")Signed-off-by Pali Rohár <[email protected]>--- common/board_f.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)common/board_f.c +2
-3@@ -325,7 +325,7 @@ static int setup_dest_addr(void)/* * Ram is setup, size stored in gd !! */ -debug ("Ram size: %08lX\n" , (ulong )gd->ram_size); +debug ("Ram size: %08llX\n" , (unsigned long long )gd->ram_size);#if defined(CONFIG_SYS_MEM_TOP_HIDE )/* * Subtract specified amount of memory to hide so that it won't @@ -345,7 +345,7 @@ static int setup_dest_addr(void) gd->ram_top = gd->ram_base +get_effective_memsize (); gd->ram_top =board_get_usable_ram_top (gd->mon_len); gd->relocaddr = gd->ram_top; -debug ("Ram top: %08lX\n" , (ulong )gd->ram_top); +debug ("Ram top: %08llX\n" , (unsigned long long )gd->ram_top);#if defined(CONFIG_MP ) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500 ))/* * We need to make sure the location we intend to put secondary core -- Quoted 2 lines
2.20.1
Reviewed-by Simon Glass <[email protected]>
Quoted 3 lines
Quoted 1 line
This seems OK, as it still only shows 8 digits in most cases.
No? IIRC %08 prints at least 8 digits (not at most).
Yes we are saying the same thing. It is %016x that I would object to.
Regards,
Simon
Re: [PATCH 1/9] common/memsize.c: Fix get_effective_memsize() to always check for CONFIG_MAX_MEM_MAPPED
In reply to Pali RohárQuoted 4 lines · Pali Rohár
CONFIG_MAX_MEM_MAPPEDwhen defined specifies upper memory mapped limit. So check for it always, and not only whenCONFIG_VERY_BIG_RAMis defined.Signed-off-by Pali Rohár <[email protected]>
For the series, applied to u-boot/next, thanks!
Signature · 1 line
Tom