DS-5调试CYCLONE V(1)---hello world

1、从下图可以看到裸程序可以由preloader加载,所以要调试裸程序要做的第一件事是生成并编译一个preloader。


生成preloader的过程,很多资料可以查到。首先要使用qsys生成的配置文件,该配置文件放在quartus工程的hps_isw_handoff\som_hps_hps_som目录。

2、生成与编译一个preloader

1)、打开soc eds 16.1 shell command,并输入下面命令:

$bsp-editor

2)、选择file->new Bsp。

A、preloader需要知道HPS系统中有那些外围,以便它在启动阶段初始化他们。QSYS生成的硬配置,放在自己工程目录下面hps_isw_handoff\som_hps_hps_som目录。

B、去掉usr default locations。选择我们建立的一个工程目录册。比如我们放在

C、点OK后,进入下面图所示的配置页面。

3)、在main设置页面,我们只修改两个参数。

A、spl.boot下,关闭WATCHDOG_ENABLE。这样会阻止系统超时重启。这样做的目的是在烧写裸程序时。其它任何操作系统都会定时写看门狗定时。

B、打开fat支持。这样可以使preloader从文件系统加载第二段启动程序。默认的是u-boot.img,我们这里保持不变。

C、点generate按键。然后退出BSP-EDITOR。

4)、在soc eds 16.1 shell command,切换目录到E:\altera\firstdemo,然后执行make.这样就会在firedemo目录生成preloader-mkpimage.bin.这个是可以烧写到flash中,供上电启动使用的。我们目前调试需要使用uboot-socfpga\spl\u-boot-spl文件供调试器加载使用。

3、建立C工程


altera提供了hwlib库,方便对CPU进行编译。如果我们想在ds-5中使用该库,需要做如下工作:

定义符号:soc_cv_av

添加头文件路径:{quartus_install_dir}\16.1\embedded\ip\altera\hps\altera_hps\hwlib\include

                           {quartus_install_dir}\16.1\embedded\ip\altera\hps\altera_hps\hwlib\include\soc_cv_av



由于我们不使用操作系统,目前我需要一个link script,来在DDR3中布局裸程序。altera提供了许多link script,我们可以使用

{quartus_install_dir}\16.1\embedded\host_tools\mentor\gnu\arm\baremetal\arm-altera-eabi\lib\cycloneV-dk-oc-ram-hosted.ld,这种带hosted的LINK SCRIPT是带有主机功能的,比如printf可以向terminal输出信息。本例使用一个hello world工程列举其调试过程,所以带hosted的脚本是非常适用的。


裸程序在上电时并不能立刻运行。HPS必须的先执行preloader。Preloader执行终止前跳到用户软件。现在就是跳到裸程序的开始。直为了完成这个,我们使用DS-5 DUBUG SCRIPT来执导DS-5如果加载我们的裸程序到HPS内存中去。DEBUGGER脚本将会加载并执行preloader,然后跳到裸程序执行。

4、创建debug脚本

在工程目录下创建一个ds-5脚本文件debug_setup.ds。该脚本告诉debugger加载preloader然后加载我们的裸程序。通过在preloader执行最后一次一个函数之后,转移控制权到下一个阶段前旋转一个断点完成的。Spl_boot_device负责选择下一阶段启动介质,并跑到它的地址。对于裸程序,我们不想启动过程继续。相反我们希望加载我们的裸程序,并跳舞到它的地址。

# Reset and stop the system.
stop
wait 30s
reset system
wait 30s




# Delete all breakpoints.
delete breakpoints


# Disable semihosting
set semihosting enabled false


# Load the preloader.
loadfile "$sdir/../uboot-socfpga/spl/u-boot-spl" 0x0 对应自己的地址。$sdir是指目前的C工程目录。


# Enable semihosting to allow printing even if you don't have a uart module
# available.
set semihosting enabled true


# Set a breakpoint at the "spl_boot_device()" function. This function is the
# last step of the preloader. It looks for a boot device (qspi flash, sdcard,
# fpga), and jumps to that address. For our bare-metal programs, we don't want
# to use any boot device, but want to run our own program, so we want the
# processor to stop here. Then, we will modify its execution to make it run our
# program.
tbreak spl_boot_device




# Set the PC register to the entry point address previously recorded by the
# "load" or "loadfile" command and start running the target.
run




# Instruct the debugger to wait until either the application completes or a
# breakpoint is hit. In our case, it will hit the breakpoint.
wait




# Load our bare-metal program.
loadfile "$sdir/Debug/baremetal.axf"




# Set a breakpoint at our program's "main()" function.
tbreak main




# Start running the target.
run




# wait at main().
wait

5、建立debug链接





这一步要添建立的ds文件。


6、建立一个c文件写一个helloworld程序。

#include "hwlib.h"
int main() {
printf("hello world\n");
return 0;
}

然后进入调试器。如下图所示:




这里我们可以看到,程序停在了main函数。我们可以使用F6,F5,F7,F8等快捷键进行调试。我们使用F6执行完程序后,会在terminal输出hello world.




ds-5提供了强大的调试工具,可以查看许多CPU的寄存器与调用栈等,如图所示.


猜你喜欢

转载自blog.csdn.net/benjorsun/article/details/79173790