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 | * Filename: |
| 38 | * --------- |
| 39 | * nvram_ltable.c |
| 40 | * |
| 41 | * Project: |
| 42 | * -------- |
| 43 | * MAUI |
| 44 | * |
| 45 | * Description: |
| 46 | * ------------ |
| 47 | * This is |
| 48 | * |
| 49 | * Author: |
| 50 | * ------- |
| 51 | * ------- |
| 52 | * |
| 53 | *============================================================================ |
| 54 | * HISTORY |
| 55 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 56 | *------------------------------------------------------------------------------ |
| 57 | * removed! |
| 58 | * |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * removed! |
| 62 | * removed! |
| 63 | * |
| 64 | * removed! |
| 65 | * removed! |
| 66 | * removed! |
| 67 | * |
| 68 | * removed! |
| 69 | * removed! |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * removed! |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * removed! |
| 78 | * removed! |
| 79 | * |
| 80 | * removed! |
| 81 | * removed! |
| 82 | * removed! |
| 83 | * removed! |
| 84 | * removed! |
| 85 | * removed! |
| 86 | * removed! |
| 87 | * removed! |
| 88 | * removed! |
| 89 | * removed! |
| 90 | * |
| 91 | * removed! |
| 92 | * removed! |
| 93 | * removed! |
| 94 | * removed! |
| 95 | * |
| 96 | * removed! |
| 97 | * removed! |
| 98 | * removed! |
| 99 | * removed! |
| 100 | * |
| 101 | * removed! |
| 102 | * removed! |
| 103 | * removed! |
| 104 | * removed! |
| 105 | * removed! |
| 106 | * removed! |
| 107 | * removed! |
| 108 | * removed! |
| 109 | * |
| 110 | * removed! |
| 111 | * removed! |
| 112 | * |
| 113 | * removed! |
| 114 | * removed! |
| 115 | * |
| 116 | * removed! |
| 117 | * removed! |
| 118 | * removed! |
| 119 | * |
| 120 | * removed! |
| 121 | * removed! |
| 122 | * |
| 123 | * removed! |
| 124 | * removed! |
| 125 | * removed! |
| 126 | * removed! |
| 127 | * |
| 128 | * removed! |
| 129 | * removed! |
| 130 | * removed! |
| 131 | * removed! |
| 132 | * |
| 133 | * removed! |
| 134 | * removed! |
| 135 | * removed! |
| 136 | * removed! |
| 137 | * removed! |
| 138 | * removed! |
| 139 | * |
| 140 | * removed! |
| 141 | * removed! |
| 142 | * removed! |
| 143 | * removed! |
| 144 | * |
| 145 | * removed! |
| 146 | * removed! |
| 147 | * removed! |
| 148 | * removed! |
| 149 | * |
| 150 | * removed! |
| 151 | * removed! |
| 152 | * removed! |
| 153 | * |
| 154 | * removed! |
| 155 | * removed! |
| 156 | * removed! |
| 157 | * |
| 158 | * removed! |
| 159 | * removed! |
| 160 | * removed! |
| 161 | * removed! |
| 162 | * |
| 163 | * removed! |
| 164 | * removed! |
| 165 | * removed! |
| 166 | * removed! |
| 167 | * |
| 168 | * removed! |
| 169 | * removed! |
| 170 | * removed! |
| 171 | * |
| 172 | * removed! |
| 173 | * removed! |
| 174 | * removed! |
| 175 | * |
| 176 | * removed! |
| 177 | * removed! |
| 178 | * removed! |
| 179 | * |
| 180 | * removed! |
| 181 | * removed! |
| 182 | * removed! |
| 183 | * |
| 184 | * removed! |
| 185 | * removed! |
| 186 | * |
| 187 | * removed! |
| 188 | * removed! |
| 189 | * removed! |
| 190 | * |
| 191 | * removed! |
| 192 | * removed! |
| 193 | * removed! |
| 194 | * |
| 195 | * removed! |
| 196 | * removed! |
| 197 | * |
| 198 | * removed! |
| 199 | * removed! |
| 200 | * removed! |
| 201 | * |
| 202 | * removed! |
| 203 | * removed! |
| 204 | * |
| 205 | * removed! |
| 206 | * removed! |
| 207 | * removed! |
| 208 | * |
| 209 | * removed! |
| 210 | * removed! |
| 211 | * removed! |
| 212 | * |
| 213 | * removed! |
| 214 | * removed! |
| 215 | * |
| 216 | * removed! |
| 217 | * removed! |
| 218 | * |
| 219 | * removed! |
| 220 | * removed! |
| 221 | * removed! |
| 222 | * |
| 223 | * removed! |
| 224 | * removed! |
| 225 | * removed! |
| 226 | * |
| 227 | * removed! |
| 228 | * removed! |
| 229 | * removed! |
| 230 | * |
| 231 | * removed! |
| 232 | * removed! |
| 233 | * removed! |
| 234 | * |
| 235 | * removed! |
| 236 | * removed! |
| 237 | * removed! |
| 238 | * |
| 239 | * removed! |
| 240 | * removed! |
| 241 | * removed! |
| 242 | * |
| 243 | * removed! |
| 244 | * removed! |
| 245 | * removed! |
| 246 | * |
| 247 | * removed! |
| 248 | * removed! |
| 249 | * removed! |
| 250 | * |
| 251 | * removed! |
| 252 | * removed! |
| 253 | * removed! |
| 254 | * |
| 255 | * removed! |
| 256 | * removed! |
| 257 | * removed! |
| 258 | * |
| 259 | * removed! |
| 260 | * removed! |
| 261 | * removed! |
| 262 | * removed! |
| 263 | * removed! |
| 264 | * removed! |
| 265 | * removed! |
| 266 | * removed! |
| 267 | * removed! |
| 268 | * removed! |
| 269 | * removed! |
| 270 | * |
| 271 | * removed! |
| 272 | * removed! |
| 273 | * removed! |
| 274 | * |
| 275 | * removed! |
| 276 | * removed! |
| 277 | * removed! |
| 278 | * |
| 279 | * removed! |
| 280 | * removed! |
| 281 | * removed! |
| 282 | * |
| 283 | * removed! |
| 284 | * removed! |
| 285 | * removed! |
| 286 | * |
| 287 | * removed! |
| 288 | * removed! |
| 289 | * removed! |
| 290 | * |
| 291 | * removed! |
| 292 | * removed! |
| 293 | * removed! |
| 294 | * |
| 295 | * removed! |
| 296 | * removed! |
| 297 | * removed! |
| 298 | * |
| 299 | * removed! |
| 300 | * removed! |
| 301 | * removed! |
| 302 | * |
| 303 | * removed! |
| 304 | * removed! |
| 305 | * removed! |
| 306 | * |
| 307 | * removed! |
| 308 | * removed! |
| 309 | * removed! |
| 310 | * |
| 311 | * removed! |
| 312 | * removed! |
| 313 | * removed! |
| 314 | * |
| 315 | * removed! |
| 316 | * removed! |
| 317 | * removed! |
| 318 | * |
| 319 | * removed! |
| 320 | * removed! |
| 321 | * removed! |
| 322 | * |
| 323 | * removed! |
| 324 | * removed! |
| 325 | * removed! |
| 326 | * |
| 327 | * removed! |
| 328 | * removed! |
| 329 | * removed! |
| 330 | * |
| 331 | * removed! |
| 332 | * removed! |
| 333 | * removed! |
| 334 | * |
| 335 | * removed! |
| 336 | * removed! |
| 337 | * removed! |
| 338 | * |
| 339 | * removed! |
| 340 | * removed! |
| 341 | * removed! |
| 342 | * |
| 343 | * removed! |
| 344 | * removed! |
| 345 | * removed! |
| 346 | * |
| 347 | * removed! |
| 348 | * removed! |
| 349 | * removed! |
| 350 | * |
| 351 | * removed! |
| 352 | * removed! |
| 353 | * removed! |
| 354 | * |
| 355 | * removed! |
| 356 | * removed! |
| 357 | * removed! |
| 358 | * |
| 359 | * removed! |
| 360 | * removed! |
| 361 | * removed! |
| 362 | * |
| 363 | * removed! |
| 364 | * removed! |
| 365 | * removed! |
| 366 | * |
| 367 | * removed! |
| 368 | * removed! |
| 369 | * removed! |
| 370 | * |
| 371 | * removed! |
| 372 | * removed! |
| 373 | * removed! |
| 374 | * |
| 375 | * removed! |
| 376 | * removed! |
| 377 | * removed! |
| 378 | * |
| 379 | * removed! |
| 380 | * removed! |
| 381 | * removed! |
| 382 | * |
| 383 | * removed! |
| 384 | * removed! |
| 385 | * removed! |
| 386 | * |
| 387 | * removed! |
| 388 | * removed! |
| 389 | * removed! |
| 390 | * |
| 391 | * removed! |
| 392 | * removed! |
| 393 | * removed! |
| 394 | * |
| 395 | * removed! |
| 396 | * removed! |
| 397 | * removed! |
| 398 | * |
| 399 | * removed! |
| 400 | * removed! |
| 401 | * removed! |
| 402 | * |
| 403 | * removed! |
| 404 | * removed! |
| 405 | * removed! |
| 406 | * |
| 407 | * removed! |
| 408 | * removed! |
| 409 | * removed! |
| 410 | * |
| 411 | * removed! |
| 412 | * removed! |
| 413 | * removed! |
| 414 | * |
| 415 | * removed! |
| 416 | * removed! |
| 417 | * removed! |
| 418 | * |
| 419 | * removed! |
| 420 | * removed! |
| 421 | * removed! |
| 422 | * |
| 423 | * removed! |
| 424 | * removed! |
| 425 | * removed! |
| 426 | * |
| 427 | * removed! |
| 428 | * removed! |
| 429 | * removed! |
| 430 | * |
| 431 | * removed! |
| 432 | * removed! |
| 433 | * removed! |
| 434 | * |
| 435 | * removed! |
| 436 | * removed! |
| 437 | * removed! |
| 438 | * |
| 439 | * removed! |
| 440 | * removed! |
| 441 | * removed! |
| 442 | * |
| 443 | * removed! |
| 444 | * removed! |
| 445 | * removed! |
| 446 | * |
| 447 | * removed! |
| 448 | * removed! |
| 449 | * removed! |
| 450 | * |
| 451 | * removed! |
| 452 | * removed! |
| 453 | * removed! |
| 454 | * |
| 455 | * removed! |
| 456 | * removed! |
| 457 | * removed! |
| 458 | * |
| 459 | * removed! |
| 460 | * removed! |
| 461 | * removed! |
| 462 | * |
| 463 | * removed! |
| 464 | * removed! |
| 465 | * |
| 466 | * |
| 467 | * removed! |
| 468 | * removed! |
| 469 | * |
| 470 | * |
| 471 | * removed! |
| 472 | * removed! |
| 473 | * |
| 474 | * |
| 475 | * removed! |
| 476 | * removed! |
| 477 | * |
| 478 | * |
| 479 | * removed! |
| 480 | * removed! |
| 481 | * |
| 482 | * |
| 483 | * removed! |
| 484 | * removed! |
| 485 | * |
| 486 | * |
| 487 | * removed! |
| 488 | * removed! |
| 489 | * |
| 490 | * |
| 491 | * removed! |
| 492 | * removed! |
| 493 | * |
| 494 | * |
| 495 | * removed! |
| 496 | * removed! |
| 497 | * |
| 498 | * |
| 499 | * removed! |
| 500 | * removed! |
| 501 | * |
| 502 | * |
| 503 | * removed! |
| 504 | * removed! |
| 505 | * |
| 506 | * |
| 507 | * removed! |
| 508 | * removed! |
| 509 | * |
| 510 | * |
| 511 | * removed! |
| 512 | * removed! |
| 513 | * |
| 514 | * |
| 515 | * removed! |
| 516 | * removed! |
| 517 | * |
| 518 | * |
| 519 | * removed! |
| 520 | * removed! |
| 521 | * |
| 522 | * |
| 523 | * removed! |
| 524 | * removed! |
| 525 | * |
| 526 | * |
| 527 | * removed! |
| 528 | * removed! |
| 529 | * |
| 530 | * |
| 531 | * removed! |
| 532 | * removed! |
| 533 | * |
| 534 | * |
| 535 | * removed! |
| 536 | * removed! |
| 537 | * |
| 538 | * |
| 539 | * removed! |
| 540 | * removed! |
| 541 | * |
| 542 | * |
| 543 | * removed! |
| 544 | * removed! |
| 545 | * |
| 546 | * |
| 547 | * removed! |
| 548 | * removed! |
| 549 | * |
| 550 | * |
| 551 | * removed! |
| 552 | * removed! |
| 553 | * |
| 554 | * |
| 555 | * removed! |
| 556 | * removed! |
| 557 | * |
| 558 | * |
| 559 | * removed! |
| 560 | * removed! |
| 561 | * |
| 562 | * |
| 563 | * removed! |
| 564 | * removed! |
| 565 | * |
| 566 | * |
| 567 | * removed! |
| 568 | * removed! |
| 569 | * |
| 570 | * |
| 571 | * removed! |
| 572 | * removed! |
| 573 | * |
| 574 | * |
| 575 | * removed! |
| 576 | * removed! |
| 577 | * |
| 578 | * |
| 579 | * removed! |
| 580 | * removed! |
| 581 | * |
| 582 | * |
| 583 | * removed! |
| 584 | * removed! |
| 585 | * |
| 586 | * |
| 587 | * removed! |
| 588 | * removed! |
| 589 | * |
| 590 | * |
| 591 | * removed! |
| 592 | * removed! |
| 593 | * |
| 594 | * |
| 595 | * removed! |
| 596 | * removed! |
| 597 | * |
| 598 | * |
| 599 | * removed! |
| 600 | * removed! |
| 601 | * |
| 602 | * |
| 603 | * removed! |
| 604 | * removed! |
| 605 | * |
| 606 | * |
| 607 | * removed! |
| 608 | * removed! |
| 609 | * |
| 610 | * |
| 611 | * removed! |
| 612 | * removed! |
| 613 | * |
| 614 | * |
| 615 | * removed! |
| 616 | * removed! |
| 617 | * |
| 618 | * |
| 619 | * removed! |
| 620 | * removed! |
| 621 | * |
| 622 | * |
| 623 | * removed! |
| 624 | * removed! |
| 625 | * |
| 626 | * |
| 627 | * removed! |
| 628 | * removed! |
| 629 | * |
| 630 | * |
| 631 | * removed! |
| 632 | * removed! |
| 633 | * |
| 634 | * |
| 635 | * removed! |
| 636 | * removed! |
| 637 | * |
| 638 | * |
| 639 | * removed! |
| 640 | * removed! |
| 641 | * removed! |
| 642 | * |
| 643 | * removed! |
| 644 | * removed! |
| 645 | * removed! |
| 646 | * |
| 647 | * removed! |
| 648 | * removed! |
| 649 | * |
| 650 | * |
| 651 | * removed! |
| 652 | * removed! |
| 653 | * |
| 654 | * |
| 655 | * removed! |
| 656 | * removed! |
| 657 | * |
| 658 | * |
| 659 | * removed! |
| 660 | * removed! |
| 661 | * removed! |
| 662 | * |
| 663 | * removed! |
| 664 | * removed! |
| 665 | * |
| 666 | * |
| 667 | * removed! |
| 668 | * removed! |
| 669 | * removed! |
| 670 | * |
| 671 | * removed! |
| 672 | * removed! |
| 673 | * |
| 674 | * |
| 675 | * removed! |
| 676 | * removed! |
| 677 | * |
| 678 | * |
| 679 | * removed! |
| 680 | * removed! |
| 681 | * |
| 682 | * |
| 683 | * removed! |
| 684 | * removed! |
| 685 | * |
| 686 | * |
| 687 | * removed! |
| 688 | * removed! |
| 689 | * |
| 690 | * |
| 691 | * removed! |
| 692 | * removed! |
| 693 | * |
| 694 | * |
| 695 | * removed! |
| 696 | * removed! |
| 697 | * |
| 698 | * |
| 699 | * removed! |
| 700 | * removed! |
| 701 | * |
| 702 | * |
| 703 | * removed! |
| 704 | * removed! |
| 705 | * |
| 706 | * |
| 707 | * removed! |
| 708 | * removed! |
| 709 | * removed! |
| 710 | * |
| 711 | * removed! |
| 712 | * removed! |
| 713 | * removed! |
| 714 | * |
| 715 | * removed! |
| 716 | * removed! |
| 717 | * |
| 718 | * |
| 719 | * removed! |
| 720 | * removed! |
| 721 | * removed! |
| 722 | * |
| 723 | * removed! |
| 724 | * removed! |
| 725 | * removed! |
| 726 | * |
| 727 | * removed! |
| 728 | * removed! |
| 729 | * |
| 730 | * |
| 731 | * removed! |
| 732 | * removed! |
| 733 | * |
| 734 | * |
| 735 | *------------------------------------------------------------------------------ |
| 736 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 737 | *============================================================================ |
| 738 | ****************************************************************************/ |
| 739 | |
| 740 | /* |
| 741 | * include |
| 742 | */ |
| 743 | #include "stdio.h" |
| 744 | #include "string.h" |
| 745 | |
| 746 | #include "kal_general_types.h" |
| 747 | #include "kal_public_api.h" |
| 748 | |
| 749 | #if defined(__MMI_FMI__) |
| 750 | #if !defined(NVRAM_NOT_PRESENT) && !defined(__L1_STANDALONE__) |
| 751 | #include "custom_jump_tbl.h" |
| 752 | #include "resource_custpack_jtbl.h" |
| 753 | #endif /* !defined(NVRAM_NOT_PRESENT) && !defined(__L1_STANDALONE__) */ |
| 754 | #include "resource_verno.h" |
| 755 | #endif |
| 756 | |
| 757 | #include "nvram_editor_data_item.h" |
| 758 | #include "nvram_group_editor.h" //add for break group files from header file |
| 759 | #include "nvram_main.h" |
| 760 | |
| 761 | #include "nvram_lid_statistics.h" |
| 762 | |
| 763 | #ifdef __NVRAM_OTP__ |
| 764 | #include "fs_gprot.h" |
| 765 | #include "fs_iprot.h" |
| 766 | #endif |
| 767 | |
| 768 | #if defined(__MTK_TARGET__) |
| 769 | #include "SST_secure.h" |
| 770 | #endif |
| 771 | |
| 772 | #include "us_timer.h" |
| 773 | #include "custom_nvram_cat.h" |
| 774 | |
| 775 | /******************************************** |
| 776 | * External API, cannot include header file |
| 777 | **************************************************/ |
| 778 | extern kal_char *release_verno(void); |
| 779 | extern kal_char *release_branch(void); |
| 780 | extern kal_char *release_flavor(void); |
| 781 | extern kal_char *build_date_time(void); |
| 782 | extern kal_bool nvram_custom_lock_status(void); |
| 783 | extern module_type stack_get_active_module_id( void ); |
| 784 | |
| 785 | |
| 786 | /******************************************** |
| 787 | * Global and Static Variable |
| 788 | **************************************************/ |
| 789 | typedef struct |
| 790 | { |
| 791 | kal_uint8 const* version; |
| 792 | nvram_lid_enum lid[NVRAM_CUSTPACK_TOTAL]; |
| 793 | }nvram_custpack_lid_tbl_struct; |
| 794 | |
| 795 | extern nvram_ee_info_type* nvram_ee_info; |
| 796 | extern kal_char nvram_trace_dump_temp_buffer[]; |
| 797 | extern kal_char nvram_trace_dump_buffer[]; |
| 798 | extern kal_mutexid g_nvram_dump_trace_mutex; |
| 799 | extern kal_wchar nvram_trace_filename[]; |
| 800 | extern FS_HANDLE nvram_trace_file_hdl; |
| 801 | extern kal_uint32 nvram_trace_dump_buffer_offset; |
| 802 | #ifdef __NVRAM_LID_CACHE__ |
| 803 | extern kal_uint8* g_nvcache_base_address; |
| 804 | extern kal_uint32 g_nvcache_memory_size; |
| 805 | extern kal_bool g_nvram_cache_ready; |
| 806 | #endif |
| 807 | |
| 808 | //#if !defined(NVRAM_NOT_PRESENT) && !defined(__L1_STANDALONE__) |
| 809 | #ifdef __NVRAM_SUPPORT_CUSTPACK__ |
| 810 | static custpack_nvram_header *custpack_nvram_header_ptr; |
| 811 | #endif |
| 812 | //#endif |
| 813 | |
| 814 | #ifdef __NVRAM_OTP__ |
| 815 | typedef struct |
| 816 | { |
| 817 | nvram_lid_enum LID; /* Logical Data Item ID */ |
| 818 | kal_uint32 offset; /* start address in Shadow buffer*/ |
| 819 | }nvram_otp_table_sturct; |
| 820 | |
| 821 | static nvram_otp_table_sturct nvram_otp_ltable[NVRAM_OTP_TOTAL]; |
| 822 | #endif |
| 823 | |
| 824 | #if defined (__NVRAM_UT_TEST__) |
| 825 | kal_uint8 NVRAM_EF_TEST_8_DEFAULT[NVRAM_EF_TEST_8_LID_RECORD_TOTAL][NVRAM_EF_TEST_8_LID_SIZE] = { |
| 826 | {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}, |
| 827 | {0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18}, |
| 828 | {0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28}, |
| 829 | }; |
| 830 | #endif |
| 831 | |
| 832 | #ifndef __MTK_TARGET__ |
| 833 | #ifdef _MSC_VER |
| 834 | nvram_ltable_entry_struct __pragma(data_seg("_nvram_ltable_begin")) _nvram_ltable_start ={0}; |
| 835 | #else |
| 836 | __attribute__ ((section("_nvram_ltable_begin"))) nvram_ltable_entry_struct _nvram_ltable_start ={0}; |
| 837 | #endif |
| 838 | #endif |
| 839 | #ifdef __NVRAM_SEC_CHECK_EN__ |
| 840 | extern void srand(kal_uint32 seed); |
| 841 | extern int rand(void); |
| 842 | extern void nvram_AES_encrypt(unsigned char *buffer, unsigned int length); |
| 843 | void nvram_get_sec_default_value_to_write(nvram_lid_enum lid, kal_uint8 *buffer, kal_uint16 buffer_size) |
| 844 | { |
| 845 | kal_uint32 rec0_idx, rec1_idx; |
| 846 | kal_uint8 nvram_sec_buf[NVRAM_SEC_CHECK_LEN*2]; |
| 847 | #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__ |
| 848 | kal_uint8 *rec0_buf_ptr=NULL; |
| 849 | #endif |
| 850 | kal_uint8 *rec1_buf_ptr=NULL; |
| 851 | |
| 852 | #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__ |
| 853 | rec0_buf_ptr = &nvram_sec_buf[0]; |
| 854 | #endif |
| 855 | |
| 856 | rec1_buf_ptr = &nvram_sec_buf[NVRAM_SEC_CHECK_LEN]; |
| 857 | srand(0); |
| 858 | for(rec0_idx =0; rec0_idx<(NVRAM_SEC_CHECK_LEN/2); rec0_idx++){ |
| 859 | rec1_idx = rec0_idx+NVRAM_SEC_CHECK_LEN; |
| 860 | nvram_sec_buf[rec0_idx]=rand()%0xFF; |
| 861 | nvram_sec_buf[rec1_idx]=rand()%0xFF; |
| 862 | nvram_sec_buf[rec0_idx+NVRAM_SEC_CHECK_LEN/2]=~(nvram_sec_buf[rec0_idx]); |
| 863 | nvram_sec_buf[rec1_idx+NVRAM_SEC_CHECK_LEN/2]=~(nvram_sec_buf[rec1_idx]); |
| 864 | } |
| 865 | #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__ |
| 866 | SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)rec0_buf_ptr, NVRAM_SEC_CHECK_LEN, nvram_ptr->secret_key, rec0_buf_ptr); |
| 867 | #endif |
| 868 | |
| 869 | nvram_AES_encrypt(rec1_buf_ptr, NVRAM_SEC_CHECK_LEN); |
| 870 | |
| 871 | kal_mem_cpy(buffer, nvram_sec_buf, buffer_size); |
| 872 | |
| 873 | } |
| 874 | #endif |
| 875 | |
| 876 | #if defined (__NVRAM_UT_TEST__) |
| 877 | /***************************************************************************** |
| 878 | * FUNCTION |
| 879 | * nvram_internal_test_fun_default_value |
| 880 | * DESCRIPTION |
| 881 | * This function is assign |
| 882 | * the internal test LID function default value |
| 883 | * PARAMETERS |
| 884 | * void |
| 885 | * RETURNS |
| 886 | * void |
| 887 | *****************************************************************************/ |
| 888 | void nvram_internal_test_fun_default_value(nvram_lid_enum file_id, kal_uint8 *buffer, kal_uint16 buffer_size) |
| 889 | { |
| 890 | nvram_ltable_entry_struct *ldi = NULL; |
| 891 | kal_uint32 i = 0, offset = 0; |
| 892 | |
| 893 | nvram_util_get_data_item(&ldi, file_id); |
| 894 | kal_mem_set(buffer, 0, buffer_size); |
| 895 | for(i = 1; i <= ldi->total_records; i++) |
| 896 | { |
| 897 | offset = (i-1) * ldi->size; |
| 898 | buffer[offset] = i; |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | #endif |
| 903 | |
| 904 | static void nvram_assign_sys_default(nvram_lid_enum file_id, kal_uint8 *buffer, kal_uint16 buffer_size); |
| 905 | |
| 906 | ltable_entry_struct logical_data_item_table_internal[] = |
| 907 | { |
| 908 | { |
| 909 | NVRAM_EF_SYS_LID, |
| 910 | NVRAM_EF_SYS_TOTAL, |
| 911 | NVRAM_EF_SYS_SIZE, |
| 912 | NVRAM_DEFAULT_FUNC(nvram_assign_sys_default), |
| 913 | NVRAM_CATEGORY_IMPORTANT_L1 | NVRAM_CATEGORY_FUNC_DEFAULT, |
| 914 | NVRAM_ATTR_WRITEPROTECT | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MULTIPLE |
| 915 | #if defined (__CCCIFS_SUPPORT__) |
| 916 | | NVRAM_ATTR_COMMITTED |
| 917 | #endif |
| 918 | , |
| 919 | "MT00", |
| 920 | VER(NVRAM_EF_SYS_LID) |
| 921 | }, |
| 922 | |
| 923 | #ifdef __NVRAM_SUPPORT_CUSTPACK__ |
| 924 | { |
| 925 | NVRAM_EF_CUSTPACK_VERNO_LID, |
| 926 | NVRAM_EF_CUSTPACK_VERNO_TOTAL, |
| 927 | NVRAM_EF_CUSTPACK_VERNO_SIZE, |
| 928 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 929 | NVRAM_CATEGORY_INTERNAL, |
| 930 | NVRAM_ATTR_WRITEPROTECT | NVRAM_ATTR_AVERAGE, |
| 931 | "MT02", |
| 932 | VER(NVRAM_EF_CUSTPACK_VERNO_LID) |
| 933 | }, |
| 934 | #endif |
| 935 | { |
| 936 | NVRAM_EF_NVRAM_LOCK_LID, |
| 937 | NVRAM_EF_NVRAM_LOCK_TOTAL, |
| 938 | NVRAM_EF_NVRAM_LOCK_SIZE, |
| 939 | NVRAM_DEFAULT_FUNC(nvram_assign_sys_default), |
| 940 | NVRAM_CATEGORY_IMPORTANT | NVRAM_CATEGORY_FUNC_DEFAULT, |
| 941 | NVRAM_ATTR_WRITEPROTECT | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_CONFIDENTIAL | NVRAM_ATTR_FAULT_ASSERT |
| 942 | #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__ |
| 943 | | NVRAM_ATTR_MSP | NVRAM_ATTR_MULTIPLE |
| 944 | #endif |
| 945 | #if defined (__CCCIFS_SUPPORT__) |
| 946 | | NVRAM_ATTR_COMMITTED |
| 947 | #endif |
| 948 | , |
| 949 | "NV01", |
| 950 | VER(NVRAM_EF_NVRAM_LOCK_LID) |
| 951 | }, |
| 952 | #ifdef __NVRAM_READ_RESERVED_FILE__ |
| 953 | { |
| 954 | NVRAM_EF_READ_RESERVED_LID, |
| 955 | NVRAM_EF_READ_RESERVED_TOTAL, |
| 956 | NVRAM_EF_READ_RESERVED_SIZE, |
| 957 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 958 | NVRAM_CATEGORY_RESERVED, |
| 959 | NVRAM_ATTR_AVERAGE, |
| 960 | "NONE", |
| 961 | VER(NVRAM_EF_READ_RESERVED_LID) |
| 962 | }, |
| 963 | #endif |
| 964 | #ifdef __NVRAM_SEC_CHECK_EN__ |
| 965 | { |
| 966 | NVRAM_EF_NVRAM_SEC_CHECK_LID, |
| 967 | NVRAM_EF_NVRAM_SEC_CHECK_TOTAL, |
| 968 | NVRAM_EF_NVRAM_SEC_CHECK_SIZE, |
| 969 | NVRAM_DEFAULT_FUNC(nvram_get_sec_default_value_to_write), |
| 970 | NVRAM_CATEGORY_IMPORTANT | NVRAM_CATEGORY_FUNC_DEFAULT, |
| 971 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_FAULT_ASSERT | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MULTI_DEFAULT |
| 972 | #if defined (__CCCIFS_SUPPORT__) |
| 973 | | NVRAM_ATTR_COMMITTED |
| 974 | #endif |
| 975 | , |
| 976 | "NV0S", |
| 977 | VER(NVRAM_EF_NVRAM_SEC_CHECK_LID) |
| 978 | }, |
| 979 | #endif |
| 980 | #ifdef __NVRAM_UNIT_TEST__ |
| 981 | { |
| 982 | NVRAM_EF_NVRAM_UNIT_TEST_LID, |
| 983 | NVRAM_EF_NVRAM_UNIT_TEST_TOTAL, |
| 984 | NVRAM_EF_NVRAM_UNIT_TEST_SIZE, |
| 985 | NVRAM_NORMAL((const kal_uint8 *)NVRAM_EF_ZERO_DEFAULT), |
| 986 | #ifdef __SECURE_DATA_STORAGE__ |
| 987 | NVRAM_CATEGORY_INTERNAL, |
| 988 | #else |
| 989 | NVRAM_CATEGORY_USER, |
| 990 | #endif |
| 991 | NVRAM_ATTR_AVERAGE, |
| 992 | "MT10", |
| 993 | VER(NVRAM_EF_NVRAM_UNIT_TEST_LID) |
| 994 | }, |
| 995 | #endif |
| 996 | |
| 997 | #if defined (__NVRAM_UT_TEST__) |
| 998 | |
| 999 | { |
| 1000 | NVRAM_EF_NVRAM_TEST_1_LID, |
| 1001 | NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1002 | NVRAM_EF_TEST_LID_SIZE, |
| 1003 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1004 | NVRAM_CATEGORY_USER, |
| 1005 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT, |
| 1006 | "MTT1", |
| 1007 | VER(NVRAM_EF_NVRAM_TEST_1_LID) |
| 1008 | }, |
| 1009 | |
| 1010 | { |
| 1011 | NVRAM_EF_NVRAM_TEST_2_LID, |
| 1012 | NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1013 | NVRAM_EF_TEST_LID_SIZE, |
| 1014 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1015 | NVRAM_CATEGORY_INTERNAL, |
| 1016 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT, |
| 1017 | "MTT2", |
| 1018 | VER(NVRAM_EF_NVRAM_TEST_2_LID) |
| 1019 | }, |
| 1020 | |
| 1021 | { |
| 1022 | NVRAM_EF_NVRAM_TEST_3_LID, |
| 1023 | NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1024 | NVRAM_EF_TEST_LID_SIZE, |
| 1025 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1026 | NVRAM_CATEGORY_CALIBRAT, |
| 1027 | NVRAM_ATTR_AVERAGE, |
| 1028 | "MTT3", |
| 1029 | VER(NVRAM_EF_NVRAM_TEST_3_LID) |
| 1030 | }, |
| 1031 | |
| 1032 | { |
| 1033 | NVRAM_EF_NVRAM_TEST_4_LID, |
| 1034 | NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1035 | NVRAM_EF_TEST_LID_SIZE, |
| 1036 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1037 | NVRAM_CATEGORY_IMPORTANT, |
| 1038 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT |
| 1039 | #if defined (__CCCIFS_SUPPORT__) |
| 1040 | | NVRAM_ATTR_COMMITTED |
| 1041 | #endif |
| 1042 | , |
| 1043 | "MTT4", |
| 1044 | VER(NVRAM_EF_NVRAM_TEST_4_LID) |
| 1045 | }, |
| 1046 | |
| 1047 | { |
| 1048 | NVRAM_EF_NVRAM_TEST_5_LID, |
| 1049 | NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1050 | NVRAM_EF_TEST_LID_SIZE, |
| 1051 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1052 | NVRAM_CATEGORY_IMPORTANT_L1, |
| 1053 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT, |
| 1054 | "MTT5", |
| 1055 | VER(NVRAM_EF_NVRAM_TEST_5_LID) |
| 1056 | }, |
| 1057 | |
| 1058 | { |
| 1059 | NVRAM_EF_NVRAM_TEST_6_LID, |
| 1060 | NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1061 | NVRAM_EF_TEST_LID_SIZE, |
| 1062 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1063 | NVRAM_CATEGORY_IMPORTANT_L4, |
| 1064 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_CHKSUM_INTEGRATE |
| 1065 | #if defined (__CCCIFS_SUPPORT__) |
| 1066 | | NVRAM_ATTR_COMMITTED |
| 1067 | #endif |
| 1068 | , |
| 1069 | "MTT6", |
| 1070 | VER(NVRAM_EF_NVRAM_TEST_6_LID) |
| 1071 | }, |
| 1072 | |
| 1073 | { |
| 1074 | NVRAM_EF_NVRAM_TEST_7_LID, |
| 1075 | 1, //NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1076 | NVRAM_EF_TEST_LID_SIZE, |
| 1077 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1078 | NVRAM_CATEGORY_CALIBRAT, |
| 1079 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_RAW_DATA, |
| 1080 | "MTT7", |
| 1081 | VER(NVRAM_EF_NVRAM_TEST_7_LID) |
| 1082 | }, |
| 1083 | |
| 1084 | { |
| 1085 | NVRAM_EF_NVRAM_TEST_8_LID, |
| 1086 | NVRAM_EF_TEST_8_LID_RECORD_TOTAL, |
| 1087 | NVRAM_EF_TEST_8_LID_SIZE, |
| 1088 | NVRAM_NORMAL(NVRAM_EF_TEST_8_DEFAULT), |
| 1089 | NVRAM_CATEGORY_USER, |
| 1090 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_MULTI_DEFAULT | NVRAM_ATTR_CHKSUM_INTEGRATE, |
| 1091 | "MTT8", |
| 1092 | VER(NVRAM_EF_NVRAM_TEST_8_LID) |
| 1093 | }, |
| 1094 | { |
| 1095 | NVRAM_EF_NVRAM_TEST_9_LID, |
| 1096 | NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1097 | NVRAM_EF_TEST_LID_SIZE, |
| 1098 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1099 | NVRAM_CATEGORY_USER, |
| 1100 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MCF_OTA_FOR_QUERY, |
| 1101 | "MTT9", |
| 1102 | VER(NVRAM_EF_NVRAM_TEST_9_LID) |
| 1103 | }, |
| 1104 | { |
| 1105 | NVRAM_EF_NVRAM_TEST_10_LID, |
| 1106 | NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1107 | NVRAM_EF_TEST_LID_SIZE, |
| 1108 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1109 | NVRAM_CATEGORY_USER, |
| 1110 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MCF_OTA_BY_OP, |
| 1111 | "MTTA", |
| 1112 | VER(NVRAM_EF_NVRAM_TEST_10_LID) |
| 1113 | }, |
| 1114 | { |
| 1115 | NVRAM_EF_NVRAM_TEST_11_LID, |
| 1116 | NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1117 | NVRAM_EF_TEST_LID_SIZE, |
| 1118 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1119 | NVRAM_CATEGORY_USER, |
| 1120 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MCF_OTA | NVRAM_ATTR_MCF_OTA_BY_OP, |
| 1121 | "MTTB", |
| 1122 | VER(NVRAM_EF_NVRAM_TEST_11_LID) |
| 1123 | }, |
| 1124 | { |
| 1125 | NVRAM_EF_NVRAM_TEST_12_LID, |
| 1126 | NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1127 | NVRAM_EF_TEST_LID_SIZE, |
| 1128 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1129 | NVRAM_CATEGORY_USER, |
| 1130 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MCF_OTA, |
| 1131 | "MTTC", |
| 1132 | VER(NVRAM_EF_NVRAM_TEST_12_LID) |
| 1133 | }, |
| 1134 | { |
| 1135 | NVRAM_EF_INTERNAL_13_LID, |
| 1136 | NVRAM_EF_TEST_13_LID_RECORD_TOTAL, |
| 1137 | NVRAM_EF_TEST_13_LID_SIZE, |
| 1138 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1139 | NVRAM_CATEGORY_IMPORTANT_L1, |
| 1140 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MULTI_DEFAULT, |
| 1141 | "MTTD", |
| 1142 | VER(NVRAM_EF_INTERNAL_13_LID) |
| 1143 | }, |
| 1144 | { |
| 1145 | NVRAM_EF_INTERNAL_TEST_14_LID, |
| 1146 | NVRAM_EF_TEST_14_LID_RECORD_TOTAL, |
| 1147 | NVRAM_EF_TEST_14_LID_SIZE, |
| 1148 | NVRAM_DEFAULT_FUNC(nvram_internal_test_fun_default_value), |
| 1149 | NVRAM_CATEGORY_USER | NVRAM_CATEGORY_FUNC_DEFAULT, |
| 1150 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_GEN_DEFAULT | NVRAM_ATTR_MULTI_DEFAULT, |
| 1151 | "MTTE", |
| 1152 | VER(NVRAM_EF_INTERNAL_TEST_14_LID) |
| 1153 | }, |
| 1154 | { |
| 1155 | NVRAM_EF_INTERNAL_TEST_16_LID, |
| 1156 | NVRAM_EF_INTERNAL_TEST_16_LID_RECORD_TOTAL, |
| 1157 | NVRAM_EF_INTERNAL_TEST_16_LID_SIZE, |
| 1158 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1159 | NVRAM_CATEGORY_CALIBRAT, |
| 1160 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_CHKSUM_INTEGRATE | NVRAM_ATTR_FAULT_ASSERT, |
| 1161 | "MTTG", |
| 1162 | VER(NVRAM_EF_INTERNAL_TEST_16_LID) |
| 1163 | }, |
| 1164 | { |
| 1165 | NVRAM_EF_INTERNAL_TEST_17_LID, |
| 1166 | NVRAM_EF_TEST_LID_RECORD_TOTAL, |
| 1167 | NVRAM_EF_TEST_LID_SIZE, |
| 1168 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1169 | NVRAM_CATEGORY_USER, |
| 1170 | NVRAM_ATTR_AVERAGE | NVRAM_ATTR_MULTIPLE, |
| 1171 | "MTTH", |
| 1172 | VER(NVRAM_EF_INTERNAL_TEST_17_LID) |
| 1173 | }, |
| 1174 | #endif |
| 1175 | |
| 1176 | #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__) |
| 1177 | { |
| 1178 | NVRAM_EF_CHKSUM_RESET_REC_LID, |
| 1179 | NVRAM_EF_CHKSUM_RESET_REC_LID_TOTAL, |
| 1180 | NVRAM_EF_CHKSUM_RESET_REC_SIZE, |
| 1181 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1182 | NVRAM_CATEGORY_INTERNAL, |
| 1183 | NVRAM_ATTR_AVERAGE, |
| 1184 | "MTCR", //NVRAM check sum reset |
| 1185 | VER(NVRAM_EF_CHKSUM_RESET_REC_LID) |
| 1186 | }, |
| 1187 | #endif |
| 1188 | |
| 1189 | }; |
| 1190 | |
| 1191 | #ifdef __NVRAM_READ_RESERVED_FILE__ |
| 1192 | //use to reset NVRAM_EF_READ_RESERVED_LID default value |
| 1193 | nvram_ltable_entry_struct const reserved_logical_data_item = |
| 1194 | { |
| 1195 | NVRAM_EF_READ_RESERVED_LID, |
| 1196 | NVRAM_EF_READ_RESERVED_TOTAL, |
| 1197 | NVRAM_EF_READ_RESERVED_SIZE, |
| 1198 | NVRAM_NORMAL(NVRAM_EF_ZERO_DEFAULT), |
| 1199 | NVRAM_CATEGORY_RESERVED, |
| 1200 | NVRAM_ATTR_AVERAGE, |
| 1201 | "NONE", |
| 1202 | VER(NVRAM_EF_READ_RESERVED_LID) |
| 1203 | }; |
| 1204 | #endif |
| 1205 | |
| 1206 | #ifndef __MTK_TARGET__ |
| 1207 | #ifdef _MSC_VER |
| 1208 | #pragma comment(linker, "/MERGE:_nvram_ltable_content=_nvram_ltable_begin") |
| 1209 | |
| 1210 | nvram_ltable_entry_struct __pragma(data_seg("_nvram_ltable_end")) the_nvram_ltable_end = {0}; |
| 1211 | |
| 1212 | #pragma comment(linker, "/MERGE:_nvram_ltable_end=_nvram_ltable_begin") |
| 1213 | |
| 1214 | nvram_ltable_entry_struct __pragma(data_seg("thegarbge")) the_garbge = {0}; |
| 1215 | #else |
| 1216 | // section merge is moved to linker script for other compilers |
| 1217 | __attribute__ ((section("_nvram_ltable_end"))) nvram_ltable_entry_struct the_nvram_ltable_end = {0}; |
| 1218 | __attribute__ ((section("thegarbge"))) nvram_ltable_entry_struct the_garbge = {0}; |
| 1219 | #endif |
| 1220 | //#ifndef __L1_STANDALONE__ |
| 1221 | #ifdef __NVRAM_SUPPORT_CUSTPACK__ |
| 1222 | #pragma comment(linker, "/INCLUDE:_g_nvram_custpack_init") |
| 1223 | #endif |
| 1224 | //#endif |
| 1225 | |
| 1226 | #include "nvram_ltable_list.h" |
| 1227 | #endif |
| 1228 | extern void nvram_data_item_register(void); |
| 1229 | /***************************************************************************** |
| 1230 | * FUNCTION |
| 1231 | * nvram_ee_info_init |
| 1232 | * DESCRIPTION |
| 1233 | * This function init NVRAM Debug information on share memory. |
| 1234 | * PARAMETERS |
| 1235 | * void |
| 1236 | * RETURNS |
| 1237 | *****************************************************************************/ |
| 1238 | void nvram_ee_info_init(void) |
| 1239 | { |
| 1240 | #if defined (__NVRAM_UT_TEST__) |
| 1241 | if((nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id)) |
| 1242 | {} //do not create mutex again, otherwise fatal error happen |
| 1243 | else |
| 1244 | #endif |
| 1245 | { |
| 1246 | if(g_nvram_dump_trace_mutex == NULL) |
| 1247 | { |
| 1248 | g_nvram_dump_trace_mutex = kal_create_mutex("NV_DUMP"); |
| 1249 | } |
| 1250 | nvram_trace_dump_buffer_offset = 0; |
| 1251 | kal_mem_set(nvram_trace_dump_buffer,0,NVRAM_DUMP_TRACE_BUFFER_SIZE); |
| 1252 | } |
| 1253 | if(nvram_ee_info != NULL){ |
| 1254 | //kal_mem_set(nvram_ee_info,0,sizeof(nvram_ee_info_type)); |
| 1255 | nvram_ee_info->nvram_init_step = NVRAM_INIT_START; |
| 1256 | nvram_ee_info->nvram_init_time[0] = kal_get_systicks(); |
| 1257 | |
| 1258 | nvram_ee_info->nvram_init_context.sw_status = 0; |
| 1259 | nvram_ee_info->nvram_init_context.lock = KAL_FALSE; |
| 1260 | nvram_ee_info->nvram_init_context.saved_lock = nvram_custom_lock_status(); |
| 1261 | nvram_ee_info->nvram_access_info.total_time = 0; |
| 1262 | nvram_ee_info->nvram_access_info.max_time = 0; |
| 1263 | nvram_ee_info->nvram_access_info.min_time = 0xFFFFFFFF; |
| 1264 | nvram_ee_info->nvram_trace_fs_access_val = 0; |
| 1265 | #ifdef __NVRAM_LID_CACHE__ |
| 1266 | nvram_ee_info->nvram_cache_setting.cache_memory_addr = (kal_uint32)g_nvcache_base_address; |
| 1267 | nvram_ee_info->nvram_cache_setting.cache_memory_size = g_nvcache_memory_size; |
| 1268 | nvram_ee_info->nvram_cache_setting.cache_init_status = g_nvram_cache_ready; |
| 1269 | #endif |
| 1270 | } |
| 1271 | } |
| 1272 | /***************************************************************************** |
| 1273 | * FUNCTION |
| 1274 | * nvram_pre_init |
| 1275 | * DESCRIPTION |
| 1276 | * This function init necessary NVRAM information. |
| 1277 | * (no matter NVRAM task is on or not) |
| 1278 | * PARAMETERS |
| 1279 | * void |
| 1280 | * RETURNS |
| 1281 | * NVRAM_ERRNO_SUCCESS if succeed, NVRAM_ERRNO_INVALID otherwise (ie, invalid LID).(?)(?) |
| 1282 | *****************************************************************************/ |
| 1283 | void nvram_pre_init(void) |
| 1284 | { |
| 1285 | /*----------------------------------------------------------------*/ |
| 1286 | /* Local Variables */ |
| 1287 | /*----------------------------------------------------------------*/ |
| 1288 | |
| 1289 | /*----------------------------------------------------------------*/ |
| 1290 | /* Code Body */ |
| 1291 | /*----------------------------------------------------------------*/ |
| 1292 | |
| 1293 | //NVRAM table force link |
| 1294 | nvram_data_item_register(); |
| 1295 | |
| 1296 | /* For HAL rule, NVRAM cannot access the symbols directly, but in-direct reference instead. |
| 1297 | User shall call NVRAM API to register their logical data item tables, to force the Linker links these symbols in the target load.*/ |
| 1298 | //nvram_ltable_register(logical_data_item_table_ul1); |
| 1299 | |
| 1300 | if (nvram_ptr->ltable.table == NULL) /* assume that ltable still not initialized if total_LID==0 */ |
| 1301 | { |
| 1302 | nvram_init_secupack(nvram_ptr->secret_key); |
| 1303 | |
| 1304 | custom_nvram_get_key((char*)nvram_ptr->secret_key, nvram_ptr->secret_key); |
| 1305 | |
| 1306 | /* Construct logical data item table */ |
| 1307 | nvram_ltable_construct(); |
| 1308 | } |
| 1309 | |
| 1310 | //reset NVRAM_EF_READ_RESERVED_LID info |
| 1311 | { |
| 1312 | extern nvram_ltable_entry_struct const reserved_logical_data_item; |
| 1313 | nvram_ltable_entry_struct *ldi; |
| 1314 | nvram_util_get_data_item(&ldi, NVRAM_EF_READ_RESERVED_LID); |
| 1315 | if(ldi) { |
| 1316 | kal_mem_cpy(ldi, &reserved_logical_data_item, sizeof(nvram_ltable_entry_struct)); |
| 1317 | } |
| 1318 | } |
| 1319 | if(nvram_ee_info != NULL){ |
| 1320 | kal_mem_cpy((kal_uint8 *)(nvram_ee_info->nvram_init_context.secret_key),(kal_uint8 *)nvram_ptr->secret_key,NVRAM_SECRET_SEED_KEY_SIZE); |
| 1321 | } |
| 1322 | } |
| 1323 | //#ifndef __L1_STANDALONE__ |
| 1324 | #ifdef __NVRAM_SUPPORT_CUSTPACK__ |
| 1325 | void nvram_custpack_int_init(custpack_nvram_header *custpack_ptr) |
| 1326 | { |
| 1327 | custpack_nvram_header_ptr = custpack_ptr; |
| 1328 | } |
| 1329 | #endif |
| 1330 | //#endif |
| 1331 | /***************************************************************************** |
| 1332 | * FUNCTION |
| 1333 | * nvram_assign_custpack_default_value |
| 1334 | * DESCRIPTION |
| 1335 | * This function is assign |
| 1336 | * the point of default value from 3rd jump table to logical table |
| 1337 | * PARAMETERS |
| 1338 | * void |
| 1339 | * RETURNS |
| 1340 | * void |
| 1341 | *****************************************************************************/ |
| 1342 | #define NVRAM_LTABLE_C_ONLY |
| 1343 | static void nvram_assign_sys_default(nvram_lid_enum file_id, kal_uint8 *buffer, kal_uint16 buffer_size) |
| 1344 | { |
| 1345 | |
| 1346 | switch(file_id) |
| 1347 | { |
| 1348 | case NVRAM_EF_SYS_LID: |
| 1349 | memcpy(buffer, nvram_ptr->coded_version, buffer_size); |
| 1350 | break; |
| 1351 | case NVRAM_EF_BRANCH_VERNO_LID: |
| 1352 | memcpy(buffer, nvram_ptr->branch_version, buffer_size); |
| 1353 | break; |
| 1354 | case NVRAM_EF_FLAVOR_VERNO_LID: |
| 1355 | memcpy(buffer, nvram_ptr->flavor_version, buffer_size); |
| 1356 | break; |
| 1357 | case NVRAM_EF_BUILD_TIME_LID: |
| 1358 | memcpy(buffer, nvram_ptr->build_time, buffer_size); |
| 1359 | break; |
| 1360 | case NVRAM_EF_NVRAM_LOCK_LID: |
| 1361 | //default value get from nvram_custom_lock_status() |
| 1362 | if(nvram_ptr->saved_lock) { |
| 1363 | memcpy(buffer, NVRAM_LOCK_PATTERN_LOCKED, CODED_LOCK_PATTERN_SIZE); |
| 1364 | } |
| 1365 | else { |
| 1366 | memcpy(buffer, NVRAM_LOCK_PATTERN_UNLOCKED, CODED_LOCK_PATTERN_SIZE); |
| 1367 | } |
| 1368 | //NVRAM_EF_NVRAM_LOCK_LID have NVRAM_ATTR_CONFIDENTIAL |
| 1369 | //custom_nvram_encrypt(nvram_ptr->secret_key, buffer, CODED_LOCK_PATTERN_SIZE, 1); |
| 1370 | break; |
| 1371 | } |
| 1372 | } |
| 1373 | static void nvram_assign_custpack_default_value(void) |
| 1374 | { |
| 1375 | #if defined(__MMI_FMI__) |
| 1376 | #if !defined(NVRAM_NOT_PRESENT) && !defined(__L1_STANDALONE__) |
| 1377 | |
| 1378 | #ifdef __NVRAM_SUPPORT_CUSTPACK__ |
| 1379 | /*----------------------------------------------------------------*/ |
| 1380 | /* Local Variables */ |
| 1381 | /*----------------------------------------------------------------*/ |
| 1382 | kal_uint32 file_idx; |
| 1383 | nvram_lid_enum custpack_idx = 0; |
| 1384 | nvram_ltable_entry_struct *ldi = &logical_data_item_table[0]; |
| 1385 | #include "nvram_custpack_table_lid.c" |
| 1386 | |
| 1387 | /*----------------------------------------------------------------*/ |
| 1388 | /* Code Body */ |
| 1389 | /*----------------------------------------------------------------*/ |
| 1390 | |
| 1391 | // custpack_header = (void **)GET_ResCUSTPACK_Addr(g_entry_preamble); |
| 1392 | // custpack_nvram_header_ptr = (custpack_nvram_header*) custpack_header[g_custpack_nvram]; |
| 1393 | |
| 1394 | #ifndef __MTK_TARGET__ |
| 1395 | extern void nvram_custpack_init(void); |
| 1396 | nvram_custpack_init(); |
| 1397 | |
| 1398 | #endif |
| 1399 | do |
| 1400 | { |
| 1401 | |
| 1402 | // #ifdef __NVRAM_SUPPORT_CUSTPACK__ |
| 1403 | if (ldi->LID == NVRAM_EF_CUSTPACK_VERNO_LID) |
| 1404 | { |
| 1405 | memset(nvram_ptr->custpack_version, 0, NVRAM_EF_CUSTPACK_VERNO_SIZE + 1); |
| 1406 | |
| 1407 | if (custpack_nvram_header_ptr->version != NULL) |
| 1408 | { |
| 1409 | strncpy((char*)nvram_ptr->custpack_version, (char*)custpack_nvram_header_ptr->version, NVRAM_EF_CUSTPACK_VERNO_SIZE); |
| 1410 | } |
| 1411 | else |
| 1412 | { |
| 1413 | sprintf((char*)nvram_ptr->custpack_version, "version %d", CURRENT_CUSTPACK_RES_VERSION); |
| 1414 | } |
| 1415 | |
| 1416 | ldi->default_value = nvram_ptr->custpack_version; |
| 1417 | } |
| 1418 | // #endif |
| 1419 | |
| 1420 | if (!NVRAM_IS_CATEGORY_CUSTPACK(ldi->category)) |
| 1421 | { |
| 1422 | continue; |
| 1423 | } |
| 1424 | |
| 1425 | for (file_idx = 0; file_idx < NVRAM_CUSTPACK_TOTAL; file_idx++) |
| 1426 | { |
| 1427 | if (custpack_nvram_lid_tbl.lid[file_idx] == ldi->LID) |
| 1428 | { |
| 1429 | break; |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | ldi->default_value = custpack_nvram_header_ptr->custpack_default[file_idx]; |
| 1434 | custpack_idx++; |
| 1435 | |
| 1436 | NVRAM_EXT_ASSERT(custpack_idx <= NVRAM_CUSTPACK_TOTAL && file_idx <= NVRAM_CUSTPACK_TOTAL, 0, NVRAM_LOC_GEN_TARGET_ASYNC_CUSTPACK, (custpack_idx > file_idx ? (custpack_idx): file_idx)); |
| 1437 | |
| 1438 | }while(nvram_util_next_data_item(&ldi)); |
| 1439 | |
| 1440 | #endif /* __NVRAM_SUPPORT_CUSTPACK__ */ |
| 1441 | #endif /* !defined(NVRAM_NOT_PRESENT) && !defined(__L1_STANDALONE__) */ |
| 1442 | #endif /* __MMI_FMI__ */ |
| 1443 | } |
| 1444 | |
| 1445 | /***************************************************************************** |
| 1446 | * FUNCTION |
| 1447 | * nvram_update_lock_state |
| 1448 | * DESCRIPTION |
| 1449 | * This function construct the default value of lock status. |
| 1450 | * PARAMETERS |
| 1451 | * locked :[in ] lock state. |
| 1452 | * RETURNS |
| 1453 | * success or fail |
| 1454 | *****************************************************************************/ |
| 1455 | kal_bool nvram_update_lock_state(kal_bool locked) |
| 1456 | { |
| 1457 | /*----------------------------------------------------------------*/ |
| 1458 | /* Local Variables */ |
| 1459 | /*----------------------------------------------------------------*/ |
| 1460 | nvram_ltable_entry_struct *ldi = NULL; |
| 1461 | |
| 1462 | /*----------------------------------------------------------------*/ |
| 1463 | /* Code Body */ |
| 1464 | /*----------------------------------------------------------------*/ |
| 1465 | nvram_ptr->saved_lock = locked; |
| 1466 | nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_LOCK_LID); |
| 1467 | return nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, 1); |
| 1468 | } |
| 1469 | |
| 1470 | /***************************************************************************** |
| 1471 | * FUNCTION |
| 1472 | * nvram_decrypt_lock_state |
| 1473 | * DESCRIPTION |
| 1474 | * Set lock state to nvram context. |
| 1475 | * PARAMETERS |
| 1476 | * |
| 1477 | * RETURNS |
| 1478 | * void |
| 1479 | *****************************************************************************/ |
| 1480 | kal_bool nvram_decrypt_lock_state() |
| 1481 | { |
| 1482 | /*----------------------------------------------------------------*/ |
| 1483 | /* Local Variables */ |
| 1484 | /*----------------------------------------------------------------*/ |
| 1485 | kal_uint8 lock_pattern[NVRAM_EF_NVRAM_LOCK_SIZE]; |
| 1486 | nvram_ltable_entry_struct *ldi = NULL; |
| 1487 | |
| 1488 | /*----------------------------------------------------------------*/ |
| 1489 | /* Code Body */ |
| 1490 | /*----------------------------------------------------------------*/ |
| 1491 | nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_LOCK_LID); |
| 1492 | nvram_read_data_item(ldi, 1, 1, lock_pattern, NVRAM_EF_NVRAM_LOCK_SIZE); |
| 1493 | |
| 1494 | //NVRAM_EF_NVRAM_LOCK_LID have NVRAM_ATTR_CONFIDENTIAL |
| 1495 | //custom_nvram_decrypt(nvram_ptr->secret_key, lock_pattern, CODED_LOCK_PATTERN_SIZE, 0); |
| 1496 | |
| 1497 | /* Compare the lock pattern to set current lock status */ |
| 1498 | if (kal_mem_cmp(lock_pattern, NVRAM_LOCK_PATTERN_LOCKED, CODED_LOCK_PATTERN_SIZE) == 0) |
| 1499 | { |
| 1500 | nvram_ptr->saved_lock = KAL_TRUE; |
| 1501 | if(nvram_ee_info != NULL){ |
| 1502 | nvram_ee_info->nvram_init_context.saved_lock = nvram_ptr->saved_lock; |
| 1503 | } |
| 1504 | return KAL_TRUE; |
| 1505 | } |
| 1506 | else |
| 1507 | { |
| 1508 | nvram_ptr->saved_lock = KAL_FALSE; |
| 1509 | if(nvram_ee_info != NULL){ |
| 1510 | nvram_ee_info->nvram_init_context.saved_lock = nvram_ptr->saved_lock; |
| 1511 | } |
| 1512 | return KAL_FALSE; |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | /***************************************************************************** |
| 1517 | * FUNCTION |
| 1518 | * nvram_assign_system_record_default_value |
| 1519 | * DESCRIPTION |
| 1520 | * This function construct the default value of system record. |
| 1521 | * PARAMETERS |
| 1522 | * des_str_sys_rec :[out] point of the string of des system record. |
| 1523 | * source_str_sys_rec :[in ] point of the string of source system record. |
| 1524 | * RETURNS |
| 1525 | * point of the string of des system record |
| 1526 | *****************************************************************************/ |
| 1527 | kal_char * nvram_assign_system_record_default_value(kal_char *des_str_sys_rec, const kal_char *source_str_sys_rec) |
| 1528 | { |
| 1529 | /*----------------------------------------------------------------*/ |
| 1530 | /* Local Variables */ |
| 1531 | /*----------------------------------------------------------------*/ |
| 1532 | kal_uint8* CODED_PADDING = (kal_uint8*)"\x00\xDD\xC5\xB9"; |
| 1533 | |
| 1534 | /*----------------------------------------------------------------*/ |
| 1535 | /* Code Body */ |
| 1536 | /*----------------------------------------------------------------*/ |
| 1537 | kal_mem_set(des_str_sys_rec, 0, NVRAM_EF_SYS_SIZE); |
| 1538 | |
| 1539 | /** |
| 1540 | * If length of returned verno is larger than maximum capacity, |
| 1541 | * truncate it to retain tail `CODED_DATA_VERSION_SIZE' bytes, and |
| 1542 | * use it as coded_version. |
| 1543 | * Note that maximum capacity is exactly CODED_DATA_VERSION_SIZE, |
| 1544 | * instead of (CODED_DATA_VERSION_SIZE - 1); because CODED_PADDING |
| 1545 | * guarantees to terminated it with zero. |
| 1546 | */ |
| 1547 | if (strlen(source_str_sys_rec) > CODED_DATA_VERSION_SIZE) |
| 1548 | { |
| 1549 | kal_uint16 len = strlen(source_str_sys_rec) - CODED_DATA_VERSION_SIZE; |
| 1550 | |
| 1551 | source_str_sys_rec += len; |
| 1552 | } |
| 1553 | |
| 1554 | /* code version */ |
| 1555 | strncpy(des_str_sys_rec, source_str_sys_rec, CODED_DATA_VERSION_SIZE); |
| 1556 | |
| 1557 | /* code padding */ |
| 1558 | kal_mem_cpy(des_str_sys_rec + CODED_DATA_VERSION_SIZE, CODED_PADDING, CODED_PADDING_SIZE); |
| 1559 | |
| 1560 | return des_str_sys_rec; |
| 1561 | } |
| 1562 | |
| 1563 | /***************************************************************************** |
| 1564 | * FUNCTION |
| 1565 | * nvram_pre_init |
| 1566 | * DESCRIPTION |
| 1567 | * This function init necessary NVRAM information. |
| 1568 | * (no matter NVRAM task is on or not) |
| 1569 | * PARAMETERS |
| 1570 | * void |
| 1571 | * RETURNS |
| 1572 | * NVRAM_ERRNO_SUCCESS if succeed, NVRAM_ERRNO_INVALID otherwise (ie, invalid LID).(?)(?) |
| 1573 | *****************************************************************************/ |
| 1574 | static void nvram_assign_table_entry(nvram_lid_enum position, nvram_ltable_entry_struct* ldi) |
| 1575 | { |
| 1576 | /*----------------------------------------------------------------*/ |
| 1577 | /* Local Variables */ |
| 1578 | /*----------------------------------------------------------------*/ |
| 1579 | |
| 1580 | /*----------------------------------------------------------------*/ |
| 1581 | /* Code Body */ |
| 1582 | /*----------------------------------------------------------------*/ |
| 1583 | |
| 1584 | |
| 1585 | //Tool check begin: nvram_pre_gen.pl check if it is same as nvram_assign_table_entry() and nvram_gen_assign_entry() |
| 1586 | //*************************************************************************** |
| 1587 | // Adjust Attr/Category I |
| 1588 | // Do not need multiple attribute if nvram saved on nor flash |
| 1589 | //*************************************************************************** |
| 1590 | |
| 1591 | //*************************************************************************** |
| 1592 | // Adjust Attr/Category II |
| 1593 | // MULTIPLE / BACKUP_RAW / BACKUP_FAT are mutually exclusive |
| 1594 | //*************************************************************************** |
| 1595 | if (NVRAM_IS_CATEGORY_CALIBRAT(ldi->category)) |
| 1596 | { |
| 1597 | #if defined(__NVRAM_BACKUP_DISK_FAT__) |
| 1598 | ldi->attr &= ~NVRAM_ATTR_MULTIPLE; |
| 1599 | ldi->attr &= ~NVRAM_ATTR_BACKUP_RAW; |
| 1600 | ldi->attr |= NVRAM_ATTR_BACKUP_FAT; |
| 1601 | #elif defined(__NVRAM_BACKUP_DISK_RAW__) |
| 1602 | ldi->attr &= ~NVRAM_ATTR_MULTIPLE; |
| 1603 | ldi->attr |= NVRAM_ATTR_BACKUP_RAW; |
| 1604 | ldi->attr &= ~NVRAM_ATTR_BACKUP_FAT; |
| 1605 | #else |
| 1606 | #if !defined(__CCCIFS_SUPPORT__) && !defined(__FS_RAMDISK__) |
| 1607 | ldi->attr |= NVRAM_ATTR_MULTIPLE; |
| 1608 | #endif |
| 1609 | ldi->attr &= ~NVRAM_ATTR_BACKUP_RAW; |
| 1610 | ldi->attr &= ~NVRAM_ATTR_BACKUP_FAT; |
| 1611 | #endif |
| 1612 | } |
| 1613 | |
| 1614 | |
| 1615 | |
| 1616 | //*************************************************************************** |
| 1617 | // Adjust Attr/Category V |
| 1618 | // Add pseudo merge attribute |
| 1619 | //*************************************************************************** |
| 1620 | /* Record data item will be restored (end) */ |
| 1621 | #ifdef __NVRAM_PSEUDO_MERGE__ |
| 1622 | kal_uint32 nvram_chksum_size = 0; |
| 1623 | nvram_lid_chksum_info lid_chksum_info = {0}; |
| 1624 | |
| 1625 | nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE); |
| 1626 | nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length; |
| 1627 | |
| 1628 | if (!NVRAM_IS_CATEGORY_INTERNAL(ldi->category) && |
| 1629 | !NVRAM_IS_CATEGORY_SECUPACK(ldi->category) && |
| 1630 | !NVRAM_IS_CATEGORY_IMPORTANT(ldi->category) && |
| 1631 | !NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) && |
| 1632 | #ifdef __NVRAM_CUSTOM_SENSITIVE__ |
| 1633 | !NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) && |
| 1634 | #endif |
| 1635 | #ifdef __NVRAM_CUSTOM_DISK__ |
| 1636 | !NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category) && |
| 1637 | #endif |
| 1638 | ((ldi->size + nvram_chksum_size) * ldi->total_records < NVRAM_CLUSTER_SIZE)) |
| 1639 | { |
| 1640 | ldi->attr |= NVRAM_ATTR_PACKAGE; |
| 1641 | } |
| 1642 | |
| 1643 | if (NVRAM_IS_ATTR_PACKAGE(ldi->attr)) |
| 1644 | { |
| 1645 | ldi->description = NULL; |
| 1646 | ldi->attr &= ~ (NVRAM_ATTR_MULTIPLE); |
| 1647 | ldi->attr &= ~ (NVRAM_ATTR_MSP); |
| 1648 | } |
| 1649 | #endif |
| 1650 | |
| 1651 | |
| 1652 | |
| 1653 | //*************************************************************************** |
| 1654 | // Adjust Attr/Category |
| 1655 | // Simulation/Palladium/FPGA remove NVRAM_ATTR_GEN_DEFAULT |
| 1656 | //*************************************************************************** |
| 1657 | #if defined(_SIMULATION) || defined(__PALLADIUM__) || defined(__FPGA__) |
| 1658 | if (!NVRAM_IS_CATEGORY_INTERNAL(ldi->category) && (ldi->LID != NVRAM_EF_SYS_LID) && (ldi->LID != NVRAM_EF_CORE_FACTORY_RESET_AND_OTA_LID)) |
| 1659 | { |
| 1660 | #if defined (__NVRAM_UT_TEST__) |
| 1661 | // Don't remove test lid gen default attribute |
| 1662 | if(ldi->LID < NVRAM_EF_NVRAM_UNIT_TEST_LID || ldi->LID > NVRAM_EF_NVRAM_UNIT_TEST_LID_END) |
| 1663 | #endif |
| 1664 | ldi->attr &= ~(NVRAM_ATTR_GEN_DEFAULT); |
| 1665 | } |
| 1666 | #endif |
| 1667 | |
| 1668 | |
| 1669 | //*************************************************************************** |
| 1670 | // Adjust Attr/Category X |
| 1671 | // 1. Compress the data in MT table and it is in custpack |
| 1672 | // 2. Compress the default value of the data not in MT table |
| 1673 | // and its default value is not zero default or ff default |
| 1674 | // coppress function had phaseout |
| 1675 | //*************************************************************************** |
| 1676 | |
| 1677 | //*************************************************************************** |
| 1678 | // Adjust Attr/Category XI |
| 1679 | // Put Internal, Calibration, Important data into SDS |
| 1680 | //*************************************************************************** |
| 1681 | #if defined(__NVRAM_SECURE_DATA_STORAGE__) |
| 1682 | if (NVRAM_IS_CATEGORY_INTERNAL(ldi->category) || |
| 1683 | NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) || |
| 1684 | NVRAM_IS_CATEGORY_IMPORTANT(ldi->category) || |
| 1685 | NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category)) |
| 1686 | { |
| 1687 | ldi->category |= NVRAM_CATEGORY_BACKUP_SDS; |
| 1688 | |
| 1689 | ldi->attr &= ~ NVRAM_ATTR_MULTIPLE; |
| 1690 | ldi->attr &= ~ NVRAM_ATTR_RING; |
| 1691 | ldi->attr &= ~ NVRAM_ATTR_PACKAGE; |
| 1692 | ldi->attr &= ~ NVRAM_ATTR_BACKUP_FAT; |
| 1693 | ldi->attr &= ~ NVRAM_ATTR_BACKUP_RAW; |
| 1694 | } |
| 1695 | #endif |
| 1696 | //Tool check end: nvram_pre_gen.pl |
| 1697 | |
| 1698 | //*************************************************************************** |
| 1699 | // Assign entry I |
| 1700 | // Assign the secupack |
| 1701 | //*************************************************************************** |
| 1702 | if (NVRAM_IS_CATEGORY_SECUPACK(ldi->category)) |
| 1703 | { |
| 1704 | nvram_assign_secupack_entry(ldi); |
| 1705 | } |
| 1706 | |
| 1707 | //*************************************************************************** |
| 1708 | // Assign entry II |
| 1709 | // Assign the pseudo merge, nvram will use ldi->description as file offset |
| 1710 | //*************************************************************************** |
| 1711 | |
| 1712 | #ifdef __NVRAM_PSEUDO_MERGE__ |
| 1713 | ldi->description = NULL; |
| 1714 | #endif |
| 1715 | |
| 1716 | } |
| 1717 | |
| 1718 | /***************************************************************************** |
| 1719 | * FUNCTION |
| 1720 | * nvram_assign_cat_entry |
| 1721 | * DESCRIPTION |
| 1722 | * PARAMETERS |
| 1723 | * RETURNS |
| 1724 | *****************************************************************************/ |
| 1725 | static void nvram_assign_cat_default_value(nvram_lid_enum position, nvram_cat_replace_setting* cat_item) |
| 1726 | { |
| 1727 | /*----------------------------------------------------------------*/ |
| 1728 | /* Local Variables */ |
| 1729 | /*----------------------------------------------------------------*/ |
| 1730 | nvram_ltable_entry_struct *ldi; |
| 1731 | |
| 1732 | /*----------------------------------------------------------------*/ |
| 1733 | /* Code Body */ |
| 1734 | /*----------------------------------------------------------------*/ |
| 1735 | nvram_util_get_data_item(&ldi, position); |
| 1736 | |
| 1737 | if (cat_item->size != ldi->size || |
| 1738 | cat_item->total_records != ldi->total_records) |
| 1739 | { |
| 1740 | return; |
| 1741 | } |
| 1742 | |
| 1743 | ldi->default_value = cat_item->default_value; |
| 1744 | |
| 1745 | if (cat_item->is_multi_default) |
| 1746 | { |
| 1747 | ldi->attr &= NVRAM_ATTR_MULTI_DEFAULT; |
| 1748 | } |
| 1749 | else |
| 1750 | { |
| 1751 | ldi->attr &= ~NVRAM_ATTR_MULTI_DEFAULT; |
| 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | /***************************************************************************** |
| 1756 | * FUNCTION |
| 1757 | * ltable_construct |
| 1758 | * DESCRIPTION |
| 1759 | * Constructor of ltable. Calculate Record ID according to each logical data item's |
| 1760 | * attributes. |
| 1761 | * PARAMETERS |
| 1762 | * ltable [IN/OUT] The user configured logical data item table. |
| 1763 | * RETURNS |
| 1764 | * void |
| 1765 | *****************************************************************************/ |
| 1766 | static nvram_ltable_entry_struct *tbl_p; |
| 1767 | void nvram_set_ltable(nvram_ltable_entry_struct *table) |
| 1768 | { |
| 1769 | tbl_p = (table>logical_data_item_table_internal)?table:logical_data_item_table_internal; |
| 1770 | } |
| 1771 | |
| 1772 | nvram_ltable_entry_struct *nvram_get_ltable(void) |
| 1773 | { |
| 1774 | return tbl_p; |
| 1775 | } |
| 1776 | |
| 1777 | static void nvram_assgn_ltable(void) |
| 1778 | { |
| 1779 | #ifdef __MTK_TARGET__ |
| 1780 | extern kal_uint32 _nvram_ltable$$Base, _nvram_ltable$$Length; |
| 1781 | |
| 1782 | logical_data_item_table = (nvram_ltable_entry_struct *)&_nvram_ltable$$Base; |
| 1783 | nvram_ptr->ltable.table = &logical_data_item_table; |
| 1784 | nvram_ptr->ltable.area_size = (kal_uint32)&_nvram_ltable$$Length; |
| 1785 | nvram_ptr->ltable.total_LID = nvram_ptr->ltable.area_size/sizeof(nvram_ltable_entry_struct); |
| 1786 | if(nvram_ee_info != NULL){ |
| 1787 | nvram_ee_info->nvram_init_context.total_LID= nvram_ptr->ltable.total_LID; |
| 1788 | nvram_ee_info->nvram_init_context.area_size = nvram_ptr->ltable.area_size; |
| 1789 | } |
| 1790 | #else |
| 1791 | kal_uint32 i, offset = 0; |
| 1792 | nvram_ltable_entry_struct *ltable_entry = NULL; |
| 1793 | nvram_ltable_entry_struct *the_start = &_nvram_ltable_start; |
| 1794 | kal_uint32 start_addr = (kal_uint32)the_start, end_addr = (kal_uint32)&the_nvram_ltable_end; |
| 1795 | |
| 1796 | #if defined(_MSC_VER) && !defined(L1_SIM) |
| 1797 | //skip session gap |
| 1798 | for (offset = 0; offset < 0x1000; offset += 32) // __declspec(align(32)) |
| 1799 | { |
| 1800 | ltable_entry = (nvram_ltable_entry_struct*)((kal_uint32)&the_start[0] + offset); |
| 1801 | if(ltable_entry->fileprefix[0]) { |
| 1802 | break; |
| 1803 | } |
| 1804 | } |
| 1805 | #endif |
| 1806 | |
| 1807 | for (i = 0;(kal_uint32)ltable_entry <= end_addr; i++) |
| 1808 | { |
| 1809 | ltable_entry = (nvram_ltable_entry_struct*)((kal_uint32)&the_start[i] + offset); |
| 1810 | |
| 1811 | if (logical_data_item_table == NULL && ltable_entry->fileprefix[0]) |
| 1812 | { |
| 1813 | logical_data_item_table = ltable_entry; |
| 1814 | nvram_ptr->ltable.table = &logical_data_item_table; |
| 1815 | } |
| 1816 | |
| 1817 | if (ltable_entry->fileprefix[0]) |
| 1818 | { |
| 1819 | //printf("%03d: ltable[%d]:%x filename = %s\n", nvram_ptr->ltable.total_LID, ltable_entry->LID, ltable_entry, ltable_entry->fileprefix); |
| 1820 | nvram_ptr->ltable.total_LID++; |
| 1821 | } |
| 1822 | else |
| 1823 | { |
| 1824 | ltable_entry = (nvram_ltable_entry_struct*)((kal_uint32)&the_start[i] + offset + 32); |
| 1825 | if (ltable_entry->fileprefix[0]) |
| 1826 | { |
| 1827 | //printf("%03d: ltable[%d]:%x filename = %s\n", nvram_ptr->ltable.total_LID, ltable_entry->LID, ltable_entry, ltable_entry->fileprefix); |
| 1828 | nvram_ptr->ltable.total_LID++; |
| 1829 | } |
| 1830 | } |
| 1831 | } |
| 1832 | |
| 1833 | nvram_ptr->ltable.area_size = (kal_uint32)ltable_entry - (kal_uint32)logical_data_item_table; |
| 1834 | |
| 1835 | #endif |
| 1836 | } |
| 1837 | |
| 1838 | void nvram_ltable_construct(void) |
| 1839 | { |
| 1840 | /*----------------------------------------------------------------*/ |
| 1841 | /* Local Variables */ |
| 1842 | /*----------------------------------------------------------------*/ |
| 1843 | kal_uint32 i = 0; |
| 1844 | nvram_ltable_entry_struct *ltable_entry; |
| 1845 | |
| 1846 | /*----------------------------------------------------------------*/ |
| 1847 | /* Code Body */ |
| 1848 | /*----------------------------------------------------------------*/ |
| 1849 | |
| 1850 | |
| 1851 | nvram_assgn_ltable(); |
| 1852 | |
| 1853 | ltable_entry = &logical_data_item_table[0]; |
| 1854 | do |
| 1855 | { |
| 1856 | if (ltable_entry) |
| 1857 | { |
| 1858 | #ifdef __NVRAM_PSEUDO_MERGE__ |
| 1859 | if (nvram_query_lid_merge(ltable_entry)) |
| 1860 | { |
| 1861 | nvram_assign_package_entry(ltable_entry); |
| 1862 | } |
| 1863 | #endif /* __NVRAM_PSEUDO_MERGE__ */ |
| 1864 | |
| 1865 | nvram_assign_table_entry(ltable_entry->LID, ltable_entry); |
| 1866 | } |
| 1867 | |
| 1868 | }while(nvram_util_next_data_item(<able_entry)); |
| 1869 | |
| 1870 | |
| 1871 | /* |
| 1872 | * So far,logical table has been constructed |
| 1873 | */ |
| 1874 | |
| 1875 | /* |
| 1876 | * Assign the custpack default value to ltable |
| 1877 | */ |
| 1878 | nvram_assign_custpack_default_value(); |
| 1879 | |
| 1880 | /* |
| 1881 | * Assign the cat tool default value |
| 1882 | */ |
| 1883 | i = 0; |
| 1884 | while (nvram_cat_replace_tbl[i].LID != NVRAM_EF_RESERVED_LID) |
| 1885 | { |
| 1886 | nvram_assign_cat_default_value(nvram_cat_replace_tbl[i].LID, &nvram_cat_replace_tbl[i]); |
| 1887 | i++; |
| 1888 | } |
| 1889 | |
| 1890 | /* |
| 1891 | * Assign the versions to ltable |
| 1892 | */ |
| 1893 | |
| 1894 | /* First, define system-level record */ |
| 1895 | |
| 1896 | |
| 1897 | /* Branch version */ |
| 1898 | memset(nvram_ptr->branch_version, 0, NVRAM_EF_BRANCH_VERNO_SIZE + 1); |
| 1899 | strncpy((char*)nvram_ptr->branch_version, (char*)release_branch(), NVRAM_EF_BRANCH_VERNO_SIZE); |
| 1900 | |
| 1901 | /* Flavor version */ |
| 1902 | memset(nvram_ptr->flavor_version, 0, NVRAM_EF_FLAVOR_VERNO_SIZE + 1); |
| 1903 | strncpy((char*)nvram_ptr->flavor_version, (char*)release_flavor(), NVRAM_EF_FLAVOR_VERNO_SIZE); |
| 1904 | |
| 1905 | /* Build time */ |
| 1906 | memset(nvram_ptr->build_time, 0, NVRAM_EF_BUILD_TIME_SIZE + 1); |
| 1907 | strncpy((char*)nvram_ptr->build_time, (char*)build_date_time(), NVRAM_EF_FLAVOR_VERNO_SIZE); |
| 1908 | |
| 1909 | |
| 1910 | /* Default lock status is LOCKED -- by using lock pattern of CODED_LOCK_PATTERN */ |
| 1911 | nvram_assign_system_record_default_value((kal_char *)nvram_ptr->coded_version, release_verno()); |
| 1912 | //nvram_ptr->lock should be KAL_FALSE during pre-init |
| 1913 | nvram_ptr->lock = KAL_FALSE; |
| 1914 | nvram_ptr->saved_lock = nvram_custom_lock_status(); |
| 1915 | if(nvram_ee_info != NULL){ |
| 1916 | nvram_ee_info->nvram_init_context.lock = nvram_ptr->lock; |
| 1917 | nvram_ee_info->nvram_init_context.saved_lock = nvram_ptr->saved_lock; |
| 1918 | } |
| 1919 | } /* end of ltable_construct function */ |
| 1920 | |
| 1921 | |
| 1922 | #ifdef __NVRAM_OTP__ |
| 1923 | |
| 1924 | |
| 1925 | /***************************************************************************** |
| 1926 | * FUNCTION |
| 1927 | * nvram_otp_construct |
| 1928 | * DESCRIPTION |
| 1929 | * Construct OTP table. |
| 1930 | * PARAMETERS |
| 1931 | * void |
| 1932 | * RETURNS |
| 1933 | * void |
| 1934 | *****************************************************************************/ |
| 1935 | void nvram_otp_construct(void) |
| 1936 | { |
| 1937 | /*----------------------------------------------------------------*/ |
| 1938 | /* Local Variables */ |
| 1939 | /*----------------------------------------------------------------*/ |
| 1940 | // kal_uint32 file_idx; |
| 1941 | nvram_ltable_entry_struct *ldi; |
| 1942 | kal_uint32 fs_otp_size = 0; |
| 1943 | nvram_lid_enum nvram_otp_idx = 0; |
| 1944 | kal_uint32 nvram_otp_size = 0; /* if version is supported, init it as version length */ |
| 1945 | nvram_drv_status_enum status; |
| 1946 | |
| 1947 | /*----------------------------------------------------------------*/ |
| 1948 | /* Code Body */ |
| 1949 | /*----------------------------------------------------------------*/ |
| 1950 | ldi = &logical_data_item_table[0]; |
| 1951 | do |
| 1952 | { |
| 1953 | |
| 1954 | if (ldi->category & NVRAM_CATEGORY_OTP) |
| 1955 | { |
| 1956 | NVRAM_EXT_ASSERT(nvram_otp_idx < NVRAM_OTP_TOTAL,(kal_uint32)nvram_otp_idx, NVRAM_LOC_INVALID_INDEX_1, NVRAM_OTP_TOTAL); |
| 1957 | |
| 1958 | nvram_otp_ltable[nvram_otp_idx].offset = nvram_otp_size; |
| 1959 | nvram_otp_size += ldi->size * ldi->total_records; |
| 1960 | |
| 1961 | nvram_otp_ltable[nvram_otp_idx].LID = ldi->LID; |
| 1962 | nvram_otp_idx++; |
| 1963 | } |
| 1964 | }while(nvram_util_next_data_item(&ldi)); |
| 1965 | #ifdef __MTK_TARGET__ |
| 1966 | NVRAM_FS_START(FS_OP_OTPQUERYLENGTH); |
| 1967 | status = FS_OTPQueryLength(FS_DEVICE_TYPE_UNKNOWN, &fs_otp_size); |
| 1968 | NVRAM_FS_END(FS_OP_OTPQUERYLENGTH,status); |
| 1969 | #else |
| 1970 | fs_otp_size = 256; |
| 1971 | #endif |
| 1972 | NVRAM_EXT_ASSERT(nvram_otp_size <= fs_otp_size, status, NVRAM_LOC_OTP_INIT_FAIL, fs_otp_size); |
| 1973 | |
| 1974 | } |
| 1975 | |
| 1976 | /***************************************************************************** |
| 1977 | * FUNCTION |
| 1978 | * nvram_get_otp_offset |
| 1979 | * DESCRIPTION |
| 1980 | * Construct OTP table. |
| 1981 | * PARAMETERS |
| 1982 | * void |
| 1983 | * RETURNS |
| 1984 | * void |
| 1985 | *****************************************************************************/ |
| 1986 | kal_uint32 nvram_get_otp_offset(nvram_lid_enum lid) |
| 1987 | { |
| 1988 | /*----------------------------------------------------------------*/ |
| 1989 | /* Local Variables */ |
| 1990 | /*----------------------------------------------------------------*/ |
| 1991 | kal_int32 i; |
| 1992 | |
| 1993 | /*----------------------------------------------------------------*/ |
| 1994 | /* Code Body */ |
| 1995 | /*----------------------------------------------------------------*/ |
| 1996 | for(i = NVRAM_OTP_TOTAL - 1; i >= 0 ; i--) |
| 1997 | { |
| 1998 | if (nvram_otp_ltable[i].LID == lid) |
| 1999 | { |
| 2000 | return nvram_otp_ltable[i].offset; |
| 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)lid, NVRAM_LOC_INVALID_LID_3, i); |
| 2005 | |
| 2006 | return 0; |
| 2007 | } |
| 2008 | |
| 2009 | |
| 2010 | #endif /* __NVRAM_OTP__ */ |