【Xilinx-Petalinux學習】-08-OpenAMP系統實現

openAMP系統實現。html

一個核跑Linux,一個核裸跑。     ----->  已經實現。linux

一個核跑Linux,一個核跑UCOS   ----->  還未實現。bash

Micrium的ucos OpenAMP例子與Xilinx的例子框架結構有些不一樣,嘗試修改共享內存基地址、改變程序結構,還未成功。先放一放,之後再來實驗,或者等Micrium給出官方的例程~~~~TT架構

 

step1: openAMP框架介紹app

參考文檔:ug1186框架

 

step2: 建立standalone應用工程
dom

從Vivado中Export Hardwre(Include bitstream)後,點擊Launch SDK打開Xilinx SDK開發工具。ide

這一次咱們須要實如今裸機上運行AMP架構的程序。工具

首先建立BSP:File -> New -> Board Support Package開發工具

對話框的選項按下面配置:

Hardware Platform :選擇從vivado中輸出的平臺名稱
CPU :選擇ps7_cortexa9_1,(即第二個arm核,第一個用來運行Linux和做爲AMP的主機)
BSP OS platform :選擇standalone

點擊Finish按鍵,進入BSP的詳細配置界面:

 

Overview,庫支持中選中xilopenamp
standalone選項,stdin和stdout須要選擇與Linux系統(ps_uart1)不一樣的串口
drivers->ps7_cortexa9_1,修改 extra_compiler_flags的值,加入「-DUSE_AMP=1」

#-DUSE_AMP=1說明
#Add -DUSEAMP=1 to the extra_compiler_flags to disable the definition of
#low-level read, write, and open operations. 
#This also disables the vector table location in
#the tightly-coupled memory (TCM).

點擊OK,BSP就配置完成了,等待Xilinx SDK自動生成各類文件。

 

接着,須要依賴這個BSP去建立OpenAMP的應用程序。

針對裸機standalone,軟件內提供了三個例子:echo-test,matrix multiplication Demo,RPC Demo。以下圖:

咱們直接調用例子,生成三個OpenAMP應用程序。編譯後,咱們就可以在每一個應用工程的Debug文件夾下,找到須要的裸機elf可執行文件。

編譯時候有一些警告,官網查到說不用理會這些。警告有:

in expansion of macro 'XScuGic_EnableIntr'
in expansion of macro 'XScuGic_DisableIntr'
implicit declaration of function 'Xil_Out32' [-Wimplicit-function-declaration]
implicit declaration of function 'Xil_In32' [-Wimplicit-function-declaration]

 

我下載的2015.4的PetaLinux中,默認是沒有OpenAMP的例子的。

所以我從別的地方拷貝了一些例子來用。

網址:https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-design-tools/2015-4.html

在裏面下載Avnet-Digilent-ZedBoard BSP安裝包,安裝後在 ./componets/apps 和 ./componets/modules 文件夾下會有我須要用到了三個APP和兩個Module

從裏面直接複製如下文件夾,並粘貼到咱們的PetaLinux工程相同的目錄下:

/componets/apps/echo_test
/componets/apps/mat_mul_demo
/componets/apps/proxy_app
/componets/modules/rpmsg_proxy_dev_driver
/componets/modules/rpmsg_usr_dev_driver

複製完成後,每一個app文件夾下還有一個「data」文件夾,這個就是咱們以後OpenAMP系統中第二個內核須要加載的可執行代碼。分別是:

image_echo_test , image_matrix_multiply , image_rpc_demo

這三個代碼是基於ZedBoard,用FreeRTOS實現的三個例子。試驗過,它們也可以在個人系統中直接使用,能夠試試。

 

咱們如今講咱們本身經過Xilinx SDK編譯出的三個elf文件複製出來,分別命名爲image_echo_test , image_matrix_multiply , image_rpc_demo,並複製到各自app中的data文件夾中去(提早刪除或是備份原有的文件)。

這樣,針對OpenAMP的準備工做就作好了,開始進行PetaLinux的配置。

 

step3: PetaLinux中加入OpenAMP的支持

硬件平臺的內存爲4Gb,即512MB。咱們將低256MB做爲裸機的內存,高256MB則做爲Linux的內存。

下面來進行配置。

首先是地址空間配置:

petalinux-config

#在選項中配置Linux內核基地址爲0x10000000
Subsystem AUTO Hardware Settings --->
	Memory Settings --->
		(0x10000000) kernel base address
