From 068a0d10fdc0ecaffbdb75384a2240aeed345e9f Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Wed, 2 Aug 2023 14:28:17 -0500 Subject: [PATCH 01/22] Added a Makefile to the Linux directory to take care of the Buildroot setup and other dependencies. --- linux/Makefile | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 linux/Makefile diff --git a/linux/Makefile b/linux/Makefile new file mode 100644 index 000000000..dfb938f70 --- /dev/null +++ b/linux/Makefile @@ -0,0 +1,23 @@ +RISCV := /opt/riscv +BUILDROOT := ${RISCV}/buildroot +IMAGES := ${BUILDROOT}/output/images +WALLYLINUX := $(shell pwd) + +.PHONY: all clean patch + +all: + +patch: $(BUILDROOT) + @ echo "${WALLYLINUX}" + cp -r $(WALLYLINUX)/buildroot-config-src/wally $ Date: Wed, 2 Aug 2023 14:56:23 -0500 Subject: [PATCH 02/22] Linux makefile now copies the package contents with the correct package source. --- linux/Makefile | 8 ++++++-- linux/buildroot-packages/fpga-axi-sdc/fpga-axi-sdc.mk | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index dfb938f70..bb5086e59 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -2,15 +2,19 @@ RISCV := /opt/riscv BUILDROOT := ${RISCV}/buildroot IMAGES := ${BUILDROOT}/output/images WALLYLINUX := $(shell pwd) +PACKAGE_SOURCE := ${WALLYLINUX}/buildroot-packages/package-source +FPGA_AXI_SDC := ${WALLYLINUX}/buildroot-packages/fpga-axi-sdc .PHONY: all clean patch -all: +all: + sed -i 's|FPGA_AXI_SDC_SITE = __site__|FPGA_AXI_SDC_SITE = $(PACKAGE_SOURCE)|1' $(FPGA_AXI_SDC)/fpga-axi-sdc.mk -patch: $(BUILDROOT) +patch: $(BUILDROOT) @ echo "${WALLYLINUX}" cp -r $(WALLYLINUX)/buildroot-config-src/wally $ Date: Wed, 2 Aug 2023 14:59:20 -0500 Subject: [PATCH 03/22] Removed duplicate line in Makefile. --- linux/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/Makefile b/linux/Makefile index bb5086e59..621653aaa 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -8,7 +8,7 @@ FPGA_AXI_SDC := ${WALLYLINUX}/buildroot-packages/fpga-axi-sdc .PHONY: all clean patch all: - sed -i 's|FPGA_AXI_SDC_SITE = __site__|FPGA_AXI_SDC_SITE = $(PACKAGE_SOURCE)|1' $(FPGA_AXI_SDC)/fpga-axi-sdc.mk + patch: $(BUILDROOT) @ echo "${WALLYLINUX}" From 064e86347647e0b5bc08646a8622bbf21dc1e597 Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Wed, 2 Aug 2023 16:12:26 -0500 Subject: [PATCH 04/22] Buildroot can now be set up with the new Linux Makefile. The driver can now also be loaded from addins/vivado-risc-v and should be removed from the main Wally repo. A sed command customizes the package source location for the new buildroot directory. --- linux/Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index 621653aaa..ccabbeffe 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -1,27 +1,32 @@ RISCV := /opt/riscv BUILDROOT := ${RISCV}/buildroot IMAGES := ${BUILDROOT}/output/images +WALLY := $(shell dirname $(shell pwd)) WALLYLINUX := $(shell pwd) PACKAGE_SOURCE := ${WALLYLINUX}/buildroot-packages/package-source FPGA_AXI_SDC := ${WALLYLINUX}/buildroot-packages/fpga-axi-sdc +DRIVER := ${PACKAGE_SOURCE}/fpga-axi-sdc.c .PHONY: all clean patch -all: - +all: $(IMAGES) -patch: $(BUILDROOT) +patch: $(BUILDROOT) $(DRIVER) @ echo "${WALLYLINUX}" + cp ../addins/vivado-risc-v/patches/fpga-axi-sdc.c $(DRIVER) cp -r $(WALLYLINUX)/buildroot-config-src/wally $ Date: Wed, 2 Aug 2023 16:24:20 -0500 Subject: [PATCH 05/22] Adjusted the new makefile. --- linux/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index ccabbeffe..cfe2d7328 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -12,8 +12,7 @@ DRIVER := ${PACKAGE_SOURCE}/fpga-axi-sdc.c all: $(IMAGES) patch: $(BUILDROOT) $(DRIVER) - @ echo "${WALLYLINUX}" - cp ../addins/vivado-risc-v/patches/fpga-axi-sdc.c $(DRIVER) + @ echo "Patching buildroot directory at: $<" cp -r $(WALLYLINUX)/buildroot-config-src/wally $ Date: Wed, 2 Aug 2023 18:59:42 -0500 Subject: [PATCH 06/22] Updated linux config. Works in QEMU now. --- linux/Makefile | 11 +- .../buildroot-2023.05.1/linux.config | 107 ++++++++++-------- 2 files changed, 66 insertions(+), 52 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index cfe2d7328..1d8107c24 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -7,10 +7,12 @@ PACKAGE_SOURCE := ${WALLYLINUX}/buildroot-packages/package-source FPGA_AXI_SDC := ${WALLYLINUX}/buildroot-packages/fpga-axi-sdc DRIVER := ${PACKAGE_SOURCE}/fpga-axi-sdc.c -.PHONY: all clean patch +.PHONY: generate clean patch -all: $(IMAGES) +generate: $(IMAGES) + +# This directive should be run as: make patch BUILDROOT=path/to/buildroot patch: $(BUILDROOT) $(DRIVER) @ echo "Patching buildroot directory at: $<" cp -r $(WALLYLINUX)/buildroot-config-src/wally $ Date: Wed, 2 Aug 2023 19:26:35 -0500 Subject: [PATCH 07/22] Added device tree generation to Linux directory Makefile. Exits on not finding output/images folder in buildroot directory. --- linux/Makefile | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index 1d8107c24..41d9e00df 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -7,15 +7,29 @@ PACKAGE_SOURCE := ${WALLYLINUX}/buildroot-packages/package-source FPGA_AXI_SDC := ${WALLYLINUX}/buildroot-packages/fpga-axi-sdc DRIVER := ${PACKAGE_SOURCE}/fpga-axi-sdc.c -.PHONY: generate clean patch +DTS ?= $(shell find -type f -regex ".*\.dts" | sort) -generate: $(IMAGES) - +.PHONY: generate cleanDriver patch + +# Generate device tree binaries from device tree source files +# Currently supported fpga device tree binaries are also generated +generate: $(DTS) $(IMAGES) + dtc -I dts -O dtb devicetree/wally-virt.dts > ${IMAGES}/wally-virt.dtb + dtc -I dts -O dtb devicetree/wally-vcu108.dts > ${IMAGES}/wally-vcu108.dtb + dtc -I dts -O dtb devicetree/wally-vcu118.dts > ${IMAGES}/wally-vcu118.dtb + dtc -I dts -O dtb devicetree/wally-vcu118.dts > ${IMAGES}/wally-artya7.dtb + +disassemble: + +# Generating new Buildroot directories -------------------------------- # This directive should be run as: make patch BUILDROOT=path/to/buildroot patch: $(BUILDROOT) $(DRIVER) @ echo "Patching buildroot directory at: $<" + @ echo "Copying wally configuration files and rootfs_overlay to buildroot." cp -r $(WALLYLINUX)/buildroot-config-src/wally $ Date: Fri, 4 Aug 2023 13:56:03 -0500 Subject: [PATCH 08/22] Makefile dynamically generates all device tree files now. --- linux/Makefile | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index 41d9e00df..d846db791 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -7,17 +7,20 @@ PACKAGE_SOURCE := ${WALLYLINUX}/buildroot-packages/package-source FPGA_AXI_SDC := ${WALLYLINUX}/buildroot-packages/fpga-axi-sdc DRIVER := ${PACKAGE_SOURCE}/fpga-axi-sdc.c -DTS ?= $(shell find -type f -regex ".*\.dts" | sort) +# Device tree file +DTS ?= $(shell find -type f -regex ".*\.dts" | sort) +DTB := $(DTS:%.dts=%.dtb) +DTB := $(foreach name, $(DTB), $(IMAGES)/$(shell basename $(name))) -.PHONY: generate cleanDriver patch +.PHONY: generate cleanDriver patch clean -# Generate device tree binaries from device tree source files -# Currently supported fpga device tree binaries are also generated -generate: $(DTS) $(IMAGES) - dtc -I dts -O dtb devicetree/wally-virt.dts > ${IMAGES}/wally-virt.dtb - dtc -I dts -O dtb devicetree/wally-vcu108.dts > ${IMAGES}/wally-vcu108.dtb - dtc -I dts -O dtb devicetree/wally-vcu118.dts > ${IMAGES}/wally-vcu118.dtb - dtc -I dts -O dtb devicetree/wally-vcu118.dts > ${IMAGES}/wally-artya7.dtb +# Generate all device trees +# TODO: Add configuration for only generating device tree for specified +# supported FPGA. +generate: $(DTB) + +$(DTB): $(DTS) + dtc -I dts -O dtb $< > $@ disassemble: @@ -29,12 +32,20 @@ patch: $(BUILDROOT) $(DRIVER) @ echo "Copying wally configuration files and rootfs_overlay to buildroot." cp -r $(WALLYLINUX)/buildroot-config-src/wally $ Date: Fri, 4 Aug 2023 17:28:22 -0500 Subject: [PATCH 09/22] flash-sd.sh fixed. GPT table is now destroyed before re-partioning, thus avoiding backup table collisions. --- linux/sdcard/flash-sd.sh | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/linux/sdcard/flash-sd.sh b/linux/sdcard/flash-sd.sh index d864e2c31..f41fdfe7d 100755 --- a/linux/sdcard/flash-sd.sh +++ b/linux/sdcard/flash-sd.sh @@ -1,7 +1,7 @@ #!/bin/bash # Exit on any error (return code != 0) -set -e +# set -e # Output colors GREEN='\033[1;32m' @@ -11,10 +11,10 @@ NAME="$GREEN"${0:2}"$NC" # File location variables RISCV=/opt/riscv -IMAGES=/home/ross/repos/buildroot/output/images/ +IMAGES=$RISCV/buildroot/output/images/ FW_JUMP=$IMAGES/fw_jump.bin LINUX_KERNEL=$IMAGES/Image -DEVICE_TREE=$IMAGES/wally-artya7.dtb +DEVICE_TREE=$IMAGES/wally-vcu108.dtb # Mount Directory MNT_DIR=wallyimg @@ -61,12 +61,19 @@ echo -e "$NAME: Device tree block size: $DST_SIZE" echo -e "$NAME: OpenSBI FW_JUMP block size: $FW_JUMP_SIZE" echo -e "$NAME: Kernel block size: $KERNEL_SIZE" -read -p "Warning: " -n 1 -r +read -p "Warning: Doing this will replace all data on this card.\nContinue? y/n: " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]] ; then - # Make empty image - #echo -e "$NAME: Creating blank image" - #sudo dd if=/dev/zero of=$1 bs=4k conv=noerror status=progress && sync + DEVBASENAME=$(basename $1) + CHECKMOUNT=$(lsblk | grep "sdb4" | tr -s ' ' | cut -d' ' -f 7) + + if [ ! -z $CHECKMOUNT ] ; then + sudo umount -v $CHECKMOUNT + fi + + #Make empty image + echo -e "$NAME: Creating blank image" + sudo dd if=/dev/zero of=$1 bs=64k status=progress && sync # GUID Partition Tables (GPT) # =============================================== @@ -76,12 +83,10 @@ if [[ $REPLY =~ ^[Yy]$ ]] ; then # to 1 sector boundaries I think? This would normally be set to 2048 # apparently. - # sudo sgdisk -g --clear --set-alignment=1 \ - # --new=1:34:+$FW_JUMP_SIZE: --change-name=1:'opensbi' --typecode=1:2E54B353-1271-4842-806F-E436D6AF6985 \ - # --new=2:$KERNEL_START:+$KERNEL_SIZE --change-name=2:'kernel' --typecode=2:3000 \ - # --new=3:$FS_START:-0 --change-name=3:'filesystem' \ - # $1 + sudo sgdisk -z $1 + sleep 1 + echo -e "$NAME: Creating GUID Partition Table" sudo sgdisk -g --clear --set-alignment=1 \ --new=1:34:+$DST_SIZE: --change-name=1:'fdt' \ @@ -92,6 +97,8 @@ if [[ $REPLY =~ ^[Yy]$ ]] ; then sudo partprobe $1 + sleep 3 + echo -e "$NAME: Copying binaries into their partitions." DD_FLAGS="bs=4k iflag=fullblock oflag=direct conv=fsync status=progress" From ca1a9c577cb07e31aa3e678018becea4daa7e838 Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Sat, 5 Aug 2023 13:28:33 -0500 Subject: [PATCH 10/22] Created dependency tree for patch target in the linux subdirectory Makefile. --- linux/Makefile | 62 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index d846db791..8469bc589 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -3,31 +3,53 @@ BUILDROOT := ${RISCV}/buildroot IMAGES := ${BUILDROOT}/output/images WALLY := $(shell dirname $(shell pwd)) WALLYLINUX := $(shell pwd) +DIS := ${IMAGES}/disassembly +BRPACKAGES := $(WALLYLINUX)/buildroot-packages + +# Buildroot Config Stuff +WALLYBOARDSRC := $(WALLYLINUX)/buildroot-config-src/wally +WALLYBOARD := $(BUILDROOT)/board/wally + +# Buildroot Package Stuff PACKAGE_SOURCE := ${WALLYLINUX}/buildroot-packages/package-source FPGA_AXI_SDC := ${WALLYLINUX}/buildroot-packages/fpga-axi-sdc DRIVER := ${PACKAGE_SOURCE}/fpga-axi-sdc.c +PATCHFILE := $(BRPACKAGES)/package.patch -# Device tree file +# Device tree files DTS ?= $(shell find -type f -regex ".*\.dts" | sort) DTB := $(DTS:%.dts=%.dtb) DTB := $(foreach name, $(DTB), $(IMAGES)/$(shell basename $(name))) +# Disassembly stuff +BINARIES := fw_jump.elf vmlinux busybox +BINARIES := $(foreach name, $(BINARIES), $(shell find -type f -regex ".*$(name)")) +OBJDUMPS := fw_jump.objdump vmlinux.objdump busybox.objdump +OBJDUMPS := $(foreach name, $(OBJDUMPS), $(DIS)/$(name)) + .PHONY: generate cleanDriver patch clean # Generate all device trees # TODO: Add configuration for only generating device tree for specified # supported FPGA. +test: + generate: $(DTB) $(DTB): $(DTS) dtc -I dts -O dtb $< > $@ disassemble: + mkdir -p $(DIS) + make -j $(OBJDUMPS) + +$(OBJDUMPS): $(BINARIES) + riscv64-unknown-elf-objdump -DS $< >> $@ # Generating new Buildroot directories -------------------------------- -# This directive should be run as: make patch BUILDROOT=path/to/buildroot -patch: $(BUILDROOT) $(DRIVER) +# This directive should be run as: make newbr BUILDROOT=path/to/buildroot +newbr: $(BUILDROOT) $(DRIVER) @ echo "Patching buildroot directory at: $<" @ echo "Copying wally configuration files and rootfs_overlay to buildroot." cp -r $(WALLYLINUX)/buildroot-config-src/wally $ Date: Sat, 5 Aug 2023 15:27:17 -0500 Subject: [PATCH 11/22] Fixed Makefile bugs, and removed old code. --- linux/Makefile | 47 +++++++++++++---------------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index 8469bc589..0c5d66a1d 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -36,8 +36,12 @@ test: generate: $(DTB) -$(DTB): $(DTS) - dtc -I dts -O dtb $< > $@ +$(DTB): $(DTS) $(IMAGES) + dtc -I dts -O dtb $< > $@ + +$(IMAGES): + @ echo "No output/images directory in buildroot." + @ echo "Run make --jobs in buildroot directory before generating device tree binaries."; exit 1 disassemble: mkdir -p $(DIS) @@ -48,33 +52,9 @@ $(OBJDUMPS): $(BINARIES) # Generating new Buildroot directories -------------------------------- -# This directive should be run as: make newbr BUILDROOT=path/to/buildroot -newbr: $(BUILDROOT) $(DRIVER) - @ echo "Patching buildroot directory at: $<" - @ echo "Copying wally configuration files and rootfs_overlay to buildroot." - cp -r $(WALLYLINUX)/buildroot-config-src/wally $ Date: Sun, 6 Aug 2023 18:50:37 -0500 Subject: [PATCH 12/22] Stopped makefile from crashing when patch is already applied. --- linux/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/Makefile b/linux/Makefile index 0c5d66a1d..28edebeda 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -70,7 +70,7 @@ $(WALLYBOARD): $(BUILDROOT) $(BUILDROOT)/package/fpga-axi-sdc: $(BUILDROOT) $(PATCHFILE) $(BRPACKAGES)/fpga-axi-sdc cp -r $(BRPACKAGES)/fpga-axi-sdc $(BUILDROOT)/package sed -i 's|FPGA_AXI_SDC_SITE =|FPGA_AXI_SDC_SITE = $(PACKAGE_SOURCE)|1' $(BUILDROOT)/package/fpga-axi-sdc/fpga-axi-sdc.mk - cd $(BUILDROOT); git apply $(PATCHFILE) + cd $(BUILDROOT); if git apply --check $(PATCHFILE) > /dev/null ; then git apply $(PATCHFILE); fi $(PATCHFILE): cd $(BUILDROOT); git apply $(PATCHFILE) From 1582376d71ac24a38cc5621b3ef6154aa6854705 Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Wed, 9 Aug 2023 00:22:20 -0500 Subject: [PATCH 13/22] Fixed device tree generation make rule. Make targets are simplified. --- linux/Makefile | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index 28edebeda..520536fe0 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -23,37 +23,48 @@ DTB := $(foreach name, $(DTB), $(IMAGES)/$(shell basename $(name))) # Disassembly stuff BINARIES := fw_jump.elf vmlinux busybox -BINARIES := $(foreach name, $(BINARIES), $(shell find -type f -regex ".*$(name)")) +BINARIES := $(foreach name, $(BINARIES), $(IMAGES)/$(name)) +#BINARIES := $(foreach name, $(BINARIES), $(shell find -type f -regex ".*$(name)")) OBJDUMPS := fw_jump.objdump vmlinux.objdump busybox.objdump OBJDUMPS := $(foreach name, $(OBJDUMPS), $(DIS)/$(name)) -.PHONY: generate cleanDriver patch clean +.PHONY: generate disassemble install clean cleanDTB cleanDriver -# Generate all device trees +# Generate all device trees ------------------------------------------- # TODO: Add configuration for only generating device tree for specified # supported FPGA. -test: -generate: $(DTB) +generate: $(DTB) $(IMAGES) -$(DTB): $(DTS) $(IMAGES) +$(IMAGES)/%.dtb: ./devicetree/%.dts dtc -I dts -O dtb $< > $@ $(IMAGES): @ echo "No output/images directory in buildroot." @ echo "Run make --jobs in buildroot directory before generating device tree binaries."; exit 1 +# Disassembly rules --------------------------------------------------- + disassemble: mkdir -p $(DIS) make -j $(OBJDUMPS) -$(OBJDUMPS): $(BINARIES) +$(DIS)/%.objdump: $(IMAGES)/%.elf riscv64-unknown-elf-objdump -DS $< >> $@ +$(DIS)/%.objdump: $(IMAGES)/% + riscv64-unknown-elf-objdump -S $< >> $@ + +$(IMAGES)/vmlinux: $(BUILDROOT)/output/build/linux-5.10.7/vmlinux + cp $< $@ + +$(IMAGES)/busybox: $(BUILDROOT)/output/build/busybox-1.33.0/busybox + cp $< $@ + # Generating new Buildroot directories -------------------------------- -# This directive should be run as: make patch BUILDROOT=path/to/buildroot -patch: $(BUILDROOT)/package/fpga-axi-sdc $(WALLYBOARD)/main.config $(WALLYBOARD)/linux.config $(DRIVER) +# This directive should be run as: make install BUILDROOT=path/to/buildroot +install: $(BUILDROOT)/package/fpga-axi-sdc $(WALLYBOARD)/main.config $(WALLYBOARD)/linux.config $(DRIVER) cp $(WALLYBOARD)/main.config $(BUILDROOT)/.config # CONFIG DEPENDENCIES 2021.05 ----------------------------------------- @@ -91,6 +102,9 @@ $(DRIVER): cleanDriver: rm -f $(DRIVER) +cleanDTB: + rm -f $(IMAGES)/*.dtb + clean: ls $(IMAGES) rm -rf $(IMAGES)/*.dtb From 40096ac662297930a0f212471f2b9f0246b15882 Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Wed, 9 Aug 2023 12:31:14 -0500 Subject: [PATCH 14/22] Fixed bugs. Added an 'all' target that performs the whole process of building the images needed for booting linux, including device tree files. --- linux/Makefile | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index 520536fe0..7c85e0ee4 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -23,17 +23,25 @@ DTB := $(foreach name, $(DTB), $(IMAGES)/$(shell basename $(name))) # Disassembly stuff BINARIES := fw_jump.elf vmlinux busybox -BINARIES := $(foreach name, $(BINARIES), $(IMAGES)/$(name)) -#BINARIES := $(foreach name, $(BINARIES), $(shell find -type f -regex ".*$(name)")) -OBJDUMPS := fw_jump.objdump vmlinux.objdump busybox.objdump -OBJDUMPS := $(foreach name, $(OBJDUMPS), $(DIS)/$(name)) +OBJDUMPS := $(foreach name, $(BINARIES), $(basename $(name) .elf)) +OBJDUMPS := $(foreach name, $(OBJDUMPS), $(DIS)/$(name).objdump) -.PHONY: generate disassemble install clean cleanDTB cleanDriver +.PHONY: all generate disassemble install clean cleanDTB cleanDriver test # Generate all device trees ------------------------------------------- # TODO: Add configuration for only generating device tree for specified # supported FPGA. +all: + $(MAKE) install + make -C $(BUILDROOT) --jobs + $(MAKE) generate + # TODO: Need to find a way to set the PATH for child processes. + # source ../setup.sh; $(MAKE) disassemble + +test: + @echo $(OBJDUMPS) + generate: $(DTB) $(IMAGES) $(IMAGES)/%.dtb: ./devicetree/%.dts @@ -43,6 +51,10 @@ $(IMAGES): @ echo "No output/images directory in buildroot." @ echo "Run make --jobs in buildroot directory before generating device tree binaries."; exit 1 +$(RISCV): + @ echo "ERROR: No $(RISCV) directory. Make sure you have installed the Wally Toolchain." + @ echo "this can be done with /bin/wally-tool-chain-install.sh" + # Disassembly rules --------------------------------------------------- disassemble: @@ -64,18 +76,20 @@ $(IMAGES)/busybox: $(BUILDROOT)/output/build/busybox-1.33.0/busybox # Generating new Buildroot directories -------------------------------- # This directive should be run as: make install BUILDROOT=path/to/buildroot -install: $(BUILDROOT)/package/fpga-axi-sdc $(WALLYBOARD)/main.config $(WALLYBOARD)/linux.config $(DRIVER) +install: $(BUILDROOT)/package/fpga-axi-sdc $(WALLYBOARD) $(DRIVER) cp $(WALLYBOARD)/main.config $(BUILDROOT)/.config # CONFIG DEPENDENCIES 2021.05 ----------------------------------------- -$(WALLYBOARD)/main.config: $(WALLYBOARD) $(BRPACKAGES)/wally.config - cp $(BRPACKAGES)/wally.config $@ +# $(WALLYBOARD)/main.config: $(WALLYBOARD) $(BRPACKAGES)/wally.config +# cp $(BRPACKAGES)/wally.config $@ -$(WALLYBOARD)/linux.config: $(WALLYBOARD) $(BRPACKAGES)/linux.config - cp $(BRPACKAGES)/linux.config $@ +# $(WALLYBOARD)/linux.config: $(BRPACKAGES)/linux.config $(WALLYBOARD) +# cp $(BRPACKAGES)/linux.config $@ $(WALLYBOARD): $(BUILDROOT) cp -r $(WALLYBOARDSRC) $(BUILDROOT)/board + cp $(BRPACKAGES)/wally.config $(WALLYBOARD)/main.config + cp $(BRPACKAGES)/linux.config $(WALLYBOARD)/linux.config # Buildroot Package --------------------------------------------------- $(BUILDROOT)/package/fpga-axi-sdc: $(BUILDROOT) $(PATCHFILE) $(BRPACKAGES)/fpga-axi-sdc From 027190ecc90f8c13255082cd2d02e178d835d728 Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Fri, 11 Aug 2023 12:11:56 -0500 Subject: [PATCH 15/22] Added a README.md for the linux directory. WIP. --- linux/README.MD | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 linux/README.MD diff --git a/linux/README.MD b/linux/README.MD new file mode 100644 index 000000000..d753c7ab3 --- /dev/null +++ b/linux/README.MD @@ -0,0 +1,26 @@ +# Linux for core-v-wally + +## Setting up Buildroot + +In order to generate the Linux and boot stage binaries compatible with Wally, Buildroot is used for cross-compilation. To set up a Buildroot directory, configuration files for Buildroot, Linux, and Busybox must be copied into the correct locations inside the main Buildroot directory. This can be done automatically using the Makefile inside Wally's Linux subdirectory (this one). To install and patch a fresh Buildroot directory, type: + + $ make install BUILDROOT=path/to/buildroot + +In addition to copying the configuration files, it will install the buildroot package needed to build the SD card driver for Linux. + +To install a new buildroot directory, build the binaries, and generate the device tree binaries in one command, use: + + $ make BUILDROOT=path/to/buildroot + +Or simply use the default buildroot location in /opt/riscv: + + $ make + +Note that the `$RISCV` variable cannot be set prior to building in buildroot or the build will fail. It is best to run `source ./setup.sh` to alter your `$PATH` and set the `$RISCV` variable after buildroot has succesfully built the binaries. If you're new to buildroot, you can find the binaries in `/output/images`. + +## Generating Device Tree Binaries + + +## Creating a Bootable SD Card + + From 5f0edbd82531dac41ba301a4d75e54e68b7cbf3f Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Fri, 11 Aug 2023 12:27:23 -0500 Subject: [PATCH 16/22] Added details to the README.md for linux. --- linux/README.MD | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/linux/README.MD b/linux/README.MD index d753c7ab3..3e47f58e5 100644 --- a/linux/README.MD +++ b/linux/README.MD @@ -6,13 +6,13 @@ In order to generate the Linux and boot stage binaries compatible with Wally, Bu $ make install BUILDROOT=path/to/buildroot -In addition to copying the configuration files, it will install the buildroot package needed to build the SD card driver for Linux. +You can override the `BUILDROOT` variable to place buildroot where you want it. By default it will be placed at `/opt/riscv/buildroot`. In addition to copying the configuration files, it will install the buildroot package needed to build the SD card driver for Linux. To install a new buildroot directory, build the binaries, and generate the device tree binaries in one command, use: $ make BUILDROOT=path/to/buildroot -Or simply use the default buildroot location in /opt/riscv: +Or simply use the default buildroot location in `/opt/riscv`: $ make @@ -20,6 +20,13 @@ Note that the `$RISCV` variable cannot be set prior to building in buildroot or ## Generating Device Tree Binaries +The device tree files for the various FPGA's Wally supports, as well as QEMU's device tree for the virt machine, are located in the `./devicetree` subdirectory. These device tree files are necessary for the boot process. In order to build the device tree binaries (.dtb) from the device tree sources (.dts), we can build all of them at once using: + + $ make generate BUILDROOT=path/to/buildroot + + Or for the default buildroot location: + + $ make generate ## Creating a Bootable SD Card From 4b22d137f841bc37e08d4d4685875e90c80a96e7 Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Fri, 11 Aug 2023 13:11:06 -0500 Subject: [PATCH 17/22] Added instructions on disassembly to the README for Linux. --- linux/README.MD | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/linux/README.MD b/linux/README.MD index 3e47f58e5..c87b107a9 100644 --- a/linux/README.MD +++ b/linux/README.MD @@ -27,6 +27,18 @@ The device tree files for the various FPGA's Wally supports, as well as QEMU's d Or for the default buildroot location: $ make generate + +The .dts files will end up in the `/output/images` folder of your chosen buildroot directory. + +## Disassembling the Binaries for Debugging + +By using the `riscv64-unknown-elf-objdump` utility, we can disassemble the binaries in `/output/images` so that we can explore the resulting machine code instructions and see what assembly or C code the instructions came from, along with the corresponding addresses. This is useful during debugging in order to trace how code is being executed. + +To create the disassembled binaries, run: + + $ make disassemble BUILDROOT=path/to/buildroot + +You'll find the resulting disassembled files in `/output/images/disassembly`. ## Creating a Bootable SD Card From 2be76bd6f8856f139ae7771813d388916349d64e Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Fri, 11 Aug 2023 15:48:49 -0500 Subject: [PATCH 18/22] Added a table of contents to the linux readme. --- linux/README.MD | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/linux/README.MD b/linux/README.MD index c87b107a9..68de94f03 100644 --- a/linux/README.MD +++ b/linux/README.MD @@ -1,6 +1,13 @@ # Linux for core-v-wally -## Setting up Buildroot +## Table of Contents + +1. [Setting up Buildroot](#buildroot) +2. [Generating Device Tree Binaries](#devicetree) +3. [Disassembling the Binaries for Debugging](#disassembly) +4. [Creating a Bootable SD Card](#sdcard) + +## Setting up Buildroot In order to generate the Linux and boot stage binaries compatible with Wally, Buildroot is used for cross-compilation. To set up a Buildroot directory, configuration files for Buildroot, Linux, and Busybox must be copied into the correct locations inside the main Buildroot directory. This can be done automatically using the Makefile inside Wally's Linux subdirectory (this one). To install and patch a fresh Buildroot directory, type: @@ -18,7 +25,7 @@ Or simply use the default buildroot location in `/opt/riscv`: Note that the `$RISCV` variable cannot be set prior to building in buildroot or the build will fail. It is best to run `source ./setup.sh` to alter your `$PATH` and set the `$RISCV` variable after buildroot has succesfully built the binaries. If you're new to buildroot, you can find the binaries in `/output/images`. -## Generating Device Tree Binaries +## Generating Device Tree Binaries The device tree files for the various FPGA's Wally supports, as well as QEMU's device tree for the virt machine, are located in the `./devicetree` subdirectory. These device tree files are necessary for the boot process. In order to build the device tree binaries (.dtb) from the device tree sources (.dts), we can build all of them at once using: @@ -30,7 +37,7 @@ The device tree files for the various FPGA's Wally supports, as well as QEMU's d The .dts files will end up in the `/output/images` folder of your chosen buildroot directory. -## Disassembling the Binaries for Debugging +## Disassembling the Binaries for Debugging By using the `riscv64-unknown-elf-objdump` utility, we can disassemble the binaries in `/output/images` so that we can explore the resulting machine code instructions and see what assembly or C code the instructions came from, along with the corresponding addresses. This is useful during debugging in order to trace how code is being executed. @@ -40,6 +47,6 @@ To create the disassembled binaries, run: You'll find the resulting disassembled files in `/output/images/disassembly`. -## Creating a Bootable SD Card +## Creating a Bootable SD Card From bb8d3806d63cdce5a36e6c34944cae003b5c6d64 Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Fri, 11 Aug 2023 16:22:12 -0500 Subject: [PATCH 19/22] Cleaned up some things. --- linux/Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/linux/Makefile b/linux/Makefile index 7c85e0ee4..abbf4a51a 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -39,6 +39,7 @@ all: # TODO: Need to find a way to set the PATH for child processes. # source ../setup.sh; $(MAKE) disassemble +# Temp rule for debugging test: @echo $(OBJDUMPS) @@ -120,7 +121,4 @@ cleanDTB: rm -f $(IMAGES)/*.dtb clean: - ls $(IMAGES) - rm -rf $(IMAGES)/*.dtb rm -rf $(DIS) - ls $(IMAGES) From 63e901e981e61860f5348a111de1ee562726f7d4 Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Wed, 16 Aug 2023 12:12:31 -0500 Subject: [PATCH 20/22] Added probe script to generate a single probe for the fpga. --- fpga/probe | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 fpga/probe diff --git a/fpga/probe b/fpga/probe new file mode 100755 index 000000000..f95c8c2b7 --- /dev/null +++ b/fpga/probe @@ -0,0 +1,74 @@ +#!/usr/bin/python3 + +import sys + +def usage(): + print("Usage: ./probes name width probenum") + exit(1) + +def header(): + return """create_debug_core u_ila_0 ila + +set_property C_DATA_DEPTH 16384 [get_debug_cores u_ila_0] +set_property C_TRIGIN_EN false [get_debug_cores u_ila_0] +set_property C_TRIGOUT_EN false [get_debug_cores u_ila_0] +set_property C_ADV_TRIGGER false [get_debug_cores u_ila_0] +set_property C_INPUT_PIPE_STAGES 0 [get_debug_cores u_ila_0] +set_property C_EN_STRG_QUAL false [get_debug_cores u_ila_0] +set_property ALL_PROBE_SAME_MU true [get_debug_cores u_ila_0] +set_property ALL_PROBE_SAME_MU_CNT 1 [get_debug_cores u_ila_0] +startgroup +set_property C_EN_STRG_QUAL true [get_debug_cores u_ila_0 ] +set_property C_ADV_TRIGGER true [get_debug_cores u_ila_0 ] +set_property ALL_PROBE_SAME_MU true [get_debug_cores u_ila_0 ] +set_property ALL_PROBE_SAME_MU_CNT 4 [get_debug_cores u_ila_0 ] +endgroup +connect_debug_port u_ila_0/clk [get_nets [list xlnx_ddr4_c0/inst/u_ddr4_infrastructure/addn_ui_clkout1 ]]""" + +def convertLine(x): + temp = x.split() + temp[1] = int(temp[1]) + return tuple(temp) + +def probeBits( probe ): + str = '' + + if (probe[1] > 1): + for i in range(probe[1]): + if i != (probe[1]-1): + str = str + f"{{{probe[0]}[{i}]}} " + else: + str = str + f"{{{probe[0]}[{i}]}} " + + else: + str = f'{{{probe[0]}}}' + + return str + +def printProbe( probe, i ): + bits = probeBits(probe) + + return ( + f'create_debug_port u_ila_0 probe\n' + f'set_property port_width {probe[1]} [get_debug_ports u_ila_0/probe{i}]\n' + f'set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe{i}]\n' + f'connect_debug_port u_ila_0/probe{i} [get_nets [list {bits}]]\n\n' + ) + +def main(args): + if (len(args) != 3): + usage() + + name = args[0] + width = int(args[1]) + probeNum = int(args[2]) + + + probe = (name, width) + + print(printProbe(probe, probeNum)) + +if __name__ == '__main__': + main(sys.argv[1:]) + + From c2f2bef4333fff9f0b9e2f7f559d39fa0c5162c5 Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Wed, 16 Aug 2023 12:20:08 -0500 Subject: [PATCH 21/22] Fixed bug caused by errant tab size in probe script. --- fpga/probe | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fpga/probe b/fpga/probe index f95c8c2b7..5067a2cf6 100755 --- a/fpga/probe +++ b/fpga/probe @@ -40,19 +40,21 @@ def probeBits( probe ): else: str = str + f"{{{probe[0]}[{i}]}} " - else: - str = f'{{{probe[0]}}}' + else: + str = f'{{{probe[0]}}}' return str def printProbe( probe, i ): bits = probeBits(probe) + print(bits) + return ( - f'create_debug_port u_ila_0 probe\n' - f'set_property port_width {probe[1]} [get_debug_ports u_ila_0/probe{i}]\n' - f'set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe{i}]\n' - f'connect_debug_port u_ila_0/probe{i} [get_nets [list {bits}]]\n\n' + f'create_debug_port u_ila_0 probe\n' + f'set_property port_width {probe[1]} [get_debug_ports u_ila_0/probe{i}]\n' + f'set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe{i}]\n' + f'connect_debug_port u_ila_0/probe{i} [get_nets [list {bits}]]\n\n' ) def main(args): From f91157fc959ff33396eb020d2e537a7a44eb0d33 Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Wed, 16 Aug 2023 13:05:37 -0500 Subject: [PATCH 22/22] Added SPDX header to probe script. --- fpga/probe | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/fpga/probe b/fpga/probe index 5067a2cf6..21e5d8240 100755 --- a/fpga/probe +++ b/fpga/probe @@ -1,4 +1,28 @@ #!/usr/bin/python3 +########################################### +## probe.sh +## +## Written: Jacob Pease jacobpease@protonmail.com +## Created: 16 August 2023 +## Modified: 16 August 2023 +## +## A component of the CORE-V-WALLY configurable RISC-V project. +## +## Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +## +## SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +## +## Licensed under the Solderpad Hardware License v 2.1 (the “License”); you may not use this file +## except in compliance with the License, or, at your option, the Apache License version 2.0. You +## may obtain a copy of the License at +## +## https:##solderpad.org#licenses#SHL-2.1# +## +## Unless required by applicable law or agreed to in writing, any work distributed under the +## License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +## either express or implied. See the License for the specific language governing permissions +## and limitations under the License. +################################################################################################ import sys @@ -6,25 +30,6 @@ def usage(): print("Usage: ./probes name width probenum") exit(1) -def header(): - return """create_debug_core u_ila_0 ila - -set_property C_DATA_DEPTH 16384 [get_debug_cores u_ila_0] -set_property C_TRIGIN_EN false [get_debug_cores u_ila_0] -set_property C_TRIGOUT_EN false [get_debug_cores u_ila_0] -set_property C_ADV_TRIGGER false [get_debug_cores u_ila_0] -set_property C_INPUT_PIPE_STAGES 0 [get_debug_cores u_ila_0] -set_property C_EN_STRG_QUAL false [get_debug_cores u_ila_0] -set_property ALL_PROBE_SAME_MU true [get_debug_cores u_ila_0] -set_property ALL_PROBE_SAME_MU_CNT 1 [get_debug_cores u_ila_0] -startgroup -set_property C_EN_STRG_QUAL true [get_debug_cores u_ila_0 ] -set_property C_ADV_TRIGGER true [get_debug_cores u_ila_0 ] -set_property ALL_PROBE_SAME_MU true [get_debug_cores u_ila_0 ] -set_property ALL_PROBE_SAME_MU_CNT 4 [get_debug_cores u_ila_0 ] -endgroup -connect_debug_port u_ila_0/clk [get_nets [list xlnx_ddr4_c0/inst/u_ddr4_infrastructure/addn_ui_clkout1 ]]""" - def convertLine(x): temp = x.split() temp[1] = int(temp[1])