Browse Source

dubhe: openocd: Enable openocd in default build

Enable openocd in EXTRA_IMAGEDEPENDS, thus enabling openocd to be built in
eSDK. Thus, user will not need to manually download a RISC-V OpenOCD before
proceeding to flash or debug via FPGA.

Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
Jun Yuan Tan 1 year ago
parent
commit
3f980a7263

+ 6 - 0
conf/layer.conf

@@ -3,6 +3,12 @@ BBPATH =. "${LAYERDIR}:"
 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
             ${LAYERDIR}/recipes-*/*/*.bbappend"
 
+BBFILES_DYNAMIC += " \
+    openembedded-layer:${LAYERDIR}/dynamic-layers/openembedded-layer/*/*/*.bb \
+    openembedded-layer:${LAYERDIR}/dynamic-layers/openembedded-layer/*/*/*.bbappend \
+    \
+"
+
 BBFILE_COLLECTIONS += "meta-starfive"
 BBFILE_PATTERN_meta-starfive = "^${LAYERDIR}/"
 BBFILE_PRIORITY_meta-starfive = "7"

+ 1 - 1
conf/machine/starfive-dubhe.conf

@@ -5,7 +5,7 @@
 
 LLVMVERSION = "14.0.0"
 CLANGSDK = "1"
-EXTRA_IMAGEDEPENDS:append = " llvm file-native rpm-native popt-native"
+EXTRA_IMAGEDEPENDS:append = " llvm file-native rpm-native popt-native openocd-native"
 EXTRA_IMAGE_FEATURES:append = " dbg-pkgs tools-profile"
 
 PACKAGE_DEBUG_SPLIT_STYLE = 'debug-file-directory'

+ 38 - 0
dynamic-layers/openembedded-layer/recipes-devtools/openocd/openocd/Dubhe_FPGA_openocd.patch

@@ -0,0 +1,38 @@
+diff --git a/src/flash/nor/fespi.c b/src/flash/nor/fespi.c
+index b2b3f97df..215734bae 100644
+--- a/src/flash/nor/fespi.c
++++ b/src/flash/nor/fespi.c
+@@ -138,6 +138,8 @@ static const struct fespi_target target_devices[] = {
+ 	/* name,   tap_idcode, ctrl_base */
+ 	{ "Freedom E310-G000 SPI Flash", 0x10e31913, 0x10014000 },
+ 	{ "Freedom E310-G002 SPI Flash", 0x20000913, 0x10014000 },
++	{ "Dubhe FPGA SPI Flash",        0x00000913, 0x10010000 },
++	{ "Dubhe FPGA SPI Flash 2",      0x00000cfd, 0x10010000 },
+ 	{ NULL, 0, 0 }
+ };
+ 
+@@ -826,6 +828,11 @@ static int fespi_probe(struct flash_bank *bank)
+ 
+ 	bank->sectors = sectors;
+ 	fespi_info->probed = true;
++
++	/* Set to 4 bytes addressing for XIP */
++	if (fespi_write_reg(bank, FESPI_REG_FFMT, 0x00130009) != ERROR_OK)
++		return ERROR_FAIL;
++
+ 	return ERROR_OK;
+ }
+ 
+diff --git a/src/flash/nor/spi.c b/src/flash/nor/spi.c
+index 627bb416d..34ad5bdcb 100644
+--- a/src/flash/nor/spi.c
++++ b/src/flash/nor/spi.c
+@@ -89,6 +89,7 @@ const struct flash_device flash_devices[] = {
+ 	FLASH_ID("mac 25r3235f",        0x03, 0x00, 0x02, 0xd8, 0xc7, 0x001628c2, 0x100, 0x10000, 0x400000),
+ 	FLASH_ID("mac 25r6435f",        0x03, 0x00, 0x02, 0xd8, 0xc7, 0x001728c2, 0x100, 0x10000, 0x800000),
+ 	FLASH_ID("mac 25u1635e",        0x03, 0xeb, 0x02, 0x20, 0xc7, 0x003525c2, 0x100, 0x1000,  0x100000),
++	FLASH_ID("mac 66u1g45g",        0x13, 0xec, 0x12, 0xdc, 0xc7, 0x003b25c2, 0x100, 0x10000, 0x8000000),
+ 	FLASH_ID("micron n25q032",      0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0016ba20, 0x100, 0x10000, 0x400000),
+ 	FLASH_ID("micron n25q064",      0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0017ba20, 0x100, 0x10000, 0x800000),
+ 	FLASH_ID("micron n25q128",      0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0018ba20, 0x100, 0x10000, 0x1000000),
+

+ 33 - 0
dynamic-layers/openembedded-layer/recipes-devtools/openocd/openocd/olimex-openocd_s5.cfg

@@ -0,0 +1,33 @@
+adapter driver ftdi
+ftdi device_desc "Olimex OpenOCD JTAG ARM-USB-TINY-H"
+ftdi vid_pid 0x15ba 0x002a
+#Uncomment line below and change to your machine's Dubhe Olimex JTAG serial number if your FPGA is connecting to more than 1 daughter card
+#ftdi serial "OLDBAA13"
+
+transport select jtag
+
+adapter speed 20000
+
+ftdi layout_init 0x0808 0x0a1b
+ftdi layout_signal nSRST -oe 0x0200
+ftdi layout_signal nTRST -data 0x0100 -oe 0x0100
+ftdi layout_signal LED -data 0x0800
+
+
+
+
+
+set _CHIPNAME riscv
+jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x00000cfd
+ 
+set _TARGETNAME $_CHIPNAME.cpu
+target create $_TARGETNAME riscv -chain-position $_TARGETNAME
+
+riscv set_command_timeout_sec 20
+
+#gdb_report_data_abort enable
+ 
+init
+halt
+
+

+ 30 - 0
dynamic-layers/openembedded-layer/recipes-devtools/openocd/openocd/olimex_flash_write.cfg

@@ -0,0 +1,30 @@
+adapter driver ftdi
+ftdi device_desc "Olimex OpenOCD JTAG ARM-USB-TINY-H"
+ftdi vid_pid 0x15ba 0x002a
+
+transport select jtag
+
+adapter speed 20000
+
+ftdi layout_init 0x0808 0x0a1b
+ftdi layout_signal nSRST -oe 0x0200
+ftdi layout_signal nTRST -data 0x0100 -oe 0x0100
+ftdi layout_signal LED -data 0x0800
+
+set _CHIPNAME riscv
+jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x00000cfd
+ 
+set _TARGETNAME $_CHIPNAME.cpu
+target create $_TARGETNAME riscv -chain-position $_TARGETNAME
+
+echo "configure work area .................."
+$_TARGETNAME configure -work-area-phys 0x80000000 -work-area-size 0x80000000 -work-area-backup 0
+echo "configure work area complete.................."
+
+echo "configure flash bank.................."
+flash bank onboard_spi_flash fespi 0x20000000 0 0 0 $_TARGETNAME 0x10010000 
+echo "configure flash bank complete .................."
+
+init
+reset init
+halt

+ 28 - 0
dynamic-layers/openembedded-layer/recipes-devtools/openocd/openocd_riscv.bbappend

@@ -0,0 +1,28 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/openocd:"
+
+LIC_FILES_CHKSUM = "file://COPYING;md5=599d2d1ee7fc84c0467b3d19801db870"
+
+PV = "riscv22"
+
+SRC_URI = " \
+    git://github.com/riscv/riscv-openocd.git;protocol=https;branch=riscv;name=openocd \
+    git://repo.or.cz/r/git2cl.git;protocol=http;destsuffix=tools/git2cl;name=git2cl;branch=master \
+    git://github.com/msteveb/jimtcl.git;protocol=https;branch=master;name=jimtcl;destsuffix=git/jimtcl \
+    git://repo.or.cz/r/libjaylink.git;protocol=http;destsuffix=git/src/jtag/drivers/libjaylink;name=libjaylink;branch=master \
+    file://Dubhe_FPGA_openocd.patch \
+    file://olimex-openocd_s5.cfg \
+    file://olimex_flash_write.cfg \
+"
+
+SRCREV_openocd = "a037b20f2e015859327ab37588792386c4fc942f"
+SRCREV_jimtcl = "70b007b63669a709b0e8aef34a22658047815cc2"
+
+EXTRA_OECONF = "--enable-ftdi"
+
+inherit deploy
+do_deploy(){
+	install -m 755 ${WORKDIR}/olimex-openocd_s5.cfg ${DEPLOYDIR}/
+	install -m 755 ${WORKDIR}/olimex_flash_write.cfg ${DEPLOYDIR}/
+}
+
+addtask deploy before do_build after do_install