blob: 64c0f7f7883e3fdb9943a5132c39b3929c38008e [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);
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 Kotzerbb8be142016-02-23 09:38:25 +0200127#ifdef MDTP_SUPPORT
128 dprintf(INFO, "Running mdtp LK tests ... \n");
129 cmd_mdtp_runtests();
130#endif
131
Channagoud Kadabi736c4962015-08-21 11:56:52 -0700132 fastboot_okay("");
Parth Dixitcb0c6082015-12-30 15:01:13 +0530133 enable_test_mode = false;
Channagoud Kadabi736c4962015-08-21 11:56:52 -0700134}