Commit d3e488eaf48c49980adb8509a76f8577b1cf2599

Authored by Guillaume GARDET
Committed by Tom Rini
1 parent 878cd63e02

spl: Fix SPL EXT support

Commit 9f12cd0e062614e19734b2ab37842d387457c5e5 has broken SPL EXT support.
This patch update error code check to get SPL EXT support working again.

Tested on a Pandaboard (rev. A3).

Reviewed-by: Suriyan Ramasami <suriyan.r@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@ti.com>

Showing 1 changed file with 5 additions and 5 deletions Inline Diff

common/spl/spl_ext.c
1 /* 1 /*
2 * SPDX-License-Identifier: GPL-2.0+ 2 * SPDX-License-Identifier: GPL-2.0+
3 */ 3 */
4 4
5 #include <common.h> 5 #include <common.h>
6 #include <spl.h> 6 #include <spl.h>
7 #include <asm/u-boot.h> 7 #include <asm/u-boot.h>
8 #include <ext4fs.h> 8 #include <ext4fs.h>
9 #include <image.h> 9 #include <image.h>
10 10
11 #ifdef CONFIG_SPL_EXT_SUPPORT 11 #ifdef CONFIG_SPL_EXT_SUPPORT
12 int spl_load_image_ext(block_dev_desc_t *block_dev, 12 int spl_load_image_ext(block_dev_desc_t *block_dev,
13 int partition, 13 int partition,
14 const char *filename) 14 const char *filename)
15 { 15 {
16 s32 err; 16 s32 err;
17 struct image_header *header; 17 struct image_header *header;
18 loff_t filelen, actlen; 18 loff_t filelen, actlen;
19 disk_partition_t part_info = {}; 19 disk_partition_t part_info = {};
20 20
21 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - 21 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
22 sizeof(struct image_header)); 22 sizeof(struct image_header));
23 23
24 if (get_partition_info(block_dev, 24 if (get_partition_info(block_dev,
25 partition, &part_info)) { 25 partition, &part_info)) {
26 printf("spl: no partition table found\n"); 26 printf("spl: no partition table found\n");
27 return -1; 27 return -1;
28 } 28 }
29 29
30 ext4fs_set_blk_dev(block_dev, &part_info); 30 ext4fs_set_blk_dev(block_dev, &part_info);
31 31
32 err = ext4fs_mount(0); 32 err = ext4fs_mount(0);
33 if (!err) { 33 if (!err) {
34 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 34 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
35 printf("%s: ext4fs mount err - %d\n", __func__, err); 35 printf("%s: ext4fs mount err - %d\n", __func__, err);
36 #endif 36 #endif
37 goto end; 37 goto end;
38 } 38 }
39 39
40 err = ext4fs_open(filename, &filelen); 40 err = ext4fs_open(filename, &filelen);
41 if (err < 0) { 41 if (err < 0) {
42 puts("spl: ext4fs_open failed\n"); 42 puts("spl: ext4fs_open failed\n");
43 goto end; 43 goto end;
44 } 44 }
45 err = ext4fs_read((char *)header, sizeof(struct image_header), &actlen); 45 err = ext4fs_read((char *)header, sizeof(struct image_header), &actlen);
46 if (err <= 0) { 46 if (err < 0) {
47 puts("spl: ext4fs_read failed\n"); 47 puts("spl: ext4fs_read failed\n");
48 goto end; 48 goto end;
49 } 49 }
50 50
51 spl_parse_image_header(header); 51 spl_parse_image_header(header);
52 52
53 err = ext4fs_read((char *)spl_image.load_addr, filelen, &actlen); 53 err = ext4fs_read((char *)spl_image.load_addr, filelen, &actlen);
54 54
55 end: 55 end:
56 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 56 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
57 if (err <= 0) 57 if (err < 0)
58 printf("%s: error reading image %s, err - %d\n", 58 printf("%s: error reading image %s, err - %d\n",
59 __func__, filename, err); 59 __func__, filename, err);
60 #endif 60 #endif
61 61
62 return err <= 0; 62 return err < 0;
63 } 63 }
64 64
65 #ifdef CONFIG_SPL_OS_BOOT 65 #ifdef CONFIG_SPL_OS_BOOT
66 int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition) 66 int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition)
67 { 67 {
68 int err; 68 int err;
69 __maybe_unused loff_t filelen, actlen; 69 __maybe_unused loff_t filelen, actlen;
70 disk_partition_t part_info = {}; 70 disk_partition_t part_info = {};
71 __maybe_unused char *file; 71 __maybe_unused char *file;
72 72
73 if (get_partition_info(block_dev, 73 if (get_partition_info(block_dev,
74 partition, &part_info)) { 74 partition, &part_info)) {
75 printf("spl: no partition table found\n"); 75 printf("spl: no partition table found\n");
76 return -1; 76 return -1;
77 } 77 }
78 78
79 ext4fs_set_blk_dev(block_dev, &part_info); 79 ext4fs_set_blk_dev(block_dev, &part_info);
80 80
81 err = ext4fs_mount(0); 81 err = ext4fs_mount(0);
82 if (!err) { 82 if (!err) {
83 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 83 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
84 printf("%s: ext4fs mount err - %d\n", __func__, err); 84 printf("%s: ext4fs mount err - %d\n", __func__, err);
85 #endif 85 #endif
86 return -1; 86 return -1;
87 } 87 }
88 88
89 #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT) 89 #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT)
90 file = getenv("falcon_args_file"); 90 file = getenv("falcon_args_file");
91 if (file) { 91 if (file) {
92 err = ext4fs_open(file, &filelen); 92 err = ext4fs_open(file, &filelen);
93 if (err < 0) { 93 if (err < 0) {
94 puts("spl: ext4fs_open failed\n"); 94 puts("spl: ext4fs_open failed\n");
95 goto defaults; 95 goto defaults;
96 } 96 }
97 err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen); 97 err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen);
98 if (err <= 0) { 98 if (err < 0) {
99 printf("spl: error reading image %s, err - %d, falling back to default\n", 99 printf("spl: error reading image %s, err - %d, falling back to default\n",
100 file, err); 100 file, err);
101 goto defaults; 101 goto defaults;
102 } 102 }
103 file = getenv("falcon_image_file"); 103 file = getenv("falcon_image_file");
104 if (file) { 104 if (file) {
105 err = spl_load_image_ext(block_dev, partition, file); 105 err = spl_load_image_ext(block_dev, partition, file);
106 if (err != 0) { 106 if (err != 0) {
107 puts("spl: falling back to default\n"); 107 puts("spl: falling back to default\n");
108 goto defaults; 108 goto defaults;
109 } 109 }
110 110
111 return 0; 111 return 0;
112 } else { 112 } else {
113 puts("spl: falcon_image_file not set in environment, falling back to default\n"); 113 puts("spl: falcon_image_file not set in environment, falling back to default\n");
114 } 114 }
115 } else { 115 } else {
116 puts("spl: falcon_args_file not set in environment, falling back to default\n"); 116 puts("spl: falcon_args_file not set in environment, falling back to default\n");
117 } 117 }
118 118
119 defaults: 119 defaults:
120 #endif 120 #endif
121 121
122 err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME, &filelen); 122 err = ext4fs_open(CONFIG_SPL_FS_LOAD_ARGS_NAME, &filelen);
123 if (err < 0) 123 if (err < 0)
124 puts("spl: ext4fs_open failed\n"); 124 puts("spl: ext4fs_open failed\n");
125 125
126 err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen); 126 err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen);
127 if (err <= 0) { 127 if (err < 0) {
128 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT 128 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
129 printf("%s: error reading image %s, err - %d\n", 129 printf("%s: error reading image %s, err - %d\n",
130 __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err); 130 __func__, CONFIG_SPL_FS_LOAD_ARGS_NAME, err);
131 #endif 131 #endif
132 return -1; 132 return -1;
133 } 133 }
134 134
135 return spl_load_image_ext(block_dev, partition, 135 return spl_load_image_ext(block_dev, partition,
136 CONFIG_SPL_FS_LOAD_KERNEL_NAME); 136 CONFIG_SPL_FS_LOAD_KERNEL_NAME);
137 } 137 }
138 #endif 138 #endif
139 #endif 139 #endif
140 140