Skip to contentSkip to conversation

Introduce TPMv2.0 support

PATCH New Miquel Raynal 3 participants 112 messages May 15, 2018 – May 27, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover Introduce TPMv2.0 support

Current U-Boot supports TPM v1.2 specification. The new specification (v2.0) is not backward compatible and renames/introduces several functions. This series introduces the support for TPMv2.x chips.

First, some cleaning is done in TPM-related code. Then, the code is split in two categories: generic code (common for both specifications) and specific code (only used by one specification).

Then, basic functionalities are introduced one by one for the v2.x specification. TPMv1 vs TPMv2 commands/support distinction is done with Kconfig options. Drivers of only one specification can be selected at a time.

A new SPI driver following the TPM v2.x specification is introduced. It has been tested on a ST TPM but should be usable with others v2.0 compliant chips.

Finally a full Python test suite is added, as well as a Sandbox driver. Regular testing may be done through the test/py/ framework when using real hardware as well as the Sandbox driver. The following test has run more than 300 times without failing with my setup:

        test/py/test.py --bd <board> -k tpm2

Available commands for v2.0 TPMs are:
* STARTUP
* SELF TEST
* CLEAR
* PCR EXTEND
* PCR READ
* GET CAPABILITY
* DICTIONARY ATTACK LOCK RESET
* DICTIONARY ATTACK CHANGE PARAMETERS
* HIERARCHY CHANGE AUTH

Two commands have been written but could not be tested (unsupported by the TPM chosen):
* PCR CHANGE AUTH POLICY
* PCR CHANGE AUTH VALUE

With this set of function, minimal TPMv2.0 handling is possible with the following sequence.

* First, initialize the TPM stack in U-Boot.

Quoted 1 line

tpm init

* Then send the STARTUP command to the TPM. The flag is slightly different between the revisions.

Quoted 1 line

tpm startup TPM2_SU_CLEAR

* To enable full TPM capabilities, continue the tests (or do them all again). It seems like self_test_full always waits for the operation to finish, while continue_self_test returns a busy state if called to early.

Quoted 2 lines

tpm self_test full
tpm self_test continue

* Manage passwords (force_clear also resets a lot of internal stuff). Olderly, TAKE OWNERSHIP == CLEAR + CHANGE AUTH. LOCKOUT is an example, ENDORSEMENT and PLATFORM hierarchies are available too:

Quoted 2 lines

tpm clear TPM2_RH_LOCKOUT [<pw>]
tpm change_auth TPM2_RH_LOCKOUT <new_pw> [<old_pw>]

* Dictionary Attack Mitigation (DAM) parameters can be changed. It is possible to reset the failure counter and disable the lockout (values erased after a CLEAR). It is then possible to check the parameters have been correctly applied.

Quoted 3 lines

tpm dam_reset [<pw>]
tpm dam_parameters 0xffff 1 0 [<pw>]
tpm get_capability 0x0006 0x020e 0x4000000 4

* PCR policy may be changed (untested).
PCR can be extended (no protection against packet replay yet). PCR can be read (the counter with the number of "extensions" is also given).

Quoted 3 lines

tpm pcr_setauthpolicy 0 12345678901234567890123456789012 [<pw>] tpm pcr_read 0 0x4000000
tpm pcr_extend 0 0x4000000

Thanks,
Miquèl

Changes since v3:
=================
* Added Simon Glass's RB tags.
* Moved all the small fixes about lines, alignments, spellings, etc out of the big commit splitting the TPM code structure. Multiple commits have been made for these changes. Now the split is still done in one commit, but it is supposed to be only code moves and headers changes.
* Used map_sysmem() calls to let Sandbox run TPM commands instead of my hack (allocating memory on the go).
* Updated the documentation to use the new way of declaring parameters:
s/@param x: y/@x: y/.
* Added two parameters in the chip private structure to store the number of PCRs and the minimum number of bytes needed to address one in a TPM command. This should fit all the TIS TPM2 compliant modules.
* The above change removes some (wrongly) hardcoded values.
* Changed the error path as suggested in tpm2_get_capability().
* Minor rephrasing.
* Explained in tpm2_get_capability() the offset '19'.
* Removed useless reset of rx_buf[0] in tpm_tis_spi_xfer().
* Changed the way spi_xfer return code is checked: error out on any value != 0 instead of just negative ones.
* Removed unused functions flagged __maybe_unused as well as well as the __maybe_unused flags themselves when not needed.
* Simplified the validity check of the GPIO as suggested.
* Updated the compatible property for the SPI modules (as well as the bindings docuementation) to be simply "tis,tpm2-spi" which should work with most compliant chips. Data is linked to this generic compatible in the TPM driver, other values may be added if needed in the future to fit other chips that would use different values than the current ones (used by Infineon SLB 9670 and ST ST33TPHF20 modules, for instance).

Changes since v2:
=================
* Wrote a full sandbox driver that passes _all_ the Python tests.
* Added changes in the library to support running in Sandbox.
* Did not rename the former I2C driver. Instead, will prefix new ones by "tpm2_" to make the distinction.
* Updated the Kconfig menu to have a clear separated view of the different drivers/specifications. CMD_TPM is now selected by a TPM_DRIVER_SELECTED boolean that is selected automatically when one driver at least is selected. One driver can only be selected if only one specification was precised (1.x or 2.x).
* Removed the styling fixes in the TPMv1.x command file as another one will be created.
* Removed the buffer length variable renaming as there is no need for it anymore.
* Split the whole architecture: for commands and library files, one tpm-common.c file plus one tpm-v<x>.c per specification. Same split for the header files. Some prototypes have been moved to lib/tpm-utils.h and cmd/tpm-user-utils.h depending on their use. This removed the need for an initialization with the right specification and the boilerplate coming with it.
* Commented all the TPMv2 enumerations.
* Renamed the macro U<XX>_TO_ARRAY into tpm_u<xx> as suggested.
* Dropped the buffer length name change as the files are split, there is no more need for such a rename.
* Added RB/AB tags.
* Used the new logging mechanism.
* Added documentation (bindings) for both drivers.
* Add the reset by GPIO in the SPI TPMv2.0 driver.
* Added a delay in the tests between the pcr_extend and the read_pcr.
* Ran the test suite a saw random errors sometimes, with a "LIB_ERROR". I wonder what produces these. Added traces to try to detect where it comes from.
* Some checkpatch.pl warnings have been left intentionally.

Changes since v1:
=================
* Complete test suite for the TPMv2 commands in test/py/.
* s/STRINGIFY<X>/U<X>_TO_ARRAY/ (the macros had nothing to do with actual "stringification").
* Changed/fixed some comments.

Miquel Raynal (32):
tpm: remove redundant blank line
tpm: remove extra spaces between a function and its opening bracket
tpm: substitute deprecated uint<x>_t types with their u<x> equivalent
tpm: align arguments with open parenthesis
tpm: use the BIT() macro where applicable
tpm: fix spelling
tpm: add extra blank lines between declarations and code
tpm: add Revision ID field in the chip structure
tpm: prepare introduction of TPMv2.x support in Kconfig
tpm: disociate TPMv1.x specific and generic code
tpm: add missing parameter in private data structure description
tpm: prepare support for TPMv2.x commands
tpm: add macros to enhance TPM commands readability
tpm: add possible traces to analyze buffers returned by the TPM
tpm: report driver error code to upper layer
tpm: add TPM2_Startup command support
tpm: add TPM2_SelfTest command support
tpm: add TPM2_Clear command support
tpm: add TPM2_PCR_Extend command support
tpm: add TPM2_PCR_Read command support
tpm: add TPM2_GetCapability command support
tpm: add dictionary attack mitigation commands support
tpm: add TPM2_HierarchyChangeAuth command support
tpm: add PCR authentication commands support
tpm: add support for TPMv2.x SPI modules
tpm: add the possibility to reset the chip with a gpio
doc: device-tree-bindings: add TIS TPMv2.0 SPI module info test/py: add TPMv2.x test suite
tpm: add a Sandbox TPMv2.x driver
doc: device-tree-bindings: add Sandbox TPMv2.0 module info
sandbox: dts: add Sandbox TPMv2.x node
configs: add TPMv2.x support in Sandbox

 arch/sandbox/dts/sandbox.dts                   |   4 +
 arch/sandbox/dts/sandbox64.dts                 |   4 +
 arch/sandbox/dts/test.dts                      |   4 +
 cmd/Kconfig                                    |  24 +-
 cmd/Makefile                                   |   4 +-
 cmd/tpm-common.c                               | 289 +++++++++++
 cmd/tpm-user-utils.h                           |  25 +
 cmd/{tpm.c => tpm-v1.c}                        | 488 ++++--------------
 cmd/tpm-v2.c                                   | 389 ++++++++++++++
 cmd/tpm_test.c                                 |   2 +-
 configs/sandbox64_defconfig                    |   1 +
 configs/sandbox_defconfig                      |   1 +
 configs/sandbox_flattree_defconfig             |   1 +
 configs/sandbox_noblk_defconfig                |   1 +
 configs/sandbox_spl_defconfig                  |   1 +
 doc/device-tree-bindings/tpm2/sandbox.txt      |  11 +
 doc/device-tree-bindings/tpm2/tis-tpm2-spi.txt |  18 +
 drivers/tpm/Kconfig                            |  83 ++-
 drivers/tpm/Makefile                           |   3 +
 drivers/tpm/tpm-uclass.c                       |   6 +-
 drivers/tpm/tpm2_tis_sandbox.c                 | 626 +++++++++++++++++++++++
 drivers/tpm/tpm2_tis_spi.c                     | 681 +++++++++++++++++++++++++
 drivers/tpm/tpm_atmel_twi.c                    |   2 +-
 drivers/tpm/tpm_tis.h                          |   1 +
 drivers/tpm/tpm_tis_infineon.c                 |   2 +-
 drivers/tpm/tpm_tis_lpc.c                      |   2 +-
 drivers/tpm/tpm_tis_sandbox.c                  |   2 +-
 drivers/tpm/tpm_tis_st33zp24_i2c.c             |   2 +-
 drivers/tpm/tpm_tis_st33zp24_spi.c             |   2 +-
 include/tpm-common.h                           | 218 ++++++++
 include/{tpm.h => tpm-v1.h}                    | 296 ++---------
 include/tpm-v2.h                               | 262 ++++++++++
 lib/Makefile                                   |   4 +-
 lib/tpm-common.c                               | 198 +++++++
 lib/tpm-utils.h                                | 102 ++++
 lib/{tpm.c => tpm-v1.c}                        | 600 +++++++---------------
 lib/tpm-v2.c                                   | 419 +++++++++++++++
 test/py/tests/test_tpm2.py                     | 234 +++++++++
 38 files changed, 3936 insertions(+), 1076 deletions(-)
 create mode 100644 cmd/tpm-common.c
 create mode 100644 cmd/tpm-user-utils.h
 rename cmd/{tpm.c => tpm-v1.c} (64%)
 create mode 100644 cmd/tpm-v2.c
 create mode 100644 doc/device-tree-bindings/tpm2/sandbox.txt
 create mode 100644 doc/device-tree-bindings/tpm2/tis-tpm2-spi.txt
 create mode 100644 drivers/tpm/tpm2_tis_sandbox.c
 create mode 100644 drivers/tpm/tpm2_tis_spi.c
 create mode 100644 include/tpm-common.h
 rename include/{tpm.h => tpm-v1.h} (60%)
 create mode 100644 include/tpm-v2.h
 create mode 100644 lib/tpm-common.c
 create mode 100644 lib/tpm-utils.h
 rename lib/{tpm.c => tpm-v1.c} (59%)
 create mode 100644 lib/tpm-v2.c
 create mode 100644 test/py/tests/test_tpm2.py
Signature · 1 line
2.14.1
#1 lore raw

PATCH v4 1/32 tpm: remove redundant blank line

Fix following checkpatch.pl issue in TPM-related code:

CHECK: Please don't use multiple blank lines

---
 lib/tpm.c | 1 -
 1 file changed, 1 deletion(-)
lib/tpm.c +0 -1
index c8bf06178f..0d8cdf9651 100644
@@ -821,7 +821,6 @@ static uint32_t verify_response_auth(uint32_t command_code,
 	return TPM_SUCCESS;
 }
 
