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 » return result == TPM_E_INVALID_POSTINIT ? TPM_SUCCESS : result; |
| 30 } |
| 31 |
| 32 /* u-boot internal timer test |
| 33 */ |
| 34 |
| 35 static int test_timer(void) |
| 36 { |
| 37 » printf("get_timer(0) = %lu\n", get_timer(0)); |
| 38 » return 0; |
30 } | 39 } |
31 | 40 |
32 /* vboot_reference/tests/tpm_lite tests | 41 /* vboot_reference/tests/tpm_lite tests |
33 * | |
34 */ | 42 */ |
35 | 43 |
36 static int test_early_extend(void) | 44 static int test_early_extend(void) |
37 { | 45 { |
38 uint8_t value_in[20]; | 46 uint8_t value_in[20]; |
39 uint8_t value_out[20]; | 47 uint8_t value_out[20]; |
40 printf("Testing earlyextend ..."); | 48 printf("Testing earlyextend ..."); |
41 TlclLibInit(); | 49 TlclLibInit(); |
42 TPM_CHECK(TlclStartup()); | 50 TPM_CHECK(TlclStartup()); |
43 TPM_CHECK(TlclContinueSelfTest()); | 51 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); | 352 printf("\ttpm getflags failed with 0x%x\n", result); |
345 } | 353 } |
346 printf("\tdone\n"); | 354 printf("\tdone\n"); |
347 return 0; | 355 return 0; |
348 } | 356 } |
349 | 357 |
350 /* Runs [op] and ensures it returns success and doesn't run longer than | 358 /* Runs [op] and ensures it returns success and doesn't run longer than |
351 * [time_limit] in milliseconds. | 359 * [time_limit] in milliseconds. |
352 */ | 360 */ |
353 #define TTPM_CHECK(op, time_limit) do { \ | 361 #define TTPM_CHECK(op, time_limit) do { \ |
354 » ulong start; \ | 362 » ulong start, time; \ |
355 » ulong time_us, time; \ | |
356 uint32_t __result; \ | 363 uint32_t __result; \ |
357 start = get_timer(0); \ | 364 start = get_timer(0); \ |
358 __result = op; \ | 365 __result = op; \ |
359 if (__result != TPM_SUCCESS) { \ | 366 if (__result != TPM_SUCCESS) { \ |
360 printf("\t" #op ": error 0x%x\n", __result); \ | 367 printf("\t" #op ": error 0x%x\n", __result); \ |
361 return (-1); \ | 368 return (-1); \ |
362 } \ | 369 } \ |
363 » time_us = get_timer(start); \ | 370 » time = get_timer(start); \ |
364 » time = time_us / 1000; \ | |
365 printf("\t" #op ": %lu ms\n", time); \ | 371 printf("\t" #op ": %lu ms\n", time); \ |
366 if (time > (ulong)time_limit) { \ | 372 if (time > (ulong)time_limit) { \ |
367 printf("\t" #op " exceeded " #time_limit " ms\n"); \ | 373 printf("\t" #op " exceeded " #time_limit " ms\n"); \ |
368 return (-1); \ | |
369 } \ | 374 } \ |
370 } while (0) | 375 } while (0) |
371 | 376 |
372 | 377 |
373 static int test_timing(void) | 378 static int test_timing(void) |
374 { | 379 { |
375 uint32_t x; | 380 uint32_t x; |
376 uint8_t in[20], out[20]; | 381 uint8_t in[20], out[20]; |
377 printf("Testing timing ..."); | 382 printf("Testing timing ..."); |
378 TlclLibInit(); | 383 TlclLibInit(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 VOIDTEST(enable) | 456 VOIDTEST(enable) |
452 VOIDTEST(fast_enable) | 457 VOIDTEST(fast_enable) |
453 VOIDTEST(global_lock) | 458 VOIDTEST(global_lock) |
454 VOIDTEST(lock) | 459 VOIDTEST(lock) |
455 VOIDTEST(readonly) | 460 VOIDTEST(readonly) |
456 VOIDTEST(redefine_unowned) | 461 VOIDTEST(redefine_unowned) |
457 VOIDTEST(space_perm) | 462 VOIDTEST(space_perm) |
458 VOIDTEST(startup) | 463 VOIDTEST(startup) |
459 VOIDTEST(timing) | 464 VOIDTEST(timing) |
460 VOIDTEST(write_limit) | 465 VOIDTEST(write_limit) |
| 466 VOIDTEST(timer) |
461 | 467 |
462 static cmd_tbl_t cmd_cros_tpm_sub[] = { | 468 static cmd_tbl_t cmd_cros_tpm_sub[] = { |
463 VOIDENT(early_extend), | 469 VOIDENT(early_extend), |
464 VOIDENT(early_nvram), | 470 VOIDENT(early_nvram), |
465 VOIDENT(early_nvram2), | 471 VOIDENT(early_nvram2), |
466 VOIDENT(enable), | 472 VOIDENT(enable), |
467 VOIDENT(fast_enable), | 473 VOIDENT(fast_enable), |
468 VOIDENT(global_lock), | 474 VOIDENT(global_lock), |
469 VOIDENT(lock), | 475 VOIDENT(lock), |
470 VOIDENT(readonly), | 476 VOIDENT(readonly), |
471 VOIDENT(redefine_unowned), | 477 VOIDENT(redefine_unowned), |
472 VOIDENT(space_perm), | 478 VOIDENT(space_perm), |
473 VOIDENT(startup), | 479 VOIDENT(startup), |
474 VOIDENT(timing), | 480 VOIDENT(timing), |
475 » VOIDENT(write_limit) | 481 » VOIDENT(write_limit), |
| 482 » VOIDENT(timer) |
476 }; | 483 }; |
477 | 484 |
478 /* u-boot shell commands | 485 /* u-boot shell commands |
479 */ | 486 */ |
480 static int do_cros_tpm_test(cmd_tbl_t * cmdtp, int flag, int argc, | 487 static int do_cros_tpm_test(cmd_tbl_t * cmdtp, int flag, int argc, |
481 char * const argv[]) | 488 char * const argv[]) |
482 { | 489 { |
483 cmd_tbl_t *c; | 490 cmd_tbl_t *c; |
484 printf("argc = %d, argv = ", argc); | 491 printf("argc = %d, argv = ", argc); |
485 do { | 492 do { |
(...skipping 17 matching lines...) Expand all Loading... |
503 "\tfast_enable\n" | 510 "\tfast_enable\n" |
504 "\tglobal_lock\n" | 511 "\tglobal_lock\n" |
505 "\tlock\n" | 512 "\tlock\n" |
506 "\treadonly\n" | 513 "\treadonly\n" |
507 "\tredefine_unowned\n" | 514 "\tredefine_unowned\n" |
508 "\tspace_perm\n" | 515 "\tspace_perm\n" |
509 "\tstartup\n" | 516 "\tstartup\n" |
510 "\ttiming\n" | 517 "\ttiming\n" |
511 "\twrite_limit\n"); | 518 "\twrite_limit\n"); |
512 | 519 |
OLD | NEW |