Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 2 | |
| 3 | Redistribution and use in source and binary forms, with or without |
| 4 | modification, are permitted provided that the following conditions are |
| 5 | met: |
| 6 | * Redistributions of source code must retain the above copyright |
| 7 | notice, this list of conditions and the following disclaimer. |
| 8 | * Redistributions in binary form must reproduce the above |
| 9 | copyright notice, this list of conditions and the following |
| 10 | disclaimer in the documentation and/or other materials provided |
| 11 | with the distribution. |
| 12 | * Neither the name of The Linux Foundation nor the names of its |
| 13 | contributors may be used to endorse or promote products derived |
| 14 | from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | |
| 30 | #include <stdlib.h> |
| 31 | #include <debug.h> |
| 32 | #include "devinfo.h" |
| 33 | #include "fastboot.h" |
| 34 | #include "fastboot_test.h" |
| 35 | #include <app/tests.h> |
Sridhar Parasuram | 890f592 | 2015-09-28 15:43:57 -0700 | [diff] [blame] | 36 | #include <target.h> |
| 37 | #include <boot_device.h> |
Amir Kotzer | bb8be14 | 2016-02-23 09:38:25 +0200 | [diff] [blame^] | 38 | #include "mdtp.h" |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 39 | #if USE_RPMB_FOR_DEVINFO |
| 40 | #include <rpmb.h> |
| 41 | #endif |
| 42 | /* main function that calls into the tests */ |
| 43 | |
| 44 | extern void ramdump_table_map(); |
| 45 | extern void kauth_test(); |
Sridhar Parasuram | 890f592 | 2015-09-28 15:43:57 -0700 | [diff] [blame] | 46 | extern int ufs_get_boot_lun(); |
| 47 | extern int ufs_set_boot_lun(uint32_t bootlunid); |
| 48 | extern int fastboot_init(); |
Parth Dixit | cb0c608 | 2015-12-30 15:01:13 +0530 | [diff] [blame] | 49 | static bool enable_test_mode = false; |
| 50 | |
| 51 | bool is_test_mode_enabled(void) |
| 52 | { |
| 53 | return enable_test_mode; |
| 54 | } |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 55 | |
| 56 | void cmd_oem_runtests() |
| 57 | { |
| 58 | dprintf(INFO, "Running LK tests ... \n"); |
Parth Dixit | cb0c608 | 2015-12-30 15:01:13 +0530 | [diff] [blame] | 59 | enable_test_mode = true; |
Sridhar Parasuram | 890f592 | 2015-09-28 15:43:57 -0700 | [diff] [blame] | 60 | // Test boot lun enable for UFS |
| 61 | if (!platform_boot_dev_isemmc()) |
| 62 | { |
| 63 | int ret = 0; |
| 64 | uint32_t set_lun = 0x2, get_lun; |
| 65 | ret = ufs_set_boot_lun(set_lun); |
| 66 | if (ret == UFS_SUCCESS) |
| 67 | { |
| 68 | get_lun = ufs_get_boot_lun(); |
| 69 | if (get_lun == set_lun) |
| 70 | { |
| 71 | dprintf(INFO, "UFS Boot LUN En TEST: [ PASS ]\n"); |
| 72 | set_lun = 0x1; // default is 0x1 LUN A, revert back to 0x1 |
| 73 | ret = ufs_set_boot_lun(set_lun); |
| 74 | } |
| 75 | else |
| 76 | dprintf(INFO, "UFS Boot LUN En TEST: [ FAIL ]\n"); |
| 77 | } |
| 78 | else |
| 79 | dprintf(INFO, "UFS Boot LUN En TEST: [ FAIL ]\n"); |
| 80 | } |
| 81 | |
| 82 | |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 83 | #if LPAE |
| 84 | ramdump_table_map(); |
| 85 | #endif |
| 86 | |
| 87 | #if USE_RPMB_FOR_DEVINFO |
| 88 | dprintf(INFO, "Running RPMB test case, please make sure RPMB key is provisioned ...\n"); |
| 89 | struct device_info *write_info = memalign(PAGE_SIZE, 4096); |
| 90 | struct device_info *read_info = memalign(PAGE_SIZE, 4096); |
| 91 | if((read_device_info_rpmb((void*) read_info, PAGE_SIZE)) < 0) |
| 92 | dprintf(INFO, "RPMB READ TEST : [ FAIL ]\n"); |
| 93 | |
| 94 | write_info->is_unlocked = !read_info->is_unlocked; |
| 95 | |
| 96 | if((write_device_info_rpmb((void*) write_info, PAGE_SIZE)) < 0) |
| 97 | dprintf(INFO, "RPMB WRITE TEST : [ FAIL ]\n"); |
| 98 | |
| 99 | if((read_device_info_rpmb((void*) read_info, PAGE_SIZE)) < 0) |
| 100 | dprintf(INFO, "RPMB READ TEST : [ FAIL ]\n"); |
| 101 | |
| 102 | if (read_info->is_unlocked == write_info->is_unlocked) |
| 103 | dprintf(INFO, "RPMB READ/WRITE TEST: [ PASS ]\n"); |
| 104 | else |
| 105 | dprintf(INFO, "RPMB READ/WRITE TEST: [ FAIL ]\n"); |
| 106 | |
| 107 | free(read_info); |
| 108 | free(write_info); |
| 109 | #endif |
| 110 | |
| 111 | #if VERIFIED_BOOT |
| 112 | if (!boot_linux_from_mmc()) |
| 113 | dprintf(INFO, "Verifid Boot authentication test: [ PASS ]\n"); |
| 114 | else |
| 115 | dprintf(INFO, "Verifid Boot authentication test: [ FAIL ]\n"); |
| 116 | |
| 117 | kauth_test(); |
| 118 | #endif |
| 119 | |
| 120 | if (!thread_tests()) |
| 121 | dprintf(INFO, "Thread Test: [ PASS ]\n"); |
| 122 | else |
| 123 | dprintf(INFO, "Thread Test: [ FAIL ]\n"); |
| 124 | |
| 125 | printf_tests(); |
| 126 | |
Amir Kotzer | bb8be14 | 2016-02-23 09:38:25 +0200 | [diff] [blame^] | 127 | #ifdef MDTP_SUPPORT |
| 128 | dprintf(INFO, "Running mdtp LK tests ... \n"); |
| 129 | cmd_mdtp_runtests(); |
| 130 | #endif |
| 131 | |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 132 | fastboot_okay(""); |
Parth Dixit | cb0c608 | 2015-12-30 15:01:13 +0530 | [diff] [blame] | 133 | enable_test_mode = false; |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 134 | } |