xref: /rk3399_ARM-atf/plat/st/stm32mp1/include/boot_api.h (revision c3cf06f1a3a9b9ee8ac7a0ae505f95c45f7dca84)
14353bb20SYann Gautier /*
2aec7de41SYann Gautier  * Copyright (c) 2017-2018, STMicroelectronics - All Rights Reserved
34353bb20SYann Gautier  *
44353bb20SYann Gautier  * SPDX-License-Identifier: BSD-3-Clause
54353bb20SYann Gautier  */
64353bb20SYann Gautier 
7*c3cf06f1SAntonio Nino Diaz #ifndef BOOT_API_H
8*c3cf06f1SAntonio Nino Diaz #define BOOT_API_H
94353bb20SYann Gautier 
104353bb20SYann Gautier #include <stdint.h>
11aec7de41SYann Gautier #include <stdio.h>
124353bb20SYann Gautier 
134353bb20SYann Gautier /*
144353bb20SYann Gautier  * Possible value of boot context field 'boot_interface_sel'
154353bb20SYann Gautier  */
164353bb20SYann Gautier 
174353bb20SYann Gautier /* Value of field 'boot_interface_sel' when no boot occurred */
184353bb20SYann Gautier #define BOOT_API_CTX_BOOT_INTERFACE_SEL_NO			0x0U
194353bb20SYann Gautier 
204353bb20SYann Gautier /* Boot occurred on SD */
214353bb20SYann Gautier #define BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD		0x1U
224353bb20SYann Gautier 
234353bb20SYann Gautier /* Boot occurred on EMMC */
244353bb20SYann Gautier #define BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC		0x2U
254353bb20SYann Gautier 
264353bb20SYann Gautier /**
274353bb20SYann Gautier  * @brief  Possible value of boot context field 'EmmcXferStatus'
284353bb20SYann Gautier  */
294353bb20SYann Gautier /*
304353bb20SYann Gautier  * Possible value of boot context field 'emmc_xfer_status'
314353bb20SYann Gautier  */
324353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_NOT_STARTED			0x0U
334353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_DATAEND_DETECTED			0x1U
344353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_XFER_OVERALL_TIMEOUT_DETECTED	0x2U
354353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_XFER_DATA_TIMEOUT			0x3U
364353bb20SYann Gautier 
374353bb20SYann Gautier /*
384353bb20SYann Gautier  * Possible value of boot context field 'emmc_error_status'
394353bb20SYann Gautier  */
404353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_NONE                     0x0U
414353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_CMD_TIMEOUT              0x1U
424353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_ACK_TIMEOUT              0x2U
434353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_DATA_CRC_FAIL            0x3U
444353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_NOT_ENOUGH_BOOT_DATA_RX  0x4U
454353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_HEADER_NOT_FOUND         0x5U
464353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_HEADER_SIZE_ZERO         0x6U
474353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_IMAGE_NOT_COMPLETE       0x7U
484353bb20SYann Gautier 
494353bb20SYann Gautier /* Image Header related definitions */
504353bb20SYann Gautier 
514353bb20SYann Gautier /* Definition of header version */
524353bb20SYann Gautier #define BOOT_API_HEADER_VERSION					0x00010000U
534353bb20SYann Gautier 
544353bb20SYann Gautier /*
554353bb20SYann Gautier  * Magic number used to detect header in memory
564353bb20SYann Gautier  * Its value must be 'S' 'T' 'M' 0x32, i.e 0x324D5453 as field
574353bb20SYann Gautier  * 'bootapi_image_header_t.magic'
584353bb20SYann Gautier  * This identifies the start of a boot image.
594353bb20SYann Gautier  */
604353bb20SYann Gautier #define BOOT_API_IMAGE_HEADER_MAGIC_NB				0x324D5453U
614353bb20SYann Gautier 
624353bb20SYann Gautier /* Definitions related to Authentication used in image header structure */
634353bb20SYann Gautier #define BOOT_API_ECDSA_PUB_KEY_LEN_IN_BYTES			64
644353bb20SYann Gautier #define BOOT_API_ECDSA_SIGNATURE_LEN_IN_BYTES			64
654353bb20SYann Gautier #define BOOT_API_SHA256_DIGEST_SIZE_IN_BYTES			32
664353bb20SYann Gautier 
674353bb20SYann Gautier /* Possible values of the field 'boot_api_image_header_t.ecc_algo_type' */
684353bb20SYann Gautier #define BOOT_API_ECDSA_ALGO_TYPE_P256NIST			1
694353bb20SYann Gautier #define BOOT_API_ECDSA_ALGO_TYPE_BRAINPOOL256			2
704353bb20SYann Gautier 
714353bb20SYann Gautier /*
724353bb20SYann Gautier  * Cores secure magic numbers
734353bb20SYann Gautier  * Constant to be stored in bakcup register
744353bb20SYann Gautier  * BOOT_API_MAGIC_NUMBER_TAMP_BCK_REG_IDX
754353bb20SYann Gautier  */
764353bb20SYann Gautier #define BOOT_API_A7_CORE0_MAGIC_NUMBER				0xCA7FACE0U
774353bb20SYann Gautier #define BOOT_API_A7_CORE1_MAGIC_NUMBER				0xCA7FACE1U
784353bb20SYann Gautier 
794353bb20SYann Gautier /*
804353bb20SYann Gautier  * TAMP_BCK4R register index
814353bb20SYann Gautier  * This register is used to write a Magic Number in order to restart
824353bb20SYann Gautier  * Cortex A7 Core 1 and make it execute @ branch address from TAMP_BCK5R
834353bb20SYann Gautier  */
844353bb20SYann Gautier #define BOOT_API_CORE1_MAGIC_NUMBER_TAMP_BCK_REG_IDX		4U
854353bb20SYann Gautier 
864353bb20SYann Gautier /*
874353bb20SYann Gautier  * TAMP_BCK5R register index
884353bb20SYann Gautier  * This register is used to contain the branch address of
894353bb20SYann Gautier  * Cortex A7 Core 1 when restarted by a TAMP_BCK4R magic number writing
904353bb20SYann Gautier  */
914353bb20SYann Gautier #define BOOT_API_CORE1_BRANCH_ADDRESS_TAMP_BCK_REG_IDX		5U
924353bb20SYann Gautier 
934353bb20SYann Gautier /*
944353bb20SYann Gautier  * Possible value of boot context field 'hse_clock_value_in_hz'
954353bb20SYann Gautier  */
964353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_UNDEFINED			0U
974353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_24_MHZ			24000000U
984353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_25_MHZ			25000000U
994353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_26_MHZ			26000000U
1004353bb20SYann Gautier 
1014353bb20SYann Gautier /*
1024353bb20SYann Gautier  * Possible value of boot context field 'boot_partition_used_toboot'
1034353bb20SYann Gautier  */
1044353bb20SYann Gautier #define BOOT_API_CTX_BOOT_PARTITION_UNDEFINED			0U
1054353bb20SYann Gautier 
1064353bb20SYann Gautier /* Used FSBL1 to boot */
1074353bb20SYann Gautier #define BOOT_API_CTX_BOOT_PARTITION_FSBL1			1U
1084353bb20SYann Gautier 
1094353bb20SYann Gautier /* Used FSBL2 to boot */
1104353bb20SYann Gautier #define BOOT_API_CTX_BOOT_PARTITION_FSBL2			2U
1114353bb20SYann Gautier 
1124353bb20SYann Gautier /* OTP_CFG0 */
1134353bb20SYann Gautier #define BOOT_API_OTP_MODE_WORD_NB				0
1144353bb20SYann Gautier /* Closed = OTP_CFG0[6] */
1154353bb20SYann Gautier #define BOOT_API_OTP_MODE_CLOSED_BIT_POS			6
1164353bb20SYann Gautier 
1174353bb20SYann Gautier /*
1184353bb20SYann Gautier  * Boot Context related definitions
1194353bb20SYann Gautier  */
1204353bb20SYann Gautier 
1214353bb20SYann Gautier /*
1224353bb20SYann Gautier  * Boot core boot configuration structure
1234353bb20SYann Gautier  * Specifies all items of the cold boot configuration
1244353bb20SYann Gautier  * Memory and peripheral part.
1254353bb20SYann Gautier  */
1264353bb20SYann Gautier typedef struct {
1274353bb20SYann Gautier 	/*
1284353bb20SYann Gautier 	 * Boot interface used to boot : take values from defines
1294353bb20SYann Gautier 	 * BOOT_API_CTX_BOOT_INTERFACE_SEL_XXX above
1304353bb20SYann Gautier 	 */
1314353bb20SYann Gautier 	uint16_t boot_interface_selected;
1324353bb20SYann Gautier 	uint16_t boot_interface_instance;
1334353bb20SYann Gautier 	uint32_t reserved1[13];
1344353bb20SYann Gautier 	uint32_t otp_afmux_values[3];
1354353bb20SYann Gautier 	uint32_t reserved[9];
1364353bb20SYann Gautier 	/*
1374353bb20SYann Gautier 	 * Information specific to an SD boot
1384353bb20SYann Gautier 	 * Updated each time an SD boot is at least attempted,
1394353bb20SYann Gautier 	 * even if not successful
1404353bb20SYann Gautier 	 * Note : This is useful to understand why an SD boot failed
1414353bb20SYann Gautier 	 * in particular
1424353bb20SYann Gautier 	 */
1434353bb20SYann Gautier 	uint32_t sd_err_internal_timeout_cnt;
1444353bb20SYann Gautier 	uint32_t sd_err_dcrc_fail_cnt;
1454353bb20SYann Gautier 	uint32_t sd_err_dtimeout_cnt;
1464353bb20SYann Gautier 	uint32_t sd_err_ctimeout_cnt;
1474353bb20SYann Gautier 	uint32_t sd_err_ccrc_fail_cnt;
1484353bb20SYann Gautier 	uint32_t sd_overall_retry_cnt;
1494353bb20SYann Gautier 	/*
1504353bb20SYann Gautier 	 * Information specific to an eMMC boot
1514353bb20SYann Gautier 	 * Updated each time an eMMC boot is at least attempted,
1524353bb20SYann Gautier 	 * even if not successful
1534353bb20SYann Gautier 	 * Note : This is useful to understand why an eMMC boot failed
1544353bb20SYann Gautier 	 * in particular
1554353bb20SYann Gautier 	 */
1564353bb20SYann Gautier 	uint32_t emmc_xfer_status;
1574353bb20SYann Gautier 	uint32_t emmc_error_status;
1584353bb20SYann Gautier 	uint32_t emmc_nbbytes_rxcopied_tosysram_download_area;
1594353bb20SYann Gautier 	uint32_t hse_clock_value_in_hz;
1604353bb20SYann Gautier 	/*
1614353bb20SYann Gautier 	 * Boot partition :
1624353bb20SYann Gautier 	 * ie FSBL partition on which the boot was successful
1634353bb20SYann Gautier 	 */
1644353bb20SYann Gautier 	uint32_t boot_partition_used_toboot;
1654353bb20SYann Gautier 
1664353bb20SYann Gautier } __packed boot_api_context_t;
1674353bb20SYann Gautier 
1684353bb20SYann Gautier /*
1694353bb20SYann Gautier  * Image Header related definitions
1704353bb20SYann Gautier  */
1714353bb20SYann Gautier 
1724353bb20SYann Gautier /*
1734353bb20SYann Gautier  * Structure used to define the common Header format used for FSBL, xloader,
1744353bb20SYann Gautier  * ... and in particular used by bootROM for FSBL header readout.
1754353bb20SYann Gautier  * FSBL header size is 256 Bytes = 0x100
1764353bb20SYann Gautier  */
1774353bb20SYann Gautier typedef struct {
1784353bb20SYann Gautier 	/* BOOT_API_IMAGE_HEADER_MAGIC_NB */
1794353bb20SYann Gautier 	uint32_t magic;
1804353bb20SYann Gautier 	uint8_t image_signature[BOOT_API_ECDSA_SIGNATURE_LEN_IN_BYTES];
1814353bb20SYann Gautier 	/*
1824353bb20SYann Gautier 	 * Checksum of payload
1834353bb20SYann Gautier 	 * 32-bit sum all all payload bytes considered as 8 bit unigned numbers,
1844353bb20SYann Gautier 	 * discarding any overflow bits.
1854353bb20SYann Gautier 	 * Use to check UART/USB downloaded image integrity when signature
1864353bb20SYann Gautier 	 * is not used (i.e bit 0 : 'No_sig_check' = 1 in option flags)
1874353bb20SYann Gautier 	 */
1884353bb20SYann Gautier 	uint32_t payload_checksum;
1894353bb20SYann Gautier 	/* Image header version : should have value BOOT_API_HEADER_VERSION */
1904353bb20SYann Gautier 	uint32_t header_version;
1914353bb20SYann Gautier 	/* Image length in bytes */
1924353bb20SYann Gautier 	uint32_t image_length;
1934353bb20SYann Gautier 	/*
1944353bb20SYann Gautier 	 * Image Entry point address : should be in the SYSRAM area
1954353bb20SYann Gautier 	 * and at least within the download area range
1964353bb20SYann Gautier 	 */
1974353bb20SYann Gautier 	uint32_t image_entry_point;
1984353bb20SYann Gautier 	/* Reserved */
1994353bb20SYann Gautier 	uint32_t reserved1;
2004353bb20SYann Gautier 	/*
2014353bb20SYann Gautier 	 * Image load address : not used by bootROM but to be consistent
2024353bb20SYann Gautier 	 * with header format for other packages (xloader, ...)
2034353bb20SYann Gautier 	 */
2044353bb20SYann Gautier 	uint32_t load_address;
2054353bb20SYann Gautier 	/* Reserved */
2064353bb20SYann Gautier 	uint32_t reserved2;
2074353bb20SYann Gautier 	/* Image version to be compared by bootROM with monotonic
2084353bb20SYann Gautier 	 * counter value in OTP_CFG4 prior executing the downloaded image
2094353bb20SYann Gautier 	 */
2104353bb20SYann Gautier 	uint32_t image_version;
2114353bb20SYann Gautier 	/*
2124353bb20SYann Gautier 	 * Option flags:
2134353bb20SYann Gautier 	 * Bit 0 : No signature check request : 'No_sig_check'
2144353bb20SYann Gautier 	 *      value 1 : for No signature check request
2154353bb20SYann Gautier 	 *      value 0 : No request to bypass the signature check
2164353bb20SYann Gautier 	 * Note : No signature check is never allowed on a Secured chip
2174353bb20SYann Gautier 	 */
2184353bb20SYann Gautier 	uint32_t option_flags;
2194353bb20SYann Gautier 	/*
2204353bb20SYann Gautier 	 * Type of ECC algorithm to use  :
2214353bb20SYann Gautier 	 * value 1 : for P-256 NIST algorithm
2224353bb20SYann Gautier 	 * value 2 : for Brainpool 256 algorithm
2234353bb20SYann Gautier 	 * See definitions 'BOOT_API_ECDSA_ALGO_TYPE_XXX' above.
2244353bb20SYann Gautier 	 */
2254353bb20SYann Gautier 	uint32_t ecc_algo_type;
2264353bb20SYann Gautier 	/*
2274353bb20SYann Gautier 	 * OEM ECC Public Key (aka Root pubk) provided in header on 512 bits.
2284353bb20SYann Gautier 	 * The SHA-256 hash of the OEM ECC pubk must match the one stored
2294353bb20SYann Gautier 	 * in OTP cells.
2304353bb20SYann Gautier 	 */
2314353bb20SYann Gautier 	uint8_t ecc_pubk[BOOT_API_ECDSA_PUB_KEY_LEN_IN_BYTES];
2324353bb20SYann Gautier 	/* Pad up to 256 byte total size */
233aec7de41SYann Gautier 	uint8_t pad[83];
234aec7de41SYann Gautier 	/* Add binary type information */
235aec7de41SYann Gautier 	uint8_t binary_type;
2364353bb20SYann Gautier } __packed boot_api_image_header_t;
2374353bb20SYann Gautier 
238*c3cf06f1SAntonio Nino Diaz #endif /* BOOT_API_H */
239