Skip to content

Commit fdf916b

Browse files
kahjingl90Alif Zakuan Yuslaimi
authored andcommitted
arch: arm: rsu: Multiboot selection Uboot SSBL for RSU (MMC)
Use different Uboot in MMC for each RSU bitstream based on the SPL. Selection is based on the current partition of the running SPL. Based on the SPL partition, multiboot will search for uboot-proper name in MMC to load. E.g: P1 SPL will select u-boot_P1.itb from MMC to load Signed-off-by: Kah Jing Lee <kah.jing.lee@intel.com>
1 parent 0da563d commit fdf916b

File tree

5 files changed

+268
-41
lines changed

5 files changed

+268
-41
lines changed

arch/arm/mach-socfpga/include/mach/rsu_spl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define _RSU_S10_SPL_H_
99
#include <asm/arch/rsu_s10.h>
1010

11-
u32 rsu_spl_ssbl_address(void);
12-
u32 rsu_spl_ssbl_size(void);
11+
u32 rsu_spl_ssbl_address(bool is_qspi_imge_check);
12+
u32 rsu_spl_ssbl_size(bool is_qspi_imge_check);
1313

1414
#endif /* _RSU_S10_SPL__H_ */

arch/arm/mach-socfpga/rsu_spl.c

Lines changed: 166 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2022 Intel Corporation <www.intel.com>
44
*
55
*/
6+
#define DEBUG
67
#include <common.h>
78
#include <linux/errno.h>
89
#include <spi.h>
@@ -15,20 +16,24 @@
1516
#define SSBL_PART_PREFIX"SSBL."
1617
#define RSU_ADDR_MASK0xFFFFFFFF
1718
#define RSU_ADDR_SHIFT32
19+
#define SSBL_PART_PREFIX "SSBL."
20+
#define UBOOT_ENV_EXT ".env"
21+
#define UBOOT_IMG_EXT ".img"
22+
#define UBOOT_ITB_EXT ".itb"
23+
#define UBOOT_ENV_PREFIX "uboot_"
24+
#define UBOOT_ENV_REDUND_PREFIX "uboot-redund_"
25+
#define UBOOT_PREFIX "u-boot_"
26+
#define FACTORY_IMG_NAME "FACTORY_IM"
1827

