blob: 09403f8846ee8136fc8d2a9edc099de6eff843fc [file] [log] [blame]
Chandni Cherukuri771d6442018-05-10 12:03:50 +05301/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <debug.h>
8#include <desc_image_load.h>
9#include <libfdt.h>
10#include <platform.h>
11
12/*******************************************************************************
13 * This function inserts Platform information via device tree nodes as,
14 * system-id {
15 * platform-id = <0>;
16 * }
17 ******************************************************************************/
18static int plat_sgi_append_config_node(void)
19{
20 bl_mem_params_node_t *mem_params;
21 void *fdt;
22 int nodeoffset, err;
23 unsigned int platid = 0;
24 char *platform_name;
25
26 mem_params = get_bl_mem_params_node(HW_CONFIG_ID);
27 if (mem_params == NULL) {
28 ERROR("HW CONFIG base address is NULL");
29 return -1;
30 }
31
32 fdt = (void *)(mem_params->image_info.image_base);
33
34 /* Check the validity of the fdt */
35 if (fdt_check_header(fdt) != 0) {
36 ERROR("Invalid HW_CONFIG DTB passed\n");
37 return -1;
38 }
39
40 platform_name = (char *)fdt_getprop(fdt, 0, "compatible", NULL);
41
John Tsichritzis049db962018-08-16 14:37:40 +010042 if (platform_name == NULL) {
43 ERROR("Invalid HW_CONFIG DTB passed\n");
44 return -1;
45 }
46
Chandni Cherukuri771d6442018-05-10 12:03:50 +053047 if (strcmp(platform_name, "arm,sgi575") == 0) {
48 platid = mmio_read_32(SSC_VERSION);
49 } else {
John Tsichritzis049db962018-08-16 14:37:40 +010050 WARN("Invalid platform\n");
Chandni Cherukuri771d6442018-05-10 12:03:50 +053051 return -1;
52 }
53
54 /* Increase DTB blob by 512 byte */
55 err = fdt_open_into(fdt, fdt, mem_params->image_info.image_size + 512);
56 if (err < 0) {
57 ERROR("Failed to open HW_CONFIG DTB\n");
58 return -1;
59 }
60
61 /* Create "/system-id" node */
62 nodeoffset = fdt_add_subnode(fdt, 0, "system-id");
63 if (nodeoffset < 0) {
64 ERROR("Failed to add node system-id\n");
65 return -1;
66 }
67
68 err = fdt_setprop_u32(fdt, nodeoffset, "platform-id", platid);
69 if (err < 0) {
70 ERROR("Failed to add node platform-id\n");
71 return -1;
72 }
73 return 0;
74}
75
76/*******************************************************************************
77 * This function returns the list of executable images.
78 ******************************************************************************/
79bl_params_t *plat_get_next_bl_params(void)
80{
81 int ret;
82 bl_params_t *next_bl_params;
83
84 ret = plat_sgi_append_config_node();
85 if (ret != 0)
86 panic();
87
88 next_bl_params = get_next_bl_params_from_mem_params_desc();
89 populate_next_bl_params_config(next_bl_params);
90
91 return next_bl_params;
92}