一、在NIOS II EDS打开“Flash Programmer”,当然也可直接使用shell脚本。如图1-1所示:
图1-1
二、File->New->-"Get flash programmer system detail fromBSPSettings File" or "Get flash programmer system detail fromSOPCSettings File",这里使用SOPC。如图2-1所示
图2-1
三、添加FPGA硬件配置文件(.sof)和nios可执行链接文件(.elf),如图3-1所示
图3-1
其中:
1、为SOPC中EPCS控制器起始地址为0x1005000;
2、为EPCS控制器ROM大小(ALTERA 在提供的BSP已提供EPCS的API访问接口);
3、FPGA硬件配置文件(.sof)的偏移地址,本例程无偏移;
4、NIOS可执行链接文件(.elf)的存储直接跟在硬件配置信息之后;
5、.sof/elf文件转换为.flash文件的shell脚本命令
“sof2flash --input="I:../output_files/project_name.sof" --output="I:../flash/project_name_sof_epcs.flash" --epcs --verbose”;
"elf2flash --input="I:../project_name_epcs.elf" --output="I:../project_name_epcs.flash" --epcs --after="I:../flash/project_name_elf_epcs.flash" --verbose ";简单、粗暴、明了
6、下载.flash文件的shell脚本命令
“nios2-flash-programmer "I:../flash/project_name_sof_epcs.flash" --base=0x1005000 --epcs --sidp=0x1006000 --id=0x1 --timestamp=1428805264 --device=1 --instance=0 '--cable=USB-Blaster on localhost [USB-0]' --program --verbose”
“nios2-flash-programmer "I:../flash/project_name_sof_epcs.flash" --base=0x1005000 --epcs --sidp=0x1006000 --id=0x1 --timestamp=1428805264 --device=1 --instance=0 '--cable=USB-Blaster on localhost [USB-0]' --program --verbose”;
base为EPCS控制器基址,sidp为system_id基址,id为SOPC文件中system_id设的值,后面为时间戳,器件以及usb-blaster信息;
7、下载开始。
四、“prossing”进程栏中出现“Leaving Target Processor Paused”,即.flash文件已经下载到EPCS fash中,如图4-1所示
图4-1
以下为下载过程中的shell基本命令:
Info: Info: *******************************************************************
Info: Info: Running Quartus II 32-bit Convert_programming_file 运行quartus文件转换工具,选择EPCS器件以及转换为pof(programmer object file)文件为什么???
Info: Info: Command: quartus_cpf --no_banner --convert --device=EPCS128 --option=I:../flash/project_name_sof_epcs.opt I:../seg7top.sof I:../flash/project_name_sof_epcs.pof
Info: Info (210033): Memory Map File I:../flash/project_name_sof_epcs.map contains memory usage information for file I:../flash/project_name_sof_epcs.pof
Info: Info: Quartus II 32-bit Convert_programming_file was successful. 0 errors, 0 warnings
Info: Info: Peak virtual memory: 170 megabytes
Info: Info: Processing ended: Sun Apr 12 22:02:53 2015
Info: Info: Elapsed time: 00:00:08
Info: Info: Total CPU time (on all processors): 00:00:03
Info: Info: *******************************************************************
Info: Info: Running Quartus II 32-bit Convert_programming_file运行quartus文件转换工具,选择EPCS器件以及转换为pof(programmer object file)文件为什么???
Info: Info: Command: quartus_cpf --no_banner --convert I:../flash/project_name_elf_epcs.pof I:../flash/project_name_elf_epcs.rpd
Info: Info: Quartus II 32-bit Convert_programming_file was successful. 0 errors, 0 warnings
Info: Info: Peak virtual memory: 166 megabytes
Info: Info: Processing ended: Sun Apr 12 22:02:58 2015
Info: Info: Elapsed time: 00:00:04
Info: Info: Total CPU time (on all processors): 00:00:03
Info: Using cable "USB-Blaster [USB-0]", device 1, instance 0x00
Info: Resetting and pausing target processor: OK
Info: Reading System ID at address 0x01006000: verified 读取system_id
Info:
Info: : Checksumming existing contents 对扇区0、1存在内容进行校验和计算
Info:
Info: 00000000 : Verifying existing contents 64KB PER Block对于EPCS16
Info:
Info: 00010000 : Verifying existing contents
Info:
Info: 00000000 : Reading existing contents
Info:
Info: 00010000 : Reading existing contents
Info:
Info: Checksummed/read 50kB in 2.3s 两个扇区中共有数据50KB
Info:
Info: 00000000 ( 0%): Erasing
Info:
Info: 00010000 (50%): Erasing
Info:
Info: Erased 128kB in 1.2s (106.6kB/s) 擦除两个扇区
Info:
Info: 00000000 ( 0%): Programming
Info:
Info: 00010000 (50%): Programming
Info:
Info: Programmed 79KB +49KB in 13.1s (9.7KB/s) 下载.flash文件 (.sof)
Info: Did not attempt to verify device contents
Info: Leaving target processor paused
Info: Using cable "USB-Blaster [USB-0]", device 1, instance 0x00
Info: Resetting and pausing target processor: OK
Info: Reading System ID at address 0x01006000: verified
Info:
Info: : Checksumming existing contents 对扇区1、2存在内容进行校验和计算
Info:
Info: 00010000 : Verifying existing contents
Info:
Info: 00020000 : Verifying existing contents
Info:
Info: 00010000 : Reading existing contents
Info:
Info: 00020000 : Reading existing contents
Info:
Info: Checksummed/read 66kB in 2.8s
Info:
Info: 00010000 ( 0%): Erasing
Info:
Info: 00020000 (50%): Erasing
Info:
Info: Erased 128kB in 6.7s (19.1kB/s) 擦除两个扇区
Info:
Info: 00010000 ( 0%): Programming
Info:
Info: 00020000 (50%): Programming
Info:
Info: Programmed 63KB +65KB in 5.2s (24.6KB/s) 下载.flash文件 (.elf)
Info: Did not attempt to verify device contents
Info: Leaving target processor paused
也许会有人问?为什么会有连续的两次两个扇区的校验,擦除,下载呢?
因为在选择.sof和.elf文件的页面中,.sof文件直接从EPCS flash的0x0地址存储的,.sof的大小存储到两个扇区中(不满两个),那么在第二个扇区中还有空闲位置,另.elf文件的存储直接跟在.elf文件后面,所以.elf也是跨扇区存储的。NIOS在BSP中提供的API接口对于EPCS的写操作有两种:非数据保护和数据保护写操作,前者比较任性,误操作的话,容易造成数据破坏,而使用数据保护写操作时,在写之前必须先擦除整块扇区,因此用户可以先备份(部分数据需写入)目标扇区中的数据到缓存,然后将需写入的数据也写到缓存中去,然后擦除目标扇区,最后将缓存中的数据写入到目标扇区中。因此就有了上述操作!!!
另.flash文件的存储格式为:
<类型(1B)><数据长度(nB)><起始地址(4B)><有效数据><校验和值(1B)><有效数据><校验和值(1B)>
eg.:
S32500000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF566FFFFE0024039000566FFFFE00240388
解包:
S3-25-00000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF-56-6FFFFE0024039000566FFFFE002403-88
类型:S3
数据长度:25B
起始地址:00000000
数据:
0x00000000:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFchecksum->0x56
0x00000001:6FFFFE0024039000566FFFFE002403checksum->0x88
OVER!