1 /* 2 * Copyright 2021 NXP 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 * 7 */ 8 9 #ifndef _FSL_FLASH_FFR_H_ 10 #define _FSL_FLASH_FFR_H_ 11 12 #include "fsl_flash.h" 13 14 /*! 15 * @addtogroup flash_ffr_driver 16 * @{ 17 */ 18 19 /*! @file */ 20 21 /******************************************************************************* 22 * Definitions 23 ******************************************************************************/ 24 25 /*! @brief Alignment(down) utility. */ 26 #if !defined(ALIGN_DOWN) 27 #define ALIGN_DOWN(x, a) ((x) & (uint32_t)(-((int32_t)(a)))) 28 #endif 29 30 /*! @brief Alignment(up) utility. */ 31 #if !defined(ALIGN_UP) 32 #define ALIGN_UP(x, a) (-((int32_t)((uint32_t)(-((int32_t)(x))) & (uint32_t)(-((int32_t)(a)))))) 33 #endif 34 35 #define FLASH_FFR_MAX_PAGE_SIZE (512U) 36 #define FLASH_FFR_HASH_DIGEST_SIZE (32U) 37 #define FLASH_FFR_IV_CODE_SIZE (52U) 38 39 enum flash_ffr_page_offset 40 { 41 kFfrPageOffset_CFPA = 0U, /*!< Customer In-Field programmed area*/ 42 kFfrPageOffset_CFPA_Scratch = 0U, /*!< CFPA Scratch page */ 43 kFfrPageOffset_CFPA_CfgPing = 1U, /*!< CFPA Configuration area (Ping page)*/ 44 kFfrPageOffset_CFPA_CfgPong = 2U, /*!< Same as CFPA page (Pong page)*/ 45 46 #if defined(LPC55S36_SERIES) 47 kFfrPageOffset_CMPA = 3U, /*!< Customer Manufacturing programmed area*/ 48 kFfrPageOffset_CMPA_Cfg = 3U, /*!< CMPA Configuration area (Part of CMPA)*/ 49 kFfrPageOffset_CMPA_Csr_Key = 4U, /*!< Customer Key Store Area (Part of CMPA)*/ 50 51 kFfrPageOffset_NMPA_Key = 5U, /*!< Key Store area (Part of NMPA)*/ 52 kFfrPageOffset_NMPA = 5U, /*!< NXP Manufacturing programmed area*/ 53 kFfrPageOffset_NMPA_Romcp = 8U, /*!< ROM patch area (Part of NMPA)*/ 54 kFfrPageOffset_NMPA_Repair = 10U, /*!< Repair area (Part of NMPA)*/ 55 kFfrPageOffset_NMPA_Cfg = 16U, /*!< NMPA configuration area (Part of NMPA)*/ 56 kFfrPageOffset_NMPA_End = 17U, /*!< Reserved (Part of NMPA)*/ 57 #else 58 kFfrPageOffset_CMPA = 3U, /*!< Customer Manufacturing programmed area*/ 59 kFfrPageOffset_CMPA_Cfg = 3U, /*!< CMPA Configuration area (Part of CMPA)*/ 60 kFfrPageOffset_CMPA_Key = 4U, /*!< Key Store area (Part of CMPA)*/ 61 62 kFfrPageOffset_NMPA = 7U, /*!< NXP Manufacturing programmed area*/ 63 kFfrPageOffset_NMPA_Romcp = 7U, /*!< ROM patch area (Part of NMPA)*/ 64 kFfrPageOffset_NMPA_Repair = 9U, /*!< Repair area (Part of NMPA)*/ 65 kFfrPageOffset_NMPA_Cfg = 15U, /*!< NMPA configuration area (Part of NMPA)*/ 66 kFfrPageOffset_NMPA_End = 16U, /*!< Reserved (Part of NMPA)*/ 67 #endif 68 69 }; 70 71 enum flash_ffr_page_num 72 { 73 kFfrPageNum_CFPA = 3U, /*!< Customer In-Field programmed area*/ 74 #if defined(LPC55S36_SERIES) 75 kFfrPageNum_CMPA = 2U, /*!< Customer Manufacturing programmed area*/ 76 #else 77 kFfrPageNum_CMPA = 4U, /*!< Customer Manufacturing programmed area*/ 78 #endif 79 kFfrPageNum_NMPA = 13U, /*!< NXP Manufacturing programmed area*/ 80 81 kFfrPageNum_CMPA_Cfg = 1U, 82 kFfrPageNum_NMPA_Romcp = 2U, 83 84 kFfrPageNum_SpecArea = kFfrPageNum_CFPA + kFfrPageNum_CMPA, 85 kFfrPageNum_Total = (kFfrPageNum_CFPA + kFfrPageNum_CMPA + kFfrPageNum_NMPA), 86 }; 87 88 enum flash_ffr_block_size 89 { 90 kFfrBlockSize_Key = 52U, 91 #if defined(LPC55S36_SERIES) 92 kFfrBlockSize_ActivationCode = 996U, 93 #else 94 kFfrBlockSize_ActivationCode = 1192U, 95 #endif 96 }; 97 98 enum cfpa_cfg_cmpa_prog_status 99 { 100 kFfrCmpaProgStatus_Idle = 0x0U, 101 kFfrCmpaProgStatus_InProgress = 0x5CC55AA5U, 102 }; 103 104 typedef enum 105 { 106 kFfrCmpaProgProcess_Pre = 0x0U, 107 kFfrCmpaProgProcess_Post = 0xFFFFFFFFU, 108 } cmpa_prog_process_t; 109 110 typedef struct 111 { 112 uint32_t header; /*!< [0x000-0x003] */ 113 uint32_t version; /*!< [0x004-0x007] */ 114 uint32_t secureFwVersion; /*!< [0x008-0x00b] */ 115 uint32_t nsFwVersion; /*!< [0x00c-0x00f] */ 116 uint32_t imageKeyRevoke; /*!< [0x010-0x013] */ 117 uint32_t ivPrince[3]; /*!< [0x014-0x01f] */ 118 uint32_t ivIped[4]; /*!< [0x020-0x02f] */ 119 uint32_t custCtr[8]; /*!< [0x030-0x03f] */ 120 uint32_t rotkhRevoke; /*!< [0x018-0x01b] */ 121 uint32_t vendorUsage; /*!< [0x050-0x053] */ 122 uint32_t dcfgNsPin; /*!< [0x058-0x05b] */ 123 uint32_t dcfgNsDflt; /*!< [0x05c-0x05f] */ 124 uint32_t enableFaMode; /*!< [0x060-0x063] */ 125 uint32_t cmpaProgInProgress; /*!< [0x064-0x067] */ 126 uint32_t imageCmacUpdateEn; /*!< [0x068-0x06b] */ 127 uint32_t cfpaVersion; /*!< [0x06c-0x06f] */ 128 uint32_t img0Cmac[4]; /*!< [0x070-0x07f] */ 129 uint32_t img1Cmac[4]; /*!< [0x080-0x08f] */ 130 uint8_t reserved2[348]; /*!< [0x090-0x1eb] */ 131 uint32_t cfpaCrc; /*!< [0x1eb-0x1ef] */ 132 uint32_t cfpaCmac[4]; /*!< [0x1f0-0x1ff] */ 133 } cfpa_cfg_info_t; 134 135 #define FFR_BOOTCFG_USBSPEED_SHIFT (9U) 136 #define FFR_BOOTCFG_USBSPEED_MASK (0x3u << FFR_BOOTCFG_USBSPEED_SHIFT) 137 #define FFR_BOOTCFG_USBSPEED_NMPASEL0 (0x0U) 138 #define FFR_BOOTCFG_USBSPEED_FS (0x1U) 139 #define FFR_BOOTCFG_USBSPEED_HS (0x2U) 140 #define FFR_BOOTCFG_USBSPEED_NMPASEL3 (0x3U) 141 142 #define FFR_BOOTCFG_BOOTSPEED_MASK (0x18U) 143 #define FFR_BOOTCFG_BOOTSPEED_SHIFT (7U) 144 #define FFR_BOOTCFG_BOOTSPEED_NMPASEL (0x0U) 145 #define FFR_BOOTCFG_BOOTSPEED_48MHZ (0x1U) 146 #define FFR_BOOTCFG_BOOTSPEED_96MHZ (0x2U) 147 148 #define FFR_USBID_VENDORID_MASK (0xFFFFU) 149 #define FFR_USBID_VENDORID_SHIFT (0U) 150 #define FFR_USBID_PRODUCTID_MASK (0xFFFF0000U) 151 #define FFR_USBID_PRODUCTID_SHIFT (16U) 152 153 #define FFR_IMAGE0_CMAC_UPDATE_MASK (0x1U) 154 #define FFR_IMAGE1_CMAC_UPDATE_MASK (0x2U) 155 156 typedef struct 157 { 158 uint32_t bootCfg; /*!< [0x000-0x003] */ 159 uint32_t spiFlashCanCfg; /*!< [0x004-0x007] */ 160 struct 161 { 162 uint16_t vid; 163 uint16_t pid; 164 } usbId; /*!< [0x008-0x00b] */ 165 uint32_t sdioCfg; /*!< [0x00c-0x00f] */ 166 uint32_t dcfgPin; /*!< [0x010-0x013] */ 167 uint32_t dcfgDflt; /*!< [0x014-0x017] */ 168 uint32_t dapVendorUsage; /*!< [0x018-0x01b] */ 169 uint32_t secureBootCfg; /*!< [0x01c-0x01f] */ 170 uint32_t princeBaseAddr; /*!< [0x020-0x023] */ 171 uint32_t princeSr[3]; /*!< [0x024-0x02f] */ 172 uint32_t xtal32kCapBankTrim; /*!< [0x030-0x033] */ 173 uint32_t xtal16mCapBankTrim; /*!< [0x034-0x037] */ 174 uint32_t flashRemapSize; /*!< [0x038-0x03b] */ 175 uint32_t flashRemapOffset; /*!< [0x03c-0x03f] */ 176 uint32_t princeXom[3]; /*!< [0x040-0x04b] */ 177 uint32_t rokthUsage; /*!< [0x04c-0x04f] */ 178 uint32_t rotkh[12]; /*!< [0x050-0x07f] */ 179 uint32_t flexspiCfg0; /*!< [0x080-0x083] */ 180 uint32_t flexspiCfg1; /*!< [0x084-0x087] */ 181 uint8_t reserved1[8]; /*!< [0x088-0x08f] */ 182 struct 183 { 184 uint32_t ipedStartAddr; /*!< [0x090-0x093] */ 185 uint32_t ipedEndAddr; /*!< [0x094-0x097] */ 186 } ipedRegions[4]; 187 188 uint8_t reserved2[320]; /*!< [0x0b0-0x1ef] */ 189 uint32_t cmpaCmac[4]; /*!< [0x1f0-0x1ff] */ 190 } cmpa_cfg_info_t; 191 192 typedef struct 193 { 194 uint32_t header; 195 uint8_t reserved[4]; 196 } cmpa_key_store_header_t; 197 198 #define FFR_SYSTEM_SPEED_CODE_MASK (0x3U) 199 #define FFR_SYSTEM_SPEED_CODE_SHIFT (0U) 200 #define FFR_SYSTEM_SPEED_CODE_FRO12MHZ_12MHZ (0x0U) 201 #define FFR_SYSTEM_SPEED_CODE_FROHF96MHZ_24MHZ (0x1U) 202 #define FFR_SYSTEM_SPEED_CODE_FROHF96MHZ_48MHZ (0x2U) 203 #define FFR_SYSTEM_SPEED_CODE_FROHF96MHZ_96MHZ (0x3U) 204 205 #define FFR_USBCFG_USBSPEED_HS (0x0U) 206 #define FFR_USBCFG_USBSPEED_FS (0x1U) 207 #define FFR_USBCFG_USBSPEED_NO (0x2U) 208 209 #define FFR_MCAN_BAUDRATE_MASK (0xF0000U) 210 #define FFR_MCAN_BAUDRATE_SHIFT (16U) 211 212 #define FFR_PERIPHERALCFG_PERI_MASK (0x7FFFFFFFU) 213 #define FFR_PERIPHERALCFG_PERI_SHIFT (0U) 214 #define FFR_PERIPHERALCFG_COREEN_MASK (0x10000000U) 215 #define FFR_PERIPHERALCFG_COREEN_SHIFT (31U) 216 217 #define FFR_PUF_SRAM_CONFIG_MASK (0x3FFFF07) 218 #define FFR_PUF_SRAM_CONFIG_MASK_SHIFT (0U) 219 #define FFR_PUF_SRAM_VALID_MASK (0x1U) 220 #define FFR_PUF_SRAM_VALID_SHIFT (0U) 221 #define FFR_PUF_SRAM_MODE_MASK (0x2U) 222 #define FFR_PUF_SRAM_MODE_SHIFT (1U) 223 #define FFR_PUF_SRAM_CKGATING_MASK (0x4U) 224 #define FFR_PUF_SRAM_CKGATING_SHIFT (2U) 225 #define FFR_PUF_SRAM_SMB_MASK (0x300U) 226 #define FFR_PUF_SRAM_SMB_SHIFT (8U) 227 #define FFR_PUF_SRAM_RM_MASK (0x1C00U) 228 #define FFR_PUF_SRAM_RM_SHIFT (10U) 229 #define FFR_PUF_SRAM_WM_MASK (0xE000U) 230 #define FFR_PUF_SRAM_WM_SHIFT (13U) 231 #define FFR_PUF_SRAM_WRME_MASK (0x10000U) 232 #define FFR_PUF_SRAM_WRME_SHIFT (16U) 233 #define FFR_PUF_SRAM_RAEN_MASK (0x20000U) 234 #define FFR_PUF_SRAM_RAEN_SHIFT (17U) 235 #define FFR_PUF_SRAM_RAM_MASK (0x3C0000U) 236 #define FFR_PUF_SRAM_RAM_SHIFT (18U) 237 #define FFR_PUF_SRAM_WAEN_MASK (0x400000U) 238 #define FFR_PUF_SRAM_WAEN_SHIFT (22U) 239 #define FFR_PUF_SRAM_WAM_MASK (0x1800000U) 240 #define FFR_PUF_SRAM_WAM_SHIFT (23U) 241 #define FFR_PUF_SRAM_STBP_MASK (0x2000000U) 242 #define FFR_PUF_SRAM_STBP_SHIFT (25U) 243 244 typedef struct 245 { 246 uint32_t fro32kCfg; /*!< [0x000-0x003] */ 247 uint32_t puf_cfg; /*!< [0x004-0x007] */ 248 uint32_t bod; /*!< [0x008-0x00b] */ 249 uint32_t trim; /*!< [0x00c-0x00f] */ 250 uint32_t deviceID; /*!< [0x010-0x03f] */ 251 uint32_t peripheralCfg; /*!< [0x014-0x017] */ 252 uint32_t dcdPowerProFileLOW[2]; /*!< [0x018-0x01f] */ 253 uint32_t deviceType; /*!< [0x020-0x023] */ 254 uint32_t ldo_ao; /*!< [0x024-0x027] */ 255 uint32_t gdetDelayCfg; /*!< [0x028-0x02b] */ 256 uint32_t gdetMargin; /*!< [0x02c-0x02f] */ 257 uint32_t gdetTrim1; /*!< [0x030-0x033] */ 258 uint32_t gdetEanble1; /*!< [0x034-0x037] */ 259 uint32_t gdetCtrl1; /*!< [0x038-0x03b] */ 260 uint32_t gdetUpdateTimer; /*!< [0x03c-0x03f] */ 261 uint32_t GpoDataChecksum[4]; /*!< [0x040-0x04f] */ 262 uint32_t finalTestBatchId[4]; /*!< [0x050-0x05f] */ 263 uint32_t ecidBackup[4]; /*!< [0x060-0x06f] */ 264 uint32_t uuid[4]; /*!< [0x070-0x07f] */ 265 uint32_t reserved1[7]; /*!< [0x080-0x09b] */ 266 struct 267 { 268 uint8_t xo32mReadyTimeoutInMs; 269 uint8_t usbSpeed; 270 uint8_t reserved[2]; 271 } usbCfg; /*!< [0x09c-0x09f] */ 272 uint32_t reserved2[80]; /*!< [0x0a0-0x1df] */ 273 uint8_t cmac[16]; /*!< [0x1e0-0x1ef] */ 274 uint32_t pageChecksum[4]; /*!< [0x1f0-0x1ff] */ 275 } nmpa_cfg_info_t; 276 277 typedef struct 278 { 279 uint8_t reserved[1][FLASH_FFR_MAX_PAGE_SIZE]; 280 } ffr_key_store_t; 281 282 typedef enum 283 { 284 kFFR_KeyTypeSbkek = 0x00U, 285 kFFR_KeyTypeUser = 0x01U, 286 kFFR_KeyTypeUds = 0x02U, 287 kFFR_KeyTypePrinceRegion0 = 0x03U, 288 kFFR_KeyTypePrinceRegion1 = 0x04U, 289 kFFR_KeyTypePrinceRegion2 = 0x05U, 290 } ffr_key_type_t; 291 292 typedef enum 293 { 294 kFFR_BankTypeBank0_NMPA = 0x00U, 295 kFFR_BankTypeBank1_CMPA = 0x01U, 296 kFFR_BankTypeBank2_CFPA = 0x02U 297 } ffr_bank_type_t; 298 299 /******************************************************************************* 300 * API 301 ******************************************************************************/ 302 303 #if defined(__cplusplus) 304 extern "C" { 305 #endif 306 307 /*! 308 * @name FFR APIs 309 * @{ 310 */ 311 312 /*! 313 * @brief Initializes the global FFR properties structure members. 314 * 315 * @param config A pointer to the storage for the driver runtime state. 316 * 317 * @retval #kStatus_FLASH_Success API was executed successfully. 318 */ 319 status_t FFR_Init(flash_config_t *config); 320 321 /*! 322 * @brief Enable firewall for all flash banks. 323 * 324 * CFPA, CMPA, and NMPA flash areas region will be locked, After this function executed; 325 * Unless the board is reset again. 326 * 327 * @param config A pointer to the storage for the driver runtime state. 328 * 329 * @retval #kStatus_FLASH_Success An invalid argument is provided. 330 */ 331 status_t FFR_Lock(flash_config_t *config); 332 333 /*! 334 * @brief Initialize the Security Library for FFR driver. 335 * 336 * @param config A pointer to the storage for the driver runtime state. 337 * @param context A pointer to the storage for the nboot data. 338 * 339 * @retval #kStatus_FLASH_Success An invalid argument is provided. 340 * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided. 341 */ 342 status_t FFR_SecLibInit(flash_config_t *config, uint32_t *context); 343 344 status_t FFR_GetCustKeystoreData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len); 345 346 /*! 347 * @brief APIs to access CFPA pages 348 * 349 * This routine will erase CFPA and program the CFPA page with passed data. 350 * 351 * @param config A pointer to the storage for the driver runtime state. 352 * 353 * @retval #kStatus_FLASH_Success The desire page-data were programed successfully into CFPA. 354 * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided. 355 * @retval #kStatus_FLASH_FfrBankIsLocked The FFR bank region is locked. 356 * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided. 357 * @retval #kStatus_FTFx_AddressError Address is out of range. 358 * @retval #kStatus_FLASH_ReadHidingAreaDisallowed Flash hiding read is not allowed 359 * @retval #kStatus_FLASH_CfpaScratchPageInvalid CFPA Scratch Page is invalid 360 * @retval #kStatus_FLASH_CfpaVersionRollbackDisallowed CFPA version rollback is not allowed 361 * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline 362 * @retval #kStatus_FLASH_EraseKeyError API erase key is invalid. 363 * @retval #kStatus_FLASH_ModifyProtectedAreaDisallowed Flash firewall page locked erase and program are not allowed 364 * @retval #kStatus_FLASH_FfrBankIsLocked The CFPA was locked. 365 * @retval #kStatus_FLASH_OutOfDateCfpaPage It is not newest CFPA page. 366 * @retval #kStatus_FLASH_CommandFailure access error. 367 * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported 368 * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution. 369 * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read. 370 */ 371 status_t FFR_CustomerPagesInit(flash_config_t *config); 372 373 /*! 374 * @brief APIs to access CFPA pages 375 * 376 * This routine will erase CFPA and program the CFPA page with passed data. 377 * 378 * @param config A pointer to the storage for the driver runtime state. 379 * @param page_data A pointer to the source buffer of data that is to be programmed 380 * into the CFPA. 381 * @param valid_len The length, given in bytes, to be programmed. 382 * 383 * @retval #kStatus_FLASH_Success The desire page-data were programed successfully into CFPA. 384 * @retval #kStatus_FLASH_SizeError Error size 385 * @retval #kStatus_FLASH_ReadHidingAreaDisallowed Flash hiding read is not allowed 386 * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline 387 * @retval #kStatus_FLASH_ModifyProtectedAreaDisallowed Flash firewall page locked erase and program are not allowed 388 * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided. 389 * @retval #kStatus_FTFx_AddressError Address is out of range. 390 * @retval #kStatus_FLASH_FfrBankIsLocked The CFPA was locked. 391 * @retval #kStatus_FLASH_OutOfDateCfpaPage It is not newest CFPA page. 392 * @retval #kStatus_FLASH_CommandFailure access error. 393 * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported 394 * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution. 395 * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read. 396 */ 397 status_t FFR_InfieldPageWrite(flash_config_t *config, uint8_t *page_data, uint32_t valid_len); 398 399 /*! 400 * @brief APIs to access CFPA pages 401 * 402 * Generic read function, used by customer to read data stored in 'Customer In-field Page'. 403 * 404 * @param config A pointer to the storage for the driver runtime state. 405 * @param pData A pointer to the dest buffer of data that is to be read from 'Customer In-field Page'. 406 * @param offset An offset from the 'Customer In-field Page' start address. 407 * @param len The length, given in bytes, to be read. 408 * 409 * @retval #kStatus_FLASH_Success Get data from 'Customer In-field Page'. 410 * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided. 411 * @retval #kStatus_FTFx_AddressError Address is out of range. 412 * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline. 413 * @retval #kStatus_FLASH_ReadHidingAreaDisallowed Flash hiding read is not allowed 414 * @retval #kStatus_FLASH_CommandFailure access error. 415 * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported 416 * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution. 417 * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read. 418 */ 419 status_t FFR_GetCustomerInfieldData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len); 420 421 /*! 422 * @brief APIs to access CMPA pages 423 * 424 * This routine will erase "customer factory page" and program the page with passed data. 425 * If 'seal_part' parameter is TRUE then the routine will compute SHA256 hash of 426 * the page contents and then programs the pages. 427 * 1.During development customer code uses this API with 'seal_part' set to FALSE. 428 * 2.During manufacturing this parameter should be set to TRUE to seal the part 429 * from further modifications 430 * 3.This routine checks if the page is sealed or not. A page is said to be sealed if 431 * the SHA256 value in the page has non-zero value. On boot ROM locks the firewall for 432 * the region if hash is programmed anyways. So, write/erase commands will fail eventually. 433 * 434 * @param config A pointer to the storage for the driver runtime state. 435 * @param page_data A pointer to the source buffer of data that is to be programmed 436 * into the "customer factory page". 437 * @param seal_part Set fasle for During development customer code. 438 * 439 * @retval #kStatus_FLASH_Success The desire page-data were programed successfully into CMPA. 440 * @retval #kStatus_FLASH_InvalidArgument Parameter is not aligned with the specified baseline. 441 * @retval #kStatus_FTFx_AddressError Address is out of range. 442 * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline. 443 * @retval #kStatus_FLASH_EraseKeyError API erase key is invalid. 444 * @retval #kStatus_FLASH_ModifyProtectedAreaDisallowed Flash firewall page locked erase and program are not allowed 445 * @retval #kStatus_Fail Generic status for Fail. 446 * @retval #kStatus_FLASH_CommandFailure access error. 447 * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported 448 * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution. 449 * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read. 450 */ 451 status_t FFR_CustFactoryPageWrite(flash_config_t *config, uint8_t *page_data, bool seal_part); 452 453 /*! 454 * @brief APIs to access CMPA page 455 * 456 * Read data stored in 'Customer Factory CFG Page'. 457 * 458 * @param config A pointer to the storage for the driver runtime state. 459 * @param pData A pointer to the dest buffer of data that is to be read 460 * from the Customer Factory CFG Page. 461 * @param offset Address offset relative to the CMPA area. 462 * @param len The length, given in bytes to be read. 463 * 464 * @retval #kStatus_FLASH_Success Get data from 'Customer Factory CFG Page'. 465 * @retval #kStatus_FLASH_InvalidArgument Parameter is not aligned with the specified baseline. 466 * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline. 467 * @retval #kStatus_FTFx_AddressError Address is out of range. 468 * @retval #kStatus_FLASH_CommandFailure access error. 469 * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported 470 * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution. 471 * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read. 472 * @retval #kStatus_FLASH_ReadHidingAreaDisallowed Flash hiding read is not allowed 473 */ 474 status_t FFR_GetCustomerData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len); 475 476 /*! 477 * @brief The API is used for getting the customer key store data from the customer key store region(0x3e400 �C 0x3e600), 478 * and the API should be called after the FLASH_Init and FFR_Init. 479 * 480 * @param config A pointer to the storage for the driver runtime state. 481 * @param pData A pointer to the dest buffer of data that is to be read 482 * from the Customer Factory CFG Page. 483 * @param offset Address offset relative to the CMPA area. 484 * @param len The length, given in bytes to be read. 485 * 486 * @retval #kStatus_FLASH_Success Get data from 'Customer Factory CFG Page'. 487 * @retval #kStatus_FLASH_InvalidArgument Parameter is not aligned with the specified baseline. 488 * @retval #kStatus_FTFx_AddressError Address is out of range. 489 * @retval #kStatus_FLASH_AddressError Address is out of range 490 * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline. 491 * @retval #kStatus_FLASH_ReadHidingAreaDisallowed Flash hiding read is not allowed 492 * @retval #kStatus_FLASH_CommandFailure access error. 493 * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported 494 * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution. 495 * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read. 496 */ 497 status_t FFR_GetCustKeystoreData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len); 498 499 /*! 500 * @brief This routine writes the 3 pages allocated for Key store data. 501 * 502 * @param config A pointer to the storage for the driver runtime state. 503 * @param pKeyStore A pointer to the source buffer of data that is to be programmed 504 * into the "Key store". 505 * 506 * @retval #kStatus_FLASH_Success Get data from 'Customer Factory CFG Page'. 507 * @retval #kStatus_FLASH_InvalidArgument Parameter is not aligned with the specified baseline. 508 * @retval #kStatus_FLASH_CommandFailure access error. 509 * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported 510 * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution. 511 * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read. 512 * @retval #kStatus_FLASH_SealedFfrRegion The FFR region is sealed. 513 * @retval #kStatus_FLASH_FfrBankIsLocked The FFR bank region is locked. 514 * @retval #kStatus_FLASH_AddressError Address is out of range 515 * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline. 516 * @retval #kStatus_FLASH_ModifyProtectedAreaDisallowed Flash firewall page locked erase and program are not allowed 517 */ 518 status_t FFR_CustKeystoreWrite(flash_config_t *config, ffr_key_store_t *pKeyStore); 519 520 /*! 521 * @brief APIs to access CMPA page 522 * 523 * 1.SW should use this API routine to get the UUID of the chip. 524 * 2.Calling routine should pass a pointer to buffer which can hold 128-bit value. 525 * 526 * @retval #kStatus_FLASH_Success Get data from 'Customer Factory CFG Page'. 527 * @retval #kStatus_FLASH_InvalidArgument Parameter is not aligned with the specified baseline. 528 * @retval #kStatus_FLASH_ReadHidingAreaDisallowed Flash hiding read is not allowed 529 * @retval #kStatus_FLASH_CommandFailure Run-time error during command execution. 530 * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported 531 * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read. 532 */ 533 status_t FFR_GetUUID(flash_config_t *config, uint8_t *uuid); 534 535 /*! 536 * @brief This routine writes the 3 pages allocated for Key store data, 537 * 538 * 1.Used during manufacturing. Should write pages when 'customer factory page' is not in sealed state. 539 * 2.Optional routines to set individual data members (activation code, key codes etc) to construct 540 * the key store structure in RAM before committing it to IFR/FFR. 541 * 542 * @param config A pointer to the storage for the driver runtime state. 543 * @param pKeyStore A Pointer to the 3 pages allocated for Key store data. 544 * that will be written to 'customer factory page'. 545 * 546 * @retval #kStatus_FLASH_Success The key were programed successfully into FFR. 547 * @retval #kStatus_FLASH_InvalidArgument Parameter is not aligned with the specified baseline. 548 * @retval #kStatus_FTFx_AddressError Address is out of range. 549 * @retval #kStatus_FLASH_CommandFailure access error. 550 * @retval #kStatus_FLASH_SealedFfrRegion The FFR region is sealed. 551 * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline. 552 * @retval #kStatus_FLASH_AddressError Address is out of range 553 * @retval #kStatus_FLASH_EraseKeyError API erase key is invalid. 554 * @retval #kStatus_FLASH_ModifyProtectedAreaDisallowed Flash firewall page locked erase and program are not allowed 555 * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported 556 * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read. 557 */ 558 status_t FFR_CustKeystoreWrite(flash_config_t *config, ffr_key_store_t *pKeyStore); 559 560 /*@}*/ 561 562 #ifdef __cplusplus 563 } 564 #endif 565 566 /*@}*/ 567 568 #endif /*! _FSL_FLASH_FFR_H_ */ 569