xilinx FPGA multi boot之镜像切换

这篇具有很好参考价值的文章主要介绍了xilinx FPGA multi boot之镜像切换。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

最近做的了一个无线通信的项目,需要在同一套设备上实现两套不同的波形软件,因为FPGA的逻辑资源不够同时放下两套代码,因此采用了镜像切换的方式来实现,xilinx的专业术语叫multi boot功能 。意思是在一片Flash中的不同地址放两个代码镜像,通过FPGA的任意一个IO切换镜像。详细概念可以参考UG470,PG134等文档,本文仅讲具体的实现代码。

既然是多镜像,意思就是同一套硬件,有多套软件。类似于同一台电脑,可以装了一个linux系统,又装了一个win7系统,甚至多套系统。开机时由用户选择启动哪个系统。
本示例包含2个工程镜像,使用512Mbit的QSPI flash。工程1的镜像放在0地址,工程2的镜像放在地址0x02000000。当外部输入引脚SW为低电平时加载第一个镜像,否则加载第二个镜像。每当SW电平变化,都会启动镜像切换。
第一个工程的顶层如下:

module project1(
	input		CLK,//输入时钟,不要超过100M
	input		rst_n,//复位输入
	output		SW,	//输入为低电平启动镜像1,输入为高电平启动镜像2
	output		LED1,//镜像1亮,镜像2灭
	output		LED2 //镜像1灭,镜像2亮
    );
    
	assign 	LED1 = 1;
	assign 	LED2 = 0;        
    
    mult_boot mult_boot_inst(
        .clk        (CLK),
        .rst_n      (rst_n),
        .img_index  (0),
        .boot_sel   (SW));
endmodule

第二个工程顶层如下:

module project2(
	input		CLK,//输入时钟,不要超过100M
	input		rst_n,//复位输入
	output		SW,	//输入为低电平启动镜像1,输入为高电平启动镜像2
	output		LED1,//镜像1亮,镜像2灭
	output		LED2 //镜像1灭,镜像2亮
    );
    
	assign 	LED1 = 0;
	assign 	LED2 = 1;        
    
    mult_boot mult_boot_inst(
        .clk        (CLK),
        .rst_n      (rst_n),
        .img_index  (1),
        .boot_sel   (SW));
endmodule

注意两个工程都需要调用mult_boot模块,不同的工程img_index输入不一样。工程1设置为0,工程2设置为1。
如果你的SPI flash大于128Mb,必须加上如下约束:
set_property BITSTREAM.CONFIG.SPI_32BIT_ADDR YES [current_design]

mult_boot.v代码如下:

