Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 2 | /* |
Ulises Cardenas | 8df2acd | 2015-07-02 21:26:30 -0500 | [diff] [blame] | 3 | * Copyright (C) 2012-2015 Freescale Semiconductor, Inc. All Rights Reserved. |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 4 | * |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __SECURE_MX6Q_H__ |
| 8 | #define __SECURE_MX6Q_H__ |
| 9 | |
| 10 | #include <linux/types.h> |
Bryan O'Donoghue | 316a087 | 2018-03-09 13:07:19 +0000 | [diff] [blame] | 11 | #include <linux/compiler.h> |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 12 | |
Bryan O'Donoghue | a6a5454 | 2018-01-12 12:40:02 +0000 | [diff] [blame] | 13 | /* |
| 14 | * IVT header definitions |
| 15 | * Security Reference Manual for i.MX 7Dual and 7Solo Applications Processors, |
| 16 | * Rev. 0, 03/2017 |
| 17 | * Section : 6.7.1.1 |
| 18 | */ |
| 19 | #define IVT_HEADER_MAGIC 0xD1 |
| 20 | #define IVT_TOTAL_LENGTH 0x20 |
Bryan O'Donoghue | a6a5454 | 2018-01-12 12:40:02 +0000 | [diff] [blame] | 21 | |
Bryan O'Donoghue | 0c7504e | 2018-03-09 13:07:20 +0000 | [diff] [blame] | 22 | struct __packed ivt_header { |
Bryan O'Donoghue | a6a5454 | 2018-01-12 12:40:02 +0000 | [diff] [blame] | 23 | uint8_t magic; |
| 24 | uint16_t length; |
| 25 | uint8_t version; |
Bryan O'Donoghue | 0c7504e | 2018-03-09 13:07:20 +0000 | [diff] [blame] | 26 | }; |
Bryan O'Donoghue | a6a5454 | 2018-01-12 12:40:02 +0000 | [diff] [blame] | 27 | |
| 28 | struct ivt { |
| 29 | struct ivt_header hdr; /* IVT header above */ |
| 30 | uint32_t entry; /* Absolute address of first instruction */ |
| 31 | uint32_t reserved1; /* Reserved should be zero */ |
| 32 | uint32_t dcd; /* Absolute address of the image DCD */ |
| 33 | uint32_t boot; /* Absolute address of the boot data */ |
| 34 | uint32_t self; /* Absolute address of the IVT */ |
| 35 | uint32_t csf; /* Absolute address of the CSF */ |
| 36 | uint32_t reserved2; /* Reserved should be zero */ |
| 37 | }; |
| 38 | |
Utkarsh Gupta | 2b1f414 | 2018-02-20 01:19:24 +0000 | [diff] [blame] | 39 | struct __packed hab_hdr { |
| 40 | u8 tag; /* Tag field */ |
| 41 | u8 len[2]; /* Length field in bytes (big-endian) */ |
| 42 | u8 par; /* Parameters field */ |
| 43 | }; |
| 44 | |
Breno Lima | 3adb6f0 | 2021-03-25 17:30:13 +0800 | [diff] [blame] | 45 | /* Default event structure */ |
| 46 | struct __packed evt_def { |
| 47 | struct hab_hdr hdr; /* Header */ |
| 48 | uint32_t sts; /* Status */ |
| 49 | uint32_t ctx; /* Default context */ |
| 50 | uint8_t *data; /* Default data location */ |
| 51 | size_t bytes; /* Size of default data */ |
| 52 | }; |
| 53 | |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 54 | /* -------- start of HAB API updates ------------*/ |
| 55 | /* The following are taken from HAB4 SIS */ |
| 56 | |
| 57 | /* Status definitions */ |
| 58 | enum hab_status { |
| 59 | HAB_STS_ANY = 0x00, |
| 60 | HAB_FAILURE = 0x33, |
| 61 | HAB_WARNING = 0x69, |
| 62 | HAB_SUCCESS = 0xf0 |
| 63 | }; |
| 64 | |
| 65 | /* Security Configuration definitions */ |
| 66 | enum hab_config { |
Ulises Cardenas | 8df2acd | 2015-07-02 21:26:30 -0500 | [diff] [blame] | 67 | HAB_CFG_RETURN = 0x33, /* < Field Return IC */ |
| 68 | HAB_CFG_OPEN = 0xf0, /* < Non-secure IC */ |
| 69 | HAB_CFG_CLOSED = 0xcc /* < Secure IC */ |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* State definitions */ |
| 73 | enum hab_state { |
Ulises Cardenas | 8df2acd | 2015-07-02 21:26:30 -0500 | [diff] [blame] | 74 | HAB_STATE_INITIAL = 0x33, /* Initialising state (transitory) */ |
| 75 | HAB_STATE_CHECK = 0x55, /* Check state (non-secure) */ |
| 76 | HAB_STATE_NONSECURE = 0x66, /* Non-secure state */ |
| 77 | HAB_STATE_TRUSTED = 0x99, /* Trusted state */ |
| 78 | HAB_STATE_SECURE = 0xaa, /* Secure state */ |
| 79 | HAB_STATE_FAIL_SOFT = 0xcc, /* Soft fail state */ |
| 80 | HAB_STATE_FAIL_HARD = 0xff, /* Hard fail state (terminal) */ |
| 81 | HAB_STATE_NONE = 0xf0, /* No security state machine */ |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 82 | HAB_STATE_MAX |
| 83 | }; |
| 84 | |
Ulises Cardenas | 8df2acd | 2015-07-02 21:26:30 -0500 | [diff] [blame] | 85 | enum hab_reason { |
| 86 | HAB_RSN_ANY = 0x00, /* Match any reason */ |
| 87 | HAB_ENG_FAIL = 0x30, /* Engine failure */ |
| 88 | HAB_INV_ADDRESS = 0x22, /* Invalid address: access denied */ |
| 89 | HAB_INV_ASSERTION = 0x0c, /* Invalid assertion */ |
| 90 | HAB_INV_CALL = 0x28, /* Function called out of sequence */ |
| 91 | HAB_INV_CERTIFICATE = 0x21, /* Invalid certificate */ |
| 92 | HAB_INV_COMMAND = 0x06, /* Invalid command: command malformed */ |
| 93 | HAB_INV_CSF = 0x11, /* Invalid csf */ |
| 94 | HAB_INV_DCD = 0x27, /* Invalid dcd */ |
| 95 | HAB_INV_INDEX = 0x0f, /* Invalid index: access denied */ |
| 96 | HAB_INV_IVT = 0x05, /* Invalid ivt */ |
| 97 | HAB_INV_KEY = 0x1d, /* Invalid key */ |
| 98 | HAB_INV_RETURN = 0x1e, /* Failed callback function */ |
| 99 | HAB_INV_SIGNATURE = 0x18, /* Invalid signature */ |
| 100 | HAB_INV_SIZE = 0x17, /* Invalid data size */ |
| 101 | HAB_MEM_FAIL = 0x2e, /* Memory failure */ |
| 102 | HAB_OVR_COUNT = 0x2b, /* Expired poll count */ |
| 103 | HAB_OVR_STORAGE = 0x2d, /* Exhausted storage region */ |
| 104 | HAB_UNS_ALGORITHM = 0x12, /* Unsupported algorithm */ |
| 105 | HAB_UNS_COMMAND = 0x03, /* Unsupported command */ |
| 106 | HAB_UNS_ENGINE = 0x0a, /* Unsupported engine */ |
| 107 | HAB_UNS_ITEM = 0x24, /* Unsupported configuration item */ |
| 108 | HAB_UNS_KEY = 0x1b, /* Unsupported key type/parameters */ |
| 109 | HAB_UNS_PROTOCOL = 0x14, /* Unsupported protocol */ |
| 110 | HAB_UNS_STATE = 0x09, /* Unsuitable state */ |
| 111 | HAB_RSN_MAX |
| 112 | }; |
| 113 | |
| 114 | enum hab_context { |
| 115 | HAB_CTX_ANY = 0x00, /* Match any context */ |
| 116 | HAB_CTX_FAB = 0xff, /* Event logged in hab_fab_test() */ |
| 117 | HAB_CTX_ENTRY = 0xe1, /* Event logged in hab_rvt.entry() */ |
| 118 | HAB_CTX_TARGET = 0x33, /* Event logged in hab_rvt.check_target() */ |
| 119 | HAB_CTX_AUTHENTICATE = 0x0a,/* Logged in hab_rvt.authenticate_image() */ |
| 120 | HAB_CTX_DCD = 0xdd, /* Event logged in hab_rvt.run_dcd() */ |
| 121 | HAB_CTX_CSF = 0xcf, /* Event logged in hab_rvt.run_csf() */ |
| 122 | HAB_CTX_COMMAND = 0xc0, /* Event logged executing csf/dcd command */ |
| 123 | HAB_CTX_AUT_DAT = 0xdb, /* Authenticated data block */ |
| 124 | HAB_CTX_ASSERT = 0xa0, /* Event logged in hab_rvt.assert() */ |
| 125 | HAB_CTX_EXIT = 0xee, /* Event logged in hab_rvt.exit() */ |
| 126 | HAB_CTX_MAX |
| 127 | }; |
| 128 | |
Bryan O'Donoghue | d03dcea | 2018-01-12 12:40:08 +0000 | [diff] [blame] | 129 | enum hab_target { |
| 130 | HAB_TGT_MEMORY = 0x0f, |
| 131 | HAB_TGT_PERIPHERAL = 0xf0, |
| 132 | HAB_TGT_ANY = 0x55, |
| 133 | }; |
| 134 | |
Adrian Alonso | ae1e853 | 2015-10-12 13:48:11 -0500 | [diff] [blame] | 135 | struct imx_sec_config_fuse_t { |
| 136 | int bank; |
| 137 | int word; |
| 138 | }; |
| 139 | |
Stefano Babic | f8b509b | 2019-09-20 08:47:53 +0200 | [diff] [blame] | 140 | #if defined(CONFIG_IMX_HAB) |
Adrian Alonso | ae1e853 | 2015-10-12 13:48:11 -0500 | [diff] [blame] | 141 | extern struct imx_sec_config_fuse_t const imx_sec_config_fuse; |
| 142 | #endif |
| 143 | |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 144 | /*Function prototype description*/ |
| 145 | typedef enum hab_status hab_rvt_report_event_t(enum hab_status, uint32_t, |
| 146 | uint8_t* , size_t*); |
| 147 | typedef enum hab_status hab_rvt_report_status_t(enum hab_config *, |
| 148 | enum hab_state *); |
| 149 | typedef enum hab_status hab_loader_callback_f_t(void**, size_t*, const void*); |
| 150 | typedef enum hab_status hab_rvt_entry_t(void); |
| 151 | typedef enum hab_status hab_rvt_exit_t(void); |
| 152 | typedef void *hab_rvt_authenticate_image_t(uint8_t, ptrdiff_t, |
| 153 | void **, size_t *, hab_loader_callback_f_t); |
Bryan O'Donoghue | d03dcea | 2018-01-12 12:40:08 +0000 | [diff] [blame] | 154 | typedef enum hab_status hab_rvt_check_target_t(enum hab_target, const void *, |
| 155 | size_t); |
Bryan O'Donoghue | 529fd57 | 2018-01-12 12:40:17 +0000 | [diff] [blame] | 156 | typedef void hab_rvt_failsafe_t(void); |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 157 | typedef void hapi_clock_init_t(void); |
| 158 | |
Ulises Cardenas | 8df2acd | 2015-07-02 21:26:30 -0500 | [diff] [blame] | 159 | #define HAB_ENG_ANY 0x00 /* Select first compatible engine */ |
| 160 | #define HAB_ENG_SCC 0x03 /* Security controller */ |
| 161 | #define HAB_ENG_RTIC 0x05 /* Run-time integrity checker */ |
| 162 | #define HAB_ENG_SAHARA 0x06 /* Crypto accelerator */ |
| 163 | #define HAB_ENG_CSU 0x0a /* Central Security Unit */ |
| 164 | #define HAB_ENG_SRTC 0x0c /* Secure clock */ |
| 165 | #define HAB_ENG_DCP 0x1b /* Data Co-Processor */ |
| 166 | #define HAB_ENG_CAAM 0x1d /* CAAM */ |
| 167 | #define HAB_ENG_SNVS 0x1e /* Secure Non-Volatile Storage */ |
| 168 | #define HAB_ENG_OCOTP 0x21 /* Fuse controller */ |
| 169 | #define HAB_ENG_DTCP 0x22 /* DTCP co-processor */ |
| 170 | #define HAB_ENG_ROM 0x36 /* Protected ROM area */ |
| 171 | #define HAB_ENG_HDCP 0x24 /* HDCP co-processor */ |
| 172 | #define HAB_ENG_RTL 0x77 /* RTL simulation engine */ |
| 173 | #define HAB_ENG_SW 0xff /* Software engine */ |
| 174 | |
Peng Fan | 4f3cf8f | 2021-03-25 17:30:07 +0800 | [diff] [blame] | 175 | #ifdef CONFIG_ARM64 |
Ye Li | 953ef28 | 2021-03-25 17:30:15 +0800 | [diff] [blame] | 176 | #ifdef CONFIG_IMX8MQ |
Peng Fan | 4f3cf8f | 2021-03-25 17:30:07 +0800 | [diff] [blame] | 177 | #define HAB_RVT_BASE 0x00000880 |
Ye Li | 953ef28 | 2021-03-25 17:30:15 +0800 | [diff] [blame] | 178 | #else |
| 179 | #define HAB_RVT_BASE 0x00000900 |
| 180 | #endif |
Peng Fan | 4f3cf8f | 2021-03-25 17:30:07 +0800 | [diff] [blame] | 181 | |
| 182 | #define HAB_RVT_ENTRY (*(ulong *)(HAB_RVT_BASE + 0x08)) |
| 183 | #define HAB_RVT_EXIT (*(ulong *)(HAB_RVT_BASE + 0x10)) |
| 184 | #define HAB_RVT_CHECK_TARGET (*(ulong *)(HAB_RVT_BASE + 0x18)) |
| 185 | #define HAB_RVT_AUTHENTICATE_IMAGE (*(ulong *)(HAB_RVT_BASE + 0x20)) |
| 186 | #define HAB_RVT_REPORT_EVENT (*(ulong *)(HAB_RVT_BASE + 0x40)) |
| 187 | #define HAB_RVT_REPORT_STATUS (*(ulong *)(HAB_RVT_BASE + 0x48)) |
| 188 | #define HAB_RVT_FAILSAFE (*(ulong *)(HAB_RVT_BASE + 0x50)) |
| 189 | #else |
| 190 | |
Adrian Alonso | 994d9cf | 2015-10-12 13:48:09 -0500 | [diff] [blame] | 191 | #ifdef CONFIG_ROM_UNIFIED_SECTIONS |
Nitin Garg | 416d53f | 2014-09-30 11:39:29 -0500 | [diff] [blame] | 192 | #define HAB_RVT_BASE 0x00000100 |
| 193 | #else |
Breno Lima | f4a7224 | 2018-02-20 01:19:26 +0000 | [diff] [blame] | 194 | #define HAB_RVT_BASE_NEW 0x00000098 |
| 195 | #define HAB_RVT_BASE_OLD 0x00000094 |
| 196 | #define HAB_RVT_BASE ((is_mx6dqp()) ? \ |
| 197 | HAB_RVT_BASE_NEW : \ |
Breno Lima | 90ec0ea | 2021-03-25 17:30:19 +0800 | [diff] [blame] | 198 | (is_mx6dq() && (soc_rev() >= CHIP_REV_1_3)) ? \ |
Breno Lima | f4a7224 | 2018-02-20 01:19:26 +0000 | [diff] [blame] | 199 | HAB_RVT_BASE_NEW : \ |
| 200 | (is_mx6sdl() && (soc_rev() >= CHIP_REV_1_2)) ? \ |
| 201 | HAB_RVT_BASE_NEW : HAB_RVT_BASE_OLD) |
Nitin Garg | 416d53f | 2014-09-30 11:39:29 -0500 | [diff] [blame] | 202 | #endif |
| 203 | |
| 204 | #define HAB_RVT_ENTRY (*(uint32_t *)(HAB_RVT_BASE + 0x04)) |
| 205 | #define HAB_RVT_EXIT (*(uint32_t *)(HAB_RVT_BASE + 0x08)) |
Bryan O'Donoghue | d03dcea | 2018-01-12 12:40:08 +0000 | [diff] [blame] | 206 | #define HAB_RVT_CHECK_TARGET (*(uint32_t *)(HAB_RVT_BASE + 0x0C)) |
Nitin Garg | 416d53f | 2014-09-30 11:39:29 -0500 | [diff] [blame] | 207 | #define HAB_RVT_AUTHENTICATE_IMAGE (*(uint32_t *)(HAB_RVT_BASE + 0x10)) |
| 208 | #define HAB_RVT_REPORT_EVENT (*(uint32_t *)(HAB_RVT_BASE + 0x20)) |
| 209 | #define HAB_RVT_REPORT_STATUS (*(uint32_t *)(HAB_RVT_BASE + 0x24)) |
Bryan O'Donoghue | 529fd57 | 2018-01-12 12:40:17 +0000 | [diff] [blame] | 210 | #define HAB_RVT_FAILSAFE (*(uint32_t *)(HAB_RVT_BASE + 0x28)) |
Stefano Babic | 1440442 | 2014-06-10 10:26:22 +0200 | [diff] [blame] | 211 | |
Peng Fan | 4f3cf8f | 2021-03-25 17:30:07 +0800 | [diff] [blame] | 212 | #endif /*CONFIG_ARM64*/ |
| 213 | |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 214 | #define HAB_CID_ROM 0 /**< ROM Caller ID */ |
| 215 | #define HAB_CID_UBOOT 1 /**< UBOOT Caller ID*/ |
Ulises Cardenas | 8df2acd | 2015-07-02 21:26:30 -0500 | [diff] [blame] | 216 | |
Sjoerd Simons | 27f3fae | 2019-06-18 23:08:59 +0200 | [diff] [blame] | 217 | #define HAB_TAG_RVT 0xDD /* ROM Vector Table */ |
Utkarsh Gupta | 2b1f414 | 2018-02-20 01:19:24 +0000 | [diff] [blame] | 218 | #define HAB_CMD_HDR 0xD4 /* CSF Header */ |
Utkarsh Gupta | 09af35c | 2018-02-20 01:19:25 +0000 | [diff] [blame] | 219 | #define HAB_CMD_WRT_DAT 0xCC /* Write Data command tag */ |
| 220 | #define HAB_CMD_CHK_DAT 0xCF /* Check Data command tag */ |
| 221 | #define HAB_CMD_SET 0xB1 /* Set command tag */ |
| 222 | #define HAB_PAR_MID 0x01 /* MID parameter value */ |
Utkarsh Gupta | 2b1f414 | 2018-02-20 01:19:24 +0000 | [diff] [blame] | 223 | |
Bryan O'Donoghue | f6bbd37 | 2018-01-12 12:39:59 +0000 | [diff] [blame] | 224 | #define IVT_SIZE 0x20 |
Bryan O'Donoghue | 73f9a72 | 2018-01-12 12:40:00 +0000 | [diff] [blame] | 225 | #define CSF_PAD_SIZE 0x2000 |
Bryan O'Donoghue | f6bbd37 | 2018-01-12 12:39:59 +0000 | [diff] [blame] | 226 | |
Breno Lima | 3adb6f0 | 2021-03-25 17:30:13 +0800 | [diff] [blame] | 227 | #define HAB_TAG_EVT 0xDB |
| 228 | #define HAB_TAG_EVT_DEF 0x0C |
| 229 | |
| 230 | #define HAB_MAJ_VER 0x40 |
| 231 | #define HAB_MAJ_MASK 0xF0 |
| 232 | |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 233 | /* ----------- end of HAB API updates ------------*/ |
| 234 | |
Bryan O'Donoghue | 1efba6a | 2018-01-12 12:40:13 +0000 | [diff] [blame] | 235 | int imx_hab_authenticate_image(uint32_t ddr_start, uint32_t image_size, |
| 236 | uint32_t ivt_offset); |
Bryan O'Donoghue | 47b3f34 | 2018-01-12 12:40:16 +0000 | [diff] [blame] | 237 | bool imx_hab_is_enabled(void); |
Sven Ebenfeld | eba5e33 | 2016-11-06 16:37:55 +0100 | [diff] [blame] | 238 | |
Stefano Babic | 83fd858 | 2013-06-28 00:20:21 +0200 | [diff] [blame] | 239 | #endif |