-
 uint32_t tpm_terminate_auth_session(uint32_t auth_handle)
 {
 	const uint8_t command[18] = {
Signature · 1 line
2.14.1
#2 lore raw

PATCH v4 1/32 tpm: remove redundant blank line

Quoted 5 lines · Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

CHECK: Please don't use multiple blank lines

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/216169c7/attachment.sig>
#4 lore raw

PATCH v4 1/32 tpm: remove redundant blank line

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

CHECK: Please don't use multiple blank lines

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/2dafb32b/attachment.sig>
#5 lore raw

PATCH v4 2/32 tpm: remove extra spaces between a function and its opening bracket

In reply to Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

WARNING: space prohibited between function name and open parenthesis '('

---
 lib/tpm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/tpm.c +2 -2
index 0d8cdf9651..58b0a76b97 100644
@@ -611,7 +611,7 @@ uint32_t tpm_get_permanent_flags(struct tpm_permanent_flags *pflags)
 		0x0, 0x0, 0x1, 0x8,	/* subcap value */
 	};
 	const size_t data_size_offset = TPM_HEADER_SIZE;
-	const size_t data_offset = TPM_HEADER_SIZE + sizeof (uint32_t);
+	const size_t data_offset = TPM_HEADER_SIZE + sizeof(uint32_t);
 	uint8_t response[COMMAND_BUFFER_SIZE];
 	size_t response_length = sizeof(response);
 	uint32_t err;
@@ -1069,7 +1069,7 @@ uint32_t tpm_get_random(void *data, uint32_t count)
 
 	while (count > 0) {
 		uint32_t this_bytes = min((size_t)count,
-					  sizeof (response) - data_offset);
+					  sizeof(response) - data_offset);
 		uint32_t err;
 
 		if (pack_byte_string(buf, sizeof(buf), "sd",
Signature · 1 line
2.14.1
#6 lore raw

PATCH v4 2/32 tpm: remove extra spaces between a function and its opening bracket

Quoted 6 lines · Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

WARNING: space prohibited between function name and open parenthesis '('

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/2a9ea660/attachment.sig>
#8 lore raw

PATCH v4 2/32 tpm: remove extra spaces between a function and its opening bracket

In reply to Miquel Raynal
Quoted 8 lines · Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

WARNING: space prohibited between function name and open parenthesis '('

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/c0b1bae5/attachment.sig>
#9 lore raw

PATCH v4 3/32 tpm: substitute deprecated uint<x>_t types with their u<x> equivalent

In reply to Miquel Raynal

Fix following checkpatch.pl issues in TPM-related code:

CHECK: Prefer kernel type 'u8' over 'uint8_t'
CHECK: Prefer kernel type 'u16' over 'uint16_t'
CHECK: Prefer kernel type 'u32' over 'uint32_t'

---
 cmd/tpm.c     |  86 ++++++++---------
 include/tpm.h |  72 +++++++--------
 lib/tpm.c     | 290 +++++++++++++++++++++++++++++-----------------------------
 3 files changed, 220 insertions(+), 228 deletions(-)
cmd/tpm.c +43 -43
index d9b433582c..4109ace362 100644
@@ -25,7 +25,7 @@ enum {
  * @param data		byte string to be printed
  * @param count		number of bytes to be printed
  */
-static void print_byte_string(uint8_t *data, size_t count)
+static void print_byte_string(u8 *data, size_t count)
 {
 	int i, print_newline = 0;
 
@@ -52,7 +52,7 @@ static void print_byte_string(uint8_t *data, size_t count)
  * @param count_ptr	output variable for the length of byte string
  * @return pointer to output buffer
  */
-static void *parse_byte_string(char *bytes, uint8_t *data, size_t *count_ptr)
+static void *parse_byte_string(char *bytes, u8 *data, size_t *count_ptr)
 {
 	char byte[3];
 	size_t count, length;
@@ -72,7 +72,7 @@ static void *parse_byte_string(char *bytes, uint8_t *data, size_t *count_ptr)
 	for (i = 0; i < length; i += 2) {
 		byte[0] = bytes[i];
 		byte[1] = bytes[i + 1];
-		data[i / 2] = (uint8_t)simple_strtoul(byte, NULL, 16);
+		data[i / 2] = (u8)simple_strtoul(byte, NULL, 16);
 	}
 
 	if (count_ptr)
@@ -146,7 +146,7 @@ static size_t type_string_get_space_size(const char *type_str)
  * @param count		pointer for storing size of buffer
  * @return pointer to buffer or NULL on error
  */
-static void *type_string_alloc(const char *type_str, uint32_t *count)
+static void *type_string_alloc(const char *type_str, u32 *count)
 {
 	void *data;
 	size_t size;
@@ -171,10 +171,10 @@ static void *type_string_alloc(const char *type_str, uint32_t *count)
  * @return 0 on success, non-0 on error
  */
 static int type_string_pack(const char *type_str, char * const values[],
-		uint8_t *data)
+			    u8 *data)
 {
 	size_t offset;
-	uint32_t value;
+	u32 value;
 
 	for (offset = 0; *type_str; type_str++, values++) {
 		value = simple_strtoul(values[0], NULL, 0);
@@ -208,11 +208,11 @@ static int type_string_pack(const char *type_str, char * const values[],
  * @param vars		names of environment variables
  * @return 0 on success, non-0 on error
  */
-static int type_string_write_vars(const char *type_str, uint8_t *data,
-		char * const vars[])
+static int type_string_write_vars(const char *type_str, u8 *data,
+				  char * const vars[])
 {
 	size_t offset;
-	uint32_t value;
+	u32 value;
 
 	for (offset = 0; *type_str; type_str++, vars++) {
 		switch (*type_str) {
@@ -262,7 +262,7 @@ static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t index, perm, size;
+	u32 index, perm, size;
 
 	if (argc != 4)
 		return CMD_RET_USAGE;
@@ -276,7 +276,7 @@ static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t index, count, rc;
+	u32 index, count, rc;
 	void *data;
 
 	if (argc != 4)
@@ -297,7 +297,7 @@ static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t index, rc;
+	u32 index, rc;
 	size_t count;
 	void *data;
 
@@ -319,8 +319,8 @@ static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t index, rc;
-	uint8_t in_digest[20], out_digest[20];
+	u32 index, rc;
+	u8 in_digest[20], out_digest[20];
 
 	if (argc != 3)
 		return CMD_RET_USAGE;
@@ -342,7 +342,7 @@ static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t index, count, rc;
+	u32 index, count, rc;
 	void *data;
 
 	if (argc != 4)
@@ -363,11 +363,11 @@ static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint16_t presence;
+	u16 presence;
 
 	if (argc != 2)
 		return CMD_RET_USAGE;
-	presence = (uint16_t)simple_strtoul(argv[1], NULL, 0);
+	presence = (u16)simple_strtoul(argv[1], NULL, 0);
 
 	return report_return_code(tpm_tsc_physical_presence(presence));
 }
@@ -375,7 +375,7 @@ static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t count, rc;
+	u32 count, rc;
 	void *data;
 
 	if (argc != 3)
@@ -395,11 +395,11 @@ static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint8_t state;
+	u8 state;
 
 	if (argc != 2)
 		return CMD_RET_USAGE;
-	state = (uint8_t)simple_strtoul(argv[1], NULL, 0);
+	state = (u8)simple_strtoul(argv[1], NULL, 0);
 
 	return report_return_code(tpm_physical_set_deactivated(state));
 }
@@ -407,7 +407,7 @@ static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t cap_area, sub_cap, rc;
+	u32 cap_area, sub_cap, rc;
 	void *cap;
 	size_t count;
 
@@ -481,9 +481,9 @@ static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
 {
 	struct udevice *dev;
 	void *command;
-	uint8_t response[1024];
+	u8 response[1024];
 	size_t count, response_length = sizeof(response);
-	uint32_t rc;
+	u32 rc;
 
 	command = parse_byte_string(argv[1], NULL, &count);
 	if (!command) {
@@ -508,7 +508,7 @@ static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t index, perm, size;
+	u32 index, perm, size;
 
 	if (argc != 4)
 		return CMD_RET_USAGE;
@@ -526,7 +526,7 @@ static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t index, count, err;
+	u32 index, count, err;
 	void *data;
 
 	if (argc < 3)
@@ -555,7 +555,7 @@ static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t index, count, err;
+	u32 index, count, err;
 	void *data;
 
 	if (argc < 3)
@@ -585,7 +585,7 @@ static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t auth_handle, err;
+	u32 auth_handle, err;
 
 	err = tpm_oiap(&auth_handle);
 
@@ -596,10 +596,10 @@ static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_load_key_by_sha1(cmd_tbl_t *cmdtp, int flag, int argc, char *
 				   const argv[])
 {
-	uint32_t parent_handle = 0;
-	uint32_t key_len, key_handle, err;
-	uint8_t usage_auth[DIGEST_LENGTH];
-	uint8_t parent_hash[DIGEST_LENGTH];
+	u32 parent_handle = 0;
+	u32 key_len, key_handle, err;
+	u8 usage_auth[DIGEST_LENGTH];
+	u8 parent_hash[DIGEST_LENGTH];
 	void *key;
 
 	if (argc < 5)
@@ -634,8 +634,8 @@ static int do_tpm_load_key_by_sha1(cmd_tbl_t *cmdtp, int flag, int argc, char *
 static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t parent_handle, key_len, key_handle, err;
-	uint8_t usage_auth[DIGEST_LENGTH];
+	u32 parent_handle, key_len, key_handle, err;
+	u8 usage_auth[DIGEST_LENGTH];
 	void *key;
 
 	if (argc < 5)
@@ -659,9 +659,9 @@ static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag,
 static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag,
 		int argc, char * const argv[])
 {
-	uint32_t key_handle, err;
-	uint8_t usage_auth[DIGEST_LENGTH];
-	uint8_t pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
+	u32 key_handle, err;
+	u8 usage_auth[DIGEST_LENGTH];
+	u8 pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
 	size_t pub_key_len = sizeof(pub_key_buffer);
 
 	if (argc < 3)
@@ -721,9 +721,9 @@ static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc,
 	}
 
 	if (!strcasecmp(argv[2], "all")) {
-		uint16_t res_count;
-		uint8_t buf[288];
-		uint8_t *ptr;
+		u16 res_count;
+		u8 buf[288];
+		u8 *ptr;
 		int err;
 		uint i;
 
@@ -739,7 +739,7 @@ static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc,
 		for (i = 0; i < res_count; ++i, ptr += 4)
 			tpm_flush_specific(get_unaligned_be32(ptr), type);
 	} else {
-		uint32_t handle = simple_strtoul(argv[2], NULL, 0);
+		u32 handle = simple_strtoul(argv[2], NULL, 0);
 
 		if (!handle) {
 			printf("Illegal resource handle %s\n", argv[2]);
@@ -757,9 +757,9 @@ static int do_tpm_list(cmd_tbl_t *cmdtp, int flag, int argc,
 		       char * const argv[])
 {
 	int type = 0;
-	uint16_t res_count;
-	uint8_t buf[288];
-	uint8_t *ptr;
+	u16 res_count;
+	u8 buf[288];
+	u8 *ptr;
 	int err;
 	uint i;
 
include/tpm.h +34 -38

245 lines not on this page · raw message

lib/tpm.c +143 -147

688 lines not on this page · raw message

Signature · 1 line
2.14.1
#10 lore raw

PATCH v4 3/32 tpm: substitute deprecated uint<x>_t types with their u<x> equivalent

Quoted 7 lines · Miquel Raynal

Fix following checkpatch.pl issues in TPM-related code:

CHECK: Prefer kernel type 'u8' over 'uint8_t'
CHECK: Prefer kernel type 'u16' over 'uint16_t'
CHECK: Prefer kernel type 'u32' over 'uint32_t'

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/6d7396d0/attachment.sig>
#11 lore raw

PATCH v4 3/32 tpm: substitute deprecated uint<x>_t types with their u<x> equivalent

In reply to Miquel Raynal
Quoted 6 lines · Miquel Raynal

Fix following checkpatch.pl issues in TPM-related code:

CHECK: Prefer kernel type 'u8' over 'uint8_t'
CHECK: Prefer kernel type 'u16' over 'uint16_t'
CHECK: Prefer kernel type 'u32' over 'uint32_t'

Quoted 6 lines
---
 cmd/tpm.c     |  86 ++++++++---------
 include/tpm.h |  72 +++++++--------
 lib/tpm.c     | 290 +++++++++++++++++++++++++++++-----------------------------
 3 files changed, 220 insertions(+), 228 deletions(-)
#12 lore raw

PATCH v4 3/32 tpm: substitute deprecated uint<x>_t types with their u<x> equivalent

In reply to Miquel Raynal
Quoted 9 lines · Miquel Raynal

Fix following checkpatch.pl issues in TPM-related code:

CHECK: Prefer kernel type 'u8' over 'uint8_t'
CHECK: Prefer kernel type 'u16' over 'uint16_t'
CHECK: Prefer kernel type 'u32' over 'uint32_t'

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/9c2a6c7b/attachment.sig>
#13 lore raw

PATCH v4 4/32 tpm: align arguments with open parenthesis

In reply to Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

CHECK: Alignment should match open parenthesis

---
 cmd/tpm.c | 120 ++++++++++++++++++++++++++++++--------------------------------
 lib/tpm.c | 100 ++++++++++++++++++++++++++-------------------------
 2 files changed, 110 insertions(+), 110 deletions(-)
cmd/tpm.c +59 -61
index 4109ace362..a7ea1c9012 100644
@@ -238,8 +238,8 @@ static int type_string_write_vars(const char *type_str, u8 *data,
 	return 0;
 }
 
-static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag, int argc,
+			  char * const argv[])
 {
 	enum tpm_startup_type mode;
 
@@ -259,8 +259,8 @@ static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(tpm_startup(mode));
 }
 
-static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag, int argc,
+				  char * const argv[])
 {
 	u32 index, perm, size;
 
@@ -273,8 +273,8 @@ static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(tpm_nv_define_space(index, perm, size));
 }
 
-static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag, int argc,
+				char * const argv[])
 {
 	u32 index, count, rc;
 	void *data;
@@ -294,8 +294,8 @@ static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(rc);
 }
 
-static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag, int argc,
+				 char * const argv[])
 {
 	u32 index, rc;
 	size_t count;
@@ -316,8 +316,8 @@ static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(rc);
 }
 
-static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag, int argc,
+			 char * const argv[])
 {
 	u32 index, rc;
 	u8 in_digest[20], out_digest[20];
@@ -339,8 +339,8 @@ static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(rc);
 }
 
-static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc,
+			   char * const argv[])
 {
 	u32 index, count, rc;
 	void *data;
@@ -360,8 +360,8 @@ static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(rc);
 }
 
-static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag, int argc,
+					char * const argv[])
 {
 	u16 presence;
 
@@ -372,8 +372,8 @@ static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(tpm_tsc_physical_presence(presence));
 }
 
-static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag, int argc,
+			     char * const argv[])
 {
 	u32 count, rc;
 	void *data;
@@ -392,8 +392,8 @@ static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(rc);
 }
 
-static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag, int argc,
+					   char * const argv[])
 {
 	u8 state;
 
@@ -404,8 +404,8 @@ static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(tpm_physical_set_deactivated(state));
 }
 
-static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc,
+				 char * const argv[])
 {
 	u32 cap_area, sub_cap, rc;
 	void *cap;
@@ -429,7 +429,7 @@ static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag,
 
 #define TPM_COMMAND_NO_ARG(cmd)				\
 static int do_##cmd(cmd_tbl_t *cmdtp, int flag,		\
-		int argc, char * const argv[])		\
+		    int argc, char * const argv[])	\
 {							\
 	if (argc != 1)					\
 		return CMD_RET_USAGE;			\
@@ -456,8 +456,7 @@ static int get_tpm(struct udevice **devp)
 	return 0;
 }
 
-static int do_tpm_info(cmd_tbl_t *cmdtp, int flag, int argc,
-		       char *const argv[])
+static int do_tpm_info(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 {
 	struct udevice *dev;
 	char buf[80];
@@ -476,8 +475,8 @@ static int do_tpm_info(cmd_tbl_t *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag, int argc,
+			       char * const argv[])
 {
 	struct udevice *dev;
 	void *command;
@@ -505,8 +504,8 @@ static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(rc);
 }
 
-static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag, int argc,
+			    char * const argv[])
 {
 	u32 index, perm, size;
 
@@ -523,8 +522,8 @@ static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(tpm_nv_define_space(index, perm, size));
 }
 
-static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag, int argc,
+			  char * const argv[])
 {
 	u32 index, count, err;
 	void *data;
@@ -552,8 +551,8 @@ static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag,
 	return report_return_code(err);
 }
 
-static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag, int argc,
+			   char * const argv[])
 {
 	u32 index, count, err;
 	void *data;
@@ -582,8 +581,8 @@ static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag,
 
 #ifdef CONFIG_TPM_AUTH_SESSIONS
 
-static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
+		       char * const argv[])
 {
 	u32 auth_handle, err;
 
@@ -631,8 +630,8 @@ static int do_tpm_load_key_by_sha1(cmd_tbl_t *cmdtp, int flag, int argc, char *
 }
 #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
 
-static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
+				 char * const argv[])
 {
 	u32 parent_handle, key_len, key_handle, err;
 	u8 usage_auth[DIGEST_LENGTH];
@@ -649,15 +648,15 @@ static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag,
 	parse_byte_string(argv[4], usage_auth, NULL);
 
 	err = tpm_load_key2_oiap(parent_handle, key, key_len, usage_auth,
-			&key_handle);
+				 &key_handle);
 	if (!err)
 		printf("Key handle is 0x%x\n", key_handle);
 
 	return report_return_code(err);
 }
 
-static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag,
-		int argc, char * const argv[])
+static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
+				   char * const argv[])
 {
 	u32 key_handle, err;
 	u8 usage_auth[DIGEST_LENGTH];
@@ -672,8 +671,8 @@ static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	parse_byte_string(argv[2], usage_auth, NULL);
 
-	err = tpm_get_pub_key_oiap(key_handle, usage_auth,
-			pub_key_buffer, &pub_key_len);
+	err = tpm_get_pub_key_oiap(key_handle, usage_auth, pub_key_buffer,
+				   &pub_key_len);
 	if (!err) {
 		printf("dump of received pub key structure:\n");
 		print_byte_string(pub_key_buffer, pub_key_len);
@@ -819,46 +818,45 @@ static int do_tpm_list(cmd_tbl_t *cmdtp, int flag, int argc,
 
 static cmd_tbl_t tpm_commands[] = {
 	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
-	U_BOOT_CMD_MKENT(init, 0, 1,
-			do_tpm_init, "", ""),
+	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
 	U_BOOT_CMD_MKENT(startup, 0, 1,
-			do_tpm_startup, "", ""),
+			 do_tpm_startup, "", ""),
 	U_BOOT_CMD_MKENT(self_test_full, 0, 1,
-			do_tpm_self_test_full, "", ""),
+			 do_tpm_self_test_full, "", ""),
 	U_BOOT_CMD_MKENT(continue_self_test, 0, 1,
-			do_tpm_continue_self_test, "", ""),
+			 do_tpm_continue_self_test, "", ""),
 	U_BOOT_CMD_MKENT(force_clear, 0, 1,
-			do_tpm_force_clear, "", ""),
+			 do_tpm_force_clear, "", ""),
 	U_BOOT_CMD_MKENT(physical_enable, 0, 1,
-			do_tpm_physical_enable, "", ""),
+			 do_tpm_physical_enable, "", ""),
 	U_BOOT_CMD_MKENT(physical_disable, 0, 1,
-			do_tpm_physical_disable, "", ""),
+			 do_tpm_physical_disable, "", ""),
 	U_BOOT_CMD_MKENT(nv_define_space, 0, 1,
-			do_tpm_nv_define_space, "", ""),
+			 do_tpm_nv_define_space, "", ""),
 	U_BOOT_CMD_MKENT(nv_read_value, 0, 1,
-			do_tpm_nv_read_value, "", ""),
+			 do_tpm_nv_read_value, "", ""),
 	U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
-			do_tpm_nv_write_value, "", ""),
+			 do_tpm_nv_write_value, "", ""),
 	U_BOOT_CMD_MKENT(extend, 0, 1,
-			do_tpm_extend, "", ""),
+			 do_tpm_extend, "", ""),
 	U_BOOT_CMD_MKENT(pcr_read, 0, 1,
-			do_tpm_pcr_read, "", ""),
+			 do_tpm_pcr_read, "", ""),
 	U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
-			do_tpm_tsc_physical_presence, "", ""),
+			 do_tpm_tsc_physical_presence, "", ""),
 	U_BOOT_CMD_MKENT(read_pubek, 0, 1,
-			do_tpm_read_pubek, "", ""),
+			 do_tpm_read_pubek, "", ""),
 	U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1,
-			do_tpm_physical_set_deactivated, "", ""),
+			 do_tpm_physical_set_deactivated, "", ""),
 	U_BOOT_CMD_MKENT(get_capability, 0, 1,
-			do_tpm_get_capability, "", ""),
+			 do_tpm_get_capability, "", ""),
 	U_BOOT_CMD_MKENT(raw_transfer, 0, 1,
-			do_tpm_raw_transfer, "", ""),
+			 do_tpm_raw_transfer, "", ""),
 	U_BOOT_CMD_MKENT(nv_define, 0, 1,
-			do_tpm_nv_define, "", ""),
+			 do_tpm_nv_define, "", ""),
 	U_BOOT_CMD_MKENT(nv_read, 0, 1,
-			do_tpm_nv_read, "", ""),
+			 do_tpm_nv_read, "", ""),
 	U_BOOT_CMD_MKENT(nv_write, 0, 1,
-			do_tpm_nv_write, "", ""),
+			 do_tpm_nv_write, "", ""),
 #ifdef CONFIG_TPM_AUTH_SESSIONS
 	U_BOOT_CMD_MKENT(oiap, 0, 1,
 			 do_tpm_oiap, "", ""),
lib/tpm.c +51 -49

224 lines not on this page · raw message

Signature · 1 line
2.14.1
#14 lore raw

PATCH v4 4/32 tpm: align arguments with open parenthesis

Quoted 5 lines · Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

CHECK: Alignment should match open parenthesis

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/029d6539/attachment-0001.sig>
#15 lore raw

PATCH v4 4/32 tpm: align arguments with open parenthesis

In reply to Miquel Raynal
Quoted 9 lines · Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

CHECK: Alignment should match open parenthesis

---
 cmd/tpm.c | 120 ++++++++++++++++++++++++++++++--------------------------------
 lib/tpm.c | 100 ++++++++++++++++++++++++++-------------------------
 2 files changed, 110 insertions(+), 110 deletions(-)
#16 lore raw

PATCH v4 4/32 tpm: align arguments with open parenthesis

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

CHECK: Alignment should match open parenthesis

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/732f55cb/attachment.sig>
#17 lore raw

PATCH v4 5/32 tpm: use the BIT() macro where applicable

In reply to Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

CHECK: Prefer using the BIT macro

---
 include/tpm.h | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
include/tpm.h +7 -7
index 62117f6cc2..241597d879 100644
@@ -83,13 +83,13 @@ enum tpm_capability_areas {
 	TPM_CAP_VERSION_VAL	= 0x0000001A,
 };
 
-#define TPM_NV_PER_GLOBALLOCK		(1U << 15)
-#define TPM_NV_PER_PPREAD		(1U << 16)
-#define TPM_NV_PER_PPWRITE		(1U << 0)
-#define TPM_NV_PER_READ_STCLEAR		(1U << 31)
-#define TPM_NV_PER_WRITE_STCLEAR	(1U << 14)
-#define TPM_NV_PER_WRITEDEFINE		(1U << 13)
-#define TPM_NV_PER_WRITEALL		(1U << 12)
+#define TPM_NV_PER_GLOBALLOCK		BIT(15)
+#define TPM_NV_PER_PPREAD		BIT(16)
+#define TPM_NV_PER_PPWRITE		BIT(0)
+#define TPM_NV_PER_READ_STCLEAR		BIT(31)
+#define TPM_NV_PER_WRITE_STCLEAR	BIT(14)
+#define TPM_NV_PER_WRITEDEFINE		BIT(13)
+#define TPM_NV_PER_WRITEALL		BIT(12)
 
 enum {
 	TPM_PUBEK_SIZE			= 256,
Signature · 1 line
2.14.1
#18 lore raw

PATCH v4 5/32 tpm: use the BIT() macro where applicable

Quoted 5 lines · Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

CHECK: Prefer using the BIT macro

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/dc2be590/attachment.sig>
#20 lore raw

PATCH v4 5/32 tpm: use the BIT() macro where applicable

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

CHECK: Prefer using the BIT macro

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/04b4305a/attachment.sig>
#21 lore raw

PATCH v4 6/32 tpm: fix spelling

In reply to Miquel Raynal

Fix following checkpatch.pl issues in TPM-related code:

CHECK: '<x>' may be misspelled - perhaps '<y>'?

---
 include/tpm.h | 8 ++++----
 lib/tpm.c     | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
include/tpm.h +4 -4
index 241597d879..e1fc2ec252 100644
@@ -509,7 +509,7 @@ u32 tpm_tsc_physical_presence(u16 presence);
  * Issue a TPM_ReadPubek command.
  *
  * @param data		output buffer for the public endorsement key
- * @param count		size of ouput buffer
+ * @param count		size of output buffer
  * @return return code of the operation
  */
 u32 tpm_read_pubek(void *data, size_t count);
@@ -551,13 +551,13 @@ u32 tpm_physical_set_deactivated(u8 state);
  * @param sub_cap	further definition of capability, which is
  *			limited to be 4-byte wide
  * @param cap		output buffer for capability information
- * @param count		size of ouput buffer
+ * @param count		size of output buffer
  * @return return code of the operation
  */
 u32 tpm_get_capability(u32 cap_area, u32 sub_cap, void *cap, size_t count);
 
 /**
- * Issue a TPM_FlushSpecific command for a AUTH ressource.
+ * Issue a TPM_FlushSpecific command for a AUTH resource.
  *
  * @param auth_handle	handle of the auth session
  * @return return code of the operation
@@ -565,7 +565,7 @@ u32 tpm_get_capability(u32 cap_area, u32 sub_cap, void *cap, size_t count);
 u32 tpm_terminate_auth_session(u32 auth_handle);
 
 /**
- * Issue a TPM_OIAP command to setup an object independant authorization
+ * Issue a TPM_OIAP command to setup an object independent authorization
  * session.
  * Information about the session is stored internally.
  * If there was already an OIAP session active it is terminated and a new
lib/tpm.c +1 -1
index 0c57910f53..cc76a46e78 100644
@@ -826,7 +826,7 @@ u32 tpm_terminate_auth_session(u32 auth_handle)
 		0x00, 0x00, 0x00, 0x00,	/* parameter size */
 		0x00, 0x00, 0x00, 0xba,	/* TPM_COMMAND_CODE */
 		0x00, 0x00, 0x00, 0x00,	/* TPM_HANDLE */
-		0x00, 0x00, 0x00, 0x02,	/* TPM_RESSOURCE_TYPE */
+		0x00, 0x00, 0x00, 0x02,	/* TPM_RESOURCE_TYPE */
 	};
 	const size_t req_handle_offset = TPM_REQUEST_HEADER_LENGTH;
 	u8 request[COMMAND_BUFFER_SIZE];
Signature · 1 line
2.14.1
#22 lore raw

PATCH v4 6/32 tpm: fix spelling

Quoted 5 lines · Miquel Raynal

Fix following checkpatch.pl issues in TPM-related code:

CHECK: '<x>' may be misspelled - perhaps '<y>'?

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/faf90df6/attachment.sig>
#24 lore raw

PATCH v4 6/32 tpm: fix spelling

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Fix following checkpatch.pl issues in TPM-related code:

CHECK: '<x>' may be misspelled - perhaps '<y>'?

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/5684c5c9/attachment.sig>
#25 lore raw

