diff mbox series

[RFC,v2,20/48] lmb: reserve common areas during board init

Message ID 20240704073544.670249-21-sughosh.ganu@linaro.org
State New
Headers show
Series Make U-Boot memory reservations coherent | expand

Commit Message

Sughosh Ganu July 4, 2024, 7:35 a.m. UTC
The LMB module provides API's for allocating and reserving chunks of
memory which is then typically used for things like loading images for
booting. Reserve the portion of memory that is occupied by the U-Boot
image itself, and other parts of memory that might have been marked as
reserved in the board's DTB.

Mark these regions of memory with the LMB_NOOVERWRITE flag to indicate
that these regions cannot be re-requested or overwritten.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---
Changes since V1:
* Mark the reserved regions as LMB_NOOVERWRITE.
* Call the lmb_reserve_common() function in U-Boot proper after
  relocation.

 lib/lmb.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Simon Glass July 13, 2024, 3:15 p.m. UTC | #1
On Thu, 4 Jul 2024 at 08:37, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> The LMB module provides API's for allocating and reserving chunks of
> memory which is then typically used for things like loading images for
> booting. Reserve the portion of memory that is occupied by the U-Boot
> image itself, and other parts of memory that might have been marked as
> reserved in the board's DTB.
>
> Mark these regions of memory with the LMB_NOOVERWRITE flag to indicate
> that these regions cannot be re-requested or overwritten.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> ---
> Changes since V1:
> * Mark the reserved regions as LMB_NOOVERWRITE.
> * Call the lmb_reserve_common() function in U-Boot proper after
>   relocation.
>
>  lib/lmb.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/lib/lmb.c b/lib/lmb.c
index e1dde14a3c..456b64c00a 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -13,6 +13,7 @@ 
 #include <lmb.h>
 #include <log.h>
 #include <malloc.h>
+#include <spl.h>
 
 #include <asm/global_data.h>
 #include <asm/sections.h>
@@ -173,10 +174,11 @@  void arch_lmb_reserve_generic(ulong sp, ulong end, ulong align)
 		if (bank_end > end)
 			bank_end = end - 1;
 
-		lmb_reserve(sp, bank_end - sp + 1);
+		lmb_reserve_flags(sp, bank_end - sp + 1, LMB_NOOVERWRITE);
 
 		if (gd->flags & GD_FLG_SKIP_RELOC)
-			lmb_reserve((phys_addr_t)(uintptr_t)_start, gd->mon_len);
+			lmb_reserve_flags((phys_addr_t)(uintptr_t)_start,
+				    gd->mon_len, LMB_NOOVERWRITE);
 
 		break;
 	}
@@ -739,5 +741,9 @@  int lmb_mem_regions_init(void)
 
 	lmb_add_memory();
 
+	/* Reserve the U-Boot image region once U-Boot has relocated */
+	if (spl_phase() == PHASE_BOARD_R)
+		lmb_reserve_common((void *)gd->fdt_blob);
+
 	return 0;
 }