2025-01-22 04:14:01 +00:00
|
|
|
BUILDROOT := buildroot
|
|
|
|
IMAGE_DIR := ${BUILDROOT}/output/images
|
|
|
|
DISASSEMBLY_DIR := ${IMAGE_DIR}/disassembly
|
|
|
|
WALLYLINUX := $(WALLY)/linux
|
2025-01-04 16:22:39 +00:00
|
|
|
BR2_EXTERNAL_TREE := $(WALLYLINUX)/br2-external-tree
|
2025-01-22 04:14:01 +00:00
|
|
|
LINUX_TESTVECTORS := $(RISCV)/linux-testvectors
|
2023-08-05 18:28:33 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
BUILDROOT_OUTPUTS := Image fw_jump.bin fw_jump.elf rootfs.cpio vmlinux busybox
|
2023-08-05 18:28:33 +00:00
|
|
|
|
2024-07-26 18:46:09 +00:00
|
|
|
# Device tree files
|
2025-01-21 09:19:36 +00:00
|
|
|
DTS ?= $(wildcard devicetree/*.dts)
|
2025-01-22 04:14:01 +00:00
|
|
|
DTB := $(foreach name, $(DTS:%.dts=%.dtb), $(IMAGE_DIR)/$(notdir $(name)))
|
2023-08-02 19:28:17 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Disassembly files
|
2023-08-05 18:28:33 +00:00
|
|
|
BINARIES := fw_jump.elf vmlinux busybox
|
2025-01-22 04:14:01 +00:00
|
|
|
OBJDUMPS := $(foreach name, $(basename $(BINARIES) .elf), $(DISASSEMBLY_DIR)/$(name).objdump)
|
|
|
|
|
|
|
|
# Testvector files
|
|
|
|
RAW_RAM_FILE := ${LINUX_TESTVECTORS}/ramGDB.bin
|
|
|
|
RAM_FILE := ${LINUX_TESTVECTORS}/ram.bin
|
|
|
|
RAW_BOOTMEM_FILE := ${LINUX_TESTVECTORS}/bootmemGDB.bin
|
|
|
|
BOOTMEM_FILE := ${LINUX_TESTVECTORS}/bootmem.bin
|
2023-08-05 18:28:33 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
.PHONY: all check_environment check_write_permissions config build disassemble devicetrees install dumptvs clean cleanDTB
|
2023-08-03 00:26:35 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Default target
|
|
|
|
all: check_write_permissions clean config build disassemble install dumptvs
|
2024-10-20 23:40:11 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Check if the environment variables are set correctly
|
2024-10-20 23:40:11 +00:00
|
|
|
check_environment: $(RISCV)
|
|
|
|
ifeq ($(findstring :$(RISCV)/lib:,:$(LD_LIBRARY_PATH):),)
|
|
|
|
@(echo "ERROR: Your environment variables are not set correctly." >&2 \
|
|
|
|
&& echo "Make sure to source setup.sh or install buildroot using the wally-tool-chain-install.sh script." >&2 \
|
|
|
|
&& exit 1)
|
|
|
|
endif
|
2023-11-22 02:21:26 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Check if the user has write permissions to the RISCV directory, potentially using sudo
|
|
|
|
SUDO := $(shell mkdir -p $(RISCV)/.test > /dev/null 2>&1 || echo sudo)
|
2025-01-21 09:19:36 +00:00
|
|
|
check_write_permissions: check_environment
|
2024-07-26 18:46:09 +00:00
|
|
|
ifeq ($(SUDO), sudo)
|
|
|
|
@echo "Cannot write to '$(RISCV)'." \
|
|
|
|
"Using sudo (you may be prompted for your password several times throughout the install)"
|
|
|
|
endif
|
|
|
|
@$(SUDO) mkdir -p $(RISCV)/.test || \
|
|
|
|
(echo "ERROR: Still unable to write to '$(RISCV)'." >&2 \
|
2024-07-24 07:22:28 +00:00
|
|
|
&& exit 1)
|
2024-07-26 18:46:09 +00:00
|
|
|
@$(SUDO) rm -r $(RISCV)/.test
|
2024-04-06 04:38:30 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Build buildroot and device tree binaries
|
|
|
|
build: $(BUILDROOT_OUTPUTS) devicetrees
|
|
|
|
|
|
|
|
# Build buildroot itself
|
|
|
|
# LD_LIBRARY_PATH must be unset to avoid conflicts between the host and cross compiler
|
|
|
|
$(BUILDROOT_OUTPUTS): check_environment $(BUILDROOT)
|
2024-07-26 22:46:08 +00:00
|
|
|
bash -c "unset LD_LIBRARY_PATH; $(MAKE) -C $(BUILDROOT)"
|
2023-08-09 17:31:14 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Install buildroot to $RISCV
|
2025-01-21 09:19:36 +00:00
|
|
|
install: check_write_permissions
|
2024-07-26 18:46:09 +00:00
|
|
|
$(SUDO) rm -rf $(RISCV)/$(BUILDROOT)
|
|
|
|
$(SUDO) mv $(BUILDROOT) $(RISCV)/$(BUILDROOT)
|
2025-01-21 09:19:36 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Generate linux boot testvectors
|
|
|
|
dumptvs: ${RAM_FILE} ${BOOTMEM_FILE}
|
2025-01-21 09:19:36 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Format QEMU memory dumps for use as testvectors
|
|
|
|
${LINUX_TESTVECTORS}/%.bin: ${LINUX_TESTVECTORS}/%GDB.bin
|
2025-01-21 09:19:36 +00:00
|
|
|
truncate -s %8 $^ # Extend file to 8 byte multiple
|
|
|
|
objcopy --reverse-bytes=8 -F binary $^ $@ # Reverse bytes
|
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Generate memory dumps from QEMU buildroot boot
|
|
|
|
TCP_PORT := 1235
|
|
|
|
${LINUX_TESTVECTORS}/%GDB.bin: | $(LINUX_TESTVECTORS)
|
2025-01-21 09:19:36 +00:00
|
|
|
${WALLYLINUX}/qemuBoot.sh --gdb ${TCP_PORT} &
|
|
|
|
riscv64-unknown-elf-gdb -batch \
|
|
|
|
-ex "target remote :${TCP_PORT}" \
|
|
|
|
-ex "maintenance packet Qqemu.PhyMemMode:1" \
|
|
|
|
-ex "printf \"Creating ${RAW_BOOTMEM_FILE}\n\"" \
|
|
|
|
-ex "dump binary memory ${RAW_BOOTMEM_FILE} 0x1000 0x1fff" \
|
|
|
|
-ex "printf \"Creating ${RAW_RAM_FILE}\n\"" \
|
|
|
|
-ex "dump binary memory ${RAW_RAM_FILE} 0x80000000 0x8fffffff" \
|
2025-01-22 04:14:01 +00:00
|
|
|
-ex "kill"
|
2023-08-04 18:56:03 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Generate device tree binaries
|
|
|
|
devicetrees: $(DTB)
|
|
|
|
$(IMAGE_DIR)/%.dtb: ${WALLYLINUX}/devicetree/%.dts
|
2023-08-05 20:27:17 +00:00
|
|
|
dtc -I dts -O dtb $< > $@
|
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Create disassembly files
|
|
|
|
disassemble: check_environment $(OBJDUMPS) $(DISASSEMBLY_DIR)/rootfs
|
2023-08-03 00:26:35 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Extract rootfs
|
|
|
|
$(DISASSEMBLY_DIR)/rootfs: $(IMAGE_DIR)/rootfs.cpio
|
2024-07-26 22:46:08 +00:00
|
|
|
@echo "Ignore error about dev/console when extracting rootfs from rootfs.cpio"
|
2025-01-22 04:33:25 +00:00
|
|
|
-cpio -id -D $(DISASSEMBLY_DIR)/rootfs -F $(IMAGE_DIR)rootfs.cpio
|
2023-08-05 18:28:33 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Disassemble binaries
|
|
|
|
objdump_flags = $(if $(findstring .elf,$<),-SD,-S) # Add -D flag for .elf files
|
|
|
|
$(DISASSEMBLY_DIR)/%.objdump: $(IMAGE_DIR)/% | $(DISASSEMBLY_DIR)
|
|
|
|
riscv64-unknown-elf-objdump $(objdump_flags) $< >> $@
|
2024-07-27 01:33:09 +00:00
|
|
|
$(WALLY)/bin/extractFunctionRadix.sh $@
|
2023-08-03 00:26:35 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Load wally buildroot configuration
|
2025-01-21 09:19:36 +00:00
|
|
|
config: $(BUILDROOT) $(BR2_EXTERNAL_TREE)/configs/wally_defconfig
|
2025-01-04 06:32:11 +00:00
|
|
|
$(MAKE) -C $(BUILDROOT) wally_defconfig BR2_EXTERNAL=$(BR2_EXTERNAL_TREE)
|
2023-08-05 18:28:33 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Clone buildroot and checkout the correct version
|
2023-08-02 19:28:17 +00:00
|
|
|
$(BUILDROOT):
|
|
|
|
git clone https://github.com/buildroot/buildroot.git $@
|
2025-01-04 05:52:48 +00:00
|
|
|
cd $@; git checkout 2024.11.x
|
2023-08-03 00:26:35 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Create directories
|
|
|
|
$(LINUX_TESTVECTORS): check_write_permissions
|
2025-01-21 09:19:36 +00:00
|
|
|
$(SUDO) mkdir -p $@
|
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
$(DISASSEMBLY_DIR):
|
2025-01-21 09:19:36 +00:00
|
|
|
mkdir -p $@
|
2023-08-02 23:59:42 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Remove device tree binaries
|
2023-08-09 05:22:20 +00:00
|
|
|
cleanDTB:
|
2025-01-22 04:14:01 +00:00
|
|
|
rm -f $(IMAGE_DIR)/*.dtb
|
2023-08-09 05:22:20 +00:00
|
|
|
|
2025-01-22 04:14:01 +00:00
|
|
|
# Remove buildroot directory
|
2023-08-04 18:56:03 +00:00
|
|
|
clean:
|
2023-12-13 19:33:59 +00:00
|
|
|
rm -rf $(BUILDROOT)
|
2025-01-22 04:14:01 +00:00
|
|
|
|
|
|
|
# Check if the RISCV environment variable is set
|
|
|
|
$(RISCV):
|
|
|
|
@ echo "ERROR: No $(RISCV) directory. Make sure you have installed the Wally Toolchain."
|
|
|
|
@ echo "and sourced setup.sh"
|