aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2023-11-16 12:46:09 -0500
committerTom Rini <trini@konsulko.com>2023-11-16 13:49:13 -0500
commit5e6a112e1187ebc570b8befd1dd6eef3a64dec39 (patch)
tree0f87bf8f8b38403cc7b331ecc1660a2ef6b3af45 /common
parenta9a73799731807cca117d234c4338b710db3cfdd (diff)
parent8502b5bf20505408773d98fbc6e9307cb962e8b0 (diff)
downloadu-boot-5e6a112e1187ebc570b8befd1dd6eef3a64dec39.zip
u-boot-5e6a112e1187ebc570b8befd1dd6eef3a64dec39.tar.gz
u-boot-5e6a112e1187ebc570b8befd1dd6eef3a64dec39.tar.bz2
Merge patch series "nand: Add sandbox tests"
To quote the author: This series tests raw nand flash in sandbox and fixes various bugs discovered in the process. I've tried to do things in a contemporary manner, avoiding the (numerous) variations present on only a few boards. The test is pretty minimal. Future work could test the rest of the nand API as well as the MTD API. Bloat (for v1) at [1] (for boards with SPL_NAND_SUPPORT enabled). Almost everything grows by a few bytes due to nand_page_size. A few boards grow more, mostly those using nand_spl_loaders.c. CI at [2]. [1] https://gist.github.com/Forty-Bot/9694f3401893c9e706ccc374922de6c2 [2] https://source.denx.de/u-boot/custodians/u-boot-clk/-/pipelines/18443
Diffstat (limited to 'common')
-rw-r--r--common/spl/Kconfig2
-rw-r--r--common/spl/spl_legacy.c18
-rw-r--r--common/spl/spl_nand.c20
3 files changed, 22 insertions, 18 deletions
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 25cd18a..00332cf 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -857,7 +857,7 @@ config SPL_MPC8XXX_INIT_DDR
allows DRAM to be set up before loading U-Boot into that DRAM,
where it can run.
-config SPL_MTD_SUPPORT
+config SPL_MTD
bool "Support MTD drivers"
help
Enable support for MTD (Memory Technology Device) within SPL. MTD
diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
index 51656fb..9189576 100644
--- a/common/spl/spl_legacy.c
+++ b/common/spl/spl_legacy.c
@@ -133,25 +133,31 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
map_sysmem(spl_image->load_addr, spl_image->size));
break;
- case IH_COMP_LZMA:
+ case IH_COMP_LZMA: {
+ ulong overhead, size;
+
lzma_len = LZMA_LEN;
/* dataptr points to compressed payload */
- dataptr = offset + sizeof(*hdr);
+ dataptr = ALIGN_DOWN(sizeof(*hdr), load->bl_len);
+ overhead = sizeof(*hdr) - dataptr;
+ size = ALIGN(spl_image->size + overhead, load->bl_len);
+ dataptr += offset;
debug("LZMA: Decompressing %08lx to %08lx\n",
dataptr, spl_image->load_addr);
- src = malloc(spl_image->size);
+ src = malloc(size);
if (!src) {
printf("Unable to allocate %d bytes for LZMA\n",
spl_image->size);
return -ENOMEM;
}
- load->read(load, dataptr, spl_image->size, src);
+ load->read(load, dataptr, size, src);
ret = lzmaBuffToBuffDecompress(map_sysmem(spl_image->load_addr,
spl_image->size),
- &lzma_len, src, spl_image->size);
+ &lzma_len, src + overhead,
+ spl_image->size);
if (ret) {
printf("LZMA decompression error: %d\n", ret);
return ret;
@@ -159,7 +165,7 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
spl_image->size = lzma_len;
break;
-
+ }
default:
debug("Compression method %s is not supported\n",
genimg_get_comp_short_name(image_get_comp(hdr)));
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 07916be..b8cd640 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -11,6 +11,7 @@
#include <log.h>
#include <spl.h>
#include <asm/io.h>
+#include <mapmem.h>
#include <nand.h>
#include <linux/libfdt_env.h>
#include <fdt.h>
@@ -32,7 +33,8 @@ static int spl_nand_load_image(struct spl_image_info *spl_image,
nand_spl_load_image(spl_nand_get_uboot_raw_page(),
CFG_SYS_NAND_U_BOOT_SIZE,
- (void *)CFG_SYS_NAND_U_BOOT_DST);
+ map_sysmem(CFG_SYS_NAND_U_BOOT_DST,
+ CFG_SYS_NAND_U_BOOT_SIZE));
spl_set_header_raw_uboot(spl_image);
nand_deselect();
@@ -72,23 +74,18 @@ static ulong spl_nand_legacy_read(struct spl_load_info *load, ulong offs,
return size;
}
-struct mtd_info * __weak nand_get_mtd(void)
-{
- return NULL;
-}
-
static int spl_nand_load_element(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev,
int offset, struct legacy_img_hdr *header)
{
- struct mtd_info *mtd = nand_get_mtd();
- int bl_len = mtd ? mtd->writesize : 1;
+ int bl_len;
int err;
err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
if (err)
return err;
+ bl_len = nand_page_size();
if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
image_get_magic(header) == FDT_MAGIC) {
struct spl_load_info load;
@@ -105,7 +102,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
struct spl_load_info load;
load.dev = NULL;
- load.priv = NULL;
+ load.priv = &offset;
load.filename = NULL;
load.bl_len = bl_len;
load.read = spl_nand_fit_read;
@@ -118,7 +115,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
load.dev = NULL;
load.priv = NULL;
load.filename = NULL;
- load.bl_len = 1;
+ load.bl_len = IS_ENABLED(CONFIG_SPL_LZMA) ? bl_len : 1;
load.read = spl_nand_legacy_read;
return spl_load_legacy_img(spl_image, bootdev, &load, offset, header);
@@ -127,7 +124,8 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
if (err)
return err;
return nand_spl_load_image(offset, spl_image->size,
- (void *)(ulong)spl_image->load_addr);
+ map_sysmem(spl_image->load_addr,
+ spl_image->size));
}
}