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