1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2021 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
14 /* Declare a new SPL test */
15 #define SPL_TEST(_name, _flags) UNIT_TEST(_name, _flags, spl_test)
17 /* Context used for this test */
22 static ulong read_fit_image(struct spl_load_info *load, ulong sector,
23 ulong count, void *buf)
25 struct text_ctx *text_ctx = load->priv;
29 offset = sector * load->bl_len;
30 ret = os_lseek(text_ctx->fd, offset, OS_SEEK_SET);
32 printf("Failed to seek to %zx, got %zx (errno=%d)\n", offset,
37 res = os_read(text_ctx->fd, buf, count * load->bl_len);
39 printf("Failed to read %lx bytes, got %ld (errno=%d)\n",
40 count * load->bl_len, res, errno);
47 int board_fit_config_name_match(const char *name)
52 struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
54 return map_sysmem(0x100000, 0);
57 static int spl_test_load(struct unit_test_state *uts)
59 struct spl_image_info image;
60 struct image_header *header;
61 struct text_ctx text_ctx;
62 struct spl_load_info load;
67 memset(&load, '\0', sizeof(load));
69 load.read = read_fit_image;
71 ret = sandbox_find_next_phase(fname, sizeof(fname), true);
73 printf("(%s not found, error %d)\n", fname, ret);
76 load.filename = fname;
78 header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
80 fd = os_open(fname, OS_O_RDONLY);
82 ut_asserteq(512, os_read(fd, header, 512));
85 load.priv = &text_ctx;
87 ut_assertok(spl_load_simple_fit(&image, &load, 0, header));
91 SPL_TEST(spl_test_load, 0);