From: Lukas Hruska <lhruska@suse.cz>
To: linux-debuggers@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Michal Koutny <mkoutny@suse.com>,
YOSHIDA Masanori <masanori.yoshida.tv@hitachi.com>
Subject: [RFC PATCH 4/4 v1] livedump: Add tools to make livedump creation easier
Date: Fri, 10 Nov 2023 16:00:57 +0100 [thread overview]
Message-ID: <20231110150057.15717-5-lhruska@suse.cz> (raw)
In-Reply-To: <20231110150057.15717-1-lhruska@suse.cz>
Add tool wrapping all handling of livedump's sysfs. Add tool extracting the
dump from block device first checking the correct size of dumped memory. This
way the extraction can be done even after resizing the physical memory.
Signed-off-by: Lukas Hruska <lhruska@suse.cz>
---
tools/livedump/livedump.sh | 44 ++++++++++++++++++++++++++++++
| 19 +++++++++++++
2 files changed, 63 insertions(+)
create mode 100755 tools/livedump/livedump.sh
create mode 100755 tools/livedump/livedump_extract.sh
diff --git a/tools/livedump/livedump.sh b/tools/livedump/livedump.sh
new file mode 100755
index 000000000000..2cc67bbbc380
--- /dev/null
+++ b/tools/livedump/livedump.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# This is a wrapper for livedump's sysfs to make a complete memdump.
+# Usage: livedump block_device
+#
+# Author: Lukas Hruska <lhruska@suse.cz>
+#
+# This file has been put into the public domain.
+# You can do whatever you want with this file.
+#
+
+if [ $# -ne 1 ]; then
+ >&2 echo "Usage: livedump block_device"
+ >&2 echo "Not enough arugments"
+ exit 1
+fi
+
+DEV=$1
+
+write_and_check() {
+ NAME=$1
+ VAL=$2
+ PATH=$3
+
+ echo -n "$NAME: "
+ echo $VAL > $PATH
+ if [ $? -ne 0 ]; then
+ exit 1
+ fi
+ echo "OK"
+}
+
+CUR_STATE=`head -n 1 /sys/kernel/livedump/state`
+if [ $CUR_STATE -ne 0 ] && [ $CUR_STATE -ne 5 ]; then
+ write_and_check "reset" 5 /sys/kernel/livedump/state
+fi
+
+write_and_check "device" $DEV /sys/kernel/livedump/output
+write_and_check "init" 1 /sys/kernel/livedump/state
+write_and_check "start" 2 /sys/kernel/livedump/state
+write_and_check "sweep" 3 /sys/kernel/livedump/state
+write_and_check "finish" 4 /sys/kernel/livedump/state
+write_and_check "uninit" 5 /sys/kernel/livedump/state
--git a/tools/livedump/livedump_extract.sh b/tools/livedump/livedump_extract.sh
new file mode 100755
index 000000000000..c1dc69da7559
--- /dev/null
+++ b/tools/livedump/livedump_extract.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# This script extracts the ELF formatted livedump from block device with correct size.
+# Usage: livedump_extract block_device output_file
+#
+# Author: Lukas Hruska <lhruska@suse.cz>
+#
+# This file has been put into the public domain.
+# You can do whatever you want with this file.
+#
+device=$1
+output=$2
+
+head -c 4096 $device > /tmp/livedump_hdr
+size=$(readelf -l /tmp/livedump_hdr | tail -2 | tr '\n' ' ' | tr -s ' ' \
+ | cut -d ' ' -f 5,6 | xargs printf "%d + %d" | xargs expr)
+size=$(expr $size / 4096)
+dd if=$device of=$output count=$size bs=4096 status=progress
--
2.39.2
prev parent reply other threads:[~2023-11-10 15:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-10 15:00 [RFC PATCH 0/4 v1] LPC materials: livedump Lukas Hruska
2023-11-10 15:00 ` [RFC PATCH 1/4 v1] crash/vmcore: VMCOREINFO creation from non-kdump kernel Lukas Hruska
2023-11-10 15:00 ` [RFC PATCH 2/4 v1] livedump: Add write protection management Lukas Hruska
2023-11-10 15:00 ` [RFC PATCH 3/4 v1] livedump: Add memory dumping functionality Lukas Hruska
2023-11-10 15:00 ` Lukas Hruska [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231110150057.15717-5-lhruska@suse.cz \
--to=lhruska@suse.cz \
--cc=linux-debuggers@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masanori.yoshida.tv@hitachi.com \
--cc=mkoutny@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox