summaryrefslogtreecommitdiff
path: root/futility
Commit message (Collapse)AuthorAgeFilesLines
* futility: updater: Revise error message when model is not defined in manifeststabilize-11306.BHung-Te Lin2018-11-271-2/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | "Model '%s' is not defined in manifest." is not very easy to understand for people who are debugging devices in early stages. We should provide better instructions. For example, running with Coral updater will now show: ERROR: manifest_find_model: Cannot get model name. You are probably running an image for wrong board, or a device in early stage that 'mosys' command is not ready, or image from old (or factory) branches that Unified Build config is not updated yet for 'mosys'. Please check command 'mosys platform model', which should output one of the supported models below: unprovisioned_meep sparky orbatrix unprovisioned_fleex grabbiter bobba unprovisioned_bobba mimrock fleex meep yorp phaser360 sparky360 phaser bobba360 unprovisioned_phaser bip BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ib17fcb654d1530b94c44cf21aaa28717841f11ed Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1351171 Reviewed-by: Cheng-Han Yang <chenghan@chromium.org> Reviewed-by: Ting Shen <phoenixshen@chromium.org>
* futility: updater: Revise output messages for debug logsHung-Te Lin2018-11-245-51/+54
| | | | | | | | | | | | | | | | | | | | | | | | In auto update and recovery, the firmware updater was executed with both stdout and stderr logged. However, the logs usually comes with all stderr first then all stdout. This makes it harder to debug because the messages logged in out of order. TO solve that, few macros are introduced: INFO: for useful information. STATUS: the most common information, usually comes with a prefix code. And all messages should now go to stderr except the final execution result (and those output commands, for example --manifest). BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility CQ-DEPEND=CL:1345250 BRANCH=None Change-Id: Ie0dc6594ece10e7e15caf9c36353e2b3ec8754c5 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1345611 Reviewed-by: Youcheng Syu <youcheng@chromium.org>
* futility: updater: Add new quirk 'allow_empty_wltag'Hung-Te Lin2018-11-243-6/+29
| | | | | | | | | | | | | | | There were devices shipped as "only device" (no key set) and then became one of the "white label" family. This is now no longer valid on newer devices but we have to support the legacy ones, for example Reks. BUG=chromium:906962 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I437be08726ab2c46229062689bf765ac6837ca5d Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1345610 Reviewed-by: Youcheng Syu <youcheng@chromium.org>
* futility: updater: Load quirks immediately after host image is loadedHung-Te Lin2018-11-241-13/+32
| | | | | | | | | | | | | | | There may be quirks needed during image archive setup (for example loading white label tags) so we have to move quirks setup to some earlier place. BUG=chromium:906962 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I1f6eddb0119c64098df75bad72809ba8366625c7 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1345609 Reviewed-by: Youcheng Syu <youcheng@chromium.org>
* futility: updater: Need --force when re-keying to DEV keysHung-Te Lin2018-11-191-13/+47
| | | | | | | | | | | | | | | | | | | For dogfood devices, we usually will only re-key from DEV to PreMP, and then PreMP to MP. It was found that for retail devices, if WP was disabled (unintended), user may accidentally re-key to DEV keys if they (1) recover with a DEV-signed image, or (2) received an AU that didn't have right signing keys. As a result, we want to make it harder when recovering to DEV keys. BUG=chromium:894324 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Id3f7788e6c86d12b6e37b77818a1b4c2ceda1e2f Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1312596 Reviewed-by: Mike Frysinger <vapier@chromium.org>
* futility: updater: Check EC/PD WP state again before updatingHung-Te Lin2018-11-141-6/+25
| | | | | | | | | | | | | | | | | | | | | | | There are devices, especially during or after RMA, may have WP states not synced; for example HW = 1 SW (AP) = 0 SW (EC) = 1 In this case, we can still update host firmware but not EC. This happens more often on EC that needs an extra reboot to change WP states. As a result, we do want to check real programmer again before updating optional images. BUG=chromium:902546 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I9a526cde19a1ab3c41afecb4f7247bd941edc3f4 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1322295 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: update: Strip \xFF from version stringHung-Te Lin2018-11-071-6/+17
| | | | | | | | | | | | | | | If some system that firmware RW sections were damaged, the firmware string may become '\xFF' (flash erased content). We do not want to see that as version string, and this will help FAFT testing. BUG=chromium:899901 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I947ec3c8286a022163abf01ae1d8ab5747aacf08 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1317050 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Add more legacy optionsHung-Te Lin2018-11-041-0/+10
| | | | | | | | | | | | | | | | | | To simplify the migration plan, we want to support the legacy arguments used by FAFT: --noupdate_ec => --host_only --noupdate_pd => --host_only --nocheck_keys => --force --update_main => ignore BUG=chromium:882445,b:118509893 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I31652806085937fe5ca2f2facc7321021977cbb7 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1310253 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Fix model detection errorHung-Te Lin2018-10-291-1/+1
| | | | | | | | | | | | | | | In mosys, $(mosys platform name) currently returns the board (family) name while the real model name needs $(mosys platform model). BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ie3355ca94d577e88a2140567b9284da40c0b39c5 Reviewed-on: https://chromium-review.googlesource.com/1301013 Commit-Ready: Hung-Te Lin <hungte@chromium.org> Tested-by: Hung-Te Lin <hungte@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Support --repack and --unpackHung-Te Lin2018-10-244-16/+182
| | | | | | | | | | | | | | | | In order to make the firmware updater package more consistent file contents (for example, we don't want time stamps, and better if the files are always physically located in same order) we want to create and manipulate the ZIP based package directly using updater. BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ie4c5aafe51f633729de2879c73bf7074a695151f Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1286173 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
* futility: Preserve programmer in free_firmware_imageHung-Te Lin2018-10-232-3/+9
| | | | | | | | | | | | | | | | | The `programmer` cannot be decided in `load_firmware_image` and is always specified (and managed) by an outer context, and should be preserved even when we call `free_firmware_image`. This helps reloading or removing loaded images at runtime. BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I22f698d4a7118197379e11556b18f70ecd023ca2 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1295209 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: update: Add `--host_only` argumentHung-Te Lin2018-10-233-4/+12
| | | | | | | | | | | | | | | | | | | | | | | The legacy firmware updater can update explicitly only some type of images by using `--[no]update_main`, `--[no]update_ec`, `--[no]update_pd`. Since software sync is introduced, usually it does not make sense to only update EC or PD; instead the real request is to "ignore provided EC and PD images and update only host". The new `--host_only` argument provides an easy way to ignore images in command line (`--ec_image`, `--pd_image`) and archives (`ec.bin`, `pd.bin`). BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Idf403680880cd58a00867172ccec97fd60c1b826 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1295210 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Support --mode=output and --output_dirHung-Te Lin2018-10-223-0/+42
| | | | | | | | | | | | | | For backward compatibility, we need to support the 'output' mode in legacy firmware updater. The output must select right files according to system model, and apply all white label transform if needed. BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ib433647317fa97387aa4a7f8f2101b47e6ca2123 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1282084
* futility: updater: Support white label from VPD and --signature_idHung-Te Lin2018-10-224-10/+164
| | | | | | | | | | | | | | | | | | | | For white label devices, we have to select and patch key files (root key and vblock) by VPD (`whitelabel_tag` or `customization_id`). The white label tag VPD will be processed and converted to a "signature ID" for key selection. To support that, updater has to fetch current (system) image if the matched model is following white label (so we can read VPD from it). For developers who want to load and use particular files, they can use --signature_id to override VPD values. BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I3630bae28d1a8493b56d0e5efd29f3c61a470379 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1278420
* futility: updater: Add '--model' and select images by system modelHung-Te Lin2018-10-224-27/+148
| | | | | | | | | | | | | | | | | For devices using Unified Build, we have to select and load images from archive by model configuration (setvars.sh). The system model can be retrieved by $(mosys platform model), but for developers who want to simulate or get images for particular platform, a command line argument --model is needed. BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I8f4a6735b34bc694a05808b001c7309623b2afa3 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1278419 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Do not preserve GBB flags in --factory mode.Hung-Te Lin2018-10-182-10/+14
| | | | | | | | | | | | | | | | | In RMA or factory reinstall flow, we will want to make sure device will next boot into developer mode, which was usually enforced by GBB flags. In updater4, this is done by updater using flags defined in target image. We should keep same behavior. BUG=b:117866155 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Idb6337d453d606dbf88b2a2b82961f21125b7fef Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1288211 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Change default model name to FWID platform nameHung-Te Lin2018-10-181-1/+28
| | | | | | | | | | | | | | | | | | | | | For devices not using Unified Build, the firmware updater may contain a single set of firmware images. To make the manifest more consistent for both cases (Unified Build or not), we want to change to model name to be the platform name from FWID if available. This does not make sense because for these devices, usually platform = board = model, and it helps to make sure programs parsing manifest won't try to use the hard coded name 'default' (which does not always work in Unified Build). BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I6d56336f3b30981e3e936fa63dec7dd45d74b31a Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1278418 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Allow patching rootkey and vblock filesHung-Te Lin2018-10-153-10/+206
| | | | | | | | | | | | | | | | | | | | | For white label projects, the firmware updater has to select correct root key and corresponding vblock files per different LOEM. In Unified build, multiple models may share same firmware base image, with different key files (per OEM). As a result, we have to apply the key files before using the firmware image files. This change adds the "patch" information when building manifest, and prints the correct key hash in `--manifest` mode. BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ib5e31af5262a0989a5a474d0683c83121f24cc78 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1270323 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Add --manifest to scan and print archive infoHung-Te Lin2018-10-134-5/+336
| | | | | | | | | | | | | | | | | | | | | | | The firmware updater packages used to rely on a pre-generated VERSION file to report what files were included and their image versions. Its format was hard to parse, and may be out-dated if people repack without updating VERSION file. The firmware updater today has the ability to read and parse version, key hash, ... etc everything we need, so it seems more reasonable to just let firmware updater scan updater package and print the information in JSON format, so it will be very easy to fetch latest information. To make sure the output is purely JSON, the start and end messages are now sent to stderr instead of stdout. BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ifa468fbb3adf798c7931f015258e6c6ce93de993 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1260804
* futility: updater: Refactor how arguments were configuredHung-Te Lin2018-10-133-125/+118
| | | | | | | | | | | | | | | | | | We are going to have more command line arguments that must be passed to updater_setup_config, and it is better to manage so many variables in a struct. Also, revised the order or argument processing so that simple settings are now processed first, then complicated ones or those with dependency. BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I03ac036d26e49cdf924c03d6e86a272ce89fc2aa Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1265575 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Add '--archive' to read from an archive or directoryHung-Te Lin2018-10-135-18/+398
| | | | | | | | | | | | | | | | | | | | | | A firmware update is usually released as a package with multiple images, instructions, signed vblocks and other files. To work with that, a new argument '--archive' is added. The --archive accepts a directory or file, and will determine the correct driver automatically. For resources (for example --image) in relative path, updater should find files from archive. Note in current implementation, only ZIP is supported for file type drivers (and need the system to have libzip already installed). BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I6a91cbe73fb4ee203c5fa4607f6651a39ba854d5 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1253229 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Refactor function namesHung-Te Lin2018-10-133-36/+37
| | | | | | | | | | | | | | | | | | | | | | | No real function changes. For incoming changes, we want to rename the shared functions to make it more clear (and more consistent) in hot it was used, including: - load_image: should be load_firmware_image(image, filename) - free_image: should be free_firmware_image - reload_image: should be reload_firmware_image - load_system_image: should be load_system_firmware - create_temp_file: should be updater_create_temp_file to make it more clear it is created for updater (and deleted when updater has finished) BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I120e30b5a4c40ccce03e5f361734f2583476703a Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1270322 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Add ASPRINTF macroHung-Te Lin2018-10-133-30/+18
| | | | | | | | | | | | | | | | | | | | When calling `asprintf`, if the return value is negative value then the strp parameter is not allocated. Updater will need to call asprintf very often in future, and we should abort immediately if asprintf can't allocate buffer, since that implies either we are running out of memory, or the system has gone very wrong. Instead of writing if (asprintf(...) < 0) { ERROR(); return...} everywhere, it seems easier to just add a macro and abort as exit(1). BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I8ea5f6c22dcc8225bc53fbd54b4b41a928f84910 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1260803 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Revise verbosity and error messagesHung-Te Lin2018-10-024-19/+44
| | | | | | | | | | | | | | | | | | | | | | `futility` used to print debug messages to stdout, but there is a side effect that stdout may be buffered and then flush later than stderr. For example, when calling futility via ssh, we will see flashrom messages before any of futility's own messages. Also, many people want to get flashrom verbose messages (-V). With this change, when calling ERROR and DEBUG, we will always output to stderr. This also enables better parameter type checking. `-d` and `-v` both contribute to verbosity, that will be converted to -V's when calling flashrom. BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I1d22a8054fc43cdc5e6c7415e131cc9826fbff0c Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1251145
* futility: updater: Support reading main image from stdinHung-Te Lin2018-10-021-1/+30
| | | | | | | | | | | | | | | | | | "Can we make futility support stdin like flashrom? I typically flash with: ssh root@DUT flashrom -p host - < foo.bin" Yes we can: ssh root@DUT futility update -i - < foo.bin BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ib1ee5d4c882620e3b6f56fd5e4692b4829cf025a Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1251141 Reviewed-by: Raul E Rangel <rrangel@chromium.org>
* futility: updater: Preserve SMMSTORE and add quirk 'eve_smm_store'Hung-Te Lin2018-10-023-0/+92
| | | | | | | | | | | | | | | | | The 'SMM store' must be preserved during firmware update. On newer systems, this can be done by preserving FMAP section 'SMMSTORE' (CL:1221210). For Eve, the SMM store did not have its own FMAP section and needs to be reserved by explicit cbfstool calls. BRANCH=None BUG=b:70682365 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility Change-Id: Ica043f51de0170b5c40f61d059437b9572025e2e Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1250464 Reviewed-by: Joel Kitching <kitching@chromium.org>
* futility: updater: Add quirk 'daisy_snow_dual_model' for daisy_snowHung-Te Lin2018-10-023-7/+117
| | | | | | | | | | | | | | | | | | | | | | The target AUE for daisy_snow is 74 or even longer, so we need to get a better solution to get rid of script based updater customization (and the painful EXTRA list in updater configuration). The new quirk 'daisy_snow_dual_model' is assuming the input firmware image has both daisy_snow x8 and x16 firmware packed into a single image (because in vboot1, RW_A is identical to RW_B), and will modify A/B contents according to target system. BRANCH=None BUG=chromium:881034 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility # Provide a fake mosys and output both MP / MPx16 to: futility update -i bios-snow-2695.132.117-rw.bin \ --quirks daisy_snow_dual_model --emu emu.bin --sys_props 0,0x0000,0 Change-Id: I8af1b6c3117a703aed4da59902aaecb1009101f2 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1239798
* futility: updater: Add default quirksHung-Te Lin2018-10-023-2/+64
| | | | | | | | | | | | | | | | | | For people running updater directly without the packaged firmware updater (chromeos-firmwareupdate), it is easier if we identify the quirks inside updater itself instead of the wrapper script. This change enables getting "default quirks" by target image RO version so we won't need to pack firmware images first. BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I179227f7a829577dc9fe5deb085fdee1a738c070 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1245663 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: updater: Refactor: move quirks to 'updater_quirks.c'Hung-Te Lin2018-10-023-202/+274
| | | | | | | | | | | | | There will be more and more board-specific quirks in future and we want to put them together into a special module. BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I4fd2ff5e2b2e891cbd3da8c9393c6fbdf7024c75 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1245645
* futility: updater: Refactor: localize temp files managementHung-Te Lin2018-10-023-20/+16
| | | | | | | | | | | | | | | The creation and deletion of temp files can be managed in same context where updater config lives. BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ic1745d27a071047d4882b21905bd11e15b5632cd Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1245644 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Joel Kitching <kitching@chromium.org>
* futility: updater: Refactor: move command line processing to cmd_update.cHung-Te Lin2018-10-023-249/+400
| | | | | | | | | | | | | | Move the do_update back to cmd_update with better initialization. The update.c now has few APIs to invoke the firmware updater without relying command line processing. BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I99f792bf902ed72e487242ac8872aec384783555 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1245643
* futility: update: Refactor: move updater logic to 'updater.c'Hung-Te Lin2018-09-271-0/+0
| | | | | | | | | | | | | | | | | | The updater is getting more complicated and we may want to split into few modules, for example "updater", "quirks", and "host". The first step is to change cmd_update.c to updater.c (to preserve most GIT history). BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Icae37db8720162130cf38767fec14a970cc9899d Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1245642 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Joel Kitching <kitching@chromium.org>
* futility: update: Add --programmer to override flashrom programmer for servoHung-Te Lin2018-09-271-7/+24
| | | | | | | | | | | | | | | | | | | | | | | | | Many developers need to reflash or update firmware using servo, and the firmware logic has been complicated enough that simply calling 'flashrom -w image.bin -p $SERVO' will usually destroy many important settings, for example HWID, VPD, and other data provisioned in factory. It should be more convenient if we can use 'futility update' against servo. The '--programmer' provides first step - to override the flashrom programmer so we can read and write via special programmer (like servo). With this change, developers can reflash using: futility -p $SERVO -i $IMAGE --force --wp 0 BRANCH=None BUG=b:116326638 TEST=make futil; sudo tests/futility/run_test_scripts.sh $(pwd)/build/futility Change-Id: Iad4819ff8258086e1abb58fefd462d94050754d0 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1239817 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: update: Refactor 'emulation' (--emulate).Hung-Te Lin2018-09-271-78/+23
| | | | | | | | | | | | | | | | | | | | | | | In order to support overriding programmer, we need to clean up the 'emulation' first. The firmware_image.emulation was implemented as a flashrom emulate programmer so we can emulate with calling flashrom in the very beginning; and then replaced by native FMAP library because calling flashrom add too much dependency and much slower in unit tests. As a result, we can replace emulation to be the real file name being emulated, and only keep that in the global config. BRANCH=None BUG=b:116326638 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility Change-Id: I5423e64d66be03a09ccfde29ecc3f4ef114c9453 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1239816 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: update: Revise error messagesHung-Te Lin2018-09-271-2/+2
| | | | | | | | | | | | | | | Error messages should be printed using ERROR when being outside the main updater function (do_update). BRANCH=None BUG=None TEST=make futil; sudo tests/futility/run_test_scripts.sh $(pwd)/build/futility Change-Id: I037c99b6e4fbb6a05fd95d64a87d187d8531da39 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1245641 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: update: Allow tpm_fwver=0 and allow --force to waive TPM checkHung-Te Lin2018-09-271-13/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | By b/116298359#comment3, we know the tpm_fwver may be zero if the firmware slot has been just created and no successful boots since last boot. This is very common for factory and recovery so we should consider 0 as "success". There is still possible in early or proto builds, the device may have vboot data structure changed so the updater calling vboot library cannot get tpm_fwver properly. Also for people who wants to re-key their devices with DEV firmware, we should allow waiving all TPM checks by --force. Also, in order to test that correctly, override_properties_from_list should accept negative values to simulate failure in getting tpm_fwver from VbGetSystemPropertyInt. BRANCH=None BUG=b:116298359 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility Change-Id: I09c91af36ceec340e393fb68999bea8d1907267d Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1239814 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: update: Preserve RW_ELOGHung-Te Lin2018-09-261-0/+2
| | | | | | | | | | | | | | The eventlog is stored in RW_ELOG and should not be destroyed during firmware update. BUG=chromium:655423 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I0b4fe1e78ae2d499e985471f51cfa9eb983c8adc Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1242663 Reviewed-by: Julius Werner <jwerner@chromium.org>
* futility: update: Preserve RO_FSGHung-Te Lin2018-09-261-0/+5
| | | | | | | | | | | | | | | | Cheza early proto devices have declared few sections that must be preserved before RO_PRESERVE is introduced, so we want to temporarily include them until the migration is completed. BUG=b:116326638 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ie8f397c000839ccfd475eab1d248843b23320465 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1239797 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Julius Werner <jwerner@chromium.org>
* futility: update: Preserve new sections: RO_PRESERVE and RW_PRESERVEHung-Te Lin2018-09-261-6/+26
| | | | | | | | | | | | | | | | | | | There may be more platforms that want to preserve some data in RO+RW firmware update. To prevent adding a huge list, we want to add new RO_PRESERVE and RW_PRESERVE so sections to be preserved can be simply defined as sub section of these and no more changes in updater side. RO_VPD, RW_VPD and RW_NVRAM are remain unchanged due to legacy. BUG=b:116326638 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I669e61aa75ab292fcee1a7b056af0e4d5fb14a7b Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1239815 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Julius Werner <jwerner@chromium.org>
* futility: update: Skip TPM check if tpm_fwver is not valid.stabilize-11101.BHung-Te Lin2018-09-211-6/+12
| | | | | | | | | | | | | | | | | | | Ideally we should fail if `tpm_fwver` can't be retrieved, but if an user can run the updater then his system is already up so it's more likely to be a vboot library issue (especially in early proto devices) that the crossystem values were not reported correctly. As a result, it seems more reasonable to skip checking TPM anti-rollback if `tpm_fwver` can't be retrieved. BRANCH=None BUG=b:115764295 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility Change-Id: I7b6bf72531edb334a465c730fe8b3fbafa469b3a Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1238099 Reviewed-by: Joel Kitching <kitching@chromium.org>
* futility: update: Add legacy option '--factory'Hung-Te Lin2018-09-191-5/+12
| | | | | | | | | | | | | | | The '--factory' is an alias to '--mode=factory_install' and was widely used in several documents. Also moved WP check to end of argument parsing so '--mode=factory --wp=0' can set WP correctly. BRANCH=None BUG=b:115764295 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility Change-Id: I7987d77c577414efb03941442e3125f35ac5ad98 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1233373 Reviewed-by: Joel Kitching <kitching@chromium.org>
* futility: update: Fix update failure in factory mode due to wrong WP logicHung-Te Lin2018-09-181-1/+1
| | | | | | | | | | | | | | In --mode=factory, we should fail if write protection is enabled. Also added an unit test for the case. BRANCH=None BUG=b:115764295 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility Change-Id: I6c693e470a034554b1f4a3cb16cfbf974ae6f54b Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1226587 Reviewed-by: Marco Chen <marcochen@chromium.org>
* futility: cmd_update: Add quirk 'min_platform_version'Hung-Te Lin2018-09-101-0/+49
| | | | | | | | | | | | | | | | | | | | Many device may have some minor difference in early builds, for example (board id) rev 0 and rev 1 may have GPIO pins connected to different components. Usually the firmware should read board identifier and do the right mapping, but sometimes the firmware may be totally incompatible and no way to workaround (for example even the CPU may be different). The min_platform_version is introduced so we can prevent updating to incompatible systems, by reading $(mosys platform version). BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I418fee1aad884551b38ac25c340b2797b8503596 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1198815 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: cmd_update: Add quirk 'unlock_me_for_update'Hung-Te Lin2018-09-101-4/+46
| | | | | | | | | | | | | | | | | | | | On recent Intel platforms, flashing to SI_ME may get corrupted due to ME execution in parallel. If we lock SI_ME immediately (by writing the new SI_DESC), the device may fail to boot due to ME execution failure. As a result, a quirk is added so the firmware updater will never lock SI_ME. The Flash Master values are always unlocked when updating SI_ME, and after system reboot, a board-postinst script should check ME status and reflash SI_DESC only if SI_ME looks all good. BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I584aa373797e2b4c2608f07aac21c16cdb34a5c4 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1198807 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: cmd_update: Add quirk 'enlarge_image'Hung-Te Lin2018-09-101-4/+67
| | | | | | | | | | | | | | | | | Some devices may have shipped with a smaller image that the real flash may be larger, especially if the device's original flash has been EOL'ed. The quirk 'enlarge_image' allows changing image size according to current_image size by padding 0xFF (flash default value). BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I84373cfa9bcbd98a2cd96a7dd4bed27a6f724cf3 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1198806 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: cmd_update: Add --quirks for device-specific hacksHung-Te Lin2018-09-101-4/+115
| | | | | | | | | | | | | | | | | | | | | The firmware updater usually needs to apply many special rules for particular device, previously done by the 'updater_custom.sh' script. In futility updater, we want to support that by a 'quirks' system, that the updater package can declare a list of needed quirks and send to updater as `futility update --quirks LIST`. Currently only a dummy "test" quirks is defined. The real quirks will be added in follow up changes. BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ic935d69a54473f2347964e7c161ffcdc0af43ec6 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1198804 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: cmd_update: Create and remove temporary files properlyHung-Te Lin2018-09-101-5/+64
| | | | | | | | | | | | | | | | | When running on DUT we should create temporary files using system calls instead of using hard-coded path and file name. The new create_temp_file() will collect all temporary files and remove them all when the remove_temp_files() is invoked (usually at end of program). BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I866dd8dfe7acbf8c5a586249ea2d19f33891672d Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1203334 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: cmd_update: Add new 'legacy' modeHung-Te Lin2018-09-101-2/+25
| | | | | | | | | | | | | | | | | | | | | For devices that do not have update tag provisioned in legacy CBFS, we need a way to push and enforce the updater to complete first migration. The '--mode=legacy' provides a short cut to do "flashrom -p host -w image -i RW_LEGACY" Devices that need newer (or latest) legacy firmware should invoke firmware updater in their initialization or setup process, to enforce updating RW_LEGACY. BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I87db067ad134e82bbbdc937bd2880c6731ec892b Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1198808 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* futility: cmd_update: Correctly handle error counterHung-Te Lin2018-09-071-4/+4
| | | | | | | | | | | | | | | | The errorcnt in do_update should not add function return values directly because the function may return negative values, which would lead to wrong results. Instead we can process using '!!' so the returned value will always be zero or positive integers. BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I9f450b2ee8d86035288f06bdb314dfb1dce3ca64 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1209023 Reviewed-by: Joel Kitching <kitching@chromium.org>
* validate_rec_mrc: Check size before reading metadataFurquan Shaikh2018-09-071-0/+6
| | | | | | | | | | | | | | | | This change ensures that the slot_len is enough to hold the metadata before attempting to actually read it. BUG=None BRANCH=None TEST=None Change-Id: Ief50edccc7a73c2c3002f772c616e4ed5557ecbd Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://chromium-review.googlesource.com/1212528 Commit-Ready: Furquan Shaikh <furquan@chromium.org> Tested-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Hung-Te Lin <hungte@chromium.org>