]> Git Repo - J-u-boot.git/blame - common/spl/spl_ext.c
common: Remove <common.h> and add needed includes
[J-u-boot.git] / common / spl / spl_ext.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
592f9222 2
7b51b576 3#include <env.h>
e6f6f9e6 4#include <part.h>
592f9222 5#include <spl.h>
b8ed7225 6#include <spl_load.h>
592f9222
GG
7#include <asm/u-boot.h>
8#include <ext4fs.h>
339245b7 9#include <errno.h>
592f9222
GG
10#include <image.h>
11
b8ed7225
SA
12static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
13 ulong size, void *buf)
14{
15 int ret;
16 loff_t actlen;
17
18 ret = ext4fs_read(buf, file_offset, size, &actlen);
19 if (ret)
20 return ret;
21 return actlen;
22}
23
b4a6c2aa 24int spl_load_image_ext(struct spl_image_info *spl_image,
2e0429bc 25 struct spl_boot_device *bootdev,
b4a6c2aa
SG
26 struct blk_desc *block_dev, int partition,
27 const char *filename)
592f9222
GG
28{
29 s32 err;
b8ed7225 30 loff_t filelen;
0528979f 31 struct disk_partition part_info = {};
b8ed7225 32 struct spl_load_info load;
592f9222 33
3e8bd469 34 if (part_get_info(block_dev, partition, &part_info)) {
592f9222
GG
35 printf("spl: no partition table found\n");
36 return -1;
37 }
38
39 ext4fs_set_blk_dev(block_dev, &part_info);
40
7667bdeb 41 err = ext4fs_mount();
592f9222
GG
42 if (!err) {
43#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
44 printf("%s: ext4fs mount err - %d\n", __func__, err);
45#endif
ea5003ad 46 return -1;
592f9222
GG
47 }
48
9f12cd0e 49 err = ext4fs_open(filename, &filelen);
592f9222
GG
50 if (err < 0) {
51 puts("spl: ext4fs_open failed\n");
52 goto end;
53 }
592f9222 54
b8ed7225
SA
55 spl_set_bl_len(&load, 1);
56 load.read = spl_fit_read;
57 err = spl_load(spl_image, bootdev, &load, filelen, 0);
592f9222
GG
58
59end:
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
7115007c 69#if CONFIG_IS_ENABLED(OS_BOOT)
b4a6c2aa 70int spl_load_image_ext_os(struct spl_image_info *spl_image,
2e0429bc 71 struct spl_boot_device *bootdev,
b4a6c2aa 72 struct blk_desc *block_dev, int partition)
592f9222
GG
73{
74 int err;
9f12cd0e 75 __maybe_unused loff_t filelen, actlen;
0528979f 76 struct disk_partition part_info = {};
592f9222
GG
77 __maybe_unused char *file;
78
3e8bd469 79 if (part_get_info(block_dev, partition, &part_info)) {
592f9222
GG
80 printf("spl: no partition table found\n");
81 return -1;
82 }
83
84 ext4fs_set_blk_dev(block_dev, &part_info);
85
7667bdeb 86 err = ext4fs_mount();
592f9222
GG
87 if (!err) {
88#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
89 printf("%s: ext4fs mount err - %d\n", __func__, err);
90#endif
91 return -1;
92 }
58c95d53 93#if defined(CONFIG_SPL_ENV_SUPPORT)
00caae6d 94 file = env_get("falcon_args_file");
592f9222 95 if (file) {
9f12cd0e 96 err = ext4fs_open(file, &filelen);
592f9222
GG
97 if (err < 0) {
98 puts("spl: ext4fs_open failed\n");
99 goto defaults;
100 }
9cbdc3a0 101 err = ext4fs_read((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, 0, filelen, &actlen);
d3e488ea 102 if (err < 0) {
592f9222
GG
103 printf("spl: error reading image %s, err - %d, falling back to default\n",
104 file, err);
105 goto defaults;
106 }
00caae6d 107 file = env_get("falcon_image_file");
592f9222 108 if (file) {
2e0429bc 109 err = spl_load_image_ext(spl_image, bootdev, block_dev,
b4a6c2aa 110 partition, file);
592f9222
GG
111 if (err != 0) {
112 puts("spl: falling back to default\n");
113 goto defaults;
114 }
115
116 return 0;
117 } else {
118 puts("spl: falcon_image_file not set in environment, falling back to default\n");
119 }
120 } else {
121 puts("spl: falcon_args_file not set in environment, falling back to default\n");
122 }
123
124defaults:
125#endif
126
9f12cd0e 127 err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME, &filelen);
592f9222
GG
128 if (err < 0)
129 puts("spl: ext4fs_open failed\n");
130
9cbdc3a0 131 err = ext4fs_read((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR, 0, filelen, &actlen);
d3e488ea 132 if (err < 0) {
592f9222
GG
133#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
134 printf("%s: error reading image %s, err - %d\n",
135 __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err);
136#endif
137 return -1;
138 }
139
2e0429bc 140 return spl_load_image_ext(spl_image, bootdev, block_dev, partition,
592f9222
GG
141 CONFIG_SPL_FS_LOAD_KERNEL_NAME);
142}
339245b7 143#else
b4a6c2aa 144int spl_load_image_ext_os(struct spl_image_info *spl_image,
2e0429bc 145 struct spl_boot_device *bootdev,
b4a6c2aa 146 struct blk_desc *block_dev, int partition)
339245b7
NK
147{
148 return -ENOSYS;
149}
592f9222 150#endif
This page took 0.379724 seconds and 4 git commands to generate.