]>
Commit | Line | Data |
---|---|---|
592f9222 GG |
1 | /* |
2 | * SPDX-License-Identifier: GPL-2.0+ | |
3 | */ | |
4 | ||
5 | #include <common.h> | |
6 | #include <spl.h> | |
7 | #include <asm/u-boot.h> | |
8 | #include <ext4fs.h> | |
339245b7 | 9 | #include <errno.h> |
592f9222 GG |
10 | #include <image.h> |
11 | ||
b4a6c2aa SG |
12 | int spl_load_image_ext(struct spl_image_info *spl_image, |
13 | struct blk_desc *block_dev, int partition, | |
14 | const char *filename) | |
592f9222 GG |
15 | { |
16 | s32 err; | |
17 | struct image_header *header; | |
9f12cd0e | 18 | loff_t filelen, actlen; |
592f9222 GG |
19 | disk_partition_t part_info = {}; |
20 | ||
21 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - | |
22 | sizeof(struct image_header)); | |
23 | ||
3e8bd469 | 24 | if (part_get_info(block_dev, partition, &part_info)) { |
592f9222 GG |
25 | printf("spl: no partition table found\n"); |
26 | return -1; | |
27 | } | |
28 | ||
29 | ext4fs_set_blk_dev(block_dev, &part_info); | |
30 | ||
31 | err = ext4fs_mount(0); | |
32 | if (!err) { | |
33 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | |
34 | printf("%s: ext4fs mount err - %d\n", __func__, err); | |
35 | #endif | |
36 | goto end; | |
37 | } | |
38 | ||
9f12cd0e | 39 | err = ext4fs_open(filename, &filelen); |
592f9222 GG |
40 | if (err < 0) { |
41 | puts("spl: ext4fs_open failed\n"); | |
42 | goto end; | |
43 | } | |
66a47ff2 | 44 | err = ext4fs_read((char *)header, 0, sizeof(struct image_header), &actlen); |
d3e488ea | 45 | if (err < 0) { |
592f9222 GG |
46 | puts("spl: ext4fs_read failed\n"); |
47 | goto end; | |
48 | } | |
49 | ||
b4a6c2aa | 50 | err = spl_parse_image_header(spl_image, header); |
7e0f2267 | 51 | if (err < 0) { |
9ab165d8 | 52 | puts("spl: ext: failed to parse image header\n"); |
7e0f2267 MV |
53 | goto end; |
54 | } | |
592f9222 | 55 | |
66a47ff2 | 56 | err = ext4fs_read((char *)spl_image->load_addr, 0, filelen, &actlen); |
592f9222 GG |
57 | |
58 | end: | |
59 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | |
d3e488ea | 60 | if (err < 0) |
592f9222 GG |
61 | printf("%s: error reading image %s, err - %d\n", |
62 | __func__, filename, err); | |
63 | #endif | |
64 | ||
d3e488ea | 65 | return err < 0; |
592f9222 GG |
66 | } |
67 | ||
68 | #ifdef CONFIG_SPL_OS_BOOT | |
b4a6c2aa SG |
69 | int spl_load_image_ext_os(struct spl_image_info *spl_image, |
70 | struct blk_desc *block_dev, int partition) | |
592f9222 GG |
71 | { |
72 | int err; | |
9f12cd0e | 73 | __maybe_unused loff_t filelen, actlen; |
592f9222 GG |
74 | disk_partition_t part_info = {}; |
75 | __maybe_unused char *file; | |
76 | ||
3e8bd469 | 77 | if (part_get_info(block_dev, partition, &part_info)) { |
592f9222 GG |
78 | printf("spl: no partition table found\n"); |
79 | return -1; | |
80 | } | |
81 | ||
82 | ext4fs_set_blk_dev(block_dev, &part_info); | |
83 | ||
84 | err = ext4fs_mount(0); | |
85 | if (!err) { | |
86 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | |
87 | printf("%s: ext4fs mount err - %d\n", __func__, err); | |
88 | #endif | |
89 | return -1; | |
90 | } | |
58c95d53 | 91 | #if defined(CONFIG_SPL_ENV_SUPPORT) |
00caae6d | 92 | file = env_get("falcon_args_file"); |
592f9222 | 93 | if (file) { |
9f12cd0e | 94 | err = ext4fs_open(file, &filelen); |
592f9222 GG |
95 | if (err < 0) { |
96 | puts("spl: ext4fs_open failed\n"); | |
97 | goto defaults; | |
98 | } | |
66a47ff2 | 99 | err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, filelen, &actlen); |
d3e488ea | 100 | if (err < 0) { |
592f9222 GG |
101 | printf("spl: error reading image %s, err - %d, falling back to default\n", |
102 | file, err); | |
103 | goto defaults; | |
104 | } | |
00caae6d | 105 | file = env_get("falcon_image_file"); |
592f9222 | 106 | if (file) { |
b4a6c2aa SG |
107 | err = spl_load_image_ext(spl_image, block_dev, |
108 | partition, file); | |
592f9222 GG |
109 | if (err != 0) { |
110 | puts("spl: falling back to default\n"); | |
111 | goto defaults; | |
112 | } | |
113 | ||
114 | return 0; | |
115 | } else { | |
116 | puts("spl: falcon_image_file not set in environment, falling back to default\n"); | |
117 | } | |
118 | } else { | |
119 | puts("spl: falcon_args_file not set in environment, falling back to default\n"); | |
120 | } | |
121 | ||
122 | defaults: | |
123 | #endif | |
124 | ||
9f12cd0e | 125 | err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME, &filelen); |
592f9222 GG |
126 | if (err < 0) |
127 | puts("spl: ext4fs_open failed\n"); | |
128 | ||
66a47ff2 | 129 | err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, filelen, &actlen); |
d3e488ea | 130 | if (err < 0) { |
592f9222 GG |
131 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
132 | printf("%s: error reading image %s, err - %d\n", | |
133 | __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err); | |
134 | #endif | |
135 | return -1; | |
136 | } | |
137 | ||
b4a6c2aa | 138 | return spl_load_image_ext(spl_image, block_dev, partition, |
592f9222 GG |
139 | CONFIG_SPL_FS_LOAD_KERNEL_NAME); |
140 | } | |
339245b7 | 141 | #else |
b4a6c2aa SG |
142 | int spl_load_image_ext_os(struct spl_image_info *spl_image, |
143 | struct blk_desc *block_dev, int partition) | |
339245b7 NK |
144 | { |
145 | return -ENOSYS; | |
146 | } | |
592f9222 | 147 | #endif |