Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +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 <common/fdt_wrappers.h> |
| 11 | #include <drivers/io/io_storage.h> |
| 12 | #include <lib/object_pool.h> |
| 13 | #include <libfdt.h> |
| 14 | #include <tools_share/firmware_image_package.h> |
| 15 | |
| 16 | #include <plat/arm/common/arm_fconf_getter.h> |
| 17 | #include <plat/arm/common/arm_fconf_io_storage.h> |
| 18 | #include <platform_def.h> |
| 19 | |
| 20 | const io_block_spec_t fip_block_spec = { |
| 21 | .offset = PLAT_ARM_FIP_BASE, |
| 22 | .length = PLAT_ARM_FIP_MAX_SIZE |
| 23 | }; |
| 24 | |
| 25 | const io_uuid_spec_t arm_uuid_spec[MAX_NUMBER_IDS] = { |
| 26 | [BL2_IMAGE_ID] = {UUID_TRUSTED_BOOT_FIRMWARE_BL2}, |
| 27 | [TB_FW_CONFIG_ID] = {UUID_TB_FW_CONFIG}, |
| 28 | #if TRUSTED_BOARD_BOOT |
| 29 | [TRUSTED_BOOT_FW_CERT_ID] = {UUID_TRUSTED_BOOT_FW_CERT}, |
| 30 | #endif /* TRUSTED_BOARD_BOOT */ |
| 31 | }; |
| 32 | |
| 33 | /* By default, ARM platforms load images from the FIP */ |
| 34 | struct plat_io_policy policies[MAX_NUMBER_IDS] = { |
| 35 | [FIP_IMAGE_ID] = { |
| 36 | &memmap_dev_handle, |
| 37 | (uintptr_t)&fip_block_spec, |
| 38 | open_memmap |
| 39 | }, |
| 40 | [BL2_IMAGE_ID] = { |
| 41 | &fip_dev_handle, |
| 42 | (uintptr_t)&arm_uuid_spec[BL2_IMAGE_ID], |
| 43 | open_fip |
| 44 | }, |
| 45 | [TB_FW_CONFIG_ID] = { |
| 46 | &fip_dev_handle, |
| 47 | (uintptr_t)&arm_uuid_spec[TB_FW_CONFIG_ID], |
| 48 | open_fip |
| 49 | }, |
| 50 | #if TRUSTED_BOARD_BOOT |
| 51 | [TRUSTED_BOOT_FW_CERT_ID] = { |
| 52 | &fip_dev_handle, |
| 53 | (uintptr_t)&arm_uuid_spec[TRUSTED_BOOT_FW_CERT_ID], |
| 54 | open_fip |
| 55 | }, |
| 56 | #endif /* TRUSTED_BOARD_BOOT */ |
| 57 | }; |
| 58 | |
| 59 | #ifdef IMAGE_BL2 |
| 60 | |
| 61 | #if TRUSTED_BOARD_BOOT |
Louis Mayencourt | 2711cc8 | 2020-02-24 14:37:25 +0000 | [diff] [blame] | 62 | #define FCONF_ARM_IO_UUID_NUMBER U(19) |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 63 | #else |
Louis Mayencourt | 2711cc8 | 2020-02-24 14:37:25 +0000 | [diff] [blame] | 64 | #define FCONF_ARM_IO_UUID_NUMBER U(10) |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 65 | #endif |
| 66 | |
| 67 | static io_uuid_spec_t fconf_arm_uuids[FCONF_ARM_IO_UUID_NUMBER]; |
| 68 | static OBJECT_POOL_ARRAY(fconf_arm_uuids_pool, fconf_arm_uuids); |
| 69 | |
| 70 | struct policies_load_info { |
| 71 | unsigned int image_id; |
| 72 | const char *name; |
| 73 | }; |
| 74 | |
| 75 | /* image id to property name table */ |
| 76 | static const struct policies_load_info load_info[FCONF_ARM_IO_UUID_NUMBER] = { |
| 77 | {SCP_BL2_IMAGE_ID, "scp_bl2_uuid"}, |
| 78 | {BL31_IMAGE_ID, "bl31_uuid"}, |
| 79 | {BL32_IMAGE_ID, "bl32_uuid"}, |
| 80 | {BL32_EXTRA1_IMAGE_ID, "bl32_extra1_uuid"}, |
| 81 | {BL32_EXTRA2_IMAGE_ID, "bl32_extra2_uuid"}, |
| 82 | {BL33_IMAGE_ID, "bl33_uuid"}, |
| 83 | {HW_CONFIG_ID, "hw_cfg_uuid"}, |
| 84 | {SOC_FW_CONFIG_ID, "soc_fw_cfg_uuid"}, |
| 85 | {TOS_FW_CONFIG_ID, "tos_fw_cfg_uuid"}, |
| 86 | {NT_FW_CONFIG_ID, "nt_fw_cfg_uuid"}, |
| 87 | #if TRUSTED_BOARD_BOOT |
| 88 | {TRUSTED_KEY_CERT_ID, "t_key_cert_uuid"}, |
| 89 | {SCP_FW_KEY_CERT_ID, "scp_fw_key_uuid"}, |
| 90 | {SOC_FW_KEY_CERT_ID, "soc_fw_key_uuid"}, |
| 91 | {TRUSTED_OS_FW_KEY_CERT_ID, "tos_fw_key_cert_uuid"}, |
| 92 | {NON_TRUSTED_FW_KEY_CERT_ID, "nt_fw_key_cert_uuid"}, |
| 93 | {SCP_FW_CONTENT_CERT_ID, "scp_fw_content_cert_uuid"}, |
| 94 | {SOC_FW_CONTENT_CERT_ID, "soc_fw_content_cert_uuid"}, |
| 95 | {TRUSTED_OS_FW_CONTENT_CERT_ID, "tos_fw_content_cert_uuid"}, |
| 96 | {NON_TRUSTED_FW_CONTENT_CERT_ID, "nt_fw_content_cert_uuid"}, |
| 97 | #endif /* TRUSTED_BOARD_BOOT */ |
| 98 | }; |
| 99 | |
| 100 | int fconf_populate_arm_io_policies(uintptr_t config) |
| 101 | { |
| 102 | int err, node; |
| 103 | unsigned int i; |
| 104 | |
| 105 | union uuid_helper_t uuid_helper; |
| 106 | io_uuid_spec_t *uuid_ptr; |
| 107 | |
| 108 | /* As libfdt uses void *, we can't avoid this cast */ |
| 109 | const void *dtb = (void *)config; |
| 110 | |
| 111 | /* Assert the node offset point to "arm,io-fip-handle" compatible property */ |
| 112 | const char *compatible_str = "arm,io-fip-handle"; |
| 113 | node = fdt_node_offset_by_compatible(dtb, -1, compatible_str); |
| 114 | if (node < 0) { |
| 115 | ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str); |
| 116 | return node; |
| 117 | } |
| 118 | |
| 119 | /* Locate the uuid cells and read the value for all the load info uuid */ |
| 120 | for (i = 0; i < FCONF_ARM_IO_UUID_NUMBER; i++) { |
| 121 | uuid_ptr = pool_alloc(&fconf_arm_uuids_pool); |
| 122 | err = fdtw_read_array(dtb, node, load_info[i].name, 4, &uuid_helper.word); |
| 123 | if (err < 0) { |
| 124 | WARN("FCONF: Read cell failed for %s\n", load_info[i].name); |
| 125 | return err; |
| 126 | } |
| 127 | |
| 128 | VERBOSE("FCONF: arm-io_policies.%s cell found with value = 0x%x 0x%x 0x%x 0x%x\n", |
| 129 | load_info[i].name, |
| 130 | uuid_helper.word[0], uuid_helper.word[1], |
| 131 | uuid_helper.word[2], uuid_helper.word[3]); |
| 132 | |
| 133 | uuid_ptr->uuid = uuid_helper.uuid_struct; |
| 134 | policies[load_info[i].image_id].image_spec = (uintptr_t)uuid_ptr; |
| 135 | policies[load_info[i].image_id].dev_handle = &fip_dev_handle; |
| 136 | policies[load_info[i].image_id].check = open_fip; |
| 137 | } |
| 138 | return 0; |
| 139 | } |
| 140 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 141 | FCONF_REGISTER_POPULATOR(TB_FW, arm_io, fconf_populate_arm_io_policies); |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 142 | |
| 143 | #endif /* IMAGE_BL2 */ |