Allow booting a 32-bit system with a top memory address beyond 4 GiB
Subsystems (7)
cover Allow booting a 32-bit system with a top memory address beyond 4 GiB
When testing QEMU RISC-V 'virt' machine with a 2 GiB memory configuration, it was discovered gd->ram_top is assigned to value zero in setup_dest_addr().
While 2 GiB QEMU RISC-V 'virt' happens to work with U-Boot today, increasing more memory doesn't make a bootable system. There are various places in U-Boot that prevents such from working.
While this is seen and tested on RISC-V, it's not RISC-V centric, but a generic issue that may affect all architectures.
Bin Meng (7):
riscv: Adjust board_get_usable_ram_top() for 32-bit global_data.h: Change ram_top type to phys_addr_t
serial: sifive: Cast dev_read_addr() with uintptr_t
fdtdec: Cast prior_stage_fdt_address with uintptr_t
riscv: Change phys_addr_t and phys_size_t to 64-bit
bdinfo: Rename function names to be clearer
bdinfo: Change to use bdinfo_print_num_ll() where the number could be
64-bit
arch/arm/lib/bdinfo.c | 16 +++++----- arch/m68k/lib/bdinfo.c | 2 +- arch/powerpc/lib/bdinfo.c | 4 +-- arch/riscv/cpu/fu540/dram.c | 7 ++--- arch/riscv/cpu/generic/dram.c | 7 ++--- arch/riscv/include/asm/types.h | 4 +-- cmd/bdinfo.c | 52 +++++++++++++++---------------- drivers/serial/serial_sifive.c | 2 +- include/asm-generic/global_data.h | 2 +- include/init.h | 3 +- lib/fdtdec.c | 2 +- 11 files changed, 50 insertions(+), 51 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/7 riscv: Adjust board_get_usable_ram_top() for 32-bit
From: Bin Meng <[email protected]>
When testing QEMU RISC-V 'virt' machine with a 2 GiB memory configuration, it was discovered gd->ram_top is assigned to value zero in setup_dest_addr().
While gd->ram_top should not be declared as type unsigned long, which will be updated in a future patch, the current logic in board_get_usable_ram_top() can be updated to cover both 64-bit and 32-bit RISC-V.
---
arch/riscv/cpu/fu540/dram.c | 7 +++---- arch/riscv/cpu/generic/dram.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-)
arch/riscv/cpu/fu540/dram.c +3 -4
@@ -22,7 +22,6 @@ int dram_init_banksize(void)ulong board_get_usable_ram_top (ulong total_size) { -#ifdef CONFIG_64BIT /* * Ensure that we run from first 4GB so that all * addresses used by U-Boot are 32bit addresses.
@@ -31,8 +30,8 @@ ulong board_get_usable_ram_top(ulong total_size)* devices work fine because DMA mapping APIs will * provide 32bit DMA addresses only. */ -if (gd->ram_top >SZ_4G ) -return SZ_4G ; -#endif +if (gd->ram_top >=SZ_4G ) +return SZ_4G -1 ; +return gd->ram_top; }
arch/riscv/cpu/generic/dram.c +3 -4
@@ -22,7 +22,6 @@ int dram_init_banksize(void)ulong board_get_usable_ram_top (ulong total_size) { -#ifdef CONFIG_64BIT /* * Ensure that we run from first 4GB so that all * addresses used by U-Boot are 32bit addresses.
@@ -31,8 +30,8 @@ ulong board_get_usable_ram_top(ulong total_size)* devices work fine because DMA mapping APIs will * provide 32bit DMA addresses only. */ -if (gd->ram_top >SZ_4G ) -return SZ_4G ; -#endif +if (gd->ram_top >=SZ_4G ) +return SZ_4G -1 ; +return gd->ram_top; }
Signature · 1 line
2.25.1
PATCH 2/7 global_data.h: Change ram_top type to phys_addr_t
In reply to Bin MengFrom: Bin Meng <[email protected]>
It's possible to have ram_top above 4 GiB in a 32-bit system, hence we need to declare ram_top as phys_addr_t.
---
include/asm-generic/global_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/global_data.h +1 -1
@@ -147,7 +147,7 @@ struct global_data {/** * @ram_top: top address of RAM used by U-Boot */ -unsigned long ram_top; +phys_addr_t ram_top;/** * @relocaddr: start address of U-Boot in RAM *
Signature · 1 line
2.25.1
PATCH 2/7 global_data.h: Change ram_top type to phys_addr_t
Quoted 11 lines · Bin Meng
From: Bin Meng <[email protected]>
It's possible to have
ram_topabove 4 GiB in a 32-bit system, hence we need to declareram_topasphys_addr_t.Signed-off-by Bin Meng <[email protected]>---
include/asm-generic/global_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 2/7 global_data.h: Change ram_top type to phys_addr_t
Hi Bin,
Quoted 8 lines · Simon Glass
Quoted 6 lines · Bin Meng
From: Bin Meng <[email protected]>
It's possible to have
ram_topabove 4 GiB in a 32-bit system, hence we need to declareram_topasphys_addr_t.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Bin Meng <[email protected]>---
include/asm-generic/global_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>
This patch causes build warnings...can you please take a look?
https://gitlab.denx.de/u-boot/custodians/u-boot-dm/-/jobs/213226
Regards,
Simon
PATCH 2/7 global_data.h: Change ram_top type to phys_addr_t
Hi Simon,
Quoted 15 lines · Simon Glass
Hi Bin,
Quoted 11 lines · Simon Glass
Quoted 9 lines · Bin Meng
From: Bin Meng <[email protected]>
It's possible to have
ram_topabove 4 GiB in a 32-bit system, hence we need to declareram_topasphys_addr_t.Signed-off-by Bin Meng <[email protected]>---
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
include/asm-generic/global_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>This patch causes build warnings...can you please take a look?
https://gitlab.denx.de/u-boot/custodians/u-boot-dm/-/jobs/213226
That's strange. I did run Azure before I posted this series, and Azure did not report any failure.
See https://dev.azure.com/bmeng/GitHub/_build/results?buildId=307&view=results
Did you apply all patches in this series?
Regards,
Bin
PATCH 2/7 global_data.h: Change ram_top type to phys_addr_t
Hi Bin,
Quoted 26 lines · Bin Meng
Hi Simon,
Quoted 22 lines · Simon Glass
Hi Bin,
Quoted 8 lines · Simon Glass
Quoted 6 lines · Bin Meng
From: Bin Meng <[email protected]>
It's possible to have
ram_topabove 4 GiB in a 32-bit system, hence we need to declareram_topasphys_addr_t.Quoted 7 lines
Quoted 5 lines
Signed-off-by Bin Meng <[email protected]>---
include/asm-generic/global_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>This patch causes build warnings...can you please take a look?
Quoted 8 lines
That's strange. I did run Azure before I posted this series, and Azure did not report any failure.
See https://dev.azure.com/bmeng/GitHub/_build/results?buildId=307&view=results
Did you apply all patches in this series?
At that link you can see the commit I built...I don't know how to see the list of previous commits in the web interface but I suppose you could fetch it and look.
Re the warning, it is there... see here:
https://dev.azure.com/bmeng/f9017223-94f4-4916-a888-4cac5e17223f/_apis/build/builds/307/logs/603
Regards,
Simon
PATCH 2/7 global_data.h: Change ram_top type to phys_addr_t
Hi Simon,
Quoted 39 lines · Simon Glass
Hi Bin,
Quoted 26 lines · Bin Meng
Hi Simon,
Quoted 22 lines · Simon Glass
Hi Bin,
Quoted 8 lines · Simon Glass
Quoted 6 lines · Bin Meng
From: Bin Meng <[email protected]>
It's possible to have
ram_topabove 4 GiB in a 32-bit system, hence we need to declareram_topasphys_addr_t.Quoted 7 lines
Quoted 5 lines
Signed-off-by Bin Meng <[email protected]>---
include/asm-generic/global_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>This patch causes build warnings...can you please take a look?
Quoted 8 lines
That's strange. I did run Azure before I posted this series, and Azure did not report any failure.
See https://dev.azure.com/bmeng/GitHub/_build/results?buildId=307&view=results
Did you apply all patches in this series?
Quoted 8 lines
At that link you can see the commit I built...I don't know how to see the list of previous commits in the web interface but I suppose you could fetch it and look.
Re the warning, it is there... see here:
https://dev.azure.com/bmeng/f9017223-94f4-4916-a888-4cac5e17223f/_apis/build/builds/307/logs/603
Strange, I wonder why Azure does not report it but gitlab reports it ..
Regards,
Bin
PATCH 2/7 global_data.h: Change ram_top type to phys_addr_t
Hi Bin,
Quoted 47 lines · Bin Meng
Hi Simon,
Quoted 43 lines · Simon Glass
Hi Bin,
Quoted 26 lines · Bin Meng
Hi Simon,
Quoted 22 lines · Simon Glass
Hi Bin,
Quoted 8 lines · Simon Glass
Quoted 6 lines · Bin Meng
From: Bin Meng <[email protected]>
It's possible to have
ram_topabove 4 GiB in a 32-bit system, hence we need to declareram_topasphys_addr_t.Quoted 7 lines
Quoted 5 lines
Signed-off-by Bin Meng <[email protected]>---
include/asm-generic/global_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>This patch causes build warnings...can you please take a look?
Quoted 8 lines
That's strange. I did run Azure before I posted this series, and Azure did not report any failure.
See https://dev.azure.com/bmeng/GitHub/_build/results?buildId=307&view=results
Did you apply all patches in this series?
At that link you can see the commit I built...I don't know how to see the list of previous commits in the web interface but I suppose you could fetch it and look.
Quoted 6 lines
Quoted 4 lines
Re the warning, it is there... see here:
https://dev.azure.com/bmeng/f9017223-94f4-4916-a888-4cac5e17223f/_apis/build/builds/307/logs/603
Strange, I wonder why Azure does not report it but gitlab reports it ..
I wonder if gitlab uses buildman -E but Azure does not?
Regards,
Simon
PATCH 2/7 global_data.h: Change ram_top type to phys_addr_t
Hi Simon,
Quoted 51 lines · Simon Glass
Hi Bin,
Quoted 47 lines · Bin Meng
Hi Simon,
Quoted 43 lines · Simon Glass
Hi Bin,
Quoted 26 lines · Bin Meng
Hi Simon,
Quoted 22 lines · Simon Glass
Hi Bin,
Quoted 8 lines · Simon Glass
Quoted 6 lines · Bin Meng
From: Bin Meng <[email protected]>
It's possible to have
ram_topabove 4 GiB in a 32-bit system, hence we need to declareram_topasphys_addr_t.Quoted 7 lines
Quoted 5 lines
Signed-off-by Bin Meng <[email protected]>---
include/asm-generic/global_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>This patch causes build warnings...can you please take a look?
Quoted 8 lines
That's strange. I did run Azure before I posted this series, and Azure did not report any failure.
See https://dev.azure.com/bmeng/GitHub/_build/results?buildId=307&view=results
Did you apply all patches in this series?
At that link you can see the commit I built...I don't know how to see the list of previous commits in the web interface but I suppose you could fetch it and look.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Re the warning, it is there... see here:
https://dev.azure.com/bmeng/f9017223-94f4-4916-a888-4cac5e17223f/_apis/build/builds/307/logs/603
Strange, I wonder why Azure does not report it but gitlab reports it ..
I wonder if gitlab uses buildman -E but Azure does not?
Yes, caused by commit dd5c954e917b937f85a2f8bfd79e0c9bce372985. I will send a patch to correct this.
Regards,
Bin
PATCH 3/7 serial: sifive: Cast dev_read_addr() with uintptr_t
In reply to Bin MengFrom: Bin Meng <[email protected]>
dev_read_addr() returns fdt_addr_t which is now a 64-bit address. In a 32-bit build, this causes the following warning seen when building serial_sifive.c:
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
Cast the return value with uintptr_t.
---
drivers/serial/serial_sifive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/serial/serial_sifive.c +1 -1
@@ -178,7 +178,7 @@ static int sifive_serial_of_to_plat(struct udevice *dev) {struct sifive_uart_plat *plat =dev_get_plat (dev); - plat->regs = (struct uart_sifive *)dev_read_addr (dev); + plat->regs = (struct uart_sifive *)(uintptr_t )dev_read_addr (dev);if (IS_ERR (plat->regs))return PTR_ERR (plat->regs);
Signature · 1 line
2.25.1
PATCH 4/7 fdtdec: Cast prior_stage_fdt_address with uintptr_t
In reply to Bin MengFrom: Bin Meng <[email protected]>
At present prior_stage_fdt_address is declared as phys_addr_t. On a 32-bit platform where phys_addr_t can be 64-bit, assigning its value to gd->fdt_blob which is a pointer, can cause warnings.
Cast it to uintptr_t before the assignment.
---
lib/fdtdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fdtdec.c +1 -1
@@ -1571,7 +1571,7 @@ int fdtdec_setup(void) return -1; }# elif defined(CONFIG_OF_PRIOR_STAGE) - gd->fdt_blob = (void *)prior_stage_fdt_address; + gd->fdt_blob = (void *)(uintptr_t )prior_stage_fdt_address;# endif # ifndef CONFIG_SPL_BUILD /* Allow the early environment to override the fdt address */
Signature · 1 line
2.25.1
PATCH 4/7 fdtdec: Cast prior_stage_fdt_address with uintptr_t
Quoted 7 lines · Bin Meng
From: Bin Meng <[email protected]>
At present
prior_stage_fdt_addressis declared asphys_addr_t. On a 32-bit platform wherephys_addr_tcan be 64-bit, assigning its value togd->fdt_blobwhich is a pointer, can cause warnings.
Quoted 7 lines
Cast it to
uintptr_tbefore the assignment.Signed-off-by Bin Meng <[email protected]>---
lib/fdtdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
The prior-stage stuff should be modified to use SPL_HANDOFF
PATCH 5/7 riscv: Change phys_addr_t and phys_size_t to 64-bit
In reply to Bin MengFrom: Bin Meng <[email protected]>
phys_addr_t and phys_size_t are currently defined as unsigned long, but RV32 supports 34-bit physical address, hence both phys_addr_t and phys_size_t should be defined to 64-bit using unsigned long long.
---
arch/riscv/include/asm/types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/include/asm/types.h +2 -2
@@ -35,8 +35,8 @@ typedef u64 dma_addr_t;typedef u32 dma_addr_t ;#endif -typedef unsigned long phys_addr_t ; -typedef unsigned long phys_size_t ; +typedef unsigned long long phys_addr_t ; +typedef unsigned long long phys_size_t ;#endif /* __KERNEL__ */
Signature · 1 line
2.25.1
PATCH 6/7 bdinfo: Rename function names to be clearer
In reply to Bin MengFrom: Bin Meng <[email protected]>
At present we have bdinfo_print_num() to print unsigned long numbers. We also have print_phys_addr() which accept numbers that might be 64-bit on a 32-bit platform.
Rename these 2 functions to be clearer:
bdinfo_print_num() => bdinfo_print_num_l()print_phys_addr() => bdinfo_print_num_ll()
While we are here, make bdinfo_print_num_ll() public so that it can be used outside cmd/bdinfo.c in the future.
---
arch/arm/lib/bdinfo.c | 16 ++++++------ arch/m68k/lib/bdinfo.c | 2 +- arch/powerpc/lib/bdinfo.c | 4 +-- cmd/bdinfo.c | 52 +++++++++++++++++++-------------------- include/init.h | 3 ++- 5 files changed, 39 insertions(+), 38 deletions(-)
arch/arm/lib/bdinfo.c +8 -8
@@ -15,23 +15,23 @@ void arch_print_bdinfo(void) {struct bd_info *bd = gd->bd; -bdinfo_print_num ("arch_number" , bd->bi_arch_number); +bdinfo_print_num_l ("arch_number" , bd->bi_arch_number);#ifdef CONFIG_SYS_MEM_RESERVE_SECURE if (gd->arch.secure_ram &MEM_RESERVE_SECURE_SECURED ) { -bdinfo_print_num ("Secure ram" , - gd->arch.secure_ram & -MEM_RESERVE_SECURE_ADDR_MASK ); +bdinfo_print_num_l ("Secure ram" , + gd->arch.secure_ram & +MEM_RESERVE_SECURE_ADDR_MASK ); }#endif #ifdef CONFIG_RESV_RAM if (gd->arch.resv_ram) -bdinfo_print_num ("Reserved ram" , gd->arch.resv_ram); +bdinfo_print_num_l ("Reserved ram" , gd->arch.resv_ram);#endif #if !(CONFIG_IS_ENABLED (SYS_ICACHE_OFF ) &&CONFIG_IS_ENABLED (SYS_DCACHE_OFF )) -bdinfo_print_num ("TLB addr" , gd->arch.tlb_addr); +bdinfo_print_num_l ("TLB addr" , gd->arch.tlb_addr);#endif -bdinfo_print_num ("irq_sp" , gd->irq_sp);/* irq stack pointer */ -bdinfo_print_num ("sp start " , gd->start_addr_sp); +bdinfo_print_num_l ("irq_sp" , gd->irq_sp);/* irq stack pointer */ +bdinfo_print_num_l ("sp start " , gd->start_addr_sp);/* * TODO: Currently only support for davinci SOC's is added. * Remove this check once all the board implement this.
arch/m68k/lib/bdinfo.c +1 -1
@@ -38,7 +38,7 @@ void arch_print_bdinfo(void)bdinfo_print_mhz ("busfreq" , bd->bi_busfreq);#if defined(CONFIG_SYS_MBAR ) -bdinfo_print_num ("mbar" , bd->bi_mbar_base); +bdinfo_print_num_l ("mbar" , bd->bi_mbar_base);#endif bdinfo_print_mhz ("cpufreq" , bd->bi_intfreq);if (IS_ENABLED (CONFIG_PCI ))
arch/powerpc/lib/bdinfo.c +2 -2
@@ -47,9 +47,9 @@ void arch_print_bdinfo(void)bdinfo_print_mhz ("busfreq" , bd->bi_busfreq);#if defined(CONFIG_MPC8xx) || defined(CONFIG_E500 ) -bdinfo_print_num ("immr_base" , bd->bi_immr_base); +bdinfo_print_num_l ("immr_base" , bd->bi_immr_base);#endif -bdinfo_print_num ("bootflags" , bd->bi_bootflags); +bdinfo_print_num_l ("bootflags" , bd->bi_bootflags);bdinfo_print_mhz ("intfreq" , bd->bi_intfreq);#ifdef CONFIG_ENABLE_36BIT_PHYS if (IS_ENABLED (CONFIG_PHYS_64BIT ))
cmd/bdinfo.c +26 -26
103 lines not on this page · raw message
include/init.h +2 -1
@@ -326,7 +326,8 @@ void relocate_code(ulong start_addr_sp, struct global_data *new_gd,#endif /* Print a numeric value (for use in arch_print_bdinfo()) */ -void bdinfo_print_num (const char *name,ulong value); +void bdinfo_print_num_l (const char *name,ulong value); +void bdinfo_print_num_ll (const char *name,unsigned long long value);/* Print a clock speed in MHz */ void bdinfo_print_mhz (const char *name,unsigned long hz);
Signature · 1 line
2.25.1
PATCH 7/7 bdinfo: Change to use bdinfo_print_num_ll() where the number could be 64-bit
In reply to Bin MengFrom: Bin Meng <[email protected]>
There are some calls to bdinfo_print_num_l() with parameters that could be a 64-bit value on a 32-bit system. Change those calls to use bdinfo_print_num_ll() instead.
---
arch/arm/lib/bdinfo.c | 8 ++++---- cmd/bdinfo.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
arch/arm/lib/bdinfo.c +4 -4
@@ -18,14 +18,14 @@ void arch_print_bdinfo(void)bdinfo_print_num_l ("arch_number" , bd->bi_arch_number);#ifdef CONFIG_SYS_MEM_RESERVE_SECURE if (gd->arch.secure_ram &MEM_RESERVE_SECURE_SECURED ) { -bdinfo_print_num_l ("Secure ram" , - gd->arch.secure_ram & -MEM_RESERVE_SECURE_ADDR_MASK ); +bdinfo_print_num_ll ("Secure ram" , + gd->arch.secure_ram & +MEM_RESERVE_SECURE_ADDR_MASK ); }#endif #ifdef CONFIG_RESV_RAM if (gd->arch.resv_ram) -bdinfo_print_num_l ("Reserved ram" , gd->arch.resv_ram); +bdinfo_print_num_ll ("Reserved ram" , gd->arch.resv_ram);#endif #if !(CONFIG_IS_ENABLED (SYS_ICACHE_OFF ) &&CONFIG_IS_ENABLED (SYS_DCACHE_OFF ))bdinfo_print_num_l ("TLB addr" , gd->arch.tlb_addr);
cmd/bdinfo.c +2 -2
@@ -55,8 +55,8 @@ static void print_bi_dram(const struct bd_info *bd)for (i =0 ; i <CONFIG_NR_DRAM_BANKS ; ++i) {if (bd->bi_dram[i].size) {bdinfo_print_num_l ("DRAM bank" , i); -bdinfo_print_num_l ("-> start" , bd->bi_dram[i].start); -bdinfo_print_num_l ("-> size" , bd->bi_dram[i].size); +bdinfo_print_num_ll ("-> start" , bd->bi_dram[i].start); +bdinfo_print_num_ll ("-> size" , bd->bi_dram[i].size); } } }
Signature · 1 line
2.25.1