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> |
| 12 | #include <libfdt.h> |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 13 | #include <plat/common/platform.h> |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 14 | #include <platform_def.h> |
| 15 | |
Louis Mayencourt | 81bd916 | 2019-10-17 15:14:25 +0100 | [diff] [blame] | 16 | struct fconf_dtb_info_t fconf_dtb_info; |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 17 | |
| 18 | void fconf_load_config(void) |
| 19 | { |
| 20 | int err; |
Louis Mayencourt | 6d2b573 | 2019-12-17 13:17:25 +0000 | [diff] [blame] | 21 | /* fconf FW_CONFIG and TB_FW_CONFIG are currently the same DTB */ |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 22 | image_info_t arm_tb_fw_info = { |
| 23 | .h.type = (uint8_t)PARAM_IMAGE_BINARY, |
| 24 | .h.version = (uint8_t)VERSION_2, |
| 25 | .h.size = (uint16_t)sizeof(image_info_t), |
| 26 | .h.attr = 0, |
| 27 | .image_base = ARM_TB_FW_CONFIG_BASE, |
| 28 | .image_max_size = (uint32_t) |
Louis Mayencourt | 81bd916 | 2019-10-17 15:14:25 +0100 | [diff] [blame] | 29 | (ARM_TB_FW_CONFIG_LIMIT - ARM_TB_FW_CONFIG_BASE) |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | VERBOSE("FCONF: Loading FW_CONFIG\n"); |
| 33 | err = load_auth_image(TB_FW_CONFIG_ID, &arm_tb_fw_info); |
| 34 | if (err != 0) { |
| 35 | /* Return if FW_CONFIG is not loaded */ |
| 36 | VERBOSE("Failed to load FW_CONFIG\n"); |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | /* At this point we know that a DTB is indeed available */ |
Louis Mayencourt | 81bd916 | 2019-10-17 15:14:25 +0100 | [diff] [blame] | 41 | fconf_dtb_info.base_addr = arm_tb_fw_info.image_base; |
| 42 | fconf_dtb_info.size = (size_t)arm_tb_fw_info.image_size; |
| 43 | |
| 44 | #if !BL2_AT_EL3 |
| 45 | image_desc_t *desc; |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 46 | |
| 47 | /* The BL2 ep_info arg0 is modified to point to FW_CONFIG */ |
| 48 | desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); |
| 49 | assert(desc != NULL); |
Louis Mayencourt | 81bd916 | 2019-10-17 15:14:25 +0100 | [diff] [blame] | 50 | desc->ep_info.args.arg0 = arm_tb_fw_info.image_base; |
| 51 | #endif |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 52 | |
Louis Mayencourt | 81bd916 | 2019-10-17 15:14:25 +0100 | [diff] [blame] | 53 | INFO("FCONF: FW_CONFIG loaded at address = 0x%lx\n", arm_tb_fw_info.image_base); |
Louis Mayencourt | 5a15b2d | 2019-10-17 14:46:51 +0100 | [diff] [blame] | 54 | } |
| 55 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 56 | void fconf_populate(const char *config_type, uintptr_t config) |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 57 | { |
| 58 | assert(config != 0UL); |
| 59 | |
| 60 | /* Check if the pointer to DTB is correct */ |
| 61 | if (fdt_check_header((void *)config) != 0) { |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 62 | ERROR("FCONF: Invalid DTB file passed for %s\n", config_type); |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 63 | panic(); |
| 64 | } |
| 65 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 66 | 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] | 67 | |
| 68 | /* Go through all registered populate functions */ |
| 69 | IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_START__, start); |
| 70 | IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_END__, end); |
| 71 | const struct fconf_populator *populator; |
| 72 | |
| 73 | for (populator = start; populator != end; populator++) { |
| 74 | assert((populator->info != NULL) && (populator->populate != NULL)); |
| 75 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 76 | if (strcmp(populator->config_type, config_type) == 0) { |
| 77 | INFO("FCONF: Reading firmware configuration information for: %s\n", populator->info); |
| 78 | if (populator->populate(config) != 0) { |
| 79 | /* TODO: handle property miss */ |
| 80 | panic(); |
| 81 | } |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 82 | } |
| 83 | } |
Louis Mayencourt | 81bd916 | 2019-10-17 15:14:25 +0100 | [diff] [blame] | 84 | |
| 85 | /* save local pointer to the config dtb */ |
| 86 | fconf_dtb_info.base_addr = config; |
Louis Mayencourt | 944ade8 | 2019-08-08 12:03:26 +0100 | [diff] [blame] | 87 | } |