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

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

	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");
			return 0;
		}
	} while (retry++ < 3);
	gdix_err("Firmware update err:ret=%d\n", ret);
	return -4;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
testb $0x1, 0x18(%rax)
jne 0xfd7c
jmp 0xfd3e
leaq 0x16554(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xfd6e
movq 0x16287(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0xd314(%rip), %rsi      # 0x1d06f
leaq 0xd348(%rip), %rdx      # 0x1d0aa
movl $0x2d, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xfd70
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xfedd
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
testb $0x1, (%rax)
jne 0xfde2
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xfde0
jmp 0xfda2
leaq 0x164f0(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xfdd2
movq 0x16223(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0xd318(%rip), %rsi      # 0x1d0d7
leaq 0xd2e4(%rip), %rdx      # 0x1d0aa
movl $0x36, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xfdd4
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0xfedd
jmp 0xfde2
movl $0x0, -0x20(%rbp)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %esi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xfe43
jmp 0xfe05
leaq 0x1648d(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xfe35
movq 0x161a0(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq 0xd2ea(%rip), %rsi      # 0x1d10c
leaq 0xd281(%rip), %rdx      # 0x1d0aa
movl $0x3f, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xfe37
movl $0x30d40, %edi          # imm = 0x30D40
callq 0x5180
jmp 0xfe88
movl $0x493e0, %edi          # imm = 0x493E0
callq 0x5180
leaq 0x16445(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xfe7d
movq 0x16158(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq 0xd2c2(%rip), %rsi      # 0x1d12c
leaq 0xd239(%rip), %rdx      # 0x1d0aa
movl $0x43, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xfe7f
movl $0x0, -0x4(%rbp)
jmp 0xfedd
jmp 0xfe8a
movl -0x20(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x20(%rbp)
cmpl $0x3, %eax
jl 0xfde9
jmp 0xfea0
leaq 0x163f2(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xfed4
movq 0x16125(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
movl -0x1c(%rbp), %r8d
leaq 0xcaa2(%rip), %rsi      # 0x1c963
leaq 0xd1e2(%rip), %rdx      # 0x1d0aa
movl $0x47, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xfed6
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)