Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 #include <common.h> | 6 #include <common.h> |
| 7 #include <command.h> | 7 #include <command.h> |
| 8 #include <environment.h> | 8 #include <environment.h> |
| 9 #include <tlcl.h> | 9 #include <tlcl.h> |
| 10 | 10 |
| 11 /* Prints error and returns on failure */ | 11 /* Prints error and returns on failure */ |
| 12 #define TPM_CHECK(tpm_command) do { \ | 12 #define TPM_CHECK(tpm_command) do { \ |
| 13 uint32_t result; \ | 13 uint32_t result; \ |
| 14 if ((result = (tpm_command)) != TPM_SUCCESS) { \ | 14 if ((result = (tpm_command)) != TPM_SUCCESS) { \ |
| 15 printf("TEST FAILED: line %d: " #tpm_command ": 0x%x\n", \ | 15 printf("TEST FAILED: line %d: " #tpm_command ": 0x%x\n", \ |
| 16 __LINE__, result); \ | 16 __LINE__, result); \ |
| 17 return result; \ | 17 return result; \ |
| 18 } \ | 18 } \ |
| 19 } while (0) | 19 } while (0) |
| 20 | 20 |
| 21 #define INDEX0 0xda70 | 21 #define INDEX0 0xda70 |
| 22 #define INDEX1 0xda71 | 22 #define INDEX1 0xda71 |
| 23 #define INDEX2 0xda72 | 23 #define INDEX2 0xda72 |
| 24 #define INDEX3 0xda73 | 24 #define INDEX3 0xda73 |
| 25 #define INDEX_INITIALIZED 0xda80 | 25 #define INDEX_INITIALIZED 0xda80 |
| 26 | 26 |
| 27 static uint32_t TlclStartupIfNeeded(void) { | 27 static uint32_t TlclStartupIfNeeded(void) { |
| 28 uint32_t result = TlclStartup(); | 28 uint32_t result = TlclStartup(); |
| 29 return result == TPM_E_INVALID_POSTINIT ? TPM_SUCCESS : result; | 29 if (result != TPM_SUCCESS) |
| 30 » printf("TlclStartup = %u\n", result); | |
| 31 return TPM_SUCCESS; | |
|
Che-Liang Chiou
2011/03/14 08:49:54
Logic here is a little bit different. (When result
rongchang
2011/03/23 11:44:57
The TlclStartupIfNeeded's return value can be igno
| |
| 32 } | |
| 33 | |
| 34 /* u-boot internal timer test | |
| 35 */ | |
| 36 | |
| 37 static int test_timer(void) | |
| 38 { | |
| 39 » printf("get_timer(0) = %lu\n", get_timer(0)); | |
| 40 » return 0; | |
| 30 } | 41 } |
| 31 | 42 |
| 32 /* vboot_reference/tests/tpm_lite tests | 43 /* vboot_reference/tests/tpm_lite tests |
| 33 * | |
| 34 */ | 44 */ |
| 35 | 45 |
| 36 static int test_early_extend(void) | 46 static int test_early_extend(void) |
| 37 { | 47 { |
| 38 uint8_t value_in[20]; | 48 uint8_t value_in[20]; |
| 39 uint8_t value_out[20]; | 49 uint8_t value_out[20]; |
| 40 printf("Testing earlyextend ..."); | 50 printf("Testing earlyextend ..."); |
| 41 TlclLibInit(); | 51 TlclLibInit(); |
| 42 TPM_CHECK(TlclStartup()); | 52 TPM_CHECK(TlclStartup()); |
| 43 TPM_CHECK(TlclContinueSelfTest()); | 53 TPM_CHECK(TlclContinueSelfTest()); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 printf("\ttpm getflags failed with 0x%x\n", result); | 354 printf("\ttpm getflags failed with 0x%x\n", result); |
| 345 } | 355 } |
| 346 printf("\tdone\n"); | 356 printf("\tdone\n"); |
| 347 return 0; | 357 return 0; |
| 348 } | 358 } |
| 349 | 359 |
| 350 /* Runs [op] and ensures it returns success and doesn't run longer than | 360 /* Runs [op] and ensures it returns success and doesn't run longer than |
| 351 * [time_limit] in milliseconds. | 361 * [time_limit] in milliseconds. |
| 352 */ | 362 */ |
| 353 #define TTPM_CHECK(op, time_limit) do { \ | 363 #define TTPM_CHECK(op, time_limit) do { \ |
| 354 » ulong start; \ | 364 » ulong start, time; \ |
| 355 » ulong time_us, time; \ | |
| 356 uint32_t __result; \ | 365 uint32_t __result; \ |
| 357 start = get_timer(0); \ | 366 start = get_timer(0); \ |
| 358 __result = op; \ | 367 __result = op; \ |
| 359 if (__result != TPM_SUCCESS) { \ | 368 if (__result != TPM_SUCCESS) { \ |
| 360 printf("\t" #op ": error 0x%x\n", __result); \ | 369 printf("\t" #op ": error 0x%x\n", __result); \ |
| 361 return (-1); \ | 370 return (-1); \ |
| 362 } \ | 371 } \ |
| 363 » time_us = get_timer(start); \ | 372 » time = get_timer(start); \ |
| 364 » time = time_us / 1000; \ | |
| 365 printf("\t" #op ": %lu ms\n", time); \ | 373 printf("\t" #op ": %lu ms\n", time); \ |
| 366 if (time > (ulong)time_limit) { \ | 374 if (time > (ulong)time_limit) { \ |
| 367 printf("\t" #op " exceeded " #time_limit " ms\n"); \ | 375 printf("\t" #op " exceeded " #time_limit " ms\n"); \ |
| 368 return (-1); \ | |
| 369 } \ | 376 } \ |
| 370 } while (0) | 377 } while (0) |
| 371 | 378 |
| 372 | 379 |
| 373 static int test_timing(void) | 380 static int test_timing(void) |
| 374 { | 381 { |
| 375 uint32_t x; | 382 uint32_t x; |
| 376 uint8_t in[20], out[20]; | 383 uint8_t in[20], out[20]; |
| 377 printf("Testing timing ..."); | 384 printf("Testing timing ..."); |
| 378 TlclLibInit(); | 385 TlclLibInit(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 VOIDTEST(enable) | 458 VOIDTEST(enable) |
| 452 VOIDTEST(fast_enable) | 459 VOIDTEST(fast_enable) |
| 453 VOIDTEST(global_lock) | 460 VOIDTEST(global_lock) |
| 454 VOIDTEST(lock) | 461 VOIDTEST(lock) |
| 455 VOIDTEST(readonly) | 462 VOIDTEST(readonly) |
| 456 VOIDTEST(redefine_unowned) | 463 VOIDTEST(redefine_unowned) |
| 457 VOIDTEST(space_perm) | 464 VOIDTEST(space_perm) |
| 458 VOIDTEST(startup) | 465 VOIDTEST(startup) |
| 459 VOIDTEST(timing) | 466 VOIDTEST(timing) |
| 460 VOIDTEST(write_limit) | 467 VOIDTEST(write_limit) |
| 468 VOIDTEST(timer) | |
| 461 | 469 |
| 462 static cmd_tbl_t cmd_cros_tpm_sub[] = { | 470 static cmd_tbl_t cmd_cros_tpm_sub[] = { |
| 463 VOIDENT(early_extend), | 471 VOIDENT(early_extend), |
| 464 VOIDENT(early_nvram), | 472 VOIDENT(early_nvram), |
| 465 VOIDENT(early_nvram2), | 473 VOIDENT(early_nvram2), |
| 466 VOIDENT(enable), | 474 VOIDENT(enable), |
| 467 VOIDENT(fast_enable), | 475 VOIDENT(fast_enable), |
| 468 VOIDENT(global_lock), | 476 VOIDENT(global_lock), |
| 469 VOIDENT(lock), | 477 VOIDENT(lock), |
| 470 VOIDENT(readonly), | 478 VOIDENT(readonly), |
| 471 VOIDENT(redefine_unowned), | 479 VOIDENT(redefine_unowned), |
| 472 VOIDENT(space_perm), | 480 VOIDENT(space_perm), |
| 473 VOIDENT(startup), | 481 VOIDENT(startup), |
| 474 VOIDENT(timing), | 482 VOIDENT(timing), |
| 475 » VOIDENT(write_limit) | 483 » VOIDENT(write_limit), |
| 484 » VOIDENT(timer) | |
| 476 }; | 485 }; |
| 477 | 486 |
| 478 /* u-boot shell commands | 487 /* u-boot shell commands |
| 479 */ | 488 */ |
| 480 static int do_cros_tpm_test(cmd_tbl_t * cmdtp, int flag, int argc, | 489 static int do_cros_tpm_test(cmd_tbl_t * cmdtp, int flag, int argc, |
| 481 char * const argv[]) | 490 char * const argv[]) |
| 482 { | 491 { |
| 483 cmd_tbl_t *c; | 492 cmd_tbl_t *c; |
| 484 printf("argc = %d, argv = ", argc); | 493 printf("argc = %d, argv = ", argc); |
| 485 do { | 494 do { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 503 "\tfast_enable\n" | 512 "\tfast_enable\n" |
| 504 "\tglobal_lock\n" | 513 "\tglobal_lock\n" |
| 505 "\tlock\n" | 514 "\tlock\n" |
| 506 "\treadonly\n" | 515 "\treadonly\n" |
| 507 "\tredefine_unowned\n" | 516 "\tredefine_unowned\n" |
| 508 "\tspace_perm\n" | 517 "\tspace_perm\n" |
| 509 "\tstartup\n" | 518 "\tstartup\n" |
| 510 "\ttiming\n" | 519 "\ttiming\n" |
| 511 "\twrite_limit\n"); | 520 "\twrite_limit\n"); |
| 512 | 521 |
| OLD | NEW |