1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// SPDX-License-Identifier: GPL-2.0+
/*
* FIT image loader using MTD read
*
* Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
* Apurva Nandan <a-nandan@ti.com>
*/
#include <common.h>
#include <config.h>
#include <image.h>
#include <log.h>
#include <spl.h>
#include <asm/io.h>
#include <mtd.h>
uint32_t __weak spl_mtd_get_uboot_offs(void)
{
return CONFIG_SYS_MTD_U_BOOT_OFFS;
}
static ulong spl_mtd_fit_read(struct spl_load_info *load, ulong offs,
ulong size, void *dst)
{
struct mtd_info *mtd = load->dev;
int err;
size_t ret_len;
err = mtd_read(mtd, offs, size, &ret_len, dst);
if (!err)
return ret_len;
return 0;
}
static int spl_mtd_load_image(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev)
{
int err;
struct image_header *header;
__maybe_unused struct spl_load_info load;
struct mtd_info *mtd;
size_t ret_len;
mtd_probe_devices();
switch (bootdev->boot_device) {
case BOOT_DEVICE_SPINAND:
mtd = get_mtd_device_nm("spi-nand0");
if (IS_ERR_OR_NULL(mtd)) {
printf("MTD device %s not found, ret %ld\n", "spi-nand",
PTR_ERR(mtd));
err = PTR_ERR(mtd);
goto remove_mtd_device;
}
break;
default:
puts(SPL_TPL_PROMPT "Unsupported MTD Boot Device!\n");
err = -EINVAL;
goto remove_mtd_device;
}
header = spl_get_load_buffer(0, sizeof(*header));
err = mtd_read(mtd, spl_mtd_get_uboot_offs(), sizeof(*header),
&ret_len, (void *)header);
if (err)
goto remove_mtd_device;
if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
image_get_magic(header) == FDT_MAGIC) {
debug("Found FIT\n");
load.dev = mtd;
load.priv = NULL;
load.filename = NULL;
load.bl_len = 1;
load.read = spl_mtd_fit_read;
err = spl_load_simple_fit(spl_image, &load,
spl_mtd_get_uboot_offs(), header);
} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
load.dev = mtd;
load.priv = NULL;
load.filename = NULL;
load.bl_len = 1;
load.read = spl_mtd_fit_read;
err = spl_load_imx_container(spl_image, &load,
spl_mtd_get_uboot_offs());
} else {
err = spl_parse_image_header(spl_image, header);
if (err)
goto remove_mtd_device;
err = mtd_read(mtd, spl_mtd_get_uboot_offs(), spl_image->size,
&ret_len, (void *)(ulong)spl_image->load_addr);
}
remove_mtd_device:
mtd_remove(mtd);
return err;
}
SPL_LOAD_IMAGE_METHOD("SPINAND", 0, BOOT_DEVICE_SPINAND, spl_mtd_load_image);
|