深入探究Xilinx Multiboot实例

原理 关于multiboot的原理参考《xilinx 7系列fpga multiboot介绍-远程更新》,基本原理都在此文写的很清楚,本文主要从实例出发演示multiboot。
补充 fpga spi闪存配置接口 7系列fpga和具有x1数据宽度的spi闪存之间的基本连接。读取和地址指令通过主输出-从输入(mosi)引脚从fpga发送到spi闪存。数据通过主输入从输出(miso)引脚从spi闪存返回。sck是时钟引脚,ss是低电平从选择引脚。
参考:ug470
vivado工具流程(multiboot大致流程) 为multiboot程序准备bit流
本节概述了为多引导应用程序创建和更新比特流所需的比特流属性。对于未指定的位流选项,请使用默认设置。
表1概述了用于生成和更新具有每个属性描述的位流的基本多引导位流属性。有关这些属性的详细说明,请参阅vivado design suite用户指南:编程和调试(ug908)。
具体含义如下:
启用在配置尝试失败时加载默认位流
使用下一个配置映像的启动地址设置热启动启动启动地址(wbstar[28:0]位)寄存器
指定启用fpga位流文件压缩
在vivado中打开黄金设计实现(golden)的约束文件(.xdc)。将以下内容复制粘贴到约束文件中,然后保存对.xdc文件所做的更改:
set_property bitstream.config.configfallback enable [current_design]set_property bitstream.config.next_config_addr 0x0400000 [current_design]set_property bitstream.general.compress true [current_design]set_property bitstream.config.spi_buswidth 1 [current_design] 上述不理解没关系,后续实例会有使用教程。
接下来,可以在更新设计(将要更新的文件)中打开约束文件(.xdc),并将以下比特流属性添加到约束文件中,然后保存:
set_property bitstream.config.configfallback enable [current_design]set_property bitstream.general.compress true [current_design]set_property bitstream.config.spi_buswidth 1 [current_design] 注:默认情况下,spi_bus为x1,如果未使用默认x1模式,请确保设置此属性。
生成spi闪存编程文件
具体查看《【vivado那些事】vivado两种生成、固化烧录文件》。
使用write_cfgmem tcl命令创建闪存编程文件(.mcs)。
write_cfgmem获取fpga位流(.bit)并生成可用于编程spi闪存的闪存文件(.mcs)。
例如,生成包含两个fpga位流(.bit文件)的闪存编程文件(.mcs)文件,如下所示:
write_cfgmem -format mcs -interface spix1 -size 16 -loadbit up 0 /golden.bit up0x0400000 /update.bit /filename.mcs 注:地址值0x0400000是参考设计中使用的示例。应使用黄金图像(更新图像的起始地址)中设置的addr a1值(见表1)。
请参阅vivado design suite用户指南:编程和调试(ug908或使用vivado中的-help命令,以了解每个write_cfgmem命令选项的详细说明:
  write_cfgmem -help 硬件验证 硬件验证其实很简单,我们分别建立两个工程,两个工程都是流水灯程序,分别从左到右和从右到左流水灯,这样可以很清楚知道fpga运行了哪个程序。接下来破坏golden程序,按照上述制作mcs文件后运行,看下运行哪个程序。
建立工程 详细的verilog文件如下:
golden工程
module top_multiboot_module_a (    input clk, output reg[3:0]led_out);         ////////////////////////////////////////////  wire reset;assign reset = 1'b1;////////////////////////////////////////////////首先定义一个时间计数寄存器counter,每当达到预定的100ms时,//计数寄存器就清零,否则的话寄存器就加1//然后计算计数器计数的最大值。时钟频率为12mhz//也就是周期为1/12m 3ns,要计数的最大值为t100ms= 100ms/83ns-1 = 120_4818//reg[31:0] counter;parameter t100ms = 25'd920_4818;always @ (posedge clk)if(counter==t100ms) counter<=25'd0;else counter<=counter+1'b1;////////////////////////////////////////////always @ (posedge clk or negedge reset)  if(!reset)   led_out<=4'b0001;        //初值,最低位led[0]灯亮   else if(counter==t100ms)   begin    if(led_out==4'b0000)      //当溢出最高位时     led_out<=4'b0001;    //回到复位时的状态    else     led_out<=led_out<<1;     //循环左移一位  endendmodule // run_led update工程
module top_multiboot_module_b (    input clk, output reg[3:0]led_out);         ////////////////////////////////////////////  wire reset;assign reset = 1'b1;////////////////////////////////////////////////首先定义一个时间计数寄存器counter,每当达到预定的100ms时,//计数寄存器就清零,否则的话寄存器就加1��//然后计算计数器计数的最大值。时钟频率为12mhz��//也就是周期为1/12m ��3ns,要计数的最大值为t100ms= 100ms/83ns-1 = 120_4818��//reg[31:0] counter;parameter t100ms = 25'd920_4818;always @ (posedge clk)if(counter==t100ms) counter<=25'd0;else counter<=counter+1'b1;////////////////////////////////////////////always @ (posedge clk or negedge reset)  if(!reset)   led_out<=4'b0001;        //初值,最低位led[0]灯亮   else if(counter==t100ms)   begin    if(led_out==4'b0000)      //当溢出最高位时     led_out<=4'b0001;    //回到复位时的状态    else     led_out<=led_out<<1;     //循环左移一位  endendmodule // run_led 两个工程基本一样,流水的操作是在约束里实现的。
golden工程约束
#clocks#sysclk set_property iostandard lvcmos18 [get_ports clk]set_property package_pin d27 [get_ports clk]#gpio leds# set_property package_pin ab8 [get_ports led_revxx[7]]# set_property iostandard lvcmos15 [get_ports led_revxx[7]]# set_property package_pin aa8 [get_ports led_revxx[6]]# set_property iostandard lvcmos15 [get_ports led_revxx[6]]# set_property package_pin ac9 [get_ports led_revxx[5]]# set_property iostandard lvcmos15 [get_ports led_revxx[5]]# set_property package_pin ab9 [get_ports led_revxx[4]]# set_property iostandard lvcmos15 [get_ports led_revxx[4]]# set_property package_pin ae26 [get_ports led_out[3]]# set_property iostandard lvcmos33 [get_ports led_out[3]]set_property package_pin t21 [get_ports led_out[2]]set_property iostandard lvcmos33 [get_ports led_out[2]]set_property package_pin t20 [get_ports led_out[1]]set_property iostandard lvcmos33 [get_ports led_out[1]]set_property package_pin r24 [get_ports led_out[0]]set_property iostandard lvcmos33 [get_ports led_out[0]]# cfgbvs and spi mode propertiesset_property cfgbvs vcco [current_design]set_property config_voltage 2.5 [current_design]set_property config_mode spix1 [current_design]#compress the bitstream to fit on 128m qspi of the k7set_property bitstream.general.compress true [current_design]#bitstream properties required for golden image:set_property bitstream.config.spi_buswidth 1 [current_design]set_property bitstream.config.configfallback enable [current_design]set_property bitstream.config.next_config_addr 0x0400000 [current_design]#(if the spi flash is equal to or greater than 256 mb, uncomment the constraint below):#set_property bitstream.config.spi_32bit_addr yes [current_design] 这里解释一下,前面物理约束不重要,因为“穷”,我的板子只有3颗led,所以只进行了三个物理约束。
cfgbvs and spi mode properties及compress the bitstream to fit on 128m qspi of the k7、bitstream properties required for golden image是重点约束的对象,具体解释看下表一。
set_property bitstream.config.spi_buswidth 1 [current_design]set_property bitstream.config.configfallback enable [current_design]set_property bitstream.config.next_config_addr 0x0400000 [current_design] 这三个约束是和update工程有关,一个是spi的buswidth,一个是否开启configfallback,最后一个是地址,这是非常重要的。
接下来是update工程的约束文件
#clocks#sysclk set_property iostandard lvcmos18 [get_ports clk]set_property package_pin d27 [get_ports clk]#gpio leds# set_property package_pin ab8 [get_ports led_revxx[7]]# set_property iostandard lvcmos15 [get_ports led_revxx[7]]# set_property package_pin aa8 [get_ports led_revxx[6]]# set_property iostandard lvcmos15 [get_ports led_revxx[6]]# set_property package_pin ac9 [get_ports led_revxx[5]]# set_property iostandard lvcmos15 [get_ports led_revxx[5]]# set_property package_pin ab9 [get_ports led_revxx[4]]# set_property iostandard lvcmos15 [get_ports led_revxx[4]]# set_property package_pin ae26 [get_ports led_out[3]]# set_property iostandard lvcmos33 [get_ports led_out[3]]set_property package_pin r24 [get_ports led_out[2]]set_property iostandard lvcmos33 [get_ports led_out[2]]set_property package_pin t20 [get_ports led_out[1]]set_property iostandard lvcmos33 [get_ports led_out[1]]set_property package_pin t21 [get_ports led_out[0]]set_property iostandard lvcmos33 [get_ports led_out[0]]# cfgbvs and spi mode propertiesset_property cfgbvs vcco [current_design]set_property config_voltage 2.5 [current_design]set_property config_mode spix1 [current_design]#compress the bitstream set_property bitstream.general.compress true [current_design]#bitstream properties required for golden image:set_property bitstream.config.spi_buswidth 1 [current_design]set_property bitstream.config.configfallback enable [current_design]#(if the spi flash is equal to or greater than 256 mb, uncomment the constraint below):#set_property bitstream.config.spi_32bit_addr yes [current_design] 物理约束同样不重要,重要的还是下面的和multiboot相关的约束,具体解释和上面一样。
生成bit流并运行 上述两个工程分别生成bit流并运行,查看两个流水灯是否是两个不同方向的。
合成mcs文件并运行 将两个bit流文件合成一个mcs文件,命令如下:
write_cfgmem -format mcs -interface spix1 -size 16 -loadbit up 0 /golden.bit up0x0400000 /update.bit /filename.mcs 两个bit流文件位置;
filename: mcs文件名称。
将上诉mcs文件下载到fpga开发板上,可以看见update工程文件运行。
破坏golden文件 回退到golden可以通过不同的方式触发。主要有以下几种方式:
id code错误 crc错误 watchdog超时 bpi地址越界 有关更多信息,请参阅ug470中的重新配置和多引导章节。
本应用说明演示了由crc错误触发的回退。可以手动损坏更新位流以导致crc错误。在reset crc命令和crc命令之间有许多可以翻转位的位置。下图显示了一个示例。
1.使用十六进制编辑器(hxd hex editor)中打开更新(update)比特流(.bit),在比特流中间翻转一些数据字节,例如从00到11,如图所示。 为了保证破坏彻底,可以多更改几处。
  保存损坏的更新位流,并使用此损坏的位流生成新的闪存编程文件(.mcs)。 write_cfgmem -format mcs -interface spix1 -size 16 -loadbit up 0 /golden.bit up0x0400000 /update.bit /filename.mcs 3.重新下载文件 观察是golden还是update文件运行,同理可以将上诉命令修改,将golden和update更换一下mcs文件位置,对比测试,上诉两个情况本人都有亲自测试过,都是golden文件运行,证明multiboot已经生效。

时隔近3个月后,小米再次发布红米全新一代旗舰“K30S 至尊纪念版”
云原生的代表性技术
将OLED显示器与NodeMCU ESP8266连接的过程
ASML最新一代EUV设备2025年量产
助力华为打开芯片市场,微软用其AI芯片
深入探究Xilinx Multiboot实例
无线设备测试的衰落概念详解
IPv4超网的定义 超网是如何进行聚合的?
Raspberry Pi与过去的计算机相比如何?
特斯拉电池的维修
PSoC™ 62温湿采集功耗测试
启动电容和运行电容接线图
恩智浦推出提高频率、功率和效率的第2代射频多芯片模块,保持5G基础设施领先地位
风机中变桨系统的作用是什么
怎么实现语音识别_手机语音识别怎么设置
技术开拓未来,格瑞普为百年大党与中国巨变演绎中国奇迹
Udelv在2019年CES展上推出其自动驾驶送货车 现已开始接受2020年的预订
如何设计高效高可靠的LED驱动
苹果对决Android实质:乔布斯的专利核战争
放大器电路设计中的常见问题解析