blob: ec242207948badae6a545d93cf7fae8bd1ee6189 [file] [log] [blame]
Sean Anderson8502b5b2023-11-04 16:37:53 -04001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2023 Sean Anderson <seanga2@gmail.com>
4 */
5
6#include <nand.h>
7#include <spl.h>
8#include <test/spl.h>
9#include <test/ut.h>
10
11uint32_t spl_nand_get_uboot_raw_page(void);
12
13static int spl_test_nand_write_image(struct unit_test_state *uts, void *img,
14 size_t img_size)
15{
16 uint32_t off = spl_nand_get_uboot_raw_page();
17 struct mtd_info *mtd;
18 struct erase_info erase = { };
19 size_t length;
20
21 nand_reinit();
22 mtd = get_nand_dev_by_index(0);
23 ut_assertnonnull(mtd);
24
25 /* Mark the first block as bad to test that it gets skipped */
26 ut_assertok(mtd_block_markbad(mtd, off & ~mtd->erasesize_mask));
27 off += mtd->erasesize;
28
29 erase.mtd = mtd;
30 erase.len = img_size + (off & mtd->erasesize_mask);
31 erase.len += mtd->erasesize_mask;
32 erase.len &= ~mtd->erasesize_mask;
33 erase.addr = off & ~mtd->erasesize_mask;
34 erase.scrub = 1;
35 ut_assertok(mtd_erase(mtd, &erase));
36
37 ut_assertok(mtd_write(mtd, off, img_size, &length, img));
38
39 return 0;
40}
41
42static int spl_test_nand(struct unit_test_state *uts, const char *test_name,
43 enum spl_test_image type)
44{
45 return do_spl_test_load(uts, test_name, type,
46 SPL_LOAD_IMAGE_GET(1, BOOT_DEVICE_NAND,
47 spl_nand_load_image),
48 spl_test_nand_write_image);
49}
50SPL_IMG_TEST(spl_test_nand, LEGACY, DM_FLAGS);
51SPL_IMG_TEST(spl_test_nand, LEGACY_LZMA, DM_FLAGS);
52SPL_IMG_TEST(spl_test_nand, IMX8, DM_FLAGS);
53SPL_IMG_TEST(spl_test_nand, FIT_INTERNAL, DM_FLAGS);
Sean Anderson11f83462023-11-08 11:48:51 -050054#if !IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)
Sean Anderson8502b5b2023-11-04 16:37:53 -040055SPL_IMG_TEST(spl_test_nand, FIT_EXTERNAL, DM_FLAGS);
Sean Anderson11f83462023-11-08 11:48:51 -050056#endif