Merge "platform: msm_shared: increase the dynamic fps frame rate size" into lk.lnx.1.0-dev.1.0
diff --git a/app/aboot/fastboot_test.c b/app/aboot/fastboot_test.c
index 7941f61..64c0f7f 100644
--- a/app/aboot/fastboot_test.c
+++ b/app/aboot/fastboot_test.c
@@ -35,6 +35,7 @@
 #include <app/tests.h>
 #include <target.h>
 #include <boot_device.h>
+#include "mdtp.h"
 #if USE_RPMB_FOR_DEVINFO
 #include <rpmb.h>
 #endif
@@ -123,6 +124,11 @@
 
 	printf_tests();
 
+#ifdef MDTP_SUPPORT
+	dprintf(INFO, "Running mdtp LK tests ... \n");
+	cmd_mdtp_runtests();
+#endif
+
 	fastboot_okay("");
 	enable_test_mode = false;
 }
diff --git a/app/aboot/mdtp.c b/app/aboot/mdtp.c
index a2d52bf..a38092e 100644
--- a/app/aboot/mdtp.c
+++ b/app/aboot/mdtp.c
@@ -57,6 +57,14 @@
 /** Extract major version number from complete version. */
 #define MDTP_GET_MAJOR_VERSION(version) ((version) >> 16)
 
+
+/** UT defines **/
+#define BAD_PARAM_SIZE 0
+#define BAD_PARAM_VERIF_RATIO 101
+#define BAD_HASH_MODE 10
+
+/********************************************************************************/
+
 static int mdtp_tzbsp_dec_verify_DIP(DIP_t *enc_dip, DIP_t *dec_dip, uint32_t *verified);
 static int mdtp_tzbsp_enc_hash_DIP(DIP_t *dec_dip, DIP_t *enc_dip);
 static void mdtp_tzbsp_disallow_cipher_DIP(void);
