blob: 52aa420e8c05bb6fb8fde31c8ae05d75f67d027f [file] [log] [blame]
Channagoud Kadabi571193a2014-02-05 13:58:49 -08001/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#include <libfdt.h>
30#include <dev_tree.h>
31#include <lib/ptable.h>
32#include <malloc.h>
33#include <qpic_nand.h>
34#include <stdlib.h>
35#include <string.h>
36#include <platform.h>
37#include <board.h>
Lijuan Gao9f152862014-08-18 13:45:24 +080038#include <list.h>
39#include <kernel/thread.h>
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070040
Joel Kingaa335dc2013-06-03 16:11:08 -070041struct dt_entry_v1
42{
43 uint32_t platform_id;
44 uint32_t variant_id;
45 uint32_t soc_rev;
46 uint32_t offset;
47 uint32_t size;
48};
49
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -070050static struct dt_mem_node_info mem_node;
Lijuan Gao9f152862014-08-18 13:45:24 +080051static int platform_dt_absolute_match(struct dt_entry *cur_dt_entry, struct dt_entry_node *dt_list);
52static struct dt_entry *platform_dt_match_best(struct dt_entry_node *dt_list);
53static int update_dtb_entry_node(struct dt_entry_node *dt_list, uint32_t dtb_info);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070054extern int target_is_emmc_boot(void);
55extern uint32_t target_dev_tree_mem(void *fdt, uint32_t memory_node_offset);
Deepa Dinamanic55f01b2013-05-30 14:05:56 -070056/* TODO: This function needs to be moved to target layer to check violations
57 * against all the other regions as well.
58 */
59extern int check_aboot_addr_range_overlap(uint32_t start, uint32_t size);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070060
Shashank Mittalc0f10282013-07-15 14:53:31 -070061/* Returns soc version if platform id and hardware id matches
62 otherwise return 0xFFFFFFFF */
63#define INVALID_SOC_REV_ID 0XFFFFFFFF
Lijuan Gao9f152862014-08-18 13:45:24 +080064
65/* Add function to allocate dt entry list, used for recording
66* the entry which conform to platform_dt_absolute_match()
67*/
68static struct dt_entry_node *dt_entry_list_init(void)
69{
70 struct dt_entry_node *dt_node_member = NULL;
71
72 dt_node_member = (struct dt_entry_node *)
73 malloc(sizeof(struct dt_entry_node));
74
75 ASSERT(dt_node_member);
76
77 list_clear_node(&dt_node_member->node);
78 dt_node_member->dt_entry_m = (struct dt_entry *)
79 malloc(sizeof(struct dt_entry));
80 ASSERT(dt_node_member->dt_entry_m);
81
82 memset(dt_node_member->dt_entry_m ,0 ,sizeof(struct dt_entry));
83 return dt_node_member;
84}
85
86static void insert_dt_entry_in_queue(struct dt_entry_node *dt_list, struct dt_entry_node *dt_node_member)
87{
88 list_add_tail(&dt_list->node, &dt_node_member->node);
89}
90
91static void dt_entry_list_delete(struct dt_entry_node *dt_node_member)
92{
93 if (list_in_list(&dt_node_member->node)) {
94 list_delete(&dt_node_member->node);
95 free(dt_node_member->dt_entry_m);
96 free(dt_node_member);
97 }
98}
99
100static int dev_tree_compatible(void *dtb, uint32_t dtb_size, struct dt_entry_node *dtb_list)
Dima Zavinc46f8382013-05-03 12:23:06 -0700101{
102 int root_offset;
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700103 const void *prop = NULL;
104 const char *plat_prop = NULL;
105 const char *board_prop = NULL;
Lijuan Gao9f152862014-08-18 13:45:24 +0800106 const char *pmic_prop = NULL;
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700107 char *model = NULL;
Lijuan Gao9f152862014-08-18 13:45:24 +0800108 struct dt_entry *cur_dt_entry;
109 struct dt_entry *dt_entry_array = NULL;
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700110 struct board_id *board_data = NULL;
111 struct plat_id *platform_data = NULL;
Lijuan Gao9f152862014-08-18 13:45:24 +0800112 struct pmic_id *pmic_data = NULL;
Dima Zavinc46f8382013-05-03 12:23:06 -0700113 int len;
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700114 int len_board_id;
115 int len_plat_id;
116 int min_plat_id_len = 0;
Lijuan Gao9f152862014-08-18 13:45:24 +0800117 int len_pmic_id;
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700118 uint32_t dtb_ver;
119 uint32_t num_entries = 0;
Lijuan Gao9f152862014-08-18 13:45:24 +0800120 uint32_t i, j, k, n;
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700121 uint32_t msm_data_count;
122 uint32_t board_data_count;
Lijuan Gao9f152862014-08-18 13:45:24 +0800123 uint32_t pmic_data_count;
Dima Zavinc46f8382013-05-03 12:23:06 -0700124
125 root_offset = fdt_path_offset(dtb, "/");
126 if (root_offset < 0)
127 return false;
128
129 prop = fdt_getprop(dtb, root_offset, "model", &len);
130 if (prop && len > 0) {
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700131 model = (char *) malloc(sizeof(char) * len);
132 ASSERT(model);
133 strlcpy(model, prop, len);
Dima Zavinc46f8382013-05-03 12:23:06 -0700134 } else {
vijay kumar89d36d82014-06-30 19:32:18 +0530135 dprintf(INFO, "model does not exist in device tree\n");
Dima Zavinc46f8382013-05-03 12:23:06 -0700136 }
Lijuan Gao9f152862014-08-18 13:45:24 +0800137 /* Find the pmic-id prop from DTB , if pmic-id is present then
138 * the DTB is version 3, otherwise find the board-id prop from DTB ,
139 * if board-id is present then the DTB is version 2 */
140 pmic_prop = (const char *)fdt_getprop(dtb, root_offset, "qcom,pmic-id", &len_pmic_id);
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700141 board_prop = (const char *)fdt_getprop(dtb, root_offset, "qcom,board-id", &len_board_id);
Lijuan Gao9f152862014-08-18 13:45:24 +0800142 if (pmic_prop && (len_pmic_id > 0) && board_prop && (len_board_id > 0)) {
143 if ((len_pmic_id % PMIC_ID_SIZE) || (len_board_id % BOARD_ID_SIZE))
144 {
145 dprintf(CRITICAL, "qcom,pmic-id(%d) or qcom,board-id(%d) in device tree is not a multiple of (%d %d)\n",
146 len_pmic_id, len_board_id, PMIC_ID_SIZE, BOARD_ID_SIZE);
147 return false;
148 }
149 dtb_ver = DEV_TREE_VERSION_V3;
150 min_plat_id_len = PLAT_ID_SIZE;
151 } else if (board_prop && len_board_id > 0) {
vijay kumar89d36d82014-06-30 19:32:18 +0530152 if (len_board_id % BOARD_ID_SIZE)
153 {
154 dprintf(CRITICAL, "qcom,board-id in device tree is (%d) not a multiple of (%d)\n",
155 len_board_id, BOARD_ID_SIZE);
156 return false;
157 }
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700158 dtb_ver = DEV_TREE_VERSION_V2;
159 min_plat_id_len = PLAT_ID_SIZE;
Lijuan Gao9f152862014-08-18 13:45:24 +0800160 } else {
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700161 dtb_ver = DEV_TREE_VERSION_V1;
162 min_plat_id_len = DT_ENTRY_V1_SIZE;
163 }
164
165 /* Get the msm-id prop from DTB */
166 plat_prop = (const char *)fdt_getprop(dtb, root_offset, "qcom,msm-id", &len_plat_id);
167 if (!plat_prop || len_plat_id <= 0) {
Dima Zavinc46f8382013-05-03 12:23:06 -0700168 dprintf(INFO, "qcom,msm-id entry not found\n");
169 return false;
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700170 } else if (len_plat_id % min_plat_id_len) {
171 dprintf(INFO, "qcom,msm-id in device tree is (%d) not a multiple of (%d)\n",
172 len_plat_id, min_plat_id_len);
Dima Zavinc46f8382013-05-03 12:23:06 -0700173 return false;
174 }
Dima Zavinc46f8382013-05-03 12:23:06 -0700175
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700176 /*
177 * If DTB version is '1' look for <x y z> pair in the DTB
178 * x: platform_id
179 * y: variant_id
180 * z: SOC rev
181 */
Lijuan Gao9f152862014-08-18 13:45:24 +0800182 if (dtb_ver == DEV_TREE_VERSION_V1) {
183 cur_dt_entry = (struct dt_entry *)
184 malloc(sizeof(struct dt_entry));
Dima Zavinc46f8382013-05-03 12:23:06 -0700185
Lijuan Gao9f152862014-08-18 13:45:24 +0800186 if (!cur_dt_entry) {
187 dprintf(CRITICAL, "Out of memory\n");
188 return false;
189 }
190 memset(cur_dt_entry, 0, sizeof(struct dt_entry));
191
192 while (len_plat_id) {
193 cur_dt_entry->platform_id = fdt32_to_cpu(((const struct dt_entry_v1 *)plat_prop)->platform_id);
194 cur_dt_entry->variant_id = fdt32_to_cpu(((const struct dt_entry_v1 *)plat_prop)->variant_id);
195 cur_dt_entry->soc_rev = fdt32_to_cpu(((const struct dt_entry_v1 *)plat_prop)->soc_rev);
196 cur_dt_entry->board_hw_subtype =
197 fdt32_to_cpu(((const struct dt_entry_v1 *)plat_prop)->variant_id) >> 0x18;
198 cur_dt_entry->pmic_rev[0] = board_pmic_target(0);
199 cur_dt_entry->pmic_rev[1] = board_pmic_target(1);
200 cur_dt_entry->pmic_rev[2] = board_pmic_target(2);
201 cur_dt_entry->pmic_rev[3] = board_pmic_target(3);
202 cur_dt_entry->offset = (uint32_t)dtb;
203 cur_dt_entry->size = dtb_size;
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700204
205 dprintf(SPEW, "Found an appended flattened device tree (%s - %u %u 0x%x)\n",
Lijuan Gao9f152862014-08-18 13:45:24 +0800206 *model ? model : "unknown",
207 cur_dt_entry->platform_id, cur_dt_entry->variant_id, cur_dt_entry->soc_rev);
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700208
Lijuan Gao9f152862014-08-18 13:45:24 +0800209 if (platform_dt_absolute_match(cur_dt_entry, dtb_list)) {
210 dprintf(SPEW, "Device tree exact match the board: <%u %u 0x%x> != <%u %u 0x%x>\n",
211 cur_dt_entry->platform_id,
212 cur_dt_entry->variant_id,
213 cur_dt_entry->soc_rev,
214 board_platform_id(),
215 board_hardware_id(),
216 board_soc_version());
217
218 } else {
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700219 dprintf(SPEW, "Device tree's msm_id doesn't match the board: <%u %u 0x%x> != <%u %u 0x%x>\n",
Lijuan Gao9f152862014-08-18 13:45:24 +0800220 cur_dt_entry->platform_id,
221 cur_dt_entry->variant_id,
222 cur_dt_entry->soc_rev,
223 board_platform_id(),
224 board_hardware_id(),
225 board_soc_version());
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700226 plat_prop += DT_ENTRY_V1_SIZE;
227 len_plat_id -= DT_ENTRY_V1_SIZE;
228 continue;
229 }
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700230 }
Lijuan Gao9f152862014-08-18 13:45:24 +0800231 free(cur_dt_entry);
232
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700233 }
234 /*
Lijuan Gao9f152862014-08-18 13:45:24 +0800235 * If DTB Version is '3' then we have split DTB with board & msm data & pmic
236 * populated saperately in board-id & msm-id & pmic-id prop respectively.
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700237 * Extract the data & prepare a look up table
238 */
Lijuan Gao9f152862014-08-18 13:45:24 +0800239 else if (dtb_ver == DEV_TREE_VERSION_V2 || dtb_ver == DEV_TREE_VERSION_V3) {
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700240 board_data_count = (len_board_id / BOARD_ID_SIZE);
241 msm_data_count = (len_plat_id / PLAT_ID_SIZE);
Lijuan Gao9f152862014-08-18 13:45:24 +0800242 /* If dtb version is v2.0, the pmic_data_count will be <= 0 */
243 pmic_data_count = (len_pmic_id / PMIC_ID_SIZE);
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700244
Lijuan Gao9f152862014-08-18 13:45:24 +0800245 /* If we are using dtb v3.0, then we have split board, msm & pmic data in the DTB
246 * If we are using dtb v2.0, then we have split board & msmdata in the DTB
247 */
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700248 board_data = (struct board_id *) malloc(sizeof(struct board_id) * (len_board_id / BOARD_ID_SIZE));
249 ASSERT(board_data);
250 platform_data = (struct plat_id *) malloc(sizeof(struct plat_id) * (len_plat_id / PLAT_ID_SIZE));
251 ASSERT(platform_data);
Lijuan Gao9f152862014-08-18 13:45:24 +0800252 if (dtb_ver == DEV_TREE_VERSION_V3) {
253 pmic_data = (struct pmic_id *) malloc(sizeof(struct pmic_id) * (len_pmic_id / PMIC_ID_SIZE));
254 ASSERT(pmic_data);
255 }
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700256 i = 0;
257
258 /* Extract board data from DTB */
Lijuan Gao9f152862014-08-18 13:45:24 +0800259 for(i = 0 ; i < board_data_count; i++) {
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700260 board_data[i].variant_id = fdt32_to_cpu(((struct board_id *)board_prop)->variant_id);
261 board_data[i].platform_subtype = fdt32_to_cpu(((struct board_id *)board_prop)->platform_subtype);
Lijuan Gao9f152862014-08-18 13:45:24 +0800262 /* For V2/V3 version of DTBs we have platform version field as part
263 * of variant ID, in such case the subtype will be mentioned as 0x0
264 * As the qcom, board-id = <0xSSPMPmPH, 0x0>
265 * SS -- Subtype
266 * PM -- Platform major version
267 * Pm -- Platform minor version
268 * PH -- Platform hardware CDP/MTP
269 * In such case to make it compatible with LK algorithm move the subtype
270 * from variant_id to subtype field
271 */
272 if (board_data[i].platform_subtype == 0)
273 board_data[i].platform_subtype =
274 fdt32_to_cpu(((struct board_id *)board_prop)->variant_id) >> 0x18;
275
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700276 len_board_id -= sizeof(struct board_id);
277 board_prop += sizeof(struct board_id);
278 }
279
280 /* Extract platform data from DTB */
Lijuan Gao9f152862014-08-18 13:45:24 +0800281 for(i = 0 ; i < msm_data_count; i++) {
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700282 platform_data[i].platform_id = fdt32_to_cpu(((struct plat_id *)plat_prop)->platform_id);
283 platform_data[i].soc_rev = fdt32_to_cpu(((struct plat_id *)plat_prop)->soc_rev);
284 len_plat_id -= sizeof(struct plat_id);
285 plat_prop += sizeof(struct plat_id);
286 }
287
Lijuan Gao9f152862014-08-18 13:45:24 +0800288 if (dtb_ver == DEV_TREE_VERSION_V3 && pmic_prop) {
289 /* Extract pmic data from DTB */
290 for(i = 0 ; i < pmic_data_count; i++) {
291 pmic_data[i].pmic_version[0]= fdt32_to_cpu(((struct pmic_id *)pmic_prop)->pmic_version[0]);
292 pmic_data[i].pmic_version[1]= fdt32_to_cpu(((struct pmic_id *)pmic_prop)->pmic_version[1]);
293 pmic_data[i].pmic_version[2]= fdt32_to_cpu(((struct pmic_id *)pmic_prop)->pmic_version[2]);
294 pmic_data[i].pmic_version[3]= fdt32_to_cpu(((struct pmic_id *)pmic_prop)->pmic_version[3]);
295 len_pmic_id -= sizeof(struct pmic_id);
296 pmic_prop += sizeof(struct pmic_id);
297 }
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700298
Lijuan Gao9f152862014-08-18 13:45:24 +0800299 /* We need to merge board & platform data into dt entry structure */
300 num_entries = msm_data_count * board_data_count * pmic_data_count;
301 } else {
302 /* We need to merge board & platform data into dt entry structure */
303 num_entries = msm_data_count * board_data_count;
304 }
vijay kumar89d36d82014-06-30 19:32:18 +0530305
Lijuan Gao9f152862014-08-18 13:45:24 +0800306 if ((((uint64_t)msm_data_count * (uint64_t)board_data_count * (uint64_t)pmic_data_count) !=
307 msm_data_count * board_data_count * pmic_data_count) ||
308 (((uint64_t)msm_data_count * (uint64_t)board_data_count) != msm_data_count * board_data_count)) {
309
310 free(board_data);
311 free(platform_data);
312 if (pmic_data)
313 free(pmic_data);
314 if (model)
315 free(model);
316 return false;
317 }
318
319 dt_entry_array = (struct dt_entry*) malloc(sizeof(struct dt_entry) * num_entries);
320 ASSERT(dt_entry_array);
321
322 /* If we have '<X>; <Y>; <Z>' as platform data & '<A>; <B>; <C>' as board data.
323 * Then dt entry should look like
324 * <X ,A >;<X, B>;<X, C>;
325 * <Y ,A >;<Y, B>;<Y, C>;
326 * <Z ,A >;<Z, B>;<Z, C>;
327 */
328 i = 0;
329 k = 0;
330 n = 0;
331 for (i = 0; i < msm_data_count; i++) {
332 for (j = 0; j < board_data_count; j++) {
333 if (dtb_ver == DEV_TREE_VERSION_V3 && pmic_prop) {
334 for (n = 0; n < pmic_data_count; n++) {
335 dt_entry_array[k].platform_id = platform_data[i].platform_id;
336 dt_entry_array[k].soc_rev = platform_data[i].soc_rev;
337 dt_entry_array[k].variant_id = board_data[j].variant_id;
338 dt_entry_array[k].board_hw_subtype = board_data[j].platform_subtype;
339 dt_entry_array[k].pmic_rev[0]= pmic_data[n].pmic_version[0];
340 dt_entry_array[k].pmic_rev[1]= pmic_data[n].pmic_version[1];
341 dt_entry_array[k].pmic_rev[2]= pmic_data[n].pmic_version[2];
342 dt_entry_array[k].pmic_rev[3]= pmic_data[n].pmic_version[3];
343 dt_entry_array[k].offset = (uint32_t)dtb;
344 dt_entry_array[k].size = dtb_size;
345 k++;
346 }
347
348 } else {
349 dt_entry_array[k].platform_id = platform_data[i].platform_id;
350 dt_entry_array[k].soc_rev = platform_data[i].soc_rev;
351 dt_entry_array[k].variant_id = board_data[j].variant_id;
352 dt_entry_array[k].board_hw_subtype = board_data[j].platform_subtype;
353 dt_entry_array[k].pmic_rev[0]= board_pmic_target(0);
354 dt_entry_array[k].pmic_rev[1]= board_pmic_target(1);
355 dt_entry_array[k].pmic_rev[2]= board_pmic_target(2);
356 dt_entry_array[k].pmic_rev[3]= board_pmic_target(3);
357 dt_entry_array[k].offset = (uint32_t)dtb;
358 dt_entry_array[k].size = dtb_size;
vijay kumar89d36d82014-06-30 19:32:18 +0530359 k++;
360 }
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700361 }
Lijuan Gao9f152862014-08-18 13:45:24 +0800362 }
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700363
Lijuan Gao9f152862014-08-18 13:45:24 +0800364 for (i=0 ;i < num_entries; i++) {
365 dprintf(SPEW, "Found an appended flattened device tree (%s - %u %u %u 0x%x)\n",
366 *model ? model : "unknown",
367 dt_entry_array[i].platform_id, dt_entry_array[i].variant_id, dt_entry_array[i].board_hw_subtype, dt_entry_array[i].soc_rev);
vijay kumar89d36d82014-06-30 19:32:18 +0530368
Lijuan Gao9f152862014-08-18 13:45:24 +0800369 if (platform_dt_absolute_match(&(dt_entry_array[i]), dtb_list)) {
370 dprintf(SPEW, "Device tree exact match the board: <%u %u %u 0x%x> == <%u %u %u 0x%x>\n",
371 dt_entry_array[i].platform_id,
372 dt_entry_array[i].variant_id,
373 dt_entry_array[i].soc_rev,
374 dt_entry_array[i].board_hw_subtype,
375 board_platform_id(),
376 board_hardware_id(),
377 board_hardware_subtype(),
378 board_soc_version());
vijay kumar89d36d82014-06-30 19:32:18 +0530379
Lijuan Gao9f152862014-08-18 13:45:24 +0800380 } else {
381 dprintf(SPEW, "Device tree's msm_id doesn't match the board: <%u %u %u 0x%x> != <%u %u %u 0x%x>\n",
382 dt_entry_array[i].platform_id,
383 dt_entry_array[i].variant_id,
384 dt_entry_array[i].soc_rev,
385 dt_entry_array[i].board_hw_subtype,
386 board_platform_id(),
387 board_hardware_id(),
388 board_hardware_subtype(),
389 board_soc_version());
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700390 }
391 }
Lijuan Gao9f152862014-08-18 13:45:24 +0800392
393 free(board_data);
394 free(platform_data);
395 if (pmic_data)
396 free(pmic_data);
397 free(dt_entry_array);
Dima Zavinc46f8382013-05-03 12:23:06 -0700398 }
Lijuan Gao9f152862014-08-18 13:45:24 +0800399 if (model)
vijay kumar89d36d82014-06-30 19:32:18 +0530400 free(model);
Lijuan Gao9f152862014-08-18 13:45:24 +0800401 return true;
Dima Zavinc46f8382013-05-03 12:23:06 -0700402}
403
Channagoud Kadabi11682e92013-02-28 11:21:46 -0800404/*
Dima Zavin77e41f32013-03-06 16:10:43 -0800405 * Will relocate the DTB to the tags addr if the device tree is found and return
406 * its address
407 *
408 * Arguments: kernel - Start address of the kernel loaded in RAM
409 * tags - Start address of the tags loaded in RAM
Channagoud Kadabi704cd562013-04-25 15:19:59 -0700410 * kernel_size - Size of the kernel in bytes
411 *
Channagoud Kadabi11682e92013-02-28 11:21:46 -0800412 * Return Value: DTB address : If appended device tree is found
Dima Zavin77e41f32013-03-06 16:10:43 -0800413 * 'NULL' : Otherwise
Channagoud Kadabi11682e92013-02-28 11:21:46 -0800414 */
Dima Zavinc46f8382013-05-03 12:23:06 -0700415void *dev_tree_appended(void *kernel, uint32_t kernel_size, void *tags)
Channagoud Kadabi11682e92013-02-28 11:21:46 -0800416{
Dima Zavinc46f8382013-05-03 12:23:06 -0700417 void *kernel_end = kernel + kernel_size;
Channagoud Kadabi11682e92013-02-28 11:21:46 -0800418 uint32_t app_dtb_offset = 0;
Lijuan Gao9f152862014-08-18 13:45:24 +0800419 void *dtb = NULL;
Shashank Mittalc0f10282013-07-15 14:53:31 -0700420 void *bestmatch_tag = NULL;
Lijuan Gao9f152862014-08-18 13:45:24 +0800421 struct dt_entry *best_match_dt_entry = NULL;
Shashank Mittalc0f10282013-07-15 14:53:31 -0700422 uint32_t bestmatch_tag_size;
Lijuan Gao9f152862014-08-18 13:45:24 +0800423 struct dt_entry_node *dt_entry_queue = NULL;
424 struct dt_entry_node *dt_node_tmp1 = NULL;
425 struct dt_entry_node *dt_node_tmp2 = NULL;
426
427
428 /* Initialize the dtb entry node*/
429 dt_entry_queue = (struct dt_entry_node *)
430 malloc(sizeof(struct dt_entry_node));
431
432 if (!dt_entry_queue) {
433 dprintf(CRITICAL, "Out of memory\n");
434 return NULL;
435 }
436 list_initialize(&dt_entry_queue->node);
437
Channagoud Kadabi11682e92013-02-28 11:21:46 -0800438
439 memcpy((void*) &app_dtb_offset, (void*) (kernel + DTB_OFFSET), sizeof(uint32_t));
Channagoud Kadabi11682e92013-02-28 11:21:46 -0800440
vijay kumare2a5ea82014-06-25 12:24:14 +0530441 if (((uintptr_t)kernel + (uintptr_t)app_dtb_offset) < (uintptr_t)kernel) {
442 return NULL;
443 }
Dima Zavinc46f8382013-05-03 12:23:06 -0700444 dtb = kernel + app_dtb_offset;
vijay kumare2a5ea82014-06-25 12:24:14 +0530445 while (((uintptr_t)dtb + sizeof(struct fdt_header)) < (uintptr_t)kernel_end) {
Dima Zavinc46f8382013-05-03 12:23:06 -0700446 struct fdt_header dtb_hdr;
447 uint32_t dtb_size;
Dima Zavin77e41f32013-03-06 16:10:43 -0800448
Dima Zavinc46f8382013-05-03 12:23:06 -0700449 /* the DTB could be unaligned, so extract the header,
450 * and operate on it separately */
451 memcpy(&dtb_hdr, dtb, sizeof(struct fdt_header));
452 if (fdt_check_header((const void *)&dtb_hdr) != 0 ||
vijay kumare2a5ea82014-06-25 12:24:14 +0530453 ((uintptr_t)dtb + (uintptr_t)fdt_totalsize((const void *)&dtb_hdr) < (uintptr_t)dtb) ||
454 ((uintptr_t)dtb + (uintptr_t)fdt_totalsize((const void *)&dtb_hdr) > (uintptr_t)kernel_end))
Dima Zavinc46f8382013-05-03 12:23:06 -0700455 break;
456 dtb_size = fdt_totalsize(&dtb_hdr);
457
vijay kumarb05eed22014-06-24 16:30:18 +0530458 if (check_aboot_addr_range_overlap(tags, dtb_size)) {
459 dprintf(CRITICAL, "Tags addresses overlap with aboot addresses.\n");
460 return NULL;
461 }
462
Lijuan Gao9f152862014-08-18 13:45:24 +0800463 dev_tree_compatible(dtb, dtb_size, dt_entry_queue);
Dima Zavinc46f8382013-05-03 12:23:06 -0700464
465 /* goto the next device tree if any */
466 dtb += dtb_size;
Channagoud Kadabi11682e92013-02-28 11:21:46 -0800467 }
Dima Zavinc46f8382013-05-03 12:23:06 -0700468
Lijuan Gao9f152862014-08-18 13:45:24 +0800469 best_match_dt_entry = platform_dt_match_best(dt_entry_queue);
470 if (best_match_dt_entry){
471 bestmatch_tag = (void *)best_match_dt_entry->offset;
472 bestmatch_tag_size = best_match_dt_entry->size;
473 dprintf(INFO, "Best match DTB tags %u/%08x/0x%08x/%x/%x/%x/%x/%x/%x/%x\n",
474 best_match_dt_entry->platform_id, best_match_dt_entry->variant_id,
475 best_match_dt_entry->board_hw_subtype, best_match_dt_entry->soc_rev,
476 best_match_dt_entry->pmic_rev[0], best_match_dt_entry->pmic_rev[1],
477 best_match_dt_entry->pmic_rev[2], best_match_dt_entry->pmic_rev[3],
478 best_match_dt_entry->offset, best_match_dt_entry->size);
479 dprintf(INFO, "Using pmic info 0x%0x/0x%x/0x%x/0x%0x for device 0x%0x/0x%x/0x%x/0x%0x\n",
480 best_match_dt_entry->pmic_rev[0], best_match_dt_entry->pmic_rev[1],
481 best_match_dt_entry->pmic_rev[2], best_match_dt_entry->pmic_rev[3],
482 board_pmic_target(0), board_pmic_target(1),
483 board_pmic_target(2), board_pmic_target(3));
484 }
485 /* free queue's memory */
486 list_for_every_entry(&dt_entry_queue->node, dt_node_tmp1, dt_node, node) {
487 dt_node_tmp2 = dt_node_tmp1->node.prev;
488 dt_entry_list_delete(dt_node_tmp1);
489 dt_node_tmp1 = dt_node_tmp2;
490 }
491
Shashank Mittalc0f10282013-07-15 14:53:31 -0700492 if(bestmatch_tag) {
Shashank Mittalc0f10282013-07-15 14:53:31 -0700493 memcpy(tags, bestmatch_tag, bestmatch_tag_size);
494 /* clear out the old DTB magic so kernel doesn't find it */
495 *((uint32_t *)(kernel + app_dtb_offset)) = 0;
496 return tags;
497 }
498
Dima Zavinc46f8382013-05-03 12:23:06 -0700499 dprintf(CRITICAL, "DTB offset is incorrect, kernel image does not have appended DTB\n");
Channagoud Kadabi11682e92013-02-28 11:21:46 -0800500
Dima Zavin77e41f32013-03-06 16:10:43 -0800501 return NULL;
Channagoud Kadabi11682e92013-02-28 11:21:46 -0800502}
503
Joel Kingaa335dc2013-06-03 16:11:08 -0700504/* Returns 0 if the device tree is valid. */
Deepa Dinamani87252952013-09-09 13:58:27 -0700505int dev_tree_validate(struct dt_table *table, unsigned int page_size, uint32_t *dt_hdr_size)
Joel Kingaa335dc2013-06-03 16:11:08 -0700506{
507 int dt_entry_size;
Channagoud Kadabid87c2772014-06-20 15:41:55 -0700508 uint64_t hdr_size;
Joel Kingaa335dc2013-06-03 16:11:08 -0700509
510 /* Validate the device tree table header */
511 if(table->magic != DEV_TREE_MAGIC) {
512 dprintf(CRITICAL, "ERROR: Bad magic in device tree table \n");
513 return -1;
514 }
515
516 if (table->version == DEV_TREE_VERSION_V1) {
517 dt_entry_size = sizeof(struct dt_entry_v1);
518 } else if (table->version == DEV_TREE_VERSION_V2) {
Lijuan Gao9f152862014-08-18 13:45:24 +0800519 dt_entry_size = sizeof(struct dt_entry_v2);
520 } else if (table->version == DEV_TREE_VERSION_V3) {
Joel Kingaa335dc2013-06-03 16:11:08 -0700521 dt_entry_size = sizeof(struct dt_entry);
522 } else {
523 dprintf(CRITICAL, "ERROR: Unsupported version (%d) in DT table \n",
524 table->version);
525 return -1;
526 }
527
Channagoud Kadabid87c2772014-06-20 15:41:55 -0700528 hdr_size = (uint64_t)table->num_entries * dt_entry_size + DEV_TREE_HEADER_SIZE;
529
Deepa Dinamani87252952013-09-09 13:58:27 -0700530 /* Roundup to page_size. */
531 hdr_size = ROUNDUP(hdr_size, page_size);
532
Channagoud Kadabid87c2772014-06-20 15:41:55 -0700533 if (hdr_size > UINT_MAX)
534 return -1;
535 else
536 *dt_hdr_size = hdr_size & UINT_MAX;
Joel Kingaa335dc2013-06-03 16:11:08 -0700537
538 return 0;
539}
540
Lijuan Gao9f152862014-08-18 13:45:24 +0800541static int platform_dt_absolute_match(struct dt_entry *cur_dt_entry, struct dt_entry_node *dt_list)
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700542{
Aparna Mallavarapu6eb30902014-05-13 17:03:10 +0530543 uint32_t cur_dt_hlos_subtype;
Lijuan Gao9f152862014-08-18 13:45:24 +0800544 uint32_t cur_dt_hw_platform;
545 uint32_t cur_dt_hw_subtype;
546 uint32_t cur_dt_msm_id;
547 dt_node *dt_node_tmp = NULL;
Channagoud Kadabi571193a2014-02-05 13:58:49 -0800548
Lijuan Gao9f152862014-08-18 13:45:24 +0800549 /* Platform-id
550 * bit no |31 24|23 16|15 0|
551 * |reserved|foundry-id|msm-id|
552 */
553 cur_dt_msm_id = (cur_dt_entry->platform_id & 0x0000ffff);
554 cur_dt_hw_platform = (cur_dt_entry->variant_id & 0x000000ff);
Lijuan Gao0621b862014-09-02 10:02:52 +0800555 cur_dt_hw_subtype = (cur_dt_entry->board_hw_subtype & 0xff);
Lijuan Gao9f152862014-08-18 13:45:24 +0800556
557
Aparna Mallavarapu6eb30902014-05-13 17:03:10 +0530558 /* Determine the bits 23:8 to check the DT with the DDR Size */
559 cur_dt_hlos_subtype = (cur_dt_entry->board_hw_subtype & 0xffff00);
Channagoud Kadabi571193a2014-02-05 13:58:49 -0800560
Lijuan Gao9f152862014-08-18 13:45:24 +0800561 /* 1. must match the msm_id, platform_hw_id, platform_subtype and DDR size
562 * soc, board major/minor, pmic major/minor must less than board info
563 * 2. find the matched DTB then return 1
564 * 3. otherwise return 0
Maria Yu2e2d2c22013-07-03 19:20:33 +0800565 */
Lijuan Gao9f152862014-08-18 13:45:24 +0800566 if((cur_dt_msm_id == (board_platform_id() & 0x0000ffff)) &&
567 (cur_dt_hw_platform == board_hardware_id()) &&
568 (cur_dt_hw_subtype == board_hardware_subtype()) &&
569 (cur_dt_hlos_subtype == target_get_hlos_subtype()) &&
570 (cur_dt_entry->soc_rev <= board_soc_version()) &&
571 ((cur_dt_entry->variant_id & 0x00ffff00) <= (board_target_id() & 0x00ffff00)) &&
572 ((cur_dt_entry->pmic_rev[0] & 0x00ffff00) <= (board_pmic_target(0) & 0x00ffff00)) &&
573 ((cur_dt_entry->pmic_rev[1] & 0x00ffff00) <= (board_pmic_target(1) & 0x00ffff00)) &&
574 ((cur_dt_entry->pmic_rev[2] & 0x00ffff00) <= (board_pmic_target(2) & 0x00ffff00)) &&
575 ((cur_dt_entry->pmic_rev[3] & 0x00ffff00) <= (board_pmic_target(3) & 0x00ffff00))) {
Maria Yu2e2d2c22013-07-03 19:20:33 +0800576
Lijuan Gao9f152862014-08-18 13:45:24 +0800577 dt_node_tmp = dt_entry_list_init();
578 memcpy((char*)dt_node_tmp->dt_entry_m,(char*)cur_dt_entry, sizeof(struct dt_entry));
579
580 dprintf(SPEW, "Add DTB entry %u/%08x/0x%08x/%x/%x/%x/%x/%x/%x/%x\n",
581 dt_node_tmp->dt_entry_m->platform_id, dt_node_tmp->dt_entry_m->variant_id,
582 dt_node_tmp->dt_entry_m->board_hw_subtype, dt_node_tmp->dt_entry_m->soc_rev,
583 dt_node_tmp->dt_entry_m->pmic_rev[0], dt_node_tmp->dt_entry_m->pmic_rev[1],
584 dt_node_tmp->dt_entry_m->pmic_rev[2], dt_node_tmp->dt_entry_m->pmic_rev[3],
585 dt_node_tmp->dt_entry_m->offset, dt_node_tmp->dt_entry_m->size);
586
587 insert_dt_entry_in_queue(dt_list, dt_node_tmp);
588 return 1;
589 }
590 return 0;
591}
592
593static int platform_dt_absolute_compat_match(struct dt_entry_node *dt_list, uint32_t dtb_info) {
594 struct dt_entry_node *dt_node_tmp1 = NULL;
595 struct dt_entry_node *dt_node_tmp2 = NULL;
596 uint32_t current_info = 0;
597 uint32_t board_info = 0;
598 uint32_t best_info = 0;
599 uint32_t current_pmic_model[4] = {0, 0, 0, 0};
600 uint32_t board_pmic_model[4] = {0, 0, 0, 0};
601 uint32_t best_pmic_model[4] = {0, 0, 0, 0};
602 uint32_t delete_current_dt = 0;
603 uint32_t i;
604
605 /* start to select the exact entry
606 * default to exact match 0, if find current DTB entry info is the same as board info,
607 * then exact match board info.
608 */
609 list_for_every_entry(&dt_list->node, dt_node_tmp1, dt_node, node) {
610 if (!dt_node_tmp1){
611 dprintf(SPEW, "Current node is the end\n");
612 break;
613 }
614 switch(dtb_info) {
615 case DTB_FOUNDRY:
616 current_info = ((dt_node_tmp1->dt_entry_m->platform_id) & 0x00ff0000);
617 board_info = board_foundry_id();
618 break;
619 case DTB_PMIC_MODEL:
620 for (i = 0; i < 4; i++) {
621 current_pmic_model[i] = (dt_node_tmp1->dt_entry_m->pmic_rev[i] & 0xff);
622 board_pmic_model[i] = (board_pmic_target(i) & 0xff);
623 }
624 break;
625 default:
626 dprintf(CRITICAL, "ERROR: Unsupported version (%d) in dt node check \n",
627 dtb_info);
Maria Yuca51ee22013-06-27 21:45:24 +0800628 return 0;
Lijuan Gao9f152862014-08-18 13:45:24 +0800629 }
630
631 if (dtb_info == DTB_PMIC_MODEL) {
632 if ((current_pmic_model[0] == board_pmic_model[0]) &&
633 (current_pmic_model[1] == board_pmic_model[1]) &&
634 (current_pmic_model[2] == board_pmic_model[2]) &&
635 (current_pmic_model[3] == board_pmic_model[3])) {
636
637 for (i = 0; i < 4; i++) {
638 best_pmic_model[i] = current_pmic_model[i];
639 }
640 break;
641 }
642 } else {
643 if (current_info == board_info) {
644 best_info = current_info;
645 break;
646 }
647 }
648 }
649
650 list_for_every_entry(&dt_list->node, dt_node_tmp1, dt_node, node) {
651 if (!dt_node_tmp1){
652 dprintf(SPEW, "Current node is the end\n");
653 break;
654 }
655 switch(dtb_info) {
656 case DTB_FOUNDRY:
657 current_info = ((dt_node_tmp1->dt_entry_m->platform_id) & 0x00ff0000);
658 break;
659 case DTB_PMIC_MODEL:
660 for (i = 0; i < 4; i++) {
661 current_pmic_model[i] = (dt_node_tmp1->dt_entry_m->pmic_rev[i] & 0xff);
662 }
663 break;
664 default:
665 dprintf(CRITICAL, "ERROR: Unsupported version (%d) in dt node check \n",
666 dtb_info);
667 return 0;
668 }
669
670 if (dtb_info == DTB_PMIC_MODEL) {
671 if ((current_pmic_model[0] != best_pmic_model[0]) ||
672 (current_pmic_model[1] != best_pmic_model[1]) ||
673 (current_pmic_model[2] != best_pmic_model[2]) ||
674 (current_pmic_model[3] != best_pmic_model[3])) {
675
676 delete_current_dt = 1;
677 }
678 } else {
679 if (current_info != best_info) {
680 delete_current_dt = 1;
681 }
682 }
683
684 if (delete_current_dt) {
685 dprintf(SPEW, "Delete don't fit DTB entry %u/%08x/0x%08x/%x/%x/%x/%x/%x/%x/%x\n",
686 dt_node_tmp1->dt_entry_m->platform_id, dt_node_tmp1->dt_entry_m->variant_id,
687 dt_node_tmp1->dt_entry_m->board_hw_subtype, dt_node_tmp1->dt_entry_m->soc_rev,
688 dt_node_tmp1->dt_entry_m->pmic_rev[0], dt_node_tmp1->dt_entry_m->pmic_rev[1],
689 dt_node_tmp1->dt_entry_m->pmic_rev[2], dt_node_tmp1->dt_entry_m->pmic_rev[3],
690 dt_node_tmp1->dt_entry_m->offset, dt_node_tmp1->dt_entry_m->size);
691
692 dt_node_tmp2 = dt_node_tmp1->node.prev;
693 dt_entry_list_delete(dt_node_tmp1);
694 dt_node_tmp1 = dt_node_tmp2;
695 delete_current_dt = 0;
Maria Yuca51ee22013-06-27 21:45:24 +0800696 }
697 }
Maria Yuca51ee22013-06-27 21:45:24 +0800698
Maria Yu2e2d2c22013-07-03 19:20:33 +0800699 return 1;
Maria Yuca51ee22013-06-27 21:45:24 +0800700}
701
Lijuan Gao9f152862014-08-18 13:45:24 +0800702static int update_dtb_entry_node(struct dt_entry_node *dt_list, uint32_t dtb_info) {
703 struct dt_entry_node *dt_node_tmp1 = NULL;
704 struct dt_entry_node *dt_node_tmp2 = NULL;
705 uint32_t current_info = 0;
706 uint32_t board_info = 0;
707 uint32_t best_info = 0;
708
709 /* start to select the best entry*/
710 list_for_every_entry(&dt_list->node, dt_node_tmp1, dt_node, node) {
711 if (!dt_node_tmp1){
712 dprintf(SPEW, "Current node is the end\n");
713 break;
714 }
715 switch(dtb_info) {
716 case DTB_SOC:
717 current_info = dt_node_tmp1->dt_entry_m->soc_rev;
718 board_info = board_soc_version();
719 break;
720 case DTB_MAJOR_MINOR:
721 current_info = ((dt_node_tmp1->dt_entry_m->variant_id) & 0x00ffff00);
722 board_info = (board_target_id() & 0x00ffff00);
723 break;
724 case DTB_PMIC0:
725 current_info = ((dt_node_tmp1->dt_entry_m->pmic_rev[0]) & 0x00ffff00);
726 board_info = (board_pmic_target(0) & 0x00ffff00);
727 break;
728 case DTB_PMIC1:
729 current_info = ((dt_node_tmp1->dt_entry_m->pmic_rev[1]) & 0x00ffff00);
730 board_info = (board_pmic_target(1) & 0x00ffff00);
731 break;
732 case DTB_PMIC2:
733 current_info = ((dt_node_tmp1->dt_entry_m->pmic_rev[2]) & 0x00ffff00);
734 board_info = (board_pmic_target(2) & 0x00ffff00);
735 break;
736 case DTB_PMIC3:
737 current_info = ((dt_node_tmp1->dt_entry_m->pmic_rev[3]) & 0x00ffff00);
738 board_info = (board_pmic_target(3) & 0x00ffff00);
739 break;
740 default:
741 dprintf(CRITICAL, "ERROR: Unsupported version (%d) in dt node check \n",
742 dtb_info);
743 return 0;
744 }
745
746 if (current_info == board_info) {
747 best_info = current_info;
748 break;
749 }
750 if ((current_info < board_info) && (current_info > best_info)) {
751 best_info = current_info;
752 }
753 if (current_info < best_info) {
754 dprintf(SPEW, "Delete don't fit DTB entry %u/%08x/0x%08x/%x/%x/%x/%x/%x/%x/%x\n",
755 dt_node_tmp1->dt_entry_m->platform_id, dt_node_tmp1->dt_entry_m->variant_id,
756 dt_node_tmp1->dt_entry_m->board_hw_subtype, dt_node_tmp1->dt_entry_m->soc_rev,
757 dt_node_tmp1->dt_entry_m->pmic_rev[0], dt_node_tmp1->dt_entry_m->pmic_rev[1],
758 dt_node_tmp1->dt_entry_m->pmic_rev[2], dt_node_tmp1->dt_entry_m->pmic_rev[3],
759 dt_node_tmp1->dt_entry_m->offset, dt_node_tmp1->dt_entry_m->size);
760
761 dt_node_tmp2 = dt_node_tmp1->node.prev;
762 dt_entry_list_delete(dt_node_tmp1);
763 dt_node_tmp1 = dt_node_tmp2;
764 }
765 }
766
767 list_for_every_entry(&dt_list->node, dt_node_tmp1, dt_node, node) {
768 if (!dt_node_tmp1){
769 dprintf(SPEW, "Current node is the end\n");
770 break;
771 }
772 switch(dtb_info) {
773 case DTB_SOC:
774 current_info = dt_node_tmp1->dt_entry_m->soc_rev;
775 break;
776 case DTB_MAJOR_MINOR:
777 current_info = ((dt_node_tmp1->dt_entry_m->variant_id) & 0x00ffff00);
778 break;
779 case DTB_PMIC0:
780 current_info = ((dt_node_tmp1->dt_entry_m->pmic_rev[0]) & 0x00ffff00);
781 break;
782 case DTB_PMIC1:
783 current_info = ((dt_node_tmp1->dt_entry_m->pmic_rev[1]) & 0x00ffff00);
784 break;
785 case DTB_PMIC2:
786 current_info = ((dt_node_tmp1->dt_entry_m->pmic_rev[2]) & 0x00ffff00);
787 break;
788 case DTB_PMIC3:
789 current_info = ((dt_node_tmp1->dt_entry_m->pmic_rev[3]) & 0x00ffff00);
790 break;
791 default:
792 dprintf(CRITICAL, "ERROR: Unsupported version (%d) in dt node check \n",
793 dtb_info);
794 return 0;
795 }
796
797 if (current_info != best_info) {
798 dprintf(SPEW, "Delete don't fit DTB entry %u/%08x/0x%08x/%x/%x/%x/%x/%x/%x/%x\n",
799 dt_node_tmp1->dt_entry_m->platform_id, dt_node_tmp1->dt_entry_m->variant_id,
800 dt_node_tmp1->dt_entry_m->board_hw_subtype, dt_node_tmp1->dt_entry_m->soc_rev,
801 dt_node_tmp1->dt_entry_m->pmic_rev[0], dt_node_tmp1->dt_entry_m->pmic_rev[1],
802 dt_node_tmp1->dt_entry_m->pmic_rev[2], dt_node_tmp1->dt_entry_m->pmic_rev[3],
803 dt_node_tmp1->dt_entry_m->offset, dt_node_tmp1->dt_entry_m->size);
804
805 dt_node_tmp2 = dt_node_tmp1->node.prev;
806 dt_entry_list_delete(dt_node_tmp1);
807 dt_node_tmp1 = dt_node_tmp2;
808 }
809 }
810 return 1;
811}
812
813static struct dt_entry *platform_dt_match_best(struct dt_entry_node *dt_list)
814{
815 struct dt_entry_node *dt_node_tmp1 = NULL;
816
817 /* check Foundry id
818 * the foundry id must exact match board founddry id, this is compatibility check,
819 * if couldn't find the exact match from DTB, will exact match 0x0.
820 */
821 if (!platform_dt_absolute_compat_match(dt_list, DTB_FOUNDRY))
822 return NULL;
823
824 /* check PMIC model
825 * the PMIC model must exact match board PMIC model, this is compatibility check,
826 * if couldn't find the exact match from DTB, will exact match 0x0.
827 */
828 if (!platform_dt_absolute_compat_match(dt_list, DTB_PMIC_MODEL))
829 return NULL;
830
831 /* check soc version
832 * the suitable soc version must less than or equal to board soc version
833 */
834 if (!update_dtb_entry_node(dt_list, DTB_SOC))
835 return NULL;
836
837 /*check major and minor version
838 * the suitable major&minor version must less than or equal to board major&minor version
839 */
840 if (!update_dtb_entry_node(dt_list, DTB_MAJOR_MINOR))
841 return NULL;
842
843 /*check pmic info
844 * the suitable pmic major&minor info must less than or equal to board pmic major&minor version
845 */
846 if (!update_dtb_entry_node(dt_list, DTB_PMIC0))
847 return NULL;
848 if (!update_dtb_entry_node(dt_list, DTB_PMIC1))
849 return NULL;
850 if (!update_dtb_entry_node(dt_list, DTB_PMIC2))
851 return NULL;
852 if (!update_dtb_entry_node(dt_list, DTB_PMIC3))
853 return NULL;
854
855 list_for_every_entry(&dt_list->node, dt_node_tmp1, dt_node, node) {
856 if (!dt_node_tmp1) {
857 dprintf(CRITICAL, "ERROR: Couldn't find the suitable DTB!\n");
858 return NULL;
859 }
860 if (dt_node_tmp1->dt_entry_m)
861 return dt_node_tmp1->dt_entry_m;
862 }
863
864 return NULL;
865}
866
867/* Function to obtain the index information for the correct device tree
868 * based on the platform data.
869 * If a matching device tree is found, the information is returned in the
870 * "dt_entry_info" out parameter and a function value of 0 is returned, otherwise
871 * a non-zero function value is returned.
872 */
873int dev_tree_get_entry_info(struct dt_table *table, struct dt_entry *dt_entry_info)
Maria Yuca51ee22013-06-27 21:45:24 +0800874{
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700875 uint32_t i;
Lijuan Gao9f152862014-08-18 13:45:24 +0800876 unsigned char *table_ptr = NULL;
Joel Kingaa335dc2013-06-03 16:11:08 -0700877 struct dt_entry dt_entry_buf_1;
Lijuan Gao9f152862014-08-18 13:45:24 +0800878 struct dt_entry *cur_dt_entry = NULL;
879 struct dt_entry *best_match_dt_entry = NULL;
880 struct dt_entry_v1 *dt_entry_v1 = NULL;
881 struct dt_entry_v2 *dt_entry_v2 = NULL;
882 struct dt_entry_node *dt_entry_queue = NULL;
883 struct dt_entry_node *dt_node_tmp1 = NULL;
884 struct dt_entry_node *dt_node_tmp2 = NULL;
Maria Yu2e2d2c22013-07-03 19:20:33 +0800885 uint32_t found = 0;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700886
Joel Kingaa335dc2013-06-03 16:11:08 -0700887 if (!dt_entry_info) {
888 dprintf(CRITICAL, "ERROR: Bad parameter passed to %s \n",
889 __func__);
890 return -1;
891 }
892
893 table_ptr = (unsigned char *)table + DEV_TREE_HEADER_SIZE;
894 cur_dt_entry = &dt_entry_buf_1;
895 best_match_dt_entry = NULL;
Lijuan Gao9f152862014-08-18 13:45:24 +0800896 dt_entry_queue = (struct dt_entry_node *)
897 malloc(sizeof(struct dt_entry_node));
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700898
Lijuan Gao9f152862014-08-18 13:45:24 +0800899 if (!dt_entry_queue) {
900 dprintf(CRITICAL, "Out of memory\n");
901 return -1;
902 }
903
904 list_initialize(&dt_entry_queue->node);
905 dprintf(INFO, "DTB Total entry: %d, DTB version: %d\n", table->num_entries, table->version);
Maria Yu2e2d2c22013-07-03 19:20:33 +0800906 for(i = 0; found == 0 && i < table->num_entries; i++)
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700907 {
Joel Kingaa335dc2013-06-03 16:11:08 -0700908 memset(cur_dt_entry, 0, sizeof(struct dt_entry));
909 switch(table->version) {
910 case DEV_TREE_VERSION_V1:
911 dt_entry_v1 = (struct dt_entry_v1 *)table_ptr;
912 cur_dt_entry->platform_id = dt_entry_v1->platform_id;
913 cur_dt_entry->variant_id = dt_entry_v1->variant_id;
914 cur_dt_entry->soc_rev = dt_entry_v1->soc_rev;
Lijuan Gao9f152862014-08-18 13:45:24 +0800915 cur_dt_entry->board_hw_subtype = (dt_entry_v1->variant_id >> 0x18);
916 cur_dt_entry->pmic_rev[0] = board_pmic_target(0);
917 cur_dt_entry->pmic_rev[1] = board_pmic_target(1);
918 cur_dt_entry->pmic_rev[2] = board_pmic_target(2);
919 cur_dt_entry->pmic_rev[3] = board_pmic_target(3);
Joel Kingaa335dc2013-06-03 16:11:08 -0700920 cur_dt_entry->offset = dt_entry_v1->offset;
921 cur_dt_entry->size = dt_entry_v1->size;
922 table_ptr += sizeof(struct dt_entry_v1);
923 break;
924 case DEV_TREE_VERSION_V2:
Lijuan Gao9f152862014-08-18 13:45:24 +0800925 dt_entry_v2 = (struct dt_entry_v2*)table_ptr;
926 cur_dt_entry->platform_id = dt_entry_v2->platform_id;
927 cur_dt_entry->variant_id = dt_entry_v2->variant_id;
928 cur_dt_entry->soc_rev = dt_entry_v2->soc_rev;
929 /* For V2 version of DTBs we have platform version field as part
930 * of variant ID, in such case the subtype will be mentioned as 0x0
931 * As the qcom, board-id = <0xSSPMPmPH, 0x0>
932 * SS -- Subtype
933 * PM -- Platform major version
934 * Pm -- Platform minor version
935 * PH -- Platform hardware CDP/MTP
936 * In such case to make it compatible with LK algorithm move the subtype
937 * from variant_id to subtype field
938 */
939 if (dt_entry_v2->board_hw_subtype == 0)
940 cur_dt_entry->board_hw_subtype = (cur_dt_entry->variant_id >> 0x18);
941 else
942 cur_dt_entry->board_hw_subtype = dt_entry_v2->board_hw_subtype;
943 cur_dt_entry->pmic_rev[0] = board_pmic_target(0);
944 cur_dt_entry->pmic_rev[1] = board_pmic_target(1);
945 cur_dt_entry->pmic_rev[2] = board_pmic_target(2);
946 cur_dt_entry->pmic_rev[3] = board_pmic_target(3);
947 cur_dt_entry->offset = dt_entry_v2->offset;
948 cur_dt_entry->size = dt_entry_v2->size;
949 table_ptr += sizeof(struct dt_entry_v2);
950 break;
951 case DEV_TREE_VERSION_V3:
Joel Kingaa335dc2013-06-03 16:11:08 -0700952 memcpy(cur_dt_entry, (struct dt_entry *)table_ptr,
953 sizeof(struct dt_entry));
Lijuan Gao9f152862014-08-18 13:45:24 +0800954 /* For V3 version of DTBs we have platform version field as part
955 * of variant ID, in such case the subtype will be mentioned as 0x0
956 * As the qcom, board-id = <0xSSPMPmPH, 0x0>
957 * SS -- Subtype
958 * PM -- Platform major version
959 * Pm -- Platform minor version
960 * PH -- Platform hardware CDP/MTP
961 * In such case to make it compatible with LK algorithm move the subtype
962 * from variant_id to subtype field
963 */
964 if (cur_dt_entry->board_hw_subtype == 0)
965 cur_dt_entry->board_hw_subtype = (cur_dt_entry->variant_id >> 0x18);
966
Joel Kingaa335dc2013-06-03 16:11:08 -0700967 table_ptr += sizeof(struct dt_entry);
968 break;
969 default:
970 dprintf(CRITICAL, "ERROR: Unsupported version (%d) in DT table \n",
971 table->version);
Lijuan Gao9f152862014-08-18 13:45:24 +0800972 free(dt_entry_queue);
Joel Kingaa335dc2013-06-03 16:11:08 -0700973 return -1;
974 }
975
Lijuan Gao9f152862014-08-18 13:45:24 +0800976 /* DTBs must match the platform_id, platform_hw_id, platform_subtype and DDR size.
977 * The satisfactory DTBs are stored in dt_entry_queue
978 */
979 platform_dt_absolute_match(cur_dt_entry, dt_entry_queue);
Channagoud Kadabiafd62bf2013-01-08 20:32:52 -0800980
Lijuan Gao9f152862014-08-18 13:45:24 +0800981 }
982 best_match_dt_entry = platform_dt_match_best(dt_entry_queue);
Joel Kingaa335dc2013-06-03 16:11:08 -0700983 if (best_match_dt_entry) {
984 *dt_entry_info = *best_match_dt_entry;
Maria Yu2e2d2c22013-07-03 19:20:33 +0800985 found = 1;
986 }
987
988 if (found != 0) {
Sundarajan Srinivasan763c0db2014-05-20 17:08:36 -0700989 dprintf(INFO, "Using DTB entry 0x%08x/%08x/0x%08x/%u for device 0x%08x/%08x/0x%08x/%u\n",
David Ng618293a2013-06-25 12:29:03 -0700990 dt_entry_info->platform_id, dt_entry_info->soc_rev,
991 dt_entry_info->variant_id, dt_entry_info->board_hw_subtype,
Lijuan Gao9f152862014-08-18 13:45:24 +0800992 board_platform_id(), board_soc_version(),
993 board_target_id(), board_hardware_subtype());
994 if (dt_entry_info->pmic_rev[0] == 0 && dt_entry_info->pmic_rev[0] == 0 &&
995 dt_entry_info->pmic_rev[0] == 0 && dt_entry_info->pmic_rev[0] == 0) {
996 dprintf(SPEW, "No maintain pmic info in DTB, device pmic info is 0x%0x/0x%x/0x%x/0x%0x\n",
997 board_pmic_target(0), board_pmic_target(1),
998 board_pmic_target(2), board_pmic_target(3));
999 } else {
1000 dprintf(INFO, "Using pmic info 0x%0x/0x%x/0x%x/0x%0x for device 0x%0x/0x%x/0x%x/0x%0x\n",
1001 dt_entry_info->pmic_rev[0], dt_entry_info->pmic_rev[1],
1002 dt_entry_info->pmic_rev[2], dt_entry_info->pmic_rev[3],
1003 board_pmic_target(0), board_pmic_target(1),
1004 board_pmic_target(2), board_pmic_target(3));
1005 }
Joel Kingaa335dc2013-06-03 16:11:08 -07001006 return 0;
Channagoud Kadabiafd62bf2013-01-08 20:32:52 -08001007 }
1008
Lijuan Gao9f152862014-08-18 13:45:24 +08001009 dprintf(CRITICAL, "ERROR: Unable to find suitable device tree for device (%u/0x%08x/0x%08x/%u)\n",
1010 board_platform_id(), board_soc_version(),
1011 board_target_id(), board_hardware_subtype());
1012
1013 list_for_every_entry(&dt_entry_queue->node, dt_node_tmp1, dt_node, node) {
1014 /* free node memory */
1015 dt_node_tmp2 = dt_node_tmp1->node.prev;
1016 dt_entry_list_delete(dt_node_tmp1);
1017 dt_node_tmp1 = dt_node_tmp2;
1018 }
1019 free(dt_entry_queue);
Joel Kingaa335dc2013-06-03 16:11:08 -07001020 return -1;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001021}
1022
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001023/* Function to add the first RAM partition info to the device tree.
1024 * Note: The function replaces the reg property in the "/memory" node
1025 * with the addr and size provided.
1026 */
1027int dev_tree_add_first_mem_info(uint32_t *fdt, uint32_t offset, uint32_t addr, uint32_t size)
1028{
1029 int ret;
1030
1031 ret = fdt_setprop_u32(fdt, offset, "reg", addr);
1032
1033 if (ret)
1034 {
1035 dprintf(CRITICAL, "Failed to add the memory information addr: %d\n",
1036 ret);
1037 }
1038
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001039 ret = fdt_appendprop_u32(fdt, offset, "reg", size);
1040
1041 if (ret)
1042 {
1043 dprintf(CRITICAL, "Failed to add the memory information size: %d\n",
1044 ret);
1045 }
1046
1047 return ret;
1048}
1049
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -07001050static int dev_tree_query_memory_cell_sizes(void *fdt, struct dt_mem_node_info *mem_node, uint32_t mem_node_offset)
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001051{
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -07001052 int len;
1053 uint32_t *valp;
1054 int ret;
1055 uint32_t offset;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001056
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -07001057 mem_node->offset = mem_node_offset;
1058
1059 /* Get offset of the root node */
1060 ret = fdt_path_offset(fdt, "/");
1061 if (ret < 0)
1062 {
1063 dprintf(CRITICAL, "Could not find memory node.\n");
1064 return ret;
1065 }
1066
1067 offset = ret;
1068
1069 /* Find the #address-cells size. */
1070 valp = (uint32_t*)fdt_getprop(fdt, offset, "#address-cells", &len);
Lijuan Gaoae0927b2014-07-18 17:16:16 +08001071 if (len <= 0 || !valp)
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -07001072 {
1073 if (len == -FDT_ERR_NOTFOUND)
1074 {
1075 /* Property not found.
1076 * Assume standard sizes.
1077 */
1078 mem_node->addr_cell_size = 2;
1079 dprintf(CRITICAL, "Using default #addr_cell_size: %u\n", mem_node->addr_cell_size);
1080 }
1081 else
1082 {
1083 dprintf(CRITICAL, "Error finding the #address-cells property\n");
1084 return len;
1085 }
1086 }
1087 else
1088 mem_node->addr_cell_size = fdt32_to_cpu(*valp);
1089
1090 /* Find the #size-cells size. */
1091 valp = (uint32_t*)fdt_getprop(fdt, offset, "#size-cells", &len);
Lijuan Gaoae0927b2014-07-18 17:16:16 +08001092 if (len <= 0 || !valp)
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -07001093 {
1094 if (len == -FDT_ERR_NOTFOUND)
1095 {
1096 /* Property not found.
1097 * Assume standard sizes.
1098 */
1099 mem_node->size_cell_size = 1;
1100 dprintf(CRITICAL, "Using default #size_cell_size: %u\n", mem_node->size_cell_size);
1101 }
1102 else
1103 {
1104 dprintf(CRITICAL, "Error finding the #size-cells property\n");
1105 return len;
1106 }
1107 }
1108 else
1109 mem_node->size_cell_size = fdt32_to_cpu(*valp);
1110
1111 return 0;
1112}
1113
1114static void dev_tree_update_memory_node(uint32_t offset)
1115{
1116 mem_node.offset = offset;
1117 mem_node.addr_cell_size = 1;
1118 mem_node.size_cell_size = 1;
1119}
1120
1121/* Function to add the subsequent RAM partition info to the device tree. */
1122int dev_tree_add_mem_info(void *fdt, uint32_t offset, uint64_t addr, uint64_t size)
1123{
1124 int ret = 0;
1125
1126 if(smem_get_ram_ptable_version() >= 1)
1127 {
1128 ret = dev_tree_query_memory_cell_sizes(fdt, &mem_node, offset);
1129 if (ret < 0)
1130 {
1131 dprintf(CRITICAL, "Could not find #address-cells and #size-cells properties: ret %d\n", ret);
1132 return ret;
1133 }
1134
1135 }
1136 else
1137 {
1138 dev_tree_update_memory_node(offset);
1139 }
1140
1141 if (!(mem_node.mem_info_cnt))
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001142 {
1143 /* Replace any other reg prop in the memory node. */
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -07001144
1145 /* cell_size is the number of 32 bit words used to represent an address/length in the device tree.
1146 * memory node in DT can be either 32-bit(cell-size = 1) or 64-bit(cell-size = 2).So when updating
1147 * the memory node in the device tree, we write one word or two words based on cell_size = 1 or 2.
1148 */
1149
1150 if(mem_node.addr_cell_size == 2)
1151 {
1152 ret = fdt_setprop_u32(fdt, mem_node.offset, "reg", addr >> 32);
1153 if(ret)
1154 {
1155 dprintf(CRITICAL, "ERROR: Could not set prop reg for memory node\n");
1156 return ret;
1157 }
1158
1159 ret = fdt_appendprop_u32(fdt, mem_node.offset, "reg", (uint32_t)addr);
1160 if(ret)
1161 {
1162 dprintf(CRITICAL, "ERROR: Could not append prop reg for memory node\n");
1163 return ret;
1164 }
1165 }
1166 else
1167 {
1168 ret = fdt_setprop_u32(fdt, mem_node.offset, "reg", (uint32_t)addr);
1169 if(ret)
1170 {
1171 dprintf(CRITICAL, "ERROR: Could not set prop reg for memory node\n");
1172 return ret;
1173 }
1174 }
1175
1176 mem_node.mem_info_cnt = 1;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001177 }
1178 else
1179 {
1180 /* Append the mem info to the reg prop for subsequent nodes. */
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -07001181 if(mem_node.addr_cell_size == 2)
1182 {
1183 ret = fdt_appendprop_u32(fdt, mem_node.offset, "reg", addr >> 32);
1184 if(ret)
1185 {
1186 dprintf(CRITICAL, "ERROR: Could not append prop reg for memory node\n");
1187 return ret;
1188 }
1189 }
1190
1191 ret = fdt_appendprop_u32(fdt, mem_node.offset, "reg", (uint32_t)addr);
1192 if(ret)
1193 {
1194 dprintf(CRITICAL, "ERROR: Could not append prop reg for memory node\n");
1195 return ret;
1196 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001197 }
1198
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -07001199 if(mem_node.size_cell_size == 2)
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001200 {
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -07001201 ret = fdt_appendprop_u32(fdt, mem_node.offset, "reg", size>>32);
1202 if(ret)
1203 {
1204 dprintf(CRITICAL, "ERROR: Could not append prop reg for memory node\n");
1205 return ret;
1206 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001207 }
1208
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -07001209 ret = fdt_appendprop_u32(fdt, mem_node.offset, "reg", (uint32_t)size);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001210
1211 if (ret)
1212 {
1213 dprintf(CRITICAL, "Failed to add the memory information size: %d\n",
1214 ret);
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -07001215 return ret;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001216 }
1217
1218 return ret;
1219}
1220
1221/* Top level function that updates the device tree. */
1222int update_device_tree(void *fdt, const char *cmdline,
1223 void *ramdisk, uint32_t ramdisk_size)
1224{
1225 int ret = 0;
1226 uint32_t offset;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001227
1228 /* Check the device tree header */
1229 ret = fdt_check_header(fdt);
1230 if (ret)
1231 {
1232 dprintf(CRITICAL, "Invalid device tree header \n");
1233 return ret;
1234 }
1235
Deepa Dinamani1c970732013-04-19 14:23:01 -07001236 /* Add padding to make space for new nodes and properties. */
1237 ret = fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + DTB_PAD_SIZE);
1238 if (ret!= 0)
1239 {
1240 dprintf(CRITICAL, "Failed to move/resize dtb buffer: %d\n", ret);
1241 return ret;
1242 }
1243
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001244 /* Get offset of the memory node */
1245 ret = fdt_path_offset(fdt, "/memory");
1246 if (ret < 0)
1247 {
1248 dprintf(CRITICAL, "Could not find memory node.\n");
1249 return ret;
1250 }
1251
1252 offset = ret;
1253
1254 ret = target_dev_tree_mem(fdt, offset);
1255 if(ret)
1256 {
1257 dprintf(CRITICAL, "ERROR: Cannot update memory node\n");
1258 return ret;
1259 }
1260
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001261 /* Get offset of the chosen node */
1262 ret = fdt_path_offset(fdt, "/chosen");
1263 if (ret < 0)
1264 {
1265 dprintf(CRITICAL, "Could not find chosen node.\n");
1266 return ret;
1267 }
1268
1269 offset = ret;
Maria Yuabde9542014-07-07 14:49:34 +08001270 if (cmdline)
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001271 {
Maria Yuabde9542014-07-07 14:49:34 +08001272 /* Adding the cmdline to the chosen node */
1273 ret = fdt_appendprop_string(fdt, offset, (const char*)"bootargs", (const void*)cmdline);
1274 if (ret)
1275 {
1276 dprintf(CRITICAL, "ERROR: Cannot update chosen node [bootargs]\n");
1277 return ret;
1278 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001279 }
1280
Joonwoo Parka5b5f492014-02-13 18:24:48 -08001281 if (ramdisk_size) {
1282 /* Adding the initrd-start to the chosen node */
1283 ret = fdt_setprop_u32(fdt, offset, "linux,initrd-start",
1284 (uint32_t)ramdisk);
1285 if (ret)
1286 {
1287 dprintf(CRITICAL, "ERROR: Cannot update chosen node [linux,initrd-start]\n");
1288 return ret;
1289 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001290
Joonwoo Parka5b5f492014-02-13 18:24:48 -08001291 /* Adding the initrd-end to the chosen node */
1292 ret = fdt_setprop_u32(fdt, offset, "linux,initrd-end",
1293 ((uint32_t)ramdisk + ramdisk_size));
1294 if (ret)
1295 {
1296 dprintf(CRITICAL, "ERROR: Cannot update chosen node [linux,initrd-end]\n");
1297 return ret;
1298 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001299 }
1300
1301 fdt_pack(fdt);
1302
1303 return ret;
1304}
Maria Yuca51ee22013-06-27 21:45:24 +08001305