replace common qcom sources with samsung ones
This commit is contained in:
138
qcom/opensource/tools/minidump/generate_appself.py
Normal file
138
qcom/opensource/tools/minidump/generate_appself.py
Normal file
@@ -0,0 +1,138 @@
|
||||
# Copyright (c) 2020-2021 The Linux Foundation. All rights reserved.
|
||||
# Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2 and
|
||||
# only version 2 as published by the Free Software Foundation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
import sys
|
||||
import os
|
||||
import string
|
||||
import struct
|
||||
|
||||
outputfile = "ap_minidump.elf"
|
||||
|
||||
|
||||
def add_file(fo, path, delete):
|
||||
try:
|
||||
fi = open_file(path, "rb")
|
||||
except:
|
||||
print("Not able to open file %s" % (path))
|
||||
return -1
|
||||
while True:
|
||||
buf = fi.read(4096)
|
||||
if len(buf) == 0:
|
||||
break
|
||||
fo.write(buf)
|
||||
fi.close()
|
||||
if delete:
|
||||
os.unlink(os.path.join(out_folder, path))
|
||||
return 0
|
||||
|
||||
|
||||
def open_file(name, op):
|
||||
path = os.path.join(out_folder, name)
|
||||
out_file = open(path, op)
|
||||
return out_file
|
||||
|
||||
|
||||
def get_strings(buf, length):
|
||||
offset = 0
|
||||
string = ""
|
||||
nlist = []
|
||||
begin = False
|
||||
str_tbl = ""
|
||||
while offset < length:
|
||||
str_tbl = ""
|
||||
if not begin:
|
||||
(ch,) = struct.unpack_from("<B", buf, offset)
|
||||
str_tbl += chr(ch)
|
||||
(ch,) = struct.unpack_from("<B", buf, offset+1)
|
||||
str_tbl += chr(ch)
|
||||
(ch,) = struct.unpack_from("<B", buf, offset+2)
|
||||
str_tbl += chr(ch)
|
||||
(ch,) = struct.unpack_from("<B", buf, offset+3)
|
||||
str_tbl += chr(ch)
|
||||
(ch,) = struct.unpack_from("<B", buf, offset+4)
|
||||
str_tbl += chr(ch)
|
||||
(ch,) = struct.unpack_from("<B", buf, offset+5)
|
||||
str_tbl += chr(ch)
|
||||
(ch,) = struct.unpack_from("<B", buf, offset+6)
|
||||
str_tbl += chr(ch)
|
||||
if str_tbl == "STR_TBL":
|
||||
begin = True
|
||||
offset += 6
|
||||
else:
|
||||
offset += 1
|
||||
continue
|
||||
(ch,) = struct.unpack_from("<B", buf, offset)
|
||||
offset += 1
|
||||
if (ch >= 0x30 and ch < 0x80) or ch==0x2e:
|
||||
string += chr(ch)
|
||||
elif (string != "" and len(string) >= 3 and
|
||||
string != 'linux_banner' and string != 'minidump_table'):
|
||||
nlist.append(string)
|
||||
string = ""
|
||||
else:
|
||||
string = ""
|
||||
if ch == 0:
|
||||
(ch1,) = struct.unpack_from("<B", buf, offset+1)
|
||||
if ch1 == 0:
|
||||
(ch2,) = struct.unpack_from("<B", buf, offset+2)
|
||||
if ch2 == 0:
|
||||
return nlist
|
||||
return nlist
|
||||
|
||||
|
||||
def generate_elf():
|
||||
delete = False
|
||||
elfhd = os.path.join(out_folder, "md_KELF_HEADER.BIN")
|
||||
elfhd_new = os.path.join(out_folder, "md_KELF_HDR.BIN")
|
||||
fo = open_file(outputfile, "wb")
|
||||
if os.path.exists(elfhd):
|
||||
fi = open_file("md_KELF_HEADER.BIN", "rb")
|
||||
hsize = os.path.getsize(elfhd)
|
||||
elif os.path.exists(elfhd_new):
|
||||
fi = open_file("md_KELF_HDR.BIN", "rb")
|
||||
hsize = os.path.getsize(elfhd_new)
|
||||
else:
|
||||
print("ELF header binary is missing")
|
||||
sys.exit(2)
|
||||
print("ELF header size %d" % hsize)
|
||||
buf = fi.read(hsize)
|
||||
fo.write(buf)
|
||||
nlist = get_strings(buf, len(buf))
|
||||
for names in nlist:
|
||||
filepath = "md_" + names + ".BIN"
|
||||
# print ("%s size %x\n" % (filepath, os.path.getsize(filepath)))
|
||||
ret = add_file(fo, filepath, delete)
|
||||
if ret == -1:
|
||||
print("Exting!!")
|
||||
fo.close()
|
||||
fi.close()
|
||||
os.unlink(os.path.join(out_folder, outputfile))
|
||||
return
|
||||
fi.close()
|
||||
fo.close()
|
||||
|
||||
|
||||
def help():
|
||||
print("\nThis script generates ap_minidump.elf from QPST dump for LDRP\n")
|
||||
print("\nProvide QPST minidump location\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = sys.argv
|
||||
if len(args) > 1:
|
||||
out_folder = args[1]
|
||||
else:
|
||||
help()
|
||||
sys.exit(2)
|
||||
|
||||
print("using outfodler %s" % out_folder)
|
||||
generate_elf()
|
||||
176
qcom/opensource/tools/minidump/minidump.py
Executable file
176
qcom/opensource/tools/minidump/minidump.py
Executable file
@@ -0,0 +1,176 @@
|
||||
# Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2 and
|
||||
# only version 2 as published by the Free Software Foundation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
import sys
|
||||
import os
|
||||
import getopt
|
||||
import re
|
||||
import string
|
||||
import struct
|
||||
|
||||
|
||||
class minidump():
|
||||
|
||||
out_folder = '.'
|
||||
out_file = None
|
||||
|
||||
def print_output(self, string):
|
||||
self.out_file.write(string + "\n")
|
||||
|
||||
def open_file(self, name, op):
|
||||
path = os.path.join(self.out_folder, name)
|
||||
self.out_file = open(path, op)
|
||||
return self.out_file
|
||||
|
||||
def split_rawdump(self, rawdump, option='file'):
|
||||
|
||||
head = "<8sIIQ8sIQQI";
|
||||
head_size = struct.calcsize(head)
|
||||
|
||||
section_head = "<IIIQQQQ20s";
|
||||
section_head_size = struct.calcsize(section_head)
|
||||
print("headsize:%d %d" % (head_size, section_head_size))
|
||||
|
||||
filename = os.path.join("", rawdump)
|
||||
if not os.path.exists(filename):
|
||||
print ("rawdump not exist")
|
||||
return False
|
||||
f = open(filename, "rb")
|
||||
head_buf = f.read(head_size)
|
||||
(sig, version, valid, data, context, reset_trigger, dump_size, total_size, sections_count) = struct.unpack_from(head, head_buf, 0)
|
||||
if sig != b'Raw_Dmp!':
|
||||
print ("rawdump signal is not Raw_Dmp!")
|
||||
return False
|
||||
if valid != 1:
|
||||
if valid == 2:
|
||||
print ("Ramdump not complete: no space was left on device during the dump operation.")
|
||||
print ("This usually happens when a full dump is set to be written to a rawdump partion.")
|
||||
print ("Please check if the value of /sys/kernel/dload/dload_mode is set to 'mini'.")
|
||||
else:
|
||||
print ("Valid tag not set!")
|
||||
return False
|
||||
count = 0
|
||||
section_list = []
|
||||
file_list ={}
|
||||
|
||||
while count < sections_count:
|
||||
section_buf = f.read(section_head_size)
|
||||
section_list.append(section_buf)
|
||||
count += 1
|
||||
|
||||
if option == 'list':
|
||||
print ("File list in rawdump:")
|
||||
print("name, section_offset, paddr, section_size, section_type, valid, version")
|
||||
elif option == 'split':
|
||||
print("Split rawdump %s to seperate file to %s ..." % (rawdump, self.out_folder))
|
||||
|
||||
print("sig:\t%s\nversion:\t%d\nvalid:\t%d\ndata:\t0x%lx\ncontext:\t%s\nreset_trigger:\t%x\ndump_size:\t0x%lx\nTotal Size:\t0x%lx\nSection Count:\t%d\n"
|
||||
|
||||
% (sig, version, valid, data, context, reset_trigger, dump_size, total_size, sections_count))
|
||||
for i, one_section in enumerate(section_list):
|
||||
valid, version, section_type, section_offset, section_size, paddr, info, name = struct.unpack_from(section_head, one_section, 0)
|
||||
name = name.decode().strip('\0')
|
||||
file_list[name] = {}
|
||||
file_list[name]['size'] = section_size
|
||||
file_list[name]['paddr'] = paddr
|
||||
if name == 'load.cmm':
|
||||
f.seek(section_offset)
|
||||
cmmbuf = f.read(section_size)
|
||||
|
||||
if option == 'list':
|
||||
print("%s\t0x%x\t0x%x\t0x%x\t%d %d %d " % (name, section_offset, paddr, section_size, section_type, valid, version ))
|
||||
continue
|
||||
|
||||
if option == 'split' or name.startswith('md_K'):
|
||||
print ("Writing %s @0x%x len:0x%x ..." % (name, section_offset, section_size))
|
||||
fout = self.open_file(name, "wb")
|
||||
f.seek(section_offset)
|
||||
allread = 0
|
||||
block_size = 0x100000 * 10
|
||||
left = section_size
|
||||
size = block_size if left > block_size else left
|
||||
while left > 0:
|
||||
buf = f.read(size)
|
||||
fout.write(buf)
|
||||
allread += size
|
||||
left -= size
|
||||
if allread % (block_size * 20) == 0:
|
||||
print(("%d MB ") % (allread / 1024 / 1024))
|
||||
size = block_size if left > block_size else left
|
||||
fout.close()
|
||||
|
||||
f.close()
|
||||
|
||||
# filename = os.path.join(out_folder, "load.cmm")
|
||||
# with open(filename) as f:
|
||||
for line in cmmbuf.decode().split('\n'):
|
||||
m = re.search("d.load.binary\s+(\S+)\s+([0-9a-fA-FxX]+)", line)
|
||||
if m:
|
||||
filename = m.group(1)
|
||||
base = int(m.group(2), 16)
|
||||
file_list[filename]['base'] = base
|
||||
|
||||
if option != 'list':
|
||||
f = self.open_file("dump_info.txt", "w")
|
||||
else:
|
||||
return
|
||||
|
||||
for fname,bs in iter(file_list.items()):
|
||||
if 'base' in bs.keys():
|
||||
base = bs['base']
|
||||
elif 'paddr' in bs.keys():
|
||||
base = bs['paddr']
|
||||
else:
|
||||
base = 0
|
||||
f.write("1 0x{:0>16x}\t{:0>16}\t{:<20}\t{}\r\n".format( base, bs['size'], fname, fname))
|
||||
if option != 'list':
|
||||
f.close()
|
||||
return True
|
||||
|
||||
def __init__(self, out_folder):
|
||||
if not os.path.isdir(out_folder):
|
||||
os.mkdir(out_folder)
|
||||
self.out_folder = out_folder
|
||||
|
||||
def help():
|
||||
print (" minidump tool v1.1")
|
||||
print ("%s [-s|-l|-c|-d|-m|-k] <rawdump> [out_folder] " % sys.argv[0])
|
||||
print (" -l list files in sbldump.bin")
|
||||
print (" -s split to seperate files")
|
||||
|
||||
if __name__=='__main__':
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "ls")
|
||||
except getopt.GetoptError:
|
||||
print ("please check usage")
|
||||
help()
|
||||
sys.exit(-1)
|
||||
|
||||
if len(args) > 0:
|
||||
rawdump = args[0]
|
||||
if len(args) > 1:
|
||||
out_folder = args[1]
|
||||
else:
|
||||
out_folder = "."
|
||||
else:
|
||||
help()
|
||||
sys.exit(-1)
|
||||
|
||||
mdump = minidump(out_folder)
|
||||
option = 'file'
|
||||
for opt, val in opts:
|
||||
if opt=="-l":
|
||||
option = 'list'
|
||||
break;
|
||||
if opt=="-s":
|
||||
option = 'split'
|
||||
break;
|
||||
mdump.split_rawdump(rawdump, option)
|
||||
88
qcom/opensource/tools/minidump/pull_minidump.py
Executable file
88
qcom/opensource/tools/minidump/pull_minidump.py
Executable file
@@ -0,0 +1,88 @@
|
||||
# Copyright (c) 2020, The Linux Foundation. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2 and
|
||||
# only version 2 as published by the Free Software Foundation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
import string
|
||||
import struct
|
||||
import sys
|
||||
|
||||
|
||||
def wait_for_root_access():
|
||||
subprocess.call('adb wait-for-devices', shell=True)
|
||||
subprocess.call('adb root', shell=True)
|
||||
subprocess.call('adb wait-for-devices', shell=True)
|
||||
|
||||
|
||||
def pulldump():
|
||||
|
||||
file_name = out_folder + "sbldump_temp.bin"
|
||||
|
||||
subprocess.call('adb pull /dev/block/bootdevice/by-name/rawdump ' +
|
||||
file_name, shell=True)
|
||||
head = "<8sIIQ8sIQQI"
|
||||
head_size = struct.calcsize(head)
|
||||
|
||||
section_head = "<IIIQQQQ20s"
|
||||
section_head_size = struct.calcsize(section_head)
|
||||
|
||||
if not os.path.exists(file_name):
|
||||
print("Failed to pull Minidump from device")
|
||||
return False
|
||||
|
||||
f = open(file_name, "rb")
|
||||
head_buf = f.read(head_size)
|
||||
(sig, version, valid, data, context, reset_trigger, dump_size, total_size,
|
||||
sections_count) = struct.unpack_from(head, head_buf, 0)
|
||||
|
||||
if sig != "Raw_Dmp!":
|
||||
print("rawdump signal is not Raw_Dmp!")
|
||||
return False
|
||||
if valid != 1:
|
||||
print("Valid tag not set!")
|
||||
return False
|
||||
|
||||
print("Dump size %d" % dump_size)
|
||||
|
||||
f.seek(0)
|
||||
fo = open(out_folder + "sbldump.bin", "wb")
|
||||
tbuf = f.read(dump_size)
|
||||
fo.write(tbuf)
|
||||
|
||||
f.close()
|
||||
fo.close()
|
||||
os.unlink(file_name)
|
||||
|
||||
# clear rawdump partition
|
||||
# FIXME: clear only single dump size? if multi dump support is present
|
||||
subprocess.call('adb shell "dd if=/dev/zero
|
||||
of=/dev/block/bootdevice/by-name/rawdump count=128
|
||||
bs=1048576"', shell=True)
|
||||
|
||||
subprocess.call('adb shell sync', shell=True)
|
||||
|
||||
|
||||
def help():
|
||||
print("\nThis script pulls sbldump.bin Minidump from rawdump partition!!")
|
||||
print("\nProvide QPST minidump location\n")
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = sys.argv
|
||||
if len(args) > 1:
|
||||
out_folder = args[1]
|
||||
else:
|
||||
help()
|
||||
sys.exit(2)
|
||||
|
||||
print("Using outfodler %s" % out_folder)
|
||||
|
||||
wait_for_root_access()
|
||||
pulldump()
|
||||
Reference in New Issue
Block a user