blob: 651d9fc9cb88b1c611adc379e71802c3df526fb0 [file] [log] [blame]
Siew Chin Lim612ee822021-03-15 15:59:16 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2020 Intel Corporation. All rights reserved
Tien Fong Chee43975a12025-02-18 16:34:59 +08004 * Copyright (C) 2025 Altera Corporation <www.altera.com>
Siew Chin Lim612ee822021-03-15 15:59:16 +08005 *
6 */
7
Tien Fong Chee43975a12025-02-18 16:34:59 +08008#include <hang.h>
Siew Chin Lim612ee822021-03-15 15:59:16 +08009#include <spl.h>
Tien Fong Chee43975a12025-02-18 16:34:59 +080010#include <dm/uclass.h>
Siew Chin Lim612ee822021-03-15 15:59:16 +080011
12DECLARE_GLOBAL_DATA_PTR;
13
14u32 spl_boot_device(void)
15{
16 return BOOT_DEVICE_MMC1;
17}
18
Tien Fong Chee618ae692025-02-18 16:35:09 +080019/* This function is to map specified node onto SPL boot devices */
20static int spl_node_to_boot_device(int node)
21{
22 const void *blob = gd->fdt_blob;
23 struct udevice *parent;
24 const char *prop;
25
26 if (!uclass_get_device_by_of_offset(UCLASS_MMC, node, &parent))
27 return BOOT_DEVICE_MMC1;
28 else if (!uclass_get_device_by_of_offset(UCLASS_SPI_FLASH, node, &parent))
29 return BOOT_DEVICE_SPI;
30 else if (!uclass_get_device_by_of_offset(UCLASS_MTD, node, &parent))
31 return BOOT_DEVICE_NAND;
32
33 prop = fdt_getprop(blob, node, "device_type", NULL);
34 if (prop) {
35 if (!strcmp(prop, "memory"))
36 return BOOT_DEVICE_RAM;
37
38 printf("%s: unknown device_type %s\n", __func__, prop);
39 }
40
41 return -ENODEV;
42}
43
44static void default_spl_boot_list(u32 *spl_boot_list, int length)
45{
46 spl_boot_list[0] = spl_boot_device();
47
48 if (length > 1)
49 spl_boot_list[1] = BOOT_DEVICE_SPI;
50
51 if (length > 2)
52 spl_boot_list[2] = BOOT_DEVICE_NAND;
53}
54
55void board_boot_order(u32 *spl_boot_list)
56{
57 int idx = 0;
58 const void *blob = gd->fdt_blob;
59 int chosen_node = fdt_path_offset(blob, "/chosen");
60 const char *conf;
61 int elem;
62 int boot_device;
63 int node;
64 int length;
65
66 /* expect valid initialized spl_boot_list */
67 if (!spl_boot_list)
68 return;
69
70 length = 1;
71 while (spl_boot_list[length] == spl_boot_list[length - 1])
72 length++;
73
74 debug("%s: chosen_node is %d\n", __func__, chosen_node);
75 if (chosen_node < 0) {
76 printf("%s: /chosen not found, using default\n", __func__);
77 default_spl_boot_list(spl_boot_list, length);
78 return;
79 }
80
81 for (elem = 0;
82 (conf = fdt_stringlist_get(blob, chosen_node,
83 "u-boot,spl-boot-order", elem, NULL));
84 elem++) {
85 if (idx >= length) {
86 printf("%s: limit %d to spl_boot_list exceeded\n", __func__,
87 length);
88 break;
89 }
90
91 /* Resolve conf item as a path in device tree */
92 node = fdt_path_offset(blob, conf);
93 if (node < 0) {
94 debug("%s: could not find %s in FDT\n", __func__, conf);
95 continue;
96 }
97
98 /* Try to map spl node back onto SPL boot devices */
99 boot_device = spl_node_to_boot_device(node);
100 if (boot_device < 0) {
101 debug("%s: could not map node @%x to a boot-device\n",
102 __func__, node);
103 continue;
104 }
105
106 spl_boot_list[idx] = boot_device;
107 debug("%s: spl_boot_list[%d] = %u\n", __func__, idx,
108 spl_boot_list[idx]);
109 idx++;
110 }
111
112 if (idx == 0) {
113 if (!conf && !elem) {
114 printf("%s: spl-boot-order invalid, using default\n", __func__);
115 default_spl_boot_list(spl_boot_list, length);
116 } else {
117 printf("%s: no valid element spl-boot-order list\n", __func__);
118 }
119 }
120}
121
Simon Glassb58bfe02021-08-08 12:20:09 -0600122#if IS_ENABLED(CONFIG_SPL_MMC)
Siew Chin Lim612ee822021-03-15 15:59:16 +0800123u32 spl_boot_mode(const u32 boot_device)
124{
125 if (IS_ENABLED(CONFIG_SPL_FS_FAT) || IS_ENABLED(CONFIG_SPL_FS_EXT4))
126 return MMCSD_MODE_FS;
127 else
128 return MMCSD_MODE_RAW;
129}
130#endif
Tien Fong Chee43975a12025-02-18 16:34:59 +0800131
132/* board specific function prior loading SSBL / U-Boot */
133void spl_perform_fixups(struct spl_image_info *spl_image)
134{
135 int ret;
136 struct udevice *dev;
137
138 ret = uclass_get_device_by_name(UCLASS_NOP, "socfpga-smmu-secure-config", &dev);
139 if (ret) {
140 printf("HPS SMMU secure settings init failed: %d\n", ret);
141 hang();
142 }
143}