PATCH v4 7/32 tpm: add extra blank lines between declarations and code

In reply to Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

WARNING: Missing a blank line after declarations

---
 lib/tpm.c | 3 +++
 1 file changed, 3 insertions(+)
lib/tpm.c +3 -0
index cc76a46e78..e8ebbbe6cd 100644
@@ -205,6 +205,7 @@ int unpack_byte_string(const u8 *str, size_t size, const char *format, ...)
 static u32 tpm_command_size(const void *command)
 {
 	const size_t command_size_offset = 2;
+
 	return get_unaligned_be32(command + command_size_offset);
 }
 
@@ -217,6 +218,7 @@ static u32 tpm_command_size(const void *command)
 static u32 tpm_return_code(const void *response)
 {
 	const size_t return_code_offset = 6;
+
 	return get_unaligned_be32(response + return_code_offset);
 }
 
@@ -844,6 +846,7 @@ u32 tpm_terminate_auth_session(u32 auth_handle)
 u32 tpm_end_oiap(void)
 {
 	u32 err = TPM_SUCCESS;
+
 	if (oiap_session.valid)
 		err = tpm_terminate_auth_session(oiap_session.handle);
 	return err;
Signature · 1 line
2.14.1
#26 lore raw

PATCH v4 7/32 tpm: add extra blank lines between declarations and code

Quoted 5 lines · Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

WARNING: Missing a blank line after declarations

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/d9d9f833/attachment.sig>
#28 lore raw

PATCH v4 7/32 tpm: add extra blank lines between declarations and code

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Fix following checkpatch.pl issue in TPM-related code:

WARNING: Missing a blank line after declarations

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/8b656378/attachment.sig>
#29 lore raw

PATCH v4 8/32 tpm: add Revision ID field in the chip structure

In reply to Miquel Raynal

TPM are shipped with a few read-only register from which we can retrieve for instance:
- vendor ID
- product ID
- revision ID

Product and vendor ID share the same register and are already referenced in the tpm_chip structure. Add the revision ID entry which is missing.

---
 drivers/tpm/tpm_tis.h | 1 +
 1 file changed, 1 insertion(+)
drivers/tpm/tpm_tis.h +1 -0
index 25b152b321..2b81f3be50 100644
@@ -41,6 +41,7 @@ struct tpm_chip {
 	int is_open;
 	int locality;
 	u32 vend_dev;
+	u8 rid;
 	unsigned long timeout_a, timeout_b, timeout_c, timeout_d;  /* msec */
 	ulong chip_type;
 };
Signature · 1 line
2.14.1
#30 lore raw

PATCH v4 8/32 tpm: add Revision ID field in the chip structure

Quoted 11 lines · Miquel Raynal

TPM are shipped with a few read-only register from which we can retrieve for instance:
- vendor ID
- product ID
- revision ID

Product and vendor ID share the same register and are already referenced in the tpm_chip structure. Add the revision ID entry which is missing.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/362c8046/attachment.sig>
#31 lore raw

PATCH v4 8/32 tpm: add Revision ID field in the chip structure

In reply to Miquel Raynal
Quoted 6 lines · Miquel Raynal

TPM are shipped with a few read-only register from which we can retrieve for instance:
- vendor ID
- product ID
- revision ID

Quoted 6 lines

Product and vendor ID share the same register and are already referenced in the tpm_chip structure. Add the revision ID entry which is missing.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/14fb11d1/attachment.sig>
#32 lore raw

PATCH v4 9/32 tpm: prepare introduction of TPMv2.x support in Kconfig

In reply to Miquel Raynal

Because both major revisions are not compatible at all, let's make them mutually exclusive in Kconfig. This way we will be sure, when using a command or a library function that it is supported by the right revision.

Current drivers are currently prefixed by "tpm_", we will prefix TPMv2.x files by "tpm2_" to make the distinction without moving everything.

The Kconfig menu about TPM drivers is now divided into two sections, one for each specification. Compliant drivers with one specification will only show up if this specification _only_ has been selected, otherwise a comment is displayed.

Once a driver is selected by the user, it selects automatically a boolean value, that is needed in order to activate the TPM commands. Selecting the TPM commands will automatically select the right command/library files.

---
 cmd/Kconfig         | 24 +++++++++++++++------
 cmd/Makefile        |  2 +-
 drivers/tpm/Kconfig | 62 +++++++++++++++++++++++++++++++++++++++++++----------
 lib/Makefile        |  2 +-
 4 files changed, 71 insertions(+), 19 deletions(-)
cmd/Kconfig +18 -6
index 136836d146..7c09c94d6d 100644
@@ -1354,25 +1354,37 @@ config HASH_VERIFY
 	help
 	  Add -v option to verify data against a hash.
 
+config CMD_TPM_V1
+	bool
+
+config CMD_TPM_V2
+	bool
+
 config CMD_TPM
 	bool "Enable the 'tpm' command"
-	depends on TPM
+	depends on TPM_DRIVER_SELECTED
+	select CMD_TPM_V1 if TPM_V1
+	select CMD_TPM_V2 if TPM_V2
 	help
 	  This provides a means to talk to a TPM from the command line. A wide
 	  range of commands if provided - see 'tpm help' for details. The
 	  command requires a suitable TPM on your board and the correct driver
 	  must be enabled.
 
+if CMD_TPM
+
 config CMD_TPM_TEST
 	bool "Enable the 'tpm test' command"
-	depends on CMD_TPM
+	depends on TPM_V1
 	help
-	  This provides a a series of tests to confirm that the TPM is working
-	  correctly. The tests cover initialisation, non-volatile RAM, extend,
-	  global lock and checking that timing is within expectations. The
-	  tests pass correctly on Infineon TPMs but may need to be adjusted
+	  This provides a a series of tests to confirm that the TPMv1.x is
+	  working correctly. The tests cover initialisation, non-volatile RAM,
+	  extend, global lock and checking that timing is within expectations.
+	  The tests pass correctly on Infineon TPMs but may need to be adjusted
 	  for other devices.
 
+endif
+
 endmenu
 
 menu "Firmware commands"
cmd/Makefile +1 -1
index 9a358e4801..bbeeb7e7f7 100644
@@ -117,7 +117,7 @@ obj-$(CONFIG_CMD_TERMINAL) += terminal.o
 obj-$(CONFIG_CMD_TIME) += time.o
 obj-$(CONFIG_CMD_TRACE) += trace.o
 obj-$(CONFIG_HUSH_PARSER) += test.o
-obj-$(CONFIG_CMD_TPM) += tpm.o
+obj-$(CONFIG_CMD_TPM_V1) += tpm.o
 obj-$(CONFIG_CMD_TPM_TEST) += tpm_test.o
 obj-$(CONFIG_CMD_CROS_EC) += cros_ec.o
 obj-$(CONFIG_CMD_TSI148) += tsi148.o
drivers/tpm/Kconfig +51 -11

131 lines not on this page · raw message

lib/Makefile +1 -1
index 0db41c19f3..9ec4a93043 100644
@@ -40,7 +40,7 @@ obj-$(CONFIG_PHYSMEM) += physmem.o
 obj-y += qsort.o
 obj-y += rc4.o
 obj-$(CONFIG_SUPPORT_EMMC_RPMB) += sha256.o
-obj-$(CONFIG_TPM) += tpm.o
+obj-$(CONFIG_TPM_V1) += tpm.o
 obj-$(CONFIG_RBTREE)	+= rbtree.o
 obj-$(CONFIG_BITREVERSE) += bitrev.o
 obj-y += list_sort.o
Signature · 1 line
2.14.1
#33 lore raw

PATCH v4 9/32 tpm: prepare introduction of TPMv2.x support in Kconfig

Quoted 13 lines · Miquel Raynal

Because both major revisions are not compatible at all, let's make them mutually exclusive in Kconfig. This way we will be sure, when using a command or a library function that it is supported by the right revision.

Current drivers are currently prefixed by "tpm_", we will prefix TPMv2.x files by "tpm2_" to make the distinction without moving everything.

The Kconfig menu about TPM drivers is now divided into two sections, one for each specification. Compliant drivers with one specification will only show up if this specification _only_ has been selected, otherwise a comment is displayed.

Quoted 7 lines

Once a driver is selected by the user, it selects automatically a boolean value, that is needed in order to activate the TPM commands. Selecting the TPM commands will automatically select the right command/library files.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/4918847c/attachment.sig>
#34 lore raw

PATCH v4 9/32 tpm: prepare introduction of TPMv2.x support in Kconfig

In reply to Miquel Raynal
Quoted 13 lines · Miquel Raynal

Because both major revisions are not compatible at all, let's make them mutually exclusive in Kconfig. This way we will be sure, when using a command or a library function that it is supported by the right revision.

Current drivers are currently prefixed by "tpm_", we will prefix TPMv2.x files by "tpm2_" to make the distinction without moving everything.

The Kconfig menu about TPM drivers is now divided into two sections, one for each specification. Compliant drivers with one specification will only show up if this specification _only_ has been selected, otherwise a comment is displayed.

Quoted 8 lines

Once a driver is selected by the user, it selects automatically a boolean value, that is needed in order to activate the TPM commands. Selecting the TPM commands will automatically select the right command/library files.

There was a thinko in here that I noticed when building for everything, that I have fixed. Both TPM_V1 and TPM_V2 need to depend on TPM (which comes from lib/Kconfig) otherwise we would start building TPMv1 support for all platforms. I also ended up dropping out TPM_DRIVER_SELECTED and instead making CMD_TPM depend on TPM_V1 || TPM_V2 as that ended up being a cleaner way to deal with the gdsys boards with TPM but without a dedicated driver exactly. With that fixed:

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/f572fb84/attachment.sig>
#35 lore raw

PATCH v4 9/32 tpm: prepare introduction of TPMv2.x support in Kconfig

Hi Tom,

Quoted 32 lines · Tom Rini
Quoted 13 lines · Miquel Raynal

Because both major revisions are not compatible at all, let's make them mutually exclusive in Kconfig. This way we will be sure, when using a command or a library function that it is supported by the right revision.

Current drivers are currently prefixed by "tpm_", we will prefix TPMv2.x files by "tpm2_" to make the distinction without moving everything.

The Kconfig menu about TPM drivers is now divided into two sections, one for each specification. Compliant drivers with one specification will only show up if this specification _only_ has been selected, otherwise a comment is displayed.

Quoted 8 lines

Once a driver is selected by the user, it selects automatically a boolean value, that is needed in order to activate the TPM commands. Selecting the TPM commands will automatically select the right command/library files.

There was a thinko in here that I noticed when building for everything, that I have fixed. Both TPM_V1 and TPM_V2 need to depend on TPM (which comes from lib/Kconfig) otherwise we would start building TPMv1 support for all platforms. I also ended up dropping out TPM_DRIVER_SELECTED and instead making CMD_TPM depend on TPM_V1 || TPM_V2 as that ended up being a cleaner way to deal with the gdsys boards with TPM but without a dedicated driver exactly. With that fixed:

Quoted 2 lines

Applied to u-boot/master, thanks!

Ok, thanks for the update.

Nice to see all that series merged!

Regards,
Miquèl

#36 lore raw

PATCH v4 10/32 tpm: disociate TPMv1.x specific and generic code

In reply to Miquel Raynal

There are no changes in this commit but a new organization of the code as follow.

* cmd/ directory:
> move existing code from cmd/tpm.c in cmd/tpm-common.c > move specific code in cmd/tpm-v1.c
> create a specific header file with generic definitions for
commands only called cmd/tpm-user-utils.h

* lib/ directory:
> move existing code from lib/tpm.c in lib/tpm-common.c > move specific code in lib/tpm-v1.c
> create a specific header file with generic definitions for
the library itself called lib/tpm-utils.h

* include/ directory:
> move existing code from include/tpm.h in include/tpm-common.h > move specific code in include/tpm-v1.h

Code designated as 'common' is compiled if TPM are used. Code designated as 'specific' is compiled only if the right specification has been selected.

All files include tpm-common.h.
Files in cmd/ include tpm-user-utils.h.
Files in lib/ include tpm-utils.h.
Depending on the specification, files may include either (not both) tpm-v1.h or tpm-v2.h.

---
 cmd/Makefile                       |   3 +-
 cmd/tpm-common.c                   | 289 +++++++++++++++++++++++++++++++++++
 cmd/tpm-user-utils.h               |  25 +++
 cmd/{tpm.c => tpm-v1.c}            | 304 ++-----------------------------------
 cmd/tpm_test.c                     |   2 +-
 drivers/tpm/tpm-uclass.c           |   4 +-
 drivers/tpm/tpm_atmel_twi.c        |   2 +-
 drivers/tpm/tpm_tis_infineon.c     |   2 +-
 drivers/tpm/tpm_tis_lpc.c          |   2 +-
 drivers/tpm/tpm_tis_sandbox.c      |   2 +-
 drivers/tpm/tpm_tis_st33zp24_i2c.c |   2 +-
 drivers/tpm/tpm_tis_st33zp24_spi.c |   2 +-
 include/tpm-common.h               | 211 +++++++++++++++++++++++++
 include/{tpm.h => tpm-v1.h}        | 214 ++------------------------
 lib/Makefile                       |   3 +-
 lib/tpm-common.c                   | 189 +++++++++++++++++++++++
 lib/tpm-utils.h                    |  96 ++++++++++++
 lib/{tpm.c => tpm-v1.c}            | 250 +-----------------------------
 18 files changed, 855 insertions(+), 747 deletions(-)
 create mode 100644 cmd/tpm-common.c
 create mode 100644 cmd/tpm-user-utils.h
 rename cmd/{tpm.c => tpm-v1.c} (76%)
 create mode 100644 include/tpm-common.h
 rename include/{tpm.h => tpm-v1.h} (70%)
 create mode 100644 lib/tpm-common.c
 create mode 100644 lib/tpm-utils.h
 rename lib/{tpm.c => tpm-v1.c} (81%)
cmd/Makefile +2 -1
index bbeeb7e7f7..66732085e8 100644
@@ -117,7 +117,8 @@ obj-$(CONFIG_CMD_TERMINAL) += terminal.o
 obj-$(CONFIG_CMD_TIME) += time.o
 obj-$(CONFIG_CMD_TRACE) += trace.o
 obj-$(CONFIG_HUSH_PARSER) += test.o
-obj-$(CONFIG_CMD_TPM_V1) += tpm.o
+obj-$(CONFIG_CMD_TPM) += tpm-common.o
+obj-$(CONFIG_CMD_TPM_V1) += tpm-v1.o
 obj-$(CONFIG_CMD_TPM_TEST) += tpm_test.o
 obj-$(CONFIG_CMD_CROS_EC) += cros_ec.o
 obj-$(CONFIG_CMD_TSI148) += tsi148.o
cmd/tpm-common.c new file +289 -0

289 lines not on this page · raw message

cmd/tpm-user-utils.h new file +25 -0
new file mode 100644
index 0000000000..6017090971
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2013 The Chromium OS Authors.
+ * Coypright (c) 2013 Guntermann & Drunck GmbH
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __TPM_USER_UTILS_H
+#define __TPM_USER_UTILS_H
+
+void print_byte_string(u8 *data, size_t count);
+void *parse_byte_string(char *bytes, u8 *data, size_t *count_ptr);
+int report_return_code(int return_code);
+int type_string_get_num_values(const char *type_str);
+size_t type_string_get_space_size(const char *type_str);
+void *type_string_alloc(const char *type_str, u32 *count);
+int type_string_pack(const char *type_str, char * const values[], u8 *data);
+int type_string_write_vars(const char *type_str, u8 *data, char * const vars[]);
+int get_tpm(struct udevice **devp);
+
+int do_tpm_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
+int do_tpm_info(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
+int do_tpm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+
+#endif /* __TPM_USER_UTILS_H */
cmd/tpm-v1.c renamed from cmd/tpm.c +13 -291

336 lines not on this page · raw message

cmd/tpm_test.c +1 -1
index 37ad2ff33d..c9d641f0ce 100644
@@ -7,7 +7,7 @@
 #include <common.h>
 #include <command.h>
 #include <environment.h>
-#include <tpm.h>
+#include <tpm-v1.h>
 
 /* Prints error and returns on failure */
 #define TPM_CHECK(tpm_command) do { \
drivers/tpm/tpm-uclass.c +3 -1
index b6e1fc5e62..eb0e511c8f 100644
@@ -7,8 +7,10 @@
 
 #include <common.h>
 #include <dm.h>
-#include <tpm.h>
 #include <linux/unaligned/be_byteshift.h>
+#if defined(CONFIG_TPM_V1)
+#include <tpm-v1.h>
+#endif
 #include "tpm_internal.h"
 
 int tpm_open(struct udevice *dev)
drivers/tpm/tpm_atmel_twi.c +1 -1
index 4fd772dc4f..a6f5a333dd 100644
@@ -8,7 +8,7 @@
 
 #include <common.h>
 #include <dm.h>
-#include <tpm.h>
+#include <tpm-v1.h>
 #include <i2c.h>
 #include <asm/unaligned.h>
 
drivers/tpm/tpm_tis_infineon.c +1 -1
index 41b748e7a2..30170afce0 100644
@@ -24,7 +24,7 @@
 #include <dm.h>
 #include <fdtdec.h>
 #include <i2c.h>
-#include <tpm.h>
+#include <tpm-v1.h>
 #include <linux/errno.h>
 #include <linux/compiler.h>
 #include <linux/types.h>
drivers/tpm/tpm_tis_lpc.c +1 -1
index c00a2d030b..bf955e73f2 100644
@@ -16,7 +16,7 @@
 #include <common.h>
 #include <dm.h>
 #include <mapmem.h>
-#include <tpm.h>
+#include <tpm-v1.h>
 #include <asm/io.h>
 
 #define PREFIX "lpc_tpm: "
drivers/tpm/tpm_tis_sandbox.c +1 -1
index e7746dc675..a19c1ba33d 100644
@@ -6,7 +6,7 @@
 
 #include <common.h>
 #include <dm.h>
-#include <tpm.h>
+#include <tpm-v1.h>
 #include <asm/state.h>
 #include <asm/unaligned.h>
 #include <linux/crc8.h>
drivers/tpm/tpm_tis_st33zp24_i2c.c +1 -1
index 245218fc07..21c2b56034 100644
@@ -17,7 +17,7 @@
 #include <dm.h>
 #include <fdtdec.h>
 #include <i2c.h>
-#include <tpm.h>
+#include <tpm-v1.h>
 #include <errno.h>
 #include <linux/types.h>
 #include <asm/unaligned.h>
drivers/tpm/tpm_tis_st33zp24_spi.c +1 -1
index c4c5e05286..07daad7beb 100644
@@ -17,7 +17,7 @@
 #include <dm.h>
 #include <fdtdec.h>
 #include <spi.h>
-#include <tpm.h>
+#include <tpm-v1.h>
 #include <errno.h>
 #include <linux/types.h>
 #include <asm/unaligned.h>
include/tpm-common.h new file +211 -0

211 lines not on this page · raw message

include/tpm-v1.h renamed from include/tpm.h +15 -199

231 lines not on this page · raw message

lib/Makefile +2 -1
index 9ec4a93043..2052954841 100644
@@ -40,7 +40,8 @@ obj-$(CONFIG_PHYSMEM) += physmem.o
 obj-y += qsort.o
 obj-y += rc4.o
 obj-$(CONFIG_SUPPORT_EMMC_RPMB) += sha256.o
-obj-$(CONFIG_TPM_V1) += tpm.o
+obj-$(CONFIG_TPM) += tpm-common.o
+obj-$(CONFIG_TPM_V1) += tpm-v1.o
 obj-$(CONFIG_RBTREE)	+= rbtree.o
 obj-$(CONFIG_BITREVERSE) += bitrev.o
 obj-y += list_sort.o
lib/tpm-common.c new file +189 -0

189 lines not on this page · raw message

lib/tpm-utils.h new file +96 -0

96 lines not on this page · raw message

lib/tpm-v1.c renamed from lib/tpm.c +3 -247

264 lines not on this page · raw message

Signature · 1 line
2.14.1
#37 lore raw

PATCH v4 10/32 tpm: disociate TPMv1.x specific and generic code

Quoted 23 lines · Miquel Raynal

There are no changes in this commit but a new organization of the code as follow.

* cmd/ directory:
> move existing code from cmd/tpm.c in cmd/tpm-common.c > move specific code in cmd/tpm-v1.c
> create a specific header file with generic definitions for
commands only called cmd/tpm-user-utils.h

* lib/ directory:
> move existing code from lib/tpm.c in lib/tpm-common.c > move specific code in lib/tpm-v1.c
> create a specific header file with generic definitions for
the library itself called lib/tpm-utils.h

* include/ directory:
> move existing code from include/tpm.h in include/tpm-common.h > move specific code in include/tpm-v1.h

Code designated as 'common' is compiled if TPM are used. Code designated as 'specific' is compiled only if the right specification has been selected.

Quoted 7 lines

All files include tpm-common.h.
Files in cmd/ include tpm-user-utils.h.
Files in lib/ include tpm-utils.h.
Depending on the specification, files may include either (not both) tpm-v1.h or tpm-v2.h.

Doing some out-of-band copy/diff'ing to check before/after in the parts git couldn't just see as a move looks good to me:

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/f430ecb5/attachment.sig>
#38 lore raw

PATCH v4 10/32 tpm: disociate TPMv1.x specific and generic code

In reply to Miquel Raynal
Quoted 23 lines · Miquel Raynal

There are no changes in this commit but a new organization of the code as follow.

* cmd/ directory:
> move existing code from cmd/tpm.c in cmd/tpm-common.c > move specific code in cmd/tpm-v1.c
> create a specific header file with generic definitions for
commands only called cmd/tpm-user-utils.h

* lib/ directory:
> move existing code from lib/tpm.c in lib/tpm-common.c > move specific code in lib/tpm-v1.c
> create a specific header file with generic definitions for
the library itself called lib/tpm-utils.h

* include/ directory:
> move existing code from include/tpm.h in include/tpm-common.h > move specific code in include/tpm-v1.h

Code designated as 'common' is compiled if TPM are used. Code designated as 'specific' is compiled only if the right specification has been selected.

Quoted 8 lines

All files include tpm-common.h.
Files in cmd/ include tpm-user-utils.h.
Files in lib/ include tpm-utils.h.
Depending on the specification, files may include either (not both) tpm-v1.h or tpm-v2.h.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/a08eb103/attachment.sig>
#39 lore raw

PATCH v4 11/32 tpm: add missing parameter in private data structure description

In reply to Miquel Raynal

Both parameters 'duration_ms' and 'retry_time_ms' of the tpm_chip_priv structure are documented is the comment above the declaration but 'buf' was forgotten. Add the missing description.

---
 include/tpm-common.h | 1 +
 1 file changed, 1 insertion(+)
include/tpm-common.h +1 -0
index ecc7bc067a..6b15466781 100644
@@ -36,6 +36,7 @@ enum tpm_duration {
  *
  * @duration_ms:	Length of each duration type in milliseconds
  * @retry_time_ms:	Time to wait before retrying receive
+ * @buf:		Buffer used during the exchanges with the chip
  */
 struct tpm_chip_priv {
 	uint duration_ms[TPM_DURATION_COUNT];
Signature · 1 line
2.14.1
#40 lore raw

PATCH v4 11/32 tpm: add missing parameter in private data structure description

Quoted 5 lines · Miquel Raynal

Both parameters 'duration_ms' and 'retry_time_ms' of the tpm_chip_priv structure are documented is the comment above the declaration but 'buf' was forgotten. Add the missing description.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/c62f2337/attachment.sig>
#41 lore raw

PATCH v4 11/32 tpm: add missing parameter in private data structure description

In reply to Miquel Raynal
Quoted 8 lines · Miquel Raynal

Both parameters 'duration_ms' and 'retry_time_ms' of the tpm_chip_priv structure are documented is the comment above the declaration but 'buf' was forgotten. Add the missing description.

---
 include/tpm-common.h | 1 +
 1 file changed, 1 insertion(+)
#42 lore raw

PATCH v4 11/32 tpm: add missing parameter in private data structure description

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Both parameters 'duration_ms' and 'retry_time_ms' of the tpm_chip_priv structure are documented is the comment above the declaration but 'buf' was forgotten. Add the missing description.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/62a31448/attachment.sig>
#43 lore raw

PATCH v4 12/32 tpm: prepare support for TPMv2.x commands

In reply to Miquel Raynal

Choice between v1 and v2 compliant functions is done with the configuration.

Create the various files that will receive TPMv2-only code on the same scheme as for the TPMv1 code.

---
 cmd/Makefile             |   1 +
 cmd/tpm-v2.c             |  33 ++++++++++++
 drivers/tpm/tpm-uclass.c |   2 +
 include/tpm-common.h     |   6 +++
 include/tpm-v2.h         | 128 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/Makefile             |   1 +
 lib/tpm-v2.c             |  11 ++++
 7 files changed, 182 insertions(+)
 create mode 100644 cmd/tpm-v2.c
 create mode 100644 include/tpm-v2.h
 create mode 100644 lib/tpm-v2.c
cmd/Makefile +1 -0
index 66732085e8..bdb5475e07 100644
@@ -120,6 +120,7 @@ obj-$(CONFIG_HUSH_PARSER) += test.o
 obj-$(CONFIG_CMD_TPM) += tpm-common.o
 obj-$(CONFIG_CMD_TPM_V1) += tpm-v1.o
 obj-$(CONFIG_CMD_TPM_TEST) += tpm_test.o
+obj-$(CONFIG_CMD_TPM_V2) += tpm-v2.o
 obj-$(CONFIG_CMD_CROS_EC) += cros_ec.o
 obj-$(CONFIG_CMD_TSI148) += tsi148.o
 obj-$(CONFIG_CMD_UBI) += ubi.o
cmd/tpm-v2.c new file +33 -0
new file mode 100644
index 0000000000..606aa92409
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier:	GPL-2.0+
+/*
+ * Copyright (c) 2018 Bootlin
+ * Author: Miquel Raynal <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <log.h>
+#include <tpm-common.h>
+#include <tpm-v2.h>
+#include "tpm-user-utils.h"
+
+static cmd_tbl_t tpm2_commands[] = {
+	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
+	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
+};
+
+cmd_tbl_t *get_tpm_commands(unsigned int *size)
+{
+	*size = ARRAY_SIZE(tpm2_commands);
+
+	return tpm2_commands;
+}
+
+U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
+"<command> [<arguments>]\n"
+"\n"
+"info\n"
+"    Show information about the TPM.\n"
+"init\n"
+"    Initialize the software stack. Always the first command to issue.\n"
+);
drivers/tpm/tpm-uclass.c +2 -0
index eb0e511c8f..cbf4873cbb 100644
@@ -10,6 +10,8 @@
 #include <linux/unaligned/be_byteshift.h>
 #if defined(CONFIG_TPM_V1)
 #include <tpm-v1.h>
+#elif defined(CONFIG_TPM_V2)
+#include <tpm-v2.h>
 #endif
 #include "tpm_internal.h"
 
include/tpm-common.h +6 -0
index 6b15466781..94f0f310b4 100644
@@ -36,11 +36,17 @@ enum tpm_duration {
  *
  * @duration_ms:	Length of each duration type in milliseconds
  * @retry_time_ms:	Time to wait before retrying receive
+ * @pcr_count:		Number of PCR per bank
+ * @pcr_select_min:	Minimum size in bytes of the pcrSelect array
  * @buf:		Buffer used during the exchanges with the chip
  */
 struct tpm_chip_priv {
 	uint duration_ms[TPM_DURATION_COUNT];
 	uint retry_time_ms;
+#if defined(CONFIG_TPM_V2)
+	uint pcr_count;
+	uint pcr_select_min;
+#endif
 	u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)];  /* Max buffer size + addr */
 };
 
include/tpm-v2.h new file +128 -0

128 lines not on this page · raw message

lib/Makefile +1 -0
index 2052954841..ddf8db6be8 100644
@@ -42,6 +42,7 @@ obj-y += rc4.o
 obj-$(CONFIG_SUPPORT_EMMC_RPMB) += sha256.o
 obj-$(CONFIG_TPM) += tpm-common.o
 obj-$(CONFIG_TPM_V1) += tpm-v1.o
+obj-$(CONFIG_TPM_V2) += tpm-v2.o
 obj-$(CONFIG_RBTREE)	+= rbtree.o
 obj-$(CONFIG_BITREVERSE) += bitrev.o
 obj-y += list_sort.o
lib/tpm-v2.c new file +11 -0
new file mode 100644
index 0000000000..ef4ebcd8ac
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier:	GPL-2.0+
+/*
+ * Copyright (c) 2018 Bootlin
+ * Author: Miquel Raynal <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <tpm-common.h>
+#include <tpm-v2.h>
+#include "tpm-utils.h"
Signature · 1 line
2.14.1
#44 lore raw

PATCH v4 12/32 tpm: prepare support for TPMv2.x commands

Quoted 8 lines · Miquel Raynal

Choice between v1 and v2 compliant functions is done with the configuration.

Create the various files that will receive TPMv2-only code on the same scheme as for the TPMv1 code.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/c743595e/attachment.sig>
#45 lore raw

PATCH v4 12/32 tpm: prepare support for TPMv2.x commands

In reply to Miquel Raynal
Quoted 9 lines · Miquel Raynal

Choice between v1 and v2 compliant functions is done with the configuration.

Create the various files that will receive TPMv2-only code on the same scheme as for the TPMv1 code.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/adc4d1d6/attachment.sig>
#46 lore raw

PATCH v4 13/32 tpm: add macros to enhance TPM commands readability

In reply to Miquel Raynal

TPM commands are much easier to read/write with these macros that will transform words or integers into byte strings. This way, there is no need to call pack_byte_string() while all variable length in a command are known (and at must 4 bytes, which is a lot of them).

---
 lib/tpm-utils.h | 6 ++++++
 1 file changed, 6 insertions(+)
lib/tpm-utils.h +6 -0
index 429da46232..9c875e6fa7 100644
@@ -13,6 +13,12 @@
 /* Internal error of TPM command library */
 #define TPM_LIB_ERROR ((u32)~0u)
 
+/* To make strings of commands more easily */
+#define __MSB(x) ((x) >> 8)
+#define __LSB(x) ((x) & 0xFF)
+#define tpm_u16(x) __MSB(x), __LSB(x)
+#define tpm_u32(x) tpm_u16((x) >> 16), tpm_u16((x) & 0xFFFF)
+
 /**
  * tpm_open() - Request access to locality 0 for the caller
  *
Signature · 1 line
2.14.1
#47 lore raw

PATCH v4 13/32 tpm: add macros to enhance TPM commands readability

Quoted 7 lines · Miquel Raynal

TPM commands are much easier to read/write with these macros that will transform words or integers into byte strings. This way, there is no need to call pack_byte_string() while all variable length in a command are known (and at must 4 bytes, which is a lot of them).

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/c0f770b9/attachment.sig>
#48 lore raw

PATCH v4 13/32 tpm: add macros to enhance TPM commands readability

In reply to Miquel Raynal
Quoted 8 lines · Miquel Raynal

TPM commands are much easier to read/write with these macros that will transform words or integers into byte strings. This way, there is no need to call pack_byte_string() while all variable length in a command are known (and at must 4 bytes, which is a lot of them).

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/ad32032c/attachment.sig>
#49 lore raw

PATCH v4 14/32 tpm: add possible traces to analyze buffers returned by the TPM

In reply to Miquel Raynal

When debugging, it is welcome to get more information about what the TPM returns. Add the possibility to print the packets received to show their exact content.

---
 lib/tpm-common.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
lib/tpm-common.c +9 -1
index 0812b73220..57832debf3 100644
@@ -154,6 +154,7 @@ u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr)
 	int err, ret;
 	u8 response_buffer[COMMAND_BUFFER_SIZE];
 	size_t response_length;
+	int i;
 
 	if (response) {
 		response_length = *size_ptr;
@@ -173,7 +174,14 @@ u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr)
 	if (size_ptr)
 		*size_ptr = response_length;
 
-	return tpm_return_code(response);
+	ret = tpm_return_code(response);
+
+	log(LOGC_NONE, LOGL_DEBUG, "TPM response [ret:%d]: ", ret);
+	for (i = 0; i < response_length; i++)
+		log(LOGC_NONE, LOGL_DEBUG, "%02x ", ((u8 *)response)[i]);
+	log(LOGC_NONE, LOGL_DEBUG, "\n");
+
+	return ret;
 }
 
 int tpm_init(void)
Signature · 1 line
2.14.1
#50 lore raw

PATCH v4 14/32 tpm: add possible traces to analyze buffers returned by the TPM

Quoted 6 lines · Miquel Raynal

When debugging, it is welcome to get more information about what the TPM returns. Add the possibility to print the packets received to show their exact content.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/58fad844/attachment.sig>
#51 lore raw

PATCH v4 14/32 tpm: add possible traces to analyze buffers returned by the TPM

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

When debugging, it is welcome to get more information about what the TPM returns. Add the possibility to print the packets received to show their exact content.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/ae4a9cc2/attachment.sig>
#52 lore raw

PATCH v4 15/32 tpm: report driver error code to upper layer

In reply to Miquel Raynal

Instead of returning a generic 'library' error, report back the actual error code so it can be displayed to the user by the regular error path.

---
 lib/tpm-common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/tpm-common.c +2 -1
index 57832debf3..08e2c2ad44 100644
@@ -170,7 +170,8 @@ u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr)
 		       response, &response_length);
 
 	if (err < 0)
-		return TPM_LIB_ERROR;
+		return err;
+
 	if (size_ptr)
 		*size_ptr = response_length;
 
Signature · 1 line
2.14.1
#53 lore raw

PATCH v4 15/32 tpm: report driver error code to upper layer

Quoted 5 lines · Miquel Raynal

Instead of returning a generic 'library' error, report back the actual error code so it can be displayed to the user by the regular error path.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/068ff1e0/attachment.sig>
#54 lore raw

PATCH v4 15/32 tpm: report driver error code to upper layer

In reply to Miquel Raynal
Quoted 6 lines · Miquel Raynal

Instead of returning a generic 'library' error, report back the actual error code so it can be displayed to the user by the regular error path.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/436cf742/attachment.sig>
#55 lore raw

PATCH v4 16/32 tpm: add TPM2_Startup command support

In reply to Miquel Raynal

Add support for the TPM2_Startup command.

Change the command file and the help accordingly.

---
 cmd/tpm-v2.c     | 26 ++++++++++++++++++++++++++
 include/tpm-v2.h |  9 +++++++++
 lib/tpm-v2.c     | 21 +++++++++++++++++++++
 3 files changed, 56 insertions(+)
cmd/tpm-v2.c +26 -0
index 606aa92409..d11820404e 100644
@@ -11,9 +11,30 @@
 #include <tpm-v2.h>
 #include "tpm-user-utils.h"
 
+static int do_tpm2_startup(cmd_tbl_t *cmdtp, int flag, int argc,
+			   char * const argv[])
+{
+	enum tpm2_startup_types mode;
+
+	if (argc != 2)
+		return CMD_RET_USAGE;
+
+	if (!strcasecmp("TPM2_SU_CLEAR", argv[1])) {
+		mode = TPM2_SU_CLEAR;
+	} else if (!strcasecmp("TPM2_SU_STATE", argv[1])) {
+		mode = TPM2_SU_STATE;
+	} else {
+		printf("Couldn't recognize mode string: %s\n", argv[1]);
+		return CMD_RET_FAILURE;
+	}
+
+	return report_return_code(tpm2_startup(mode));
+}
+
 static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
 	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
+	U_BOOT_CMD_MKENT(startup, 0, 1, do_tpm2_startup, "", ""),
 };
 
 cmd_tbl_t *get_tpm_commands(unsigned int *size)
@@ -30,4 +51,9 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 "    Show information about the TPM.\n"
 "init\n"
 "    Initialize the software stack. Always the first command to issue.\n"
+"startup <mode>\n"
+"    Issue a TPM2_Startup command.\n"
+"    <mode> is one of:\n"
+"        * TPM2_SU_CLEAR (reset state)\n"
+"        * TPM2_SU_STATE (preserved state)\n"
 );
include/tpm-v2.h +9 -0
index 09a7a8b183..b9d6488b4c 100644
@@ -125,4 +125,13 @@ enum tpm2_algorithms {
 	TPM2_ALG_NULL		= 0x10,
 };
 
+/**
+ * Issue a TPM2_Startup command.
+ *
+ * @mode	TPM startup mode
+ *
+ * @return code of the operation
+ */
+u32 tpm2_startup(enum tpm2_startup_types mode);
+
 #endif /* __TPM_V2_H */
lib/tpm-v2.c +21 -0
index ef4ebcd8ac..0d5ecebd32 100644
@@ -9,3 +9,24 @@
 #include <tpm-common.h>
 #include <tpm-v2.h>
 #include "tpm-utils.h"
+
+u32 tpm2_startup(enum tpm2_startup_types mode)
+{
+	const u8 command_v2[12] = {
+		tpm_u16(TPM2_ST_NO_SESSIONS),
+		tpm_u32(12),
+		tpm_u32(TPM2_CC_STARTUP),
+		tpm_u16(mode),
+	};
+	int ret;
+
+	/*
+	 * Note TPM2_Startup command will return RC_SUCCESS the first time,
+	 * but will return RC_INITIALIZE otherwise.
+	 */
+	ret = tpm_sendrecv_command(command_v2, NULL, NULL);
+	if (ret && ret != TPM2_RC_INITIALIZE)
+		return ret;
+
+	return 0;
+}
Signature · 1 line
2.14.1
#56 lore raw

PATCH v4 16/32 tpm: add TPM2_Startup command support

Quoted 6 lines · Miquel Raynal

Add support for the TPM2_Startup command.

Change the command file and the help accordingly.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/e7537cf6/attachment.sig>
#57 lore raw

PATCH v4 16/32 tpm: add TPM2_Startup command support

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Add support for the TPM2_Startup command.

Change the command file and the help accordingly.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/0c383094/attachment.sig>
#58 lore raw

PATCH v4 17/32 tpm: add TPM2_SelfTest command support

In reply to Miquel Raynal

Add support for the TPM2_Selftest command.

Change the command file and the help accordingly.

---
 cmd/tpm-v2.c     | 26 ++++++++++++++++++++++++++
 include/tpm-v2.h |  9 +++++++++
 lib/tpm-v2.c     | 12 ++++++++++++
 3 files changed, 47 insertions(+)
cmd/tpm-v2.c +26 -0
index d11820404e..1e746a7f09 100644
@@ -31,10 +31,31 @@ static int do_tpm2_startup(cmd_tbl_t *cmdtp, int flag, int argc,
 	return report_return_code(tpm2_startup(mode));
 }
 
+static int do_tpm2_self_test(cmd_tbl_t *cmdtp, int flag, int argc,
+			     char * const argv[])
+{
+	enum tpm2_yes_no full_test;
+
+	if (argc != 2)
+		return CMD_RET_USAGE;
+
+	if (!strcasecmp("full", argv[1])) {
+		full_test = TPMI_YES;
+	} else if (!strcasecmp("continue", argv[1])) {
+		full_test = TPMI_NO;
+	} else {
+		printf("Couldn't recognize test mode: %s\n", argv[1]);
+		return CMD_RET_FAILURE;
+	}
+
+	return report_return_code(tpm2_self_test(full_test));
+}
+
 static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
 	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
 	U_BOOT_CMD_MKENT(startup, 0, 1, do_tpm2_startup, "", ""),
+	U_BOOT_CMD_MKENT(self_test, 0, 1, do_tpm2_self_test, "", ""),
 };
 
 cmd_tbl_t *get_tpm_commands(unsigned int *size)
@@ -56,4 +77,9 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 "    <mode> is one of:\n"
 "        * TPM2_SU_CLEAR (reset state)\n"
 "        * TPM2_SU_STATE (preserved state)\n"
+"self_test <type>\n"
+"    Test the TPM capabilities.\n"
+"    <type> is one of:\n"
+"        * full (perform all tests)\n"
+"        * continue (only check untested tests)\n"
 );
