Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 # | 2 # |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 # | 6 # |
| 7 # For factory and auto update, after shell-ball self-extracts, this script is | 7 # For factory and auto update, after shell-ball self-extracts, this script is |
| 8 # called to update BIOS and EC firmware as per how many files are extracted. | 8 # called to update BIOS and EC firmware as per how many files are extracted. |
| 9 # To simply design, THIS SCRIPT MUST BE EXECUTED IN A R/W EXCLUSIVE TEMP FOLDER. | 9 # To simply design, THIS SCRIPT MUST BE EXECUTED IN A R/W EXCLUSIVE TEMP FOLDER. |
| 10 # AND ALL FILENAMES FOR INPUT AND OUTPUT MUST NOT CONTAIN SPACE. | 10 # AND ALL FILENAMES FOR INPUT AND OUTPUT MUST NOT CONTAIN SPACE. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 # Customization Section | 26 # Customization Section |
| 27 | 27 |
| 28 # Customization script file name - do not change this. | 28 # Customization script file name - do not change this. |
| 29 # You have to create a file with this name to put your customization. | 29 # You have to create a file with this name to put your customization. |
| 30 CUSTOMIZATION_SCRIPT="updater_custom.sh" | 30 CUSTOMIZATION_SCRIPT="updater_custom.sh" |
| 31 | 31 |
| 32 # Customization script main entry - do not change this. | 32 # Customization script main entry - do not change this. |
| 33 # You have to define a function with this name to run your customization. | 33 # You have to define a function with this name to run your customization. |
| 34 CUSTOMIZATION_MAIN="updater_custom_main" | 34 CUSTOMIZATION_MAIN="updater_custom_main" |
| 35 | 35 |
| 36 # Customization script "compatibility check" function. | |
| 37 # Overrides this with any function names to test if current system is compatible | |
| 38 # with this updater. | |
| 39 # Returns $FLAGS_FALSE if not compatible (i.e., need incompatible_mode) | |
| 40 CUSTOMIZATION_COMPATIBILITY_CHECK="" | |
| 41 | |
| 36 # Override this with the name with RO_FWID prefix. | 42 # Override this with the name with RO_FWID prefix. |
| 37 # Updater will stop and give error if the platform does not match. | 43 # Updater will stop and give error if the platform does not match. |
| 38 TARGET_PLATFORM="" | 44 TARGET_PLATFORM="" |
| 39 | 45 |
| 40 # ---------------------------------------------------------------------------- | 46 # ---------------------------------------------------------------------------- |
| 41 # Constants | 47 # Constants |
| 42 | 48 |
| 43 # Slot names defined by ChromeOS Firmware Specification | 49 # Slot names defined by ChromeOS Firmware Specification |
| 44 SLOT_A="RW_SECTION_A" | 50 SLOT_A="RW_SECTION_A" |
| 45 SLOT_B="RW_SECTION_B" | 51 SLOT_B="RW_SECTION_B" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 71 HWID="$(crossystem hwid 2>/dev/null || true)" | 77 HWID="$(crossystem hwid 2>/dev/null || true)" |
| 72 FWID="$(crossystem fwid 2>/dev/null || true)" | 78 FWID="$(crossystem fwid 2>/dev/null || true)" |
| 73 PLATFORM="$(crossystem ro_fwid 2>/dev/null | sed 's/\..*//' || true)" | 79 PLATFORM="$(crossystem ro_fwid 2>/dev/null | sed 's/\..*//' || true)" |
| 74 [ -n "$PLATFORM" ] || PLATFORM="<Unknown>" | 80 [ -n "$PLATFORM" ] || PLATFORM="<Unknown>" |
| 75 | 81 |
| 76 # ---------------------------------------------------------------------------- | 82 # ---------------------------------------------------------------------------- |
| 77 # Parameters | 83 # Parameters |
| 78 | 84 |
| 79 DEFINE_string mode "" \ | 85 DEFINE_string mode "" \ |
| 80 "Updater mode ( startup | bootok | autoupdate | todev | recovery |"\ | 86 "Updater mode ( startup | bootok | autoupdate | todev | recovery |"\ |
| 81 " factory_install | factory_final )" "m" | 87 " factory_install | factory_final | incompatible_update )" "m" |
|
Randall Spangler
2011/04/05 16:42:38
Why are we adding a new mode?
Hung-Te
2011/04/06 02:02:51
Since an incompatible RW update needs different lo
| |
| 82 DEFINE_boolean debug $FLAGS_FALSE "Enable debug messages." "d" | 88 DEFINE_boolean debug $FLAGS_FALSE "Enable debug messages." "d" |
| 83 DEFINE_boolean verbose $FLAGS_TRUE "Enable verbose messages." "v" | 89 DEFINE_boolean verbose $FLAGS_TRUE "Enable verbose messages." "v" |
| 84 DEFINE_boolean dry_run $FLAGS_FALSE "Enable dry-run mode." "" | 90 DEFINE_boolean dry_run $FLAGS_FALSE "Enable dry-run mode." "" |
| 85 | 91 |
| 86 DEFINE_boolean update_ec $FLAGS_TRUE "Enable updating for Embedded Firmware." "" | 92 DEFINE_boolean update_ec $FLAGS_TRUE "Enable updating for Embedded Firmware." "" |
| 87 DEFINE_boolean update_main $FLAGS_TRUE "Enable updating for Main Firmware." "" | 93 DEFINE_boolean update_main $FLAGS_TRUE "Enable updating for Main Firmware." "" |
| 88 | 94 |
| 89 # RO update flags are usually enabled only in customization. | 95 # RO update flags are usually enabled only in customization. |
| 90 DEFINE_boolean update_ro_main $FLAGS_FALSE \ | 96 DEFINE_boolean update_ro_main $FLAGS_FALSE \ |
| 91 "Allow updating RO section of Main Firmware" | 97 "Allow updating RO section of Main Firmware" |
| 92 DEFINE_boolean update_ro_ec $FLAGS_FALSE \ | 98 DEFINE_boolean update_ro_ec $FLAGS_FALSE \ |
| 93 "Allow updating RO section of EC Firmware" | 99 "Allow updating RO section of EC Firmware" |
| 94 | 100 |
| 95 DEFINE_boolean check_keys $FLAGS_TRUE "Check firmware keys before updating." "" | 101 DEFINE_boolean check_keys $FLAGS_TRUE "Check firmware keys before updating." "" |
| 96 DEFINE_boolean check_wp $FLAGS_TRUE \ | 102 DEFINE_boolean check_wp $FLAGS_TRUE \ |
| 97 "Check if write protection is enabled before updating RO sections" "" | 103 "Check if write protection is enabled before updating RO sections" "" |
| 104 DEFINE_boolean check_incompatible $FLAGS_TRUE \ | |
| 105 "Check if an incompatible update should be triggered or scheduled" "" | |
|
Randall Spangler
2011/04/05 16:42:38
This sounds confusing. Why would we ever trigger
Hung-Te
2011/04/06 02:02:51
Done.
| |
| 98 DEFINE_boolean check_devfw $FLAGS_TRUE \ | 106 DEFINE_boolean check_devfw $FLAGS_TRUE \ |
| 99 "Check if developer firmware is activated and bypass updates" "" | 107 "Bypass firmware updates if active firmware type is developer" "" |
| 100 | |
| 101 # Required for factory compatibility | 108 # Required for factory compatibility |
| 102 DEFINE_boolean factory $FLAGS_FALSE "Equivalent to --mode=factory_install" | 109 DEFINE_boolean factory $FLAGS_FALSE "Equivalent to --mode=factory_install" |
| 103 | 110 |
| 104 # ---------------------------------------------------------------------------- | 111 # ---------------------------------------------------------------------------- |
| 105 # General Updater | 112 # General Updater |
| 106 | 113 |
| 107 # Update Main Firmware (BIOS, SPI) | 114 # Update Main Firmware (BIOS, SPI) |
| 108 update_mainfw() { | 115 update_mainfw() { |
| 109 # Syntax: update_mainfw SLOT FIRMWARE_SOURCE_TYPE | 116 # Syntax: update_mainfw SLOT FIRMWARE_SOURCE_TYPE |
| 110 # Write assigned type (normal/developer) of firmware source into | 117 # Write assigned type (normal/developer) of firmware source into |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 fi | 547 fi |
| 541 fi | 548 fi |
| 542 if [ "${FLAGS_update_ec}" = "${FLAGS_TRUE}" ]; then | 549 if [ "${FLAGS_update_ec}" = "${FLAGS_TRUE}" ]; then |
| 543 update_ecfw | 550 update_ecfw |
| 544 fi | 551 fi |
| 545 } | 552 } |
| 546 | 553 |
| 547 # ---------------------------------------------------------------------------- | 554 # ---------------------------------------------------------------------------- |
| 548 # Main Entry | 555 # Main Entry |
| 549 | 556 |
| 557 main_check_compatibility() { | |
| 558 local try_autoupdate="$1" | |
| 559 if [ "${FLAGS_check_incompatible}" = "${FLAGS_FALSE}" ]; then | |
| 560 verbose_msg "Bypassed compatbility check. You're on your own." | |
| 561 return $FLAGS_TRUE | |
| 562 fi | |
| 563 | |
| 564 if [ -n "$CUSTOMIZATION_COMPATIBILITY_CHECK" ]; then | |
| 565 debug_msg "No compatibility check rules defined in customization." | |
| 566 return $FLAGS_TRUE | |
| 567 fi | |
| 568 | |
| 569 local is_compatible="${FLAGS_TRUE}" | |
| 570 "$CUSTOMIZATION_COMPATIBILITY_CHECK" || is_compatible="${FLAGS_FALSE}" | |
| 571 if [ "$is_compatible" = "${FLAGS_TRUE}" ]; then | |
| 572 return $FLAGS_TRUE | |
| 573 fi | |
| 574 | |
| 575 verbose_msg "Incompatible firmware detected. Need incompatible mode update." | |
|
Randall Spangler
2011/04/05 16:42:38
RW firmware update is not compatible with current
Hung-Te
2011/04/06 02:02:51
Done.
| |
| 576 | |
| 577 if [ "$try_autoupdate" = "$FLAGS_FALSE" ]; then | |
| 578 # No need to print anything in this case. | |
| 579 return $FLAGS_FALSE | |
| 580 fi | |
| 581 | |
| 582 if is_developer_firmware; then | |
| 583 try_autoupdate=$FLAGS_FALSE | |
| 584 verbose_msg "Developer firmware detected - not scheduling auto updates." | |
| 585 else | |
| 586 # Try to schedule an autoupdate. | |
| 587 (cros_set_startup_update_tries 6) || try_autoupdate="${FLAGS_FALSE}" | |
| 588 fi | |
| 589 | |
| 590 alert_incompatible_firmware "$try_autoupdate" | |
| 591 return $FLAGS_FALSE | |
| 592 } | |
| 593 | |
| 550 main() { | 594 main() { |
| 551 if [ -r /tmp/chromeos-firmwareupdate-running ]; then | 595 if [ -r /tmp/chromeos-firmwareupdate-running ]; then |
| 552 err_die "chromeos-firmwareupdate is already running. Please retry later." | 596 err_die "chromeos-firmwareupdate is already running. Please retry later." |
| 553 fi | 597 fi |
| 554 touch /tmp/chromeos-firmwareupdate-running | 598 touch /tmp/chromeos-firmwareupdate-running |
| 555 | 599 |
| 556 # Clean up on regular or error exits. | 600 # Clean up on regular or error exits. |
| 557 trap drop_lock EXIT | 601 trap drop_lock EXIT |
| 558 | 602 |
| 559 # factory compatibility | 603 # factory compatibility |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 588 alert_unknown_platform "$PLATFORM" "$TARGET_PLATFORM" | 632 alert_unknown_platform "$PLATFORM" "$TARGET_PLATFORM" |
| 589 exit 1 | 633 exit 1 |
| 590 fi | 634 fi |
| 591 | 635 |
| 592 # invoke customization | 636 # invoke customization |
| 593 debug_msg "starting customized updater main..." | 637 debug_msg "starting customized updater main..." |
| 594 $CUSTOMIZATION_MAIN | 638 $CUSTOMIZATION_MAIN |
| 595 fi | 639 fi |
| 596 | 640 |
| 597 case "${FLAGS_mode}" in | 641 case "${FLAGS_mode}" in |
| 598 startup | bootok | autoupdate | todev | recovery | \ | 642 # Modes that are allowed to trigger incompatible mode updates |
|
Randall Spangler
2011/04/05 16:42:38
Modes which can attempt to update RO if RO+RW are
Hung-Te
2011/04/06 02:02:51
Done.
| |
| 599 incompatible_update | factory_install | factory_final ) | 643 startup | recovery ) |
| 600 debug_msg "mode: ${FLAGS_mode}" | 644 debug_msg "mode allowing compatibility update: ${FLAGS_mode}" |
| 645 if main_check_compatibility $FLAGS_FALSE; then | |
| 646 mode_"${FLAGS_mode}" | |
| 647 else | |
| 648 verbose_msg "Starting an incompatible mode update..." | |
| 649 mode_incompatible_update | |
| 650 fi | |
| 651 ;; | |
| 652 # Modes with incompatible checks | |
|
Randall Spangler
2011/04/05 16:42:38
Modes which update RW firmware only; these need to
Hung-Te
2011/04/06 02:02:51
Done.
| |
| 653 autoupdate | bootok | todev ) | |
| 654 debug_msg "mode with compatibility check: ${FLAGS_mode}" | |
| 655 if main_check_compatibility $FLAGS_TRUE; then | |
| 656 mode_"${FLAGS_mode}" | |
| 657 fi | |
| 658 ;; | |
| 659 # Modes without incompatible checks | |
|
Randall Spangler
2011/04/05 16:42:38
Modes which don't mix existing RO firmware with ne
Hung-Te
2011/04/06 02:02:51
Done.
| |
| 660 factory_install | factory_final | incompatible_update ) | |
| 661 debug_msg "mode without incompatible checks: ${FLAGS_mode}" | |
| 601 mode_"${FLAGS_mode}" | 662 mode_"${FLAGS_mode}" |
| 602 ;; | 663 ;; |
| 603 "" ) | 664 "" ) |
| 604 err_die "Please assign updater mode by --mode option." | 665 err_die "Please assign updater mode by --mode option." |
| 605 ;; | 666 ;; |
| 606 * ) | 667 * ) |
| 607 err_die "Unknown mode: ${FLAGS_mode}" | 668 err_die "Unknown mode: ${FLAGS_mode}" |
| 608 ;; | 669 ;; |
| 609 esac | 670 esac |
| 610 verbose_msg "Firmware update (${FLAGS_mode}) completed." | 671 verbose_msg "Firmware update (${FLAGS_mode}) completed." |
| 611 } | 672 } |
| 612 | 673 |
| 613 # Parse command line | 674 # Parse command line |
| 614 FLAGS "$@" || exit 1 | 675 FLAGS "$@" || exit 1 |
| 615 eval set -- "$FLAGS_ARGV" | 676 eval set -- "$FLAGS_ARGV" |
| 616 | 677 |
| 617 # Exit on error | 678 # Exit on error |
| 618 set -e | 679 set -e |
| 619 | 680 |
| 620 # Main Entry | 681 # Main Entry |
| 621 main | 682 main |
| OLD | NEW |