mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-01 00:49:43 +00:00
spl: test: Add a test for spl_load_simple_fit()
As an example of an SPL test, add a new test for loading a FIT within SPL. This runs on sandbox_spl. For this to work, the text base is adjusted so that there is plenty of space available. While we are here, document struct spl_load_info properly, since this is currently ambiguous. This test only verifies the logic path. It does not actually check that the image is loaded correctly. It is not possible for sandbox's SPL to actually run u-boot.img since it currently includes u-boot.bin rather than u-boot. Further work could expand the test in that direction. The need for this was noted at: http://patchwork.ozlabs.org/project/uboot/patch/20201216000944.2832585-3-mr.nuke.me@gmail.com/ Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
891d9e84a7
commit
2e059e4a6e
6 changed files with 110 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
|||
CONFIG_SYS_TEXT_BASE=0
|
||||
CONFIG_SYS_TEXT_BASE=0x200000
|
||||
CONFIG_SPL_LIBCOMMON_SUPPORT=y
|
||||
CONFIG_SPL_LIBGENERIC_SUPPORT=y
|
||||
CONFIG_NR_DRAM_BANKS=1
|
||||
|
|
|
@ -537,5 +537,7 @@ Addr Config Usage
|
|||
e000 CONFIG_BLOBLIST_ADDR Blob list
|
||||
10000 CONFIG_MALLOC_F_ADDR Early memory allocation
|
||||
f0000 CONFIG_PRE_CON_BUF_ADDR Pre-console buffer
|
||||
100000 CONFIG_TRACE_EARLY_ADDR Early trace buffer (if enabled)
|
||||
100000 CONFIG_TRACE_EARLY_ADDR Early trace buffer (if enabled). Also used
|
||||
as the SPL load buffer in spl_test_load().
|
||||
200000 CONFIG_SYS_TEXT_BASE Load buffer for U-Boot (sandbox_spl only)
|
||||
======= ======================== ===============================
|
||||
|
|
|
@ -222,6 +222,15 @@ struct spl_load_info {
|
|||
void *priv;
|
||||
int bl_len;
|
||||
const char *filename;
|
||||
/**
|
||||
* read() - Read from device
|
||||
*
|
||||
* @load: Information about the load state
|
||||
* @sector: Sector number to read from (each @load->bl_len bytes)
|
||||
* @count: Number of sectors to read
|
||||
* @buf: Buffer to read into
|
||||
* @return number of sectors read, 0 on error
|
||||
*/
|
||||
ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
|
||||
void *buf);
|
||||
};
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# (C) Copyright 2012 The Chromium Authors
|
||||
|
||||
obj-y += test-main.o
|
||||
obj-$(CONFIG_SANDBOX) += image/
|
||||
|
||||
ifneq ($(CONFIG_$(SPL_)BLOBLIST),)
|
||||
obj-$(CONFIG_$(SPL_)CMDLINE) += bloblist.o
|
||||
|
|
5
test/image/Makefile
Normal file
5
test/image/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
# SPDX-License-Identifier: GPL-2.0+
|
||||
#
|
||||
# Copyright 2021 Google LLC
|
||||
|
||||
obj-$(CONFIG_SPL_BUILD) += spl_load.o
|
91
test/image/spl_load.c
Normal file
91
test/image/spl_load.c
Normal file
|
@ -0,0 +1,91 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Copyright 2021 Google LLC
|
||||
* Written by Simon Glass <sjg@chromium.org>
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <image.h>
|
||||
#include <mapmem.h>
|
||||
#include <os.h>
|
||||
#include <spl.h>
|
||||
#include <test/ut.h>
|
||||
|
||||
/* Declare a new SPL test */
|
||||
#define SPL_TEST(_name, _flags) UNIT_TEST(_name, _flags, spl_test)
|
||||
|
||||
/* Context used for this test */
|
||||
struct text_ctx {
|
||||
int fd;
|
||||
};
|
||||
|
||||
static ulong read_fit_image(struct spl_load_info *load, ulong sector,
|
||||
ulong count, void *buf)
|
||||
{
|
||||
struct text_ctx *text_ctx = load->priv;
|
||||
off_t offset, ret;
|
||||
ssize_t res;
|
||||
|
||||
offset = sector * load->bl_len;
|
||||
ret = os_lseek(text_ctx->fd, offset, OS_SEEK_SET);
|
||||
if (ret != offset) {
|
||||
printf("Failed to seek to %zx, got %zx (errno=%d)\n", offset,
|
||||
ret, errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
res = os_read(text_ctx->fd, buf, count * load->bl_len);
|
||||
if (res == -1) {
|
||||
printf("Failed to read %lx bytes, got %ld (errno=%d)\n",
|
||||
count * load->bl_len, res, errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int board_fit_config_name_match(const char *name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
|
||||
{
|
||||
return map_sysmem(0x100000, 0);
|
||||
}
|
||||
|
||||
static int spl_test_load(struct unit_test_state *uts)
|
||||
{
|
||||
struct spl_image_info image;
|
||||
struct image_header *header;
|
||||
struct text_ctx text_ctx;
|
||||
struct spl_load_info load;
|
||||
char fname[256];
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
memset(&load, '\0', sizeof(load));
|
||||
load.bl_len = 512;
|
||||
load.read = read_fit_image;
|
||||
|
||||
ret = os_find_u_boot(fname, sizeof(fname), true);
|
||||
if (ret) {
|
||||
printf("(%s not found, error %d)\n", fname, ret);
|
||||
return ret;
|
||||
}
|
||||
load.filename = fname;
|
||||
|
||||
header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
|
||||
|
||||
fd = os_open(fname, OS_O_RDONLY);
|
||||
ut_assert(fd >= 0);
|
||||
ut_asserteq(512, os_read(fd, header, 512));
|
||||
text_ctx.fd = fd;
|
||||
|
||||
load.priv = &text_ctx;
|
||||
|
||||
ut_assertok(spl_load_simple_fit(&image, &load, 0, header));
|
||||
|
||||
return 0;
|
||||
}
|
||||
SPL_TEST(spl_test_load, 0);
|
Loading…
Reference in a new issue