Using file openwrt_release into get_baseinfo

pull/3/head
remittor 3 years ago
parent 598cb73130
commit ae0b93a002

@ -184,7 +184,9 @@ class Gateway():
self.stok = None self.stok = None
if not self.nonce_key or not self.mac_address: if not self.nonce_key or not self.mac_address:
die("Xiaomi Mi Wi-Fi device is wrong model or not the stock firmware in it.") die("Xiaomi Mi Wi-Fi device is wrong model or not the stock firmware in it.")
nonce = "0_" + self.mac_address + "_" + str(int(time.time())) + "_" + str(random.randint(1000, 10000)) dtype = 0 # 0: Web, 1: Android, 2: iOS, 3: Mac, 4: PC
device = self.mac_address
nonce = "{}_{}_{}_{}".format(dtype, device, int(time.time()), random.randint(1000, 10000))
web_pass = self.webpassword web_pass = self.webpassword
if not web_pass: if not web_pass:
web_pass = input("Enter device WEB password: ") web_pass = input("Enter device WEB password: ")

@ -98,12 +98,14 @@ class DevInfo():
self.dmesg = None self.dmesg = None
fn_local = 'outdir/dmesg.log' fn_local = 'outdir/dmesg.log'
fn_remote = '/tmp/dmesg.log' fn_remote = '/tmp/dmesg.log'
if os.path.exists(fn_local):
os.remove(fn_local)
try: try:
self.gw.run_cmd("dmesg > " + fn_remote) self.gw.run_cmd("dmesg > " + fn_remote)
self.gw.download(fn_remote, fn_local) self.gw.download(fn_remote, fn_local)
self.gw.run_cmd("rm -f " + fn_remote) self.gw.run_cmd("rm -f " + fn_remote)
except Exception: except Exception:
return self.kcmdline return None
if not os.path.exists(fn_local): if not os.path.exists(fn_local):
return None return None
if os.path.getsize(fn_local) <= 1: if os.path.getsize(fn_local) <= 1:
@ -227,65 +229,76 @@ class DevInfo():
verbose = verbose if verbose is not None else self.verbose verbose = verbose if verbose is not None else self.verbose
self.info = BaseInfo() self.info = BaseInfo()
ret = self.info ret = self.info
if not self.dmesg:
return ret
if verbose: if verbose:
print('Base info:') print('Base info:')
# Linux version 3.10.14 (jenkins@cefa8cf504dc) (gcc version 4.8.5 (crosstool-NG crosstool-ng-1.22.0) ) if self.dmesg:
x = re.search(r'Linux version (.*?) ', self.dmesg) # Linux version 3.10.14 (jenkins@cefa8cf504dc) (gcc version 4.8.5 (crosstool-NG crosstool-ng-1.22.0) )
if x: x = re.search(r'Linux version (.*?) ', self.dmesg)
ret.linux_ver = x.group(1).strip() if x:
ret.linux_ver = x.group(1).strip()
if verbose: if verbose:
print(' Linux version: {}'.format(ret.linux_ver)) print(' Linux version: {}'.format(ret.linux_ver))
# MIPS secondary cache 256kB, 8-way, linesize 32 bytes. fn_local = 'outdir/openwrt_release.txt'
x = re.search(r'MIPS secondary cache (.*?) linesize ', self.dmesg) fn_remote = '/etc/openwrt_release'
if x: if os.path.exists(fn_local):
ret.cpu_arch = 'mips' os.remove(fn_local)
# CPU: ARMv7 Processor [512f04d0] revision 0 (ARMv7), cr=10c5387d try:
# Boot CPU: AArch64 Processor [410fd034] self.gw.download(fn_remote, fn_local, verbose=0)
x = re.search(r'CPU: (.*?) Processor \[([0-9a-f]+)\]', self.dmesg) except Exception:
if x: if verbose:
ret.cpu_arch = x.group(1).strip().lower() print(' File "{}" cannot download!'.format(fn_remote))
if ret.cpu_arch == 'aarch64': return ret
ret.cpu_arch = 'arm64' if not os.path.exists(fn_local):
#if verbose: return ret
# print(' CPU arch: {}'.format(ret.cpu_arch)) if os.path.getsize(fn_local) <= 1:
# start MT7621 PCIe register access return ret
x = re.search(r'start (.*?) PCIe register access', self.dmesg) with open(fn_local, "r", encoding="latin_1") as file:
if x: txt = file.read()
ret.cpu_name = x.group(1).strip().lower() x = re.search("DISTRIB_TARGET='(.*?)'", txt)
x = self.dmesg.find("acpuclk-ipq806x acpuclk-ipq806x: ") if not x:
if x > 0: return ret
ret.cpu_name = 'ipq806x' if verbose:
x = self.dmesg.find("cpr4_ipq807x_apss_read_fuse_data: apc_corner: speed bin =") print(" DISTRIB_TARGET =", x.group(1))
if x > 0: target = x.group(1).strip().lower()
ret.cpu_name = 'ipq807x' board = target.split(r'/')[0]
ret.cpu_arch = 'arm64' subtarget = target.split(r'/')[1]
x = self.dmesg.find('mt7622_pa_lna_set():') cpu_arch = None
if x > 0: cpu_name = ''
ret.cpu_name = 'mt7622' if board == 'ramips':
ret.cpu_arch = 'arm64' cpu_arch = 'mips'
# Machine model: MediaTek MT7986a RFB cpu_name = subtarget
x = re.search(r'] Machine model: (.*?)\n', self.dmesg) if board == 'mediatek':
if x: cpu_arch = 'arm64'
vendor_cpu = x.group(1).strip().lower() cpu_name = subtarget[:6]
if vendor_cpu.startswith("mediatek"): if board.startswith('ar71'): # Atheros
cpu = vendor_cpu.split(" ")[1] cpu_arch = 'mips'
if not ret.cpu_name: cpu_name = board[:6]
ret.cpu_name = cpu if board == 'ipq' and subtarget.startswith('ipq'):
if cpu and len(cpu) >= 4: cpu_name = subtarget[:7]
cpu = cpu[:6] elif board.startswith('ipq') and len(board) >= 7:
if cpu in 'mt7622 mt7981 mt7986 mt7988': cpu_name = board[:7]
ret.cpu_arch = 'arm64' if cpu_name.startswith('ipq401'):
cpu_arch = 'armv7'
if cpu_name.startswith('ipq806'):
cpu_arch = 'armv7'
if cpu_name.startswith('ipq807'):
cpu_arch = 'arm64'
if cpu_name.startswith('ipq50'):
cpu_arch = 'arm64'
if cpu_name.startswith('ipq60'):
cpu_arch = 'arm64'
ret.cpu_arch = cpu_arch
ret.cpu_name = cpu_name if cpu_name is not None else None
if verbose: if verbose:
print(' CPU arch: {}'.format(ret.cpu_arch)) print(' CPU arch: {}'.format(ret.cpu_arch))
print(' CPU name: {}'.format(ret.cpu_name)) print(' CPU name: {}'.format(ret.cpu_name))
# spi-mt7621 1e000b00.spi: sys_freq: 50000000 if board == 'ramips' and self.dmesg:
x = re.search(r'spi-mt(.*?) (.*?).spi: sys_freq: ', self.dmesg) # spi-mt7621 1e000b00.spi: sys_freq: 50000000
if x: x = re.search(r'spi-mt(.*?) (.*?).spi: sys_freq: ', self.dmesg)
ret.spi_rom = True if x:
if verbose: ret.spi_rom = True
print(' SPI rom: {}'.format(ret.spi_rom)) if verbose:
print(' SPI rom: {}'.format(ret.spi_rom))
if verbose: if verbose:
print(" ") print(" ")
return ret return ret

Loading…
Cancel
Save