rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2005 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /***************************************************************************** |
| 37 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * combo_flash_init.c |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * Maui_Software |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * This Module defines the ComboMCP Init function |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | *============================================================================ |
| 55 | * HISTORY |
| 56 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 57 | *------------------------------------------------------------------------------ |
| 58 | * removed! |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * |
| 62 | * removed! |
| 63 | * removed! |
| 64 | * removed! |
| 65 | * |
| 66 | * removed! |
| 67 | * removed! |
| 68 | * removed! |
| 69 | * removed! |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * |
| 73 | * removed! |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * |
| 77 | * removed! |
| 78 | * removed! |
| 79 | * removed! |
| 80 | * |
| 81 | * removed! |
| 82 | * removed! |
| 83 | * removed! |
| 84 | * removed! |
| 85 | * removed! |
| 86 | * removed! |
| 87 | * removed! |
| 88 | * |
| 89 | * removed! |
| 90 | * removed! |
| 91 | * removed! |
| 92 | * |
| 93 | * removed! |
| 94 | * removed! |
| 95 | * removed! |
| 96 | * |
| 97 | * removed! |
| 98 | * removed! |
| 99 | * removed! |
| 100 | * |
| 101 | * removed! |
| 102 | * removed! |
| 103 | * removed! |
| 104 | * |
| 105 | * removed! |
| 106 | * removed! |
| 107 | * removed! |
| 108 | * |
| 109 | * removed! |
| 110 | * removed! |
| 111 | * removed! |
| 112 | * |
| 113 | * removed! |
| 114 | * removed! |
| 115 | * removed! |
| 116 | * |
| 117 | * removed! |
| 118 | * removed! |
| 119 | * removed! |
| 120 | * |
| 121 | * removed! |
| 122 | * removed! |
| 123 | * removed! |
| 124 | * |
| 125 | * removed! |
| 126 | * removed! |
| 127 | * removed! |
| 128 | * |
| 129 | * removed! |
| 130 | * removed! |
| 131 | * removed! |
| 132 | * |
| 133 | * removed! |
| 134 | * removed! |
| 135 | * removed! |
| 136 | * |
| 137 | * removed! |
| 138 | * removed! |
| 139 | * removed! |
| 140 | * |
| 141 | * removed! |
| 142 | * removed! |
| 143 | * removed! |
| 144 | * |
| 145 | * removed! |
| 146 | * removed! |
| 147 | * removed! |
| 148 | * |
| 149 | * removed! |
| 150 | * removed! |
| 151 | * removed! |
| 152 | * |
| 153 | * removed! |
| 154 | * removed! |
| 155 | * removed! |
| 156 | * |
| 157 | * removed! |
| 158 | * removed! |
| 159 | * removed! |
| 160 | * |
| 161 | * |
| 162 | *------------------------------------------------------------------------------ |
| 163 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 164 | *============================================================================ |
| 165 | ****************************************************************************/ |
| 166 | #include "custom_MemoryDevice.h" |
| 167 | #include "flash_opt.h" |
| 168 | |
| 169 | #if defined(__SERIAL_FLASH__) || (defined(_NAND_FLASH_BOOTING_) && defined(__NAND_MDL_APPEND__)) |
| 170 | #include "combo_flash_init.h" |
| 171 | #include "combo_flash_defs.h" |
| 172 | #if (!defined(_NAND_FLASH_BOOTING_)) |
| 173 | #include "flash_cfi.h" |
| 174 | #include "flash_cfi_internal.h" |
| 175 | #include "flash_mtd.h" |
| 176 | #endif |
| 177 | #if defined(NAND_SUPPORT) |
| 178 | #ifdef __UBL__ |
| 179 | extern void NFI_ReadID(kal_uint32 id_num, kal_uint8* id_data); |
| 180 | #else |
| 181 | extern kal_bool DAL_is_initialized; |
| 182 | extern kal_int32 DAL_init (void); |
| 183 | extern void MTD_ReadID(kal_uint32 id_num,kal_uint8* id_data); |
| 184 | #endif |
| 185 | #endif |
| 186 | #if defined(__SERIAL_FLASH__) |
| 187 | #include "flash_sf.h" |
| 188 | #endif |
| 189 | |
| 190 | #if defined(__SV5_ENABLED__) || defined(__SV5X_ENABLED__) |
| 191 | #include "br_GFH_cmem_id_info.h" |
| 192 | #endif /* __SV5_ENABLED__ */ |
| 193 | |
| 194 | //----------------------------------------------------------------------------- |
| 195 | // MCP ID Table |
| 196 | //----------------------------------------------------------------------------- |
| 197 | |
| 198 | //----------------------------------------------------------------------------- |
| 199 | // [Section] RVCT and GCC |
| 200 | //----------------------------------------------------------------------------- |
| 201 | #if defined(__MTK_TARGET__) |
| 202 | #if defined(__SV5_ENABLED__)|| defined(__SV5X_ENABLED__) |
| 203 | #if defined(__UBL__) |
| 204 | #if defined (__MINI_BOOTLOADER__) |
| 205 | #define __sf_section_RODATA_GFH __attribute__ ((section ("BOOTLOADER_GFH_EXT"))) |
| 206 | #elif defined ( __EXT_BOOTLOADER__) |
| 207 | #define __sf_section_RODATA_GFH __attribute__ ((section ("EXT_BOOTLOADER_GFH_EXT"))) |
| 208 | #endif |
| 209 | #else |
| 210 | #define __sf_section_RODATA_GFH __attribute__ ((section ("MAUI_GFH_EXT"))) |
| 211 | #endif |
| 212 | #else // SV3 |
| 213 | // Method1 |
| 214 | // #define __sf_section_RODATA_GFH __attribute__ ((section ("SECOND_PART_RODATA"))) |
| 215 | // Method2 |
| 216 | #define __sf_section_RODATA_GFH |
| 217 | #endif |
| 218 | #else //defined(__MTK_TARGET__) |
| 219 | /* Reserve for MoDIS */ |
| 220 | #define __sf_section_RODATA_GFH |
| 221 | #endif // defined(__MTK_TARGET__) |
| 222 | |
| 223 | #if defined(__MTK_TARGET__) |
| 224 | #define __sf_section_RWDATA_EMI __attribute__ ((section ("EMIINITRW"))) |
| 225 | #define __sf_section_SECOND_PART /* Second part region is removed */ |
| 226 | #define __sf_section_EMI __attribute__ ((section ("EMIINITCODE"))) |
| 227 | #else |
| 228 | /* Reserve for MoDIS */ |
| 229 | #define __sf_section_RWDATA_EMI |
| 230 | #define __sf_section_SECOND_PART |
| 231 | #define __sf_section_EMI |
| 232 | #endif // __MTK_TARGET__ |
| 233 | |
| 234 | |
| 235 | |
| 236 | #define COMBO_MEM_TYPE_MODIFIER __sf_section_RODATA_GFH const |
| 237 | #define COMBO_MEM_INST_NAME combo_mem_id_list |
| 238 | |
| 239 | #if defined(__SV5_ENABLED__) || defined(__SV5X_ENABLED__) |
| 240 | #define COMBO_MEM_TYPE_NAME GFH_CMEM_ID_INFO_v1 |
| 241 | #else |
| 242 | #define COMBO_MEM_TYPE_NAME CMEMEntryIDList |
| 243 | #endif |
| 244 | |
| 245 | #if defined(__SV5_ENABLED__) || defined(__SV5X_ENABLED__) |
| 246 | #define COMBO_MEM_STRUCT_HEAD COMBO_MEM_ID_GFH_HEADER, { COMBO_MEM_ID_VER, COMBO_MEM_DEVICE_COUNT, { |
| 247 | #define COMBO_MEM_STRUCT_FOOT } } |
| 248 | #else |
| 249 | #define COMBO_MEM_STRUCT_HEAD COMBO_MEM_IDENTITY_ID, COMBO_MEM_ID_VER, COMBO_MEM_DEVICE_COUNT, { |
| 250 | #define COMBO_MEM_STRUCT_FOOT } |
| 251 | #endif |
| 252 | |
| 253 | |
| 254 | #include "combo_flash_id.h" // ==== Instantiate ID table |
| 255 | |
| 256 | |
| 257 | |
| 258 | //----------------------------------------------------------------------------- |
| 259 | // External Functions |
| 260 | //----------------------------------------------------------------------------- |
| 261 | extern kal_uint32 custom_get_fat_addr(void); |
| 262 | |
| 263 | //----------------------------------------------------------------------------- |
| 264 | // Internal Functions |
| 265 | //----------------------------------------------------------------------------- |
| 266 | // ===[EMI/SFI Initialization]=== |
| 267 | kal_int32 CMEM_EMIINIT_Index(void); |
| 268 | void CMEM_EMIINIT_ReadID(void *BaseAddr, kal_uint16 *flashid); |
| 269 | |
| 270 | //----------------------------------------------------------------------------- |
| 271 | // Internal Variables |
| 272 | //----------------------------------------------------------------------------- |
| 273 | #define CMEM_INVALID_INDEX -1 |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | //----------------------------------------------------------------------------- |
| 279 | /*! |
| 280 | @brief |
| 281 | Determine whether SF ID is valid. |
| 282 | Apply for MT6250 because after command issue(ex: Read ID), Data pins are in floating, may read trasient value instead of 0x00 or 0xFF. |
| 283 | @retval |
| 284 | KAL_TRUE: the device ID0 is valid. |
| 285 | KAL_FALSE: the device ID0 is not valid. |
| 286 | */ |
| 287 | __sf_section_SECOND_PART kal_bool CMEM_CheckValidDeviceID(kal_uint8 *id) |
| 288 | { |
| 289 | // Serial Flash |
| 290 | #if defined(__SERIAL_FLASH__) |
| 291 | kal_int32 i, j; |
| 292 | const CMEMEntryID *id_list=NULL; |
| 293 | |
| 294 | #if defined(__SV5_ENABLED__) || defined(__SV5X_ENABLED__) |
| 295 | id_list=combo_mem_id_list.m_data.List; |
| 296 | #else |
| 297 | id_list=combo_mem_id_list.List; |
| 298 | #endif |
| 299 | // seach CMEM list for specific Flash ID |
| 300 | for (i=0; i<COMBO_MEM_DEVICE_COUNT; i++) { |
| 301 | // Check 1: Compare ID |
| 302 | for (j=0; j<id_list[i].IDLength; j++) { |
| 303 | if (id_list[i].ID[j]!=id[j]) break; |
| 304 | } |
| 305 | // Check 2: Compare RegionInfo |
| 306 | if (j==id_list[i].IDLength) { |
| 307 | // TBD: Compare RegionInfo |
| 308 | return KAL_TRUE; |
| 309 | } |
| 310 | } |
| 311 | #endif //defined(__SERIAL_FLASH__) |
| 312 | return KAL_FALSE; |
| 313 | } |
| 314 | |
| 315 | //----------------------------------------------------------------------------- |
| 316 | /*! |
| 317 | @brief |
| 318 | Seach device in the combo MCP list by Flash ID. |
| 319 | 1. Read NOR/NAND flash ID |
| 320 | 2. Lookup ID table and return the index to the found entry. |
| 321 | |
| 322 | @retval |
| 323 | The index to the found entry. |
| 324 | -1 : ID not found |
| 325 | @remars |
| 326 | If combo MCP was not turned on, the returned index is always 0. |
| 327 | */ |
| 328 | |
| 329 | __sf_section_SECOND_PART kal_int32 CMEM_Index(void) |
| 330 | { |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | |
| 335 | __sf_section_SECOND_PART const CMEMEntryID *CMEM_GetIDEntry(kal_uint32 index) |
| 336 | { |
| 337 | #if defined(__SV5_ENABLED__) || defined(__SV5X_ENABLED__) |
| 338 | return &combo_mem_id_list.m_data.List[index]; |
| 339 | #else |
| 340 | return &combo_mem_id_list.List[index]; |
| 341 | #endif |
| 342 | } |
| 343 | |
| 344 | |
| 345 | //----------------------------------------------------------------------------- |
| 346 | /*! |
| 347 | @brief |
| 348 | Read Flash ID |
| 349 | @param[in] BaseAddr Base address to the Flash |
| 350 | @param[out] flashid Flash ID |
| 351 | @remarks |
| 352 | This function is only allowed in EMI/SFI init stage. |
| 353 | */ |
| 354 | __sf_section_EMI void CMEM_EMIINIT_ReadID(void *BaseAddr, kal_uint16 *flashid) |
| 355 | { |
| 356 | // Serial Flash |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | |
| 361 | //----------------------------------------------------------------------------- |
| 362 | /*! |
| 363 | @brief |
| 364 | Determine whether SF ID is valid. |
| 365 | Apply for MT6250 because after command issue(ex: Read ID), Data pins are in floating, may read trasient value instead of 0x00 or 0xFF. |
| 366 | @retval |
| 367 | KAL_TRUE: the device ID0 is valid. |
| 368 | KAL_FALSE: the device ID0 is not valid. |
| 369 | */ |
| 370 | __sf_section_EMI kal_bool CMEM_EMIINIT_CheckValidDeviceID(kal_uint8 *id) |
| 371 | { |
| 372 | // Serial Flash |
| 373 | #if defined(__SERIAL_FLASH__) |
| 374 | kal_int32 i, j; |
| 375 | const CMEMEntryID *id_list=NULL; |
| 376 | // seach CMEM list for specific Flash ID |
| 377 | #if defined(__SV5_ENABLED__) || defined(__SV5X_ENABLED__) |
| 378 | id_list=combo_mem_id_list.m_data.List; |
| 379 | #else |
| 380 | id_list=combo_mem_id_list.List; |
| 381 | #endif |
| 382 | |
| 383 | for (i=0; i<COMBO_MEM_DEVICE_COUNT; i++) { |
| 384 | // Check 1: Compare ID |
| 385 | for (j=0; j<id_list[i].IDLength; j++) { |
| 386 | if (id_list[i].ID[j]!=id[j]) break; |
| 387 | } |
| 388 | // Check 2: Compare RegionInfo |
| 389 | if (j==id_list[i].IDLength) { |
| 390 | // TBD: Compare RegionInfo |
| 391 | return KAL_TRUE; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | #endif //defined(__SERIAL_FLASH__) |
| 396 | return KAL_FALSE; |
| 397 | } |
| 398 | |
| 399 | |
| 400 | |
| 401 | //----------------------------------------------------------------------------- |
| 402 | /*! |
| 403 | @brief |
| 404 | Search device ID list |
| 405 | @retval |
| 406 | The index to the found device ID. |
| 407 | -1: device not found |
| 408 | @remarks |
| 409 | This function is only allowed in EMI/SFI init stage. |
| 410 | */ |
| 411 | |
| 412 | __sf_section_EMI kal_int32 CMEM_EMIINIT_Index(void) |
| 413 | { |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | |
| 418 | |
| 419 | #if defined(_NAND_FLASH_BOOTING_) && defined(__NAND_MDL_APPEND__) |
| 420 | kal_bool CMEM_GetflashInfo(kal_uint8* id, CMEMFlashInfo* st) |
| 421 | { |
| 422 | const CMEMEntryID *flash_id_list=NULL; |
| 423 | kal_uint32 icount, l_index; |
| 424 | |
| 425 | if((id == NULL) || (st == NULL)) |
| 426 | return KAL_FALSE; |
| 427 | |
| 428 | #if defined(__SV5_ENABLED__) || defined(__SV5X_ENABLED__) |
| 429 | flash_id_list = combo_mem_id_list.m_data.List; |
| 430 | #else |
| 431 | flash_id_list = combo_mem_id_list.List; |
| 432 | #endif |
| 433 | |
| 434 | for(l_index = 0; l_index < COMBO_MEM_DEVICE_COUNT; l_index++) |
| 435 | { |
| 436 | for(icount = 0; icount < flash_id_list[l_index].IDLength; icount++) |
| 437 | { |
| 438 | if (flash_id_list[l_index].ID[icount] != id[icount]) |
| 439 | break; |
| 440 | } |
| 441 | |
| 442 | if (icount == flash_id_list[l_index].IDLength) |
| 443 | { |
| 444 | break; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | if(l_index == COMBO_MEM_DEVICE_COUNT) |
| 449 | return KAL_FALSE; |
| 450 | |
| 451 | st->block_size = flash_id_list[l_index].FlashDevice_Info.block_size; |
| 452 | st->page_size = flash_id_list[l_index].FlashDevice_Info.page_size; |
| 453 | st->spare_size = flash_id_list[l_index].FlashDevice_Info.spare_size; |
| 454 | |
| 455 | return KAL_TRUE; |
| 456 | } |
| 457 | #endif |
| 458 | |
| 459 | |
| 460 | #endif // defined(__COMBO_MEMORY_SUPPORT__) || defined(__SERIAL_FLASH__) || defined(__NAND_MDL_APPEND__) |