u-boot Configuration --->
	(0x11000000) netboot offset

kernel配置:

petalinux-config -c kernel

#手動配置
[*] Enable loadable module support --->
Device Drivers --->
	Generic Driver Options --->
		<*> Userspace firmware loading support
	Remoteproc drivers --->
		<M> Support ZYNQ remoteproc
		<M> Support Microblaze remoteproc #can be unselected
	Rpmsg drivers --->
		<M> An rpmsg server sample
Kernel Features--->
	Memory split (...)--->
		(x) 2G/2G user/kernel split
	[*] High Memory Support--->

rootfs配置:

petalinux-config -c rootfs

#手動配置
Apps --->
	[*] echo_test --->
	[*] mat_mul_demo --->
	[*] proxy_app --->
Modules --->
	[*] rpmsg_proxy_dev_driver --->
	[*] rpmsg_user_dev_driver --->

最後是修改設備樹:

#建立設備樹文件
gedit ./subsystem/linux/configs/device-tree/openamp-overlay.dtsi
#加入如下文本信息:
/ {
	amba {
		remoteproc0: remoteproc@0 {
			compatible = "xlnx,zynq_remoteproc";
			reg = < 0x00000000 0x10000000 >;
			firmware = "firmware";
			vring0 = <15>;
			vring1 = <14>;
		};
	};
};
#保存並關閉

#添加到openamp-overlay.dtsi的引用
gedit ./subsystem/linux/configs/device-tree/system-top.dtsi
#在最後面加入下面的文本
/include/ "openamp-overlay.dtsi"
#保存並關閉

最後進行編譯:

petalinux-build

 

生成BOOT.bin,並拷貝它和image.ub兩個文件,更新咱們硬件平臺上的文件。從新啓動運行!

 

step4: OpenAMP程序測試

echo_test測試:

#安裝
modprobe zynq_remoteproc firmware=image_echo_test
modprobe rpmsg_user_dev_driver
#運行
echo_test
#卸載
modprobe -r rpmsg_user_dev_driver
modprobe -r zynq_remoteproc

mat_mul_demo測試:

#安裝
modprobe zynq_remoteproc firmware=image_matrix_multiply
modprobe rpmsg_user_dev_driver
#運行
mat_mul_demo
#卸載
modprobe -r rpmsg_user_dev_driver
modprobe -r zynq_remoteproc

proxy_app測試:

#運行:
proxy_app -m zynq_remoteproc

 

出現的問題:

問題一:執行echo_test時,出現錯誤:Failed to open rpmsg file /dev/rpmsg0.: No such file or directory

網址:https://forums.xilinx.com/t5/OpenAMP/Failed-to-open-rmpsg-file-in-open-amp/td-p/672640

緣由:沒有包含openamp的設備樹信息

解決:在system-top.dts文件最後面加入

 /include/ "openamp-overlay.dtsi"

問題二:加載指定目錄的image時,出現錯誤remoteproc0: Direct firmware load for /lib/firmware/test.elf failed with error -2

網址:https://forums.xilinx.com/t5/OpenAMP/remoteproc-don-t-load-pre-built-test-apps-when-specifing-full/td-p/714886

解決:須要使用相對路徑

modprobe zynq_remoteproc firmware=../../myrootdir/test.elf

 

測試程序log:

echo_test:

root@ifc_petalinux:~# modprobe zynq_remoteproc firmware=image_echo_test
CPU1: shutdown
 remoteproc0: 0.remoteproc is available
 remoteproc0: Note: remoteproc is still under development and considered experimental.
 remoteproc0: THE BINARY FORMAT IS NOT YET FINALIZED, and backward compatibility isn't yet guaranteed.
root@ifc_petalinux:~#  remoteproc0: registered virtio0 (type 7)
 remoteproc0: powering up 0.remoteproc
 remoteproc0: Booting fw image image_echo_test, size 164688
