Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Unified Diff: utility/tpm-nvsize

Issue 3479003: Utility to measure the available size of a TPM NVRAM. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git
Patch Set: remove tabs Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | utility/tpmc.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utility/tpm-nvsize
diff --git a/utility/tpm-nvsize b/utility/tpm-nvsize
new file mode 100755
index 0000000000000000000000000000000000000000..ba5b46ff85bee57977b559f68cd6dc8df7b3a2be
--- /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
« no previous file with comments | « no previous file | utility/tpmc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698