diff mbox series

[16/40] lmb: allow lmb module to be used in SPL

Message ID 20240724060224.3071065-17-sughosh.ganu@linaro.org
State Superseded
Headers show
Series Make LMB memory map global and persistent | expand

Commit Message

Sughosh Ganu July 24, 2024, 6:02 a.m. UTC
With the introduction of separate config symbols for the SPL phase of
U-Boot, the condition checks need to be tweaked so that platforms that
enable the LMB module in SPL are also able to call the LMB API's. Use
the appropriate condition checks to achieve this.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---
Changes since rfc:
* Replace conditional compilation of lmb code to an if
  (CONFIG_IS_ENABLED()) in store_block() and tftp_init_load_addr().

 board/xilinx/common/board.c |  2 +-
 boot/bootm.c                |  4 ++--
 boot/image-board.c          |  2 +-
 fs/fs.c                     |  4 ++--
 lib/Makefile                |  2 +-
 net/tftp.c                  | 40 ++++++++++++++++++-------------------
 net/wget.c                  |  4 ++--
 7 files changed, 29 insertions(+), 29 deletions(-)

Comments

Simon Glass July 25, 2024, 11:32 p.m. UTC | #1
Hi Sughosh,

On Wed, 24 Jul 2024 at 00:04, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> With the introduction of separate config symbols for the SPL phase of
> U-Boot, the condition checks need to be tweaked so that platforms that
> enable the LMB module in SPL are also able to call the LMB API's. Use
> the appropriate condition checks to achieve this.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> ---
> Changes since rfc:
> * Replace conditional compilation of lmb code to an if
>   (CONFIG_IS_ENABLED()) in store_block() and tftp_init_load_addr().
>
>  board/xilinx/common/board.c |  2 +-
>  boot/bootm.c                |  4 ++--
>  boot/image-board.c          |  2 +-
>  fs/fs.c                     |  4 ++--
>  lib/Makefile                |  2 +-
>  net/tftp.c                  | 40 ++++++++++++++++++-------------------
>  net/wget.c                  |  4 ++--
>  7 files changed, 29 insertions(+), 29 deletions(-)

Same question as previous patch...do any platforms need lmb in SPL?

The cover letter says "The LMB module is enabled by default for the
main U-Boot image, while it needs to be enabled for SPL." but I don't
really understand that.

Regards,
Simon
Sughosh Ganu July 29, 2024, 7:51 a.m. UTC | #2
On Fri, 26 Jul 2024 at 05:02, Simon Glass <sjg@chromium.org> wrote:
>
> Hi Sughosh,
>
> On Wed, 24 Jul 2024 at 00:04, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
> >
> > With the introduction of separate config symbols for the SPL phase of
> > U-Boot, the condition checks need to be tweaked so that platforms that
> > enable the LMB module in SPL are also able to call the LMB API's. Use
> > the appropriate condition checks to achieve this.
> >
> > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > ---
> > Changes since rfc:
> > * Replace conditional compilation of lmb code to an if
> >   (CONFIG_IS_ENABLED()) in store_block() and tftp_init_load_addr().
> >
> >  board/xilinx/common/board.c |  2 +-
> >  boot/bootm.c                |  4 ++--
> >  boot/image-board.c          |  2 +-
> >  fs/fs.c                     |  4 ++--
> >  lib/Makefile                |  2 +-
> >  net/tftp.c                  | 40 ++++++++++++++++++-------------------
> >  net/wget.c                  |  4 ++--
> >  7 files changed, 29 insertions(+), 29 deletions(-)
>
> Same question as previous patch...do any platforms need lmb in SPL?

Same answer as my other two emails. This was called for by the maintainers.

-sughosh

>
> The cover letter says "The LMB module is enabled by default for the
> main U-Boot image, while it needs to be enabled for SPL." but I don't
> really understand that.
>
> Regards,
> Simon
diff mbox series

Patch

diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index 4056884400..f04c92a70f 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -665,7 +665,7 @@  int embedded_dtb_select(void)
 }
 #endif
 
-#if defined(CONFIG_LMB)
+#if IS_ENABLED(CONFIG_LMB)
 
 #ifndef MMU_SECTION_SIZE
 #define MMU_SECTION_SIZE        (1 * 1024 * 1024)
diff --git a/boot/bootm.c b/boot/bootm.c
index 7b3fe551de..5ce84b73b5 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -239,7 +239,7 @@  static int boot_get_kernel(const char *addr_fit, struct bootm_headers *images,
 	return 0;
 }
 
-#ifdef CONFIG_LMB
+#if CONFIG_IS_ENABLED(LMB)
 static void boot_start_lmb(void)
 {
 	phys_addr_t	mem_start;
@@ -1048,7 +1048,7 @@  int bootm_run_states(struct bootm_info *bmi, int states)
 		}
 	}
 #endif
