diff options
author | Luigi Semenzato <semenzato@google.com> | 2010-09-21 14:12:15 -0700 |
---|---|---|
committer | Luigi Semenzato <semenzato@google.com> | 2010-09-21 14:12:15 -0700 |
commit | a8cba996b793547b2dab92c9808cf97b98e2a555 (patch) | |
tree | d0ceb47f927038054639c048b264c96df4307848 /utility/tpm-nvsize | |
parent | e19da8b8183edbbc41cbc651277b07c2362c6236 (diff) | |
download | vboot-a8cba996b793547b2dab92c9808cf97b98e2a555.tar.gz |
Utility to measure the available size of a TPM NVRAM.
Also change tpmc to return the TPM error code, or 255.
Change-Id: Ie5fc107ff50efd4480c2a47b91f3b8a93b4f95e3
BUG=none
TEST=ran it on a TPM
Review URL: http://codereview.chromium.org/3479003
Diffstat (limited to 'utility/tpm-nvsize')
-rwxr-xr-x | utility/tpm-nvsize | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/utility/tpm-nvsize b/utility/tpm-nvsize new file mode 100755 index 00000000..ba5b46ff --- /dev/null +++ b/utility/tpm-nvsize @@ -0,0 +1,50 @@ +#! /bin/sh -e +# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# Finds the largest NV space that can be defined on the TPM in this state +# (i.e. without removing existing spaces). +# +# The TPM must be unowned, and physical presence must be on. + +low=1 +high=1500 +try=$high + +# Binary search with no upper bound +while true; do + ## echo trying $try [ $low $high ] + if /usr/bin/tpmc definespace 0xf004 $(printf "0x%x" $try) 0x1 \ + > dev/null 2>&1; then + # definespace success: end, or $try must grow + if [ $try -eq $low ]; then + echo $low + exit 0 + elif [ $try -lt $high ]; then + low=$try + try=$(( ( $high + $low ) / 2 )) + else + # special case: when try == high, expand the search + low=$try + try=$(( $try * 2 )) + high=$try + fi + else + # check for unexpected errors + result=$? + if [ $result -ne 17 ]; then + echo running tpmc definespace 0xf004 0x1 0x1 + /usr/bin/tpmc definespace 0xf004 0x1 0x1 + echo please correct this condition and try again + exit 1 + fi + # definespace failure: end, or $try must shrink + if [ $try -eq $low ]; then + echo 0 + exit 0 + fi + high=$try + try=$(( ( $high + $low ) / 2 )) + fi +done |