From: Jacob Lifshay Date: Tue, 12 Dec 2023 18:11:04 +0000 (-0800) Subject: add make_gdb_vm_image.sh script, it doesn't work yet but could be useful X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e3b4611686e93e858f209fc969650b99d5e27bab;p=openpower-isa.git add make_gdb_vm_image.sh script, it doesn't work yet but could be useful see https://bugs.libre-soc.org/show_bug.cgi?id=1228#c15 --- diff --git a/.gitignore b/.gitignore index 6ce67a3b..cce157d9 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ dist /crtl* /formal_test_temp /test-out/ +*.iso diff --git a/make_gdb_vm_image.sh b/make_gdb_vm_image.sh new file mode 100755 index 00000000..7df88420 --- /dev/null +++ b/make_gdb_vm_image.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# doesn't actually fully work yet... +set -e +if [[ "$(id -u)" != 0 ]]; then + exec sudo bash "$0" "$@" +fi +build_dir="$(mktemp -d)" +iso_dir="$build_dir/iso" +mounts=() +function at_exit() { + set +e + for i in "${mounts[@]}"; do + umount "$i" + done + rm -rf --one-file-system "$build_dir" +} +trap at_exit EXIT +mmdebstrap -v --variant=apt --include=grub-ieee1275-bin,xorriso,gdbserver,linux-image-powerpc64le --architecture=ppc64el bullseye "$build_dir" +echo "gdb-vm-build" > "$build_dir"/etc/debian_chroot +if [[ "$(arch)" != "ppc64le" ]]; then + cp /usr/bin/qemu-ppc64le-static "$build_dir"/usr/bin/qemu-ppc64le-static +fi +cp /etc/resolv.conf "$build_dir"/etc/resolv.conf +mount --bind /dev "$build_dir"/dev +mounts=("$build_dir"/dev "${mounts[@]}") +mount --bind /dev/pts "$build_dir"/dev/pts +mounts=("$build_dir"/dev/pts "${mounts[@]}") +mount --bind /proc "$build_dir"/proc +mounts=("$build_dir"/proc "${mounts[@]}") +mount --bind /sys "$build_dir"/sys +mounts=("$build_dir"/sys "${mounts[@]}") +mkdir "$iso_dir" +cat > "$build_dir"/etc/initramfs-tools/hooks/gdbserver <<'EOF' +#!/bin/sh + +PREREQ="" +prereqs() +{ + echo "$PREREQ" +} + +case $1 in +prereqs) + prereqs + exit 0 + ;; +esac + +. /usr/share/initramfs-tools/hook-functions + +echo copying gdbserver... +copy_exec /usr/bin/gdbserver /usr/bin/gdbserver + +exit 0 +EOF +chmod +x "$build_dir"/etc/initramfs-tools/hooks/gdbserver +cat > "$build_dir"/etc/initramfs-tools/scripts/init-top/gdbserver <<'EOF' +#!/bin/sh +PREREQ="" + +prereqs() +{ + echo "$PREREQ" +} + +case $1 in +# get pre-requisites +prereqs) + prereqs + exit 0 + ;; +esac + +# TODO: call gdbserver on serial port instead...then poweroff +sh <>/dev/tty1 >&0 2>&0 + +exit 0 +EOF +chmod +x "$build_dir"/etc/initramfs-tools/scripts/init-top/gdbserver +chroot "$build_dir" update-initramfs -k all -u +cp "$build_dir"/boot/vmlinu?-* "$iso_dir"/vmlinux +cp "$build_dir"/boot/initrd.img-* "$iso_dir"/initrd.gz +mkdir -p "$iso_dir"/boot/grub +cat > "$iso_dir"/boot/grub/grub.cfg <<'EOF' +set timeout=0 +set default=0 + +menuentry "boot" { + insmod gzio + # not a real UUID, just makes initrd work... + set root=(ieee1275/cdrom,apple3) + linux /vmlinux root=UUID=2942fbed-5e30-4bbd-b1ba-5ac1875bc41c debug + initrd /initrd.gz +} +EOF +chroot "$build_dir" grub-mkrescue -o gdb-vm.iso /iso +install -m 644 "$build_dir"/gdb-vm.iso gdb-vm.iso +