19-
static int get_ssbl_slot(struct socfpga_rsu_s10_spt_slot *rsu_ssbl_slot)
28+
static int get_spl_slot(struct socfpga_rsu_s10_spt *rsu_spt,
29+
size_t rsu_spt_size, int *crt_spt_index)
2030
{
21-
struct socfpga_rsu_s10_spt rsu_spt = {0};
2231
u32 rsu_spt0_offset = 0, rsu_spt1_offset = 0;
23-
u32 spt_offset[4];
24-
struct rsu_status_info rsu_status;
25-
int crt_spt_index = -EINVAL;
26-
char *result;
32+
u32 spt_offset[4] = {0};
33+
struct rsu_status_info rsu_status = {0};
2734
struct spi_flash *flash;
2835
int i;
2936

30-
rsu_ssbl_slot->offset[0] = -EINVAL;
31-
3237
/* get rsu status */
3338
if (mbox_rsu_status((u32 *)&rsu_status, sizeof(rsu_status) / 4)) {
3439
puts("RSU: Error - mbox_rsu_status failed!\n");
@@ -55,23 +60,23 @@ static int get_ssbl_slot(struct socfpga_rsu_s10_spt_slot *rsu_ssbl_slot)
5560
}
5661

5762
/* read spt0 */
58-
if (spi_flash_read(flash, rsu_spt0_offset, sizeof(rsu_spt), &rsu_spt)) {
63+
if (spi_flash_read(flash, rsu_spt0_offset, rsu_spt_size, rsu_spt)) {
5964
puts("RSU: Error - spi_flash_read failed!\n");
6065
return -EINVAL;
6166
}
6267

6368
/* if spt0 does not have the correct magic number */
64-
if (rsu_spt.magic_number != RSU_S10_SPT_MAGIC_NUMBER) {
69+
if (rsu_spt->magic_number != RSU_S10_SPT_MAGIC_NUMBER) {
6570
/* read spt1 */
66-
if (spi_flash_read(flash, rsu_spt1_offset, sizeof(rsu_spt), &rsu_spt)) {
71+
if (spi_flash_read(flash, rsu_spt1_offset, rsu_spt_size, rsu_spt)) {
6772
printf("RSU: Error - spi_flash_read failed!\n");
6873
return -EINVAL;
6974
}
7075

7176
/* bail out if spt1 does not have the correct magic number */
72-
if (rsu_spt.magic_number != RSU_S10_SPT_MAGIC_NUMBER) {
77+
if (rsu_spt->magic_number != RSU_S10_SPT_MAGIC_NUMBER) {
7378
printf("RSU: Error: spt table magic number not match 0x%08x!\n",
74-
rsu_spt.magic_number);
79+
rsu_spt->magic_number);
7580
return -EINVAL;
7681
}
7782
}
@@ -83,24 +88,38 @@ static int get_ssbl_slot(struct socfpga_rsu_s10_spt_slot *rsu_ssbl_slot)
8388
debug("RSU error details: 0x%08x\n", rsu_status.error_details);
8489

8590
/* display partitions */
86-
for (i = 0; i < rsu_spt.entries; i++) {
91+
for (i = 0; i < rsu_spt->entries; i++) {
8792
debug("RSU: Partition '%s' start=0x%08x length=0x%08x\n",
88-
rsu_spt.spt_slot[i].name, rsu_spt.spt_slot[i].offset[0],
89-
rsu_spt.spt_slot[i].length);
93+
rsu_spt->spt_slot[i].name, rsu_spt->spt_slot[i].offset[0],
94+
rsu_spt->spt_slot[i].length);
9095
}
9196

9297
/* locate the SPT entry for currently loaded image */
93-
for (i = 0; i < rsu_spt.entries; i++) {
98+
for (i = 0; i < rsu_spt->entries; i++) {
9499
if (((rsu_status.current_image & RSU_ADDR_MASK) ==
95-
rsu_spt.spt_slot[i].offset[0]) &&
100+
rsu_spt->spt_slot[i].offset[0]) &&
96101
((rsu_status.current_image >> RSU_ADDR_SHIFT) ==
97-
rsu_spt.spt_slot[i].offset[1])) {
98-
crt_spt_index = i;
99-
break;
102+
rsu_spt->spt_slot[i].offset[1])) {
103+
*crt_spt_index = i;
104+
return 0;
100105
}
101106
}
102107

103-
if (crt_spt_index == -EINVAL) {
108+
puts("RSU: Error - could not locate SPL partition in the SPT table!\n");
109+
return -EINVAL;
110+
}
111+
112+
static int get_ssbl_slot(struct socfpga_rsu_s10_spt_slot *rsu_ssbl_slot)
113+
{
114+
struct socfpga_rsu_s10_spt rsu_spt = {0};
115+
int crt_spt_index = -EINVAL;
116+
char *result;
117+
int i, ret;
118+
119+
rsu_ssbl_slot->offset[0] = -EINVAL;
120+
121+
ret = get_spl_slot(&rsu_spt, sizeof(rsu_spt), &crt_spt_index);
122+
if (ret) {
104123
puts("RSU: Error - could not locate partition in the SPT table!\n");
105124
return -EINVAL;
106125
}
@@ -121,7 +140,8 @@ static int get_ssbl_slot(struct socfpga_rsu_s10_spt_slot *rsu_ssbl_slot)
121140

122141
/* compare SPL's spt name after the prefix */
123142
if (!strncmp(result, rsu_spt.spt_slot[crt_spt_index].name,
124-
MAX_PART_NAME_LENGTH - strlen(SSBL_PART_PREFIX))) {
143+
MAX_PART_NAME_LENGTH - strlen(SSBL_PART_PREFIX)) ||
144+
!strncmp(result, FACTORY_IMG_NAME, strlen(FACTORY_IMG_NAME))) {
125145
printf("RSU: found SSBL partition %s at address 0x%08x.\n",
126146
result, (int)rsu_spt.spt_slot[i].offset[0]);
127147
memcpy(rsu_ssbl_slot, &rsu_spt.spt_slot[i],
@@ -139,7 +159,100 @@ static int get_ssbl_slot(struct socfpga_rsu_s10_spt_slot *rsu_ssbl_slot)
139159
return -EINVAL;
140160
}
141161

142-
u32 rsu_spl_ssbl_address(void)
162+
int rsu_spl_mmc_filename(char *filename, int max_size)
163+
{
164+
struct socfpga_rsu_s10_spt rsu_spt = {0};
165+
int crt_spt_index = -EINVAL;
166+
int ret, len;
167+
168+
if (!filename) {
169+
printf("RSU: filename is NULL!\n");
170+
return -ENOENT;
171+
}
172+
173+
if ((strlen(UBOOT_PREFIX) + MAX_PART_NAME_LENGTH + strlen(UBOOT_ITB_EXT))
174+
> max_size)
175+
return -ENAMETOOLONG;
176+
177+
ret = get_spl_slot(&rsu_spt, sizeof(rsu_spt), &crt_spt_index);
178+
if (ret) {
179+
if (ret == -EOPNOTSUPP) {
180+
puts("RSU: Error - mbox_rsu_status failed! Check for RSU image.\n");
181+
return -EOPNOTSUPP;
182+
}
183+
184+
/* should throw error if cannot find u-boot proper(SSBL) in MMC */
185+
panic("ERROR: could not find u-boot proper(SSBL): SSBL.%s!",
186+
rsu_spt.spt_slot[crt_spt_index].name);
187+
}
188+
189+
/* add 1 to the length to copy for NULL terminated string */
190+
strlcat(filename, UBOOT_PREFIX, strlen(UBOOT_PREFIX) + 1);
191+
strlcat(filename + strlen(UBOOT_PREFIX),
192+
rsu_spt.spt_slot[crt_spt_index].name,
193+
strlen(rsu_spt.spt_slot[crt_spt_index].name) + 1);
194+
len = strlen(UBOOT_PREFIX) + strlen(rsu_spt.spt_slot[crt_spt_index].name);
195+
#if IS_ENABLED(CONFIG_SPL_LOAD_FIT)
196+
strlcat(filename + len,
197+
UBOOT_ITB_EXT, strlen(UBOOT_ITB_EXT) + 1);
198+
#else
199+
strlcat(filename + len,
200+
UBOOT_IMG_EXT, strlen(UBOOT_IMG_EXT) + 1);
201+
#endif
202+
printf("%s, filename: %s\n", __func__, filename);
203+
return 0;
204+
}
205+
206+
int rsu_spl_mmc_env_name(char *filename, int max_size, bool redund)
207+
{
208+
struct socfpga_rsu_s10_spt rsu_spt = {0};
209+
int crt_spt_index = -EINVAL;
210+
int ret, len;
211+
212+
if (!filename) {
213+
printf("RSU: filename is NULL!\n");
214+
return -ENOENT;
215+
}
216+
217+
if ((strlen(UBOOT_ENV_REDUND_PREFIX) + strlen(UBOOT_ENV_PREFIX) +
218+
MAX_PART_NAME_LENGTH + strlen(UBOOT_ENV_EXT)) > max_size)
219+
return -ENAMETOOLONG;
220+
221+
ret = get_spl_slot(&rsu_spt, sizeof(rsu_spt), &crt_spt_index);
222+
if (ret) {
223+
if (ret == -EOPNOTSUPP) {
224+
puts("RSU: Error - mbox_rsu_status failed! Check for RSU image.\n");
225+
return -EOPNOTSUPP;
226+
}
227+
228+
/* should throw error if cannot find u-boot proper(SSBL) in MMC */
229+
printf("ERROR: could not find u-boot.env!");
230+
return ret;
231+
}
232+
233+
if (redund) {
234+
strlcat(filename, UBOOT_ENV_REDUND_PREFIX,
235+
strlen(UBOOT_ENV_REDUND_PREFIX) + 1);
236+
strlcat(filename + strlen(UBOOT_ENV_REDUND_PREFIX),
237+
rsu_spt.spt_slot[crt_spt_index].name,
238+
strlen(rsu_spt.spt_slot[crt_spt_index].name) + 1);
239+
len = strlen(UBOOT_ENV_REDUND_PREFIX) +
240+
strlen(rsu_spt.spt_slot[crt_spt_index].name);
241+
} else {
242+
strlcat(filename, UBOOT_ENV_PREFIX, strlen(UBOOT_ENV_PREFIX) + 1);
243+
strlcat(filename + strlen(UBOOT_ENV_PREFIX),
244+
rsu_spt.spt_slot[crt_spt_index].name,
245+
strlen(rsu_spt.spt_slot[crt_spt_index].name) + 1);
246+
len = strlen(UBOOT_ENV_PREFIX) +
247+
strlen(rsu_spt.spt_slot[crt_spt_index].name);
248+
}
249+
strlcat(filename + len, UBOOT_ENV_EXT, strlen(UBOOT_ENV_EXT) + 1);
250+
251+
printf("%s, filename: %s\n", __func__, filename);
252+
return 0;
253+
}
254+
255+
u32 rsu_spl_ssbl_address(bool is_qspi_imge_check)
143256
{
144257
int ret;
145258
struct socfpga_rsu_s10_spt_slot rsu_ssbl_slot = {0};
@@ -152,33 +265,53 @@ u32 rsu_spl_ssbl_address(void)
152265
}
153266

154267
/* should throw error if cannot find u-boot proper(SSBL) address */
155-
panic("ERROR: could not find u-boot proper(SSBL) address!");
268+
if (is_qspi_imge_check) {
269+
panic("ERROR: could not find u-boot proper(SSBL) address!");
270+
} else {
271+
printf("ERROR: could not find u-boot env address!");
272+
return ret;
273+
}
156274
}
157275

158-
printf("RSU: Success found SSBL at offset: %08x.\n", rsu_ssbl_slot.offset[0]);
276+
printf("RSU: Success found SSBL at offset: %08x.\n",
277+
rsu_ssbl_slot.offset[0]);
159278
return rsu_ssbl_slot.offset[0];
160279
}
161280

162-
u32 rsu_spl_ssbl_size(void)
281+
u32 rsu_spl_ssbl_size(bool is_qspi_imge_check)
163282
{
283+
int ret;
164284
struct socfpga_rsu_s10_spt_slot rsu_ssbl_slot = {0};
165285

166286
/* check for valid u-boot proper(SSBL) address for the size */
167-
if (get_ssbl_slot(&rsu_ssbl_slot) == -EOPNOTSUPP) {
168-
printf("ERROR: Invalid address, could not retrieve SSBL size!");
169-
return 0;
287+
ret = get_ssbl_slot(&rsu_ssbl_slot);
288+
if (ret) {
289+
if (ret == -EOPNOTSUPP) {
290+
printf("ERROR: Invalid address, could not retrieve SSBL size!");
291+
return 0;
292+
}
293+
294+
/* should throw error if cannot find u-boot proper(SSBL) address */
295+
if (is_qspi_imge_check) {
296+
panic("ERROR: could not find u-boot proper(SSBL) address!");
297+
} else {
298+
printf("ERROR: could not find u-boot env address!");
299+
return ret;
300+
}
170301
}
171302

172303
if (!rsu_ssbl_slot.length) {
173304
/* throw error if cannot find u-boot proper(SSBL) size */
174-
panic("ERROR: could not retrieve u-boot proper(SSBL) size!");
305+
printf("ERROR: could not retrieve u-boot proper(SSBL) size!");
306+
return ret;
175307
}
176308

177-
printf("RSU: Success found SSBL with length: %08x.\n", rsu_ssbl_slot.length);
309+
printf("RSU: Success found SSBL with length: %08x.\n",
310+
rsu_ssbl_slot.length);
178311
return rsu_ssbl_slot.length;
179312
}
180313

181314
unsigned int spl_spi_get_uboot_offs(struct spi_flash *flash)
182315
{
183-
return rsu_spl_ssbl_address();
316+
return rsu_spl_ssbl_address(true);
184317
}

common/spl/spl_mmc.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,38 @@ int spl_mmc_load(struct spl_image_info *spl_image,
429429
return ret;
430430
}
431431

432+
__weak int rsu_spl_mmc_filename(char *filename, int max_size)
433+
{
434+
return -ENOENT;
435+
}
436+
432437
int spl_mmc_load_image(struct spl_image_info *spl_image,
433438
struct spl_boot_device *bootdev)
434439
{
440+
#if IS_ENABLED(CONFIG_SOCFPGA_RSU_MULTIBOOT)
441+
const char *file;
442+
char filename[SZ_256] = {0};
443+
int ret;
444+
445+
ret = rsu_spl_mmc_filename(filename, SZ_256);
446+
if (ret) {
447+
printf("RSU: Multiboot filename is not found\n");
448+
return ret;
449+
}
450+
451+
file = filename;
452+
printf("%s: Boot from filename: %s\n", __func__, filename);
453+
#endif
435454
return spl_mmc_load(spl_image, bootdev,
455+
#if IS_ENABLED(CONFIG_SOCFPGA_RSU_MULTIBOOT)
456+
file,
457+
#else
436458
#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
437459
CONFIG_SPL_FS_LOAD_PAYLOAD_NAME,
438460
#else
439461
NULL,
440462
#endif
463+
#endif
441464
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
442465
spl_mmc_boot_partition(bootdev->boot_device),
443466
#else

0 commit comments

Comments
 (0)