summaryrefslogtreecommitdiff
path: root/firmware/2lib
Commit message (Collapse)AuthorAgeFilesLines
* vboot2: Introduce vb2ex_hwcrypto APIstabilize-storm-6683.Bstabilize-6670.Bstabilize-6662.BJulius Werner2015-01-068-32/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | This patch extends the vboot2 API by three callback functions that the platform firmware may implement to offer hardware crypto engine support. For now we only support this for hash algorithms, and we will only allow it for firmware body hashes (not the keyblock or preamble which are too small to matter execution-time-wise anyway). The API is similar to the vb2api_*_hash() functions used to start body hashing in the first place, but we still take this round trip through vboot to allow it to do key/signature management and retain full control of the verification process. We also add a new preamble flag to explicitly disable this feature, so that we can later return to a solely software-based verification path through a firmware update in case a hardware crypto engine turns out to be insecure. CQ-DEPEND=CL:236435 BRANCH=None BUG=chrome-os-partner:32987 TEST='make runtests VBOOT2=1'. Manually booted on Pinky with and without HW crypto support and with the preamble flag set to confirm expected behavior. lib21/ parts untested except for compiling and new unit tests. Change-Id: I17c7d02f392089875a5942a5aafcf6a657354863 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/236453 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* vboot2: Get rid of extra '2' at end of new struct namesRandall Spangler2014-12-055-41/+9
| | | | | | | | | | | | | | | | | | | | Now that lib20 and lib21 are distinct, they can have overlapping struct names. This will be cleaner in the long run, since vboot 2.0 (lib20) is just a temporary stepping stone to vboot 2.1 (lib21). It would be a shame to need to carry around the overhead of that extra digit forever. No functional changes, just a lot of renaming. BUG=chromium:423882 BRANCH=none TEST=make runtests && VBOOT2=1 make runtests (works with/withoug VBOOT2 flag) And compile firmware for veyron_pinky Change-Id: I25f348fd31e32d08ca576836dfdd1278828765a1 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/233183 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: Move old struct handling to lib20/Randall Spangler2014-12-047-1106/+3
| | | | | | | | | | | | | | | | | | | | | This is part 4 of a series of changes to rearrange the vboot2 library so that it's possible to start using the new-style data structs. This change moves knowledge of the old vboot1 data structs into lib20; 2lib now contains only code which is common to both vboot2.x libraries (that is, code which is data structure version agnostic). No functional changes; just rearranging code and tests. BUG=chromium:423882 BRANCH=none TEST=make runtests && VBOOT2=1 make runtests (works with/withoug VBOOT2 flag) And compile firmware for veyron_pinky CQ-DEPEND=CL:233051 Change-Id: I8f9e67157575e5be14952ef4809c3dfafd92596d Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/233021 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Move knowledge of vboot 2.1 data structures inside lib21/Randall Spangler2014-12-042-398/+31
| | | | | | | | | | | | | | | | | | | Code which compiles against fwlib2 no longer knows or cares about the new data structures. This should shrink fwlib2 a bit. This is part 3 of 4 changes which split vboot 2.0 struct handling (old vboot1 structs) from vboot 2.1 struct handling (new style structs). No functional changes; just shuffling around code. BUG=chromium:423882 BRANCH=none TEST=make runtests && VBOOT2=1 make runtests (works with/withoug VBOOT2 flag) And compile firmware for veyron_pinky. Change-Id: Ibccd7d1974e07f38b90c19c924ef3b1ffcb77d62 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/233020 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: vb2_unpack_key2() no longer passes through to vb2_unpack_key()ChromeOS Developer2014-12-041-0/+3
| | | | | | | | | | | | | | | | | | | At one point I thought I'd be able to support both vboot1 and vboot2.1 data structures and dynamically determine which verification path to run. But space limitations on current platforms (e.g. pinky) mean that's not feasible. Remove this vestigal support, so that it's easier to make a clean break to the new data structures on appropriate platforms. BUG=chromium:423882 BRANCH=none TEST=make runtests && VBOOT2=1 make runtests (works with/withoug VBOOT2 flag) And build firmware for veyron_pinky. Change-Id: I9887e0c54114c475df81d5a2b701b9b52e95b017 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/232979 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Move files which use new vboot 2.1 structs to their own directoriesRandall Spangler2014-12-044-935/+0
| | | | | | | | | | | | | | | | | | This is part 1 of a series of 4 changes which rearrange the vboot2 files and unit tests so that we can more cleanly switch over from old-style structs to new-style structs. No functional changes, just shuffling around code. BUG=chromium:423882 BRANCH=none TEST=make runtests && VBOOT2=1 make runtests (works with/withoug VBOOT2 flag) And build firmware for veyron_pinky. Change-Id: I170d737bf151a6bafe61cde23b3d2f7a3fae43ce Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/232978 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Add host lib function to create a vb2-style firmware preambleRandall Spangler2014-12-011-0/+14
| | | | | | | | | | | | | And associated unit tests BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I3bf6ff6c6e32dfd0dd737f9b04ff0546e9e0a463 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/231728 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Add host lib function to create a vb2-style keyblockRandall Spangler2014-12-014-7/+36
| | | | | | | | | | | | | | | | | | | Also add vb2_common_desc() helper function to return the description for an object starting with a common struct header. And use the new host lib function to create the keyblock for verifying the firmware lib. Add tests for everything new. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I1fadb3e249e771a692cc69b23620c6ddd46a48ac Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/231721 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Add host library functions for signing to new struct formatRandall Spangler2014-11-271-0/+41
| | | | | | | | | | | | | | Including signing with bare hashes, and signing an object with more than one signature. With unit tests, even. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: Iad0b9f9f6cca7129071aebf0cbc60c0daa94d382 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/231452 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Add host lib support for bare hash keysRandall Spangler2014-11-272-10/+21
| | | | | | | | | | | | | | And use them in the other vboot2 unit tests. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I0c3590649a0acf792e41e295ca4279ccba17a41f Reviewed-on: https://chromium-review.googlesource.com/231345 Tested-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Randall Spangler <rspangler@chromium.org>
* vboot2: Add host library functions to read/write new-format key objectsRandall Spangler2014-11-274-28/+172
| | | | | | | | | | | | And unit tests for them. BUG=chromium:423882 BRANCH=none TEST=make runtests && VBOOT2=1 make runtests Change-Id: I720bfb2537bae60f05b5ce28ab196a331a82eedf Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/230931
* vboot2: Add host library functions to read/write files and objectsRandall Spangler2014-11-271-2/+31
| | | | | | | | | | | | | | | | And unit tests for them. Move roundup32() into hostlib. Fix WriteFile() returning success even if it failed to write to the file. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I8a115335c088dc5c66c88423d1ccbda7eaca1996 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/230844
* vboot2: Add api-level functions to use new data structuresRandall Spangler2014-11-144-4/+179
| | | | | | | | | | | | | | | | | | And associated unit tests. And fix a memory overwrite in the old vb_api_tests.c, which apparently didn't touch a critical piece of the shared work buffer, but was still wrong. (This was a problem in the test, not in the code being tested.) BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I322fb7e6bb5214b0adcf5d6d48a0cd238abba88e Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/229738 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Split vb2_guid into its own header fileRandall Spangler2014-11-143-32/+44
| | | | | | | | | | | | | | | | This allows the api header to include it without pulling in the rest of the vboot2 internal structs. No functional changes; just moving a struct definition. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: Ife9408f9b597939a3cc85a10d534108e12f2d739 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/229793 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: load keyblock and preamble from new-style structsRandall Spangler2014-11-143-0/+251
| | | | | | | | | | | | | And associated unit tests. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I6565d8f5da947b4874a656a61051df1a4ce415c7 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/229163 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: Add code and tests for verifying vb2_fw_preamble2Randall Spangler2014-11-124-5/+89
| | | | | | | | | | | | | | | This is the last low-level data structure verification code for the new data structures. Subsequent changes are the next level up the food chain. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I2e45106c27447eb624c1ed562e40b98088249742 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/228360 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: Change preamble to contain a list of signaturesrelease-R40-6457.Bfactory-auron-6459.BRandall Spangler2014-11-064-44/+27
| | | | | | | | | | | | | | | Use struct vb2_signature2 objects to hold the hashes of firmware components, rather than a separate vb2_fw_preamble2_hash struct. Better for code reuse. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: Ia9e23c1488a884f2d6fab4c4be51b25d3ff25c2f Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/228241 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: pass const work buffers, and clarify min_offset outputRandall Spangler2014-11-065-18/+25
| | | | | | | | | | | | | | | | | | | | | When a work buffer is passed to a function, and duplicated inside that function, allocations made against the duplicate are automatically freed when the duplicate goes out of scope. Make that explicit in the comments. And pass in const struct workbuf * instead of struct workbuf *, to make it clear that the passed-in work buffer pointer is not being altered by the function. Also, comment that the value of min_offset becomes undefined if vb2_verify_common_member() or vb2_verify_common_subobject() fails. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: Icc6010e6ef786f78cd2176a59d4d0e6e14905a11 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/227524 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: add code to verify vb2_keyblock2Randall Spangler2014-11-062-1/+77
| | | | | | | | | | | | | | | Now supports multiple signatures per keyblock. And associated unit tests. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I7f2ef216e3689a22ed86c34763f68345d4080e04 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/227181 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: add support for verify data / digest using new signature structRandall Spangler2014-11-052-2/+157
| | | | | | | | | | | | | | | This adds the vb2_signature2 equivalents of vb2_verify_digest() and vb2_verify_data(), including support for bare hash signatures. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I372c9e5f0be926a833e4ca8f84665cfb05907481 Reviewed-on: https://chromium-review.googlesource.com/226950 Tested-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Randall Spangler <rspangler@chromium.org>
* vboot2: add support for new vb2_signature2 structRandall Spangler2014-11-053-0/+85
| | | | | | | | | | | | | And assocated unit tests. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I37fccafd8ccee5c0d55e3746c1611a8dff73145a Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/226939 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: be consistent in use of sig_algorithm vs sig_alg in vboot2 structsRandall Spangler2014-11-052-7/+7
| | | | | | | | | | | | | | | | Previously, we had a mix of sig_algorithm and sig_alg member names, and it was hard to remember which struct used which variant. Prefer sig_alg because of the 80-column limit. Same with hash_alg vs. hash_algorithm BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: Ifbb60f3172549e29efc0fb1f7f693efa51eb7cc3 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/226943 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: use common header size fieldsRandall Spangler2014-11-055-57/+225
| | | | | | | | | | | | | | | | Add functions for verifying object integrity using common header size fields. Convert vb2_packed_key2 to use the the new functions. This isn't much prettier for packed keys; the benefit is more obvious for keyblocks (coming next). BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I0c09533368abb7ced3b5ac622a15e62832413b7f Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/226874 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vb2: parse dev mode in phase1Aaron Durbin2014-11-032-17/+12
| | | | | | | | | | | | | | | | | | | | | | The rest of the system software expects dev mode to be orthogonal to recovery mode. However, vb2_fw_phase1() was only checking recovery mode. The caller would then not call vb2_fw_phase2() which checked the developer mode settings. Fix this by doing the necessary steps in vb2_fw_phase1(). BUG=chrome-os-partner:33264 BRANCH=None TEST=None yet. Change-Id: I06da388c3ca33754ddb5937a2877fbc287946490 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://chromium-review.googlesource.com/225906 Tested-by: Furquan Shaikh <furquan@chromium.org> Commit-Queue: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Benson Leung <bleung@chromium.org> Tested-by: Benson Leung <bleung@chromium.org>
* vboot2: un-nest data structuresRandall Spangler2014-11-014-89/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Originally, we designed the vboot data structures so that some of them had sub-structures. Then the variable-length data for each of the structures was at the end. So: struct vb2_keyblock { struct vb2_packed_key struct vb2_signature } // Followed by variable-length data for keyblock // Followed by variable-length data for packed key // Followed by variable-length data for signature This had the weird side effect that the header and data for the sub-structs were not contiguous. That wasn't too bad before, but it gets more complicated with the new data structures. Each structure now can also have a description. And keyblocks can have a list of signatures. Structures also couldn't really know their own size, since a sub-struct might have a 20-byte header, but then 2K of other data in between that and the data for the sub-struct itself. So, un-nest all the data structures. That is, the keyblock now contains the offset of the signature struct, rather than the signature struct itself. And then all the variable-length data for each struct immediately follows the struct itself. So: struct vb2_keyblock2 { // Offset of packed key // Offset of first signature } // Followed by variable-length data for keyblock struct vb2_packed_key // Followed by variable-length data for packed key struct vb2_signature2 // Followed by variable-length data for signature (desc, sig data) Verifying and traversing these objects is much more straightforward. And each struct can now know its own size. This first change rearranges the structures. Descriptions now immediately follow the fixed size structure headers. The next change adds better verification of the structures, using the fixed_size and total_size fields in the common header. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: Ieb9148d6f26c3e59ea542f3a95e59d8019ccee21 Reviewed-on: https://chromium-review.googlesource.com/226824 Tested-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Randall Spangler <rspangler@chromium.org>
* vboot2: Add GUIDs for VB2_SIG_NONE signature typesRandall Spangler2014-10-311-3/+16
| | | | | | | | | | | | | | | Signatures with VB2_SIG_NONE are unsigned hashes. To make it easier to locate these signatures in the keyblock's list of signatures, define GUIDs for them. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I5bf9424107d7703b1a191b1bdf02954192ffc583 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/226813 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: Add vb2_unpack_key2() and unit testsfactory-rambi-6420.BRandall Spangler2014-10-296-3/+133
| | | | | | | | | | | | | | | | | | | | | | | This unpacks new-style packed keys. For now, it can also handle old-style packed keys by passing them to the old unpacking function. Once we've switched over to new-style keys in the signing scripts, we'll remove the old format to save code size. Also added is a test library which converts from old to new struct formats. That should eventually get absorbed into futility, and the test keys directory should have both old and new format packed keys in it. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I0fe31f124781d1ea1efedab65dcd6130bfca18dd Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225490 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Add verification for common vb2 struct headerRandall Spangler2014-10-294-10/+70
| | | | | | | | | | | | | | All new-style structs have a common header. This adds a verification function for that common header, and tests for it. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I668486e77f7200c10b43aa2d17b4dd6639e5538e Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225459 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Move and rename functionsRandall Spangler2014-10-286-86/+94
| | | | | | | | | | | | | | | | | | | | | | | | Move packed key functions to their own file, in preparation for introducing support for vb2_packed_key2. Rename the awfully-named vb2_verify_fw_preamble2() function to vb2_load_fw_premable(), since the new structs actually have a vb2_fw_preamble2 struct and that would be very confusing. Rename vb2_verify_fw_keyblock() to vb2_load_fw_keyblock(), so it matches. No functional changes, just renaming. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: Ia914e48e6c5814ab3205b999ceda1aa2452206ff Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225458 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: use enum signature algorithmRandall Spangler2014-10-284-64/+99
| | | | | | | | | | | | | | | | | | | This changes the internals of vboot2 to use the enumerated type for signature algorithm. The conversion from crypto algorithm is done only when unpacking the key. This is preparation for the vboot2 data types, which separate signature and hash algorithms into their own fields. There is no external change in the calling API to vboot, and no change to the external data structures. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I2e176d186d88cc7541644e001e720b4aee456be0 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225209
* vboot2: use enum hash algorithmstabilize-6412.BRandall Spangler2014-10-288-40/+51
| | | | | | | | | | | | | | | | | | | | | | This changes the internals of vboot2 to use the enumerated type for hash algorithm. The conversion from crypto algorithm is done only when unpacking the key (and ok, in checking the rsa padding, but that goes away in the next change). This is preparation for the vboot2 data types, which separate signature and hash algorithms into their own fields. There is no external change in the calling API to vboot, and no change to the external data structures. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I9c6de08d742dab941beb806fbd2bfc1e11c01e2c Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225208 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Log recovery reason and subcode to consoleJulius Werner2014-10-251-2/+6
| | | | | | | | | | | | | | | | | | | | | Looks like vboot2 currently never outputs the current recovery reason anywhere, which is annoying for debugging devices without working display (where you could press TAB). This patch adds log messages both when deciding to go into recovery mode and when picking up an existing recovery request from NVRAM, for maximum visibility. Also removes the "Both slots are bad." part of the vb2_fail() message, since this is not necessarily true and can be confusing (there are many other possible reasons why it might want to go into recovery). BRANCH=ToT BUG=None TEST=Manual Change-Id: Ic98c61223dce00e830ea0f199878d47b214bb224 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225160 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* vboot2: new data structuresRandall Spangler2014-10-244-25/+424
| | | | | | | | | | | | | | | | | These structures allow for simplication and feature expansion in vboot. They are NOT backwards-compatible with old vboot1 structs. This CL simply adds the new structs and unit tests for struct packing; future CLs will add support for them in the firmware library and futility. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I22532acf985dd74316bd30f17e750f993b6c53d7 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/224820 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Fix broken compatiblity check for gbb header 1.1Randall Spangler2014-10-231-1/+1
| | | | | | | | | | | | | | | | vboot2 supports only GBB header versions 1.1+. When the GBB header was rev'd to 1.2, this broke the compatibility check for 1.1. However, the test was written in such a way that wasn't detected. Fix the check and the test. BUG=chromium:415227 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: Ifeb1f21bf5cf3cc05d31ac7912693e090eb8fd5e Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/225110 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: move verify digest to 2commonRandall Spangler2014-10-226-37/+61
| | | | | | | | | | | | | | This removes code duplicated between 2common.c and 2rsa.c. This is in preparation for adding new unsigned hash algorithms. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make -j runtests Change-Id: Ic9c542ae14d3b7f786129c1d52f8963847a94fb8 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/224780 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Add hwid digest field to GBB headerBill Richardson2014-10-211-2/+9
| | | | | | | | | | | | | | | | | | | This adds a field in the GBB header to store the sha256 digest of the HWID string, and updates gbb_utility so that it stores the digest when it modifies the HWID. Because this is a new field, the GBB_MINOR_VER is incremented. BUG=chromium:415227 BRANCH=ToT TEST=make runtests, VBOOT2=1 make runtests Since the GBB is in the RO firmware, there should be no side effects for existing devices (but even without that, they should handle a minor version change without complaint). Change-Id: Icdb2a0b564677b0b65e58df897d2ec5af3964998 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/221360
* vboot2: move vb2_safe_memcmp() from rsa to commonRandall Spangler2014-10-183-32/+34
| | | | | | | | | | | | | | This will be needed by other algorithms, so should not live inside the rsa module. Also added explicit unit tests for it. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I92c8c6484964a93d755ac2ee93b57511794540e9 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/224111 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: move firmware hash tags to their own header fileRandall Spangler2014-10-162-17/+42
| | | | | | | | | | | | | | | And add a few hash tag types we'll be supporting soon. No functional changes; just moving an enum from one header to another. BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I6f0fa54ee85fd857c4037856b81e2159e92f1ea9 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/223532 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Split crypto algorithms into their own header fileRandall Spangler2014-10-164-28/+46
| | | | | | | | | | | | | | | | This allows the algorithm list to be shared by code which simply needs to look at the vboot structures. No functional changes; just moving enums around and adding comments. BUG=chromium:423882 BRANCH=none TEST=make runtests; VBOOT2=1 make runtests Change-Id: Ia8cefeffb28d5eceb290540195193ea13e68e2c1 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/223541 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Add previously tried slot and result to NV storageRandall Spangler2014-10-043-3/+35
| | | | | | | | | | | | | | | | | | | | This gives recovery mode information on two boots back instead of one, which may be handy for debugging. It also allows determining whether a failure of the current boot should try the other slot or go to recovery, using only information stored in NV storage. Added crossystem support for printing the fields, and unit tests. BUG=chrome-os-partner:32585 BRANCH=none TEST=make runtests; VBOOT2=1 make runtests Change-Id: Ia9f4186210d30217b902db7c513ae4ab8851f8f4 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/221230 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: Fix saving the slot we tried back to nv storageRandall Spangler2014-10-041-0/+3
| | | | | | | | | | | | | | | | | Previously, we only kept that slot info in RAM. We read it from NV storage, but never wrote it back. Added a test to confirm proper behavior (and made sure it failed before patching 2misc.c with the fix). BUG=chrome-os-partner:32583 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: Ie12124d9cbe417914fbde14ea5086380d637240f Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/221214 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: Fix potential null pointer dereferenceRandall Spangler2014-09-241-1/+2
| | | | | | | | | | | | | | | If key is null in vb2_verify_digest(), we could attempt to dereference it. In practice it never is, but for safety's sake we should avoid the reference. BUG=chrome-os-partner:32235 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I5a817e432922ea4c3b439b696cd2f8d988d0fecc Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/219574 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Add GBB flag to disable PD software syncstabilize-6146.Brelease-R38-6158.BDuncan Laurie2014-08-121-0/+3
| | | | | | | | | | | | | | | | | | | | | | In order to disable PD software sync but still do EC software sync it is useful to have a separate GBB flag for it. This will allow me to release a Samus P2B firmware image that will update the EC but not the PD, since the PD FW that comes on P2B devices cannot be updated with software sync. BUG=chrome-os-partner:30079 BRANCH=None TEST=flash BIOS with updated EC+PD: 1) no GBB flags to override behavior updates both EC and PD 2) GBB flag to disable EC software sync disables both EC and PD update 3) GBB flag to disable PD software sync disables only PD update Change-Id: I49ffb59238bee4a2dd66b24f2516e3ce46ea06cd Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/211910 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Add nvstorage / crossystem support for new vboot2 fieldsRandall Spangler2014-06-281-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows testing vboot2. These fields are ignored by original vboot firmware. BUG=chromium:370082 BRANCH=none TEST=manual crossystem -> fw_tried=A, fw_result=unknown, fw_try_next=A crossystem fw_tried=B echo $? -> 1 crossystem -> fw_tried=A, fw_result=unknown, fw_try_next=A crossystem fw_try_next=B crossystem -> fw_tried=A, fw_result=unknown, fw_try_next=B crossystem fw_try_next=beats_me echo $? -> 1 crossystem -> fw_tried=A, fw_result=unknown, fw_try_next=B crossystem fw_try_next=A crossystem -> fw_tried=A, fw_result=unknown, fw_try_next=A crossystem fw_result=trying crossystem -> fw_tried=A, fw_result=trying, fw_try_next=A crossystem fw_result=bupkis echo $? -> 1 crossystem -> fw_tried=A, fw_result=trying, fw_try_next=A crossystem fw_result=success crossystem -> fw_tried=A, fw_result=success, fw_try_next=A crossystem fw_result=failure crossystem -> fw_tried=A, fw_result=failure, fw_try_next=A crossystem fw_result=unknown crossystem -> fw_tried=A, fw_result=unknown, fw_try_next=A crossystem -> fw_try_count = 0, fwb_tries = 0 crossystem fw_try_count=6 crossystem -> fw_try_count = 6, fwb_tries = 6 crossystem fwb_tries=0 crossystem -> fw_try_count = 0, fwb_tries = 0 Change-Id: I1532f3384f8c05de2a7ff3f35abcc35d18049491 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/205475
* vboot2: fix overloaded NV bitRandall Spangler2014-06-252-4/+14
| | | | | | | | | | | | | | Bill and I both added meanings for byte 1 bit 0x10. His changed (NV_BOOT_BACKUP_NVRAM) landed first, so move the vboot2 bit to byte 2. BUG=chromium:370082 BRANCH=none TEST=make clean && VBOOT2=1 make runtests Change-Id: Ib7ff8da47d03f91cbeb729ca517c6315dfb4e6ac Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/205408 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* vboot2: Scramble the GBB magic numberDaisuke Nojiri2014-06-253-5/+28
| | | | | | | | | | | | | | | | Compiling in the GBB magic number as is causes any tools that search for the number to fail. This patch allows firmware to embed XOR'ed signature. TEST=Booted Nyan in normal mode. FAFT:firmware_DevMode passes. BUG=none BRANCH=none Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Id18905a9969af3db24151e7c51332d0e94405108 Reviewed-on: https://chromium-review.googlesource.com/205416 Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: More specific errors for unimplemented external APIsRandall Spangler2014-06-242-2/+8
| | | | | | | | | | | | | | | When porting vboot2 to a platform, it's common to copy 2stub.c and then start implementing APIs. Adding explicit errors makes it clearer when an unimplemented API is called. BUG=chromium:370082 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: I1f412b7ed4b431dbdbdee5e33b27bf7206186918 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/204960 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* vboot2: Allow platform dependent debug loggingDaisuke Nojiri2014-06-232-5/+10
| | | | | | | | | | | | | TEST=Built with VBOOT_DEBUG on/off. Booted Nyan Blaze. Verified debut output. BUG=None BRANCH=none Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Id189231f16ca8719dfff0ef3c9a8d4982b741d5f Reviewed-on: https://chromium-review.googlesource.com/205157 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* vboot2: Check necessity of recovery when firmware body hash fails to matchDaisuke Nojiri2014-06-232-0/+4
| | | | | | | | | | | | | TEST=Booted Nyan Blaze and verified recovery is requested. BUG=None BRANCH=none Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I076e9714de4b853973cadad9a02a35d28431790c Reviewed-on: https://chromium-review.googlesource.com/205156 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* vboot2: api-level routinesRandall Spangler2014-06-193-7/+491
| | | | | | | | | | | | | | I'm breaking the last chunk of vboot2 into smaller pieces as I add tests. This has the api-level routines actually called by depthcharge. BUG=chromium:370082 BRANCH=none TEST=make clean && VBOOT2=1 COV=1 make Change-Id: Ic7c082fc5faa0b874b2fa5a15ebda7135dcafe0b Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/200151 Reviewed-by: Bill Richardson <wfrichar@chromium.org>