// File: /workspace/github_cpp_makefile_star2_O2/goodix[P]gdix_hid_firmware_update/gtx2/gtx2_update.cpp
// Function: GTx2Update::Run(void*)
int GTx2Update::Run(void *para)
{
	int ret = 0;
	int retry = 0;
	updateFlag flag = NO_NEED_UPDATE;
	if (!m_Initialized) {
		gdix_err("Can't Process Update Before Initialized.\n");
		return -1;
	}
	// get all parameter
	pGTUpdatePara parameter = (pGTUpdatePara)para;

	// check if the image has config
	if (image->HasConfig()) {
		flag = image->GetUpdateFlag();
	} else {
		// default for firmware
		flag = NEED_UPDATE_FW;
	}

	gdix_dbg("Flag = %d\n", flag);

	if (!parameter->force) {
		ret = check_update();
		if (ret) {
			gdix_err("Doesn't meet the update conditions\n");
			return -3;
		}
	}

	if (flag & NEED_UPDATE_CONFIG) {
		retry = 0;
		do {
			ret = cfg_update();
			if (ret) {
				gdix_dbg("Update cfg failed\n");
				usleep(200000);
			} else {
				usleep(300000);
				gdix_dbg("Update cfg success\n");
				break;
			}
		} while (retry++ < 3);
		if (ret) {
			gdix_err("config update err:ret=%d\n", ret);
			return ret;
		}
	}

	if (flag & NEED_UPDATE_FW) {
		retry = 0;
		do {
			ret = fw_update(parameter->firmwareFlag);
			if (ret) {
				gdix_dbg("Update failed\n");
				usleep(200000);
			} else {
				usleep(300000);
				gdix_dbg("Update success\n");
				break;
			}
		} while (retry++ < 3);
		if (ret) {
			gdix_err("Firmware update err:ret=%d\n", ret);
			return ret;
		}
	}

	// before go forward,Set Basic Properties to refresh SensorID
	// dev->SetBasicProperties();

	// if (flag & NEED_UPDATE_CONFIG) {
	// 	retry = 0;
	// 	do {
	// 		ret = cfg_update();
	// 		if (ret) {
	// 			gdix_dbg("Update cfg failed\n");
	// 			usleep(200000);
	// 		} else {
	// 			usleep(300000);
	// 			gdix_dbg("Update cfg success\n");
	// 			break;
	// 		}
	// 	} while (retry++ < 3);
	// 	if (ret) {
	// 		gdix_err("config update err:ret=%d\n", ret);
	// 		return ret;
	// 	}
	// }
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpb $0x0, 0x18(%rdi)
je 0x9287
movq %rsi, %rbx
movq %rdi, %r14
movq 0x10(%rdi), %rdi
movq (%rdi), %rax
callq *0x98(%rax)
testb %al, %al
je 0x92b9
movq 0x10(%r14), %rdi
movq (%rdi), %rax
callq *0xa8(%rax)
movl %eax, %ebp
jmp 0x92bc
leaq 0x17003(%rip), %rax     # 0x20291
pushq $-0x1
popq %rbp
cmpb $0x1, (%rax)
jne 0x94af
movq 0x16d37(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xcd6e(%rip), %rsi      # 0x16019
leaq 0xcda2(%rip), %rdx      # 0x16054
pushq $0x35
jmp 0x94a3
pushq $0x1
popq %rbp
leaq 0x16fce(%rip), %r12     # 0x20291
cmpb $0x1, (%r12)
jne 0x92ef
movq 0x16ce7(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xd970(%rip), %rsi      # 0x16c4b
leaq 0xcd72(%rip), %rdx      # 0x16054
pushq $0x43
popq %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
cmpb $0x0, (%rbx)
jne 0x932e
movq (%r14), %rax
movq %r14, %rdi
callq *0x20(%rax)
testl %eax, %eax
je 0x932e
pushq $-0x3
popq %rbp
cmpb $0x1, (%r12)
jne 0x94af
movq 0x16cc2(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xcd61(%rip), %rsi      # 0x16081
leaq 0xcd2d(%rip), %rdx      # 0x16054
pushq $0x48
jmp 0x94a3
testb $0x2, %bpl
je 0x93ec
movl %ebp, 0x4(%rsp)
pushq $0x4
popq %r13
pushq $0x52
popq %r15
movq (%r14), %rax
movq %r14, %rdi
callq *0x38(%rax)
testl %eax, %eax
je 0x93b5
movl %eax, %ebp
cmpb $0x1, (%r12)
jne 0x937c
movq 0x16c57(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xcdba(%rip), %rsi      # 0x16125
leaq 0xcce2(%rip), %rdx      # 0x16054
movl %r15d, %ecx
xorl %eax, %eax
callq 0x5180
movl $0x30d40, %edi          # imm = 0x30D40
callq 0x5170
decl %r13d
jne 0x9344
cmpb $0x1, (%r12)
jne 0x94af
movq 0x16c3b(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xcdc7(%rip), %rsi      # 0x1616e
leaq 0xcca6(%rip), %rdx      # 0x16054
pushq $0x5b
jmp 0x9469
movl $0x493e0, %edi          # imm = 0x493E0
callq 0x5170
cmpb $0x1, (%r12)
movl 0x4(%rsp), %ebp
jne 0x93ec
movq 0x16be7(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xcd6e(%rip), %rsi      # 0x16149
leaq 0xcc72(%rip), %rdx      # 0x16054
pushq $0x56
popq %rcx
xorl %eax, %eax
callq 0x5180
testb $0x1, %bpl
je 0x94ad
pushq $0x4
popq %r15
pushq $0x65
popq %r13
movl 0x4(%rbx), %esi
movq (%r14), %rax
movq %r14, %rdi
callq *0x30(%rax)
testl %eax, %eax
je 0x9476
movl %eax, %ebp
cmpb $0x1, (%r12)
jne 0x9439
movq 0x16b9a(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xcc8e(%rip), %rsi      # 0x160b6
leaq 0xcc25(%rip), %rdx      # 0x16054
movl %r13d, %ecx
xorl %eax, %eax
callq 0x5180
movl $0x30d40, %edi          # imm = 0x30D40
callq 0x5170
decl %r15d
jne 0x93fe
cmpb $0x1, (%r12)
jne 0x94af
movq 0x16b82(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0xc4b2(%rip), %rsi      # 0x15912
leaq 0xcbed(%rip), %rdx      # 0x16054
pushq $0x6e
popq %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5180
jmp 0x94af
movl $0x493e0, %edi          # imm = 0x493E0
callq 0x5170
cmpb $0x1, (%r12)
jne 0x94ad
movq 0x16b2a(%rip), %rax     # 0x1ffb8
movq (%rax), %rdi
leaq 0xcc3e(%rip), %rsi      # 0x160d6
leaq 0xcbb5(%rip), %rdx      # 0x16054
xorl %ebp, %ebp
pushq $0x69
popq %rcx
xorl %eax, %eax
callq 0x5180
jmp 0x94af
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq