diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/archive-source.sh | 34 | ||||
-rw-r--r-- | scripts/dump-guest-memory.py | 61 | ||||
-rwxr-xr-x | scripts/git-submodule.sh | 38 |
3 files changed, 127 insertions, 6 deletions
diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh index c4e7d98f4d..4e63774f9a 100755 --- a/scripts/archive-source.sh +++ b/scripts/archive-source.sh @@ -18,15 +18,37 @@ if test $# -lt 1; then error "Usage: $0 <output tarball>" fi -tar_file="$1" -list_file="$1.list" -submodules=$(git submodule foreach --recursive --quiet 'echo $name') +tar_file=`realpath "$1"` +list_file="${tar_file}.list" +vroot_dir="${tar_file}.vroot" -if test $? -ne 0; then - error "git submodule command failed" +# We want a predictable list of submodules for builds, that is +# independent of what the developer currently has initialized +# in their checkout, because the build environment is completely +# different to the host OS. +submodules="dtc ui/keycodemapdb" + +trap "status=$?; rm -rf \"$list_file\" \"$vroot_dir\"; exit \$status" 0 1 2 3 15 + +if git diff-index --quiet HEAD -- &>/dev/null +then + HEAD=HEAD +else + HEAD=`git stash create` fi +git clone --shared . "$vroot_dir" +test $? -ne 0 && error "failed to clone into '$vroot_dir'" + +cd "$vroot_dir" +test $? -ne 0 && error "failed to change into '$vroot_dir'" + +git checkout $HEAD +test $? -ne 0 && error "failed to checkout $HEAD revision" -trap "status=$?; rm -f \"$list_file\"; exit \$status" 0 1 2 3 15 +for sm in $submodules; do + git submodule update --init $sm + test $? -ne 0 && error "failed to init submodule $sm" +done if test -n "$submodules"; then { diff --git a/scripts/dump-guest-memory.py b/scripts/dump-guest-memory.py index f7c6635f15..69dd5efadf 100644 --- a/scripts/dump-guest-memory.py +++ b/scripts/dump-guest-memory.py @@ -14,6 +14,7 @@ the COPYING file in the top-level directory. """ import ctypes +import struct UINTPTR_T = gdb.lookup_type("uintptr_t") @@ -45,6 +46,17 @@ EM_S390 = 22 EM_AARCH = 183 EM_X86_64 = 62 +VMCOREINFO_FORMAT_ELF = 1 + +def le16_to_cpu(val): + return struct.unpack("<H", struct.pack("=H", val))[0] + +def le32_to_cpu(val): + return struct.unpack("<I", struct.pack("=I", val))[0] + +def le64_to_cpu(val): + return struct.unpack("<Q", struct.pack("=Q", val))[0] + class ELF(object): """Representation of a ELF file.""" @@ -120,6 +132,25 @@ class ELF(object): self.segments[0].p_filesz += ctypes.sizeof(note) self.segments[0].p_memsz += ctypes.sizeof(note) + + def add_vmcoreinfo_note(self, vmcoreinfo): + """Adds a vmcoreinfo note to the ELF dump.""" + # compute the header size, and copy that many bytes from the note + header = get_arch_note(self.endianness, 0, 0) + ctypes.memmove(ctypes.pointer(header), + vmcoreinfo, ctypes.sizeof(header)) + if header.n_descsz > 1 << 20: + print('warning: invalid vmcoreinfo size') + return + # now get the full note + note = get_arch_note(self.endianness, + header.n_namesz - 1, header.n_descsz) + ctypes.memmove(ctypes.pointer(note), vmcoreinfo, ctypes.sizeof(note)) + + self.notes.append(note) + self.segments[0].p_filesz += ctypes.sizeof(note) + self.segments[0].p_memsz += ctypes.sizeof(note) + def add_segment(self, p_type, p_paddr, p_size): """Adds a segment to the elf.""" @@ -505,6 +536,35 @@ shape and this command should mostly work.""" cur += chunk_size left -= chunk_size + def phys_memory_read(self, addr, size): + qemu_core = gdb.inferiors()[0] + for block in self.guest_phys_blocks: + if block["target_start"] <= addr \ + and addr + size <= block["target_end"]: + haddr = block["host_addr"] + (addr - block["target_start"]) + return qemu_core.read_memory(haddr, size) + return None + + def add_vmcoreinfo(self): + if not gdb.parse_and_eval("vmcoreinfo_find()") \ + or not gdb.parse_and_eval("vmcoreinfo_find()->has_vmcoreinfo"): + return + + fmt = gdb.parse_and_eval("vmcoreinfo_find()->vmcoreinfo.guest_format") + addr = gdb.parse_and_eval("vmcoreinfo_find()->vmcoreinfo.paddr") + size = gdb.parse_and_eval("vmcoreinfo_find()->vmcoreinfo.size") + + fmt = le16_to_cpu(fmt) + addr = le64_to_cpu(addr) + size = le32_to_cpu(size) + + if fmt != VMCOREINFO_FORMAT_ELF: + return + + vmcoreinfo = self.phys_memory_read(addr, size) + if vmcoreinfo: + self.elf.add_vmcoreinfo_note(vmcoreinfo.tobytes()) + def invoke(self, args, from_tty): """Handles command invocation from gdb.""" @@ -518,6 +578,7 @@ shape and this command should mostly work.""" self.elf = ELF(argv[1]) self.guest_phys_blocks = get_guest_phys_blocks() + self.add_vmcoreinfo() with open(argv[0], "wb") as vmcore: self.dump_init(vmcore) diff --git a/scripts/git-submodule.sh b/scripts/git-submodule.sh new file mode 100755 index 0000000000..d8fbc7e47e --- /dev/null +++ b/scripts/git-submodule.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# +# This code is licensed under the GPL version 2 or later. See +# the COPYING file in the top-level directory. + +set -e + +substat=".git-submodule-status" + +command=$1 +shift +modules="$@" + +if test -z "$modules" +then + test -e $substat || touch $substat + exit 0 +fi + +if ! test -e ".git" +then + echo "$0: unexpectedly called with submodules but no git checkout exists" + exit 1 +fi + +case "$command" in +status) + test -f "$substat" || exit 1 + trap "rm -f ${substat}.tmp" EXIT + git submodule status $modules > "${substat}.tmp" + diff "${substat}" "${substat}.tmp" >/dev/null + exit $? + ;; +update) + git submodule update --init $modules 1>/dev/null 2>&1 + git submodule status $modules > "${substat}" + ;; +esac |