xref: /rk3399_ARM-atf/plat/st/stm32mp1/include/boot_api.h (revision 12e21dfde236407b8253fcde6937f11ca44cb8b0)
14353bb20SYann Gautier /*
24bdb1a7aSLionel Debieve  * Copyright (c) 2017-2019, STMicroelectronics - All Rights Reserved
34353bb20SYann Gautier  *
44353bb20SYann Gautier  * SPDX-License-Identifier: BSD-3-Clause
54353bb20SYann Gautier  */
64353bb20SYann Gautier 
7c3cf06f1SAntonio Nino Diaz #ifndef BOOT_API_H
8c3cf06f1SAntonio Nino Diaz #define BOOT_API_H
94353bb20SYann Gautier 
104353bb20SYann Gautier #include <stdint.h>
11aec7de41SYann Gautier #include <stdio.h>
124353bb20SYann Gautier 
134353bb20SYann Gautier /*
144bdb1a7aSLionel Debieve  * Possible value of boot context field 'auth_status'
154bdb1a7aSLionel Debieve  */
164bdb1a7aSLionel Debieve /* No authentication done */
174bdb1a7aSLionel Debieve #define BOOT_API_CTX_AUTH_NO					0x0U
184bdb1a7aSLionel Debieve /* Authentication done and failed */
194bdb1a7aSLionel Debieve #define BOOT_API_CTX_AUTH_FAILED				0x1U
204bdb1a7aSLionel Debieve /* Authentication done and succeeded */
214bdb1a7aSLionel Debieve #define BOOT_API_CTX_AUTH_SUCCESS				0x2U
224bdb1a7aSLionel Debieve 
234bdb1a7aSLionel Debieve /*
244353bb20SYann Gautier  * Possible value of boot context field 'boot_interface_sel'
254353bb20SYann Gautier  */
264353bb20SYann Gautier 
274353bb20SYann Gautier /* Value of field 'boot_interface_sel' when no boot occurred */
284353bb20SYann Gautier #define BOOT_API_CTX_BOOT_INTERFACE_SEL_NO			0x0U
294353bb20SYann Gautier 
304353bb20SYann Gautier /* Boot occurred on SD */
314353bb20SYann Gautier #define BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD		0x1U
324353bb20SYann Gautier 
334353bb20SYann Gautier /* Boot occurred on EMMC */
344353bb20SYann Gautier #define BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC		0x2U
354353bb20SYann Gautier 
36*12e21dfdSLionel Debieve /* Boot occurred on FMC */
37*12e21dfdSLionel Debieve #define BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC		0x3U
38*12e21dfdSLionel Debieve 
394353bb20SYann Gautier /**
404353bb20SYann Gautier  * @brief  Possible value of boot context field 'EmmcXferStatus'
414353bb20SYann Gautier  */
424353bb20SYann Gautier /*
434353bb20SYann Gautier  * Possible value of boot context field 'emmc_xfer_status'
444353bb20SYann Gautier  */
454353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_NOT_STARTED			0x0U
464353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_DATAEND_DETECTED			0x1U
474353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_XFER_OVERALL_TIMEOUT_DETECTED	0x2U
484353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_XFER_DATA_TIMEOUT			0x3U
494353bb20SYann Gautier 
504353bb20SYann Gautier /*
514353bb20SYann Gautier  * Possible value of boot context field 'emmc_error_status'
524353bb20SYann Gautier  */
534353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_NONE                     0x0U
544353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_CMD_TIMEOUT              0x1U
554353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_ACK_TIMEOUT              0x2U
564353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_DATA_CRC_FAIL            0x3U
574353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_NOT_ENOUGH_BOOT_DATA_RX  0x4U
584353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_HEADER_NOT_FOUND         0x5U
594353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_HEADER_SIZE_ZERO         0x6U
604353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_IMAGE_NOT_COMPLETE       0x7U
614353bb20SYann Gautier 
624353bb20SYann Gautier /* Image Header related definitions */
634353bb20SYann Gautier 
644353bb20SYann Gautier /* Definition of header version */
654353bb20SYann Gautier #define BOOT_API_HEADER_VERSION					0x00010000U
664353bb20SYann Gautier 
674353bb20SYann Gautier /*
684353bb20SYann Gautier  * Magic number used to detect header in memory
694353bb20SYann Gautier  * Its value must be 'S' 'T' 'M' 0x32, i.e 0x324D5453 as field
704353bb20SYann Gautier  * 'bootapi_image_header_t.magic'
714353bb20SYann Gautier  * This identifies the start of a boot image.
724353bb20SYann Gautier  */
734353bb20SYann Gautier #define BOOT_API_IMAGE_HEADER_MAGIC_NB				0x324D5453U
744353bb20SYann Gautier 
754353bb20SYann Gautier /* Definitions related to Authentication used in image header structure */
764353bb20SYann Gautier #define BOOT_API_ECDSA_PUB_KEY_LEN_IN_BYTES			64
774353bb20SYann Gautier #define BOOT_API_ECDSA_SIGNATURE_LEN_IN_BYTES			64
784353bb20SYann Gautier #define BOOT_API_SHA256_DIGEST_SIZE_IN_BYTES			32
794353bb20SYann Gautier 
804353bb20SYann Gautier /* Possible values of the field 'boot_api_image_header_t.ecc_algo_type' */
814353bb20SYann Gautier #define BOOT_API_ECDSA_ALGO_TYPE_P256NIST			1
824353bb20SYann Gautier #define BOOT_API_ECDSA_ALGO_TYPE_BRAINPOOL256			2
834353bb20SYann Gautier 
844353bb20SYann Gautier /*
854353bb20SYann Gautier  * Cores secure magic numbers
864353bb20SYann Gautier  * Constant to be stored in bakcup register
874353bb20SYann Gautier  * BOOT_API_MAGIC_NUMBER_TAMP_BCK_REG_IDX
884353bb20SYann Gautier  */
894353bb20SYann Gautier #define BOOT_API_A7_CORE0_MAGIC_NUMBER				0xCA7FACE0U
904353bb20SYann Gautier #define BOOT_API_A7_CORE1_MAGIC_NUMBER				0xCA7FACE1U
914353bb20SYann Gautier 
924353bb20SYann Gautier /*
934353bb20SYann Gautier  * TAMP_BCK4R register index
944353bb20SYann Gautier  * This register is used to write a Magic Number in order to restart
954353bb20SYann Gautier  * Cortex A7 Core 1 and make it execute @ branch address from TAMP_BCK5R
964353bb20SYann Gautier  */
974353bb20SYann Gautier #define BOOT_API_CORE1_MAGIC_NUMBER_TAMP_BCK_REG_IDX		4U
984353bb20SYann Gautier 
994353bb20SYann Gautier /*
1004353bb20SYann Gautier  * TAMP_BCK5R register index
1014353bb20SYann Gautier  * This register is used to contain the branch address of
1024353bb20SYann Gautier  * Cortex A7 Core 1 when restarted by a TAMP_BCK4R magic number writing
1034353bb20SYann Gautier  */
1044353bb20SYann Gautier #define BOOT_API_CORE1_BRANCH_ADDRESS_TAMP_BCK_REG_IDX		5U
1054353bb20SYann Gautier 
1064353bb20SYann Gautier /*
1074353bb20SYann Gautier  * Possible value of boot context field 'hse_clock_value_in_hz'
1084353bb20SYann Gautier  */
1094353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_UNDEFINED			0U
1104353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_24_MHZ			24000000U
1114353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_25_MHZ			25000000U
1124353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_26_MHZ			26000000U
1134353bb20SYann Gautier 
1144353bb20SYann Gautier /*
1154353bb20SYann Gautier  * Possible value of boot context field 'boot_partition_used_toboot'
1164353bb20SYann Gautier  */
1174353bb20SYann Gautier #define BOOT_API_CTX_BOOT_PARTITION_UNDEFINED			0U
1184353bb20SYann Gautier 
1194353bb20SYann Gautier /* Used FSBL1 to boot */
1204353bb20SYann Gautier #define BOOT_API_CTX_BOOT_PARTITION_FSBL1			1U
1214353bb20SYann Gautier 
1224353bb20SYann Gautier /* Used FSBL2 to boot */
1234353bb20SYann Gautier #define BOOT_API_CTX_BOOT_PARTITION_FSBL2			2U
1244353bb20SYann Gautier 
1254353bb20SYann Gautier /* OTP_CFG0 */
1264353bb20SYann Gautier #define BOOT_API_OTP_MODE_WORD_NB				0
1274353bb20SYann Gautier /* Closed = OTP_CFG0[6] */
1284353bb20SYann Gautier #define BOOT_API_OTP_MODE_CLOSED_BIT_POS			6
1294353bb20SYann Gautier 
130697d18aeSLionel Debieve #define BOOT_API_RETURN_OK					0x77U
1314bdb1a7aSLionel Debieve 
1324353bb20SYann Gautier /*
1334353bb20SYann Gautier  * Boot Context related definitions
1344353bb20SYann Gautier  */
1354353bb20SYann Gautier 
1364353bb20SYann Gautier /*
1374353bb20SYann Gautier  * Boot core boot configuration structure
1384353bb20SYann Gautier  * Specifies all items of the cold boot configuration
1394353bb20SYann Gautier  * Memory and peripheral part.
1404353bb20SYann Gautier  */
1414353bb20SYann Gautier typedef struct {
1424353bb20SYann Gautier 	/*
1434353bb20SYann Gautier 	 * Boot interface used to boot : take values from defines
1444353bb20SYann Gautier 	 * BOOT_API_CTX_BOOT_INTERFACE_SEL_XXX above
1454353bb20SYann Gautier 	 */
1464353bb20SYann Gautier 	uint16_t boot_interface_selected;
1474353bb20SYann Gautier 	uint16_t boot_interface_instance;
1484353bb20SYann Gautier 	uint32_t reserved1[13];
1494353bb20SYann Gautier 	uint32_t otp_afmux_values[3];
1504bdb1a7aSLionel Debieve 	uint32_t reserved[5];
1514bdb1a7aSLionel Debieve 	uint32_t auth_status;
1524bdb1a7aSLionel Debieve 
1534bdb1a7aSLionel Debieve 	/*
1544bdb1a7aSLionel Debieve 	 * Pointers to bootROM External Secure Services
1554bdb1a7aSLionel Debieve 	 * - ECDSA check key
1564bdb1a7aSLionel Debieve 	 * - ECDSA verify signature
1574bdb1a7aSLionel Debieve 	 * - ECDSA verify signature and go
1584bdb1a7aSLionel Debieve 	 */
1594bdb1a7aSLionel Debieve 	uint32_t (*bootrom_ecdsa_check_key)(uint8_t *pubkey_in,
1604bdb1a7aSLionel Debieve 					    uint8_t *pubkey_out);
1614bdb1a7aSLionel Debieve 	uint32_t (*bootrom_ecdsa_verify_signature)(uint8_t *hash_in,
1624bdb1a7aSLionel Debieve 						   uint8_t *pubkey_in,
1634bdb1a7aSLionel Debieve 						   uint8_t *signature,
1644bdb1a7aSLionel Debieve 						   uint32_t ecc_algo);
1654bdb1a7aSLionel Debieve 	uint32_t (*bootrom_ecdsa_verify_and_go)(uint8_t *hash_in,
1664bdb1a7aSLionel Debieve 						uint8_t *pub_key_in,
1674bdb1a7aSLionel Debieve 						uint8_t *signature,
1684bdb1a7aSLionel Debieve 						uint32_t ecc_algo,
1694bdb1a7aSLionel Debieve 						uint32_t *entry_in);
1704bdb1a7aSLionel Debieve 
1714353bb20SYann Gautier 	/*
1724353bb20SYann Gautier 	 * Information specific to an SD boot
1734353bb20SYann Gautier 	 * Updated each time an SD boot is at least attempted,
1744353bb20SYann Gautier 	 * even if not successful
1754353bb20SYann Gautier 	 * Note : This is useful to understand why an SD boot failed
1764353bb20SYann Gautier 	 * in particular
1774353bb20SYann Gautier 	 */
1784353bb20SYann Gautier 	uint32_t sd_err_internal_timeout_cnt;
1794353bb20SYann Gautier 	uint32_t sd_err_dcrc_fail_cnt;
1804353bb20SYann Gautier 	uint32_t sd_err_dtimeout_cnt;
1814353bb20SYann Gautier 	uint32_t sd_err_ctimeout_cnt;
1824353bb20SYann Gautier 	uint32_t sd_err_ccrc_fail_cnt;
1834353bb20SYann Gautier 	uint32_t sd_overall_retry_cnt;
1844353bb20SYann Gautier 	/*
1854353bb20SYann Gautier 	 * Information specific to an eMMC boot
1864353bb20SYann Gautier 	 * Updated each time an eMMC boot is at least attempted,
1874353bb20SYann Gautier 	 * even if not successful
1884353bb20SYann Gautier 	 * Note : This is useful to understand why an eMMC boot failed
1894353bb20SYann Gautier 	 * in particular
1904353bb20SYann Gautier 	 */
1914353bb20SYann Gautier 	uint32_t emmc_xfer_status;
1924353bb20SYann Gautier 	uint32_t emmc_error_status;
1934353bb20SYann Gautier 	uint32_t emmc_nbbytes_rxcopied_tosysram_download_area;
1944353bb20SYann Gautier 	uint32_t hse_clock_value_in_hz;
1954353bb20SYann Gautier 	/*
1964353bb20SYann Gautier 	 * Boot partition :
1974353bb20SYann Gautier 	 * ie FSBL partition on which the boot was successful
1984353bb20SYann Gautier 	 */
1994353bb20SYann Gautier 	uint32_t boot_partition_used_toboot;
2004353bb20SYann Gautier 
2014353bb20SYann Gautier } __packed boot_api_context_t;
2024353bb20SYann Gautier 
2034353bb20SYann Gautier /*
2044353bb20SYann Gautier  * Image Header related definitions
2054353bb20SYann Gautier  */
2064353bb20SYann Gautier 
2074353bb20SYann Gautier /*
2084353bb20SYann Gautier  * Structure used to define the common Header format used for FSBL, xloader,
2094353bb20SYann Gautier  * ... and in particular used by bootROM for FSBL header readout.
2104353bb20SYann Gautier  * FSBL header size is 256 Bytes = 0x100
2114353bb20SYann Gautier  */
2124353bb20SYann Gautier typedef struct {
2134353bb20SYann Gautier 	/* BOOT_API_IMAGE_HEADER_MAGIC_NB */
2144353bb20SYann Gautier 	uint32_t magic;
2154353bb20SYann Gautier 	uint8_t image_signature[BOOT_API_ECDSA_SIGNATURE_LEN_IN_BYTES];
2164353bb20SYann Gautier 	/*
2174353bb20SYann Gautier 	 * Checksum of payload
2184353bb20SYann Gautier 	 * 32-bit sum all all payload bytes considered as 8 bit unigned numbers,
2194353bb20SYann Gautier 	 * discarding any overflow bits.
2204353bb20SYann Gautier 	 * Use to check UART/USB downloaded image integrity when signature
2214353bb20SYann Gautier 	 * is not used (i.e bit 0 : 'No_sig_check' = 1 in option flags)
2224353bb20SYann Gautier 	 */
2234353bb20SYann Gautier 	uint32_t payload_checksum;
2244353bb20SYann Gautier 	/* Image header version : should have value BOOT_API_HEADER_VERSION */
2254353bb20SYann Gautier 	uint32_t header_version;
2264353bb20SYann Gautier 	/* Image length in bytes */
2274353bb20SYann Gautier 	uint32_t image_length;
2284353bb20SYann Gautier 	/*
2294353bb20SYann Gautier 	 * Image Entry point address : should be in the SYSRAM area
2304353bb20SYann Gautier 	 * and at least within the download area range
2314353bb20SYann Gautier 	 */
2324353bb20SYann Gautier 	uint32_t image_entry_point;
2334353bb20SYann Gautier 	/* Reserved */
2344353bb20SYann Gautier 	uint32_t reserved1;
2354353bb20SYann Gautier 	/*
2364353bb20SYann Gautier 	 * Image load address : not used by bootROM but to be consistent
2374353bb20SYann Gautier 	 * with header format for other packages (xloader, ...)
2384353bb20SYann Gautier 	 */
2394353bb20SYann Gautier 	uint32_t load_address;
2404353bb20SYann Gautier 	/* Reserved */
2414353bb20SYann Gautier 	uint32_t reserved2;
2424353bb20SYann Gautier 	/* Image version to be compared by bootROM with monotonic
2434353bb20SYann Gautier 	 * counter value in OTP_CFG4 prior executing the downloaded image
2444353bb20SYann Gautier 	 */
2454353bb20SYann Gautier 	uint32_t image_version;
2464353bb20SYann Gautier 	/*
2474353bb20SYann Gautier 	 * Option flags:
2484353bb20SYann Gautier 	 * Bit 0 : No signature check request : 'No_sig_check'
2494353bb20SYann Gautier 	 *      value 1 : for No signature check request
2504353bb20SYann Gautier 	 *      value 0 : No request to bypass the signature check
2514353bb20SYann Gautier 	 * Note : No signature check is never allowed on a Secured chip
2524353bb20SYann Gautier 	 */
2534353bb20SYann Gautier 	uint32_t option_flags;
2544353bb20SYann Gautier 	/*
2554353bb20SYann Gautier 	 * Type of ECC algorithm to use  :
2564353bb20SYann Gautier 	 * value 1 : for P-256 NIST algorithm
2574353bb20SYann Gautier 	 * value 2 : for Brainpool 256 algorithm
2584353bb20SYann Gautier 	 * See definitions 'BOOT_API_ECDSA_ALGO_TYPE_XXX' above.
2594353bb20SYann Gautier 	 */
2604353bb20SYann Gautier 	uint32_t ecc_algo_type;
2614353bb20SYann Gautier 	/*
2624353bb20SYann Gautier 	 * OEM ECC Public Key (aka Root pubk) provided in header on 512 bits.
2634353bb20SYann Gautier 	 * The SHA-256 hash of the OEM ECC pubk must match the one stored
2644353bb20SYann Gautier 	 * in OTP cells.
2654353bb20SYann Gautier 	 */
2664353bb20SYann Gautier 	uint8_t ecc_pubk[BOOT_API_ECDSA_PUB_KEY_LEN_IN_BYTES];
2674353bb20SYann Gautier 	/* Pad up to 256 byte total size */
268aec7de41SYann Gautier 	uint8_t pad[83];
269aec7de41SYann Gautier 	/* Add binary type information */
270aec7de41SYann Gautier 	uint8_t binary_type;
2714353bb20SYann Gautier } __packed boot_api_image_header_t;
2724353bb20SYann Gautier 
273c3cf06f1SAntonio Nino Diaz #endif /* BOOT_API_H */
274