app: aboot: mdtp: read mdtp eFuse in runtime

Since 8976 and 8952 have the same binaries,
we can no longer pick the relevant mdtp eFuse
during compilation. Therefore, the code was
modified to retrieve the correct eFuse in
runtime, based on the target we actually
run on.

Change-Id: I14a80bab43b08939c73b010fa8c607982bc8cc6d
diff --git a/app/aboot/mdtp_ui_defs.c b/app/aboot/mdtp_defs.c
similarity index 92%
rename from app/aboot/mdtp_ui_defs.c
rename to app/aboot/mdtp_defs.c
index 2c9fbb0..d9eb903 100644
--- a/app/aboot/mdtp_ui_defs.c
+++ b/app/aboot/mdtp_defs.c
@@ -28,7 +28,7 @@
  */
 
 #include <compiler.h>
-#include "mdtp_ui_defs.h"
+#include "mdtp_defs.h"
 
 struct mdtp_ui_defs mdtp_ui_defs_default = {
         // Image dimensions
@@ -66,3 +66,10 @@
 {
     return mdtp_ui_defs_default;
 }
+
+__WEAK int mdtp_get_target_efuse(struct mdtp_target_efuse* target_efuse)
+{
+
+    dprintf(CRITICAL, "mdtp: mdtp_get_target_efuse: ERROR, eFuse not defined for this target\n");
+    return -1;
+}
diff --git a/app/aboot/mdtp_ui_defs.h b/app/aboot/mdtp_defs.h
similarity index 94%
rename from app/aboot/mdtp_ui_defs.h
rename to app/aboot/mdtp_defs.h
index 15e3b51..9fe05ae 100644
--- a/app/aboot/mdtp_ui_defs.h
+++ b/app/aboot/mdtp_defs.h
@@ -62,4 +62,11 @@
     uint32_t digit_space;
 };
 
+struct mdtp_target_efuse {
+    uint32_t address;
+    uint32_t start;
+};
+
 struct mdtp_ui_defs mdtp_get_target_ui_defs();
+
+int mdtp_get_target_efuse(struct mdtp_target_efuse* target_efuse);
diff --git a/app/aboot/mdtp_fuse.c b/app/aboot/mdtp_fuse.c
index a66f87b..7f67661 100644
--- a/app/aboot/mdtp_fuse.c
+++ b/app/aboot/mdtp_fuse.c
@@ -34,6 +34,7 @@
 #include <stdlib.h>
 #include <reg.h>
 #include "mdtp.h"
+#include "mdtp_defs.h"
 #include "scm.h"
 
 #define MAX_METADATA_SIZE       (0x1000)
@@ -92,12 +93,12 @@
 	}
 	else
 	{
-		dprintf(CRITICAL, "mdtp: is_test_mode: qsee_get_secure_state returned error: %d, status.value[0]: %d", ret, status_low);
+		dprintf(CRITICAL, "mdtp: is_test_mode: qsee_get_secure_state returned error: %d, status.value[0]: %d\n", ret, status_low);
 		test_mode = 0;
     }
 
 	test_mode_set = 1;
-	dprintf(INFO, "mdtp: is_test_mode: test mode is set to %d", test_mode);
+	dprintf(INFO, "mdtp: is_test_mode: test mode is set to %d\n", test_mode);
 
 	return test_mode;
 }
@@ -155,12 +156,19 @@
  */
 static int read_QFPROM_fuse(uint8_t *mask)
 {
+	struct mdtp_target_efuse target_efuse;
 	uint32_t val = 0;
 
-	val = readl(MDTP_EFUSE_ADDRESS);
+	if (mdtp_get_target_efuse(&target_efuse))
+	{
+		dprintf(CRITICAL, "mdtp: read_QFPROM_fuse: failed to get target eFuse\n");
+		return -1;
+	}
+
+	val = readl(target_efuse.address);
 
 	/* Shift the read data to be reflected in mask */
-	*mask = (uint8_t)(val >> MDTP_EFUSE_START);
+	*mask = (uint8_t)(val >> target_efuse.start);
 
 	return 0;
 }
@@ -181,7 +189,7 @@
 
 	status = read_metadata(&metadata);
 	if (status) {
-		dprintf(CRITICAL, "mdtp: read_test_fuse: Failure getting metadata");
+		dprintf(CRITICAL, "mdtp: read_test_fuse: Failure getting metadata\n");
 		return -1;
 	}
 
@@ -229,7 +237,7 @@
 	status = read_fuse(&eFuses.mask);
 	if (status)
 	{
-		dprintf(CRITICAL, "mdtp: mdtp_fuse_get_enabled: Failure in reading fuse");
+		dprintf(CRITICAL, "mdtp: mdtp_fuse_get_enabled: Failure in reading fuse\n");
 		return -1;
 	}
 
diff --git a/app/aboot/mdtp_ui.c b/app/aboot/mdtp_ui.c
index dcdf75f..643ed73 100644
--- a/app/aboot/mdtp_ui.c
+++ b/app/aboot/mdtp_ui.c
@@ -34,7 +34,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "mdtp.h"
-#include "mdtp_ui_defs.h"
+#include "mdtp_defs.h"
 
 // Image releative locations
 #define ERROR_MESSAGE_RELATIVE_Y_LOCATION   (0.18)
@@ -62,8 +62,6 @@
     uint8_t image[MDTP_MAX_IMAGE_SIZE];
 };
 
-struct mdtp_ui_defs mdtp_ui_defs_data;
-
 /*----------------------------------------------------------------------------
  * Global Variables
  * -------------------------------------------------------------------------*/
@@ -76,6 +74,8 @@
 static struct mdtp_fbimage *g_mdtp_header = NULL;
 static struct fbcon_config *fb_config = NULL;
 
+struct mdtp_ui_defs mdtp_ui_defs_data;
+
 /*----------------------------------------------------------------------------
  * Local Functions
  * -------------------------------------------------------------------------*/
diff --git a/app/aboot/rules.mk b/app/aboot/rules.mk
index cbc053a..24bca43 100644
--- a/app/aboot/rules.mk
+++ b/app/aboot/rules.mk
@@ -16,5 +16,5 @@
 	$(LOCAL_DIR)/mdtp.o \
 	$(LOCAL_DIR)/mdtp_ui.o \
 	$(LOCAL_DIR)/mdtp_fuse.o \
-	$(LOCAL_DIR)/mdtp_ui_defs.o
+	$(LOCAL_DIR)/mdtp_defs.o
 endif
diff --git a/target/msm8952/mdtp_ui_defs.c b/target/msm8952/mdtp_ui_defs.c
index 7091f15..668feb2 100644
--- a/target/msm8952/mdtp_ui_defs.c
+++ b/target/msm8952/mdtp_ui_defs.c
@@ -27,7 +27,7 @@
  *
  */
 
-#include "mdtp_ui_defs.h"
+#include "mdtp_defs.h"
 
 struct mdtp_ui_defs mdtp_ui_defs_msm8952 = {
         // Image dimensions