include/tpm-v2.h +9 -0
index b9d6488b4c..f6d50a3a0b 100644
@@ -134,4 +134,13 @@ enum tpm2_algorithms {
  */
 u32 tpm2_startup(enum tpm2_startup_types mode);
 
+/**
+ * Issue a TPM2_SelfTest command.
+ *
+ * @full_test	Asking to perform all tests or only the untested ones
+ *
+ * @return code of the operation
+ */
+u32 tpm2_self_test(enum tpm2_yes_no full_test);
+
 #endif /* __TPM_V2_H */
lib/tpm-v2.c +12 -0
index 0d5ecebd32..c7156e569b 100644
@@ -30,3 +30,15 @@ u32 tpm2_startup(enum tpm2_startup_types mode)
 
 	return 0;
 }
+
+u32 tpm2_self_test(enum tpm2_yes_no full_test)
+{
+	const u8 command_v2[12] = {
+		tpm_u16(TPM2_ST_NO_SESSIONS),
+		tpm_u32(11),
+		tpm_u32(TPM2_CC_SELF_TEST),
+		full_test,
+	};
+
+	return tpm_sendrecv_command(command_v2, NULL, NULL);
+}
Signature · 1 line
2.14.1
#59 lore raw

PATCH v4 17/32 tpm: add TPM2_SelfTest command support