-#if CONFIG_IS_ENABLED(OF_LIBFDT) && defined(CONFIG_LMB)
+#if CONFIG_IS_ENABLED(OF_LIBFDT) && CONFIG_IS_ENABLED(LMB)
 	if (!ret && (states & BOOTM_STATE_FDT)) {
 		boot_fdt_add_mem_rsv_regions(images->ft_addr);
 		ret = boot_relocate_fdt(&images->ft_addr, &images->ft_len);
diff --git a/boot/image-board.c b/boot/image-board.c
index 1f8c1ac69f..99ee7968ba 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -883,7 +883,7 @@  int image_setup_linux(struct bootm_headers *images)
 	int ret;
 
 	/* This function cannot be called without lmb support */
-	if (!IS_ENABLED(CONFIG_LMB))
+	if (!CONFIG_IS_ENABLED(LMB))
 		return -EFAULT;
 	if (CONFIG_IS_ENABLED(OF_LIBFDT))
 		boot_fdt_add_mem_rsv_regions(*of_flat_tree);
diff --git a/fs/fs.c b/fs/fs.c
index 2c835eef86..3fb00590be 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -526,7 +526,7 @@  int fs_size(const char *filename, loff_t *size)
 	return ret;
 }
 
-#ifdef CONFIG_LMB
+#if CONFIG_IS_ENABLED(LMB)
 /* Check if a file may be read to the given address */
 static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset,
 			     loff_t len, struct fstype_info *info)
@@ -567,7 +567,7 @@  static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
 	void *buf;
 	int ret;
 
-#ifdef CONFIG_LMB
+#if CONFIG_IS_ENABLED(LMB)
 	if (do_lmb_check) {
 		ret = fs_read_lmb_check(filename, addr, offset, len, info);
 		if (ret)
diff --git a/lib/Makefile b/lib/Makefile
index 81b503ab52..398c11726e 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -118,7 +118,7 @@  obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += fdtdec.o fdtdec_common.o
 obj-y += hang.o
 obj-y += linux_compat.o
 obj-y += linux_string.o
-obj-$(CONFIG_LMB) += lmb.o
+obj-$(CONFIG_$(SPL_)LMB) += lmb.o
 obj-y += membuff.o
 obj-$(CONFIG_REGEX) += slre.o
 obj-y += string.o
diff --git a/net/tftp.c b/net/tftp.c
index a199f4a6df..f841f6b701 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -82,9 +82,7 @@  static ulong	tftp_block_wrap;
 static ulong	tftp_block_wrap_offset;
 static int	tftp_state;
 static ulong	tftp_load_addr;
-#ifdef CONFIG_LMB
 static ulong	tftp_load_size;
-#endif
 #ifdef CONFIG_TFTP_TSIZE
 /* The file size reported by the server */
 static int	tftp_tsize;
@@ -160,19 +158,20 @@  static inline int store_block(int block, uchar *src, unsigned int len)
 	ulong store_addr = tftp_load_addr + offset;
 	void *ptr;
 
-#ifdef CONFIG_LMB
-	ulong end_addr = tftp_load_addr + tftp_load_size;
+	if (CONFIG_IS_ENABLED(LMB)) {
+		ulong end_addr = tftp_load_addr + tftp_load_size;
 
-	if (!end_addr)
-		end_addr = ULONG_MAX;
+		if (!end_addr)
+			end_addr = ULONG_MAX;
 
-	if (store_addr < tftp_load_addr ||
-	    store_addr + len > end_addr) {
-		puts("\nTFTP error: ");
-		puts("trying to overwrite reserved memory...\n");
-		return -1;
+		if (store_addr < tftp_load_addr ||
+		    store_addr + len > end_addr) {
+			puts("\nTFTP error: ");
+			puts("trying to overwrite reserved memory...\n");
+			return -1;
+		}
 	}
-#endif
+
 	ptr = map_sysmem(store_addr, len);
 	memcpy(ptr, src, len);
 	unmap_sysmem(ptr);
@@ -709,17 +708,18 @@  static void tftp_timeout_handler(void)
 /* Initialize tftp_load_addr and tftp_load_size from image_load_addr and lmb */
 static int tftp_init_load_addr(void)
 {
-#ifdef CONFIG_LMB
-	phys_size_t max_size;
+	if (CONFIG_IS_ENABLED(LMB)) {
+		phys_size_t max_size;
 
-	lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob);
+		lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob);
 
-	max_size = lmb_get_free_size(image_load_addr);
-	if (!max_size)
-		return -1;
+		max_size = lmb_get_free_size(image_load_addr);
+		if (!max_size)
+			return -1;
+
+		tftp_load_size = max_size;
+	}
 
-	tftp_load_size = max_size;
-#endif
 	tftp_load_addr = image_load_addr;
 	return 0;
 }
diff --git a/net/wget.c b/net/wget.c
index 7cf809a8ef..b8ea43e7f0 100644
--- a/net/wget.c
+++ b/net/wget.c
@@ -98,7 +98,7 @@  static inline int store_block(uchar *src, unsigned int offset, unsigned int len)
 	ulong newsize = offset + len;
 	uchar *ptr;
 
-	if (IS_ENABLED(CONFIG_LMB)) {
+	if (CONFIG_IS_ENABLED(LMB)) {
 		ulong end_addr = image_load_addr + wget_load_size;
 
 		if (!end_addr)
@@ -496,7 +496,7 @@  void wget_start(void)
 	debug_cond(DEBUG_WGET,
 		   "\nwget:Load address: 0x%lx\nLoading: *\b", image_load_addr);
 
-	if (IS_ENABLED(CONFIG_LMB)) {
+	if (CONFIG_IS_ENABLED(LMB)) {
 		if (wget_init_load_size()) {
 			printf("\nwget error: ");
 			printf("trying to overwrite reserved memory...\n");