1 /* 2 * Copyright 2020 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #include "fsl_common.h" 10 #include "nvm_adapter.h" 11 12 #if gNvStorageIncluded_d 13 #if (defined(__CC_ARM) || defined(__ARMCC_VERSION)) 14 15 extern uint32_t Load$$ER_NVM_ADAPTER_TABLE$$Base[]; 16 extern uint32_t Load$$ER_NVM_ADAPTER_TABLE$$Limit[]; 17 18 #define gNVM_ADAPTER_TABLE_startAddr_c ((nvm_adapter_table_t *)Load$$ER_NVM_ADAPTER_TABLE$$Base) 19 #define gNVM_ADAPTER_TABLE_endAddr_c ((nvm_adapter_table_t *)Load$$ER_NVM_ADAPTER_TABLE$$Limit) 20 21 #elif defined(__GNUC__) 22 extern uint32_t __start_NVM_ADAPTER_TABLE[]; 23 extern uint32_t __stop_NVM_ADAPTER_TABLE[]; 24 #define gNVM_ADAPTER_TABLE_startAddr_c ((nvm_adapter_table_t *)(void *)__start_NVM_ADAPTER_TABLE) 25 #define gNVM_ADAPTER_TABLE_endAddr_c ((nvm_adapter_table_t *)(void *)__stop_NVM_ADAPTER_TABLE) 26 #elif (defined(__IAR_SYSTEMS_ICC__)) 27 #define gNVM_ADAPTER_TABLE_startAddr_c ((nvm_adapter_table_t *)__section_begin("NVM_ADAPTER_TABLE")) 28 #define gNVM_ADAPTER_TABLE_endAddr_c ((nvm_adapter_table_t *)__section_end("NVM_ADAPTER_TABLE")) 29 #else 30 #define gNVM_ADAPTER_TABLE_startAddr_c ((nvm_adapter_table_t *)0) 31 #define gNVM_ADAPTER_TABLE_endAddr_c ((nvm_adapter_table_t *)0) 32 #warning Module information will not be stored! 33 #endif 34 NVM_AdapterInit(void)35int NVM_AdapterInit(void) 36 { 37 static uint8_t initialized = 0; 38 nvm_adapter_table_t *start; 39 uint32_t startAddress = (uint32_t)gNVM_ADAPTER_TABLE_startAddr_c; 40 uint32_t endAddress = (uint32_t)gNVM_ADAPTER_TABLE_endAddr_c; 41 int err = 0; 42 43 if (0U == initialized) 44 { 45 initialized = 1; 46 start = (nvm_adapter_table_t *)startAddress; 47 48 while ((uint32_t)start < endAddress) 49 { 50 if (NULL != start->init) 51 { 52 err = start->init(); 53 if (0 != err) 54 { 55 break; 56 } 57 } 58 start++; 59 } 60 if (0 == err) 61 { 62 if (gNVM_OK_c != NvModuleInit()) 63 { 64 err = -1; 65 } 66 } 67 } 68 else 69 { 70 err = -1; 71 } 72 return err; 73 } 74 NVM_AdapterLoad(void)75int NVM_AdapterLoad(void) 76 { 77 nvm_adapter_table_t *start; 78 uint32_t startAddress = (uint32_t)gNVM_ADAPTER_TABLE_startAddr_c; 79 uint32_t endAddress = (uint32_t)gNVM_ADAPTER_TABLE_endAddr_c; 80 int err = 0; 81 82 NVM_AdapterInit(); 83 84 start = (nvm_adapter_table_t *)startAddress; 85 86 while ((uint32_t)start < endAddress) 87 { 88 if (NULL != start->load) 89 { 90 err = start->load(); 91 if (0 != err) 92 { 93 break; 94 } 95 } 96 start++; 97 } 98 99 start = (nvm_adapter_table_t *)startAddress; 100 101 while ((uint32_t)start < endAddress) 102 { 103 if (NULL != start->commit) 104 { 105 err = start->commit(); 106 if (0 != err) 107 { 108 break; 109 } 110 } 111 start++; 112 } 113 return err; 114 } 115 116 #endif 117