首先让我们来了解几个简单的数据类型:
/* structure definition */ // 此结构体用来记录程序镜像的各项数据
struct image_info
{
unsigned int offset; // 偏移量
unsigned int length; // 镜像的长度
char *filename; // 镜像的名字
unsigned char *dest; // 镜像的位置(在存储芯片的位置)
unsigned char of;
unsigned int of_offset;
unsigned int of_length;
char *of_filename;
unsigned char *of_dest;
};
typedef int (*load_function)(struct image_info *img_info); // 定义加载镜像的函数指针
static load_function load_image; // 创建一个加载镜像函数的指针变量,在init_loadfunction(void)进行初始化
然后让我们根据main.c中的main函数中程序执行的步骤进行分析:
int main(void)
{
struct image_info image; // 创建一个记录镜像信息的对象
char *media_str = NULL; // 记录系统的启动方式,(即镜像存储芯片的类型:NandFlash、SdCard或者DataFlash)
int ret;
char filename[FILENAME_BUF_LEN];
char of_filename[FILENAME_BUF_LEN];
memset