@@ -400,7 +408,7 @@
 static void display_recovery_ui(mdtp_cfg_t *mdtp_cfg)
 {
 	uint32_t pin_length = 0;
-	char entered_pin[MDTP_MAX_PIN_LEN+1] = {0};
+	char entered_pin[MDTP_PIN_LEN+1] = {0};
 	uint32_t i;
 	char pin_mismatch = 0;
 
@@ -410,7 +418,7 @@
 
 		pin_length = strlen(mdtp_cfg->mdtp_pin.mdtp_pin);
 
-		if (pin_length > MDTP_MAX_PIN_LEN || pin_length < MDTP_MIN_PIN_LEN)
+		if (pin_length != MDTP_PIN_LEN)
 		{
 			dprintf(CRITICAL, "mdtp: display_recovery_ui: Error, invalid PIN length\n");
 			display_error_msg(); /* This will never return */
@@ -882,3 +890,86 @@
 
 	free(dip);
 }
+
+/********************************************************************************/
+
+/** UT functions **/
+
+/** Hashing fuctions UT **/
+int mdtp_verify_hash_ut(){
+	unsigned char digest[HASH_LEN]={0};
+	unsigned int hash_expected_result = 0xD42B0A29;
+	char *buf = "MTDP LK UT hashing functions sanity check";
+	int size = 0;
+	DIP_hash_table_entry_t partition_hash_table;
+	uint8_t partition_force_verify_block = 0;
+
+	char ptr = buf[0];
+	while(ptr){
+		ptr = buf[++size];
+	}
+	//Bad partition name - single mode
+	if(verify_partition_single_hash("BAD_PARTITION", 1, &partition_hash_table) != -1){
+		dprintf(INFO, "verify_hash_ut: [FAIL (1)].\n");
+		return -1;
+	}
+
+	//Bad partition name - block mode
+	if(verify_partition_block_hash("BAD_PARTITION", 1, 1, &partition_hash_table, &partition_force_verify_block) != -1){
+		dprintf(INFO, "verify_hash_ut: [FAIL (2)].\n");
+		return -1;
+	}
+
+	//Hashing sanity check
+	hash_find((unsigned char*)buf, size, digest, CRYPTO_AUTH_ALG_SHA256);
+	unsigned int *hash_res = (unsigned int *)digest;
+	if (*hash_res != hash_expected_result){
+		dprintf(INFO, "verify_hash_ut: [FAIL (3)].\n");
+		return -1;
+	}
+	dprintf(INFO, "verify_hash_ut: [PASS].\n");
+	return 0;
+}
+
+/** Validate partitions params UT **/
+int mdtp_validate_partition_params_ut(){
+	int partition_size = 10;
+	//Bad size
+	if(validate_partition_params(BAD_PARAM_SIZE, MDTP_FWLOCK_MODE_SINGLE, 1) != -1){
+		dprintf(INFO, "validate_partition_params_ut: [FAIL (1)].\n");
+		return -1;
+	}
+
+	//Bad size
+	if(validate_partition_params((uint64_t)MDTP_FWLOCK_BLOCK_SIZE * (uint64_t)MAX_BLOCKS + 1,
+		MDTP_FWLOCK_MODE_SINGLE, 1) != -1){
+		dprintf(INFO, "validate_partition_params_ut: [FAIL (2)].\n");
+		return -1;
+	}
+
+	//Bad verification ratio
+	if(validate_partition_params(partition_size, MDTP_FWLOCK_MODE_SIZE, BAD_PARAM_VERIF_RATIO) != -1){
+		dprintf(INFO, "validate_partition_params_ut: [FAIL (3)].\n");
+		return -1;
+	}
+	dprintf(INFO, "MDTP LK UT: validate_partition_params_ut [ PASS ]\n");
+	return 0;
+}
+
+/** Verify partition UT **/
+int mdtp_verify_partition_ut(){
+	uint8_t partition_force_verify_block = 0;
+	DIP_hash_table_entry_t partition_hash_table;
+	int verify_num_blocks = 10,partition_size = 1;
+
+	//Unkown hashing mode
+	if(verify_partition("system", partition_size, BAD_HASH_MODE, verify_num_blocks,
+		&partition_hash_table, &partition_force_verify_block) != -1){
+		dprintf(INFO, "verify_partition_ut: Failed Test 1.\n");
+		dprintf(INFO, "MDTP LK UT: verify_partition_ut [ FAIL ]\n");
+		return -1;
+	}
+	dprintf(INFO, "MDTP LK UT: verify_partition_ut [ PASS ]\n");
+	return 0;
+}
+
diff --git a/app/aboot/mdtp.h b/app/aboot/mdtp.h
index 88eff44..adb3878 100644
--- a/app/aboot/mdtp.h
+++ b/app/aboot/mdtp.h
@@ -34,8 +34,7 @@
 #define MAX_PARTITIONS         (3)
 #define MAX_PARTITION_NAME_LEN (100)
 #define HASH_LEN               (32)
-#define MDTP_MAX_PIN_LEN       (8)
-#define MDTP_MIN_PIN_LEN       (5)
+#define MDTP_PIN_LEN           (8)
 #define DIP_PADDING            (15)
 
 #define INITIAL_DELAY_MSECONDS      5000
@@ -84,14 +83,14 @@
 } DIP_partition_cfg_t;
 
 typedef struct mdtp_pin {
-	char mdtp_pin[MDTP_MAX_PIN_LEN+1];              /* A null terminated PIN. */
+	char mdtp_pin[MDTP_PIN_LEN+1];              /* A null terminated PIN. */
 } mdtp_pin_t;
 
 /** MDTP configuration. */
 typedef struct mdtp_cfg {
 	uint8_t enable_local_pin_authentication;/* Allow local authentication using a PIN. */
 	mdtp_pin_t mdtp_pin;                    /* Null terminated PIN provided by the user for local deactivation.
-                                               PIN length should be from MDTP_MIN_PIN_LEN to MDTP_MAX_PIN_LEN digits. */
+                                               PIN length should be MDTP_PIN_LEN digits. */
 } mdtp_cfg_t;
 
 typedef struct DIP {
@@ -217,4 +216,17 @@
  **/
 void mdtp_fwlock_verify_lock(mdtp_ext_partition_verification_t *ext_partition);
 
+
+//UT functions
+
+/** Entry point of the MDTP LK UT.
+ * Start UT on LK mdtp components during fastboot.
+ **/
+void cmd_mdtp_runtests();
+
+int mdtp_verify_hash_ut();
+int mdtp_validate_partition_params_ut();
+int mdtp_verify_partition_ut();
+int mdtp_verify_external_partition_ut(mdtp_ext_partition_verification_t* ext_partition);
+
 #endif
diff --git a/app/aboot/mdtp_lk_ut.c b/app/aboot/mdtp_lk_ut.c
new file mode 100644
index 0000000..4fc1178
--- /dev/null
+++ b/app/aboot/mdtp_lk_ut.c
@@ -0,0 +1,53 @@
+/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include <stdlib.h>
+#include "mdtp.h"
+#include "mdtp_defs.h"
+#include "fastboot_test.h"
+
+
+/** External UT Functions **/
+void cmd_mdtp_runtests(){
+	bool res = false;
+	int tests_res = 0;
+	struct mdtp_target_efuse target_efuse;
+
+	tests_res += mdtp_fuse_get_enabled(&res);
+	tests_res += mdtp_get_target_efuse(&target_efuse);
+	tests_res += mdtp_verify_hash_ut();
+	tests_res += mdtp_validate_partition_params_ut();
+	tests_res += mdtp_verify_partition_ut();
+
+	if(!tests_res){
+		dprintf(INFO, "MDTP LK UT: [ PASS ]\n");
+	}else{
+		dprintf(INFO, "MDTP LK UT: [ FAILED ]\n");
+	}
+}
\ No newline at end of file
diff --git a/app/aboot/mdtp_ui.c b/app/aboot/mdtp_ui.c
index f03b818..fafb787 100644
--- a/app/aboot/mdtp_ui.c
+++ b/app/aboot/mdtp_ui.c
@@ -69,7 +69,7 @@
  * Global Variables
  * -------------------------------------------------------------------------*/
 
-static uint32_t g_pin_frames_x_location[MDTP_MAX_PIN_LEN] = {0};
+static uint32_t g_pin_frames_x_location[MDTP_PIN_LEN] = {0};
 static uint32_t g_pin_frames_y_location = 0;
 
 static bool g_initial_screen_displayed = false;
diff --git a/app/aboot/rules.mk b/app/aboot/rules.mk
index 68e1c9b..36b8c58 100644
--- a/app/aboot/rules.mk
+++ b/app/aboot/rules.mk
@@ -14,6 +14,10 @@
 ifeq ($(ENABLE_UNITTEST_FW), 1)
 OBJS += \
 	$(LOCAL_DIR)/fastboot_test.o
+	ifeq ($(ENABLE_MDTP_SUPPORT),1)
+		OBJS += \
+			$(LOCAL_DIR)/mdtp_lk_ut.o
+	endif
 endif
 
 ifeq ($(ENABLE_MDTP_SUPPORT),1)