]> Git Repo - J-u-boot.git/blame - common/spl/spl_ext.c
fs: yaffs2: Finish Kconfig migration
[J-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>
e6f6f9e6 5#include <part.h>
592f9222
GG
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
12int 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;
0528979f 19 struct disk_partition part_info = {};
592f9222 20
04ce5427 21 header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
592f9222 22
3e8bd469 23 if (part_get_info(block_dev, partition, &part_info)) {
592f9222
GG
24 printf("spl: no partition table found\n");
25 return -1;
26 }
27
28 ext4fs_set_blk_dev(block_dev, &part_info);
29
30 err = ext4fs_mount(0);
31 if (!err) {
32#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
33 printf("%s: ext4fs mount err - %d\n", __func__, err);
34#endif
ea5003ad 35 return -1;
592f9222
GG
36 }
37
9f12cd0e 38 err = ext4fs_open(filename, &filelen);
592f9222
GG
39 if (err < 0) {
40 puts("spl: ext4fs_open failed\n");
41 goto end;
42 }
66a47ff2 43 err = ext4fs_read((char *)header, 0, sizeof(struct image_header), &actlen);
d3e488ea 44 if (err < 0) {
592f9222
GG
45 puts("spl: ext4fs_read failed\n");
46 goto end;
47 }
48
b4a6c2aa 49 err = spl_parse_image_header(spl_image, header);
7e0f2267 50 if (err < 0) {
9ab165d8 51 puts("spl: ext: failed to parse image header\n");
7e0f2267
MV
52 goto end;
53 }
592f9222 54
66a47ff2 55 err = ext4fs_read((char *)spl_image->load_addr, 0, filelen, &actlen);
592f9222
GG
56
57end:
58#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
d3e488ea 59 if (err < 0)
592f9222
GG
60 printf("%s: error reading image %s, err - %d\n",
61 __func__, filename, err);
62#endif
63
d3e488ea 64 return err < 0;
592f9222
GG
65}
66
67#ifdef CONFIG_SPL_OS_BOOT
b4a6c2aa
SG
68int spl_load_image_ext_os(struct spl_image_info *spl_image,
69 struct blk_desc *block_dev, int partition)
592f9222
GG
70{
71 int err;
9f12cd0e 72 __maybe_unused loff_t filelen, actlen;
0528979f 73 struct disk_partition part_info = {};
592f9222
GG
74 __maybe_unused char *file;
75
3e8bd469 76 if (part_get_info(block_dev, partition, &part_info)) {
592f9222
GG
77 printf("spl: no partition table found\n");
78 return -1;
79 }
80
81 ext4fs_set_blk_dev(block_dev, &part_info);
82
83 err = ext4fs_mount(0);
84 if (!err) {
85#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
86 printf("%s: ext4fs mount err - %d\n", __func__, err);
87#endif
88 return -1;
89 }
58c95d53 90#if defined(CONFIG_SPL_ENV_SUPPORT)
00caae6d 91 file = env_get("falcon_args_file");
592f9222 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 }
66a47ff2 98 err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, 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 }
00caae6d 104 file = env_get("falcon_image_file");
592f9222 105 if (file) {
b4a6c2aa
SG
106 err = spl_load_image_ext(spl_image, block_dev,
107 partition, file);
592f9222
GG
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
121defaults:
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
66a47ff2 128 err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, 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
b4a6c2aa 137 return spl_load_image_ext(spl_image, block_dev, partition,
592f9222
GG
138 CONFIG_SPL_FS_LOAD_KERNEL_NAME);
139}
339245b7 140#else
b4a6c2aa
SG
141int spl_load_image_ext_os(struct spl_image_info *spl_image,
142 struct blk_desc *block_dev, int partition)
339245b7
NK
143{
144 return -ENOSYS;
145}
592f9222 146#endif
This page took 0.365873 seconds and 4 git commands to generate.