Skip to contentSkip to conversation

xilinx: common: change bootm_size to not go beyond ram_top

PATCH Superseded Ricardo Salveti 2 participants 3 messages Jan 19, 2022 – Jan 20, 2022 Arm/Zynq architecture

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xilinx: common: change bootm_size to not go beyond ram_top

The available ram can be limited by ram_top as that depends on the reserved memory nodes provided by the device-tree (via board_get_usable_ram_top), so make sure to respect ram_top when setting up bootm_size to avoid overlapping reserved memory regions (e.g. memory used by OP-TEE).

The same logic is available in env_get_bootm_size when bootm_size is not defined by the default environment.

---
 board/xilinx/common/board.c | 3 +++
 1 file changed, 3 insertions(+)
board/xilinx/common/board.c +3 -0
index 78a5d0efa86..4928fab2c96 100644
@@ -389,6 +389,9 @@ int board_late_init_xilinx(void)
 	if (CONFIG_IS_ENABLED(ARCH_ZYNQ) || CONFIG_IS_ENABLED(MICROBLAZE))
 		bootm_size = min(bootm_size, (phys_size_t)(SZ_512M + SZ_256M));
 
+	if (gd->ram_base + bootm_size > gd->ram_top)
+		bootm_size = gd->ram_top - gd->ram_base;
+
 	ret |= env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET);
 
 	ret |= env_set_addr("bootm_low", (void *)gd->ram_base);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 19 lines · Ricardo Salveti

The available ram can be limited by ram_top as that depends on the reserved memory nodes provided by the device-tree (via board_get_usable_ram_top), so make sure to respect ram_top when setting up bootm_size to avoid overlapping reserved memory regions (e.g. memory used by OP-TEE).

The same logic is available in env_get_bootm_size when bootm_size is not defined by the default environment.

---
  board/xilinx/common/board.c | 3 +++
  1 file changed, 3 insertions(+)
board/xilinx/common/board.c +0 -0
index 78a5d0efa86..4928fab2c96 100644

board/xilinx/common/board.c int board_late_init_xilinx(void) · line 397

Quoted 9 lines
board/xilinx/common/board.c +3 -0
@@ -389,6 +389,9 @@ int board_late_init_xilinx(void)
  	if (CONFIG_IS_ENABLED(ARCH_ZYNQ) || CONFIG_IS_ENABLED(MICROBLAZE))
  		bootm_size = min(bootm_size, (phys_size_t)(SZ_512M + SZ_256M));
 
+	if (gd->ram_base + bootm_size > gd->ram_top)
+		bootm_size = gd->ram_top - gd->ram_base;
+
  	ret |= env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET);
 
  	ret |= env_set_addr("bootm_low", (void *)gd->ram_base);

Isn't it easier to directly setup bootm_size like this?

phys_size_t bootm_size = gd->ram_top - gd->ram_base;

Thanks,
Michal

Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs
#2 lore raw
Quoted 28 lines · Michal Simek
Quoted 27 lines · Ricardo Salveti

The available ram can be limited by ram_top as that depends on the reserved memory nodes provided by the device-tree (via board_get_usable_ram_top), so make sure to respect ram_top when setting up bootm_size to avoid overlapping reserved memory regions (e.g. memory used by OP-TEE).

The same logic is available in env_get_bootm_size when bootm_size is not defined by the default environment.

---
  board/xilinx/common/board.c | 3 +++
  1 file changed, 3 insertions(+)
board/xilinx/common/board.c +3 -0
index 78a5d0efa86..4928fab2c96 100644
@@ -389,6 +389,9 @@ int board_late_init_xilinx(void)
      if (CONFIG_IS_ENABLED(ARCH_ZYNQ) || CONFIG_IS_ENABLED(MICROBLAZE))
              bootm_size = min(bootm_size, (phys_size_t)(SZ_512M + SZ_256M));
 
+     if (gd->ram_base + bootm_size > gd->ram_top)
+             bootm_size = gd->ram_top - gd->ram_base;
+
      ret |= env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET);
 
Quoted 5 lines

board/xilinx/common/board.c int board_late_init_xilinx(void) · line 397

Quoted 1 line
board/xilinx/common/board.c +0 -0
      ret |= env_set_addr("bootm_low", (void *)gd->ram_base);

Isn't it easier to directly setup bootm_size like this?

phys_size_t bootm_size = gd->ram_top - gd->ram_base;

Yup, that should work better, will send a v2.

Thanks,

Signature · 1 line
Ricardo Salveti