]>
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 | ||
12 | #ifdef CONFIG_SPL_EXT_SUPPORT | |
4101f687 | 13 | int spl_load_image_ext(struct blk_desc *block_dev, |
592f9222 GG |
14 | int partition, |
15 | const char *filename) | |
16 | { | |
17 | s32 err; | |
18 | struct image_header *header; | |
9f12cd0e | 19 | loff_t filelen, actlen; |
592f9222 GG |
20 | disk_partition_t part_info = {}; |
21 | ||
22 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - | |
23 | sizeof(struct image_header)); | |
24 | ||
3e8bd469 | 25 | if (part_get_info(block_dev, partition, &part_info)) { |
592f9222 GG |
26 | printf("spl: no partition table found\n"); |
27 | return -1; | |
28 | } | |
29 | ||
30 | ext4fs_set_blk_dev(block_dev, &part_info); | |
31 | ||
32 | err = ext4fs_mount(0); | |
33 | if (!err) { | |
34 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | |
35 | printf("%s: ext4fs mount err - %d\n", __func__, err); | |
36 | #endif | |
37 | goto end; | |
38 | } | |
39 | ||
9f12cd0e | 40 | err = ext4fs_open(filename, &filelen); |
592f9222 GG |
41 | if (err < 0) { |
42 | puts("spl: ext4fs_open failed\n"); | |
43 | goto end; | |
44 | } | |
9f12cd0e | 45 | err = ext4fs_read((char *)header, sizeof(struct image_header), &actlen); |
d3e488ea | 46 | if (err < 0) { |
592f9222 GG |
47 | puts("spl: ext4fs_read failed\n"); |
48 | goto end; | |
49 | } | |
50 | ||
71316c1d | 51 | err = spl_parse_image_header(&spl_image, header); |
7e0f2267 | 52 | if (err < 0) { |
9ab165d8 | 53 | puts("spl: ext: failed to parse image header\n"); |
7e0f2267 MV |
54 | goto end; |
55 | } | |
592f9222 | 56 | |
9f12cd0e | 57 | err = ext4fs_read((char *)spl_image.load_addr, filelen, &actlen); |
592f9222 GG |
58 | |
59 | end: | |
60 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | |
d3e488ea | 61 | if (err < 0) |
592f9222 GG |
62 | printf("%s: error reading image %s, err - %d\n", |
63 | __func__, filename, err); | |
64 | #endif | |
65 | ||
d3e488ea | 66 | return err < 0; |
592f9222 GG |
67 | } |
68 | ||
69 | #ifdef CONFIG_SPL_OS_BOOT | |
4101f687 | 70 | int spl_load_image_ext_os(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) |
592f9222 GG |
92 | file = getenv("falcon_args_file"); |
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 | } | |
9f12cd0e | 99 | err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 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 | } | |
105 | file = getenv("falcon_image_file"); | |
106 | if (file) { | |
107 | err = spl_load_image_ext(block_dev, partition, file); | |
108 | if (err != 0) { | |
109 | puts("spl: falling back to default\n"); | |
110 | goto defaults; | |
111 | } | |
112 | ||
113 | return 0; | |
114 | } else { | |
115 | puts("spl: falcon_image_file not set in environment, falling back to default\n"); | |
116 | } | |
117 | } else { | |
118 | puts("spl: falcon_args_file not set in environment, falling back to default\n"); | |
119 | } | |
120 | ||
121 | defaults: | |
122 | #endif | |
123 | ||
9f12cd0e | 124 | err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME, &filelen); |
592f9222 GG |
125 | if (err < 0) |
126 | puts("spl: ext4fs_open failed\n"); | |
127 | ||
9f12cd0e | 128 | err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen); |
d3e488ea | 129 | if (err < 0) { |
592f9222 GG |
130 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
131 | printf("%s: error reading image %s, err - %d\n", | |
132 | __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err); | |
133 | #endif | |
134 | return -1; | |
135 | } | |
136 | ||
137 | return spl_load_image_ext(block_dev, partition, | |
138 | CONFIG_SPL_FS_LOAD_KERNEL_NAME); | |
139 | } | |
339245b7 | 140 | #else |
4101f687 | 141 | int spl_load_image_ext_os(struct blk_desc *block_dev, int partition) |
339245b7 NK |
142 | { |
143 | return -ENOSYS; | |
144 | } | |
592f9222 GG |
145 | #endif |
146 | #endif |