blob: 5ad5b58de431a6e63847393604f35d0151f10574 [file] [log] [blame]
Channagoud Kadabi736c4962015-08-21 11:56:52 -07001/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions are
5met:
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
16THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26IF 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 Parasuram890f5922015-09-28 15:43:57 -070036#include <target.h>
37#include <boot_device.h>
Amir Kotzerbb8be142016-02-23 09:38:25 +020038#include "mdtp.h"
Mayank Grover7a58ec72017-09-12 20:01:39 +053039#include <ufs.h>
Channagoud Kadabi736c4962015-08-21 11:56:52 -070040#if USE_RPMB_FOR_DEVINFO
41#include <rpmb.h>
42#endif
43/* main function that calls into the tests */
44
45extern void ramdump_table_map();
46extern void kauth_test();
Sridhar Parasuram890f5922015-09-28 15:43:57 -070047extern int ufs_get_boot_lun();
48extern int ufs_set_boot_lun(uint32_t bootlunid);
49extern int fastboot_init();
Parth Dixitcb0c6082015-12-30 15:01:13 +053050static bool enable_test_mode = false;
51
52bool is_test_mode_enabled(void)
53{
54 return enable_test_mode;
55}
Channagoud Kadabi736c4962015-08-21 11:56:52 -070056
57void cmd_oem_runtests()
58{
59 dprintf(INFO, "Running LK tests ... \n");
Parth Dixitcb0c6082015-12-30 15:01:13 +053060 enable_test_mode = true;
Sridhar Parasuram890f5922015-09-28 15:43:57 -070061 // 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 Kadabi736c4962015-08-21 11:56:52 -070084#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 Dixitd07685d2016-04-22 15:15:53 +053092
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 Kadabi736c4962015-08-21 11:56:52 -070099 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 Dixitd07685d2016-04-22 15:15:53 +0530115err:
Channagoud Kadabi736c4962015-08-21 11:56:52 -0700116 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 Kotzerbb8be142016-02-23 09:38:25 +0200136#ifdef MDTP_SUPPORT
137 dprintf(INFO, "Running mdtp LK tests ... \n");
138 cmd_mdtp_runtests();
139#endif
140
Channagoud Kadabi736c4962015-08-21 11:56:52 -0700141 fastboot_okay("");
Parth Dixitcb0c6082015-12-30 15:01:13 +0530142 enable_test_mode = false;
Channagoud Kadabi736c4962015-08-21 11:56:52 -0700143}