From a9cd457536d8e76aff7f0ddbc494d45dfcaf49d5 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Wed, 24 Jul 2024 00:22:28 -0700 Subject: [PATCH] Update buildroot makefile to test for write access to $RISCV and remove separate sudo/no_sudo versions (just run the makefile as sudo if needed) --- linux/Makefile | 28 ++++++++--------------- linux/testvector-generation/genInitMem.sh | 8 +------ 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index 89f31a3da..a1c8999f1 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -1,4 +1,3 @@ -#BUILDROOT := ${RISCV}/buildroot-test BUILDROOT := buildroot IMAGES := ${BUILDROOT}/output/images WALLY := $(shell dirname $(shell pwd)) @@ -27,36 +26,29 @@ BINARIES := fw_jump.elf vmlinux busybox OBJDUMPS := $(foreach name, $(BINARIES), $(basename $(name) .elf)) OBJDUMPS := $(foreach name, $(OBJDUMPS), $(DIS)/$(name).objdump) -.PHONY: all generate disassemble install clean cleanDTB cleanDriver test +.PHONY: all generate disassemble install clean cleanDTB cleanDriver check_write_permissions -all: clean download Image disassemble install dumptvs +all: check_write_permissions clean download Image disassemble install dumptvs -all_nosudo: clean download Image disassemble install_nosudo dumptvs_nosudo +check_write_permissions: + @mkdir -p $(RISCV)/.test || \ + (echo "ERROR: Cannot write to '$(RISCV)'." \ + "Make sure you have write permissions (you may need to run as sudo).'" \ + && exit 1) + @rm -r $(RISCV)/.test Image: bash -c "unset LD_LIBRARY_PATH; make -C $(BUILDROOT) --jobs ${shell nproc --ignore 1};" $(MAKE) generate -install: - sudo rm -rf $(RISCV)/$(BUILDROOT) - sudo mv $(BUILDROOT) $(RISCV)/$(BUILDROOT) - -install_nosudo: +install: check_write_permissions rm -rf $(RISCV)/$(BUILDROOT) mv $(BUILDROOT) $(RISCV)/$(BUILDROOT) -dumptvs: - sudo mkdir -p $(RISCV)/linux-testvectors - cd testvector-generation; sudo ./genInitMem.sh - -dumptvs_nosudo: +dumptvs: check_write_permissions mkdir -p $(RISCV)/linux-testvectors cd testvector-generation; ./genInitMem.sh -# Temp rule for debugging -test: - echo $(shell find $(BUILDROOT)/output/build -maxdepth 2 -type d -regex ".*/linux-[0-9]+\.[0-9]+\.[0-9]+$$") - generate: $(DTB) $(IMAGES) $(IMAGES)/%.dtb: ./devicetree/%.dts diff --git a/linux/testvector-generation/genInitMem.sh b/linux/testvector-generation/genInitMem.sh index c4c3c7291..61f570482 100755 --- a/linux/testvector-generation/genInitMem.sh +++ b/linux/testvector-generation/genInitMem.sh @@ -7,7 +7,6 @@ ramFile="$tvDir/ram.bin" rawBootmemFile="$tvDir/bootmemGDB.bin" bootmemFile="$tvDir/bootmem.bin" rawUntrimmedBootmemFile="$tvDir/untrimmedBootmemFileGDB.bin" -untrimmedBootmemFile="$tvDir/untrimmedBootmemFile.bin" DEVICE_TREE=${imageDir}/wally-virt.dtb if ! mkdir -p "$tvDir"; then @@ -24,6 +23,7 @@ if ! test -w "$tvDir"; then exit 1 fi fi + echo "Launching QEMU in replay mode!" (qemu-system-riscv64 \ -M virt -m 256M -dtb $DEVICE_TREE \ @@ -44,15 +44,10 @@ echo "Launching QEMU in replay mode!" -ex "kill" \ -ex "q" -#-ex "printf \"Warning - please verify that the second half of $rawUntrimmedBootmemFile is all 0s\n\"" \ -#-ex "printf \"Creating $rawUntrimmedBootmemFile\n\"" \ -#-ex "dump binary memory $rawUntrimmedBootmemFile 0x1000 0x2fff" \ - echo "Changing Endianness" make fixBinMem ./fixBinMem "$rawRamFile" "$ramFile" ./fixBinMem "$rawBootmemFile" "$bootmemFile" -#./fixBinMem "$rawUntrimmedBootmemFile" "$untrimmedBootmemFile" # doesn't seem to be used for anything rm -f "$rawRamFile" "$rawBootmemFile" "$rawUntrimmedBootmemFile" echo "genInitMem.sh completed!" @@ -60,4 +55,3 @@ echo "You may want to restrict write access to $tvDir now and give cad ownership echo "Run the following:" echo " sudo chown -R cad:cad $tvDir" echo " sudo chmod -R go-w $tvDir" -