From 80f3b940578b30fa5ecef7de513232c753f54841 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 9 Nov 2024 17:01:34 -0800 Subject: [PATCH 1/3] Replace fixBinMem.c with objcopy --- linux/Makefile | 2 +- .../{testvector-generation => }/genInitMem.sh | 5 ++- linux/testvector-generation/Makefile | 13 -------- linux/testvector-generation/fixBinMem.c | 33 ------------------- 4 files changed, 3 insertions(+), 50 deletions(-) rename linux/{testvector-generation => }/genInitMem.sh (93%) delete mode 100644 linux/testvector-generation/Makefile delete mode 100644 linux/testvector-generation/fixBinMem.c diff --git a/linux/Makefile b/linux/Makefile index b098b0a8b..85ef24ccb 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -60,7 +60,7 @@ install: check_write_permissions check_environment dumptvs: check_write_permissions check_environment $(SUDO) mkdir -p $(RISCV)/linux-testvectors - cd testvector-generation; ./genInitMem.sh + ./genInitMem.sh @echo "Testvectors successfully generated." generate: $(DTB) $(IMAGES) diff --git a/linux/testvector-generation/genInitMem.sh b/linux/genInitMem.sh similarity index 93% rename from linux/testvector-generation/genInitMem.sh rename to linux/genInitMem.sh index 1274a4240..664f7fcfe 100755 --- a/linux/testvector-generation/genInitMem.sh +++ b/linux/genInitMem.sh @@ -46,9 +46,8 @@ echo "Launching QEMU in replay mode!" -ex "q" echo "Changing Endianness" -make fixBinMem -./fixBinMem "$rawRamFile" "$ramFile" -./fixBinMem "$rawBootmemFile" "$bootmemFile" +objcopy --reverse-bytes=8 -F binary "$rawRamFile" "$ramFile" +objcopy --reverse-bytes=8 -F binary "$rawBootmemFile" "$bootmemFile" rm -f "$rawRamFile" "$rawBootmemFile" "$rawUntrimmedBootmemFile" echo "genInitMem.sh completed!" diff --git a/linux/testvector-generation/Makefile b/linux/testvector-generation/Makefile deleted file mode 100644 index c31aae39d..000000000 --- a/linux/testvector-generation/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -SHELL = /bin/sh - -CFLAG = -Wall -g -CC = gcc - -all: fixBinMem - -fixBinMem: fixBinMem.c - ${CC} ${CFLAGS} fixBinMem.c -o fixBinMem - chmod +x fixBinMem - -clean: - -rm -f fixBinMem diff --git a/linux/testvector-generation/fixBinMem.c b/linux/testvector-generation/fixBinMem.c deleted file mode 100644 index fe071008b..000000000 --- a/linux/testvector-generation/fixBinMem.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -int main(int argc, char *argv[]) { - if (argc < 3){ - fprintf(stderr, "Expected 2 arguments: \n"); - exit(1); - } - char* rawGDBfilePath = argv[1]; - FILE* rawGDBfile; - if ((rawGDBfile = fopen(rawGDBfilePath,"rb"))==NULL) { - fprintf(stderr, "File not found: %s\n",rawGDBfilePath); - exit(1); - } - char* outFilePath = argv[2]; - FILE* outFile = fopen(outFilePath,"w"); - uint64_t qemuWord; - uint64_t verilogWord; - int bytesReturned=0; - do { - bytesReturned=fread(&qemuWord, 8, 1, rawGDBfile); - verilogWord = (((qemuWord>>0 )&0xff)<<56 | - ((qemuWord>>8 )&0xff)<<48 | - ((qemuWord>>16)&0xff)<<40 | - ((qemuWord>>24)&0xff)<<32 | - ((qemuWord>>32)&0xff)<<24 | - ((qemuWord>>40)&0xff)<<16 | - ((qemuWord>>48)&0xff)<<8 | - ((qemuWord>>56)&0xff)<<0); - fwrite(&verilogWord, 8, 1, outFile); - } while(bytesReturned!=0); - return 0; -} From 5bbaf2d95ddcdcc3de160036e369daa1e7613e20 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 9 Nov 2024 17:01:55 -0800 Subject: [PATCH 2/3] Remove bootmem.txt --- linux/bootmem.txt | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 linux/bootmem.txt diff --git a/linux/bootmem.txt b/linux/bootmem.txt deleted file mode 100644 index 7cf7d8453..000000000 --- a/linux/bootmem.txt +++ /dev/null @@ -1,12 +0,0 @@ -00001000: 00000297 auipc t0, 0 # t0 = 0x00001000 -00001004: 02828613 addi a2, t0,0x28 # a2 = 0x00001028 -00001008: f1402573 csrr a0, mhartid # a0 = mhartid -0000100c: 0202b583 ld a1, 32(t0) # a1 = 87000000 - device tree address -00001010: 0182b283 ld t0, 24(t0) # t0 = 80000000 - start of firmware -00001014: 00028067 jr t0 # jump to firmware -00001018: 0000000080000000 # firmware start address -00001020: 000000008fe00000 # flattened device tree load address -00001028: 000000004942534f # a2 points to this 8 dword data structure -00001030: 0000000000000002 -00001038: 0000000080200000 -00001040: 0000000000000001 From 43d0510bc78285ade163003f19401011c30f05ac Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 9 Nov 2024 17:32:43 -0800 Subject: [PATCH 3/3] Pad linux raw testvectors before reversing --- linux/genInitMem.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/linux/genInitMem.sh b/linux/genInitMem.sh index 664f7fcfe..a85837f80 100755 --- a/linux/genInitMem.sh +++ b/linux/genInitMem.sh @@ -46,6 +46,10 @@ echo "Launching QEMU in replay mode!" -ex "q" echo "Changing Endianness" +# Extend files to 8 byte multiple +truncate -s %8 "$rawRamFile" +truncate -s %8 "$rawBootmemFile" +# Reverse bytes objcopy --reverse-bytes=8 -F binary "$rawRamFile" "$ramFile" objcopy --reverse-bytes=8 -F binary "$rawBootmemFile" "$bootmemFile" rm -f "$rawRamFile" "$rawBootmemFile" "$rawUntrimmedBootmemFile"