Quoted 6 lines · Miquel Raynal

Add support for the TPM2_Selftest command.

Change the command file and the help accordingly.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/1f564317/attachment.sig>
#60 lore raw

PATCH v4 17/32 tpm: add TPM2_SelfTest command support

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Add support for the TPM2_Selftest command.

Change the command file and the help accordingly.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/1611aae3/attachment.sig>
#61 lore raw

PATCH v4 18/32 tpm: add TPM2_Clear command support

In reply to Miquel Raynal

Add support for the TPM2_Clear command.

Change the command file and the help accordingly.

---
 cmd/tpm-v2.c     | 29 +++++++++++++++++++++++++++++
 include/tpm-v2.h | 11 +++++++++++
 lib/tpm-v2.c     | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+)
cmd/tpm-v2.c +29 -0
index 1e746a7f09..9f6a8fc0b6 100644
@@ -51,11 +51,35 @@ static int do_tpm2_self_test(cmd_tbl_t *cmdtp, int flag, int argc,
 	return report_return_code(tpm2_self_test(full_test));
 }
 
+static int do_tpm2_clear(cmd_tbl_t *cmdtp, int flag, int argc,
+			 char * const argv[])
+{
+	u32 handle = 0;
+	const char *pw = (argc < 3) ? NULL : argv[2];
+	const ssize_t pw_sz = pw ? strlen(pw) : 0;
+
+	if (argc < 2 || argc > 3)
+		return CMD_RET_USAGE;
+
+	if (pw_sz > TPM2_DIGEST_LEN)
+		return -EINVAL;
+
+	if (!strcasecmp("TPM2_RH_LOCKOUT", argv[1]))
+		handle = TPM2_RH_LOCKOUT;
+	else if (!strcasecmp("TPM2_RH_PLATFORM", argv[1]))
+		handle = TPM2_RH_PLATFORM;
+	else
+		return CMD_RET_USAGE;
+
+	return report_return_code(tpm2_clear(handle, pw, pw_sz));
+}
+
 static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
 	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
 	U_BOOT_CMD_MKENT(startup, 0, 1, do_tpm2_startup, "", ""),
 	U_BOOT_CMD_MKENT(self_test, 0, 1, do_tpm2_self_test, "", ""),
+	U_BOOT_CMD_MKENT(clear, 0, 1, do_tpm2_clear, "", ""),
 };
 
 cmd_tbl_t *get_tpm_commands(unsigned int *size)
@@ -82,4 +106,9 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 "    <type> is one of:\n"
 "        * full (perform all tests)\n"
 "        * continue (only check untested tests)\n"
+"clear <hierarchy>\n"
+"    Issue a TPM2_Clear command.\n"
+"    <hierarchy> is one of:\n"
+"        * TPM2_RH_LOCKOUT\n"
+"        * TPM2_RH_PLATFORM\n"
 );
include/tpm-v2.h +11 -0
index f6d50a3a0b..0d02e4a89b 100644
@@ -143,4 +143,15 @@ u32 tpm2_startup(enum tpm2_startup_types mode);
  */
 u32 tpm2_self_test(enum tpm2_yes_no full_test);
 
+/**
+ * Issue a TPM2_Clear command.
+ *
+ * @handle	Handle
+ * @pw		Password
+ * @pw_sz	Length of the password
+ *
+ * @return code of the operation
+ */
+u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz);
+
 #endif /* __TPM_V2_H */
lib/tpm-v2.c +35 -0
index c7156e569b..e3bfec5082 100644
@@ -42,3 +42,38 @@ u32 tpm2_self_test(enum tpm2_yes_no full_test)
 
 	return tpm_sendrecv_command(command_v2, NULL, NULL);
 }
+
+u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz)
+{
+	u8 command_v2[COMMAND_BUFFER_SIZE] = {
+		tpm_u16(TPM2_ST_SESSIONS),	/* TAG */
+		tpm_u32(27 + pw_sz),		/* Length */
+		tpm_u32(TPM2_CC_CLEAR),		/* Command code */
+
+		/* HANDLE */
+		tpm_u32(handle),		/* TPM resource handle */
+
+		/* AUTH_SESSION */
+		tpm_u32(9 + pw_sz),		/* Authorization size */
+		tpm_u32(TPM2_RS_PW),		/* Session handle */
+		tpm_u16(0),			/* Size of <nonce> */
+						/* <nonce> (if any) */
+		0,				/* Attributes: Cont/Excl/Rst */
+		tpm_u16(pw_sz),			/* Size of <hmac/password> */
+		/* STRING(pw)			   <hmac/password> (if any) */
+	};
+	unsigned int offset = 27;
+	int ret;
+
+	/*
+	 * Fill the command structure starting from the first buffer:
+	 *     - the password (if any)
+	 */
+	ret = pack_byte_string(command_v2, sizeof(command_v2), "s",
+			       offset, pw, pw_sz);
+	offset += pw_sz;
+	if (ret)
+		return TPM_LIB_ERROR;
+
+	return tpm_sendrecv_command(command_v2, NULL, NULL);
+}
Signature · 1 line
2.14.1
#62 lore raw

PATCH v4 18/32 tpm: add TPM2_Clear command support

Quoted 6 lines · Miquel Raynal

Add support for the TPM2_Clear command.

Change the command file and the help accordingly.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/1cf5df89/attachment.sig>
#63 lore raw

PATCH v4 18/32 tpm: add TPM2_Clear command support

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Add support for the TPM2_Clear command.

Change the command file and the help accordingly.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/3b65edf0/attachment.sig>
#64 lore raw

PATCH v4 19/32 tpm: add TPM2_PCR_Extend command support

In reply to Miquel Raynal

Add support for the TPM2_PCR_Extend command.

Change the command file and the help accordingly.

---
 cmd/tpm-v2.c     | 37 +++++++++++++++++++++++++++++++++++++
 include/tpm-v2.h | 10 ++++++++++
 lib/tpm-v2.c     | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)
cmd/tpm-v2.c +37 -0
index 9f6a8fc0b6..df6cd6919c 100644
@@ -7,6 +7,7 @@
 #include <common.h>
 #include <dm.h>
 #include <log.h>
+#include <mapmem.h>
 #include <tpm-common.h>
 #include <tpm-v2.h>
 #include "tpm-user-utils.h"
@@ -74,12 +75,44 @@ static int do_tpm2_clear(cmd_tbl_t *cmdtp, int flag, int argc,
 	return report_return_code(tpm2_clear(handle, pw, pw_sz));
 }
 
+static int do_tpm2_pcr_extend(cmd_tbl_t *cmdtp, int flag, int argc,
+			      char * const argv[])
+{
+	struct udevice *dev;
+	struct tpm_chip_priv *priv;
+	u32 index = simple_strtoul(argv[1], NULL, 0);
+	void *digest = map_sysmem(simple_strtoul(argv[2], NULL, 0), 0);
+	int ret;
+	u32 rc;
+
+	if (argc != 3)
+		return CMD_RET_USAGE;
+
+	ret = uclass_first_device_err(UCLASS_TPM, &dev);
+	if (ret)
+		return ret;
+
+	priv = dev_get_uclass_priv(dev);
+	if (!priv)
+		return -EINVAL;
+
+	if (index >= priv->pcr_count)
+		return -EINVAL;
+
+	rc = tpm2_pcr_extend(index, digest);
+
+	unmap_sysmem(digest);
+
+	return report_return_code(rc);
+}
+
 static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
 	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
 	U_BOOT_CMD_MKENT(startup, 0, 1, do_tpm2_startup, "", ""),
 	U_BOOT_CMD_MKENT(self_test, 0, 1, do_tpm2_self_test, "", ""),
 	U_BOOT_CMD_MKENT(clear, 0, 1, do_tpm2_clear, "", ""),
+	U_BOOT_CMD_MKENT(pcr_extend, 0, 1, do_tpm2_pcr_extend, "", ""),
 };
 
 cmd_tbl_t *get_tpm_commands(unsigned int *size)
@@ -111,4 +144,8 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 "    <hierarchy> is one of:\n"
 "        * TPM2_RH_LOCKOUT\n"
 "        * TPM2_RH_PLATFORM\n"
+"pcr_extend <pcr> <digest_addr>\n"
+"    Extend PCR #<pcr> with digest at <digest_addr>.\n"
+"    <pcr>: index of the PCR\n"
+"    <digest_addr>: address of a 32-byte SHA256 digest\n"
 );
include/tpm-v2.h +10 -0
index 0d02e4a89b..0706a925ce 100644
@@ -154,4 +154,14 @@ u32 tpm2_self_test(enum tpm2_yes_no full_test);
  */
 u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz);
 
+/**
+ * Issue a TPM2_PCR_Extend command.
+ *
+ * @index	Index of the PCR
+ * @digest	Value representing the event to be recorded
+ *
+ * @return code of the operation
+ */
+u32 tpm2_pcr_extend(u32 index, const uint8_t *digest);
+
 #endif /* __TPM_V2_H */
lib/tpm-v2.c +38 -0
index e3bfec5082..2696f8145d 100644
@@ -77,3 +77,41 @@ u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz)
 
 	return tpm_sendrecv_command(command_v2, NULL, NULL);
 }
+
+u32 tpm2_pcr_extend(u32 index, const uint8_t *digest)
+{
+	u8 command_v2[COMMAND_BUFFER_SIZE] = {
+		tpm_u16(TPM2_ST_SESSIONS),	/* TAG */
+		tpm_u32(33 + TPM2_DIGEST_LEN),	/* Length */
+		tpm_u32(TPM2_CC_PCR_EXTEND),	/* Command code */
+
+		/* HANDLE */
+		tpm_u32(index),			/* Handle (PCR Index) */
+
+		/* AUTH_SESSION */
+		tpm_u32(9),			/* Authorization size */
+		tpm_u32(TPM2_RS_PW),		/* Session handle */
+		tpm_u16(0),			/* Size of <nonce> */
+						/* <nonce> (if any) */
+		0,				/* Attributes: Cont/Excl/Rst */
+		tpm_u16(0),			/* Size of <hmac/password> */
+						/* <hmac/password> (if any) */
+		tpm_u32(1),			/* Count (number of hashes) */
+		tpm_u16(TPM2_ALG_SHA256),	/* Algorithm of the hash */
+		/* STRING(digest)		   Digest */
+	};
+	unsigned int offset = 33;
+	int ret;
+
+	/*
+	 * Fill the command structure starting from the first buffer:
+	 *     - the digest
+	 */
+	ret = pack_byte_string(command_v2, sizeof(command_v2), "s",
+			       offset, digest, TPM2_DIGEST_LEN);
+	offset += TPM2_DIGEST_LEN;
+	if (ret)
+		return TPM_LIB_ERROR;
+
+	return tpm_sendrecv_command(command_v2,	NULL, NULL);
+}
Signature · 1 line
2.14.1
#65 lore raw

PATCH v4 19/32 tpm: add TPM2_PCR_Extend command support

Quoted 6 lines · Miquel Raynal

Add support for the TPM2_PCR_Extend command.

Change the command file and the help accordingly.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/bd9c54fe/attachment.sig>
#66 lore raw

PATCH v4 19/32 tpm: add TPM2_PCR_Extend command support

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Add support for the TPM2_PCR_Extend command.

Change the command file and the help accordingly.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/58031f5b/attachment.sig>
#67 lore raw

PATCH v4 20/32 tpm: add TPM2_PCR_Read command support

In reply to Miquel Raynal

Add support for the TPM2_PCR_Read command.

Change the command file and the help accordingly.

---
 cmd/tpm-v2.c     | 43 +++++++++++++++++++++++++++++++++++++++++++
 include/tpm-v2.h | 13 +++++++++++++
 lib/tpm-v2.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 98 insertions(+)
cmd/tpm-v2.c +43 -0
index df6cd6919c..49c22aaeaa 100644
@@ -106,6 +106,44 @@ static int do_tpm2_pcr_extend(cmd_tbl_t *cmdtp, int flag, int argc,
 	return report_return_code(rc);
 }
 
+static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc,
+			   char * const argv[])
+{
+	struct udevice *dev;
+	struct tpm_chip_priv *priv;
+	u32 index, rc;
+	unsigned int updates;
+	void *data;
+	int ret;
+
+	if (argc != 3)
+		return CMD_RET_USAGE;
+
+	ret = uclass_first_device_err(UCLASS_TPM, &dev);
+	if (ret)
+		return ret;
+
+	priv = dev_get_uclass_priv(dev);
+	if (!priv)
+		return -EINVAL;
+
+	index = simple_strtoul(argv[1], NULL, 0);
+	if (index >= priv->pcr_count)
+		return -EINVAL;
+
+	data = map_sysmem(simple_strtoul(argv[2], NULL, 0), 0);
+
+	rc = tpm2_pcr_read(index, priv->pcr_select_min, data, &updates);
+	if (!rc) {
+		printf("PCR #%u content (%d known updates):\n", index, updates);
+		print_byte_string(data, TPM2_DIGEST_LEN);
+	}
+
+	unmap_sysmem(data);
+
+	return report_return_code(rc);
+}
+
 static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
 	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
@@ -113,6 +151,7 @@ static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(self_test, 0, 1, do_tpm2_self_test, "", ""),
 	U_BOOT_CMD_MKENT(clear, 0, 1, do_tpm2_clear, "", ""),
 	U_BOOT_CMD_MKENT(pcr_extend, 0, 1, do_tpm2_pcr_extend, "", ""),
+	U_BOOT_CMD_MKENT(pcr_read, 0, 1, do_tpm_pcr_read, "", ""),
 };
 
 cmd_tbl_t *get_tpm_commands(unsigned int *size)
@@ -148,4 +187,8 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 "    Extend PCR #<pcr> with digest at <digest_addr>.\n"
 "    <pcr>: index of the PCR\n"
 "    <digest_addr>: address of a 32-byte SHA256 digest\n"
+"pcr_read <pcr> <digest_addr>\n"
+"    Read PCR #<pcr> to memory address <digest_addr>.\n"
+"    <pcr>: index of the PCR\n"
+"    <digest_addr>: address to store the a 32-byte SHA256 digest\n"
 );
include/tpm-v2.h +13 -0
index 0706a925ce..b9f36b22ba 100644
@@ -164,4 +164,17 @@ u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz);
  */
 u32 tpm2_pcr_extend(u32 index, const uint8_t *digest);
 
+/**
+ * Issue a TPM2_PCR_Read command.
+ *
+ * @idx		Index of the PCR
+ * @idx_min_sz	Minimum size in bytes of the pcrSelect array
+ * @data	Output buffer for contents of the named PCR
+ * @updates	Optional out parameter: number of updates for this PCR
+ *
+ * @return code of the operation
+ */
+u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data,
+		  unsigned int *updates);
+
 #endif /* __TPM_V2_H */
lib/tpm-v2.c +42 -0

45 lines not on this page · raw message

Signature · 1 line
2.14.1
#68 lore raw

PATCH v4 20/32 tpm: add TPM2_PCR_Read command support

Quoted 6 lines · Miquel Raynal

Add support for the TPM2_PCR_Read command.

Change the command file and the help accordingly.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/b73deff1/attachment.sig>
#69 lore raw

PATCH v4 20/32 tpm: add TPM2_PCR_Read command support

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Add support for the TPM2_PCR_Read command.

Change the command file and the help accordingly.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/a27f223a/attachment.sig>
#70 lore raw

PATCH v4 21/32 tpm: add TPM2_GetCapability command support

In reply to Miquel Raynal

Add support for the TPM2_GetCapability command.

Change the command file and the help accordingly.

---
 cmd/tpm-v2.c     | 45 +++++++++++++++++++++++++++++++++++++++++++++
 include/tpm-v2.h | 14 ++++++++++++++
 lib/tpm-v2.c     | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+)
cmd/tpm-v2.c +45 -0
index 49c22aaeaa..3599763e90 100644
@@ -144,6 +144,43 @@ static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc,
 	return report_return_code(rc);
 }
 
+static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc,
+				 char * const argv[])
+{
+	u32 capability, property, rc;
+	u8 *data;
+	size_t count;
+	int i, j;
+
+	if (argc != 5)
+		return CMD_RET_USAGE;
+
+	capability = simple_strtoul(argv[1], NULL, 0);
+	property = simple_strtoul(argv[2], NULL, 0);
+	data = map_sysmem(simple_strtoul(argv[3], NULL, 0), 0);
+	count = simple_strtoul(argv[4], NULL, 0);
+
+	rc = tpm2_get_capability(capability, property, data, count);
+	if (rc)
+		goto unmap_data;
+
+	printf("Capabilities read from TPM:\n");
+	for (i = 0; i < count; i++) {
+		printf("Property 0x");
+		for (j = 0; j < 4; j++)
+			printf("%02x", data[(i * 8) + j]);
+		printf(": 0x");
+		for (j = 4; j < 8; j++)
+			printf("%02x", data[(i * 8) + j]);
+		printf("\n");
+	}
+
+unmap_data:
+	unmap_sysmem(data);
+
+	return report_return_code(rc);
+}
+
 static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
 	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
@@ -152,6 +189,7 @@ static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(clear, 0, 1, do_tpm2_clear, "", ""),
 	U_BOOT_CMD_MKENT(pcr_extend, 0, 1, do_tpm2_pcr_extend, "", ""),
 	U_BOOT_CMD_MKENT(pcr_read, 0, 1, do_tpm_pcr_read, "", ""),
+	U_BOOT_CMD_MKENT(get_capability, 0, 1, do_tpm_get_capability, "", ""),
 };
 
 cmd_tbl_t *get_tpm_commands(unsigned int *size)
@@ -191,4 +229,11 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 "    Read PCR #<pcr> to memory address <digest_addr>.\n"
 "    <pcr>: index of the PCR\n"
 "    <digest_addr>: address to store the a 32-byte SHA256 digest\n"
+"get_capability <capability> <property> <addr> <count>\n"
+"    Read and display <count> entries indexed by <capability>/<property>.\n"
+"    Values are 4 bytes long and are written at <addr>.\n"
+"    <capability>: capability\n"
+"    <property>: property\n"
+"    <addr>: address to store <count> entries of 4 bytes\n"
+"    <count>: number of entries to retrieve\n"
 );
include/tpm-v2.h +14 -0
index b9f36b22ba..618026ce2a 100644
@@ -177,4 +177,18 @@ u32 tpm2_pcr_extend(u32 index, const uint8_t *digest);
 u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data,
 		  unsigned int *updates);
 
+/**
+ * Issue a TPM2_GetCapability command.  This implementation is limited
+ * to query property index that is 4-byte wide.
+ *
+ * @capability	Partition of capabilities
+ * @property	Further definition of capability, limited to be 4 bytes wide
+ * @buf		Output buffer for capability information
+ * @prop_count	Size of output buffer
+ *
+ * @return code of the operation
+ */
+u32 tpm2_get_capability(u32 capability, u32 property, void *buf,
+			size_t prop_count);
+
 #endif /* __TPM_V2_H */
