]> Git Repo - u-boot.git/blame - common/spl/spl_ext.c
env: Move env_get() to env.h
[u-boot.git] / common / spl / spl_ext.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
592f9222
GG
2
3#include <common.h>
7b51b576 4#include <env.h>
592f9222
GG
5#include <spl.h>
6#include <asm/u-boot.h>
7#include <ext4fs.h>
339245b7 8#include <errno.h>
592f9222
GG
9#include <image.h>
10
b4a6c2aa
SG
11int spl_load_image_ext(struct spl_image_info *spl_image,
12 struct blk_desc *block_dev, int partition,
13 const char *filename)
592f9222
GG
14{
15 s32 err;
16 struct image_header *header;
9f12cd0e 17 loff_t filelen, actlen;
592f9222
GG
18 disk_partition_t part_info = {};
19
04ce5427 20 header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
592f9222 21
3e8bd469 22 if (part_get_info(block_dev, partition, &part_info)) {
592f9222
GG
23 printf("spl: no partition table found\n");
24 return -1;
25 }
26
27 ext4fs_set_blk_dev(block_dev, &part_info);
28
29 err = ext4fs_mount(0);
30 if (!err) {
31#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
32 printf("%s: ext4fs mount err - %d\n", __func__, err);
33#endif
34 goto end;
35 }
36
9f12cd0e 37 err = ext4fs_open(filename, &filelen);
592f9222
GG
38 if (err < 0) {
39 puts("spl: ext4fs_open failed\n");
40 goto end;
41 }
66a47ff2 42 err = ext4fs_read((char *)header, 0, sizeof(struct image_header), &actlen);
d3e488ea 43 if (err < 0) {
592f9222
GG
44 puts("spl: ext4fs_read failed\n");
45 goto end;
46 }
47
b4a6c2aa 48 err = spl_parse_image_header(spl_image, header);
7e0f2267 49 if (err < 0) {
9ab165d8 50 puts("spl: ext: failed to parse image header\n");
7e0f2267
MV
51 goto end;
52 }
592f9222 53
66a47ff2 54 err = ext4fs_read((char *)spl_image->load_addr, 0, filelen, &actlen);
592f9222
GG
55
56end:
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
b4a6c2aa
SG
67int spl_load_image_ext_os(struct spl_image_info *spl_image,
68 struct blk_desc *block_dev, int partition)
592f9222
GG
69{
70 int err;
9f12cd0e 71 __maybe_unused loff_t filelen, actlen;
592f9222
GG
72 disk_partition_t part_info = {};
73 __maybe_unused char *file;
74
3e8bd469 75 if (part_get_info(block_dev, partition, &part_info)) {
592f9222
GG
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 }
58c95d53 89#if defined(CONFIG_SPL_ENV_SUPPORT)
00caae6d 90 file = env_get("falcon_args_file");
592f9222 91 if (file) {
9f12cd0e 92 err = ext4fs_open(file, &filelen);
592f9222
GG
93 if (err < 0) {
94 puts("spl: ext4fs_open failed\n");
95 goto defaults;
96 }
66a47ff2 97 err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, filelen, &actlen);
d3e488ea 98 if (err < 0) {
592f9222
GG
99 printf("spl: error reading image %s, err - %d, falling back to default\n",
100 file, err);
101 goto defaults;
102 }
00caae6d 103 file = env_get("falcon_image_file");
592f9222 104 if (file) {
b4a6c2aa
SG
105 err = spl_load_image_ext(spl_image, block_dev,
106 partition, file);
592f9222
GG
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
120defaults:
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
66a47ff2 127 err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, 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
b4a6c2aa 136 return spl_load_image_ext(spl_image, block_dev, partition,
592f9222
GG
137 CONFIG_SPL_FS_LOAD_KERNEL_NAME);
138}
339245b7 139#else
b4a6c2aa
SG
140int spl_load_image_ext_os(struct spl_image_info *spl_image,
141 struct blk_desc *block_dev, int partition)
339245b7
NK
142{
143 return -ENOSYS;
144}
592f9222 145#endif
This page took 0.186557 seconds and 4 git commands to generate.