Commit Graph

1522 Commits

Author SHA1 Message Date
Bill Richardson
0f21441e78 vb21: Replace the key GUID with a sha1sum instead
We want a quick and human-friendly way to match keys with
signatures, so we decided to give each key a unique GUID and
carry that ID around when signing things.

But then we realized that we could autogenerate a unique
identifier from the .pem file itself, which is even better
because then we can match our binary keypair structs with the
openssl file used to generate them.

This change replaces the GUID id with a sha1sum calculated from
the public key's "keyb" blob.

BUG=none
BRANCH=none
TEST=make runtests

Also:

  futility show tests/testkeys/key_rsa4096.pem
  futility create tests/testkeys/key_rsa4096.pem foo
  futility show foo.vbp*

Note that the GUID is the same for all files.

Change-Id: Ie44e46c83433718b1ff0163c1e7c51ec331b99f9
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/256181
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-03-10 23:46:03 +00:00
Bill Richardson
9c647efd7f cleanup: Fix some typos in comments
No code changes, just fix a few spelling errors and change C++
style comments to C-style.

BUG=none
BRANCH=none
TEST=make runtests

Change-Id: I153f821a3f42a92867c7dc4761a2bcde7f2518c4
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/256123
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2015-03-10 23:45:58 +00:00
Bill Richardson
64b3697297 futility: show some information about .pem files
We use the .pem files to generate our public and private key
files. Since we display the sha1sums of those files to help keep
track of them, we might as well also display the same information
about the RSA .pem files, too.