lib/tpm-v2.c +33 -0
index a1f1dbc3d6..330844ee31 100644
@@ -157,3 +157,36 @@ u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data,
 
 	return 0;
 }
+
+u32 tpm2_get_capability(u32 capability, u32 property, void *buf,
+			size_t prop_count)
+{
+	u8 command_v2[COMMAND_BUFFER_SIZE] = {
+		tpm_u16(TPM2_ST_NO_SESSIONS),		/* TAG */
+		tpm_u32(22),				/* Length */
+		tpm_u32(TPM2_CC_GET_CAPABILITY),	/* Command code */
+
+		tpm_u32(capability),			/* Capability */
+		tpm_u32(property),			/* Property */
+		tpm_u32(prop_count),			/* Property count */
+	};
+	u8 response[COMMAND_BUFFER_SIZE];
+	size_t response_len = COMMAND_BUFFER_SIZE;
+	unsigned int properties_off;
+	int ret;
+
+	ret = tpm_sendrecv_command(command_v2, response, &response_len);
+	if (ret)
+		return ret;
+
+	/*
+	 * In the response buffer, the properties are located after the:
+	 * tag (u16), response size (u32), response code (u32),
+	 * YES/NO flag (u8), TPM_CAP (u32) and TPMU_CAPABILITIES (u32).
+	 */
+	properties_off = sizeof(u16) + sizeof(u32) + sizeof(u32) +
+			 sizeof(u8) + sizeof(u32) + sizeof(u32);
+	memcpy(buf, &response[properties_off], response_len - properties_off);
+
+	return 0;
+}
Signature · 1 line
2.14.1
#71 lore raw

PATCH v4 21/32 tpm: add TPM2_GetCapability command support

Quoted 6 lines · Miquel Raynal

Add support for the TPM2_GetCapability command.

Change the command file and the help accordingly.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/43ac03a1/attachment.sig>
#72 lore raw

PATCH v4 21/32 tpm: add TPM2_GetCapability command support

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Add support for the TPM2_GetCapability command.

Change the command file and the help accordingly.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/7504fe57/attachment.sig>
#73 lore raw

PATCH v4 22/32 tpm: add dictionary attack mitigation commands support

In reply to Miquel Raynal

Add support for the TPM2_DictionaryAttackParameters and TPM2_DictionaryAttackLockReset commands.

Change the command file and the help accordingly.

---
 cmd/tpm-v2.c     | 67 +++++++++++++++++++++++++++++++++++++++++++++
 include/tpm-v2.h | 25 +++++++++++++++++
 lib/tpm-v2.c     | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 175 insertions(+)
cmd/tpm-v2.c +67 -0
index 3599763e90..5e3ebc7984 100644
@@ -181,6 +181,59 @@ unmap_data:
 	return report_return_code(rc);
 }
 
+static int do_tpm_dam_reset(cmd_tbl_t *cmdtp, int flag, int argc,
+			    char *const argv[])
+{
+	const char *pw = (argc < 2) ? NULL : argv[1];
+	const ssize_t pw_sz = pw ? strlen(pw) : 0;
+
+	if (argc > 2)
+		return CMD_RET_USAGE;
+
+	if (pw_sz > TPM2_DIGEST_LEN)
+		return -EINVAL;
+
+	return report_return_code(tpm2_dam_reset(pw, pw_sz));
+}
+
+static int do_tpm_dam_parameters(cmd_tbl_t *cmdtp, int flag, int argc,
+				 char *const argv[])
+{
+	const char *pw = (argc < 5) ? NULL : argv[4];
+	const ssize_t pw_sz = pw ? strlen(pw) : 0;
+	/*
+	 * No Dictionary Attack Mitigation (DAM) means:
+	 * maxtries = 0xFFFFFFFF, recovery_time = 1, lockout_recovery = 0
+	 */
+	unsigned long int max_tries;
+	unsigned long int recovery_time;
+	unsigned long int lockout_recovery;
+
+	if (argc < 4 || argc > 5)
+		return CMD_RET_USAGE;
+
+	if (pw_sz > TPM2_DIGEST_LEN)
+		return -EINVAL;
+
+	if (strict_strtoul(argv[1], 0, &max_tries))
+		return CMD_RET_USAGE;
+
+	if (strict_strtoul(argv[2], 0, &recovery_time))
+		return CMD_RET_USAGE;
+
+	if (strict_strtoul(argv[3], 0, &lockout_recovery))
+		return CMD_RET_USAGE;
+
+	log(LOGC_NONE, LOGL_INFO, "Changing dictionary attack parameters:\n");
+	log(LOGC_NONE, LOGL_INFO, "- maxTries: %lu", max_tries);
+	log(LOGC_NONE, LOGL_INFO, "- recoveryTime: %lu\n", recovery_time);
+	log(LOGC_NONE, LOGL_INFO, "- lockoutRecovery: %lu\n", lockout_recovery);
+
+	return report_return_code(tpm2_dam_parameters(pw, pw_sz, max_tries,
+						      recovery_time,
+						      lockout_recovery));
+}
+
 static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
 	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
@@ -190,6 +243,8 @@ static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(pcr_extend, 0, 1, do_tpm2_pcr_extend, "", ""),
 	U_BOOT_CMD_MKENT(pcr_read, 0, 1, do_tpm_pcr_read, "", ""),
 	U_BOOT_CMD_MKENT(get_capability, 0, 1, do_tpm_get_capability, "", ""),
+	U_BOOT_CMD_MKENT(dam_reset, 0, 1, do_tpm_dam_reset, "", ""),
+	U_BOOT_CMD_MKENT(dam_parameters, 0, 1, do_tpm_dam_parameters, "", ""),
 };
 
 cmd_tbl_t *get_tpm_commands(unsigned int *size)
@@ -236,4 +291,16 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 "    <property>: property\n"
 "    <addr>: address to store <count> entries of 4 bytes\n"
 "    <count>: number of entries to retrieve\n"
+"  dam_reset_counter [<password>]\n"
+"    - If the TPM is not in a LOCKOUT state, reset the internal error\n"
+"      counter (TPMv2 only)\n"
+"  dam_set_parameters <maxTries> <recoveryTime> <lockoutRecovery> [<password>]\n"
+"    - If the TPM is not in a LOCKOUT state, set the dictionary attack\n"
+"      parameters:\n"
+"          * maxTries: maximum number of failures before lockout.\n"
+"                          0 means always locking.\n"
+"          * recoveryTime: time before decrementation of the error counter,\n"
+"                          0 means no lockout.\n"
+"          * lockoutRecovery: time of a lockout (before the next try)\n"
+"                          0 means a reboot is needed.\n"
 );
include/tpm-v2.h +25 -0
index 618026ce2a..4e182cf827 100644
@@ -191,4 +191,29 @@ u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data,
 u32 tpm2_get_capability(u32 capability, u32 property, void *buf,
 			size_t prop_count);
 
+/**
+ * Issue a TPM2_DictionaryAttackLockReset command.
+ *
+ * @pw		Password
+ * @pw_sz	Length of the password
+ *
+ * @return code of the operation
+ */
+u32 tpm2_dam_reset(const char *pw, const ssize_t pw_sz);
+
+/**
+ * Issue a TPM2_DictionaryAttackParameters command.
+ *
+ * @pw		Password
+ * @pw_sz	Length of the password
+ * @max_tries	Count of authorizations before lockout
+ * @recovery_time Time before decrementation of the failure count
+ * @lockout_recovery Time to wait after a lockout
+ *
+ * @return code of the operation
+ */
+u32 tpm2_dam_parameters(const char *pw, const ssize_t pw_sz,
+			unsigned int max_tries, unsigned int recovery_time,
+			unsigned int lockout_recovery);
+
 #endif /* __TPM_V2_H */
lib/tpm-v2.c +83 -0

86 lines not on this page · raw message

Signature · 1 line
2.14.1
#74 lore raw

PATCH v4 22/32 tpm: add dictionary attack mitigation commands support

Quoted 7 lines · Miquel Raynal

Add support for the TPM2_DictionaryAttackParameters and TPM2_DictionaryAttackLockReset commands.

Change the command file and the help accordingly.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/7d44cb2f/attachment.sig>
#75 lore raw

PATCH v4 22/32 tpm: add dictionary attack mitigation commands support

In reply to Miquel Raynal
Quoted 8 lines · Miquel Raynal

Add support for the TPM2_DictionaryAttackParameters and TPM2_DictionaryAttackLockReset commands.

Change the command file and the help accordingly.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/6028ba8d/attachment.sig>
#76 lore raw

PATCH v4 23/32 tpm: add TPM2_HierarchyChangeAuth command support

In reply to Miquel Raynal

Add support for the TPM2_HierarchyChangeAuth command.

Change the command file and the help accordingly.

---
 cmd/tpm-v2.c     | 59 ++++++++++++++++++++++++++++++++++++++++++++------------
 include/tpm-v2.h | 14 ++++++++++++++
 lib/tpm-v2.c     | 44 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 12 deletions(-)
cmd/tpm-v2.c +47 -12
index 5e3ebc7984..b52409846b 100644
@@ -234,6 +234,36 @@ static int do_tpm_dam_parameters(cmd_tbl_t *cmdtp, int flag, int argc,
 						      lockout_recovery));
 }
 
+static int do_tpm_change_auth(cmd_tbl_t *cmdtp, int flag, int argc,
+			      char *const argv[])
+{
+	u32 handle;
+	const char *newpw = argv[2];
+	const char *oldpw = (argc == 3) ? NULL : argv[3];
+	const ssize_t newpw_sz = strlen(newpw);
+	const ssize_t oldpw_sz = oldpw ? strlen(oldpw) : 0;
+
+	if (argc < 3 || argc > 4)
+		return CMD_RET_USAGE;
+
+	if (newpw_sz > TPM2_DIGEST_LEN || oldpw_sz > TPM2_DIGEST_LEN)
+		return -EINVAL;
+
+	if (!strcasecmp("TPM2_RH_LOCKOUT", argv[1]))
+		handle = TPM2_RH_LOCKOUT;
+	else if (!strcasecmp("TPM2_RH_ENDORSEMENT", argv[1]))
+		handle = TPM2_RH_ENDORSEMENT;
+	else if (!strcasecmp("TPM2_RH_OWNER", argv[1]))
+		handle = TPM2_RH_OWNER;
+	else if (!strcasecmp("TPM2_RH_PLATFORM", argv[1]))
+		handle = TPM2_RH_PLATFORM;
+	else
+		return CMD_RET_USAGE;
+
+	return report_return_code(tpm2_change_auth(handle, newpw, newpw_sz,
+						   oldpw, oldpw_sz));
+}
+
 static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
 	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
@@ -245,6 +275,7 @@ static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(get_capability, 0, 1, do_tpm_get_capability, "", ""),
 	U_BOOT_CMD_MKENT(dam_reset, 0, 1, do_tpm_dam_reset, "", ""),
 	U_BOOT_CMD_MKENT(dam_parameters, 0, 1, do_tpm_dam_parameters, "", ""),
+	U_BOOT_CMD_MKENT(change_auth, 0, 1, do_tpm_change_auth, "", ""),
 };
 
 cmd_tbl_t *get_tpm_commands(unsigned int *size)
@@ -291,16 +322,20 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 "    <property>: property\n"
 "    <addr>: address to store <count> entries of 4 bytes\n"
 "    <count>: number of entries to retrieve\n"
-"  dam_reset_counter [<password>]\n"
-"    - If the TPM is not in a LOCKOUT state, reset the internal error\n"
-"      counter (TPMv2 only)\n"
-"  dam_set_parameters <maxTries> <recoveryTime> <lockoutRecovery> [<password>]\n"
-"    - If the TPM is not in a LOCKOUT state, set the dictionary attack\n"
-"      parameters:\n"
-"          * maxTries: maximum number of failures before lockout.\n"
-"                          0 means always locking.\n"
-"          * recoveryTime: time before decrementation of the error counter,\n"
-"                          0 means no lockout.\n"
-"          * lockoutRecovery: time of a lockout (before the next try)\n"
-"                          0 means a reboot is needed.\n"
+"dam_reset [<password>]\n"
+"    If the TPM is not in a LOCKOUT state, reset the internal error counter.\n"
+"    <password>: optional password\n"
+"dam_parameters <max_tries> <recovery_time> <lockout_recovery> [<password>]\n"
+"    If the TPM is not in a LOCKOUT state, set the DAM parameters\n"
+"    <maxTries>: maximum number of failures before lockout,\n"
+"                0 means always locking\n"
+"    <recoveryTime>: time before decrement of the error counter,\n"
+"                    0 means no lockout\n"
+"    <lockoutRecovery>: time of a lockout (before the next try),\n"
+"                       0 means a reboot is needed\n"
+"    <password>: optional password of the LOCKOUT hierarchy\n"
+"change_auth <hierarchy> <new_pw> [<old_pw>]\n"
+"    <hierarchy>: the hierarchy\n"
+"    <new_pw>: new password for <hierarchy>\n"
+"    <old_pw>: optional previous password of <hierarchy>\n"
 );
include/tpm-v2.h +14 -0
index 4e182cf827..19f0ecd80b 100644
@@ -216,4 +216,18 @@ u32 tpm2_dam_parameters(const char *pw, const ssize_t pw_sz,
 			unsigned int max_tries, unsigned int recovery_time,
 			unsigned int lockout_recovery);
 
+/**
+ * Issue a TPM2_HierarchyChangeAuth command.
+ *
+ * @handle	Handle
+ * @newpw	New password
+ * @newpw_sz	Length of the new password
+ * @oldpw	Old password
+ * @oldpw_sz	Length of the old password
+ *
+ * @return code of the operation
+ */
+int tpm2_change_auth(u32 handle, const char *newpw, const ssize_t newpw_sz,
+		     const char *oldpw, const ssize_t oldpw_sz);
+
 #endif /* __TPM_V2_H */
lib/tpm-v2.c +44 -0

47 lines not on this page · raw message

Signature · 1 line
2.14.1
#77 lore raw

PATCH v4 23/32 tpm: add TPM2_HierarchyChangeAuth command support

Quoted 6 lines · Miquel Raynal

Add support for the TPM2_HierarchyChangeAuth command.

Change the command file and the help accordingly.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/51a48c65/attachment.sig>
#78 lore raw

PATCH v4 23/32 tpm: add TPM2_HierarchyChangeAuth command support

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Add support for the TPM2_HierarchyChangeAuth command.

Change the command file and the help accordingly.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/d63c9804/attachment.sig>
#79 lore raw

PATCH v4 24/32 tpm: add PCR authentication commands support

In reply to Miquel Raynal

Add support for the TPM2_PCR_SetAuthPolicy and
TPM2_PCR_SetAuthValue commands.

Change the command file and the help accordingly.

Note: These commands could not be tested because the TPMs available do not support them, however they could be useful for someone else. The user is warned by the command help.

---
 cmd/tpm-v2.c     |  48 ++++++++++++++++++++++++++
 include/tpm-v2.h |  29 ++++++++++++++++
 lib/tpm-v2.c     | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 177 insertions(+)
cmd/tpm-v2.c +48 -0
index b52409846b..6d7d6cabbd 100644
@@ -264,6 +264,43 @@ static int do_tpm_change_auth(cmd_tbl_t *cmdtp, int flag, int argc,
 						   oldpw, oldpw_sz));
 }
 
+static int do_tpm_pcr_setauthpolicy(cmd_tbl_t *cmdtp, int flag, int argc,
+				    char * const argv[])
+{
+	u32 index = simple_strtoul(argv[1], NULL, 0);
+	char *key = argv[2];
+	const char *pw = (argc < 4) ? NULL : argv[3];
+	const ssize_t pw_sz = pw ? strlen(pw) : 0;
+
+	if (strlen(key) != TPM2_DIGEST_LEN)
+		return -EINVAL;
+
+	if (argc < 3 || argc > 4)
+		return CMD_RET_USAGE;
+
+	return report_return_code(tpm2_pcr_setauthpolicy(pw, pw_sz, index,
+							 key));
+}
+
+static int do_tpm_pcr_setauthvalue(cmd_tbl_t *cmdtp, int flag,
+				   int argc, char * const argv[])
+{
+	u32 index = simple_strtoul(argv[1], NULL, 0);
+	char *key = argv[2];
+	const ssize_t key_sz = strlen(key);
+	const char *pw = (argc < 4) ? NULL : argv[3];
+	const ssize_t pw_sz = pw ? strlen(pw) : 0;
+
+	if (strlen(key) != TPM2_DIGEST_LEN)
+		return -EINVAL;
+
+	if (argc < 3 || argc > 4)
+		return CMD_RET_USAGE;
+
+	return report_return_code(tpm2_pcr_setauthvalue(pw, pw_sz, index,
+							key, key_sz));
+}
+
 static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
 	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
@@ -276,6 +313,10 @@ static cmd_tbl_t tpm2_commands[] = {
 	U_BOOT_CMD_MKENT(dam_reset, 0, 1, do_tpm_dam_reset, "", ""),
 	U_BOOT_CMD_MKENT(dam_parameters, 0, 1, do_tpm_dam_parameters, "", ""),
 	U_BOOT_CMD_MKENT(change_auth, 0, 1, do_tpm_change_auth, "", ""),
+	U_BOOT_CMD_MKENT(pcr_setauthpolicy, 0, 1,
+			 do_tpm_pcr_setauthpolicy, "", ""),
+	U_BOOT_CMD_MKENT(pcr_setauthvalue, 0, 1,
+			 do_tpm_pcr_setauthvalue, "", ""),
 };
 
 cmd_tbl_t *get_tpm_commands(unsigned int *size)
@@ -338,4 +379,11 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
 "    <hierarchy>: the hierarchy\n"
 "    <new_pw>: new password for <hierarchy>\n"
 "    <old_pw>: optional previous password of <hierarchy>\n"
+"pcr_setauthpolicy|pcr_setauthvalue <pcr> <key> [<password>]\n"
+"    Change the <key> to access PCR #<pcr>.\n"
+"    hierarchy and may be empty.\n"
+"    /!\\WARNING: untested function, use at your own risks !\n"
+"    <pcr>: index of the PCR\n"
+"    <key>: secret to protect the access of PCR #<pcr>\n"
+"    <password>: optional password of the PLATFORM hierarchy\n"
 );
include/tpm-v2.h +29 -0
index 19f0ecd80b..b7820b405d 100644
@@ -80,11 +80,13 @@ enum tpm2_command_codes {
 	TPM2_CC_CLEAR		= 0x0126,
 	TPM2_CC_CLEARCONTROL	= 0x0127,
 	TPM2_CC_HIERCHANGEAUTH	= 0x0129,
+	TPM2_CC_PCR_SETAUTHPOL	= 0x012C,
 	TPM2_CC_DAM_RESET	= 0x0139,
 	TPM2_CC_DAM_PARAMETERS	= 0x013A,
 	TPM2_CC_GET_CAPABILITY	= 0x017A,
 	TPM2_CC_PCR_READ	= 0x017E,
 	TPM2_CC_PCR_EXTEND	= 0x0182,
+	TPM2_CC_PCR_SETAUTHVAL	= 0x0183,
 };
 
 /**
@@ -230,4 +232,31 @@ u32 tpm2_dam_parameters(const char *pw, const ssize_t pw_sz,
 int tpm2_change_auth(u32 handle, const char *newpw, const ssize_t newpw_sz,
 		     const char *oldpw, const ssize_t oldpw_sz);
 
+/**
+ * Issue a TPM_PCR_SetAuthPolicy command.
+ *
+ * @pw		Platform password
+ * @pw_sz	Length of the password
+ * @index	Index of the PCR
+ * @digest	New key to access the PCR
+ *
+ * @return code of the operation
+ */
+u32 tpm2_pcr_setauthpolicy(const char *pw, const ssize_t pw_sz, u32 index,
+			   const char *key);
+
+/**
+ * Issue a TPM_PCR_SetAuthValue command.
+ *
+ * @pw		Platform password
+ * @pw_sz	Length of the password
+ * @index	Index of the PCR
+ * @digest	New key to access the PCR
+ * @key_sz	Length of the new key
+ *
+ * @return code of the operation
+ */
+u32 tpm2_pcr_setauthvalue(const char *pw, const ssize_t pw_sz, u32 index,
+			  const char *key, const ssize_t key_sz);
+
 #endif /* __TPM_V2_H */
