yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [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 | * nvram_main.c |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * MAUI |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * This is main() function of NVRAM module. |
| 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 | * |
| 60 | * removed! |
| 61 | * removed! |
| 62 | * removed! |
| 63 | * |
| 64 | * removed! |
| 65 | * removed! |
| 66 | * removed! |
| 67 | * removed! |
| 68 | * |
| 69 | * removed! |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * removed! |
| 78 | * |
| 79 | * removed! |
| 80 | * removed! |
| 81 | * removed! |
| 82 | * removed! |
| 83 | * |
| 84 | * removed! |
| 85 | * removed! |
| 86 | * removed! |
| 87 | * removed! |
| 88 | * |
| 89 | * removed! |
| 90 | * removed! |
| 91 | * removed! |
| 92 | * |
| 93 | * removed! |
| 94 | * removed! |
| 95 | * removed! |
| 96 | * removed! |
| 97 | * |
| 98 | * removed! |
| 99 | * removed! |
| 100 | * removed! |
| 101 | * removed! |
| 102 | * |
| 103 | * removed! |
| 104 | * removed! |
| 105 | * removed! |
| 106 | * |
| 107 | * removed! |
| 108 | * removed! |
| 109 | * removed! |
| 110 | * removed! |
| 111 | * removed! |
| 112 | * removed! |
| 113 | * removed! |
| 114 | * removed! |
| 115 | * removed! |
| 116 | * removed! |
| 117 | * removed! |
| 118 | * |
| 119 | * removed! |
| 120 | * removed! |
| 121 | * removed! |
| 122 | * removed! |
| 123 | * removed! |
| 124 | * removed! |
| 125 | * removed! |
| 126 | * removed! |
| 127 | * removed! |
| 128 | * removed! |
| 129 | * |
| 130 | * removed! |
| 131 | * removed! |
| 132 | * removed! |
| 133 | * removed! |
| 134 | * |
| 135 | * removed! |
| 136 | * removed! |
| 137 | * removed! |
| 138 | * removed! |
| 139 | * |
| 140 | * removed! |
| 141 | * removed! |
| 142 | * removed! |
| 143 | * |
| 144 | * removed! |
| 145 | * removed! |
| 146 | * removed! |
| 147 | * |
| 148 | * removed! |
| 149 | * |
| 150 | * removed! |
| 151 | * removed! |
| 152 | * removed! |
| 153 | * removed! |
| 154 | * removed! |
| 155 | * removed! |
| 156 | * removed! |
| 157 | * removed! |
| 158 | * |
| 159 | * removed! |
| 160 | * removed! |
| 161 | * |
| 162 | * removed! |
| 163 | * removed! |
| 164 | * removed! |
| 165 | * removed! |
| 166 | * |
| 167 | * removed! |
| 168 | * removed! |
| 169 | * removed! |
| 170 | * removed! |
| 171 | * |
| 172 | * removed! |
| 173 | * removed! |
| 174 | * removed! |
| 175 | * removed! |
| 176 | * |
| 177 | * removed! |
| 178 | * removed! |
| 179 | * removed! |
| 180 | * |
| 181 | * removed! |
| 182 | * removed! |
| 183 | * |
| 184 | * removed! |
| 185 | * removed! |
| 186 | * removed! |
| 187 | * removed! |
| 188 | * |
| 189 | * removed! |
| 190 | * removed! |
| 191 | * removed! |
| 192 | * removed! |
| 193 | * |
| 194 | * removed! |
| 195 | * removed! |
| 196 | * removed! |
| 197 | * removed! |
| 198 | * |
| 199 | * removed! |
| 200 | * removed! |
| 201 | * |
| 202 | * removed! |
| 203 | * removed! |
| 204 | * removed! |
| 205 | * |
| 206 | * removed! |
| 207 | * removed! |
| 208 | * removed! |
| 209 | * removed! |
| 210 | * |
| 211 | * removed! |
| 212 | * removed! |
| 213 | * removed! |
| 214 | * removed! |
| 215 | * |
| 216 | * removed! |
| 217 | * removed! |
| 218 | * removed! |
| 219 | * removed! |
| 220 | * |
| 221 | * removed! |
| 222 | * removed! |
| 223 | * |
| 224 | * removed! |
| 225 | * removed! |
| 226 | * removed! |
| 227 | * |
| 228 | * removed! |
| 229 | * removed! |
| 230 | * removed! |
| 231 | * |
| 232 | * removed! |
| 233 | * removed! |
| 234 | * removed! |
| 235 | * removed! |
| 236 | * removed! |
| 237 | * |
| 238 | * removed! |
| 239 | * removed! |
| 240 | * removed! |
| 241 | * |
| 242 | * removed! |
| 243 | * removed! |
| 244 | * removed! |
| 245 | * |
| 246 | * removed! |
| 247 | * removed! |
| 248 | * removed! |
| 249 | * |
| 250 | * removed! |
| 251 | * removed! |
| 252 | * removed! |
| 253 | * |
| 254 | * removed! |
| 255 | * removed! |
| 256 | * removed! |
| 257 | * removed! |
| 258 | * |
| 259 | * removed! |
| 260 | * removed! |
| 261 | * removed! |
| 262 | * removed! |
| 263 | * |
| 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 | * removed! |
| 283 | * |
| 284 | * removed! |
| 285 | * removed! |
| 286 | * removed! |
| 287 | * |
| 288 | * removed! |
| 289 | * removed! |
| 290 | * |
| 291 | * removed! |
| 292 | * removed! |
| 293 | * removed! |
| 294 | * |
| 295 | * removed! |
| 296 | * removed! |
| 297 | * removed! |
| 298 | * |
| 299 | * removed! |
| 300 | * removed! |
| 301 | * |
| 302 | * removed! |
| 303 | * removed! |
| 304 | * |
| 305 | * removed! |
| 306 | * removed! |
| 307 | * removed! |
| 308 | * |
| 309 | * removed! |
| 310 | * removed! |
| 311 | * removed! |
| 312 | * |
| 313 | * removed! |
| 314 | * removed! |
| 315 | * removed! |
| 316 | * |
| 317 | * removed! |
| 318 | * removed! |
| 319 | * removed! |
| 320 | * |
| 321 | * removed! |
| 322 | * removed! |
| 323 | * removed! |
| 324 | * |
| 325 | * removed! |
| 326 | * removed! |
| 327 | * removed! |
| 328 | * removed! |
| 329 | * |
| 330 | * removed! |
| 331 | * removed! |
| 332 | * |
| 333 | * removed! |
| 334 | * removed! |
| 335 | * |
| 336 | * removed! |
| 337 | * removed! |
| 338 | * removed! |
| 339 | * |
| 340 | * removed! |
| 341 | * removed! |
| 342 | * removed! |
| 343 | * |
| 344 | * removed! |
| 345 | * removed! |
| 346 | * removed! |
| 347 | * |
| 348 | * removed! |
| 349 | * removed! |
| 350 | * removed! |
| 351 | * |
| 352 | * removed! |
| 353 | * removed! |
| 354 | * removed! |
| 355 | * |
| 356 | * removed! |
| 357 | * removed! |
| 358 | * removed! |
| 359 | * |
| 360 | * removed! |
| 361 | * removed! |
| 362 | * removed! |
| 363 | * |
| 364 | * removed! |
| 365 | * removed! |
| 366 | * removed! |
| 367 | * |
| 368 | * removed! |
| 369 | * removed! |
| 370 | * removed! |
| 371 | * |
| 372 | * removed! |
| 373 | * removed! |
| 374 | * removed! |
| 375 | * |
| 376 | * removed! |
| 377 | * removed! |
| 378 | * removed! |
| 379 | * |
| 380 | * removed! |
| 381 | * removed! |
| 382 | * removed! |
| 383 | * |
| 384 | * removed! |
| 385 | * removed! |
| 386 | * removed! |
| 387 | * |
| 388 | * removed! |
| 389 | * removed! |
| 390 | * removed! |
| 391 | * |
| 392 | * removed! |
| 393 | * removed! |
| 394 | * removed! |
| 395 | * |
| 396 | * removed! |
| 397 | * removed! |
| 398 | * removed! |
| 399 | * |
| 400 | * removed! |
| 401 | * removed! |
| 402 | * removed! |
| 403 | * |
| 404 | * removed! |
| 405 | * removed! |
| 406 | * removed! |
| 407 | * |
| 408 | * removed! |
| 409 | * removed! |
| 410 | * removed! |
| 411 | * |
| 412 | * removed! |
| 413 | * removed! |
| 414 | * removed! |
| 415 | * |
| 416 | * removed! |
| 417 | * removed! |
| 418 | * removed! |
| 419 | * |
| 420 | * removed! |
| 421 | * removed! |
| 422 | * removed! |
| 423 | * |
| 424 | * removed! |
| 425 | * removed! |
| 426 | * removed! |
| 427 | * |
| 428 | * removed! |
| 429 | * removed! |
| 430 | * removed! |
| 431 | * |
| 432 | * removed! |
| 433 | * removed! |
| 434 | * removed! |
| 435 | * |
| 436 | * removed! |
| 437 | * removed! |
| 438 | * removed! |
| 439 | * |
| 440 | * removed! |
| 441 | * removed! |
| 442 | * removed! |
| 443 | * |
| 444 | * removed! |
| 445 | * removed! |
| 446 | * removed! |
| 447 | * removed! |
| 448 | * removed! |
| 449 | * removed! |
| 450 | * removed! |
| 451 | * removed! |
| 452 | * removed! |
| 453 | * removed! |
| 454 | * removed! |
| 455 | * removed! |
| 456 | * removed! |
| 457 | * removed! |
| 458 | * removed! |
| 459 | * removed! |
| 460 | * removed! |
| 461 | * removed! |
| 462 | * removed! |
| 463 | * removed! |
| 464 | * removed! |
| 465 | * removed! |
| 466 | * removed! |
| 467 | * removed! |
| 468 | * |
| 469 | * removed! |
| 470 | * removed! |
| 471 | * removed! |
| 472 | * |
| 473 | * removed! |
| 474 | * removed! |
| 475 | * removed! |
| 476 | * |
| 477 | * removed! |
| 478 | * removed! |
| 479 | * removed! |
| 480 | * |
| 481 | * removed! |
| 482 | * removed! |
| 483 | * removed! |
| 484 | * |
| 485 | * removed! |
| 486 | * removed! |
| 487 | * removed! |
| 488 | * |
| 489 | * removed! |
| 490 | * removed! |
| 491 | * removed! |
| 492 | * |
| 493 | * removed! |
| 494 | * removed! |
| 495 | * removed! |
| 496 | * |
| 497 | * removed! |
| 498 | * removed! |
| 499 | * removed! |
| 500 | * |
| 501 | * removed! |
| 502 | * removed! |
| 503 | * removed! |
| 504 | * |
| 505 | * removed! |
| 506 | * removed! |
| 507 | * removed! |
| 508 | * |
| 509 | * removed! |
| 510 | * removed! |
| 511 | * removed! |
| 512 | * |
| 513 | * removed! |
| 514 | * removed! |
| 515 | * removed! |
| 516 | * |
| 517 | * removed! |
| 518 | * removed! |
| 519 | * removed! |
| 520 | * |
| 521 | * removed! |
| 522 | * removed! |
| 523 | * removed! |
| 524 | * |
| 525 | * removed! |
| 526 | * removed! |
| 527 | * removed! |
| 528 | * |
| 529 | * removed! |
| 530 | * removed! |
| 531 | * removed! |
| 532 | * |
| 533 | * removed! |
| 534 | * removed! |
| 535 | * removed! |
| 536 | * |
| 537 | * removed! |
| 538 | * removed! |
| 539 | * removed! |
| 540 | * |
| 541 | * removed! |
| 542 | * removed! |
| 543 | * removed! |
| 544 | * |
| 545 | * removed! |
| 546 | * removed! |
| 547 | * removed! |
| 548 | * |
| 549 | * removed! |
| 550 | * removed! |
| 551 | * removed! |
| 552 | * |
| 553 | * removed! |
| 554 | * removed! |
| 555 | * removed! |
| 556 | * |
| 557 | * removed! |
| 558 | * removed! |
| 559 | * removed! |
| 560 | * |
| 561 | * removed! |
| 562 | * removed! |
| 563 | * removed! |
| 564 | * |
| 565 | * removed! |
| 566 | * removed! |
| 567 | * removed! |
| 568 | * |
| 569 | * removed! |
| 570 | * removed! |
| 571 | * removed! |
| 572 | * |
| 573 | * removed! |
| 574 | * removed! |
| 575 | * removed! |
| 576 | * |
| 577 | * removed! |
| 578 | * removed! |
| 579 | * removed! |
| 580 | * |
| 581 | * removed! |
| 582 | * removed! |
| 583 | * removed! |
| 584 | * |
| 585 | * removed! |
| 586 | * removed! |
| 587 | * removed! |
| 588 | * |
| 589 | * removed! |
| 590 | * removed! |
| 591 | * removed! |
| 592 | * |
| 593 | * removed! |
| 594 | * removed! |
| 595 | * removed! |
| 596 | * |
| 597 | * removed! |
| 598 | * removed! |
| 599 | * removed! |
| 600 | * |
| 601 | * removed! |
| 602 | * removed! |
| 603 | * removed! |
| 604 | * |
| 605 | * removed! |
| 606 | * removed! |
| 607 | * removed! |
| 608 | * |
| 609 | * removed! |
| 610 | * removed! |
| 611 | * removed! |
| 612 | * |
| 613 | * removed! |
| 614 | * removed! |
| 615 | * removed! |
| 616 | * |
| 617 | * removed! |
| 618 | * removed! |
| 619 | * removed! |
| 620 | * |
| 621 | * removed! |
| 622 | * removed! |
| 623 | * removed! |
| 624 | * |
| 625 | * removed! |
| 626 | * removed! |
| 627 | * removed! |
| 628 | * |
| 629 | * removed! |
| 630 | * removed! |
| 631 | * removed! |
| 632 | * |
| 633 | * removed! |
| 634 | * removed! |
| 635 | * removed! |
| 636 | * |
| 637 | * removed! |
| 638 | * removed! |
| 639 | * removed! |
| 640 | * |
| 641 | * removed! |
| 642 | * removed! |
| 643 | * removed! |
| 644 | * |
| 645 | * removed! |
| 646 | * removed! |
| 647 | * removed! |
| 648 | * |
| 649 | * removed! |
| 650 | * removed! |
| 651 | * removed! |
| 652 | * |
| 653 | * removed! |
| 654 | * removed! |
| 655 | * removed! |
| 656 | * |
| 657 | * removed! |
| 658 | * removed! |
| 659 | * removed! |
| 660 | * |
| 661 | * removed! |
| 662 | * removed! |
| 663 | * removed! |
| 664 | * |
| 665 | * removed! |
| 666 | * removed! |
| 667 | * removed! |
| 668 | * |
| 669 | * removed! |
| 670 | * removed! |
| 671 | * removed! |
| 672 | * |
| 673 | * removed! |
| 674 | * removed! |
| 675 | * removed! |
| 676 | * |
| 677 | * removed! |
| 678 | * removed! |
| 679 | * removed! |
| 680 | * |
| 681 | * removed! |
| 682 | * removed! |
| 683 | * removed! |
| 684 | * |
| 685 | * removed! |
| 686 | * removed! |
| 687 | * removed! |
| 688 | * |
| 689 | * removed! |
| 690 | * removed! |
| 691 | * removed! |
| 692 | * |
| 693 | * removed! |
| 694 | * removed! |
| 695 | * removed! |
| 696 | * |
| 697 | * removed! |
| 698 | * removed! |
| 699 | * removed! |
| 700 | * |
| 701 | * removed! |
| 702 | * removed! |
| 703 | * removed! |
| 704 | * |
| 705 | * removed! |
| 706 | * removed! |
| 707 | * removed! |
| 708 | * |
| 709 | * removed! |
| 710 | * removed! |
| 711 | * |
| 712 | * |
| 713 | * removed! |
| 714 | * removed! |
| 715 | * |
| 716 | * |
| 717 | * removed! |
| 718 | * removed! |
| 719 | * |
| 720 | * |
| 721 | * removed! |
| 722 | * removed! |
| 723 | * |
| 724 | * |
| 725 | * removed! |
| 726 | * removed! |
| 727 | * |
| 728 | * |
| 729 | * removed! |
| 730 | * removed! |
| 731 | * |
| 732 | * |
| 733 | * removed! |
| 734 | * removed! |
| 735 | * |
| 736 | * |
| 737 | * removed! |
| 738 | * removed! |
| 739 | * |
| 740 | * |
| 741 | * removed! |
| 742 | * removed! |
| 743 | * |
| 744 | * |
| 745 | * removed! |
| 746 | * removed! |
| 747 | * |
| 748 | * |
| 749 | * removed! |
| 750 | * removed! |
| 751 | * |
| 752 | * |
| 753 | * removed! |
| 754 | * removed! |
| 755 | * |
| 756 | * |
| 757 | * removed! |
| 758 | * removed! |
| 759 | * |
| 760 | * |
| 761 | * removed! |
| 762 | * removed! |
| 763 | * |
| 764 | * |
| 765 | * removed! |
| 766 | * removed! |
| 767 | * |
| 768 | * |
| 769 | * removed! |
| 770 | * removed! |
| 771 | * |
| 772 | * |
| 773 | * removed! |
| 774 | * removed! |
| 775 | * |
| 776 | * |
| 777 | * removed! |
| 778 | * removed! |
| 779 | * |
| 780 | * |
| 781 | * removed! |
| 782 | * removed! |
| 783 | * |
| 784 | * |
| 785 | * removed! |
| 786 | * removed! |
| 787 | * |
| 788 | * |
| 789 | * removed! |
| 790 | * removed! |
| 791 | * |
| 792 | * |
| 793 | * removed! |
| 794 | * removed! |
| 795 | * |
| 796 | * |
| 797 | * removed! |
| 798 | * removed! |
| 799 | * |
| 800 | * |
| 801 | * removed! |
| 802 | * removed! |
| 803 | * |
| 804 | * |
| 805 | * removed! |
| 806 | * removed! |
| 807 | * |
| 808 | * |
| 809 | * removed! |
| 810 | * removed! |
| 811 | * |
| 812 | * |
| 813 | * removed! |
| 814 | * removed! |
| 815 | * |
| 816 | * |
| 817 | * removed! |
| 818 | * removed! |
| 819 | * |
| 820 | * |
| 821 | * removed! |
| 822 | * removed! |
| 823 | * |
| 824 | * |
| 825 | * removed! |
| 826 | * removed! |
| 827 | * |
| 828 | * |
| 829 | * removed! |
| 830 | * removed! |
| 831 | * |
| 832 | * |
| 833 | * removed! |
| 834 | * removed! |
| 835 | * |
| 836 | * |
| 837 | * removed! |
| 838 | * removed! |
| 839 | * |
| 840 | * |
| 841 | * removed! |
| 842 | * removed! |
| 843 | * |
| 844 | * |
| 845 | * removed! |
| 846 | * removed! |
| 847 | * |
| 848 | * |
| 849 | * removed! |
| 850 | * removed! |
| 851 | * |
| 852 | * |
| 853 | * removed! |
| 854 | * removed! |
| 855 | * |
| 856 | * |
| 857 | * removed! |
| 858 | * removed! |
| 859 | * |
| 860 | * |
| 861 | * removed! |
| 862 | * removed! |
| 863 | * |
| 864 | * |
| 865 | * removed! |
| 866 | * removed! |
| 867 | * |
| 868 | * |
| 869 | * removed! |
| 870 | * removed! |
| 871 | * |
| 872 | * |
| 873 | * removed! |
| 874 | * removed! |
| 875 | * |
| 876 | * |
| 877 | * removed! |
| 878 | * removed! |
| 879 | * |
| 880 | * |
| 881 | * removed! |
| 882 | * removed! |
| 883 | * |
| 884 | * |
| 885 | * removed! |
| 886 | * removed! |
| 887 | * |
| 888 | * |
| 889 | * removed! |
| 890 | * removed! |
| 891 | * |
| 892 | * |
| 893 | * removed! |
| 894 | * removed! |
| 895 | * |
| 896 | * |
| 897 | * removed! |
| 898 | * removed! |
| 899 | * |
| 900 | * |
| 901 | * removed! |
| 902 | * removed! |
| 903 | * |
| 904 | * |
| 905 | * removed! |
| 906 | * removed! |
| 907 | * |
| 908 | * |
| 909 | * removed! |
| 910 | * removed! |
| 911 | * |
| 912 | * |
| 913 | * removed! |
| 914 | * removed! |
| 915 | * |
| 916 | * |
| 917 | * removed! |
| 918 | * removed! |
| 919 | * |
| 920 | * |
| 921 | * removed! |
| 922 | * removed! |
| 923 | * |
| 924 | * |
| 925 | * removed! |
| 926 | * removed! |
| 927 | * |
| 928 | * |
| 929 | * removed! |
| 930 | * removed! |
| 931 | * |
| 932 | * |
| 933 | * removed! |
| 934 | * removed! |
| 935 | * |
| 936 | * |
| 937 | * removed! |
| 938 | * removed! |
| 939 | * |
| 940 | * |
| 941 | * removed! |
| 942 | * removed! |
| 943 | * |
| 944 | * |
| 945 | * removed! |
| 946 | * removed! |
| 947 | * |
| 948 | * |
| 949 | * removed! |
| 950 | * removed! |
| 951 | * |
| 952 | * |
| 953 | * removed! |
| 954 | * removed! |
| 955 | * |
| 956 | * |
| 957 | * removed! |
| 958 | * removed! |
| 959 | * |
| 960 | * |
| 961 | * removed! |
| 962 | * removed! |
| 963 | * |
| 964 | * |
| 965 | * removed! |
| 966 | * removed! |
| 967 | * |
| 968 | * |
| 969 | * removed! |
| 970 | * removed! |
| 971 | * |
| 972 | * |
| 973 | * removed! |
| 974 | * removed! |
| 975 | * |
| 976 | * |
| 977 | * removed! |
| 978 | * removed! |
| 979 | * removed! |
| 980 | * |
| 981 | * removed! |
| 982 | * removed! |
| 983 | * |
| 984 | * |
| 985 | * removed! |
| 986 | * removed! |
| 987 | * removed! |
| 988 | * |
| 989 | * removed! |
| 990 | * removed! |
| 991 | * |
| 992 | * |
| 993 | * removed! |
| 994 | * removed! |
| 995 | * |
| 996 | * |
| 997 | * removed! |
| 998 | * removed! |
| 999 | * |
| 1000 | * |
| 1001 | * removed! |
| 1002 | * removed! |
| 1003 | * |
| 1004 | * |
| 1005 | * removed! |
| 1006 | * removed! |
| 1007 | * |
| 1008 | * |
| 1009 | * removed! |
| 1010 | * removed! |
| 1011 | * |
| 1012 | * |
| 1013 | * removed! |
| 1014 | * removed! |
| 1015 | * |
| 1016 | * |
| 1017 | * removed! |
| 1018 | * removed! |
| 1019 | * |
| 1020 | * |
| 1021 | * removed! |
| 1022 | * removed! |
| 1023 | * |
| 1024 | * |
| 1025 | * removed! |
| 1026 | * removed! |
| 1027 | * |
| 1028 | * |
| 1029 | * removed! |
| 1030 | * removed! |
| 1031 | * |
| 1032 | * |
| 1033 | * removed! |
| 1034 | * removed! |
| 1035 | * |
| 1036 | * |
| 1037 | * removed! |
| 1038 | * removed! |
| 1039 | * removed! |
| 1040 | * |
| 1041 | * removed! |
| 1042 | * removed! |
| 1043 | * |
| 1044 | * |
| 1045 | * removed! |
| 1046 | * removed! |
| 1047 | * |
| 1048 | * |
| 1049 | * removed! |
| 1050 | * removed! |
| 1051 | * |
| 1052 | * |
| 1053 | * removed! |
| 1054 | * removed! |
| 1055 | * |
| 1056 | * |
| 1057 | * removed! |
| 1058 | * removed! |
| 1059 | * |
| 1060 | * |
| 1061 | * removed! |
| 1062 | * removed! |
| 1063 | * |
| 1064 | * |
| 1065 | * removed! |
| 1066 | * removed! |
| 1067 | * |
| 1068 | * |
| 1069 | * removed! |
| 1070 | * removed! |
| 1071 | * |
| 1072 | * |
| 1073 | * removed! |
| 1074 | * removed! |
| 1075 | * |
| 1076 | * |
| 1077 | * removed! |
| 1078 | * removed! |
| 1079 | * |
| 1080 | * |
| 1081 | * removed! |
| 1082 | * removed! |
| 1083 | * removed! |
| 1084 | * |
| 1085 | * removed! |
| 1086 | * removed! |
| 1087 | * removed! |
| 1088 | * |
| 1089 | * removed! |
| 1090 | * removed! |
| 1091 | * removed! |
| 1092 | * |
| 1093 | * removed! |
| 1094 | * removed! |
| 1095 | * removed! |
| 1096 | * |
| 1097 | * removed! |
| 1098 | * removed! |
| 1099 | * |
| 1100 | * |
| 1101 | * removed! |
| 1102 | * removed! |
| 1103 | * removed! |
| 1104 | * |
| 1105 | * removed! |
| 1106 | * removed! |
| 1107 | * |
| 1108 | * |
| 1109 | * removed! |
| 1110 | * removed! |
| 1111 | * removed! |
| 1112 | * |
| 1113 | * removed! |
| 1114 | * removed! |
| 1115 | * removed! |
| 1116 | * |
| 1117 | * removed! |
| 1118 | * removed! |
| 1119 | * removed! |
| 1120 | * |
| 1121 | * removed! |
| 1122 | * removed! |
| 1123 | * |
| 1124 | * |
| 1125 | * removed! |
| 1126 | * removed! |
| 1127 | * removed! |
| 1128 | * |
| 1129 | * removed! |
| 1130 | * removed! |
| 1131 | * removed! |
| 1132 | * |
| 1133 | * removed! |
| 1134 | * removed! |
| 1135 | * removed! |
| 1136 | * |
| 1137 | * removed! |
| 1138 | * removed! |
| 1139 | * |
| 1140 | * |
| 1141 | *------------------------------------------------------------------------------ |
| 1142 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 1143 | *============================================================================ |
| 1144 | ****************************************************************************/ |
| 1145 | /* |
| 1146 | * Include |
| 1147 | */ |
| 1148 | #include <string.h> |
| 1149 | #include "nvram_msgid.h" |
| 1150 | |
| 1151 | #include "kal_general_types.h" |
| 1152 | #include "kal_internal_api.h" |
| 1153 | #include "kal_public_defs.h" |
| 1154 | #include "kal_public_api.h" |
| 1155 | #include "kal_trace.h" |
| 1156 | |
| 1157 | #include "syscomp_config.h" |
| 1158 | #include "task_config.h" |
| 1159 | #include "sysconf_statistics.h" /* stack_statistics_struct */ |
| 1160 | #include "custom_em.h" |
| 1161 | /* Factory mode, should not send ADC calibration data to BMT */ |
| 1162 | #ifdef __MULTI_BOOT__ |
| 1163 | #include "multiboot_config.h" |
| 1164 | #include "intrCtrl.h" /* INT_BootMode */ |
| 1165 | #endif /* __MULTI_BOOT__ */ |
| 1166 | |
| 1167 | #ifdef __CCCIFS_SUPPORT__ |
| 1168 | #include "ccci.h" |
| 1169 | #endif |
| 1170 | |
| 1171 | #if defined(__HIF_CCCI_SUPPORT__) |
| 1172 | #include "ccci_if.h" |
| 1173 | #endif |
| 1174 | |
| 1175 | #if defined(__MTK_TARGET__) |
| 1176 | #include "SST_secure.h" |
| 1177 | #endif |
| 1178 | |
| 1179 | #include "fs_type.h" /* FS_HANDLE */ |
| 1180 | #include "fs_func.h" /* FS_Delete */ |
| 1181 | #include "fs_errcode.h" /* FS_NO_ERROR */ |
| 1182 | #include "ex_item.h" /* EX_LOG_T */ |
| 1183 | |
| 1184 | #include "nvram_main.h" |
| 1185 | #include "nvram_interface.h" |
| 1186 | |
| 1187 | #include "nvram_msg_handler.h" |
| 1188 | |
| 1189 | #include "tst_msgid.h" |
| 1190 | #include "sbp_public_utility.h" |
| 1191 | #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__) |
| 1192 | #include "dcl_gpt.h" |
| 1193 | #endif |
| 1194 | |
| 1195 | #include "mcf_if.h" |
| 1196 | #include "mcf_enum.h" |
| 1197 | |
| 1198 | #ifdef __NVRAM_LID_CACHE__ |
| 1199 | #include "nvram_cache_interface.h" |
| 1200 | #endif |
| 1201 | #include "ex_public.h" |
| 1202 | |
| 1203 | /******************************************************* |
| 1204 | * External Function |
| 1205 | *******************************************************/ |
| 1206 | extern void MMISWChangeWarning( |
| 1207 | kal_uint8 type, |
| 1208 | kal_uint32 space, |
| 1209 | kal_uint8 const *codeversion, |
| 1210 | kal_uint8 const *diskversion); |
| 1211 | |
| 1212 | extern void MMICheckDiskDisplay(void); |
| 1213 | |
| 1214 | |
| 1215 | extern void *kal_tmp_mem_alloc(kal_uint32 size); |
| 1216 | extern void kal_tmp_mem_free(void *mem_ptr); |
| 1217 | extern kal_char *release_verno(void); |
| 1218 | extern kal_char *release_branch(void); |
| 1219 | extern kal_char *release_flavor(void); |
| 1220 | extern kal_char *build_date_time(void); |
| 1221 | extern kal_bool nvram_custom_lock_status(void); |
| 1222 | extern void custom_nvram_config(void); |
| 1223 | extern void custom_default_mode_config(void); |
| 1224 | extern kal_int32 nvram_recover_data_item(nvram_ltable_entry_struct *ldi); |
| 1225 | |
| 1226 | #ifdef __NVRAM_DEBUG_READ_DUMP__ |
| 1227 | extern void nvram_debug_log_dump(kal_bool valid, kal_char *log_str, kal_uint32 p1, kal_uint32 p2, kal_uint32 p3, kal_uint8 *buffer, kal_uint32 buffer_size); |
| 1228 | #else |
| 1229 | #define nvram_debug_log_dump(...) |
| 1230 | #endif |
| 1231 | #ifdef __TC01__ // ALPS0144925 |
| 1232 | extern nvram_ef_sbp_modem_config_struct cust_sbp_config; |
| 1233 | #endif |
| 1234 | #if defined (__NVRAM_UT_TEST__) |
| 1235 | extern kal_uint32 nvram_boot_trace; |
| 1236 | extern kal_uint8 is_clean_boot_test; |
| 1237 | #endif |
| 1238 | |
| 1239 | #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__) |
| 1240 | extern const checksum_reset_struct lid_structure_chksum[]; |
| 1241 | extern const checksum_reset_struct lid_default_value_chksum[]; |
| 1242 | #endif |
| 1243 | |
| 1244 | extern void nvram_sml_ota_converter(kal_uint8 *old_value_buffer, kal_uint32 ota_hdr_record_size, kal_uint8 *new_value_buffer, kal_uint32 new_record_size); |
| 1245 | /******************************************************* |
| 1246 | * Define |
| 1247 | *******************************************************/ |
| 1248 | #define OVERHEAD_CLUSTER 5 /* extra space in bytes needed for conflict resolution. ex, report files */ |
| 1249 | #define DISPLAY_WARNING_TIME 1000 /* 1000 ticks = 4.6 sec */ |
| 1250 | #define MAX_CHANGE_ARRAY_SIZE (nvram_ptr->ltable.total_LID + 1) |
| 1251 | |
| 1252 | #define NVRAM_SET_OTA_MARKED(LID) \ |
| 1253 | nvram_util_take_mutex(g_nvram_impt_mutex); \ |
| 1254 | nvram_util_lid_bimtap_set(LIDCheckedArray, LID); \ |
| 1255 | nvram_util_give_mutex(g_nvram_impt_mutex) |
| 1256 | |
| 1257 | #define NVRAM_CHK_OTA_MARKED(LID) nvram_util_lid_bitmap_check(LIDCheckedArray, LID) |
| 1258 | |
| 1259 | #if defined(__NVRAM_CREATE_FILE_ON_WRITE__) |
| 1260 | #define NVRAM_SET_CREATEED_FILE_INFO(LID) \ |
| 1261 | nvram_util_take_mutex(nvram_bitmap_mutex); \ |
| 1262 | nvram_util_lid_bimtap_set(nvram_bitmap_ptr, LID); \ |
| 1263 | nvram_util_give_mutex(nvram_bitmap_mutex) |
| 1264 | |
| 1265 | #define NVRAM_CHK_CREATEED_FILE_INFO(LID) nvram_util_lid_bitmap_check(nvram_bitmap_ptr, LID) |
| 1266 | #else |
| 1267 | #define NVRAM_SET_CREATEED_FILE_INFO(LID) |
| 1268 | #define NVRAM_CHK_CREATEED_FILE_INFO(LID) KAL_FALSE |
| 1269 | #endif |
| 1270 | |
| 1271 | #define CALIBRATE_FILE_MAX_CNT (1000) |
| 1272 | #define IMEI_FILE_MAX_CNT (64) |
| 1273 | #define FILE_LIST_ITEM_LENGTH (9) |
| 1274 | /******************************************************* |
| 1275 | * Typedef |
| 1276 | *******************************************************/ |
| 1277 | typedef struct |
| 1278 | { |
| 1279 | kal_bool checked; |
| 1280 | WCHAR diskfile[NVRAM_FILE_LEN + 1]; |
| 1281 | } diskTableEntry; |
| 1282 | |
| 1283 | /******************************************************* |
| 1284 | * Global Variable |
| 1285 | *******************************************************/ |
| 1286 | kal_mutexid g_nvram_impt_mutex = NULL; |
| 1287 | kal_mutexid g_nvram_fs_mutex = NULL; |
| 1288 | kal_mutexid g_nvram_trace_mutex = NULL; //this mutex is used to record nvram last read/write 10 times information |
| 1289 | //nvram external API may called by many users, so need this mutex |
| 1290 | kal_mutexid g_nvram_dump_trace_mutex = NULL;//this mutex is used to dump nvram trace to file |
| 1291 | kal_uint32 g_nvram_task_idx = 0xFFFFFFFF; |
| 1292 | ilm_struct *g_ilm_ptr = NULL; |
| 1293 | nvram_access_trace_information nvram_access_trace; |
| 1294 | #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__) |
| 1295 | DCL_HANDLE nvram_gpt_handle; |
| 1296 | #endif |
| 1297 | |
| 1298 | #ifdef __NVRAM_WRITE_WITH_FILE_SIZE__ |
| 1299 | kal_bool bResetNvramData = KAL_FALSE; |
| 1300 | #endif |
| 1301 | |
| 1302 | #ifdef __NVRAM_WRITE_PROTECT_ENABLE__ |
| 1303 | kal_bool isneedwriteprotect2 = KAL_FALSE; |
| 1304 | #endif |
| 1305 | |
| 1306 | nvram_context_type nvram_context; |
| 1307 | nvram_context_type *nvram_ptr = &nvram_context; |
| 1308 | #ifdef __NV_CHKSUM_ENHANCE__ |
| 1309 | extern nvram_algo_info *chksum_algo_ptr; |
| 1310 | #endif |
| 1311 | |
| 1312 | mcf_ota_result_e mcf_full_ota_status = MCF_OTA_R_MAX; |
| 1313 | |
| 1314 | nvram_ee_info_type* nvram_ee_info = NULL; |
| 1315 | kal_wchar nvram_trace_filename[NVRAM_MAX_PATH_LEN]; |
| 1316 | kal_char nvram_trace_dump_temp_buffer[NVRAM_DUMP_TRACE_TEMP_BUFFER_SIZE]; |
| 1317 | kal_char nvram_trace_dump_buffer[NVRAM_DUMP_TRACE_BUFFER_SIZE]; |
| 1318 | kal_uint32 nvram_trace_dump_buffer_offset = 0; |
| 1319 | FS_HANDLE nvram_trace_file_hdl = 0; |
| 1320 | |
| 1321 | /******************************************************* |
| 1322 | * Local Function |
| 1323 | *******************************************************/ |
| 1324 | |
| 1325 | static kal_bool nvram_init_all_ldi(nvram_reset_category_enum reset_category); |
| 1326 | static kal_bool nvram_supplementary_check(void); |
| 1327 | |
| 1328 | /******************************************************* |
| 1329 | * Local Variable |
| 1330 | *******************************************************/ |
| 1331 | static kal_uint32 BytesPerCluster; /* will be set to exact value in nvram_get_disk_file_info */ |
| 1332 | static kal_uint32 *nvram_init_tmp_pool; |
| 1333 | //static diskTableEntry *DiskTable; |
| 1334 | static kal_uint16 files_in_folder[NVRAM_FOLDER_TOTAL]; |
| 1335 | static kal_uint32 diskSize_of_folder[NVRAM_FOLDER_TOTAL]; |
| 1336 | |
| 1337 | static nvram_lid_enum *LIDResetArray = NULL; /* [count, lid1, lid2,..] ex. [3, 12, 29] */ |
| 1338 | static nvram_lid_enum LIDResetCnt = 0; |
| 1339 | static kal_uint32 LIDResetMax = 0; |
| 1340 | |
| 1341 | static kal_uint8 *LIDCheckedArray = NULL; |
| 1342 | #ifdef __NVRAM_CHECK_FILE_AND_RECOVER__ |
| 1343 | kal_uint8 *CALI_FileListBuf = NULL; |
| 1344 | kal_uint8 *IMEI_FileListBuf = NULL; |
| 1345 | kal_bool is_nvram_in_ota_flow = KAL_FALSE; |
| 1346 | kal_bool is_nvram_first_restore = KAL_TRUE; |
| 1347 | kal_bool Cali_filelist_found = KAL_FALSE; |
| 1348 | kal_bool Imei_filelist_found = KAL_FALSE; |
| 1349 | #endif |
| 1350 | kal_bool is_nvram_factory_reset = KAL_FALSE; |
| 1351 | |
| 1352 | /***************************************************************************** |
| 1353 | * FUNCTION |
| 1354 | * nvram_create |
| 1355 | * DESCRIPTION |
| 1356 | * NVRAM task create function |
| 1357 | * PARAMETERS |
| 1358 | * handle [IN] |
| 1359 | * RETURNS |
| 1360 | * success or fail |
| 1361 | *****************************************************************************/ |
| 1362 | kal_bool nvram_create(comptask_handler_struct **handle) |
| 1363 | { |
| 1364 | /*----------------------------------------------------------------*/ |
| 1365 | /* Local Variables */ |
| 1366 | /*----------------------------------------------------------------*/ |
| 1367 | static const comptask_handler_struct nvram_handler_info = |
| 1368 | { |
| 1369 | nvram_task_main, /* task entry function */ |
| 1370 | nvram_init, /* task initialization function */ |
| 1371 | nvram_reset /* task reset handler */ |
| 1372 | }; |
| 1373 | |
| 1374 | /*----------------------------------------------------------------*/ |
| 1375 | /* Code Body */ |
| 1376 | /*----------------------------------------------------------------*/ |
| 1377 | *handle = (comptask_handler_struct*) & nvram_handler_info; |
| 1378 | return KAL_TRUE; |
| 1379 | } |
| 1380 | |
| 1381 | |
| 1382 | /***************************************************************************** |
| 1383 | * FUNCTION |
| 1384 | * nvram_task_main |
| 1385 | * DESCRIPTION |
| 1386 | * NVRAM task |
| 1387 | * PARAMETERS |
| 1388 | * task_entry_ptr [?] |
| 1389 | * RETURNS |
| 1390 | * void |
| 1391 | *****************************************************************************/ |
| 1392 | |
| 1393 | #ifndef __MTK_TARGET__ |
| 1394 | #ifdef _MSC_VER |
| 1395 | nvram_read_callback_struct __pragma(data_seg("_nvram_callback_tbl_begin")) _nvram_callback_tbl_begin_p = {0}; |
| 1396 | |
| 1397 | #pragma comment(linker, "/MERGE:_nvram_callback_tbl_content=_nvram_callback_tbl_begin") |
| 1398 | |
| 1399 | nvram_read_callback_struct __pragma(data_seg("_nvram_callback_tbl_end")) _nvram_callback_tbl_end_p = {0}; |
| 1400 | |
| 1401 | #pragma comment(linker, "/MERGE:_nvram_callback_tbl_end=_nvram_callback_tbl_begin") |
| 1402 | #else |
| 1403 | // section merge is moved to linker script for other compilers |
| 1404 | __attribute__ ((section("_nvram_callback_tbl_begin"))) nvram_read_callback_struct _nvram_callback_tbl_begin_p = {0}; |
| 1405 | __attribute__ ((section("_nvram_callback_tbl_end"))) nvram_read_callback_struct _nvram_callback_tbl_end_p = {0}; |
| 1406 | #endif |
| 1407 | #endif |
| 1408 | |
| 1409 | void nvram_task_main(task_entry_struct *task_entry_ptr) |
| 1410 | { |
| 1411 | /*----------------------------------------------------------------*/ |
| 1412 | /* Local Variables */ |
| 1413 | /*----------------------------------------------------------------*/ |
| 1414 | ilm_struct current_ilm; |
| 1415 | kal_int32 cb_idx; |
| 1416 | nvram_read_callback_struct *cb_first_entry; |
| 1417 | |
| 1418 | #ifdef __MTK_TARGET__ |
| 1419 | extern kal_uint32 _nvram_callback_tbl$$Base, _nvram_callback_tbl$$Length; |
| 1420 | cb_idx = (kal_uint32)&_nvram_callback_tbl$$Length/sizeof(nvram_read_callback_struct); |
| 1421 | cb_first_entry = (nvram_read_callback_struct *)&_nvram_callback_tbl$$Base; |
| 1422 | |
| 1423 | |
| 1424 | #else |
| 1425 | |
| 1426 | cb_idx = (kal_uint32)(&_nvram_callback_tbl_end_p - &_nvram_callback_tbl_begin_p); |
| 1427 | cb_first_entry = (nvram_read_callback_struct *)&_nvram_callback_tbl_begin_p; |
| 1428 | |
| 1429 | #endif |
| 1430 | |
| 1431 | #if defined(__NVRAM_INIT_LID_BUFFER__) |
| 1432 | NVRAM_INIT_TIME_UT_STAMP(8); |
| 1433 | nvram_init_lid_buffer_writeback(); |
| 1434 | NVRAM_INIT_TIME_UT_STAMP(9); |
| 1435 | #endif |
| 1436 | // Write result to NVRAM_SYS_NVRAM_INIT_TIME_UT |
| 1437 | NVRAM_INIT_TIME_UT_SAVE(); |
| 1438 | |
| 1439 | /*----------------------------------------------------------------*/ |
| 1440 | /* Code Body */ |
| 1441 | /*----------------------------------------------------------------*/ |
| 1442 | |
| 1443 | while (1) |
| 1444 | { |
| 1445 | kal_int32 i = 0; |
| 1446 | /* nvram special service */ |
| 1447 | for (;i < cb_idx; i++) |
| 1448 | { |
| 1449 | nvram_read_callback_struct *entry = (nvram_read_callback_struct *)(cb_first_entry + i); |
| 1450 | if (!entry->processed) |
| 1451 | { |
| 1452 | kal_bool result = KAL_TRUE; |
| 1453 | if (entry->callback) |
| 1454 | { |
| 1455 | result = entry->callback(entry->user_data); |
| 1456 | entry->processed = KAL_TRUE; |
| 1457 | } |
| 1458 | |
| 1459 | if (result && entry->module != MOD_NIL && NVRAM_IS_LID_VALID(entry->file_id)) |
| 1460 | { |
| 1461 | { |
| 1462 | nvram_ltable_entry_struct *ldi; |
| 1463 | peer_buff_struct *peer_buf_ptr; |
| 1464 | kal_uint8 *pdu_ptr; |
| 1465 | kal_uint16 pdu_length; |
| 1466 | nvram_read_req_struct *local_data; |
| 1467 | nvram_util_get_data_item(&ldi, entry->file_id); |
| 1468 | |
| 1469 | local_data = (nvram_read_req_struct*) construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL); |
| 1470 | |
| 1471 | local_data->access_id = 0; |
| 1472 | local_data->file_idx = entry->file_id; |
| 1473 | local_data->para = 1; |
| 1474 | |
| 1475 | pdu_length = ldi->size; |
| 1476 | peer_buf_ptr = construct_peer_buff(pdu_length, 0, 0, TD_CTRL); |
| 1477 | |
| 1478 | pdu_ptr = get_peer_buff_pdu(peer_buf_ptr, &pdu_length); |
| 1479 | |
| 1480 | nvram_read_confirm( |
| 1481 | entry->module, |
| 1482 | nvram_read_data_item(ldi, 1, 1, pdu_ptr, pdu_length), /* multi-rec read support */ |
| 1483 | local_data, |
| 1484 | ldi->size, |
| 1485 | peer_buf_ptr); |
| 1486 | |
| 1487 | free_local_para((local_para_struct*) local_data); |
| 1488 | } |
| 1489 | |
| 1490 | entry->processed = KAL_TRUE; |
| 1491 | } |
| 1492 | |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | #if defined(__NVRAM_WRITE_PROTECT_ENABLE__) && defined(__NVRAM_IMPORTANT_PARTITIONS__) && defined(__CCCIFS_SUPPORT__) |
| 1497 | if (KAL_TRUE == isneedwriteprotect2) |
| 1498 | { |
| 1499 | ccci_send_message(CCMSG_ID_SYSMSGSVC_MD_UNPROTECT_PART_REQ, 0xCBA); |
| 1500 | isneedwriteprotect2 = KAL_FALSE; |
| 1501 | } |
| 1502 | #endif |
| 1503 | |
| 1504 | msg_receive_extq(¤t_ilm); |
| 1505 | kal_set_active_module_id(current_ilm.dest_mod_id); |
| 1506 | |
| 1507 | nvram_main(¤t_ilm); |
| 1508 | |
| 1509 | destroy_ilm(¤t_ilm); |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | |
| 1514 | /***************************************************************************** |
| 1515 | * FUNCTION |
| 1516 | * nvram_main |
| 1517 | * DESCRIPTION |
| 1518 | * This is main() function of NVRAM module. |
| 1519 | * PARAMETERS |
| 1520 | * ilm_ptr [IN] The primitives |
| 1521 | * RETURNS |
| 1522 | * void |
| 1523 | *****************************************************************************/ |
| 1524 | void nvram_main(ilm_struct *ilm_ptr) |
| 1525 | { |
| 1526 | /*----------------------------------------------------------------*/ |
| 1527 | /* Local Variables */ |
| 1528 | /*----------------------------------------------------------------*/ |
| 1529 | |
| 1530 | /*----------------------------------------------------------------*/ |
| 1531 | /* Code Body */ |
| 1532 | /*----------------------------------------------------------------*/ |
| 1533 | EXT_ASSERT(ilm_ptr != NULL,(kal_uint32)ilm_ptr, NVRAM_LOC_ILM_PTR_IS_NULL_1, 0); |
| 1534 | |
| 1535 | if (ilm_ptr != NULL) |
| 1536 | { |
| 1537 | if ((ilm_ptr->msg_id >= MSG_ID_NVRAM_CODE_BEGIN) && (ilm_ptr->msg_id <= MSG_ID_NVRAM_CODE_END)) |
| 1538 | { |
| 1539 | g_ilm_ptr = ilm_ptr; |
| 1540 | g_nvram_task_idx = kal_get_current_task_index(); |
| 1541 | if (ilm_ptr->msg_id == MSG_ID_NVRAM_STARTUP_REQ) |
| 1542 | { |
| 1543 | nvram_startup_handler(ilm_ptr); |
| 1544 | } |
| 1545 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_RESET_REQ) |
| 1546 | { |
| 1547 | nvram_reset_handler(ilm_ptr); |
| 1548 | } |
| 1549 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_READ_REQ) |
| 1550 | { |
| 1551 | nvram_read_handler(ilm_ptr); |
| 1552 | } |
| 1553 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_READ_DEFAULT_REQ) |
| 1554 | { |
| 1555 | nvram_read_default_handler(ilm_ptr); |
| 1556 | } |
| 1557 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_WRITE_REQ) |
| 1558 | { |
| 1559 | nvram_write_handler(ilm_ptr); |
| 1560 | } |
| 1561 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_WRITE_IMEI_REQ) |
| 1562 | { |
| 1563 | nvram_write_imei_handler(ilm_ptr); |
| 1564 | } |
| 1565 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_SET_LOCK_REQ) |
| 1566 | { |
| 1567 | nvram_set_lock_handler(ilm_ptr); |
| 1568 | } |
| 1569 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_CALLBACK_REQ) |
| 1570 | { |
| 1571 | /*when user call nvram_register_read_req() will send this message to NVRAM |
| 1572 | this is used to wakeup NVRAM task if NVRAM task is waiting for extq msg*/ |
| 1573 | return; |
| 1574 | } |
| 1575 | #if 0 |
| 1576 | /* under construction !*/ |
| 1577 | /* under construction !*/ |
| 1578 | /* under construction !*/ |
| 1579 | /* under construction !*/ |
| 1580 | /* under construction !*/ |
| 1581 | /* under construction !*/ |
| 1582 | /* under construction !*/ |
| 1583 | /* under construction !*/ |
| 1584 | #endif |
| 1585 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_SUSPEND_REQ) |
| 1586 | { |
| 1587 | nvram_suspend_handler(ilm_ptr); |
| 1588 | } |
| 1589 | #ifdef __NVRAM_BACKUP_DISK_RAW__ |
| 1590 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_CREATE_IMAGE_REQ) |
| 1591 | { |
| 1592 | nvram_create_image_handler(ilm_ptr); |
| 1593 | } |
| 1594 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_RECOVER_IMAGE_REQ) |
| 1595 | { |
| 1596 | nvram_recover_image_handler(ilm_ptr); |
| 1597 | } |
| 1598 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_VERIFY_IMAGE_REQ) |
| 1599 | { |
| 1600 | nvram_verify_image_handler(ilm_ptr); |
| 1601 | } |
| 1602 | #endif /* __SYSDRV_BACKUP_DISK_RAW__ */ |
| 1603 | #ifdef __NVRAM_SECURE_DATA_STORAGE__ |
| 1604 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_SDS_REQ) |
| 1605 | { |
| 1606 | nvram_sds_handler(ilm_ptr); |
| 1607 | } |
| 1608 | #endif |
| 1609 | #if defined(__CCCIFS_SUPPORT__) && defined(__MODEM_CARD__) // Hosted Dongle Data Card |
| 1610 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_BIN_REGION_REQ) |
| 1611 | { |
| 1612 | nvram_ap_bin_region_handler(ilm_ptr); |
| 1613 | } |
| 1614 | #endif |
| 1615 | #if defined(__NVRAM_MONITOR_ENABLED__) |
| 1616 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_REG_NOTIFY_REQ) |
| 1617 | { |
| 1618 | nvram_mon_reg_handler(ilm_ptr); |
| 1619 | } |
| 1620 | else if (ilm_ptr->msg_id == MSG_ID_NVRAM_DEREG_NOTIFY_REQ) |
| 1621 | { |
| 1622 | nvram_mon_dereg_handler(ilm_ptr); |
| 1623 | } |
| 1624 | #endif |
| 1625 | } |
| 1626 | #ifdef TST_HANDLER |
| 1627 | else |
| 1628 | { |
| 1629 | /* not nvram defined message */ |
| 1630 | if (ilm_ptr->msg_id == MSG_ID_TST_INJECT_STRING) |
| 1631 | { |
| 1632 | nvram_tst_handler(ilm_ptr); |
| 1633 | } |
| 1634 | } |
| 1635 | #endif /* TST_HANDLER */ |
| 1636 | |
| 1637 | } |
| 1638 | } /* end of module main function */ |
| 1639 | |
| 1640 | /***************************************************************************** |
| 1641 | * FUNCTION |
| 1642 | * nvram_report_reset_data_item |
| 1643 | * DESCRIPTION |
| 1644 | * |
| 1645 | * PARAMETERS |
| 1646 | * LID [IN] |
| 1647 | * RETURNS |
| 1648 | * void |
| 1649 | *****************************************************************************/ |
| 1650 | static void nvram_report_reset_data_item(nvram_lid_enum LID) |
| 1651 | { |
| 1652 | /*----------------------------------------------------------------*/ |
| 1653 | /* Local Variables */ |
| 1654 | /*----------------------------------------------------------------*/ |
| 1655 | |
| 1656 | /*----------------------------------------------------------------*/ |
| 1657 | /* Code Body */ |
| 1658 | /*----------------------------------------------------------------*/ |
| 1659 | LIDResetCnt++; |
| 1660 | EXT_ASSERT(LIDResetCnt < LIDResetMax,(kal_uint32)LIDResetCnt, NVRAM_LOC_INVALID_INDEX_2, LIDResetMax); |
| 1661 | |
| 1662 | LIDResetArray[0] = LIDResetCnt; /* Count */ |
| 1663 | LIDResetArray[LIDResetCnt] = LID; |
| 1664 | } |
| 1665 | |
| 1666 | |
| 1667 | /***************************************************************************** |
| 1668 | * FUNCTION |
| 1669 | * nvram_create_report_file |
| 1670 | * DESCRIPTION |
| 1671 | * |
| 1672 | * PARAMETERS |
| 1673 | * void |
| 1674 | * RETURNS |
| 1675 | * |
| 1676 | *****************************************************************************/ |
| 1677 | static kal_bool nvram_create_report_file() |
| 1678 | { |
| 1679 | /*----------------------------------------------------------------*/ |
| 1680 | /* Local Variables */ |
| 1681 | /*----------------------------------------------------------------*/ |
| 1682 | kal_wchar filename[NVRAM_MAX_PATH_LEN]; |
| 1683 | FS_HANDLE handle; |
| 1684 | kal_int32 result = FS_NO_ERROR; |
| 1685 | #if !defined(__CCCIFS_SUPPORT__) |
| 1686 | kal_uint32 filelen = (1 + LIDResetCnt) * sizeof(nvram_lid_enum); |
| 1687 | kal_uint32 written; |
| 1688 | #endif |
| 1689 | |
| 1690 | /*----------------------------------------------------------------*/ |
| 1691 | /* Code Body */ |
| 1692 | /*----------------------------------------------------------------*/ |
| 1693 | #if !defined(__CCCIFS_SUPPORT__) |
| 1694 | kal_wsprintf(filename, "%s", NVRAM_SWCHANGE_REPORT_FILE); |
| 1695 | NVRAM_FS_START_EX(FS_OP_DELETE,filename); |
| 1696 | result = FS_Delete(filename); |
| 1697 | NVRAM_FS_END(FS_OP_DELETE,result); |
| 1698 | NVRAM_FS_START_EX(FS_OP_OPEN,filename); |
| 1699 | handle = FS_Open(filename, FS_CREATE_ALWAYS | FS_READ_WRITE); |
| 1700 | NVRAM_FS_END(FS_OP_OPEN,handle); |
| 1701 | if (handle > FS_NO_ERROR) |
| 1702 | { |
| 1703 | NVRAM_FS_START(FS_OP_WRITE); |
| 1704 | result = FS_Write(handle, LIDResetArray, filelen, &written); |
| 1705 | NVRAM_FS_END(FS_OP_WRITE,result); |
| 1706 | if (result != FS_NO_ERROR) |
| 1707 | { |
| 1708 | NVRAM_FS_START(FS_OP_CLOSE); |
| 1709 | result = FS_Close(handle); |
| 1710 | NVRAM_FS_END(FS_OP_CLOSE,result); |
| 1711 | return KAL_FALSE; |
| 1712 | } |
| 1713 | } |
| 1714 | else |
| 1715 | { |
| 1716 | return KAL_FALSE; |
| 1717 | } |
| 1718 | NVRAM_FS_START(FS_OP_CLOSE); |
| 1719 | result = FS_Close(handle); |
| 1720 | NVRAM_FS_END(FS_OP_CLOSE,result); |
| 1721 | #endif |
| 1722 | |
| 1723 | kal_wsprintf(filename, "%s", NVRAM_SWCHANGE_REPORT_FILE_TXT); |
| 1724 | NVRAM_FS_START_EX(FS_OP_DELETE,filename); |
| 1725 | result = FS_Delete(filename); |
| 1726 | NVRAM_FS_END(FS_OP_DELETE,result); |
| 1727 | NVRAM_FS_START_EX(FS_OP_OPEN,filename); |
| 1728 | handle = FS_Open(filename, FS_CREATE_ALWAYS | FS_READ_WRITE); |
| 1729 | NVRAM_FS_END(FS_OP_OPEN,handle); |
| 1730 | if (handle > FS_NO_ERROR) |
| 1731 | { |
| 1732 | #if 1 |
| 1733 | // Write previous version and current version into SWCHANGE.TXT |
| 1734 | // Version string saved in coded_verion len is 18 bytes |
| 1735 | kal_char buf[128] = {0}; |
| 1736 | kal_uint32 len = 0; |
| 1737 | |
| 1738 | len = kal_snprintf(buf, 128, "OTA from %s to %s(%s), ", nvram_ptr->old_coded_version, nvram_ptr->coded_version, nvram_ptr->build_time); |
| 1739 | NVRAM_FS_START(FS_OP_WRITE); |
| 1740 | result = FS_Write(handle, buf, len, &len); |
| 1741 | NVRAM_FS_END(FS_OP_WRITE,result); |
| 1742 | NVRAM_FS_START(FS_OP_WRITE); |
| 1743 | len = kal_snprintf(buf, 64, "%s(%s)\n", release_branch(), release_flavor()); |
| 1744 | result = FS_Write(handle, buf, len, &len); |
| 1745 | NVRAM_FS_END(FS_OP_WRITE,result); |
| 1746 | #else |
| 1747 | /* under construction !*/ |
| 1748 | /* under construction !*/ |
| 1749 | /* under construction !*/ |
| 1750 | /* under construction !*/ |
| 1751 | /* under construction !*/ |
| 1752 | /* under construction !*/ |
| 1753 | /* under construction !*/ |
| 1754 | /* under construction !*/ |
| 1755 | /* under construction !*/ |
| 1756 | /* under construction !*/ |
| 1757 | /* under construction !*/ |
| 1758 | /* under construction !*/ |
| 1759 | /* under construction !*/ |
| 1760 | /* under construction !*/ |
| 1761 | /* under construction !*/ |
| 1762 | /* under construction !*/ |
| 1763 | /* under construction !*/ |
| 1764 | /* under construction !*/ |
| 1765 | /* under construction !*/ |
| 1766 | /* under construction !*/ |
| 1767 | /* under construction !*/ |
| 1768 | /* under construction !*/ |
| 1769 | /* under construction !*/ |
| 1770 | #endif |
| 1771 | } |
| 1772 | else |
| 1773 | { |
| 1774 | return KAL_FALSE; |
| 1775 | } |
| 1776 | NVRAM_FS_START(FS_OP_CLOSE); |
| 1777 | result = FS_Close(handle); |
| 1778 | NVRAM_FS_END(FS_OP_CLOSE,result); |
| 1779 | return KAL_TRUE; |
| 1780 | } |
| 1781 | |
| 1782 | /***************************************************************************** |
| 1783 | * FUNCTION |
| 1784 | * nvram_swchange_warning |
| 1785 | * DESCRIPTION |
| 1786 | * To warn the user there is no enough space to perform software change. |
| 1787 | * PARAMETERS |
| 1788 | * SpaceNedded [IN] |
| 1789 | * diskversion [IN] |
| 1790 | * RETURNS |
| 1791 | * void |
| 1792 | *****************************************************************************/ |
| 1793 | #if 0 |
| 1794 | /* under construction !*/ |
| 1795 | /* under construction !*/ |
| 1796 | /* under construction !*/ |
| 1797 | /* under construction !*/ |
| 1798 | /* under construction !*/ |
| 1799 | /* under construction !*/ |
| 1800 | /* under construction !*/ |
| 1801 | /* under construction !*/ |
| 1802 | /* under construction !*/ |
| 1803 | /* under construction !*/ |
| 1804 | #if (!defined(__L1_STANDALONE__) && !defined(EMPTY_MMI)) && !defined(EXTERNAL_MMI) |
| 1805 | /* under construction !*/ |
| 1806 | #endif |
| 1807 | /* under construction !*/ |
| 1808 | /* under construction !*/ |
| 1809 | /* under construction !*/ |
| 1810 | /* under construction !*/ |
| 1811 | /* under construction !*/ |
| 1812 | /* under construction !*/ |
| 1813 | /* under construction !*/ |
| 1814 | /* under construction !*/ |
| 1815 | /* under construction !*/ |
| 1816 | /* under construction !*/ |
| 1817 | /* under construction !*/ |
| 1818 | /* under construction !*/ |
| 1819 | /* under construction !*/ |
| 1820 | /* under construction !*/ |
| 1821 | #endif |
| 1822 | |
| 1823 | /***************************************************************************** |
| 1824 | * FUNCTION |
| 1825 | * nvram_get_disk_file_info |
| 1826 | * DESCRIPTION |
| 1827 | * To get infomation of NVRAM FS usage. |
| 1828 | * PARAMETERS |
| 1829 | * diskfilesize [OUT] Total existence file size |
| 1830 | * freespace [OUT] Free space of FS (in byte) |
| 1831 | * overhead [OUT] Overhead space (in byte) |
| 1832 | * RETURNS |
| 1833 | * Success or Fail |
| 1834 | *****************************************************************************/ |
| 1835 | kal_bool nvram_get_disk_file_info(kal_uint32 *diskfilesize, kal_uint32 *freespace, kal_uint32 *overhead) |
| 1836 | { |
| 1837 | /*----------------------------------------------------------------*/ |
| 1838 | /* Local Variables */ |
| 1839 | /*----------------------------------------------------------------*/ |
| 1840 | WCHAR DriveName[8]; |
| 1841 | FS_DiskInfo DI; |
| 1842 | kal_uint32 loop_idx; |
| 1843 | kal_int32 result = FS_NO_ERROR; |
| 1844 | /*----------------------------------------------------------------*/ |
| 1845 | /* Code Body */ |
| 1846 | /*----------------------------------------------------------------*/ |
| 1847 | kal_wsprintf(DriveName, "%s\0", "Z:\\"); |
| 1848 | NVRAM_FS_START_EX(FS_OP_GETDISKINFO,DriveName); |
| 1849 | result = FS_GetDiskInfo((const WCHAR*)DriveName, &DI, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE); |
| 1850 | NVRAM_FS_END(FS_OP_GETDISKINFO,result); |
| 1851 | if (result < FS_NO_ERROR) |
| 1852 | { |
| 1853 | return KAL_FALSE; |
| 1854 | } |
| 1855 | |
| 1856 | /* Set BytesPerCluster to the accurate value */ |
| 1857 | BytesPerCluster = DI.BytesPerSector * DI.SectorsPerCluster; |
| 1858 | |
| 1859 | *freespace = BytesPerCluster * DI.FreeClusters; |
| 1860 | |
| 1861 | for (*diskfilesize = 0, loop_idx = NVRAM_FOLDER_TOTAL; loop_idx > NVRAM_FOLDER_BEGIN; loop_idx--) |
| 1862 | { |
| 1863 | *diskfilesize += diskSize_of_folder[loop_idx - 1]; |
| 1864 | } |
| 1865 | |
| 1866 | *overhead = BytesPerCluster * OVERHEAD_CLUSTER; |
| 1867 | |
| 1868 | return KAL_TRUE; |
| 1869 | } |
| 1870 | |
| 1871 | #ifdef __NVRAM_DISK_SIZE_CHECK__ |
| 1872 | /***************************************************************************** |
| 1873 | * FUNCTION |
| 1874 | * nvram_get_code_file_size |
| 1875 | * DESCRIPTION |
| 1876 | * To get infomation of NVRAM RO usage. |
| 1877 | * PARAMETERS |
| 1878 | * CodeFileSizeTotal [OUT] Total RO size |
| 1879 | * RETURNS |
| 1880 | * void |
| 1881 | *****************************************************************************/ |
| 1882 | void nvram_get_code_file_size(kal_uint32 *CodeFileSizeTotal) |
| 1883 | { |
| 1884 | /*----------------------------------------------------------------*/ |
| 1885 | /* Local Variables */ |
| 1886 | /*----------------------------------------------------------------*/ |
| 1887 | nvram_ltable_entry_struct *ldi = &logical_data_item_table[0]; |
| 1888 | kal_uint32 onefilesize; |
| 1889 | kal_uint32 nvram_chksum_size = 0; |
| 1890 | nvram_lid_chksum_info lid_chksum_info = {0}; |
| 1891 | |
| 1892 | #ifdef __NVRAM_PSEUDO_MERGE__ |
| 1893 | kal_uint32 package_size = 0; |
| 1894 | kal_uint32 infolid_size = sizeof(head_info_struct); |
| 1895 | #endif |
| 1896 | |
| 1897 | /*----------------------------------------------------------------*/ |
| 1898 | /* Code Body */ |
| 1899 | /*----------------------------------------------------------------*/ |
| 1900 | *CodeFileSizeTotal = 2 * BytesPerCluster * (1 + (NVRAM_EF_SYS_SIZE - 1) / BytesPerCluster); |
| 1901 | |
| 1902 | do |
| 1903 | { |
| 1904 | |
| 1905 | nvram_get_lid_chksum_algo_info(ldi, &lid_chksum_info, KAL_FALSE, KAL_FALSE); |
| 1906 | nvram_chksum_size = lid_chksum_info.algo_info.chksum_algo_length; |
| 1907 | |
| 1908 | /* each record followed by a 2-byte checksum */ |
| 1909 | onefilesize = (ldi->size + nvram_chksum_size) * ldi->total_records; |
| 1910 | |
| 1911 | #ifdef __NVRAM_PSEUDO_MERGE__ |
| 1912 | if (NVRAM_IS_ATTR_PACKAGE(ldi->attr)) |
| 1913 | { |
| 1914 | package_size += onefilesize; |
| 1915 | infolid_size += sizeof(LID_info_struct); |
| 1916 | } |
| 1917 | else |
| 1918 | #endif |
| 1919 | if (NVRAM_IS_CATEGORY_OTP(ldi->category)) |
| 1920 | { |
| 1921 | continue; |
| 1922 | } |
| 1923 | else if (NVRAM_IS_ATTR_MULTIPLE(ldi->attr)) |
| 1924 | { |
| 1925 | *CodeFileSizeTotal += 2 * BytesPerCluster * (1 + (onefilesize - 1) / BytesPerCluster); |
| 1926 | } |
| 1927 | else |
| 1928 | { |
| 1929 | *CodeFileSizeTotal += BytesPerCluster * (1 + (onefilesize - 1) / BytesPerCluster); |
| 1930 | } |
| 1931 | }while(nvram_util_next_data_item(&ldi)); |
| 1932 | |
| 1933 | #ifdef __NVRAM_PSEUDO_MERGE__ |
| 1934 | if (package_size) |
| 1935 | { |
| 1936 | *CodeFileSizeTotal += BytesPerCluster * (1 + (package_size - 1) / BytesPerCluster); |
| 1937 | *CodeFileSizeTotal += BytesPerCluster * (1 + (infolid_size - 1) / BytesPerCluster); |
| 1938 | } |
| 1939 | #endif |
| 1940 | } |
| 1941 | |
| 1942 | |
| 1943 | /***************************************************************************** |
| 1944 | * FUNCTION |
| 1945 | * nvram_conflict_resolve_prelim |
| 1946 | * DESCRIPTION |
| 1947 | * To calc the disk size that software upgrade needs. |
| 1948 | * PARAMETERS |
| 1949 | * sysrecord [IN] Sysrecord |
| 1950 | * RETURNS |
| 1951 | * Success or Fail |
| 1952 | *****************************************************************************/ |
| 1953 | static kal_bool nvram_conflict_resolve_prelim(kal_uint8 *sysrecord) |
| 1954 | { |
| 1955 | /*----------------------------------------------------------------*/ |
| 1956 | /* Local Variables */ |
| 1957 | /*----------------------------------------------------------------*/ |
| 1958 | kal_uint32 diskfilesize, codefilesize, freespace, overhead; |
| 1959 | kal_int32 spaceDelta; |
| 1960 | |
| 1961 | /*----------------------------------------------------------------*/ |
| 1962 | /* Code Body */ |
| 1963 | /*----------------------------------------------------------------*/ |
| 1964 | if (!nvram_get_disk_file_info(&diskfilesize, &freespace, &overhead)) |
| 1965 | { |
| 1966 | return KAL_FALSE; |
| 1967 | } |
| 1968 | |
| 1969 | nvram_get_code_file_size(&codefilesize); |
| 1970 | |
| 1971 | spaceDelta = codefilesize + overhead - diskfilesize; |
| 1972 | |
| 1973 | if ((spaceDelta > 0) && (spaceDelta > (kal_int32)freespace)) |
| 1974 | { |
| 1975 | NVRAM_EXT_ASSERT(KAL_FALSE, 0, NVRAM_LOC_SPACE_NOT_ENOUGH_2, spaceDelta - freespace); |
| 1976 | } |
| 1977 | |
| 1978 | return KAL_TRUE; |
| 1979 | } |
| 1980 | #endif /* __NVRAM_DISK_SIZE_CHECK__ */ |
| 1981 | |
| 1982 | /***************************************************************************** |
| 1983 | * FUNCTION |
| 1984 | * nvram_destruct_certain_disk_table |
| 1985 | * DESCRIPTION |
| 1986 | * Free memory pool |
| 1987 | * PARAMETERS |
| 1988 | * ret [IN] |
| 1989 | * RETURNS |
| 1990 | * |
| 1991 | *****************************************************************************/ |
| 1992 | static kal_bool nvram_destruct_disk_table(void) |
| 1993 | { |
| 1994 | /*----------------------------------------------------------------*/ |
| 1995 | /* Local Variables */ |
| 1996 | /*----------------------------------------------------------------*/ |
| 1997 | |
| 1998 | /*----------------------------------------------------------------*/ |
| 1999 | /* Code Body */ |
| 2000 | /*----------------------------------------------------------------*/ |
| 2001 | if (nvram_init_tmp_pool) |
| 2002 | { |
| 2003 | //kal_tmp_mem_free(nvram_init_tmp_pool); |
| 2004 | //nvram_init_tmp_pool = NULL; |
| 2005 | free_ctrl_buffer_set_null(nvram_init_tmp_pool); |
| 2006 | #ifdef __NVRAM_CHECK_FILE_AND_RECOVER__ |
| 2007 | free_ctrl_buffer_set_null(CALI_FileListBuf); |
| 2008 | free_ctrl_buffer_set_null(IMEI_FileListBuf); |
| 2009 | #endif |
| 2010 | } |
| 2011 | |
| 2012 | return KAL_TRUE; |
| 2013 | } |
| 2014 | |
| 2015 | |
| 2016 | /***************************************************************************** |
| 2017 | * FUNCTION |
| 2018 | * nvram_malloc_disk_table |
| 2019 | * DESCRIPTION |
| 2020 | * Malloc and construct disk table |
| 2021 | * PARAMETERS |
| 2022 | * void |
| 2023 | * RETURNS |
| 2024 | * Success or Fail |
| 2025 | *****************************************************************************/ |
| 2026 | static kal_bool nvram_malloc_disk_table(void) |
| 2027 | { |
| 2028 | /*----------------------------------------------------------------*/ |
| 2029 | /* Local Variables */ |
| 2030 | /*----------------------------------------------------------------*/ |
| 2031 | kal_uint32 folder_idx; |
| 2032 | kal_uint32 size; |
| 2033 | |
| 2034 | #ifdef NVRAM_DISK_SIZE_CHECK |
| 2035 | kal_uint16 total_file = 0; |
| 2036 | kal_wchar namepattern[32]; |
| 2037 | kal_wchar nvramname[NVRAM_FILE_LEN + 1]; |
| 2038 | FS_DOSDirEntry fileinfo; |
| 2039 | FS_HANDLE handle; |
| 2040 | kal_int32 result = FS_NO_ERROR; |
| 2041 | #endif |
| 2042 | |
| 2043 | /*----------------------------------------------------------------*/ |
| 2044 | /* Code Body */ |
| 2045 | /*----------------------------------------------------------------*/ |
| 2046 | |
| 2047 | /* Step 1: Use FS_FindFist to parse the nvram folder to get the file number and file size */ |
| 2048 | |
| 2049 | for (folder_idx = NVRAM_FOLDER_BEGIN; folder_idx < NVRAM_FOLDER_TOTAL; folder_idx++) |
| 2050 | { |
| 2051 | files_in_folder[folder_idx] = 0; |
| 2052 | diskSize_of_folder[folder_idx] = 0; |
| 2053 | |
| 2054 | //skip scan OTA backup folder |
| 2055 | if((nvram_folder_enum)folder_idx == NVRAM_NVD_BACKUP) { |
| 2056 | continue; |
| 2057 | } |
| 2058 | |
| 2059 | #ifdef __NVRAM_DISK_SIZE_CHECK__ |
| 2060 | nvram_query_file_name((nvram_folder_enum)folder_idx, "*", namepattern); |
| 2061 | |
| 2062 | /* |
| 2063 | * 1: Collect disk file count |
| 2064 | * 2: Compute allocate DiskTable |
| 2065 | */ |
| 2066 | NVRAM_FS_START_EX(FS_OP_FINDFIRST,namepattern); |
| 2067 | handle = FS_FindFirst(namepattern, 0, FS_ATTR_DIR, &fileinfo, nvramname, sizeof(nvramname)); |
| 2068 | NVRAM_FS_END(FS_OP_FINDFIRST,handle); |
| 2069 | if (handle > 0) |
| 2070 | { |
| 2071 | do |
| 2072 | { |
| 2073 | files_in_folder[folder_idx]++; |
| 2074 | diskSize_of_folder[folder_idx] += BytesPerCluster * (1 + (fileinfo.FileSize - 1) / BytesPerCluster); |
| 2075 | NVRAM_FS_START(FS_OP_FINDNEXT); |
| 2076 | result = FS_FindNext(handle, &fileinfo, nvramname, sizeof(nvramname)); |
| 2077 | NVRAM_FS_END(FS_OP_FINDNEXT,result); |
| 2078 | } |
| 2079 | while (result == FS_NO_ERROR); |
| 2080 | NVRAM_FS_START(FS_OP_FINDCLOSE); |
| 2081 | result = FS_FindClose(handle); |
| 2082 | NVRAM_FS_END(FS_OP_FINDCLOSE,result); |
| 2083 | } |
| 2084 | else |
| 2085 | { |
| 2086 | files_in_folder[folder_idx] = 0; |
| 2087 | } |
| 2088 | |
| 2089 | total_file += files_in_folder[folder_idx]; |
| 2090 | #endif |
| 2091 | } |
| 2092 | |
| 2093 | /* Step 2: allocate enough memory */ |
| 2094 | /* Should revise this place some day. NVRAM should not use kal_tmp_mem_alloc |
| 2095 | And there is a hidden limitation of kal_tmp_mem_alloc. |
| 2096 | kal_tmp_mem_free must be used in pair with kal_tmp_mem_alloc without |
| 2097 | kal_tmp_mem_alloc/kal_sys_mem_alloc in between. |
| 2098 | Therefore, We need to invoke FS_GetDiskInfo in nvram_init one time to avoid this prolem. |
| 2099 | FS_GetDiskInfo -> RTFSYSALLocMutex() -> kal_create_sem -> kal_sys_mem_alloc */ |
| 2100 | |
| 2101 | //nvram_init_tmp_pool = (kal_uint32 *)kal_tmp_mem_alloc(sizeof(kal_uint32) * MAX_CHANGE_ARRAY_SIZE * 2 + |
| 2102 | // (kal_uint32)(total_file * sizeof(diskTableEntry))); |
| 2103 | |
| 2104 | LIDResetMax = MAX_CHANGE_ARRAY_SIZE; |
| 2105 | //nvram_init_tmp_pool = (kal_uint32 *)kal_tmp_mem_alloc((sizeof(nvram_lid_enum) * LIDResetMax) + nvram_ota_buffer_size()); |
| 2106 | size = ((sizeof(nvram_lid_enum) * LIDResetMax) + nvram_ota_buffer_size()); |
| 2107 | nvram_init_tmp_pool = (kal_uint32 *)get_ctrl_buffer(size); |
| 2108 | kal_mem_set(nvram_init_tmp_pool, 0, size); |
| 2109 | |
| 2110 | LIDResetArray = (nvram_lid_enum *)nvram_init_tmp_pool; |
| 2111 | LIDCheckedArray = ((kal_uint8*)LIDResetArray + (sizeof(nvram_lid_enum) * LIDResetMax)); |
| 2112 | #ifdef __NVRAM_CHECK_FILE_AND_RECOVER__ |
| 2113 | CALI_FileListBuf = (kal_uint8 *)get_ctrl_buffer(CALIBRATE_FILE_MAX_CNT*FILE_LIST_ITEM_LENGTH); |
| 2114 | kal_mem_set(CALI_FileListBuf, 0, CALIBRATE_FILE_MAX_CNT*FILE_LIST_ITEM_LENGTH); |
| 2115 | |
| 2116 | IMEI_FileListBuf = (kal_uint8 *)get_ctrl_buffer(IMEI_FILE_MAX_CNT*FILE_LIST_ITEM_LENGTH); |
| 2117 | kal_mem_set(IMEI_FileListBuf, 0, IMEI_FILE_MAX_CNT*FILE_LIST_ITEM_LENGTH); |
| 2118 | #endif |
| 2119 | LIDResetArray[0] = 0; /* Count */ |
| 2120 | LIDResetCnt = 0; |
| 2121 | |
| 2122 | return KAL_TRUE; |
| 2123 | } |
| 2124 | |
| 2125 | /***************************************************************************** |
| 2126 | * FUNCTION |
| 2127 | * nvram_filelost_precheck |
| 2128 | * DESCRIPTION |
| 2129 | * check if assert when found the NVRAM_EF_SML_LID/NVRAM_EF_SIM_LOCK_LID lost |
| 2130 | * PARAMETERS |
| 2131 | * LIDtoCheck [IN] Should be the assign record to check |
| 2132 | * default_value [IN] |
| 2133 | * RETURNS |
| 2134 | * void |
| 2135 | *****************************************************************************/ |
| 2136 | #if (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__)) |
| 2137 | static kal_bool nvram_filelost_precheck(nvram_lid_enum LIDtoCheck,kal_uint8 *default_item_value) |
| 2138 | { |
| 2139 | /*----------------------------------------------------------------*/ |
| 2140 | /* Local Variables */ |
| 2141 | /*----------------------------------------------------------------*/ |
| 2142 | nvram_ltable_entry_struct *ldi; |
| 2143 | kal_bool result = KAL_FALSE; |
| 2144 | |
| 2145 | kal_uint16 rec_id = 1;//NVRAM_EF_SYS_LID |
| 2146 | kal_uint8 *buffer; |
| 2147 | /*----------------------------------------------------------------*/ |
| 2148 | /* Code Body */ |
| 2149 | /*----------------------------------------------------------------*/ |
| 2150 | |
| 2151 | switch(LIDtoCheck) |
| 2152 | { |
| 2153 | case NVRAM_EF_SYS_LID: |
| 2154 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 2155 | rec_id = 1; |
| 2156 | break; |
| 2157 | case NVRAM_EF_BRANCH_VERNO_LID: |
| 2158 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 2159 | rec_id = 2; |
| 2160 | break; |
| 2161 | case NVRAM_EF_FLAVOR_VERNO_LID: |
| 2162 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 2163 | rec_id = 3; |
| 2164 | break; |
| 2165 | case NVRAM_EF_BUILD_TIME_LID: |
| 2166 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 2167 | rec_id = 4; |
| 2168 | break; |
| 2169 | default: |
| 2170 | nvram_util_get_data_item(&ldi, LIDtoCheck); |
| 2171 | break; |
| 2172 | } |
| 2173 | buffer = (kal_uint8*) get_ctrl_buffer(ldi->size); |
| 2174 | kal_mem_set(buffer, 0, ldi->size); |
| 2175 | if(nvram_read_data_item(ldi, rec_id, 1, buffer, ldi->size) == NVRAM_IO_ERRNO_OK) |
| 2176 | { |
| 2177 | if(NULL != strstr((const char *)buffer,(const char *)default_item_value)) |
| 2178 | { |
| 2179 | result = KAL_FALSE; |
| 2180 | } |
| 2181 | else |
| 2182 | { |
| 2183 | result = KAL_TRUE; |
| 2184 | } |
| 2185 | } |
| 2186 | else |
| 2187 | { |
| 2188 | result = KAL_FALSE; |
| 2189 | } |
| 2190 | free_ctrl_buffer(buffer); |
| 2191 | return result; |
| 2192 | } |
| 2193 | |
| 2194 | #endif |
| 2195 | |
| 2196 | #if defined(__CCCIFS_SUPPORT__) |
| 2197 | static kal_bool nvram_update_SML_info(nvram_ltable_entry_struct *ldi,kal_uint32 ota_hdr_record_size,kal_uint32 ota_hdr_ldi_attr) |
| 2198 | { |
| 2199 | kal_uint8 *old_value_buffer = NULL; |
| 2200 | kal_uint8 *new_value_buffer = NULL; |
| 2201 | kal_uint32 old_value_buffer_size = 0; |
| 2202 | kal_uint32 new_value_buffer_size = 0; |
| 2203 | kal_uint32 new_record_size = ldi->size; //backup the record size |
| 2204 | kal_uint32 new_ldi_attr = ldi->attr ; //backup the LID attribute |
| 2205 | nvram_errno_enum status; |
| 2206 | kal_uint8 *data = NULL; |
| 2207 | kal_uint32 i = 0; |
| 2208 | |
| 2209 | //Alloc the memory to save the old SML data |
| 2210 | old_value_buffer_size = ldi->total_records *ota_hdr_record_size; |
| 2211 | old_value_buffer = (kal_uint8 *)get_ctrl_buffer(old_value_buffer_size); |
| 2212 | if((ota_hdr_ldi_attr & NVRAM_ATTR_MSP) != (ldi->attr & NVRAM_ATTR_MSP)) |
| 2213 | { |
| 2214 | NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_ERROR_LOC_LID_ATTR_CHANGE_1,ota_hdr_ldi_attr); |
| 2215 | } |
| 2216 | if(old_value_buffer == NULL) |
| 2217 | { |
| 2218 | NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)old_value_buffer,NVRAM_LOC_BUFFER_PTR_IS_NULL_8,old_value_buffer_size); |
| 2219 | } |
| 2220 | kal_mem_set(old_value_buffer,0, old_value_buffer_size); |
| 2221 | |
| 2222 | //Alloc the memory to save the new SML data |
| 2223 | new_value_buffer_size = ldi->total_records *new_record_size; |
| 2224 | new_value_buffer = (kal_uint8 *)get_ctrl_buffer(new_value_buffer_size); |
| 2225 | if(new_value_buffer == NULL) |
| 2226 | { |
| 2227 | free_ctrl_buffer_set_null(old_value_buffer); |
| 2228 | NVRAM_EXT_ASSERT(KAL_FALSE,(kal_uint32)new_value_buffer,NVRAM_LOC_BUFFER_PTR_IS_NULL_9,new_value_buffer_size); |
| 2229 | } |
| 2230 | kal_mem_set(new_value_buffer,0, new_value_buffer_size); |
| 2231 | |
| 2232 | //Update the old record size to LID table |
| 2233 | ldi->size = ota_hdr_record_size; |
| 2234 | //Update the old LID attribute to LID table |
| 2235 | ldi->attr = ota_hdr_ldi_attr; |
| 2236 | |
| 2237 | //Read the old SML data from the storage |
| 2238 | status = nvram_read_data_item(ldi,1,ldi->total_records , old_value_buffer, old_value_buffer_size); |
| 2239 | if(status != NVRAM_IO_ERRNO_OK) |
| 2240 | { |
| 2241 | free_ctrl_buffer_set_null(old_value_buffer); |
| 2242 | free_ctrl_buffer_set_null(new_value_buffer); |
| 2243 | NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_LOC_READ_IMPORTANT_DATA_FAIL_2,0); |
| 2244 | return KAL_FALSE; |
| 2245 | } |
| 2246 | if(ldi->LID == NVRAM_EF_SML_LID) |
| 2247 | { |
| 2248 | //convert the old data to new data |
| 2249 | /* |
| 2250 | parameter description: |
| 2251 | - kal_uint8 *old_value_buffer: the source point of data buffer |
| 2252 | - kal_uint32 ota_hdr_record_size: old structure size |
| 2253 | - kal_uint8 *new_value_buffer: destination point of data buffer |
| 2254 | - kal_uint32 new_record_size: new structure size |
| 2255 | */ |
| 2256 | nvram_sml_ota_converter(old_value_buffer,ota_hdr_record_size,new_value_buffer,new_record_size); |
| 2257 | } |
| 2258 | else |
| 2259 | { |
| 2260 | kal_mem_cpy(new_value_buffer,old_value_buffer,ota_hdr_record_size); |
| 2261 | } |
| 2262 | nvram_util_mark_file_uncreated(ldi); |
| 2263 | //free the non-used buffer to avoid alloc new buffer fail |
| 2264 | free_ctrl_buffer_set_null(old_value_buffer); |
| 2265 | |
| 2266 | //Recover the record size and attribute |
| 2267 | ldi->size = new_record_size; |
| 2268 | ldi->attr = new_ldi_attr; |
| 2269 | |
| 2270 | //Reset SML LID |
| 2271 | if (!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records)) |
| 2272 | { |
| 2273 | free_ctrl_buffer_set_null(new_value_buffer); |
| 2274 | NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL_3,0); |
| 2275 | return KAL_FALSE; |
| 2276 | } |
| 2277 | |
| 2278 | //Update the New data to storage |
| 2279 | for(i = 1; i <= ldi->total_records; i++) |
| 2280 | { |
| 2281 | data = new_value_buffer + (i-1)*ldi->size; |
| 2282 | //write one record data per time |
| 2283 | status = nvram_write_data_item(ldi, i, data, KAL_FALSE); |
| 2284 | if(status != NVRAM_IO_ERRNO_OK) |
| 2285 | { |
| 2286 | free_ctrl_buffer_set_null(new_value_buffer); |
| 2287 | NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL_4,0); |
| 2288 | return KAL_FALSE; |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | free_ctrl_buffer_set_null(new_value_buffer); |
| 2293 | |
| 2294 | return KAL_TRUE; |
| 2295 | } |
| 2296 | #endif |
| 2297 | |
| 2298 | /***************************************************************************** |
| 2299 | * FUNCTION |
| 2300 | * nvram_file_lost_judgement |
| 2301 | * DESCRIPTION |
| 2302 | * deal with nvram file lost condition |
| 2303 | * PARAMETERS |
| 2304 | * LID [IN] |
| 2305 | * RETURNS |
| 2306 | * void |
| 2307 | *****************************************************************************/ |
| 2308 | static kal_bool nvram_file_lost_judgement(nvram_ltable_entry_struct *ldi, kal_bool trigger_assert) |
| 2309 | { |
| 2310 | #if (defined(__SMART_PHONE_MODEM__) || defined(__CCCIFS_SUPPORT__)) |
| 2311 | kal_char default_brach_verno[] = "LR12A.R1.MP"; |
| 2312 | switch(ldi->LID) { |
| 2313 | case NVRAM_EF_SML_LID: |
| 2314 | case NVRAM_EF_SIM_LOCK_LID: |
| 2315 | case NVRAM_EF_SML_GBLOB_LID: |
| 2316 | case NVRAM_EF_SML_GBLOB_KEY_LID: |
| 2317 | case NVRAM_EF_SML_S_LID: |
| 2318 | case NVRAM_EF_SUBSIDY_LOCK_LID: |
| 2319 | case NVRAM_EF_SUBSIDY_LOCK_ODM_DATA_LID: |
| 2320 | /* Do not allow file lost */ |
| 2321 | if(trigger_assert && nvram_filelost_precheck(NVRAM_EF_BRANCH_VERNO_LID,(kal_uint8*)default_brach_verno)) { |
| 2322 | NVRAM_EXT_ASSERT(KAL_FALSE, ldi->LID, NVRAM_LOC_READ_IMPORTANT_DATA_FAIL_1, -9); //FS_FILE_NOT_FOUND |
| 2323 | } |
| 2324 | return KAL_TRUE; |
| 2325 | default: |
| 2326 | break; |
| 2327 | }; |
| 2328 | #endif |
| 2329 | return KAL_FALSE; |
| 2330 | } |
| 2331 | |
| 2332 | /***************************************************************************** |
| 2333 | * FUNCTION |
| 2334 | * nvram_construct_certain_disk_table |
| 2335 | * DESCRIPTION |
| 2336 | * Construct the files in certain folder to disk table |
| 2337 | * PARAMETERS |
| 2338 | * folder_idx |
| 2339 | * RETURNS |
| 2340 | * Success or Fail |
| 2341 | *****************************************************************************/ |
| 2342 | static kal_bool nvram_construct_certain_disk_table(nvram_folder_enum folder_idx, kal_uint8 *rst_record_ptr) |
| 2343 | { |
| 2344 | /*----------------------------------------------------------------*/ |
| 2345 | /* Local Variables */ |
| 2346 | /*----------------------------------------------------------------*/ |
| 2347 | FS_HANDLE handle; |
| 2348 | FS_DOSDirEntry fileinfo; |
| 2349 | WCHAR namepattern[NVRAM_MAX_PATH_LEN]; |
| 2350 | WCHAR filename[NVRAM_FILE_LEN + 1]; |
| 2351 | char cfilename[NVRAM_FILE_LEN + 1]; |
| 2352 | char trace_filename[NVRAM_FILE_LEN + 1]; |
| 2353 | nvram_ldi_header nv_header; |
| 2354 | nvram_ltable_entry_struct *ldi = NULL; |
| 2355 | kal_bool hdr_ret = KAL_TRUE; |
| 2356 | #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__) |
| 2357 | chksum_rst_rec_struct *rst_rec_ptr = (chksum_rst_rec_struct *)rst_record_ptr; |
| 2358 | kal_int32 chksum_index; |
| 2359 | const char invalid_chksum[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}; |
| 2360 | #endif |
| 2361 | kal_int32 result = FS_NO_ERROR; |
| 2362 | /*----------------------------------------------------------------*/ |
| 2363 | /* Code Body */ |
| 2364 | /*----------------------------------------------------------------*/ |
| 2365 | kal_mem_set(&nv_header, 0x0, sizeof(nv_header)); |
| 2366 | nvram_query_file_name(folder_idx, "*", namepattern); |
| 2367 | NVRAM_FS_START_EX(FS_OP_FINDFIRST,namepattern); |
| 2368 | handle = FS_FindFirst(namepattern, 0, FS_ATTR_DIR, &fileinfo, filename, sizeof(filename)); |
| 2369 | NVRAM_FS_END(FS_OP_FINDFIRST,handle); |
| 2370 | if (handle > 0) |
| 2371 | { |
| 2372 | do |
| 2373 | { |
| 2374 | // Get file header |
| 2375 | nvram_query_file_name(folder_idx, "", namepattern); |
| 2376 | kal_wstrcat(namepattern, filename); |
| 2377 | kal_mem_set(&nv_header, 0x0, sizeof(nv_header)); |
| 2378 | hdr_ret = nvram_read_data_header(namepattern, LDI_HEADER_ALL_SECTION, (void*)&nv_header, NVRAM_LDI_HEADER_SIZE); |
| 2379 | if(!hdr_ret) { |
| 2380 | //read header fail, skip OTA this file |
| 2381 | NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[OTA]nvram_construct_certain_disk_table() ->nvram_read_data_header %s fail\r\n",cfilename); |
| 2382 | goto find_next_file; |
| 2383 | } |
| 2384 | |
| 2385 | // check in ltable |
| 2386 | kal_dchar2char(filename, cfilename); |
| 2387 | if(!nvram_util_get_data_item_by_fileprefix(&ldi, cfilename)) { |
| 2388 | if(NVRAM_IS_ATTR_RESERVE_BACKWARD(nv_header.nv_ota_header.ldi_attr)) { |
| 2389 | hdr_ret = nvram_ota_backup_file(namepattern, &(nv_header.nv_ota_header)); |
| 2390 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]backup file %s at %d\r\n",cfilename,__LINE__); |
| 2391 | } |
| 2392 | NVRAM_FS_START_EX(FS_OP_DELETE, namepattern); |
| 2393 | result = FS_Delete(namepattern); |
| 2394 | NVRAM_FS_END(FS_OP_DELETE,result); |
| 2395 | goto find_next_file; |
| 2396 | } |
| 2397 | |
| 2398 | // check file verno |
| 2399 | // check file category |
| 2400 | kal_dchar2char(&filename[NVRAM_FILE_LEN - FILE_VERNO_LEN], cfilename); |
| 2401 | kal_dchar2char(&filename[NVRAM_FILE_LEN - NVRAM_FILE_LEN], trace_filename); |
| 2402 | if((strcmp(ldi->fileverno, cfilename) == 0) && strcmp(nv_header.nv_ota_header.header,"LDI")){ |
| 2403 | nvram_prepare_data_header(ldi,(kal_uint8 *)(&nv_header)); |
| 2404 | nvram_write_data_header(ldi, LDI_HEADER_ALL_SECTION); |
| 2405 | } |
| 2406 | if(strcmp(ldi->fileverno, cfilename) || |
| 2407 | (ldi->category != nv_header.nv_ota_header.ldi_category) ) |
| 2408 | { |
| 2409 | if(NVRAM_IS_ATTR_RESERVE_BACKWARD(nv_header.nv_ota_header.ldi_attr)) { |
| 2410 | hdr_ret = nvram_ota_backup_file(namepattern, &(nv_header.nv_ota_header)); |
| 2411 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]backup file %s at %d\r\n",cfilename,__LINE__); |
| 2412 | } |
| 2413 | NVRAM_FS_START_EX(FS_OP_DELETE,namepattern); |
| 2414 | result = FS_Delete(namepattern); |
| 2415 | NVRAM_FS_END(FS_OP_DELETE,result); |
| 2416 | if(strcmp(ldi->fileverno, cfilename)) { |
| 2417 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]new VERNO %s mismatch ->VERNO:%s \r\n", ldi->fileverno, cfilename); |
| 2418 | } |
| 2419 | if(ldi->category != nv_header.nv_ota_header.ldi_category) { |
| 2420 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]new Category 0x%08X mismatch ->Category:0x%08X\r\n", (kal_uint32)ldi->category, (kal_uint32)nv_header.nv_ota_header.ldi_category); |
| 2421 | } |
| 2422 | goto find_next_file; |
| 2423 | } |
| 2424 | |
| 2425 | // check NVRAM_ATTR_OTA_RESET |
| 2426 | if(NVRAM_IS_ATTR_OTA_RESET(ldi->attr)) { |
| 2427 | nvram_report_reset_data_item(ldi->LID); |
| 2428 | NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan |
| 2429 | NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist |
| 2430 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Mark LID 0x%04X with OTA_RESET,attr 0x%08X,filename:%s\r\n",ldi->LID, (kal_uint32)ldi->attr,trace_filename); |
| 2431 | goto find_next_file; |
| 2432 | } |
| 2433 | |
| 2434 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[OTA]name%s->LID 0x%04x NVRAM_LOC_ATTRIBUITE_2:(0x%x), nv_hd_attr(0x%x)\r\n", cfilename, ldi->LID, ldi->attr, nv_header.nv_ota_header.ldi_attr); |
| 2435 | // check NVRAM checksum algorithm whether change |
| 2436 | #ifdef __NV_CHKSUM_ENHANCE__ |
| 2437 | if(NVRAM_IO_ERRNO_OK == nvram_ota_for_lid_chksum_algo(&nv_header, ldi)) |
| 2438 | { |
| 2439 | NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan |
| 2440 | NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist |
| 2441 | goto find_next_file; |
| 2442 | } |
| 2443 | #endif |
| 2444 | |
| 2445 | //for R1->R2 OTA NVRAM_EF_SIM_LOCK_LID LID attribute change |
| 2446 | #if defined(__CCCIFS_SUPPORT__) |
| 2447 | if((nv_header.nv_ota_header.ldi_attr != ldi->attr )&& (ldi->LID == NVRAM_EF_SIM_LOCK_LID)) |
| 2448 | { |
| 2449 | if((nv_header.nv_ota_header.ldi_attr & NVRAM_ATTR_MULTIPLE) != (ldi->attr & NVRAM_ATTR_MULTIPLE)) |
| 2450 | { |
| 2451 | hdr_ret = nvram_update_SML_info(ldi,nv_header.nv_ota_header.record_size,nv_header.nv_ota_header.ldi_attr); |
| 2452 | if(hdr_ret == KAL_FALSE) |
| 2453 | { |
| 2454 | NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL_5,0); |
| 2455 | } |
| 2456 | NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist |
| 2457 | NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan |
| 2458 | goto find_next_file; |
| 2459 | } |
| 2460 | } |
| 2461 | #endif |
| 2462 | // check record & size |
| 2463 | if((nv_header.nv_ota_header.record_size != ldi->size) || (nv_header.nv_ota_header.total_records!= ldi->total_records)) { |
| 2464 | /* |
| 2465 | #if defined (__NVRAM_UT_TEST__) |
| 2466 | if(NVRAM_IS_CATEGORY_CALIBRAT(ldi->category) || NVRAM_IS_CATEGORY_IMPORTANT(ldi->category) |
| 2467 | #if defined(__CCCIFS_SUPPORT__) |
| 2468 | || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) |
| 2469 | #endif |
| 2470 | ) |
| 2471 | { |
| 2472 | FS_FindClose(handle); |
| 2473 | } |
| 2474 | #endif |
| 2475 | */ |
| 2476 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]LID 0x%04X size changed:record size %d -> %d\r\n",ldi->LID,nv_header.nv_ota_header.record_size,ldi->size); |
| 2477 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]record number %d -> %d\r\n",nv_header.nv_ota_header.total_records,ldi->total_records); |
| 2478 | //Calibration data and Important data sensitive to size change |
| 2479 | NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_CALIBRAT(ldi->category), ldi->LID, NVRAM_LOC_CALIBRATION_SIZE_CHANGE, (nv_header.nv_ota_header.record_size * nv_header.nv_ota_header.total_records)); |
| 2480 | NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_IMPORTANT(ldi->category), ldi->LID, NVRAM_LOC_IMPORTANT_SIZE_CHANGE, (nv_header.nv_ota_header.record_size * nv_header.nv_ota_header.total_records)); |
| 2481 | #if defined(__CCCIFS_SUPPORT__) |
| 2482 | //for R1->R2 OTA SML Structure size change |
| 2483 | if(ldi->LID == NVRAM_EF_SML_LID && |
| 2484 | ((nv_header.nv_ota_header.record_size == 0x0104 && ldi->size == 0x00CC) ||(nv_header.nv_ota_header.record_size == 0x00CC && ldi->size == 0x0104))) |
| 2485 | { |
| 2486 | hdr_ret = nvram_update_SML_info(ldi,nv_header.nv_ota_header.record_size,nv_header.nv_ota_header.ldi_attr); |
| 2487 | if(hdr_ret == KAL_FALSE) |
| 2488 | { |
| 2489 | NVRAM_EXT_ASSERT(KAL_FALSE,ldi->LID,NVRAM_LOC_WRITE_IMPORTANT_DATA_FAIL_2,0); |
| 2490 | } |
| 2491 | NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist |
| 2492 | NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan |
| 2493 | goto find_next_file; |
| 2494 | } |
| 2495 | #if defined(__MTK_INTERNAL_ENG_USER__) |
| 2496 | NVRAM_EXT_ASSERT(!NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category), ldi->LID, NVRAM_LOC_INVALID_LID_SIZE_4, (nv_header.nv_ota_header.record_size * nv_header.nv_ota_header.total_records)); |
| 2497 | #else |
| 2498 | if(NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) && (ldi->attr & NVRAM_ATTR_FAULT_ASSERT)) |
| 2499 | { |
| 2500 | NVRAM_EXT_ASSERT(KAL_FALSE, ldi->LID, NVRAM_LOC_INVALID_LID_SIZE_4, (nv_header.nv_ota_header.record_size * nv_header.nv_ota_header.total_records)); |
| 2501 | } |
| 2502 | #endif |
| 2503 | #endif |
| 2504 | //Try to backup and restore LID |
| 2505 | if(NVRAM_IS_ATTR_RESERVE_BACKWARD(nv_header.nv_ota_header.ldi_attr)) { |
| 2506 | hdr_ret = nvram_ota_backup_file(namepattern, &(nv_header.nv_ota_header)); |
| 2507 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Size changed ->%s Backup at %d\r\n",trace_filename,__LINE__); |
| 2508 | if(!nvram_ota_restore_file(ldi)) { |
| 2509 | //bypass size change when OTA |
| 2510 | //nvram_report_reset_data_item(ldi->LID); |
| 2511 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Size changed ->%s Restore fail\r\n", trace_filename); |
| 2512 | } |
| 2513 | else { |
| 2514 | //file restore success |
| 2515 | NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist |
| 2516 | NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan |
| 2517 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Size changed ->%s Restore success\r\n", trace_filename); |
| 2518 | } |
| 2519 | } |
| 2520 | else { |
| 2521 | //bypass size change when OTA |
| 2522 | //nvram_report_reset_data_item(ldi->LID); |
| 2523 | NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist |
| 2524 | NVRAM_SET_OTA_MARKED(ldi->LID); //mark resolved, bypass 2nd scan |
| 2525 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Size changed ->%s Ignore\r\n", trace_filename); |
| 2526 | } |
| 2527 | goto find_next_file; |
| 2528 | } |
| 2529 | |
| 2530 | #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__) |
| 2531 | if(NVRAM_IS_CATEGORY_IMPORTANT_L1(ldi->category) || (NVRAM_NVD_DATA == nvram_query_folder_index(ldi->category))) |
| 2532 | { |
| 2533 | if(NVRAM_IS_ATTRIBUTE_CHANGE(nv_header, ldi)) |
| 2534 | { |
| 2535 | nvram_report_reset_data_item(ldi->LID); |
| 2536 | NVRAM_SET_OTA_MARKED(ldi->LID); |
| 2537 | goto find_next_file; |
| 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | if(NVRAM_STRUCTURE_CHKSUM_CHANGE_RESETABLE(ldi) || NVRAM_DEFVAL_CHKSUM_CHANGE_RESETABLE(ldi)) |
| 2542 | { |
| 2543 | if(! kal_mem_cmp((const char*)(nv_header.nv_dbg_header.struct_chkrst), (const char*)invalid_chksum, RST_CHKSUM_SIZE)) |
| 2544 | { |
| 2545 | nvram_write_data_header(ldi, LDI_HEADER_ALL_SECTION); |
| 2546 | NVRAM_SET_OTA_MARKED(ldi->LID); |
| 2547 | NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); |
| 2548 | goto find_next_file; |
| 2549 | } |
| 2550 | } |
| 2551 | #endif |
| 2552 | |
| 2553 | #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) |
| 2554 | if(NVRAM_STRUCTURE_CHKSUM_CHANGE_RESETABLE(ldi)) |
| 2555 | { |
| 2556 | chksum_index = nvram_get_structure_chksum_index(ldi->LID); |
| 2557 | if(-1 != chksum_index) |
| 2558 | { |
| 2559 | if(kal_mem_cmp((const char *)(nv_header.nv_dbg_header.struct_chkrst), (const char *)(lid_structure_chksum[chksum_index].chksum), RST_CHKSUM_SIZE)) |
| 2560 | { |
| 2561 | nvram_report_reset_data_item(ldi->LID); |
| 2562 | //record reset LID info |
| 2563 | if(rst_rec_ptr->structure_rst_index >= NVRAM_CHKSUM_RST_REC_NUM) |
| 2564 | rst_rec_ptr->structure_rst_index = 0; |
| 2565 | rst_rec_ptr->structure_rst[rst_rec_ptr->structure_rst_index].LID= ldi->LID; |
| 2566 | strncpy(rst_rec_ptr->structure_rst[rst_rec_ptr->structure_rst_index].fileprefix, ldi->fileprefix, FILE_PREFIX_LEN); |
| 2567 | NVRAM_SET_OTA_MARKED(ldi->LID); |
| 2568 | rst_rec_ptr->structure_rst_index = (rst_rec_ptr->structure_rst_index+1)%NVRAM_CHKSUM_RST_REC_NUM; |
| 2569 | goto find_next_file; |
| 2570 | } |
| 2571 | } |
| 2572 | else |
| 2573 | { |
| 2574 | if(rst_rec_ptr->structure_chksum_nofound_index >= NVRAM_CHKSUM_RST_REC_NUM) |
| 2575 | rst_rec_ptr->structure_chksum_nofound_index = 0; |
| 2576 | rst_rec_ptr->structure_chksum_nofound[rst_rec_ptr->structure_chksum_nofound_index].LID = ldi->LID; |
| 2577 | strncpy(rst_rec_ptr->structure_chksum_nofound[rst_rec_ptr->structure_chksum_nofound_index].fileprefix, ldi->fileprefix, FILE_PREFIX_LEN); |
| 2578 | rst_rec_ptr->structure_chksum_nofound_index = (rst_rec_ptr->structure_chksum_nofound_index+1)%NVRAM_CHKSUM_RST_REC_NUM; |
| 2579 | } |
| 2580 | } |
| 2581 | #endif |
| 2582 | |
| 2583 | #if defined(__NVRAM_DEFVAL_CHANGE_RESET__) |
| 2584 | if(NVRAM_DEFVAL_CHKSUM_CHANGE_RESETABLE(ldi)) |
| 2585 | { |
| 2586 | chksum_index = nvram_get_defval_chksum_index(ldi->LID); |
| 2587 | if(-1 != chksum_index) |
| 2588 | { |
| 2589 | if(kal_mem_cmp((const char *)(nv_header.nv_ota_header.defval_chkrst_h), (const char *)(lid_default_value_chksum[chksum_index].chksum), RST_CHKSUM_SIZE-6) || |
| 2590 | kal_mem_cmp((const char *)(nv_header.nv_dbg_header.defval_chkrst_l), (const char*)(&(lid_default_value_chksum[chksum_index].chksum[RST_CHKSUM_SIZE-6])), 6)) |
| 2591 | { |
| 2592 | nvram_report_reset_data_item(ldi->LID); |
| 2593 | //record reset LID info |
| 2594 | if(rst_rec_ptr->defval_rst_index >= NVRAM_CHKSUM_RST_REC_NUM) |
| 2595 | rst_rec_ptr->defval_rst_index = 0; |
| 2596 | rst_rec_ptr->defval_rst[rst_rec_ptr->defval_rst_index].LID = ldi->LID; |
| 2597 | strncpy(rst_rec_ptr->defval_rst[rst_rec_ptr->defval_rst_index].fileprefix, ldi->fileprefix, FILE_PREFIX_LEN); |
| 2598 | NVRAM_SET_OTA_MARKED(ldi->LID); |
| 2599 | rst_rec_ptr->defval_rst_index = (rst_rec_ptr->defval_rst_index+1)%NVRAM_CHKSUM_RST_REC_NUM; |
| 2600 | goto find_next_file; |
| 2601 | } |
| 2602 | } |
| 2603 | else |
| 2604 | { |
| 2605 | if(rst_rec_ptr->defval_chksum_nofound_index >= NVRAM_CHKSUM_RST_REC_NUM) |
| 2606 | rst_rec_ptr->defval_chksum_nofound_index = 0; |
| 2607 | rst_rec_ptr->defval_chksum_nofound[rst_rec_ptr->defval_chksum_nofound_index].LID = ldi->LID; |
| 2608 | strncpy(rst_rec_ptr->defval_chksum_nofound[rst_rec_ptr->defval_chksum_nofound_index].fileprefix, ldi->fileprefix, FILE_PREFIX_LEN); |
| 2609 | rst_rec_ptr->defval_chksum_nofound_index = (rst_rec_ptr->defval_chksum_nofound_index+1)%NVRAM_CHKSUM_RST_REC_NUM; |
| 2610 | } |
| 2611 | } |
| 2612 | #endif |
| 2613 | |
| 2614 | //mark resolved, bypass 2nd scan |
| 2615 | NVRAM_SET_OTA_MARKED(ldi->LID); |
| 2616 | // file match ldi, record to bitmap |
| 2617 | NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist |
| 2618 | find_next_file: |
| 2619 | NVRAM_FS_START(FS_OP_FINDNEXT); |
| 2620 | result = FS_FindNext(handle, &fileinfo, filename, sizeof(filename)); |
| 2621 | NVRAM_FS_END(FS_OP_FINDNEXT,result); |
| 2622 | } |
| 2623 | while (result == FS_NO_ERROR); |
| 2624 | } |
| 2625 | #ifdef __NVRAM_DISK_SIZE_CHECK__ |
| 2626 | else |
| 2627 | { |
| 2628 | if (files_in_folder[folder_idx] != 0) |
| 2629 | { |
| 2630 | return KAL_FALSE; |
| 2631 | } |
| 2632 | else |
| 2633 | { |
| 2634 | return KAL_TRUE; |
| 2635 | } |
| 2636 | } |
| 2637 | #endif |
| 2638 | NVRAM_FS_START(FS_OP_FINDCLOSE); |
| 2639 | result = FS_FindClose(handle); |
| 2640 | NVRAM_FS_END(FS_OP_FINDCLOSE,result); |
| 2641 | |
| 2642 | |
| 2643 | return KAL_TRUE; |
| 2644 | } |
| 2645 | |
| 2646 | /***************************************************************************** |
| 2647 | * FUNCTION |
| 2648 | * nvram_construct_disk_table |
| 2649 | * DESCRIPTION |
| 2650 | * |
| 2651 | * PARAMETERS |
| 2652 | * void |
| 2653 | * RETURNS |
| 2654 | * |
| 2655 | *****************************************************************************/ |
| 2656 | static kal_bool nvram_construct_disk_table(void) |
| 2657 | { |
| 2658 | /*----------------------------------------------------------------*/ |
| 2659 | /* Local Variables */ |
| 2660 | /*----------------------------------------------------------------*/ |
| 2661 | kal_uint32 loop_idx; |
| 2662 | kal_uint8* rst_rec_ptr; |
| 2663 | kal_bool ret; |
| 2664 | #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__) |
| 2665 | nvram_ltable_entry_struct *ldi; |
| 2666 | #endif |
| 2667 | /*----------------------------------------------------------------*/ |
| 2668 | /* Code Body */ |
| 2669 | /*----------------------------------------------------------------*/ |
| 2670 | |
| 2671 | if (!nvram_malloc_disk_table()) |
| 2672 | { |
| 2673 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[OTA][Error]%s fail\r\n", __FUNCTION__); |
| 2674 | return KAL_FALSE; |
| 2675 | } |
| 2676 | rst_rec_ptr = (kal_uint8*) get_ctrl_buffer(NVRAM_EF_CHKSUM_RESET_REC_SIZE); |
| 2677 | kal_mem_set(rst_rec_ptr, 0x0, NVRAM_EF_CHKSUM_RESET_REC_SIZE); |
| 2678 | |
| 2679 | for (loop_idx = NVRAM_FOLDER_TOTAL; loop_idx > NVRAM_FOLDER_BEGIN ; loop_idx--) |
| 2680 | { |
| 2681 | //skip scan OTA backup folder |
| 2682 | if((nvram_folder_enum)(loop_idx - 1) == NVRAM_NVD_BACKUP) { |
| 2683 | continue; |
| 2684 | } |
| 2685 | |
| 2686 | ret = nvram_construct_certain_disk_table((nvram_folder_enum)(loop_idx - 1), rst_rec_ptr); |
| 2687 | |
| 2688 | if (!ret) |
| 2689 | { |
| 2690 | nvram_destruct_disk_table(); |
| 2691 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[OTA][Error]nvram_construct_certain_disk_table() fail ret= %d", (kal_uint32)ret); |
| 2692 | free_ctrl_buffer(rst_rec_ptr); |
| 2693 | return KAL_FALSE; |
| 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | #if defined(__NVRAM_STRUCTURE_CHANGE_RESET__) || defined(__NVRAM_DEFVAL_CHANGE_RESET__) |
| 2698 | nvram_util_get_data_item(&ldi, NVRAM_EF_CHKSUM_RESET_REC_LID); |
| 2699 | nvram_write_data_item(ldi, 1, rst_rec_ptr, KAL_FALSE); |
| 2700 | #endif |
| 2701 | free_ctrl_buffer(rst_rec_ptr); |
| 2702 | |
| 2703 | return KAL_TRUE; |
| 2704 | } |
| 2705 | |
| 2706 | |
| 2707 | /***************************************************************************** |
| 2708 | * FUNCTION |
| 2709 | * nvram_version_conflict_resolve |
| 2710 | * DESCRIPTION |
| 2711 | * To perform software upgrade. |
| 2712 | * PARAMETERS |
| 2713 | * sysrecord [IN] Sysrecord |
| 2714 | * RETURNS |
| 2715 | * Success or Fail |
| 2716 | *****************************************************************************/ |
| 2717 | static kal_bool nvram_version_conflict_resolve(kal_uint8 *sysrecord) |
| 2718 | { |
| 2719 | /*----------------------------------------------------------------*/ |
| 2720 | /* Local Variables */ |
| 2721 | /*----------------------------------------------------------------*/ |
| 2722 | nvram_ltable_entry_struct *ldi; |
| 2723 | kal_uint32 file_idx; |
| 2724 | kal_uint32 index; |
| 2725 | |
| 2726 | /*----------------------------------------------------------------*/ |
| 2727 | /* Code Body */ |
| 2728 | /*----------------------------------------------------------------*/ |
| 2729 | /***************************************************** |
| 2730 | * Launch power first and show the first picture |
| 2731 | ******************************************************/ |
| 2732 | nvram_util_poweron(); |
| 2733 | #if !defined(__L1_STANDALONE__) && !defined(EMPTY_MMI) && !defined(EXTERNAL_MMI) |
| 2734 | MMICheckDiskDisplay(); |
| 2735 | #endif |
| 2736 | |
| 2737 | #if defined(__NVRAM_CREATE_FILE_ON_WRITE__) |
| 2738 | nvram_util_take_mutex(nvram_bitmap_mutex); |
| 2739 | nvram_utile_reset_lid_bitmap(); |
| 2740 | nvram_util_give_mutex(nvram_bitmap_mutex); |
| 2741 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->nvram_utile_reset_lid_bitmap()\r\n\r\n\r\n",__FUNCTION__); |
| 2742 | #endif |
| 2743 | /*********************************************************************/ |
| 2744 | /****** 1st phase for loop starts here. The looping is based on the Exist File ******/ |
| 2745 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage1 Start\r\n",__FUNCTION__); |
| 2746 | if (!nvram_construct_disk_table()) |
| 2747 | { |
| 2748 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]][OTA]%s->nvram_construct_disk_table() fail\r\n",__FUNCTION__); |
| 2749 | return KAL_FALSE; |
| 2750 | } |
| 2751 | if(nvram_ee_info != NULL){ |
| 2752 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_VERSION_CONFLICT_RESOLVE_STAGE1; |
| 2753 | nvram_ee_info->nvram_init_time[9] = kal_get_systicks(); |
| 2754 | } |
| 2755 | /****** 1st phase for loop ends here ******/ |
| 2756 | /*===========================*/ |
| 2757 | |
| 2758 | #ifdef __NVRAM_DISK_SIZE_CHECK__ |
| 2759 | if (!nvram_conflict_resolve_prelim(sysrecord)) |
| 2760 | { |
| 2761 | return nvram_destruct_disk_table(); |
| 2762 | } |
| 2763 | #endif |
| 2764 | |
| 2765 | MD_TRC_FUNC_NVRAM_VERSION_CONFLICT_RESOLVE(0); |
| 2766 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage1 End\r\n\r\n\r\n",__FUNCTION__); |
| 2767 | /***********************************************************************/ |
| 2768 | /****** 2nd phase for loop starts here. The looping is based on the Code table ******/ |
| 2769 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage2 Start\r\n",__FUNCTION__); |
| 2770 | ldi = &logical_data_item_table[0]; |
| 2771 | do |
| 2772 | { |
| 2773 | /* skip pre-resolve marked lid */ |
| 2774 | if(NVRAM_CHK_CREATEED_FILE_INFO(ldi->LID)) { //bypass exist file |
| 2775 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Skip Pre-resolved LID 0x%04X\r\n",__FUNCTION__,ldi->LID); |
| 2776 | continue; |
| 2777 | } |
| 2778 | /* skip special lid */ |
| 2779 | if(ldi->LID == NVRAM_EF_READ_RESERVED_LID) { |
| 2780 | continue; |
| 2781 | } |
| 2782 | |
| 2783 | /* those data items need to be reset to code default values */ |
| 2784 | if (ldi->attr & NVRAM_ATTR_OTA_RESET) |
| 2785 | { |
| 2786 | nvram_report_reset_data_item(ldi->LID); |
| 2787 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]LID 0x%04X with OTA_RESET->Mark Reset in Stage2\r\n",ldi->LID); |
| 2788 | } |
| 2789 | else |
| 2790 | { |
| 2791 | #ifdef __NVRAM_PSEUDO_MERGE__ |
| 2792 | if (NVRAM_IS_ATTR_PACKAGE(ldi->attr)) |
| 2793 | { |
| 2794 | continue; /* this function will not deal with package lid */ |
| 2795 | } |
| 2796 | else |
| 2797 | #endif |
| 2798 | //bypass 1st phase marked file |
| 2799 | if(NVRAM_CHK_OTA_MARKED(ldi->LID)) { |
| 2800 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Bypass LID 0x%04X marked in Stage1\r\n",ldi->LID); |
| 2801 | continue; |
| 2802 | } |
| 2803 | nvram_file_lost_judgement(ldi, KAL_TRUE); |
| 2804 | // try restore from bin region |
| 2805 | #if (defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__)) || defined(__NVRAM_BIN_REGION_SIMULATION__) |
| 2806 | if (NVRAM_IS_CATEGORY_IN_BIN_REGION(ldi->category)) { |
| 2807 | if (nvram_recover_data_item(ldi) == NVRAM_IO_ERRNO_OK) { |
| 2808 | NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist |
| 2809 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]LID 0x%04X ->nvram_recover_data_item()Success\r\n",ldi->LID); |
| 2810 | continue; |
| 2811 | } |
| 2812 | else { |
| 2813 | NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[OTA]LID 0x%04X ->nvram_recover_data_item() Fail\r\n",ldi->LID); |
| 2814 | } |
| 2815 | } |
| 2816 | #endif |
| 2817 | // try restore from reserved folder |
| 2818 | if(NVRAM_IS_ATTR_RESERVE_BACKWARD(ldi->attr)) { |
| 2819 | if(nvram_ota_restore_file(ldi)) { |
| 2820 | //file restore success |
| 2821 | NVRAM_SET_CREATEED_FILE_INFO(ldi->LID); //mark file exist |
| 2822 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]LID 0x%04X ->nvram_ota_restore_file() Success\r\n",ldi->LID); |
| 2823 | continue; |
| 2824 | } |
| 2825 | else { |
| 2826 | NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[OTA]LID 0x%04X ->nvram_ota_restore_file() Fail\r\n",ldi->LID); |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | nvram_report_reset_data_item(ldi->LID); |
| 2831 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]LID 0x%04X ->Mark Reset in Stage2\r\n",ldi->LID); |
| 2832 | } |
| 2833 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->nvram_util_next_data_item \r\n",__FUNCTION__); |
| 2834 | }while(nvram_util_next_data_item(&ldi)); |
| 2835 | |
| 2836 | #if defined(__NVRAM_CREATE_FILE_ON_WRITE__) |
| 2837 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->take nvram_bitmap_mutex\r\n",__FUNCTION__); |
| 2838 | nvram_util_take_mutex(nvram_bitmap_mutex); |
| 2839 | nvram_delete_bitmap_file(); |
| 2840 | nvram_write_bitmap_into_file(); |
| 2841 | nvram_util_give_mutex(nvram_bitmap_mutex); |
| 2842 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->give nvram_bitmap_mutex\r\n",__FUNCTION__); |
| 2843 | #endif |
| 2844 | if(nvram_ee_info != NULL){ |
| 2845 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_VERSION_CONFLICT_RESOLVE_STAGE2; |
| 2846 | nvram_ee_info->nvram_init_time[10] = kal_get_systicks(); |
| 2847 | } |
| 2848 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage2 End\r\n\r\n\r\n",__FUNCTION__); |
| 2849 | MD_TRC_FUNC_NVRAM_VERSION_CONFLICT_RESOLVE(1); |
| 2850 | /****** 2nd phase for loop ends here ******/ |
| 2851 | /*===========================*/ |
| 2852 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage3 Start\r\n",__FUNCTION__); |
| 2853 | nvram_create_report_file(); |
| 2854 | |
| 2855 | /*************************************************************************/ |
| 2856 | /******** 3rd phase for loop starts here. The looping is based on LIDResetCnt ********/ |
| 2857 | for (index = 1; index <= LIDResetCnt; index++) |
| 2858 | { |
| 2859 | file_idx = LIDResetArray[index]; |
| 2860 | |
| 2861 | nvram_util_get_data_item(&ldi, file_idx); |
| 2862 | |
| 2863 | if (!ldi) |
| 2864 | { |
| 2865 | continue; |
| 2866 | } |
| 2867 | #ifdef __NVRAM_BACKUP_DISK__ |
| 2868 | if (NVRAM_IS_ATTR_BACKUP_FAT(ldi->attr) || NVRAM_IS_ATTR_BACKUP_RAW(ldi->attr)) |
| 2869 | { |
| 2870 | if (nvram_recover_image_by_lid(ldi) == NVRAM_ERRNO_SUCCESS) |
| 2871 | { |
| 2872 | continue; |
| 2873 | } |
| 2874 | } |
| 2875 | #endif |
| 2876 | |
| 2877 | if (!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records)) |
| 2878 | { |
| 2879 | NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[OTA]%s-> nvram_reset_data_items() Fail \r\n",__FUNCTION__); |
| 2880 | return nvram_destruct_disk_table(); |
| 2881 | } |
| 2882 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s-> nvram_reset_data_items() Success \r\n",__FUNCTION__); |
| 2883 | } |
| 2884 | /****** 3rd phase for loop ends here ******/ |
| 2885 | /*===========================*/ |
| 2886 | if(nvram_ee_info != NULL){ |
| 2887 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_VERSION_CONFLICT_RESOLVE_STAGE3; |
| 2888 | nvram_ee_info->nvram_init_time[11] = kal_get_systicks(); |
| 2889 | } |
| 2890 | MD_TRC_FUNC_NVRAM_VERSION_CONFLICT_RESOLVE(3); |
| 2891 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]%s->Stage3 End\r\n\r\n\r\n",__FUNCTION__); |
| 2892 | |
| 2893 | /****** rewrite system records ******/ |
| 2894 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 2895 | if (!nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records)) |
| 2896 | { |
| 2897 | NVRAM_DEBUG_DUMP(NVRAM_WARNING_DUMP,"[OTA]%s-> Reset NVRAM_EF_SYS_LID Fail\r\n",__FUNCTION__); |
| 2898 | return nvram_destruct_disk_table(); |
| 2899 | } |
| 2900 | if(nvram_ee_info != NULL){ |
| 2901 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_RESET_SYS_LID_FILE_DONE; |
| 2902 | } |
| 2903 | nvram_util_get_data_item(&ldi, NVRAM_EF_CORE_FACTORY_RESET_AND_OTA_LID); |
| 2904 | nvram_write_data_item(ldi, 1, nvram_ptr->build_time, KAL_TRUE); |
| 2905 | if(nvram_ee_info != NULL){ |
| 2906 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_UPDATE_BUILD_TIME_FILE_DONE; |
| 2907 | } |
| 2908 | |
| 2909 | #ifdef __NV_CHKSUM_ENHANCE__ |
| 2910 | nvram_util_get_data_item(&ldi, NVRAM_EF_CORE_CHKSUM_INFO_LID); |
| 2911 | if(ldi == NULL) |
| 2912 | { |
| 2913 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[OTA]%s->LINE 0x%04x :lid is NULL\r\n", __FUNCTION__, __LINE__); |
| 2914 | NVRAM_EXT_ASSERT(KAL_FALSE, NVRAM_EF_CORE_CHKSUM_INFO_LID, NVRAM_LOC_INVALID_LID_6, 0, __LINE__); |
| 2915 | } |
| 2916 | nvram_write_data_item(ldi, 1, (kal_uint8 *)(&(chksum_algo_ptr->cur_algo)), KAL_TRUE); |
| 2917 | if(nvram_ee_info != NULL){ |
| 2918 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_UPDATE_CHKSUM_INFO_FILE_DONE; |
| 2919 | } |
| 2920 | #endif |
| 2921 | MD_TRC_FUNC_NVRAM_VERSION_CONFLICT_RESOLVE(4); |
| 2922 | |
| 2923 | return nvram_destruct_disk_table(); |
| 2924 | } |
| 2925 | |
| 2926 | /***************************************************************************** |
| 2927 | * FUNCTION |
| 2928 | * nvram_write_system_record |
| 2929 | * DESCRIPTION |
| 2930 | * This function is used to write system record |
| 2931 | * PARAMETERS |
| 2932 | * void |
| 2933 | * RETURNS |
| 2934 | * void |
| 2935 | *****************************************************************************/ |
| 2936 | |
| 2937 | kal_bool nvram_write_system_record(nvram_lock_state_enum lock_state) |
| 2938 | { |
| 2939 | /*----------------------------------------------------------------*/ |
| 2940 | /* Local Variables */ |
| 2941 | /*----------------------------------------------------------------*/ |
| 2942 | kal_bool write_status = KAL_FALSE; |
| 2943 | nvram_ltable_entry_struct *ldi; |
| 2944 | |
| 2945 | /*----------------------------------------------------------------*/ |
| 2946 | /* Code Body */ |
| 2947 | /*----------------------------------------------------------------*/ |
| 2948 | |
| 2949 | if (lock_state == NVRAM_LOCK_DISABLE) |
| 2950 | { |
| 2951 | nvram_ptr->lock = KAL_FALSE; |
| 2952 | } |
| 2953 | else if (lock_state == NVRAM_LOCK_ENABLE) |
| 2954 | { |
| 2955 | nvram_ptr->lock = KAL_TRUE; |
| 2956 | } |
| 2957 | else |
| 2958 | { |
| 2959 | /* use default value assigned by custom */ |
| 2960 | nvram_ptr->lock = nvram_custom_lock_status(); |
| 2961 | } |
| 2962 | if(nvram_ee_info != NULL){ |
| 2963 | nvram_ee_info->nvram_init_context.lock = nvram_ptr->lock; |
| 2964 | } |
| 2965 | nvram_assign_system_record_default_value((kal_char *)nvram_ptr->coded_version, release_verno()); |
| 2966 | nvram_update_lock_state(nvram_ptr->lock); |
| 2967 | |
| 2968 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 2969 | write_status = nvram_reset_data_items(NVRAM_RESET_CERTAIN, NVRAM_APP_RESERVED, ldi, 1, ldi->total_records); |
| 2970 | /* Fatal error. Cannot write system-level record!? */ |
| 2971 | NVRAM_EXT_ASSERT(write_status == KAL_TRUE, 0, NVRAM_LOC_WRITE_SYS_LID_FAIL, nvram_ptr->state); |
| 2972 | |
| 2973 | return write_status; |
| 2974 | } |
| 2975 | |
| 2976 | |
| 2977 | |
| 2978 | /***************************************************************************** |
| 2979 | * FUNCTION |
| 2980 | * nvram_supplementary_check_data_item_for_fw |
| 2981 | * DESCRIPTION |
| 2982 | * do the supplementary check :build time check |
| 2983 | * PARAMETERS |
| 2984 | * LIDtoCheck [IN] Should be the record to check |
| 2985 | * RETURNS |
| 2986 | * void |
| 2987 | *****************************************************************************/ |
| 2988 | static kal_bool nvram_supplementary_check_data_item_for_fw() |
| 2989 | { |
| 2990 | /*----------------------------------------------------------------*/ |
| 2991 | /* Local Variables */ |
| 2992 | /*----------------------------------------------------------------*/ |
| 2993 | nvram_ltable_entry_struct *ldi; |
| 2994 | kal_bool result = KAL_FALSE; |
| 2995 | kal_uint8 *buffer = NULL; |
| 2996 | kal_uint8 *default_value = NULL; |
| 2997 | /*----------------------------------------------------------------*/ |
| 2998 | /* Code Body */ |
| 2999 | /*----------------------------------------------------------------*/ |
| 3000 | |
| 3001 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 3002 | |
| 3003 | buffer = (kal_uint8*) get_ctrl_buffer(ldi->size); |
| 3004 | default_value = (kal_uint8*) get_ctrl_buffer(ldi->size); |
| 3005 | nvram_get_default_value_to_write(ldi, 4, default_value, ldi->size); //get the build time |
| 3006 | |
| 3007 | nvram_util_get_data_item(&ldi, NVRAM_EF_CORE_FACTORY_RESET_AND_OTA_LID); |
| 3008 | if (nvram_read_data_item(ldi, 1, 1, buffer, ldi->size) == NVRAM_IO_ERRNO_OK) |
| 3009 | { |
| 3010 | if (kal_mem_cmp((kal_char*) buffer, (kal_char*) default_value, ldi->size) != 0) |
| 3011 | { |
| 3012 | result = KAL_FALSE; |
| 3013 | } |
| 3014 | else |
| 3015 | { |
| 3016 | result = KAL_TRUE; |
| 3017 | } |
| 3018 | } |
| 3019 | else |
| 3020 | { |
| 3021 | result = KAL_FALSE; |
| 3022 | } |
| 3023 | free_ctrl_buffer(default_value); |
| 3024 | free_ctrl_buffer(buffer); |
| 3025 | return result; |
| 3026 | } |
| 3027 | |
| 3028 | void update_old_md_version_to_nvram_ee_info() |
| 3029 | { |
| 3030 | nvram_ltable_entry_struct *ldi; |
| 3031 | kal_uint8 *buffer = NULL; |
| 3032 | |
| 3033 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 3034 | buffer = (kal_uint8*) get_ctrl_buffer(4*ldi->size); |
| 3035 | kal_mem_set(buffer,0,4*ldi->size); |
| 3036 | //rec_id:1->code version;rec_id:2->NVRAM_EF_BRANCH_VERNO_LID; |
| 3037 | //rec_id:3->NVRAM_EF_FLAVOR_VERNO_LID;4->NVRAM_EF_BUILD_TIME_LID |
| 3038 | if (nvram_read_data_item(ldi, 1, 4, buffer, 4*ldi->size) == NVRAM_IO_ERRNO_OK) |
| 3039 | { |
| 3040 | if(nvram_ee_info != NULL){ |
| 3041 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_START; |
| 3042 | kal_mem_cpy((kal_uint8*)(nvram_ee_info->nvram_init_context.old_coded_version), (kal_uint8*)buffer, NVRAM_MD_VERSION_INFO_SIZE); |
| 3043 | kal_mem_cpy((kal_uint8*)(nvram_ee_info->nvram_init_context.old_branch_version), (kal_uint8*)(buffer+ldi->size), NVRAM_MD_VERSION_INFO_SIZE); |
| 3044 | kal_mem_cpy((kal_uint8*)(nvram_ee_info->nvram_init_context.old_flavor_version), (kal_uint8*)(buffer+2*ldi->size), NVRAM_MD_VERSION_INFO_SIZE); |
| 3045 | kal_mem_cpy((kal_uint8*)(nvram_ee_info->nvram_init_context.old_build_time), (kal_uint8*)(buffer+3*ldi->size), NVRAM_MD_VERSION_INFO_SIZE); |
| 3046 | nvram_ee_info->nvram_init_time[8] = kal_get_systicks(); |
| 3047 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"old coded_version: %s \r\n",nvram_ee_info->nvram_init_context.old_coded_version); |
| 3048 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"old branch_version: %s \r\n",nvram_ee_info->nvram_init_context.old_branch_version); |
| 3049 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"old flavor_version: %s \r\n",nvram_ee_info->nvram_init_context.old_flavor_version); |
| 3050 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"old build_time: %s \r\n",nvram_ee_info->nvram_init_context.old_build_time); |
| 3051 | } |
| 3052 | } |
| 3053 | free_ctrl_buffer(buffer); |
| 3054 | return; |
| 3055 | } |
| 3056 | /***************************************************************************** |
| 3057 | * FUNCTION |
| 3058 | * nvram_supplementary_check_data_item |
| 3059 | * DESCRIPTION |
| 3060 | * do some supplementary check, such as branch or customer package |
| 3061 | * PARAMETERS |
| 3062 | * LIDtoCheck [IN] Should be the record to check |
| 3063 | * RETURNS |
| 3064 | * void |
| 3065 | *****************************************************************************/ |
| 3066 | static kal_bool nvram_supplementary_check_data_item(nvram_lid_enum LIDtoCheck) |
| 3067 | { |
| 3068 | /*----------------------------------------------------------------*/ |
| 3069 | /* Local Variables */ |
| 3070 | /*----------------------------------------------------------------*/ |
| 3071 | nvram_ltable_entry_struct *ldi; |
| 3072 | kal_bool result = KAL_FALSE; |
| 3073 | kal_uint16 rec_id = 1; |
| 3074 | |
| 3075 | /*----------------------------------------------------------------*/ |
| 3076 | /* Code Body */ |
| 3077 | /*----------------------------------------------------------------*/ |
| 3078 | |
| 3079 | |
| 3080 | switch(LIDtoCheck) |
| 3081 | { |
| 3082 | case NVRAM_EF_SYS_LID: |
| 3083 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 3084 | rec_id = 1; |
| 3085 | break; |
| 3086 | case NVRAM_EF_BRANCH_VERNO_LID: |
| 3087 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 3088 | rec_id = 2; |
| 3089 | break; |
| 3090 | case NVRAM_EF_FLAVOR_VERNO_LID: |
| 3091 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 3092 | rec_id = 3; |
| 3093 | break; |
| 3094 | case NVRAM_EF_BUILD_TIME_LID: |
| 3095 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 3096 | rec_id = 4; |
| 3097 | break; |
| 3098 | default: |
| 3099 | nvram_util_get_data_item(&ldi, LIDtoCheck); |
| 3100 | break; |
| 3101 | } |
| 3102 | |
| 3103 | { |
| 3104 | kal_uint8 *buffer = (kal_uint8*) get_ctrl_buffer(ldi->size); |
| 3105 | |
| 3106 | if (nvram_read_data_item(ldi, rec_id, 1, buffer, ldi->size) == NVRAM_IO_ERRNO_OK) |
| 3107 | { |
| 3108 | kal_uint8 *default_value = (kal_uint8*) get_ctrl_buffer(ldi->size); |
| 3109 | |
| 3110 | nvram_get_default_value_to_write(ldi, rec_id, default_value, ldi->size); |
| 3111 | |
| 3112 | if (kal_mem_cmp((kal_char*) buffer, (kal_char*) default_value, ldi->size) != 0) |
| 3113 | { |
| 3114 | result = KAL_FALSE; |
| 3115 | } |
| 3116 | else |
| 3117 | { |
| 3118 | result = KAL_TRUE; |
| 3119 | } |
| 3120 | free_ctrl_buffer(default_value); |
| 3121 | } |
| 3122 | else |
| 3123 | { |
| 3124 | result = KAL_FALSE; |
| 3125 | } |
| 3126 | free_ctrl_buffer(buffer); |
| 3127 | } |
| 3128 | |
| 3129 | return result; |
| 3130 | } |
| 3131 | |
| 3132 | |
| 3133 | /***************************************************************************** |
| 3134 | * FUNCTION |
| 3135 | * nvram_supplementary_check |
| 3136 | * DESCRIPTION |
| 3137 | * do some supplementary check, such as branch or customer package |
| 3138 | * PARAMETERS |
| 3139 | * |
| 3140 | * RETURNS |
| 3141 | * void |
| 3142 | *****************************************************************************/ |
| 3143 | static kal_bool nvram_supplementary_check(void) |
| 3144 | { |
| 3145 | /*----------------------------------------------------------------*/ |
| 3146 | /* Local Variables */ |
| 3147 | /*----------------------------------------------------------------*/ |
| 3148 | kal_bool temp_result = KAL_TRUE; |
| 3149 | |
| 3150 | /*----------------------------------------------------------------*/ |
| 3151 | /* Code Body */ |
| 3152 | /*----------------------------------------------------------------*/ |
| 3153 | |
| 3154 | /* Step 1: handle branch(flavor)/BIN change */ |
| 3155 | /* branch and flavor must all same with before, or else reset branch */ |
| 3156 | if ((!nvram_supplementary_check_data_item(NVRAM_EF_BRANCH_VERNO_LID)) |
| 3157 | || (!nvram_supplementary_check_data_item(NVRAM_EF_FLAVOR_VERNO_LID))) |
| 3158 | { |
| 3159 | MD_TRC_FUNC_NVRAM_SUPPLEMENTARY_CHECK(0); |
| 3160 | #if defined(__CCCIFS_SUPPORT__) |
| 3161 | // [Smart Phone Modem][Telephony Load Reduction] && [Data Card][RNDIS/HOSTED Dongle] |
| 3162 | // Skip flavor checks, because of LID sharing between modems. |
| 3163 | #else |
| 3164 | temp_result = nvram_reset_data_items(NVRAM_RESET_BRANCH, NVRAM_APP_RESERVED, NULL, 0, 0); |
| 3165 | #endif |
| 3166 | nvram_ptr->sw_status |= NVRAM_SW_BRANCH_CHANGE; |
| 3167 | if(nvram_ee_info != NULL){ |
| 3168 | nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status; |
| 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | #ifdef __NVRAM_SUPPORT_CUSTPACK__ |
| 3173 | /* Step 2: handle custpack change */ |
| 3174 | if (!nvram_supplementary_check_data_item(NVRAM_EF_CUSTPACK_VERNO_LID)) |
| 3175 | { |
| 3176 | MD_TRC_FUNC_NVRAM_SUPPLEMENTARY_CHECK(1); |
| 3177 | temp_result = nvram_reset_data_items(NVRAM_RESET_CUSTPACK, NVRAM_APP_RESERVED, NULL, 0, 0); |
| 3178 | nvram_ptr->sw_status |= NVRAM_SW_CUSTPACK_CHANGE; |
| 3179 | if(nvram_ee_info != NULL){ |
| 3180 | nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status; |
| 3181 | } |
| 3182 | } |
| 3183 | #endif |
| 3184 | |
| 3185 | return temp_result; |
| 3186 | } |
| 3187 | |
| 3188 | #if !defined(__MTK_INTERNAL_ENG_USER__) && defined(__NVRAM_INIT_ACTIVE_RECOVER__) |
| 3189 | /***************************************************************************** |
| 3190 | * FUNCTION |
| 3191 | * nvram_recover_all_ldi |
| 3192 | * DESCRIPTION |
| 3193 | * Recover select category from bin region |
| 3194 | * |
| 3195 | * PARAMETERS |
| 3196 | * category [IN] |
| 3197 | * RETURNS |
| 3198 | * KAL_TRUE if success, KAL_FALSE otherwise. |
| 3199 | *****************************************************************************/ |
| 3200 | static kal_bool nvram_recover_all_ldi(nvram_category_enum category) |
| 3201 | { |
| 3202 | /*----------------------------------------------------------------*/ |
| 3203 | /* Local Variables */ |
| 3204 | /*----------------------------------------------------------------*/ |
| 3205 | nvram_ltable_entry_struct *ldi; |
| 3206 | NVRAM_FILE_NAME nvramname; |
| 3207 | nvram_folder_enum folder_index; |
| 3208 | |
| 3209 | /*----------------------------------------------------------------*/ |
| 3210 | /* Code Body */ |
| 3211 | /*----------------------------------------------------------------*/ |
| 3212 | |
| 3213 | //check nvram lock flag |
| 3214 | nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_LOCK_LID); |
| 3215 | folder_index = nvram_query_folder_index(ldi->category); |
| 3216 | nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE); |
| 3217 | if(nvram_drv_fat_auto_recover(nvramname, folder_index) != NVRAM_ERRNO_SUCCESS) { |
| 3218 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s nvram_drv_fat_auto_recover NVRAM_EF_NVRAM_LOCK_LID fail\r\n",__FUNCTION__); |
| 3219 | return KAL_FALSE; |
| 3220 | } |
| 3221 | |
| 3222 | //try to recover category |
| 3223 | ldi = &logical_data_item_table[0]; |
| 3224 | do |
| 3225 | { |
| 3226 | if (!(ldi->category & category) || (ldi->LID == NVRAM_EF_NVRAM_LOCK_LID)) { |
| 3227 | continue; |
| 3228 | } |
| 3229 | folder_index = nvram_query_folder_index(ldi->category); |
| 3230 | nvram_util_make_lid_filename(ldi, nvramname, KAL_TRUE); |
| 3231 | nvram_drv_fat_auto_recover(nvramname, folder_index); |
| 3232 | }while(nvram_util_next_data_item(&ldi)); |
| 3233 | |
| 3234 | return KAL_TRUE; |
| 3235 | } |
| 3236 | #endif |
| 3237 | |
| 3238 | |
| 3239 | /***************************************************************************** |
| 3240 | * FUNCTION |
| 3241 | * nvram_init_all_ldi |
| 3242 | * DESCRIPTION |
| 3243 | * Formats device by invoking drv_format() function. Re-initialize all logical data items to |
| 3244 | * default value. |
| 3245 | * |
| 3246 | * This function is supposed to be called only when: |
| 3247 | * 1> unformatted device. |
| 3248 | * 2> system level record read error. |
| 3249 | * 3> incompatible version. |
| 3250 | * PARAMETERS |
| 3251 | * reset_category [IN] |
| 3252 | * is_after_format(?) [IN] Only when device is just re-formatted will this value be true. |
| 3253 | * RETURNS |
| 3254 | * Result of writing system records. KAL_TRUE if success, KAL_FALSE otherwise. |
| 3255 | *****************************************************************************/ |
| 3256 | static kal_bool nvram_init_all_ldi(nvram_reset_category_enum reset_category) |
| 3257 | { |
| 3258 | /*----------------------------------------------------------------*/ |
| 3259 | /* Local Variables */ |
| 3260 | /*----------------------------------------------------------------*/ |
| 3261 | |
| 3262 | /*----------------------------------------------------------------*/ |
| 3263 | /* Code Body */ |
| 3264 | /*----------------------------------------------------------------*/ |
| 3265 | |
| 3266 | /***************************************************** |
| 3267 | * Launch power first and show the first picture |
| 3268 | ******************************************************/ |
| 3269 | nvram_util_poweron(); |
| 3270 | #if !defined(__L1_STANDALONE__) && !defined(EMPTY_MMI) && !defined(EXTERNAL_MMI) |
| 3271 | MMICheckDiskDisplay(); |
| 3272 | #endif |
| 3273 | |
| 3274 | #ifdef __NVRAM_WRITE_WITH_FILE_SIZE__ |
| 3275 | bResetNvramData = KAL_TRUE; |
| 3276 | #endif |
| 3277 | |
| 3278 | MD_TRC_FUNC_NVRAM_INIT_ALL(reset_category); |
| 3279 | reset_category = NVRAM_RESET_ALL; |
| 3280 | if (reset_category == NVRAM_RESET_ALL) |
| 3281 | { |
| 3282 | if (nvram_ptr->sw_status & NVRAM_SW_EMPTY_FAT) |
| 3283 | { |
| 3284 | nvram_delete_all_nvram_files(NVRAM_FIRST_BOOTUP); |
| 3285 | } |
| 3286 | else |
| 3287 | { |
| 3288 | nvram_delete_all_nvram_files(NVRAM_NORMAL_BOOTUP); |
| 3289 | if(nvram_ee_info != NULL){ |
| 3290 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTOR_BOOT_DELETE_NVDATA_DONE; |
| 3291 | nvram_ee_info->nvram_init_time[5] = kal_get_systicks(); |
| 3292 | } |
| 3293 | } |
| 3294 | } |
| 3295 | |
| 3296 | nvram_reset_data_items(reset_category, NVRAM_APP_RESERVED, NULL, 0, 0); |
| 3297 | nvram_write_system_record((nvram_lock_state_enum)nvram_ptr->lock); |
| 3298 | if(nvram_ee_info != NULL){ |
| 3299 | if(nvram_ee_info->nvram_init_step ==NVRAM_CORE_INIT_FIRST_BOOT_RESET_ALL_FILE_DONE){ |
| 3300 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_RESET_SYS_LID_FILE_DONE; |
| 3301 | } |
| 3302 | else if(nvram_ee_info->nvram_init_step ==NVRAM_CORE_INIT_FACTOR_BOOT_RESET_NON_CRITICAL_FILE_DONE){ |
| 3303 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTOR_BOOT_RESET_SYS_LID_FILE_DONE; |
| 3304 | nvram_ee_info->nvram_init_time[6] = kal_get_systicks(); |
| 3305 | } |
| 3306 | } |
| 3307 | return KAL_TRUE; |
| 3308 | } |
| 3309 | |
| 3310 | /***************************************************************************** |
| 3311 | * FUNCTION |
| 3312 | * nvram_test_lock |
| 3313 | * DESCRIPTION |
| 3314 | * get lock state from nvram context. |
| 3315 | * PARAMETERS |
| 3316 | * void |
| 3317 | * RETURNS |
| 3318 | * KAL_TRUE if locked, else KAL_FALSE |
| 3319 | *****************************************************************************/ |
| 3320 | kal_bool nvram_test_lock(void) |
| 3321 | { |
| 3322 | /*----------------------------------------------------------------*/ |
| 3323 | /* Local Variables */ |
| 3324 | /*----------------------------------------------------------------*/ |
| 3325 | |
| 3326 | /*----------------------------------------------------------------*/ |
| 3327 | /* Code Body */ |
| 3328 | /*----------------------------------------------------------------*/ |
| 3329 | return nvram_ptr->lock; |
| 3330 | } |
| 3331 | |
| 3332 | kal_bool nvram_sec_check(void){ |
| 3333 | #ifdef __NVRAM_SEC_CHECK_EN__ |
| 3334 | /*----------------------------------------------------------------*/ |
| 3335 | /* Local Variables */ |
| 3336 | /*----------------------------------------------------------------*/ |
| 3337 | kal_uint8* sec_pattern=NULL; |
| 3338 | kal_uint8* record_buf_ptr; |
| 3339 | nvram_ltable_entry_struct *ldi = NULL; |
| 3340 | kal_uint32 idx = 0; |
| 3341 | kal_uint32 record_sz, record_cnt, sec_pattern_sz; |
| 3342 | |
| 3343 | record_sz = NVRAM_SEC_CHECK_LEN; |
| 3344 | record_cnt = NVRAM_EF_NVRAM_SEC_CHECK_TOTAL; |
| 3345 | sec_pattern_sz = record_sz*record_cnt; |
| 3346 | |
| 3347 | /*----------------------------------------------------------------*/ |
| 3348 | /* Code Body */ |
| 3349 | /*----------------------------------------------------------------*/ |
| 3350 | sec_pattern = (kal_uint8*) get_ctrl_buffer(sec_pattern_sz); |
| 3351 | |
| 3352 | |
| 3353 | nvram_util_get_data_item(&ldi, NVRAM_EF_NVRAM_SEC_CHECK_LID); |
| 3354 | kal_mem_set(sec_pattern, 0, sec_pattern_sz); |
| 3355 | nvram_read_data_item(ldi, 1, record_cnt, sec_pattern, sec_pattern_sz); |
| 3356 | |
| 3357 | record_buf_ptr = sec_pattern; |
| 3358 | #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__ |
| 3359 | SST_Secure_Algo(NVRAM_MSP_DECRYPT, (kal_uint32)(record_buf_ptr), record_sz, nvram_ptr->secret_key, record_buf_ptr); |
| 3360 | for(idx= 0; idx<record_sz/2; idx++){ |
| 3361 | if(record_buf_ptr[idx]!=((~(record_buf_ptr[idx+record_sz/2]))&0xFF)){ |
| 3362 | NVRAM_EXT_ASSERT(KAL_FALSE,0 ,NVRAM_ERRNO_MSP_CHECK_ERROR,0, free_ctrl_buffer(sec_pattern)); |
| 3363 | } |
| 3364 | } |
| 3365 | #endif |
| 3366 | record_buf_ptr = &sec_pattern[record_sz]; |
| 3367 | nvram_AES_decrypt(record_buf_ptr, record_sz); |
| 3368 | |
| 3369 | for(idx= 0; idx<record_sz/2; idx++){ |
| 3370 | if(record_buf_ptr[idx]!=((~(record_buf_ptr[idx+record_sz/2]))&0xFF)){ |
| 3371 | NVRAM_EXT_ASSERT(KAL_FALSE,0,NVRAM_ERRNO_CONF_CHECK_ERROR,0, free_ctrl_buffer(sec_pattern)); |
| 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | free_ctrl_buffer(sec_pattern); |
| 3376 | #endif |
| 3377 | return KAL_TRUE; |
| 3378 | } |
| 3379 | |
| 3380 | /***************************************************************************** |
| 3381 | * FUNCTION |
| 3382 | * nvram_init |
| 3383 | * DESCRIPTION |
| 3384 | * This is init() function of NVRAM module. |
| 3385 | * This function initialize all the context variables required for NVRAM module |
| 3386 | * PARAMETERS |
| 3387 | * task_indx [IN] |
| 3388 | * RETURNS |
| 3389 | * True if succeed. |
| 3390 | *****************************************************************************/ |
| 3391 | kal_bool nvram_init(void) |
| 3392 | { |
| 3393 | /*----------------------------------------------------------------*/ |
| 3394 | /* Local Variables */ |
| 3395 | /*----------------------------------------------------------------*/ |
| 3396 | kal_bool ld_init_result = KAL_TRUE; |
| 3397 | nvram_drv_status_enum drv_init_result = NVRAM_ERRNO_SUCCESS; |
| 3398 | nvram_ltable_entry_struct *ldi = NULL; |
| 3399 | kal_int32 Ret = 0; |
| 3400 | /*----------------------------------------------------------------*/ |
| 3401 | /* Code Body */ |
| 3402 | /*----------------------------------------------------------------*/ |
| 3403 | /* Assume that BytesPerCluster still not initialized if BytesPerCluster==0 */ |
| 3404 | |
| 3405 | nvram_ee_info_init(); |
| 3406 | nvram_get_trace_configuration(); |
| 3407 | NVRAM_INIT_TIME_UT_STAMP(0); |
| 3408 | if (BytesPerCluster == 0) |
| 3409 | { |
| 3410 | /* Please do not remove this code if NVRAM still use kal_tmp_mem_alloc |
| 3411 | The detail reason please see nvram_malloc_disk_table */ |
| 3412 | FS_DiskInfo DI; |
| 3413 | NVRAM_FS_START_EX(FS_OP_GETDISKINFO, L"Z:\\"); |
| 3414 | Ret = FS_GetDiskInfo((const WCHAR*)L"Z:\\", &DI, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE); |
| 3415 | NVRAM_FS_END(FS_OP_GETDISKINFO,Ret); |
| 3416 | /* Set BytesPerCluster to the accurate value */ |
| 3417 | BytesPerCluster = DI.BytesPerSector * DI.SectorsPerCluster; |
| 3418 | } |
| 3419 | |
| 3420 | #if defined (__NVRAM_UT_TEST__) |
| 3421 | nvram_ptr->state = NVRAM_STATE_NOT_READY; |
| 3422 | if((nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id)) |
| 3423 | {} //do not create mutex again, otherwise fatal error happen |
| 3424 | else |
| 3425 | #endif |
| 3426 | { |
| 3427 | g_nvram_impt_mutex = kal_create_mutex("NV_IMPT"); |
| 3428 | g_nvram_fs_mutex = kal_create_mutex("NV_FS"); |
| 3429 | g_nvram_trace_mutex = kal_create_mutex("NV_TRACE"); |
| 3430 | #if defined(__NVRAM_ACCESS_TIMEOUT_ASSERT__) |
| 3431 | nvram_gpt_handle = DclSGPT_Open(DCL_GPT_CB, FLAGS_NONE); |
| 3432 | #endif |
| 3433 | } |
| 3434 | |
| 3435 | nvram_ptr->sw_status = 0; |
| 3436 | |
| 3437 | /***************************************************** |
| 3438 | * NVRAM get custoemr checksum algorithm config value |
| 3439 | ******************************************************/ |
| 3440 | #ifdef __NV_CHKSUM_ENHANCE__ |
| 3441 | nvram_cfg_crrnt_chksum_algo(); |
| 3442 | #endif |
| 3443 | /***************************************************** |
| 3444 | * Construct NVRAM table and init some default value |
| 3445 | ******************************************************/ |
| 3446 | nvram_pre_init(); |
| 3447 | |
| 3448 | #if defined(__NVRAM_MONITOR_ENABLED__) |
| 3449 | /***************************************** |
| 3450 | * NVRAM Monitor Init |
| 3451 | *********************************************/ |
| 3452 | #if defined (__NVRAM_UT_TEST__) |
| 3453 | if((nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id)) |
| 3454 | {} //do not create mutex again, otherwise fatal error happen |
| 3455 | else |
| 3456 | #endif |
| 3457 | { |
| 3458 | nvram_mon_init(); |
| 3459 | } |
| 3460 | #endif |
| 3461 | if(nvram_ee_info != NULL){ |
| 3462 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"NVRAM Core Init Start at %d\r\n",__LINE__); |
| 3463 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"build_time: %s \r\n",build_date_time()); |
| 3464 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"branch_version: %s \r\n",release_branch()); |
| 3465 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"flavor_version: %s \r\n",release_flavor()); |
| 3466 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"coded_version: %s \r\n",nvram_ptr->coded_version); |
| 3467 | nvram_ee_info->nvram_init_step = NVRAM_PRE_INIT_DONE; |
| 3468 | nvram_ee_info->nvram_init_time[1] = kal_get_systicks(); |
| 3469 | } |
| 3470 | #ifdef __NVRAM_BACKUP_DISK__ |
| 3471 | /***************************************** |
| 3472 | * Init Backup partition |
| 3473 | *********************************************/ |
| 3474 | nvram_init_backup_disk(); |
| 3475 | #endif |
| 3476 | |
| 3477 | |
| 3478 | #ifdef __NVRAM_SECURE_DATA_STORAGE__ |
| 3479 | /**************************************************** |
| 3480 | * Init Secure Data Storage and get the storage mode |
| 3481 | ******************************************************/ |
| 3482 | if (nvram_sds_status() == NVRAM_ERRNO_SDS_EMPTY) |
| 3483 | { |
| 3484 | MD_TRC_FUNC_NVRAM_INIT(0, 0); |
| 3485 | nvram_ptr->sw_status |= NVRAM_SW_EMPTY_SDS; |
| 3486 | if(nvram_ee_info != NULL){ |
| 3487 | nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status; |
| 3488 | } |
| 3489 | nvram_sds_init_start(); |
| 3490 | //nvram_init_all_ldi(NVRAM_RESET_SDS); |
| 3491 | nvram_sds_init_end(); |
| 3492 | } |
| 3493 | #endif |
| 3494 | |
| 3495 | /***************************************** |
| 3496 | * Init FAT |
| 3497 | * if the secure storage is empty => software version ... and many data is missing |
| 3498 | * => format all |
| 3499 | *********************************************/ |
| 3500 | #if !defined(__MTK_INTERNAL_ENG_USER__) && defined(__NVRAM_INIT_ACTIVE_RECOVER__) |
| 3501 | REINIT_FAT: |
| 3502 | #endif |
| 3503 | if ((drv_init_result = nvram_drv_fat_status()) == NVRAM_DRV_UNFORMATTED) |
| 3504 | { |
| 3505 | #if !defined(__MTK_INTERNAL_ENG_USER__) && defined(__NVRAM_INIT_ACTIVE_RECOVER__) |
| 3506 | if(nvram_recover_all_ldi(NVRAM_CATEGORY_IMPORTANT)) { |
| 3507 | goto REINIT_FAT; |
| 3508 | } |
| 3509 | #endif |
| 3510 | #if defined (__NVRAM_UT_TEST__) |
| 3511 | nvram_boot_trace |= BOOT_TRACE_DRV_UNFORMATTED; |
| 3512 | #endif |
| 3513 | MD_TRC_FUNC_NVRAM_INIT(1, 0); |
| 3514 | nvram_ptr->sw_status |= NVRAM_SW_EMPTY_FAT; |
| 3515 | nvram_drv_fat_init_start(); |
| 3516 | |
| 3517 | #if defined(__NVRAM_CREATE_FILE_ON_WRITE__) |
| 3518 | nvram_util_init_info_file(); |
| 3519 | #endif |
| 3520 | nvram_init_all_ldi(NVRAM_RESET_ALL); |
| 3521 | nvram_util_get_data_item(&ldi, NVRAM_EF_CORE_FACTORY_RESET_AND_OTA_LID); |
| 3522 | nvram_write_data_item(ldi, 1, nvram_ptr->build_time, KAL_TRUE); |
| 3523 | nvram_drv_fat_init_end(); |
| 3524 | if(nvram_ee_info != NULL){ |
| 3525 | nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status; |
| 3526 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FIRST_BOOT_END; |
| 3527 | nvram_ee_info->nvram_init_time[4] = kal_get_systicks(); |
| 3528 | } |
| 3529 | } |
| 3530 | else if (drv_init_result == NVRAM_DRV_FOLDER_NOT_READY) |
| 3531 | { |
| 3532 | #if defined (__NVRAM_UT_TEST__) |
| 3533 | nvram_boot_trace |= BOOT_TRACE_FOLDER_NOT_READY; |
| 3534 | #endif |
| 3535 | if(nvram_ee_info != NULL){ |
| 3536 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTORY_BOOT_CHECK_DONE; |
| 3537 | } |
| 3538 | nvram_create_all_folder(); |
| 3539 | if(nvram_ee_info != NULL){ |
| 3540 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTORY_BOOT_CREATE_ALL_FOLDER_DONE; |
| 3541 | } |
| 3542 | } |
| 3543 | else if (drv_init_result == NVRAM_DRV_DRIVE_BROKEN || drv_init_result == NVRAM_DRV_DRIVE_VNOERR) |
| 3544 | { |
| 3545 | #if defined (__NVRAM_UT_TEST__) |
| 3546 | nvram_boot_trace |= BOOT_TRACE_DRIVE_BROKEN_VNOERR; |
| 3547 | #endif |
| 3548 | MD_TRC_FUNC_NVRAM_INIT(2, 0); |
| 3549 | nvram_ptr->dev_broken = KAL_TRUE; |
| 3550 | goto INIT_END; |
| 3551 | } |
| 3552 | |
| 3553 | /***************************************** |
| 3554 | * Init OTP |
| 3555 | *********************************************/ |
| 3556 | #ifdef __NVRAM_OTP__ |
| 3557 | nvram_otp_construct(); |
| 3558 | #endif |
| 3559 | |
| 3560 | /***************************************** |
| 3561 | * Check system record and do version compatible |
| 3562 | *********************************************/ |
| 3563 | if ((nvram_ptr->sw_status & NVRAM_SW_EMPTY_FAT) |
| 3564 | #ifdef __NVRAM_SECURE_DATA_STORAGE__ |
| 3565 | && (nvram_ptr->sw_status & NVRAM_SW_EMPTY_SDS) |
| 3566 | #endif |
| 3567 | ) |
| 3568 | { |
| 3569 | |
| 3570 | MD_TRC_FUNC_NVRAM_INIT(3, 0); |
| 3571 | goto INIT_END; |
| 3572 | } |
| 3573 | |
| 3574 | |
| 3575 | #if defined(__NVRAM_CREATE_FILE_ON_WRITE__) |
| 3576 | nvram_util_init_info_file(); |
| 3577 | #endif |
| 3578 | NVRAM_INIT_TIME_UT_STAMP(1); |
| 3579 | |
| 3580 | /* Read back system-level record to retrieve software-lock status and data version |
| 3581 | * |
| 3582 | * 1. Read failed: |
| 3583 | * NVRAM Layer must re-initialize all logical data items |
| 3584 | * b'coz we could not ensure the healthy of all ldi, and return. |
| 3585 | * 2. Read success but incompatible versions: |
| 3586 | * Step 1: NVRAM Layer must re-initialize all 'USER' category logical data items. |
| 3587 | * Step 2: According the result of step 1, jump step 3 or step 4 |
| 3588 | * Step 3: Step 1 is success, Must assue following version don't re-initialize in step 1. |
| 3589 | * 3.1 check branch version |
| 3590 | * 3.2 check flavor version |
| 3591 | * 3.3 check custpack version |
| 3592 | * 3.4 check secupack version |
| 3593 | * Step 4: Step 1 is fail |
| 3594 | * 4.1 Initial all data item |
| 3595 | * 3. Read success and compatible versions: |
| 3596 | * 3.1 check branch version |
| 3597 | * 3.2 check flavor version |
| 3598 | * 3.3 check custpack version |
| 3599 | * 3.4 check secupack version |
| 3600 | */ |
| 3601 | nvram_sec_check(); |
| 3602 | |
| 3603 | #ifdef __NV_CHKSUM_ENHANCE__ |
| 3604 | if(NVRAM_IO_ERRNO_OK != nvram_chksum_def_algo_check()) |
| 3605 | { |
| 3606 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"%s():NVRAM checksum algorithm checked %d.\r\n", __FUNCTION__,__LINE__); |
| 3607 | #if defined (__NVRAM_UT_TEST__) |
| 3608 | return KAL_FALSE; |
| 3609 | #endif |
| 3610 | } |
| 3611 | #endif |
| 3612 | |
| 3613 | nvram_ptr->lock = nvram_decrypt_lock_state(); |
| 3614 | if(nvram_ee_info != NULL){ |
| 3615 | nvram_ee_info->nvram_init_context.lock = nvram_ptr->lock; |
| 3616 | } |
| 3617 | kal_mem_set(nvram_ptr->old_coded_version, 0, NVRAM_EF_SYS_SIZE + 1); |
| 3618 | nvram_util_get_data_item(&ldi, NVRAM_EF_SYS_LID); |
| 3619 | if((nvram_read_data_item(ldi, 1, 1, nvram_ptr->old_coded_version, NVRAM_EF_SYS_SIZE) != NVRAM_IO_ERRNO_OK) || is_nvram_factory_reset) |
| 3620 | { |
| 3621 | MD_TRC_FUNC_NVRAM_INIT(5, 0); |
| 3622 | #ifndef __NVRAM_MULTI_FOLDERS__ |
| 3623 | nvram_ptr->sw_status |= NVRAM_SW_EMPTY_FAT; |
| 3624 | #else |
| 3625 | nvram_ptr->sw_status |= NVRAM_SW_VERSION_CHANGE; |
| 3626 | #endif |
| 3627 | nvram_init_all_ldi(NVRAM_RESET_FAT); |
| 3628 | is_nvram_factory_reset = KAL_FALSE; |
| 3629 | if(nvram_ee_info != NULL){ |
| 3630 | nvram_ee_info->nvram_init_time[7] = kal_get_systicks(); |
| 3631 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_FACTORY_BOOT_END; |
| 3632 | nvram_ee_info->nvram_init_type |= NVRAM_INIT_FACTORY_BOOT_UP; |
| 3633 | nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status; |
| 3634 | } |
| 3635 | NVRAM_INIT_TIME_UT_FLOW(NVRAM_INIT_READ_VERSION_FAIL); |
| 3636 | #if defined (__NVRAM_UT_TEST__) |
| 3637 | nvram_boot_trace |= BOOT_TRACE_READ_SYS_LID_FAIL; |
| 3638 | #endif |
| 3639 | } |
| 3640 | #if defined(__CCCIFS_SUPPORT__) && defined(__MTK_TARGET__) |
| 3641 | else if (ccci_queryBootAttributes(BOOT_ATTR_IS_CLEAN_BOOT)) |
| 3642 | { |
| 3643 | MD_TRC_FUNC_NVRAM_INIT(6, 0); |
| 3644 | nvram_init_all_ldi(NVRAM_RESET_FAT); |
| 3645 | NVRAM_INIT_TIME_UT_FLOW(NVRAM_INIT_CLEAN_BOOT); |
| 3646 | } |
| 3647 | #endif |
| 3648 | // Always check if it's version upgrade (in case factory reset and upgrade at one time) |
| 3649 | // Factory reset and OTA upgrade may happen at one time |
| 3650 | { |
| 3651 | /* Initial pseudo merge first */ |
| 3652 | #ifdef __NVRAM_PSEUDO_MERGE__ |
| 3653 | if (!nvram_pseudo_merge()) |
| 3654 | { |
| 3655 | NVRAM_FS_START_EX(FS_OP_DELETE,L"z:\\NVRAM\\NVD_DATA\\INFOALID"); |
| 3656 | Ret = FS_Delete(L"z:\\NVRAM\\NVD_DATA\\INFOALID"); |
| 3657 | NVRAM_FS_END(FS_OP_DELETE,Ret); |
| 3658 | NVRAM_FS_START_EX(FS_OP_DELETE,L"z:\\NVRAM\\NVD_DATA\\PACKALID"); |
| 3659 | Ret = FS_Delete(L"z:\\NVRAM\\NVD_DATA\\PACKALID"); |
| 3660 | NVRAM_FS_END(FS_OP_DELETE,Ret); |
| 3661 | nvram_pseudo_merge(); |
| 3662 | } |
| 3663 | #endif |
| 3664 | |
| 3665 | /* maintain the lock status even after software upgrade */ |
| 3666 | //nvram_ptr->lock = nvram_decrypt_lock_state(); |
| 3667 | |
| 3668 | MD_TRC_FUNC_NVRAM_INIT(7, nvram_ptr->lock); |
| 3669 | nvram_assign_system_record_default_value((kal_char *)nvram_ptr->coded_version, release_verno()); |
| 3670 | |
| 3671 | if(nvram_ee_info != NULL){ |
| 3672 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_START; |
| 3673 | kal_mem_cpy((kal_uint8*)(nvram_ee_info->nvram_init_context.old_coded_version), (kal_uint8*)nvram_ptr->old_coded_version, NVRAM_MD_VERSION_INFO_SIZE); |
| 3674 | update_old_md_version_to_nvram_ee_info(); |
| 3675 | } |
| 3676 | |
| 3677 | /* |
| 3678 | * Read system record success, Compare code version first |
| 3679 | */ |
| 3680 | if (strncmp((kal_char*) nvram_ptr->old_coded_version, (kal_char*) nvram_ptr->coded_version, CODED_DATA_VERSION_SIZE) != 0 || |
| 3681 | (!nvram_supplementary_check_data_item(NVRAM_EF_BUILD_TIME_LID)) || (!nvram_supplementary_check_data_item_for_fw())) |
| 3682 | { |
| 3683 | MD_TRC_FUNC_NVRAM_INIT(8, 0); |
| 3684 | |
| 3685 | nvram_ptr->sw_status |= NVRAM_SW_VERSION_CHANGE; |
| 3686 | #ifdef __NVRAM_CHECK_FILE_AND_RECOVER__ |
| 3687 | is_nvram_first_restore = KAL_TRUE; |
| 3688 | is_nvram_in_ota_flow = KAL_TRUE; |
| 3689 | #endif |
| 3690 | if(nvram_ee_info != NULL){ |
| 3691 | nvram_ee_info->nvram_init_context.sw_status = nvram_ptr->sw_status; |
| 3692 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_CHECK_DONE; |
| 3693 | } |
| 3694 | ld_init_result = nvram_version_conflict_resolve(nvram_ptr->old_coded_version); |
| 3695 | #ifdef __NVRAM_CHECK_FILE_AND_RECOVER__ |
| 3696 | is_nvram_in_ota_flow = KAL_FALSE; |
| 3697 | #endif |
| 3698 | #if 0 |
| 3699 | /* under construction !*/ |
| 3700 | #if !defined(__CCCIFS_SUPPORT__) |
| 3701 | /* under construction !*/ |
| 3702 | #else |
| 3703 | /* under construction !*/ |
| 3704 | /* under construction !*/ |
| 3705 | /* under construction !*/ |
| 3706 | #endif |
| 3707 | #endif |
| 3708 | if(nvram_ee_info != NULL){ |
| 3709 | nvram_ee_info->nvram_init_step = NVRAM_CORE_INIT_OTA_BOOT_END; |
| 3710 | nvram_ee_info->nvram_init_type |= NVRAM_INIT_OTA_BOOT_UP; |
| 3711 | nvram_ee_info->nvram_init_time[12] = kal_get_systicks(); |
| 3712 | } |
| 3713 | if (ld_init_result) |
| 3714 | { |
| 3715 | MD_TRC_FUNC_NVRAM_INIT(9, 0); |
| 3716 | ld_init_result = nvram_supplementary_check(); |
| 3717 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]nvram_supplementary_check() Success,result=%d\r\n",ld_init_result); |
| 3718 | } |
| 3719 | else |
| 3720 | { |
| 3721 | MD_TRC_FUNC_NVRAM_INIT(10, 0); |
| 3722 | /* if errors happen during conflict resolution, initialize all LIDs */ |
| 3723 | ld_init_result = nvram_init_all_ldi(NVRAM_RESET_ALL); |
| 3724 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]nvram_init_all_ldi() Fail %d -> nvram_init_all_ldi()\r\n", (kal_uint32)ld_init_result); |
| 3725 | } |
| 3726 | |
| 3727 | #if defined (__NVRAM_UT_TEST__) |
| 3728 | nvram_boot_trace |= BOOT_TRACE_SW_VERNO_CONFLICT; |
| 3729 | #endif |
| 3730 | /* switch the mode back to SDS mode if need */ |
| 3731 | NVRAM_INIT_TIME_UT_FLOW(NVRAM_INIT_VERSION_CHANGE); |
| 3732 | } |
| 3733 | else /* version compatible */ |
| 3734 | { |
| 3735 | /* |
| 3736 | * Read sys record success and version compatible |
| 3737 | * This case means handset is power on normally: |
| 3738 | * So, nvram should only query restore factory in this case |
| 3739 | */ |
| 3740 | MD_TRC_FUNC_NVRAM_INIT(12, 0); |
| 3741 | //Fast MD booting feature for Modem only load |
| 3742 | //Note: |
| 3743 | // 1. You need to download the correct RAMDISK image to EVB |
| 3744 | // a. RAMDISK image can be dump with META |
| 3745 | // b. FDD/TDD have different RAMDISK image |
| 3746 | // 2. Mark nvram_scan_all_ldi |
| 3747 | ld_init_result = nvram_supplementary_check(); |
| 3748 | |
| 3749 | if ((ld_init_result == KAL_TRUE) && nvram_check_restore_factory_flag()) |
| 3750 | { |
| 3751 | MD_TRC_FUNC_NVRAM_INIT(13, 0); |
| 3752 | NVRAM_DEBUG_DUMP(NVRAM_INFO_DUMP,"[OTA]Check:%d nvram_check_restore_factory_flag fail\r\n",ld_init_result); |
| 3753 | nvram_reset_data_items(NVRAM_RESET_FACTORY, NVRAM_APP_RESERVED, 0, 0, 0); |
| 3754 | } |
| 3755 | NVRAM_INIT_TIME_UT_FLOW(NVRAM_INIT_NORMAL_BOOT); |
| 3756 | #if defined (__NVRAM_UT_TEST__) |
| 3757 | nvram_boot_trace |= BOOT_TRACE_SW_VERNO_COMPATIBLE; |
| 3758 | #endif |
| 3759 | |
| 3760 | } /* version compatible */ |
| 3761 | } |
| 3762 | |
| 3763 | MD_TRC_FUNC_NVRAM_INIT(14, 0); |
| 3764 | |
| 3765 | INIT_END: |
| 3766 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"NVRAM Core Init Done at %d\r\n",__LINE__); |
| 3767 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"NVRAM Post Init Start at %d\r\n\r\n",__LINE__); |
| 3768 | nvram_ptr->state = NVRAM_STATE_READY; |
| 3769 | if(nvram_ee_info != NULL){ |
| 3770 | nvram_ee_info->nvram_init_context.state = NVRAM_STATE_READY; |
| 3771 | nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_START; |
| 3772 | } |
| 3773 | nvram_write_bitmap_into_file(); |
| 3774 | if(nvram_ee_info != NULL){ |
| 3775 | nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_WRITE_BITMAP_DONE; |
| 3776 | nvram_ee_info->nvram_init_time[13] = kal_get_systicks(); |
| 3777 | } |
| 3778 | NVRAM_INIT_TIME_UT_STAMP(2); |
| 3779 | #if !defined (__NVRAM_UT_TEST__) |
| 3780 | mcf_full_ota_status = mcf_do_ota_full(); |
| 3781 | #endif |
| 3782 | if(nvram_ee_info != NULL){ |
| 3783 | nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_MCF_OTA_DONE; |
| 3784 | nvram_ee_info->nvram_init_time[14] = kal_get_systicks(); |
| 3785 | } |
| 3786 | NVRAM_INIT_TIME_UT_STAMP(3); |
| 3787 | #if defined(__NVRAM_INIT_LID_BUFFER__) |
| 3788 | nvram_init_lid_buffer_prepare(); |
| 3789 | #endif |
| 3790 | |
| 3791 | #ifdef __NVRAM_LID_PREREAD__ |
| 3792 | nvram_pre_read_white_list_lid(); |
| 3793 | #endif |
| 3794 | if(nvram_ee_info != NULL){ |
| 3795 | nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_CACHE_PREREAD_DONE; |
| 3796 | nvram_ee_info->nvram_init_time[15] = kal_get_systicks(); |
| 3797 | } |
| 3798 | #if defined (__NVRAM_UT_TEST__) |
| 3799 | if((nvram_test_task1_id) && (kal_get_current_task()==nvram_test_task1_id)) |
| 3800 | {} //do nothing here |
| 3801 | else |
| 3802 | #endif |
| 3803 | { |
| 3804 | NVRAM_INIT_TIME_UT_STAMP(4); |
| 3805 | custom_em_nvram_config_com_port(); |
| 3806 | if(nvram_ee_info != NULL){ |
| 3807 | nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_CUSTOM_EM_NVRAM_CONFIG_DONE; |
| 3808 | nvram_ee_info->nvram_init_time[16] = kal_get_systicks(); |
| 3809 | } |
| 3810 | NVRAM_INIT_TIME_UT_STAMP(5); |
| 3811 | custom_nvram_config(); |
| 3812 | if(nvram_ee_info != NULL){ |
| 3813 | nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_CUSTOM_NVRAM_CONFIG_DONE; |
| 3814 | nvram_ee_info->nvram_init_time[17] = kal_get_systicks(); |
| 3815 | } |
| 3816 | |
| 3817 | NVRAM_INIT_TIME_UT_STAMP(6); |
| 3818 | custom_default_mode_config(); |
| 3819 | NVRAM_INIT_TIME_UT_STAMP(7); |
| 3820 | if(nvram_ee_info != NULL){ |
| 3821 | nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_CUSTOM_DEFAULT_MODE_CONFIG; |
| 3822 | nvram_ee_info->nvram_init_time[18] = kal_get_systicks(); |
| 3823 | } |
| 3824 | #ifdef __NVRAM_CRYPT_TEST__ |
| 3825 | { |
| 3826 | kal_uint8 array_t[NVRAM_MSP_TEST_LEN]; |
| 3827 | nvram_external_read_data(NVRAM_EF_NVRAM_MSP_TEST_LID, |
| 3828 | 1, |
| 3829 | (kal_uint8*)array_t, |
| 3830 | NVRAM_EF_NVRAM_MSP_TEST_SIZE); |
| 3831 | } |
| 3832 | #endif |
| 3833 | } |
| 3834 | if(nvram_ee_info != NULL){ |
| 3835 | nvram_ee_info->nvram_init_step = NVRAM_POST_INIT_END; |
| 3836 | NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"NVRAM Post Init Done at %d\r\n\r\n",__LINE__); |
| 3837 | } |
| 3838 | return KAL_TRUE; |
| 3839 | } /* end of nvram_init function */ |
| 3840 | |
| 3841 | /***************************************************************************** |
| 3842 | * FUNCTION |
| 3843 | * nvram_reset |
| 3844 | * DESCRIPTION |
| 3845 | * This is reset() function of NVRAM module. |
| 3846 | * PARAMETERS |
| 3847 | * task_indx [IN] |
| 3848 | * RETURNS |
| 3849 | * void |
| 3850 | *****************************************************************************/ |
| 3851 | kal_bool nvram_reset(void) |
| 3852 | { |
| 3853 | /*----------------------------------------------------------------*/ |
| 3854 | /* Local Variables */ |
| 3855 | /*----------------------------------------------------------------*/ |
| 3856 | |
| 3857 | /*----------------------------------------------------------------*/ |
| 3858 | /* Code Body */ |
| 3859 | /*----------------------------------------------------------------*/ |
| 3860 | #if !defined(__MTK_TARGET__) |
| 3861 | nvram_ptr->state = NVRAM_STATE_NULL; |
| 3862 | #endif |
| 3863 | return KAL_TRUE; |
| 3864 | } /* end of nvram_reset function */ |
| 3865 | |
| 3866 | |
| 3867 | |
| 3868 | /***************************************************************************** |
| 3869 | * FUNCTION |
| 3870 | * nvram_report_last_exception |
| 3871 | * DESCRIPTION |
| 3872 | * |
| 3873 | * PARAMETERS |
| 3874 | * task_name_p [?] |
| 3875 | * type_p [?] |
| 3876 | * time_p [?] |
| 3877 | * status_p [?] |
| 3878 | * RETURNS |
| 3879 | * void |
| 3880 | *****************************************************************************/ |
| 3881 | void nvram_report_last_exception(void *task_name_p, void *type_p, void *time_p, void *status_p) |
| 3882 | { |
| 3883 | } |
| 3884 | |
| 3885 | /***************************************************************************** |
| 3886 | * FUNCTION |
| 3887 | * nvram_create_first_bootup_name |
| 3888 | * DESCRIPTION |
| 3889 | * |
| 3890 | * PARAMETERS |
| 3891 | * void |
| 3892 | * RETURNS |
| 3893 | * void |
| 3894 | *****************************************************************************/ |
| 3895 | void nvram_create_first_bootup_name(kal_char *prefix, kal_wchar* filename) |
| 3896 | { |
| 3897 | /*----------------------------------------------------------------*/ |
| 3898 | /* Local Variables */ |
| 3899 | /*----------------------------------------------------------------*/ |
| 3900 | kal_uint8 *working_buffer = (kal_uint8*) get_ctrl_buffer(32); |
| 3901 | |
| 3902 | /*----------------------------------------------------------------*/ |
| 3903 | /* Code Body */ |
| 3904 | /*----------------------------------------------------------------*/ |
| 3905 | memset(working_buffer, 0, 32); |
| 3906 | strncpy((kal_char*)working_buffer, release_verno(), 32); |
| 3907 | #ifdef __NVRAM_BIND_TO_CHIP_CIPHER__ |
| 3908 | SST_Secure_Algo(NVRAM_MSP_ENCRYPT, (kal_uint32)working_buffer, 32, nvram_ptr->secret_key, (kal_uint8*)working_buffer); |
| 3909 | #else |
| 3910 | //custom_nvram_encrypt(nvram_ptr->secret_key, (unsigned char *)working_buffer, 32, 0); |
| 3911 | nvram_AES_encrypt((unsigned char *)working_buffer, 32); |
| 3912 | #endif |
| 3913 | kal_wsprintf(filename, "Z:\\%s%02X%02X%02X%02X.log", prefix, working_buffer[4], working_buffer[5], working_buffer[6], working_buffer[7]); |
| 3914 | |
| 3915 | free_ctrl_buffer(working_buffer); |
| 3916 | } |
| 3917 | |
| 3918 | /***************************************************************************** |
| 3919 | * FUNCTION |
| 3920 | * nvram_create_first_bootup_file |
| 3921 | * DESCRIPTION |
| 3922 | * |
| 3923 | * PARAMETERS |
| 3924 | * void |
| 3925 | * RETURNS |
| 3926 | * void |
| 3927 | *****************************************************************************/ |
| 3928 | void nvram_create_first_bootup_log(kal_char *prefix) |
| 3929 | { |
| 3930 | /*----------------------------------------------------------------*/ |
| 3931 | /* Local Variables */ |
| 3932 | /*----------------------------------------------------------------*/ |
| 3933 | kal_wchar filename[NVRAM_MAX_PATH_LEN]; |
| 3934 | kal_int32 result = FS_NO_ERROR; |
| 3935 | FS_HANDLE handle; |
| 3936 | /*----------------------------------------------------------------*/ |
| 3937 | /* Code Body */ |
| 3938 | /*----------------------------------------------------------------*/ |
| 3939 | |
| 3940 | nvram_create_first_bootup_name(prefix, filename); |
| 3941 | NVRAM_FS_START_EX(FS_OP_OPEN,filename); |
| 3942 | handle = FS_Open(filename, FS_READ_WRITE | FS_CREATE_ALWAYS); |
| 3943 | NVRAM_FS_END(FS_OP_OPEN,handle); |
| 3944 | NVRAM_FS_START(FS_OP_CLOSE); |
| 3945 | result = FS_Close(handle); |
| 3946 | NVRAM_FS_END(FS_OP_CLOSE,result); |
| 3947 | } |
| 3948 | |
| 3949 | /***************************************************************************** |
| 3950 | * FUNCTION |
| 3951 | * nvram_check_first_bootup_log |
| 3952 | * DESCRIPTION |
| 3953 | * |
| 3954 | * PARAMETERS |
| 3955 | * void |
| 3956 | * RETURNS |
| 3957 | * void |
| 3958 | *****************************************************************************/ |
| 3959 | kal_bool nvram_check_first_bootup_log(kal_char *prefix) |
| 3960 | { |
| 3961 | /*----------------------------------------------------------------*/ |
| 3962 | /* Local Variables */ |
| 3963 | /*----------------------------------------------------------------*/ |
| 3964 | kal_wchar filename[NVRAM_MAX_PATH_LEN]; |
| 3965 | kal_int32 result = FS_NO_ERROR; |
| 3966 | /*----------------------------------------------------------------*/ |
| 3967 | /* Code Body */ |
| 3968 | /*----------------------------------------------------------------*/ |
| 3969 | |
| 3970 | nvram_create_first_bootup_name(prefix, filename); |
| 3971 | NVRAM_FS_START_EX(FS_OP_GETATTRIBUTES,filename); |
| 3972 | result = FS_GetAttributes(filename); |
| 3973 | NVRAM_FS_END(FS_OP_GETATTRIBUTES,result); |
| 3974 | if (result >= FS_NO_ERROR) |
| 3975 | { |
| 3976 | return KAL_TRUE; |
| 3977 | } |
| 3978 | else |
| 3979 | { |
| 3980 | return KAL_FALSE; |
| 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | /***************************************************************************** |
| 3985 | * FUNCTION |
| 3986 | * nvram_delete_first_bootup_log |
| 3987 | * DESCRIPTION |
| 3988 | * |
| 3989 | * PARAMETERS |
| 3990 | * void |
| 3991 | * RETURNS |
| 3992 | * void |
| 3993 | *****************************************************************************/ |
| 3994 | void nvram_delete_first_bootup_log(kal_char *prefix) |
| 3995 | { |
| 3996 | /*----------------------------------------------------------------*/ |
| 3997 | /* Local Variables */ |
| 3998 | /*----------------------------------------------------------------*/ |
| 3999 | kal_wchar filename[NVRAM_MAX_PATH_LEN]; |
| 4000 | kal_int32 result = FS_NO_ERROR; |
| 4001 | /*----------------------------------------------------------------*/ |
| 4002 | /* Code Body */ |
| 4003 | /*----------------------------------------------------------------*/ |
| 4004 | nvram_create_first_bootup_name(prefix, filename); |
| 4005 | NVRAM_FS_START_EX(FS_OP_DELETE,filename); |
| 4006 | result = FS_Delete(filename); |
| 4007 | NVRAM_FS_END(FS_OP_DELETE,result); |
| 4008 | } |
| 4009 | |
| 4010 | #ifdef __NVRAM_SECURE_DATA_STORAGE__ |
| 4011 | |
| 4012 | /***************************************************************************** |
| 4013 | * FUNCTION |
| 4014 | * nvram_access_sds |
| 4015 | * DESCRIPTION |
| 4016 | * PARAMETERS |
| 4017 | * RETURNS |
| 4018 | *****************************************************************************/ |
| 4019 | kal_int32 nvram_access_sds(nvram_sds_access_enum access_mode) |
| 4020 | { |
| 4021 | /*----------------------------------------------------------------*/ |
| 4022 | /* Local Variables */ |
| 4023 | /*----------------------------------------------------------------*/ |
| 4024 | /*----------------------------------------------------------------*/ |
| 4025 | /* Code Body */ |
| 4026 | /*----------------------------------------------------------------*/ |
| 4027 | |
| 4028 | |
| 4029 | nvram_errno_enum result = NVRAM_ERRNO_SUCCESS; |
| 4030 | |
| 4031 | if (access_mode == NVRAM_SDS_ACCESS_BACKUP) |
| 4032 | { |
| 4033 | result = nvram_sds_backup(); |
| 4034 | } |
| 4035 | else |
| 4036 | { |
| 4037 | result = nvram_sds_restore(); |
| 4038 | } |
| 4039 | |
| 4040 | |
| 4041 | return result; |
| 4042 | } |
| 4043 | #endif |