Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019-2020, ARM Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | |
| 9 | #include <common/debug.h> |
Louis Mayencourt | 81bd916 | 2019-10-17 15:14:25 +0100 | [diff] [blame] | 10 | #include <common/fdt_wrappers.h> |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 11 | #include <lib/fconf/fconf.h> |
Manish V Badarkhe | bb533c7 | 2020-06-11 22:17:30 +0100 | [diff] [blame] | 12 | #include <lib/fconf/fconf_dyn_cfg_getter.h> |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 13 | #include <libfdt.h> |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 14 | #include <plat/common/platform.h> |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 15 | #include <platform_def.h> |
| 16 | |
Manish V Badarkhe | e069f8a | 2020-06-11 22:25:53 +0100 | [diff] [blame] | 17 | int fconf_load_config(unsigned int image_id) |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 18 | { |
| 19 | int err; |
Manish V Badarkhe | e069f8a | 2020-06-11 22:25:53 +0100 | [diff] [blame] | 20 | const struct dyn_cfg_dtb_info_t *config_info; |
Manish V Badarkhe | bb533c7 | 2020-06-11 22:17:30 +0100 | [diff] [blame] | 21 | |
| 22 | assert((image_id == FW_CONFIG_ID) || (image_id == TB_FW_CONFIG_ID)); |
| 23 | |
Manish V Badarkhe | e069f8a | 2020-06-11 22:25:53 +0100 | [diff] [blame] | 24 | image_info_t config_image_info = { |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 25 | .h.type = (uint8_t)PARAM_IMAGE_BINARY, |
| 26 | .h.version = (uint8_t)VERSION_2, |
| 27 | .h.size = (uint16_t)sizeof(image_info_t), |
Manish V Badarkhe | bb533c7 | 2020-06-11 22:17:30 +0100 | [diff] [blame] | 28 | .h.attr = 0 |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 29 | }; |
| 30 | |
Manish V Badarkhe | bb533c7 | 2020-06-11 22:17:30 +0100 | [diff] [blame] | 31 | config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, image_id); |
Manish V Badarkhe | 99a8e14 | 2020-06-11 22:32:11 +0100 | [diff] [blame] | 32 | assert(config_info != NULL); |
| 33 | |
Manish V Badarkhe | e069f8a | 2020-06-11 22:25:53 +0100 | [diff] [blame] | 34 | config_image_info.image_base = config_info->config_addr; |
Manish V Badarkhe | a8be3bb | 2020-07-15 04:27:57 +0100 | [diff] [blame] | 35 | config_image_info.image_max_size = config_info->config_max_size; |
Manish V Badarkhe | bb533c7 | 2020-06-11 22:17:30 +0100 | [diff] [blame] | 36 | |
| 37 | VERBOSE("FCONF: Loading config with image ID: %d\n", image_id); |
Manish V Badarkhe | e069f8a | 2020-06-11 22:25:53 +0100 | [diff] [blame] | 38 | err = load_auth_image(image_id, &config_image_info); |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 39 | if (err != 0) { |
Manish V Badarkhe | e069f8a | 2020-06-11 22:25:53 +0100 | [diff] [blame] | 40 | VERBOSE("Failed to load config %d\n", image_id); |
| 41 | return err; |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Manish V Badarkhe | bb533c7 | 2020-06-11 22:17:30 +0100 | [diff] [blame] | 44 | INFO("FCONF: Config file with image ID:%d loaded at address = 0x%lx\n", |
Manish V Badarkhe | e069f8a | 2020-06-11 22:25:53 +0100 | [diff] [blame] | 45 | image_id, config_image_info.image_base); |
Louis Mayencourt | 81bd916 | 2019-10-17 15:14:25 +0100 | [diff] [blame] | 46 | |
Manish V Badarkhe | e069f8a | 2020-06-11 22:25:53 +0100 | [diff] [blame] | 47 | return 0; |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 50 | void fconf_populate(const char *config_type, uintptr_t config) |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 51 | { |
| 52 | assert(config != 0UL); |
| 53 | |
| 54 | /* Check if the pointer to DTB is correct */ |
| 55 | if (fdt_check_header((void *)config) != 0) { |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 56 | ERROR("FCONF: Invalid DTB file passed for %s\n", config_type); |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 57 | panic(); |
| 58 | } |
| 59 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 60 | INFO("FCONF: Reading %s firmware configuration file from: 0x%lx\n", config_type, config); |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 61 | |
| 62 | /* Go through all registered populate functions */ |
| 63 | IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_START__, start); |
| 64 | IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_END__, end); |
| 65 | const struct fconf_populator *populator; |
| 66 | |
| 67 | for (populator = start; populator != end; populator++) { |
| 68 | assert((populator->info != NULL) && (populator->populate != NULL)); |
| 69 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 70 | if (strcmp(populator->config_type, config_type) == 0) { |
| 71 | INFO("FCONF: Reading firmware configuration information for: %s\n", populator->info); |
| 72 | if (populator->populate(config) != 0) { |
| 73 | /* TODO: handle property miss */ |
| 74 | panic(); |
| 75 | } |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 76 | } |
| 77 | } |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 78 | } |