]>
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 | ||
25 | if (get_partition_info(block_dev, | |
26 | partition, &part_info)) { | |
27 | printf("spl: no partition table found\n"); | |
28 | return -1; | |
29 | } | |
30 | ||
31 | ext4fs_set_blk_dev(block_dev, &part_info); | |
32 | ||
33 | err = ext4fs_mount(0); | |
34 | if (!err) { | |
35 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | |
36 | printf("%s: ext4fs mount err - %d\n", __func__, err); | |
37 | #endif | |
38 | goto end; | |
39 | } | |
40 | ||
9f12cd0e | 41 | err = ext4fs_open(filename, &filelen); |
592f9222 GG |
42 | if (err < 0) { |
43 | puts("spl: ext4fs_open failed\n"); | |
44 | goto end; | |
45 | } | |
9f12cd0e | 46 | err = ext4fs_read((char *)header, sizeof(struct image_header), &actlen); |
d3e488ea | 47 | if (err < 0) { |
592f9222 GG |
48 | puts("spl: ext4fs_read failed\n"); |
49 | goto end; | |
50 | } | |
51 | ||
52 | spl_parse_image_header(header); | |
53 | ||
9f12cd0e | 54 | err = ext4fs_read((char *)spl_image.load_addr, filelen, &actlen); |
592f9222 GG |
55 | |
56 | end: | |
57 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | |
d3e488ea | 58 | if (err < 0) |
592f9222 GG |
59 | printf("%s: error reading image %s, err - %d\n", |
60 | __func__, filename, err); | |
61 | #endif | |
62 | ||
d3e488ea | 63 | return err < 0; |
592f9222 GG |
64 | } |
65 | ||
66 | #ifdef CONFIG_SPL_OS_BOOT | |
4101f687 | 67 | int spl_load_image_ext_os(struct blk_desc *block_dev, int partition) |
592f9222 GG |
68 | { |
69 | int err; | |
9f12cd0e | 70 | __maybe_unused loff_t filelen, actlen; |
592f9222 GG |
71 | disk_partition_t part_info = {}; |
72 | __maybe_unused char *file; | |
73 | ||
74 | if (get_partition_info(block_dev, | |
75 | partition, &part_info)) { | |
76 | printf("spl: no partition table found\n"); | |
77 | return -1; | |
78 | } | |
79 | ||
80 | ext4fs_set_blk_dev(block_dev, &part_info); | |
81 | ||
82 | err = ext4fs_mount(0); | |
83 | if (!err) { | |
84 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT | |
85 | printf("%s: ext4fs mount err - %d\n", __func__, err); | |
86 | #endif | |
87 | return -1; | |
88 | } | |
89 | ||
90 | #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT) | |
91 | file = getenv("falcon_args_file"); | |
92 | if (file) { | |
9f12cd0e | 93 | err = ext4fs_open(file, &filelen); |
592f9222 GG |
94 | if (err < 0) { |
95 | puts("spl: ext4fs_open failed\n"); | |
96 | goto defaults; | |
97 | } | |
9f12cd0e | 98 | err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen); |
d3e488ea | 99 | if (err < 0) { |
592f9222 GG |
100 | printf("spl: error reading image %s, err - %d, falling back to default\n", |
101 | file, err); | |
102 | goto defaults; | |
103 | } | |
104 | file = getenv("falcon_image_file"); | |
105 | if (file) { | |
106 | err = spl_load_image_ext(block_dev, partition, file); | |
107 | if (err != 0) { | |
108 | puts("spl: falling back to default\n"); | |
109 | goto defaults; | |
110 | } | |
111 | ||
112 | return 0; | |
113 | } else { | |
114 | puts("spl: falcon_image_file not set in environment, falling back to default\n"); | |
115 | } | |
116 | } else { | |
117 | puts("spl: falcon_args_file not set in environment, falling back to default\n"); | |
118 | } | |
119 | ||
120 | defaults: | |
121 | #endif | |
122 | ||
9f12cd0e | 123 | err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME, &filelen); |
592f9222 GG |
124 | if (err < 0) |
125 | puts("spl: ext4fs_open failed\n"); | |
126 | ||
9f12cd0e | 127 | err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen); |
d3e488ea | 128 | if (err < 0) { |
592f9222 GG |
129 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
130 | printf("%s: error reading image %s, err - %d\n", | |
131 | __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err); | |
132 | #endif | |
133 | return -1; | |
134 | } | |
135 | ||
136 | return spl_load_image_ext(block_dev, partition, | |
137 | CONFIG_SPL_FS_LOAD_KERNEL_NAME); | |
138 | } | |
339245b7 | 139 | #else |
4101f687 | 140 | int spl_load_image_ext_os(struct blk_desc *block_dev, int partition) |
339245b7 NK |
141 | { |
142 | return -ENOSYS; | |
143 | } | |
592f9222 GG |
144 | #endif |
145 | #endif |