BUG=chromium:231574
BRANCH=none
TEST=make runtests

  futility show tests/testkeys/*.pem

Change-Id: Ibfd1e016d65981d477ed7d117d23dedf48b95873
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/246769
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-03-10 23:45:30 +00:00
Bill Richardson
3855e2e948 futility: show sha1sums for private keys too
Because all of our private key structs carry around the openssl
struct rsa_st data blobs, we can use those blobs to extract the
corresponding public key and generate a digest of it.

This lets us match our public and private keys without having to
rely on the filenames. There's no crypto verification without
actually *using* them, of course, but it's handy for quick reference.

BUG=chromium:231574
BRANCH=none
TEST=make runtests

This also adds a test to ensure that all the public and private
keys generated from the same .pem file have the same sha1sums.

Change-Id: If83492437e3ef37f7c4ebca4675336b75f631901
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/246768
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-03-10 23:45:26 +00:00
Bill Richardson
add997fa94 futility: Display public and private keys for both formats
This enhances the futility show command to recognize and identify
our public and private key files, for both the old vboot 1.0
format and the new vboot 2.1 format.

BUG=chromium:231547
BRANCH=ToT
TEST=make runtests

vboot 1.0:

  futility show tests/devkeys/*.vbp*

vboot 2.1:

  futility create tests/testkeys/key_rsa2048.pem foo
  futility show foo.vbp*

Change-Id: I9d7641db03e480b416790a7da6b473215444128a
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/246767
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-03-10 23:45:21 +00:00
Bill Richardson
4e4c19602e futility: Add create command to make keypairs from RSA files
This command reads a single .pem file and emits the public and
private keys generated from it. It can produce both the old-style
vboot 1.0 keys (.vbpubk and .vbprivk), or the new vboot 2.1
format keys (.vbpubk2 and .vbprik2). The default is the new
format, but you can give futility the --vb1 arg to force the old
format.

A test is included.

BUG=chromium:231547
BRANCH=ToT
TEST=make runtests

Change-Id: I4713dc5bf34151052870f88ba52ddccf9d4dab50
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/246766
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-03-10 20:44:43 +00:00
Hung-Te Lin
26af0da4f7 make_dev_ssd: Allow smaller kernel partition.
Some Brillo devices may have smaller kernel partition and we need to reduce the
size limit.

BUG=none
BRANCH=none
TEST=make_dev_ssd.sh applied on a Brillo config with 8MB kernel partition.

Change-Id: I9ca37445a6cdb20138f13dbe975c207383a1474c
Reviewed-on: https://chromium-review.googlesource.com/255341
Tested-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Mao Huang <littlecvr@chromium.org>
Commit-Queue: Hung-Te Lin <hungte@chromium.org>
2015-03-03 21:37:59 +00:00
Bill Richardson
1eae873b61 futility: Add global args to specify vboot API and format
The host-side futility tool will need to support all extant vboot
implementations. Some legacy futility commands only support the
original vb1 format, but others ("show" or "sign", for example)
may need to be instructed which formats to expect or emit.

This change adds some global args to specify the preferred
formats. It also cleans up a few [unused AFAICT] one-letter args
to avoid conflicts.

BUG=chromium:231574
BRANCH=none
TEST=make runtests

Nothing makes use of this yet, except the "help" command.

Change-Id: Ib79fa12af72b8860b9494e5d9e90b9572c006107
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/246765
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-28 00:56:13 +00:00
Bill Richardson
822120106c Do not litter the source directory with build artifacts
Before, building locally left a file named "vboot_host.pc" in the
top directory.

With this change, it's put into the $BUILD directory where it
belongs.

It still gets installed into the same place, of course.

BUG=chromium:459338
BRANCH=none
TEST=make runtests, and

Run:

  make test_setup MINIMAL=
  make test_setup MINIMAL=1
  find . -name vboot_host.pc

Before this CL:

  ./build/install_for_test/usr/lib/pkgconfig/vboot_host.pc
  ./build/install_for_test/lib/pkgconfig/vboot_host.pc
  ./vboot_host.pc

After this CL:

  ./build/install_for_test/usr/lib/pkgconfig/vboot_host.pc
  ./build/install_for_test/lib/pkgconfig/vboot_host.pc
  ./build/vboot_host.pc

Change-Id: I3a888f72a5753228eec5187178d0da22de782171
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/254712
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Nam Nguyen <namnguyen@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-28 00:56:08 +00:00
Bill Richardson
0840b842c1 Fix some Makefile dependencies for parallel tests
make runtests -j4 occasionally failed due to missing
dependencies. This helps. Of course, there may be others...

BUG=none
BRANCH=ToT
TEST=make runtests -j4

Change-Id: Iff6e96f94b125a16be76d8cf34ce473bf6c65fe5
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/246764
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-27 23:48:32 +00:00
Anatol Pomazau
9d437e9122 Remove duplicated linker flag
We already set '-static' to LDFLAGS above no need to do it again here.

TEST=build with 'make' and 'make STATIC=1'. Check that 'STATIC=1' adds '-static' linker flag.
BUG=None

Change-Id: I83e23984753094af203432eb4570930085788398
Reviewed-on: https://chromium-review.googlesource.com/251151
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Anatol Pomazau <anatol@google.com>
Commit-Queue: Anatol Pomazau <anatol@google.com>
Tested-by: Anatol Pomazau <anatol@google.com>
2015-02-25 08:45:04 +00:00
Alex Deymo
3fec0e47bd cgpt_wrapper: Print error if execv() fails.
This shows an error message when cgpt.bin failed to run, with its
reason. Without this patch, "cgpt" would just fail and return -1 in
that case making it difficult to know the reason of the failure.

BUG=chrome-os-partner:36061
TEST=replaced this binary in storm recovery initramfs 6699.0.0 and it
shows the error message if cgpt.bin is not installed.
BRANCH=None

Change-Id: I3ffaba5a63c491ac7d5b16086d5ae21005f40317
Reviewed-on: https://chromium-review.googlesource.com/251868
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Trybot-Ready: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
2015-02-23 20:02:49 +00:00
Zach Reizner
317bb498a6 vboot2: add library function for extracting vmlinuz from kernel part
postinst needs access to a kernel that is bootable from legacy BIOS.
futility provides extraction of a bootable vmlinuz from the kernel
partition via the command line. This patch provides a function which
does the same thing and is suitable for static linking into postinst
with minimal additonal code linked in. This way we can avoid issues with
running dynamic executables during postinst.

BRANCH=none
TEST=None
BUG=chromium:455343

Change-Id: Iaec2f48e4d8f78a4bbfcc1636b6ce478e95e9a8e
Reviewed-on: https://chromium-review.googlesource.com/251760
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
2015-02-23 18:41:01 +00:00
Nam T. Nguyen
f44ebbe36b vboot_reference: Support MTD devices in dump_kernel_config
This CL implements a read function that works with MTD devices in
dump_kernel_config.

BUG=chromium:457862
BRANCH=none
TEST=make runtests
TEST=try on storm_nand

Change-Id: Id784d422de64e7918b163005c0b426d727d2115e
Reviewed-on: https://chromium-review.googlesource.com/249271
Reviewed-by: Nam Nguyen <namnguyen@chromium.org>
Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
Trybot-Ready: Nam Nguyen <namnguyen@chromium.org>
Tested-by: Nam Nguyen <namnguyen@chromium.org>
2015-02-19 21:17:02 +00:00
Anatol Pomazau
a0f7ab5567 Use /usr/bin/python2 in shebangs
Per the pep-0394 recommendation, version specific python scripts should
specify the interpreter version.

TEST=Run tests on a system with python3 default
BUG=None

Change-Id: I83e98f3bb0235230293819104570930085788398
Reviewed-on: https://chromium-review.googlesource.com/251132
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Anatol Pomazau <anatol@google.com>
Commit-Queue: Anatol Pomazau <anatol@google.com>
2015-02-19 21:16:54 +00:00
Nam T. Nguyen
07d9043da4 vboot_reference: Install vboot_host.pc file
Since we are going to pull in libmtdutils, it would be nice to let
downstream packages automatically query for appropriate linking flags.

BUG=chromium:459338
BRANCH=None
CQ-DEPEND=CL:250836
TEST=See the depending CL.

Change-Id: I9ff8046b95e1d7e909a483fe87a69d460777e192
Reviewed-on: https://chromium-review.googlesource.com/250530
Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
Trybot-Ready: Nam Nguyen <namnguyen@chromium.org>
Tested-by: Nam Nguyen <namnguyen@chromium.org>
Reviewed-by: Nam Nguyen <namnguyen@chromium.org>
2015-02-19 01:18:37 +00:00
Nam T. Nguyen
aa4ee34524 vboot_reference: Remove mmap() in dump_kernel_config
dump_kernel_config utility used mmap() to map a file or block device to
memory and searched from there. This CL removes mmap(), and reads from
the input sequentially. We need this so that working with MTD devices is
possible. We just need to implement another read function.

BUG=chromium:457862
BRANCH=none
TEST=make runtests
TEST=FEATURES=test emerge vboot_reference

Change-Id: I83e98f3bb079879f411d7f2f584b1792131b9b38
Reviewed-on: https://chromium-review.googlesource.com/249270
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Tested-by: Nam Nguyen <namnguyen@chromium.org>
Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
Trybot-Ready: Nam Nguyen <namnguyen@chromium.org>
2015-02-17 18:19:14 +00:00
Furquan Shaikh
b7d1f03e36 kernel flags: Pass back kernel premable flags in kparams
Kernel preamble flags are set by the signer for passing hints about
the image. Read these flags from the preamble and pass it back to the
caller in kparams structure.

BUG=chrome-os-partner:35861
BRANCH=None
TEST=Compiles and boots to kernel prompt for both CrOS image and bootimg.

Change-Id: I07a8b974dcf3ab5cd93d26a752c989d268c8da99
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/245951
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Tested-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Furquan Shaikh <furquan@chromium.org>
2015-02-12 04:40:39 +00:00
Furquan Shaikh
80e779d50b kernel flags: Add flags field to kernel preamble.
1. Increase kernel preamble revision from 2.1 to 2.2.
2. Add flags field to kernel preamble.
3. Update futility to accept flags parameter for vbutil_kernel and
cmd_sign for kernel.
4. Pass in an extra flags field to SignKernelBlob and
CreateKernelPreamble.

BUG=chrome-os-partner:35861
BRANCH=None
TEST=1) "make runalltests" completes successfully. 2) vboot_reference
compiles successfully for ryu. 3) Verified flags field in header using
futility show.

Change-Id: If9f06f98778a7339194c77090cbef4807d5e34e2
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/245950
Tested-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Furquan Shaikh <furquan@chromium.org>
2015-02-12 04:40:35 +00:00
David Riley
623d6c4744 initial Android.mk
Minimal Android.mk sufficient to build host tools to compile
futility vbutil_keyblock and vbutil_kernel to sign kernel images.

BUG=none
TEST='mm' from within Android tree compiles
BRANCH=none

Change-Id: Ie46be27cd14a5ca73a23eb52238eb9fd326ccaf4
Signed-off-by: David Riley <davidriley@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/247820
2015-02-12 04:40:28 +00:00
Julius Werner
187f069f89 vboot2: Add more precise recovery reasons to firmware verification
vboot1 kept track of an internal "LoadFirmware() check" value for both
firmware slots and encoded the value for the slot that managed to go
further in the verification flow into a special range of recovery
reasons. vboot2 instead uses the generic "invalid RW" reason for all
firmware verification failures and communicates further information
through the subcode.

While the subcode may be good enough for developers, it's difficult to
communicate failure reasons to "normal" users (like non-firmware
developers) on the TAB screen. Currently we just display a couple of
numbers that people won't know how to interpret and "RW firmware failed
signature check" for any verification error (including rollback, which
might be the most commonly encountered in practice).

Since our recovery reason space is big enough (and we don't reuse old
numbers anyway), we might as well reuse the more precise numbers (and
strings) from vboot1 to communicate the failure reason, even if we don't
implement its "which slot came further" algorithm. This patch translates
the most common/useful VBSD_LF_CHECK numbers into plain VB2_RECOVERY
reasons and uses them where appropriate.

CQ-DEPEND=CL:248400
BRANCH=veyron
BUG=None
TEST=make runtests VBOOT2=1
test_that my_jerry firmware_CorruptBothFwSigAB
firmware_CorruptBothFwBodyAB firmware_RollbackFirmware
(Confirmed that matched recovery reasons are the more precise ones in
the 0x10-0x1F range.)

Change-Id: I51ecf1b820d1faa40405cb84377380d6f3f6ca1d
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/248392
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2015-02-12 00:41:33 +00:00
David Riley
05987b159a Changes to compile signing tools on darwin
The following works from a Mac with these changes:
make Q= ARCH=arm HAVE_MACOS=1 `pwd`/build/futility/futility

Only vbutil_keyblock and vbutil_kernel have been exercised.

BUG=none
TEST='make Q= ARCH=arm HAVE_MACOS=1 `pwd`/build/futility/futility'
BRANCH=none

Signed-off-by: David Riley <davidriley@chromium.org>

Change-Id: Ie69cfee0c650d4ff96be6322083a2fea1543ee39
Reviewed-on: https://chromium-review.googlesource.com/246773
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Tested-by: David Riley <davidriley@chromium.org>
Commit-Queue: David Riley <davidriley@chromium.org>
2015-02-11 23:05:39 +00:00
Furquan Shaikh
2b0dc16745 Add LINUX_FS_GUID to list of GUIDs.
This is for experimental purpose.

BUG=chrome-os-partner:35861
BRANCH=None
TEST=Compiles successfully.

Change-Id: I53ce56f3728b72473a42581665969c90598ffd62
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/242924
Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Trybot-Ready: Furquan Shaikh <furquan@chromium.org>
Tested-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Commit-Queue: Furquan Shaikh <furquan@chromium.org>
2015-02-11 23:05:35 +00:00
Julius Werner
dc8ec103c0 vboot1: Add vboot2 recovery reason strings and subcode to TAB display
vboot2 added a few new recovery reasons (and abolished many old ones).
In the current vboot2/vboot1 hybrid architecture used on Veyron, the
vboot1 kernel verification part controls the status display when
pressing the TAB key, which may try to show recovery reasons set by the
vboot2 firmware verification part. These currently result in the not
very helpful "We have no idea what this means", so lets hack a few more
strings into vboot1 which will be otherwise harmless. Also add the
recovery_subcode field to the display, which is used much more
extensively by vboot2 and often very useful in firguring out what really
went wrong.

BRANCH=veyron
BUG=None
TEST=Manually set a few recovery reasons and subcodes through crossystem
and made sure they get displayed correctly on my Jerry.

Change-Id: I3f3e6c6ae6e7981337841c0c5e3cd767628472c3
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/248391
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-11 23:05:29 +00:00
Ken Chang
c93ddb60aa crossystem: read recovery switch status from chromeos_arm device
The kernel chromeos_arm platform device provides the recovery status
with the consideration of active polarity.
Thus make crossystem to read from chromeos_arm device first. If this
is not available, read directly from gpio pin status.

BUG=chrome-os-partner:36425
BRANCH=none
TEST=ran on kitty,
'crossystem recoverysw_cur' return 0 with recovery switch off
'crossystem recoverysw_cur' return 1 with recovery switch on

Change-Id: Ie20630d7d07aeadf24044cd3ffc495df7cdd8a4a
Signed-off-by: Ken Chang <kenc@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/246883
Tested-by: Titan Lee <titanlee@nvidia.com>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Titan Lee <titanlee@nvidia.com>
2015-02-10 08:46:06 +00:00
Bill Richardson
864fae2d78 Check the correct length of the GPT header signature
The length of the signature is 8 bytes. We've been checking 9
bytes instead, pretty much forever. All the tests have passed
because although the signature we're looking for is an 8-byte
string followed by a '\0', the next field in the header contains
the revision number 0x00010000, so the 9th byte is always zero.

We should follow the spec, though.

BUG=none
BRANCH=none
TEST=make runtests

Change-Id: I7cc6370250fa36a193f4a9fa5bc0099aea465618
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/247331
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-09 02:13:51 +00:00
Julius Werner
b550fb1804 vboot2: Fail vb2_secdata_(get|set) when secdata was not initialized
This patch adds a check to vboot2 secdata accessor functions that
returns an error if vb2_secdata_init() has not yet been called or
failed for some reason. This avoids a problem where vboot may
misinterpret random garbage (e.g. from transient read failures) as
valid secdata in recovery mode and write it back to the TPM (bricking
the device in a way that requires manual repair).

Also removes VB2_ERROR_SECDATA_VERSION check. This check was not
terribly useful since there should be no way a vboot2 device could ever
have secdata version 1 (and if it did, it should still fail CRC checks).
This error can trigger for cases when secdata contains random garbage
(e.g. all zeroes) and prevent the much more appropriate
VB2_ERROR_SECDATA_CRC error from even being checked for, which just
creates confusion and makes it harder to determine the real problem.

BRANCH=veyron
BUG=chrome-os-partner:34871
TEST=Emulated TPM read errors by just manually memset()ing secdata to 0
in coreboot, verified that vboot does not write back to the TPM and the
device will start working fine again once the disruption is removed.

Change-Id: I76bcbdbcd8106a0d34717cc91a8f2d7cda303c3f
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/244846
2015-02-04 22:01:18 +00:00
Mike Frysinger
d7d9d3b669 keygeneration: fix typos in previous commit
Forgot to update the bitsizes in the variable constants.

BUG=chromium:454651
TEST=`./create_new_keys.sh` still generates 8k keys
TEST=`./create_new_keys.sh --4k` now generates 4k keys
BRANCH=None

Change-Id: Ie285649f4d58ad2e2cba71f4cab737cc2235e3ab
Reviewed-on: https://chromium-review.googlesource.com/245890
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2015-02-03 22:46:06 +00:00
Mike Frysinger
79add75aa3 create_new_keys: add options for generating 4k keys
BUG=chromium:454651
TEST=`./create_new_keys.sh` still generates 8k keys
TEST=`./create_new_keys.sh --4k` now generates 4k keys
BRANCH=None

Change-Id: I2203536880b9320959fd741c4bbcf814aded603c
Reviewed-on: https://chromium-review.googlesource.com/245318
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2015-02-03 22:03:34 +00:00
Shelley Chen
1bdc612578 vboot_reference: fix pointer issue in vmlinuz recontruction
vmlinuz_header_address was using an offset as opposed to a pointer.

BUG=None
BRANCH=None
TEST=Take a kernel block and reconstruction the vmlinuz image:
     "vbutil_kernel --get-vmlinuz kern0 --vmlinuz-out vm.out"
     Then, try to kexec vm.out.

Change-Id: Ifb41a00fd73f3222673467eef370c7abdbd0fd9c
Reviewed-on: https://chromium-review.googlesource.com/245441
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Shelley Chen <shchen@chromium.org>
Tested-by: Shelley Chen <shchen@chromium.org>
2015-02-03 20:29:38 +00:00
Mike Frysinger
37b6afe030 create_new_keys: add a proper main func
While we do this, clean up:
 - use braces everywhere
 - convert local vars from $VAR to $var
 - parse all command line args properly
 - run in `set -e` mode

BUG=chromium:454651
TEST=`./create_new_keys.sh` still generates sane keys
TEST=`./create_new_keys.sh --help` shows help output
TEST=`./create_new_keys.sh --asdfasdf` shows an error
TEST=`./create_new_keys.sh` outside chroot (w/out vboot binaries) aborts after first failure
BRANCH=None

Change-Id: I1ba0db0b24c0f2f10cf397b47115f0e98384d991
Reviewed-on: https://chromium-review.googlesource.com/245317
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2015-02-03 07:06:32 +00:00
Bill Richardson
4805f1841d futility: show .vbprivk files
BUG=none
BRANCH=none
TEST=make runtests

futility show tests/devkeys/*.vbprivk

Change-Id: Ic062a193c7ee3d7f9837698e1c8fc6bb1e3d7757
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245503
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-03 05:39:28 +00:00
Bill Richardson
04d98e399d Restore lost dependencies
Oops. Somehow the Makefile stopped including the generated
dependencies. As long as we're building from scratch this didn't
matter, but rebuilding following local changes wouldn't always
work. Let's fix it.

BUG=none
BRANCH=none
TEST=make runtests

Change-Id: I80bd30d1847734a288cddf61f28bb33ae9906525
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245501
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-03 05:39:23 +00:00
Bill Richardson
7ccd9ce48e futility: handle truncated BIOS images without segfault
A truncated BIOS with an otherwise valid FMAP that now points way
off the end of the file shouldn't cause coredumps.

BUG=none
BRANCH=ToT
TEST=make runtests

Change-Id: Idf96e1e6a381bf0fe0b1cb2d16e3dad39ce7a0dc
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245500
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-03 05:39:19 +00:00
Julius Werner
21aedee1ce vboot2: Add sd->fw_version_secdata field to communicate to crossystem
This patchs adds a new vb2_shared_data field to store the current
rollback prevention version number stored in secdata (TPM). This
information needs to be retrieved from there by coreboot (current
hack) or vboot2 kernel verification (bright shiny future) so it can be
passed along to the operating system and user space.

BRANCH=veyron
BUG=chrome-os-partner:35941
TEST=make runtests. Booted Jerry in recovery mode (with corresponding
coreboot patch), ensured that crossystem tpm_fwver still shows the
correct value.

Change-Id: I2a0c3e51b158a35ac129d2abce19b40c6c6381a6
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/244601
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-01-31 08:06:47 +00:00
Daisuke Nojiri
62d482ecdd add vb2api_get_pcr_digest
this api allows firmware to get the digest indicating boot mode status.

BUG=chromium:451609
TEST=VBOOT2=1 make run2tests
BRANCH=tot

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Change-Id: Idca7bc5f6aed947689ad7cf219805aad35047c7d
Reviewed-on: https://chromium-review.googlesource.com/244542
2015-01-31 05:42:54 +00:00
Bill Richardson
2559338dbd futility: refactor file type detection into new files
This moves the what-kind-of-file-is-this logic into a separate
file, and makes it work by calling distinct recognizers until one
hits. A new "-t" option to the show command prints what it's
doing.

BUG=chromium:228932
BRANCH=ToT
TEST=make runtests

Change-Id: Id8f60bdf3fe6a9adf41b4555b3448a261fa52fea
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245122
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-01-31 05:42:48 +00:00
Julius Werner
65ce99b3e2 crossystem: Add fw_prev_tried and fw_prev_result to output values
CL:221230 added the new NVRAM fields fw_prev_tried and fw_prev_result.
It also provided support in the crossystem library to decode these
values, but it forgot to add them to the table of allowed crossystem
options so they actually cannot be queried by the command line tool. Fix
that since this information is useful to debug failures after updating.

BRANCH=R41
BUG=chrome-os-partner:36183
TEST=make runtests VBOOT2=1. cros deployed onto Jerry and confirmed
fw_prev_tried and fw_prev_result are correct.

Change-Id: I8bad7266379d959f5370b7ebeefbbba939c5de06
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245143
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-01-31 04:32:38 +00:00
Bill Richardson
190eefb3ff sign_official_build.sh should work without dev-firmware keys
The signing scripts pass a bunch of args around, including paths
to the keys used to sign dev-mode-specific firmware. That was
only used on Alex and ZGB, so all the newer systems don't have
those keys and the script falls over.

This uses the normal firmware keys if the dev-firmware keys don't
exist. This was an oversight with the original CL that touched
resign_firmwarefd.sh

BUG=chromium:453901
BRANCH=ToT
TEST=manual

Download a newer signed recovery image, say for nyan, and save it as

  scripts/image_signing/nyan-recovery-mp.bin

Temporarily delete the developer firmware keys from the devkeys:

  rm -f tests/devkeys/dev_firmware*

Now try resigning the recovery image:

  cd scripts/image_signing
  ./sign_official_build.sh recovery nyan-recovery-mp.bin \
                           ../../tests/devkeys/ signed.bin \
                           ../../tests/devkeys/key.versions

It should work.

Change-Id: I474811158cb33e16ad09c16b0db825c40217dd70
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245151
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2015-01-31 04:32:31 +00:00
Bill Richardson
8db64da092 Don't include lib20 files in xrefs
The vboot 2.0 stuff is deprecated, so let's not index that when
building cross-references (cscope.files and TAGS).

BUG=none
BRANCH=ToT
TEST=manual

make xrefs

Change-Id: If3a9c42f869308acd929e32d5290e3354f5c3555
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/244751
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-01-31 00:41:10 +00:00
Bill Richardson
e1ed0ab45c lib21: Close the open file when finished using it
BUG=none
BRANCH=ToT
TEST=make runtests

Change-Id: Ie4ac1ae71e70b62f9bc89fa1441ff5ca65199f79
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/244673
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-01-31 00:41:09 +00:00
Bill Richardson
06eb78c0f6 Rename Makefile's fwlib2 target to fwlib20.
This accurately reflects what's really happening. Vboot 2.0 is
backwards-compatible with the binary structs used in vboot 1.0,
while vboot 2.1 will not be.

When building firmware, vboot_reference should be invoked in one
of three ways:

  TARGET        OUTPUT           VERSION

  fwlib         vboot_fw.a       1.0
  fwlib20       vboot_fw20.a     2.0
  fwlib21       vboot_fw21.a     2.1

BUG=chromium:228932
BRANCH=ToT
CQ-DEPEND=CL:243981
TEST=manual

  emerge-veyron_pinky coreboot
  emerge-samus coreboot
  emerge-daisy_spring chromeos-u-boot

  make runtests

Change-Id: I98d8ea6b48e5922a470e744d56699cad43eabb3d
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/243980
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-01-29 21:35:06 +00:00
Hung-Te Lin
b6ebb1ab1c sign_official_build: Support old images without kernel in partition 4.
Old images don't put kernel on partition 4 and rely on vblock for installation.
The signer script has to support both old and new images, by testing if kernel
partition has valid data.

BRANCH=signer
BUG=chromium:449450
TEST=(get old image without kernel blob on partition 4)
     sign_official_build.sh usb image.bin ../../tests/devkeys signed.bin \
     ../../tests/devkeys/key.versions

Change-Id: I92542ffb162660d86c30d9598fe1ca59ff69afe4
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/243874
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2015-01-29 21:34:56 +00:00
Hung-Te Lin
4083725867 sign_official_buid: Fix "incorrect rootfs hash" when image has no firmware updater .
For each mount_image_partition, we have to unmount explicitly before doing other
changes (especially when using dd) to image. Otherwise system may flush data
when releaseing loop device and cause output image to be corrupted.

BUG=chromium:449450
TEST=sign_official_build.sh factory factory_install_shim.bin \
     ../../../tests/devkeys signed.bin ../../../tests/devkeys/key.versions
     sign_official_build.sh verify signed.bin
BRANCH=signer

Change-Id: I20756d9769c3737e25cfea348a9a4d64cc43b202
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/243496
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2015-01-28 11:14:03 +00:00
Bill Richardson
5fb14634b9 futility: extract vb2_verify_fw to an external test
The vb2_verify_fw command is used only in a host-side test. It
doesn't need to be built into futility. This makes it a separate
executable used just for that test.

BUG=chromium:231547
BRANCH=none
TEST=make VBOOT2=1 runtests

Note that tests/vb2_firmware_tests.sh still passes, now using an
external vb2_verify_fw executable instead of a futility command.

Change-Id: Iee58df065e7a762369c5e691f6c2093de9122ed2
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/243630
2015-01-28 11:13:58 +00:00
Bill Richardson
40890c5cbb vboot2: Add stub implementation for vb2ex_printf()
BUG=none
BRANCH=ToT
TEST=manual

  make VBOOT2=1 DEBUG=1 runtests

Change-Id: I5e99082d713e2f8ad2c56a10b86d0e0a44037549
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/243360
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-01-28 08:01:31 +00:00
Bill Richardson
9bfe2c9f26 futility: vbutil_kernel should check the kernel a bit more
Trying to repack an invalid kernel blob should notice and
complain that the blob is invalid instead of just segfaulting.

BUG=chromium:452353
BRANCH=ToT
TEST=manual

See the bug report for an example test case. Many more tests are
being added as futility development continues.

Change-Id: I2bbfb8ab41a0f596b25a76f76f74d7b47b7e4a17
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/243583
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-01-28 01:56:09 +00:00
Bill Richardson
73e5eb3882 vboot2: fix alignment issues on 32-bit architectures
We were assuming 8-byte alignment for buffers. That's not true on
32-bit architectures. We should make the alignment requirements
explicit (and correct) for all architectures.

BUG=chromium:452179
BRANCH=ToT
CQ-DEPEND=CL:243380
TEST=manual

  USE=vboot2 FEATURES=test emerge-x86-alex vboot_reference

Change-Id: I120f23e9c5312d7c21ff9ebb6eea2bac1e430e37
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/243362
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-01-28 01:55:58 +00:00
Nam T. Nguyen
9a8dfd00ec cgpt_wrapper: Fix non-zero return code when okay
I forgot to reset "ret" to zero in the case the two hashes come out the
same. This CL fixes that silly logic bug.

BUG=None
BRANCH=None
TEST=`cgpt show /dev/mtd0` should exit with status 0

Change-Id: I1c64ea215c861c8afb44e235d090c72a5d006d55
Reviewed-on: https://chromium-review.googlesource.com/243325
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
Trybot-Ready: Nam Nguyen <namnguyen@chromium.org>
Tested-by: Nam Nguyen <namnguyen@chromium.org>
2015-01-27 00:22:11 +00:00
Furquan Shaikh
f620c0d656 cgptlib: Add functions to cgptlib API
Following changes are done to the cgptlib API in order to allow backend
component of fastboot to perform erase and write operations on
partitions and manipulate GPT entries:
GptFindNthEntry - Returns the nth entry in GPT that matches provided
GUID.
GptGetEntrySizeLba - Returns size of a partition in lba.
GptGetEntrySizeBytes - Returns size of a partition in bytes.
GptUpdateKernelWithEntry - Given kernel entry is updated using the
provided update_type. GptUpdateKernelEntry calls this function with
entry for current_kernel.

Add flags GPT_UPDATE_ENTRY_RESET and GPT_UPDATE_ENTRY_INVALID for
calls to GptUpdateKernelEntry. These operations are used by write
image and erase partition respectively.

BUG=chrome-os-partner:35861
BRANCH=None
TEST=Compiles successfully and all the newly added functions work as expected.

Change-Id: I82c87e4c97de2d207e80209dbd4922b4bcd5880a
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/240268
Trybot-Ready: Furquan Shaikh <furquan@chromium.org>
Tested-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Commit-Queue: Furquan Shaikh <furquan@chromium.org>
2015-01-24 01:46:02 +00:00