root@ifc_petalinux:~# modprobe zynq_remoteproc firmware=image_echo_test remoteproc0: remote processor 0.remoteproc is now up
virtio_rpmsg_bus virtio0: rpmsg host is online
virtio_rpmsg_bus virtio0: creating channel rpmsg-openamp-demo-channel addr 0x1
root@ifc_petalinux:~# modprobe rpmsg_user_dev_driver
rpmsg_proxy_dev_rpmsg rpmsg0: rpmsg_user_dev_rpmsg_drv_probe
rpmsg_proxy_dev_rpmsg rpmsg0: Sent init_msg to target 0x0.
rpmsg_proxy_dev_rpmsg rpmsg0: new channel: 0x400 -> 0x1!
root@ifc_petalinux:~# echo_test 

 Echo test start 

 Open rpmsg dev! 

 Query internal info .. 
 rpmsg kernel fifo size = 2048 
 rpmsg kernel fifo free space = 2048 

 **************************************** 
 Please enter command and press enter key
 **************************************** 
 1 - Send data to remote core, retrieve the echo and validate its integrity .. 
 2 - Quit this application .. 
 CMD>1

 sending payload number 0 of size 9 
echo test: sent : 9
 received payload number 0 of size 16 

 sending payload number 2 of size 10 
echo test: sent : 10
 received payload number 2 of size 16 

 sending payload number 3 of size 11 
echo test: sent : 11
 received payload number 3 of size 16 

~~~~~~~~~~~~
 sending payload number 470 of size 478 
echo test: sent : 478
 received payload number 470 of size 480 

 sending payload number 471 of size 479 
echo test: sent : 479
 received payload number 471 of size 480 

 **************************************

 Test Results: Error count = 0

 **************************************

 **************************************** 
 Please enter command and press enter key
 **************************************** 
 1 - Send data to remote core, retrieve the echo and validate its integrity .. 
 2 - Quit this application .. 
 CMD>2
virtio_rpmsg_bus virtio0: destroying channel rpmsg-openamp-demo-channel addr 0x1
rpmsg_proxy_dev_rpmsg rpmsg0: rpmsg_user_dev_rpmsg_drv_remove

 Quitting application .. 
 Echo test end 
root@ifc_petalinux:~# modprobe -r rpmsg_user_dev_driver
 remoteproc0: stopped remote processor 0.remoteproc
root@ifc_petalinux:~# modprobe -r zynq_remoteproc
zynq_remoteproc 0.remoteproc: zynq_remoteproc_remove
zynq_remoteproc 0.remoteproc: Deleting the irq_list
 remoteproc0: releasing 0.remoteproc
root@ifc_petalinux:~#

mat_mul_demo:

root@ifc_petalinux:~# modprobe zynq_remoteproc firmware=image_matrix_multiply
CPU1: shutdown
 remoteproc0: 0.remoteproc is available
 remoteproc0: Note: remoteproc is still under development and considered experimental.
 remoteproc0: THE BINARY FORMAT IS NOT YET FINALIZED, and backward compatibility isn't yet guaranteed.
root@ifc_petalinux:~#  remoteproc0: registered virtio0 (type 7)
 remoteproc0: powering up 0.remoteproc
 remoteproc0: Booting fw image image_matrix_multiply, size 164688
 remoteproc0: remote processor 0.remoteproc is now up
virtio_rpmsg_bus virtio0: rpmsg host is online
virtio_rpmsg_bus virtio0: creating channel rpmsg-openamp-demo-channel addr 0x1

root@ifc_petalinux:~# modprobe rpmsg_user_dev_driver
rpmsg_proxy_dev_rpmsg rpmsg0: rpmsg_user_dev_rpmsg_drv_probe
rpmsg_proxy_dev_rpmsg rpmsg0: Sent init_msg to target 0x0.
rpmsg_proxy_dev_rpmsg rpmsg0: new channel: 0x400 -> 0x1!
root@ifc_petalinux:~# mat_mul_demo 

 Matrix multiplication demo start 

 Open rpmsg dev! 

 Query internal info .. 
 rpmsg kernel fifo size = 2048 
 rpmsg kernel fifo free space = 2048 

 Creating ui_thread and compute_thread ... 

 **************************************** 
 Please enter command and press enter key
 **************************************** 
 1 - Generates random 6x6 matrices and transmits them to remote core over rpmsg .. 
 2 - Quit this application .. 
 CMD>1

 Compute thread unblocked .. 
 The compute thread is now blocking ona read() from rpmsg device 

 Generating random matrices now ... 
 
 Master : Linux : Input matrix 0 

 4  0  3  5  9  6 
 7  1  6  4  1  4 
 2  9  4  4  7  4 
 8  6  4  3  7  2 
 5  4  0  4  9  0 
 1  5  2  4  0  2 
 
 Master : Linux : Input matrix 1 

 2  9  5  0  4  6 
 5  8  5  1  4  4 
 7  2  0  2  7  0 
 6  3  4  6  9  5 
 9  0  0  1  6  0 
 5  0  2  0  3  6 

 Writing generated matrices to rpmsg rpmsg device, 296 bytes written .. 

 Received results! - 148 bytes from rpmsg device (transmitted from remote context) 
 
 Master : Linux : Printing results 
 170  57  52  45  154  85 
 114  95  64  38  128  90 
 184  110  79  48  162  92 
 165  137  86  39  159  99 
 135  89  61  37  126  66 
 75  65  50  33  80  58 

 **************************************** 
 Please enter command and press enter key
 **************************************** 
 1 - Generates random 6x6 matrices and transmits them to remote core over rpmsg .. 
 2 - Quit this application .. 
 CMD>2

 Quitting application .. 
