aboutsummaryrefslogtreecommitdiff
path: root/NV.c
AgeCommit message (Collapse)Author
2017-12-08NV: allow reading FWMP before startupVadim Bendebury
This kludge makes sure that FWMP contents can be read even before TPM2_Startup command is issued, which makes sure that even on bricked protected Crhome OS devices CCD opening can be prevented. BRANCH=Cr50 BUG=b:62537474 TEST=verified that FWMP could be read even before AP is powered up Change-Id: I9693f7ff64ae86d8ed0d57c4079822ee56c464ee Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/817935 Reviewed-by: Andrey Pronin <apronin@chromium.org>
2017-01-04serialize objects in NVMEMVadim Bendebury
Reference implementation stores OBJECT structures in NVRAM unmarshaled, even though this structure layout is such that most of its 1540 bytes remain unused by the object stored in the structure. Marshaling the structure before storing it in NVMEM allows to save a lot of room there. To make sure that marshaling is not processing junk data, clear the entire structure before allocating a new OBJECT. This change is meant to be backwards compatible. When data is read from NVMEM, in case its size is equal the size of OBJECT structure, data is considered stored unmarshaled and is copied to the output directly. If the stored size is smaller - unmarshaling function is invoked. BUG=chrome-os-partner:60502 TEST=tcg test suite passes (not that it exercises this a lot, just five instances of storing/retrieving objects for the entire suite). Will test on real tpm to verify NVMEM storage format backwards compatibility. Also tried taking a chrome os device through enterprise enrollment. With the old code after enrollment there is room for just two eviction objects left: # command to retrieve number of objects in nvmem(is in the last # byte of the response) localhost ~ # trunks_send --raw 80 01 00 00 00 16 00 00 01 7a 00\ 00 00 06 00 00 02 08 00 00 00 01 80010000001B000000000100000006000000010000020800000003 # command to retrieve how many objects the tpm estimates it is # still possible to store in nvram (is in the last byte of the # response) localhost ~ # trunks_send --raw 80 01 00 00 00 16 00 00 01 7a \ 00 00 00 06 00 00 02 09 00 00 00 01 80010000001B000000000100000006000000010000020900000002 with the new code after enrollment the responses the above commands are: 80010000001B000000000100000006000000010000020800000003 80010000001B000000000100000006000000010000020900000004 That is with three objects stored there is room for 4 more objects. Also verified that the device enrolled with the old version of the cr50 firmware remains enrolled after firmware update, which demonstrates backward compatibility. Change-Id: Ic2d5f902220b451523b740b57edb7867441d1faa Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/424171 Reviewed-by: Andrey Pronin <apronin@chromium.org>
2016-12-02Introduce NVRAM storage format versioningVadim Bendebury
We want to be able to detect situations when NVRAM storage format changes for whatever reason. At the very least the NVRAM needs to be reinitialized, ideally its contents should be migrated from old to new storage format. This patch implements the reinitialization part. BUG=chrome-os-partner:60537 TEST=added some code to print out a message when NvInit() is invoked in NvCheckAndMigrateIfNeeded(). Verified that it is invoked on the first restart after upgrade to this new version. Change-Id: Ia713a6fe7814bbe44ed5ce28ebcc0435a99b7716 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/416294 Reviewed-by: Andrey Pronin <apronin@chromium.org>
2016-10-27Get firmware version values from the platformVadim Bendebury
For embedded targets, instead of hardcoding the firmware version values retrieve them using the recently added platform API. Do not store the version in the NVRAM - always get it from the platform, as firmware updates do not cause changes to the firmware version storing NVRAM locations set during manufacturing. The 8 bytes taken by the two firmware versions are still kept to avoid changing NVRAM persistent storage layout. CQ-DEPEND=CL:403115 BUG=chrome-os-partner:58177 TEST=verified that the expected values are returned for TPM firmware version: localhost ~ # tpm_version TPM 2.0 Version Info: Chip Version: 2.0.0.0 .... Firmware Version: 09004f2a08d73d07 (the first half is the zero prepended 7 characters of the ec SHA1, and the second half is the zero prepended 7 characters of the tpm2 SHA1). Change-Id: Id3b3ca15560d9ecb7af0d78abbd46e133707ee53 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/403213 Reviewed-by: Andrey Pronin <apronin@chromium.org>
2016-10-02NvIsAvailable() should report the current stateBill Richardson
The ExecuteCommand() function calls NvCheckState() to determine the current NV state before handling any command. Later, commands that use NV storage will call NvIsAvailable() to ensure that the NV state is still good. If it isn't, they should fail. But the NvIsAvailable() function doesn't actually detect changes. Instead, it just reports the original state that NvCheckState() saw. So if the NV state has changed when one of those NV storage functions calls NvIsAvailable(), the change won't be noticed until either NvCommit() is called or until the NEXT invocation of ExecuteCommand(). This CL causes NvIsAvailable() to actually be sure that the NV state is still good. BUG=none BRANCH=none TEST=run TCG tests, test on Gru (log in/out, reboot, etc.) All tests pass, no new failures seen (I didn't expect any) Change-Id: I7f1e713b760f068793513fc2426b2933e8971359 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/390752 Commit-Ready: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2015-08-18Allow compilation with -O2 flag, add -fPIC flag.Jocelyn Bohr
CL:292945 introduces CFLAGS environment variable, which contains -O2 in emerge environment. This patch fixes compiler errors "warning: dereferencing type-punned pointer will break strict-aliasing rules" introduced by using -O2 flag. This flag also introduces -fPIC when compiling not for embedded. This is needed to link against libtpm2. TEST=$ sudo emerge tpm2 builds libtpm2.a with all compiler flags $ sudo emerge tpm2-simulator builds tpm2-simulator The simulator works as before with trunks (can run --startup, --clear, and partially --own --owner_password="") $ make EMBEDDED_MODE=1 ROOTDIR=1 builds libtpm2.a for embedded BUG=none Change-Id: Iacc821fb840b653af1466edfaa8e5615fd73b36e Signed-off-by: Jocelyn Bohr <bohr@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/293815 Reviewed-by: Utkarsh Sanghi <usanghi@chromium.org>
2015-07-30Remove instances of calling marshal functions with NULL pointer.Jocelyn Bohr
In the code scraped from the TCG TPM2.0 Library specification, there are several instances where the intent is to marshal data into a buffer, but NULL pointer is passed in as size. Part 4 section 4.2.3.1 states: "If size is a NULL pointer, then no data is marshaled and the routine will compute the size of the memory required to marshal the indicated type." Implying these usages are bugs. This CL removes all instances of passing in NULL as size to a Marshal function when the intent is to marshal data. TEST=$ sudo emerge tpm2 builds libtpm2.a. Currently this is the only test we have for the scraped code. BUG=none Change-Id: If7b2a60f6a8e875b4a6eceab513dc22325bf4999 Reviewed-on: https://chromium-review.googlesource.com/289647 Reviewed-by: Utkarsh Sanghi <usanghi@chromium.org> Commit-Queue: Jocelyn Bohr <bohr@chromium.org> Tested-by: Jocelyn Bohr <bohr@chromium.org>
2015-06-05build: fix {INT}_TO_ARRAY macrosVadim Bendebury
Macros used to convert different size integers into arrays return integers themselves using the comma operator. GCC throws a 'value computed but not ussed' in this case, which can be pacified by appending (void) in front of the macro invocation. For some reason different invocations trigger GCC warnings inside and outside chroot. But the bottom line is that the code does not used the values returned by the macros, so a better fix is to change the macros not to return the values. BUG=none TEST=make succeeds for x86 both inside and outside chroot now. Change-Id: I8105b8051aee2cb72409dd70c5e5cfa4f841b549 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/275394 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2015-06-03Changes to allow compilation of NV.cVadim Bendebury
BUG=none TEST=compilation succeeds: cc -Wall -Werror -c -o /dev/null NV.c Change-Id: Ia114e64082e2dee1d1bb65ca8d8fc4974ce92a2e Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/274242 Reviewed-by: Utkarsh Sanghi <usanghi@chromium.org>
2015-05-20Initial commit to seed TPM2.0 source code directoryVadim Bendebury
LICENSE file text copied from TCG library specification. README describes the procedure used to extract source code from parts 3 and 4 of the specification. The python scripts and part{34}.txt files will be removed in the following commits. Change-Id: Ie281e6e988481831f33483053455e8aff8f3f75f Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>