[PATCH 1/2] mtd: rawnand: nand_spl_loaders: move nand page buffer to heap

Colin Foster colin.foster at in-advantage.com
Wed May 10 02:20:33 CEST 2023


SPL configurations that read from NAND need a page of RAM as a buffer.
Initially this memory was statically allocated.

Move this to the heap, so it can benefit from initialized DDR.

Signed-off-by: Colin Foster <colin.foster at in-advantage.com>
---

v2:
    New patch.
    Note: This patch gives an SPDX warning due to the comment that was
    moved.

---
 drivers/mtd/nand/raw/nand_spl_loaders.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_spl_loaders.c b/drivers/mtd/nand/raw/nand_spl_loaders.c
index 156b44d835..8f243ce1b6 100644
--- a/drivers/mtd/nand/raw/nand_spl_loaders.c
+++ b/drivers/mtd/nand/raw/nand_spl_loaders.c
@@ -1,3 +1,11 @@
+/*
+ * Temporary storage for non NAND page aligned and non NAND page sized
+ * reads. Note: This does not support runtime detected FLASH yet, but
+ * that should be reasonably easy to fix by making the buffer large
+ * enough :)
+ */
+static u8 *scratch_buf;
+
 int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)
 {
 	unsigned int block, lastblock;
@@ -70,14 +78,6 @@ u32 nand_spl_adjust_offset(u32 sector, u32 offs)
 }
 
 #ifdef CONFIG_SPL_UBI
-/*
- * Temporary storage for non NAND page aligned and non NAND page sized
- * reads. Note: This does not support runtime detected FLASH yet, but
- * that should be reasonably easy to fix by making the buffer large
- * enough :)
- */
-static u8 scratch_buf[CONFIG_SYS_NAND_PAGE_SIZE];
-
 /**
  * nand_spl_read_block - Read data from physical eraseblock into a buffer
  * @block:	Number of the physical eraseblock
@@ -103,6 +103,12 @@ int nand_spl_read_block(int block, int offset, int len, void *dst)
 {
 	int page, read;
 
+	if (!scratch_buf)
+		scratch_buf = malloc(CONFIG_SYS_NAND_PAGE_SIZE);
+
+	if (!scratch_buf)
+		return -ENOMEM;
+
 	/* Calculate the page number */
 	page = offset / CONFIG_SYS_NAND_PAGE_SIZE;
 
-- 
2.25.1



More information about the U-Boot mailing list