blob: 70bc64ef49f2feccaaf3d03945b43c46892fd0c4 [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"
Channagoud Kadabi736c4962015-08-21 11:56:52 -070039#if USE_RPMB_FOR_DEVINFO
40#include <rpmb.h>
41#endif
42/* main function that calls into the tests */
43
44extern void ramdump_table_map();
45extern void kauth_test();
Sridhar Parasuram890f5922015-09-28 15:43:57 -070046extern int ufs_get_boot_lun();
47extern int ufs_set_boot_lun(uint32_t bootlunid);
48extern int fastboot_init();
Parth Dixitcb0c6082015-12-30 15:01:13 +053049static bool enable_test_mode = false;
50
51bool is_test_mode_enabled(void)
52{
53 return enable_test_mode;
54}
Channagoud Kadabi736c4962015-08-21 11:56:52 -070055
56void cmd_oem_runtests()
57{
58 dprintf(INFO, "Running LK tests ... \n");
Parth Dixitcb0c6082015-12-30 15:01:13 +053059 enable_test_mode = true;
Sridhar Parasuram890f5922015-09-28 15:43:57 -070060 // 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 Kadabi736c4962015-08-21 11:56:52 -070083#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);
Parth Dixitd07685d2016-04-22 15:15:53 +053091
92 if((write_info == NULL)||(read_info == NULL))
93 {
94 dprintf(CRITICAL, "Failed to allocate memory for devinfo %s %d \n",__FUNCTION__,__LINE__);
95 goto err;
96 }
97
Channagoud Kadabi736c4962015-08-21 11:56:52 -070098 if((read_device_info_rpmb((void*) read_info, PAGE_SIZE)) < 0)
99 dprintf(INFO, "RPMB READ TEST : [ FAIL ]\n");
100
101 write_info->is_unlocked = !read_info->is_unlocked;
102
103 if((write_device_info_rpmb((void*) write_info, PAGE_SIZE)) < 0)
104 dprintf(INFO, "RPMB WRITE TEST : [ FAIL ]\n");
105
106 if((read_device_info_rpmb((void*) read_info, PAGE_SIZE)) < 0)
107 dprintf(INFO, "RPMB READ TEST : [ FAIL ]\n");
108
109 if (read_info->is_unlocked == write_info->is_unlocked)
110 dprintf(INFO, "RPMB READ/WRITE TEST: [ PASS ]\n");
111 else
112 dprintf(INFO, "RPMB READ/WRITE TEST: [ FAIL ]\n");
113
Parth Dixitd07685d2016-04-22 15:15:53 +0530114err:
Channagoud Kadabi736c4962015-08-21 11:56:52 -0700115 free(read_info);
116 free(write_info);
117#endif
118
119#if VERIFIED_BOOT
120 if (!boot_linux_from_mmc())
121 dprintf(INFO, "Verifid Boot authentication test: [ PASS ]\n");
122 else
123 dprintf(INFO, "Verifid Boot authentication test: [ FAIL ]\n");
124
125 kauth_test();
126#endif
127
128 if (!thread_tests())
129 dprintf(INFO, "Thread Test: [ PASS ]\n");
130 else
131 dprintf(INFO, "Thread Test: [ FAIL ]\n");
132
133 printf_tests();
134
Amir Kotzerbb8be142016-02-23 09:38:25 +0200135#ifdef MDTP_SUPPORT
136 dprintf(INFO, "Running mdtp LK tests ... \n");
137 cmd_mdtp_runtests();
138#endif
139
Channagoud Kadabi736c4962015-08-21 11:56:52 -0700140 fastboot_okay("");
Parth Dixitcb0c6082015-12-30 15:01:13 +0530141 enable_test_mode = false;
Channagoud Kadabi736c4962015-08-21 11:56:52 -0700142}