2 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
11 #include <platform_def.h>
13 #include <arch_helpers.h>
14 #include <common/debug.h>
15 #include <drivers/io/io_block.h>
16 #include <drivers/io/io_driver.h>
17 #include <drivers/io/io_fip.h>
18 #include <drivers/io/io_memmap.h>
19 #include <drivers/io/io_storage.h>
20 #include <drivers/mmc.h>
22 #include <lib/semihosting.h>
23 #include <tools_share/firmware_image_package.h>
25 #include "hikey_private.h"
27 #define EMMC_BLOCK_SHIFT 9
29 /* Page 1024, since only a few pages before 2048 are used as partition table */
30 #define SERIALNO_EMMC_OFFSET (1024 * 512)
32 struct plat_io_policy
{
33 uintptr_t *dev_handle
;
35 int (*check
)(const uintptr_t spec
);
38 static const io_dev_connector_t
*emmc_dev_con
;
39 static uintptr_t emmc_dev_handle
;
40 static const io_dev_connector_t
*fip_dev_con
;
41 static uintptr_t fip_dev_handle
;
43 static int check_emmc(const uintptr_t spec
);
44 static int check_fip(const uintptr_t spec
);
46 static const io_block_spec_t emmc_fip_spec
= {
47 .offset
= HIKEY_FIP_BASE
,
48 .length
= HIKEY_FIP_MAX_SIZE
,
51 static const io_block_dev_spec_t emmc_dev_spec
= {
52 /* It's used as temp buffer in block driver. */
55 .offset
= HIKEY_BL1_MMC_DATA_BASE
,
56 .length
= HIKEY_BL1_MMC_DATA_SIZE
,
60 .offset
= HIKEY_MMC_DATA_BASE
,
61 .length
= HIKEY_MMC_DATA_SIZE
,
65 .read
= mmc_read_blocks
,
66 .write
= mmc_write_blocks
,
68 .block_size
= MMC_BLOCK_SIZE
,
71 static const io_uuid_spec_t bl31_uuid_spec
= {
72 .uuid
= UUID_EL3_RUNTIME_FIRMWARE_BL31
,
75 static const io_uuid_spec_t bl32_uuid_spec
= {
76 .uuid
= UUID_SECURE_PAYLOAD_BL32
,
79 static const io_uuid_spec_t bl32_extra1_uuid_spec
= {
80 .uuid
= UUID_SECURE_PAYLOAD_BL32_EXTRA1
,
83 static const io_uuid_spec_t bl32_extra2_uuid_spec
= {
84 .uuid
= UUID_SECURE_PAYLOAD_BL32_EXTRA2
,
87 static const io_uuid_spec_t bl33_uuid_spec
= {
88 .uuid
= UUID_NON_TRUSTED_FIRMWARE_BL33
,
91 static const io_uuid_spec_t scp_bl2_uuid_spec
= {
92 .uuid
= UUID_SCP_FIRMWARE_SCP_BL2
,
95 #if TRUSTED_BOARD_BOOT
96 static const io_uuid_spec_t trusted_key_cert_uuid_spec
= {
97 .uuid
= UUID_TRUSTED_KEY_CERT
,
100 static const io_uuid_spec_t scp_fw_key_cert_uuid_spec
= {
101 .uuid
= UUID_SCP_FW_KEY_CERT
,
104 static const io_uuid_spec_t soc_fw_key_cert_uuid_spec
= {
105 .uuid
= UUID_SOC_FW_KEY_CERT
,
108 static const io_uuid_spec_t tos_fw_key_cert_uuid_spec
= {
109 .uuid
= UUID_TRUSTED_OS_FW_KEY_CERT
,
112 static const io_uuid_spec_t nt_fw_key_cert_uuid_spec
= {
113 .uuid
= UUID_NON_TRUSTED_FW_KEY_CERT
,
116 static const io_uuid_spec_t scp_fw_cert_uuid_spec
= {
117 .uuid
= UUID_SCP_FW_CONTENT_CERT
,
120 static const io_uuid_spec_t soc_fw_cert_uuid_spec
= {
121 .uuid
= UUID_SOC_FW_CONTENT_CERT
,
124 static const io_uuid_spec_t tos_fw_cert_uuid_spec
= {
125 .uuid
= UUID_TRUSTED_OS_FW_CONTENT_CERT
,
128 static const io_uuid_spec_t nt_fw_cert_uuid_spec
= {
129 .uuid
= UUID_NON_TRUSTED_FW_CONTENT_CERT
,
131 #endif /* TRUSTED_BOARD_BOOT */
133 static const struct plat_io_policy policies
[] = {
136 (uintptr_t)&emmc_fip_spec
,
139 [SCP_BL2_IMAGE_ID
] = {
141 (uintptr_t)&scp_bl2_uuid_spec
,
146 (uintptr_t)&bl31_uuid_spec
,
151 (uintptr_t)&bl32_uuid_spec
,
154 [BL32_EXTRA1_IMAGE_ID
] = {
156 (uintptr_t)&bl32_extra1_uuid_spec
,
159 [BL32_EXTRA2_IMAGE_ID
] = {
161 (uintptr_t)&bl32_extra2_uuid_spec
,
166 (uintptr_t)&bl33_uuid_spec
,
169 #if TRUSTED_BOARD_BOOT
170 [TRUSTED_KEY_CERT_ID
] = {
172 (uintptr_t)&trusted_key_cert_uuid_spec
,
175 [SCP_FW_KEY_CERT_ID
] = {
177 (uintptr_t)&scp_fw_key_cert_uuid_spec
,
180 [SOC_FW_KEY_CERT_ID
] = {
182 (uintptr_t)&soc_fw_key_cert_uuid_spec
,
185 [TRUSTED_OS_FW_KEY_CERT_ID
] = {
187 (uintptr_t)&tos_fw_key_cert_uuid_spec
,
190 [NON_TRUSTED_FW_KEY_CERT_ID
] = {
192 (uintptr_t)&nt_fw_key_cert_uuid_spec
,
195 [SCP_FW_CONTENT_CERT_ID
] = {
197 (uintptr_t)&scp_fw_cert_uuid_spec
,
200 [SOC_FW_CONTENT_CERT_ID
] = {
202 (uintptr_t)&soc_fw_cert_uuid_spec
,
205 [TRUSTED_OS_FW_CONTENT_CERT_ID
] = {
207 (uintptr_t)&tos_fw_cert_uuid_spec
,
210 [NON_TRUSTED_FW_CONTENT_CERT_ID
] = {
212 (uintptr_t)&nt_fw_cert_uuid_spec
,
215 #endif /* TRUSTED_BOARD_BOOT */
218 static int check_emmc(const uintptr_t spec
)
221 uintptr_t local_handle
;
223 result
= io_dev_init(emmc_dev_handle
, (uintptr_t)NULL
);
225 result
= io_open(emmc_dev_handle
, spec
, &local_handle
);
227 io_close(local_handle
);
232 static int check_fip(const uintptr_t spec
)
235 uintptr_t local_image_handle
;
237 /* See if a Firmware Image Package is available */
238 result
= io_dev_init(fip_dev_handle
, (uintptr_t)FIP_IMAGE_ID
);
240 result
= io_open(fip_dev_handle
, spec
, &local_image_handle
);
242 VERBOSE("Using FIP\n");
243 io_close(local_image_handle
);
249 void hikey_io_setup(void)
253 result
= register_io_dev_block(&emmc_dev_con
);
256 result
= register_io_dev_fip(&fip_dev_con
);
259 result
= io_dev_open(emmc_dev_con
, (uintptr_t)&emmc_dev_spec
,
263 result
= io_dev_open(fip_dev_con
, (uintptr_t)NULL
, &fip_dev_handle
);
266 /* Ignore improbable errors in release builds */
270 /* Return an IO device handle and specification which can be used to access
271 * an image. Use this to enforce platform load policy
273 int plat_get_image_source(unsigned int image_id
, uintptr_t *dev_handle
,
274 uintptr_t *image_spec
)
277 const struct plat_io_policy
*policy
;
279 assert(image_id
< ARRAY_SIZE(policies
));
281 policy
= &policies
[image_id
];
282 result
= policy
->check(policy
->image_spec
);
285 *image_spec
= policy
->image_spec
;
286 *dev_handle
= *(policy
->dev_handle
);