lib/tpm-v2.c +100 -0

103 lines not on this page · raw message

Signature · 1 line
2.14.1
#80 lore raw

PATCH v4 24/32 tpm: add PCR authentication commands support

Quoted 11 lines · Miquel Raynal

Add support for the TPM2_PCR_SetAuthPolicy and
TPM2_PCR_SetAuthValue commands.

Change the command file and the help accordingly.

Note: These commands could not be tested because the TPMs available do not support them, however they could be useful for someone else. The user is warned by the command help.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/31845903/attachment.sig>
#81 lore raw

PATCH v4 24/32 tpm: add PCR authentication commands support

In reply to Miquel Raynal
Quoted 5 lines · Miquel Raynal

Add support for the TPM2_PCR_SetAuthPolicy and
TPM2_PCR_SetAuthValue commands.

Change the command file and the help accordingly.

Quoted 7 lines

Note: These commands could not be tested because the TPMs available do not support them, however they could be useful for someone else. The user is warned by the command help.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/d77b525a/attachment.sig>
#82 lore raw

PATCH v4 25/32 tpm: add support for TPMv2.x SPI modules

In reply to Miquel Raynal

Add the tpm2_tis_spi driver that should support any TPMv2 compliant (SPI) module.

---
 drivers/tpm/Kconfig        |  10 +
 drivers/tpm/Makefile       |   2 +
 drivers/tpm/tpm2_tis_spi.c | 664 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 676 insertions(+)
 create mode 100644 drivers/tpm/tpm2_tis_spi.c
drivers/tpm/Kconfig +10 -0
index 01967ffd35..6661dcc1e3 100644
@@ -141,6 +141,16 @@ config TPM_V2
 
 if TPM_V2 && !TPM_V1
 
+config TPM2_TIS_SPI
+	bool "Enable support for TPMv2.x SPI chips"
+	depends on TPM_V2 && DM_SPI
+	select TPM_DRIVER_SELECTED
+	help
+	  This driver supports TPMv2.x devices connected on the SPI bus.
+	  The usual TPM operations and the 'tpm' command can be used to talk
+	  to the device using the standard TPM Interface Specification (TIS)
+	  protocol.
+
 endif # TPM_V2
 
 endmenu
drivers/tpm/Makefile +2 -0
index c42a93f267..2c88b64659 100644
@@ -11,3 +11,5 @@ obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
 obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o
 obj-$(CONFIG_TPM_ST33ZP24_SPI) += tpm_tis_st33zp24_spi.o
+
+obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_spi.o
drivers/tpm/tpm2_tis_spi.c new file +664 -0

664 lines not on this page · raw message

Signature · 1 line
2.14.1
#83 lore raw

PATCH v4 25/32 tpm: add support for TPMv2.x SPI modules

Quoted 4 lines · Miquel Raynal

Add the tpm2_tis_spi driver that should support any TPMv2 compliant (SPI) module.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/a5f5a272/attachment.sig>
#84 lore raw

PATCH v4 25/32 tpm: add support for TPMv2.x SPI modules

In reply to Miquel Raynal

Hi Miquel,

Quoted 11 lines · Miquel Raynal

Add the tpm2_tis_spi driver that should support any TPMv2 compliant (SPI) module.

---
 drivers/tpm/Kconfig        |  10 +
 drivers/tpm/Makefile       |   2 +
 drivers/tpm/tpm2_tis_spi.c | 664 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 676 insertions(+)
 create mode 100644 drivers/tpm/tpm2_tis_spi.c

Is there a change log for this patch?

Regards,
Simon

#85 lore raw

PATCH v4 25/32 tpm: add support for TPMv2.x SPI modules

Hi Simon,

Quoted 15 lines · Simon Glass

Hi Miquel,

Quoted 11 lines · Miquel Raynal

Add the tpm2_tis_spi driver that should support any TPMv2 compliant (SPI) module.

---
 drivers/tpm/Kconfig        |  10 +
 drivers/tpm/Makefile       |   2 +
 drivers/tpm/tpm2_tis_spi.c | 664 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 676 insertions(+)
 create mode 100644 drivers/tpm/tpm2_tis_spi.c
Quoted 1 line

Is there a change log for this patch?

Yes there is one in the cover letter but your are right it was not clear enough what file I was talking about:

<snip>

Quoted 5 lines

* Removed useless reset of rx_buf[0] in tpm_tis_spi_xfer().
* Changed the way spi_xfer return code is checked: error out on any value != 0 instead of just negative ones.
* Removed unused functions flagged __maybe_unused as well as well as the __maybe_unused flags themselves when not needed.

Quoted 8 lines

* Simplified the validity check of the GPIO as suggested.
* Updated the compatible property for the SPI modules (as well as the bindings docuementation) to be simply "tis,tpm2-spi" which should work with most compliant chips. Data is linked to this generic compatible in the TPM driver, other values may be added if needed in the future to fit other chips that would use different values than the current ones (used by Infineon SLB 9670 and ST ST33TPHF20 modules, for instance).

</snip>

Regards,
Miquèl

Signature · 3 lines
Miquel Raynal, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
#86 lore raw

PATCH v4 25/32 tpm: add support for TPMv2.x SPI modules

Quoted 39 lines · Miquel Raynal

Hi Simon,

Quoted 15 lines · Simon Glass

Hi Miquel,

Quoted 11 lines · Miquel Raynal

Add the tpm2_tis_spi driver that should support any TPMv2 compliant (SPI) module.

---
 drivers/tpm/Kconfig        |  10 +
 drivers/tpm/Makefile       |   2 +
 drivers/tpm/tpm2_tis_spi.c | 664 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 676 insertions(+)
 create mode 100644 drivers/tpm/tpm2_tis_spi.c
Quoted 1 line

Is there a change log for this patch?

Yes there is one in the cover letter but your are right it was not clear enough what file I was talking about:

<snip>

Quoted 5 lines

* Removed useless reset of rx_buf[0] in tpm_tis_spi_xfer().
* Changed the way spi_xfer return code is checked: error out on any value != 0 instead of just negative ones.
* Removed unused functions flagged __maybe_unused as well as well as the __maybe_unused flags themselves when not needed.

Quoted 8 lines

* Simplified the validity check of the GPIO as suggested.
* Updated the compatible property for the SPI modules (as well as the bindings docuementation) to be simply "tis,tpm2-spi" which should work with most compliant chips. Data is linked to this generic compatible in the TPM driver, other values may be added if needed in the future to fit other chips that would use different values than the current ones (used by Infineon SLB 9670 and ST ST33TPHF20 modules, for instance).

Quoted 1 line

</snip>

Thanks!

#87 lore raw

PATCH v4 25/32 tpm: add support for TPMv2.x SPI modules

In reply to Miquel Raynal
Quoted 6 lines · Miquel Raynal

Add the tpm2_tis_spi driver that should support any TPMv2 compliant (SPI) module.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/2a23e61a/attachment.sig>
#88 lore raw

PATCH v4 26/32 tpm: add the possibility to reset the chip with a gpio

In reply to Miquel Raynal

On some designs, the reset line could not be connected to the SoC reset line, in this case, request the GPIO and ensure the chip gets reset.

---
 drivers/tpm/tpm2_tis_spi.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/tpm/tpm2_tis_spi.c +17 -0
index 6a4d5284c9..1c7f8f3673 100644
@@ -24,6 +24,9 @@
 #include <linux/compiler.h>
 #include <linux/types.h>
 #include <linux/unaligned/be_byteshift.h>
+#ifdef CONFIG_DM_GPIO
+#include <asm-generic/gpio.h>
+#endif
 
 #include "tpm_tis.h"
 #include "tpm_internal.h"
@@ -574,6 +577,20 @@ static int tpm_tis_spi_probe(struct udevice *dev)
 	struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
 	struct tpm_chip *chip = dev_get_priv(dev);
 	int ret;
+#ifdef CONFIG_DM_GPIO
+	struct gpio_desc reset_gpio;
+
+	ret = gpio_request_by_name(dev, "gpio-reset", 0,
+				   &reset_gpio, GPIOD_IS_OUT);
+	if (ret) {
+		log(LOGC_NONE, LOGL_NOTICE, "%s: missing reset GPIO\n",
+		    __func__);
+	} else {
+		dm_gpio_set_value(&reset_gpio, 0);
+		mdelay(1);
+		dm_gpio_set_value(&reset_gpio, 1);
+	}
+#endif
 
 	/* Ensure a minimum amount of time elapsed since reset of the TPM */
 	mdelay(drv_data->time_before_first_cmd_ms);
Signature · 1 line
2.14.1
#89 lore raw

PATCH v4 26/32 tpm: add the possibility to reset the chip with a gpio

Quoted 4 lines · Miquel Raynal

On some designs, the reset line could not be connected to the SoC reset line, in this case, request the GPIO and ensure the chip gets reset.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/ad69d3ce/attachment.sig>
#90 lore raw

PATCH v4 26/32 tpm: add the possibility to reset the chip with a gpio

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

On some designs, the reset line could not be connected to the SoC reset line, in this case, request the GPIO and ensure the chip gets reset.

---
 drivers/tpm/tpm2_tis_spi.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Question below

Quoted 16 lines
drivers/tpm/tpm2_tis_spi.c +3 -0
index 6a4d5284c9..1c7f8f3673 100644
@@ -24,6 +24,9 @@
 #include <linux/compiler.h>
 #include <linux/types.h>
 #include <linux/unaligned/be_byteshift.h>
+#ifdef CONFIG_DM_GPIO
+#include <asm-generic/gpio.h>
+#endif
 
 #include "tpm_tis.h"
 #include "tpm_internal.h"

drivers/tpm/tpm2_tis_spi.c static int tpm_tis_spi_probe(struct udevice *dev) · line 580

Quoted 4 lines
drivers/tpm/tpm2_tis_spi.c +1 -0
@@ -574,6 +577,20 @@ static int tpm_tis_spi_probe(struct udevice *dev)
        struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
        struct tpm_chip *chip = dev_get_priv(dev);
        int ret;
+#ifdef CONFIG_DM_GPIO

Can this use if (IS_ENABLED(CONFIG_DM_GPIO)) ?

It helps to improve build coverage.

Quoted 19 lines
drivers/tpm/tpm2_tis_spi.c +13 -1
+       struct gpio_desc reset_gpio;
+
+       ret = gpio_request_by_name(dev, "gpio-reset", 0,
+                                  &reset_gpio, GPIOD_IS_OUT);
+       if (ret) {
+               log(LOGC_NONE, LOGL_NOTICE, "%s: missing reset GPIO\n",
+                   __func__);
+       } else {
+               dm_gpio_set_value(&reset_gpio, 0);
+               mdelay(1);
+               dm_gpio_set_value(&reset_gpio, 1);
+       }
+#endif
 
        /* Ensure a minimum amount of time elapsed since reset of the TPM */
        mdelay(drv_data->time_before_first_cmd_ms);
--

2.14.1

#91 lore raw

PATCH v4 26/32 tpm: add the possibility to reset the chip with a gpio

Simon, Tom,

Quoted 36 lines · Simon Glass
Quoted 7 lines · Miquel Raynal

On some designs, the reset line could not be connected to the SoC reset line, in this case, request the GPIO and ensure the chip gets reset.

---
 drivers/tpm/tpm2_tis_spi.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)  

Question below

Quoted 16 lines
drivers/tpm/tpm2_tis_spi.c +3 -0
index 6a4d5284c9..1c7f8f3673 100644
@@ -24,6 +24,9 @@
 #include <linux/compiler.h>
 #include <linux/types.h>
 #include <linux/unaligned/be_byteshift.h>
+#ifdef CONFIG_DM_GPIO
+#include <asm-generic/gpio.h>
+#endif
 
 #include "tpm_tis.h"
 #include "tpm_internal.h"

drivers/tpm/tpm2_tis_spi.c static int tpm_tis_spi_probe(struct udevice *dev) · line 580

Quoted 4 lines
drivers/tpm/tpm2_tis_spi.c +1 -0
@@ -574,6 +577,20 @@ static int tpm_tis_spi_probe(struct udevice *dev)
        struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
        struct tpm_chip *chip = dev_get_priv(dev);
        int ret;
+#ifdef CONFIG_DM_GPIO  

Can this use if (IS_ENABLED(CONFIG_DM_GPIO)) ?

Quoted 2 lines

It helps to improve build coverage.

Sure!

Tom, I guess the series needs the following changes:
- update the old license identifiers
- two occurrences of "#ifdef CONFIG_DM_GPIO" in this patch to be replaced by "#if (IS_ENABLED(CONFIG_DM_GPIO))"

I can either repost a new iteration of the whole series/just this patch or let you make the changes. Let me know what is best for you.

Thanks you very much, both of you, for your guidance.

Regards,
Miquèl

Signature · 3 lines
Miquel Raynal, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
#92 lore raw

PATCH v4 26/32 tpm: add the possibility to reset the chip with a gpio

Quoted 51 lines · Miquel Raynal

Simon, Tom,

Quoted 36 lines · Simon Glass
Quoted 7 lines · Miquel Raynal

On some designs, the reset line could not be connected to the SoC reset line, in this case, request the GPIO and ensure the chip gets reset.

---
 drivers/tpm/tpm2_tis_spi.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)  

Question below

Quoted 16 lines
drivers/tpm/tpm2_tis_spi.c +3 -0
index 6a4d5284c9..1c7f8f3673 100644
@@ -24,6 +24,9 @@
 #include <linux/compiler.h>
 #include <linux/types.h>
 #include <linux/unaligned/be_byteshift.h>
+#ifdef CONFIG_DM_GPIO
+#include <asm-generic/gpio.h>
+#endif
 
 #include "tpm_tis.h"
 #include "tpm_internal.h"

drivers/tpm/tpm2_tis_spi.c static int tpm_tis_spi_probe(struct udevice *dev) · line 580

Quoted 4 lines
drivers/tpm/tpm2_tis_spi.c +1 -0
@@ -574,6 +577,20 @@ static int tpm_tis_spi_probe(struct udevice *dev)
        struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
        struct tpm_chip *chip = dev_get_priv(dev);
        int ret;
+#ifdef CONFIG_DM_GPIO  

Can this use if (IS_ENABLED(CONFIG_DM_GPIO)) ?

Quoted 2 lines

It helps to improve build coverage.

Sure!

Tom, I guess the series needs the following changes:
- update the old license identifiers
- two occurrences of "#ifdef CONFIG_DM_GPIO" in this patch to be replaced by "#if (IS_ENABLED(CONFIG_DM_GPIO))"

Quoted 4 lines

I can either repost a new iteration of the whole series/just this patch or let you make the changes. Let me know what is best for you.

Thanks you very much, both of you, for your guidance.

Just this patch is fine and thanks for iterating over it all!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/2306db9c/attachment.sig>
#93 lore raw

PATCH v4 27/32 doc: device-tree-bindings: add TIS TPMv2.0 SPI module info

In reply to Miquel Raynal

Add TIS TPMv2.0 SPI module bindings.

---
 doc/device-tree-bindings/tpm2/tis-tpm2-spi.txt | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 doc/device-tree-bindings/tpm2/tis-tpm2-spi.txt
doc/device-tree-bindings/tpm2/tis-tpm2-spi.txt new file +18 -0
new file mode 100644
index 0000000000..b48a15112d
@@ -0,0 +1,18 @@
+ST33TPHF20 SPI TPMv2.0 bindings
+-------------------------------
+
+Required properties:
+- compatible		: Should be "tis,tpm2-spi"
+- reg			: SPI Chip select
+
+Optional properties:
+- gpio-reset		: Reset GPIO (if not connected to the SoC reset line)
+- spi-max-frequency	: See spi-bus.txt
+
+Example:
+
+	tpm at 1 {
+		compatible = "tis,tpm2-spi";
+		reg = <1>;
+		spi-max-frequency = <10000000>;
+	};
Signature · 1 line
2.14.1
#94 lore raw

PATCH v4 27/32 doc: device-tree-bindings: add TIS TPMv2.0 SPI module info

Quoted 4 lines · Miquel Raynal

Add TIS TPMv2.0 SPI module bindings.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/b2530523/attachment.sig>
#95 lore raw

PATCH v4 27/32 doc: device-tree-bindings: add TIS TPMv2.0 SPI module info

In reply to Miquel Raynal
Quoted 5 lines · Miquel Raynal

Add TIS TPMv2.0 SPI module bindings.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/536557f7/attachment.sig>
#96 lore raw

PATCH v4 28/32 test/py: add TPMv2.x test suite

In reply to Miquel Raynal

Add tests for the TPMv2.x commands.
These commands may run both on a physical TPM and with the sandbox driver.

---
 test/py/tests/test_tpm2.py | 234 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 234 insertions(+)
 create mode 100644 test/py/tests/test_tpm2.py
