[Feature][task-view-765][FOTA]add api for get current slot

Only Configure: No
Affected branch: ZK-first-oem-release
Affected module: FOTA
Is it affected on both ZXIC and MTK: only MTK
Self-test: Yes
Doc Update: No

Change-Id: I7ed38c9d5f16f14b255f3e7a6b6062b25e932dd8
diff --git a/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-fota/include/iot_rock.h b/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-fota/include/iot_rock.h
index ea557b9..ed974d5 100755
--- a/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-fota/include/iot_rock.h
+++ b/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-fota/include/iot_rock.h
@@ -138,7 +138,7 @@
 #define DELTA_FULL_HEARD_SIZE   8

 

 

-

+int lynq_get_slot(void);

 int iot_patch(IOT_UPDATA_CONTEXT* update_ctx);

 int lynq_read_process(void);

 unsigned int iot_hash(unsigned char *buf,unsigned int len, unsigned int* value);

diff --git a/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-fota/rock_ua/rock_ua.c b/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-fota/rock_ua/rock_ua.c
index 160ccec..7002f3e 100755
--- a/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-fota/rock_ua/rock_ua.c
+++ b/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-fota/rock_ua/rock_ua.c
@@ -2223,6 +2223,61 @@
     return lynq_ota_status.update_result;
 }
 
+int lynq_get_slot(void)
+{
+    int ret=0;
+    int ret_a = 0;
+    int ret_b = 0;
+    int is_successful = 0;
+    int current_slot = 0;
+    const hw_module_t* hw_module;
+    hw_module = &HAL_MODULE_INFO_SYM;
+
+    if (!hw_module ||
+        strcmp(BOOT_CONTROL_HARDWARE_MODULE_ID, hw_module->id) != 0) {
+        ret = -EINVAL;
+    }
+    if (ret != 0) {
+        RLOGE("+[UA]: Error loading boot_control HAL implementation.\n");
+        return -1;
+    }
+
+    module = (boot_control_module_t*)hw_module;
+    module->init(module);
+
+    if (module == NULL) {
+        RLOGE("+[UA]: Error getting bootctrl module.\n");
+        return  -1;
+    }
+
+    current_slot = module->getCurrentSlot(module);
+
+    is_successful = module->isSlotMarkedSuccessful(module, current_slot);
+
+    RLOGE("Booting slot = %d, : isSlotMarkedSuccessful= %d\n",current_slot,is_successful);
+    if((current_slot != 0)&&(current_slot != 1))
+    {
+        ret_a = system("cat /proc/cmdline |grep slot_suffix=_a");
+        ret_b = system("cat /proc/cmdline |grep slot_suffix=_b");
+        if((ret_a == 0) && (ret_b !=0))
+        {
+            current_slot = 0;
+        }
+        else if((ret_a != 0) && (ret_b ==0))
+        {
+            current_slot = 1;
+        }
+        else
+        {
+            current_slot = -1;
+        }
+
+    }
+    RLOGE("current_slot = %d\n", current_slot);
+    return current_slot;
+}
+
+
 /**
  * @brief reboot device
  *