// File: goodix[P]gdix_hid_firmware_update/gtx9/gtx9_update.cpp
// Function: GTx9Update::Run(void*)
int GTx9Update::Run(void *para)
{
	int ret;

	if (!m_Initialized) {
		gdix_err("Can't Process Update Before Initialized.\n");
		return -EINVAL;
	}
	// get all parameter
	pGTUpdatePara parameter = (pGTUpdatePara)para;

	if (!parameter->force) {
		ret = check_update();
		if (ret < 0) {
			gdix_info("Upgrades are not allowed\n");
			return ret;
		} else if (ret == 0) {
			gdix_info("Skip upgrade\n");
			return 0;
		}
		gdix_info("Ready to upgrade\n");
	} else {
		gdix_info("Force to upgrade\n");
	}

	ret = prepareUpdate();
	if (ret < 0) {
		gdix_err("Failed prepare update\n");
		return ret;
	}

	ret = fw_update(parameter->firmwareFlag);
	if (ret < 0) {
		gdix_err("Failed update\n");
		return ret;
	}

	gdix_info("Success update\n");

	return 0;
}

// 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)
testb $0x1, 0x18(%rax)
jne 0x1776e
jmp 0x17730
leaq 0xeb62(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x17760
movq 0xe895(%rip), %rax      # 0x25fd8
movq (%rax), %rdi
leaq 0x5922(%rip), %rsi      # 0x1d06f
leaq 0x5956(%rip), %rdx      # 0x1d0aa
movl $0x2b, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x17762
movl $0xffffffea, -0x4(%rbp) # imm = 0xFFFFFFEA
jmp 0x1796b
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
testb $0x1, (%rax)
jne 0x17853
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x177d5
jmp 0x17798
leaq 0xeafa(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x177c8
movq 0xe80d(%rip), %rax      # 0x25fb8
movq (%rax), %rdi
leaq 0x885c(%rip), %rsi      # 0x20011
leaq 0x58ee(%rip), %rdx      # 0x1d0aa
movl $0x34, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x177ca
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1796b
cmpl $0x0, -0x1c(%rbp)
jne 0x1781b
jmp 0x177dd
leaq 0xeab5(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x1780d
movq 0xe7c8(%rip), %rax      # 0x25fb8
movq (%rax), %rdi
leaq 0x8842(%rip), %rsi      # 0x2003c
leaq 0x58a9(%rip), %rdx      # 0x1d0aa
movl $0x37, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x1780f
movl $0x0, -0x4(%rbp)
jmp 0x1796b
jmp 0x1781d
jmp 0x1781f
leaq 0xea73(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x1784f
movq 0xe786(%rip), %rax      # 0x25fb8
movq (%rax), %rdi
leaq 0x881f(%rip), %rsi      # 0x2005b
leaq 0x5867(%rip), %rdx      # 0x1d0aa
movl $0x3a, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x17851
jmp 0x17889
jmp 0x17855
leaq 0xea3d(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x17885
movq 0xe750(%rip), %rax      # 0x25fb8
movq (%rax), %rdi
leaq 0x880c(%rip), %rsi      # 0x2007e
leaq 0x5831(%rip), %rdx      # 0x1d0aa
movl $0x3c, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x17887
jmp 0x17889
movq -0x30(%rbp), %rdi
callq 0x17980
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x178da
jmp 0x1789d
leaq 0xe9f5(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x178cd
movq 0xe728(%rip), %rax      # 0x25fd8
movq (%rax), %rdi
leaq 0x87e7(%rip), %rsi      # 0x200a1
leaq 0x57e9(%rip), %rdx      # 0x1d0aa
movl $0x41, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x178cf
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1796b
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)
jge 0x17930
jmp 0x178f6
leaq 0xe99c(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x17926
movq 0xe6cf(%rip), %rax      # 0x25fd8
movq (%rax), %rdi
leaq 0x87b6(%rip), %rsi      # 0x200c9
leaq 0x5790(%rip), %rdx      # 0x1d0aa
movl $0x47, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x17928
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1796b
jmp 0x17932
leaq 0xe960(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x17962
movq 0xe673(%rip), %rax      # 0x25fb8
movq (%rax), %rdi
leaq 0x879a(%rip), %rsi      # 0x200e9
leaq 0x5754(%rip), %rdx      # 0x1d0aa
movl $0x4b, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x17964
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)