test/py/tests/test_tpm2.py new file +234 -0
new file mode 100644
index 0000000000..2e0ef42fd4
@@ -0,0 +1,234 @@
+# Copyright (c) 2018, Bootlin
+# Author: Miquel Raynal <[email protected]>
+#
+# SPDX-License-Identifier: GPL-2.0+
+
+import os.path
+import pytest
+import u_boot_utils
+import re
+import time
+
+"""
+Test the TPMv2.x related commands. You must have a working hardware setup in
+order to do these tests.
+
+Notes:
+* These tests will prove the password mechanism. The TPM chip must be cleared of
+any password.
+* Commands like pcr_setauthpolicy and pcr_resetauthpolicy are not implemented
+here because they would fail the tests in most cases (TPMs do not implement them
+and return an error).
+"""
+
+updates = 0
+
+def force_init(u_boot_console, force=False):
+    """When a test fails, U-Boot is reset. Because TPM stack must be initialized
+    after each reboot, we must ensure these lines are always executed before
+    trying any command or they will fail with no reason. Executing 'tpm init'
+    twice will spawn an error used to detect that the TPM was not reset and no
+    initialization code should be run.
+    """
+    output = u_boot_console.run_command('tpm init')
+    if force or not 'Error' in output:
+        u_boot_console.run_command('echo --- start of init ---')
+        u_boot_console.run_command('tpm startup TPM2_SU_CLEAR')
+        u_boot_console.run_command('tpm self_test full')
+        u_boot_console.run_command('tpm clear TPM2_RH_LOCKOUT')
+        output = u_boot_console.run_command('echo $?')
+        if not output.endswith('0'):
+            u_boot_console.run_command('tpm clear TPM2_RH_PLATFORM')
+        u_boot_console.run_command('echo --- end of init ---')
+
+ at pytest.mark.buildconfigspec('cmd_tpm_v2')
+def test_tpm2_init(u_boot_console):
+    """Init the software stack to use TPMv2 commands."""
+
+    u_boot_console.run_command('tpm init')
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+
+ at pytest.mark.buildconfigspec('cmd_tpm_v2')
+def test_tpm2_startup(u_boot_console):
+    """Execute a TPM2_Startup command.
+
+    Initiate the TPM internal state machine.
+    """
+
+    u_boot_console.run_command('tpm startup TPM2_SU_CLEAR')
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+
+ at pytest.mark.buildconfigspec('cmd_tpm_v2')
+def test_tpm2_self_test_full(u_boot_console):
+    """Execute a TPM2_SelfTest (full) command.
+
+    Ask the TPM to perform all self tests to also enable full capabilities.
+    """
+
+    u_boot_console.run_command('tpm self_test full')
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+
+ at pytest.mark.buildconfigspec('cmd_tpm_v2')
+def test_tpm2_continue_self_test(u_boot_console):
+    """Execute a TPM2_SelfTest (continued) command.
+
+    Ask the TPM to finish its self tests (alternative to the full test) in order
+    to enter a fully operational state.
+    """
+
+    u_boot_console.run_command('tpm self_test continue')
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+
+ at pytest.mark.buildconfigspec('cmd_tpm_v2')
+def test_tpm2_clear(u_boot_console):
+    """Execute a TPM2_Clear command.
+
+    Ask the TPM to reset entirely its internal state (including internal
+    configuration, passwords, counters and DAM parameters). This is half of the
+    TAKE_OWNERSHIP command from TPMv1.
+
+    Use the LOCKOUT hierarchy for this. The LOCKOUT/PLATFORM hierarchies must
+    not have a password set, otherwise this test will fail. ENDORSEMENT and
+    PLATFORM hierarchies are also available.
+    """
+
+    u_boot_console.run_command('tpm clear TPM2_RH_LOCKOUT')
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+
+    u_boot_console.run_command('tpm clear TPM2_RH_PLATFORM')
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+
+ at pytest.mark.buildconfigspec('cmd_tpm_v2')
+def test_tpm2_change_auth(u_boot_console):
+    """Execute a TPM2_HierarchyChangeAuth command.
+
+    Ask the TPM to change the owner, ie. set a new password: 'unicorn'
+
+    Use the LOCKOUT hierarchy for this. ENDORSEMENT and PLATFORM hierarchies are
+    also available.
+    """
+
+    force_init(u_boot_console)
+
+    u_boot_console.run_command('tpm change_auth TPM2_RH_LOCKOUT unicorn')
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+
+    u_boot_console.run_command('tpm clear TPM2_RH_LOCKOUT unicorn')
+    output = u_boot_console.run_command('echo $?')
+    u_boot_console.run_command('tpm clear TPM2_RH_PLATFORM')
+    assert output.endswith('0')
+
+ at pytest.mark.buildconfigspec('cmd_tpm_v2')
+def test_tpm2_get_capability(u_boot_console):
+    """Execute a TPM_GetCapability command.
+
+    Display one capability. In our test case, let's display the default DAM
+    lockout counter that should be 0 since the CLEAR:
+    - TPM_CAP_TPM_PROPERTIES = 0x6
+    - TPM_PT_LOCKOUT_COUNTER (1st parameter) = PTR_VAR + 14
+
+    There is no expected default values because it would depend on the chip
+    used. We can still save them in order to check they have changed later.
+    """
+
+    force_init(u_boot_console)
+    ram = u_boot_utils.find_ram_base(u_boot_console)
+
+    read_cap = u_boot_console.run_command('tpm get_capability 0x6 0x20e 0x200 1') #0x%x 1' % ram)
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+    assert 'Property 0x0000020e: 0x00000000' in read_cap
+
+ at pytest.mark.buildconfigspec('cmd_tpm_v2')
+def test_tpm2_dam_parameters(u_boot_console):
+    """Execute a TPM2_DictionaryAttackParameters command.
+
+    Change Dictionary Attack Mitigation (DAM) parameters. Ask the TPM to change:
+    - Max number of failed authentication before lockout: 3
+    - Time before the failure counter is automatically decremented: 10 sec
+    - Time after a lockout failure before it can be attempted again: 0 sec
+
+    For an unknown reason, the DAM parameters must be changed before changing
+    the authentication, otherwise the lockout will be engaged after the first
+    failed authentication attempt.
+    """
+
+    force_init(u_boot_console)
+    ram = u_boot_utils.find_ram_base(u_boot_console)
+
+    # Set the DAM parameters to known values
+    u_boot_console.run_command('tpm dam_parameters 3 10 0')
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+
+    # Check the values have been saved
+    read_cap = u_boot_console.run_command('tpm get_capability 0x6 0x20f 0x%x 3' % ram)
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+    assert 'Property 0x0000020f: 0x00000003' in read_cap
+    assert 'Property 0x00000210: 0x0000000a' in read_cap
+    assert 'Property 0x00000211: 0x00000000' in read_cap
+
+ at pytest.mark.buildconfigspec('cmd_tpm_v2')
+def test_tpm2_pcr_read(u_boot_console):
+    """Execute a TPM2_PCR_Read command.
+
+    Perform a PCR read of the 0th PCR. Must be zero.
+    """
+
+    force_init(u_boot_console)
+    ram = u_boot_utils.find_ram_base(u_boot_console) + 1024
+
+    read_pcr = u_boot_console.run_command('tpm pcr_read 0 0x%x' % ram)
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+
+    # Save the number of PCR updates
+    str = re.findall(r'\d+ known updates', read_pcr)[0]
+    global updates
+    updates = int(re.findall(r'\d+', str)[0])
+
+    # Check the output value
+    assert 'PCR #0 content' in read_pcr
+    assert '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' in read_pcr
+
+ at pytest.mark.buildconfigspec('cmd_tpm_v2')
+def test_tpm2_pcr_extend(u_boot_console):
+    """Execute a TPM2_PCR_Extend command.
+
+    Perform a PCR extension with a known hash in memory (zeroed since the board
+    must have been rebooted).
+
+    No authentication mechanism is used here, not protecting against packet
+    replay, yet.
+    """
+
+    force_init(u_boot_console)
+    ram = u_boot_utils.find_ram_base(u_boot_console) + 1024
+
+    u_boot_console.run_command('tpm pcr_extend 0 0x%x' % ram)
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+
+    read_pcr = u_boot_console.run_command('tpm pcr_read 0 0x%x' % ram)
+    output = u_boot_console.run_command('echo $?')
+    assert output.endswith('0')
+    assert 'f5 a5 fd 42 d1 6a 20 30 27 98 ef 6e d3 09 97 9b' in read_pcr
+    assert '43 00 3d 23 20 d9 f0 e8 ea 98 31 a9 27 59 fb 4b' in read_pcr
+
+    str = re.findall(r'\d+ known updates', read_pcr)[0]
+    new_updates = int(re.findall(r'\d+', str)[0])
+    assert (updates + 1) == new_updates
+
+ at pytest.mark.buildconfigspec('cmd_tpm_v2')
+def test_tpm2_cleanup(u_boot_console):
+    """Ensure the TPM is cleared from password or test related configuration."""
+
+    force_init(u_boot_console, True)
Signature · 1 line
2.14.1
#97 lore raw

PATCH v4 28/32 test/py: add TPMv2.x test suite

Quoted 6 lines · Miquel Raynal

Add tests for the TPMv2.x commands.
These commands may run both on a physical TPM and with the sandbox driver.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/a53a064a/attachment.sig>
#98 lore raw

PATCH v4 28/32 test/py: add TPMv2.x test suite

In reply to Miquel Raynal
Quoted 7 lines · Miquel Raynal

Add tests for the TPMv2.x commands.
These commands may run both on a physical TPM and with the sandbox driver.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/324337de/attachment.sig>
#99 lore raw

PATCH v4 29/32 tpm: add a Sandbox TPMv2.x driver

In reply to Miquel Raynal

This driver can emulate all the basic functionalities of a TPMv2.x chip and should behave like them during regular testing.

---
 drivers/tpm/Kconfig            |  11 +-
 drivers/tpm/Makefile           |   1 +
 drivers/tpm/tpm2_tis_sandbox.c | 626 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 637 insertions(+), 1 deletion(-)
 create mode 100644 drivers/tpm/tpm2_tis_sandbox.c
drivers/tpm/Kconfig +10 -1
index 6661dcc1e3..b7bae5db30 100644
@@ -26,7 +26,7 @@ config TPM_TIS_SANDBOX
 	depends on TPM_V1 && SANDBOX
 	select TPM_DRIVER_SELECTED
 	help
-	  This driver emulates a TPM, providing access to base functions
+	  This driver emulates a TPMv1.x, providing access to base functions
 	  such as reading and writing TPM private data. This is enough to
 	  support Chrome OS verified boot. Extend functionality is not
 	  implemented.
@@ -141,6 +141,15 @@ config TPM_V2
 
 if TPM_V2 && !TPM_V1
 
+config TPM2_TIS_SANDBOX
+	bool "Enable sandbox TPMv2.x driver"
+	depends on TPM_V2 && SANDBOX
+	select TPM_DRIVER_SELECTED
+	help
+	  This driver emulates a TPMv2.x, providing access to base functions
+	  such as basic configuration, PCR extension and PCR read. Extended
+	  functionalities are not implemented.
+
 config TPM2_TIS_SPI
 	bool "Enable support for TPMv2.x SPI chips"
 	depends on TPM_V2 && DM_SPI
drivers/tpm/Makefile +1 -0
index 2c88b64659..98dfbfa488 100644
@@ -12,4 +12,5 @@ obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
 obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o
 obj-$(CONFIG_TPM_ST33ZP24_SPI) += tpm_tis_st33zp24_spi.o
 
+obj-$(CONFIG_TPM2_TIS_SANDBOX) += tpm2_tis_sandbox.o
 obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_spi.o
drivers/tpm/tpm2_tis_sandbox.c new file +626 -0

626 lines not on this page · raw message

Signature · 1 line
2.14.1
#100 lore raw

PATCH v4 29/32 tpm: add a Sandbox TPMv2.x driver

Quoted 5 lines · Miquel Raynal

This driver can emulate all the basic functionalities of a TPMv2.x chip and should behave like them during regular testing.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/69b94c58/attachment.sig>
#101 lore raw

PATCH v4 29/32 tpm: add a Sandbox TPMv2.x driver

In reply to Miquel Raynal
Quoted 6 lines · Miquel Raynal

This driver can emulate all the basic functionalities of a TPMv2.x chip and should behave like them during regular testing.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/f4af022b/attachment.sig>
#102 lore raw

PATCH v4 30/32 doc: device-tree-bindings: add Sandbox TPMv2.0 module info

In reply to Miquel Raynal

Add Sandbox TPMv2.0 module bindings.

---
 doc/device-tree-bindings/tpm2/sandbox.txt | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 doc/device-tree-bindings/tpm2/sandbox.txt
doc/device-tree-bindings/tpm2/sandbox.txt new file +11 -0
new file mode 100644
index 0000000000..3d0f727cc4
@@ -0,0 +1,11 @@
+Sandbox TPMv2.0 bindings
+------------------------
+
+Required properties:
+- compatible		: Should be "sandbox,tpm2"
+
+Example:
+
+	tpm {
+ 		compatible = "sandbox,tpm2";
+	};
Signature · 1 line
2.14.1
#103 lore raw

PATCH v4 30/32 doc: device-tree-bindings: add Sandbox TPMv2.0 module info

Quoted 4 lines · Miquel Raynal

Add Sandbox TPMv2.0 module bindings.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/dc73e05b/attachment.sig>
#104 lore raw

PATCH v4 30/32 doc: device-tree-bindings: add Sandbox TPMv2.0 module info

In reply to Miquel Raynal
Quoted 5 lines · Miquel Raynal

Add Sandbox TPMv2.0 module bindings.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/e4485aea/attachment.sig>
#105 lore raw

PATCH v4 31/32 sandbox: dts: add Sandbox TPMv2.x node

In reply to Miquel Raynal

This node declares the presence of the Sandbox TPMv2.x emulated chip, available for testing.

---
 arch/sandbox/dts/sandbox.dts   | 4 ++++
 arch/sandbox/dts/sandbox64.dts | 4 ++++
 arch/sandbox/dts/test.dts      | 4 ++++
 3 files changed, 12 insertions(+)
arch/sandbox/dts/sandbox.dts +4 -0
index 1fb8225fbb..09194684c6 100644
@@ -238,6 +238,10 @@
 		compatible = "google,sandbox-tpm";
 	};
 
+	tpm2 {
+		compatible = "sandbox,tpm2";
+	};
+
 	triangle {
 		compatible = "demo-shape";
 		colour = "cyan";
arch/sandbox/dts/sandbox64.dts +4 -0
index d6efc011de..6c6bcd4fce 100644
@@ -238,6 +238,10 @@
 		compatible = "google,sandbox-tpm";
 	};
 
+	tpm2 {
+		compatible = "sandbox,tpm2";
+	};
+
 	triangle {
 		compatible = "demo-shape";
 		colour = "cyan";
arch/sandbox/dts/test.dts +4 -0
index b0f0ca8f19..4a66dbdca3 100644
@@ -394,6 +394,10 @@
 		clock-frequency = <1000000>;
 	};
 
+	tpm2 {
+		compatible = "sandbox,tpm2";
+	};
+
 	uart0: serial {
 		compatible = "sandbox,serial";
 		u-boot,dm-pre-reloc;
Signature · 1 line
2.14.1
#106 lore raw

PATCH v4 31/32 sandbox: dts: add Sandbox TPMv2.x node

Quoted 5 lines · Miquel Raynal

This node declares the presence of the Sandbox TPMv2.x emulated chip, available for testing.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/100d6a14/attachment.sig>
#107 lore raw

PATCH v4 31/32 sandbox: dts: add Sandbox TPMv2.x node

In reply to Miquel Raynal
Quoted 6 lines · Miquel Raynal

This node declares the presence of the Sandbox TPMv2.x emulated chip, available for testing.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/fe4a7e5e/attachment.sig>
#108 lore raw

PATCH v4 32/32 configs: add TPMv2.x support in Sandbox

In reply to Miquel Raynal

Enable the Sandbox TPMv2 driver in all possible configurations.

---
 configs/sandbox64_defconfig        | 1 +
 configs/sandbox_defconfig          | 1 +
 configs/sandbox_flattree_defconfig | 1 +
 configs/sandbox_noblk_defconfig    | 1 +
 configs/sandbox_spl_defconfig      | 1 +
 5 files changed, 5 insertions(+)
configs/sandbox64_defconfig +1 -0
index 8f96c16d42..2123e38c57 100644
@@ -175,6 +175,7 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_TPM_TIS_SANDBOX=y
+CONFIG_TPM2_TIS_SANDBOX=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_EMUL=y
configs/sandbox_defconfig +1 -0
index 063828333d..0cc315148c 100644
@@ -175,6 +175,7 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_TPM_TIS_SANDBOX=y
+CONFIG_TPM2_TIS_SANDBOX=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_EMUL=y
configs/sandbox_flattree_defconfig +1 -0
index d5f23796b8..29b8a1fb48 100644
@@ -155,6 +155,7 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_TPM_TIS_SANDBOX=y
+CONFIG_TPM2_TIS_SANDBOX=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_EMUL=y
configs/sandbox_noblk_defconfig +1 -0
index b01a9fdf7e..7bad141007 100644
@@ -155,6 +155,7 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_TPM_TIS_SANDBOX=y
+CONFIG_TPM2_TIS_SANDBOX=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_EMUL=y
configs/sandbox_spl_defconfig +1 -0
index 802dc30f26..647e67f533 100644
@@ -173,6 +173,7 @@ CONFIG_TIMER=y
 CONFIG_TIMER_EARLY=y
 CONFIG_SANDBOX_TIMER=y
 CONFIG_TPM_TIS_SANDBOX=y
+CONFIG_TPM2_TIS_SANDBOX=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_EMUL=y
Signature · 1 line
2.14.1
#109 lore raw

PATCH v4 32/32 configs: add TPMv2.x support in Sandbox

Quoted 4 lines · Miquel Raynal

Enable the Sandbox TPMv2 driver in all possible configurations.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/6da1da48/attachment.sig>
#110 lore raw

PATCH v4 32/32 configs: add TPMv2.x support in Sandbox

In reply to Miquel Raynal
Quoted 5 lines · Miquel Raynal

Enable the Sandbox TPMv2 driver in all possible configurations.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180526/e2d47465/attachment.sig>
#111 lore raw

v4 cover Introduce TPMv2.0 support

In reply to Miquel Raynal
Quoted 111 lines · Miquel Raynal

Current U-Boot supports TPM v1.2 specification. The new specification (v2.0) is not backward compatible and renames/introduces several functions. This series introduces the support for TPMv2.x chips.

First, some cleaning is done in TPM-related code. Then, the code is split in two categories: generic code (common for both specifications) and specific code (only used by one specification).

Then, basic functionalities are introduced one by one for the v2.x specification. TPMv1 vs TPMv2 commands/support distinction is done with Kconfig options. Drivers of only one specification can be selected at a time.

A new SPI driver following the TPM v2.x specification is introduced. It has been tested on a ST TPM but should be usable with others v2.0 compliant chips.

Finally a full Python test suite is added, as well as a Sandbox driver. Regular testing may be done through the test/py/ framework when using real hardware as well as the Sandbox driver. The following test has run more than 300 times without failing with my setup:

        test/py/test.py --bd <board> -k tpm2

Available commands for v2.0 TPMs are:
* STARTUP
* SELF TEST
* CLEAR
* PCR EXTEND
* PCR READ
* GET CAPABILITY
* DICTIONARY ATTACK LOCK RESET
* DICTIONARY ATTACK CHANGE PARAMETERS
* HIERARCHY CHANGE AUTH

Two commands have been written but could not be tested (unsupported by the TPM chosen):
* PCR CHANGE AUTH POLICY
* PCR CHANGE AUTH VALUE

With this set of function, minimal TPMv2.0 handling is possible with the following sequence.

* First, initialize the TPM stack in U-Boot.

Quoted 1 line

tpm init

* Then send the STARTUP command to the TPM. The flag is slightly different between the revisions.

Quoted 1 line

tpm startup TPM2_SU_CLEAR

* To enable full TPM capabilities, continue the tests (or do them all again). It seems like self_test_full always waits for the operation to finish, while continue_self_test returns a busy state if called to early.

Quoted 2 lines

tpm self_test full
tpm self_test continue

* Manage passwords (force_clear also resets a lot of internal stuff). Olderly, TAKE OWNERSHIP == CLEAR + CHANGE AUTH. LOCKOUT is an example, ENDORSEMENT and PLATFORM hierarchies are available too:

Quoted 2 lines

tpm clear TPM2_RH_LOCKOUT [<pw>]
tpm change_auth TPM2_RH_LOCKOUT <new_pw> [<old_pw>]

* Dictionary Attack Mitigation (DAM) parameters can be changed. It is possible to reset the failure counter and disable the lockout (values erased after a CLEAR). It is then possible to check the parameters have been correctly applied.

Quoted 3 lines

tpm dam_reset [<pw>]
tpm dam_parameters 0xffff 1 0 [<pw>]
tpm get_capability 0x0006 0x020e 0x4000000 4

* PCR policy may be changed (untested).
PCR can be extended (no protection against packet replay yet). PCR can be read (the counter with the number of "extensions" is also given).

Quoted 3 lines

tpm pcr_setauthpolicy 0 12345678901234567890123456789012 [<pw>] tpm pcr_read 0 0x4000000
tpm pcr_extend 0 0x4000000

Thanks,
Miquèl

Changes since v3:
=================
* Added Simon Glass's RB tags.
* Moved all the small fixes about lines, alignments, spellings, etc out of the big commit splitting the TPM code structure. Multiple commits have been made for these changes. Now the split is still done in one commit, but it is supposed to be only code moves and headers changes.
* Used map_sysmem() calls to let Sandbox run TPM commands instead of my hack (allocating memory on the go).
* Updated the documentation to use the new way of declaring parameters:
s/@param x: y/@x: y/.
* Added two parameters in the chip private structure to store the number of PCRs and the minimum number of bytes needed to address one in a TPM command. This should fit all the TIS TPM2 compliant modules.
* The above change removes some (wrongly) hardcoded values.
* Changed the error path as suggested in tpm2_get_capability().
* Minor rephrasing.
* Explained in tpm2_get_capability() the offset '19'.
* Removed useless reset of rx_buf[0] in tpm_tis_spi_xfer().
* Changed the way spi_xfer return code is checked: error out on any value != 0 instead of just negative ones.
* Removed unused functions flagged __maybe_unused as well as well as the __maybe_unused flags themselves when not needed.

Quoted 8 lines

* Simplified the validity check of the GPIO as suggested.
* Updated the compatible property for the SPI modules (as well as the bindings docuementation) to be simply "tis,tpm2-spi" which should work with most compliant chips. Data is linked to this generic compatible in the TPM driver, other values may be added if needed in the future to fit other chips that would use different values than the current ones (used by Infineon SLB 9670 and ST ST33TPHF20 modules, for instance).

Some of the new files have old-style SPDX tags. If there's no further changes requested, I'll fix these up when applying. Thanks again!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180515/294c0a54/attachment.sig>