module mult_boot(
    input   clk,
    input   img_index,  //constant to 0 for image0,1 for image1
    input   rst_n,
    input   boot_sel    //0=boot image0;1=boot image1;
);

    parameter [31:0]    IMAGE0_ADDR  = 32'h0;
    parameter [31:0]    IMAGE1_ADDR  = 32'h02000000;
    
    /*When using ICAPE2 to set the WBSTAR address, the 24 most significant address bits should be written
    to WBSTAR[23:0]. For SPI 32-bit addressing mode, WBSTAR[23:0] are sent as address bits [31:8]. The
    lower 8 bits of the address are undefined and the value could be as high as 0xFF. Any bitstream at the
    WBSTAR address should contain 256 dummy bytes before the start of the bitstream..*/
    localparam [31:0]    WBSTAR_IMAGE0_ADDR  = {8'h0,IMAGE0_ADDR[31:8]};
    localparam [31:0]    WBSTAR_IMAGE1_ADDR  = {8'h0,IMAGE1_ADDR[31:8]};

    reg     [1:0]   state;
    reg             boot_sel_lock;
    wire    [31:0]  next_image_addr = (boot_sel_lock==0)? WBSTAR_IMAGE0_ADDR:WBSTAR_IMAGE1_ADDR;
    reg     [2:0]   index;
    reg     [31:0]  icap2_din;
    reg             icap2_csn;

   ICAPE2 #(
      .DEVICE_ID(0'h3691093),     // Specifies the pre-programmed Device ID value to be used for simulation
                                  // purposes.
      .ICAP_WIDTH("X32"),         // Specifies the input and output data width.
      .SIM_CFG_FILE_NAME("None")  // Specifies the Raw Bitstream (RBT) file to be parsed by the simulation model.
   )
   ICAPE2_inst (
      .O(),       // 32-bit output: Configuration data output bus
      .CLK(clk),            // 1-bit input: Clock Input
      .CSIB(icap2_csn),     // 1-bit input: Active-Low ICAP Enable
      .I(icap2_din),        // 32-bit input: Configuration data input bus
      .RDWRB(1'b0)         // 1-bit input: Read_n/Write Select input
   );

    function [31:0] icap_lut;
    input   [7:0]   index;
        begin
            case(index)
            0 :icap_lut={32'hFFFFFFFF         };//Dummy Word
            1 :icap_lut={32'hAA995566         };//Sync Word
            2 :icap_lut={32'h20000000         };//Type 1 NO OP
            3 :icap_lut={32'h30020001         };//Type 1 Write 1 Words to WBSTAR
            4 :icap_lut={next_image_addr      };//Warm Boot Start Address (Load the Desired Address)
            5 :icap_lut={32'h30008001         };//Type 1 Write 1 Words to CMD
            6 :icap_lut={32'h0000000F         };//IPROG Command
            7 :icap_lut={32'h20000000         };//Type 1 NO OP
            default:icap_lut=0;
            endcase
        end
    endfunction

	reg		[31:0]	command;
	always @ (posedge clk) command <= icap_lut(index);
        
    wire [31:0] command_swapped = {
        command[24],command[25],command[26],command[27],command[28],command[29],command[30],command[31],
        command[16],command[17],command[18],command[19],command[20],command[21],command[22],command[23],
        command[ 8],command[ 9],command[10],command[11],command[12],command[13],command[14],command[15],
        command[ 0],command[ 1],command[ 2],command[ 3],command[ 4],command[ 5],command[ 6],command[ 7]};        

    always @ (negedge clk or negedge rst_n)
    begin
        if(!rst_n) begin
            state<=0;icap2_csn<=1;boot_sel_lock<=img_index;index<=0;
        end
        else case(state)
            0:begin
                boot_sel_lock<=boot_sel;
                if(boot_sel_lock!=img_index)
                    state<=1;
            end
            1:begin
                if(index==8) begin
                    state<=0;index<=0;
                end
                else begin
                    state<=2;index<=index+1;icap2_csn<=0;icap2_din<=command_swapped;
                end
            end
            2:begin state<=3;icap2_csn<=1;end
            3:state<=1;
            default:state<=0;
        endcase
    end

endmodule

注意DEVICE_ID的值要根据具体FPGA的型号填入不同的值,V7系列请参考UG470的第14页。

最终实现的效果:SW输入0则加载第一个工程的镜像,LED1亮。SW输入1则加载第二个工程的镜像,LED2亮。
附上两个工程的bit文件合成一个mcs文件的脚本:

write_cfgmem  -format mcs -size 64 -interface SPIx4 -loadbit {up 0x00000000 "project1.bit" up 0x02000000 "project2.bit" } -force -file "merged.mcs"

有相关问题请留言文章来源地址https://www.toymoban.com/news/detail-761768.html

到了这里,关于xilinx FPGA multi boot之镜像切换的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • xilinx 7系列fpga上电配置

    Xilinx FPGA通过加载比特流到内部存储单元来进行配置。 Xilinx FPGA存在两种数据配置路径,一种是满足最小引脚需求的串行路径,一种是可用8位、16位或32位来连接到行业的高性能通用接口,如处理器,8位或者16位并行的闪存。与处理器和处理器外围设备一样, FPGA可以在系统中

    2024年04月14日
    浏览(35)
  • Altera&Xilinx公司FPGA简介

    Intel/Altera 系列FPGA简介 - 知乎 (zhihu.com) Altera FPGA 提供了多种可配置嵌入式 SRAM、高速收发器、高速 I/O、逻辑模块以及布线。其内置知识产权 (IP) 结合优秀的软件工具,缩短了 FPGA 开发时间,降低了功耗和成本。 Altera FPGA 非常适合从大批量应用到目前最新产品的各类应用。每一

    2024年02月05日
    浏览(32)
  • XILINX FPGA各型号差异对比

        FPGA可以提供一些其他方案没法提供的独特价值,如高性能、差异化、高灵活性和低功耗。     ASSP( Application Specific Standard Parts)汉语为专用标准产品,是为在特殊应用中使用而设计的集成电路。算法是不能改的,可能已经有些图像处理的算法嵌在里面,而且价格也很便宜

    2024年02月11日
    浏览(28)
  • Xilinx FPGA PCIE接口调试

            关于在linxu环境下Xilinx FPGA PCIE的接口调试从中遇到了几个问题,第一个就是时钟接口的选择,还有一个就是上位机如何识别XDMA;         操作系统环境:Linux         板卡:两款开发板VC707、KCU105         上位机环境准备:从Xilinx官网下载linux环境的XDMA驱

    2024年02月05日
    浏览(53)
  • 提高Xilinx FPGA Flash下载速度

    最近在编写完FPGA逻辑,成功生成.bin文件后,可以通过Vivado软件进行设置,提高烧写速度。操作如下: (1)布局布线完成后,点击Open Implementation。 (2)点击Tool----- Edit Device Properties... (3)General -----Enable Bitstream Compression -----TRUE,选择压缩数据流,提高下载速度。 (4)Co

    2024年02月03日
    浏览(44)
  • Xilinx 7系列FPGA内置ADC

     Xilinx 7系列FPGA全系内置了一个ADC,称之为XADC。这个XADC,内部是两个1mbps的ADC,可以采集模拟信号转为数字信号送给FPGA内部使用。      XADC内部可以直接获取芯片结温和FPGA的若干供电电压(7系列不包括VCCO),用于监控FPGA内部状况。同时提供了17对差分管脚,其中一对专用

    2024年02月09日
    浏览(40)
  • Xilinx FPGA I/O设置

    PullType共有四种选择: PULLUP、PULLDOWN、 NONE、KEEPER。数字电路有三种状态:高电平、低电平和高阻。当 输入为无效 信号的时候 ,可以通过上拉( PULLUP)电阻 和下拉 (PULLDOWN)电阻的方式使其处于稳定状态。当选择 (KEEPER)时, 使电平保持为上一个有效值。当 IO端口设为LVDS的 时

    2024年04月25日
    浏览(14)
  • Xilinx 7系列FPGA的时钟管理

    在7系列FPGA中,时钟管理单元(CMT)包含了混合模式时钟管理器(MMCM)和锁相环(PLL)。PLL是包含了MMCM功能的一个子集。CMT骨干网可用于链接CMT的时钟功能。CMT图(图3-1)展示了各种时钟输入源与MMCM/PLL之间连接的高级视图,时钟输入连接允许多个资源为MMCM/PLL提供参考时钟

    2024年04月26日
    浏览(33)
  • Xilinx 7系列FPGA局部时钟资源

    局部时钟网络是玩去哪独立于全局时钟网络的。与全局时钟不同,局部时钟信号(BUFR)的覆盖范围仅限于一个时钟区域。一个I/O时钟信号驱动单个时钟区域。这些网络对于源同步接口设计特别有用。在7系列器件中,I/O bank与局部时钟域的大小相同。 在7系列器件中,局部时钟

    2024年04月29日
    浏览(35)
  • xilinx 7系列FPGA 官方文档整理

    1. 官方文档查找链接 搜索结果 • AMD 自适应计算文档门户 (xilinx.com) 2. ug470 - 配置user guide 7 Series FPGAs Configuration User Guide • 7 Series FPGAs Configuration User Guide (UG470) • 阅读器 • AMD 自适应计算文档门户 (xilinx.com) 3. ug471 -IO资源 ug471_7Series_SelectIO.pdf • 查看器 • AMD 自适应计算文档

    2024年04月13日
    浏览(35)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包