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" |
Mayank Grover | 7a58ec7 | 2017-09-12 20:01:39 +0530 | [diff] [blame] | 39 | #include <ufs.h> |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 40 | #if USE_RPMB_FOR_DEVINFO |
| 41 | #include <rpmb.h> |
| 42 | #endif |
| 43 | /* main function that calls into the tests */ |
| 44 | |
| 45 | extern void ramdump_table_map(); |
| 46 | extern void kauth_test(); |
Sridhar Parasuram | 890f592 | 2015-09-28 15:43:57 -0700 | [diff] [blame] | 47 | extern int ufs_get_boot_lun(); |
| 48 | extern int ufs_set_boot_lun(uint32_t bootlunid); |
| 49 | extern int fastboot_init(); |
Parth Dixit | cb0c608 | 2015-12-30 15:01:13 +0530 | [diff] [blame] | 50 | static bool enable_test_mode = false; |
| 51 | |
| 52 | bool is_test_mode_enabled(void) |
| 53 | { |
| 54 | return enable_test_mode; |
| 55 | } |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 56 | |
| 57 | void cmd_oem_runtests() |
| 58 | { |
| 59 | dprintf(INFO, "Running LK tests ... \n"); |
Parth Dixit | cb0c608 | 2015-12-30 15:01:13 +0530 | [diff] [blame] | 60 | enable_test_mode = true; |
Sridhar Parasuram | 890f592 | 2015-09-28 15:43:57 -0700 | [diff] [blame] | 61 | // Test boot lun enable for UFS |
| 62 | if (!platform_boot_dev_isemmc()) |
| 63 | { |
| 64 | int ret = 0; |
| 65 | uint32_t set_lun = 0x2, get_lun; |
| 66 | ret = ufs_set_boot_lun(set_lun); |
| 67 | if (ret == UFS_SUCCESS) |
| 68 | { |
| 69 | get_lun = ufs_get_boot_lun(); |
| 70 | if (get_lun == set_lun) |
| 71 | { |
| 72 | dprintf(INFO, "UFS Boot LUN En TEST: [ PASS ]\n"); |
| 73 | set_lun = 0x1; // default is 0x1 LUN A, revert back to 0x1 |
| 74 | ret = ufs_set_boot_lun(set_lun); |
| 75 | } |
| 76 | else |
| 77 | dprintf(INFO, "UFS Boot LUN En TEST: [ FAIL ]\n"); |
| 78 | } |
| 79 | else |
| 80 | dprintf(INFO, "UFS Boot LUN En TEST: [ FAIL ]\n"); |
| 81 | } |
| 82 | |
| 83 | |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 84 | #if LPAE |
| 85 | ramdump_table_map(); |
| 86 | #endif |
| 87 | |
| 88 | #if USE_RPMB_FOR_DEVINFO |
| 89 | dprintf(INFO, "Running RPMB test case, please make sure RPMB key is provisioned ...\n"); |
| 90 | struct device_info *write_info = memalign(PAGE_SIZE, 4096); |
| 91 | struct device_info *read_info = memalign(PAGE_SIZE, 4096); |
Parth Dixit | d07685d | 2016-04-22 15:15:53 +0530 | [diff] [blame] | 92 | |
| 93 | if((write_info == NULL)||(read_info == NULL)) |
| 94 | { |
| 95 | dprintf(CRITICAL, "Failed to allocate memory for devinfo %s %d \n",__FUNCTION__,__LINE__); |
| 96 | goto err; |
| 97 | } |
| 98 | |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 99 | if((read_device_info_rpmb((void*) read_info, PAGE_SIZE)) < 0) |
| 100 | dprintf(INFO, "RPMB READ TEST : [ FAIL ]\n"); |
| 101 | |
| 102 | write_info->is_unlocked = !read_info->is_unlocked; |
| 103 | |
| 104 | if((write_device_info_rpmb((void*) write_info, PAGE_SIZE)) < 0) |
| 105 | dprintf(INFO, "RPMB WRITE TEST : [ FAIL ]\n"); |
| 106 | |
| 107 | if((read_device_info_rpmb((void*) read_info, PAGE_SIZE)) < 0) |
| 108 | dprintf(INFO, "RPMB READ TEST : [ FAIL ]\n"); |
| 109 | |
| 110 | if (read_info->is_unlocked == write_info->is_unlocked) |
| 111 | dprintf(INFO, "RPMB READ/WRITE TEST: [ PASS ]\n"); |
| 112 | else |
| 113 | dprintf(INFO, "RPMB READ/WRITE TEST: [ FAIL ]\n"); |
| 114 | |
Parth Dixit | d07685d | 2016-04-22 15:15:53 +0530 | [diff] [blame] | 115 | err: |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 116 | free(read_info); |
| 117 | free(write_info); |
| 118 | #endif |
| 119 | |
| 120 | #if VERIFIED_BOOT |
| 121 | if (!boot_linux_from_mmc()) |
| 122 | dprintf(INFO, "Verifid Boot authentication test: [ PASS ]\n"); |
| 123 | else |
| 124 | dprintf(INFO, "Verifid Boot authentication test: [ FAIL ]\n"); |
| 125 | |
| 126 | kauth_test(); |
| 127 | #endif |
| 128 | |
| 129 | if (!thread_tests()) |
| 130 | dprintf(INFO, "Thread Test: [ PASS ]\n"); |
| 131 | else |
| 132 | dprintf(INFO, "Thread Test: [ FAIL ]\n"); |
| 133 | |
| 134 | printf_tests(); |
| 135 | |
Amir Kotzer | bb8be14 | 2016-02-23 09:38:25 +0200 | [diff] [blame] | 136 | #ifdef MDTP_SUPPORT |
| 137 | dprintf(INFO, "Running mdtp LK tests ... \n"); |
| 138 | cmd_mdtp_runtests(); |
| 139 | #endif |
| 140 | |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 141 | fastboot_okay(""); |
Parth Dixit | cb0c608 | 2015-12-30 15:01:13 +0530 | [diff] [blame] | 142 | enable_test_mode = false; |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 143 | } |