2022-03-01 01:45:09 +00:00
|
|
|
#!/bin/bash
|
2024-07-27 00:20:56 +00:00
|
|
|
set -e
|
2022-03-01 01:45:09 +00:00
|
|
|
tcpPort=1235
|
2023-11-21 19:46:37 +00:00
|
|
|
imageDir=$RISCV/buildroot/output/images
|
|
|
|
tvDir=$RISCV/linux-testvectors
|
2022-03-01 01:45:09 +00:00
|
|
|
rawRamFile="$tvDir/ramGDB.bin"
|
|
|
|
ramFile="$tvDir/ram.bin"
|
|
|
|
rawBootmemFile="$tvDir/bootmemGDB.bin"
|
|
|
|
bootmemFile="$tvDir/bootmem.bin"
|
|
|
|
rawUntrimmedBootmemFile="$tvDir/untrimmedBootmemFileGDB.bin"
|
2023-11-22 04:14:56 +00:00
|
|
|
DEVICE_TREE=${imageDir}/wally-virt.dtb
|
2022-03-01 01:45:09 +00:00
|
|
|
|
2024-07-23 09:00:11 +00:00
|
|
|
if ! mkdir -p "$tvDir"; then
|
|
|
|
echo "Error: unable to create linux testvector directory $tvDir!">&2
|
|
|
|
echo "Please try running as sudo.">&2
|
2023-11-22 13:25:09 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-07-23 09:00:11 +00:00
|
|
|
if ! test -w "$tvDir"; then
|
|
|
|
echo "Using sudo to gain access to $tvDir"
|
|
|
|
if ! sudo chmod -R a+rw "$tvDir"; then
|
|
|
|
echo "Error: insuffcient write privileges for linux testvector directory $tvDir !">&2
|
|
|
|
echo "Please chmod it. For example:">&2
|
|
|
|
echo " sudo chmod -R a+rw $tvDir">&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-11-22 13:25:09 +00:00
|
|
|
fi
|
2024-07-24 07:22:28 +00:00
|
|
|
|
2023-11-22 13:25:09 +00:00
|
|
|
echo "Launching QEMU in replay mode!"
|
|
|
|
(qemu-system-riscv64 \
|
2024-07-26 18:46:09 +00:00
|
|
|
-M virt -m 256M -dtb "$DEVICE_TREE" \
|
2023-11-22 13:25:09 +00:00
|
|
|
-nographic \
|
2024-07-26 18:46:09 +00:00
|
|
|
-bios "$imageDir"/fw_jump.elf -kernel "$imageDir"/Image -append "root=/dev/vda ro" -initrd "$imageDir"/rootfs.cpio \
|
2023-11-22 13:25:09 +00:00
|
|
|
-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"
|
2022-03-01 01:45:09 +00:00
|
|
|
|
2023-11-22 13:25:09 +00:00
|
|
|
echo "Changing Endianness"
|
2024-11-10 01:32:43 +00:00
|
|
|
# Extend files to 8 byte multiple
|
|
|
|
truncate -s %8 "$rawRamFile"
|
|
|
|
truncate -s %8 "$rawBootmemFile"
|
|
|
|
# Reverse bytes
|
2024-11-10 01:01:34 +00:00
|
|
|
objcopy --reverse-bytes=8 -F binary "$rawRamFile" "$ramFile"
|
|
|
|
objcopy --reverse-bytes=8 -F binary "$rawBootmemFile" "$bootmemFile"
|
2023-11-22 13:25:09 +00:00
|
|
|
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"
|