目的:
进行双核AMP实验,cpu0需要将cpu1的ELF文件加载到内存。
硬件环境:
zynq7010
软件环境:
workbench6.9
vivado2018.3
petalinux2018.3
uboot中有现成的解析ELF文件的代码,直接复制就可以用。
代码执行说明:
1.使用vivado的sdk编译出cpu1.elf
2.cpu1的ELF文件放到了sd卡中,所以,先得到cpu1.elf文件的长度,再将cpu1.elf复制到内存的0x07000000这个位置。
3.经过第一步,内存的0x07000000已经放着cpu1.elf了。使用uboot的函数校验是否是ELF文件。
4.使用uboot的解析ELF函数对0x07000000地址的数据进行解析。
5.我已经运行过了,cpu1.elf已经被成功解析,并且cpu1也启动成功了。
重要说明
重要说明
重要说明
我用的是c语言,而且是workbench里编译的。
你要是编译出错或者运行出错,只能是你自己的问题。
代码如下:
h文件:
#ifndef __INCsupport_cpu1h
#define __INCsupport_cpu1h
#ifdef __cplusplus
extern "C" {
#endif
/* 将ELF文件复制到这个内存地址,仅仅是复制,不是解析 */
#define CPU1_CODE_COPY_ADDR 0x07000000
/* e_ident */
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
#ifdef __cplusplus
}
#endif
#endif /* __INCh */
c文件:
#include "elf.h"
#include <stdio.h>
#include <string.h>
#include "support_cpu1.h"
/*********************************************
* 输入:文件指针
* 输出:文件长度,单位字节
* *******************************************/
int filelength(FILE *fp)
{
int num;
fseek(fp,0,SEEK_END);
num=ftell(fp);
fseek(fp,0,SEEK_SET);
return num;
}
/*********************************************
* 打开文件 -> 复制文件到内存 -> 关闭文件
* *******************************************/
int copyCpu1Code( void )
{
FILE * fd = NULL;
char *path