From acf886651e88f57b98f330146e45d82bbaaad00e Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Mon, 20 Jan 2025 19:16:55 -0800 Subject: [PATCH] Simplify genInitMem.sh using qemuBoot.sh --- linux/genInitMem.sh | 33 +++++++++------------------------ linux/qemuBoot.sh | 8 +++++++- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/linux/genInitMem.sh b/linux/genInitMem.sh index b77445add..65e5c9825 100755 --- a/linux/genInitMem.sh +++ b/linux/genInitMem.sh @@ -1,14 +1,12 @@ #!/bin/bash set -e tcpPort=1235 -imageDir=$RISCV/buildroot/output/images tvDir=$RISCV/linux-testvectors rawRamFile="$tvDir/ramGDB.bin" ramFile="$tvDir/ram.bin" rawBootmemFile="$tvDir/bootmemGDB.bin" bootmemFile="$tvDir/bootmem.bin" rawUntrimmedBootmemFile="$tvDir/untrimmedBootmemFileGDB.bin" -DEVICE_TREE=${imageDir}/wally-virt.dtb if ! mkdir -p "$tvDir"; then echo "Error: unable to create linux testvector directory $tvDir!">&2 @@ -26,24 +24,15 @@ if ! test -w "$tvDir"; then fi echo "Launching QEMU in replay mode!" -(qemu-system-riscv64 \ --M virt -m 256M -dtb "$DEVICE_TREE" \ --nographic \ --bios "$imageDir"/fw_jump.bin -kernel "$imageDir"/Image -append "root=/dev/vda ro" -initrd "$imageDir"/rootfs.cpio \ --gdb tcp::$tcpPort -S) \ -& riscv64-unknown-elf-gdb --quiet \ --ex "set pagination off" \ --ex "set logging overwrite on" \ --ex "set logging redirect on" \ --ex "set confirm off" \ --ex "target extended-remote :$tcpPort" \ --ex "maintenance packet Qqemu.PhyMemMode:1" \ --ex "printf \"Creating $rawBootmemFile\n\"" \ --ex "dump binary memory $rawBootmemFile 0x1000 0x1fff" \ --ex "printf \"Creating $rawRamFile\n\"" \ --ex "dump binary memory $rawRamFile 0x80000000 0x8fffffff" \ --ex "kill" \ --ex "q" +./qemuBoot.sh --gdb $tcpPort & +riscv64-unknown-elf-gdb -batch \ + -ex "target remote :$tcpPort" \ + -ex "maintenance packet Qqemu.PhyMemMode:1" \ + -ex "printf \"Creating $rawBootmemFile\n\"" \ + -ex "dump binary memory $rawBootmemFile 0x1000 0x1fff" \ + -ex "printf \"Creating $rawRamFile\n\"" \ + -ex "dump binary memory $rawRamFile 0x80000000 0x8fffffff" \ + -ex "kill" \ echo "Changing Endianness" # Extend files to 8 byte multiple @@ -55,7 +44,3 @@ objcopy --reverse-bytes=8 -F binary "$rawBootmemFile" "$bootmemFile" rm -f "$rawRamFile" "$rawBootmemFile" "$rawUntrimmedBootmemFile" echo "genInitMem.sh completed!" -echo "You may want to restrict write access to $tvDir now and give cad ownership of it." -echo "Run the following:" -echo " sudo chown -R cad:cad $tvDir" -echo " sudo chmod -R go-w $tvDir" diff --git a/linux/qemuBoot.sh b/linux/qemuBoot.sh index b756ad34a..b5f130fc6 100755 --- a/linux/qemuBoot.sh +++ b/linux/qemuBoot.sh @@ -1,10 +1,16 @@ #!/bin/bash BUILDROOT="${BUILDROOT:-$RISCV/buildroot}" IMAGES="$BUILDROOT"/output/images + +if [[ "$1" == "--gdb" && -n "$2" ]]; then + GDB_FLAG="-gdb tcp::$2 -S" +fi + qemu-system-riscv64 \ -M virt -m 256M -nographic \ -bios "$IMAGES"/fw_jump.bin \ -kernel "$IMAGES"/Image \ -initrd "$IMAGES"/rootfs.cpio \ -dtb "$IMAGES"/wally-virt.dtb \ - -cpu rva22s64,zicond=true,zfa=true,zfh=true,zcb=true,zbc=true,zkn=true,sstc=true,svadu=true,svnapot=true + -cpu rva22s64,zicond=true,zfa=true,zfh=true,zcb=true,zbc=true,zkn=true,sstc=true,svadu=true,svnapot=true \ + $GDB_FLAG