clean-up build flow. Add sdcard prepare targets.

This commit is contained in:
Benjamin Krill 2014-03-27 09:16:02 +01:00
parent 9263fc72a7
commit b2e55d7bea
2 changed files with 167 additions and 59 deletions

2
README
View File

@ -1,4 +1,4 @@
Arrow SoCKIT Altera CycloneV ARM (Arrow SoCKIT)
-- FPGA build requirements -- FPGA build requirements
export QUARTUS_ROOTDIR=/home/dev/altera/13.1/quartus/ export QUARTUS_ROOTDIR=/home/dev/altera/13.1/quartus/

View File

@ -11,67 +11,61 @@ PROJECT := sockit
BUILD_DIR := $(PWD)/build_$(PROJECT) BUILD_DIR := $(PWD)/build_$(PROJECT)
BUILD_QUARTUS_DIR := $(BUILD_DIR)/quartus BUILD_QUARTUS_DIR := $(BUILD_DIR)/quartus
##### SOURCE FILES ############################ ##### SOURCE FILES #####################################################################################
SOURCE_QIP = $(TOP)/top/$(PROJECT).qip SOURCE_QIP = $(TOP)/top/$(PROJECT).qip
##### DEFAULT ################################# ##### DEFAULT ##########################################################################################
.PHONY: default .PHONY: default
default: help default: help
##### QSYS #################################### ##### QSYS #############################################################################################
.PHONY: qsys-generate qsys-edit .PHONY: qsys-generate qsys-edit
QSYS_FILE := $(TOP)/soc/soc_system.qsys QSYS_FILE = $(TOP)/soc/soc_system.qsys
QSYS_BASE := $(basename $(notdir $(QSYS_FILE))) QSYS_BASE = $(basename $(notdir $(QSYS_FILE)))
QSYS_OUTDIR := $(BUILD_DIR)/$(QSYS_BASE) QSYS_OUTDIR = $(BUILD_DIR)/$(QSYS_BASE)
QSYS_QIP := $(QSYS_OUTDIR)/$(QSYS_BASE).qip QSYS_QIP = $(QSYS_OUTDIR)/$(QSYS_BASE).qip
QSYS_SOPCINFO := $(QSYS_OUTDIR)/$(QSYS_BASE).sopcinfo QSYS_SOPCINFO = $(QSYS_OUTDIR)/$(QSYS_BASE).sopcinfo
SOURCE_QIP += $(QSYS_QIP) SOURCE_QIP += $(QSYS_QIP)
$(QSYS_QIP) qsys-generate: config $(QSYS_FILE) $(QSYS_QIP): $(QSYS_FILE)
mkdir -p $(QSYS_OUTDIR)
ip-generate \ ip-generate \
--component-file=$(QSYS_FILE) \ --component-file=$(QSYS_FILE) \
--file-set=QUARTUS_SYNTH \ --file-set=QUARTUS_SYNTH \
--output-name=$(QSYS_BASE) \ --output-name=$(QSYS_BASE) \
--output-directory=$(QSYS_OUTDIR) \ --output-directory=$(QSYS_OUTDIR) \
--reportfile=sopcinfo:$(QSYS_SOPCINFO) \ --reportfile=sopcinfo:$(QSYS_SOPCINFO) \
--reportfile=qip:$(QSYS_QIP) \ --reportfile=qip:$@ \
--language=vhdl --language=vhdl
touch $(QSYS_QIP) touch $(QSYS_QIP)
qsys-generate: $(QSYS_QIP)
qsys-edit: $(QSYS_FILE) qsys-edit: $(QSYS_FILE)
qsys-edit $^ & qsys-edit $^ &
HELP_TARGETS += qsys-generate qsys-edit HELP_TARGETS += qsys-generate qsys-edit
qsys-generate.HELP := Generate current QSYS implementation qsys-generate.HELP = Generate current QSYS implementation
qsys-edit.HELP := Edit QSYS implementation qsys-edit.HELP = Edit QSYS implementation
##### QUARTUS ################################### ##### UBOOT / PRELOADER ################################################################################
QUARTUS_QPF := $(PROJECT).qpf .PHONY: preloader uboot
QUARTUS_QSF := $(PROJECT).qsf PRELOADER_DIR = $(BUILD_DIR)/software/preloader
QSYS_HPS_INST_NAME = hps_0
PRELOADER_HANDOFF = $(BUILD_QUARTUS_DIR)/hps_isw_handoff/$(QSYS_BASE)_$(QSYS_HPS_INST_NAME)/
PRELOADER_ID = $(PRELOADER_HANDOFF)/id
PRELOADER_IMG = $(PRELOADER_DIR)/preloader-mkpimage.bin
UBOOT_IMG = $(PRELOADER_DIR)/uboot-socfpga/u-boot.img
tcl: $(BUILD_QUARTUS_DIR)/$(PROJECT).qsf $(BUILD_QUARTUS_DIR)/$(PROJECT).qpf ## uboot script
@cd $(BUILD_QUARTUS_DIR) && for pin_assign_tcl_file in $$(find $(BUILD_DIR) -name '*_pin_assignments.tcl'); do \ #bootcmd=run mmcload; run fpgaload; run mmcboot
quartus_map $(QUARTUS_QPF); \ #fpga=0
echo "Applying $${pin_assign_tcl_file} to $(QUARTUS_QPF)..."; \ #fpgadata=0x2000000
quartus_sta -t $${pin_assign_tcl_file} $(QUARTUS_QPF); \ #fpgadatasize=2126D5
done #fpgaload=fatload mmc 0:1 0x2000000 $(PROJECT).rbf; fpga load 0 ${fpgadata} ${fi}
$(BUILD_QUARTUS_DIR)/output_files/sockit.sof quartus: tcl $(PRELOADER_DIR)/Makefile: $(PRELOADER_ID)
cd $(BUILD_QUARTUS_DIR) && quartus_sh --flow compile $(QUARTUS_QPF)
HELP_TARGETS += quartus
quartus.HELP := Geneate SOF bitfile
##### UBOOT / PRELOADER #########################
.PHONY: preloader
PRELOADER_DIR := $(BUILD_DIR)/software/preloader
QSYS_HPS_INST_NAME := hps_0
PRELOADER_HANDOFF := $(BUILD_QUARTUS_DIR)/hps_isw_handoff/$(QSYS_BASE)_$(QSYS_HPS_INST_NAME)/
PRELOADER_ID := $(PRELOADER_HANDOFF)/id
PRELOADER_DEPS := $(PRELOADER_ID) quartus
preloader $(PRELOADER_DIR)/Makefile:
mkdir -p $(PRELOADER_DIR) mkdir -p $(PRELOADER_DIR)
cd $(PRELOADER_DIR) && bsp-create-settings \ cd $(PRELOADER_DIR) && bsp-create-settings \
--type spl \ --type spl \
@ -79,6 +73,10 @@ preloader $(PRELOADER_DIR)/Makefile:
--preloader-settings-dir "$(PRELOADER_HANDOFF)" \ --preloader-settings-dir "$(PRELOADER_HANDOFF)" \
--settings settings.bsp \ --settings settings.bsp \
--set spl.boot.WATCHDOG_ENABLE false --set spl.boot.WATCHDOG_ENABLE false
@echo "PATCH MAKEFILE"
sed -i 's/mkpimage -o \$$\@ \$$< \$$< \$$< \$$</mkpimage -o \$$@ \$$</' $(PRELOADER_DIR)/Makefile
preloader: $(PRELOADER_DIR)/Makefile
make -C $(PRELOADER_DIR) make -C $(PRELOADER_DIR)
uboot: $(PRELOADER_DIR)/Makefile uboot: $(PRELOADER_DIR)/Makefile
@ -92,11 +90,11 @@ bsp-edit.HELP = Edit BSP settings file
preloader.HELP = Build SoC preloader preloader.HELP = Build SoC preloader
uboot.HELP = Build UBoot uboot.HELP = Build UBoot
##### Device Tree ############################### ##### Device Tree ######################################################################################
.PHONY: dtb dts .PHONY: dtb dts
DTS_BOARDINFO := $(TOP)/soc/soc_system_board_info.xml DTS_BOARDINFO = $(TOP)/soc/soc_system_board_info.xml
DEVICE_TREE_SOURCE := $(patsubst %.sopcinfo,%.dts,$(QSYS_SOPCINFO)) DEVICE_TREE_SOURCE = $(patsubst %.sopcinfo,%.dts,$(QSYS_SOPCINFO))
DEVICE_TREE_BLOB := $(patsubst %.dts,%.dtb,$(DEVICE_TREE_SOURCE)) DEVICE_TREE_BLOB = $(patsubst %.dts,%.dtb,$(DEVICE_TREE_SOURCE))
$(DEVICE_TREE_SOURCE): %.dts: %.sopcinfo $(DEVICE_TREE_SOURCE): %.dts: %.sopcinfo
sopc2dts --input $< --output $@ --board $(DTS_BOARDINFO) sopc2dts --input $< --output $@ --board $(DTS_BOARDINFO)
@ -108,33 +106,143 @@ dts: $(DEVICE_TREE_SOURCE)
dtb: $(DEVICE_TREE_BLOB) dtb: $(DEVICE_TREE_BLOB)
HELP_TARGETS += dts HELP_TARGETS += dts
dts.HELP := Generate a device tree for this qsys design (alpha) dts.HELP = Generate a device tree for this qsys design
HELP_TARGETS += dtb HELP_TARGETS += dtb
dtb.HELP := Generate a device tree blob for this qsys design (alpha) dtb.HELP = Generate a device tree blob for this qsys design
##### CONFIGURE BUILD ########################### ##### QUARTUS ##########################################################################################
.PHONY: quartus
QUARTUS_QPF = $(PROJECT).qpf
QUARTUS_QSF = $(PROJECT).qsf
SOURCE_SRC = $(shell for q in $(SOURCE_QIP); do for s in `[ -e $$q ] && grep "\[file" $$q | sed 's/.*\[file//' | cut -d'"' -f 2`; do echo `dirname $$q`/$$s; done; done)
QUARTUS_SOF = $(BUILD_QUARTUS_DIR)/output_files/sockit.sof
QUARTUS_RBF = $(BUILD_QUARTUS_DIR)/output_files/sockit.rbf
func_quartus_find_tcl = $(shell find $(1) -name '*_pin_assignments.tcl')
$(BUILD_QUARTUS_DIR)/$(PROJECT).tcl_patch_done: $(BUILD_QUARTUS_DIR)/$(PROJECT).qsf
@cd $(BUILD_QUARTUS_DIR) && for ptf in $(call func_quartus_find_tcl,$(BUILD_DIR)); do \
quartus_map $(QUARTUS_QPF); \
echo "Applying $$ptf to $(QUARTUS_QPF) ..."; \
quartus_sta -t $$ptf $(QUARTUS_QPF); \
done
@touch $(BUILD_QUARTUS_DIR)/$(PROJECT).tcl_patch_done
$(QUARTUS_SOF) $(PRELOADER_ID): $(BUILD_QUARTUS_DIR)/$(PROJECT).tcl_patch_done $(SOURCE_SRC)
cd $(BUILD_QUARTUS_DIR) && quartus_sh --flow compile $(QUARTUS_QPF)
$(QUARTUS_RBF): $(QUARTUS_SOF)
quartus_cpf -c $< $@
quartus: $(QUARTUS_RBF)
HELP_TARGETS += quartus
quartus.HELP = Geneate SOF bitfile
##### CONFIGURE BUILD ##################################################################################
.PHONY: config .PHONY: config
config $(BUILD_QUARTUS_DIR)/$(PROJECT).qsf:
$(BUILD_QUARTUS_DIR)/$(PROJECT).qsf: $(PROJECT).qsf_tmpl $(PROJECT).qpf_tmpl $(SOURCE_QIP)
mkdir -p $(BUILD_QUARTUS_DIR) mkdir -p $(BUILD_QUARTUS_DIR)
cp $(PROJECT).qpf_tmpl $(BUILD_QUARTUS_DIR)/$(PROJECT).qpf
cp $(PROJECT).qsf_tmpl $(BUILD_QUARTUS_DIR)/$(PROJECT).qsf cp $(PROJECT).qsf_tmpl $(BUILD_QUARTUS_DIR)/$(PROJECT).qsf
cp $(PROJECT).qpf_tmpl $(BUILD_QUARTUS_DIR)/$(PROJECT).qpf
for I in $(SOURCE_QIP); do \ for I in $(SOURCE_QIP); do \
echo "set_global_assignment -name QIP_FILE $$I" >> $(BUILD_QUARTUS_DIR)/$(PROJECT).qsf; \ echo "set_global_assignment -name QIP_FILE $$I" >> $(BUILD_QUARTUS_DIR)/$(PROJECT).qsf; \
done done
HELP_TARGETS += config config: $(BUILD_QUARTUS_DIR)/$(PROJECT).qsf
config.HELP := create build sandbox
##### HELP ###################################### HELP_TARGETS += config
config.HELP = create build sandbox
##### SDCARD PREPARATION ###############################################################################
.PHONY: sdcard sd_rootfs sd_kernel sd_preloader sd_prepare
SD_DEV ?= /dev/sdx
ifeq ($(origin SD_PREPARE), command line)
ifeq ($(SD_PREPARE), 1)
SD_DEPENDENCY += sd_prepare
endif
endif
ifeq ($(origin KERNEL), command line)
SD_DEPENDENCY += sd_kernel
endif
ifeq ($(origin ROOTFS), command line)
SD_DEPENDENCY += sd_rootfs
endif
ifeq ($(origin SD_PRELOADER), command line)
SD_DEPENDENCY += sd_preloader
endif
sd_rootfs: $(SD_DEV)2 $(ROOTFS)
sudo mount $(SD_DEV)2 /mnt
sudo tar --strip-components 1 -xf $(ROOTFS) -C /mnt
sudo umount /mnt
sync
sd_kernel: $(DEVICE_TREE_BLOB) $(QUARTUS_RBF) $(KERNEL) $(SD_DEV)1
sudo mkdosfs $(SD_DEV)1
sudo mount $(SD_DEV)1 /mnt
sudo cp $(KERNEL) /mnt/uImage
sudo cp $(DEVICE_TREE_BLOB) /mnt/$(PROJECT).dtb
sudo cp $(QUARTUS_RBF) /mnt/$(PROJECT).rbf
sudo umount /mnt
sync
sd_preloader: $(SD_DEV)3
sudo dd if=$(PRELOADER_IMG) of=$(SD_DEV)3 bs=64k seek=0
sudo dd if=$(UBOOT_IMG) of=/dev/sdx3 bs=64K seek=4
sd_prepare: $(SD_DEV)
@echo "DEV_BOARD: Bootsel jumpers = 101 (booting from SD)"
@echo "DEV_BOARD: MSEL jumpers = 00000 (enable the ARM to configure the FPGA)"
sudo dd if=/dev/zero of=$(SDCARD_DEV) bs=512 count=1
sudo partprobe $(SDCARD_DEV)
@for p in "n p 2 4096 +4496384 t 83" "n p 1 9000000 +20480K t 1 b" "n p 3 2048 +1024K t 3 a2a"; do \
unset CMD; \
for c in $$p; do \
CMD="$$CMD echo $$c;"; \
done; \
CMD="( $$CMD ) | $(SD_DEV)"; \
echo "CREATE PARTITION [$$p]" \
eval $$CMD; \
done
sdcard: $(SD_DEPENDENCY)
HELP_TARGETS += sdcard
sdcard.HELP = prepare sdcard (SD_DEV=/dev/sdc SD_PREPARE=1 KERNEL=uImage.bin ROOTFS=rootfs.tar.gz SD_PRELOADER=1)
##### BUILD EVERYTHING #################################################################################
.PHONY: show all clean
func_check_file = $(shell test -e $(1) && echo $(1) || echo "not build")
show:
@eval printf %.1s '={1..'"$${COLUMNS:-`tput cols`}"\}; echo
@echo "DATE ............. : $(shell date)"
@echo "QUARTUS SOF ...... : $(call func_check_file,$(QUARTUS_SOF))"
@echo "QUARTUS RBF ...... : $(call func_check_file,$(QUARTUS_RBF))"
@echo "PRELOADER ........ : $(call func_check_file,$(PRELOADER_IMG))"
@echo "UBOOT ............ : $(call func_check_file,$(UBOOT_IMG))"
@echo "DEVICE TREE BLOB . : $(call func_check_file,$(DEVICE_TREE_BLOB))"
@eval printf %.1s '={1..'"$${COLUMNS:-`tput cols`}"\}; echo
all: $(QUARTUS_RBF) preloader uboot dtb show
clean:
rm -rf $(BUILD_DIR)
HELP_TARGETS += all clean
all.HELP = execute all needed steps
clean.HELP = clean up build directory
##### HELP #############################################################################################
.PHONY: $(HELP_TARGETS_X) help .PHONY: $(HELP_TARGETS_X) help
HELP_TARGETS += help HELP_TARGETS += help
help.HELP := Displays this info (i.e. the available targets) help.HELP = Displays this info (i.e. the available targets)
help: help-header help-targets help: help-header help-targets
HELP_TARGETS_X := $(patsubst %,help-%,$(sort $(HELP_TARGETS))) HELP_TARGETS_X := $(patsubst %,help-%,$(sort $(HELP_TARGETS)))
help-targets: $(HELP_TARGETS_X) help-targets: $(HELP_TARGETS_X)
$(HELP_TARGETS_X): help-%: $(HELP_TARGETS_X): help-%:
@printf "\t%20s\t - %s\n" $* "$($*.HELP)" @printf "%20s | %s\n" $* "$($*.HELP)"
help-header: help-header:
@printf "\t%20s\t - %s\n" target description\n @printf "%20s | %s\n" target description
@printf "\t------------------------------------------------------------------------------\n" @eval printf %.1s '-{1..'"$${COLUMNS:-`tput cols`}"\}; echo