各种软核处理器二进制文件FPGA初始化文件生成程序
不管是RISC-V, MIPS, Nios II, MicroBlaze, MSP430, 8051, OpenRISC, OpenSPARC, LEON2/LEON3等等软核处理器,在FPGA上实现的时候我们通常需要一部分片上RAM存储bootloader,可以使用gcc的objcopy把bootloader的text, exception vector, rodata, data or bss等你需要的内容copy出来,可以通过-O binary生成二进制文件,可以通过-j .section提取你要的section,当然也可以通过--gap-fill 0x00 参数指定默认各sections之间空白填充的数据。通过以下C程序可以生成符合Altera (Intel)、Xilinx和Verilog中$readmemh调用的内存初始化数据。可以根据不同处理器的大小端字节序做修改,下面的程序为小端序设计。
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* copyright @ Lyu Yang
*/ #include <stdio.h>
#include <stdlib.h> int main(int argc, char** argv)
{
int i, j, FileLen = 0, address = 0, maxaddr;
FILE * FileIn, * FileOut; if (argc != 3) {
printf("Arguments Error!\n");
printf("\nUsage: bin2fpga.exe Depth InputFile\n");
return 0;
}
else { FileIn = fopen(*(argv + 2), "rb");
if (FileIn == NULL){
printf("File does not exist!\n");
return 0;
} fseek(FileIn, 0L, SEEK_END);
FileLen = ftell(FileIn);
maxaddr = atoi(*(argv + 1)); unsigned char * buf = (unsigned char*)malloc(sizeof(char)* FileLen);
if(buf == NULL) {
printf("Memory Allocate Error!\n");
return 0;
} // For altera fpga mif file
FileOut = fopen("./altera.mif", "w"); if (FileOut == NULL) {
printf("Output File Create Error!\n");
return 0;
} fprintf(FileOut, "DEPTH = %d;\nWIDTH = 32;\nADDRESS_RADIX = DEC;\nDATA_RADIX = HEX;\nCONTENT\nBEGIN\n", maxaddr); fseek(FileIn, 0L, SEEK_SET);
fread(buf, FileLen, 1, FileIn); for (i = 0; i < FileLen; i += 4) {
fprintf(FileOut, "%d: ", address); fprintf(FileOut, "%02x", buf[i + 3]);
fprintf(FileOut, "%02x", buf[i + 2]);
fprintf(FileOut, "%02x", buf[i + 1]);
fprintf(FileOut, "%02x", buf[i + 0]); fprintf(FileOut, ";\n");
address++;
} fprintf(FileOut, "[%d..%d]: 0;\n", address, maxaddr - 1); fprintf(FileOut, "\n\nEND;\n"); fclose(FileOut); // For xilinx fpga mif file
FileOut = fopen("./xilinx.mif", "w"); if (FileOut == NULL) {
printf("Output File Create Error!\n");
return 0;
} fseek(FileIn, 0L, SEEK_SET);
fread(buf, FileLen, 1, FileIn); for (i = 0; i < FileLen; i += 4) {
unsigned int word = *((unsigned int*)(buf + i));
int x = 32;
while(x--)
fprintf(FileOut, "%c", (word >> x & 0x1) + '0'); fprintf(FileOut, "\n");
} fclose(FileOut); // For xilinx fpga coe file
FileOut = fopen("./xilinx.coe", "w"); if (FileOut == NULL) {
printf("Output File Create Error!\n");
return 0;
} fprintf(FileOut, "MEMORY_INITIALIZATION_RADIX=16;\nMEMORY_INITIALIZATION_VECTOR=\n"); fseek(FileIn, 0L, SEEK_SET);
fread(buf, FileLen, 1, FileIn); for (i = 0; i < FileLen; i += 4) {
fprintf(FileOut, "%02x", buf[i + 3]);
fprintf(FileOut, "%02x", buf[i + 2]);
fprintf(FileOut, "%02x", buf[i + 1]);
fprintf(FileOut, "%02x", buf[i + 0]); fprintf(FileOut, ",\n");
} fseek(FileOut, -2L, SEEK_END);
fprintf(FileOut, ";\n"); fclose(FileOut); // Generic verilog readmemh file
FileOut = fopen("./readmemh.txt", "w"); if (FileOut == NULL) {
printf("Output File Create Error!\n");
return 0;
} address = 0x0;
fseek(FileIn, 0L, SEEK_SET);
fread(buf, FileLen, 1, FileIn); for (i = 0; i < FileLen; i += 4) {
fprintf(FileOut, "@%08x\n", address); fprintf(FileOut, "%02x", buf[i + 3]);
fprintf(FileOut, "%02x", buf[i + 2]);
fprintf(FileOut, "%02x", buf[i + 1]);
fprintf(FileOut, "%02x", buf[i + 0]); fprintf(FileOut, "\n");
address++;
} free(buf);
fclose(FileIn);
fclose(FileOut);
} return 0;
}
各种软核处理器二进制文件FPGA初始化文件生成程序的更多相关文章
- 【小梅哥FPGA进阶教程】MC8051软核在FPGA上的使用
十.MC8051软核在FPGA上的使用 本教程内容力求以详细的步骤和讲解让读者以最快的方式学会 MC8051 IP core 的应用以及相关设计软件的使用,并激起读者对 SOPC 技术的兴趣.本实验重 ...
- wrHDL编译中软核代码初始化及编译耗时长的问题
问题的提出整个WR的ISE工程比较大,编译时间很长,导致开发效率低.通过分析发现,ISE在综合的时候大量的时间都花在了初始化DPRAM上.调研发现Xilinx提供了BMM文件和DATA2MEM工具,可 ...
- [置顶]
基于FPGA的VGA简易显存设计&NIOS ii软核接入
项目简介 本项目基于Altera公司的Cyclone IV型芯片,利用NIOS II软核,2-port RAM与时序控制模块,实现64*48分辨率的显存(再大的显存板载资源m9k不够用) 实现效果如下 ...
- FPGA的软核与硬核
硬核 zynq和pynq系列的fpga都是双ARM/Cortex-A9构成,这里的ARM处理器为硬核,Cortex-A9部分为FPGA部分.即整体分为两部分:PS/PL.PS部分为A9处理器部分,PL ...
- 关于Quartus构建nios软核以及eclipse建立c语言工程以及成功下载到FPGA芯片过程遇到的各种问题以及解决方法详解
这不是一篇构建nios的教程,而是遇到的各种问题以及解决方法.至于构建教程,网上一大把,我推荐正点原子的FPGA教程,比较新,比较详细,通俗易懂!!! 这里以一个点亮LED灯的Nios软核为例,很明显 ...
- 可编程逻辑(FPGA)与硬核处理器(HPS)之间互联的结构
本周我想进一步探究可编程逻辑(FPGA)与硬核处理器(HPS)之间互联的结构.我发现了三种主要方式,它们是如何映射并处理通信的,哪些组件需要管控时序并且有访问权限. AXI Bridge 为了能够实现 ...
- Spartan6上软核系统自定义外设调用AXI Stream FFT经验
这几天希望能在Spartan系列新品xc6slx16csg324-2运行带有FFT的软核处理系统,基本系统早就搭建好了.需要做的就是建立一个封装有Xilinx提供的FFT IP的自定义外设.由于Xil ...
- 【lattice软核】MICO8流程
The LatticeMico System software is composed of three bundled applications: Mico System Builder (MS ...
- ISE创建Microblaze软核(三)
第七步 进入SDK开发环境 编译完成后弹出如下对话框,选择SDK的工作目录.在MicroblazeTutor中创建一个Workspace文件夹,并选择该文件夹为SDK的工作目录. 进入SDK主界面. ...
随机推荐
- 三:ZooKeeper的ZAB协议
一:ZAB协议概述--->ZooKeeper并没有完全采用Paxos算法,而是使用了一种称为ZooKeeper Atomic Broadcast(ZAB,zookeeper原子消息广播协议)的协 ...
- opencv的使用——经典大坑
视频或相机中读入的帧数不对,或有空帧 image check from cap or video: you must check wether each frame is not empty when ...
- centos安装更新Python2.7以及pip的安装
一.首先对相关的软件进行更新 python -V yum -y update yum groupinstall -y development yum install -y zlib zlib-dev ...
- AC日记——「HNOI2017」礼物 LiBreOJ 2020
#2020. 「HNOI2017」礼物 思路: A题进程: 一眼出式子->各种超时过不去->看题解明白还有fft这个东西->百度文库学习fft->学习dft->学习fft ...
- Python基础系列----环境的搭建及简单输入、输出
1.Python 以下信 ...
- prerender.io 搜索引擎优化 部署成windows服务 实现开机自动开启服务
一 prerender.io服务端部署 参考官方网站的部署步骤: $ git clone https://github.com/prerender/prerender.git $ cd preren ...
- js正则表达大合集【转载自:http://caibaojian.com】
[注明原文链接吧]:http://caibaojian.com 1 用户名正则 //用户名正则,4到16位(字母,数字,下划线,减号) var uPattern = /^[a-zA-Z0-9_-]{4 ...
- 日志 log4net
先引入log4net 接着配置configuration文件 <?xml version="1.0"?><configuration> <system ...
- Mysql Sql Explain
1.使用mysql explain的原因 在我们php程序员的日常写代码中,有时候会发现我们写的sql语句运行的特别慢,导致响应时间特别长,这种情况在高并发的情况下,我们的网站会直接崩溃,为什么双十一 ...
- 洛谷——P2095 营养膳食
题目描述 Mr.L正在完成自己的增肥计划. 为了增肥,Mr.L希望吃到更多的脂肪.然而也不能只吃高脂肪食品,那样的话就会导致缺少其他营养.Mr.L通过研究发现:真正的营养膳食规定某类食品不宜一次性吃超 ...