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 3612e21dfdSLionel Debieve /* Boot occurred on FMC */ 3712e21dfdSLionel Debieve #define BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC 0x3U 3812e21dfdSLionel Debieve 39*b1b218fbSLionel Debieve /* Boot occurred on QSPI NOR */ 40*b1b218fbSLionel Debieve #define BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI 0x4U 41*b1b218fbSLionel Debieve 4257044228SLionel Debieve /* Boot occurred on QSPI NAND */ 4357044228SLionel Debieve #define BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI 0x7U 4457044228SLionel Debieve 454353bb20SYann Gautier /** 464353bb20SYann Gautier * @brief Possible value of boot context field 'EmmcXferStatus' 474353bb20SYann Gautier */ 484353bb20SYann Gautier /* 494353bb20SYann Gautier * Possible value of boot context field 'emmc_xfer_status' 504353bb20SYann Gautier */ 514353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_NOT_STARTED 0x0U 524353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_DATAEND_DETECTED 0x1U 534353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_XFER_OVERALL_TIMEOUT_DETECTED 0x2U 544353bb20SYann Gautier #define BOOT_API_CTX_EMMC_XFER_STATUS_XFER_DATA_TIMEOUT 0x3U 554353bb20SYann Gautier 564353bb20SYann Gautier /* 574353bb20SYann Gautier * Possible value of boot context field 'emmc_error_status' 584353bb20SYann Gautier */ 594353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_NONE 0x0U 604353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_CMD_TIMEOUT 0x1U 614353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_ACK_TIMEOUT 0x2U 624353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_DATA_CRC_FAIL 0x3U 634353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_NOT_ENOUGH_BOOT_DATA_RX 0x4U 644353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_HEADER_NOT_FOUND 0x5U 654353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_HEADER_SIZE_ZERO 0x6U 664353bb20SYann Gautier #define BOOT_API_CTX_EMMC_ERROR_STATUS_IMAGE_NOT_COMPLETE 0x7U 674353bb20SYann Gautier 684353bb20SYann Gautier /* Image Header related definitions */ 694353bb20SYann Gautier 704353bb20SYann Gautier /* Definition of header version */ 714353bb20SYann Gautier #define BOOT_API_HEADER_VERSION 0x00010000U 724353bb20SYann Gautier 734353bb20SYann Gautier /* 744353bb20SYann Gautier * Magic number used to detect header in memory 754353bb20SYann Gautier * Its value must be 'S' 'T' 'M' 0x32, i.e 0x324D5453 as field 764353bb20SYann Gautier * 'bootapi_image_header_t.magic' 774353bb20SYann Gautier * This identifies the start of a boot image. 784353bb20SYann Gautier */ 794353bb20SYann Gautier #define BOOT_API_IMAGE_HEADER_MAGIC_NB 0x324D5453U 804353bb20SYann Gautier 814353bb20SYann Gautier /* Definitions related to Authentication used in image header structure */ 824353bb20SYann Gautier #define BOOT_API_ECDSA_PUB_KEY_LEN_IN_BYTES 64 834353bb20SYann Gautier #define BOOT_API_ECDSA_SIGNATURE_LEN_IN_BYTES 64 844353bb20SYann Gautier #define BOOT_API_SHA256_DIGEST_SIZE_IN_BYTES 32 854353bb20SYann Gautier 864353bb20SYann Gautier /* Possible values of the field 'boot_api_image_header_t.ecc_algo_type' */ 874353bb20SYann Gautier #define BOOT_API_ECDSA_ALGO_TYPE_P256NIST 1 884353bb20SYann Gautier #define BOOT_API_ECDSA_ALGO_TYPE_BRAINPOOL256 2 894353bb20SYann Gautier 904353bb20SYann Gautier /* 914353bb20SYann Gautier * Cores secure magic numbers 924353bb20SYann Gautier * Constant to be stored in bakcup register 934353bb20SYann Gautier * BOOT_API_MAGIC_NUMBER_TAMP_BCK_REG_IDX 944353bb20SYann Gautier */ 954353bb20SYann Gautier #define BOOT_API_A7_CORE0_MAGIC_NUMBER 0xCA7FACE0U 964353bb20SYann Gautier #define BOOT_API_A7_CORE1_MAGIC_NUMBER 0xCA7FACE1U 974353bb20SYann Gautier 984353bb20SYann Gautier /* 994353bb20SYann Gautier * TAMP_BCK4R register index 1004353bb20SYann Gautier * This register is used to write a Magic Number in order to restart 1014353bb20SYann Gautier * Cortex A7 Core 1 and make it execute @ branch address from TAMP_BCK5R 1024353bb20SYann Gautier */ 1034353bb20SYann Gautier #define BOOT_API_CORE1_MAGIC_NUMBER_TAMP_BCK_REG_IDX 4U 1044353bb20SYann Gautier 1054353bb20SYann Gautier /* 1064353bb20SYann Gautier * TAMP_BCK5R register index 1074353bb20SYann Gautier * This register is used to contain the branch address of 1084353bb20SYann Gautier * Cortex A7 Core 1 when restarted by a TAMP_BCK4R magic number writing 1094353bb20SYann Gautier */ 1104353bb20SYann Gautier #define BOOT_API_CORE1_BRANCH_ADDRESS_TAMP_BCK_REG_IDX 5U 1114353bb20SYann Gautier 1124353bb20SYann Gautier /* 1134353bb20SYann Gautier * Possible value of boot context field 'hse_clock_value_in_hz' 1144353bb20SYann Gautier */ 1154353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_UNDEFINED 0U 1164353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_24_MHZ 24000000U 1174353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_25_MHZ 25000000U 1184353bb20SYann Gautier #define BOOT_API_CTX_HSE_CLOCK_VALUE_26_MHZ 26000000U 1194353bb20SYann Gautier 1204353bb20SYann Gautier /* 1214353bb20SYann Gautier * Possible value of boot context field 'boot_partition_used_toboot' 1224353bb20SYann Gautier */ 1234353bb20SYann Gautier #define BOOT_API_CTX_BOOT_PARTITION_UNDEFINED 0U 1244353bb20SYann Gautier 1254353bb20SYann Gautier /* Used FSBL1 to boot */ 1264353bb20SYann Gautier #define BOOT_API_CTX_BOOT_PARTITION_FSBL1 1U 1274353bb20SYann Gautier 1284353bb20SYann Gautier /* Used FSBL2 to boot */ 1294353bb20SYann Gautier #define BOOT_API_CTX_BOOT_PARTITION_FSBL2 2U 1304353bb20SYann Gautier 1314353bb20SYann Gautier /* OTP_CFG0 */ 1324353bb20SYann Gautier #define BOOT_API_OTP_MODE_WORD_NB 0 1334353bb20SYann Gautier /* Closed = OTP_CFG0[6] */ 1344353bb20SYann Gautier #define BOOT_API_OTP_MODE_CLOSED_BIT_POS 6 1354353bb20SYann Gautier 136697d18aeSLionel Debieve #define BOOT_API_RETURN_OK 0x77U 1374bdb1a7aSLionel Debieve 1384353bb20SYann Gautier /* 1394353bb20SYann Gautier * Boot Context related definitions 1404353bb20SYann Gautier */ 1414353bb20SYann Gautier 1424353bb20SYann Gautier /* 1434353bb20SYann Gautier * Boot core boot configuration structure 1444353bb20SYann Gautier * Specifies all items of the cold boot configuration 1454353bb20SYann Gautier * Memory and peripheral part. 1464353bb20SYann Gautier */ 1474353bb20SYann Gautier typedef struct { 1484353bb20SYann Gautier /* 1494353bb20SYann Gautier * Boot interface used to boot : take values from defines 1504353bb20SYann Gautier * BOOT_API_CTX_BOOT_INTERFACE_SEL_XXX above 1514353bb20SYann Gautier */ 1524353bb20SYann Gautier uint16_t boot_interface_selected; 1534353bb20SYann Gautier uint16_t boot_interface_instance; 1544353bb20SYann Gautier uint32_t reserved1[13]; 1554353bb20SYann Gautier uint32_t otp_afmux_values[3]; 1564bdb1a7aSLionel Debieve uint32_t reserved[5]; 1574bdb1a7aSLionel Debieve uint32_t auth_status; 1584bdb1a7aSLionel Debieve 1594bdb1a7aSLionel Debieve /* 1604bdb1a7aSLionel Debieve * Pointers to bootROM External Secure Services 1614bdb1a7aSLionel Debieve * - ECDSA check key 1624bdb1a7aSLionel Debieve * - ECDSA verify signature 1634bdb1a7aSLionel Debieve * - ECDSA verify signature and go 1644bdb1a7aSLionel Debieve */ 1654bdb1a7aSLionel Debieve uint32_t (*bootrom_ecdsa_check_key)(uint8_t *pubkey_in, 1664bdb1a7aSLionel Debieve uint8_t *pubkey_out); 1674bdb1a7aSLionel Debieve uint32_t (*bootrom_ecdsa_verify_signature)(uint8_t *hash_in, 1684bdb1a7aSLionel Debieve uint8_t *pubkey_in, 1694bdb1a7aSLionel Debieve uint8_t *signature, 1704bdb1a7aSLionel Debieve uint32_t ecc_algo); 1714bdb1a7aSLionel Debieve uint32_t (*bootrom_ecdsa_verify_and_go)(uint8_t *hash_in, 1724bdb1a7aSLionel Debieve uint8_t *pub_key_in, 1734bdb1a7aSLionel Debieve uint8_t *signature, 1744bdb1a7aSLionel Debieve uint32_t ecc_algo, 1754bdb1a7aSLionel Debieve uint32_t *entry_in); 1764bdb1a7aSLionel Debieve 1774353bb20SYann Gautier /* 1784353bb20SYann Gautier * Information specific to an SD boot 1794353bb20SYann Gautier * Updated each time an SD boot is at least attempted, 1804353bb20SYann Gautier * even if not successful 1814353bb20SYann Gautier * Note : This is useful to understand why an SD boot failed 1824353bb20SYann Gautier * in particular 1834353bb20SYann Gautier */ 1844353bb20SYann Gautier uint32_t sd_err_internal_timeout_cnt; 1854353bb20SYann Gautier uint32_t sd_err_dcrc_fail_cnt; 1864353bb20SYann Gautier uint32_t sd_err_dtimeout_cnt; 1874353bb20SYann Gautier uint32_t sd_err_ctimeout_cnt; 1884353bb20SYann Gautier uint32_t sd_err_ccrc_fail_cnt; 1894353bb20SYann Gautier uint32_t sd_overall_retry_cnt; 1904353bb20SYann Gautier /* 1914353bb20SYann Gautier * Information specific to an eMMC boot 1924353bb20SYann Gautier * Updated each time an eMMC boot is at least attempted, 1934353bb20SYann Gautier * even if not successful 1944353bb20SYann Gautier * Note : This is useful to understand why an eMMC boot failed 1954353bb20SYann Gautier * in particular 1964353bb20SYann Gautier */ 1974353bb20SYann Gautier uint32_t emmc_xfer_status; 1984353bb20SYann Gautier uint32_t emmc_error_status; 1994353bb20SYann Gautier uint32_t emmc_nbbytes_rxcopied_tosysram_download_area; 2004353bb20SYann Gautier uint32_t hse_clock_value_in_hz; 2014353bb20SYann Gautier /* 2024353bb20SYann Gautier * Boot partition : 2034353bb20SYann Gautier * ie FSBL partition on which the boot was successful 2044353bb20SYann Gautier */ 2054353bb20SYann Gautier uint32_t boot_partition_used_toboot; 2064353bb20SYann Gautier 2074353bb20SYann Gautier } __packed boot_api_context_t; 2084353bb20SYann Gautier 2094353bb20SYann Gautier /* 2104353bb20SYann Gautier * Image Header related definitions 2114353bb20SYann Gautier */ 2124353bb20SYann Gautier 2134353bb20SYann Gautier /* 2144353bb20SYann Gautier * Structure used to define the common Header format used for FSBL, xloader, 2154353bb20SYann Gautier * ... and in particular used by bootROM for FSBL header readout. 2164353bb20SYann Gautier * FSBL header size is 256 Bytes = 0x100 2174353bb20SYann Gautier */ 2184353bb20SYann Gautier typedef struct { 2194353bb20SYann Gautier /* BOOT_API_IMAGE_HEADER_MAGIC_NB */ 2204353bb20SYann Gautier uint32_t magic; 2214353bb20SYann Gautier uint8_t image_signature[BOOT_API_ECDSA_SIGNATURE_LEN_IN_BYTES]; 2224353bb20SYann Gautier /* 2234353bb20SYann Gautier * Checksum of payload 2244353bb20SYann Gautier * 32-bit sum all all payload bytes considered as 8 bit unigned numbers, 2254353bb20SYann Gautier * discarding any overflow bits. 2264353bb20SYann Gautier * Use to check UART/USB downloaded image integrity when signature 2274353bb20SYann Gautier * is not used (i.e bit 0 : 'No_sig_check' = 1 in option flags) 2284353bb20SYann Gautier */ 2294353bb20SYann Gautier uint32_t payload_checksum; 2304353bb20SYann Gautier /* Image header version : should have value BOOT_API_HEADER_VERSION */ 2314353bb20SYann Gautier uint32_t header_version; 2324353bb20SYann Gautier /* Image length in bytes */ 2334353bb20SYann Gautier uint32_t image_length; 2344353bb20SYann Gautier /* 2354353bb20SYann Gautier * Image Entry point address : should be in the SYSRAM area 2364353bb20SYann Gautier * and at least within the download area range 2374353bb20SYann Gautier */ 2384353bb20SYann Gautier uint32_t image_entry_point; 2394353bb20SYann Gautier /* Reserved */ 2404353bb20SYann Gautier uint32_t reserved1; 2414353bb20SYann Gautier /* 2424353bb20SYann Gautier * Image load address : not used by bootROM but to be consistent 2434353bb20SYann Gautier * with header format for other packages (xloader, ...) 2444353bb20SYann Gautier */ 2454353bb20SYann Gautier uint32_t load_address; 2464353bb20SYann Gautier /* Reserved */ 2474353bb20SYann Gautier uint32_t reserved2; 2484353bb20SYann Gautier /* Image version to be compared by bootROM with monotonic 2494353bb20SYann Gautier * counter value in OTP_CFG4 prior executing the downloaded image 2504353bb20SYann Gautier */ 2514353bb20SYann Gautier uint32_t image_version; 2524353bb20SYann Gautier /* 2534353bb20SYann Gautier * Option flags: 2544353bb20SYann Gautier * Bit 0 : No signature check request : 'No_sig_check' 2554353bb20SYann Gautier * value 1 : for No signature check request 2564353bb20SYann Gautier * value 0 : No request to bypass the signature check 2574353bb20SYann Gautier * Note : No signature check is never allowed on a Secured chip 2584353bb20SYann Gautier */ 2594353bb20SYann Gautier uint32_t option_flags; 2604353bb20SYann Gautier /* 2614353bb20SYann Gautier * Type of ECC algorithm to use : 2624353bb20SYann Gautier * value 1 : for P-256 NIST algorithm 2634353bb20SYann Gautier * value 2 : for Brainpool 256 algorithm 2644353bb20SYann Gautier * See definitions 'BOOT_API_ECDSA_ALGO_TYPE_XXX' above. 2654353bb20SYann Gautier */ 2664353bb20SYann Gautier uint32_t ecc_algo_type; 2674353bb20SYann Gautier /* 2684353bb20SYann Gautier * OEM ECC Public Key (aka Root pubk) provided in header on 512 bits. 2694353bb20SYann Gautier * The SHA-256 hash of the OEM ECC pubk must match the one stored 2704353bb20SYann Gautier * in OTP cells. 2714353bb20SYann Gautier */ 2724353bb20SYann Gautier uint8_t ecc_pubk[BOOT_API_ECDSA_PUB_KEY_LEN_IN_BYTES]; 2734353bb20SYann Gautier /* Pad up to 256 byte total size */ 274aec7de41SYann Gautier uint8_t pad[83]; 275aec7de41SYann Gautier /* Add binary type information */ 276aec7de41SYann Gautier uint8_t binary_type; 2774353bb20SYann Gautier } __packed boot_api_image_header_t; 2784353bb20SYann Gautier 279c3cf06f1SAntonio Nino Diaz #endif /* BOOT_API_H */ 280