virtio_rpmsg_bus virtio0: destroying channel rpmsg-openamp-demo-channel addr 0x1

rpmsg_proxy_dev_rpmsg rpmsg0: rpmsg_user_dev_rpmsg_drv_remove

 Quitting application .. 
 Matrix multiply application end 
root@ifc_petalinux:~# modprobe -r rpmsg_user_dev_driver
 remoteproc0: stopped remote processor 0.remoteproc
root@ifc_petalinux:~# modprobe -r zynq_remoteproc
zynq_remoteproc 0.remoteproc: zynq_remoteproc_remove
zynq_remoteproc 0.remoteproc: Deleting the irq_list
 remoteproc0: releasing 0.remoteproc
root@ifc_petalinux:~# 

proxy_app:

root@ifc_petalinux:~# proxy_app -m zynq_remoteproc

Master>Loading remote firmware
CPU1: shutdown
 remoteproc0: 0.remoteproc is available
 remoteproc0: Note: remoteproc is still under development and considered experimental.
 remoteproc0: THE BINARY FORMAT IS NOT YET FINALIZED, and backward compatibility isn't yet guaranteed.

Master>Create rpmsg proxy device

Master>Opening rpmsg proxy device
 remoteproc0: powering up 0.remoteproc
 remoteproc0: Booting fw image image_rpc_demo, size 181072
 remoteproc0: remote processor 0.remoteproc is now up
virtio_rpmsg_bus virtio0: rpmsg host is online
 remoteproc0: registered virtio0 (type 7)
virtio_rpmsg_bus virtio0: creating channel rpmsg-openamp-demo-channel addr 0x1
rpmsg_proxy_dev_rpmsg rpmsg0: rpmsg_proxy_dev_rpmsg_drv_probe
rpmsg_proxy_dev_rpmsg rpmsg0: Sent init_msg to target 0x1.
rpmsg_proxy_dev_rpmsg rpmsg0: new channel: 0x400 -> 0x1!
rpmsg_dev_open

Master>RPC service started !!

Remote>Baremetal Remote Procedure Call (RPC) Demonstration

Remote>***************************************************

Remote>Rpmsg based retargetting to proxy initialized..

Remote>FileIO demo ..

Remote>Creating a file on master and writing to it..

Remote>Opened file 'remote.file' with fd = 4

Remote>Wrote to fd = 4, size = 45, content = This is a test string being written to file..

Remote>Closed fd = 4

Remote>Reading a file on master and displaying its contents..

Remote>Opened file 'remote.file' with fd = 4

Remote>Read from fd = 4, size = 45, printing contents below .. This is a test string being written to file..


Remote>Closed fd = 4

Remote>Remote firmware using scanf and printf ..

Remote>Scanning user input from master..

Remote>Enter name
vacajk

Remote>Enter age
22

Remote>Enter value for pi
11.11

Remote>User name = 'vacajk'

Remote>User age = '22'

Remote>User entered value of pi = '11.110000'

Remote>Repeat demo ? (enter yes or no) 
no

Remote>RPC retargetting quitting ...

Master>RPC service exivirtio_rpmsg_bus virtio0: destroying channel rpmsg-openamp-demo-channel addr 0x1
ting !!
Master> sending shutdown signal.
rpmsg_proxy_dev_rpmsg rpmsg0: rpmsg_proxy_dev_rpmsg_drv_remove
 remoteproc0: stopped remote processor 0.remoteproc
zynq_remoteproc 0.remoteproc: zynq_remoteproc_remove
zynq_remoteproc 0.remoteproc: Deleting the irq_list
 remoteproc0: releasing 0.remoteproc
root@ifc_petalinux:~# 
相關文章
相關標籤/搜索